import"./vue.db505ee4.js";import{w as b,d as L,t as V,r as j,o as U,a as _,b as R,e as x,h as E,n as p}from"./@vue.cb43a243.js";var K=["onActivate","onAddUndo","onBeforeAddUndo","onBeforeExecCommand","onBeforeGetContent","onBeforeRenderUI","onBeforeSetContent","onBeforePaste","onBlur","onChange","onClearUndos","onClick","onContextMenu","onCopy","onCut","onDblclick","onDeactivate","onDirty","onDrag","onDragDrop","onDragEnd","onDragGesture","onDragOver","onDrop","onExecCommand","onFocus","onFocusIn","onFocusOut","onGetContent","onHide","onInit","onKeyDown","onKeyPress","onKeyUp","onLoadContent","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp","onNodeChange","onObjectResizeStart","onObjectResized","onObjectSelected","onPaste","onPostProcess","onPostRender","onPreProcess","onProgressState","onRedo","onRemove","onReset","onSaveContent","onSelectionChange","onSetAttrib","onSetContent","onShow","onSubmit","onUndo","onVisualAid"],N=function(n){return K.map(function(t){return t.toLowerCase()}).indexOf(n.toLowerCase())!==-1},T=function(n,t,e){Object.keys(t).filter(N).forEach(function(o){var r=t[o];typeof r=="function"&&(o==="onInit"?r(n,e):e.on(o.substring(2),function(i){return r(i,e)}))})},z=function(n,t,e,o){var r=n.modelEvents?n.modelEvents:null,i=Array.isArray(r)?r.join(" "):r;b(o,function(d,l){e&&typeof d=="string"&&d!==l&&d!==e.getContent({format:n.outputFormat})&&e.setContent(d)}),e.on(i||"change input undo redo",function(){t.emit("update:modelValue",e.getContent({format:n.outputFormat}))})},F=function(n,t,e,o,r,i){o.setContent(i()),e.attrs["onUpdate:modelValue"]&&z(t,e,o,r),T(n,e.attrs,o)},w=0,M=function(n){var t=Date.now(),e=Math.floor(Math.random()*1e9);return w++,n+"_"+e+w+String(t)},G=function(n){return n!==null&&n.tagName.toLowerCase()==="textarea"},D=function(n){return typeof n=="undefined"||n===""?[]:Array.isArray(n)?n:n.split(" ")},H=function(n,t){return D(n).concat(D(t))},k=function(n){return n==null},A=function(){return{listeners:[],scriptId:M("tiny-script"),scriptLoaded:!1}},q=function(){var n=A(),t=function(r,i,d,l){var a=i.createElement("script");a.referrerPolicy="origin",a.type="application/javascript",a.id=r,a.src=d;var s=function(){a.removeEventListener("load",s),l()};a.addEventListener("load",s),i.head&&i.head.appendChild(a)},e=function(r,i,d){n.scriptLoaded?d():(n.listeners.push(d),r.getElementById(n.scriptId)||t(n.scriptId,r,i,function(){n.listeners.forEach(function(l){return l()}),n.scriptLoaded=!0}))},o=function(){n=A()};return{load:e,reinitialize:o}},W=q(),J=function(){return typeof window!="undefined"?window:global},f=function(){var n=J();return n&&n.tinymce?n.tinymce:null},Q={apiKey:String,cloudChannel:String,id:String,init:Object,initialValue:String,inline:Boolean,modelEvents:[String,Array],plugins:[String,Array],tagName:String,toolbar:[String,Array],modelValue:String,disabled:Boolean,tinymceScriptSrc:String,outputFormat:{type:String,validator:function(n){return n==="html"||n==="text"}}},v=globalThis&&globalThis.__assign||function(){return v=Object.assign||function(n){for(var t,e=1,o=arguments.length;e<o;e++){t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},v.apply(this,arguments)},X=function(n,t,e,o){return n(o||"div",{id:t,ref:e})},Y=function(n,t,e){return n("textarea",{id:t,visibility:"hidden",ref:e})},nn=L({props:Q,setup:function(n,t){var e=n.init?v({},n.init):{},o=V(n),r=o.disabled,i=o.modelValue,d=o.tagName,l=j(null),a=null,s=n.id||M("tiny-vue"),C=n.init&&n.init.inline||n.inline,S=!!t.attrs["onUpdate:modelValue"],h=!0,O=n.initialValue?n.initialValue:"",y="",P=function(u){return S?function(){return(i==null?void 0:i.value)?i.value:""}:function(){return u?O:y}},g=function(){var u=P(h),c=v(v({},e),{readonly:n.disabled,selector:"#"+s,plugins:H(e.plugins,n.plugins),toolbar:n.toolbar||e.toolbar,inline:C,setup:function(m){a=m,m.on("init",function(I){return F(I,n,t,m,i,u)}),typeof e.setup=="function"&&e.setup(m)}});G(l.value)&&(l.value.style.visibility=""),f().init(c),h=!1};b(r,function(u){a!==null&&a.setMode(u?"readonly":"design")}),b(d,function(u){var c;S||(y=a.getContent()),(c=f())===null||c===void 0||c.remove(a),p(function(){return g()})}),U(function(){if(f()!==null)g();else if(l.value&&l.value.ownerDocument){var u=n.cloudChannel?n.cloudChannel:"5",c=n.apiKey?n.apiKey:"no-api-key",m=k(n.tinymceScriptSrc)?"https://cdn.tiny.cloud/1/"+c+"/tinymce/"+u+"/tinymce.min.js":n.tinymceScriptSrc;W.load(l.value.ownerDocument,m,g)}}),_(function(){f()!==null&&f().remove(a)}),C||(R(function(){h||g()}),x(function(){var u;S||(y=a.getContent()),(u=f())===null||u===void 0||u.remove(a)}));var B=function(u){var c;y=a.getContent(),(c=f())===null||c===void 0||c.remove(a),e=v(v({},e),u),p(function(){return g()})};return t.expose({rerender:B}),function(){return C?X(E,s,l,n.tagName):Y(E,s,l)}}});export{nn as E};
