trotl-table 1.0.93 → 1.0.96
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 +4 -2
- package/dist/Table.cjs.js +70 -16
- package/dist/Table.cjs.js.map +1 -1
- package/dist/Table.esm.js +70 -16
- package/dist/Table.esm.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -138,8 +138,10 @@ export default function Demo() {
|
|
|
138
138
|
- `downloadCallback`: callback invoked when the user clicks the **download** action (row passed as argument)
|
|
139
139
|
- Note: earlier versions required the delete button for multi‑select; now `enableMultiSelect` works even when `buttons` is empty
|
|
140
140
|
- `buttons`: array of action buttons to show (supports `"view"`, `"edit"`, `"delete"`, `"share"`, `"duplicate"` and `"download"`)
|
|
141
|
-
- `onCellChange`: callback invoked when a cell value changes (signature: `(row, accessor, newValue)`).
|
|
142
|
-
- Supported editable column `type` values: `checkbox`, `switch` (renders a `Switch` component), `input` (renders a text input)
|
|
141
|
+
- `onCellChange`: callback invoked when a cell value changes (signature: `(row, accessor, newValue, column)`). The fourth argument is the column definition, including optional `collConnect` metadata.
|
|
142
|
+
- Supported editable column `type` values: `checkbox`, `switch` (renders a `Switch` component), `input` (renders a text input), and `date`.
|
|
143
|
+
- Date columns may use a scalar type (`type: "date"`) or an array with a display format (`type: ["date", "DD-MM-YYYY HH:mm"]`). Date-time formats render a date-time picker; values emitted by the input remain ISO-compatible.
|
|
144
|
+
- `collConnect` is metadata exposed through the fourth callback argument so applications can persist related field updates when a cell changes.
|
|
143
145
|
|
|
144
146
|
## 🌟 Context Hooks
|
|
145
147
|
|
package/dist/Table.cjs.js
CHANGED
|
@@ -9546,6 +9546,55 @@ _defineProperty(WindowScroller, "defaultProps", {
|
|
|
9546
9546
|
});
|
|
9547
9547
|
|
|
9548
9548
|
const ITEM_TYPE = "ROW";
|
|
9549
|
+
const getColumnType = column => Array.isArray(column?.type) ? column.type[0] : column?.type;
|
|
9550
|
+
const getColumnDateFormat = column => {
|
|
9551
|
+
if (Array.isArray(column?.type)) return column.type[1] || null;
|
|
9552
|
+
return column?.dateFormat || null;
|
|
9553
|
+
};
|
|
9554
|
+
const parseDateValue = value => {
|
|
9555
|
+
if (value instanceof Date) {
|
|
9556
|
+
return Number.isNaN(value.getTime()) ? null : value;
|
|
9557
|
+
}
|
|
9558
|
+
if (value == null || value === "") return null;
|
|
9559
|
+
const text = String(value).trim();
|
|
9560
|
+
const isoMatch = text.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/);
|
|
9561
|
+
if (isoMatch) {
|
|
9562
|
+
const [, year, month, day, hour = "0", minute = "0", second = "0"] = isoMatch;
|
|
9563
|
+
const date = new Date(Number(year), Number(month) - 1, Number(day), Number(hour), Number(minute), Number(second));
|
|
9564
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
9565
|
+
}
|
|
9566
|
+
const dmyMatch = text.match(/^(\d{2})-(\d{2})-(\d{4})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/);
|
|
9567
|
+
if (dmyMatch) {
|
|
9568
|
+
const [, day, month, year, hour = "0", minute = "0", second = "0"] = dmyMatch;
|
|
9569
|
+
const date = new Date(Number(year), Number(month) - 1, Number(day), Number(hour), Number(minute), Number(second));
|
|
9570
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
9571
|
+
}
|
|
9572
|
+
const date = new Date(value);
|
|
9573
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
9574
|
+
};
|
|
9575
|
+
const formatDateValue = (value, format) => {
|
|
9576
|
+
const date = parseDateValue(value);
|
|
9577
|
+
if (!date) return "";
|
|
9578
|
+
if (!format) return date.toLocaleString("sl-SI", {
|
|
9579
|
+
hour12: false
|
|
9580
|
+
});
|
|
9581
|
+
const parts = {
|
|
9582
|
+
YYYY: String(date.getFullYear()),
|
|
9583
|
+
MM: String(date.getMonth() + 1).padStart(2, "0"),
|
|
9584
|
+
DD: String(date.getDate()).padStart(2, "0"),
|
|
9585
|
+
HH: String(date.getHours()).padStart(2, "0"),
|
|
9586
|
+
mm: String(date.getMinutes()).padStart(2, "0"),
|
|
9587
|
+
ss: String(date.getSeconds()).padStart(2, "0")
|
|
9588
|
+
};
|
|
9589
|
+
return String(format).replace(/YYYY|MM|DD|HH|mm|ss/g, token => parts[token]);
|
|
9590
|
+
};
|
|
9591
|
+
const toDateInputValue = (value, includeTime) => {
|
|
9592
|
+
const date = parseDateValue(value);
|
|
9593
|
+
if (!date) return "";
|
|
9594
|
+
const datePart = [date.getFullYear(), String(date.getMonth() + 1).padStart(2, "0"), String(date.getDate()).padStart(2, "0")].join("-");
|
|
9595
|
+
if (!includeTime) return datePart;
|
|
9596
|
+
return `${datePart}T${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
|
|
9597
|
+
};
|
|
9549
9598
|
|
|
9550
9599
|
// Normalize data into grouped format
|
|
9551
9600
|
const normalizeData = (groups, rows) => {
|
|
@@ -9659,7 +9708,7 @@ function TableInner({
|
|
|
9659
9708
|
downloadCallback = () => {},
|
|
9660
9709
|
// new undelete callback
|
|
9661
9710
|
undeleteCallback = () => {},
|
|
9662
|
-
// callback for cell edits: (row, accessor, newValue)
|
|
9711
|
+
// callback for cell edits: (row, accessor, newValue, column)
|
|
9663
9712
|
onCellChange = () => {},
|
|
9664
9713
|
// callback for any cell click
|
|
9665
9714
|
cellCallback = () => {},
|
|
@@ -10579,7 +10628,7 @@ function TableInner({
|
|
|
10579
10628
|
const accessor = col?.accessor ?? null;
|
|
10580
10629
|
const resolvedAccessor = getAccessorKey(row, accessor);
|
|
10581
10630
|
const value = explicitValue !== undefined ? explicitValue : getAccessorValue(row, accessor);
|
|
10582
|
-
const type = col
|
|
10631
|
+
const type = getColumnType(col) ?? (col?.isCustom ? "custom" : "text");
|
|
10583
10632
|
try {
|
|
10584
10633
|
const callback = cellCallbackRef.current;
|
|
10585
10634
|
if (typeof callback !== "function") return;
|
|
@@ -10601,9 +10650,10 @@ function TableInner({
|
|
|
10601
10650
|
const renderCell = React.useCallback((v, accessor, row, col) => {
|
|
10602
10651
|
const isUndefinedLike = v === undefined || typeof v === "string" && v.trim().toLowerCase() === "undefined";
|
|
10603
10652
|
const isNoData = isUndefinedLike;
|
|
10653
|
+
const columnType = getColumnType(col);
|
|
10604
10654
|
|
|
10605
10655
|
// Custom column type (editable in-table)
|
|
10606
|
-
if (
|
|
10656
|
+
if (columnType === "custom") {
|
|
10607
10657
|
const CustomComp = col["modal-comp"];
|
|
10608
10658
|
if (CustomComp) {
|
|
10609
10659
|
return /*#__PURE__*/React.createElement(CustomComp, {
|
|
@@ -10613,7 +10663,7 @@ function TableInner({
|
|
|
10613
10663
|
}
|
|
10614
10664
|
|
|
10615
10665
|
// Checkbox column type (editable in-table)
|
|
10616
|
-
if (
|
|
10666
|
+
if (columnType === "checkbox") {
|
|
10617
10667
|
const checked = isUndefinedLike ? false : !!v;
|
|
10618
10668
|
return /*#__PURE__*/React.createElement("input", {
|
|
10619
10669
|
type: "checkbox",
|
|
@@ -10636,7 +10686,7 @@ function TableInner({
|
|
|
10636
10686
|
});
|
|
10637
10687
|
refreshTriggerRef.current?.();
|
|
10638
10688
|
try {
|
|
10639
|
-
onCellChangeRef.current?.(row, accessor, next);
|
|
10689
|
+
onCellChangeRef.current?.(row, accessor, next, col);
|
|
10640
10690
|
} catch (err) {
|
|
10641
10691
|
console.error("onCellChange error", err);
|
|
10642
10692
|
}
|
|
@@ -10645,7 +10695,7 @@ function TableInner({
|
|
|
10645
10695
|
}
|
|
10646
10696
|
|
|
10647
10697
|
// Switch column type (uses internal Switch component)
|
|
10648
|
-
if (
|
|
10698
|
+
if (columnType === "switch") {
|
|
10649
10699
|
const checked = isUndefinedLike ? false : !!v;
|
|
10650
10700
|
return /*#__PURE__*/React.createElement("div", {
|
|
10651
10701
|
title: isNoData ? translate("noData") : undefined,
|
|
@@ -10668,7 +10718,7 @@ function TableInner({
|
|
|
10668
10718
|
});
|
|
10669
10719
|
refreshTriggerRef.current?.();
|
|
10670
10720
|
try {
|
|
10671
|
-
onCellChangeRef.current?.(row, accessor, next);
|
|
10721
|
+
onCellChangeRef.current?.(row, accessor, next, col);
|
|
10672
10722
|
} catch (err) {
|
|
10673
10723
|
console.error("onCellChange error", err);
|
|
10674
10724
|
}
|
|
@@ -10677,7 +10727,7 @@ function TableInner({
|
|
|
10677
10727
|
}
|
|
10678
10728
|
|
|
10679
10729
|
// Color column type (display color swatch background)
|
|
10680
|
-
if (
|
|
10730
|
+
if (columnType === "color") {
|
|
10681
10731
|
const colorVal = isUndefinedLike ? "transparent" : v || "transparent";
|
|
10682
10732
|
const text = isUndefinedLike ? "..." : String(colorVal) ;
|
|
10683
10733
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -10701,7 +10751,7 @@ function TableInner({
|
|
|
10701
10751
|
}
|
|
10702
10752
|
|
|
10703
10753
|
// Input column type (editable text)
|
|
10704
|
-
if (
|
|
10754
|
+
if (columnType === "input") {
|
|
10705
10755
|
const text = isNoData ? "" : v == null ? "" : String(v);
|
|
10706
10756
|
return /*#__PURE__*/React.createElement("input", {
|
|
10707
10757
|
type: "text",
|
|
@@ -10726,7 +10776,7 @@ function TableInner({
|
|
|
10726
10776
|
});
|
|
10727
10777
|
refreshTriggerRef.current?.();
|
|
10728
10778
|
try {
|
|
10729
|
-
onCellChangeRef.current?.(row, accessor, next);
|
|
10779
|
+
onCellChangeRef.current?.(row, accessor, next, col);
|
|
10730
10780
|
} catch (err) {
|
|
10731
10781
|
console.error("onCellChange error", err);
|
|
10732
10782
|
}
|
|
@@ -10738,15 +10788,19 @@ function TableInner({
|
|
|
10738
10788
|
});
|
|
10739
10789
|
}
|
|
10740
10790
|
|
|
10741
|
-
// Date column type (editable date picker)
|
|
10742
|
-
if (
|
|
10743
|
-
const
|
|
10791
|
+
// Date column type (editable date/date-time picker)
|
|
10792
|
+
if (columnType === "date") {
|
|
10793
|
+
const dateFormat = getColumnDateFormat(col);
|
|
10794
|
+
const includeTime = typeof dateFormat === "string" && /H|h|m|s/.test(dateFormat);
|
|
10795
|
+
const inputType = includeTime ? "datetime-local" : "date";
|
|
10796
|
+
const dateValue = isNoData ? "" : toDateInputValue(v, includeTime);
|
|
10797
|
+
const displayDateValue = dateFormat ? formatDateValue(v, dateFormat) : dateValue;
|
|
10744
10798
|
return /*#__PURE__*/React.createElement("input", {
|
|
10745
|
-
type:
|
|
10799
|
+
type: inputType,
|
|
10746
10800
|
className: "table-cell-input",
|
|
10747
10801
|
value: dateValue,
|
|
10748
10802
|
placeholder: isNoData ? "..." : undefined,
|
|
10749
|
-
title: isNoData ? translate("noData") :
|
|
10803
|
+
title: isNoData ? translate("noData") : displayDateValue,
|
|
10750
10804
|
onClick: e => {
|
|
10751
10805
|
e.stopPropagation();
|
|
10752
10806
|
triggerCellCallback(row, col, dateValue);
|
|
@@ -10764,7 +10818,7 @@ function TableInner({
|
|
|
10764
10818
|
});
|
|
10765
10819
|
refreshTriggerRef.current?.();
|
|
10766
10820
|
try {
|
|
10767
|
-
onCellChangeRef.current?.(row, accessor, next);
|
|
10821
|
+
onCellChangeRef.current?.(row, accessor, next, col);
|
|
10768
10822
|
} catch (err) {
|
|
10769
10823
|
console.error("onCellChange error", err);
|
|
10770
10824
|
}
|