@bikdotai/bik-component-library 0.0.823 → 0.0.824-beta.0

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 (98) hide show
  1. package/dist/cjs/components/adbanner/AdBanner.js.map +1 -0
  2. package/dist/cjs/components/{banner → adbanner}/Banner.styled.js +13 -9
  3. package/dist/cjs/components/adbanner/Banner.styled.js.map +1 -0
  4. package/dist/cjs/components/adbanner/BannerInline.js.map +1 -0
  5. package/dist/cjs/components/adbanner/BannerWithImage.js.map +1 -0
  6. package/dist/cjs/components/adbanner/CardBanner.js.map +1 -0
  7. package/dist/cjs/components/adbanner/CardBannerWithImage.js.map +1 -0
  8. package/dist/cjs/components/adbanner/model.js.map +1 -0
  9. package/dist/cjs/editor/BikEditor.js +1 -1
  10. package/dist/cjs/editor/BikEditor.js.map +1 -1
  11. package/dist/cjs/editor/BikEditor.styles.js +122 -2
  12. package/dist/cjs/editor/BikEditor.styles.js.map +1 -1
  13. package/dist/cjs/editor/BikEditor.types.js.map +1 -1
  14. package/dist/cjs/editor/BikEditor.utils.js +3 -2
  15. package/dist/cjs/editor/BikEditor.utils.js.map +1 -1
  16. package/dist/cjs/editor/extensions/buildExtensions.js +3 -1
  17. package/dist/cjs/editor/extensions/buildExtensions.js.map +1 -1
  18. package/dist/cjs/editor/extensions/jsonHighlight/JsonHighlightExtension.js +3 -0
  19. package/dist/cjs/editor/extensions/jsonHighlight/JsonHighlightExtension.js.map +1 -0
  20. package/dist/cjs/editor/extensions/jsonHighlight/tokenizeJson.js +2 -0
  21. package/dist/cjs/editor/extensions/jsonHighlight/tokenizeJson.js.map +1 -0
  22. package/dist/cjs/icons/BIK AI specific/WandSparkles.js +2 -0
  23. package/dist/cjs/icons/BIK AI specific/WandSparkles.js.map +1 -0
  24. package/dist/cjs/icons/index.js +1 -1
  25. package/dist/cjs/index.js +1 -1
  26. package/dist/esm/components/adbanner/AdBanner.js.map +1 -0
  27. package/dist/esm/components/{banner → adbanner}/Banner.styled.js +18 -14
  28. package/dist/esm/components/adbanner/Banner.styled.js.map +1 -0
  29. package/dist/esm/components/adbanner/BannerInline.js.map +1 -0
  30. package/dist/esm/components/adbanner/BannerWithImage.js.map +1 -0
  31. package/dist/esm/components/adbanner/CardBanner.js.map +1 -0
  32. package/dist/esm/components/adbanner/CardBannerWithImage.js.map +1 -0
  33. package/dist/esm/components/adbanner/model.js.map +1 -0
  34. package/dist/esm/editor/BikEditor.js +254 -181
  35. package/dist/esm/editor/BikEditor.js.map +1 -1
  36. package/dist/esm/editor/BikEditor.styles.d.ts +9 -0
  37. package/dist/esm/editor/BikEditor.styles.js +128 -6
  38. package/dist/esm/editor/BikEditor.styles.js.map +1 -1
  39. package/dist/esm/editor/BikEditor.types.d.ts +76 -0
  40. package/dist/esm/editor/BikEditor.types.js.map +1 -1
  41. package/dist/esm/editor/BikEditor.utils.d.ts +15 -1
  42. package/dist/esm/editor/BikEditor.utils.js +155 -92
  43. package/dist/esm/editor/BikEditor.utils.js.map +1 -1
  44. package/dist/esm/editor/extensions/buildExtensions.d.ts +1 -1
  45. package/dist/esm/editor/extensions/buildExtensions.js +86 -55
  46. package/dist/esm/editor/extensions/buildExtensions.js.map +1 -1
  47. package/dist/esm/editor/extensions/jsonHighlight/JsonHighlightExtension.d.ts +14 -0
  48. package/dist/esm/editor/extensions/jsonHighlight/JsonHighlightExtension.js +64 -0
  49. package/dist/esm/editor/extensions/jsonHighlight/JsonHighlightExtension.js.map +1 -0
  50. package/dist/esm/editor/extensions/jsonHighlight/tokenizeJson.d.ts +18 -0
  51. package/dist/esm/editor/extensions/jsonHighlight/tokenizeJson.js +21 -0
  52. package/dist/esm/editor/extensions/jsonHighlight/tokenizeJson.js.map +1 -0
  53. package/dist/esm/editor/index.d.ts +1 -1
  54. package/dist/esm/icons/BIK AI specific/WandSparkles.d.ts +7 -0
  55. package/dist/esm/icons/BIK AI specific/WandSparkles.js +39 -0
  56. package/dist/esm/icons/BIK AI specific/WandSparkles.js.map +1 -0
  57. package/dist/esm/icons/BIK AI specific/index.d.ts +1 -0
  58. package/dist/esm/icons/index.d.ts +1 -1
  59. package/dist/esm/icons/index.js +18 -16
  60. package/dist/esm/icons/index.js.map +1 -1
  61. package/dist/esm/index.d.ts +1 -1
  62. package/dist/esm/index.js +2 -2
  63. package/package.json +1 -1
  64. package/dist/cjs/components/banner/AdBanner.js.map +0 -1
  65. package/dist/cjs/components/banner/Banner.styled.js.map +0 -1
  66. package/dist/cjs/components/banner/BannerInline.js.map +0 -1
  67. package/dist/cjs/components/banner/BannerWithImage.js.map +0 -1
  68. package/dist/cjs/components/banner/CardBanner.js.map +0 -1
  69. package/dist/cjs/components/banner/CardBannerWithImage.js.map +0 -1
  70. package/dist/cjs/components/banner/model.js.map +0 -1
  71. package/dist/esm/components/banner/AdBanner.js.map +0 -1
  72. package/dist/esm/components/banner/Banner.stories.d.ts +0 -39
  73. package/dist/esm/components/banner/Banner.styled.js.map +0 -1
  74. package/dist/esm/components/banner/BannerInline.js.map +0 -1
  75. package/dist/esm/components/banner/BannerWithImage.js.map +0 -1
  76. package/dist/esm/components/banner/CardBanner.js.map +0 -1
  77. package/dist/esm/components/banner/CardBannerWithImage.js.map +0 -1
  78. package/dist/esm/components/banner/model.js.map +0 -1
  79. /package/dist/cjs/components/{banner → adbanner}/AdBanner.js +0 -0
  80. /package/dist/cjs/components/{banner → adbanner}/BannerInline.js +0 -0
  81. /package/dist/cjs/components/{banner → adbanner}/BannerWithImage.js +0 -0
  82. /package/dist/cjs/components/{banner → adbanner}/CardBanner.js +0 -0
  83. /package/dist/cjs/components/{banner → adbanner}/CardBannerWithImage.js +0 -0
  84. /package/dist/cjs/components/{banner → adbanner}/model.js +0 -0
  85. /package/dist/esm/components/{banner → adbanner}/AdBanner.d.ts +0 -0
  86. /package/dist/esm/components/{banner → adbanner}/AdBanner.js +0 -0
  87. /package/dist/esm/components/{banner → adbanner}/Banner.styled.d.ts +0 -0
  88. /package/dist/esm/components/{banner → adbanner}/BannerInline.d.ts +0 -0
  89. /package/dist/esm/components/{banner → adbanner}/BannerInline.js +0 -0
  90. /package/dist/esm/components/{banner → adbanner}/BannerWithImage.d.ts +0 -0
  91. /package/dist/esm/components/{banner → adbanner}/BannerWithImage.js +0 -0
  92. /package/dist/esm/components/{banner → adbanner}/CardBanner.d.ts +0 -0
  93. /package/dist/esm/components/{banner → adbanner}/CardBanner.js +0 -0
  94. /package/dist/esm/components/{banner → adbanner}/CardBannerWithImage.d.ts +0 -0
  95. /package/dist/esm/components/{banner → adbanner}/CardBannerWithImage.js +0 -0
  96. /package/dist/esm/components/{banner → adbanner}/index.d.ts +0 -0
  97. /package/dist/esm/components/{banner → adbanner}/model.d.ts +0 -0
  98. /package/dist/esm/components/{banner → adbanner}/model.js +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"BikEditor.utils.js","sources":["../../../src/editor/BikEditor.utils.ts"],"sourcesContent":["import { Editor } from '@tiptap/core';\nimport { DOMParser, DOMSerializer } from 'prosemirror-model';\nimport { EditorSnapshot, FormatState } from './BikEditor.types';\nimport { normalizeHardBreaks } from './extensions/plainClipboard/pasteUtils';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * 1. Unwrap style-less `<span>` wrappers (plain spans, and editor-cursor spans\n * like Quill's `<span class=\"ql-cursor\">`). Spans that carry inline styling\n * (`color` / `font-family` / `font-size` render as styled spans) or that\n * represent a `{{variable}}` token are PRESERVED — otherwise a setContent\n * round-trip would silently drop colour/font formatting that paste keeps.\n * 2. Collapse placeholder paragraphs (`<p><br></p>`) to `<p></p>`. ProseMirror\n * parses `<p></p>` as an empty paragraph and adds its own DOM `<br>` for the\n * cursor — one blank line, correct height. Leaving the source `<br>` would\n * create a `hard_break` child AND the cursor `<br>` → double-height blank line.\n *\n * Uses the DOM (regex cannot selectively pair span tags). `normalizeHtml` runs\n * in the component body for `initialContent`, so it is guarded for SSR: the\n * editor is created lazily on the client (`immediatelyRender: false`), meaning\n * the value is only parsed client-side and passing through on the server is safe.\n */\nexport function normalizeHtml(html: string): string {\n\tif (!html || typeof document === 'undefined') return html;\n\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = html;\n\n\tcontainer.querySelectorAll('span').forEach((span) => {\n\t\t// Keep schema-backed spans: styled spans, variables, and mention chips\n\t\t// (`data-type=\"mention…\"`). Stripping a mention span would drop the\n\t\t// `data-id`/`data-label`/`data-kind` the editor needs to reparse it.\n\t\tconst dataType = span.getAttribute('data-type');\n\t\tif (\n\t\t\tspan.hasAttribute('style') ||\n\t\t\tspan.hasAttribute('data-variable') ||\n\t\t\t(dataType !== null && dataType.startsWith('mention'))\n\t\t)\n\t\t\treturn;\n\t\tconst parent = span.parentNode;\n\t\tif (!parent) return;\n\t\twhile (span.firstChild) parent.insertBefore(span.firstChild, span);\n\t\tparent.removeChild(span);\n\t});\n\n\tcontainer.querySelectorAll('p').forEach((p) => {\n\t\tif (\n\t\t\tp.querySelectorAll('br').length === 1 &&\n\t\t\t(p.textContent ?? '').trim() === ''\n\t\t) {\n\t\t\tp.innerHTML = '';\n\t\t}\n\t});\n\n\treturn container.innerHTML;\n}\n\n/**\n * Make editor HTML portable across email clients and chat renderers.\n *\n * 1. Preserve consecutive spaces by converting every second space in a run\n * to `&nbsp;` (U+00A0). Standard HTML collapses adjacent regular spaces;\n * alternating with `&nbsp;` prevents that — same convention Gmail uses.\n * 2. Double a trailing `<br>` in content paragraphs so the blank line is\n * visible. A single trailing `<br>` before `</p>` is swallowed by most\n * email clients; `<br><br>` renders as a visible blank line (matches\n * Gmail's output).\n * 3. Convert empty `<p></p>` to `<p><br></p>` — email clients collapse\n * zero-height paragraphs without a `<br>`.\n */\nexport function toPortableHtml(html: string): string {\n\tconst div = document.createElement('div');\n\tdiv.innerHTML = html;\n\n\t// TreeWalker visits only text nodes, skipping HTML tags/attributes, so we safely\n\t// replace consecutive spaces with space + \\u00a0 (nbsp) to prevent email clients from collapsing them\n\tconst walker = document.createTreeWalker(div, NodeFilter.SHOW_TEXT);\n\tlet textNode: Text | null;\n\twhile ((textNode = walker.nextNode() as Text | null)) {\n\t\tif (textNode.nodeValue && textNode.nodeValue.includes(' ')) {\n\t\t\ttextNode.nodeValue = textNode.nodeValue.replace(/ {2}/g, '  ');\n\t\t}\n\t}\n\n\tconst blocks = div.querySelectorAll('p');\n\tfor (const p of Array.from(blocks)) {\n\t\tif (p.childNodes.length === 0) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t\tcontinue;\n\t\t}\n\t\tconst last = p.lastChild;\n\t\tif (last instanceof HTMLBRElement && p.childNodes.length > 1) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t}\n\t}\n\treturn div.innerHTML;\n}\n\n// ---------------------------------------------------------------------------\n// Inline content insertion\n// ---------------------------------------------------------------------------\n\n/**\n * Insert HTML at the current cursor position, merging the first paragraph\n * inline while preserving the block structure of subsequent paragraphs/lists.\n *\n * Uses `parseSlice` which returns an open-ended Slice — the first block merges\n * at the cursor, middle blocks stay intact, and the last block merges with any\n * text that follows the cursor.\n */\nexport function insertInlineHtml(editor: Editor, html: string): void {\n\tconst normalised = normalizeHtml(html);\n\tconst dom = document.createElement('div');\n\tdom.innerHTML = normalised;\n\tconst slice = DOMParser.fromSchema(editor.schema).parseSlice(dom, {\n\t\tpreserveWhitespace: true,\n\t});\n\n\tif (slice.size === 0) return;\n\n\tconst { from, to } = editor.state.selection;\n\tconst tr = editor.state.tr.replaceRange(from, to, slice);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Section divider HTML\n// ---------------------------------------------------------------------------\n\nexport const SECTION_DIVIDER_HTML = (id: string) =>\n\t`<div data-section-divider=\"${id}\" style=\"display:none;height:0;line-height:0;overflow:hidden;\"></div>`;\n\n/**\n * Build initial HTML for an editor with one or more named sections below the body.\n * Each section is separated by an invisible divider node.\n *\n * @example\n * buildSectionedContent('<p>Body</p>', [\n * { id: 'signature', content: '<p>Alice</p>' },\n * { id: 'forwarded', content: '<p>--- fwd ---</p>' },\n * ])\n */\nexport function buildSectionedContent(\n\tbody: string,\n\tsections: Array<{ id: string; content: string }>,\n): string {\n\tlet html = body;\n\tfor (const s of sections) {\n\t\thtml += SECTION_DIVIDER_HTML(s.id) + s.content;\n\t}\n\treturn html;\n}\n\n// ---------------------------------------------------------------------------\n// Section extraction\n// ---------------------------------------------------------------------------\n\n/**\n * Parse the editor HTML into a Map of sectionId → raw HTML string.\n * The special key `'body'` always holds the content before the first divider.\n * Map iteration order matches document order.\n */\nexport function extractAllSections(editor: Editor): Map<string, string> {\n\treturn extractAllSectionsFromHtml(editor.getHTML());\n}\n\n/**\n * Extract just the body portion (everything before the first section divider)\n * from an HTML string produced by BikEditor. Safe to call on plain HTML too —\n * returns the full string when no dividers are present.\n */\nexport function getBodyHtml(html: string): string {\n\tif (!html) return '';\n\tconst sections = extractAllSectionsFromHtml(html);\n\treturn sections.get('body') ?? html;\n}\n\n/**\n * Extract everything from the first section divider onward (dividers + their\n * content). Returns an empty string when there are no sections.\n */\nexport function getSectionsHtml(html: string): string {\n\tif (!html) return '';\n\tconst body = getBodyHtml(html);\n\treturn html.substring(body.length);\n}\n\nexport function extractAllSectionsFromHtml(html: string): Map<string, string> {\n\tconst sections = new Map<string, string>();\n\tconst dividerRegex =\n\t\t/<div[^>]*data-section-divider=\"([^\"]*)[^>]*>\\s*<\\/div>/g;\n\tconst dividers: Array<{ id: string; index: number; endIndex: number }> = [];\n\n\tlet match: RegExpExecArray | null;\n\twhile ((match = dividerRegex.exec(html)) !== null) {\n\t\tdividers.push({\n\t\t\tid: match[1],\n\t\t\tindex: match.index,\n\t\t\tendIndex: match.index + match[0].length,\n\t\t});\n\t}\n\n\tif (dividers.length === 0) {\n\t\tsections.set('body', html);\n\t\treturn sections;\n\t}\n\n\tsections.set('body', html.slice(0, dividers[0].index));\n\tfor (let i = 0; i < dividers.length; i++) {\n\t\tconst start = dividers[i].endIndex;\n\t\tconst end = i + 1 < dividers.length ? dividers[i + 1].index : html.length;\n\t\tsections.set(dividers[i].id, html.slice(start, end));\n\t}\n\n\treturn sections;\n}\n\n/** Returns BikEditorContent for a single named section (or 'body'). */\nexport function extractSectionContent(\n\teditor: Editor,\n\tid: string,\n): EditorSnapshot {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1)\n\t\treturn { html: '', text: '', isEmpty: true, characterCount: 0 };\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst slice = editor.state.doc.slice(startPos, endPos);\n\tconst container = document.createElement('div');\n\tconst serializer = DOMSerializer.fromSchema(editor.schema);\n\tcontainer.appendChild(serializer.serializeFragment(slice.content));\n\tconst html = toPortableHtml(container.innerHTML);\n\tconst text = container.textContent ?? '';\n\treturn { html, text, isEmpty: !text.trim(), characterCount: text.length };\n}\n\n/**\n * Parse an HTML string into ProseMirror nodes using the editor's schema.\n */\nfunction parseHtmlToNodes(editor: Editor, html: string) {\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = html;\n\treturn DOMParser.fromSchema(editor.schema).parse(container, {\n\t\tpreserveWhitespace: true,\n\t}).content;\n}\n\n/**\n * Replace the content of a single named section without touching others.\n * Uses a ProseMirror transaction to replace only the target range,\n * preserving undo history and other sections' state.\n * If the section doesn't exist yet, it is appended at the end of the document.\n */\nexport function setSectionContentInEditor(\n\teditor: Editor,\n\tid: string,\n\thtml: string,\n): void {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1) {\n\t\tconst endPos = editor.state.doc.content.size;\n\t\tconst dividerHtml = SECTION_DIVIDER_HTML(id) + html;\n\t\teditor.commands.insertContentAt(endPos, dividerHtml, {\n\t\t\tupdateSelection: false,\n\t\t});\n\t\treturn;\n\t}\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst fragment = parseHtmlToNodes(editor, html);\n\tconst { tr } = editor.state;\n\t// For body, replace from position 0 (before the first paragraph's opening\n\t// boundary) so ProseMirror swaps entire block nodes cleanly. Position 1\n\t// (inside the paragraph) would force ProseMirror to close the open paragraph\n\t// first, creating a ghost empty <p></p>.\n\tconst replaceFrom = id === 'body' ? 0 : startPos;\n\ttr.replaceWith(replaceFrom, endPos, fragment);\n\ttr.setMeta('addToHistory', false);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Convenience shorthands (body = first section)\n// ---------------------------------------------------------------------------\n\n/** Extract BikEditorContent for just the body (before the first divider). */\nexport function extractBodyContent(editor: Editor): EditorSnapshot {\n\treturn extractSectionContent(editor, 'body');\n}\n\n// ---------------------------------------------------------------------------\n// Active formats\n// ---------------------------------------------------------------------------\n\nexport function extractActiveFormats(editor: Editor): FormatState {\n\treturn {\n\t\tbold: editor.isActive('bold'),\n\t\titalic: editor.isActive('italic'),\n\t\tunderline: editor.isActive('underline'),\n\t\tstrike: editor.isActive('strike'),\n\t\tbulletList: editor.isActive('bulletList'),\n\t\torderedList: editor.isActive('orderedList'),\n\t\tblockquote: editor.isActive('blockquote'),\n\t\tcodeBlock: editor.isActive('codeBlock'),\n\t\tlink: (() => {\n\t\t\tif (editor.isActive('link')) {\n\t\t\t\treturn { href: editor.getAttributes('link')['href'] ?? '' };\n\t\t\t}\n\t\t\tconst { $from } = editor.state.selection;\n\t\t\tif ($from.pos > 0) {\n\t\t\t\tconst before = $from.doc.resolve($from.pos);\n\t\t\t\tconst linkMark = before.marks().find((m) => m.type.name === 'link');\n\t\t\t\tif (!linkMark) {\n\t\t\t\t\tconst nodeBefore = $from.nodeBefore;\n\t\t\t\t\tconst markOnPrev = nodeBefore?.marks.find(\n\t\t\t\t\t\t(m) => m.type.name === 'link',\n\t\t\t\t\t);\n\t\t\t\t\tif (markOnPrev) {\n\t\t\t\t\t\treturn { href: markOnPrev.attrs['href'] ?? '' };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn { href: linkMark.attrs['href'] ?? '' };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t})(),\n\t\ttextAlign: editor.isActive({ textAlign: 'center' })\n\t\t\t? 'center'\n\t\t\t: editor.isActive({ textAlign: 'right' })\n\t\t\t? 'right'\n\t\t\t: editor.isActive({ textAlign: 'justify' })\n\t\t\t? 'justify'\n\t\t\t: editor.isActive({ textAlign: 'left' })\n\t\t\t? 'left'\n\t\t\t: null,\n\t\tfontFamily: editor.getAttributes('textStyle')['fontFamily'] ?? null,\n\t\tfontSize: editor.getAttributes('textStyle')['fontSize'] ?? null,\n\t\tcolor: editor.getAttributes('textStyle')['color'] ?? null,\n\t\thighlight: editor.isActive('highlight')\n\t\t\t? editor.getAttributes('highlight')['color'] ?? 'default'\n\t\t\t: null,\n\t\tsuperscript: editor.isActive('superscript'),\n\t\tsubscript: editor.isActive('subscript'),\n\t};\n}\n\nexport function extractContent(editor: Editor): EditorSnapshot {\n\tconst html = toPortableHtml(editor.getHTML());\n\tconst normalized = normalizeHardBreaks(editor.state.doc.content);\n\tconst tempDoc = editor.schema.node('doc', null, normalized);\n\t// Paragraph boundary → blank line (\\n\\n), soft line break (hardBreak) → \\n.\n\t// Matches Gmail's plain-text output for the same content.\n\tconst text = tempDoc.textBetween(0, tempDoc.content.size, '\\n\\n', '\\n');\n\treturn {\n\t\thtml,\n\t\ttext,\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount: text.length,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Section position helpers (used by insertAtSectionStart/End and appendBodyContent)\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the ProseMirror position immediately after a section's opening divider\n * (i.e. the start of the section's own content).\n * For `'body'`, returns 1 (beginning of the document).\n * Returns -1 if the named section's divider is not found.\n */\nexport function findSectionStartPos(editor: Editor, sectionId: string): number {\n\tif (sectionId === 'body') return 1;\n\tlet startPos = -1;\n\teditor.state.doc.descendants((node, pos) => {\n\t\tif (startPos !== -1) return false;\n\t\tif (\n\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t) {\n\t\t\tstartPos = pos + node.nodeSize; // position right after the divider\n\t\t}\n\t});\n\treturn startPos;\n}\n\n/**\n * Returns the ProseMirror position at the end of a named section's content:\n * - For `'body'`: position of the first section divider, or end of document.\n * - For a named section: position of the next divider, or end of document.\n */\nexport function findSectionEndPos(editor: Editor, sectionId: string): number {\n\tconst doc = editor.state.doc;\n\tconst docSize = doc.content.size;\n\n\tif (sectionId === 'body') {\n\t\tlet firstDividerPos = -1;\n\t\tdoc.descendants((node, pos) => {\n\t\t\tif (firstDividerPos !== -1) return false;\n\t\t\tif (node.type.name === 'sectionDivider') {\n\t\t\t\tfirstDividerPos = pos;\n\t\t\t}\n\t\t});\n\t\treturn firstDividerPos !== -1 ? firstDividerPos : docSize;\n\t}\n\n\tlet passedSection = false;\n\tlet nextDividerPos = -1;\n\tdoc.descendants((node, pos) => {\n\t\tif (nextDividerPos !== -1) return false;\n\t\tif (!passedSection) {\n\t\t\tif (\n\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t) {\n\t\t\t\tpassedSection = true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (node.type.name === 'sectionDivider') {\n\t\t\tnextDividerPos = pos;\n\t\t}\n\t});\n\treturn nextDividerPos !== -1 ? nextDividerPos : docSize;\n}\n"],"names":["normalizeHtml","html","container","span","dataType","parent","p","toPortableHtml","div","walker","textNode","blocks","insertInlineHtml","editor","normalised","dom","slice","DOMParser","from","to","tr","SECTION_DIVIDER_HTML","id","buildSectionedContent","body","sections","s","getBodyHtml","extractAllSectionsFromHtml","getSectionsHtml","dividerRegex","dividers","match","i","start","end","extractSectionContent","startPos","findSectionStartPos","endPos","findSectionEndPos","serializer","DOMSerializer","text","parseHtmlToNodes","setSectionContentInEditor","dividerHtml","fragment","replaceFrom","extractBodyContent","extractActiveFormats","$from","linkMark","m","markOnPrev","extractContent","normalized","normalizeHardBreaks","tempDoc","sectionId","node","pos","doc","docSize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;AAAA,IACA,MAAA0C;AAAA,IACA,SAAS9B,EAAO;AAAA,IAChB,gBAAgB8B,EAAK;AAAA,EAAA;AAEvB;AAYO,SAASL,EAAoBzB,GAAgB8C,GAA2B;AAC9E,MAAIA,MAAc,OAAQ,QAAO;AACjC,MAAItB,IAAW;AACf,SAAAxB,EAAO,MAAM,IAAI,YAAY,CAAC+C,GAAMC,MAAQ;AAC3C,QAAIxB,MAAa,GAAI,QAAO;AAC5B,IACCuB,EAAK,KAAK,SAAS,oBACnBA,EAAK,MAAM,cAAiBD,MAE5BtB,IAAWwB,IAAMD,EAAK;AAAA,EAExB,CAAC,GACMvB;AACR;AAOO,SAASG,EAAkB3B,GAAgB8C,GAA2B;AAC5E,QAAMG,IAAMjD,EAAO,MAAM,KACnBkD,IAAUD,EAAI,QAAQ;AAE5B,MAAIH,MAAc,QAAQ;AACzB,QAAIK,IAAkB;AACtB,WAAAF,EAAI,YAAY,CAACF,GAAMC,MAAQ;AAC9B,UAAIG,MAAoB,GAAI,QAAO;AACnC,MAAIJ,EAAK,KAAK,SAAS,qBACtBI,IAAkBH;AAAA,IAEpB,CAAC,GACMG,MAAoB,KAAKA,IAAkBD;AAAA,EACnD;AAEA,MAAIE,IAAgB,IAChBC,IAAiB;AACrB,SAAAJ,EAAI,YAAY,CAACF,GAAMC,MAAQ;AAC9B,QAAIK,MAAmB,GAAI,QAAO;AAClC,QAAI,CAACD;AACJ,aACCL,EAAK,KAAK,SAAS,oBACnBA,EAAK,MAAM,cAAiBD,MAE5BM,IAAgB,KAEV;AAER,IAAIL,EAAK,KAAK,SAAS,qBACtBM,IAAiBL;AAAA,EAEnB,CAAC,GACMK,MAAmB,KAAKA,IAAiBH;AACjD;"}
1
+ {"version":3,"file":"BikEditor.utils.js","sources":["../../../src/editor/BikEditor.utils.ts"],"sourcesContent":["import { Editor } from '@tiptap/core';\nimport { DOMParser, DOMSerializer } from 'prosemirror-model';\nimport {\n\tEditorSnapshot,\n\tFormatState,\n\tJsonParseResult,\n} from './BikEditor.types';\nimport { normalizeHardBreaks } from './extensions/plainClipboard/pasteUtils';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * 1. Unwrap style-less `<span>` wrappers (plain spans, and editor-cursor spans\n * like Quill's `<span class=\"ql-cursor\">`). Spans that carry inline styling\n * (`color` / `font-family` / `font-size` render as styled spans) or that\n * represent a `{{variable}}` token are PRESERVED — otherwise a setContent\n * round-trip would silently drop colour/font formatting that paste keeps.\n * 2. Collapse placeholder paragraphs (`<p><br></p>`) to `<p></p>`. ProseMirror\n * parses `<p></p>` as an empty paragraph and adds its own DOM `<br>` for the\n * cursor — one blank line, correct height. Leaving the source `<br>` would\n * create a `hard_break` child AND the cursor `<br>` → double-height blank line.\n *\n * Uses the DOM (regex cannot selectively pair span tags). `normalizeHtml` runs\n * in the component body for `initialContent`, so it is guarded for SSR: the\n * editor is created lazily on the client (`immediatelyRender: false`), meaning\n * the value is only parsed client-side and passing through on the server is safe.\n */\nexport function normalizeHtml(html: string): string {\n\tif (!html || typeof document === 'undefined') return html;\n\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = html;\n\n\tcontainer.querySelectorAll('span').forEach((span) => {\n\t\t// Keep schema-backed spans: styled spans, variables, and mention chips\n\t\t// (`data-type=\"mention…\"`). Stripping a mention span would drop the\n\t\t// `data-id`/`data-label`/`data-kind` the editor needs to reparse it.\n\t\tconst dataType = span.getAttribute('data-type');\n\t\tif (\n\t\t\tspan.hasAttribute('style') ||\n\t\t\tspan.hasAttribute('data-variable') ||\n\t\t\t(dataType !== null && dataType.startsWith('mention'))\n\t\t)\n\t\t\treturn;\n\t\tconst parent = span.parentNode;\n\t\tif (!parent) return;\n\t\twhile (span.firstChild) parent.insertBefore(span.firstChild, span);\n\t\tparent.removeChild(span);\n\t});\n\n\tcontainer.querySelectorAll('p').forEach((p) => {\n\t\tif (\n\t\t\tp.querySelectorAll('br').length === 1 &&\n\t\t\t(p.textContent ?? '').trim() === ''\n\t\t) {\n\t\t\tp.innerHTML = '';\n\t\t}\n\t});\n\n\treturn container.innerHTML;\n}\n\n/**\n * Make editor HTML portable across email clients and chat renderers.\n *\n * 1. Preserve consecutive spaces by converting every second space in a run\n * to `&nbsp;` (U+00A0). Standard HTML collapses adjacent regular spaces;\n * alternating with `&nbsp;` prevents that — same convention Gmail uses.\n * 2. Double a trailing `<br>` in content paragraphs so the blank line is\n * visible. A single trailing `<br>` before `</p>` is swallowed by most\n * email clients; `<br><br>` renders as a visible blank line (matches\n * Gmail's output).\n * 3. Convert empty `<p></p>` to `<p><br></p>` — email clients collapse\n * zero-height paragraphs without a `<br>`.\n */\nexport function toPortableHtml(html: string): string {\n\tconst div = document.createElement('div');\n\tdiv.innerHTML = html;\n\n\t// TreeWalker visits only text nodes, skipping HTML tags/attributes, so we safely\n\t// replace consecutive spaces with space + \\u00a0 (nbsp) to prevent email clients from collapsing them\n\tconst walker = document.createTreeWalker(div, NodeFilter.SHOW_TEXT);\n\tlet textNode: Text | null;\n\twhile ((textNode = walker.nextNode() as Text | null)) {\n\t\tif (textNode.nodeValue && textNode.nodeValue.includes(' ')) {\n\t\t\ttextNode.nodeValue = textNode.nodeValue.replace(/ {2}/g, '  ');\n\t\t}\n\t}\n\n\tconst blocks = div.querySelectorAll('p');\n\tfor (const p of Array.from(blocks)) {\n\t\tif (p.childNodes.length === 0) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t\tcontinue;\n\t\t}\n\t\tconst last = p.lastChild;\n\t\tif (last instanceof HTMLBRElement && p.childNodes.length > 1) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t}\n\t}\n\treturn div.innerHTML;\n}\n\n// ---------------------------------------------------------------------------\n// Inline content insertion\n// ---------------------------------------------------------------------------\n\n/**\n * Insert HTML at the current cursor position, merging the first paragraph\n * inline while preserving the block structure of subsequent paragraphs/lists.\n *\n * Uses `parseSlice` which returns an open-ended Slice — the first block merges\n * at the cursor, middle blocks stay intact, and the last block merges with any\n * text that follows the cursor.\n */\nexport function insertInlineHtml(editor: Editor, html: string): void {\n\tconst normalised = normalizeHtml(html);\n\tconst dom = document.createElement('div');\n\tdom.innerHTML = normalised;\n\tconst slice = DOMParser.fromSchema(editor.schema).parseSlice(dom, {\n\t\tpreserveWhitespace: true,\n\t});\n\n\tif (slice.size === 0) return;\n\n\tconst { from, to } = editor.state.selection;\n\tconst tr = editor.state.tr.replaceRange(from, to, slice);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Section divider HTML\n// ---------------------------------------------------------------------------\n\nexport const SECTION_DIVIDER_HTML = (id: string) =>\n\t`<div data-section-divider=\"${id}\" style=\"display:none;height:0;line-height:0;overflow:hidden;\"></div>`;\n\n/**\n * Build initial HTML for an editor with one or more named sections below the body.\n * Each section is separated by an invisible divider node.\n *\n * @example\n * buildSectionedContent('<p>Body</p>', [\n * { id: 'signature', content: '<p>Alice</p>' },\n * { id: 'forwarded', content: '<p>--- fwd ---</p>' },\n * ])\n */\nexport function buildSectionedContent(\n\tbody: string,\n\tsections: Array<{ id: string; content: string }>,\n): string {\n\tlet html = body;\n\tfor (const s of sections) {\n\t\thtml += SECTION_DIVIDER_HTML(s.id) + s.content;\n\t}\n\treturn html;\n}\n\n// ---------------------------------------------------------------------------\n// Section extraction\n// ---------------------------------------------------------------------------\n\n/**\n * Parse the editor HTML into a Map of sectionId → raw HTML string.\n * The special key `'body'` always holds the content before the first divider.\n * Map iteration order matches document order.\n */\nexport function extractAllSections(editor: Editor): Map<string, string> {\n\treturn extractAllSectionsFromHtml(editor.getHTML());\n}\n\n/**\n * Extract just the body portion (everything before the first section divider)\n * from an HTML string produced by BikEditor. Safe to call on plain HTML too —\n * returns the full string when no dividers are present.\n */\nexport function getBodyHtml(html: string): string {\n\tif (!html) return '';\n\tconst sections = extractAllSectionsFromHtml(html);\n\treturn sections.get('body') ?? html;\n}\n\n/**\n * Extract everything from the first section divider onward (dividers + their\n * content). Returns an empty string when there are no sections.\n */\nexport function getSectionsHtml(html: string): string {\n\tif (!html) return '';\n\tconst body = getBodyHtml(html);\n\treturn html.substring(body.length);\n}\n\nexport function extractAllSectionsFromHtml(html: string): Map<string, string> {\n\tconst sections = new Map<string, string>();\n\tconst dividerRegex =\n\t\t/<div[^>]*data-section-divider=\"([^\"]*)[^>]*>\\s*<\\/div>/g;\n\tconst dividers: Array<{ id: string; index: number; endIndex: number }> = [];\n\n\tlet match: RegExpExecArray | null;\n\twhile ((match = dividerRegex.exec(html)) !== null) {\n\t\tdividers.push({\n\t\t\tid: match[1],\n\t\t\tindex: match.index,\n\t\t\tendIndex: match.index + match[0].length,\n\t\t});\n\t}\n\n\tif (dividers.length === 0) {\n\t\tsections.set('body', html);\n\t\treturn sections;\n\t}\n\n\tsections.set('body', html.slice(0, dividers[0].index));\n\tfor (let i = 0; i < dividers.length; i++) {\n\t\tconst start = dividers[i].endIndex;\n\t\tconst end = i + 1 < dividers.length ? dividers[i + 1].index : html.length;\n\t\tsections.set(dividers[i].id, html.slice(start, end));\n\t}\n\n\treturn sections;\n}\n\n/** Returns BikEditorContent for a single named section (or 'body'). */\nexport function extractSectionContent(\n\teditor: Editor,\n\tid: string,\n): EditorSnapshot {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1)\n\t\treturn { html: '', text: '', isEmpty: true, characterCount: 0 };\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst slice = editor.state.doc.slice(startPos, endPos);\n\tconst container = document.createElement('div');\n\tconst serializer = DOMSerializer.fromSchema(editor.schema);\n\tcontainer.appendChild(serializer.serializeFragment(slice.content));\n\tconst html = toPortableHtml(container.innerHTML);\n\tconst text = container.textContent ?? '';\n\treturn { html, text, isEmpty: !text.trim(), characterCount: text.length };\n}\n\n/**\n * Parse an HTML string into ProseMirror nodes using the editor's schema.\n */\nfunction parseHtmlToNodes(editor: Editor, html: string) {\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = html;\n\treturn DOMParser.fromSchema(editor.schema).parse(container, {\n\t\tpreserveWhitespace: true,\n\t}).content;\n}\n\n/**\n * Replace the content of a single named section without touching others.\n * Uses a ProseMirror transaction to replace only the target range,\n * preserving undo history and other sections' state.\n * If the section doesn't exist yet, it is appended at the end of the document.\n */\nexport function setSectionContentInEditor(\n\teditor: Editor,\n\tid: string,\n\thtml: string,\n): void {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1) {\n\t\tconst endPos = editor.state.doc.content.size;\n\t\tconst dividerHtml = SECTION_DIVIDER_HTML(id) + html;\n\t\teditor.commands.insertContentAt(endPos, dividerHtml, {\n\t\t\tupdateSelection: false,\n\t\t});\n\t\treturn;\n\t}\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst fragment = parseHtmlToNodes(editor, html);\n\tconst { tr } = editor.state;\n\t// For body, replace from position 0 (before the first paragraph's opening\n\t// boundary) so ProseMirror swaps entire block nodes cleanly. Position 1\n\t// (inside the paragraph) would force ProseMirror to close the open paragraph\n\t// first, creating a ghost empty <p></p>.\n\tconst replaceFrom = id === 'body' ? 0 : startPos;\n\ttr.replaceWith(replaceFrom, endPos, fragment);\n\ttr.setMeta('addToHistory', false);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Convenience shorthands (body = first section)\n// ---------------------------------------------------------------------------\n\n/** Extract BikEditorContent for just the body (before the first divider). */\nexport function extractBodyContent(editor: Editor): EditorSnapshot {\n\treturn extractSectionContent(editor, 'body');\n}\n\n// ---------------------------------------------------------------------------\n// Active formats\n// ---------------------------------------------------------------------------\n\nexport function extractActiveFormats(editor: Editor): FormatState {\n\treturn {\n\t\tbold: editor.isActive('bold'),\n\t\titalic: editor.isActive('italic'),\n\t\tunderline: editor.isActive('underline'),\n\t\tstrike: editor.isActive('strike'),\n\t\tbulletList: editor.isActive('bulletList'),\n\t\torderedList: editor.isActive('orderedList'),\n\t\tblockquote: editor.isActive('blockquote'),\n\t\tcodeBlock: editor.isActive('codeBlock'),\n\t\tlink: (() => {\n\t\t\tif (editor.isActive('link')) {\n\t\t\t\treturn { href: editor.getAttributes('link')['href'] ?? '' };\n\t\t\t}\n\t\t\tconst { $from } = editor.state.selection;\n\t\t\tif ($from.pos > 0) {\n\t\t\t\tconst before = $from.doc.resolve($from.pos);\n\t\t\t\tconst linkMark = before.marks().find((m) => m.type.name === 'link');\n\t\t\t\tif (!linkMark) {\n\t\t\t\t\tconst nodeBefore = $from.nodeBefore;\n\t\t\t\t\tconst markOnPrev = nodeBefore?.marks.find(\n\t\t\t\t\t\t(m) => m.type.name === 'link',\n\t\t\t\t\t);\n\t\t\t\t\tif (markOnPrev) {\n\t\t\t\t\t\treturn { href: markOnPrev.attrs['href'] ?? '' };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn { href: linkMark.attrs['href'] ?? '' };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t})(),\n\t\ttextAlign: editor.isActive({ textAlign: 'center' })\n\t\t\t? 'center'\n\t\t\t: editor.isActive({ textAlign: 'right' })\n\t\t\t? 'right'\n\t\t\t: editor.isActive({ textAlign: 'justify' })\n\t\t\t? 'justify'\n\t\t\t: editor.isActive({ textAlign: 'left' })\n\t\t\t? 'left'\n\t\t\t: null,\n\t\tfontFamily: editor.getAttributes('textStyle')['fontFamily'] ?? null,\n\t\tfontSize: editor.getAttributes('textStyle')['fontSize'] ?? null,\n\t\tcolor: editor.getAttributes('textStyle')['color'] ?? null,\n\t\thighlight: editor.isActive('highlight')\n\t\t\t? editor.getAttributes('highlight')['color'] ?? 'default'\n\t\t\t: null,\n\t\tsuperscript: editor.isActive('superscript'),\n\t\tsubscript: editor.isActive('subscript'),\n\t};\n}\n\nexport function extractContent(editor: Editor): EditorSnapshot {\n\tconst html = toPortableHtml(editor.getHTML());\n\tconst normalized = normalizeHardBreaks(editor.state.doc.content);\n\tconst tempDoc = editor.schema.node('doc', null, normalized);\n\t// Paragraph boundary → blank line (\\n\\n), soft line break (hardBreak) → \\n.\n\t// Matches Gmail's plain-text output for the same content.\n\tconst text = tempDoc.textBetween(0, tempDoc.content.size, '\\n\\n', '\\n');\n\treturn {\n\t\thtml,\n\t\ttext,\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount: text.length,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Section position helpers (used by insertAtSectionStart/End and appendBodyContent)\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the ProseMirror position immediately after a section's opening divider\n * (i.e. the start of the section's own content).\n * For `'body'`, returns 1 (beginning of the document).\n * Returns -1 if the named section's divider is not found.\n */\nexport function findSectionStartPos(editor: Editor, sectionId: string): number {\n\tif (sectionId === 'body') return 1;\n\tlet startPos = -1;\n\teditor.state.doc.descendants((node, pos) => {\n\t\tif (startPos !== -1) return false;\n\t\tif (\n\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t) {\n\t\t\tstartPos = pos + node.nodeSize; // position right after the divider\n\t\t}\n\t});\n\treturn startPos;\n}\n\n/**\n * Returns the ProseMirror position at the end of a named section's content:\n * - For `'body'`: position of the first section divider, or end of document.\n * - For a named section: position of the next divider, or end of document.\n */\nexport function findSectionEndPos(editor: Editor, sectionId: string): number {\n\tconst doc = editor.state.doc;\n\tconst docSize = doc.content.size;\n\n\tif (sectionId === 'body') {\n\t\tlet firstDividerPos = -1;\n\t\tdoc.descendants((node, pos) => {\n\t\t\tif (firstDividerPos !== -1) return false;\n\t\t\tif (node.type.name === 'sectionDivider') {\n\t\t\t\tfirstDividerPos = pos;\n\t\t\t}\n\t\t});\n\t\treturn firstDividerPos !== -1 ? firstDividerPos : docSize;\n\t}\n\n\tlet passedSection = false;\n\tlet nextDividerPos = -1;\n\tdoc.descendants((node, pos) => {\n\t\tif (nextDividerPos !== -1) return false;\n\t\tif (!passedSection) {\n\t\t\tif (\n\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t) {\n\t\t\t\tpassedSection = true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (node.type.name === 'sectionDivider') {\n\t\t\tnextDividerPos = pos;\n\t\t}\n\t});\n\treturn nextDividerPos !== -1 ? nextDividerPos : docSize;\n}\n\n// ---------------------------------------------------------------------------\n// JSON body helpers (used when features.jsonMode is on — the whole document is\n// a single code block whose text is raw JSON, Postman-style)\n// ---------------------------------------------------------------------------\n\nfunction escapeHtml(raw: string): string {\n\treturn raw.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n}\n\n/**\n * Wrap a raw JSON string in a `<pre><code>` code block so TipTap parses it as a\n * single code-block node (the container for JSON body mode).\n */\nexport function buildJsonCodeBlockHtml(raw: string): string {\n\treturn `<pre><code>${escapeHtml(raw ?? '')}</code></pre>`;\n}\n\n/** Returns the raw text of the first code block in the document (empty if none). */\nexport function getCodeBlockText(editor: Editor): string {\n\tlet text = '';\n\tlet found = false;\n\teditor.state.doc.descendants((node) => {\n\t\tif (found) return false;\n\t\tif (node.type.name === 'codeBlock') {\n\t\t\ttext = node.textContent;\n\t\t\tfound = true;\n\t\t\treturn false;\n\t\t}\n\t\treturn undefined;\n\t});\n\treturn text;\n}\n\n/**\n * Replace the text of the first code block with `raw`, keeping it a code block.\n * Falls back to replacing the whole document when no code block exists yet.\n */\nexport function setCodeBlockText(editor: Editor, raw: string): void {\n\teditor.commands.setContent(buildJsonCodeBlockHtml(raw), { emitUpdate: true });\n}\n\n/** 1-based line/column of a 0-based character offset within `text`. */\nfunction offsetToLineCol(\n\ttext: string,\n\toffset: number,\n): { line: number; column: number } {\n\tconst before = text.slice(0, Math.max(0, offset));\n\tconst lines = before.split('\\n');\n\treturn {\n\t\tline: lines.length,\n\t\tcolumn: (lines[lines.length - 1]?.length ?? 0) + 1,\n\t};\n}\n\n/**\n * Turn a raw `JSON.parse` error into a clean message + location. Engine messages\n * look like `\"Bad control character in string literal in JSON at position 94\n * (line 7 column 9)\"` — we strip the `\"in JSON at position …\"` tail for the\n * message and pull the line/column from it (falling back to computing them from\n * the position offset when the engine omits them).\n */\nfunction describeJsonError(\n\trawMessage: string,\n\ttext: string,\n): { message: string; line: number | null; column: number | null } {\n\tconst message =\n\t\trawMessage.replace(/\\s*in JSON at position[\\s\\S]*$/i, '').trim() ||\n\t\trawMessage;\n\n\tconst lineCol = rawMessage.match(/line (\\d+) column (\\d+)/i);\n\tif (lineCol) {\n\t\treturn {\n\t\t\tmessage,\n\t\t\tline: Number(lineCol[1]),\n\t\t\tcolumn: Number(lineCol[2]),\n\t\t};\n\t}\n\n\tconst posMatch = rawMessage.match(/position (\\d+)/i);\n\tif (posMatch) {\n\t\tconst { line, column } = offsetToLineCol(text, Number(posMatch[1]));\n\t\treturn { message, line, column };\n\t}\n\n\treturn { message, line: null, column: null };\n}\n\n/** Parse a JSON string without throwing. Empty / whitespace-only text is valid. */\nexport function parseJson(text: string): JsonParseResult {\n\tif (!text.trim()) {\n\t\treturn { valid: true, value: null, error: null, line: null, column: null };\n\t}\n\ttry {\n\t\treturn {\n\t\t\tvalid: true,\n\t\t\tvalue: JSON.parse(text),\n\t\t\terror: null,\n\t\t\tline: null,\n\t\t\tcolumn: null,\n\t\t};\n\t} catch (e) {\n\t\tconst { message, line, column } = describeJsonError(\n\t\t\t(e as Error).message,\n\t\t\ttext,\n\t\t);\n\t\treturn { valid: false, value: null, error: message, line, column };\n\t}\n}\n"],"names":["normalizeHtml","html","container","span","dataType","parent","p","toPortableHtml","div","walker","textNode","blocks","insertInlineHtml","editor","normalised","dom","slice","DOMParser","from","to","tr","SECTION_DIVIDER_HTML","id","buildSectionedContent","body","sections","s","getBodyHtml","extractAllSectionsFromHtml","getSectionsHtml","dividerRegex","dividers","match","i","start","end","extractSectionContent","startPos","findSectionStartPos","endPos","findSectionEndPos","serializer","DOMSerializer","text","parseHtmlToNodes","setSectionContentInEditor","dividerHtml","fragment","replaceFrom","extractBodyContent","extractActiveFormats","$from","linkMark","m","markOnPrev","extractContent","normalized","normalizeHardBreaks","tempDoc","sectionId","node","pos","doc","docSize","firstDividerPos","passedSection","nextDividerPos","escapeHtml","raw","buildJsonCodeBlockHtml","getCodeBlockText","found","setCodeBlockText","offsetToLineCol","offset","lines","describeJsonError","rawMessage","message","lineCol","posMatch","line","column","parseJson","e"],"mappings":";;AA+BO,SAASA,EAAcC,GAAsB;AACnD,MAAI,CAACA,KAAQ,OAAO,WAAa,IAAa,QAAOA;AAErD,QAAMC,IAAY,SAAS,cAAc,KAAK;AAC9C,SAAAA,EAAU,YAAYD,GAEtBC,EAAU,iBAAiB,MAAM,EAAE,QAAQ,CAACC,MAAS;AAIpD,UAAMC,IAAWD,EAAK,aAAa,WAAW;AAC9C,QACCA,EAAK,aAAa,OAAO,KACzBA,EAAK,aAAa,eAAe,KAChCC,MAAa,QAAQA,EAAS,WAAW,SAAS;AAEnD;AACD,UAAMC,IAASF,EAAK;AACpB,QAAKE,GACL;AAAA,aAAOF,EAAK,aAAY,CAAAE,EAAO,aAAaF,EAAK,YAAYA,CAAI;AACjE,MAAAE,EAAO,YAAYF,CAAI;AAAA;AAAA,EACxB,CAAC,GAEDD,EAAU,iBAAiB,GAAG,EAAE,QAAQ,CAACI,MAAM;AAC9C,IACCA,EAAE,iBAAiB,IAAI,EAAE,WAAW,MACnCA,EAAE,eAAe,IAAI,KAAA,MAAW,OAEjCA,EAAE,YAAY;AAAA,EAEhB,CAAC,GAEMJ,EAAU;AAClB;AAeO,SAASK,EAAeN,GAAsB;AACpD,QAAMO,IAAM,SAAS,cAAc,KAAK;AACxC,EAAAA,EAAI,YAAYP;AAIhB,QAAMQ,IAAS,SAAS,iBAAiBD,GAAK,WAAW,SAAS;AAClE,MAAIE;AACJ,SAAQA,IAAWD,EAAO;AACzB,IAAIC,EAAS,aAAaA,EAAS,UAAU,SAAS,IAAI,MACzDA,EAAS,YAAYA,EAAS,UAAU,QAAQ,SAAS,IAAI;AAI/D,QAAMC,IAASH,EAAI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AOqC,EAAS,CAAC,CAAC,CAAC;AAClE,WAAO,EAAE,SAAAF,GAAS,MAAAG,GAAM,QAAAC,EAAA;AAAA,EACzB;AAEA,SAAO,EAAE,SAAAJ,GAAS,MAAM,MAAM,QAAQ,KAAA;AACvC;AAGO,SAASK,EAAUxC,GAA+B;AACxD,MAAI,CAACA,EAAK;AACT,WAAO,EAAE,OAAO,IAAM,OAAO,MAAM,OAAO,MAAM,MAAM,MAAM,QAAQ,KAAA;AAErE,MAAI;AACH,WAAO;AAAA,MACN,OAAO;AAAA,MACP,OAAO,KAAK,MAAMA,CAAI;AAAA,MACtB,OAAO;AAAA,MACP,MAAM;AAAA,MACN,QAAQ;AAAA,IAAA;AAAA,EAEV,SAASyC,GAAG;AACX,UAAM,EAAE,SAAAN,GAAS,MAAAG,GAAM,QAAAC,EAAA,IAAWN;AAAA,MAChCQ,EAAY;AAAA,MACbzC;AAAA,IAAA;AAED,WAAO,EAAE,OAAO,IAAO,OAAO,MAAM,OAAOmC,GAAS,MAAAG,GAAM,QAAAC,EAAA;AAAA,EAC3D;AACD;"}
@@ -34,5 +34,5 @@ interface ExtensionConfig {
34
34
  renderSlashCommandItem?: (item: SlashCommandItem, isActive: boolean) => ReactNode;
35
35
  renderSlashCommandDropdown?: (props: SlashCommandDropdownRenderProps) => ReactNode;
36
36
  }
37
- export declare function buildExtensions(config: ExtensionConfig): (import('@tiptap/core').Node<any, any> | import('@tiptap/core').Extension<any, any> | import('@tiptap/core').Node<import('@tiptap/extension-mention').MentionOptions<any, import('@tiptap/extension-mention').MentionNodeAttrs>, any> | import('@tiptap/core').Node<import('@tiptap/extension-hard-break').HardBreakOptions, any> | import('@tiptap/core').Node<import('@tiptap/extension-paragraph').ParagraphOptions, any> | import('@tiptap/core').Extension<import('@tiptap/starter-kit').StarterKitOptions, any> | import('@tiptap/core').Mark<import('@tiptap/extension-underline').UnderlineOptions, any> | import('@tiptap/core').Mark<import('@tiptap/extension-link').LinkOptions, any> | import('@tiptap/core').Mark<import('@tiptap/extension-text-style').TextStyleOptions, any> | import('@tiptap/core').Extension<import('@tiptap/extensions').PlaceholderOptions, any> | import('@tiptap/core').Extension<import('@tiptap/extensions').CharacterCountOptions, import('@tiptap/extensions').CharacterCountStorage> | import('@tiptap/core').Extension<import('@tiptap/extension-text-style').ColorOptions, any> | import('@tiptap/core').Mark<import('@tiptap/extension-highlight').HighlightOptions, any> | import('@tiptap/core').Extension<import('@tiptap/extension-text-align').TextAlignOptions, any> | import('@tiptap/core').Node<import('@tiptap/extension-image').ImageOptions, any>)[];
37
+ export declare function buildExtensions(config: ExtensionConfig): (import('@tiptap/core').Node<any, any> | import('@tiptap/core').Extension<any, any> | import('@tiptap/core').Node<import('@tiptap/extension-mention').MentionOptions<any, import('@tiptap/extension-mention').MentionNodeAttrs>, any> | import('@tiptap/core').Extension<import('@tiptap/starter-kit').StarterKitOptions, any> | import('@tiptap/core').Extension<import('@tiptap/extensions').PlaceholderOptions, any> | import('@tiptap/core').Extension<import('@tiptap/extensions').CharacterCountOptions, import('@tiptap/extensions').CharacterCountStorage> | import('@tiptap/core').Node<import('@tiptap/extension-paragraph').ParagraphOptions, any> | import('@tiptap/core').Node<import('@tiptap/extension-hard-break').HardBreakOptions, any> | import('@tiptap/core').Mark<import('@tiptap/extension-underline').UnderlineOptions, any> | import('@tiptap/core').Mark<import('@tiptap/extension-link').LinkOptions, any> | import('@tiptap/core').Mark<import('@tiptap/extension-text-style').TextStyleOptions, any> | import('@tiptap/core').Extension<import('@tiptap/extension-text-style').ColorOptions, any> | import('@tiptap/core').Mark<import('@tiptap/extension-highlight').HighlightOptions, any> | import('@tiptap/core').Extension<import('@tiptap/extension-text-align').TextAlignOptions, any> | import('@tiptap/core').Node<import('@tiptap/extension-image').ImageOptions, any>)[];
38
38
  export {};
@@ -1,49 +1,80 @@
1
- import h from "@tiptap/extension-character-count";
2
- import s from "@tiptap/extension-color";
3
- import f from "@tiptap/extension-font-family";
4
- import c from "@tiptap/extension-hard-break";
5
- import x from "@tiptap/extension-highlight";
6
- import S from "@tiptap/extension-image";
7
- import M from "@tiptap/extension-link";
8
- import k from "../../node_modules/@tiptap/extension-paragraph/dist/index.js";
9
- import b from "@tiptap/extension-placeholder";
10
- import y from "@tiptap/extension-subscript";
11
- import C from "@tiptap/extension-superscript";
12
- import E from "@tiptap/extension-text-align";
13
- import { TextStyle as T } from "@tiptap/extension-text-style";
14
- import P from "@tiptap/extension-underline";
15
- import D from "@tiptap/starter-kit";
16
- import { FontSizeExtension as g } from "./FontSizeExtension.js";
17
- import { buildAgentMentionExtension as H, buildTeamMentionExtension as w } from "./mention/MentionExtension.js";
18
- import { PasteExtension as B } from "./paste/PasteExtension.js";
19
- import { PasteNormalizationExtension as I } from "./plainClipboard/PasteNormalizationExtension.js";
20
- import { SectionDividerNode as L } from "./sectionDivider/SectionDividerNode.js";
21
- import { SendShortcutExtension as O } from "./sendShortcut/SendShortcutExtension.js";
1
+ import a from "@tiptap/extension-character-count";
2
+ import i from "@tiptap/extension-color";
3
+ import S from "@tiptap/extension-font-family";
4
+ import k from "@tiptap/extension-hard-break";
5
+ import M from "@tiptap/extension-highlight";
6
+ import b from "@tiptap/extension-image";
7
+ import C from "@tiptap/extension-link";
8
+ import y from "../../node_modules/@tiptap/extension-paragraph/dist/index.js";
9
+ import l from "@tiptap/extension-placeholder";
10
+ import E from "@tiptap/extension-subscript";
11
+ import T from "@tiptap/extension-superscript";
12
+ import P from "@tiptap/extension-text-align";
13
+ import { TextStyle as D } from "@tiptap/extension-text-style";
14
+ import H from "@tiptap/extension-underline";
15
+ import m from "@tiptap/starter-kit";
16
+ import { FontSizeExtension as L } from "./FontSizeExtension.js";
17
+ import { JsonHighlightExtension as g } from "./jsonHighlight/JsonHighlightExtension.js";
18
+ import { buildAgentMentionExtension as w, buildTeamMentionExtension as B } from "./mention/MentionExtension.js";
19
+ import { PasteExtension as I } from "./paste/PasteExtension.js";
20
+ import { PasteNormalizationExtension as O } from "./plainClipboard/PasteNormalizationExtension.js";
21
+ import { SectionDividerNode as R } from "./sectionDivider/SectionDividerNode.js";
22
+ import { SendShortcutExtension as d } from "./sendShortcut/SendShortcutExtension.js";
22
23
  import { buildSlashCommandExtension as A } from "./slashCommand/SlashCommandExtension.js";
23
- import { VariableDecorationExtension as R } from "./variable/VariableDecorationExtension.js";
24
- function ae(e) {
25
- const o = e.features?.richPaste ?? !1, i = e.features?.richTypography ?? !1, n = e.features?.allowedMarks, t = (r) => !n || n.includes(r), m = c.extend({
24
+ import { VariableDecorationExtension as z } from "./variable/VariableDecorationExtension.js";
25
+ function ie(e) {
26
+ if (e.features?.jsonMode)
27
+ return [
28
+ m.configure({
29
+ link: !1,
30
+ underline: !1,
31
+ // Keep codeBlock (the JSON container) and history; drop everything
32
+ // that has no meaning inside raw JSON.
33
+ bold: !1,
34
+ italic: !1,
35
+ strike: !1,
36
+ code: !1,
37
+ heading: !1,
38
+ bulletList: !1,
39
+ orderedList: !1,
40
+ blockquote: !1,
41
+ horizontalRule: !1
42
+ }),
43
+ l.configure({
44
+ placeholder: e.placeholder ?? `{
45
+
46
+ }`
47
+ }),
48
+ g,
49
+ d.configure({
50
+ onSend: e.onSend,
51
+ sendShortcut: e.sendShortcut,
52
+ extraShortcuts: e.shortcuts ?? []
53
+ }),
54
+ ...e.maxCharacters ? [a.configure({ limit: e.maxCharacters })] : []
55
+ ];
56
+ const o = e.features?.richPaste ?? !1, u = e.features?.richTypography ?? !1, n = e.features?.allowedMarks, t = (r) => !n || n.includes(r), p = k.extend({
26
57
  addKeyboardShortcuts() {
27
58
  return {
28
59
  "Shift-Enter": () => this.editor.commands.setHardBreak()
29
60
  };
30
61
  }
31
- }), a = (r) => r === "0" || r === "0px" || r === "0pt" || r === "0em", l = k.extend({
62
+ }), s = (r) => r === "0" || r === "0px" || r === "0pt" || r === "0em", h = y.extend({
32
63
  addAttributes() {
33
64
  return {
34
65
  ...this.parent?.() ?? {},
35
66
  margin: {
36
67
  default: null,
37
- parseHTML: (r) => a(r.style.marginTop) && a(r.style.marginBottom) ? "0" : null,
68
+ parseHTML: (r) => s(r.style.marginTop) && s(r.style.marginBottom) ? "0" : null,
38
69
  renderHTML: (r) => r.margin === "0" ? { style: "margin: 0px" } : {}
39
70
  }
40
71
  };
41
72
  }
42
- }), d = [
73
+ }), f = [
43
74
  // Exclude Link and Underline from StarterKit — TipTap v3 bundles both.
44
75
  // Without this, two copies of each are registered and the StarterKit copy's
45
76
  // click handler calls window.open even when openOnClick: false is set.
46
- D.configure({
77
+ m.configure({
47
78
  link: !1,
48
79
  underline: !1,
49
80
  hardBreak: !1,
@@ -53,12 +84,12 @@ function ae(e) {
53
84
  strike: t("strike") ? {} : !1,
54
85
  code: t("code") ? {} : !1
55
86
  }),
56
- l,
57
- m,
58
- ...t("underline") ? [P] : [],
87
+ h,
88
+ p,
89
+ ...t("underline") ? [H] : [],
59
90
  // Extend Link to strip addPasteRules() and addInputRules() so pasting a
60
91
  // URL never creates a hyperlink regardless of autolink/linkOnPaste values.
61
- M.extend({
92
+ C.extend({
62
93
  addPasteRules: () => [],
63
94
  addInputRules: () => []
64
95
  }).configure({
@@ -70,36 +101,36 @@ function ae(e) {
70
101
  class: "bik-link"
71
102
  }
72
103
  }),
73
- T,
74
- b.configure({
104
+ D,
105
+ l.configure({
75
106
  placeholder: e.placeholder ?? "Type a message..."
76
107
  }),
77
108
  // Consumer paste callback runs first. If it returns true the event is
78
109
  // consumed and neither PlainClipboardExtension nor the editor's default
79
110
  // paste handling will run for that event.
80
- ...e.onPaste ? [B.configure({ onPaste: e.onPaste })] : [],
81
- I.configure({
111
+ ...e.onPaste ? [I.configure({ onPaste: e.onPaste })] : [],
112
+ O.configure({
82
113
  preserveMarks: o,
83
114
  // Only email + signature (richPaste) keep the rich HTML paste pipeline.
84
115
  // Every other channel (WhatsApp, IG, FB, comments) forces plain-text
85
116
  // paste for BOTH Cmd/Ctrl+V and Cmd/Ctrl+Shift+V — no formatting.
86
117
  plainOnly: !o
87
118
  }),
88
- O.configure({
119
+ d.configure({
89
120
  onSend: e.onSend,
90
121
  sendShortcut: e.sendShortcut,
91
122
  extraShortcuts: e.shortcuts ?? []
92
123
  }),
93
- R,
94
- ...e.maxCharacters ? [h.configure({ limit: e.maxCharacters })] : [],
124
+ z,
125
+ ...e.maxCharacters ? [a.configure({ limit: e.maxCharacters })] : [],
95
126
  // Always register SectionDividerNode so the custom <div data-section-divider>
96
127
  // node is part of the schema in every editor instance. This means imperative
97
128
  // callers (setBodyAndSections / setSectionContent) work even when no
98
129
  // `sections` prop was provided at mount time.
99
- L
100
- ], p = [
130
+ R
131
+ ], c = [
101
132
  ...e.mentions?.agents ? [
102
- H(
133
+ w(
103
134
  e.mentions.agents,
104
135
  e.onMentionSelected,
105
136
  e.renderMentionItem,
@@ -108,7 +139,7 @@ function ae(e) {
108
139
  )
109
140
  ] : [],
110
141
  ...e.mentions?.teams ? [
111
- w(
142
+ B(
112
143
  e.mentions.teams,
113
144
  e.onMentionSelected,
114
145
  e.renderMentionItem,
@@ -124,19 +155,19 @@ function ae(e) {
124
155
  e.renderSlashCommandDropdown
125
156
  )
126
157
  ] : []
127
- ], u = i ? [
128
- s,
129
- x.configure({ multicolor: !0 }),
130
- f,
131
- g,
132
- E.configure({ types: ["heading", "paragraph"] }),
133
- y,
134
- C,
135
- S
136
- ] : [s];
137
- return [...d, ...p, ...u];
158
+ ], x = u ? [
159
+ i,
160
+ M.configure({ multicolor: !0 }),
161
+ S,
162
+ L,
163
+ P.configure({ types: ["heading", "paragraph"] }),
164
+ E,
165
+ T,
166
+ b
167
+ ] : [i];
168
+ return [...f, ...c, ...x];
138
169
  }
139
170
  export {
140
- ae as buildExtensions
171
+ ie as buildExtensions
141
172
  };
142
173
  //# sourceMappingURL=buildExtensions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildExtensions.js","sources":["../../../../src/editor/extensions/buildExtensions.ts"],"sourcesContent":["import CharacterCount from '@tiptap/extension-character-count';\nimport Color from '@tiptap/extension-color';\nimport FontFamily from '@tiptap/extension-font-family';\nimport HardBreak from '@tiptap/extension-hard-break';\nimport Highlight from '@tiptap/extension-highlight';\nimport Image from '@tiptap/extension-image';\nimport Link from '@tiptap/extension-link';\nimport Paragraph from '@tiptap/extension-paragraph';\nimport Placeholder from '@tiptap/extension-placeholder';\nimport Subscript from '@tiptap/extension-subscript';\nimport Superscript from '@tiptap/extension-superscript';\nimport TextAlign from '@tiptap/extension-text-align';\nimport { TextStyle } from '@tiptap/extension-text-style';\nimport Underline from '@tiptap/extension-underline';\nimport StarterKit from '@tiptap/starter-kit';\nimport type { ReactNode } from 'react';\nimport type {\n\tEditorFeatures,\n\tEditorSnapshot,\n\tKeyboardShortcut,\n\tMentionDropdownRenderProps,\n\tMentionItem,\n\tPasteData,\n\tSlashCommandDropdownRenderProps,\n\tSlashCommandItem,\n} from '../BikEditor.types';\nimport { FontSizeExtension } from './FontSizeExtension';\nimport {\n\tbuildAgentMentionExtension,\n\tbuildTeamMentionExtension,\n} from './mention/MentionExtension';\nimport { PasteExtension } from './paste/PasteExtension';\nimport { PasteNormalizationExtension } from './plainClipboard/PasteNormalizationExtension';\nimport { SectionDividerNode } from './sectionDivider/SectionDividerNode';\nimport { SendShortcutExtension } from './sendShortcut/SendShortcutExtension';\nimport { buildSlashCommandExtension } from './slashCommand/SlashCommandExtension';\nimport { VariableDecorationExtension } from './variable/VariableDecorationExtension';\n\ninterface ExtensionConfig {\n\tfeatures?: EditorFeatures;\n\tplaceholder?: string;\n\tmaxCharacters?: number;\n\thasSections?: boolean;\n\tmentions?: {\n\t\tagents?: { current: MentionItem[] };\n\t\tteams?: { current: MentionItem[] };\n\t};\n\tslashCommands?: { current: SlashCommandItem[] };\n\tonPaste?: (data: PasteData) => boolean | void;\n\tonSend?: (content: EditorSnapshot) => void;\n\tsendShortcut?:\n\t\t| { key: string; modifiers?: Array<'mod' | 'ctrl' | 'shift' | 'alt'> }\n\t\t| Array<{\n\t\t\t\tkey: string;\n\t\t\t\tmodifiers?: Array<'mod' | 'ctrl' | 'shift' | 'alt'>;\n\t\t }>;\n\tshortcuts?: KeyboardShortcut[];\n\tonMentionSelected?: (item: MentionItem, char: '@' | '#') => void;\n\tonSlashCommandSelected?: (command: SlashCommandItem) => void;\n\trenderMentionItem?: (item: MentionItem, isActive: boolean) => ReactNode;\n\trenderMentionDropdown?: (props: MentionDropdownRenderProps) => ReactNode;\n\tremoveMentionTriggerOnDismiss?: boolean;\n\trenderSlashCommandItem?: (\n\t\titem: SlashCommandItem,\n\t\tisActive: boolean,\n\t) => ReactNode;\n\trenderSlashCommandDropdown?: (\n\t\tprops: SlashCommandDropdownRenderProps,\n\t) => ReactNode;\n}\n\nexport function buildExtensions(config: ExtensionConfig) {\n\tconst hasRichPaste = config.features?.richPaste ?? false;\n\tconst hasRichTypography = config.features?.richTypography ?? false;\n\n\t// When allowedMarks is specified only those marks are registered in the schema.\n\t// This disables rendering, keyboard shortcuts AND paste-preservation for the\n\t// excluded marks — all three come for free when the extension is absent.\n\tconst allowedMarks = config.features?.allowedMarks;\n\tconst isMark = (m: 'bold' | 'italic' | 'strike' | 'underline' | 'code') =>\n\t\t!allowedMarks || allowedMarks.includes(m);\n\n\t// Soft line break. Shift-Enter inserts a <br> inside the current block\n\t// (matches Gmail); plain Enter still splits the block into a new paragraph\n\t// via StarterKit's default. HardBreak is registered standalone — like Link\n\t// and Underline above — instead of through StarterKit, so we can bind ONLY\n\t// Shift-Enter here and leave Mod-Enter free for the send shortcut.\n\tconst softBreak = HardBreak.extend({\n\t\taddKeyboardShortcuts() {\n\t\t\treturn {\n\t\t\t\t'Shift-Enter': () => this.editor.commands.setHardBreak(),\n\t\t\t};\n\t\t},\n\t});\n\n\t// Paragraph that preserves a zero block-margin from the source (Gmail-style).\n\t// Most sources (ChatGPT, typed text) use plain <p> → no margin attr → the\n\t// editor/viewer default 1em margin provides the gap. Google-Docs-style\n\t// content uses margin:0 paragraphs and a separate blank-line paragraph for\n\t// spacing; we keep that margin:0 so the blank line — not stacked margins —\n\t// provides a single-line gap, exactly like Gmail. The paste pipeline also\n\t// sets margin:'0' on every paragraph when a paste contains blank-line\n\t// paragraphs (see applyParagraphSpacing), so spacing comes from EITHER the\n\t// margin OR the blank line, never both (no double gap).\n\tconst isZeroLen = (v: string) =>\n\t\tv === '0' || v === '0px' || v === '0pt' || v === '0em';\n\tconst ParagraphWithMargin = Paragraph.extend({\n\t\taddAttributes() {\n\t\t\treturn {\n\t\t\t\t...(this.parent?.() ?? {}),\n\t\t\t\tmargin: {\n\t\t\t\t\tdefault: null,\n\t\t\t\t\tparseHTML: (el: HTMLElement) =>\n\t\t\t\t\t\tisZeroLen(el.style.marginTop) && isZeroLen(el.style.marginBottom)\n\t\t\t\t\t\t\t? '0'\n\t\t\t\t\t\t\t: null,\n\t\t\t\t\trenderHTML: (attrs: { margin?: string | null }) =>\n\t\t\t\t\t\tattrs.margin === '0' ? { style: 'margin: 0px' } : {},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t});\n\n\tconst base = [\n\t\t// Exclude Link and Underline from StarterKit — TipTap v3 bundles both.\n\t\t// Without this, two copies of each are registered and the StarterKit copy's\n\t\t// click handler calls window.open even when openOnClick: false is set.\n\t\tStarterKit.configure({\n\t\t\tlink: false,\n\t\t\tunderline: false,\n\t\t\thardBreak: false,\n\t\t\tparagraph: false,\n\t\t\tbold: isMark('bold') ? {} : false,\n\t\t\titalic: isMark('italic') ? {} : false,\n\t\t\tstrike: isMark('strike') ? {} : false,\n\t\t\tcode: isMark('code') ? {} : false,\n\t\t}),\n\t\tParagraphWithMargin,\n\t\tsoftBreak,\n\t\t...(isMark('underline') ? [Underline] : []),\n\t\t// Extend Link to strip addPasteRules() and addInputRules() so pasting a\n\t\t// URL never creates a hyperlink regardless of autolink/linkOnPaste values.\n\t\tLink.extend({\n\t\t\taddPasteRules: () => [],\n\t\t\taddInputRules: () => [],\n\t\t}).configure({\n\t\t\topenOnClick: false,\n\t\t\tautolink: false,\n\t\t\tlinkOnPaste: false,\n\t\t\tHTMLAttributes: {\n\t\t\t\trel: 'noopener noreferrer',\n\t\t\t\tclass: 'bik-link',\n\t\t\t},\n\t\t}),\n\t\tTextStyle,\n\t\tPlaceholder.configure({\n\t\t\tplaceholder: config.placeholder ?? 'Type a message...',\n\t\t}),\n\t\t// Consumer paste callback runs first. If it returns true the event is\n\t\t// consumed and neither PlainClipboardExtension nor the editor's default\n\t\t// paste handling will run for that event.\n\t\t...(config.onPaste\n\t\t\t? [PasteExtension.configure({ onPaste: config.onPaste })]\n\t\t\t: []),\n\t\tPasteNormalizationExtension.configure({\n\t\t\tpreserveMarks: hasRichPaste,\n\t\t\t// Only email + signature (richPaste) keep the rich HTML paste pipeline.\n\t\t\t// Every other channel (WhatsApp, IG, FB, comments) forces plain-text\n\t\t\t// paste for BOTH Cmd/Ctrl+V and Cmd/Ctrl+Shift+V — no formatting.\n\t\t\tplainOnly: !hasRichPaste,\n\t\t}),\n\t\tSendShortcutExtension.configure({\n\t\t\tonSend: config.onSend,\n\t\t\tsendShortcut: config.sendShortcut,\n\t\t\textraShortcuts: config.shortcuts ?? [],\n\t\t}),\n\t\tVariableDecorationExtension,\n\t\t...(config.maxCharacters\n\t\t\t? [CharacterCount.configure({ limit: config.maxCharacters })]\n\t\t\t: []),\n\t\t// Always register SectionDividerNode so the custom <div data-section-divider>\n\t\t// node is part of the schema in every editor instance. This means imperative\n\t\t// callers (setBodyAndSections / setSectionContent) work even when no\n\t\t// `sections` prop was provided at mount time.\n\t\tSectionDividerNode,\n\t];\n\n\tconst mentionExtensions = [\n\t\t...(config.mentions?.agents\n\t\t\t? [\n\t\t\t\t\tbuildAgentMentionExtension(\n\t\t\t\t\t\tconfig.mentions.agents,\n\t\t\t\t\t\tconfig.onMentionSelected,\n\t\t\t\t\t\tconfig.renderMentionItem,\n\t\t\t\t\t\tconfig.renderMentionDropdown,\n\t\t\t\t\t\tconfig.removeMentionTriggerOnDismiss,\n\t\t\t\t\t),\n\t\t\t ]\n\t\t\t: []),\n\t\t...(config.mentions?.teams\n\t\t\t? [\n\t\t\t\t\tbuildTeamMentionExtension(\n\t\t\t\t\t\tconfig.mentions.teams,\n\t\t\t\t\t\tconfig.onMentionSelected,\n\t\t\t\t\t\tconfig.renderMentionItem,\n\t\t\t\t\t\tconfig.renderMentionDropdown,\n\t\t\t\t\t\tconfig.removeMentionTriggerOnDismiss,\n\t\t\t\t\t),\n\t\t\t ]\n\t\t\t: []),\n\t\t...(config.slashCommands\n\t\t\t? [\n\t\t\t\t\tbuildSlashCommandExtension(\n\t\t\t\t\t\tconfig.slashCommands,\n\t\t\t\t\t\tconfig.onSlashCommandSelected,\n\t\t\t\t\t\tconfig.renderSlashCommandItem,\n\t\t\t\t\t\tconfig.renderSlashCommandDropdown,\n\t\t\t\t\t),\n\t\t\t ]\n\t\t\t: []),\n\t];\n\n\tconst richExtensions = hasRichTypography\n\t\t? [\n\t\t\t\tColor,\n\t\t\t\tHighlight.configure({ multicolor: true }),\n\t\t\t\tFontFamily,\n\t\t\t\tFontSizeExtension,\n\t\t\t\tTextAlign.configure({ types: ['heading', 'paragraph'] }),\n\t\t\t\tSubscript,\n\t\t\t\tSuperscript,\n\t\t\t\tImage,\n\t\t ]\n\t\t: [Color];\n\n\treturn [...base, ...mentionExtensions, ...richExtensions];\n}\n"],"names":["buildExtensions","config","hasRichPaste","hasRichTypography","allowedMarks","isMark","m","softBreak","HardBreak","isZeroLen","v","ParagraphWithMargin","Paragraph","el","attrs","base","StarterKit","Underline","Link","TextStyle","Placeholder","PasteExtension","PasteNormalizationExtension","SendShortcutExtension","VariableDecorationExtension","CharacterCount","SectionDividerNode","mentionExtensions","buildAgentMentionExtension","buildTeamMentionExtension","buildSlashCommandExtension","richExtensions","Color","Highlight","FontFamily","FontSizeExtension","TextAlign","Subscript","Superscript","Image"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuEO,SAASA,GAAgBC,GAAyB;AACxD,QAAMC,IAAeD,EAAO,UAAU,aAAa,IAC7CE,IAAoBF,EAAO,UAAU,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MAAA;AAAA,IACR,IAEA,CAAA;AAAA,EAAC,GAGC8B,IAAiB5B,IACpB;AAAA,IACA6B;AAAA,IACAC,EAAU,UAAU,EAAE,YAAY,IAAM;AAAA,IACxCC;AAAA,IACAC;AAAA,IACAC,EAAU,UAAU,EAAE,OAAO,CAAC,WAAW,WAAW,GAAG;AAAA,IACvDC;AAAA,IACAC;AAAA,IACAC;AAAA,EAAA,IAEA,CAACP,CAAK;AAET,SAAO,CAAC,GAAGjB,GAAM,GAAGY,GAAmB,GAAGI,CAAc;AACzD;"}
1
+ {"version":3,"file":"buildExtensions.js","sources":["../../../../src/editor/extensions/buildExtensions.ts"],"sourcesContent":["import CharacterCount from '@tiptap/extension-character-count';\nimport Color from '@tiptap/extension-color';\nimport FontFamily from '@tiptap/extension-font-family';\nimport HardBreak from '@tiptap/extension-hard-break';\nimport Highlight from '@tiptap/extension-highlight';\nimport Image from '@tiptap/extension-image';\nimport Link from '@tiptap/extension-link';\nimport Paragraph from '@tiptap/extension-paragraph';\nimport Placeholder from '@tiptap/extension-placeholder';\nimport Subscript from '@tiptap/extension-subscript';\nimport Superscript from '@tiptap/extension-superscript';\nimport TextAlign from '@tiptap/extension-text-align';\nimport { TextStyle } from '@tiptap/extension-text-style';\nimport Underline from '@tiptap/extension-underline';\nimport StarterKit from '@tiptap/starter-kit';\nimport type { ReactNode } from 'react';\nimport type {\n\tEditorFeatures,\n\tEditorSnapshot,\n\tKeyboardShortcut,\n\tMentionDropdownRenderProps,\n\tMentionItem,\n\tPasteData,\n\tSlashCommandDropdownRenderProps,\n\tSlashCommandItem,\n} from '../BikEditor.types';\nimport { FontSizeExtension } from './FontSizeExtension';\nimport { JsonHighlightExtension } from './jsonHighlight/JsonHighlightExtension';\nimport {\n\tbuildAgentMentionExtension,\n\tbuildTeamMentionExtension,\n} from './mention/MentionExtension';\nimport { PasteExtension } from './paste/PasteExtension';\nimport { PasteNormalizationExtension } from './plainClipboard/PasteNormalizationExtension';\nimport { SectionDividerNode } from './sectionDivider/SectionDividerNode';\nimport { SendShortcutExtension } from './sendShortcut/SendShortcutExtension';\nimport { buildSlashCommandExtension } from './slashCommand/SlashCommandExtension';\nimport { VariableDecorationExtension } from './variable/VariableDecorationExtension';\n\ninterface ExtensionConfig {\n\tfeatures?: EditorFeatures;\n\tplaceholder?: string;\n\tmaxCharacters?: number;\n\thasSections?: boolean;\n\tmentions?: {\n\t\tagents?: { current: MentionItem[] };\n\t\tteams?: { current: MentionItem[] };\n\t};\n\tslashCommands?: { current: SlashCommandItem[] };\n\tonPaste?: (data: PasteData) => boolean | void;\n\tonSend?: (content: EditorSnapshot) => void;\n\tsendShortcut?:\n\t\t| { key: string; modifiers?: Array<'mod' | 'ctrl' | 'shift' | 'alt'> }\n\t\t| Array<{\n\t\t\t\tkey: string;\n\t\t\t\tmodifiers?: Array<'mod' | 'ctrl' | 'shift' | 'alt'>;\n\t\t }>;\n\tshortcuts?: KeyboardShortcut[];\n\tonMentionSelected?: (item: MentionItem, char: '@' | '#') => void;\n\tonSlashCommandSelected?: (command: SlashCommandItem) => void;\n\trenderMentionItem?: (item: MentionItem, isActive: boolean) => ReactNode;\n\trenderMentionDropdown?: (props: MentionDropdownRenderProps) => ReactNode;\n\tremoveMentionTriggerOnDismiss?: boolean;\n\trenderSlashCommandItem?: (\n\t\titem: SlashCommandItem,\n\t\tisActive: boolean,\n\t) => ReactNode;\n\trenderSlashCommandDropdown?: (\n\t\tprops: SlashCommandDropdownRenderProps,\n\t) => ReactNode;\n}\n\nexport function buildExtensions(config: ExtensionConfig) {\n\t// JSON body mode is a dedicated code editor — it deliberately skips the rich\n\t// text stack (mentions, typography, rich paste, sections) and turns the whole\n\t// document into one syntax-highlighted JSON code block, Postman-style.\n\tif (config.features?.jsonMode) {\n\t\treturn [\n\t\t\tStarterKit.configure({\n\t\t\t\tlink: false,\n\t\t\t\tunderline: false,\n\t\t\t\t// Keep codeBlock (the JSON container) and history; drop everything\n\t\t\t\t// that has no meaning inside raw JSON.\n\t\t\t\tbold: false,\n\t\t\t\titalic: false,\n\t\t\t\tstrike: false,\n\t\t\t\tcode: false,\n\t\t\t\theading: false,\n\t\t\t\tbulletList: false,\n\t\t\t\torderedList: false,\n\t\t\t\tblockquote: false,\n\t\t\t\thorizontalRule: false,\n\t\t\t}),\n\t\t\tPlaceholder.configure({\n\t\t\t\tplaceholder: config.placeholder ?? '{\\n \\n}',\n\t\t\t}),\n\t\t\tJsonHighlightExtension,\n\t\t\tSendShortcutExtension.configure({\n\t\t\t\tonSend: config.onSend,\n\t\t\t\tsendShortcut: config.sendShortcut,\n\t\t\t\textraShortcuts: config.shortcuts ?? [],\n\t\t\t}),\n\t\t\t...(config.maxCharacters\n\t\t\t\t? [CharacterCount.configure({ limit: config.maxCharacters })]\n\t\t\t\t: []),\n\t\t];\n\t}\n\n\tconst hasRichPaste = config.features?.richPaste ?? false;\n\tconst hasRichTypography = config.features?.richTypography ?? false;\n\n\t// When allowedMarks is specified only those marks are registered in the schema.\n\t// This disables rendering, keyboard shortcuts AND paste-preservation for the\n\t// excluded marks — all three come for free when the extension is absent.\n\tconst allowedMarks = config.features?.allowedMarks;\n\tconst isMark = (m: 'bold' | 'italic' | 'strike' | 'underline' | 'code') =>\n\t\t!allowedMarks || allowedMarks.includes(m);\n\n\t// Soft line break. Shift-Enter inserts a <br> inside the current block\n\t// (matches Gmail); plain Enter still splits the block into a new paragraph\n\t// via StarterKit's default. HardBreak is registered standalone — like Link\n\t// and Underline above — instead of through StarterKit, so we can bind ONLY\n\t// Shift-Enter here and leave Mod-Enter free for the send shortcut.\n\tconst softBreak = HardBreak.extend({\n\t\taddKeyboardShortcuts() {\n\t\t\treturn {\n\t\t\t\t'Shift-Enter': () => this.editor.commands.setHardBreak(),\n\t\t\t};\n\t\t},\n\t});\n\n\t// Paragraph that preserves a zero block-margin from the source (Gmail-style).\n\t// Most sources (ChatGPT, typed text) use plain <p> → no margin attr → the\n\t// editor/viewer default 1em margin provides the gap. Google-Docs-style\n\t// content uses margin:0 paragraphs and a separate blank-line paragraph for\n\t// spacing; we keep that margin:0 so the blank line — not stacked margins —\n\t// provides a single-line gap, exactly like Gmail. The paste pipeline also\n\t// sets margin:'0' on every paragraph when a paste contains blank-line\n\t// paragraphs (see applyParagraphSpacing), so spacing comes from EITHER the\n\t// margin OR the blank line, never both (no double gap).\n\tconst isZeroLen = (v: string) =>\n\t\tv === '0' || v === '0px' || v === '0pt' || v === '0em';\n\tconst ParagraphWithMargin = Paragraph.extend({\n\t\taddAttributes() {\n\t\t\treturn {\n\t\t\t\t...(this.parent?.() ?? {}),\n\t\t\t\tmargin: {\n\t\t\t\t\tdefault: null,\n\t\t\t\t\tparseHTML: (el: HTMLElement) =>\n\t\t\t\t\t\tisZeroLen(el.style.marginTop) && isZeroLen(el.style.marginBottom)\n\t\t\t\t\t\t\t? '0'\n\t\t\t\t\t\t\t: null,\n\t\t\t\t\trenderHTML: (attrs: { margin?: string | null }) =>\n\t\t\t\t\t\tattrs.margin === '0' ? { style: 'margin: 0px' } : {},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t});\n\n\tconst base = [\n\t\t// Exclude Link and Underline from StarterKit — TipTap v3 bundles both.\n\t\t// Without this, two copies of each are registered and the StarterKit copy's\n\t\t// click handler calls window.open even when openOnClick: false is set.\n\t\tStarterKit.configure({\n\t\t\tlink: false,\n\t\t\tunderline: false,\n\t\t\thardBreak: false,\n\t\t\tparagraph: false,\n\t\t\tbold: isMark('bold') ? {} : false,\n\t\t\titalic: isMark('italic') ? {} : false,\n\t\t\tstrike: isMark('strike') ? {} : false,\n\t\t\tcode: isMark('code') ? {} : false,\n\t\t}),\n\t\tParagraphWithMargin,\n\t\tsoftBreak,\n\t\t...(isMark('underline') ? [Underline] : []),\n\t\t// Extend Link to strip addPasteRules() and addInputRules() so pasting a\n\t\t// URL never creates a hyperlink regardless of autolink/linkOnPaste values.\n\t\tLink.extend({\n\t\t\taddPasteRules: () => [],\n\t\t\taddInputRules: () => [],\n\t\t}).configure({\n\t\t\topenOnClick: false,\n\t\t\tautolink: false,\n\t\t\tlinkOnPaste: false,\n\t\t\tHTMLAttributes: {\n\t\t\t\trel: 'noopener noreferrer',\n\t\t\t\tclass: 'bik-link',\n\t\t\t},\n\t\t}),\n\t\tTextStyle,\n\t\tPlaceholder.configure({\n\t\t\tplaceholder: config.placeholder ?? 'Type a message...',\n\t\t}),\n\t\t// Consumer paste callback runs first. If it returns true the event is\n\t\t// consumed and neither PlainClipboardExtension nor the editor's default\n\t\t// paste handling will run for that event.\n\t\t...(config.onPaste\n\t\t\t? [PasteExtension.configure({ onPaste: config.onPaste })]\n\t\t\t: []),\n\t\tPasteNormalizationExtension.configure({\n\t\t\tpreserveMarks: hasRichPaste,\n\t\t\t// Only email + signature (richPaste) keep the rich HTML paste pipeline.\n\t\t\t// Every other channel (WhatsApp, IG, FB, comments) forces plain-text\n\t\t\t// paste for BOTH Cmd/Ctrl+V and Cmd/Ctrl+Shift+V — no formatting.\n\t\t\tplainOnly: !hasRichPaste,\n\t\t}),\n\t\tSendShortcutExtension.configure({\n\t\t\tonSend: config.onSend,\n\t\t\tsendShortcut: config.sendShortcut,\n\t\t\textraShortcuts: config.shortcuts ?? [],\n\t\t}),\n\t\tVariableDecorationExtension,\n\t\t...(config.maxCharacters\n\t\t\t? [CharacterCount.configure({ limit: config.maxCharacters })]\n\t\t\t: []),\n\t\t// Always register SectionDividerNode so the custom <div data-section-divider>\n\t\t// node is part of the schema in every editor instance. This means imperative\n\t\t// callers (setBodyAndSections / setSectionContent) work even when no\n\t\t// `sections` prop was provided at mount time.\n\t\tSectionDividerNode,\n\t];\n\n\tconst mentionExtensions = [\n\t\t...(config.mentions?.agents\n\t\t\t? [\n\t\t\t\t\tbuildAgentMentionExtension(\n\t\t\t\t\t\tconfig.mentions.agents,\n\t\t\t\t\t\tconfig.onMentionSelected,\n\t\t\t\t\t\tconfig.renderMentionItem,\n\t\t\t\t\t\tconfig.renderMentionDropdown,\n\t\t\t\t\t\tconfig.removeMentionTriggerOnDismiss,\n\t\t\t\t\t),\n\t\t\t ]\n\t\t\t: []),\n\t\t...(config.mentions?.teams\n\t\t\t? [\n\t\t\t\t\tbuildTeamMentionExtension(\n\t\t\t\t\t\tconfig.mentions.teams,\n\t\t\t\t\t\tconfig.onMentionSelected,\n\t\t\t\t\t\tconfig.renderMentionItem,\n\t\t\t\t\t\tconfig.renderMentionDropdown,\n\t\t\t\t\t\tconfig.removeMentionTriggerOnDismiss,\n\t\t\t\t\t),\n\t\t\t ]\n\t\t\t: []),\n\t\t...(config.slashCommands\n\t\t\t? [\n\t\t\t\t\tbuildSlashCommandExtension(\n\t\t\t\t\t\tconfig.slashCommands,\n\t\t\t\t\t\tconfig.onSlashCommandSelected,\n\t\t\t\t\t\tconfig.renderSlashCommandItem,\n\t\t\t\t\t\tconfig.renderSlashCommandDropdown,\n\t\t\t\t\t),\n\t\t\t ]\n\t\t\t: []),\n\t];\n\n\tconst richExtensions = hasRichTypography\n\t\t? [\n\t\t\t\tColor,\n\t\t\t\tHighlight.configure({ multicolor: true }),\n\t\t\t\tFontFamily,\n\t\t\t\tFontSizeExtension,\n\t\t\t\tTextAlign.configure({ types: ['heading', 'paragraph'] }),\n\t\t\t\tSubscript,\n\t\t\t\tSuperscript,\n\t\t\t\tImage,\n\t\t ]\n\t\t: [Color];\n\n\treturn [...base, ...mentionExtensions, ...richExtensions];\n}\n"],"names":["buildExtensions","config","StarterKit","Placeholder","JsonHighlightExtension","SendShortcutExtension","CharacterCount","hasRichPaste","hasRichTypography","allowedMarks","isMark","m","softBreak","HardBreak","isZeroLen","v","ParagraphWithMargin","Paragraph","el","attrs","base","Underline","Link","TextStyle","PasteExtension","PasteNormalizationExtension","VariableDecorationExtension","SectionDividerNode","mentionExtensions","buildAgentMentionExtension","buildTeamMentionExtension","buildSlashCommandExtension","richExtensions","Color","Highlight","FontFamily","FontSizeExtension","TextAlign","Subscript","Superscript","Image"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwEO,SAASA,G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rB,gBAAgBA,EAAO,aAAa,CAAA;AAAA,IAAC,CACrC;AAAA,IACDyB;AAAA,IACA,GAAIzB,EAAO,gBACR,CAACK,EAAe,UAAU,EAAE,OAAOL,EAAO,eAAe,CAAC,IAC1D,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKH0B;AAAA,EAAA,GAGKC,IAAoB;AAAA,IACzB,GAAI3B,EAAO,UAAU,SAClB;AAAA,MACA4B;AAAA,QACC5B,EAAO,SAAS;AAAA,QAChBA,EAAO;AAAA,QACPA,EAAO;AAAA,QACPA,EAAO;AAAA,QACPA,EAAO;AAAA,MAAA;AAAA,IACR,IAEA,CAAA;AAAA,IACH,GAAIA,EAAO,UAAU,QAClB;AAAA,MACA6B;AAAA,QACC7B,EAAO,SAAS;AAAA,QAChBA,EAAO;AAAA,QACPA,EAAO;AAAA,QACPA,EAAO;AAAA,QACPA,EAAO;AAAA,MAAA;AAAA,IACR,IAEA,CAAA;AAAA,IACH,GAAIA,EAAO,gBACR;AAAA,MACA8B;AAAA,QACC9B,EAAO;AAAA,QACPA,EAAO;AAAA,QACPA,EAAO;AAAA,QACPA,EAAO;AAAA,MAAA;AAAA,IACR,IAEA,CAAA;AAAA,EAAC,GAGC+B,IAAiBxB,IACpB;AAAA,IACAyB;AAAA,IACAC,EAAU,UAAU,EAAE,YAAY,IAAM;AAAA,IACxCC;AAAA,IACAC;AAAA,IACAC,EAAU,UAAU,EAAE,OAAO,CAAC,WAAW,WAAW,GAAG;AAAA,IACvDC;AAAA,IACAC;AAAA,IACAC;AAAA,EAAA,IAEA,CAACP,CAAK;AAET,SAAO,CAAC,GAAGb,GAAM,GAAGQ,GAAmB,GAAGI,CAAc;AACzD;"}
@@ -0,0 +1,14 @@
1
+ import { Extension } from '@tiptap/core';
2
+ /**
3
+ * Colours JSON tokens inside `codeBlock` nodes and renders a line-number gutter.
4
+ * A code block stores its whole multi-line body in a single text node, so token
5
+ * offsets map 1:1 onto document positions (`nodeStart + offset`) — no cross-node
6
+ * bookkeeping needed, and lines are just the `\n`-separated runs of that text.
7
+ *
8
+ * Purely decorative: the document text is never rewritten, so undo/redo,
9
+ * character count and the cursor all behave exactly as with plain text. The
10
+ * gutter numbers are `side: -1` widgets that hang into the code block's left
11
+ * padding (see `.bik-json-lineno` in BikEditor.styles.ts), so they never enter
12
+ * the document text or shift character offsets.
13
+ */
14
+ export declare const JsonHighlightExtension: Extension<any, any>;
@@ -0,0 +1,64 @@
1
+ import { Extension as d } from "../../../node_modules/@tiptap/core/dist/index.js";
2
+ import { Plugin as g, PluginKey as m } from "@tiptap/pm/state";
3
+ import { Decoration as s, DecorationSet as p } from "@tiptap/pm/view";
4
+ import { tokenizeJson as b } from "./tokenizeJson.js";
5
+ const k = {
6
+ key: "bik-json-key",
7
+ string: "bik-json-string",
8
+ number: "bik-json-number",
9
+ boolean: "bik-json-boolean",
10
+ null: "bik-json-null",
11
+ punctuation: "bik-json-punct"
12
+ };
13
+ function a(t) {
14
+ const n = document.createElement("span");
15
+ return n.className = "bik-json-lineno", n.textContent = String(t), n.setAttribute("contenteditable", "false"), n;
16
+ }
17
+ const x = d.create({
18
+ name: "jsonHighlight",
19
+ addProseMirrorPlugins() {
20
+ return [
21
+ new g({
22
+ key: new m("jsonHighlight"),
23
+ props: {
24
+ decorations(t) {
25
+ const n = [];
26
+ return t.doc.descendants((r, u) => {
27
+ if (r.type.name !== "codeBlock") return;
28
+ const i = r.textContent, o = u + 1;
29
+ for (const e of b(i))
30
+ n.push(
31
+ s.inline(o + e.start, o + e.end, {
32
+ class: k[e.type]
33
+ })
34
+ );
35
+ let c = 1;
36
+ n.push(
37
+ s.widget(o, () => a(1), {
38
+ side: -1,
39
+ key: "ln-1"
40
+ })
41
+ );
42
+ for (let e = 0; e < i.length; e++) {
43
+ if (i[e] !== `
44
+ `) continue;
45
+ c += 1;
46
+ const l = c;
47
+ n.push(
48
+ s.widget(o + e + 1, () => a(l), {
49
+ side: -1,
50
+ key: `ln-${l}`
51
+ })
52
+ );
53
+ }
54
+ }), p.create(t.doc, n);
55
+ }
56
+ }
57
+ })
58
+ ];
59
+ }
60
+ });
61
+ export {
62
+ x as JsonHighlightExtension
63
+ };
64
+ //# sourceMappingURL=JsonHighlightExtension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonHighlightExtension.js","sources":["../../../../../src/editor/extensions/jsonHighlight/JsonHighlightExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport { Plugin, PluginKey } from '@tiptap/pm/state';\nimport { Decoration, DecorationSet } from '@tiptap/pm/view';\nimport { JsonTokenType, tokenizeJson } from './tokenizeJson';\n\nconst CLASS_BY_TYPE: Record<JsonTokenType, string> = {\n\tkey: 'bik-json-key',\n\tstring: 'bik-json-string',\n\tnumber: 'bik-json-number',\n\tboolean: 'bik-json-boolean',\n\tnull: 'bik-json-null',\n\tpunctuation: 'bik-json-punct',\n};\n\n/** Line-number widget rendered in the hanging gutter at each line start. */\nfunction lineNumberWidget(n: number): HTMLElement {\n\tconst span = document.createElement('span');\n\tspan.className = 'bik-json-lineno';\n\tspan.textContent = String(n);\n\tspan.setAttribute('contenteditable', 'false');\n\treturn span;\n}\n\n/**\n * Colours JSON tokens inside `codeBlock` nodes and renders a line-number gutter.\n * A code block stores its whole multi-line body in a single text node, so token\n * offsets map 1:1 onto document positions (`nodeStart + offset`) — no cross-node\n * bookkeeping needed, and lines are just the `\\n`-separated runs of that text.\n *\n * Purely decorative: the document text is never rewritten, so undo/redo,\n * character count and the cursor all behave exactly as with plain text. The\n * gutter numbers are `side: -1` widgets that hang into the code block's left\n * padding (see `.bik-json-lineno` in BikEditor.styles.ts), so they never enter\n * the document text or shift character offsets.\n */\nexport const JsonHighlightExtension = Extension.create({\n\tname: 'jsonHighlight',\n\taddProseMirrorPlugins() {\n\t\treturn [\n\t\t\tnew Plugin({\n\t\t\t\tkey: new PluginKey('jsonHighlight'),\n\t\t\t\tprops: {\n\t\t\t\t\tdecorations(state) {\n\t\t\t\t\t\tconst decorations: Decoration[] = [];\n\t\t\t\t\t\tstate.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (node.type.name !== 'codeBlock') return;\n\t\t\t\t\t\t\tconst text = node.textContent;\n\t\t\t\t\t\t\t// +1: step past the code-block node boundary into its text.\n\t\t\t\t\t\t\tconst base = pos + 1;\n\n\t\t\t\t\t\t\tfor (const tok of tokenizeJson(text)) {\n\t\t\t\t\t\t\t\tdecorations.push(\n\t\t\t\t\t\t\t\t\tDecoration.inline(base + tok.start, base + tok.end, {\n\t\t\t\t\t\t\t\t\t\tclass: CLASS_BY_TYPE[tok.type],\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// One line number per `\\n`-separated line (line 1 at offset 0,\n\t\t\t\t\t\t\t// then one after every newline). `white-space: pre` on the block\n\t\t\t\t\t\t\t// disables wrapping, so logical lines == visual lines.\n\t\t\t\t\t\t\tlet line = 1;\n\t\t\t\t\t\t\tdecorations.push(\n\t\t\t\t\t\t\t\tDecoration.widget(base, () => lineNumberWidget(1), {\n\t\t\t\t\t\t\t\t\tside: -1,\n\t\t\t\t\t\t\t\t\tkey: 'ln-1',\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tfor (let i = 0; i < text.length; i++) {\n\t\t\t\t\t\t\t\tif (text[i] !== '\\n') continue;\n\t\t\t\t\t\t\t\tline += 1;\n\t\t\t\t\t\t\t\tconst n = line;\n\t\t\t\t\t\t\t\tdecorations.push(\n\t\t\t\t\t\t\t\t\tDecoration.widget(base + i + 1, () => lineNumberWidget(n), {\n\t\t\t\t\t\t\t\t\t\tside: -1,\n\t\t\t\t\t\t\t\t\t\tkey: `ln-${n}`,\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn DecorationSet.create(state.doc, decorations);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t];\n\t},\n});\n"],"names":["CLASS_BY_TYPE","lineNumberWidget","n","span","JsonHighlightExtension","Extension","Plugin","PluginKey","state","decorations","node","pos","text","base","tok","tokenizeJson","Decoration","line","i","DecorationSet"],"mappings":";;;;AAKA,MAAMA,IAA+C;AAAA,EACpD,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AAAA,EACN,aAAa;AACd;AAGA,SAASC,EAAiBC,GAAwB;AACjD,QAAMC,IAAO,SAAS,cAAc,MAAM;AAC1C,SAAAA,EAAK,YAAY,mBACjBA,EAAK,cAAc,OAAOD,CAAC,GAC3BC,EAAK,aAAa,mBAAmB,OAAO,GACrCA;AACR;AAcO,MAAMC,IAAyBC,EAAU,OAAO;AAAA,EACtD,MAAM;AAAA,EACN,wBAAwB;AACvB,WAAO;AAAA,MACN,IAAIC,EAAO;AAAA,QACV,KAAK,IAAIC,EAAU,eAAe;AAAA,QAClC,OAAO;AAAA,UACN,YAAYC,GAAO;AAClB,kBAAMC,IAA4B,CAAA;AAClC,mBAAAD,EAAM,IAAI,YAAY,CAACE,GAAMC,MAAQ;AACpC,kBAAID,EAAK,KAAK,SAAS,YAAa;AACpC,oBAAME,IAAOF,EAAK,aAEZG,IAAOF,IAAM;AAEnB,yBAAWG,KAAOC,EAAaH,CAAI;AAClC,gBAAAH,EAAY;AAAA,kBACXO,EAAW,OAAOH,IAAOC,EAAI,OAAOD,IAAOC,EAAI,KAAK;AAAA,oBACnD,OAAOd,EAAcc,EAAI,IAAI;AAAA,kBAAA,CAC7B;AAAA,gBAAA;AAOH,kBAAIG,IAAO;AACX,cAAAR,EAAY;AAAA,gBACXO,EAAW,OAAOH,GAAM,MAAMZ,EAAiB,CAAC,GAAG;AAAA,kBAClD,MAAM;AAAA,kBACN,KAAK;AAAA,gBAAA,CACL;AAAA,cAAA;AAEF,uBAASiB,IAAI,GAAGA,IAAIN,EAAK,QAAQM,KAAK;AACrC,oBAAIN,EAAKM,CAAC,MAAM;AAAA,EAAM;AACtB,gBAAAD,KAAQ;AACR,sBAAMf,IAAIe;AACV,gBAAAR,EAAY;AAAA,kBACXO,EAAW,OAAOH,IAAOK,IAAI,GAAG,MAAMjB,EAAiBC,CAAC,GAAG;AAAA,oBAC1D,MAAM;AAAA,oBACN,KAAK,MAAMA,CAAC;AAAA,kBAAA,CACZ;AAAA,gBAAA;AAAA,cAEH;AAAA,YACD,CAAC,GACMiB,EAAc,OAAOX,EAAM,KAAKC,CAAW;AAAA,UACnD;AAAA,QAAA;AAAA,MACD,CACA;AAAA,IAAA;AAAA,EAEH;AACD,CAAC;"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Minimal, dependency-free JSON tokenizer used for syntax highlighting.
3
+ *
4
+ * It is a LEXER, not a parser — it never rejects input. Given any string it
5
+ * returns the ranges it recognises as JSON tokens and leaves everything else
6
+ * (whitespace, malformed fragments) undecorated. This is exactly what a code
7
+ * editor wants: highlight the valid-looking parts even while the user is still
8
+ * typing invalid JSON.
9
+ *
10
+ * Offsets are 0-based indexes into `text`; `end` is exclusive.
11
+ */
12
+ export type JsonTokenType = 'key' | 'string' | 'number' | 'boolean' | 'null' | 'punctuation';
13
+ export interface JsonToken {
14
+ start: number;
15
+ end: number;
16
+ type: JsonTokenType;
17
+ }
18
+ export declare function tokenizeJson(text: string): JsonToken[];
@@ -0,0 +1,21 @@
1
+ const u = /("(?:\\.|[^"\\])*")|(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)|\b(true|false)\b|\bnull\b|([{}[\],:])/g;
2
+ function a(l, t) {
3
+ let e = t;
4
+ for (; /\s/.test(l.charAt(e)); ) e++;
5
+ return l.charAt(e) === ":";
6
+ }
7
+ function f(l) {
8
+ const t = [];
9
+ u.lastIndex = 0;
10
+ let e;
11
+ for (; (e = u.exec(l)) !== null; ) {
12
+ const [o, c, r, d] = e, s = e.index, i = s + o.length;
13
+ let n;
14
+ c !== void 0 ? n = a(l, i) ? "key" : "string" : r !== void 0 ? n = "number" : d !== void 0 ? n = "boolean" : o === "null" ? n = "null" : n = "punctuation", t.push({ start: s, end: i, type: n });
15
+ }
16
+ return t;
17
+ }
18
+ export {
19
+ f as tokenizeJson
20
+ };
21
+ //# sourceMappingURL=tokenizeJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokenizeJson.js","sources":["../../../../../src/editor/extensions/jsonHighlight/tokenizeJson.ts"],"sourcesContent":["/**\n * Minimal, dependency-free JSON tokenizer used for syntax highlighting.\n *\n * It is a LEXER, not a parser — it never rejects input. Given any string it\n * returns the ranges it recognises as JSON tokens and leaves everything else\n * (whitespace, malformed fragments) undecorated. This is exactly what a code\n * editor wants: highlight the valid-looking parts even while the user is still\n * typing invalid JSON.\n *\n * Offsets are 0-based indexes into `text`; `end` is exclusive.\n */\nexport type JsonTokenType =\n\t| 'key'\n\t| 'string'\n\t| 'number'\n\t| 'boolean'\n\t| 'null'\n\t| 'punctuation';\n\nexport interface JsonToken {\n\tstart: number;\n\tend: number;\n\ttype: JsonTokenType;\n}\n\n// One regex, alternation ordered so strings are matched before anything else.\n// Group 1 = string body (kept so we can peek past it for the `:` that marks a key).\nconst TOKEN_RE =\n\t/(\"(?:\\\\.|[^\"\\\\])*\")|(-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?)|\\b(true|false)\\b|\\bnull\\b|([{}[\\],:])/g;\n\n/** Returns true if the next non-whitespace char after `index` is a colon. */\nfunction isFollowedByColon(text: string, index: number): boolean {\n\tlet i = index;\n\t// charAt returns '' past the end, so the loop terminates without bounds checks.\n\twhile (/\\s/.test(text.charAt(i))) i++;\n\treturn text.charAt(i) === ':';\n}\n\nexport function tokenizeJson(text: string): JsonToken[] {\n\tconst tokens: JsonToken[] = [];\n\tTOKEN_RE.lastIndex = 0;\n\tlet match: RegExpExecArray | null;\n\twhile ((match = TOKEN_RE.exec(text)) !== null) {\n\t\tconst [full, str, num, bool] = match;\n\t\tconst start = match.index;\n\t\tconst end = start + full.length;\n\t\tlet type: JsonTokenType;\n\t\tif (str !== undefined) {\n\t\t\t// A string is a KEY when the next meaningful char is `:` (object member).\n\t\t\ttype = isFollowedByColon(text, end) ? 'key' : 'string';\n\t\t} else if (num !== undefined) {\n\t\t\ttype = 'number';\n\t\t} else if (bool !== undefined) {\n\t\t\ttype = 'boolean';\n\t\t} else if (full === 'null') {\n\t\t\ttype = 'null';\n\t\t} else {\n\t\t\ttype = 'punctuation';\n\t\t}\n\t\ttokens.push({ start, end, type });\n\t}\n\treturn tokens;\n}\n"],"names":["TOKEN_RE","isFollowedByColon","text","index","i","tokenizeJson","tokens","match","full","str","num","bool","start","end","type"],"mappings":"AA2BA,MAAMA,IACL;AAGD,SAASC,EAAkBC,GAAcC,GAAwB;AAChE,MAAIC,IAAID;AAER,SAAO,KAAK,KAAKD,EAAK,OAAOE,CAAC,CAAC,IAAG,CAAAA;AAClC,SAAOF,EAAK,OAAOE,CAAC,MAAM;AAC3B;AAEO,SAASC,EAAaH,GAA2B;AACvD,QAAMI,IAAsB,CAAA;AAC5B,EAAAN,EAAS,YAAY;AACrB,MAAIO;AACJ,UAAQA,IAAQP,EAAS,KAAKE,CAAI,OAAO,QAAM;AAC9C,UAAM,CAACM,GAAMC,GAAKC,GAAKC,CAAI,IAAIJ,GACzBK,IAAQL,EAAM,OACdM,IAAMD,IAAQJ,EAAK;AACzB,QAAIM;AACJ,IAAIL,MAAQ,SAEXK,IAAOb,EAAkBC,GAAMW,CAAG,IAAI,QAAQ,WACpCH,MAAQ,SAClBI,IAAO,WACGH,MAAS,SACnBG,IAAO,YACGN,MAAS,SACnBM,IAAO,SAEPA,IAAO,eAERR,EAAO,KAAK,EAAE,OAAAM,GAAO,KAAAC,GAAK,MAAAC,GAAM;AAAA,EACjC;AACA,SAAOR;AACR;"}
@@ -3,5 +3,5 @@ export { BikEditorToolbar } from './toolbar/BikEditorToolbar';
3
3
  export { getBodyHtml, getSectionsHtml } from './BikEditor.utils';
4
4
  export { toWhatsAppText } from './serializers/toWhatsAppText';
5
5
  export { toLiveChatText } from './serializers/toLiveChatText';
6
- export type { BikEditorProps, BikEditorRef, EditorSnapshot as BikEditorContent, EditorFeatures, EditorSection, MentionConfig, MentionDropdownRenderProps, SlashCommandConfig, SlashCommandDropdownRenderProps, LinkConfig, KeyboardShortcut, PasteData, MentionItem, SlashCommandItem, LinkTooltipProps, FormatState as ActiveFormats, EditorActions, } from './BikEditor.types';
6
+ export type { BikEditorProps, BikEditorRef, EditorSnapshot as BikEditorContent, EditorFeatures, EditorSection, MentionConfig, MentionDropdownRenderProps, SlashCommandConfig, SlashCommandDropdownRenderProps, LinkConfig, KeyboardShortcut, PasteData, MentionItem, SlashCommandItem, LinkTooltipProps, JsonBodyApi, JsonParseResult, FormatState as ActiveFormats, EditorActions, } from './BikEditor.types';
7
7
  export { DEFAULT_FORMAT_STATE as DEFAULT_ACTIVE_FORMATS } from './BikEditor.types';
@@ -0,0 +1,7 @@
1
+ import { SVGProps } from 'react';
2
+ interface Props extends SVGProps<SVGSVGElement> {
3
+ size?: number | string;
4
+ color?: string;
5
+ }
6
+ declare const SvgWandSparkles: ({ size, color, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
7
+ export default SvgWandSparkles;