@3mo/data-grid 0.5.5 → 0.5.7

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 (35) hide show
  1. package/dist/CsvGenerator.js +2 -3
  2. package/dist/DataGrid.d.ts +3 -1
  3. package/dist/DataGrid.d.ts.map +1 -1
  4. package/dist/DataGrid.js +294 -297
  5. package/dist/DataGridCell.js +46 -50
  6. package/dist/DataGridFooter.js +93 -94
  7. package/dist/DataGridHeader.js +92 -92
  8. package/dist/DataGridHeaderSeparator.js +46 -47
  9. package/dist/DataGridPrimaryContextMenuItem.js +5 -5
  10. package/dist/DataGridSelectionController.js +1 -2
  11. package/dist/DataGridSidePanel.d.ts.map +1 -1
  12. package/dist/DataGridSidePanel.js +117 -130
  13. package/dist/FieldSelectDataGridPageSize.js +7 -7
  14. package/dist/columns/DataGridColumn.js +4 -7
  15. package/dist/columns/DataGridColumn.test.js +6 -6
  16. package/dist/columns/DataGridColumnBoolean.js +9 -9
  17. package/dist/columns/DataGridColumnImage.js +2 -2
  18. package/dist/columns/DataGridColumnText.js +6 -6
  19. package/dist/columns/date-time/DataGridColumnDate.js +1 -2
  20. package/dist/columns/date-time/DataGridColumnDateRange.js +1 -2
  21. package/dist/columns/date-time/DataGridColumnDateTime.js +1 -2
  22. package/dist/columns/date-time/DataGridColumnDateTimeBase.js +10 -11
  23. package/dist/columns/date-time/DataGridColumnDateTimeRange.js +1 -2
  24. package/dist/columns/number/DataGridColumnCurrency.js +10 -11
  25. package/dist/columns/number/DataGridColumnNumber.js +6 -7
  26. package/dist/columns/number/DataGridColumnNumberBase.js +5 -1
  27. package/dist/columns/number/DataGridColumnPercent.js +7 -8
  28. package/dist/columns/number/DataGridFooterSum.js +20 -20
  29. package/dist/excel.svg.js +47 -47
  30. package/dist/rows/DataGridDefaultRow.js +47 -47
  31. package/dist/rows/DataGridRow.d.ts +2 -0
  32. package/dist/rows/DataGridRow.d.ts.map +1 -1
  33. package/dist/rows/DataGridRow.js +159 -147
  34. package/dist/tsconfig.tsbuildinfo +1 -1
  35. package/package.json +55 -56
package/dist/DataGrid.js CHANGED
@@ -98,6 +98,8 @@ export var DataGridEditability;
98
98
  *
99
99
  * @cssprop --mo-data-grid-min-visible-rows - The minimum number of visible rows. Default to 2.5.
100
100
  * @cssprop --mo-data-grid-footer-background - The background of the footer.
101
+ * @cssprop --mo-data-grid-cell-padding - The inline padding of the cells. Default to 3px.
102
+ * @cssprop --mo-data-grid-column-sub-row-indentation - The indentation of the first column in the sub row. Default to 10px.
101
103
  *
102
104
  * @fires dataChange {CustomEvent<Array<TData>>}
103
105
  * @fires selectionChange {CustomEvent<Array<TData>>}
@@ -142,11 +144,10 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
142
144
  this.cellFontSize = DataGrid_1.cellRelativeFontSize.value;
143
145
  this.rowHeight = DataGrid_1.rowHeight.value;
144
146
  this.slotController = new SlotController(this, async () => {
145
- var _a;
146
147
  this.hasSums;
147
148
  this.hasFabs;
148
149
  await this.updateComplete;
149
- this.style.setProperty('--mo-data-grid-fab-slot-width', `${((_a = this.renderRoot.querySelector('slot[name=fab]')) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width) || 75}px`);
150
+ this.style.setProperty('--mo-data-grid-fab-slot-width', `${this.renderRoot.querySelector('slot[name=fab]')?.getBoundingClientRect().width || 75}px`);
150
151
  });
151
152
  this.instanceofAttributeController = new InstanceofAttributeController(this);
152
153
  this.smallScreenObserverController = new MediaQueryController(this, '(max-width: 768px)');
@@ -155,11 +156,10 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
155
156
  // eslint-disable-next-line @typescript-eslint/member-ordering
156
157
  this.lastScrollElementTop = 0;
157
158
  this.handleScroll = (e) => {
158
- var _a;
159
159
  if (this.preventFabCollapse === false) {
160
160
  if (!e.composed) {
161
161
  e.preventDefault();
162
- (_a = e.target) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new Event('scroll', { composed: true, bubbles: true }));
162
+ e.target?.dispatchEvent(new Event('scroll', { composed: true, bubbles: true }));
163
163
  if (this.hasFabs) {
164
164
  const targetElement = e.composedPath()[0];
165
165
  const scrollTop = targetElement.scrollTop;
@@ -227,8 +227,8 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
227
227
  return Array.isArray(subValue) && subValue.length > 0 ? subValue : undefined;
228
228
  }
229
229
  hasDetail(data) {
230
- var _a, _b, _c;
231
- return !!this.getSubData(data) || ((_b = (_a = this.hasDataDetail) === null || _a === void 0 ? void 0 : _a.call(this, data)) !== null && _b !== void 0 ? _b : [undefined, html.nothing].includes((_c = this.getRowDetailsTemplate) === null || _c === void 0 ? void 0 : _c.call(this, data)) === false);
230
+ return !!this.getSubData(data) || (this.hasDataDetail?.(data) ??
231
+ [undefined, html.nothing].includes(this.getRowDetailsTemplate?.(data)) === false);
232
232
  }
233
233
  get allRowDetailsOpen() {
234
234
  return this.openDetailedData.length === this.detailedData.length;
@@ -275,7 +275,7 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
275
275
  }
276
276
  handleEdit(data, dataSelector, value) {
277
277
  const row = this.rows.find(r => r.data === data);
278
- const cell = row === null || row === void 0 ? void 0 : row.cells.find(c => c.dataSelector === dataSelector);
278
+ const cell = row?.cells.find(c => c.dataSelector === dataSelector);
279
279
  if (row && cell && value !== undefined && cell.value !== value) {
280
280
  row.requestUpdate();
281
281
  setValueByKeyPath(data, dataSelector, value);
@@ -312,14 +312,12 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
312
312
  return this.filterElements.length > 0;
313
313
  }
314
314
  get hasSums() {
315
- var _a;
316
- const hasSums = !!this.columns.find(c => c.sumHeading) || !!this.querySelector('* [slot="sum"]') || !!((_a = this.renderRoot) === null || _a === void 0 ? void 0 : _a.querySelector('slot[name="sum"] > *'));
315
+ const hasSums = !!this.columns.find(c => c.sumHeading) || !!this.querySelector('* [slot="sum"]') || !!this.renderRoot?.querySelector('slot[name="sum"] > *');
317
316
  this.toggleAttribute('hasSums', hasSums);
318
317
  return hasSums;
319
318
  }
320
319
  get hasFabs() {
321
- var _a;
322
- const hasFabs = !!this.querySelector('* [slot=fab]') || !!((_a = this.renderRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#fab *:not(slot[name=fab])'));
320
+ const hasFabs = !!this.querySelector('* [slot=fab]') || !!this.renderRoot?.querySelector('#fab *:not(slot[name=fab])');
323
321
  this.toggleAttribute('hasFabs', hasFabs);
324
322
  return hasFabs;
325
323
  }
@@ -330,13 +328,12 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
330
328
  return this.hasPagination;
331
329
  }
332
330
  get pageSize() {
333
- var _a;
334
331
  const dynamicPageSize = (pageSize) => this.supportsDynamicPageSize ? pageSize : DataGrid_1.pageSize.value;
335
332
  if (!this.pagination) {
336
333
  return dynamicPageSize(this.data.length);
337
334
  }
338
335
  if (this.pagination === 'auto') {
339
- const rowsHeight = (_a = this.rowsContainer) === null || _a === void 0 ? void 0 : _a.clientHeight;
336
+ const rowsHeight = this.rowsContainer?.clientHeight;
340
337
  const rowHeight = this.rowHeight;
341
338
  const pageSize = Math.floor((rowsHeight || 0) / rowHeight) || 1;
342
339
  return dynamicPageSize(pageSize);
@@ -358,10 +355,9 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
358
355
  return this.page !== this.maxPage;
359
356
  }
360
357
  updated(...parameters) {
361
- var _a, _b, _c;
362
- (_a = this.header) === null || _a === void 0 ? void 0 : _a.requestUpdate();
363
- (_b = this.sidePanel) === null || _b === void 0 ? void 0 : _b.requestUpdate();
364
- (_c = this.footer) === null || _c === void 0 ? void 0 : _c.requestUpdate();
358
+ this.header?.requestUpdate();
359
+ this.sidePanel?.requestUpdate();
360
+ this.footer?.requestUpdate();
365
361
  this.rows.forEach(row => row.requestUpdate());
366
362
  return super.updated(...parameters);
367
363
  }
@@ -372,186 +368,185 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
372
368
  this.setPage(1);
373
369
  }
374
370
  static get styles() {
375
- return css `
376
- :host {
377
- --mo-data-grid-column-details-width: 20px;
378
- --mo-data-grid-column-selection-width: 40px;
379
- --mo-data-grid-column-more-width: 20px;
380
-
381
- --mo-data-grid-header-height: 32px;
382
- --mo-data-grid-footer-min-height: 40px;
383
- --mo-data-grid-toolbar-padding: 0px 14px 14px 14px;
384
- --mo-data-grid-border: 1px solid var(--mo-color-transparent-gray-3);
385
-
386
- /* --mo-data-grid-columns Generated in JS */
387
- --mo-data-grid-columns-gap: 6px;
388
-
389
- --mo-data-grid-row-tree-line-width: 8px;
390
- --mo-details-data-grid-start-margin: 26px;
391
- --mo-data-grid-cell-padding: 3px;
392
-
393
- --mo-data-grid-selection-background: rgba(var(--mo-color-accent-base), 0.5);
394
- display: flex;
395
- flex-direction: column;
396
- height: 100%;
397
- overflow-x: hidden;
398
- }
399
-
400
- :host([data-theme=light]) {
401
- --mo-data-grid-alternating-background: rgba(var(--mo-color-foreground-base), 0.05);
402
- }
403
-
404
- :host([data-theme=dark]) {
405
- --mo-data-grid-alternating-background: rgba(var(--mo-color-background-base), 0.2);
406
- }
407
-
408
- :host([preventVerticalContentScroll]) mo-scroller {
409
- overflow-y: hidden;
410
- }
411
-
412
- :host([preventVerticalContentScroll]) mo-scroller::part(container) {
413
- position: relative;
414
- }
415
-
416
- :host(:not([selectionMode="none"])) {
417
- --mo-data-grid-row-tree-line-width: 18px;
418
- }
419
-
420
- :host([hasDetails]) {
421
- --mo-data-grid-row-tree-line-width: 18px;
422
- }
423
-
424
- #toolbar {
425
- position: relative;
426
- padding: var(--mo-data-grid-toolbar-padding);
427
- }
428
-
429
- #toolbar mo-icon-button {
430
- align-self: flex-start;
431
- color: var(--mo-color-gray);
432
- }
433
-
434
- #flexSelectionToolbar {
435
- background: var(--mo-color-surface);
436
- position: absolute;
437
- inset: 0px;
438
- width: 100%;
439
- height: 100%;
440
- z-index: 1;
441
- }
442
-
443
- #flexSelectionToolbar > mo-flex {
444
- background: var(--mo-data-grid-selection-background);
445
- height: 100%;
446
- align-items: center;
447
- }
448
-
449
- #flexSelectionToolbar mo-icon-button {
450
- align-self: center;
451
- color: var(--mo-color-foreground);
452
- }
453
-
454
- #flexActions {
455
- align-items: center;
456
- justify-content: center;
457
- padding-inline: 14px 6px;
458
- margin: 6px 0;
459
- cursor: pointer;
460
- background: var(--mo-color-accent-transparent);
461
- height: calc(100% - calc(2 * 6px));
462
- max-height: 45px;
463
- }
464
-
465
- #fab {
466
- position: absolute;
467
- top: -72px;
468
- inset-inline-end: 16px;
469
- transition: var(--mo-data-grid-fab-transition, 250ms);
470
- }
471
-
472
- :host([hasFooter]) #fab {
473
- top: -28px;
474
- }
475
-
476
- :host([fabSlotCollapsed][hasFabs]) #fab {
477
- transform: scale(0);
478
- opacity: 0;
479
- }
480
-
481
- mo-data-grid-footer {
482
- transition: var(--mo-data-grid-fab-transition, 250ms);
483
- }
484
-
485
- :host([hasSums][hasFabs]:not([fabSlotCollapsed])) mo-data-grid-footer {
486
- --mo-data-grid-footer-trailing-padding: calc(var(--mo-data-grid-fab-slot-width, 56px) + 16px);
487
- }
488
-
489
- slot[name=fab] {
490
- display: block;
491
- z-index: 1;
492
- }
493
-
494
- mo-empty-state, ::slotted(mo-empty-state) {
495
- height: 100%;
496
- }
497
-
498
- #overlayModeContainer {
499
- position: relative;
500
- height: 100%;
501
- width: 100%;
502
- }
503
-
504
- #overlayModeContainer mo-data-grid-side-panel {
505
- position: absolute;
506
- inset: 0;
507
- width: 100%;
508
- height: 100%;
509
- z-index: 1;
510
- background-color: var(--mo-color-surface);
511
- }
371
+ return css `
372
+ :host {
373
+ --mo-data-grid-column-details-width: 20px;
374
+ --mo-data-grid-column-selection-width: 40px;
375
+ --mo-data-grid-column-more-width: 20px;
376
+
377
+ --mo-data-grid-header-height: 32px;
378
+ --mo-data-grid-footer-min-height: 40px;
379
+ --mo-data-grid-toolbar-padding: 0px 14px 14px 14px;
380
+ --mo-data-grid-border: 1px solid var(--mo-color-transparent-gray-3);
381
+
382
+ /* --mo-data-grid-columns Generated in JS */
383
+ --mo-data-grid-columns-gap: 6px;
384
+
385
+ --mo-data-grid-row-tree-line-width: 8px;
386
+ --mo-details-data-grid-start-margin: 26px;
387
+
388
+ --mo-data-grid-selection-background: rgba(var(--mo-color-accent-base), 0.5);
389
+ display: flex;
390
+ flex-direction: column;
391
+ height: 100%;
392
+ overflow-x: hidden;
393
+ }
394
+
395
+ :host([data-theme=light]) {
396
+ --mo-data-grid-alternating-background: rgba(var(--mo-color-foreground-base), 0.05);
397
+ }
398
+
399
+ :host([data-theme=dark]) {
400
+ --mo-data-grid-alternating-background: rgba(var(--mo-color-background-base), 0.2);
401
+ }
402
+
403
+ :host([preventVerticalContentScroll]) mo-scroller {
404
+ overflow-y: hidden;
405
+ }
406
+
407
+ :host([preventVerticalContentScroll]) mo-scroller::part(container) {
408
+ position: relative;
409
+ }
410
+
411
+ :host(:not([selectionMode="none"])) {
412
+ --mo-data-grid-row-tree-line-width: 18px;
413
+ }
414
+
415
+ :host([hasDetails]) {
416
+ --mo-data-grid-row-tree-line-width: 18px;
417
+ }
418
+
419
+ #toolbar {
420
+ position: relative;
421
+ padding: var(--mo-data-grid-toolbar-padding);
422
+ }
423
+
424
+ #toolbar mo-icon-button {
425
+ align-self: flex-start;
426
+ color: var(--mo-color-gray);
427
+ }
428
+
429
+ #flexSelectionToolbar {
430
+ background: var(--mo-color-surface);
431
+ position: absolute;
432
+ inset: 0px;
433
+ width: 100%;
434
+ height: 100%;
435
+ z-index: 1;
436
+ }
437
+
438
+ #flexSelectionToolbar > mo-flex {
439
+ background: var(--mo-data-grid-selection-background);
440
+ height: 100%;
441
+ align-items: center;
442
+ }
443
+
444
+ #flexSelectionToolbar mo-icon-button {
445
+ align-self: center;
446
+ color: var(--mo-color-foreground);
447
+ }
448
+
449
+ #flexActions {
450
+ align-items: center;
451
+ justify-content: center;
452
+ padding-inline: 14px 6px;
453
+ margin: 6px 0;
454
+ cursor: pointer;
455
+ background: var(--mo-color-accent-transparent);
456
+ height: calc(100% - calc(2 * 6px));
457
+ max-height: 45px;
458
+ }
459
+
460
+ #fab {
461
+ position: absolute;
462
+ top: -72px;
463
+ inset-inline-end: 16px;
464
+ transition: var(--mo-data-grid-fab-transition, 250ms);
465
+ }
466
+
467
+ :host([hasFooter]) #fab {
468
+ top: -28px;
469
+ }
470
+
471
+ :host([fabSlotCollapsed][hasFabs]) #fab {
472
+ transform: scale(0);
473
+ opacity: 0;
474
+ }
475
+
476
+ mo-data-grid-footer {
477
+ transition: var(--mo-data-grid-fab-transition, 250ms);
478
+ }
479
+
480
+ :host([hasSums][hasFabs]:not([fabSlotCollapsed])) mo-data-grid-footer {
481
+ --mo-data-grid-footer-trailing-padding: calc(var(--mo-data-grid-fab-slot-width, 56px) + 16px);
482
+ }
483
+
484
+ slot[name=fab] {
485
+ display: block;
486
+ z-index: 1;
487
+ }
488
+
489
+ mo-empty-state, ::slotted(mo-empty-state) {
490
+ height: 100%;
491
+ }
492
+
493
+ #overlayModeContainer {
494
+ position: relative;
495
+ height: 100%;
496
+ width: 100%;
497
+ }
498
+
499
+ #overlayModeContainer mo-data-grid-side-panel {
500
+ position: absolute;
501
+ inset: 0;
502
+ width: 100%;
503
+ height: 100%;
504
+ z-index: 1;
505
+ background-color: var(--mo-color-surface);
506
+ }
512
507
  `;
513
508
  }
514
509
  get template() {
515
- return html `
516
- <slot name='column' hidden ${observeMutation(() => this.requestUpdate())}>${this.columnsTemplate}</slot>
517
- ${this.toolbarTemplate}
518
- ${this.smallScreenObserverController.matches ? this.overlayModeTemplate : this.splitterModeTemplate}
510
+ return html `
511
+ <slot name='column' hidden ${observeMutation(() => this.requestUpdate())}>${this.columnsTemplate}</slot>
512
+ ${this.toolbarTemplate}
513
+ ${this.smallScreenObserverController.matches ? this.overlayModeTemplate : this.splitterModeTemplate}
519
514
  `;
520
515
  }
521
516
  get splitterModeTemplate() {
522
- return html `
523
- <mo-splitter direction='horizontal-reversed' ${style({ height: '100%' })} .resizerTemplate=${html `
524
- <mo-splitter-resizer-line style='--mo-splitter-resizer-line-thickness: 1px; --mo-splitter-resizer-line-idle-background: var(--mo-color-transparent-gray-3); --mo-splitter-resizer-line-horizontal-transform: scaleX(5);'></mo-splitter-resizer-line>
525
- `}>
526
- ${cache(this.sidePanelTab === undefined ? html.nothing : html `
527
- <mo-splitter-item size='min(25%, 300px)' min='max(15%, 250px)' max='clamp(100px, 50%, 750px)'>
528
- ${this.sidePanelTemplate}
529
- </mo-splitter-item>
530
- `)}
531
-
532
- <mo-splitter-item min='0px' ${style({ position: 'relative' })}>
533
- ${this.dataGridTemplate}
534
- </mo-splitter-item>
535
- </mo-splitter>
517
+ return html `
518
+ <mo-splitter direction='horizontal-reversed' ${style({ height: '100%' })} .resizerTemplate=${html `
519
+ <mo-splitter-resizer-line style='--mo-splitter-resizer-line-thickness: 1px; --mo-splitter-resizer-line-idle-background: var(--mo-color-transparent-gray-3); --mo-splitter-resizer-line-horizontal-transform: scaleX(5);'></mo-splitter-resizer-line>
520
+ `}>
521
+ ${cache(this.sidePanelTab === undefined ? html.nothing : html `
522
+ <mo-splitter-item size='min(25%, 300px)' min='max(15%, 250px)' max='clamp(100px, 50%, 750px)'>
523
+ ${this.sidePanelTemplate}
524
+ </mo-splitter-item>
525
+ `)}
526
+
527
+ <mo-splitter-item min='0px' ${style({ position: 'relative' })}>
528
+ ${this.dataGridTemplate}
529
+ </mo-splitter-item>
530
+ </mo-splitter>
536
531
  `;
537
532
  }
538
533
  get overlayModeTemplate() {
539
- return html `
540
- <mo-flex id='overlayModeContainer'>
541
- ${this.dataGridTemplate}
542
- ${this.sidePanelTab === undefined ? html.nothing : this.sidePanelTemplate}
543
- </mo-flex>
534
+ return html `
535
+ <mo-flex id='overlayModeContainer'>
536
+ ${this.dataGridTemplate}
537
+ ${this.sidePanelTab === undefined ? html.nothing : this.sidePanelTemplate}
538
+ </mo-flex>
544
539
  `;
545
540
  }
546
541
  get sidePanelTemplate() {
547
- return html `
548
- <mo-data-grid-side-panel
549
- .dataGrid=${this}
550
- tab=${ifDefined(this.sidePanelTab)}
551
- >
552
- <slot slot='settings' name='settings'>${this.settingsDefaultTemplate}</slot>
553
- <slot slot='filter' name='filter'>${this.filtersDefaultTemplate}</slot>
554
- </mo-data-grid-side-panel>
542
+ return html `
543
+ <mo-data-grid-side-panel
544
+ .dataGrid=${this}
545
+ tab=${ifDefined(this.sidePanelTab)}
546
+ >
547
+ <slot slot='settings' name='settings'>${this.settingsDefaultTemplate}</slot>
548
+ <slot slot='filter' name='filter'>${this.filtersDefaultTemplate}</slot>
549
+ </mo-data-grid-side-panel>
555
550
  `;
556
551
  }
557
552
  get settingsDefaultTemplate() {
@@ -570,40 +565,40 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
570
565
  // These also update the respective attributes for now
571
566
  this.hasSums;
572
567
  this.hasFabs;
573
- return html `
574
- <slot name='fab' @slotchange=${() => { this.hasSums; this.hasFabs; }}></slot>
568
+ return html `
569
+ <slot name='fab' @slotchange=${() => { this.hasSums; this.hasFabs; }}></slot>
575
570
  `;
576
571
  }
577
572
  get contentTemplate() {
578
573
  return !this.data.length ? this.noContentTemplate : this.rowsTemplate;
579
574
  }
580
575
  get noContentTemplate() {
581
- return html `
582
- <slot name='error-no-content'>
583
- <mo-empty-state icon='youtube_searched_for'>${t('No results')}</mo-empty-state>
584
- </slot>
576
+ return html `
577
+ <slot name='error-no-content'>
578
+ <mo-empty-state icon='youtube_searched_for'>${t('No results')}</mo-empty-state>
579
+ </slot>
585
580
  `;
586
581
  }
587
582
  get dataGridTemplate() {
588
583
  this.provideCssColumnsProperties();
589
584
  this.toggleAttribute('hasDetails', this.hasDetails);
590
- return html `
591
- <mo-flex ${style({ flex: '1', position: 'relative' })}>
592
- <mo-grid ${style({ flex: '1' })} rows='* auto'>
593
- <mo-scroller ${style({ minHeight: 'var(--mo-data-grid-content-min-height, calc(var(--mo-data-grid-min-visible-rows, 2.5) * var(--mo-data-grid-row-height) + var(--mo-data-grid-header-height)))' })}>
594
- <mo-grid ${style({ height: '100%' })} rows='auto *'>
595
- ${this.headerTemplate}
596
- ${this.contentTemplate}
597
- </mo-grid>
598
- </mo-scroller>
599
- ${this.footerTemplate}
600
- </mo-grid>
601
- </mo-flex>
585
+ return html `
586
+ <mo-flex ${style({ flex: '1', position: 'relative' })}>
587
+ <mo-grid ${style({ flex: '1' })} rows='* auto'>
588
+ <mo-scroller ${style({ minHeight: 'var(--mo-data-grid-content-min-height, calc(var(--mo-data-grid-min-visible-rows, 2.5) * var(--mo-data-grid-row-height) + var(--mo-data-grid-header-height)))' })}>
589
+ <mo-grid ${style({ height: '100%' })} rows='auto *'>
590
+ ${this.headerTemplate}
591
+ ${this.contentTemplate}
592
+ </mo-grid>
593
+ </mo-scroller>
594
+ ${this.footerTemplate}
595
+ </mo-grid>
596
+ </mo-flex>
602
597
  `;
603
598
  }
604
599
  get headerTemplate() {
605
- return this.headerHidden ? html.nothing : html `
606
- <mo-data-grid-header .dataGrid=${this}></mo-data-grid-header>
600
+ return this.headerHidden ? html.nothing : html `
601
+ <mo-data-grid-header .dataGrid=${this}></mo-data-grid-header>
607
602
  `;
608
603
  }
609
604
  get rowsTemplate() {
@@ -612,27 +607,28 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
612
607
  const content = shallVirtualize === false
613
608
  ? this.renderData.map(getRowTemplate)
614
609
  : html `<mo-virtualized-scroller .items=${this.renderData} .getItemTemplate=${getRowTemplate}></mo-virtualized-scroller>`;
615
- return html `
616
- <mo-scroller id='rowsContainer'
617
- ${style({ gridRow: '2', gridColumn: '1 / last-line', overflowX: 'hidden' })}
618
- ${observeResize(() => this.requestUpdate())}
619
- @scroll=${this.handleScroll}
620
- >
621
- ${content}
622
- </mo-scroller>
610
+ return html `
611
+ <mo-scroller id='rowsContainer'
612
+ ${style({ gridRow: '2', gridColumn: '1 / last-line', overflowX: 'hidden' })}
613
+ ${observeResize(() => this.requestUpdate())}
614
+ @scroll=${this.handleScroll}
615
+ >
616
+ ${content}
617
+ </mo-scroller>
623
618
  `;
624
619
  }
625
- getRowTemplate(data, index) {
626
- return staticHtml `
627
- <${this.rowElementTag} part='row'
628
- .dataGrid=${this}
629
- .data=${data}
630
- ?data-has-alternating-background=${index !== undefined && this.hasAlternatingBackground && index % 2 === 1}
631
- ?data-grid-has-details=${this.hasDetails}
632
- ?selected=${live(this.selectedData.includes(data))}
633
- ?detailsOpen=${live(this.openDetailedData.includes(data))}
634
- @detailsOpenChange=${(event) => this.handleRowDetailsOpenChange(data, event.detail)}
635
- ></${this.rowElementTag}>
620
+ getRowTemplate(data, index, level = 0) {
621
+ return staticHtml `
622
+ <${this.rowElementTag} part='row'
623
+ .level=${level}
624
+ .dataGrid=${this}
625
+ .data=${data}
626
+ ?data-has-alternating-background=${index !== undefined && this.hasAlternatingBackground && index % 2 === 1}
627
+ ?data-grid-has-details=${this.hasDetails}
628
+ ?selected=${live(this.selectedData.includes(data))}
629
+ ?detailsOpen=${live(this.openDetailedData.includes(data))}
630
+ @detailsOpenChange=${(event) => this.handleRowDetailsOpenChange(data, event.detail)}
631
+ ></${this.rowElementTag}>
636
632
  `;
637
633
  }
638
634
  handleRowDetailsOpenChange(data, open) {
@@ -647,30 +643,30 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
647
643
  : this.openDetailedData.filter(d => d !== data);
648
644
  }
649
645
  get footerTemplate() {
650
- return html `
651
- <mo-flex ${style({ position: 'relative' })}>
652
- <mo-flex id='fab' direction='vertical-reversed' gap='8px'>
653
- ${this.fabTemplate}
654
- </mo-flex>
655
- ${this.hasFooter === false ? html.nothing : html `
656
- <mo-data-grid-footer
657
- .dataGrid=${this}
658
- page=${this.page}
659
- >
660
- <slot name='sum' slot='sum'>${this.sumDefaultTemplate}</slot>
661
- </mo-data-grid-footer>
662
- `}
663
- </mo-flex>
646
+ return html `
647
+ <mo-flex ${style({ position: 'relative' })}>
648
+ <mo-flex id='fab' direction='vertical-reversed' gap='8px'>
649
+ ${this.fabTemplate}
650
+ </mo-flex>
651
+ ${this.hasFooter === false ? html.nothing : html `
652
+ <mo-data-grid-footer
653
+ .dataGrid=${this}
654
+ page=${this.page}
655
+ >
656
+ <slot name='sum' slot='sum'>${this.sumDefaultTemplate}</slot>
657
+ </mo-data-grid-footer>
658
+ `}
659
+ </mo-flex>
664
660
  `;
665
661
  }
666
662
  get sumsData() {
667
663
  return this.selectedData.length > 0 ? this.selectedData : this.renderData;
668
664
  }
669
665
  get sumsTemplate() {
670
- return html `
671
- <mo-flex direction='horizontal' gap='10px' wrap='wrap-reverse' alignItems='center' ${style({ padding: '2px 4px' })}>
672
- ${this.columns.map(column => this.getSumTemplate(column))}
673
- </mo-flex>
666
+ return html `
667
+ <mo-flex direction='horizontal' gap='10px' wrap='wrap-reverse' alignItems='center' ${style({ padding: '2px 4px' })}>
668
+ ${this.columns.map(column => this.getSumTemplate(column))}
669
+ </mo-flex>
674
670
  `;
675
671
  }
676
672
  getSumTemplate(column) {
@@ -682,24 +678,24 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
682
678
  .filter(n => isNaN(n) === false)
683
679
  .reduce(((a, b) => a + b), 0)
684
680
  || 0;
685
- return html `
686
- <mo-data-grid-footer-sum heading=${column.sumHeading + ''} ${style({ color: this.selectedData.length > 0 ? 'var(--mo-color-accent)' : 'currentColor' })}>
687
- ${column.getSumTemplate(sum)}
688
- </mo-data-grid-footer-sum>
681
+ return html `
682
+ <mo-data-grid-footer-sum heading=${column.sumHeading + ''} ${style({ color: this.selectedData.length > 0 ? 'var(--mo-color-accent)' : 'currentColor' })}>
683
+ ${column.getSumTemplate(sum)}
684
+ </mo-data-grid-footer-sum>
689
685
  `;
690
686
  }
691
687
  get toolbarTemplate() {
692
- return this.hasToolbar === false ? html.nothing : html `
693
- <mo-flex id='toolbar' direction='horizontal' gap='8px' wrap='wrap' justifyContent='end' alignItems='center'>
694
- <mo-flex direction='horizontal' alignItems='inherit' gap='8px' wrap='wrap' ${style({ flex: '1' })}>
695
- <slot name='toolbar'>${this.toolbarDefaultTemplate}</slot>
696
- </mo-flex>
697
- <mo-flex direction='horizontal' gap='8px'>
698
- <slot name='toolbarAction'>${this.toolbarActionDefaultTemplate}</slot>
699
- ${this.toolbarActionsTemplate}
700
- ${this.selectionToolbarTemplate}
701
- </mo-flex>
702
- </mo-flex>
688
+ return this.hasToolbar === false ? html.nothing : html `
689
+ <mo-flex id='toolbar' direction='horizontal' gap='8px' wrap='wrap' justifyContent='end' alignItems='center'>
690
+ <mo-flex direction='horizontal' alignItems='inherit' gap='8px' wrap='wrap' ${style({ flex: '1' })}>
691
+ <slot name='toolbar'>${this.toolbarDefaultTemplate}</slot>
692
+ </mo-flex>
693
+ <mo-flex direction='horizontal' gap='8px'>
694
+ <slot name='toolbarAction'>${this.toolbarActionDefaultTemplate}</slot>
695
+ ${this.toolbarActionsTemplate}
696
+ ${this.selectionToolbarTemplate}
697
+ </mo-flex>
698
+ </mo-flex>
703
699
  `;
704
700
  }
705
701
  get toolbarDefaultTemplate() {
@@ -712,42 +708,42 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
712
708
  return html.nothing;
713
709
  }
714
710
  get selectionToolbarTemplate() {
715
- return this.selectionToolbarDisabled === true || this.selectedData.length === 0 ? html.nothing : html `
716
- <mo-flex id='flexSelectionToolbar'>
717
- <mo-flex direction='horizontal' gap='30px' ${style({ placeSelf: 'stretch' })}>
718
- <div ${style({ fontWeight: '500', margin: '0 6px' })}>
719
- ${t('${count:pluralityNumber} entries selected', { count: this.selectedData.length })}
720
- </div>
721
- ${!this.getRowContextMenuTemplate ? html.nothing : html `
722
- <mo-flex id='flexActions' direction='horizontal' @click=${(e) => { var _a, _b; return ContextMenu.open(e, (_b = (_a = this.getRowContextMenuTemplate) === null || _a === void 0 ? void 0 : _a.call(this, this.selectedData)) !== null && _b !== void 0 ? _b : html.nothing); }}>
723
- <div ${style({ flex: '1' })}>${t('Options')}</div>
724
- <mo-icon-button dense icon='arrow_drop_down' ${style({ display: 'flex', alignItems: 'center', justifyContent: 'center' })}></mo-icon-button>
725
- </mo-flex>
726
- `}
727
- <div ${style({ flex: '1' })}></div>
728
- <mo-icon-button icon='close'
729
- ${tooltip(t('Deselect All'))}
730
- @click=${() => this.deselectAll()}
731
- ></mo-icon-button>
732
- </mo-flex>
733
- </mo-flex>
711
+ return this.selectionToolbarDisabled === true || this.selectedData.length === 0 ? html.nothing : html `
712
+ <mo-flex id='flexSelectionToolbar'>
713
+ <mo-flex direction='horizontal' gap='30px' ${style({ placeSelf: 'stretch' })}>
714
+ <div ${style({ fontWeight: '500', margin: '0 6px' })}>
715
+ ${t('${count:pluralityNumber} entries selected', { count: this.selectedData.length })}
716
+ </div>
717
+ ${!this.getRowContextMenuTemplate ? html.nothing : html `
718
+ <mo-flex id='flexActions' direction='horizontal' @click=${(e) => ContextMenu.open(e, this.getRowContextMenuTemplate?.(this.selectedData) ?? html.nothing)}>
719
+ <div ${style({ flex: '1' })}>${t('Options')}</div>
720
+ <mo-icon-button dense icon='arrow_drop_down' ${style({ display: 'flex', alignItems: 'center', justifyContent: 'center' })}></mo-icon-button>
721
+ </mo-flex>
722
+ `}
723
+ <div ${style({ flex: '1' })}></div>
724
+ <mo-icon-button icon='close'
725
+ ${tooltip(t('Deselect All'))}
726
+ @click=${() => this.deselectAll()}
727
+ ></mo-icon-button>
728
+ </mo-flex>
729
+ </mo-flex>
734
730
  `;
735
731
  }
736
732
  get toolbarActionsTemplate() {
737
- return html `
738
- ${!this.hasFilters ? html.nothing : html `
739
- <mo-icon-button icon='filter_list'
740
- ${tooltip(t('More Filters'))}
741
- ${style({ color: this.sidePanelTab === DataGridSidePanelTab.Filters ? 'var(--mo-color-accent)' : 'var(--mo-color-gray)' })}
742
- @click=${() => this.navigateToSidePanelTab(this.sidePanelTab === DataGridSidePanelTab.Filters ? undefined : DataGridSidePanelTab.Filters)}
743
- ></mo-icon-button>
744
- `}
745
-
746
- <mo-icon-button icon='settings'
747
- ${tooltip(t('Settings'))}
748
- ${style({ color: this.sidePanelTab === DataGridSidePanelTab.Settings ? 'var(--mo-color-accent)' : 'var(--mo-color-gray)' })}
749
- @click=${() => this.navigateToSidePanelTab(this.sidePanelTab === DataGridSidePanelTab.Settings ? undefined : DataGridSidePanelTab.Settings)}
750
- ></mo-icon-button>
733
+ return html `
734
+ ${!this.hasFilters ? html.nothing : html `
735
+ <mo-icon-button icon='filter_list'
736
+ ${tooltip(t('More Filters'))}
737
+ ${style({ color: this.sidePanelTab === DataGridSidePanelTab.Filters ? 'var(--mo-color-accent)' : 'var(--mo-color-gray)' })}
738
+ @click=${() => this.navigateToSidePanelTab(this.sidePanelTab === DataGridSidePanelTab.Filters ? undefined : DataGridSidePanelTab.Filters)}
739
+ ></mo-icon-button>
740
+ `}
741
+
742
+ <mo-icon-button icon='settings'
743
+ ${tooltip(t('Settings'))}
744
+ ${style({ color: this.sidePanelTab === DataGridSidePanelTab.Settings ? 'var(--mo-color-accent)' : 'var(--mo-color-gray)' })}
745
+ @click=${() => this.navigateToSidePanelTab(this.sidePanelTab === DataGridSidePanelTab.Settings ? undefined : DataGridSidePanelTab.Settings)}
746
+ ></mo-icon-button>
751
747
  `;
752
748
  }
753
749
  // The reason for not doing this in the CSS is that we need to trim all the 0px values out of the columns
@@ -788,7 +784,10 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
788
784
  getSortingDefinition(column) {
789
785
  const sorting = this.getSorting();
790
786
  const definition = sorting.find(s => s.selector === (column.sortDataSelector || column.dataSelector));
791
- return !definition ? undefined : Object.assign(Object.assign({}, definition), { rank: sorting.indexOf(definition) + 1 });
787
+ return !definition ? undefined : {
788
+ ...definition,
789
+ rank: sorting.indexOf(definition) + 1
790
+ };
792
791
  }
793
792
  *getFlattenedData() {
794
793
  if (!this.subDataGridDataSelector) {
@@ -815,15 +814,14 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
815
814
  get sortedData() {
816
815
  const sorting = this.getSorting();
817
816
  const sortedData = [...this.data];
818
- if (!(sorting === null || sorting === void 0 ? void 0 : sorting.length)) {
817
+ if (!sorting?.length) {
819
818
  return sortedData;
820
819
  }
821
820
  return sortedData.sort((a, b) => {
822
- var _a, _b;
823
821
  for (const sortCriteria of sorting) {
824
822
  const { selector, strategy } = sortCriteria;
825
- const aValue = (_a = getValueByKeyPath(a, selector)) !== null && _a !== void 0 ? _a : Infinity;
826
- const bValue = (_b = getValueByKeyPath(b, selector)) !== null && _b !== void 0 ? _b : Infinity;
823
+ const aValue = getValueByKeyPath(a, selector) ?? Infinity;
824
+ const bValue = getValueByKeyPath(b, selector) ?? Infinity;
827
825
  if (aValue < bValue) {
828
826
  return strategy === DataGridSortingStrategy.Ascending ? -1 : 1;
829
827
  }
@@ -844,13 +842,12 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
844
842
  return this.sortedData.slice(from, to);
845
843
  }
846
844
  get elementExtractedColumns() {
847
- var _a;
848
845
  if (!this.columnsSlot) {
849
846
  return [];
850
847
  }
851
848
  const children = this.columnsSlot.children.length > 0 ? Array.from(this.columnsSlot.children) : undefined;
852
849
  const assigned = this.columnsSlot.assignedElements().length > 0 ? Array.from(this.columnsSlot.assignedElements()) : undefined;
853
- return Array.from((_a = assigned !== null && assigned !== void 0 ? assigned : children) !== null && _a !== void 0 ? _a : [])
850
+ return Array.from(assigned ?? children ?? [])
854
851
  .filter((c) => {
855
852
  const isColumn = c instanceof DataGridColumn;
856
853
  if (isColumn) {