@vaadin/grid-pro 24.4.0-dev.4b20a0c55.3 → 24.4.0-rc1

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 (34) hide show
  1. package/package.json +11 -11
  2. package/src/vaadin-grid-pro-edit-column-mixin.d.ts +18 -0
  3. package/src/vaadin-grid-pro-edit-column-mixin.js +32 -9
  4. package/src/vaadin-grid-pro-inline-editing-mixin.js +98 -43
  5. package/theme/lumo/vaadin-grid-pro-edit-checkbox.d.ts +2 -0
  6. package/theme/lumo/vaadin-grid-pro-edit-column.d.ts +4 -0
  7. package/theme/lumo/vaadin-grid-pro-edit-select-styles.d.ts +2 -0
  8. package/theme/lumo/vaadin-grid-pro-edit-select.d.ts +3 -0
  9. package/theme/lumo/vaadin-grid-pro-edit-text-field-styles.d.ts +1 -0
  10. package/theme/lumo/vaadin-grid-pro-edit-text-field.d.ts +3 -0
  11. package/theme/lumo/vaadin-grid-pro-editor-styles.d.ts +5 -0
  12. package/theme/lumo/vaadin-grid-pro-styles.d.ts +2 -0
  13. package/theme/lumo/vaadin-grid-pro.d.ts +3 -0
  14. package/theme/lumo/vaadin-lit-grid-pro-edit-checkbox.d.ts +2 -0
  15. package/theme/lumo/vaadin-lit-grid-pro-edit-column.d.ts +4 -0
  16. package/theme/lumo/vaadin-lit-grid-pro-edit-select.d.ts +3 -0
  17. package/theme/lumo/vaadin-lit-grid-pro-edit-text-field.d.ts +3 -0
  18. package/theme/lumo/vaadin-lit-grid-pro.d.ts +3 -0
  19. package/theme/material/vaadin-grid-pro-edit-checkbox.d.ts +2 -0
  20. package/theme/material/vaadin-grid-pro-edit-column.d.ts +4 -0
  21. package/theme/material/vaadin-grid-pro-edit-select-styles.d.ts +1 -0
  22. package/theme/material/vaadin-grid-pro-edit-select.d.ts +3 -0
  23. package/theme/material/vaadin-grid-pro-edit-text-field-styles.d.ts +1 -0
  24. package/theme/material/vaadin-grid-pro-edit-text-field.d.ts +3 -0
  25. package/theme/material/vaadin-grid-pro-editor-styles.d.ts +2 -0
  26. package/theme/material/vaadin-grid-pro-styles.d.ts +2 -0
  27. package/theme/material/vaadin-grid-pro.d.ts +3 -0
  28. package/theme/material/vaadin-lit-grid-pro-edit-checkbox.d.ts +2 -0
  29. package/theme/material/vaadin-lit-grid-pro-edit-column.d.ts +4 -0
  30. package/theme/material/vaadin-lit-grid-pro-edit-select.d.ts +3 -0
  31. package/theme/material/vaadin-lit-grid-pro-edit-text-field.d.ts +3 -0
  32. package/theme/material/vaadin-lit-grid-pro.d.ts +3 -0
  33. package/web-types.json +910 -0
  34. package/web-types.lit.json +489 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/grid-pro",
3
- "version": "24.4.0-dev.4b20a0c55.3",
3
+ "version": "24.4.0-rc1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -39,15 +39,15 @@
39
39
  "dependencies": {
40
40
  "@open-wc/dedupe-mixin": "^1.3.0",
41
41
  "@polymer/polymer": "^3.0.0",
42
- "@vaadin/checkbox": "24.4.0-dev.4b20a0c55.3",
43
- "@vaadin/component-base": "24.4.0-dev.4b20a0c55.3",
44
- "@vaadin/grid": "24.4.0-dev.4b20a0c55.3",
45
- "@vaadin/lit-renderer": "24.4.0-dev.4b20a0c55.3",
46
- "@vaadin/select": "24.4.0-dev.4b20a0c55.3",
47
- "@vaadin/text-field": "24.4.0-dev.4b20a0c55.3",
48
- "@vaadin/vaadin-lumo-styles": "24.4.0-dev.4b20a0c55.3",
49
- "@vaadin/vaadin-material-styles": "24.4.0-dev.4b20a0c55.3",
50
- "@vaadin/vaadin-themable-mixin": "24.4.0-dev.4b20a0c55.3",
42
+ "@vaadin/checkbox": "24.4.0-rc1",
43
+ "@vaadin/component-base": "24.4.0-rc1",
44
+ "@vaadin/grid": "24.4.0-rc1",
45
+ "@vaadin/lit-renderer": "24.4.0-rc1",
46
+ "@vaadin/select": "24.4.0-rc1",
47
+ "@vaadin/text-field": "24.4.0-rc1",
48
+ "@vaadin/vaadin-lumo-styles": "24.4.0-rc1",
49
+ "@vaadin/vaadin-material-styles": "24.4.0-rc1",
50
+ "@vaadin/vaadin-themable-mixin": "24.4.0-rc1",
51
51
  "lit": "^3.0.0"
52
52
  },
53
53
  "devDependencies": {
@@ -60,5 +60,5 @@
60
60
  "web-types.json",
61
61
  "web-types.lit.json"
62
62
  ],
63
- "gitHead": "41cf17453d7506fb635c088a0425e20b6e82b89b"
63
+ "gitHead": "a81e3b927d44c56613fa4e1307494a2acc81005f"
64
64
  }
@@ -58,6 +58,24 @@ export declare class GridProEditColumnMixinClass<TItem> {
58
58
  */
59
59
  editorValuePath: string;
60
60
 
61
+ /**
62
+ * A function to check whether a specific cell of this column can be
63
+ * edited. This allows to disable editing of individual rows or cells,
64
+ * based on the item.
65
+ *
66
+ * Receives a `model` object containing the item for an individual row,
67
+ * and should return a boolean indicating whether the column's cell in
68
+ * that row is editable.
69
+ *
70
+ * The `model` object contains:
71
+ * - `model.index` The index of the item.
72
+ * - `model.item` The item.
73
+ * - `model.expanded` Sublevel toggle state.
74
+ * - `model.level` Level of the tree represented with a horizontal offset of the toggle button.
75
+ * - `model.selected` Selected state.
76
+ */
77
+ isCellEditable: (model: GridItemModel<TItem>) => boolean;
78
+
61
79
  protected _getEditorComponent(cell: HTMLElement): HTMLElement | null;
62
80
 
63
81
  protected _getEditorValue(editor: HTMLElement): unknown | null;
@@ -8,7 +8,6 @@
8
8
  * See https://vaadin.com/commercial-license-and-service-terms for the full
9
9
  * license.
10
10
  */
11
- import { addValueToAttribute } from '@vaadin/component-base/src/dom-utils.js';
12
11
  import { get, set } from '@vaadin/component-base/src/path-utils.js';
13
12
 
14
13
  /**
@@ -84,13 +83,36 @@ export const GridProEditColumnMixin = (superClass) =>
84
83
  sync: true,
85
84
  },
86
85
 
86
+ /**
87
+ * A function to check whether a specific cell of this column can be
88
+ * edited. This allows to disable editing of individual rows or cells,
89
+ * based on the item.
90
+ *
91
+ * Receives a `model` object containing the item for an individual row,
92
+ * and should return a boolean indicating whether the column's cell in
93
+ * that row is editable.
94
+ *
95
+ * The `model` object contains:
96
+ * - `model.index` The index of the item.
97
+ * - `model.item` The item.
98
+ * - `model.expanded` Sublevel toggle state.
99
+ * - `model.level` Level of the tree represented with a horizontal offset of the toggle button.
100
+ * - `model.selected` Selected state.
101
+ *
102
+ * @type {(model: GridItemModel) => boolean}
103
+ */
104
+ isCellEditable: {
105
+ type: Function,
106
+ observer: '_isCellEditableChanged',
107
+ },
108
+
87
109
  /** @private */
88
110
  _oldRenderer: Function,
89
111
  };
90
112
  }
91
113
 
92
114
  static get observers() {
93
- return ['_editModeRendererChanged(editModeRenderer, __initialized)', '_cellsChanged(_cells)'];
115
+ return ['_editModeRendererChanged(editModeRenderer, __initialized)'];
94
116
  }
95
117
 
96
118
  constructor() {
@@ -121,11 +143,9 @@ export const GridProEditColumnMixin = (superClass) =>
121
143
  }
122
144
 
123
145
  /** @private */
124
- _cellsChanged() {
125
- this._cells.forEach((cell) => {
126
- const target = cell._focusButton || cell;
127
- addValueToAttribute(target, 'part', 'editable-cell');
128
- });
146
+ _isCellEditableChanged(newValue, oldValue) {
147
+ // Re-render grid to update editable-cell part names
148
+ this._grid.requestContentUpdate();
129
149
  }
130
150
 
131
151
  /** @private */
@@ -267,8 +287,11 @@ export const GridProEditColumnMixin = (superClass) =>
267
287
  this._setEditorValue(editor, get(this.path, model.item));
268
288
  editor._grid = this._grid;
269
289
 
270
- this._focusEditor(editor);
271
- requestAnimationFrame(() => this._focusEditor(editor));
290
+ if (editor.updateComplete) {
291
+ editor.updateComplete.then(() => this._focusEditor(editor));
292
+ } else {
293
+ this._focusEditor(editor);
294
+ }
272
295
  }
273
296
 
274
297
  /**
@@ -11,6 +11,7 @@
11
11
  import { animationFrame } from '@vaadin/component-base/src/async.js';
12
12
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
13
13
  import { get, set } from '@vaadin/component-base/src/path-utils.js';
14
+ import { iterateRowCells, updatePart } from '@vaadin/grid/src/vaadin-grid-helpers.js';
14
15
 
15
16
  /**
16
17
  * @polymerMixin
@@ -218,6 +219,10 @@ export const InlineEditingMixin = (superClass) =>
218
219
  return;
219
220
  }
220
221
 
222
+ if (!this._isCellEditable(cell)) {
223
+ return;
224
+ }
225
+
221
226
  callback(e);
222
227
  }
223
228
  });
@@ -325,8 +330,10 @@ export const InlineEditingMixin = (superClass) =>
325
330
 
326
331
  /** @private */
327
332
  _startEdit(cell, column) {
333
+ const isCellEditable = this._isCellEditable(cell);
334
+
328
335
  // TODO: remove `_editingDisabled` after Flow counterpart is updated.
329
- if (this.disabled || this._editingDisabled) {
336
+ if (this.disabled || this._editingDisabled || !isCellEditable) {
330
337
  return;
331
338
  }
332
339
  // Cancel debouncer enqueued on focusout
@@ -421,59 +428,67 @@ export const InlineEditingMixin = (superClass) =>
421
428
 
422
429
  this._cancelStopEdit();
423
430
 
424
- const cols = this._getEditColumns();
425
-
431
+ const editableColumns = this._getEditColumns();
426
432
  const { cell, column, model } = this.__edited;
427
- const colIndex = cols.indexOf(column);
428
- const { index } = model;
429
433
 
430
- let nextCol = null;
431
- let nextIdx = index;
432
-
433
- // Enter key
434
- if (e.keyCode === 13) {
435
- nextCol = column;
436
-
437
- // Move up / down
438
- if (this.enterNextRow) {
439
- nextIdx = e.shiftKey ? index - 1 : index + 1;
440
- }
434
+ this._stopEdit();
435
+ e.preventDefault();
436
+ // Prevent vaadin-grid handler from being called
437
+ e.stopImmediatePropagation();
438
+
439
+ // Try to find the next editable cell
440
+ let nextIndex = model.index;
441
+ let nextColumn = column;
442
+ let nextCell = cell;
443
+ let directionX = 0;
444
+ let directionY = 0;
445
+
446
+ // Enter key: move up / down
447
+ if (e.keyCode === 13 && this.enterNextRow) {
448
+ directionY = e.shiftKey ? -1 : 1;
441
449
  }
442
450
 
443
451
  // Tab: move right / left
444
452
  if (e.keyCode === 9) {
445
- if (e.shiftKey) {
446
- if (cols[colIndex - 1]) {
447
- nextCol = cols[colIndex - 1];
448
- } else if (index > 0) {
449
- nextIdx = index - 1;
450
- nextCol = cols[cols.length - 1];
453
+ directionX = e.shiftKey ? -1 : 1;
454
+ }
455
+
456
+ if (directionX || directionY) {
457
+ while (nextCell) {
458
+ if (directionX) {
459
+ // Move horizontally
460
+ nextColumn = editableColumns[editableColumns.indexOf(nextColumn) + directionX];
461
+ if (!nextColumn) {
462
+ // Wrap to the next or previous row
463
+ nextIndex += directionX;
464
+ nextColumn = editableColumns[directionX > 0 ? 0 : editableColumns.length - 1];
465
+ }
466
+ }
467
+ // Move vertically
468
+ if (directionY) {
469
+ nextIndex += directionY;
470
+ }
471
+ // Stop looking if the next cell is editable
472
+ const nextRow = this._getRowByIndex(nextIndex);
473
+ // eslint-disable-next-line @typescript-eslint/no-loop-func
474
+ nextCell = nextRow && Array.from(nextRow.children).find((cell) => cell._column === nextColumn);
475
+ if (nextCell && this._isCellEditable(nextCell)) {
476
+ break;
451
477
  }
452
- } else if (cols[colIndex + 1]) {
453
- nextCol = cols[colIndex + 1];
454
- } else {
455
- nextIdx = index + 1;
456
- nextCol = cols[0];
457
478
  }
458
479
  }
459
480
 
460
- const nextRow = nextIdx === index ? cell.parentNode : this._getRowByIndex(nextIdx) || null;
461
-
462
- this._stopEdit();
463
-
464
- if (nextRow && nextCol) {
465
- const nextCell = Array.from(nextRow.children).find((cell) => cell._column === nextCol);
466
- e.preventDefault();
467
-
468
- // Prevent vaadin-grid handler from being called
469
- e.stopImmediatePropagation();
481
+ // Focus current cell as fallback
482
+ if (!nextCell) {
483
+ nextCell = cell;
484
+ nextIndex = model.index;
485
+ }
470
486
 
471
- if (!this.singleCellEdit && nextCell !== cell) {
472
- this._startEdit(nextCell, nextCol);
473
- } else {
474
- this._ensureScrolledToIndex(nextIdx);
475
- nextCell.focus();
476
- }
487
+ if (!this.singleCellEdit && nextCell !== cell) {
488
+ this._startEdit(nextCell, nextColumn);
489
+ } else {
490
+ this._ensureScrolledToIndex(nextIndex);
491
+ nextCell.focus();
477
492
  }
478
493
  }
479
494
 
@@ -492,6 +507,46 @@ export const InlineEditingMixin = (superClass) =>
492
507
  super._updateItem(row, item);
493
508
  }
494
509
 
510
+ /**
511
+ * Override method from `StylingMixin` to apply `editable-cell` part to the
512
+ * cells of edit columns.
513
+ *
514
+ * @override
515
+ */
516
+ _generateCellPartNames(row, model) {
517
+ super._generateCellPartNames(row, model);
518
+
519
+ iterateRowCells(row, (cell) => {
520
+ const isEditable = this._isCellEditable(cell);
521
+ const target = cell._focusButton || cell;
522
+ updatePart(target, isEditable, 'editable-cell');
523
+ });
524
+ }
525
+
526
+ /** @private */
527
+ _isCellEditable(cell) {
528
+ const column = cell._column;
529
+ // Not editable if the column is not an edit column
530
+ if (!this._isEditColumn(column)) {
531
+ return false;
532
+ }
533
+ // Cell is editable by default if isCellEditable is not configured
534
+ if (!column.isCellEditable) {
535
+ return true;
536
+ }
537
+ // Otherwise, check isCellEditable function
538
+ const model = this.__getRowModel(cell.parentElement);
539
+ const isEditable = column.isCellEditable(model);
540
+
541
+ // Cancel editing if the cell is currently edited one and becomes no longer editable
542
+ // TODO: should be moved to `_updateItem` when Grid connector is updated to use it.
543
+ if (this.__edited && this.__edited.cell === cell && !isEditable) {
544
+ this._stopEdit(true, true);
545
+ }
546
+
547
+ return isEditable;
548
+ }
549
+
495
550
  /**
496
551
  * Fired before exiting the cell edit mode, if the value has been changed.
497
552
  * If the default is prevented, value change would not be applied.
@@ -0,0 +1,2 @@
1
+ import '@vaadin/checkbox/theme/lumo/vaadin-checkbox.js';
2
+ import '../../src/vaadin-grid-pro-edit-checkbox.js';
@@ -0,0 +1,4 @@
1
+ import './vaadin-grid-pro-edit-checkbox.js';
2
+ import './vaadin-grid-pro-edit-select.js';
3
+ import './vaadin-grid-pro-edit-text-field.js';
4
+ import '../../src/vaadin-grid-pro-edit-column.js';
@@ -0,0 +1,2 @@
1
+ import '@vaadin/vaadin-lumo-styles/spacing.js';
2
+ import '@vaadin/vaadin-lumo-styles/typography.js';
@@ -0,0 +1,3 @@
1
+ import '@vaadin/select/theme/lumo/vaadin-select.js';
2
+ import './vaadin-grid-pro-edit-select-styles.js';
3
+ import '../../src/vaadin-grid-pro-edit-select.js';
@@ -0,0 +1,3 @@
1
+ import '@vaadin/text-field/theme/lumo/vaadin-text-field.js';
2
+ import './vaadin-grid-pro-edit-text-field-styles.js';
3
+ import '../../src/vaadin-grid-pro-edit-text-field.js';
@@ -0,0 +1,5 @@
1
+ import '@vaadin/vaadin-lumo-styles/color.js';
2
+ import '@vaadin/vaadin-lumo-styles/spacing.js';
3
+ import '@vaadin/vaadin-lumo-styles/typography.js';
4
+ declare const gridProEditor: import("lit").CSSResult;
5
+ export { gridProEditor };
@@ -0,0 +1,2 @@
1
+ import '@vaadin/vaadin-lumo-styles/color.js';
2
+ import '@vaadin/vaadin-lumo-styles/style.js';
@@ -0,0 +1,3 @@
1
+ import '@vaadin/grid/theme/lumo/vaadin-grid-styles.js';
2
+ import './vaadin-grid-pro-styles.js';
3
+ import '../../src/vaadin-grid-pro.js';
@@ -0,0 +1,2 @@
1
+ import '@vaadin/checkbox/theme/lumo/vaadin-checkbox-styles.js';
2
+ import '../../src/vaadin-lit-grid-pro-edit-checkbox.js';
@@ -0,0 +1,4 @@
1
+ import './vaadin-lit-grid-pro-edit-checkbox.js';
2
+ import './vaadin-lit-grid-pro-edit-select.js';
3
+ import './vaadin-lit-grid-pro-edit-text-field.js';
4
+ import '../../src/vaadin-lit-grid-pro-edit-column.js';
@@ -0,0 +1,3 @@
1
+ import '@vaadin/select/theme/lumo/vaadin-select-styles.js';
2
+ import './vaadin-grid-pro-edit-select-styles.js';
3
+ import '../../src/vaadin-lit-grid-pro-edit-select.js';
@@ -0,0 +1,3 @@
1
+ import '@vaadin/text-field/theme/lumo/vaadin-text-field-styles.js';
2
+ import './vaadin-grid-pro-edit-text-field-styles.js';
3
+ import '../../src/vaadin-lit-grid-pro-edit-text-field.js';
@@ -0,0 +1,3 @@
1
+ import '@vaadin/grid/theme/lumo/vaadin-grid-styles.js';
2
+ import './vaadin-grid-pro-styles.js';
3
+ import '../../src/vaadin-lit-grid-pro.js';
@@ -0,0 +1,2 @@
1
+ import '@vaadin/checkbox/theme/material/vaadin-checkbox.js';
2
+ import '../../src/vaadin-grid-pro-edit-checkbox.js';
@@ -0,0 +1,4 @@
1
+ import './vaadin-grid-pro-edit-checkbox.js';
2
+ import './vaadin-grid-pro-edit-select.js';
3
+ import './vaadin-grid-pro-edit-text-field.js';
4
+ import '../../src/vaadin-grid-pro-edit-column.js';
@@ -0,0 +1,3 @@
1
+ import '@vaadin/select/theme/material/vaadin-select.js';
2
+ import './vaadin-grid-pro-edit-select-styles.js';
3
+ import '../../src/vaadin-grid-pro-edit-select.js';
@@ -0,0 +1,3 @@
1
+ import '@vaadin/text-field/theme/material/vaadin-text-field.js';
2
+ import './vaadin-grid-pro-edit-text-field-styles.js';
3
+ import '../../src/vaadin-grid-pro-edit-text-field.js';
@@ -0,0 +1,2 @@
1
+ declare const gridProEditor: import("lit").CSSResult;
2
+ export { gridProEditor };
@@ -0,0 +1,2 @@
1
+ import '@vaadin/vaadin-material-styles/color.js';
2
+ import '@vaadin/grid/theme/material/vaadin-grid-styles.js';
@@ -0,0 +1,3 @@
1
+ import '@vaadin/grid/theme/material/vaadin-grid-styles.js';
2
+ import './vaadin-grid-pro-styles.js';
3
+ import '../../src/vaadin-grid-pro.js';
@@ -0,0 +1,2 @@
1
+ import '@vaadin/checkbox/theme/material/vaadin-checkbox-styles.js';
2
+ import '../../src/vaadin-lit-grid-pro-edit-checkbox.js';
@@ -0,0 +1,4 @@
1
+ import './vaadin-lit-grid-pro-edit-checkbox.js';
2
+ import './vaadin-lit-grid-pro-edit-select.js';
3
+ import './vaadin-lit-grid-pro-edit-text-field.js';
4
+ import '../../src/vaadin-lit-grid-pro-edit-column.js';
@@ -0,0 +1,3 @@
1
+ import '@vaadin/select/theme/material/vaadin-select-styles.js';
2
+ import './vaadin-grid-pro-edit-select-styles.js';
3
+ import '../../src/vaadin-lit-grid-pro-edit-select.js';
@@ -0,0 +1,3 @@
1
+ import '@vaadin/text-field/theme/material/vaadin-text-field-styles.js';
2
+ import './vaadin-grid-pro-edit-text-field-styles.js';
3
+ import '../../src/vaadin-lit-grid-pro-edit-text-field.js';
@@ -0,0 +1,3 @@
1
+ import '@vaadin/grid/theme/material/vaadin-grid-styles.js';
2
+ import './vaadin-grid-pro-styles.js';
3
+ import '../../src/vaadin-lit-grid-pro.js';