Packages
ckeditor5_phoenix
1.2.1
1.28.2
1.28.1
1.28.0
1.27.2
1.27.1
1.27.0
1.26.0
1.25.1
1.25.0
1.24.2
1.24.1
1.24.0
1.23.0
1.22.0
1.21.0
1.20.0
1.19.0
1.18.0
1.17.2
1.17.1
1.17.0
1.16.1
1.16.0
1.15.8
1.15.7
1.15.6
1.15.5
1.15.4
1.15.3
1.15.2
1.15.1
1.15.0
1.14.2
1.14.1
1.14.0
1.13.0
1.12.0
1.11.0
1.10.2
1.10.1
1.10.0
1.9.0
1.8.0
1.7.0
1.6.0
1.5.0
1.4.1
1.4.0
1.3.0
1.2.1
1.2.0
1.1.0
1.0.8
1.0.7
CKEditor 5 integration for Phoenix Framework
Current section
Files
Jump to
Current section
Files
dist/index.cjs
"use strict";var v=Object.create;var k=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var R=(n,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of A(t))!H.call(n,o)&&o!==e&&k(n,o,{get:()=>t[o],enumerable:!(i=I(t,o))||i.enumerable});return n};var b=(n,t,e)=>(e=n!=null?v(C(n)):{},R(t||!n||!n.__esModule?k(e,"default",{value:n,enumerable:!0}):e,n));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function f(n,t){let e=null;return(...i)=>{e&&clearTimeout(e),e=setTimeout(()=>{t(...i)},n)}}class p{el;liveSocket;pushEvent;pushEventTo;handleEvent}function E(n){return{mounted(){const t=new n;this.el.instance=t,t.el=this.el,t.liveSocket=this.liveSocket,t.pushEvent=(e,i,o)=>this.pushEvent?.(e,i,o),t.pushEventTo=(e,i,o,r)=>this.pushEventTo?.(e,i,o,r),t.handleEvent=(e,i)=>this.handleEvent?.(e,i),t.mounted?.()},beforeUpdate(){this.el.instance.beforeUpdate?.()},destroyed(){this.el.instance.destroyed?.()},disconnected(){this.el.instance.disconnected?.()},reconnected(){this.el.instance.reconnected?.()}}}function P(n,t){const e=Object.entries(n).map(([i,o])=>[i,t(o,i)]);return Object.fromEntries(e)}function S(n){if(n===null)return null;const t=Number.parseInt(n,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:i,editors:o}=this,r=o.get(t);return r?Promise.resolve(e(r)):new Promise(s=>{const a=async u=>s(await e(u));this.callbacks.has(t)||i.set(t,[]),i.set(t,[...i.get(t),a])})}register(t,e){const{editors:i,callbacks:o}=this,r=o.get(t);if(i.has(t))throw new Error(`Editor with ID "${t}" is already registered.`);i.set(t,e),r&&(r.forEach(s=>s(e)),o.delete(t)),this.editors.size===1&&this.register(null,e)}unregister(t){const{editors:e,callbacks:i}=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),i.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 V extends p{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:i,initialValue:o}=this.attrs,r=this.el.querySelector(`#${t}_input`);this.mountedPromise=l.the.execute(e,s=>{const{ui:a,editing:u,model:h}=s;if(h.document.getRoot(i))return;s.addRoot(i,{isUndoable:!1,data:o});const m=this.el.querySelector("[data-cke-editable-content]"),c=a.view.createEditable(i,m);a.addEditable(c),u.view.forceRender(),r&&O(r,s,i)})}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,i=>{const o=i.model.document.getRoot(e);o&&(i.detachEditable(o),i.detachRoot(e,!1))})}}const $=E(V);function O(n,t,e){const i=()=>{n.value=t.getData({rootName:e})};t.model.document.on("change:data",f(100,i)),i()}function y(n){return["inline","classic","balloon","decoupled"].includes(n)}async function T(n){const t=await import("ckeditor5"),i={inline:t.InlineEditor,balloon:t.BalloonEditor,classic:t.ClassicEditor,decoupled:t.DecoupledEditor,multiroot:t.MultiRootEditor}[n];if(!i)throw new Error(`Unsupported editor type: ${n}`);return i}async function j(n){const t=await import("ckeditor5");let e=null;const i=n.map(async o=>{const{[o]:r}=t;if(r)return r;if(!e)try{e=await import("ckeditor5-premium-features")}catch(a){console.error(`Failed to load premium package: ${a}`)}const{[o]:s}=e||{};if(s)return s;throw new Error(`Plugin "${o}" not found in base or premium packages.`)});return Promise.all(i)}function g(n){const t=document.querySelectorAll([`[data-cke-editor-id="${n}"][data-cke-editable-root-name]`,"[data-cke-editable-root-name]:not([data-cke-editor-id])"].join(", "));return Array.from(t).reduce((e,i)=>{const o=i.getAttribute("data-cke-editable-root-name"),r=i.getAttribute("data-cke-editable-initial-value")||"",s=i.querySelector("[data-cke-editable-content]");return!o||!s?e:{...e,[o]:{content:s,initialValue:r}}},Object.create({}))}const w=["inline","classic","balloon","decoupled","multiroot"];function N(n){const t=n.getAttribute("cke-preset");if(!t)throw new Error('CKEditor5 hook requires a "cke-preset" attribute on the element.');const{type:e,config:i,license:o}=JSON.parse(t);if(!e||!i||!o)throw new Error('CKEditor5 hook configuration must include "editor", "config", and "license" properties.');if(!w.includes(e))throw new Error(`Invalid editor type: ${e}. Must be one of: ${w.join(", ")}.`);return{type:e,config:i,license:o}}function U(n,t){const{editing:e}=n;e.view.change(i=>{i.setStyle("height",`${t}px`,e.view.document.getRoot())})}class x extends p{editorPromise=null;get attrs(){const t={editorId:this.el.getAttribute("id"),preset:N(this.el),editableHeight:S(this.el.getAttribute("cke-editable-height")),changeEvent:this.el.getAttribute("cke-change-event")!==null};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:i,changeEvent:o}=this.attrs,{type:r,license:s,config:{plugins:a,...u}}=t,h=await T(r),m=q(e,r),c=await h.create(m,{...u,initialData:B(e,r),licenseKey:s.key,plugins:await j(a)});if(o&&this.setupContentPush(e,c),this.handleEvent("ckeditor5:set-data",({data:d})=>{c.setData(d)}),y(r)){const d=document.getElementById(`${e}_input`);d&&M(d,c),i&&U(c,i)}return c}setupContentPush(t,e){const i=()=>{this.pushEvent("ckeditor5:change",{editorId:t,data:D(e)})};e.model.document.on("change:data",f(250,i)),i()}}function D(n){return n.model.document.getRootNames().reduce((e,i)=>(e[i]=n.getData({rootName:i}),e),Object.create({}))}function M(n,t){const e=()=>{n.value=t.getData()};t.model.document.on("change:data",f(250,e)),K(n)?.addEventListener("submit",e),e()}function K(n){return n.closest("form")}function q(n,t){if(y(t))return document.getElementById(`${n}_editor`);const e=g(n);return P(e,({content:i})=>i)}function B(n,t){if(t==="decoupled"){const i=g(n).main?.initialValue;if(i)return i}if(y(t))return document.getElementById(n)?.getAttribute("cke-initial-value")||"";const e=g(n);return P(e,({initialValue:i})=>i)}const F=E(x);class L extends p{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,i=>{const{ui:o}=i,r=_(e),s=o.view[r];if(!s){console.error(`Unknown UI part name: "${e}". Supported names are "toolbar" and "menubar".`);return}this.el.appendChild(s.element)})}async destroyed(){this.el.style.display="none",await this.mountedPromise,this.mountedPromise=null,this.el.innerHTML=""}}function _(n){switch(n){case"toolbar":return"toolbar";case"menubar":return"menuBarView";default:return null}}const z=E(L),G={CKEditor5:F,CKEditable:$,CKUIPart:z};exports.EditorsRegistry=l;exports.Hooks=G;
//# sourceMappingURL=index.cjs.map