@bikdotai/bik-component-library 0.0.858-beta.1 → 0.0.858

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 (77) hide show
  1. package/README.md +4 -4
  2. package/dist/cjs/components/WhatsAppTextEditor/WhatsAppTextEditor.js +23 -23
  3. package/dist/cjs/components/WhatsAppTextEditor/WhatsAppTextEditor.js.map +1 -1
  4. package/dist/cjs/components/agent-builder/components/AiTextArea.js +1 -1
  5. package/dist/cjs/components/agent-builder/components/AiTextArea.js.map +1 -1
  6. package/dist/cjs/components/agent-builder/components/ToolInstructionsField.js +2 -2
  7. package/dist/cjs/components/agent-builder/components/ToolInstructionsField.js.map +1 -1
  8. package/dist/cjs/components/bik-chatbot/components/ChatWindow.js +20 -20
  9. package/dist/cjs/components/bik-chatbot/components/ChatWindow.js.map +1 -1
  10. package/dist/cjs/components/feature-announcements/FeatureAnnouncementProvider.js +2 -2
  11. package/dist/cjs/components/feature-announcements/FeatureAnnouncementProvider.js.map +1 -1
  12. package/dist/cjs/components/feature-announcements/MajorUpdatePopup.js +2 -2
  13. package/dist/cjs/components/feature-announcements/MajorUpdatePopup.js.map +1 -1
  14. package/dist/cjs/components/feature-announcements/MinorUpdatePopup.js +1 -1
  15. package/dist/cjs/components/feature-announcements/MinorUpdatePopup.js.map +1 -1
  16. package/dist/cjs/components/input/ChipInput.js +1 -1
  17. package/dist/cjs/components/input/ChipInput.js.map +1 -1
  18. package/dist/cjs/components/input/Input-helper.js +1 -1
  19. package/dist/cjs/components/input/Input-helper.js.map +1 -1
  20. package/dist/cjs/components/input/Input.js +1 -1
  21. package/dist/cjs/components/input/Input.js.map +1 -1
  22. package/dist/cjs/components/plans/SubscriptionPlanSelector.js +5 -5
  23. package/dist/cjs/components/plans/SubscriptionPlanSelector.js.map +1 -1
  24. package/dist/cjs/editor/BikEditor.js +1 -1
  25. package/dist/cjs/editor/BikEditor.js.map +1 -1
  26. package/dist/cjs/editor/BikEditor.utils.js +3 -3
  27. package/dist/cjs/editor/BikEditor.utils.js.map +1 -1
  28. package/dist/cjs/editor/extensions/buildExtensions.js +2 -2
  29. package/dist/cjs/editor/extensions/buildExtensions.js.map +1 -1
  30. package/dist/cjs/editor/extensions/htmlTagStrip/HtmlTagStripExtension.js +2 -0
  31. package/dist/cjs/editor/extensions/htmlTagStrip/HtmlTagStripExtension.js.map +1 -0
  32. package/dist/cjs/helpers/sanitize.js +2 -0
  33. package/dist/cjs/helpers/sanitize.js.map +1 -0
  34. package/dist/cjs/index.js +1 -1
  35. package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditor.js +144 -143
  36. package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditor.js.map +1 -1
  37. package/dist/esm/components/agent-builder/components/AiTextArea.js +24 -23
  38. package/dist/esm/components/agent-builder/components/AiTextArea.js.map +1 -1
  39. package/dist/esm/components/agent-builder/components/ToolInstructionsField.js +38 -37
  40. package/dist/esm/components/agent-builder/components/ToolInstructionsField.js.map +1 -1
  41. package/dist/esm/components/bik-chatbot/components/ChatWindow.js +54 -53
  42. package/dist/esm/components/bik-chatbot/components/ChatWindow.js.map +1 -1
  43. package/dist/esm/components/feature-announcements/FeatureAnnouncementProvider.js +346 -420
  44. package/dist/esm/components/feature-announcements/FeatureAnnouncementProvider.js.map +1 -1
  45. package/dist/esm/components/feature-announcements/MajorUpdatePopup.js +35 -33
  46. package/dist/esm/components/feature-announcements/MajorUpdatePopup.js.map +1 -1
  47. package/dist/esm/components/feature-announcements/MinorUpdatePopup.js +48 -47
  48. package/dist/esm/components/feature-announcements/MinorUpdatePopup.js.map +1 -1
  49. package/dist/esm/components/feature-announcements/types/props.types.d.ts +2 -2
  50. package/dist/esm/components/input/ChipInput.js +41 -40
  51. package/dist/esm/components/input/ChipInput.js.map +1 -1
  52. package/dist/esm/components/input/Input-helper.d.ts +7 -0
  53. package/dist/esm/components/input/Input-helper.js +16 -25
  54. package/dist/esm/components/input/Input-helper.js.map +1 -1
  55. package/dist/esm/components/input/Input.js +59 -57
  56. package/dist/esm/components/input/Input.js.map +1 -1
  57. package/dist/esm/components/input/Input.model.d.ts +1 -0
  58. package/dist/esm/components/plans/SubscriptionPlanSelector.js +42 -40
  59. package/dist/esm/components/plans/SubscriptionPlanSelector.js.map +1 -1
  60. package/dist/esm/editor/BikEditor.js +221 -217
  61. package/dist/esm/editor/BikEditor.js.map +1 -1
  62. package/dist/esm/editor/BikEditor.utils.d.ts +1 -1
  63. package/dist/esm/editor/BikEditor.utils.js +141 -140
  64. package/dist/esm/editor/BikEditor.utils.js.map +1 -1
  65. package/dist/esm/editor/extensions/buildExtensions.js +35 -25
  66. package/dist/esm/editor/extensions/buildExtensions.js.map +1 -1
  67. package/dist/esm/editor/extensions/htmlTagStrip/HtmlTagStripExtension.d.ts +13 -0
  68. package/dist/esm/editor/extensions/htmlTagStrip/HtmlTagStripExtension.js +64 -0
  69. package/dist/esm/editor/extensions/htmlTagStrip/HtmlTagStripExtension.js.map +1 -0
  70. package/dist/esm/helpers/index.d.ts +1 -0
  71. package/dist/esm/helpers/sanitize.d.ts +32 -0
  72. package/dist/esm/helpers/sanitize.js +207 -0
  73. package/dist/esm/helpers/sanitize.js.map +1 -0
  74. package/dist/esm/icons/index.d.ts +25 -25
  75. package/dist/esm/index.js +125 -115
  76. package/dist/esm/index.js.map +1 -1
  77. package/package.json +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":"BikEditor.js","sources":["../../../src/editor/BikEditor.tsx"],"sourcesContent":["'use client';\n\n/**\n * IMPLEMENTATION LAYER — TipTap-specific.\n * If the underlying editor is swapped, this file changes; BikEditor.types.ts and\n * src/editor/index.ts (the consumer contract) do NOT change.\n */\nimport { Editor, getMarkRange } from '@tiptap/core';\nimport { EditorContent, useEditor } from '@tiptap/react';\nimport React, {\n\tforwardRef,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n\tuseState,\n} from 'react';\nimport { BodyCaption } from '@src/components/TypographyStyle';\nimport { Code, Copy, Info, WandSparkles } from '../icons';\nimport {\n\tBikEditorShell,\n\tBikJsonBody,\n\tBikJsonEmptyState,\n\tBikJsonError,\n\tBikJsonHeader,\n} from './BikEditor.styles';\nimport {\n\tBikEditorProps,\n\tBikEditorRef,\n\tDEFAULT_FORMAT_STATE,\n\tFormatState,\n\tJsonParseResult,\n} from './BikEditor.types';\nimport {\n\tbuildJsonCodeBlockHtml,\n\tbuildSectionedContent,\n\textractActiveFormats,\n\textractBodyContent,\n\textractContent,\n\textractSectionContent,\n\tfindSectionEndPos,\n\tfindSectionStartPos,\n\tgetCodeBlockText,\n\tinsertInlineHtml,\n\tnormalizeHtml,\n\tparseJson,\n\tsetCodeBlockText,\n\tsetSectionContentInEditor,\n} from './BikEditor.utils';\nimport { buildExtensions } from './extensions/buildExtensions';\nimport { LinkBubbleMenu } from './floating/LinkBubbleMenu';\n\n/** Convert React.CSSProperties to an inline CSS string for editorProps.attributes. */\nfunction cssToString(style: React.CSSProperties): string {\n\treturn Object.entries(style)\n\t\t.map(\n\t\t\t([k, v]) => `${k.replace(/([A-Z])/g, (c) => `-${c.toLowerCase()}`)}:${v}`,\n\t\t)\n\t\t.join(';');\n}\n\nconst BikEditorInner = (\n\tprops: BikEditorProps,\n\tref: React.Ref<BikEditorRef>,\n) => {\n\tconst {\n\t\tinitialContent,\n\t\tsections,\n\t\tfeatures,\n\t\tdisabled,\n\t\tmaxCharacters,\n\t\tcharacterLimit,\n\t\tcharacterLimitHard,\n\t\tshortcuts,\n\t\tsendShortcut,\n\t\tmentions,\n\t\tslashCommands,\n\t\tlink,\n\t\tonPaste,\n\t\tonReady,\n\t\tonChange,\n\t\tonSend,\n\t\tonFocus,\n\t\tonBlur,\n\t\tonSelectionChange,\n\t\tminHeight,\n\t\tmaxHeight,\n\t\tstyle,\n\t\tclassName,\n\t\teditorClassName,\n\t\teditorStyle,\n\t\trenderJsonError,\n\t} = props;\n\n\tconst isJsonMode = !!features?.jsonMode;\n\n\t// Live JSON parse error, shown inside the editor when jsonMode is on.\n\t// null = valid (or not applicable) → nothing rendered.\n\tconst [jsonError, setJsonError] = useState<JsonParseResult | null>(null);\n\t// Transient \"Copied\" state for the jsonMode copy button.\n\tconst [jsonCopied, setJsonCopied] = useState(false);\n\t// jsonMode: no content yet → centered code-glyph + placeholder overlay.\n\tconst [jsonEmpty, setJsonEmpty] = useState(\n\t\tisJsonMode && !(initialContent ?? '').trim(),\n\t);\n\t// jsonMode: hide the placeholder overlay while the editor is focused, so\n\t// clicking in gives a clean field to type into.\n\tconst [jsonFocused, setJsonFocused] = useState(false);\n\n\t// JSON body mode: treat initialContent as raw JSON text and wrap it in a code\n\t// block. Skips section/HTML normalisation entirely.\n\tconst initialEditorContent = isJsonMode\n\t\t? buildJsonCodeBlockHtml(initialContent ?? '')\n\t\t: sections?.length\n\t\t? buildSectionedContent(\n\t\t\t\tnormalizeHtml(initialContent ?? ''),\n\t\t\t\tsections.map((s) => ({ ...s, content: normalizeHtml(s.content) })),\n\t\t )\n\t\t: normalizeHtml(initialContent ?? '');\n\n\t// ── Command queue ─────────────────────────────────────────────────────────\n\t// TipTap's useEditor initializes asynchronously; the editor instance is null\n\t// until the first commit. Any imperative method called before the editor is\n\t// ready is enqueued here and flushed automatically once it becomes non-null.\n\t// Consumers never need setTimeout or readiness guards.\n\tconst pendingQueue = useRef<Array<(e: Editor) => void>>([]);\n\tconst hasCalledOnReady = useRef(false);\n\t// Keep stable refs to all callbacks so useEditor receives the same function\n\t// identity on every render — prevents TipTap from re-registering event\n\t// handlers every time the parent re-renders with new inline function props.\n\tconst onReadyRef = useRef(onReady);\n\tonReadyRef.current = onReady;\n\tconst onChangeRef = useRef(onChange);\n\tonChangeRef.current = onChange;\n\tconst onSelectionChangeRef = useRef(onSelectionChange);\n\tonSelectionChangeRef.current = onSelectionChange;\n\tconst prevFormatsRef = useRef<FormatState>(DEFAULT_FORMAT_STATE);\n\tconst onFocusRef = useRef(onFocus);\n\tonFocusRef.current = onFocus;\n\tconst onBlurRef = useRef(onBlur);\n\tonBlurRef.current = onBlur;\n\tconst onSendRef = useRef(onSend);\n\tonSendRef.current = onSend;\n\tconst agentMentionsRef = useRef(mentions?.agents ?? []);\n\tagentMentionsRef.current = mentions?.agents ?? [];\n\tconst teamMentionsRef = useRef(mentions?.teams ?? []);\n\tteamMentionsRef.current = mentions?.teams ?? [];\n\tconst slashCommandsRef = useRef(slashCommands?.items ?? []);\n\tslashCommandsRef.current = slashCommands?.items ?? [];\n\n\tconst editor = useEditor({\n\t\textensions: buildExtensions({\n\t\t\tfeatures,\n\t\t\tplaceholder: props.placeholder,\n\t\t\tmaxCharacters,\n\t\t\tcharacterLimit,\n\t\t\tcharacterLimitHard,\n\t\t\thasSections: (sections?.length ?? 0) > 0,\n\t\t\tmentions: {\n\t\t\t\tagents: mentions ? agentMentionsRef : undefined,\n\t\t\t\tteams: mentions ? teamMentionsRef : undefined,\n\t\t\t},\n\t\t\tslashCommands: slashCommands ? slashCommandsRef : undefined,\n\t\t\tonPaste,\n\t\t\tonSend: onSend ? (snapshot) => onSendRef.current?.(snapshot) : undefined,\n\t\t\tsendShortcut,\n\t\t\tshortcuts,\n\t\t\tonMentionSelected: mentions?.onSelect,\n\t\t\tonSlashCommandSelected: slashCommands?.onSelect,\n\t\t\trenderMentionItem: mentions?.renderItem,\n\t\t\trenderMentionDropdown: mentions?.renderDropdown,\n\t\t\tremoveMentionTriggerOnDismiss: mentions?.removeTriggerOnDismiss,\n\t\t\trenderMentionChipIcon: mentions?.renderChipIcon,\n\t\t\trenderSlashCommandItem: slashCommands?.renderItem,\n\t\t\trenderSlashCommandDropdown: slashCommands?.renderDropdown,\n\t\t}),\n\t\tcontent: initialEditorContent,\n\t\teditable: !disabled,\n\t\timmediatelyRender: false, // SSR-safe — NEVER remove this\n\t\teditorProps: {\n\t\t\tattributes: {\n\t\t\t\t...(editorClassName ? { class: editorClassName } : {}),\n\t\t\t\t...(editorStyle ? { style: cssToString(editorStyle) } : {}),\n\t\t\t},\n\t\t},\n\t\tonUpdate: ({ editor: e }) => {\n\t\t\tonChangeRef.current?.(extractContent(e));\n\t\t\tif (isJsonMode) {\n\t\t\t\tconst text = getCodeBlockText(e);\n\t\t\t\tconst result = parseJson(text);\n\t\t\t\tsetJsonError(result.valid ? null : result);\n\t\t\t\tsetJsonEmpty(!text.trim());\n\t\t\t}\n\t\t},\n\t\tonTransaction: ({ editor: e }) => {\n\t\t\tconst next = extractActiveFormats(e);\n\t\t\tconst prev = prevFormatsRef.current;\n\t\t\tconst changed =\n\t\t\t\tprev.bold !== next.bold ||\n\t\t\t\tprev.italic !== next.italic ||\n\t\t\t\tprev.underline !== next.underline ||\n\t\t\t\tprev.strike !== next.strike ||\n\t\t\t\tprev.bulletList !== next.bulletList ||\n\t\t\t\tprev.orderedList !== next.orderedList ||\n\t\t\t\tprev.blockquote !== next.blockquote ||\n\t\t\t\tprev.codeBlock !== next.codeBlock ||\n\t\t\t\tprev.superscript !== next.superscript ||\n\t\t\t\tprev.subscript !== next.subscript ||\n\t\t\t\tprev.textAlign !== next.textAlign ||\n\t\t\t\tprev.fontFamily !== next.fontFamily ||\n\t\t\t\tprev.fontSize !== next.fontSize ||\n\t\t\t\tprev.color !== next.color ||\n\t\t\t\tprev.highlight !== next.highlight ||\n\t\t\t\tprev.link?.href !== next.link?.href;\n\t\t\tif (changed) {\n\t\t\t\tprevFormatsRef.current = next;\n\t\t\t\tonSelectionChangeRef.current?.(next);\n\t\t\t}\n\t\t},\n\t\tonFocus: () => {\n\t\t\tsetJsonFocused(true);\n\t\t\tonFocusRef.current?.();\n\t\t},\n\t\tonBlur: () => {\n\t\t\tsetJsonFocused(false);\n\t\t\tonBlurRef.current?.();\n\t\t},\n\t});\n\n\t// ── enqueue ───────────────────────────────────────────────────────────────\n\t// Run immediately if the editor is ready; otherwise defer to the queue.\n\t// Closures passed to enqueue MUST capture all parameters explicitly —\n\t// they must NOT close over `editor` (which would be null at enqueue time).\n\tfunction enqueue(op: (e: Editor) => void): void {\n\t\tif (editor) {\n\t\t\top(editor);\n\t\t} else {\n\t\t\tpendingQueue.current.push(op);\n\t\t}\n\t}\n\n\t// Flush the pending queue and fire onReady when editor transitions null → ready.\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\t\tif (pendingQueue.current.length > 0) {\n\t\t\tconst queue = pendingQueue.current.splice(0);\n\t\t\tqueue.forEach((op) => op(editor));\n\t\t}\n\t\tif (!hasCalledOnReady.current) {\n\t\t\thasCalledOnReady.current = true;\n\t\t\tonReadyRef.current?.();\n\t\t}\n\t\t// Surface an error for invalid initialContent immediately on mount.\n\t\tif (isJsonMode) {\n\t\t\tconst text = getCodeBlockText(editor);\n\t\t\tconst result = parseJson(text);\n\t\t\tsetJsonError(result.valid ? null : result);\n\t\t\tsetJsonEmpty(!text.trim());\n\t\t}\n\t}, [editor, isJsonMode]);\n\n\tuseImperativeHandle(\n\t\tref,\n\t\t() => ({\n\t\t\t// ── Focus ────────────────────────────────────────────────────────\n\t\t\tfocus: (position) => enqueue((e) => e.commands.focus(position)),\n\t\t\tblur: () => enqueue((e) => e.commands.blur()),\n\n\t\t\t// ── Content ──────────────────────────────────────────────────────\n\t\t\tclearContent: () => enqueue((e) => e.commands.clearContent(true)),\n\t\t\tsetContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.setContent(normalised, { emitUpdate: true }));\n\t\t\t},\n\t\t\tinsertContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContent(normalised));\n\t\t\t},\n\t\t\tinsertInlineContent: (html) => {\n\t\t\t\tenqueue((e) => insertInlineHtml(e, html));\n\t\t\t},\n\t\t\tinsertAtStart: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(1, normalised));\n\t\t\t},\n\t\t\tinsertBlock: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\tappendInline: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// doc.content.size is after the last </p> (block boundary).\n\t\t\t\t// Subtract 1 to land inside the last paragraph so text appends\n\t\t\t\t// inline rather than being wrapped in a new paragraph each call.\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size - 1, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\t// Backwards-compatible aliases\n\t\t\tinsertAtEnd(html) {\n\t\t\t\tthis.insertBlock(html);\n\t\t\t},\n\t\t\tappendContent(html) {\n\t\t\t\tthis.appendInline(html);\n\t\t\t},\n\t\t\tgetContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tgetJSON: () => editor?.getJSON() ?? null,\n\t\t\tgetMentions: () => {\n\t\t\t\tconst agentIds = new Set<string>();\n\t\t\t\tconst teamIds = new Set<string>();\n\t\t\t\tif (!editor) return { agentIds: [], teamIds: [] };\n\t\t\t\teditor.state.doc.descendants((node) => {\n\t\t\t\t\tif (node.type.name === 'mentionAgent' && node.attrs['id'] != null) {\n\t\t\t\t\t\tagentIds.add(String(node.attrs['id']));\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tnode.type.name === 'mentionTeam' &&\n\t\t\t\t\t\tnode.attrs['id'] != null\n\t\t\t\t\t) {\n\t\t\t\t\t\tteamIds.add(String(node.attrs['id']));\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn { agentIds: Array.from(agentIds), teamIds: Array.from(teamIds) };\n\t\t\t},\n\n\t\t\t// ── Selection ────────────────────────────────────────────────────\n\t\t\tgetCursorPosition: () => {\n\t\t\t\tif (!editor) return { from: 0, to: 0 };\n\t\t\t\tconst { from, to } = editor.state.selection;\n\t\t\t\treturn { from, to };\n\t\t\t},\n\t\t\tinsertAtPosition: (pos, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(pos, normalised));\n\t\t\t},\n\t\t\tgetSelectedText: () => {\n\t\t\t\tif (!editor) return '';\n\t\t\t\tconst { state } = editor;\n\t\t\t\tconst { from, to, empty } = state.selection;\n\t\t\t\tif (!empty) {\n\t\t\t\t\treturn state.doc.textBetween(from, to, ' ');\n\t\t\t\t}\n\t\t\t\t// When the cursor is inside a link with nothing selected, return the\n\t\t\t\t// full link text — useful for pre-filling a link modal's text field.\n\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\tif (linkMarkType) {\n\t\t\t\t\tconst range = getMarkRange(state.doc.resolve(from), linkMarkType);\n\t\t\t\t\tif (range) {\n\t\t\t\t\t\treturn state.doc.textBetween(range.from, range.to, ' ');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn '';\n\t\t\t},\n\n\t\t\t// ── Character count ───────────────────────────────────────────────\n\t\t\tgetCharacterCount: () => ({\n\t\t\t\tcount:\n\t\t\t\t\teditor?.storage.characterCount?.characters?.() ??\n\t\t\t\t\teditor?.getText().length ??\n\t\t\t\t\t0,\n\t\t\t\tlimit: maxCharacters ?? null,\n\t\t\t}),\n\n\t\t\t// ── Sections ─────────────────────────────────────────────────────\n\t\t\tgetSectionContent: (sectionId) =>\n\t\t\t\teditor\n\t\t\t\t\t? extractSectionContent(editor, sectionId)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\n\t\t\tsetSectionContent: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, normalised));\n\t\t\t},\n\n\t\t\tfocusSection: (sectionId) => {\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tif (sectionId === 'body') {\n\t\t\t\t\t\tlet endOfBody = e.state.doc.content.size - 1;\n\t\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\t\tendOfBody === e.state.doc.content.size - 1\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tendOfBody = pos - 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn endOfBody === e.state.doc.content.size - 1;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (endOfBody < 1) endOfBody = 1;\n\t\t\t\t\t\te.chain().focus().setTextSelection(endOfBody).run();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet targetPos = -1;\n\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\tif (targetPos !== -1) return false;\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// pos + nodeSize lands right after the divider;\n\t\t\t\t\t\t\t// +1 more puts us inside the first paragraph of that section.\n\t\t\t\t\t\t\ttargetPos = pos + node.nodeSize + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tif (targetPos !== -1) {\n\t\t\t\t\t\te.chain().focus().setTextSelection(targetPos).run();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\n\t\t\tclearSection: (sectionId) => {\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, '<p></p>'));\n\t\t\t},\n\n\t\t\t// ── Convenience body shorthands ───────────────────────────────────\n\t\t\tgetBodyContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractBodyContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tsetBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, 'body', normalised));\n\t\t\t},\n\t\t\tsetBodyAndSections: (body, sections) => {\n\t\t\t\tconst html = buildSectionedContent(\n\t\t\t\t\tnormalizeHtml(body),\n\t\t\t\t\tsections.map((s) => ({\n\t\t\t\t\t\tid: s.id,\n\t\t\t\t\t\tcontent: normalizeHtml(s.content),\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t\tenqueue((e) => e.commands.setContent(html, { emitUpdate: true }));\n\t\t\t},\n\t\t\tappendBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// findSectionEndPos returns the position of the first divider (or\n\t\t\t\t// doc.content.size), which is the block boundary after the last </p>.\n\t\t\t\t// Subtract 1 to stay inside the last paragraph so successive calls\n\t\t\t\t// append inline text rather than creating a new paragraph each time.\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst boundaryPos = findSectionEndPos(e, 'body');\n\t\t\t\t\te.commands.insertContentAt(boundaryPos - 1, normalised, {\n\t\t\t\t\t\tparseOptions: { preserveWhitespace: true },\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionStart: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionStartPos(e, sectionId);\n\t\t\t\t\tif (pos !== -1)\n\t\t\t\t\t\te.commands.insertContentAt(pos, normalised, {\n\t\t\t\t\t\t\tparseOptions: { preserveWhitespace: true },\n\t\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionEnd: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionEndPos(e, sectionId);\n\t\t\t\t\te.commands.insertContentAt(pos, normalised, {\n\t\t\t\t\t\tparseOptions: { preserveWhitespace: true },\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\t// ── Formats & actions ─────────────────────────────────────────────\n\t\t\tgetActiveFormats: () =>\n\t\t\t\teditor ? extractActiveFormats(editor) : DEFAULT_FORMAT_STATE,\n\t\t\tactions: {\n\t\t\t\ttoggleBold: () => editor?.chain().focus().toggleBold().run(),\n\t\t\t\ttoggleItalic: () => editor?.chain().focus().toggleItalic().run(),\n\t\t\t\ttoggleUnderline: () => editor?.chain().focus().toggleUnderline().run(),\n\t\t\t\ttoggleStrike: () => editor?.chain().focus().toggleStrike().run(),\n\t\t\t\ttoggleBulletList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBulletList().run(),\n\t\t\t\ttoggleOrderedList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleOrderedList().run(),\n\t\t\t\ttoggleBlockquote: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBlockquote().run(),\n\t\t\t\ttoggleCodeBlock: () => editor?.chain().focus().toggleCodeBlock().run(),\n\t\t\t\tsetTextAlign: (align) =>\n\t\t\t\t\teditor?.chain().focus().setTextAlign(align).run(),\n\t\t\t\tsetFontFamily: (font) =>\n\t\t\t\t\teditor?.chain().focus().setFontFamily(font).run(),\n\t\t\t\tsetFontSize: (size) => editor?.chain().focus().setFontSize(size).run(),\n\t\t\t\tsetColor: (color) => editor?.chain().focus().setColor(color).run(),\n\t\t\t\tsetHighlight: (color) =>\n\t\t\t\t\teditor?.chain().focus().toggleHighlight({ color }).run(),\n\t\t\t\tunsetColor: () => editor?.chain().focus().unsetColor().run(),\n\t\t\t\tunsetHighlight: () => editor?.chain().focus().unsetHighlight().run(),\n\t\t\t\tsetLink: (href, text) => {\n\t\t\t\t\tif (!editor) return;\n\t\t\t\t\tif (text !== undefined) {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.command(({ tr, state }) => {\n\t\t\t\t\t\t\t\tconst { from, to } = tr.selection;\n\t\t\t\t\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\t\t\t\t\tif (!linkMarkType) return false;\n\t\t\t\t\t\t\t\tconst linkNode = state.schema.text(text, [\n\t\t\t\t\t\t\t\t\tlinkMarkType.create({ href }),\n\t\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\t\tconst space = state.schema.text(' ');\n\t\t\t\t\t\t\t\ttr.replaceWith(from, to, [linkNode, space]);\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t} else {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t\t.insertContent(' ')\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tupdateLink: (href) =>\n\t\t\t\t\teditor\n\t\t\t\t\t\t?.chain()\n\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t.run(),\n\t\t\t\tremoveLink: () =>\n\t\t\t\t\teditor?.chain().focus().extendMarkRange('link').unsetLink().run(),\n\t\t\t\tinsertEmoji: (emoji) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(emoji).run(),\n\t\t\t\tinsertVariable: (variableName) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(`{{${variableName}}}`).run(),\n\t\t\t\tinsertHtml: (html) =>\n\t\t\t\t\teditor?.commands.insertContent(normalizeHtml(html)),\n\t\t\t\topenMentionMenu: (char = '@') => {\n\t\t\t\t\tif (!editor) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\t// Collapse to the selection's END first — insertContent over a live\n\t\t\t\t\t// selection would REPLACE the selected text with the trigger char.\n\t\t\t\t\tconst { to } = editor.state.selection;\n\t\t\t\t\tconst prev = to > 1 ? editor.state.doc.textBetween(to - 1, to) : '';\n\t\t\t\t\tconst needsSpace = prev !== '' && !/\\s/.test(prev);\n\t\t\t\t\teditor\n\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t.setTextSelection(to)\n\t\t\t\t\t\t.insertContent(needsSpace ? ` ${char}` : char)\n\t\t\t\t\t\t.run();\n\t\t\t\t},\n\t\t\t\tundo: () => editor?.chain().focus().undo().run(),\n\t\t\t\tredo: () => editor?.chain().focus().redo().run(),\n\t\t\t\tcanUndo: () => editor?.can().undo() ?? false,\n\t\t\t\tcanRedo: () => editor?.can().redo() ?? false,\n\t\t\t\ttoggleSuperscript: () =>\n\t\t\t\t\teditor?.chain().focus().toggleSuperscript().run(),\n\t\t\t\ttoggleSubscript: () => editor?.chain().focus().toggleSubscript().run(),\n\t\t\t\tinsertImage: (src) => editor?.chain().focus().setImage({ src }).run(),\n\t\t\t},\n\n\t\t\t// ── JSON body ─────────────────────────────────────────────────────\n\t\t\tjson: features?.jsonMode\n\t\t\t\t? {\n\t\t\t\t\t\tgetText: () => (editor ? getCodeBlockText(editor) : ''),\n\t\t\t\t\t\tsetText: (raw) => enqueue((e) => setCodeBlockText(e, raw)),\n\t\t\t\t\t\tparse: () => parseJson(editor ? getCodeBlockText(editor) : ''),\n\t\t\t\t\t\tisValid: () =>\n\t\t\t\t\t\t\tparseJson(editor ? getCodeBlockText(editor) : '').valid,\n\t\t\t\t\t\tformat: (indent = 2) =>\n\t\t\t\t\t\t\tenqueue((e) => {\n\t\t\t\t\t\t\t\tconst { valid, value } = parseJson(getCodeBlockText(e));\n\t\t\t\t\t\t\t\tif (!valid || value === null) return;\n\t\t\t\t\t\t\t\tsetCodeBlockText(e, JSON.stringify(value, null, indent));\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\tminify: () =>\n\t\t\t\t\t\t\tenqueue((e) => {\n\t\t\t\t\t\t\t\tconst { valid, value } = parseJson(getCodeBlockText(e));\n\t\t\t\t\t\t\t\tif (!valid || value === null) return;\n\t\t\t\t\t\t\t\tsetCodeBlockText(e, JSON.stringify(value));\n\t\t\t\t\t\t\t}),\n\t\t\t\t }\n\t\t\t\t: undefined,\n\t\t}),\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t[editor],\n\t);\n\n\t// ── jsonMode floating actions ────────────────────────────────────────────\n\t// Beautify pretty-prints in place (no-op / disabled while the JSON is broken);\n\t// Copy writes the raw text to the clipboard with transient feedback.\n\tconst handleJsonBeautify = () => {\n\t\tif (!editor) return;\n\t\tconst { valid, value } = parseJson(getCodeBlockText(editor));\n\t\tif (!valid || value === null) return;\n\t\tsetCodeBlockText(editor, JSON.stringify(value, null, 2));\n\t};\n\tconst handleJsonCopy = () => {\n\t\tif (!editor) return;\n\t\tvoid navigator.clipboard?.writeText(getCodeBlockText(editor));\n\t\tsetJsonCopied(true);\n\t\tsetTimeout(() => setJsonCopied(false), 1500);\n\t};\n\n\tif (!editor) return null;\n\n\treturn (\n\t\t<BikEditorShell\n\t\t\tminHeight={minHeight}\n\t\t\tmaxHeight={maxHeight}\n\t\t\ttightParagraphs={!features?.richPaste}\n\t\t\tjsonMode={isJsonMode}\n\t\t\tstyle={style}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t{isJsonMode && (\n\t\t\t\t<BikJsonHeader>\n\t\t\t\t\t<span className=\"bik-json-header-label\">JSON</span>\n\t\t\t\t\t<div className=\"bik-json-header-actions\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tonClick={handleJsonBeautify}\n\t\t\t\t\t\t\tdisabled={!!jsonError || jsonEmpty}\n\t\t\t\t\t\t\ttitle=\"Format JSON\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<WandSparkles size={16} />\n\t\t\t\t\t\t\t<BodyCaption>Beautify</BodyCaption>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tonClick={handleJsonCopy}\n\t\t\t\t\t\t\tdisabled={jsonEmpty}\n\t\t\t\t\t\t\ttitle=\"Copy JSON\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Copy size={16} />\n\t\t\t\t\t\t\t{jsonCopied && <BodyCaption>Copied</BodyCaption>}\n\t\t\t\t\t\t</button>\n\t\t\t\t\t</div>\n\t\t\t\t</BikJsonHeader>\n\t\t\t)}\n\t\t\t{isJsonMode ? (\n\t\t\t\t<BikJsonBody $error={!!jsonError}>\n\t\t\t\t\t<EditorContent editor={editor} />\n\t\t\t\t\t{jsonEmpty && !jsonFocused && (\n\t\t\t\t\t\t<BikJsonEmptyState aria-hidden>\n\t\t\t\t\t\t\t<Code size={20} />\n\t\t\t\t\t\t\t<span>{props.placeholder ?? 'Type or paste JSON here'}</span>\n\t\t\t\t\t\t</BikJsonEmptyState>\n\t\t\t\t\t)}\n\t\t\t\t</BikJsonBody>\n\t\t\t) : (\n\t\t\t\t<EditorContent editor={editor} />\n\t\t\t)}\n\t\t\t<LinkBubbleMenu editor={editor} renderLinkTooltip={link?.renderTooltip} />\n\t\t\t{isJsonMode && jsonError ? (\n\t\t\t\trenderJsonError ? (\n\t\t\t\t\trenderJsonError(jsonError)\n\t\t\t\t) : (\n\t\t\t\t\t<BikJsonError>\n\t\t\t\t\t\t<Info size={16} />\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t{jsonError.line != null && (\n\t\t\t\t\t\t\t\t<strong>\n\t\t\t\t\t\t\t\t\tLine {jsonError.line}\n\t\t\t\t\t\t\t\t\t{jsonError.column != null\n\t\t\t\t\t\t\t\t\t\t? `, column ${jsonError.column}`\n\t\t\t\t\t\t\t\t\t\t: ''}\n\t\t\t\t\t\t\t\t\t:{' '}\n\t\t\t\t\t\t\t\t</strong>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t{jsonError.error}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</BikJsonError>\n\t\t\t\t)\n\t\t\t) : null}\n\t\t</BikEditorShell>\n\t);\n};\n\nexport const BikEditor = forwardRef<BikEditorRef, BikEditorProps>(\n\tBikEditorInner,\n);\nBikEditor.displayName = 'BikEditor';\n"],"names":["cssToString","style","k","v","c","BikEditorInner","props","ref","initialContent","sections","features","disabled","maxCharacters","characterLimit","characterLimitHard","shortcuts","sendShortcut","mentions","slashCommands","link","onPaste","onReady","onChange","onSend","onFocus","onBlur","onSelectionChange","minHeight","maxHeight","className","editorClassName","editorStyle","renderJsonError","isJsonMode","jsonError","setJsonError","useState","jsonCopied","setJsonCopied","jsonEmpty","setJsonEmpty","jsonFocused","setJsonFocused","initialEditorContent","buildJsonCodeBlockHtml","buildSectionedContent","normalizeHtml","s","pendingQueue","useRef","hasCalledOnReady","onReadyRef","onChangeRef","onSelectionChangeRef","prevFormatsRef","DEFAULT_FORMAT_STATE","onFocusRef","onBlurRef","onSendRef","agentMentionsRef","teamMentionsRef","slashCommandsRef","editor","useEditor","buildExtensions","snapshot","extractContent","text","getCodeBlockText","result","parseJson","next","extractActiveFormats","prev","enqueue","op","useEffect","useImperativeHandle","position","e","html","normalised","insertInlineHtml","agentIds","teamIds","node","from","to","pos","state","empty","linkMarkType","range","getMarkRange","sectionId","extractSectionContent","setSectionContentInEditor","endOfBody","targetPos","extractBodyContent","body","boundaryPos","findSectionEndPos","findSectionStartPos","align","font","size","color","href","tr","linkNode","space","emoji","variableName","char","needsSpace","src","raw","setCodeBlockText","indent","valid","value","handleJsonBeautify","handleJsonCopy","jsxs","BikEditorShell","BikJsonHeader","jsx","WandSparkles","BodyCaption","Copy","BikJsonBody","EditorContent","BikJsonEmptyState","Code","LinkBubbleMenu","BikJsonError","Info","BikEditor","forwardRef"],"mappings":";;;;;;;;;;;;;;AAoDA,SAASA,GAAYC,GAAoC;AACxD,SAAO,OAAO,QAAQA,CAAK,EACzB;AAAA,IACA,CAAC,CAACC,GAAGC,CAAC,MAAM,GAAGD,EAAE,QAAQ,YAAY,CAACE,MAAM,IAAIA,EAAE,YAAA,CA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GAAA,CAAI;AAAA,YAChB,gBAAAP,EAAC,QAAA,EAAM,UAAAzH,EAAM,eAAe,0BAAA,CAA0B;AAAA,UAAA,EAAA,CACvD;AAAA,QAAA,EAAA,CAEF,IAEA,gBAAAyH,EAACK,IAAA,EAAc,QAAAtE,EAAA,CAAgB;AAAA,QAEhC,gBAAAiE,EAACQ,IAAA,EAAe,QAAAzE,GAAgB,mBAAmB3C,IAAM,eAAe;AAAA,QACvEc,KAAcC,IACdF,IACCA,EAAgBE,CAAS,sBAExBsG,IAAA,EACA,UAAA;AAAA,UAAA,gBAAAT,EAACU,IAAA,EAAK,MAAM,GAAA,CAAI;AAAA,4BACf,QAAA,EACC,UAAA;AAAA,YAAAvG,EAAU,QAAQ,QAClB,gBAAA0F,EAAC,UAAA,EAAO,UAAA;AAAA,cAAA;AAAA,cACD1F,EAAU;AAAA,cACfA,EAAU,UAAU,OAClB,YAAYA,EAAU,MAAM,KAC5B;AAAA,cAAG;AAAA,cACJ;AAAA,YAAA,GACH;AAAA,YAEAA,EAAU;AAAA,UAAA,EAAA,CACZ;AAAA,QAAA,EAAA,CACD,IAEE;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,IAtEc;AAyErB,GAEawG,KAAYC;AAAA,EACxBtI;AACD;AACAqI,GAAU,cAAc;"}
1
+ {"version":3,"file":"BikEditor.js","sources":["../../../src/editor/BikEditor.tsx"],"sourcesContent":["'use client';\n\n/**\n * IMPLEMENTATION LAYER — TipTap-specific.\n * If the underlying editor is swapped, this file changes; BikEditor.types.ts and\n * src/editor/index.ts (the consumer contract) do NOT change.\n */\nimport { Editor, getMarkRange } from '@tiptap/core';\nimport { EditorContent, useEditor } from '@tiptap/react';\nimport React, {\n\tforwardRef,\n\tuseCallback,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n\tuseState,\n} from 'react';\nimport { BodyCaption } from '@src/components/TypographyStyle';\nimport { sanitizeBasicHtml, sanitizeEmailHtml } from '../helpers/sanitize';\nimport { Code, Copy, Info, WandSparkles } from '../icons';\nimport {\n\tBikEditorShell,\n\tBikJsonBody,\n\tBikJsonEmptyState,\n\tBikJsonError,\n\tBikJsonHeader,\n} from './BikEditor.styles';\nimport {\n\tBikEditorProps,\n\tBikEditorRef,\n\tDEFAULT_FORMAT_STATE,\n\tFormatState,\n\tJsonParseResult,\n} from './BikEditor.types';\nimport {\n\tbuildJsonCodeBlockHtml,\n\tbuildSectionedContent,\n\textractActiveFormats,\n\textractBodyContent,\n\textractContent,\n\textractSectionContent,\n\tfindSectionEndPos,\n\tfindSectionStartPos,\n\tgetCodeBlockText,\n\tinsertInlineHtml,\n\tnormalizeHtml,\n\tparseJson,\n\tsetCodeBlockText,\n\tsetSectionContentInEditor,\n} from './BikEditor.utils';\nimport { buildExtensions } from './extensions/buildExtensions';\nimport { LinkBubbleMenu } from './floating/LinkBubbleMenu';\n\n/** Convert React.CSSProperties to an inline CSS string for editorProps.attributes. */\nfunction cssToString(style: React.CSSProperties): string {\n\treturn Object.entries(style)\n\t\t.map(\n\t\t\t([k, v]) => `${k.replace(/([A-Z])/g, (c) => `-${c.toLowerCase()}`)}:${v}`,\n\t\t)\n\t\t.join(';');\n}\n\nconst BikEditorInner = (\n\tprops: BikEditorProps,\n\tref: React.Ref<BikEditorRef>,\n) => {\n\tconst {\n\t\tinitialContent,\n\t\tsections,\n\t\tfeatures,\n\t\tdisabled,\n\t\tmaxCharacters,\n\t\tcharacterLimit,\n\t\tcharacterLimitHard,\n\t\tshortcuts,\n\t\tsendShortcut,\n\t\tmentions,\n\t\tslashCommands,\n\t\tlink,\n\t\tonPaste,\n\t\tonReady,\n\t\tonChange,\n\t\tonSend,\n\t\tonFocus,\n\t\tonBlur,\n\t\tonSelectionChange,\n\t\tminHeight,\n\t\tmaxHeight,\n\t\tstyle,\n\t\tclassName,\n\t\teditorClassName,\n\t\teditorStyle,\n\t\trenderJsonError,\n\t} = props;\n\n\tconst isJsonMode = !!features?.jsonMode;\n\tconst isRichPaste = !!features?.richPaste;\n\n\t// Pick the right sanitizer: email channels (richPaste) get the full email\n\t// allowlist; non-email channels get the basic formatting allowlist.\n\tconst sanitizer = isRichPaste ? sanitizeEmailHtml : sanitizeBasicHtml;\n\tconst normalize = useCallback(\n\t\t(html: string) => normalizeHtml(html, sanitizer),\n\t\t[sanitizer],\n\t);\n\n\t// Live JSON parse error, shown inside the editor when jsonMode is on.\n\t// null = valid (or not applicable) → nothing rendered.\n\tconst [jsonError, setJsonError] = useState<JsonParseResult | null>(null);\n\t// Transient \"Copied\" state for the jsonMode copy button.\n\tconst [jsonCopied, setJsonCopied] = useState(false);\n\t// jsonMode: no content yet → centered code-glyph + placeholder overlay.\n\tconst [jsonEmpty, setJsonEmpty] = useState(\n\t\tisJsonMode && !(initialContent ?? '').trim(),\n\t);\n\t// jsonMode: hide the placeholder overlay while the editor is focused, so\n\t// clicking in gives a clean field to type into.\n\tconst [jsonFocused, setJsonFocused] = useState(false);\n\n\t// JSON body mode: treat initialContent as raw JSON text and wrap it in a code\n\t// block. Skips section/HTML normalisation entirely.\n\tconst initialEditorContent = isJsonMode\n\t\t? buildJsonCodeBlockHtml(initialContent ?? '')\n\t\t: sections?.length\n\t\t? buildSectionedContent(\n\t\t\t\tnormalize(initialContent ?? ''),\n\t\t\t\tsections.map((s) => ({ ...s, content: normalize(s.content) })),\n\t\t )\n\t\t: normalize(initialContent ?? '');\n\n\t// ── Command queue ─────────────────────────────────────────────────────────\n\t// TipTap's useEditor initializes asynchronously; the editor instance is null\n\t// until the first commit. Any imperative method called before the editor is\n\t// ready is enqueued here and flushed automatically once it becomes non-null.\n\t// Consumers never need setTimeout or readiness guards.\n\tconst pendingQueue = useRef<Array<(e: Editor) => void>>([]);\n\tconst hasCalledOnReady = useRef(false);\n\t// Keep stable refs to all callbacks so useEditor receives the same function\n\t// identity on every render — prevents TipTap from re-registering event\n\t// handlers every time the parent re-renders with new inline function props.\n\tconst onReadyRef = useRef(onReady);\n\tonReadyRef.current = onReady;\n\tconst onChangeRef = useRef(onChange);\n\tonChangeRef.current = onChange;\n\tconst onSelectionChangeRef = useRef(onSelectionChange);\n\tonSelectionChangeRef.current = onSelectionChange;\n\tconst prevFormatsRef = useRef<FormatState>(DEFAULT_FORMAT_STATE);\n\tconst onFocusRef = useRef(onFocus);\n\tonFocusRef.current = onFocus;\n\tconst onBlurRef = useRef(onBlur);\n\tonBlurRef.current = onBlur;\n\tconst onSendRef = useRef(onSend);\n\tonSendRef.current = onSend;\n\tconst agentMentionsRef = useRef(mentions?.agents ?? []);\n\tagentMentionsRef.current = mentions?.agents ?? [];\n\tconst teamMentionsRef = useRef(mentions?.teams ?? []);\n\tteamMentionsRef.current = mentions?.teams ?? [];\n\tconst slashCommandsRef = useRef(slashCommands?.items ?? []);\n\tslashCommandsRef.current = slashCommands?.items ?? [];\n\n\tconst editor = useEditor({\n\t\textensions: buildExtensions({\n\t\t\tfeatures,\n\t\t\tplaceholder: props.placeholder,\n\t\t\tmaxCharacters,\n\t\t\tcharacterLimit,\n\t\t\tcharacterLimitHard,\n\t\t\thasSections: (sections?.length ?? 0) > 0,\n\t\t\tmentions: {\n\t\t\t\tagents: mentions ? agentMentionsRef : undefined,\n\t\t\t\tteams: mentions ? teamMentionsRef : undefined,\n\t\t\t},\n\t\t\tslashCommands: slashCommands ? slashCommandsRef : undefined,\n\t\t\tonPaste,\n\t\t\tonSend: onSend ? (snapshot) => onSendRef.current?.(snapshot) : undefined,\n\t\t\tsendShortcut,\n\t\t\tshortcuts,\n\t\t\tonMentionSelected: mentions?.onSelect,\n\t\t\tonSlashCommandSelected: slashCommands?.onSelect,\n\t\t\trenderMentionItem: mentions?.renderItem,\n\t\t\trenderMentionDropdown: mentions?.renderDropdown,\n\t\t\tremoveMentionTriggerOnDismiss: mentions?.removeTriggerOnDismiss,\n\t\t\trenderMentionChipIcon: mentions?.renderChipIcon,\n\t\t\trenderSlashCommandItem: slashCommands?.renderItem,\n\t\t\trenderSlashCommandDropdown: slashCommands?.renderDropdown,\n\t\t}),\n\t\tcontent: initialEditorContent,\n\t\teditable: !disabled,\n\t\timmediatelyRender: false, // SSR-safe — NEVER remove this\n\t\teditorProps: {\n\t\t\tattributes: {\n\t\t\t\t...(editorClassName ? { class: editorClassName } : {}),\n\t\t\t\t...(editorStyle ? { style: cssToString(editorStyle) } : {}),\n\t\t\t},\n\t\t},\n\t\tonUpdate: ({ editor: e }) => {\n\t\t\tonChangeRef.current?.(extractContent(e));\n\t\t\tif (isJsonMode) {\n\t\t\t\tconst text = getCodeBlockText(e);\n\t\t\t\tconst result = parseJson(text);\n\t\t\t\tsetJsonError(result.valid ? null : result);\n\t\t\t\tsetJsonEmpty(!text.trim());\n\t\t\t}\n\t\t},\n\t\tonTransaction: ({ editor: e }) => {\n\t\t\tconst next = extractActiveFormats(e);\n\t\t\tconst prev = prevFormatsRef.current;\n\t\t\tconst changed =\n\t\t\t\tprev.bold !== next.bold ||\n\t\t\t\tprev.italic !== next.italic ||\n\t\t\t\tprev.underline !== next.underline ||\n\t\t\t\tprev.strike !== next.strike ||\n\t\t\t\tprev.bulletList !== next.bulletList ||\n\t\t\t\tprev.orderedList !== next.orderedList ||\n\t\t\t\tprev.blockquote !== next.blockquote ||\n\t\t\t\tprev.codeBlock !== next.codeBlock ||\n\t\t\t\tprev.superscript !== next.superscript ||\n\t\t\t\tprev.subscript !== next.subscript ||\n\t\t\t\tprev.textAlign !== next.textAlign ||\n\t\t\t\tprev.fontFamily !== next.fontFamily ||\n\t\t\t\tprev.fontSize !== next.fontSize ||\n\t\t\t\tprev.color !== next.color ||\n\t\t\t\tprev.highlight !== next.highlight ||\n\t\t\t\tprev.link?.href !== next.link?.href;\n\t\t\tif (changed) {\n\t\t\t\tprevFormatsRef.current = next;\n\t\t\t\tonSelectionChangeRef.current?.(next);\n\t\t\t}\n\t\t},\n\t\tonFocus: () => {\n\t\t\tsetJsonFocused(true);\n\t\t\tonFocusRef.current?.();\n\t\t},\n\t\tonBlur: () => {\n\t\t\tsetJsonFocused(false);\n\t\t\tonBlurRef.current?.();\n\t\t},\n\t});\n\n\t// ── enqueue ───────────────────────────────────────────────────────────────\n\t// Run immediately if the editor is ready; otherwise defer to the queue.\n\t// Closures passed to enqueue MUST capture all parameters explicitly —\n\t// they must NOT close over `editor` (which would be null at enqueue time).\n\tfunction enqueue(op: (e: Editor) => void): void {\n\t\tif (editor) {\n\t\t\top(editor);\n\t\t} else {\n\t\t\tpendingQueue.current.push(op);\n\t\t}\n\t}\n\n\t// Flush the pending queue and fire onReady when editor transitions null → ready.\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\t\tif (pendingQueue.current.length > 0) {\n\t\t\tconst queue = pendingQueue.current.splice(0);\n\t\t\tqueue.forEach((op) => op(editor));\n\t\t}\n\t\tif (!hasCalledOnReady.current) {\n\t\t\thasCalledOnReady.current = true;\n\t\t\tonReadyRef.current?.();\n\t\t}\n\t\t// Surface an error for invalid initialContent immediately on mount.\n\t\tif (isJsonMode) {\n\t\t\tconst text = getCodeBlockText(editor);\n\t\t\tconst result = parseJson(text);\n\t\t\tsetJsonError(result.valid ? null : result);\n\t\t\tsetJsonEmpty(!text.trim());\n\t\t}\n\t}, [editor, isJsonMode]);\n\n\tuseImperativeHandle(\n\t\tref,\n\t\t() => ({\n\t\t\t// ── Focus ────────────────────────────────────────────────────────\n\t\t\tfocus: (position) => enqueue((e) => e.commands.focus(position)),\n\t\t\tblur: () => enqueue((e) => e.commands.blur()),\n\n\t\t\t// ── Content ──────────────────────────────────────────────────────\n\t\t\tclearContent: () => enqueue((e) => e.commands.clearContent(true)),\n\t\t\tsetContent: (html) => {\n\t\t\t\tconst normalised = normalize(html);\n\t\t\t\tenqueue((e) => e.commands.setContent(normalised, { emitUpdate: true }));\n\t\t\t},\n\t\t\tinsertContent: (html) => {\n\t\t\t\tconst normalised = normalize(html);\n\t\t\t\tenqueue((e) => e.commands.insertContent(normalised));\n\t\t\t},\n\t\t\tinsertInlineContent: (html) => {\n\t\t\t\tenqueue((e) => insertInlineHtml(e, html));\n\t\t\t},\n\t\t\tinsertAtStart: (html) => {\n\t\t\t\tconst normalised = normalize(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(1, normalised));\n\t\t\t},\n\t\t\tinsertBlock: (html) => {\n\t\t\t\tconst normalised = normalize(html);\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\tappendInline: (html) => {\n\t\t\t\tconst normalised = normalize(html);\n\t\t\t\t// doc.content.size is after the last </p> (block boundary).\n\t\t\t\t// Subtract 1 to land inside the last paragraph so text appends\n\t\t\t\t// inline rather than being wrapped in a new paragraph each call.\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size - 1, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\t// Backwards-compatible aliases\n\t\t\tinsertAtEnd(html) {\n\t\t\t\tthis.insertBlock(html);\n\t\t\t},\n\t\t\tappendContent(html) {\n\t\t\t\tthis.appendInline(html);\n\t\t\t},\n\t\t\tgetContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tgetJSON: () => editor?.getJSON() ?? null,\n\t\t\tgetMentions: () => {\n\t\t\t\tconst agentIds = new Set<string>();\n\t\t\t\tconst teamIds = new Set<string>();\n\t\t\t\tif (!editor) return { agentIds: [], teamIds: [] };\n\t\t\t\teditor.state.doc.descendants((node) => {\n\t\t\t\t\tif (node.type.name === 'mentionAgent' && node.attrs['id'] != null) {\n\t\t\t\t\t\tagentIds.add(String(node.attrs['id']));\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tnode.type.name === 'mentionTeam' &&\n\t\t\t\t\t\tnode.attrs['id'] != null\n\t\t\t\t\t) {\n\t\t\t\t\t\tteamIds.add(String(node.attrs['id']));\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn { agentIds: Array.from(agentIds), teamIds: Array.from(teamIds) };\n\t\t\t},\n\n\t\t\t// ── Selection ────────────────────────────────────────────────────\n\t\t\tgetCursorPosition: () => {\n\t\t\t\tif (!editor) return { from: 0, to: 0 };\n\t\t\t\tconst { from, to } = editor.state.selection;\n\t\t\t\treturn { from, to };\n\t\t\t},\n\t\t\tinsertAtPosition: (pos, html) => {\n\t\t\t\tconst normalised = normalize(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(pos, normalised));\n\t\t\t},\n\t\t\tgetSelectedText: () => {\n\t\t\t\tif (!editor) return '';\n\t\t\t\tconst { state } = editor;\n\t\t\t\tconst { from, to, empty } = state.selection;\n\t\t\t\tif (!empty) {\n\t\t\t\t\treturn state.doc.textBetween(from, to, ' ');\n\t\t\t\t}\n\t\t\t\t// When the cursor is inside a link with nothing selected, return the\n\t\t\t\t// full link text — useful for pre-filling a link modal's text field.\n\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\tif (linkMarkType) {\n\t\t\t\t\tconst range = getMarkRange(state.doc.resolve(from), linkMarkType);\n\t\t\t\t\tif (range) {\n\t\t\t\t\t\treturn state.doc.textBetween(range.from, range.to, ' ');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn '';\n\t\t\t},\n\n\t\t\t// ── Character count ───────────────────────────────────────────────\n\t\t\tgetCharacterCount: () => ({\n\t\t\t\tcount:\n\t\t\t\t\teditor?.storage.characterCount?.characters?.() ??\n\t\t\t\t\teditor?.getText().length ??\n\t\t\t\t\t0,\n\t\t\t\tlimit: maxCharacters ?? null,\n\t\t\t}),\n\n\t\t\t// ── Sections ─────────────────────────────────────────────────────\n\t\t\tgetSectionContent: (sectionId) =>\n\t\t\t\teditor\n\t\t\t\t\t? extractSectionContent(editor, sectionId)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\n\t\t\tsetSectionContent: (sectionId, html) => {\n\t\t\t\tconst normalised = normalize(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, normalised));\n\t\t\t},\n\n\t\t\tfocusSection: (sectionId) => {\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tif (sectionId === 'body') {\n\t\t\t\t\t\tlet endOfBody = e.state.doc.content.size - 1;\n\t\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\t\tendOfBody === e.state.doc.content.size - 1\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tendOfBody = pos - 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn endOfBody === e.state.doc.content.size - 1;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (endOfBody < 1) endOfBody = 1;\n\t\t\t\t\t\te.chain().focus().setTextSelection(endOfBody).run();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet targetPos = -1;\n\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\tif (targetPos !== -1) return false;\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// pos + nodeSize lands right after the divider;\n\t\t\t\t\t\t\t// +1 more puts us inside the first paragraph of that section.\n\t\t\t\t\t\t\ttargetPos = pos + node.nodeSize + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tif (targetPos !== -1) {\n\t\t\t\t\t\te.chain().focus().setTextSelection(targetPos).run();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\n\t\t\tclearSection: (sectionId) => {\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, '<p></p>'));\n\t\t\t},\n\n\t\t\t// ── Convenience body shorthands ───────────────────────────────────\n\t\t\tgetBodyContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractBodyContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tsetBodyContent: (html) => {\n\t\t\t\tconst normalised = normalize(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, 'body', normalised));\n\t\t\t},\n\t\t\tsetBodyAndSections: (body, sections) => {\n\t\t\t\tconst html = buildSectionedContent(\n\t\t\t\t\tnormalize(body),\n\t\t\t\t\tsections.map((s) => ({\n\t\t\t\t\t\tid: s.id,\n\t\t\t\t\t\tcontent: normalize(s.content),\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t\tenqueue((e) => e.commands.setContent(html, { emitUpdate: true }));\n\t\t\t},\n\t\t\tappendBodyContent: (html) => {\n\t\t\t\tconst normalised = normalize(html);\n\t\t\t\t// findSectionEndPos returns the position of the first divider (or\n\t\t\t\t// doc.content.size), which is the block boundary after the last </p>.\n\t\t\t\t// Subtract 1 to stay inside the last paragraph so successive calls\n\t\t\t\t// append inline text rather than creating a new paragraph each time.\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst boundaryPos = findSectionEndPos(e, 'body');\n\t\t\t\t\te.commands.insertContentAt(boundaryPos - 1, normalised, {\n\t\t\t\t\t\tparseOptions: { preserveWhitespace: true },\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionStart: (sectionId, html) => {\n\t\t\t\tconst normalised = normalize(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionStartPos(e, sectionId);\n\t\t\t\t\tif (pos !== -1)\n\t\t\t\t\t\te.commands.insertContentAt(pos, normalised, {\n\t\t\t\t\t\t\tparseOptions: { preserveWhitespace: true },\n\t\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionEnd: (sectionId, html) => {\n\t\t\t\tconst normalised = normalize(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionEndPos(e, sectionId);\n\t\t\t\t\te.commands.insertContentAt(pos, normalised, {\n\t\t\t\t\t\tparseOptions: { preserveWhitespace: true },\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\t// ── Formats & actions ─────────────────────────────────────────────\n\t\t\tgetActiveFormats: () =>\n\t\t\t\teditor ? extractActiveFormats(editor) : DEFAULT_FORMAT_STATE,\n\t\t\tactions: {\n\t\t\t\ttoggleBold: () => editor?.chain().focus().toggleBold().run(),\n\t\t\t\ttoggleItalic: () => editor?.chain().focus().toggleItalic().run(),\n\t\t\t\ttoggleUnderline: () => editor?.chain().focus().toggleUnderline().run(),\n\t\t\t\ttoggleStrike: () => editor?.chain().focus().toggleStrike().run(),\n\t\t\t\ttoggleBulletList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBulletList().run(),\n\t\t\t\ttoggleOrderedList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleOrderedList().run(),\n\t\t\t\ttoggleBlockquote: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBlockquote().run(),\n\t\t\t\ttoggleCodeBlock: () => editor?.chain().focus().toggleCodeBlock().run(),\n\t\t\t\tsetTextAlign: (align) =>\n\t\t\t\t\teditor?.chain().focus().setTextAlign(align).run(),\n\t\t\t\tsetFontFamily: (font) =>\n\t\t\t\t\teditor?.chain().focus().setFontFamily(font).run(),\n\t\t\t\tsetFontSize: (size) => editor?.chain().focus().setFontSize(size).run(),\n\t\t\t\tsetColor: (color) => editor?.chain().focus().setColor(color).run(),\n\t\t\t\tsetHighlight: (color) =>\n\t\t\t\t\teditor?.chain().focus().toggleHighlight({ color }).run(),\n\t\t\t\tunsetColor: () => editor?.chain().focus().unsetColor().run(),\n\t\t\t\tunsetHighlight: () => editor?.chain().focus().unsetHighlight().run(),\n\t\t\t\tsetLink: (href, text) => {\n\t\t\t\t\tif (!editor) return;\n\t\t\t\t\tif (text !== undefined) {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.command(({ tr, state }) => {\n\t\t\t\t\t\t\t\tconst { from, to } = tr.selection;\n\t\t\t\t\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\t\t\t\t\tif (!linkMarkType) return false;\n\t\t\t\t\t\t\t\tconst linkNode = state.schema.text(text, [\n\t\t\t\t\t\t\t\t\tlinkMarkType.create({ href }),\n\t\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\t\tconst space = state.schema.text(' ');\n\t\t\t\t\t\t\t\ttr.replaceWith(from, to, [linkNode, space]);\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t} else {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t\t.insertContent(' ')\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tupdateLink: (href) =>\n\t\t\t\t\teditor\n\t\t\t\t\t\t?.chain()\n\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t.run(),\n\t\t\t\tremoveLink: () =>\n\t\t\t\t\teditor?.chain().focus().extendMarkRange('link').unsetLink().run(),\n\t\t\t\tinsertEmoji: (emoji) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(emoji).run(),\n\t\t\t\tinsertVariable: (variableName) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(`{{${variableName}}}`).run(),\n\t\t\t\tinsertHtml: (html) => editor?.commands.insertContent(normalize(html)),\n\t\t\t\topenMentionMenu: (char = '@') => {\n\t\t\t\t\tif (!editor) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\t// Collapse to the selection's END first — insertContent over a live\n\t\t\t\t\t// selection would REPLACE the selected text with the trigger char.\n\t\t\t\t\tconst { to } = editor.state.selection;\n\t\t\t\t\tconst prev = to > 1 ? editor.state.doc.textBetween(to - 1, to) : '';\n\t\t\t\t\tconst needsSpace = prev !== '' && !/\\s/.test(prev);\n\t\t\t\t\teditor\n\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t.setTextSelection(to)\n\t\t\t\t\t\t.insertContent(needsSpace ? ` ${char}` : char)\n\t\t\t\t\t\t.run();\n\t\t\t\t},\n\t\t\t\tundo: () => editor?.chain().focus().undo().run(),\n\t\t\t\tredo: () => editor?.chain().focus().redo().run(),\n\t\t\t\tcanUndo: () => editor?.can().undo() ?? false,\n\t\t\t\tcanRedo: () => editor?.can().redo() ?? false,\n\t\t\t\ttoggleSuperscript: () =>\n\t\t\t\t\teditor?.chain().focus().toggleSuperscript().run(),\n\t\t\t\ttoggleSubscript: () => editor?.chain().focus().toggleSubscript().run(),\n\t\t\t\tinsertImage: (src) => editor?.chain().focus().setImage({ src }).run(),\n\t\t\t},\n\n\t\t\t// ── JSON body ─────────────────────────────────────────────────────\n\t\t\tjson: features?.jsonMode\n\t\t\t\t? {\n\t\t\t\t\t\tgetText: () => (editor ? getCodeBlockText(editor) : ''),\n\t\t\t\t\t\tsetText: (raw) => enqueue((e) => setCodeBlockText(e, raw)),\n\t\t\t\t\t\tparse: () => parseJson(editor ? getCodeBlockText(editor) : ''),\n\t\t\t\t\t\tisValid: () =>\n\t\t\t\t\t\t\tparseJson(editor ? getCodeBlockText(editor) : '').valid,\n\t\t\t\t\t\tformat: (indent = 2) =>\n\t\t\t\t\t\t\tenqueue((e) => {\n\t\t\t\t\t\t\t\tconst { valid, value } = parseJson(getCodeBlockText(e));\n\t\t\t\t\t\t\t\tif (!valid || value === null) return;\n\t\t\t\t\t\t\t\tsetCodeBlockText(e, JSON.stringify(value, null, indent));\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\tminify: () =>\n\t\t\t\t\t\t\tenqueue((e) => {\n\t\t\t\t\t\t\t\tconst { valid, value } = parseJson(getCodeBlockText(e));\n\t\t\t\t\t\t\t\tif (!valid || value === null) return;\n\t\t\t\t\t\t\t\tsetCodeBlockText(e, JSON.stringify(value));\n\t\t\t\t\t\t\t}),\n\t\t\t\t }\n\t\t\t\t: undefined,\n\t\t}),\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t[editor],\n\t);\n\n\t// ── jsonMode floating actions ────────────────────────────────────────────\n\t// Beautify pretty-prints in place (no-op / disabled while the JSON is broken);\n\t// Copy writes the raw text to the clipboard with transient feedback.\n\tconst handleJsonBeautify = () => {\n\t\tif (!editor) return;\n\t\tconst { valid, value } = parseJson(getCodeBlockText(editor));\n\t\tif (!valid || value === null) return;\n\t\tsetCodeBlockText(editor, JSON.stringify(value, null, 2));\n\t};\n\tconst handleJsonCopy = () => {\n\t\tif (!editor) return;\n\t\tvoid navigator.clipboard?.writeText(getCodeBlockText(editor));\n\t\tsetJsonCopied(true);\n\t\tsetTimeout(() => setJsonCopied(false), 1500);\n\t};\n\n\tif (!editor) return null;\n\n\treturn (\n\t\t<BikEditorShell\n\t\t\tminHeight={minHeight}\n\t\t\tmaxHeight={maxHeight}\n\t\t\ttightParagraphs={!features?.richPaste}\n\t\t\tjsonMode={isJsonMode}\n\t\t\tstyle={style}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t{isJsonMode && (\n\t\t\t\t<BikJsonHeader>\n\t\t\t\t\t<span className=\"bik-json-header-label\">JSON</span>\n\t\t\t\t\t<div className=\"bik-json-header-actions\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tonClick={handleJsonBeautify}\n\t\t\t\t\t\t\tdisabled={!!jsonError || jsonEmpty}\n\t\t\t\t\t\t\ttitle=\"Format JSON\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<WandSparkles size={16} />\n\t\t\t\t\t\t\t<BodyCaption>Beautify</BodyCaption>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tonClick={handleJsonCopy}\n\t\t\t\t\t\t\tdisabled={jsonEmpty}\n\t\t\t\t\t\t\ttitle=\"Copy JSON\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Copy size={16} />\n\t\t\t\t\t\t\t{jsonCopied && <BodyCaption>Copied</BodyCaption>}\n\t\t\t\t\t\t</button>\n\t\t\t\t\t</div>\n\t\t\t\t</BikJsonHeader>\n\t\t\t)}\n\t\t\t{isJsonMode ? (\n\t\t\t\t<BikJsonBody $error={!!jsonError}>\n\t\t\t\t\t<EditorContent editor={editor} />\n\t\t\t\t\t{jsonEmpty && !jsonFocused && (\n\t\t\t\t\t\t<BikJsonEmptyState aria-hidden>\n\t\t\t\t\t\t\t<Code size={20} />\n\t\t\t\t\t\t\t<span>{props.placeholder ?? 'Type or paste JSON here'}</span>\n\t\t\t\t\t\t</BikJsonEmptyState>\n\t\t\t\t\t)}\n\t\t\t\t</BikJsonBody>\n\t\t\t) : (\n\t\t\t\t<EditorContent editor={editor} />\n\t\t\t)}\n\t\t\t<LinkBubbleMenu editor={editor} renderLinkTooltip={link?.renderTooltip} />\n\t\t\t{isJsonMode && jsonError ? (\n\t\t\t\trenderJsonError ? (\n\t\t\t\t\trenderJsonError(jsonError)\n\t\t\t\t) : (\n\t\t\t\t\t<BikJsonError>\n\t\t\t\t\t\t<Info size={16} />\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t{jsonError.line != null && (\n\t\t\t\t\t\t\t\t<strong>\n\t\t\t\t\t\t\t\t\tLine {jsonError.line}\n\t\t\t\t\t\t\t\t\t{jsonError.column != null\n\t\t\t\t\t\t\t\t\t\t? `, column ${jsonError.column}`\n\t\t\t\t\t\t\t\t\t\t: ''}\n\t\t\t\t\t\t\t\t\t:{' '}\n\t\t\t\t\t\t\t\t</strong>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t{jsonError.error}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</BikJsonError>\n\t\t\t\t)\n\t\t\t) : null}\n\t\t</BikEditorShell>\n\t);\n};\n\nexport const BikEditor = forwardRef<BikEditorRef, BikEditorProps>(\n\tBikEditorInner,\n);\nBikEditor.displayName = 'BikEditor';\n"],"names":["cssToString","style","k","v","c","BikEditorInner","props","ref","initialContent","sections","features","disabled","maxCharacters","characterLimit","characterLimitHard","shortcuts","sendShortcut","mentions","slashCommands","link","onPaste","onReady","onChange","onSend","onFocus","onBlur","onSelectionChange","minHeight","maxHeight","className","editorClassName","editorStyle","renderJsonError","isJsonMode","sanitizer","sanitizeEmailHtml","sanitizeBasicHtml","normalize","useCallback","html","normalizeHtml","jsonError","setJsonError","useState","jsonCopied","setJsonCopied","jsonEmpty","setJsonEmpty","jsonFocused","setJsonFocused","initialEditorContent","buildJsonCodeBlockHtml","buildSectionedContent","s","pendingQueue","useRef","hasCalledOnReady","onReadyRef","onChangeRef","onSelectionChangeRef","prevFormatsRef","DEFAULT_FORMAT_STATE","onFocusRef","onBlurRef","onSendRef","agentMentionsRef","teamMentionsRef","slashCommandsRef","editor","useEditor","buildExtensions","snapshot","e","extractContent","text","getCodeBlockText","result","parseJson","next","extractActiveFormats","prev","enqueue","op","useEffect","useImperativeHandle","position","normalised","insertInlineHtml","agentIds","teamIds","node","from","to","pos","state","empty","linkMarkType","range","getMarkRange","sectionId","extractSectionContent","setSectionContentInEditor","endOfBody","targetPos","extractBodyContent","body","boundaryPos","findSectionEndPos","findSectionStartPos","align","font","size","color","href","tr","linkNode","space","emoji","variableName","char","needsSpace","src","raw","setCodeBlockText","indent","valid","value","handleJsonBeautify","handleJsonCopy","jsxs","BikEditorShell","BikJsonHeader","jsx","WandSparkles","BodyCaption","Copy","BikJsonBody","EditorContent","BikJsonEmptyState","Code","LinkBubbleMenu","BikJsonError","Info","BikEditor","forwardRef"],"mappings":";;;;;;;;;;;;;;;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  * editor is created lazily on the client (`immediatelyRender: false`), meaning
19
19
  * the value is only parsed client-side and passing through on the server is safe.
20
20
  */
21
- export declare function normalizeHtml(html: string): string;
21
+ export declare function normalizeHtml(html: string, sanitizer?: (input: string) => string): string;
22
22
  /**
23
23
  * Make editor HTML portable across email clients and chat renderers.
24
24
  *
@@ -1,112 +1,113 @@
1
1
  import { DOMSerializer as p, DOMParser as a } from "../node_modules/prosemirror-model/dist/index.js";
2
- import { normalizeHardBreaks as v } from "./extensions/plainClipboard/pasteUtils.js";
3
- function g(e) {
2
+ import { sanitizeEmailHtml as v } from "../helpers/sanitize.js";
3
+ import { normalizeHardBreaks as g } from "./extensions/plainClipboard/pasteUtils.js";
4
+ function b(e, n = v) {
4
5
  if (!e || typeof document > "u") return e;
5
- const t = document.createElement("div");
6
- return t.innerHTML = e, t.querySelectorAll("span").forEach((i) => {
7
- const n = i.getAttribute("data-type");
8
- if (i.hasAttribute("style") || i.hasAttribute("data-variable") || n !== null && n.startsWith("mention"))
6
+ const i = document.createElement("div");
7
+ return i.innerHTML = n(e), i.querySelectorAll("span").forEach((t) => {
8
+ const o = t.getAttribute("data-type");
9
+ if (t.hasAttribute("style") || t.hasAttribute("data-variable") || o !== null && o.startsWith("mention"))
9
10
  return;
10
- const r = i.parentNode;
11
+ const r = t.parentNode;
11
12
  if (r) {
12
- for (; i.firstChild; ) r.insertBefore(i.firstChild, i);
13
- r.removeChild(i);
13
+ for (; t.firstChild; ) r.insertBefore(t.firstChild, t);
14
+ r.removeChild(t);
14
15
  }
15
- }), t.querySelectorAll("p").forEach((i) => {
16
- i.querySelectorAll("br").length === 1 && (i.textContent ?? "").trim() === "" && (i.innerHTML = "");
17
- }), t.innerHTML;
16
+ }), i.querySelectorAll("p").forEach((t) => {
17
+ t.querySelectorAll("br").length === 1 && (t.textContent ?? "").trim() === "" && (t.innerHTML = "");
18
+ }), i.innerHTML;
18
19
  }
19
20
  function u(e) {
20
- const t = document.createElement("div");
21
- t.innerHTML = e;
22
- const i = document.createTreeWalker(t, NodeFilter.SHOW_TEXT);
23
- let n;
24
- for (; n = i.nextNode(); )
25
- n.nodeValue && n.nodeValue.includes(" ") && (n.nodeValue = n.nodeValue.replace(/ {2}/g, "  "));
26
- const r = t.querySelectorAll("p");
27
- for (const o of Array.from(r)) {
28
- if (o.childNodes.length === 0) {
29
- o.appendChild(document.createElement("br"));
21
+ const n = document.createElement("div");
22
+ n.innerHTML = e;
23
+ const i = document.createTreeWalker(n, NodeFilter.SHOW_TEXT);
24
+ let t;
25
+ for (; t = i.nextNode(); )
26
+ t.nodeValue && t.nodeValue.includes(" ") && (t.nodeValue = t.nodeValue.replace(/ {2}/g, "  "));
27
+ const o = n.querySelectorAll("p");
28
+ for (const r of Array.from(o)) {
29
+ if (r.childNodes.length === 0) {
30
+ r.appendChild(document.createElement("br"));
30
31
  continue;
31
32
  }
32
- o.lastChild instanceof HTMLBRElement && o.childNodes.length > 1 && o.appendChild(document.createElement("br"));
33
+ r.lastChild instanceof HTMLBRElement && r.childNodes.length > 1 && r.appendChild(document.createElement("br"));
33
34
  }
34
- return t.innerHTML;
35
+ return n.innerHTML;
35
36
  }
36
- function L(e, t) {
37
- const i = g(t), n = document.createElement("div");
38
- n.innerHTML = i;
39
- const r = a.fromSchema(e.schema).parseSlice(n, {
37
+ function B(e, n) {
38
+ const i = b(n), t = document.createElement("div");
39
+ t.innerHTML = i;
40
+ const o = a.fromSchema(e.schema).parseSlice(t, {
40
41
  preserveWhitespace: !0
41
42
  });
42
- if (r.size === 0) return;
43
- const { from: o, to: c } = e.state.selection, s = e.state.tr.replaceRange(o, c, r);
43
+ if (o.size === 0) return;
44
+ const { from: r, to: c } = e.state.selection, s = e.state.tr.replaceRange(r, c, o);
44
45
  e.view.dispatch(s);
45
46
  }
46
47
  const d = (e) => `<div data-section-divider="${e}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;
47
- function B(e, t) {
48
+ function M(e, n) {
48
49
  let i = e;
49
- for (const n of t)
50
- i += d(n.id) + n.content;
50
+ for (const t of n)
51
+ i += d(t.id) + t.content;
51
52
  return i;
52
53
  }
53
- function b(e) {
54
- return e ? y(e).get("body") ?? e : "";
54
+ function y(e) {
55
+ return e ? A(e).get("body") ?? e : "";
55
56
  }
56
- function M(e) {
57
+ function N(e) {
57
58
  if (!e) return "";
58
- const t = b(e);
59
- return e.substring(t.length);
59
+ const n = y(e);
60
+ return e.substring(n.length);
60
61
  }
61
- function y(e) {
62
- const t = /* @__PURE__ */ new Map(), i = /<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g, n = [];
63
- let r;
64
- for (; (r = i.exec(e)) !== null; )
65
- n.push({
66
- id: r[1],
67
- index: r.index,
68
- endIndex: r.index + r[0].length
62
+ function A(e) {
63
+ const n = /* @__PURE__ */ new Map(), i = /<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g, t = [];
64
+ let o;
65
+ for (; (o = i.exec(e)) !== null; )
66
+ t.push({
67
+ id: o[1],
68
+ index: o.index,
69
+ endIndex: o.index + o[0].length
69
70
  });
70
- if (n.length === 0)
71
- return t.set("body", e), t;
72
- t.set("body", e.slice(0, n[0].index));
73
- for (let o = 0; o < n.length; o++) {
74
- const c = n[o].endIndex, s = o + 1 < n.length ? n[o + 1].index : e.length;
75
- t.set(n[o].id, e.slice(c, s));
71
+ if (t.length === 0)
72
+ return n.set("body", e), n;
73
+ n.set("body", e.slice(0, t[0].index));
74
+ for (let r = 0; r < t.length; r++) {
75
+ const c = t[r].endIndex, s = r + 1 < t.length ? t[r + 1].index : e.length;
76
+ n.set(t[r].id, e.slice(c, s));
76
77
  }
77
- return t;
78
+ return n;
78
79
  }
79
- function A(e, t) {
80
- const i = f(e, t);
80
+ function x(e, n) {
81
+ const i = f(e, n);
81
82
  if (i === -1)
82
83
  return { html: "", text: "", isEmpty: !0, characterCount: 0 };
83
- const n = m(e, t), r = e.state.doc.slice(i, n), o = document.createElement("div"), c = p.fromSchema(e.schema);
84
- o.appendChild(c.serializeFragment(r.content));
85
- const s = u(o.innerHTML), l = o.textContent ?? "";
84
+ const t = m(e, n), o = e.state.doc.slice(i, t), r = document.createElement("div"), c = p.fromSchema(e.schema);
85
+ r.appendChild(c.serializeFragment(o.content));
86
+ const s = u(r.innerHTML), l = r.textContent ?? "";
86
87
  return { html: s, text: l, isEmpty: !l.trim(), characterCount: l.length };
87
88
  }
88
- function x(e, t) {
89
+ function S(e, n) {
89
90
  const i = document.createElement("div");
90
- return i.innerHTML = t, a.fromSchema(e.schema).parse(i, {
91
+ return i.innerHTML = n, a.fromSchema(e.schema).parse(i, {
91
92
  preserveWhitespace: !0
92
93
  }).content;
93
94
  }
94
- function z(e, t, i) {
95
- const n = f(e, t);
96
- if (n === -1) {
97
- const l = e.state.doc.content.size, h = d(t) + i;
95
+ function P(e, n, i) {
96
+ const t = f(e, n);
97
+ if (t === -1) {
98
+ const l = e.state.doc.content.size, h = d(n) + i;
98
99
  e.commands.insertContentAt(l, h, {
99
100
  updateSelection: !1
100
101
  });
101
102
  return;
102
103
  }
103
- const r = m(e, t), o = x(e, i), { tr: c } = e.state, s = t === "body" ? 0 : n;
104
- c.replaceWith(s, r, o), c.setMeta("addToHistory", !1), e.view.dispatch(c);
104
+ const o = m(e, n), r = S(e, i), { tr: c } = e.state, s = n === "body" ? 0 : t;
105
+ c.replaceWith(s, o, r), c.setMeta("addToHistory", !1), e.view.dispatch(c);
105
106
  }
106
- function N(e) {
107
- return A(e, "body");
107
+ function D(e) {
108
+ return x(e, "body");
108
109
  }
109
- function P(e) {
110
+ function F(e) {
110
111
  return {
111
112
  bold: e.isActive("bold"),
112
113
  italic: e.isActive("italic"),
@@ -119,17 +120,17 @@ function P(e) {
119
120
  link: (() => {
120
121
  if (e.isActive("link"))
121
122
  return { href: e.getAttributes("link").href ?? "" };
122
- const { $from: t } = e.state.selection;
123
- if (t.pos > 0) {
124
- const n = t.doc.resolve(t.pos).marks().find((r) => r.type.name === "link");
125
- if (n)
126
- return { href: n.attrs.href ?? "" };
123
+ const { $from: n } = e.state.selection;
124
+ if (n.pos > 0) {
125
+ const t = n.doc.resolve(n.pos).marks().find((o) => o.type.name === "link");
126
+ if (t)
127
+ return { href: t.attrs.href ?? "" };
127
128
  {
128
- const o = t.nodeBefore?.marks.find(
129
+ const r = n.nodeBefore?.marks.find(
129
130
  (c) => c.type.name === "link"
130
131
  );
131
- if (o)
132
- return { href: o.attrs.href ?? "" };
132
+ if (r)
133
+ return { href: r.attrs.href ?? "" };
133
134
  }
134
135
  }
135
136
  return null;
@@ -143,84 +144,84 @@ function P(e) {
143
144
  subscript: e.isActive("subscript")
144
145
  };
145
146
  }
146
- function D(e) {
147
- const t = u(e.getHTML()), i = v(e.state.doc.content), n = e.schema.node("doc", null, i), r = n.textBetween(0, n.content.size, `
147
+ function I(e) {
148
+ const n = u(e.getHTML()), i = g(e.state.doc.content), t = e.schema.node("doc", null, i), o = t.textBetween(0, t.content.size, `
148
149
 
149
150
  `, `
150
151
  `);
151
152
  return {
152
- html: t,
153
- text: r,
153
+ html: n,
154
+ text: o,
154
155
  isEmpty: e.isEmpty,
155
- characterCount: r.length
156
+ characterCount: o.length
156
157
  };
157
158
  }
158
- function f(e, t) {
159
- if (t === "body") return 1;
159
+ function f(e, n) {
160
+ if (n === "body") return 1;
160
161
  let i = -1;
161
- return e.state.doc.descendants((n, r) => {
162
+ return e.state.doc.descendants((t, o) => {
162
163
  if (i !== -1) return !1;
163
- n.type.name === "sectionDivider" && n.attrs.sectionId === t && (i = r + n.nodeSize);
164
+ t.type.name === "sectionDivider" && t.attrs.sectionId === n && (i = o + t.nodeSize);
164
165
  }), i;
165
166
  }
166
- function m(e, t) {
167
- const i = e.state.doc, n = i.content.size;
168
- if (t === "body") {
167
+ function m(e, n) {
168
+ const i = e.state.doc, t = i.content.size;
169
+ if (n === "body") {
169
170
  let c = -1;
170
171
  return i.descendants((s, l) => {
171
172
  if (c !== -1) return !1;
172
173
  s.type.name === "sectionDivider" && (c = l);
173
- }), c !== -1 ? c : n;
174
+ }), c !== -1 ? c : t;
174
175
  }
175
- let r = !1, o = -1;
176
+ let o = !1, r = -1;
176
177
  return i.descendants((c, s) => {
177
- if (o !== -1) return !1;
178
- if (!r)
179
- return c.type.name === "sectionDivider" && c.attrs.sectionId === t && (r = !0), !1;
180
- c.type.name === "sectionDivider" && (o = s);
181
- }), o !== -1 ? o : n;
178
+ if (r !== -1) return !1;
179
+ if (!o)
180
+ return c.type.name === "sectionDivider" && c.attrs.sectionId === n && (o = !0), !1;
181
+ c.type.name === "sectionDivider" && (r = s);
182
+ }), r !== -1 ? r : t;
182
183
  }
183
- function S(e) {
184
+ function C(e) {
184
185
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
185
186
  }
186
- function C(e) {
187
- return `<pre><code>${S(e ?? "")}</code></pre>`;
187
+ function H(e) {
188
+ return `<pre><code>${C(e ?? "")}</code></pre>`;
188
189
  }
189
- function F(e) {
190
- let t = "", i = !1;
191
- return e.state.doc.descendants((n) => {
190
+ function O(e) {
191
+ let n = "", i = !1;
192
+ return e.state.doc.descendants((t) => {
192
193
  if (i) return !1;
193
- if (n.type.name === "codeBlock")
194
- return t = n.textContent, i = !0, !1;
195
- }), t;
194
+ if (t.type.name === "codeBlock")
195
+ return n = t.textContent, i = !0, !1;
196
+ }), n;
196
197
  }
197
- function I(e, t) {
198
- e.commands.setContent(C(t), { emitUpdate: !0 });
198
+ function q(e, n) {
199
+ e.commands.setContent(H(n), { emitUpdate: !0 });
199
200
  }
200
- function k(e, t) {
201
- const n = e.slice(0, Math.max(0, t)).split(`
201
+ function k(e, n) {
202
+ const t = e.slice(0, Math.max(0, n)).split(`
202
203
  `);
203
204
  return {
204
- line: n.length,
205
- column: (n[n.length - 1]?.length ?? 0) + 1
205
+ line: t.length,
206
+ column: (t[t.length - 1]?.length ?? 0) + 1
206
207
  };
207
208
  }
208
- function H(e, t) {
209
- const i = e.replace(/\s*in JSON at position[\s\S]*$/i, "").trim() || e, n = e.match(/line (\d+) column (\d+)/i);
210
- if (n)
209
+ function E(e, n) {
210
+ const i = e.replace(/\s*in JSON at position[\s\S]*$/i, "").trim() || e, t = e.match(/line (\d+) column (\d+)/i);
211
+ if (t)
211
212
  return {
212
213
  message: i,
213
- line: Number(n[1]),
214
- column: Number(n[2])
214
+ line: Number(t[1]),
215
+ column: Number(t[2])
215
216
  };
216
- const r = e.match(/position (\d+)/i);
217
- if (r) {
218
- const { line: o, column: c } = k(t, Number(r[1]));
219
- return { message: i, line: o, column: c };
217
+ const o = e.match(/position (\d+)/i);
218
+ if (o) {
219
+ const { line: r, column: c } = k(n, Number(o[1]));
220
+ return { message: i, line: r, column: c };
220
221
  }
221
222
  return { message: i, line: null, column: null };
222
223
  }
223
- function O(e) {
224
+ function w(e) {
224
225
  if (!e.trim())
225
226
  return { valid: !0, value: null, error: null, line: null, column: null };
226
227
  try {
@@ -231,33 +232,33 @@ function O(e) {
231
232
  line: null,
232
233
  column: null
233
234
  };
234
- } catch (t) {
235
- const { message: i, line: n, column: r } = H(
236
- t.message,
235
+ } catch (n) {
236
+ const { message: i, line: t, column: o } = E(
237
+ n.message,
237
238
  e
238
239
  );
239
- return { valid: !1, value: null, error: i, line: n, column: r };
240
+ return { valid: !1, value: null, error: i, line: t, column: o };
240
241
  }
241
242
  }
242
243
  export {
243
244
  d as SECTION_DIVIDER_HTML,
244
- C as buildJsonCodeBlockHtml,
245
- B as buildSectionedContent,
246
- P as extractActiveFormats,
247
- y as extractAllSectionsFromHtml,
248
- N as extractBodyContent,
249
- D as extractContent,
250
- A as extractSectionContent,
245
+ H as buildJsonCodeBlockHtml,
246
+ M as buildSectionedContent,
247
+ F as extractActiveFormats,
248
+ A as extractAllSectionsFromHtml,
249
+ D as extractBodyContent,
250
+ I as extractContent,
251
+ x as extractSectionContent,
251
252
  m as findSectionEndPos,
252
253
  f as findSectionStartPos,
253
- b as getBodyHtml,
254
- F as getCodeBlockText,
255
- M as getSectionsHtml,
256
- L as insertInlineHtml,
257
- g as normalizeHtml,
258
- O as parseJson,
259
- I as setCodeBlockText,
260
- z as setSectionContentInEditor,
254
+ y as getBodyHtml,
255
+ O as getCodeBlockText,
256
+ N as getSectionsHtml,
257
+ B as insertInlineHtml,
258
+ b as normalizeHtml,
259
+ w as parseJson,
260
+ q as setCodeBlockText,
261
+ P as setSectionContentInEditor,
261
262
  u as toPortableHtml
262
263
  };
263
264
  //# sourceMappingURL=BikEditor.utils.js.map