@tiptap/extension-mention 2.0.0-beta.91 → 2.0.0-beta.95
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.
- package/dist/tiptap-extension-mention.cjs.js +3 -3
- package/dist/tiptap-extension-mention.cjs.js.map +1 -1
- package/dist/tiptap-extension-mention.esm.js +3 -3
- package/dist/tiptap-extension-mention.esm.js.map +1 -1
- package/dist/tiptap-extension-mention.umd.js +3 -3
- package/dist/tiptap-extension-mention.umd.js.map +1 -1
- package/package.json +3 -3
- package/src/mention.ts +3 -3
|
@@ -47,9 +47,9 @@ const Mention = core.Node.create({
|
|
|
47
47
|
])
|
|
48
48
|
.run();
|
|
49
49
|
},
|
|
50
|
-
allow: ({
|
|
51
|
-
const $from =
|
|
52
|
-
const type =
|
|
50
|
+
allow: ({ state, range }) => {
|
|
51
|
+
const $from = state.doc.resolve(range.from);
|
|
52
|
+
const type = state.schema.nodes[this.name];
|
|
53
53
|
const allow = !!$from.parent.type.contentMatch.matchType(type);
|
|
54
54
|
return allow;
|
|
55
55
|
},
|
|
@@ -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: ({
|
|
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: ({ state, range }) => {\n const $from = state.doc.resolve(range.from)\n const type = state.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,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,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;;;;;;"}
|
|
@@ -39,9 +39,9 @@ const Mention = Node.create({
|
|
|
39
39
|
])
|
|
40
40
|
.run();
|
|
41
41
|
},
|
|
42
|
-
allow: ({
|
|
43
|
-
const $from =
|
|
44
|
-
const type =
|
|
42
|
+
allow: ({ state, range }) => {
|
|
43
|
+
const $from = state.doc.resolve(range.from);
|
|
44
|
+
const type = state.schema.nodes[this.name];
|
|
45
45
|
const allow = !!$from.parent.type.contentMatch.matchType(type);
|
|
46
46
|
return allow;
|
|
47
47
|
},
|
|
@@ -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: ({
|
|
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: ({ state, range }) => {\n const $from = state.doc.resolve(range.from)\n const type = state.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,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;qBACF,CAAC;yBACD,GAAG,EAAE,CAAA;iB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F;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;;;;"}
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
])
|
|
46
46
|
.run();
|
|
47
47
|
},
|
|
48
|
-
allow: ({
|
|
49
|
-
const $from =
|
|
50
|
-
const type =
|
|
48
|
+
allow: ({ state, range }) => {
|
|
49
|
+
const $from = state.doc.resolve(range.from);
|
|
50
|
+
const type = state.schema.nodes[this.name];
|
|
51
51
|
const allow = !!$from.parent.type.contentMatch.matchType(type);
|
|
52
52
|
return allow;
|
|
53
53
|
},
|
|
@@ -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: ({
|
|
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: ({ state, range }) => {\n const $from = state.doc.resolve(range.from)\n const type = state.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;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,GA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;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.
|
|
4
|
+
"version": "2.0.0-beta.95",
|
|
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.
|
|
27
|
+
"@tiptap/suggestion": "^2.0.0-beta.90",
|
|
28
28
|
"prosemirror-model": "^1.16.1",
|
|
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": "
|
|
36
|
+
"gitHead": "82759a898a77aa0bf6a459178021e86b6713ef39"
|
|
37
37
|
}
|
package/src/mention.ts
CHANGED
|
@@ -51,9 +51,9 @@ export const Mention = Node.create<MentionOptions>({
|
|
|
51
51
|
])
|
|
52
52
|
.run()
|
|
53
53
|
},
|
|
54
|
-
allow: ({
|
|
55
|
-
const $from =
|
|
56
|
-
const type =
|
|
54
|
+
allow: ({ state, range }) => {
|
|
55
|
+
const $from = state.doc.resolve(range.from)
|
|
56
|
+
const type = state.schema.nodes[this.name]
|
|
57
57
|
const allow = !!$from.parent.type.contentMatch.matchType(type)
|
|
58
58
|
|
|
59
59
|
return allow
|