ckeditor5 1.36.1 → 1.36.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 176a1a844ad3d2302bdd5e2ba7b905e0b1dc9703699f95b831a9516daf616b13
4
- data.tar.gz: d0a3d50c0d136cd475f9ff95712e42d464e57ff20ededf3145c8b4cfffdc5392
3
+ metadata.gz: f7bbaae8fee579e42642635dc2a378f4b275df97433203dc6b3b29ee339cc080
4
+ data.tar.gz: c4f5260ae103b12a6210a016fe7d6fbdd10b3c7cbb020657a4d24861b021ecf0
5
5
  SHA512:
6
- metadata.gz: 482c804a43fe91ef7dd408ca330ab1cf24df80835ea289927c852ac46948b238574f060ad73544c6f10c0e8a53f828809a8b8a1abda5840578342b5246562ec1
7
- data.tar.gz: 7a102e56e646e672f7ffdc6a7315203aef2ff57a36acd4e833f4bece96e3180e1edccc1eb4f71f35a0f691ba4b488cdb93dba438a56057cdbec9272c4f34a0d0
6
+ metadata.gz: 00bcf95c57719c8b8a234fc95e572a7e98dfb8f06b4642fa6e57a1b6907f8fe3e689c220e42da6eea71289e3e6dffd5e394a2eb8af45af6ce308708b73b3920a
7
+ data.tar.gz: 0a4f77254438ead768f41f5a6556de2c013fde3bc53ba5b1623da29272893eef4c6c84043caf53ad608be000e156838993dcb46875a45c1dcda2d7a84209abb7
data/README.md CHANGED
@@ -96,7 +96,7 @@ CKEditor5::Rails.configure do
96
96
 
97
97
  # Optionally, you can specify version of CKEditor 5 to use.
98
98
  # If it's not specified the default version specified in the gem will be used.
99
- # version '48.0.0'
99
+ # version '48.1.0'
100
100
 
101
101
  # Upload images to the server using the simple upload adapter, instead of Base64 encoding.
102
102
  # simple_upload_adapter
@@ -142,8 +142,12 @@ Explore various editor configurations with the interactive [demo application](ht
142
142
  To run the demos locally, follow these steps:
143
143
 
144
144
  ```bash
145
- bundle install # Install dependencies
146
- bundle exec guard -g rails # Start the server
145
+ npm install
146
+ bundle install
147
+
148
+ # Start the server
149
+ npm run npm_package:watch
150
+ bundle exec guard -g rails
147
151
  ```
148
152
 
149
153
  Open [http://localhost:3000/](http://localhost:3000/) in a browser to start experimenting. Modify the code as needed.
@@ -240,16 +244,16 @@ For extending CKEditor's functionality, refer to the [plugins directory](https:/
240
244
 
241
245
  ## Presets 🎨
242
246
 
243
- Presets are predefined configurations of CKEditor 5, allowing quick setup with specific features. The gem includes a `:default` preset with common features like bold, italic, underline, and link for the classic editor.
247
+ Presets are predefined configurations of CKEditor 5, allowing quick setup with specific features. The gem includes a [`:default`](/lib/ckeditor5/rails/presets/manager.rb) preset with common features like bold, italic, underline, and link for the classic editor.
244
248
 
245
- You can create your own by defining it in the `config/initializers/ckeditor5.rb` file using the `config.presets.define` method. The example below illustrates the setup of a custom preset with a classic editor and a custom toolbar:
249
+ You can create your own by defining it in the [`config/initializers/ckeditor5.rb`](/sandbox/config/initializers/ckeditor5.rb) file using the [`config.presets.define`](/lib/ckeditor5/rails/presets/manager.rb) method. The example below illustrates the setup of a custom preset with a classic editor and a custom toolbar:
246
250
 
247
251
  ```rb
248
252
  # config/initializers/ckeditor5.rb
249
253
 
250
254
  CKEditor5::Rails.configure do
251
255
  # It's possible to override the default preset right in the initializer.
252
- version '48.0.0'
256
+ version '48.1.0'
253
257
 
254
258
  # New presets inherit properties from the default preset defined in the initializer.
255
259
  # In this example, the custom preset inherits everything from default but disables the menubar:
@@ -259,7 +263,7 @@ CKEditor5::Rails.configure do
259
263
 
260
264
  # In order to define preset from scratch, you can use the `inherit: false` option.
261
265
  presets.define :blank_preset, inherit: false do
262
- version '48.0.0'
266
+ version '48.1.0'
263
267
 
264
268
  # It tells the integration to fetch the newest security patches and bug fixes.
265
269
  # It may be disabled, but it's highly recommended to keep it enabled to avoid
@@ -292,7 +296,7 @@ CKEditor5::Rails.configure do
292
296
  end
293
297
  ```
294
298
 
295
- In order to override existing presets, you can use the `presets.override` method. The method takes the name of the preset you want to override and a block with the old configuration. The example below shows how to hide the menubar in the default preset:
299
+ In order to override existing presets, you can use the [`presets.override`](/lib/ckeditor5/rails/presets/manager.rb) method. The method takes the name of the preset you want to override and a block with the old configuration. The example below shows how to hide the menubar in the default preset:
296
300
 
297
301
  ```rb
298
302
  # config/initializers/ckeditor5.rb
@@ -308,7 +312,7 @@ CKEditor5::Rails.configure do
308
312
  end
309
313
  ```
310
314
 
311
- You can define presets in the controller using the `ckeditor5_preset` helper method. See it in the section below ([Controller / View helpers](#controller--view-helpers-)).
315
+ You can define presets in the controller using the [`ckeditor5_preset`](/lib/ckeditor5/rails/editor/helpers/config_helpers.rb) helper method. See it in the section below ([Controller / View helpers](#controller--view-helpers-)).
312
316
 
313
317
  Configuration of the editor can be complex, and it's recommended to use the [CKEditor 5 online builder](https://ckeditor.com/ckeditor-5/online-builder/) to generate the configuration. It allows you to select the features you want to include and generate the configuration code in JavaScript format. Keep in mind that you need to convert the JavaScript configuration to Ruby format before using it in this gem.
314
318
 
@@ -383,7 +387,7 @@ Defines the version of CKEditor 5 to be used. The example below shows how to set
383
387
  CKEditor5::Rails.configure do
384
388
  # ... other configuration
385
389
 
386
- version '48.0.0'
390
+ version '48.1.0'
387
391
  end
388
392
  ```
389
393
 
@@ -395,7 +399,7 @@ In order to disable default patches, you can pass the `apply_patches: false` key
395
399
  CKEditor5::Rails.configure do
396
400
  # ... other configuration
397
401
 
398
- version '48.0.0', apply_patches: false
402
+ version '48.1.0', apply_patches: false
399
403
  end
400
404
  ```
401
405
 
@@ -1375,7 +1379,7 @@ It may be useful when you want to define a preset based on the current user or r
1375
1379
  class ApplicationController < ActionController::Base
1376
1380
  def show
1377
1381
  @preset = ckeditor5_preset do
1378
- version '48.0.0'
1382
+ version '48.1.0'
1379
1383
 
1380
1384
  toolbar :sourceEditing, :|, :bold, :italic, :underline, :strikethrough,
1381
1385
  :subscript, :superscript, :removeFormat, :|, :bulletedList, :numberedList,
@@ -1410,7 +1414,7 @@ If you want to override the preset defined in the initializer, you can search fo
1410
1414
  class ApplicationController < ActionController::Base
1411
1415
  def show
1412
1416
  @preset = ckeditor5_preset(:default).override do
1413
- version '48.0.0'
1417
+ version '48.1.0'
1414
1418
 
1415
1419
  toolbar :sourceEditing, :|, :bold, :italic, :underline, :strikethrough,
1416
1420
  :subscript, :superscript, :removeFormat, :|, :bulletedList, :numberedList,
@@ -1583,7 +1587,7 @@ In that scenario it's recommended to add `gpl` method to the initializer along w
1583
1587
 
1584
1588
  CKEditor5::Rails.configure do
1585
1589
  gpl
1586
- version '48.0.0'
1590
+ version '48.1.0'
1587
1591
  end
1588
1592
  ```
1589
1593
 
@@ -2392,6 +2396,12 @@ If you want to watch the tests, you can use the following command:
2392
2396
  bundle exec guard -g rspec
2393
2397
  ```
2394
2398
 
2399
+ If you want to run E2E tests:
2400
+
2401
+ ```sh
2402
+ bundle exec rake e2e
2403
+ ```
2404
+
2395
2405
  ## Psst... 👀
2396
2406
 
2397
2407
  If you're looking for similar stuff, check these out:
@@ -2,8 +2,8 @@
2
2
 
3
3
  module CKEditor5
4
4
  module Rails
5
- VERSION = '1.36.1'
5
+ VERSION = '1.36.3'
6
6
 
7
- DEFAULT_CKEDITOR_VERSION = '48.0.0'
7
+ DEFAULT_CKEDITOR_VERSION = '48.1.0'
8
8
  end
9
9
  end
@@ -1,2 +1,2 @@
1
- "use strict";var C=Object.create;var w=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var k=(s,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of P(t))!S.call(s,n)&&n!==e&&w(s,n,{get:()=>t[n],enumerable:!(i=A(t,n))||i.enumerable});return s};var g=(s,t,e)=>(e=s!=null?C(x(s)):{},k(t||!s||!s.__esModule?w(e,"default",{value:s,enumerable:!0}):e,s));function p(s){switch(document.readyState){case"loading":document.addEventListener("DOMContentLoaded",s,{once:!0});break;case"interactive":case"complete":setTimeout(s,0);break;default:console.warn("Unexpected document.readyState:",document.readyState),setTimeout(s,0)}}const b=new Map;function R(s){if(b.has(s))return b.get(s);const t=new Promise((e,i)=>{const n=document.createElement("script");n.src=s,n.onload=e,n.onerror=i,document.head.appendChild(n)});return b.set(s,t),t}function M(s){return typeof s=="string"&&s!=="__proto__"&&s!=="constructor"&&s!=="prototype"}function $(s){return Array.from(document.styleSheets).some(t=>t.href===s||t.href===new URL(s,window.location.href).href)}function E(s=[]){const t=s.map(e=>new Promise((i,n)=>{if($(e)){i();return}const r=document.createElement("link");r.rel="stylesheet",r.href=e,r.onerror=n,r.onload=()=>i(),document.head.appendChild(r)}));return Promise.all(t)}function h(s=[]){const t=async({url:i,import_name:n,import_as:r,window_name:o,stylesheets:a})=>{if(a?.length&&await E(a),o){let d=function(){return Object.prototype.hasOwnProperty.call(window,o)};if(i&&!d()&&await R(i),d()||window.dispatchEvent(new CustomEvent(`ckeditor:request-cjs-plugin:${o}`)),!d())throw new Error(`Plugin window['${o}'] not found in global scope. Please ensure the plugin is loaded before CKEditor initialization.`);return window[o]}const c=await import(n),l=c[r||"default"];if(!l)throw new Error(`Plugin "${r||"default"}" not found in the ESM module "${n}"! Available imports: ${Object.keys(c).join(", ")}! Consider changing "import_as" value.`);return l};function e(i){return t(typeof i=="string"?{import_name:"ckeditor5",import_as:i}:i)}return Promise.all(s.map(e))}function u(s){if(!s||typeof s!="object")return s;if(Array.isArray(s))return s.map(i=>u(i));const t=s;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(s))e[i]=u(n);return e}function I(){return Math.random().toString(36).substring(2)}class T extends HTMLElement{instance=null;instancePromise=Promise.withResolvers();#e=new Set;static get observedAttributes(){return["plugins","config"]}async connectedCallback(){try{p(()=>this.#t())}catch(t){console.error("Failed to initialize context:",t),this.dispatchEvent(new CustomEvent("context-error",{detail:t}))}}async attributeChangedCallback(t,e,i){e!==null&&e!==i&&await this.#t()}async disconnectedCallback(){this.instance&&(await this.instance.destroy(),this.instance=null)}registerEditor(t){this.#e.add(t)}unregisterEditor(t){this.#e.delete(t)}async#t(){this.instance&&(this.instancePromise=Promise.withResolvers(),await this.instance.destroy(),this.instance=null),window.dispatchEvent(new CustomEvent("ckeditor:context:attach:before",{detail:{element:this}}));const{Context:t,ContextWatchdog:e}=await import("ckeditor5"),i=await this.#i(),n=this.#s();window.dispatchEvent(new CustomEvent("ckeditor:context:attach",{detail:{config:n,element:this}})),this.instance=new e(t,{crashNumberLimit:10}),await this.instance.create({...n,plugins:i}),this.instance.on("itemError",(...r)=>{console.error("Context item error:",...r)}),this.instancePromise.resolve(this.instance),this.dispatchEvent(new CustomEvent("context-ready",{detail:this.instance})),await Promise.all([...this.#e].map(r=>r.reinitializeEditor()))}async#i(){const t=this.getAttribute("plugins");return h(t?JSON.parse(t):[])}#s(){const t=JSON.parse(this.getAttribute("config")||"{}");return u(t)}}customElements.define("ckeditor-context-component",T);class L extends HTMLElement{static get observedAttributes(){return["name"]}get name(){return this.getAttribute("name")||"editable"}get editableElement(){return this.querySelector("div")}connectedCallback(){p(()=>{const t=this.#e();if(!t)throw new Error("ckeditor-editable-component must be a child of ckeditor-component");if(this.innerHTML=`<div>${this.innerHTML}</div>`,this.style.display="block",t.isDecoupled())t.runAfterEditorReady(e=>{this.appendChild(e.ui.view[this.name].element)});else{if(!this.name)throw new Error('Editable component missing required "name" attribute');t.editables[this.name]=this}})}attributeChangedCallback(t,e,i){if(e!==i)if(t==="name"){if(!e)return;const n=this.#e();n&&(n.editables[i]=n.editables[e],delete n.editables[e])}else this.editableElement.setAttribute(t,i)}disconnectedCallback(){const t=this.#e();t&&delete t.editables[this.name]}#e(){return this.closest("ckeditor-component")||document.body.querySelector("ckeditor-component")}}customElements.define("ckeditor-editable-component",L);class y{#e;#t;constructor(t,e={}){return this.#e=t,this.#t=e,new Proxy(this,{get(i,n){return typeof i[n]=="function"?i[n].bind(i):i.#t[n]},set(i,n,r){return i.#t[n]!==r&&(i.attachRoot(n,r),i.#t[n]=r),!0},deleteProperty(i,n){return i.detachRoot(n),delete i.#t[n],!0}})}async attachRoot(t,e){return await this.detachRoot(t),this.#e.runAfterEditorReady(i=>{const{ui:n,editing:r,model:o}=i;i.addRoot(t,{isUndoable:!1,data:e.innerHTML});const a=o.document.getRoot(t);n.getEditableElement(t)&&i.detachEditable(a);const c=n.view.createEditable(t,e);n.addEditable(c),r.view.forceRender()})}async detachRoot(t){return this.#e.runAfterEditorReady(e=>{const i=e.model.document.getRoot(t);i&&(e.detachEditable(i),e.detachRoot(t,!0))})}getAll(){return this.#t}}class m extends HTMLElement{instancePromise=Promise.withResolvers();watchdog=null;instance=null;editables=Object.create({});#e="";#t=null;#i=null;#s=null;static get observedAttributes(){return["config","plugins","translations","type"]}static get inputAttributes(){return["name","required","value"]}get oneditorchange(){return this.#r("editorchange")}set oneditorchange(t){this.#o("editorchange",t)}get oneditorready(){return this.#r("editorready")}set oneditorready(t){this.#o("editorready",t)}get oneditorerror(){return this.#r("editorerror")}set oneditorerror(t){this.#o("editorerror",t)}#r(t){if(this.hasAttribute(`on${t}`)){const e=this.getAttribute(`on${t}`);if(!M(e))throw new Error(`Unsafe event handler attribute value: ${e}`);return window[e]||new Function("event",e)}return this[`#${t}Handler`]}#o(t,e){typeof e=="string"?this.setAttribute(`on${t}`,e):(this.removeAttribute(`on${t}`),this[`#${t}Handler`]=e)}connectedCallback(){this.#t=this.closest("ckeditor-context-component"),this.#e=this.innerHTML;try{p(async()=>{this.#t&&(await this.#t.instancePromise.promise,this.#t.registerEditor(this)),await this.reinitializeEditor()})}catch(t){console.error("Failed to initialize editor:",t);const e=new CustomEvent("editor-error",{detail:t});this.dispatchEvent(e),this.oneditorerror?.(e)}}async attributeChangedCallback(t,e,i){e!==null&&e!==i&&m.observedAttributes.includes(t)&&this.isConnected&&await this.reinitializeEditor()}async disconnectedCallback(){this.#t&&this.#t.unregisterEditor(this);try{await this.#d()}catch(t){console.error("Failed to destroy editor:",t)}}runAfterEditorReady(t){return this.instance?Promise.resolve(t(this.instance)):this.instancePromise.promise.then(t)}get#n(){return this.getAttribute("type")==="ClassicEditor"?"textarea":"div"}get#a(){return this.#t?.instance}async#d(){this.#i&&await this.#a.remove(this.#i),await this.instance?.destroy(),this.watchdog?.destroy()}#l(){const t=JSON.parse(this.getAttribute("config")||"{}");return u(t)}async#u(t){await Promise.all([this.#b(),this.#w()]);let e=t;t instanceof y?e=t.getAll():typeof t!="string"&&(e=t.main);const i={...e instanceof HTMLElement&&{element:e},...typeof e=="string"&&{data:e},...e instanceof Object&&{editables:e}};window.dispatchEvent(new CustomEvent("ckeditor:attach:before",{detail:i}));const n=await this.#v(),[r,o]=await Promise.all([this.#E(),this.#y()]),a={...this.#l(),...o.length&&{translations:o},plugins:r};window.dispatchEvent(new CustomEvent("ckeditor:attach",{detail:{config:a,...i}}));let c=null,l=null,d=null;if(this.#t)d=I(),await this.#a.add({creator:(f,v)=>n.create(f,v),id:d,sourceElementOrData:e,type:"editor",config:a}),l=this.#a.getItem(d);else if(this.hasWatchdog()){const{EditorWatchdog:f}=await import("ckeditor5");c=new f(n),await c.create(e,a),l=c.editor}else l=await n.create(e,a);return{contextId:d,instance:l,watchdog:c}}async reinitializeEditor(){this.instance&&(this.instancePromise=Promise.withResolvers(),await this.#d(),this.instance=null),this.style.display="block",!this.isMultiroot()&&!this.isDecoupled()&&(this.innerHTML=`<${this.#n}>${this.#e}</${this.#n}>`,this.#p()),this.isMultiroot()?this.editables=new y(this,this.#h()):this.isDecoupled()?this.editables=null:this.editables=this.#h();try{const{watchdog:t,instance:e,contextId:i}=await this.#u(this.editables||this.#l().initialData||"");this.watchdog=t,this.instance=e,this.#i=i,this.#f(),this.#g(),this.#m(),this.instancePromise.resolve(this.instance);const n=new CustomEvent("editor-ready",{detail:this.instance});this.dispatchEvent(n),this.oneditorready?.(n)}catch(t){throw this.instancePromise.reject(t),t}}#m(){const t=i=>this.instance.getData({rootName:i}),e=()=>this.instance?.model.document.getRootNames().reduce((i,n)=>({...i,[n]:t(n)}),{});this.instance?.model.document.on("change:data",()=>{const i=new CustomEvent("editor-change",{detail:{editor:this.instance,data:e()},bubbles:!0});this.dispatchEvent(i),this.oneditorchange?.(i)})}isClassic(){return this.getAttribute("type")==="ClassicEditor"}isBallon(){return this.getAttribute("type")==="BalloonEditor"}isMultiroot(){return this.getAttribute("type")==="MultiRootEditor"}isDecoupled(){return this.getAttribute("type")==="DecoupledEditor"}hasWatchdog(){return this.getAttribute("watchdog")==="true"}#h(){if(this.isDecoupled())return{};if(this.isMultiroot())return[...this.querySelectorAll("ckeditor-editable-component")].reduce((i,n)=>{if(!n.name)throw new Error('Editable component missing required "name" attribute');return i[n.name]=n,i},Object.create(null));const t=this.querySelector(this.#n);if(!t)throw new Error(`No ${this.#n} element found`);return{main:t}}#p(){const t=this.querySelector("textarea");if(t)for(const e of m.inputAttributes)this.hasAttribute(e)&&t.setAttribute(e,this.getAttribute(e))}#f(){if(!this.instance)return;const t=this.querySelector("textarea");if(!t)return;const e=()=>{this.style.position="relative",t.innerHTML="",t.value=this.instance.getData(),t.tabIndex=-1,Object.assign(t.style,{display:"flex",position:"absolute",bottom:"0",left:"50%",width:"1px",height:"1px",opacity:"0",pointerEvents:"none",margin:"0",padding:"0",border:"none"})};e(),this.instance.model.document.on("change:data",()=>{t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),e()})}#g(){if(!this.isClassic()&&!this.isBallon())return;const{instance:t}=this,e=Number.parseInt(this.getAttribute("editable-height"),10);Number.isNaN(e)||t.editing.view.change(i=>{i.setStyle("height",`${e}px`,t.editing.view.document.getRoot())})}#c(){return this.#s||=JSON.parse(this.getAttribute("bundle"))}async#b(){await E(this.#c()?.stylesheets||[])}async#w(){const t=(this.#c()?.scripts||[]).filter(e=>!!e.window_name);await h(t)}async#y(){const t=this.#c()?.scripts.filter(e=>e.translation);return h(t)}async#E(){const t=this.getAttribute("plugins"),i=(t?JSON.parse(t):[]).map(n=>typeof n=="string"?{import_name:"ckeditor5",import_as:n}:n);return h(i)}async#v(){const t=await import("ckeditor5"),e=this.getAttribute("type");if(!e||!Object.prototype.hasOwnProperty.call(t,e))throw new Error(`Invalid editor type: ${e}`);return t[e]}}customElements.define("ckeditor-component",m);class O extends HTMLElement{connectedCallback(){p(async()=>{const t=this.getAttribute("name"),e=await this.#e().instancePromise.promise;this.appendChild(e.ui.view[t].element)})}#e(){return this.closest("ckeditor-component")||document.body.querySelector("ckeditor-component")}}customElements.define("ckeditor-ui-part-component",O);
1
+ "use strict";var C=Object.create;var w=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var k=(s,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of P(t))!S.call(s,n)&&n!==e&&w(s,n,{get:()=>t[n],enumerable:!(i=A(t,n))||i.enumerable});return s};var g=(s,t,e)=>(e=s!=null?C(x(s)):{},k(t||!s||!s.__esModule?w(e,"default",{value:s,enumerable:!0}):e,s));function p(s){switch(document.readyState){case"loading":document.addEventListener("DOMContentLoaded",s,{once:!0});break;case"interactive":case"complete":setTimeout(s,0);break;default:console.warn("Unexpected document.readyState:",document.readyState),setTimeout(s,0)}}const b=new Map;function R(s){if(b.has(s))return b.get(s);const t=new Promise((e,i)=>{const n=document.createElement("script");n.src=s,n.onload=e,n.onerror=i,document.head.appendChild(n)});return b.set(s,t),t}function M(s){return typeof s=="string"&&s!=="__proto__"&&s!=="constructor"&&s!=="prototype"}function $(s){return Array.from(document.styleSheets).some(t=>t.href===s||t.href===new URL(s,window.location.href).href)}function E(s=[]){const t=s.map(e=>new Promise((i,n)=>{if($(e)){i();return}const r=document.createElement("link");r.rel="stylesheet",r.href=e,r.onerror=n,r.onload=()=>i(),document.head.appendChild(r)}));return Promise.all(t)}function h(s=[]){const t=async({url:i,import_name:n,import_as:r,window_name:o,stylesheets:a})=>{if(a?.length&&await E(a),o){let d=function(){return Object.prototype.hasOwnProperty.call(window,o)};if(i&&!d()&&await R(i),d()||window.dispatchEvent(new CustomEvent(`ckeditor:request-cjs-plugin:${o}`)),!d())throw new Error(`Plugin window['${o}'] not found in global scope. Please ensure the plugin is loaded before CKEditor initialization.`);return window[o]}const c=await import(n),l=c[r||"default"];if(!l)throw new Error(`Plugin "${r||"default"}" not found in the ESM module "${n}"! Available imports: ${Object.keys(c).join(", ")}! Consider changing "import_as" value.`);return l};function e(i){return t(typeof i=="string"?{import_name:"ckeditor5",import_as:i}:i)}return Promise.all(s.map(e))}function u(s){if(!s||typeof s!="object")return s;if(Array.isArray(s))return s.map(i=>u(i));const t=s;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(s))e[i]=u(n);return e}function I(){return Math.random().toString(36).substring(2)}class T extends HTMLElement{instance=null;instancePromise=Promise.withResolvers();#e=new Set;static get observedAttributes(){return["plugins","config"]}async connectedCallback(){try{p(()=>this.#t())}catch(t){console.error("Failed to initialize context:",t),this.dispatchEvent(new CustomEvent("context-error",{detail:t}))}}async attributeChangedCallback(t,e,i){e!==null&&e!==i&&await this.#t()}async disconnectedCallback(){this.instance&&(await this.instance.destroy(),this.instance=null)}registerEditor(t){this.#e.add(t)}unregisterEditor(t){this.#e.delete(t)}async#t(){this.instance&&(this.instancePromise=Promise.withResolvers(),await this.instance.destroy(),this.instance=null),window.dispatchEvent(new CustomEvent("ckeditor:context:attach:before",{detail:{element:this}}));const{Context:t,ContextWatchdog:e}=await import("ckeditor5"),i=await this.#i(),n=this.#s();window.dispatchEvent(new CustomEvent("ckeditor:context:attach",{detail:{config:n,element:this}})),this.instance=new e(t,{crashNumberLimit:10}),await this.instance.create({...n,plugins:i}),this.instance.on("itemError",(...r)=>{console.error("Context item error:",...r)}),this.instancePromise.resolve(this.instance),this.dispatchEvent(new CustomEvent("context-ready",{detail:this.instance})),await Promise.all([...this.#e].map(r=>r.reinitializeEditor()))}async#i(){const t=this.getAttribute("plugins");return h(t?JSON.parse(t):[])}#s(){const t=JSON.parse(this.getAttribute("config")||"{}");return u(t)}}customElements.define("ckeditor-context-component",T);class L extends HTMLElement{static get observedAttributes(){return["name"]}get name(){return this.getAttribute("name")||"editable"}get editableElement(){return this.querySelector("div")}connectedCallback(){p(()=>{const t=this.#e();if(!t)throw new Error("ckeditor-editable-component must be a child of ckeditor-component");if(this.innerHTML=`<div>${this.innerHTML}</div>`,this.style.display="block",t.isDecoupled())t.runAfterEditorReady(e=>{this.appendChild(e.ui.view[this.name].element)});else if(t.editables){if(!this.name)throw new Error('Editable component missing required "name" attribute');t.editables[this.name]=this}})}attributeChangedCallback(t,e,i){if(e!==i)if(t==="name"){if(!e)return;const n=this.#e();n?.editables?.[e]&&(n.editables[i]=n.editables[e],delete n.editables[e])}else this.editableElement.setAttribute(t,i)}disconnectedCallback(){const t=this.#e();t?.editables&&delete t.editables[this.name]}#e(){return this.closest("ckeditor-component")||document.body.querySelector("ckeditor-component")}}customElements.define("ckeditor-editable-component",L);class y{#e;#t;constructor(t,e={}){return this.#e=t,this.#t=e,new Proxy(this,{get(i,n){return typeof i[n]=="function"?i[n].bind(i):i.#t[n]},set(i,n,r){return i.#t[n]!==r&&(i.attachRoot(n,r),i.#t[n]=r),!0},deleteProperty(i,n){return i.detachRoot(n),delete i.#t[n],!0}})}async attachRoot(t,e){return await this.detachRoot(t),this.#e.runAfterEditorReady(i=>{const{ui:n,editing:r,model:o}=i;i.addRoot(t,{isUndoable:!1,data:e.innerHTML});const a=o.document.getRoot(t);n.getEditableElement(t)&&i.detachEditable(a);const c=n.view.createEditable(t,e);n.addEditable(c),r.view.forceRender()})}async detachRoot(t){return this.#e.runAfterEditorReady(e=>{const i=e.model.document.getRoot(t);i&&(e.detachEditable(i),e.detachRoot(t,!0))})}getAll(){return this.#t}}class m extends HTMLElement{instancePromise=Promise.withResolvers();watchdog=null;instance=null;editables=Object.create({});#e="";#t=null;#i=null;#s=null;static get observedAttributes(){return["config","plugins","translations","type"]}static get inputAttributes(){return["name","required","value"]}get oneditorchange(){return this.#r("editorchange")}set oneditorchange(t){this.#o("editorchange",t)}get oneditorready(){return this.#r("editorready")}set oneditorready(t){this.#o("editorready",t)}get oneditorerror(){return this.#r("editorerror")}set oneditorerror(t){this.#o("editorerror",t)}#r(t){if(this.hasAttribute(`on${t}`)){const e=this.getAttribute(`on${t}`);if(!M(e))throw new Error(`Unsafe event handler attribute value: ${e}`);return window[e]||new Function("event",e)}return this[`#${t}Handler`]}#o(t,e){typeof e=="string"?this.setAttribute(`on${t}`,e):(this.removeAttribute(`on${t}`),this[`#${t}Handler`]=e)}connectedCallback(){this.#t=this.closest("ckeditor-context-component"),this.#e=this.innerHTML;try{p(async()=>{this.#t&&(await this.#t.instancePromise.promise,this.#t.registerEditor(this)),await this.reinitializeEditor()})}catch(t){console.error("Failed to initialize editor:",t);const e=new CustomEvent("editor-error",{detail:t});this.dispatchEvent(e),this.oneditorerror?.(e)}}async attributeChangedCallback(t,e,i){e!==null&&e!==i&&m.observedAttributes.includes(t)&&this.isConnected&&await this.reinitializeEditor()}async disconnectedCallback(){this.#t&&this.#t.unregisterEditor(this);try{await this.#d()}catch(t){console.error("Failed to destroy editor:",t)}}runAfterEditorReady(t){return this.instance?Promise.resolve(t(this.instance)):this.instancePromise.promise.then(t)}get#n(){return this.getAttribute("type")==="ClassicEditor"?"textarea":"div"}get#a(){return this.#t?.instance}async#d(){this.#i&&await this.#a.remove(this.#i),await this.instance?.destroy(),this.watchdog?.destroy()}#l(){const t=JSON.parse(this.getAttribute("config")||"{}");return u(t)}async#u(t){await Promise.all([this.#b(),this.#w()]);let e=t;t instanceof y?e=t.getAll():typeof t!="string"&&(e=t.main);const i={...e instanceof HTMLElement&&{element:e},...typeof e=="string"&&{data:e},...e instanceof Object&&{editables:e}};window.dispatchEvent(new CustomEvent("ckeditor:attach:before",{detail:i}));const n=await this.#v(),[r,o]=await Promise.all([this.#E(),this.#y()]),a={...this.#l(),...o.length&&{translations:o},plugins:r};window.dispatchEvent(new CustomEvent("ckeditor:attach",{detail:{config:a,...i}}));let c=null,l=null,d=null;if(this.#t)d=I(),await this.#a.add({creator:(f,v)=>n.create(f,v),id:d,sourceElementOrData:e,type:"editor",config:a}),l=this.#a.getItem(d);else if(this.hasWatchdog()){const{EditorWatchdog:f}=await import("ckeditor5");c=new f(n),await c.create(e,a),l=c.editor}else l=await n.create(e,a);return{contextId:d,instance:l,watchdog:c}}async reinitializeEditor(){this.instance&&(this.instancePromise=Promise.withResolvers(),await this.#d(),this.instance=null),this.style.display="block",!this.isMultiroot()&&!this.isDecoupled()&&(this.innerHTML=`<${this.#n}>${this.#e}</${this.#n}>`,this.#p()),this.isMultiroot()?this.editables=new y(this,this.#h()):this.isDecoupled()?this.editables=null:this.editables=this.#h();try{const{watchdog:t,instance:e,contextId:i}=await this.#u(this.editables||this.#l().initialData||"");this.watchdog=t,this.instance=e,this.#i=i,this.#f(),this.#g(),this.#m(),this.instancePromise.resolve(this.instance);const n=new CustomEvent("editor-ready",{detail:this.instance});this.dispatchEvent(n),this.oneditorready?.(n)}catch(t){throw this.instancePromise.reject(t),t}}#m(){const t=i=>this.instance.getData({rootName:i}),e=()=>this.instance?.model.document.getRootNames().reduce((i,n)=>({...i,[n]:t(n)}),{});this.instance?.model.document.on("change:data",()=>{const i=new CustomEvent("editor-change",{detail:{editor:this.instance,data:e()},bubbles:!0});this.dispatchEvent(i),this.oneditorchange?.(i)})}isClassic(){return this.getAttribute("type")==="ClassicEditor"}isBallon(){return this.getAttribute("type")==="BalloonEditor"}isMultiroot(){return this.getAttribute("type")==="MultiRootEditor"}isDecoupled(){return this.getAttribute("type")==="DecoupledEditor"}hasWatchdog(){return this.getAttribute("watchdog")==="true"}#h(){if(this.isDecoupled())return{};if(this.isMultiroot())return[...this.querySelectorAll("ckeditor-editable-component")].reduce((i,n)=>{if(!n.name)throw new Error('Editable component missing required "name" attribute');return i[n.name]=n,i},Object.create(null));const t=this.querySelector(this.#n);if(!t)throw new Error(`No ${this.#n} element found`);return{main:t}}#p(){const t=this.querySelector("textarea");if(t)for(const e of m.inputAttributes)this.hasAttribute(e)&&t.setAttribute(e,this.getAttribute(e))}#f(){if(!this.instance)return;const t=this.querySelector("textarea");if(!t)return;const e=()=>{this.style.position="relative",t.innerHTML="",t.value=this.instance.getData(),t.tabIndex=-1,Object.assign(t.style,{display:"flex",position:"absolute",bottom:"0",left:"50%",width:"1px",height:"1px",opacity:"0",pointerEvents:"none",margin:"0",padding:"0",border:"none"})};e(),this.instance.model.document.on("change:data",()=>{t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),e()})}#g(){if(!this.isClassic()&&!this.isBallon())return;const{instance:t}=this,e=Number.parseInt(this.getAttribute("editable-height"),10);Number.isNaN(e)||t.editing.view.change(i=>{i.setStyle("height",`${e}px`,t.editing.view.document.getRoot())})}#c(){return this.#s||=JSON.parse(this.getAttribute("bundle"))}async#b(){await E(this.#c()?.stylesheets||[])}async#w(){const t=(this.#c()?.scripts||[]).filter(e=>!!e.window_name);await h(t)}async#y(){const t=this.#c()?.scripts.filter(e=>e.translation);return h(t)}async#E(){const t=this.getAttribute("plugins"),i=(t?JSON.parse(t):[]).map(n=>typeof n=="string"?{import_name:"ckeditor5",import_as:n}:n);return h(i)}async#v(){const t=await import("ckeditor5"),e=this.getAttribute("type");if(!e||!Object.prototype.hasOwnProperty.call(t,e))throw new Error(`Invalid editor type: ${e}`);return t[e]}}customElements.define("ckeditor-component",m);class O extends HTMLElement{connectedCallback(){p(async()=>{const t=this.getAttribute("name"),e=await this.#e().instancePromise.promise;this.appendChild(e.ui.view[t].element)})}#e(){return this.closest("ckeditor-component")||document.body.querySelector("ckeditor-component")}}customElements.define("ckeditor-ui-part-component",O);
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/helpers/exec-if-dom-ready.ts","../src/helpers/inject-script.ts","../src/helpers/is-safe-key.ts","../src/helpers/load-async-css.ts","../src/helpers/load-async-imports.ts","../src/helpers/resolve-config-element-references.ts","../src/helpers/uid.ts","../src/components/context.ts","../src/components/editable.ts","../src/components/editor/multiroot-editables-tracker.ts","../src/components/editor/editor.ts","../src/components/ui-part.ts"],"sourcesContent":["/**\n * Executes callback when DOM is ready.\n *\n * @param callback - Function to execute when DOM is ready.\n */\nexport function execIfDOMReady(callback: VoidFunction) {\n switch (document.readyState) {\n case 'loading':\n document.addEventListener('DOMContentLoaded', callback, { once: true });\n break;\n\n case 'interactive':\n case 'complete':\n setTimeout(callback, 0);\n break;\n\n default:\n console.warn('Unexpected document.readyState:', document.readyState);\n setTimeout(callback, 0);\n }\n}\n","const SCRIPT_LOAD_PROMISES = new Map();\n\n/**\n * Dynamically loads script files based on configuration.\n * Uses caching to avoid loading the same script multiple times.\n *\n * @param url - URL of the script to load\n */\nexport function injectScript(url: string) {\n if (SCRIPT_LOAD_PROMISES.has(url)) {\n return SCRIPT_LOAD_PROMISES.get(url);\n }\n\n const promise = new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.src = url;\n script.onload = resolve;\n script.onerror = reject;\n\n document.head.appendChild(script);\n });\n\n SCRIPT_LOAD_PROMISES.set(url, promise);\n return promise;\n}\n","/**\n * Checks if a key is safe to use in configuration objects to prevent prototype pollution\n *\n * @param key - Key name to check\n * @returns True if key is safe to use\n */\nexport function isSafeKey(key: string) {\n return (\n typeof key === 'string'\n && key !== '__proto__'\n && key !== 'constructor'\n && key !== 'prototype'\n );\n}\n","/**\n * Checks if stylesheet with given href already exists in document\n *\n * @param href - Stylesheet URL to check\n * @returns True if stylesheet already exists\n */\nfunction stylesheetExists(href: string) {\n return Array\n .from(document.styleSheets)\n .some(sheet =>\n sheet.href === href || sheet.href === new URL(href, window.location.href).href,\n );\n}\n\n/**\n * Dynamically loads CSS files based on configuration\n *\n * @param stylesheets - Array of CSS file URLs to load\n * @returns Array of promises for each CSS file load\n * @throws When CSS file loading fails\n */\nexport function loadAsyncCSS(stylesheets: string[] = []) {\n const promises = stylesheets.map(href =>\n new Promise<void>((resolve, reject) => {\n if (stylesheetExists(href)) {\n resolve();\n return;\n }\n\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = href;\n\n link.onerror = reject;\n link.onload = () => resolve();\n\n document.head.appendChild(link);\n }),\n );\n\n return Promise.all(promises);\n}\n","import { injectScript } from './inject-script';\nimport { loadAsyncCSS } from './load-async-css';\n\n/**\n * Dynamically imports modules based on configuration\n *\n * @param imports - Array of import configurations\n * @param imports[].name - Name of inline plugin (for inline type)\n * @param imports[].code - Source code of inline plugin (for inline type)\n * @param imports[].import_name - Module path to import (for external type)\n * @param imports[].import_as - Name to import as (for external type)\n * @param imports[].window_name - Global window object name (for external type)\n * @param imports[].type - Type of import\n * @returns Array of loaded modules\n * @throws When plugin loading fails\n */\nexport function loadAsyncImports(imports: Array<AsyncImportRawDescription | string> = []) {\n const loadExternalPlugin = async ({ url, import_name, import_as, window_name, stylesheets }: AsyncImportRawDescription) => {\n if (stylesheets?.length) {\n await loadAsyncCSS(stylesheets);\n }\n\n if (window_name) {\n function isScriptPresent() {\n return Object.prototype.hasOwnProperty.call(window, window_name!);\n }\n\n if (url && !isScriptPresent()) {\n await injectScript(url);\n }\n\n if (!isScriptPresent()) {\n window.dispatchEvent(\n new CustomEvent(`ckeditor:request-cjs-plugin:${window_name}`),\n );\n }\n\n if (!isScriptPresent()) {\n throw new Error(\n `Plugin window['${window_name}'] not found in global scope. `\n + 'Please ensure the plugin is loaded before CKEditor initialization.',\n );\n }\n\n return (window as any)[window_name!];\n }\n\n const module = await import(import_name!);\n const imported = module[import_as || 'default'];\n\n if (!imported) {\n throw new Error(\n `Plugin \"${import_as || 'default'}\" not found in the ESM module `\n + `\"${import_name}\"! Available imports: ${Object.keys(module).join(', ')}! `\n + 'Consider changing \"import_as\" value.',\n );\n }\n\n return imported;\n };\n\n function uncompressImport(pkg: any) {\n if (typeof pkg === 'string') {\n return loadExternalPlugin({ import_name: 'ckeditor5', import_as: pkg });\n }\n\n return loadExternalPlugin(pkg);\n }\n\n return Promise.all(imports.map(uncompressImport));\n}\n\n/**\n * Type definition for plugin raw descriptor\n */\nexport type AsyncImportRawDescription = {\n url?: string;\n import_name?: string;\n import_as?: string;\n window_name?: string;\n stylesheets?: string[];\n};\n","/**\n * Resolves element references in configuration object.\n * Looks for objects with { $element: \"selector\" } format and replaces them with actual DOM elements.\n *\n * @param obj - Configuration object to process\n * @returns Processed configuration object with resolved element references\n */\nexport function resolveConfigElementReferences<T>(obj: T): T {\n if (!obj || typeof obj !== 'object') {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map(item => resolveConfigElementReferences(item)) as T;\n }\n\n const anyObj = obj as any;\n\n if (anyObj.$element && typeof anyObj.$element === 'string') {\n const element = document.querySelector(anyObj.$element);\n\n if (!element) {\n console.warn(`Element not found for selector: ${anyObj.$element}`);\n }\n\n return (element || null) as T;\n }\n\n const result = Object.create(null);\n\n for (const [key, value] of Object.entries(obj)) {\n result[key] = resolveConfigElementReferences(value);\n }\n\n return result as T;\n}\n","/**\n * Generates a unique identifier string\n *\n * @returns Random string that can be used as unique identifier\n */\nexport function uid() {\n return Math.random().toString(36).substring(2);\n}\n","import type { ContextWatchdog } from 'ckeditor5';\n\nimport { execIfDOMReady, loadAsyncImports, resolveConfigElementReferences } from 'src/helpers';\n\nimport type { CKEditorComponent } from './editor';\n\nexport class CKEditorContextComponent extends HTMLElement {\n instance: ContextWatchdog | null = null;\n\n instancePromise = Promise.withResolvers<ContextWatchdog>();\n\n #connectedEditors = new Set<CKEditorComponent>();\n\n static get observedAttributes() {\n return ['plugins', 'config'];\n }\n\n async connectedCallback() {\n try {\n execIfDOMReady(() => this.#initializeContext());\n }\n catch (error) {\n console.error('Failed to initialize context:', error);\n this.dispatchEvent(new CustomEvent('context-error', { detail: error }));\n }\n }\n\n async attributeChangedCallback(_: unknown, oldValue: string | null, newValue: string | null) {\n if (oldValue !== null && oldValue !== newValue) {\n await this.#initializeContext();\n }\n }\n\n async disconnectedCallback() {\n if (this.instance) {\n await this.instance.destroy();\n this.instance = null;\n }\n }\n\n /**\n * Register editor component with this context\n *\n * @param editor - Editor component to register.\n */\n registerEditor(editor: CKEditorComponent) {\n this.#connectedEditors.add(editor);\n }\n\n /**\n * Unregister editor component from this context\n *\n * @param editor - Editor component to unregister\n */\n unregisterEditor(editor: CKEditorComponent) {\n this.#connectedEditors.delete(editor);\n }\n\n /**\n * Initialize CKEditor context with shared configuration\n *\n * @private\n */\n async #initializeContext() {\n if (this.instance) {\n this.instancePromise = Promise.withResolvers<ContextWatchdog>();\n\n await this.instance.destroy();\n\n this.instance = null;\n }\n\n // Broadcast context initialization event\n window.dispatchEvent(\n new CustomEvent('ckeditor:context:attach:before', { detail: { element: this } }),\n );\n\n const { Context, ContextWatchdog } = await import('ckeditor5');\n const plugins = await this.#getPlugins();\n const config = this.#getConfig();\n\n // Broadcast context mounting event with configuration\n window.dispatchEvent(\n new CustomEvent('ckeditor:context:attach', { detail: { config, element: this } }),\n );\n\n this.instance = new ContextWatchdog(Context, {\n crashNumberLimit: 10,\n });\n\n await this.instance.create({\n ...config,\n plugins,\n });\n\n this.instance.on('itemError', (...args) => {\n console.error('Context item error:', ...args);\n });\n\n this.instancePromise.resolve(this.instance);\n this.dispatchEvent(new CustomEvent('context-ready', { detail: this.instance }));\n\n // Reinitialize connected editors.\n await Promise.all(\n [...this.#connectedEditors].map(editor => editor.reinitializeEditor()),\n );\n }\n\n async #getPlugins() {\n const raw = this.getAttribute('plugins');\n\n return loadAsyncImports(raw ? JSON.parse(raw) : []);\n }\n\n /**\n * Gets context configuration with resolved element references.\n *\n * @private\n */\n #getConfig() {\n const config = JSON.parse(this.getAttribute('config') || '{}');\n\n return resolveConfigElementReferences(config);\n }\n}\n\ncustomElements.define('ckeditor-context-component', CKEditorContextComponent);\n","import type { CKEditorComponent } from './editor';\n\nimport { execIfDOMReady } from '../helpers/exec-if-dom-ready';\n\nexport class CKEditorEditableComponent extends HTMLElement {\n /**\n * List of attributes that trigger updates when changed\n *\n * @static\n * @returns {string[]} Array of attribute names to observe\n */\n static get observedAttributes() {\n return ['name'];\n }\n\n /**\n * Gets the name of this editable region\n */\n get name() {\n return this.getAttribute('name') || 'editable';\n }\n\n /**\n * Gets the actual editable DOM element.\n */\n get editableElement() {\n return this.querySelector('div')!;\n }\n\n /**\n * Lifecycle callback when element is added to DOM\n * Sets up the editable element and registers it with the parent editor\n */\n connectedCallback() {\n execIfDOMReady(() => {\n const editorComponent = this.#queryEditorElement();\n\n if (!editorComponent) {\n throw new Error('ckeditor-editable-component must be a child of ckeditor-component');\n }\n\n this.innerHTML = `<div>${this.innerHTML}</div>`;\n this.style.display = 'block';\n\n if (editorComponent.isDecoupled()) {\n editorComponent.runAfterEditorReady((editor) => {\n this.appendChild((editor.ui.view as any)[this.name].element);\n });\n }\n else {\n if (!this.name) {\n throw new Error('Editable component missing required \"name\" attribute');\n }\n\n editorComponent.editables![this.name] = this;\n }\n });\n }\n\n /**\n * Lifecycle callback for attribute changes\n * Handles name changes and propagates other attributes to editable element\n */\n attributeChangedCallback(name: string, oldValue: string, newValue: string) {\n if (oldValue === newValue) {\n return;\n }\n\n if (name === 'name') {\n if (!oldValue) {\n return;\n }\n\n const editorComponent = this.#queryEditorElement();\n\n if (editorComponent) {\n editorComponent.editables![newValue] = editorComponent.editables![oldValue]!;\n delete editorComponent.editables![oldValue];\n }\n }\n else {\n this.editableElement.setAttribute(name, newValue!);\n }\n }\n\n /**\n * Lifecycle callback when element is removed\n * Un-registers this editable from the parent editor\n */\n disconnectedCallback() {\n const editorComponent = this.#queryEditorElement();\n\n if (editorComponent) {\n delete editorComponent.editables![this.name];\n }\n }\n\n /**\n * Finds the parent editor component\n */\n #queryEditorElement(): CKEditorComponent | null {\n return this.closest('ckeditor-component') || document.body.querySelector('ckeditor-component');\n }\n}\n\ncustomElements.define('ckeditor-editable-component', CKEditorEditableComponent);\n","import type { MultiRootEditor } from 'ckeditor5';\n\nimport type { CKEditorComponent } from './editor';\n\nexport class CKEditorMultiRootEditablesTracker {\n #editorElement: CKEditorComponent;\n #editables: Record<string, HTMLElement>;\n\n /**\n * Creates new tracker instance wrapped in a Proxy for dynamic property access\n *\n * @param editorElement - Parent editor component reference\n * @param initialEditables - Initial editable elements\n * @returns Proxy wrapping the tracker\n */\n constructor(\n editorElement: CKEditorComponent,\n initialEditables: Record<string, HTMLElement> = {},\n ) {\n this.#editorElement = editorElement;\n this.#editables = initialEditables;\n\n return new Proxy(this, {\n /**\n * Handles property access, returns class methods or editable elements\n *\n * @param target - The tracker instance\n * @param name - Property name being accessed\n */\n get(target: CKEditorMultiRootEditablesTracker, name: string) {\n if (typeof (target as any)[name] === 'function') {\n return (target as any)[name].bind(target);\n }\n\n return target.#editables[name];\n },\n\n /**\n * Handles setting new editable elements, triggers root attachment\n *\n * @param target - The tracker instance\n * @param name - Name of the editable root\n * @param element - Element to attach as editable\n */\n set(target: CKEditorMultiRootEditablesTracker, name: string, element: HTMLElement) {\n if (target.#editables[name] !== element) {\n void target.attachRoot(name, element);\n target.#editables[name] = element;\n }\n return true;\n },\n\n /**\n * Handles removing editable elements, triggers root detachment\n *\n * @param target - The tracker instance\n * @param name - Name of the root to remove\n */\n deleteProperty(target: CKEditorMultiRootEditablesTracker, name: string) {\n void target.detachRoot(name);\n delete target.#editables[name];\n\n return true;\n },\n });\n }\n\n /**\n * Attaches a new editable root to the editor.\n * Creates new editor root and binds UI elements.\n *\n * @param name - Name of the editable root\n * @param element - DOM element to use as editable\n * @returns Resolves when root is attached\n */\n async attachRoot(name: string, element: HTMLElement) {\n await this.detachRoot(name);\n\n return this.#editorElement.runAfterEditorReady<MultiRootEditor>((editor) => {\n const { ui, editing, model } = editor;\n\n editor.addRoot(name, {\n isUndoable: false,\n data: element.innerHTML,\n });\n\n const root = model.document.getRoot(name);\n\n if (ui.getEditableElement(name)) {\n editor.detachEditable(root!);\n }\n\n const editable = ui.view.createEditable(name, element);\n ui.addEditable(editable);\n editing.view.forceRender();\n });\n }\n\n /**\n * Detaches an editable root from the editor.\n * Removes editor root and cleans up UI bindings.\n *\n * @param name - Name of root to detach\n * @returns Resolves when root is detached\n */\n async detachRoot(name: string) {\n return this.#editorElement.runAfterEditorReady<MultiRootEditor>((editor) => {\n const root = editor.model.document.getRoot(name);\n\n if (root) {\n editor.detachEditable(root);\n editor.detachRoot(name, true);\n }\n });\n }\n\n /**\n * Gets all currently tracked editable elements\n *\n * @returns Map of all editable elements\n */\n getAll() {\n return this.#editables;\n }\n}\n","import type { Editor, EditorWatchdog, Watchdog } from 'ckeditor5';\n\nimport type { AsyncImportRawDescription } from '../../helpers';\nimport type { CKEditorContextComponent } from '../context';\nimport type { CKEditorEditableComponent } from '../editable';\n\nimport {\n execIfDOMReady,\n isSafeKey,\n loadAsyncCSS,\n loadAsyncImports,\n resolveConfigElementReferences,\n uid,\n} from '../../helpers';\nimport { CKEditorMultiRootEditablesTracker } from './multiroot-editables-tracker';\n\nexport class CKEditorComponent extends HTMLElement {\n instancePromise = Promise.withResolvers<Editor>();\n\n watchdog: Watchdog | null = null;\n\n instance: Editor | null = null;\n\n editables: Record<string, HTMLElement> | null = Object.create({});\n\n #initialHTML: string = '';\n\n #context: CKEditorContextComponent | null = null;\n\n #contextEditorId: string | null = null;\n\n #bundle: object | null = null;\n\n /**\n * List of attributes that trigger updates when changed.\n */\n static get observedAttributes() {\n return ['config', 'plugins', 'translations', 'type'];\n }\n\n /**\n * List of input attributes that trigger updates when changed.\n */\n static get inputAttributes() {\n return ['name', 'required', 'value'];\n }\n\n get oneditorchange() {\n return this.#getEventHandler('editorchange');\n }\n\n set oneditorchange(handler) {\n this.#setEventHandler('editorchange', handler);\n }\n\n get oneditorready() {\n return this.#getEventHandler('editorready');\n }\n\n set oneditorready(handler) {\n this.#setEventHandler('editorready', handler);\n }\n\n get oneditorerror() {\n return this.#getEventHandler('editorerror');\n }\n\n set oneditorerror(handler) {\n this.#setEventHandler('editorerror', handler);\n }\n\n /**\n * Gets event handler function from attribute or property\n *\n * @private\n * @param name - Event name without 'on' prefix\n * @returns Event handler or null\n */\n #getEventHandler(name: string): Function | null {\n if (this.hasAttribute(`on${name}`)) {\n const handler = this.getAttribute(`on${name}`)!;\n\n if (!isSafeKey(handler)) {\n throw new Error(`Unsafe event handler attribute value: ${handler}`);\n }\n\n // eslint-disable-next-line no-new-func\n return (window as any)[handler] || new Function('event', handler);\n }\n return (this as any)[`#${name}Handler`];\n }\n\n /**\n * Sets event handler function\n *\n * @private\n * @param name - Event name without 'on' prefix\n * @param handler - Event handler\n */\n #setEventHandler(name: string, handler: Function | null) {\n if (typeof handler === 'string') {\n this.setAttribute(`on${name}`, handler);\n }\n else {\n this.removeAttribute(`on${name}`);\n (this as any)[`#${name}Handler`] = handler;\n }\n }\n\n /**\n * Lifecycle callback when element is connected to DOM\n * Initializes the editor when DOM is ready\n *\n * @protected\n */\n connectedCallback() {\n this.#context = this.closest('ckeditor-context-component');\n this.#initialHTML = this.innerHTML;\n\n try {\n execIfDOMReady(async () => {\n if (this.#context) {\n await this.#context.instancePromise.promise;\n this.#context.registerEditor(this);\n }\n\n await this.reinitializeEditor();\n });\n }\n catch (error) {\n console.error('Failed to initialize editor:', error);\n\n const event = new CustomEvent('editor-error', { detail: error });\n\n this.dispatchEvent(event);\n this.oneditorerror?.(event);\n }\n }\n\n /**\n * Handles attribute changes and reinitializes editor if needed\n *\n * @protected\n * @param name - Name of changed attribute\n * @param oldValue - Previous attribute value\n * @param newValue - New attribute value\n */\n async attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {\n if (oldValue !== null\n && oldValue !== newValue\n && CKEditorComponent.observedAttributes.includes(name) && this.isConnected) {\n await this.reinitializeEditor();\n }\n }\n\n /**\n * Lifecycle callback when element is removed from DOM\n * Destroys the editor instance\n * @protected\n */\n async disconnectedCallback() {\n if (this.#context) {\n this.#context.unregisterEditor(this);\n }\n\n try {\n await this.#destroy();\n }\n catch (error) {\n console.error('Failed to destroy editor:', error);\n }\n }\n\n /**\n * Runs a callback after the editor is ready. It waits for editor\n * initialization if needed.\n *\n * @param callback - Callback to run\n */\n runAfterEditorReady<E extends Editor>(callback: (editor: E) => void): Promise<void> {\n if (this.instance) {\n return Promise.resolve(callback(this.instance as unknown as E));\n }\n\n return this.instancePromise.promise.then(callback as unknown as any);\n }\n\n /**\n * Determines appropriate editor element tag based on editor type\n */\n get #editorElementTag() {\n switch (this.getAttribute('type')) {\n case 'ClassicEditor':\n return 'textarea';\n\n default:\n return 'div';\n }\n }\n\n /**\n * Gets the CKEditor context instance if available.\n */\n get #contextWatchdog() {\n return this.#context?.instance;\n }\n\n /**\n * Destroys the editor instance and watchdog if available\n */\n async #destroy() {\n if (this.#contextEditorId) {\n await this.#contextWatchdog!.remove(this.#contextEditorId);\n }\n\n await this.instance?.destroy();\n this.watchdog?.destroy();\n }\n\n /**\n * Gets editor configuration with resolved element references\n */\n #getConfig() {\n const config = JSON.parse(this.getAttribute('config') || '{}');\n\n return resolveConfigElementReferences(config);\n }\n\n /**\n * Creates a new CKEditor instance\n */\n async #initializeEditor(editablesOrContent: Record<string, HTMLElement | string> | CKEditorMultiRootEditablesTracker | string | HTMLElement) {\n await Promise.all([\n this.#ensureStylesheetsInjected(),\n this.#ensureWindowScriptsInjected(),\n ]);\n\n // Depending on the type of the editor the content supplied on the first\n // argument is different. For ClassicEditor it's a element or string, for MultiRootEditor\n // it's an object with editables, for DecoupledEditor it's string.\n let content: any = editablesOrContent;\n\n if (editablesOrContent instanceof CKEditorMultiRootEditablesTracker) {\n content = editablesOrContent.getAll();\n }\n else if (typeof editablesOrContent !== 'string') {\n content = (editablesOrContent as any)['main'];\n }\n\n // Broadcast editor initialization event. It's good time to load add inline window plugins.\n const beforeInitEventDetails = {\n ...content instanceof HTMLElement && { element: content },\n ...typeof content === 'string' && { data: content },\n ...content instanceof Object && { editables: content },\n };\n\n window.dispatchEvent(\n new CustomEvent('ckeditor:attach:before', { detail: beforeInitEventDetails }),\n );\n\n // Start fetching constructor.\n const Editor = await this.#getEditorConstructor();\n const [plugins, translations] = await Promise.all([\n this.#getPlugins(),\n this.#getTranslations(),\n ]);\n\n const config = {\n ...this.#getConfig(),\n ...translations.length && {\n translations,\n },\n plugins,\n };\n\n // Broadcast editor mounting event. It's good time to map configuration.\n window.dispatchEvent(\n new CustomEvent('ckeditor:attach', { detail: { config, ...beforeInitEventDetails } }),\n );\n\n // Initialize watchdog if needed\n let watchdog: EditorWatchdog | null = null;\n let instance: Editor | null = null;\n let contextId: string | null = null;\n\n if (this.#context) {\n contextId = uid();\n\n await this.#contextWatchdog!.add({\n creator: (_element, _config) => Editor.create(_element, _config),\n id: contextId,\n sourceElementOrData: content,\n type: 'editor',\n config,\n });\n\n instance = this.#contextWatchdog!.getItem(contextId) as Editor;\n }\n else if (this.hasWatchdog()) {\n // Let's create use with plain watchdog.\n const { EditorWatchdog } = await import('ckeditor5');\n watchdog = new EditorWatchdog(Editor);\n\n await watchdog.create(content, config);\n\n instance = watchdog.editor;\n }\n else {\n // Let's create the editor without watchdog.\n instance = await Editor.create(content, config);\n }\n\n return {\n contextId,\n instance,\n watchdog,\n };\n }\n\n /**\n * Re-initializes the editor by destroying existing instance and creating new one\n *\n * @private\n * @returns {Promise<void>}\n */\n async reinitializeEditor() {\n if (this.instance) {\n this.instancePromise = Promise.withResolvers();\n\n await this.#destroy();\n\n this.instance = null;\n }\n\n this.style.display = 'block';\n\n if (!this.isMultiroot() && !this.isDecoupled()) {\n this.innerHTML = `<${this.#editorElementTag}>${this.#initialHTML}</${this.#editorElementTag}>`;\n this.#assignInputAttributes();\n }\n\n // Let's track changes in editables if it's a multiroot editor.\n if (this.isMultiroot()) {\n this.editables = new CKEditorMultiRootEditablesTracker(this, this.#queryEditables()) as unknown as Record<string, HTMLElement>;\n }\n else if (this.isDecoupled()) {\n this.editables = null;\n }\n else {\n this.editables = this.#queryEditables();\n }\n\n try {\n const { watchdog, instance, contextId } = await this.#initializeEditor(this.editables || this.#getConfig().initialData || '');\n\n this.watchdog = watchdog;\n this.instance = instance!;\n this.#contextEditorId = contextId;\n\n this.#setupContentSync();\n this.#setupEditableHeight();\n this.#setupDataChangeListener();\n\n this.instancePromise.resolve(this.instance!);\n\n // Broadcast editor ready event\n const event = new CustomEvent('editor-ready', { detail: this.instance });\n\n this.dispatchEvent(event);\n this.oneditorready?.(event);\n }\n catch (err) {\n this.instancePromise.reject(err);\n throw err;\n }\n }\n\n /**\n * Sets up data change listener that broadcasts content changes\n */\n #setupDataChangeListener() {\n const getRootContent = (rootName: string) => this.instance!.getData({ rootName });\n const getAllRoots = () =>\n this.instance?.model.document\n .getRootNames()\n .reduce((acc, rootName) => ({\n ...acc,\n [rootName]: getRootContent(rootName),\n }), {});\n\n this.instance?.model.document.on('change:data', () => {\n const event = new CustomEvent('editor-change', {\n detail: {\n editor: this.instance,\n data: getAllRoots(),\n },\n bubbles: true,\n });\n\n this.dispatchEvent(event);\n this.oneditorchange?.(event);\n });\n }\n\n /**\n * Checks if current editor is classic type\n */\n isClassic() {\n return this.getAttribute('type') === 'ClassicEditor';\n }\n\n /**\n * Checks if current editor is balloon type\n */\n isBallon() {\n return this.getAttribute('type') === 'BalloonEditor';\n }\n\n /**\n * Checks if current editor is multiroot type\n */\n isMultiroot() {\n return this.getAttribute('type') === 'MultiRootEditor';\n }\n\n /**\n * Checks if current editor is decoupled type\n */\n isDecoupled() {\n return this.getAttribute('type') === 'DecoupledEditor';\n }\n\n /**\n * Checks if current editor has watchdog enabled\n */\n hasWatchdog() {\n return this.getAttribute('watchdog') === 'true';\n }\n\n /**\n * Queries and validates editable elements\n */\n #queryEditables() {\n if (this.isDecoupled()) {\n return {};\n }\n\n if (this.isMultiroot()) {\n const editables = [...this.querySelectorAll('ckeditor-editable-component')] as CKEditorEditableComponent[];\n\n return editables.reduce((acc, element) => {\n if (!element.name) {\n throw new Error('Editable component missing required \"name\" attribute');\n }\n acc[element.name] = element;\n return acc;\n }, Object.create(null));\n }\n\n const mainEditable = this.querySelector(this.#editorElementTag);\n\n if (!mainEditable) {\n throw new Error(`No ${this.#editorElementTag} element found`);\n }\n\n return { main: mainEditable };\n }\n\n /**\n * Copies input-related attributes from component to the main editable element\n *\n * @private\n */\n #assignInputAttributes() {\n const textarea = this.querySelector('textarea');\n\n if (!textarea) {\n return;\n }\n\n for (const attr of CKEditorComponent.inputAttributes) {\n if (this.hasAttribute(attr)) {\n textarea.setAttribute(attr, this.getAttribute(attr)!);\n }\n }\n }\n\n /**\n * Sets up content sync between editor and textarea element.\n *\n * @private\n */\n #setupContentSync() {\n if (!this.instance) {\n return;\n }\n\n const textarea = this.querySelector('textarea');\n\n if (!textarea) {\n return;\n }\n\n // Initial sync\n const syncInput = () => {\n this.style.position = 'relative';\n\n textarea.innerHTML = '';\n textarea.value = this.instance!.getData();\n textarea.tabIndex = -1;\n\n Object.assign(textarea.style, {\n display: 'flex',\n position: 'absolute',\n bottom: '0',\n left: '50%',\n width: '1px',\n height: '1px',\n opacity: '0',\n pointerEvents: 'none',\n margin: '0',\n padding: '0',\n border: 'none',\n });\n };\n\n syncInput();\n\n // Listen for changes\n this.instance.model.document.on('change:data', () => {\n textarea.dispatchEvent(new Event('input', { bubbles: true }));\n textarea.dispatchEvent(new Event('change', { bubbles: true }));\n\n syncInput();\n });\n }\n\n /**\n * Sets up editable height for ClassicEditor\n *\n * @private\n */\n #setupEditableHeight() {\n if (!this.isClassic() && !this.isBallon()) {\n return;\n }\n\n const { instance } = this;\n const height = Number.parseInt(this.getAttribute('editable-height')!, 10);\n\n if (Number.isNaN(height)) {\n return;\n }\n\n instance!.editing.view.change((writer) => {\n writer.setStyle('height', `${height}px`, instance!.editing.view.document.getRoot()!);\n });\n }\n\n /**\n * Gets bundle JSON description from translations attribute\n */\n #getBundle(): BundleDescription {\n return this.#bundle ||= JSON.parse(this.getAttribute('bundle')!);\n }\n\n /**\n * Checks if all required stylesheets are injected. If not, inject.\n */\n async #ensureStylesheetsInjected() {\n await loadAsyncCSS(this.#getBundle()?.stylesheets || []);\n }\n\n /**\n * Checks if all required scripts are injected. If not, inject.\n */\n async #ensureWindowScriptsInjected() {\n const windowScripts = (this.#getBundle()?.scripts || []).filter(script => !!script.window_name);\n\n await loadAsyncImports(windowScripts);\n }\n\n /**\n * Loads translation modules\n */\n async #getTranslations() {\n const translations = this.#getBundle()?.scripts.filter(script => script.translation);\n\n return loadAsyncImports(translations);\n }\n\n /**\n * Loads plugin modules\n */\n async #getPlugins() {\n const raw = this.getAttribute('plugins');\n const items = raw ? JSON.parse(raw) : [];\n const mappedItems = items.map((item: any) =>\n typeof item === 'string'\n ? { import_name: 'ckeditor5', import_as: item }\n : item,\n );\n\n return loadAsyncImports(mappedItems);\n }\n\n /**\n * Gets editor constructor based on type attribute\n */\n async #getEditorConstructor() {\n const CKEditor = await import('ckeditor5');\n const editorType = this.getAttribute('type');\n\n if (!editorType || !Object.prototype.hasOwnProperty.call(CKEditor, editorType)) {\n throw new Error(`Invalid editor type: ${editorType}`);\n }\n\n return (CKEditor as any)[editorType] as EditorConstructor;\n }\n}\n\ntype EditorConstructor = {\n create: (...args: any[]) => Promise<Editor>;\n};\n\ntype BundleDescription = {\n stylesheets: string[];\n scripts: Array<AsyncImportRawDescription & {\n translation?: boolean;\n }>;\n};\n\ncustomElements.define('ckeditor-component', CKEditorComponent);\n","import type { CKEditorComponent } from './editor';\n\nimport { execIfDOMReady } from '../helpers';\n\nclass CKEditorUIPartComponent extends HTMLElement {\n /**\n * Lifecycle callback when element is added to DOM.\n * Adds the toolbar to the editor UI.\n */\n connectedCallback() {\n execIfDOMReady(async () => {\n const uiPart = this.getAttribute('name')!;\n const editor = await this.#queryEditorElement()!.instancePromise.promise;\n\n this.appendChild((editor.ui.view as any)[uiPart].element);\n });\n }\n\n /**\n * Finds the parent editor component.\n */\n #queryEditorElement(): CKEditorComponent | null {\n return this.closest('ckeditor-component') || document.body.querySelector('ckeditor-component');\n }\n}\n\ncustomElements.define('ckeditor-ui-part-component', CKEditorUIPartComponent);\n"],"names":["execIfDOMReady","callback","SCRIPT_LOAD_PROMISES","injectScript","url","promise","resolve","reject","script","isSafeKey","key","stylesheetExists","href","sheet","loadAsyncCSS","stylesheets","promises","link","loadAsyncImports","imports","loadExternalPlugin","import_name","import_as","window_name","isScriptPresent","module","imported","uncompressImport","pkg","resolveConfigElementReferences","obj","item","anyObj","element","result","value","uid","CKEditorContextComponent","#connectedEditors","#initializeContext","error","_","oldValue","newValue","editor","Context","ContextWatchdog","plugins","#getPlugins","config","#getConfig","args","raw","CKEditorEditableComponent","editorComponent","#queryEditorElement","name","CKEditorMultiRootEditablesTracker","#editorElement","#editables","editorElement","initialEditables","target","ui","editing","model","root","editable","CKEditorComponent","#initialHTML","#context","#contextEditorId","#bundle","#getEventHandler","handler","#setEventHandler","event","#destroy","#editorElementTag","#contextWatchdog","#initializeEditor","editablesOrContent","#ensureStylesheetsInjected","#ensureWindowScriptsInjected","content","beforeInitEventDetails","Editor","#getEditorConstructor","translations","#getTranslations","watchdog","instance","contextId","_element","_config","EditorWatchdog","#assignInputAttributes","#queryEditables","#setupContentSync","#setupEditableHeight","#setupDataChangeListener","err","getRootContent","rootName","getAllRoots","acc","mainEditable","textarea","attr","syncInput","height","writer","#getBundle","windowScripts","mappedItems","CKEditor","editorType","CKEditorUIPartComponent","uiPart"],"mappings":"wdAKO,SAASA,EAAeC,EAAwB,CACrD,OAAQ,SAAS,WAAA,CACf,IAAK,UACH,SAAS,iBAAiB,mBAAoBA,EAAU,CAAE,KAAM,GAAM,EACtE,MAEF,IAAK,cACL,IAAK,WACH,WAAWA,EAAU,CAAC,EACtB,MAEF,QACE,QAAQ,KAAK,kCAAmC,SAAS,UAAU,EACnE,WAAWA,EAAU,CAAC,CAAA,CAE5B,CCpBA,MAAMC,MAA2B,IAQ1B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ECpnB7D,MAAMiD,UAAgC,WAAY,CAKhD,mBAAoB,CAClBrH,EAAe,SAAY,CACzB,MAAMsH,EAAS,KAAK,aAAa,MAAM,EACjC1E,EAAS,MAAM,KAAKW,GAAA,EAAuB,gBAAgB,QAEjE,KAAK,YAAaX,EAAO,GAAG,KAAa0E,CAAM,EAAE,OAAO,CAC1D,CAAC,CACH,CAKA/D,IAAgD,CAC9C,OAAO,KAAK,QAAQ,oBAAoB,GAAK,SAAS,KAAK,cAAc,oBAAoB,CAC/F,CACF,CAEA,eAAe,OAAO,6BAA8B8D,CAAuB"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/helpers/exec-if-dom-ready.ts","../src/helpers/inject-script.ts","../src/helpers/is-safe-key.ts","../src/helpers/load-async-css.ts","../src/helpers/load-async-imports.ts","../src/helpers/resolve-config-element-references.ts","../src/helpers/uid.ts","../src/components/context.ts","../src/components/editable.ts","../src/components/editor/multiroot-editables-tracker.ts","../src/components/editor/editor.ts","../src/components/ui-part.ts"],"sourcesContent":["/**\n * Executes callback when DOM is ready.\n *\n * @param callback - Function to execute when DOM is ready.\n */\nexport function execIfDOMReady(callback: VoidFunction) {\n switch (document.readyState) {\n case 'loading':\n document.addEventListener('DOMContentLoaded', callback, { once: true });\n break;\n\n case 'interactive':\n case 'complete':\n setTimeout(callback, 0);\n break;\n\n default:\n console.warn('Unexpected document.readyState:', document.readyState);\n setTimeout(callback, 0);\n }\n}\n","const SCRIPT_LOAD_PROMISES = new Map();\n\n/**\n * Dynamically loads script files based on configuration.\n * Uses caching to avoid loading the same script multiple times.\n *\n * @param url - URL of the script to load\n */\nexport function injectScript(url: string) {\n if (SCRIPT_LOAD_PROMISES.has(url)) {\n return SCRIPT_LOAD_PROMISES.get(url);\n }\n\n const promise = new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.src = url;\n script.onload = resolve;\n script.onerror = reject;\n\n document.head.appendChild(script);\n });\n\n SCRIPT_LOAD_PROMISES.set(url, promise);\n return promise;\n}\n","/**\n * Checks if a key is safe to use in configuration objects to prevent prototype pollution\n *\n * @param key - Key name to check\n * @returns True if key is safe to use\n */\nexport function isSafeKey(key: string) {\n return (\n typeof key === 'string'\n && key !== '__proto__'\n && key !== 'constructor'\n && key !== 'prototype'\n );\n}\n","/**\n * Checks if stylesheet with given href already exists in document\n *\n * @param href - Stylesheet URL to check\n * @returns True if stylesheet already exists\n */\nfunction stylesheetExists(href: string) {\n return Array\n .from(document.styleSheets)\n .some(sheet =>\n sheet.href === href || sheet.href === new URL(href, window.location.href).href,\n );\n}\n\n/**\n * Dynamically loads CSS files based on configuration\n *\n * @param stylesheets - Array of CSS file URLs to load\n * @returns Array of promises for each CSS file load\n * @throws When CSS file loading fails\n */\nexport function loadAsyncCSS(stylesheets: string[] = []) {\n const promises = stylesheets.map(href =>\n new Promise<void>((resolve, reject) => {\n if (stylesheetExists(href)) {\n resolve();\n return;\n }\n\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = href;\n\n link.onerror = reject;\n link.onload = () => resolve();\n\n document.head.appendChild(link);\n }),\n );\n\n return Promise.all(promises);\n}\n","import { injectScript } from './inject-script';\nimport { loadAsyncCSS } from './load-async-css';\n\n/**\n * Dynamically imports modules based on configuration\n *\n * @param imports - Array of import configurations\n * @param imports[].name - Name of inline plugin (for inline type)\n * @param imports[].code - Source code of inline plugin (for inline type)\n * @param imports[].import_name - Module path to import (for external type)\n * @param imports[].import_as - Name to import as (for external type)\n * @param imports[].window_name - Global window object name (for external type)\n * @param imports[].type - Type of import\n * @returns Array of loaded modules\n * @throws When plugin loading fails\n */\nexport function loadAsyncImports(imports: Array<AsyncImportRawDescription | string> = []) {\n const loadExternalPlugin = async ({ url, import_name, import_as, window_name, stylesheets }: AsyncImportRawDescription) => {\n if (stylesheets?.length) {\n await loadAsyncCSS(stylesheets);\n }\n\n if (window_name) {\n function isScriptPresent() {\n return Object.prototype.hasOwnProperty.call(window, window_name!);\n }\n\n if (url && !isScriptPresent()) {\n await injectScript(url);\n }\n\n if (!isScriptPresent()) {\n window.dispatchEvent(\n new CustomEvent(`ckeditor:request-cjs-plugin:${window_name}`),\n );\n }\n\n if (!isScriptPresent()) {\n throw new Error(\n `Plugin window['${window_name}'] not found in global scope. `\n + 'Please ensure the plugin is loaded before CKEditor initialization.',\n );\n }\n\n return (window as any)[window_name!];\n }\n\n const module = await import(import_name!);\n const imported = module[import_as || 'default'];\n\n if (!imported) {\n throw new Error(\n `Plugin \"${import_as || 'default'}\" not found in the ESM module `\n + `\"${import_name}\"! Available imports: ${Object.keys(module).join(', ')}! `\n + 'Consider changing \"import_as\" value.',\n );\n }\n\n return imported;\n };\n\n function uncompressImport(pkg: any) {\n if (typeof pkg === 'string') {\n return loadExternalPlugin({ import_name: 'ckeditor5', import_as: pkg });\n }\n\n return loadExternalPlugin(pkg);\n }\n\n return Promise.all(imports.map(uncompressImport));\n}\n\n/**\n * Type definition for plugin raw descriptor\n */\nexport type AsyncImportRawDescription = {\n url?: string;\n import_name?: string;\n import_as?: string;\n window_name?: string;\n stylesheets?: string[];\n};\n","/**\n * Resolves element references in configuration object.\n * Looks for objects with { $element: \"selector\" } format and replaces them with actual DOM elements.\n *\n * @param obj - Configuration object to process\n * @returns Processed configuration object with resolved element references\n */\nexport function resolveConfigElementReferences<T>(obj: T): T {\n if (!obj || typeof obj !== 'object') {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map(item => resolveConfigElementReferences(item)) as T;\n }\n\n const anyObj = obj as any;\n\n if (anyObj.$element && typeof anyObj.$element === 'string') {\n const element = document.querySelector(anyObj.$element);\n\n if (!element) {\n console.warn(`Element not found for selector: ${anyObj.$element}`);\n }\n\n return (element || null) as T;\n }\n\n const result = Object.create(null);\n\n for (const [key, value] of Object.entries(obj)) {\n result[key] = resolveConfigElementReferences(value);\n }\n\n return result as T;\n}\n","/**\n * Generates a unique identifier string\n *\n * @returns Random string that can be used as unique identifier\n */\nexport function uid() {\n return Math.random().toString(36).substring(2);\n}\n","import type { ContextWatchdog } from 'ckeditor5';\n\nimport type { CKEditorComponent } from './editor';\n\nimport { execIfDOMReady, loadAsyncImports, resolveConfigElementReferences } from '../helpers';\n\nexport class CKEditorContextComponent extends HTMLElement {\n instance: ContextWatchdog | null = null;\n\n instancePromise = Promise.withResolvers<ContextWatchdog>();\n\n #connectedEditors = new Set<CKEditorComponent>();\n\n static get observedAttributes() {\n return ['plugins', 'config'];\n }\n\n async connectedCallback() {\n try {\n execIfDOMReady(() => this.#initializeContext());\n }\n catch (error) {\n console.error('Failed to initialize context:', error);\n this.dispatchEvent(new CustomEvent('context-error', { detail: error }));\n }\n }\n\n async attributeChangedCallback(_: unknown, oldValue: string | null, newValue: string | null) {\n if (oldValue !== null && oldValue !== newValue) {\n await this.#initializeContext();\n }\n }\n\n async disconnectedCallback() {\n if (this.instance) {\n await this.instance.destroy();\n this.instance = null;\n }\n }\n\n /**\n * Register editor component with this context\n *\n * @param editor - Editor component to register.\n */\n registerEditor(editor: CKEditorComponent) {\n this.#connectedEditors.add(editor);\n }\n\n /**\n * Unregister editor component from this context\n *\n * @param editor - Editor component to unregister\n */\n unregisterEditor(editor: CKEditorComponent) {\n this.#connectedEditors.delete(editor);\n }\n\n /**\n * Initialize CKEditor context with shared configuration\n *\n * @private\n */\n async #initializeContext() {\n if (this.instance) {\n this.instancePromise = Promise.withResolvers<ContextWatchdog>();\n\n await this.instance.destroy();\n\n this.instance = null;\n }\n\n // Broadcast context initialization event\n window.dispatchEvent(\n new CustomEvent('ckeditor:context:attach:before', { detail: { element: this } }),\n );\n\n const { Context, ContextWatchdog } = await import('ckeditor5');\n const plugins = await this.#getPlugins();\n const config = this.#getConfig();\n\n // Broadcast context mounting event with configuration\n window.dispatchEvent(\n new CustomEvent('ckeditor:context:attach', { detail: { config, element: this } }),\n );\n\n this.instance = new ContextWatchdog(Context, {\n crashNumberLimit: 10,\n });\n\n await this.instance.create({\n ...config,\n plugins,\n });\n\n this.instance.on('itemError', (...args) => {\n console.error('Context item error:', ...args);\n });\n\n this.instancePromise.resolve(this.instance);\n this.dispatchEvent(new CustomEvent('context-ready', { detail: this.instance }));\n\n // Reinitialize connected editors.\n await Promise.all(\n [...this.#connectedEditors].map(editor => editor.reinitializeEditor()),\n );\n }\n\n async #getPlugins() {\n const raw = this.getAttribute('plugins');\n\n return loadAsyncImports(raw ? JSON.parse(raw) : []);\n }\n\n /**\n * Gets context configuration with resolved element references.\n *\n * @private\n */\n #getConfig() {\n const config = JSON.parse(this.getAttribute('config') || '{}');\n\n return resolveConfigElementReferences(config);\n }\n}\n\ncustomElements.define('ckeditor-context-component', CKEditorContextComponent);\n","import type { CKEditorComponent } from './editor';\n\nimport { execIfDOMReady } from '../helpers/exec-if-dom-ready';\n\nexport class CKEditorEditableComponent extends HTMLElement {\n /**\n * List of attributes that trigger updates when changed\n *\n * @static\n * @returns {string[]} Array of attribute names to observe\n */\n static get observedAttributes() {\n return ['name'];\n }\n\n /**\n * Gets the name of this editable region\n */\n get name() {\n return this.getAttribute('name') || 'editable';\n }\n\n /**\n * Gets the actual editable DOM element.\n */\n get editableElement() {\n return this.querySelector('div')!;\n }\n\n /**\n * Lifecycle callback when element is added to DOM\n * Sets up the editable element and registers it with the parent editor\n */\n connectedCallback() {\n execIfDOMReady(() => {\n const editorComponent = this.#queryEditorElement();\n\n if (!editorComponent) {\n throw new Error('ckeditor-editable-component must be a child of ckeditor-component');\n }\n\n this.innerHTML = `<div>${this.innerHTML}</div>`;\n this.style.display = 'block';\n\n if (editorComponent.isDecoupled()) {\n editorComponent.runAfterEditorReady((editor) => {\n this.appendChild((editor.ui.view as any)[this.name].element);\n });\n }\n else if (editorComponent.editables) {\n if (!this.name) {\n throw new Error('Editable component missing required \"name\" attribute');\n }\n\n editorComponent.editables[this.name] = this;\n }\n });\n }\n\n /**\n * Lifecycle callback for attribute changes\n * Handles name changes and propagates other attributes to editable element\n */\n attributeChangedCallback(name: string, oldValue: string, newValue: string) {\n if (oldValue === newValue) {\n return;\n }\n\n if (name === 'name') {\n if (!oldValue) {\n return;\n }\n\n const editorComponent = this.#queryEditorElement();\n\n if (editorComponent?.editables?.[oldValue]) {\n editorComponent.editables[newValue] = editorComponent.editables[oldValue];\n delete editorComponent.editables[oldValue];\n }\n }\n else {\n this.editableElement.setAttribute(name, newValue!);\n }\n }\n\n /**\n * Lifecycle callback when element is removed\n * Un-registers this editable from the parent editor\n */\n disconnectedCallback() {\n const editorComponent = this.#queryEditorElement();\n\n if (editorComponent?.editables) {\n delete editorComponent.editables[this.name];\n }\n }\n\n /**\n * Finds the parent editor component\n */\n #queryEditorElement(): CKEditorComponent | null {\n return this.closest('ckeditor-component') || document.body.querySelector('ckeditor-component');\n }\n}\n\ncustomElements.define('ckeditor-editable-component', CKEditorEditableComponent);\n","import type { MultiRootEditor } from 'ckeditor5';\n\nimport type { CKEditorComponent } from './editor';\n\nexport class CKEditorMultiRootEditablesTracker {\n #editorElement: CKEditorComponent;\n #editables: Record<string, HTMLElement>;\n\n /**\n * Creates new tracker instance wrapped in a Proxy for dynamic property access\n *\n * @param editorElement - Parent editor component reference\n * @param initialEditables - Initial editable elements\n * @returns Proxy wrapping the tracker\n */\n constructor(\n editorElement: CKEditorComponent,\n initialEditables: Record<string, HTMLElement> = {},\n ) {\n this.#editorElement = editorElement;\n this.#editables = initialEditables;\n\n return new Proxy(this, {\n /**\n * Handles property access, returns class methods or editable elements\n *\n * @param target - The tracker instance\n * @param name - Property name being accessed\n */\n get(target: CKEditorMultiRootEditablesTracker, name: string) {\n if (typeof (target as any)[name] === 'function') {\n return (target as any)[name].bind(target);\n }\n\n return target.#editables[name];\n },\n\n /**\n * Handles setting new editable elements, triggers root attachment\n *\n * @param target - The tracker instance\n * @param name - Name of the editable root\n * @param element - Element to attach as editable\n */\n set(target: CKEditorMultiRootEditablesTracker, name: string, element: HTMLElement) {\n if (target.#editables[name] !== element) {\n void target.attachRoot(name, element);\n target.#editables[name] = element;\n }\n return true;\n },\n\n /**\n * Handles removing editable elements, triggers root detachment\n *\n * @param target - The tracker instance\n * @param name - Name of the root to remove\n */\n deleteProperty(target: CKEditorMultiRootEditablesTracker, name: string) {\n void target.detachRoot(name);\n delete target.#editables[name];\n\n return true;\n },\n });\n }\n\n /**\n * Attaches a new editable root to the editor.\n * Creates new editor root and binds UI elements.\n *\n * @param name - Name of the editable root\n * @param element - DOM element to use as editable\n * @returns Resolves when root is attached\n */\n async attachRoot(name: string, element: HTMLElement) {\n await this.detachRoot(name);\n\n return this.#editorElement.runAfterEditorReady<MultiRootEditor>((editor) => {\n const { ui, editing, model } = editor;\n\n editor.addRoot(name, {\n isUndoable: false,\n data: element.innerHTML,\n });\n\n const root = model.document.getRoot(name);\n\n if (ui.getEditableElement(name)) {\n editor.detachEditable(root!);\n }\n\n const editable = ui.view.createEditable(name, element);\n ui.addEditable(editable);\n editing.view.forceRender();\n });\n }\n\n /**\n * Detaches an editable root from the editor.\n * Removes editor root and cleans up UI bindings.\n *\n * @param name - Name of root to detach\n * @returns Resolves when root is detached\n */\n async detachRoot(name: string) {\n return this.#editorElement.runAfterEditorReady<MultiRootEditor>((editor) => {\n const root = editor.model.document.getRoot(name);\n\n if (root) {\n editor.detachEditable(root);\n editor.detachRoot(name, true);\n }\n });\n }\n\n /**\n * Gets all currently tracked editable elements\n *\n * @returns Map of all editable elements\n */\n getAll() {\n return this.#editables;\n }\n}\n","import type { Editor, EditorWatchdog, Watchdog } from 'ckeditor5';\n\nimport type { AsyncImportRawDescription } from '../../helpers';\nimport type { CKEditorContextComponent } from '../context';\nimport type { CKEditorEditableComponent } from '../editable';\n\nimport {\n execIfDOMReady,\n isSafeKey,\n loadAsyncCSS,\n loadAsyncImports,\n resolveConfigElementReferences,\n uid,\n} from '../../helpers';\nimport { CKEditorMultiRootEditablesTracker } from './multiroot-editables-tracker';\n\nexport class CKEditorComponent extends HTMLElement {\n instancePromise = Promise.withResolvers<Editor>();\n\n watchdog: Watchdog | null = null;\n\n instance: Editor | null = null;\n\n editables: Record<string, HTMLElement> | null = Object.create({});\n\n #initialHTML: string = '';\n\n #context: CKEditorContextComponent | null = null;\n\n #contextEditorId: string | null = null;\n\n #bundle: object | null = null;\n\n /**\n * List of attributes that trigger updates when changed.\n */\n static get observedAttributes() {\n return ['config', 'plugins', 'translations', 'type'];\n }\n\n /**\n * List of input attributes that trigger updates when changed.\n */\n static get inputAttributes() {\n return ['name', 'required', 'value'];\n }\n\n get oneditorchange() {\n return this.#getEventHandler('editorchange');\n }\n\n set oneditorchange(handler) {\n this.#setEventHandler('editorchange', handler);\n }\n\n get oneditorready() {\n return this.#getEventHandler('editorready');\n }\n\n set oneditorready(handler) {\n this.#setEventHandler('editorready', handler);\n }\n\n get oneditorerror() {\n return this.#getEventHandler('editorerror');\n }\n\n set oneditorerror(handler) {\n this.#setEventHandler('editorerror', handler);\n }\n\n /**\n * Gets event handler function from attribute or property\n *\n * @private\n * @param name - Event name without 'on' prefix\n * @returns Event handler or null\n */\n #getEventHandler(name: string): Function | null {\n if (this.hasAttribute(`on${name}`)) {\n const handler = this.getAttribute(`on${name}`)!;\n\n if (!isSafeKey(handler)) {\n throw new Error(`Unsafe event handler attribute value: ${handler}`);\n }\n\n // eslint-disable-next-line no-new-func\n return (window as any)[handler] || new Function('event', handler);\n }\n return (this as any)[`#${name}Handler`];\n }\n\n /**\n * Sets event handler function\n *\n * @private\n * @param name - Event name without 'on' prefix\n * @param handler - Event handler\n */\n #setEventHandler(name: string, handler: Function | null) {\n if (typeof handler === 'string') {\n this.setAttribute(`on${name}`, handler);\n }\n else {\n this.removeAttribute(`on${name}`);\n (this as any)[`#${name}Handler`] = handler;\n }\n }\n\n /**\n * Lifecycle callback when element is connected to DOM\n * Initializes the editor when DOM is ready\n *\n * @protected\n */\n connectedCallback() {\n this.#context = this.closest('ckeditor-context-component');\n this.#initialHTML = this.innerHTML;\n\n try {\n execIfDOMReady(async () => {\n if (this.#context) {\n await this.#context.instancePromise.promise;\n this.#context.registerEditor(this);\n }\n\n await this.reinitializeEditor();\n });\n }\n catch (error) {\n console.error('Failed to initialize editor:', error);\n\n const event = new CustomEvent('editor-error', { detail: error });\n\n this.dispatchEvent(event);\n this.oneditorerror?.(event);\n }\n }\n\n /**\n * Handles attribute changes and reinitializes editor if needed\n *\n * @protected\n * @param name - Name of changed attribute\n * @param oldValue - Previous attribute value\n * @param newValue - New attribute value\n */\n async attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {\n if (oldValue !== null\n && oldValue !== newValue\n && CKEditorComponent.observedAttributes.includes(name) && this.isConnected) {\n await this.reinitializeEditor();\n }\n }\n\n /**\n * Lifecycle callback when element is removed from DOM\n * Destroys the editor instance\n * @protected\n */\n async disconnectedCallback() {\n if (this.#context) {\n this.#context.unregisterEditor(this);\n }\n\n try {\n await this.#destroy();\n }\n catch (error) {\n console.error('Failed to destroy editor:', error);\n }\n }\n\n /**\n * Runs a callback after the editor is ready. It waits for editor\n * initialization if needed.\n *\n * @param callback - Callback to run\n */\n runAfterEditorReady<E extends Editor>(callback: (editor: E) => void): Promise<void> {\n if (this.instance) {\n return Promise.resolve(callback(this.instance as unknown as E));\n }\n\n return this.instancePromise.promise.then(callback as unknown as any);\n }\n\n /**\n * Determines appropriate editor element tag based on editor type\n */\n get #editorElementTag() {\n switch (this.getAttribute('type')) {\n case 'ClassicEditor':\n return 'textarea';\n\n default:\n return 'div';\n }\n }\n\n /**\n * Gets the CKEditor context instance if available.\n */\n get #contextWatchdog() {\n return this.#context?.instance;\n }\n\n /**\n * Destroys the editor instance and watchdog if available\n */\n async #destroy() {\n if (this.#contextEditorId) {\n await this.#contextWatchdog!.remove(this.#contextEditorId);\n }\n\n await this.instance?.destroy();\n this.watchdog?.destroy();\n }\n\n /**\n * Gets editor configuration with resolved element references\n */\n #getConfig() {\n const config = JSON.parse(this.getAttribute('config') || '{}');\n\n return resolveConfigElementReferences(config);\n }\n\n /**\n * Creates a new CKEditor instance\n */\n async #initializeEditor(editablesOrContent: Record<string, HTMLElement | string> | CKEditorMultiRootEditablesTracker | string | HTMLElement) {\n await Promise.all([\n this.#ensureStylesheetsInjected(),\n this.#ensureWindowScriptsInjected(),\n ]);\n\n // Depending on the type of the editor the content supplied on the first\n // argument is different. For ClassicEditor it's a element or string, for MultiRootEditor\n // it's an object with editables, for DecoupledEditor it's string.\n let content: any = editablesOrContent;\n\n if (editablesOrContent instanceof CKEditorMultiRootEditablesTracker) {\n content = editablesOrContent.getAll();\n }\n else if (typeof editablesOrContent !== 'string') {\n content = (editablesOrContent as any)['main'];\n }\n\n // Broadcast editor initialization event. It's good time to load add inline window plugins.\n const beforeInitEventDetails = {\n ...content instanceof HTMLElement && { element: content },\n ...typeof content === 'string' && { data: content },\n ...content instanceof Object && { editables: content },\n };\n\n window.dispatchEvent(\n new CustomEvent('ckeditor:attach:before', { detail: beforeInitEventDetails }),\n );\n\n // Start fetching constructor.\n const Editor = await this.#getEditorConstructor();\n const [plugins, translations] = await Promise.all([\n this.#getPlugins(),\n this.#getTranslations(),\n ]);\n\n const config = {\n ...this.#getConfig(),\n ...translations.length && {\n translations,\n },\n plugins,\n };\n\n // Broadcast editor mounting event. It's good time to map configuration.\n window.dispatchEvent(\n new CustomEvent('ckeditor:attach', { detail: { config, ...beforeInitEventDetails } }),\n );\n\n // Initialize watchdog if needed\n let watchdog: EditorWatchdog | null = null;\n let instance: Editor | null = null;\n let contextId: string | null = null;\n\n if (this.#context) {\n contextId = uid();\n\n await this.#contextWatchdog!.add({\n creator: (_element, _config) => Editor.create(_element, _config),\n id: contextId,\n sourceElementOrData: content,\n type: 'editor',\n config,\n });\n\n instance = this.#contextWatchdog!.getItem(contextId) as Editor;\n }\n else if (this.hasWatchdog()) {\n // Let's create use with plain watchdog.\n const { EditorWatchdog } = await import('ckeditor5');\n watchdog = new EditorWatchdog(Editor);\n\n await watchdog.create(content, config);\n\n instance = watchdog.editor;\n }\n else {\n // Let's create the editor without watchdog.\n instance = await Editor.create(content, config);\n }\n\n return {\n contextId,\n instance,\n watchdog,\n };\n }\n\n /**\n * Re-initializes the editor by destroying existing instance and creating new one\n *\n * @private\n * @returns {Promise<void>}\n */\n async reinitializeEditor() {\n if (this.instance) {\n this.instancePromise = Promise.withResolvers();\n\n await this.#destroy();\n\n this.instance = null;\n }\n\n this.style.display = 'block';\n\n if (!this.isMultiroot() && !this.isDecoupled()) {\n this.innerHTML = `<${this.#editorElementTag}>${this.#initialHTML}</${this.#editorElementTag}>`;\n this.#assignInputAttributes();\n }\n\n // Let's track changes in editables if it's a multiroot editor.\n if (this.isMultiroot()) {\n this.editables = new CKEditorMultiRootEditablesTracker(this, this.#queryEditables()) as unknown as Record<string, HTMLElement>;\n }\n else if (this.isDecoupled()) {\n this.editables = null;\n }\n else {\n this.editables = this.#queryEditables();\n }\n\n try {\n const { watchdog, instance, contextId } = await this.#initializeEditor(this.editables || this.#getConfig().initialData || '');\n\n this.watchdog = watchdog;\n this.instance = instance!;\n this.#contextEditorId = contextId;\n\n this.#setupContentSync();\n this.#setupEditableHeight();\n this.#setupDataChangeListener();\n\n this.instancePromise.resolve(this.instance!);\n\n // Broadcast editor ready event\n const event = new CustomEvent('editor-ready', { detail: this.instance });\n\n this.dispatchEvent(event);\n this.oneditorready?.(event);\n }\n catch (err) {\n this.instancePromise.reject(err);\n throw err;\n }\n }\n\n /**\n * Sets up data change listener that broadcasts content changes\n */\n #setupDataChangeListener() {\n const getRootContent = (rootName: string) => this.instance!.getData({ rootName });\n const getAllRoots = () =>\n this.instance?.model.document\n .getRootNames()\n .reduce((acc, rootName) => ({\n ...acc,\n [rootName]: getRootContent(rootName),\n }), {});\n\n this.instance?.model.document.on('change:data', () => {\n const event = new CustomEvent('editor-change', {\n detail: {\n editor: this.instance,\n data: getAllRoots(),\n },\n bubbles: true,\n });\n\n this.dispatchEvent(event);\n this.oneditorchange?.(event);\n });\n }\n\n /**\n * Checks if current editor is classic type\n */\n isClassic() {\n return this.getAttribute('type') === 'ClassicEditor';\n }\n\n /**\n * Checks if current editor is balloon type\n */\n isBallon() {\n return this.getAttribute('type') === 'BalloonEditor';\n }\n\n /**\n * Checks if current editor is multiroot type\n */\n isMultiroot() {\n return this.getAttribute('type') === 'MultiRootEditor';\n }\n\n /**\n * Checks if current editor is decoupled type\n */\n isDecoupled() {\n return this.getAttribute('type') === 'DecoupledEditor';\n }\n\n /**\n * Checks if current editor has watchdog enabled\n */\n hasWatchdog() {\n return this.getAttribute('watchdog') === 'true';\n }\n\n /**\n * Queries and validates editable elements\n */\n #queryEditables() {\n if (this.isDecoupled()) {\n return {};\n }\n\n if (this.isMultiroot()) {\n const editables = [...this.querySelectorAll('ckeditor-editable-component')] as CKEditorEditableComponent[];\n\n return editables.reduce((acc, element) => {\n if (!element.name) {\n throw new Error('Editable component missing required \"name\" attribute');\n }\n acc[element.name] = element;\n return acc;\n }, Object.create(null));\n }\n\n const mainEditable = this.querySelector(this.#editorElementTag);\n\n if (!mainEditable) {\n throw new Error(`No ${this.#editorElementTag} element found`);\n }\n\n return { main: mainEditable };\n }\n\n /**\n * Copies input-related attributes from component to the main editable element\n *\n * @private\n */\n #assignInputAttributes() {\n const textarea = this.querySelector('textarea');\n\n if (!textarea) {\n return;\n }\n\n for (const attr of CKEditorComponent.inputAttributes) {\n if (this.hasAttribute(attr)) {\n textarea.setAttribute(attr, this.getAttribute(attr)!);\n }\n }\n }\n\n /**\n * Sets up content sync between editor and textarea element.\n *\n * @private\n */\n #setupContentSync() {\n if (!this.instance) {\n return;\n }\n\n const textarea = this.querySelector('textarea');\n\n if (!textarea) {\n return;\n }\n\n // Initial sync\n const syncInput = () => {\n this.style.position = 'relative';\n\n textarea.innerHTML = '';\n textarea.value = this.instance!.getData();\n textarea.tabIndex = -1;\n\n Object.assign(textarea.style, {\n display: 'flex',\n position: 'absolute',\n bottom: '0',\n left: '50%',\n width: '1px',\n height: '1px',\n opacity: '0',\n pointerEvents: 'none',\n margin: '0',\n padding: '0',\n border: 'none',\n });\n };\n\n syncInput();\n\n // Listen for changes\n this.instance.model.document.on('change:data', () => {\n textarea.dispatchEvent(new Event('input', { bubbles: true }));\n textarea.dispatchEvent(new Event('change', { bubbles: true }));\n\n syncInput();\n });\n }\n\n /**\n * Sets up editable height for ClassicEditor\n *\n * @private\n */\n #setupEditableHeight() {\n if (!this.isClassic() && !this.isBallon()) {\n return;\n }\n\n const { instance } = this;\n const height = Number.parseInt(this.getAttribute('editable-height')!, 10);\n\n if (Number.isNaN(height)) {\n return;\n }\n\n instance!.editing.view.change((writer) => {\n writer.setStyle('height', `${height}px`, instance!.editing.view.document.getRoot()!);\n });\n }\n\n /**\n * Gets bundle JSON description from translations attribute\n */\n #getBundle(): BundleDescription {\n return this.#bundle ||= JSON.parse(this.getAttribute('bundle')!);\n }\n\n /**\n * Checks if all required stylesheets are injected. If not, inject.\n */\n async #ensureStylesheetsInjected() {\n await loadAsyncCSS(this.#getBundle()?.stylesheets || []);\n }\n\n /**\n * Checks if all required scripts are injected. If not, inject.\n */\n async #ensureWindowScriptsInjected() {\n const windowScripts = (this.#getBundle()?.scripts || []).filter(script => !!script.window_name);\n\n await loadAsyncImports(windowScripts);\n }\n\n /**\n * Loads translation modules\n */\n async #getTranslations() {\n const translations = this.#getBundle()?.scripts.filter(script => script.translation);\n\n return loadAsyncImports(translations);\n }\n\n /**\n * Loads plugin modules\n */\n async #getPlugins() {\n const raw = this.getAttribute('plugins');\n const items = raw ? JSON.parse(raw) : [];\n const mappedItems = items.map((item: any) =>\n typeof item === 'string'\n ? { import_name: 'ckeditor5', import_as: item }\n : item,\n );\n\n return loadAsyncImports(mappedItems);\n }\n\n /**\n * Gets editor constructor based on type attribute\n */\n async #getEditorConstructor() {\n const CKEditor = await import('ckeditor5');\n const editorType = this.getAttribute('type');\n\n if (!editorType || !Object.prototype.hasOwnProperty.call(CKEditor, editorType)) {\n throw new Error(`Invalid editor type: ${editorType}`);\n }\n\n return (CKEditor as any)[editorType] as EditorConstructor;\n }\n}\n\ntype EditorConstructor = {\n create: (...args: any[]) => Promise<Editor>;\n};\n\ntype BundleDescription = {\n stylesheets: string[];\n scripts: Array<AsyncImportRawDescription & {\n translation?: boolean;\n }>;\n};\n\ncustomElements.define('ckeditor-component', CKEditorComponent);\n","import type { CKEditorComponent } from './editor';\n\nimport { execIfDOMReady } from '../helpers';\n\nclass CKEditorUIPartComponent extends HTMLElement {\n /**\n * Lifecycle callback when element is added to DOM.\n * Adds the toolbar to the editor UI.\n */\n connectedCallback() {\n execIfDOMReady(async () => {\n const uiPart = this.getAttribute('name')!;\n const editor = await this.#queryEditorElement()!.instancePromise.promise;\n\n this.appendChild((editor.ui.view as any)[uiPart].element);\n });\n }\n\n /**\n * Finds the parent editor component.\n */\n #queryEditorElement(): CKEditorComponent | null {\n return this.closest('ckeditor-component') || document.body.querySelector('ckeditor-component');\n }\n}\n\ncustomElements.define('ckeditor-ui-part-component', CKEditorUIPartComponent);\n"],"names":["execIfDOMReady","callback","SCRIPT_LOAD_PROMISES","injectScript","url","promise","resolve","reject","script","isSafeKey","key","stylesheetExists","href","sheet","loadAsyncCSS","stylesheets","promises","link","loadAsyncImports","imports","loadExternalPlugin","import_name","import_as","window_name","isScriptPresent","module","imported","uncompressImport","pkg","resolveConfigElementReferences","obj","item","anyObj","element","result","value","uid","CKEditorContextComponent","#connectedEditors","#initializeContext","error","_","oldValue","newValue","editor","Context","ContextWatchdog","plugins","#getPlugins","config","#getConfig","args","raw","CKEditorEditableComponent","editorComponent","#queryEditorElement","name","CKEditorMultiRootEditablesTracker","#editorElement","#editables","editorElement","initialEditables","target","ui","editing","model","root","editable","CKEditorComponent","#initialHTML","#context","#contextEditorId","#bundle","#getEventHandler","handler","#setEventHandler","event","#destroy","#editorElementTag","#contextWatchdog","#initializeEditor","editablesOrContent","#ensureStylesheetsInjected","#ensureWindowScriptsInjected","content","beforeInitEventDetails","Editor","#getEditorConstructor","translations","#getTranslations","watchdog","instance","contextId","_element","_config","EditorWatchdog","#assignInputAttributes","#queryEditables","#setupContentSync","#setupEditableHeight","#setupDataChangeListener","err","getRootContent","rootName","getAllRoots","acc","mainEditable","textarea","attr","syncInput","height","writer","#getBundle","windowScripts","mappedItems","CKEditor","editorType","CKEditorUIPartComponent","uiPart"],"mappings":"wdAKO,SAASA,EAAeC,EAAwB,CACrD,OAAQ,SAAS,WAAA,CACf,IAAK,UACH,SAAS,iBAAiB,mBAAoBA,EAAU,CAAE,KAAM,GAAM,EACtE,MAEF,IAAK,cACL,IAAK,WACH,WAAWA,EAAU,CAAC,EACtB,MAEF,QACE,QAAQ,KAAK,kCAAmC,SAAS,UAAU,EACnE,WAAWA,EAAU,CAAC,CAAA,CAE5B,CCpBA,MAAMC,MAA2B,IAQ1B,SAASC,EAAaC,EAAa,CACxC,GAAIF,EAAqB,IAAIE,CAAG,EAC9B,OAAOF,EAAqB,IAAIE,CAAG,EAGrC,MAAMC,EAAU,IAAI,QAAQ,CAACC,EAASC,IAAW,CAC/C,MAAMC,EAAS,SAAS,cAAc,QAAQ,EAC9CA,EAAO,IAAMJ,EACbI,EAAO,OAASF,EAChBE,EAAO,QAAUD,EAEjB,SAAS,KAAK,YAAYC,CAAM,CAClC,CAAC,EAED,OAAAN,EAAqB,IAAIE,EAAKC,CAAO,EAC9BA,CACT,CClBO,SAASI,EAAUC,EAAa,CACrC,OACE,OAAOA,GAAQ,UACZA,IAAQ,aACRA,IAAQ,eACRA,IAAQ,WAEf,CCPA,SAASC,EAAiBC,EAAc,CACtC,OAAO,MACJ,KAAK,SAAS,WAAW,EACzB,KAAKC,GACJA,EAAM,OAASD,GAAQC,EAAM,OAAS,IAAI,IAAID,EAAM,OAAO,SAAS,IAAI,EAAE,IAAA,CAEhF,CASO,SAASE,EAAaC,EAAwB,GAAI,CACvD,MAAMC,EAAWD,EAAY,IAAIH,GAC/B,IAAI,QAAc,CAACN,EAASC,IAAW,CACrC,GAAII,EAAiBC,CAAI,EAAG,CAC1BN,EAAA,EACA,MACF,CAEA,MAAMW,EAAO,SAAS,cAAc,MAAM,EAC1CA,EAAK,IAAM,aACXA,EAAK,KAAOL,EAEZK,EAAK,QAAUV,EACfU,EAAK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,CAAA,GACZ,IAAKrB,GAC7B,OAAOA,GAAS,SACZ,CAAE,YAAa,YAAa,UAAWA,GACvCA,CAAA,EAGN,OAAOb,EAAiBgG,CAAW,CACrC,CAKA,KAAM3B,IAAwB,CAC5B,MAAM4B,EAAW,KAAM,QAAO,WAAW,EACnCC,EAAa,KAAK,aAAa,MAAM,EAE3C,GAAI,CAACA,GAAc,CAAC,OAAO,UAAU,eAAe,KAAKD,EAAUC,CAAU,EAC3E,MAAM,IAAI,MAAM,wBAAwBA,CAAU,EAAE,EAGtD,OAAQD,EAAiBC,CAAU,CACrC,CACF,CAaA,eAAe,OAAO,qBAAsBhD,CAAiB,ECpnB7D,MAAMiD,UAAgC,WAAY,CAKhD,mBAAoB,CAClBrH,EAAe,SAAY,CACzB,MAAMsH,EAAS,KAAK,aAAa,MAAM,EACjC1E,EAAS,MAAM,KAAKW,GAAA,EAAuB,gBAAgB,QAEjE,KAAK,YAAaX,EAAO,GAAG,KAAa0E,CAAM,EAAE,OAAO,CAC1D,CAAC,CACH,CAKA/D,IAAgD,CAC9C,OAAO,KAAK,QAAQ,oBAAoB,GAAK,SAAS,KAAK,cAAc,oBAAoB,CAC/F,CACF,CAEA,eAAe,OAAO,6BAA8B8D,CAAuB"}
@@ -195,7 +195,7 @@ class x extends HTMLElement {
195
195
  t.runAfterEditorReady((e) => {
196
196
  this.appendChild(e.ui.view[this.name].element);
197
197
  });
198
- else {
198
+ else if (t.editables) {
199
199
  if (!this.name)
200
200
  throw new Error('Editable component missing required "name" attribute');
201
201
  t.editables[this.name] = this;
@@ -212,7 +212,7 @@ class x extends HTMLElement {
212
212
  if (!e)
213
213
  return;
214
214
  const n = this.#e();
215
- n && (n.editables[i] = n.editables[e], delete n.editables[e]);
215
+ n?.editables?.[e] && (n.editables[i] = n.editables[e], delete n.editables[e]);
216
216
  } else
217
217
  this.editableElement.setAttribute(t, i);
218
218
  }
@@ -222,7 +222,7 @@ class x extends HTMLElement {
222
222
  */
223
223
  disconnectedCallback() {
224
224
  const t = this.#e();
225
- t && delete t.editables[this.name];
225
+ t?.editables && delete t.editables[this.name];
226
226
  }
227
227
  /**
228
228
  * Finds the parent editor component
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/helpers/exec-if-dom-ready.ts","../src/helpers/inject-script.ts","../src/helpers/is-safe-key.ts","../src/helpers/load-async-css.ts","../src/helpers/load-async-imports.ts","../src/helpers/resolve-config-element-references.ts","../src/helpers/uid.ts","../src/components/context.ts","../src/components/editable.ts","../src/components/editor/multiroot-editables-tracker.ts","../src/components/editor/editor.ts","../src/components/ui-part.ts"],"sourcesContent":["/**\n * Executes callback when DOM is ready.\n *\n * @param callback - Function to execute when DOM is ready.\n */\nexport function execIfDOMReady(callback: VoidFunction) {\n switch (document.readyState) {\n case 'loading':\n document.addEventListener('DOMContentLoaded', callback, { once: true });\n break;\n\n case 'interactive':\n case 'complete':\n setTimeout(callback, 0);\n break;\n\n default:\n console.warn('Unexpected document.readyState:', document.readyState);\n setTimeout(callback, 0);\n }\n}\n","const SCRIPT_LOAD_PROMISES = new Map();\n\n/**\n * Dynamically loads script files based on configuration.\n * Uses caching to avoid loading the same script multiple times.\n *\n * @param url - URL of the script to load\n */\nexport function injectScript(url: string) {\n if (SCRIPT_LOAD_PROMISES.has(url)) {\n return SCRIPT_LOAD_PROMISES.get(url);\n }\n\n const promise = new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.src = url;\n script.onload = resolve;\n script.onerror = reject;\n\n document.head.appendChild(script);\n });\n\n SCRIPT_LOAD_PROMISES.set(url, promise);\n return promise;\n}\n","/**\n * Checks if a key is safe to use in configuration objects to prevent prototype pollution\n *\n * @param key - Key name to check\n * @returns True if key is safe to use\n */\nexport function isSafeKey(key: string) {\n return (\n typeof key === 'string'\n && key !== '__proto__'\n && key !== 'constructor'\n && key !== 'prototype'\n );\n}\n","/**\n * Checks if stylesheet with given href already exists in document\n *\n * @param href - Stylesheet URL to check\n * @returns True if stylesheet already exists\n */\nfunction stylesheetExists(href: string) {\n return Array\n .from(document.styleSheets)\n .some(sheet =>\n sheet.href === href || sheet.href === new URL(href, window.location.href).href,\n );\n}\n\n/**\n * Dynamically loads CSS files based on configuration\n *\n * @param stylesheets - Array of CSS file URLs to load\n * @returns Array of promises for each CSS file load\n * @throws When CSS file loading fails\n */\nexport function loadAsyncCSS(stylesheets: string[] = []) {\n const promises = stylesheets.map(href =>\n new Promise<void>((resolve, reject) => {\n if (stylesheetExists(href)) {\n resolve();\n return;\n }\n\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = href;\n\n link.onerror = reject;\n link.onload = () => resolve();\n\n document.head.appendChild(link);\n }),\n );\n\n return Promise.all(promises);\n}\n","import { injectScript } from './inject-script';\nimport { loadAsyncCSS } from './load-async-css';\n\n/**\n * Dynamically imports modules based on configuration\n *\n * @param imports - Array of import configurations\n * @param imports[].name - Name of inline plugin (for inline type)\n * @param imports[].code - Source code of inline plugin (for inline type)\n * @param imports[].import_name - Module path to import (for external type)\n * @param imports[].import_as - Name to import as (for external type)\n * @param imports[].window_name - Global window object name (for external type)\n * @param imports[].type - Type of import\n * @returns Array of loaded modules\n * @throws When plugin loading fails\n */\nexport function loadAsyncImports(imports: Array<AsyncImportRawDescription | string> = []) {\n const loadExternalPlugin = async ({ url, import_name, import_as, window_name, stylesheets }: AsyncImportRawDescription) => {\n if (stylesheets?.length) {\n await loadAsyncCSS(stylesheets);\n }\n\n if (window_name) {\n function isScriptPresent() {\n return Object.prototype.hasOwnProperty.call(window, window_name!);\n }\n\n if (url && !isScriptPresent()) {\n await injectScript(url);\n }\n\n if (!isScriptPresent()) {\n window.dispatchEvent(\n new CustomEvent(`ckeditor:request-cjs-plugin:${window_name}`),\n );\n }\n\n if (!isScriptPresent()) {\n throw new Error(\n `Plugin window['${window_name}'] not found in global scope. `\n + 'Please ensure the plugin is loaded before CKEditor initialization.',\n );\n }\n\n return (window as any)[window_name!];\n }\n\n const module = await import(import_name!);\n const imported = module[import_as || 'default'];\n\n if (!imported) {\n throw new Error(\n `Plugin \"${import_as || 'default'}\" not found in the ESM module `\n + `\"${import_name}\"! Available imports: ${Object.keys(module).join(', ')}! `\n + 'Consider changing \"import_as\" value.',\n );\n }\n\n return imported;\n };\n\n function uncompressImport(pkg: any) {\n if (typeof pkg === 'string') {\n return loadExternalPlugin({ import_name: 'ckeditor5', import_as: pkg });\n }\n\n return loadExternalPlugin(pkg);\n }\n\n return Promise.all(imports.map(uncompressImport));\n}\n\n/**\n * Type definition for plugin raw descriptor\n */\nexport type AsyncImportRawDescription = {\n url?: string;\n import_name?: string;\n import_as?: string;\n window_name?: string;\n stylesheets?: string[];\n};\n","/**\n * Resolves element references in configuration object.\n * Looks for objects with { $element: \"selector\" } format and replaces them with actual DOM elements.\n *\n * @param obj - Configuration object to process\n * @returns Processed configuration object with resolved element references\n */\nexport function resolveConfigElementReferences<T>(obj: T): T {\n if (!obj || typeof obj !== 'object') {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map(item => resolveConfigElementReferences(item)) as T;\n }\n\n const anyObj = obj as any;\n\n if (anyObj.$element && typeof anyObj.$element === 'string') {\n const element = document.querySelector(anyObj.$element);\n\n if (!element) {\n console.warn(`Element not found for selector: ${anyObj.$element}`);\n }\n\n return (element || null) as T;\n }\n\n const result = Object.create(null);\n\n for (const [key, value] of Object.entries(obj)) {\n result[key] = resolveConfigElementReferences(value);\n }\n\n return result as T;\n}\n","/**\n * Generates a unique identifier string\n *\n * @returns Random string that can be used as unique identifier\n */\nexport function uid() {\n return Math.random().toString(36).substring(2);\n}\n","import type { ContextWatchdog } from 'ckeditor5';\n\nimport { execIfDOMReady, loadAsyncImports, resolveConfigElementReferences } from 'src/helpers';\n\nimport type { CKEditorComponent } from './editor';\n\nexport class CKEditorContextComponent extends HTMLElement {\n instance: ContextWatchdog | null = null;\n\n instancePromise = Promise.withResolvers<ContextWatchdog>();\n\n #connectedEditors = new Set<CKEditorComponent>();\n\n static get observedAttributes() {\n return ['plugins', 'config'];\n }\n\n async connectedCallback() {\n try {\n execIfDOMReady(() => this.#initializeContext());\n }\n catch (error) {\n console.error('Failed to initialize context:', error);\n this.dispatchEvent(new CustomEvent('context-error', { detail: error }));\n }\n }\n\n async attributeChangedCallback(_: unknown, oldValue: string | null, newValue: string | null) {\n if (oldValue !== null && oldValue !== newValue) {\n await this.#initializeContext();\n }\n }\n\n async disconnectedCallback() {\n if (this.instance) {\n await this.instance.destroy();\n this.instance = null;\n }\n }\n\n /**\n * Register editor component with this context\n *\n * @param editor - Editor component to register.\n */\n registerEditor(editor: CKEditorComponent) {\n this.#connectedEditors.add(editor);\n }\n\n /**\n * Unregister editor component from this context\n *\n * @param editor - Editor component to unregister\n */\n unregisterEditor(editor: CKEditorComponent) {\n this.#connectedEditors.delete(editor);\n }\n\n /**\n * Initialize CKEditor context with shared configuration\n *\n * @private\n */\n async #initializeContext() {\n if (this.instance) {\n this.instancePromise = Promise.withResolvers<ContextWatchdog>();\n\n await this.instance.destroy();\n\n this.instance = null;\n }\n\n // Broadcast context initialization event\n window.dispatchEvent(\n new CustomEvent('ckeditor:context:attach:before', { detail: { element: this } }),\n );\n\n const { Context, ContextWatchdog } = await import('ckeditor5');\n const plugins = await this.#getPlugins();\n const config = this.#getConfig();\n\n // Broadcast context mounting event with configuration\n window.dispatchEvent(\n new CustomEvent('ckeditor:context:attach', { detail: { config, element: this } }),\n );\n\n this.instance = new ContextWatchdog(Context, {\n crashNumberLimit: 10,\n });\n\n await this.instance.create({\n ...config,\n plugins,\n });\n\n this.instance.on('itemError', (...args) => {\n console.error('Context item error:', ...args);\n });\n\n this.instancePromise.resolve(this.instance);\n this.dispatchEvent(new CustomEvent('context-ready', { detail: this.instance }));\n\n // Reinitialize connected editors.\n await Promise.all(\n [...this.#connectedEditors].map(editor => editor.reinitializeEditor()),\n );\n }\n\n async #getPlugins() {\n const raw = this.getAttribute('plugins');\n\n return loadAsyncImports(raw ? JSON.parse(raw) : []);\n }\n\n /**\n * Gets context configuration with resolved element references.\n *\n * @private\n */\n #getConfig() {\n const config = JSON.parse(this.getAttribute('config') || '{}');\n\n return resolveConfigElementReferences(config);\n }\n}\n\ncustomElements.define('ckeditor-context-component', CKEditorContextComponent);\n","import type { CKEditorComponent } from './editor';\n\nimport { execIfDOMReady } from '../helpers/exec-if-dom-ready';\n\nexport class CKEditorEditableComponent extends HTMLElement {\n /**\n * List of attributes that trigger updates when changed\n *\n * @static\n * @returns {string[]} Array of attribute names to observe\n */\n static get observedAttributes() {\n return ['name'];\n }\n\n /**\n * Gets the name of this editable region\n */\n get name() {\n return this.getAttribute('name') || 'editable';\n }\n\n /**\n * Gets the actual editable DOM element.\n */\n get editableElement() {\n return this.querySelector('div')!;\n }\n\n /**\n * Lifecycle callback when element is added to DOM\n * Sets up the editable element and registers it with the parent editor\n */\n connectedCallback() {\n execIfDOMReady(() => {\n const editorComponent = this.#queryEditorElement();\n\n if (!editorComponent) {\n throw new Error('ckeditor-editable-component must be a child of ckeditor-component');\n }\n\n this.innerHTML = `<div>${this.innerHTML}</div>`;\n this.style.display = 'block';\n\n if (editorComponent.isDecoupled()) {\n editorComponent.runAfterEditorReady((editor) => {\n this.appendChild((editor.ui.view as any)[this.name].element);\n });\n }\n else {\n if (!this.name) {\n throw new Error('Editable component missing required \"name\" attribute');\n }\n\n editorComponent.editables![this.name] = this;\n }\n });\n }\n\n /**\n * Lifecycle callback for attribute changes\n * Handles name changes and propagates other attributes to editable element\n */\n attributeChangedCallback(name: string, oldValue: string, newValue: string) {\n if (oldValue === newValue) {\n return;\n }\n\n if (name === 'name') {\n if (!oldValue) {\n return;\n }\n\n const editorComponent = this.#queryEditorElement();\n\n if (editorComponent) {\n editorComponent.editables![newValue] = editorComponent.editables![oldValue]!;\n delete editorComponent.editables![oldValue];\n }\n }\n else {\n this.editableElement.setAttribute(name, newValue!);\n }\n }\n\n /**\n * Lifecycle callback when element is removed\n * Un-registers this editable from the parent editor\n */\n disconnectedCallback() {\n const editorComponent = this.#queryEditorElement();\n\n if (editorComponent) {\n delete editorComponent.editables![this.name];\n }\n }\n\n /**\n * Finds the parent editor component\n */\n #queryEditorElement(): CKEditorComponent | null {\n return this.closest('ckeditor-component') || document.body.querySelector('ckeditor-component');\n }\n}\n\ncustomElements.define('ckeditor-editable-component', CKEditorEditableComponent);\n","import type { MultiRootEditor } from 'ckeditor5';\n\nimport type { CKEditorComponent } from './editor';\n\nexport class CKEditorMultiRootEditablesTracker {\n #editorElement: CKEditorComponent;\n #editables: Record<string, HTMLElement>;\n\n /**\n * Creates new tracker instance wrapped in a Proxy for dynamic property access\n *\n * @param editorElement - Parent editor component reference\n * @param initialEditables - Initial editable elements\n * @returns Proxy wrapping the tracker\n */\n constructor(\n editorElement: CKEditorComponent,\n initialEditables: Record<string, HTMLElement> = {},\n ) {\n this.#editorElement = editorElement;\n this.#editables = initialEditables;\n\n return new Proxy(this, {\n /**\n * Handles property access, returns class methods or editable elements\n *\n * @param target - The tracker instance\n * @param name - Property name being accessed\n */\n get(target: CKEditorMultiRootEditablesTracker, name: string) {\n if (typeof (target as any)[name] === 'function') {\n return (target as any)[name].bind(target);\n }\n\n return target.#editables[name];\n },\n\n /**\n * Handles setting new editable elements, triggers root attachment\n *\n * @param target - The tracker instance\n * @param name - Name of the editable root\n * @param element - Element to attach as editable\n */\n set(target: CKEditorMultiRootEditablesTracker, name: string, element: HTMLElement) {\n if (target.#editables[name] !== element) {\n void target.attachRoot(name, element);\n target.#editables[name] = element;\n }\n return true;\n },\n\n /**\n * Handles removing editable elements, triggers root detachment\n *\n * @param target - The tracker instance\n * @param name - Name of the root to remove\n */\n deleteProperty(target: CKEditorMultiRootEditablesTracker, name: string) {\n void target.detachRoot(name);\n delete target.#editables[name];\n\n return true;\n },\n });\n }\n\n /**\n * Attaches a new editable root to the editor.\n * Creates new editor root and binds UI elements.\n *\n * @param name - Name of the editable root\n * @param element - DOM element to use as editable\n * @returns Resolves when root is attached\n */\n async attachRoot(name: string, element: HTMLElement) {\n await this.detachRoot(name);\n\n return this.#editorElement.runAfterEditorReady<MultiRootEditor>((editor) => {\n const { ui, editing, model } = editor;\n\n editor.addRoot(name, {\n isUndoable: false,\n data: element.innerHTML,\n });\n\n const root = model.document.getRoot(name);\n\n if (ui.getEditableElement(name)) {\n editor.detachEditable(root!);\n }\n\n const editable = ui.view.createEditable(name, element);\n ui.addEditable(editable);\n editing.view.forceRender();\n });\n }\n\n /**\n * Detaches an editable root from the editor.\n * Removes editor root and cleans up UI bindings.\n *\n * @param name - Name of root to detach\n * @returns Resolves when root is detached\n */\n async detachRoot(name: string) {\n return this.#editorElement.runAfterEditorReady<MultiRootEditor>((editor) => {\n const root = editor.model.document.getRoot(name);\n\n if (root) {\n editor.detachEditable(root);\n editor.detachRoot(name, true);\n }\n });\n }\n\n /**\n * Gets all currently tracked editable elements\n *\n * @returns Map of all editable elements\n */\n getAll() {\n return this.#editables;\n }\n}\n","import type { Editor, EditorWatchdog, Watchdog } from 'ckeditor5';\n\nimport type { AsyncImportRawDescription } from '../../helpers';\nimport type { CKEditorContextComponent } from '../context';\nimport type { CKEditorEditableComponent } from '../editable';\n\nimport {\n execIfDOMReady,\n isSafeKey,\n loadAsyncCSS,\n loadAsyncImports,\n resolveConfigElementReferences,\n uid,\n} from '../../helpers';\nimport { CKEditorMultiRootEditablesTracker } from './multiroot-editables-tracker';\n\nexport class CKEditorComponent extends HTMLElement {\n instancePromise = Promise.withResolvers<Editor>();\n\n watchdog: Watchdog | null = null;\n\n instance: Editor | null = null;\n\n editables: Record<string, HTMLElement> | null = Object.create({});\n\n #initialHTML: string = '';\n\n #context: CKEditorContextComponent | null = null;\n\n #contextEditorId: string | null = null;\n\n #bundle: object | null = null;\n\n /**\n * List of attributes that trigger updates when changed.\n */\n static get observedAttributes() {\n return ['config', 'plugins', 'translations', 'type'];\n }\n\n /**\n * List of input attributes that trigger updates when changed.\n */\n static get inputAttributes() {\n return ['name', 'required', 'value'];\n }\n\n get oneditorchange() {\n return this.#getEventHandler('editorchange');\n }\n\n set oneditorchange(handler) {\n this.#setEventHandler('editorchange', handler);\n }\n\n get oneditorready() {\n return this.#getEventHandler('editorready');\n }\n\n set oneditorready(handler) {\n this.#setEventHandler('editorready', handler);\n }\n\n get oneditorerror() {\n return this.#getEventHandler('editorerror');\n }\n\n set oneditorerror(handler) {\n this.#setEventHandler('editorerror', handler);\n }\n\n /**\n * Gets event handler function from attribute or property\n *\n * @private\n * @param name - Event name without 'on' prefix\n * @returns Event handler or null\n */\n #getEventHandler(name: string): Function | null {\n if (this.hasAttribute(`on${name}`)) {\n const handler = this.getAttribute(`on${name}`)!;\n\n if (!isSafeKey(handler)) {\n throw new Error(`Unsafe event handler attribute value: ${handler}`);\n }\n\n // eslint-disable-next-line no-new-func\n return (window as any)[handler] || new Function('event', handler);\n }\n return (this as any)[`#${name}Handler`];\n }\n\n /**\n * Sets event handler function\n *\n * @private\n * @param name - Event name without 'on' prefix\n * @param handler - Event handler\n */\n #setEventHandler(name: string, handler: Function | null) {\n if (typeof handler === 'string') {\n this.setAttribute(`on${name}`, handler);\n }\n else {\n this.removeAttribute(`on${name}`);\n (this as any)[`#${name}Handler`] = handler;\n }\n }\n\n /**\n * Lifecycle callback when element is connected to DOM\n * Initializes the editor when DOM is ready\n *\n * @protected\n */\n connectedCallback() {\n this.#context = this.closest('ckeditor-context-component');\n this.#initialHTML = this.innerHTML;\n\n try {\n execIfDOMReady(async () => {\n if (this.#context) {\n await this.#context.instancePromise.promise;\n this.#context.registerEditor(this);\n }\n\n await this.reinitializeEditor();\n });\n }\n catch (error) {\n console.error('Failed to initialize editor:', error);\n\n const event = new CustomEvent('editor-error', { detail: error });\n\n this.dispatchEvent(event);\n this.oneditorerror?.(event);\n }\n }\n\n /**\n * Handles attribute changes and reinitializes editor if needed\n *\n * @protected\n * @param name - Name of changed attribute\n * @param oldValue - Previous attribute value\n * @param newValue - New attribute value\n */\n async attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {\n if (oldValue !== null\n && oldValue !== newValue\n && CKEditorComponent.observedAttributes.includes(name) && this.isConnected) {\n await this.reinitializeEditor();\n }\n }\n\n /**\n * Lifecycle callback when element is removed from DOM\n * Destroys the editor instance\n * @protected\n */\n async disconnectedCallback() {\n if (this.#context) {\n this.#context.unregisterEditor(this);\n }\n\n try {\n await this.#destroy();\n }\n catch (error) {\n console.error('Failed to destroy editor:', error);\n }\n }\n\n /**\n * Runs a callback after the editor is ready. It waits for editor\n * initialization if needed.\n *\n * @param callback - Callback to run\n */\n runAfterEditorReady<E extends Editor>(callback: (editor: E) => void): Promise<void> {\n if (this.instance) {\n return Promise.resolve(callback(this.instance as unknown as E));\n }\n\n return this.instancePromise.promise.then(callback as unknown as any);\n }\n\n /**\n * Determines appropriate editor element tag based on editor type\n */\n get #editorElementTag() {\n switch (this.getAttribute('type')) {\n case 'ClassicEditor':\n return 'textarea';\n\n default:\n return 'div';\n }\n }\n\n /**\n * Gets the CKEditor context instance if available.\n */\n get #contextWatchdog() {\n return this.#context?.instance;\n }\n\n /**\n * Destroys the editor instance and watchdog if available\n */\n async #destroy() {\n if (this.#contextEditorId) {\n await this.#contextWatchdog!.remove(this.#contextEditorId);\n }\n\n await this.instance?.destroy();\n this.watchdog?.destroy();\n }\n\n /**\n * Gets editor configuration with resolved element references\n */\n #getConfig() {\n const config = JSON.parse(this.getAttribute('config') || '{}');\n\n return resolveConfigElementReferences(config);\n }\n\n /**\n * Creates a new CKEditor instance\n */\n async #initializeEditor(editablesOrContent: Record<string, HTMLElement | string> | CKEditorMultiRootEditablesTracker | string | HTMLElement) {\n await Promise.all([\n this.#ensureStylesheetsInjected(),\n this.#ensureWindowScriptsInjected(),\n ]);\n\n // Depending on the type of the editor the content supplied on the first\n // argument is different. For ClassicEditor it's a element or string, for MultiRootEditor\n // it's an object with editables, for DecoupledEditor it's string.\n let content: any = editablesOrContent;\n\n if (editablesOrContent instanceof CKEditorMultiRootEditablesTracker) {\n content = editablesOrContent.getAll();\n }\n else if (typeof editablesOrContent !== 'string') {\n content = (editablesOrContent as any)['main'];\n }\n\n // Broadcast editor initialization event. It's good time to load add inline window plugins.\n const beforeInitEventDetails = {\n ...content instanceof HTMLElement && { element: content },\n ...typeof content === 'string' && { data: content },\n ...content instanceof Object && { editables: content },\n };\n\n window.dispatchEvent(\n new CustomEvent('ckeditor:attach:before', { detail: beforeInitEventDetails }),\n );\n\n // Start fetching constructor.\n const Editor = await this.#getEditorConstructor();\n const [plugins, translations] = await Promise.all([\n this.#getPlugins(),\n this.#getTranslations(),\n ]);\n\n const config = {\n ...this.#getConfig(),\n ...translations.length && {\n translations,\n },\n plugins,\n };\n\n // Broadcast editor mounting event. It's good time to map configuration.\n window.dispatchEvent(\n new CustomEvent('ckeditor:attach', { detail: { config, ...beforeInitEventDetails } }),\n );\n\n // Initialize watchdog if needed\n let watchdog: EditorWatchdog | null = null;\n let instance: Editor | null = null;\n let contextId: string | null = null;\n\n if (this.#context) {\n contextId = uid();\n\n await this.#contextWatchdog!.add({\n creator: (_element, _config) => Editor.create(_element, _config),\n id: contextId,\n sourceElementOrData: content,\n type: 'editor',\n config,\n });\n\n instance = this.#contextWatchdog!.getItem(contextId) as Editor;\n }\n else if (this.hasWatchdog()) {\n // Let's create use with plain watchdog.\n const { EditorWatchdog } = await import('ckeditor5');\n watchdog = new EditorWatchdog(Editor);\n\n await watchdog.create(content, config);\n\n instance = watchdog.editor;\n }\n else {\n // Let's create the editor without watchdog.\n instance = await Editor.create(content, config);\n }\n\n return {\n contextId,\n instance,\n watchdog,\n };\n }\n\n /**\n * Re-initializes the editor by destroying existing instance and creating new one\n *\n * @private\n * @returns {Promise<void>}\n */\n async reinitializeEditor() {\n if (this.instance) {\n this.instancePromise = Promise.withResolvers();\n\n await this.#destroy();\n\n this.instance = null;\n }\n\n this.style.display = 'block';\n\n if (!this.isMultiroot() && !this.isDecoupled()) {\n this.innerHTML = `<${this.#editorElementTag}>${this.#initialHTML}</${this.#editorElementTag}>`;\n this.#assignInputAttributes();\n }\n\n // Let's track changes in editables if it's a multiroot editor.\n if (this.isMultiroot()) {\n this.editables = new CKEditorMultiRootEditablesTracker(this, this.#queryEditables()) as unknown as Record<string, HTMLElement>;\n }\n else if (this.isDecoupled()) {\n this.editables = null;\n }\n else {\n this.editables = this.#queryEditables();\n }\n\n try {\n const { watchdog, instance, contextId } = await this.#initializeEditor(this.editables || this.#getConfig().initialData || '');\n\n this.watchdog = watchdog;\n this.instance = instance!;\n this.#contextEditorId = contextId;\n\n this.#setupContentSync();\n this.#setupEditableHeight();\n this.#setupDataChangeListener();\n\n this.instancePromise.resolve(this.instance!);\n\n // Broadcast editor ready event\n const event = new CustomEvent('editor-ready', { detail: this.instance });\n\n this.dispatchEvent(event);\n this.oneditorready?.(event);\n }\n catch (err) {\n this.instancePromise.reject(err);\n throw err;\n }\n }\n\n /**\n * Sets up data change listener that broadcasts content changes\n */\n #setupDataChangeListener() {\n const getRootContent = (rootName: string) => this.instance!.getData({ rootName });\n const getAllRoots = () =>\n this.instance?.model.document\n .getRootNames()\n .reduce((acc, rootName) => ({\n ...acc,\n [rootName]: getRootContent(rootName),\n }), {});\n\n this.instance?.model.document.on('change:data', () => {\n const event = new CustomEvent('editor-change', {\n detail: {\n editor: this.instance,\n data: getAllRoots(),\n },\n bubbles: true,\n });\n\n this.dispatchEvent(event);\n this.oneditorchange?.(event);\n });\n }\n\n /**\n * Checks if current editor is classic type\n */\n isClassic() {\n return this.getAttribute('type') === 'ClassicEditor';\n }\n\n /**\n * Checks if current editor is balloon type\n */\n isBallon() {\n return this.getAttribute('type') === 'BalloonEditor';\n }\n\n /**\n * Checks if current editor is multiroot type\n */\n isMultiroot() {\n return this.getAttribute('type') === 'MultiRootEditor';\n }\n\n /**\n * Checks if current editor is decoupled type\n */\n isDecoupled() {\n return this.getAttribute('type') === 'DecoupledEditor';\n }\n\n /**\n * Checks if current editor has watchdog enabled\n */\n hasWatchdog() {\n return this.getAttribute('watchdog') === 'true';\n }\n\n /**\n * Queries and validates editable elements\n */\n #queryEditables() {\n if (this.isDecoupled()) {\n return {};\n }\n\n if (this.isMultiroot()) {\n const editables = [...this.querySelectorAll('ckeditor-editable-component')] as CKEditorEditableComponent[];\n\n return editables.reduce((acc, element) => {\n if (!element.name) {\n throw new Error('Editable component missing required \"name\" attribute');\n }\n acc[element.name] = element;\n return acc;\n }, Object.create(null));\n }\n\n const mainEditable = this.querySelector(this.#editorElementTag);\n\n if (!mainEditable) {\n throw new Error(`No ${this.#editorElementTag} element found`);\n }\n\n return { main: mainEditable };\n }\n\n /**\n * Copies input-related attributes from component to the main editable element\n *\n * @private\n */\n #assignInputAttributes() {\n const textarea = this.querySelector('textarea');\n\n if (!textarea) {\n return;\n }\n\n for (const attr of CKEditorComponent.inputAttributes) {\n if (this.hasAttribute(attr)) {\n textarea.setAttribute(attr, this.getAttribute(attr)!);\n }\n }\n }\n\n /**\n * Sets up content sync between editor and textarea element.\n *\n * @private\n */\n #setupContentSync() {\n if (!this.instance) {\n return;\n }\n\n const textarea = this.querySelector('textarea');\n\n if (!textarea) {\n return;\n }\n\n // Initial sync\n const syncInput = () => {\n this.style.position = 'relative';\n\n textarea.innerHTML = '';\n textarea.value = this.instance!.getData();\n textarea.tabIndex = -1;\n\n Object.assign(textarea.style, {\n display: 'flex',\n position: 'absolute',\n bottom: '0',\n left: '50%',\n width: '1px',\n height: '1px',\n opacity: '0',\n pointerEvents: 'none',\n margin: '0',\n padding: '0',\n border: 'none',\n });\n };\n\n syncInput();\n\n // Listen for changes\n this.instance.model.document.on('change:data', () => {\n textarea.dispatchEvent(new Event('input', { bubbles: true }));\n textarea.dispatchEvent(new Event('change', { bubbles: true }));\n\n syncInput();\n });\n }\n\n /**\n * Sets up editable height for ClassicEditor\n *\n * @private\n */\n #setupEditableHeight() {\n if (!this.isClassic() && !this.isBallon()) {\n return;\n }\n\n const { instance } = this;\n const height = Number.parseInt(this.getAttribute('editable-height')!, 10);\n\n if (Number.isNaN(height)) {\n return;\n }\n\n instance!.editing.view.change((writer) => {\n writer.setStyle('height', `${height}px`, instance!.editing.view.document.getRoot()!);\n });\n }\n\n /**\n * Gets bundle JSON description from translations attribute\n */\n #getBundle(): BundleDescription {\n return this.#bundle ||= JSON.parse(this.getAttribute('bundle')!);\n }\n\n /**\n * Checks if all required stylesheets are injected. If not, inject.\n */\n async #ensureStylesheetsInjected() {\n await loadAsyncCSS(this.#getBundle()?.stylesheets || []);\n }\n\n /**\n * Checks if all required scripts are injected. If not, inject.\n */\n async #ensureWindowScriptsInjected() {\n const windowScripts = (this.#getBundle()?.scripts || []).filter(script => !!script.window_name);\n\n await loadAsyncImports(windowScripts);\n }\n\n /**\n * Loads translation modules\n */\n async #getTranslations() {\n const translations = this.#getBundle()?.scripts.filter(script => script.translation);\n\n return loadAsyncImports(translations);\n }\n\n /**\n * Loads plugin modules\n */\n async #getPlugins() {\n const raw = this.getAttribute('plugins');\n const items = raw ? JSON.parse(raw) : [];\n const mappedItems = items.map((item: any) =>\n typeof item === 'string'\n ? { import_name: 'ckeditor5', import_as: item }\n : item,\n );\n\n return loadAsyncImports(mappedItems);\n }\n\n /**\n * Gets editor constructor based on type attribute\n */\n async #getEditorConstructor() {\n const CKEditor = await import('ckeditor5');\n const editorType = this.getAttribute('type');\n\n if (!editorType || !Object.prototype.hasOwnProperty.call(CKEditor, editorType)) {\n throw new Error(`Invalid editor type: ${editorType}`);\n }\n\n return (CKEditor as any)[editorType] as EditorConstructor;\n }\n}\n\ntype EditorConstructor = {\n create: (...args: any[]) => Promise<Editor>;\n};\n\ntype BundleDescription = {\n stylesheets: string[];\n scripts: Array<AsyncImportRawDescription & {\n translation?: boolean;\n }>;\n};\n\ncustomElements.define('ckeditor-component', CKEditorComponent);\n","import type { CKEditorComponent } from './editor';\n\nimport { execIfDOMReady } from '../helpers';\n\nclass CKEditorUIPartComponent extends HTMLElement {\n /**\n * Lifecycle callback when element is added to DOM.\n * Adds the toolbar to the editor UI.\n */\n connectedCallback() {\n execIfDOMReady(async () => {\n const uiPart = this.getAttribute('name')!;\n const editor = await this.#queryEditorElement()!.instancePromise.promise;\n\n this.appendChild((editor.ui.view as any)[uiPart].element);\n });\n }\n\n /**\n * Finds the parent editor component.\n */\n #queryEditorElement(): CKEditorComponent | null {\n return this.closest('ckeditor-component') || document.body.querySelector('ckeditor-component');\n }\n}\n\ncustomElements.define('ckeditor-ui-part-component', CKEditorUIPartComponent);\n"],"names":["execIfDOMReady","callback","SCRIPT_LOAD_PROMISES","injectScript","url","promise","resolve","reject","script","isSafeKey","key","stylesheetExists","href","sheet","loadAsyncCSS","stylesheets","promises","link","loadAsyncImports","imports","loadExternalPlugin","import_name","import_as","window_name","isScriptPresent","module","imported","uncompressImport","pkg","resolveConfigElementReferences","obj","item","anyObj","element","result","value","uid","CKEditorContextComponent","#connectedEditors","#initializeContext","error","_","oldValue","newValue","editor","Context","ContextWatchdog","plugins","#getPlugins","config","#getConfig","args","raw","CKEditorEditableComponent","editorComponent","#queryEditorElement","name","CKEditorMultiRootEditablesTracker","#editorElement","#editables","editorElement","initialEditables","target","ui","editing","model","root","editable","CKEditorComponent","#initialHTML","#context","#contextEditorId","#bundle","#getEventHandler","handler","#setEventHandler","event","#destroy","#editorElementTag","#contextWatchdog","#initializeEditor","editablesOrContent","#ensureStylesheetsInjected","#ensureWindowScriptsInjected","content","beforeInitEventDetails","Editor","#getEditorConstructor","translations","#getTranslations","watchdog","instance","contextId","_element","_config","EditorWatchdog","#assignInputAttributes","#queryEditables","#setupContentSync","#setupEditableHeight","#setupDataChangeListener","err","getRootContent","rootName","getAllRoots","acc","mainEditable","textarea","attr","syncInput","height","writer","#getBundle","windowScripts","mappedItems","CKEditor","editorType","CKEditorUIPartComponent","uiPart"],"mappings":"AAKO,SAASA,EAAeC,GAAwB;AACrD,UAAQ,SAAS,YAAA;AAAA,IACf,KAAK;AACH,eAAS,iBAAiB,oBAAoBA,GAAU,EAAE,MAAM,IAAM;AACtE;AAAA,IAEF,KAAK;AAAA,IACL,KAAK;AACH,iBAAWA,GAAU,CAAC;AACtB;AAAA,IAE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AAc,QAAQ,OAAO,CAAAxG,MAAUA,EAAO,WAAW;AAEnF,WAAOU,EAAiBsE,CAAY;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAMxC,KAAc;AAClB,UAAMI,IAAM,KAAK,aAAa,SAAS,GAEjC8D,KADQ9D,IAAM,KAAK,MAAMA,CAAG,IAAI,CAAA,GACZ;AAAA,MAAI,CAACrB,MAC7B,OAAOA,KAAS,WACZ,EAAE,aAAa,aAAa,WAAWA,MACvCA;AAAA,IAAA;AAGN,WAAOb,EAAiBgG,CAAW;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM3B,KAAwB;AAC5B,UAAM4B,IAAW,MAAM,OAAO,WAAW,GACnCC,IAAa,KAAK,aAAa,MAAM;AAE3C,QAAI,CAACA,KAAc,CAAC,OAAO,UAAU,eAAe,KAAKD,GAAUC,CAAU;AAC3E,YAAM,IAAI,MAAM,wBAAwBA,CAAU,EAAE;AAGtD,WAAQD,EAAiBC,CAAU;AAAA,EACrC;AACF;AAaA,eAAe,OAAO,sBAAsBhD,CAAiB;ACpnB7D,MAAMiD,UAAgC,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA,EAKhD,oBAAoB;AAClB,IAAArH,EAAe,YAAY;AACzB,YAAMsH,IAAS,KAAK,aAAa,MAAM,GACjC1E,IAAS,MAAM,KAAKW,GAAA,EAAuB,gBAAgB;AAEjE,WAAK,YAAaX,EAAO,GAAG,KAAa0E,CAAM,EAAE,OAAO;AAAA,IAC1D,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA/D,KAAgD;AAC9C,WAAO,KAAK,QAAQ,oBAAoB,KAAK,SAAS,KAAK,cAAc,oBAAoB;AAAA,EAC/F;AACF;AAEA,eAAe,OAAO,8BAA8B8D,CAAuB;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/helpers/exec-if-dom-ready.ts","../src/helpers/inject-script.ts","../src/helpers/is-safe-key.ts","../src/helpers/load-async-css.ts","../src/helpers/load-async-imports.ts","../src/helpers/resolve-config-element-references.ts","../src/helpers/uid.ts","../src/components/context.ts","../src/components/editable.ts","../src/components/editor/multiroot-editables-tracker.ts","../src/components/editor/editor.ts","../src/components/ui-part.ts"],"sourcesContent":["/**\n * Executes callback when DOM is ready.\n *\n * @param callback - Function to execute when DOM is ready.\n */\nexport function execIfDOMReady(callback: VoidFunction) {\n switch (document.readyState) {\n case 'loading':\n document.addEventListener('DOMContentLoaded', callback, { once: true });\n break;\n\n case 'interactive':\n case 'complete':\n setTimeout(callback, 0);\n break;\n\n default:\n console.warn('Unexpected document.readyState:', document.readyState);\n setTimeout(callback, 0);\n }\n}\n","const SCRIPT_LOAD_PROMISES = new Map();\n\n/**\n * Dynamically loads script files based on configuration.\n * Uses caching to avoid loading the same script multiple times.\n *\n * @param url - URL of the script to load\n */\nexport function injectScript(url: string) {\n if (SCRIPT_LOAD_PROMISES.has(url)) {\n return SCRIPT_LOAD_PROMISES.get(url);\n }\n\n const promise = new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.src = url;\n script.onload = resolve;\n script.onerror = reject;\n\n document.head.appendChild(script);\n });\n\n SCRIPT_LOAD_PROMISES.set(url, promise);\n return promise;\n}\n","/**\n * Checks if a key is safe to use in configuration objects to prevent prototype pollution\n *\n * @param key - Key name to check\n * @returns True if key is safe to use\n */\nexport function isSafeKey(key: string) {\n return (\n typeof key === 'string'\n && key !== '__proto__'\n && key !== 'constructor'\n && key !== 'prototype'\n );\n}\n","/**\n * Checks if stylesheet with given href already exists in document\n *\n * @param href - Stylesheet URL to check\n * @returns True if stylesheet already exists\n */\nfunction stylesheetExists(href: string) {\n return Array\n .from(document.styleSheets)\n .some(sheet =>\n sheet.href === href || sheet.href === new URL(href, window.location.href).href,\n );\n}\n\n/**\n * Dynamically loads CSS files based on configuration\n *\n * @param stylesheets - Array of CSS file URLs to load\n * @returns Array of promises for each CSS file load\n * @throws When CSS file loading fails\n */\nexport function loadAsyncCSS(stylesheets: string[] = []) {\n const promises = stylesheets.map(href =>\n new Promise<void>((resolve, reject) => {\n if (stylesheetExists(href)) {\n resolve();\n return;\n }\n\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = href;\n\n link.onerror = reject;\n link.onload = () => resolve();\n\n document.head.appendChild(link);\n }),\n );\n\n return Promise.all(promises);\n}\n","import { injectScript } from './inject-script';\nimport { loadAsyncCSS } from './load-async-css';\n\n/**\n * Dynamically imports modules based on configuration\n *\n * @param imports - Array of import configurations\n * @param imports[].name - Name of inline plugin (for inline type)\n * @param imports[].code - Source code of inline plugin (for inline type)\n * @param imports[].import_name - Module path to import (for external type)\n * @param imports[].import_as - Name to import as (for external type)\n * @param imports[].window_name - Global window object name (for external type)\n * @param imports[].type - Type of import\n * @returns Array of loaded modules\n * @throws When plugin loading fails\n */\nexport function loadAsyncImports(imports: Array<AsyncImportRawDescription | string> = []) {\n const loadExternalPlugin = async ({ url, import_name, import_as, window_name, stylesheets }: AsyncImportRawDescription) => {\n if (stylesheets?.length) {\n await loadAsyncCSS(stylesheets);\n }\n\n if (window_name) {\n function isScriptPresent() {\n return Object.prototype.hasOwnProperty.call(window, window_name!);\n }\n\n if (url && !isScriptPresent()) {\n await injectScript(url);\n }\n\n if (!isScriptPresent()) {\n window.dispatchEvent(\n new CustomEvent(`ckeditor:request-cjs-plugin:${window_name}`),\n );\n }\n\n if (!isScriptPresent()) {\n throw new Error(\n `Plugin window['${window_name}'] not found in global scope. `\n + 'Please ensure the plugin is loaded before CKEditor initialization.',\n );\n }\n\n return (window as any)[window_name!];\n }\n\n const module = await import(import_name!);\n const imported = module[import_as || 'default'];\n\n if (!imported) {\n throw new Error(\n `Plugin \"${import_as || 'default'}\" not found in the ESM module `\n + `\"${import_name}\"! Available imports: ${Object.keys(module).join(', ')}! `\n + 'Consider changing \"import_as\" value.',\n );\n }\n\n return imported;\n };\n\n function uncompressImport(pkg: any) {\n if (typeof pkg === 'string') {\n return loadExternalPlugin({ import_name: 'ckeditor5', import_as: pkg });\n }\n\n return loadExternalPlugin(pkg);\n }\n\n return Promise.all(imports.map(uncompressImport));\n}\n\n/**\n * Type definition for plugin raw descriptor\n */\nexport type AsyncImportRawDescription = {\n url?: string;\n import_name?: string;\n import_as?: string;\n window_name?: string;\n stylesheets?: string[];\n};\n","/**\n * Resolves element references in configuration object.\n * Looks for objects with { $element: \"selector\" } format and replaces them with actual DOM elements.\n *\n * @param obj - Configuration object to process\n * @returns Processed configuration object with resolved element references\n */\nexport function resolveConfigElementReferences<T>(obj: T): T {\n if (!obj || typeof obj !== 'object') {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map(item => resolveConfigElementReferences(item)) as T;\n }\n\n const anyObj = obj as any;\n\n if (anyObj.$element && typeof anyObj.$element === 'string') {\n const element = document.querySelector(anyObj.$element);\n\n if (!element) {\n console.warn(`Element not found for selector: ${anyObj.$element}`);\n }\n\n return (element || null) as T;\n }\n\n const result = Object.create(null);\n\n for (const [key, value] of Object.entries(obj)) {\n result[key] = resolveConfigElementReferences(value);\n }\n\n return result as T;\n}\n","/**\n * Generates a unique identifier string\n *\n * @returns Random string that can be used as unique identifier\n */\nexport function uid() {\n return Math.random().toString(36).substring(2);\n}\n","import type { ContextWatchdog } from 'ckeditor5';\n\nimport type { CKEditorComponent } from './editor';\n\nimport { execIfDOMReady, loadAsyncImports, resolveConfigElementReferences } from '../helpers';\n\nexport class CKEditorContextComponent extends HTMLElement {\n instance: ContextWatchdog | null = null;\n\n instancePromise = Promise.withResolvers<ContextWatchdog>();\n\n #connectedEditors = new Set<CKEditorComponent>();\n\n static get observedAttributes() {\n return ['plugins', 'config'];\n }\n\n async connectedCallback() {\n try {\n execIfDOMReady(() => this.#initializeContext());\n }\n catch (error) {\n console.error('Failed to initialize context:', error);\n this.dispatchEvent(new CustomEvent('context-error', { detail: error }));\n }\n }\n\n async attributeChangedCallback(_: unknown, oldValue: string | null, newValue: string | null) {\n if (oldValue !== null && oldValue !== newValue) {\n await this.#initializeContext();\n }\n }\n\n async disconnectedCallback() {\n if (this.instance) {\n await this.instance.destroy();\n this.instance = null;\n }\n }\n\n /**\n * Register editor component with this context\n *\n * @param editor - Editor component to register.\n */\n registerEditor(editor: CKEditorComponent) {\n this.#connectedEditors.add(editor);\n }\n\n /**\n * Unregister editor component from this context\n *\n * @param editor - Editor component to unregister\n */\n unregisterEditor(editor: CKEditorComponent) {\n this.#connectedEditors.delete(editor);\n }\n\n /**\n * Initialize CKEditor context with shared configuration\n *\n * @private\n */\n async #initializeContext() {\n if (this.instance) {\n this.instancePromise = Promise.withResolvers<ContextWatchdog>();\n\n await this.instance.destroy();\n\n this.instance = null;\n }\n\n // Broadcast context initialization event\n window.dispatchEvent(\n new CustomEvent('ckeditor:context:attach:before', { detail: { element: this } }),\n );\n\n const { Context, ContextWatchdog } = await import('ckeditor5');\n const plugins = await this.#getPlugins();\n const config = this.#getConfig();\n\n // Broadcast context mounting event with configuration\n window.dispatchEvent(\n new CustomEvent('ckeditor:context:attach', { detail: { config, element: this } }),\n );\n\n this.instance = new ContextWatchdog(Context, {\n crashNumberLimit: 10,\n });\n\n await this.instance.create({\n ...config,\n plugins,\n });\n\n this.instance.on('itemError', (...args) => {\n console.error('Context item error:', ...args);\n });\n\n this.instancePromise.resolve(this.instance);\n this.dispatchEvent(new CustomEvent('context-ready', { detail: this.instance }));\n\n // Reinitialize connected editors.\n await Promise.all(\n [...this.#connectedEditors].map(editor => editor.reinitializeEditor()),\n );\n }\n\n async #getPlugins() {\n const raw = this.getAttribute('plugins');\n\n return loadAsyncImports(raw ? JSON.parse(raw) : []);\n }\n\n /**\n * Gets context configuration with resolved element references.\n *\n * @private\n */\n #getConfig() {\n const config = JSON.parse(this.getAttribute('config') || '{}');\n\n return resolveConfigElementReferences(config);\n }\n}\n\ncustomElements.define('ckeditor-context-component', CKEditorContextComponent);\n","import type { CKEditorComponent } from './editor';\n\nimport { execIfDOMReady } from '../helpers/exec-if-dom-ready';\n\nexport class CKEditorEditableComponent extends HTMLElement {\n /**\n * List of attributes that trigger updates when changed\n *\n * @static\n * @returns {string[]} Array of attribute names to observe\n */\n static get observedAttributes() {\n return ['name'];\n }\n\n /**\n * Gets the name of this editable region\n */\n get name() {\n return this.getAttribute('name') || 'editable';\n }\n\n /**\n * Gets the actual editable DOM element.\n */\n get editableElement() {\n return this.querySelector('div')!;\n }\n\n /**\n * Lifecycle callback when element is added to DOM\n * Sets up the editable element and registers it with the parent editor\n */\n connectedCallback() {\n execIfDOMReady(() => {\n const editorComponent = this.#queryEditorElement();\n\n if (!editorComponent) {\n throw new Error('ckeditor-editable-component must be a child of ckeditor-component');\n }\n\n this.innerHTML = `<div>${this.innerHTML}</div>`;\n this.style.display = 'block';\n\n if (editorComponent.isDecoupled()) {\n editorComponent.runAfterEditorReady((editor) => {\n this.appendChild((editor.ui.view as any)[this.name].element);\n });\n }\n else if (editorComponent.editables) {\n if (!this.name) {\n throw new Error('Editable component missing required \"name\" attribute');\n }\n\n editorComponent.editables[this.name] = this;\n }\n });\n }\n\n /**\n * Lifecycle callback for attribute changes\n * Handles name changes and propagates other attributes to editable element\n */\n attributeChangedCallback(name: string, oldValue: string, newValue: string) {\n if (oldValue === newValue) {\n return;\n }\n\n if (name === 'name') {\n if (!oldValue) {\n return;\n }\n\n const editorComponent = this.#queryEditorElement();\n\n if (editorComponent?.editables?.[oldValue]) {\n editorComponent.editables[newValue] = editorComponent.editables[oldValue];\n delete editorComponent.editables[oldValue];\n }\n }\n else {\n this.editableElement.setAttribute(name, newValue!);\n }\n }\n\n /**\n * Lifecycle callback when element is removed\n * Un-registers this editable from the parent editor\n */\n disconnectedCallback() {\n const editorComponent = this.#queryEditorElement();\n\n if (editorComponent?.editables) {\n delete editorComponent.editables[this.name];\n }\n }\n\n /**\n * Finds the parent editor component\n */\n #queryEditorElement(): CKEditorComponent | null {\n return this.closest('ckeditor-component') || document.body.querySelector('ckeditor-component');\n }\n}\n\ncustomElements.define('ckeditor-editable-component', CKEditorEditableComponent);\n","import type { MultiRootEditor } from 'ckeditor5';\n\nimport type { CKEditorComponent } from './editor';\n\nexport class CKEditorMultiRootEditablesTracker {\n #editorElement: CKEditorComponent;\n #editables: Record<string, HTMLElement>;\n\n /**\n * Creates new tracker instance wrapped in a Proxy for dynamic property access\n *\n * @param editorElement - Parent editor component reference\n * @param initialEditables - Initial editable elements\n * @returns Proxy wrapping the tracker\n */\n constructor(\n editorElement: CKEditorComponent,\n initialEditables: Record<string, HTMLElement> = {},\n ) {\n this.#editorElement = editorElement;\n this.#editables = initialEditables;\n\n return new Proxy(this, {\n /**\n * Handles property access, returns class methods or editable elements\n *\n * @param target - The tracker instance\n * @param name - Property name being accessed\n */\n get(target: CKEditorMultiRootEditablesTracker, name: string) {\n if (typeof (target as any)[name] === 'function') {\n return (target as any)[name].bind(target);\n }\n\n return target.#editables[name];\n },\n\n /**\n * Handles setting new editable elements, triggers root attachment\n *\n * @param target - The tracker instance\n * @param name - Name of the editable root\n * @param element - Element to attach as editable\n */\n set(target: CKEditorMultiRootEditablesTracker, name: string, element: HTMLElement) {\n if (target.#editables[name] !== element) {\n void target.attachRoot(name, element);\n target.#editables[name] = element;\n }\n return true;\n },\n\n /**\n * Handles removing editable elements, triggers root detachment\n *\n * @param target - The tracker instance\n * @param name - Name of the root to remove\n */\n deleteProperty(target: CKEditorMultiRootEditablesTracker, name: string) {\n void target.detachRoot(name);\n delete target.#editables[name];\n\n return true;\n },\n });\n }\n\n /**\n * Attaches a new editable root to the editor.\n * Creates new editor root and binds UI elements.\n *\n * @param name - Name of the editable root\n * @param element - DOM element to use as editable\n * @returns Resolves when root is attached\n */\n async attachRoot(name: string, element: HTMLElement) {\n await this.detachRoot(name);\n\n return this.#editorElement.runAfterEditorReady<MultiRootEditor>((editor) => {\n const { ui, editing, model } = editor;\n\n editor.addRoot(name, {\n isUndoable: false,\n data: element.innerHTML,\n });\n\n const root = model.document.getRoot(name);\n\n if (ui.getEditableElement(name)) {\n editor.detachEditable(root!);\n }\n\n const editable = ui.view.createEditable(name, element);\n ui.addEditable(editable);\n editing.view.forceRender();\n });\n }\n\n /**\n * Detaches an editable root from the editor.\n * Removes editor root and cleans up UI bindings.\n *\n * @param name - Name of root to detach\n * @returns Resolves when root is detached\n */\n async detachRoot(name: string) {\n return this.#editorElement.runAfterEditorReady<MultiRootEditor>((editor) => {\n const root = editor.model.document.getRoot(name);\n\n if (root) {\n editor.detachEditable(root);\n editor.detachRoot(name, true);\n }\n });\n }\n\n /**\n * Gets all currently tracked editable elements\n *\n * @returns Map of all editable elements\n */\n getAll() {\n return this.#editables;\n }\n}\n","import type { Editor, EditorWatchdog, Watchdog } from 'ckeditor5';\n\nimport type { AsyncImportRawDescription } from '../../helpers';\nimport type { CKEditorContextComponent } from '../context';\nimport type { CKEditorEditableComponent } from '../editable';\n\nimport {\n execIfDOMReady,\n isSafeKey,\n loadAsyncCSS,\n loadAsyncImports,\n resolveConfigElementReferences,\n uid,\n} from '../../helpers';\nimport { CKEditorMultiRootEditablesTracker } from './multiroot-editables-tracker';\n\nexport class CKEditorComponent extends HTMLElement {\n instancePromise = Promise.withResolvers<Editor>();\n\n watchdog: Watchdog | null = null;\n\n instance: Editor | null = null;\n\n editables: Record<string, HTMLElement> | null = Object.create({});\n\n #initialHTML: string = '';\n\n #context: CKEditorContextComponent | null = null;\n\n #contextEditorId: string | null = null;\n\n #bundle: object | null = null;\n\n /**\n * List of attributes that trigger updates when changed.\n */\n static get observedAttributes() {\n return ['config', 'plugins', 'translations', 'type'];\n }\n\n /**\n * List of input attributes that trigger updates when changed.\n */\n static get inputAttributes() {\n return ['name', 'required', 'value'];\n }\n\n get oneditorchange() {\n return this.#getEventHandler('editorchange');\n }\n\n set oneditorchange(handler) {\n this.#setEventHandler('editorchange', handler);\n }\n\n get oneditorready() {\n return this.#getEventHandler('editorready');\n }\n\n set oneditorready(handler) {\n this.#setEventHandler('editorready', handler);\n }\n\n get oneditorerror() {\n return this.#getEventHandler('editorerror');\n }\n\n set oneditorerror(handler) {\n this.#setEventHandler('editorerror', handler);\n }\n\n /**\n * Gets event handler function from attribute or property\n *\n * @private\n * @param name - Event name without 'on' prefix\n * @returns Event handler or null\n */\n #getEventHandler(name: string): Function | null {\n if (this.hasAttribute(`on${name}`)) {\n const handler = this.getAttribute(`on${name}`)!;\n\n if (!isSafeKey(handler)) {\n throw new Error(`Unsafe event handler attribute value: ${handler}`);\n }\n\n // eslint-disable-next-line no-new-func\n return (window as any)[handler] || new Function('event', handler);\n }\n return (this as any)[`#${name}Handler`];\n }\n\n /**\n * Sets event handler function\n *\n * @private\n * @param name - Event name without 'on' prefix\n * @param handler - Event handler\n */\n #setEventHandler(name: string, handler: Function | null) {\n if (typeof handler === 'string') {\n this.setAttribute(`on${name}`, handler);\n }\n else {\n this.removeAttribute(`on${name}`);\n (this as any)[`#${name}Handler`] = handler;\n }\n }\n\n /**\n * Lifecycle callback when element is connected to DOM\n * Initializes the editor when DOM is ready\n *\n * @protected\n */\n connectedCallback() {\n this.#context = this.closest('ckeditor-context-component');\n this.#initialHTML = this.innerHTML;\n\n try {\n execIfDOMReady(async () => {\n if (this.#context) {\n await this.#context.instancePromise.promise;\n this.#context.registerEditor(this);\n }\n\n await this.reinitializeEditor();\n });\n }\n catch (error) {\n console.error('Failed to initialize editor:', error);\n\n const event = new CustomEvent('editor-error', { detail: error });\n\n this.dispatchEvent(event);\n this.oneditorerror?.(event);\n }\n }\n\n /**\n * Handles attribute changes and reinitializes editor if needed\n *\n * @protected\n * @param name - Name of changed attribute\n * @param oldValue - Previous attribute value\n * @param newValue - New attribute value\n */\n async attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {\n if (oldValue !== null\n && oldValue !== newValue\n && CKEditorComponent.observedAttributes.includes(name) && this.isConnected) {\n await this.reinitializeEditor();\n }\n }\n\n /**\n * Lifecycle callback when element is removed from DOM\n * Destroys the editor instance\n * @protected\n */\n async disconnectedCallback() {\n if (this.#context) {\n this.#context.unregisterEditor(this);\n }\n\n try {\n await this.#destroy();\n }\n catch (error) {\n console.error('Failed to destroy editor:', error);\n }\n }\n\n /**\n * Runs a callback after the editor is ready. It waits for editor\n * initialization if needed.\n *\n * @param callback - Callback to run\n */\n runAfterEditorReady<E extends Editor>(callback: (editor: E) => void): Promise<void> {\n if (this.instance) {\n return Promise.resolve(callback(this.instance as unknown as E));\n }\n\n return this.instancePromise.promise.then(callback as unknown as any);\n }\n\n /**\n * Determines appropriate editor element tag based on editor type\n */\n get #editorElementTag() {\n switch (this.getAttribute('type')) {\n case 'ClassicEditor':\n return 'textarea';\n\n default:\n return 'div';\n }\n }\n\n /**\n * Gets the CKEditor context instance if available.\n */\n get #contextWatchdog() {\n return this.#context?.instance;\n }\n\n /**\n * Destroys the editor instance and watchdog if available\n */\n async #destroy() {\n if (this.#contextEditorId) {\n await this.#contextWatchdog!.remove(this.#contextEditorId);\n }\n\n await this.instance?.destroy();\n this.watchdog?.destroy();\n }\n\n /**\n * Gets editor configuration with resolved element references\n */\n #getConfig() {\n const config = JSON.parse(this.getAttribute('config') || '{}');\n\n return resolveConfigElementReferences(config);\n }\n\n /**\n * Creates a new CKEditor instance\n */\n async #initializeEditor(editablesOrContent: Record<string, HTMLElement | string> | CKEditorMultiRootEditablesTracker | string | HTMLElement) {\n await Promise.all([\n this.#ensureStylesheetsInjected(),\n this.#ensureWindowScriptsInjected(),\n ]);\n\n // Depending on the type of the editor the content supplied on the first\n // argument is different. For ClassicEditor it's a element or string, for MultiRootEditor\n // it's an object with editables, for DecoupledEditor it's string.\n let content: any = editablesOrContent;\n\n if (editablesOrContent instanceof CKEditorMultiRootEditablesTracker) {\n content = editablesOrContent.getAll();\n }\n else if (typeof editablesOrContent !== 'string') {\n content = (editablesOrContent as any)['main'];\n }\n\n // Broadcast editor initialization event. It's good time to load add inline window plugins.\n const beforeInitEventDetails = {\n ...content instanceof HTMLElement && { element: content },\n ...typeof content === 'string' && { data: content },\n ...content instanceof Object && { editables: content },\n };\n\n window.dispatchEvent(\n new CustomEvent('ckeditor:attach:before', { detail: beforeInitEventDetails }),\n );\n\n // Start fetching constructor.\n const Editor = await this.#getEditorConstructor();\n const [plugins, translations] = await Promise.all([\n this.#getPlugins(),\n this.#getTranslations(),\n ]);\n\n const config = {\n ...this.#getConfig(),\n ...translations.length && {\n translations,\n },\n plugins,\n };\n\n // Broadcast editor mounting event. It's good time to map configuration.\n window.dispatchEvent(\n new CustomEvent('ckeditor:attach', { detail: { config, ...beforeInitEventDetails } }),\n );\n\n // Initialize watchdog if needed\n let watchdog: EditorWatchdog | null = null;\n let instance: Editor | null = null;\n let contextId: string | null = null;\n\n if (this.#context) {\n contextId = uid();\n\n await this.#contextWatchdog!.add({\n creator: (_element, _config) => Editor.create(_element, _config),\n id: contextId,\n sourceElementOrData: content,\n type: 'editor',\n config,\n });\n\n instance = this.#contextWatchdog!.getItem(contextId) as Editor;\n }\n else if (this.hasWatchdog()) {\n // Let's create use with plain watchdog.\n const { EditorWatchdog } = await import('ckeditor5');\n watchdog = new EditorWatchdog(Editor);\n\n await watchdog.create(content, config);\n\n instance = watchdog.editor;\n }\n else {\n // Let's create the editor without watchdog.\n instance = await Editor.create(content, config);\n }\n\n return {\n contextId,\n instance,\n watchdog,\n };\n }\n\n /**\n * Re-initializes the editor by destroying existing instance and creating new one\n *\n * @private\n * @returns {Promise<void>}\n */\n async reinitializeEditor() {\n if (this.instance) {\n this.instancePromise = Promise.withResolvers();\n\n await this.#destroy();\n\n this.instance = null;\n }\n\n this.style.display = 'block';\n\n if (!this.isMultiroot() && !this.isDecoupled()) {\n this.innerHTML = `<${this.#editorElementTag}>${this.#initialHTML}</${this.#editorElementTag}>`;\n this.#assignInputAttributes();\n }\n\n // Let's track changes in editables if it's a multiroot editor.\n if (this.isMultiroot()) {\n this.editables = new CKEditorMultiRootEditablesTracker(this, this.#queryEditables()) as unknown as Record<string, HTMLElement>;\n }\n else if (this.isDecoupled()) {\n this.editables = null;\n }\n else {\n this.editables = this.#queryEditables();\n }\n\n try {\n const { watchdog, instance, contextId } = await this.#initializeEditor(this.editables || this.#getConfig().initialData || '');\n\n this.watchdog = watchdog;\n this.instance = instance!;\n this.#contextEditorId = contextId;\n\n this.#setupContentSync();\n this.#setupEditableHeight();\n this.#setupDataChangeListener();\n\n this.instancePromise.resolve(this.instance!);\n\n // Broadcast editor ready event\n const event = new CustomEvent('editor-ready', { detail: this.instance });\n\n this.dispatchEvent(event);\n this.oneditorready?.(event);\n }\n catch (err) {\n this.instancePromise.reject(err);\n throw err;\n }\n }\n\n /**\n * Sets up data change listener that broadcasts content changes\n */\n #setupDataChangeListener() {\n const getRootContent = (rootName: string) => this.instance!.getData({ rootName });\n const getAllRoots = () =>\n this.instance?.model.document\n .getRootNames()\n .reduce((acc, rootName) => ({\n ...acc,\n [rootName]: getRootContent(rootName),\n }), {});\n\n this.instance?.model.document.on('change:data', () => {\n const event = new CustomEvent('editor-change', {\n detail: {\n editor: this.instance,\n data: getAllRoots(),\n },\n bubbles: true,\n });\n\n this.dispatchEvent(event);\n this.oneditorchange?.(event);\n });\n }\n\n /**\n * Checks if current editor is classic type\n */\n isClassic() {\n return this.getAttribute('type') === 'ClassicEditor';\n }\n\n /**\n * Checks if current editor is balloon type\n */\n isBallon() {\n return this.getAttribute('type') === 'BalloonEditor';\n }\n\n /**\n * Checks if current editor is multiroot type\n */\n isMultiroot() {\n return this.getAttribute('type') === 'MultiRootEditor';\n }\n\n /**\n * Checks if current editor is decoupled type\n */\n isDecoupled() {\n return this.getAttribute('type') === 'DecoupledEditor';\n }\n\n /**\n * Checks if current editor has watchdog enabled\n */\n hasWatchdog() {\n return this.getAttribute('watchdog') === 'true';\n }\n\n /**\n * Queries and validates editable elements\n */\n #queryEditables() {\n if (this.isDecoupled()) {\n return {};\n }\n\n if (this.isMultiroot()) {\n const editables = [...this.querySelectorAll('ckeditor-editable-component')] as CKEditorEditableComponent[];\n\n return editables.reduce((acc, element) => {\n if (!element.name) {\n throw new Error('Editable component missing required \"name\" attribute');\n }\n acc[element.name] = element;\n return acc;\n }, Object.create(null));\n }\n\n const mainEditable = this.querySelector(this.#editorElementTag);\n\n if (!mainEditable) {\n throw new Error(`No ${this.#editorElementTag} element found`);\n }\n\n return { main: mainEditable };\n }\n\n /**\n * Copies input-related attributes from component to the main editable element\n *\n * @private\n */\n #assignInputAttributes() {\n const textarea = this.querySelector('textarea');\n\n if (!textarea) {\n return;\n }\n\n for (const attr of CKEditorComponent.inputAttributes) {\n if (this.hasAttribute(attr)) {\n textarea.setAttribute(attr, this.getAttribute(attr)!);\n }\n }\n }\n\n /**\n * Sets up content sync between editor and textarea element.\n *\n * @private\n */\n #setupContentSync() {\n if (!this.instance) {\n return;\n }\n\n const textarea = this.querySelector('textarea');\n\n if (!textarea) {\n return;\n }\n\n // Initial sync\n const syncInput = () => {\n this.style.position = 'relative';\n\n textarea.innerHTML = '';\n textarea.value = this.instance!.getData();\n textarea.tabIndex = -1;\n\n Object.assign(textarea.style, {\n display: 'flex',\n position: 'absolute',\n bottom: '0',\n left: '50%',\n width: '1px',\n height: '1px',\n opacity: '0',\n pointerEvents: 'none',\n margin: '0',\n padding: '0',\n border: 'none',\n });\n };\n\n syncInput();\n\n // Listen for changes\n this.instance.model.document.on('change:data', () => {\n textarea.dispatchEvent(new Event('input', { bubbles: true }));\n textarea.dispatchEvent(new Event('change', { bubbles: true }));\n\n syncInput();\n });\n }\n\n /**\n * Sets up editable height for ClassicEditor\n *\n * @private\n */\n #setupEditableHeight() {\n if (!this.isClassic() && !this.isBallon()) {\n return;\n }\n\n const { instance } = this;\n const height = Number.parseInt(this.getAttribute('editable-height')!, 10);\n\n if (Number.isNaN(height)) {\n return;\n }\n\n instance!.editing.view.change((writer) => {\n writer.setStyle('height', `${height}px`, instance!.editing.view.document.getRoot()!);\n });\n }\n\n /**\n * Gets bundle JSON description from translations attribute\n */\n #getBundle(): BundleDescription {\n return this.#bundle ||= JSON.parse(this.getAttribute('bundle')!);\n }\n\n /**\n * Checks if all required stylesheets are injected. If not, inject.\n */\n async #ensureStylesheetsInjected() {\n await loadAsyncCSS(this.#getBundle()?.stylesheets || []);\n }\n\n /**\n * Checks if all required scripts are injected. If not, inject.\n */\n async #ensureWindowScriptsInjected() {\n const windowScripts = (this.#getBundle()?.scripts || []).filter(script => !!script.window_name);\n\n await loadAsyncImports(windowScripts);\n }\n\n /**\n * Loads translation modules\n */\n async #getTranslations() {\n const translations = this.#getBundle()?.scripts.filter(script => script.translation);\n\n return loadAsyncImports(translations);\n }\n\n /**\n * Loads plugin modules\n */\n async #getPlugins() {\n const raw = this.getAttribute('plugins');\n const items = raw ? JSON.parse(raw) : [];\n const mappedItems = items.map((item: any) =>\n typeof item === 'string'\n ? { import_name: 'ckeditor5', import_as: item }\n : item,\n );\n\n return loadAsyncImports(mappedItems);\n }\n\n /**\n * Gets editor constructor based on type attribute\n */\n async #getEditorConstructor() {\n const CKEditor = await import('ckeditor5');\n const editorType = this.getAttribute('type');\n\n if (!editorType || !Object.prototype.hasOwnProperty.call(CKEditor, editorType)) {\n throw new Error(`Invalid editor type: ${editorType}`);\n }\n\n return (CKEditor as any)[editorType] as EditorConstructor;\n }\n}\n\ntype EditorConstructor = {\n create: (...args: any[]) => Promise<Editor>;\n};\n\ntype BundleDescription = {\n stylesheets: string[];\n scripts: Array<AsyncImportRawDescription & {\n translation?: boolean;\n }>;\n};\n\ncustomElements.define('ckeditor-component', CKEditorComponent);\n","import type { CKEditorComponent } from './editor';\n\nimport { execIfDOMReady } from '../helpers';\n\nclass CKEditorUIPartComponent extends HTMLElement {\n /**\n * Lifecycle callback when element is added to DOM.\n * Adds the toolbar to the editor UI.\n */\n connectedCallback() {\n execIfDOMReady(async () => {\n const uiPart = this.getAttribute('name')!;\n const editor = await this.#queryEditorElement()!.instancePromise.promise;\n\n this.appendChild((editor.ui.view as any)[uiPart].element);\n });\n }\n\n /**\n * Finds the parent editor component.\n */\n #queryEditorElement(): CKEditorComponent | null {\n return this.closest('ckeditor-component') || document.body.querySelector('ckeditor-component');\n }\n}\n\ncustomElements.define('ckeditor-ui-part-component', CKEditorUIPartComponent);\n"],"names":["execIfDOMReady","callback","SCRIPT_LOAD_PROMISES","injectScript","url","promise","resolve","reject","script","isSafeKey","key","stylesheetExists","href","sheet","loadAsyncCSS","stylesheets","promises","link","loadAsyncImports","imports","loadExternalPlugin","import_name","import_as","window_name","isScriptPresent","module","imported","uncompressImport","pkg","resolveConfigElementReferences","obj","item","anyObj","element","result","value","uid","CKEditorContextComponent","#connectedEditors","#initializeContext","error","_","oldValue","newValue","editor","Context","ContextWatchdog","plugins","#getPlugins","config","#getConfig","args","raw","CKEditorEditableComponent","editorComponent","#queryEditorElement","name","CKEditorMultiRootEditablesTracker","#editorElement","#editables","editorElement","initialEditables","target","ui","editing","model","root","editable","CKEditorComponent","#initialHTML","#context","#contextEditorId","#bundle","#getEventHandler","handler","#setEventHandler","event","#destroy","#editorElementTag","#contextWatchdog","#initializeEditor","editablesOrContent","#ensureStylesheetsInjected","#ensureWindowScriptsInjected","content","beforeInitEventDetails","Editor","#getEditorConstructor","translations","#getTranslations","watchdog","instance","contextId","_element","_config","EditorWatchdog","#assignInputAttributes","#queryEditables","#setupContentSync","#setupEditableHeight","#setupDataChangeListener","err","getRootContent","rootName","getAllRoots","acc","mainEditable","textarea","attr","syncInput","height","writer","#getBundle","windowScripts","mappedItems","CKEditor","editorType","CKEditorUIPartComponent","uiPart"],"mappings":"AAKO,SAASA,EAAeC,GAAwB;AACrD,UAAQ,SAAS,YAAA;AAAA,IACf,KAAK;AACH,eAAS,iBAAiB,oBAAoBA,GAAU,EAAE,MAAM,IAAM;AACtE;AAAA,IAEF,KAAK;AAAA,IACL,KAAK;AACH,iBAAWA,GAAU,CAAC;AACtB;AAAA,IAEF;AACE,cAAQ,KAAK,mCAAmC,SAAS,UAAU,GACnE,WAAWA,GAAU,CAAC;AAAA,EAAA;AAE5B;ACpBA,MAAMC,wBAA2B,IAAA;AAQ1B,SAASC,EAAaC,GAAa;AACxC,MAAIF,EAAqB,IAAIE,CAAG;AAC9B,WAAOF,EAAqB,IA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AI,CAAQ;IAExC,eAAe,qEAA4C;IAI3D,MAAM,KAAK,kBAAkB,aAE5B;IAEK,iBAAiB;IAUjB,wBAAwB,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAMrF,oBAAoB;IAO1B;;;;OAIG;IACH,cAAc,CAAC,MAAM,EAAE,iBAAiB;IAIxC;;;;OAIG;IACH,gBAAgB,CAAC,MAAM,EAAE,iBAAiB;CAsE3C"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/components/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAIlD,qBAAa,wBAAyB,SAAQ,WAAW;;IACvD,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAQ;IAExC,eAAe,qEAA4C;IAI3D,MAAM,KAAK,kBAAkB,aAE5B;IAEK,iBAAiB;IAUjB,wBAAwB,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAMrF,oBAAoB;IAO1B;;;;OAIG;IACH,cAAc,CAAC,MAAM,EAAE,iBAAiB;IAIxC;;;;OAIG;IACH,gBAAgB,CAAC,MAAM,EAAE,iBAAiB;CAsE3C"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ckeditor5-rails",
3
- "version": "1.36.0",
3
+ "version": "1.36.2",
4
4
  "description": "CKEditor 5 integration for Rails Framework",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "typescript": "^5.5.4",
37
- "vite": "^7.1.11",
37
+ "vite": "^7.3.2",
38
38
  "vite-plugin-dts": "^4.5.4",
39
39
  "vite-tsconfig-paths": "^5.1.4"
40
40
  }
@@ -26,8 +26,7 @@ RSpec.describe 'AJAX Form Integration', type: :feature, js: true do
26
26
  end
27
27
 
28
28
  it 'validates required fields' do
29
- editable.click
30
- editable.send_keys([[:control, 'a'], :backspace])
29
+ clear_editor_content(editable)
31
30
  text_field.set('')
32
31
  submit_button.click
33
32
 
@@ -38,9 +37,7 @@ RSpec.describe 'AJAX Form Integration', type: :feature, js: true do
38
37
  it 'submits form and shows response' do
39
38
  test_content = "Test content #{Time.now.to_i}"
40
39
 
41
- editable.click
42
- editable.send_keys([[:control, 'a'], :backspace])
43
- editable.send_keys(test_content)
40
+ replace_editor_content(editable, test_content)
44
41
 
45
42
  sleep 1
46
43
 
@@ -20,14 +20,10 @@ RSpec.describe 'CKEditor5 Context Integration', type: :feature, js: true do
20
20
  editors = all('.ck-editor__editable', count: 2, wait: 10)
21
21
 
22
22
  # Test first editor
23
- editors[0].click
24
- editors[0].send_keys([[:control, 'a'], :backspace])
25
- editors[0].send_keys('Modified Context Item 1')
23
+ replace_editor_content(editors[0], 'Modified Context Item 1')
26
24
 
27
25
  # Test second editor
28
- editors[1].click
29
- editors[1].send_keys([[:control, 'a'], :backspace])
30
- editors[1].send_keys('Modified Context Item 2')
26
+ replace_editor_content(editors[1], 'Modified Context Item 2')
31
27
 
32
28
  # Verify content
33
29
  expect(editors[0].text).to eq('Modified Context Item 1')
@@ -29,9 +29,7 @@ RSpec.describe 'CKEditor5 Types Integration', type: :feature, js: true do
29
29
  JS
30
30
 
31
31
  # Clear editor and type text
32
- editor.click
33
- editor.send_keys([[:control, 'a'], :backspace])
34
- editor.send_keys('Hello from keyboard!')
32
+ replace_editor_content(editor, 'Hello from keyboard!')
35
33
 
36
34
  # Wait for change events and verify the last one
37
35
  eventually do
@@ -68,12 +66,8 @@ RSpec.describe 'CKEditor5 Types Integration', type: :feature, js: true do
68
66
  # Test each editable
69
67
  expected_data = {}
70
68
  editors.each_with_index do |editor, index|
71
- editor.click
72
- editor.send_keys([[:control, 'a'], :backspace])
73
-
74
69
  content = "Content for #{editables[index]}"
75
-
76
- editor.send_keys(content)
70
+ replace_editor_content(editor, content)
77
71
  expected_data[editables[index]] = "<p>#{content}</p>"
78
72
  end
79
73
 
@@ -178,9 +172,7 @@ RSpec.describe 'CKEditor5 Types Integration', type: :feature, js: true do
178
172
  expect(page).to have_css('.ck-editor__editable', minimum: 3, wait: 10)
179
173
 
180
174
  new_editable = find("[name='new-root']")
181
- new_editable.click
182
- new_editable.send_keys([[:control, 'a'], :backspace])
183
- new_editable.send_keys('Content for new root')
175
+ replace_editor_content(new_editable, 'Content for new root')
184
176
 
185
177
  eventually do
186
178
  events = page.evaluate_script('window._newEditableEvents')
@@ -21,8 +21,7 @@ RSpec.describe 'Form Integration', type: :feature, js: true do
21
21
  end
22
22
 
23
23
  it 'validates required fields' do
24
- editable.click
25
- editable.send_keys([[:control, 'a'], :backspace])
24
+ clear_editor_content(editable)
26
25
 
27
26
  text_field.set('')
28
27
  submit_button.click
@@ -40,6 +40,7 @@ end
40
40
  Capybara.server = :webrick
41
41
  Capybara.default_driver = :cuprite
42
42
  Capybara.javascript_driver = :cuprite
43
+ Capybara.default_max_wait_time = 10
43
44
 
44
45
  RSpec.configure do |config|
45
46
  config.around :each, :js do |example|
@@ -1,6 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FormHelpers
4
+ def clear_editor_content(editor)
5
+ editor.click
6
+ editor.send_keys([select_all_modifier, :backspace])
7
+ end
8
+
9
+ def replace_editor_content(editor, new_content)
10
+ clear_editor_content(editor)
11
+ editor.send_keys(new_content)
12
+ end
13
+
14
+ def select_all_modifier
15
+ case RbConfig::CONFIG['host_os']
16
+ when /darwin/i
17
+ [:command, 'a']
18
+ else
19
+ [:control, 'a']
20
+ end
21
+ end
22
+
4
23
  def setup_form_tracking(driver)
5
24
  driver.execute_script <<~JS
6
25
  window.lastSubmittedForm = null;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ckeditor5
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.36.1
4
+ version: 1.36.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Bagiński
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2026-04-01 00:00:00.000000000 Z
12
+ date: 2026-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails