@bikdotai/bik-component-library 0.0.804-beta.6 → 0.0.804-beta.8

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("react/jsx-runtime"),e=require("../node_modules/@tiptap/core/dist/index.js"),n=require("@tiptap/react"),o=require("react"),i=require("./BikEditor.styles.js"),r=require("./BikEditor.types.js"),l=require("./BikEditor.utils.js"),s=require("./extensions/buildExtensions.js"),c=require("./floating/LinkBubbleMenu.js");function a(t){return Object.entries(t).map((t=>{let[e,n]=t;return`${e.replace(/([A-Z])/g,(t=>`-${t.toLowerCase()}`))}:${n}`})).join(";")}const u=(u,d)=>{var m;const{initialContent:g,sections:v,features:h,disabled:f,maxCharacters:C,shortcuts:p,sendShortcut:S,mentions:k,slashCommands:x,link:y,onPaste:B,onReady:b,onChange:H,onSend:A,onFocus:E,onBlur:z,onSelectionChange:j,minHeight:I,maxHeight:R,style:L,className:T,editorClassName:F,editorStyle:M}=u,O=(null==v?void 0:v.length)?l.buildSectionedContent(l.normalizeHtml(null!=g?g:""),v.map((t=>Object.assign(Object.assign({},t),{content:l.normalizeHtml(t.content)})))):l.normalizeHtml(null!=g?g:""),q=o.useRef([]),w=o.useRef(!1),P=o.useRef(b);P.current=b;const D=o.useRef(H);D.current=H;const U=o.useRef(j);U.current=j;const N=o.useRef(E);N.current=E;const _=o.useRef(z);_.current=z;const $=o.useRef(A);$.current=A;const J=n.useEditor({extensions:s.buildExtensions({features:h,placeholder:u.placeholder,maxCharacters:C,hasSections:(null!==(m=null==v?void 0:v.length)&&void 0!==m?m:0)>0,mentions:{agents:null==k?void 0:k.agents,teams:null==k?void 0:k.teams},slashCommands:null==x?void 0:x.items,onPaste:B,onSend:A?t=>{var e;return null===(e=$.current)||void 0===e?void 0:e.call($,t)}:void 0,sendShortcut:S,shortcuts:p,onMentionSelected:null==k?void 0:k.onSelect,onSlashCommandSelected:null==x?void 0:x.onSelect,renderMentionItem:null==k?void 0:k.renderItem,renderMentionDropdown:null==k?void 0:k.renderDropdown,renderSlashCommandItem:null==x?void 0:x.renderItem,renderSlashCommandDropdown:null==x?void 0:x.renderDropdown}),content:O,editable:!f,immediatelyRender:!1,editorProps:{attributes:Object.assign(Object.assign({},F?{class:F}:{}),M?{style:a(M)}:{})},onUpdate:t=>{let{editor:e}=t;var n;null===(n=D.current)||void 0===n||n.call(D,l.extractContent(e))},onTransaction:t=>{let{editor:e}=t;var n;null===(n=U.current)||void 0===n||n.call(U,l.extractActiveFormats(e))},onFocus:()=>{var t;return null===(t=N.current)||void 0===t?void 0:t.call(N)},onBlur:()=>{var t;return null===(t=_.current)||void 0===t?void 0:t.call(_)}});function V(t){J?t(J):q.current.push(t)}return o.useEffect((()=>{var t;if(J){if(q.current.length>0){q.current.splice(0).forEach((t=>t(J)))}w.current||(w.current=!0,null===(t=P.current)||void 0===t||t.call(P))}}),[J]),o.useImperativeHandle(d,(()=>({focus:t=>V((e=>e.commands.focus(t))),blur:()=>V((t=>t.commands.blur())),clearContent:()=>V((t=>t.commands.clearContent(!0))),setContent:t=>{const e=l.normalizeHtml(t);V((t=>t.commands.setContent(e,{emitUpdate:!0})))},insertContent:t=>{const e=l.normalizeHtml(t);V((t=>t.commands.insertContent(e)))},insertAtStart:t=>{const e=l.normalizeHtml(t);V((t=>t.commands.insertContentAt(1,e)))},insertBlock:t=>{const e=l.normalizeHtml(t);V((t=>t.commands.insertContentAt(t.state.doc.content.size,e)))},appendInline:t=>{const e=l.normalizeHtml(t);V((t=>t.commands.insertContentAt(t.state.doc.content.size-1,e)))},insertAtEnd(t){this.insertBlock(t)},appendContent(t){this.appendInline(t)},getContent:()=>J?l.extractContent(J):{html:"",text:"",isEmpty:!0,characterCount:0},getJSON:()=>{var t;return null!==(t=null==J?void 0:J.getJSON())&&void 0!==t?t:null},getMentions:()=>{const t=new Set,e=new Set;return J?(J.state.doc.descendants((n=>{"mentionAgent"===n.type.name&&null!=n.attrs.id?t.add(String(n.attrs.id)):"mentionTeam"===n.type.name&&null!=n.attrs.id&&e.add(String(n.attrs.id))})),{agentIds:Array.from(t),teamIds:Array.from(e)}):{agentIds:[],teamIds:[]}},getCursorPosition:()=>{if(!J)return{from:0,to:0};const{from:t,to:e}=J.state.selection;return{from:t,to:e}},insertAtPosition:(t,e)=>{const n=l.normalizeHtml(e);V((e=>e.commands.insertContentAt(t,n)))},getSelectedText:()=>{if(!J)return"";const{state:t}=J,{from:n,to:o,empty:i}=t.selection;if(!i)return t.doc.textBetween(n,o," ");const r=t.schema.marks.link;if(r){const o=e.getMarkRange(t.doc.resolve(n),r);if(o)return t.doc.textBetween(o.from,o.to," ")}return""},getCharacterCount:()=>{var t,e,n,o;return{count:null!==(o=null!==(n=null===(e=null===(t=null==J?void 0:J.storage.characterCount)||void 0===t?void 0:t.characters)||void 0===e?void 0:e.call(t))&&void 0!==n?n:null==J?void 0:J.getText().length)&&void 0!==o?o:0,limit:null!=C?C:null}},getSectionContent:t=>J?l.extractSectionContent(J,t):{html:"",text:"",isEmpty:!0,characterCount:0},setSectionContent:(t,e)=>{const n=l.normalizeHtml(e);V((e=>l.setSectionContentInEditor(e,t,n)))},focusSection:t=>{V((e=>{if("body"===t){let t=e.state.doc.content.size-1;return e.state.doc.descendants(((n,o)=>("sectionDivider"===n.type.name&&t===e.state.doc.content.size-1&&(t=o-1),t===e.state.doc.content.size-1))),t<1&&(t=1),void e.chain().focus().setTextSelection(t).run()}let n=-1;e.state.doc.descendants(((e,o)=>{if(-1!==n)return!1;"sectionDivider"===e.type.name&&e.attrs.sectionId===t&&(n=o+e.nodeSize+1)})),-1!==n&&e.chain().focus().setTextSelection(n).run()}))},clearSection:t=>{V((e=>l.setSectionContentInEditor(e,t,"<p></p>")))},getBodyContent:()=>J?l.extractBodyContent(J):{html:"",text:"",isEmpty:!0,characterCount:0},setBodyContent:t=>{const e=l.normalizeHtml(t);V((t=>l.setSectionContentInEditor(t,"body",e)))},setBodyAndSections:(t,e)=>{const n=l.buildSectionedContent(l.normalizeHtml(t),e.map((t=>({id:t.id,content:l.normalizeHtml(t.content)}))));V((t=>t.commands.setContent(n,{emitUpdate:!0})))},appendBodyContent:t=>{const e=l.normalizeHtml(t);V((t=>{const n=l.findSectionEndPos(t,"body");t.commands.insertContentAt(n-1,e)}))},insertAtSectionStart:(t,e)=>{const n=l.normalizeHtml(e);V((e=>{const o=l.findSectionStartPos(e,t);-1!==o&&e.commands.insertContentAt(o,n)}))},insertAtSectionEnd:(t,e)=>{const n=l.normalizeHtml(e);V((e=>{const o=l.findSectionEndPos(e,t);e.commands.insertContentAt(o,n)}))},getActiveFormats:()=>J?l.extractActiveFormats(J):r.DEFAULT_FORMAT_STATE,actions:{toggleBold:()=>null==J?void 0:J.chain().focus().toggleBold().run(),toggleItalic:()=>null==J?void 0:J.chain().focus().toggleItalic().run(),toggleUnderline:()=>null==J?void 0:J.chain().focus().toggleUnderline().run(),toggleStrike:()=>null==J?void 0:J.chain().focus().toggleStrike().run(),toggleBulletList:()=>null==J?void 0:J.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>null==J?void 0:J.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>null==J?void 0:J.chain().focus().toggleBlockquote().run(),toggleCodeBlock:()=>null==J?void 0:J.chain().focus().toggleCodeBlock().run(),setTextAlign:t=>null==J?void 0:J.chain().focus().setTextAlign(t).run(),setFontFamily:t=>null==J?void 0:J.chain().focus().setFontFamily(t).run(),setFontSize:t=>null==J?void 0:J.chain().focus().setFontSize(t).run(),setColor:t=>null==J?void 0:J.chain().focus().setColor(t).run(),setHighlight:t=>null==J?void 0:J.chain().focus().toggleHighlight({color:t}).run(),unsetColor:()=>null==J?void 0:J.chain().focus().unsetColor().run(),unsetHighlight:()=>null==J?void 0:J.chain().focus().unsetHighlight().run(),setLink:(t,e)=>{J&&(void 0!==e?J.chain().focus().extendMarkRange("link").command((n=>{let{tr:o,state:i}=n;const{from:r,to:l}=o.selection,s=i.schema.marks.link;return!!s&&(o.replaceWith(r,l,i.schema.text(e,[s.create({href:t})])),!0)})).run():J.chain().focus().extendMarkRange("link").setLink({href:t}).run())},updateLink:t=>null==J?void 0:J.chain().focus().extendMarkRange("link").setLink({href:t}).run(),removeLink:()=>null==J?void 0:J.chain().focus().extendMarkRange("link").unsetLink().run(),insertEmoji:t=>null==J?void 0:J.chain().focus().insertContent(t).run(),insertVariable:t=>null==J?void 0:J.chain().focus().insertContent(`{{${t}}}`).run(),insertHtml:t=>null==J?void 0:J.commands.insertContent(t),undo:()=>null==J?void 0:J.chain().focus().undo().run(),redo:()=>null==J?void 0:J.chain().focus().redo().run(),canUndo:()=>{var t;return null!==(t=null==J?void 0:J.can().undo())&&void 0!==t&&t},canRedo:()=>{var t;return null!==(t=null==J?void 0:J.can().redo())&&void 0!==t&&t},toggleSuperscript:()=>null==J?void 0:J.chain().focus().toggleSuperscript().run(),toggleSubscript:()=>null==J?void 0:J.chain().focus().toggleSubscript().run(),insertImage:t=>null==J?void 0:J.chain().focus().setImage({src:t}).run()}})),[J]),J?t.jsxs(i.BikEditorShell,Object.assign({minHeight:I,maxHeight:R,style:L,className:T},{children:[t.jsx(n.EditorContent,{editor:J}),t.jsx(c.LinkBubbleMenu,{editor:J,renderLinkTooltip:null==y?void 0:y.renderTooltip})]})):null},d=o.forwardRef(u);d.displayName="BikEditor",exports.BikEditor=d;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react/jsx-runtime"),e=require("../node_modules/@tiptap/core/dist/index.js"),n=require("@tiptap/react"),o=require("react"),i=require("./BikEditor.styles.js"),r=require("./BikEditor.types.js"),l=require("./BikEditor.utils.js"),s=require("./extensions/buildExtensions.js"),c=require("./floating/LinkBubbleMenu.js");function a(t){return Object.entries(t).map((t=>{let[e,n]=t;return`${e.replace(/([A-Z])/g,(t=>`-${t.toLowerCase()}`))}:${n}`})).join(";")}const u=(u,d)=>{var m;const{initialContent:g,sections:v,features:h,disabled:f,maxCharacters:C,shortcuts:p,sendShortcut:S,mentions:x,slashCommands:k,link:y,onPaste:B,onReady:b,onChange:H,onSend:A,onFocus:E,onBlur:z,onSelectionChange:j,minHeight:I,maxHeight:R,style:L,className:T,editorClassName:F,editorStyle:M}=u,O=(null==v?void 0:v.length)?l.buildSectionedContent(l.normalizeHtml(null!=g?g:""),v.map((t=>Object.assign(Object.assign({},t),{content:l.normalizeHtml(t.content)})))):l.normalizeHtml(null!=g?g:""),q=o.useRef([]),w=o.useRef(!1),P=o.useRef(b);P.current=b;const D=o.useRef(H);D.current=H;const U=o.useRef(j);U.current=j;const N=o.useRef(E);N.current=E;const _=o.useRef(z);_.current=z;const $=o.useRef(A);$.current=A;const J=n.useEditor({extensions:s.buildExtensions({features:h,placeholder:u.placeholder,maxCharacters:C,hasSections:(null!==(m=null==v?void 0:v.length)&&void 0!==m?m:0)>0,mentions:{agents:null==x?void 0:x.agents,teams:null==x?void 0:x.teams},slashCommands:null==k?void 0:k.items,onPaste:B,onSend:A?t=>{var e;return null===(e=$.current)||void 0===e?void 0:e.call($,t)}:void 0,sendShortcut:S,shortcuts:p,onMentionSelected:null==x?void 0:x.onSelect,onSlashCommandSelected:null==k?void 0:k.onSelect,renderMentionItem:null==x?void 0:x.renderItem,renderMentionDropdown:null==x?void 0:x.renderDropdown,renderSlashCommandItem:null==k?void 0:k.renderItem,renderSlashCommandDropdown:null==k?void 0:k.renderDropdown}),content:O,editable:!f,immediatelyRender:!1,editorProps:{attributes:Object.assign(Object.assign({},F?{class:F}:{}),M?{style:a(M)}:{})},onUpdate:t=>{let{editor:e}=t;var n;null===(n=D.current)||void 0===n||n.call(D,l.extractContent(e))},onTransaction:t=>{let{editor:e}=t;var n;null===(n=U.current)||void 0===n||n.call(U,l.extractActiveFormats(e))},onFocus:()=>{var t;return null===(t=N.current)||void 0===t?void 0:t.call(N)},onBlur:()=>{var t;return null===(t=_.current)||void 0===t?void 0:t.call(_)}});function V(t){J?t(J):q.current.push(t)}return o.useEffect((()=>{var t;if(J){if(q.current.length>0){q.current.splice(0).forEach((t=>t(J)))}w.current||(w.current=!0,null===(t=P.current)||void 0===t||t.call(P))}}),[J]),o.useImperativeHandle(d,(()=>({focus:t=>V((e=>e.commands.focus(t))),blur:()=>V((t=>t.commands.blur())),clearContent:()=>V((t=>t.commands.clearContent(!0))),setContent:t=>{const e=l.normalizeHtml(t);V((t=>t.commands.setContent(e,{emitUpdate:!0})))},insertContent:t=>{const e=l.normalizeHtml(t);V((t=>t.commands.insertContent(e)))},insertAtStart:t=>{const e=l.normalizeHtml(t);V((t=>t.commands.insertContentAt(1,e)))},insertBlock:t=>{const e=l.normalizeHtml(t);V((t=>t.commands.insertContentAt(t.state.doc.content.size,e)))},appendInline:t=>{const e=l.normalizeHtml(t);V((t=>t.commands.insertContentAt(t.state.doc.content.size-1,e)))},insertAtEnd(t){this.insertBlock(t)},appendContent(t){this.appendInline(t)},getContent:()=>J?l.extractContent(J):{html:"",text:"",isEmpty:!0,characterCount:0},getJSON:()=>{var t;return null!==(t=null==J?void 0:J.getJSON())&&void 0!==t?t:null},getMentions:()=>{const t=new Set,e=new Set;return J?(J.state.doc.descendants((n=>{"mentionAgent"===n.type.name&&null!=n.attrs.id?t.add(String(n.attrs.id)):"mentionTeam"===n.type.name&&null!=n.attrs.id&&e.add(String(n.attrs.id))})),{agentIds:Array.from(t),teamIds:Array.from(e)}):{agentIds:[],teamIds:[]}},getCursorPosition:()=>{if(!J)return{from:0,to:0};const{from:t,to:e}=J.state.selection;return{from:t,to:e}},insertAtPosition:(t,e)=>{const n=l.normalizeHtml(e);V((e=>e.commands.insertContentAt(t,n)))},getSelectedText:()=>{if(!J)return"";const{state:t}=J,{from:n,to:o,empty:i}=t.selection;if(!i)return t.doc.textBetween(n,o," ");const r=t.schema.marks.link;if(r){const o=e.getMarkRange(t.doc.resolve(n),r);if(o)return t.doc.textBetween(o.from,o.to," ")}return""},getCharacterCount:()=>{var t,e,n,o;return{count:null!==(o=null!==(n=null===(e=null===(t=null==J?void 0:J.storage.characterCount)||void 0===t?void 0:t.characters)||void 0===e?void 0:e.call(t))&&void 0!==n?n:null==J?void 0:J.getText().length)&&void 0!==o?o:0,limit:null!=C?C:null}},getSectionContent:t=>J?l.extractSectionContent(J,t):{html:"",text:"",isEmpty:!0,characterCount:0},setSectionContent:(t,e)=>{const n=l.normalizeHtml(e);V((e=>l.setSectionContentInEditor(e,t,n)))},focusSection:t=>{V((e=>{if("body"===t){let t=e.state.doc.content.size-1;return e.state.doc.descendants(((n,o)=>("sectionDivider"===n.type.name&&t===e.state.doc.content.size-1&&(t=o-1),t===e.state.doc.content.size-1))),t<1&&(t=1),void e.chain().focus().setTextSelection(t).run()}let n=-1;e.state.doc.descendants(((e,o)=>{if(-1!==n)return!1;"sectionDivider"===e.type.name&&e.attrs.sectionId===t&&(n=o+e.nodeSize+1)})),-1!==n&&e.chain().focus().setTextSelection(n).run()}))},clearSection:t=>{V((e=>l.setSectionContentInEditor(e,t,"<p></p>")))},getBodyContent:()=>J?l.extractBodyContent(J):{html:"",text:"",isEmpty:!0,characterCount:0},setBodyContent:t=>{const e=l.normalizeHtml(t);V((t=>l.setSectionContentInEditor(t,"body",e)))},setBodyAndSections:(t,e)=>{const n=l.buildSectionedContent(l.normalizeHtml(t),e.map((t=>({id:t.id,content:l.normalizeHtml(t.content)}))));V((t=>t.commands.setContent(n,{emitUpdate:!0})))},appendBodyContent:t=>{const e=l.normalizeHtml(t);V((t=>{const n=l.findSectionEndPos(t,"body");t.commands.insertContentAt(n-1,e)}))},insertAtSectionStart:(t,e)=>{const n=l.normalizeHtml(e);V((e=>{const o=l.findSectionStartPos(e,t);-1!==o&&e.commands.insertContentAt(o,n)}))},insertAtSectionEnd:(t,e)=>{const n=l.normalizeHtml(e);V((e=>{const o=l.findSectionEndPos(e,t);e.commands.insertContentAt(o,n)}))},getActiveFormats:()=>J?l.extractActiveFormats(J):r.DEFAULT_FORMAT_STATE,actions:{toggleBold:()=>null==J?void 0:J.chain().focus().toggleBold().run(),toggleItalic:()=>null==J?void 0:J.chain().focus().toggleItalic().run(),toggleUnderline:()=>null==J?void 0:J.chain().focus().toggleUnderline().run(),toggleStrike:()=>null==J?void 0:J.chain().focus().toggleStrike().run(),toggleBulletList:()=>null==J?void 0:J.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>null==J?void 0:J.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>null==J?void 0:J.chain().focus().toggleBlockquote().run(),toggleCodeBlock:()=>null==J?void 0:J.chain().focus().toggleCodeBlock().run(),setTextAlign:t=>null==J?void 0:J.chain().focus().setTextAlign(t).run(),setFontFamily:t=>null==J?void 0:J.chain().focus().setFontFamily(t).run(),setFontSize:t=>null==J?void 0:J.chain().focus().setFontSize(t).run(),setColor:t=>null==J?void 0:J.chain().focus().setColor(t).run(),setHighlight:t=>null==J?void 0:J.chain().focus().toggleHighlight({color:t}).run(),unsetColor:()=>null==J?void 0:J.chain().focus().unsetColor().run(),unsetHighlight:()=>null==J?void 0:J.chain().focus().unsetHighlight().run(),setLink:(t,e)=>{J&&(void 0!==e?J.chain().focus().extendMarkRange("link").command((n=>{let{tr:o,state:i}=n;const{from:r,to:l}=o.selection,s=i.schema.marks.link;if(!s)return!1;const c=i.schema.text(e,[s.create({href:t})]),a=i.schema.text(" ");return o.replaceWith(r,l,[c,a]),!0})).run():J.chain().focus().extendMarkRange("link").setLink({href:t}).insertContent(" ").run())},updateLink:t=>null==J?void 0:J.chain().focus().extendMarkRange("link").setLink({href:t}).run(),removeLink:()=>null==J?void 0:J.chain().focus().extendMarkRange("link").unsetLink().run(),insertEmoji:t=>null==J?void 0:J.chain().focus().insertContent(t).run(),insertVariable:t=>null==J?void 0:J.chain().focus().insertContent(`{{${t}}}`).run(),insertHtml:t=>null==J?void 0:J.commands.insertContent(t),undo:()=>null==J?void 0:J.chain().focus().undo().run(),redo:()=>null==J?void 0:J.chain().focus().redo().run(),canUndo:()=>{var t;return null!==(t=null==J?void 0:J.can().undo())&&void 0!==t&&t},canRedo:()=>{var t;return null!==(t=null==J?void 0:J.can().redo())&&void 0!==t&&t},toggleSuperscript:()=>null==J?void 0:J.chain().focus().toggleSuperscript().run(),toggleSubscript:()=>null==J?void 0:J.chain().focus().toggleSubscript().run(),insertImage:t=>null==J?void 0:J.chain().focus().setImage({src:t}).run()}})),[J]),J?t.jsxs(i.BikEditorShell,Object.assign({minHeight:I,maxHeight:R,style:L,className:T},{children:[t.jsx(n.EditorContent,{editor:J}),t.jsx(c.LinkBubbleMenu,{editor:J,renderLinkTooltip:null==y?void 0:y.renderTooltip})]})):null},d=o.forwardRef(u);d.displayName="BikEditor",exports.BikEditor=d;
2
2
  //# sourceMappingURL=BikEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BikEditor.js","sources":["../../../src/editor/BikEditor.tsx"],"sourcesContent":["'use client';\n\n/**\n * IMPLEMENTATION LAYER — TipTap-specific.\n * If the underlying editor is swapped, this file changes; BikEditor.types.ts and\n * src/editor/index.ts (the consumer contract) do NOT change.\n */\nimport { Editor, getMarkRange } from '@tiptap/core';\nimport { EditorContent, useEditor } from '@tiptap/react';\nimport React, {\n\tforwardRef,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n} from 'react';\nimport { BikEditorShell } from './BikEditor.styles';\nimport {\n\tBikEditorProps,\n\tBikEditorRef,\n\tDEFAULT_FORMAT_STATE,\n} from './BikEditor.types';\nimport {\n\tbuildSectionedContent,\n\textractActiveFormats,\n\textractBodyContent,\n\textractContent,\n\textractSectionContent,\n\tfindSectionEndPos,\n\tfindSectionStartPos,\n\tnormalizeHtml,\n\tsetSectionContentInEditor,\n} from './BikEditor.utils';\nimport { buildExtensions } from './extensions/buildExtensions';\nimport { LinkBubbleMenu } from './floating/LinkBubbleMenu';\n\n/** Convert React.CSSProperties to an inline CSS string for editorProps.attributes. */\nfunction cssToString(style: React.CSSProperties): string {\n\treturn Object.entries(style)\n\t\t.map(\n\t\t\t([k, v]) => `${k.replace(/([A-Z])/g, (c) => `-${c.toLowerCase()}`)}:${v}`,\n\t\t)\n\t\t.join(';');\n}\n\nconst BikEditorInner = (\n\tprops: BikEditorProps,\n\tref: React.Ref<BikEditorRef>,\n) => {\n\tconst {\n\t\tinitialContent,\n\t\tsections,\n\t\tfeatures,\n\t\tdisabled,\n\t\tmaxCharacters,\n\t\tshortcuts,\n\t\tsendShortcut,\n\t\tmentions,\n\t\tslashCommands,\n\t\tlink,\n\t\tonPaste,\n\t\tonReady,\n\t\tonChange,\n\t\tonSend,\n\t\tonFocus,\n\t\tonBlur,\n\t\tonSelectionChange,\n\t\tminHeight,\n\t\tmaxHeight,\n\t\tstyle,\n\t\tclassName,\n\t\teditorClassName,\n\t\teditorStyle,\n\t} = props;\n\n\tconst initialEditorContent = sections?.length\n\t\t? buildSectionedContent(\n\t\t\t\tnormalizeHtml(initialContent ?? ''),\n\t\t\t\tsections.map((s) => ({ ...s, content: normalizeHtml(s.content) })),\n\t\t )\n\t\t: normalizeHtml(initialContent ?? '');\n\n\t// ── Command queue ─────────────────────────────────────────────────────────\n\t// TipTap's useEditor initializes asynchronously; the editor instance is null\n\t// until the first commit. Any imperative method called before the editor is\n\t// ready is enqueued here and flushed automatically once it becomes non-null.\n\t// Consumers never need setTimeout or readiness guards.\n\tconst pendingQueue = useRef<Array<(e: Editor) => void>>([]);\n\tconst hasCalledOnReady = useRef(false);\n\t// Keep stable refs to all callbacks so useEditor receives the same function\n\t// identity on every render — prevents TipTap from re-registering event\n\t// handlers every time the parent re-renders with new inline function props.\n\tconst onReadyRef = useRef(onReady);\n\tonReadyRef.current = onReady;\n\tconst onChangeRef = useRef(onChange);\n\tonChangeRef.current = onChange;\n\tconst onSelectionChangeRef = useRef(onSelectionChange);\n\tonSelectionChangeRef.current = onSelectionChange;\n\tconst onFocusRef = useRef(onFocus);\n\tonFocusRef.current = onFocus;\n\tconst onBlurRef = useRef(onBlur);\n\tonBlurRef.current = onBlur;\n\tconst onSendRef = useRef(onSend);\n\tonSendRef.current = onSend;\n\n\tconst editor = useEditor({\n\t\textensions: buildExtensions({\n\t\t\tfeatures,\n\t\t\tplaceholder: props.placeholder,\n\t\t\tmaxCharacters,\n\t\t\thasSections: (sections?.length ?? 0) > 0,\n\t\t\tmentions: {\n\t\t\t\tagents: mentions?.agents,\n\t\t\t\tteams: mentions?.teams,\n\t\t\t},\n\t\t\tslashCommands: slashCommands?.items,\n\t\t\tonPaste,\n\t\t\tonSend: onSend ? (snapshot) => onSendRef.current?.(snapshot) : undefined,\n\t\t\tsendShortcut,\n\t\t\tshortcuts,\n\t\t\tonMentionSelected: mentions?.onSelect,\n\t\t\tonSlashCommandSelected: slashCommands?.onSelect,\n\t\t\trenderMentionItem: mentions?.renderItem,\n\t\t\trenderMentionDropdown: mentions?.renderDropdown,\n\t\t\trenderSlashCommandItem: slashCommands?.renderItem,\n\t\t\trenderSlashCommandDropdown: slashCommands?.renderDropdown,\n\t\t}),\n\t\tcontent: initialEditorContent,\n\t\teditable: !disabled,\n\t\timmediatelyRender: false, // SSR-safe — NEVER remove this\n\t\teditorProps: {\n\t\t\tattributes: {\n\t\t\t\t...(editorClassName ? { class: editorClassName } : {}),\n\t\t\t\t...(editorStyle ? { style: cssToString(editorStyle) } : {}),\n\t\t\t},\n\t\t},\n\t\tonUpdate: ({ editor: e }) => {\n\t\t\tonChangeRef.current?.(extractContent(e));\n\t\t},\n\t\tonTransaction: ({ editor: e }) => {\n\t\t\tonSelectionChangeRef.current?.(extractActiveFormats(e));\n\t\t},\n\t\tonFocus: () => onFocusRef.current?.(),\n\t\tonBlur: () => onBlurRef.current?.(),\n\t});\n\n\t// ── enqueue ───────────────────────────────────────────────────────────────\n\t// Run immediately if the editor is ready; otherwise defer to the queue.\n\t// Closures passed to enqueue MUST capture all parameters explicitly —\n\t// they must NOT close over `editor` (which would be null at enqueue time).\n\tfunction enqueue(op: (e: Editor) => void): void {\n\t\tif (editor) {\n\t\t\top(editor);\n\t\t} else {\n\t\t\tpendingQueue.current.push(op);\n\t\t}\n\t}\n\n\t// Flush the pending queue and fire onReady when editor transitions null → ready.\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\t\tif (pendingQueue.current.length > 0) {\n\t\t\tconst queue = pendingQueue.current.splice(0);\n\t\t\tqueue.forEach((op) => op(editor));\n\t\t}\n\t\tif (!hasCalledOnReady.current) {\n\t\t\thasCalledOnReady.current = true;\n\t\t\tonReadyRef.current?.();\n\t\t}\n\t}, [editor]);\n\n\tuseImperativeHandle(\n\t\tref,\n\t\t() => ({\n\t\t\t// ── Focus ────────────────────────────────────────────────────────\n\t\t\tfocus: (position) => enqueue((e) => e.commands.focus(position)),\n\t\t\tblur: () => enqueue((e) => e.commands.blur()),\n\n\t\t\t// ── Content ──────────────────────────────────────────────────────\n\t\t\tclearContent: () => enqueue((e) => e.commands.clearContent(true)),\n\t\t\tsetContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.setContent(normalised, { emitUpdate: true }));\n\t\t\t},\n\t\t\tinsertContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContent(normalised));\n\t\t\t},\n\t\t\tinsertAtStart: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(1, normalised));\n\t\t\t},\n\t\t\tinsertBlock: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\tappendInline: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// doc.content.size is after the last </p> (block boundary).\n\t\t\t\t// Subtract 1 to land inside the last paragraph so text appends\n\t\t\t\t// inline rather than being wrapped in a new paragraph each call.\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size - 1, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\t// Backwards-compatible aliases\n\t\t\tinsertAtEnd(html) {\n\t\t\t\tthis.insertBlock(html);\n\t\t\t},\n\t\t\tappendContent(html) {\n\t\t\t\tthis.appendInline(html);\n\t\t\t},\n\t\t\tgetContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tgetJSON: () => editor?.getJSON() ?? null,\n\t\t\tgetMentions: () => {\n\t\t\t\tconst agentIds = new Set<string>();\n\t\t\t\tconst teamIds = new Set<string>();\n\t\t\t\tif (!editor) return { agentIds: [], teamIds: [] };\n\t\t\t\teditor.state.doc.descendants((node) => {\n\t\t\t\t\tif (node.type.name === 'mentionAgent' && node.attrs['id'] != null) {\n\t\t\t\t\t\tagentIds.add(String(node.attrs['id']));\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tnode.type.name === 'mentionTeam' &&\n\t\t\t\t\t\tnode.attrs['id'] != null\n\t\t\t\t\t) {\n\t\t\t\t\t\tteamIds.add(String(node.attrs['id']));\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn { agentIds: Array.from(agentIds), teamIds: Array.from(teamIds) };\n\t\t\t},\n\n\t\t\t// ── Selection ────────────────────────────────────────────────────\n\t\t\tgetCursorPosition: () => {\n\t\t\t\tif (!editor) return { from: 0, to: 0 };\n\t\t\t\tconst { from, to } = editor.state.selection;\n\t\t\t\treturn { from, to };\n\t\t\t},\n\t\t\tinsertAtPosition: (pos, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(pos, normalised));\n\t\t\t},\n\t\t\tgetSelectedText: () => {\n\t\t\t\tif (!editor) return '';\n\t\t\t\tconst { state } = editor;\n\t\t\t\tconst { from, to, empty } = state.selection;\n\t\t\t\tif (!empty) {\n\t\t\t\t\treturn state.doc.textBetween(from, to, ' ');\n\t\t\t\t}\n\t\t\t\t// When the cursor is inside a link with nothing selected, return the\n\t\t\t\t// full link text — useful for pre-filling a link modal's text field.\n\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\tif (linkMarkType) {\n\t\t\t\t\tconst range = getMarkRange(state.doc.resolve(from), linkMarkType);\n\t\t\t\t\tif (range) {\n\t\t\t\t\t\treturn state.doc.textBetween(range.from, range.to, ' ');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn '';\n\t\t\t},\n\n\t\t\t// ── Character count ───────────────────────────────────────────────\n\t\t\tgetCharacterCount: () => ({\n\t\t\t\tcount:\n\t\t\t\t\teditor?.storage.characterCount?.characters?.() ??\n\t\t\t\t\teditor?.getText().length ??\n\t\t\t\t\t0,\n\t\t\t\tlimit: maxCharacters ?? null,\n\t\t\t}),\n\n\t\t\t// ── Sections ─────────────────────────────────────────────────────\n\t\t\tgetSectionContent: (sectionId) =>\n\t\t\t\teditor\n\t\t\t\t\t? extractSectionContent(editor, sectionId)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\n\t\t\tsetSectionContent: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, normalised));\n\t\t\t},\n\n\t\t\tfocusSection: (sectionId) => {\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tif (sectionId === 'body') {\n\t\t\t\t\t\tlet endOfBody = e.state.doc.content.size - 1;\n\t\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\t\tendOfBody === e.state.doc.content.size - 1\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tendOfBody = pos - 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn endOfBody === e.state.doc.content.size - 1;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (endOfBody < 1) endOfBody = 1;\n\t\t\t\t\t\te.chain().focus().setTextSelection(endOfBody).run();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet targetPos = -1;\n\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\tif (targetPos !== -1) return false;\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// pos + nodeSize lands right after the divider;\n\t\t\t\t\t\t\t// +1 more puts us inside the first paragraph of that section.\n\t\t\t\t\t\t\ttargetPos = pos + node.nodeSize + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tif (targetPos !== -1) {\n\t\t\t\t\t\te.chain().focus().setTextSelection(targetPos).run();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\n\t\t\tclearSection: (sectionId) => {\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, '<p></p>'));\n\t\t\t},\n\n\t\t\t// ── Convenience body shorthands ───────────────────────────────────\n\t\t\tgetBodyContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractBodyContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tsetBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, 'body', normalised));\n\t\t\t},\n\t\t\tsetBodyAndSections: (body, sections) => {\n\t\t\t\tconst html = buildSectionedContent(\n\t\t\t\t\tnormalizeHtml(body),\n\t\t\t\t\tsections.map((s) => ({\n\t\t\t\t\t\tid: s.id,\n\t\t\t\t\t\tcontent: normalizeHtml(s.content),\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t\tenqueue((e) => e.commands.setContent(html, { emitUpdate: true }));\n\t\t\t},\n\t\t\tappendBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// findSectionEndPos returns the position of the first divider (or\n\t\t\t\t// doc.content.size), which is the block boundary after the last </p>.\n\t\t\t\t// Subtract 1 to stay inside the last paragraph so successive calls\n\t\t\t\t// append inline text rather than creating a new paragraph each time.\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst boundaryPos = findSectionEndPos(e, 'body');\n\t\t\t\t\te.commands.insertContentAt(boundaryPos - 1, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionStart: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionStartPos(e, sectionId);\n\t\t\t\t\tif (pos !== -1) e.commands.insertContentAt(pos, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionEnd: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionEndPos(e, sectionId);\n\t\t\t\t\te.commands.insertContentAt(pos, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\t// ── Formats & actions ─────────────────────────────────────────────\n\t\t\tgetActiveFormats: () =>\n\t\t\t\teditor ? extractActiveFormats(editor) : DEFAULT_FORMAT_STATE,\n\t\t\tactions: {\n\t\t\t\ttoggleBold: () => editor?.chain().focus().toggleBold().run(),\n\t\t\t\ttoggleItalic: () => editor?.chain().focus().toggleItalic().run(),\n\t\t\t\ttoggleUnderline: () => editor?.chain().focus().toggleUnderline().run(),\n\t\t\t\ttoggleStrike: () => editor?.chain().focus().toggleStrike().run(),\n\t\t\t\ttoggleBulletList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBulletList().run(),\n\t\t\t\ttoggleOrderedList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleOrderedList().run(),\n\t\t\t\ttoggleBlockquote: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBlockquote().run(),\n\t\t\t\ttoggleCodeBlock: () => editor?.chain().focus().toggleCodeBlock().run(),\n\t\t\t\tsetTextAlign: (align) =>\n\t\t\t\t\teditor?.chain().focus().setTextAlign(align).run(),\n\t\t\t\tsetFontFamily: (font) =>\n\t\t\t\t\teditor?.chain().focus().setFontFamily(font).run(),\n\t\t\t\tsetFontSize: (size) => editor?.chain().focus().setFontSize(size).run(),\n\t\t\t\tsetColor: (color) => editor?.chain().focus().setColor(color).run(),\n\t\t\t\tsetHighlight: (color) =>\n\t\t\t\t\teditor?.chain().focus().toggleHighlight({ color }).run(),\n\t\t\t\tunsetColor: () => editor?.chain().focus().unsetColor().run(),\n\t\t\t\tunsetHighlight: () => editor?.chain().focus().unsetHighlight().run(),\n\t\t\t\tsetLink: (href, text) => {\n\t\t\t\t\tif (!editor) return;\n\t\t\t\t\tif (text !== undefined) {\n\t\t\t\t\t\t// Replace both the display text and href in one transaction.\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.command(({ tr, state }) => {\n\t\t\t\t\t\t\t\tconst { from, to } = tr.selection;\n\t\t\t\t\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\t\t\t\t\tif (!linkMarkType) return false;\n\t\t\t\t\t\t\t\ttr.replaceWith(\n\t\t\t\t\t\t\t\t\tfrom,\n\t\t\t\t\t\t\t\t\tto,\n\t\t\t\t\t\t\t\t\tstate.schema.text(text, [linkMarkType.create({ href })]),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t} else {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tupdateLink: (href) =>\n\t\t\t\t\teditor\n\t\t\t\t\t\t?.chain()\n\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t.run(),\n\t\t\t\tremoveLink: () =>\n\t\t\t\t\teditor?.chain().focus().extendMarkRange('link').unsetLink().run(),\n\t\t\t\tinsertEmoji: (emoji) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(emoji).run(),\n\t\t\t\tinsertVariable: (variableName) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(`{{${variableName}}}`).run(),\n\t\t\t\tinsertHtml: (html) => editor?.commands.insertContent(html),\n\t\t\t\tundo: () => editor?.chain().focus().undo().run(),\n\t\t\t\tredo: () => editor?.chain().focus().redo().run(),\n\t\t\t\tcanUndo: () => editor?.can().undo() ?? false,\n\t\t\t\tcanRedo: () => editor?.can().redo() ?? false,\n\t\t\t\ttoggleSuperscript: () =>\n\t\t\t\t\teditor?.chain().focus().toggleSuperscript().run(),\n\t\t\t\ttoggleSubscript: () => editor?.chain().focus().toggleSubscript().run(),\n\t\t\t\tinsertImage: (src) => editor?.chain().focus().setImage({ src }).run(),\n\t\t\t},\n\t\t}),\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t[editor],\n\t);\n\n\tif (!editor) return null;\n\n\treturn (\n\t\t<BikEditorShell\n\t\t\tminHeight={minHeight}\n\t\t\tmaxHeight={maxHeight}\n\t\t\tstyle={style}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t<EditorContent editor={editor} />\n\t\t\t<LinkBubbleMenu editor={editor} renderLinkTooltip={link?.renderTooltip} />\n\t\t</BikEditorShell>\n\t);\n};\n\nexport const BikEditor = forwardRef<BikEditorRef, BikEditorProps>(\n\tBikEditorInner,\n);\nBikEditor.displayName = 'BikEditor';\n"],"names":["cssToString","style","Object","entries","map","_ref","k","v","replace","c","toLowerCase","join","BikEditorInner","props","ref","initialContent","sections","features","disabled","maxCharacters","shortcuts","sendShortcut","mentions","slashCommands","link","onPaste","onReady","onChange","onSend","onFocus","onBlur","onSelectionChange","minHeight","maxHeight","className","editorClassName","editorStyle","initialEditorContent","length","buildSectionedContent","normalizeHtml","s","assign","content","pendingQueue","useRef","hasCalledOnReady","onReadyRef","current","onChangeRef","onSelectionChangeRef","onFocusRef","onBlurRef","onSendRef","editor","useEditor","extensions","buildExtensions","placeholder","hasSections","_a","agents","teams","items","snapshot","call","undefined","onMentionSelected","onSelect","onSlashCommandSelected","renderMentionItem","renderItem","renderMentionDropdown","renderDropdown","renderSlashCommandItem","renderSlashCommandDropdown","editable","immediatelyRender","editorProps","attributes","class","onUpdate","_ref2","e","extractContent","onTransaction","_ref3","extractActiveFormats","enqueue","op","push","useEffect","splice","forEach","useImperativeHandle","focus","position","commands","blur","clearContent","setContent","html","normalised","emitUpdate","insertContent","insertAtStart","insertContentAt","insertBlock","state","doc","size","appendInline","insertAtEnd","this","appendContent","getContent","text","isEmpty","characterCount","getJSON","getMentions","agentIds","Set","teamIds","descendants","node","type","name","attrs","add","String","Array","from","getCursorPosition","to","selection","insertAtPosition","pos","getSelectedText","empty","textBetween","linkMarkType","schema","marks","range","getMarkRange","resolve","getCharacterCount","count","_d","_c","_b","storage","characters","getText","limit","getSectionContent","sectionId","extractSectionContent","setSectionContent","setSectionContentInEditor","focusSection","endOfBody","chain","setTextSelection","run","targetPos","nodeSize","clearSection","getBodyContent","extractBodyContent","setBodyContent","setBodyAndSections","body","id","appendBodyContent","boundaryPos","findSectionEndPos","insertAtSectionStart","findSectionStartPos","insertAtSectionEnd","getActiveFormats","DEFAULT_FORMAT_STATE","actions","toggleBold","toggleItalic","toggleUnderline","toggleStrike","toggleBulletList","toggleOrderedList","toggleBlockquote","toggleCodeBlock","setTextAlign","align","setFontFamily","font","setFontSize","setColor","color","setHighlight","toggleHighlight","unsetColor","unsetHighlight","setLink","href","extendMarkRange","command","_ref4","tr","replaceWith","create","updateLink","removeLink","unsetLink","insertEmoji","emoji","insertVariable","variableName","insertHtml","undo","redo","canUndo","can","canRedo","toggleSuperscript","toggleSubscript","insertImage","src","setImage","_jsxs","BikEditorShell","children","_jsx","jsx","EditorContent","LinkBubbleMenu","renderLinkTooltip","renderTooltip","BikEditor","forwardRef","displayName"],"mappings":"2YAoCA,SAASA,EAAYC,GACpB,OAAOC,OAAOC,QAAQF,GACpBG,KACAC,IAAA,IAAEC,EAAGC,GAAEF,EAAA,MAAK,GAAGC,EAAEE,QAAQ,YAAaC,OAAUA,EAAEC,qBAAoBH,GAAG,IAEzEI,KAAK,IACR,CAEA,MAAMC,EAAiBA,CACtBC,EACAC,WAEA,MAAMC,eACLA,EAAcC,SACdA,EAAQC,SACRA,EAAQC,SACRA,EAAQC,cACRA,EAAaC,UACbA,EAASC,aACTA,EAAYC,SACZA,EAAQC,cACRA,EAAaC,KACbA,EAAIC,QACJA,EAAOC,QACPA,EAAOC,SACPA,EAAQC,OACRA,EAAMC,QACNA,EAAOC,OACPA,EAAMC,kBACNA,EAAiBC,UACjBA,EAASC,UACTA,EAAShC,MACTA,EAAKiC,UACLA,EAASC,gBACTA,EAAeC,YACfA,GACGvB,EAEEwB,GAAuBrB,aAAQ,EAARA,EAAUsB,QACpCC,EAAqBA,sBACrBC,EAAaA,cAACzB,QAAAA,EAAkB,IAChCC,EAASZ,KAAKqC,GAAYvC,OAAAwC,OAAAxC,OAAAwC,OAAA,CAAA,EAAAD,IAAGE,QAASH,EAAAA,cAAcC,EAAEE,cAEtDH,EAAaA,cAACzB,QAAAA,EAAkB,IAO7B6B,EAAeC,SAAmC,IAClDC,EAAmBD,UAAO,GAI1BE,EAAaF,SAAOnB,GAC1BqB,EAAWC,QAAUtB,EACrB,MAAMuB,EAAcJ,SAAOlB,GAC3BsB,EAAYD,QAAUrB,EACtB,MAAMuB,EAAuBL,SAAOd,GACpCmB,EAAqBF,QAAUjB,EAC/B,MAAMoB,EAAaN,SAAOhB,GAC1BsB,EAAW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4H,OAAOtD,MAC3CuD,KAAMA,IAAMtK,aAAM,EAANA,EAAQ6G,QAAQpE,QAAQ6H,OAAOvD,MAC3CwD,QAASA,WAAM,OAAwB,QAAxBjK,EAAAN,eAAAA,EAAQwK,MAAMH,cAAU,IAAA/J,GAAAA,CAAK,EAC5CmK,QAASA,WAAM,OAAwB,QAAxBnK,EAAAN,eAAAA,EAAQwK,MAAMF,cAAU,IAAAhK,GAAAA,CAAK,EAC5CoK,kBAAmBA,IAClB1K,aAAM,EAANA,EAAQ6G,QAAQpE,QAAQiI,oBAAoB3D,MAC7C4D,gBAAiBA,IAAM3K,aAAM,EAANA,EAAQ6G,QAAQpE,QAAQkI,kBAAkB5D,MACjE6D,YAAcC,GAAQ7K,aAAA,EAAAA,EAAQ6G,QAAQpE,QAAQqI,SAAS,CAAED,QAAO9D,UAIlE,CAAC/G,IAGGA,EAGJ+K,OAACC,EAAAA,eAAcpO,OAAAwC,OAAA,CACdV,UAAWA,EACXC,UAAWA,EACXhC,MAAOA,EACPiC,UAAWA,GAEX,CAAAqM,SAAA,CAAAC,EAAAC,IAACC,gBAAa,CAACpL,OAAQA,IACvBkL,EAAAC,IAACE,iBAAe,CAAArL,OAAQA,EAAQsL,kBAAmBpN,aAAA,EAAAA,EAAMqN,oBAVvC,IAWF,EAINC,EAAYC,EAAUA,WAClCnO,GAEDkO,EAAUE,YAAc"}
1
+ {"version":3,"file":"BikEditor.js","sources":["../../../src/editor/BikEditor.tsx"],"sourcesContent":["'use client';\n\n/**\n * IMPLEMENTATION LAYER — TipTap-specific.\n * If the underlying editor is swapped, this file changes; BikEditor.types.ts and\n * src/editor/index.ts (the consumer contract) do NOT change.\n */\nimport { Editor, getMarkRange } from '@tiptap/core';\nimport { EditorContent, useEditor } from '@tiptap/react';\nimport React, {\n\tforwardRef,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n} from 'react';\nimport { BikEditorShell } from './BikEditor.styles';\nimport {\n\tBikEditorProps,\n\tBikEditorRef,\n\tDEFAULT_FORMAT_STATE,\n} from './BikEditor.types';\nimport {\n\tbuildSectionedContent,\n\textractActiveFormats,\n\textractBodyContent,\n\textractContent,\n\textractSectionContent,\n\tfindSectionEndPos,\n\tfindSectionStartPos,\n\tnormalizeHtml,\n\tsetSectionContentInEditor,\n} from './BikEditor.utils';\nimport { buildExtensions } from './extensions/buildExtensions';\nimport { LinkBubbleMenu } from './floating/LinkBubbleMenu';\n\n/** Convert React.CSSProperties to an inline CSS string for editorProps.attributes. */\nfunction cssToString(style: React.CSSProperties): string {\n\treturn Object.entries(style)\n\t\t.map(\n\t\t\t([k, v]) => `${k.replace(/([A-Z])/g, (c) => `-${c.toLowerCase()}`)}:${v}`,\n\t\t)\n\t\t.join(';');\n}\n\nconst BikEditorInner = (\n\tprops: BikEditorProps,\n\tref: React.Ref<BikEditorRef>,\n) => {\n\tconst {\n\t\tinitialContent,\n\t\tsections,\n\t\tfeatures,\n\t\tdisabled,\n\t\tmaxCharacters,\n\t\tshortcuts,\n\t\tsendShortcut,\n\t\tmentions,\n\t\tslashCommands,\n\t\tlink,\n\t\tonPaste,\n\t\tonReady,\n\t\tonChange,\n\t\tonSend,\n\t\tonFocus,\n\t\tonBlur,\n\t\tonSelectionChange,\n\t\tminHeight,\n\t\tmaxHeight,\n\t\tstyle,\n\t\tclassName,\n\t\teditorClassName,\n\t\teditorStyle,\n\t} = props;\n\n\tconst initialEditorContent = sections?.length\n\t\t? buildSectionedContent(\n\t\t\t\tnormalizeHtml(initialContent ?? ''),\n\t\t\t\tsections.map((s) => ({ ...s, content: normalizeHtml(s.content) })),\n\t\t )\n\t\t: normalizeHtml(initialContent ?? '');\n\n\t// ── Command queue ─────────────────────────────────────────────────────────\n\t// TipTap's useEditor initializes asynchronously; the editor instance is null\n\t// until the first commit. Any imperative method called before the editor is\n\t// ready is enqueued here and flushed automatically once it becomes non-null.\n\t// Consumers never need setTimeout or readiness guards.\n\tconst pendingQueue = useRef<Array<(e: Editor) => void>>([]);\n\tconst hasCalledOnReady = useRef(false);\n\t// Keep stable refs to all callbacks so useEditor receives the same function\n\t// identity on every render — prevents TipTap from re-registering event\n\t// handlers every time the parent re-renders with new inline function props.\n\tconst onReadyRef = useRef(onReady);\n\tonReadyRef.current = onReady;\n\tconst onChangeRef = useRef(onChange);\n\tonChangeRef.current = onChange;\n\tconst onSelectionChangeRef = useRef(onSelectionChange);\n\tonSelectionChangeRef.current = onSelectionChange;\n\tconst onFocusRef = useRef(onFocus);\n\tonFocusRef.current = onFocus;\n\tconst onBlurRef = useRef(onBlur);\n\tonBlurRef.current = onBlur;\n\tconst onSendRef = useRef(onSend);\n\tonSendRef.current = onSend;\n\n\tconst editor = useEditor({\n\t\textensions: buildExtensions({\n\t\t\tfeatures,\n\t\t\tplaceholder: props.placeholder,\n\t\t\tmaxCharacters,\n\t\t\thasSections: (sections?.length ?? 0) > 0,\n\t\t\tmentions: {\n\t\t\t\tagents: mentions?.agents,\n\t\t\t\tteams: mentions?.teams,\n\t\t\t},\n\t\t\tslashCommands: slashCommands?.items,\n\t\t\tonPaste,\n\t\t\tonSend: onSend ? (snapshot) => onSendRef.current?.(snapshot) : undefined,\n\t\t\tsendShortcut,\n\t\t\tshortcuts,\n\t\t\tonMentionSelected: mentions?.onSelect,\n\t\t\tonSlashCommandSelected: slashCommands?.onSelect,\n\t\t\trenderMentionItem: mentions?.renderItem,\n\t\t\trenderMentionDropdown: mentions?.renderDropdown,\n\t\t\trenderSlashCommandItem: slashCommands?.renderItem,\n\t\t\trenderSlashCommandDropdown: slashCommands?.renderDropdown,\n\t\t}),\n\t\tcontent: initialEditorContent,\n\t\teditable: !disabled,\n\t\timmediatelyRender: false, // SSR-safe — NEVER remove this\n\t\teditorProps: {\n\t\t\tattributes: {\n\t\t\t\t...(editorClassName ? { class: editorClassName } : {}),\n\t\t\t\t...(editorStyle ? { style: cssToString(editorStyle) } : {}),\n\t\t\t},\n\t\t},\n\t\tonUpdate: ({ editor: e }) => {\n\t\t\tonChangeRef.current?.(extractContent(e));\n\t\t},\n\t\tonTransaction: ({ editor: e }) => {\n\t\t\tonSelectionChangeRef.current?.(extractActiveFormats(e));\n\t\t},\n\t\tonFocus: () => onFocusRef.current?.(),\n\t\tonBlur: () => onBlurRef.current?.(),\n\t});\n\n\t// ── enqueue ───────────────────────────────────────────────────────────────\n\t// Run immediately if the editor is ready; otherwise defer to the queue.\n\t// Closures passed to enqueue MUST capture all parameters explicitly —\n\t// they must NOT close over `editor` (which would be null at enqueue time).\n\tfunction enqueue(op: (e: Editor) => void): void {\n\t\tif (editor) {\n\t\t\top(editor);\n\t\t} else {\n\t\t\tpendingQueue.current.push(op);\n\t\t}\n\t}\n\n\t// Flush the pending queue and fire onReady when editor transitions null → ready.\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\t\tif (pendingQueue.current.length > 0) {\n\t\t\tconst queue = pendingQueue.current.splice(0);\n\t\t\tqueue.forEach((op) => op(editor));\n\t\t}\n\t\tif (!hasCalledOnReady.current) {\n\t\t\thasCalledOnReady.current = true;\n\t\t\tonReadyRef.current?.();\n\t\t}\n\t}, [editor]);\n\n\tuseImperativeHandle(\n\t\tref,\n\t\t() => ({\n\t\t\t// ── Focus ────────────────────────────────────────────────────────\n\t\t\tfocus: (position) => enqueue((e) => e.commands.focus(position)),\n\t\t\tblur: () => enqueue((e) => e.commands.blur()),\n\n\t\t\t// ── Content ──────────────────────────────────────────────────────\n\t\t\tclearContent: () => enqueue((e) => e.commands.clearContent(true)),\n\t\t\tsetContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.setContent(normalised, { emitUpdate: true }));\n\t\t\t},\n\t\t\tinsertContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContent(normalised));\n\t\t\t},\n\t\t\tinsertAtStart: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(1, normalised));\n\t\t\t},\n\t\t\tinsertBlock: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\tappendInline: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// doc.content.size is after the last </p> (block boundary).\n\t\t\t\t// Subtract 1 to land inside the last paragraph so text appends\n\t\t\t\t// inline rather than being wrapped in a new paragraph each call.\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size - 1, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\t// Backwards-compatible aliases\n\t\t\tinsertAtEnd(html) {\n\t\t\t\tthis.insertBlock(html);\n\t\t\t},\n\t\t\tappendContent(html) {\n\t\t\t\tthis.appendInline(html);\n\t\t\t},\n\t\t\tgetContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tgetJSON: () => editor?.getJSON() ?? null,\n\t\t\tgetMentions: () => {\n\t\t\t\tconst agentIds = new Set<string>();\n\t\t\t\tconst teamIds = new Set<string>();\n\t\t\t\tif (!editor) return { agentIds: [], teamIds: [] };\n\t\t\t\teditor.state.doc.descendants((node) => {\n\t\t\t\t\tif (node.type.name === 'mentionAgent' && node.attrs['id'] != null) {\n\t\t\t\t\t\tagentIds.add(String(node.attrs['id']));\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tnode.type.name === 'mentionTeam' &&\n\t\t\t\t\t\tnode.attrs['id'] != null\n\t\t\t\t\t) {\n\t\t\t\t\t\tteamIds.add(String(node.attrs['id']));\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn { agentIds: Array.from(agentIds), teamIds: Array.from(teamIds) };\n\t\t\t},\n\n\t\t\t// ── Selection ────────────────────────────────────────────────────\n\t\t\tgetCursorPosition: () => {\n\t\t\t\tif (!editor) return { from: 0, to: 0 };\n\t\t\t\tconst { from, to } = editor.state.selection;\n\t\t\t\treturn { from, to };\n\t\t\t},\n\t\t\tinsertAtPosition: (pos, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(pos, normalised));\n\t\t\t},\n\t\t\tgetSelectedText: () => {\n\t\t\t\tif (!editor) return '';\n\t\t\t\tconst { state } = editor;\n\t\t\t\tconst { from, to, empty } = state.selection;\n\t\t\t\tif (!empty) {\n\t\t\t\t\treturn state.doc.textBetween(from, to, ' ');\n\t\t\t\t}\n\t\t\t\t// When the cursor is inside a link with nothing selected, return the\n\t\t\t\t// full link text — useful for pre-filling a link modal's text field.\n\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\tif (linkMarkType) {\n\t\t\t\t\tconst range = getMarkRange(state.doc.resolve(from), linkMarkType);\n\t\t\t\t\tif (range) {\n\t\t\t\t\t\treturn state.doc.textBetween(range.from, range.to, ' ');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn '';\n\t\t\t},\n\n\t\t\t// ── Character count ───────────────────────────────────────────────\n\t\t\tgetCharacterCount: () => ({\n\t\t\t\tcount:\n\t\t\t\t\teditor?.storage.characterCount?.characters?.() ??\n\t\t\t\t\teditor?.getText().length ??\n\t\t\t\t\t0,\n\t\t\t\tlimit: maxCharacters ?? null,\n\t\t\t}),\n\n\t\t\t// ── Sections ─────────────────────────────────────────────────────\n\t\t\tgetSectionContent: (sectionId) =>\n\t\t\t\teditor\n\t\t\t\t\t? extractSectionContent(editor, sectionId)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\n\t\t\tsetSectionContent: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, normalised));\n\t\t\t},\n\n\t\t\tfocusSection: (sectionId) => {\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tif (sectionId === 'body') {\n\t\t\t\t\t\tlet endOfBody = e.state.doc.content.size - 1;\n\t\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\t\tendOfBody === e.state.doc.content.size - 1\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tendOfBody = pos - 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn endOfBody === e.state.doc.content.size - 1;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (endOfBody < 1) endOfBody = 1;\n\t\t\t\t\t\te.chain().focus().setTextSelection(endOfBody).run();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet targetPos = -1;\n\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\tif (targetPos !== -1) return false;\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// pos + nodeSize lands right after the divider;\n\t\t\t\t\t\t\t// +1 more puts us inside the first paragraph of that section.\n\t\t\t\t\t\t\ttargetPos = pos + node.nodeSize + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tif (targetPos !== -1) {\n\t\t\t\t\t\te.chain().focus().setTextSelection(targetPos).run();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\n\t\t\tclearSection: (sectionId) => {\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, '<p></p>'));\n\t\t\t},\n\n\t\t\t// ── Convenience body shorthands ───────────────────────────────────\n\t\t\tgetBodyContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractBodyContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tsetBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, 'body', normalised));\n\t\t\t},\n\t\t\tsetBodyAndSections: (body, sections) => {\n\t\t\t\tconst html = buildSectionedContent(\n\t\t\t\t\tnormalizeHtml(body),\n\t\t\t\t\tsections.map((s) => ({\n\t\t\t\t\t\tid: s.id,\n\t\t\t\t\t\tcontent: normalizeHtml(s.content),\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t\tenqueue((e) => e.commands.setContent(html, { emitUpdate: true }));\n\t\t\t},\n\t\t\tappendBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// findSectionEndPos returns the position of the first divider (or\n\t\t\t\t// doc.content.size), which is the block boundary after the last </p>.\n\t\t\t\t// Subtract 1 to stay inside the last paragraph so successive calls\n\t\t\t\t// append inline text rather than creating a new paragraph each time.\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst boundaryPos = findSectionEndPos(e, 'body');\n\t\t\t\t\te.commands.insertContentAt(boundaryPos - 1, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionStart: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionStartPos(e, sectionId);\n\t\t\t\t\tif (pos !== -1) e.commands.insertContentAt(pos, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionEnd: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionEndPos(e, sectionId);\n\t\t\t\t\te.commands.insertContentAt(pos, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\t// ── Formats & actions ─────────────────────────────────────────────\n\t\t\tgetActiveFormats: () =>\n\t\t\t\teditor ? extractActiveFormats(editor) : DEFAULT_FORMAT_STATE,\n\t\t\tactions: {\n\t\t\t\ttoggleBold: () => editor?.chain().focus().toggleBold().run(),\n\t\t\t\ttoggleItalic: () => editor?.chain().focus().toggleItalic().run(),\n\t\t\t\ttoggleUnderline: () => editor?.chain().focus().toggleUnderline().run(),\n\t\t\t\ttoggleStrike: () => editor?.chain().focus().toggleStrike().run(),\n\t\t\t\ttoggleBulletList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBulletList().run(),\n\t\t\t\ttoggleOrderedList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleOrderedList().run(),\n\t\t\t\ttoggleBlockquote: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBlockquote().run(),\n\t\t\t\ttoggleCodeBlock: () => editor?.chain().focus().toggleCodeBlock().run(),\n\t\t\t\tsetTextAlign: (align) =>\n\t\t\t\t\teditor?.chain().focus().setTextAlign(align).run(),\n\t\t\t\tsetFontFamily: (font) =>\n\t\t\t\t\teditor?.chain().focus().setFontFamily(font).run(),\n\t\t\t\tsetFontSize: (size) => editor?.chain().focus().setFontSize(size).run(),\n\t\t\t\tsetColor: (color) => editor?.chain().focus().setColor(color).run(),\n\t\t\t\tsetHighlight: (color) =>\n\t\t\t\t\teditor?.chain().focus().toggleHighlight({ color }).run(),\n\t\t\t\tunsetColor: () => editor?.chain().focus().unsetColor().run(),\n\t\t\t\tunsetHighlight: () => editor?.chain().focus().unsetHighlight().run(),\n\t\t\t\tsetLink: (href, text) => {\n\t\t\t\t\tif (!editor) return;\n\t\t\t\t\tif (text !== undefined) {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.command(({ tr, state }) => {\n\t\t\t\t\t\t\t\tconst { from, to } = tr.selection;\n\t\t\t\t\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\t\t\t\t\tif (!linkMarkType) return false;\n\t\t\t\t\t\t\t\tconst linkNode = state.schema.text(text, [\n\t\t\t\t\t\t\t\t\tlinkMarkType.create({ href }),\n\t\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\t\tconst space = state.schema.text(' ');\n\t\t\t\t\t\t\t\ttr.replaceWith(from, to, [linkNode, space]);\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t} else {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t\t.insertContent(' ')\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tupdateLink: (href) =>\n\t\t\t\t\teditor\n\t\t\t\t\t\t?.chain()\n\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t.run(),\n\t\t\t\tremoveLink: () =>\n\t\t\t\t\teditor?.chain().focus().extendMarkRange('link').unsetLink().run(),\n\t\t\t\tinsertEmoji: (emoji) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(emoji).run(),\n\t\t\t\tinsertVariable: (variableName) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(`{{${variableName}}}`).run(),\n\t\t\t\tinsertHtml: (html) => editor?.commands.insertContent(html),\n\t\t\t\tundo: () => editor?.chain().focus().undo().run(),\n\t\t\t\tredo: () => editor?.chain().focus().redo().run(),\n\t\t\t\tcanUndo: () => editor?.can().undo() ?? false,\n\t\t\t\tcanRedo: () => editor?.can().redo() ?? false,\n\t\t\t\ttoggleSuperscript: () =>\n\t\t\t\t\teditor?.chain().focus().toggleSuperscript().run(),\n\t\t\t\ttoggleSubscript: () => editor?.chain().focus().toggleSubscript().run(),\n\t\t\t\tinsertImage: (src) => editor?.chain().focus().setImage({ src }).run(),\n\t\t\t},\n\t\t}),\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t[editor],\n\t);\n\n\tif (!editor) return null;\n\n\treturn (\n\t\t<BikEditorShell\n\t\t\tminHeight={minHeight}\n\t\t\tmaxHeight={maxHeight}\n\t\t\tstyle={style}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t<EditorContent editor={editor} />\n\t\t\t<LinkBubbleMenu editor={editor} renderLinkTooltip={link?.renderTooltip} />\n\t\t</BikEditorShell>\n\t);\n};\n\nexport const BikEditor = forwardRef<BikEditorRef, BikEditorProps>(\n\tBikEditorInner,\n);\nBikEditor.displayName = 'BikEditor';\n"],"names":["cssToString","style","Object","entries","map","_ref","k","v","replace","c","toLowerCase","join","BikEditorInner","props","ref","initialContent","sections","features","disabled","maxCharacters","shortcuts","sendShortcut","mentions","slashCommands","link","onPaste","onReady","onChange","onSend","onFocus","onBlur","onSelectionChange","minHeight","maxHeight","className","editorClassName","editorStyle","initialEditorContent","length","buildSectionedContent","normalizeHtml","s","assign","content","pendingQueue","useRef","hasCalledOnReady","onReadyRef","current","onChangeRef","onSelectionChangeRef","onFocusRef","onBlurRef","onSendRef","editor","useEditor","extensions","buildExtensions","placeholder","hasSections","_a","agents","teams","items","snapshot","call","undefined","onMentionSelected","onSelect","onSlashCommandSelected","renderMentionItem","renderItem","renderMentionDropdown","renderDropdown","renderSlashCommandItem","renderSlashCommandDropdown","editable","immediatelyRender","editorProps","attributes","class","onUpdate","_ref2","e","extractContent","onTransaction","_ref3","extractActiveFormats","enqueue","op","push","useEffect","splice","forEach","useImperativeHandle","focus","position","commands","blur","clearContent","setContent","html","normalised","emitUpdate","insertContent","insertAtStart","insertContentAt","insertBlock","state","doc","size","appendInline","insertAtEnd","this","appendContent","getContent","text","isEmpty","characterCount","getJSON","getMentions","agentIds","Set","teamIds","descendants","node","type","name","attrs","add","String","Array","from","getCursorPosition","to","selection","insertAtPosition","pos","getSelectedText","empty","textBetween","linkMarkType","schema","marks","range","getMarkRange","resolve","getCharacterCount","count","_d","_c","_b","storage","characters","getText","limit","getSectionContent","sectionId","extractSectionContent","setSectionContent","setSectionContentInEditor","focusSection","endOfBody","chain","setTextSelection","run","targetPos","nodeSize","clearSection","getBodyContent","extractBodyContent","setBodyContent","setBodyAndSections","body","id","appendBodyContent","boundaryPos","findSectionEndPos","insertAtSectionStart","findSectionStartPos","insertAtSectionEnd","getActiveFormats","DEFAULT_FORMAT_STATE","actions","toggleBold","toggleItalic","toggleUnderline","toggleStrike","toggleBulletList","toggleOrderedList","toggleBlockquote","toggleCodeBlock","setTextAlign","align","setFontFamily","font","setFontSize","setColor","color","setHighlight","toggleHighlight","unsetColor","unsetHighlight","setLink","href","extendMarkRange","command","_ref4","tr","linkNode","create","space","replaceWith","updateLink","removeLink","unsetLink","insertEmoji","emoji","insertVariable","variableName","insertHtml","undo","redo","canUndo","can","canRedo","toggleSuperscript","toggleSubscript","insertImage","src","setImage","_jsxs","BikEditorShell","children","_jsx","jsx","EditorContent","LinkBubbleMenu","renderLinkTooltip","renderTooltip","BikEditor","forwardRef","displayName"],"mappings":"2YAoCA,SAASA,EAAYC,GACpB,OAAOC,OAAOC,QAAQF,GACpBG,KACAC,IAAA,IAAEC,EAAGC,GAAEF,EAAA,MAAK,GAAGC,EAAEE,QAAQ,YAAaC,OAAUA,EAAEC,qBAAoBH,GAAG,IAEzEI,KAAK,IACR,CAEA,MAAMC,EAAiBA,CACtBC,EACAC,WAEA,MAAMC,eACLA,EAAcC,SACdA,EAAQC,SACRA,EAAQC,SACRA,EAAQC,cACRA,EAAaC,UACbA,EAASC,aACTA,EAAYC,SACZA,EAAQC,cACRA,EAAaC,KACbA,EAAIC,QACJA,EAAOC,QACPA,EAAOC,SACPA,EAAQC,OACRA,EAAMC,QACNA,EAAOC,OACPA,EAAMC,kBACNA,EAAiBC,UACjBA,EAASC,UACTA,EAAShC,MACTA,EAAKiC,UACLA,EAASC,gBACTA,EAAeC,YACfA,GACGvB,EAEEwB,GAAuBrB,aAAQ,EAARA,EAAUsB,QACpCC,EAAqBA,sBACrBC,EAAaA,c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A,IACvBoL,EAAAC,IAACE,iBAAe,CAAAvL,OAAQA,EAAQwL,kBAAmBtN,aAAA,EAAAA,EAAMuN,oBAVvC,IAWF,EAINC,EAAYC,EAAUA,WAClCrO,GAEDoO,EAAUE,YAAc"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("../node_modules/prosemirror-model/dist/index.js");const e=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function n(t){var e;if(!t)return"";return null!==(e=i(t).get("body"))&&void 0!==e?e:t}function i(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 r(e,n){var i;const r=o(e,n);if(-1===r)return{html:"",text:"",isEmpty:!0,characterCount:0};const c=s(e,n),l=e.state.doc.slice(r,c),d=document.createElement("div"),u=t.DOMSerializer.fromSchema(e.schema);d.appendChild(u.serializeFragment(l.content));const a=d.innerHTML,v=null!==(i=d.textContent)&&void 0!==i?i:"";return{html:a,text:v,isEmpty:!v.trim(),characterCount:v.length}}function o(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 s(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=e,exports.buildSectionedContent=function(t,n){let i=t;for(const t of n)i+=e(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=i,exports.extractBodyContent=function(t){return r(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=r,exports.findSectionEndPos=s,exports.findSectionStartPos=o,exports.getBodyHtml=n,exports.getSectionsHtml=function(t){if(!t)return"";const e=n(t);return t.substring(e.length)},exports.normalizeHtml=function(t){return t.replace(/<p>\s*<br\s*\/?>\s*<\/p>/gi,"<p></p>").replace(/<span[^>]*>(\{\{[^}]+\}\})<\/span>/gi,"$1")},exports.setSectionContentInEditor=function(n,i,r){const c=o(n,i);if(-1===c){const t=n.state.doc.content.size,o=e(i)+r;return void n.commands.insertContentAt(t,o,{updateSelection:!1})}const l=s(n,i),d=function(e,n){const i=document.createElement("div");return i.innerHTML=n,t.DOMParser.fromSchema(e.schema).parse(i).content}(n,r),{tr:u}=n.state,a="body"===i?0:c;u.replaceWith(a,l,d),u.setMeta("addToHistory",!1),n.view.dispatch(u)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("../node_modules/prosemirror-model/dist/index.js");const e=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function n(t){var e;if(!t)return"";return null!==(e=i(t).get("body"))&&void 0!==e?e:t}function i(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 r(e,n){var i;const r=o(e,n);if(-1===r)return{html:"",text:"",isEmpty:!0,characterCount:0};const c=s(e,n),l=e.state.doc.slice(r,c),d=document.createElement("div"),u=t.DOMSerializer.fromSchema(e.schema);d.appendChild(u.serializeFragment(l.content));const a=d.innerHTML,v=null!==(i=d.textContent)&&void 0!==i?i:"";return{html:a,text:v,isEmpty:!v.trim(),characterCount:v.length}}function o(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 s(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=e,exports.buildSectionedContent=function(t,n){let i=t;for(const t of n)i+=e(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=i,exports.extractBodyContent=function(t){return r(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=r,exports.findSectionEndPos=s,exports.findSectionStartPos=o,exports.getBodyHtml=n,exports.getSectionsHtml=function(t){if(!t)return"";const e=n(t);return t.substring(e.length)},exports.normalizeHtml=function(t){return t.replace(/<p>\s*<br\s*\/?>\s*<\/p>/gi,"<p></p>").replace(/<\/?span[^>]*>/gi,"")},exports.setSectionContentInEditor=function(n,i,r){const c=o(n,i);if(-1===c){const t=n.state.doc.content.size,o=e(i)+r;return void n.commands.insertContentAt(t,o,{updateSelection:!1})}const l=s(n,i),d=function(e,n){const i=document.createElement("div");return i.innerHTML=n,t.DOMParser.fromSchema(e.schema).parse(i).content}(n,r),{tr:u}=n.state,a="body"===i?0:c;u.replaceWith(a,l,d),u.setMeta("addToHistory",!1),n.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 } 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[^>]*>(\\{\\{[^}]+\\}\\})<\\/span>/gi, '$1');\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":["SECTION_DIVIDER_HTML","id","getBodyHtml","html","_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","replace","dividerHtml","commands","insertContentAt","updateSelection","fragment","DOMParser","parse","parseHtmlToNodes","tr","replaceFrom","replaceWith","setMeta","view","dispatch"],"mappings":"2IAgCaA,EAAwBC,GACpC,8BAA8BA,yEAyCzB,SAAUC,EAAYC,SAC3B,IAAKA,EAAM,MAAO,GAElB,OAA+B,QAAxBC,EADUC,EAA2BF,GAC5BG,IAAI,eAAW,IAAAF,EAAAA,EAAAD,CAChC,CAYM,SAAUE,EAA2BF,GAC1C,MAAMI,EAAW,IAAIC,IACfC,EACL,0DACKC,EAAmE,GAEzE,IAAIC,EACJ,KAA6C,QAArCA,EAAQF,EAAaG,KAAKT,KACjCO,EAASG,KAAK,CACbZ,GAAIU,EAAM,GACVG,MAAOH,EAAMG,MACbC,SAAUJ,EAAMG,MAAQH,EAAM,GAAGK,SAInC,GAAwB,IAApBN,EAASM,OAEZ,OADAT,EAASU,IAAI,OAAQd,GACdI,EAGRA,EAASU,IAAI,OAAQd,EAAKe,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,MAAQX,EAAKa,OACnET,EAASU,IAAIP,EAASS,GAAGlB,GAAIE,EAAKe,MAAME,EAAOC,GAC/C,CAED,OAAOd,CACR,CAGgB,SAAAe,EACfC,EACAtB,SAEA,MAAMuB,EAAWC,EAAoBF,EAAQtB,GAC7C,IAAkB,IAAduB,EACH,MAA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gBAAgBvE,EAAQqE,EAAa,CACpDG,iBAAiB,GAGlB,CACD,MAAMxE,EAASC,EAAkBP,EAAQtB,GACnCqG,EA3BP,SAA0B/E,EAAgBpB,GACzC,MAAM8B,EAAYC,SAASC,cAAc,OAEzC,OADAF,EAAUU,UAAYxC,EACfoG,EAASA,UAACjE,WAAWf,EAAOgB,QAAQiE,MAAMvE,GAAWS,OAC7D,CAuBkB+D,CAAiBlF,EAAQpB,IACpCuG,GAAEA,GAAOnF,EAAOQ,MAKhB4E,EAAqB,SAAP1G,EAAgB,EAAIuB,EACxCkF,EAAGE,YAAYD,EAAa9E,EAAQyE,GACpCI,EAAGG,QAAQ,gBAAgB,GAC3BtF,EAAOuF,KAAKC,SAASL,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';\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// 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":["SECTION_DIVIDER_HTML","id","getBodyHtml","html","_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","replace","dividerHtml","commands","insertContentAt","updateSelection","fragment","DOMParser","parse","parseHtmlToNodes","tr","replaceFrom","replaceWith","setMeta","view","dispatch"],"mappings":"2IAgCaA,EAAwBC,GACpC,8BAA8BA,yEAyCzB,SAAUC,EAAYC,SAC3B,IAAKA,EAAM,MAAO,GAElB,OAA+B,QAAxBC,EADUC,EAA2BF,GAC5BG,IAAI,eAAW,IAAAF,EAAAA,EAAAD,CAChC,CAYM,SAAUE,EAA2BF,GAC1C,MAAMI,EAAW,IAAIC,IACfC,EACL,0DACKC,EAAmE,GAEzE,IAAIC,EACJ,KAA6C,QAArCA,EAAQF,EAAaG,KAAKT,KACjCO,EAASG,KAAK,CACbZ,GAAIU,EAAM,GACVG,MAAOH,EAAMG,MACbC,SAAUJ,EAAMG,MAAQH,EAAM,GAAGK,SAInC,GAAwB,IAApBN,EAASM,OAEZ,OADAT,EAASU,IAAI,OAAQd,GACdI,EAGRA,EAASU,IAAI,OAAQd,EAAKe,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,MAAQX,EAAKa,OACnET,EAASU,IAAIP,EAASS,GAAGlB,GAAIE,EAAKe,MAAME,EAAOC,GAC/C,CAED,OAAOd,CACR,CAGgB,SAAAe,EACfC,EACAtB,SAEA,MAAMuB,EAAWC,EAAoBF,EAAQtB,GAC7C,IAAkB,IAAduB,EACH,MAAO,CAAErB,KAAM,GAAIuB,KAAM,GAAIC,SAAS,EAAMC,eAAgB,GAC7D,MAAMC,EAASC,EAAkBP,EAAQtB,GACnCiB,EAAQK,EAAOQ,MAAMC,IAAId,MAAMM,EAAUK,GACzCI,EAAYC,SAASC,cAAc,OACnCC,EAAaC,E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,EAASA,UAACjE,WAAWf,EAAOgB,QAAQiE,MAAMvE,GAAWS,OAC7D,CAuBkB+D,CAAiBlF,EAAQpB,IACpCuG,GAAEA,GAAOnF,EAAOQ,MAKhB4E,EAAqB,SAAP1G,EAAgB,EAAIuB,EACxCkF,EAAGE,YAAYD,EAAa9E,EAAQyE,GACpCI,EAAGG,QAAQ,gBAAgB,GAC3BtF,EAAOuF,KAAKC,SAASL,EACtB"}
@@ -1,2 +1,2 @@
1
- import{jsxs as t,jsx as n}from"react/jsx-runtime";import{getMarkRange as e}from"../node_modules/@tiptap/core/dist/index.js";import{useEditor as o,EditorContent as r}from"@tiptap/react";import{forwardRef as i,useRef as s,useEffect as l,useImperativeHandle as c}from"react";import{BikEditorShell as a}from"./BikEditor.styles.js";import{DEFAULT_FORMAT_STATE as d}from"./BikEditor.types.js";import{buildSectionedContent as u,normalizeHtml as m,extractContent as g,extractActiveFormats as h,extractSectionContent as v,extractBodyContent as f,setSectionContentInEditor as p,findSectionEndPos as C,findSectionStartPos as S}from"./BikEditor.utils.js";import{buildExtensions as k}from"./extensions/buildExtensions.js";import{LinkBubbleMenu as y}from"./floating/LinkBubbleMenu.js";function x(t){return Object.entries(t).map((t=>{let[n,e]=t;return`${n.replace(/([A-Z])/g,(t=>`-${t.toLowerCase()}`))}:${e}`})).join(";")}const B=i(((i,B)=>{var b;const{initialContent:A,sections:j,features:I,disabled:L,maxCharacters:E,shortcuts:O,sendShortcut:T,mentions:w,slashCommands:F,link:H,onPaste:M,onReady:z,onChange:R,onSend:D,onFocus:N,onBlur:U,onSelectionChange:P,minHeight:$,maxHeight:q,style:J,className:V,editorClassName:W,editorStyle:Z}=i,_=(null==j?void 0:j.length)?u(m(null!=A?A:""),j.map((t=>Object.assign(Object.assign({},t),{content:m(t.content)})))):m(null!=A?A:""),G=s([]),K=s(!1),Q=s(z);Q.current=z;const X=s(R);X.current=R;const Y=s(P);Y.current=P;const tt=s(N);tt.current=N;const nt=s(U);nt.current=U;const et=s(D);et.current=D;const ot=o({extensions:k({features:I,placeholder:i.placeholder,maxCharacters:E,hasSections:(null!==(b=null==j?void 0:j.length)&&void 0!==b?b:0)>0,mentions:{agents:null==w?void 0:w.agents,teams:null==w?void 0:w.teams},slashCommands:null==F?void 0:F.items,onPaste:M,onSend:D?t=>{var n;return null===(n=et.current)||void 0===n?void 0:n.call(et,t)}:void 0,sendShortcut:T,shortcuts:O,onMentionSelected:null==w?void 0:w.onSelect,onSlashCommandSelected:null==F?void 0:F.onSelect,renderMentionItem:null==w?void 0:w.renderItem,renderMentionDropdown:null==w?void 0:w.renderDropdown,renderSlashCommandItem:null==F?void 0:F.renderItem,renderSlashCommandDropdown:null==F?void 0:F.renderDropdown}),content:_,editable:!L,immediatelyRender:!1,editorProps:{attributes:Object.assign(Object.assign({},W?{class:W}:{}),Z?{style:x(Z)}:{})},onUpdate:t=>{let{editor:n}=t;var e;null===(e=X.current)||void 0===e||e.call(X,g(n))},onTransaction:t=>{let{editor:n}=t;var e;null===(e=Y.current)||void 0===e||e.call(Y,h(n))},onFocus:()=>{var t;return null===(t=tt.current)||void 0===t?void 0:t.call(tt)},onBlur:()=>{var t;return null===(t=nt.current)||void 0===t?void 0:t.call(nt)}});function rt(t){ot?t(ot):G.current.push(t)}return l((()=>{var t;if(ot){if(G.current.length>0){G.current.splice(0).forEach((t=>t(ot)))}K.current||(K.current=!0,null===(t=Q.current)||void 0===t||t.call(Q))}}),[ot]),c(B,(()=>({focus:t=>rt((n=>n.commands.focus(t))),blur:()=>rt((t=>t.commands.blur())),clearContent:()=>rt((t=>t.commands.clearContent(!0))),setContent:t=>{const n=m(t);rt((t=>t.commands.setContent(n,{emitUpdate:!0})))},insertContent:t=>{const n=m(t);rt((t=>t.commands.insertContent(n)))},insertAtStart:t=>{const n=m(t);rt((t=>t.commands.insertContentAt(1,n)))},insertBlock:t=>{const n=m(t);rt((t=>t.commands.insertContentAt(t.state.doc.content.size,n)))},appendInline:t=>{const n=m(t);rt((t=>t.commands.insertContentAt(t.state.doc.content.size-1,n)))},insertAtEnd(t){this.insertBlock(t)},appendContent(t){this.appendInline(t)},getContent:()=>ot?g(ot):{html:"",text:"",isEmpty:!0,characterCount:0},getJSON:()=>{var t;return null!==(t=null==ot?void 0:ot.getJSON())&&void 0!==t?t:null},getMentions:()=>{const t=new Set,n=new Set;return ot?(ot.state.doc.descendants((e=>{"mentionAgent"===e.type.name&&null!=e.attrs.id?t.add(String(e.attrs.id)):"mentionTeam"===e.type.name&&null!=e.attrs.id&&n.add(String(e.attrs.id))})),{agentIds:Array.from(t),teamIds:Array.from(n)}):{agentIds:[],teamIds:[]}},getCursorPosition:()=>{if(!ot)return{from:0,to:0};const{from:t,to:n}=ot.state.selection;return{from:t,to:n}},insertAtPosition:(t,n)=>{const e=m(n);rt((n=>n.commands.insertContentAt(t,e)))},getSelectedText:()=>{if(!ot)return"";const{state:t}=ot,{from:n,to:o,empty:r}=t.selection;if(!r)return t.doc.textBetween(n,o," ");const i=t.schema.marks.link;if(i){const o=e(t.doc.resolve(n),i);if(o)return t.doc.textBetween(o.from,o.to," ")}return""},getCharacterCount:()=>{var t,n,e,o;return{count:null!==(o=null!==(e=null===(n=null===(t=null==ot?void 0:ot.storage.characterCount)||void 0===t?void 0:t.characters)||void 0===n?void 0:n.call(t))&&void 0!==e?e:null==ot?void 0:ot.getText().length)&&void 0!==o?o:0,limit:null!=E?E:null}},getSectionContent:t=>ot?v(ot,t):{html:"",text:"",isEmpty:!0,characterCount:0},setSectionContent:(t,n)=>{const e=m(n);rt((n=>p(n,t,e)))},focusSection:t=>{rt((n=>{if("body"===t){let t=n.state.doc.content.size-1;return n.state.doc.descendants(((e,o)=>("sectionDivider"===e.type.name&&t===n.state.doc.content.size-1&&(t=o-1),t===n.state.doc.content.size-1))),t<1&&(t=1),void n.chain().focus().setTextSelection(t).run()}let e=-1;n.state.doc.descendants(((n,o)=>{if(-1!==e)return!1;"sectionDivider"===n.type.name&&n.attrs.sectionId===t&&(e=o+n.nodeSize+1)})),-1!==e&&n.chain().focus().setTextSelection(e).run()}))},clearSection:t=>{rt((n=>p(n,t,"<p></p>")))},getBodyContent:()=>ot?f(ot):{html:"",text:"",isEmpty:!0,characterCount:0},setBodyContent:t=>{const n=m(t);rt((t=>p(t,"body",n)))},setBodyAndSections:(t,n)=>{const e=u(m(t),n.map((t=>({id:t.id,content:m(t.content)}))));rt((t=>t.commands.setContent(e,{emitUpdate:!0})))},appendBodyContent:t=>{const n=m(t);rt((t=>{const e=C(t,"body");t.commands.insertContentAt(e-1,n)}))},insertAtSectionStart:(t,n)=>{const e=m(n);rt((n=>{const o=S(n,t);-1!==o&&n.commands.insertContentAt(o,e)}))},insertAtSectionEnd:(t,n)=>{const e=m(n);rt((n=>{const o=C(n,t);n.commands.insertContentAt(o,e)}))},getActiveFormats:()=>ot?h(ot):d,actions:{toggleBold:()=>null==ot?void 0:ot.chain().focus().toggleBold().run(),toggleItalic:()=>null==ot?void 0:ot.chain().focus().toggleItalic().run(),toggleUnderline:()=>null==ot?void 0:ot.chain().focus().toggleUnderline().run(),toggleStrike:()=>null==ot?void 0:ot.chain().focus().toggleStrike().run(),toggleBulletList:()=>null==ot?void 0:ot.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>null==ot?void 0:ot.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>null==ot?void 0:ot.chain().focus().toggleBlockquote().run(),toggleCodeBlock:()=>null==ot?void 0:ot.chain().focus().toggleCodeBlock().run(),setTextAlign:t=>null==ot?void 0:ot.chain().focus().setTextAlign(t).run(),setFontFamily:t=>null==ot?void 0:ot.chain().focus().setFontFamily(t).run(),setFontSize:t=>null==ot?void 0:ot.chain().focus().setFontSize(t).run(),setColor:t=>null==ot?void 0:ot.chain().focus().setColor(t).run(),setHighlight:t=>null==ot?void 0:ot.chain().focus().toggleHighlight({color:t}).run(),unsetColor:()=>null==ot?void 0:ot.chain().focus().unsetColor().run(),unsetHighlight:()=>null==ot?void 0:ot.chain().focus().unsetHighlight().run(),setLink:(t,n)=>{ot&&(void 0!==n?ot.chain().focus().extendMarkRange("link").command((e=>{let{tr:o,state:r}=e;const{from:i,to:s}=o.selection,l=r.schema.marks.link;return!!l&&(o.replaceWith(i,s,r.schema.text(n,[l.create({href:t})])),!0)})).run():ot.chain().focus().extendMarkRange("link").setLink({href:t}).run())},updateLink:t=>null==ot?void 0:ot.chain().focus().extendMarkRange("link").setLink({href:t}).run(),removeLink:()=>null==ot?void 0:ot.chain().focus().extendMarkRange("link").unsetLink().run(),insertEmoji:t=>null==ot?void 0:ot.chain().focus().insertContent(t).run(),insertVariable:t=>null==ot?void 0:ot.chain().focus().insertContent(`{{${t}}}`).run(),insertHtml:t=>null==ot?void 0:ot.commands.insertContent(t),undo:()=>null==ot?void 0:ot.chain().focus().undo().run(),redo:()=>null==ot?void 0:ot.chain().focus().redo().run(),canUndo:()=>{var t;return null!==(t=null==ot?void 0:ot.can().undo())&&void 0!==t&&t},canRedo:()=>{var t;return null!==(t=null==ot?void 0:ot.can().redo())&&void 0!==t&&t},toggleSuperscript:()=>null==ot?void 0:ot.chain().focus().toggleSuperscript().run(),toggleSubscript:()=>null==ot?void 0:ot.chain().focus().toggleSubscript().run(),insertImage:t=>null==ot?void 0:ot.chain().focus().setImage({src:t}).run()}})),[ot]),ot?t(a,Object.assign({minHeight:$,maxHeight:q,style:J,className:V},{children:[n(r,{editor:ot}),n(y,{editor:ot,renderLinkTooltip:null==H?void 0:H.renderTooltip})]})):null}));B.displayName="BikEditor";export{B as BikEditor};
1
+ import{jsxs as t,jsx as n}from"react/jsx-runtime";import{getMarkRange as e}from"../node_modules/@tiptap/core/dist/index.js";import{useEditor as o,EditorContent as r}from"@tiptap/react";import{forwardRef as i,useRef as s,useEffect as l,useImperativeHandle as c}from"react";import{BikEditorShell as a}from"./BikEditor.styles.js";import{DEFAULT_FORMAT_STATE as u}from"./BikEditor.types.js";import{buildSectionedContent as d,normalizeHtml as m,extractContent as g,extractActiveFormats as h,extractSectionContent as v,extractBodyContent as f,setSectionContentInEditor as p,findSectionEndPos as C,findSectionStartPos as S}from"./BikEditor.utils.js";import{buildExtensions as k}from"./extensions/buildExtensions.js";import{LinkBubbleMenu as y}from"./floating/LinkBubbleMenu.js";function x(t){return Object.entries(t).map((t=>{let[n,e]=t;return`${n.replace(/([A-Z])/g,(t=>`-${t.toLowerCase()}`))}:${e}`})).join(";")}const B=i(((i,B)=>{var b;const{initialContent:A,sections:j,features:I,disabled:L,maxCharacters:E,shortcuts:O,sendShortcut:T,mentions:w,slashCommands:F,link:H,onPaste:M,onReady:z,onChange:R,onSend:D,onFocus:N,onBlur:U,onSelectionChange:P,minHeight:$,maxHeight:q,style:J,className:V,editorClassName:W,editorStyle:Z}=i,_=(null==j?void 0:j.length)?d(m(null!=A?A:""),j.map((t=>Object.assign(Object.assign({},t),{content:m(t.content)})))):m(null!=A?A:""),G=s([]),K=s(!1),Q=s(z);Q.current=z;const X=s(R);X.current=R;const Y=s(P);Y.current=P;const tt=s(N);tt.current=N;const nt=s(U);nt.current=U;const et=s(D);et.current=D;const ot=o({extensions:k({features:I,placeholder:i.placeholder,maxCharacters:E,hasSections:(null!==(b=null==j?void 0:j.length)&&void 0!==b?b:0)>0,mentions:{agents:null==w?void 0:w.agents,teams:null==w?void 0:w.teams},slashCommands:null==F?void 0:F.items,onPaste:M,onSend:D?t=>{var n;return null===(n=et.current)||void 0===n?void 0:n.call(et,t)}:void 0,sendShortcut:T,shortcuts:O,onMentionSelected:null==w?void 0:w.onSelect,onSlashCommandSelected:null==F?void 0:F.onSelect,renderMentionItem:null==w?void 0:w.renderItem,renderMentionDropdown:null==w?void 0:w.renderDropdown,renderSlashCommandItem:null==F?void 0:F.renderItem,renderSlashCommandDropdown:null==F?void 0:F.renderDropdown}),content:_,editable:!L,immediatelyRender:!1,editorProps:{attributes:Object.assign(Object.assign({},W?{class:W}:{}),Z?{style:x(Z)}:{})},onUpdate:t=>{let{editor:n}=t;var e;null===(e=X.current)||void 0===e||e.call(X,g(n))},onTransaction:t=>{let{editor:n}=t;var e;null===(e=Y.current)||void 0===e||e.call(Y,h(n))},onFocus:()=>{var t;return null===(t=tt.current)||void 0===t?void 0:t.call(tt)},onBlur:()=>{var t;return null===(t=nt.current)||void 0===t?void 0:t.call(nt)}});function rt(t){ot?t(ot):G.current.push(t)}return l((()=>{var t;if(ot){if(G.current.length>0){G.current.splice(0).forEach((t=>t(ot)))}K.current||(K.current=!0,null===(t=Q.current)||void 0===t||t.call(Q))}}),[ot]),c(B,(()=>({focus:t=>rt((n=>n.commands.focus(t))),blur:()=>rt((t=>t.commands.blur())),clearContent:()=>rt((t=>t.commands.clearContent(!0))),setContent:t=>{const n=m(t);rt((t=>t.commands.setContent(n,{emitUpdate:!0})))},insertContent:t=>{const n=m(t);rt((t=>t.commands.insertContent(n)))},insertAtStart:t=>{const n=m(t);rt((t=>t.commands.insertContentAt(1,n)))},insertBlock:t=>{const n=m(t);rt((t=>t.commands.insertContentAt(t.state.doc.content.size,n)))},appendInline:t=>{const n=m(t);rt((t=>t.commands.insertContentAt(t.state.doc.content.size-1,n)))},insertAtEnd(t){this.insertBlock(t)},appendContent(t){this.appendInline(t)},getContent:()=>ot?g(ot):{html:"",text:"",isEmpty:!0,characterCount:0},getJSON:()=>{var t;return null!==(t=null==ot?void 0:ot.getJSON())&&void 0!==t?t:null},getMentions:()=>{const t=new Set,n=new Set;return ot?(ot.state.doc.descendants((e=>{"mentionAgent"===e.type.name&&null!=e.attrs.id?t.add(String(e.attrs.id)):"mentionTeam"===e.type.name&&null!=e.attrs.id&&n.add(String(e.attrs.id))})),{agentIds:Array.from(t),teamIds:Array.from(n)}):{agentIds:[],teamIds:[]}},getCursorPosition:()=>{if(!ot)return{from:0,to:0};const{from:t,to:n}=ot.state.selection;return{from:t,to:n}},insertAtPosition:(t,n)=>{const e=m(n);rt((n=>n.commands.insertContentAt(t,e)))},getSelectedText:()=>{if(!ot)return"";const{state:t}=ot,{from:n,to:o,empty:r}=t.selection;if(!r)return t.doc.textBetween(n,o," ");const i=t.schema.marks.link;if(i){const o=e(t.doc.resolve(n),i);if(o)return t.doc.textBetween(o.from,o.to," ")}return""},getCharacterCount:()=>{var t,n,e,o;return{count:null!==(o=null!==(e=null===(n=null===(t=null==ot?void 0:ot.storage.characterCount)||void 0===t?void 0:t.characters)||void 0===n?void 0:n.call(t))&&void 0!==e?e:null==ot?void 0:ot.getText().length)&&void 0!==o?o:0,limit:null!=E?E:null}},getSectionContent:t=>ot?v(ot,t):{html:"",text:"",isEmpty:!0,characterCount:0},setSectionContent:(t,n)=>{const e=m(n);rt((n=>p(n,t,e)))},focusSection:t=>{rt((n=>{if("body"===t){let t=n.state.doc.content.size-1;return n.state.doc.descendants(((e,o)=>("sectionDivider"===e.type.name&&t===n.state.doc.content.size-1&&(t=o-1),t===n.state.doc.content.size-1))),t<1&&(t=1),void n.chain().focus().setTextSelection(t).run()}let e=-1;n.state.doc.descendants(((n,o)=>{if(-1!==e)return!1;"sectionDivider"===n.type.name&&n.attrs.sectionId===t&&(e=o+n.nodeSize+1)})),-1!==e&&n.chain().focus().setTextSelection(e).run()}))},clearSection:t=>{rt((n=>p(n,t,"<p></p>")))},getBodyContent:()=>ot?f(ot):{html:"",text:"",isEmpty:!0,characterCount:0},setBodyContent:t=>{const n=m(t);rt((t=>p(t,"body",n)))},setBodyAndSections:(t,n)=>{const e=d(m(t),n.map((t=>({id:t.id,content:m(t.content)}))));rt((t=>t.commands.setContent(e,{emitUpdate:!0})))},appendBodyContent:t=>{const n=m(t);rt((t=>{const e=C(t,"body");t.commands.insertContentAt(e-1,n)}))},insertAtSectionStart:(t,n)=>{const e=m(n);rt((n=>{const o=S(n,t);-1!==o&&n.commands.insertContentAt(o,e)}))},insertAtSectionEnd:(t,n)=>{const e=m(n);rt((n=>{const o=C(n,t);n.commands.insertContentAt(o,e)}))},getActiveFormats:()=>ot?h(ot):u,actions:{toggleBold:()=>null==ot?void 0:ot.chain().focus().toggleBold().run(),toggleItalic:()=>null==ot?void 0:ot.chain().focus().toggleItalic().run(),toggleUnderline:()=>null==ot?void 0:ot.chain().focus().toggleUnderline().run(),toggleStrike:()=>null==ot?void 0:ot.chain().focus().toggleStrike().run(),toggleBulletList:()=>null==ot?void 0:ot.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>null==ot?void 0:ot.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>null==ot?void 0:ot.chain().focus().toggleBlockquote().run(),toggleCodeBlock:()=>null==ot?void 0:ot.chain().focus().toggleCodeBlock().run(),setTextAlign:t=>null==ot?void 0:ot.chain().focus().setTextAlign(t).run(),setFontFamily:t=>null==ot?void 0:ot.chain().focus().setFontFamily(t).run(),setFontSize:t=>null==ot?void 0:ot.chain().focus().setFontSize(t).run(),setColor:t=>null==ot?void 0:ot.chain().focus().setColor(t).run(),setHighlight:t=>null==ot?void 0:ot.chain().focus().toggleHighlight({color:t}).run(),unsetColor:()=>null==ot?void 0:ot.chain().focus().unsetColor().run(),unsetHighlight:()=>null==ot?void 0:ot.chain().focus().unsetHighlight().run(),setLink:(t,n)=>{ot&&(void 0!==n?ot.chain().focus().extendMarkRange("link").command((e=>{let{tr:o,state:r}=e;const{from:i,to:s}=o.selection,l=r.schema.marks.link;if(!l)return!1;const c=r.schema.text(n,[l.create({href:t})]),a=r.schema.text(" ");return o.replaceWith(i,s,[c,a]),!0})).run():ot.chain().focus().extendMarkRange("link").setLink({href:t}).insertContent(" ").run())},updateLink:t=>null==ot?void 0:ot.chain().focus().extendMarkRange("link").setLink({href:t}).run(),removeLink:()=>null==ot?void 0:ot.chain().focus().extendMarkRange("link").unsetLink().run(),insertEmoji:t=>null==ot?void 0:ot.chain().focus().insertContent(t).run(),insertVariable:t=>null==ot?void 0:ot.chain().focus().insertContent(`{{${t}}}`).run(),insertHtml:t=>null==ot?void 0:ot.commands.insertContent(t),undo:()=>null==ot?void 0:ot.chain().focus().undo().run(),redo:()=>null==ot?void 0:ot.chain().focus().redo().run(),canUndo:()=>{var t;return null!==(t=null==ot?void 0:ot.can().undo())&&void 0!==t&&t},canRedo:()=>{var t;return null!==(t=null==ot?void 0:ot.can().redo())&&void 0!==t&&t},toggleSuperscript:()=>null==ot?void 0:ot.chain().focus().toggleSuperscript().run(),toggleSubscript:()=>null==ot?void 0:ot.chain().focus().toggleSubscript().run(),insertImage:t=>null==ot?void 0:ot.chain().focus().setImage({src:t}).run()}})),[ot]),ot?t(a,Object.assign({minHeight:$,maxHeight:q,style:J,className:V},{children:[n(r,{editor:ot}),n(y,{editor:ot,renderLinkTooltip:null==H?void 0:H.renderTooltip})]})):null}));B.displayName="BikEditor";export{B as BikEditor};
2
2
  //# sourceMappingURL=BikEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BikEditor.js","sources":["../../../src/editor/BikEditor.tsx"],"sourcesContent":["'use client';\n\n/**\n * IMPLEMENTATION LAYER — TipTap-specific.\n * If the underlying editor is swapped, this file changes; BikEditor.types.ts and\n * src/editor/index.ts (the consumer contract) do NOT change.\n */\nimport { Editor, getMarkRange } from '@tiptap/core';\nimport { EditorContent, useEditor } from '@tiptap/react';\nimport React, {\n\tforwardRef,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n} from 'react';\nimport { BikEditorShell } from './BikEditor.styles';\nimport {\n\tBikEditorProps,\n\tBikEditorRef,\n\tDEFAULT_FORMAT_STATE,\n} from './BikEditor.types';\nimport {\n\tbuildSectionedContent,\n\textractActiveFormats,\n\textractBodyContent,\n\textractContent,\n\textractSectionContent,\n\tfindSectionEndPos,\n\tfindSectionStartPos,\n\tnormalizeHtml,\n\tsetSectionContentInEditor,\n} from './BikEditor.utils';\nimport { buildExtensions } from './extensions/buildExtensions';\nimport { LinkBubbleMenu } from './floating/LinkBubbleMenu';\n\n/** Convert React.CSSProperties to an inline CSS string for editorProps.attributes. */\nfunction cssToString(style: React.CSSProperties): string {\n\treturn Object.entries(style)\n\t\t.map(\n\t\t\t([k, v]) => `${k.replace(/([A-Z])/g, (c) => `-${c.toLowerCase()}`)}:${v}`,\n\t\t)\n\t\t.join(';');\n}\n\nconst BikEditorInner = (\n\tprops: BikEditorProps,\n\tref: React.Ref<BikEditorRef>,\n) => {\n\tconst {\n\t\tinitialContent,\n\t\tsections,\n\t\tfeatures,\n\t\tdisabled,\n\t\tmaxCharacters,\n\t\tshortcuts,\n\t\tsendShortcut,\n\t\tmentions,\n\t\tslashCommands,\n\t\tlink,\n\t\tonPaste,\n\t\tonReady,\n\t\tonChange,\n\t\tonSend,\n\t\tonFocus,\n\t\tonBlur,\n\t\tonSelectionChange,\n\t\tminHeight,\n\t\tmaxHeight,\n\t\tstyle,\n\t\tclassName,\n\t\teditorClassName,\n\t\teditorStyle,\n\t} = props;\n\n\tconst initialEditorContent = sections?.length\n\t\t? buildSectionedContent(\n\t\t\t\tnormalizeHtml(initialContent ?? ''),\n\t\t\t\tsections.map((s) => ({ ...s, content: normalizeHtml(s.content) })),\n\t\t )\n\t\t: normalizeHtml(initialContent ?? '');\n\n\t// ── Command queue ─────────────────────────────────────────────────────────\n\t// TipTap's useEditor initializes asynchronously; the editor instance is null\n\t// until the first commit. Any imperative method called before the editor is\n\t// ready is enqueued here and flushed automatically once it becomes non-null.\n\t// Consumers never need setTimeout or readiness guards.\n\tconst pendingQueue = useRef<Array<(e: Editor) => void>>([]);\n\tconst hasCalledOnReady = useRef(false);\n\t// Keep stable refs to all callbacks so useEditor receives the same function\n\t// identity on every render — prevents TipTap from re-registering event\n\t// handlers every time the parent re-renders with new inline function props.\n\tconst onReadyRef = useRef(onReady);\n\tonReadyRef.current = onReady;\n\tconst onChangeRef = useRef(onChange);\n\tonChangeRef.current = onChange;\n\tconst onSelectionChangeRef = useRef(onSelectionChange);\n\tonSelectionChangeRef.current = onSelectionChange;\n\tconst onFocusRef = useRef(onFocus);\n\tonFocusRef.current = onFocus;\n\tconst onBlurRef = useRef(onBlur);\n\tonBlurRef.current = onBlur;\n\tconst onSendRef = useRef(onSend);\n\tonSendRef.current = onSend;\n\n\tconst editor = useEditor({\n\t\textensions: buildExtensions({\n\t\t\tfeatures,\n\t\t\tplaceholder: props.placeholder,\n\t\t\tmaxCharacters,\n\t\t\thasSections: (sections?.length ?? 0) > 0,\n\t\t\tmentions: {\n\t\t\t\tagents: mentions?.agents,\n\t\t\t\tteams: mentions?.teams,\n\t\t\t},\n\t\t\tslashCommands: slashCommands?.items,\n\t\t\tonPaste,\n\t\t\tonSend: onSend ? (snapshot) => onSendRef.current?.(snapshot) : undefined,\n\t\t\tsendShortcut,\n\t\t\tshortcuts,\n\t\t\tonMentionSelected: mentions?.onSelect,\n\t\t\tonSlashCommandSelected: slashCommands?.onSelect,\n\t\t\trenderMentionItem: mentions?.renderItem,\n\t\t\trenderMentionDropdown: mentions?.renderDropdown,\n\t\t\trenderSlashCommandItem: slashCommands?.renderItem,\n\t\t\trenderSlashCommandDropdown: slashCommands?.renderDropdown,\n\t\t}),\n\t\tcontent: initialEditorContent,\n\t\teditable: !disabled,\n\t\timmediatelyRender: false, // SSR-safe — NEVER remove this\n\t\teditorProps: {\n\t\t\tattributes: {\n\t\t\t\t...(editorClassName ? { class: editorClassName } : {}),\n\t\t\t\t...(editorStyle ? { style: cssToString(editorStyle) } : {}),\n\t\t\t},\n\t\t},\n\t\tonUpdate: ({ editor: e }) => {\n\t\t\tonChangeRef.current?.(extractContent(e));\n\t\t},\n\t\tonTransaction: ({ editor: e }) => {\n\t\t\tonSelectionChangeRef.current?.(extractActiveFormats(e));\n\t\t},\n\t\tonFocus: () => onFocusRef.current?.(),\n\t\tonBlur: () => onBlurRef.current?.(),\n\t});\n\n\t// ── enqueue ───────────────────────────────────────────────────────────────\n\t// Run immediately if the editor is ready; otherwise defer to the queue.\n\t// Closures passed to enqueue MUST capture all parameters explicitly —\n\t// they must NOT close over `editor` (which would be null at enqueue time).\n\tfunction enqueue(op: (e: Editor) => void): void {\n\t\tif (editor) {\n\t\t\top(editor);\n\t\t} else {\n\t\t\tpendingQueue.current.push(op);\n\t\t}\n\t}\n\n\t// Flush the pending queue and fire onReady when editor transitions null → ready.\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\t\tif (pendingQueue.current.length > 0) {\n\t\t\tconst queue = pendingQueue.current.splice(0);\n\t\t\tqueue.forEach((op) => op(editor));\n\t\t}\n\t\tif (!hasCalledOnReady.current) {\n\t\t\thasCalledOnReady.current = true;\n\t\t\tonReadyRef.current?.();\n\t\t}\n\t}, [editor]);\n\n\tuseImperativeHandle(\n\t\tref,\n\t\t() => ({\n\t\t\t// ── Focus ────────────────────────────────────────────────────────\n\t\t\tfocus: (position) => enqueue((e) => e.commands.focus(position)),\n\t\t\tblur: () => enqueue((e) => e.commands.blur()),\n\n\t\t\t// ── Content ──────────────────────────────────────────────────────\n\t\t\tclearContent: () => enqueue((e) => e.commands.clearContent(true)),\n\t\t\tsetContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.setContent(normalised, { emitUpdate: true }));\n\t\t\t},\n\t\t\tinsertContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContent(normalised));\n\t\t\t},\n\t\t\tinsertAtStart: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(1, normalised));\n\t\t\t},\n\t\t\tinsertBlock: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\tappendInline: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// doc.content.size is after the last </p> (block boundary).\n\t\t\t\t// Subtract 1 to land inside the last paragraph so text appends\n\t\t\t\t// inline rather than being wrapped in a new paragraph each call.\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size - 1, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\t// Backwards-compatible aliases\n\t\t\tinsertAtEnd(html) {\n\t\t\t\tthis.insertBlock(html);\n\t\t\t},\n\t\t\tappendContent(html) {\n\t\t\t\tthis.appendInline(html);\n\t\t\t},\n\t\t\tgetContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tgetJSON: () => editor?.getJSON() ?? null,\n\t\t\tgetMentions: () => {\n\t\t\t\tconst agentIds = new Set<string>();\n\t\t\t\tconst teamIds = new Set<string>();\n\t\t\t\tif (!editor) return { agentIds: [], teamIds: [] };\n\t\t\t\teditor.state.doc.descendants((node) => {\n\t\t\t\t\tif (node.type.name === 'mentionAgent' && node.attrs['id'] != null) {\n\t\t\t\t\t\tagentIds.add(String(node.attrs['id']));\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tnode.type.name === 'mentionTeam' &&\n\t\t\t\t\t\tnode.attrs['id'] != null\n\t\t\t\t\t) {\n\t\t\t\t\t\tteamIds.add(String(node.attrs['id']));\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn { agentIds: Array.from(agentIds), teamIds: Array.from(teamIds) };\n\t\t\t},\n\n\t\t\t// ── Selection ────────────────────────────────────────────────────\n\t\t\tgetCursorPosition: () => {\n\t\t\t\tif (!editor) return { from: 0, to: 0 };\n\t\t\t\tconst { from, to } = editor.state.selection;\n\t\t\t\treturn { from, to };\n\t\t\t},\n\t\t\tinsertAtPosition: (pos, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(pos, normalised));\n\t\t\t},\n\t\t\tgetSelectedText: () => {\n\t\t\t\tif (!editor) return '';\n\t\t\t\tconst { state } = editor;\n\t\t\t\tconst { from, to, empty } = state.selection;\n\t\t\t\tif (!empty) {\n\t\t\t\t\treturn state.doc.textBetween(from, to, ' ');\n\t\t\t\t}\n\t\t\t\t// When the cursor is inside a link with nothing selected, return the\n\t\t\t\t// full link text — useful for pre-filling a link modal's text field.\n\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\tif (linkMarkType) {\n\t\t\t\t\tconst range = getMarkRange(state.doc.resolve(from), linkMarkType);\n\t\t\t\t\tif (range) {\n\t\t\t\t\t\treturn state.doc.textBetween(range.from, range.to, ' ');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn '';\n\t\t\t},\n\n\t\t\t// ── Character count ───────────────────────────────────────────────\n\t\t\tgetCharacterCount: () => ({\n\t\t\t\tcount:\n\t\t\t\t\teditor?.storage.characterCount?.characters?.() ??\n\t\t\t\t\teditor?.getText().length ??\n\t\t\t\t\t0,\n\t\t\t\tlimit: maxCharacters ?? null,\n\t\t\t}),\n\n\t\t\t// ── Sections ─────────────────────────────────────────────────────\n\t\t\tgetSectionContent: (sectionId) =>\n\t\t\t\teditor\n\t\t\t\t\t? extractSectionContent(editor, sectionId)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\n\t\t\tsetSectionContent: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, normalised));\n\t\t\t},\n\n\t\t\tfocusSection: (sectionId) => {\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tif (sectionId === 'body') {\n\t\t\t\t\t\tlet endOfBody = e.state.doc.content.size - 1;\n\t\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\t\tendOfBody === e.state.doc.content.size - 1\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tendOfBody = pos - 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn endOfBody === e.state.doc.content.size - 1;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (endOfBody < 1) endOfBody = 1;\n\t\t\t\t\t\te.chain().focus().setTextSelection(endOfBody).run();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet targetPos = -1;\n\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\tif (targetPos !== -1) return false;\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// pos + nodeSize lands right after the divider;\n\t\t\t\t\t\t\t// +1 more puts us inside the first paragraph of that section.\n\t\t\t\t\t\t\ttargetPos = pos + node.nodeSize + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tif (targetPos !== -1) {\n\t\t\t\t\t\te.chain().focus().setTextSelection(targetPos).run();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\n\t\t\tclearSection: (sectionId) => {\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, '<p></p>'));\n\t\t\t},\n\n\t\t\t// ── Convenience body shorthands ───────────────────────────────────\n\t\t\tgetBodyContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractBodyContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tsetBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, 'body', normalised));\n\t\t\t},\n\t\t\tsetBodyAndSections: (body, sections) => {\n\t\t\t\tconst html = buildSectionedContent(\n\t\t\t\t\tnormalizeHtml(body),\n\t\t\t\t\tsections.map((s) => ({\n\t\t\t\t\t\tid: s.id,\n\t\t\t\t\t\tcontent: normalizeHtml(s.content),\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t\tenqueue((e) => e.commands.setContent(html, { emitUpdate: true }));\n\t\t\t},\n\t\t\tappendBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// findSectionEndPos returns the position of the first divider (or\n\t\t\t\t// doc.content.size), which is the block boundary after the last </p>.\n\t\t\t\t// Subtract 1 to stay inside the last paragraph so successive calls\n\t\t\t\t// append inline text rather than creating a new paragraph each time.\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst boundaryPos = findSectionEndPos(e, 'body');\n\t\t\t\t\te.commands.insertContentAt(boundaryPos - 1, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionStart: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionStartPos(e, sectionId);\n\t\t\t\t\tif (pos !== -1) e.commands.insertContentAt(pos, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionEnd: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionEndPos(e, sectionId);\n\t\t\t\t\te.commands.insertContentAt(pos, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\t// ── Formats & actions ─────────────────────────────────────────────\n\t\t\tgetActiveFormats: () =>\n\t\t\t\teditor ? extractActiveFormats(editor) : DEFAULT_FORMAT_STATE,\n\t\t\tactions: {\n\t\t\t\ttoggleBold: () => editor?.chain().focus().toggleBold().run(),\n\t\t\t\ttoggleItalic: () => editor?.chain().focus().toggleItalic().run(),\n\t\t\t\ttoggleUnderline: () => editor?.chain().focus().toggleUnderline().run(),\n\t\t\t\ttoggleStrike: () => editor?.chain().focus().toggleStrike().run(),\n\t\t\t\ttoggleBulletList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBulletList().run(),\n\t\t\t\ttoggleOrderedList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleOrderedList().run(),\n\t\t\t\ttoggleBlockquote: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBlockquote().run(),\n\t\t\t\ttoggleCodeBlock: () => editor?.chain().focus().toggleCodeBlock().run(),\n\t\t\t\tsetTextAlign: (align) =>\n\t\t\t\t\teditor?.chain().focus().setTextAlign(align).run(),\n\t\t\t\tsetFontFamily: (font) =>\n\t\t\t\t\teditor?.chain().focus().setFontFamily(font).run(),\n\t\t\t\tsetFontSize: (size) => editor?.chain().focus().setFontSize(size).run(),\n\t\t\t\tsetColor: (color) => editor?.chain().focus().setColor(color).run(),\n\t\t\t\tsetHighlight: (color) =>\n\t\t\t\t\teditor?.chain().focus().toggleHighlight({ color }).run(),\n\t\t\t\tunsetColor: () => editor?.chain().focus().unsetColor().run(),\n\t\t\t\tunsetHighlight: () => editor?.chain().focus().unsetHighlight().run(),\n\t\t\t\tsetLink: (href, text) => {\n\t\t\t\t\tif (!editor) return;\n\t\t\t\t\tif (text !== undefined) {\n\t\t\t\t\t\t// Replace both the display text and href in one transaction.\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.command(({ tr, state }) => {\n\t\t\t\t\t\t\t\tconst { from, to } = tr.selection;\n\t\t\t\t\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\t\t\t\t\tif (!linkMarkType) return false;\n\t\t\t\t\t\t\t\ttr.replaceWith(\n\t\t\t\t\t\t\t\t\tfrom,\n\t\t\t\t\t\t\t\t\tto,\n\t\t\t\t\t\t\t\t\tstate.schema.text(text, [linkMarkType.create({ href })]),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t} else {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tupdateLink: (href) =>\n\t\t\t\t\teditor\n\t\t\t\t\t\t?.chain()\n\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t.run(),\n\t\t\t\tremoveLink: () =>\n\t\t\t\t\teditor?.chain().focus().extendMarkRange('link').unsetLink().run(),\n\t\t\t\tinsertEmoji: (emoji) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(emoji).run(),\n\t\t\t\tinsertVariable: (variableName) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(`{{${variableName}}}`).run(),\n\t\t\t\tinsertHtml: (html) => editor?.commands.insertContent(html),\n\t\t\t\tundo: () => editor?.chain().focus().undo().run(),\n\t\t\t\tredo: () => editor?.chain().focus().redo().run(),\n\t\t\t\tcanUndo: () => editor?.can().undo() ?? false,\n\t\t\t\tcanRedo: () => editor?.can().redo() ?? false,\n\t\t\t\ttoggleSuperscript: () =>\n\t\t\t\t\teditor?.chain().focus().toggleSuperscript().run(),\n\t\t\t\ttoggleSubscript: () => editor?.chain().focus().toggleSubscript().run(),\n\t\t\t\tinsertImage: (src) => editor?.chain().focus().setImage({ src }).run(),\n\t\t\t},\n\t\t}),\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t[editor],\n\t);\n\n\tif (!editor) return null;\n\n\treturn (\n\t\t<BikEditorShell\n\t\t\tminHeight={minHeight}\n\t\t\tmaxHeight={maxHeight}\n\t\t\tstyle={style}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t<EditorContent editor={editor} />\n\t\t\t<LinkBubbleMenu editor={editor} renderLinkTooltip={link?.renderTooltip} />\n\t\t</BikEditorShell>\n\t);\n};\n\nexport const BikEditor = forwardRef<BikEditorRef, BikEditorProps>(\n\tBikEditorInner,\n);\nBikEditor.displayName = 'BikEditor';\n"],"names":["cssToString","style","Object","entries","map","_ref","k","v","replace","c","toLowerCase","join","BikEditor","forwardRef","BikEditorInner","props","ref","initialContent","sections","features","disabled","maxCharacters","shortcuts","sendShortcut","mentions","slashCommands","link","onPaste","onReady","onChange","onSend","onFocus","onBlur","onSelectionChange","minHeight","maxHeight","className","editorClassName","editorStyle","initialEditorContent","length","buildSectionedContent","normalizeHtml","s","assign","content","pendingQueue","useRef","hasCalledOnReady","onReadyRef","current","onChangeRef","onSelectionChangeRef","onFocusRef","onBlurRef","onSendRef","editor","useEditor","extensions","buildExtensions","placeholder","hasSections","_a","agents","teams","items","snapshot","call","undefined","onMentionSelected","onSelect","onSlashCommandSelected","renderMentionItem","renderItem","renderMentionDropdown","renderDropdown","renderSlashCommandItem","renderSlashCommandDropdown","editable","immediatelyRender","editorProps","attributes","class","onUpdate","_ref2","e","extractContent","onTransaction","_ref3","extractActiveFormats","enqueue","op","push","useEffect","splice","forEach","useImperativeHandle","focus","position","commands","blur","clearContent","setContent","html","normalised","emitUpdate","insertContent","insertAtStart","insertContentAt","insertBlock","state","doc","size","appendInline","insertAtEnd","this","appendContent","getContent","text","isEmpty","characterCount","getJSON","getMentions","agentIds","Set","teamIds","descendants","node","type","name","attrs","add","String","Array","from","getCursorPosition","to","selection","insertAtPosition","pos","getSelectedText","empty","textBetween","linkMarkType","schema","marks","range","getMarkRange","resolve","getCharacterCount","count","_d","_c","_b","storage","characters","getText","limit","getSectionContent","sectionId","extractSectionContent","setSectionContent","setSectionContentInEditor","focusSection","endOfBody","chain","setTextSelection","run","targetPos","nodeSize","clearSection","getBodyContent","extractBodyContent","setBodyContent","setBodyAndSections","body","id","appendBodyContent","boundaryPos","findSectionEndPos","insertAtSectionStart","findSectionStartPos","insertAtSectionEnd","getActiveFormats","DEFAULT_FORMAT_STATE","actions","toggleBold","toggleItalic","toggleUnderline","toggleStrike","toggleBulletList","toggleOrderedList","toggleBlockquote","toggleCodeBlock","setTextAlign","align","setFontFamily","font","setFontSize","setColor","color","setHighlight","toggleHighlight","unsetColor","unsetHighlight","setLink","href","extendMarkRange","command","_ref4","tr","replaceWith","create","updateLink","removeLink","unsetLink","insertEmoji","emoji","insertVariable","variableName","insertHtml","undo","redo","canUndo","can","canRedo","toggleSuperscript","toggleSubscript","insertImage","src","setImage","_jsxs","BikEditorShell","children","_jsx","EditorContent","LinkBubbleMenu","renderLinkTooltip","renderTooltip","displayName"],"mappings":"mwBAoCA,SAASA,EAAYC,GACpB,OAAOC,OAAOC,QAAQF,GACpBG,KACAC,IAAA,IAAEC,EAAGC,GAAEF,EAAA,MAAK,GAAGC,EAAEE,QAAQ,YAAaC,OAAUA,EAAEC,qBAAoBH,GAAG,IAEzEI,KAAK,IACR,CAEA,MAoaaC,EAAYC,GApaFC,CACtBC,EACAC,WAEA,MAAMC,eACLA,EAAcC,SACdA,EAAQC,SACRA,EAAQC,SACRA,EAAQC,cACRA,EAAaC,UACbA,EAASC,aACTA,EAAYC,SACZA,EAAQC,cACRA,EAAaC,KACbA,EAAIC,QACJA,EAAOC,QACPA,EAAOC,SACPA,EAAQC,OACRA,EAAMC,QACNA,EAAOC,OACPA,EAAMC,kBACNA,EAAiBC,UACjBA,EAASC,UACTA,EAASlC,MACTA,EAAKmC,UACLA,EAASC,gBACTA,EAAeC,YACfA,GACGvB,EAEEwB,GAAuBrB,aAAQ,EAARA,EAAUsB,QACpCC,EACAC,EAAczB,QAAAA,EAAkB,IAChCC,EAASd,KAAKuC,GAAYzC,OAAA0C,OAAA1C,OAAA0C,OAAA,CAAA,EAAAD,IAAGE,QAASH,EAAcC,EAAEE,cAEtDH,EAAczB,QAAAA,EAAkB,IAO7B6B,EAAeC,EAAmC,IAClDC,EAAmBD,GAAO,GAI1BE,EAAaF,EAAOnB,GAC1BqB,EAAWC,QAAUtB,EACrB,MAAMuB,EAAcJ,EAAOlB,GAC3BsB,EAAYD,QAAUrB,EACtB,MAAMuB,EAAuBL,EAAOd,GACpCmB,EAAqBF,QAAUjB,EAC/B,MAAMoB,GAAaN,EAAOhB,GAC1BsB,GAAWH,QAAUnB,EACrB,MAAMuB,GAAYP,EAAOf,GACzBsB,GAAUJ,QAAUlB,EACpB,MAAM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cAAU,IAAAhK,GAAAA,CAAK,EAC5CoK,kBAAmBA,IAClB1K,cAAM,EAANA,GAAQ6G,QAAQpE,QAAQiI,oBAAoB3D,MAC7C4D,gBAAiBA,IAAM3K,cAAM,EAANA,GAAQ6G,QAAQpE,QAAQkI,kBAAkB5D,MACjE6D,YAAcC,GAAQ7K,cAAA,EAAAA,GAAQ6G,QAAQpE,QAAQqI,SAAS,CAAED,QAAO9D,UAIlE,CAAC/G,KAGGA,GAGJ+K,EAACC,EAActO,OAAA0C,OAAA,CACdV,UAAWA,EACXC,UAAWA,EACXlC,MAAOA,EACPmC,UAAWA,GAEX,CAAAqM,SAAA,CAAAC,EAACC,EAAa,CAACnL,OAAQA,KACvBkL,EAACE,EAAe,CAAApL,OAAQA,GAAQqL,kBAAmBnN,aAAA,EAAAA,EAAMoN,oBAVvC,IAWF,IAOnBlO,EAAUmO,YAAc"}
1
+ {"version":3,"file":"BikEditor.js","sources":["../../../src/editor/BikEditor.tsx"],"sourcesContent":["'use client';\n\n/**\n * IMPLEMENTATION LAYER — TipTap-specific.\n * If the underlying editor is swapped, this file changes; BikEditor.types.ts and\n * src/editor/index.ts (the consumer contract) do NOT change.\n */\nimport { Editor, getMarkRange } from '@tiptap/core';\nimport { EditorContent, useEditor } from '@tiptap/react';\nimport React, {\n\tforwardRef,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n} from 'react';\nimport { BikEditorShell } from './BikEditor.styles';\nimport {\n\tBikEditorProps,\n\tBikEditorRef,\n\tDEFAULT_FORMAT_STATE,\n} from './BikEditor.types';\nimport {\n\tbuildSectionedContent,\n\textractActiveFormats,\n\textractBodyContent,\n\textractContent,\n\textractSectionContent,\n\tfindSectionEndPos,\n\tfindSectionStartPos,\n\tnormalizeHtml,\n\tsetSectionContentInEditor,\n} from './BikEditor.utils';\nimport { buildExtensions } from './extensions/buildExtensions';\nimport { LinkBubbleMenu } from './floating/LinkBubbleMenu';\n\n/** Convert React.CSSProperties to an inline CSS string for editorProps.attributes. */\nfunction cssToString(style: React.CSSProperties): string {\n\treturn Object.entries(style)\n\t\t.map(\n\t\t\t([k, v]) => `${k.replace(/([A-Z])/g, (c) => `-${c.toLowerCase()}`)}:${v}`,\n\t\t)\n\t\t.join(';');\n}\n\nconst BikEditorInner = (\n\tprops: BikEditorProps,\n\tref: React.Ref<BikEditorRef>,\n) => {\n\tconst {\n\t\tinitialContent,\n\t\tsections,\n\t\tfeatures,\n\t\tdisabled,\n\t\tmaxCharacters,\n\t\tshortcuts,\n\t\tsendShortcut,\n\t\tmentions,\n\t\tslashCommands,\n\t\tlink,\n\t\tonPaste,\n\t\tonReady,\n\t\tonChange,\n\t\tonSend,\n\t\tonFocus,\n\t\tonBlur,\n\t\tonSelectionChange,\n\t\tminHeight,\n\t\tmaxHeight,\n\t\tstyle,\n\t\tclassName,\n\t\teditorClassName,\n\t\teditorStyle,\n\t} = props;\n\n\tconst initialEditorContent = sections?.length\n\t\t? buildSectionedContent(\n\t\t\t\tnormalizeHtml(initialContent ?? ''),\n\t\t\t\tsections.map((s) => ({ ...s, content: normalizeHtml(s.content) })),\n\t\t )\n\t\t: normalizeHtml(initialContent ?? '');\n\n\t// ── Command queue ─────────────────────────────────────────────────────────\n\t// TipTap's useEditor initializes asynchronously; the editor instance is null\n\t// until the first commit. Any imperative method called before the editor is\n\t// ready is enqueued here and flushed automatically once it becomes non-null.\n\t// Consumers never need setTimeout or readiness guards.\n\tconst pendingQueue = useRef<Array<(e: Editor) => void>>([]);\n\tconst hasCalledOnReady = useRef(false);\n\t// Keep stable refs to all callbacks so useEditor receives the same function\n\t// identity on every render — prevents TipTap from re-registering event\n\t// handlers every time the parent re-renders with new inline function props.\n\tconst onReadyRef = useRef(onReady);\n\tonReadyRef.current = onReady;\n\tconst onChangeRef = useRef(onChange);\n\tonChangeRef.current = onChange;\n\tconst onSelectionChangeRef = useRef(onSelectionChange);\n\tonSelectionChangeRef.current = onSelectionChange;\n\tconst onFocusRef = useRef(onFocus);\n\tonFocusRef.current = onFocus;\n\tconst onBlurRef = useRef(onBlur);\n\tonBlurRef.current = onBlur;\n\tconst onSendRef = useRef(onSend);\n\tonSendRef.current = onSend;\n\n\tconst editor = useEditor({\n\t\textensions: buildExtensions({\n\t\t\tfeatures,\n\t\t\tplaceholder: props.placeholder,\n\t\t\tmaxCharacters,\n\t\t\thasSections: (sections?.length ?? 0) > 0,\n\t\t\tmentions: {\n\t\t\t\tagents: mentions?.agents,\n\t\t\t\tteams: mentions?.teams,\n\t\t\t},\n\t\t\tslashCommands: slashCommands?.items,\n\t\t\tonPaste,\n\t\t\tonSend: onSend ? (snapshot) => onSendRef.current?.(snapshot) : undefined,\n\t\t\tsendShortcut,\n\t\t\tshortcuts,\n\t\t\tonMentionSelected: mentions?.onSelect,\n\t\t\tonSlashCommandSelected: slashCommands?.onSelect,\n\t\t\trenderMentionItem: mentions?.renderItem,\n\t\t\trenderMentionDropdown: mentions?.renderDropdown,\n\t\t\trenderSlashCommandItem: slashCommands?.renderItem,\n\t\t\trenderSlashCommandDropdown: slashCommands?.renderDropdown,\n\t\t}),\n\t\tcontent: initialEditorContent,\n\t\teditable: !disabled,\n\t\timmediatelyRender: false, // SSR-safe — NEVER remove this\n\t\teditorProps: {\n\t\t\tattributes: {\n\t\t\t\t...(editorClassName ? { class: editorClassName } : {}),\n\t\t\t\t...(editorStyle ? { style: cssToString(editorStyle) } : {}),\n\t\t\t},\n\t\t},\n\t\tonUpdate: ({ editor: e }) => {\n\t\t\tonChangeRef.current?.(extractContent(e));\n\t\t},\n\t\tonTransaction: ({ editor: e }) => {\n\t\t\tonSelectionChangeRef.current?.(extractActiveFormats(e));\n\t\t},\n\t\tonFocus: () => onFocusRef.current?.(),\n\t\tonBlur: () => onBlurRef.current?.(),\n\t});\n\n\t// ── enqueue ───────────────────────────────────────────────────────────────\n\t// Run immediately if the editor is ready; otherwise defer to the queue.\n\t// Closures passed to enqueue MUST capture all parameters explicitly —\n\t// they must NOT close over `editor` (which would be null at enqueue time).\n\tfunction enqueue(op: (e: Editor) => void): void {\n\t\tif (editor) {\n\t\t\top(editor);\n\t\t} else {\n\t\t\tpendingQueue.current.push(op);\n\t\t}\n\t}\n\n\t// Flush the pending queue and fire onReady when editor transitions null → ready.\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\t\tif (pendingQueue.current.length > 0) {\n\t\t\tconst queue = pendingQueue.current.splice(0);\n\t\t\tqueue.forEach((op) => op(editor));\n\t\t}\n\t\tif (!hasCalledOnReady.current) {\n\t\t\thasCalledOnReady.current = true;\n\t\t\tonReadyRef.current?.();\n\t\t}\n\t}, [editor]);\n\n\tuseImperativeHandle(\n\t\tref,\n\t\t() => ({\n\t\t\t// ── Focus ────────────────────────────────────────────────────────\n\t\t\tfocus: (position) => enqueue((e) => e.commands.focus(position)),\n\t\t\tblur: () => enqueue((e) => e.commands.blur()),\n\n\t\t\t// ── Content ──────────────────────────────────────────────────────\n\t\t\tclearContent: () => enqueue((e) => e.commands.clearContent(true)),\n\t\t\tsetContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.setContent(normalised, { emitUpdate: true }));\n\t\t\t},\n\t\t\tinsertContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContent(normalised));\n\t\t\t},\n\t\t\tinsertAtStart: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(1, normalised));\n\t\t\t},\n\t\t\tinsertBlock: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\tappendInline: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// doc.content.size is after the last </p> (block boundary).\n\t\t\t\t// Subtract 1 to land inside the last paragraph so text appends\n\t\t\t\t// inline rather than being wrapped in a new paragraph each call.\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size - 1, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\t// Backwards-compatible aliases\n\t\t\tinsertAtEnd(html) {\n\t\t\t\tthis.insertBlock(html);\n\t\t\t},\n\t\t\tappendContent(html) {\n\t\t\t\tthis.appendInline(html);\n\t\t\t},\n\t\t\tgetContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tgetJSON: () => editor?.getJSON() ?? null,\n\t\t\tgetMentions: () => {\n\t\t\t\tconst agentIds = new Set<string>();\n\t\t\t\tconst teamIds = new Set<string>();\n\t\t\t\tif (!editor) return { agentIds: [], teamIds: [] };\n\t\t\t\teditor.state.doc.descendants((node) => {\n\t\t\t\t\tif (node.type.name === 'mentionAgent' && node.attrs['id'] != null) {\n\t\t\t\t\t\tagentIds.add(String(node.attrs['id']));\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tnode.type.name === 'mentionTeam' &&\n\t\t\t\t\t\tnode.attrs['id'] != null\n\t\t\t\t\t) {\n\t\t\t\t\t\tteamIds.add(String(node.attrs['id']));\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn { agentIds: Array.from(agentIds), teamIds: Array.from(teamIds) };\n\t\t\t},\n\n\t\t\t// ── Selection ────────────────────────────────────────────────────\n\t\t\tgetCursorPosition: () => {\n\t\t\t\tif (!editor) return { from: 0, to: 0 };\n\t\t\t\tconst { from, to } = editor.state.selection;\n\t\t\t\treturn { from, to };\n\t\t\t},\n\t\t\tinsertAtPosition: (pos, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(pos, normalised));\n\t\t\t},\n\t\t\tgetSelectedText: () => {\n\t\t\t\tif (!editor) return '';\n\t\t\t\tconst { state } = editor;\n\t\t\t\tconst { from, to, empty } = state.selection;\n\t\t\t\tif (!empty) {\n\t\t\t\t\treturn state.doc.textBetween(from, to, ' ');\n\t\t\t\t}\n\t\t\t\t// When the cursor is inside a link with nothing selected, return the\n\t\t\t\t// full link text — useful for pre-filling a link modal's text field.\n\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\tif (linkMarkType) {\n\t\t\t\t\tconst range = getMarkRange(state.doc.resolve(from), linkMarkType);\n\t\t\t\t\tif (range) {\n\t\t\t\t\t\treturn state.doc.textBetween(range.from, range.to, ' ');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn '';\n\t\t\t},\n\n\t\t\t// ── Character count ───────────────────────────────────────────────\n\t\t\tgetCharacterCount: () => ({\n\t\t\t\tcount:\n\t\t\t\t\teditor?.storage.characterCount?.characters?.() ??\n\t\t\t\t\teditor?.getText().length ??\n\t\t\t\t\t0,\n\t\t\t\tlimit: maxCharacters ?? null,\n\t\t\t}),\n\n\t\t\t// ── Sections ─────────────────────────────────────────────────────\n\t\t\tgetSectionContent: (sectionId) =>\n\t\t\t\teditor\n\t\t\t\t\t? extractSectionContent(editor, sectionId)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\n\t\t\tsetSectionContent: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, normalised));\n\t\t\t},\n\n\t\t\tfocusSection: (sectionId) => {\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tif (sectionId === 'body') {\n\t\t\t\t\t\tlet endOfBody = e.state.doc.content.size - 1;\n\t\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\t\tendOfBody === e.state.doc.content.size - 1\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tendOfBody = pos - 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn endOfBody === e.state.doc.content.size - 1;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (endOfBody < 1) endOfBody = 1;\n\t\t\t\t\t\te.chain().focus().setTextSelection(endOfBody).run();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet targetPos = -1;\n\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\tif (targetPos !== -1) return false;\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// pos + nodeSize lands right after the divider;\n\t\t\t\t\t\t\t// +1 more puts us inside the first paragraph of that section.\n\t\t\t\t\t\t\ttargetPos = pos + node.nodeSize + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tif (targetPos !== -1) {\n\t\t\t\t\t\te.chain().focus().setTextSelection(targetPos).run();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\n\t\t\tclearSection: (sectionId) => {\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, '<p></p>'));\n\t\t\t},\n\n\t\t\t// ── Convenience body shorthands ───────────────────────────────────\n\t\t\tgetBodyContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractBodyContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tsetBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, 'body', normalised));\n\t\t\t},\n\t\t\tsetBodyAndSections: (body, sections) => {\n\t\t\t\tconst html = buildSectionedContent(\n\t\t\t\t\tnormalizeHtml(body),\n\t\t\t\t\tsections.map((s) => ({\n\t\t\t\t\t\tid: s.id,\n\t\t\t\t\t\tcontent: normalizeHtml(s.content),\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t\tenqueue((e) => e.commands.setContent(html, { emitUpdate: true }));\n\t\t\t},\n\t\t\tappendBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// findSectionEndPos returns the position of the first divider (or\n\t\t\t\t// doc.content.size), which is the block boundary after the last </p>.\n\t\t\t\t// Subtract 1 to stay inside the last paragraph so successive calls\n\t\t\t\t// append inline text rather than creating a new paragraph each time.\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst boundaryPos = findSectionEndPos(e, 'body');\n\t\t\t\t\te.commands.insertContentAt(boundaryPos - 1, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionStart: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionStartPos(e, sectionId);\n\t\t\t\t\tif (pos !== -1) e.commands.insertContentAt(pos, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionEnd: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionEndPos(e, sectionId);\n\t\t\t\t\te.commands.insertContentAt(pos, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\t// ── Formats & actions ─────────────────────────────────────────────\n\t\t\tgetActiveFormats: () =>\n\t\t\t\teditor ? extractActiveFormats(editor) : DEFAULT_FORMAT_STATE,\n\t\t\tactions: {\n\t\t\t\ttoggleBold: () => editor?.chain().focus().toggleBold().run(),\n\t\t\t\ttoggleItalic: () => editor?.chain().focus().toggleItalic().run(),\n\t\t\t\ttoggleUnderline: () => editor?.chain().focus().toggleUnderline().run(),\n\t\t\t\ttoggleStrike: () => editor?.chain().focus().toggleStrike().run(),\n\t\t\t\ttoggleBulletList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBulletList().run(),\n\t\t\t\ttoggleOrderedList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleOrderedList().run(),\n\t\t\t\ttoggleBlockquote: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBlockquote().run(),\n\t\t\t\ttoggleCodeBlock: () => editor?.chain().focus().toggleCodeBlock().run(),\n\t\t\t\tsetTextAlign: (align) =>\n\t\t\t\t\teditor?.chain().focus().setTextAlign(align).run(),\n\t\t\t\tsetFontFamily: (font) =>\n\t\t\t\t\teditor?.chain().focus().setFontFamily(font).run(),\n\t\t\t\tsetFontSize: (size) => editor?.chain().focus().setFontSize(size).run(),\n\t\t\t\tsetColor: (color) => editor?.chain().focus().setColor(color).run(),\n\t\t\t\tsetHighlight: (color) =>\n\t\t\t\t\teditor?.chain().focus().toggleHighlight({ color }).run(),\n\t\t\t\tunsetColor: () => editor?.chain().focus().unsetColor().run(),\n\t\t\t\tunsetHighlight: () => editor?.chain().focus().unsetHighlight().run(),\n\t\t\t\tsetLink: (href, text) => {\n\t\t\t\t\tif (!editor) return;\n\t\t\t\t\tif (text !== undefined) {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.command(({ tr, state }) => {\n\t\t\t\t\t\t\t\tconst { from, to } = tr.selection;\n\t\t\t\t\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\t\t\t\t\tif (!linkMarkType) return false;\n\t\t\t\t\t\t\t\tconst linkNode = state.schema.text(text, [\n\t\t\t\t\t\t\t\t\tlinkMarkType.create({ href }),\n\t\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\t\tconst space = state.schema.text(' ');\n\t\t\t\t\t\t\t\ttr.replaceWith(from, to, [linkNode, space]);\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t} else {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t\t.insertContent(' ')\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tupdateLink: (href) =>\n\t\t\t\t\teditor\n\t\t\t\t\t\t?.chain()\n\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t.run(),\n\t\t\t\tremoveLink: () =>\n\t\t\t\t\teditor?.chain().focus().extendMarkRange('link').unsetLink().run(),\n\t\t\t\tinsertEmoji: (emoji) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(emoji).run(),\n\t\t\t\tinsertVariable: (variableName) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(`{{${variableName}}}`).run(),\n\t\t\t\tinsertHtml: (html) => editor?.commands.insertContent(html),\n\t\t\t\tundo: () => editor?.chain().focus().undo().run(),\n\t\t\t\tredo: () => editor?.chain().focus().redo().run(),\n\t\t\t\tcanUndo: () => editor?.can().undo() ?? false,\n\t\t\t\tcanRedo: () => editor?.can().redo() ?? false,\n\t\t\t\ttoggleSuperscript: () =>\n\t\t\t\t\teditor?.chain().focus().toggleSuperscript().run(),\n\t\t\t\ttoggleSubscript: () => editor?.chain().focus().toggleSubscript().run(),\n\t\t\t\tinsertImage: (src) => editor?.chain().focus().setImage({ src }).run(),\n\t\t\t},\n\t\t}),\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t[editor],\n\t);\n\n\tif (!editor) return null;\n\n\treturn (\n\t\t<BikEditorShell\n\t\t\tminHeight={minHeight}\n\t\t\tmaxHeight={maxHeight}\n\t\t\tstyle={style}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t<EditorContent editor={editor} />\n\t\t\t<LinkBubbleMenu editor={editor} renderLinkTooltip={link?.renderTooltip} />\n\t\t</BikEditorShell>\n\t);\n};\n\nexport const BikEditor = forwardRef<BikEditorRef, BikEditorProps>(\n\tBikEditorInner,\n);\nBikEditor.displayName = 'BikEditor';\n"],"names":["cssToString","style","Object","entries","map","_ref","k","v","replace","c","toLowerCase","join","BikEditor","forwardRef","BikEditorInner","props","ref","initialContent","sections","features","disabled","maxCharacters","shortcuts","sendShortcut","mentions","slashCommands","link","onPaste","onReady","onChange","onSend","onFocus","onBlur","onSelectionChange","minHeight","maxHeight","className","editorClassName","editorStyle","initialEditorContent","length","buildSectionedContent","normalizeHtml","s","assign","content","pendingQueue","useRef","hasCalledOnReady","onReadyRef","current","onChangeRef","onSelectionChangeRef","onFocusRef","onBlurRef","onSendRef","editor","useEditor","extensions","buildExtensions","placeholder","hasSections","_a","agents","teams","items","snapshot","call","undefined","onMentionSelected","onSelect","onSlashCommandSelected","renderMentionItem","renderItem","renderMentionDropdown","renderDropdown","renderSlashCommandItem","renderSlashCommandDropdown","editable","immediatelyRender","editorProps","attributes","class","onUpdate","_ref2","e","extractContent","onTransaction","_ref3","extractActiveFormats","enqueue","op","push","useEffect","splice","forEach","useImperativeHandle","focus","position","commands","blur","clearContent","setContent","html","normalised","emitUpdate","insertContent","insertAtStart","insertContentAt","insertBlock","state","doc","size","appendInline","insertAtEnd","this","appendContent","getContent","text","isEmpty","characterCount","getJSON","getMentions","agentIds","Set","teamIds","descendants","node","type","name","attrs","add","String","Array","from","getCursorPosition","to","selection","insertAtPosition","pos","getSelectedText","empty","textBetween","linkMarkType","schema","marks","range","getMarkRange","resolve","getCharacterCount","count","_d","_c","_b","storage","characters","getText","limit","getSectionContent","sectionId","extractSectionContent","setSectionContent","setSectionContentInEditor","focusSection","endOfBody","chain","setTextSelection","run","targetPos","nodeSize","clearSection","getBodyContent","extractBodyContent","setBodyContent","setBodyAndSections","body","id","appendBodyContent","boundaryPos","findSectionEndPos","insertAtSectionStart","findSectionStartPos","insertAtSectionEnd","getActiveFormats","DEFAULT_FORMAT_STATE","actions","toggleBold","toggleItalic","toggleUnderline","toggleStrike","toggleBulletList","toggleOrderedList","toggleBlockquote","toggleCodeBlock","setTextAlign","align","setFontFamily","font","setFontSize","setColor","color","setHighlight","toggleHighlight","unsetColor","unsetHighlight","setLink","href","extendMarkRange","command","_ref4","tr","linkNode","create","space","replaceWith","updateLink","removeLink","unsetLink","insertEmoji","emoji","insertVariable","variableName","insertHtml","undo","redo","canUndo","can","canRedo","toggleSuperscript","toggleSubscript","insertImage","src","setImage","_jsxs","BikEditorShell","children","_jsx","EditorContent","LinkBubbleMenu","renderLinkTooltip","renderTooltip","displayName"],"mappings":"mwBAoCA,SAASA,EAAYC,GACpB,OAAOC,OAAOC,QAAQF,GACpBG,KACAC,IAAA,IAAEC,EAAGC,GAAEF,EAAA,MAAK,GAAGC,EAAEE,QAAQ,YAAaC,OAAUA,EAAEC,qBAAoBH,GAAG,IAEzEI,KAAK,IACR,CAEA,MAoaaC,EAAYC,GApaFC,CACtBC,EACAC,WAEA,MAAMC,eACLA,EAAcC,SACdA,EAAQC,SACRA,EAAQC,SACRA,EAAQC,cACRA,EAAaC,UACbA,EAASC,aACTA,EAAYC,SACZA,EAAQC,cACRA,EAAaC,KACbA,EAAIC,QACJA,EAAOC,QACPA,EAAOC,SACPA,EAAQC,OACRA,EAAMC,QACNA,EAAOC,OACPA,EAAMC,kBACNA,EAAiBC,UACjBA,EAASC,UACTA,EAASlC,MACTA,EAAKmC,UACLA,EAASC,gBACTA,EAAeC,YACfA,GACGvB,EAEEwB,GAAuBrB,aAAQ,EAARA,EAAUsB,QACpCC,EACAC,EAAczB,QAAAA,EAAkB,IAChCC,EAASd,KAAKuC,GAAYzC,OAAA0C,OAAA1C,OAAA0C,OAAA,CAAA,EAAAD,IAAGE,QAASH,EAAcC,EAAEE,cAEtDH,EAAczB,QAAAA,EAAkB,IAO7B6B,EAAeC,EAAmC,IAClDC,EAAmBD,GAAO,GAI1BE,EAAaF,EAAOnB,GAC1BqB,EAAWC,QAAUtB,EACrB,MAAMuB,EAAcJ,EAAOlB,GAC3BsB,EAAYD,QAAUrB,EACtB,MAAMuB,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6G,QAAQpE,QAAQ8H,OAAOxD,MAC3CyD,KAAMA,IAAMxK,cAAM,EAANA,GAAQ6G,QAAQpE,QAAQ+H,OAAOzD,MAC3C0D,QAASA,WAAM,OAAwB,QAAxBnK,EAAAN,gBAAAA,GAAQ0K,MAAMH,cAAU,IAAAjK,GAAAA,CAAK,EAC5CqK,QAASA,WAAM,OAAwB,QAAxBrK,EAAAN,gBAAAA,GAAQ0K,MAAMF,cAAU,IAAAlK,GAAAA,CAAK,EAC5CsK,kBAAmBA,IAClB5K,cAAM,EAANA,GAAQ6G,QAAQpE,QAAQmI,oBAAoB7D,MAC7C8D,gBAAiBA,IAAM7K,cAAM,EAANA,GAAQ6G,QAAQpE,QAAQoI,kBAAkB9D,MACjE+D,YAAcC,GAAQ/K,cAAA,EAAAA,GAAQ6G,QAAQpE,QAAQuI,SAAS,CAAED,QAAOhE,UAIlE,CAAC/G,KAGGA,GAGJiL,EAACC,EAAcxO,OAAA0C,OAAA,CACdV,UAAWA,EACXC,UAAWA,EACXlC,MAAOA,EACPmC,UAAWA,GAEX,CAAAuM,SAAA,CAAAC,EAACC,EAAa,CAACrL,OAAQA,KACvBoL,EAACE,EAAe,CAAAtL,OAAQA,GAAQuL,kBAAmBrN,aAAA,EAAAA,EAAMsN,oBAVvC,IAWF,IAOnBpO,EAAUqO,YAAc"}
@@ -1,2 +1,2 @@
1
- import{DOMSerializer as t,DOMParser as e}from"../node_modules/prosemirror-model/dist/index.js";function i(t){return t.replace(/<p>\s*<br\s*\/?>\s*<\/p>/gi,"<p></p>").replace(/<span[^>]*>(\{\{[^}]+\}\})<\/span>/gi,"$1")}const n=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function r(t,e){let i=t;for(const t of e)i+=n(t.id)+t.content;return i}function o(t){var e;if(!t)return"";return null!==(e=l(t).get("body"))&&void 0!==e?e:t}function s(t){if(!t)return"";const e=o(t);return t.substring(e.length)}function l(t){const e=new Map,i=/<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g,n=[];let r;for(;null!==(r=i.exec(t));)n.push({id:r[1],index:r.index,endIndex:r.index+r[0].length});if(0===n.length)return e.set("body",t),e;e.set("body",t.slice(0,n[0].index));for(let i=0;i<n.length;i++){const r=n[i].endIndex,o=i+1<n.length?n[i+1].index:t.length;e.set(n[i].id,t.slice(r,o))}return e}function c(e,i){var n;const r=v(e,i);if(-1===r)return{html:"",text:"",isEmpty:!0,characterCount:0};const o=h(e,i),s=e.state.doc.slice(r,o),l=document.createElement("div"),c=t.fromSchema(e.schema);l.appendChild(c.serializeFragment(s.content));const d=l.innerHTML,u=null!==(n=l.textContent)&&void 0!==n?n:"";return{html:d,text:u,isEmpty:!u.trim(),characterCount:u.length}}function d(t,i,r){const o=v(t,i);if(-1===o){const e=t.state.doc.content.size,o=n(i)+r;return void t.commands.insertContentAt(e,o,{updateSelection:!1})}const s=h(t,i),l=function(t,i){const n=document.createElement("div");return n.innerHTML=i,e.fromSchema(t.schema).parse(n).content}(t,r),{tr:c}=t.state,d="body"===i?0:o;c.replaceWith(d,s,l),c.setMeta("addToHistory",!1),t.view.dispatch(c)}function u(t){return c(t,"body")}function a(t){var e,i,n,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,i,n;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!==(n=t.attrs.href)&&void 0!==n?n:""};{const t=r.nodeBefore,e=null==t?void 0:t.marks.find((t=>"link"===t.type.name));if(e)return{href:null!==(i=e.attrs.href)&&void 0!==i?i:""}}}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!==(i=t.getAttributes("textStyle").fontSize)&&void 0!==i?i:null,color:null!==(n=t.getAttributes("textStyle").color)&&void 0!==n?n: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 f(t){var e,i,n;return{html:t.getHTML(),text:t.getText(),isEmpty:t.isEmpty,characterCount:null!==(n=null===(i=null===(e=t.storage.characterCount)||void 0===e?void 0:e.characters)||void 0===i?void 0:i.call(e))&&void 0!==n?n:t.getText().length}}function v(t,e){if("body"===e)return 1;let i=-1;return t.state.doc.descendants(((t,n)=>{if(-1!==i)return!1;"sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(i=n+t.nodeSize)})),i}function h(t,e){const i=t.state.doc,n=i.content.size;if("body"===e){let t=-1;return i.descendants(((e,i)=>{if(-1!==t)return!1;"sectionDivider"===e.type.name&&(t=i)})),-1!==t?t:n}let r=!1,o=-1;return i.descendants(((t,i)=>-1===o&&(r?void("sectionDivider"===t.type.name&&(o=i)):("sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(r=!0),!1)))),-1!==o?o:n}export{n as SECTION_DIVIDER_HTML,r as buildSectionedContent,a as extractActiveFormats,l as extractAllSectionsFromHtml,u as extractBodyContent,f as extractContent,c as extractSectionContent,h as findSectionEndPos,v as findSectionStartPos,o as getBodyHtml,s as getSectionsHtml,i as normalizeHtml,d as setSectionContentInEditor};
1
+ import{DOMSerializer as t,DOMParser as e}from"../node_modules/prosemirror-model/dist/index.js";function i(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 r(t,e){let i=t;for(const t of e)i+=n(t.id)+t.content;return i}function o(t){var e;if(!t)return"";return null!==(e=l(t).get("body"))&&void 0!==e?e:t}function s(t){if(!t)return"";const e=o(t);return t.substring(e.length)}function l(t){const e=new Map,i=/<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g,n=[];let r;for(;null!==(r=i.exec(t));)n.push({id:r[1],index:r.index,endIndex:r.index+r[0].length});if(0===n.length)return e.set("body",t),e;e.set("body",t.slice(0,n[0].index));for(let i=0;i<n.length;i++){const r=n[i].endIndex,o=i+1<n.length?n[i+1].index:t.length;e.set(n[i].id,t.slice(r,o))}return e}function c(e,i){var n;const r=v(e,i);if(-1===r)return{html:"",text:"",isEmpty:!0,characterCount:0};const o=h(e,i),s=e.state.doc.slice(r,o),l=document.createElement("div"),c=t.fromSchema(e.schema);l.appendChild(c.serializeFragment(s.content));const d=l.innerHTML,u=null!==(n=l.textContent)&&void 0!==n?n:"";return{html:d,text:u,isEmpty:!u.trim(),characterCount:u.length}}function d(t,i,r){const o=v(t,i);if(-1===o){const e=t.state.doc.content.size,o=n(i)+r;return void t.commands.insertContentAt(e,o,{updateSelection:!1})}const s=h(t,i),l=function(t,i){const n=document.createElement("div");return n.innerHTML=i,e.fromSchema(t.schema).parse(n).content}(t,r),{tr:c}=t.state,d="body"===i?0:o;c.replaceWith(d,s,l),c.setMeta("addToHistory",!1),t.view.dispatch(c)}function u(t){return c(t,"body")}function a(t){var e,i,n,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,i,n;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!==(n=t.attrs.href)&&void 0!==n?n:""};{const t=r.nodeBefore,e=null==t?void 0:t.marks.find((t=>"link"===t.type.name));if(e)return{href:null!==(i=e.attrs.href)&&void 0!==i?i:""}}}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!==(i=t.getAttributes("textStyle").fontSize)&&void 0!==i?i:null,color:null!==(n=t.getAttributes("textStyle").color)&&void 0!==n?n: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 f(t){var e,i,n;return{html:t.getHTML(),text:t.getText(),isEmpty:t.isEmpty,characterCount:null!==(n=null===(i=null===(e=t.storage.characterCount)||void 0===e?void 0:e.characters)||void 0===i?void 0:i.call(e))&&void 0!==n?n:t.getText().length}}function v(t,e){if("body"===e)return 1;let i=-1;return t.state.doc.descendants(((t,n)=>{if(-1!==i)return!1;"sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(i=n+t.nodeSize)})),i}function h(t,e){const i=t.state.doc,n=i.content.size;if("body"===e){let t=-1;return i.descendants(((e,i)=>{if(-1!==t)return!1;"sectionDivider"===e.type.name&&(t=i)})),-1!==t?t:n}let r=!1,o=-1;return i.descendants(((t,i)=>-1===o&&(r?void("sectionDivider"===t.type.name&&(o=i)):("sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(r=!0),!1)))),-1!==o?o:n}export{n as SECTION_DIVIDER_HTML,r as buildSectionedContent,a as extractActiveFormats,l as extractAllSectionsFromHtml,u as extractBodyContent,f as extractContent,c as extractSectionContent,h as findSectionEndPos,v as findSectionStartPos,o as getBodyHtml,s as getSectionsHtml,i as normalizeHtml,d 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 } 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[^>]*>(\\{\\{[^}]+\\}\\})<\\/span>/gi, '$1');\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","buildSectionedContent","body","sections","s","content","getBodyHtml","_a","extractAllSectionsFromHtml","get","getSectionsHtml","substring","length","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","document","createElement","serializer","DOMSerializer","fromSchema","schema","appendChild","serializeFragment","innerHTML","textContent","trim","setSectionContentInEditor","size","dividerHtml","commands","insertContentAt","updateSelection","fragment","DOMParser","parse","parseHtmlToNodes","tr","replaceFrom","replaceWith","setMeta","view","dispatch","extractBodyContent","extractActiveFormats","bold","isActive","italic","underline","strike","bulletList","orderedList","blockquote","codeBlock","link","href","getAttributes","$from","selection","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,uCAAwC,KACnD,OAMaC,EAAwBC,GACpC,8BAA8BA,yEAYf,SAAAC,EACfC,EACAC,GAEA,IAAIN,EAAOK,EACX,IAAK,MAAME,KAAKD,EACfN,GAAQE,EAAqBK,EAAEJ,IAAMI,EAAEC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Content":["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// 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","buildSectionedContent","body","sections","s","content","getBodyHtml","_a","extractAllSectionsFromHtml","get","getSectionsHtml","substring","length","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","document","createElement","serializer","DOMSerializer","fromSchema","schema","appendChild","serializeFragment","innerHTML","textContent","trim","setSectionContentInEditor","size","dividerHtml","commands","insertContentAt","updateSelection","fragment","DOMParser","parse","parseHtmlToNodes","tr","replaceFrom","replaceWith","setMeta","view","dispatch","extractBodyContent","extractActiveFormats","bold","isActive","italic","underline","strike","bulletList","orderedList","blockquote","codeBlock","link","href","getAttributes","$from","selection","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,OAMaC,EAAwBC,GACpC,8BAA8BA,yEAYf,SAAAC,EACfC,EACAC,GAEA,IAAIN,EAAOK,EACX,IAAK,MAAME,KAAKD,EACfN,GAAQE,EAAqBK,EAAEJ,IAAMI,EAAEC,QAExC,OAAOR,CACR,CAoBM,SAAUS,EAAYT,SAC3B,IAAKA,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AM8B,EAAO4E,UACbzE,KAAMH,EAAO6E,UACbzE,QAASJ,EAAOI,QAChBC,eACkD,QAAjDyD,UAAAI,EAA+B,UAA/BlE,EAAO8E,QAAQzE,sBAAgB,IAAAzB,OAAA,EAAAA,EAAAmG,gDAAkB,IAAAjB,EAAAA,EAAA9D,EAAO6E,UAAU5F,OAErE,CAYgB,SAAAiB,EAAoBF,EAAgBgF,GACnD,GAAkB,SAAdA,EAAsB,OAAO,EACjC,IAAI/E,GAAY,EAUhB,OATAD,EAAOQ,MAAMC,IAAIwE,aAAY,CAACC,EAAM5B,KACnC,IAAkB,IAAdrD,EAAiB,OAAO,EAER,mBAAnBiF,EAAKtB,KAAKC,MACVqB,EAAKnB,MAAiB,YAAMiB,IAE5B/E,EAAWqD,EAAM4B,EAAKC,SACtB,IAEKlF,CACR,CAOgB,SAAAM,EAAkBP,EAAgBgF,GACjD,MAAMvE,EAAMT,EAAOQ,MAAMC,IACnB2E,EAAU3E,EAAI/B,QAAQ6C,KAE5B,GAAkB,SAAdyD,EAAsB,CACzB,IAAIK,GAAmB,EAOvB,OANA5E,EAAIwE,aAAY,CAACC,EAAM5B,KACtB,IAAyB,IAArB+B,EAAwB,OAAO,EACZ,mBAAnBH,EAAKtB,KAAKC,OACbwB,EAAkB/B,EAClB,KAE0B,IAArB+B,EAAyBA,EAAkBD,CAClD,CAED,IAAIE,GAAgB,EAChBC,GAAkB,EAgBtB,OAfA9E,EAAIwE,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.804-beta.6",
3
+ "version": "0.0.804-beta.8",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",