{"version":3,"sources":["../src/hooks/base-ai-textarea-implementation/use-ai-textarea-editor.tsx"],"sourcesContent":["import { useMemo } from \"react\";\nimport { createEditor, Element } from \"slate\";\nimport { withReact } from \"slate-react\";\nimport {\n  defaultShouldSave,\n  ShouldSaveToHistory,\n  withPartialHistory,\n} from \"../../lib/slatejs-edits/with-partial-history\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nconst shouldSave: ShouldSaveToHistory = (op, prev) => {\n  const excludedNodeType = \"suggestion\";\n  // Check if the operation involves the suggestion inline node type\n  if (\n    op.type === \"insert_node\" &&\n    Element.isElement(op.node) &&\n    op.node.type === excludedNodeType\n  ) {\n    return false;\n  }\n\n  if (\n    op.type === \"remove_node\" &&\n    Element.isElement(op.node) &&\n    op.node.type === excludedNodeType\n  ) {\n    return false;\n  }\n\n  if (\n    op.type === \"set_node\" &&\n    \"type\" in op.newProperties &&\n    op.newProperties.type === excludedNodeType\n  ) {\n    return false;\n  }\n\n  if (op.type == \"set_node\" && \"type\" in op.properties && op.properties.type === excludedNodeType) {\n    return false;\n  }\n\n  if (\n    op.type === \"merge_node\" &&\n    \"type\" in op.properties &&\n    op.properties.type === excludedNodeType\n  ) {\n    return false;\n  }\n\n  if (\n    op.type === \"split_node\" &&\n    \"type\" in op.properties &&\n    op.properties.type === excludedNodeType\n  ) {\n    return false;\n  }\n\n  // Otherwise, save the operation to history\n  return defaultShouldSave(op, prev);\n};\n\nexport function useAiTextareaEditor(): CustomEditor {\n  const editor = useMemo(() => {\n    const editor = withPartialHistory(withReact(createEditor()), shouldSave);\n\n    const { isVoid } = editor;\n    editor.isVoid = (element) => {\n      switch (element.type) {\n        case \"suggestion\":\n          return true;\n        default:\n          return isVoid(element);\n      }\n    };\n\n    const { markableVoid } = editor;\n    editor.markableVoid = (element) => {\n      switch (element.type) {\n        case \"suggestion\":\n          return true;\n        default:\n          return markableVoid(element);\n      }\n    };\n\n    const { isInline } = editor;\n    editor.isInline = (element) => {\n      switch (element.type) {\n        case \"suggestion\":\n          return element.inline;\n        default:\n          return isInline(element);\n      }\n    };\n\n    return editor;\n  }, []);\n\n  return editor;\n}\n"],"mappings":";;;;;;AAAA,SAAS,eAAe;AACxB,SAAS,cAAc,eAAe;AACtC,SAAS,iBAAiB;AAQ1B,IAAM,aAAkC,CAAC,IAAI,SAAS;AACpD,QAAM,mBAAmB;AAEzB,MACE,GAAG,SAAS,iBACZ,QAAQ,UAAU,GAAG,IAAI,KACzB,GAAG,KAAK,SAAS,kBACjB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,iBACZ,QAAQ,UAAU,GAAG,IAAI,KACzB,GAAG,KAAK,SAAS,kBACjB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,cACZ,UAAU,GAAG,iBACb,GAAG,cAAc,SAAS,kBAC1B;AACA,WAAO;AAAA,EACT;AAEA,MAAI,GAAG,QAAQ,cAAc,UAAU,GAAG,cAAc,GAAG,WAAW,SAAS,kBAAkB;AAC/F,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,gBACZ,UAAU,GAAG,cACb,GAAG,WAAW,SAAS,kBACvB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,gBACZ,UAAU,GAAG,cACb,GAAG,WAAW,SAAS,kBACvB;AACA,WAAO;AAAA,EACT;AAGA,SAAO,kBAAkB,IAAI,IAAI;AACnC;AAEO,SAAS,sBAAoC;AAClD,QAAM,SAAS,QAAQ,MAAM;AAC3B,UAAMA,UAAS,mBAAmB,UAAU,aAAa,CAAC,GAAG,UAAU;AAEvE,UAAM,EAAE,OAAO,IAAIA;AACnB,IAAAA,QAAO,SAAS,CAAC,YAAY;AAC3B,cAAQ,QAAQ,MAAM;AAAA,QACpB,KAAK;AACH,iBAAO;AAAA,QACT;AACE,iBAAO,OAAO,OAAO;AAAA,MACzB;AAAA,IACF;AAEA,UAAM,EAAE,aAAa,IAAIA;AACzB,IAAAA,QAAO,eAAe,CAAC,YAAY;AACjC,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