@ckeditor/ckeditor5-table 36.0.1 → 37.0.0-alpha.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 (166) hide show
  1. package/build/table.js +1 -1
  2. package/package.json +34 -29
  3. package/src/commands/insertcolumncommand.d.ts +61 -0
  4. package/src/commands/insertcolumncommand.js +45 -60
  5. package/src/commands/insertrowcommand.d.ts +60 -0
  6. package/src/commands/insertrowcommand.js +44 -59
  7. package/src/commands/inserttablecommand.d.ts +50 -0
  8. package/src/commands/inserttablecommand.js +51 -68
  9. package/src/commands/mergecellcommand.d.ts +76 -0
  10. package/src/commands/mergecellcommand.js +169 -244
  11. package/src/commands/mergecellscommand.d.ts +33 -0
  12. package/src/commands/mergecellscommand.js +72 -101
  13. package/src/commands/removecolumncommand.d.ts +34 -0
  14. package/src/commands/removecolumncommand.js +88 -102
  15. package/src/commands/removerowcommand.d.ts +34 -0
  16. package/src/commands/removerowcommand.js +63 -80
  17. package/src/commands/selectcolumncommand.d.ts +38 -0
  18. package/src/commands/selectcolumncommand.js +41 -54
  19. package/src/commands/selectrowcommand.d.ts +38 -0
  20. package/src/commands/selectrowcommand.js +38 -48
  21. package/src/commands/setheadercolumncommand.d.ts +55 -0
  22. package/src/commands/setheadercolumncommand.js +48 -73
  23. package/src/commands/setheaderrowcommand.d.ts +58 -0
  24. package/src/commands/setheaderrowcommand.js +56 -85
  25. package/src/commands/splitcellcommand.d.ts +49 -0
  26. package/src/commands/splitcellcommand.js +35 -49
  27. package/src/converters/downcast.d.ts +63 -0
  28. package/src/converters/downcast.js +98 -130
  29. package/src/converters/table-caption-post-fixer.d.ts +20 -0
  30. package/src/converters/table-caption-post-fixer.js +36 -52
  31. package/src/converters/table-cell-paragraph-post-fixer.d.ts +32 -0
  32. package/src/converters/table-cell-paragraph-post-fixer.js +88 -119
  33. package/src/converters/table-cell-refresh-handler.d.ts +18 -0
  34. package/src/converters/table-cell-refresh-handler.js +29 -48
  35. package/src/converters/table-headings-refresh-handler.d.ts +17 -0
  36. package/src/converters/table-headings-refresh-handler.js +35 -54
  37. package/src/converters/table-layout-post-fixer.d.ts +226 -0
  38. package/src/converters/table-layout-post-fixer.js +276 -313
  39. package/src/converters/tableproperties.d.ts +54 -0
  40. package/src/converters/tableproperties.js +136 -168
  41. package/src/converters/upcasttable.d.ts +49 -0
  42. package/src/converters/upcasttable.js +196 -251
  43. package/src/index.d.ts +29 -0
  44. package/src/index.js +0 -2
  45. package/src/plaintableoutput.d.ts +30 -0
  46. package/src/plaintableoutput.js +107 -135
  47. package/src/table.d.ts +38 -0
  48. package/src/table.js +12 -88
  49. package/src/tablecaption/tablecaptionediting.d.ts +68 -0
  50. package/src/tablecaption/tablecaptionediting.js +104 -135
  51. package/src/tablecaption/tablecaptionui.d.ts +26 -0
  52. package/src/tablecaption/tablecaptionui.js +42 -58
  53. package/src/tablecaption/toggletablecaptioncommand.d.ts +73 -0
  54. package/src/tablecaption/toggletablecaptioncommand.js +77 -92
  55. package/src/tablecaption/utils.d.ts +42 -0
  56. package/src/tablecaption/utils.js +35 -61
  57. package/src/tablecaption.d.ts +27 -0
  58. package/src/tablecaption.js +12 -19
  59. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.d.ts +37 -0
  60. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.js +14 -20
  61. package/src/tablecellproperties/commands/tablecellbordercolorcommand.d.ts +42 -0
  62. package/src/tablecellproperties/commands/tablecellbordercolorcommand.js +27 -37
  63. package/src/tablecellproperties/commands/tablecellborderstylecommand.d.ts +42 -0
  64. package/src/tablecellproperties/commands/tablecellborderstylecommand.js +27 -37
  65. package/src/tablecellproperties/commands/tablecellborderwidthcommand.d.ts +56 -0
  66. package/src/tablecellproperties/commands/tablecellborderwidthcommand.js +42 -53
  67. package/src/tablecellproperties/commands/tablecellheightcommand.d.ts +51 -0
  68. package/src/tablecellproperties/commands/tablecellheightcommand.js +29 -36
  69. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.d.ts +37 -0
  70. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.js +14 -20
  71. package/src/tablecellproperties/commands/tablecellpaddingcommand.d.ts +56 -0
  72. package/src/tablecellproperties/commands/tablecellpaddingcommand.js +42 -53
  73. package/src/tablecellproperties/commands/tablecellpropertycommand.d.ts +62 -0
  74. package/src/tablecellproperties/commands/tablecellpropertycommand.js +77 -122
  75. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.d.ts +45 -0
  76. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.js +14 -20
  77. package/src/tablecellproperties/tablecellpropertiesediting.d.ts +47 -0
  78. package/src/tablecellproperties/tablecellpropertiesediting.js +194 -236
  79. package/src/tablecellproperties/tablecellpropertiesui.d.ts +117 -0
  80. package/src/tablecellproperties/tablecellpropertiesui.js +303 -456
  81. package/src/tablecellproperties/ui/tablecellpropertiesview.d.ts +227 -0
  82. package/src/tablecellproperties/ui/tablecellpropertiesview.js +509 -844
  83. package/src/tablecellproperties.d.ts +33 -0
  84. package/src/tablecellproperties.js +12 -98
  85. package/src/tablecellwidth/commands/tablecellwidthcommand.d.ts +51 -0
  86. package/src/tablecellwidth/commands/tablecellwidthcommand.js +29 -35
  87. package/src/tablecellwidth/tablecellwidthediting.d.ts +34 -0
  88. package/src/tablecellwidth/tablecellwidthediting.js +26 -38
  89. package/src/tableclipboard.d.ts +68 -0
  90. package/src/tableclipboard.js +429 -568
  91. package/src/tablecolumnresize/constants.d.ts +20 -0
  92. package/src/tablecolumnresize/constants.js +0 -10
  93. package/src/tablecolumnresize/converters.d.ts +18 -0
  94. package/src/tablecolumnresize/converters.js +35 -119
  95. package/src/tablecolumnresize/tablecolumnresizeediting.d.ts +142 -0
  96. package/src/tablecolumnresize/tablecolumnresizeediting.js +545 -711
  97. package/src/tablecolumnresize/tablewidthscommand.d.ts +38 -0
  98. package/src/tablecolumnresize/tablewidthscommand.js +61 -0
  99. package/src/tablecolumnresize/utils.d.ts +141 -0
  100. package/src/tablecolumnresize/utils.js +256 -233
  101. package/src/tablecolumnresize.d.ts +29 -0
  102. package/src/tablecolumnresize.js +12 -19
  103. package/src/tableconfig.d.ts +341 -0
  104. package/src/tableconfig.js +5 -0
  105. package/src/tableediting.d.ts +102 -0
  106. package/src/tableediting.js +157 -176
  107. package/src/tablekeyboard.d.ts +68 -0
  108. package/src/tablekeyboard.js +261 -344
  109. package/src/tablemouse/mouseeventsobserver.d.ts +62 -0
  110. package/src/tablemouse/mouseeventsobserver.js +12 -49
  111. package/src/tablemouse.d.ts +51 -0
  112. package/src/tablemouse.js +154 -202
  113. package/src/tableproperties/commands/tablealignmentcommand.d.ts +37 -0
  114. package/src/tableproperties/commands/tablealignmentcommand.js +14 -20
  115. package/src/tableproperties/commands/tablebackgroundcolorcommand.d.ts +37 -0
  116. package/src/tableproperties/commands/tablebackgroundcolorcommand.js +14 -20
  117. package/src/tableproperties/commands/tablebordercolorcommand.d.ts +42 -0
  118. package/src/tableproperties/commands/tablebordercolorcommand.js +27 -37
  119. package/src/tableproperties/commands/tableborderstylecommand.d.ts +42 -0
  120. package/src/tableproperties/commands/tableborderstylecommand.js +27 -37
  121. package/src/tableproperties/commands/tableborderwidthcommand.d.ts +56 -0
  122. package/src/tableproperties/commands/tableborderwidthcommand.js +42 -53
  123. package/src/tableproperties/commands/tableheightcommand.d.ts +51 -0
  124. package/src/tableproperties/commands/tableheightcommand.js +29 -33
  125. package/src/tableproperties/commands/tablepropertycommand.d.ts +61 -0
  126. package/src/tableproperties/commands/tablepropertycommand.js +68 -112
  127. package/src/tableproperties/commands/tablewidthcommand.d.ts +51 -0
  128. package/src/tableproperties/commands/tablewidthcommand.js +29 -33
  129. package/src/tableproperties/tablepropertiesediting.d.ts +45 -0
  130. package/src/tableproperties/tablepropertiesediting.js +164 -210
  131. package/src/tableproperties/tablepropertiesui.d.ts +119 -0
  132. package/src/tableproperties/tablepropertiesui.js +294 -439
  133. package/src/tableproperties/ui/tablepropertiesview.d.ts +203 -0
  134. package/src/tableproperties/ui/tablepropertiesview.js +427 -718
  135. package/src/tableproperties.d.ts +33 -0
  136. package/src/tableproperties.js +12 -95
  137. package/src/tableselection.d.ts +111 -0
  138. package/src/tableselection.js +279 -376
  139. package/src/tabletoolbar.d.ts +37 -0
  140. package/src/tabletoolbar.js +39 -92
  141. package/src/tableui.d.ts +58 -0
  142. package/src/tableui.js +281 -338
  143. package/src/tableutils.d.ts +453 -0
  144. package/src/tableutils.js +1015 -1229
  145. package/src/tablewalker.d.ts +323 -0
  146. package/src/tablewalker.js +308 -548
  147. package/src/ui/colorinputview.d.ts +143 -0
  148. package/src/ui/colorinputview.js +229 -366
  149. package/src/ui/formrowview.d.ts +61 -0
  150. package/src/ui/formrowview.js +38 -84
  151. package/src/ui/inserttableview.d.ts +77 -0
  152. package/src/ui/inserttableview.js +152 -242
  153. package/src/utils/common.d.ts +42 -0
  154. package/src/utils/common.js +33 -57
  155. package/src/utils/structure.d.ts +245 -0
  156. package/src/utils/structure.js +261 -379
  157. package/src/utils/table-properties.d.ts +67 -0
  158. package/src/utils/table-properties.js +60 -81
  159. package/src/utils/ui/contextualballoon.d.ts +34 -0
  160. package/src/utils/ui/contextualballoon.js +70 -89
  161. package/src/utils/ui/table-properties.d.ts +193 -0
  162. package/src/utils/ui/table-properties.js +259 -319
  163. package/src/utils/ui/widget.d.ts +16 -0
  164. package/src/utils/ui/widget.js +24 -46
  165. package/src/tablecolumnresize/tablecolumnwidthscommand.js +0 -55
  166. package/src/tablecolumnresize/tablewidthresizecommand.js +0 -65
@@ -2,154 +2,117 @@
2
2
  * @license Copyright (c) 2003-2023, 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 table/utils/ui/table-properties
8
7
  */
9
-
10
8
  import { ButtonView, Model } from 'ckeditor5/src/ui';
11
9
  import { Collection } from 'ckeditor5/src/utils';
12
10
  import { isColor, isLength, isPercentage } from 'ckeditor5/src/engine';
13
-
14
11
  import ColorInputView from '../../ui/colorinputview';
15
-
16
- const isEmpty = val => val === '';
17
-
12
+ const isEmpty = (val) => val === '';
18
13
  /**
19
14
  * Returns an object containing pairs of CSS border style values and their localized UI
20
15
  * labels. Used by {@link module:table/tablecellproperties/ui/tablecellpropertiesview~TableCellPropertiesView}
21
16
  * and {@link module:table/tableproperties/ui/tablepropertiesview~TablePropertiesView}.
22
17
  *
23
- * @param {module:utils/locale~Locale#t} t The "t" function provided by the editor
24
- * that is used to localize strings.
25
- * @returns {Object.<String,String>}
18
+ * @param t The "t" function provided by the editor that is used to localize strings.
26
19
  */
27
- export function getBorderStyleLabels( t ) {
28
- return {
29
- none: t( 'None' ),
30
- solid: t( 'Solid' ),
31
- dotted: t( 'Dotted' ),
32
- dashed: t( 'Dashed' ),
33
- double: t( 'Double' ),
34
- groove: t( 'Groove' ),
35
- ridge: t( 'Ridge' ),
36
- inset: t( 'Inset' ),
37
- outset: t( 'Outset' )
38
- };
20
+ export function getBorderStyleLabels(t) {
21
+ return {
22
+ none: t('None'),
23
+ solid: t('Solid'),
24
+ dotted: t('Dotted'),
25
+ dashed: t('Dashed'),
26
+ double: t('Double'),
27
+ groove: t('Groove'),
28
+ ridge: t('Ridge'),
29
+ inset: t('Inset'),
30
+ outset: t('Outset')
31
+ };
39
32
  }
40
-
41
33
  /**
42
34
  * Returns a localized error string that can be displayed next to color (background, border)
43
35
  * fields that have an invalid value.
44
36
  *
45
- * @param {module:utils/locale~Locale#t} t The "t" function provided by the editor
46
- * that is used to localize strings.
47
- * @returns {String}
37
+ * @param t The "t" function provided by the editor that is used to localize strings.
48
38
  */
49
- export function getLocalizedColorErrorText( t ) {
50
- return t( 'The color is invalid. Try "#FF0000" or "rgb(255,0,0)" or "red".' );
39
+ export function getLocalizedColorErrorText(t) {
40
+ return t('The color is invalid. Try "#FF0000" or "rgb(255,0,0)" or "red".');
51
41
  }
52
-
53
42
  /**
54
43
  * Returns a localized error string that can be displayed next to length (padding, border width)
55
44
  * fields that have an invalid value.
56
45
  *
57
- * @param {module:utils/locale~Locale#t} t The "t" function provided by the editor
58
- * that is used to localize strings.
59
- * @returns {String}
46
+ * @param t The "t" function provided by the editor that is used to localize strings.
60
47
  */
61
- export function getLocalizedLengthErrorText( t ) {
62
- return t( 'The value is invalid. Try "10px" or "2em" or simply "2".' );
48
+ export function getLocalizedLengthErrorText(t) {
49
+ return t('The value is invalid. Try "10px" or "2em" or simply "2".');
63
50
  }
64
-
65
51
  /**
66
52
  * Returns `true` when the passed value is an empty string or a valid CSS color expression.
67
53
  * Otherwise, `false` is returned.
68
54
  *
69
55
  * See {@link module:engine/view/styles/utils~isColor}.
70
- *
71
- * @param {String} value
72
- * @returns {Boolean}
73
56
  */
74
- export function colorFieldValidator( value ) {
75
- value = value.trim();
76
-
77
- return isEmpty( value ) || isColor( value );
57
+ export function colorFieldValidator(value) {
58
+ value = value.trim();
59
+ return isEmpty(value) || isColor(value);
78
60
  }
79
-
80
61
  /**
81
62
  * Returns `true` when the passed value is an empty string, a number without a unit or a valid CSS length expression.
82
63
  * Otherwise, `false` is returned.
83
64
  *
84
65
  * See {@link module:engine/view/styles/utils~isLength}.
85
66
  * See {@link module:engine/view/styles/utils~isPercentage}.
86
- *
87
- * @param {String} value
88
- * @returns {Boolean}
89
67
  */
90
- export function lengthFieldValidator( value ) {
91
- value = value.trim();
92
-
93
- return isEmpty( value ) || isNumberString( value ) || isLength( value ) || isPercentage( value );
68
+ export function lengthFieldValidator(value) {
69
+ value = value.trim();
70
+ return isEmpty(value) || isNumberString(value) || isLength(value) || isPercentage(value);
94
71
  }
95
-
96
72
  /**
97
73
  * Returns `true` when the passed value is an empty string, a number without a unit or a valid CSS length expression.
98
74
  * Otherwise, `false` is returned.
99
75
  *
100
76
  * See {@link module:engine/view/styles/utils~isLength}.
101
- *
102
- * @param {String} value
103
- * @returns {Boolean}
104
77
  */
105
- export function lineWidthFieldValidator( value ) {
106
- value = value.trim();
107
-
108
- return isEmpty( value ) || isNumberString( value ) || isLength( value );
78
+ export function lineWidthFieldValidator(value) {
79
+ value = value.trim();
80
+ return isEmpty(value) || isNumberString(value) || isLength(value);
109
81
  }
110
-
111
82
  /**
112
83
  * Generates item definitions for a UI dropdown that allows changing the border style of a table or a table cell.
113
84
  *
114
- * @param {module:table/tablecellproperties/ui/tablecellpropertiesview~TableCellPropertiesView|
115
- * module:table/tableproperties/ui/tablepropertiesview~TablePropertiesView} view
116
- * @param {String} defaultStyle The default border.
117
- * @returns {Iterable.<module:ui/dropdown/utils~ListDropdownItemDefinition>}
85
+ * @param defaultStyle The default border.
118
86
  */
119
- export function getBorderStyleDefinitions( view, defaultStyle ) {
120
- const itemDefinitions = new Collection();
121
- const styleLabels = getBorderStyleLabels( view.t );
122
-
123
- for ( const style in styleLabels ) {
124
- const definition = {
125
- type: 'button',
126
- model: new Model( {
127
- _borderStyleValue: style,
128
- label: styleLabels[ style ],
129
- withText: true
130
- } )
131
- };
132
-
133
- if ( style === 'none' ) {
134
- definition.model.bind( 'isOn' ).to( view, 'borderStyle', value => {
135
- if ( defaultStyle === 'none' ) {
136
- return !value;
137
- }
138
-
139
- return value === style;
140
- } );
141
- } else {
142
- definition.model.bind( 'isOn' ).to( view, 'borderStyle', value => {
143
- return value === style;
144
- } );
145
- }
146
-
147
- itemDefinitions.add( definition );
148
- }
149
-
150
- return itemDefinitions;
87
+ export function getBorderStyleDefinitions(view, defaultStyle) {
88
+ const itemDefinitions = new Collection();
89
+ const styleLabels = getBorderStyleLabels(view.t);
90
+ for (const style in styleLabels) {
91
+ const definition = {
92
+ type: 'button',
93
+ model: new Model({
94
+ _borderStyleValue: style,
95
+ label: styleLabels[style],
96
+ withText: true
97
+ })
98
+ };
99
+ if (style === 'none') {
100
+ definition.model.bind('isOn').to(view, 'borderStyle', value => {
101
+ if (defaultStyle === 'none') {
102
+ return !value;
103
+ }
104
+ return value === style;
105
+ });
106
+ }
107
+ else {
108
+ definition.model.bind('isOn').to(view, 'borderStyle', value => {
109
+ return value === style;
110
+ });
111
+ }
112
+ itemDefinitions.add(definition);
113
+ }
114
+ return itemDefinitions;
151
115
  }
152
-
153
116
  /**
154
117
  * A helper that fills a toolbar with buttons that:
155
118
  *
@@ -157,185 +120,171 @@ export function getBorderStyleDefinitions( view, defaultStyle ) {
157
120
  * * have some icons,
158
121
  * * set a certain UI view property value upon execution.
159
122
  *
160
- * @param {Object} options
161
- * @param {module:table/tablecellproperties/ui/tablecellpropertiesview~TableCellPropertiesView|
162
- * module:table/tableproperties/ui/tablepropertiesview~TablePropertiesView} options.view
163
- * @param {Array.<String>} options.icons
164
- * @param {module:ui/toolbar/toolbarview~ToolbarView} options.toolbar
165
- * @param {Object.<String,String>} labels
166
- * @param {String} propertyName
167
- * @param {Function} nameToValue A function that maps a button name to a value. By default names are the same as values.
123
+ * @param nameToValue A function that maps a button name to a value. By default names are the same as values.
168
124
  */
169
- export function fillToolbar( options ) {
170
- const { view, icons, toolbar, labels, propertyName, nameToValue, defaultValue } = options;
171
- for ( const name in labels ) {
172
- const button = new ButtonView( view.locale );
173
-
174
- button.set( {
175
- label: labels[ name ],
176
- icon: icons[ name ],
177
- tooltip: labels[ name ]
178
- } );
179
-
180
- // If specified the `nameToValue()` callback, map the value based on the option's name.
181
- const buttonValue = nameToValue ? nameToValue( name ) : name;
182
-
183
- button.bind( 'isOn' ).to( view, propertyName, value => {
184
- // `value` comes from `view[ propertyName ]`.
185
- let valueToCompare = value;
186
-
187
- // If it's empty, and the `defaultValue` is specified, use it instead.
188
- if ( value === '' && defaultValue ) {
189
- valueToCompare = defaultValue;
190
- }
191
-
192
- return buttonValue === valueToCompare;
193
- } );
194
-
195
- button.on( 'execute', () => {
196
- view[ propertyName ] = buttonValue;
197
- } );
198
-
199
- toolbar.items.add( button );
200
- }
125
+ export function fillToolbar(options) {
126
+ const { view, icons, toolbar, labels, propertyName, nameToValue, defaultValue } = options;
127
+ for (const name in labels) {
128
+ const button = new ButtonView(view.locale);
129
+ button.set({
130
+ label: labels[name],
131
+ icon: icons[name],
132
+ tooltip: labels[name]
133
+ });
134
+ // If specified the `nameToValue()` callback, map the value based on the option's name.
135
+ const buttonValue = nameToValue ? nameToValue(name) : name;
136
+ button.bind('isOn').to(view, propertyName, value => {
137
+ // `value` comes from `view[ propertyName ]`.
138
+ let valueToCompare = value;
139
+ // If it's empty, and the `defaultValue` is specified, use it instead.
140
+ if (value === '' && defaultValue) {
141
+ valueToCompare = defaultValue;
142
+ }
143
+ return buttonValue === valueToCompare;
144
+ });
145
+ button.on('execute', () => {
146
+ view[propertyName] = buttonValue;
147
+ });
148
+ toolbar.items.add(button);
149
+ }
201
150
  }
202
-
203
151
  /**
204
152
  * A default color palette used by various user interfaces related to tables, for instance,
205
153
  * by {@link module:table/tablecellproperties/tablecellpropertiesui~TableCellPropertiesUI} or
206
154
  * {@link module:table/tableproperties/tablepropertiesui~TablePropertiesUI}.
207
155
  *
208
- * The color palette follows the {@link module:table/table~TableColorConfig table color configuration format}
156
+ * The color palette follows the {@link module:table/tableconfig~TableColorConfig table color configuration format}
209
157
  * and contains the following color definitions:
210
158
  *
211
- * const defaultColors = [
212
- * {
213
- * color: 'hsl(0, 0%, 0%)',
214
- * label: 'Black'
215
- * },
216
- * {
217
- * color: 'hsl(0, 0%, 30%)',
218
- * label: 'Dim grey'
219
- * },
220
- * {
221
- * color: 'hsl(0, 0%, 60%)',
222
- * label: 'Grey'
223
- * },
224
- * {
225
- * color: 'hsl(0, 0%, 90%)',
226
- * label: 'Light grey'
227
- * },
228
- * {
229
- * color: 'hsl(0, 0%, 100%)',
230
- * label: 'White',
231
- * hasBorder: true
232
- * },
233
- * {
234
- * color: 'hsl(0, 75%, 60%)',
235
- * label: 'Red'
236
- * },
237
- * {
238
- * color: 'hsl(30, 75%, 60%)',
239
- * label: 'Orange'
240
- * },
241
- * {
242
- * color: 'hsl(60, 75%, 60%)',
243
- * label: 'Yellow'
244
- * },
245
- * {
246
- * color: 'hsl(90, 75%, 60%)',
247
- * label: 'Light green'
248
- * },
249
- * {
250
- * color: 'hsl(120, 75%, 60%)',
251
- * label: 'Green'
252
- * },
253
- * {
254
- * color: 'hsl(150, 75%, 60%)',
255
- * label: 'Aquamarine'
256
- * },
257
- * {
258
- * color: 'hsl(180, 75%, 60%)',
259
- * label: 'Turquoise'
260
- * },
261
- * {
262
- * color: 'hsl(210, 75%, 60%)',
263
- * label: 'Light blue'
264
- * },
265
- * {
266
- * color: 'hsl(240, 75%, 60%)',
267
- * label: 'Blue'
268
- * },
269
- * {
270
- * color: 'hsl(270, 75%, 60%)',
271
- * label: 'Purple'
272
- * }
273
- * ];
159
+ * ```ts
160
+ * const defaultColors = [
161
+ * {
162
+ * color: 'hsl(0, 0%, 0%)',
163
+ * label: 'Black'
164
+ * },
165
+ * {
166
+ * color: 'hsl(0, 0%, 30%)',
167
+ * label: 'Dim grey'
168
+ * },
169
+ * {
170
+ * color: 'hsl(0, 0%, 60%)',
171
+ * label: 'Grey'
172
+ * },
173
+ * {
174
+ * color: 'hsl(0, 0%, 90%)',
175
+ * label: 'Light grey'
176
+ * },
177
+ * {
178
+ * color: 'hsl(0, 0%, 100%)',
179
+ * label: 'White',
180
+ * hasBorder: true
181
+ * },
182
+ * {
183
+ * color: 'hsl(0, 75%, 60%)',
184
+ * label: 'Red'
185
+ * },
186
+ * {
187
+ * color: 'hsl(30, 75%, 60%)',
188
+ * label: 'Orange'
189
+ * },
190
+ * {
191
+ * color: 'hsl(60, 75%, 60%)',
192
+ * label: 'Yellow'
193
+ * },
194
+ * {
195
+ * color: 'hsl(90, 75%, 60%)',
196
+ * label: 'Light green'
197
+ * },
198
+ * {
199
+ * color: 'hsl(120, 75%, 60%)',
200
+ * label: 'Green'
201
+ * },
202
+ * {
203
+ * color: 'hsl(150, 75%, 60%)',
204
+ * label: 'Aquamarine'
205
+ * },
206
+ * {
207
+ * color: 'hsl(180, 75%, 60%)',
208
+ * label: 'Turquoise'
209
+ * },
210
+ * {
211
+ * color: 'hsl(210, 75%, 60%)',
212
+ * label: 'Light blue'
213
+ * },
214
+ * {
215
+ * color: 'hsl(240, 75%, 60%)',
216
+ * label: 'Blue'
217
+ * },
218
+ * {
219
+ * color: 'hsl(270, 75%, 60%)',
220
+ * label: 'Purple'
221
+ * }
222
+ * ];
223
+ * ```
274
224
  */
275
225
  export const defaultColors = [
276
- {
277
- color: 'hsl(0, 0%, 0%)',
278
- label: 'Black'
279
- },
280
- {
281
- color: 'hsl(0, 0%, 30%)',
282
- label: 'Dim grey'
283
- },
284
- {
285
- color: 'hsl(0, 0%, 60%)',
286
- label: 'Grey'
287
- },
288
- {
289
- color: 'hsl(0, 0%, 90%)',
290
- label: 'Light grey'
291
- },
292
- {
293
- color: 'hsl(0, 0%, 100%)',
294
- label: 'White',
295
- hasBorder: true
296
- },
297
- {
298
- color: 'hsl(0, 75%, 60%)',
299
- label: 'Red'
300
- },
301
- {
302
- color: 'hsl(30, 75%, 60%)',
303
- label: 'Orange'
304
- },
305
- {
306
- color: 'hsl(60, 75%, 60%)',
307
- label: 'Yellow'
308
- },
309
- {
310
- color: 'hsl(90, 75%, 60%)',
311
- label: 'Light green'
312
- },
313
- {
314
- color: 'hsl(120, 75%, 60%)',
315
- label: 'Green'
316
- },
317
- {
318
- color: 'hsl(150, 75%, 60%)',
319
- label: 'Aquamarine'
320
- },
321
- {
322
- color: 'hsl(180, 75%, 60%)',
323
- label: 'Turquoise'
324
- },
325
- {
326
- color: 'hsl(210, 75%, 60%)',
327
- label: 'Light blue'
328
- },
329
- {
330
- color: 'hsl(240, 75%, 60%)',
331
- label: 'Blue'
332
- },
333
- {
334
- color: 'hsl(270, 75%, 60%)',
335
- label: 'Purple'
336
- }
226
+ {
227
+ color: 'hsl(0, 0%, 0%)',
228
+ label: 'Black'
229
+ },
230
+ {
231
+ color: 'hsl(0, 0%, 30%)',
232
+ label: 'Dim grey'
233
+ },
234
+ {
235
+ color: 'hsl(0, 0%, 60%)',
236
+ label: 'Grey'
237
+ },
238
+ {
239
+ color: 'hsl(0, 0%, 90%)',
240
+ label: 'Light grey'
241
+ },
242
+ {
243
+ color: 'hsl(0, 0%, 100%)',
244
+ label: 'White',
245
+ hasBorder: true
246
+ },
247
+ {
248
+ color: 'hsl(0, 75%, 60%)',
249
+ label: 'Red'
250
+ },
251
+ {
252
+ color: 'hsl(30, 75%, 60%)',
253
+ label: 'Orange'
254
+ },
255
+ {
256
+ color: 'hsl(60, 75%, 60%)',
257
+ label: 'Yellow'
258
+ },
259
+ {
260
+ color: 'hsl(90, 75%, 60%)',
261
+ label: 'Light green'
262
+ },
263
+ {
264
+ color: 'hsl(120, 75%, 60%)',
265
+ label: 'Green'
266
+ },
267
+ {
268
+ color: 'hsl(150, 75%, 60%)',
269
+ label: 'Aquamarine'
270
+ },
271
+ {
272
+ color: 'hsl(180, 75%, 60%)',
273
+ label: 'Turquoise'
274
+ },
275
+ {
276
+ color: 'hsl(210, 75%, 60%)',
277
+ label: 'Light blue'
278
+ },
279
+ {
280
+ color: 'hsl(240, 75%, 60%)',
281
+ label: 'Blue'
282
+ },
283
+ {
284
+ color: 'hsl(270, 75%, 60%)',
285
+ label: 'Purple'
286
+ }
337
287
  ];
338
-
339
288
  /**
340
289
  * Returns a creator for a color input with a label.
341
290
  *
@@ -352,68 +301,59 @@ export const defaultColors = [
352
301
  *
353
302
  * Usage:
354
303
  *
355
- * const colorInputCreator = getLabeledColorInputCreator( {
356
- * colorConfig: [ ... ],
357
- * columns: 3,
358
- * } );
304
+ * ```ts
305
+ * const colorInputCreator = getLabeledColorInputCreator( {
306
+ * colorConfig: [ ... ],
307
+ * columns: 3,
308
+ * } );
359
309
  *
360
- * const labeledInputView = new LabeledFieldView( locale, colorInputCreator );
361
- * console.log( labeledInputView.view ); // A color input instance.
310
+ * const labeledInputView = new LabeledFieldView( locale, colorInputCreator );
311
+ * console.log( labeledInputView.view ); // A color input instance.
312
+ * ```
362
313
  *
363
- * @private
314
+ * @internal
364
315
  * @param options Color input options.
365
- * @param {module:table/table~TableColorConfig} options.colorConfig The configuration of the color palette
366
- * displayed in the input's dropdown.
367
- * @param {Number} options.columns The configuration of the number of columns the color palette consists of
368
- * in the input's dropdown.
369
- * @param {String} [options.defaultColorValue] If specified, the color input view will replace the "Remove color" button with
316
+ * @param options.colorConfig The configuration of the color palette displayed in the input's dropdown.
317
+ * @param options.columns The configuration of the number of columns the color palette consists of in the input's dropdown.
318
+ * @param options.defaultColorValue If specified, the color input view will replace the "Remove color" button with
370
319
  * the "Restore default" button. Instead of clearing the input field, the default color value will be set.
371
- * @returns {Function}
372
320
  */
373
- export function getLabeledColorInputCreator( options ) {
374
- return ( labeledFieldView, viewUid, statusUid ) => {
375
- const colorInputView = new ColorInputView( labeledFieldView.locale, {
376
- colorDefinitions: colorConfigToColorGridDefinitions( options.colorConfig ),
377
- columns: options.columns,
378
- defaultColorValue: options.defaultColorValue
379
- } );
380
-
381
- colorInputView.inputView.set( {
382
- id: viewUid,
383
- ariaDescribedById: statusUid
384
- } );
385
-
386
- colorInputView.bind( 'isReadOnly' ).to( labeledFieldView, 'isEnabled', value => !value );
387
- colorInputView.bind( 'hasError' ).to( labeledFieldView, 'errorText', value => !!value );
388
-
389
- colorInputView.on( 'input', () => {
390
- // UX: Make the error text disappear and disable the error indicator as the user
391
- // starts fixing the errors.
392
- labeledFieldView.errorText = null;
393
- } );
394
-
395
- labeledFieldView.bind( 'isEmpty', 'isFocused' ).to( colorInputView );
396
-
397
- return colorInputView;
398
- };
321
+ export function getLabeledColorInputCreator(options) {
322
+ return (labeledFieldView, viewUid, statusUid) => {
323
+ const colorInputView = new ColorInputView(labeledFieldView.locale, {
324
+ colorDefinitions: colorConfigToColorGridDefinitions(options.colorConfig),
325
+ columns: options.columns,
326
+ defaultColorValue: options.defaultColorValue
327
+ });
328
+ colorInputView.inputView.set({
329
+ id: viewUid,
330
+ ariaDescribedById: statusUid
331
+ });
332
+ colorInputView.bind('isReadOnly').to(labeledFieldView, 'isEnabled', value => !value);
333
+ colorInputView.bind('hasError').to(labeledFieldView, 'errorText', value => !!value);
334
+ colorInputView.on('input', () => {
335
+ // UX: Make the error text disappear and disable the error indicator as the user
336
+ // starts fixing the errors.
337
+ labeledFieldView.errorText = null;
338
+ });
339
+ labeledFieldView.bind('isEmpty', 'isFocused').to(colorInputView);
340
+ return colorInputView;
341
+ };
399
342
  }
400
-
401
- // A simple helper method to detect number strings.
402
- // I allows full number notation, so omitting 0 is not allowed:
403
- function isNumberString( value ) {
404
- const parsedValue = parseFloat( value );
405
-
406
- return !Number.isNaN( parsedValue ) && value === String( parsedValue );
343
+ /**
344
+ * A simple helper method to detect number strings.
345
+ * I allows full number notation, so omitting 0 is not allowed:
346
+ */
347
+ function isNumberString(value) {
348
+ const parsedValue = parseFloat(value);
349
+ return !Number.isNaN(parsedValue) && value === String(parsedValue);
407
350
  }
408
-
409
- // @param {Array.<Object>} colorConfig
410
- // @returns {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>}
411
- function colorConfigToColorGridDefinitions( colorConfig ) {
412
- return colorConfig.map( item => ( {
413
- color: item.model,
414
- label: item.label,
415
- options: {
416
- hasBorder: item.hasBorder
417
- }
418
- } ) );
351
+ function colorConfigToColorGridDefinitions(colorConfig) {
352
+ return colorConfig.map(item => ({
353
+ color: item.model,
354
+ label: item.label,
355
+ options: {
356
+ hasBorder: item.hasBorder
357
+ }
358
+ }));
419
359
  }