{"version":3,"file":"taiga-ui-editor-extensions-mention.mjs","sources":["../../../projects/editor/extensions/mention/index.ts","../../../projects/editor/extensions/mention/taiga-ui-editor-extensions-mention.ts"],"sourcesContent":["import {type Attributes, mergeAttributes, Node} from '@tiptap/core';\nimport {type DOMOutputSpec, type Node as ProseMirrorNode} from '@tiptap/pm/model';\n\nexport interface TuiMentionOptions {\n    HTMLAttributes: Record<string, any>;\n    renderHTML(props: {options: TuiMentionOptions; node: ProseMirrorNode}): DOMOutputSpec;\n}\n\nexport const TuiMention = Node.create<TuiMentionOptions>({\n    name: 'mention',\n    group: 'inline',\n    inline: true,\n    selectable: true,\n    atom: true,\n\n    addOptions(): TuiMentionOptions {\n        return {\n            HTMLAttributes: {},\n            renderHTML({node}) {\n                return [\n                    'span',\n                    this.HTMLAttributes,\n                    `@${node.attrs.label ?? node.attrs.id}`.replaceAll(/@+/g, '@'),\n                ];\n            },\n        };\n    },\n\n    addAttributes(): Attributes {\n        return {\n            id: {\n                default: null,\n                keepOnSplit: true,\n                parseHTML: (element) => element.innerText,\n                renderHTML: () => ({'data-type': this.name}),\n            },\n            class: {\n                default: null,\n                keepOnSplit: true,\n            },\n            dataAttributes: {\n                default: {},\n                keepOnSplit: true,\n                parseHTML: (element) =>\n                    element\n                        .getAttributeNames()\n                        .filter(\n                            (attribute) =>\n                                attribute.startsWith('data-') &&\n                                attribute !== 'data-type',\n                        )\n                        .reduce<Record<string, string | null>>(\n                            (attributes, attribute) => ({\n                                ...attributes,\n                                [attribute]: element.getAttribute(attribute),\n                            }),\n                            {},\n                        ),\n                renderHTML: ({dataAttributes}) => dataAttributes,\n            },\n        };\n    },\n\n    parseHTML(): [{tag: string}] {\n        return [{tag: `span[data-type=\"${this.name}\"]`}];\n    },\n\n    renderHTML({node, HTMLAttributes}): DOMOutputSpec {\n        const html = this.options.renderHTML({\n            options: this.options,\n            node,\n        });\n\n        if (typeof html === 'string') {\n            return [\n                'span',\n                mergeAttributes(\n                    {'data-type': this.name},\n                    this.options.HTMLAttributes,\n                    HTMLAttributes,\n                ),\n                html,\n            ];\n        }\n\n        return [\n            'span',\n            mergeAttributes(\n                {'data-type': this.name},\n                this.options.HTMLAttributes,\n                HTMLAttributes,\n            ),\n            (html as any)?.[2],\n        ];\n    },\n});\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AAQa,MAAA,UAAU,GAAG,IAAI,CAAC,MAAM,CAAoB;AACrD,IAAA,IAAI,EAAE,SAAS;AACf,IAAA,KAAK,EAAE,QAAQ;AACf,IAAA,MAAM,EAAE,IAAI;AACZ,IAAA,UAAU,EAAE,IAAI;AAChB,IAAA,IAAI,EAAE,IAAI;IAEV,UAAU,GAAA;QACN,OAAO;AACH,YAAA,cAAc,EAAE,EAAE;YAClB,UAAU,CAAC,EAAC,IAAI,EAAC,EAAA;gBACb,OAAO;oBACH,MAAM;AACN,oBAAA,IAAI,CAAC,cAAc;AACnB,oBAAA,CAAA,CAAA,EAAI,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC;iBACjE,CAAC;aACL;SACJ,CAAC;KACL;IAED,aAAa,GAAA;QACT,OAAO;AACH,YAAA,EAAE,EAAE;AACA,gBAAA,OAAO,EAAE,IAAI;AACb,gBAAA,WAAW,EAAE,IAAI;gBACjB,SAAS,EAAE,CAAC,OAAO,KAAK,OAAO,CAAC,SAAS;AACzC,gBAAA,UAAU,EAAE,OAAO,EAAC,WAAW,EAAE,IAAI,CAAC,IAAI,EAAC,CAAC;AAC/C,aAAA;AACD,YAAA,KAAK,EAAE;AACH,gBAAA,OAAO,EAAE,IAAI;AACb,gBAAA,WAAW,EAAE,IAAI;AACpB,aAAA;AACD,YAAA,cAAc,EAAE;AACZ,gBAAA,OAAO,EAAE,EAAE;AACX,gBAAA,WAAW,EAAE,IAAI;AACjB,gBAAA,SAAS,EAAE,CAAC,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