@ckeditor/ckeditor5-ui 35.2.1 → 35.3.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.
Files changed (59) hide show
  1. package/package.json +31 -23
  2. package/src/bindings/addkeyboardhandlingforgrid.js +45 -57
  3. package/src/bindings/clickoutsidehandler.js +15 -21
  4. package/src/bindings/injectcsstransitiondisabler.js +16 -20
  5. package/src/bindings/preventdefault.js +6 -8
  6. package/src/bindings/submithandler.js +5 -7
  7. package/src/button/button.js +5 -0
  8. package/src/button/buttonview.js +220 -259
  9. package/src/button/switchbuttonview.js +56 -71
  10. package/src/colorgrid/colorgridview.js +135 -197
  11. package/src/colorgrid/colortileview.js +37 -47
  12. package/src/colorgrid/utils.js +57 -66
  13. package/src/componentfactory.js +79 -93
  14. package/src/dropdown/button/dropdownbutton.js +5 -0
  15. package/src/dropdown/button/dropdownbuttonview.js +44 -57
  16. package/src/dropdown/button/splitbuttonview.js +159 -207
  17. package/src/dropdown/dropdownpanelfocusable.js +5 -0
  18. package/src/dropdown/dropdownpanelview.js +101 -112
  19. package/src/dropdown/dropdownview.js +396 -438
  20. package/src/dropdown/utils.js +164 -213
  21. package/src/editableui/editableuiview.js +125 -141
  22. package/src/editableui/inline/inlineeditableuiview.js +44 -54
  23. package/src/editorui/bodycollection.js +61 -75
  24. package/src/editorui/boxed/boxededitoruiview.js +91 -104
  25. package/src/editorui/editoruiview.js +30 -39
  26. package/src/focuscycler.js +214 -245
  27. package/src/formheader/formheaderview.js +58 -70
  28. package/src/icon/iconview.js +145 -111
  29. package/src/iframe/iframeview.js +37 -49
  30. package/src/index.js +0 -17
  31. package/src/input/inputview.js +170 -198
  32. package/src/inputnumber/inputnumberview.js +48 -56
  33. package/src/inputtext/inputtextview.js +14 -18
  34. package/src/label/labelview.js +44 -53
  35. package/src/labeledfield/labeledfieldview.js +212 -235
  36. package/src/labeledfield/utils.js +39 -57
  37. package/src/labeledinput/labeledinputview.js +190 -221
  38. package/src/list/listitemview.js +40 -50
  39. package/src/list/listseparatorview.js +15 -19
  40. package/src/list/listview.js +94 -115
  41. package/src/model.js +19 -25
  42. package/src/notification/notification.js +151 -202
  43. package/src/panel/balloon/balloonpanelview.js +535 -628
  44. package/src/panel/balloon/contextualballoon.js +611 -732
  45. package/src/panel/sticky/stickypanelview.js +238 -270
  46. package/src/template.js +1049 -1479
  47. package/src/toolbar/balloon/balloontoolbar.js +337 -424
  48. package/src/toolbar/block/blockbuttonview.js +32 -42
  49. package/src/toolbar/block/blocktoolbar.js +375 -477
  50. package/src/toolbar/normalizetoolbarconfig.js +17 -21
  51. package/src/toolbar/toolbarlinebreakview.js +15 -19
  52. package/src/toolbar/toolbarseparatorview.js +15 -19
  53. package/src/toolbar/toolbarview.js +866 -1053
  54. package/src/tooltipmanager.js +324 -353
  55. package/src/view.js +389 -430
  56. package/src/viewcollection.js +147 -178
  57. package/src/button/button.jsdoc +0 -165
  58. package/src/dropdown/button/dropdownbutton.jsdoc +0 -22
  59. package/src/dropdown/dropdownpanelfocusable.jsdoc +0 -27
@@ -2,216 +2,154 @@
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/colorgrid/colorgrid
8
7
  */
9
-
10
8
  import View from '../view';
11
9
  import ColorTileView from './colortileview';
12
10
  import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
13
11
  import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
14
12
  import addKeyboardHandlingForGrid from '../bindings/addkeyboardhandlingforgrid';
15
-
16
13
  import '../../theme/components/colorgrid/colorgrid.css';
17
-
18
14
  /**
19
15
  * A grid of {@link module:ui/colorgrid/colortile~ColorTileView color tiles}.
20
16
  *
21
17
  * @extends module:ui/view~View
22
18
  */
23
19
  export default class ColorGridView extends View {
24
- /**
25
- * Creates an instance of a color grid containing {@link module:ui/colorgrid/colortile~ColorTileView tiles}.
26
- *
27
- * @param {module:utils/locale~Locale} [locale] The localization services instance.
28
- * @param {Object} options Component configuration
29
- * @param {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>} [options.colorDefinitions] Array with definitions
30
- * required to create the {@link module:ui/colorgrid/colortile~ColorTileView tiles}.
31
- * @param {Number} [options.columns=5] A number of columns to display the tiles.
32
- */
33
- constructor( locale, options ) {
34
- super( locale );
35
-
36
- const colorDefinitions = options && options.colorDefinitions || [];
37
- const viewStyleAttribute = {};
38
-
39
- /**
40
- * A number of columns for the tiles grid.
41
- *
42
- * @readonly
43
- * @member {Number}
44
- */
45
- this.columns = options && options.columns ? options.columns : 5;
46
-
47
- viewStyleAttribute.gridTemplateColumns = `repeat( ${ this.columns }, 1fr)`;
48
-
49
- /**
50
- * The color of the currently selected color tile in {@link #items}.
51
- *
52
- * @observable
53
- * @type {String}
54
- */
55
- this.set( 'selectedColor' );
56
-
57
- /**
58
- * Collection of the child tile views.
59
- *
60
- * @readonly
61
- * @member {module:ui/viewcollection~ViewCollection}
62
- */
63
- this.items = this.createCollection();
64
-
65
- /**
66
- * Tracks information about DOM focus in the grid.
67
- *
68
- * @readonly
69
- * @member {module:utils/focustracker~FocusTracker}
70
- */
71
- this.focusTracker = new FocusTracker();
72
-
73
- /**
74
- * Instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
75
- *
76
- * @readonly
77
- * @member {module:utils/keystrokehandler~KeystrokeHandler}
78
- */
79
- this.keystrokes = new KeystrokeHandler();
80
-
81
- this.items.on( 'add', ( evt, colorTile ) => {
82
- colorTile.isOn = colorTile.color === this.selectedColor;
83
- } );
84
-
85
- colorDefinitions.forEach( color => {
86
- const colorTile = new ColorTileView();
87
-
88
- colorTile.set( {
89
- color: color.color,
90
- label: color.label,
91
- tooltip: true,
92
- hasBorder: color.options.hasBorder
93
- } );
94
-
95
- colorTile.on( 'execute', () => {
96
- this.fire( 'execute', {
97
- value: color.color,
98
- hasBorder: color.options.hasBorder,
99
- label: color.label
100
- } );
101
- } );
102
-
103
- this.items.add( colorTile );
104
- } );
105
-
106
- this.setTemplate( {
107
- tag: 'div',
108
- children: this.items,
109
- attributes: {
110
- class: [
111
- 'ck',
112
- 'ck-color-grid'
113
- ],
114
- style: viewStyleAttribute
115
- }
116
- } );
117
-
118
- this.on( 'change:selectedColor', ( evt, name, selectedColor ) => {
119
- for ( const item of this.items ) {
120
- item.isOn = item.color === selectedColor;
121
- }
122
- } );
123
- }
124
-
125
- /**
126
- * Focuses the first focusable in {@link #items}.
127
- */
128
- focus() {
129
- if ( this.items.length ) {
130
- this.items.first.focus();
131
- }
132
- }
133
-
134
- /**
135
- * Focuses the last focusable in {@link #items}.
136
- */
137
- focusLast() {
138
- if ( this.items.length ) {
139
- this.items.last.focus();
140
- }
141
- }
142
-
143
- /**
144
- * @inheritDoc
145
- */
146
- render() {
147
- super.render();
148
-
149
- // Items added before rendering should be known to the #focusTracker.
150
- for ( const item of this.items ) {
151
- this.focusTracker.add( item.element );
152
- }
153
-
154
- this.items.on( 'add', ( evt, item ) => {
155
- this.focusTracker.add( item.element );
156
- } );
157
-
158
- this.items.on( 'remove', ( evt, item ) => {
159
- this.focusTracker.remove( item.element );
160
- } );
161
-
162
- // Start listening for the keystrokes coming from #element.
163
- this.keystrokes.listenTo( this.element );
164
-
165
- addKeyboardHandlingForGrid( {
166
- keystrokeHandler: this.keystrokes,
167
- focusTracker: this.focusTracker,
168
- gridItems: this.items,
169
- numberOfColumns: this.columns
170
- } );
171
- }
172
-
173
- /**
174
- * @inheritDoc
175
- */
176
- destroy() {
177
- super.destroy();
178
-
179
- this.focusTracker.destroy();
180
- this.keystrokes.destroy();
181
- }
182
-
183
- /**
184
- * Fired when the `ColorTileView` for the picked item is executed.
185
- *
186
- * @event execute
187
- * @param {Object} data Additional information about the event.
188
- * @param {String} data.value The value of the selected color
189
- * ({@link module:ui/colorgrid/colorgrid~ColorDefinition#color `color.color`}).
190
- * @param {Boolean} data.hasBorder The `hasBorder` property of the selected color
191
- * ({@link module:ui/colorgrid/colorgrid~ColorDefinition#options `color.options.hasBorder`}).
192
- * @param {String} data.Label The label of the selected color
193
- * ({@link module:ui/colorgrid/colorgrid~ColorDefinition#label `color.label`})
194
- */
20
+ /**
21
+ * Creates an instance of a color grid containing {@link module:ui/colorgrid/colortile~ColorTileView tiles}.
22
+ *
23
+ * @param {module:utils/locale~Locale} [locale] The localization services instance.
24
+ * @param {Object} options Component configuration
25
+ * @param {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>} [options.colorDefinitions] Array with definitions
26
+ * required to create the {@link module:ui/colorgrid/colortile~ColorTileView tiles}.
27
+ * @param {Number} [options.columns=5] A number of columns to display the tiles.
28
+ */
29
+ constructor(locale, options) {
30
+ super(locale);
31
+ const colorDefinitions = options && options.colorDefinitions || [];
32
+ /**
33
+ * A number of columns for the tiles grid.
34
+ *
35
+ * @readonly
36
+ * @member {Number}
37
+ */
38
+ this.columns = options && options.columns ? options.columns : 5;
39
+ const viewStyleAttribute = {
40
+ gridTemplateColumns: `repeat( ${this.columns}, 1fr)`
41
+ };
42
+ /**
43
+ * The color of the currently selected color tile in {@link #items}.
44
+ *
45
+ * @observable
46
+ * @type {String}
47
+ */
48
+ this.set('selectedColor', undefined);
49
+ /**
50
+ * Collection of the child tile views.
51
+ *
52
+ * @readonly
53
+ * @member {module:ui/viewcollection~ViewCollection}
54
+ */
55
+ this.items = this.createCollection();
56
+ /**
57
+ * Tracks information about DOM focus in the grid.
58
+ *
59
+ * @readonly
60
+ * @member {module:utils/focustracker~FocusTracker}
61
+ */
62
+ this.focusTracker = new FocusTracker();
63
+ /**
64
+ * Instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
65
+ *
66
+ * @readonly
67
+ * @member {module:utils/keystrokehandler~KeystrokeHandler}
68
+ */
69
+ this.keystrokes = new KeystrokeHandler();
70
+ this.items.on('add', (evt, colorTile) => {
71
+ colorTile.isOn = colorTile.color === this.selectedColor;
72
+ });
73
+ colorDefinitions.forEach(color => {
74
+ const colorTile = new ColorTileView();
75
+ colorTile.set({
76
+ color: color.color,
77
+ label: color.label,
78
+ tooltip: true,
79
+ hasBorder: color.options.hasBorder
80
+ });
81
+ colorTile.on('execute', () => {
82
+ this.fire('execute', {
83
+ value: color.color,
84
+ hasBorder: color.options.hasBorder,
85
+ label: color.label
86
+ });
87
+ });
88
+ this.items.add(colorTile);
89
+ });
90
+ this.setTemplate({
91
+ tag: 'div',
92
+ children: this.items,
93
+ attributes: {
94
+ class: [
95
+ 'ck',
96
+ 'ck-color-grid'
97
+ ],
98
+ style: viewStyleAttribute
99
+ }
100
+ });
101
+ this.on('change:selectedColor', (evt, name, selectedColor) => {
102
+ for (const item of this.items) {
103
+ item.isOn = item.color === selectedColor;
104
+ }
105
+ });
106
+ }
107
+ /**
108
+ * Focuses the first focusable in {@link #items}.
109
+ */
110
+ focus() {
111
+ if (this.items.length) {
112
+ this.items.first.focus();
113
+ }
114
+ }
115
+ /**
116
+ * Focuses the last focusable in {@link #items}.
117
+ */
118
+ focusLast() {
119
+ if (this.items.length) {
120
+ this.items.last.focus();
121
+ }
122
+ }
123
+ /**
124
+ * @inheritDoc
125
+ */
126
+ render() {
127
+ super.render();
128
+ // Items added before rendering should be known to the #focusTracker.
129
+ for (const item of this.items) {
130
+ this.focusTracker.add(item.element);
131
+ }
132
+ this.items.on('add', (evt, item) => {
133
+ this.focusTracker.add(item.element);
134
+ });
135
+ this.items.on('remove', (evt, item) => {
136
+ this.focusTracker.remove(item.element);
137
+ });
138
+ // Start listening for the keystrokes coming from #element.
139
+ this.keystrokes.listenTo(this.element);
140
+ addKeyboardHandlingForGrid({
141
+ keystrokeHandler: this.keystrokes,
142
+ focusTracker: this.focusTracker,
143
+ gridItems: this.items,
144
+ numberOfColumns: this.columns
145
+ });
146
+ }
147
+ /**
148
+ * @inheritDoc
149
+ */
150
+ destroy() {
151
+ super.destroy();
152
+ this.focusTracker.destroy();
153
+ this.keystrokes.destroy();
154
+ }
195
155
  }
196
-
197
- /**
198
- * A color definition used to create a {@link module:ui/colorgrid/colortile~ColorTileView}.
199
- *
200
- * {
201
- * color: 'hsl(0, 0%, 75%)',
202
- * label: 'Light Grey',
203
- * options: {
204
- * hasBorder: true
205
- * }
206
- * }
207
- *
208
- * @typedef {Object} module:ui/colorgrid/colorgrid~ColorDefinition
209
- * @type Object
210
- *
211
- * @property {String} color String representing a color.
212
- * It is used as value of background-color style in {@link module:ui/colorgrid/colortile~ColorTileView}.
213
- * @property {String} label String used as label for {@link module:ui/colorgrid/colortile~ColorTileView}.
214
- * @property {Object} options Additional options passed to create a {@link module:ui/colorgrid/colortile~ColorTileView}.
215
- * @property {Boolean} options.hasBorder A flag that indicates if special a CSS class should be added
216
- * to {@link module:ui/colorgrid/colortile~ColorTileView}, which renders a border around it.
217
- */
@@ -2,62 +2,52 @@
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/colorgrid/colortile
8
7
  */
9
-
10
8
  import ButtonView from '../button/buttonview';
11
9
  import checkIcon from '../../theme/icons/color-tile-check.svg';
12
-
13
10
  /**
14
11
  * This class represents a single color tile in the {@link module:ui/colorgrid/colorgrid~ColorGridView}.
15
12
  *
16
13
  * @extends module:ui/button/buttonview~ButtonView
17
14
  */
18
15
  export default class ColorTileView extends ButtonView {
19
- constructor( locale ) {
20
- super( locale );
21
-
22
- const bind = this.bindTemplate;
23
-
24
- /**
25
- * String representing a color shown as tile's background.
26
- *
27
- * @type {String}
28
- */
29
- this.set( 'color' );
30
-
31
- /**
32
- * A flag that toggles a special CSS class responsible for displaying
33
- * a border around the button.
34
- *
35
- * @type {Boolean}
36
- */
37
- this.set( 'hasBorder' );
38
-
39
- this.icon = checkIcon;
40
-
41
- this.extendTemplate( {
42
- attributes: {
43
- style: {
44
- backgroundColor: bind.to( 'color' )
45
- },
46
- class: [
47
- 'ck',
48
- 'ck-color-grid__tile',
49
- bind.if( 'hasBorder', 'ck-color-table__color-tile_bordered' )
50
- ]
51
- }
52
- } );
53
- }
54
-
55
- /**
56
- * @inheritDoc
57
- */
58
- render() {
59
- super.render();
60
-
61
- this.iconView.fillColor = 'hsl(0, 0%, 100%)';
62
- }
16
+ constructor(locale) {
17
+ super(locale);
18
+ const bind = this.bindTemplate;
19
+ /**
20
+ * String representing a color shown as tile's background.
21
+ *
22
+ * @type {String}
23
+ */
24
+ this.set('color', undefined);
25
+ /**
26
+ * A flag that toggles a special CSS class responsible for displaying
27
+ * a border around the button.
28
+ *
29
+ * @type {Boolean}
30
+ */
31
+ this.set('hasBorder', false);
32
+ this.icon = checkIcon;
33
+ this.extendTemplate({
34
+ attributes: {
35
+ style: {
36
+ backgroundColor: bind.to('color')
37
+ },
38
+ class: [
39
+ 'ck',
40
+ 'ck-color-grid__tile',
41
+ bind.if('hasBorder', 'ck-color-table__color-tile_bordered')
42
+ ]
43
+ }
44
+ });
45
+ }
46
+ /**
47
+ * @inheritDoc
48
+ */
49
+ render() {
50
+ super.render();
51
+ this.iconView.fillColor = 'hsl(0, 0%, 100%)';
52
+ }
63
53
  }
@@ -2,11 +2,6 @@
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
- /**
7
- * @module ui/colorgrid/utils
8
- */
9
-
10
5
  /**
11
6
  * Returns color configuration options as defined in `editor.config.(fontColor|fontBackgroundColor).colors` or
12
7
  * `editor.config.table.(tableProperties|tableCellProperties).(background|border).colors
@@ -19,37 +14,33 @@
19
14
  * @param {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>} options
20
15
  * @returns {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>}.
21
16
  */
22
- export function getLocalizedColorOptions( locale, options ) {
23
- const t = locale.t;
24
- const localizedColorNames = {
25
- Black: t( 'Black' ),
26
- 'Dim grey': t( 'Dim grey' ),
27
- Grey: t( 'Grey' ),
28
- 'Light grey': t( 'Light grey' ),
29
- White: t( 'White' ),
30
- Red: t( 'Red' ),
31
- Orange: t( 'Orange' ),
32
- Yellow: t( 'Yellow' ),
33
- 'Light green': t( 'Light green' ),
34
- Green: t( 'Green' ),
35
- Aquamarine: t( 'Aquamarine' ),
36
- Turquoise: t( 'Turquoise' ),
37
- 'Light blue': t( 'Light blue' ),
38
- Blue: t( 'Blue' ),
39
- Purple: t( 'Purple' )
40
- };
41
-
42
- return options.map( colorOption => {
43
- const label = localizedColorNames[ colorOption.label ];
44
-
45
- if ( label && label != colorOption.label ) {
46
- colorOption.label = label;
47
- }
48
-
49
- return colorOption;
50
- } );
17
+ export function getLocalizedColorOptions(locale, options) {
18
+ const t = locale.t;
19
+ const localizedColorNames = {
20
+ Black: t('Black'),
21
+ 'Dim grey': t('Dim grey'),
22
+ Grey: t('Grey'),
23
+ 'Light grey': t('Light grey'),
24
+ White: t('White'),
25
+ Red: t('Red'),
26
+ Orange: t('Orange'),
27
+ Yellow: t('Yellow'),
28
+ 'Light green': t('Light green'),
29
+ Green: t('Green'),
30
+ Aquamarine: t('Aquamarine'),
31
+ Turquoise: t('Turquoise'),
32
+ 'Light blue': t('Light blue'),
33
+ Blue: t('Blue'),
34
+ Purple: t('Purple')
35
+ };
36
+ return options.map(colorOption => {
37
+ const label = localizedColorNames[colorOption.label];
38
+ if (label && label != colorOption.label) {
39
+ colorOption.label = label;
40
+ }
41
+ return colorOption;
42
+ });
51
43
  }
52
-
53
44
  /**
54
45
  * Creates a unified color definition object from color configuration options.
55
46
  * The object contains the information necessary to both render the UI and initialize the conversion.
@@ -57,12 +48,11 @@ export function getLocalizedColorOptions( locale, options ) {
57
48
  * @param {module:ui/colorgrid/colorgrid~ColorDefinition} options
58
49
  * @returns {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>}
59
50
  */
60
- export function normalizeColorOptions( options ) {
61
- return options
62
- .map( normalizeSingleColorDefinition )
63
- .filter( option => !!option );
51
+ export function normalizeColorOptions(options) {
52
+ return options
53
+ .map(normalizeSingleColorDefinition)
54
+ .filter(option => !!option);
64
55
  }
65
-
66
56
  // Creates a normalized color definition from the user-defined configuration.
67
57
  // The "normalization" means it will create full
68
58
  // {@link module:ui/colorgrid/colorgrid~ColorDefinition `ColorDefinition-like`}
@@ -70,30 +60,31 @@ export function normalizeColorOptions( options ) {
70
60
  //
71
61
  // @param {String|module:ui/colorgrid/colorgrid~ColorDefinition}
72
62
  // @returns {module:ui/colorgrid/colorgrid~ColorDefinition}
73
- export function normalizeSingleColorDefinition( color ) {
74
- if ( typeof color === 'string' ) {
75
- return {
76
- model: color,
77
- label: color,
78
- hasBorder: false,
79
- view: {
80
- name: 'span',
81
- styles: {
82
- color
83
- }
84
- }
85
- };
86
- } else {
87
- return {
88
- model: color.color,
89
- label: color.label || color.color,
90
- hasBorder: color.hasBorder === undefined ? false : color.hasBorder,
91
- view: {
92
- name: 'span',
93
- styles: {
94
- color: `${ color.color }`
95
- }
96
- }
97
- };
98
- }
63
+ export function normalizeSingleColorDefinition(color) {
64
+ if (typeof color === 'string') {
65
+ return {
66
+ model: color,
67
+ label: color,
68
+ hasBorder: false,
69
+ view: {
70
+ name: 'span',
71
+ styles: {
72
+ color
73
+ }
74
+ }
75
+ };
76
+ }
77
+ else {
78
+ return {
79
+ model: color.color,
80
+ label: color.label || color.color,
81
+ hasBorder: color.hasBorder === undefined ? false : color.hasBorder,
82
+ view: {
83
+ name: 'span',
84
+ styles: {
85
+ color: `${color.color}`
86
+ }
87
+ }
88
+ };
89
+ }
99
90
  }