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EL,cAAcH,EAAM6B,EAAK,OACvB,GAAM,CAAE,OAAAC,EAAQ,MAAAC,CAAK,EAAKjC,EAAO,SAASE,EAAK,KAAK,EAEpD,OAAK8B,KAIEvD,EAAAsB,GAAQ,KAAR,OAAAA,EAAU,aAAS,MAAAtB,IAAA,OAAA,OAAAA,EAAA,KAAAsB,EAAG,CAAE,KAAAG,EAAM,MAAA6B,EAAO,MAAAE,CAAK,CAAE,IAAK,IAI1D,YAAYnB,EAAK,CACf,GAAM,CACJ,OAAAkB,EAAQ,MAAAC,EAAO,aAAAhB,EAAc,MAAAiB,CAAK,EAChClC,EAAO,SAASc,CAAK,EAEzB,GAAI,CAACkB,EACH,OAAO,KAGT,IAAMG,EAAU,EAACD,GAAK,MAALA,EAAO,QAClBE,EAAa,CAAC9C,CAAe,EAEnC,OAAI6C,GACFC,EAAW,KAAK5C,CAAoB,EAG/B6C,EAAc,OAAOvB,EAAM,IAAK,CACrCwB,EAAW,OAAOL,EAAM,KAAMA,EAAM,GAAI,CACtC,SAAU5C,EACV,MAAO+C,EAAW,KAAK,GAAG,EAC1B,qBAAsBnB,EACtB,0BAA2B1B,EAC5B,CACF,CAAA,EAEJ,CACF,CAAA,EAED,OAAOS,CACT","names":["findSuggestionMatch","config","char","allowSpacesOption","allowToIncludeChar","allowedPrefixes","startOfLine","$position","allowSpaces","escapedChar","escapeForRegEx","suffix","prefix","finalEscapedChar","regexp","text","_a","textFrom","match","matchPrefix","matchPrefixIsAllowed","from","to","SuggestionPluginKey","PluginKey","Suggestion","pluginKey","editor","decorationTag","decorationClass","decorationContent","decorationEmptyClass","command","items","render","allow","defaultFindSuggestionMatch","props","renderer","plugin","Plugin","view","prevState","prev","next","_b","moved","started","stopped","changed","handleStart","handleChange","handleExit","state","decorationNode","commandProps","decorationId","currentDecorationNode","_c","_d","_e","_f","_g","transaction","_oldState","isEditable","composing","selection","empty","__spreadValues","event","active","range","query","isEmpty","classNames","DecorationSet","Decoration"],"sources":["../esm/npm/@tiptap/suggestion@2.27.3/node_modules/@tiptap/suggestion/src/findSuggestionMatch.ts","../esm/npm/@tiptap/suggestion@2.27.3/node_modules/@tiptap/suggestion/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  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 \u0026\u0026 !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 \u0026\u0026 $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 \u0026\u0026 !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 \u0026\u0026 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 \u003c $position.pos \u0026\u0026 to \u003e= $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 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\u003cI = any, TSelected = any\u003e {\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   * @example 'Type to search...'\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 }) =\u003e { props.command(props.props) }\n   */\n  command?: (props: { editor: Editor; range: Range; props: TSelected }) =\u003e 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 }) =\u003e [{ id: 1, label: 'John Doe' }]\n   */\n  items?: (props: { query: string; editor: Editor }) =\u003e I[] | Promise\u003cI[]\u003e\n\n  /**\n   * The render function for the suggestion.\n   * @returns An object with render functions.\n   */\n  render?: () =\u003e {\n    onBeforeStart?: (props: SuggestionProps\u003cI, TSelected\u003e) =\u003e void\n    onStart?: (props: SuggestionProps\u003cI, TSelected\u003e) =\u003e void\n    onBeforeUpdate?: (props: SuggestionProps\u003cI, TSelected\u003e) =\u003e void\n    onUpdate?: (props: SuggestionProps\u003cI, TSelected\u003e) =\u003e void\n    onExit?: (props: SuggestionProps\u003cI, TSelected\u003e) =\u003e void\n    onKeyDown?: (props: SuggestionKeyDownProps) =\u003e 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: {\n    editor: Editor\n    state: EditorState\n    range: Range\n    isActive?: boolean\n  }) =\u003e boolean\n  findSuggestionMatch?: typeof defaultFindSuggestionMatch\n}\n\nexport interface SuggestionProps\u003cI = any, TSelected = any\u003e {\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) =\u003e 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 () =\u003e new DOMRect(0, 0, 0, 0)\n   */\n  clientRect?: (() =\u003e 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\u003cI = any, TSelected = any\u003e({\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 = () =\u003e null,\n  items = () =\u003e [],\n  render = () =\u003e ({}),\n  allow = () =\u003e true,\n  findSuggestionMatch = defaultFindSuggestionMatch,\n}: SuggestionOptions\u003cI, TSelected\u003e) {\n  let props: SuggestionProps\u003cI, TSelected\u003e | undefined\n  const renderer = render?.()\n\n  const plugin: Plugin\u003cany\u003e = new Plugin({\n    key: pluginKey,\n\n    view() {\n      return {\n        update: async (view, prevState) =\u003e {\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 \u0026\u0026 next.active \u0026\u0026 prev.range.from !== next.range.from\n          const started = !prev.active \u0026\u0026 next.active\n          const stopped = prev.active \u0026\u0026 !next.active\n          const changed = !started \u0026\u0026 !stopped \u0026\u0026 prev.query !== next.query\n\n          const handleStart = started || (moved \u0026\u0026 changed)\n          const handleChange = changed || moved\n          const handleExit = stopped || (moved \u0026\u0026 changed)\n\n          // Cancel when suggestion isn't active\n          if (!handleStart \u0026\u0026 !handleChange \u0026\u0026 !handleExit) {\n            return\n          }\n\n          const state = handleExit \u0026\u0026 !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 =\u003e {\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              ? () =\u003e {\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: () =\u003e {\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 \u0026\u0026 (empty || editor.view.composing)) {\n          // Reset active state if we just left the previous suggestion range\n          if (\n            (from \u003c prev.range.from || from \u003e prev.range.to)\n            \u0026\u0026 !composing\n            \u0026\u0026 !prev.composing\n          ) {\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            \u0026\u0026 allow({\n              editor,\n              state,\n              range: match.range,\n              isActive: prev.active,\n            })\n          ) {\n            next.active = true\n            next.decorationId = prev.decorationId\n              ? prev.decorationId\n              : 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 {\n          active, range, decorationId, query,\n        } = 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"],"version":3}
