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 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) => {
@@ -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?.type ?? (col?.isCustom ? "custom" : "text");
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 (col && col.type === "custom") {
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 (col && col.type === "checkbox") {
10666
+ if (columnType === "checkbox") {
10617
10667
  const checked = isUndefinedLike ? false : !!v;
10618
10668
  return /*#__PURE__*/React.createElement("input", {
10619
10669
  type: "checkbox",
@@ -10645,7 +10695,7 @@ function TableInner({
10645
10695
  }
10646
10696
 
10647
10697
  // Switch column type (uses internal Switch component)
10648
- if (col && col.type === "switch") {
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,
@@ -10677,7 +10727,7 @@ function TableInner({
10677
10727
  }
10678
10728
 
10679
10729
  // Color column type (display color swatch background)
10680
- if (col && col.type === "color") {
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 (col && col.type === "input") {
10754
+ if (columnType === "input") {
10705
10755
  const text = isNoData ? "" : v == null ? "" : String(v);
10706
10756
  return /*#__PURE__*/React.createElement("input", {
10707
10757
  type: "text",
@@ -10738,15 +10788,19 @@ function TableInner({
10738
10788
  });
10739
10789
  }
10740
10790
 
10741
- // Date column type (editable date picker)
10742
- if (col && col.type === "date") {
10743
- const dateValue = isNoData ? "" : v == null ? "" : v instanceof Date ? v.toISOString().slice(0, 10) : String(v).slice(0, 10);
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: "date",
10799
+ type: inputType,
10746
10800
  className: "table-cell-input",
10747
10801
  value: dateValue,
10748
10802
  placeholder: isNoData ? "..." : undefined,
10749
- title: isNoData ? translate("noData") : dateValue,
10803
+ title: isNoData ? translate("noData") : displayDateValue,
10750
10804
  onClick: e => {
10751
10805
  e.stopPropagation();
10752
10806
  triggerCellCallback(row, col, dateValue);
@@ -10869,8 +10923,9 @@ function TableInner({
10869
10923
  }
10870
10924
  }, v ? "✓" : "✗");
10871
10925
  }
10872
- // existing highlight logic for other fields
10873
- return highlight(String(v));
10926
+ // Translate only the displayed value; keep the raw value for data operations.
10927
+ const displayValue = col?.translate ? translate(String(v)) : v;
10928
+ return highlight(String(displayValue ?? v));
10874
10929
  }, [highlight, isGrouped, triggerCellCallback, translate, formatArrayValue]);
10875
10930
  const showView = buttons.includes("view");
10876
10931
  const showEdit = buttons.includes("edit");