@vaadin/grid-pro 24.3.0-alpha8 → 24.3.0-beta1

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 (31) hide show
  1. package/package.json +11 -13
  2. package/src/vaadin-grid-pro-edit-column-mixin.d.ts +68 -0
  3. package/src/vaadin-grid-pro-edit-column-mixin.js +284 -0
  4. package/src/vaadin-grid-pro-edit-column.d.ts +9 -56
  5. package/src/vaadin-grid-pro-edit-column.js +3 -263
  6. package/src/vaadin-grid-pro-edit-select-mixin.js +119 -0
  7. package/src/vaadin-grid-pro-edit-select.js +3 -115
  8. package/src/vaadin-grid-pro-inline-editing-mixin.js +4 -3
  9. package/src/vaadin-lit-grid-pro-edit-checkbox.js +28 -0
  10. package/src/vaadin-lit-grid-pro-edit-column.js +34 -0
  11. package/src/vaadin-lit-grid-pro-edit-select.js +29 -0
  12. package/src/vaadin-lit-grid-pro-edit-text-field.js +33 -0
  13. package/src/vaadin-lit-grid-pro.js +35 -0
  14. package/theme/lumo/vaadin-grid-pro-edit-select.js +0 -2
  15. package/theme/lumo/vaadin-lit-grid-pro-edit-checkbox.js +2 -0
  16. package/theme/lumo/vaadin-lit-grid-pro-edit-column.js +4 -0
  17. package/theme/lumo/vaadin-lit-grid-pro-edit-select.js +3 -0
  18. package/theme/lumo/vaadin-lit-grid-pro-edit-text-field.js +3 -0
  19. package/theme/lumo/vaadin-lit-grid-pro.js +3 -0
  20. package/theme/material/vaadin-grid-pro-edit-select.js +0 -2
  21. package/theme/material/vaadin-lit-grid-pro-edit-checkbox.js +2 -0
  22. package/theme/material/vaadin-lit-grid-pro-edit-column.js +4 -0
  23. package/theme/material/vaadin-lit-grid-pro-edit-select.js +3 -0
  24. package/theme/material/vaadin-lit-grid-pro-edit-text-field.js +3 -0
  25. package/theme/material/vaadin-lit-grid-pro.js +3 -0
  26. package/vaadin-lit-grid-pro-edit-column.d.ts +1 -0
  27. package/vaadin-lit-grid-pro-edit-column.js +3 -0
  28. package/vaadin-lit-grid-pro.d.ts +1 -0
  29. package/vaadin-lit-grid-pro.js +3 -0
  30. package/web-types.json +2 -2
  31. package/web-types.lit.json +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/grid-pro",
3
- "version": "24.3.0-alpha8",
3
+ "version": "24.3.0-beta1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -39,17 +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.3.0-alpha8",
43
- "@vaadin/component-base": "24.3.0-alpha8",
44
- "@vaadin/grid": "24.3.0-alpha8",
45
- "@vaadin/item": "24.3.0-alpha8",
46
- "@vaadin/list-box": "24.3.0-alpha8",
47
- "@vaadin/lit-renderer": "24.3.0-alpha8",
48
- "@vaadin/select": "24.3.0-alpha8",
49
- "@vaadin/text-field": "24.3.0-alpha8",
50
- "@vaadin/vaadin-lumo-styles": "24.3.0-alpha8",
51
- "@vaadin/vaadin-material-styles": "24.3.0-alpha8",
52
- "@vaadin/vaadin-themable-mixin": "24.3.0-alpha8"
42
+ "@vaadin/checkbox": "24.3.0-beta1",
43
+ "@vaadin/component-base": "24.3.0-beta1",
44
+ "@vaadin/grid": "24.3.0-beta1",
45
+ "@vaadin/lit-renderer": "24.3.0-beta1",
46
+ "@vaadin/select": "24.3.0-beta1",
47
+ "@vaadin/text-field": "24.3.0-beta1",
48
+ "@vaadin/vaadin-lumo-styles": "24.3.0-beta1",
49
+ "@vaadin/vaadin-material-styles": "24.3.0-beta1",
50
+ "@vaadin/vaadin-themable-mixin": "24.3.0-beta1"
53
51
  },
54
52
  "devDependencies": {
55
53
  "@esm-bundle/chai": "^4.3.4",
@@ -62,5 +60,5 @@
62
60
  "web-types.json",
63
61
  "web-types.lit.json"
64
62
  ],
65
- "gitHead": "03b2f1c55aadb86b15ad96c7e7dcb059e5fc0604"
63
+ "gitHead": "a197041861e1bbf8d3e966d893648f5dd462b036"
66
64
  }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2000 - 2023 Vaadin Ltd.
4
+ *
5
+ * This program is available under Vaadin Commercial License and Service Terms.
6
+ *
7
+ *
8
+ * See https://vaadin.com/commercial-license-and-service-terms for the full
9
+ * license.
10
+ */
11
+ import type { GridBodyRenderer, GridItemModel } from '@vaadin/grid/src/vaadin-grid.js';
12
+
13
+ export type GridProEditorType = 'checkbox' | 'custom' | 'select' | 'text';
14
+
15
+ export declare class GridProEditColumnMixinClass<TItem> {
16
+ /**
17
+ * JS Path of the property in the item used for the editable content.
18
+ */
19
+ path: string | null | undefined;
20
+
21
+ /**
22
+ * Custom function for rendering the cell content in edit mode.
23
+ * Receives three arguments:
24
+ *
25
+ * - `root` The cell content DOM element. Append your editor component to it.
26
+ * - `column` The `<vaadin-grid-pro-edit-column>` element.
27
+ * - `model` The object with the properties related with
28
+ * the rendered item, contains:
29
+ * - `model.index` The index of the item.
30
+ * - `model.item` The item.
31
+ * - `model.expanded` Sublevel toggle state.
32
+ * - `model.level` Level of the tree represented with a horizontal offset of the toggle button.
33
+ * - `model.selected` Selected state.
34
+ * - `model.detailsOpened` Details opened state.
35
+ */
36
+ editModeRenderer: GridBodyRenderer<TItem> | null | undefined;
37
+
38
+ /**
39
+ * The list of options which should be passed to cell editor component.
40
+ * Used with the `select` editor type, to provide a list of items.
41
+ */
42
+ editorOptions: string[];
43
+
44
+ /**
45
+ * Type of the cell editor component to be rendered. Allowed values:
46
+ * - `text` (default) - renders a text field
47
+ * - `checkbox` - renders a checkbox
48
+ * - `select` - renders a select with a list of items passed as `editorOptions`
49
+ *
50
+ * Editor type is set to `custom` when `editModeRenderer` is set.
51
+ * @attr {text|checkbox|select|custom} editor-type
52
+ */
53
+ editorType: GridProEditorType;
54
+
55
+ /**
56
+ * Path of the property used for the value of the editor component.
57
+ * @attr {string} editor-value-path
58
+ */
59
+ editorValuePath: string;
60
+
61
+ protected _getEditorComponent(cell: HTMLElement): HTMLElement | null;
62
+
63
+ protected _getEditorValue(editor: HTMLElement): unknown | null;
64
+
65
+ protected _startCellEdit(cell: HTMLElement, model: GridItemModel<TItem>): void;
66
+
67
+ protected _stopCellEdit(cell: HTMLElement, model: GridItemModel<TItem>): void;
68
+ }
@@ -0,0 +1,284 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2000 - 2023 Vaadin Ltd.
4
+ *
5
+ * This program is available under Vaadin Commercial License and Service Terms.
6
+ *
7
+ *
8
+ * See https://vaadin.com/commercial-license-and-service-terms for the full
9
+ * license.
10
+ */
11
+ import { addValueToAttribute } from '@vaadin/component-base/src/dom-utils.js';
12
+ import { get, set } from '@vaadin/component-base/src/path-utils.js';
13
+
14
+ /**
15
+ * @polymerMixin
16
+ */
17
+ export const GridProEditColumnMixin = (superClass) =>
18
+ class extends superClass {
19
+ static get properties() {
20
+ return {
21
+ /**
22
+ * Custom function for rendering the cell content in edit mode.
23
+ * Receives three arguments:
24
+ *
25
+ * - `root` The cell content DOM element. Append your editor component to it.
26
+ * - `column` The `<vaadin-grid-pro-edit-column>` element.
27
+ * - `model` The object with the properties related with
28
+ * the rendered item, contains:
29
+ * - `model.index` The index of the item.
30
+ * - `model.item` The item.
31
+ * - `model.expanded` Sublevel toggle state.
32
+ * - `model.level` Level of the tree represented with a horizontal offset of the toggle button.
33
+ * - `model.selected` Selected state.
34
+ * - `model.detailsOpened` Details opened state.
35
+ * @type {!GridBodyRenderer | null | undefined}
36
+ */
37
+ editModeRenderer: {
38
+ type: Function,
39
+ sync: true,
40
+ },
41
+
42
+ /**
43
+ * The list of options which should be passed to cell editor component.
44
+ * Used with the `select` editor type, to provide a list of items.
45
+ * @type {!Array<string>}
46
+ */
47
+ editorOptions: {
48
+ type: Array,
49
+ value: () => [],
50
+ },
51
+
52
+ /**
53
+ * Type of the cell editor component to be rendered. Allowed values:
54
+ * - `text` (default) - renders a text field
55
+ * - `checkbox` - renders a checkbox
56
+ * - `select` - renders a select with a list of items passed as `editorOptions`
57
+ *
58
+ * Editor type is set to `custom` when `editModeRenderer` is set.
59
+ * @attr {text|checkbox|select|custom} editor-type
60
+ * @type {!GridProEditorType}
61
+ */
62
+ editorType: {
63
+ type: String,
64
+ notify: true, // FIXME(web-padawan): needed by Flow counterpart
65
+ value: 'text',
66
+ },
67
+
68
+ /**
69
+ * Path of the property used for the value of the editor component.
70
+ * @attr {string} editor-value-path
71
+ * @type {string}
72
+ */
73
+ editorValuePath: {
74
+ type: String,
75
+ value: 'value',
76
+ },
77
+
78
+ /**
79
+ * JS Path of the property in the item used for the editable content.
80
+ */
81
+ path: {
82
+ type: String,
83
+ observer: '_pathChanged',
84
+ sync: true,
85
+ },
86
+
87
+ /** @private */
88
+ _oldRenderer: Function,
89
+ };
90
+ }
91
+
92
+ static get observers() {
93
+ return ['_editModeRendererChanged(editModeRenderer, __initialized)', '_cellsChanged(_cells)'];
94
+ }
95
+
96
+ constructor() {
97
+ super();
98
+
99
+ // Enable focus button mode for Mac OS to ensure focused
100
+ // editable cell stays in sync with the VoiceOver cursor
101
+ // https://github.com/vaadin/web-components/issues/3820
102
+ this._focusButtonMode = navigator.platform.includes('Mac');
103
+
104
+ this.__editModeRenderer = function (root, column) {
105
+ const cell = root.assignedSlot.parentNode;
106
+
107
+ const tagName = column._getEditorTagName(cell);
108
+ if (!root.firstElementChild || root.firstElementChild.localName.toLowerCase() !== tagName) {
109
+ root.innerHTML = `
110
+ <${tagName}></${tagName}>
111
+ `;
112
+ }
113
+ };
114
+ }
115
+
116
+ /** @private */
117
+ _pathChanged(path) {
118
+ if (!path || path.length === 0) {
119
+ throw new Error('You should specify the path for the edit column');
120
+ }
121
+ }
122
+
123
+ /** @private */
124
+ _cellsChanged() {
125
+ this._cells.forEach((cell) => {
126
+ const target = cell._focusButton || cell;
127
+ addValueToAttribute(target, 'part', 'editable-cell');
128
+ });
129
+ }
130
+
131
+ /** @private */
132
+ _editModeRendererChanged(renderer) {
133
+ if (renderer) {
134
+ this.editorType = 'custom';
135
+ } else if (this._oldRenderer) {
136
+ this.editorType = 'text';
137
+ }
138
+
139
+ this._oldRenderer = renderer;
140
+ }
141
+
142
+ /**
143
+ * @param {!HTMLElement} cell
144
+ * @return {string}
145
+ * @protected
146
+ */
147
+ _getEditorTagName(cell) {
148
+ return this.editorType === 'custom' ? this._getEditorComponent(cell).localName : this._getTagNameByType();
149
+ }
150
+
151
+ /**
152
+ * @param {!HTMLElement} cell
153
+ * @return {HTMLElement | null}
154
+ * @protected
155
+ */
156
+ _getEditorComponent(cell) {
157
+ return this.editorType === 'custom'
158
+ ? cell._content.firstElementChild
159
+ : cell._content.querySelector(this._getEditorTagName(cell));
160
+ }
161
+
162
+ /** @private */
163
+ _getTagNameByType() {
164
+ let type;
165
+ switch (this.editorType) {
166
+ case 'checkbox':
167
+ type = 'checkbox';
168
+ break;
169
+ case 'select':
170
+ type = 'select';
171
+ break;
172
+ case 'text':
173
+ default:
174
+ type = 'text-field';
175
+ break;
176
+ }
177
+ return this.constructor.is.replace('column', type);
178
+ }
179
+
180
+ /** @private */
181
+ _focusEditor(editor) {
182
+ editor.focus();
183
+ if (this.editorType === 'checkbox') {
184
+ editor.setAttribute('focus-ring', '');
185
+ } else if (editor instanceof HTMLInputElement) {
186
+ editor.select();
187
+ } else if (editor.focusElement && editor.focusElement instanceof HTMLInputElement) {
188
+ editor.focusElement.select();
189
+ }
190
+ }
191
+
192
+ /**
193
+ * @param {!HTMLElement} editor
194
+ * @return {unknown}
195
+ * @protected
196
+ */
197
+ _getEditorValue(editor) {
198
+ const path = this.editorType === 'checkbox' ? 'checked' : this.editorValuePath;
199
+ return get(path, editor);
200
+ }
201
+
202
+ /** @private */
203
+ _renderEditor(cell, model) {
204
+ cell.__savedRenderer = this._renderer || cell._renderer;
205
+ cell._renderer = this.editModeRenderer || this.__editModeRenderer;
206
+
207
+ // Remove role to avoid announcing button while editing
208
+ if (cell._focusButton) {
209
+ cell._focusButton.removeAttribute('role');
210
+ }
211
+
212
+ this._clearCellContent(cell);
213
+ this._runRenderer(cell._renderer, cell, model);
214
+ }
215
+
216
+ /** @private */
217
+ _removeEditor(cell, _model) {
218
+ if (!cell.__savedRenderer) {
219
+ return;
220
+ }
221
+
222
+ cell._renderer = cell.__savedRenderer;
223
+ cell.__savedRenderer = undefined;
224
+
225
+ this._clearCellContent(cell);
226
+
227
+ // Restore previously removed role attribute
228
+ if (cell._focusButton) {
229
+ cell._focusButton.setAttribute('role', 'button');
230
+ }
231
+
232
+ this.__renderCellsContent(cell._renderer, [cell]);
233
+ }
234
+
235
+ /** @private */
236
+ _setEditorOptions(editor) {
237
+ if (this.editorOptions && this.editorOptions.length) {
238
+ editor.options = this.editorOptions;
239
+ }
240
+ }
241
+
242
+ /** @private */
243
+ _setEditorValue(editor, value) {
244
+ const path = this.editorType === 'checkbox' ? 'checked' : this.editorValuePath;
245
+ // FIXME(yuriy): Required for the flow counterpart as it is passing the string value to webcomponent
246
+ value = this.editorType === 'checkbox' && typeof value === 'string' ? value === 'true' : value;
247
+ set(path, value, editor);
248
+ if (editor.notifyPath) {
249
+ editor.notifyPath(path, value);
250
+ }
251
+ }
252
+
253
+ /**
254
+ * @param {!HTMLElement} cell
255
+ * @param {!GridItemModel} model
256
+ * @protected
257
+ */
258
+ _startCellEdit(cell, model) {
259
+ this._renderEditor(cell, model);
260
+
261
+ const editor = this._getEditorComponent(cell);
262
+ editor.addEventListener('focusout', this._grid.__boundEditorFocusOut);
263
+ editor.addEventListener('focusin', this._grid.__boundEditorFocusIn);
264
+ editor.addEventListener('internal-tab', this._grid.__boundCancelCellSwitch);
265
+ document.body.addEventListener('focusin', this._grid.__boundGlobalFocusIn);
266
+ this._setEditorOptions(editor);
267
+ this._setEditorValue(editor, get(this.path, model.item));
268
+ editor._grid = this._grid;
269
+
270
+ this._focusEditor(editor);
271
+ requestAnimationFrame(() => this._focusEditor(editor));
272
+ }
273
+
274
+ /**
275
+ * @param {!HTMLElement} cell
276
+ * @param {!GridItemModel} model
277
+ * @protected
278
+ */
279
+ _stopCellEdit(cell, model) {
280
+ document.body.removeEventListener('focusin', this._grid.__boundGlobalFocusIn);
281
+
282
+ this._removeEditor(cell, model);
283
+ }
284
+ };
@@ -8,10 +8,11 @@
8
8
  * See https://vaadin.com/commercial-license-and-service-terms for the full
9
9
  * license.
10
10
  */
11
- import type { GridBodyRenderer, GridDefaultItem, GridItemModel } from '@vaadin/grid/src/vaadin-grid.js';
12
- import { GridColumn } from '@vaadin/grid/src/vaadin-grid-column.js';
11
+ import type { GridDefaultItem } from '@vaadin/grid/src/vaadin-grid.js';
12
+ import type { GridColumn, GridColumnMixin } from '@vaadin/grid/src/vaadin-grid-column.js';
13
+ import type { GridProEditColumnMixinClass } from './vaadin-grid-pro-edit-column-mixin.js';
13
14
 
14
- export type GridProEditorType = 'checkbox' | 'custom' | 'select' | 'text';
15
+ export * from './vaadin-grid-pro-edit-column-mixin.js';
15
16
 
16
17
  /**
17
18
  * `<vaadin-grid-pro-edit-column>` is a helper element for the `<vaadin-grid-pro>`
@@ -28,60 +29,12 @@ export type GridProEditorType = 'checkbox' | 'custom' | 'select' | 'text';
28
29
  * ...
29
30
  * ```
30
31
  */
31
- declare class GridProEditColumn<TItem = GridDefaultItem> extends GridColumn<TItem> {
32
- /**
33
- * JS Path of the property in the item used for the editable content.
34
- */
35
- path: string | null | undefined;
32
+ declare class GridProEditColumn<TItem = GridDefaultItem> extends HTMLElement {}
36
33
 
37
- /**
38
- * Custom function for rendering the cell content in edit mode.
39
- * Receives three arguments:
40
- *
41
- * - `root` The cell content DOM element. Append your editor component to it.
42
- * - `column` The `<vaadin-grid-pro-edit-column>` element.
43
- * - `model` The object with the properties related with
44
- * the rendered item, contains:
45
- * - `model.index` The index of the item.
46
- * - `model.item` The item.
47
- * - `model.expanded` Sublevel toggle state.
48
- * - `model.level` Level of the tree represented with a horizontal offset of the toggle button.
49
- * - `model.selected` Selected state.
50
- * - `model.detailsOpened` Details opened state.
51
- */
52
- editModeRenderer: GridBodyRenderer<TItem> | null | undefined;
53
-
54
- /**
55
- * The list of options which should be passed to cell editor component.
56
- * Used with the `select` editor type, to provide a list of items.
57
- */
58
- editorOptions: string[];
59
-
60
- /**
61
- * Type of the cell editor component to be rendered. Allowed values:
62
- * - `text` (default) - renders a text field
63
- * - `checkbox` - renders a checkbox
64
- * - `select` - renders a select with a list of items passed as `editorOptions`
65
- *
66
- * Editor type is set to `custom` when `editModeRenderer` is set.
67
- * @attr {text|checkbox|select|custom} editor-type
68
- */
69
- editorType: GridProEditorType;
70
-
71
- /**
72
- * Path of the property used for the value of the editor component.
73
- * @attr {string} editor-value-path
74
- */
75
- editorValuePath: string;
76
-
77
- protected _getEditorComponent(cell: HTMLElement): HTMLElement | null;
78
-
79
- protected _getEditorValue(editor: HTMLElement): unknown | null;
80
-
81
- protected _startCellEdit(cell: HTMLElement, model: GridItemModel<TItem>): void;
82
-
83
- protected _stopCellEdit(cell: HTMLElement, model: GridItemModel<TItem>): void;
84
- }
34
+ interface GridProEditColumn<TItem = GridDefaultItem>
35
+ extends GridProEditColumnMixinClass<TItem>,
36
+ GridColumnMixin<TItem, GridColumn<TItem>>,
37
+ GridColumn<TItem> {}
85
38
 
86
39
  declare global {
87
40
  interface HTMLElementTagNameMap {