@shortfuse/materialdesignweb 0.4.0 → 0.5.0
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/.browserslistrc +2 -1
- package/.eslintrc.json +59 -8
- package/.stylelintrc.json +94 -49
- package/CHANGELOG.md +12 -0
- package/README.md +1 -3
- package/adapters/datatable/column.js +27 -54
- package/adapters/datatable/index.js +69 -81
- package/adapters/dom/index.js +32 -47
- package/adapters/search/index.js +107 -133
- package/components/appbar/_spec.scss +77 -137
- package/components/banner/_spec.scss +28 -63
- package/components/bottomnav/_spec.scss +46 -54
- package/components/bottomnav/index.js +15 -20
- package/components/bottomnav/item.js +4 -5
- package/components/button/README.md +1 -1
- package/components/button/_spec.scss +43 -42
- package/components/button/_theme.scss +27 -50
- package/components/card/_spec.scss +61 -69
- package/components/chip/_spec.scss +21 -44
- package/components/chip/_theme.scss +79 -151
- package/components/chip/index.js +6 -4
- package/components/datatable/_spec.scss +36 -99
- package/components/datatable/_theme.scss +98 -124
- package/components/datatable/cell.js +1 -2
- package/components/datatable/columnheader.js +1 -2
- package/components/datatable/index.js +33 -47
- package/components/datatable/row.js +4 -5
- package/components/dialog/_spec.scss +53 -63
- package/components/dialog/_theme.scss +7 -0
- package/components/dialog/index.js +62 -88
- package/components/divider/_spec.scss +6 -8
- package/components/elevation/_spec.scss +1 -1
- package/components/fab/_spec.scss +30 -42
- package/components/fab/index.js +4 -8
- package/components/grid/_spec.scss +68 -211
- package/components/layout/_mixins.scss +0 -22
- package/components/layout/_spec.scss +267 -363
- package/components/layout/_theme.scss +10 -35
- package/components/layout/index.js +40 -50
- package/components/list/_spec.scss +57 -91
- package/components/list/_theme.scss +75 -84
- package/components/list/content.js +9 -13
- package/components/list/index.js +34 -38
- package/components/list/item.js +8 -11
- package/components/list/secondary.js +8 -9
- package/components/menu/_spec.scss +134 -167
- package/components/menu/index.js +45 -61
- package/components/menu/item.js +11 -19
- package/components/progress/_spec.scss +43 -34
- package/components/selection/_spec.scss +123 -133
- package/components/selection/_theme.scss +88 -120
- package/components/selection/index.js +9 -15
- package/components/selection/input.js +3 -5
- package/components/selection/radiogroup.js +8 -15
- package/components/slider/_spec.scss +23 -28
- package/components/snackbar/_spec.scss +17 -62
- package/components/snackbar/index.js +15 -21
- package/components/tab/_spec.scss +35 -50
- package/components/tab/content.js +33 -28
- package/components/tab/index.js +30 -33
- package/components/tab/item.js +4 -5
- package/components/tab/list.js +22 -36
- package/components/textfield/README.md +2 -2
- package/components/textfield/_spec.scss +241 -287
- package/components/textfield/_theme.scss +197 -232
- package/components/textfield/index.js +8 -16
- package/components/tooltip/_spec.scss +23 -26
- package/components/type/_spec.scss +19 -16
- package/core/_breakpoint.scss +33 -33
- package/core/_elevation.scss +40 -0
- package/core/_length.scss +0 -1
- package/core/_platform.scss +0 -22
- package/core/_type.scss +7 -6
- package/core/aria/button.js +4 -5
- package/core/aria/keyboard.js +1 -2
- package/core/aria/rovingtabindex.js +14 -17
- package/core/aria/tab.js +1 -2
- package/core/dom.js +18 -109
- package/core/overlay/_spec.scss +5 -8
- package/core/overlay/_theme.scss +126 -150
- package/core/overlay/index.js +19 -32
- package/core/ripple/_spec.scss +16 -17
- package/core/ripple/_theme.scss +13 -33
- package/core/ripple/index.js +36 -44
- package/core/theme/_aliases.scss +15 -0
- package/core/theme/_config.scss +8 -2
- package/core/theme/_functions.scss +22 -0
- package/core/theme/_palettes.scss +0 -1
- package/core/{color → theme}/_spec.scss +0 -0
- package/core/theme/_theme.scss +268 -0
- package/core/theme/index.scss +4 -0
- package/core/transition/index.js +73 -76
- package/docs/_flex.scss +7 -1
- package/docs/_menuoptions.js +2 -2
- package/docs/_partials/_appbar.eta +12 -14
- package/docs/_partials/_header.eta +41 -44
- package/docs/_sample-utils.js +15 -20
- package/docs/docs.scss +123 -87
- package/docs/framework.scss +26 -0
- package/docs/index.eta +2 -6
- package/docs/index.js +7 -0
- package/docs/pages/appbar.eta +22 -28
- package/docs/pages/bottomnav.js +17 -14
- package/docs/pages/button.js +10 -10
- package/docs/pages/card.js +20 -22
- package/docs/pages/chip.js +11 -13
- package/docs/pages/color.js +35 -36
- package/docs/pages/datatable.js +11 -15
- package/docs/pages/dialog.eta +9 -11
- package/docs/pages/dialog.js +6 -9
- package/docs/pages/dom.js +6 -9
- package/docs/pages/elevation.eta +10 -10
- package/docs/pages/fab.js +2 -3
- package/docs/pages/grid.js +5 -5
- package/docs/pages/list.js +1 -2
- package/docs/pages/menu.eta +17 -19
- package/docs/pages/menu.js +7 -11
- package/docs/pages/overlay.js +1 -2
- package/docs/pages/progress.eta +2 -2
- package/docs/pages/progress.js +1 -1
- package/docs/pages/ripple.js +1 -2
- package/docs/pages/search.eta +20 -24
- package/docs/pages/search.js +24 -41
- package/docs/pages/selection.eta +2 -6
- package/docs/pages/selection.js +3 -4
- package/docs/pages/snackbar.js +3 -4
- package/docs/pages/tab.eta +61 -75
- package/docs/pages/tab.js +16 -15
- package/docs/pages/textfield.eta +9 -8
- package/docs/pages/textfield.js +26 -23
- package/docs/pages/tooltip.eta +10 -12
- package/docs/pages/transition.js +5 -7
- package/docs/postrender.js +7 -5
- package/docs/pwa/pwa.eta +14 -16
- package/docs/pwa/pwa.js +19 -27
- package/docs/pwa/pwa.scss +12 -7
- package/docs/themes/theme-colored.scss +9 -11
- package/docs/themes/theme-default.scss +0 -14
- package/index.scss +27 -0
- package/jsconfig.json +7 -3
- package/package.json +26 -15
- package/tsconfig.json +16 -0
- package/{webpack.config.cjs → webpack.config.js} +105 -58
- package/components/template/_theme.scss +0 -27
- package/components/textfield/_mixins.scss +0 -52
- package/core/color/_theme.scss +0 -390
- package/core/color/index.scss +0 -2
- package/core/theme/_mixins.scss +0 -172
- package/core/theme/_variables.scss +0 -24
- package/docs/_mixins.pug +0 -155
- package/docs/pages/appbar.pug +0 -78
- package/docs/pages/bottomnav.pug +0 -137
- package/docs/pages/button.pug +0 -121
- package/docs/pages/card.pug +0 -74
- package/docs/pages/chip.pug +0 -91
- package/docs/pages/color.pug +0 -121
- package/docs/pages/datatable.pug +0 -283
- package/docs/pages/dialog.pug +0 -132
- package/docs/pages/dom.pug +0 -22
- package/docs/pages/elevation.pug +0 -25
- package/docs/pages/fab.pug +0 -66
- package/docs/pages/grid.pug +0 -95
- package/docs/pages/layout.pug +0 -7
- package/docs/pages/list.pug +0 -326
- package/docs/pages/menu.pug +0 -205
- package/docs/pages/overlay.pug +0 -55
- package/docs/pages/progress.pug +0 -16
- package/docs/pages/ripple.pug +0 -21
- package/docs/pages/search.pug +0 -165
- package/docs/pages/selection.pug +0 -74
- package/docs/pages/slider.pug +0 -17
- package/docs/pages/snackbar.pug +0 -60
- package/docs/pages/tab.pug +0 -304
- package/docs/pages/textfield.pug +0 -360
- package/docs/pages/tooltip.pug +0 -78
- package/docs/pages/transition.pug +0 -76
- package/docs/pages/type.pug +0 -29
- package/docs/pwa/_dialogs.pug +0 -96
- package/docs/pwa/_menus.pug +0 -11
- package/docs/pwa/pwa.pug +0 -325
- package/docs/spec.scss +0 -26
- package/docs/themes/_component-themes.scss +0 -26
- package/docs/themes/theme-colored-fallbacks.scss +0 -17
- package/docs/themes/theme-default-fallbacks.scss +0 -17
|
@@ -6,14 +6,12 @@ import * as DataTableRow from '../../components/datatable/row.js';
|
|
|
6
6
|
import * as DataTableRowHeader from '../../components/datatable/rowheader.js';
|
|
7
7
|
import * as Selection from '../../components/selection/index.js';
|
|
8
8
|
import * as RovingTabIndex from '../../core/aria/rovingtabindex.js';
|
|
9
|
-
import { getPassiveEventListenerOption, iterateArrayLike, iterateSomeOfArrayLike } from '../../core/dom.js';
|
|
10
|
-
import { noop } from '../../utils/function.js';
|
|
11
9
|
|
|
12
10
|
import DataTableAdapterColumn from './column.js';
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* @template {Record<string, any>} T
|
|
16
|
-
* @template {keyof T & string} K
|
|
14
|
+
* @template {(keyof T & string)|string} K
|
|
17
15
|
* @typedef {import('./column').DataTableAdapterColumnOptions<T,K>} DataTableAdapterColumnOptions<T,K>
|
|
18
16
|
*/
|
|
19
17
|
|
|
@@ -77,8 +75,8 @@ export default class DataTableAdapter {
|
|
|
77
75
|
this.datasource = options.datasource;
|
|
78
76
|
this.filter = options.filter;
|
|
79
77
|
this.sorter = options.sorter;
|
|
80
|
-
this.onValueChangeRequested = options.onValueChangeRequested
|
|
81
|
-
this.onValueChanged = options.onValueChanged
|
|
78
|
+
this.onValueChangeRequested = options.onValueChangeRequested;
|
|
79
|
+
this.onValueChanged = options.onValueChanged;
|
|
82
80
|
DataTable.attach(this.element);
|
|
83
81
|
|
|
84
82
|
this.onElementScrollListener = () => this.onElementScroll();
|
|
@@ -107,6 +105,8 @@ export default class DataTableAdapter {
|
|
|
107
105
|
DataTableAdapter.onRowSelectedChangeEvent,
|
|
108
106
|
);
|
|
109
107
|
|
|
108
|
+
/** @type {HTMLTableSectionElement} */
|
|
109
|
+
this.tbody = null;
|
|
110
110
|
this.scroller = DataTable.getScroller(this.element);
|
|
111
111
|
this.element.setAttribute('mdw-datatable-adapter', '');
|
|
112
112
|
/** @type {DataTableAdapterColumn<T,any>[]} */
|
|
@@ -123,8 +123,7 @@ export default class DataTableAdapter {
|
|
|
123
123
|
* @return {void}
|
|
124
124
|
*/
|
|
125
125
|
onDataTableColumnHeaderSort(event) {
|
|
126
|
-
/** @type {HTMLTableHeaderCellElement} */
|
|
127
|
-
const cell = (event.target);
|
|
126
|
+
const cell = /** @type {HTMLTableHeaderCellElement} */ (event.target);
|
|
128
127
|
const ascending = event.detail.sort === 'ascending';
|
|
129
128
|
this.updateSortIcons(cell, ascending);
|
|
130
129
|
if (this.updateSortColumn) {
|
|
@@ -168,8 +167,7 @@ export default class DataTableAdapter {
|
|
|
168
167
|
* @return {void}
|
|
169
168
|
*/
|
|
170
169
|
static onRowSelectedChangeEvent(event) {
|
|
171
|
-
/** @type {HTMLTableRowElement} */
|
|
172
|
-
const row = (event.target);
|
|
170
|
+
const row = /** @type {HTMLTableRowElement} */ (event.target);
|
|
173
171
|
const selectionElement = row.querySelector('[mdw-selector] .mdw-selection[aria-checked]');
|
|
174
172
|
if (!selectionElement) {
|
|
175
173
|
return;
|
|
@@ -198,7 +196,7 @@ export default class DataTableAdapter {
|
|
|
198
196
|
}
|
|
199
197
|
|
|
200
198
|
buildScrollListener() {
|
|
201
|
-
this.scroller.addEventListener('scroll', this.onElementScrollListener,
|
|
199
|
+
this.scroller.addEventListener('scroll', this.onElementScrollListener, { passive: true });
|
|
202
200
|
}
|
|
203
201
|
|
|
204
202
|
destroyScrollListener() {
|
|
@@ -210,8 +208,7 @@ export default class DataTableAdapter {
|
|
|
210
208
|
* @return {void}
|
|
211
209
|
*/
|
|
212
210
|
onCheckedChangeEvent(event) {
|
|
213
|
-
/** @type {HTMLElement} */
|
|
214
|
-
const selectionElement = (event.target);
|
|
211
|
+
const selectionElement = /** @type {HTMLElement} */ (event.target);
|
|
215
212
|
const checked = event.detail.value === 'true';
|
|
216
213
|
const currentCell = this.getTableCell(selectionElement);
|
|
217
214
|
if (currentCell.getAttribute('role') === 'columnheader') {
|
|
@@ -221,15 +218,14 @@ export default class DataTableAdapter {
|
|
|
221
218
|
}
|
|
222
219
|
const currentRow = this.getTableRow(selectionElement);
|
|
223
220
|
const object = this.getDataForTableRow(currentRow);
|
|
224
|
-
/** @type {keyof T & string} */
|
|
225
221
|
// eslint-disable-next-line prefer-destructuring
|
|
226
|
-
const key = (currentCell.dataset.key);
|
|
227
|
-
if (this.onValueChangeRequested(object, key, checked)) {
|
|
222
|
+
const key = /** @type {keyof T & string} */ (currentCell.dataset.key);
|
|
223
|
+
if (this.onValueChangeRequested?.(object, key, checked)) {
|
|
228
224
|
event.preventDefault();
|
|
229
225
|
return;
|
|
230
226
|
}
|
|
231
227
|
object[key] = checked;
|
|
232
|
-
this.onValueChanged(object, key, checked);
|
|
228
|
+
this.onValueChanged?.(object, key, checked);
|
|
233
229
|
if (currentCell.hasAttribute('mdw-selector')) {
|
|
234
230
|
DataTableRow.setSelected(currentRow, event.detail.value, true);
|
|
235
231
|
}
|
|
@@ -270,7 +266,7 @@ export default class DataTableAdapter {
|
|
|
270
266
|
return direction;
|
|
271
267
|
}
|
|
272
268
|
if (tableColumn.type === 'number') {
|
|
273
|
-
return (parseFloat(valueA) - parseFloat(valueB)) * direction;
|
|
269
|
+
return (Number.parseFloat(valueA) - Number.parseFloat(valueB)) * direction;
|
|
274
270
|
}
|
|
275
271
|
if (tableColumn.type === 'checkbox') {
|
|
276
272
|
return ((valueA ? 1 : 0) - (valueB ? 1 : 0)) * direction;
|
|
@@ -300,11 +296,11 @@ export default class DataTableAdapter {
|
|
|
300
296
|
sortedTableHeaderCell.setAttribute('aria-sort', 'descending');
|
|
301
297
|
}
|
|
302
298
|
}
|
|
303
|
-
|
|
299
|
+
for (const otherTableHeader of this.getHeaderRow().getElementsByTagName('th')) {
|
|
304
300
|
if (otherTableHeader !== sortedTableHeaderCell && otherTableHeader.hasAttribute('aria-sort')) {
|
|
305
301
|
otherTableHeader.setAttribute('aria-sort', 'none');
|
|
306
302
|
}
|
|
307
|
-
}
|
|
303
|
+
}
|
|
308
304
|
}
|
|
309
305
|
|
|
310
306
|
/**
|
|
@@ -314,9 +310,9 @@ export default class DataTableAdapter {
|
|
|
314
310
|
*/
|
|
315
311
|
setCheckOnAllRows(value, columnIndex) {
|
|
316
312
|
const column = this.columns[columnIndex];
|
|
317
|
-
this.datasource
|
|
318
|
-
object[column.key] = value;
|
|
319
|
-
}
|
|
313
|
+
for (const object of this.datasource) {
|
|
314
|
+
object[column.key] = value;
|
|
315
|
+
}
|
|
320
316
|
this.refresh();
|
|
321
317
|
}
|
|
322
318
|
|
|
@@ -356,7 +352,7 @@ export default class DataTableAdapter {
|
|
|
356
352
|
|
|
357
353
|
/** @return {T[]} */
|
|
358
354
|
getSelectedRows() {
|
|
359
|
-
const selectorColumn = this.columns.
|
|
355
|
+
const selectorColumn = this.columns.find((column) => column.rowSelector);
|
|
360
356
|
if (!selectorColumn) {
|
|
361
357
|
return [];
|
|
362
358
|
}
|
|
@@ -398,7 +394,7 @@ export default class DataTableAdapter {
|
|
|
398
394
|
}
|
|
399
395
|
|
|
400
396
|
/**
|
|
401
|
-
* @template {keyof T & string} K
|
|
397
|
+
* @template {(keyof T & string)|string} K
|
|
402
398
|
* @param {DataTableAdapterColumnOptions<T,K>} options
|
|
403
399
|
* @return {DataTableAdapterColumn<T,K>}
|
|
404
400
|
*/
|
|
@@ -456,14 +452,14 @@ export default class DataTableAdapter {
|
|
|
456
452
|
limitsElement.setAttribute('mdw-solo', '');
|
|
457
453
|
const select = document.createElement('select');
|
|
458
454
|
select.classList.add('mdw-textfield__input');
|
|
459
|
-
|
|
455
|
+
for (const limit of limits) {
|
|
460
456
|
const option = document.createElement('option');
|
|
461
457
|
option.value = limit.toString();
|
|
462
458
|
option.textContent = limit.toString();
|
|
463
459
|
option.className = 'mdw-theme';
|
|
464
460
|
option.setAttribute('mdw-surface', 'card');
|
|
465
461
|
select.appendChild(option);
|
|
466
|
-
}
|
|
462
|
+
}
|
|
467
463
|
select.value = (options.limit && options.limit.toString()) || '10';
|
|
468
464
|
const dropdownIcon = document.createElement('div');
|
|
469
465
|
dropdownIcon.classList.add('mdw-textfield__icon');
|
|
@@ -474,23 +470,23 @@ export default class DataTableAdapter {
|
|
|
474
470
|
optionsElement.appendChild(limitsElement);
|
|
475
471
|
footer.appendChild(optionsElement);
|
|
476
472
|
select.addEventListener('input', () => {
|
|
477
|
-
this.pageLimit = parseInt(select.value, 10);
|
|
473
|
+
this.pageLimit = Number.parseInt(select.value, 10);
|
|
478
474
|
this.updateRowCount(false);
|
|
479
475
|
this.updatePaginator();
|
|
480
476
|
this.refreshRows();
|
|
481
477
|
});
|
|
482
478
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
479
|
+
|
|
480
|
+
this.paginationDetailsElement ||= /** @type {HTMLDivElement} */ (footer.getElementsByClassName('mdw-datatable__footer-details')[0]);
|
|
481
|
+
|
|
486
482
|
if (!this.paginationDetailsElement) {
|
|
487
483
|
this.paginationDetailsElement = document.createElement('div');
|
|
488
484
|
this.paginationDetailsElement.classList.add('mdw-datatable__footer-details');
|
|
489
485
|
footer.appendChild(this.paginationDetailsElement);
|
|
490
486
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
487
|
+
|
|
488
|
+
this.paginationControls ||= /** @type {HTMLDivElement} */ (footer.getElementsByClassName('mdw-datatable__footer-controls')[0]);
|
|
489
|
+
|
|
494
490
|
if (!this.paginationControls) {
|
|
495
491
|
this.paginationControls = document.createElement('div');
|
|
496
492
|
this.paginationControls.classList.add('mdw-datatable__footer-controls');
|
|
@@ -548,8 +544,7 @@ export default class DataTableAdapter {
|
|
|
548
544
|
* @return {HTMLElement}
|
|
549
545
|
*/
|
|
550
546
|
getFooter(create) {
|
|
551
|
-
/** @type {HTMLElement} */
|
|
552
|
-
let footer = (this.element.getElementsByClassName('mdw-datatable__footer')[0]);
|
|
547
|
+
let footer = /** @type {HTMLElement} */ (this.element.getElementsByClassName('mdw-datatable__footer')[0]);
|
|
553
548
|
if (!footer && create) {
|
|
554
549
|
footer = document.createElement('div');
|
|
555
550
|
footer.classList.add('mdw-datatable__footer');
|
|
@@ -591,15 +586,16 @@ export default class DataTableAdapter {
|
|
|
591
586
|
if (visibleRows.length === tbody.rows.length) {
|
|
592
587
|
return;
|
|
593
588
|
}
|
|
594
|
-
let firstRowIndex =
|
|
595
|
-
let lastRowIndex =
|
|
589
|
+
let firstRowIndex = Number.POSITIVE_INFINITY;
|
|
590
|
+
let lastRowIndex = Number.NEGATIVE_INFINITY;
|
|
596
591
|
if (visibleRows.length) {
|
|
597
592
|
firstRowIndex = visibleRows[0].sectionRowIndex;
|
|
598
593
|
lastRowIndex = visibleRows[visibleRows.length - 1].sectionRowIndex;
|
|
599
594
|
}
|
|
600
|
-
|
|
595
|
+
for (let index = 0; index < tbody.rows.length; index++) {
|
|
596
|
+
const row = tbody.rows[index];
|
|
601
597
|
if (index >= firstRowIndex && index <= lastRowIndex) {
|
|
602
|
-
|
|
598
|
+
continue;
|
|
603
599
|
}
|
|
604
600
|
if (row.lastChild) {
|
|
605
601
|
// Store row height to prevent layout shifting
|
|
@@ -608,7 +604,7 @@ export default class DataTableAdapter {
|
|
|
608
604
|
while (row.lastChild) {
|
|
609
605
|
row.removeChild(row.lastChild);
|
|
610
606
|
}
|
|
611
|
-
}
|
|
607
|
+
}
|
|
612
608
|
}
|
|
613
609
|
|
|
614
610
|
/**
|
|
@@ -621,9 +617,9 @@ export default class DataTableAdapter {
|
|
|
621
617
|
const rows = [];
|
|
622
618
|
const minRowCount = window.screen.height / 48;
|
|
623
619
|
if (len <= minRowCount) {
|
|
624
|
-
|
|
620
|
+
for (const row of tbody.rows) {
|
|
625
621
|
rows.push(row);
|
|
626
|
-
}
|
|
622
|
+
}
|
|
627
623
|
return rows;
|
|
628
624
|
}
|
|
629
625
|
let foundFirstVisibleRow = false;
|
|
@@ -631,18 +627,19 @@ export default class DataTableAdapter {
|
|
|
631
627
|
let endIndex = 0;
|
|
632
628
|
const viewportTop = this.scroller.scrollTop;
|
|
633
629
|
const viewportBottom = viewportTop + this.scroller.offsetHeight;
|
|
634
|
-
|
|
630
|
+
|
|
631
|
+
for (let i = 0; i < tbody.rows.length; i++) {
|
|
632
|
+
const row = tbody.rows.item(i);
|
|
635
633
|
if (this.isRowVisible(row, viewportTop, viewportBottom)) {
|
|
636
634
|
if (!foundFirstVisibleRow) {
|
|
637
635
|
foundFirstVisibleRow = true;
|
|
638
|
-
startIndex =
|
|
636
|
+
startIndex = i;
|
|
639
637
|
}
|
|
640
|
-
endIndex =
|
|
638
|
+
endIndex = i;
|
|
641
639
|
} else if (foundFirstVisibleRow) {
|
|
642
|
-
|
|
640
|
+
break;
|
|
643
641
|
}
|
|
644
|
-
|
|
645
|
-
});
|
|
642
|
+
}
|
|
646
643
|
|
|
647
644
|
while ((endIndex - startIndex) + 1 < minRowCount) {
|
|
648
645
|
if (startIndex === 0) {
|
|
@@ -667,11 +664,11 @@ export default class DataTableAdapter {
|
|
|
667
664
|
*/
|
|
668
665
|
performLazyRender(forceRefresh = false) {
|
|
669
666
|
const visibleRows = this.getLazyRenderRows();
|
|
670
|
-
|
|
667
|
+
for (const row of visibleRows) {
|
|
671
668
|
if (forceRefresh || !row.cells.length) {
|
|
672
669
|
this.refreshRow(row.sectionRowIndex);
|
|
673
670
|
}
|
|
674
|
-
}
|
|
671
|
+
}
|
|
675
672
|
this.clearNonvisibleRows(visibleRows);
|
|
676
673
|
}
|
|
677
674
|
|
|
@@ -771,9 +768,9 @@ export default class DataTableAdapter {
|
|
|
771
768
|
if (this.useLazyRendering) {
|
|
772
769
|
this.scheduleThrottledRender(true);
|
|
773
770
|
} else {
|
|
774
|
-
|
|
771
|
+
for (const row of newRows) {
|
|
775
772
|
this.refreshRow(row.sectionRowIndex);
|
|
776
|
-
}
|
|
773
|
+
}
|
|
777
774
|
}
|
|
778
775
|
}
|
|
779
776
|
}
|
|
@@ -784,9 +781,9 @@ export default class DataTableAdapter {
|
|
|
784
781
|
this.performLazyRender(true);
|
|
785
782
|
} else {
|
|
786
783
|
const tbody = this.getTableBody();
|
|
787
|
-
|
|
788
|
-
this.refreshRow(
|
|
789
|
-
}
|
|
784
|
+
for (let i = 0; i < tbody.rows.length; i++) {
|
|
785
|
+
this.refreshRow(i);
|
|
786
|
+
}
|
|
790
787
|
}
|
|
791
788
|
if (this.useLazyRendering) {
|
|
792
789
|
this.scheduleThrottledRender();
|
|
@@ -830,9 +827,9 @@ export default class DataTableAdapter {
|
|
|
830
827
|
refreshRow(rowIndex) {
|
|
831
828
|
const row = this.getTableBody().rows.item(rowIndex);
|
|
832
829
|
row.style.removeProperty('height');
|
|
833
|
-
this.columns.
|
|
834
|
-
this.refreshCell(
|
|
835
|
-
}
|
|
830
|
+
for (let i = 0; i < this.columns.length; i++) {
|
|
831
|
+
this.refreshCell(i, rowIndex);
|
|
832
|
+
}
|
|
836
833
|
}
|
|
837
834
|
|
|
838
835
|
/**
|
|
@@ -843,6 +840,7 @@ export default class DataTableAdapter {
|
|
|
843
840
|
refreshCell(columnIndex, rowIndex) {
|
|
844
841
|
const tableColumn = this.columns[columnIndex];
|
|
845
842
|
const row = this.getTableBody().rows.item(rowIndex);
|
|
843
|
+
if (!row) return;
|
|
846
844
|
let len = row.cells.length;
|
|
847
845
|
let createdCells = false;
|
|
848
846
|
while (len <= columnIndex) {
|
|
@@ -879,18 +877,14 @@ export default class DataTableAdapter {
|
|
|
879
877
|
}
|
|
880
878
|
len += 1;
|
|
881
879
|
}
|
|
882
|
-
if (createdCells) {
|
|
883
|
-
|
|
884
|
-
RovingTabIndex.setupTabIndexes(row.querySelectorAll(DataTable.CELL_TABINDEX_QUERIES.join(',')));
|
|
885
|
-
}
|
|
880
|
+
if (createdCells && this.element.hasAttribute('mdw-cell-focusable')) {
|
|
881
|
+
RovingTabIndex.setupTabIndexes(row.querySelectorAll(DataTable.CELL_TABINDEX_QUERIES.join(',')));
|
|
886
882
|
}
|
|
887
883
|
const cell = row.cells.item(columnIndex);
|
|
888
884
|
const data = this.getDataForTableRow(row);
|
|
889
885
|
const value = data[tableColumn.key];
|
|
890
|
-
if (tableColumn.rowSelector) {
|
|
891
|
-
|
|
892
|
-
row.setAttribute('aria-selected', (value ? 'true' : 'false'));
|
|
893
|
-
}
|
|
886
|
+
if (tableColumn.rowSelector && row.getAttribute('aria-selected') !== (value ? 'true' : 'false')) {
|
|
887
|
+
row.setAttribute('aria-selected', (value ? 'true' : 'false'));
|
|
894
888
|
}
|
|
895
889
|
const formattedValue = tableColumn.formatter(value, data);
|
|
896
890
|
tableColumn.renderer(cell, formattedValue, data);
|
|
@@ -906,10 +900,10 @@ export default class DataTableAdapter {
|
|
|
906
900
|
return search;
|
|
907
901
|
}
|
|
908
902
|
if (search instanceof HTMLTableCellElement) {
|
|
909
|
-
return this.columns.
|
|
903
|
+
return this.columns.find((column) => column.element === search);
|
|
910
904
|
}
|
|
911
905
|
if (typeof search === 'string') {
|
|
912
|
-
return this.columns.
|
|
906
|
+
return this.columns.find((column) => column.element.dataset.key === search);
|
|
913
907
|
}
|
|
914
908
|
return this.columns[search];
|
|
915
909
|
}
|
|
@@ -947,16 +941,10 @@ export default class DataTableAdapter {
|
|
|
947
941
|
|
|
948
942
|
/** @return {HTMLTableSectionElement} */
|
|
949
943
|
getTableBody() {
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
if (!this.tbody) {
|
|
955
|
-
const table = this.getTable();
|
|
956
|
-
this.tbody = document.createElement('tbody');
|
|
957
|
-
table.appendChild(this.tbody);
|
|
958
|
-
}
|
|
959
|
-
return this.tbody;
|
|
944
|
+
// eslint-disable-next-line no-return-assign
|
|
945
|
+
return this.tbody
|
|
946
|
+
||= this.element.getElementsByTagName('tbody')[0]
|
|
947
|
+
|| this.getTable().appendChild(document.createElement('tbody'));
|
|
960
948
|
}
|
|
961
949
|
|
|
962
950
|
/**
|
|
@@ -965,8 +953,8 @@ export default class DataTableAdapter {
|
|
|
965
953
|
*/
|
|
966
954
|
refreshColumn(columnIndex) {
|
|
967
955
|
const tbody = this.getTableBody();
|
|
968
|
-
|
|
969
|
-
this.refreshCell(columnIndex,
|
|
970
|
-
}
|
|
956
|
+
for (let i = 0; i < tbody.rows.length; i++) {
|
|
957
|
+
this.refreshCell(columnIndex, i);
|
|
958
|
+
}
|
|
971
959
|
}
|
|
972
960
|
}
|
package/adapters/dom/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { getPassiveEventListenerOption } from '../../core/dom.js';
|
|
2
|
-
|
|
3
1
|
/** @return {HTMLElement} */
|
|
4
2
|
function AnyDomAdapterCreator() {
|
|
5
3
|
return document.createElement('div');
|
|
@@ -13,15 +11,9 @@ function AnyDomAdapterCreator() {
|
|
|
13
11
|
function AnyDomAdapterRenderer(element, data) {
|
|
14
12
|
let s = '';
|
|
15
13
|
if (data != null) {
|
|
16
|
-
|
|
17
|
-
s = data.toString();
|
|
18
|
-
} else {
|
|
19
|
-
// eslint-disable-next-line no-new-wrappers
|
|
20
|
-
s = new String(data).toString();
|
|
21
|
-
}
|
|
14
|
+
s = data.toString ? data.toString() : String(data).toString();
|
|
22
15
|
}
|
|
23
16
|
if (element.textContent !== s) {
|
|
24
|
-
// eslint-disable-next-line no-param-reassign
|
|
25
17
|
element.textContent = s;
|
|
26
18
|
}
|
|
27
19
|
}
|
|
@@ -86,7 +78,7 @@ export default class DomAdapter {
|
|
|
86
78
|
if (!this.recycle) {
|
|
87
79
|
return;
|
|
88
80
|
}
|
|
89
|
-
this.recycle.scroller.addEventListener('scroll', this.onScrollerScrollListener,
|
|
81
|
+
this.recycle.scroller.addEventListener('scroll', this.onScrollerScrollListener, { passive: true });
|
|
90
82
|
const scrollerStyle = window.getComputedStyle(this.recycle.scroller);
|
|
91
83
|
if (scrollerStyle.position === 'static') {
|
|
92
84
|
this.recycle.scroller.style.setProperty('position', 'relative');
|
|
@@ -116,25 +108,25 @@ export default class DomAdapter {
|
|
|
116
108
|
const unlinkedDataItems = [];
|
|
117
109
|
/** @type {T2[]} */
|
|
118
110
|
const orphanedElements = [];
|
|
119
|
-
this.dataElementMap.
|
|
120
|
-
if (this.datasource.
|
|
111
|
+
for (const data of this.dataElementMap.keys()) {
|
|
112
|
+
if (!this.datasource.includes(data)) {
|
|
121
113
|
unlinkedDataItems.push(data);
|
|
122
114
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const child = (this.element.children.item(i));
|
|
115
|
+
}
|
|
116
|
+
let i = this.element.children.length;
|
|
117
|
+
while (i--) {
|
|
118
|
+
const child = /** @type {T2} */ (this.element.children.item(i));
|
|
127
119
|
const data = this.elementDataMap.get(child);
|
|
128
|
-
if (data && this.datasource.
|
|
120
|
+
if (data && !this.datasource.includes(data)) {
|
|
129
121
|
orphanedElements.push(child);
|
|
130
122
|
}
|
|
131
123
|
}
|
|
132
|
-
|
|
124
|
+
for (const data of unlinkedDataItems) {
|
|
133
125
|
this.removeItem(data);
|
|
134
|
-
}
|
|
135
|
-
|
|
126
|
+
}
|
|
127
|
+
for (const el of orphanedElements) {
|
|
136
128
|
this.removeElement(el);
|
|
137
|
-
}
|
|
129
|
+
}
|
|
138
130
|
}
|
|
139
131
|
if (this.recycle) {
|
|
140
132
|
this.element.style.removeProperty('box-sizing');
|
|
@@ -144,9 +136,9 @@ export default class DomAdapter {
|
|
|
144
136
|
this.clear();
|
|
145
137
|
this.drawViewport(true);
|
|
146
138
|
} else {
|
|
147
|
-
this.datasource
|
|
139
|
+
for (const data of this.datasource) {
|
|
148
140
|
this.refreshItem(data);
|
|
149
|
-
}
|
|
141
|
+
}
|
|
150
142
|
}
|
|
151
143
|
}
|
|
152
144
|
|
|
@@ -261,10 +253,10 @@ export default class DomAdapter {
|
|
|
261
253
|
}
|
|
262
254
|
renderedElements.push(element);
|
|
263
255
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const child = (this.element.children.item(i));
|
|
267
|
-
if (renderedElements.
|
|
256
|
+
let i = this.element.children.length;
|
|
257
|
+
while (i--) {
|
|
258
|
+
const child = /** @type {T2} */ (this.element.children.item(i));
|
|
259
|
+
if (!renderedElements.includes(child)) {
|
|
268
260
|
this.removeElement(child);
|
|
269
261
|
}
|
|
270
262
|
}
|
|
@@ -295,7 +287,7 @@ export default class DomAdapter {
|
|
|
295
287
|
/**
|
|
296
288
|
* @param {T1} data
|
|
297
289
|
* @param {number} [indexHint]
|
|
298
|
-
* @return {DomAdapterBounds}
|
|
290
|
+
* @return {?DomAdapterBounds}
|
|
299
291
|
*/
|
|
300
292
|
getBounds(data, indexHint) {
|
|
301
293
|
const cached = this.dataBoundsMap.get(data);
|
|
@@ -303,11 +295,7 @@ export default class DomAdapter {
|
|
|
303
295
|
return cached;
|
|
304
296
|
}
|
|
305
297
|
let index = -1;
|
|
306
|
-
|
|
307
|
-
index = this.datasource.indexOf(data);
|
|
308
|
-
} else {
|
|
309
|
-
index = indexHint;
|
|
310
|
-
}
|
|
298
|
+
index = indexHint === -1 || indexHint == null ? this.datasource.indexOf(data) : indexHint;
|
|
311
299
|
if (index === -1) {
|
|
312
300
|
return null;
|
|
313
301
|
}
|
|
@@ -330,7 +318,6 @@ export default class DomAdapter {
|
|
|
330
318
|
const firstBounds = this.dataBoundsMap.get(this.datasource[0]);
|
|
331
319
|
if (firstBounds && firstBounds.height) {
|
|
332
320
|
top = firstBounds.height * index;
|
|
333
|
-
// eslint-disable-next-line prefer-destructuring
|
|
334
321
|
height = firstBounds.height;
|
|
335
322
|
} else {
|
|
336
323
|
return null;
|
|
@@ -430,8 +417,7 @@ export default class DomAdapter {
|
|
|
430
417
|
if (!element) {
|
|
431
418
|
// Element does not exist, assume size changed
|
|
432
419
|
invalidate = true;
|
|
433
|
-
/** @type {T2} */
|
|
434
|
-
element = (this.create(data));
|
|
420
|
+
element = /** @type {T2} */ (this.create(data));
|
|
435
421
|
this.dataElementMap.set(data, element);
|
|
436
422
|
this.elementDataMap.set(element, data);
|
|
437
423
|
}
|
|
@@ -467,9 +453,9 @@ export default class DomAdapter {
|
|
|
467
453
|
}
|
|
468
454
|
}
|
|
469
455
|
if (elementIndex !== dataIndex) {
|
|
470
|
-
if (!this.element.
|
|
456
|
+
if (!this.element.hasChildNodes()) {
|
|
471
457
|
if (element.parentElement) {
|
|
472
|
-
element.
|
|
458
|
+
element.remove();
|
|
473
459
|
}
|
|
474
460
|
this.element.appendChild(element);
|
|
475
461
|
} else {
|
|
@@ -483,9 +469,9 @@ export default class DomAdapter {
|
|
|
483
469
|
if (previousElement) {
|
|
484
470
|
if (element.previousElementSibling !== previousElement) {
|
|
485
471
|
if (element.parentElement) {
|
|
486
|
-
element.
|
|
472
|
+
element.remove();
|
|
487
473
|
}
|
|
488
|
-
previousElement.
|
|
474
|
+
previousElement.after(element);
|
|
489
475
|
}
|
|
490
476
|
inserted = true;
|
|
491
477
|
} else {
|
|
@@ -494,7 +480,7 @@ export default class DomAdapter {
|
|
|
494
480
|
} while (previousDataObject && !inserted);
|
|
495
481
|
if (!inserted) {
|
|
496
482
|
if (element.parentElement) {
|
|
497
|
-
element.
|
|
483
|
+
element.remove();
|
|
498
484
|
}
|
|
499
485
|
this.element.insertBefore(element, this.element.firstElementChild);
|
|
500
486
|
}
|
|
@@ -514,11 +500,10 @@ export default class DomAdapter {
|
|
|
514
500
|
prevClientHeight = element.clientHeight;
|
|
515
501
|
}
|
|
516
502
|
this.render(element, data, dataIndex);
|
|
517
|
-
if (!invalidate && options.invalidate !== false
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
}
|
|
503
|
+
if (!invalidate && options.invalidate !== false
|
|
504
|
+
&& (element.clientWidth !== prevClientWidth || element.clientHeight !== prevClientHeight)) {
|
|
505
|
+
// Element width or height has changed
|
|
506
|
+
invalidate = true;
|
|
522
507
|
}
|
|
523
508
|
}
|
|
524
509
|
if (options.invalidate === true || (invalidate && options.invalidate !== false)) {
|
|
@@ -533,7 +518,7 @@ export default class DomAdapter {
|
|
|
533
518
|
*/
|
|
534
519
|
removeElement(element) {
|
|
535
520
|
if (element.parentElement) {
|
|
536
|
-
element.
|
|
521
|
+
element.remove();
|
|
537
522
|
}
|
|
538
523
|
const data = this.elementDataMap.get(element);
|
|
539
524
|
if (data) {
|