trotl-table 1.0.92 → 1.0.95
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 +68 -13
- package/dist/Table.cjs.js.map +1 -1
- package/dist/Table.esm.js +68 -13
- package/dist/Table.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/Table.esm.js
CHANGED
|
@@ -9524,6 +9524,55 @@ _defineProperty(WindowScroller, "defaultProps", {
|
|
|
9524
9524
|
});
|
|
9525
9525
|
|
|
9526
9526
|
const ITEM_TYPE = "ROW";
|
|
9527
|
+
const getColumnType = column => Array.isArray(column?.type) ? column.type[0] : column?.type;
|
|
9528
|
+
const getColumnDateFormat = column => {
|
|
9529
|
+
if (Array.isArray(column?.type)) return column.type[1] || null;
|
|
9530
|
+
return column?.dateFormat || null;
|
|
9531
|
+
};
|
|
9532
|
+
const parseDateValue = value => {
|
|
9533
|
+
if (value instanceof Date) {
|
|
9534
|
+
return Number.isNaN(value.getTime()) ? null : value;
|
|
9535
|
+
}
|
|
9536
|
+
if (value == null || value === "") return null;
|
|
9537
|
+
const text = String(value).trim();
|
|
9538
|
+
const isoMatch = text.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/);
|
|
9539
|
+
if (isoMatch) {
|
|
9540
|
+
const [, year, month, day, hour = "0", minute = "0", second = "0"] = isoMatch;
|
|
9541
|
+
const date = new Date(Number(year), Number(month) - 1, Number(day), Number(hour), Number(minute), Number(second));
|
|
9542
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
9543
|
+
}
|
|
9544
|
+
const dmyMatch = text.match(/^(\d{2})-(\d{2})-(\d{4})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/);
|
|
9545
|
+
if (dmyMatch) {
|
|
9546
|
+
const [, day, month, year, hour = "0", minute = "0", second = "0"] = dmyMatch;
|
|
9547
|
+
const date = new Date(Number(year), Number(month) - 1, Number(day), Number(hour), Number(minute), Number(second));
|
|
9548
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
9549
|
+
}
|
|
9550
|
+
const date = new Date(value);
|
|
9551
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
9552
|
+
};
|
|
9553
|
+
const formatDateValue = (value, format) => {
|
|
9554
|
+
const date = parseDateValue(value);
|
|
9555
|
+
if (!date) return "";
|
|
9556
|
+
if (!format) return date.toLocaleString("sl-SI", {
|
|
9557
|
+
hour12: false
|
|
9558
|
+
});
|
|
9559
|
+
const parts = {
|
|
9560
|
+
YYYY: String(date.getFullYear()),
|
|
9561
|
+
MM: String(date.getMonth() + 1).padStart(2, "0"),
|
|
9562
|
+
DD: String(date.getDate()).padStart(2, "0"),
|
|
9563
|
+
HH: String(date.getHours()).padStart(2, "0"),
|
|
9564
|
+
mm: String(date.getMinutes()).padStart(2, "0"),
|
|
9565
|
+
ss: String(date.getSeconds()).padStart(2, "0")
|
|
9566
|
+
};
|
|
9567
|
+
return String(format).replace(/YYYY|MM|DD|HH|mm|ss/g, token => parts[token]);
|
|
9568
|
+
};
|
|
9569
|
+
const toDateInputValue = (value, includeTime) => {
|
|
9570
|
+
const date = parseDateValue(value);
|
|
9571
|
+
if (!date) return "";
|
|
9572
|
+
const datePart = [date.getFullYear(), String(date.getMonth() + 1).padStart(2, "0"), String(date.getDate()).padStart(2, "0")].join("-");
|
|
9573
|
+
if (!includeTime) return datePart;
|
|
9574
|
+
return `${datePart}T${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
|
|
9575
|
+
};
|
|
9527
9576
|
|
|
9528
9577
|
// Normalize data into grouped format
|
|
9529
9578
|
const normalizeData = (groups, rows) => {
|
|
@@ -10557,7 +10606,7 @@ function TableInner({
|
|
|
10557
10606
|
const accessor = col?.accessor ?? null;
|
|
10558
10607
|
const resolvedAccessor = getAccessorKey(row, accessor);
|
|
10559
10608
|
const value = explicitValue !== undefined ? explicitValue : getAccessorValue(row, accessor);
|
|
10560
|
-
const type = col
|
|
10609
|
+
const type = getColumnType(col) ?? (col?.isCustom ? "custom" : "text");
|
|
10561
10610
|
try {
|
|
10562
10611
|
const callback = cellCallbackRef.current;
|
|
10563
10612
|
if (typeof callback !== "function") return;
|
|
@@ -10579,9 +10628,10 @@ function TableInner({
|
|
|
10579
10628
|
const renderCell = useCallback((v, accessor, row, col) => {
|
|
10580
10629
|
const isUndefinedLike = v === undefined || typeof v === "string" && v.trim().toLowerCase() === "undefined";
|
|
10581
10630
|
const isNoData = isUndefinedLike;
|
|
10631
|
+
const columnType = getColumnType(col);
|
|
10582
10632
|
|
|
10583
10633
|
// Custom column type (editable in-table)
|
|
10584
|
-
if (
|
|
10634
|
+
if (columnType === "custom") {
|
|
10585
10635
|
const CustomComp = col["modal-comp"];
|
|
10586
10636
|
if (CustomComp) {
|
|
10587
10637
|
return /*#__PURE__*/React__default.createElement(CustomComp, {
|
|
@@ -10591,7 +10641,7 @@ function TableInner({
|
|
|
10591
10641
|
}
|
|
10592
10642
|
|
|
10593
10643
|
// Checkbox column type (editable in-table)
|
|
10594
|
-
if (
|
|
10644
|
+
if (columnType === "checkbox") {
|
|
10595
10645
|
const checked = isUndefinedLike ? false : !!v;
|
|
10596
10646
|
return /*#__PURE__*/React__default.createElement("input", {
|
|
10597
10647
|
type: "checkbox",
|
|
@@ -10623,7 +10673,7 @@ function TableInner({
|
|
|
10623
10673
|
}
|
|
10624
10674
|
|
|
10625
10675
|
// Switch column type (uses internal Switch component)
|
|
10626
|
-
if (
|
|
10676
|
+
if (columnType === "switch") {
|
|
10627
10677
|
const checked = isUndefinedLike ? false : !!v;
|
|
10628
10678
|
return /*#__PURE__*/React__default.createElement("div", {
|
|
10629
10679
|
title: isNoData ? translate("noData") : undefined,
|
|
@@ -10655,7 +10705,7 @@ function TableInner({
|
|
|
10655
10705
|
}
|
|
10656
10706
|
|
|
10657
10707
|
// Color column type (display color swatch background)
|
|
10658
|
-
if (
|
|
10708
|
+
if (columnType === "color") {
|
|
10659
10709
|
const colorVal = isUndefinedLike ? "transparent" : v || "transparent";
|
|
10660
10710
|
const text = isUndefinedLike ? "..." : String(colorVal) ;
|
|
10661
10711
|
return /*#__PURE__*/React__default.createElement("div", {
|
|
@@ -10679,7 +10729,7 @@ function TableInner({
|
|
|
10679
10729
|
}
|
|
10680
10730
|
|
|
10681
10731
|
// Input column type (editable text)
|
|
10682
|
-
if (
|
|
10732
|
+
if (columnType === "input") {
|
|
10683
10733
|
const text = isNoData ? "" : v == null ? "" : String(v);
|
|
10684
10734
|
return /*#__PURE__*/React__default.createElement("input", {
|
|
10685
10735
|
type: "text",
|
|
@@ -10716,15 +10766,19 @@ function TableInner({
|
|
|
10716
10766
|
});
|
|
10717
10767
|
}
|
|
10718
10768
|
|
|
10719
|
-
// Date column type (editable date picker)
|
|
10720
|
-
if (
|
|
10721
|
-
const
|
|
10769
|
+
// Date column type (editable date/date-time picker)
|
|
10770
|
+
if (columnType === "date") {
|
|
10771
|
+
const dateFormat = getColumnDateFormat(col);
|
|
10772
|
+
const includeTime = typeof dateFormat === "string" && /H|h|m|s/.test(dateFormat);
|
|
10773
|
+
const inputType = includeTime ? "datetime-local" : "date";
|
|
10774
|
+
const dateValue = isNoData ? "" : toDateInputValue(v, includeTime);
|
|
10775
|
+
const displayDateValue = dateFormat ? formatDateValue(v, dateFormat) : dateValue;
|
|
10722
10776
|
return /*#__PURE__*/React__default.createElement("input", {
|
|
10723
|
-
type:
|
|
10777
|
+
type: inputType,
|
|
10724
10778
|
className: "table-cell-input",
|
|
10725
10779
|
value: dateValue,
|
|
10726
10780
|
placeholder: isNoData ? "..." : undefined,
|
|
10727
|
-
title: isNoData ? translate("noData") :
|
|
10781
|
+
title: isNoData ? translate("noData") : displayDateValue,
|
|
10728
10782
|
onClick: e => {
|
|
10729
10783
|
e.stopPropagation();
|
|
10730
10784
|
triggerCellCallback(row, col, dateValue);
|
|
@@ -10847,8 +10901,9 @@ function TableInner({
|
|
|
10847
10901
|
}
|
|
10848
10902
|
}, v ? "✓" : "✗");
|
|
10849
10903
|
}
|
|
10850
|
-
//
|
|
10851
|
-
|
|
10904
|
+
// Translate only the displayed value; keep the raw value for data operations.
|
|
10905
|
+
const displayValue = col?.translate ? translate(String(v)) : v;
|
|
10906
|
+
return highlight(String(displayValue ?? v));
|
|
10852
10907
|
}, [highlight, isGrouped, triggerCellCallback, translate, formatArrayValue]);
|
|
10853
10908
|
const showView = buttons.includes("view");
|
|
10854
10909
|
const showEdit = buttons.includes("edit");
|