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/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) => {
@@ -9637,7 +9686,7 @@ function TableInner({
9637
9686
  downloadCallback = () => {},
9638
9687
  // new undelete callback
9639
9688
  undeleteCallback = () => {},
9640
- // callback for cell edits: (row, accessor, newValue)
9689
+ // callback for cell edits: (row, accessor, newValue, column)
9641
9690
  onCellChange = () => {},
9642
9691
  // callback for any cell click
9643
9692
  cellCallback = () => {},
@@ -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?.type ?? (col?.isCustom ? "custom" : "text");
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 (col && col.type === "custom") {
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 (col && col.type === "checkbox") {
10644
+ if (columnType === "checkbox") {
10595
10645
  const checked = isUndefinedLike ? false : !!v;
10596
10646
  return /*#__PURE__*/React__default.createElement("input", {
10597
10647
  type: "checkbox",
@@ -10614,7 +10664,7 @@ function TableInner({
10614
10664
  });
10615
10665
  refreshTriggerRef.current?.();
10616
10666
  try {
10617
- onCellChangeRef.current?.(row, accessor, next);
10667
+ onCellChangeRef.current?.(row, accessor, next, col);
10618
10668
  } catch (err) {
10619
10669
  console.error("onCellChange error", err);
10620
10670
  }
@@ -10623,7 +10673,7 @@ function TableInner({
10623
10673
  }
10624
10674
 
10625
10675
  // Switch column type (uses internal Switch component)
10626
- if (col && col.type === "switch") {
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,
@@ -10646,7 +10696,7 @@ function TableInner({
10646
10696
  });
10647
10697
  refreshTriggerRef.current?.();
10648
10698
  try {
10649
- onCellChangeRef.current?.(row, accessor, next);
10699
+ onCellChangeRef.current?.(row, accessor, next, col);
10650
10700
  } catch (err) {
10651
10701
  console.error("onCellChange error", err);
10652
10702
  }
@@ -10655,7 +10705,7 @@ function TableInner({
10655
10705
  }
10656
10706
 
10657
10707
  // Color column type (display color swatch background)
10658
- if (col && col.type === "color") {
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 (col && col.type === "input") {
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",
@@ -10704,7 +10754,7 @@ function TableInner({
10704
10754
  });
10705
10755
  refreshTriggerRef.current?.();
10706
10756
  try {
10707
- onCellChangeRef.current?.(row, accessor, next);
10757
+ onCellChangeRef.current?.(row, accessor, next, col);
10708
10758
  } catch (err) {
10709
10759
  console.error("onCellChange error", err);
10710
10760
  }
@@ -10716,15 +10766,19 @@ function TableInner({
10716
10766
  });
10717
10767
  }
10718
10768
 
10719
- // Date column type (editable date picker)
10720
- if (col && col.type === "date") {
10721
- const dateValue = isNoData ? "" : v == null ? "" : v instanceof Date ? v.toISOString().slice(0, 10) : String(v).slice(0, 10);
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: "date",
10777
+ type: inputType,
10724
10778
  className: "table-cell-input",
10725
10779
  value: dateValue,
10726
10780
  placeholder: isNoData ? "..." : undefined,
10727
- title: isNoData ? translate("noData") : dateValue,
10781
+ title: isNoData ? translate("noData") : displayDateValue,
10728
10782
  onClick: e => {
10729
10783
  e.stopPropagation();
10730
10784
  triggerCellCallback(row, col, dateValue);
@@ -10742,7 +10796,7 @@ function TableInner({
10742
10796
  });
10743
10797
  refreshTriggerRef.current?.();
10744
10798
  try {
10745
- onCellChangeRef.current?.(row, accessor, next);
10799
+ onCellChangeRef.current?.(row, accessor, next, col);
10746
10800
  } catch (err) {
10747
10801
  console.error("onCellChange error", err);
10748
10802
  }