@ckeditor/ckeditor5-editor-inline 38.0.1 → 38.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/build/editor-inline.js.map +1 -0
- package/package.json +2 -26
- package/src/index.d.ts +8 -8
- package/src/index.js +8 -8
- package/src/inlineeditor.d.ts +176 -176
- package/src/inlineeditor.js +226 -226
- package/src/inlineeditorui.d.ts +52 -52
- package/src/inlineeditorui.js +122 -122
- package/src/inlineeditoruiview.d.ts +137 -137
- package/src/inlineeditoruiview.js +130 -130
package/src/inlineeditor.js
CHANGED
@@ -1,226 +1,226 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
-
*/
|
5
|
-
/**
|
6
|
-
* @module editor-inline/inlineeditor
|
7
|
-
*/
|
8
|
-
import { Editor, Context, DataApiMixin, ElementApiMixin, attachToForm, secureSourceElement } from 'ckeditor5/src/core';
|
9
|
-
import { getDataFromElement, CKEditorError } from 'ckeditor5/src/utils';
|
10
|
-
import { ContextWatchdog, EditorWatchdog } from 'ckeditor5/src/watchdog';
|
11
|
-
import InlineEditorUI from './inlineeditorui';
|
12
|
-
import InlineEditorUIView from './inlineeditoruiview';
|
13
|
-
import { isElement as _isElement } from 'lodash-es';
|
14
|
-
/**
|
15
|
-
* The {@glink installation/getting-started/predefined-builds#inline-editor inline editor} implementation.
|
16
|
-
* It uses an inline editable and a floating toolbar.
|
17
|
-
* See the {@glink examples/builds/inline-editor demo}.
|
18
|
-
*
|
19
|
-
* In order to create a inline editor instance, use the static
|
20
|
-
* {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`} method.
|
21
|
-
*
|
22
|
-
* # Inline editor and inline build
|
23
|
-
*
|
24
|
-
* The inline editor can be used directly from source (if you installed the
|
25
|
-
* [`@ckeditor/ckeditor5-editor-inline`](https://www.npmjs.com/package/@ckeditor/ckeditor5-editor-inline) package)
|
26
|
-
* but it is also available in the {@glink installation/getting-started/predefined-builds#inline-editor inline build}.
|
27
|
-
*
|
28
|
-
* {@glink installation/getting-started/predefined-builds Builds}
|
29
|
-
* are ready-to-use editors with plugins bundled in. When using the editor from
|
30
|
-
* source you need to take care of loading all plugins by yourself
|
31
|
-
* (through the {@link module:core/editor/editorconfig~EditorConfig#plugins `config.plugins`} option).
|
32
|
-
* Using the editor from source gives much better flexibility and allows easier customization.
|
33
|
-
*
|
34
|
-
* Read more about initializing the editor from source or as a build in
|
35
|
-
* {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`}.
|
36
|
-
*/
|
37
|
-
export default class InlineEditor extends DataApiMixin(ElementApiMixin(Editor)) {
|
38
|
-
/**
|
39
|
-
* Creates an instance of the inline editor.
|
40
|
-
*
|
41
|
-
* **Note:** Do not use the constructor to create editor instances. Use the static
|
42
|
-
* {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`} method instead.
|
43
|
-
*
|
44
|
-
* @param sourceElementOrData The DOM element that will be the source for the created editor
|
45
|
-
* (on which the editor will be initialized) or initial data for the editor. For more information see
|
46
|
-
* {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`}.
|
47
|
-
* @param config The editor configuration.
|
48
|
-
*/
|
49
|
-
constructor(sourceElementOrData, config = {}) {
|
50
|
-
// If both `config.initialData` and initial data parameter in `create()` are set, then throw.
|
51
|
-
if (!isElement(sourceElementOrData) && config.initialData !== undefined) {
|
52
|
-
// Documented in core/editor/editorconfig.jsdoc.
|
53
|
-
// eslint-disable-next-line ckeditor5-rules/ckeditor-error-message
|
54
|
-
throw new CKEditorError('editor-create-initial-data', null);
|
55
|
-
}
|
56
|
-
super(config);
|
57
|
-
if (this.config.get('initialData') === undefined) {
|
58
|
-
this.config.set('initialData', getInitialData(sourceElementOrData));
|
59
|
-
}
|
60
|
-
this.model.document.createRoot();
|
61
|
-
if (isElement(sourceElementOrData)) {
|
62
|
-
this.sourceElement = sourceElementOrData;
|
63
|
-
secureSourceElement(this, sourceElementOrData);
|
64
|
-
}
|
65
|
-
const shouldToolbarGroupWhenFull = !this.config.get('toolbar.shouldNotGroupWhenFull');
|
66
|
-
const view = new InlineEditorUIView(this.locale, this.editing.view, this.sourceElement, {
|
67
|
-
shouldToolbarGroupWhenFull
|
68
|
-
});
|
69
|
-
this.ui = new InlineEditorUI(this, view);
|
70
|
-
attachToForm(this);
|
71
|
-
}
|
72
|
-
/**
|
73
|
-
* Destroys the editor instance, releasing all resources used by it.
|
74
|
-
*
|
75
|
-
* Updates the original editor element with the data if the
|
76
|
-
* {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy `updateSourceElementOnDestroy`}
|
77
|
-
* configuration option is set to `true`.
|
78
|
-
*/
|
79
|
-
destroy() {
|
80
|
-
// Cache the data, then destroy.
|
81
|
-
// It's safe to assume that the model->view conversion will not work after super.destroy().
|
82
|
-
const data = this.getData();
|
83
|
-
this.ui.destroy();
|
84
|
-
return super.destroy()
|
85
|
-
.then(() => {
|
86
|
-
if (this.sourceElement) {
|
87
|
-
this.updateSourceElement(data);
|
88
|
-
}
|
89
|
-
});
|
90
|
-
}
|
91
|
-
/**
|
92
|
-
* Creates a new inline editor instance.
|
93
|
-
*
|
94
|
-
* There are three general ways how the editor can be initialized.
|
95
|
-
*
|
96
|
-
* # Using an existing DOM element (and loading data from it)
|
97
|
-
*
|
98
|
-
* You can initialize the editor using an existing DOM element:
|
99
|
-
*
|
100
|
-
* ```ts
|
101
|
-
* InlineEditor
|
102
|
-
* .create( document.querySelector( '#editor' ) )
|
103
|
-
* .then( editor => {
|
104
|
-
* console.log( 'Editor was initialized', editor );
|
105
|
-
* } )
|
106
|
-
* .catch( err => {
|
107
|
-
* console.error( err.stack );
|
108
|
-
* } );
|
109
|
-
* ```
|
110
|
-
*
|
111
|
-
* The element's content will be used as the editor data and the element will become the editable element.
|
112
|
-
*
|
113
|
-
* # Creating a detached editor
|
114
|
-
*
|
115
|
-
* Alternatively, you can initialize the editor by passing the initial data directly as a `String`.
|
116
|
-
* In this case, the editor will render an element that must be inserted into the DOM for the editor to work properly:
|
117
|
-
*
|
118
|
-
* ```ts
|
119
|
-
* InlineEditor
|
120
|
-
* .create( '<p>Hello world!</p>' )
|
121
|
-
* .then( editor => {
|
122
|
-
* console.log( 'Editor was initialized', editor );
|
123
|
-
*
|
124
|
-
* // Initial data was provided so the editor UI element needs to be added manually to the DOM.
|
125
|
-
* document.body.appendChild( editor.ui.element );
|
126
|
-
* } )
|
127
|
-
* .catch( err => {
|
128
|
-
* console.error( err.stack );
|
129
|
-
* } );
|
130
|
-
* ```
|
131
|
-
*
|
132
|
-
* This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
|
133
|
-
* web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
|
134
|
-
*
|
135
|
-
* # Using an existing DOM element (and data provided in `config.initialData`)
|
136
|
-
*
|
137
|
-
* You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
|
138
|
-
*
|
139
|
-
* ```ts
|
140
|
-
* InlineEditor
|
141
|
-
* .create( document.querySelector( '#editor' ), {
|
142
|
-
* initialData: '<h2>Initial data</h2><p>Foo bar.</p>'
|
143
|
-
* } )
|
144
|
-
* .then( editor => {
|
145
|
-
* console.log( 'Editor was initialized', editor );
|
146
|
-
* } )
|
147
|
-
* .catch( err => {
|
148
|
-
* console.error( err.stack );
|
149
|
-
* } );
|
150
|
-
* ```
|
151
|
-
*
|
152
|
-
* This method can be used to initialize the editor on an existing element with the specified content in case if your integration
|
153
|
-
* makes it difficult to set the content of the source element.
|
154
|
-
*
|
155
|
-
* Note that an error will be thrown if you pass the initial data both as the first parameter and also in the configuration.
|
156
|
-
*
|
157
|
-
* # Configuring the editor
|
158
|
-
*
|
159
|
-
* See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
|
160
|
-
* customizing plugins, toolbar and more.
|
161
|
-
*
|
162
|
-
* # Using the editor from source
|
163
|
-
*
|
164
|
-
* The code samples listed in the previous sections of this documentation assume that you are using an
|
165
|
-
* {@glink installation/getting-started/predefined-builds editor build} (for example – `@ckeditor/ckeditor5-build-inline`).
|
166
|
-
*
|
167
|
-
* If you want to use the inline editor from source (`@ckeditor/ckeditor5-editor-inline/src/inlineeditor`),
|
168
|
-
* you need to define the list of
|
169
|
-
* {@link module:core/editor/editorconfig~EditorConfig#plugins plugins to be initialized} and
|
170
|
-
* {@link module:core/editor/editorconfig~EditorConfig#toolbar toolbar items}. Read more about using the editor from
|
171
|
-
* source in the {@glink installation/advanced/alternative-setups/integrating-from-source-webpack dedicated guide}.
|
172
|
-
*
|
173
|
-
* @param sourceElementOrData The DOM element that will be the source for the created editor
|
174
|
-
* or the editor's initial data.
|
175
|
-
*
|
176
|
-
* If a DOM element is passed, its content will be automatically loaded to the editor upon initialization.
|
177
|
-
* The editor data will be set back to the original element once the editor is destroyed only if the
|
178
|
-
* {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy updateSourceElementOnDestroy}
|
179
|
-
* option is set to `true`.
|
180
|
-
*
|
181
|
-
* If the initial data is passed, a detached editor will be created. In this case you need to insert it into the DOM manually.
|
182
|
-
* It is available under the {@link module:editor-inline/inlineeditorui~InlineEditorUI#element `editor.ui.element`} property.
|
183
|
-
*
|
184
|
-
* @param config The editor configuration.
|
185
|
-
* @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
|
186
|
-
*/
|
187
|
-
static create(sourceElementOrData, config = {}) {
|
188
|
-
return new Promise(resolve => {
|
189
|
-
if (isElement(sourceElementOrData) && sourceElementOrData.tagName === 'TEXTAREA') {
|
190
|
-
// Documented in core/editor/editor.js
|
191
|
-
// eslint-disable-next-line ckeditor5-rules/ckeditor-error-message
|
192
|
-
throw new CKEditorError('editor-wrong-element', null);
|
193
|
-
}
|
194
|
-
const editor = new this(sourceElementOrData, config);
|
195
|
-
resolve(editor.initPlugins()
|
196
|
-
.then(() => editor.ui.init())
|
197
|
-
.then(() => editor.data.init(editor.config.get('initialData')))
|
198
|
-
.then(() => editor.fire('ready'))
|
199
|
-
.then(() => editor));
|
200
|
-
});
|
201
|
-
}
|
202
|
-
}
|
203
|
-
/**
|
204
|
-
* The {@link module:core/context~Context} class.
|
205
|
-
*
|
206
|
-
* Exposed as static editor field for easier access in editor builds.
|
207
|
-
*/
|
208
|
-
InlineEditor.Context = Context;
|
209
|
-
/**
|
210
|
-
* The {@link module:watchdog/editorwatchdog~EditorWatchdog} class.
|
211
|
-
*
|
212
|
-
* Exposed as static editor field for easier access in editor builds.
|
213
|
-
*/
|
214
|
-
InlineEditor.EditorWatchdog = EditorWatchdog;
|
215
|
-
/**
|
216
|
-
* The {@link module:watchdog/contextwatchdog~ContextWatchdog} class.
|
217
|
-
*
|
218
|
-
* Exposed as static editor field for easier access in editor builds.
|
219
|
-
*/
|
220
|
-
InlineEditor.ContextWatchdog = ContextWatchdog;
|
221
|
-
function getInitialData(sourceElementOrData) {
|
222
|
-
return isElement(sourceElementOrData) ? getDataFromElement(sourceElementOrData) : sourceElementOrData;
|
223
|
-
}
|
224
|
-
function isElement(value) {
|
225
|
-
return _isElement(value);
|
226
|
-
}
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module editor-inline/inlineeditor
|
7
|
+
*/
|
8
|
+
import { Editor, Context, DataApiMixin, ElementApiMixin, attachToForm, secureSourceElement } from 'ckeditor5/src/core';
|
9
|
+
import { getDataFromElement, CKEditorError } from 'ckeditor5/src/utils';
|
10
|
+
import { ContextWatchdog, EditorWatchdog } from 'ckeditor5/src/watchdog';
|
11
|
+
import InlineEditorUI from './inlineeditorui';
|
12
|
+
import InlineEditorUIView from './inlineeditoruiview';
|
13
|
+
import { isElement as _isElement } from 'lodash-es';
|
14
|
+
/**
|
15
|
+
* The {@glink installation/getting-started/predefined-builds#inline-editor inline editor} implementation.
|
16
|
+
* It uses an inline editable and a floating toolbar.
|
17
|
+
* See the {@glink examples/builds/inline-editor demo}.
|
18
|
+
*
|
19
|
+
* In order to create a inline editor instance, use the static
|
20
|
+
* {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`} method.
|
21
|
+
*
|
22
|
+
* # Inline editor and inline build
|
23
|
+
*
|
24
|
+
* The inline editor can be used directly from source (if you installed the
|
25
|
+
* [`@ckeditor/ckeditor5-editor-inline`](https://www.npmjs.com/package/@ckeditor/ckeditor5-editor-inline) package)
|
26
|
+
* but it is also available in the {@glink installation/getting-started/predefined-builds#inline-editor inline build}.
|
27
|
+
*
|
28
|
+
* {@glink installation/getting-started/predefined-builds Builds}
|
29
|
+
* are ready-to-use editors with plugins bundled in. When using the editor from
|
30
|
+
* source you need to take care of loading all plugins by yourself
|
31
|
+
* (through the {@link module:core/editor/editorconfig~EditorConfig#plugins `config.plugins`} option).
|
32
|
+
* Using the editor from source gives much better flexibility and allows easier customization.
|
33
|
+
*
|
34
|
+
* Read more about initializing the editor from source or as a build in
|
35
|
+
* {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`}.
|
36
|
+
*/
|
37
|
+
export default class InlineEditor extends DataApiMixin(ElementApiMixin(Editor)) {
|
38
|
+
/**
|
39
|
+
* Creates an instance of the inline editor.
|
40
|
+
*
|
41
|
+
* **Note:** Do not use the constructor to create editor instances. Use the static
|
42
|
+
* {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`} method instead.
|
43
|
+
*
|
44
|
+
* @param sourceElementOrData The DOM element that will be the source for the created editor
|
45
|
+
* (on which the editor will be initialized) or initial data for the editor. For more information see
|
46
|
+
* {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`}.
|
47
|
+
* @param config The editor configuration.
|
48
|
+
*/
|
49
|
+
constructor(sourceElementOrData, config = {}) {
|
50
|
+
// If both `config.initialData` and initial data parameter in `create()` are set, then throw.
|
51
|
+
if (!isElement(sourceElementOrData) && config.initialData !== undefined) {
|
52
|
+
// Documented in core/editor/editorconfig.jsdoc.
|
53
|
+
// eslint-disable-next-line ckeditor5-rules/ckeditor-error-message
|
54
|
+
throw new CKEditorError('editor-create-initial-data', null);
|
55
|
+
}
|
56
|
+
super(config);
|
57
|
+
if (this.config.get('initialData') === undefined) {
|
58
|
+
this.config.set('initialData', getInitialData(sourceElementOrData));
|
59
|
+
}
|
60
|
+
this.model.document.createRoot();
|
61
|
+
if (isElement(sourceElementOrData)) {
|
62
|
+
this.sourceElement = sourceElementOrData;
|
63
|
+
secureSourceElement(this, sourceElementOrData);
|
64
|
+
}
|
65
|
+
const shouldToolbarGroupWhenFull = !this.config.get('toolbar.shouldNotGroupWhenFull');
|
66
|
+
const view = new InlineEditorUIView(this.locale, this.editing.view, this.sourceElement, {
|
67
|
+
shouldToolbarGroupWhenFull
|
68
|
+
});
|
69
|
+
this.ui = new InlineEditorUI(this, view);
|
70
|
+
attachToForm(this);
|
71
|
+
}
|
72
|
+
/**
|
73
|
+
* Destroys the editor instance, releasing all resources used by it.
|
74
|
+
*
|
75
|
+
* Updates the original editor element with the data if the
|
76
|
+
* {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy `updateSourceElementOnDestroy`}
|
77
|
+
* configuration option is set to `true`.
|
78
|
+
*/
|
79
|
+
destroy() {
|
80
|
+
// Cache the data, then destroy.
|
81
|
+
// It's safe to assume that the model->view conversion will not work after super.destroy().
|
82
|
+
const data = this.getData();
|
83
|
+
this.ui.destroy();
|
84
|
+
return super.destroy()
|
85
|
+
.then(() => {
|
86
|
+
if (this.sourceElement) {
|
87
|
+
this.updateSourceElement(data);
|
88
|
+
}
|
89
|
+
});
|
90
|
+
}
|
91
|
+
/**
|
92
|
+
* Creates a new inline editor instance.
|
93
|
+
*
|
94
|
+
* There are three general ways how the editor can be initialized.
|
95
|
+
*
|
96
|
+
* # Using an existing DOM element (and loading data from it)
|
97
|
+
*
|
98
|
+
* You can initialize the editor using an existing DOM element:
|
99
|
+
*
|
100
|
+
* ```ts
|
101
|
+
* InlineEditor
|
102
|
+
* .create( document.querySelector( '#editor' ) )
|
103
|
+
* .then( editor => {
|
104
|
+
* console.log( 'Editor was initialized', editor );
|
105
|
+
* } )
|
106
|
+
* .catch( err => {
|
107
|
+
* console.error( err.stack );
|
108
|
+
* } );
|
109
|
+
* ```
|
110
|
+
*
|
111
|
+
* The element's content will be used as the editor data and the element will become the editable element.
|
112
|
+
*
|
113
|
+
* # Creating a detached editor
|
114
|
+
*
|
115
|
+
* Alternatively, you can initialize the editor by passing the initial data directly as a `String`.
|
116
|
+
* In this case, the editor will render an element that must be inserted into the DOM for the editor to work properly:
|
117
|
+
*
|
118
|
+
* ```ts
|
119
|
+
* InlineEditor
|
120
|
+
* .create( '<p>Hello world!</p>' )
|
121
|
+
* .then( editor => {
|
122
|
+
* console.log( 'Editor was initialized', editor );
|
123
|
+
*
|
124
|
+
* // Initial data was provided so the editor UI element needs to be added manually to the DOM.
|
125
|
+
* document.body.appendChild( editor.ui.element );
|
126
|
+
* } )
|
127
|
+
* .catch( err => {
|
128
|
+
* console.error( err.stack );
|
129
|
+
* } );
|
130
|
+
* ```
|
131
|
+
*
|
132
|
+
* This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
|
133
|
+
* web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
|
134
|
+
*
|
135
|
+
* # Using an existing DOM element (and data provided in `config.initialData`)
|
136
|
+
*
|
137
|
+
* You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
|
138
|
+
*
|
139
|
+
* ```ts
|
140
|
+
* InlineEditor
|
141
|
+
* .create( document.querySelector( '#editor' ), {
|
142
|
+
* initialData: '<h2>Initial data</h2><p>Foo bar.</p>'
|
143
|
+
* } )
|
144
|
+
* .then( editor => {
|
145
|
+
* console.log( 'Editor was initialized', editor );
|
146
|
+
* } )
|
147
|
+
* .catch( err => {
|
148
|
+
* console.error( err.stack );
|
149
|
+
* } );
|
150
|
+
* ```
|
151
|
+
*
|
152
|
+
* This method can be used to initialize the editor on an existing element with the specified content in case if your integration
|
153
|
+
* makes it difficult to set the content of the source element.
|
154
|
+
*
|
155
|
+
* Note that an error will be thrown if you pass the initial data both as the first parameter and also in the configuration.
|
156
|
+
*
|
157
|
+
* # Configuring the editor
|
158
|
+
*
|
159
|
+
* See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
|
160
|
+
* customizing plugins, toolbar and more.
|
161
|
+
*
|
162
|
+
* # Using the editor from source
|
163
|
+
*
|
164
|
+
* The code samples listed in the previous sections of this documentation assume that you are using an
|
165
|
+
* {@glink installation/getting-started/predefined-builds editor build} (for example – `@ckeditor/ckeditor5-build-inline`).
|
166
|
+
*
|
167
|
+
* If you want to use the inline editor from source (`@ckeditor/ckeditor5-editor-inline/src/inlineeditor`),
|
168
|
+
* you need to define the list of
|
169
|
+
* {@link module:core/editor/editorconfig~EditorConfig#plugins plugins to be initialized} and
|
170
|
+
* {@link module:core/editor/editorconfig~EditorConfig#toolbar toolbar items}. Read more about using the editor from
|
171
|
+
* source in the {@glink installation/advanced/alternative-setups/integrating-from-source-webpack dedicated guide}.
|
172
|
+
*
|
173
|
+
* @param sourceElementOrData The DOM element that will be the source for the created editor
|
174
|
+
* or the editor's initial data.
|
175
|
+
*
|
176
|
+
* If a DOM element is passed, its content will be automatically loaded to the editor upon initialization.
|
177
|
+
* The editor data will be set back to the original element once the editor is destroyed only if the
|
178
|
+
* {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy updateSourceElementOnDestroy}
|
179
|
+
* option is set to `true`.
|
180
|
+
*
|
181
|
+
* If the initial data is passed, a detached editor will be created. In this case you need to insert it into the DOM manually.
|
182
|
+
* It is available under the {@link module:editor-inline/inlineeditorui~InlineEditorUI#element `editor.ui.element`} property.
|
183
|
+
*
|
184
|
+
* @param config The editor configuration.
|
185
|
+
* @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
|
186
|
+
*/
|
187
|
+
static create(sourceElementOrData, config = {}) {
|
188
|
+
return new Promise(resolve => {
|
189
|
+
if (isElement(sourceElementOrData) && sourceElementOrData.tagName === 'TEXTAREA') {
|
190
|
+
// Documented in core/editor/editor.js
|
191
|
+
// eslint-disable-next-line ckeditor5-rules/ckeditor-error-message
|
192
|
+
throw new CKEditorError('editor-wrong-element', null);
|
193
|
+
}
|
194
|
+
const editor = new this(sourceElementOrData, config);
|
195
|
+
resolve(editor.initPlugins()
|
196
|
+
.then(() => editor.ui.init())
|
197
|
+
.then(() => editor.data.init(editor.config.get('initialData')))
|
198
|
+
.then(() => editor.fire('ready'))
|
199
|
+
.then(() => editor));
|
200
|
+
});
|
201
|
+
}
|
202
|
+
}
|
203
|
+
/**
|
204
|
+
* The {@link module:core/context~Context} class.
|
205
|
+
*
|
206
|
+
* Exposed as static editor field for easier access in editor builds.
|
207
|
+
*/
|
208
|
+
InlineEditor.Context = Context;
|
209
|
+
/**
|
210
|
+
* The {@link module:watchdog/editorwatchdog~EditorWatchdog} class.
|
211
|
+
*
|
212
|
+
* Exposed as static editor field for easier access in editor builds.
|
213
|
+
*/
|
214
|
+
InlineEditor.EditorWatchdog = EditorWatchdog;
|
215
|
+
/**
|
216
|
+
* The {@link module:watchdog/contextwatchdog~ContextWatchdog} class.
|
217
|
+
*
|
218
|
+
* Exposed as static editor field for easier access in editor builds.
|
219
|
+
*/
|
220
|
+
InlineEditor.ContextWatchdog = ContextWatchdog;
|
221
|
+
function getInitialData(sourceElementOrData) {
|
222
|
+
return isElement(sourceElementOrData) ? getDataFromElement(sourceElementOrData) : sourceElementOrData;
|
223
|
+
}
|
224
|
+
function isElement(value) {
|
225
|
+
return _isElement(value);
|
226
|
+
}
|
package/src/inlineeditorui.d.ts
CHANGED
@@ -1,52 +1,52 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
-
*/
|
5
|
-
/**
|
6
|
-
* @module editor-inline/inlineeditorui
|
7
|
-
*/
|
8
|
-
import { type Editor } from 'ckeditor5/src/core';
|
9
|
-
import { EditorUI } from 'ckeditor5/src/ui';
|
10
|
-
import type InlineEditorUIView from './inlineeditoruiview';
|
11
|
-
/**
|
12
|
-
* The inline editor UI class.
|
13
|
-
*
|
14
|
-
* @extends module:ui/editorui/editorui~EditorUI
|
15
|
-
*/
|
16
|
-
export default class InlineEditorUI extends EditorUI {
|
17
|
-
/**
|
18
|
-
* The main (top–most) view of the editor UI.
|
19
|
-
*/
|
20
|
-
readonly view: InlineEditorUIView;
|
21
|
-
/**
|
22
|
-
* A normalized `config.toolbar` object.
|
23
|
-
*/
|
24
|
-
private readonly _toolbarConfig;
|
25
|
-
/**
|
26
|
-
* Creates an instance of the inline editor UI class.
|
27
|
-
*
|
28
|
-
* @param editor The editor instance.
|
29
|
-
* @param view The view of the UI.
|
30
|
-
*/
|
31
|
-
constructor(editor: Editor, view: InlineEditorUIView);
|
32
|
-
/**
|
33
|
-
* @inheritDoc
|
34
|
-
*/
|
35
|
-
get element(): HTMLElement | null;
|
36
|
-
/**
|
37
|
-
* Initializes the UI.
|
38
|
-
*/
|
39
|
-
init(): void;
|
40
|
-
/**
|
41
|
-
* @inheritDoc
|
42
|
-
*/
|
43
|
-
destroy(): void;
|
44
|
-
/**
|
45
|
-
* Initializes the inline editor toolbar and its panel.
|
46
|
-
*/
|
47
|
-
private _initToolbar;
|
48
|
-
/**
|
49
|
-
* Enable the placeholder text on the editing root, if any was configured.
|
50
|
-
*/
|
51
|
-
private _initPlaceholder;
|
52
|
-
}
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module editor-inline/inlineeditorui
|
7
|
+
*/
|
8
|
+
import { type Editor } from 'ckeditor5/src/core';
|
9
|
+
import { EditorUI } from 'ckeditor5/src/ui';
|
10
|
+
import type InlineEditorUIView from './inlineeditoruiview';
|
11
|
+
/**
|
12
|
+
* The inline editor UI class.
|
13
|
+
*
|
14
|
+
* @extends module:ui/editorui/editorui~EditorUI
|
15
|
+
*/
|
16
|
+
export default class InlineEditorUI extends EditorUI {
|
17
|
+
/**
|
18
|
+
* The main (top–most) view of the editor UI.
|
19
|
+
*/
|
20
|
+
readonly view: InlineEditorUIView;
|
21
|
+
/**
|
22
|
+
* A normalized `config.toolbar` object.
|
23
|
+
*/
|
24
|
+
private readonly _toolbarConfig;
|
25
|
+
/**
|
26
|
+
* Creates an instance of the inline editor UI class.
|
27
|
+
*
|
28
|
+
* @param editor The editor instance.
|
29
|
+
* @param view The view of the UI.
|
30
|
+
*/
|
31
|
+
constructor(editor: Editor, view: InlineEditorUIView);
|
32
|
+
/**
|
33
|
+
* @inheritDoc
|
34
|
+
*/
|
35
|
+
get element(): HTMLElement | null;
|
36
|
+
/**
|
37
|
+
* Initializes the UI.
|
38
|
+
*/
|
39
|
+
init(): void;
|
40
|
+
/**
|
41
|
+
* @inheritDoc
|
42
|
+
*/
|
43
|
+
destroy(): void;
|
44
|
+
/**
|
45
|
+
* Initializes the inline editor toolbar and its panel.
|
46
|
+
*/
|
47
|
+
private _initToolbar;
|
48
|
+
/**
|
49
|
+
* Enable the placeholder text on the editing root, if any was configured.
|
50
|
+
*/
|
51
|
+
private _initPlaceholder;
|
52
|
+
}
|