@tiptap/extension-mention 2.0.0-beta.77 → 2.0.0-beta.80

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.
@@ -11,4 +11,4 @@ export declare type MentionOptions = {
11
11
  suggestion: Omit<SuggestionOptions, 'editor'>;
12
12
  };
13
13
  export declare const MentionPluginKey: PluginKey<any, any>;
14
- export declare const Mention: Node<MentionOptions>;
14
+ export declare const Mention: Node<MentionOptions, any>;
@@ -13,43 +13,48 @@ var Suggestion__default = /*#__PURE__*/_interopDefaultLegacy(Suggestion);
13
13
  const MentionPluginKey = new prosemirrorState.PluginKey('mention');
14
14
  const Mention = core.Node.create({
15
15
  name: 'mention',
16
- defaultOptions: {
17
- HTMLAttributes: {},
18
- renderLabel({ options, node }) {
19
- var _a;
20
- return `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`;
21
- },
22
- suggestion: {
23
- char: '@',
24
- pluginKey: MentionPluginKey,
25
- command: ({ editor, range, props }) => {
16
+ addOptions() {
17
+ return {
18
+ HTMLAttributes: {},
19
+ renderLabel({ options, node }) {
26
20
  var _a;
27
- // increase range.to by one when the next node is of type "text"
28
- // and starts with a space character
29
- const nodeAfter = editor.view.state.selection.$to.nodeAfter;
30
- const overrideSpace = (_a = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.text) === null || _a === void 0 ? void 0 : _a.startsWith(' ');
31
- if (overrideSpace) {
32
- range.to += 1;
33
- }
34
- editor
35
- .chain()
36
- .focus()
37
- .insertContentAt(range, [
38
- {
39
- type: 'mention',
40
- attrs: props,
41
- },
42
- {
43
- type: 'text',
44
- text: ' ',
45
- },
46
- ])
47
- .run();
21
+ return `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`;
48
22
  },
49
- allow: ({ editor, range }) => {
50
- return editor.can().insertContentAt(range, { type: 'mention' });
23
+ suggestion: {
24
+ char: '@',
25
+ pluginKey: MentionPluginKey,
26
+ command: ({ editor, range, props }) => {
27
+ var _a;
28
+ // increase range.to by one when the next node is of type "text"
29
+ // and starts with a space character
30
+ const nodeAfter = editor.view.state.selection.$to.nodeAfter;
31
+ const overrideSpace = (_a = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.text) === null || _a === void 0 ? void 0 : _a.startsWith(' ');
32
+ if (overrideSpace) {
33
+ range.to += 1;
34
+ }
35
+ editor
36
+ .chain()
37
+ .focus()
38
+ .insertContentAt(range, [
39
+ {
40
+ type: this.name,
41
+ attrs: props,
42
+ },
43
+ {
44
+ type: 'text',
45
+ text: ' ',
46
+ },
47
+ ])
48
+ .run();
49
+ },
50
+ allow: ({ editor, range }) => {
51
+ const $from = editor.state.doc.resolve(range.from);
52
+ const type = editor.schema.nodes[this.name];
53
+ const allow = !!$from.parent.type.contentMatch.matchType(type);
54
+ return allow;
55
+ },
51
56
  },
52
- },
57
+ };
53
58
  },
54
59
  group: 'inline',
55
60
  inline: true,
@@ -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 defaultOptions: {\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: 'mention',\n attrs: props,\n },\n {\n type: 'text',\n text: ' ',\n },\n ])\n .run()\n },\n allow: ({ editor, range }) => {\n return editor.can().insertContentAt(range, { type: 'mention' })\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,IAA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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;;;;;;"}
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;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,KAA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AE3E,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;;;;;;"}
@@ -5,43 +5,48 @@ import Suggestion from '@tiptap/suggestion';
5
5
  const MentionPluginKey = new PluginKey('mention');
6
6
  const Mention = Node.create({
7
7
  name: 'mention',
8
- defaultOptions: {
9
- HTMLAttributes: {},
10
- renderLabel({ options, node }) {
11
- var _a;
12
- return `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`;
13
- },
14
- suggestion: {
15
- char: '@',
16
- pluginKey: MentionPluginKey,
17
- command: ({ editor, range, props }) => {
8
+ addOptions() {
9
+ return {
10
+ HTMLAttributes: {},
11
+ renderLabel({ options, node }) {
18
12
  var _a;
19
- // increase range.to by one when the next node is of type "text"
20
- // and starts with a space character
21
- const nodeAfter = editor.view.state.selection.$to.nodeAfter;
22
- const overrideSpace = (_a = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.text) === null || _a === void 0 ? void 0 : _a.startsWith(' ');
23
- if (overrideSpace) {
24
- range.to += 1;
25
- }
26
- editor
27
- .chain()
28
- .focus()
29
- .insertContentAt(range, [
30
- {
31
- type: 'mention',
32
- attrs: props,
33
- },
34
- {
35
- type: 'text',
36
- text: ' ',
37
- },
38
- ])
39
- .run();
13
+ return `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`;
40
14
  },
41
- allow: ({ editor, range }) => {
42
- return editor.can().insertContentAt(range, { type: 'mention' });
15
+ suggestion: {
16
+ char: '@',
17
+ pluginKey: MentionPluginKey,
18
+ command: ({ editor, range, props }) => {
19
+ var _a;
20
+ // increase range.to by one when the next node is of type "text"
21
+ // and starts with a space character
22
+ const nodeAfter = editor.view.state.selection.$to.nodeAfter;
23
+ const overrideSpace = (_a = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.text) === null || _a === void 0 ? void 0 : _a.startsWith(' ');
24
+ if (overrideSpace) {
25
+ range.to += 1;
26
+ }
27
+ editor
28
+ .chain()
29
+ .focus()
30
+ .insertContentAt(range, [
31
+ {
32
+ type: this.name,
33
+ attrs: props,
34
+ },
35
+ {
36
+ type: 'text',
37
+ text: ' ',
38
+ },
39
+ ])
40
+ .run();
41
+ },
42
+ allow: ({ editor, range }) => {
43
+ const $from = editor.state.doc.resolve(range.from);
44
+ const type = editor.schema.nodes[this.name];
45
+ const allow = !!$from.parent.type.contentMatch.matchType(type);
46
+ return allow;
47
+ },
43
48
  },
44
- },
49
+ };
45
50
  },
46
51
  group: 'inline',
47
52
  inline: true,
@@ -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 defaultOptions: {\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: 'mention',\n attrs: props,\n },\n {\n type: 'text',\n text: ' ',\n },\n ])\n .run()\n },\n allow: ({ editor, range }) => {\n return editor.can().insertContentAt(range, { type: 'mention' })\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,cAAc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,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;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-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;qBACF,CAAC;yBACD,GAAG,EAAE,CAAA;iBACT;gBACD,KAAK,EAAE,CAAC,EAAE,MAAM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IAAI,CAAC,MAAM;gBACnB,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU;aAC3B,CAAC;SACH,CAAA;KACF;CACF;;;;"}
@@ -11,43 +11,48 @@
11
11
  const MentionPluginKey = new prosemirrorState.PluginKey('mention');
12
12
  const Mention = core.Node.create({
13
13
  name: 'mention',
14
- defaultOptions: {
15
- HTMLAttributes: {},
16
- renderLabel({ options, node }) {
17
- var _a;
18
- return `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`;
19
- },
20
- suggestion: {
21
- char: '@',
22
- pluginKey: MentionPluginKey,
23
- command: ({ editor, range, props }) => {
14
+ addOptions() {
15
+ return {
16
+ HTMLAttributes: {},
17
+ renderLabel({ options, node }) {
24
18
  var _a;
25
- // increase range.to by one when the next node is of type "text"
26
- // and starts with a space character
27
- const nodeAfter = editor.view.state.selection.$to.nodeAfter;
28
- const overrideSpace = (_a = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.text) === null || _a === void 0 ? void 0 : _a.startsWith(' ');
29
- if (overrideSpace) {
30
- range.to += 1;
31
- }
32
- editor
33
- .chain()
34
- .focus()
35
- .insertContentAt(range, [
36
- {
37
- type: 'mention',
38
- attrs: props,
39
- },
40
- {
41
- type: 'text',
42
- text: ' ',
43
- },
44
- ])
45
- .run();
19
+ return `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`;
46
20
  },
47
- allow: ({ editor, range }) => {
48
- return editor.can().insertContentAt(range, { type: 'mention' });
21
+ suggestion: {
22
+ char: '@',
23
+ pluginKey: MentionPluginKey,
24
+ command: ({ editor, range, props }) => {
25
+ var _a;
26
+ // increase range.to by one when the next node is of type "text"
27
+ // and starts with a space character
28
+ const nodeAfter = editor.view.state.selection.$to.nodeAfter;
29
+ const overrideSpace = (_a = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.text) === null || _a === void 0 ? void 0 : _a.startsWith(' ');
30
+ if (overrideSpace) {
31
+ range.to += 1;
32
+ }
33
+ editor
34
+ .chain()
35
+ .focus()
36
+ .insertContentAt(range, [
37
+ {
38
+ type: this.name,
39
+ attrs: props,
40
+ },
41
+ {
42
+ type: 'text',
43
+ text: ' ',
44
+ },
45
+ ])
46
+ .run();
47
+ },
48
+ allow: ({ editor, range }) => {
49
+ const $from = editor.state.doc.resolve(range.from);
50
+ const type = editor.schema.nodes[this.name];
51
+ const allow = !!$from.parent.type.contentMatch.matchType(type);
52
+ return allow;
53
+ },
49
54
  },
50
- },
55
+ };
51
56
  },
52
57
  group: 'inline',
53
58
  inline: true,
@@ -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 defaultOptions: {\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: 'mention',\n attrs: props,\n },\n {\n type: 'text',\n text: ' ',\n },\n ])\n .run()\n },\n allow: ({ editor, range }) => {\n return editor.can().insertContentAt(range, { type: 'mention' })\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,cAAc,EAAE;UACd,cAAc,EAAE,EAAE;UAClB,WAAW,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE;;cAC3B,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,MAAA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;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;;;;;;;;;;;;"}
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 ]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AA;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.77",
4
+ "version": "2.0.0-beta.80",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -24,8 +24,8 @@
24
24
  "@tiptap/core": "^2.0.0-beta.1"
25
25
  },
26
26
  "dependencies": {
27
- "@tiptap/suggestion": "^2.0.0-beta.74",
28
- "prosemirror-model": "^1.14.3",
27
+ "@tiptap/suggestion": "^2.0.0-beta.76",
28
+ "prosemirror-model": "^1.15.0",
29
29
  "prosemirror-state": "^1.3.4"
30
30
  },
31
31
  "repository": {
@@ -33,5 +33,5 @@
33
33
  "url": "https://github.com/ueberdosis/tiptap",
34
34
  "directory": "packages/extension-mention"
35
35
  },
36
- "gitHead": "9948e2499a3aa6ca72b677ef2ca96de1db1cb6b5"
36
+ "gitHead": "642627ec3635a1d8fa851887d75bee5f193ec63b"
37
37
  }
package/src/mention.ts CHANGED
@@ -17,43 +17,49 @@ export const MentionPluginKey = new PluginKey('mention')
17
17
  export const Mention = Node.create<MentionOptions>({
18
18
  name: 'mention',
19
19
 
20
- defaultOptions: {
21
- HTMLAttributes: {},
22
- renderLabel({ options, node }) {
23
- return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`
24
- },
25
- suggestion: {
26
- char: '@',
27
- pluginKey: MentionPluginKey,
28
- command: ({ editor, range, props }) => {
29
- // increase range.to by one when the next node is of type "text"
30
- // and starts with a space character
31
- const nodeAfter = editor.view.state.selection.$to.nodeAfter
32
- const overrideSpace = nodeAfter?.text?.startsWith(' ')
33
-
34
- if (overrideSpace) {
35
- range.to += 1
36
- }
37
-
38
- editor
39
- .chain()
40
- .focus()
41
- .insertContentAt(range, [
42
- {
43
- type: 'mention',
44
- attrs: props,
45
- },
46
- {
47
- type: 'text',
48
- text: ' ',
49
- },
50
- ])
51
- .run()
20
+ addOptions() {
21
+ return {
22
+ HTMLAttributes: {},
23
+ renderLabel({ options, node }) {
24
+ return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`
52
25
  },
53
- allow: ({ editor, range }) => {
54
- return editor.can().insertContentAt(range, { type: 'mention' })
26
+ suggestion: {
27
+ char: '@',
28
+ pluginKey: MentionPluginKey,
29
+ command: ({ editor, range, props }) => {
30
+ // increase range.to by one when the next node is of type "text"
31
+ // and starts with a space character
32
+ const nodeAfter = editor.view.state.selection.$to.nodeAfter
33
+ const overrideSpace = nodeAfter?.text?.startsWith(' ')
34
+
35
+ if (overrideSpace) {
36
+ range.to += 1
37
+ }
38
+
39
+ editor
40
+ .chain()
41
+ .focus()
42
+ .insertContentAt(range, [
43
+ {
44
+ type: this.name,
45
+ attrs: props,
46
+ },
47
+ {
48
+ type: 'text',
49
+ text: ' ',
50
+ },
51
+ ])
52
+ .run()
53
+ },
54
+ allow: ({ editor, range }) => {
55
+ const $from = editor.state.doc.resolve(range.from)
56
+ const type = editor.schema.nodes[this.name]
57
+ const allow = !!$from.parent.type.contentMatch.matchType(type)
58
+
59
+ return allow
60
+ },
55
61
  },
56
- },
62
+ }
57
63
  },
58
64
 
59
65
  group: 'inline',