@ckeditor/ckeditor5-ui 35.2.1 → 35.3.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/package.json +31 -23
- package/src/bindings/addkeyboardhandlingforgrid.js +45 -57
- package/src/bindings/clickoutsidehandler.js +15 -21
- package/src/bindings/injectcsstransitiondisabler.js +16 -20
- package/src/bindings/preventdefault.js +6 -8
- package/src/bindings/submithandler.js +5 -7
- package/src/button/button.js +5 -0
- package/src/button/buttonview.js +220 -259
- package/src/button/switchbuttonview.js +56 -71
- package/src/colorgrid/colorgridview.js +135 -197
- package/src/colorgrid/colortileview.js +37 -47
- package/src/colorgrid/utils.js +57 -66
- package/src/componentfactory.js +79 -93
- package/src/dropdown/button/dropdownbutton.js +5 -0
- package/src/dropdown/button/dropdownbuttonview.js +44 -57
- package/src/dropdown/button/splitbuttonview.js +159 -207
- package/src/dropdown/dropdownpanelfocusable.js +5 -0
- package/src/dropdown/dropdownpanelview.js +101 -112
- package/src/dropdown/dropdownview.js +396 -438
- package/src/dropdown/utils.js +164 -213
- package/src/editableui/editableuiview.js +125 -141
- package/src/editableui/inline/inlineeditableuiview.js +44 -54
- package/src/editorui/bodycollection.js +61 -75
- package/src/editorui/boxed/boxededitoruiview.js +91 -104
- package/src/editorui/editoruiview.js +30 -39
- package/src/focuscycler.js +214 -245
- package/src/formheader/formheaderview.js +58 -70
- package/src/icon/iconview.js +145 -111
- package/src/iframe/iframeview.js +37 -49
- package/src/index.js +0 -17
- package/src/input/inputview.js +170 -198
- package/src/inputnumber/inputnumberview.js +48 -56
- package/src/inputtext/inputtextview.js +14 -18
- package/src/label/labelview.js +44 -53
- package/src/labeledfield/labeledfieldview.js +212 -235
- package/src/labeledfield/utils.js +39 -57
- package/src/labeledinput/labeledinputview.js +190 -221
- package/src/list/listitemview.js +40 -50
- package/src/list/listseparatorview.js +15 -19
- package/src/list/listview.js +94 -115
- package/src/model.js +19 -25
- package/src/notification/notification.js +151 -202
- package/src/panel/balloon/balloonpanelview.js +535 -628
- package/src/panel/balloon/contextualballoon.js +611 -732
- package/src/panel/sticky/stickypanelview.js +238 -270
- package/src/template.js +1049 -1479
- package/src/toolbar/balloon/balloontoolbar.js +337 -424
- package/src/toolbar/block/blockbuttonview.js +32 -42
- package/src/toolbar/block/blocktoolbar.js +375 -477
- package/src/toolbar/normalizetoolbarconfig.js +17 -21
- package/src/toolbar/toolbarlinebreakview.js +15 -19
- package/src/toolbar/toolbarseparatorview.js +15 -19
- package/src/toolbar/toolbarview.js +866 -1053
- package/src/tooltipmanager.js +324 -353
- package/src/view.js +389 -430
- package/src/viewcollection.js +147 -178
- package/src/button/button.jsdoc +0 -165
- package/src/dropdown/button/dropdownbutton.jsdoc +0 -22
- package/src/dropdown/dropdownpanelfocusable.jsdoc +0 -27
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module ui/toolbar/balloon/balloontoolbar
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
11
9
|
import ContextualBalloon from '../../panel/balloon/contextualballoon';
|
|
12
10
|
import ToolbarView from '../toolbarview';
|
|
13
|
-
import BalloonPanelView, { generatePositions } from '../../panel/balloon/balloonpanelview
|
|
11
|
+
import BalloonPanelView, { generatePositions } from '../../panel/balloon/balloonpanelview';
|
|
14
12
|
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
|
|
15
13
|
import Rect from '@ckeditor/ckeditor5-utils/src/dom/rect';
|
|
16
14
|
import normalizeToolbarConfig from '../normalizetoolbarconfig';
|
|
@@ -18,9 +16,7 @@ import { debounce } from 'lodash-es';
|
|
|
18
16
|
import ResizeObserver from '@ckeditor/ckeditor5-utils/src/dom/resizeobserver';
|
|
19
17
|
import toUnit from '@ckeditor/ckeditor5-utils/src/dom/tounit';
|
|
20
18
|
import { env, global } from '@ckeditor/ckeditor5-utils';
|
|
21
|
-
|
|
22
|
-
const toPx = toUnit( 'px' );
|
|
23
|
-
|
|
19
|
+
const toPx = toUnit('px');
|
|
24
20
|
/**
|
|
25
21
|
* The contextual toolbar.
|
|
26
22
|
*
|
|
@@ -29,382 +25,333 @@ const toPx = toUnit( 'px' );
|
|
|
29
25
|
* @extends module:core/plugin~Plugin
|
|
30
26
|
*/
|
|
31
27
|
export default class BalloonToolbar extends Plugin {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
* @protected
|
|
359
|
-
* @event _selectionChangeDebounced
|
|
360
|
-
*/
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Returns toolbar positions for the given direction of the selection.
|
|
364
|
-
*
|
|
365
|
-
* @private
|
|
366
|
-
* @param {Boolean} isBackward
|
|
367
|
-
* @returns {Array.<module:utils/dom/position~Position>}
|
|
368
|
-
*/
|
|
369
|
-
_getBalloonPositions( isBackward ) {
|
|
370
|
-
const isSafariIniOS = env.isSafari && env.isiOS;
|
|
371
|
-
|
|
372
|
-
// https://github.com/ckeditor/ckeditor5/issues/7707
|
|
373
|
-
const positions = isSafariIniOS ? generatePositions( {
|
|
374
|
-
// 20px when zoomed out. Less then 20px when zoomed in; the "radius" of the native selection handle gets
|
|
375
|
-
// smaller as the user zooms in. No less than the default v-offset, though.
|
|
376
|
-
heightOffset: Math.max(
|
|
377
|
-
BalloonPanelView.arrowHeightOffset,
|
|
378
|
-
Math.round( 20 / global.window.visualViewport.scale )
|
|
379
|
-
)
|
|
380
|
-
} ) : BalloonPanelView.defaultPositions;
|
|
381
|
-
|
|
382
|
-
return isBackward ? [
|
|
383
|
-
positions.northWestArrowSouth,
|
|
384
|
-
positions.northWestArrowSouthWest,
|
|
385
|
-
positions.northWestArrowSouthEast,
|
|
386
|
-
positions.northWestArrowSouthMiddleEast,
|
|
387
|
-
positions.northWestArrowSouthMiddleWest,
|
|
388
|
-
positions.southWestArrowNorth,
|
|
389
|
-
positions.southWestArrowNorthWest,
|
|
390
|
-
positions.southWestArrowNorthEast,
|
|
391
|
-
positions.southWestArrowNorthMiddleWest,
|
|
392
|
-
positions.southWestArrowNorthMiddleEast
|
|
393
|
-
] : [
|
|
394
|
-
positions.southEastArrowNorth,
|
|
395
|
-
positions.southEastArrowNorthEast,
|
|
396
|
-
positions.southEastArrowNorthWest,
|
|
397
|
-
positions.southEastArrowNorthMiddleEast,
|
|
398
|
-
positions.southEastArrowNorthMiddleWest,
|
|
399
|
-
positions.northEastArrowSouth,
|
|
400
|
-
positions.northEastArrowSouthEast,
|
|
401
|
-
positions.northEastArrowSouthWest,
|
|
402
|
-
positions.northEastArrowSouthMiddleEast,
|
|
403
|
-
positions.northEastArrowSouthMiddleWest
|
|
404
|
-
];
|
|
405
|
-
}
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
constructor(editor) {
|
|
32
|
+
super(editor);
|
|
33
|
+
/**
|
|
34
|
+
* A cached and normalized `config.balloonToolbar` object.
|
|
35
|
+
*
|
|
36
|
+
* @type {module:core/editor/editorconfig~EditorConfig#balloonToolbar}
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
this._balloonConfig = normalizeToolbarConfig(editor.config.get('balloonToolbar'));
|
|
40
|
+
/**
|
|
41
|
+
* The toolbar view displayed in the balloon.
|
|
42
|
+
*
|
|
43
|
+
* @type {module:ui/toolbar/toolbarview~ToolbarView}
|
|
44
|
+
*/
|
|
45
|
+
this.toolbarView = this._createToolbarView();
|
|
46
|
+
/**
|
|
47
|
+
* Tracks the focus of the {@link module:core/editor/editorui~EditorUI#getEditableElement editable element}
|
|
48
|
+
* and the {@link #toolbarView}. When both are blurred then the toolbar should hide.
|
|
49
|
+
*
|
|
50
|
+
* @readonly
|
|
51
|
+
* @type {module:utils:focustracker~FocusTracker}
|
|
52
|
+
*/
|
|
53
|
+
this.focusTracker = new FocusTracker();
|
|
54
|
+
// Wait for the EditorUI#init. EditableElement is not available before.
|
|
55
|
+
editor.ui.once('ready', () => {
|
|
56
|
+
this.focusTracker.add(editor.ui.getEditableElement());
|
|
57
|
+
this.focusTracker.add(this.toolbarView.element);
|
|
58
|
+
});
|
|
59
|
+
// Register the toolbar so it becomes available for Alt+F10 and Esc navigation.
|
|
60
|
+
editor.ui.addToolbar(this.toolbarView, {
|
|
61
|
+
beforeFocus: () => this.show(true),
|
|
62
|
+
afterBlur: () => this.hide(),
|
|
63
|
+
isContextual: true
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* An instance of the resize observer that allows to respond to changes in editable's geometry
|
|
67
|
+
* so the toolbar can stay within its boundaries (and group toolbar items that do not fit).
|
|
68
|
+
*
|
|
69
|
+
* **Note**: Used only when `shouldNotGroupWhenFull` was **not** set in the
|
|
70
|
+
* {@link module:core/editor/editorconfig~EditorConfig#balloonToolbar configuration}.
|
|
71
|
+
*
|
|
72
|
+
* **Note:** Created in {@link #init}.
|
|
73
|
+
*
|
|
74
|
+
* @protected
|
|
75
|
+
* @member {module:utils/dom/resizeobserver~ResizeObserver}
|
|
76
|
+
*/
|
|
77
|
+
this._resizeObserver = null;
|
|
78
|
+
/**
|
|
79
|
+
* The contextual balloon plugin instance.
|
|
80
|
+
*
|
|
81
|
+
* @private
|
|
82
|
+
* @type {module:ui/panel/balloon/contextualballoon~ContextualBalloon}
|
|
83
|
+
*/
|
|
84
|
+
this._balloon = editor.plugins.get(ContextualBalloon);
|
|
85
|
+
/**
|
|
86
|
+
* Fires {@link #event:_selectionChangeDebounced} event using `lodash#debounce`.
|
|
87
|
+
*
|
|
88
|
+
* This function is stored as a plugin property to make possible to cancel
|
|
89
|
+
* trailing debounced invocation on destroy.
|
|
90
|
+
*
|
|
91
|
+
* @private
|
|
92
|
+
* @type {Function}
|
|
93
|
+
*/
|
|
94
|
+
this._fireSelectionChangeDebounced = debounce(() => this.fire('_selectionChangeDebounced'), 200);
|
|
95
|
+
// The appearance of the BalloonToolbar method is event–driven.
|
|
96
|
+
// It is possible to stop the #show event and this prevent the toolbar from showing up.
|
|
97
|
+
this.decorate('show');
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @inheritDoc
|
|
101
|
+
*/
|
|
102
|
+
static get pluginName() {
|
|
103
|
+
return 'BalloonToolbar';
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @inheritDoc
|
|
107
|
+
*/
|
|
108
|
+
static get requires() {
|
|
109
|
+
return [ContextualBalloon];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @inheritDoc
|
|
113
|
+
*/
|
|
114
|
+
init() {
|
|
115
|
+
const editor = this.editor;
|
|
116
|
+
const selection = editor.model.document.selection;
|
|
117
|
+
// Show/hide the toolbar on editable focus/blur.
|
|
118
|
+
this.listenTo(this.focusTracker, 'change:isFocused', (evt, name, isFocused) => {
|
|
119
|
+
const isToolbarVisible = this._balloon.visibleView === this.toolbarView;
|
|
120
|
+
if (!isFocused && isToolbarVisible) {
|
|
121
|
+
this.hide();
|
|
122
|
+
}
|
|
123
|
+
else if (isFocused) {
|
|
124
|
+
this.show();
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
// Hide the toolbar when the selection is changed by a direct change or has changed to collapsed.
|
|
128
|
+
this.listenTo(selection, 'change:range', (evt, data) => {
|
|
129
|
+
if (data.directChange || selection.isCollapsed) {
|
|
130
|
+
this.hide();
|
|
131
|
+
}
|
|
132
|
+
// Fire internal `_selectionChangeDebounced` event to use it for showing
|
|
133
|
+
// the toolbar after the selection stops changing.
|
|
134
|
+
this._fireSelectionChangeDebounced();
|
|
135
|
+
});
|
|
136
|
+
// Show the toolbar when the selection stops changing.
|
|
137
|
+
this.listenTo(this, '_selectionChangeDebounced', () => {
|
|
138
|
+
if (this.editor.editing.view.document.isFocused) {
|
|
139
|
+
this.show();
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
if (!this._balloonConfig.shouldNotGroupWhenFull) {
|
|
143
|
+
this.listenTo(editor, 'ready', () => {
|
|
144
|
+
const editableElement = editor.ui.view.editable.element;
|
|
145
|
+
// Set #toolbarView's max-width on the initialization and update it on the editable resize.
|
|
146
|
+
this._resizeObserver = new ResizeObserver(editableElement, () => {
|
|
147
|
+
// The max-width equals 90% of the editable's width for the best user experience.
|
|
148
|
+
// The value keeps the balloon very close to the boundaries of the editable and limits the cases
|
|
149
|
+
// when the balloon juts out from the editable element it belongs to.
|
|
150
|
+
this.toolbarView.maxWidth = toPx(new Rect(editableElement).width * .9);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
// Listen to the toolbar view and whenever it changes its geometry due to some items being
|
|
155
|
+
// grouped or ungrouped, update the position of the balloon because a shorter/longer toolbar
|
|
156
|
+
// means the balloon could be pointing at the wrong place. Once updated, the balloon will point
|
|
157
|
+
// at the right selection in the content again.
|
|
158
|
+
// https://github.com/ckeditor/ckeditor5/issues/6444
|
|
159
|
+
this.listenTo(this.toolbarView, 'groupedItemsUpdate', () => {
|
|
160
|
+
this._updatePosition();
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Creates toolbar components based on given configuration.
|
|
165
|
+
* This needs to be done when all plugins are ready.
|
|
166
|
+
*
|
|
167
|
+
* @inheritDoc
|
|
168
|
+
*/
|
|
169
|
+
afterInit() {
|
|
170
|
+
const factory = this.editor.ui.componentFactory;
|
|
171
|
+
this.toolbarView.fillFromConfig(this._balloonConfig, factory);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Creates the toolbar view instance.
|
|
175
|
+
*
|
|
176
|
+
* @private
|
|
177
|
+
* @returns {module:ui/toolbar/toolbarview~ToolbarView}
|
|
178
|
+
*/
|
|
179
|
+
_createToolbarView() {
|
|
180
|
+
const t = this.editor.locale.t;
|
|
181
|
+
const shouldGroupWhenFull = !this._balloonConfig.shouldNotGroupWhenFull;
|
|
182
|
+
const toolbarView = new ToolbarView(this.editor.locale, {
|
|
183
|
+
shouldGroupWhenFull,
|
|
184
|
+
isFloating: true
|
|
185
|
+
});
|
|
186
|
+
toolbarView.ariaLabel = t('Editor contextual toolbar');
|
|
187
|
+
toolbarView.render();
|
|
188
|
+
return toolbarView;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Shows the toolbar and attaches it to the selection.
|
|
192
|
+
*
|
|
193
|
+
* Fires {@link #event:show} event which can be stopped to prevent the toolbar from showing up.
|
|
194
|
+
*
|
|
195
|
+
* @param {Boolean} [showForCollapsedSelection=false] When set `true`, the toolbar will show despite collapsed selection in the
|
|
196
|
+
* editing view.
|
|
197
|
+
*/
|
|
198
|
+
show(showForCollapsedSelection = false) {
|
|
199
|
+
const editor = this.editor;
|
|
200
|
+
const selection = editor.model.document.selection;
|
|
201
|
+
const schema = editor.model.schema;
|
|
202
|
+
// Do not add the toolbar to the balloon stack twice.
|
|
203
|
+
if (this._balloon.hasView(this.toolbarView)) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
// Do not show the toolbar when the selection is collapsed.
|
|
207
|
+
if (selection.isCollapsed && !showForCollapsedSelection) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
// Do not show the toolbar when there is more than one range in the selection and they fully contain selectable elements.
|
|
211
|
+
// See https://github.com/ckeditor/ckeditor5/issues/6443.
|
|
212
|
+
if (selectionContainsOnlyMultipleSelectables(selection, schema)) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
// Don not show the toolbar when all components inside are disabled
|
|
216
|
+
// see https://github.com/ckeditor/ckeditor5-ui/issues/269.
|
|
217
|
+
if (Array.from(this.toolbarView.items).every((item) => item.isEnabled !== undefined && !item.isEnabled)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
// Update the toolbar position when the editor ui should be refreshed.
|
|
221
|
+
this.listenTo(this.editor.ui, 'update', () => {
|
|
222
|
+
this._updatePosition();
|
|
223
|
+
});
|
|
224
|
+
// Add the toolbar to the common editor contextual balloon.
|
|
225
|
+
this._balloon.add({
|
|
226
|
+
view: this.toolbarView,
|
|
227
|
+
position: this._getBalloonPositionData(),
|
|
228
|
+
balloonClassName: 'ck-toolbar-container'
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Hides the toolbar.
|
|
233
|
+
*/
|
|
234
|
+
hide() {
|
|
235
|
+
if (this._balloon.hasView(this.toolbarView)) {
|
|
236
|
+
this.stopListening(this.editor.ui, 'update');
|
|
237
|
+
this._balloon.remove(this.toolbarView);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Returns positioning options for the {@link #_balloon}. They control the way balloon is attached
|
|
242
|
+
* to the selection.
|
|
243
|
+
*
|
|
244
|
+
* @private
|
|
245
|
+
* @returns {module:utils/dom/position~Options}
|
|
246
|
+
*/
|
|
247
|
+
_getBalloonPositionData() {
|
|
248
|
+
const editor = this.editor;
|
|
249
|
+
const view = editor.editing.view;
|
|
250
|
+
const viewDocument = view.document;
|
|
251
|
+
const viewSelection = viewDocument.selection;
|
|
252
|
+
// Get direction of the selection.
|
|
253
|
+
const isBackward = viewDocument.selection.isBackward;
|
|
254
|
+
return {
|
|
255
|
+
// Because the target for BalloonPanelView is a Rect (not DOMRange), it's geometry will stay fixed
|
|
256
|
+
// as the window scrolls. To let the BalloonPanelView follow such Rect, is must be continuously
|
|
257
|
+
// computed and hence, the target is defined as a function instead of a static value.
|
|
258
|
+
// https://github.com/ckeditor/ckeditor5-ui/issues/195
|
|
259
|
+
target: () => {
|
|
260
|
+
const range = isBackward ? viewSelection.getFirstRange() : viewSelection.getLastRange();
|
|
261
|
+
const rangeRects = Rect.getDomRangeRects(view.domConverter.viewRangeToDom(range));
|
|
262
|
+
// Select the proper range rect depending on the direction of the selection.
|
|
263
|
+
if (isBackward) {
|
|
264
|
+
return rangeRects[0];
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
// Ditch the zero-width "orphan" rect in the next line for the forward selection if there's
|
|
268
|
+
// another one preceding it. It is not rendered as a selection by the web browser anyway.
|
|
269
|
+
// https://github.com/ckeditor/ckeditor5-ui/issues/308
|
|
270
|
+
if (rangeRects.length > 1 && rangeRects[rangeRects.length - 1].width === 0) {
|
|
271
|
+
rangeRects.pop();
|
|
272
|
+
}
|
|
273
|
+
return rangeRects[rangeRects.length - 1];
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
positions: this._getBalloonPositions(isBackward)
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Updates the position of the {@link #_balloon} to make up for changes:
|
|
281
|
+
*
|
|
282
|
+
* * in the geometry of the selection it is attached to (e.g. the selection moved in the viewport or expanded or shrunk),
|
|
283
|
+
* * or the geometry of the balloon toolbar itself (e.g. the toolbar has grouped or ungrouped some items and it is shorter or longer).
|
|
284
|
+
*
|
|
285
|
+
* @private
|
|
286
|
+
*/
|
|
287
|
+
_updatePosition() {
|
|
288
|
+
this._balloon.updatePosition(this._getBalloonPositionData());
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* @inheritDoc
|
|
292
|
+
*/
|
|
293
|
+
destroy() {
|
|
294
|
+
super.destroy();
|
|
295
|
+
this.stopListening();
|
|
296
|
+
this._fireSelectionChangeDebounced.cancel();
|
|
297
|
+
this.toolbarView.destroy();
|
|
298
|
+
this.focusTracker.destroy();
|
|
299
|
+
if (this._resizeObserver) {
|
|
300
|
+
this._resizeObserver.destroy();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* This event is fired just before the toolbar shows up. Stopping this event will prevent this.
|
|
305
|
+
*
|
|
306
|
+
* @event show
|
|
307
|
+
*/
|
|
308
|
+
/**
|
|
309
|
+
* This is internal plugin event which is fired 200 ms after model selection last change.
|
|
310
|
+
* This is to makes easy test debounced action without need to use `setTimeout`.
|
|
311
|
+
*
|
|
312
|
+
* @protected
|
|
313
|
+
* @event _selectionChangeDebounced
|
|
314
|
+
*/
|
|
315
|
+
/**
|
|
316
|
+
* Returns toolbar positions for the given direction of the selection.
|
|
317
|
+
*
|
|
318
|
+
* @private
|
|
319
|
+
* @param {Boolean} isBackward
|
|
320
|
+
* @returns {Array.<module:utils/dom/position~Position>}
|
|
321
|
+
*/
|
|
322
|
+
_getBalloonPositions(isBackward) {
|
|
323
|
+
const isSafariIniOS = env.isSafari && env.isiOS;
|
|
324
|
+
// https://github.com/ckeditor/ckeditor5/issues/7707
|
|
325
|
+
const positions = isSafariIniOS ? generatePositions({
|
|
326
|
+
// 20px when zoomed out. Less then 20px when zoomed in; the "radius" of the native selection handle gets
|
|
327
|
+
// smaller as the user zooms in. No less than the default v-offset, though.
|
|
328
|
+
heightOffset: Math.max(BalloonPanelView.arrowHeightOffset, Math.round(20 / global.window.visualViewport.scale))
|
|
329
|
+
}) : BalloonPanelView.defaultPositions;
|
|
330
|
+
return isBackward ? [
|
|
331
|
+
positions.northWestArrowSouth,
|
|
332
|
+
positions.northWestArrowSouthWest,
|
|
333
|
+
positions.northWestArrowSouthEast,
|
|
334
|
+
positions.northWestArrowSouthMiddleEast,
|
|
335
|
+
positions.northWestArrowSouthMiddleWest,
|
|
336
|
+
positions.southWestArrowNorth,
|
|
337
|
+
positions.southWestArrowNorthWest,
|
|
338
|
+
positions.southWestArrowNorthEast,
|
|
339
|
+
positions.southWestArrowNorthMiddleWest,
|
|
340
|
+
positions.southWestArrowNorthMiddleEast
|
|
341
|
+
] : [
|
|
342
|
+
positions.southEastArrowNorth,
|
|
343
|
+
positions.southEastArrowNorthEast,
|
|
344
|
+
positions.southEastArrowNorthWest,
|
|
345
|
+
positions.southEastArrowNorthMiddleEast,
|
|
346
|
+
positions.southEastArrowNorthMiddleWest,
|
|
347
|
+
positions.northEastArrowSouth,
|
|
348
|
+
positions.northEastArrowSouthEast,
|
|
349
|
+
positions.northEastArrowSouthWest,
|
|
350
|
+
positions.northEastArrowSouthMiddleEast,
|
|
351
|
+
positions.northEastArrowSouthMiddleWest
|
|
352
|
+
];
|
|
353
|
+
}
|
|
406
354
|
}
|
|
407
|
-
|
|
408
355
|
// Returns "true" when the selection has multiple ranges and each range contains a selectable element
|
|
409
356
|
// and nothing else.
|
|
410
357
|
//
|
|
@@ -412,47 +359,13 @@ export default class BalloonToolbar extends Plugin {
|
|
|
412
359
|
// @param {module:engine/model/selection~Selection} selection
|
|
413
360
|
// @param {module:engine/model/schema~Schema} schema
|
|
414
361
|
// @returns {Boolean}
|
|
415
|
-
function selectionContainsOnlyMultipleSelectables(
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
return element && schema.isSelectable( element );
|
|
425
|
-
} );
|
|
362
|
+
function selectionContainsOnlyMultipleSelectables(selection, schema) {
|
|
363
|
+
// It doesn't contain multiple objects if there is only one range.
|
|
364
|
+
if (selection.rangeCount === 1) {
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
return [...selection.getRanges()].every(range => {
|
|
368
|
+
const element = range.getContainedElement();
|
|
369
|
+
return element && schema.isSelectable(element);
|
|
370
|
+
});
|
|
426
371
|
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Contextual toolbar configuration. Used by the {@link module:ui/toolbar/balloon/balloontoolbar~BalloonToolbar}
|
|
430
|
-
* feature.
|
|
431
|
-
*
|
|
432
|
-
* ## Configuring toolbar items
|
|
433
|
-
*
|
|
434
|
-
* const config = {
|
|
435
|
-
* balloonToolbar: [ 'bold', 'italic', 'undo', 'redo' ]
|
|
436
|
-
* };
|
|
437
|
-
*
|
|
438
|
-
* You can also use `'|'` to create a separator between groups of items:
|
|
439
|
-
*
|
|
440
|
-
* const config = {
|
|
441
|
-
* balloonToolbar: [ 'bold', 'italic', '|', 'undo', 'redo' ]
|
|
442
|
-
* };
|
|
443
|
-
*
|
|
444
|
-
* Read also about configuring the main editor toolbar in {@link module:core/editor/editorconfig~EditorConfig#toolbar}.
|
|
445
|
-
*
|
|
446
|
-
* ## Configuring items grouping
|
|
447
|
-
*
|
|
448
|
-
* You can prevent automatic items grouping by setting the `shouldNotGroupWhenFull` option:
|
|
449
|
-
*
|
|
450
|
-
* const config = {
|
|
451
|
-
* balloonToolbar: {
|
|
452
|
-
* items: [ 'bold', 'italic', 'undo', 'redo' ],
|
|
453
|
-
* shouldNotGroupWhenFull: true
|
|
454
|
-
* },
|
|
455
|
-
* };
|
|
456
|
-
*
|
|
457
|
-
* @member {Array.<String>|Object} module:core/editor/editorconfig~EditorConfig#balloonToolbar
|
|
458
|
-
*/
|