ckeditor5 1.31.8 → 1.32.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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -4
  3. data/lib/ckeditor5/rails/assets/webcomponent_bundle.rb +2 -21
  4. data/lib/ckeditor5/rails/version.rb +1 -1
  5. data/npm_package/dist/index.cjs +2 -0
  6. data/npm_package/dist/index.cjs.map +1 -0
  7. data/npm_package/dist/index.d.ts +1 -0
  8. data/npm_package/dist/index.mjs +723 -0
  9. data/npm_package/dist/index.mjs.map +1 -0
  10. data/npm_package/dist/src/components/context.d.ts +24 -0
  11. data/npm_package/dist/src/components/context.d.ts.map +1 -0
  12. data/npm_package/dist/src/components/editable.d.ts +34 -0
  13. data/npm_package/dist/src/components/editable.d.ts.map +1 -0
  14. data/npm_package/dist/src/components/editor/editor.d.ts +79 -0
  15. data/npm_package/dist/src/components/editor/editor.d.ts.map +1 -0
  16. data/npm_package/dist/src/components/editor/index.d.ts +3 -0
  17. data/npm_package/dist/src/components/editor/index.d.ts.map +1 -0
  18. data/npm_package/dist/src/components/editor/multiroot-editables-tracker.d.ts +36 -0
  19. data/npm_package/dist/src/components/editor/multiroot-editables-tracker.d.ts.map +1 -0
  20. data/npm_package/dist/src/components/index.d.ts +5 -0
  21. data/npm_package/dist/src/components/index.d.ts.map +1 -0
  22. data/npm_package/dist/src/components/ui-part.d.ts +2 -0
  23. data/npm_package/dist/src/components/ui-part.d.ts.map +1 -0
  24. data/npm_package/dist/src/helpers/exec-if-dom-ready.d.ts +7 -0
  25. data/npm_package/dist/src/helpers/exec-if-dom-ready.d.ts.map +1 -0
  26. data/npm_package/dist/src/helpers/index.d.ts +8 -0
  27. data/npm_package/dist/src/helpers/index.d.ts.map +1 -0
  28. data/npm_package/dist/src/helpers/inject-script.d.ts +8 -0
  29. data/npm_package/dist/src/helpers/inject-script.d.ts.map +1 -0
  30. data/npm_package/dist/src/helpers/is-safe-key.d.ts +8 -0
  31. data/npm_package/dist/src/helpers/is-safe-key.d.ts.map +1 -0
  32. data/npm_package/dist/src/helpers/load-async-css.d.ts +9 -0
  33. data/npm_package/dist/src/helpers/load-async-css.d.ts.map +1 -0
  34. data/npm_package/dist/src/helpers/load-async-imports.d.ts +25 -0
  35. data/npm_package/dist/src/helpers/load-async-imports.d.ts.map +1 -0
  36. data/npm_package/dist/src/helpers/resolve-config-element-references.d.ts +9 -0
  37. data/npm_package/dist/src/helpers/resolve-config-element-references.d.ts.map +1 -0
  38. data/npm_package/dist/src/helpers/uid.d.ts +7 -0
  39. data/npm_package/dist/src/helpers/uid.d.ts.map +1 -0
  40. data/npm_package/dist/src/index.d.ts +1 -0
  41. data/npm_package/dist/src/index.d.ts.map +1 -0
  42. data/npm_package/dist/vite.config.d.ts +3 -0
  43. data/npm_package/dist/vite.config.d.ts.map +1 -0
  44. data/npm_package/package.json +37 -0
  45. metadata +41 -6
  46. data/lib/ckeditor5/rails/assets/webcomponents/components/context.mjs +0 -123
  47. data/lib/ckeditor5/rails/assets/webcomponents/components/editable.mjs +0 -113
  48. data/lib/ckeditor5/rails/assets/webcomponents/components/editor.mjs +0 -778
  49. data/lib/ckeditor5/rails/assets/webcomponents/components/ui-part.mjs +0 -26
  50. data/lib/ckeditor5/rails/assets/webcomponents/utils.mjs +0 -235
@@ -1,26 +0,0 @@
1
- class CKEditorUIPartComponent extends HTMLElement {
2
- /**
3
- * Lifecycle callback when element is added to DOM
4
- * Adds the toolbar to the editor UI
5
- */
6
- connectedCallback() {
7
- execIfDOMReady(async () => {
8
- const uiPart = this.getAttribute('name');
9
- const editor = await this.#queryEditorElement().instancePromise.promise;
10
-
11
- this.appendChild(editor.ui.view[uiPart].element);
12
- });
13
- }
14
-
15
- /**
16
- * Finds the parent editor component
17
- *
18
- * @private
19
- * @returns {CKEditorComponent|null} Parent editor component or null if not found
20
- */
21
- #queryEditorElement() {
22
- return this.closest('ckeditor-component') || document.body.querySelector('ckeditor-component');
23
- }
24
- }
25
-
26
- customElements.define('ckeditor-ui-part-component', CKEditorUIPartComponent);
@@ -1,235 +0,0 @@
1
- /**
2
- * Executes callback when DOM is ready
3
- *
4
- * @param {() => void} callback - Function to execute when DOM is ready
5
- */
6
- function execIfDOMReady(callback) {
7
- switch (document.readyState) {
8
- case 'loading':
9
- document.addEventListener('DOMContentLoaded', callback, { once: true });
10
- break;
11
-
12
- case 'interactive':
13
- case 'complete':
14
- setTimeout(callback, 0);
15
- break;
16
-
17
- default:
18
- console.warn('Unexpected document.readyState:', document.readyState);
19
- setTimeout(callback, 0);
20
- }
21
- }
22
-
23
- /**
24
- * Dynamically imports modules based on configuration
25
- *
26
- * @param {Array<Object>} imports - Array of import configurations
27
- * @param {Object} imports[].name - Name of inline plugin (for inline type)
28
- * @param {Object} imports[].code - Source code of inline plugin (for inline type)
29
- * @param {Object} imports[].import_name - Module path to import (for external type)
30
- * @param {Object} imports[].import_as - Name to import as (for external type)
31
- * @param {Object} imports[].window_name - Global window object name (for external type)
32
- * @param {('inline'|'external')} imports[].type - Type of import
33
- * @returns {Promise<Array<any>>} Array of loaded modules
34
- * @throws {Error} When plugin loading fails
35
- */
36
- function loadAsyncImports(imports = []) {
37
- const loadExternalPlugin = async ({ url, import_name, import_as, window_name, stylesheets }) => {
38
- if (stylesheets?.length) {
39
- await loadAsyncCSS(stylesheets);
40
- }
41
-
42
- if (window_name) {
43
- function isScriptPresent() {
44
- return Object.prototype.hasOwnProperty.call(window, window_name);
45
- }
46
-
47
- if (url && !isScriptPresent()) {
48
- await injectScript(url);
49
- }
50
-
51
- if (!isScriptPresent()) {
52
- window.dispatchEvent(
53
- new CustomEvent(`ckeditor:request-cjs-plugin:${window_name}`)
54
- );
55
- }
56
-
57
- if (!isScriptPresent()) {
58
- throw new Error(
59
- `Plugin window['${window_name}'] not found in global scope. ` +
60
- 'Please ensure the plugin is loaded before CKEditor initialization.'
61
- );
62
- }
63
-
64
- return window[window_name];
65
- }
66
-
67
- const module = await import(import_name);
68
- const imported = module[import_as || 'default'];
69
-
70
- if (!imported) {
71
- throw new Error(
72
- `Plugin "${import_as || 'default'}" not found in the ESM module ` +
73
- `"${import_name}"! Available imports: ${Object.keys(module).join(', ')}! ` +
74
- 'Consider changing "import_as" value.'
75
- );
76
- }
77
-
78
- return imported;
79
- };
80
-
81
- function uncompressImport(pkg) {
82
- if (typeof pkg === 'string') {
83
- return loadExternalPlugin({ import_name: 'ckeditor5', import_as: pkg });
84
- }
85
-
86
- return loadExternalPlugin(pkg);
87
- }
88
-
89
- return Promise.all(imports.map(uncompressImport));
90
- }
91
-
92
- /**
93
- * Checks if stylesheet with given href already exists in document
94
- *
95
- * @param {string} href - Stylesheet URL to check
96
- * @returns {boolean} True if stylesheet already exists
97
- */
98
- function stylesheetExists(href) {
99
- return Array
100
- .from(document.styleSheets)
101
- .some(sheet =>
102
- sheet.href === href || sheet.href === new URL(href, window.location.href).href
103
- );
104
- }
105
-
106
- /**
107
- * Dynamically loads CSS files based on configuration
108
- *
109
- * @param {Array<string>} imports - Array of CSS file URLs to load
110
- * @returns {Promise<Array<void>>} Array of promises for each CSS file load
111
- * @throws {Error} When CSS file loading fails
112
- */
113
- function loadAsyncCSS(stylesheets = []) {
114
- const promises = stylesheets.map(href =>
115
- new Promise((resolve, reject) => {
116
- if (stylesheetExists(href)) {
117
- resolve();
118
- return;
119
- }
120
-
121
- const link = document.createElement('link');
122
- link.rel = 'stylesheet';
123
- link.href = href;
124
-
125
- link.onerror = reject;
126
- link.onload = () => resolve();
127
-
128
- document.head.appendChild(link);
129
- })
130
- );
131
-
132
- return Promise.all(promises);
133
- }
134
-
135
- const SCRIPT_LOAD_PROMISES = new Map();
136
-
137
- /**
138
- * Dynamically loads script files based on configuration.
139
- * Uses caching to avoid loading the same script multiple times.
140
- *
141
- * @param {string} url - URL of the script to load
142
- */
143
- function injectScript(url) {
144
- if (SCRIPT_LOAD_PROMISES.has(url)) {
145
- return SCRIPT_LOAD_PROMISES.get(url);
146
- }
147
-
148
- const promise = new Promise((resolve, reject) => {
149
- const script = document.createElement('script');
150
- script.src = url;
151
- script.onload = resolve;
152
- script.onerror = reject;
153
-
154
- document.head.appendChild(script);
155
- });
156
-
157
- SCRIPT_LOAD_PROMISES.set(url, promise);
158
- return promise;
159
- }
160
-
161
- /**
162
- * Checks if a key is safe to use in configuration objects to prevent prototype pollution
163
- *
164
- * @param {string} key - Key name to check
165
- * @returns {boolean} True if key is safe to use
166
- */
167
- function isSafeKey(key) {
168
- return typeof key === 'string' &&
169
- key !== '__proto__' &&
170
- key !== 'constructor' &&
171
- key !== 'prototype';
172
- }
173
-
174
- /**
175
- * Resolves element references in configuration object.
176
- * Looks for objects with { $element: "selector" } format and replaces them with actual DOM elements.
177
- *
178
- * @param {Object} obj - Configuration object to process
179
- * @returns {Object} Processed configuration object with resolved element references
180
- * @throws {Error} When element reference is invalid
181
- */
182
- function resolveElementReferences(obj) {
183
- if (!obj || typeof obj !== 'object') {
184
- return obj;
185
- }
186
-
187
- if (Array.isArray(obj)) {
188
- return obj.map(item => resolveElementReferences(item));
189
- }
190
-
191
- const result = Object.create(null);
192
-
193
- for (const key of Object.getOwnPropertyNames(obj)) {
194
- if (!isSafeKey(key)) {
195
- console.warn(`Suspicious key "${key}" detected in config, skipping`);
196
- continue;
197
- }
198
-
199
- const value = obj[key];
200
-
201
- if (value && typeof value === 'object') {
202
- if (value.$element) {
203
- const selector = value.$element;
204
-
205
- if (typeof selector !== 'string') {
206
- console.warn(`Invalid selector type for "${key}", expected string`);
207
- continue;
208
- }
209
-
210
- const element = document.querySelector(selector);
211
-
212
- if (!element) {
213
- console.warn(`Element not found for selector: ${selector}`);
214
- }
215
-
216
- result[key] = element || null;
217
- } else {
218
- result[key] = resolveElementReferences(value);
219
- }
220
- } else {
221
- result[key] = value;
222
- }
223
- }
224
-
225
- return result;
226
- }
227
-
228
- /**
229
- * Generates a unique identifier string
230
- *
231
- * @returns {string} Random string that can be used as unique identifier
232
- */
233
- function uid() {
234
- return Math.random().toString(36).substring(2);
235
- }