@vaadin/vaadin-grid-pro 22.0.0-alpha5 → 22.0.0-alpha9

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