@tiptap/extension-mention 2.6.2 → 3.0.0-next.1

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.
Files changed (174) hide show
  1. package/dist/index.cjs +202 -178
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/{packages/extension-mention/src/mention.d.ts → index.d.cts} +12 -9
  4. package/dist/index.d.ts +79 -0
  5. package/dist/index.js +166 -170
  6. package/dist/index.js.map +1 -1
  7. package/package.json +10 -12
  8. package/dist/index.umd.js +0 -187
  9. package/dist/index.umd.js.map +0 -1
  10. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  11. package/dist/packages/core/src/Editor.d.ts +0 -163
  12. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  13. package/dist/packages/core/src/Extension.d.ts +0 -344
  14. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  15. package/dist/packages/core/src/InputRule.d.ts +0 -42
  16. package/dist/packages/core/src/Mark.d.ts +0 -452
  17. package/dist/packages/core/src/Node.d.ts +0 -612
  18. package/dist/packages/core/src/NodePos.d.ts +0 -44
  19. package/dist/packages/core/src/NodeView.d.ts +0 -31
  20. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  21. package/dist/packages/core/src/Tracker.d.ts +0 -11
  22. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  23. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  24. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  25. package/dist/packages/core/src/commands/command.d.ts +0 -18
  26. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  27. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  28. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  29. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  30. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  31. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  32. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  33. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  34. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  35. package/dist/packages/core/src/commands/first.d.ts +0 -14
  36. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  37. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  38. package/dist/packages/core/src/commands/index.d.ts +0 -55
  39. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  40. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  41. package/dist/packages/core/src/commands/join.d.ts +0 -41
  42. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  43. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  44. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  45. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  46. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  47. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  48. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  49. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  50. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  51. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  52. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  53. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  54. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  55. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  56. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  57. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  58. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  59. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  60. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  61. package/dist/packages/core/src/commands/setMeta.d.ts +0 -16
  62. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  63. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  64. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  65. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  66. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  67. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -16
  68. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  69. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  70. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  71. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  72. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  73. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  74. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  75. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  76. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  77. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  78. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  79. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  80. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  81. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  82. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  83. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  84. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  85. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  86. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  87. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  88. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  89. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  90. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  91. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  92. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  93. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  94. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  95. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  96. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  97. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  98. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  99. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  100. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  101. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  102. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  103. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  104. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  105. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  106. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  107. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  108. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  109. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  110. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  111. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  112. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  113. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  114. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  115. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  116. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  117. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  118. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  119. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  120. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  121. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  122. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  123. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  124. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  125. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  126. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  127. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  128. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  129. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -14
  130. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  131. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  132. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  133. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  134. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  135. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  136. package/dist/packages/core/src/index.d.ts +0 -24
  137. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  138. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  139. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  140. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  141. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  142. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  143. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  144. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  145. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -14
  146. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  147. package/dist/packages/core/src/style.d.ts +0 -1
  148. package/dist/packages/core/src/types.d.ts +0 -253
  149. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  150. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  151. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  152. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  153. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  154. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  155. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  156. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  157. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  158. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  159. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  160. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  161. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  162. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  163. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  164. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  165. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  166. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  167. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  168. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  169. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  170. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  171. package/dist/packages/extension-mention/src/index.d.ts +0 -3
  172. package/dist/packages/suggestion/src/findSuggestionMatch.d.ts +0 -15
  173. package/dist/packages/suggestion/src/index.d.ts +0 -4
  174. package/dist/packages/suggestion/src/suggestion.d.ts +0 -153
package/dist/index.cjs CHANGED
@@ -1,189 +1,213 @@
1
- 'use strict';
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
29
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var core = require('@tiptap/core');
6
- var state = require('@tiptap/pm/state');
7
- var Suggestion = require('@tiptap/suggestion');
8
-
9
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
10
-
11
- var Suggestion__default = /*#__PURE__*/_interopDefaultCompat(Suggestion);
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ Mention: () => Mention,
34
+ MentionPluginKey: () => MentionPluginKey,
35
+ default: () => src_default
36
+ });
37
+ module.exports = __toCommonJS(src_exports);
12
38
 
13
- /**
14
- * The plugin key for the mention plugin.
15
- * @default 'mention'
16
- */
17
- const MentionPluginKey = new state.PluginKey('mention');
18
- /**
19
- * This extension allows you to insert mentions into the editor.
20
- * @see https://www.tiptap.dev/api/extensions/mention
21
- */
22
- const Mention = core.Node.create({
23
- name: 'mention',
24
- addOptions() {
25
- return {
26
- HTMLAttributes: {},
27
- renderText({ options, node }) {
28
- var _a;
29
- return `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`;
30
- },
31
- deleteTriggerWithBackspace: false,
32
- renderHTML({ options, node }) {
33
- var _a;
34
- return [
35
- 'span',
36
- core.mergeAttributes(this.HTMLAttributes, options.HTMLAttributes),
37
- `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`,
38
- ];
39
- },
40
- suggestion: {
41
- char: '@',
42
- pluginKey: MentionPluginKey,
43
- command: ({ editor, range, props }) => {
44
- var _a, _b;
45
- // increase range.to by one when the next node is of type "text"
46
- // and starts with a space character
47
- const nodeAfter = editor.view.state.selection.$to.nodeAfter;
48
- const overrideSpace = (_a = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.text) === null || _a === void 0 ? void 0 : _a.startsWith(' ');
49
- if (overrideSpace) {
50
- range.to += 1;
51
- }
52
- editor
53
- .chain()
54
- .focus()
55
- .insertContentAt(range, [
56
- {
57
- type: this.name,
58
- attrs: props,
59
- },
60
- {
61
- type: 'text',
62
- text: ' ',
63
- },
64
- ])
65
- .run();
66
- (_b = window.getSelection()) === null || _b === void 0 ? void 0 : _b.collapseToEnd();
67
- },
68
- allow: ({ state, range }) => {
69
- const $from = state.doc.resolve(range.from);
70
- const type = state.schema.nodes[this.name];
71
- const allow = !!$from.parent.type.contentMatch.matchType(type);
72
- return allow;
73
- },
74
- },
75
- };
76
- },
77
- group: 'inline',
78
- inline: true,
79
- selectable: false,
80
- atom: true,
81
- addAttributes() {
82
- return {
83
- id: {
84
- default: null,
85
- parseHTML: element => element.getAttribute('data-id'),
86
- renderHTML: attributes => {
87
- if (!attributes.id) {
88
- return {};
89
- }
90
- return {
91
- 'data-id': attributes.id,
92
- };
93
- },
94
- },
95
- label: {
96
- default: null,
97
- parseHTML: element => element.getAttribute('data-label'),
98
- renderHTML: attributes => {
99
- if (!attributes.label) {
100
- return {};
101
- }
102
- return {
103
- 'data-label': attributes.label,
104
- };
105
- },
106
- },
107
- };
108
- },
109
- parseHTML() {
39
+ // src/mention.ts
40
+ var import_core = require("@tiptap/core");
41
+ var import_state = require("@tiptap/pm/state");
42
+ var import_suggestion = __toESM(require("@tiptap/suggestion"), 1);
43
+ var MentionPluginKey = new import_state.PluginKey("mention");
44
+ var Mention = import_core.Node.create({
45
+ name: "mention",
46
+ addOptions() {
47
+ return {
48
+ HTMLAttributes: {},
49
+ renderText({ options, node }) {
50
+ var _a;
51
+ return `${options.suggestion.char}${(_a = node.attrs.label) != null ? _a : node.attrs.id}`;
52
+ },
53
+ deleteTriggerWithBackspace: false,
54
+ renderHTML({ options, node }) {
55
+ var _a;
110
56
  return [
57
+ "span",
58
+ (0, import_core.mergeAttributes)(this.HTMLAttributes, options.HTMLAttributes),
59
+ `${options.suggestion.char}${(_a = node.attrs.label) != null ? _a : node.attrs.id}`
60
+ ];
61
+ },
62
+ suggestion: {
63
+ char: "@",
64
+ pluginKey: MentionPluginKey,
65
+ command: ({ editor, range, props }) => {
66
+ var _a, _b;
67
+ const nodeAfter = editor.view.state.selection.$to.nodeAfter;
68
+ const overrideSpace = (_a = nodeAfter == null ? void 0 : nodeAfter.text) == null ? void 0 : _a.startsWith(" ");
69
+ if (overrideSpace) {
70
+ range.to += 1;
71
+ }
72
+ editor.chain().focus().insertContentAt(range, [
111
73
  {
112
- tag: `span[data-type="${this.name}"]`,
74
+ type: this.name,
75
+ attrs: props
113
76
  },
114
- ];
115
- },
116
- renderHTML({ node, HTMLAttributes }) {
117
- if (this.options.renderLabel !== undefined) {
118
- console.warn('renderLabel is deprecated use renderText and renderHTML instead');
119
- return [
120
- 'span',
121
- core.mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),
122
- this.options.renderLabel({
123
- options: this.options,
124
- node,
125
- }),
126
- ];
77
+ {
78
+ type: "text",
79
+ text: " "
80
+ }
81
+ ]).run();
82
+ (_b = window.getSelection()) == null ? void 0 : _b.collapseToEnd();
83
+ },
84
+ allow: ({ state, range }) => {
85
+ const $from = state.doc.resolve(range.from);
86
+ const type = state.schema.nodes[this.name];
87
+ const allow = !!$from.parent.type.contentMatch.matchType(type);
88
+ return allow;
127
89
  }
128
- const mergedOptions = { ...this.options };
129
- mergedOptions.HTMLAttributes = core.mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes);
130
- const html = this.options.renderHTML({
131
- options: mergedOptions,
132
- node,
133
- });
134
- if (typeof html === 'string') {
135
- return [
136
- 'span',
137
- core.mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),
138
- html,
139
- ];
90
+ }
91
+ };
92
+ },
93
+ group: "inline",
94
+ inline: true,
95
+ selectable: false,
96
+ atom: true,
97
+ addAttributes() {
98
+ return {
99
+ id: {
100
+ default: null,
101
+ parseHTML: (element) => element.getAttribute("data-id"),
102
+ renderHTML: (attributes) => {
103
+ if (!attributes.id) {
104
+ return {};
105
+ }
106
+ return {
107
+ "data-id": attributes.id
108
+ };
140
109
  }
141
- return html;
142
- },
143
- renderText({ node }) {
144
- if (this.options.renderLabel !== undefined) {
145
- console.warn('renderLabel is deprecated use renderText and renderHTML instead');
146
- return this.options.renderLabel({
147
- options: this.options,
148
- node,
149
- });
110
+ },
111
+ label: {
112
+ default: null,
113
+ parseHTML: (element) => element.getAttribute("data-label"),
114
+ renderHTML: (attributes) => {
115
+ if (!attributes.label) {
116
+ return {};
117
+ }
118
+ return {
119
+ "data-label": attributes.label
120
+ };
150
121
  }
151
- return this.options.renderText({
152
- options: this.options,
153
- node,
122
+ }
123
+ };
124
+ },
125
+ parseHTML() {
126
+ return [
127
+ {
128
+ tag: `span[data-type="${this.name}"]`
129
+ }
130
+ ];
131
+ },
132
+ renderHTML({ node, HTMLAttributes }) {
133
+ if (this.options.renderLabel !== void 0) {
134
+ console.warn("renderLabel is deprecated use renderText and renderHTML instead");
135
+ return [
136
+ "span",
137
+ (0, import_core.mergeAttributes)({ "data-type": this.name }, this.options.HTMLAttributes, HTMLAttributes),
138
+ this.options.renderLabel({
139
+ options: this.options,
140
+ node
141
+ })
142
+ ];
143
+ }
144
+ const mergedOptions = { ...this.options };
145
+ mergedOptions.HTMLAttributes = (0, import_core.mergeAttributes)({ "data-type": this.name }, this.options.HTMLAttributes, HTMLAttributes);
146
+ const html = this.options.renderHTML({
147
+ options: mergedOptions,
148
+ node
149
+ });
150
+ if (typeof html === "string") {
151
+ return [
152
+ "span",
153
+ (0, import_core.mergeAttributes)({ "data-type": this.name }, this.options.HTMLAttributes, HTMLAttributes),
154
+ html
155
+ ];
156
+ }
157
+ return html;
158
+ },
159
+ renderText({ node }) {
160
+ if (this.options.renderLabel !== void 0) {
161
+ console.warn("renderLabel is deprecated use renderText and renderHTML instead");
162
+ return this.options.renderLabel({
163
+ options: this.options,
164
+ node
165
+ });
166
+ }
167
+ return this.options.renderText({
168
+ options: this.options,
169
+ node
170
+ });
171
+ },
172
+ addKeyboardShortcuts() {
173
+ return {
174
+ Backspace: () => this.editor.commands.command(({ tr, state }) => {
175
+ let isMention = false;
176
+ const { selection } = state;
177
+ const { empty, anchor } = selection;
178
+ if (!empty) {
179
+ return false;
180
+ }
181
+ state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
182
+ if (node.type.name === this.name) {
183
+ isMention = true;
184
+ tr.insertText(
185
+ this.options.deleteTriggerWithBackspace ? "" : this.options.suggestion.char || "",
186
+ pos,
187
+ pos + node.nodeSize
188
+ );
189
+ return false;
190
+ }
154
191
  });
155
- },
156
- addKeyboardShortcuts() {
157
- return {
158
- Backspace: () => this.editor.commands.command(({ tr, state }) => {
159
- let isMention = false;
160
- const { selection } = state;
161
- const { empty, anchor } = selection;
162
- if (!empty) {
163
- return false;
164
- }
165
- state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
166
- if (node.type.name === this.name) {
167
- isMention = true;
168
- tr.insertText(this.options.deleteTriggerWithBackspace ? '' : this.options.suggestion.char || '', pos, pos + node.nodeSize);
169
- return false;
170
- }
171
- });
172
- return isMention;
173
- }),
174
- };
175
- },
176
- addProseMirrorPlugins() {
177
- return [
178
- Suggestion__default.default({
179
- editor: this.editor,
180
- ...this.options.suggestion,
181
- }),
182
- ];
183
- },
192
+ return isMention;
193
+ })
194
+ };
195
+ },
196
+ addProseMirrorPlugins() {
197
+ return [
198
+ (0, import_suggestion.default)({
199
+ editor: this.editor,
200
+ ...this.options.suggestion
201
+ })
202
+ ];
203
+ }
184
204
  });
185
205
 
186
- exports.Mention = Mention;
187
- exports.MentionPluginKey = MentionPluginKey;
188
- exports.default = Mention;
189
- //# sourceMappingURL=index.cjs.map
206
+ // src/index.ts
207
+ var src_default = Mention;
208
+ // Annotate the CommonJS export names for ESM import in node:
209
+ 0 && (module.exports = {
210
+ Mention,
211
+ MentionPluginKey
212
+ });
213
+ //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/mention.ts"],"sourcesContent":["import { mergeAttributes, Node } from '@tiptap/core'\nimport { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { PluginKey } from '@tiptap/pm/state'\nimport Suggestion, { SuggestionOptions } from '@tiptap/suggestion'\n\n// See `addAttributes` below\nexport interface MentionNodeAttrs {\n /**\n * The identifier for the selected item that was mentioned, stored as a `data-id`\n * attribute.\n */\n id: string | null;\n /**\n * The label to be rendered by the editor as the displayed text for this mentioned\n * item, if provided. Stored as a `data-label` attribute. See `renderLabel`.\n */\n label?: string | null;\n}\n\nexport type MentionOptions<SuggestionItem = any, Attrs extends Record<string, any> = MentionNodeAttrs> = {\n /**\n * The HTML attributes for a mention node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * A function to render the label of a mention.\n * @deprecated use renderText and renderHTML instead\n * @param props The render props\n * @returns The label\n * @example ({ options, node }) => `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`\n */\n renderLabel?: (props: { options: MentionOptions<SuggestionItem, Attrs>; node: ProseMirrorNode }) => string\n\n /**\n * A function to render the text of a mention.\n * @param props The render props\n * @returns The text\n * @example ({ options, node }) => `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`\n */\n renderText: (props: { options: MentionOptions<SuggestionItem, Attrs>; node: ProseMirrorNode }) => string\n\n /**\n * A function to render the HTML of a mention.\n * @param props The render props\n * @returns The HTML as a ProseMirror DOM Output Spec\n * @example ({ options, node }) => ['span', { 'data-type': 'mention' }, `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`]\n */\n renderHTML: (props: { options: MentionOptions<SuggestionItem, Attrs>; node: ProseMirrorNode }) => DOMOutputSpec\n\n /**\n * Whether to delete the trigger character with backspace.\n * @default false\n */\n deleteTriggerWithBackspace: boolean\n\n /**\n * The suggestion options.\n * @default {}\n * @example { char: '@', pluginKey: MentionPluginKey, command: ({ editor, range, props }) => { ... } }\n */\n suggestion: Omit<SuggestionOptions<SuggestionItem, Attrs>, 'editor'>\n}\n\n/**\n * The plugin key for the mention plugin.\n * @default 'mention'\n */\nexport const MentionPluginKey = new PluginKey('mention')\n\n/**\n * This extension allows you to insert mentions into the editor.\n * @see https://www.tiptap.dev/api/extensions/mention\n */\nexport const Mention = Node.create<MentionOptions>({\n name: 'mention',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n renderText({ options, node }) {\n return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`\n },\n deleteTriggerWithBackspace: false,\n renderHTML({ options, node }) {\n return [\n 'span',\n mergeAttributes(this.HTMLAttributes, options.HTMLAttributes),\n `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`,\n ]\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 window.getSelection()?.collapseToEnd()\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 if (this.options.renderLabel !== undefined) {\n console.warn('renderLabel is deprecated use renderText and renderHTML instead')\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 const mergedOptions = { ...this.options }\n\n mergedOptions.HTMLAttributes = mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes)\n const html = this.options.renderHTML({\n options: mergedOptions,\n node,\n })\n\n if (typeof html === 'string') {\n return [\n 'span',\n mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),\n html,\n ]\n }\n return html\n },\n\n renderText({ node }) {\n if (this.options.renderLabel !== undefined) {\n console.warn('renderLabel is deprecated use renderText and renderHTML instead')\n return this.options.renderLabel({\n options: this.options,\n node,\n })\n }\n return this.options.renderText({\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(\n this.options.deleteTriggerWithBackspace ? '' : this.options.suggestion.char || '',\n pos,\n pos + node.nodeSize,\n )\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":";;;;;;;;;;;;AAkEA;;;AAGG;MACU,gBAAgB,GAAG,IAAIA,eAAS,CAAC,SAAS,EAAC;AAExD;;;AAGG;AACU,MAAA,OAAO,GAAGC,SAAI,CAAC,MAAM,CAAiB;AACjD,IAAA,IAAI,EAAE,SAAS;IAEf,UAAU,GAAA;QACR,OAAO;AACL,YAAA,cAAc,EAAE,EAAE;AAClB,YAAA,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAA;;gBAC1B,OAAO,CAAA,EAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAA,EAAG,MAAA,IAAI,CAAC,KAAK,CAAC,KAAK,mCAAI,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAA;aACxE;AACD,YAAA,0BAA0B,EAAE,KAAK;AACjC,YAAA,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAA;;gBAC1B,OAAO;oBACL,MAAM;oBACNC,oBAAe,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,cAAc,CAAC;AAC5D,oBAAA,CAAA,EAAG,OAA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wBAAA,OAAO,KAAK,CAAA;qBACb;AACH,iBAAC,CAAC,CAAA;AAEF,gBAAA,OAAO,SAAS,CAAA;AAClB,aAAC,CAAC;SACH,CAAA;KACF;IAED,qBAAqB,GAAA;QACnB,OAAO;AACL,YAAAC,2BAAU,CAAC;gBACT,MAAM,EAAE,IAAI,CAAC,MAAM;AACnB,gBAAA,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU;aAC3B,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;;;"}
1
+ {"version":3,"sources":["../src/index.ts","../src/mention.ts"],"sourcesContent":["import { Mention } from './mention.js'\n\nexport * from './mention.js'\n\nexport default Mention\n","import { mergeAttributes, Node } from '@tiptap/core'\nimport { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { PluginKey } from '@tiptap/pm/state'\nimport Suggestion, { SuggestionOptions } from '@tiptap/suggestion'\n\n// See `addAttributes` below\nexport interface MentionNodeAttrs {\n /**\n * The identifier for the selected item that was mentioned, stored as a `data-id`\n * attribute.\n */\n id: string | null;\n /**\n * The label to be rendered by the editor as the displayed text for this mentioned\n * item, if provided. Stored as a `data-label` attribute. See `renderLabel`.\n */\n label?: string | null;\n}\n\nexport type MentionOptions<SuggestionItem = any, Attrs extends Record<string, any> = MentionNodeAttrs> = {\n /**\n * The HTML attributes for a mention node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * A function to render the label of a mention.\n * @deprecated use renderText and renderHTML instead\n * @param props The render props\n * @returns The label\n * @example ({ options, node }) => `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`\n */\n renderLabel?: (props: { options: MentionOptions<SuggestionItem, Attrs>; node: ProseMirrorNode }) => string\n\n /**\n * A function to render the text of a mention.\n * @param props The render props\n * @returns The text\n * @example ({ options, node }) => `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`\n */\n renderText: (props: { options: MentionOptions<SuggestionItem, Attrs>; node: ProseMirrorNode }) => string\n\n /**\n * A function to render the HTML of a mention.\n * @param props The render props\n * @returns The HTML as a ProseMirror DOM Output Spec\n * @example ({ options, node }) => ['span', { 'data-type': 'mention' }, `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`]\n */\n renderHTML: (props: { options: MentionOptions<SuggestionItem, Attrs>; node: ProseMirrorNode }) => DOMOutputSpec\n\n /**\n * Whether to delete the trigger character with backspace.\n * @default false\n */\n deleteTriggerWithBackspace: boolean\n\n /**\n * The suggestion options.\n * @default {}\n * @example { char: '@', pluginKey: MentionPluginKey, command: ({ editor, range, props }) => { ... } }\n */\n suggestion: Omit<SuggestionOptions<SuggestionItem, Attrs>, 'editor'>\n}\n\n/**\n * The plugin key for the mention plugin.\n * @default 'mention'\n */\nexport const MentionPluginKey = new PluginKey('mention')\n\n/**\n * This extension allows you to insert mentions into the editor.\n * @see https://www.tiptap.dev/api/extensions/mention\n */\nexport const Mention = Node.create<MentionOptions>({\n name: 'mention',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n renderText({ options, node }) {\n return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`\n },\n deleteTriggerWithBackspace: false,\n renderHTML({ options, node }) {\n return [\n 'span',\n mergeAttributes(this.HTMLAttributes, options.HTMLAttributes),\n `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`,\n ]\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 window.getSelection()?.collapseToEnd()\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 if (this.options.renderLabel !== undefined) {\n console.warn('renderLabel is deprecated use renderText and renderHTML instead')\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 const mergedOptions = { ...this.options }\n\n mergedOptions.HTMLAttributes = mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes)\n const html = this.options.renderHTML({\n options: mergedOptions,\n node,\n })\n\n if (typeof html === 'string') {\n return [\n 'span',\n mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),\n html,\n ]\n }\n return html\n },\n\n renderText({ node }) {\n if (this.options.renderLabel !== undefined) {\n console.warn('renderLabel is deprecated use renderText and renderHTML instead')\n return this.options.renderLabel({\n options: this.options,\n node,\n })\n }\n return this.options.renderText({\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(\n this.options.deleteTriggerWithBackspace ? '' : this.options.suggestion.char || '',\n pos,\n pos + node.nodeSize,\n )\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAsC;AAEtC,mBAA0B;AAC1B,wBAA8C;AAmEvC,IAAM,mBAAmB,IAAI,uBAAU,SAAS;AAMhD,IAAM,UAAU,iBAAK,OAAuB;AAAA,EACjD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,gBAAgB,CAAC;AAAA,MACjB,WAAW,EAAE,SAAS,KAAK,GAAG;AAlFpC;AAmFQ,eAAO,GAAG,QAAQ,WAAW,IAAI,IAAG,UAAK,MAAM,UAAX,YAAoB,KAAK,MAAM,EAAE;AAAA,MACvE;AAAA,MACA,4BAA4B;AAAA,MAC5B,WAAW,EAAE,SAAS,KAAK,GAAG;AAtFpC;AAuFQ,eAAO;AAAA,UACL;AAAA,cACA,6BAAgB,KAAK,gBAAgB,QAAQ,cAAc;AAAA,UAC3D,GAAG,QAAQ,WAAW,IAAI,IAAG,UAAK,MAAM,UAAX,YAAoB,KAAK,MAAM,EAAE;AAAA,QAChE;AAAA,MACF;AAAA,MACA,YAAY;AAAA,QACV,MAAM;AAAA,QACN,WAAW;AAAA,QACX,SAAS,CAAC,EAAE,QAAQ,OAAO,MAAM,MAAM;AAhG/C;AAmGU,gBAAM,YAAY,OAAO,KAAK,MAAM,UAAU,IAAI;AAClD,gBAAM,iBAAgB,4CAAW,SAAX,mBAAiB,WAAW;AAElD,cAAI,eAAe;AACjB,kBAAM,MAAM;AAAA,UACd;AAEA,iBACG,MAAM,EACN,MAAM,EACN,gBAAgB,OAAO;AAAA,YACtB;AAAA,cACE,MAAM,KAAK;AAAA,cACX,OAAO;AAAA,YACT;AAAA,YACA;AAAA,cACE,MAAM;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;AAAA,cACD,KAAK,QAAQ,6BAA6B,KAAK,KAAK,QAAQ,WAAW,QAAQ;AAAA,cAC/E;AAAA,cACA,MAAM,KAAK;AAAA,YACb;AAEA,mBAAO;AAAA,UACT;AAAA,QACF,CAAC;AAED,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO;AAAA,UACL,kBAAAA,SAAW;AAAA,QACT,QAAQ,KAAK;AAAA,QACb,GAAG,KAAK,QAAQ;AAAA,MAClB,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;ADnQD,IAAO,cAAQ;","names":["Suggestion"]}
@@ -1,8 +1,9 @@
1
- import { Node } from '@tiptap/core';
2
- import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model';
1
+ import { Node as Node$1 } from '@tiptap/core';
2
+ import { Node, DOMOutputSpec } from '@tiptap/pm/model';
3
3
  import { PluginKey } from '@tiptap/pm/state';
4
4
  import { SuggestionOptions } from '@tiptap/suggestion';
5
- export interface MentionNodeAttrs {
5
+
6
+ interface MentionNodeAttrs {
6
7
  /**
7
8
  * The identifier for the selected item that was mentioned, stored as a `data-id`
8
9
  * attribute.
@@ -14,7 +15,7 @@ export interface MentionNodeAttrs {
14
15
  */
15
16
  label?: string | null;
16
17
  }
17
- export type MentionOptions<SuggestionItem = any, Attrs extends Record<string, any> = MentionNodeAttrs> = {
18
+ type MentionOptions<SuggestionItem = any, Attrs extends Record<string, any> = MentionNodeAttrs> = {
18
19
  /**
19
20
  * The HTML attributes for a mention node.
20
21
  * @default {}
@@ -30,7 +31,7 @@ export type MentionOptions<SuggestionItem = any, Attrs extends Record<string, an
30
31
  */
31
32
  renderLabel?: (props: {
32
33
  options: MentionOptions<SuggestionItem, Attrs>;
33
- node: ProseMirrorNode;
34
+ node: Node;
34
35
  }) => string;
35
36
  /**
36
37
  * A function to render the text of a mention.
@@ -40,7 +41,7 @@ export type MentionOptions<SuggestionItem = any, Attrs extends Record<string, an
40
41
  */
41
42
  renderText: (props: {
42
43
  options: MentionOptions<SuggestionItem, Attrs>;
43
- node: ProseMirrorNode;
44
+ node: Node;
44
45
  }) => string;
45
46
  /**
46
47
  * A function to render the HTML of a mention.
@@ -50,7 +51,7 @@ export type MentionOptions<SuggestionItem = any, Attrs extends Record<string, an
50
51
  */
51
52
  renderHTML: (props: {
52
53
  options: MentionOptions<SuggestionItem, Attrs>;
53
- node: ProseMirrorNode;
54
+ node: Node;
54
55
  }) => DOMOutputSpec;
55
56
  /**
56
57
  * Whether to delete the trigger character with backspace.
@@ -68,9 +69,11 @@ export type MentionOptions<SuggestionItem = any, Attrs extends Record<string, an
68
69
  * The plugin key for the mention plugin.
69
70
  * @default 'mention'
70
71
  */
71
- export declare const MentionPluginKey: PluginKey<any>;
72
+ declare const MentionPluginKey: PluginKey<any>;
72
73
  /**
73
74
  * This extension allows you to insert mentions into the editor.
74
75
  * @see https://www.tiptap.dev/api/extensions/mention
75
76
  */
76
- export declare const Mention: Node<MentionOptions<any, MentionNodeAttrs>, any>;
77
+ declare const Mention: Node$1<MentionOptions<any, MentionNodeAttrs>, any>;
78
+
79
+ export { Mention, type MentionNodeAttrs, type MentionOptions, MentionPluginKey, Mention as default };
@@ -0,0 +1,79 @@
1
+ import { Node as Node$1 } from '@tiptap/core';
2
+ import { Node, DOMOutputSpec } from '@tiptap/pm/model';
3
+ import { PluginKey } from '@tiptap/pm/state';
4
+ import { SuggestionOptions } from '@tiptap/suggestion';
5
+
6
+ interface MentionNodeAttrs {
7
+ /**
8
+ * The identifier for the selected item that was mentioned, stored as a `data-id`
9
+ * attribute.
10
+ */
11
+ id: string | null;
12
+ /**
13
+ * The label to be rendered by the editor as the displayed text for this mentioned
14
+ * item, if provided. Stored as a `data-label` attribute. See `renderLabel`.
15
+ */
16
+ label?: string | null;
17
+ }
18
+ type MentionOptions<SuggestionItem = any, Attrs extends Record<string, any> = MentionNodeAttrs> = {
19
+ /**
20
+ * The HTML attributes for a mention node.
21
+ * @default {}
22
+ * @example { class: 'foo' }
23
+ */
24
+ HTMLAttributes: Record<string, any>;
25
+ /**
26
+ * A function to render the label of a mention.
27
+ * @deprecated use renderText and renderHTML instead
28
+ * @param props The render props
29
+ * @returns The label
30
+ * @example ({ options, node }) => `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`
31
+ */
32
+ renderLabel?: (props: {
33
+ options: MentionOptions<SuggestionItem, Attrs>;
34
+ node: Node;
35
+ }) => string;
36
+ /**
37
+ * A function to render the text of a mention.
38
+ * @param props The render props
39
+ * @returns The text
40
+ * @example ({ options, node }) => `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`
41
+ */
42
+ renderText: (props: {
43
+ options: MentionOptions<SuggestionItem, Attrs>;
44
+ node: Node;
45
+ }) => string;
46
+ /**
47
+ * A function to render the HTML of a mention.
48
+ * @param props The render props
49
+ * @returns The HTML as a ProseMirror DOM Output Spec
50
+ * @example ({ options, node }) => ['span', { 'data-type': 'mention' }, `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`]
51
+ */
52
+ renderHTML: (props: {
53
+ options: MentionOptions<SuggestionItem, Attrs>;
54
+ node: Node;
55
+ }) => DOMOutputSpec;
56
+ /**
57
+ * Whether to delete the trigger character with backspace.
58
+ * @default false
59
+ */
60
+ deleteTriggerWithBackspace: boolean;
61
+ /**
62
+ * The suggestion options.
63
+ * @default {}
64
+ * @example { char: '@', pluginKey: MentionPluginKey, command: ({ editor, range, props }) => { ... } }
65
+ */
66
+ suggestion: Omit<SuggestionOptions<SuggestionItem, Attrs>, 'editor'>;
67
+ };
68
+ /**
69
+ * The plugin key for the mention plugin.
70
+ * @default 'mention'
71
+ */
72
+ declare const MentionPluginKey: PluginKey<any>;
73
+ /**
74
+ * This extension allows you to insert mentions into the editor.
75
+ * @see https://www.tiptap.dev/api/extensions/mention
76
+ */
77
+ declare const Mention: Node$1<MentionOptions<any, MentionNodeAttrs>, any>;
78
+
79
+ export { Mention, type MentionNodeAttrs, type MentionOptions, MentionPluginKey, Mention as default };