@vaadin/grid-pro 24.2.3 → 24.3.0-alpha10
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.
- package/package.json +16 -16
- package/src/vaadin-grid-pro-edit-column-mixin.d.ts +68 -0
- package/src/vaadin-grid-pro-edit-column-mixin.js +284 -0
- package/src/vaadin-grid-pro-edit-column.d.ts +9 -56
- package/src/vaadin-grid-pro-edit-column.js +3 -263
- package/src/vaadin-grid-pro-edit-select-mixin.js +119 -0
- package/src/vaadin-grid-pro-edit-select.js +3 -115
- package/src/vaadin-grid-pro-inline-editing-mixin.js +4 -3
- package/src/vaadin-lit-grid-pro-edit-checkbox.js +29 -0
- package/src/vaadin-lit-grid-pro-edit-select.js +30 -0
- package/src/vaadin-lit-grid-pro-edit-text-field.js +34 -0
- package/theme/lumo/vaadin-grid-pro-edit-select.js +0 -2
- package/theme/lumo/vaadin-grid-pro-editor-styles.js +1 -1
- package/theme/lumo/vaadin-grid-pro-styles.js +1 -1
- package/theme/lumo/vaadin-lit-grid-pro-edit-checkbox.js +2 -0
- package/theme/lumo/vaadin-lit-grid-pro-edit-select.js +3 -0
- package/theme/lumo/vaadin-lit-grid-pro-edit-text-field.js +3 -0
- package/theme/material/vaadin-grid-pro-edit-select.js +0 -2
- package/theme/material/vaadin-lit-grid-pro-edit-checkbox.js +2 -0
- package/theme/material/vaadin-lit-grid-pro-edit-select.js +3 -0
- package/theme/material/vaadin-lit-grid-pro-edit-text-field.js +3 -0
- package/web-types.json +46 -2
- package/web-types.lit.json +16 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/grid-pro",
|
|
3
|
-
"version": "24.
|
|
3
|
+
"version": "24.3.0-alpha10",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
"vaadin-*.d.ts",
|
|
28
28
|
"vaadin-*.js",
|
|
29
29
|
"web-types.json",
|
|
30
|
-
"web-types.lit.json"
|
|
30
|
+
"web-types.lit.json",
|
|
31
|
+
"!vaadin-lit-*.d.ts",
|
|
32
|
+
"!vaadin-lit-*.js"
|
|
31
33
|
],
|
|
32
34
|
"keywords": [
|
|
33
35
|
"Vaadin",
|
|
@@ -39,22 +41,20 @@
|
|
|
39
41
|
"dependencies": {
|
|
40
42
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
41
43
|
"@polymer/polymer": "^3.0.0",
|
|
42
|
-
"@vaadin/checkbox": "
|
|
43
|
-
"@vaadin/component-base": "
|
|
44
|
-
"@vaadin/grid": "
|
|
45
|
-
"@vaadin/
|
|
46
|
-
"@vaadin/
|
|
47
|
-
"@vaadin/
|
|
48
|
-
"@vaadin/
|
|
49
|
-
"@vaadin/
|
|
50
|
-
"@vaadin/vaadin-
|
|
51
|
-
"@vaadin/vaadin-material-styles": "~24.2.3",
|
|
52
|
-
"@vaadin/vaadin-themable-mixin": "~24.2.3"
|
|
44
|
+
"@vaadin/checkbox": "24.3.0-alpha10",
|
|
45
|
+
"@vaadin/component-base": "24.3.0-alpha10",
|
|
46
|
+
"@vaadin/grid": "24.3.0-alpha10",
|
|
47
|
+
"@vaadin/lit-renderer": "24.3.0-alpha10",
|
|
48
|
+
"@vaadin/select": "24.3.0-alpha10",
|
|
49
|
+
"@vaadin/text-field": "24.3.0-alpha10",
|
|
50
|
+
"@vaadin/vaadin-lumo-styles": "24.3.0-alpha10",
|
|
51
|
+
"@vaadin/vaadin-material-styles": "24.3.0-alpha10",
|
|
52
|
+
"@vaadin/vaadin-themable-mixin": "24.3.0-alpha10"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@esm-bundle/chai": "^4.3.4",
|
|
56
|
-
"@vaadin/testing-helpers": "^0.
|
|
57
|
-
"lit": "^
|
|
56
|
+
"@vaadin/testing-helpers": "^0.6.0",
|
|
57
|
+
"lit": "^3.0.0",
|
|
58
58
|
"sinon": "^13.0.2"
|
|
59
59
|
},
|
|
60
60
|
"cvdlName": "vaadin-grid-pro",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"web-types.json",
|
|
63
63
|
"web-types.lit.json"
|
|
64
64
|
],
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "0271523d93fe5df0425ff64206886614f3c6f401"
|
|
66
66
|
}
|
|
@@ -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 {
|
|
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
|
|
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
|
|
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
|
-
|
|
39
|
-
|
|
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 {
|
|
@@ -11,10 +11,9 @@
|
|
|
11
11
|
import './vaadin-grid-pro-edit-checkbox.js';
|
|
12
12
|
import './vaadin-grid-pro-edit-select.js';
|
|
13
13
|
import './vaadin-grid-pro-edit-text-field.js';
|
|
14
|
-
import { get, set } from '@polymer/polymer/lib/utils/path.js';
|
|
15
14
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
16
|
-
import { addValueToAttribute } from '@vaadin/component-base/src/dom-utils.js';
|
|
17
15
|
import { GridColumn } from '@vaadin/grid/src/vaadin-grid-column.js';
|
|
16
|
+
import { GridProEditColumnMixin } from './vaadin-grid-pro-edit-column-mixin.js';
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
19
|
* `<vaadin-grid-pro-edit-column>` is a helper element for the `<vaadin-grid-pro>`
|
|
@@ -33,271 +32,12 @@ import { GridColumn } from '@vaadin/grid/src/vaadin-grid-column.js';
|
|
|
33
32
|
*
|
|
34
33
|
* @customElement
|
|
35
34
|
* @extends GridColumn
|
|
35
|
+
* @mixes GridProEditColumnMixin
|
|
36
36
|
*/
|
|
37
|
-
class GridProEditColumn extends GridColumn {
|
|
37
|
+
class GridProEditColumn extends GridProEditColumnMixin(GridColumn) {
|
|
38
38
|
static get is() {
|
|
39
39
|
return 'vaadin-grid-pro-edit-column';
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
static get properties() {
|
|
43
|
-
return {
|
|
44
|
-
/**
|
|
45
|
-
* Custom function for rendering the cell content in edit mode.
|
|
46
|
-
* Receives three arguments:
|
|
47
|
-
*
|
|
48
|
-
* - `root` The cell content DOM element. Append your editor component to it.
|
|
49
|
-
* - `column` The `<vaadin-grid-pro-edit-column>` element.
|
|
50
|
-
* - `model` The object with the properties related with
|
|
51
|
-
* the rendered item, contains:
|
|
52
|
-
* - `model.index` The index of the item.
|
|
53
|
-
* - `model.item` The item.
|
|
54
|
-
* - `model.expanded` Sublevel toggle state.
|
|
55
|
-
* - `model.level` Level of the tree represented with a horizontal offset of the toggle button.
|
|
56
|
-
* - `model.selected` Selected state.
|
|
57
|
-
* - `model.detailsOpened` Details opened state.
|
|
58
|
-
* @type {!GridBodyRenderer | null | undefined}
|
|
59
|
-
*/
|
|
60
|
-
editModeRenderer: Function,
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* The list of options which should be passed to cell editor component.
|
|
64
|
-
* Used with the `select` editor type, to provide a list of items.
|
|
65
|
-
* @type {!Array<string>}
|
|
66
|
-
*/
|
|
67
|
-
editorOptions: {
|
|
68
|
-
type: Array,
|
|
69
|
-
value: () => [],
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Type of the cell editor component to be rendered. Allowed values:
|
|
74
|
-
* - `text` (default) - renders a text field
|
|
75
|
-
* - `checkbox` - renders a checkbox
|
|
76
|
-
* - `select` - renders a select with a list of items passed as `editorOptions`
|
|
77
|
-
*
|
|
78
|
-
* Editor type is set to `custom` when `editModeRenderer` is set.
|
|
79
|
-
* @attr {text|checkbox|select|custom} editor-type
|
|
80
|
-
* @type {!GridProEditorType}
|
|
81
|
-
*/
|
|
82
|
-
editorType: {
|
|
83
|
-
type: String,
|
|
84
|
-
notify: true, // FIXME(web-padawan): needed by Flow counterpart
|
|
85
|
-
value: 'text',
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Path of the property used for the value of the editor component.
|
|
90
|
-
* @attr {string} editor-value-path
|
|
91
|
-
* @type {string}
|
|
92
|
-
*/
|
|
93
|
-
editorValuePath: {
|
|
94
|
-
type: String,
|
|
95
|
-
value: 'value',
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* JS Path of the property in the item used for the editable content.
|
|
100
|
-
*/
|
|
101
|
-
path: {
|
|
102
|
-
type: String,
|
|
103
|
-
observer: '_pathChanged',
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
/** @private */
|
|
107
|
-
_oldRenderer: Function,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
static get observers() {
|
|
112
|
-
return ['_editModeRendererChanged(editModeRenderer, __initialized)', '_cellsChanged(_cells.*)'];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
constructor() {
|
|
116
|
-
super();
|
|
117
|
-
|
|
118
|
-
// Enable focus button mode for Mac OS to ensure focused
|
|
119
|
-
// editable cell stays in sync with the VoiceOver cursor
|
|
120
|
-
// https://github.com/vaadin/web-components/issues/3820
|
|
121
|
-
this._focusButtonMode = navigator.platform.includes('Mac');
|
|
122
|
-
|
|
123
|
-
this.__editModeRenderer = function (root, column) {
|
|
124
|
-
const cell = root.assignedSlot.parentNode;
|
|
125
|
-
|
|
126
|
-
const tagName = column._getEditorTagName(cell);
|
|
127
|
-
if (!root.firstElementChild || root.firstElementChild.localName.toLowerCase() !== tagName) {
|
|
128
|
-
root.innerHTML = `
|
|
129
|
-
<${tagName}></${tagName}>
|
|
130
|
-
`;
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** @private */
|
|
136
|
-
_pathChanged(path) {
|
|
137
|
-
if (!path || path.length === 0) {
|
|
138
|
-
throw new Error('You should specify the path for the edit column');
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/** @private */
|
|
143
|
-
_cellsChanged() {
|
|
144
|
-
this._cells.forEach((cell) => {
|
|
145
|
-
const target = cell._focusButton || cell;
|
|
146
|
-
addValueToAttribute(target, 'part', 'editable-cell');
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** @private */
|
|
151
|
-
_editModeRendererChanged(renderer) {
|
|
152
|
-
if (renderer) {
|
|
153
|
-
this.editorType = 'custom';
|
|
154
|
-
} else if (this._oldRenderer) {
|
|
155
|
-
this.editorType = 'text';
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
this._oldRenderer = renderer;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* @param {!HTMLElement} cell
|
|
163
|
-
* @return {string}
|
|
164
|
-
* @protected
|
|
165
|
-
*/
|
|
166
|
-
_getEditorTagName(cell) {
|
|
167
|
-
return this.editorType === 'custom' ? this._getEditorComponent(cell).localName : this._getTagNameByType();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* @param {!HTMLElement} cell
|
|
172
|
-
* @return {HTMLElement | null}
|
|
173
|
-
* @protected
|
|
174
|
-
*/
|
|
175
|
-
_getEditorComponent(cell) {
|
|
176
|
-
return this.editorType === 'custom'
|
|
177
|
-
? cell._content.firstElementChild
|
|
178
|
-
: cell._content.querySelector(this._getEditorTagName(cell));
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/** @private */
|
|
182
|
-
_getTagNameByType() {
|
|
183
|
-
let type;
|
|
184
|
-
switch (this.editorType) {
|
|
185
|
-
case 'checkbox':
|
|
186
|
-
type = 'checkbox';
|
|
187
|
-
break;
|
|
188
|
-
case 'select':
|
|
189
|
-
type = 'select';
|
|
190
|
-
break;
|
|
191
|
-
case 'text':
|
|
192
|
-
default:
|
|
193
|
-
type = 'text-field';
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
return this.constructor.is.replace('column', type);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/** @private */
|
|
200
|
-
_focusEditor(editor) {
|
|
201
|
-
editor.focus();
|
|
202
|
-
if (this.editorType === 'checkbox') {
|
|
203
|
-
editor.setAttribute('focus-ring', '');
|
|
204
|
-
} else if (editor instanceof HTMLInputElement) {
|
|
205
|
-
editor.select();
|
|
206
|
-
} else if (editor.focusElement && editor.focusElement instanceof HTMLInputElement) {
|
|
207
|
-
editor.focusElement.select();
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* @param {!HTMLElement} editor
|
|
213
|
-
* @return {unknown}
|
|
214
|
-
* @protected
|
|
215
|
-
*/
|
|
216
|
-
_getEditorValue(editor) {
|
|
217
|
-
const path = this.editorType === 'checkbox' ? 'checked' : this.editorValuePath;
|
|
218
|
-
return get(editor, path);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/** @private */
|
|
222
|
-
_renderEditor(cell, model) {
|
|
223
|
-
cell.__savedRenderer = this._renderer || cell._renderer;
|
|
224
|
-
cell._renderer = this.editModeRenderer || this.__editModeRenderer;
|
|
225
|
-
|
|
226
|
-
// Remove role to avoid announcing button while editing
|
|
227
|
-
if (cell._focusButton) {
|
|
228
|
-
cell._focusButton.removeAttribute('role');
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
this._clearCellContent(cell);
|
|
232
|
-
this._runRenderer(cell._renderer, cell, model);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/** @private */
|
|
236
|
-
_removeEditor(cell, _model) {
|
|
237
|
-
if (!cell.__savedRenderer) {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
cell._renderer = cell.__savedRenderer;
|
|
242
|
-
cell.__savedRenderer = undefined;
|
|
243
|
-
|
|
244
|
-
this._clearCellContent(cell);
|
|
245
|
-
|
|
246
|
-
// Restore previously removed role attribute
|
|
247
|
-
if (cell._focusButton) {
|
|
248
|
-
cell._focusButton.setAttribute('role', 'button');
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
this.__renderCellsContent(cell._renderer, [cell]);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/** @private */
|
|
255
|
-
_setEditorOptions(editor) {
|
|
256
|
-
if (this.editorOptions && this.editorOptions.length) {
|
|
257
|
-
editor.options = this.editorOptions;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/** @private */
|
|
262
|
-
_setEditorValue(editor, value) {
|
|
263
|
-
const path = this.editorType === 'checkbox' ? 'checked' : this.editorValuePath;
|
|
264
|
-
// FIXME(yuriy): Required for the flow counterpart as it is passing the string value to webcomponent
|
|
265
|
-
value = this.editorType === 'checkbox' && typeof value === 'string' ? value === 'true' : value;
|
|
266
|
-
set(editor, path, value);
|
|
267
|
-
if (editor.notifyPath) {
|
|
268
|
-
editor.notifyPath(path, value);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* @param {!HTMLElement} cell
|
|
274
|
-
* @param {!GridItemModel} model
|
|
275
|
-
* @protected
|
|
276
|
-
*/
|
|
277
|
-
_startCellEdit(cell, model) {
|
|
278
|
-
this._renderEditor(cell, model);
|
|
279
|
-
|
|
280
|
-
const editor = this._getEditorComponent(cell);
|
|
281
|
-
editor.addEventListener('focusout', this._grid.__boundEditorFocusOut);
|
|
282
|
-
editor.addEventListener('focusin', this._grid.__boundEditorFocusIn);
|
|
283
|
-
editor.addEventListener('internal-tab', this._grid.__boundCancelCellSwitch);
|
|
284
|
-
document.body.addEventListener('focusin', this._grid.__boundGlobalFocusIn);
|
|
285
|
-
this._setEditorOptions(editor);
|
|
286
|
-
this._setEditorValue(editor, get(model.item, this.path));
|
|
287
|
-
editor._grid = this._grid;
|
|
288
|
-
this._focusEditor(editor);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* @param {!HTMLElement} cell
|
|
293
|
-
* @param {!GridItemModel} model
|
|
294
|
-
* @protected
|
|
295
|
-
*/
|
|
296
|
-
_stopCellEdit(cell, model) {
|
|
297
|
-
document.body.removeEventListener('focusin', this._grid.__boundGlobalFocusIn);
|
|
298
|
-
|
|
299
|
-
this._removeEditor(cell, model);
|
|
300
|
-
}
|
|
301
41
|
}
|
|
302
42
|
|
|
303
43
|
defineCustomElement(GridProEditColumn);
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @polymerMixin
|
|
14
|
+
*/
|
|
15
|
+
export const GridProEditSelectMixin = (superClass) =>
|
|
16
|
+
class extends superClass {
|
|
17
|
+
static get properties() {
|
|
18
|
+
return {
|
|
19
|
+
options: {
|
|
20
|
+
type: Array,
|
|
21
|
+
value: () => [],
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
_grid: {
|
|
25
|
+
type: Object,
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
_initialized: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static get observers() {
|
|
35
|
+
return ['_optionsChanged(options)'];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
ready() {
|
|
39
|
+
super.ready();
|
|
40
|
+
|
|
41
|
+
this.setAttribute('theme', 'grid-pro-editor');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_onKeyDown(e) {
|
|
45
|
+
super._onKeyDown(e);
|
|
46
|
+
|
|
47
|
+
if (this.options.length === 0 && /^(ArrowDown|Down|ArrowUp|Up|Enter|SpaceBar| )$/u.test(e.key)) {
|
|
48
|
+
console.warn('Missing "editorOptions" for <vaadin-grid-pro-edit-column> select editor!');
|
|
49
|
+
}
|
|
50
|
+
// Event handled in select, stop here
|
|
51
|
+
if (e.defaultPrevented) {
|
|
52
|
+
e.stopPropagation();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Override list-box event listener inherited from `Select`:
|
|
58
|
+
* - Enter: set flag for moving to next row on value change,
|
|
59
|
+
* - Tab: switch to next cell when "singleCellEdit" is false.
|
|
60
|
+
* @param {!KeyboardEvent} event
|
|
61
|
+
* @protected
|
|
62
|
+
* @override
|
|
63
|
+
*/
|
|
64
|
+
_onKeyDownInside(event) {
|
|
65
|
+
if (event.keyCode === 13) {
|
|
66
|
+
this._enterKeydown = event;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (event.keyCode === 9) {
|
|
70
|
+
if (!this._grid.singleCellEdit) {
|
|
71
|
+
this._grid._switchEditCell(event);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Call `super` to close overlay on Tab.
|
|
76
|
+
super._onKeyDownInside(event);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_valueChanged(value, oldValue) {
|
|
80
|
+
super._valueChanged(value, oldValue);
|
|
81
|
+
|
|
82
|
+
// Select is first created without a value
|
|
83
|
+
if (value === '' && oldValue === undefined) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (this._initialized) {
|
|
87
|
+
const enter = this._enterKeydown;
|
|
88
|
+
if (enter && this._grid.enterNextRow) {
|
|
89
|
+
this._grid._switchEditCell(enter);
|
|
90
|
+
} else if (this._grid.singleCellEdit) {
|
|
91
|
+
this._grid._stopEdit(false, true);
|
|
92
|
+
} else {
|
|
93
|
+
this.focus();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
_optionsChanged(options) {
|
|
99
|
+
if (options && options.length) {
|
|
100
|
+
this.items = options.map((option) => ({
|
|
101
|
+
label: option,
|
|
102
|
+
value: option,
|
|
103
|
+
}));
|
|
104
|
+
|
|
105
|
+
this._overlayElement ||= this.shadowRoot.querySelector('vaadin-select-overlay');
|
|
106
|
+
this._overlayElement.addEventListener('vaadin-overlay-outside-click', () => {
|
|
107
|
+
this._grid._stopEdit();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// FIXME(web-padawan): _updateValueSlot() in `vaadin-select` resets opened to false
|
|
111
|
+
// see https://github.com/vaadin/vaadin-list-mixin/issues/49
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
this.opened = true;
|
|
114
|
+
// Any value change after first open will stop edit
|
|
115
|
+
this._initialized = true;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
@@ -8,134 +8,22 @@
|
|
|
8
8
|
* See https://vaadin.com/commercial-license-and-service-terms for the full
|
|
9
9
|
* license.
|
|
10
10
|
*/
|
|
11
|
-
import '@vaadin/item/src/vaadin-item.js';
|
|
12
|
-
import '@vaadin/list-box/src/vaadin-list-box.js';
|
|
13
11
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
14
12
|
import { Select } from '@vaadin/select/src/vaadin-select.js';
|
|
13
|
+
import { GridProEditSelectMixin } from './vaadin-grid-pro-edit-select-mixin.js';
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* An element used internally by `<vaadin-grid-pro>`. Not intended to be used separately.
|
|
18
17
|
*
|
|
19
18
|
* @customElement
|
|
20
19
|
* @extends Select
|
|
20
|
+
* @mixes GridProEditSelectMixin
|
|
21
21
|
* @private
|
|
22
22
|
*/
|
|
23
|
-
class GridProEditSelect extends Select {
|
|
23
|
+
class GridProEditSelect extends GridProEditSelectMixin(Select) {
|
|
24
24
|
static get is() {
|
|
25
25
|
return 'vaadin-grid-pro-edit-select';
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
static get properties() {
|
|
29
|
-
return {
|
|
30
|
-
options: {
|
|
31
|
-
type: Array,
|
|
32
|
-
value: () => [],
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
_grid: {
|
|
36
|
-
type: Object,
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
_initialized: {
|
|
40
|
-
type: Boolean,
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static get observers() {
|
|
46
|
-
return ['_optionsChanged(options)'];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
ready() {
|
|
50
|
-
super.ready();
|
|
51
|
-
|
|
52
|
-
this.setAttribute('theme', 'grid-pro-editor');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
_onKeyDown(e) {
|
|
56
|
-
super._onKeyDown(e);
|
|
57
|
-
|
|
58
|
-
if (this.options.length === 0 && /^(ArrowDown|Down|ArrowUp|Up|Enter|SpaceBar| )$/u.test(e.key)) {
|
|
59
|
-
console.warn('Missing "editorOptions" for <vaadin-grid-pro-edit-column> select editor!');
|
|
60
|
-
}
|
|
61
|
-
// Event handled in select, stop here
|
|
62
|
-
if (e.defaultPrevented) {
|
|
63
|
-
e.stopPropagation();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Override list-box event listener inherited from `Select`:
|
|
69
|
-
* - Enter: set flag for moving to next row on value change,
|
|
70
|
-
* - Tab: switch to next cell when "singleCellEdit" is false.
|
|
71
|
-
* @param {!KeyboardEvent} event
|
|
72
|
-
* @protected
|
|
73
|
-
* @override
|
|
74
|
-
*/
|
|
75
|
-
_onKeyDownInside(event) {
|
|
76
|
-
if (event.keyCode === 13) {
|
|
77
|
-
this._enterKeydown = event;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (event.keyCode === 9) {
|
|
81
|
-
if (!this._grid.singleCellEdit) {
|
|
82
|
-
this._grid._switchEditCell(event);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Call `super` to close overlay on Tab.
|
|
87
|
-
super._onKeyDownInside(event);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
_valueChanged(value, oldValue) {
|
|
91
|
-
super._valueChanged(value, oldValue);
|
|
92
|
-
|
|
93
|
-
// Select is first created without a value
|
|
94
|
-
if (value === '' && oldValue === undefined) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (this._initialized) {
|
|
98
|
-
const enter = this._enterKeydown;
|
|
99
|
-
if (enter && this._grid.enterNextRow) {
|
|
100
|
-
this._grid._switchEditCell(enter);
|
|
101
|
-
} else if (this._grid.singleCellEdit) {
|
|
102
|
-
this._grid._stopEdit(false, true);
|
|
103
|
-
} else {
|
|
104
|
-
this.focus();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
_optionsChanged(options) {
|
|
110
|
-
if (options && options.length) {
|
|
111
|
-
this.renderer = (root) => {
|
|
112
|
-
if (root.firstChild) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const listBox = document.createElement('vaadin-list-box');
|
|
116
|
-
listBox.selected = options.indexOf(this.value);
|
|
117
|
-
options.forEach((option) => {
|
|
118
|
-
const item = document.createElement('vaadin-item');
|
|
119
|
-
item.textContent = option;
|
|
120
|
-
listBox.appendChild(item);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
root.appendChild(listBox);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
this._overlayElement.addEventListener('vaadin-overlay-outside-click', () => {
|
|
127
|
-
this._grid._stopEdit();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
// FIXME(web-padawan): _updateValueSlot() in `vaadin-select` resets opened to false
|
|
131
|
-
// see https://github.com/vaadin/vaadin-list-mixin/issues/49
|
|
132
|
-
setTimeout(() => {
|
|
133
|
-
this.opened = true;
|
|
134
|
-
// Any value change after first open will stop edit
|
|
135
|
-
this._initialized = true;
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
27
|
}
|
|
140
28
|
|
|
141
29
|
defineCustomElement(GridProEditSelect);
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { animationFrame } from '@vaadin/component-base/src/async.js';
|
|
12
12
|
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
|
|
13
|
+
import { get, set } from '@vaadin/component-base/src/path-utils.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @polymerMixin
|
|
@@ -194,8 +195,8 @@ export const InlineEditingMixin = (superClass) =>
|
|
|
194
195
|
|
|
195
196
|
/** @private */
|
|
196
197
|
_applyEdit({ path, value, index, item }) {
|
|
197
|
-
|
|
198
|
-
this.
|
|
198
|
+
set(path, value, item);
|
|
199
|
+
this.requestContentUpdate();
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
/** @private */
|
|
@@ -365,7 +366,7 @@ export const InlineEditingMixin = (superClass) =>
|
|
|
365
366
|
const editor = column._getEditorComponent(cell);
|
|
366
367
|
if (editor) {
|
|
367
368
|
const value = column._getEditorValue(editor);
|
|
368
|
-
if (value !==
|
|
369
|
+
if (value !== get(column.path, model.item)) {
|
|
369
370
|
// In some cases, where the value comes from the editor's change
|
|
370
371
|
// event (eg. custom editor in vaadin-grid-pro-flow), the event is
|
|
371
372
|
// not dispatched in FF/Safari/Edge. That's due the change event
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { Checkbox } from '@vaadin/checkbox/src/vaadin-lit-checkbox.js';
|
|
12
|
+
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* LitElement based version of `<vaadin-grid-pro-edit-checkbox>` web component.
|
|
16
|
+
*
|
|
17
|
+
* ## Disclaimer
|
|
18
|
+
*
|
|
19
|
+
* This component is an experiment not intended for publishing to npm.
|
|
20
|
+
* There is no ETA regarding specific Vaadin version where it'll land.
|
|
21
|
+
* Feel free to try this code in your apps as per Apache 2.0 license.
|
|
22
|
+
*/
|
|
23
|
+
class GridProEditCheckbox extends Checkbox {
|
|
24
|
+
static get is() {
|
|
25
|
+
return 'vaadin-grid-pro-edit-checkbox';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
defineCustomElement(GridProEditCheckbox);
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
12
|
+
import { Select } from '@vaadin/select/src/vaadin-lit-select.js';
|
|
13
|
+
import { GridProEditSelectMixin } from './vaadin-grid-pro-edit-select-mixin.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* LitElement based version of `<vaadin-grid-pro-edit-select>` web component.
|
|
17
|
+
*
|
|
18
|
+
* ## Disclaimer
|
|
19
|
+
*
|
|
20
|
+
* This component is an experiment not intended for publishing to npm.
|
|
21
|
+
* There is no ETA regarding specific Vaadin version where it'll land.
|
|
22
|
+
* Feel free to try this code in your apps as per Apache 2.0 license.
|
|
23
|
+
*/
|
|
24
|
+
class GridProEditSelect extends GridProEditSelectMixin(Select) {
|
|
25
|
+
static get is() {
|
|
26
|
+
return 'vaadin-grid-pro-edit-select';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
defineCustomElement(GridProEditSelect);
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
12
|
+
import { TextField } from '@vaadin/text-field/src/vaadin-lit-text-field.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* LitElement based version of `<vaadin-grid-pro-edit-text-field>` web component.
|
|
16
|
+
*
|
|
17
|
+
* ## Disclaimer
|
|
18
|
+
*
|
|
19
|
+
* This component is an experiment not intended for publishing to npm.
|
|
20
|
+
* There is no ETA regarding specific Vaadin version where it'll land.
|
|
21
|
+
* Feel free to try this code in your apps as per Apache 2.0 license.
|
|
22
|
+
*/
|
|
23
|
+
class GridProEditText extends TextField {
|
|
24
|
+
static get is() {
|
|
25
|
+
return 'vaadin-grid-pro-edit-text-field';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
ready() {
|
|
29
|
+
super.ready();
|
|
30
|
+
this.setAttribute('theme', 'grid-pro-editor');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
defineCustomElement(GridProEditText);
|
|
@@ -12,7 +12,7 @@ const gridProEditor = css`
|
|
|
12
12
|
font-size: inherit;
|
|
13
13
|
--lumo-text-field-size: 27px;
|
|
14
14
|
/* outline similar to what grid uses */
|
|
15
|
-
box-shadow: inset 0 0 0
|
|
15
|
+
box-shadow: inset 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
:host([theme~='grid-pro-editor']) [part='input-field'] {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import '@vaadin/item/theme/material/vaadin-item.js';
|
|
2
|
-
import '@vaadin/list-box/theme/material/vaadin-list-box.js';
|
|
3
1
|
import '@vaadin/select/theme/material/vaadin-select.js';
|
|
4
2
|
import './vaadin-grid-pro-edit-select-styles.js';
|
|
5
3
|
import '../../src/vaadin-grid-pro-edit-select.js';
|
package/web-types.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/web-types",
|
|
3
3
|
"name": "@vaadin/grid-pro",
|
|
4
|
-
"version": "24.
|
|
4
|
+
"version": "24.3.0-alpha10",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"contributions": {
|
|
7
7
|
"html": {
|
|
@@ -81,6 +81,28 @@
|
|
|
81
81
|
]
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
|
+
{
|
|
85
|
+
"name": "header-part-name",
|
|
86
|
+
"description": "Custom part name for the header cell.",
|
|
87
|
+
"value": {
|
|
88
|
+
"type": [
|
|
89
|
+
"string",
|
|
90
|
+
"null",
|
|
91
|
+
"undefined"
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"name": "footer-part-name",
|
|
97
|
+
"description": "Custom part name for the footer cell.",
|
|
98
|
+
"value": {
|
|
99
|
+
"type": [
|
|
100
|
+
"string",
|
|
101
|
+
"null",
|
|
102
|
+
"undefined"
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
},
|
|
84
106
|
{
|
|
85
107
|
"name": "width",
|
|
86
108
|
"description": "Width of the cells for this column.",
|
|
@@ -224,6 +246,28 @@
|
|
|
224
246
|
]
|
|
225
247
|
}
|
|
226
248
|
},
|
|
249
|
+
{
|
|
250
|
+
"name": "headerPartName",
|
|
251
|
+
"description": "Custom part name for the header cell.",
|
|
252
|
+
"value": {
|
|
253
|
+
"type": [
|
|
254
|
+
"string",
|
|
255
|
+
"null",
|
|
256
|
+
"undefined"
|
|
257
|
+
]
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
"name": "footerPartName",
|
|
262
|
+
"description": "Custom part name for the footer cell.",
|
|
263
|
+
"value": {
|
|
264
|
+
"type": [
|
|
265
|
+
"string",
|
|
266
|
+
"null",
|
|
267
|
+
"undefined"
|
|
268
|
+
]
|
|
269
|
+
}
|
|
270
|
+
},
|
|
227
271
|
{
|
|
228
272
|
"name": "headerRenderer",
|
|
229
273
|
"description": "Custom function for rendering the header content.\nReceives two arguments:\n\n- `root` The header cell content DOM element. Append your content to it.\n- `column` The `<vaadin-grid-column>` element.",
|
|
@@ -346,7 +390,7 @@
|
|
|
346
390
|
},
|
|
347
391
|
{
|
|
348
392
|
"name": "vaadin-grid-pro",
|
|
349
|
-
"description": "`<vaadin-grid-pro>` is a high quality data grid / data table Web Component with extended functionality.\nIt extends `<vaadin-grid>` and adds extra features on top of the basic ones.\n\nSee [`<vaadin-grid>`](https://cdn.vaadin.com/vaadin-web-components/24.
|
|
393
|
+
"description": "`<vaadin-grid-pro>` is a high quality data grid / data table Web Component with extended functionality.\nIt extends `<vaadin-grid>` and adds extra features on top of the basic ones.\n\nSee [`<vaadin-grid>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-alpha10/#/elements/vaadin-grid) documentation for details.\n\n```\n<vaadin-grid-pro></vaadin-grid-pro>\n```\n\n### Internal components\n\nIn addition to `<vaadin-grid-pro>` itself, the following internal\ncomponents are themable:\n\n- `<vaadin-grid-pro-edit-checkbox>` - has the same API as [`<vaadin-checkbox>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-alpha10/#/elements/vaadin-checkbox).\n- `<vaadin-grid-pro-edit-text-field>` - has the same API as [`<vaadin-text-field>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-alpha10/#/elements/vaadin-text-field).\n- `<vaadin-grid-pro-edit-select>` - has the same API as [`<vaadin-select>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-alpha10/#/elements/vaadin-select).",
|
|
350
394
|
"attributes": [
|
|
351
395
|
{
|
|
352
396
|
"name": "size",
|
package/web-types.lit.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/web-types",
|
|
3
3
|
"name": "@vaadin/grid-pro",
|
|
4
|
-
"version": "24.
|
|
4
|
+
"version": "24.3.0-alpha10",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"framework": "lit",
|
|
7
7
|
"framework-config": {
|
|
@@ -75,6 +75,20 @@
|
|
|
75
75
|
"kind": "expression"
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
{
|
|
79
|
+
"name": ".headerPartName",
|
|
80
|
+
"description": "Custom part name for the header cell.",
|
|
81
|
+
"value": {
|
|
82
|
+
"kind": "expression"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"name": ".footerPartName",
|
|
87
|
+
"description": "Custom part name for the footer cell.",
|
|
88
|
+
"value": {
|
|
89
|
+
"kind": "expression"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
78
92
|
{
|
|
79
93
|
"name": ".headerRenderer",
|
|
80
94
|
"description": "Custom function for rendering the header content.\nReceives two arguments:\n\n- `root` The header cell content DOM element. Append your content to it.\n- `column` The `<vaadin-grid-column>` element.",
|
|
@@ -156,7 +170,7 @@
|
|
|
156
170
|
},
|
|
157
171
|
{
|
|
158
172
|
"name": "vaadin-grid-pro",
|
|
159
|
-
"description": "`<vaadin-grid-pro>` is a high quality data grid / data table Web Component with extended functionality.\nIt extends `<vaadin-grid>` and adds extra features on top of the basic ones.\n\nSee [`<vaadin-grid>`](https://cdn.vaadin.com/vaadin-web-components/24.
|
|
173
|
+
"description": "`<vaadin-grid-pro>` is a high quality data grid / data table Web Component with extended functionality.\nIt extends `<vaadin-grid>` and adds extra features on top of the basic ones.\n\nSee [`<vaadin-grid>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-alpha10/#/elements/vaadin-grid) documentation for details.\n\n```\n<vaadin-grid-pro></vaadin-grid-pro>\n```\n\n### Internal components\n\nIn addition to `<vaadin-grid-pro>` itself, the following internal\ncomponents are themable:\n\n- `<vaadin-grid-pro-edit-checkbox>` - has the same API as [`<vaadin-checkbox>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-alpha10/#/elements/vaadin-checkbox).\n- `<vaadin-grid-pro-edit-text-field>` - has the same API as [`<vaadin-text-field>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-alpha10/#/elements/vaadin-text-field).\n- `<vaadin-grid-pro-edit-select>` - has the same API as [`<vaadin-select>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-alpha10/#/elements/vaadin-select).",
|
|
160
174
|
"extension": true,
|
|
161
175
|
"attributes": [
|
|
162
176
|
{
|