@tiptap/extension-mention 2.0.0-beta.83 → 2.0.0-beta.88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -91,14 +91,14 @@ const Mention = core.Node.create({
91
91
  parseHTML() {
92
92
  return [
93
93
  {
94
- tag: 'span[data-mention]',
94
+ tag: `span[data-type="${this.name}"]`,
95
95
  },
96
96
  ];
97
97
  },
98
98
  renderHTML({ node, HTMLAttributes }) {
99
99
  return [
100
100
  'span',
101
- core.mergeAttributes({ 'data-mention': '' }, this.options.HTMLAttributes, HTMLAttributes),
101
+ core.mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),
102
102
  this.options.renderLabel({
103
103
  options: this.options,
104
104
  node,
@@ -1 +1 @@
1
- {"version":3,"file":"tiptap-extension-mention.cjs.js","sources":["../src/mention.ts"],"sourcesContent":["import { Node, mergeAttributes } from '@tiptap/core'\nimport { Node as ProseMirrorNode } from 'prosemirror-model'\nimport { PluginKey } from 'prosemirror-state'\nimport Suggestion, { SuggestionOptions } from '@tiptap/suggestion'\n\nexport type MentionOptions = {\n HTMLAttributes: Record<string, any>,\n renderLabel: (props: {\n options: MentionOptions,\n node: ProseMirrorNode,\n }) => string,\n suggestion: Omit<SuggestionOptions, 'editor'>,\n}\n\nexport const MentionPluginKey = new PluginKey('mention')\n\nexport const Mention = Node.create<MentionOptions>({\n name: 'mention',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n renderLabel({ options, node }) {\n return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`\n },\n suggestion: {\n char: '@',\n pluginKey: MentionPluginKey,\n command: ({ editor, range, props }) => {\n // increase range.to by one when the next node is of type \"text\"\n // and starts with a space character\n const nodeAfter = editor.view.state.selection.$to.nodeAfter\n const overrideSpace = nodeAfter?.text?.startsWith(' ')\n\n if (overrideSpace) {\n range.to += 1\n }\n\n editor\n .chain()\n .focus()\n .insertContentAt(range, [\n {\n type: this.name,\n attrs: props,\n },\n {\n type: 'text',\n text: ' ',\n },\n ])\n .run()\n },\n allow: ({ editor, range }) => {\n const $from = editor.state.doc.resolve(range.from)\n const type = editor.schema.nodes[this.name]\n const allow = !!$from.parent.type.contentMatch.matchType(type)\n\n return allow\n },\n },\n }\n },\n\n group: 'inline',\n\n inline: true,\n\n selectable: false,\n\n atom: true,\n\n addAttributes() {\n return {\n id: {\n default: null,\n parseHTML: element => element.getAttribute('data-id'),\n renderHTML: attributes => {\n if (!attributes.id) {\n return {}\n }\n\n return {\n 'data-id': attributes.id,\n }\n },\n },\n\n label: {\n default: null,\n parseHTML: element => element.getAttribute('data-label'),\n renderHTML: attributes => {\n if (!attributes.label) {\n return {}\n }\n\n return {\n 'data-label': attributes.label,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'span[data-mention]',\n },\n ]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n return [\n 'span',\n mergeAttributes({ 'data-mention': '' }, this.options.HTMLAttributes, HTMLAttributes),\n this.options.renderLabel({\n options: this.options,\n node,\n }),\n ]\n },\n\n renderText({ node }) {\n return this.options.renderLabel({\n options: this.options,\n node,\n })\n },\n\n addKeyboardShortcuts() {\n return {\n Backspace: () => this.editor.commands.command(({ tr, state }) => {\n let isMention = false\n const { selection } = state\n const { empty, anchor } = selection\n\n if (!empty) {\n return false\n }\n\n state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {\n if (node.type.name === this.name) {\n isMention = true\n tr.insertText(this.options.suggestion.char || '', pos, pos + node.nodeSize)\n\n return false\n }\n })\n\n return isMention\n }),\n }\n },\n\n addProseMirrorPlugins() {\n return [\n Suggestion({\n editor: this.editor,\n ...this.options.suggestion,\n }),\n ]\n },\n})\n"],"names":["PluginKey","Node","mergeAttributes","Suggestion"],"mappings":";;;;;;;;;;;;MAca,gBAAgB,GAAG,IAAIA,0BAAS,CAAC,SAAS,EAAC;MAE3C,OAAO,GAAGC,SAAI,CAAC,MAAM,CAAiB;IAC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;QACjB,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;YAC9B,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI;SACL,CAAC,CAAA;KACH;IAED,oBAAoB;QAClB,OAAO;YACL,SAAS,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE;gBAC1D,IAAI,SAAS,GAAG,KAAK,CAAA;gBACrB,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAA;gBAC3B,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;gBAEnC,IAAI,CAAC,KAAK,EAAE;oBACV,OAAO,KAAK,CAAA;iBACb;gBAED,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,GAAG;oBACnD,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;wBAChC,SAAS,GAAG,IAAI,CAAA;wBAChB,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;wBAE3E,OAAO,KAAK,CAAA;qBACb;iBACF,CAAC,CAAA;gBAEF,OAAO,SAAS,CAAA;aACjB,CAAC;SACH,CAAA;KACF;IAED,qBAAqB;QACnB,OAAO;YACLC,8BAAU,CAAC;gBACT,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU;aAC3B,CAAC;SACH,CAAA;KACF;CACF;;;;;;"}
1
+ {"version":3,"file":"tiptap-extension-mention.cjs.js","sources":["../src/mention.ts"],"sourcesContent":["import { Node, mergeAttributes } from '@tiptap/core'\nimport { Node as ProseMirrorNode } from 'prosemirror-model'\nimport { PluginKey } from 'prosemirror-state'\nimport Suggestion, { SuggestionOptions } from '@tiptap/suggestion'\n\nexport type MentionOptions = {\n HTMLAttributes: Record<string, any>,\n renderLabel: (props: {\n options: MentionOptions,\n node: ProseMirrorNode,\n }) => string,\n suggestion: Omit<SuggestionOptions, 'editor'>,\n}\n\nexport const MentionPluginKey = new PluginKey('mention')\n\nexport const Mention = Node.create<MentionOptions>({\n name: 'mention',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n renderLabel({ options, node }) {\n return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`\n },\n suggestion: {\n char: '@',\n pluginKey: MentionPluginKey,\n command: ({ editor, range, props }) => {\n // increase range.to by one when the next node is of type \"text\"\n // and starts with a space character\n const nodeAfter = editor.view.state.selection.$to.nodeAfter\n const overrideSpace = nodeAfter?.text?.startsWith(' ')\n\n if (overrideSpace) {\n range.to += 1\n }\n\n editor\n .chain()\n .focus()\n .insertContentAt(range, [\n {\n type: this.name,\n attrs: props,\n },\n {\n type: 'text',\n text: ' ',\n },\n ])\n .run()\n },\n allow: ({ editor, range }) => {\n const $from = editor.state.doc.resolve(range.from)\n const type = editor.schema.nodes[this.name]\n const allow = !!$from.parent.type.contentMatch.matchType(type)\n\n return allow\n },\n },\n }\n },\n\n group: 'inline',\n\n inline: true,\n\n selectable: false,\n\n atom: true,\n\n addAttributes() {\n return {\n id: {\n default: null,\n parseHTML: element => element.getAttribute('data-id'),\n renderHTML: attributes => {\n if (!attributes.id) {\n return {}\n }\n\n return {\n 'data-id': attributes.id,\n }\n },\n },\n\n label: {\n default: null,\n parseHTML: element => element.getAttribute('data-label'),\n renderHTML: attributes => {\n if (!attributes.label) {\n return {}\n }\n\n return {\n 'data-label': attributes.label,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: `span[data-type=\"${this.name}\"]`,\n },\n ]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n return [\n 'span',\n mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),\n this.options.renderLabel({\n options: this.options,\n node,\n }),\n ]\n },\n\n renderText({ node }) {\n return this.options.renderLabel({\n options: this.options,\n node,\n })\n },\n\n addKeyboardShortcuts() {\n return {\n Backspace: () => this.editor.commands.command(({ tr, state }) => {\n let isMention = false\n const { selection } = state\n const { empty, anchor } = selection\n\n if (!empty) {\n return false\n }\n\n state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {\n if (node.type.name === this.name) {\n isMention = true\n tr.insertText(this.options.suggestion.char || '', pos, pos + node.nodeSize)\n\n return false\n }\n })\n\n return isMention\n }),\n }\n },\n\n addProseMirrorPlugins() {\n return [\n Suggestion({\n editor: this.editor,\n ...this.options.suggestion,\n }),\n ]\n },\n})\n"],"names":["PluginKey","Node","mergeAttributes","Suggestion"],"mappings":";;;;;;;;;;;;MAca,gBAAgB,GAAG,IAAIA,0BAAS,CAAC,SAAS,EAAC;MAE3C,OAAO,GAAGC,SAAI,CAAC,MAAM,CAAiB;IACjD,IAAI,EAAE,SAAS;IAEf,UAAU;QACR,OAAO;YACL,cAAc,EAAE,EAAE;YAClB,WAAW,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE;;gBAC3B,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,MAAA,IAAI,CAAC,KAAK,CAAC,KAAK,mCAAI,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAA;aACxE;YACD,UAAU,EAAE;gBACV,IAAI,EAAE,GAAG;gBACT,SAAS,EAAE,gBAAgB;gBAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE;;;;oBAGhC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAA;oBAC3D,MAAM,aAAa,GAAG,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,0CAAE,UAAU,CAAC,GAAG,CAAC,CAAA;oBAEtD,I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AC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;wBAChC,SAAS,GAAG,IAAI,CAAA;wBAChB,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;wBAE3E,OAAO,KAAK,CAAA;qBACb;iBACF,CAAC,CAAA;gBAEF,OAAO,SAAS,CAAA;aACjB,CAAC;SACH,CAAA;KACF;IAED,qBAAqB;QACnB,OAAO;YACLC,8BAAU,CAAC;gBACT,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU;aAC3B,CAAC;SACH,CAAA;KACF;CACF;;;;;;"}
@@ -83,14 +83,14 @@ const Mention = Node.create({
83
83
  parseHTML() {
84
84
  return [
85
85
  {
86
- tag: 'span[data-mention]',
86
+ tag: `span[data-type="${this.name}"]`,
87
87
  },
88
88
  ];
89
89
  },
90
90
  renderHTML({ node, HTMLAttributes }) {
91
91
  return [
92
92
  'span',
93
- mergeAttributes({ 'data-mention': '' }, this.options.HTMLAttributes, HTMLAttributes),
93
+ mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),
94
94
  this.options.renderLabel({
95
95
  options: this.options,
96
96
  node,
@@ -1 +1 @@
1
- {"version":3,"file":"tiptap-extension-mention.esm.js","sources":["../src/mention.ts"],"sourcesContent":["import { Node, mergeAttributes } from '@tiptap/core'\nimport { Node as ProseMirrorNode } from 'prosemirror-model'\nimport { PluginKey } from 'prosemirror-state'\nimport Suggestion, { SuggestionOptions } from '@tiptap/suggestion'\n\nexport type MentionOptions = {\n HTMLAttributes: Record<string, any>,\n renderLabel: (props: {\n options: MentionOptions,\n node: ProseMirrorNode,\n }) => string,\n suggestion: Omit<SuggestionOptions, 'editor'>,\n}\n\nexport const MentionPluginKey = new PluginKey('mention')\n\nexport const Mention = Node.create<MentionOptions>({\n name: 'mention',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n renderLabel({ options, node }) {\n return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`\n },\n suggestion: {\n char: '@',\n pluginKey: MentionPluginKey,\n command: ({ editor, range, props }) => {\n // increase range.to by one when the next node is of type \"text\"\n // and starts with a space character\n const nodeAfter = editor.view.state.selection.$to.nodeAfter\n const overrideSpace = nodeAfter?.text?.startsWith(' ')\n\n if (overrideSpace) {\n range.to += 1\n }\n\n editor\n .chain()\n .focus()\n .insertContentAt(range, [\n {\n type: this.name,\n attrs: props,\n },\n {\n type: 'text',\n text: ' ',\n },\n ])\n .run()\n },\n allow: ({ editor, range }) => {\n const $from = editor.state.doc.resolve(range.from)\n const type = editor.schema.nodes[this.name]\n const allow = !!$from.parent.type.contentMatch.matchType(type)\n\n return allow\n },\n },\n }\n },\n\n group: 'inline',\n\n inline: true,\n\n selectable: false,\n\n atom: true,\n\n addAttributes() {\n return {\n id: {\n default: null,\n parseHTML: element => element.getAttribute('data-id'),\n renderHTML: attributes => {\n if (!attributes.id) {\n return {}\n }\n\n return {\n 'data-id': attributes.id,\n }\n },\n },\n\n label: {\n default: null,\n parseHTML: element => element.getAttribute('data-label'),\n renderHTML: attributes => {\n if (!attributes.label) {\n return {}\n }\n\n return {\n 'data-label': attributes.label,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'span[data-mention]',\n },\n ]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n return [\n 'span',\n mergeAttributes({ 'data-mention': '' }, this.options.HTMLAttributes, HTMLAttributes),\n this.options.renderLabel({\n options: this.options,\n node,\n }),\n ]\n },\n\n renderText({ node }) {\n return this.options.renderLabel({\n options: this.options,\n node,\n })\n },\n\n addKeyboardShortcuts() {\n return {\n Backspace: () => this.editor.commands.command(({ tr, state }) => {\n let isMention = false\n const { selection } = state\n const { empty, anchor } = selection\n\n if (!empty) {\n return false\n }\n\n state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {\n if (node.type.name === this.name) {\n isMention = true\n tr.insertText(this.options.suggestion.char || '', pos, pos + node.nodeSize)\n\n return false\n }\n })\n\n return isMention\n }),\n }\n },\n\n addProseMirrorPlugins() {\n return [\n Suggestion({\n editor: this.editor,\n ...this.options.suggestion,\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;;;MAca,gBAAgB,GAAG,IAAI,SAAS,CAAC,SAAS,EAAC;MAE3C,OAAO,GAAG,IAAI,CAAC,MAAM,CAAiB;IACjD,IAAI,EAAE,SAAS;IAEf,UAAU;QACR,OAAO;YACL,cAAc,EAAE,EAAE;YAClB,WAAW,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE;;gBAC3B,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,MAAA,IAAI,CAAC,KAAK,CAAC,KAAK,mCAAI,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAA;aACxE;YACD,UAAU,EAAE;gBACV,IAAI,EAAE,GAAG;gBACT,SAAS,EAAE,gBAAgB;gBAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE;;;;oBAGhC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAA;oBAC3D,MAAM,aAAa,GAAG,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,0CAAE,UAAU,CAAC,GAAG,CAAC,CAAA;oBAEtD,IAAI,aAAa,EAAE;wBACjB,KAAK,CAAC,EAAE,IAAI,CAAC,CAAA;qBACd;oBAED,MAAM;yBACH,KAAK,EAAE;yBACP,KAAK,EAAE;yBACP,eAAe,CAAC,KAAK,EAAE;wBACtB;4BACE,IAAI,EAAE,IAAI,CAAC,IAAI;4BACf,KAAK,EAAE,KAAK;yBACb;wBACD;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,GAAG;yBACV;qB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ACH,CAAA;KACF;IAED,qBAAqB;QACnB,OAAO;YACL,UAAU,CAAC;gBACT,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU;aAC3B,CAAC;SACH,CAAA;KACF;CACF;;;;"}
1
+ {"version":3,"file":"tiptap-extension-mention.esm.js","sources":["../src/mention.ts"],"sourcesContent":["import { Node, mergeAttributes } from '@tiptap/core'\nimport { Node as ProseMirrorNode } from 'prosemirror-model'\nimport { PluginKey } from 'prosemirror-state'\nimport Suggestion, { SuggestionOptions } from '@tiptap/suggestion'\n\nexport type MentionOptions = {\n HTMLAttributes: Record<string, any>,\n renderLabel: (props: {\n options: MentionOptions,\n node: ProseMirrorNode,\n }) => string,\n suggestion: Omit<SuggestionOptions, 'editor'>,\n}\n\nexport const MentionPluginKey = new PluginKey('mention')\n\nexport const Mention = Node.create<MentionOptions>({\n name: 'mention',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n renderLabel({ options, node }) {\n return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`\n },\n suggestion: {\n char: '@',\n pluginKey: MentionPluginKey,\n command: ({ editor, range, props }) => {\n // increase range.to by one when the next node is of type \"text\"\n // and starts with a space character\n const nodeAfter = editor.view.state.selection.$to.nodeAfter\n const overrideSpace = nodeAfter?.text?.startsWith(' ')\n\n if (overrideSpace) {\n range.to += 1\n }\n\n editor\n .chain()\n .focus()\n .insertContentAt(range, [\n {\n type: this.name,\n attrs: props,\n },\n {\n type: 'text',\n text: ' ',\n },\n ])\n .run()\n },\n allow: ({ editor, range }) => {\n const $from = editor.state.doc.resolve(range.from)\n const type = editor.schema.nodes[this.name]\n const allow = !!$from.parent.type.contentMatch.matchType(type)\n\n return allow\n },\n },\n }\n },\n\n group: 'inline',\n\n inline: true,\n\n selectable: false,\n\n atom: true,\n\n addAttributes() {\n return {\n id: {\n default: null,\n parseHTML: element => element.getAttribute('data-id'),\n renderHTML: attributes => {\n if (!attributes.id) {\n return {}\n }\n\n return {\n 'data-id': attributes.id,\n }\n },\n },\n\n label: {\n default: null,\n parseHTML: element => element.getAttribute('data-label'),\n renderHTML: attributes => {\n if (!attributes.label) {\n return {}\n }\n\n return {\n 'data-label': attributes.label,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: `span[data-type=\"${this.name}\"]`,\n },\n ]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n return [\n 'span',\n mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),\n this.options.renderLabel({\n options: this.options,\n node,\n }),\n ]\n },\n\n renderText({ node }) {\n return this.options.renderLabel({\n options: this.options,\n node,\n })\n },\n\n addKeyboardShortcuts() {\n return {\n Backspace: () => this.editor.commands.command(({ tr, state }) => {\n let isMention = false\n const { selection } = state\n const { empty, anchor } = selection\n\n if (!empty) {\n return false\n }\n\n state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {\n if (node.type.name === this.name) {\n isMention = true\n tr.insertText(this.options.suggestion.char || '', pos, pos + node.nodeSize)\n\n return false\n }\n })\n\n return isMention\n }),\n }\n },\n\n addProseMirrorPlugins() {\n return [\n Suggestion({\n editor: this.editor,\n ...this.options.suggestion,\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;;;MAca,gBAAgB,GAAG,IAAI,SAAS,CAAC,SAAS,EAAC;MAE3C,OAAO,GAAG,IAAI,CAAC,MAAM,CAAiB;IACjD,IAAI,EAAE,SAAS;IAEf,UAAU;QACR,OAAO;YACL,cAAc,EAAE,EAAE;YAClB,WAAW,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE;;gBAC3B,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,MAAA,IAAI,CAAC,KAAK,CAAC,KAAK,mCAAI,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAA;aACxE;YACD,UAAU,EAAE;gBACV,IAAI,EAAE,GAAG;gBACT,SAAS,EAAE,gBAAgB;gBAC3B,OAAO,EAA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EAAE,GAAG,KAAK,CAAA;gBAC3B,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;gBAEnC,IAAI,CAAC,KAAK,EAAE;oBACV,OAAO,KAAK,CAAA;iBACb;gBAED,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,GAAG;oBACnD,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;wBAChC,SAAS,GAAG,IAAI,CAAA;wBAChB,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;wBAE3E,OAAO,KAAK,CAAA;qBACb;iBACF,CAAC,CAAA;gBAEF,OAAO,SAAS,CAAA;aACjB,CAAC;SACH,CAAA;KACF;IAED,qBAAqB;QACnB,OAAO;YACL,UAAU,CAAC;gBACT,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU;aAC3B,CAAC;SACH,CAAA;KACF;CACF;;;;"}
@@ -89,14 +89,14 @@
89
89
  parseHTML() {
90
90
  return [
91
91
  {
92
- tag: 'span[data-mention]',
92
+ tag: `span[data-type="${this.name}"]`,
93
93
  },
94
94
  ];
95
95
  },
96
96
  renderHTML({ node, HTMLAttributes }) {
97
97
  return [
98
98
  'span',
99
- core.mergeAttributes({ 'data-mention': '' }, this.options.HTMLAttributes, HTMLAttributes),
99
+ core.mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),
100
100
  this.options.renderLabel({
101
101
  options: this.options,
102
102
  node,
@@ -1 +1 @@
1
- {"version":3,"file":"tiptap-extension-mention.umd.js","sources":["../src/mention.ts"],"sourcesContent":["import { Node, mergeAttributes } from '@tiptap/core'\nimport { Node as ProseMirrorNode } from 'prosemirror-model'\nimport { PluginKey } from 'prosemirror-state'\nimport Suggestion, { SuggestionOptions } from '@tiptap/suggestion'\n\nexport type MentionOptions = {\n HTMLAttributes: Record<string, any>,\n renderLabel: (props: {\n options: MentionOptions,\n node: ProseMirrorNode,\n }) => string,\n suggestion: Omit<SuggestionOptions, 'editor'>,\n}\n\nexport const MentionPluginKey = new PluginKey('mention')\n\nexport const Mention = Node.create<MentionOptions>({\n name: 'mention',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n renderLabel({ options, node }) {\n return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`\n },\n suggestion: {\n char: '@',\n pluginKey: MentionPluginKey,\n command: ({ editor, range, props }) => {\n // increase range.to by one when the next node is of type \"text\"\n // and starts with a space character\n const nodeAfter = editor.view.state.selection.$to.nodeAfter\n const overrideSpace = nodeAfter?.text?.startsWith(' ')\n\n if (overrideSpace) {\n range.to += 1\n }\n\n editor\n .chain()\n .focus()\n .insertContentAt(range, [\n {\n type: this.name,\n attrs: props,\n },\n {\n type: 'text',\n text: ' ',\n },\n ])\n .run()\n },\n allow: ({ editor, range }) => {\n const $from = editor.state.doc.resolve(range.from)\n const type = editor.schema.nodes[this.name]\n const allow = !!$from.parent.type.contentMatch.matchType(type)\n\n return allow\n },\n },\n }\n },\n\n group: 'inline',\n\n inline: true,\n\n selectable: false,\n\n atom: true,\n\n addAttributes() {\n return {\n id: {\n default: null,\n parseHTML: element => element.getAttribute('data-id'),\n renderHTML: attributes => {\n if (!attributes.id) {\n return {}\n }\n\n return {\n 'data-id': attributes.id,\n }\n },\n },\n\n label: {\n default: null,\n parseHTML: element => element.getAttribute('data-label'),\n renderHTML: attributes => {\n if (!attributes.label) {\n return {}\n }\n\n return {\n 'data-label': attributes.label,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'span[data-mention]',\n },\n ]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n return [\n 'span',\n mergeAttributes({ 'data-mention': '' }, this.options.HTMLAttributes, HTMLAttributes),\n this.options.renderLabel({\n options: this.options,\n node,\n }),\n ]\n },\n\n renderText({ node }) {\n return this.options.renderLabel({\n options: this.options,\n node,\n })\n },\n\n addKeyboardShortcuts() {\n return {\n Backspace: () => this.editor.commands.command(({ tr, state }) => {\n let isMention = false\n const { selection } = state\n const { empty, anchor } = selection\n\n if (!empty) {\n return false\n }\n\n state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {\n if (node.type.name === this.name) {\n isMention = true\n tr.insertText(this.options.suggestion.char || '', pos, pos + node.nodeSize)\n\n return false\n }\n })\n\n return isMention\n }),\n }\n },\n\n addProseMirrorPlugins() {\n return [\n Suggestion({\n editor: this.editor,\n ...this.options.suggestion,\n }),\n ]\n },\n})\n"],"names":["PluginKey","Node","mergeAttributes","Suggestion"],"mappings":";;;;;;;;;;QAca,gBAAgB,GAAG,IAAIA,0BAAS,CAAC,SAAS,EAAC;QAE3C,OAAO,GAAGC,SAAI,CAAC,MAAM,CAAiB;MACjD,IAAI,EAAE,SAAS;MAEf,UAAU;UACR,OAAO;cACL,cAAc,EAAE,EAAE;cAClB,WAAW,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE;;kBAC3B,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,MAAA,IAAI,CAAC,KAAK,CAAC,KAAK,mCAAI,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAA;eACxE;cACD,UAAU,EAAE;kBACV,IAAI,EAAE,GAAG;kBACT,SAAS,EAAE,gBAAgB;kBAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE;;;;sBAGhC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAA;sBAC3D,MAAM,aAAa,GAAG,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,0CAAE,UAAU,CAAC,GAAG,CAAC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AI,KAAK,IAAI,CAAC,IAAI,EAAE;0BAChC,SAAS,GAAG,IAAI,CAAA;0BAChB,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;0BAE3E,OAAO,KAAK,CAAA;uBACb;mBACF,CAAC,CAAA;kBAEF,OAAO,SAAS,CAAA;eACjB,CAAC;WACH,CAAA;OACF;MAED,qBAAqB;UACnB,OAAO;cACLC,8BAAU,CAAC;kBACT,MAAM,EAAE,IAAI,CAAC,MAAM;kBACnB,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU;eAC3B,CAAC;WACH,CAAA;OACF;GACF;;;;;;;;;;;;"}
1
+ {"version":3,"file":"tiptap-extension-mention.umd.js","sources":["../src/mention.ts"],"sourcesContent":["import { Node, mergeAttributes } from '@tiptap/core'\nimport { Node as ProseMirrorNode } from 'prosemirror-model'\nimport { PluginKey } from 'prosemirror-state'\nimport Suggestion, { SuggestionOptions } from '@tiptap/suggestion'\n\nexport type MentionOptions = {\n HTMLAttributes: Record<string, any>,\n renderLabel: (props: {\n options: MentionOptions,\n node: ProseMirrorNode,\n }) => string,\n suggestion: Omit<SuggestionOptions, 'editor'>,\n}\n\nexport const MentionPluginKey = new PluginKey('mention')\n\nexport const Mention = Node.create<MentionOptions>({\n name: 'mention',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n renderLabel({ options, node }) {\n return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`\n },\n suggestion: {\n char: '@',\n pluginKey: MentionPluginKey,\n command: ({ editor, range, props }) => {\n // increase range.to by one when the next node is of type \"text\"\n // and starts with a space character\n const nodeAfter = editor.view.state.selection.$to.nodeAfter\n const overrideSpace = nodeAfter?.text?.startsWith(' ')\n\n if (overrideSpace) {\n range.to += 1\n }\n\n editor\n .chain()\n .focus()\n .insertContentAt(range, [\n {\n type: this.name,\n attrs: props,\n },\n {\n type: 'text',\n text: ' ',\n },\n ])\n .run()\n },\n allow: ({ editor, range }) => {\n const $from = editor.state.doc.resolve(range.from)\n const type = editor.schema.nodes[this.name]\n const allow = !!$from.parent.type.contentMatch.matchType(type)\n\n return allow\n },\n },\n }\n },\n\n group: 'inline',\n\n inline: true,\n\n selectable: false,\n\n atom: true,\n\n addAttributes() {\n return {\n id: {\n default: null,\n parseHTML: element => element.getAttribute('data-id'),\n renderHTML: attributes => {\n if (!attributes.id) {\n return {}\n }\n\n return {\n 'data-id': attributes.id,\n }\n },\n },\n\n label: {\n default: null,\n parseHTML: element => element.getAttribute('data-label'),\n renderHTML: attributes => {\n if (!attributes.label) {\n return {}\n }\n\n return {\n 'data-label': attributes.label,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: `span[data-type=\"${this.name}\"]`,\n },\n ]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n return [\n 'span',\n mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),\n this.options.renderLabel({\n options: this.options,\n node,\n }),\n ]\n },\n\n renderText({ node }) {\n return this.options.renderLabel({\n options: this.options,\n node,\n })\n },\n\n addKeyboardShortcuts() {\n return {\n Backspace: () => this.editor.commands.command(({ tr, state }) => {\n let isMention = false\n const { selection } = state\n const { empty, anchor } = selection\n\n if (!empty) {\n return false\n }\n\n state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {\n if (node.type.name === this.name) {\n isMention = true\n tr.insertText(this.options.suggestion.char || '', pos, pos + node.nodeSize)\n\n return false\n }\n })\n\n return isMention\n }),\n }\n },\n\n addProseMirrorPlugins() {\n return [\n Suggestion({\n editor: this.editor,\n ...this.options.suggestion,\n }),\n ]\n },\n})\n"],"names":["PluginKey","Node","mergeAttributes","Suggestion"],"mappings":";;;;;;;;;;QAca,gBAAgB,GAAG,IAAIA,0BAAS,CAAC,SAAS,EAAC;QAE3C,OAAO,GAAGC,SAAI,CAAC,MAAM,CAAiB;M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F;MAED,UAAU,CAAC,EAAE,IAAI,EAAE;UACjB,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;cAC9B,OAAO,EAAE,IAAI,CAAC,OAAO;cACrB,IAAI;WACL,CAAC,CAAA;OACH;MAED,oBAAoB;UAClB,OAAO;cACL,SAAS,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE;kBAC1D,IAAI,SAAS,GAAG,KAAK,CAAA;kBACrB,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAA;kBAC3B,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;kBAEnC,IAAI,CAAC,KAAK,EAAE;sBACV,OAAO,KAAK,CAAA;mBACb;kBAED,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,GAAG;sBACnD,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;0BAChC,SAAS,GAAG,IAAI,CAAA;0BAChB,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;0BAE3E,OAAO,KAAK,CAAA;uBACb;mBACF,CAAC,CAAA;kBAEF,OAAO,SAAS,CAAA;eACjB,CAAC;WACH,CAAA;OACF;MAED,qBAAqB;UACnB,OAAO;cACLC,8BAAU,CAAC;kBACT,MAAM,EAAE,IAAI,CAAC,MAAM;kBACnB,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU;eAC3B,CAAC;WACH,CAAA;OACF;GACF;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/extension-mention",
3
3
  "description": "mention extension for tiptap",
4
- "version": "2.0.0-beta.83",
4
+ "version": "2.0.0-beta.88",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -24,7 +24,7 @@
24
24
  "@tiptap/core": "^2.0.0-beta.1"
25
25
  },
26
26
  "dependencies": {
27
- "@tiptap/suggestion": "^2.0.0-beta.79",
27
+ "@tiptap/suggestion": "^2.0.0-beta.83",
28
28
  "prosemirror-model": "^1.15.0",
29
29
  "prosemirror-state": "^1.3.4"
30
30
  },
@@ -33,5 +33,5 @@
33
33
  "url": "https://github.com/ueberdosis/tiptap",
34
34
  "directory": "packages/extension-mention"
35
35
  },
36
- "gitHead": "926cfcd6025c6a333ed0b53b9a687c238a9a69b3"
36
+ "gitHead": "270543995c92243fc27c4a688af6a93033fb4b7e"
37
37
  }
package/src/mention.ts CHANGED
@@ -105,7 +105,7 @@ export const Mention = Node.create<MentionOptions>({
105
105
  parseHTML() {
106
106
  return [
107
107
  {
108
- tag: 'span[data-mention]',
108
+ tag: `span[data-type="${this.name}"]`,
109
109
  },
110
110
  ]
111
111
  },
@@ -113,7 +113,7 @@ export const Mention = Node.create<MentionOptions>({
113
113
  renderHTML({ node, HTMLAttributes }) {
114
114
  return [
115
115
  'span',
116
- mergeAttributes({ 'data-mention': '' }, this.options.HTMLAttributes, HTMLAttributes),
116
+ mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),
117
117
  this.options.renderLabel({
118
118
  options: this.options,
119
119
  node,