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