hs-uix 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -2
- package/common-components.d.ts +55 -0
- package/dist/common-components.js +260 -0
- package/dist/common-components.mjs +221 -0
- package/dist/datatable.js +74 -38
- package/dist/datatable.mjs +74 -38
- package/dist/form.js +204 -76
- package/dist/form.mjs +204 -76
- package/dist/index.js +486 -114
- package/dist/index.mjs +481 -114
- package/dist/utils.js +269 -0
- package/dist/utils.mjs +230 -0
- package/index.d.ts +21 -0
- package/package.json +14 -2
- package/utils.d.ts +59 -0
package/dist/datatable.js
CHANGED
|
@@ -309,7 +309,9 @@ var DataTable = ({
|
|
|
309
309
|
const initialSortState = (0, import_react.useMemo)(() => {
|
|
310
310
|
return normalizeSortState(columns, defaultSort);
|
|
311
311
|
}, [columns, defaultSort]);
|
|
312
|
-
const [internalSearchTerm, setInternalSearchTerm] = (0, import_react.useState)(
|
|
312
|
+
const [internalSearchTerm, setInternalSearchTerm] = (0, import_react.useState)(
|
|
313
|
+
() => serverSide && searchValue != null ? searchValue : ""
|
|
314
|
+
);
|
|
313
315
|
const [internalFilterValues, setInternalFilterValues] = (0, import_react.useState)(() => {
|
|
314
316
|
const init = {};
|
|
315
317
|
filters.forEach((f) => {
|
|
@@ -320,7 +322,16 @@ var DataTable = ({
|
|
|
320
322
|
const [internalSortState, setInternalSortState] = (0, import_react.useState)(initialSortState);
|
|
321
323
|
const [currentPage, setCurrentPage] = (0, import_react.useState)(1);
|
|
322
324
|
const [showMoreFilters, setShowMoreFilters] = (0, import_react.useState)(false);
|
|
325
|
+
const lastAppliedSearchRef = (0, import_react.useRef)(
|
|
326
|
+
serverSide && searchValue != null ? searchValue : ""
|
|
327
|
+
);
|
|
323
328
|
const searchTerm = serverSide && searchValue != null ? searchValue : internalSearchTerm;
|
|
329
|
+
(0, import_react.useEffect)(() => {
|
|
330
|
+
if (!serverSide || searchValue == null) return;
|
|
331
|
+
if (searchValue === lastAppliedSearchRef.current) return;
|
|
332
|
+
lastAppliedSearchRef.current = searchValue;
|
|
333
|
+
setInternalSearchTerm(searchValue);
|
|
334
|
+
}, [serverSide, searchValue]);
|
|
324
335
|
const filterValues = serverSide && externalFilterValues != null ? externalFilterValues : internalFilterValues;
|
|
325
336
|
const externalSortState = (0, import_react.useMemo)(
|
|
326
337
|
() => normalizeSortState(columns, externalSort),
|
|
@@ -354,15 +365,16 @@ var DataTable = ({
|
|
|
354
365
|
const handleSearchChange = (0, import_react.useCallback)((term) => {
|
|
355
366
|
setInternalSearchTerm(term);
|
|
356
367
|
resetPage();
|
|
368
|
+
const dispatch = () => {
|
|
369
|
+
lastAppliedSearchRef.current = term;
|
|
370
|
+
fireSearchCallback(term);
|
|
371
|
+
fireParamsChange({ search: term, page: resetPageOnChange ? 1 : void 0 });
|
|
372
|
+
};
|
|
357
373
|
if (searchDebounce > 0) {
|
|
358
374
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
359
|
-
debounceRef.current = setTimeout(
|
|
360
|
-
fireSearchCallback(term);
|
|
361
|
-
fireParamsChange({ search: term, page: resetPageOnChange ? 1 : void 0 });
|
|
362
|
-
}, searchDebounce);
|
|
375
|
+
debounceRef.current = setTimeout(dispatch, searchDebounce);
|
|
363
376
|
} else {
|
|
364
|
-
|
|
365
|
-
fireParamsChange({ search: term, page: resetPageOnChange ? 1 : void 0 });
|
|
377
|
+
dispatch();
|
|
366
378
|
}
|
|
367
379
|
}, [searchDebounce, fireSearchCallback, fireParamsChange, resetPage, resetPageOnChange]);
|
|
368
380
|
(0, import_react.useEffect)(() => () => {
|
|
@@ -444,10 +456,23 @@ var DataTable = ({
|
|
|
444
456
|
if (serverSide) return filteredData;
|
|
445
457
|
const activeField = Object.keys(sortState).find((k) => sortState[k] !== "none");
|
|
446
458
|
if (!activeField) return filteredData;
|
|
459
|
+
const activeCol = columns.find((c) => c.field === activeField);
|
|
460
|
+
const sortOrder = Array.isArray(activeCol == null ? void 0 : activeCol.sortOrder) ? activeCol.sortOrder : null;
|
|
461
|
+
const sortOrderIndex = (val) => {
|
|
462
|
+
const idx = sortOrder.indexOf(val);
|
|
463
|
+
return idx === -1 ? sortOrder.length : idx;
|
|
464
|
+
};
|
|
447
465
|
return [...filteredData].sort((a, b) => {
|
|
448
466
|
const dir = sortState[activeField] === "ascending" ? 1 : -1;
|
|
449
467
|
const aVal = a[activeField];
|
|
450
468
|
const bVal = b[activeField];
|
|
469
|
+
if (typeof (activeCol == null ? void 0 : activeCol.sortComparator) === "function") {
|
|
470
|
+
return dir * activeCol.sortComparator(aVal, bVal, a, b);
|
|
471
|
+
}
|
|
472
|
+
if (sortOrder) {
|
|
473
|
+
const diff = sortOrderIndex(aVal) - sortOrderIndex(bVal);
|
|
474
|
+
if (diff !== 0) return dir * diff;
|
|
475
|
+
}
|
|
451
476
|
if (aVal == null && bVal == null) return 0;
|
|
452
477
|
if (aVal == null) return 1;
|
|
453
478
|
if (bVal == null) return -1;
|
|
@@ -455,7 +480,7 @@ var DataTable = ({
|
|
|
455
480
|
if (aVal > bVal) return dir;
|
|
456
481
|
return 0;
|
|
457
482
|
});
|
|
458
|
-
}, [filteredData, sortState, serverSide]);
|
|
483
|
+
}, [filteredData, sortState, serverSide, columns]);
|
|
459
484
|
const groupedData = (0, import_react.useMemo)(() => {
|
|
460
485
|
if (!groupBy) return null;
|
|
461
486
|
const source = serverSide ? data : sortedData;
|
|
@@ -507,28 +532,33 @@ var DataTable = ({
|
|
|
507
532
|
return next;
|
|
508
533
|
});
|
|
509
534
|
}, []);
|
|
510
|
-
const
|
|
511
|
-
if (!groupedData) return
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
if (expandedGroups.has(group.key)) {
|
|
516
|
-
group.rows.forEach((row) => flat.push({ type: "data", row }));
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
return flat;
|
|
520
|
-
}, [groupedData, sortedData, data, serverSide, expandedGroups]);
|
|
521
|
-
const totalItems = serverSide ? totalCount || data.length : flatRows.length;
|
|
535
|
+
const datasetRows = (0, import_react.useMemo)(() => {
|
|
536
|
+
if (!groupedData) return serverSide ? data : sortedData;
|
|
537
|
+
return groupedData.flatMap((group) => group.rows);
|
|
538
|
+
}, [groupedData, sortedData, data, serverSide]);
|
|
539
|
+
const totalItems = serverSide ? totalCount || data.length : datasetRows.length;
|
|
522
540
|
const pageCount = Math.ceil(totalItems / pageSize);
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
} else {
|
|
527
|
-
displayRows = flatRows.slice(
|
|
541
|
+
const paginatedRows = (0, import_react.useMemo)(() => {
|
|
542
|
+
if (serverSide) return datasetRows;
|
|
543
|
+
return datasetRows.slice(
|
|
528
544
|
(activePage - 1) * pageSize,
|
|
529
545
|
activePage * pageSize
|
|
530
546
|
);
|
|
531
|
-
}
|
|
547
|
+
}, [serverSide, datasetRows, activePage, pageSize]);
|
|
548
|
+
const displayRows = (0, import_react.useMemo)(() => {
|
|
549
|
+
if (!groupedData) return paginatedRows.map((row) => ({ type: "data", row }));
|
|
550
|
+
const pageRows = new Set(paginatedRows);
|
|
551
|
+
const rows = [];
|
|
552
|
+
groupedData.forEach((group) => {
|
|
553
|
+
const groupPageRows = group.rows.filter((row) => pageRows.has(row));
|
|
554
|
+
if (groupPageRows.length === 0) return;
|
|
555
|
+
rows.push({ type: "group-header", group });
|
|
556
|
+
if (expandedGroups.has(group.key)) {
|
|
557
|
+
groupPageRows.forEach((row) => rows.push({ type: "data", row }));
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
return rows;
|
|
561
|
+
}, [groupedData, paginatedRows, expandedGroups]);
|
|
532
562
|
const footerData = serverSide ? data : filteredData;
|
|
533
563
|
const activeChips = (0, import_react.useMemo)(() => {
|
|
534
564
|
const chips = [];
|
|
@@ -639,8 +669,8 @@ var DataTable = ({
|
|
|
639
669
|
return displayRows.filter((r) => r.type === "data").map((r) => r.row[rowIdField]).filter((id) => id != null);
|
|
640
670
|
}, [serverSide, data, displayRows, rowIdField]);
|
|
641
671
|
const allRowIds = (0, import_react.useMemo)(
|
|
642
|
-
() =>
|
|
643
|
-
[
|
|
672
|
+
() => datasetRows.map((row) => row[rowIdField]).filter((id) => id != null),
|
|
673
|
+
[datasetRows, rowIdField]
|
|
644
674
|
);
|
|
645
675
|
const handleSelectRow = (0, import_react.useCallback)((rowId, checked) => {
|
|
646
676
|
const next = new Set(selectedIds);
|
|
@@ -687,19 +717,25 @@ var DataTable = ({
|
|
|
687
717
|
if (row) onEditStart(row, field, currentValue);
|
|
688
718
|
}
|
|
689
719
|
}, [onEditStart, data, rowIdField]);
|
|
690
|
-
const commitEdit = (0, import_react.useCallback)((row, field, value) => {
|
|
720
|
+
const commitEdit = (0, import_react.useCallback)((row, field, value, options = {}) => {
|
|
721
|
+
const { keepEditing = false } = options;
|
|
691
722
|
const col = columns.find((c) => c.field === field);
|
|
692
723
|
if (col == null ? void 0 : col.editValidate) {
|
|
693
724
|
const result = col.editValidate(value, row);
|
|
694
725
|
if (result !== true && result !== void 0 && result !== null) {
|
|
695
726
|
setEditError(typeof result === "string" ? result : "Invalid value");
|
|
696
|
-
return;
|
|
727
|
+
return false;
|
|
697
728
|
}
|
|
698
729
|
}
|
|
699
730
|
if (onRowEdit) onRowEdit(row, field, value);
|
|
700
|
-
|
|
701
|
-
|
|
731
|
+
if (!keepEditing) {
|
|
732
|
+
setEditingCell(null);
|
|
733
|
+
setEditValue(null);
|
|
734
|
+
} else {
|
|
735
|
+
setEditValue(value);
|
|
736
|
+
}
|
|
702
737
|
setEditError(null);
|
|
738
|
+
return true;
|
|
703
739
|
}, [onRowEdit, columns]);
|
|
704
740
|
const renderEditControl = (col, row) => {
|
|
705
741
|
const type = col.editType || "text";
|
|
@@ -758,12 +794,12 @@ var DataTable = ({
|
|
|
758
794
|
case "datetime":
|
|
759
795
|
return /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.Flex, { direction: "row", align: "center", gap: "xs", wrap: "nowrap" }, /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.DateInput, { ...extra, name: `${fieldName}-date`, label: "", value: editValue == null ? void 0 : editValue.date, onChange: (val) => {
|
|
760
796
|
const next = { ...editValue, date: val };
|
|
761
|
-
|
|
762
|
-
|
|
797
|
+
handleInput(next);
|
|
798
|
+
commitEdit(row, col.field, next, { keepEditing: true });
|
|
763
799
|
}, onBlur: maybeExitDatetimeEdit }), /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.TimeInput, { ...extra.timeProps || {}, name: `${fieldName}-time`, label: "", value: editValue == null ? void 0 : editValue.time, onChange: (val) => {
|
|
764
800
|
const next = { ...editValue, time: val };
|
|
765
|
-
|
|
766
|
-
|
|
801
|
+
handleInput(next);
|
|
802
|
+
commitEdit(row, col.field, next, { keepEditing: true });
|
|
767
803
|
}, onBlur: maybeExitDatetimeEdit }));
|
|
768
804
|
case "toggle":
|
|
769
805
|
return /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.Toggle, { ...extra, name: fieldName, label: "", checked: !!editValue, onChange: commit });
|
|
@@ -968,12 +1004,12 @@ var DataTable = ({
|
|
|
968
1004
|
}
|
|
969
1005
|
);
|
|
970
1006
|
};
|
|
971
|
-
return /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.Flex, { direction: "column", gap: "xs" }, /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.Flex, { direction: "row", gap: "sm" }, /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.Box, { flex: 3 }, /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.Flex, { direction: "column", gap: "sm" }, /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.Flex, { direction: "row", align: "
|
|
1007
|
+
return /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.Flex, { direction: "column", gap: "xs" }, /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.Flex, { direction: "row", gap: "sm" }, /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.Box, { flex: 3 }, /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.Flex, { direction: "column", gap: "sm" }, /* @__PURE__ */ import_react.default.createElement(import_ui_extensions.Flex, { direction: "row", align: "end", gap: "sm", wrap: "wrap" }, showSearch && searchFields.length > 0 && /* @__PURE__ */ import_react.default.createElement(
|
|
972
1008
|
import_ui_extensions.SearchInput,
|
|
973
1009
|
{
|
|
974
1010
|
name: "datatable-search",
|
|
975
1011
|
placeholder: searchPlaceholder,
|
|
976
|
-
value:
|
|
1012
|
+
value: internalSearchTerm,
|
|
977
1013
|
onChange: handleSearchChange
|
|
978
1014
|
}
|
|
979
1015
|
), filters.slice(0, filterInlineLimit).map(renderFilterControl), filters.length > filterInlineLimit && /* @__PURE__ */ import_react.default.createElement(
|
package/dist/datatable.mjs
CHANGED
|
@@ -304,7 +304,9 @@ var DataTable = ({
|
|
|
304
304
|
const initialSortState = useMemo(() => {
|
|
305
305
|
return normalizeSortState(columns, defaultSort);
|
|
306
306
|
}, [columns, defaultSort]);
|
|
307
|
-
const [internalSearchTerm, setInternalSearchTerm] = useState(
|
|
307
|
+
const [internalSearchTerm, setInternalSearchTerm] = useState(
|
|
308
|
+
() => serverSide && searchValue != null ? searchValue : ""
|
|
309
|
+
);
|
|
308
310
|
const [internalFilterValues, setInternalFilterValues] = useState(() => {
|
|
309
311
|
const init = {};
|
|
310
312
|
filters.forEach((f) => {
|
|
@@ -315,7 +317,16 @@ var DataTable = ({
|
|
|
315
317
|
const [internalSortState, setInternalSortState] = useState(initialSortState);
|
|
316
318
|
const [currentPage, setCurrentPage] = useState(1);
|
|
317
319
|
const [showMoreFilters, setShowMoreFilters] = useState(false);
|
|
320
|
+
const lastAppliedSearchRef = useRef(
|
|
321
|
+
serverSide && searchValue != null ? searchValue : ""
|
|
322
|
+
);
|
|
318
323
|
const searchTerm = serverSide && searchValue != null ? searchValue : internalSearchTerm;
|
|
324
|
+
useEffect(() => {
|
|
325
|
+
if (!serverSide || searchValue == null) return;
|
|
326
|
+
if (searchValue === lastAppliedSearchRef.current) return;
|
|
327
|
+
lastAppliedSearchRef.current = searchValue;
|
|
328
|
+
setInternalSearchTerm(searchValue);
|
|
329
|
+
}, [serverSide, searchValue]);
|
|
319
330
|
const filterValues = serverSide && externalFilterValues != null ? externalFilterValues : internalFilterValues;
|
|
320
331
|
const externalSortState = useMemo(
|
|
321
332
|
() => normalizeSortState(columns, externalSort),
|
|
@@ -349,15 +360,16 @@ var DataTable = ({
|
|
|
349
360
|
const handleSearchChange = useCallback((term) => {
|
|
350
361
|
setInternalSearchTerm(term);
|
|
351
362
|
resetPage();
|
|
363
|
+
const dispatch = () => {
|
|
364
|
+
lastAppliedSearchRef.current = term;
|
|
365
|
+
fireSearchCallback(term);
|
|
366
|
+
fireParamsChange({ search: term, page: resetPageOnChange ? 1 : void 0 });
|
|
367
|
+
};
|
|
352
368
|
if (searchDebounce > 0) {
|
|
353
369
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
354
|
-
debounceRef.current = setTimeout(
|
|
355
|
-
fireSearchCallback(term);
|
|
356
|
-
fireParamsChange({ search: term, page: resetPageOnChange ? 1 : void 0 });
|
|
357
|
-
}, searchDebounce);
|
|
370
|
+
debounceRef.current = setTimeout(dispatch, searchDebounce);
|
|
358
371
|
} else {
|
|
359
|
-
|
|
360
|
-
fireParamsChange({ search: term, page: resetPageOnChange ? 1 : void 0 });
|
|
372
|
+
dispatch();
|
|
361
373
|
}
|
|
362
374
|
}, [searchDebounce, fireSearchCallback, fireParamsChange, resetPage, resetPageOnChange]);
|
|
363
375
|
useEffect(() => () => {
|
|
@@ -439,10 +451,23 @@ var DataTable = ({
|
|
|
439
451
|
if (serverSide) return filteredData;
|
|
440
452
|
const activeField = Object.keys(sortState).find((k) => sortState[k] !== "none");
|
|
441
453
|
if (!activeField) return filteredData;
|
|
454
|
+
const activeCol = columns.find((c) => c.field === activeField);
|
|
455
|
+
const sortOrder = Array.isArray(activeCol == null ? void 0 : activeCol.sortOrder) ? activeCol.sortOrder : null;
|
|
456
|
+
const sortOrderIndex = (val) => {
|
|
457
|
+
const idx = sortOrder.indexOf(val);
|
|
458
|
+
return idx === -1 ? sortOrder.length : idx;
|
|
459
|
+
};
|
|
442
460
|
return [...filteredData].sort((a, b) => {
|
|
443
461
|
const dir = sortState[activeField] === "ascending" ? 1 : -1;
|
|
444
462
|
const aVal = a[activeField];
|
|
445
463
|
const bVal = b[activeField];
|
|
464
|
+
if (typeof (activeCol == null ? void 0 : activeCol.sortComparator) === "function") {
|
|
465
|
+
return dir * activeCol.sortComparator(aVal, bVal, a, b);
|
|
466
|
+
}
|
|
467
|
+
if (sortOrder) {
|
|
468
|
+
const diff = sortOrderIndex(aVal) - sortOrderIndex(bVal);
|
|
469
|
+
if (diff !== 0) return dir * diff;
|
|
470
|
+
}
|
|
446
471
|
if (aVal == null && bVal == null) return 0;
|
|
447
472
|
if (aVal == null) return 1;
|
|
448
473
|
if (bVal == null) return -1;
|
|
@@ -450,7 +475,7 @@ var DataTable = ({
|
|
|
450
475
|
if (aVal > bVal) return dir;
|
|
451
476
|
return 0;
|
|
452
477
|
});
|
|
453
|
-
}, [filteredData, sortState, serverSide]);
|
|
478
|
+
}, [filteredData, sortState, serverSide, columns]);
|
|
454
479
|
const groupedData = useMemo(() => {
|
|
455
480
|
if (!groupBy) return null;
|
|
456
481
|
const source = serverSide ? data : sortedData;
|
|
@@ -502,28 +527,33 @@ var DataTable = ({
|
|
|
502
527
|
return next;
|
|
503
528
|
});
|
|
504
529
|
}, []);
|
|
505
|
-
const
|
|
506
|
-
if (!groupedData) return
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
if (expandedGroups.has(group.key)) {
|
|
511
|
-
group.rows.forEach((row) => flat.push({ type: "data", row }));
|
|
512
|
-
}
|
|
513
|
-
});
|
|
514
|
-
return flat;
|
|
515
|
-
}, [groupedData, sortedData, data, serverSide, expandedGroups]);
|
|
516
|
-
const totalItems = serverSide ? totalCount || data.length : flatRows.length;
|
|
530
|
+
const datasetRows = useMemo(() => {
|
|
531
|
+
if (!groupedData) return serverSide ? data : sortedData;
|
|
532
|
+
return groupedData.flatMap((group) => group.rows);
|
|
533
|
+
}, [groupedData, sortedData, data, serverSide]);
|
|
534
|
+
const totalItems = serverSide ? totalCount || data.length : datasetRows.length;
|
|
517
535
|
const pageCount = Math.ceil(totalItems / pageSize);
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
} else {
|
|
522
|
-
displayRows = flatRows.slice(
|
|
536
|
+
const paginatedRows = useMemo(() => {
|
|
537
|
+
if (serverSide) return datasetRows;
|
|
538
|
+
return datasetRows.slice(
|
|
523
539
|
(activePage - 1) * pageSize,
|
|
524
540
|
activePage * pageSize
|
|
525
541
|
);
|
|
526
|
-
}
|
|
542
|
+
}, [serverSide, datasetRows, activePage, pageSize]);
|
|
543
|
+
const displayRows = useMemo(() => {
|
|
544
|
+
if (!groupedData) return paginatedRows.map((row) => ({ type: "data", row }));
|
|
545
|
+
const pageRows = new Set(paginatedRows);
|
|
546
|
+
const rows = [];
|
|
547
|
+
groupedData.forEach((group) => {
|
|
548
|
+
const groupPageRows = group.rows.filter((row) => pageRows.has(row));
|
|
549
|
+
if (groupPageRows.length === 0) return;
|
|
550
|
+
rows.push({ type: "group-header", group });
|
|
551
|
+
if (expandedGroups.has(group.key)) {
|
|
552
|
+
groupPageRows.forEach((row) => rows.push({ type: "data", row }));
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
return rows;
|
|
556
|
+
}, [groupedData, paginatedRows, expandedGroups]);
|
|
527
557
|
const footerData = serverSide ? data : filteredData;
|
|
528
558
|
const activeChips = useMemo(() => {
|
|
529
559
|
const chips = [];
|
|
@@ -634,8 +664,8 @@ var DataTable = ({
|
|
|
634
664
|
return displayRows.filter((r) => r.type === "data").map((r) => r.row[rowIdField]).filter((id) => id != null);
|
|
635
665
|
}, [serverSide, data, displayRows, rowIdField]);
|
|
636
666
|
const allRowIds = useMemo(
|
|
637
|
-
() =>
|
|
638
|
-
[
|
|
667
|
+
() => datasetRows.map((row) => row[rowIdField]).filter((id) => id != null),
|
|
668
|
+
[datasetRows, rowIdField]
|
|
639
669
|
);
|
|
640
670
|
const handleSelectRow = useCallback((rowId, checked) => {
|
|
641
671
|
const next = new Set(selectedIds);
|
|
@@ -682,19 +712,25 @@ var DataTable = ({
|
|
|
682
712
|
if (row) onEditStart(row, field, currentValue);
|
|
683
713
|
}
|
|
684
714
|
}, [onEditStart, data, rowIdField]);
|
|
685
|
-
const commitEdit = useCallback((row, field, value) => {
|
|
715
|
+
const commitEdit = useCallback((row, field, value, options = {}) => {
|
|
716
|
+
const { keepEditing = false } = options;
|
|
686
717
|
const col = columns.find((c) => c.field === field);
|
|
687
718
|
if (col == null ? void 0 : col.editValidate) {
|
|
688
719
|
const result = col.editValidate(value, row);
|
|
689
720
|
if (result !== true && result !== void 0 && result !== null) {
|
|
690
721
|
setEditError(typeof result === "string" ? result : "Invalid value");
|
|
691
|
-
return;
|
|
722
|
+
return false;
|
|
692
723
|
}
|
|
693
724
|
}
|
|
694
725
|
if (onRowEdit) onRowEdit(row, field, value);
|
|
695
|
-
|
|
696
|
-
|
|
726
|
+
if (!keepEditing) {
|
|
727
|
+
setEditingCell(null);
|
|
728
|
+
setEditValue(null);
|
|
729
|
+
} else {
|
|
730
|
+
setEditValue(value);
|
|
731
|
+
}
|
|
697
732
|
setEditError(null);
|
|
733
|
+
return true;
|
|
698
734
|
}, [onRowEdit, columns]);
|
|
699
735
|
const renderEditControl = (col, row) => {
|
|
700
736
|
const type = col.editType || "text";
|
|
@@ -753,12 +789,12 @@ var DataTable = ({
|
|
|
753
789
|
case "datetime":
|
|
754
790
|
return /* @__PURE__ */ React.createElement(Flex, { direction: "row", align: "center", gap: "xs", wrap: "nowrap" }, /* @__PURE__ */ React.createElement(DateInput, { ...extra, name: `${fieldName}-date`, label: "", value: editValue == null ? void 0 : editValue.date, onChange: (val) => {
|
|
755
791
|
const next = { ...editValue, date: val };
|
|
756
|
-
|
|
757
|
-
|
|
792
|
+
handleInput(next);
|
|
793
|
+
commitEdit(row, col.field, next, { keepEditing: true });
|
|
758
794
|
}, onBlur: maybeExitDatetimeEdit }), /* @__PURE__ */ React.createElement(TimeInput, { ...extra.timeProps || {}, name: `${fieldName}-time`, label: "", value: editValue == null ? void 0 : editValue.time, onChange: (val) => {
|
|
759
795
|
const next = { ...editValue, time: val };
|
|
760
|
-
|
|
761
|
-
|
|
796
|
+
handleInput(next);
|
|
797
|
+
commitEdit(row, col.field, next, { keepEditing: true });
|
|
762
798
|
}, onBlur: maybeExitDatetimeEdit }));
|
|
763
799
|
case "toggle":
|
|
764
800
|
return /* @__PURE__ */ React.createElement(Toggle, { ...extra, name: fieldName, label: "", checked: !!editValue, onChange: commit });
|
|
@@ -963,12 +999,12 @@ var DataTable = ({
|
|
|
963
999
|
}
|
|
964
1000
|
);
|
|
965
1001
|
};
|
|
966
|
-
return /* @__PURE__ */ React.createElement(Flex, { direction: "column", gap: "xs" }, /* @__PURE__ */ React.createElement(Flex, { direction: "row", gap: "sm" }, /* @__PURE__ */ React.createElement(Box, { flex: 3 }, /* @__PURE__ */ React.createElement(Flex, { direction: "column", gap: "sm" }, /* @__PURE__ */ React.createElement(Flex, { direction: "row", align: "
|
|
1002
|
+
return /* @__PURE__ */ React.createElement(Flex, { direction: "column", gap: "xs" }, /* @__PURE__ */ React.createElement(Flex, { direction: "row", gap: "sm" }, /* @__PURE__ */ React.createElement(Box, { flex: 3 }, /* @__PURE__ */ React.createElement(Flex, { direction: "column", gap: "sm" }, /* @__PURE__ */ React.createElement(Flex, { direction: "row", align: "end", gap: "sm", wrap: "wrap" }, showSearch && searchFields.length > 0 && /* @__PURE__ */ React.createElement(
|
|
967
1003
|
SearchInput,
|
|
968
1004
|
{
|
|
969
1005
|
name: "datatable-search",
|
|
970
1006
|
placeholder: searchPlaceholder,
|
|
971
|
-
value:
|
|
1007
|
+
value: internalSearchTerm,
|
|
972
1008
|
onChange: handleSearchChange
|
|
973
1009
|
}
|
|
974
1010
|
), filters.slice(0, filterInlineLimit).map(renderFilterControl), filters.length > filterInlineLimit && /* @__PURE__ */ React.createElement(
|