@tiptap/suggestion 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.
Files changed (176) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +5 -1
  3. package/dist/index.cjs +268 -233
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/{packages/suggestion/src/suggestion.d.ts → index.d.cts} +46 -11
  6. package/dist/index.d.ts +188 -0
  7. package/dist/index.js +241 -228
  8. package/dist/index.js.map +1 -1
  9. package/package.json +13 -11
  10. package/src/findSuggestionMatch.ts +10 -7
  11. package/src/suggestion.ts +65 -29
  12. package/dist/index.umd.js +0 -246
  13. package/dist/index.umd.js.map +0 -1
  14. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  15. package/dist/packages/core/src/Editor.d.ts +0 -161
  16. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  17. package/dist/packages/core/src/Extension.d.ts +0 -343
  18. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  19. package/dist/packages/core/src/InputRule.d.ts +0 -42
  20. package/dist/packages/core/src/Mark.d.ts +0 -451
  21. package/dist/packages/core/src/Node.d.ts +0 -611
  22. package/dist/packages/core/src/NodePos.d.ts +0 -44
  23. package/dist/packages/core/src/NodeView.d.ts +0 -31
  24. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  25. package/dist/packages/core/src/Tracker.d.ts +0 -11
  26. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  27. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  28. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  29. package/dist/packages/core/src/commands/command.d.ts +0 -18
  30. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  31. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  32. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  33. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  34. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  35. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  36. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  37. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  38. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  39. package/dist/packages/core/src/commands/first.d.ts +0 -14
  40. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  41. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  42. package/dist/packages/core/src/commands/index.d.ts +0 -55
  43. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  44. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  45. package/dist/packages/core/src/commands/join.d.ts +0 -41
  46. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  47. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  48. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  49. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  50. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  51. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  52. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  53. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  54. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  55. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  56. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  57. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  58. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  59. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  60. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  61. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  62. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  63. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  64. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  65. package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
  66. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  67. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  68. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  69. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  70. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  71. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
  72. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  73. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  74. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  75. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  76. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  77. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  78. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  79. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  80. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  81. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  82. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  83. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  84. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  85. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  86. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  87. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  88. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  89. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  90. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  91. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  92. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  93. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  94. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  95. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  96. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  97. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  98. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  99. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  100. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  101. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  102. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  103. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  104. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  105. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  106. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  107. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  108. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  109. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  110. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  111. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  112. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  113. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  114. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  115. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  116. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  117. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  118. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  119. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  120. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  121. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  122. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  123. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  124. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  125. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  126. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  127. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  128. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  129. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  130. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  131. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  132. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  133. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
  134. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  135. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  136. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  137. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  138. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  139. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  140. package/dist/packages/core/src/index.d.ts +0 -24
  141. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  142. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  143. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  144. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  145. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  146. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  147. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  148. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  149. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
  150. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  151. package/dist/packages/core/src/style.d.ts +0 -1
  152. package/dist/packages/core/src/types.d.ts +0 -255
  153. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  154. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  155. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  156. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  157. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  158. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  159. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  160. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  161. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  162. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  163. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  164. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  165. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  166. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  167. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  168. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  169. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  170. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  171. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  172. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  173. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  174. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  175. package/dist/packages/suggestion/src/findSuggestionMatch.d.ts +0 -15
  176. package/dist/packages/suggestion/src/index.d.ts +0 -4
@@ -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 popper.js or tippy.js\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,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AAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,KAAI,KAAK,CAAA;aAC9D;;AAGD,YAAA,WAAW,CAAC,KAAK,EAAA;AACf,gBAAA,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;gBAE9D,IAAI,CAAC,MAAM,EAAE;AACX,oBAAA,OAAO,IAAI,CAAA;iBACZ;AAED,gBAAA,OAAOG,kBAAa,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;oBACrCC,eAAU,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE;AACtC,wBAAA,QAAQ,EAAE,aAAa;AACvB,wBAAA,KAAK,EAAE,eAAe;AACtB,wBAAA,oBAAoB,EAAE,YAAY;qBACnC,CAAC;AACH,iBAAA,CAAC,CAAA;aACH;AACF,SAAA;AACF,KAAA,CAAC,CAAA;AAEF,IAAA,OAAO,MAAM,CAAA;AACf;;;;;;;"}
1
+ {"version":3,"sources":["../src/index.ts","../src/suggestion.ts","../src/findSuggestionMatch.ts"],"sourcesContent":["import { Suggestion } from './suggestion.js'\n\nexport * from './findSuggestionMatch.js'\nexport * from './suggestion.js'\n\nexport default Suggestion\n","import type { Editor, Range } from '@tiptap/core'\nimport type { EditorState } from '@tiptap/pm/state'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { EditorView } from '@tiptap/pm/view'\nimport { Decoration, DecorationSet } 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 * Creates a decoration with the provided content.\n * @param decorationContent - The content to display in the decoration\n * @default \"\" - Creates an empty decoration if no content provided\n */\n decorationContent?: string\n\n /**\n * The class name of the decoration node when it is empty.\n * @default 'is-empty'\n * @example 'is-empty'\n */\n decorationEmptyClass?: 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 decorationContent = '',\n decorationEmptyClass = 'is-empty',\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(`[data-decoration-id=\"${state.decorationId}\"]`)\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(`[data-decoration-id=\"${decorationId}\"]`)\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 (\n match &&\n allow({\n editor,\n state,\n range: match.range,\n isActive: prev.active,\n })\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, query } = plugin.getState(state)\n\n if (!active) {\n return null\n }\n\n const isEmpty = !query?.length\n const classNames = [decorationClass]\n\n if (isEmpty) {\n classNames.push(decorationEmptyClass)\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(range.from, range.to, {\n nodeName: decorationTag,\n class: classNames.join(' '),\n 'data-decoration-id': decorationId,\n 'data-decoration-content': decorationContent,\n }),\n ])\n },\n },\n })\n\n return plugin\n}\n","import type { Range } from '@tiptap/core'\nimport { escapeForRegEx } from '@tiptap/core'\nimport type { 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 { char, allowSpaces: allowSpacesOption, allowToIncludeChar, allowedPrefixes, startOfLine, $position } = 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 text: match[0],\n }\n }\n\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,mBAAkC;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EAAE,MAAM,GAAG,IAAI,EAAE;AAC9B,eAAK,QAAQ;AACb,eAAK,OAAO;AAAA,QACd;AAEA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,OAAO;AAAA;AAAA,MAEL,cAAc,MAAM,OAAO;AArYjC;AAsYQ,cAAM,EAAE,QAAQ,MAAM,IAAI,OAAO,SAAS,KAAK,KAAK;AAEpD,YAAI,CAAC,QAAQ;AACX,iBAAO;AAAA,QACT;AAEA,iBAAO,0CAAU,cAAV,kCAAsB,EAAE,MAAM,OAAO,MAAM,OAAM;AAAA,MAC1D;AAAA;AAAA,MAGA,YAAY,OAAO;AACjB,cAAM,EAAE,QAAQ,OAAO,cAAc,MAAM,IAAI,OAAO,SAAS,KAAK;AAEpE,YAAI,CAAC,QAAQ;AACX,iBAAO;AAAA,QACT;AAEA,cAAM,UAAU,EAAC,+BAAO;AACxB,cAAM,aAAa,CAAC,eAAe;AAEnC,YAAI,SAAS;AACX,qBAAW,KAAK,oBAAoB;AAAA,QACtC;AAEA,eAAO,0BAAc,OAAO,MAAM,KAAK;AAAA,UACrC,uBAAW,OAAO,MAAM,MAAM,MAAM,IAAI;AAAA,YACtC,UAAU;AAAA,YACV,OAAO,WAAW,KAAK,GAAG;AAAA,YAC1B,sBAAsB;AAAA,YACtB,2BAA2B;AAAA,UAC7B,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;ADtaA,IAAO,gBAAQ;","names":["findSuggestionMatch","_a"]}
@@ -1,8 +1,24 @@
1
- import { Editor, Range } from '@tiptap/core';
2
- import { EditorState, Plugin, PluginKey } from '@tiptap/pm/state';
1
+ import { Range, Editor } from '@tiptap/core';
2
+ import { PluginKey, EditorState, Plugin } from '@tiptap/pm/state';
3
3
  import { EditorView } from '@tiptap/pm/view';
4
- import { findSuggestionMatch as defaultFindSuggestionMatch } from './findSuggestionMatch.js';
5
- export interface SuggestionOptions<I = any, TSelected = any> {
4
+ import { ResolvedPos } from '@tiptap/pm/model';
5
+
6
+ interface Trigger {
7
+ char: string;
8
+ allowSpaces: boolean;
9
+ allowToIncludeChar: boolean;
10
+ allowedPrefixes: string[] | null;
11
+ startOfLine: boolean;
12
+ $position: ResolvedPos;
13
+ }
14
+ type SuggestionMatch = {
15
+ range: Range;
16
+ query: string;
17
+ text: string;
18
+ } | null;
19
+ declare function findSuggestionMatch(config: Trigger): SuggestionMatch;
20
+
21
+ interface SuggestionOptions<I = any, TSelected = any> {
6
22
  /**
7
23
  * The plugin key for the suggestion plugin.
8
24
  * @default 'suggestion'
@@ -21,11 +37,16 @@ export interface SuggestionOptions<I = any, TSelected = any> {
21
37
  */
22
38
  char?: string;
23
39
  /**
24
- * Allow spaces in the suggestion query.
40
+ * Allow spaces in the suggestion query. Not compatible with `allowToIncludeChar`. Will be disabled if `allowToIncludeChar` is set to `true`.
25
41
  * @default false
26
42
  * @example true
27
- */
43
+ */
28
44
  allowSpaces?: boolean;
45
+ /**
46
+ * Allow the character to be included in the suggestion query. Not compatible with `allowSpaces`.
47
+ * @default false
48
+ */
49
+ allowToIncludeChar?: boolean;
29
50
  /**
30
51
  * Allow prefixes in the suggestion query.
31
52
  * @default [' ']
@@ -50,6 +71,18 @@ export interface SuggestionOptions<I = any, TSelected = any> {
50
71
  * @example 'mention'
51
72
  */
52
73
  decorationClass?: string;
74
+ /**
75
+ * Creates a decoration with the provided content.
76
+ * @param decorationContent - The content to display in the decoration
77
+ * @default "" - Creates an empty decoration if no content provided
78
+ */
79
+ decorationContent?: string;
80
+ /**
81
+ * The class name of the decoration node when it is empty.
82
+ * @default 'is-empty'
83
+ * @example 'is-empty'
84
+ */
85
+ decorationEmptyClass?: string;
53
86
  /**
54
87
  * A function that is called when a suggestion is selected.
55
88
  * @param props The props object.
@@ -99,9 +132,9 @@ export interface SuggestionOptions<I = any, TSelected = any> {
99
132
  range: Range;
100
133
  isActive?: boolean;
101
134
  }) => boolean;
102
- findSuggestionMatch?: typeof defaultFindSuggestionMatch;
135
+ findSuggestionMatch?: typeof findSuggestionMatch;
103
136
  }
104
- export interface SuggestionProps<I = any, TSelected = any> {
137
+ interface SuggestionProps<I = any, TSelected = any> {
105
138
  /**
106
139
  * The editor instance.
107
140
  */
@@ -140,14 +173,16 @@ export interface SuggestionProps<I = any, TSelected = any> {
140
173
  */
141
174
  clientRect?: (() => DOMRect | null) | null;
142
175
  }
143
- export interface SuggestionKeyDownProps {
176
+ interface SuggestionKeyDownProps {
144
177
  view: EditorView;
145
178
  event: KeyboardEvent;
146
179
  range: Range;
147
180
  }
148
- export declare const SuggestionPluginKey: PluginKey<any>;
181
+ declare const SuggestionPluginKey: PluginKey<any>;
149
182
  /**
150
183
  * This utility allows you to create suggestions.
151
184
  * @see https://tiptap.dev/api/utilities/suggestion
152
185
  */
153
- export declare function Suggestion<I = any, TSelected = any>({ pluginKey, editor, char, allowSpaces, allowedPrefixes, startOfLine, decorationTag, decorationClass, command, items, render, allow, findSuggestionMatch, }: SuggestionOptions<I, TSelected>): Plugin<any>;
186
+ declare function Suggestion<I = any, TSelected = any>({ pluginKey, editor, char, allowSpaces, allowToIncludeChar, allowedPrefixes, startOfLine, decorationTag, decorationClass, decorationContent, decorationEmptyClass, command, items, render, allow, findSuggestionMatch, }: SuggestionOptions<I, TSelected>): Plugin<any>;
187
+
188
+ export { Suggestion, type SuggestionKeyDownProps, type SuggestionMatch, type SuggestionOptions, SuggestionPluginKey, type SuggestionProps, type Trigger, Suggestion as default, findSuggestionMatch };
@@ -0,0 +1,188 @@
1
+ import { Range, Editor } from '@tiptap/core';
2
+ import { PluginKey, EditorState, Plugin } from '@tiptap/pm/state';
3
+ import { EditorView } from '@tiptap/pm/view';
4
+ import { ResolvedPos } from '@tiptap/pm/model';
5
+
6
+ interface Trigger {
7
+ char: string;
8
+ allowSpaces: boolean;
9
+ allowToIncludeChar: boolean;
10
+ allowedPrefixes: string[] | null;
11
+ startOfLine: boolean;
12
+ $position: ResolvedPos;
13
+ }
14
+ type SuggestionMatch = {
15
+ range: Range;
16
+ query: string;
17
+ text: string;
18
+ } | null;
19
+ declare function findSuggestionMatch(config: Trigger): SuggestionMatch;
20
+
21
+ interface SuggestionOptions<I = any, TSelected = any> {
22
+ /**
23
+ * The plugin key for the suggestion plugin.
24
+ * @default 'suggestion'
25
+ * @example 'mention'
26
+ */
27
+ pluginKey?: PluginKey;
28
+ /**
29
+ * The editor instance.
30
+ * @default null
31
+ */
32
+ editor: Editor;
33
+ /**
34
+ * The character that triggers the suggestion.
35
+ * @default '@'
36
+ * @example '#'
37
+ */
38
+ char?: string;
39
+ /**
40
+ * Allow spaces in the suggestion query. Not compatible with `allowToIncludeChar`. Will be disabled if `allowToIncludeChar` is set to `true`.
41
+ * @default false
42
+ * @example true
43
+ */
44
+ allowSpaces?: boolean;
45
+ /**
46
+ * Allow the character to be included in the suggestion query. Not compatible with `allowSpaces`.
47
+ * @default false
48
+ */
49
+ allowToIncludeChar?: boolean;
50
+ /**
51
+ * Allow prefixes in the suggestion query.
52
+ * @default [' ']
53
+ * @example [' ', '@']
54
+ */
55
+ allowedPrefixes?: string[] | null;
56
+ /**
57
+ * Only match suggestions at the start of the line.
58
+ * @default false
59
+ * @example true
60
+ */
61
+ startOfLine?: boolean;
62
+ /**
63
+ * The tag name of the decoration node.
64
+ * @default 'span'
65
+ * @example 'div'
66
+ */
67
+ decorationTag?: string;
68
+ /**
69
+ * The class name of the decoration node.
70
+ * @default 'suggestion'
71
+ * @example 'mention'
72
+ */
73
+ decorationClass?: string;
74
+ /**
75
+ * Creates a decoration with the provided content.
76
+ * @param decorationContent - The content to display in the decoration
77
+ * @default "" - Creates an empty decoration if no content provided
78
+ */
79
+ decorationContent?: string;
80
+ /**
81
+ * The class name of the decoration node when it is empty.
82
+ * @default 'is-empty'
83
+ * @example 'is-empty'
84
+ */
85
+ decorationEmptyClass?: string;
86
+ /**
87
+ * A function that is called when a suggestion is selected.
88
+ * @param props The props object.
89
+ * @param props.editor The editor instance.
90
+ * @param props.range The range of the suggestion.
91
+ * @param props.props The props of the selected suggestion.
92
+ * @returns void
93
+ * @example ({ editor, range, props }) => { props.command(props.props) }
94
+ */
95
+ command?: (props: {
96
+ editor: Editor;
97
+ range: Range;
98
+ props: TSelected;
99
+ }) => void;
100
+ /**
101
+ * A function that returns the suggestion items in form of an array.
102
+ * @param props The props object.
103
+ * @param props.editor The editor instance.
104
+ * @param props.query The current suggestion query.
105
+ * @returns An array of suggestion items.
106
+ * @example ({ editor, query }) => [{ id: 1, label: 'John Doe' }]
107
+ */
108
+ items?: (props: {
109
+ query: string;
110
+ editor: Editor;
111
+ }) => I[] | Promise<I[]>;
112
+ /**
113
+ * The render function for the suggestion.
114
+ * @returns An object with render functions.
115
+ */
116
+ render?: () => {
117
+ onBeforeStart?: (props: SuggestionProps<I, TSelected>) => void;
118
+ onStart?: (props: SuggestionProps<I, TSelected>) => void;
119
+ onBeforeUpdate?: (props: SuggestionProps<I, TSelected>) => void;
120
+ onUpdate?: (props: SuggestionProps<I, TSelected>) => void;
121
+ onExit?: (props: SuggestionProps<I, TSelected>) => void;
122
+ onKeyDown?: (props: SuggestionKeyDownProps) => boolean;
123
+ };
124
+ /**
125
+ * A function that returns a boolean to indicate if the suggestion should be active.
126
+ * @param props The props object.
127
+ * @returns {boolean}
128
+ */
129
+ allow?: (props: {
130
+ editor: Editor;
131
+ state: EditorState;
132
+ range: Range;
133
+ isActive?: boolean;
134
+ }) => boolean;
135
+ findSuggestionMatch?: typeof findSuggestionMatch;
136
+ }
137
+ interface SuggestionProps<I = any, TSelected = any> {
138
+ /**
139
+ * The editor instance.
140
+ */
141
+ editor: Editor;
142
+ /**
143
+ * The range of the suggestion.
144
+ */
145
+ range: Range;
146
+ /**
147
+ * The current suggestion query.
148
+ */
149
+ query: string;
150
+ /**
151
+ * The current suggestion text.
152
+ */
153
+ text: string;
154
+ /**
155
+ * The suggestion items array.
156
+ */
157
+ items: I[];
158
+ /**
159
+ * A function that is called when a suggestion is selected.
160
+ * @param props The props object.
161
+ * @returns void
162
+ */
163
+ command: (props: TSelected) => void;
164
+ /**
165
+ * The decoration node HTML element
166
+ * @default null
167
+ */
168
+ decorationNode: Element | null;
169
+ /**
170
+ * The function that returns the client rect
171
+ * @default null
172
+ * @example () => new DOMRect(0, 0, 0, 0)
173
+ */
174
+ clientRect?: (() => DOMRect | null) | null;
175
+ }
176
+ interface SuggestionKeyDownProps {
177
+ view: EditorView;
178
+ event: KeyboardEvent;
179
+ range: Range;
180
+ }
181
+ declare const SuggestionPluginKey: PluginKey<any>;
182
+ /**
183
+ * This utility allows you to create suggestions.
184
+ * @see https://tiptap.dev/api/utilities/suggestion
185
+ */
186
+ declare function Suggestion<I = any, TSelected = any>({ pluginKey, editor, char, allowSpaces, allowToIncludeChar, allowedPrefixes, startOfLine, decorationTag, decorationClass, decorationContent, decorationEmptyClass, command, items, render, allow, findSuggestionMatch, }: SuggestionOptions<I, TSelected>): Plugin<any>;
187
+
188
+ export { Suggestion, type SuggestionKeyDownProps, type SuggestionMatch, type SuggestionOptions, SuggestionPluginKey, type SuggestionProps, type Trigger, Suggestion as default, findSuggestionMatch };