ckeditor5-phoenix 1.24.0 → 1.24.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/context/context.d.ts +1 -1
- package/dist/hooks/context/context.d.ts.map +1 -1
- package/dist/hooks/editable.d.ts +1 -1
- package/dist/hooks/editable.d.ts.map +1 -1
- package/dist/hooks/editor/editor.d.ts +1 -1
- package/dist/hooks/editor/editor.d.ts.map +1 -1
- package/dist/hooks/editor/utils/cleanup-orphan-editor-elements.d.ts +8 -0
- package/dist/hooks/editor/utils/cleanup-orphan-editor-elements.d.ts.map +1 -0
- package/dist/hooks/editor/utils/index.d.ts +1 -0
- package/dist/hooks/editor/utils/index.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +4 -4
- package/dist/hooks/ui-part.d.ts +1 -1
- package/dist/hooks/ui-part.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +164 -133
- package/dist/index.mjs.map +1 -1
- package/dist/shared/async-registry.d.ts +6 -0
- package/dist/shared/async-registry.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/hooks/editable.test.ts +3 -3
- package/src/hooks/editor/editor.test.ts +3 -3
- package/src/hooks/editor/editor.ts +13 -1
- package/src/hooks/editor/utils/cleanup-orphan-editor-elements.test.ts +155 -0
- package/src/hooks/editor/utils/cleanup-orphan-editor-elements.ts +56 -0
- package/src/hooks/editor/utils/index.ts +1 -0
- package/src/shared/async-registry.test.ts +19 -5
- package/src/shared/async-registry.ts +9 -0
- package/src/shared/hook.test.ts +4 -4
|
@@ -6,5 +6,5 @@ export declare function getNearestContextParentPromise(el: HTMLElement): Promise
|
|
|
6
6
|
/**
|
|
7
7
|
* Phoenix LiveView hook for CKEditor 5 context elements.
|
|
8
8
|
*/
|
|
9
|
-
export declare const ContextHook: import('../../types').RequiredBy<import('phoenix_live_view').Hook<any>, "mounted" | "destroyed">;
|
|
9
|
+
export declare const ContextHook: import('../../types').RequiredBy<import('phoenix_live_view').Hook<any, HTMLElement>, "mounted" | "destroyed">;
|
|
10
10
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/hooks/context/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAoJ1D;;GAEG;AACH,wBAAsB,8BAA8B,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAQ9G;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/hooks/context/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAoJ1D;;GAEG;AACH,wBAAsB,8BAA8B,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAQ9G;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,+GAA4B,CAAC"}
|
package/dist/hooks/editable.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Phoenix LiveView hook for CKEditor 5 editable elements.
|
|
3
3
|
*/
|
|
4
|
-
export declare const EditableHook: import('../types').RequiredBy<import('phoenix_live_view').Hook<any>, "mounted" | "destroyed">;
|
|
4
|
+
export declare const EditableHook: import('../types').RequiredBy<import('phoenix_live_view').Hook<any, HTMLElement>, "mounted" | "destroyed">;
|
|
5
5
|
//# sourceMappingURL=editable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editable.d.ts","sourceRoot":"","sources":["../../src/hooks/editable.ts"],"names":[],"mappings":"AAiIA;;GAEG;AACH,eAAO,MAAM,YAAY
|
|
1
|
+
{"version":3,"file":"editable.d.ts","sourceRoot":"","sources":["../../src/hooks/editable.ts"],"names":[],"mappings":"AAiIA;;GAEG;AACH,eAAO,MAAM,YAAY,4GAA6B,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Phoenix LiveView hook for CKEditor 5.
|
|
3
3
|
*/
|
|
4
|
-
export declare const EditorHook: import('../../types').RequiredBy<import('phoenix_live_view').Hook<any>, "mounted" | "destroyed">;
|
|
4
|
+
export declare const EditorHook: import('../../types').RequiredBy<import('phoenix_live_view').Hook<any, HTMLElement>, "mounted" | "destroyed">;
|
|
5
5
|
//# sourceMappingURL=editor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../src/hooks/editor/editor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../src/hooks/editor/editor.ts"],"names":[],"mappings":"AA6WA;;GAEG;AACH,eAAO,MAAM,UAAU,+GAA2B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Editor } from 'ckeditor5';
|
|
2
|
+
/**
|
|
3
|
+
* Removes all DOM elements injected by a specific CKEditor instance.
|
|
4
|
+
* Call this before assigning a new instance (e.g. in the 'restart' watchdog handler),
|
|
5
|
+
* because the watchdog does not clean up the previous editor's DOM on its own.
|
|
6
|
+
*/
|
|
7
|
+
export declare function cleanupOrphanEditorElements(editor: Editor): void;
|
|
8
|
+
//# sourceMappingURL=cleanup-orphan-editor-elements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanup-orphan-editor-elements.d.ts","sourceRoot":"","sources":["../../../../src/hooks/editor/utils/cleanup-orphan-editor-elements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAgDhE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/editor/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,6CAA6C,CAAC;AAC5D,cAAc,sCAAsC,CAAC;AACrD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/editor/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,6CAA6C,CAAC;AAC5D,cAAc,sCAAsC,CAAC;AACrD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const Hooks: {
|
|
2
|
-
CKEditor5: import('../types').RequiredBy<import('phoenix_live_view').Hook<any>, "mounted" | "destroyed">;
|
|
3
|
-
CKEditable: import('../types').RequiredBy<import('phoenix_live_view').Hook<any>, "mounted" | "destroyed">;
|
|
4
|
-
CKUIPart: import('../types').RequiredBy<import('phoenix_live_view').Hook<any>, "mounted" | "destroyed">;
|
|
5
|
-
CKContext: import('../types').RequiredBy<import('phoenix_live_view').Hook<any>, "mounted" | "destroyed">;
|
|
2
|
+
CKEditor5: import('../types').RequiredBy<import('phoenix_live_view').Hook<any, HTMLElement>, "mounted" | "destroyed">;
|
|
3
|
+
CKEditable: import('../types').RequiredBy<import('phoenix_live_view').Hook<any, HTMLElement>, "mounted" | "destroyed">;
|
|
4
|
+
CKUIPart: import('../types').RequiredBy<import('phoenix_live_view').Hook<any, HTMLElement>, "mounted" | "destroyed">;
|
|
5
|
+
CKContext: import('../types').RequiredBy<import('phoenix_live_view').Hook<any, HTMLElement>, "mounted" | "destroyed">;
|
|
6
6
|
};
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/hooks/ui-part.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Phoenix LiveView hook for CKEditor 5 UI parts.
|
|
3
3
|
*/
|
|
4
|
-
export declare const UIPartHook: import('../types').RequiredBy<import('phoenix_live_view').Hook<any>, "mounted" | "destroyed">;
|
|
4
|
+
export declare const UIPartHook: import('../types').RequiredBy<import('phoenix_live_view').Hook<any, HTMLElement>, "mounted" | "destroyed">;
|
|
5
5
|
//# sourceMappingURL=ui-part.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-part.d.ts","sourceRoot":"","sources":["../../src/hooks/ui-part.ts"],"names":[],"mappings":"AA0FA;;GAEG;AACH,eAAO,MAAM,UAAU
|
|
1
|
+
{"version":3,"file":"ui-part.d.ts","sourceRoot":"","sources":["../../src/hooks/ui-part.ts"],"names":[],"mappings":"AA0FA;;GAEG;AACH,eAAO,MAAM,UAAU,4GAA2B,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var at=Object.create;var z=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var st=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty;var ct=(a,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of nt(t))!ot.call(a,n)&&n!==e&&z(a,n,{get:()=>t[n],enumerable:!(i=it(t,n))||i.enumerable});return a};var r=(a,t,e)=>(e=a!=null?at(st(a)):{},ct(t||!a||!a.__esModule?z(e,"default",{value:a,enumerable:!0}):e,a));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class B{items=new Map;initializationErrors=new Map;pendingCallbacks=new Map;watchers=new Set;execute(t,e,i){const n=this.items.get(t),s=this.initializationErrors.get(t);return s?(i?.(s),Promise.reject(s)):n?Promise.resolve(e(n)):new Promise((o,u)=>{const c=this.getPendingCallbacks(t);c.success.push(async l=>{o(await e(l))}),i?c.error.push(i):c.error.push(u)})}register(t,e){if(this.items.has(t))throw new Error(`Item with ID "${t}" is already registered.`);this.resetErrors(t),this.items.set(t,e);const i=this.pendingCallbacks.get(t);i&&(i.success.forEach(n=>n(e)),this.pendingCallbacks.delete(t)),this.registerAsDefault(t,e),this.notifyWatchers()}error(t,e){this.items.delete(t),this.initializationErrors.set(t,e);const i=this.pendingCallbacks.get(t);i&&(i.error.forEach(n=>n(e)),this.pendingCallbacks.delete(t)),this.initializationErrors.size===1&&!this.items.size&&this.error(null,e),this.notifyWatchers()}resetErrors(t){const{initializationErrors:e}=this;e.has(null)&&e.get(null)===e.get(t)&&e.delete(null),e.delete(t)}unregister(t){if(!this.items.has(t))throw new Error(`Item with ID "${t}" is not registered.`);t&&this.items.get(null)===this.items.get(t)&&this.unregister(null),this.items.delete(t),this.pendingCallbacks.delete(t),this.notifyWatchers()}getItems(){return Array.from(this.items.values())}hasItem(t){return this.items.has(t)}waitFor(t){return new Promise((e,i)=>{this.execute(t,e,i)})}async destroyAll(){const t=Array.from(new Set(this.items.values())).map(e=>e.destroy());this.items.clear(),this.pendingCallbacks.clear(),await Promise.all(t),this.notifyWatchers()}watch(t){return this.watchers.add(t),t(new Map(this.items),new Map(this.initializationErrors)),this.unwatch.bind(this,t)}unwatch(t){this.watchers.delete(t)}notifyWatchers(){this.watchers.forEach(t=>t(new Map(this.items),new Map(this.initializationErrors)))}getPendingCallbacks(t){let e=this.pendingCallbacks.get(t);return e||(e={success:[],error:[]},this.pendingCallbacks.set(t,e)),e}registerAsDefault(t,e){this.items.size===1&&t!==null&&this.register(null,e)}}function ut(a){return a.replace(/[-_\s]+(.)?/g,(t,e)=>e?e.toUpperCase():"").replace(/^./,t=>t.toLowerCase())}function C(a,t){let e=null;return(...i)=>{e&&clearTimeout(e),e=setTimeout(()=>{t(...i)},a)}}function lt(a){if(Object.prototype.toString.call(a)!=="[object Object]")return!1;const t=Object.getPrototypeOf(a);return t===Object.prototype||t===null}function A(a){if(Array.isArray(a))return a.map(A);if(lt(a)){const t=Object.create(null);for(const[e,i]of Object.entries(a))t[ut(e)]=A(i);return t}return a}function dt(a,t){const e=Object.entries(a).filter(([i,n])=>t(n,i));return Object.fromEntries(e)}function ht(){const a=document.querySelector('meta[name="csrf-token"]');if(a)return a.getAttribute("content");const t=document.cookie.match(/(?:^|; )_csrf_token=([^;]*)/);return t?decodeURIComponent(t[1]):null}class x{state="mounting";el;_beforeDestroyCallbacks=[];onBeforeDestroy(t){this._beforeDestroyCallbacks.push(t)}pushEvent;pushEventTo;handleEvent;mounted(){}destroyed(){}updated(){}isBeingDestroyed(){return this.state==="destroyed"||this.state==="destroying"}_runBeforeDestroyCallbacks(){for(const t of this._beforeDestroyCallbacks.reverse())t();this._beforeDestroyCallbacks=[]}}function O(a){return{async mounted(){const t=new a;this.el.instance=t,t.el=this.el,t.pushEvent=(i,n,s)=>this.pushEvent?.(i,n,s),t.pushEventTo=(i,n,s,o)=>this.pushEventTo?.(i,n,s,o),t.handleEvent=(i,n)=>this.handleEvent?.(i,n),t.state="mounting";const e=await t.mounted?.();return t.state="mounted",e},beforeUpdate(){this.el.instance.beforeUpdate?.()},async destroyed(){const{instance:t}=this.el;t.state="destroying",t._runBeforeDestroyCallbacks(),await t.destroyed?.(),t.state="destroyed"},disconnected(){this.el.instance.disconnected?.()},reconnected(){this.el.instance.reconnected?.()},updated(){return this.el.instance.updated?.()}}}function L(a){return Object.keys(a).length===0&&a.constructor===Object}function mt(a){return a==null}function $(a,t){const e=Object.entries(a).map(([i,n])=>[i,t(n,i)]);return Object.fromEntries(e)}function _(a){if(a===null)return null;const t=Number.parseInt(a,10);return Number.isNaN(t)?null:t}function pt(a){return a==null||a.trim()===""?null:JSON.parse(a)}function ft(a,t){if(a===t)return!0;const e=Object.keys(a),i=Object.keys(t);if(e.length!==i.length)return!1;for(const n of e)if(a[n]!==t[n]||!Object.prototype.hasOwnProperty.call(t,n))return!1;return!0}function wt(){return Math.random().toString(36).substring(2)}function gt(a,{timeOutAfter:t=500,retryAfter:e=100}={}){return new Promise((i,n)=>{const s=Date.now();let o=null;const u=setTimeout(()=>{n(o??new Error("Timeout"))},t),c=async()=>{try{const l=await a();clearTimeout(u),i(l)}catch(l){o=l,Date.now()-s>t?n(l):setTimeout(c,e)}};c()})}const R=Symbol.for("context-editor-watchdog");async function yt({element:a,context:t,creator:e,config:i}){const n=wt();await t.add({creator:(c,l)=>e.create(c,l),id:n,sourceElementOrData:a,type:"editor",config:i});const s=t.getItem(n),o={state:"available",editorContextId:n,context:t};s[R]=o;const u=t.destroy.bind(t);return t.destroy=async()=>(o.state="unavailable",u()),{...o,editor:s}}function K(a){return R in a?a[R]:null}function P(a){return["inline","classic","balloon","decoupled"].includes(a)}async function bt(a){const t=await import("ckeditor5"),i={inline:t.InlineEditor,balloon:t.BalloonEditor,classic:t.ClassicEditor,decoupled:t.DecoupledEditor,multiroot:t.MultiRootEditor}[a];if(!i)throw new Error(`Unsupported editor type: ${a}`);return i}class D{static the=new D;plugins=new Map;constructor(){}register(t,e){if(this.plugins.has(t))throw new Error(`Plugin with name "${t}" is already registered.`);return this.plugins.set(t,e),this.unregister.bind(this,t)}unregister(t){if(!this.plugins.has(t))throw new Error(`Plugin with name "${t}" is not registered.`);this.plugins.delete(t)}unregisterAll(){this.plugins.clear()}async get(t){return this.plugins.get(t)?.()}has(t){return this.plugins.has(t)}}async function Y(a){const t=await import("ckeditor5");let e=null;const i=a.map(async n=>{const s=await D.the.get(n);if(s)return s;const{[n]:o}=t;if(o)return o;if(!e)try{e=await import("ckeditor5-premium-features")}catch(c){console.error(`Failed to load premium package: ${c}`)}const{[n]:u}=e||{};if(u)return u;throw new Error(`Plugin "${n}" not found in base or premium packages.`)});return{loadedPlugins:await Promise.all(i),hasPremium:!!e}}async function J(a,t){const e=[a.ui,a.content];return await Promise.all([q("ckeditor5",e),t&&q("ckeditor5-premium-features",e)].filter(n=>!!n)).then(n=>n.flat())}async function q(a,t){return await Promise.all(t.filter(e=>e!=="en").map(async e=>{const i=await kt(a,e);return i?.default??i}).filter(Boolean))}async function kt(a,t){try{if(a==="ckeditor5")switch(t){case"af":return await import("ckeditor5/translations/af.js");case"ar":return await import("ckeditor5/translations/ar.js");case"ast":return await import("ckeditor5/translations/ast.js");case"az":return await import("ckeditor5/translations/az.js");case"bg":return await import("ckeditor5/translations/bg.js");case"bn":return await import("ckeditor5/translations/bn.js");case"bs":return await import("ckeditor5/translations/bs.js");case"ca":return await import("ckeditor5/translations/ca.js");case"cs":return await import("ckeditor5/translations/cs.js");case"da":return await import("ckeditor5/translations/da.js");case"de":return await import("ckeditor5/translations/de.js");case"de-ch":return await import("ckeditor5/translations/de-ch.js");case"el":return await import("ckeditor5/translations/el.js");case"en":return await import("ckeditor5/translations/en.js");case"en-au":return await import("ckeditor5/translations/en-au.js");case"en-gb":return await import("ckeditor5/translations/en-gb.js");case"eo":return await import("ckeditor5/translations/eo.js");case"es":return await import("ckeditor5/translations/es.js");case"es-co":return await import("ckeditor5/translations/es-co.js");case"et":return await import("ckeditor5/translations/et.js");case"eu":return await import("ckeditor5/translations/eu.js");case"fa":return await import("ckeditor5/translations/fa.js");case"fi":return await import("ckeditor5/translations/fi.js");case"fr":return await import("ckeditor5/translations/fr.js");case"gl":return await import("ckeditor5/translations/gl.js");case"gu":return await import("ckeditor5/translations/gu.js");case"he":return await import("ckeditor5/translations/he.js");case"hi":return await import("ckeditor5/translations/hi.js");case"hr":return await import("ckeditor5/translations/hr.js");case"hu":return await import("ckeditor5/translations/hu.js");case"hy":return await import("ckeditor5/translations/hy.js");case"id":return await import("ckeditor5/translations/id.js");case"it":return await import("ckeditor5/translations/it.js");case"ja":return await import("ckeditor5/translations/ja.js");case"jv":return await import("ckeditor5/translations/jv.js");case"kk":return await import("ckeditor5/translations/kk.js");case"km":return await import("ckeditor5/translations/km.js");case"kn":return await import("ckeditor5/translations/kn.js");case"ko":return await import("ckeditor5/translations/ko.js");case"ku":return await import("ckeditor5/translations/ku.js");case"lt":return await import("ckeditor5/translations/lt.js");case"lv":return await import("ckeditor5/translations/lv.js");case"ms":return await import("ckeditor5/translations/ms.js");case"nb":return await import("ckeditor5/translations/nb.js");case"ne":return await import("ckeditor5/translations/ne.js");case"nl":return await import("ckeditor5/translations/nl.js");case"no":return await import("ckeditor5/translations/no.js");case"oc":return await import("ckeditor5/translations/oc.js");case"pl":return await import("ckeditor5/translations/pl.js");case"pt":return await import("ckeditor5/translations/pt.js");case"pt-br":return await import("ckeditor5/translations/pt-br.js");case"ro":return await import("ckeditor5/translations/ro.js");case"ru":return await import("ckeditor5/translations/ru.js");case"si":return await import("ckeditor5/translations/si.js");case"sk":return await import("ckeditor5/translations/sk.js");case"sl":return await import("ckeditor5/translations/sl.js");case"sq":return await import("ckeditor5/translations/sq.js");case"sr":return await import("ckeditor5/translations/sr.js");case"sr-latn":return await import("ckeditor5/translations/sr-latn.js");case"sv":return await import("ckeditor5/translations/sv.js");case"th":return await import("ckeditor5/translations/th.js");case"tk":return await import("ckeditor5/translations/tk.js");case"tr":return await import("ckeditor5/translations/tr.js");case"tt":return await import("ckeditor5/translations/tt.js");case"ug":return await import("ckeditor5/translations/ug.js");case"uk":return await import("ckeditor5/translations/uk.js");case"ur":return await import("ckeditor5/translations/ur.js");case"uz":return await import("ckeditor5/translations/uz.js");case"vi":return await import("ckeditor5/translations/vi.js");case"zh":return await import("ckeditor5/translations/zh.js");case"zh-cn":return await import("ckeditor5/translations/zh-cn.js");default:return console.warn(`Language ${t} not found in ckeditor5 translations`),null}else switch(t){case"af":return await import("ckeditor5-premium-features/translations/af.js");case"ar":return await import("ckeditor5-premium-features/translations/ar.js");case"ast":return await import("ckeditor5-premium-features/translations/ast.js");case"az":return await import("ckeditor5-premium-features/translations/az.js");case"bg":return await import("ckeditor5-premium-features/translations/bg.js");case"bn":return await import("ckeditor5-premium-features/translations/bn.js");case"bs":return await import("ckeditor5-premium-features/translations/bs.js");case"ca":return await import("ckeditor5-premium-features/translations/ca.js");case"cs":return await import("ckeditor5-premium-features/translations/cs.js");case"da":return await import("ckeditor5-premium-features/translations/da.js");case"de":return await import("ckeditor5-premium-features/translations/de.js");case"de-ch":return await import("ckeditor5-premium-features/translations/de-ch.js");case"el":return await import("ckeditor5-premium-features/translations/el.js");case"en":return await import("ckeditor5-premium-features/translations/en.js");case"en-au":return await import("ckeditor5-premium-features/translations/en-au.js");case"en-gb":return await import("ckeditor5-premium-features/translations/en-gb.js");case"eo":return await import("ckeditor5-premium-features/translations/eo.js");case"es":return await import("ckeditor5-premium-features/translations/es.js");case"es-co":return await import("ckeditor5-premium-features/translations/es-co.js");case"et":return await import("ckeditor5-premium-features/translations/et.js");case"eu":return await import("ckeditor5-premium-features/translations/eu.js");case"fa":return await import("ckeditor5-premium-features/translations/fa.js");case"fi":return await import("ckeditor5-premium-features/translations/fi.js");case"fr":return await import("ckeditor5-premium-features/translations/fr.js");case"gl":return await import("ckeditor5-premium-features/translations/gl.js");case"gu":return await import("ckeditor5-premium-features/translations/gu.js");case"he":return await import("ckeditor5-premium-features/translations/he.js");case"hi":return await import("ckeditor5-premium-features/translations/hi.js");case"hr":return await import("ckeditor5-premium-features/translations/hr.js");case"hu":return await import("ckeditor5-premium-features/translations/hu.js");case"hy":return await import("ckeditor5-premium-features/translations/hy.js");case"id":return await import("ckeditor5-premium-features/translations/id.js");case"it":return await import("ckeditor5-premium-features/translations/it.js");case"ja":return await import("ckeditor5-premium-features/translations/ja.js");case"jv":return await import("ckeditor5-premium-features/translations/jv.js");case"kk":return await import("ckeditor5-premium-features/translations/kk.js");case"km":return await import("ckeditor5-premium-features/translations/km.js");case"kn":return await import("ckeditor5-premium-features/translations/kn.js");case"ko":return await import("ckeditor5-premium-features/translations/ko.js");case"ku":return await import("ckeditor5-premium-features/translations/ku.js");case"lt":return await import("ckeditor5-premium-features/translations/lt.js");case"lv":return await import("ckeditor5-premium-features/translations/lv.js");case"ms":return await import("ckeditor5-premium-features/translations/ms.js");case"nb":return await import("ckeditor5-premium-features/translations/nb.js");case"ne":return await import("ckeditor5-premium-features/translations/ne.js");case"nl":return await import("ckeditor5-premium-features/translations/nl.js");case"no":return await import("ckeditor5-premium-features/translations/no.js");case"oc":return await import("ckeditor5-premium-features/translations/oc.js");case"pl":return await import("ckeditor5-premium-features/translations/pl.js");case"pt":return await import("ckeditor5-premium-features/translations/pt.js");case"pt-br":return await import("ckeditor5-premium-features/translations/pt-br.js");case"ro":return await import("ckeditor5-premium-features/translations/ro.js");case"ru":return await import("ckeditor5-premium-features/translations/ru.js");case"si":return await import("ckeditor5-premium-features/translations/si.js");case"sk":return await import("ckeditor5-premium-features/translations/sk.js");case"sl":return await import("ckeditor5-premium-features/translations/sl.js");case"sq":return await import("ckeditor5-premium-features/translations/sq.js");case"sr":return await import("ckeditor5-premium-features/translations/sr.js");case"sr-latn":return await import("ckeditor5-premium-features/translations/sr-latn.js");case"sv":return await import("ckeditor5-premium-features/translations/sv.js");case"th":return await import("ckeditor5-premium-features/translations/th.js");case"tk":return await import("ckeditor5-premium-features/translations/tk.js");case"tr":return await import("ckeditor5-premium-features/translations/tr.js");case"tt":return await import("ckeditor5-premium-features/translations/tt.js");case"ug":return await import("ckeditor5-premium-features/translations/ug.js");case"uk":return await import("ckeditor5-premium-features/translations/uk.js");case"ur":return await import("ckeditor5-premium-features/translations/ur.js");case"uz":return await import("ckeditor5-premium-features/translations/uz.js");case"vi":return await import("ckeditor5-premium-features/translations/vi.js");case"zh":return await import("ckeditor5-premium-features/translations/zh.js");case"zh-cn":return await import("ckeditor5-premium-features/translations/zh-cn.js");default:return console.warn(`Language ${t} not found in premium translations`),await import("ckeditor5-premium-features/translations/en.js")}}catch(e){return console.error(`Failed to load translation for ${a}/${t}:`,e),null}}function G(a){return $(a,t=>({dictionary:t}))}function X(a){const t=Q(a);return $(t,({content:e})=>e)}function F(a){const t=Q(a),e=$(t,({initialValue:i})=>i);return dt(e,i=>typeof i=="string")}function Q(a){const t=document.querySelectorAll([`[data-cke-editor-id="${a}"][data-cke-editable-root-name]`,"[data-cke-editable-root-name]:not([data-cke-editor-id])"].join(", ")),e=Array.from(t).reduce((u,c)=>{const l=c.getAttribute("data-cke-editable-root-name"),d=c.getAttribute("data-cke-editable-initial-value")||"",h=c.querySelector("[data-cke-editable-content]");return!l||!h?u:{...u,[l]:{content:h,initialValue:d}}},Object.create({})),i=document.querySelector(`[phx-hook="CKEditor5"][id="${a}"]`);if(!i)return e;const n=i.getAttribute("data-cke-initial-value")||"",s=i.querySelector(`#${a}_editor `),o=e.main;return o?{...e,main:{...o,initialValue:o.initialValue||n}}:s?{...e,main:{content:s,initialValue:n}}:e}const W=["inline","classic","balloon","decoupled","multiroot"];function Et(a){const t=a.getAttribute("data-cke-preset");if(!t)throw new Error('CKEditor5 hook requires a "cke-preset" attribute on the element.');const{type:e,config:i,license:n,...s}=JSON.parse(t);if(!e||!i||!n)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,license:n,config:A(i),customTranslations:s.customTranslations||s.custom_translations}}function T(a){if(!a||typeof a!="object")return a;if(Array.isArray(a))return a.map(i=>T(i));const t=a;if(t.$element&&typeof t.$element=="string"){const i=document.querySelector(t.$element);return i||console.warn(`Element not found for selector: ${t.$element}`),i||null}const e=Object.create(null);for(const[i,n]of Object.entries(a))e[i]=T(n);return e}function I(a,t,e){if(!e||typeof e!="object")return e;if(Array.isArray(e))return e.map(s=>I(a,t,s));const i=e;if(i.$translation&&typeof i.$translation=="string"){const s=i.$translation,o=vt(a,s,t);return o===void 0&&console.warn(`Translation not found for key: ${s}`),o!==void 0?o:null}const n=Object.create(null);for(const[s,o]of Object.entries(e))n[s]=I(a,t,o);return n}function vt(a,t,e){for(const i of a){const n=i[e];if(n?.dictionary&&t in n.dictionary)return n.dictionary[t]}}function Pt(a,t){const{editing:e}=a;e.view.change(i=>{i.setStyle("height",`${t}px`,e.view.document.getRoot())})}const V=Symbol.for("elixir-editor-watchdog");async function Ct(a){const{EditorWatchdog:t}=await import("ckeditor5"),e=new t(a);return e.setCreator(async(...i)=>{const n=await a.create(...i);return n[V]=e,n}),{watchdog:e,Constructor:{create:async(...i)=>(await e.create(...i),e.editor)}}}function Z(a){return V in a?a[V]:null}class w extends B{static the=new w}function At(a){const t=a.getAttribute("data-cke-context");if(!t)throw new Error('CKEditor5 hook requires a "data-cke-context" attribute on the element.');const{config:e,...i}=JSON.parse(t);return{config:A(e),customTranslations:i.customTranslations||i.custom_translations,watchdogConfig:i.watchdogConfig||i.watchdog_config}}class Tt extends x{contextPromise=null;get attrs(){const t=i=>this.el.getAttribute(i)||null,e={id:this.el.id,config:At(this.el),language:{ui:t("data-cke-language")||"en",content:t("data-cke-content-language")||"en"}};return Object.defineProperty(this,"attrs",{value:e,writable:!1,configurable:!1,enumerable:!0}),e}async mounted(){const{id:t,language:e}=this.attrs,{customTranslations:i,watchdogConfig:n,config:{plugins:s,...o}}=this.attrs.config,{loadedPlugins:u,hasPremium:c}=await Y(s??[]),d=[...await J(e,c),G(i?.dictionary||{})].filter(f=>!L(f));let h=T(o);h=I([...d].reverse(),e.ui,h),this.contextPromise=(async()=>{const{ContextWatchdog:f,Context:b}=await import("ckeditor5"),g=new f(b,{crashNumberLimit:10,...n});return await g.create({...h,language:e,plugins:u,...d.length&&{translations:d}}),g.on("itemError",(...E)=>{console.error("Context item error:",...E)}),g})();const y=await this.contextPromise;this.isBeingDestroyed()||w.the.register(t,y)}async destroyed(){const{id:t}=this.attrs;this.el.style.display="none";try{await(await this.contextPromise)?.destroy()}finally{this.contextPromise=null,w.the.hasItem(t)&&w.the.unregister(t)}}}function It(a){return a.hasAttribute("data-cke-context")}function xt(a){let t=a;for(;t;){if(It(t))return t;t=t.parentElement}return null}async function Ot(a){const t=xt(a);return t?w.the.waitFor(t.id):null}const Dt=O(Tt);class p extends B{static the=new p}function St(a,t){const e=new Set;return i=>{let n=!1;return a.model.enqueueChange({isUndoable:!1},s=>{const o=a.model.document.getRoot(t);if(o){for(const u of e)i&&u in i||(s.removeAttribute(u,o),e.delete(u),n=!0);for(const[u,c]of Object.entries(i??{}))s.setAttribute(u,c,o),e.add(u),n=!0}}),n}}async function Nt(){const{Plugin:a,FileRepository:t}=await import("ckeditor5");return class extends a{static get pluginName(){return"PhoenixUploadAdapter"}static get requires(){return[t]}init(){const{editor:i}=this,{plugins:n,config:s}=i,o=s.get("phoenixUpload.url");if(!o||n.has("SimpleUploadAdapter")||n.has("Base64UploadAdapter")||n.has("CKFinderUploadAdapter"))return;const u=n.get(t);u.createUploadAdapter=c=>new Rt(c,o)}}}class Rt{loader;uploadUrl;abortController=null;constructor(t,e){this.loader=t,this.uploadUrl=e}async upload(){const t=await this.loader.file;this.abortController=new AbortController;const e=new FormData;e.append("file",t),t.size&&(this.loader.uploadTotal=t.size,this.loader.uploaded=0);const i={},n=ht();n&&(i["X-CSRF-Token"]=n);try{const s=await fetch(this.uploadUrl,{method:"POST",headers:i,body:e,signal:this.abortController.signal});if(!s.ok){let u="Couldn't upload file!";try{const c=await s.json();c?.error?.message&&(u=c.error.message)}catch{}throw new Error(u)}return this.loader.uploaded=this.loader.uploadTotal,{default:(await s.json()).url}}catch(s){throw s.name==="AbortError"?s:s.message||"Couldn't upload file!"}}abort(){this.abortController?.abort(),this.abortController=null}}async function Vt({editorId:a,saveDebounceMs:t}){const{Plugin:e}=await import("ckeditor5");return class extends e{input=null;form=null;static get pluginName(){return"SyncEditorWithInput"}afterInit(){const{editor:n}=this;this.input=document.getElementById(`${a}_input`),this.input&&(n.model.document.on("change:data",C(t,()=>this.sync())),n.once("ready",this.sync),this.form=this.input.closest("form"),this.form?.addEventListener("submit",this.sync))}sync=()=>{const n=this.editor.getData();this.input.value=n,this.input.dispatchEvent(new Event("input",{bubbles:!0}))};destroy(){this.form&&this.form.removeEventListener("submit",this.sync),this.input=null,this.form=null}}}const U=Symbol("suppress-phoenix-sync");async function Ut(a){const{Plugin:t}=await import("ckeditor5"),{editorId:e,saveDebounceMs:i,events:n,pushEvent:s,handleEvent:o}=a;return class extends t{static get pluginName(){return"SyncEditorWithPhoenix"}init(){const{editor:c}=this;n.change&&this.setupTypingContentPush(),n.blur&&this.setupEventPush("blur"),n.focus&&this.setupEventPush("focus"),n.ready&&this.editor.once("ready",()=>{s("ckeditor5:ready",{editorId:e,data:N(c)})}),o("ckeditor5:set-data",({editorId:l,data:d})=>{(mt(l)||l===e)&&c.setData(d)})}setupTypingContentPush(){const{editor:c}=this;let l=null,d=!1;const h=()=>{if(d)return;const f=N(c);(!l||!ft(l,f))&&(s("ckeditor5:change",{editorId:e,data:f}),l=f)},y=C(i,h);c.model.document.on("change:data",C(10,f=>{if($t(f)){l=null;return}c.ui.focusTracker.isFocused?y():h()})),c.once("ready",h),c.once("destroy",()=>{d=!0})}setupEventPush(c){const{editor:l}=this,d=()=>{const{isFocused:h}=l.ui.focusTracker;(h?"focus":"blur")===c&&s(`ckeditor5:${c}`,{editorId:e,data:N(l)})};l.ui.focusTracker.on("change:isFocused",d)}}}function N(a){return a.model.document.getRootNames().reduce((e,i)=>(e[i]=a.getData({rootName:i}),e),Object.create({}))}function $t(a){const t=a[U];return delete a[U],!!t}function jt(a){let t=!1;const e=i=>{t||(i[U]=!0)};return a.model.document.once("change:data",e,{priority:"highest"}),()=>{t=!0,a.model.document.off("change:data",e)}}class tt{el;editorId;rootName;valueAttrName;rootAttrsAttrName;isDestroyed=!1;cleanupCallbacks=[];editorPromise=null;pendingValue=null;previousValue=null;attrsUpdater=null;constructor({el:t,editorId:e,rootName:i,valueAttrName:n="data-cke-value",rootAttrsAttrName:s="data-cke-root-attrs"}){this.el=t,this.editorId=e,this.rootName=i,this.valueAttrName=n,this.rootAttrsAttrName=s;const{value:o}=this.attrs;this.previousValue=o,this.editorPromise=p.the.execute(this.editorId,u=>this.isDestroyed?null:(this.setupSyncHandlers(u,this.rootName),u))}get attrs(){return{rootAttributes:pt(this.el.getAttribute(this.rootAttrsAttrName)),value:this.el.getAttribute(this.valueAttrName)}}async updated(){const{value:t,rootAttributes:e}=this.attrs,i=await this.editorPromise;if(!i||i.state==="destroyed"||this.isDestroyed)return;let n=()=>{};i.model.enqueueChange({isUndoable:!1},()=>{let s=this.attrsUpdater?.(e);t!==this.previousValue&&(this.previousValue=t,i.ui.focusTracker.isFocused?this.pendingValue=t:(this.setRootValue(i,this.rootName,t),s=!0)),s&&(n=jt(i))}),n()}setupSyncHandlers(t,e){this.attrsUpdater=St(t,e),this.attrsUpdater(this.attrs.rootAttributes);const i=()=>{this.pendingValue=null},n=()=>{!t.ui.focusTracker.isFocused&&this.pendingValue!==null&&(this.setRootValue(t,e,this.pendingValue),this.pendingValue=null)};t.model.document.on("change:data",i),t.ui.focusTracker.on("change:isFocused",n),this.cleanupCallbacks.push(()=>{t.model.document.off("change:data",i),t.ui.focusTracker.off("change:isFocused",n)})}setRootValue(t,e,i){t.getData({rootName:e})!==i&&t.setData({[e]:i})}destroy(){this.isDestroyed=!0,this.cleanupCallbacks.forEach(t=>t()),this.cleanupCallbacks=[]}}class Mt extends x{editorPromise=null;sentinel=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:n}=this.attrs,s=this.el.querySelector(`#${t}_input`);this.editorPromise=p.the.execute(e,async o=>{if(this.isBeingDestroyed())return null;const{ui:u,editing:c,model:l}=o;if(!l.document.getRoot(i)){o.addRoot(i,{isUndoable:!1,data:n});const d=this.el.querySelector("[data-cke-editable-content]"),h=u.view.createEditable(i,d);u.addEditable(h),c.view.forceRender()}if(this.sentinel=new tt({el:this.el,valueAttrName:"data-cke-editable-initial-value",rootAttrsAttrName:"data-cke-editable-root-attrs",editorId:e,rootName:i}),s){const d=zt(s,o,i);this.onBeforeDestroy(d)}return o})}async updated(){this.sentinel?.updated()}async destroyed(){const{rootName:t}=this.attrs;this.el.style.display="none",this.sentinel?.destroy(),this.sentinel=null;const e=await this.editorPromise;if(this.editorPromise=null,e&&e.state!=="destroyed"){const i=e.model.document.getRoot(t);i&&"detachEditable"in e&&(e.ui.view.editables[t]&&e.detachEditable(i),i.isAttached()&&e.detachRoot(t,!1))}}}const Ht=O(Mt);function zt(a,t,e){const i=()=>{a.value=t.getData({rootName:e})},n=C(200,i);return t.model.document.on("change:data",n),i(),()=>{t.model.document.off("change:data",n)}}class _t extends x{editorPromise=null;sentinel=null;get attrs(){const{el:t}=this,e=t.getAttribute.bind(t),i=t.hasAttribute.bind(t),n={editorId:e("id"),contextId:e("data-cke-context-id"),preset:Et(t),editableHeight:_(e("data-cke-editable-height")),watchdog:i("data-cke-watchdog"),events:{change:i("data-cke-change-event"),blur:i("data-cke-blur-event"),focus:i("data-cke-focus-event"),ready:i("data-cke-ready-event")},saveDebounceMs:_(e("data-cke-save-debounce-ms"))??400,language:{ui:e("data-cke-language")||"en",content:e("data-cke-content-language")||"en"}};return Object.defineProperty(this,"attrs",{value:n,writable:!1,configurable:!1,enumerable:!0}),n}async mounted(){const{editorId:t}=this.attrs;p.the.resetErrors(t);try{this.editorPromise=this.createEditor();const e=await this.editorPromise;this.isBeingDestroyed()||(p.the.register(t,e),e.once("destroy",()=>{p.the.hasItem(t)&&p.the.unregister(t)}),this.sentinel=new tt({editorId:t,el:this.el,rootName:"main",valueAttrName:"data-cke-initial-value",rootAttrsAttrName:"data-cke-root-attrs"}))}catch(e){this.editorPromise=null,p.the.error(t,e)}return this}async updated(){this.sentinel?.updated()}async destroyed(){this.el.style.display="none",this.sentinel?.destroy(),this.sentinel=null;try{const t=await this.editorPromise;if(!t)return;const e=K(t),i=Z(t);e?e.state!=="unavailable"&&await e.context.remove(e.editorContextId):i?await i.destroy():await t.destroy()}finally{this.editorPromise=null}}async createEditor(){const{preset:t,editorId:e,contextId:i,editableHeight:n,events:s,saveDebounceMs:o,language:u,watchdog:c}=this.attrs,{customTranslations:l,type:d,license:h,config:{plugins:y,...f}}=t;let b=await bt(d);const g=await(i?w.the.waitFor(i):Ot(this.el));if(c&&!g){const m=await Ct(b);({Constructor:b}=m),m.watchdog.on("restart",()=>{const k=m.watchdog.editor;this.editorPromise=Promise.resolve(k),p.the.register(e,k)})}const{loadedPlugins:E,hasPremium:rt}=await Y(y);P(d)&&E.push(await Vt({editorId:e,saveDebounceMs:o})),E.push(...await Promise.all([Ut({editorId:e,saveDebounceMs:o,events:s,pushEvent:this.pushEvent.bind(this),handleEvent:this.handleEvent.bind(this)}),Nt()]));const S=[...await J(u,rt),G(l?.dictionary||{})].filter(m=>!L(m));let v=F(e);P(d)&&(v=v.main||"");const j=await(async()=>{let m=X(e);if(!(m instanceof HTMLElement)&&!("main"in m)){const H=d==="decoupled"?["main"]:Object.keys(v);et(m,H)||(m=await qt(e,H),v=F(e))}P(d)&&"main"in m&&(m=m.main);let k=T(f);k=I([...S].reverse(),u.ui,k);const M={...k,initialData:v,licenseKey:h.key,plugins:E,language:u,...S.length&&{translations:S}};return!g||!(m instanceof HTMLElement)?b.create(m,M):(await yt({context:g,element:m,creator:b,config:M})).editor})();return P(d)&&n&&Pt(j,n),j}}function et(a,t){return t.every(e=>a[e])}async function qt(a,t){return gt(()=>{const e=X(a);if(!et(e,t))throw new Error(`It looks like not all required root elements are present yet.
|
|
1
|
+
"use strict";var at=Object.create;var j=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var st=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty;var ct=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of nt(t))!ot.call(r,n)&&n!==e&&j(r,n,{get:()=>t[n],enumerable:!(i=it(t,n))||i.enumerable});return r};var a=(r,t,e)=>(e=r!=null?at(st(r)):{},ct(t||!r||!r.__esModule?j(e,"default",{value:r,enumerable:!0}):e,r));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class L{items=new Map;initializationErrors=new Map;pendingCallbacks=new Map;watchers=new Set;execute(t,e,i){const n=this.items.get(t),s=this.initializationErrors.get(t);return s?(i?.(s),Promise.reject(s)):n?Promise.resolve(e(n)):new Promise((o,u)=>{const c=this.getPendingCallbacks(t);c.success.push(async l=>{o(await e(l))}),i?c.error.push(i):c.error.push(u)})}register(t,e){if(this.items.has(t))throw new Error(`Item with ID "${t}" is already registered.`);this.resetErrors(t),this.items.set(t,e);const i=this.pendingCallbacks.get(t);i&&(i.success.forEach(n=>n(e)),this.pendingCallbacks.delete(t)),this.registerAsDefault(t,e),this.notifyWatchers()}error(t,e){this.items.delete(t),this.initializationErrors.set(t,e);const i=this.pendingCallbacks.get(t);i&&(i.error.forEach(n=>n(e)),this.pendingCallbacks.delete(t)),this.initializationErrors.size===1&&!this.items.size&&this.error(null,e),this.notifyWatchers()}resetErrors(t){const{initializationErrors:e}=this;e.has(null)&&e.get(null)===e.get(t)&&e.delete(null),e.delete(t)}unregister(t){if(!this.items.has(t))throw new Error(`Item with ID "${t}" is not registered.`);t&&this.items.get(null)===this.items.get(t)&&this.unregister(null),this.items.delete(t),this.pendingCallbacks.delete(t),this.notifyWatchers()}getItems(){return Array.from(this.items.values())}getItem(t){return this.items.get(t)}hasItem(t){return this.items.has(t)}waitFor(t){return new Promise((e,i)=>{this.execute(t,e,i)})}async destroyAll(){const t=Array.from(new Set(this.items.values())).map(e=>e.destroy());this.items.clear(),this.pendingCallbacks.clear(),await Promise.all(t),this.notifyWatchers()}watch(t){return this.watchers.add(t),t(new Map(this.items),new Map(this.initializationErrors)),this.unwatch.bind(this,t)}unwatch(t){this.watchers.delete(t)}notifyWatchers(){this.watchers.forEach(t=>t(new Map(this.items),new Map(this.initializationErrors)))}getPendingCallbacks(t){let e=this.pendingCallbacks.get(t);return e||(e={success:[],error:[]},this.pendingCallbacks.set(t,e)),e}registerAsDefault(t,e){this.items.size===1&&t!==null&&this.register(null,e)}}function ut(r){return r.replace(/[-_\s]+(.)?/g,(t,e)=>e?e.toUpperCase():"").replace(/^./,t=>t.toLowerCase())}function A(r,t){let e=null;return(...i)=>{e&&clearTimeout(e),e=setTimeout(()=>{t(...i)},r)}}function lt(r){if(Object.prototype.toString.call(r)!=="[object Object]")return!1;const t=Object.getPrototypeOf(r);return t===Object.prototype||t===null}function T(r){if(Array.isArray(r))return r.map(T);if(lt(r)){const t=Object.create(null);for(const[e,i]of Object.entries(r))t[ut(e)]=T(i);return t}return r}function dt(r,t){const e=Object.entries(r).filter(([i,n])=>t(n,i));return Object.fromEntries(e)}function mt(){const r=document.querySelector('meta[name="csrf-token"]');if(r)return r.getAttribute("content");const t=document.cookie.match(/(?:^|; )_csrf_token=([^;]*)/);return t?decodeURIComponent(t[1]):null}class O{state="mounting";el;_beforeDestroyCallbacks=[];onBeforeDestroy(t){this._beforeDestroyCallbacks.push(t)}pushEvent;pushEventTo;handleEvent;mounted(){}destroyed(){}updated(){}isBeingDestroyed(){return this.state==="destroyed"||this.state==="destroying"}_runBeforeDestroyCallbacks(){for(const t of this._beforeDestroyCallbacks.reverse())t();this._beforeDestroyCallbacks=[]}}function D(r){return{async mounted(){const t=new r;this.el.instance=t,t.el=this.el,t.pushEvent=(i,n,s)=>this.pushEvent?.(i,n,s),t.pushEventTo=(i,n,s,o)=>this.pushEventTo?.(i,n,s,o),t.handleEvent=(i,n)=>this.handleEvent?.(i,n),t.state="mounting";const e=await t.mounted?.();return t.state="mounted",e},beforeUpdate(){this.el.instance.beforeUpdate?.()},async destroyed(){const{instance:t}=this.el;t.state="destroying",t._runBeforeDestroyCallbacks(),await t.destroyed?.(),t.state="destroyed"},disconnected(){this.el.instance.disconnected?.()},reconnected(){this.el.instance.reconnected?.()},updated(){return this.el.instance.updated?.()}}}function B(r){return Object.keys(r).length===0&&r.constructor===Object}function ht(r){return r==null}function M(r,t){const e=Object.entries(r).map(([i,n])=>[i,t(n,i)]);return Object.fromEntries(e)}function z(r){if(r===null)return null;const t=Number.parseInt(r,10);return Number.isNaN(t)?null:t}function pt(r){return r==null||r.trim()===""?null:JSON.parse(r)}function ft(r,t){if(r===t)return!0;const e=Object.keys(r),i=Object.keys(t);if(e.length!==i.length)return!1;for(const n of e)if(r[n]!==t[n]||!Object.prototype.hasOwnProperty.call(t,n))return!1;return!0}function wt(){return Math.random().toString(36).substring(2)}function gt(r,{timeOutAfter:t=500,retryAfter:e=100}={}){return new Promise((i,n)=>{const s=Date.now();let o=null;const u=setTimeout(()=>{n(o??new Error("Timeout"))},t),c=async()=>{try{const l=await r();clearTimeout(u),i(l)}catch(l){o=l,Date.now()-s>t?n(l):setTimeout(c,e)}};c()})}function yt(r){const t=r.ui?.element;t?.isConnected&&n(t);const e=r.ui?.view?.body?._bodyCollectionContainer;e?.isConnected&&n(e);const i=r.editing?.view;if(i)for(const s of i.domRoots.values())s instanceof HTMLElement&&(s.removeAttribute("contenteditable"),s.removeAttribute("role"),s.removeAttribute("aria-label"),s.removeAttribute("aria-multiline"),s.removeAttribute("spellcheck"),s.classList.remove("ck","ck-content","ck-editor__editable","ck-rounded-corners","ck-editor__editable_inline","ck-blurred","ck-focused"),n(s));function n(s){s.hasAttribute("data-cke-controlled")?s.innerHTML="":s.remove()}}const V=Symbol.for("context-editor-watchdog");async function bt({element:r,context:t,creator:e,config:i}){const n=wt();await t.add({creator:(c,l)=>e.create(c,l),id:n,sourceElementOrData:r,type:"editor",config:i});const s=t.getItem(n),o={state:"available",editorContextId:n,context:t};s[V]=o;const u=t.destroy.bind(t);return t.destroy=async()=>(o.state="unavailable",u()),{...o,editor:s}}function K(r){return V in r?r[V]:null}function P(r){return["inline","classic","balloon","decoupled"].includes(r)}async function kt(r){const t=await import("ckeditor5"),i={inline:t.InlineEditor,balloon:t.BalloonEditor,classic:t.ClassicEditor,decoupled:t.DecoupledEditor,multiroot:t.MultiRootEditor}[r];if(!i)throw new Error(`Unsupported editor type: ${r}`);return i}class S{static the=new S;plugins=new Map;constructor(){}register(t,e){if(this.plugins.has(t))throw new Error(`Plugin with name "${t}" is already registered.`);return this.plugins.set(t,e),this.unregister.bind(this,t)}unregister(t){if(!this.plugins.has(t))throw new Error(`Plugin with name "${t}" is not registered.`);this.plugins.delete(t)}unregisterAll(){this.plugins.clear()}async get(t){return this.plugins.get(t)?.()}has(t){return this.plugins.has(t)}}async function Y(r){const t=await import("ckeditor5");let e=null;const i=r.map(async n=>{const s=await S.the.get(n);if(s)return s;const{[n]:o}=t;if(o)return o;if(!e)try{e=await import("ckeditor5-premium-features")}catch(c){console.error(`Failed to load premium package: ${c}`)}const{[n]:u}=e||{};if(u)return u;throw new Error(`Plugin "${n}" not found in base or premium packages.`)});return{loadedPlugins:await Promise.all(i),hasPremium:!!e}}async function J(r,t){const e=[r.ui,r.content];return await Promise.all([q("ckeditor5",e),t&&q("ckeditor5-premium-features",e)].filter(n=>!!n)).then(n=>n.flat())}async function q(r,t){return await Promise.all(t.filter(e=>e!=="en").map(async e=>{const i=await Et(r,e);return i?.default??i}).filter(Boolean))}async function Et(r,t){try{if(r==="ckeditor5")switch(t){case"af":return await import("ckeditor5/translations/af.js");case"ar":return await import("ckeditor5/translations/ar.js");case"ast":return await import("ckeditor5/translations/ast.js");case"az":return await import("ckeditor5/translations/az.js");case"bg":return await import("ckeditor5/translations/bg.js");case"bn":return await import("ckeditor5/translations/bn.js");case"bs":return await import("ckeditor5/translations/bs.js");case"ca":return await import("ckeditor5/translations/ca.js");case"cs":return await import("ckeditor5/translations/cs.js");case"da":return await import("ckeditor5/translations/da.js");case"de":return await import("ckeditor5/translations/de.js");case"de-ch":return await import("ckeditor5/translations/de-ch.js");case"el":return await import("ckeditor5/translations/el.js");case"en":return await import("ckeditor5/translations/en.js");case"en-au":return await import("ckeditor5/translations/en-au.js");case"en-gb":return await import("ckeditor5/translations/en-gb.js");case"eo":return await import("ckeditor5/translations/eo.js");case"es":return await import("ckeditor5/translations/es.js");case"es-co":return await import("ckeditor5/translations/es-co.js");case"et":return await import("ckeditor5/translations/et.js");case"eu":return await import("ckeditor5/translations/eu.js");case"fa":return await import("ckeditor5/translations/fa.js");case"fi":return await import("ckeditor5/translations/fi.js");case"fr":return await import("ckeditor5/translations/fr.js");case"gl":return await import("ckeditor5/translations/gl.js");case"gu":return await import("ckeditor5/translations/gu.js");case"he":return await import("ckeditor5/translations/he.js");case"hi":return await import("ckeditor5/translations/hi.js");case"hr":return await import("ckeditor5/translations/hr.js");case"hu":return await import("ckeditor5/translations/hu.js");case"hy":return await import("ckeditor5/translations/hy.js");case"id":return await import("ckeditor5/translations/id.js");case"it":return await import("ckeditor5/translations/it.js");case"ja":return await import("ckeditor5/translations/ja.js");case"jv":return await import("ckeditor5/translations/jv.js");case"kk":return await import("ckeditor5/translations/kk.js");case"km":return await import("ckeditor5/translations/km.js");case"kn":return await import("ckeditor5/translations/kn.js");case"ko":return await import("ckeditor5/translations/ko.js");case"ku":return await import("ckeditor5/translations/ku.js");case"lt":return await import("ckeditor5/translations/lt.js");case"lv":return await import("ckeditor5/translations/lv.js");case"ms":return await import("ckeditor5/translations/ms.js");case"nb":return await import("ckeditor5/translations/nb.js");case"ne":return await import("ckeditor5/translations/ne.js");case"nl":return await import("ckeditor5/translations/nl.js");case"no":return await import("ckeditor5/translations/no.js");case"oc":return await import("ckeditor5/translations/oc.js");case"pl":return await import("ckeditor5/translations/pl.js");case"pt":return await import("ckeditor5/translations/pt.js");case"pt-br":return await import("ckeditor5/translations/pt-br.js");case"ro":return await import("ckeditor5/translations/ro.js");case"ru":return await import("ckeditor5/translations/ru.js");case"si":return await import("ckeditor5/translations/si.js");case"sk":return await import("ckeditor5/translations/sk.js");case"sl":return await import("ckeditor5/translations/sl.js");case"sq":return await import("ckeditor5/translations/sq.js");case"sr":return await import("ckeditor5/translations/sr.js");case"sr-latn":return await import("ckeditor5/translations/sr-latn.js");case"sv":return await import("ckeditor5/translations/sv.js");case"th":return await import("ckeditor5/translations/th.js");case"tk":return await import("ckeditor5/translations/tk.js");case"tr":return await import("ckeditor5/translations/tr.js");case"tt":return await import("ckeditor5/translations/tt.js");case"ug":return await import("ckeditor5/translations/ug.js");case"uk":return await import("ckeditor5/translations/uk.js");case"ur":return await import("ckeditor5/translations/ur.js");case"uz":return await import("ckeditor5/translations/uz.js");case"vi":return await import("ckeditor5/translations/vi.js");case"zh":return await import("ckeditor5/translations/zh.js");case"zh-cn":return await import("ckeditor5/translations/zh-cn.js");default:return console.warn(`Language ${t} not found in ckeditor5 translations`),null}else switch(t){case"af":return await import("ckeditor5-premium-features/translations/af.js");case"ar":return await import("ckeditor5-premium-features/translations/ar.js");case"ast":return await import("ckeditor5-premium-features/translations/ast.js");case"az":return await import("ckeditor5-premium-features/translations/az.js");case"bg":return await import("ckeditor5-premium-features/translations/bg.js");case"bn":return await import("ckeditor5-premium-features/translations/bn.js");case"bs":return await import("ckeditor5-premium-features/translations/bs.js");case"ca":return await import("ckeditor5-premium-features/translations/ca.js");case"cs":return await import("ckeditor5-premium-features/translations/cs.js");case"da":return await import("ckeditor5-premium-features/translations/da.js");case"de":return await import("ckeditor5-premium-features/translations/de.js");case"de-ch":return await import("ckeditor5-premium-features/translations/de-ch.js");case"el":return await import("ckeditor5-premium-features/translations/el.js");case"en":return await import("ckeditor5-premium-features/translations/en.js");case"en-au":return await import("ckeditor5-premium-features/translations/en-au.js");case"en-gb":return await import("ckeditor5-premium-features/translations/en-gb.js");case"eo":return await import("ckeditor5-premium-features/translations/eo.js");case"es":return await import("ckeditor5-premium-features/translations/es.js");case"es-co":return await import("ckeditor5-premium-features/translations/es-co.js");case"et":return await import("ckeditor5-premium-features/translations/et.js");case"eu":return await import("ckeditor5-premium-features/translations/eu.js");case"fa":return await import("ckeditor5-premium-features/translations/fa.js");case"fi":return await import("ckeditor5-premium-features/translations/fi.js");case"fr":return await import("ckeditor5-premium-features/translations/fr.js");case"gl":return await import("ckeditor5-premium-features/translations/gl.js");case"gu":return await import("ckeditor5-premium-features/translations/gu.js");case"he":return await import("ckeditor5-premium-features/translations/he.js");case"hi":return await import("ckeditor5-premium-features/translations/hi.js");case"hr":return await import("ckeditor5-premium-features/translations/hr.js");case"hu":return await import("ckeditor5-premium-features/translations/hu.js");case"hy":return await import("ckeditor5-premium-features/translations/hy.js");case"id":return await import("ckeditor5-premium-features/translations/id.js");case"it":return await import("ckeditor5-premium-features/translations/it.js");case"ja":return await import("ckeditor5-premium-features/translations/ja.js");case"jv":return await import("ckeditor5-premium-features/translations/jv.js");case"kk":return await import("ckeditor5-premium-features/translations/kk.js");case"km":return await import("ckeditor5-premium-features/translations/km.js");case"kn":return await import("ckeditor5-premium-features/translations/kn.js");case"ko":return await import("ckeditor5-premium-features/translations/ko.js");case"ku":return await import("ckeditor5-premium-features/translations/ku.js");case"lt":return await import("ckeditor5-premium-features/translations/lt.js");case"lv":return await import("ckeditor5-premium-features/translations/lv.js");case"ms":return await import("ckeditor5-premium-features/translations/ms.js");case"nb":return await import("ckeditor5-premium-features/translations/nb.js");case"ne":return await import("ckeditor5-premium-features/translations/ne.js");case"nl":return await import("ckeditor5-premium-features/translations/nl.js");case"no":return await import("ckeditor5-premium-features/translations/no.js");case"oc":return await import("ckeditor5-premium-features/translations/oc.js");case"pl":return await import("ckeditor5-premium-features/translations/pl.js");case"pt":return await import("ckeditor5-premium-features/translations/pt.js");case"pt-br":return await import("ckeditor5-premium-features/translations/pt-br.js");case"ro":return await import("ckeditor5-premium-features/translations/ro.js");case"ru":return await import("ckeditor5-premium-features/translations/ru.js");case"si":return await import("ckeditor5-premium-features/translations/si.js");case"sk":return await import("ckeditor5-premium-features/translations/sk.js");case"sl":return await import("ckeditor5-premium-features/translations/sl.js");case"sq":return await import("ckeditor5-premium-features/translations/sq.js");case"sr":return await import("ckeditor5-premium-features/translations/sr.js");case"sr-latn":return await import("ckeditor5-premium-features/translations/sr-latn.js");case"sv":return await import("ckeditor5-premium-features/translations/sv.js");case"th":return await import("ckeditor5-premium-features/translations/th.js");case"tk":return await import("ckeditor5-premium-features/translations/tk.js");case"tr":return await import("ckeditor5-premium-features/translations/tr.js");case"tt":return await import("ckeditor5-premium-features/translations/tt.js");case"ug":return await import("ckeditor5-premium-features/translations/ug.js");case"uk":return await import("ckeditor5-premium-features/translations/uk.js");case"ur":return await import("ckeditor5-premium-features/translations/ur.js");case"uz":return await import("ckeditor5-premium-features/translations/uz.js");case"vi":return await import("ckeditor5-premium-features/translations/vi.js");case"zh":return await import("ckeditor5-premium-features/translations/zh.js");case"zh-cn":return await import("ckeditor5-premium-features/translations/zh-cn.js");default:return console.warn(`Language ${t} not found in premium translations`),await import("ckeditor5-premium-features/translations/en.js")}}catch(e){return console.error(`Failed to load translation for ${r}/${t}:`,e),null}}function G(r){return M(r,t=>({dictionary:t}))}function X(r){const t=Q(r);return M(t,({content:e})=>e)}function F(r){const t=Q(r),e=M(t,({initialValue:i})=>i);return dt(e,i=>typeof i=="string")}function Q(r){const t=document.querySelectorAll([`[data-cke-editor-id="${r}"][data-cke-editable-root-name]`,"[data-cke-editable-root-name]:not([data-cke-editor-id])"].join(", ")),e=Array.from(t).reduce((u,c)=>{const l=c.getAttribute("data-cke-editable-root-name"),d=c.getAttribute("data-cke-editable-initial-value")||"",m=c.querySelector("[data-cke-editable-content]");return!l||!m?u:{...u,[l]:{content:m,initialValue:d}}},Object.create({})),i=document.querySelector(`[phx-hook="CKEditor5"][id="${r}"]`);if(!i)return e;const n=i.getAttribute("data-cke-initial-value")||"",s=i.querySelector(`#${r}_editor `),o=e.main;return o?{...e,main:{...o,initialValue:o.initialValue||n}}:s?{...e,main:{content:s,initialValue:n}}:e}const W=["inline","classic","balloon","decoupled","multiroot"];function vt(r){const t=r.getAttribute("data-cke-preset");if(!t)throw new Error('CKEditor5 hook requires a "cke-preset" attribute on the element.');const{type:e,config:i,license:n,...s}=JSON.parse(t);if(!e||!i||!n)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,license:n,config:T(i),customTranslations:s.customTranslations||s.custom_translations}}function I(r){if(!r||typeof r!="object")return r;if(Array.isArray(r))return r.map(i=>I(i));const t=r;if(t.$element&&typeof t.$element=="string"){const i=document.querySelector(t.$element);return i||console.warn(`Element not found for selector: ${t.$element}`),i||null}const e=Object.create(null);for(const[i,n]of Object.entries(r))e[i]=I(n);return e}function x(r,t,e){if(!e||typeof e!="object")return e;if(Array.isArray(e))return e.map(s=>x(r,t,s));const i=e;if(i.$translation&&typeof i.$translation=="string"){const s=i.$translation,o=Ct(r,s,t);return o===void 0&&console.warn(`Translation not found for key: ${s}`),o!==void 0?o:null}const n=Object.create(null);for(const[s,o]of Object.entries(e))n[s]=x(r,t,o);return n}function Ct(r,t,e){for(const i of r){const n=i[e];if(n?.dictionary&&t in n.dictionary)return n.dictionary[t]}}function Pt(r,t){const{editing:e}=r;e.view.change(i=>{i.setStyle("height",`${t}px`,e.view.document.getRoot())})}const U=Symbol.for("elixir-editor-watchdog");async function At(r){const{EditorWatchdog:t}=await import("ckeditor5"),e=new t(r);return e.setCreator(async(...i)=>{const n=await r.create(...i);return n[U]=e,n}),{watchdog:e,Constructor:{create:async(...i)=>(await e.create(...i),e.editor)}}}function Z(r){return U in r?r[U]:null}class w extends L{static the=new w}function Tt(r){const t=r.getAttribute("data-cke-context");if(!t)throw new Error('CKEditor5 hook requires a "data-cke-context" attribute on the element.');const{config:e,...i}=JSON.parse(t);return{config:T(e),customTranslations:i.customTranslations||i.custom_translations,watchdogConfig:i.watchdogConfig||i.watchdog_config}}class It extends O{contextPromise=null;get attrs(){const t=i=>this.el.getAttribute(i)||null,e={id:this.el.id,config:Tt(this.el),language:{ui:t("data-cke-language")||"en",content:t("data-cke-content-language")||"en"}};return Object.defineProperty(this,"attrs",{value:e,writable:!1,configurable:!1,enumerable:!0}),e}async mounted(){const{id:t,language:e}=this.attrs,{customTranslations:i,watchdogConfig:n,config:{plugins:s,...o}}=this.attrs.config,{loadedPlugins:u,hasPremium:c}=await Y(s??[]),d=[...await J(e,c),G(i?.dictionary||{})].filter(f=>!B(f));let m=I(o);m=x([...d].reverse(),e.ui,m),this.contextPromise=(async()=>{const{ContextWatchdog:f,Context:b}=await import("ckeditor5"),g=new f(b,{crashNumberLimit:10,...n});return await g.create({...m,language:e,plugins:u,...d.length&&{translations:d}}),g.on("itemError",(...E)=>{console.error("Context item error:",...E)}),g})();const y=await this.contextPromise;this.isBeingDestroyed()||w.the.register(t,y)}async destroyed(){const{id:t}=this.attrs;this.el.style.display="none";try{await(await this.contextPromise)?.destroy()}finally{this.contextPromise=null,w.the.hasItem(t)&&w.the.unregister(t)}}}function xt(r){return r.hasAttribute("data-cke-context")}function Ot(r){let t=r;for(;t;){if(xt(t))return t;t=t.parentElement}return null}async function Dt(r){const t=Ot(r);return t?w.the.waitFor(t.id):null}const St=D(It);class p extends L{static the=new p}function Nt(r,t){const e=new Set;return i=>{let n=!1;return r.model.enqueueChange({isUndoable:!1},s=>{const o=r.model.document.getRoot(t);if(o){for(const u of e)i&&u in i||(s.removeAttribute(u,o),e.delete(u),n=!0);for(const[u,c]of Object.entries(i??{}))s.setAttribute(u,c,o),e.add(u),n=!0}}),n}}async function Rt(){const{Plugin:r,FileRepository:t}=await import("ckeditor5");return class extends r{static get pluginName(){return"PhoenixUploadAdapter"}static get requires(){return[t]}init(){const{editor:i}=this,{plugins:n,config:s}=i,o=s.get("phoenixUpload.url");if(!o||n.has("SimpleUploadAdapter")||n.has("Base64UploadAdapter")||n.has("CKFinderUploadAdapter"))return;const u=n.get(t);u.createUploadAdapter=c=>new Vt(c,o)}}}class Vt{loader;uploadUrl;abortController=null;constructor(t,e){this.loader=t,this.uploadUrl=e}async upload(){const t=await this.loader.file;this.abortController=new AbortController;const e=new FormData;e.append("file",t),t.size&&(this.loader.uploadTotal=t.size,this.loader.uploaded=0);const i={},n=mt();n&&(i["X-CSRF-Token"]=n);try{const s=await fetch(this.uploadUrl,{method:"POST",headers:i,body:e,signal:this.abortController.signal});if(!s.ok){let u="Couldn't upload file!";try{const c=await s.json();c?.error?.message&&(u=c.error.message)}catch{}throw new Error(u)}return this.loader.uploaded=this.loader.uploadTotal,{default:(await s.json()).url}}catch(s){throw s.name==="AbortError"?s:s.message||"Couldn't upload file!"}}abort(){this.abortController?.abort(),this.abortController=null}}async function Ut({editorId:r,saveDebounceMs:t}){const{Plugin:e}=await import("ckeditor5");return class extends e{input=null;form=null;static get pluginName(){return"SyncEditorWithInput"}afterInit(){const{editor:n}=this;this.input=document.getElementById(`${r}_input`),this.input&&(n.model.document.on("change:data",A(t,()=>this.sync())),n.once("ready",this.sync),this.form=this.input.closest("form"),this.form?.addEventListener("submit",this.sync))}sync=()=>{const n=this.editor.getData();this.input.value=n,this.input.dispatchEvent(new Event("input",{bubbles:!0}))};destroy(){this.form&&this.form.removeEventListener("submit",this.sync),this.input=null,this.form=null}}}const $=Symbol("suppress-phoenix-sync");async function $t(r){const{Plugin:t}=await import("ckeditor5"),{editorId:e,saveDebounceMs:i,events:n,pushEvent:s,handleEvent:o}=r;return class extends t{static get pluginName(){return"SyncEditorWithPhoenix"}init(){const{editor:c}=this;n.change&&this.setupTypingContentPush(),n.blur&&this.setupEventPush("blur"),n.focus&&this.setupEventPush("focus"),n.ready&&this.editor.once("ready",()=>{s("ckeditor5:ready",{editorId:e,data:R(c)})}),o("ckeditor5:set-data",({editorId:l,data:d})=>{(ht(l)||l===e)&&c.setData(d)})}setupTypingContentPush(){const{editor:c}=this;let l=null,d=!1;const m=()=>{if(d)return;const f=R(c);(!l||!ft(l,f))&&(s("ckeditor5:change",{editorId:e,data:f}),l=f)},y=A(i,m);c.model.document.on("change:data",A(10,f=>{if(Mt(f)){l=null;return}c.ui.focusTracker.isFocused?y():m()})),c.once("ready",m),c.once("destroy",()=>{d=!0})}setupEventPush(c){const{editor:l}=this,d=()=>{const{isFocused:m}=l.ui.focusTracker;(m?"focus":"blur")===c&&s(`ckeditor5:${c}`,{editorId:e,data:R(l)})};l.ui.focusTracker.on("change:isFocused",d)}}}function R(r){return r.model.document.getRootNames().reduce((e,i)=>(e[i]=r.getData({rootName:i}),e),Object.create({}))}function Mt(r){const t=r[$];return delete r[$],!!t}function _t(r){let t=!1;const e=i=>{t||(i[$]=!0)};return r.model.document.once("change:data",e,{priority:"highest"}),()=>{t=!0,r.model.document.off("change:data",e)}}class tt{el;editorId;rootName;valueAttrName;rootAttrsAttrName;isDestroyed=!1;cleanupCallbacks=[];editorPromise=null;pendingValue=null;previousValue=null;attrsUpdater=null;constructor({el:t,editorId:e,rootName:i,valueAttrName:n="data-cke-value",rootAttrsAttrName:s="data-cke-root-attrs"}){this.el=t,this.editorId=e,this.rootName=i,this.valueAttrName=n,this.rootAttrsAttrName=s;const{value:o}=this.attrs;this.previousValue=o,this.editorPromise=p.the.execute(this.editorId,u=>this.isDestroyed?null:(this.setupSyncHandlers(u,this.rootName),u))}get attrs(){return{rootAttributes:pt(this.el.getAttribute(this.rootAttrsAttrName)),value:this.el.getAttribute(this.valueAttrName)}}async updated(){const{value:t,rootAttributes:e}=this.attrs,i=await this.editorPromise;if(!i||i.state==="destroyed"||this.isDestroyed)return;let n=()=>{};i.model.enqueueChange({isUndoable:!1},()=>{let s=this.attrsUpdater?.(e);t!==this.previousValue&&(this.previousValue=t,i.ui.focusTracker.isFocused?this.pendingValue=t:(this.setRootValue(i,this.rootName,t),s=!0)),s&&(n=_t(i))}),n()}setupSyncHandlers(t,e){this.attrsUpdater=Nt(t,e),this.attrsUpdater(this.attrs.rootAttributes);const i=()=>{this.pendingValue=null},n=()=>{!t.ui.focusTracker.isFocused&&this.pendingValue!==null&&(this.setRootValue(t,e,this.pendingValue),this.pendingValue=null)};t.model.document.on("change:data",i),t.ui.focusTracker.on("change:isFocused",n),this.cleanupCallbacks.push(()=>{t.model.document.off("change:data",i),t.ui.focusTracker.off("change:isFocused",n)})}setRootValue(t,e,i){t.getData({rootName:e})!==i&&t.setData({[e]:i})}destroy(){this.isDestroyed=!0,this.cleanupCallbacks.forEach(t=>t()),this.cleanupCallbacks=[]}}class Ht extends O{editorPromise=null;sentinel=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:n}=this.attrs,s=this.el.querySelector(`#${t}_input`);this.editorPromise=p.the.execute(e,async o=>{if(this.isBeingDestroyed())return null;const{ui:u,editing:c,model:l}=o;if(!l.document.getRoot(i)){o.addRoot(i,{isUndoable:!1,data:n});const d=this.el.querySelector("[data-cke-editable-content]"),m=u.view.createEditable(i,d);u.addEditable(m),c.view.forceRender()}if(this.sentinel=new tt({el:this.el,valueAttrName:"data-cke-editable-initial-value",rootAttrsAttrName:"data-cke-editable-root-attrs",editorId:e,rootName:i}),s){const d=zt(s,o,i);this.onBeforeDestroy(d)}return o})}async updated(){this.sentinel?.updated()}async destroyed(){const{rootName:t}=this.attrs;this.el.style.display="none",this.sentinel?.destroy(),this.sentinel=null;const e=await this.editorPromise;if(this.editorPromise=null,e&&e.state!=="destroyed"){const i=e.model.document.getRoot(t);i&&"detachEditable"in e&&(e.ui.view.editables[t]&&e.detachEditable(i),i.isAttached()&&e.detachRoot(t,!1))}}}const jt=D(Ht);function zt(r,t,e){const i=()=>{r.value=t.getData({rootName:e})},n=A(200,i);return t.model.document.on("change:data",n),i(),()=>{t.model.document.off("change:data",n)}}class qt extends O{editorPromise=null;sentinel=null;get attrs(){const{el:t}=this,e=t.getAttribute.bind(t),i=t.hasAttribute.bind(t),n={editorId:e("id"),contextId:e("data-cke-context-id"),preset:vt(t),editableHeight:z(e("data-cke-editable-height")),watchdog:i("data-cke-watchdog"),events:{change:i("data-cke-change-event"),blur:i("data-cke-blur-event"),focus:i("data-cke-focus-event"),ready:i("data-cke-ready-event")},saveDebounceMs:z(e("data-cke-save-debounce-ms"))??400,language:{ui:e("data-cke-language")||"en",content:e("data-cke-content-language")||"en"}};return Object.defineProperty(this,"attrs",{value:n,writable:!1,configurable:!1,enumerable:!0}),n}async mounted(){const{editorId:t}=this.attrs;p.the.resetErrors(t);try{this.editorPromise=this.createEditor();const e=await this.editorPromise;this.isBeingDestroyed()||(p.the.register(t,e),e.once("destroy",()=>{p.the.hasItem(t)&&p.the.unregister(t)}),this.sentinel=new tt({editorId:t,el:this.el,rootName:"main",valueAttrName:"data-cke-initial-value",rootAttrsAttrName:"data-cke-root-attrs"}))}catch(e){this.editorPromise=null,p.the.error(t,e)}return this}async updated(){this.sentinel?.updated()}async destroyed(){this.el.style.display="none",this.sentinel?.destroy(),this.sentinel=null;try{const t=await this.editorPromise;if(!t)return;const e=K(t),i=Z(t);e?e.state!=="unavailable"&&await e.context.remove(e.editorContextId):i?await i.destroy():await t.destroy()}finally{this.editorPromise=null}}async createEditor(){const{preset:t,editorId:e,contextId:i,editableHeight:n,events:s,saveDebounceMs:o,language:u,watchdog:c}=this.attrs,{customTranslations:l,type:d,license:m,config:{plugins:y,...f}}=t;let b=await kt(d);const g=await(i?w.the.waitFor(i):Dt(this.el));if(c&&!g){const h=await At(b);({Constructor:b}=h),h.watchdog.on("restart",()=>{const k=p.the.getItem(e);k&&yt(k);const C=h.watchdog.editor;this.editorPromise=Promise.resolve(C),p.the.register(e,C)})}const{loadedPlugins:E,hasPremium:rt}=await Y(y);P(d)&&E.push(await Ut({editorId:e,saveDebounceMs:o})),E.push(...await Promise.all([$t({editorId:e,saveDebounceMs:o,events:s,pushEvent:this.pushEvent.bind(this),handleEvent:this.handleEvent.bind(this)}),Rt()]));const N=[...await J(u,rt),G(l?.dictionary||{})].filter(h=>!B(h));let v=F(e);P(d)&&(v=v.main||"");const _=await(async()=>{let h=X(e);if(!(h instanceof HTMLElement)&&!("main"in h)){const H=d==="decoupled"?["main"]:Object.keys(v);et(h,H)||(h=await Ft(e,H),v=F(e))}P(d)&&"main"in h&&(h=h.main);let k=I(f);k=x([...N].reverse(),u.ui,k);const C={...k,initialData:v,licenseKey:m.key,plugins:E,language:u,...N.length&&{translations:N}};return!g||!(h instanceof HTMLElement)?b.create(h,C):(await bt({context:g,element:h,creator:b,config:C})).editor})();return P(d)&&n&&Pt(_,n),_}}function et(r,t){return t.every(e=>r[e])}async function Ft(r,t){return gt(()=>{const e=X(r);if(!et(e,t))throw new Error(`It looks like not all required root elements are present yet.
|
|
2
2
|
* If you want to wait for them, ensure they are registered before editor initialization.
|
|
3
3
|
* If you want lazy initialize roots, consider removing root values from the \`initialData\` config and assign initial data in editable components.
|
|
4
|
-
Missing roots: ${t.filter(i=>!e[i]).join(", ")}.`);return e},{timeOutAfter:2e3,retryAfter:100})}const
|
|
4
|
+
Missing roots: ${t.filter(i=>!e[i]).join(", ")}.`);return e},{timeOutAfter:2e3,retryAfter:100})}const Wt=D(qt);class Lt extends O{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=p.the.execute(t,i=>{if(this.isBeingDestroyed())return;const{ui:n}=i,s=Bt(e),o=n.view[s];if(!o){console.error(`Unknown UI part name: "${e}". Supported names are "toolbar" and "menubar".`);return}this.el.appendChild(o.element)})}async destroyed(){this.el.style.display="none",await this.mountedPromise,this.mountedPromise=null,this.el.innerHTML=""}}function Bt(r){switch(r){case"toolbar":return"toolbar";case"menubar":return"menuBarView";default:return null}}const Kt=D(Lt),Yt={CKEditor5:Wt,CKEditable:jt,CKUIPart:Kt,CKContext:St};exports.ContextsRegistry=w;exports.CustomEditorPluginsRegistry=S;exports.EditorsRegistry=p;exports.Hooks=Yt;exports.unwrapEditorContext=K;exports.unwrapEditorWatchdog=Z;
|
|
5
5
|
//# sourceMappingURL=index.cjs.map
|