@nova-design-system/nova-react 3.0.0-beta.47 → 3.1.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.
Files changed (48) hide show
  1. package/dist/cjs/{constants-98e2dcc2-C0SBCapP.js → constants-b97e736d-BzFAKCkR.js} +11 -0
  2. package/dist/cjs/{index-Byv3Vmev.js → index-Cn-oNJnW.js} +1839 -1420
  3. package/dist/cjs/index.js +1 -1
  4. package/dist/cjs/{nv-alert.entry-BXY4KXbF.js → nv-alert.entry-BFwufSUQ.js} +11 -11
  5. package/dist/cjs/{nv-avatar.entry-BnPSKkJJ.js → nv-avatar.entry-Do1K4s3s.js} +7 -7
  6. package/dist/cjs/nv-badge_2.entry-NTGHyFdg.js +204 -0
  7. package/dist/cjs/{nv-breadcrumb.entry-D5vGHLOG.js → nv-breadcrumb.entry-oPVGJYlk.js} +1 -1
  8. package/dist/cjs/{nv-breadcrumbs.entry-CsaqAsnb.js → nv-breadcrumbs.entry-BsOw153b.js} +1 -1
  9. package/dist/cjs/{nv-button.entry-DzZfGZGy.js → nv-button.entry-13tdBiRr.js} +7 -7
  10. package/dist/cjs/nv-calendar.entry-u9MgGb83.js +1064 -0
  11. package/dist/cjs/{nv-col.entry-Cng8NaTW.js → nv-col.entry-DFhv-GI7.js} +1 -1
  12. package/dist/cjs/{nv-datagrid.entry-BbAOzpiO.js → nv-datagrid.entry-BoB17gvI.js} +377 -40
  13. package/dist/cjs/{nv-datagridcolumn.entry-CRogHbVM.js → nv-datagridcolumn.entry-C3MYBmfS.js} +1 -1
  14. package/dist/cjs/{nv-dialog.entry-BSIZGYGF.js → nv-dialog.entry-OA3qL3Tx.js} +19 -13
  15. package/dist/cjs/{nv-dialogfooter_2.entry-Q4_li_QU.js → nv-dialogfooter_2.entry-LAQYSiGV.js} +3 -3
  16. package/dist/cjs/{nv-fieldcheckbox.entry-DmgzfmRd.js → nv-fieldcheckbox.entry-CP7SDzVO.js} +1 -1
  17. package/dist/cjs/{nv-fielddate.entry-qAvLX_Ru.js → nv-fielddate.entry-CD7PX6yA.js} +9 -18
  18. package/dist/cjs/{nv-fielddaterange.entry-DVB8Rwxk.js → nv-fielddaterange.entry-BVBVGmly.js} +27 -29
  19. package/dist/cjs/{nv-fielddropdown.entry-DKXmoXeW.js → nv-fielddropdown.entry-Nwric1vT.js} +13 -6
  20. package/dist/cjs/{nv-fielddropdownitem.entry-BVLVXi0e.js → nv-fielddropdownitem.entry-CiqSw5VL.js} +2 -2
  21. package/dist/cjs/{nv-fieldmultiselect.entry-DrTbd3Dj.js → nv-fieldmultiselect.entry-QKNIBcW1.js} +11 -5
  22. package/dist/cjs/nv-fieldnumber.entry-DfHcI-sO.js +130 -0
  23. package/dist/cjs/nv-fieldpassword.entry-b2pUmS8F.js +121 -0
  24. package/dist/cjs/{nv-fieldradio.entry-CVEY4v6F.js → nv-fieldradio.entry-Dxc6ZCyb.js} +4 -4
  25. package/dist/cjs/{nv-fieldselect.entry-BrCUuRWa.js → nv-fieldselect.entry-Cys0KRyG.js} +11 -7
  26. package/dist/cjs/nv-fieldtext.entry-DCZWLFFp.js +123 -0
  27. package/dist/cjs/{nv-fieldtextarea.entry-B4qiLmX1.js → nv-fieldtextarea.entry-DEeRdtZ7.js} +9 -5
  28. package/dist/cjs/{nv-fieldtime.entry-Bp2IWjhN.js → nv-fieldtime.entry-BqxiFlLI.js} +71 -68
  29. package/dist/cjs/nv-icon.entry-CzEdUDdA.js +79 -0
  30. package/dist/cjs/{nv-iconbutton_2.entry-BRPAGl2S.js → nv-iconbutton_2.entry-BLNrQz9Q.js} +3 -3
  31. package/dist/cjs/{nv-menu.entry-BiWiIZAm.js → nv-menu.entry-7IDfPmZ8.js} +4 -2
  32. package/dist/cjs/{nv-menuitem.entry-CFkXoZ_r.js → nv-menuitem.entry-B9cjy7O8.js} +2 -2
  33. package/dist/cjs/{nv-popover.entry-KT1iQUJk.js → nv-popover.entry-ChLYZ3zY.js} +2 -2
  34. package/dist/cjs/{nv-row.entry-Cs2GDrcu.js → nv-row.entry-DiLY8Vbc.js} +2 -2
  35. package/dist/cjs/{nv-stack.entry-Ci7pxGSo.js → nv-stack.entry-MpPzmg5_.js} +2 -2
  36. package/dist/cjs/{nv-table.entry-N4MV8Y6E.js → nv-table.entry-cME3Zuq2.js} +3 -3
  37. package/dist/cjs/{nv-tablecolumn.entry-CTz4jsZl.js → nv-tablecolumn.entry-DSctDxCS.js} +1 -1
  38. package/dist/cjs/{nv-toggle.entry-m10-ncYR.js → nv-toggle.entry-EBWm3Xy5.js} +3 -3
  39. package/dist/cjs/{nv-tooltip.entry-B6aRDto3.js → nv-tooltip.entry-q6rJLq1C.js} +2 -2
  40. package/dist/generated/components.js +4 -1
  41. package/dist/types/generated/components.d.ts +14 -7
  42. package/package.json +1 -1
  43. package/dist/cjs/nv-badge_2.entry-BsI3B8Rr.js +0 -195
  44. package/dist/cjs/nv-calendar.entry-CGKv_-gO.js +0 -1065
  45. package/dist/cjs/nv-fieldnumber.entry-DegbEHRL.js +0 -126
  46. package/dist/cjs/nv-fieldpassword.entry-gqjlEl7a.js +0 -117
  47. package/dist/cjs/nv-fieldtext.entry-q9NnqL5c.js +0 -119
  48. package/dist/cjs/nv-icon.entry-B1ax9cJS.js +0 -79
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-Byv3Vmev.js');
3
+ var index = require('./index-Cn-oNJnW.js');
4
4
  var clsx297c1ffe = require('./clsx-297c1ffe-BtxeOLZW.js');
5
5
  require('react');
6
6
 
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-Byv3Vmev.js');
3
+ var index = require('./index-Cn-oNJnW.js');
4
4
  var dom_utilsAc71e0ef = require('./dom.utils-ac71e0ef-CmIwRr6O.js');
5
+ var constantsB97e736d = require('./constants-b97e736d-BzFAKCkR.js');
5
6
  require('react');
6
7
 
7
8
  /**
@@ -3202,6 +3203,92 @@ function getPaginationRowModel(opts) {
3202
3203
  }, getMemoOptions(table.options, 'debugTable'));
3203
3204
  }
3204
3205
 
3206
+ function getSortedRowModel() {
3207
+ return table => memo(() => [table.getState().sorting, table.getPreSortedRowModel()], (sorting, rowModel) => {
3208
+ if (!rowModel.rows.length || !(sorting != null && sorting.length)) {
3209
+ return rowModel;
3210
+ }
3211
+ const sortingState = table.getState().sorting;
3212
+ const sortedFlatRows = [];
3213
+
3214
+ // Filter out sortings that correspond to non existing columns
3215
+ const availableSorting = sortingState.filter(sort => {
3216
+ var _table$getColumn;
3217
+ return (_table$getColumn = table.getColumn(sort.id)) == null ? void 0 : _table$getColumn.getCanSort();
3218
+ });
3219
+ const columnInfoById = {};
3220
+ availableSorting.forEach(sortEntry => {
3221
+ const column = table.getColumn(sortEntry.id);
3222
+ if (!column) return;
3223
+ columnInfoById[sortEntry.id] = {
3224
+ sortUndefined: column.columnDef.sortUndefined,
3225
+ invertSorting: column.columnDef.invertSorting,
3226
+ sortingFn: column.getSortingFn()
3227
+ };
3228
+ });
3229
+ const sortData = rows => {
3230
+ // This will also perform a stable sorting using the row index
3231
+ // if needed.
3232
+ const sortedData = rows.map(row => ({
3233
+ ...row
3234
+ }));
3235
+ sortedData.sort((rowA, rowB) => {
3236
+ for (let i = 0; i < availableSorting.length; i += 1) {
3237
+ var _sortEntry$desc;
3238
+ const sortEntry = availableSorting[i];
3239
+ const columnInfo = columnInfoById[sortEntry.id];
3240
+ const sortUndefined = columnInfo.sortUndefined;
3241
+ const isDesc = (_sortEntry$desc = sortEntry == null ? void 0 : sortEntry.desc) != null ? _sortEntry$desc : false;
3242
+ let sortInt = 0;
3243
+
3244
+ // All sorting ints should always return in ascending order
3245
+ if (sortUndefined) {
3246
+ const aValue = rowA.getValue(sortEntry.id);
3247
+ const bValue = rowB.getValue(sortEntry.id);
3248
+ const aUndefined = aValue === undefined;
3249
+ const bUndefined = bValue === undefined;
3250
+ if (aUndefined || bUndefined) {
3251
+ if (sortUndefined === 'first') return aUndefined ? -1 : 1;
3252
+ if (sortUndefined === 'last') return aUndefined ? 1 : -1;
3253
+ sortInt = aUndefined && bUndefined ? 0 : aUndefined ? sortUndefined : -sortUndefined;
3254
+ }
3255
+ }
3256
+ if (sortInt === 0) {
3257
+ sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
3258
+ }
3259
+
3260
+ // If sorting is non-zero, take care of desc and inversion
3261
+ if (sortInt !== 0) {
3262
+ if (isDesc) {
3263
+ sortInt *= -1;
3264
+ }
3265
+ if (columnInfo.invertSorting) {
3266
+ sortInt *= -1;
3267
+ }
3268
+ return sortInt;
3269
+ }
3270
+ }
3271
+ return rowA.index - rowB.index;
3272
+ });
3273
+
3274
+ // If there are sub-rows, sort them
3275
+ sortedData.forEach(row => {
3276
+ var _row$subRows;
3277
+ sortedFlatRows.push(row);
3278
+ if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
3279
+ row.subRows = sortData(row.subRows);
3280
+ }
3281
+ });
3282
+ return sortedData;
3283
+ };
3284
+ return {
3285
+ rows: sortData(rowModel.rows),
3286
+ flatRows: sortedFlatRows,
3287
+ rowsById: rowModel.rowsById
3288
+ };
3289
+ }, getMemoOptions(table.options, 'debugTable', 'getSortedRowModel', () => table._autoResetPageIndex()));
3290
+ }
3291
+
3205
3292
  /* eslint-disable @typescript-eslint/no-explicit-any */
3206
3293
  /**
3207
3294
  * Debounce function to prevent multiple calls in a short
@@ -3222,13 +3309,14 @@ function debounce(func, wait) {
3222
3309
  };
3223
3310
  }
3224
3311
 
3225
- const nvDatagridCss = "nv-datagrid{display:block}nv-datagrid .hidden{display:none}nv-datagrid table{border-collapse:collapse;border-color:inherit;text-indent:0;width:100%}nv-datagrid th{text-align:left;border-bottom:1px solid var(--components-datagrid-header-border);height:var(--spacing-12);padding:var(--spacing-3) var(--spacing-4);font-size:var(--font-size-md);font-weight:700;color:var(--components-datagrid-header-text)}nv-datagrid td{border-bottom:1px solid var(--components-datagrid-body-border);height:var(--spacing-12);max-height:var(--spacing-14);padding:var(--spacing-2) var(--spacing-4);font-size:var(--font-size-md);font-weight:400;color:var(--components-datagrid-body-text);white-space:nowrap;text-overflow:ellipsis}nv-datagrid tbody>tr:hover{background:var(--color-interaction-container-neutral-background-hover)}";
3312
+ const nvDatagridCss = "nv-datagrid{--nv-datagrid-border-default:var(\n --components-form-field-border-default\n );--nv-datagrid-border-hover:var(--components-form-field-border-hover);--nv-datagrid-border-focus:var(--components-form-field-border-default);--nv-datagrid-background-default:var(\n --components-form-field-background-default\n );--nv-datagrid-background-checked:var(\n --components-form-field-background-checked\n );--nv-datagrid-background-disabled:var(\n --components-form-field-background-disabled\n );--nv-datagrid-color-checked:var(\n --components-form-shape-foreground-default\n );--nv-datagrid-color-disabled:var(\n --components-form-shape-foreground-disabled\n );--nv-datagrid-outline-color:var(--color-focus-brand);display:block}nv-datagrid .hidden{display:none}nv-datagrid table{border-collapse:collapse;border-color:inherit;text-indent:0;width:100%}nv-datagrid th{text-align:left;border-bottom:1px solid var(--components-datagrid-header-border);height:var(--spacing-12);padding:var(--spacing-3) var(--spacing-4);font-size:var(--font-size-md);font-weight:700;color:var(--components-datagrid-header-text)}nv-datagrid td{border-bottom:1px solid var(--components-datagrid-body-border);height:var(--spacing-12);max-height:var(--spacing-14);padding:var(--spacing-2) var(--spacing-4);font-size:var(--font-size-md);font-weight:400;color:var(--components-datagrid-body-text);white-space:nowrap;text-overflow:ellipsis}nv-datagrid tbody>tr:hover{background:var(--color-interaction-container-neutral-background-hover)}nv-datagrid .cursor-pointer{cursor:pointer}nv-datagrid .select-none{-webkit-user-select:none;user-select:none}nv-datagrid .search-container{display:flex}nv-datagrid .checkbox-container{position:relative;color:var(--nv-datagrid-color-checked)}nv-datagrid .checkbox-container input[type=checkbox][readonly]{opacity:0.5}nv-datagrid .checkbox-container:has(input[type=checkbox]:disabled:not([readonly])){color:var(--nv-datagrid-color-disabled)}nv-datagrid .checkbox-container input[type=checkbox]{appearance:none;position:relative;display:flex;width:var(--form-checkbox-size);height:var(--form-checkbox-size);flex-direction:column;align-items:flex-start;border-radius:var(--form-checkbox-radius);border-width:var(--form-checkbox-border-width);border-style:solid;border-color:var(--nv-datagrid-border-default);background:var(--nv-datagrid-background-default)}nv-datagrid .checkbox-container input[type=checkbox]:hover{border-color:var(--nv-datagrid-border-hover)}nv-datagrid .checkbox-container input[type=checkbox]:focus{border-color:var(--nv-datagrid-border-focus)}nv-datagrid .checkbox-container input[type=checkbox]:focus,nv-datagrid .checkbox-container input[type=checkbox]:focus-within{outline:none}nv-datagrid .checkbox-container input[type=checkbox]:focus-visible,nv-datagrid .checkbox-container input[type=checkbox]:has(:focus-visible){outline:calc(var(--focus-outline-stroke) * 1) solid var(--nv-datagrid-outline-color);outline-offset:calc(var(--focus-outline-offset) * 1)}nv-datagrid .checkbox-container input[type=checkbox]:checked,nv-datagrid .checkbox-container input[type=checkbox]:indeterminate{background:var(--nv-datagrid-background-checked);border-color:var(--nv-datagrid-background-checked)}nv-datagrid .checkbox-container input[type=checkbox]:disabled:not([readonly]){background:var(--nv-datagrid-background-disabled);border-color:var(--nv-datagrid-border-default)}nv-datagrid .checkbox-container input[type=checkbox][readonly]{opacity:0.5}nv-datagrid .checkbox-container .icon{pointer-events:none;position:absolute;top:0;left:0;width:100%;height:100%;display:flex;justify-content:center;align-items:center}nv-datagrid .checkbox-container .icon svg{width:var(--form-checkbox-icon-size);height:var(--form-checkbox-icon-size);fill:none;stroke:currentcolor;stroke-width:var(--form-checkbox-icon-stroke);flex-shrink:0}";
3226
3313
  const NvDatagridStyle0 = nvDatagridCss;
3227
3314
 
3228
3315
  const NvDatagrid = class {
3229
3316
  constructor(hostRef) {
3230
3317
  index.registerInstance(this, hostRef);
3231
3318
  this.action = index.createEvent(this, "action");
3319
+ this.selectedRows = index.createEvent(this, "selectedRows");
3232
3320
  this.templateCache = new Map();
3233
3321
  this.headerTemplateCache = new Map();
3234
3322
  this.minPageIndex = 1;
@@ -3240,6 +3328,8 @@ const NvDatagrid = class {
3240
3328
  this.globalFilterSearchTerm = '';
3241
3329
  this.columnData = [];
3242
3330
  this.paginationState = null;
3331
+ this.sorting = [];
3332
+ this.rowSelectionState = {};
3243
3333
  //#endregion STATES
3244
3334
  /****************************************************************************/
3245
3335
  //#region PROPERTIES
@@ -3275,6 +3365,12 @@ const NvDatagrid = class {
3275
3365
  * @default 'No data or columns available to display.'
3276
3366
  */
3277
3367
  this.noColumnsNoDataMessage = 'No data or columns available to display.';
3368
+ /**
3369
+ * Whether to automatically generate columns if none are provided.
3370
+ * If columns are explicitly set, this property is ignored.
3371
+ * @default false
3372
+ */
3373
+ this.autoGenerateColumns = false;
3278
3374
  /**
3279
3375
  * Whether to enable global filtering for the data grid.
3280
3376
  * This allows users to search across all columns for a specific value.
@@ -3284,11 +3380,9 @@ const NvDatagrid = class {
3284
3380
  */
3285
3381
  this.enableGlobalFilter = false;
3286
3382
  /**
3287
- * Whether to automatically generate columns if none are provided.
3288
- * If columns are explicitly set, this property is ignored.
3289
- * @default false
3383
+ * Position the global filter input field
3290
3384
  */
3291
- this.autoGenerateColumns = false;
3385
+ this.globalFilterPosition = 'end';
3292
3386
  /**
3293
3387
  * Whether to enable pagination for the data grid.
3294
3388
  * @default false
@@ -3296,6 +3390,7 @@ const NvDatagrid = class {
3296
3390
  this.enablePagination = false;
3297
3391
  /**
3298
3392
  * The number of rows to display per page.
3393
+ * If the number is not present in the property pageSizes it takes the first of the list.
3299
3394
  * @default 10
3300
3395
  */
3301
3396
  this.pageSize = 10;
@@ -3304,6 +3399,15 @@ const NvDatagrid = class {
3304
3399
  * @default [10, 20, 30, 40, 50]
3305
3400
  */
3306
3401
  this.pageSizes = [10, 20, 30, 40, 50];
3402
+ /**
3403
+ * Whether to enable sorting for the data grid.
3404
+ * @default false
3405
+ */
3406
+ this.enableSorting = false;
3407
+ /**
3408
+ * Whether to enable row selection for the data grid.
3409
+ */
3410
+ this.enableRowSelection = false;
3307
3411
  this.debouncedFilter = debounce((value) => {
3308
3412
  var _a;
3309
3413
  (_a = this.table) === null || _a === void 0 ? void 0 : _a.setGlobalFilter(value);
@@ -3336,8 +3440,32 @@ const NvDatagrid = class {
3336
3440
  };
3337
3441
  this.handlePageSizeChange = (event) => {
3338
3442
  const target = event.target;
3443
+ let effectivePageSize = Number(target.value);
3444
+ if (!this.pageSizes.includes(effectivePageSize) && this.pageSizes) {
3445
+ effectivePageSize = this.pageSizes[0];
3446
+ }
3339
3447
  // Simply use `setPageSize` to update the page size directly
3340
- this.paginationState = Object.assign(Object.assign({}, this.paginationState), { pageSize: Number(target.value) }); // This triggers the paginationState watcher
3448
+ this.paginationState = Object.assign(Object.assign({}, this.paginationState), { pageSize: effectivePageSize }); // This triggers the paginationState watcher
3449
+ };
3450
+ this.handleSortingClick = (event, header) => {
3451
+ var _a;
3452
+ if (!header.column.getCanSort()) {
3453
+ return;
3454
+ }
3455
+ (_a = header.column.getToggleSortingHandler()) === null || _a === void 0 ? void 0 : _a(event);
3456
+ };
3457
+ this.getSortTitle = (header) => {
3458
+ if (!header.column.getCanSort())
3459
+ return;
3460
+ const nextOrder = header.column.getNextSortingOrder();
3461
+ switch (nextOrder) {
3462
+ case constantsB97e736d.SortingPossibility.Asc:
3463
+ return 'Sort ascending';
3464
+ case constantsB97e736d.SortingPossibility.Desc:
3465
+ return 'Sort descending';
3466
+ default:
3467
+ return 'Clear sort';
3468
+ }
3341
3469
  };
3342
3470
  }
3343
3471
  //#endregion PROPERTIES
@@ -3528,9 +3656,14 @@ const NvDatagrid = class {
3528
3656
  }
3529
3657
  if (this.enablePagination) {
3530
3658
  tableOptions.getPaginationRowModel = getPaginationRowModel();
3659
+ const pageIndex = (_b = (_a = this.paginationState) === null || _a === void 0 ? void 0 : _a.pageIndex) !== null && _b !== void 0 ? _b : 0;
3660
+ let effectivePageSize = (_d = (_c = this.paginationState) === null || _c === void 0 ? void 0 : _c.pageSize) !== null && _d !== void 0 ? _d : 10;
3661
+ if (!this.pageSizes.includes(effectivePageSize) && this.pageSizes) {
3662
+ effectivePageSize = this.pageSizes[0];
3663
+ }
3531
3664
  const pagination = {
3532
- pageIndex: (_b = (_a = this.paginationState) === null || _a === void 0 ? void 0 : _a.pageIndex) !== null && _b !== void 0 ? _b : 0,
3533
- pageSize: (_d = (_c = this.paginationState) === null || _c === void 0 ? void 0 : _c.pageSize) !== null && _d !== void 0 ? _d : 10,
3665
+ pageIndex: pageIndex,
3666
+ pageSize: effectivePageSize,
3534
3667
  };
3535
3668
  // Set the initial pagination value with safeguards
3536
3669
  tableOptions.state.pagination = pagination;
@@ -3541,6 +3674,33 @@ const NvDatagrid = class {
3541
3674
  this.paginationState = newPagination;
3542
3675
  };
3543
3676
  }
3677
+ if (this.enableSorting) {
3678
+ tableOptions.getSortedRowModel = getSortedRowModel();
3679
+ tableOptions.enableSorting = this.enableSorting;
3680
+ tableOptions.state.sorting = this.sorting;
3681
+ tableOptions.onSortingChange = updater => {
3682
+ const newSorting = typeof updater === 'function' ? updater(this.sorting) : updater;
3683
+ this.sorting = newSorting; // Will automatically trigger the searchTerm watcher and update the table
3684
+ };
3685
+ }
3686
+ if (this.enableRowSelection) {
3687
+ tableOptions.state.rowSelection = this.rowSelectionState;
3688
+ tableOptions.onRowSelectionChange = updater => {
3689
+ const newRowSelectionState = typeof updater === 'function'
3690
+ ? updater(this.rowSelectionState)
3691
+ : updater;
3692
+ this.rowSelectionState = newRowSelectionState;
3693
+ // Emit the original rows instead of IDs
3694
+ const selectedRows = Object.keys(newRowSelectionState)
3695
+ .filter(rowId => newRowSelectionState[rowId])
3696
+ .map(rowId => {
3697
+ // Assuming rowId corresponds to the index in parsedData
3698
+ const index = parseInt(rowId, 10); // Convert rowId to an integer index
3699
+ return this.parsedData[index]; // Get the original row data
3700
+ });
3701
+ this.selectedRows.emit(selectedRows); // Emit the original rows
3702
+ };
3703
+ }
3544
3704
  // Initialize the table
3545
3705
  this.table = createTable(tableOptions);
3546
3706
  }
@@ -3575,14 +3735,67 @@ const NvDatagrid = class {
3575
3735
  };
3576
3736
  return checkValue(row.original);
3577
3737
  }
3738
+ createIconSpan(checked, indeterminate) {
3739
+ const span = document.createElement('span');
3740
+ span.className = 'icon';
3741
+ if (checked && !indeterminate) {
3742
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
3743
+ svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
3744
+ svg.setAttribute('width', '14');
3745
+ svg.setAttribute('height', '14');
3746
+ svg.setAttribute('viewBox', '0 0 14 14');
3747
+ svg.setAttribute('fill', 'none');
3748
+ const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
3749
+ path.setAttribute('d', 'M11.6667 3.5L5.25004 9.91667L2.33337 7');
3750
+ path.setAttribute('stroke-linecap', 'round');
3751
+ path.setAttribute('stroke-linejoin', 'round');
3752
+ svg.appendChild(path);
3753
+ span.appendChild(svg);
3754
+ }
3755
+ if (indeterminate) {
3756
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
3757
+ svg.classList.add('indeterminate-svg');
3758
+ svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
3759
+ svg.setAttribute('viewBox', '0 0 14 14');
3760
+ svg.setAttribute('fill', 'none');
3761
+ const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
3762
+ path.setAttribute('d', 'M2.9165 7H11.0832');
3763
+ path.setAttribute('stroke-linecap', 'round');
3764
+ path.setAttribute('stroke-linejoin', 'round');
3765
+ svg.appendChild(path);
3766
+ span.appendChild(svg);
3767
+ }
3768
+ return span;
3769
+ }
3770
+ createIndeterminateCheckbox(options = {}) {
3771
+ const { indeterminate, checked = false, disabled = false, className = '', onChange, } = options;
3772
+ const input = document.createElement('input');
3773
+ input.type = 'checkbox';
3774
+ input.checked = checked;
3775
+ input.disabled = disabled;
3776
+ input.className = `${className} cursor-pointer`.trim();
3777
+ if (typeof indeterminate === 'boolean') {
3778
+ input.indeterminate = !checked && indeterminate;
3779
+ }
3780
+ if (onChange) {
3781
+ input.addEventListener('change', onChange);
3782
+ }
3783
+ const iconSpan = this.createIconSpan(checked, indeterminate);
3784
+ const container = document.createElement('div');
3785
+ container.className = 'checkbox-container';
3786
+ container.appendChild(input);
3787
+ container.appendChild(iconSpan);
3788
+ return container;
3789
+ }
3578
3790
  // Helper function to generate column definitions
3579
3791
  generateColumns(validColumns, tableOptions) {
3792
+ let generatedColumns = [];
3580
3793
  const columnHelper = createColumnHelper();
3581
3794
  if (validColumns.length > 0) {
3582
3795
  // Use defined columns
3583
- return validColumns.map(column => {
3796
+ generatedColumns = validColumns.map(column => {
3584
3797
  var _a, _b;
3585
- return columnHelper.accessor(column.accessor, {
3798
+ const identifiedColumnDef = {
3586
3799
  header: (_b = (this.renderTemplate(this.headerTemplateCache.get(column.accessor), (_a = column.header) !== null && _a !== void 0 ? _a : column.accessor, null) ||
3587
3800
  column.header)) !== null && _b !== void 0 ? _b : column.accessor,
3588
3801
  cell: (info) => {
@@ -3600,35 +3813,81 @@ const NvDatagrid = class {
3600
3813
  value)) !== null && _b !== void 0 ? _b : value) !== null && _c !== void 0 ? _c : this.fallbackValue;
3601
3814
  },
3602
3815
  enableGlobalFilter: this.enableGlobalFilter,
3603
- });
3816
+ enableSorting: this.enableSorting,
3817
+ };
3818
+ if (this.enableSorting) {
3819
+ identifiedColumnDef.sortUndefined = 'last'; // Force undefined values to the end
3820
+ identifiedColumnDef.sortDescFirst = false; // First sort order will be ascending (nullable values can mess up auto detection of sort order)
3821
+ }
3822
+ return columnHelper.accessor(column.accessor, identifiedColumnDef);
3604
3823
  });
3605
3824
  }
3606
3825
  else if (tableOptions.data && tableOptions.data.length > 0) {
3607
3826
  // Generate columns from data keys
3608
3827
  const sampleRow = tableOptions.data[0];
3609
- return Object.keys(sampleRow).map(key => columnHelper.accessor(key, {
3610
- header: this.renderTemplate(this.headerTemplateCache.get(key), key.charAt(0).toUpperCase() + key.slice(1), null) || key.charAt(0).toUpperCase() + key.slice(1), // Capitalize key for header
3611
- cell: (info) => {
3612
- var _a, _b, _c;
3613
- const value = info.getValue();
3614
- const cellAccessors = key;
3615
- const row = info.row;
3616
- return ((_a = this.columnData.find(x => x.accessor === cellAccessors)) === null || _a === void 0 ? void 0 : _a.repeatTemplate) && Array.isArray(value)
3617
- ? value.map((item) => {
3618
- var _a, _b;
3619
- return (_b = (_a = (this.renderTemplate(this.templateCache.get(cellAccessors), item, row) ||
3620
- item)) !== null && _a !== void 0 ? _a : value) !== null && _b !== void 0 ? _b : this.fallbackValue;
3621
- })
3622
- : (_c = (_b = (this.renderTemplate(this.templateCache.get(cellAccessors), value, row) ||
3623
- value)) !== null && _b !== void 0 ? _b : value) !== null && _c !== void 0 ? _c : this.fallbackValue;
3624
- },
3625
- enableGlobalFilter: this.enableGlobalFilter,
3626
- }));
3828
+ generatedColumns = Object.keys(sampleRow).map(key => {
3829
+ const identifiedColumnDef = {
3830
+ header: this.renderTemplate(this.headerTemplateCache.get(key), key.charAt(0).toUpperCase() + key.slice(1), null) || key.charAt(0).toUpperCase() + key.slice(1), // Capitalize key for header
3831
+ cell: (info) => {
3832
+ var _a, _b, _c;
3833
+ const value = info.getValue();
3834
+ const cellAccessors = key;
3835
+ const row = info.row;
3836
+ return ((_a = this.columnData.find(x => x.accessor === cellAccessors)) === null || _a === void 0 ? void 0 : _a.repeatTemplate) && Array.isArray(value)
3837
+ ? value.map((item) => {
3838
+ var _a, _b;
3839
+ return (_b = (_a = (this.renderTemplate(this.templateCache.get(cellAccessors), item, row) ||
3840
+ item)) !== null && _a !== void 0 ? _a : value) !== null && _b !== void 0 ? _b : this.fallbackValue;
3841
+ })
3842
+ : (_c = (_b = (this.renderTemplate(this.templateCache.get(cellAccessors), value, row) ||
3843
+ value)) !== null && _b !== void 0 ? _b : value) !== null && _c !== void 0 ? _c : this.fallbackValue;
3844
+ },
3845
+ enableGlobalFilter: this.enableGlobalFilter,
3846
+ enableSorting: this.enableSorting,
3847
+ };
3848
+ if (this.enableSorting) {
3849
+ identifiedColumnDef.sortUndefined = 'last'; // Force undefined values to the end
3850
+ identifiedColumnDef.sortDescFirst = false; // First sort order will be ascending (nullable values can mess up auto detection of sort order)
3851
+ }
3852
+ return columnHelper.accessor(key, identifiedColumnDef);
3853
+ });
3627
3854
  }
3628
- else {
3629
- // No columns and no data
3630
- return [];
3855
+ else ;
3856
+ if (this.enableRowSelection) {
3857
+ const rowSelection = columnHelper.accessor('select', {
3858
+ header: ({ table }) => {
3859
+ return (index.h("div", { class: "flex px-1", ref: el => {
3860
+ const checkbox = this.createIndeterminateCheckbox({
3861
+ checked: table === null || table === void 0 ? void 0 : table.getIsAllRowsSelected(),
3862
+ indeterminate: table === null || table === void 0 ? void 0 : table.getIsSomeRowsSelected(),
3863
+ onChange: table === null || table === void 0 ? void 0 : table.getToggleAllRowsSelectedHandler(),
3864
+ });
3865
+ if (el) {
3866
+ el.innerHTML = ''; // Remove existing content
3867
+ el.appendChild(checkbox); // Append new checkbox
3868
+ }
3869
+ } }));
3870
+ },
3871
+ cell: ({ row }) => {
3872
+ return (index.h("div", { class: "flex px-1", ref: el => {
3873
+ const checkbox = this.createIndeterminateCheckbox({
3874
+ checked: row === null || row === void 0 ? void 0 : row.getIsSelected(),
3875
+ disabled: !(row === null || row === void 0 ? void 0 : row.getCanSelect()),
3876
+ indeterminate: row === null || row === void 0 ? void 0 : row.getIsSomeSelected(),
3877
+ onChange: row === null || row === void 0 ? void 0 : row.getToggleSelectedHandler(),
3878
+ });
3879
+ if (el) {
3880
+ el.innerHTML = ''; // Remove existing content
3881
+ el.appendChild(checkbox); // Append new checkbox
3882
+ }
3883
+ } }));
3884
+ },
3885
+ enableGlobalFilter: false,
3886
+ enableSorting: false,
3887
+ });
3888
+ generatedColumns = [rowSelection, ...generatedColumns];
3631
3889
  }
3890
+ return generatedColumns;
3632
3891
  }
3633
3892
  getTableData() {
3634
3893
  if (this.parsedData &&
@@ -3876,6 +4135,46 @@ const NvDatagrid = class {
3876
4135
  });
3877
4136
  }
3878
4137
  }
4138
+ getArrowSorting(header) {
4139
+ if (!header.column.getCanSort())
4140
+ return null;
4141
+ const sortState = header.column.getIsSorted();
4142
+ if (sortState === constantsB97e736d.SortingPossibility.Asc) {
4143
+ return (index.h("div", { class: "inline-flex align-middle" }, index.h("nv-icon", { name: "arrow-up" })));
4144
+ }
4145
+ if (sortState === constantsB97e736d.SortingPossibility.Desc) {
4146
+ return (index.h("div", { class: "inline-flex align-middle" }, index.h("nv-icon", { name: "arrow-down" })));
4147
+ }
4148
+ return null;
4149
+ }
4150
+ getHeaderCell(header) {
4151
+ const isSortable = header.column.getCanSort();
4152
+ const sortTitle = this.getSortTitle(header);
4153
+ const content = header.isPlaceholder
4154
+ ? null
4155
+ : header.column.columnDef.header
4156
+ ? this.flexRender(header.column.columnDef.header, header.getContext())
4157
+ : null; // Ensure content is not null
4158
+ const sortIcon = this.getArrowSorting(header);
4159
+ const handleClick = this.createSortingClickHandler(header);
4160
+ if (this.enableRowSelection) {
4161
+ return (index.h("th", { key: header.id }, content, " "));
4162
+ }
4163
+ const returnHtml = (index.h("th", { key: header.id }, index.h("button", { type: "button", class: isSortable
4164
+ ? 'w-full text-left cursor-pointer select-none bg-transparent border-none p-0 m-0 focus:outline-none'
4165
+ : 'w-full text-left bg-transparent border-none p-0 m-0 cursor-default', onClick: handleClick, title: sortTitle }, index.h("span", { class: "inline-flex items-center gap-1" }, content, sortIcon))));
4166
+ return returnHtml;
4167
+ }
4168
+ // 👇 Helper method to avoid arrow function in JSX
4169
+ createSortingClickHandler(header) {
4170
+ return (e) => {
4171
+ this.handleSortingClick(e, header);
4172
+ };
4173
+ }
4174
+ getPagination() {
4175
+ var _a;
4176
+ return (this.enablePagination && (index.h("div", { class: "flex items-center gap-2" }, index.h("button", { class: "border rounded p-1", disabled: !this.table.getCanPreviousPage(), onClick: this.table.firstPage }, "<<"), index.h("button", { class: "border rounded p-1", disabled: !this.table.getCanPreviousPage(), onClick: this.table.previousPage }, "<"), index.h("button", { class: "border rounded p-1", disabled: !this.table.getCanNextPage(), onClick: this.table.nextPage }, ">"), index.h("button", { class: "border rounded p-1", disabled: !this.table.getCanNextPage(), onClick: this.table.lastPage }, ">>"), index.h("span", { class: "flex items-center gap-1" }, index.h("div", null, "Page"), index.h("strong", null, this.table.getState().pagination.pageIndex + 1, " of", ' ', this.table.getPageCount().toLocaleString())), index.h("span", { class: "flex items-center gap-1" }, "| Go to page:", ' ', index.h("input", { type: "number", min: this.minPageIndex, max: this.table.getPageCount(), value: this.table.getState().pagination.pageIndex + 1, class: "border p-1 rounded w-16", "aria-label": "Go to page", onInput: this.handlePageIndexChange })), ((_a = this.pageSizes) === null || _a === void 0 ? void 0 : _a.length) > 0 && (index.h("select", { "aria-label": "Rows per page", onChange: this.handlePageSizeChange }, this.pageSizes.map(pageSize => (index.h("option", { value: String(pageSize), selected: this.table.getState().pagination.pageSize === pageSize }, "Show ", pageSize))))))));
4177
+ }
3879
4178
  //#endregion METHODS
3880
4179
  /****************************************************************************/
3881
4180
  //#region WATCHERS
@@ -3933,6 +4232,39 @@ const NvDatagrid = class {
3933
4232
  this.table.options.state.pagination = newValue;
3934
4233
  }
3935
4234
  }
4235
+ handleSorting(newValue) {
4236
+ if (!this.table) {
4237
+ console.warn('Table is not initialized yet.');
4238
+ return;
4239
+ }
4240
+ // Not working
4241
+ /*// Set the sorting for the table
4242
+ this.table.setSorting(newValue);*/
4243
+ // Manually update the sorting state
4244
+ this.table.options.state.sorting = newValue;
4245
+ }
4246
+ handlePageSize(newValue) {
4247
+ let effectivePageSize = newValue;
4248
+ if (!this.pageSizes.includes(effectivePageSize) && this.pageSizes) {
4249
+ effectivePageSize = this.pageSizes[0];
4250
+ }
4251
+ // Simply use `setPageSize` to update the page size directly
4252
+ this.paginationState = Object.assign(Object.assign({}, this.paginationState), { pageSize: effectivePageSize }); // This triggers the paginationState watcher
4253
+ }
4254
+ handleRowSelectionState(newValue, oldValue) {
4255
+ if (!this.table) {
4256
+ console.warn('Table is not initialized yet.');
4257
+ return;
4258
+ }
4259
+ // Only update if there is a meaningful change
4260
+ if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
4261
+ // Not working
4262
+ /*// Set the rowSelection for the table
4263
+ this.table.setRowSelection(newValue);*/
4264
+ // Manually update the row selection state
4265
+ this.table.options.state.rowSelection = newValue;
4266
+ }
4267
+ }
3936
4268
  //#endregion WATCHERS
3937
4269
  /****************************************************************************/
3938
4270
  //#region LIFECYCLE
@@ -3942,7 +4274,10 @@ const NvDatagrid = class {
3942
4274
  this.initializeTable();
3943
4275
  if (this.enablePagination) {
3944
4276
  // Ensure a valid page size
3945
- const effectivePageSize = this.pageSize > 0 ? this.pageSize : 10;
4277
+ let effectivePageSize = this.pageSize > 0 ? this.pageSize : 10;
4278
+ if (!this.pageSizes.includes(effectivePageSize) && this.pageSizes) {
4279
+ effectivePageSize = this.pageSizes[0];
4280
+ }
3946
4281
  this.paginationState = {
3947
4282
  pageIndex: Math.max(0, this.minPageIndex - 1),
3948
4283
  pageSize: effectivePageSize,
@@ -3960,11 +4295,9 @@ const NvDatagrid = class {
3960
4295
  const rows = !this.table || this.table === undefined || this.parsedData.length === 0
3961
4296
  ? []
3962
4297
  : (_c = (_b = this.table) === null || _b === void 0 ? void 0 : _b.getRowModel()) === null || _c === void 0 ? void 0 : _c.rows;
3963
- return (index.h(index.Host, { key: 'b3886397a5e6694611636d4da7d61ae5ccbe1903' }, index.h("div", { key: '8fa71d83f4cfa79cf7fb334bcf6115e4cf253c5d', class: "hidden" }, index.h("slot", { key: '9aad5956b5973cafc486f3a854a66ae86038ef4a' })), index.h("slot", { key: '7a1ca93223567faffabb3473df2176cd02654247', name: "before" }), this.enableGlobalFilter && this.table && (index.h("div", { key: '0020880c229d8ed9070c15182191e86b8b3fed1d', class: "search-container" }, index.h("input", { key: 'cefc47330a7d770c3668d1406930b9ac50992a10', type: "text", value: (_d = this.globalFilterSearchTerm) !== null && _d !== void 0 ? _d : '', onInput: this.handleGlobalFilteringOnInput, placeholder: "Search all columns...", class: "search-input", "aria-label": "Search all columns" }))), this.parsedColumns.length === 0 && this.parsedData.length === 0 ? (index.h("div", { class: "no-data" }, this.noColumnsNoDataMessage)) : (index.h("div", null, index.h("table", null, this.parsedColumns.length > 0 && headerGroups.length > 0 && (index.h("thead", null, this.parsedColumns.length > 0 && headerGroups
4298
+ return (index.h(index.Host, { key: '7ed48645de6272bb3fed7897406e2a798021bba2' }, index.h("div", { key: '4ae6135c7ca302e06c3d26509dbf813128631a2e', class: "hidden" }, index.h("slot", { key: '3f8078b877a4e2ebe46842fc3a52d7059cb3cc68' })), index.h("slot", { key: 'c97cb30a0ce80dc8c25c2b855eb6086937dbe76b', name: "before" }), this.enableGlobalFilter && this.table && (index.h("div", { key: '68cd75ed6ecad3de049797ebfe7787f5a0b357fa', class: `search-container justify-${this.globalFilterPosition}` }, index.h("nv-fieldtext", { key: '80b4f8b50c3dda39555597a44707f3a296fbb8e6', value: this.globalFilterSearchTerm, onInput: this.handleGlobalFilteringOnInput, placeholder: "Search all columns..." }))), this.parsedColumns.length === 0 && this.parsedData.length === 0 ? (index.h("div", { class: "no-data" }, this.noColumnsNoDataMessage)) : (index.h("div", null, index.h("table", null, this.parsedColumns.length > 0 && headerGroups.length > 0 && (index.h("thead", null, this.parsedColumns.length > 0 && headerGroups
3964
4299
  ? headerGroups === null || headerGroups === void 0 ? void 0 : headerGroups.map(headerGroup => (index.h("tr", { key: headerGroup.id }, headerGroup.headers.map(header => {
3965
- return (index.h("th", { key: header.id }, header.isPlaceholder
3966
- ? null
3967
- : this.flexRender(header.column.columnDef.header, header.getContext())));
4300
+ return this.getHeaderCell(header);
3968
4301
  }))))
3969
4302
  : null)), index.h("tbody", null, !rows || rows.length === 0 || this.parsedData.length === 0 ? (index.h("tr", null, index.h("td", { colSpan: this.parsedColumns.length || 12, class: "no-data" }, this.noDataMessage))) : (rows.map(row => {
3970
4303
  const rowId = row.id;
@@ -3972,7 +4305,8 @@ const NvDatagrid = class {
3972
4305
  return (index.h("tr", { key: rowId }, visibleCells.map(cell => {
3973
4306
  return (index.h("td", { key: cell.id, "data-row-id": rowId }, this.flexRender(cell.column.columnDef.cell, cell.getContext())));
3974
4307
  })));
3975
- })))), this.enablePagination && (index.h("div", { class: "flex items-center gap-2" }, index.h("button", { class: "border rounded p-1", disabled: !this.table.getCanPreviousPage(), onClick: this.table.firstPage }, "<<"), index.h("button", { class: "border rounded p-1", disabled: !this.table.getCanPreviousPage(), onClick: this.table.previousPage }, "<"), index.h("button", { class: "border rounded p-1", disabled: !this.table.getCanNextPage(), onClick: this.table.nextPage }, ">"), index.h("button", { class: "border rounded p-1", disabled: !this.table.getCanNextPage(), onClick: this.table.lastPage }, ">>"), index.h("span", { class: "flex items-center gap-1" }, index.h("div", null, "Page"), index.h("strong", null, this.table.getState().pagination.pageIndex + 1, " of", ' ', this.table.getPageCount().toLocaleString())), index.h("span", { class: "flex items-center gap-1" }, "| Go to page:", ' ', index.h("input", { type: "number", min: this.minPageIndex, max: this.table.getPageCount(), value: this.table.getState().pagination.pageIndex + 1, class: "border p-1 rounded w-16", "aria-label": "Go to page", onInput: this.handlePageIndexChange })), (_e = this.pageSizes) !== null && _e !== void 0 ? _e : (index.h("select", { "aria-label": "Rows per page", onChange: this.handlePageSizeChange }, this.pageSizes.map(pageSize => (index.h("option", { value: String(pageSize), selected: this.table.getState().pagination.pageSize === pageSize }, "Show ", pageSize))))))))), index.h("slot", { key: '2030fdc2b38a293e749f2ffd4645987e834fee76', name: "after" })));
4308
+ }))), this.table && this.enableRowSelection ? (index.h("tfoot", null, index.h("tr", null, index.h("td", { colSpan: 20 }, this.enableRowSelection && this.table ? (index.h("div", null, this.rowSelectionState &&
4309
+ Object.keys(this.rowSelectionState).length > 0 ? (index.h("span", null, Object.keys(this.rowSelectionState).length, " of", ' ', ((_e = (_d = this.table.getPreFilteredRowModel()) === null || _d === void 0 ? void 0 : _d.rows) === null || _e === void 0 ? void 0 : _e.length) || 0, ' ', "Total Rows Selected")) : (index.h("span", null, "No rows selected")))) : null)))) : null), this.getPagination())), index.h("slot", { key: 'f7209e67ff423310bb4b59b866f486ade897781a', name: "after" })));
3976
4310
  }
3977
4311
  get el() { return index.getElement(this); }
3978
4312
  static get watchers() { return {
@@ -3983,7 +4317,10 @@ const NvDatagrid = class {
3983
4317
  "parsedColumns": ["handleParsedChange"],
3984
4318
  "parsedData": ["handleParsedChange"],
3985
4319
  "globalFilterSearchTerm": ["handleGlobalFilterSearchTerm"],
3986
- "paginationState": ["handlePaginationState"]
4320
+ "paginationState": ["handlePaginationState"],
4321
+ "sorting": ["handleSorting"],
4322
+ "pageSize": ["handlePageSize"],
4323
+ "rowSelectionState": ["handleRowSelectionState"]
3987
4324
  }; }
3988
4325
  };
3989
4326
  NvDatagrid.style = NvDatagridStyle0;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-Byv3Vmev.js');
3
+ var index = require('./index-Cn-oNJnW.js');
4
4
  require('react');
5
5
 
6
6
  const NvDatagridcolumn = class {