@nova-design-system/nova-react 3.0.0-beta.46 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{index-BgDhK4Po.js → index-Byv3Vmev.js} +605 -495
- package/dist/cjs/index.js +1 -2
- package/dist/cjs/{nv-alert.entry-C9DnCn0Q.js → nv-alert.entry-BXY4KXbF.js} +1 -1
- package/dist/cjs/{nv-avatar.entry-Cj_bK7KY.js → nv-avatar.entry-BnPSKkJJ.js} +1 -1
- package/dist/cjs/{nv-badge_2.entry-H664ASUM.js → nv-badge_2.entry-BsI3B8Rr.js} +2 -2
- package/dist/cjs/{nv-breadcrumb.entry-BOyjRSxM.js → nv-breadcrumb.entry-D5vGHLOG.js} +2 -2
- package/dist/cjs/{nv-breadcrumbs.entry-DkffTj6Z.js → nv-breadcrumbs.entry-CsaqAsnb.js} +2 -2
- package/dist/cjs/{nv-button.entry-Dv4bG9oE.js → nv-button.entry-DzZfGZGy.js} +2 -2
- package/dist/cjs/{nv-calendar.entry-DSoKDy9Q.js → nv-calendar.entry-CGKv_-gO.js} +49 -20
- package/dist/cjs/{nv-col.entry-CGNiCKta.js → nv-col.entry-Cng8NaTW.js} +2 -2
- package/dist/cjs/{nv-datagrid.entry-YSL7aTz5.js → nv-datagrid.entry-BbAOzpiO.js} +352 -92
- package/dist/cjs/{nv-datagridcolumn.entry-7whgB5iS.js → nv-datagridcolumn.entry-CRogHbVM.js} +2 -2
- package/dist/cjs/{nv-dialog.entry-CLANnPw3.js → nv-dialog.entry-BSIZGYGF.js} +2 -2
- package/dist/cjs/{nv-dialogfooter_2.entry-cHevwuGs.js → nv-dialogfooter_2.entry-Q4_li_QU.js} +3 -3
- package/dist/cjs/{nv-fieldcheckbox.entry-BV8M8SyS.js → nv-fieldcheckbox.entry-DmgzfmRd.js} +5 -5
- package/dist/cjs/{nv-fielddate.entry--KEcXuio.js → nv-fielddate.entry-qAvLX_Ru.js} +6 -6
- package/dist/cjs/{nv-fielddaterange.entry-Bctzvr40.js → nv-fielddaterange.entry-DVB8Rwxk.js} +5 -5
- package/dist/cjs/{nv-fielddropdown.entry-DJPARQ0F.js → nv-fielddropdown.entry-DKXmoXeW.js} +16 -30
- package/dist/cjs/{nv-fielddropdownitem.entry-DAlnhF7-.js → nv-fielddropdownitem.entry-BVLVXi0e.js} +2 -2
- package/dist/cjs/{nv-fieldmultiselect.entry-DDKtC-sR.js → nv-fieldmultiselect.entry-DrTbd3Dj.js} +29 -72
- package/dist/cjs/{nv-fieldnumber.entry-FzcOQMWp.js → nv-fieldnumber.entry-DegbEHRL.js} +4 -4
- package/dist/cjs/{nv-fieldpassword.entry-ZgJKgEWo.js → nv-fieldpassword.entry-gqjlEl7a.js} +4 -4
- package/dist/cjs/{nv-fieldradio.entry-B6vwI0oH.js → nv-fieldradio.entry-CVEY4v6F.js} +4 -4
- package/dist/cjs/{nv-fieldselect.entry-Dpb1RR2D.js → nv-fieldselect.entry-BrCUuRWa.js} +6 -6
- package/dist/cjs/{nv-fieldtext.entry-WhMFksEn.js → nv-fieldtext.entry-q9NnqL5c.js} +4 -4
- package/dist/cjs/{nv-fieldtextarea.entry-Cpqi_pE7.js → nv-fieldtextarea.entry-B4qiLmX1.js} +4 -4
- package/dist/cjs/{nv-fieldtime.entry-BApGHC9K.js → nv-fieldtime.entry-Bp2IWjhN.js} +10 -10
- package/dist/cjs/{nv-icon.entry-DTbgrNDQ.js → nv-icon.entry-B1ax9cJS.js} +2 -2
- package/dist/cjs/{nv-iconbutton_2.entry-D5Wjr6mr.js → nv-iconbutton_2.entry-BRPAGl2S.js} +3 -3
- package/dist/cjs/{nv-menu.entry-4P44Bom1.js → nv-menu.entry-BiWiIZAm.js} +17 -43
- package/dist/cjs/{nv-menuitem.entry-pYkLIeY9.js → nv-menuitem.entry-CFkXoZ_r.js} +2 -2
- package/dist/cjs/{nv-popover.entry-DJzEjs-d.js → nv-popover.entry-KT1iQUJk.js} +2 -2
- package/dist/cjs/{nv-row.entry-AQGhBTGs.js → nv-row.entry-Cs2GDrcu.js} +2 -2
- package/dist/cjs/{nv-stack.entry-Bb6k4Yob.js → nv-stack.entry-Ci7pxGSo.js} +2 -2
- package/dist/cjs/{nv-table.entry-C4DY5CRF.js → nv-table.entry-N4MV8Y6E.js} +3 -3
- package/dist/cjs/{nv-tablecolumn.entry-jJAoHJnt.js → nv-tablecolumn.entry-CTz4jsZl.js} +1 -1
- package/dist/cjs/{nv-toggle.entry-P76L0fsx.js → nv-toggle.entry-m10-ncYR.js} +3 -3
- package/dist/cjs/{nv-tooltip.entry-DC7XngcD.js → nv-tooltip.entry-B6aRDto3.js} +2 -2
- package/dist/generated/components.js +0 -8
- package/dist/types/generated/components.d.ts +0 -3
- package/package.json +1 -1
- package/dist/cjs/nv-base.entry-DdLnS1hF.js +0 -71
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
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,13 +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.
|
|
3240
|
+
this.globalFilterSearchTerm = '';
|
|
3181
3241
|
this.columnData = [];
|
|
3242
|
+
this.paginationState = null;
|
|
3182
3243
|
//#endregion STATES
|
|
3183
3244
|
/****************************************************************************/
|
|
3184
3245
|
//#region PROPERTIES
|
|
@@ -3228,8 +3289,24 @@ const NvDatagrid = class {
|
|
|
3228
3289
|
* @default false
|
|
3229
3290
|
*/
|
|
3230
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];
|
|
3231
3307
|
this.debouncedFilter = debounce((value) => {
|
|
3232
|
-
|
|
3308
|
+
var _a;
|
|
3309
|
+
(_a = this.table) === null || _a === void 0 ? void 0 : _a.setGlobalFilter(value);
|
|
3233
3310
|
}, 300);
|
|
3234
3311
|
/**
|
|
3235
3312
|
* Handles global filtering on input event for the search input.
|
|
@@ -3245,6 +3322,23 @@ const NvDatagrid = class {
|
|
|
3245
3322
|
this.debouncedFilter(value);
|
|
3246
3323
|
}
|
|
3247
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
|
+
};
|
|
3248
3342
|
}
|
|
3249
3343
|
//#endregion PROPERTIES
|
|
3250
3344
|
/****************************************************************************/
|
|
@@ -3346,6 +3440,7 @@ const NvDatagrid = class {
|
|
|
3346
3440
|
this.parsedColumns = safeNewValue;
|
|
3347
3441
|
}
|
|
3348
3442
|
initializeTable() {
|
|
3443
|
+
var _a, _b, _c, _d;
|
|
3349
3444
|
// Clear the previous table instance (if any)
|
|
3350
3445
|
this.table = null;
|
|
3351
3446
|
// Set default options for the table
|
|
@@ -3379,26 +3474,9 @@ const NvDatagrid = class {
|
|
|
3379
3474
|
}, // Default: no column sizing info
|
|
3380
3475
|
},
|
|
3381
3476
|
};
|
|
3382
|
-
if (this.enableGlobalFilter) {
|
|
3383
|
-
tableOptions.getFilteredRowModel = getFilteredRowModel();
|
|
3384
|
-
// Set the initial global filter value
|
|
3385
|
-
tableOptions.state.globalFilter = this.globalFilter;
|
|
3386
|
-
// Define the callback for global filter changes
|
|
3387
|
-
tableOptions.onGlobalFilterChange = value => {
|
|
3388
|
-
this.globalFilter = value;
|
|
3389
|
-
};
|
|
3390
|
-
tableOptions.globalFilterFn = (row, columnId, filterValue) => {
|
|
3391
|
-
const response = row
|
|
3392
|
-
.getValue(columnId)
|
|
3393
|
-
.toString()
|
|
3394
|
-
.toLowerCase()
|
|
3395
|
-
.includes(filterValue.toLowerCase());
|
|
3396
|
-
return response;
|
|
3397
|
-
};
|
|
3398
|
-
}
|
|
3399
3477
|
if (this.parsedColumns.length > 0) {
|
|
3400
3478
|
// Validate and generate column definitions
|
|
3401
|
-
const validColumns = this.parsedColumns.filter(column =>
|
|
3479
|
+
const validColumns = this.parsedColumns.filter(column => column === null || column === void 0 ? void 0 : column.accessor);
|
|
3402
3480
|
// Update tableOptions based on parsed data and columns
|
|
3403
3481
|
const hasColumns = validColumns && Array.isArray(validColumns) && validColumns.length > 0;
|
|
3404
3482
|
const hasData = this.parsedData &&
|
|
@@ -3406,22 +3484,22 @@ const NvDatagrid = class {
|
|
|
3406
3484
|
this.parsedData.length > 0;
|
|
3407
3485
|
if (!hasColumns && !hasData) ;
|
|
3408
3486
|
else if (hasColumns && !hasData) {
|
|
3487
|
+
// Has columns but no data
|
|
3409
3488
|
tableOptions.columns = this.generateColumns(validColumns, tableOptions);
|
|
3410
3489
|
}
|
|
3411
3490
|
else {
|
|
3412
3491
|
// Both columns and data are available
|
|
3413
|
-
// No columns and data is available
|
|
3414
3492
|
tableOptions.data = this.getTableData();
|
|
3415
3493
|
tableOptions.columns = this.generateColumns(validColumns, tableOptions);
|
|
3416
3494
|
}
|
|
3417
3495
|
}
|
|
3418
3496
|
else {
|
|
3419
|
-
// No columns and data is available
|
|
3497
|
+
// No parsed columns and data is available
|
|
3420
3498
|
const hasData = this.parsedData &&
|
|
3421
3499
|
Array.isArray(this.parsedData) &&
|
|
3422
3500
|
this.parsedData.length > 0;
|
|
3423
3501
|
if (hasData) {
|
|
3424
|
-
// No columns and data is available
|
|
3502
|
+
// No parsed columns and data is available
|
|
3425
3503
|
const firstRow = this.parsedData[0];
|
|
3426
3504
|
const arrayColumnsConfig = Object.keys(firstRow).map(key => ({
|
|
3427
3505
|
accessor: key,
|
|
@@ -3434,26 +3512,116 @@ const NvDatagrid = class {
|
|
|
3434
3512
|
tableOptions.columns = this.generateColumns(arrayColumnsConfig, tableOptions);
|
|
3435
3513
|
}
|
|
3436
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
|
+
}
|
|
3437
3544
|
// Initialize the table
|
|
3438
3545
|
this.table = createTable(tableOptions);
|
|
3439
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
|
+
}
|
|
3440
3578
|
// Helper function to generate column definitions
|
|
3441
3579
|
generateColumns(validColumns, tableOptions) {
|
|
3442
3580
|
const columnHelper = createColumnHelper();
|
|
3443
3581
|
if (validColumns.length > 0) {
|
|
3444
3582
|
// Use defined columns
|
|
3445
|
-
return validColumns.map(column =>
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
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
|
+
});
|
|
3450
3605
|
}
|
|
3451
3606
|
else if (tableOptions.data && tableOptions.data.length > 0) {
|
|
3452
3607
|
// Generate columns from data keys
|
|
3453
3608
|
const sampleRow = tableOptions.data[0];
|
|
3454
3609
|
return Object.keys(sampleRow).map(key => columnHelper.accessor(key, {
|
|
3455
|
-
header: key.charAt(0).toUpperCase() + key.slice(1), // Capitalize key for header
|
|
3456
|
-
cell: info =>
|
|
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
|
+
},
|
|
3457
3625
|
enableGlobalFilter: this.enableGlobalFilter,
|
|
3458
3626
|
}));
|
|
3459
3627
|
}
|
|
@@ -3482,11 +3650,11 @@ const NvDatagrid = class {
|
|
|
3482
3650
|
// Replace placeholders in text content, attributes, and properties
|
|
3483
3651
|
element.querySelectorAll('*').forEach(el => {
|
|
3484
3652
|
// Replace placeholders in text content
|
|
3485
|
-
this.replacePlaceholdersTextContent(el, cellValue);
|
|
3653
|
+
this.replacePlaceholdersTextContent(el, cellValue, row);
|
|
3486
3654
|
// Replace placeholders in attributes
|
|
3487
|
-
this.replacePlaceholdersAttributes(el, cellValue);
|
|
3655
|
+
this.replacePlaceholdersAttributes(el, cellValue, row);
|
|
3488
3656
|
// Replace placeholders in properties
|
|
3489
|
-
this.replacePlaceholdersProperties(el, cellValue);
|
|
3657
|
+
this.replacePlaceholdersProperties(el, cellValue, row);
|
|
3490
3658
|
});
|
|
3491
3659
|
// Handle `data-bind-event`
|
|
3492
3660
|
element.querySelectorAll('[data-bind-event]').forEach(el => {
|
|
@@ -3585,51 +3753,128 @@ const NvDatagrid = class {
|
|
|
3585
3753
|
// If cellValue is a primitive (string, number, boolean, etc.), return it as a string
|
|
3586
3754
|
return (_a = cellValue === null || cellValue === void 0 ? void 0 : cellValue.toString()) !== null && _a !== void 0 ? _a : this.fallbackValue;
|
|
3587
3755
|
}
|
|
3588
|
-
replacePlaceholdersTextContent(element, cellValue) {
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
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
|
+
}
|
|
3595
3783
|
}
|
|
3596
|
-
replacePlaceholdersAttributes(element, cellValue) {
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
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
|
+
}
|
|
3603
3811
|
}
|
|
3604
|
-
replacePlaceholdersProperties(element, cellValue) {
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
Object.keys(
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
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
|
+
) {
|
|
3622
3833
|
const propValue = element[prop];
|
|
3623
|
-
// ✅ Replace placeholders only if the value is a string
|
|
3624
3834
|
if (typeof propValue === 'string' && propValue.includes('__')) {
|
|
3625
|
-
element[prop] = propValue.replace(/__([\w.]+)__/g, (_, key) =>
|
|
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
|
+
});
|
|
3626
3844
|
}
|
|
3627
3845
|
}
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
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);
|
|
3631
3858
|
}
|
|
3632
|
-
|
|
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
|
+
}
|
|
3633
3878
|
}
|
|
3634
3879
|
//#endregion METHODS
|
|
3635
3880
|
/****************************************************************************/
|
|
@@ -3663,14 +3908,30 @@ const NvDatagrid = class {
|
|
|
3663
3908
|
handleParsedChange() {
|
|
3664
3909
|
this.initializeTable();
|
|
3665
3910
|
}
|
|
3666
|
-
|
|
3911
|
+
handleGlobalFilterSearchTerm(newValue) {
|
|
3912
|
+
if (!this.table) {
|
|
3913
|
+
console.warn('Table is not initialized yet.');
|
|
3914
|
+
return;
|
|
3915
|
+
}
|
|
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) {
|
|
3667
3923
|
if (!this.table) {
|
|
3668
3924
|
console.warn('Table is not initialized yet.');
|
|
3669
3925
|
return;
|
|
3670
3926
|
}
|
|
3671
|
-
//
|
|
3672
|
-
|
|
3673
|
-
|
|
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
|
+
}
|
|
3674
3935
|
}
|
|
3675
3936
|
//#endregion WATCHERS
|
|
3676
3937
|
/****************************************************************************/
|
|
@@ -3679,41 +3940,39 @@ const NvDatagrid = class {
|
|
|
3679
3940
|
this.cacheTemplates();
|
|
3680
3941
|
this.parseDataAndColumns();
|
|
3681
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
|
+
}
|
|
3682
3951
|
}
|
|
3683
3952
|
//#endregion EVENTS
|
|
3684
3953
|
/****************************************************************************/
|
|
3685
3954
|
//#region RENDER
|
|
3686
3955
|
render() {
|
|
3687
|
-
var _a, _b, _c, _d;
|
|
3956
|
+
var _a, _b, _c, _d, _e;
|
|
3688
3957
|
const headerGroups = !this.table || this.table === undefined || this.parsedColumns.length === 0
|
|
3689
3958
|
? []
|
|
3690
3959
|
: (_a = this.table) === null || _a === void 0 ? void 0 : _a.getHeaderGroups();
|
|
3691
3960
|
const rows = !this.table || this.table === undefined || this.parsedData.length === 0
|
|
3692
3961
|
? []
|
|
3693
3962
|
: (_c = (_b = this.table) === null || _b === void 0 ? void 0 : _b.getRowModel()) === null || _c === void 0 ? void 0 : _c.rows;
|
|
3694
|
-
return (index.h(index.Host, { key: '
|
|
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
|
|
3695
3964
|
? headerGroups === null || headerGroups === void 0 ? void 0 : headerGroups.map(headerGroup => (index.h("tr", { key: headerGroup.id }, headerGroup.headers.map(header => {
|
|
3696
3965
|
return (index.h("th", { key: header.id }, header.isPlaceholder
|
|
3697
3966
|
? null
|
|
3698
|
-
: this.
|
|
3967
|
+
: this.flexRender(header.column.columnDef.header, header.getContext())));
|
|
3699
3968
|
}))))
|
|
3700
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 => {
|
|
3701
3970
|
const rowId = row.id;
|
|
3702
3971
|
const visibleCells = row === null || row === void 0 ? void 0 : row.getVisibleCells();
|
|
3703
3972
|
return (index.h("tr", { key: rowId }, visibleCells.map(cell => {
|
|
3704
|
-
|
|
3705
|
-
const cellAccessors = cell.column.id;
|
|
3706
|
-
const cellValue = cell.getValue();
|
|
3707
|
-
return (index.h("td", { key: cell.id, "data-row-id": rowId }, ((_a = this.columnData.find(x => x.accessor === cellAccessors)) === null || _a === void 0 ? void 0 : _a.repeatTemplate) && Array.isArray(cellValue)
|
|
3708
|
-
? cellValue.map((item) => {
|
|
3709
|
-
var _a;
|
|
3710
|
-
return (_a = (this.renderTemplate(this.templateCache.get(cellAccessors), item, row) ||
|
|
3711
|
-
item)) !== null && _a !== void 0 ? _a : this.fallbackValue;
|
|
3712
|
-
})
|
|
3713
|
-
: (_b = (this.renderTemplate(this.templateCache.get(cellAccessors), cellValue, row) ||
|
|
3714
|
-
cellValue)) !== null && _b !== void 0 ? _b : this.fallbackValue));
|
|
3973
|
+
return (index.h("td", { key: cell.id, "data-row-id": rowId }, this.flexRender(cell.column.columnDef.cell, cell.getContext())));
|
|
3715
3974
|
})));
|
|
3716
|
-
}))))), index.h("slot", { key: '
|
|
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" })));
|
|
3717
3976
|
}
|
|
3718
3977
|
get el() { return index.getElement(this); }
|
|
3719
3978
|
static get watchers() { return {
|
|
@@ -3723,7 +3982,8 @@ const NvDatagrid = class {
|
|
|
3723
3982
|
"dataJson": ["parseJsonData"],
|
|
3724
3983
|
"parsedColumns": ["handleParsedChange"],
|
|
3725
3984
|
"parsedData": ["handleParsedChange"],
|
|
3726
|
-
"
|
|
3985
|
+
"globalFilterSearchTerm": ["handleGlobalFilterSearchTerm"],
|
|
3986
|
+
"paginationState": ["handlePaginationState"]
|
|
3727
3987
|
}; }
|
|
3728
3988
|
};
|
|
3729
3989
|
NvDatagrid.style = NvDatagridStyle0;
|
package/dist/cjs/{nv-datagridcolumn.entry-7whgB5iS.js → nv-datagridcolumn.entry-CRogHbVM.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-Byv3Vmev.js');
|
|
4
4
|
require('react');
|
|
5
5
|
|
|
6
6
|
const NvDatagridcolumn = class {
|
|
@@ -15,7 +15,7 @@ const NvDatagridcolumn = class {
|
|
|
15
15
|
/****************************************************************************/
|
|
16
16
|
//#region RENDER
|
|
17
17
|
render() {
|
|
18
|
-
return (index.h(index.Host, { key: '
|
|
18
|
+
return (index.h(index.Host, { key: '20839d4a0abfa07e55a49b434ad26e3ddaebb66b' }, index.h("slot", { key: '2c1b24aef73e9be8e500d48741e4dc6a42ed6f06', name: "header" }), index.h("slot", { key: 'cbc4bcbb080f8647c6f702e4a52411fe9be1f6ca', name: "cell" })));
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
|