@ckeditor/ckeditor5-core 35.0.1 → 35.1.0

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.
@@ -46,4 +46,4 @@ msgstr "Non é posíbel cargar o ficheiro:"
46
46
 
47
47
  msgctxt "Accessible label of the specific editing area of the editor acting as a root of the entire application."
48
48
  msgid "Rich Text Editor. Editing area: %0"
49
- msgstr ""
49
+ msgstr "Editor de texto mellorado. Área de edición: %0"
@@ -18,7 +18,7 @@ msgstr ""
18
18
 
19
19
  msgctxt "Label for the Cancel button."
20
20
  msgid "Cancel"
21
- msgstr ""
21
+ msgstr "Баш тарт"
22
22
 
23
23
  msgctxt "The label used by a button next to the color palette in the color picker that removes the color (resets it to an empty value, example usages in font color or table properties)."
24
24
  msgid "Remove color"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-core",
3
- "version": "35.0.1",
3
+ "version": "35.1.0",
4
4
  "description": "The core architecture of CKEditor 5 – the best browser-based rich text editor.",
5
5
  "keywords": [
6
6
  "wysiwyg",
@@ -23,25 +23,25 @@
23
23
  ],
24
24
  "main": "src/index.js",
25
25
  "dependencies": {
26
- "@ckeditor/ckeditor5-engine": "^35.0.1",
27
- "@ckeditor/ckeditor5-ui": "^35.0.1",
28
- "@ckeditor/ckeditor5-utils": "^35.0.1",
26
+ "@ckeditor/ckeditor5-engine": "^35.1.0",
27
+ "@ckeditor/ckeditor5-ui": "^35.1.0",
28
+ "@ckeditor/ckeditor5-utils": "^35.1.0",
29
29
  "lodash-es": "^4.17.15"
30
30
  },
31
31
  "devDependencies": {
32
- "@ckeditor/ckeditor5-autoformat": "^35.0.1",
33
- "@ckeditor/ckeditor5-basic-styles": "^35.0.1",
34
- "@ckeditor/ckeditor5-block-quote": "^35.0.1",
35
- "@ckeditor/ckeditor5-editor-classic": "^35.0.1",
36
- "@ckeditor/ckeditor5-essentials": "^35.0.1",
37
- "@ckeditor/ckeditor5-heading": "^35.0.1",
38
- "@ckeditor/ckeditor5-image": "^35.0.1",
39
- "@ckeditor/ckeditor5-indent": "^35.0.1",
40
- "@ckeditor/ckeditor5-link": "^35.0.1",
41
- "@ckeditor/ckeditor5-list": "^35.0.1",
42
- "@ckeditor/ckeditor5-media-embed": "^35.0.1",
43
- "@ckeditor/ckeditor5-paragraph": "^35.0.1",
44
- "@ckeditor/ckeditor5-table": "^35.0.1"
32
+ "@ckeditor/ckeditor5-autoformat": "^35.1.0",
33
+ "@ckeditor/ckeditor5-basic-styles": "^35.1.0",
34
+ "@ckeditor/ckeditor5-block-quote": "^35.1.0",
35
+ "@ckeditor/ckeditor5-editor-classic": "^35.1.0",
36
+ "@ckeditor/ckeditor5-essentials": "^35.1.0",
37
+ "@ckeditor/ckeditor5-heading": "^35.1.0",
38
+ "@ckeditor/ckeditor5-image": "^35.1.0",
39
+ "@ckeditor/ckeditor5-indent": "^35.1.0",
40
+ "@ckeditor/ckeditor5-link": "^35.1.0",
41
+ "@ckeditor/ckeditor5-list": "^35.1.0",
42
+ "@ckeditor/ckeditor5-media-embed": "^35.1.0",
43
+ "@ckeditor/ckeditor5-paragraph": "^35.1.0",
44
+ "@ckeditor/ckeditor5-table": "^35.1.0"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=14.0.0",
@@ -11,9 +11,11 @@
11
11
 
12
12
  import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory';
13
13
  import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
14
+ import TooltipManager from '@ckeditor/ckeditor5-ui/src/tooltipmanager';
14
15
 
15
16
  import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
16
17
  import mix from '@ckeditor/ckeditor5-utils/src/mix';
18
+ import isVisible from '@ckeditor/ckeditor5-utils/src/dom/isvisible';
17
19
 
18
20
  /**
19
21
  * A class providing the minimal interface that is required to successfully bootstrap any editor UI.
@@ -53,6 +55,14 @@ export default class EditorUI {
53
55
  */
54
56
  this.focusTracker = new FocusTracker();
55
57
 
58
+ /**
59
+ * Manages the tooltips displayed on mouseover and focus across the UI.
60
+ *
61
+ * @readonly
62
+ * @member {module:ui/tooltipmanager~TooltipManager}
63
+ */
64
+ this.tooltipManager = new TooltipManager( editor );
65
+
56
66
  /**
57
67
  * Stores viewport offsets from every direction.
58
68
  *
@@ -86,6 +96,18 @@ export default class EditorUI {
86
96
  */
87
97
  this.set( 'viewportOffset', this._readViewportOffsetFromConfig() );
88
98
 
99
+ /**
100
+ * Indicates the UI is ready. Set `true` after {@link #event:ready} event is fired.
101
+ *
102
+ * @readonly
103
+ * @default false
104
+ * @member {Boolean} #isReady
105
+ */
106
+ this.isReady = false;
107
+ this.once( 'ready', () => {
108
+ this.isReady = true;
109
+ } );
110
+
89
111
  /**
90
112
  * Stores all editable elements used by the editor instance.
91
113
  *
@@ -94,8 +116,18 @@ export default class EditorUI {
94
116
  */
95
117
  this._editableElementsMap = new Map();
96
118
 
119
+ /**
120
+ * All available & focusable toolbars.
121
+ *
122
+ * @private
123
+ * @type {Array.<module:core/editor/editorui~FocusableToolbarDefinition>}
124
+ */
125
+ this._focusableToolbarDefinitions = [];
126
+
97
127
  // Informs UI components that should be refreshed after layout change.
98
128
  this.listenTo( editor.editing.view.document, 'layoutChanged', () => this.update() );
129
+
130
+ this._initFocusTracking();
99
131
  }
100
132
 
101
133
  /**
@@ -134,6 +166,7 @@ export default class EditorUI {
134
166
  this.stopListening();
135
167
 
136
168
  this.focusTracker.destroy();
169
+ this.tooltipManager.destroy( this.editor );
137
170
 
138
171
  // Clean–up the references to the CKEditor instance stored in the native editable DOM elements.
139
172
  for ( const domElement of this._editableElementsMap.values() ) {
@@ -141,11 +174,14 @@ export default class EditorUI {
141
174
  }
142
175
 
143
176
  this._editableElementsMap = new Map();
177
+ this._focusableToolbarDefinitions = [];
144
178
  }
145
179
 
146
180
  /**
147
- * Store the native DOM editable element used by the editor under
148
- * a unique name.
181
+ * Stores the native DOM editable element used by the editor under a unique name.
182
+ *
183
+ * Also, registers the element in the editor to maintain the accessibility of the UI. When the user is editing text in a focusable
184
+ * editable area, they can use the <kbd>Alt</kbd> + <kbd>F10</kbd> keystroke to navigate over editor toolbars. See {@link #addToolbar}.
149
185
  *
150
186
  * @param {String} rootName The unique name of the editable element.
151
187
  * @param {HTMLElement} domElement The native DOM editable element.
@@ -160,6 +196,28 @@ export default class EditorUI {
160
196
  if ( !domElement.ckeditorInstance ) {
161
197
  domElement.ckeditorInstance = this.editor;
162
198
  }
199
+
200
+ // Register the element so it becomes available for Alt+F10 and Esc navigation.
201
+ this.focusTracker.add( domElement );
202
+
203
+ const setUpKeystrokeHandler = () => {
204
+ // The editing view of the editor is already listening to keystrokes from DOM roots (see: KeyObserver).
205
+ // Do not duplicate listeners.
206
+ if ( this.editor.editing.view.getDomRoot( rootName ) ) {
207
+ return;
208
+ }
209
+
210
+ this.editor.keystrokes.listenTo( domElement );
211
+ };
212
+
213
+ // For editable elements set by features after EditorUI is ready (e.g. source editing).
214
+ if ( this.isReady ) {
215
+ setUpKeystrokeHandler();
216
+ }
217
+ // For editable elements set while the editor is being created (e.g. DOM roots).
218
+ else {
219
+ this.once( 'ready', setUpKeystrokeHandler );
220
+ }
163
221
  }
164
222
 
165
223
  /**
@@ -181,6 +239,35 @@ export default class EditorUI {
181
239
  return this._editableElementsMap.keys();
182
240
  }
183
241
 
242
+ /**
243
+ * Adds a toolbar to the editor UI. Used primarily to maintain the accessibility of the UI.
244
+ *
245
+ * Focusable toolbars can be accessed (focused) by users by pressing the <kbd>Alt</kbd> + <kbd>F10</kbd> keystroke.
246
+ * Successive keystroke presses navigate over available toolbars.
247
+ *
248
+ * @param {module:ui/toolbar/toolbarview~ToolbarView} toolbarView A instance of the toolbar to be registered.
249
+ * @param {Object} [options]
250
+ * @param {Boolean} [options.isContextual] Set `true` if the toolbar is attached to the content of the editor. Such toolbar takes
251
+ * a precedence over other toolbars when a user pressed <kbd>Alt</kbd> + <kbd>F10</kbd>.
252
+ * @param {Function} [options.beforeFocus] Specify a callback executed before the toolbar instance DOM element gains focus
253
+ * upon the <kbd>Alt</kbd> + <kbd>F10</kbd> keystroke.
254
+ * @param {Function} [options.afterBlur] Specify a callback executed after the toolbar instance DOM element loses focus upon
255
+ * <kbd>Esc</kbd> keystroke but before the focus goes back to the {@link #setEditableElement editable element}.
256
+ */
257
+ addToolbar( toolbarView, options = {} ) {
258
+ if ( toolbarView.isRendered ) {
259
+ this.focusTracker.add( toolbarView.element );
260
+ this.editor.keystrokes.listenTo( toolbarView.element );
261
+ } else {
262
+ toolbarView.once( 'render', () => {
263
+ this.focusTracker.add( toolbarView.element );
264
+ this.editor.keystrokes.listenTo( toolbarView.element );
265
+ } );
266
+ }
267
+
268
+ this._focusableToolbarDefinitions.push( { toolbarView, options } );
269
+ }
270
+
184
271
  /**
185
272
  * Stores all editable elements used by the editor instance.
186
273
  *
@@ -254,6 +341,177 @@ export default class EditorUI {
254
341
  return { top: 0 };
255
342
  }
256
343
 
344
+ /**
345
+ * Starts listening for <kbd>Alt</kbd> + <kbd>F10</kbd> and <kbd>Esc</kbd> keystrokes in the context of focusable
346
+ * {@link #setEditableElement editable elements} and {@link #addToolbar toolbars}
347
+ * to allow users navigate across the UI.
348
+ *
349
+ * @private
350
+ */
351
+ _initFocusTracking() {
352
+ const editor = this.editor;
353
+ const editingView = editor.editing.view;
354
+
355
+ let lastFocusedForeignElement;
356
+ let candidateDefinitions;
357
+
358
+ // Focus the next focusable toolbar on <kbd>Alt</kbd> + <kbd>F10</kbd>.
359
+ editor.keystrokes.set( 'Alt+F10', ( data, cancel ) => {
360
+ const focusedElement = this.focusTracker.focusedElement;
361
+
362
+ // Focus moved out of a DOM element that
363
+ // * is not a toolbar,
364
+ // * does not belong to the editing view (e.g. source editing).
365
+ if (
366
+ Array.from( this._editableElementsMap.values() ).includes( focusedElement ) &&
367
+ !Array.from( editingView.domRoots.values() ).includes( focusedElement )
368
+ ) {
369
+ lastFocusedForeignElement = focusedElement;
370
+ }
371
+
372
+ const currentFocusedToolbarDefinition = this._getCurrentFocusedToolbarDefinition();
373
+
374
+ // * When focusing a toolbar for the first time, set the array of definitions for successive presses of Alt+F10.
375
+ // This ensures, the navigation works always the same and no pair of toolbars takes over
376
+ // (e.g. image and table toolbars when a selected image is inside a cell).
377
+ // * It could be that the focus went to the toolbar by clicking a toolbar item (e.g. a dropdown). In this case,
378
+ // there were no candidates so they must be obtained (#12339).
379
+ if ( !currentFocusedToolbarDefinition || !candidateDefinitions ) {
380
+ candidateDefinitions = this._getFocusableCandidateToolbarDefinitions( currentFocusedToolbarDefinition );
381
+ }
382
+
383
+ // In a single Alt+F10 press, check all candidates but if none were focused, don't go any further.
384
+ // This prevents an infinite loop.
385
+ for ( let i = 0; i < candidateDefinitions.length; i++ ) {
386
+ const candidateDefinition = candidateDefinitions.shift();
387
+
388
+ // Put the first definition to the back of the array. This allows circular navigation over all toolbars
389
+ // on successive presses of Alt+F10.
390
+ candidateDefinitions.push( candidateDefinition );
391
+
392
+ // Don't focus the same toolbar again. If you did, this would move focus from the nth focused toolbar item back to the
393
+ // first item as per ToolbarView#focus() if the user navigated inside the toolbar.
394
+ if (
395
+ candidateDefinition !== currentFocusedToolbarDefinition &&
396
+ this._focusFocusableCandidateToolbar( candidateDefinition )
397
+ ) {
398
+ // Clean up after a current visible toolbar when switching to the next one.
399
+ if ( currentFocusedToolbarDefinition && currentFocusedToolbarDefinition.options.afterBlur ) {
400
+ currentFocusedToolbarDefinition.options.afterBlur();
401
+ }
402
+
403
+ break;
404
+ }
405
+ }
406
+
407
+ cancel();
408
+ } );
409
+
410
+ // Blur the focused toolbar on <kbd>Esc</kbd> and bring the focus back to its origin.
411
+ editor.keystrokes.set( 'Esc', ( data, cancel ) => {
412
+ const focusedToolbarDef = this._getCurrentFocusedToolbarDefinition();
413
+
414
+ if ( !focusedToolbarDef ) {
415
+ return;
416
+ }
417
+
418
+ // Bring focus back to where it came from before focusing the toolbar:
419
+ // 1. If it came from outside the engine view (e.g. source editing), move it there.
420
+ if ( lastFocusedForeignElement ) {
421
+ lastFocusedForeignElement.focus();
422
+ lastFocusedForeignElement = null;
423
+ }
424
+ // 2. There are two possibilities left:
425
+ // 2.1. It could be that the focus went from an editable element in the view (root or nested).
426
+ // 2.2. It could be the focus went straight to the toolbar before even focusing the editing area.
427
+ // In either case, just focus the view editing. The focus will land where it belongs.
428
+ else {
429
+ editor.editing.view.focus();
430
+ }
431
+
432
+ // Clean up after the toolbar if there is anything to do there.
433
+ if ( focusedToolbarDef.options.afterBlur ) {
434
+ focusedToolbarDef.options.afterBlur();
435
+ }
436
+
437
+ cancel();
438
+ } );
439
+ }
440
+
441
+ /**
442
+ * Returns definitions of toolbars that could potentially be focused, sorted by their importance for the user.
443
+ *
444
+ * Focusable toolbars candidates are either:
445
+ * * already visible,
446
+ * * have `beforeFocus()` set in their {@link module:core/editor/editorui~FocusableToolbarDefinition definition} that suggests that
447
+ * they might show up when called. Keep in mind that determining whether a toolbar will show up (and become focusable) is impossible
448
+ * at this stage because it depends on its implementation, that in turn depends on the editing context (selection).
449
+ *
450
+ * **Note**: Contextual toolbars take precedence over regular toolbars.
451
+ *
452
+ * @private
453
+ * @returns {Array.<module:core/editor/editorui~FocusableToolbarDefinition>}
454
+ */
455
+ _getFocusableCandidateToolbarDefinitions() {
456
+ const definitions = [];
457
+
458
+ for ( const toolbarDef of this._focusableToolbarDefinitions ) {
459
+ const { toolbarView, options } = toolbarDef;
460
+
461
+ if ( isVisible( toolbarView.element ) || options.beforeFocus ) {
462
+ definitions.push( toolbarDef );
463
+ }
464
+ }
465
+
466
+ // Contextual and already visible toolbars have higher priority. If both are true, the toolbar will always focus first.
467
+ // For instance, a selected widget toolbar vs inline editor toolbar: both are visible but the widget toolbar is contextual.
468
+ definitions.sort( ( defA, defB ) => getToolbarDefinitionWeight( defA ) - getToolbarDefinitionWeight( defB ) );
469
+
470
+ return definitions;
471
+ }
472
+
473
+ /**
474
+ * Returns a definition of the toolbar that is currently visible and focused (one of its children has focus).
475
+ *
476
+ * `null` is returned when no toolbar is currently focused.
477
+ *
478
+ * @private
479
+ * @returns {module:core/editor/editorui~FocusableToolbarDefinition|null}
480
+ */
481
+ _getCurrentFocusedToolbarDefinition() {
482
+ for ( const definition of this._focusableToolbarDefinitions ) {
483
+ if ( definition.toolbarView.element && definition.toolbarView.element.contains( this.focusTracker.focusedElement ) ) {
484
+ return definition;
485
+ }
486
+ }
487
+
488
+ return null;
489
+ }
490
+
491
+ /**
492
+ * Focuses a focusable toolbar candidate using its definition.
493
+ *
494
+ * @private
495
+ * @param {module:core/editor/editorui~FocusableToolbarDefinition} candidateToolbarDefinition A definition of the toolbar to focus.
496
+ * @returns {Boolean} `true` when the toolbar candidate was focused. `false` otherwise.
497
+ */
498
+ _focusFocusableCandidateToolbar( candidateToolbarDefinition ) {
499
+ const { toolbarView, options: { beforeFocus } } = candidateToolbarDefinition;
500
+
501
+ if ( beforeFocus ) {
502
+ beforeFocus();
503
+ }
504
+
505
+ // If it didn't show up after beforeFocus(), it's not focusable at all.
506
+ if ( !isVisible( toolbarView.element ) ) {
507
+ return false;
508
+ }
509
+
510
+ toolbarView.focus();
511
+
512
+ return true;
513
+ }
514
+
257
515
  /**
258
516
  * Fired when the editor UI is ready.
259
517
  *
@@ -273,3 +531,52 @@ export default class EditorUI {
273
531
  }
274
532
 
275
533
  mix( EditorUI, ObservableMixin );
534
+
535
+ /**
536
+ * A definition of a focusable toolbar. Used by {@link module:core/editor/editorui~EditorUI#addToolbar}.
537
+ *
538
+ * @private
539
+ * @interface module:core/editor/editorui~FocusableToolbarDefinition
540
+ */
541
+
542
+ /**
543
+ * An instance of a focusable toolbar view.
544
+ *
545
+ * @member {module:ui/toolbar/toolbarview~ToolbarView} #toolbarView
546
+ */
547
+
548
+ /**
549
+ * Options of a focusable toolbar view:
550
+ *
551
+ * * `isContextual`: Marks the higher priority toolbar. For example when there are 2 visible toolbars,
552
+ * it allows to distinguish which toolbar should be focused first after the `alt+f10` keystroke
553
+ * * `beforeFocus`: A callback executed before the `ToolbarView` gains focus upon the `Alt+F10` keystroke.
554
+ * * `afterBlur`: A callback executed after `ToolbarView` loses focus upon `Esc` keystroke but before the focus goes back to the `origin`.
555
+ *
556
+ * @member {Object} #options
557
+ */
558
+
559
+ // Returns a number (weight) for a toolbar definition. Visible toolbars have a higher priority and so do
560
+ // contextual toolbars (displayed in the context of a content, for instance, an image toolbar).
561
+ //
562
+ // A standard invisible toolbar is the heaviest. A visible contextual toolbar is the lightest.
563
+ //
564
+ // @private
565
+ // @param {module:core/editor/editorui~FocusableToolbarDefinition} toolbarDef A toolbar definition to be weighted.
566
+ // @returns {Number}
567
+ function getToolbarDefinitionWeight( toolbarDef ) {
568
+ const { toolbarView, options } = toolbarDef;
569
+ let weight = 10;
570
+
571
+ // Prioritize already visible toolbars. They should get focused first.
572
+ if ( isVisible( toolbarView.element ) ) {
573
+ weight--;
574
+ }
575
+
576
+ // Prioritize contextual toolbars. They are displayed at the selection.
577
+ if ( options.isContextual ) {
578
+ weight--;
579
+ }
580
+
581
+ return weight;
582
+ }