@bikdotai/bik-component-library 0.0.804-beta.12 → 0.0.804-beta.14

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.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("../node_modules/prosemirror-model/dist/index.js");function e(t){return t.replace(/<p>\s*<br\s*\/?>\s*<\/p>/gi,"<p></p>").replace(/<\/?span[^>]*>/gi,"")}const n=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function i(t){var e;if(!t)return"";return null!==(e=r(t).get("body"))&&void 0!==e?e:t}function r(t){const e=new Map,n=/<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g,i=[];let r;for(;null!==(r=n.exec(t));)i.push({id:r[1],index:r.index,endIndex:r.index+r[0].length});if(0===i.length)return e.set("body",t),e;e.set("body",t.slice(0,i[0].index));for(let n=0;n<i.length;n++){const r=i[n].endIndex,o=n+1<i.length?i[n+1].index:t.length;e.set(i[n].id,t.slice(r,o))}return e}function o(e,n){var i;const r=s(e,n);if(-1===r)return{html:"",text:"",isEmpty:!0,characterCount:0};const o=c(e,n),l=e.state.doc.slice(r,o),d=document.createElement("div"),u=t.DOMSerializer.fromSchema(e.schema);d.appendChild(u.serializeFragment(l.content));const a=d.innerHTML,f=null!==(i=d.textContent)&&void 0!==i?i:"";return{html:a,text:f,isEmpty:!f.trim(),characterCount:f.length}}function s(t,e){if("body"===e)return 1;let n=-1;return t.state.doc.descendants(((t,i)=>{if(-1!==n)return!1;"sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(n=i+t.nodeSize)})),n}function c(t,e){const n=t.state.doc,i=n.content.size;if("body"===e){let t=-1;return n.descendants(((e,n)=>{if(-1!==t)return!1;"sectionDivider"===e.type.name&&(t=n)})),-1!==t?t:i}let r=!1,o=-1;return n.descendants(((t,n)=>-1===o&&(r?void("sectionDivider"===t.type.name&&(o=n)):("sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(r=!0),!1)))),-1!==o?o:i}exports.SECTION_DIVIDER_HTML=n,exports.buildSectionedContent=function(t,e){let i=t;for(const t of e)i+=n(t.id)+t.content;return i},exports.extractActiveFormats=function(t){var e,n,i,r;return{bold:t.isActive("bold"),italic:t.isActive("italic"),underline:t.isActive("underline"),strike:t.isActive("strike"),bulletList:t.isActive("bulletList"),orderedList:t.isActive("orderedList"),blockquote:t.isActive("blockquote"),codeBlock:t.isActive("codeBlock"),link:(()=>{var e,n,i;if(t.isActive("link"))return{href:null!==(e=t.getAttributes("link").href)&&void 0!==e?e:""};const{$from:r}=t.state.selection;if(r.pos>0){const t=r.doc.resolve(r.pos).marks().find((t=>"link"===t.type.name));if(t)return{href:null!==(i=t.attrs.href)&&void 0!==i?i:""};{const t=r.nodeBefore,e=null==t?void 0:t.marks.find((t=>"link"===t.type.name));if(e)return{href:null!==(n=e.attrs.href)&&void 0!==n?n:""}}}return null})(),textAlign:t.isActive({textAlign:"center"})?"center":t.isActive({textAlign:"right"})?"right":t.isActive({textAlign:"justify"})?"justify":t.isActive({textAlign:"left"})?"left":null,fontFamily:null!==(e=t.getAttributes("textStyle").fontFamily)&&void 0!==e?e:null,fontSize:null!==(n=t.getAttributes("textStyle").fontSize)&&void 0!==n?n:null,color:null!==(i=t.getAttributes("textStyle").color)&&void 0!==i?i:null,highlight:t.isActive("highlight")?null!==(r=t.getAttributes("highlight").color)&&void 0!==r?r:"default":null,superscript:t.isActive("superscript"),subscript:t.isActive("subscript")}},exports.extractAllSectionsFromHtml=r,exports.extractBodyContent=function(t){return o(t,"body")},exports.extractContent=function(t){var e,n,i;return{html:t.getHTML(),text:t.getText(),isEmpty:t.isEmpty,characterCount:null!==(i=null===(n=null===(e=t.storage.characterCount)||void 0===e?void 0:e.characters)||void 0===n?void 0:n.call(e))&&void 0!==i?i:t.getText().length}},exports.extractSectionContent=o,exports.findSectionEndPos=c,exports.findSectionStartPos=s,exports.getBodyHtml=i,exports.getSectionsHtml=function(t){if(!t)return"";const e=i(t);return t.substring(e.length)},exports.insertInlineHtml=function(n,i){const r=e(i),o=n.schema,s=document.createElement("div");s.innerHTML=r;const c=t.DOMParser.fromSchema(o).parse(s),l=[];if(c.content.forEach((e=>{e.isTextblock?e.content.size>0&&l.push(e.content):(e.isInline||e.isText)&&l.push(t.Fragment.from(e))})),0===l.length)return;let d=t.Fragment.empty;for(const t of l)d=d.append(t);const{from:u,to:a}=n.state.selection,f=new t.Slice(d,0,0),p=n.state.tr.replaceRange(u,a,f);n.view.dispatch(p)},exports.normalizeHtml=e,exports.setSectionContentInEditor=function(e,i,r){const o=s(e,i);if(-1===o){const t=e.state.doc.content.size,o=n(i)+r;return void e.commands.insertContentAt(t,o,{updateSelection:!1})}const l=c(e,i),d=function(e,n){const i=document.createElement("div");return i.innerHTML=n,t.DOMParser.fromSchema(e.schema).parse(i).content}(e,r),{tr:u}=e.state,a="body"===i?0:o;u.replaceWith(a,l,d),u.setMeta("addToHistory",!1),e.view.dispatch(u)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("../node_modules/prosemirror-model/dist/index.js");function e(t){return t.replace(/<p>\s*<br\s*\/?>\s*<\/p>/gi,"<p></p>").replace(/<\/?span[^>]*>/gi,"")}const n=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function i(t){var e;if(!t)return"";return null!==(e=r(t).get("body"))&&void 0!==e?e:t}function r(t){const e=new Map,n=/<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g,i=[];let r;for(;null!==(r=n.exec(t));)i.push({id:r[1],index:r.index,endIndex:r.index+r[0].length});if(0===i.length)return e.set("body",t),e;e.set("body",t.slice(0,i[0].index));for(let n=0;n<i.length;n++){const r=i[n].endIndex,o=n+1<i.length?i[n+1].index:t.length;e.set(i[n].id,t.slice(r,o))}return e}function o(e,n){var i;const r=s(e,n);if(-1===r)return{html:"",text:"",isEmpty:!0,characterCount:0};const o=c(e,n),l=e.state.doc.slice(r,o),d=document.createElement("div"),u=t.DOMSerializer.fromSchema(e.schema);d.appendChild(u.serializeFragment(l.content));const a=d.innerHTML,f=null!==(i=d.textContent)&&void 0!==i?i:"";return{html:a,text:f,isEmpty:!f.trim(),characterCount:f.length}}function s(t,e){if("body"===e)return 1;let n=-1;return t.state.doc.descendants(((t,i)=>{if(-1!==n)return!1;"sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(n=i+t.nodeSize)})),n}function c(t,e){const n=t.state.doc,i=n.content.size;if("body"===e){let t=-1;return n.descendants(((e,n)=>{if(-1!==t)return!1;"sectionDivider"===e.type.name&&(t=n)})),-1!==t?t:i}let r=!1,o=-1;return n.descendants(((t,n)=>-1===o&&(r?void("sectionDivider"===t.type.name&&(o=n)):("sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(r=!0),!1)))),-1!==o?o:i}exports.SECTION_DIVIDER_HTML=n,exports.buildSectionedContent=function(t,e){let i=t;for(const t of e)i+=n(t.id)+t.content;return i},exports.extractActiveFormats=function(t){var e,n,i,r;return{bold:t.isActive("bold"),italic:t.isActive("italic"),underline:t.isActive("underline"),strike:t.isActive("strike"),bulletList:t.isActive("bulletList"),orderedList:t.isActive("orderedList"),blockquote:t.isActive("blockquote"),codeBlock:t.isActive("codeBlock"),link:(()=>{var e,n,i;if(t.isActive("link"))return{href:null!==(e=t.getAttributes("link").href)&&void 0!==e?e:""};const{$from:r}=t.state.selection;if(r.pos>0){const t=r.doc.resolve(r.pos).marks().find((t=>"link"===t.type.name));if(t)return{href:null!==(i=t.attrs.href)&&void 0!==i?i:""};{const t=r.nodeBefore,e=null==t?void 0:t.marks.find((t=>"link"===t.type.name));if(e)return{href:null!==(n=e.attrs.href)&&void 0!==n?n:""}}}return null})(),textAlign:t.isActive({textAlign:"center"})?"center":t.isActive({textAlign:"right"})?"right":t.isActive({textAlign:"justify"})?"justify":t.isActive({textAlign:"left"})?"left":null,fontFamily:null!==(e=t.getAttributes("textStyle").fontFamily)&&void 0!==e?e:null,fontSize:null!==(n=t.getAttributes("textStyle").fontSize)&&void 0!==n?n:null,color:null!==(i=t.getAttributes("textStyle").color)&&void 0!==i?i:null,highlight:t.isActive("highlight")?null!==(r=t.getAttributes("highlight").color)&&void 0!==r?r:"default":null,superscript:t.isActive("superscript"),subscript:t.isActive("subscript")}},exports.extractAllSectionsFromHtml=r,exports.extractBodyContent=function(t){return o(t,"body")},exports.extractContent=function(t){var e,n,i;return{html:t.getHTML(),text:t.getText(),isEmpty:t.isEmpty,characterCount:null!==(i=null===(n=null===(e=t.storage.characterCount)||void 0===e?void 0:e.characters)||void 0===n?void 0:n.call(e))&&void 0!==i?i:t.getText().length}},exports.extractSectionContent=o,exports.findSectionEndPos=c,exports.findSectionStartPos=s,exports.getBodyHtml=i,exports.getSectionsHtml=function(t){if(!t)return"";const e=i(t);return t.substring(e.length)},exports.insertInlineHtml=function(n,i){const r=e(i),o=document.createElement("div");o.innerHTML=r;const s=t.DOMParser.fromSchema(n.schema).parseSlice(o);if(0===s.size)return;const{from:c,to:l}=n.state.selection,d=n.state.tr.replaceRange(c,l,s);n.view.dispatch(d)},exports.normalizeHtml=e,exports.setSectionContentInEditor=function(e,i,r){const o=s(e,i);if(-1===o){const t=e.state.doc.content.size,o=n(i)+r;return void e.commands.insertContentAt(t,o,{updateSelection:!1})}const l=c(e,i),d=function(e,n){const i=document.createElement("div");return i.innerHTML=n,t.DOMParser.fromSchema(e.schema).parse(i).content}(e,r),{tr:u}=e.state,a="body"===i?0:o;u.replaceWith(a,l,d),u.setMeta("addToHistory",!1),e.view.dispatch(u)};
2
2
  //# sourceMappingURL=BikEditor.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BikEditor.utils.js","sources":["../../../src/editor/BikEditor.utils.ts"],"sourcesContent":["import { Editor } from '@tiptap/core';\nimport { DOMParser, DOMSerializer, Fragment, Slice } from 'prosemirror-model';\nimport { EditorSnapshot, FormatState } from './BikEditor.types';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * Problem: Quill uses `<p><br></p>` as a blank-line separator. TipTap's\n * HardBreak extension parses that `<br>` as a real `hard_break` node.\n * ProseMirror then also appends `<br class=\"ProseMirror-trailingBreak\">` as a\n * cursor-position decoration, making the empty paragraph render at **2× line\n * height** instead of 1×.\n *\n * Fix: replace `<p><br></p>` → `<p></p>` so TipTap stores a truly empty\n * paragraph. ProseMirror adds only the trailing decoration, giving the correct\n * 1× line height. The WA text output is unchanged (`\\n` either way after\n * surrounding-newline collapse in `toWhatsAppText`).\n */\nexport function normalizeHtml(html: string): string {\n\treturn html\n\t\t.replace(/<p>\\s*<br\\s*\\/?>\\s*<\\/p>/gi, '<p></p>')\n\t\t.replace(/<\\/?span[^>]*>/gi, '');\n}\n\n// ---------------------------------------------------------------------------\n// Inline content insertion\n// ---------------------------------------------------------------------------\n\n/**\n * Insert HTML at the current cursor position as inline content.\n * Parses the HTML into ProseMirror nodes, collects only the inline children\n * (unwrapping block wrappers like <p>), and replaces the current selection\n * with an open Slice so the content merges into the surrounding paragraph.\n */\nexport function insertInlineHtml(editor: Editor, html: string): void {\n\tconst normalised = normalizeHtml(html);\n\tconst schema = editor.schema;\n\tconst dom = document.createElement('div');\n\tdom.innerHTML = normalised;\n\tconst parsed = DOMParser.fromSchema(schema).parse(dom);\n\n\tconst inlineFragments: Fragment[] = [];\n\tparsed.content.forEach((node) => {\n\t\tif (node.isTextblock) {\n\t\t\tif (node.content.size > 0) inlineFragments.push(node.content);\n\t\t} else if (node.isInline || node.isText) {\n\t\t\tinlineFragments.push(Fragment.from(node));\n\t\t}\n\t});\n\n\tif (inlineFragments.length === 0) return;\n\n\tlet combined = Fragment.empty;\n\tfor (const frag of inlineFragments) {\n\t\tcombined = combined.append(frag);\n\t}\n\n\tconst { from, to } = editor.state.selection;\n\tconst slice = new Slice(combined, 0, 0);\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 = 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).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\treturn {\n\t\thtml: editor.getHTML(),\n\t\ttext: editor.getText(),\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount:\n\t\t\teditor.storage.characterCount?.characters?.() ?? editor.getText().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","replace","SECTION_DIVIDER_HTML","id","getBodyHtml","_a","extractAllSectionsFromHtml","get","sections","Map","dividerRegex","dividers","match","exec","push","index","endIndex","length","set","slice","i","start","end","extractSectionContent","editor","startPos","findSectionStartPos","text","isEmpty","characterCount","endPos","findSectionEndPos","state","doc","container","document","createElement","serializer","DOMSerializer","fromSchema","schema","appendChild","serializeFragment","content","innerHTML","textContent","trim","sectionId","descendants","node","pos","type","name","attrs","nodeSize","docSize","size","firstDividerPos","passedSection","nextDividerPos","body","s","bold","isActive","italic","underline","strike","bulletList","orderedList","blockquote","codeBlock","link","href","getAttributes","$from","selection","linkMark","resolve","marks","find","m","_c","nodeBefore","markOnPrev","_b","textAlign","fontFamily","fontSize","color","highlight","_d","superscript","subscript","getHTML","getText","storage","characters","substring","normalised","dom","parsed","DOMParser","parse","inlineFragments","forEach","isTextblock","isInline","isText","Fragment","from","combined","empty","frag","append","to","Slice","tr","replaceRange","view","dispatch","dividerHtml","commands","insertContentAt","updateSelection","fragment","parseHtmlToNodes","replaceFrom","replaceWith","setMeta"],"mappings":"qIAsBM,SAAUA,EAAcC,GAC7B,OAAOA,EACLC,QAAQ,6BAA8B,WACtCA,QAAQ,mBAAoB,GAC/B,OA6CaC,EAAwBC,GACpC,8BAA8BA,yEAyCzB,SAAUC,EAAYJ,SAC3B,IAAKA,EAAM,MAAO,GAElB,OAA+B,QAAxBK,EADUC,EAA2BN,GAC5BO,IAAI,eAAW,IAAAF,EAAAA,EAAAL,CAChC,CAYM,SAAUM,EAA2BN,GAC1C,MAAMQ,EAAW,IAAIC,IACfC,EACL,0DACKC,EAAmE,GAEzE,IAAIC,EACJ,KAA6C,QAArCA,EAAQF,EAAaG,KAAKb,KACjCW,EAASG,KAAK,CACbX,GAAIS,EAAM,GACVG,MAAOH,EAAMG,MACbC,SAAUJ,EAAMG,MAAQH,EAAM,GAAGK,SAInC,GAAwB,IAApBN,EAASM,OAEZ,OADAT,EAASU,IAAI,OAAQlB,GACdQ,EAGRA,EAASU,IAAI,OAAQlB,EAAKmB,MAAM,EAAGR,EAAS,GAAGI,QAC/C,IAAK,IAAIK,EAAI,EAAGA,EAAIT,EAASM,OAAQG,IAAK,CACzC,MAAMC,EAAQV,EAASS,GAAGJ,SACpBM,EAAMF,EAAI,EAAIT,EAASM,OAASN,EAASS,EAAI,GAAGL,MAAQf,EAAKiB,OACnET,EAASU,IAAIP,EAASS,GAAGjB,GAAIH,EAAKmB,MAAME,EAAOC,GAC/C,CAED,OAAOd,CAC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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';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * Problem: Quill uses `<p><br></p>` as a blank-line separator. TipTap's\n * HardBreak extension parses that `<br>` as a real `hard_break` node.\n * ProseMirror then also appends `<br class=\"ProseMirror-trailingBreak\">` as a\n * cursor-position decoration, making the empty paragraph render at **2× line\n * height** instead of 1×.\n *\n * Fix: replace `<p><br></p>` → `<p></p>` so TipTap stores a truly empty\n * paragraph. ProseMirror adds only the trailing decoration, giving the correct\n * 1× line height. The WA text output is unchanged (`\\n` either way after\n * surrounding-newline collapse in `toWhatsAppText`).\n */\nexport function normalizeHtml(html: string): string {\n\treturn html\n\t\t.replace(/<p>\\s*<br\\s*\\/?>\\s*<\\/p>/gi, '<p></p>')\n\t\t.replace(/<\\/?span[^>]*>/gi, '');\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\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 = 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).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\treturn {\n\t\thtml: editor.getHTML(),\n\t\ttext: editor.getText(),\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount:\n\t\t\teditor.storage.characterCount?.characters?.() ?? editor.getText().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","replace","SECTION_DIVIDER_HTML","id","getBodyHtml","_a","extractAllSectionsFromHtml","get","sections","Map","dividerRegex","dividers","match","exec","push","index","endIndex","length","set","slice","i","start","end","extractSectionContent","editor","startPos","findSectionStartPos","text","isEmpty","characterCount","endPos","findSectionEndPos","state","doc","container","document","createElement","serializer","DOMSerializer","fromSchema","schema","appendChild","serializeFragment","content","innerHTML","textContent","trim","sectionId","descendants","node","pos","type","name","attrs","nodeSize","docSize","size","firstDividerPos","passedSection","nextDividerPos","body","s","bold","isActive","italic","underline","strike","bulletList","orderedList","blockquote","codeBlock","link","href","getAttributes","$from","selection","linkMark","resolve","marks","find","m","_c","nodeBefore","markOnPrev","_b","textAlign","fontFamily","fontSize","color","highlight","_d","superscript","subscript","getHTML","getText","storage","characters","substring","normalised","dom","DOMParser","parseSlice","from","to","tr","replaceRange","view","dispatch","dividerHtml","commands","insertContentAt","updateSelection","fragment","parse","parseHtmlToNodes","replaceFrom","replaceWith","setMeta"],"mappings":"qIAsBM,SAAUA,EAAcC,GAC7B,OAAOA,EACLC,QAAQ,6BAA8B,WACtCA,QAAQ,mBAAoB,GAC/B,OA+BaC,EAAwBC,GACpC,8BAA8BA,yEAyCzB,SAAUC,EAAYJ,SAC3B,IAAKA,EAAM,MAAO,GAElB,OAA+B,QAAxBK,EADUC,EAA2BN,GAC5BO,IAAI,eAAW,IAAAF,EAAAA,EAAAL,CAChC,CAYM,SAAUM,EAA2BN,GAC1C,MAAMQ,EAAW,IAAIC,IACfC,EACL,0DACKC,EAAmE,GAEzE,IAAIC,EACJ,KAA6C,QAArCA,EAAQF,EAAaG,KAAKb,KACjCW,EAASG,KAAK,CACbX,GAAIS,EAAM,GACVG,MAAOH,EAAMG,MACbC,SAAUJ,EAAMG,MAAQH,EAAM,GAAGK,SAInC,GAAwB,IAApBN,EAASM,OAEZ,OADAT,EAASU,IAAI,OAAQlB,GACdQ,EAGRA,EAASU,IAAI,OAAQlB,EAAKmB,MAAM,EAAGR,EAAS,GAAGI,QAC/C,IAAK,IAAIK,EAAI,EAAGA,EAAIT,EAASM,OAAQG,IAAK,CACzC,MAAMC,EAAQV,EAASS,GAAGJ,SACpBM,EAAMF,EAAI,EAAIT,EAASM,OAASN,EAASS,EAAI,GAAGL,MAAQf,EAAKiB,OACnET,EAASU,IAAIP,EAASS,GAAGjB,GAAIH,EAAKmB,MAAME,EAAOC,GAC/C,CAED,OAAOd,CACR,CAGgB,SAAAe,EACfC,EACArB,SAEA,MAAMsB,EAAWC,EAAoBF,EAAQrB,GAC7C,IAAkB,IAAdsB,EACH,MAAO,CAAEzB,KAAM,GAAI2B,KAAM,GAAIC,SAAS,EAAMC,eAAgB,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IpF,GAClDK,EAAOkF,KAAKC,SAASH,EACtB,qEAgIChF,EACArB,EACAH,GAEA,MAAMyB,EAAWC,EAAoBF,EAAQrB,GAC7C,IAAkB,IAAdsB,EAAiB,CACpB,MAAMK,EAASN,EAAOQ,MAAMC,IAAIU,QAAQa,KAClCoD,EAAc1G,EAAqBC,GAAMH,EAI/C,YAHAwB,EAAOqF,SAASC,gBAAgBhF,EAAQ8E,EAAa,CACpDG,iBAAiB,GAGlB,CACD,MAAMjF,EAASC,EAAkBP,EAAQrB,GACnC6G,EA3BP,SAA0BxF,EAAgBxB,GACzC,MAAMkC,EAAYC,SAASC,cAAc,OAEzC,OADAF,EAAUU,UAAY5C,EACfoG,EAASA,UAAC7D,WAAWf,EAAOgB,QAAQyE,MAAM/E,GAAWS,OAC7D,CAuBkBuE,CAAiB1F,EAAQxB,IACpCwG,GAAEA,GAAOhF,EAAOQ,MAKhBmF,EAAqB,SAAPhH,EAAgB,EAAIsB,EACxC+E,EAAGY,YAAYD,EAAarF,EAAQkF,GACpCR,EAAGa,QAAQ,gBAAgB,GAC3B7F,EAAOkF,KAAKC,SAASH,EACtB"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.createSuggestionPopup=function(e,t){const o=document.createElement("div");function n(e){const t=null==e?void 0:e();if(!t)return;const n=o.offsetHeight,i=o.offsetWidth,s=window.innerHeight,d=window.innerWidth,p=s-t.bottom-4,l=t.top-4,r=p>=n?t.bottom+4:l>=n?t.top-4-n:4,u=Math.min(t.left,d-i-4);o.style.left=`${Math.max(4,u)}px`,o.style.top=`${r}px`}return o.style.cssText="position:fixed;z-index:9999;pointer-events:auto;",o.appendChild(e),document.body.appendChild(o),n(t),{element:o,show(){o.style.display=""},hide(){o.style.display="none"},destroy(){o.remove()},updatePosition(e){n(e)}}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.createSuggestionPopup=function(e,t){const o=document.createElement("div");o.style.cssText="position:fixed;z-index:9999;pointer-events:auto;",o.appendChild(e),document.body.appendChild(o);let n=t;function i(){const e=null==n?void 0:n();if(!e)return;const t=o.offsetHeight,i=o.offsetWidth,s=window.innerHeight,d=window.innerWidth,p=s-e.bottom-4,r=e.top-4,l=p>=t?e.bottom+4:r>=t?e.top-4-t:4,c=Math.min(e.left,d-i-4);o.style.left=`${Math.max(4,c)}px`,o.style.top=`${l}px`}const s=new ResizeObserver(i);return s.observe(o),i(),{element:o,show(){o.style.display=""},hide(){o.style.display="none"},destroy(){s.disconnect(),o.remove()},updatePosition(e){n=e,i()}}};
2
2
  //# sourceMappingURL=suggestionPopup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"suggestionPopup.js","sources":["../../../../src/editor/extensions/suggestionPopup.ts"],"sourcesContent":["/**\n * Lightweight popup positioner for suggestion dropdowns (mentions, slash commands).\n * Replaces tippy.js — all we need is a positioned container near the cursor\n * that flips above when there isn't enough room below.\n */\n\nconst GAP = 4;\n\nexport interface SuggestionPopup {\n\tshow(): void;\n\thide(): void;\n\tdestroy(): void;\n\tupdatePosition(clientRect: () => DOMRect | null): void;\n\treadonly element: HTMLDivElement;\n}\n\nexport function createSuggestionPopup(\n\tcontent: HTMLElement,\n\tclientRect: (() => DOMRect | null) | null,\n): SuggestionPopup {\n\tconst wrapper = document.createElement('div');\n\twrapper.style.cssText = 'position:fixed;z-index:9999;pointer-events:auto;';\n\twrapper.appendChild(content);\n\tdocument.body.appendChild(wrapper);\n\n\tfunction reposition(getRectFn: (() => DOMRect | null) | null) {\n\t\tconst rect = getRectFn?.();\n\t\tif (!rect) return;\n\n\t\tconst popupHeight = wrapper.offsetHeight;\n\t\tconst popupWidth = wrapper.offsetWidth;\n\t\tconst viewportH = window.innerHeight;\n\t\tconst viewportW = window.innerWidth;\n\n\t\tconst spaceBelow = viewportH - rect.bottom - GAP;\n\t\tconst spaceAbove = rect.top - GAP;\n\t\tconst fitsBelow = spaceBelow >= popupHeight;\n\n\t\tconst top = fitsBelow\n\t\t\t? rect.bottom + GAP\n\t\t\t: spaceAbove >= popupHeight\n\t\t\t? rect.top - GAP - popupHeight\n\t\t\t: GAP;\n\n\t\tconst left = Math.min(rect.left, viewportW - popupWidth - GAP);\n\n\t\twrapper.style.left = `${Math.max(GAP, left)}px`;\n\t\twrapper.style.top = `${top}px`;\n\t}\n\n\treposition(clientRect);\n\n\treturn {\n\t\telement: wrapper,\n\t\tshow() {\n\t\t\twrapper.style.display = '';\n\t\t},\n\t\thide() {\n\t\t\twrapper.style.display = 'none';\n\t\t},\n\t\tdestroy() {\n\t\t\twrapper.remove();\n\t\t},\n\t\tupdatePosition(getRectFn: () => DOMRect | null) {\n\t\t\treposition(getRectFn);\n\t\t},\n\t};\n}\n"],"names":["content","clientRect","wrapper","document","createElement","reposition","getRectFn","rect","popupHeight","offsetHeight","popupWidth","offsetWidth","viewportH","window","innerHeight","viewportW","innerWidth","spaceBelow","bottom","spaceAbove","top","left","Math","min","style","max","cssText","appendChild","body","element","show","display","hide","destroy","remove","updatePosition"],"mappings":"kGAgBgB,SACfA,EACAC,GAEA,MAAMC,EAAUC,SAASC,cAAc,OAKvC,SAASC,EAAWC,GACnB,MAAMC,EAAOD,aAAA,EAAAA,IACb,IAAKC,EAAM,OAEX,MAAMC,EAAcN,EAAQO,aACtBC,EAAaR,EAAQS,YACrBC,EAAYC,OAAOC,YACnBC,EAAYF,OAAOG,WAEnBC,EAAaL,EAAYL,EAAKW,OA5B1B,EA6BJC,EAAaZ,EAAKa,IA7Bd,EAgCJA,EAFYH,GAAcT,EAG7BD,EAAKW,OAjCE,EAkCPC,GAAcX,EACdD,EAAKa,IAnCE,EAmCUZ,EAnCV,EAsCJa,EAAOC,KAAKC,IAAIhB,EAAKc,KAAMN,EAAYL,EAtCnC,GAwCVR,EAAQsB,MAAMH,KAAU,GAAAC,KAAKG,IAxCnB,EAwC4BJ,OACtCnB,EAAQsB,MAAMJ,IAAS,GAAAA,KACxB,CAIA,OA/BAlB,EAAQsB,MAAME,QAAU,mDACxBxB,EAAQyB,YAAY3B,GACpBG,SAASyB,KAAKD,YAAYzB,GA2B1BG,EAAWJ,GAEJ,CACN4B,QAAS3B,EACT4B,OACC5B,EAAQsB,MAAMO,QAAU,EACxB,EACDC,OACC9B,EAAQsB,MAAMO,QAAU,MACxB,EACDE,UACC/B,EAAQgC,QACR,EACDC,eAAe7B,GACdD,EAAWC,EACZ,EAEF"}
1
+ {"version":3,"file":"suggestionPopup.js","sources":["../../../../src/editor/extensions/suggestionPopup.ts"],"sourcesContent":["/**\n * Lightweight popup positioner for suggestion dropdowns (mentions, slash commands).\n * Replaces tippy.js — all we need is a positioned container near the cursor\n * that flips above when there isn't enough room below.\n */\n\nconst GAP = 4;\n\nexport interface SuggestionPopup {\n\tshow(): void;\n\thide(): void;\n\tdestroy(): void;\n\tupdatePosition(clientRect: () => DOMRect | null): void;\n\treadonly element: HTMLDivElement;\n}\n\nexport function createSuggestionPopup(\n\tcontent: HTMLElement,\n\tclientRect: (() => DOMRect | null) | null,\n): SuggestionPopup {\n\tconst wrapper = document.createElement('div');\n\twrapper.style.cssText = 'position:fixed;z-index:9999;pointer-events:auto;';\n\twrapper.appendChild(content);\n\tdocument.body.appendChild(wrapper);\n\n\tlet latestRectFn: (() => DOMRect | null) | null = clientRect;\n\n\tfunction reposition() {\n\t\tconst rect = latestRectFn?.();\n\t\tif (!rect) return;\n\n\t\tconst popupHeight = wrapper.offsetHeight;\n\t\tconst popupWidth = wrapper.offsetWidth;\n\t\tconst viewportH = window.innerHeight;\n\t\tconst viewportW = window.innerWidth;\n\n\t\tconst spaceBelow = viewportH - rect.bottom - GAP;\n\t\tconst spaceAbove = rect.top - GAP;\n\t\tconst fitsBelow = spaceBelow >= popupHeight;\n\n\t\tconst top = fitsBelow\n\t\t\t? rect.bottom + GAP\n\t\t\t: spaceAbove >= popupHeight\n\t\t\t? rect.top - GAP - popupHeight\n\t\t\t: GAP;\n\n\t\tconst left = Math.min(rect.left, viewportW - popupWidth - GAP);\n\n\t\twrapper.style.left = `${Math.max(GAP, left)}px`;\n\t\twrapper.style.top = `${top}px`;\n\t}\n\n\tconst observer = new ResizeObserver(reposition);\n\tobserver.observe(wrapper);\n\n\treposition();\n\n\treturn {\n\t\telement: wrapper,\n\t\tshow() {\n\t\t\twrapper.style.display = '';\n\t\t},\n\t\thide() {\n\t\t\twrapper.style.display = 'none';\n\t\t},\n\t\tdestroy() {\n\t\t\tobserver.disconnect();\n\t\t\twrapper.remove();\n\t\t},\n\t\tupdatePosition(getRectFn: () => DOMRect | null) {\n\t\t\tlatestRectFn = getRectFn;\n\t\t\treposition();\n\t\t},\n\t};\n}\n"],"names":["content","clientRect","wrapper","document","createElement","style","cssText","appendChild","body","latestRectFn","reposition","rect","popupHeight","offsetHeight","popupWidth","offsetWidth","viewportH","window","innerHeight","viewportW","innerWidth","spaceBelow","bottom","spaceAbove","top","left","Math","min","max","observer","ResizeObserver","observe","element","show","display","hide","destroy","disconnect","remove","updatePosition","getRectFn"],"mappings":"kGAgBgB,SACfA,EACAC,GAEA,MAAMC,EAAUC,SAASC,cAAc,OACvCF,EAAQG,MAAMC,QAAU,mDACxBJ,EAAQK,YAAYP,GACpBG,SAASK,KAAKD,YAAYL,GAE1B,IAAIO,EAA8CR,EAElD,SAASS,IACR,MAAMC,EAAOF,aAAA,EAAAA,IACb,IAAKE,EAAM,OAEX,MAAMC,EAAcV,EAAQW,aACtBC,EAAaZ,EAAQa,YACrBC,EAAYC,OAAOC,YACnBC,EAAYF,OAAOG,WAEnBC,EAAaL,EAAYL,EAAKW,OA9B1B,EA+BJC,EAAaZ,EAAKa,IA/Bd,EAkCJA,EAFYH,GAAcT,EAG7BD,EAAKW,OAnCE,EAoCPC,GAAcX,EACdD,EAAKa,IArCE,EAqCUZ,EArCV,EAwCJa,EAAOC,KAAKC,IAAIhB,EAAKc,KAAMN,EAAYL,EAxCnC,GA0CVZ,EAAQG,MAAMoB,KAAU,GAAAC,KAAKE,IA1CnB,EA0C4BH,OACtCvB,EAAQG,MAAMmB,IAAS,GAAAA,KACxB,CAEA,MAAMK,EAAW,IAAIC,eAAepB,GAKpC,OAJAmB,EAASE,QAAQ7B,GAEjBQ,IAEO,CACNsB,QAAS9B,EACT+B,OACC/B,EAAQG,MAAM6B,QAAU,EACxB,EACDC,OACCjC,EAAQG,MAAM6B,QAAU,MACxB,EACDE,UACCP,EAASQ,aACTnC,EAAQoC,QACR,EACDC,eAAeC,GACd/B,EAAe+B,EACf9B,GACD,EAEF"}
@@ -16,10 +16,12 @@ import { EditorSnapshot, FormatState } from './BikEditor.types';
16
16
  */
17
17
  export declare function normalizeHtml(html: string): string;
18
18
  /**
19
- * Insert HTML at the current cursor position as inline content.
20
- * Parses the HTML into ProseMirror nodes, collects only the inline children
21
- * (unwrapping block wrappers like <p>), and replaces the current selection
22
- * with an open Slice so the content merges into the surrounding paragraph.
19
+ * Insert HTML at the current cursor position, merging the first paragraph
20
+ * inline while preserving the block structure of subsequent paragraphs/lists.
21
+ *
22
+ * Uses `parseSlice` which returns an open-ended Slice the first block merges
23
+ * at the cursor, middle blocks stay intact, and the last block merges with any
24
+ * text that follows the cursor.
23
25
  */
24
26
  export declare function insertInlineHtml(editor: Editor, html: string): void;
25
27
  export declare const SECTION_DIVIDER_HTML: (id: string) => string;
@@ -1,2 +1,2 @@
1
- import{DOMSerializer as t,DOMParser as e,Fragment as n,Slice as i}from"../node_modules/prosemirror-model/dist/index.js";function r(t){return t.replace(/<p>\s*<br\s*\/?>\s*<\/p>/gi,"<p></p>").replace(/<\/?span[^>]*>/gi,"")}function o(t,o){const s=r(o),c=t.schema,l=document.createElement("div");l.innerHTML=s;const d=e.fromSchema(c).parse(l),u=[];if(d.content.forEach((t=>{t.isTextblock?t.content.size>0&&u.push(t.content):(t.isInline||t.isText)&&u.push(n.from(t))})),0===u.length)return;let a=n.empty;for(const t of u)a=a.append(t);const{from:f,to:v}=t.state.selection,h=new i(a,0,0),m=t.state.tr.replaceRange(f,v,h);t.view.dispatch(m)}const s=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function c(t,e){let n=t;for(const t of e)n+=s(t.id)+t.content;return n}function l(t){var e;if(!t)return"";return null!==(e=u(t).get("body"))&&void 0!==e?e:t}function d(t){if(!t)return"";const e=l(t);return t.substring(e.length)}function u(t){const e=new Map,n=/<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g,i=[];let r;for(;null!==(r=n.exec(t));)i.push({id:r[1],index:r.index,endIndex:r.index+r[0].length});if(0===i.length)return e.set("body",t),e;e.set("body",t.slice(0,i[0].index));for(let n=0;n<i.length;n++){const r=i[n].endIndex,o=n+1<i.length?i[n+1].index:t.length;e.set(i[n].id,t.slice(r,o))}return e}function a(e,n){var i;const r=p(e,n);if(-1===r)return{html:"",text:"",isEmpty:!0,characterCount:0};const o=g(e,n),s=e.state.doc.slice(r,o),c=document.createElement("div"),l=t.fromSchema(e.schema);c.appendChild(l.serializeFragment(s.content));const d=c.innerHTML,u=null!==(i=c.textContent)&&void 0!==i?i:"";return{html:d,text:u,isEmpty:!u.trim(),characterCount:u.length}}function f(t,n,i){const r=p(t,n);if(-1===r){const e=t.state.doc.content.size,r=s(n)+i;return void t.commands.insertContentAt(e,r,{updateSelection:!1})}const o=g(t,n),c=function(t,n){const i=document.createElement("div");return i.innerHTML=n,e.fromSchema(t.schema).parse(i).content}(t,i),{tr:l}=t.state,d="body"===n?0:r;l.replaceWith(d,o,c),l.setMeta("addToHistory",!1),t.view.dispatch(l)}function v(t){return a(t,"body")}function h(t){var e,n,i,r;return{bold:t.isActive("bold"),italic:t.isActive("italic"),underline:t.isActive("underline"),strike:t.isActive("strike"),bulletList:t.isActive("bulletList"),orderedList:t.isActive("orderedList"),blockquote:t.isActive("blockquote"),codeBlock:t.isActive("codeBlock"),link:(()=>{var e,n,i;if(t.isActive("link"))return{href:null!==(e=t.getAttributes("link").href)&&void 0!==e?e:""};const{$from:r}=t.state.selection;if(r.pos>0){const t=r.doc.resolve(r.pos).marks().find((t=>"link"===t.type.name));if(t)return{href:null!==(i=t.attrs.href)&&void 0!==i?i:""};{const t=r.nodeBefore,e=null==t?void 0:t.marks.find((t=>"link"===t.type.name));if(e)return{href:null!==(n=e.attrs.href)&&void 0!==n?n:""}}}return null})(),textAlign:t.isActive({textAlign:"center"})?"center":t.isActive({textAlign:"right"})?"right":t.isActive({textAlign:"justify"})?"justify":t.isActive({textAlign:"left"})?"left":null,fontFamily:null!==(e=t.getAttributes("textStyle").fontFamily)&&void 0!==e?e:null,fontSize:null!==(n=t.getAttributes("textStyle").fontSize)&&void 0!==n?n:null,color:null!==(i=t.getAttributes("textStyle").color)&&void 0!==i?i:null,highlight:t.isActive("highlight")?null!==(r=t.getAttributes("highlight").color)&&void 0!==r?r:"default":null,superscript:t.isActive("superscript"),subscript:t.isActive("subscript")}}function m(t){var e,n,i;return{html:t.getHTML(),text:t.getText(),isEmpty:t.isEmpty,characterCount:null!==(i=null===(n=null===(e=t.storage.characterCount)||void 0===e?void 0:e.characters)||void 0===n?void 0:n.call(e))&&void 0!==i?i:t.getText().length}}function p(t,e){if("body"===e)return 1;let n=-1;return t.state.doc.descendants(((t,i)=>{if(-1!==n)return!1;"sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(n=i+t.nodeSize)})),n}function g(t,e){const n=t.state.doc,i=n.content.size;if("body"===e){let t=-1;return n.descendants(((e,n)=>{if(-1!==t)return!1;"sectionDivider"===e.type.name&&(t=n)})),-1!==t?t:i}let r=!1,o=-1;return n.descendants(((t,n)=>-1===o&&(r?void("sectionDivider"===t.type.name&&(o=n)):("sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(r=!0),!1)))),-1!==o?o:i}export{s as SECTION_DIVIDER_HTML,c as buildSectionedContent,h as extractActiveFormats,u as extractAllSectionsFromHtml,v as extractBodyContent,m as extractContent,a as extractSectionContent,g as findSectionEndPos,p as findSectionStartPos,l as getBodyHtml,d as getSectionsHtml,o as insertInlineHtml,r as normalizeHtml,f as setSectionContentInEditor};
1
+ import{DOMSerializer as t,DOMParser as e}from"../node_modules/prosemirror-model/dist/index.js";function n(t){return t.replace(/<p>\s*<br\s*\/?>\s*<\/p>/gi,"<p></p>").replace(/<\/?span[^>]*>/gi,"")}function i(t,i){const r=n(i),o=document.createElement("div");o.innerHTML=r;const s=e.fromSchema(t.schema).parseSlice(o);if(0===s.size)return;const{from:c,to:l}=t.state.selection,d=t.state.tr.replaceRange(c,l,s);t.view.dispatch(d)}const r=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function o(t,e){let n=t;for(const t of e)n+=r(t.id)+t.content;return n}function s(t){var e;if(!t)return"";return null!==(e=l(t).get("body"))&&void 0!==e?e:t}function c(t){if(!t)return"";const e=s(t);return t.substring(e.length)}function l(t){const e=new Map,n=/<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g,i=[];let r;for(;null!==(r=n.exec(t));)i.push({id:r[1],index:r.index,endIndex:r.index+r[0].length});if(0===i.length)return e.set("body",t),e;e.set("body",t.slice(0,i[0].index));for(let n=0;n<i.length;n++){const r=i[n].endIndex,o=n+1<i.length?i[n+1].index:t.length;e.set(i[n].id,t.slice(r,o))}return e}function d(e,n){var i;const r=h(e,n);if(-1===r)return{html:"",text:"",isEmpty:!0,characterCount:0};const o=m(e,n),s=e.state.doc.slice(r,o),c=document.createElement("div"),l=t.fromSchema(e.schema);c.appendChild(l.serializeFragment(s.content));const d=c.innerHTML,u=null!==(i=c.textContent)&&void 0!==i?i:"";return{html:d,text:u,isEmpty:!u.trim(),characterCount:u.length}}function u(t,n,i){const o=h(t,n);if(-1===o){const e=t.state.doc.content.size,o=r(n)+i;return void t.commands.insertContentAt(e,o,{updateSelection:!1})}const s=m(t,n),c=function(t,n){const i=document.createElement("div");return i.innerHTML=n,e.fromSchema(t.schema).parse(i).content}(t,i),{tr:l}=t.state,d="body"===n?0:o;l.replaceWith(d,s,c),l.setMeta("addToHistory",!1),t.view.dispatch(l)}function a(t){return d(t,"body")}function f(t){var e,n,i,r;return{bold:t.isActive("bold"),italic:t.isActive("italic"),underline:t.isActive("underline"),strike:t.isActive("strike"),bulletList:t.isActive("bulletList"),orderedList:t.isActive("orderedList"),blockquote:t.isActive("blockquote"),codeBlock:t.isActive("codeBlock"),link:(()=>{var e,n,i;if(t.isActive("link"))return{href:null!==(e=t.getAttributes("link").href)&&void 0!==e?e:""};const{$from:r}=t.state.selection;if(r.pos>0){const t=r.doc.resolve(r.pos).marks().find((t=>"link"===t.type.name));if(t)return{href:null!==(i=t.attrs.href)&&void 0!==i?i:""};{const t=r.nodeBefore,e=null==t?void 0:t.marks.find((t=>"link"===t.type.name));if(e)return{href:null!==(n=e.attrs.href)&&void 0!==n?n:""}}}return null})(),textAlign:t.isActive({textAlign:"center"})?"center":t.isActive({textAlign:"right"})?"right":t.isActive({textAlign:"justify"})?"justify":t.isActive({textAlign:"left"})?"left":null,fontFamily:null!==(e=t.getAttributes("textStyle").fontFamily)&&void 0!==e?e:null,fontSize:null!==(n=t.getAttributes("textStyle").fontSize)&&void 0!==n?n:null,color:null!==(i=t.getAttributes("textStyle").color)&&void 0!==i?i:null,highlight:t.isActive("highlight")?null!==(r=t.getAttributes("highlight").color)&&void 0!==r?r:"default":null,superscript:t.isActive("superscript"),subscript:t.isActive("subscript")}}function v(t){var e,n,i;return{html:t.getHTML(),text:t.getText(),isEmpty:t.isEmpty,characterCount:null!==(i=null===(n=null===(e=t.storage.characterCount)||void 0===e?void 0:e.characters)||void 0===n?void 0:n.call(e))&&void 0!==i?i:t.getText().length}}function h(t,e){if("body"===e)return 1;let n=-1;return t.state.doc.descendants(((t,i)=>{if(-1!==n)return!1;"sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(n=i+t.nodeSize)})),n}function m(t,e){const n=t.state.doc,i=n.content.size;if("body"===e){let t=-1;return n.descendants(((e,n)=>{if(-1!==t)return!1;"sectionDivider"===e.type.name&&(t=n)})),-1!==t?t:i}let r=!1,o=-1;return n.descendants(((t,n)=>-1===o&&(r?void("sectionDivider"===t.type.name&&(o=n)):("sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(r=!0),!1)))),-1!==o?o:i}export{r as SECTION_DIVIDER_HTML,o as buildSectionedContent,f as extractActiveFormats,l as extractAllSectionsFromHtml,a as extractBodyContent,v as extractContent,d as extractSectionContent,m as findSectionEndPos,h as findSectionStartPos,s as getBodyHtml,c as getSectionsHtml,i as insertInlineHtml,n as normalizeHtml,u as setSectionContentInEditor};
2
2
  //# sourceMappingURL=BikEditor.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BikEditor.utils.js","sources":["../../../src/editor/BikEditor.utils.ts"],"sourcesContent":["import { Editor } from '@tiptap/core';\nimport { DOMParser, DOMSerializer, Fragment, Slice } from 'prosemirror-model';\nimport { EditorSnapshot, FormatState } from './BikEditor.types';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * Problem: Quill uses `<p><br></p>` as a blank-line separator. TipTap's\n * HardBreak extension parses that `<br>` as a real `hard_break` node.\n * ProseMirror then also appends `<br class=\"ProseMirror-trailingBreak\">` as a\n * cursor-position decoration, making the empty paragraph render at **2× line\n * height** instead of 1×.\n *\n * Fix: replace `<p><br></p>` → `<p></p>` so TipTap stores a truly empty\n * paragraph. ProseMirror adds only the trailing decoration, giving the correct\n * 1× line height. The WA text output is unchanged (`\\n` either way after\n * surrounding-newline collapse in `toWhatsAppText`).\n */\nexport function normalizeHtml(html: string): string {\n\treturn html\n\t\t.replace(/<p>\\s*<br\\s*\\/?>\\s*<\\/p>/gi, '<p></p>')\n\t\t.replace(/<\\/?span[^>]*>/gi, '');\n}\n\n// ---------------------------------------------------------------------------\n// Inline content insertion\n// ---------------------------------------------------------------------------\n\n/**\n * Insert HTML at the current cursor position as inline content.\n * Parses the HTML into ProseMirror nodes, collects only the inline children\n * (unwrapping block wrappers like <p>), and replaces the current selection\n * with an open Slice so the content merges into the surrounding paragraph.\n */\nexport function insertInlineHtml(editor: Editor, html: string): void {\n\tconst normalised = normalizeHtml(html);\n\tconst schema = editor.schema;\n\tconst dom = document.createElement('div');\n\tdom.innerHTML = normalised;\n\tconst parsed = DOMParser.fromSchema(schema).parse(dom);\n\n\tconst inlineFragments: Fragment[] = [];\n\tparsed.content.forEach((node) => {\n\t\tif (node.isTextblock) {\n\t\t\tif (node.content.size > 0) inlineFragments.push(node.content);\n\t\t} else if (node.isInline || node.isText) {\n\t\t\tinlineFragments.push(Fragment.from(node));\n\t\t}\n\t});\n\n\tif (inlineFragments.length === 0) return;\n\n\tlet combined = Fragment.empty;\n\tfor (const frag of inlineFragments) {\n\t\tcombined = combined.append(frag);\n\t}\n\n\tconst { from, to } = editor.state.selection;\n\tconst slice = new Slice(combined, 0, 0);\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 = 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).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\treturn {\n\t\thtml: editor.getHTML(),\n\t\ttext: editor.getText(),\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount:\n\t\t\teditor.storage.characterCount?.characters?.() ?? editor.getText().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","replace","insertInlineHtml","editor","normalised","schema","dom","document","createElement","innerHTML","parsed","DOMParser","fromSchema","parse","inlineFragments","content","forEach","node","isTextblock","size","push","isInline","isText","Fragment","from","length","combined","empty","frag","append","to","state","selection","slice","Slice","tr","replaceRange","view","dispatch","SECTION_DIVIDER_HTML","id","buildSectionedContent","body","sections","s","getBodyHtml","_a","extractAllSectionsFromHtml","get","getSectionsHtml","substring","Map","dividerRegex","dividers","match","exec","index","endIndex","set","i","start","end","extractSectionContent","startPos","findSectionStartPos","text","isEmpty","characterCount","endPos","findSectionEndPos","doc","container","serializer","DOMSerializer","appendChild","serializeFragment","textContent","trim","setSectionContentInEditor","dividerHtml","commands","insertContentAt","updateSelection","fragment","parseHtmlToNodes","replaceFrom","replaceWith","setMeta","extractBodyContent","extractActiveFormats","bold","isActive","italic","underline","strike","bulletList","orderedList","blockquote","codeBlock","link","href","getAttributes","$from","pos","linkMark","resolve","marks","find","m","type","name","_c","attrs","nodeBefore","markOnPrev","_b","textAlign","fontFamily","fontSize","color","highlight","_d","superscript","subscript","extractContent","getHTML","getText","storage","characters","sectionId","descendants","nodeSize","docSize","firstDividerPos","passedSection","nextDividerPos"],"mappings":"wHAsBM,SAAUA,EAAcC,GAC7B,OAAOA,EACLC,QAAQ,6BAA8B,WACtCA,QAAQ,mBAAoB,GAC/B,CAYgB,SAAAC,EAAiBC,EAAgBH,GAChD,MAAMI,EAAaL,EAAcC,GAC3BK,EAASF,EAAOE,OAChBC,EAAMC,SAASC,cAAc,OACnCF,EAAIG,UAAYL,EAChB,MAAMM,EAASC,EAAUC,WAAWP,GAAQQ,MAAMP,GAE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C,EAAMtF,EAAKkH,SACtB,IAEKpE,CACR,CAOgB,SAAAM,EAAkBlE,EAAgB8H,GACjD,MAAM3D,EAAMnE,EAAO4B,MAAMuC,IACnB8D,EAAU9D,EAAIvD,QAAQI,KAE5B,GAAkB,SAAd8G,EAAsB,CACzB,IAAII,GAAmB,EAOvB,OANA/D,EAAI4D,aAAY,CAACjH,EAAMsF,KACtB,IAAyB,IAArB8B,EAAwB,OAAO,EACZ,mBAAnBpH,EAAK4F,KAAKC,OACbuB,EAAkB9B,EAClB,KAE0B,IAArB8B,EAAyBA,EAAkBD,CAClD,CAED,IAAIE,GAAgB,EAChBC,GAAkB,EAgBtB,OAfAjE,EAAI4D,aAAY,CAACjH,EAAMsF,KACE,IAApBgC,IACCD,OASkB,mBAAnBrH,EAAK4F,KAAKC,OACbyB,EAAiBhC,KARG,mBAAnBtF,EAAK4F,KAAKC,MACV7F,EAAK+F,MAAiB,YAAMiB,IAE5BK,GAAgB,IAEV,OAMkB,IAApBC,EAAwBA,EAAiBH,CACjD"}
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';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * Problem: Quill uses `<p><br></p>` as a blank-line separator. TipTap's\n * HardBreak extension parses that `<br>` as a real `hard_break` node.\n * ProseMirror then also appends `<br class=\"ProseMirror-trailingBreak\">` as a\n * cursor-position decoration, making the empty paragraph render at **2× line\n * height** instead of 1×.\n *\n * Fix: replace `<p><br></p>` → `<p></p>` so TipTap stores a truly empty\n * paragraph. ProseMirror adds only the trailing decoration, giving the correct\n * 1× line height. The WA text output is unchanged (`\\n` either way after\n * surrounding-newline collapse in `toWhatsAppText`).\n */\nexport function normalizeHtml(html: string): string {\n\treturn html\n\t\t.replace(/<p>\\s*<br\\s*\\/?>\\s*<\\/p>/gi, '<p></p>')\n\t\t.replace(/<\\/?span[^>]*>/gi, '');\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\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 = 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).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\treturn {\n\t\thtml: editor.getHTML(),\n\t\ttext: editor.getText(),\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount:\n\t\t\teditor.storage.characterCount?.characters?.() ?? editor.getText().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","replace","insertInlineHtml","editor","normalised","dom","document","createElement","innerHTML","slice","DOMParser","fromSchema","schema","parseSlice","size","from","to","state","selection","tr","replaceRange","view","dispatch","SECTION_DIVIDER_HTML","id","buildSectionedContent","body","sections","s","content","getBodyHtml","_a","extractAllSectionsFromHtml","get","getSectionsHtml","substring","length","Map","dividerRegex","dividers","match","exec","push","index","endIndex","set","i","start","end","extractSectionContent","startPos","findSectionStartPos","text","isEmpty","characterCount","endPos","findSectionEndPos","doc","container","serializer","DOMSerializer","appendChild","serializeFragment","textContent","trim","setSectionContentInEditor","dividerHtml","commands","insertContentAt","updateSelection","fragment","parse","parseHtmlToNodes","replaceFrom","replaceWith","setMeta","extractBodyContent","extractActiveFormats","bold","isActive","italic","underline","strike","bulletList","orderedList","blockquote","codeBlock","link","href","getAttributes","$from","pos","linkMark","resolve","marks","find","m","type","name","_c","attrs","nodeBefore","markOnPrev","_b","textAlign","fontFamily","fontSize","color","highlight","_d","superscript","subscript","extractContent","getHTML","getText","storage","characters","sectionId","descendants","node","nodeSize","docSize","firstDividerPos","passedSection","nextDividerPos"],"mappings":"+FAsBM,SAAUA,EAAcC,GAC7B,OAAOA,EACLC,QAAQ,6BAA8B,WACtCA,QAAQ,mBAAoB,GAC/B,CAcgB,SAAAC,EAAiBC,EAAgBH,GAChD,MAAMI,EAAaL,EAAcC,GAC3BK,EAAMC,SAASC,cAAc,OACnCF,EAAIG,UAAYJ,EAChB,MAAMK,EAAQC,EAAUC,WAAWR,EAAOS,QAAQC,WAAWR,GAE7D,GAAmB,IAAfI,EAAMK,KAAY,OAEtB,MAAMC,KAAEA,E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AgBtB,OAfAnE,EAAI6D,aAAY,CAACC,EAAM5B,KACE,IAApBiC,IACCD,OASkB,mBAAnBJ,EAAKtB,KAAKC,OACb0B,EAAiBjC,KARG,mBAAnB4B,EAAKtB,KAAKC,MACVqB,EAAKnB,MAAiB,YAAMiB,IAE5BM,GAAgB,IAEV,OAMkB,IAApBC,EAAwBA,EAAiBH,CACjD"}
@@ -1,2 +1,2 @@
1
- function t(t,e){const o=document.createElement("div");function n(t){const e=null==t?void 0:t();if(!e)return;const n=o.offsetHeight,i=o.offsetWidth,d=window.innerHeight,s=window.innerWidth,l=d-e.bottom-4,p=e.top-4,r=l>=n?e.bottom+4:p>=n?e.top-4-n:4,a=Math.min(e.left,s-i-4);o.style.left=`${Math.max(4,a)}px`,o.style.top=`${r}px`}return o.style.cssText="position:fixed;z-index:9999;pointer-events:auto;",o.appendChild(t),document.body.appendChild(o),n(e),{element:o,show(){o.style.display=""},hide(){o.style.display="none"},destroy(){o.remove()},updatePosition(t){n(t)}}}export{t as createSuggestionPopup};
1
+ function e(e,t){const n=document.createElement("div");n.style.cssText="position:fixed;z-index:9999;pointer-events:auto;",n.appendChild(e),document.body.appendChild(n);let o=t;function i(){const e=null==o?void 0:o();if(!e)return;const t=n.offsetHeight,i=n.offsetWidth,s=window.innerHeight,d=window.innerWidth,l=s-e.bottom-4,p=e.top-4,r=l>=t?e.bottom+4:p>=t?e.top-4-t:4,c=Math.min(e.left,d-i-4);n.style.left=`${Math.max(4,c)}px`,n.style.top=`${r}px`}const s=new ResizeObserver(i);return s.observe(n),i(),{element:n,show(){n.style.display=""},hide(){n.style.display="none"},destroy(){s.disconnect(),n.remove()},updatePosition(e){o=e,i()}}}export{e as createSuggestionPopup};
2
2
  //# sourceMappingURL=suggestionPopup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"suggestionPopup.js","sources":["../../../../src/editor/extensions/suggestionPopup.ts"],"sourcesContent":["/**\n * Lightweight popup positioner for suggestion dropdowns (mentions, slash commands).\n * Replaces tippy.js — all we need is a positioned container near the cursor\n * that flips above when there isn't enough room below.\n */\n\nconst GAP = 4;\n\nexport interface SuggestionPopup {\n\tshow(): void;\n\thide(): void;\n\tdestroy(): void;\n\tupdatePosition(clientRect: () => DOMRect | null): void;\n\treadonly element: HTMLDivElement;\n}\n\nexport function createSuggestionPopup(\n\tcontent: HTMLElement,\n\tclientRect: (() => DOMRect | null) | null,\n): SuggestionPopup {\n\tconst wrapper = document.createElement('div');\n\twrapper.style.cssText = 'position:fixed;z-index:9999;pointer-events:auto;';\n\twrapper.appendChild(content);\n\tdocument.body.appendChild(wrapper);\n\n\tfunction reposition(getRectFn: (() => DOMRect | null) | null) {\n\t\tconst rect = getRectFn?.();\n\t\tif (!rect) return;\n\n\t\tconst popupHeight = wrapper.offsetHeight;\n\t\tconst popupWidth = wrapper.offsetWidth;\n\t\tconst viewportH = window.innerHeight;\n\t\tconst viewportW = window.innerWidth;\n\n\t\tconst spaceBelow = viewportH - rect.bottom - GAP;\n\t\tconst spaceAbove = rect.top - GAP;\n\t\tconst fitsBelow = spaceBelow >= popupHeight;\n\n\t\tconst top = fitsBelow\n\t\t\t? rect.bottom + GAP\n\t\t\t: spaceAbove >= popupHeight\n\t\t\t? rect.top - GAP - popupHeight\n\t\t\t: GAP;\n\n\t\tconst left = Math.min(rect.left, viewportW - popupWidth - GAP);\n\n\t\twrapper.style.left = `${Math.max(GAP, left)}px`;\n\t\twrapper.style.top = `${top}px`;\n\t}\n\n\treposition(clientRect);\n\n\treturn {\n\t\telement: wrapper,\n\t\tshow() {\n\t\t\twrapper.style.display = '';\n\t\t},\n\t\thide() {\n\t\t\twrapper.style.display = 'none';\n\t\t},\n\t\tdestroy() {\n\t\t\twrapper.remove();\n\t\t},\n\t\tupdatePosition(getRectFn: () => DOMRect | null) {\n\t\t\treposition(getRectFn);\n\t\t},\n\t};\n}\n"],"names":["createSuggestionPopup","content","clientRect","wrapper","document","createElement","reposition","getRectFn","rect","popupHeight","offsetHeight","popupWidth","offsetWidth","viewportH","window","innerHeight","viewportW","innerWidth","spaceBelow","bottom","spaceAbove","top","left","Math","min","style","max","cssText","appendChild","body","element","show","display","hide","destroy","remove","updatePosition"],"mappings":"AAgBgB,SAAAA,EACfC,EACAC,GAEA,MAAMC,EAAUC,SAASC,cAAc,OAKvC,SAASC,EAAWC,GACnB,MAAMC,EAAOD,aAAA,EAAAA,IACb,IAAKC,EAAM,OAEX,MAAMC,EAAcN,EAAQO,aACtBC,EAAaR,EAAQS,YACrBC,EAAYC,OAAOC,YACnBC,EAAYF,OAAOG,WAEnBC,EAAaL,EAAYL,EAAKW,OA5B1B,EA6BJC,EAAaZ,EAAKa,IA7Bd,EAgCJA,EAFYH,GAAcT,EAG7BD,EAAKW,OAjCE,EAkCPC,GAAcX,EACdD,EAAKa,IAnCE,EAmCUZ,EAnCV,EAsCJa,EAAOC,KAAKC,IAAIhB,EAAKc,KAAMN,EAAYL,EAtCnC,GAwCVR,EAAQsB,MAAMH,KAAU,GAAAC,KAAKG,IAxCnB,EAwC4BJ,OACtCnB,EAAQsB,MAAMJ,IAAS,GAAAA,KACxB,CAIA,OA/BAlB,EAAQsB,MAAME,QAAU,mDACxBxB,EAAQyB,YAAY3B,GACpBG,SAASyB,KAAKD,YAAYzB,GA2B1BG,EAAWJ,GAEJ,CACN4B,QAAS3B,EACT4B,OACC5B,EAAQsB,MAAMO,QAAU,EACxB,EACDC,OACC9B,EAAQsB,MAAMO,QAAU,MACxB,EACDE,UACC/B,EAAQgC,QACR,EACDC,eAAe7B,GACdD,EAAWC,EACZ,EAEF"}
1
+ {"version":3,"file":"suggestionPopup.js","sources":["../../../../src/editor/extensions/suggestionPopup.ts"],"sourcesContent":["/**\n * Lightweight popup positioner for suggestion dropdowns (mentions, slash commands).\n * Replaces tippy.js — all we need is a positioned container near the cursor\n * that flips above when there isn't enough room below.\n */\n\nconst GAP = 4;\n\nexport interface SuggestionPopup {\n\tshow(): void;\n\thide(): void;\n\tdestroy(): void;\n\tupdatePosition(clientRect: () => DOMRect | null): void;\n\treadonly element: HTMLDivElement;\n}\n\nexport function createSuggestionPopup(\n\tcontent: HTMLElement,\n\tclientRect: (() => DOMRect | null) | null,\n): SuggestionPopup {\n\tconst wrapper = document.createElement('div');\n\twrapper.style.cssText = 'position:fixed;z-index:9999;pointer-events:auto;';\n\twrapper.appendChild(content);\n\tdocument.body.appendChild(wrapper);\n\n\tlet latestRectFn: (() => DOMRect | null) | null = clientRect;\n\n\tfunction reposition() {\n\t\tconst rect = latestRectFn?.();\n\t\tif (!rect) return;\n\n\t\tconst popupHeight = wrapper.offsetHeight;\n\t\tconst popupWidth = wrapper.offsetWidth;\n\t\tconst viewportH = window.innerHeight;\n\t\tconst viewportW = window.innerWidth;\n\n\t\tconst spaceBelow = viewportH - rect.bottom - GAP;\n\t\tconst spaceAbove = rect.top - GAP;\n\t\tconst fitsBelow = spaceBelow >= popupHeight;\n\n\t\tconst top = fitsBelow\n\t\t\t? rect.bottom + GAP\n\t\t\t: spaceAbove >= popupHeight\n\t\t\t? rect.top - GAP - popupHeight\n\t\t\t: GAP;\n\n\t\tconst left = Math.min(rect.left, viewportW - popupWidth - GAP);\n\n\t\twrapper.style.left = `${Math.max(GAP, left)}px`;\n\t\twrapper.style.top = `${top}px`;\n\t}\n\n\tconst observer = new ResizeObserver(reposition);\n\tobserver.observe(wrapper);\n\n\treposition();\n\n\treturn {\n\t\telement: wrapper,\n\t\tshow() {\n\t\t\twrapper.style.display = '';\n\t\t},\n\t\thide() {\n\t\t\twrapper.style.display = 'none';\n\t\t},\n\t\tdestroy() {\n\t\t\tobserver.disconnect();\n\t\t\twrapper.remove();\n\t\t},\n\t\tupdatePosition(getRectFn: () => DOMRect | null) {\n\t\t\tlatestRectFn = getRectFn;\n\t\t\treposition();\n\t\t},\n\t};\n}\n"],"names":["createSuggestionPopup","content","clientRect","wrapper","document","createElement","style","cssText","appendChild","body","latestRectFn","reposition","rect","popupHeight","offsetHeight","popupWidth","offsetWidth","viewportH","window","innerHeight","viewportW","innerWidth","spaceBelow","bottom","spaceAbove","top","left","Math","min","max","observer","ResizeObserver","observe","element","show","display","hide","destroy","disconnect","remove","updatePosition","getRectFn"],"mappings":"AAgBgB,SAAAA,EACfC,EACAC,GAEA,MAAMC,EAAUC,SAASC,cAAc,OACvCF,EAAQG,MAAMC,QAAU,mDACxBJ,EAAQK,YAAYP,GACpBG,SAASK,KAAKD,YAAYL,GAE1B,IAAIO,EAA8CR,EAElD,SAASS,IACR,MAAMC,EAAOF,aAAA,EAAAA,IACb,IAAKE,EAAM,OAEX,MAAMC,EAAcV,EAAQW,aACtBC,EAAaZ,EAAQa,YACrBC,EAAYC,OAAOC,YACnBC,EAAYF,OAAOG,WAEnBC,EAAaL,EAAYL,EAAKW,OA9B1B,EA+BJC,EAAaZ,EAAKa,IA/Bd,EAkCJA,EAFYH,GAAcT,EAG7BD,EAAKW,OAnCE,EAoCPC,GAAcX,EACdD,EAAKa,IArCE,EAqCUZ,EArCV,EAwCJa,EAAOC,KAAKC,IAAIhB,EAAKc,KAAMN,EAAYL,EAxCnC,GA0CVZ,EAAQG,MAAMoB,KAAU,GAAAC,KAAKE,IA1CnB,EA0C4BH,OACtCvB,EAAQG,MAAMmB,IAAS,GAAAA,KACxB,CAEA,MAAMK,EAAW,IAAIC,eAAepB,GAKpC,OAJAmB,EAASE,QAAQ7B,GAEjBQ,IAEO,CACNsB,QAAS9B,EACT+B,OACC/B,EAAQG,MAAM6B,QAAU,EACxB,EACDC,OACCjC,EAAQG,MAAM6B,QAAU,MACxB,EACDE,UACCP,EAASQ,aACTnC,EAAQoC,QACR,EACDC,eAAeC,GACd/B,EAAe+B,EACf9B,GACD,EAEF"}
@@ -16,10 +16,12 @@ import { EditorSnapshot, FormatState } from './BikEditor.types';
16
16
  */
17
17
  export declare function normalizeHtml(html: string): string;
18
18
  /**
19
- * Insert HTML at the current cursor position as inline content.
20
- * Parses the HTML into ProseMirror nodes, collects only the inline children
21
- * (unwrapping block wrappers like <p>), and replaces the current selection
22
- * with an open Slice so the content merges into the surrounding paragraph.
19
+ * Insert HTML at the current cursor position, merging the first paragraph
20
+ * inline while preserving the block structure of subsequent paragraphs/lists.
21
+ *
22
+ * Uses `parseSlice` which returns an open-ended Slice the first block merges
23
+ * at the cursor, middle blocks stay intact, and the last block merges with any
24
+ * text that follows the cursor.
23
25
  */
24
26
  export declare function insertInlineHtml(editor: Editor, html: string): void;
25
27
  export declare const SECTION_DIVIDER_HTML: (id: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.804-beta.12",
3
+ "version": "0.0.804-beta.14",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",