@ckeditor/ckeditor5-table 35.1.0 → 35.2.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.
@@ -7,9 +7,9 @@
7
7
  * @module table/ui/inserttableview
8
8
  */
9
9
 
10
- import { View, addKeyboardHandlingForGrid } from 'ckeditor5/src/ui';
10
+ import { View, ButtonView, addKeyboardHandlingForGrid } from 'ckeditor5/src/ui';
11
11
 
12
- import { KeystrokeHandler, FocusTracker, uid } from 'ckeditor5/src/utils';
12
+ import { KeystrokeHandler, FocusTracker } from 'ckeditor5/src/utils';
13
13
 
14
14
  import './../../theme/inserttable.css';
15
15
 
@@ -31,23 +31,19 @@ export default class InsertTableView extends View {
31
31
  const bind = this.bindTemplate;
32
32
 
33
33
  /**
34
- * A unique id of a label element displaying the current geometry of the table.
35
- * Used by every {@link #items item} of the view as a pointer to an accessible label.
34
+ * A collection of table size box items.
36
35
  *
37
- * @private
38
36
  * @readonly
39
- * @member {String}
37
+ * @member {module:ui/viewcollection~ViewCollection}
40
38
  */
41
- this._geometryLabelId = `ck-editor__label_${ uid() }`;
39
+ this.items = this._createGridCollection();
42
40
 
43
41
  /**
44
- * A collection of table size box items.
42
+ * Listen to `keydown` events fired in this view's main element.
45
43
  *
46
44
  * @readonly
47
- * @member {module:ui/viewcollection~ViewCollection}
45
+ * @member {module:utils/keystrokeHandler~KeystrokeHandler}
48
46
  */
49
- this.items = this._createGridCollection();
50
-
51
47
  this.keystrokes = new KeystrokeHandler();
52
48
 
53
49
  /**
@@ -103,11 +99,11 @@ export default class InsertTableView extends View {
103
99
  {
104
100
  tag: 'div',
105
101
  attributes: {
106
- id: this._geometryLabelId,
107
102
  class: [
108
103
  'ck',
109
104
  'ck-insert-table-dropdown__label'
110
- ]
105
+ ],
106
+ 'aria-hidden': true
111
107
  },
112
108
  children: [
113
109
  {
@@ -124,13 +120,6 @@ export default class InsertTableView extends View {
124
120
 
125
121
  click: bind.to( () => {
126
122
  this.fire( 'execute' );
127
- } ),
128
-
129
- keydown: bind.to( evt => {
130
- if ( evt.key === 'Enter' ) {
131
- this.fire( 'execute' );
132
- evt.preventDefault();
133
- }
134
123
  } )
135
124
  }
136
125
  } );
@@ -138,8 +127,7 @@ export default class InsertTableView extends View {
138
127
  // #rows and #columns are set via changes to #focusTracker on mouse over.
139
128
  this.on( 'boxover', ( evt, domEvt ) => {
140
129
  const { row, column } = domEvt.target.dataset;
141
-
142
- this.items.get( ( row - 1 ) * 10 + ( column - 1 ) ).focus();
130
+ this.items.get( ( parseInt( row, 10 ) - 1 ) * 10 + ( parseInt( column, 10 ) - 1 ) ).focus();
143
131
  } );
144
132
 
145
133
  // This allows the #rows and #columns to be updated when:
@@ -215,6 +203,34 @@ export default class InsertTableView extends View {
215
203
  } );
216
204
  }
217
205
 
206
+ /**
207
+ * Creates a new Button for the grid.
208
+ *
209
+ * @private
210
+ * @param {module:utils/locale~Locale} locale The locale instance.
211
+ * @param {Number} row Row number.
212
+ * @param {Number} column Column number.
213
+ * @param {String} label The grid button label.
214
+ * @returns {module:ui/button/buttonview~ButtonView}
215
+ */
216
+ _createGridButton( locale, row, column, label ) {
217
+ const button = new ButtonView( locale );
218
+
219
+ button.set( {
220
+ label,
221
+ class: 'ck-insert-table-dropdown-grid-box'
222
+ } );
223
+
224
+ button.extendTemplate( {
225
+ attributes: {
226
+ 'data-row': row,
227
+ 'data-column': column
228
+ }
229
+ } );
230
+
231
+ return button;
232
+ }
233
+
218
234
  /**
219
235
  * @private
220
236
  * @returns {module:ui/viewcollection~ViewCollection} A view collection containing boxes to be placed in a table grid.
@@ -226,8 +242,9 @@ export default class InsertTableView extends View {
226
242
  for ( let index = 0; index < 100; index++ ) {
227
243
  const row = Math.floor( index / 10 );
228
244
  const column = index % 10;
245
+ const label = `${ row + 1 } × ${ column + 1 }`;
229
246
 
230
- boxes.push( new TableSizeGridBoxView( this.locale, row + 1, column + 1, this._geometryLabelId ) );
247
+ boxes.push( this._createGridButton( this.locale, row + 1, column + 1, label ) );
231
248
  }
232
249
 
233
250
  return this.createCollection( boxes );
@@ -239,51 +256,3 @@ export default class InsertTableView extends View {
239
256
  * @event boxover
240
257
  */
241
258
  }
242
-
243
- /**
244
- * A single grid box view element.
245
- *
246
- * This class is used to render the table size selection grid in {@link module:table/ui/inserttableview~InsertTableView}.
247
- *
248
- * @private
249
- */
250
- class TableSizeGridBoxView extends View {
251
- /**
252
- * @inheritDoc
253
- */
254
- constructor( locale, row, column, ariaLabelledById ) {
255
- super( locale );
256
-
257
- const bind = this.bindTemplate;
258
-
259
- /**
260
- * Controls whether the grid box view is "on".
261
- *
262
- * @observable
263
- * @member {Boolean} #isOn
264
- */
265
- this.set( 'isOn', false );
266
-
267
- this.setTemplate( {
268
- tag: 'div',
269
- attributes: {
270
- class: [
271
- 'ck',
272
- 'ck-insert-table-dropdown-grid-box',
273
- bind.if( 'isOn', 'ck-on' )
274
- ],
275
- 'data-row': row,
276
- 'data-column': column,
277
- 'tabindex': -1,
278
- 'aria-labelledby': ariaLabelledById
279
- }
280
- } );
281
- }
282
-
283
- /**
284
- * @inheritDoc
285
- */
286
- focus() {
287
- this.element.focus();
288
- }
289
- }
@@ -7,6 +7,8 @@
7
7
  * @module table/utils/common
8
8
  */
9
9
 
10
+ import { downcastAttributeToStyle, upcastStyleToAttribute } from './../converters/tableproperties';
11
+
10
12
  /**
11
13
  * A common method to update the numeric value. If a value is the default one, it will be unset.
12
14
  *
@@ -55,3 +57,25 @@ export function isHeadingColumnCell( tableUtils, tableCell ) {
55
57
 
56
58
  return !!headingColumns && column < headingColumns;
57
59
  }
60
+
61
+ /**
62
+ * Enables conversion for an attribute for simple view-model mappings.
63
+ *
64
+ * @param {module:engine/model/schema~Schema} schema
65
+ * @param {module:engine/conversion/conversion~Conversion} conversion
66
+ * @param {Object} options
67
+ * @param {String} options.modelAttribute
68
+ * @param {String} options.styleName
69
+ * @param {String} options.defaultValue The default value for the specified `modelAttribute`.
70
+ * @param {Boolean} [options.reduceBoxSides=false]
71
+ */
72
+ export function enableProperty( schema, conversion, options ) {
73
+ const { modelAttribute } = options;
74
+
75
+ schema.extend( 'tableCell', {
76
+ allowAttributes: [ modelAttribute ]
77
+ } );
78
+
79
+ upcastStyleToAttribute( conversion, { viewElement: /^(td|th)$/, ...options } );
80
+ downcastAttributeToStyle( conversion, { modelElement: 'tableCell', ...options } );
81
+ }
@@ -372,29 +372,29 @@ export const defaultColors = [
372
372
  */
373
373
  export function getLabeledColorInputCreator( options ) {
374
374
  return ( labeledFieldView, viewUid, statusUid ) => {
375
- const inputView = new ColorInputView( labeledFieldView.locale, {
375
+ const colorInputView = new ColorInputView( labeledFieldView.locale, {
376
376
  colorDefinitions: colorConfigToColorGridDefinitions( options.colorConfig ),
377
377
  columns: options.columns,
378
378
  defaultColorValue: options.defaultColorValue
379
379
  } );
380
380
 
381
- inputView.set( {
381
+ colorInputView.inputView.set( {
382
382
  id: viewUid,
383
383
  ariaDescribedById: statusUid
384
384
  } );
385
385
 
386
- inputView.bind( 'isReadOnly' ).to( labeledFieldView, 'isEnabled', value => !value );
387
- inputView.bind( 'hasError' ).to( labeledFieldView, 'errorText', value => !!value );
386
+ colorInputView.bind( 'isReadOnly' ).to( labeledFieldView, 'isEnabled', value => !value );
387
+ colorInputView.bind( 'hasError' ).to( labeledFieldView, 'errorText', value => !!value );
388
388
 
389
- inputView.on( 'input', () => {
389
+ colorInputView.on( 'input', () => {
390
390
  // UX: Make the error text disappear and disable the error indicator as the user
391
391
  // starts fixing the errors.
392
392
  labeledFieldView.errorText = null;
393
393
  } );
394
394
 
395
- labeledFieldView.bind( 'isEmpty', 'isFocused' ).to( inputView );
395
+ labeledFieldView.bind( 'isEmpty', 'isFocused' ).to( colorInputView );
396
396
 
397
- return inputView;
397
+ return colorInputView;
398
398
  };
399
399
  }
400
400