{"version":3,"sources":["jsdelivr-header.js","/npm/@udecode/plate-combobox@49.0.0/src/index.ts","/npm/@udecode/plate-combobox@49.0.0/src/lib/withTriggerCombobox.ts","/npm/@udecode/plate-combobox@49.0.0/src/lib/utils/filterWords.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,8iBCNA,cAAA,GAAA,SAAA,cAAA,CAAA,YAAA,IAAA,YAAA,oBAAA,IAAA,sBAAA,OAAA,QAAA,aAAA,eCSO,IAAM,oBAET,EAAG,SAAQ,aAAY,IAAM,cAAc,WActC,CACL,WAAY,CACV,UAAA,CAAW,EAAM,GACf,MAAM,oBACJ,EAAA,2BACA,EAAA,aACA,GACE,IAEJ,GACE,GAAS,KACR,EAAO,YAxBO,CAAC,IACtB,MAAM,QAAE,GAAY,IAEpB,OAAI,aAAmB,OACd,EAAQ,KAAK,GAElB,MAAM,QAAQ,GACT,EAAQ,SAAS,GAGnB,IAAS,CAAA,EAeT,CAAe,IACf,IAAiB,EAAa,GAE/B,OAAO,EAAW,EAAM,GAI1B,MAAM,EAAe,EAAO,IAAI,OAC9B,EAAO,IAAI,MAAM,SAAU,EAAO,YAG9B,EACJ,GAA4B,KAAK,GAEnC,GAAI,EAA4B,CAC9B,MAAM,EAAsB,EACxB,EAAoB,GACpB,CAAE,SAAU,CAAC,CAAE,KAAM,KAAO,QAEhC,OAAO,EAAO,GAAG,YAAY,EAAW,EAC1C,CAEA,OAAO,EAAW,EAAM,EAC1B,KCtDO,YAAc,CACzB,EACA,GAEE,aAAa,YACb,eAAe,MACf,iBAAiB,aACK,CAAC,KAEzB,MAAM,EAAgB,EAAS,OAAO,MAAM,GACtC,EAAc,EAAO,OAAO,MAAM,GAIxC,OAAO,EAF+B,cAAnB,EAAiC,QAAU,SAE/B,CAAC,EAAY,KAC1C,MAAM,EAAA,MACJ,OAAQ,GACN,IAAK,YACH,OAAO,EAET,IAAK,YACH,OAAO,IAAM,EAAY,OAAS,EAEpC,IAAK,OACH,OAAO,EAGb,EAZM,GAcN,OAAO,EAAc,MAAM,GAShB,KARY,EACjB,EAAqB,MAAM,EAAG,EAAW,QACzC,GAGW,cAAc,OAAY,EAAW,CAChD,YAAa,OACb,MAAO,YAGZ,GACF","file":"/npm/@udecode/plate-combobox@49.0.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@udecode/plate-combobox@49.0.0/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './lib/index';\n","import type {\n  OverrideEditor,\n  PluginConfig,\n  SlateEditor,\n  TElement,\n} from '@udecode/plate';\n\nimport type { TriggerComboboxPluginOptions } from './types';\n\nexport const withTriggerCombobox: OverrideEditor<\n  PluginConfig<any, TriggerComboboxPluginOptions>\n> = ({ editor, getOptions, tf: { insertText }, type }) => {\n  const matchesTrigger = (text: string) => {\n    const { trigger } = getOptions();\n\n    if (trigger instanceof RegExp) {\n      return trigger.test(text);\n    }\n    if (Array.isArray(trigger)) {\n      return trigger.includes(text);\n    }\n\n    return text === trigger;\n  };\n\n  return {\n    transforms: {\n      insertText(text, options) {\n        const {\n          createComboboxInput,\n          triggerPreviousCharPattern,\n          triggerQuery,\n        } = getOptions();\n\n        if (\n          options?.at ||\n          !editor.selection ||\n          !matchesTrigger(text) ||\n          (triggerQuery && !triggerQuery(editor as SlateEditor))\n        ) {\n          return insertText(text, options);\n        }\n\n        // Make sure an input is created at the beginning of line or after a whitespace\n        const previousChar = editor.api.string(\n          editor.api.range('before', editor.selection)\n        );\n\n        const matchesPreviousCharPattern =\n          triggerPreviousCharPattern?.test(previousChar);\n\n        if (matchesPreviousCharPattern) {\n          const inputNode: TElement = createComboboxInput\n            ? createComboboxInput(text)\n            : { children: [{ text: '' }], type };\n\n          return editor.tf.insertNodes(inputNode, options);\n        }\n\n        return insertText(text, options);\n      },\n    },\n  };\n};\n","export interface FilterWordsOptions {\n  prefixMode?: 'all-words' | 'last-word' | 'none';\n  wordBoundary?: RegExp;\n  wordQuantifier?: 'match-all' | 'match-any';\n}\n\nexport const filterWords = (\n  haystack: string,\n  needle: string,\n  {\n    prefixMode = 'last-word',\n    wordBoundary = /\\s+/,\n    wordQuantifier = 'match-all',\n  }: FilterWordsOptions = {}\n): boolean => {\n  const haystackWords = haystack.trim().split(wordBoundary);\n  const needleWords = needle.trim().split(wordBoundary);\n\n  const quantifier = wordQuantifier === 'match-all' ? 'every' : 'some';\n\n  return needleWords[quantifier]((needleWord, i) => {\n    const allowPrefix = (() => {\n      switch (prefixMode) {\n        case 'all-words': {\n          return true;\n        }\n        case 'last-word': {\n          return i === needleWords.length - 1;\n        }\n        case 'none': {\n          return false;\n        }\n      }\n    })();\n\n    return haystackWords.some((unslicedHaystackWord) => {\n      const haystackWord = allowPrefix\n        ? unslicedHaystackWord.slice(0, needleWord.length)\n        : unslicedHaystackWord;\n\n      return (\n        haystackWord.localeCompare(needleWord, undefined, {\n          sensitivity: 'base',\n          usage: 'search',\n        }) === 0\n      );\n    });\n  });\n};\n"]}