Current section

Files

Jump to
ckeditor5_phoenix dist index.cjs
Raw

dist/index.cjs

"use strict";var A=Object.create;var w=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var S=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of V(t))!R.call(i,o)&&o!==e&&w(i,o,{get:()=>t[o],enumerable:!(n=C(t,o))||n.enumerable});return i};var g=(i,t,e)=>(e=i!=null?A(H(i)):{},S(t||!i||!i.__esModule?w(e,"default",{value:i,enumerable:!0}):e,i));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function p(i,t){let e=null;return(...n)=>{e&&clearTimeout(e),e=setTimeout(()=>{t(...n)},i)}}class E{el;liveSocket;pushEvent;pushEventTo;handleEvent}function k(i){return{mounted(){const t=new i;this.el.instance=t,t.el=this.el,t.liveSocket=this.liveSocket,t.pushEvent=(e,n,o)=>this.pushEvent?.(e,n,o),t.pushEventTo=(e,n,o,s)=>this.pushEventTo?.(e,n,o,s),t.handleEvent=(e,n)=>this.handleEvent?.(e,n),t.mounted?.()},beforeUpdate(){this.el.instance.beforeUpdate?.()},destroyed(){this.el.instance.destroyed?.()},disconnected(){this.el.instance.disconnected?.()},reconnected(){this.el.instance.reconnected?.()}}}function I(i,t){const e=Object.entries(i).map(([n,o])=>[n,t(o,n)]);return Object.fromEntries(e)}function v(i){if(i===null)return null;const t=Number.parseInt(i,10);return Number.isNaN(t)?null:t}class l{static the=new l;editors=new Map;callbacks=new Map;constructor(){}execute(t,e){const{callbacks:n,editors:o}=this,s=o.get(t);return s?Promise.resolve(e(s)):new Promise(r=>{const a=async c=>r(await e(c));this.callbacks.has(t)||n.set(t,[]),n.set(t,[...n.get(t),a])})}register(t,e){const{editors:n,callbacks:o}=this,s=o.get(t);if(n.has(t))throw new Error(`Editor with ID "${t}" is already registered.`);n.set(t,e),s&&(s.forEach(r=>r(e)),o.delete(t)),this.editors.size===1&&this.register(null,e)}unregister(t){const{editors:e,callbacks:n}=this;if(!e.has(t))throw new Error(`Editor with ID "${t}" is not registered.`);t&&this.editors.get(null)===e.get(t)&&this.unregister(null),e.delete(t),n.delete(t)}getEditors(){return Array.from(this.editors.values())}hasEditor(t){return this.editors.has(t)}waitForEditor(t){return this.execute(t,e=>e)}async destroyAllEditors(){const t=Array.from(this.editors.values()).map(e=>e.destroy());this.editors.clear(),this.callbacks.clear(),await Promise.all(t)}}class $ extends E{mountedPromise=null;get attrs(){const t={editableId:this.el.getAttribute("id"),editorId:this.el.getAttribute("data-cke-editor-id")||null,rootName:this.el.getAttribute("data-cke-editable-root-name"),initialValue:this.el.getAttribute("data-cke-editable-initial-value")||""};return Object.defineProperty(this,"attrs",{value:t,writable:!1,configurable:!1,enumerable:!0}),t}async mounted(){const{editableId:t,editorId:e,rootName:n,initialValue:o}=this.attrs,s=this.el.querySelector(`#${t}_input`);this.mountedPromise=l.the.execute(e,r=>{const{ui:a,editing:c,model:h}=r;if(h.document.getRoot(n))return;r.addRoot(n,{isUndoable:!1,data:o});const m=this.el.querySelector("[data-cke-editable-content]"),b=a.view.createEditable(n,m);a.addEditable(b),c.view.forceRender(),s&&T(s,r,n)})}async destroyed(){const{editorId:t,rootName:e}=this.attrs;this.el.style.display="none",await this.mountedPromise,this.mountedPromise=null,await l.the.execute(t,n=>{const o=n.model.document.getRoot(e);o&&(n.detachEditable(o),n.detachRoot(e,!1))})}}const O=k($);function T(i,t,e){const n=()=>{i.value=t.getData({rootName:e})};t.model.document.on("change:data",p(100,n)),n()}function y(i){return["inline","classic","balloon","decoupled"].includes(i)}async function j(i){const t=await import("ckeditor5"),n={inline:t.InlineEditor,balloon:t.BalloonEditor,classic:t.ClassicEditor,decoupled:t.DecoupledEditor,multiroot:t.MultiRootEditor}[i];if(!n)throw new Error(`Unsupported editor type: ${i}`);return n}async function D(i){const t=await import("ckeditor5");let e=null;const n=i.map(async o=>{const{[o]:s}=t;if(s)return s;if(!e)try{e=await import("ckeditor5-premium-features")}catch(a){console.error(`Failed to load premium package: ${a}`)}const{[o]:r}=e||{};if(r)return r;throw new Error(`Plugin "${o}" not found in base or premium packages.`)});return Promise.all(n)}function f(i){const t=document.querySelectorAll([`[data-cke-editor-id="${i}"][data-cke-editable-root-name]`,"[data-cke-editable-root-name]:not([data-cke-editor-id])"].join(", "));return Array.from(t).reduce((e,n)=>{const o=n.getAttribute("data-cke-editable-root-name"),s=n.getAttribute("data-cke-editable-initial-value")||"",r=n.querySelector("[data-cke-editable-content]");return!o||!r?e:{...e,[o]:{content:r,initialValue:s}}},Object.create({}))}const P=["inline","classic","balloon","decoupled","multiroot"];function N(i){const t=i.getAttribute("cke-preset");if(!t)throw new Error('CKEditor5 hook requires a "cke-preset" attribute on the element.');const{type:e,config:n,license:o}=JSON.parse(t);if(!e||!n||!o)throw new Error('CKEditor5 hook configuration must include "editor", "config", and "license" properties.');if(!P.includes(e))throw new Error(`Invalid editor type: ${e}. Must be one of: ${P.join(", ")}.`);return{type:e,config:n,license:o}}function M(i,t){const{editing:e}=i;e.view.change(n=>{n.setStyle("height",`${t}px`,e.view.document.getRoot())})}class U extends E{editorPromise=null;get attrs(){const t={editorId:this.el.getAttribute("id"),preset:N(this.el),editableHeight:v(this.el.getAttribute("cke-editable-height")),changeEvent:this.el.getAttribute("cke-change-event")!==null,saveDebounceMs:v(this.el.getAttribute("cke-save-debounce-ms"))??400};return Object.defineProperty(this,"attrs",{value:t,writable:!1,configurable:!1,enumerable:!0}),t}async mounted(){return this.editorPromise=this.createEditor(),l.the.register(this.attrs.editorId,await this.editorPromise),this}async destroyed(){this.el.style.display="none",(await this.editorPromise)?.destroy(),this.editorPromise=null,l.the.unregister(this.attrs.editorId)}async createEditor(){const{preset:t,editorId:e,editableHeight:n,changeEvent:o,saveDebounceMs:s}=this.attrs,{type:r,license:a,config:{plugins:c,...h}}=t,m=await j(r),b=B(e,r),u=await m.create(b,{...h,initialData:F(e,r),licenseKey:a.key,plugins:await D(c)});if(o&&this.setupContentPush(e,u,s),this.handleEvent("ckeditor5:set-data",({data:d})=>{u.setData(d)}),y(r)){const d=document.getElementById(`${e}_input`);d&&K(d,u,s),n&&M(u,n)}return u}setupContentPush(t,e,n){const o=()=>{this.pushEvent("ckeditor5:change",{editorId:t,data:x(e)})};e.model.document.on("change:data",p(n,o)),o()}}function x(i){return i.model.document.getRootNames().reduce((e,n)=>(e[n]=i.getData({rootName:n}),e),Object.create({}))}function K(i,t,e){const n=()=>{const o=t.getData();i.value=o,i.dispatchEvent(new Event("input",{bubbles:!0}))};t.model.document.on("change:data",p(e,n)),q(i)?.addEventListener("submit",n),n()}function q(i){return i.closest("form")}function B(i,t){if(y(t))return document.getElementById(`${i}_editor`);const e=f(i);return I(e,({content:n})=>n)}function F(i,t){if(t==="decoupled"){const n=f(i).main?.initialValue;if(n)return n}if(y(t))return document.getElementById(i)?.getAttribute("cke-initial-value")||"";const e=f(i);return I(e,({initialValue:n})=>n)}const L=k(U);class _ extends E{mountedPromise=null;get attrs(){const t={editorId:this.el.getAttribute("data-cke-editor-id")||null,name:this.el.getAttribute("data-cke-ui-part-name")};return Object.defineProperty(this,"attrs",{value:t,writable:!1,configurable:!1,enumerable:!0}),t}async mounted(){const{editorId:t,name:e}=this.attrs;this.mountedPromise=l.the.execute(t,n=>{const{ui:o}=n,s=z(e),r=o.view[s];if(!r){console.error(`Unknown UI part name: "${e}". Supported names are "toolbar" and "menubar".`);return}this.el.appendChild(r.element)})}async destroyed(){this.el.style.display="none",await this.mountedPromise,this.mountedPromise=null,this.el.innerHTML=""}}function z(i){switch(i){case"toolbar":return"toolbar";case"menubar":return"menuBarView";default:return null}}const G=k(_),J={CKEditor5:L,CKEditable:O,CKUIPart:G};exports.EditorsRegistry=l;exports.Hooks=J;
//# sourceMappingURL=index.cjs.map