@tiptap/extension-mention 3.0.0 → 3.0.2
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 +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +250 -172
- package/dist/index.cjs.map +1 -1
- package/dist/{packages/extension-mention/src/mention.d.ts → index.d.cts} +33 -16
- package/dist/index.d.ts +93 -0
- package/dist/index.js +215 -168
- package/dist/index.js.map +1 -1
- package/package.json +15 -13
- package/src/mention.ts +158 -95
- package/src/utils/get-default-suggestion-attributes.ts +89 -0
- package/dist/index.umd.js +0 -187
- package/dist/index.umd.js.map +0 -1
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -161
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -343
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -451
- package/dist/packages/core/src/Node.d.ts +0 -611
- package/dist/packages/core/src/NodePos.d.ts +0 -44
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/PasteRule.d.ts +0 -50
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
- package/dist/packages/core/src/commands/command.d.ts +0 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
- package/dist/packages/core/src/commands/cut.d.ts +0 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
- package/dist/packages/core/src/commands/enter.d.ts +0 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
- package/dist/packages/core/src/commands/first.d.ts +0 -14
- package/dist/packages/core/src/commands/focus.d.ts +0 -27
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
- package/dist/packages/core/src/commands/join.d.ts +0 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
- package/dist/packages/core/src/commands/lift.d.ts +0 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
- package/dist/packages/core/src/commands/setContent.d.ts +0 -40
- package/dist/packages/core/src/commands/setMark.d.ts +0 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
- package/dist/packages/core/src/commands/setNode.d.ts +0 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
- package/dist/packages/core/src/extensions/commands.d.ts +0 -3
- package/dist/packages/core/src/extensions/editable.d.ts +0 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
- package/dist/packages/core/src/extensions/index.d.ts +0 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getText.d.ts +0 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
- package/dist/packages/core/src/helpers/index.d.ts +0 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
- package/dist/packages/core/src/index.d.ts +0 -24
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -255
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/index.d.ts +0 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
- package/dist/packages/extension-mention/src/index.d.ts +0 -3
- package/dist/packages/suggestion/src/findSuggestionMatch.d.ts +0 -15
- package/dist/packages/suggestion/src/index.d.ts +0 -4
- package/dist/packages/suggestion/src/suggestion.d.ts +0 -153
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Node as Node$1 } from '@tiptap/core';
|
|
2
|
+
import { Node, DOMOutputSpec } from '@tiptap/pm/model';
|
|
3
|
+
import { SuggestionOptions } from '@tiptap/suggestion';
|
|
4
|
+
|
|
5
|
+
interface MentionNodeAttrs {
|
|
6
|
+
/**
|
|
7
|
+
* The identifier for the selected item that was mentioned, stored as a `data-id`
|
|
8
|
+
* attribute.
|
|
9
|
+
*/
|
|
10
|
+
id: string | null;
|
|
11
|
+
/**
|
|
12
|
+
* The label to be rendered by the editor as the displayed text for this mentioned
|
|
13
|
+
* item, if provided. Stored as a `data-label` attribute. See `renderLabel`.
|
|
14
|
+
*/
|
|
15
|
+
label?: string | null;
|
|
16
|
+
/**
|
|
17
|
+
* The character that triggers the suggestion, stored as
|
|
18
|
+
* `data-mention-suggestion-char` attribute.
|
|
19
|
+
*/
|
|
20
|
+
mentionSuggestionChar?: string;
|
|
21
|
+
}
|
|
22
|
+
interface MentionOptions<SuggestionItem = any, Attrs extends Record<string, any> = MentionNodeAttrs> {
|
|
23
|
+
/**
|
|
24
|
+
* The HTML attributes for a mention node.
|
|
25
|
+
* @default {}
|
|
26
|
+
* @example { class: 'foo' }
|
|
27
|
+
*/
|
|
28
|
+
HTMLAttributes: Record<string, any>;
|
|
29
|
+
/**
|
|
30
|
+
* A function to render the label of a mention.
|
|
31
|
+
* @deprecated use renderText and renderHTML instead
|
|
32
|
+
* @param props The render props
|
|
33
|
+
* @returns The label
|
|
34
|
+
* @example ({ options, node }) => `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`
|
|
35
|
+
*/
|
|
36
|
+
renderLabel?: (props: {
|
|
37
|
+
options: MentionOptions<SuggestionItem, Attrs>;
|
|
38
|
+
node: Node;
|
|
39
|
+
suggestion: SuggestionOptions | null;
|
|
40
|
+
}) => string;
|
|
41
|
+
/**
|
|
42
|
+
* A function to render the text of a mention.
|
|
43
|
+
* @param props The render props
|
|
44
|
+
* @returns The text
|
|
45
|
+
* @example ({ options, node }) => `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`
|
|
46
|
+
*/
|
|
47
|
+
renderText: (props: {
|
|
48
|
+
options: MentionOptions<SuggestionItem, Attrs>;
|
|
49
|
+
node: Node;
|
|
50
|
+
suggestion: SuggestionOptions | null;
|
|
51
|
+
}) => string;
|
|
52
|
+
/**
|
|
53
|
+
* A function to render the HTML of a mention.
|
|
54
|
+
* @param props The render props
|
|
55
|
+
* @returns The HTML as a ProseMirror DOM Output Spec
|
|
56
|
+
* @example ({ options, node }) => ['span', { 'data-type': 'mention' }, `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`]
|
|
57
|
+
*/
|
|
58
|
+
renderHTML: (props: {
|
|
59
|
+
options: MentionOptions<SuggestionItem, Attrs>;
|
|
60
|
+
node: Node;
|
|
61
|
+
suggestion: SuggestionOptions | null;
|
|
62
|
+
}) => DOMOutputSpec;
|
|
63
|
+
/**
|
|
64
|
+
* Whether to delete the trigger character with backspace.
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
deleteTriggerWithBackspace: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* The suggestion options, when you want to support multiple triggers.
|
|
70
|
+
*
|
|
71
|
+
* With this parameter, you can define multiple types of mention. For example, you can use the `@` character
|
|
72
|
+
* to mention users and the `#` character to mention tags.
|
|
73
|
+
*
|
|
74
|
+
* @default [{ char: '@', pluginKey: MentionPluginKey }]
|
|
75
|
+
* @example [{ char: '@', pluginKey: MentionPluginKey }, { char: '#', pluginKey: new PluginKey('hashtag') }]
|
|
76
|
+
*/
|
|
77
|
+
suggestions: Array<Omit<SuggestionOptions<SuggestionItem, Attrs>, 'editor'>>;
|
|
78
|
+
/**
|
|
79
|
+
* The suggestion options, when you want to support only one trigger. To support multiple triggers, use the
|
|
80
|
+
* `suggestions` parameter instead.
|
|
81
|
+
*
|
|
82
|
+
* @default {}
|
|
83
|
+
* @example { char: '@', pluginKey: MentionPluginKey, command: ({ editor, range, props }) => { ... } }
|
|
84
|
+
*/
|
|
85
|
+
suggestion: Omit<SuggestionOptions<SuggestionItem, Attrs>, 'editor'>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* This extension allows you to insert mentions into the editor.
|
|
89
|
+
* @see https://www.tiptap.dev/api/extensions/mention
|
|
90
|
+
*/
|
|
91
|
+
declare const Mention: Node$1<MentionOptions<any, MentionNodeAttrs>, any>;
|
|
92
|
+
|
|
93
|
+
export { Mention, type MentionNodeAttrs, type MentionOptions, Mention as default };
|
package/dist/index.js
CHANGED
|
@@ -1,179 +1,226 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
// src/mention.ts
|
|
2
|
+
import { mergeAttributes, Node } from "@tiptap/core";
|
|
3
|
+
import { Node as ProseMirrorNode } from "@tiptap/pm/model";
|
|
4
|
+
import Suggestion from "@tiptap/suggestion";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var _a, _b;
|
|
37
|
-
// increase range.to by one when the next node is of type "text"
|
|
38
|
-
// and starts with a space character
|
|
39
|
-
const nodeAfter = editor.view.state.selection.$to.nodeAfter;
|
|
40
|
-
const overrideSpace = (_a = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.text) === null || _a === void 0 ? void 0 : _a.startsWith(' ');
|
|
41
|
-
if (overrideSpace) {
|
|
42
|
-
range.to += 1;
|
|
43
|
-
}
|
|
44
|
-
editor
|
|
45
|
-
.chain()
|
|
46
|
-
.focus()
|
|
47
|
-
.insertContentAt(range, [
|
|
48
|
-
{
|
|
49
|
-
type: this.name,
|
|
50
|
-
attrs: props,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
type: 'text',
|
|
54
|
-
text: ' ',
|
|
55
|
-
},
|
|
56
|
-
])
|
|
57
|
-
.run();
|
|
58
|
-
(_b = window.getSelection()) === null || _b === void 0 ? void 0 : _b.collapseToEnd();
|
|
59
|
-
},
|
|
60
|
-
allow: ({ state, range }) => {
|
|
61
|
-
const $from = state.doc.resolve(range.from);
|
|
62
|
-
const type = state.schema.nodes[this.name];
|
|
63
|
-
const allow = !!$from.parent.type.contentMatch.matchType(type);
|
|
64
|
-
return allow;
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
};
|
|
6
|
+
// src/utils/get-default-suggestion-attributes.ts
|
|
7
|
+
import { PluginKey } from "@tiptap/pm/state";
|
|
8
|
+
function getSuggestionOptions({
|
|
9
|
+
editor: tiptapEditor,
|
|
10
|
+
overrideSuggestionOptions,
|
|
11
|
+
extensionName,
|
|
12
|
+
char = "@"
|
|
13
|
+
}) {
|
|
14
|
+
const pluginKey = new PluginKey();
|
|
15
|
+
return {
|
|
16
|
+
editor: tiptapEditor,
|
|
17
|
+
char,
|
|
18
|
+
pluginKey,
|
|
19
|
+
command: ({ editor, range, props }) => {
|
|
20
|
+
var _a, _b, _c;
|
|
21
|
+
const nodeAfter = editor.view.state.selection.$to.nodeAfter;
|
|
22
|
+
const overrideSpace = (_a = nodeAfter == null ? void 0 : nodeAfter.text) == null ? void 0 : _a.startsWith(" ");
|
|
23
|
+
if (overrideSpace) {
|
|
24
|
+
range.to += 1;
|
|
25
|
+
}
|
|
26
|
+
editor.chain().focus().insertContentAt(range, [
|
|
27
|
+
{
|
|
28
|
+
type: extensionName,
|
|
29
|
+
attrs: { ...props, mentionSuggestionChar: char }
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type: "text",
|
|
33
|
+
text: " "
|
|
34
|
+
}
|
|
35
|
+
]).run();
|
|
36
|
+
(_c = (_b = editor.view.dom.ownerDocument.defaultView) == null ? void 0 : _b.getSelection()) == null ? void 0 : _c.collapseToEnd();
|
|
68
37
|
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
id: {
|
|
76
|
-
default: null,
|
|
77
|
-
parseHTML: element => element.getAttribute('data-id'),
|
|
78
|
-
renderHTML: attributes => {
|
|
79
|
-
if (!attributes.id) {
|
|
80
|
-
return {};
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
'data-id': attributes.id,
|
|
84
|
-
};
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
label: {
|
|
88
|
-
default: null,
|
|
89
|
-
parseHTML: element => element.getAttribute('data-label'),
|
|
90
|
-
renderHTML: attributes => {
|
|
91
|
-
if (!attributes.label) {
|
|
92
|
-
return {};
|
|
93
|
-
}
|
|
94
|
-
return {
|
|
95
|
-
'data-label': attributes.label,
|
|
96
|
-
};
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
};
|
|
38
|
+
allow: ({ state, range }) => {
|
|
39
|
+
const $from = state.doc.resolve(range.from);
|
|
40
|
+
const type = state.schema.nodes[extensionName];
|
|
41
|
+
const allow = !!$from.parent.type.contentMatch.matchType(type);
|
|
42
|
+
return allow;
|
|
100
43
|
},
|
|
101
|
-
|
|
44
|
+
...overrideSuggestionOptions
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/mention.ts
|
|
49
|
+
function getSuggestions(options) {
|
|
50
|
+
return (options.options.suggestions.length ? options.options.suggestions : [options.options.suggestion]).map(
|
|
51
|
+
(suggestion) => getSuggestionOptions({
|
|
52
|
+
// @ts-ignore `editor` can be `undefined` when converting the document to HTML with the HTML utility
|
|
53
|
+
editor: options.editor,
|
|
54
|
+
overrideSuggestionOptions: suggestion,
|
|
55
|
+
extensionName: options.name,
|
|
56
|
+
char: suggestion.char
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
function getSuggestionFromChar(options, char) {
|
|
61
|
+
const suggestions = getSuggestions(options);
|
|
62
|
+
const suggestion = suggestions.find((s) => s.char === char);
|
|
63
|
+
if (suggestion) {
|
|
64
|
+
return suggestion;
|
|
65
|
+
}
|
|
66
|
+
if (suggestions.length) {
|
|
67
|
+
return suggestions[0];
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
var Mention = Node.create({
|
|
72
|
+
name: "mention",
|
|
73
|
+
priority: 101,
|
|
74
|
+
addOptions() {
|
|
75
|
+
return {
|
|
76
|
+
HTMLAttributes: {},
|
|
77
|
+
renderText({ node, suggestion }) {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
return `${(_a = suggestion == null ? void 0 : suggestion.char) != null ? _a : "@"}${(_b = node.attrs.label) != null ? _b : node.attrs.id}`;
|
|
80
|
+
},
|
|
81
|
+
deleteTriggerWithBackspace: false,
|
|
82
|
+
renderHTML({ options, node, suggestion }) {
|
|
83
|
+
var _a, _b;
|
|
102
84
|
return [
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
85
|
+
"span",
|
|
86
|
+
mergeAttributes(this.HTMLAttributes, options.HTMLAttributes),
|
|
87
|
+
`${(_a = suggestion == null ? void 0 : suggestion.char) != null ? _a : "@"}${(_b = node.attrs.label) != null ? _b : node.attrs.id}`
|
|
106
88
|
];
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
89
|
+
},
|
|
90
|
+
suggestions: [],
|
|
91
|
+
suggestion: {}
|
|
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
|
+
};
|
|
119
110
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
];
|
|
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
|
+
};
|
|
132
122
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
123
|
+
},
|
|
124
|
+
// When there are multiple types of mentions, this attribute helps distinguish them
|
|
125
|
+
mentionSuggestionChar: {
|
|
126
|
+
default: "@",
|
|
127
|
+
parseHTML: (element) => element.getAttribute("data-mention-suggestion-char"),
|
|
128
|
+
renderHTML: (attributes) => {
|
|
129
|
+
return {
|
|
130
|
+
"data-mention-suggestion-char": attributes.mentionSuggestionChar
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
parseHTML() {
|
|
137
|
+
return [
|
|
138
|
+
{
|
|
139
|
+
tag: `span[data-type="${this.name}"]`
|
|
140
|
+
}
|
|
141
|
+
];
|
|
142
|
+
},
|
|
143
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
144
|
+
const suggestion = getSuggestionFromChar(this, node.attrs.mentionSuggestionChar);
|
|
145
|
+
if (this.options.renderLabel !== void 0) {
|
|
146
|
+
console.warn("renderLabel is deprecated use renderText and renderHTML instead");
|
|
147
|
+
return [
|
|
148
|
+
"span",
|
|
149
|
+
mergeAttributes({ "data-type": this.name }, this.options.HTMLAttributes, HTMLAttributes),
|
|
150
|
+
this.options.renderLabel({
|
|
151
|
+
options: this.options,
|
|
152
|
+
node,
|
|
153
|
+
suggestion
|
|
154
|
+
})
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
const mergedOptions = { ...this.options };
|
|
158
|
+
mergedOptions.HTMLAttributes = mergeAttributes(
|
|
159
|
+
{ "data-type": this.name },
|
|
160
|
+
this.options.HTMLAttributes,
|
|
161
|
+
HTMLAttributes
|
|
162
|
+
);
|
|
163
|
+
const html = this.options.renderHTML({
|
|
164
|
+
options: mergedOptions,
|
|
165
|
+
node,
|
|
166
|
+
suggestion
|
|
167
|
+
});
|
|
168
|
+
if (typeof html === "string") {
|
|
169
|
+
return ["span", mergeAttributes({ "data-type": this.name }, this.options.HTMLAttributes, HTMLAttributes), html];
|
|
170
|
+
}
|
|
171
|
+
return html;
|
|
172
|
+
},
|
|
173
|
+
renderText({ node }) {
|
|
174
|
+
const args = {
|
|
175
|
+
options: this.options,
|
|
176
|
+
node,
|
|
177
|
+
suggestion: getSuggestionFromChar(this, node.attrs.mentionSuggestionChar)
|
|
178
|
+
};
|
|
179
|
+
if (this.options.renderLabel !== void 0) {
|
|
180
|
+
console.warn("renderLabel is deprecated use renderText and renderHTML instead");
|
|
181
|
+
return this.options.renderLabel(args);
|
|
182
|
+
}
|
|
183
|
+
return this.options.renderText(args);
|
|
184
|
+
},
|
|
185
|
+
addKeyboardShortcuts() {
|
|
186
|
+
return {
|
|
187
|
+
Backspace: () => this.editor.commands.command(({ tr, state }) => {
|
|
188
|
+
let isMention = false;
|
|
189
|
+
const { selection } = state;
|
|
190
|
+
const { empty, anchor } = selection;
|
|
191
|
+
if (!empty) {
|
|
192
|
+
return false;
|
|
142
193
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
194
|
+
let mentionNode = new ProseMirrorNode();
|
|
195
|
+
let mentionPos = 0;
|
|
196
|
+
state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
|
|
197
|
+
if (node.type.name === this.name) {
|
|
198
|
+
isMention = true;
|
|
199
|
+
mentionNode = node;
|
|
200
|
+
mentionPos = pos;
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
146
203
|
});
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
return isMention;
|
|
165
|
-
}),
|
|
166
|
-
};
|
|
167
|
-
},
|
|
168
|
-
addProseMirrorPlugins() {
|
|
169
|
-
return [
|
|
170
|
-
Suggestion({
|
|
171
|
-
editor: this.editor,
|
|
172
|
-
...this.options.suggestion,
|
|
173
|
-
}),
|
|
174
|
-
];
|
|
175
|
-
},
|
|
204
|
+
if (isMention) {
|
|
205
|
+
tr.insertText(
|
|
206
|
+
this.options.deleteTriggerWithBackspace ? "" : mentionNode.attrs.mentionSuggestionChar,
|
|
207
|
+
mentionPos,
|
|
208
|
+
mentionPos + mentionNode.nodeSize
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
return isMention;
|
|
212
|
+
})
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
addProseMirrorPlugins() {
|
|
216
|
+
return getSuggestions(this).map(Suggestion);
|
|
217
|
+
}
|
|
176
218
|
});
|
|
177
219
|
|
|
178
|
-
|
|
179
|
-
|
|
220
|
+
// src/index.ts
|
|
221
|
+
var index_default = Mention;
|
|
222
|
+
export {
|
|
223
|
+
Mention,
|
|
224
|
+
index_default as default
|
|
225
|
+
};
|
|
226
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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":[],"mappings":";;;;AAkEA;;;AAGG;MACU,gBAAgB,GAAG,IAAI,SAAS,CAAC,SAAS,EAAC;AAExD;;;AAGG;AACU,MAAA,OAAO,GAAG,IAAI,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,mCAA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AI,CAAC,IAAI,EAAE;wBAChC,SAAS,GAAG,IAAI,CAAA;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,CAAA;AAED,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,YAAA,UAAU,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/mention.ts","../src/utils/get-default-suggestion-attributes.ts","../src/index.ts"],"sourcesContent":["import type { Editor } from '@tiptap/core'\nimport { mergeAttributes, Node } from '@tiptap/core'\nimport type { DOMOutputSpec } from '@tiptap/pm/model'\nimport { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport type { SuggestionOptions } from '@tiptap/suggestion'\nimport Suggestion from '@tiptap/suggestion'\n\nimport { getSuggestionOptions } from './utils/get-default-suggestion-attributes.js'\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 * The character that triggers the suggestion, stored as\n * `data-mention-suggestion-char` attribute.\n */\n mentionSuggestionChar?: string\n}\n\nexport interface 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: {\n options: MentionOptions<SuggestionItem, Attrs>\n node: ProseMirrorNode\n suggestion: SuggestionOptions | null\n }) => 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: {\n options: MentionOptions<SuggestionItem, Attrs>\n node: ProseMirrorNode\n suggestion: SuggestionOptions | null\n }) => 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: {\n options: MentionOptions<SuggestionItem, Attrs>\n node: ProseMirrorNode\n suggestion: SuggestionOptions | null\n }) => 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, when you want to support multiple triggers.\n *\n * With this parameter, you can define multiple types of mention. For example, you can use the `@` character\n * to mention users and the `#` character to mention tags.\n *\n * @default [{ char: '@', pluginKey: MentionPluginKey }]\n * @example [{ char: '@', pluginKey: MentionPluginKey }, { char: '#', pluginKey: new PluginKey('hashtag') }]\n */\n suggestions: Array<Omit<SuggestionOptions<SuggestionItem, Attrs>, 'editor'>>\n\n /**\n * The suggestion options, when you want to support only one trigger. To support multiple triggers, use the\n * `suggestions` parameter instead.\n *\n * @default {}\n * @example { char: '@', pluginKey: MentionPluginKey, command: ({ editor, range, props }) => { ... } }\n */\n suggestion: Omit<SuggestionOptions<SuggestionItem, Attrs>, 'editor'>\n}\n\ninterface GetSuggestionsOptions {\n editor?: Editor\n options: MentionOptions\n name: string\n}\n\n/**\n * Returns the suggestions for the mention extension.\n *\n * @param options The extension options\n * @returns the suggestions\n */\nfunction getSuggestions(options: GetSuggestionsOptions) {\n return (options.options.suggestions.length ? options.options.suggestions : [options.options.suggestion]).map(\n suggestion =>\n getSuggestionOptions({\n // @ts-ignore `editor` can be `undefined` when converting the document to HTML with the HTML utility\n editor: options.editor,\n overrideSuggestionOptions: suggestion,\n extensionName: options.name,\n char: suggestion.char,\n }),\n )\n}\n\n/**\n * Returns the suggestion options of the mention that has a given character trigger. If not\n * found, it returns the first suggestion.\n *\n * @param options The extension options\n * @param char The character that triggers the mention\n * @returns The suggestion options\n */\nfunction getSuggestionFromChar(options: GetSuggestionsOptions, char: string) {\n const suggestions = getSuggestions(options)\n\n const suggestion = suggestions.find(s => s.char === char)\n if (suggestion) {\n return suggestion\n }\n\n if (suggestions.length) {\n return suggestions[0]\n }\n\n return null\n}\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({ node, suggestion }) {\n return `${suggestion?.char ?? '@'}${node.attrs.label ?? node.attrs.id}`\n },\n deleteTriggerWithBackspace: false,\n renderHTML({ options, node, suggestion }) {\n return [\n 'span',\n mergeAttributes(this.HTMLAttributes, options.HTMLAttributes),\n `${suggestion?.char ?? '@'}${node.attrs.label ?? node.attrs.id}`,\n ]\n },\n suggestions: [],\n suggestion: {},\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 // When there are multiple types of mentions, this attribute helps distinguish them\n mentionSuggestionChar: {\n default: '@',\n parseHTML: element => element.getAttribute('data-mention-suggestion-char'),\n renderHTML: attributes => {\n return {\n 'data-mention-suggestion-char': attributes.mentionSuggestionChar,\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 const suggestion = getSuggestionFromChar(this, node.attrs.mentionSuggestionChar)\n\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 suggestion,\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\n const html = this.options.renderHTML({\n options: mergedOptions,\n node,\n suggestion,\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 const args = {\n options: this.options,\n node,\n suggestion: getSuggestionFromChar(this, node.attrs.mentionSuggestionChar),\n }\n if (this.options.renderLabel !== undefined) {\n console.warn('renderLabel is deprecated use renderText and renderHTML instead')\n return this.options.renderLabel(args)\n }\n\n return this.options.renderText(args)\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 // Store node and position for later use\n let mentionNode = new ProseMirrorNode()\n let mentionPos = 0\n\n state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {\n if (node.type.name === this.name) {\n isMention = true\n mentionNode = node\n mentionPos = pos\n return false\n }\n })\n\n if (isMention) {\n tr.insertText(\n this.options.deleteTriggerWithBackspace ? '' : mentionNode.attrs.mentionSuggestionChar,\n mentionPos,\n mentionPos + mentionNode.nodeSize,\n )\n }\n\n return isMention\n }),\n }\n },\n\n addProseMirrorPlugins() {\n // Create a plugin for each suggestion configuration\n return getSuggestions(this).map(Suggestion)\n },\n})\n","import type { Editor } from '@tiptap/core'\nimport { PluginKey } from '@tiptap/pm/state'\nimport type { SuggestionOptions } from '@tiptap/suggestion'\n\n/**\n * Arguments for the `getSuggestionOptions` function\n * @see getSuggestionOptions\n */\nexport interface GetSuggestionOptionsOptions {\n /**\n * The Tiptap editor instance.\n */\n editor: Editor\n /**\n * The suggestion options configuration provided to the\n * `Mention` extension.\n */\n overrideSuggestionOptions: Omit<SuggestionOptions, 'editor'>\n /**\n * The name of the Mention extension\n */\n extensionName: string\n /**\n * The character that triggers the suggestion.\n * @default '@'\n */\n char?: string\n}\n\n/**\n * Returns the suggestion options for a trigger of the Mention extension. These\n * options are used to create a `Suggestion` ProseMirror plugin. Each plugin lets\n * you define a different trigger that opens the Mention menu. For example,\n * you can define a `@` trigger to mention users and a `#` trigger to mention\n * tags.\n *\n * @param param0 The configured options for the suggestion\n * @returns\n */\nexport function getSuggestionOptions({\n editor: tiptapEditor,\n overrideSuggestionOptions,\n extensionName,\n char = '@',\n}: GetSuggestionOptionsOptions): SuggestionOptions {\n const pluginKey = new PluginKey()\n\n return {\n editor: tiptapEditor,\n char,\n pluginKey,\n command: ({ editor, range, props }: { editor: any; range: any; props: any }) => {\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: extensionName,\n attrs: { ...props, mentionSuggestionChar: char },\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 }: { state: any; range: any }) => {\n const $from = state.doc.resolve(range.from)\n const type = state.schema.nodes[extensionName]\n const allow = !!$from.parent.type.contentMatch.matchType(type)\n\n return allow\n },\n ...overrideSuggestionOptions,\n }\n}\n","import { Mention } from './mention.js'\n\nexport * from './mention.js'\n\nexport default Mention\n"],"mappings":";AACA,SAAS,iBAAiB,YAAY;AAEtC,SAAS,QAAQ,uBAAuB;AAExC,OAAO,gBAAgB;;;ACJvB,SAAS,iBAAiB;AAsCnB,SAAS,qBAAqB;AAAA,EACnC,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA,OAAO;AACT,GAAmD;AACjD,QAAM,YAAY,IAAI,UAAU;AAEhC,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,SAAS,CAAC,EAAE,QAAQ,OAAO,MAAM,MAA+C;AAnDpF;AAsDM,YAAM,YAAY,OAAO,KAAK,MAAM,UAAU,IAAI;AAClD,YAAM,iBAAgB,4CAAW,SAAX,mBAAiB,WAAW;AAElD,UAAI,eAAe;AACjB,cAAM,MAAM;AAAA,MACd;AAEA,aACG,MAAM,EACN,MAAM,EACN,gBAAgB,OAAO;AAAA,QACtB;AAAA,UACE,MAAM;AAAA,UACN,OAAO,EAAE,GAAG,OAAO,uBAAuB,KAAK;AAAA,QACjD;AAAA,QACA;AAAA,UACE,MAAM;AAAA,UACN,MAAM;AAAA,QACR;AAAA,MACF,CAAC,EACA,IAAI;AAGP,yBAAO,KAAK,IAAI,cAAc,gBAA9B,mBAA2C,mBAA3C,mBAA2D;AAAA,IAC7D;AAAA,IACA,OAAO,CAAC,EAAE,OAAO,MAAM,MAAkC;AACvD,YAAM,QAAQ,MAAM,IAAI,QAAQ,MAAM,IAAI;AAC1C,YAAM,OAAO,MAAM,OAAO,MAAM,aAAa;AAC7C,YAAM,QAAQ,CAAC,CAAC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;AAAA,QACF,CAAC;AAED,YAAI,WAAW;AACb,aAAG;AAAA,YACD,KAAK,QAAQ,6BAA6B,KAAK,YAAY,MAAM;AAAA,YACjE;AAAA,YACA,aAAa,YAAY;AAAA,UAC3B;AAAA,QACF;AAEA,eAAO;AAAA,MACT,CAAC;AAAA,IACL;AAAA,EACF;AAAA,EAEA,wBAAwB;AAEtB,WAAO,eAAe,IAAI,EAAE,IAAI,UAAU;AAAA,EAC5C;AACF,CAAC;;;AElUD,IAAO,gBAAQ;","names":[]}
|
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": "3.0.
|
|
4
|
+
"version": "3.0.2",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -15,28 +15,30 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types":
|
|
18
|
+
"types": {
|
|
19
|
+
"import": "./dist/index.d.ts",
|
|
20
|
+
"require": "./dist/index.d.cts"
|
|
21
|
+
},
|
|
19
22
|
"import": "./dist/index.js",
|
|
20
23
|
"require": "./dist/index.cjs"
|
|
21
24
|
}
|
|
22
25
|
},
|
|
23
26
|
"main": "dist/index.cjs",
|
|
24
27
|
"module": "dist/index.js",
|
|
25
|
-
"
|
|
26
|
-
"types": "dist/packages/extension-mention/src/index.d.ts",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
27
29
|
"files": [
|
|
28
30
|
"src",
|
|
29
31
|
"dist"
|
|
30
32
|
],
|
|
31
33
|
"devDependencies": {
|
|
32
|
-
"@tiptap/core": "^3.0.
|
|
33
|
-
"@tiptap/pm": "^3.0.
|
|
34
|
-
"@tiptap/suggestion": "^3.0.
|
|
34
|
+
"@tiptap/core": "^3.0.2",
|
|
35
|
+
"@tiptap/pm": "^3.0.2",
|
|
36
|
+
"@tiptap/suggestion": "^3.0.2"
|
|
35
37
|
},
|
|
36
38
|
"peerDependencies": {
|
|
37
|
-
"@tiptap/core": "^3.0.
|
|
38
|
-
"@tiptap/pm": "^3.0.
|
|
39
|
-
"@tiptap/suggestion": "^3.0.
|
|
39
|
+
"@tiptap/core": "^3.0.2",
|
|
40
|
+
"@tiptap/pm": "^3.0.2",
|
|
41
|
+
"@tiptap/suggestion": "^3.0.2"
|
|
40
42
|
},
|
|
41
43
|
"repository": {
|
|
42
44
|
"type": "git",
|
|
@@ -44,7 +46,7 @@
|
|
|
44
46
|
"directory": "packages/extension-mention"
|
|
45
47
|
},
|
|
46
48
|
"scripts": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
+
"build": "tsup",
|
|
50
|
+
"lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/"
|
|
49
51
|
}
|
|
50
|
-
}
|
|
52
|
+
}
|