@bikdotai/bik-component-library 0.0.809-beta.20 → 0.0.809-beta.21
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"),e=require("./extensions/plainClipboard/pasteUtils.js");function n(t){return t.replace(/<\/?span[^>]*>/gi,"").replace(/(<p[^>]*>)\s*<br\s*\/?>\s*(<\/p>)/gi,"$1$2")}function i(t){const e=document.createElement("div");e.innerHTML=t;for(const t of Array.from(e.querySelectorAll("p"))){if(0===t.childNodes.length){t.appendChild(document.createElement("br"));continue}t.lastChild instanceof HTMLBRElement&&t.childNodes.length>1&&t.appendChild(document.createElement("br"))}return e.innerHTML}const r=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function o(t){var e;if(!t)return"";return null!==(e=s(t).get("body"))&&void 0!==e?e:t}function s(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 c(e,n){var r;const o=l(e,n);if(-1===o)return{html:"",text:"",isEmpty:!0,characterCount:0};const s=d(e,n),c=e.state.doc.slice(o,s),a=document.createElement("div"),u=t.DOMSerializer.fromSchema(e.schema);a.appendChild(u.serializeFragment(c.content));const f=i(a.innerHTML),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("../node_modules/prosemirror-model/dist/index.js"),e=require("./extensions/plainClipboard/pasteUtils.js");function n(t){return t.replace(/<\/?span[^>]*>/gi,"").replace(/(<p[^>]*>)\s*<br\s*\/?>\s*(<\/p>)/gi,"$1$2")}function i(t){const e=document.createElement("div");e.innerHTML=t;for(const t of Array.from(e.querySelectorAll("p"))){if(t.style.margin="0",0===t.childNodes.length){t.appendChild(document.createElement("br"));continue}t.lastChild instanceof HTMLBRElement&&t.childNodes.length>1&&t.appendChild(document.createElement("br"))}return e.innerHTML}const r=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function o(t){var e;if(!t)return"";return null!==(e=s(t).get("body"))&&void 0!==e?e:t}function s(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 c(e,n){var r;const o=l(e,n);if(-1===o)return{html:"",text:"",isEmpty:!0,characterCount:0};const s=d(e,n),c=e.state.doc.slice(o,s),a=document.createElement("div"),u=t.DOMSerializer.fromSchema(e.schema);a.appendChild(u.serializeFragment(c.content));const f=i(a.innerHTML),m=null!==(r=a.textContent)&&void 0!==r?r:"";return{html:f,text:m,isEmpty:!m.trim(),characterCount:m.length}}function l(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 d(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=r,exports.buildSectionedContent=function(t,e){let n=t;for(const t of e)n+=r(t.id)+t.content;return n},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=s,exports.extractBodyContent=function(t){return c(t,"body")},exports.extractContent=function(t){const n=i(t.getHTML()),r=e.normalizeHardBreaks(t.state.doc.content),o=t.schema.node("doc",null,r),s=o.textBetween(0,o.content.size,"\n","\n");return{html:n,text:s,isEmpty:t.isEmpty,characterCount:s.length}},exports.extractSectionContent=c,exports.findSectionEndPos=d,exports.findSectionStartPos=l,exports.getBodyHtml=o,exports.getSectionsHtml=function(t){if(!t)return"";const e=o(t);return t.substring(e.length)},exports.insertInlineHtml=function(e,i){const r=n(i),o=document.createElement("div");o.innerHTML=r;const s=t.DOMParser.fromSchema(e.schema).parseSlice(o);if(0===s.size)return;const{from:c,to:l}=e.state.selection,d=e.state.tr.replaceRange(c,l,s);e.view.dispatch(d)},exports.normalizeHtml=n,exports.setSectionContentInEditor=function(e,n,i){const o=l(e,n);if(-1===o){const t=e.state.doc.content.size,o=r(n)+i;return void e.commands.insertContentAt(t,o,{updateSelection:!1})}const s=d(e,n),c=function(e,n){const i=document.createElement("div");return i.innerHTML=n,t.DOMParser.fromSchema(e.schema).parse(i).content}(e,i),{tr:a}=e.state,u="body"===n?0:o;a.replaceWith(u,s,c),a.setMeta("addToHistory",!1),e.view.dispatch(a)},exports.toPortableHtml=i;
|
|
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 } from 'prosemirror-model';\nimport { EditorSnapshot, FormatState } from './BikEditor.types';\nimport { normalizeHardBreaks } from './extensions/plainClipboard/pasteUtils';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * 1. Strip all `<span>` tags first (keeps inner content). This exposes\n * bare `<br>` inside otherwise-empty paragraphs like Quill's\n * `<p><span class=\"ql-cursor\"><br></span></p>`.\n * 2. Then convert `<p><br></p>` → `<p></p>`. ProseMirror parses `<p></p>`\n * as an empty paragraph node and adds its own DOM `<br>` for cursor\n * positioning — one blank line, correct height. Leaving the `<br>`\n * would create a `hard_break` child AND the cursor `<br>`, producing\n * double-height blank lines.\n */\nexport function normalizeHtml(html: string): string {\n\treturn html\n\t\t.replace(/<\\/?span[^>]*>/gi, '')\n\t\t.replace(/(<p[^>]*>)\\s*<br\\s*\\/?>\\s*(<\\/p>)/gi, '$1$2');\n}\n\n/**\n * Make editor HTML portable across email clients and chat renderers.\n *\n * 1. Double a trailing `<br>` in content paragraphs so the blank line is\n * visible. A single trailing `<br>` before `</p>` is swallowed by most\n * email clients; `<br><br>` renders as a visible blank line (matches\n * Gmail's output).\n * 2. Convert empty `<p></p>` to `<p><br></p>` — email clients collapse\n * zero-height paragraphs without a `<br>`.\n */\nexport function toPortableHtml(html: string): string {\n\tconst div = document.createElement('div');\n\tdiv.innerHTML = html;\n\tfor (const p of Array.from(div.querySelectorAll('p'))) {\n\t\tif (p.childNodes.length === 0) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t\tcontinue;\n\t\t}\n\t\tconst last = p.lastChild;\n\t\tif (last instanceof HTMLBRElement && p.childNodes.length > 1) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t}\n\t}\n\treturn div.innerHTML;\n}\n\n// ---------------------------------------------------------------------------\n// Inline content insertion\n// ---------------------------------------------------------------------------\n\n/**\n * Insert HTML at the current cursor position, merging the first paragraph\n * inline while preserving the block structure of subsequent paragraphs/lists.\n *\n * Uses `parseSlice` which returns an open-ended Slice — the first block merges\n * at the cursor, middle blocks stay intact, and the last block merges with any\n * text that follows the cursor.\n */\nexport function insertInlineHtml(editor: Editor, html: string): void {\n\tconst normalised = normalizeHtml(html);\n\tconst dom = document.createElement('div');\n\tdom.innerHTML = normalised;\n\tconst slice = DOMParser.fromSchema(editor.schema).parseSlice(dom);\n\n\tif (slice.size === 0) return;\n\n\tconst { from, to } = editor.state.selection;\n\tconst tr = editor.state.tr.replaceRange(from, to, slice);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Section divider HTML\n// ---------------------------------------------------------------------------\n\nexport const SECTION_DIVIDER_HTML = (id: string) =>\n\t`<div data-section-divider=\"${id}\" style=\"display:none;height:0;line-height:0;overflow:hidden;\"></div>`;\n\n/**\n * Build initial HTML for an editor with one or more named sections below the body.\n * Each section is separated by an invisible divider node.\n *\n * @example\n * buildSectionedContent('<p>Body</p>', [\n * { id: 'signature', content: '<p>Alice</p>' },\n * { id: 'forwarded', content: '<p>--- fwd ---</p>' },\n * ])\n */\nexport function buildSectionedContent(\n\tbody: string,\n\tsections: Array<{ id: string; content: string }>,\n): string {\n\tlet html = body;\n\tfor (const s of sections) {\n\t\thtml += SECTION_DIVIDER_HTML(s.id) + s.content;\n\t}\n\treturn html;\n}\n\n// ---------------------------------------------------------------------------\n// Section extraction\n// ---------------------------------------------------------------------------\n\n/**\n * Parse the editor HTML into a Map of sectionId → raw HTML string.\n * The special key `'body'` always holds the content before the first divider.\n * Map iteration order matches document order.\n */\nexport function extractAllSections(editor: Editor): Map<string, string> {\n\treturn extractAllSectionsFromHtml(editor.getHTML());\n}\n\n/**\n * Extract just the body portion (everything before the first section divider)\n * from an HTML string produced by BikEditor. Safe to call on plain HTML too —\n * returns the full string when no dividers are present.\n */\nexport function getBodyHtml(html: string): string {\n\tif (!html) return '';\n\tconst sections = extractAllSectionsFromHtml(html);\n\treturn sections.get('body') ?? html;\n}\n\n/**\n * Extract everything from the first section divider onward (dividers + their\n * content). Returns an empty string when there are no sections.\n */\nexport function getSectionsHtml(html: string): string {\n\tif (!html) return '';\n\tconst body = getBodyHtml(html);\n\treturn html.substring(body.length);\n}\n\nexport function extractAllSectionsFromHtml(html: string): Map<string, string> {\n\tconst sections = new Map<string, string>();\n\tconst dividerRegex =\n\t\t/<div[^>]*data-section-divider=\"([^\"]*)[^>]*>\\s*<\\/div>/g;\n\tconst dividers: Array<{ id: string; index: number; endIndex: number }> = [];\n\n\tlet match: RegExpExecArray | null;\n\twhile ((match = dividerRegex.exec(html)) !== null) {\n\t\tdividers.push({\n\t\t\tid: match[1],\n\t\t\tindex: match.index,\n\t\t\tendIndex: match.index + match[0].length,\n\t\t});\n\t}\n\n\tif (dividers.length === 0) {\n\t\tsections.set('body', html);\n\t\treturn sections;\n\t}\n\n\tsections.set('body', html.slice(0, dividers[0].index));\n\tfor (let i = 0; i < dividers.length; i++) {\n\t\tconst start = dividers[i].endIndex;\n\t\tconst end = i + 1 < dividers.length ? dividers[i + 1].index : html.length;\n\t\tsections.set(dividers[i].id, html.slice(start, end));\n\t}\n\n\treturn sections;\n}\n\n/** Returns BikEditorContent for a single named section (or 'body'). */\nexport function extractSectionContent(\n\teditor: Editor,\n\tid: string,\n): EditorSnapshot {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1)\n\t\treturn { html: '', text: '', isEmpty: true, characterCount: 0 };\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst slice = editor.state.doc.slice(startPos, endPos);\n\tconst container = document.createElement('div');\n\tconst serializer = DOMSerializer.fromSchema(editor.schema);\n\tcontainer.appendChild(serializer.serializeFragment(slice.content));\n\tconst html = toPortableHtml(container.innerHTML);\n\tconst text = container.textContent ?? '';\n\treturn { html, text, isEmpty: !text.trim(), characterCount: text.length };\n}\n\n/**\n * Parse an HTML string into ProseMirror nodes using the editor's schema.\n */\nfunction parseHtmlToNodes(editor: Editor, html: string) {\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = html;\n\treturn DOMParser.fromSchema(editor.schema).parse(container).content;\n}\n\n/**\n * Replace the content of a single named section without touching others.\n * Uses a ProseMirror transaction to replace only the target range,\n * preserving undo history and other sections' state.\n * If the section doesn't exist yet, it is appended at the end of the document.\n */\nexport function setSectionContentInEditor(\n\teditor: Editor,\n\tid: string,\n\thtml: string,\n): void {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1) {\n\t\tconst endPos = editor.state.doc.content.size;\n\t\tconst dividerHtml = SECTION_DIVIDER_HTML(id) + html;\n\t\teditor.commands.insertContentAt(endPos, dividerHtml, {\n\t\t\tupdateSelection: false,\n\t\t});\n\t\treturn;\n\t}\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst fragment = parseHtmlToNodes(editor, html);\n\tconst { tr } = editor.state;\n\t// For body, replace from position 0 (before the first paragraph's opening\n\t// boundary) so ProseMirror swaps entire block nodes cleanly. Position 1\n\t// (inside the paragraph) would force ProseMirror to close the open paragraph\n\t// first, creating a ghost empty <p></p>.\n\tconst replaceFrom = id === 'body' ? 0 : startPos;\n\ttr.replaceWith(replaceFrom, endPos, fragment);\n\ttr.setMeta('addToHistory', false);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Convenience shorthands (body = first section)\n// ---------------------------------------------------------------------------\n\n/** Extract BikEditorContent for just the body (before the first divider). */\nexport function extractBodyContent(editor: Editor): EditorSnapshot {\n\treturn extractSectionContent(editor, 'body');\n}\n\n// ---------------------------------------------------------------------------\n// Active formats\n// ---------------------------------------------------------------------------\n\nexport function extractActiveFormats(editor: Editor): FormatState {\n\treturn {\n\t\tbold: editor.isActive('bold'),\n\t\titalic: editor.isActive('italic'),\n\t\tunderline: editor.isActive('underline'),\n\t\tstrike: editor.isActive('strike'),\n\t\tbulletList: editor.isActive('bulletList'),\n\t\torderedList: editor.isActive('orderedList'),\n\t\tblockquote: editor.isActive('blockquote'),\n\t\tcodeBlock: editor.isActive('codeBlock'),\n\t\tlink: (() => {\n\t\t\tif (editor.isActive('link')) {\n\t\t\t\treturn { href: editor.getAttributes('link')['href'] ?? '' };\n\t\t\t}\n\t\t\tconst { $from } = editor.state.selection;\n\t\t\tif ($from.pos > 0) {\n\t\t\t\tconst before = $from.doc.resolve($from.pos);\n\t\t\t\tconst linkMark = before.marks().find((m) => m.type.name === 'link');\n\t\t\t\tif (!linkMark) {\n\t\t\t\t\tconst nodeBefore = $from.nodeBefore;\n\t\t\t\t\tconst markOnPrev = nodeBefore?.marks.find(\n\t\t\t\t\t\t(m) => m.type.name === 'link',\n\t\t\t\t\t);\n\t\t\t\t\tif (markOnPrev) {\n\t\t\t\t\t\treturn { href: markOnPrev.attrs['href'] ?? '' };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn { href: linkMark.attrs['href'] ?? '' };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t})(),\n\t\ttextAlign: editor.isActive({ textAlign: 'center' })\n\t\t\t? 'center'\n\t\t\t: editor.isActive({ textAlign: 'right' })\n\t\t\t? 'right'\n\t\t\t: editor.isActive({ textAlign: 'justify' })\n\t\t\t? 'justify'\n\t\t\t: editor.isActive({ textAlign: 'left' })\n\t\t\t? 'left'\n\t\t\t: null,\n\t\tfontFamily: editor.getAttributes('textStyle')['fontFamily'] ?? null,\n\t\tfontSize: editor.getAttributes('textStyle')['fontSize'] ?? null,\n\t\tcolor: editor.getAttributes('textStyle')['color'] ?? null,\n\t\thighlight: editor.isActive('highlight')\n\t\t\t? editor.getAttributes('highlight')['color'] ?? 'default'\n\t\t\t: null,\n\t\tsuperscript: editor.isActive('superscript'),\n\t\tsubscript: editor.isActive('subscript'),\n\t};\n}\n\nexport function extractContent(editor: Editor): EditorSnapshot {\n\tconst html = toPortableHtml(editor.getHTML());\n\tconst normalized = normalizeHardBreaks(editor.state.doc.content);\n\tconst tempDoc = editor.schema.node('doc', null, normalized);\n\tconst text = tempDoc.textBetween(0, tempDoc.content.size, '\\n\\n');\n\treturn {\n\t\thtml,\n\t\ttext,\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount: text.length,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Section position helpers (used by insertAtSectionStart/End and appendBodyContent)\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the ProseMirror position immediately after a section's opening divider\n * (i.e. the start of the section's own content).\n * For `'body'`, returns 1 (beginning of the document).\n * Returns -1 if the named section's divider is not found.\n */\nexport function findSectionStartPos(editor: Editor, sectionId: string): number {\n\tif (sectionId === 'body') return 1;\n\tlet startPos = -1;\n\teditor.state.doc.descendants((node, pos) => {\n\t\tif (startPos !== -1) return false;\n\t\tif (\n\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t) {\n\t\t\tstartPos = pos + node.nodeSize; // position right after the divider\n\t\t}\n\t});\n\treturn startPos;\n}\n\n/**\n * Returns the ProseMirror position at the end of a named section's content:\n * - For `'body'`: position of the first section divider, or end of document.\n * - For a named section: position of the next divider, or end of document.\n */\nexport function findSectionEndPos(editor: Editor, sectionId: string): number {\n\tconst doc = editor.state.doc;\n\tconst docSize = doc.content.size;\n\n\tif (sectionId === 'body') {\n\t\tlet firstDividerPos = -1;\n\t\tdoc.descendants((node, pos) => {\n\t\t\tif (firstDividerPos !== -1) return false;\n\t\t\tif (node.type.name === 'sectionDivider') {\n\t\t\t\tfirstDividerPos = pos;\n\t\t\t}\n\t\t});\n\t\treturn firstDividerPos !== -1 ? firstDividerPos : docSize;\n\t}\n\n\tlet passedSection = false;\n\tlet nextDividerPos = -1;\n\tdoc.descendants((node, pos) => {\n\t\tif (nextDividerPos !== -1) return false;\n\t\tif (!passedSection) {\n\t\t\tif (\n\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t) {\n\t\t\t\tpassedSection = true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (node.type.name === 'sectionDivider') {\n\t\t\tnextDividerPos = pos;\n\t\t}\n\t});\n\treturn nextDividerPos !== -1 ? nextDividerPos : docSize;\n}\n"],"names":["normalizeHtml","html","replace","toPortableHtml","div","document","createElement","innerHTML","p","Array","from","querySelectorAll","childNodes","length","appendChild","lastChild","HTMLBRElement","SECTION_DIVIDER_HTML","id","getBodyHtml","_a","extractAllSectionsFromHtml","get","sections","Map","dividerRegex","dividers","match","exec","push","index","endIndex","set","slice","i","start","end","extractSectionContent","editor","startPos","findSectionStartPos","text","isEmpty","characterCount","endPos","findSectionEndPos","state","doc","container","serializer","DOMSerializer","fromSchema","schema","serializeFragment","content","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","normalized","normalizeHardBreaks","tempDoc","textBetween","substring","normalised","dom","DOMParser","parseSlice","to","tr","replaceRange","view","dispatch","dividerHtml","commands","insertContentAt","updateSelection","fragment","parse","parseHtmlToNodes","replaceFrom","replaceWith","setMeta"],"mappings":"4LAqBM,SAAUA,EAAcC,GAC7B,OAAOA,EACLC,QAAQ,mBAAoB,IAC5BA,QAAQ,sCAAuC,OAClD,CAYM,SAAUC,EAAeF,GAC9B,MAAMG,EAAMC,SAASC,cAAc,OACnCF,EAAIG,UAAYN,EAChB,IAAK,MAAMO,KAAKC,MAAMC,KAAKN,EAAIO,iBAAiB,MAAO,CACtD,GAA4B,IAAxBH,EAAEI,WAAWC,OAAc,CAC9BL,EAAEM,YAAYT,SAASC,cAAc,OACrC,QACA,CACYE,EAAEO,qBACKC,eAAiBR,EAAEI,WAAWC,OAAS,GAC1DL,EAAEM,YAAYT,SAASC,cAAc,MAEtC,CACD,OAAOF,EAAIG,SACZ,OA+BaU,EAAwBC,GACpC,8BAA8BA,yEAyCzB,SAAUC,EAAYlB,SAC3B,IAAKA,EAAM,MAAO,GAElB,OAA+B,QAAxBmB,EADUC,EAA2BpB,GAC5BqB,IAAI,eAAW,IAAAF,EAAAA,EAAAnB,CAChC,CAYM,SAAUoB,EAA2BpB,GAC1C,MAAMsB,EAAW,IAAIC,IACfC,EACL,0DACKC,EAAmE,GAEzE,IAAIC,EACJ,KAA6C,QAArCA,EAAQF,EAAaG,KAAK3B,KACjCyB,EAASG,KAAK,CACbX,GAAIS,EAAM,GACVG,MAAOH,EAAMG,MACbC,SAAUJ,EAAMG,MAAQH,EAAM,GAAGd,SAInC,GAAwB,IAApBa,EAASb,OAEZ,OADAU,EAASS,IAAI,OAAQ/B,GACdsB,EAGRA,EAASS,IAAI,OAAQ/B,EAAKgC,MAAM,EAAGP,EAAS,GAAGI,QAC/C,IAAK,IAAII,EAAI,EAAGA,EAAIR,EAASb,OAAQqB,IAAK,CACzC,MAAMC,EAAQT,EA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OnD,EAAYlB,GACzB,OAAOA,EAAK2G,UAAUtC,EAAKzD,OAC5B,2BAzEgB,SAAiByB,EAAgBrC,GAChD,MAAM4G,EAAa7G,EAAcC,GAC3B6G,EAAMzG,SAASC,cAAc,OACnCwG,EAAIvG,UAAYsG,EAChB,MAAM5E,EAAQ8E,EAASA,UAAC5D,WAAWb,EAAOc,QAAQ4D,WAAWF,GAE7D,GAAmB,IAAf7E,EAAMiC,KAAY,OAEtB,MAAMxD,KAAEA,EAAIuG,GAAEA,GAAO3E,EAAOQ,MAAMuC,UAC5B6B,EAAK5E,EAAOQ,MAAMoE,GAAGC,aAAazG,EAAMuG,EAAIhF,GAClDK,EAAO8E,KAAKC,SAASH,EACtB,qEAgIC5E,EACApB,EACAjB,GAEA,MAAMsC,EAAWC,EAAoBF,EAAQpB,GAC7C,IAAkB,IAAdqB,EAAiB,CACpB,MAAMK,EAASN,EAAOQ,MAAMC,IAAIO,QAAQY,KAClCoD,EAAcrG,EAAqBC,GAAMjB,EAI/C,YAHAqC,EAAOiF,SAASC,gBAAgB5E,EAAQ0E,EAAa,CACpDG,iBAAiB,GAGlB,CACD,MAAM7E,EAASC,EAAkBP,EAAQpB,GACnCwG,EA3BP,SAA0BpF,EAAgBrC,GACzC,MAAM+C,EAAY3C,SAASC,cAAc,OAEzC,OADA0C,EAAUzC,UAAYN,EACf8G,EAASA,UAAC5D,WAAWb,EAAOc,QAAQuE,MAAM3E,GAAWM,OAC7D,CAuBkBsE,CAAiBtF,EAAQrC,IACpCiH,GAAEA,GAAO5E,EAAOQ,MAKhB+E,EAAqB,SAAP3G,EAAgB,EAAIqB,EACxC2E,EAAGY,YAAYD,EAAajF,EAAQ8E,GACpCR,EAAGa,QAAQ,gBAAgB,GAC3BzF,EAAO8E,KAAKC,SAASH,EACtB"}
|
|
1
|
+
{"version":3,"file":"BikEditor.utils.js","sources":["../../../src/editor/BikEditor.utils.ts"],"sourcesContent":["import { Editor } from '@tiptap/core';\nimport { DOMParser, DOMSerializer } from 'prosemirror-model';\nimport { EditorSnapshot, FormatState } from './BikEditor.types';\nimport { normalizeHardBreaks } from './extensions/plainClipboard/pasteUtils';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * 1. Strip all `<span>` tags first (keeps inner content). This exposes\n * bare `<br>` inside otherwise-empty paragraphs like Quill's\n * `<p><span class=\"ql-cursor\"><br></span></p>`.\n * 2. Then convert `<p><br></p>` → `<p></p>`. ProseMirror parses `<p></p>`\n * as an empty paragraph node and adds its own DOM `<br>` for cursor\n * positioning — one blank line, correct height. Leaving the `<br>`\n * would create a `hard_break` child AND the cursor `<br>`, producing\n * double-height blank lines.\n */\nexport function normalizeHtml(html: string): string {\n\treturn html\n\t\t.replace(/<\\/?span[^>]*>/gi, '')\n\t\t.replace(/(<p[^>]*>)\\s*<br\\s*\\/?>\\s*(<\\/p>)/gi, '$1$2');\n}\n\n/**\n * Make editor HTML portable across email clients and chat renderers.\n *\n * 1. Double a trailing `<br>` in content paragraphs so the blank line is\n * visible. A single trailing `<br>` before `</p>` is swallowed by most\n * email clients; `<br><br>` renders as a visible blank line (matches\n * Gmail's output).\n * 2. Convert empty `<p></p>` to `<p><br></p>` — email clients collapse\n * zero-height paragraphs without a `<br>`.\n */\nexport function toPortableHtml(html: string): string {\n\tconst div = document.createElement('div');\n\tdiv.innerHTML = html;\n\tfor (const p of Array.from(div.querySelectorAll('p'))) {\n\t\tp.style.margin = '0';\n\t\tif (p.childNodes.length === 0) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t\tcontinue;\n\t\t}\n\t\tconst last = p.lastChild;\n\t\tif (last instanceof HTMLBRElement && p.childNodes.length > 1) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t}\n\t}\n\treturn div.innerHTML;\n}\n\n// ---------------------------------------------------------------------------\n// Inline content insertion\n// ---------------------------------------------------------------------------\n\n/**\n * Insert HTML at the current cursor position, merging the first paragraph\n * inline while preserving the block structure of subsequent paragraphs/lists.\n *\n * Uses `parseSlice` which returns an open-ended Slice — the first block merges\n * at the cursor, middle blocks stay intact, and the last block merges with any\n * text that follows the cursor.\n */\nexport function insertInlineHtml(editor: Editor, html: string): void {\n\tconst normalised = normalizeHtml(html);\n\tconst dom = document.createElement('div');\n\tdom.innerHTML = normalised;\n\tconst slice = DOMParser.fromSchema(editor.schema).parseSlice(dom);\n\n\tif (slice.size === 0) return;\n\n\tconst { from, to } = editor.state.selection;\n\tconst tr = editor.state.tr.replaceRange(from, to, slice);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Section divider HTML\n// ---------------------------------------------------------------------------\n\nexport const SECTION_DIVIDER_HTML = (id: string) =>\n\t`<div data-section-divider=\"${id}\" style=\"display:none;height:0;line-height:0;overflow:hidden;\"></div>`;\n\n/**\n * Build initial HTML for an editor with one or more named sections below the body.\n * Each section is separated by an invisible divider node.\n *\n * @example\n * buildSectionedContent('<p>Body</p>', [\n * { id: 'signature', content: '<p>Alice</p>' },\n * { id: 'forwarded', content: '<p>--- fwd ---</p>' },\n * ])\n */\nexport function buildSectionedContent(\n\tbody: string,\n\tsections: Array<{ id: string; content: string }>,\n): string {\n\tlet html = body;\n\tfor (const s of sections) {\n\t\thtml += SECTION_DIVIDER_HTML(s.id) + s.content;\n\t}\n\treturn html;\n}\n\n// ---------------------------------------------------------------------------\n// Section extraction\n// ---------------------------------------------------------------------------\n\n/**\n * Parse the editor HTML into a Map of sectionId → raw HTML string.\n * The special key `'body'` always holds the content before the first divider.\n * Map iteration order matches document order.\n */\nexport function extractAllSections(editor: Editor): Map<string, string> {\n\treturn extractAllSectionsFromHtml(editor.getHTML());\n}\n\n/**\n * Extract just the body portion (everything before the first section divider)\n * from an HTML string produced by BikEditor. Safe to call on plain HTML too —\n * returns the full string when no dividers are present.\n */\nexport function getBodyHtml(html: string): string {\n\tif (!html) return '';\n\tconst sections = extractAllSectionsFromHtml(html);\n\treturn sections.get('body') ?? html;\n}\n\n/**\n * Extract everything from the first section divider onward (dividers + their\n * content). Returns an empty string when there are no sections.\n */\nexport function getSectionsHtml(html: string): string {\n\tif (!html) return '';\n\tconst body = getBodyHtml(html);\n\treturn html.substring(body.length);\n}\n\nexport function extractAllSectionsFromHtml(html: string): Map<string, string> {\n\tconst sections = new Map<string, string>();\n\tconst dividerRegex =\n\t\t/<div[^>]*data-section-divider=\"([^\"]*)[^>]*>\\s*<\\/div>/g;\n\tconst dividers: Array<{ id: string; index: number; endIndex: number }> = [];\n\n\tlet match: RegExpExecArray | null;\n\twhile ((match = dividerRegex.exec(html)) !== null) {\n\t\tdividers.push({\n\t\t\tid: match[1],\n\t\t\tindex: match.index,\n\t\t\tendIndex: match.index + match[0].length,\n\t\t});\n\t}\n\n\tif (dividers.length === 0) {\n\t\tsections.set('body', html);\n\t\treturn sections;\n\t}\n\n\tsections.set('body', html.slice(0, dividers[0].index));\n\tfor (let i = 0; i < dividers.length; i++) {\n\t\tconst start = dividers[i].endIndex;\n\t\tconst end = i + 1 < dividers.length ? dividers[i + 1].index : html.length;\n\t\tsections.set(dividers[i].id, html.slice(start, end));\n\t}\n\n\treturn sections;\n}\n\n/** Returns BikEditorContent for a single named section (or 'body'). */\nexport function extractSectionContent(\n\teditor: Editor,\n\tid: string,\n): EditorSnapshot {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1)\n\t\treturn { html: '', text: '', isEmpty: true, characterCount: 0 };\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst slice = editor.state.doc.slice(startPos, endPos);\n\tconst container = document.createElement('div');\n\tconst serializer = DOMSerializer.fromSchema(editor.schema);\n\tcontainer.appendChild(serializer.serializeFragment(slice.content));\n\tconst html = toPortableHtml(container.innerHTML);\n\tconst text = container.textContent ?? '';\n\treturn { html, text, isEmpty: !text.trim(), characterCount: text.length };\n}\n\n/**\n * Parse an HTML string into ProseMirror nodes using the editor's schema.\n */\nfunction parseHtmlToNodes(editor: Editor, html: string) {\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = html;\n\treturn DOMParser.fromSchema(editor.schema).parse(container).content;\n}\n\n/**\n * Replace the content of a single named section without touching others.\n * Uses a ProseMirror transaction to replace only the target range,\n * preserving undo history and other sections' state.\n * If the section doesn't exist yet, it is appended at the end of the document.\n */\nexport function setSectionContentInEditor(\n\teditor: Editor,\n\tid: string,\n\thtml: string,\n): void {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1) {\n\t\tconst endPos = editor.state.doc.content.size;\n\t\tconst dividerHtml = SECTION_DIVIDER_HTML(id) + html;\n\t\teditor.commands.insertContentAt(endPos, dividerHtml, {\n\t\t\tupdateSelection: false,\n\t\t});\n\t\treturn;\n\t}\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst fragment = parseHtmlToNodes(editor, html);\n\tconst { tr } = editor.state;\n\t// For body, replace from position 0 (before the first paragraph's opening\n\t// boundary) so ProseMirror swaps entire block nodes cleanly. Position 1\n\t// (inside the paragraph) would force ProseMirror to close the open paragraph\n\t// first, creating a ghost empty <p></p>.\n\tconst replaceFrom = id === 'body' ? 0 : startPos;\n\ttr.replaceWith(replaceFrom, endPos, fragment);\n\ttr.setMeta('addToHistory', false);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Convenience shorthands (body = first section)\n// ---------------------------------------------------------------------------\n\n/** Extract BikEditorContent for just the body (before the first divider). */\nexport function extractBodyContent(editor: Editor): EditorSnapshot {\n\treturn extractSectionContent(editor, 'body');\n}\n\n// ---------------------------------------------------------------------------\n// Active formats\n// ---------------------------------------------------------------------------\n\nexport function extractActiveFormats(editor: Editor): FormatState {\n\treturn {\n\t\tbold: editor.isActive('bold'),\n\t\titalic: editor.isActive('italic'),\n\t\tunderline: editor.isActive('underline'),\n\t\tstrike: editor.isActive('strike'),\n\t\tbulletList: editor.isActive('bulletList'),\n\t\torderedList: editor.isActive('orderedList'),\n\t\tblockquote: editor.isActive('blockquote'),\n\t\tcodeBlock: editor.isActive('codeBlock'),\n\t\tlink: (() => {\n\t\t\tif (editor.isActive('link')) {\n\t\t\t\treturn { href: editor.getAttributes('link')['href'] ?? '' };\n\t\t\t}\n\t\t\tconst { $from } = editor.state.selection;\n\t\t\tif ($from.pos > 0) {\n\t\t\t\tconst before = $from.doc.resolve($from.pos);\n\t\t\t\tconst linkMark = before.marks().find((m) => m.type.name === 'link');\n\t\t\t\tif (!linkMark) {\n\t\t\t\t\tconst nodeBefore = $from.nodeBefore;\n\t\t\t\t\tconst markOnPrev = nodeBefore?.marks.find(\n\t\t\t\t\t\t(m) => m.type.name === 'link',\n\t\t\t\t\t);\n\t\t\t\t\tif (markOnPrev) {\n\t\t\t\t\t\treturn { href: markOnPrev.attrs['href'] ?? '' };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn { href: linkMark.attrs['href'] ?? '' };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t})(),\n\t\ttextAlign: editor.isActive({ textAlign: 'center' })\n\t\t\t? 'center'\n\t\t\t: editor.isActive({ textAlign: 'right' })\n\t\t\t? 'right'\n\t\t\t: editor.isActive({ textAlign: 'justify' })\n\t\t\t? 'justify'\n\t\t\t: editor.isActive({ textAlign: 'left' })\n\t\t\t? 'left'\n\t\t\t: null,\n\t\tfontFamily: editor.getAttributes('textStyle')['fontFamily'] ?? null,\n\t\tfontSize: editor.getAttributes('textStyle')['fontSize'] ?? null,\n\t\tcolor: editor.getAttributes('textStyle')['color'] ?? null,\n\t\thighlight: editor.isActive('highlight')\n\t\t\t? editor.getAttributes('highlight')['color'] ?? 'default'\n\t\t\t: null,\n\t\tsuperscript: editor.isActive('superscript'),\n\t\tsubscript: editor.isActive('subscript'),\n\t};\n}\n\nexport function extractContent(editor: Editor): EditorSnapshot {\n\tconst html = toPortableHtml(editor.getHTML());\n\tconst normalized = normalizeHardBreaks(editor.state.doc.content);\n\tconst tempDoc = editor.schema.node('doc', null, normalized);\n\tconst text = tempDoc.textBetween(0, tempDoc.content.size, '\\n', '\\n');\n\treturn {\n\t\thtml,\n\t\ttext,\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount: text.length,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Section position helpers (used by insertAtSectionStart/End and appendBodyContent)\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the ProseMirror position immediately after a section's opening divider\n * (i.e. the start of the section's own content).\n * For `'body'`, returns 1 (beginning of the document).\n * Returns -1 if the named section's divider is not found.\n */\nexport function findSectionStartPos(editor: Editor, sectionId: string): number {\n\tif (sectionId === 'body') return 1;\n\tlet startPos = -1;\n\teditor.state.doc.descendants((node, pos) => {\n\t\tif (startPos !== -1) return false;\n\t\tif (\n\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t) {\n\t\t\tstartPos = pos + node.nodeSize; // position right after the divider\n\t\t}\n\t});\n\treturn startPos;\n}\n\n/**\n * Returns the ProseMirror position at the end of a named section's content:\n * - For `'body'`: position of the first section divider, or end of document.\n * - For a named section: position of the next divider, or end of document.\n */\nexport function findSectionEndPos(editor: Editor, sectionId: string): number {\n\tconst doc = editor.state.doc;\n\tconst docSize = doc.content.size;\n\n\tif (sectionId === 'body') {\n\t\tlet firstDividerPos = -1;\n\t\tdoc.descendants((node, pos) => {\n\t\t\tif (firstDividerPos !== -1) return false;\n\t\t\tif (node.type.name === 'sectionDivider') {\n\t\t\t\tfirstDividerPos = pos;\n\t\t\t}\n\t\t});\n\t\treturn firstDividerPos !== -1 ? firstDividerPos : docSize;\n\t}\n\n\tlet passedSection = false;\n\tlet nextDividerPos = -1;\n\tdoc.descendants((node, pos) => {\n\t\tif (nextDividerPos !== -1) return false;\n\t\tif (!passedSection) {\n\t\t\tif (\n\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t) {\n\t\t\t\tpassedSection = true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (node.type.name === 'sectionDivider') {\n\t\t\tnextDividerPos = pos;\n\t\t}\n\t});\n\treturn nextDividerPos !== -1 ? nextDividerPos : docSize;\n}\n"],"names":["normalizeHtml","html","replace","toPortableHtml","div","document","createElement","innerHTML","p","Array","from","querySelectorAll","style","margin","childNodes","length","appendChild","lastChild","HTMLBRElement","SECTION_DIVIDER_HTML","id","getBodyHtml","_a","extractAllSectionsFromHtml","get","sections","Map","dividerRegex","dividers","match","exec","push","index","endIndex","set","slice","i","start","end","extractSectionContent","editor","startPos","findSectionStartPos","text","isEmpty","characterCount","endPos","findSectionEndPos","state","doc","container","serializer","DOMSerializer","fromSchema","schema","serializeFragment","content","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","normalized","normalizeHardBreaks","tempDoc","textBetween","substring","normalised","dom","DOMParser","parseSlice","to","tr","replaceRange","view","dispatch","dividerHtml","commands","insertContentAt","updateSelection","fragment","parse","parseHtmlToNodes","replaceFrom","replaceWith","setMeta"],"mappings":"4LAqBM,SAAUA,EAAcC,GAC7B,OAAOA,EACLC,QAAQ,mBAAoB,IAC5BA,QAAQ,sCAAuC,OAClD,CAYM,SAAUC,EAAeF,GAC9B,MAAMG,EAAMC,SAASC,cAAc,OACnCF,EAAIG,UAAYN,EAChB,IAAK,MAAMO,KAAKC,MAAMC,KAAKN,EAAIO,iBAAiB,MAAO,CAEtD,GADAH,EAAEI,MAAMC,OAAS,IACW,IAAxBL,EAAEM,WAAWC,OAAc,CAC9BP,EAAEQ,YAAYX,SAASC,cAAc,OACrC,QACA,CACYE,EAAES,qBACKC,eAAiBV,EAAEM,WAAWC,OAAS,GAC1DP,EAAEQ,Y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ASN,EAAOQ,MAAMC,IAAIO,QAAQY,KAClCoD,EAAcrG,EAAqBC,GAAMnB,EAI/C,YAHAuC,EAAOiF,SAASC,gBAAgB5E,EAAQ0E,EAAa,CACpDG,iBAAiB,GAGlB,CACD,MAAM7E,EAASC,EAAkBP,EAAQpB,GACnCwG,EA3BP,SAA0BpF,EAAgBvC,GACzC,MAAMiD,EAAY7C,SAASC,cAAc,OAEzC,OADA4C,EAAU3C,UAAYN,EACfgH,EAASA,UAAC5D,WAAWb,EAAOc,QAAQuE,MAAM3E,GAAWM,OAC7D,CAuBkBsE,CAAiBtF,EAAQvC,IACpCmH,GAAEA,GAAO5E,EAAOQ,MAKhB+E,EAAqB,SAAP3G,EAAgB,EAAIqB,EACxC2E,EAAGY,YAAYD,EAAajF,EAAQ8E,GACpCR,EAAGa,QAAQ,gBAAgB,GAC3BzF,EAAO8E,KAAKC,SAASH,EACtB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DOMSerializer as t,DOMParser as e}from"../node_modules/prosemirror-model/dist/index.js";import{normalizeHardBreaks as n}from"./extensions/plainClipboard/pasteUtils.js";function i(t){return t.replace(/<\/?span[^>]*>/gi,"").replace(/(<p[^>]*>)\s*<br\s*\/?>\s*(<\/p>)/gi,"$1$2")}function r(t){const e=document.createElement("div");e.innerHTML=t;for(const t of Array.from(e.querySelectorAll("p"))){if(0===t.childNodes.length){t.appendChild(document.createElement("br"));continue}t.lastChild instanceof HTMLBRElement&&t.childNodes.length>1&&t.appendChild(document.createElement("br"))}return e.innerHTML}function o(t,n){const r=i(n),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 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 o=p(e,n);if(-1===o)return{html:"",text:"",isEmpty:!0,characterCount:0};const s=g(e,n),c=e.state.doc.slice(o,s),l=document.createElement("div"),d=t.fromSchema(e.schema);l.appendChild(d.serializeFragment(c.content));const u=r(l.innerHTML),a=null!==(i=l.textContent)&&void 0!==i?i:"";return{html:u,text:a,isEmpty:!a.trim(),characterCount:a.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 h(t){return a(t,"body")}function m(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){const e=r(t.getHTML()),i=n(t.state.doc.content),o=t.schema.node("doc",null,i),s=o.textBetween(0,o.content.size,"\n\n");return{html:e,text:s,isEmpty:t.isEmpty,characterCount:s.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,m as extractActiveFormats,u as extractAllSectionsFromHtml,h as extractBodyContent,v as extractContent,a as extractSectionContent,g as findSectionEndPos,p as findSectionStartPos,l as getBodyHtml,d as getSectionsHtml,o as insertInlineHtml,i as normalizeHtml,f as setSectionContentInEditor,r as toPortableHtml};
|
|
1
|
+
import{DOMSerializer as t,DOMParser as e}from"../node_modules/prosemirror-model/dist/index.js";import{normalizeHardBreaks as n}from"./extensions/plainClipboard/pasteUtils.js";function i(t){return t.replace(/<\/?span[^>]*>/gi,"").replace(/(<p[^>]*>)\s*<br\s*\/?>\s*(<\/p>)/gi,"$1$2")}function r(t){const e=document.createElement("div");e.innerHTML=t;for(const t of Array.from(e.querySelectorAll("p"))){if(t.style.margin="0",0===t.childNodes.length){t.appendChild(document.createElement("br"));continue}t.lastChild instanceof HTMLBRElement&&t.childNodes.length>1&&t.appendChild(document.createElement("br"))}return e.innerHTML}function o(t,n){const r=i(n),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 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 o=p(e,n);if(-1===o)return{html:"",text:"",isEmpty:!0,characterCount:0};const s=g(e,n),c=e.state.doc.slice(o,s),l=document.createElement("div"),d=t.fromSchema(e.schema);l.appendChild(d.serializeFragment(c.content));const u=r(l.innerHTML),a=null!==(i=l.textContent)&&void 0!==i?i:"";return{html:u,text:a,isEmpty:!a.trim(),characterCount:a.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 h(t){return a(t,"body")}function m(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){const e=r(t.getHTML()),i=n(t.state.doc.content),o=t.schema.node("doc",null,i),s=o.textBetween(0,o.content.size,"\n","\n");return{html:e,text:s,isEmpty:t.isEmpty,characterCount:s.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,m as extractActiveFormats,u as extractAllSectionsFromHtml,h as extractBodyContent,v as extractContent,a as extractSectionContent,g as findSectionEndPos,p as findSectionStartPos,l as getBodyHtml,d as getSectionsHtml,o as insertInlineHtml,i as normalizeHtml,f as setSectionContentInEditor,r as toPortableHtml};
|
|
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 } from 'prosemirror-model';\nimport { EditorSnapshot, FormatState } from './BikEditor.types';\nimport { normalizeHardBreaks } from './extensions/plainClipboard/pasteUtils';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * 1. Strip all `<span>` tags first (keeps inner content). This exposes\n * bare `<br>` inside otherwise-empty paragraphs like Quill's\n * `<p><span class=\"ql-cursor\"><br></span></p>`.\n * 2. Then convert `<p><br></p>` → `<p></p>`. ProseMirror parses `<p></p>`\n * as an empty paragraph node and adds its own DOM `<br>` for cursor\n * positioning — one blank line, correct height. Leaving the `<br>`\n * would create a `hard_break` child AND the cursor `<br>`, producing\n * double-height blank lines.\n */\nexport function normalizeHtml(html: string): string {\n\treturn html\n\t\t.replace(/<\\/?span[^>]*>/gi, '')\n\t\t.replace(/(<p[^>]*>)\\s*<br\\s*\\/?>\\s*(<\\/p>)/gi, '$1$2');\n}\n\n/**\n * Make editor HTML portable across email clients and chat renderers.\n *\n * 1. Double a trailing `<br>` in content paragraphs so the blank line is\n * visible. A single trailing `<br>` before `</p>` is swallowed by most\n * email clients; `<br><br>` renders as a visible blank line (matches\n * Gmail's output).\n * 2. Convert empty `<p></p>` to `<p><br></p>` — email clients collapse\n * zero-height paragraphs without a `<br>`.\n */\nexport function toPortableHtml(html: string): string {\n\tconst div = document.createElement('div');\n\tdiv.innerHTML = html;\n\tfor (const p of Array.from(div.querySelectorAll('p'))) {\n\t\tif (p.childNodes.length === 0) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t\tcontinue;\n\t\t}\n\t\tconst last = p.lastChild;\n\t\tif (last instanceof HTMLBRElement && p.childNodes.length > 1) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t}\n\t}\n\treturn div.innerHTML;\n}\n\n// ---------------------------------------------------------------------------\n// Inline content insertion\n// ---------------------------------------------------------------------------\n\n/**\n * Insert HTML at the current cursor position, merging the first paragraph\n * inline while preserving the block structure of subsequent paragraphs/lists.\n *\n * Uses `parseSlice` which returns an open-ended Slice — the first block merges\n * at the cursor, middle blocks stay intact, and the last block merges with any\n * text that follows the cursor.\n */\nexport function insertInlineHtml(editor: Editor, html: string): void {\n\tconst normalised = normalizeHtml(html);\n\tconst dom = document.createElement('div');\n\tdom.innerHTML = normalised;\n\tconst slice = DOMParser.fromSchema(editor.schema).parseSlice(dom);\n\n\tif (slice.size === 0) return;\n\n\tconst { from, to } = editor.state.selection;\n\tconst tr = editor.state.tr.replaceRange(from, to, slice);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Section divider HTML\n// ---------------------------------------------------------------------------\n\nexport const SECTION_DIVIDER_HTML = (id: string) =>\n\t`<div data-section-divider=\"${id}\" style=\"display:none;height:0;line-height:0;overflow:hidden;\"></div>`;\n\n/**\n * Build initial HTML for an editor with one or more named sections below the body.\n * Each section is separated by an invisible divider node.\n *\n * @example\n * buildSectionedContent('<p>Body</p>', [\n * { id: 'signature', content: '<p>Alice</p>' },\n * { id: 'forwarded', content: '<p>--- fwd ---</p>' },\n * ])\n */\nexport function buildSectionedContent(\n\tbody: string,\n\tsections: Array<{ id: string; content: string }>,\n): string {\n\tlet html = body;\n\tfor (const s of sections) {\n\t\thtml += SECTION_DIVIDER_HTML(s.id) + s.content;\n\t}\n\treturn html;\n}\n\n// ---------------------------------------------------------------------------\n// Section extraction\n// ---------------------------------------------------------------------------\n\n/**\n * Parse the editor HTML into a Map of sectionId → raw HTML string.\n * The special key `'body'` always holds the content before the first divider.\n * Map iteration order matches document order.\n */\nexport function extractAllSections(editor: Editor): Map<string, string> {\n\treturn extractAllSectionsFromHtml(editor.getHTML());\n}\n\n/**\n * Extract just the body portion (everything before the first section divider)\n * from an HTML string produced by BikEditor. Safe to call on plain HTML too —\n * returns the full string when no dividers are present.\n */\nexport function getBodyHtml(html: string): string {\n\tif (!html) return '';\n\tconst sections = extractAllSectionsFromHtml(html);\n\treturn sections.get('body') ?? html;\n}\n\n/**\n * Extract everything from the first section divider onward (dividers + their\n * content). Returns an empty string when there are no sections.\n */\nexport function getSectionsHtml(html: string): string {\n\tif (!html) return '';\n\tconst body = getBodyHtml(html);\n\treturn html.substring(body.length);\n}\n\nexport function extractAllSectionsFromHtml(html: string): Map<string, string> {\n\tconst sections = new Map<string, string>();\n\tconst dividerRegex =\n\t\t/<div[^>]*data-section-divider=\"([^\"]*)[^>]*>\\s*<\\/div>/g;\n\tconst dividers: Array<{ id: string; index: number; endIndex: number }> = [];\n\n\tlet match: RegExpExecArray | null;\n\twhile ((match = dividerRegex.exec(html)) !== null) {\n\t\tdividers.push({\n\t\t\tid: match[1],\n\t\t\tindex: match.index,\n\t\t\tendIndex: match.index + match[0].length,\n\t\t});\n\t}\n\n\tif (dividers.length === 0) {\n\t\tsections.set('body', html);\n\t\treturn sections;\n\t}\n\n\tsections.set('body', html.slice(0, dividers[0].index));\n\tfor (let i = 0; i < dividers.length; i++) {\n\t\tconst start = dividers[i].endIndex;\n\t\tconst end = i + 1 < dividers.length ? dividers[i + 1].index : html.length;\n\t\tsections.set(dividers[i].id, html.slice(start, end));\n\t}\n\n\treturn sections;\n}\n\n/** Returns BikEditorContent for a single named section (or 'body'). */\nexport function extractSectionContent(\n\teditor: Editor,\n\tid: string,\n): EditorSnapshot {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1)\n\t\treturn { html: '', text: '', isEmpty: true, characterCount: 0 };\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst slice = editor.state.doc.slice(startPos, endPos);\n\tconst container = document.createElement('div');\n\tconst serializer = DOMSerializer.fromSchema(editor.schema);\n\tcontainer.appendChild(serializer.serializeFragment(slice.content));\n\tconst html = toPortableHtml(container.innerHTML);\n\tconst text = container.textContent ?? '';\n\treturn { html, text, isEmpty: !text.trim(), characterCount: text.length };\n}\n\n/**\n * Parse an HTML string into ProseMirror nodes using the editor's schema.\n */\nfunction parseHtmlToNodes(editor: Editor, html: string) {\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = html;\n\treturn DOMParser.fromSchema(editor.schema).parse(container).content;\n}\n\n/**\n * Replace the content of a single named section without touching others.\n * Uses a ProseMirror transaction to replace only the target range,\n * preserving undo history and other sections' state.\n * If the section doesn't exist yet, it is appended at the end of the document.\n */\nexport function setSectionContentInEditor(\n\teditor: Editor,\n\tid: string,\n\thtml: string,\n): void {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1) {\n\t\tconst endPos = editor.state.doc.content.size;\n\t\tconst dividerHtml = SECTION_DIVIDER_HTML(id) + html;\n\t\teditor.commands.insertContentAt(endPos, dividerHtml, {\n\t\t\tupdateSelection: false,\n\t\t});\n\t\treturn;\n\t}\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst fragment = parseHtmlToNodes(editor, html);\n\tconst { tr } = editor.state;\n\t// For body, replace from position 0 (before the first paragraph's opening\n\t// boundary) so ProseMirror swaps entire block nodes cleanly. Position 1\n\t// (inside the paragraph) would force ProseMirror to close the open paragraph\n\t// first, creating a ghost empty <p></p>.\n\tconst replaceFrom = id === 'body' ? 0 : startPos;\n\ttr.replaceWith(replaceFrom, endPos, fragment);\n\ttr.setMeta('addToHistory', false);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Convenience shorthands (body = first section)\n// ---------------------------------------------------------------------------\n\n/** Extract BikEditorContent for just the body (before the first divider). */\nexport function extractBodyContent(editor: Editor): EditorSnapshot {\n\treturn extractSectionContent(editor, 'body');\n}\n\n// ---------------------------------------------------------------------------\n// Active formats\n// ---------------------------------------------------------------------------\n\nexport function extractActiveFormats(editor: Editor): FormatState {\n\treturn {\n\t\tbold: editor.isActive('bold'),\n\t\titalic: editor.isActive('italic'),\n\t\tunderline: editor.isActive('underline'),\n\t\tstrike: editor.isActive('strike'),\n\t\tbulletList: editor.isActive('bulletList'),\n\t\torderedList: editor.isActive('orderedList'),\n\t\tblockquote: editor.isActive('blockquote'),\n\t\tcodeBlock: editor.isActive('codeBlock'),\n\t\tlink: (() => {\n\t\t\tif (editor.isActive('link')) {\n\t\t\t\treturn { href: editor.getAttributes('link')['href'] ?? '' };\n\t\t\t}\n\t\t\tconst { $from } = editor.state.selection;\n\t\t\tif ($from.pos > 0) {\n\t\t\t\tconst before = $from.doc.resolve($from.pos);\n\t\t\t\tconst linkMark = before.marks().find((m) => m.type.name === 'link');\n\t\t\t\tif (!linkMark) {\n\t\t\t\t\tconst nodeBefore = $from.nodeBefore;\n\t\t\t\t\tconst markOnPrev = nodeBefore?.marks.find(\n\t\t\t\t\t\t(m) => m.type.name === 'link',\n\t\t\t\t\t);\n\t\t\t\t\tif (markOnPrev) {\n\t\t\t\t\t\treturn { href: markOnPrev.attrs['href'] ?? '' };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn { href: linkMark.attrs['href'] ?? '' };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t})(),\n\t\ttextAlign: editor.isActive({ textAlign: 'center' })\n\t\t\t? 'center'\n\t\t\t: editor.isActive({ textAlign: 'right' })\n\t\t\t? 'right'\n\t\t\t: editor.isActive({ textAlign: 'justify' })\n\t\t\t? 'justify'\n\t\t\t: editor.isActive({ textAlign: 'left' })\n\t\t\t? 'left'\n\t\t\t: null,\n\t\tfontFamily: editor.getAttributes('textStyle')['fontFamily'] ?? null,\n\t\tfontSize: editor.getAttributes('textStyle')['fontSize'] ?? null,\n\t\tcolor: editor.getAttributes('textStyle')['color'] ?? null,\n\t\thighlight: editor.isActive('highlight')\n\t\t\t? editor.getAttributes('highlight')['color'] ?? 'default'\n\t\t\t: null,\n\t\tsuperscript: editor.isActive('superscript'),\n\t\tsubscript: editor.isActive('subscript'),\n\t};\n}\n\nexport function extractContent(editor: Editor): EditorSnapshot {\n\tconst html = toPortableHtml(editor.getHTML());\n\tconst normalized = normalizeHardBreaks(editor.state.doc.content);\n\tconst tempDoc = editor.schema.node('doc', null, normalized);\n\tconst text = tempDoc.textBetween(0, tempDoc.content.size, '\\n\\n');\n\treturn {\n\t\thtml,\n\t\ttext,\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount: text.length,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Section position helpers (used by insertAtSectionStart/End and appendBodyContent)\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the ProseMirror position immediately after a section's opening divider\n * (i.e. the start of the section's own content).\n * For `'body'`, returns 1 (beginning of the document).\n * Returns -1 if the named section's divider is not found.\n */\nexport function findSectionStartPos(editor: Editor, sectionId: string): number {\n\tif (sectionId === 'body') return 1;\n\tlet startPos = -1;\n\teditor.state.doc.descendants((node, pos) => {\n\t\tif (startPos !== -1) return false;\n\t\tif (\n\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t) {\n\t\t\tstartPos = pos + node.nodeSize; // position right after the divider\n\t\t}\n\t});\n\treturn startPos;\n}\n\n/**\n * Returns the ProseMirror position at the end of a named section's content:\n * - For `'body'`: position of the first section divider, or end of document.\n * - For a named section: position of the next divider, or end of document.\n */\nexport function findSectionEndPos(editor: Editor, sectionId: string): number {\n\tconst doc = editor.state.doc;\n\tconst docSize = doc.content.size;\n\n\tif (sectionId === 'body') {\n\t\tlet firstDividerPos = -1;\n\t\tdoc.descendants((node, pos) => {\n\t\t\tif (firstDividerPos !== -1) return false;\n\t\t\tif (node.type.name === 'sectionDivider') {\n\t\t\t\tfirstDividerPos = pos;\n\t\t\t}\n\t\t});\n\t\treturn firstDividerPos !== -1 ? firstDividerPos : docSize;\n\t}\n\n\tlet passedSection = false;\n\tlet nextDividerPos = -1;\n\tdoc.descendants((node, pos) => {\n\t\tif (nextDividerPos !== -1) return false;\n\t\tif (!passedSection) {\n\t\t\tif (\n\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t) {\n\t\t\t\tpassedSection = true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (node.type.name === 'sectionDivider') {\n\t\t\tnextDividerPos = pos;\n\t\t}\n\t});\n\treturn nextDividerPos !== -1 ? nextDividerPos : docSize;\n}\n"],"names":["normalizeHtml","html","replace","toPortableHtml","div","document","createElement","innerHTML","p","Array","from","querySelectorAll","childNodes","length","appendChild","lastChild","HTMLBRElement","insertInlineHtml","editor","normalised","dom","slice","DOMParser","fromSchema","schema","parseSlice","size","to","state","selection","tr","replaceRange","view","dispatch","SECTION_DIVIDER_HTML","id","buildSectionedContent","body","sections","s","content","getBodyHtml","_a","extractAllSectionsFromHtml","get","getSectionsHtml","substring","Map","dividerRegex","dividers","match","exec","push","index","endIndex","set","i","start","end","extractSectionContent","startPos","findSectionStartPos","text","isEmpty","characterCount","endPos","findSectionEndPos","doc","container","serializer","DOMSerializer","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","normalized","normalizeHardBreaks","tempDoc","node","textBetween","sectionId","descendants","nodeSize","docSize","firstDividerPos","passedSection","nextDividerPos"],"mappings":"+KAqBM,SAAUA,EAAcC,GAC7B,OAAOA,EACLC,QAAQ,mBAAoB,IAC5BA,QAAQ,sCAAuC,OAClD,CAYM,SAAUC,EAAeF,GAC9B,MAAMG,EAAMC,SAASC,cAAc,OACnCF,EAAIG,UAAYN,EAChB,IAAK,MAAMO,KAAKC,MAAMC,KAAKN,EAAIO,iBAAiB,MAAO,CACtD,GAA4B,IAAxBH,EAAEI,WAAWC,OAAc,CAC9BL,EAAEM,YAAYT,SAASC,cAAc,OACrC,QACA,CACYE,EAAEO,qBACKC,eAAiBR,EAAEI,WAAWC,OAAS,GAC1DL,EAAEM,YAAYT,SAASC,cAAc,MAEtC,CACD,OAAOF,EAAIG,SACZ,CAcgB,SAAAU,EAAiBC,EAAgBjB,GAChD,MAAMkB,EAAanB,EAAcC,GAC3BmB,EAAMf,SAASC,cAAc,OACnCc,EAAIb,UAAYY,EAChB,MAAME,EAAQC,EAAUC,WAAWL,EAAOM,QAAQC,WAAWL,GAE7D,GAAmB,IAAfC,EAAMK,KAAY,OAEtB,MAAMhB,KAAEA,EAAIiB,GAAEA,GAAOT,EAAOU,MAAMC,UAC5BC,EAAKZ,EAAOU,MAAME,GAAGC,aAAarB,EAAMiB,EAAIN,GAClDH,EAAOc,KAAKC,SAASH,EACtB,OAMaI,EAAwBC,GACpC,8BAA8BA,yEAYf,SAAAC,EACfC,EACAC,GAEA,IAAIrC,EAAOoC,EACX,IAAK,MAAME,KAAKD,EACfrC,GAAQiC,EAAqBK,EAAEJ,IAAMI,EAAEC,QAExC,OAAOvC,CACR,CAoBM,SAAUwC,EAAYxC,SAC3B,IAAKA,EAAM,MAAO,GAElB,OAA+B,Q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ts"],"sourcesContent":["import { Editor } from '@tiptap/core';\nimport { DOMParser, DOMSerializer } from 'prosemirror-model';\nimport { EditorSnapshot, FormatState } from './BikEditor.types';\nimport { normalizeHardBreaks } from './extensions/plainClipboard/pasteUtils';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * 1. Strip all `<span>` tags first (keeps inner content). This exposes\n * bare `<br>` inside otherwise-empty paragraphs like Quill's\n * `<p><span class=\"ql-cursor\"><br></span></p>`.\n * 2. Then convert `<p><br></p>` → `<p></p>`. ProseMirror parses `<p></p>`\n * as an empty paragraph node and adds its own DOM `<br>` for cursor\n * positioning — one blank line, correct height. Leaving the `<br>`\n * would create a `hard_break` child AND the cursor `<br>`, producing\n * double-height blank lines.\n */\nexport function normalizeHtml(html: string): string {\n\treturn html\n\t\t.replace(/<\\/?span[^>]*>/gi, '')\n\t\t.replace(/(<p[^>]*>)\\s*<br\\s*\\/?>\\s*(<\\/p>)/gi, '$1$2');\n}\n\n/**\n * Make editor HTML portable across email clients and chat renderers.\n *\n * 1. Double a trailing `<br>` in content paragraphs so the blank line is\n * visible. A single trailing `<br>` before `</p>` is swallowed by most\n * email clients; `<br><br>` renders as a visible blank line (matches\n * Gmail's output).\n * 2. Convert empty `<p></p>` to `<p><br></p>` — email clients collapse\n * zero-height paragraphs without a `<br>`.\n */\nexport function toPortableHtml(html: string): string {\n\tconst div = document.createElement('div');\n\tdiv.innerHTML = html;\n\tfor (const p of Array.from(div.querySelectorAll('p'))) {\n\t\tp.style.margin = '0';\n\t\tif (p.childNodes.length === 0) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t\tcontinue;\n\t\t}\n\t\tconst last = p.lastChild;\n\t\tif (last instanceof HTMLBRElement && p.childNodes.length > 1) {\n\t\t\tp.appendChild(document.createElement('br'));\n\t\t}\n\t}\n\treturn div.innerHTML;\n}\n\n// ---------------------------------------------------------------------------\n// Inline content insertion\n// ---------------------------------------------------------------------------\n\n/**\n * Insert HTML at the current cursor position, merging the first paragraph\n * inline while preserving the block structure of subsequent paragraphs/lists.\n *\n * Uses `parseSlice` which returns an open-ended Slice — the first block merges\n * at the cursor, middle blocks stay intact, and the last block merges with any\n * text that follows the cursor.\n */\nexport function insertInlineHtml(editor: Editor, html: string): void {\n\tconst normalised = normalizeHtml(html);\n\tconst dom = document.createElement('div');\n\tdom.innerHTML = normalised;\n\tconst slice = DOMParser.fromSchema(editor.schema).parseSlice(dom);\n\n\tif (slice.size === 0) return;\n\n\tconst { from, to } = editor.state.selection;\n\tconst tr = editor.state.tr.replaceRange(from, to, slice);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Section divider HTML\n// ---------------------------------------------------------------------------\n\nexport const SECTION_DIVIDER_HTML = (id: string) =>\n\t`<div data-section-divider=\"${id}\" style=\"display:none;height:0;line-height:0;overflow:hidden;\"></div>`;\n\n/**\n * Build initial HTML for an editor with one or more named sections below the body.\n * Each section is separated by an invisible divider node.\n *\n * @example\n * buildSectionedContent('<p>Body</p>', [\n * { id: 'signature', content: '<p>Alice</p>' },\n * { id: 'forwarded', content: '<p>--- fwd ---</p>' },\n * ])\n */\nexport function buildSectionedContent(\n\tbody: string,\n\tsections: Array<{ id: string; content: string }>,\n): string {\n\tlet html = body;\n\tfor (const s of sections) {\n\t\thtml += SECTION_DIVIDER_HTML(s.id) + s.content;\n\t}\n\treturn html;\n}\n\n// ---------------------------------------------------------------------------\n// Section extraction\n// ---------------------------------------------------------------------------\n\n/**\n * Parse the editor HTML into a Map of sectionId → raw HTML string.\n * The special key `'body'` always holds the content before the first divider.\n * Map iteration order matches document order.\n */\nexport function extractAllSections(editor: Editor): Map<string, string> {\n\treturn extractAllSectionsFromHtml(editor.getHTML());\n}\n\n/**\n * Extract just the body portion (everything before the first section divider)\n * from an HTML string produced by BikEditor. Safe to call on plain HTML too —\n * returns the full string when no dividers are present.\n */\nexport function getBodyHtml(html: string): string {\n\tif (!html) return '';\n\tconst sections = extractAllSectionsFromHtml(html);\n\treturn sections.get('body') ?? html;\n}\n\n/**\n * Extract everything from the first section divider onward (dividers + their\n * content). Returns an empty string when there are no sections.\n */\nexport function getSectionsHtml(html: string): string {\n\tif (!html) return '';\n\tconst body = getBodyHtml(html);\n\treturn html.substring(body.length);\n}\n\nexport function extractAllSectionsFromHtml(html: string): Map<string, string> {\n\tconst sections = new Map<string, string>();\n\tconst dividerRegex =\n\t\t/<div[^>]*data-section-divider=\"([^\"]*)[^>]*>\\s*<\\/div>/g;\n\tconst dividers: Array<{ id: string; index: number; endIndex: number }> = [];\n\n\tlet match: RegExpExecArray | null;\n\twhile ((match = dividerRegex.exec(html)) !== null) {\n\t\tdividers.push({\n\t\t\tid: match[1],\n\t\t\tindex: match.index,\n\t\t\tendIndex: match.index + match[0].length,\n\t\t});\n\t}\n\n\tif (dividers.length === 0) {\n\t\tsections.set('body', html);\n\t\treturn sections;\n\t}\n\n\tsections.set('body', html.slice(0, dividers[0].index));\n\tfor (let i = 0; i < dividers.length; i++) {\n\t\tconst start = dividers[i].endIndex;\n\t\tconst end = i + 1 < dividers.length ? dividers[i + 1].index : html.length;\n\t\tsections.set(dividers[i].id, html.slice(start, end));\n\t}\n\n\treturn sections;\n}\n\n/** Returns BikEditorContent for a single named section (or 'body'). */\nexport function extractSectionContent(\n\teditor: Editor,\n\tid: string,\n): EditorSnapshot {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1)\n\t\treturn { html: '', text: '', isEmpty: true, characterCount: 0 };\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst slice = editor.state.doc.slice(startPos, endPos);\n\tconst container = document.createElement('div');\n\tconst serializer = DOMSerializer.fromSchema(editor.schema);\n\tcontainer.appendChild(serializer.serializeFragment(slice.content));\n\tconst html = toPortableHtml(container.innerHTML);\n\tconst text = container.textContent ?? '';\n\treturn { html, text, isEmpty: !text.trim(), characterCount: text.length };\n}\n\n/**\n * Parse an HTML string into ProseMirror nodes using the editor's schema.\n */\nfunction parseHtmlToNodes(editor: Editor, html: string) {\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = html;\n\treturn DOMParser.fromSchema(editor.schema).parse(container).content;\n}\n\n/**\n * Replace the content of a single named section without touching others.\n * Uses a ProseMirror transaction to replace only the target range,\n * preserving undo history and other sections' state.\n * If the section doesn't exist yet, it is appended at the end of the document.\n */\nexport function setSectionContentInEditor(\n\teditor: Editor,\n\tid: string,\n\thtml: string,\n): void {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1) {\n\t\tconst endPos = editor.state.doc.content.size;\n\t\tconst dividerHtml = SECTION_DIVIDER_HTML(id) + html;\n\t\teditor.commands.insertContentAt(endPos, dividerHtml, {\n\t\t\tupdateSelection: false,\n\t\t});\n\t\treturn;\n\t}\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst fragment = parseHtmlToNodes(editor, html);\n\tconst { tr } = editor.state;\n\t// For body, replace from position 0 (before the first paragraph's opening\n\t// boundary) so ProseMirror swaps entire block nodes cleanly. Position 1\n\t// (inside the paragraph) would force ProseMirror to close the open paragraph\n\t// first, creating a ghost empty <p></p>.\n\tconst replaceFrom = id === 'body' ? 0 : startPos;\n\ttr.replaceWith(replaceFrom, endPos, fragment);\n\ttr.setMeta('addToHistory', false);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Convenience shorthands (body = first section)\n// ---------------------------------------------------------------------------\n\n/** Extract BikEditorContent for just the body (before the first divider). */\nexport function extractBodyContent(editor: Editor): EditorSnapshot {\n\treturn extractSectionContent(editor, 'body');\n}\n\n// ---------------------------------------------------------------------------\n// Active formats\n// ---------------------------------------------------------------------------\n\nexport function extractActiveFormats(editor: Editor): FormatState {\n\treturn {\n\t\tbold: editor.isActive('bold'),\n\t\titalic: editor.isActive('italic'),\n\t\tunderline: editor.isActive('underline'),\n\t\tstrike: editor.isActive('strike'),\n\t\tbulletList: editor.isActive('bulletList'),\n\t\torderedList: editor.isActive('orderedList'),\n\t\tblockquote: editor.isActive('blockquote'),\n\t\tcodeBlock: editor.isActive('codeBlock'),\n\t\tlink: (() => {\n\t\t\tif (editor.isActive('link')) {\n\t\t\t\treturn { href: editor.getAttributes('link')['href'] ?? '' };\n\t\t\t}\n\t\t\tconst { $from } = editor.state.selection;\n\t\t\tif ($from.pos > 0) {\n\t\t\t\tconst before = $from.doc.resolve($from.pos);\n\t\t\t\tconst linkMark = before.marks().find((m) => m.type.name === 'link');\n\t\t\t\tif (!linkMark) {\n\t\t\t\t\tconst nodeBefore = $from.nodeBefore;\n\t\t\t\t\tconst markOnPrev = nodeBefore?.marks.find(\n\t\t\t\t\t\t(m) => m.type.name === 'link',\n\t\t\t\t\t);\n\t\t\t\t\tif (markOnPrev) {\n\t\t\t\t\t\treturn { href: markOnPrev.attrs['href'] ?? '' };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn { href: linkMark.attrs['href'] ?? '' };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t})(),\n\t\ttextAlign: editor.isActive({ textAlign: 'center' })\n\t\t\t? 'center'\n\t\t\t: editor.isActive({ textAlign: 'right' })\n\t\t\t? 'right'\n\t\t\t: editor.isActive({ textAlign: 'justify' })\n\t\t\t? 'justify'\n\t\t\t: editor.isActive({ textAlign: 'left' })\n\t\t\t? 'left'\n\t\t\t: null,\n\t\tfontFamily: editor.getAttributes('textStyle')['fontFamily'] ?? null,\n\t\tfontSize: editor.getAttributes('textStyle')['fontSize'] ?? null,\n\t\tcolor: editor.getAttributes('textStyle')['color'] ?? null,\n\t\thighlight: editor.isActive('highlight')\n\t\t\t? editor.getAttributes('highlight')['color'] ?? 'default'\n\t\t\t: null,\n\t\tsuperscript: editor.isActive('superscript'),\n\t\tsubscript: editor.isActive('subscript'),\n\t};\n}\n\nexport function extractContent(editor: Editor): EditorSnapshot {\n\tconst html = toPortableHtml(editor.getHTML());\n\tconst normalized = normalizeHardBreaks(editor.state.doc.content);\n\tconst tempDoc = editor.schema.node('doc', null, normalized);\n\tconst text = tempDoc.textBetween(0, tempDoc.content.size, '\\n', '\\n');\n\treturn {\n\t\thtml,\n\t\ttext,\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount: text.length,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Section position helpers (used by insertAtSectionStart/End and appendBodyContent)\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the ProseMirror position immediately after a section's opening divider\n * (i.e. the start of the section's own content).\n * For `'body'`, returns 1 (beginning of the document).\n * Returns -1 if the named section's divider is not found.\n */\nexport function findSectionStartPos(editor: Editor, sectionId: string): number {\n\tif (sectionId === 'body') return 1;\n\tlet startPos = -1;\n\teditor.state.doc.descendants((node, pos) => {\n\t\tif (startPos !== -1) return false;\n\t\tif (\n\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t) {\n\t\t\tstartPos = pos + node.nodeSize; // position right after the divider\n\t\t}\n\t});\n\treturn startPos;\n}\n\n/**\n * Returns the ProseMirror position at the end of a named section's content:\n * - For `'body'`: position of the first section divider, or end of document.\n * - For a named section: position of the next divider, or end of document.\n */\nexport function findSectionEndPos(editor: Editor, sectionId: string): number {\n\tconst doc = editor.state.doc;\n\tconst docSize = doc.content.size;\n\n\tif (sectionId === 'body') {\n\t\tlet firstDividerPos = -1;\n\t\tdoc.descendants((node, pos) => {\n\t\t\tif (firstDividerPos !== -1) return false;\n\t\t\tif (node.type.name === 'sectionDivider') {\n\t\t\t\tfirstDividerPos = pos;\n\t\t\t}\n\t\t});\n\t\treturn firstDividerPos !== -1 ? firstDividerPos : docSize;\n\t}\n\n\tlet passedSection = false;\n\tlet nextDividerPos = -1;\n\tdoc.descendants((node, pos) => {\n\t\tif (nextDividerPos !== -1) return false;\n\t\tif (!passedSection) {\n\t\t\tif (\n\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t) {\n\t\t\t\tpassedSection = true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (node.type.name === 'sectionDivider') {\n\t\t\tnextDividerPos = pos;\n\t\t}\n\t});\n\treturn nextDividerPos !== -1 ? nextDividerPos : docSize;\n}\n"],"names":["normalizeHtml","html","replace","toPortableHtml","div","document","createElement","innerHTML","p","Array","from","querySelectorAll","style","margin","childNodes","length","appendChild","lastChild","HTMLBRElement","insertInlineHtml","editor","normalised","dom","slice","DOMParser","fromSchema","schema","parseSlice","size","to","state","selection","tr","replaceRange","view","dispatch","SECTION_DIVIDER_HTML","id","buildSectionedContent","body","sections","s","content","getBodyHtml","_a","extractAllSectionsFromHtml","get","getSectionsHtml","substring","Map","dividerRegex","dividers","match","exec","push","index","endIndex","set","i","start","end","extractSectionContent","startPos","findSectionStartPos","text","isEmpty","characterCount","endPos","findSectionEndPos","doc","container","serializer","DOMSerializer","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","normalized","normalizeHardBreaks","tempDoc","node","textBetween","sectionId","descendants","nodeSize","docSize","firstDividerPos","passedSection","nextDividerPos"],"mappings":"+KAqBM,SAAUA,EAAcC,GAC7B,OAAOA,EACLC,QAAQ,mBAAoB,IAC5BA,QAAQ,sCAAuC,OAClD,CAYM,SAAUC,EAAeF,GAC9B,MAAMG,EAAMC,SAASC,cAAc,OACnCF,EAAIG,UAAYN,EAChB,IAAK,MAAMO,KAAKC,MAAMC,KAAKN,EAAIO,iBAAiB,MAAO,CAEtD,GADAH,EAAEI,MAAMC,OAAS,IACW,IAAxBL,EAAEM,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EAER,mBAAnBkE,EAAKpB,KAAKC,MACVmB,EAAKjB,MAAiB,YAAMmB,IAE5BpE,EAAWwC,EAAM0B,EAAKI,SACtB,IAEKtE,CACR,CAOgB,SAAAM,EAAkBhD,EAAgB8G,GACjD,MAAM7D,EAAMjD,EAAOU,MAAMuC,IACnBgE,EAAUhE,EAAI3B,QAAQd,KAE5B,GAAkB,SAAdsG,EAAsB,CACzB,IAAII,GAAmB,EAOvB,OANAjE,EAAI8D,aAAY,CAACH,EAAM1B,KACtB,IAAyB,IAArBgC,EAAwB,OAAO,EACZ,mBAAnBN,EAAKpB,KAAKC,OACbyB,EAAkBhC,EAClB,KAE0B,IAArBgC,EAAyBA,EAAkBD,CAClD,CAED,IAAIE,GAAgB,EAChBC,GAAkB,EAgBtB,OAfAnE,EAAI8D,aAAY,CAACH,EAAM1B,KACE,IAApBkC,IACCD,OASkB,mBAAnBP,EAAKpB,KAAKC,OACb2B,EAAiBlC,KARG,mBAAnB0B,EAAKpB,KAAKC,MACVmB,EAAKjB,MAAiB,YAAMmB,IAE5BK,GAAgB,IAEV,OAMkB,IAApBC,EAAwBA,EAAiBH,CACjD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bikdotai/bik-component-library",
|
|
3
|
-
"version": "0.0.809-beta.
|
|
3
|
+
"version": "0.0.809-beta.21",
|
|
4
4
|
"description": "Bik Component Library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,7 +64,6 @@
|
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@amplitude/analytics-browser": "^2.9.3",
|
|
66
66
|
"@babel/runtime": "^7.20.7",
|
|
67
|
-
"@bikdotai/bik-component-library": "^0.0.809-beta.18",
|
|
68
67
|
"@bikdotai/bik-models": "11.4.0",
|
|
69
68
|
"@hello-pangea/dnd": "^18.0.1",
|
|
70
69
|
"@popperjs/core": "^2.11.7",
|