@bikdotai/bik-component-library 0.0.788-beta.11 → 0.0.788-beta.12

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 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react/jsx-runtime"),t=require("../node_modules/@tiptap/core/dist/index.js"),e=require("@tiptap/react"),o=require("react"),i=require("./BikEditor.styles.js"),l=require("./BikEditor.utils.js"),r=require("./extensions/buildExtensions.js"),s=require("./floating/LinkBubbleMenu.js");function d(n){return Object.entries(n).map((n=>{let[t,e]=n;return`${t.replace(/([A-Z])/g,(n=>`-${n.toLowerCase()}`))}:${e}`})).join(";")}const a=(a,c)=>{var u;const{initialContent:m,sections:g,features:v,disabled:h,maxCharacters:C,shortcuts:f,sendShortcut:S,mentions:p,slashCommands:x,link:k,onPaste:H,onChange:b,onSend:B,onFocus:y,onBlur:z,onSelectionChange:A,minHeight:j,maxHeight:E,style:L,className:F,editorClassName:I,editorStyle:M}=a,q=(null==g?void 0:g.length)?l.buildSectionedContent(l.normalizeHtml(null!=m?m:""),g.map((n=>Object.assign(Object.assign({},n),{content:l.normalizeHtml(n.content)})))):l.normalizeHtml(null!=m?m:""),O=e.useEditor({extensions:r.buildExtensions({features:v,placeholder:a.placeholder,maxCharacters:C,hasSections:(null!==(u=null==g?void 0:g.length)&&void 0!==u?u:0)>0,mentions:{agents:null==p?void 0:p.agents,teams:null==p?void 0:p.teams},slashCommands:null==x?void 0:x.items,onPaste:H,onSend:B,sendShortcut:S,shortcuts:f,onMentionSelected:null==p?void 0:p.onSelect,onSlashCommandSelected:null==x?void 0:x.onSelect,renderMentionItem:null==p?void 0:p.renderItem,renderMentionDropdown:null==p?void 0:p.renderDropdown,renderSlashCommandItem:null==x?void 0:x.renderItem,renderSlashCommandDropdown:null==x?void 0:x.renderDropdown}),content:q,editable:!h,immediatelyRender:!1,editorProps:{attributes:Object.assign(Object.assign({},I?{class:I}:{}),M?{style:d(M)}:{})},onUpdate:n=>{let{editor:t}=n;return null==b?void 0:b(l.extractContent(t))},onSelectionUpdate:n=>{let{editor:t}=n;return null==A?void 0:A(l.extractActiveFormats(t))},onFocus:()=>null==y?void 0:y(),onBlur:()=>null==z?void 0:z()});return o.useImperativeHandle(c,(()=>({focus:()=>null==O?void 0:O.commands.focus(),blur:()=>null==O?void 0:O.commands.blur(),clearContent:()=>null==O?void 0:O.commands.clearContent(!0),setContent:n=>null==O?void 0:O.commands.setContent(l.normalizeHtml(n),{emitUpdate:!0}),insertContent:n=>null==O?void 0:O.commands.insertContent(l.normalizeHtml(n)),insertAtStart:n=>{O&&O.commands.insertContentAt(1,l.normalizeHtml(n))},insertAtEnd:n=>{O&&O.commands.insertContentAt(O.state.doc.content.size,l.normalizeHtml(n))},appendContent:n=>{O&&O.commands.insertContentAt(O.state.doc.content.size-1,l.normalizeHtml(n))},getContent:()=>O?l.extractContent(O):{html:"",text:"",isEmpty:!0,characterCount:0},getCursorPosition:()=>{const{from:n,to:t}=O.state.selection;return{from:n,to:t}},insertAtPosition:(n,t)=>{O&&O.commands.insertContentAt(n,t)},getSelectedText:()=>{const{state:n}=O,{from:e,to:o,empty:i}=n.selection;if(!i)return n.doc.textBetween(e,o," ");const l=n.schema.marks.link;if(l){const o=t.getMarkRange(n.doc.resolve(e),l);if(o)return n.doc.textBetween(o.from,o.to," ")}return""},getCharacterCount:()=>{var n,t,e,o;return{count:null!==(o=null!==(e=null===(t=null===(n=null==O?void 0:O.storage.characterCount)||void 0===n?void 0:n.characters)||void 0===t?void 0:t.call(n))&&void 0!==e?e:null==O?void 0:O.getText().length)&&void 0!==o?o:0,limit:null!=C?C:null}},getSectionContent:n=>l.extractSectionContent(O,n),setSectionContent:(n,t)=>{O&&l.setSectionContentInEditor(O,n,l.normalizeHtml(t))},focusSection:n=>{if(!O)return;if("body"===n)return void O.chain().focus().setTextSelection(1).run();let t=-1;O.state.doc.descendants(((e,o)=>{if(-1!==t)return!1;"sectionDivider"===e.type.name&&e.attrs.sectionId===n&&(t=o+e.nodeSize+1)})),-1!==t&&O.chain().focus().setTextSelection(t).run()},clearSection:n=>{O&&l.setSectionContentInEditor(O,n,"<p></p>")},getBodyContent:()=>l.extractBodyContent(O),setBodyContent:n=>{O&&l.setSectionContentInEditor(O,"body",l.normalizeHtml(n))},setBodyAndSections:(n,t)=>{if(!O)return;const e=l.buildSectionedContent(l.normalizeHtml(n),t.map((n=>({id:n.id,content:l.normalizeHtml(n.content)}))));O.commands.setContent(e,{emitUpdate:!0})},appendBodyContent:n=>{if(!O)return;const t=l.normalizeHtml(n),e=l.findSectionEndPos(O,"body");O.commands.insertContentAt(e-1,t)},insertAtSectionStart:(n,t)=>{if(!O)return;const e=l.findSectionStartPos(O,n);-1!==e&&O.commands.insertContentAt(e,l.normalizeHtml(t))},insertAtSectionEnd:(n,t)=>{if(!O)return;const e=l.findSectionEndPos(O,n);O.commands.insertContentAt(e,l.normalizeHtml(t))},getActiveFormats:()=>l.extractActiveFormats(O),actions:{toggleBold:()=>null==O?void 0:O.chain().focus().toggleBold().run(),toggleItalic:()=>null==O?void 0:O.chain().focus().toggleItalic().run(),toggleUnderline:()=>null==O?void 0:O.chain().focus().toggleUnderline().run(),toggleStrike:()=>null==O?void 0:O.chain().focus().toggleStrike().run(),toggleBulletList:()=>null==O?void 0:O.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>null==O?void 0:O.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>null==O?void 0:O.chain().focus().toggleBlockquote().run(),toggleCodeBlock:()=>null==O?void 0:O.chain().focus().toggleCodeBlock().run(),setTextAlign:n=>null==O?void 0:O.chain().focus().setTextAlign(n).run(),setFontFamily:n=>null==O?void 0:O.chain().focus().setFontFamily(n).run(),setFontSize:n=>null==O?void 0:O.chain().focus().setFontSize(n).run(),setColor:n=>null==O?void 0:O.chain().focus().setColor(n).run(),setHighlight:n=>null==O?void 0:O.chain().focus().toggleHighlight({color:n}).run(),unsetColor:()=>null==O?void 0:O.chain().focus().unsetColor().run(),unsetHighlight:()=>null==O?void 0:O.chain().focus().unsetHighlight().run(),setLink:(n,t)=>{O&&(void 0!==t?O.chain().focus().extendMarkRange("link").command((e=>{let{tr:o,state:i}=e;const{from:l,to:r}=o.selection,s=i.schema.marks.link;return!!s&&(o.replaceWith(l,r,i.schema.text(t,[s.create({href:n})])),!0)})).run():O.chain().focus().extendMarkRange("link").setLink({href:n}).run())},updateLink:n=>null==O?void 0:O.chain().focus().extendMarkRange("link").setLink({href:n}).run(),removeLink:()=>null==O?void 0:O.chain().focus().extendMarkRange("link").unsetLink().run(),insertEmoji:n=>null==O?void 0:O.chain().focus().insertContent(n).run(),insertVariable:n=>null==O?void 0:O.chain().focus().insertContent(`{{${n}}}`).run(),insertHtml:n=>null==O?void 0:O.commands.insertContent(n),undo:()=>null==O?void 0:O.chain().focus().undo().run(),redo:()=>null==O?void 0:O.chain().focus().redo().run(),canUndo:()=>{var n;return null!==(n=null==O?void 0:O.can().undo())&&void 0!==n&&n},canRedo:()=>{var n;return null!==(n=null==O?void 0:O.can().redo())&&void 0!==n&&n}}})),[O]),O?n.jsxs(i.BikEditorShell,Object.assign({minHeight:j,maxHeight:E,style:L,className:F},{children:[n.jsx(e.EditorContent,{editor:O}),n.jsx(s.LinkBubbleMenu,{editor:O,renderLinkTooltip:null==k?void 0:k.renderTooltip})]})):null},c=o.forwardRef(a);c.displayName="BikEditor",exports.BikEditor=c;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react/jsx-runtime"),n=require("../node_modules/@tiptap/core/dist/index.js"),e=require("@tiptap/react"),o=require("react"),i=require("./BikEditor.styles.js"),l=require("./BikEditor.utils.js"),r=require("./extensions/buildExtensions.js"),s=require("./floating/LinkBubbleMenu.js");function c(t){return Object.entries(t).map((t=>{let[n,e]=t;return`${n.replace(/([A-Z])/g,(t=>`-${t.toLowerCase()}`))}:${e}`})).join(";")}const a=(a,d)=>{var u;const{initialContent:m,sections:g,features:h,disabled:v,maxCharacters:f,shortcuts:C,sendShortcut:S,mentions:p,slashCommands:x,link:k,onPaste:H,onReady:b,onChange:B,onSend:y,onFocus:z,onBlur:E,onSelectionChange:A,minHeight:j,maxHeight:L,style:R,className:F,editorClassName:I,editorStyle:M}=a,q=(null==g?void 0:g.length)?l.buildSectionedContent(l.normalizeHtml(null!=m?m:""),g.map((t=>Object.assign(Object.assign({},t),{content:l.normalizeHtml(t.content)})))):l.normalizeHtml(null!=m?m:""),O=o.useRef([]),P=o.useRef(!1),w=o.useRef(b);w.current=b;const T=e.useEditor({extensions:r.buildExtensions({features:h,placeholder:a.placeholder,maxCharacters:f,hasSections:(null!==(u=null==g?void 0:g.length)&&void 0!==u?u:0)>0,mentions:{agents:null==p?void 0:p.agents,teams:null==p?void 0:p.teams},slashCommands:null==x?void 0:x.items,onPaste:H,onSend:y,sendShortcut:S,shortcuts:C,onMentionSelected:null==p?void 0:p.onSelect,onSlashCommandSelected:null==x?void 0:x.onSelect,renderMentionItem:null==p?void 0:p.renderItem,renderMentionDropdown:null==p?void 0:p.renderDropdown,renderSlashCommandItem:null==x?void 0:x.renderItem,renderSlashCommandDropdown:null==x?void 0:x.renderDropdown}),content:q,editable:!v,immediatelyRender:!1,editorProps:{attributes:Object.assign(Object.assign({},I?{class:I}:{}),M?{style:c(M)}:{})},onUpdate:t=>{let{editor:n}=t;return null==B?void 0:B(l.extractContent(n))},onSelectionUpdate:t=>{let{editor:n}=t;return null==A?void 0:A(l.extractActiveFormats(n))},onFocus:()=>null==z?void 0:z(),onBlur:()=>null==E?void 0:E()});function U(t){T?t(T):O.current.push(t)}return o.useEffect((()=>{var t;if(T){if(O.current.length>0){O.current.splice(0).forEach((t=>t(T)))}P.current||(P.current=!0,null===(t=w.current)||void 0===t||t.call(w))}}),[T]),o.useImperativeHandle(d,(()=>({focus:()=>U((t=>t.commands.focus())),blur:()=>U((t=>t.commands.blur())),clearContent:()=>U((t=>t.commands.clearContent(!0))),setContent:t=>{const n=l.normalizeHtml(t);U((t=>t.commands.setContent(n,{emitUpdate:!0})))},insertContent:t=>{const n=l.normalizeHtml(t);U((t=>t.commands.insertContent(n)))},insertAtStart:t=>{const n=l.normalizeHtml(t);U((t=>t.commands.insertContentAt(1,n)))},insertAtEnd:t=>{const n=l.normalizeHtml(t);U((t=>t.commands.insertContentAt(t.state.doc.content.size,n)))},appendContent:t=>{const n=l.normalizeHtml(t);U((t=>t.commands.insertContentAt(t.state.doc.content.size-1,n)))},getContent:()=>T?l.extractContent(T):{html:"",text:"",isEmpty:!0,characterCount:0},getCursorPosition:()=>{const{from:t,to:n}=T.state.selection;return{from:t,to:n}},insertAtPosition:(t,n)=>{const e=l.normalizeHtml(n);U((n=>n.commands.insertContentAt(t,e)))},getSelectedText:()=>{const{state:t}=T,{from:e,to:o,empty:i}=t.selection;if(!i)return t.doc.textBetween(e,o," ");const l=t.schema.marks.link;if(l){const o=n.getMarkRange(t.doc.resolve(e),l);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==T?void 0:T.storage.characterCount)||void 0===t?void 0:t.characters)||void 0===n?void 0:n.call(t))&&void 0!==e?e:null==T?void 0:T.getText().length)&&void 0!==o?o:0,limit:null!=f?f:null}},getSectionContent:t=>l.extractSectionContent(T,t),setSectionContent:(t,n)=>{const e=l.normalizeHtml(n);U((n=>l.setSectionContentInEditor(n,t,e)))},focusSection:t=>{U((n=>{if("body"===t)return void n.chain().focus().setTextSelection(1).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=>{U((n=>l.setSectionContentInEditor(n,t,"<p></p>")))},getBodyContent:()=>l.extractBodyContent(T),setBodyContent:t=>{const n=l.normalizeHtml(t);U((t=>l.setSectionContentInEditor(t,"body",n)))},setBodyAndSections:(t,n)=>{const e=l.buildSectionedContent(l.normalizeHtml(t),n.map((t=>({id:t.id,content:l.normalizeHtml(t.content)}))));U((t=>t.commands.setContent(e,{emitUpdate:!0})))},appendBodyContent:t=>{const n=l.normalizeHtml(t);U((t=>{const e=l.findSectionEndPos(t,"body");t.commands.insertContentAt(e-1,n)}))},insertAtSectionStart:(t,n)=>{const e=l.normalizeHtml(n);U((n=>{const o=l.findSectionStartPos(n,t);-1!==o&&n.commands.insertContentAt(o,e)}))},insertAtSectionEnd:(t,n)=>{const e=l.normalizeHtml(n);U((n=>{const o=l.findSectionEndPos(n,t);n.commands.insertContentAt(o,e)}))},getActiveFormats:()=>l.extractActiveFormats(T),actions:{toggleBold:()=>null==T?void 0:T.chain().focus().toggleBold().run(),toggleItalic:()=>null==T?void 0:T.chain().focus().toggleItalic().run(),toggleUnderline:()=>null==T?void 0:T.chain().focus().toggleUnderline().run(),toggleStrike:()=>null==T?void 0:T.chain().focus().toggleStrike().run(),toggleBulletList:()=>null==T?void 0:T.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>null==T?void 0:T.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>null==T?void 0:T.chain().focus().toggleBlockquote().run(),toggleCodeBlock:()=>null==T?void 0:T.chain().focus().toggleCodeBlock().run(),setTextAlign:t=>null==T?void 0:T.chain().focus().setTextAlign(t).run(),setFontFamily:t=>null==T?void 0:T.chain().focus().setFontFamily(t).run(),setFontSize:t=>null==T?void 0:T.chain().focus().setFontSize(t).run(),setColor:t=>null==T?void 0:T.chain().focus().setColor(t).run(),setHighlight:t=>null==T?void 0:T.chain().focus().toggleHighlight({color:t}).run(),unsetColor:()=>null==T?void 0:T.chain().focus().unsetColor().run(),unsetHighlight:()=>null==T?void 0:T.chain().focus().unsetHighlight().run(),setLink:(t,n)=>{T&&(void 0!==n?T.chain().focus().extendMarkRange("link").command((e=>{let{tr:o,state:i}=e;const{from:l,to:r}=o.selection,s=i.schema.marks.link;return!!s&&(o.replaceWith(l,r,i.schema.text(n,[s.create({href:t})])),!0)})).run():T.chain().focus().extendMarkRange("link").setLink({href:t}).run())},updateLink:t=>null==T?void 0:T.chain().focus().extendMarkRange("link").setLink({href:t}).run(),removeLink:()=>null==T?void 0:T.chain().focus().extendMarkRange("link").unsetLink().run(),insertEmoji:t=>null==T?void 0:T.chain().focus().insertContent(t).run(),insertVariable:t=>null==T?void 0:T.chain().focus().insertContent(`{{${t}}}`).run(),insertHtml:t=>null==T?void 0:T.commands.insertContent(t),undo:()=>null==T?void 0:T.chain().focus().undo().run(),redo:()=>null==T?void 0:T.chain().focus().redo().run(),canUndo:()=>{var t;return null!==(t=null==T?void 0:T.can().undo())&&void 0!==t&&t},canRedo:()=>{var t;return null!==(t=null==T?void 0:T.can().redo())&&void 0!==t&&t}}})),[T]),T?t.jsxs(i.BikEditorShell,Object.assign({minHeight:j,maxHeight:L,style:R,className:F},{children:[t.jsx(e.EditorContent,{editor:T}),t.jsx(s.LinkBubbleMenu,{editor:T,renderLinkTooltip:null==k?void 0:k.renderTooltip})]})):null},d=o.forwardRef(a);d.displayName="BikEditor",exports.BikEditor=d;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const Menus: ({
3
2
  displayName: string;
4
3
  key: number;
@@ -631,6 +631,19 @@ export interface BikEditorProps {
631
631
  * )}}
632
632
  */
633
633
  link?: LinkConfig;
634
+ /**
635
+ * Called once, immediately after the editor finishes initializing.
636
+ * Any imperative ref methods called before this fires are queued internally
637
+ * and executed automatically once the editor is ready — consumers do not
638
+ * need timers or readiness guards.
639
+ *
640
+ * @example
641
+ * <BikEditor
642
+ * ref={editorRef}
643
+ * onReady={() => editorRef.current?.setContent(savedDraft)}
644
+ * />
645
+ */
646
+ onReady?: () => void;
634
647
  /** Called on every document change. */
635
648
  onChange?: (content: EditorSnapshot) => void;
636
649
  /**
@@ -1 +1 @@
1
- import{jsxs as n,jsx as t}from"react/jsx-runtime";import{getMarkRange as e}from"../node_modules/@tiptap/core/dist/index.js";import{useEditor as o,EditorContent as i}from"@tiptap/react";import{forwardRef as l,useImperativeHandle as r}from"react";import{BikEditorShell as s}from"./BikEditor.styles.js";import{buildSectionedContent as d,normalizeHtml as c,extractContent as u,extractActiveFormats as a,extractSectionContent as m,setSectionContentInEditor as g,extractBodyContent as h,findSectionEndPos as v,findSectionStartPos as f}from"./BikEditor.utils.js";import{buildExtensions as C}from"./extensions/buildExtensions.js";import{LinkBubbleMenu as p}from"./floating/LinkBubbleMenu.js";function S(n){return Object.entries(n).map((n=>{let[t,e]=n;return`${t.replace(/([A-Z])/g,(n=>`-${n.toLowerCase()}`))}:${e}`})).join(";")}const k=l(((l,k)=>{var x;const{initialContent:B,sections:y,features:b,disabled:A,maxCharacters:j,shortcuts:L,sendShortcut:F,mentions:H,slashCommands:E,link:M,onPaste:O,onChange:T,onSend:w,onFocus:I,onBlur:U,onSelectionChange:R,minHeight:z,maxHeight:D,style:P,className:N,editorClassName:$,editorStyle:q}=l,V=(null==y?void 0:y.length)?d(c(null!=B?B:""),y.map((n=>Object.assign(Object.assign({},n),{content:c(n.content)})))):c(null!=B?B:""),W=o({extensions:C({features:b,placeholder:l.placeholder,maxCharacters:j,hasSections:(null!==(x=null==y?void 0:y.length)&&void 0!==x?x:0)>0,mentions:{agents:null==H?void 0:H.agents,teams:null==H?void 0:H.teams},slashCommands:null==E?void 0:E.items,onPaste:O,onSend:w,sendShortcut:F,shortcuts:L,onMentionSelected:null==H?void 0:H.onSelect,onSlashCommandSelected:null==E?void 0:E.onSelect,renderMentionItem:null==H?void 0:H.renderItem,renderMentionDropdown:null==H?void 0:H.renderDropdown,renderSlashCommandItem:null==E?void 0:E.renderItem,renderSlashCommandDropdown:null==E?void 0:E.renderDropdown}),content:V,editable:!A,immediatelyRender:!1,editorProps:{attributes:Object.assign(Object.assign({},$?{class:$}:{}),q?{style:S(q)}:{})},onUpdate:n=>{let{editor:t}=n;return null==T?void 0:T(u(t))},onSelectionUpdate:n=>{let{editor:t}=n;return null==R?void 0:R(a(t))},onFocus:()=>null==I?void 0:I(),onBlur:()=>null==U?void 0:U()});return r(k,(()=>({focus:()=>null==W?void 0:W.commands.focus(),blur:()=>null==W?void 0:W.commands.blur(),clearContent:()=>null==W?void 0:W.commands.clearContent(!0),setContent:n=>null==W?void 0:W.commands.setContent(c(n),{emitUpdate:!0}),insertContent:n=>null==W?void 0:W.commands.insertContent(c(n)),insertAtStart:n=>{W&&W.commands.insertContentAt(1,c(n))},insertAtEnd:n=>{W&&W.commands.insertContentAt(W.state.doc.content.size,c(n))},appendContent:n=>{W&&W.commands.insertContentAt(W.state.doc.content.size-1,c(n))},getContent:()=>W?u(W):{html:"",text:"",isEmpty:!0,characterCount:0},getCursorPosition:()=>{const{from:n,to:t}=W.state.selection;return{from:n,to:t}},insertAtPosition:(n,t)=>{W&&W.commands.insertContentAt(n,t)},getSelectedText:()=>{const{state:n}=W,{from:t,to:o,empty:i}=n.selection;if(!i)return n.doc.textBetween(t,o," ");const l=n.schema.marks.link;if(l){const o=e(n.doc.resolve(t),l);if(o)return n.doc.textBetween(o.from,o.to," ")}return""},getCharacterCount:()=>{var n,t,e,o;return{count:null!==(o=null!==(e=null===(t=null===(n=null==W?void 0:W.storage.characterCount)||void 0===n?void 0:n.characters)||void 0===t?void 0:t.call(n))&&void 0!==e?e:null==W?void 0:W.getText().length)&&void 0!==o?o:0,limit:null!=j?j:null}},getSectionContent:n=>m(W,n),setSectionContent:(n,t)=>{W&&g(W,n,c(t))},focusSection:n=>{if(!W)return;if("body"===n)return void W.chain().focus().setTextSelection(1).run();let t=-1;W.state.doc.descendants(((e,o)=>{if(-1!==t)return!1;"sectionDivider"===e.type.name&&e.attrs.sectionId===n&&(t=o+e.nodeSize+1)})),-1!==t&&W.chain().focus().setTextSelection(t).run()},clearSection:n=>{W&&g(W,n,"<p></p>")},getBodyContent:()=>h(W),setBodyContent:n=>{W&&g(W,"body",c(n))},setBodyAndSections:(n,t)=>{if(!W)return;const e=d(c(n),t.map((n=>({id:n.id,content:c(n.content)}))));W.commands.setContent(e,{emitUpdate:!0})},appendBodyContent:n=>{if(!W)return;const t=c(n),e=v(W,"body");W.commands.insertContentAt(e-1,t)},insertAtSectionStart:(n,t)=>{if(!W)return;const e=f(W,n);-1!==e&&W.commands.insertContentAt(e,c(t))},insertAtSectionEnd:(n,t)=>{if(!W)return;const e=v(W,n);W.commands.insertContentAt(e,c(t))},getActiveFormats:()=>a(W),actions:{toggleBold:()=>null==W?void 0:W.chain().focus().toggleBold().run(),toggleItalic:()=>null==W?void 0:W.chain().focus().toggleItalic().run(),toggleUnderline:()=>null==W?void 0:W.chain().focus().toggleUnderline().run(),toggleStrike:()=>null==W?void 0:W.chain().focus().toggleStrike().run(),toggleBulletList:()=>null==W?void 0:W.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>null==W?void 0:W.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>null==W?void 0:W.chain().focus().toggleBlockquote().run(),toggleCodeBlock:()=>null==W?void 0:W.chain().focus().toggleCodeBlock().run(),setTextAlign:n=>null==W?void 0:W.chain().focus().setTextAlign(n).run(),setFontFamily:n=>null==W?void 0:W.chain().focus().setFontFamily(n).run(),setFontSize:n=>null==W?void 0:W.chain().focus().setFontSize(n).run(),setColor:n=>null==W?void 0:W.chain().focus().setColor(n).run(),setHighlight:n=>null==W?void 0:W.chain().focus().toggleHighlight({color:n}).run(),unsetColor:()=>null==W?void 0:W.chain().focus().unsetColor().run(),unsetHighlight:()=>null==W?void 0:W.chain().focus().unsetHighlight().run(),setLink:(n,t)=>{W&&(void 0!==t?W.chain().focus().extendMarkRange("link").command((e=>{let{tr:o,state:i}=e;const{from:l,to:r}=o.selection,s=i.schema.marks.link;return!!s&&(o.replaceWith(l,r,i.schema.text(t,[s.create({href:n})])),!0)})).run():W.chain().focus().extendMarkRange("link").setLink({href:n}).run())},updateLink:n=>null==W?void 0:W.chain().focus().extendMarkRange("link").setLink({href:n}).run(),removeLink:()=>null==W?void 0:W.chain().focus().extendMarkRange("link").unsetLink().run(),insertEmoji:n=>null==W?void 0:W.chain().focus().insertContent(n).run(),insertVariable:n=>null==W?void 0:W.chain().focus().insertContent(`{{${n}}}`).run(),insertHtml:n=>null==W?void 0:W.commands.insertContent(n),undo:()=>null==W?void 0:W.chain().focus().undo().run(),redo:()=>null==W?void 0:W.chain().focus().redo().run(),canUndo:()=>{var n;return null!==(n=null==W?void 0:W.can().undo())&&void 0!==n&&n},canRedo:()=>{var n;return null!==(n=null==W?void 0:W.can().redo())&&void 0!==n&&n}}})),[W]),W?n(s,Object.assign({minHeight:z,maxHeight:D,style:P,className:N},{children:[t(i,{editor:W}),t(p,{editor:W,renderLinkTooltip:null==M?void 0:M.renderTooltip})]})):null}));k.displayName="BikEditor";export{k as BikEditor};
1
+ import{jsxs as n,jsx as t}from"react/jsx-runtime";import{getMarkRange as e}from"../node_modules/@tiptap/core/dist/index.js";import{useEditor as o,EditorContent as i}from"@tiptap/react";import{forwardRef as l,useRef as r,useEffect as s,useImperativeHandle as c}from"react";import{BikEditorShell as d}from"./BikEditor.styles.js";import{buildSectionedContent as u,normalizeHtml as a,extractContent as m,extractActiveFormats as g,extractSectionContent as h,extractBodyContent as v,setSectionContentInEditor as f,findSectionEndPos as C,findSectionStartPos as p}from"./BikEditor.utils.js";import{buildExtensions as S}from"./extensions/buildExtensions.js";import{LinkBubbleMenu as k}from"./floating/LinkBubbleMenu.js";function x(n){return Object.entries(n).map((n=>{let[t,e]=n;return`${t.replace(/([A-Z])/g,(n=>`-${n.toLowerCase()}`))}:${e}`})).join(";")}const y=l(((l,y)=>{var B;const{initialContent:b,sections:A,features:j,disabled:L,maxCharacters:E,shortcuts:F,sendShortcut:H,mentions:M,slashCommands:O,link:T,onPaste:w,onReady:I,onChange:R,onSend:U,onFocus:z,onBlur:D,onSelectionChange:P,minHeight:N,maxHeight:$,style:q,className:V,editorClassName:W,editorStyle:Z}=l,_=(null==A?void 0:A.length)?u(a(null!=b?b:""),A.map((n=>Object.assign(Object.assign({},n),{content:a(n.content)})))):a(null!=b?b:""),G=r([]),J=r(!1),K=r(I);K.current=I;const Q=o({extensions:S({features:j,placeholder:l.placeholder,maxCharacters:E,hasSections:(null!==(B=null==A?void 0:A.length)&&void 0!==B?B:0)>0,mentions:{agents:null==M?void 0:M.agents,teams:null==M?void 0:M.teams},slashCommands:null==O?void 0:O.items,onPaste:w,onSend:U,sendShortcut:H,shortcuts:F,onMentionSelected:null==M?void 0:M.onSelect,onSlashCommandSelected:null==O?void 0:O.onSelect,renderMentionItem:null==M?void 0:M.renderItem,renderMentionDropdown:null==M?void 0:M.renderDropdown,renderSlashCommandItem:null==O?void 0:O.renderItem,renderSlashCommandDropdown:null==O?void 0:O.renderDropdown}),content:_,editable:!L,immediatelyRender:!1,editorProps:{attributes:Object.assign(Object.assign({},W?{class:W}:{}),Z?{style:x(Z)}:{})},onUpdate:n=>{let{editor:t}=n;return null==R?void 0:R(m(t))},onSelectionUpdate:n=>{let{editor:t}=n;return null==P?void 0:P(g(t))},onFocus:()=>null==z?void 0:z(),onBlur:()=>null==D?void 0:D()});function X(n){Q?n(Q):G.current.push(n)}return s((()=>{var n;if(Q){if(G.current.length>0){G.current.splice(0).forEach((n=>n(Q)))}J.current||(J.current=!0,null===(n=K.current)||void 0===n||n.call(K))}}),[Q]),c(y,(()=>({focus:()=>X((n=>n.commands.focus())),blur:()=>X((n=>n.commands.blur())),clearContent:()=>X((n=>n.commands.clearContent(!0))),setContent:n=>{const t=a(n);X((n=>n.commands.setContent(t,{emitUpdate:!0})))},insertContent:n=>{const t=a(n);X((n=>n.commands.insertContent(t)))},insertAtStart:n=>{const t=a(n);X((n=>n.commands.insertContentAt(1,t)))},insertAtEnd:n=>{const t=a(n);X((n=>n.commands.insertContentAt(n.state.doc.content.size,t)))},appendContent:n=>{const t=a(n);X((n=>n.commands.insertContentAt(n.state.doc.content.size-1,t)))},getContent:()=>Q?m(Q):{html:"",text:"",isEmpty:!0,characterCount:0},getCursorPosition:()=>{const{from:n,to:t}=Q.state.selection;return{from:n,to:t}},insertAtPosition:(n,t)=>{const e=a(t);X((t=>t.commands.insertContentAt(n,e)))},getSelectedText:()=>{const{state:n}=Q,{from:t,to:o,empty:i}=n.selection;if(!i)return n.doc.textBetween(t,o," ");const l=n.schema.marks.link;if(l){const o=e(n.doc.resolve(t),l);if(o)return n.doc.textBetween(o.from,o.to," ")}return""},getCharacterCount:()=>{var n,t,e,o;return{count:null!==(o=null!==(e=null===(t=null===(n=null==Q?void 0:Q.storage.characterCount)||void 0===n?void 0:n.characters)||void 0===t?void 0:t.call(n))&&void 0!==e?e:null==Q?void 0:Q.getText().length)&&void 0!==o?o:0,limit:null!=E?E:null}},getSectionContent:n=>h(Q,n),setSectionContent:(n,t)=>{const e=a(t);X((t=>f(t,n,e)))},focusSection:n=>{X((t=>{if("body"===n)return void t.chain().focus().setTextSelection(1).run();let e=-1;t.state.doc.descendants(((t,o)=>{if(-1!==e)return!1;"sectionDivider"===t.type.name&&t.attrs.sectionId===n&&(e=o+t.nodeSize+1)})),-1!==e&&t.chain().focus().setTextSelection(e).run()}))},clearSection:n=>{X((t=>f(t,n,"<p></p>")))},getBodyContent:()=>v(Q),setBodyContent:n=>{const t=a(n);X((n=>f(n,"body",t)))},setBodyAndSections:(n,t)=>{const e=u(a(n),t.map((n=>({id:n.id,content:a(n.content)}))));X((n=>n.commands.setContent(e,{emitUpdate:!0})))},appendBodyContent:n=>{const t=a(n);X((n=>{const e=C(n,"body");n.commands.insertContentAt(e-1,t)}))},insertAtSectionStart:(n,t)=>{const e=a(t);X((t=>{const o=p(t,n);-1!==o&&t.commands.insertContentAt(o,e)}))},insertAtSectionEnd:(n,t)=>{const e=a(t);X((t=>{const o=C(t,n);t.commands.insertContentAt(o,e)}))},getActiveFormats:()=>g(Q),actions:{toggleBold:()=>null==Q?void 0:Q.chain().focus().toggleBold().run(),toggleItalic:()=>null==Q?void 0:Q.chain().focus().toggleItalic().run(),toggleUnderline:()=>null==Q?void 0:Q.chain().focus().toggleUnderline().run(),toggleStrike:()=>null==Q?void 0:Q.chain().focus().toggleStrike().run(),toggleBulletList:()=>null==Q?void 0:Q.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>null==Q?void 0:Q.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>null==Q?void 0:Q.chain().focus().toggleBlockquote().run(),toggleCodeBlock:()=>null==Q?void 0:Q.chain().focus().toggleCodeBlock().run(),setTextAlign:n=>null==Q?void 0:Q.chain().focus().setTextAlign(n).run(),setFontFamily:n=>null==Q?void 0:Q.chain().focus().setFontFamily(n).run(),setFontSize:n=>null==Q?void 0:Q.chain().focus().setFontSize(n).run(),setColor:n=>null==Q?void 0:Q.chain().focus().setColor(n).run(),setHighlight:n=>null==Q?void 0:Q.chain().focus().toggleHighlight({color:n}).run(),unsetColor:()=>null==Q?void 0:Q.chain().focus().unsetColor().run(),unsetHighlight:()=>null==Q?void 0:Q.chain().focus().unsetHighlight().run(),setLink:(n,t)=>{Q&&(void 0!==t?Q.chain().focus().extendMarkRange("link").command((e=>{let{tr:o,state:i}=e;const{from:l,to:r}=o.selection,s=i.schema.marks.link;return!!s&&(o.replaceWith(l,r,i.schema.text(t,[s.create({href:n})])),!0)})).run():Q.chain().focus().extendMarkRange("link").setLink({href:n}).run())},updateLink:n=>null==Q?void 0:Q.chain().focus().extendMarkRange("link").setLink({href:n}).run(),removeLink:()=>null==Q?void 0:Q.chain().focus().extendMarkRange("link").unsetLink().run(),insertEmoji:n=>null==Q?void 0:Q.chain().focus().insertContent(n).run(),insertVariable:n=>null==Q?void 0:Q.chain().focus().insertContent(`{{${n}}}`).run(),insertHtml:n=>null==Q?void 0:Q.commands.insertContent(n),undo:()=>null==Q?void 0:Q.chain().focus().undo().run(),redo:()=>null==Q?void 0:Q.chain().focus().redo().run(),canUndo:()=>{var n;return null!==(n=null==Q?void 0:Q.can().undo())&&void 0!==n&&n},canRedo:()=>{var n;return null!==(n=null==Q?void 0:Q.can().redo())&&void 0!==n&&n}}})),[Q]),Q?n(d,Object.assign({minHeight:N,maxHeight:$,style:q,className:V},{children:[t(i,{editor:Q}),t(k,{editor:Q,renderLinkTooltip:null==T?void 0:T.renderTooltip})]})):null}));y.displayName="BikEditor";export{y as BikEditor};
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const Menus: ({
3
2
  displayName: string;
4
3
  key: number;
@@ -631,6 +631,19 @@ export interface BikEditorProps {
631
631
  * )}}
632
632
  */
633
633
  link?: LinkConfig;
634
+ /**
635
+ * Called once, immediately after the editor finishes initializing.
636
+ * Any imperative ref methods called before this fires are queued internally
637
+ * and executed automatically once the editor is ready — consumers do not
638
+ * need timers or readiness guards.
639
+ *
640
+ * @example
641
+ * <BikEditor
642
+ * ref={editorRef}
643
+ * onReady={() => editorRef.current?.setContent(savedDraft)}
644
+ * />
645
+ */
646
+ onReady?: () => void;
634
647
  /** Called on every document change. */
635
648
  onChange?: (content: EditorSnapshot) => void;
636
649
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.788-beta.11",
3
+ "version": "0.0.788-beta.12",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,31 +0,0 @@
1
- import { ComponentMeta, ComponentStory } from '@storybook/react';
2
- declare const _default: ComponentMeta<({ color, size, }: {
3
- color?: string | undefined;
4
- size?: number | undefined;
5
- }) => import("react/jsx-runtime").JSX.Element>;
6
- export default _default;
7
- export declare const AllIcons: ComponentStory<({ color, size, }: {
8
- color?: string | undefined;
9
- size?: number | undefined;
10
- }) => import("react/jsx-runtime").JSX.Element>;
11
- export declare const ActiveChecklist: ComponentStory<any>;
12
- export declare const CheckIndicator: ComponentStory<any>;
13
- export declare const CompletedChecklist: ComponentStory<any>;
14
- export declare const InactiveChecklist: ComponentStory<any>;
15
- export declare const ProgressBadge: ComponentStory<any>;
16
- export declare const Redirect2: ComponentStory<any>;
17
- export declare const SearchIconComponent: ComponentStory<any>;
18
- export declare const SmallCheck: ComponentStory<any>;
19
- export declare const Customise: ComponentStory<any>;
20
- export declare const Enable: ComponentStory<any>;
21
- export declare const GoLive: ComponentStory<any>;
22
- export declare const Headset: ComponentStory<any>;
23
- export declare const ListChecks: ComponentStory<any>;
24
- export declare const Marketing: ComponentStory<any>;
25
- export declare const Nudges: ComponentStory<any>;
26
- export declare const OnboardingLogoStory: ComponentStory<any>;
27
- export declare const OrderTracking: ComponentStory<any>;
28
- export declare const PlusIconComponent: ComponentStory<any>;
29
- export declare const Shopping: ComponentStory<any>;
30
- export declare const Support: ComponentStory<any>;
31
- export declare const Training: ComponentStory<any>;
@@ -1,31 +0,0 @@
1
- import { ComponentMeta, ComponentStory } from '@storybook/react';
2
- declare const _default: ComponentMeta<({ color, size, }: {
3
- color?: string | undefined;
4
- size?: number | undefined;
5
- }) => import("react/jsx-runtime").JSX.Element>;
6
- export default _default;
7
- export declare const AllIcons: ComponentStory<({ color, size, }: {
8
- color?: string | undefined;
9
- size?: number | undefined;
10
- }) => import("react/jsx-runtime").JSX.Element>;
11
- export declare const ActiveChecklist: ComponentStory<any>;
12
- export declare const CheckIndicator: ComponentStory<any>;
13
- export declare const CompletedChecklist: ComponentStory<any>;
14
- export declare const InactiveChecklist: ComponentStory<any>;
15
- export declare const ProgressBadge: ComponentStory<any>;
16
- export declare const Redirect2: ComponentStory<any>;
17
- export declare const SearchIconComponent: ComponentStory<any>;
18
- export declare const SmallCheck: ComponentStory<any>;
19
- export declare const Customise: ComponentStory<any>;
20
- export declare const Enable: ComponentStory<any>;
21
- export declare const GoLive: ComponentStory<any>;
22
- export declare const Headset: ComponentStory<any>;
23
- export declare const ListChecks: ComponentStory<any>;
24
- export declare const Marketing: ComponentStory<any>;
25
- export declare const Nudges: ComponentStory<any>;
26
- export declare const OnboardingLogoStory: ComponentStory<any>;
27
- export declare const OrderTracking: ComponentStory<any>;
28
- export declare const PlusIconComponent: ComponentStory<any>;
29
- export declare const Shopping: ComponentStory<any>;
30
- export declare const Support: ComponentStory<any>;
31
- export declare const Training: ComponentStory<any>;