@bikdotai/bik-component-library 0.0.792-beta.0 → 0.0.792-beta.1

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"),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
+ "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:E,onSelectionChange:A,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(A);U.current=A;const D=o.useRef(z);D.current=z;const N=o.useRef(E);N.current=E;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;return null===(n=T.current)||void 0===n?void 0:n.call(T,r.extractContent(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 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.DEFAULT_FORMAT_STATE={bold:!1,italic:!1,underline:!1,strike:!1,bulletList:!1,orderedList:!1,blockquote:!1,codeBlock:!1,link:null,textAlign:"left",fontFamily:null,fontSize:null,color:null,highlight:null};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.DEFAULT_FORMAT_STATE={bold:!1,italic:!1,underline:!1,strike:!1,bulletList:!1,orderedList:!1,blockquote:!1,codeBlock:!1,link:null,textAlign:"left",fontFamily:null,fontSize:null,color:null,highlight:null,superscript:!1,subscript:!1};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function e(e,n){let i=e;for(const e of n)i+=t(e.id)+e.content;return i}function n(t){return o(t.getHTML())}function i(t){var e;if(!t)return"";return null!==(e=o(t).get("body"))&&void 0!==e?e:t}function o(t){const e=new Map,n=/<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g,i=[];let o;for(;null!==(o=n.exec(t));)i.push({id:o[1],index:o.index,endIndex:o.index+o[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 o=i[n].endIndex,r=n+1<i.length?i[n+1].index:t.length;e.set(i[n].id,t.slice(o,r))}return e}function r(t,e){var i;return function(t){var e;const n="undefined"!=typeof document?document.createElement("div"):null;n&&(n.innerHTML=t);const i=null!==(e=null==n?void 0:n.textContent)&&void 0!==e?e:"";return{html:t,text:i,isEmpty:!i.trim(),characterCount:i.length}}(null!==(i=n(t).get(e))&&void 0!==i?i:"")}exports.SECTION_DIVIDER_HTML=t,exports.buildSectionedContent=e,exports.extractActiveFormats=function(t){var e,n,i,o,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:t.isActive("link")?{href:null!==(e=t.getAttributes("link").href)&&void 0!==e?e:""}:null,textAlign:t.isActive({textAlign:"center"})?"center":t.isActive({textAlign:"right"})?"right":t.isActive({textAlign:"justify"})?"justify":"left",fontFamily:null!==(n=t.getAttributes("textStyle").fontFamily)&&void 0!==n?n:null,fontSize:null!==(i=t.getAttributes("textStyle").fontSize)&&void 0!==i?i:null,color:null!==(o=t.getAttributes("textStyle").color)&&void 0!==o?o:null,highlight:t.isActive("highlight")?null!==(r=t.getAttributes("highlight").color)&&void 0!==r?r:"default":null}},exports.extractAllSections=n,exports.extractAllSectionsFromHtml=o,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=function(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 o=!1,r=-1;return n.descendants(((t,n)=>-1===r&&(o?void("sectionDivider"===t.type.name&&(r=n)):("sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(o=!0),!1)))),-1!==r?r:i},exports.findSectionStartPos=function(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},exports.getBodyHtml=i,exports.getSectionsHtml=function(t){if(!t)return"";const e=i(t);return t.substring(e.length)},exports.normalizeHtml=function(t){return t.replace(/<p>\s*<br\s*\/?>\s*<\/p>/gi,"<p></p>")},exports.setSectionContentInEditor=function(t,i,o){var r;const l=n(t);l.set(i,o);const s=e(null!==(r=l.get("body"))&&void 0!==r?r:"",[...l.entries()].filter((t=>{let[e]=t;return"body"!==e})).map((t=>{let[e,n]=t;return{id:e,content:n}})));t.commands.setContent(s,{emitUpdate:!1})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function e(e,n){let i=e;for(const e of n)i+=t(e.id)+e.content;return i}function n(t){return o(t.getHTML())}function i(t){var e;if(!t)return"";return null!==(e=o(t).get("body"))&&void 0!==e?e:t}function o(t){const e=new Map,n=/<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g,i=[];let o;for(;null!==(o=n.exec(t));)i.push({id:o[1],index:o.index,endIndex:o.index+o[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 o=i[n].endIndex,r=n+1<i.length?i[n+1].index:t.length;e.set(i[n].id,t.slice(o,r))}return e}function r(t,e){var i;return function(t){var e;const n="undefined"!=typeof document?document.createElement("div"):null;n&&(n.innerHTML=t);const i=null!==(e=null==n?void 0:n.textContent)&&void 0!==e?e:"";return{html:t,text:i,isEmpty:!i.trim(),characterCount:i.length}}(null!==(i=n(t).get(e))&&void 0!==i?i:"")}exports.SECTION_DIVIDER_HTML=t,exports.buildSectionedContent=e,exports.extractActiveFormats=function(t){var e,n,i,o,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:t.isActive("link")?{href:null!==(e=t.getAttributes("link").href)&&void 0!==e?e:""}:null,textAlign:t.isActive({textAlign:"center"})?"center":t.isActive({textAlign:"right"})?"right":t.isActive({textAlign:"justify"})?"justify":"left",fontFamily:null!==(n=t.getAttributes("textStyle").fontFamily)&&void 0!==n?n:null,fontSize:null!==(i=t.getAttributes("textStyle").fontSize)&&void 0!==i?i:null,color:null!==(o=t.getAttributes("textStyle").color)&&void 0!==o?o: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.extractAllSections=n,exports.extractAllSectionsFromHtml=o,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=function(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 o=!1,r=-1;return n.descendants(((t,n)=>-1===r&&(o?void("sectionDivider"===t.type.name&&(r=n)):("sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(o=!0),!1)))),-1!==r?r:i},exports.findSectionStartPos=function(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},exports.getBodyHtml=i,exports.getSectionsHtml=function(t){if(!t)return"";const e=i(t);return t.substring(e.length)},exports.normalizeHtml=function(t){return t.replace(/<p>\s*<br\s*\/?>\s*<\/p>/gi,"<p></p>")},exports.setSectionContentInEditor=function(t,i,o){var r;const l=n(t);l.set(i,o);const s=e(null!==(r=l.get("body"))&&void 0!==r?r:"",[...l.entries()].filter((t=>{let[e]=t;return"body"!==e})).map((t=>{let[e,n]=t;return{id:e,content:n}})));t.commands.setContent(s,{emitUpdate:!1})};
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare const Menus: ({
2
3
  displayName: string;
3
4
  key: number;
@@ -297,6 +297,10 @@ export interface FormatState {
297
297
  color: string | null;
298
298
  /** Active highlight (background) colour, or null if none. */
299
299
  highlight: string | null;
300
+ /** True when the cursor/selection is in a superscript. */
301
+ superscript: boolean;
302
+ /** True when the cursor/selection is in a subscript. */
303
+ subscript: boolean;
300
304
  }
301
305
  export declare const DEFAULT_FORMAT_STATE: FormatState;
302
306
  /**
@@ -360,6 +364,12 @@ export interface EditorActions {
360
364
  redo: () => void;
361
365
  canUndo: () => boolean;
362
366
  canRedo: () => boolean;
367
+ /** Toggles superscript on the selection. Only works when richTypography is on. */
368
+ toggleSuperscript: () => void;
369
+ /** Toggles subscript on the selection. Only works when richTypography is on. */
370
+ toggleSubscript: () => void;
371
+ /** Inserts an inline image at the cursor. Only works when richTypography is on. */
372
+ insertImage: (src: string) => void;
363
373
  }
364
374
  /** Props passed to your renderLinkTooltip render prop. */
365
375
  export interface LinkTooltipProps {
@@ -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,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
+ 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;return null===(e=Q.current)||void 0===e?void 0:e.call(Q,m(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 +1 @@
1
- const l={bold:!1,italic:!1,underline:!1,strike:!1,bulletList:!1,orderedList:!1,blockquote:!1,codeBlock:!1,link:null,textAlign:"left",fontFamily:null,fontSize:null,color:null,highlight:null};export{l as DEFAULT_FORMAT_STATE};
1
+ const l={bold:!1,italic:!1,underline:!1,strike:!1,bulletList:!1,orderedList:!1,blockquote:!1,codeBlock:!1,link:null,textAlign:"left",fontFamily:null,fontSize:null,color:null,highlight:null,superscript:!1,subscript:!1};export{l as DEFAULT_FORMAT_STATE};
@@ -1 +1 @@
1
- function t(t){return t.replace(/<p>\s*<br\s*\/?>\s*<\/p>/gi,"<p></p>")}const e=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function n(t,n){let i=t;for(const t of n)i+=e(t.id)+t.content;return i}function i(t){return r(t.getHTML())}function l(t){var e;if(!t)return"";return null!==(e=r(t).get("body"))&&void 0!==e?e:t}function o(t){if(!t)return"";const e=l(t);return t.substring(e.length)}function r(t){const e=new Map,n=/<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g,i=[];let l;for(;null!==(l=n.exec(t));)i.push({id:l[1],index:l.index,endIndex:l.index+l[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 l=i[n].endIndex,o=n+1<i.length?i[n+1].index:t.length;e.set(i[n].id,t.slice(l,o))}return e}function c(t,e){var n;return function(t){var e;const n="undefined"!=typeof document?document.createElement("div"):null;n&&(n.innerHTML=t);const i=null!==(e=null==n?void 0:n.textContent)&&void 0!==e?e:"";return{html:t,text:i,isEmpty:!i.trim(),characterCount:i.length}}(null!==(n=i(t).get(e))&&void 0!==n?n:"")}function d(t,e,l){var o;const r=i(t);r.set(e,l);const c=n(null!==(o=r.get("body"))&&void 0!==o?o:"",[...r.entries()].filter((t=>{let[e]=t;return"body"!==e})).map((t=>{let[e,n]=t;return{id:e,content:n}})));t.commands.setContent(c,{emitUpdate:!1})}function s(t){return c(t,"body")}function u(t){var e,n,i,l,o;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:t.isActive("link")?{href:null!==(e=t.getAttributes("link").href)&&void 0!==e?e:""}:null,textAlign:t.isActive({textAlign:"center"})?"center":t.isActive({textAlign:"right"})?"right":t.isActive({textAlign:"justify"})?"justify":"left",fontFamily:null!==(n=t.getAttributes("textStyle").fontFamily)&&void 0!==n?n:null,fontSize:null!==(i=t.getAttributes("textStyle").fontSize)&&void 0!==i?i:null,color:null!==(l=t.getAttributes("textStyle").color)&&void 0!==l?l:null,highlight:t.isActive("highlight")?null!==(o=t.getAttributes("highlight").color)&&void 0!==o?o:"default":null}}function v(t){var e,n,i;return{html:t.getHTML(),text:t.getText(),isEmpty:t.isEmpty,characterCount:null!==(i=null===(n=null===(e=t.storage.characterCount)||void 0===e?void 0:e.characters)||void 0===n?void 0:n.call(e))&&void 0!==i?i:t.getText().length}}function a(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 f(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 l=!1,o=-1;return n.descendants(((t,n)=>-1===o&&(l?void("sectionDivider"===t.type.name&&(o=n)):("sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(l=!0),!1)))),-1!==o?o:i}export{e as SECTION_DIVIDER_HTML,n as buildSectionedContent,u as extractActiveFormats,i as extractAllSections,r as extractAllSectionsFromHtml,s as extractBodyContent,v as extractContent,c as extractSectionContent,f as findSectionEndPos,a as findSectionStartPos,l as getBodyHtml,o as getSectionsHtml,t as normalizeHtml,d as setSectionContentInEditor};
1
+ function t(t){return t.replace(/<p>\s*<br\s*\/?>\s*<\/p>/gi,"<p></p>")}const e=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function i(t,i){let n=t;for(const t of i)n+=e(t.id)+t.content;return n}function n(t){return o(t.getHTML())}function r(t){var e;if(!t)return"";return null!==(e=o(t).get("body"))&&void 0!==e?e:t}function l(t){if(!t)return"";const e=r(t);return t.substring(e.length)}function o(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,l=i+1<n.length?n[i+1].index:t.length;e.set(n[i].id,t.slice(r,l))}return e}function c(t,e){var i;return function(t){var e;const i="undefined"!=typeof document?document.createElement("div"):null;i&&(i.innerHTML=t);const n=null!==(e=null==i?void 0:i.textContent)&&void 0!==e?e:"";return{html:t,text:n,isEmpty:!n.trim(),characterCount:n.length}}(null!==(i=n(t).get(e))&&void 0!==i?i:"")}function s(t,e,r){var l;const o=n(t);o.set(e,r);const c=i(null!==(l=o.get("body"))&&void 0!==l?l:"",[...o.entries()].filter((t=>{let[e]=t;return"body"!==e})).map((t=>{let[e,i]=t;return{id:e,content:i}})));t.commands.setContent(c,{emitUpdate:!1})}function d(t){return c(t,"body")}function u(t){var e,i,n,r,l;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:t.isActive("link")?{href:null!==(e=t.getAttributes("link").href)&&void 0!==e?e:""}:null,textAlign:t.isActive({textAlign:"center"})?"center":t.isActive({textAlign:"right"})?"right":t.isActive({textAlign:"justify"})?"justify":"left",fontFamily:null!==(i=t.getAttributes("textStyle").fontFamily)&&void 0!==i?i:null,fontSize:null!==(n=t.getAttributes("textStyle").fontSize)&&void 0!==n?n:null,color:null!==(r=t.getAttributes("textStyle").color)&&void 0!==r?r:null,highlight:t.isActive("highlight")?null!==(l=t.getAttributes("highlight").color)&&void 0!==l?l:"default":null,superscript:t.isActive("superscript"),subscript:t.isActive("subscript")}}function v(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 a(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 f(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,l=-1;return i.descendants(((t,i)=>-1===l&&(r?void("sectionDivider"===t.type.name&&(l=i)):("sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(r=!0),!1)))),-1!==l?l:n}export{e as SECTION_DIVIDER_HTML,i as buildSectionedContent,u as extractActiveFormats,n as extractAllSections,o as extractAllSectionsFromHtml,d as extractBodyContent,v as extractContent,c as extractSectionContent,f as findSectionEndPos,a as findSectionStartPos,r as getBodyHtml,l as getSectionsHtml,t as normalizeHtml,s as setSectionContentInEditor};
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare const Menus: ({
2
3
  displayName: string;
3
4
  key: number;
@@ -297,6 +297,10 @@ export interface FormatState {
297
297
  color: string | null;
298
298
  /** Active highlight (background) colour, or null if none. */
299
299
  highlight: string | null;
300
+ /** True when the cursor/selection is in a superscript. */
301
+ superscript: boolean;
302
+ /** True when the cursor/selection is in a subscript. */
303
+ subscript: boolean;
300
304
  }
301
305
  export declare const DEFAULT_FORMAT_STATE: FormatState;
302
306
  /**
@@ -360,6 +364,12 @@ export interface EditorActions {
360
364
  redo: () => void;
361
365
  canUndo: () => boolean;
362
366
  canRedo: () => boolean;
367
+ /** Toggles superscript on the selection. Only works when richTypography is on. */
368
+ toggleSuperscript: () => void;
369
+ /** Toggles subscript on the selection. Only works when richTypography is on. */
370
+ toggleSubscript: () => void;
371
+ /** Inserts an inline image at the cursor. Only works when richTypography is on. */
372
+ insertImage: (src: string) => void;
363
373
  }
364
374
  /** Props passed to your renderLinkTooltip render prop. */
365
375
  export interface LinkTooltipProps {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.792-beta.0",
3
+ "version": "0.0.792-beta.1",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",