@bikdotai/bik-component-library 0.0.792-beta.3 → 0.0.792-beta.4

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 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.utils.js"),l=require("./extensions/buildExtensions.js"),s=require("./floating/LinkBubbleMenu.js");function c(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,a)=>{var d;const{initialContent:m,sections:g,features:v,disabled:h,maxCharacters:f,shortcuts:C,sendShortcut:S,mentions:p,slashCommands:x,link:k,onPaste:b,onReady:H,onChange:B,onSend:y,onFocus:z,onBlur:A,onSelectionChange:E,minHeight:j,maxHeight:R,style:L,className:I,editorClassName:F,editorStyle:M}=u,q=(null==g?void 0:g.length)?r.buildSectionedContent(r.normalizeHtml(null!=m?m:""),g.map((t=>Object.assign(Object.assign({},t),{content:r.normalizeHtml(t.content)})))):r.normalizeHtml(null!=m?m:""),O=o.useRef([]),P=o.useRef(!1),w=o.useRef(H);w.current=H;const T=o.useRef(B);T.current=B;const U=o.useRef(E);U.current=E;const D=o.useRef(z);D.current=z;const N=o.useRef(A);N.current=A;const $=n.useEditor({extensions:l.buildExtensions({features:v,placeholder:u.placeholder,maxCharacters:f,hasSections:(null!==(d=null==g?void 0:g.length)&&void 0!==d?d: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:b,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:!h,immediatelyRender:!1,editorProps:{attributes:Object.assign(Object.assign({},F?{class:F}:{}),M?{style:c(M)}:{})},onUpdate:t=>{let{editor:e}=t;var n,o;null===(n=T.current)||void 0===n||n.call(T,r.extractContent(e)),null===(o=U.current)||void 0===o||o.call(U,r.extractActiveFormats(e))},onSelectionUpdate:t=>{let{editor:e}=t;var n;return null===(n=U.current)||void 0===n?void 0:n.call(U,r.extractActiveFormats(e))},onFocus:()=>{var t;return null===(t=D.current)||void 0===t?void 0:t.call(D)},onBlur:()=>{var t;return null===(t=N.current)||void 0===t?void 0:t.call(N)}});function _(t){$?t($):O.current.push(t)}return o.useEffect((()=>{var t;if($){if(O.current.length>0){O.current.splice(0).forEach((t=>t($)))}P.current||(P.current=!0,null===(t=w.current)||void 0===t||t.call(w))}}),[$]),o.useImperativeHandle(a,(()=>({focus:()=>_((t=>t.commands.focus())),blur:()=>_((t=>t.commands.blur())),clearContent:()=>_((t=>t.commands.clearContent(!0))),setContent:t=>{const e=r.normalizeHtml(t);_((t=>t.commands.setContent(e,{emitUpdate:!0})))},insertContent:t=>{const e=r.normalizeHtml(t);_((t=>t.commands.insertContent(e)))},insertAtStart:t=>{const e=r.normalizeHtml(t);_((t=>t.commands.insertContentAt(1,e)))},insertAtEnd:t=>{const e=r.normalizeHtml(t);_((t=>t.commands.insertContentAt(t.state.doc.content.size,e)))},appendContent:t=>{const e=r.normalizeHtml(t);_((t=>t.commands.insertContentAt(t.state.doc.content.size-1,e)))},getContent:()=>$?r.extractContent($):{html:"",text:"",isEmpty:!0,characterCount:0},getCursorPosition:()=>{const{from:t,to:e}=$.state.selection;return{from:t,to:e}},insertAtPosition:(t,e)=>{const n=r.normalizeHtml(e);_((e=>e.commands.insertContentAt(t,n)))},getSelectedText:()=>{const{state:t}=$,{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==$?void 0:$.storage.characterCount)||void 0===t?void 0:t.characters)||void 0===e?void 0:e.call(t))&&void 0!==n?n:null==$?void 0:$.getText().length)&&void 0!==o?o:0,limit:null!=f?f:null}},getSectionContent:t=>r.extractSectionContent($,t),setSectionContent:(t,e)=>{const n=r.normalizeHtml(e);_((e=>r.setSectionContentInEditor(e,t,n)))},focusSection:t=>{_((e=>{if("body"===t)return void e.chain().focus().setTextSelection(1).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=>{_((e=>r.setSectionContentInEditor(e,t,"<p></p>")))},getBodyContent:()=>r.extractBodyContent($),setBodyContent:t=>{const e=r.normalizeHtml(t);_((t=>r.setSectionContentInEditor(t,"body",e)))},setBodyAndSections:(t,e)=>{const n=r.buildSectionedContent(r.normalizeHtml(t),e.map((t=>({id:t.id,content:r.normalizeHtml(t.content)}))));_((t=>t.commands.setContent(n,{emitUpdate:!0})))},appendBodyContent:t=>{const e=r.normalizeHtml(t);_((t=>{const n=r.findSectionEndPos(t,"body");t.commands.insertContentAt(n-1,e)}))},insertAtSectionStart:(t,e)=>{const n=r.normalizeHtml(e);_((e=>{const o=r.findSectionStartPos(e,t);-1!==o&&e.commands.insertContentAt(o,n)}))},insertAtSectionEnd:(t,e)=>{const n=r.normalizeHtml(e);_((e=>{const o=r.findSectionEndPos(e,t);e.commands.insertContentAt(o,n)}))},getActiveFormats:()=>r.extractActiveFormats($),actions:{toggleBold:()=>null==$?void 0:$.chain().focus().toggleBold().run(),toggleItalic:()=>null==$?void 0:$.chain().focus().toggleItalic().run(),toggleUnderline:()=>null==$?void 0:$.chain().focus().toggleUnderline().run(),toggleStrike:()=>null==$?void 0:$.chain().focus().toggleStrike().run(),toggleBulletList:()=>null==$?void 0:$.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>null==$?void 0:$.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>null==$?void 0:$.chain().focus().toggleBlockquote().run(),toggleCodeBlock:()=>null==$?void 0:$.chain().focus().toggleCodeBlock().run(),setTextAlign:t=>null==$?void 0:$.chain().focus().setTextAlign(t).run(),setFontFamily:t=>null==$?void 0:$.chain().focus().setFontFamily(t).run(),setFontSize:t=>null==$?void 0:$.chain().focus().setFontSize(t).run(),setColor:t=>null==$?void 0:$.chain().focus().setColor(t).run(),setHighlight:t=>null==$?void 0:$.chain().focus().toggleHighlight({color:t}).run(),unsetColor:()=>null==$?void 0:$.chain().focus().unsetColor().run(),unsetHighlight:()=>null==$?void 0:$.chain().focus().unsetHighlight().run(),setLink:(t,e)=>{$&&(void 0!==e?$.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():$.chain().focus().extendMarkRange("link").setLink({href:t}).run())},updateLink:t=>null==$?void 0:$.chain().focus().extendMarkRange("link").setLink({href:t}).run(),removeLink:()=>null==$?void 0:$.chain().focus().extendMarkRange("link").unsetLink().run(),insertEmoji:t=>null==$?void 0:$.chain().focus().insertContent(t).run(),insertVariable:t=>null==$?void 0:$.chain().focus().insertContent(`{{${t}}}`).run(),insertHtml:t=>null==$?void 0:$.commands.insertContent(t),undo:()=>null==$?void 0:$.chain().focus().undo().run(),redo:()=>null==$?void 0:$.chain().focus().redo().run(),canUndo:()=>{var t;return null!==(t=null==$?void 0:$.can().undo())&&void 0!==t&&t},canRedo:()=>{var t;return null!==(t=null==$?void 0:$.can().redo())&&void 0!==t&&t},toggleSuperscript:()=>null==$?void 0:$.chain().focus().toggleSuperscript().run(),toggleSubscript:()=>null==$?void 0:$.chain().focus().toggleSubscript().run(),insertImage:t=>null==$?void 0:$.chain().focus().setImage({src:t}).run()}})),[$]),$?t.jsxs(i.BikEditorShell,Object.assign({minHeight:j,maxHeight:R,style:L,className:I},{children:[t.jsx(n.EditorContent,{editor:$}),t.jsx(s.LinkBubbleMenu,{editor:$,renderLinkTooltip:null==k?void 0:k.renderTooltip})]})):null},a=o.forwardRef(u);a.displayName="BikEditor",exports.BikEditor=a;
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 u(t){return Object.entries(t).map((t=>{let[e,n]=t;return`${e.replace(/([A-Z])/g,(t=>`-${t.toLowerCase()}`))}:${n}`})).join(";")}const a=(a,d)=>{var m;const{initialContent:g,sections:v,features:h,disabled:f,maxCharacters:C,shortcuts:S,sendShortcut:p,mentions:x,slashCommands:k,link:b,onPaste:H,onReady:B,onChange:y,onSend:A,onFocus:E,onBlur:z,onSelectionChange:j,minHeight:R,maxHeight:L,style:F,className:I,editorClassName:M,editorStyle:T}=a,q=(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:""),O=o.useRef([]),P=o.useRef(!1),w=o.useRef(B);w.current=B;const U=o.useRef(y);U.current=y;const D=o.useRef(j);D.current=j;const _=o.useRef(E);_.current=E;const N=o.useRef(z);N.current=z;const $=n.useEditor({extensions:s.buildExtensions({features:h,placeholder:a.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:H,onSend:A,sendShortcut:p,shortcuts:S,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:q,editable:!f,immediatelyRender:!1,editorProps:{attributes:Object.assign(Object.assign({},M?{class:M}:{}),T?{style:u(T)}:{})},onUpdate:t=>{let{editor:e}=t;var n,o;null===(n=U.current)||void 0===n||n.call(U,l.extractContent(e)),null===(o=D.current)||void 0===o||o.call(D,l.extractActiveFormats(e))},onSelectionUpdate:t=>{let{editor:e}=t;var n;return null===(n=D.current)||void 0===n?void 0:n.call(D,l.extractActiveFormats(e))},onFocus:()=>{var t;return null===(t=_.current)||void 0===t?void 0:t.call(_)},onBlur:()=>{var t;return null===(t=N.current)||void 0===t?void 0:t.call(N)}});function V(t){$?t($):O.current.push(t)}return o.useEffect((()=>{var t;if($){if(O.current.length>0){O.current.splice(0).forEach((t=>t($)))}P.current||(P.current=!0,null===(t=w.current)||void 0===t||t.call(w))}}),[$]),o.useImperativeHandle(d,(()=>({focus:()=>V((t=>t.commands.focus())),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)))},insertAtEnd:t=>{const e=l.normalizeHtml(t);V((t=>t.commands.insertContentAt(t.state.doc.content.size,e)))},appendContent:t=>{const e=l.normalizeHtml(t);V((t=>t.commands.insertContentAt(t.state.doc.content.size-1,e)))},getContent:()=>$?l.extractContent($):{html:"",text:"",isEmpty:!0,characterCount:0},getCursorPosition:()=>{const{from:t,to:e}=$.state.selection;return{from:t,to:e}},insertAtPosition:(t,e)=>{const n=l.normalizeHtml(e);V((e=>e.commands.insertContentAt(t,n)))},getSelectedText:()=>{const{state:t}=$,{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==$?void 0:$.storage.characterCount)||void 0===t?void 0:t.characters)||void 0===e?void 0:e.call(t))&&void 0!==n?n:null==$?void 0:$.getText().length)&&void 0!==o?o:0,limit:null!=C?C:null}},getSectionContent:t=>l.extractSectionContent($,t),setSectionContent:(t,e)=>{const n=l.normalizeHtml(e);V((e=>l.setSectionContentInEditor(e,t,n)))},focusSection:t=>{V((e=>{if("body"===t)return void e.chain().focus().setTextSelection(1).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:()=>l.extractBodyContent($),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:()=>$?l.extractActiveFormats($):r.DEFAULT_FORMAT_STATE,actions:{toggleBold:()=>null==$?void 0:$.chain().focus().toggleBold().run(),toggleItalic:()=>null==$?void 0:$.chain().focus().toggleItalic().run(),toggleUnderline:()=>null==$?void 0:$.chain().focus().toggleUnderline().run(),toggleStrike:()=>null==$?void 0:$.chain().focus().toggleStrike().run(),toggleBulletList:()=>null==$?void 0:$.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>null==$?void 0:$.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>null==$?void 0:$.chain().focus().toggleBlockquote().run(),toggleCodeBlock:()=>null==$?void 0:$.chain().focus().toggleCodeBlock().run(),setTextAlign:t=>null==$?void 0:$.chain().focus().setTextAlign(t).run(),setFontFamily:t=>null==$?void 0:$.chain().focus().setFontFamily(t).run(),setFontSize:t=>null==$?void 0:$.chain().focus().setFontSize(t).run(),setColor:t=>null==$?void 0:$.chain().focus().setColor(t).run(),setHighlight:t=>null==$?void 0:$.chain().focus().toggleHighlight({color:t}).run(),unsetColor:()=>null==$?void 0:$.chain().focus().unsetColor().run(),unsetHighlight:()=>null==$?void 0:$.chain().focus().unsetHighlight().run(),setLink:(t,e)=>{$&&(void 0!==e?$.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():$.chain().focus().extendMarkRange("link").setLink({href:t}).run())},updateLink:t=>null==$?void 0:$.chain().focus().extendMarkRange("link").setLink({href:t}).run(),removeLink:()=>null==$?void 0:$.chain().focus().extendMarkRange("link").unsetLink().run(),insertEmoji:t=>null==$?void 0:$.chain().focus().insertContent(t).run(),insertVariable:t=>null==$?void 0:$.chain().focus().insertContent(`{{${t}}}`).run(),insertHtml:t=>null==$?void 0:$.commands.insertContent(t),undo:()=>null==$?void 0:$.chain().focus().undo().run(),redo:()=>null==$?void 0:$.chain().focus().redo().run(),canUndo:()=>{var t;return null!==(t=null==$?void 0:$.can().undo())&&void 0!==t&&t},canRedo:()=>{var t;return null!==(t=null==$?void 0:$.can().redo())&&void 0!==t&&t},toggleSuperscript:()=>null==$?void 0:$.chain().focus().toggleSuperscript().run(),toggleSubscript:()=>null==$?void 0:$.chain().focus().toggleSubscript().run(),insertImage:t=>null==$?void 0:$.chain().focus().setImage({src:t}).run()}})),[$]),$?t.jsxs(i.BikEditorShell,Object.assign({minHeight:R,maxHeight:L,style:F,className:I},{children:[t.jsx(n.EditorContent,{editor:$}),t.jsx(c.LinkBubbleMenu,{editor:$,renderLinkTooltip:null==b?void 0:b.renderTooltip})]})):null},d=o.forwardRef(a);d.displayName="BikEditor",exports.BikEditor=d;
@@ -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 r,useRef as l,useEffect as s,useImperativeHandle as c}from"react";import{BikEditorShell as u}from"./BikEditor.styles.js";import{buildSectionedContent as a,normalizeHtml as d,extractContent as m,extractActiveFormats as g,extractSectionContent as h,extractBodyContent as v,setSectionContentInEditor as f,findSectionEndPos as p,findSectionStartPos as C}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 b=r(((r,b)=>{var y;const{initialContent:B,sections:A,features:j,disabled:L,maxCharacters:E,shortcuts:F,sendShortcut:H,mentions:I,slashCommands:M,link:O,onPaste:T,onReady:w,onChange:R,onSend:U,onFocus:z,onBlur:D,onSelectionChange:P,minHeight:N,maxHeight:$,style:q,className:V,editorClassName:W,editorStyle:Z}=r,_=(null==A?void 0:A.length)?a(d(null!=B?B:""),A.map((n=>Object.assign(Object.assign({},n),{content:d(n.content)})))):d(null!=B?B:""),G=l([]),J=l(!1),K=l(w);K.current=w;const Q=l(R);Q.current=R;const X=l(P);X.current=P;const Y=l(z);Y.current=z;const nn=l(D);nn.current=D;const tn=o({extensions:S({features:j,placeholder:r.placeholder,maxCharacters:E,hasSections:(null!==(y=null==A?void 0:A.length)&&void 0!==y?y:0)>0,mentions:{agents:null==I?void 0:I.agents,teams:null==I?void 0:I.teams},slashCommands:null==M?void 0:M.items,onPaste:T,onSend:U,sendShortcut:H,shortcuts:F,onMentionSelected:null==I?void 0:I.onSelect,onSlashCommandSelected:null==M?void 0:M.onSelect,renderMentionItem:null==I?void 0:I.renderItem,renderMentionDropdown:null==I?void 0:I.renderDropdown,renderSlashCommandItem:null==M?void 0:M.renderItem,renderSlashCommandDropdown:null==M?void 0:M.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;var e,o;null===(e=Q.current)||void 0===e||e.call(Q,m(t)),null===(o=X.current)||void 0===o||o.call(X,g(t))},onSelectionUpdate:n=>{let{editor:t}=n;var e;return null===(e=X.current)||void 0===e?void 0:e.call(X,g(t))},onFocus:()=>{var n;return null===(n=Y.current)||void 0===n?void 0:n.call(Y)},onBlur:()=>{var n;return null===(n=nn.current)||void 0===n?void 0:n.call(nn)}});function en(n){tn?n(tn):G.current.push(n)}return s((()=>{var n;if(tn){if(G.current.length>0){G.current.splice(0).forEach((n=>n(tn)))}J.current||(J.current=!0,null===(n=K.current)||void 0===n||n.call(K))}}),[tn]),c(b,(()=>({focus:()=>en((n=>n.commands.focus())),blur:()=>en((n=>n.commands.blur())),clearContent:()=>en((n=>n.commands.clearContent(!0))),setContent:n=>{const t=d(n);en((n=>n.commands.setContent(t,{emitUpdate:!0})))},insertContent:n=>{const t=d(n);en((n=>n.commands.insertContent(t)))},insertAtStart:n=>{const t=d(n);en((n=>n.commands.insertContentAt(1,t)))},insertAtEnd:n=>{const t=d(n);en((n=>n.commands.insertContentAt(n.state.doc.content.size,t)))},appendContent:n=>{const t=d(n);en((n=>n.commands.insertContentAt(n.state.doc.content.size-1,t)))},getContent:()=>tn?m(tn):{html:"",text:"",isEmpty:!0,characterCount:0},getCursorPosition:()=>{const{from:n,to:t}=tn.state.selection;return{from:n,to:t}},insertAtPosition:(n,t)=>{const e=d(t);en((t=>t.commands.insertContentAt(n,e)))},getSelectedText:()=>{const{state:n}=tn,{from:t,to:o,empty:i}=n.selection;if(!i)return n.doc.textBetween(t,o," ");const r=n.schema.marks.link;if(r){const o=e(n.doc.resolve(t),r);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==tn?void 0:tn.storage.characterCount)||void 0===n?void 0:n.characters)||void 0===t?void 0:t.call(n))&&void 0!==e?e:null==tn?void 0:tn.getText().length)&&void 0!==o?o:0,limit:null!=E?E:null}},getSectionContent:n=>h(tn,n),setSectionContent:(n,t)=>{const e=d(t);en((t=>f(t,n,e)))},focusSection:n=>{en((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=>{en((t=>f(t,n,"<p></p>")))},getBodyContent:()=>v(tn),setBodyContent:n=>{const t=d(n);en((n=>f(n,"body",t)))},setBodyAndSections:(n,t)=>{const e=a(d(n),t.map((n=>({id:n.id,content:d(n.content)}))));en((n=>n.commands.setContent(e,{emitUpdate:!0})))},appendBodyContent:n=>{const t=d(n);en((n=>{const e=p(n,"body");n.commands.insertContentAt(e-1,t)}))},insertAtSectionStart:(n,t)=>{const e=d(t);en((t=>{const o=C(t,n);-1!==o&&t.commands.insertContentAt(o,e)}))},insertAtSectionEnd:(n,t)=>{const e=d(t);en((t=>{const o=p(t,n);t.commands.insertContentAt(o,e)}))},getActiveFormats:()=>g(tn),actions:{toggleBold:()=>null==tn?void 0:tn.chain().focus().toggleBold().run(),toggleItalic:()=>null==tn?void 0:tn.chain().focus().toggleItalic().run(),toggleUnderline:()=>null==tn?void 0:tn.chain().focus().toggleUnderline().run(),toggleStrike:()=>null==tn?void 0:tn.chain().focus().toggleStrike().run(),toggleBulletList:()=>null==tn?void 0:tn.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>null==tn?void 0:tn.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>null==tn?void 0:tn.chain().focus().toggleBlockquote().run(),toggleCodeBlock:()=>null==tn?void 0:tn.chain().focus().toggleCodeBlock().run(),setTextAlign:n=>null==tn?void 0:tn.chain().focus().setTextAlign(n).run(),setFontFamily:n=>null==tn?void 0:tn.chain().focus().setFontFamily(n).run(),setFontSize:n=>null==tn?void 0:tn.chain().focus().setFontSize(n).run(),setColor:n=>null==tn?void 0:tn.chain().focus().setColor(n).run(),setHighlight:n=>null==tn?void 0:tn.chain().focus().toggleHighlight({color:n}).run(),unsetColor:()=>null==tn?void 0:tn.chain().focus().unsetColor().run(),unsetHighlight:()=>null==tn?void 0:tn.chain().focus().unsetHighlight().run(),setLink:(n,t)=>{tn&&(void 0!==t?tn.chain().focus().extendMarkRange("link").command((e=>{let{tr:o,state:i}=e;const{from:r,to:l}=o.selection,s=i.schema.marks.link;return!!s&&(o.replaceWith(r,l,i.schema.text(t,[s.create({href:n})])),!0)})).run():tn.chain().focus().extendMarkRange("link").setLink({href:n}).run())},updateLink:n=>null==tn?void 0:tn.chain().focus().extendMarkRange("link").setLink({href:n}).run(),removeLink:()=>null==tn?void 0:tn.chain().focus().extendMarkRange("link").unsetLink().run(),insertEmoji:n=>null==tn?void 0:tn.chain().focus().insertContent(n).run(),insertVariable:n=>null==tn?void 0:tn.chain().focus().insertContent(`{{${n}}}`).run(),insertHtml:n=>null==tn?void 0:tn.commands.insertContent(n),undo:()=>null==tn?void 0:tn.chain().focus().undo().run(),redo:()=>null==tn?void 0:tn.chain().focus().redo().run(),canUndo:()=>{var n;return null!==(n=null==tn?void 0:tn.can().undo())&&void 0!==n&&n},canRedo:()=>{var n;return null!==(n=null==tn?void 0:tn.can().redo())&&void 0!==n&&n},toggleSuperscript:()=>null==tn?void 0:tn.chain().focus().toggleSuperscript().run(),toggleSubscript:()=>null==tn?void 0:tn.chain().focus().toggleSubscript().run(),insertImage:n=>null==tn?void 0:tn.chain().focus().setImage({src:n}).run()}})),[tn]),tn?n(u,Object.assign({minHeight:N,maxHeight:$,style:q,className:V},{children:[t(i,{editor:tn}),t(k,{editor:tn,renderLinkTooltip:null==O?void 0:O.renderTooltip})]})):null}));b.displayName="BikEditor";export{b 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 r,useRef as l,useEffect as s,useImperativeHandle as c}from"react";import{BikEditorShell as u}from"./BikEditor.styles.js";import{DEFAULT_FORMAT_STATE as a}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 x}from"./floating/LinkBubbleMenu.js";function y(n){return Object.entries(n).map((n=>{let[t,e]=n;return`${t.replace(/([A-Z])/g,(n=>`-${n.toLowerCase()}`))}:${e}`})).join(";")}const B=r(((r,B)=>{var b;const{initialContent:A,sections:j,features:L,disabled:E,maxCharacters:F,shortcuts:H,sendShortcut:I,mentions:M,slashCommands:O,link:T,onPaste:w,onReady:R,onChange:U,onSend:z,onFocus:D,onBlur:P,onSelectionChange:N,minHeight:$,maxHeight:q,style:V,className:W,editorClassName:Z,editorStyle:_}=r,G=(null==j?void 0:j.length)?d(m(null!=A?A:""),j.map((n=>Object.assign(Object.assign({},n),{content:m(n.content)})))):m(null!=A?A:""),J=l([]),K=l(!1),Q=l(R);Q.current=R;const X=l(U);X.current=U;const Y=l(N);Y.current=N;const nn=l(D);nn.current=D;const tn=l(P);tn.current=P;const en=o({extensions:k({features:L,placeholder:r.placeholder,maxCharacters:F,hasSections:(null!==(b=null==j?void 0:j.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:z,sendShortcut:I,shortcuts:H,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:G,editable:!E,immediatelyRender:!1,editorProps:{attributes:Object.assign(Object.assign({},Z?{class:Z}:{}),_?{style:y(_)}:{})},onUpdate:n=>{let{editor:t}=n;var e,o;null===(e=X.current)||void 0===e||e.call(X,g(t)),null===(o=Y.current)||void 0===o||o.call(Y,h(t))},onSelectionUpdate:n=>{let{editor:t}=n;var e;return null===(e=Y.current)||void 0===e?void 0:e.call(Y,h(t))},onFocus:()=>{var n;return null===(n=nn.current)||void 0===n?void 0:n.call(nn)},onBlur:()=>{var n;return null===(n=tn.current)||void 0===n?void 0:n.call(tn)}});function on(n){en?n(en):J.current.push(n)}return s((()=>{var n;if(en){if(J.current.length>0){J.current.splice(0).forEach((n=>n(en)))}K.current||(K.current=!0,null===(n=Q.current)||void 0===n||n.call(Q))}}),[en]),c(B,(()=>({focus:()=>on((n=>n.commands.focus())),blur:()=>on((n=>n.commands.blur())),clearContent:()=>on((n=>n.commands.clearContent(!0))),setContent:n=>{const t=m(n);on((n=>n.commands.setContent(t,{emitUpdate:!0})))},insertContent:n=>{const t=m(n);on((n=>n.commands.insertContent(t)))},insertAtStart:n=>{const t=m(n);on((n=>n.commands.insertContentAt(1,t)))},insertAtEnd:n=>{const t=m(n);on((n=>n.commands.insertContentAt(n.state.doc.content.size,t)))},appendContent:n=>{const t=m(n);on((n=>n.commands.insertContentAt(n.state.doc.content.size-1,t)))},getContent:()=>en?g(en):{html:"",text:"",isEmpty:!0,characterCount:0},getCursorPosition:()=>{const{from:n,to:t}=en.state.selection;return{from:n,to:t}},insertAtPosition:(n,t)=>{const e=m(t);on((t=>t.commands.insertContentAt(n,e)))},getSelectedText:()=>{const{state:n}=en,{from:t,to:o,empty:i}=n.selection;if(!i)return n.doc.textBetween(t,o," ");const r=n.schema.marks.link;if(r){const o=e(n.doc.resolve(t),r);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==en?void 0:en.storage.characterCount)||void 0===n?void 0:n.characters)||void 0===t?void 0:t.call(n))&&void 0!==e?e:null==en?void 0:en.getText().length)&&void 0!==o?o:0,limit:null!=F?F:null}},getSectionContent:n=>v(en,n),setSectionContent:(n,t)=>{const e=m(t);on((t=>p(t,n,e)))},focusSection:n=>{on((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=>{on((t=>p(t,n,"<p></p>")))},getBodyContent:()=>f(en),setBodyContent:n=>{const t=m(n);on((n=>p(n,"body",t)))},setBodyAndSections:(n,t)=>{const e=d(m(n),t.map((n=>({id:n.id,content:m(n.content)}))));on((n=>n.commands.setContent(e,{emitUpdate:!0})))},appendBodyContent:n=>{const t=m(n);on((n=>{const e=C(n,"body");n.commands.insertContentAt(e-1,t)}))},insertAtSectionStart:(n,t)=>{const e=m(t);on((t=>{const o=S(t,n);-1!==o&&t.commands.insertContentAt(o,e)}))},insertAtSectionEnd:(n,t)=>{const e=m(t);on((t=>{const o=C(t,n);t.commands.insertContentAt(o,e)}))},getActiveFormats:()=>en?h(en):a,actions:{toggleBold:()=>null==en?void 0:en.chain().focus().toggleBold().run(),toggleItalic:()=>null==en?void 0:en.chain().focus().toggleItalic().run(),toggleUnderline:()=>null==en?void 0:en.chain().focus().toggleUnderline().run(),toggleStrike:()=>null==en?void 0:en.chain().focus().toggleStrike().run(),toggleBulletList:()=>null==en?void 0:en.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>null==en?void 0:en.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>null==en?void 0:en.chain().focus().toggleBlockquote().run(),toggleCodeBlock:()=>null==en?void 0:en.chain().focus().toggleCodeBlock().run(),setTextAlign:n=>null==en?void 0:en.chain().focus().setTextAlign(n).run(),setFontFamily:n=>null==en?void 0:en.chain().focus().setFontFamily(n).run(),setFontSize:n=>null==en?void 0:en.chain().focus().setFontSize(n).run(),setColor:n=>null==en?void 0:en.chain().focus().setColor(n).run(),setHighlight:n=>null==en?void 0:en.chain().focus().toggleHighlight({color:n}).run(),unsetColor:()=>null==en?void 0:en.chain().focus().unsetColor().run(),unsetHighlight:()=>null==en?void 0:en.chain().focus().unsetHighlight().run(),setLink:(n,t)=>{en&&(void 0!==t?en.chain().focus().extendMarkRange("link").command((e=>{let{tr:o,state:i}=e;const{from:r,to:l}=o.selection,s=i.schema.marks.link;return!!s&&(o.replaceWith(r,l,i.schema.text(t,[s.create({href:n})])),!0)})).run():en.chain().focus().extendMarkRange("link").setLink({href:n}).run())},updateLink:n=>null==en?void 0:en.chain().focus().extendMarkRange("link").setLink({href:n}).run(),removeLink:()=>null==en?void 0:en.chain().focus().extendMarkRange("link").unsetLink().run(),insertEmoji:n=>null==en?void 0:en.chain().focus().insertContent(n).run(),insertVariable:n=>null==en?void 0:en.chain().focus().insertContent(`{{${n}}}`).run(),insertHtml:n=>null==en?void 0:en.commands.insertContent(n),undo:()=>null==en?void 0:en.chain().focus().undo().run(),redo:()=>null==en?void 0:en.chain().focus().redo().run(),canUndo:()=>{var n;return null!==(n=null==en?void 0:en.can().undo())&&void 0!==n&&n},canRedo:()=>{var n;return null!==(n=null==en?void 0:en.can().redo())&&void 0!==n&&n},toggleSuperscript:()=>null==en?void 0:en.chain().focus().toggleSuperscript().run(),toggleSubscript:()=>null==en?void 0:en.chain().focus().toggleSubscript().run(),insertImage:n=>null==en?void 0:en.chain().focus().setImage({src:n}).run()}})),[en]),en?n(u,Object.assign({minHeight:$,maxHeight:q,style:V,className:W},{children:[t(i,{editor:en}),t(x,{editor:en,renderLinkTooltip:null==T?void 0:T.renderTooltip})]})):null}));B.displayName="BikEditor";export{B as BikEditor};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.792-beta.3",
3
+ "version": "0.0.792-beta.4",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",