@bikdotai/bik-component-library 0.0.788-beta.5 → 0.0.788-beta.7
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.
- package/dist/cjs/editor/BikEditor.js +1 -1
- package/dist/cjs/editor/extensions/buildExtensions.js +1 -1
- package/dist/cjs/src/editor/BikEditor.types.d.ts +27 -0
- package/dist/esm/editor/BikEditor.js +1 -1
- package/dist/esm/editor/extensions/buildExtensions.js +1 -1
- package/dist/esm/src/editor/BikEditor.types.d.ts +27 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react/jsx-runtime"),e=require("../node_modules/@tiptap/core/dist/index.js"),t=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[e,t]=n;return`${e.replace(/([A-Z])/g,(n=>`-${n.toLowerCase()}`))}:${t}`})).join(";")}const a=(a,c)=>{var u;const{initialContent:m,sections:g,features:v,disabled:h,maxCharacters:f,shortcuts:C,sendShortcut:S,mentions:p,slashCommands:k,link:x,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=t.useEditor({extensions:r.buildExtensions({features:v,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==k?void 0:k.items,onPaste:H,onSend:B,sendShortcut:S,shortcuts:C,onMentionSelected:null==p?void 0:p.onSelect,onSlashCommandSelected:null==k?void 0:k.onSelect,renderMentionItem:null==p?void 0:p.renderItem,renderMentionDropdown:null==p?void 0:p.renderDropdown,renderSlashCommandItem:null==k?void 0:k.renderItem,renderSlashCommandDropdown:null==k?void 0:k.renderDropdown}),content:q,editable:!h,immediatelyRender:!1,editorProps:{attributes:Object.assign(Object.assign({},I?{class:I}:{}),M?{style:d(M)}:{})},onUpdate:n=>{let{editor:e}=n;return null==b?void 0:b(l.extractContent(e))},onSelectionUpdate:n=>{let{editor:e}=n;return null==A?void 0:A(l.extractActiveFormats(e))},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:()=>l.extractContent(O),getCursorPosition:()=>{const{from:n,to:e}=O.state.selection;return{from:n,to:e}},insertAtPosition:(n,e)=>{O&&O.commands.insertContentAt(n,e)},getSelectedText:()=>{const{state:n}=O,{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.getMarkRange(n.doc.resolve(t),l);if(o)return n.doc.textBetween(o.from,o.to," ")}return""},getCharacterCount:()=>{var n,e,t,o;return{count:null!==(o=null!==(t=null===(e=null===(n=null==O?void 0:O.storage.characterCount)||void 0===n?void 0:n.characters)||void 0===e?void 0:e.call(n))&&void 0!==t?t:null==O?void 0:O.getText().length)&&void 0!==o?o:0,limit:null!=f?f:null}},getSectionContent:n=>l.extractSectionContent(O,n),setSectionContent:(n,e)=>{O&&l.setSectionContentInEditor(O,n,l.normalizeHtml(e))},focusSection:n=>{if(!O)return;if("body"===n)return void O.chain().focus().setTextSelection(1).run();let e=-1;O.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&&O.chain().focus().setTextSelection(e).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,e)=>{if(!O)return;const t=l.buildSectionedContent(l.normalizeHtml(n),e.map((n=>({id:n.id,content:l.normalizeHtml(n.content)}))));O.commands.setContent(t,{emitUpdate:!1})},appendBodyContent:n=>{if(!O)return;const e=l.normalizeHtml(n),t=l.findSectionEndPos(O,"body");O.commands.insertContentAt(t-1,e)},insertAtSectionStart:(n,e)=>{if(!O)return;const t=l.findSectionStartPos(O,n);-1!==t&&O.commands.insertContentAt(t,l.normalizeHtml(e))},insertAtSectionEnd:(n,e)=>{if(!O)return;const t=l.findSectionEndPos(O,n);O.commands.insertContentAt(t,l.normalizeHtml(e))},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,e)=>{O&&(void 0!==e?O.chain().focus().extendMarkRange("link").command((t=>{let{tr:o,state:i}=t;const{from:l,to:r}=o.selection,s=i.schema.marks.link;return!!s&&(o.replaceWith(l,r,i.schema.text(e,[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(t.EditorContent,{editor:O}),n.jsx(s.LinkBubbleMenu,{editor:O,renderLinkTooltip:null==x?void 0:x.renderTooltip})]})):null},c=o.forwardRef(a);c.displayName="BikEditor",exports.BikEditor=c;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@tiptap/extension-character-count"),n=require("@tiptap/extension-color"),t=require("@tiptap/extension-font-family"),i=require("@tiptap/extension-highlight"),o=require("@tiptap/extension-image"),r=require("@tiptap/extension-link"),a=require("@tiptap/extension-placeholder"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@tiptap/extension-character-count"),n=require("@tiptap/extension-color"),t=require("@tiptap/extension-font-family"),i=require("@tiptap/extension-highlight"),o=require("@tiptap/extension-image"),r=require("@tiptap/extension-link"),a=require("@tiptap/extension-placeholder"),l=require("@tiptap/extension-subscript"),s=require("@tiptap/extension-superscript"),d=require("@tiptap/extension-text-align"),u=require("@tiptap/extension-text-style"),p=require("@tiptap/extension-underline"),c=require("@tiptap/starter-kit"),x=require("./FontSizeExtension.js"),m=require("./mention/MentionExtension.js"),f=require("./paste/PasteExtension.js"),h=require("./plainClipboard/PlainClipboardExtension.js"),v=require("./sectionDivider/SectionDividerNode.js"),S=require("./sendShortcut/SendShortcutExtension.js"),g=require("./slashCommand/SlashCommandExtension.js"),q=require("./variable/VariableDecorationExtension.js");function b(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var E=b(e),C=b(n),M=b(t),k=b(i),P=b(o),j=b(r),y=b(a),D=b(l),T=b(s),w=b(d),I=b(p),O=b(c);exports.buildExtensions=function(e){var n,t,i,o,r,a,l,s,d,p,c,b;const z=null!==(t=null===(n=e.features)||void 0===n?void 0:n.richPaste)&&void 0!==t&&t,A=null!==(o=null===(i=e.features)||void 0===i?void 0:i.richTypography)&&void 0!==o&&o,F=null===(r=e.features)||void 0===r?void 0:r.allowedMarks,N=e=>!F||F.includes(e);return[...[O.default.configure({link:!1,underline:!1,bold:!!N("bold")&&{},italic:!!N("italic")&&{},strike:!!N("strike")&&{},code:!!N("code")&&{}}),...N("underline")?[I.default]:[],j.default.extend({addPasteRules:()=>[],addInputRules:()=>[]}).configure({openOnClick:!1,autolink:!1,linkOnPaste:!1,HTMLAttributes:{rel:"noopener noreferrer",class:"bik-link"}}),u.TextStyle,y.default.configure({placeholder:null!==(a=e.placeholder)&&void 0!==a?a:"Type a message..."}),...e.onPaste?[f.PasteExtension.configure({onPaste:e.onPaste})]:[],...z?[]:[h.PlainClipboardExtension],S.SendShortcutExtension.configure({onSend:e.onSend,sendShortcut:e.sendShortcut,extraShortcuts:null!==(l=e.shortcuts)&&void 0!==l?l:[]}),q.VariableDecorationExtension,...e.maxCharacters?[E.default.configure({limit:e.maxCharacters})]:[],v.SectionDividerNode],...[...(null===(d=null===(s=e.mentions)||void 0===s?void 0:s.agents)||void 0===d?void 0:d.length)?[m.buildAgentMentionExtension(e.mentions.agents,e.onMentionSelected,e.renderMentionItem,e.renderMentionDropdown)]:[],...(null===(c=null===(p=e.mentions)||void 0===p?void 0:p.teams)||void 0===c?void 0:c.length)?[m.buildTeamMentionExtension(e.mentions.teams,e.onMentionSelected,e.renderMentionItem,e.renderMentionDropdown)]:[],...(null===(b=e.slashCommands)||void 0===b?void 0:b.length)?[g.buildSlashCommandExtension(e.slashCommands,e.onSlashCommandSelected,e.renderSlashCommandItem,e.renderSlashCommandDropdown)]:[]],...A?[C.default,k.default.configure({multicolor:!0}),M.default,x.FontSizeExtension,w.default.configure({types:["heading","paragraph"]}),D.default,T.default,P.default]:[C.default]]};
|
|
@@ -26,6 +26,17 @@ export interface EditorFeatures {
|
|
|
26
26
|
richPaste?: boolean;
|
|
27
27
|
/** Enable font family, font size, text alignment, highlight, subscript, superscript, and image. Default: `false`. */
|
|
28
28
|
richTypography?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Restrict which inline marks are active in the editor.
|
|
31
|
+
* When set, only the listed marks are registered — all others are disabled
|
|
32
|
+
* (no rendering, no keyboard shortcuts, no paste preservation).
|
|
33
|
+
* Omit to allow all marks (default).
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // LiveChat: bold only, no italic / underline / strike
|
|
37
|
+
* features={{ allowedMarks: ['bold'] }}
|
|
38
|
+
*/
|
|
39
|
+
allowedMarks?: Array<'bold' | 'italic' | 'strike' | 'underline' | 'code'>;
|
|
29
40
|
}
|
|
30
41
|
/**
|
|
31
42
|
* A named content section placed below the main body, separated by an invisible divider.
|
|
@@ -478,6 +489,22 @@ export interface BikEditorRef {
|
|
|
478
489
|
getBodyContent: () => EditorSnapshot;
|
|
479
490
|
/** Shorthand for `setSectionContent('body', html)`. */
|
|
480
491
|
setBodyContent: (html: string) => void;
|
|
492
|
+
/**
|
|
493
|
+
* Atomically sets the body AND all sections in a single editor update.
|
|
494
|
+
* Sections are laid out in the exact order supplied — use this instead of
|
|
495
|
+
* multiple `setSectionContent()` calls whenever order matters (e.g. forward
|
|
496
|
+
* mail where signature must appear before the forwarded thread).
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ref.current?.setBodyAndSections('<p></p>', [
|
|
500
|
+
* { id: 'signature', content: '<p>Alice</p>' },
|
|
501
|
+
* { id: 'forwarded', content: '<p>--- Forwarded ---</p>' },
|
|
502
|
+
* ]);
|
|
503
|
+
*/
|
|
504
|
+
setBodyAndSections: (body: string, sections: Array<{
|
|
505
|
+
id: string;
|
|
506
|
+
content: string;
|
|
507
|
+
}>) => void;
|
|
481
508
|
/**
|
|
482
509
|
* Appends HTML to the end of the body section without moving the cursor.
|
|
483
510
|
* Ideal for streaming AI-generated content — call repeatedly with each chunk.
|
|
@@ -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
|
|
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:b,features:y,disabled:A,maxCharacters:j,shortcuts:L,sendShortcut:F,mentions:H,slashCommands:M,link:O,onPaste:T,onChange:w,onSend:E,onFocus:I,onBlur:U,onSelectionChange:R,minHeight:z,maxHeight:D,style:P,className:N,editorClassName:$,editorStyle:q}=l,V=(null==b?void 0:b.length)?d(c(null!=B?B:""),b.map((n=>Object.assign(Object.assign({},n),{content:c(n.content)})))):c(null!=B?B:""),W=o({extensions:C({features:y,placeholder:l.placeholder,maxCharacters:j,hasSections:(null!==(x=null==b?void 0:b.length)&&void 0!==x?x:0)>0,mentions:{agents:null==H?void 0:H.agents,teams:null==H?void 0:H.teams},slashCommands:null==M?void 0:M.items,onPaste:T,onSend:E,sendShortcut:F,shortcuts:L,onMentionSelected:null==H?void 0:H.onSelect,onSlashCommandSelected:null==M?void 0:M.onSelect,renderMentionItem:null==H?void 0:H.renderItem,renderMentionDropdown:null==H?void 0:H.renderDropdown,renderSlashCommandItem:null==M?void 0:M.renderItem,renderSlashCommandDropdown:null==M?void 0:M.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==w?void 0:w(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:()=>u(W),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:!1})},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==O?void 0:O.renderTooltip})]})):null}));k.displayName="BikEditor";export{k as BikEditor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import o from"@tiptap/extension-character-count";import e from"@tiptap/extension-color";import
|
|
1
|
+
import o from"@tiptap/extension-character-count";import e from"@tiptap/extension-color";import t from"@tiptap/extension-font-family";import n from"@tiptap/extension-highlight";import i from"@tiptap/extension-image";import r from"@tiptap/extension-link";import s from"@tiptap/extension-placeholder";import a from"@tiptap/extension-subscript";import l from"@tiptap/extension-superscript";import m from"@tiptap/extension-text-align";import{TextStyle as p}from"@tiptap/extension-text-style";import d from"@tiptap/extension-underline";import u from"@tiptap/starter-kit";import{FontSizeExtension as c}from"./FontSizeExtension.js";import{buildAgentMentionExtension as f,buildTeamMentionExtension as h}from"./mention/MentionExtension.js";import{PasteExtension as x}from"./paste/PasteExtension.js";import{PlainClipboardExtension as v}from"./plainClipboard/PlainClipboardExtension.js";import{SectionDividerNode as g}from"./sectionDivider/SectionDividerNode.js";import{SendShortcutExtension as S}from"./sendShortcut/SendShortcutExtension.js";import{buildSlashCommandExtension as C}from"./slashCommand/SlashCommandExtension.js";import{VariableDecorationExtension as k}from"./variable/VariableDecorationExtension.js";function b(b){var M,j,P,E,y,D,w,I,T,O,R,z;const A=null!==(j=null===(M=b.features)||void 0===M?void 0:M.richPaste)&&void 0!==j&&j,F=null!==(E=null===(P=b.features)||void 0===P?void 0:P.richTypography)&&void 0!==E&&E,H=null===(y=b.features)||void 0===y?void 0:y.allowedMarks,L=o=>!H||H.includes(o);return[...[u.configure({link:!1,underline:!1,bold:!!L("bold")&&{},italic:!!L("italic")&&{},strike:!!L("strike")&&{},code:!!L("code")&&{}}),...L("underline")?[d]:[],r.extend({addPasteRules:()=>[],addInputRules:()=>[]}).configure({openOnClick:!1,autolink:!1,linkOnPaste:!1,HTMLAttributes:{rel:"noopener noreferrer",class:"bik-link"}}),p,s.configure({placeholder:null!==(D=b.placeholder)&&void 0!==D?D:"Type a message..."}),...b.onPaste?[x.configure({onPaste:b.onPaste})]:[],...A?[]:[v],S.configure({onSend:b.onSend,sendShortcut:b.sendShortcut,extraShortcuts:null!==(w=b.shortcuts)&&void 0!==w?w:[]}),k,...b.maxCharacters?[o.configure({limit:b.maxCharacters})]:[],g],...[...(null===(T=null===(I=b.mentions)||void 0===I?void 0:I.agents)||void 0===T?void 0:T.length)?[f(b.mentions.agents,b.onMentionSelected,b.renderMentionItem,b.renderMentionDropdown)]:[],...(null===(R=null===(O=b.mentions)||void 0===O?void 0:O.teams)||void 0===R?void 0:R.length)?[h(b.mentions.teams,b.onMentionSelected,b.renderMentionItem,b.renderMentionDropdown)]:[],...(null===(z=b.slashCommands)||void 0===z?void 0:z.length)?[C(b.slashCommands,b.onSlashCommandSelected,b.renderSlashCommandItem,b.renderSlashCommandDropdown)]:[]],...F?[e,n.configure({multicolor:!0}),t,c,m.configure({types:["heading","paragraph"]}),a,l,i]:[e]]}export{b as buildExtensions};
|
|
@@ -26,6 +26,17 @@ export interface EditorFeatures {
|
|
|
26
26
|
richPaste?: boolean;
|
|
27
27
|
/** Enable font family, font size, text alignment, highlight, subscript, superscript, and image. Default: `false`. */
|
|
28
28
|
richTypography?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Restrict which inline marks are active in the editor.
|
|
31
|
+
* When set, only the listed marks are registered — all others are disabled
|
|
32
|
+
* (no rendering, no keyboard shortcuts, no paste preservation).
|
|
33
|
+
* Omit to allow all marks (default).
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // LiveChat: bold only, no italic / underline / strike
|
|
37
|
+
* features={{ allowedMarks: ['bold'] }}
|
|
38
|
+
*/
|
|
39
|
+
allowedMarks?: Array<'bold' | 'italic' | 'strike' | 'underline' | 'code'>;
|
|
29
40
|
}
|
|
30
41
|
/**
|
|
31
42
|
* A named content section placed below the main body, separated by an invisible divider.
|
|
@@ -478,6 +489,22 @@ export interface BikEditorRef {
|
|
|
478
489
|
getBodyContent: () => EditorSnapshot;
|
|
479
490
|
/** Shorthand for `setSectionContent('body', html)`. */
|
|
480
491
|
setBodyContent: (html: string) => void;
|
|
492
|
+
/**
|
|
493
|
+
* Atomically sets the body AND all sections in a single editor update.
|
|
494
|
+
* Sections are laid out in the exact order supplied — use this instead of
|
|
495
|
+
* multiple `setSectionContent()` calls whenever order matters (e.g. forward
|
|
496
|
+
* mail where signature must appear before the forwarded thread).
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ref.current?.setBodyAndSections('<p></p>', [
|
|
500
|
+
* { id: 'signature', content: '<p>Alice</p>' },
|
|
501
|
+
* { id: 'forwarded', content: '<p>--- Forwarded ---</p>' },
|
|
502
|
+
* ]);
|
|
503
|
+
*/
|
|
504
|
+
setBodyAndSections: (body: string, sections: Array<{
|
|
505
|
+
id: string;
|
|
506
|
+
content: string;
|
|
507
|
+
}>) => void;
|
|
481
508
|
/**
|
|
482
509
|
* Appends HTML to the end of the body section without moving the cursor.
|
|
483
510
|
* Ideal for streaming AI-generated content — call repeatedly with each chunk.
|