@vaadin/grid-pro 22.0.0-alpha7
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/LICENSE +262 -0
- package/README.md +72 -0
- package/package.json +58 -0
- package/src/interfaces.d.ts +1 -0
- package/src/vaadin-grid-pro-edit-checkbox.js +21 -0
- package/src/vaadin-grid-pro-edit-column.d.ts +85 -0
- package/src/vaadin-grid-pro-edit-column.js +282 -0
- package/src/vaadin-grid-pro-edit-select.js +128 -0
- package/src/vaadin-grid-pro-edit-text-field.js +26 -0
- package/src/vaadin-grid-pro-inline-editing-mixin.d.ts +40 -0
- package/src/vaadin-grid-pro-inline-editing-mixin.js +483 -0
- package/src/vaadin-grid-pro.d.ts +95 -0
- package/src/vaadin-grid-pro.js +68 -0
- package/theme/lumo/vaadin-grid-pro-edit-checkbox.js +2 -0
- package/theme/lumo/vaadin-grid-pro-edit-column.js +4 -0
- package/theme/lumo/vaadin-grid-pro-edit-select-styles.js +24 -0
- package/theme/lumo/vaadin-grid-pro-edit-select.js +5 -0
- package/theme/lumo/vaadin-grid-pro-edit-text-field-styles.js +6 -0
- package/theme/lumo/vaadin-grid-pro-edit-text-field.js +3 -0
- package/theme/lumo/vaadin-grid-pro-editor-styles.js +41 -0
- package/theme/lumo/vaadin-grid-pro-styles.js +19 -0
- package/theme/lumo/vaadin-grid-pro.js +3 -0
- package/theme/material/vaadin-grid-pro-edit-checkbox.js +2 -0
- package/theme/material/vaadin-grid-pro-edit-column.js +4 -0
- package/theme/material/vaadin-grid-pro-edit-select-styles.js +17 -0
- package/theme/material/vaadin-grid-pro-edit-select.js +5 -0
- package/theme/material/vaadin-grid-pro-edit-text-field-styles.js +6 -0
- package/theme/material/vaadin-grid-pro-edit-text-field.js +3 -0
- package/theme/material/vaadin-grid-pro-editor-styles.js +21 -0
- package/theme/material/vaadin-grid-pro-styles.js +13 -0
- package/theme/material/vaadin-grid-pro.js +3 -0
- package/vaadin-grid-pro-edit-column.d.ts +1 -0
- package/vaadin-grid-pro-edit-column.js +3 -0
- package/vaadin-grid-pro.d.ts +2 -0
- package/vaadin-grid-pro.js +3 -0
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2019 - 2021 Vaadin Ltd.
|
|
4
|
+
* This program is available under Commercial Vaadin Developer License 4.0 (CVDLv4).
|
|
5
|
+
* See <a href="https://vaadin.com/license/cvdl-4.0">the website</a> for the complete license.
|
|
6
|
+
*/
|
|
7
|
+
import { animationFrame } from '@vaadin/component-base/src/async.js';
|
|
8
|
+
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @polymerMixin
|
|
12
|
+
*/
|
|
13
|
+
export const InlineEditingMixin = (superClass) =>
|
|
14
|
+
class InlineEditingMixin extends superClass {
|
|
15
|
+
static get properties() {
|
|
16
|
+
return {
|
|
17
|
+
/**
|
|
18
|
+
* When true, pressing Enter while in cell edit mode
|
|
19
|
+
* will move focus to the editable cell in the next row
|
|
20
|
+
* (Shift + Enter - same, but for previous row).
|
|
21
|
+
* @attr {boolean} enter-next-row
|
|
22
|
+
*/
|
|
23
|
+
enterNextRow: {
|
|
24
|
+
type: Boolean,
|
|
25
|
+
notify: true // FIXME(yuriy-fix): needed by Flow counterpart
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* When true, after moving to next or previous editable cell using
|
|
30
|
+
* Tab / Shift+Tab, it will be focused without edit mode.
|
|
31
|
+
*
|
|
32
|
+
* When `enterNextRow` is true, pressing Enter will also
|
|
33
|
+
* preserve edit mode, otherwise, it will have no effect.
|
|
34
|
+
* @attr {boolean} single-cell-edit
|
|
35
|
+
*/
|
|
36
|
+
singleCellEdit: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
notify: true // FIXME(yuriy-fix): needed by Flow counterpart
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* When true, the grid enters cell edit mode on a single click
|
|
43
|
+
* instead of the default double click.
|
|
44
|
+
* @attr {boolean} edit-on-click
|
|
45
|
+
*/
|
|
46
|
+
editOnClick: {
|
|
47
|
+
type: Boolean
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
/** @private */
|
|
51
|
+
_editingDisabled: {
|
|
52
|
+
type: Boolean
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
constructor() {
|
|
58
|
+
super();
|
|
59
|
+
this.__boundItemPropertyChanged = this._onItemPropertyChanged.bind(this);
|
|
60
|
+
this.__boundEditorFocusOut = this._onEditorFocusOut.bind(this);
|
|
61
|
+
this.__boundEditorFocusIn = this._onEditorFocusIn.bind(this);
|
|
62
|
+
this.__boundCancelCellSwitch = this._setCancelCellSwitch.bind(this);
|
|
63
|
+
this.__boundGlobalFocusIn = this._onGlobalFocusIn.bind(this);
|
|
64
|
+
|
|
65
|
+
this._addEditColumnListener('mousedown', (e) => {
|
|
66
|
+
// prevent grid from resetting navigating state
|
|
67
|
+
e.stopImmediatePropagation();
|
|
68
|
+
this.toggleAttribute('navigating', true);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
this._addEditColumnListener('focusout', (e) => {
|
|
72
|
+
// prevent grid from resetting navigating state
|
|
73
|
+
e.stopImmediatePropagation();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @protected */
|
|
78
|
+
ready() {
|
|
79
|
+
// add listener before `vaadin-grid` interaction mode listener
|
|
80
|
+
this.addEventListener('keydown', (e) => {
|
|
81
|
+
switch (e.keyCode) {
|
|
82
|
+
case 27:
|
|
83
|
+
this.__edited && this._stopEdit(true);
|
|
84
|
+
break;
|
|
85
|
+
case 9:
|
|
86
|
+
this.__edited && this._switchEditCell(e);
|
|
87
|
+
break;
|
|
88
|
+
case 13:
|
|
89
|
+
this.__edited ? this._switchEditCell(e) : this._enterEditFromEvent(e);
|
|
90
|
+
break;
|
|
91
|
+
case 32:
|
|
92
|
+
!this.__edited && this._enterEditFromEvent(e);
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
e.key && e.key.length === 1 && this._enterEditFromEvent(e, 'text');
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
super.ready();
|
|
101
|
+
|
|
102
|
+
this.$.table.addEventListener('click', (e) => {
|
|
103
|
+
const column = this.getEventContext(e).column;
|
|
104
|
+
if (column && this._isEditColumn(column)) {
|
|
105
|
+
if (e.target.matches(':not([type=checkbox])')) {
|
|
106
|
+
// Prevents the `click` event from a column's cell in order to prevent making the cell's parent row active.
|
|
107
|
+
// Note, it should not prevent the `click` event from checkboxes. Otherwise, they will not respond to user interactions.
|
|
108
|
+
// Read more: https://github.com/vaadin/web-components/pull/2539#discussion_r712076433.
|
|
109
|
+
// TODO: Using `preventDefault()` for any other purpose than preventing the default browser's behavior is bad practice
|
|
110
|
+
// and therefore it would be great to refactor this part someday.
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (this.editOnClick) {
|
|
115
|
+
this._enterEditFromEvent(e);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// dblclick does not work on iOS Safari
|
|
121
|
+
if (this._ios) {
|
|
122
|
+
let firstClickTime;
|
|
123
|
+
let waitingSecondClick = false;
|
|
124
|
+
|
|
125
|
+
this.addEventListener('click', (e) => {
|
|
126
|
+
if (!waitingSecondClick) {
|
|
127
|
+
firstClickTime = new Date().getTime();
|
|
128
|
+
waitingSecondClick = true;
|
|
129
|
+
|
|
130
|
+
setTimeout(() => {
|
|
131
|
+
waitingSecondClick = false;
|
|
132
|
+
}, 300);
|
|
133
|
+
} else {
|
|
134
|
+
waitingSecondClick = false;
|
|
135
|
+
|
|
136
|
+
const time = new Date().getTime();
|
|
137
|
+
if (time - firstClickTime < 300) {
|
|
138
|
+
this._enterEditFromEvent(e);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
} else {
|
|
143
|
+
this.addEventListener('dblclick', (e) => {
|
|
144
|
+
if (!this.editOnClick) {
|
|
145
|
+
this._enterEditFromEvent(e);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** @protected */
|
|
152
|
+
_checkImports() {
|
|
153
|
+
super._checkImports();
|
|
154
|
+
['vaadin-grid-pro-edit-column'].forEach((elementName) => {
|
|
155
|
+
const element = this.querySelector(elementName);
|
|
156
|
+
if (element && !customElements.get(elementName)) {
|
|
157
|
+
console.warn(`Make sure you have imported the required module for <${elementName}> element.`);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** @private */
|
|
163
|
+
_applyEdit({ path, value, index, item }) {
|
|
164
|
+
this.set(path, value, item);
|
|
165
|
+
this.notifyPath('items.' + index + '.' + path, value);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** @private */
|
|
169
|
+
_addEditColumnListener(type, callback) {
|
|
170
|
+
this.addEventListener(type, (e) => {
|
|
171
|
+
const context = this.getEventContext(e);
|
|
172
|
+
const column = context.column;
|
|
173
|
+
const edited = this.__edited;
|
|
174
|
+
|
|
175
|
+
if (context.item && this._isEditColumn(column)) {
|
|
176
|
+
const path = e.composedPath();
|
|
177
|
+
const cell = path[path.indexOf(this.$.table) - 3];
|
|
178
|
+
|
|
179
|
+
if (!cell || cell.getAttribute('part').indexOf('details-cell') > -1) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (edited && edited.cell === cell) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
callback(e);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** @private */
|
|
193
|
+
_onItemPropertyChanged(e) {
|
|
194
|
+
if (!e.defaultPrevented) {
|
|
195
|
+
this._applyEdit(e.detail);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** @private */
|
|
200
|
+
_getRowByIndex(index) {
|
|
201
|
+
return Array.from(this.$.items.children).filter((el) => el.index === index)[0];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** @private */
|
|
205
|
+
_isEditColumn(column) {
|
|
206
|
+
return column && column.localName.toLowerCase() === 'vaadin-grid-pro-edit-column';
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** @private */
|
|
210
|
+
_getEditColumns() {
|
|
211
|
+
const columnTreeLevel = this._columnTree.length - 1;
|
|
212
|
+
return this._columnTree[columnTreeLevel]
|
|
213
|
+
.filter((column) => this._isEditColumn(column) && !column.hidden)
|
|
214
|
+
.sort((a, b) => a._order - b._order);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** @private */
|
|
218
|
+
_cancelStopEdit() {
|
|
219
|
+
// stop edit on outside click will always trigger notify resize.
|
|
220
|
+
// when tabbing within same row it might not be needed, so cancel
|
|
221
|
+
if (this._debouncerStopEdit) {
|
|
222
|
+
this._debouncerStopEdit.cancel();
|
|
223
|
+
delete this._debouncerStopEdit;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** @private */
|
|
228
|
+
_flushStopEdit() {
|
|
229
|
+
if (this._debouncerStopEdit) {
|
|
230
|
+
this._debouncerStopEdit.flush();
|
|
231
|
+
delete this._debouncerStopEdit;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** @private */
|
|
236
|
+
_enterEditFromEvent(e, type) {
|
|
237
|
+
const context = this.getEventContext(e);
|
|
238
|
+
const column = context.column;
|
|
239
|
+
const edited = this.__edited;
|
|
240
|
+
|
|
241
|
+
if (context.item && this._isEditColumn(column)) {
|
|
242
|
+
const path = e.composedPath();
|
|
243
|
+
const cell = path[path.indexOf(this.$.table) - 3];
|
|
244
|
+
|
|
245
|
+
if (!cell || cell.getAttribute('part').indexOf('details-cell') > -1) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (type && column.editorType !== type) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (edited && edited.cell === cell && column._getEditorComponent(cell).contains(e.target)) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
this._flushStopEdit();
|
|
258
|
+
|
|
259
|
+
this._startEdit(cell, column);
|
|
260
|
+
} else if (edited) {
|
|
261
|
+
this._stopEdit();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** @private */
|
|
266
|
+
_onEditorFocusOut() {
|
|
267
|
+
// schedule stop on editor component focusout
|
|
268
|
+
this._debouncerStopEdit = Debouncer.debounce(this._debouncerStopEdit, animationFrame, this._stopEdit.bind(this));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** @private */
|
|
272
|
+
_onEditorFocusIn() {
|
|
273
|
+
this._cancelStopEdit();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** @private */
|
|
277
|
+
_onGlobalFocusIn(e) {
|
|
278
|
+
const edited = this.__edited;
|
|
279
|
+
if (edited) {
|
|
280
|
+
// detect focus moving to e.g. vaadin-select-overlay
|
|
281
|
+
const overlay = Array.from(e.composedPath()).filter(
|
|
282
|
+
(node) => node.nodeType === Node.ELEMENT_NODE && /^vaadin-(?!dialog).*-overlay$/i.test(node.localName)
|
|
283
|
+
)[0];
|
|
284
|
+
|
|
285
|
+
if (overlay) {
|
|
286
|
+
overlay.addEventListener('vaadin-overlay-outside-click', this.__boundEditorFocusOut);
|
|
287
|
+
this._cancelStopEdit();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** @private */
|
|
293
|
+
_startEdit(cell, column) {
|
|
294
|
+
if (this._editingDisabled) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
// cancel debouncer enqueued on focusout
|
|
298
|
+
this._cancelStopEdit();
|
|
299
|
+
|
|
300
|
+
this._scrollHorizontallyToCell(cell);
|
|
301
|
+
|
|
302
|
+
const model = this.__getRowModel(cell.parentElement);
|
|
303
|
+
this.__edited = { cell, column, model };
|
|
304
|
+
column._startCellEdit(cell, model);
|
|
305
|
+
|
|
306
|
+
this.dispatchEvent(
|
|
307
|
+
new CustomEvent('cell-edit-started', {
|
|
308
|
+
detail: {
|
|
309
|
+
index: model.index,
|
|
310
|
+
item: model.item,
|
|
311
|
+
path: column.path
|
|
312
|
+
},
|
|
313
|
+
composed: true
|
|
314
|
+
})
|
|
315
|
+
);
|
|
316
|
+
this.addEventListener('item-property-changed', this.__boundItemPropertyChanged);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* @param {boolean=} shouldCancel
|
|
321
|
+
* @param {boolean=} shouldRestoreFocus
|
|
322
|
+
* @protected
|
|
323
|
+
*/
|
|
324
|
+
_stopEdit(shouldCancel, shouldRestoreFocus) {
|
|
325
|
+
if (!this.__edited) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const { cell, column, model } = this.__edited;
|
|
329
|
+
|
|
330
|
+
if (!shouldCancel) {
|
|
331
|
+
const editor = column._getEditorComponent(cell);
|
|
332
|
+
if (editor) {
|
|
333
|
+
const value = column._getEditorValue(editor);
|
|
334
|
+
if (value !== this.get(column.path, model.item)) {
|
|
335
|
+
// In some cases, where the value comes from the editor's change
|
|
336
|
+
// event (eg. custom editor in vaadin-grid-pro-flow), the event is
|
|
337
|
+
// not dispatched in FF/Safari/Edge. That's due the change event
|
|
338
|
+
// doesn't occur when the editor is removed from the DOM. Manually
|
|
339
|
+
// calling blur makes the event to be dispatched.
|
|
340
|
+
editor.blur();
|
|
341
|
+
|
|
342
|
+
this.dispatchEvent(
|
|
343
|
+
new CustomEvent('item-property-changed', {
|
|
344
|
+
detail: {
|
|
345
|
+
index: model.index,
|
|
346
|
+
item: model.item,
|
|
347
|
+
path: column.path,
|
|
348
|
+
value: value
|
|
349
|
+
},
|
|
350
|
+
bubbles: true,
|
|
351
|
+
cancelable: true,
|
|
352
|
+
composed: true
|
|
353
|
+
})
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
column._stopCellEdit(cell, model);
|
|
360
|
+
|
|
361
|
+
this.__edited = null;
|
|
362
|
+
|
|
363
|
+
this.removeEventListener('item-property-changed', this.__boundItemPropertyChanged);
|
|
364
|
+
|
|
365
|
+
if (shouldRestoreFocus) {
|
|
366
|
+
cell.focus();
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** @private */
|
|
371
|
+
_setCancelCellSwitch() {
|
|
372
|
+
this.__cancelCellSwitch = true;
|
|
373
|
+
window.requestAnimationFrame(() => (this.__cancelCellSwitch = false));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* @param {!KeyboardEvent} e
|
|
378
|
+
* @protected
|
|
379
|
+
*/
|
|
380
|
+
_switchEditCell(e) {
|
|
381
|
+
if (this.__cancelCellSwitch || (e.defaultPrevented && e.keyCode === 9)) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
this._cancelStopEdit();
|
|
386
|
+
|
|
387
|
+
const cols = this._getEditColumns();
|
|
388
|
+
|
|
389
|
+
const { cell, column, model } = this.__edited;
|
|
390
|
+
const colIndex = cols.indexOf(column);
|
|
391
|
+
const { index } = model;
|
|
392
|
+
|
|
393
|
+
let nextCol = null;
|
|
394
|
+
let nextIdx = index;
|
|
395
|
+
|
|
396
|
+
// enter key
|
|
397
|
+
if (e.keyCode === 13) {
|
|
398
|
+
nextCol = column;
|
|
399
|
+
|
|
400
|
+
// move up / down
|
|
401
|
+
if (this.enterNextRow) {
|
|
402
|
+
nextIdx = e.shiftKey ? index - 1 : index + 1;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// tab: move right / left
|
|
407
|
+
if (e.keyCode === 9) {
|
|
408
|
+
if (e.shiftKey) {
|
|
409
|
+
if (cols[colIndex - 1]) {
|
|
410
|
+
nextCol = cols[colIndex - 1];
|
|
411
|
+
} else {
|
|
412
|
+
if (index > 0) {
|
|
413
|
+
nextIdx = index - 1;
|
|
414
|
+
nextCol = cols[cols.length - 1];
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
} else {
|
|
418
|
+
if (cols[colIndex + 1]) {
|
|
419
|
+
nextCol = cols[colIndex + 1];
|
|
420
|
+
} else {
|
|
421
|
+
nextIdx = index + 1;
|
|
422
|
+
nextCol = cols[0];
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const nextRow = nextIdx === index ? cell.parentNode : this._getRowByIndex(nextIdx) || null;
|
|
428
|
+
|
|
429
|
+
this._stopEdit();
|
|
430
|
+
|
|
431
|
+
if (nextRow && nextCol) {
|
|
432
|
+
const nextCell = Array.from(nextRow.children).filter((cell) => cell._column === nextCol)[0];
|
|
433
|
+
e.preventDefault();
|
|
434
|
+
|
|
435
|
+
// prevent vaadin-grid handler from being called
|
|
436
|
+
e.stopImmediatePropagation();
|
|
437
|
+
|
|
438
|
+
if (!this.singleCellEdit && nextCell !== cell) {
|
|
439
|
+
this._startEdit(nextCell, nextCol);
|
|
440
|
+
} else {
|
|
441
|
+
this._ensureScrolledToIndex(nextIdx);
|
|
442
|
+
nextCell.focus();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* @param {!HTMLElement} row
|
|
449
|
+
* @param {GridItem} item
|
|
450
|
+
* @protected
|
|
451
|
+
*/
|
|
452
|
+
_updateItem(row, item) {
|
|
453
|
+
if (this.__edited) {
|
|
454
|
+
const { cell, model } = this.__edited;
|
|
455
|
+
if (cell.parentNode === row && model.item !== item) {
|
|
456
|
+
this._stopEdit();
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
super._updateItem(row, item);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Fired before exiting the cell edit mode, if the value has been changed.
|
|
464
|
+
* If the default is prevented, value change would not be applied.
|
|
465
|
+
*
|
|
466
|
+
* @event item-property-changed
|
|
467
|
+
* @param {Object} detail
|
|
468
|
+
* @param {Object} detail.index the row index of the edited cell
|
|
469
|
+
* @param {Object} detail.item the grid item rendered to the row of the edited cell
|
|
470
|
+
* @param {Object} detail.path the column path of the edited cell
|
|
471
|
+
* @param {Object} detail.value the new value of the edited cell
|
|
472
|
+
*/
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Fired when the user starts editing a grid cell.
|
|
476
|
+
*
|
|
477
|
+
* @event cell-edit-started
|
|
478
|
+
* @param {Object} detail
|
|
479
|
+
* @param {Object} detail.index the row index of the edited cell
|
|
480
|
+
* @param {Object} detail.item the grid item rendered to the row of the edited cell
|
|
481
|
+
* @param {Object} detail.path the column path of the edited cell
|
|
482
|
+
*/
|
|
483
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { GridDefaultItem, Grid, GridCustomEventMap } from '@vaadin/grid';
|
|
2
|
+
|
|
3
|
+
import { InlineEditingMixin } from './vaadin-grid-pro-inline-editing-mixin.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fired when the user starts editing a grid cell.
|
|
7
|
+
*/
|
|
8
|
+
export type GridProCellEditStartedEvent<TItem> = CustomEvent<{
|
|
9
|
+
value: {
|
|
10
|
+
index: number;
|
|
11
|
+
item: TItem;
|
|
12
|
+
path: string;
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Fired before exiting the cell edit mode, if the value has been changed.
|
|
18
|
+
*/
|
|
19
|
+
export type GridProItemPropertyChangedEvent<TItem> = CustomEvent<{
|
|
20
|
+
value: {
|
|
21
|
+
index: number;
|
|
22
|
+
item: TItem;
|
|
23
|
+
path: string;
|
|
24
|
+
value: string | boolean;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
|
27
|
+
|
|
28
|
+
export interface GridProCustomEventMap<TItem> {
|
|
29
|
+
'cell-edit-started': GridProCellEditStartedEvent<TItem>;
|
|
30
|
+
|
|
31
|
+
'item-property-changed': GridProItemPropertyChangedEvent<TItem>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface GridProEventMap<TItem>
|
|
35
|
+
extends HTMLElementEventMap,
|
|
36
|
+
GridProCustomEventMap<TItem>,
|
|
37
|
+
GridCustomEventMap<TItem> {}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* `<vaadin-grid-pro>` is a high quality data grid / data table Web Component with extended functionality.
|
|
41
|
+
* It extends `<vaadin-grid>` and adds extra features on top of the basic ones.
|
|
42
|
+
*
|
|
43
|
+
* See [`<vaadin-grid>`](#/elements/vaadin-grid) documentation for details.
|
|
44
|
+
*
|
|
45
|
+
* ```
|
|
46
|
+
* <vaadin-grid-pro></vaadin-grid-pro>
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* ### Internal components
|
|
50
|
+
*
|
|
51
|
+
* In addition to `<vaadin-grid-pro>` itself, the following internal
|
|
52
|
+
* components are themable:
|
|
53
|
+
*
|
|
54
|
+
* - `<vaadin-grid-pro-edit-checkbox>` - has the same API as [`<vaadin-checkbox>`](#/elements/vaadin-checkbox).
|
|
55
|
+
* - `<vaadin-grid-pro-edit-text-field>` - has the same API as [`<vaadin-text-field>`](#/elements/vaadin-text-field).
|
|
56
|
+
* - `<vaadin-grid-pro-edit-select>` - has the same API as [`<vaadin-select>`](#/elements/vaadin-select).
|
|
57
|
+
*
|
|
58
|
+
* @fires {CustomEvent} active-item-changed - Fired when the `activeItem` property changes.
|
|
59
|
+
* @fires {CustomEvent} cell-activate - Fired when the cell is activated with click or keyboard.
|
|
60
|
+
* @fires {CustomEvent} cell-edit-started - Fired when the user starts editing a grid cell.
|
|
61
|
+
* @fires {CustomEvent} column-reorder - Fired when the columns in the grid are reordered.
|
|
62
|
+
* @fires {CustomEvent} column-resize - Fired when the grid column resize is finished.
|
|
63
|
+
* @fires {CustomEvent} expanded-items-changed - Fired when the `expandedItems` property changes.
|
|
64
|
+
* @fires {CustomEvent} grid-dragstart - Fired when starting to drag grid rows.
|
|
65
|
+
* @fires {CustomEvent} grid-dragend - Fired when the dragging of the rows ends.
|
|
66
|
+
* @fires {CustomEvent} grid-drop - Fired when a drop occurs on top of the grid.
|
|
67
|
+
* @fires {CustomEvent} item-property-changed - Fired before exiting the cell edit mode, if the value has been changed.
|
|
68
|
+
* @fires {CustomEvent} loading-changed - Fired when the `loading` property changes.
|
|
69
|
+
* @fires {CustomEvent} selected-items-changed - Fired when the `selectedItems` property changes.
|
|
70
|
+
*/
|
|
71
|
+
declare class GridPro<TItem = GridDefaultItem> extends Grid<TItem> {
|
|
72
|
+
static _finalizeClass(): void;
|
|
73
|
+
|
|
74
|
+
addEventListener<K extends keyof GridProEventMap<TItem>>(
|
|
75
|
+
type: K,
|
|
76
|
+
listener: (this: GridPro<TItem>, ev: GridProEventMap<TItem>[K]) => void,
|
|
77
|
+
options?: boolean | AddEventListenerOptions
|
|
78
|
+
): void;
|
|
79
|
+
|
|
80
|
+
removeEventListener<K extends keyof GridProEventMap<TItem>>(
|
|
81
|
+
type: K,
|
|
82
|
+
listener: (this: GridPro<TItem>, ev: GridProEventMap<TItem>[K]) => void,
|
|
83
|
+
options?: boolean | EventListenerOptions
|
|
84
|
+
): void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface GridPro extends InlineEditingMixin {}
|
|
88
|
+
|
|
89
|
+
declare global {
|
|
90
|
+
interface HTMLElementTagNameMap {
|
|
91
|
+
'vaadin-grid-pro': GridPro<GridDefaultItem>;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { GridPro };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2019 - 2021 Vaadin Ltd.
|
|
4
|
+
* This program is available under Commercial Vaadin Developer License 4.0 (CVDLv4).
|
|
5
|
+
* See <a href="https://vaadin.com/license/cvdl-4.0">the website</a> for the complete license.
|
|
6
|
+
*/
|
|
7
|
+
import { Grid } from '@vaadin/grid/src/vaadin-grid.js';
|
|
8
|
+
import { InlineEditingMixin } from './vaadin-grid-pro-inline-editing-mixin.js';
|
|
9
|
+
import '@vaadin/vaadin-license-checker/vaadin-license-checker.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* `<vaadin-grid-pro>` is a high quality data grid / data table Web Component with extended functionality.
|
|
14
|
+
* It extends `<vaadin-grid>` and adds extra features on top of the basic ones.
|
|
15
|
+
*
|
|
16
|
+
* See [`<vaadin-grid>`](#/elements/vaadin-grid) documentation for details.
|
|
17
|
+
*
|
|
18
|
+
* ```
|
|
19
|
+
* <vaadin-grid-pro></vaadin-grid-pro>
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* ### Internal components
|
|
23
|
+
*
|
|
24
|
+
* In addition to `<vaadin-grid-pro>` itself, the following internal
|
|
25
|
+
* components are themable:
|
|
26
|
+
*
|
|
27
|
+
* - `<vaadin-grid-pro-edit-checkbox>` - has the same API as [`<vaadin-checkbox>`](#/elements/vaadin-checkbox).
|
|
28
|
+
* - `<vaadin-grid-pro-edit-text-field>` - has the same API as [`<vaadin-text-field>`](#/elements/vaadin-text-field).
|
|
29
|
+
* - `<vaadin-grid-pro-edit-select>` - has the same API as [`<vaadin-select>`](#/elements/vaadin-select).
|
|
30
|
+
*
|
|
31
|
+
* @fires {CustomEvent} active-item-changed - Fired when the `activeItem` property changes.
|
|
32
|
+
* @fires {CustomEvent} cell-activate - Fired when the cell is activated with click or keyboard.
|
|
33
|
+
* @fires {CustomEvent} cell-edit-started - Fired when the user starts editing a grid cell.
|
|
34
|
+
* @fires {CustomEvent} column-reorder - Fired when the columns in the grid are reordered.
|
|
35
|
+
* @fires {CustomEvent} column-resize - Fired when the grid column resize is finished.
|
|
36
|
+
* @fires {CustomEvent} expanded-items-changed - Fired when the `expandedItems` property changes.
|
|
37
|
+
* @fires {CustomEvent} grid-dragstart - Fired when starting to drag grid rows.
|
|
38
|
+
* @fires {CustomEvent} grid-dragend - Fired when the dragging of the rows ends.
|
|
39
|
+
* @fires {CustomEvent} grid-drop - Fired when a drop occurs on top of the grid.
|
|
40
|
+
* @fires {CustomEvent} item-property-changed - Fired before exiting the cell edit mode, if the value has been changed.
|
|
41
|
+
* @fires {CustomEvent} loading-changed - Fired when the `loading` property changes.
|
|
42
|
+
* @fires {CustomEvent} selected-items-changed - Fired when the `selectedItems` property changes.
|
|
43
|
+
*
|
|
44
|
+
* @extends Grid
|
|
45
|
+
* @mixes InlineEditingMixin
|
|
46
|
+
*/
|
|
47
|
+
class GridPro extends InlineEditingMixin(Grid) {
|
|
48
|
+
static get is() {
|
|
49
|
+
return 'vaadin-grid-pro';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @protected
|
|
54
|
+
*/
|
|
55
|
+
static _finalizeClass() {
|
|
56
|
+
super._finalizeClass();
|
|
57
|
+
|
|
58
|
+
const devModeCallback = window.Vaadin.developmentModeCallback;
|
|
59
|
+
const licenseChecker = devModeCallback && devModeCallback['vaadin-license-checker'];
|
|
60
|
+
if (typeof licenseChecker === 'function') {
|
|
61
|
+
licenseChecker(GridPro);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
customElements.define(GridPro.is, GridPro);
|
|
67
|
+
|
|
68
|
+
export { GridPro };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
|
|
2
|
+
import '@vaadin/vaadin-lumo-styles/spacing.js';
|
|
3
|
+
import '@vaadin/vaadin-lumo-styles/typography.js';
|
|
4
|
+
import { gridProEditor } from './vaadin-grid-pro-editor-styles.js';
|
|
5
|
+
|
|
6
|
+
const gridProEditSelect = css`
|
|
7
|
+
:host([theme~='grid-pro-editor']) [part='toggle-button'] {
|
|
8
|
+
margin-right: var(--lumo-space-xs);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
:host([theme~='grid-pro-editor']) [part='input-field'] ::slotted([slot='value']) {
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
padding: 0 var(--lumo-space-m);
|
|
14
|
+
font-size: var(--lumo-font-size-m);
|
|
15
|
+
/* prevent selection on editor focus */
|
|
16
|
+
-webkit-user-select: none;
|
|
17
|
+
-moz-user-select: none;
|
|
18
|
+
user-select: none;
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
registerStyles('vaadin-grid-pro-edit-select', [gridProEditor, gridProEditSelect], {
|
|
23
|
+
moduleId: 'lumo-grid-pro-edit-select'
|
|
24
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { registerStyles } from '@vaadin/vaadin-themable-mixin/register-styles.js';
|
|
2
|
+
import { gridProEditor } from './vaadin-grid-pro-editor-styles.js';
|
|
3
|
+
|
|
4
|
+
registerStyles('vaadin-grid-pro-edit-text-field', gridProEditor, {
|
|
5
|
+
moduleId: 'lumo-grid-pro-edit-text-field'
|
|
6
|
+
});
|