"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SliceBehavior = void 0;
const constants_1 = require("../slice/constants");
const util_1 = require("../slice/util");
const sliceCustomData = new WeakMap();
class SliceBehavior {
    isInline() {
        return this.stacking !== constants_1.SliceStacking.Marker;
    }
    /**
     * An opaque object which can be mutated in-place by the rendering layer
     * to store custom rendering-specific data. This is useful for storing, for
     * example, React component references, which is specific to the rendering
     * layer.
     *
     * Usage:
     *
     * ```ts
     * registry.get(SliceTypeCon.a)?.data().ReactConfig = ReactConfigCompForLink;
     * ```
     *
     * @returns The custom data of the slice.
     */
    data() {
        const data = sliceCustomData.get(this);
        if (data)
            return data;
        const newData = {};
        sliceCustomData.set(this, newData);
        return newData;
    }
    constructor(
    /**
     * Specifies whether the slice is an inline or block element. And if it is
     * an inline element, whether multiple instances of the same tag are allowed
     * to be applied to a range of tex - "Many", or only one instance - "One".
     */
    stacking, 
    /**
     * The tag name of this slice. The tag is one step in the type path of the
     * slice. For example, below is a type path composed of three steps:
     *
     * ```js
     * ['ul', 'li', 'p']
     * ```
     *
     * Tag types are normally numbers of type {@link SliceTypeCon}, however,
     * they can also be any arbitrary strings or numbers.
     */
    tag, 
    /**
     * User friendly display name. Also used for translation purposes.
     */
    name, 
    /**
     * Default expected schema of the slice data.
     */
    schema = void 0, 
    /**
     * This property is relevant only for block split markers. It specifies
     * whether the block split marker is a container for other block elements.
     *
     * For example, a `blockquote` is a container for `paragraph` elements,
     * however, a `paragraph` is not a container (it can only contain inline
     * elements).
     *
     * If the marker slice is of the container sort, they tag can appear in the
     * path steps of the type:
     *
     * ```
     *
     * ```
     */
    container = false, 
    /**
     * Converts a node of this type to HTML representation: returns the HTML tag
     * and attributes. The method receives {@link PeritextMlElement} as an
     * argument, which is a tuple of internal HTML-like representation of the
     * node.
     */
    toHtml = void 0, 
    /**
     * Specifies a mapping of converters from HTML {@link JsonMlElement} to
     * {@link PeritextMlElement}. This way a slice type can specify multiple
     * HTML tags that are converted to the same slice type.
     *
     * For example, both, `<b>` and `<strong>` tags can be converted to the
     * {@link SliceTypeCon.b} slice type.
     */
    fromHtml) {
        this.stacking = stacking;
        this.tag = tag;
        this.name = name;
        this.schema = schema;
        this.container = container;
        this.toHtml = toHtml;
        this.fromHtml = fromHtml;
    }
    /** ----------------------------------------------------- {@link Printable} */
    toString(tab = '') {
        return `${(0, util_1.formatType)(this.tag)} (${this.stacking}) ${JSON.stringify(Object.keys(this.data))}`;
    }
}
exports.SliceBehavior = SliceBehavior;
//# sourceMappingURL=SliceBehavior.js.map