@l3mpire/ui 3.5.0 → 3.5.1

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/index.js CHANGED
@@ -7268,6 +7268,18 @@ function ColumnFilterPopover({
7268
7268
  ) })
7269
7269
  ] });
7270
7270
  }
7271
+ function pinnedStickyStyle(pinned, offset, zIndex) {
7272
+ if (pinned === "left") return { position: "sticky", left: offset, zIndex };
7273
+ if (pinned === "right") return { position: "sticky", right: offset, zIndex };
7274
+ return {};
7275
+ }
7276
+ function pinnedDividerClass(pinned) {
7277
+ if (pinned === "left")
7278
+ return "shadow-[1px_0_0_0_var(--core-border-main-primary)]";
7279
+ if (pinned === "right")
7280
+ return "shadow-[-1px_0_0_0_var(--core-border-main-primary)]";
7281
+ return "";
7282
+ }
7271
7283
  function DraggableHeaderCell({
7272
7284
  header,
7273
7285
  enableSorting,
@@ -7295,6 +7307,7 @@ function DraggableHeaderCell({
7295
7307
  disabled: !canDrag
7296
7308
  });
7297
7309
  const pinned = header.column.getIsPinned();
7310
+ const pinOffset = pinned === "left" ? header.column.getStart("left") : pinned === "right" ? header.column.getAfter("right") : void 0;
7298
7311
  const style = {
7299
7312
  width: enableColumnResizing ? header.getSize() : void 0,
7300
7313
  minWidth: enableColumnResizing ? header.column.columnDef.minSize : void 0,
@@ -7305,18 +7318,7 @@ function DraggableHeaderCell({
7305
7318
  // Pinning sticky positioning — must override the default `relative` we
7306
7319
  // also use for the resize handle. The resize handle is still absolutely
7307
7320
  // positioned because it references `right: 0` relative to the cell.
7308
- ...pinned === "left" ? {
7309
- position: "sticky",
7310
- left: header.column.getStart("left"),
7311
- zIndex: isDragging ? 5 : 3
7312
- } : pinned === "right" ? {
7313
- position: "sticky",
7314
- right: header.column.getAfter("right"),
7315
- zIndex: isDragging ? 5 : 3
7316
- } : {
7317
- position: "relative",
7318
- zIndex: isDragging ? 1 : void 0
7319
- }
7321
+ ...pinned ? pinnedStickyStyle(pinned, pinOffset, isDragging ? 5 : 3) : { position: "relative", zIndex: isDragging ? 1 : void 0 }
7320
7322
  };
7321
7323
  return /* @__PURE__ */ (0, import_jsx_runtime55.jsxs)(
7322
7324
  TableHead,
@@ -7330,8 +7332,7 @@ function DraggableHeaderCell({
7330
7332
  // Pinned columns keep their bg so the scrolling content can pass
7331
7333
  // under them. The default `bg-table-head-bg-default` is already on
7332
7334
  // <th> so we only need to add a divider on the boundary.
7333
- pinned === "left" && "shadow-[1px_0_0_0_var(--core-border-main-primary)]",
7334
- pinned === "right" && "shadow-[-1px_0_0_0_var(--core-border-main-primary)]"
7335
+ pinnedDividerClass(pinned)
7335
7336
  ),
7336
7337
  onClick: canSort ? header.column.getToggleSortingHandler() : void 0,
7337
7338
  onMouseEnter: () => setIsHovered(true),
@@ -7560,15 +7561,22 @@ function DataTableInner({
7560
7561
  }).filter(Boolean),
7561
7562
  [columns]
7562
7563
  );
7564
+ const lastSyncedColumnIdsRef = React54.useRef(null);
7563
7565
  React54.useEffect(() => {
7564
7566
  if (!enableColumnDrag) return;
7567
+ const signature = allColumnIds.join(" ");
7568
+ if (signature === lastSyncedColumnIdsRef.current) return;
7569
+ lastSyncedColumnIdsRef.current = signature;
7565
7570
  if (columnOrder.length === 0) {
7566
7571
  setColumnOrder(allColumnIds);
7567
7572
  return;
7568
7573
  }
7569
- const missing = allColumnIds.filter((id) => !columnOrder.includes(id));
7570
- if (missing.length > 0) {
7571
- setColumnOrder([...columnOrder, ...missing]);
7574
+ const pruned = columnOrder.filter((id) => allColumnIds.includes(id));
7575
+ const missing = allColumnIds.filter((id) => !pruned.includes(id));
7576
+ const next = [...pruned, ...missing];
7577
+ const changed = next.length !== columnOrder.length || next.some((id, i) => id !== columnOrder[i]);
7578
+ if (changed) {
7579
+ setColumnOrder(next);
7572
7580
  }
7573
7581
  }, [enableColumnDrag, columnOrder, allColumnIds, setColumnOrder]);
7574
7582
  const table = (0, import_react_table.useReactTable)({
@@ -7685,6 +7693,16 @@ function DataTableInner({
7685
7693
  return vars;
7686
7694
  }, [enableColumnResizing, table.getState().columnSizing]);
7687
7695
  const totalSize = enableColumnResizing ? table.getTotalSize() : void 0;
7696
+ const pinnedOffsets = React54.useMemo(() => {
7697
+ const map = /* @__PURE__ */ new Map();
7698
+ for (const col of table.getVisibleLeafColumns()) {
7699
+ const p = col.getIsPinned();
7700
+ if (p === "left") map.set(col.id, { side: "left", offset: col.getStart("left") });
7701
+ else if (p === "right")
7702
+ map.set(col.id, { side: "right", offset: col.getAfter("right") });
7703
+ }
7704
+ return map;
7705
+ }, [table, table.getState().columnPinning, table.getState().columnSizing]);
7688
7706
  const tableContent = /* @__PURE__ */ (0, import_jsx_runtime55.jsxs)("div", { className: cn("w-full", className), style: columnSizeVars, children: [
7689
7707
  /* @__PURE__ */ (0, import_jsx_runtime55.jsxs)(
7690
7708
  Table,
@@ -7760,17 +7778,10 @@ function DataTableInner({
7760
7778
  "data-state": row.getIsSelected() ? "selected" : void 0,
7761
7779
  children: row.getVisibleCells().map((cell) => {
7762
7780
  const cellPinned = cell.column.getIsPinned();
7781
+ const pin = cellPinned ? pinnedOffsets.get(cell.column.id) : void 0;
7763
7782
  const cellStyle = {
7764
7783
  ...enableColumnResizing ? { width: `var(--col-${cell.column.id}-size)` } : {},
7765
- ...cellPinned === "left" ? {
7766
- position: "sticky",
7767
- left: cell.column.getStart("left"),
7768
- zIndex: 2
7769
- } : cellPinned === "right" ? {
7770
- position: "sticky",
7771
- right: cell.column.getAfter("right"),
7772
- zIndex: 2
7773
- } : {}
7784
+ ...pinnedStickyStyle(cellPinned, pin?.offset, 2)
7774
7785
  };
7775
7786
  return /* @__PURE__ */ (0, import_jsx_runtime55.jsx)(
7776
7787
  TableCell,
@@ -7781,8 +7792,8 @@ function DataTableInner({
7781
7792
  enableColumnResizing && "truncate",
7782
7793
  // Pinned cells need an opaque background so scrolled
7783
7794
  // content does not show through.
7784
- cellPinned === "left" && "bg-table-row-bg-default group-hover/row:bg-table-row-bg-hover data-[state=selected]:bg-table-row-bg-selected shadow-[1px_0_0_0_var(--core-border-main-primary)]",
7785
- cellPinned === "right" && "bg-table-row-bg-default group-hover/row:bg-table-row-bg-hover data-[state=selected]:bg-table-row-bg-selected shadow-[-1px_0_0_0_var(--core-border-main-primary)]"
7795
+ cellPinned && "bg-table-row-bg-default group-hover/row:bg-table-row-bg-hover data-[state=selected]:bg-table-row-bg-selected",
7796
+ pinnedDividerClass(cellPinned)
7786
7797
  ),
7787
7798
  children: (0, import_react_table.flexRender)(
7788
7799
  cell.column.columnDef.cell,