@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
package/src/tooltipmanager.js
CHANGED
|
@@ -2,22 +2,16 @@
|
|
|
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/tooltipmanager
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import View from './view';
|
|
11
9
|
import BalloonPanelView, { generatePositions } from './panel/balloon/balloonpanelview';
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
import { global, isVisible, mix, first } from '@ckeditor/ckeditor5-utils';
|
|
10
|
+
import { Emitter as DomEmitter } from '@ckeditor/ckeditor5-utils/src/dom/emittermixin';
|
|
11
|
+
import { global, isVisible, first, ResizeObserver } from '@ckeditor/ckeditor5-utils';
|
|
15
12
|
import { isElement, debounce } from 'lodash-es';
|
|
16
|
-
|
|
17
13
|
import '../theme/components/tooltip/tooltip.css';
|
|
18
|
-
|
|
19
14
|
const BALLOON_CLASS = 'ck-tooltip';
|
|
20
|
-
|
|
21
15
|
/**
|
|
22
16
|
* A tooltip manager class for the UI of the editor.
|
|
23
17
|
*
|
|
@@ -65,324 +59,306 @@ const BALLOON_CLASS = 'ck-tooltip';
|
|
|
65
59
|
*
|
|
66
60
|
* @mixes module:utils/domemittermixin~DomEmitterMixin
|
|
67
61
|
*/
|
|
68
|
-
export default class TooltipManager {
|
|
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
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return {
|
|
369
|
-
// South is most popular. We can use positioning heuristics to avoid clipping by the viewport with the sane fallback.
|
|
370
|
-
s: [
|
|
371
|
-
defaultPositions.southArrowNorth,
|
|
372
|
-
defaultPositions.southArrowNorthEast,
|
|
373
|
-
defaultPositions.southArrowNorthWest
|
|
374
|
-
],
|
|
375
|
-
n: [ defaultPositions.northArrowSouth ],
|
|
376
|
-
e: [ defaultPositions.eastArrowWest ],
|
|
377
|
-
w: [ defaultPositions.westArrowEast ],
|
|
378
|
-
sw: [ defaultPositions.southArrowNorthEast ],
|
|
379
|
-
se: [ defaultPositions.southArrowNorthWest ]
|
|
380
|
-
}[ position ];
|
|
381
|
-
}
|
|
62
|
+
export default class TooltipManager extends DomEmitter {
|
|
63
|
+
/**
|
|
64
|
+
* Creates an instance of the tooltip manager.
|
|
65
|
+
*
|
|
66
|
+
* @param {module:core/editor/editor~Editor} editor
|
|
67
|
+
*/
|
|
68
|
+
constructor(editor) {
|
|
69
|
+
super();
|
|
70
|
+
TooltipManager._editors.add(editor);
|
|
71
|
+
// TooltipManager must be a singleton. Multiple instances would mean multiple tooltips attached
|
|
72
|
+
// to the same DOM element with data-cke-tooltip-* attributes.
|
|
73
|
+
if (TooltipManager._instance) {
|
|
74
|
+
return TooltipManager._instance;
|
|
75
|
+
}
|
|
76
|
+
TooltipManager._instance = this;
|
|
77
|
+
/**
|
|
78
|
+
* The view rendering text of the tooltip.
|
|
79
|
+
*
|
|
80
|
+
* @readonly
|
|
81
|
+
* @member {module:ui/view~View} #tooltipTextView
|
|
82
|
+
*/
|
|
83
|
+
this.tooltipTextView = new View(editor.locale);
|
|
84
|
+
this.tooltipTextView.set('text', '');
|
|
85
|
+
this.tooltipTextView.setTemplate({
|
|
86
|
+
tag: 'span',
|
|
87
|
+
attributes: {
|
|
88
|
+
class: [
|
|
89
|
+
'ck',
|
|
90
|
+
'ck-tooltip__text'
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
children: [
|
|
94
|
+
{
|
|
95
|
+
text: this.tooltipTextView.bindTemplate.to('text')
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
});
|
|
99
|
+
/**
|
|
100
|
+
* The instance of the balloon panel that renders and positions the tooltip.
|
|
101
|
+
*
|
|
102
|
+
* @readonly
|
|
103
|
+
* @member {module:ui/panel/balloon/balloonpanelview~BalloonPanelView} #balloonPanelView
|
|
104
|
+
*/
|
|
105
|
+
this.balloonPanelView = new BalloonPanelView(editor.locale);
|
|
106
|
+
this.balloonPanelView.class = BALLOON_CLASS;
|
|
107
|
+
this.balloonPanelView.content.add(this.tooltipTextView);
|
|
108
|
+
/**
|
|
109
|
+
* An instance of the resize observer that keeps track on target element visibility,
|
|
110
|
+
* when it hides the tooltip should also disappear.
|
|
111
|
+
*
|
|
112
|
+
* {@link module:core/editor/editorconfig~EditorConfig#balloonToolbar configuration}.
|
|
113
|
+
*
|
|
114
|
+
* @protected
|
|
115
|
+
* @member {module:utils/dom/resizeobserver~ResizeObserver|null}
|
|
116
|
+
*
|
|
117
|
+
*/
|
|
118
|
+
this._resizeObserver = null;
|
|
119
|
+
/**
|
|
120
|
+
* Stores the reference to the DOM element the tooltip is attached to. `null` when there's no tooltip
|
|
121
|
+
* in the UI.
|
|
122
|
+
*
|
|
123
|
+
* @private
|
|
124
|
+
* @readonly
|
|
125
|
+
* @member {HTMLElement|null} #_currentElementWithTooltip
|
|
126
|
+
*/
|
|
127
|
+
this._currentElementWithTooltip = null;
|
|
128
|
+
/**
|
|
129
|
+
* Stores the current tooltip position. `null` when there's no tooltip in the UI.
|
|
130
|
+
*
|
|
131
|
+
* @private
|
|
132
|
+
* @readonly
|
|
133
|
+
* @member {String|null} #_currentTooltipPosition
|
|
134
|
+
*/
|
|
135
|
+
this._currentTooltipPosition = null;
|
|
136
|
+
/**
|
|
137
|
+
* A debounced version of {@link #_pinTooltip}. Tooltips show with a delay to avoid flashing and
|
|
138
|
+
* to improve the UX.
|
|
139
|
+
*
|
|
140
|
+
* @private
|
|
141
|
+
* @readonly
|
|
142
|
+
* @member {Function} #_pinTooltipDebounced
|
|
143
|
+
*/
|
|
144
|
+
this._pinTooltipDebounced = debounce(this._pinTooltip, 600);
|
|
145
|
+
this.listenTo(global.document, 'mouseenter', this._onEnterOrFocus.bind(this), { useCapture: true });
|
|
146
|
+
this.listenTo(global.document, 'mouseleave', this._onLeaveOrBlur.bind(this), { useCapture: true });
|
|
147
|
+
this.listenTo(global.document, 'focus', this._onEnterOrFocus.bind(this), { useCapture: true });
|
|
148
|
+
this.listenTo(global.document, 'blur', this._onLeaveOrBlur.bind(this), { useCapture: true });
|
|
149
|
+
this.listenTo(global.document, 'scroll', this._onScroll.bind(this), { useCapture: true });
|
|
150
|
+
// Because this class is a singleton, its only instance is shared across all editors and connects them through the reference.
|
|
151
|
+
// This causes issues with the ContextWatchdog. When an error is thrown in one editor, the watchdog traverses the references
|
|
152
|
+
// and (because of shared tooltip manager) figures that the error affects all editors and restarts them all.
|
|
153
|
+
// This flag, excludes tooltip manager instance from the traversal and brings ContextWatchdog back to normal.
|
|
154
|
+
// More in https://github.com/ckeditor/ckeditor5/issues/12292.
|
|
155
|
+
this._watchdogExcluded = true;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Destroys the tooltip manager.
|
|
159
|
+
*
|
|
160
|
+
* **Note**: The manager singleton cannot be destroyed until all editors that use it are destroyed.
|
|
161
|
+
*
|
|
162
|
+
* @param {module:core/editor/editor~Editor} editor The editor the manager was created for.
|
|
163
|
+
*/
|
|
164
|
+
destroy(editor) {
|
|
165
|
+
const editorBodyViewCollection = editor.ui.view && editor.ui.view.body;
|
|
166
|
+
TooltipManager._editors.delete(editor);
|
|
167
|
+
this.stopListening(editor.ui);
|
|
168
|
+
// Prevent the balloon panel from being destroyed in the EditorUI#destroy() cascade. It should be destroyed along
|
|
169
|
+
// with the last editor only (https://github.com/ckeditor/ckeditor5/issues/12602).
|
|
170
|
+
if (editorBodyViewCollection && editorBodyViewCollection.has(this.balloonPanelView)) {
|
|
171
|
+
editorBodyViewCollection.remove(this.balloonPanelView);
|
|
172
|
+
}
|
|
173
|
+
if (!TooltipManager._editors.size) {
|
|
174
|
+
this._unpinTooltip();
|
|
175
|
+
this.balloonPanelView.destroy();
|
|
176
|
+
this.stopListening();
|
|
177
|
+
TooltipManager._instance = null;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Returns {@link #balloonPanelView} {@link module:utils/dom/position~PositioningFunction positioning functions} for a given position
|
|
182
|
+
* name.
|
|
183
|
+
*
|
|
184
|
+
* @static
|
|
185
|
+
* @param {String} position Name of the position (`s`, `se`, `sw`, `n`, `e`, or `w`).
|
|
186
|
+
* @returns {Array.<module:utils/dom/position~PositioningFunction>} Positioning functions to be used by the {@link #balloonPanelView}.
|
|
187
|
+
*/
|
|
188
|
+
static getPositioningFunctions(position) {
|
|
189
|
+
const defaultPositions = TooltipManager.defaultBalloonPositions;
|
|
190
|
+
return {
|
|
191
|
+
// South is most popular. We can use positioning heuristics to avoid clipping by the viewport with the sane fallback.
|
|
192
|
+
s: [
|
|
193
|
+
defaultPositions.southArrowNorth,
|
|
194
|
+
defaultPositions.southArrowNorthEast,
|
|
195
|
+
defaultPositions.southArrowNorthWest
|
|
196
|
+
],
|
|
197
|
+
n: [defaultPositions.northArrowSouth],
|
|
198
|
+
e: [defaultPositions.eastArrowWest],
|
|
199
|
+
w: [defaultPositions.westArrowEast],
|
|
200
|
+
sw: [defaultPositions.southArrowNorthEast],
|
|
201
|
+
se: [defaultPositions.southArrowNorthWest]
|
|
202
|
+
}[position];
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Handles displaying tooltips on `mouseenter` and `focus` in DOM.
|
|
206
|
+
*
|
|
207
|
+
* @private
|
|
208
|
+
* @param {module:utils/eventinfo~EventInfo} evt An object containing information about the fired event.
|
|
209
|
+
* @param {Event} domEvent The DOM event.
|
|
210
|
+
*/
|
|
211
|
+
_onEnterOrFocus(evt, { target }) {
|
|
212
|
+
const elementWithTooltipAttribute = getDescendantWithTooltip(target);
|
|
213
|
+
// Abort when there's no descendant needing tooltip.
|
|
214
|
+
if (!elementWithTooltipAttribute) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
// Abort to avoid flashing when, for instance:
|
|
218
|
+
// * a tooltip is displayed for a focused element, then the same element gets mouseentered,
|
|
219
|
+
// * a tooltip is displayed for an element via mouseenter, then the focus moves to the same element.
|
|
220
|
+
if (elementWithTooltipAttribute === this._currentElementWithTooltip) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
this._unpinTooltip();
|
|
224
|
+
this._pinTooltipDebounced(elementWithTooltipAttribute, getTooltipData(elementWithTooltipAttribute));
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Handles hiding tooltips on `mouseleave` and `blur` in DOM.
|
|
228
|
+
*
|
|
229
|
+
* @private
|
|
230
|
+
* @param {module:utils/eventinfo~EventInfo} evt An object containing information about the fired event.
|
|
231
|
+
* @param {Event} domEvent The DOM event.
|
|
232
|
+
*/
|
|
233
|
+
_onLeaveOrBlur(evt, { target, relatedTarget }) {
|
|
234
|
+
if (evt.name === 'mouseleave') {
|
|
235
|
+
// Don't act when the event does not concern a DOM element (e.g. a mouseleave out of an entire document),
|
|
236
|
+
if (!isElement(target)) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
// If a tooltip is currently visible, don't act for a targets other than the one it is attached to.
|
|
240
|
+
// For instance, a random mouseleave far away in the page should not unpin the tooltip that was pinned because
|
|
241
|
+
// of a previous focus. Only leaving the same element should hide the tooltip.
|
|
242
|
+
if (this._currentElementWithTooltip && target !== this._currentElementWithTooltip) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const descendantWithTooltip = getDescendantWithTooltip(target);
|
|
246
|
+
const relatedDescendantWithTooltip = getDescendantWithTooltip(relatedTarget);
|
|
247
|
+
// Unpin when the mouse was leaving element with a tooltip to a place which does not have or has a different tooltip.
|
|
248
|
+
// Note that this should happen whether the tooltip is already visible or not, for instance, it could be invisible but queued
|
|
249
|
+
// (debounced): it should get canceled.
|
|
250
|
+
if (descendantWithTooltip && descendantWithTooltip !== relatedDescendantWithTooltip) {
|
|
251
|
+
this._unpinTooltip();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
// If a tooltip is currently visible, don't act for a targets other than the one it is attached to.
|
|
256
|
+
// For instance, a random blur in the web page should not unpin the tooltip that was pinned because of a previous mouseenter.
|
|
257
|
+
if (this._currentElementWithTooltip && target !== this._currentElementWithTooltip) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
// Note that unpinning should happen whether the tooltip is already visible or not, for instance, it could be invisible but
|
|
261
|
+
// queued (debounced): it should get canceled (e.g. quick focus then quick blur using the keyboard).
|
|
262
|
+
this._unpinTooltip();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Handles hiding tooltips on `scroll` in DOM.
|
|
267
|
+
*
|
|
268
|
+
* @private
|
|
269
|
+
* @param {module:utils/eventinfo~EventInfo} evt An object containing information about the fired event.
|
|
270
|
+
* @param {Event} domEvent The DOM event.
|
|
271
|
+
*/
|
|
272
|
+
_onScroll(evt, { target }) {
|
|
273
|
+
// No tooltip, no reason to react on scroll.
|
|
274
|
+
if (!this._currentElementWithTooltip) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
// When scrolling a container that has both the balloon and the current element (common ancestor), the balloon can remain
|
|
278
|
+
// visible (e.g. scrolling ≤body>). Otherwise, to avoid glitches (clipping, lagging) better just hide the tooltip.
|
|
279
|
+
// Also, don't do anything when scrolling an unrelated DOM element that has nothing to do with the current element and the balloon.
|
|
280
|
+
if (target.contains(this.balloonPanelView.element) && target.contains(this._currentElementWithTooltip)) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
this._unpinTooltip();
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Pins the tooltip to a specific DOM element.
|
|
287
|
+
*
|
|
288
|
+
* @private
|
|
289
|
+
* @param {Element} targetDomElement
|
|
290
|
+
* @param {Object} options
|
|
291
|
+
* @param {String} options.text Text of the tooltip to display.
|
|
292
|
+
* @param {String} options.position The position of the tooltip.
|
|
293
|
+
* @param {String} options.cssClass Additional CSS class of the balloon with the tooltip.
|
|
294
|
+
*/
|
|
295
|
+
_pinTooltip(targetDomElement, { text, position, cssClass }) {
|
|
296
|
+
// Use the body collection of the first editor.
|
|
297
|
+
const bodyViewCollection = first(TooltipManager._editors.values()).ui.view.body;
|
|
298
|
+
if (!bodyViewCollection.has(this.balloonPanelView)) {
|
|
299
|
+
bodyViewCollection.add(this.balloonPanelView);
|
|
300
|
+
}
|
|
301
|
+
this.tooltipTextView.text = text;
|
|
302
|
+
this.balloonPanelView.pin({
|
|
303
|
+
target: targetDomElement,
|
|
304
|
+
positions: TooltipManager.getPositioningFunctions(position)
|
|
305
|
+
});
|
|
306
|
+
this._resizeObserver = new ResizeObserver(targetDomElement, () => {
|
|
307
|
+
// The ResizeObserver will call its callback when the target element hides and the tooltip
|
|
308
|
+
// should also disappear (https://github.com/ckeditor/ckeditor5/issues/12492).
|
|
309
|
+
if (!isVisible(targetDomElement)) {
|
|
310
|
+
this._unpinTooltip();
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
this.balloonPanelView.class = [BALLOON_CLASS, cssClass]
|
|
314
|
+
.filter(className => className)
|
|
315
|
+
.join(' ');
|
|
316
|
+
// Start responding to changes in editor UI or content layout. For instance, when collaborators change content
|
|
317
|
+
// and a contextual toolbar attached to a content starts to move (and so should move the tooltip).
|
|
318
|
+
// Note: Using low priority to let other listeners that position contextual toolbars etc. to react first.
|
|
319
|
+
for (const editor of TooltipManager._editors) {
|
|
320
|
+
this.listenTo(editor.ui, 'update', this._updateTooltipPosition.bind(this), { priority: 'low' });
|
|
321
|
+
}
|
|
322
|
+
this._currentElementWithTooltip = targetDomElement;
|
|
323
|
+
this._currentTooltipPosition = position;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Unpins the tooltip and cancels all queued pinning.
|
|
327
|
+
*
|
|
328
|
+
* @private
|
|
329
|
+
*/
|
|
330
|
+
_unpinTooltip() {
|
|
331
|
+
this._pinTooltipDebounced.cancel();
|
|
332
|
+
this.balloonPanelView.unpin();
|
|
333
|
+
for (const editor of TooltipManager._editors) {
|
|
334
|
+
this.stopListening(editor.ui, 'update');
|
|
335
|
+
}
|
|
336
|
+
this._currentElementWithTooltip = null;
|
|
337
|
+
this._currentTooltipPosition = null;
|
|
338
|
+
if (this._resizeObserver) {
|
|
339
|
+
this._resizeObserver.destroy();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Updates the position of the tooltip so it stays in sync with the element it is pinned to.
|
|
344
|
+
*
|
|
345
|
+
* Hides the tooltip when the element is no longer visible in DOM.
|
|
346
|
+
*
|
|
347
|
+
* @private
|
|
348
|
+
*/
|
|
349
|
+
_updateTooltipPosition() {
|
|
350
|
+
// This could happen if the tooltip was attached somewhere in a contextual content toolbar and the toolbar
|
|
351
|
+
// disappeared (e.g. removed an image).
|
|
352
|
+
if (!isVisible(this._currentElementWithTooltip)) {
|
|
353
|
+
this._unpinTooltip();
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
this.balloonPanelView.pin({
|
|
357
|
+
target: this._currentElementWithTooltip,
|
|
358
|
+
positions: TooltipManager.getPositioningFunctions(this._currentTooltipPosition)
|
|
359
|
+
});
|
|
360
|
+
}
|
|
382
361
|
}
|
|
383
|
-
|
|
384
|
-
mix( TooltipManager, DomEmitterMixin );
|
|
385
|
-
|
|
386
362
|
/**
|
|
387
363
|
* A set of default {@link module:utils/dom/position~PositioningFunction positioning functions} used by the `TooltipManager`
|
|
388
364
|
* to pin tooltips in different positions.
|
|
@@ -390,41 +366,36 @@ mix( TooltipManager, DomEmitterMixin );
|
|
|
390
366
|
* @member {Object.<String,module:utils/dom/position~PositioningFunction>}
|
|
391
367
|
* module:ui/tooltipmanager~TooltipManager.defaultBalloonPositions
|
|
392
368
|
*/
|
|
393
|
-
TooltipManager.defaultBalloonPositions = generatePositions(
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
|
|
369
|
+
TooltipManager.defaultBalloonPositions = generatePositions({
|
|
370
|
+
heightOffset: 5,
|
|
371
|
+
sideOffset: 13
|
|
372
|
+
});
|
|
398
373
|
/**
|
|
399
|
-
* A
|
|
400
|
-
*
|
|
374
|
+
* A set of editors the single tooltip manager instance must listen to.
|
|
375
|
+
* This is mostly to handle `EditorUI#update` listeners from individual editors.
|
|
401
376
|
*
|
|
402
377
|
* @private
|
|
403
|
-
* @member {module:
|
|
378
|
+
* @member {Set.<module:core/editor/editor~Editor>} module:ui/tooltipmanager~TooltipManager._editors
|
|
404
379
|
*/
|
|
405
|
-
TooltipManager.
|
|
406
|
-
|
|
380
|
+
TooltipManager._editors = new Set();
|
|
407
381
|
/**
|
|
408
|
-
*
|
|
409
|
-
*
|
|
382
|
+
* A reference to the `TooltipManager` instance. The class is a singleton and as such,
|
|
383
|
+
* successive attempts at creating instances should return this instance.
|
|
410
384
|
*
|
|
411
385
|
* @private
|
|
412
|
-
* @member {
|
|
386
|
+
* @member {module:ui/tooltipmanager~TooltipManager} module:ui/tooltipmanager~TooltipManager._instance
|
|
413
387
|
*/
|
|
414
|
-
TooltipManager.
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
return element.closest( '[data-cke-tooltip-text]:not([data-cke-tooltip-disabled])' );
|
|
388
|
+
TooltipManager._instance = null;
|
|
389
|
+
function getDescendantWithTooltip(element) {
|
|
390
|
+
if (!isElement(element)) {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
return element.closest('[data-cke-tooltip-text]:not([data-cke-tooltip-disabled])');
|
|
422
394
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
};
|
|
395
|
+
function getTooltipData(element) {
|
|
396
|
+
return {
|
|
397
|
+
text: element.dataset.ckeTooltipText,
|
|
398
|
+
position: (element.dataset.ckeTooltipPosition || 's'),
|
|
399
|
+
cssClass: element.dataset.ckeTooltipClass || ''
|
|
400
|
+
};
|
|
430
401
|
}
|