@tiptap/suggestion 3.0.0-next.0 → 3.0.0-next.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.
Files changed (174) hide show
  1. package/dist/index.cjs +271 -233
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/{packages/suggestion/src/suggestion.d.ts → index.d.cts} +33 -10
  4. package/dist/index.d.ts +176 -0
  5. package/dist/index.js +244 -228
  6. package/dist/index.js.map +1 -1
  7. package/package.json +8 -10
  8. package/src/findSuggestionMatch.ts +7 -3
  9. package/src/suggestion.ts +11 -3
  10. package/dist/index.umd.js +0 -246
  11. package/dist/index.umd.js.map +0 -1
  12. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  13. package/dist/packages/core/src/Editor.d.ts +0 -159
  14. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  15. package/dist/packages/core/src/Extension.d.ts +0 -343
  16. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  17. package/dist/packages/core/src/InputRule.d.ts +0 -42
  18. package/dist/packages/core/src/Mark.d.ts +0 -451
  19. package/dist/packages/core/src/Node.d.ts +0 -611
  20. package/dist/packages/core/src/NodePos.d.ts +0 -44
  21. package/dist/packages/core/src/NodeView.d.ts +0 -31
  22. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  23. package/dist/packages/core/src/Tracker.d.ts +0 -11
  24. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  25. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  26. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  27. package/dist/packages/core/src/commands/command.d.ts +0 -18
  28. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  29. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  30. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  31. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  32. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  33. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  34. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  35. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  36. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  37. package/dist/packages/core/src/commands/first.d.ts +0 -14
  38. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  39. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  40. package/dist/packages/core/src/commands/index.d.ts +0 -55
  41. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  42. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  43. package/dist/packages/core/src/commands/join.d.ts +0 -41
  44. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  45. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  46. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  47. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  48. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  49. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  50. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  51. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  52. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  53. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  54. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  55. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  56. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  57. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  58. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  59. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  60. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  61. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  62. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  63. package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
  64. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  65. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  66. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  67. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  68. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  69. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
  70. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  71. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  72. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  73. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  74. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  75. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  76. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  77. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  78. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  79. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  80. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  81. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  82. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  83. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  84. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  85. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  86. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  87. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  88. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  89. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  90. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  91. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  92. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  93. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  94. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  95. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  96. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  97. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  98. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  99. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  100. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  101. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  102. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  103. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  104. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  105. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  106. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  107. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  108. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  109. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  110. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  111. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  112. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  113. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  114. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  115. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  116. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  117. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  118. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  119. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  120. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  121. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  122. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  123. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  124. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  125. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  126. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  127. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  128. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  129. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  130. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  131. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -8
  132. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  133. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  134. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  135. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  136. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  137. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  138. package/dist/packages/core/src/index.d.ts +0 -24
  139. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  140. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  141. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  142. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  143. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  144. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  145. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  146. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  147. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
  148. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  149. package/dist/packages/core/src/style.d.ts +0 -1
  150. package/dist/packages/core/src/types.d.ts +0 -253
  151. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  152. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  153. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  154. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  155. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  156. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  157. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  158. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  159. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  160. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  161. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  162. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  163. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  164. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  165. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  166. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  167. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  168. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  169. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  170. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  171. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  172. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  173. package/dist/packages/suggestion/src/findSuggestionMatch.d.ts +0 -15
  174. package/dist/packages/suggestion/src/index.d.ts +0 -4
package/dist/index.cjs CHANGED
@@ -1,244 +1,282 @@
1
- 'use strict';
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
19
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Suggestion: () => Suggestion,
24
+ SuggestionPluginKey: () => SuggestionPluginKey,
25
+ default: () => src_default,
26
+ findSuggestionMatch: () => findSuggestionMatch
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
4
29
 
5
- var state = require('@tiptap/pm/state');
6
- var view = require('@tiptap/pm/view');
7
- var core = require('@tiptap/core');
30
+ // src/suggestion.ts
31
+ var import_state = require("@tiptap/pm/state");
32
+ var import_view = require("@tiptap/pm/view");
8
33
 
34
+ // src/findSuggestionMatch.ts
35
+ var import_core = require("@tiptap/core");
9
36
  function findSuggestionMatch(config) {
10
- var _a;
11
- const { char, allowSpaces, allowedPrefixes, startOfLine, $position, } = config;
12
- const escapedChar = core.escapeForRegEx(char);
13
- const suffix = new RegExp(`\\s${escapedChar}$`);
14
- const prefix = startOfLine ? '^' : '';
15
- const regexp = allowSpaces
16
- ? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${escapedChar}|$)`, 'gm')
17
- : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${escapedChar}]*`, 'gm');
18
- const text = ((_a = $position.nodeBefore) === null || _a === void 0 ? void 0 : _a.isText) && $position.nodeBefore.text;
19
- if (!text) {
20
- return null;
21
- }
22
- const textFrom = $position.pos - text.length;
23
- const match = Array.from(text.matchAll(regexp)).pop();
24
- if (!match || match.input === undefined || match.index === undefined) {
25
- return null;
26
- }
27
- // JavaScript doesn't have lookbehinds. This hacks a check that first character
28
- // is a space or the start of the line
29
- const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index);
30
- const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes === null || allowedPrefixes === void 0 ? void 0 : allowedPrefixes.join('')}\0]?$`).test(matchPrefix);
31
- if (allowedPrefixes !== null && !matchPrefixIsAllowed) {
32
- return null;
33
- }
34
- // The absolute position of the match in the document
35
- const from = textFrom + match.index;
36
- let to = from + match[0].length;
37
- // Edge case handling; if spaces are allowed and we're directly in between
38
- // two triggers
39
- if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) {
40
- match[0] += ' ';
41
- to += 1;
42
- }
43
- // If the $position is located within the matched substring, return that range
44
- if (from < $position.pos && to >= $position.pos) {
45
- return {
46
- range: {
47
- from,
48
- to,
49
- },
50
- query: match[0].slice(char.length),
51
- text: match[0],
52
- };
53
- }
37
+ var _a;
38
+ const {
39
+ char,
40
+ allowSpaces: allowSpacesOption,
41
+ allowToIncludeChar,
42
+ allowedPrefixes,
43
+ startOfLine,
44
+ $position
45
+ } = config;
46
+ const allowSpaces = allowSpacesOption && !allowToIncludeChar;
47
+ const escapedChar = (0, import_core.escapeForRegEx)(char);
48
+ const suffix = new RegExp(`\\s${escapedChar}$`);
49
+ const prefix = startOfLine ? "^" : "";
50
+ const finalEscapedChar = allowToIncludeChar ? "" : escapedChar;
51
+ const regexp = allowSpaces ? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${finalEscapedChar}|$)`, "gm") : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${finalEscapedChar}]*`, "gm");
52
+ const text = ((_a = $position.nodeBefore) == null ? void 0 : _a.isText) && $position.nodeBefore.text;
53
+ if (!text) {
54
+ return null;
55
+ }
56
+ const textFrom = $position.pos - text.length;
57
+ const match = Array.from(text.matchAll(regexp)).pop();
58
+ if (!match || match.input === void 0 || match.index === void 0) {
54
59
  return null;
60
+ }
61
+ const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index);
62
+ const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes == null ? void 0 : allowedPrefixes.join("")}\0]?$`).test(matchPrefix);
63
+ if (allowedPrefixes !== null && !matchPrefixIsAllowed) {
64
+ return null;
65
+ }
66
+ const from = textFrom + match.index;
67
+ let to = from + match[0].length;
68
+ if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) {
69
+ match[0] += " ";
70
+ to += 1;
71
+ }
72
+ if (from < $position.pos && to >= $position.pos) {
73
+ return {
74
+ range: {
75
+ from,
76
+ to
77
+ },
78
+ query: match[0].slice(char.length),
79
+ text: match[0]
80
+ };
81
+ }
82
+ return null;
55
83
  }
56
84
 
57
- const SuggestionPluginKey = new state.PluginKey('suggestion');
58
- /**
59
- * This utility allows you to create suggestions.
60
- * @see https://tiptap.dev/api/utilities/suggestion
61
- */
62
- function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = '@', allowSpaces = false, allowedPrefixes = [' '], startOfLine = false, decorationTag = 'span', decorationClass = 'suggestion', command = () => null, items = () => [], render = () => ({}), allow = () => true, findSuggestionMatch: findSuggestionMatch$1 = findSuggestionMatch, }) {
63
- let props;
64
- const renderer = render === null || render === void 0 ? void 0 : render();
65
- const plugin = new state.Plugin({
66
- key: pluginKey,
67
- view() {
68
- return {
69
- update: async (view, prevState) => {
70
- var _a, _b, _c, _d, _e, _f, _g;
71
- const prev = (_a = this.key) === null || _a === void 0 ? void 0 : _a.getState(prevState);
72
- const next = (_b = this.key) === null || _b === void 0 ? void 0 : _b.getState(view.state);
73
- // See how the state changed
74
- const moved = prev.active && next.active && prev.range.from !== next.range.from;
75
- const started = !prev.active && next.active;
76
- const stopped = prev.active && !next.active;
77
- const changed = !started && !stopped && prev.query !== next.query;
78
- const handleStart = started;
79
- const handleChange = changed || moved;
80
- const handleExit = stopped;
81
- // Cancel when suggestion isn't active
82
- if (!handleStart && !handleChange && !handleExit) {
83
- return;
84
- }
85
- const state = handleExit && !handleStart ? prev : next;
86
- const decorationNode = view.dom.querySelector(`[data-decoration-id="${state.decorationId}"]`);
87
- props = {
88
- editor,
89
- range: state.range,
90
- query: state.query,
91
- text: state.text,
92
- items: [],
93
- command: commandProps => {
94
- return command({
95
- editor,
96
- range: state.range,
97
- props: commandProps,
98
- });
99
- },
100
- decorationNode,
101
- // virtual node for positioning
102
- // this can be used for building popups without a DOM node
103
- clientRect: decorationNode
104
- ? () => {
105
- var _a;
106
- // because of `items` can be asynchrounous we’ll search for the current decoration node
107
- const { decorationId } = (_a = this.key) === null || _a === void 0 ? void 0 : _a.getState(editor.state); // eslint-disable-line
108
- const currentDecorationNode = view.dom.querySelector(`[data-decoration-id="${decorationId}"]`);
109
- return (currentDecorationNode === null || currentDecorationNode === void 0 ? void 0 : currentDecorationNode.getBoundingClientRect()) || null;
110
- }
111
- : null,
112
- };
113
- if (handleStart) {
114
- (_c = renderer === null || renderer === void 0 ? void 0 : renderer.onBeforeStart) === null || _c === void 0 ? void 0 : _c.call(renderer, props);
115
- }
116
- if (handleChange) {
117
- (_d = renderer === null || renderer === void 0 ? void 0 : renderer.onBeforeUpdate) === null || _d === void 0 ? void 0 : _d.call(renderer, props);
118
- }
119
- if (handleChange || handleStart) {
120
- props.items = await items({
121
- editor,
122
- query: state.query,
123
- });
124
- }
125
- if (handleExit) {
126
- (_e = renderer === null || renderer === void 0 ? void 0 : renderer.onExit) === null || _e === void 0 ? void 0 : _e.call(renderer, props);
127
- }
128
- if (handleChange) {
129
- (_f = renderer === null || renderer === void 0 ? void 0 : renderer.onUpdate) === null || _f === void 0 ? void 0 : _f.call(renderer, props);
130
- }
131
- if (handleStart) {
132
- (_g = renderer === null || renderer === void 0 ? void 0 : renderer.onStart) === null || _g === void 0 ? void 0 : _g.call(renderer, props);
133
- }
134
- },
135
- destroy: () => {
136
- var _a;
137
- if (!props) {
138
- return;
139
- }
140
- (_a = renderer === null || renderer === void 0 ? void 0 : renderer.onExit) === null || _a === void 0 ? void 0 : _a.call(renderer, props);
141
- },
142
- };
143
- },
144
- state: {
145
- // Initialize the plugin's internal state.
146
- init() {
147
- const state = {
148
- active: false,
149
- range: {
150
- from: 0,
151
- to: 0,
152
- },
153
- query: null,
154
- text: null,
155
- composing: false,
156
- };
157
- return state;
158
- },
159
- // Apply changes to the plugin state from a view transaction.
160
- apply(transaction, prev, _oldState, state) {
161
- const { isEditable } = editor;
162
- const { composing } = editor.view;
163
- const { selection } = transaction;
164
- const { empty, from } = selection;
165
- const next = { ...prev };
166
- next.composing = composing;
167
- // We can only be suggesting if the view is editable, and:
168
- // * there is no selection, or
169
- // * a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)
170
- if (isEditable && (empty || editor.view.composing)) {
171
- // Reset active state if we just left the previous suggestion range
172
- if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {
173
- next.active = false;
174
- }
175
- // Try to match against where our cursor currently is
176
- const match = findSuggestionMatch$1({
177
- char,
178
- allowSpaces,
179
- allowedPrefixes,
180
- startOfLine,
181
- $position: selection.$from,
182
- });
183
- const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`;
184
- // If we found a match, update the current state to show it
185
- if (match && allow({
186
- editor, state, range: match.range, isActive: prev.active,
187
- })) {
188
- next.active = true;
189
- next.decorationId = prev.decorationId ? prev.decorationId : decorationId;
190
- next.range = match.range;
191
- next.query = match.query;
192
- next.text = match.text;
193
- }
194
- else {
195
- next.active = false;
196
- }
197
- }
198
- else {
199
- next.active = false;
200
- }
201
- // Make sure to empty the range if suggestion is inactive
202
- if (!next.active) {
203
- next.decorationId = null;
204
- next.range = { from: 0, to: 0 };
205
- next.query = null;
206
- next.text = null;
207
- }
208
- return next;
209
- },
210
- },
211
- props: {
212
- // Call the keydown hook if suggestion is active.
213
- handleKeyDown(view, event) {
214
- var _a;
215
- const { active, range } = plugin.getState(view.state);
216
- if (!active) {
217
- return false;
218
- }
219
- return ((_a = renderer === null || renderer === void 0 ? void 0 : renderer.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(renderer, { view, event, range })) || false;
220
- },
221
- // Setup decorator on the currently active suggestion.
222
- decorations(state) {
223
- const { active, range, decorationId } = plugin.getState(state);
224
- if (!active) {
225
- return null;
226
- }
227
- return view.DecorationSet.create(state.doc, [
228
- view.Decoration.inline(range.from, range.to, {
229
- nodeName: decorationTag,
230
- class: decorationClass,
231
- 'data-decoration-id': decorationId,
232
- }),
233
- ]);
85
+ // src/suggestion.ts
86
+ var SuggestionPluginKey = new import_state.PluginKey("suggestion");
87
+ function Suggestion({
88
+ pluginKey = SuggestionPluginKey,
89
+ editor,
90
+ char = "@",
91
+ allowSpaces = false,
92
+ allowToIncludeChar = false,
93
+ allowedPrefixes = [" "],
94
+ startOfLine = false,
95
+ decorationTag = "span",
96
+ decorationClass = "suggestion",
97
+ command = () => null,
98
+ items = () => [],
99
+ render = () => ({}),
100
+ allow = () => true,
101
+ findSuggestionMatch: findSuggestionMatch2 = findSuggestionMatch
102
+ }) {
103
+ let props;
104
+ const renderer = render == null ? void 0 : render();
105
+ const plugin = new import_state.Plugin({
106
+ key: pluginKey,
107
+ view() {
108
+ return {
109
+ update: async (view, prevState) => {
110
+ var _a, _b, _c, _d, _e, _f, _g;
111
+ const prev = (_a = this.key) == null ? void 0 : _a.getState(prevState);
112
+ const next = (_b = this.key) == null ? void 0 : _b.getState(view.state);
113
+ const moved = prev.active && next.active && prev.range.from !== next.range.from;
114
+ const started = !prev.active && next.active;
115
+ const stopped = prev.active && !next.active;
116
+ const changed = !started && !stopped && prev.query !== next.query;
117
+ const handleStart = started || moved && changed;
118
+ const handleChange = changed || moved;
119
+ const handleExit = stopped || moved && changed;
120
+ if (!handleStart && !handleChange && !handleExit) {
121
+ return;
122
+ }
123
+ const state = handleExit && !handleStart ? prev : next;
124
+ const decorationNode = view.dom.querySelector(
125
+ `[data-decoration-id="${state.decorationId}"]`
126
+ );
127
+ props = {
128
+ editor,
129
+ range: state.range,
130
+ query: state.query,
131
+ text: state.text,
132
+ items: [],
133
+ command: (commandProps) => {
134
+ return command({
135
+ editor,
136
+ range: state.range,
137
+ props: commandProps
138
+ });
234
139
  },
140
+ decorationNode,
141
+ // virtual node for positioning
142
+ // this can be used for building popups without a DOM node
143
+ clientRect: decorationNode ? () => {
144
+ var _a2;
145
+ const { decorationId } = (_a2 = this.key) == null ? void 0 : _a2.getState(editor.state);
146
+ const currentDecorationNode = view.dom.querySelector(
147
+ `[data-decoration-id="${decorationId}"]`
148
+ );
149
+ return (currentDecorationNode == null ? void 0 : currentDecorationNode.getBoundingClientRect()) || null;
150
+ } : null
151
+ };
152
+ if (handleStart) {
153
+ (_c = renderer == null ? void 0 : renderer.onBeforeStart) == null ? void 0 : _c.call(renderer, props);
154
+ }
155
+ if (handleChange) {
156
+ (_d = renderer == null ? void 0 : renderer.onBeforeUpdate) == null ? void 0 : _d.call(renderer, props);
157
+ }
158
+ if (handleChange || handleStart) {
159
+ props.items = await items({
160
+ editor,
161
+ query: state.query
162
+ });
163
+ }
164
+ if (handleExit) {
165
+ (_e = renderer == null ? void 0 : renderer.onExit) == null ? void 0 : _e.call(renderer, props);
166
+ }
167
+ if (handleChange) {
168
+ (_f = renderer == null ? void 0 : renderer.onUpdate) == null ? void 0 : _f.call(renderer, props);
169
+ }
170
+ if (handleStart) {
171
+ (_g = renderer == null ? void 0 : renderer.onStart) == null ? void 0 : _g.call(renderer, props);
172
+ }
235
173
  },
236
- });
237
- return plugin;
174
+ destroy: () => {
175
+ var _a;
176
+ if (!props) {
177
+ return;
178
+ }
179
+ (_a = renderer == null ? void 0 : renderer.onExit) == null ? void 0 : _a.call(renderer, props);
180
+ }
181
+ };
182
+ },
183
+ state: {
184
+ // Initialize the plugin's internal state.
185
+ init() {
186
+ const state = {
187
+ active: false,
188
+ range: {
189
+ from: 0,
190
+ to: 0
191
+ },
192
+ query: null,
193
+ text: null,
194
+ composing: false
195
+ };
196
+ return state;
197
+ },
198
+ // Apply changes to the plugin state from a view transaction.
199
+ apply(transaction, prev, _oldState, state) {
200
+ const { isEditable } = editor;
201
+ const { composing } = editor.view;
202
+ const { selection } = transaction;
203
+ const { empty, from } = selection;
204
+ const next = { ...prev };
205
+ next.composing = composing;
206
+ if (isEditable && (empty || editor.view.composing)) {
207
+ if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {
208
+ next.active = false;
209
+ }
210
+ const match = findSuggestionMatch2({
211
+ char,
212
+ allowSpaces,
213
+ allowToIncludeChar,
214
+ allowedPrefixes,
215
+ startOfLine,
216
+ $position: selection.$from
217
+ });
218
+ const decorationId = `id_${Math.floor(Math.random() * 4294967295)}`;
219
+ if (match && allow({
220
+ editor,
221
+ state,
222
+ range: match.range,
223
+ isActive: prev.active
224
+ })) {
225
+ next.active = true;
226
+ next.decorationId = prev.decorationId ? prev.decorationId : decorationId;
227
+ next.range = match.range;
228
+ next.query = match.query;
229
+ next.text = match.text;
230
+ } else {
231
+ next.active = false;
232
+ }
233
+ } else {
234
+ next.active = false;
235
+ }
236
+ if (!next.active) {
237
+ next.decorationId = null;
238
+ next.range = { from: 0, to: 0 };
239
+ next.query = null;
240
+ next.text = null;
241
+ }
242
+ return next;
243
+ }
244
+ },
245
+ props: {
246
+ // Call the keydown hook if suggestion is active.
247
+ handleKeyDown(view, event) {
248
+ var _a;
249
+ const { active, range } = plugin.getState(view.state);
250
+ if (!active) {
251
+ return false;
252
+ }
253
+ return ((_a = renderer == null ? void 0 : renderer.onKeyDown) == null ? void 0 : _a.call(renderer, { view, event, range })) || false;
254
+ },
255
+ // Setup decorator on the currently active suggestion.
256
+ decorations(state) {
257
+ const { active, range, decorationId } = plugin.getState(state);
258
+ if (!active) {
259
+ return null;
260
+ }
261
+ return import_view.DecorationSet.create(state.doc, [
262
+ import_view.Decoration.inline(range.from, range.to, {
263
+ nodeName: decorationTag,
264
+ class: decorationClass,
265
+ "data-decoration-id": decorationId
266
+ })
267
+ ]);
268
+ }
269
+ }
270
+ });
271
+ return plugin;
238
272
  }
239
273
 
240
- exports.Suggestion = Suggestion;
241
- exports.SuggestionPluginKey = SuggestionPluginKey;
242
- exports.default = Suggestion;
243
- exports.findSuggestionMatch = findSuggestionMatch;
244
- //# sourceMappingURL=index.cjs.map
274
+ // src/index.ts
275
+ var src_default = Suggestion;
276
+ // Annotate the CommonJS export names for ESM import in node:
277
+ 0 && (module.exports = {
278
+ Suggestion,
279
+ SuggestionPluginKey,
280
+ findSuggestionMatch
281
+ });
282
+ //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/findSuggestionMatch.ts","../src/suggestion.ts"],"sourcesContent":["import { escapeForRegEx, Range } from '@tiptap/core'\nimport { ResolvedPos } from '@tiptap/pm/model'\n\nexport interface Trigger {\n char: string\n allowSpaces: boolean\n allowedPrefixes: string[] | null\n startOfLine: boolean\n $position: ResolvedPos\n}\n\nexport type SuggestionMatch = {\n range: Range\n query: string\n text: string\n} | null\n\nexport function findSuggestionMatch(config: Trigger): SuggestionMatch {\n const {\n char, allowSpaces, allowedPrefixes, startOfLine, $position,\n } = config\n\n const escapedChar = escapeForRegEx(char)\n const suffix = new RegExp(`\\\\s${escapedChar}$`)\n const prefix = startOfLine ? '^' : ''\n const regexp = allowSpaces\n ? new RegExp(`${prefix}${escapedChar}.*?(?=\\\\s${escapedChar}|$)`, 'gm')\n : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\\\s${escapedChar}]*`, 'gm')\n\n const text = $position.nodeBefore?.isText && $position.nodeBefore.text\n\n if (!text) {\n return null\n }\n\n const textFrom = $position.pos - text.length\n const match = Array.from(text.matchAll(regexp)).pop()\n\n if (!match || match.input === undefined || match.index === undefined) {\n return null\n }\n\n // JavaScript doesn't have lookbehinds. This hacks a check that first character\n // is a space or the start of the line\n const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index)\n const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes?.join('')}\\0]?$`).test(matchPrefix)\n\n if (allowedPrefixes !== null && !matchPrefixIsAllowed) {\n return null\n }\n\n // The absolute position of the match in the document\n const from = textFrom + match.index\n let to = from + match[0].length\n\n // Edge case handling; if spaces are allowed and we're directly in between\n // two triggers\n if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) {\n match[0] += ' '\n to += 1\n }\n\n // If the $position is located within the matched substring, return that range\n if (from < $position.pos && to >= $position.pos) {\n return {\n range: {\n from,\n to,\n },\n query: match[0].slice(char.length),\n text: match[0],\n }\n }\n\n return null\n}\n","import { Editor, Range } from '@tiptap/core'\nimport { EditorState, Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet, EditorView } from '@tiptap/pm/view'\n\nimport { findSuggestionMatch as defaultFindSuggestionMatch } from './findSuggestionMatch.js'\n\nexport interface SuggestionOptions<I = any, TSelected = any> {\n /**\n * The plugin key for the suggestion plugin.\n * @default 'suggestion'\n * @example 'mention'\n */\n pluginKey?: PluginKey\n\n /**\n * The editor instance.\n * @default null\n */\n editor: Editor\n\n /**\n * The character that triggers the suggestion.\n * @default '@'\n * @example '#'\n */\n char?: string\n\n /**\n * Allow spaces in the suggestion query.\n * @default false\n * @example true\n */\n allowSpaces?: boolean\n\n /**\n * Allow prefixes in the suggestion query.\n * @default [' ']\n * @example [' ', '@']\n */\n allowedPrefixes?: string[] | null\n\n /**\n * Only match suggestions at the start of the line.\n * @default false\n * @example true\n */\n startOfLine?: boolean\n\n /**\n * The tag name of the decoration node.\n * @default 'span'\n * @example 'div'\n */\n decorationTag?: string\n\n /**\n * The class name of the decoration node.\n * @default 'suggestion'\n * @example 'mention'\n */\n decorationClass?: string\n\n /**\n * A function that is called when a suggestion is selected.\n * @param props The props object.\n * @param props.editor The editor instance.\n * @param props.range The range of the suggestion.\n * @param props.props The props of the selected suggestion.\n * @returns void\n * @example ({ editor, range, props }) => { props.command(props.props) }\n */\n command?: (props: { editor: Editor; range: Range; props: TSelected }) => void\n\n /**\n * A function that returns the suggestion items in form of an array.\n * @param props The props object.\n * @param props.editor The editor instance.\n * @param props.query The current suggestion query.\n * @returns An array of suggestion items.\n * @example ({ editor, query }) => [{ id: 1, label: 'John Doe' }]\n */\n items?: (props: { query: string; editor: Editor }) => I[] | Promise<I[]>\n\n /**\n * The render function for the suggestion.\n * @returns An object with render functions.\n */\n render?: () => {\n onBeforeStart?: (props: SuggestionProps<I, TSelected>) => void;\n onStart?: (props: SuggestionProps<I, TSelected>) => void;\n onBeforeUpdate?: (props: SuggestionProps<I, TSelected>) => void;\n onUpdate?: (props: SuggestionProps<I, TSelected>) => void;\n onExit?: (props: SuggestionProps<I, TSelected>) => void;\n onKeyDown?: (props: SuggestionKeyDownProps) => boolean;\n }\n\n /**\n * A function that returns a boolean to indicate if the suggestion should be active.\n * @param props The props object.\n * @returns {boolean}\n */\n allow?: (props: { editor: Editor; state: EditorState; range: Range, isActive?: boolean }) => boolean\n findSuggestionMatch?: typeof defaultFindSuggestionMatch\n}\n\nexport interface SuggestionProps<I = any, TSelected = any> {\n /**\n * The editor instance.\n */\n editor: Editor\n\n /**\n * The range of the suggestion.\n */\n range: Range\n\n /**\n * The current suggestion query.\n */\n query: string\n\n /**\n * The current suggestion text.\n */\n text: string\n\n /**\n * The suggestion items array.\n */\n items: I[]\n\n /**\n * A function that is called when a suggestion is selected.\n * @param props The props object.\n * @returns void\n */\n command: (props: TSelected) => void\n\n /**\n * The decoration node HTML element\n * @default null\n */\n decorationNode: Element | null\n\n /**\n * The function that returns the client rect\n * @default null\n * @example () => new DOMRect(0, 0, 0, 0)\n */\n clientRect?: (() => DOMRect | null) | null\n}\n\nexport interface SuggestionKeyDownProps {\n view: EditorView\n event: KeyboardEvent\n range: Range\n}\n\nexport const SuggestionPluginKey = new PluginKey('suggestion')\n\n/**\n * This utility allows you to create suggestions.\n * @see https://tiptap.dev/api/utilities/suggestion\n */\nexport function Suggestion<I = any, TSelected = any>({\n pluginKey = SuggestionPluginKey,\n editor,\n char = '@',\n allowSpaces = false,\n allowedPrefixes = [' '],\n startOfLine = false,\n decorationTag = 'span',\n decorationClass = 'suggestion',\n command = () => null,\n items = () => [],\n render = () => ({}),\n allow = () => true,\n findSuggestionMatch = defaultFindSuggestionMatch,\n}: SuggestionOptions<I, TSelected>) {\n let props: SuggestionProps<I, TSelected> | undefined\n const renderer = render?.()\n\n const plugin: Plugin<any> = new Plugin({\n key: pluginKey,\n\n view() {\n return {\n update: async (view, prevState) => {\n const prev = this.key?.getState(prevState)\n const next = this.key?.getState(view.state)\n\n // See how the state changed\n const moved = prev.active && next.active && prev.range.from !== next.range.from\n const started = !prev.active && next.active\n const stopped = prev.active && !next.active\n const changed = !started && !stopped && prev.query !== next.query\n\n const handleStart = started\n const handleChange = changed || moved\n const handleExit = stopped\n\n // Cancel when suggestion isn't active\n if (!handleStart && !handleChange && !handleExit) {\n return\n }\n\n const state = handleExit && !handleStart ? prev : next\n const decorationNode = view.dom.querySelector(\n `[data-decoration-id=\"${state.decorationId}\"]`,\n )\n\n props = {\n editor,\n range: state.range,\n query: state.query,\n text: state.text,\n items: [],\n command: commandProps => {\n return command({\n editor,\n range: state.range,\n props: commandProps,\n })\n },\n decorationNode,\n // virtual node for positioning\n // this can be used for building popups without a DOM node\n clientRect: decorationNode\n ? () => {\n // because of `items` can be asynchrounous we’ll search for the current decoration node\n const { decorationId } = this.key?.getState(editor.state) // eslint-disable-line\n const currentDecorationNode = view.dom.querySelector(\n `[data-decoration-id=\"${decorationId}\"]`,\n )\n\n return currentDecorationNode?.getBoundingClientRect() || null\n }\n : null,\n }\n\n if (handleStart) {\n renderer?.onBeforeStart?.(props)\n }\n\n if (handleChange) {\n renderer?.onBeforeUpdate?.(props)\n }\n\n if (handleChange || handleStart) {\n props.items = await items({\n editor,\n query: state.query,\n })\n }\n\n if (handleExit) {\n renderer?.onExit?.(props)\n }\n\n if (handleChange) {\n renderer?.onUpdate?.(props)\n }\n\n if (handleStart) {\n renderer?.onStart?.(props)\n }\n },\n\n destroy: () => {\n if (!props) {\n return\n }\n\n renderer?.onExit?.(props)\n },\n }\n },\n\n state: {\n // Initialize the plugin's internal state.\n init() {\n const state: {\n active: boolean\n range: Range\n query: null | string\n text: null | string\n composing: boolean\n decorationId?: string | null\n } = {\n active: false,\n range: {\n from: 0,\n to: 0,\n },\n query: null,\n text: null,\n composing: false,\n }\n\n return state\n },\n\n // Apply changes to the plugin state from a view transaction.\n apply(transaction, prev, _oldState, state) {\n const { isEditable } = editor\n const { composing } = editor.view\n const { selection } = transaction\n const { empty, from } = selection\n const next = { ...prev }\n\n next.composing = composing\n\n // We can only be suggesting if the view is editable, and:\n // * there is no selection, or\n // * a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)\n if (isEditable && (empty || editor.view.composing)) {\n // Reset active state if we just left the previous suggestion range\n if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {\n next.active = false\n }\n\n // Try to match against where our cursor currently is\n const match = findSuggestionMatch({\n char,\n allowSpaces,\n allowedPrefixes,\n startOfLine,\n $position: selection.$from,\n })\n const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`\n\n // If we found a match, update the current state to show it\n if (match && allow({\n editor, state, range: match.range, isActive: prev.active,\n })) {\n next.active = true\n next.decorationId = prev.decorationId ? prev.decorationId : decorationId\n next.range = match.range\n next.query = match.query\n next.text = match.text\n } else {\n next.active = false\n }\n } else {\n next.active = false\n }\n\n // Make sure to empty the range if suggestion is inactive\n if (!next.active) {\n next.decorationId = null\n next.range = { from: 0, to: 0 }\n next.query = null\n next.text = null\n }\n\n return next\n },\n },\n\n props: {\n // Call the keydown hook if suggestion is active.\n handleKeyDown(view, event) {\n const { active, range } = plugin.getState(view.state)\n\n if (!active) {\n return false\n }\n\n return renderer?.onKeyDown?.({ view, event, range }) || false\n },\n\n // Setup decorator on the currently active suggestion.\n decorations(state) {\n const { active, range, decorationId } = plugin.getState(state)\n\n if (!active) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(range.from, range.to, {\n nodeName: decorationTag,\n class: decorationClass,\n 'data-decoration-id': decorationId,\n }),\n ])\n },\n },\n })\n\n return plugin\n}\n"],"names":["escapeForRegEx","PluginKey","findSuggestionMatch","defaultFindSuggestionMatch","Plugin","DecorationSet","Decoration"],"mappings":";;;;;;;;AAiBM,SAAU,mBAAmB,CAAC,MAAe,EAAA;;AACjD,IAAA,MAAM,EACJ,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,GAC3D,GAAG,MAAM,CAAA;AAEV,IAAA,MAAM,WAAW,GAAGA,mBAAc,CAAC,IAAI,CAAC,CAAA;IACxC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,CAAM,GAAA,EAAA,WAAW,CAAG,CAAA,CAAA,CAAC,CAAA;IAC/C,MAAM,MAAM,GAAG,WAAW,GAAG,GAAG,GAAG,EAAE,CAAA;IACrC,MAAM,MAAM,GAAG,WAAW;AACxB,UAAE,IAAI,MAAM,CAAC,CAAG,EAAA,MAAM,CAAG,EAAA,WAAW,CAAY,SAAA,EAAA,WAAW,CAAK,GAAA,CAAA,EAAE,IAAI,CAAC;AACvE,UAAE,IAAI,MAAM,CAAC,GAAG,MAAM,CAAA,MAAA,EAAS,WAAW,CAAA,KAAA,EAAQ,WAAW,CAAA,EAAA,CAAI,EAAE,IAAI,CAAC,CAAA;AAE1E,IAAA,MAAM,IAAI,GAAG,CAAA,CAAA,EAAA,GAAA,SAAS,CAAC,UAAU,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,MAAM,KAAI,SAAS,CAAC,UAAU,CAAC,IAAI,CAAA;IAEtE,IAAI,CAAC,IAAI,EAAE;AACT,QAAA,OAAO,IAAI,CAAA;KACZ;IAED,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,GAAG,IAA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estion } from './suggestion.js'\n\nexport * from './findSuggestionMatch.js'\nexport * from './suggestion.js'\n\nexport default Suggestion\n","import { Editor, Range } from '@tiptap/core'\nimport { EditorState, Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet, EditorView } from '@tiptap/pm/view'\n\nimport { findSuggestionMatch as defaultFindSuggestionMatch } from './findSuggestionMatch.js'\n\nexport interface SuggestionOptions<I = any, TSelected = any> {\n /**\n * The plugin key for the suggestion plugin.\n * @default 'suggestion'\n * @example 'mention'\n */\n pluginKey?: PluginKey\n\n /**\n * The editor instance.\n * @default null\n */\n editor: Editor\n\n /**\n * The character that triggers the suggestion.\n * @default '@'\n * @example '#'\n */\n char?: string\n\n /**\n * Allow spaces in the suggestion query. Not compatible with `allowToIncludeChar`. Will be disabled if `allowToIncludeChar` is set to `true`.\n * @default false\n * @example true\n */\n allowSpaces?: boolean\n\n /**\n * Allow the character to be included in the suggestion query. Not compatible with `allowSpaces`.\n * @default false\n */\n allowToIncludeChar?: boolean\n\n /**\n * Allow prefixes in the suggestion query.\n * @default [' ']\n * @example [' ', '@']\n */\n allowedPrefixes?: string[] | null\n\n /**\n * Only match suggestions at the start of the line.\n * @default false\n * @example true\n */\n startOfLine?: boolean\n\n /**\n * The tag name of the decoration node.\n * @default 'span'\n * @example 'div'\n */\n decorationTag?: string\n\n /**\n * The class name of the decoration node.\n * @default 'suggestion'\n * @example 'mention'\n */\n decorationClass?: string\n\n /**\n * A function that is called when a suggestion is selected.\n * @param props The props object.\n * @param props.editor The editor instance.\n * @param props.range The range of the suggestion.\n * @param props.props The props of the selected suggestion.\n * @returns void\n * @example ({ editor, range, props }) => { props.command(props.props) }\n */\n command?: (props: { editor: Editor; range: Range; props: TSelected }) => void\n\n /**\n * A function that returns the suggestion items in form of an array.\n * @param props The props object.\n * @param props.editor The editor instance.\n * @param props.query The current suggestion query.\n * @returns An array of suggestion items.\n * @example ({ editor, query }) => [{ id: 1, label: 'John Doe' }]\n */\n items?: (props: { query: string; editor: Editor }) => I[] | Promise<I[]>\n\n /**\n * The render function for the suggestion.\n * @returns An object with render functions.\n */\n render?: () => {\n onBeforeStart?: (props: SuggestionProps<I, TSelected>) => void;\n onStart?: (props: SuggestionProps<I, TSelected>) => void;\n onBeforeUpdate?: (props: SuggestionProps<I, TSelected>) => void;\n onUpdate?: (props: SuggestionProps<I, TSelected>) => void;\n onExit?: (props: SuggestionProps<I, TSelected>) => void;\n onKeyDown?: (props: SuggestionKeyDownProps) => boolean;\n }\n\n /**\n * A function that returns a boolean to indicate if the suggestion should be active.\n * @param props The props object.\n * @returns {boolean}\n */\n allow?: (props: { editor: Editor; state: EditorState; range: Range, isActive?: boolean }) => boolean\n findSuggestionMatch?: typeof defaultFindSuggestionMatch\n}\n\nexport interface SuggestionProps<I = any, TSelected = any> {\n /**\n * The editor instance.\n */\n editor: Editor\n\n /**\n * The range of the suggestion.\n */\n range: Range\n\n /**\n * The current suggestion query.\n */\n query: string\n\n /**\n * The current suggestion text.\n */\n text: string\n\n /**\n * The suggestion items array.\n */\n items: I[]\n\n /**\n * A function that is called when a suggestion is selected.\n * @param props The props object.\n * @returns void\n */\n command: (props: TSelected) => void\n\n /**\n * The decoration node HTML element\n * @default null\n */\n decorationNode: Element | null\n\n /**\n * The function that returns the client rect\n * @default null\n * @example () => new DOMRect(0, 0, 0, 0)\n */\n clientRect?: (() => DOMRect | null) | null\n}\n\nexport interface SuggestionKeyDownProps {\n view: EditorView\n event: KeyboardEvent\n range: Range\n}\n\nexport const SuggestionPluginKey = new PluginKey('suggestion')\n\n/**\n * This utility allows you to create suggestions.\n * @see https://tiptap.dev/api/utilities/suggestion\n */\nexport function Suggestion<I = any, TSelected = any>({\n pluginKey = SuggestionPluginKey,\n editor,\n char = '@',\n allowSpaces = false,\n allowToIncludeChar = false,\n allowedPrefixes = [' '],\n startOfLine = false,\n decorationTag = 'span',\n decorationClass = 'suggestion',\n command = () => null,\n items = () => [],\n render = () => ({}),\n allow = () => true,\n findSuggestionMatch = defaultFindSuggestionMatch,\n}: SuggestionOptions<I, TSelected>) {\n let props: SuggestionProps<I, TSelected> | undefined\n const renderer = render?.()\n\n const plugin: Plugin<any> = new Plugin({\n key: pluginKey,\n\n view() {\n return {\n update: async (view, prevState) => {\n const prev = this.key?.getState(prevState)\n const next = this.key?.getState(view.state)\n\n // See how the state changed\n const moved = prev.active && next.active && prev.range.from !== next.range.from\n const started = !prev.active && next.active\n const stopped = prev.active && !next.active\n const changed = !started && !stopped && prev.query !== next.query\n\n const handleStart = started || (moved && changed)\n const handleChange = changed || moved\n const handleExit = stopped || (moved && changed)\n\n // Cancel when suggestion isn't active\n if (!handleStart && !handleChange && !handleExit) {\n return\n }\n\n const state = handleExit && !handleStart ? prev : next\n const decorationNode = view.dom.querySelector(\n `[data-decoration-id=\"${state.decorationId}\"]`,\n )\n\n props = {\n editor,\n range: state.range,\n query: state.query,\n text: state.text,\n items: [],\n command: commandProps => {\n return command({\n editor,\n range: state.range,\n props: commandProps,\n })\n },\n decorationNode,\n // virtual node for positioning\n // this can be used for building popups without a DOM node\n clientRect: decorationNode\n ? () => {\n // because of `items` can be asynchrounous we’ll search for the current decoration node\n const { decorationId } = this.key?.getState(editor.state) // eslint-disable-line\n const currentDecorationNode = view.dom.querySelector(\n `[data-decoration-id=\"${decorationId}\"]`,\n )\n\n return currentDecorationNode?.getBoundingClientRect() || null\n }\n : null,\n }\n\n if (handleStart) {\n renderer?.onBeforeStart?.(props)\n }\n\n if (handleChange) {\n renderer?.onBeforeUpdate?.(props)\n }\n\n if (handleChange || handleStart) {\n props.items = await items({\n editor,\n query: state.query,\n })\n }\n\n if (handleExit) {\n renderer?.onExit?.(props)\n }\n\n if (handleChange) {\n renderer?.onUpdate?.(props)\n }\n\n if (handleStart) {\n renderer?.onStart?.(props)\n }\n },\n\n destroy: () => {\n if (!props) {\n return\n }\n\n renderer?.onExit?.(props)\n },\n }\n },\n\n state: {\n // Initialize the plugin's internal state.\n init() {\n const state: {\n active: boolean\n range: Range\n query: null | string\n text: null | string\n composing: boolean\n decorationId?: string | null\n } = {\n active: false,\n range: {\n from: 0,\n to: 0,\n },\n query: null,\n text: null,\n composing: false,\n }\n\n return state\n },\n\n // Apply changes to the plugin state from a view transaction.\n apply(transaction, prev, _oldState, state) {\n const { isEditable } = editor\n const { composing } = editor.view\n const { selection } = transaction\n const { empty, from } = selection\n const next = { ...prev }\n\n next.composing = composing\n\n // We can only be suggesting if the view is editable, and:\n // * there is no selection, or\n // * a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)\n if (isEditable && (empty || editor.view.composing)) {\n // Reset active state if we just left the previous suggestion range\n if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {\n next.active = false\n }\n\n // Try to match against where our cursor currently is\n const match = findSuggestionMatch({\n char,\n allowSpaces,\n allowToIncludeChar,\n allowedPrefixes,\n startOfLine,\n $position: selection.$from,\n })\n const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`\n\n // If we found a match, update the current state to show it\n if (match && allow({\n editor, state, range: match.range, isActive: prev.active,\n })) {\n next.active = true\n next.decorationId = prev.decorationId ? prev.decorationId : decorationId\n next.range = match.range\n next.query = match.query\n next.text = match.text\n } else {\n next.active = false\n }\n } else {\n next.active = false\n }\n\n // Make sure to empty the range if suggestion is inactive\n if (!next.active) {\n next.decorationId = null\n next.range = { from: 0, to: 0 }\n next.query = null\n next.text = null\n }\n\n return next\n },\n },\n\n props: {\n // Call the keydown hook if suggestion is active.\n handleKeyDown(view, event) {\n const { active, range } = plugin.getState(view.state)\n\n if (!active) {\n return false\n }\n\n return renderer?.onKeyDown?.({ view, event, range }) || false\n },\n\n // Setup decorator on the currently active suggestion.\n decorations(state) {\n const { active, range, decorationId } = plugin.getState(state)\n\n if (!active) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(range.from, range.to, {\n nodeName: decorationTag,\n class: decorationClass,\n 'data-decoration-id': decorationId,\n }),\n ])\n },\n },\n })\n\n return plugin\n}\n","import { escapeForRegEx, Range } from '@tiptap/core'\nimport { ResolvedPos } from '@tiptap/pm/model'\n\nexport interface Trigger {\n char: string\n allowSpaces: boolean\n allowToIncludeChar: boolean\n allowedPrefixes: string[] | null\n startOfLine: boolean\n $position: ResolvedPos\n}\n\nexport type SuggestionMatch = {\n range: Range\n query: string\n text: string\n} | null\n\nexport function findSuggestionMatch(config: Trigger): SuggestionMatch {\n const {\n char, allowSpaces: allowSpacesOption, allowToIncludeChar, allowedPrefixes, startOfLine, $position,\n } = config\n\n const allowSpaces = allowSpacesOption && !allowToIncludeChar\n\n const escapedChar = escapeForRegEx(char)\n const suffix = new RegExp(`\\\\s${escapedChar}$`)\n const prefix = startOfLine ? '^' : ''\n const finalEscapedChar = allowToIncludeChar ? '' : escapedChar\n const regexp = allowSpaces\n ? new RegExp(`${prefix}${escapedChar}.*?(?=\\\\s${finalEscapedChar}|$)`, 'gm')\n : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\\\s${finalEscapedChar}]*`, 'gm')\n\n const text = $position.nodeBefore?.isText && $position.nodeBefore.text\n\n if (!text) {\n return null\n }\n\n const textFrom = $position.pos - text.length\n const match = Array.from(text.matchAll(regexp)).pop()\n\n if (!match || match.input === undefined || match.index === undefined) {\n return null\n }\n\n // JavaScript doesn't have lookbehinds. This hacks a check that first character\n // is a space or the start of the line\n const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index)\n const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes?.join('')}\\0]?$`).test(matchPrefix)\n\n if (allowedPrefixes !== null && !matchPrefixIsAllowed) {\n return null\n }\n\n // The absolute position of the match in the document\n const from = textFrom + match.index\n let to = from + match[0].length\n\n // Edge case handling; if spaces are allowed and we're directly in between\n // two triggers\n if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) {\n match[0] += ' '\n to += 1\n }\n\n // If the $position is located within the matched substring, return that range\n if (from < $position.pos && to >= $position.pos) {\n return {\n range: {\n from,\n to,\n },\n query: match[0].slice(char.length),\n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