@dialpad/dialtone 9.126.5 → 9.126.6

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,10 +1,10 @@
1
1
  "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("../../node_modules/@tiptap/vue-3.cjs"),u=require("@tiptap/core"),I=require("@tiptap/extension-blockquote"),q=require("@tiptap/extension-code-block"),$=require("@tiptap/extension-code"),A=require("@tiptap/extension-document"),N=require("@tiptap/extension-hard-break"),P=require("@tiptap/extension-paragraph"),j=require("@tiptap/extension-placeholder"),H=require("@tiptap/extension-bold"),F=require("@tiptap/extension-bullet-list"),K=require("@tiptap/extension-italic"),W=require("@tiptap/extension-link"),U=require("@tiptap/extension-list-item"),z=require("@tiptap/extension-ordered-list"),X=require("@tiptap/extension-strike"),J=require("@tiptap/extension-underline"),Y=require("@tiptap/extension-text"),G=require("@tiptap/extension-text-align"),Q=require("@tiptap/extension-history"),Z=require("@tiptap/extension-text-style"),ee=require("@tiptap/extension-color"),te=require("@tiptap/extension-font-family"),g=require("@tiptap/pm/state"),ne=require("@tiptap/suggestion"),D=require("regex-combined-emojis"),o=require("vue"),h=require("../../_plugin-vue_export-helper-BRilXfQE.cjs"),V=require("../emoji/emoji.cjs"),f=require("../../common/emoji/index.cjs"),oe=require("@dialpad/dialtone-emojis"),re=require("../list-item/list-item.cjs"),x=require("../stack/stack.cjs"),b=require("tippy.js"),k=require("../../common/utils/index.cjs"),ie=require("@tiptap/extension-image"),B=require("@tiptap/extension-mention"),O=require("../link/link.cjs"),C=require("./rich-text-editor-constants.cjs"),se=require("../avatar/avatar.cjs"),ae=require("@dialpad/dialtone-icons/vue3/hash"),ce=require("@dialpad/dialtone-icons/vue3/lock"),le=require("deep-equal"),de=require("../button/button.cjs"),ue={compatConfig:{MODE:3},name:"EmojiComponent",components:{NodeViewWrapper:d.NodeViewWrapper,DtEmoji:V.default},props:d.nodeViewProps};function me(e,t,r,n,i,s){const a=o.resolveComponent("dt-emoji"),c=o.resolveComponent("node-view-wrapper");return o.openBlock(),o.createBlock(c,{class:"d-d-inline-block d-va-bottom d-lh0"},{default:o.withCtx(()=>[o.createVNode(a,{size:"500",code:e.node.attrs.code},null,8,["code"])]),_:1})}const he=h._(ue,[["render",me]]),pe={compatConfig:{MODE:3},name:"SuggestionList",components:{DtListItem:re.default},props:{items:{type:Array,required:!0},command:{type:Function,required:!0},itemComponent:{type:Object,required:!0},itemType:{type:String,required:!0}},data(){return{selectedIndex:0}},watch:{items(){this.selectedIndex=0}},methods:{onKeyDown({event:e}){return e.key==="ArrowUp"?(this.upHandler(),!0):e.key==="ArrowDown"?(this.downHandler(),!0):e.key==="Enter"||e.key==="Tab"?(this.selectHandler(),!0):!1},upHandler(){this.selectedIndex=(this.selectedIndex+this.items.length-1)%this.items.length,this.scrollActiveElementIntoView()},downHandler(){this.selectedIndex=(this.selectedIndex+1)%this.items.length,this.scrollActiveElementIntoView()},async scrollActiveElementIntoView(){await this.$nextTick();const e=this.$refs.suggestionList.querySelector(".d-list-item--highlighted");e&&e.scrollIntoView({behaviour:"smooth",block:"center"})},selectHandler(){this.selectItem(this.selectedIndex)},selectItem(e){const t=this.items[e];switch(this.itemType){case"emoji":this.command(t);return;case"mention":this.command({name:t.name,id:t.id,avatarSrc:t.avatarSrc});break;case"channel":this.command({name:t.name,id:t.id});break;case"slash-command":this.command({command:t.command});break}}}},fe={class:"d-popover__dialog d-suggestion-list__container"},ge={ref:"suggestionList",class:"d-suggestion-list"};function _e(e,t,r,n,i,s){const a=o.resolveComponent("dt-list-item");return o.openBlock(),o.createElementBlock("div",fe,[o.withDirectives(o.createElementVNode("ul",ge,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(r.items,(c,l)=>(o.openBlock(),o.createBlock(a,{key:c.id,class:o.normalizeClass(["d-suggestion-list__item",{"d-list-item--highlighted":l===i.selectedIndex}]),"navigation-type":"arrow-keys",onClick:m=>s.selectItem(l),onKeydown:o.withModifiers(s.onKeyDown,["prevent"])},{default:o.withCtx(()=>[(o.openBlock(),o.createBlock(o.resolveDynamicComponent(r.itemComponent),{item:c},null,8,["item"]))]),_:2},1032,["class","onClick","onKeydown"]))),128))],512),[[o.vShow,r.items.length]])])}const E=h._(pe,[["render",_e]]),ke={compatConfig:{MODE:3},name:"EmojiSuggestion",components:{DtEmoji:V.default,DtStack:x.default},props:{item:{type:Object,required:!0}}};function we(e,t,r,n,i,s){const a=o.resolveComponent("dt-emoji"),c=o.resolveComponent("dt-stack");return o.openBlock(),o.createBlock(c,{direction:"row",gap:"400"},{default:o.withCtx(()=>[o.createVNode(a,{size:"200",code:r.item.code},null,8,["code"]),o.createTextVNode(" "+o.toDisplayString(r.item.code),1)]),_:1})}const ye=h._(ke,[["render",we]]),T={name:"hideOnEsc",defaultValue:!0,fn({hide:e}){function t(r){r.keyCode===27&&e()}return{onShow(){document.addEventListener("keydown",t)},onHide(){document.removeEventListener("keydown",t)}}}},Ce=20,xe={items:({query:e})=>{if(e.length<2)return[];const t=Object.values(oe.emojisIndexed);return e=e.toLowerCase(),t.filter(n=>[n.name,n.shortname.replaceAll(":",""),...n.keywords].some(i=>i.startsWith(e))).splice(0,Ce).map(n=>({code:n.shortname}))},command:({editor:e,range:t,props:r})=>{var s,a;const n=e.view.state.selection.$to.nodeAfter;((s=n==null?void 0:n.text)==null?void 0:s.startsWith(" "))&&(t.to+=1),e.chain().focus().insertContentAt(t,[{type:"emoji",attrs:r}]).run(),(a=window.getSelection())==null||a.collapseToEnd()},render:()=>{let e,t,r=!1;return{onStart:n=>{e=new d.VueRenderer(E,{props:{itemComponent:o.markRaw(ye),itemType:"emoji",...n},editor:n.editor}),n.clientRect&&(t=b("body",{getReferenceClientRect:n.clientRect,appendTo:()=>document.body,content:e.element,showOnCreate:!1,onShow:()=>{r=!0},onHidden:()=>{r=!1},interactive:!0,trigger:"manual",placement:"top-start",zIndex:650,plugins:[T]}),n.items.length>0&&(t==null||t[0].show()))},onUpdate(n){e==null||e.updateProps(n),n.items.length>0?t==null||t[0].show():t==null||t[0].hide(),t==null||t[0].setProps({getReferenceClientRect:n.clientRect})},onKeyDown(n){var i;if(r)return(i=e==null?void 0:e.ref)==null?void 0:i.onKeyDown(n)},onExit(){t==null||t[0].destroy(),t=null,e==null||e.destroy(),e=null}}}},be=/(:\w+:)$/,Ee=new RegExp(D.emojiPattern+"$"),Te=e=>{if(e&&f.codeToEmojiData(e[0]))return{text:e[2]||e[0]}},Se=e=>[...e.matchAll(f.emojiShortCodeRegex)].filter(r=>f.codeToEmojiData(r[0])).map(r=>({index:r.index,text:r[0],match:r})),ve=u.Node.create({name:"emoji",addOptions(){return{HTMLAttributes:{}}},group:"inline",inline:!0,selectable:!1,atom:!0,addNodeView(){return d.VueNodeViewRenderer(he)},addAttributes(){return{code:{default:null}}},parseHTML(){return[{tag:"emoji-component"}]},renderText({node:e}){return f.stringToUnicode(f.codeToEmojiData(e.attrs.code).unicode_output)},renderHTML({HTMLAttributes:e}){return["emoji-component",u.mergeAttributes(this.options.HTMLAttributes,e)]},addInputRules(){return[new u.InputRule({find:e=>{const t=e.match(be)||e.match(Ee);if(t)return Te(t)},handler:({state:e,range:t,match:r,commands:n,chain:i,can:s})=>{const{tr:a}=e,c=t.from,l=t.to;a.replaceWith(c,l,this.type.create({code:r[0]}))}})]},addPasteRules(){return[u.nodePasteRule({find:Se,type:this.type,getAttributes(e){return{code:e[0]}}}),u.nodePasteRule({find:f.emojiRegex,type:this.type,getAttributes(e){return{code:e[0]}}})]},addProseMirrorPlugins(){return[ne({char:":",pluginKey:new g.PluginKey("emoji"),editor:this.editor,...this.options.suggestion,...xe})]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.command(({tr:e,state:t})=>{let r=!1;const{selection:n}=t,{empty:i,anchor:s}=n;return i?(t.doc.nodesBetween(s-1,s,(a,c)=>{if(a.type.name===this.name)return r=!0,e.insertText("",c,c+a.nodeSize),!1}),r):!1})}}});function Be(e,t,r=()=>!0){const n=[];t.lastIndex=0;let i;for(;i=t.exec(e);)r(e,i)&&n.push(i);return n}function Re(e,t){return!["#","@"].includes(e.charAt(t.index))&&!["#","@"].includes(e.charAt(t.index-1))}function Le(e){const t=new RegExp("(?:"+[`[!?.,:;'"]`,"(?:&|&amp;)(?:lt|gt|quot|apos|raquo|laquo|rsaquo|lsaquo);)+$"].join("|"),"g");return e.replace(t,"")}function Pe(e,t){const r=e.slice(0,t+1).search(/\S+\s*$/),n=e.slice(t).search(/\s/);if(n<0){const i=e.slice(r);return{text:i,from:r,to:r+i.length}}return{text:e.slice(r,n+t),from:r,to:n+t}}function v(e,t,r,n){const i=Pe(e,t);if(n.lastIndex=0,!n.test(i.text))return i;const s=r==="left"?i.from-1:i.to+1;return s<=0||s>=e.length||s===t?i:v(e,s,r,n)}function De(e,t,r,n){const i=Math.max(e.from-1,0),s=Math.min(e.to+1,t.content.size),a=u.getMarksBetween(i,s,t);for(const c of a)c.mark.type===n&&r.removeMark(c.from,c.to,n)}const R=k.getPhoneNumberRegex(1,15);function L(e,t,r,n,i,s){if(!e)return;let a=r-t-1;a=a<0?0:a;const c=n-t,l=v(e,a,"left",R),m=v(e,c,"right",R),p=e.slice(l.from,m.to);Be(p,k.linkRegex,Re).forEach(S=>{const _=Le(S[0]),y=t+l.from+S.index+1,M=y+_.length;i.addMark(y,M,s.create())})}function Ve(e){let t=!1;return new g.Plugin({key:new g.PluginKey("autolink"),appendTransaction:(r,n,i)=>{const s=r.some(p=>p.docChanged)&&!n.doc.eq(i.doc);if(t&&!s)return;const{tr:a}=i,{textContent:c}=i.doc;t||L(c,0,0,c.length,a,e.type),t=!0;const l=u.combineTransactionSteps(n.doc,[...r]);return u.getChangedRanges(l).forEach(({oldRange:p,newRange:w})=>{De(w,i.doc,a,e.type),u.findChildrenInRange(i.doc,w,_=>_.isTextblock).forEach(({node:_,pos:y})=>{L(_.textContent,y,p.from,w.to,a,e.type)})}),a}})}const Oe={class:"d-link d-c-text d-d-inline-block d-wb-break-all",rel:"noopener noreferrer nofollow"},Me=u.Mark.create({name:"CustomLink",renderHTML({HTMLAttributes:e}){return["a",u.mergeAttributes(this.options.HTMLAttributes,e,Oe)]},renderText({node:e}){return e.attrs.text},addProseMirrorPlugins(){return[Ve({type:this.type})]}}),Ie=ie.extend({name:"ConfigurableImage",addAttributes(){return{src:{default:""},alt:{default:void 0},title:{default:void 0},width:{default:void 0},height:{default:void 0},style:{default:void 0}}}}).configure({inline:!0,allowBase64:!0}),qe=P.extend({parseHTML(){return[{tag:"div"}]},renderHTML({HTMLAttributes:e}){return["div",u.mergeAttributes(this.options.HTMLAttributes,e),0]}}),$e={compatConfig:{MODE:3},name:"MentionComponent",components:{NodeViewWrapper:d.NodeViewWrapper,DtLink:O.default},props:d.nodeViewProps,computed:{text(){return"@"+this.$props.node.attrs.name}}};function Ae(e,t,r,n,i,s){const a=o.resolveComponent("dt-link"),c=o.resolveComponent("node-view-wrapper");return o.openBlock(),o.createBlock(c,{class:"d-d-inline-block"},{default:o.withCtx(()=>[o.createVNode(a,{kind:"mention"},{default:o.withCtx(()=>[o.createTextVNode(o.toDisplayString(s.text),1)]),_:1})]),_:1})}const Ne=h._($e,[["render",Ae]]),je=B.extend({addNodeView(){return d.VueNodeViewRenderer(Ne)},parseHTML(){return[{tag:"mention-component"}]},addAttributes(){return{name:{default:""},avatarSrc:{default:""},id:{default:""}}},renderText({node:e}){return`@${e.attrs.id}`},renderHTML({HTMLAttributes:e}){return["mention-component",u.mergeAttributes(this.options.HTMLAttributes,e)]}}).configure({suggestion:{char:"@",pluginKey:new g.PluginKey("mentionSuggestion")}}),He={compatConfig:{MODE:3},name:"ChannelComponent",components:{NodeViewWrapper:d.NodeViewWrapper,DtLink:O.default},props:d.nodeViewProps,computed:{text(){return"#"+this.$props.node.attrs.name}}};function Fe(e,t,r,n,i,s){const a=o.resolveComponent("dt-link"),c=o.resolveComponent("node-view-wrapper");return o.openBlock(),o.createBlock(c,{class:"d-d-inline-block"},{default:o.withCtx(()=>[o.createVNode(a,{kind:"mention"},{default:o.withCtx(()=>[o.createTextVNode(o.toDisplayString(s.text),1)]),_:1})]),_:1})}const Ke=h._(He,[["render",Fe]]),We=B.extend({name:"channel",addNodeView(){return d.VueNodeViewRenderer(Ke)},parseHTML(){return[{tag:"channel-component"}]},addAttributes(){return{name:{default:""},id:{default:""},locked:{default:!1}}},renderText({node:e}){return`#${e.attrs.id}`},renderHTML({HTMLAttributes:e}){return["channel-component",u.mergeAttributes(this.options.HTMLAttributes,e)]}}).configure({suggestion:{char:"#",pluginKey:new g.PluginKey("channelSuggestion")}}),Ue={compatConfig:{MODE:3},name:"SlashCommandsComponent",components:{NodeViewWrapper:d.NodeViewWrapper},props:{...d.nodeViewProps},emits:["selected-command"],computed:{text(){return"/"+this.$props.node.attrs.command}},created(){var r,n,i;const e=this.$props.node.attrs.command;this.$emit("selected-command",e);const t=(i=(n=(r=this.editor)==null?void 0:r.storage)==null?void 0:n["slash-commands"])==null?void 0:i.onSelectedCommand;t&&typeof t=="function"&&t(e)}};function ze(e,t,r,n,i,s){const a=o.resolveComponent("node-view-wrapper");return o.openBlock(),o.createBlock(a,{class:"d-d-inline-block"},{default:o.withCtx(()=>[o.createTextVNode(o.toDisplayString(s.text),1)]),_:1})}const Xe=h._(Ue,[["render",ze]]),Je=(e,t)=>[...e.matchAll(t)].map(n=>{let i=n[2];return i.endsWith(" ")||(i+=" "),{index:n.index,text:i,match:n}}),Ye=B.extend({name:"slash-commands",group:"inline",inline:!0,addOptions(){var e;return{...(e=this.parent)==null?void 0:e.call(this),onSelectedCommand:null}},addStorage(){return{onSelectedCommand:this.options.onSelectedCommand}},addNodeView(){return d.VueNodeViewRenderer(Xe)},parseHTML(){return[{tag:"command-component"}]},addAttributes(){return{command:{default:""},parametersExample:{default:""},description:{default:""}}},renderText({node:e}){return`/${e.attrs.command}`},renderHTML({HTMLAttributes:e}){return["command-component",u.mergeAttributes(this.options.HTMLAttributes,e)]},addInputRules(){var r;const e=(r=this.options.suggestion)==null?void 0:r.items({query:""}).map(n=>n.command),t=new RegExp(`^((?:\\/)(${e.join("|")})) $`);return[u.nodeInputRule({find:t,type:this.type,getAttributes(n){return{command:n[2]}}})]},addPasteRules(){var r;const e=(r=this.options.suggestion)==null?void 0:r.items({query:""}).map(n=>n.command),t=new RegExp(`^((?:\\/)(${e.join("|")})) ?$`,"g");return[u.nodePasteRule({find:n=>Je(n,t),type:this.type,getAttributes(n){return{command:n[0].trim()}}})]}}).configure({suggestion:{char:"/",pluginKey:new g.PluginKey("slashCommandSuggestion")}}),Ge={compatConfig:{MODE:3},name:"MentionSuggestion",components:{DtAvatar:se.default,DtStack:x.default},props:{item:{type:Object,required:!0}},computed:{name(){return this.item.name},avatarSrc(){return this.item.avatarSrc},presence(){return this.item.presence},status(){return this.item.status},presenceText(){return this.item.presenceText},presenceFontColorClass(){return{active:"d-recipe-contact-row--active",busy:"d-recipe-contact-row--busy",away:"d-recipe-contact-row--away",offline:"d-recipe-contact-row--busy"}[this.presence]},showDetails(){return this.item.showDetails}}},Qe={class:"d-mention-suggestion__name"},Ze={key:1,class:"d-mention-suggestion__divider"},et={key:2,class:"d-mention-suggestion__status"};function tt(e,t,r,n,i,s){const a=o.resolveComponent("dt-avatar"),c=o.resolveComponent("dt-stack");return o.openBlock(),o.createBlock(c,{direction:"row",class:"d-mention-suggestion__container",gap:"400"},{default:o.withCtx(()=>[o.createVNode(a,{"full-name":s.name,"image-src":s.avatarSrc,"image-alt":s.name,"show-presence":s.showDetails,presence:s.presence,size:"sm"},null,8,["full-name","image-src","image-alt","show-presence","presence"]),o.createVNode(c,{class:"d-mention-suggestion__details-container",gap:"100"},{default:o.withCtx(()=>[o.createElementVNode("span",Qe,o.toDisplayString(s.name),1),s.showDetails?(o.openBlock(),o.createBlock(c,{key:0,direction:"row",gap:"300",class:"d-label--sm-plain"},{default:o.withCtx(()=>[s.presenceText?(o.openBlock(),o.createElementBlock("span",{key:0,class:o.normalizeClass(["d-mention-suggestion__presence",[s.presenceFontColorClass]])},o.toDisplayString(s.presenceText),3)):o.createCommentVNode("",!0),s.status&&s.presenceText?(o.openBlock(),o.createElementBlock("div",Ze," • ")):o.createCommentVNode("",!0),s.status?(o.openBlock(),o.createElementBlock("div",et,o.toDisplayString(s.status),1)):o.createCommentVNode("",!0)]),_:1})):o.createCommentVNode("",!0)]),_:1})]),_:1})}const nt=h._(Ge,[["render",tt]]),ot={allowSpaces:!0,render:()=>{let e,t,r=!1;return{onStart:n=>{e=new d.VueRenderer(E,{props:{itemComponent:o.markRaw(nt),itemType:"mention",...n},editor:n.editor}),n.clientRect&&(t=b("body",{getReferenceClientRect:n.clientRect,appendTo:()=>document.body,content:e.element,showOnCreate:!1,onShow:()=>{r=!0},onHidden:()=>{r=!1},interactive:!0,trigger:"manual",placement:"top-start",zIndex:650,plugins:[T]}),n.items.length>0&&(t==null||t[0].show()))},onUpdate(n){e==null||e.updateProps(n),n.items.length>0?t==null||t[0].show():t==null||t[0].hide(),n.clientRect&&(t==null||t[0].setProps({getReferenceClientRect:n.clientRect}))},onKeyDown(n){var i;if(r)return(i=e==null?void 0:e.ref)==null?void 0:i.onKeyDown(n)},onExit(){t==null||t[0].destroy(),t=null,e==null||e.destroy(),e=null}}}},rt={compatConfig:{MODE:3},name:"ChannelSuggestion",components:{DtStack:x.default,DtIconHash:ae,DtIconLock:ce},props:{item:{type:Object,required:!0}},computed:{name(){return this.item.name}}};function it(e,t,r,n,i,s){const a=o.resolveComponent("dt-icon-hash"),c=o.resolveComponent("dt-icon-lock"),l=o.resolveComponent("dt-stack");return o.openBlock(),o.createBlock(l,{direction:"row",gap:"400"},{default:o.withCtx(()=>[r.item.locked?(o.openBlock(),o.createBlock(c,{key:1,size:"300"})):(o.openBlock(),o.createBlock(a,{key:0,size:"300"})),o.createElementVNode("span",null,o.toDisplayString(s.name),1)]),_:1})}const st=h._(rt,[["render",it]]),at={allowSpaces:!0,render:()=>{let e,t,r=!1;return{onStart:n=>{e=new d.VueRenderer(E,{props:{itemComponent:o.markRaw(st),itemType:"channel",...n},editor:n.editor}),n.clientRect&&(t=b("body",{getReferenceClientRect:n.clientRect,appendTo:()=>document.body,content:e.element,showOnCreate:!1,onShow:()=>{r=!0},onHidden:()=>{r=!1},interactive:!0,trigger:"manual",placement:"top-start",zIndex:650,plugins:[T]}),n.items.length>0&&(t==null||t[0].show()))},onUpdate(n){e==null||e.updateProps(n),n.items.length>0?t==null||t[0].show():t==null||t[0].hide(),n.clientRect&&(t==null||t[0].setProps({getReferenceClientRect:n.clientRect}))},onKeyDown(n){var i;if(r)return(i=e==null?void 0:e.ref)==null?void 0:i.onKeyDown(n)},onExit(){t==null||t[0].destroy(),t=null,e==null||e.destroy(),e=null}}}},ct={compatConfig:{MODE:3},name:"SlashCommandSuggestion",props:{item:{type:Object,required:!0}},computed:{command(){return this.item.command},description(){return this.item.description},parametersExample(){return this.item.parametersExample}}},lt={class:"d-body--md-compact"},dt={key:0},ut={class:"d-body--sm d-fc-tertiary"};function mt(e,t,r,n,i,s){return o.openBlock(),o.createElementBlock("div",null,[o.createElementVNode("div",lt,[o.createElementVNode("span",null,"/"+o.toDisplayString(s.command),1),s.parametersExample?(o.openBlock(),o.createElementBlock("span",dt,o.toDisplayString(s.parametersExample),1)):o.createCommentVNode("",!0)]),o.createElementVNode("div",ut,o.toDisplayString(s.description),1)])}const ht=h._(ct,[["render",mt]]),pt={allowSpaces:!0,startOfLine:!0,render:()=>{let e,t,r=!1;return{onStart:n=>{e=new d.VueRenderer(E,{parent:void 0,props:{itemComponent:o.markRaw(ht),itemType:"slash-command",...n},editor:n.editor}),n.clientRect&&(t=b("body",{getReferenceClientRect:n.clientRect,appendTo:()=>document.body,content:e.element,showOnCreate:!1,onShow:()=>{r=!0},onHidden:()=>{r=!1},interactive:!0,trigger:"manual",placement:"top-start",zIndex:650,plugins:[T]}),n.items.length>0&&(t==null||t[0].show()))},onUpdate(n){e==null||e.updateProps(n),n.items.length>0?t==null||t[0].show():t==null||t[0].hide(),n.clientRect&&(t==null||t[0].setProps({getReferenceClientRect:n.clientRect}))},onKeyDown(n){var i;if(r)return(i=e==null?void 0:e.ref)==null?void 0:i.onKeyDown(n)},onExit(){t==null||t[0].destroy(),t=null,e==null||e.destroy(),e=null}}}},ft={compatConfig:{MODE:3},name:"DtRichTextEditor",components:{EditorContent:d.EditorContent,BubbleMenu:d.BubbleMenu,DtButton:de.default,DtStack:x.default},props:{modelValue:{type:[Object,String],default:""},editable:{type:Boolean,default:!0},preventTyping:{type:Boolean,default:!1},pasteRichText:{type:Boolean,default:!0},allowLineBreaks:{type:Boolean,default:!1},inputAriaLabel:{type:String,required:!0},inputClass:{type:String,default:""},autoFocus:{type:[Boolean,String,Number],default:!1,validator(e){return typeof e=="string"?C.RICH_TEXT_EDITOR_AUTOFOCUS_TYPES.includes(e):!0}},outputFormat:{type:String,default:"html",validator(e){return C.RICH_TEXT_EDITOR_OUTPUT_FORMATS.includes(e)}},placeholder:{type:String,default:""},link:{type:[Boolean,Object],default:!1},customLink:{type:[Boolean,Object],default:!1},mentionSuggestion:{type:Object,default:null},channelSuggestion:{type:Object,default:null},slashCommandSuggestion:{type:Object,default:null},allowBlockquote:{type:Boolean,default:!0},allowBold:{type:Boolean,default:!0},allowBulletList:{type:Boolean,default:!0},allowItalic:{type:Boolean,default:!0},allowStrike:{type:Boolean,default:!0},allowUnderline:{type:Boolean,default:!0},allowCode:{type:Boolean,default:!0},allowCodeblock:{type:Boolean,default:!0},allowInlineImages:{type:Boolean,default:!1},allowFontColor:{type:Boolean,default:!1},allowFontFamily:{type:Boolean,default:!1},additionalExtensions:{type:Array,default:()=>[]},hideLinkBubbleMenu:{type:Boolean,default:!1},useDivTags:{type:Boolean,default:!1}},emits:["input","json-input","html-input","text-input","update:modelValue","blur","focus","enter","edit-link","selected","selected-command"],data(){return{editor:null,tippyOptions:{appendTo:()=>{var e;return(e=k.returnFirstEl(this.$refs.editor.$el).getRootNode())==null?void 0:e.querySelector("body")},placement:"top-start"}}},computed:{attrs(){return{...this.$attrs,onInput:()=>{},onFocus:()=>{},onBlur:()=>{}}},extensions(){const e=[A,Y,Q,N];e.push(this.useDivTags?qe:P),this.allowBlockquote&&e.push(I),this.allowBold&&e.push(H),this.allowBulletList&&(e.push(F),e.push(U.extend({renderText({node:n}){return n.textContent}})),e.push(z)),this.allowItalic&&e.push(K),this.allowStrike&&e.push(X),this.allowUnderline&&e.push(J),this.placeholder&&e.push(j.configure({placeholder:this.placeholder}));const t=this,r=u.Extension.create({addKeyboardShortcuts(){return{"Shift-Enter":({editor:n})=>t.allowLineBreaks?!1:(n.commands.first(({commands:i})=>[()=>i.newlineInCode(),()=>t.allowBulletList&&i.splitListItem("listItem"),()=>i.createParagraphNear(),()=>i.liftEmptyBlock(),()=>i.splitBlock()]),!0),Enter:()=>t.allowLineBreaks?!1:(t.$emit("enter"),!0)}}});if(e.push(r),this.link&&e.push(W.extend({inclusive:!1}).configure({HTMLAttributes:{class:"d-link d-wb-break-all"},openOnClick:!1,autolink:!0,protocols:C.RICH_TEXT_EDITOR_SUPPORTED_LINK_PROTOCOLS})),this.customLink&&e.push(this.getExtension(Me,this.customLink)),this.mentionSuggestion){const n={...this.mentionSuggestion,...ot};e.push(je.configure({suggestion:n}))}if(this.channelSuggestion){const n={...this.channelSuggestion,...at};e.push(We.configure({suggestion:n}))}if(this.slashCommandSuggestion){const n={...this.slashCommandSuggestion,...pt};e.push(Ye.configure({suggestion:n,onSelectedCommand:i=>{this.$emit("selected-command",i)}}))}return e.push(ve),e.push(G.configure({types:["paragraph"]})),this.allowCode&&e.push($),this.allowCodeblock&&e.push(q.extend({renderText({node:n}){return`\`\`\`
2
2
  ${n.textContent}
3
- \`\`\``}}).configure({HTMLAttributes:{class:"d-rich-text-editor__code-block"}})),this.allowInlineImages&&e.push(Ie),(this.allowFontFamily||this.allowFontColor)&&(e.push(Z),this.allowFontColor&&e.push(ee),this.allowFontFamily&&e.push(te)),this.additionalExtensions.length&&e.push(...this.additionalExtensions),e},inputAttrs(){const e={"aria-label":this.inputAriaLabel,"aria-multiline":!0,role:"textbox"};return this.editable||(e["aria-readonly"]=!0),e}},watch:{editable(e){this.editor.setEditable(e),this.updateEditorAttributes({"aria-readonly":!e})},inputClass(e){this.updateEditorAttributes({class:e})},inputAriaLabel(e){this.updateEditorAttributes({"aria-label":e})},extensions(){this.destroyEditor(),this.createEditor()},modelValue(e){this.processValue(e)}},created(){this.createEditor()},beforeUnmount(){this.destroyEditor()},mounted(){k.warnIfUnmounted(k.returnFirstEl(this.$el),this.$options.name),this.processValue(this.modelValue,!1)},methods:{createEditor(){this.editor=new d.Editor({autofocus:this.autoFocus,content:this.modelValue,editable:this.editable,extensions:this.extensions,parseOptions:{preserveWhitespace:"full"},editorProps:{attributes:{...this.inputAttrs,class:this.inputClass},handlePaste:(e,t,r)=>{const n=t.clipboardData||window.clipboardData,i=n.getData("text/plain"),s=n.getData("text/html");return this.processPasteData(e,i,s)},transformPastedHTML(e){return e.replace(/(<\/\w+>)((<br \/>)+)/g,"$2$3$1")}}}),this.addEditorListeners()},bubbleMenuShouldShow({editor:e,view:t,state:r,oldState:n,from:i,to:s}){return e.isActive("link")},getSelectedLinkText(e){var c,l,m;const{view:t,state:r}=e,{from:n,to:i}=t.state.selection,s=r.doc.textBetween(n,i,""),a=this.editor.state.doc.nodeAt(n);return a&&((m=(l=(c=a.marks)==null?void 0:c.at(0))==null?void 0:l.type)==null?void 0:m.name)==="link"?a.textContent:s},editLink(){const e=this.getSelectedLinkText(this.editor),t={href:this.editor.getAttributes("link").href,text:e};this.$emit("edit-link",t)},removeLink(){var e,t,r,n;(n=(r=(t=(e=this.editor)==null?void 0:e.chain())==null?void 0:t.focus())==null?void 0:r.unsetLink())==null||n.run()},openLink(){var t,r;(r=(t=this.editor)==null?void 0:t.chain())==null||r.focus();const e=this.editor.getAttributes("link").href;window.open(e,"_blank")},setLink(e,t,r,n=C.RICH_TEXT_EDITOR_SUPPORTED_LINK_PROTOCOLS,i){var c,l,m;if(!e){this.removeLink();return}n.find(p=>p.test(e))||(e=`${i}${e}`),this.editor.chain().focus().extendMarkRange("link").run();const a=(m=(l=(c=this.editor)==null?void 0:c.view)==null?void 0:l.state)==null?void 0:m.selection;this.editor.chain().focus().insertContent(t).setTextSelection({from:a.from,to:a.from+t.length}).setLink({href:e,class:r.class}).run()},processValue(e,t=!0){const r=this.getOutput();if(!(t&&le(e,r))){if(typeof e=="string"&&this.outputFormat==="text"){const n=new RegExp(`(${D.emojiPattern})`,"g");e=e==null?void 0:e.replace(n,'<emoji-component code="$1"></emoji-component>')}this.editor.commands.setContent(e,!1,{preserveWhitespace:"full"})}},destroyEditor(){this.editor.destroy()},insertPlainTextWithHardBreaks(e,t){const{tr:r}=e.state,{from:n,to:i}=e.state.selection;r.deleteRange(n,i);const s=t.split(/\r?\n/);let a=n;for(let c=0;c<s.length;c++)c>0&&(r.insert(a,e.state.schema.nodes.hardBreak.create()),a++),r.insertText(s[c],a),a+=s[c].length;e.dispatch(r)},shouldPreserveLineBreaks(e,t){return this.pasteRichText?!t&&e&&this.hasBlankLines(e):!!e},processPasteData(e,t,r){if(this.shouldPreserveLineBreaks(t,r))return this.insertPlainTextWithHardBreaks(e,t),!0;if(this.shouldHandlePreformattedHTML(r)){const n=this.extractPreformattedText(r);if(n&&n.includes(`
3
+ \`\`\``}}).configure({HTMLAttributes:{class:"d-rich-text-editor__code-block"}})),this.allowInlineImages&&e.push(Ie),(this.allowFontFamily||this.allowFontColor)&&(e.push(Z),this.allowFontColor&&e.push(ee),this.allowFontFamily&&e.push(te)),this.additionalExtensions.length&&e.push(...this.additionalExtensions),e},inputAttrs(){const e={"aria-label":this.inputAriaLabel,"aria-multiline":!0,role:"textbox"};return this.editable||(e["aria-readonly"]=!0),e}},watch:{editable(e){this.editor.setEditable(e),this.updateEditorAttributes({"aria-readonly":!e})},inputClass(e){this.updateEditorAttributes({class:e})},inputAriaLabel(e){this.updateEditorAttributes({"aria-label":e})},extensions(){this.destroyEditor(),this.createEditor()},modelValue(e){this.processValue(e)}},created(){this.createEditor()},beforeUnmount(){this.destroyEditor()},mounted(){k.warnIfUnmounted(k.returnFirstEl(this.$el),this.$options.name),this.processValue(this.modelValue,!1)},methods:{createEditor(){this.editor=new d.Editor({autofocus:this.autoFocus,content:this.modelValue,editable:this.editable,extensions:this.extensions,parseOptions:{preserveWhitespace:"full"},editorProps:{attributes:{...this.inputAttrs,class:this.inputClass},handleKeyDown:(e,t)=>!!(this.preventTyping&&t.key!=="Backspace"),handlePaste:(e,t,r)=>{const n=t.clipboardData||window.clipboardData,i=n.getData("text/plain"),s=n.getData("text/html");return this.processPasteData(e,i,s)},transformPastedHTML(e){return e.replace(/(<\/\w+>)((<br \/>)+)/g,"$2$3$1")}}}),this.addEditorListeners()},bubbleMenuShouldShow({editor:e,view:t,state:r,oldState:n,from:i,to:s}){return e.isActive("link")},getSelectedLinkText(e){var c,l,m;const{view:t,state:r}=e,{from:n,to:i}=t.state.selection,s=r.doc.textBetween(n,i,""),a=this.editor.state.doc.nodeAt(n);return a&&((m=(l=(c=a.marks)==null?void 0:c.at(0))==null?void 0:l.type)==null?void 0:m.name)==="link"?a.textContent:s},editLink(){const e=this.getSelectedLinkText(this.editor),t={href:this.editor.getAttributes("link").href,text:e};this.$emit("edit-link",t)},removeLink(){var e,t,r,n;(n=(r=(t=(e=this.editor)==null?void 0:e.chain())==null?void 0:t.focus())==null?void 0:r.unsetLink())==null||n.run()},openLink(){var t,r;(r=(t=this.editor)==null?void 0:t.chain())==null||r.focus();const e=this.editor.getAttributes("link").href;window.open(e,"_blank")},setLink(e,t,r,n=C.RICH_TEXT_EDITOR_SUPPORTED_LINK_PROTOCOLS,i){var c,l,m;if(!e){this.removeLink();return}n.find(p=>p.test(e))||(e=`${i}${e}`),this.editor.chain().focus().extendMarkRange("link").run();const a=(m=(l=(c=this.editor)==null?void 0:c.view)==null?void 0:l.state)==null?void 0:m.selection;this.editor.chain().focus().insertContent(t).setTextSelection({from:a.from,to:a.from+t.length}).setLink({href:e,class:r.class}).run()},processValue(e,t=!0){const r=this.getOutput();if(!(t&&le(e,r))){if(typeof e=="string"&&this.outputFormat==="text"){const n=new RegExp(`(${D.emojiPattern})`,"g");e=e==null?void 0:e.replace(n,'<emoji-component code="$1"></emoji-component>')}this.editor.commands.setContent(e,!1,{preserveWhitespace:"full"})}},destroyEditor(){this.editor.destroy()},insertPlainTextWithHardBreaks(e,t){const{tr:r}=e.state,{from:n,to:i}=e.state.selection;r.deleteRange(n,i);const s=t.split(/\r?\n/);let a=n;for(let c=0;c<s.length;c++)c>0&&(r.insert(a,e.state.schema.nodes.hardBreak.create()),a++),r.insertText(s[c],a),a+=s[c].length;e.dispatch(r)},shouldPreserveLineBreaks(e,t){return this.pasteRichText?!t&&e&&this.hasBlankLines(e):!!e},processPasteData(e,t,r){if(this.shouldPreserveLineBreaks(t,r))return this.insertPlainTextWithHardBreaks(e,t),!0;if(this.shouldHandlePreformattedHTML(r)){const n=this.extractPreformattedText(r);if(n&&n.includes(`
4
4
  `))return this.insertPlainTextWithHardBreaks(e,n),!0}return!1},shouldHandlePreformattedHTML(e){return this.pasteRichText&&e&&this.containsPreformattedContent(e)},containsPreformattedContent(e){const t=document.createElement("div");t.innerHTML=e;const r=t.querySelectorAll("*");for(const n of r)if(this.hasPreWhitespace(n)&&this.hasLineBreaks(n))return!0;return!1},hasPreWhitespace(e){const t=e.getAttribute("style")||"",r=e.style.whiteSpace||"",n=r==="pre"||r==="pre-wrap",i=t.includes("white-space: pre");return n||i},hasLineBreaks(e){return e.textContent&&e.textContent.includes(`
5
5
  `)},hasBlankLines(e){return e.includes(`
6
6
 
7
7
  `)||/\n\s*\n/.test(e)},extractPreformattedText(e){const t=document.createElement("div");return t.innerHTML=e,this.walkAndExtractText(t)},walkAndExtractText(e){let t="";if(e.nodeType===Node.TEXT_NODE)t+=e.textContent;else if(e.nodeType===Node.ELEMENT_NODE)if(this.hasPreWhitespace(e))t+=e.textContent;else for(const r of e.childNodes)t+=this.walkAndExtractText(r);return t},triggerInputChangeEvents(){const e=this.getOutput();this.$emit("input",e),this.$emit("update:modelValue",e);const t=this.editor.getJSON();this.$emit("json-input",t);const r=this.editor.getHTML();this.$emit("html-input",r);const n=this.editor.getText({blockSeparator:`
8
- `});this.$emit("text-input",n)},addEditorListeners(){this.editor.on("create",()=>{this.triggerInputChangeEvents()}),this.editor.on("update",()=>{var e,t;if(this.preventTyping&&((t=(e=this.editor.view)==null?void 0:e.input)==null?void 0:t.lastKeyCode)!==8){this.editor.commands.setContent(this.modelValue,!1);return}this.triggerInputChangeEvents()}),this.editor.on("selectionUpdate",({editor:e})=>{this.$emit("selected",this.getSelectedLinkText(e))}),this.editor.on("focus",({event:e})=>{this.$emit("focus",e)}),this.editor.on("blur",({event:e})=>{this.$emit("blur",e)})},getOutput(){switch(this.outputFormat){case"json":return this.editor.getJSON();case"html":return this.editor.getHTML();case"text":default:return this.editor.getText({blockSeparator:`
8
+ `});this.$emit("text-input",n)},addEditorListeners(){this.editor.on("create",()=>{this.triggerInputChangeEvents()}),this.editor.on("update",()=>{this.triggerInputChangeEvents()}),this.editor.on("selectionUpdate",({editor:e})=>{this.$emit("selected",this.getSelectedLinkText(e))}),this.editor.on("focus",({event:e})=>{this.$emit("focus",e)}),this.editor.on("blur",({event:e})=>{this.$emit("blur",e)})},getOutput(){switch(this.outputFormat){case"json":return this.editor.getJSON();case"html":return this.editor.getHTML();case"text":default:return this.editor.getText({blockSeparator:`
9
9
  `})}},getExtension(e,t){var r;return typeof t=="boolean"?e:(r=e.configure)==null?void 0:r.call(e,t)},updateEditorAttributes(e){this.editor.setOptions({editorProps:{attributes:{...this.inputAttrs,class:this.inputClass,...e}}})},focusEditor(){this.editor.commands.focus()}}},gt={class:"d-popover__dialog"};function _t(e,t,r,n,i,s){const a=o.resolveComponent("dt-button"),c=o.resolveComponent("dt-stack"),l=o.resolveComponent("bubble-menu"),m=o.resolveComponent("editor-content");return o.openBlock(),o.createElementBlock("div",null,[i.editor&&r.link&&!r.hideLinkBubbleMenu?(o.openBlock(),o.createBlock(l,{key:0,editor:i.editor,"should-show":s.bubbleMenuShouldShow,"tippy-options":i.tippyOptions,style:{visibility:"visible"}},{default:o.withCtx(()=>[o.createElementVNode("div",gt,[o.createVNode(c,{direction:"row",class:"d-rich-text-editor-bubble-menu__button-stack",gap:"0"},{default:o.withCtx(()=>[o.createVNode(a,{kind:"muted",importance:"clear",onClick:s.editLink},{default:o.withCtx(()=>[o.createTextVNode(" Edit ")]),_:1},8,["onClick"]),o.createVNode(a,{kind:"muted",importance:"clear",onClick:s.openLink},{default:o.withCtx(()=>[o.createTextVNode(" Open link ")]),_:1},8,["onClick"]),o.createVNode(a,{kind:"danger",importance:"clear",onClick:s.removeLink},{default:o.withCtx(()=>[o.createTextVNode(" Remove ")]),_:1},8,["onClick"])]),_:1})])]),_:1},8,["editor","should-show","tippy-options"])):o.createCommentVNode("",!0),o.createVNode(m,o.mergeProps({ref:"editor",editor:i.editor,class:"d-rich-text-editor","data-qa":"dt-rich-text-editor"},s.attrs),null,16,["editor"])])}const kt=h._(ft,[["render",_t]]);exports.default=kt;
10
10
  //# sourceMappingURL=rich-text-editor.cjs.map