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