@htmlbricks/hb-editor-tinymce
Version:
Svelte TinyMCE WebComponent
3 lines (2 loc) • 12.5 kB
JavaScript
var release=function(){"use strict";function t(){}function e(t){return t()}function n(){return Object.create(null)}function o(t){t.forEach(e)}function r(t){return"function"==typeof t}function s(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function i(t,e,n){t.insertBefore(e,n||null)}function a(t){t.parentNode&&t.parentNode.removeChild(t)}function l(t,e,n){e in t?t[e]="boolean"==typeof t[e]&&""===n||n:function(t,e,n){null==n?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}(t,e,n)}function u(t){const e={};for(const n of t)e[n.name]=n.value;return e}let c;function d(t){c=t}const h=[],m=[];let f=[];const p=[],_=Promise.resolve();let g=!1;function b(t){f.push(t)}const y=new Set;let $=0;function v(){if(0!==$)return;const t=c;do{try{for(;$<h.length;){const t=h[$];$++,d(t),w(t.$$)}}catch(t){throw h.length=0,$=0,t}for(d(null),h.length=0,$=0;m.length;)m.pop()();for(let t=0;t<f.length;t+=1){const e=f[t];y.has(e)||(y.add(e),e())}f.length=0}while(h.length);for(;p.length;)p.pop()();g=!1,y.clear(),d(t)}function w(t){if(null!==t.fragment){t.update(),o(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(b)}}const A=new Set;function k(t,e){const n=t.$$;null!==n.fragment&&(!function(t){const e=[],n=[];f.forEach((o=>-1===t.indexOf(o)?e.push(o):n.push(o))),n.forEach((t=>t())),f=e}(n.after_update),o(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function C(t,e){-1===t.$$.dirty[0]&&(h.push(t),g||(g=!0,_.then(v)),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function E(s,i,l,u,h,m,f,p=[-1]){const _=c;d(s);const g=s.$$={fragment:null,ctx:[],props:m,update:t,not_equal:h,bound:n(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(i.context||(_?_.$$.context:[])),callbacks:n(),dirty:p,skip_bound:!1,root:i.target||_.$$.root};f&&f(g.root);let y=!1;if(g.ctx=l?l(s,i.props||{},((t,e,...n)=>{const o=n.length?n[0]:e;return g.ctx&&h(g.ctx[t],g.ctx[t]=o)&&(!g.skip_bound&&g.bound[t]&&g.bound[t](o),y&&C(s,t)),e})):[],g.update(),y=!0,o(g.before_update),g.fragment=!!u&&u(g.ctx),i.target){if(i.hydrate){const t=function(t){return Array.from(t.childNodes)}(i.target);g.fragment&&g.fragment.l(t),t.forEach(a)}else g.fragment&&g.fragment.c();i.intro&&(($=s.$$.fragment)&&$.i&&(A.delete($),$.i(w))),function(t,n,s,i){const{fragment:a,after_update:l}=t.$$;a&&a.m(n,s),i||b((()=>{const n=t.$$.on_mount.map(e).filter(r);t.$$.on_destroy?t.$$.on_destroy.push(...n):o(n),t.$$.on_mount=[]})),l.forEach(b)}(s,i.target,i.anchor,i.customElement),v()}var $,w;d(_)}let x;function D(e){let n;return{c(){var o;o="tinymce-editor",n=document.createElement(o),this.c=t,l(n,"api-key",e[0]),l(n,"plugins",e[1]),l(n,"toolbar",e[2]),l(n,"images_upload_url",e[3])},m(t,e){i(t,n,e)},p(t,[e]){1&e&&l(n,"api-key",t[0]),2&e&&l(n,"plugins",t[1]),4&e&&l(n,"toolbar",t[2]),8&e&&l(n,"images_upload_url",t[3])},i:t,o:t,d(t){t&&a(n)}}}function H(t,e,n){let{id:o}=e,{key:r}=e,{plugins:s}=e,{toolbar:i}=e,{images_upload_url:a}=e;return t.$$set=t=>{"id"in t&&n(4,o=t.id),"key"in t&&n(0,r=t.key),"plugins"in t&&n(1,s=t.plugins),"toolbar"in t&&n(2,i=t.toolbar),"images_upload_url"in t&&n(3,a=t.images_upload_url)},t.$$.update=()=>{31&t.$$.dirty&&(o||n(4,o=null),r||n(0,r="no-api-key"),s||n(1,s="advlist autolink lists link image charmap print preview anchor searchreplace visualblocks code fullscreen insertdatetime media table paste code help wordcount"),i||n(2,i="undo redo | formatselect | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | help | customDateButton"),a||n(3,a=""))},[r,s,i,a,o]}"function"==typeof HTMLElement&&(x=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}connectedCallback(){const{on_mount:t}=this.$$;this.$$.on_disconnect=t.map(e).filter(r);for(const t in this.$$.slotted)this.appendChild(this.$$.slotted[t])}attributeChangedCallback(t,e,n){this[t]=n}disconnectedCallback(){o(this.$$.on_disconnect)}$destroy(){k(this,1),this.$destroy=t}$on(e,n){if(!r(n))return t;const o=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return o.push(n),()=>{const t=o.indexOf(n);-1!==t&&o.splice(t,1)}}$set(t){var e;this.$$set&&(e=t,0!==Object.keys(e).length)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}),function(){var t="undefined"!=typeof window?window:Function("return this;")(),e=function(e,n){return function(e,n){for(var o=null!=n?n:t,r=0;r<e.length&&null!=o;++r)o=o[e[r]];return o}(e.split("."),n)},n=Object.hasOwnProperty,o=function(t,e){return n.call(t,e)},r=0;const s=()=>{return{listeners:[],scriptId:(t="tiny-script",e=(new Date).getTime(),t+"_"+Math.floor(1e9*Math.random())+ ++r+String(e)),scriptLoaded:!1};var t,e},i=(()=>{let t=s();return{load:(e,n,o)=>{t.scriptLoaded?o():(t.listeners.push(o),e.getElementById(t.scriptId)||((t,e,n,o)=>{const r=e.createElement("script");r.referrerPolicy="origin",r.type="application/javascript",r.id=t,r.src=n;const s=()=>{r.removeEventListener("load",s),o()};r.addEventListener("load",s),e.head&&e.head.appendChild(r)})(t.scriptId,e,n,(()=>{t.listeners.forEach((t=>t())),t.scriptLoaded=!0})))},reinitialize:()=>{t=s()}}})();var a;!function(t){t[t.Raw=0]="Raw",t[t.Initializing=1]="Initializing",t[t.Ready=2]="Ready"}(a||(a={}));const l=t=>e=>o(t,e)?t[e]:e,u=e,c=function(t){return t},d=l({false:!1}),h=l({true:!0,false:!1}),m=t=>/^\d+$/.test(t)?Number.parseInt(t,10):t,f={setup:u,toolbar:d,menubar:d,plugins:c,content_css:c,content_style:c,width:m,height:m,toolbar_mode:c,contextmenu:d,quickbars_insert_toolbar:d,quickbars_selection_toolbar:d,powerpaste_word_import:c,powerpaste_html_import:c,powerpaste_allow_local_images:h,resize:h,skin:c,skin_url:c,images_upload_url:c,images_upload_handler:u,images_upload_base_path:c,images_upload_credentials:h,images_reuse_filename:h,icons:c,icons_url:c},p={};class _ extends HTMLElement{constructor(){super(),this._eventAttrHandler=t=>{t.forEach((t=>{var e;"attributes"===t.type&&t.target===this&&(null===(e=t.attributeName)||void 0===e?void 0:e.toLowerCase().startsWith("on-"))&&this._updateEventAttr(t.attributeName,this.getAttribute(t.attributeName))}))},this._formDataHandler=t=>{const e=this.name;if(null!==e){t.formData.append(e,this.value)}},this._status=a.Raw,this._shadowDom=this.attachShadow({mode:"open"}),this._form=null,this._eventHandlers={},this._mutationObserver=new MutationObserver(this._eventAttrHandler)}static get formAssociated(){return!0}static get observedAttributes(){return["form","readonly","autofocus","placeholder"].concat(["on-BeforePaste","on-Blur","on-Click","on-ContextMenu","on-Copy","on-Cut","on-Dblclick","on-Drag","on-DragDrop","on-DragEnd","on-DragGesture","on-DragOver","on-Drop","on-Focus","on-FocusIn","on-FocusOut","on-KeyDown","on-KeyPress","on-KeyUp","on-MouseDown","on-MouseEnter","on-MouseLeave","on-MouseMove","on-MouseOut","on-MouseOver","on-MouseUp","on-Paste","on-SelectionChange"]).concat(["on-Activate","on-AddUndo","on-BeforeAddUndo","on-BeforeExecCommand","on-BeforeGetContent","on-BeforeRenderUI","on-BeforeSetContent","on-Change","on-ClearUndos","on-Deactivate","on-Dirty","on-ExecCommand","on-GetContent","on-Hide","on-Init","on-LoadContent","on-NodeChange","on-PostProcess","on-PostRender","on-PreProcess","on-ProgressState","on-Redo","on-Remove","on-Reset","on-SaveContent","on-SetAttrib","on-ObjectResizeStart","on-ObjectResized","on-ObjectSelected","on-SetContent","on-Show","on-Submit","on-Undo","on-VisualAid"])}_updateEventAttr(t,n){const o=t.substring(3).toLowerCase(),r=null!==n?e(n):void 0;this._eventHandlers[o]!==r&&(this._editor&&this._eventHandlers[o]&&this._editor.off(o,this._eventHandlers[o]),r?(this._editor&&this._editor.on(o,r),this._eventHandlers[o]=r):delete this._eventHandlers[o])}_updateForm(){if(this.isConnected){const t=this.getAttribute("form"),e=null!==t?this.ownerDocument.querySelector("form#"+t):this.closest("form");this._form!==e&&(null!==this._form&&this._form.removeEventListener("formdata",this._formDataHandler),this._form=e,null!==this._form&&this._form.addEventListener("formdata",this._formDataHandler))}else null!==this._form&&(this._form.removeEventListener("formdata",this._formDataHandler),this._form=null)}_getTinymce(){return t.tinymce}_getConfig(){var t,e;const n=null!==(e=u(null!==(t=this.getAttribute("config"))&&void 0!==t?t:""))&&void 0!==e?e:{};for(let t=0;t<this.attributes.length;t++){const e=this.attributes.item(t);if(null!==e&&o(f,e.name)){n[o(p,e.name)?p[e.name]:e.name]=f[e.name](e.value)}}return this.readonly&&(n.readonly=!0),this.autofocus&&(n.auto_focus=!0),delete n.target,delete n.selector,n}_getEventHandlers(){const t={};for(let n=0;n<this.attributes.length;n++){const o=this.attributes.item(n);if(null!==o&&o.name.toLowerCase().startsWith("on-")){const n=o.name.toLowerCase().substr(3),r=e(o.value);t[n]=r}}return t}_doInit(){var t;this._status=a.Initializing;const e=document.createElement("textarea");e.value=null!==(t=this.textContent)&&void 0!==t?t:"",null!==this.placeholder&&(e.placeholder=this.placeholder),this._shadowDom.appendChild(e);const n=this._getConfig(),o=Object.assign(Object.assign({},n),{target:e,setup:t=>{this._editor=t,t.on("init",(t=>{this._status=a.Ready})),t.on("SwitchMode",(t=>{this.readonly=this.readonly})),Object.keys(this._eventHandlers).forEach((e=>{t.on(e,this._eventHandlers[e])})),"function"==typeof n.setup&&n.setup(t)}});this._getTinymce().init(o)}_getTinymceSrc(){var t;const e=this.getAttribute("src");if(e)return e;const n=null!==(t=this.getAttribute("channel"))&&void 0!==t?t:"5-stable";return`https://cdn.tiny.cloud/1/${this.hasAttribute("api-key")?this.getAttribute("api-key"):"no-api-key"}/tinymce/${n}/tinymce.min.js`}_loadTinyDoInit(){this._getTinymce()?this._doInit():i.load(this.ownerDocument,this._getTinymceSrc(),(()=>this._doInit()))}attributeChangedCallback(t,e,n){e!==n&&("form"===t?this._updateForm():"readonly"===t?this.readonly=null!==n:"autofocus"===t?this.autofocus=null!==n:"placeholder"===t?this.placeholder=n:t.toLowerCase().startsWith("on")&&this._updateEventAttr(t,n))}connectedCallback(){this._eventHandlers=this._getEventHandlers(),this._mutationObserver.observe(this,{attributes:!0,childList:!1,subtree:!1}),this._updateForm(),this._status===a.Raw&&this._loadTinyDoInit()}disconnectedCallback(){this._mutationObserver.disconnect(),this._updateForm()}get value(){return this._status===a.Ready?this._editor.getContent():void 0}set value(t){this._status===a.Ready&&this._editor.setContent(t)}get readonly(){return this._editor?"readonly"===this._editor.mode.get():this.hasAttribute("readonly")}set readonly(t){t?(this._editor&&"readonly"!==this._editor.mode.get()&&this._editor.mode.set("readonly"),this.hasAttribute("readonly")||this.setAttribute("readonly","")):(this._editor&&"readonly"===this._editor.mode.get()&&this._editor.mode.set("design"),this.hasAttribute("readonly")&&this.removeAttribute("readonly"))}get placeholder(){return this.getAttribute("placeholder")}set placeholder(t){if(this._editor){const e=this._editor.getElement();null!==e&&(null!==t?e.setAttribute("placeholder",t):e.removeAttribute("placeholder"))}null!==t?this.getAttribute("placeholder")!==t&&this.setAttribute("placeholder",t):this.hasAttribute("placeholder")&&this.removeAttribute("placeholder")}get autofocus(){return this.hasAttribute("autofocus")}set autofocus(t){t?this.hasAttribute("autofocus")||this.setAttribute("autofocus",""):this.hasAttribute("autofocus")&&this.removeAttribute("autofocus")}get form(){return this._form}get name(){return this.getAttribute("name")}get type(){return this.localName}}window.customElements.define("tinymce-editor",_)}();class O extends x{constructor(t){super(),E(this,{target:this.shadowRoot,props:u(this.attributes),customElement:!0},H,D,s,{id:4,key:0,plugins:1,toolbar:2,images_upload_url:3},null),t&&(t.target&&i(t.target,this,t.anchor),t.props&&(this.$set(t.props),v()))}static get observedAttributes(){return["id","key","plugins","toolbar","images_upload_url"]}get id(){return this.$$.ctx[4]}set id(t){this.$$set({id:t}),v()}get key(){return this.$$.ctx[0]}set key(t){this.$$set({key:t}),v()}get plugins(){return this.$$.ctx[1]}set plugins(t){this.$$set({plugins:t}),v()}get toolbar(){return this.$$.ctx[2]}set toolbar(t){this.$$set({toolbar:t}),v()}get images_upload_url(){return this.$$.ctx[3]}set images_upload_url(t){this.$$set({images_upload_url:t}),v()}}return customElements.define("hb-editor-tinymce",O),O}();
//# sourceMappingURL=release.js.map