@nova-design-system/nova-react 3.0.0-beta.45 → 3.0.0-beta.47

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 (43) hide show
  1. package/dist/cjs/{index-S09Gr7Tw.js → index-Byv3Vmev.js} +654 -526
  2. package/dist/cjs/index.js +1 -2
  3. package/dist/cjs/{nv-alert.entry-DH8Qd2s2.js → nv-alert.entry-BXY4KXbF.js} +1 -1
  4. package/dist/cjs/{nv-avatar.entry-B3-elLZC.js → nv-avatar.entry-BnPSKkJJ.js} +1 -1
  5. package/dist/cjs/{nv-badge_2.entry-D15EDzX0.js → nv-badge_2.entry-BsI3B8Rr.js} +5 -5
  6. package/dist/cjs/{nv-breadcrumb.entry-DG49Nj1L.js → nv-breadcrumb.entry-D5vGHLOG.js} +2 -2
  7. package/dist/cjs/{nv-breadcrumbs.entry-BqJO5pbN.js → nv-breadcrumbs.entry-CsaqAsnb.js} +2 -2
  8. package/dist/cjs/{nv-button.entry-CN9kB98T.js → nv-button.entry-DzZfGZGy.js} +2 -2
  9. package/dist/cjs/{nv-calendar.entry-CMEgSU64.js → nv-calendar.entry-CGKv_-gO.js} +49 -20
  10. package/dist/cjs/{nv-col.entry-wcZ9HHAb.js → nv-col.entry-Cng8NaTW.js} +2 -2
  11. package/dist/cjs/{nv-datagrid.entry-GCLeN2qT.js → nv-datagrid.entry-BbAOzpiO.js} +379 -86
  12. package/dist/cjs/nv-datagridcolumn.entry-CRogHbVM.js +22 -0
  13. package/dist/cjs/{nv-dialog.entry-DfY0TaYp.js → nv-dialog.entry-BSIZGYGF.js} +2 -2
  14. package/dist/cjs/{nv-dialogfooter_2.entry-OByWsulH.js → nv-dialogfooter_2.entry-Q4_li_QU.js} +3 -3
  15. package/dist/cjs/{nv-fieldcheckbox.entry-Bqpe9BK3.js → nv-fieldcheckbox.entry-DmgzfmRd.js} +5 -5
  16. package/dist/cjs/{nv-fielddate.entry-DJePv6tR.js → nv-fielddate.entry-qAvLX_Ru.js} +6 -6
  17. package/dist/cjs/{nv-fielddaterange.entry--YC750sX.js → nv-fielddaterange.entry-DVB8Rwxk.js} +5 -5
  18. package/dist/cjs/{nv-fielddropdown.entry-BPlTlc_S.js → nv-fielddropdown.entry-DKXmoXeW.js} +16 -36
  19. package/dist/cjs/{nv-fielddropdownitem.entry-zwoGySum.js → nv-fielddropdownitem.entry-BVLVXi0e.js} +2 -2
  20. package/dist/cjs/{nv-fieldmultiselect.entry-Bg_v0LUF.js → nv-fieldmultiselect.entry-DrTbd3Dj.js} +31 -87
  21. package/dist/cjs/{nv-fieldnumber.entry-BLNaq7yr.js → nv-fieldnumber.entry-DegbEHRL.js} +4 -4
  22. package/dist/cjs/{nv-fieldpassword.entry-iSEdS5R8.js → nv-fieldpassword.entry-gqjlEl7a.js} +10 -8
  23. package/dist/cjs/{nv-fieldradio.entry-Dov4vZkh.js → nv-fieldradio.entry-CVEY4v6F.js} +4 -4
  24. package/dist/cjs/{nv-fieldselect.entry-NmpesarX.js → nv-fieldselect.entry-BrCUuRWa.js} +6 -6
  25. package/dist/cjs/{nv-fieldtext.entry-r6oQajRS.js → nv-fieldtext.entry-q9NnqL5c.js} +4 -4
  26. package/dist/cjs/{nv-fieldtextarea.entry-CJ2yQkfi.js → nv-fieldtextarea.entry-B4qiLmX1.js} +4 -4
  27. package/dist/cjs/{nv-fieldtime.entry-Bxoj6N53.js → nv-fieldtime.entry-Bp2IWjhN.js} +10 -10
  28. package/dist/cjs/{nv-icon.entry-CWKRt8F0.js → nv-icon.entry-B1ax9cJS.js} +2 -2
  29. package/dist/cjs/{nv-iconbutton_2.entry-CnbscpNn.js → nv-iconbutton_2.entry-BRPAGl2S.js} +3 -3
  30. package/dist/cjs/{nv-menu.entry-wC7oSruP.js → nv-menu.entry-BiWiIZAm.js} +19 -45
  31. package/dist/cjs/{nv-menuitem.entry-BVSa1vrS.js → nv-menuitem.entry-CFkXoZ_r.js} +2 -2
  32. package/dist/cjs/{nv-popover.entry-ChP1we3l.js → nv-popover.entry-KT1iQUJk.js} +2 -2
  33. package/dist/cjs/{nv-row.entry-D6FeFpzG.js → nv-row.entry-Cs2GDrcu.js} +2 -2
  34. package/dist/cjs/{nv-stack.entry-zjJmztkO.js → nv-stack.entry-Ci7pxGSo.js} +2 -2
  35. package/dist/cjs/{nv-table.entry-CGX0jsR3.js → nv-table.entry-N4MV8Y6E.js} +3 -3
  36. package/dist/cjs/{nv-tablecolumn.entry-Cwdmo_RY.js → nv-tablecolumn.entry-CTz4jsZl.js} +1 -1
  37. package/dist/cjs/{nv-toggle.entry-BvToMkI2.js → nv-toggle.entry-m10-ncYR.js} +3 -3
  38. package/dist/cjs/{nv-tooltip.entry-DZ7_lB-p.js → nv-tooltip.entry-B6aRDto3.js} +2 -2
  39. package/dist/generated/components.js +0 -8
  40. package/dist/types/generated/components.d.ts +0 -3
  41. package/package.json +1 -1
  42. package/dist/cjs/nv-base.entry-D-_RUZTX.js +0 -71
  43. package/dist/cjs/nv-datagridcolumn.entry-lgIz71UU.js +0 -18
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-S09Gr7Tw.js');
3
+ var index = require('./index-Byv3Vmev.js');
4
4
  var dom_utilsAc71e0ef = require('./dom.utils-ac71e0ef-CmIwRr6O.js');
5
5
  require('react');
6
6
 
@@ -2956,6 +2956,22 @@ function getCoreRowModel() {
2956
2956
  return rowModel;
2957
2957
  }, getMemoOptions(table.options, 'debugTable', 'getRowModel', () => table._autoResetPageIndex()));
2958
2958
  }
2959
+ function expandRows(rowModel) {
2960
+ const expandedRows = [];
2961
+ const handleRow = row => {
2962
+ var _row$subRows;
2963
+ expandedRows.push(row);
2964
+ if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
2965
+ row.subRows.forEach(handleRow);
2966
+ }
2967
+ };
2968
+ rowModel.rows.forEach(handleRow);
2969
+ return {
2970
+ rows: expandedRows,
2971
+ flatRows: rowModel.flatRows,
2972
+ rowsById: rowModel.rowsById
2973
+ };
2974
+ }
2959
2975
 
2960
2976
  function filterRows(rows, filterRowImpl, table) {
2961
2977
  if (table.options.filterFromLeafRows) {
@@ -3143,6 +3159,49 @@ function getFilteredRowModel() {
3143
3159
  }, getMemoOptions(table.options, 'debugTable', 'getFilteredRowModel', () => table._autoResetPageIndex()));
3144
3160
  }
3145
3161
 
3162
+ function getPaginationRowModel(opts) {
3163
+ return table => memo(() => [table.getState().pagination, table.getPrePaginationRowModel(), table.options.paginateExpandedRows ? undefined : table.getState().expanded], (pagination, rowModel) => {
3164
+ if (!rowModel.rows.length) {
3165
+ return rowModel;
3166
+ }
3167
+ const {
3168
+ pageSize,
3169
+ pageIndex
3170
+ } = pagination;
3171
+ let {
3172
+ rows,
3173
+ flatRows,
3174
+ rowsById
3175
+ } = rowModel;
3176
+ const pageStart = pageSize * pageIndex;
3177
+ const pageEnd = pageStart + pageSize;
3178
+ rows = rows.slice(pageStart, pageEnd);
3179
+ let paginatedRowModel;
3180
+ if (!table.options.paginateExpandedRows) {
3181
+ paginatedRowModel = expandRows({
3182
+ rows,
3183
+ flatRows,
3184
+ rowsById
3185
+ });
3186
+ } else {
3187
+ paginatedRowModel = {
3188
+ rows,
3189
+ flatRows,
3190
+ rowsById
3191
+ };
3192
+ }
3193
+ paginatedRowModel.flatRows = [];
3194
+ const handleRow = row => {
3195
+ paginatedRowModel.flatRows.push(row);
3196
+ if (row.subRows.length) {
3197
+ row.subRows.forEach(handleRow);
3198
+ }
3199
+ };
3200
+ paginatedRowModel.rows.forEach(handleRow);
3201
+ return paginatedRowModel;
3202
+ }, getMemoOptions(table.options, 'debugTable'));
3203
+ }
3204
+
3146
3205
  /* eslint-disable @typescript-eslint/no-explicit-any */
3147
3206
  /**
3148
3207
  * Debounce function to prevent multiple calls in a short
@@ -3172,12 +3231,15 @@ const NvDatagrid = class {
3172
3231
  this.action = index.createEvent(this, "action");
3173
3232
  this.templateCache = new Map();
3174
3233
  this.headerTemplateCache = new Map();
3234
+ this.minPageIndex = 1;
3175
3235
  /****************************************************************************/
3176
3236
  //#region STATES
3177
3237
  this.table = null;
3178
3238
  this.parsedColumns = []; // Parsed array
3179
3239
  this.parsedData = []; // Parsed array
3180
- this.globalFilter = '';
3240
+ this.globalFilterSearchTerm = '';
3241
+ this.columnData = [];
3242
+ this.paginationState = null;
3181
3243
  //#endregion STATES
3182
3244
  /****************************************************************************/
3183
3245
  //#region PROPERTIES
@@ -3227,8 +3289,24 @@ const NvDatagrid = class {
3227
3289
  * @default false
3228
3290
  */
3229
3291
  this.autoGenerateColumns = false;
3292
+ /**
3293
+ * Whether to enable pagination for the data grid.
3294
+ * @default false
3295
+ */
3296
+ this.enablePagination = false;
3297
+ /**
3298
+ * The number of rows to display per page.
3299
+ * @default 10
3300
+ */
3301
+ this.pageSize = 10;
3302
+ /**
3303
+ * The array of page sizes to display in the pagination dropdown.
3304
+ * @default [10, 20, 30, 40, 50]
3305
+ */
3306
+ this.pageSizes = [10, 20, 30, 40, 50];
3230
3307
  this.debouncedFilter = debounce((value) => {
3231
- this.globalFilter = value;
3308
+ var _a;
3309
+ (_a = this.table) === null || _a === void 0 ? void 0 : _a.setGlobalFilter(value);
3232
3310
  }, 300);
3233
3311
  /**
3234
3312
  * Handles global filtering on input event for the search input.
@@ -3244,6 +3322,23 @@ const NvDatagrid = class {
3244
3322
  this.debouncedFilter(value);
3245
3323
  }
3246
3324
  };
3325
+ this.flexRender = (comp, props) => {
3326
+ if (typeof comp === 'function') {
3327
+ return comp(props);
3328
+ }
3329
+ return comp;
3330
+ };
3331
+ this.handlePageIndexChange = (event) => {
3332
+ const target = event.target;
3333
+ const page = target.value ? Number(target.value) - 1 : 0;
3334
+ // Simply use `setPageIndex` to update the page index directly
3335
+ this.paginationState = Object.assign(Object.assign({}, this.paginationState), { pageIndex: page }); // This triggers the paginationState watcher
3336
+ };
3337
+ this.handlePageSizeChange = (event) => {
3338
+ const target = event.target;
3339
+ // 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
3341
+ };
3247
3342
  }
3248
3343
  //#endregion PROPERTIES
3249
3344
  /****************************************************************************/
@@ -3253,6 +3348,7 @@ const NvDatagrid = class {
3253
3348
  */
3254
3349
  cacheTemplates() {
3255
3350
  const columns = Array.from(this.el.querySelectorAll('nv-datagridcolumn'));
3351
+ this.columnData = [];
3256
3352
  columns.forEach((col) => {
3257
3353
  const key = col.accessor;
3258
3354
  const cellSlot = col.querySelector('[slot="cell"]');
@@ -3273,6 +3369,12 @@ const NvDatagrid = class {
3273
3369
  this.headerTemplateCache.set(key, headerDiv);
3274
3370
  }
3275
3371
  }
3372
+ const colData = {
3373
+ header: col.header,
3374
+ accessor: col.accessor,
3375
+ repeatTemplate: col.hasAttribute('repeat-template'),
3376
+ };
3377
+ this.columnData.push(colData);
3276
3378
  });
3277
3379
  }
3278
3380
  parseDataAndColumns() {
@@ -3338,6 +3440,7 @@ const NvDatagrid = class {
3338
3440
  this.parsedColumns = safeNewValue;
3339
3441
  }
3340
3442
  initializeTable() {
3443
+ var _a, _b, _c, _d;
3341
3444
  // Clear the previous table instance (if any)
3342
3445
  this.table = null;
3343
3446
  // Set default options for the table
@@ -3371,26 +3474,9 @@ const NvDatagrid = class {
3371
3474
  }, // Default: no column sizing info
3372
3475
  },
3373
3476
  };
3374
- if (this.enableGlobalFilter) {
3375
- tableOptions.getFilteredRowModel = getFilteredRowModel();
3376
- // Set the initial global filter value
3377
- tableOptions.state.globalFilter = this.globalFilter;
3378
- // Define the callback for global filter changes
3379
- tableOptions.onGlobalFilterChange = value => {
3380
- this.globalFilter = value;
3381
- };
3382
- tableOptions.globalFilterFn = (row, columnId, filterValue) => {
3383
- const response = row
3384
- .getValue(columnId)
3385
- .toString()
3386
- .toLowerCase()
3387
- .includes(filterValue.toLowerCase());
3388
- return response;
3389
- };
3390
- }
3391
3477
  if (this.parsedColumns.length > 0) {
3392
3478
  // Validate and generate column definitions
3393
- const validColumns = this.parsedColumns.filter(column => (column === null || column === void 0 ? void 0 : column.accessor) && (column === null || column === void 0 ? void 0 : column.header));
3479
+ const validColumns = this.parsedColumns.filter(column => column === null || column === void 0 ? void 0 : column.accessor);
3394
3480
  // Update tableOptions based on parsed data and columns
3395
3481
  const hasColumns = validColumns && Array.isArray(validColumns) && validColumns.length > 0;
3396
3482
  const hasData = this.parsedData &&
@@ -3398,22 +3484,22 @@ const NvDatagrid = class {
3398
3484
  this.parsedData.length > 0;
3399
3485
  if (!hasColumns && !hasData) ;
3400
3486
  else if (hasColumns && !hasData) {
3487
+ // Has columns but no data
3401
3488
  tableOptions.columns = this.generateColumns(validColumns, tableOptions);
3402
3489
  }
3403
3490
  else {
3404
3491
  // Both columns and data are available
3405
- // No columns and data is available
3406
3492
  tableOptions.data = this.getTableData();
3407
3493
  tableOptions.columns = this.generateColumns(validColumns, tableOptions);
3408
3494
  }
3409
3495
  }
3410
3496
  else {
3411
- // No columns and data is available
3497
+ // No parsed columns and data is available
3412
3498
  const hasData = this.parsedData &&
3413
3499
  Array.isArray(this.parsedData) &&
3414
3500
  this.parsedData.length > 0;
3415
3501
  if (hasData) {
3416
- // No columns and data is available
3502
+ // No parsed columns and data is available
3417
3503
  const firstRow = this.parsedData[0];
3418
3504
  const arrayColumnsConfig = Object.keys(firstRow).map(key => ({
3419
3505
  accessor: key,
@@ -3426,26 +3512,116 @@ const NvDatagrid = class {
3426
3512
  tableOptions.columns = this.generateColumns(arrayColumnsConfig, tableOptions);
3427
3513
  }
3428
3514
  }
3515
+ if (this.enableGlobalFilter) {
3516
+ tableOptions.getFilteredRowModel = getFilteredRowModel();
3517
+ const globalFilter = this.globalFilterSearchTerm;
3518
+ // Set the initial global filter value
3519
+ tableOptions.state.globalFilter = globalFilter;
3520
+ // Define the callback for global filter changes
3521
+ tableOptions.onGlobalFilterChange = updater => {
3522
+ const newFilter = typeof updater === 'function'
3523
+ ? updater(this.globalFilterSearchTerm)
3524
+ : updater;
3525
+ this.globalFilterSearchTerm = newFilter; // Will automatically trigger the searchTerm watcher and update the table
3526
+ };
3527
+ tableOptions.globalFilterFn = this.globalFilterFn;
3528
+ }
3529
+ if (this.enablePagination) {
3530
+ tableOptions.getPaginationRowModel = getPaginationRowModel();
3531
+ 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,
3534
+ };
3535
+ // Set the initial pagination value with safeguards
3536
+ tableOptions.state.pagination = pagination;
3537
+ tableOptions.onPaginationChange = updater => {
3538
+ const newPagination = typeof updater === 'function'
3539
+ ? updater(this.paginationState)
3540
+ : updater;
3541
+ this.paginationState = newPagination;
3542
+ };
3543
+ }
3429
3544
  // Initialize the table
3430
3545
  this.table = createTable(tableOptions);
3431
3546
  }
3547
+ /**
3548
+ * Global filter function for the table.
3549
+ * This function checks if the specified filter value is present in any of the row's original values,
3550
+ * including nested objects and arrays. It is used to filter the rows based on the global filter value,
3551
+ * allowing for case-insensitive matching.
3552
+ *
3553
+ * @param {Row<any>} row - The row object containing the data to be filtered.
3554
+ * @param {string} _columnId - The ID of the column being filtered (not used in this function).
3555
+ * @param {string} filterValue - The value to filter the rows by. This value is checked against the row's data.
3556
+ * @returns {boolean} - Returns true if the row should be included in the filtered results, false otherwise.
3557
+ * If the filter value is empty, all rows are included.
3558
+ */
3559
+ globalFilterFn(row, _columnId, filterValue) {
3560
+ const safeFilterValue = String(filterValue).toLowerCase().trim();
3561
+ // If no filter value, return true for all rows
3562
+ if (!safeFilterValue)
3563
+ return true;
3564
+ // More robust filtering across all columns
3565
+ const checkValue = (value) => {
3566
+ if (typeof value === 'object' && value !== null) {
3567
+ // If it's an array, check each item
3568
+ if (Array.isArray(value)) {
3569
+ return value.some(item => checkValue(item));
3570
+ }
3571
+ // If it's an object, check each property
3572
+ return Object.values(value).some(val => checkValue(val));
3573
+ }
3574
+ return String(value).toLowerCase().includes(safeFilterValue);
3575
+ };
3576
+ return checkValue(row.original);
3577
+ }
3432
3578
  // Helper function to generate column definitions
3433
3579
  generateColumns(validColumns, tableOptions) {
3434
3580
  const columnHelper = createColumnHelper();
3435
3581
  if (validColumns.length > 0) {
3436
3582
  // Use defined columns
3437
- return validColumns.map(column => columnHelper.accessor(column.accessor, {
3438
- header: column.header,
3439
- cell: info => info.getValue(),
3440
- enableGlobalFilter: this.enableGlobalFilter,
3441
- }));
3583
+ return validColumns.map(column => {
3584
+ var _a, _b;
3585
+ return columnHelper.accessor(column.accessor, {
3586
+ header: (_b = (this.renderTemplate(this.headerTemplateCache.get(column.accessor), (_a = column.header) !== null && _a !== void 0 ? _a : column.accessor, null) ||
3587
+ column.header)) !== null && _b !== void 0 ? _b : column.accessor,
3588
+ cell: (info) => {
3589
+ var _a, _b, _c;
3590
+ const value = info.getValue();
3591
+ const cellAccessors = column.accessor;
3592
+ const row = info.row;
3593
+ return ((_a = this.columnData.find(x => x.accessor === cellAccessors)) === null || _a === void 0 ? void 0 : _a.repeatTemplate) && Array.isArray(value)
3594
+ ? value.map((item) => {
3595
+ var _a, _b;
3596
+ return (_b = (_a = (this.renderTemplate(this.templateCache.get(cellAccessors), item, row) ||
3597
+ item)) !== null && _a !== void 0 ? _a : value) !== null && _b !== void 0 ? _b : this.fallbackValue;
3598
+ })
3599
+ : (_c = (_b = (this.renderTemplate(this.templateCache.get(cellAccessors), value, row) ||
3600
+ value)) !== null && _b !== void 0 ? _b : value) !== null && _c !== void 0 ? _c : this.fallbackValue;
3601
+ },
3602
+ enableGlobalFilter: this.enableGlobalFilter,
3603
+ });
3604
+ });
3442
3605
  }
3443
3606
  else if (tableOptions.data && tableOptions.data.length > 0) {
3444
3607
  // Generate columns from data keys
3445
3608
  const sampleRow = tableOptions.data[0];
3446
3609
  return Object.keys(sampleRow).map(key => columnHelper.accessor(key, {
3447
- header: key.charAt(0).toUpperCase() + key.slice(1), // Capitalize key for header
3448
- cell: info => info.getValue(),
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
+ },
3449
3625
  enableGlobalFilter: this.enableGlobalFilter,
3450
3626
  }));
3451
3627
  }
@@ -3474,11 +3650,11 @@ const NvDatagrid = class {
3474
3650
  // Replace placeholders in text content, attributes, and properties
3475
3651
  element.querySelectorAll('*').forEach(el => {
3476
3652
  // Replace placeholders in text content
3477
- this.replacePlaceholdersTextContent(el, cellValue);
3653
+ this.replacePlaceholdersTextContent(el, cellValue, row);
3478
3654
  // Replace placeholders in attributes
3479
- this.replacePlaceholdersAttributes(el, cellValue);
3655
+ this.replacePlaceholdersAttributes(el, cellValue, row);
3480
3656
  // Replace placeholders in properties
3481
- this.replacePlaceholdersProperties(el, cellValue);
3657
+ this.replacePlaceholdersProperties(el, cellValue, row);
3482
3658
  });
3483
3659
  // Handle `data-bind-event`
3484
3660
  element.querySelectorAll('[data-bind-event]').forEach(el => {
@@ -3554,56 +3730,151 @@ const NvDatagrid = class {
3554
3730
  }
3555
3731
  }
3556
3732
  // Handle single-level key lookup
3557
- return key in cellValue ? String(cellValue[key]) : this.fallbackValue;
3733
+ if (key in cellValue) {
3734
+ return String(cellValue[key]);
3735
+ }
3736
+ else if (Array.isArray(cellValue)) {
3737
+ // Handle array of objects
3738
+ const response = cellValue.map((item) => {
3739
+ if (typeof item !== 'object') {
3740
+ return item.toString();
3741
+ }
3742
+ else if (key in item) {
3743
+ return item[key];
3744
+ }
3745
+ else {
3746
+ return item.toString();
3747
+ }
3748
+ });
3749
+ return response.join(', ');
3750
+ }
3751
+ return this.fallbackValue;
3558
3752
  }
3559
3753
  // If cellValue is a primitive (string, number, boolean, etc.), return it as a string
3560
3754
  return (_a = cellValue === null || cellValue === void 0 ? void 0 : cellValue.toString()) !== null && _a !== void 0 ? _a : this.fallbackValue;
3561
3755
  }
3562
- replacePlaceholdersTextContent(element, cellValue) {
3563
- // Replace placeholders in text content
3564
- element.childNodes.forEach(node => {
3565
- if (node.nodeType === Node.TEXT_NODE) {
3566
- node.textContent = node.textContent.replace(/__([\w.]+)__/g, (_, key) => this.replaceKeyWithValue(key, cellValue));
3567
- }
3568
- });
3756
+ replacePlaceholdersTextContent(element, cellValue, row) {
3757
+ if (!cellValue) {
3758
+ // Replace placeholders in text content with the row original value
3759
+ // but first get the original value
3760
+ const originalValue = row.original;
3761
+ element.childNodes.forEach(node => {
3762
+ if (node.nodeType === Node.TEXT_NODE) {
3763
+ node.textContent = node.textContent.replace(/__([\w.]+)__/g, (_, key) => {
3764
+ if (key in originalValue) {
3765
+ return this.replaceKeyWithValue(key, originalValue[key]);
3766
+ }
3767
+ else {
3768
+ console.warn(`Key ${key} not found in originalValue`);
3769
+ return '';
3770
+ }
3771
+ });
3772
+ }
3773
+ });
3774
+ }
3775
+ else {
3776
+ // ✅ Replace placeholders in text content
3777
+ element.childNodes.forEach(node => {
3778
+ if (node.nodeType === Node.TEXT_NODE) {
3779
+ node.textContent = node.textContent.replace(/__([\w.]+)__/g, (_, key) => this.replaceKeyWithValue(key, cellValue));
3780
+ }
3781
+ });
3782
+ }
3569
3783
  }
3570
- replacePlaceholdersAttributes(element, cellValue) {
3571
- // Replace placeholders in attributes
3572
- Array.from(element.attributes).forEach(attr => {
3573
- if (attr.value.includes('__')) {
3574
- attr.value = attr.value.replace(/__([\w.]+)__/g, (_, key) => this.replaceKeyWithValue(key, cellValue));
3575
- }
3576
- });
3784
+ replacePlaceholdersAttributes(element, cellValue, row) {
3785
+ if (!cellValue) {
3786
+ // ✅ Replace placeholders in attributes with the row original value
3787
+ // but first get the original value
3788
+ const originalValue = row.original;
3789
+ Array.from(element.attributes).forEach(attr => {
3790
+ if (attr.value.includes('__')) {
3791
+ attr.value = attr.value.replace(/__([\w.]+)__/g, (_, key) => {
3792
+ if (key in originalValue) {
3793
+ return this.replaceKeyWithValue(key, originalValue[key]);
3794
+ }
3795
+ else {
3796
+ console.warn(`Key ${key} not found in originalValue`);
3797
+ return '';
3798
+ }
3799
+ });
3800
+ }
3801
+ });
3802
+ }
3803
+ else {
3804
+ // ✅ Replace placeholders in attributes
3805
+ Array.from(element.attributes).forEach(attr => {
3806
+ if (attr.value.includes('__')) {
3807
+ attr.value = attr.value.replace(/__([\w.]+)__/g, (_, key) => this.replaceKeyWithValue(key, cellValue));
3808
+ }
3809
+ });
3810
+ }
3577
3811
  }
3578
- replacePlaceholdersProperties(element, cellValue) {
3579
- // Dynamically extract relevant properties
3580
- const properties = new Set();
3581
- // Collect only own enumerable properties
3582
- Object.keys(element).forEach(key => properties.add(key));
3583
- // Collect inherited properties from prototypes (HTMLElement -> Element -> Node)
3584
- let proto = Object.getPrototypeOf(element);
3585
- while (proto && proto !== HTMLElement.prototype) {
3586
- Object.keys(proto).forEach(key => properties.add(key));
3587
- proto = Object.getPrototypeOf(proto);
3588
- }
3589
- // Filter and copy only non-function properties and exclude irrelevant ones
3590
- properties.forEach(prop => {
3591
- if (typeof element[prop] !== 'function' && // Ignore methods
3592
- !prop.startsWith('on') && // Ignore event listeners (onclick, oninput, etc.)
3593
- !dom_utilsAc71e0ef.excludedProps.has(prop) // 🚨 Prevent text duplication and irrelevant props
3594
- ) {
3595
- try {
3812
+ replacePlaceholdersProperties(element, cellValue, row) {
3813
+ if (!cellValue) {
3814
+ // ✅ Replace placeholders in properties with the row original value
3815
+ // but first get the original value
3816
+ const originalValue = row.original;
3817
+ // Dynamically extract relevant properties
3818
+ const properties = new Set();
3819
+ // Collect only own enumerable properties
3820
+ Object.keys(originalValue).forEach(key => properties.add(key));
3821
+ // Collect inherited properties from prototypes (HTMLElement -> Element -> Node)
3822
+ let proto = Object.getPrototypeOf(originalValue);
3823
+ while (proto && proto !== HTMLElement.prototype) {
3824
+ Object.keys(proto).forEach(key => properties.add(key));
3825
+ proto = Object.getPrototypeOf(proto);
3826
+ }
3827
+ // Filter and copy only non-function properties and exclude irrelevant ones
3828
+ properties.forEach(prop => {
3829
+ if (typeof element[prop] !== 'function' && // Ignore methods
3830
+ !prop.startsWith('on') && // Ignore event listeners (onclick, oninput, etc.)
3831
+ !dom_utilsAc71e0ef.excludedProps.has(prop) // 🚨 Prevent text duplication and irrelevant props
3832
+ ) {
3596
3833
  const propValue = element[prop];
3597
- // ✅ Replace placeholders only if the value is a string
3598
3834
  if (typeof propValue === 'string' && propValue.includes('__')) {
3599
- element[prop] = propValue.replace(/__([\w.]+)__/g, (_, key) => this.replaceKeyWithValue(key, cellValue)); // ✅ TypeScript safe
3835
+ element[prop] = propValue.replace(/__([\w.]+)__/g, (_, key) => {
3836
+ if (key in originalValue) {
3837
+ return this.replaceKeyWithValue(key, originalValue[key]);
3838
+ }
3839
+ else {
3840
+ console.warn(`Key ${key} not found in originalValue`);
3841
+ return '';
3842
+ }
3843
+ });
3600
3844
  }
3601
3845
  }
3602
- catch (error) {
3603
- console.warn(`Could not assign property ${prop}:`, error.message);
3604
- }
3846
+ });
3847
+ }
3848
+ else {
3849
+ // ✅ Dynamically extract relevant properties
3850
+ const properties = new Set();
3851
+ // Collect only own enumerable properties
3852
+ Object.keys(element).forEach(key => properties.add(key));
3853
+ // Collect inherited properties from prototypes (HTMLElement -> Element -> Node)
3854
+ let proto = Object.getPrototypeOf(element);
3855
+ while (proto && proto !== HTMLElement.prototype) {
3856
+ Object.keys(proto).forEach(key => properties.add(key));
3857
+ proto = Object.getPrototypeOf(proto);
3605
3858
  }
3606
- });
3859
+ // ✅ Filter and copy only non-function properties and exclude irrelevant ones
3860
+ properties.forEach(prop => {
3861
+ if (typeof element[prop] !== 'function' && // Ignore methods
3862
+ !prop.startsWith('on') && // Ignore event listeners (onclick, oninput, etc.)
3863
+ !dom_utilsAc71e0ef.excludedProps.has(prop) // 🚨 Prevent text duplication and irrelevant props
3864
+ ) {
3865
+ try {
3866
+ const propValue = element[prop];
3867
+ // ✅ Replace placeholders only if the value is a string
3868
+ if (typeof propValue === 'string' && propValue.includes('__')) {
3869
+ element[prop] = propValue.replace(/__([\w.]+)__/g, (_, key) => this.replaceKeyWithValue(key, cellValue)); // ✅ TypeScript safe
3870
+ }
3871
+ }
3872
+ catch (error) {
3873
+ console.warn(`Could not assign property ${prop}:`, error.message);
3874
+ }
3875
+ }
3876
+ });
3877
+ }
3607
3878
  }
3608
3879
  //#endregion METHODS
3609
3880
  /****************************************************************************/
@@ -3637,14 +3908,30 @@ const NvDatagrid = class {
3637
3908
  handleParsedChange() {
3638
3909
  this.initializeTable();
3639
3910
  }
3640
- handleGlobalFilter(newValue) {
3911
+ handleGlobalFilterSearchTerm(newValue) {
3641
3912
  if (!this.table) {
3642
3913
  console.warn('Table is not initialized yet.');
3643
3914
  return;
3644
3915
  }
3645
- // 🚨 Manually update state before calling filter
3646
- this.table.options.state = Object.assign(Object.assign({}, this.table.options.state), { globalFilter: newValue });
3647
- this.table.setGlobalFilter(newValue);
3916
+ // Not working
3917
+ /*// Set the global filter for the table
3918
+ this.table.setGlobalFilter(newValue);*/
3919
+ // Manually update the globalFilter state
3920
+ this.table.options.state.globalFilter = newValue;
3921
+ }
3922
+ handlePaginationState(newValue, oldValue) {
3923
+ if (!this.table) {
3924
+ console.warn('Table is not initialized yet.');
3925
+ return;
3926
+ }
3927
+ // Only update if there is a meaningful change
3928
+ if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
3929
+ // Not working
3930
+ /*// Set the pagination for the table
3931
+ this.table.setPagination(newValue);*/
3932
+ // Manually update the pagination state
3933
+ this.table.options.state.pagination = newValue;
3934
+ }
3648
3935
  }
3649
3936
  //#endregion WATCHERS
3650
3937
  /****************************************************************************/
@@ -3653,34 +3940,39 @@ const NvDatagrid = class {
3653
3940
  this.cacheTemplates();
3654
3941
  this.parseDataAndColumns();
3655
3942
  this.initializeTable();
3943
+ if (this.enablePagination) {
3944
+ // Ensure a valid page size
3945
+ const effectivePageSize = this.pageSize > 0 ? this.pageSize : 10;
3946
+ this.paginationState = {
3947
+ pageIndex: Math.max(0, this.minPageIndex - 1),
3948
+ pageSize: effectivePageSize,
3949
+ };
3950
+ }
3656
3951
  }
3657
3952
  //#endregion EVENTS
3658
3953
  /****************************************************************************/
3659
3954
  //#region RENDER
3660
3955
  render() {
3661
- var _a, _b, _c, _d;
3956
+ var _a, _b, _c, _d, _e;
3662
3957
  const headerGroups = !this.table || this.table === undefined || this.parsedColumns.length === 0
3663
3958
  ? []
3664
3959
  : (_a = this.table) === null || _a === void 0 ? void 0 : _a.getHeaderGroups();
3665
3960
  const rows = !this.table || this.table === undefined || this.parsedData.length === 0
3666
3961
  ? []
3667
3962
  : (_c = (_b = this.table) === null || _b === void 0 ? void 0 : _b.getRowModel()) === null || _c === void 0 ? void 0 : _c.rows;
3668
- return (index.h(index.Host, { key: '6768db58f6a19cbb64e2206957ca27c18c408e46' }, index.h("div", { key: 'e262922097ae61025e13f8fe685ed7b38063e82c', class: "hidden" }, index.h("slot", { key: '9025f410bc3e6b409d6225a53a97d13aa3629200' })), index.h("slot", { key: '684876205d7092a4edf325c8897e97a491b77c6a', name: "before" }), this.enableGlobalFilter && this.table && (index.h("div", { key: 'b2fe6dd4a97d978617d404134286e6048eb8ddc2', class: "search-container" }, index.h("input", { key: '82c5d3b73b0bff0c2415ad896a6a4504bb1bb92c', type: "text", value: (_d = this.globalFilter) !== 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("table", null, this.parsedColumns.length > 0 && headerGroups.length > 0 && (index.h("thead", null, this.parsedColumns.length > 0 && headerGroups
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
3669
3964
  ? headerGroups === null || headerGroups === void 0 ? void 0 : headerGroups.map(headerGroup => (index.h("tr", { key: headerGroup.id }, headerGroup.headers.map(header => {
3670
3965
  return (index.h("th", { key: header.id }, header.isPlaceholder
3671
3966
  ? null
3672
- : this.renderTemplate(this.headerTemplateCache.get(header.id), {}) || header.column.columnDef.header));
3967
+ : this.flexRender(header.column.columnDef.header, header.getContext())));
3673
3968
  }))))
3674
3969
  : 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 => {
3675
3970
  const rowId = row.id;
3676
3971
  const visibleCells = row === null || row === void 0 ? void 0 : row.getVisibleCells();
3677
3972
  return (index.h("tr", { key: rowId }, visibleCells.map(cell => {
3678
- const cellAccessors = cell.column.id;
3679
- const cellValue = cell.getValue();
3680
- return (index.h("td", { key: cell.id, "data-row-id": rowId }, this.renderTemplate(this.templateCache.get(cellAccessors), cellValue, row) ||
3681
- (cellValue !== null && cellValue !== void 0 ? cellValue : this.fallbackValue)));
3973
+ return (index.h("td", { key: cell.id, "data-row-id": rowId }, this.flexRender(cell.column.columnDef.cell, cell.getContext())));
3682
3974
  })));
3683
- }))))), index.h("slot", { key: '4bda5737d7917a508b97cf38b764000f8c5d368d', name: "after" })));
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" })));
3684
3976
  }
3685
3977
  get el() { return index.getElement(this); }
3686
3978
  static get watchers() { return {
@@ -3690,7 +3982,8 @@ const NvDatagrid = class {
3690
3982
  "dataJson": ["parseJsonData"],
3691
3983
  "parsedColumns": ["handleParsedChange"],
3692
3984
  "parsedData": ["handleParsedChange"],
3693
- "globalFilter": ["handleGlobalFilter"]
3985
+ "globalFilterSearchTerm": ["handleGlobalFilterSearchTerm"],
3986
+ "paginationState": ["handlePaginationState"]
3694
3987
  }; }
3695
3988
  };
3696
3989
  NvDatagrid.style = NvDatagridStyle0;