@ckeditor/ckeditor5-editor-classic 47.6.1 → 48.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -18,7 +18,7 @@ Where not otherwise indicated, all CKEditor 5 content is authored by CKSour
18
18
 
19
19
  The following libraries are included in CKEditor 5 under the [MIT license](https://opensource.org/licenses/MIT):
20
20
 
21
- * es-toolkit - Copyright (c) 2024 Viva Republica, Inc.
21
+ * es-toolkit - Copyright (c) 2024 Viva Republica, Inc and Copyright OpenJS Foundation and other contributors.
22
22
 
23
23
  Trademarks
24
24
  ----------
@@ -6,8 +6,8 @@
6
6
  * @module editor-classic/classiceditor
7
7
  */
8
8
  import { ClassicEditorUI } from './classiceditorui.js';
9
- import { Editor, type EditorConfig } from 'ckeditor5/src/core.js';
10
- declare const ClassicEditor_base: import("ckeditor5/src/utils.js").Mixed<typeof Editor, import("ckeditor5/src/core.js").ElementApi>;
9
+ import { Editor, type EditorConfig } from '@ckeditor/ckeditor5-core';
10
+ declare const ClassicEditor_base: import("@ckeditor/ckeditor5-utils").Mixed<typeof Editor, import("@ckeditor/ckeditor5-core").ElementApi>;
11
11
  /**
12
12
  * The classic editor implementation. It uses an inline editable and a sticky toolbar, all enclosed in a boxed UI.
13
13
  * See the {@glink examples/builds/classic-editor demo}.
@@ -30,12 +30,24 @@ export declare class ClassicEditor extends /* #__PURE__ */ ClassicEditor_base {
30
30
  * **Note:** do not use the constructor to create editor instances. Use the static
31
31
  * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`} method instead.
32
32
  *
33
+ * @param config The editor configuration.
34
+ */
35
+ protected constructor(config: EditorConfig);
36
+ /**
37
+ * Creates an instance of the classic editor.
38
+ *
39
+ * **Note:** do not use the constructor to create editor instances. Use the static
40
+ * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`} method instead.
41
+ *
42
+ * **Note**: This constructor signature is deprecated and will be removed in the future release.
43
+ *
44
+ * @deprecated
33
45
  * @param sourceElementOrData The DOM element that will be the source for the created editor
34
46
  * or the editor's initial data. For more information see
35
47
  * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`}.
36
48
  * @param config The editor configuration.
37
49
  */
38
- protected constructor(sourceElementOrData: HTMLElement | string, config?: EditorConfig);
50
+ protected constructor(sourceElementOrData: HTMLElement | string, config: EditorConfig);
39
51
  /**
40
52
  * Destroys the editor instance, releasing all resources used by it.
41
53
  *
@@ -55,6 +67,90 @@ export declare class ClassicEditor extends /* #__PURE__ */ ClassicEditor_base {
55
67
  *
56
68
  * ```ts
57
69
  * ClassicEditor
70
+ * .create( {
71
+ * attachTo: document.querySelector( '#editor' )
72
+ * } )
73
+ * .then( editor => {
74
+ * console.log( 'Editor was initialized', editor );
75
+ * } )
76
+ * .catch( err => {
77
+ * console.error( err.stack );
78
+ * } );
79
+ * ```
80
+ *
81
+ * The element's content will be used as the editor data and the element will be replaced by the editor UI.
82
+ *
83
+ * # Creating a detached editor
84
+ *
85
+ * Alternatively, you can initialize the editor by passing the initial data directly as a string.
86
+ * In this case, the editor will render an element that must be inserted into the DOM:
87
+ *
88
+ * ```ts
89
+ * ClassicEditor
90
+ * .create( {
91
+ * root: {
92
+ * initialData: '<p>Hello world!</p>'
93
+ * }
94
+ * } )
95
+ * .then( editor => {
96
+ * console.log( 'Editor was initialized', editor );
97
+ *
98
+ * // Initial data was provided so the editor UI element needs to be added manually to the DOM.
99
+ * document.body.appendChild( editor.ui.element );
100
+ * } )
101
+ * .catch( err => {
102
+ * console.error( err.stack );
103
+ * } );
104
+ * ```
105
+ *
106
+ * This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
107
+ * web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
108
+ *
109
+ * # Replacing a DOM element (and data provided in `config.root.initialData`)
110
+ *
111
+ * You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
112
+ *
113
+ * ```ts
114
+ * ClassicEditor
115
+ * .create( {
116
+ * attachTo: document.querySelector( '#editor' ),
117
+ * root: {
118
+ * initialData: '<p>Hello world!</p>'
119
+ * }
120
+ * } )
121
+ * .then( editor => {
122
+ * console.log( 'Editor was initialized', editor );
123
+ * } )
124
+ * .catch( err => {
125
+ * console.error( err.stack );
126
+ * } );
127
+ * ```
128
+ *
129
+ * This method can be used to initialize the editor on an existing element with the specified content in case if your integration
130
+ * makes it difficult to set the content of the source element.
131
+ *
132
+ * # Configuring the editor
133
+ *
134
+ * See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
135
+ * customizing plugins, toolbar and more.
136
+ *
137
+ * @param config The editor configuration.
138
+ * @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
139
+ */
140
+ static create(config: EditorConfig): Promise<ClassicEditor>;
141
+ /**
142
+ * Creates a new classic editor instance.
143
+ *
144
+ * **Note**: This method signature is deprecated and will be removed in the future release.
145
+ *
146
+ * There are three ways how the editor can be initialized.
147
+ *
148
+ * # Replacing a DOM element (and loading data from it)
149
+ *
150
+ * You can initialize the editor using an existing DOM element:
151
+ *
152
+ * ```ts
153
+ * ClassicEditor
58
154
  * .create( document.querySelector( '#editor' ) )
59
155
  * .then( editor => {
60
156
  * console.log( 'Editor was initialized', editor );
@@ -88,14 +184,16 @@ export declare class ClassicEditor extends /* #__PURE__ */ ClassicEditor_base {
88
184
  * This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
89
185
  * web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
90
186
  *
91
- * # Replacing a DOM element (and data provided in `config.initialData`)
187
+ * # Replacing a DOM element (and data provided in `config.root.initialData`)
92
188
  *
93
189
  * You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
94
190
  *
95
191
  * ```ts
96
192
  * ClassicEditor
97
193
  * .create( document.querySelector( '#editor' ), {
98
- * initialData: '<h2>Initial data</h2><p>Foo bar.</p>'
194
+ * root: {
195
+ * initialData: '<p>Hello world!</p>'
196
+ * }
99
197
  * } )
100
198
  * .then( editor => {
101
199
  * console.log( 'Editor was initialized', editor );
@@ -115,6 +213,7 @@ export declare class ClassicEditor extends /* #__PURE__ */ ClassicEditor_base {
115
213
  * See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
116
214
  * customizing plugins, toolbar and more.
117
215
  *
216
+ * @deprecated
118
217
  * @param sourceElementOrData The DOM element that will be the source for the created editor
119
218
  * or the editor's initial data.
120
219
  *
@@ -133,6 +232,6 @@ export declare class ClassicEditor extends /* #__PURE__ */ ClassicEditor_base {
133
232
  * @param config The editor configuration.
134
233
  * @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
135
234
  */
136
- static create(sourceElementOrData: HTMLElement | string, config?: EditorConfig): Promise<ClassicEditor>;
235
+ static create(sourceElementOrData: HTMLElement | string, config: EditorConfig): Promise<ClassicEditor>;
137
236
  }
138
237
  export {};
@@ -5,8 +5,8 @@
5
5
  /**
6
6
  * @module editor-classic/classiceditorui
7
7
  */
8
- import type { Editor } from 'ckeditor5/src/core.js';
9
- import { EditorUI } from 'ckeditor5/src/ui.js';
8
+ import type { Editor } from '@ckeditor/ckeditor5-core';
9
+ import { EditorUI } from '@ckeditor/ckeditor5-ui';
10
10
  import { type ClassicEditorUIView } from './classiceditoruiview.js';
11
11
  /**
12
12
  * The classic editor UI class.
@@ -5,9 +5,9 @@
5
5
  /**
6
6
  * @module editor-classic/classiceditoruiview
7
7
  */
8
- import { BoxedEditorUIView, InlineEditableUIView, StickyPanelView, ToolbarView } from 'ckeditor5/src/ui.js';
9
- import type { Locale } from 'ckeditor5/src/utils.js';
10
- import type { EditingView } from 'ckeditor5/src/engine.js';
8
+ import { BoxedEditorUIView, InlineEditableUIView, StickyPanelView, ToolbarView } from '@ckeditor/ckeditor5-ui';
9
+ import type { Locale } from '@ckeditor/ckeditor5-utils';
10
+ import type { EditingView } from '@ckeditor/ckeditor5-engine';
11
11
  import '../theme/classiceditor.css';
12
12
  /**
13
13
  * Classic editor UI view. Uses an inline editable and a sticky toolbar, all
@@ -2,10 +2,21 @@
2
2
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
4
  */
5
+ .ck.ck-editor__main > .ck-editor__editable{
6
+ background:var(--ck-color-base-background);
7
+ border-radius:var(--ck-rounded-corners-radius);
8
+ border-top-left-radius:0;
9
+ border-top-right-radius:0;
10
+ }
11
+
12
+ .ck.ck-editor__main > .ck-editor__editable:not(.ck-focused){
13
+ border-color:var(--ck-color-base-border);
14
+ }
15
+
5
16
  .ck.ck-editor{
6
- position:relative;
17
+ position:relative;
7
18
  }
8
19
 
9
20
  .ck.ck-editor .ck-editor__top .ck-sticky-panel .ck-toolbar{
10
- z-index:var(--ck-z-panel);
11
- }
21
+ z-index:var(--ck-z-panel);
22
+ }
package/dist/index.css CHANGED
@@ -2,21 +2,23 @@
2
2
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
4
  */
5
- /*
6
- * Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
7
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
8
- */
5
+ .ck.ck-editor__main > .ck-editor__editable {
6
+ background: var(--ck-color-base-background);
7
+ border-radius: var(--ck-rounded-corners-radius);
8
+ border-top-left-radius: 0;
9
+ border-top-right-radius: 0;
10
+ }
11
+
12
+ .ck.ck-editor__main > .ck-editor__editable:not(.ck-focused) {
13
+ border-color: var(--ck-color-base-border);
14
+ }
9
15
 
10
16
  .ck.ck-editor {
11
- /* All the elements within `.ck-editor` are positioned relatively to it.
12
- If any element needs to be positioned with respect to the <body>, etc.,
13
- it must land outside of the `.ck-editor` in DOM. */
14
- position: relative;
17
+ position: relative;
15
18
  }
16
19
 
17
20
  .ck.ck-editor .ck-editor__top .ck-sticky-panel .ck-toolbar {
18
- /* https://github.com/ckeditor/ckeditor5-editor-classic/issues/62 */
19
- z-index: var(--ck-z-panel);
20
- }
21
+ z-index: var(--ck-z-panel);
22
+ }
21
23
 
22
24
  /*# sourceMappingURL=index.css.map */
@@ -1 +1 @@
1
- {"version":3,"sources":["../theme/classiceditor.css","index.css"],"names":[],"mappings":";;;;AAAA,CAAA;ACCA,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ;AAC3E,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC;AAClF,CAAC,CDAC;;AAEF,CAAA,EAAA,CAAA,EAAA,CAAA,MAAA,CAAA;ACCA,CDAC,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,CAAA,QAAA,CAAA,MAAA,CAAA,CAAA,CAAA,EAAA,CAAA,MAAA,CAAA,CAAA,GAAA,CAAA,UAAA,CAAA,UAAA,CAAA,EAAA,CAAA,EAAA;ACCD,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;AACxE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CDAC;ACCpD,CDAC,QAAA,CAAA,CAAA,QAAkB;AAMnB;;AAJC,CAAA,EAAA,CAAA,EAAA,CAAA,MAAA,CAAA,CAAA,EAAA,CAAA,WAAA,CAAA,CAAA,EAAA,CAAA,MAAA,CAAA,KAAA,CAAA,CAAA,EAAA,CAAA,OAAA,CAAA;ACED,CAAC,CDDC,CAAA,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA,MAAA,CAAA,GAAA,CAAA,QAAA,CAAA,SAAA,CAAA,MAAA,CAAA,OAAA,CAAA,MAAA,CAAA,EAAA,CAAA,CAAmE;ACErE,CAAC,CDDC,CAAA,CAAA,KAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,KAAA,CAA0B;ACE5B,CDDC;;ACGD,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC","file":"index.css.map","sourcesContent":["/*\n * Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options\n */\n\n.ck.ck-editor {\n\t/* All the elements within `.ck-editor` are positioned relatively to it.\n\t If any element needs to be positioned with respect to the <body>, etc.,\n\t it must land outside of the `.ck-editor` in DOM. */\n\tposition: relative;\n\n\t& .ck-editor__top .ck-sticky-panel .ck-toolbar {\n\t\t/* https://github.com/ckeditor/ckeditor5-editor-classic/issues/62 */\n\t\tz-index: var(--ck-z-panel);\n\t}\n}\n","/*\n * Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options\n */\n\n.ck.ck-editor {\n\t/* All the elements within `.ck-editor` are positioned relatively to it.\n\t If any element needs to be positioned with respect to the <body>, etc.,\n\t it must land outside of the `.ck-editor` in DOM. */\n\tposition: relative;\n}\n\n.ck.ck-editor .ck-editor__top .ck-sticky-panel .ck-toolbar {\n\t\t/* https://github.com/ckeditor/ckeditor5-editor-classic/issues/62 */\n\t\tz-index: var(--ck-z-panel);\n\t}\n\n/*# sourceMappingURL=index.css.map */"]}
1
+ {"version":3,"sources":["../theme/classiceditor.css","index.css"],"names":[],"mappings":";;;;AAOA,CAAA,EAAA,CAAA,EAAA,CAAA,YAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,gBAAA,CAAA;ACNA,CAAC,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC;AAC7C,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;AACjD,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAC3B,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;AAC5B;;ADSC,CAAA,EAAA,CAAA,EAAA,CAAA,YAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,gBAAA,CAAA,GAAA,CAAA,CAAA,EAAA,CAAA,OAAA,CAAA,CAAA;ACND,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;AAC3C;;ADUA,CAAA,EAAA,CAAA,EAAA,CAAA,MAAA,CAAA;ACPA,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ;AACpB;;ADYC,CAAA,EAAA,CAAA,EAAA,CAAA,MAAA,CAAA,CAAA,EAAA,CAAA,WAAA,CAAA,CAAA,EAAA,CAAA,MAAA,CAAA,KAAA,CAAA,CAAA,EAAA,CAAA,OAAA,CAAA;ACTD,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AAC5B;;AAEA,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC","file":"index.css.map","sourcesContent":["/*\n * Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options\n */\n\n/* Note: Use ck-editor__main to make sure these styles don't apply to other editor types */\n\n.ck.ck-editor__main > .ck-editor__editable {\n\t/* https://github.com/ckeditor/ckeditor5/issues/3384 */\n\tbackground: var(--ck-color-base-background);\n\tborder-radius: var(--ck-rounded-corners-radius);\n\tborder-top-left-radius: 0;\n\tborder-top-right-radius: 0;\n\n\t&:not(.ck-focused) {\n\t\tborder-color: var(--ck-color-base-border);\n\t}\n}\n\n.ck.ck-editor {\n\t/* All the elements within `.ck-editor` are positioned relatively to it.\n\t If any element needs to be positioned with respect to the <body>, etc.,\n\t it must land outside of the `.ck-editor` in DOM. */\n\tposition: relative;\n\n\t& .ck-editor__top .ck-sticky-panel .ck-toolbar {\n\t\t/* https://github.com/ckeditor/ckeditor5-editor-classic/issues/62 */\n\t\tz-index: var(--ck-z-panel);\n\t}\n}\n",".ck.ck-editor__main > .ck-editor__editable {\n background: var(--ck-color-base-background);\n border-radius: var(--ck-rounded-corners-radius);\n border-top-left-radius: 0;\n border-top-right-radius: 0;\n}\n\n.ck.ck-editor__main > .ck-editor__editable:not(.ck-focused) {\n border-color: var(--ck-color-base-border);\n}\n\n.ck.ck-editor {\n position: relative;\n}\n\n.ck.ck-editor .ck-editor__top .ck-sticky-panel .ck-toolbar {\n z-index: var(--ck-z-panel);\n}\n\n/*# sourceMappingURL=index.css.map */"]}
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@
4
4
  */
5
5
  import { EditorUI, normalizeToolbarConfig, DialogView, BoxedEditorUIView, StickyPanelView, ToolbarView, MenuBarView, InlineEditableUIView } from '@ckeditor/ckeditor5-ui/dist/index.js';
6
6
  import { enableViewPlaceholder } from '@ckeditor/ckeditor5-engine/dist/index.js';
7
- import { ElementReplacer, Rect, CKEditorError, getDataFromElement } from '@ckeditor/ckeditor5-utils/dist/index.js';
8
- import { ElementApiMixin, Editor, attachToForm } from '@ckeditor/ckeditor5-core/dist/index.js';
7
+ import { ElementReplacer, Rect, logWarning } from '@ckeditor/ckeditor5-utils/dist/index.js';
8
+ import { ElementApiMixin, Editor, normalizeSingleRootEditorConstructorParams, normalizeRootsConfig, attachToForm } from '@ckeditor/ckeditor5-core/dist/index.js';
9
9
  import { isElement as isElement$1 } from 'es-toolkit/compat';
10
10
 
11
11
  /**
@@ -115,9 +115,9 @@ import { isElement as isElement$1 } from 'es-toolkit/compat';
115
115
  const editingRoot = editingView.document.getRoot();
116
116
  const sourceElement = editor.sourceElement;
117
117
  let placeholderText;
118
- const placeholder = editor.config.get('placeholder');
118
+ const placeholder = editor.config.get('roots')[this.view.editable.name].placeholder;
119
119
  if (placeholder) {
120
- placeholderText = typeof placeholder === 'string' ? placeholder : placeholder[this.view.editable.name];
120
+ placeholderText = placeholder;
121
121
  }
122
122
  if (!placeholderText && sourceElement && sourceElement.tagName.toLowerCase() === 'textarea') {
123
123
  placeholderText = sourceElement.getAttribute('placeholder');
@@ -314,30 +314,24 @@ import { isElement as isElement$1 } from 'es-toolkit/compat';
314
314
  /**
315
315
  * @inheritDoc
316
316
  */ ui;
317
- /**
318
- * Creates an instance of the classic editor.
319
- *
320
- * **Note:** do not use the constructor to create editor instances. Use the static
321
- * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`} method instead.
322
- *
323
- * @param sourceElementOrData The DOM element that will be the source for the created editor
324
- * or the editor's initial data. For more information see
325
- * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`}.
326
- * @param config The editor configuration.
327
- */ constructor(sourceElementOrData, config = {}){
328
- // If both `config.initialData` is set and initial data is passed as the constructor parameter, then throw.
329
- if (!isElement(sourceElementOrData) && config.initialData !== undefined) {
330
- // Documented in core/editor/editorconfig.jsdoc.
331
- // eslint-disable-next-line ckeditor5-rules/ckeditor-error-message
332
- throw new CKEditorError('editor-create-initial-data', null);
317
+ constructor(sourceElementOrDataOrConfig, config = {}){
318
+ const { sourceElementOrData, editorConfig } = normalizeSingleRootEditorConstructorParams(sourceElementOrDataOrConfig, config);
319
+ super(editorConfig);
320
+ normalizeRootsConfig(sourceElementOrData, this.config, 'main', true);
321
+ if (isElement(this.config.get('roots').main.element)) {
322
+ /**
323
+ * The `config.attachTo` option is not compatible with the `root.element` option.
324
+ * Please use {@link module:core/editor/editorconfig~EditorConfig#attachTo `config.attachTo`}
325
+ * to specify the source element for the {@link module:editor-classic/classiceditor~ClassicEditor}.
326
+ *
327
+ * @error editor-create-attachto-conflict
328
+ */ logWarning('editor-create-attachto-conflict');
333
329
  }
334
- super(config);
330
+ // From this point use only normalized `roots.main.element`.
331
+ const sourceElement = this.config.get('attachTo');
335
332
  this.config.define('menuBar.isVisible', false);
336
- if (this.config.get('initialData') === undefined) {
337
- this.config.set('initialData', getInitialData(sourceElementOrData));
338
- }
339
- if (isElement(sourceElementOrData)) {
340
- this.sourceElement = sourceElementOrData;
333
+ if (isElement(sourceElement)) {
334
+ this.sourceElement = sourceElement;
341
335
  }
342
336
  this.model.document.createRoot();
343
337
  const shouldToolbarGroupWhenFull = !this.config.get('toolbar.shouldNotGroupWhenFull');
@@ -345,7 +339,7 @@ import { isElement as isElement$1 } from 'es-toolkit/compat';
345
339
  const view = new ClassicEditorUIView(this.locale, this.editing.view, {
346
340
  shouldToolbarGroupWhenFull,
347
341
  useMenuBar: menuBarConfig.isVisible,
348
- label: this.config.get('label')
342
+ label: this.config.get('roots').main.label
349
343
  });
350
344
  this.ui = new ClassicEditorUI(this, view);
351
345
  attachToForm(this);
@@ -363,104 +357,13 @@ import { isElement as isElement$1 } from 'es-toolkit/compat';
363
357
  this.ui.destroy();
364
358
  return super.destroy();
365
359
  }
366
- /**
367
- * Creates a new classic editor instance.
368
- *
369
- * There are three ways how the editor can be initialized.
370
- *
371
- * # Replacing a DOM element (and loading data from it)
372
- *
373
- * You can initialize the editor using an existing DOM element:
374
- *
375
- * ```ts
376
- * ClassicEditor
377
- * .create( document.querySelector( '#editor' ) )
378
- * .then( editor => {
379
- * console.log( 'Editor was initialized', editor );
380
- * } )
381
- * .catch( err => {
382
- * console.error( err.stack );
383
- * } );
384
- * ```
385
- *
386
- * The element's content will be used as the editor data and the element will be replaced by the editor UI.
387
- *
388
- * # Creating a detached editor
389
- *
390
- * Alternatively, you can initialize the editor by passing the initial data directly as a string.
391
- * In this case, the editor will render an element that must be inserted into the DOM:
392
- *
393
- * ```ts
394
- * ClassicEditor
395
- * .create( '<p>Hello world!</p>' )
396
- * .then( editor => {
397
- * console.log( 'Editor was initialized', editor );
398
- *
399
- * // Initial data was provided so the editor UI element needs to be added manually to the DOM.
400
- * document.body.appendChild( editor.ui.element );
401
- * } )
402
- * .catch( err => {
403
- * console.error( err.stack );
404
- * } );
405
- * ```
406
- *
407
- * This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
408
- * web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
409
- *
410
- * # Replacing a DOM element (and data provided in `config.initialData`)
411
- *
412
- * You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
413
- *
414
- * ```ts
415
- * ClassicEditor
416
- * .create( document.querySelector( '#editor' ), {
417
- * initialData: '<h2>Initial data</h2><p>Foo bar.</p>'
418
- * } )
419
- * .then( editor => {
420
- * console.log( 'Editor was initialized', editor );
421
- * } )
422
- * .catch( err => {
423
- * console.error( err.stack );
424
- * } );
425
- * ```
426
- *
427
- * This method can be used to initialize the editor on an existing element with the specified content in case if your integration
428
- * makes it difficult to set the content of the source element.
429
- *
430
- * Note that an error will be thrown if you pass the initial data both as the first parameter and also in the configuration.
431
- *
432
- * # Configuring the editor
433
- *
434
- * See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
435
- * customizing plugins, toolbar and more.
436
- *
437
- * @param sourceElementOrData The DOM element that will be the source for the created editor
438
- * or the editor's initial data.
439
- *
440
- * If a DOM element is passed, its content will be automatically loaded to the editor upon initialization
441
- * and the {@link module:editor-classic/classiceditorui~ClassicEditorUI#element editor element} will replace the passed element
442
- * in the DOM (the original one will be hidden and the editor will be injected next to it).
443
- *
444
- * If the {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy updateSourceElementOnDestroy}
445
- * option is set to `true`, the editor data will be set back to the original element once the editor is destroyed and when a form,
446
- * in which this element is contained, is submitted (if the original element is a `<textarea>`). This ensures seamless integration
447
- * with native web forms.
448
- *
449
- * If the initial data is passed, a detached editor will be created. In this case you need to insert it into the DOM manually.
450
- * It is available under the {@link module:editor-classic/classiceditorui~ClassicEditorUI#element `editor.ui.element`} property.
451
- *
452
- * @param config The editor configuration.
453
- * @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
454
- */ static create(sourceElementOrData, config = {}) {
360
+ static create(sourceElementOrDataOrConfig, config = {}) {
455
361
  return new Promise((resolve)=>{
456
- const editor = new this(sourceElementOrData, config);
457
- resolve(editor.initPlugins().then(()=>editor.ui.init(isElement(sourceElementOrData) ? sourceElementOrData : null)).then(()=>editor.data.init(editor.config.get('initialData'))).then(()=>editor.fire('ready')).then(()=>editor));
362
+ const editor = new this(sourceElementOrDataOrConfig, config);
363
+ resolve(editor.initPlugins().then(()=>editor.ui.init(editor.config.get('attachTo') || null)).then(()=>editor.data.init(editor.config.get('roots').main.initialData)).then(()=>editor.fire('ready')).then(()=>editor));
458
364
  });
459
365
  }
460
366
  }
461
- function getInitialData(sourceElementOrData) {
462
- return isElement(sourceElementOrData) ? getDataFromElement(sourceElementOrData) : sourceElementOrData;
463
- }
464
367
  function isElement(value) {
465
368
  return isElement$1(value);
466
369
  }