@tiptap/extension-mention 2.11.7 → 3.0.0-beta.0

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025, Tiptap GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,14 +1,18 @@
1
1
  # @tiptap/extension-mention
2
+
2
3
  [![Version](https://img.shields.io/npm/v/@tiptap/extension-mention.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-mention)
3
4
  [![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-mention.svg)](https://npmcharts.com/compare/tiptap?minimal=true)
4
5
  [![License](https://img.shields.io/npm/l/@tiptap/extension-mention.svg)](https://www.npmjs.com/package/@tiptap/extension-mention)
5
6
  [![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/ueberdosis)
6
7
 
7
8
  ## Introduction
8
- Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
9
+
10
+ Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as _New York Times_, _The Guardian_ or _Atlassian_.
9
11
 
10
12
  ## Official Documentation
13
+
11
14
  Documentation can be found on the [Tiptap website](https://tiptap.dev).
12
15
 
13
16
  ## License
17
+
14
18
  Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
package/dist/index.cjs CHANGED
@@ -1,191 +1,214 @@
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 index_exports = {};
32
+ __export(index_exports, {
33
+ Mention: () => Mention,
34
+ MentionPluginKey: () => MentionPluginKey,
35
+ default: () => index_default
36
+ });
37
+ module.exports = __toCommonJS(index_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
- priority: 101,
25
- addOptions() {
26
- return {
27
- HTMLAttributes: {},
28
- renderText({ options, node }) {
29
- var _a;
30
- return `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`;
31
- },
32
- deleteTriggerWithBackspace: false,
33
- renderHTML({ options, node }) {
34
- var _a;
35
- return [
36
- 'span',
37
- core.mergeAttributes(this.HTMLAttributes, options.HTMLAttributes),
38
- `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`,
39
- ];
40
- },
41
- suggestion: {
42
- char: '@',
43
- pluginKey: MentionPluginKey,
44
- command: ({ editor, range, props }) => {
45
- var _a, _b, _c;
46
- // increase range.to by one when the next node is of type "text"
47
- // and starts with a space character
48
- const nodeAfter = editor.view.state.selection.$to.nodeAfter;
49
- const overrideSpace = (_a = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.text) === null || _a === void 0 ? void 0 : _a.startsWith(' ');
50
- if (overrideSpace) {
51
- range.to += 1;
52
- }
53
- editor
54
- .chain()
55
- .focus()
56
- .insertContentAt(range, [
57
- {
58
- type: this.name,
59
- attrs: props,
60
- },
61
- {
62
- type: 'text',
63
- text: ' ',
64
- },
65
- ])
66
- .run();
67
- // get reference to `window` object from editor element, to support cross-frame JS usage
68
- (_c = (_b = editor.view.dom.ownerDocument.defaultView) === null || _b === void 0 ? void 0 : _b.getSelection()) === null || _c === void 0 ? void 0 : _c.collapseToEnd();
69
- },
70
- allow: ({ state, range }) => {
71
- const $from = state.doc.resolve(range.from);
72
- const type = state.schema.nodes[this.name];
73
- const allow = !!$from.parent.type.contentMatch.matchType(type);
74
- return allow;
75
- },
76
- },
77
- };
78
- },
79
- group: 'inline',
80
- inline: true,
81
- selectable: false,
82
- atom: true,
83
- addAttributes() {
84
- return {
85
- id: {
86
- default: null,
87
- parseHTML: element => element.getAttribute('data-id'),
88
- renderHTML: attributes => {
89
- if (!attributes.id) {
90
- return {};
91
- }
92
- return {
93
- 'data-id': attributes.id,
94
- };
95
- },
96
- },
97
- label: {
98
- default: null,
99
- parseHTML: element => element.getAttribute('data-label'),
100
- renderHTML: attributes => {
101
- if (!attributes.label) {
102
- return {};
103
- }
104
- return {
105
- 'data-label': attributes.label,
106
- };
107
- },
108
- },
109
- };
110
- },
111
- 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
+ priority: 101,
47
+ addOptions() {
48
+ return {
49
+ HTMLAttributes: {},
50
+ renderText({ options, node }) {
51
+ var _a;
52
+ return `${options.suggestion.char}${(_a = node.attrs.label) != null ? _a : node.attrs.id}`;
53
+ },
54
+ deleteTriggerWithBackspace: false,
55
+ renderHTML({ options, node }) {
56
+ var _a;
112
57
  return [
58
+ "span",
59
+ (0, import_core.mergeAttributes)(this.HTMLAttributes, options.HTMLAttributes),
60
+ `${options.suggestion.char}${(_a = node.attrs.label) != null ? _a : node.attrs.id}`
61
+ ];
62
+ },
63
+ suggestion: {
64
+ char: "@",
65
+ pluginKey: MentionPluginKey,
66
+ command: ({ editor, range, props }) => {
67
+ var _a, _b, _c;
68
+ const nodeAfter = editor.view.state.selection.$to.nodeAfter;
69
+ const overrideSpace = (_a = nodeAfter == null ? void 0 : nodeAfter.text) == null ? void 0 : _a.startsWith(" ");
70
+ if (overrideSpace) {
71
+ range.to += 1;
72
+ }
73
+ editor.chain().focus().insertContentAt(range, [
113
74
  {
114
- tag: `span[data-type="${this.name}"]`,
75
+ type: this.name,
76
+ attrs: props
115
77
  },
116
- ];
117
- },
118
- renderHTML({ node, HTMLAttributes }) {
119
- if (this.options.renderLabel !== undefined) {
120
- console.warn('renderLabel is deprecated use renderText and renderHTML instead');
121
- return [
122
- 'span',
123
- core.mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),
124
- this.options.renderLabel({
125
- options: this.options,
126
- node,
127
- }),
128
- ];
78
+ {
79
+ type: "text",
80
+ text: " "
81
+ }
82
+ ]).run();
83
+ (_c = (_b = editor.view.dom.ownerDocument.defaultView) == null ? void 0 : _b.getSelection()) == null ? void 0 : _c.collapseToEnd();
84
+ },
85
+ allow: ({ state, range }) => {
86
+ const $from = state.doc.resolve(range.from);
87
+ const type = state.schema.nodes[this.name];
88
+ const allow = !!$from.parent.type.contentMatch.matchType(type);
89
+ return allow;
129
90
  }
130
- const mergedOptions = { ...this.options };
131
- mergedOptions.HTMLAttributes = core.mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes);
132
- const html = this.options.renderHTML({
133
- options: mergedOptions,
134
- node,
135
- });
136
- if (typeof html === 'string') {
137
- return [
138
- 'span',
139
- core.mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),
140
- html,
141
- ];
91
+ }
92
+ };
93
+ },
94
+ group: "inline",
95
+ inline: true,
96
+ selectable: false,
97
+ atom: true,
98
+ addAttributes() {
99
+ return {
100
+ id: {
101
+ default: null,
102
+ parseHTML: (element) => element.getAttribute("data-id"),
103
+ renderHTML: (attributes) => {
104
+ if (!attributes.id) {
105
+ return {};
106
+ }
107
+ return {
108
+ "data-id": attributes.id
109
+ };
142
110
  }
143
- return html;
144
- },
145
- renderText({ node }) {
146
- if (this.options.renderLabel !== undefined) {
147
- console.warn('renderLabel is deprecated use renderText and renderHTML instead');
148
- return this.options.renderLabel({
149
- options: this.options,
150
- node,
151
- });
111
+ },
112
+ label: {
113
+ default: null,
114
+ parseHTML: (element) => element.getAttribute("data-label"),
115
+ renderHTML: (attributes) => {
116
+ if (!attributes.label) {
117
+ return {};
118
+ }
119
+ return {
120
+ "data-label": attributes.label
121
+ };
152
122
  }
153
- return this.options.renderText({
154
- options: this.options,
155
- node,
123
+ }
124
+ };
125
+ },
126
+ parseHTML() {
127
+ return [
128
+ {
129
+ tag: `span[data-type="${this.name}"]`
130
+ }
131
+ ];
132
+ },
133
+ renderHTML({ node, HTMLAttributes }) {
134
+ if (this.options.renderLabel !== void 0) {
135
+ console.warn("renderLabel is deprecated use renderText and renderHTML instead");
136
+ return [
137
+ "span",
138
+ (0, import_core.mergeAttributes)({ "data-type": this.name }, this.options.HTMLAttributes, HTMLAttributes),
139
+ this.options.renderLabel({
140
+ options: this.options,
141
+ node
142
+ })
143
+ ];
144
+ }
145
+ const mergedOptions = { ...this.options };
146
+ mergedOptions.HTMLAttributes = (0, import_core.mergeAttributes)(
147
+ { "data-type": this.name },
148
+ this.options.HTMLAttributes,
149
+ HTMLAttributes
150
+ );
151
+ const html = this.options.renderHTML({
152
+ options: mergedOptions,
153
+ node
154
+ });
155
+ if (typeof html === "string") {
156
+ return ["span", (0, import_core.mergeAttributes)({ "data-type": this.name }, this.options.HTMLAttributes, HTMLAttributes), html];
157
+ }
158
+ return html;
159
+ },
160
+ renderText({ node }) {
161
+ if (this.options.renderLabel !== void 0) {
162
+ console.warn("renderLabel is deprecated use renderText and renderHTML instead");
163
+ return this.options.renderLabel({
164
+ options: this.options,
165
+ node
166
+ });
167
+ }
168
+ return this.options.renderText({
169
+ options: this.options,
170
+ node
171
+ });
172
+ },
173
+ addKeyboardShortcuts() {
174
+ return {
175
+ Backspace: () => this.editor.commands.command(({ tr, state }) => {
176
+ let isMention = false;
177
+ const { selection } = state;
178
+ const { empty, anchor } = selection;
179
+ if (!empty) {
180
+ return false;
181
+ }
182
+ state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
183
+ if (node.type.name === this.name) {
184
+ isMention = true;
185
+ tr.insertText(
186
+ this.options.deleteTriggerWithBackspace ? "" : this.options.suggestion.char || "",
187
+ pos,
188
+ pos + node.nodeSize
189
+ );
190
+ return false;
191
+ }
156
192
  });
157
- },
158
- addKeyboardShortcuts() {
159
- return {
160
- Backspace: () => this.editor.commands.command(({ tr, state }) => {
161
- let isMention = false;
162
- const { selection } = state;
163
- const { empty, anchor } = selection;
164
- if (!empty) {
165
- return false;
166
- }
167
- state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
168
- if (node.type.name === this.name) {
169
- isMention = true;
170
- tr.insertText(this.options.deleteTriggerWithBackspace ? '' : this.options.suggestion.char || '', pos, pos + node.nodeSize);
171
- return false;
172
- }
173
- });
174
- return isMention;
175
- }),
176
- };
177
- },
178
- addProseMirrorPlugins() {
179
- return [
180
- Suggestion__default.default({
181
- editor: this.editor,
182
- ...this.options.suggestion,
183
- }),
184
- ];
185
- },
193
+ return isMention;
194
+ })
195
+ };
196
+ },
197
+ addProseMirrorPlugins() {
198
+ return [
199
+ (0, import_suggestion.default)({
200
+ editor: this.editor,
201
+ ...this.options.suggestion
202
+ })
203
+ ];
204
+ }
186
205
  });
187
206
 
188
- exports.Mention = Mention;
189
- exports.MentionPluginKey = MentionPluginKey;
190
- exports.default = Mention;
191
- //# sourceMappingURL=index.cjs.map
207
+ // src/index.ts
208
+ var index_default = Mention;
209
+ // Annotate the CommonJS export names for ESM import in node:
210
+ 0 && (module.exports = {
211
+ Mention,
212
+ MentionPluginKey
213
+ });
214
+ //# 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 priority: 101,\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 // get reference to `window` object from editor element, to support cross-frame JS usage\n editor.view.dom.ownerDocument.defaultView?.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({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,GAAG,KAAK;AACrB,gBAAA,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK;AAC3B,gBAAA,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS;gBAEnC,IAAI,CAAC,KAAK,EAAE;AACV,oBAAA,OAAO,KAAK;;AAGd,gBAAA,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,GAAG,KAAI;oBACvD,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;wBAChC,SAAS,GAAG,IAAI;AAChB,wBAAA,EAAE,CAAC,UAAU,CACX,IAAI,CAAC,OAAO,CAAC,0BAA0B,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,EACjF,GAAG,EACH,GAAG,GAAG,IAAI,CAAC,QAAQ,CACpB;AAED,wBAAA,OAAO,KAAK;;AAEhB,iBAAC,CAAC;AAEF,gBAAA,OAAO,SAAS;AAClB,aAAC,CAAC;SACH;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;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 type { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { PluginKey } from '@tiptap/pm/state'\nimport type { SuggestionOptions } from '@tiptap/suggestion'\nimport Suggestion 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 priority: 101,\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 // get reference to `window` object from editor element, to support cross-frame JS usage\n editor.view.dom.ownerDocument.defaultView?.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(\n { 'data-type': this.name },\n this.options.HTMLAttributes,\n HTMLAttributes,\n )\n const html = this.options.renderHTML({\n options: mergedOptions,\n node,\n })\n\n if (typeof html === 'string') {\n return ['span', mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes), html]\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: () =>\n 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;AAE1B,wBAAuB;AAmEhB,IAAM,mBAAmB,IAAI,uBAAU,SAAS;AAMhD,IAAM,UAAU,iBAAK,OAAuB;AAAA,EACjD,MAAM;AAAA,EAEN,UAAU;AAAA,EAEV,aAAa;AACX,WAAO;AAAA,MACL,gBAAgB,CAAC;AAAA,MACjB,WAAW,EAAE,SAAS,KAAK,GAAG;AArFpC;AAsFQ,eAAO,GAAG,QAAQ,WAAW,IAAI,IAAG,UAAK,MAAM,UAAX,YAAoB,KAAK,MAAM,EAA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AA,IAChH;AACA,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,EAAE,KAAK,GAAG;AACnB,QAAI,KAAK,QAAQ,gBAAgB,QAAW;AAC1C,cAAQ,KAAK,iEAAiE;AAC9E,aAAO,KAAK,QAAQ,YAAY;AAAA,QAC9B,SAAS,KAAK;AAAA,QACd;AAAA,MACF,CAAC;AAAA,IACH;AACA,WAAO,KAAK,QAAQ,WAAW;AAAA,MAC7B,SAAS,KAAK;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,WAAW,MACT,KAAK,OAAO,SAAS,QAAQ,CAAC,EAAE,IAAI,MAAM,MAAM;AAC9C,YAAI,YAAY;AAChB,cAAM,EAAE,UAAU,IAAI;AACtB,cAAM,EAAE,OAAO,OAAO,IAAI;AAE1B,YAAI,CAAC,OAAO;AACV,iBAAO;AAAA,QACT;AAEA,cAAM,IAAI,aAAa,SAAS,GAAG,QAAQ,CAAC,MAAM,QAAQ;AACxD,cAAI,KAAK,KAAK,SAAS,KAAK,MAAM;AAChC,wBAAY;AACZ,eAAG;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,IACL;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;;;ADxQD,IAAO,gBAAQ;","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,10 +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
- //# sourceMappingURL=mention.d.ts.map
77
+ declare const Mention: Node$1<MentionOptions<any, MentionNodeAttrs>, any>;
78
+
79
+ export { Mention, type MentionNodeAttrs, type MentionOptions, MentionPluginKey, Mention as default };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,79 @@
1
- import { Mention } from './mention.js';
2
- export * from './mention.js';
3
- export default Mention;
4
- //# sourceMappingURL=index.d.ts.map
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 };