ckeditor5 1.36.6 → 1.37.0
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 +4 -4
- data/README.md +89 -5
- data/lib/ckeditor5/rails/editor/helpers/editor_helpers.rb +33 -5
- data/lib/ckeditor5/rails/version.rb +1 -1
- data/npm_package/dist/index.cjs +1 -1
- data/npm_package/dist/index.cjs.map +1 -1
- data/npm_package/dist/index.mjs +268 -223
- data/npm_package/dist/index.mjs.map +1 -1
- data/npm_package/dist/src/components/editable.d.ts +8 -12
- data/npm_package/dist/src/components/editable.d.ts.map +1 -1
- data/npm_package/dist/src/components/editor/editor.d.ts.map +1 -1
- data/npm_package/dist/src/components/editor/multiroot-editables-tracker.d.ts.map +1 -1
- data/npm_package/package.json +3 -3
- data/spec/e2e/features/editor_types_spec.rb +7 -4
- data/spec/lib/ckeditor5/rails/editor/helpers/editor_helpers_spec.rb +8 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 130f19380b0a4789ded272e7bf2d462e1126b92bbf942ec8503c365b615418a2
|
|
4
|
+
data.tar.gz: c8e79a7ed7e4a113fd54f36a56c2722b8d8bd728aa7806a01defcfa5c157fd16
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 718530350f986982755579ed950dba6aa8fb9af44ed6ae2bb045e63034e9f14798ffddb9ee20f4c30ecf4cf370259b7815312addf056b7b2963dccf7691ead8e
|
|
7
|
+
data.tar.gz: 6032f74aeb05dc4c12e56f06ccc1e6073729aea54893443c129c4176170b8a49ee8e2a7e632e8aab22e1e9f963dc1bd6b405fbfb6f3b3c43634dfd2f1f932aa2
|
data/README.md
CHANGED
|
@@ -11,10 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
CKEditor 5 Ruby on Rails integration gem. Provides seamless integration of CKEditor 5 with Rails applications through web components and helper methods. This gem supports various editor types, including classic, inline, balloon, and decoupled editors. It also includes support for custom plugins, translations, and configuration options.
|
|
13
13
|
|
|
14
|
-
**Requirements:**
|
|
15
|
-
* Ruby >= 2.5
|
|
16
|
-
* Rails >= 5.0
|
|
17
|
-
|
|
18
14
|
> [!IMPORTANT]
|
|
19
15
|
> This gem is unofficial and not maintained by CKSource. For official CKEditor 5 documentation, visit [ckeditor.com](https://ckeditor.com/docs/ckeditor5/latest/). If you encounter any issues in editor, please report them on the [GitHub repository](https://github.com/ckeditor/ckeditor5/issues).
|
|
20
16
|
|
|
@@ -22,6 +18,13 @@ CKEditor 5 Ruby on Rails integration gem. Provides seamless integration of CKEdi
|
|
|
22
18
|
<img src="docs/intro-classic-editor.png" alt="CKEditor 5 Classic Editor in Ruby on Rails application">
|
|
23
19
|
</p>
|
|
24
20
|
|
|
21
|
+
## Compatibility 🔗
|
|
22
|
+
|
|
23
|
+
| CKEditor 5 Version | Integration Version | Ruby Version | Rails Version |
|
|
24
|
+
|--------------------|---------------------|--------------|---------------|
|
|
25
|
+
| 43.x – 47.x | `<= 1.36.x` | `>= 2.5` | `>= 5.0` |
|
|
26
|
+
| >= 48.0 | `>= 1.37.x` | `>= 2.5` | `>= 5.0` |
|
|
27
|
+
|
|
25
28
|
## Installation 🛠️
|
|
26
29
|
|
|
27
30
|
Add this line to your application's Gemfile:
|
|
@@ -147,7 +150,7 @@ bundle install
|
|
|
147
150
|
|
|
148
151
|
# Start the server
|
|
149
152
|
npm run npm_package:watch
|
|
150
|
-
bundle exec guard -g rails
|
|
153
|
+
bundle exec guard -g rails
|
|
151
154
|
```
|
|
152
155
|
|
|
153
156
|
Open [http://localhost:3000/](http://localhost:3000/) in a browser to start experimenting. Modify the code as needed.
|
|
@@ -157,6 +160,7 @@ For extending CKEditor's functionality, refer to the [plugins directory](https:/
|
|
|
157
160
|
## Table of Contents 📚
|
|
158
161
|
|
|
159
162
|
- [CKEditor 5 Rails Integration ✨](#ckeditor-5-rails-integration-)
|
|
163
|
+
- [Compatibility 🔗](#compatibility-)
|
|
160
164
|
- [Installation 🛠️](#installation-️)
|
|
161
165
|
- [If you are not using importmap (custom bundler) 📦](#if-you-are-not-using-importmap-custom-bundler-)
|
|
162
166
|
- [Try Demos! 🎮 ✨](#try-demos--)
|
|
@@ -206,9 +210,12 @@ For extending CKEditor's functionality, refer to the [plugins directory](https:/
|
|
|
206
210
|
- [Commercial usage 💰](#commercial-usage-)
|
|
207
211
|
- [Editor placement 🏗️](#editor-placement-️)
|
|
208
212
|
- [Setting Initial Content 📝](#setting-initial-content-)
|
|
213
|
+
- [Single-line editable areas (`$inlineRoot`) 📏](#single-line-editable-areas-inlineroot-)
|
|
209
214
|
- [Watchdog 🐕](#watchdog-)
|
|
210
215
|
- [Classic editor 📝](#classic-editor-)
|
|
211
216
|
- [Multiroot editor 🌳](#multiroot-editor-)
|
|
217
|
+
- [Inline roots (single-line editable areas)](#inline-roots-single-line-editable-areas)
|
|
218
|
+
- [Setting initial content of a root](#setting-initial-content-of-a-root)
|
|
212
219
|
- [Inline editor 📝](#inline-editor-)
|
|
213
220
|
- [Balloon editor 🎈](#balloon-editor-)
|
|
214
221
|
- [Decoupled editor 🌐](#decoupled-editor-)
|
|
@@ -1659,6 +1666,25 @@ In this scenario, the assets are included from the official CKEditor 5 CDN which
|
|
|
1659
1666
|
|
|
1660
1667
|
The `ckeditor5_editor` helper renders CKEditor 5 instances in your views. Before using it, ensure you've included the necessary assets in your page's head section otherwise the editor won't work as there are no CKEditor 5 JavaScript and CSS files loaded.
|
|
1661
1668
|
|
|
1669
|
+
```ruby
|
|
1670
|
+
ckeditor5_editor(
|
|
1671
|
+
preset: nil, # Symbol, PresetBuilder - preset to use (default: context preset or :default)
|
|
1672
|
+
config: nil, # Hash - custom config; replaces the preset's config (use extra_config to merge instead)
|
|
1673
|
+
extra_config: {}, # Hash - additional config, deep-merged on top of the preset/custom config
|
|
1674
|
+
type: nil, # Symbol - :classic, :inline, :balloon, :decoupled, :multiroot (default: preset's type)
|
|
1675
|
+
initial_data: nil, # String - initial HTML content for the editor (mutually exclusive with a block)
|
|
1676
|
+
watchdog: true, # Boolean - enables/disables the CKEditor 5 crash-recovery watchdog
|
|
1677
|
+
editable_height: nil, # Integer, String - fixed height of the editing area, e.g. 300 or '300px' (:classic/:balloon only)
|
|
1678
|
+
language: nil, # Symbol - UI language override for this editor instance
|
|
1679
|
+
inline: false, # Boolean - use the $inlineRoot model element instead of $root for the (single) root
|
|
1680
|
+
# (not applicable to :multiroot - use `inline` on ckeditor5_editable per root instead)
|
|
1681
|
+
**html_attributes # any other keyword becomes an HTML attribute: style:, class:, id:, data-*,
|
|
1682
|
+
# form attributes (name:, required:, value:), event handlers (oneditorready:, oneditorchange:, oneditorerror:), ...
|
|
1683
|
+
)
|
|
1684
|
+
# &block - nested content: initial data for single-root editors, or ckeditor5_toolbar / ckeditor5_menubar / ckeditor5_editable
|
|
1685
|
+
# for multiroot/decoupled editors. Mutually exclusive with `initial_data`.
|
|
1686
|
+
```
|
|
1687
|
+
|
|
1662
1688
|
### Setting Initial Content 📝
|
|
1663
1689
|
|
|
1664
1690
|
You can set the initial content of the editor using the `initial_data` keyword argument or by passing the content directly to the `ckeditor5_editor` helper block.
|
|
@@ -1681,6 +1707,18 @@ The example below shows how to set the initial content of the editor using the `
|
|
|
1681
1707
|
<% end %>
|
|
1682
1708
|
```
|
|
1683
1709
|
|
|
1710
|
+
### Single-line editable areas (`$inlineRoot`) 📏
|
|
1711
|
+
|
|
1712
|
+
If you want the (single) root to behave as a single-line editable area — e.g. a title field — instead of a regular multi-block `$root`, pass the `inline` keyword argument:
|
|
1713
|
+
|
|
1714
|
+
```erb
|
|
1715
|
+
<!-- app/views/demos/index.html.erb -->
|
|
1716
|
+
|
|
1717
|
+
<%= ckeditor5_editor inline: true, initial_data: 'Document title', style: 'width: 600px' %>
|
|
1718
|
+
```
|
|
1719
|
+
|
|
1720
|
+
This works for `:classic`, `:inline`, `:balloon` and `:decoupled` editors. For `:multiroot` editors, set `inline: true` per root using `ckeditor5_editable` instead — see [Inline roots](#inline-roots-single-line-editable-areas).
|
|
1721
|
+
|
|
1684
1722
|
### Watchdog 🐕
|
|
1685
1723
|
|
|
1686
1724
|
CKEditor 5 uses a watchdog utility to protect you from data loss in case the editor crashes. It saves your content just before the crash and creates a new instance of the editor with your content intact. It's enabled by default in the gem.
|
|
@@ -1797,6 +1835,52 @@ If you want to use a multiroot editor, you can pass the `type` keyword argument
|
|
|
1797
1835
|
|
|
1798
1836
|
Roots can be defined later to the editor by simply adding new elements rendered by `ckeditor5_editable` helper.
|
|
1799
1837
|
|
|
1838
|
+
```ruby
|
|
1839
|
+
ckeditor5_editable(
|
|
1840
|
+
name = nil, # String - root identifier, matched against the editor's roots (required for multiroot editors)
|
|
1841
|
+
inline: false, # Boolean - use the $inlineRoot model element instead of $root (single-line areas, e.g. titles)
|
|
1842
|
+
initial_data: nil, # String - initial HTML content via the `initial-data` attribute (mutually exclusive with a block)
|
|
1843
|
+
**kwargs # any other keyword becomes an HTML attribute: style:, class:, id:, ...
|
|
1844
|
+
)
|
|
1845
|
+
# &block - initial HTML content for this root, provided as nested markup. Mutually exclusive with `initial_data`.
|
|
1846
|
+
```
|
|
1847
|
+
|
|
1848
|
+
#### Inline roots (single-line editable areas)
|
|
1849
|
+
|
|
1850
|
+
Multiroot editors can expose *inline* roots — single-line editable areas (e.g. a title) that use the `$inlineRoot` model element instead of the default `$root`. Enable it by passing `inline: true` to `ckeditor5_editable`:
|
|
1851
|
+
|
|
1852
|
+
```erb
|
|
1853
|
+
<!-- app/views/demos/index.html.erb -->
|
|
1854
|
+
|
|
1855
|
+
<%= ckeditor5_editor type: :multiroot, style: 'width: 600px' do %>
|
|
1856
|
+
<%= ckeditor5_toolbar %>
|
|
1857
|
+
<br>
|
|
1858
|
+
<%= ckeditor5_editable 'title', inline: true, style: 'border: 1px solid var(--ck-color-base-border);' %>
|
|
1859
|
+
<br>
|
|
1860
|
+
<%= ckeditor5_editable 'content', style: 'border: 1px solid var(--ck-color-base-border)' %>
|
|
1861
|
+
<% end %>
|
|
1862
|
+
```
|
|
1863
|
+
|
|
1864
|
+
#### Setting initial content of a root
|
|
1865
|
+
|
|
1866
|
+
You can set the initial content of a specific root using the `initial_data` keyword argument, instead of passing it as the tag's content:
|
|
1867
|
+
|
|
1868
|
+
```erb
|
|
1869
|
+
<!-- app/views/demos/index.html.erb -->
|
|
1870
|
+
|
|
1871
|
+
<%= ckeditor5_editable 'content', initial_data: '<p>Hello</p>' %>
|
|
1872
|
+
```
|
|
1873
|
+
|
|
1874
|
+
This is equivalent to (and mutually exclusive with) passing the content as a block:
|
|
1875
|
+
|
|
1876
|
+
```erb
|
|
1877
|
+
<!-- app/views/demos/index.html.erb -->
|
|
1878
|
+
|
|
1879
|
+
<%= ckeditor5_editable 'content' do %>
|
|
1880
|
+
<p>Hello</p>
|
|
1881
|
+
<% end %>
|
|
1882
|
+
```
|
|
1883
|
+
|
|
1800
1884
|
### Inline editor 📝
|
|
1801
1885
|
|
|
1802
1886
|
Inline editor allows you to create an editor that can be placed inside any element. Keep in mind that inline editor does not work with `textarea` elements so it might be not suitable for all use cases.
|
|
@@ -19,6 +19,9 @@ module CKEditor5::Rails
|
|
|
19
19
|
# @param watchdog [Boolean] Enable/disable the editor crash recovery (default: true)
|
|
20
20
|
# @param editable_height [Integer] Set fixed height for editor in pixels
|
|
21
21
|
# @param language [Symbol] Set editor UI language (e.g. :pl, :es)
|
|
22
|
+
# @param inline [Boolean] Whether the (single) root should use the `$inlineRoot` model
|
|
23
|
+
# element instead of the default `$root`. Not applicable to `:multiroot` editors —
|
|
24
|
+
# use the `inline` argument of `ckeditor5_editable` per root instead.
|
|
22
25
|
# @param html_attributes [Hash] Additional HTML attributes for editor element
|
|
23
26
|
#
|
|
24
27
|
# @example Basic usage with default preset
|
|
@@ -30,6 +33,9 @@ module CKEditor5::Rails
|
|
|
30
33
|
# @example Inline editor with custom styling
|
|
31
34
|
# <%= ckeditor5_editor type: :inline, style: 'width: 600px' %>
|
|
32
35
|
#
|
|
36
|
+
# @example Classic editor with a single-line ($inlineRoot) editing area
|
|
37
|
+
# <%= ckeditor5_editor inline: true, style: 'width: 600px' %>
|
|
38
|
+
#
|
|
33
39
|
# @example Multiroot editor with multiple editable areas
|
|
34
40
|
# <%= ckeditor5_editor type: :multiroot do %>
|
|
35
41
|
# <%= ckeditor5_toolbar %>
|
|
@@ -60,7 +66,7 @@ module CKEditor5::Rails
|
|
|
60
66
|
preset: nil,
|
|
61
67
|
config: nil, extra_config: {}, type: nil,
|
|
62
68
|
initial_data: nil, watchdog: true,
|
|
63
|
-
editable_height: nil, language: nil,
|
|
69
|
+
editable_height: nil, language: nil, inline: false,
|
|
64
70
|
**html_attributes, &block
|
|
65
71
|
)
|
|
66
72
|
validate_editor_input!(initial_data, block)
|
|
@@ -68,7 +74,7 @@ module CKEditor5::Rails
|
|
|
68
74
|
context = ckeditor5_context_or_fallback(preset)
|
|
69
75
|
|
|
70
76
|
preset = Engine.find_preset!(preset || context[:preset] || :default)
|
|
71
|
-
config = build_editor_config(preset, config, extra_config, initial_data)
|
|
77
|
+
config = build_editor_config(preset, config, extra_config, initial_data, inline: inline)
|
|
72
78
|
|
|
73
79
|
type ||= preset.type
|
|
74
80
|
|
|
@@ -91,15 +97,30 @@ module CKEditor5::Rails
|
|
|
91
97
|
# Creates an editable area for multiroot or decoupled editors.
|
|
92
98
|
#
|
|
93
99
|
# @param name [String] Identifier for the editable area
|
|
100
|
+
# @param inline [Boolean] Whether the root should use the `$inlineRoot` model element
|
|
101
|
+
# instead of the default `$root`. Useful for single-line editable areas (e.g. titles).
|
|
102
|
+
# @param initial_data [String] Initial HTML content for this editable area, passed via
|
|
103
|
+
# the `initial-data` attribute instead of the element's content. Cannot be used
|
|
104
|
+
# together with a block.
|
|
94
105
|
# @param kwargs [Hash] HTML attributes for the editable element
|
|
95
106
|
#
|
|
96
107
|
# @example Creating a named editable area in multiroot editor
|
|
97
108
|
# <%= ckeditor5_editable 'content', style: 'border: 1px solid gray' %>
|
|
98
|
-
|
|
109
|
+
#
|
|
110
|
+
# @example Creating an inline editable area (e.g. a title) in multiroot editor
|
|
111
|
+
# <%= ckeditor5_editable 'title', inline: true %>
|
|
112
|
+
#
|
|
113
|
+
# @example Setting initial content using the initial_data argument
|
|
114
|
+
# <%= ckeditor5_editable 'content', initial_data: '<p>Hello</p>' %>
|
|
115
|
+
def ckeditor5_editable(name = nil, inline: false, initial_data: nil, **kwargs, &block)
|
|
116
|
+
raise ArgumentError, 'Cannot pass initial data and block at the same time.' if initial_data && block
|
|
117
|
+
|
|
99
118
|
tag.public_send(
|
|
100
119
|
:'ckeditor-editable-component',
|
|
101
120
|
'data-turbo-temporary': true,
|
|
102
121
|
name: name,
|
|
122
|
+
inline: inline,
|
|
123
|
+
'initial-data': initial_data,
|
|
103
124
|
**kwargs, &block
|
|
104
125
|
)
|
|
105
126
|
end
|
|
@@ -159,11 +180,18 @@ module CKEditor5::Rails
|
|
|
159
180
|
# @param config [Hash] Custom configuration that overrides preset config
|
|
160
181
|
# @param extra_config [Hash] Additional configuration to merge
|
|
161
182
|
# @param initial_data [String] Initial content for the editor
|
|
183
|
+
# @param inline [Boolean] Whether the root should use the `$inlineRoot` model element
|
|
162
184
|
# @return [Hash] The merged configuration hash
|
|
163
|
-
def build_editor_config(preset, config, extra_config, initial_data)
|
|
185
|
+
def build_editor_config(preset, config, extra_config, initial_data, inline: false)
|
|
164
186
|
editor_config = config || preset.config
|
|
165
187
|
editor_config = editor_config.deep_merge(extra_config)
|
|
166
|
-
|
|
188
|
+
|
|
189
|
+
if initial_data || inline
|
|
190
|
+
editor_config[:root] = (editor_config[:root] || {}).merge(
|
|
191
|
+
**(initial_data ? { initialData: initial_data } : {}),
|
|
192
|
+
**(inline ? { modelElement: '$inlineRoot' } : {})
|
|
193
|
+
)
|
|
194
|
+
end
|
|
167
195
|
|
|
168
196
|
if preset.automatic_upgrades? && editor_config[:version].present?
|
|
169
197
|
detected_version = VersionDetector.latest_safe_version(editor_config[:version])
|
data/npm_package/dist/index.cjs
CHANGED
|
@@ -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(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(null);#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 R=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of P(t))!S.call(e,s)&&s!==i&&w(e,s,{get:()=>t[s],enumerable:!(n=A(t,s))||n.enumerable});return e};var E=(e,t,i)=>(i=e!=null?C(x(e)):{},R(t||!e||!e.__esModule?w(i,"default",{value:e,enumerable:!0}):i,e));function f(e){switch(document.readyState){case"loading":document.addEventListener("DOMContentLoaded",e,{once:!0});break;case"interactive":case"complete":setTimeout(e,0);break;default:console.warn("Unexpected document.readyState:",document.readyState),setTimeout(e,0)}}const b=new Map;function M(e){if(b.has(e))return b.get(e);const t=new Promise((i,n)=>{const s=document.createElement("script");s.src=e,s.onload=i,s.onerror=n,document.head.appendChild(s)});return b.set(e,t),t}function k(e){return typeof e=="string"&&e!=="__proto__"&&e!=="constructor"&&e!=="prototype"}function D(e){return Array.from(document.styleSheets).some(t=>t.href===e||t.href===new URL(e,window.location.href).href)}function y(e=[]){const t=e.map(i=>new Promise((n,s)=>{if(D(i)){n();return}const r=document.createElement("link");r.rel="stylesheet",r.href=i,r.onerror=s,r.onload=()=>n(),document.head.appendChild(r)}));return Promise.all(t)}function h(e=[]){const t=async({url:n,import_name:s,import_as:r,window_name:c,stylesheets:d})=>{if(d?.length&&await y(d),c){let a=function(){return Object.prototype.hasOwnProperty.call(window,c)};if(n&&!a()&&await M(n),a()||window.dispatchEvent(new CustomEvent(`ckeditor:request-cjs-plugin:${c}`)),!a())throw new Error(`Plugin window['${c}'] not found in global scope. Please ensure the plugin is loaded before CKEditor initialization.`);return window[c]}const o=await import(s),l=o[r||"default"];if(!l)throw new Error(`Plugin "${r||"default"}" not found in the ESM module "${s}"! Available imports: ${Object.keys(o).join(", ")}! Consider changing "import_as" value.`);return l};function i(n){return t(typeof n=="string"?{import_name:"ckeditor5",import_as:n}:n)}return Promise.all(e.map(i))}function m(e){if(!e||typeof e!="object")return e;if(Array.isArray(e))return e.map(n=>m(n));const t=e;if(t.$element&&typeof t.$element=="string"){const n=document.querySelector(t.$element);return n||console.warn(`Element not found for selector: ${t.$element}`),n||null}const i=Object.create(null);for(const[n,s]of Object.entries(e))i[n]=m(s);return i}function $(){return Math.random().toString(36).substring(2)}class H extends HTMLElement{instance=null;instancePromise=Promise.withResolvers();#e=new Set;static get observedAttributes(){return["plugins","config"]}async connectedCallback(){try{f(()=>this.#t())}catch(t){console.error("Failed to initialize context:",t),this.dispatchEvent(new CustomEvent("context-error",{detail:t}))}}async attributeChangedCallback(t,i,n){i!==null&&i!==n&&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:i}=await import("ckeditor5"),n=await this.#i(),s=this.#s();window.dispatchEvent(new CustomEvent("ckeditor:context:attach",{detail:{config:s,element:this}})),this.instance=new i(t,{crashNumberLimit:10}),await this.instance.create({...s,plugins:n}),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 m(t)}}customElements.define("ckeditor-context-component",H);class T extends HTMLElement{get name(){return this.getAttribute("name")||"editable"}get editableElement(){return this.querySelector("div")}get modelElement(){return this.getAttribute("inline")==="true"?"$inlineRoot":void 0}get initialData(){return this.hasAttribute("initial-data")?this.getAttribute("initial-data"):void 0}connectedCallback(){f(()=>{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(i=>{this.appendChild(i.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}})}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",T);class v{#e;#t;constructor(t,i={}){return this.#e=t,this.#t=i,new Proxy(this,{get(n,s){return typeof n[s]=="function"?n[s].bind(n):n.#t[s]},set(n,s,r){return n.#t[s]!==r&&(n.attachRoot(s,r),n.#t[s]=r),!0},deleteProperty(n,s){return n.detachRoot(s),delete n.#t[s],!0}})}async attachRoot(t,i){return await this.detachRoot(t),this.#e.runAfterEditorReady(n=>{const{ui:s,editing:r,model:c}=n,d=i.modelElement,o=i.initialData;n.addRoot(t,{isUndoable:!1,initialData:o??i.innerHTML,...d&&{modelElement:d}});const l=c.document.getRoot(t);s.getEditableElement(t)&&n.detachEditable(l);const a=s.view.createEditable(t,i);s.addEditable(a),r.view.forceRender()})}async detachRoot(t){return this.#e.runAfterEditorReady(i=>{const n=i.model.document.getRoot(t);n&&(i.detachEditable(n),i.detachRoot(t,!0))})}getAll(){return this.#t}}class p extends HTMLElement{instancePromise=Promise.withResolvers();watchdog=null;instance=null;editables=Object.create(null);#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){return this.hasAttribute(`on${t}`)?G(this.getAttribute(`on${t}`)):this[`#${t}Handler`]}#o(t,i){typeof i=="string"?this.setAttribute(`on${t}`,i):(this.removeAttribute(`on${t}`),this[`#${t}Handler`]=i)}connectedCallback(){this.#t=this.closest("ckeditor-context-component"),this.#e=this.innerHTML;try{f(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 i=new CustomEvent("editor-error",{detail:t});this.dispatchEvent(i),this.oneditorerror?.(i)}}async attributeChangedCallback(t,i,n){i!==null&&i!==n&&p.observedAttributes.includes(t)&&this.isConnected&&await this.reinitializeEditor()}async disconnectedCallback(){this.#t&&this.#t.unregisterEditor(this);try{await this.#l()}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 L(this.getAttribute("type"))}get#a(){return this.#t?.instance}async#l(){this.#i&&await this.#a.remove(this.#i),await this.instance?.destroy(),this.watchdog?.destroy()}#d(){return I(this.getAttribute("config"))}async#h(t){await Promise.all([this.#E(),this.#b()]);const{isMultiroot:i,content:n}=O(t),s=q(n,i);window.dispatchEvent(new CustomEvent("ckeditor:attach:before",{detail:s}));const r=await this.#v(),[c,d]=await Promise.all([this.#y(),this.#w()]),o={...this.#d(),...d.length&&{translations:d},plugins:c};j(o,n,i,this.isClassic()),window.dispatchEvent(new CustomEvent("ckeditor:attach",{detail:{config:o,...s}}));let l=null,a=null,u=null;if(this.#t)u=$(),await this.#a.add({creator:g=>r.create(g),id:u,type:"editor",config:o}),a=this.#a.getItem(u);else if(this.hasWatchdog()){const{EditorWatchdog:g}=await import("ckeditor5");l=new g(r),await l.create(o),a=l.editor}else a=await r.create(o);return{contextId:u,instance:a,watchdog:l}}async reinitializeEditor(){this.instance&&(this.instancePromise=Promise.withResolvers(),await this.#l(),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 v(this,this.#u()):this.isDecoupled()?this.editables=null:this.editables=this.#u();try{const{watchdog:t,instance:i,contextId:n}=await this.#h(this.editables||this.#d().root?.initialData||"");this.watchdog=t,this.instance=i,this.#i=n,this.#f(),this.#g(),this.#m(),this.instancePromise.resolve(this.instance);const s=new CustomEvent("editor-ready",{detail:this.instance});this.dispatchEvent(s),this.oneditorready?.(s)}catch(t){throw this.instancePromise.reject(t),t}}#m(){const t=n=>this.instance.getData({rootName:n}),i=()=>this.instance?.model.document.getRootNames().reduce((n,s)=>({...n,[s]:t(s)}),{});this.instance?.model.document.on("change:data",()=>{const n=new CustomEvent("editor-change",{detail:{editor:this.instance,data:i()},bubbles:!0});this.dispatchEvent(n),this.oneditorchange?.(n)})}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"}#u(){if(this.isDecoupled())return{};if(this.isMultiroot()){const i=[...this.querySelectorAll("ckeditor-editable-component")];return z(i)}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");t&&B(this,t,p.inputAttributes)}#f(){if(!this.instance)return;const t=this.querySelector("textarea");if(!t)return;const i=()=>{this.style.position="relative",t.innerHTML="",t.value=this.instance.getData(),K(t)};i(),this.instance.model.document.on("change:data",()=>{t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),i()})}#g(){if(!this.isClassic()&&!this.isBallon())return;const t=W(this.getAttribute("editable-height"));t!==null&&J(this.instance,t)}#c(){return this.#s||=U(this.getAttribute("bundle"))}async#E(){await y(this.#c()?.stylesheets||[])}async#b(){const t=(this.#c()?.scripts||[]).filter(i=>!!i.window_name);await h(t)}async#w(){const t=this.#c()?.scripts.filter(i=>i.translation);return h(t)}async#y(){return h(_(this.getAttribute("plugins")))}async#v(){const t=await import("ckeditor5");return F(t,this.getAttribute("type"))}}function L(e){return e==="ClassicEditor"?"textarea":"div"}function I(e){const t=JSON.parse(e||"{}");return m(t)}function O(e){const t=e instanceof v;let i=e;return t?i=e.getAll():typeof e!="string"&&(i=e.main),{isMultiroot:t,content:i}}function q(e,t){return{...e instanceof HTMLElement&&{element:e},...typeof e=="string"&&{data:e},...t&&{editables:e}}}function j(e,t,i,n){i?e.roots=N(t):n&&t instanceof HTMLElement?e.attachTo=t:t instanceof HTMLElement?e.root={...e.root,element:t}:typeof t=="string"&&(e.root={...e.root,initialData:t})}function N(e){return Object.fromEntries(Object.entries(e).map(([t,i])=>{const n=i.modelElement,s=i.initialData;return[t,{element:i,initialData:s??i.innerHTML,...n&&{modelElement:n}}]}))}function z(e){return e.reduce((t,i)=>{if(!i.name)throw new Error('Editable component missing required "name" attribute');return t[i.name]=i,t},Object.create(null))}function B(e,t,i){for(const n of i)e.hasAttribute(n)&&t.setAttribute(n,e.getAttribute(n))}function K(e){e.tabIndex=-1,Object.assign(e.style,{display:"flex",position:"absolute",bottom:"0",left:"50%",width:"1px",height:"1px",opacity:"0",pointerEvents:"none",margin:"0",padding:"0",border:"none"})}function W(e){if(e===null)return null;const t=Number.parseInt(e,10);return Number.isNaN(t)?null:t}function J(e,t){e.editing.view.change(i=>{i.setStyle("height",`${t}px`,e.editing.view.document.getRoot())})}function U(e){return JSON.parse(e)}function _(e){return(e?JSON.parse(e):[]).map(i=>typeof i=="string"?{import_name:"ckeditor5",import_as:i}:i)}function F(e,t){if(!t||!Object.prototype.hasOwnProperty.call(e,t))throw new Error(`Invalid editor type: ${t}`);return e[t]}function G(e){if(!k(e))throw new Error(`Unsafe event handler attribute value: ${e}`);return window[e]||new Function("event",e)}customElements.define("ckeditor-component",p);class Q extends HTMLElement{connectedCallback(){f(async()=>{const t=this.getAttribute("name"),i=await this.#e().instancePromise.promise;this.appendChild(i.ui.view[t].element)})}#e(){return this.closest("ckeditor-component")||document.body.querySelector("ckeditor-component")}}customElements.define("ckeditor-ui-part-component",Q);
|
|
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 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(null);\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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AM,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 * 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 * Root model element.\n */\n get modelElement() {\n return this.getAttribute('inline') === 'true' ? '$inlineRoot' : undefined;\n }\n\n /**\n * Initial editable data.\n */\n get initialData() {\n return this.hasAttribute('initial-data') ? this.getAttribute('initial-data')! : undefined;\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 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 const modelElement = (element as any).modelElement as string | undefined;\n const initialData = (element as any).initialData as string | undefined;\n\n editor.addRoot(name, {\n isUndoable: false,\n initialData: initialData ?? element.innerHTML,\n ...modelElement && { modelElement },\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(null);\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 return resolveInlineEventHandler(this.getAttribute(`on${name}`)!);\n }\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 return getEditorElementTag(this.getAttribute('type'));\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 return parseEditorConfig(this.getAttribute('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 const { isMultiroot, content } = resolveEditorContent(editablesOrContent);\n const beforeInitEventDetails = buildBeforeInitEventDetails(content, isMultiroot);\n\n window.dispatchEvent(\n new CustomEvent('ckeditor:attach:before', { detail: beforeInitEventDetails }),\n );\n\n const Editor = await this.#getEditorConstructor();\n const [plugins, translations] = await Promise.all([\n this.#getPlugins(),\n this.#getTranslations(),\n ]);\n\n const config: Record<string, any> = {\n ...this.#getConfig(),\n ...translations.length && {\n translations,\n },\n plugins,\n };\n\n applyContentToConfig(config, content, isMultiroot, this.isClassic());\n\n window.dispatchEvent(\n new CustomEvent('ckeditor:attach', { detail: { config, ...beforeInitEventDetails } }),\n );\n\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: (_config: any) => Editor.create(_config),\n id: contextId,\n type: 'editor',\n config,\n });\n\n instance = this.#contextWatchdog!.getItem(contextId) as Editor;\n }\n else if (this.hasWatchdog()) {\n const { EditorWatchdog } = await import('ckeditor5');\n watchdog = new EditorWatchdog(Editor);\n\n await watchdog.create(config);\n\n instance = watchdog.editor;\n }\n else {\n instance = await Editor.create(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().root?.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 buildEditablesMap(editables);\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 copyAttributes(this, textarea, CKEditorComponent.inputAttributes);\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\n hideTextareaVisually(textarea);\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 height = parseEditableHeight(this.getAttribute('editable-height'));\n\n if (height === null) {\n return;\n }\n\n applyEditableHeight(this.instance!, height);\n }\n\n /**\n * Gets bundle JSON description from translations attribute\n */\n #getBundle(): BundleDescription {\n return (this.#bundle ||= parseBundleDescription(this.getAttribute('bundle'))) as BundleDescription;\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 return loadAsyncImports(parsePluginDescriptors(this.getAttribute('plugins')));\n }\n\n /**\n * Gets editor constructor based on type attribute\n */\n async #getEditorConstructor() {\n const CKEditor = await import('ckeditor5');\n\n return resolveEditorConstructor(CKEditor, this.getAttribute('type'));\n }\n}\n\n/**\n * Resolves the DOM tag used for the main editable element based on the editor type.\n */\nfunction getEditorElementTag(type: string | null): 'textarea' | 'div' {\n switch (type) {\n case 'ClassicEditor':\n return 'textarea';\n\n default:\n return 'div';\n }\n}\n\n/**\n * Parses the `config` attribute JSON and resolves any `$element` references within it.\n */\nfunction parseEditorConfig(raw: string | null) {\n const config = JSON.parse(raw || '{}');\n\n return resolveConfigElementReferences(config);\n}\n\n/**\n * Resolves the `editablesOrContent` argument passed to `#initializeEditor` into a\n * normalized `{ isMultiroot, content }` shape.\n */\nfunction resolveEditorContent(\n editablesOrContent: Record<string, HTMLElement | string> | CKEditorMultiRootEditablesTracker | string | HTMLElement,\n) {\n const isMultiroot = editablesOrContent instanceof CKEditorMultiRootEditablesTracker;\n\n let content: any = editablesOrContent;\n\n if (isMultiroot) {\n content = (editablesOrContent as CKEditorMultiRootEditablesTracker).getAll();\n }\n else if (typeof editablesOrContent !== 'string') {\n content = (editablesOrContent as any)['main'];\n }\n\n return { isMultiroot, content };\n}\n\n/**\n * Builds the payload broadcasted with the `ckeditor:attach:before` / `ckeditor:attach` events.\n */\nfunction buildBeforeInitEventDetails(content: any, isMultiroot: boolean) {\n return {\n ...content instanceof HTMLElement && { element: content },\n ...typeof content === 'string' && { data: content },\n ...isMultiroot && { editables: content },\n };\n}\n\n/**\n * Applies the resolved editor content to the editor configuration, using the\n * non-deprecated `attachTo` / `root` / `roots` options instead of the legacy\n * `Editor.create( sourceElementOrData, config )` signature.\n */\nfunction applyContentToConfig(\n config: Record<string, any>,\n content: any,\n isMultiroot: boolean,\n isClassic: boolean,\n) {\n if (isMultiroot) {\n config['roots'] = buildRootsConfig(content as Record<string, CKEditorEditableComponent>);\n }\n else if (isClassic && content instanceof HTMLElement) {\n config['attachTo'] = content;\n }\n else if (content instanceof HTMLElement) {\n config['root'] = { ...config['root'], element: content };\n }\n else if (typeof content === 'string') {\n config['root'] = { ...config['root'], initialData: content };\n }\n}\n\n/**\n * Builds the `roots` configuration object used to initialize a `MultiRootEditor`.\n */\nfunction buildRootsConfig(editables: Record<string, CKEditorEditableComponent>) {\n return Object.fromEntries(\n Object.entries(editables).map(([name, element]) => {\n const modelElement = (element as any).modelElement as string | undefined;\n const initialData = (element as any).initialData as string | undefined;\n\n return [\n name,\n {\n element,\n initialData: initialData ?? element.innerHTML,\n ...modelElement && { modelElement },\n },\n ];\n }),\n );\n}\n\n/**\n * Builds a `{ [name]: element }` map out of a list of editable components, validating\n * that each one has a `name` attribute set.\n */\nfunction buildEditablesMap(elements: CKEditorEditableComponent[]): Record<string, CKEditorEditableComponent> {\n return elements.reduce((acc, element) => {\n if (!element.name) {\n throw new Error('Editable component missing required \"name\" attribute');\n }\n\n acc[element.name] = element;\n\n return acc;\n }, Object.create(null));\n}\n\n/**\n * Copies the given attributes from the source element to the target element, when present.\n */\nfunction copyAttributes(source: Element, target: Element, attrNames: readonly string[]) {\n for (const attr of attrNames) {\n if (source.hasAttribute(attr)) {\n target.setAttribute(attr, source.getAttribute(attr)!);\n }\n }\n}\n\n/**\n * Hides a `<textarea>` element visually while keeping it accessible to form submissions.\n */\nfunction hideTextareaVisually(textarea: HTMLTextAreaElement) {\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/**\n * Parses the `editable-height` attribute into a pixel value, or `null` when absent/invalid.\n */\nfunction parseEditableHeight(raw: string | null): number | null {\n if (raw === null) {\n return null;\n }\n\n const height = Number.parseInt(raw, 10);\n\n return Number.isNaN(height) ? null : height;\n}\n\n/**\n * Applies a fixed editing view height to the given editor instance.\n */\nfunction applyEditableHeight(instance: Editor, height: number) {\n instance.editing.view.change((writer) => {\n writer.setStyle('height', `${height}px`, instance.editing.view.document.getRoot()!);\n });\n}\n\n/**\n * Parses the `bundle` attribute JSON into a `BundleDescription`.\n */\nfunction parseBundleDescription(raw: string | null): BundleDescription {\n return JSON.parse(raw!);\n}\n\n/**\n * Parses the `plugins` attribute JSON into async import descriptors.\n */\nfunction parsePluginDescriptors(raw: string | null) {\n const items = raw ? JSON.parse(raw) : [];\n\n return items.map((item: any) =>\n typeof item === 'string'\n ? { import_name: 'ckeditor5', import_as: item }\n : item,\n );\n}\n\n/**\n * Resolves the CKEditor 5 editor constructor matching the `type` attribute.\n */\nfunction resolveEditorConstructor(ckeditorModule: object, editorType: string | null): EditorConstructor {\n if (!editorType || !Object.prototype.hasOwnProperty.call(ckeditorModule, editorType)) {\n throw new Error(`Invalid editor type: ${editorType}`);\n }\n\n return (ckeditorModule as any)[editorType] as EditorConstructor;\n}\n\n/**\n * Resolves an inline event handler attribute value (e.g. `oneditorready=\"doSomething(event)\"`)\n * into a callable function, looking it up on `window` first.\n */\nfunction resolveInlineEventHandler(handlerAttr: string): Function {\n if (!isSafeKey(handlerAttr)) {\n throw new Error(`Unsafe event handler attribute value: ${handlerAttr}`);\n }\n\n // eslint-disable-next-line no-new-func\n return (window as any)[handlerAttr] || new Function('event', handlerAttr);\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","CKEditorMultiRootEditablesTracker","#editorElement","#editables","editorElement","initialEditables","target","name","ui","editing","model","modelElement","initialData","root","editable","CKEditorComponent","#initialHTML","#context","#contextEditorId","#bundle","#getEventHandler","handler","#setEventHandler","resolveInlineEventHandler","event","#destroy","#editorElementTag","getEditorElementTag","#contextWatchdog","parseEditorConfig","#initializeEditor","editablesOrContent","#ensureStylesheetsInjected","#ensureWindowScriptsInjected","isMultiroot","content","resolveEditorContent","beforeInitEventDetails","buildBeforeInitEventDetails","Editor","#getEditorConstructor","translations","#getTranslations","applyContentToConfig","watchdog","instance","contextId","_config","EditorWatchdog","#assignInputAttributes","#queryEditables","#setupContentSync","#setupEditableHeight","#setupDataChangeListener","err","getRootContent","rootName","getAllRoots","acc","editables","buildEditablesMap","mainEditable","textarea","copyAttributes","syncInput","hideTextareaVisually","height","parseEditableHeight","applyEditableHeight","#getBundle","parseBundleDescription","windowScripts","parsePluginDescriptors","CKEditor","resolveEditorConstructor","type","isClassic","buildRootsConfig","elements","source","attrNames","attr","writer","ckeditorModule","editorType","handlerAttr","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,GAA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