@lensui/lens-table 0.1.27 → 0.1.29

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.cjs CHANGED
@@ -1460,10 +1460,8 @@ function resolveColumnDropIndex(sourceIndex, targetIndex, edge, columnCount) {
1460
1460
  function resolveColumnDropPlacement(edge) {
1461
1461
  return edge === "right" ? "after" : "before";
1462
1462
  }
1463
- function resolveColumnDropHighlightRange(target, edge, cells) {
1464
- if (edge === "right") return { startIndex: target.startIndex, endIndex: target.endIndex };
1465
- const previous = cells.find((cell) => cell.endIndex === target.startIndex - 1 && cell.level === target.level && cell.parentKey === target.parentKey);
1466
- return previous ? { startIndex: previous.startIndex, endIndex: previous.endIndex } : { startIndex: target.startIndex, endIndex: target.endIndex };
1463
+ function resolveColumnDropHighlightRange(target, _edge, _cells) {
1464
+ return { startIndex: target.startIndex, endIndex: target.endIndex };
1467
1465
  }
1468
1466
  var ANNOTATION_COLORS = ["#f44336", "#ff7a45", "#f5a623", "#f2c94c", "#52c41a", "#13a8a8", "#1677ff", "#597ef7", "#9254de", "#eb2f96"];
1469
1467
  var FALLBACK_HEIGHT = 480;
@@ -1811,7 +1809,6 @@ function TableInner({
1811
1809
  const contextMenuRef = (0, import_react5.useRef)(null);
1812
1810
  const suppressClickRef = (0, import_react5.useRef)(false);
1813
1811
  const hasCompletedLoadRef = (0, import_react5.useRef)(!loading);
1814
- const columnDragPreviewRef = (0, import_react5.useRef)(null);
1815
1812
  const validColumnDropRef = (0, import_react5.useRef)(null);
1816
1813
  const hoveredHeaderActionRef = (0, import_react5.useRef)(null);
1817
1814
  const hoveredRowIndexRef = (0, import_react5.useRef)(null);
@@ -1845,6 +1842,7 @@ function TableInner({
1845
1842
  const [editing, setEditing] = (0, import_react5.useState)(null);
1846
1843
  const [draft, setDraft] = (0, import_react5.useState)("");
1847
1844
  const [rowDragPreview, setRowDragPreview] = (0, import_react5.useState)(null);
1845
+ const [columnDragPreview, setColumnDragPreview] = (0, import_react5.useState)(null);
1848
1846
  const [columnDropTarget, setColumnDropTarget] = (0, import_react5.useState)(null);
1849
1847
  (0, import_react5.useEffect)(() => {
1850
1848
  if (!loading) hasCompletedLoadRef.current = true;
@@ -3627,7 +3625,7 @@ function TableInner({
3627
3625
  }, []);
3628
3626
  const clearColumnOrderPointerDrag = (0, import_react5.useCallback)((canvas) => {
3629
3627
  columnOrderDragRef.current = null;
3630
- columnDragPreviewRef.current = null;
3628
+ setColumnDragPreview(null);
3631
3629
  validColumnDropRef.current = null;
3632
3630
  setColumnDropTarget(null);
3633
3631
  setDragGuide(null);
@@ -3663,6 +3661,27 @@ function TableInner({
3663
3661
  }
3664
3662
  event.preventDefault();
3665
3663
  const sourceCell = drag.sourceCell;
3664
+ const rootRect = rootRef.current?.getBoundingClientRect() ?? event.currentTarget.getBoundingClientRect();
3665
+ const sourceWidth = metrics[sourceCell.startIndex]?.width ?? 160;
3666
+ const sourceColumn = columns[sourceCell.startIndex];
3667
+ const previewContext = event.currentTarget.getContext("2d");
3668
+ const previewStyles = rootRef.current ? getComputedStyle(rootRef.current) : null;
3669
+ const previewFontSize = previewStyles ? readThemePixel(previewStyles, "--rvg-font-size-body", 13) : 13;
3670
+ if (previewContext) previewContext.font = `${previewFontSize}px Inter, ui-sans-serif, system-ui, sans-serif`;
3671
+ const measurePreviewText = (value) => previewContext?.measureText(value).width ?? value.length * previewFontSize * 0.58;
3672
+ const previewContentWidth = Math.max(
3673
+ measurePreviewText(sourceColumn?.title ?? ""),
3674
+ ...rows.slice(0, 100).map((_row, rowIndex) => measurePreviewText(getCellLabel(rowIndex, sourceCell.startIndex)))
3675
+ ) + 24;
3676
+ const previewWidth = Math.min(
3677
+ Math.max(sourceWidth, Math.ceil(previewContentWidth)),
3678
+ Math.max(60, Math.min(360, viewport.width - 16))
3679
+ );
3680
+ setColumnDragPreview({
3681
+ sourceIndex: sourceCell.startIndex,
3682
+ left: Math.max(4, Math.min(viewport.width - previewWidth - 4, event.clientX - rootRect.left - previewWidth / 2)),
3683
+ width: previewWidth
3684
+ });
3666
3685
  const hoveredColumnIndex = locateColumn(event.clientX);
3667
3686
  const targetCell = locateHeaderCell(event.clientX, event.clientY) ?? headerCells.find((cell) => hoveredColumnIndex >= cell.startIndex && hoveredColumnIndex <= cell.endIndex && cell.level === sourceCell.level && cell.leaf === sourceCell.leaf && cell.parentKey === sourceCell.parentKey && columns[cell.startIndex]?.fixed === columns[sourceCell.startIndex]?.fixed);
3668
3687
  if (!targetCell) {
@@ -3688,11 +3707,14 @@ function TableInner({
3688
3707
  columnEdge,
3689
3708
  columns.length
3690
3709
  );
3691
- columnDragPreviewRef.current = { sourceIndex: sourceCell.startIndex, targetIndex: destinationIndex };
3710
+ const compatibleHighlightCells = headerCells.filter((cell) => {
3711
+ const cellColumn = columns[cell.startIndex];
3712
+ return cellColumn && !cellColumn.rowSelection && !cellColumn.rowDragHandle && !cellColumn.rowNumber && cellColumn.fixed === targetColumn.fixed;
3713
+ });
3714
+ setColumnDropTarget(resolveColumnDropHighlightRange(targetCell, columnEdge, compatibleHighlightCells));
3715
+ setDragGuide(columnEdge === "right" ? targetLeft + targetWidth : targetLeft, headerRowOffsets[sourceCell.level] ?? 0);
3692
3716
  if (destinationIndex === sourceCell.startIndex) {
3693
3717
  validColumnDropRef.current = null;
3694
- setColumnDropTarget(null);
3695
- setDragGuide(null);
3696
3718
  return;
3697
3719
  }
3698
3720
  validColumnDropRef.current = {
@@ -3705,13 +3727,7 @@ function TableInner({
3705
3727
  fixed: targetColumn.fixed,
3706
3728
  columnEdge
3707
3729
  };
3708
- const compatibleHighlightCells = headerCells.filter((cell) => {
3709
- const cellColumn = columns[cell.startIndex];
3710
- return cellColumn && !cellColumn.rowSelection && !cellColumn.rowDragHandle && !cellColumn.rowNumber && cellColumn.fixed === targetColumn.fixed;
3711
- });
3712
- setColumnDropTarget(resolveColumnDropHighlightRange(targetCell, columnEdge, compatibleHighlightCells));
3713
- setDragGuide(columnEdge === "right" ? targetLeft + targetWidth : targetLeft, headerRowOffsets[sourceCell.level] ?? 0);
3714
- }, [columns, getHeaderCellLeft, getHeaderCellWidth, headerCells, headerRowOffsets, hideDragTooltips, locateColumn, locateHeaderCell, setDragGuide]);
3730
+ }, [columns, getCellLabel, getHeaderCellLeft, getHeaderCellWidth, headerCells, headerRowOffsets, hideDragTooltips, locateColumn, locateHeaderCell, metrics, rows, setDragGuide, viewport.width]);
3715
3731
  const finishColumnOrderPointerDrag = (0, import_react5.useCallback)((event, apply) => {
3716
3732
  const drag = columnOrderDragRef.current;
3717
3733
  if (!drag || drag.pointerId !== event.pointerId) return;
@@ -5223,6 +5239,34 @@ function TableInner({
5223
5239
  }
5224
5240
  ),
5225
5241
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { ref: dragGuideRef, className: "rvg-column-guide" }),
5242
+ columnDragPreview && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
5243
+ "div",
5244
+ {
5245
+ "aria-hidden": "true",
5246
+ className: "rvg-column-drag-preview",
5247
+ style: {
5248
+ left: columnDragPreview.left,
5249
+ top: 0,
5250
+ width: columnDragPreview.width,
5251
+ height: renderHeight
5252
+ },
5253
+ children: [
5254
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "rvg-column-drag-preview-header", style: { top: headerLeafTop, height: headerLeafHeight }, children: columns[columnDragPreview.sourceIndex]?.renderHeader?.(columns[columnDragPreview.sourceIndex]) ?? columns[columnDragPreview.sourceIndex]?.title }),
5255
+ rows.slice(domRange.rowStart, domRange.rowEnd).map((_row, visibleRowOffset) => {
5256
+ const rowIndex = domRange.rowStart + visibleRowOffset;
5257
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5258
+ "div",
5259
+ {
5260
+ className: `rvg-column-drag-preview-cell${hasStripedRows && rowIndex % 2 === 1 ? " is-striped" : ""}`,
5261
+ style: { top: bodyTop + rowIndex * rowHeight - scrollRef.current.top, height: rowHeight },
5262
+ children: getCellLabel(rowIndex, columnDragPreview.sourceIndex)
5263
+ },
5264
+ `column-preview:${String(getRowKey(rows[rowIndex], rowIndex))}`
5265
+ );
5266
+ })
5267
+ ]
5268
+ }
5269
+ ),
5226
5270
  resizeGuideX !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5227
5271
  "div",
5228
5272
  {
package/dist/index.css CHANGED
@@ -1508,12 +1508,14 @@
1508
1508
  background: var(--rvg-color-danger);
1509
1509
  }
1510
1510
  .rvg-column-drag-preview {
1511
- position: relative;
1511
+ position: absolute;
1512
+ z-index: 11;
1512
1513
  overflow: hidden;
1513
- border: 1px solid #a9c8f5;
1514
- background: #fff;
1515
- box-shadow: var(--rvg-shadow-popover);
1514
+ border: 1px solid color-mix(in srgb, var(--rvg-color-primary) 38%, var(--rvg-color-grid));
1515
+ background: var(--rvg-color-bg);
1516
+ box-shadow: 0 6px 18px rgba(50, 91, 136, 0.18);
1516
1517
  opacity: 0.94;
1518
+ pointer-events: none;
1517
1519
  box-sizing: border-box;
1518
1520
  }
1519
1521
  .rvg-column-drag-preview-header,
@@ -1538,9 +1540,12 @@
1538
1540
  }
1539
1541
  .rvg-column-drag-preview-header {
1540
1542
  background: var(--rvg-color-header-bg);
1541
- color: var(--rvg-color-muted);
1543
+ color: var(--rvg-color-text);
1542
1544
  font-weight: 600;
1543
1545
  }
1546
+ .rvg-column-drag-preview-cell.is-striped {
1547
+ background: var(--rvg-color-stripe);
1548
+ }
1544
1549
  .rvg-column-drag-preview-header .rvg-preview-header-icon {
1545
1550
  position: absolute;
1546
1551
  top: 50%;
package/dist/index.js CHANGED
@@ -1430,10 +1430,8 @@ function resolveColumnDropIndex(sourceIndex, targetIndex, edge, columnCount) {
1430
1430
  function resolveColumnDropPlacement(edge) {
1431
1431
  return edge === "right" ? "after" : "before";
1432
1432
  }
1433
- function resolveColumnDropHighlightRange(target, edge, cells) {
1434
- if (edge === "right") return { startIndex: target.startIndex, endIndex: target.endIndex };
1435
- const previous = cells.find((cell) => cell.endIndex === target.startIndex - 1 && cell.level === target.level && cell.parentKey === target.parentKey);
1436
- return previous ? { startIndex: previous.startIndex, endIndex: previous.endIndex } : { startIndex: target.startIndex, endIndex: target.endIndex };
1433
+ function resolveColumnDropHighlightRange(target, _edge, _cells) {
1434
+ return { startIndex: target.startIndex, endIndex: target.endIndex };
1437
1435
  }
1438
1436
  var ANNOTATION_COLORS = ["#f44336", "#ff7a45", "#f5a623", "#f2c94c", "#52c41a", "#13a8a8", "#1677ff", "#597ef7", "#9254de", "#eb2f96"];
1439
1437
  var FALLBACK_HEIGHT = 480;
@@ -1781,7 +1779,6 @@ function TableInner({
1781
1779
  const contextMenuRef = useRef2(null);
1782
1780
  const suppressClickRef = useRef2(false);
1783
1781
  const hasCompletedLoadRef = useRef2(!loading);
1784
- const columnDragPreviewRef = useRef2(null);
1785
1782
  const validColumnDropRef = useRef2(null);
1786
1783
  const hoveredHeaderActionRef = useRef2(null);
1787
1784
  const hoveredRowIndexRef = useRef2(null);
@@ -1815,6 +1812,7 @@ function TableInner({
1815
1812
  const [editing, setEditing] = useState4(null);
1816
1813
  const [draft, setDraft] = useState4("");
1817
1814
  const [rowDragPreview, setRowDragPreview] = useState4(null);
1815
+ const [columnDragPreview, setColumnDragPreview] = useState4(null);
1818
1816
  const [columnDropTarget, setColumnDropTarget] = useState4(null);
1819
1817
  useEffect2(() => {
1820
1818
  if (!loading) hasCompletedLoadRef.current = true;
@@ -3597,7 +3595,7 @@ function TableInner({
3597
3595
  }, []);
3598
3596
  const clearColumnOrderPointerDrag = useCallback2((canvas) => {
3599
3597
  columnOrderDragRef.current = null;
3600
- columnDragPreviewRef.current = null;
3598
+ setColumnDragPreview(null);
3601
3599
  validColumnDropRef.current = null;
3602
3600
  setColumnDropTarget(null);
3603
3601
  setDragGuide(null);
@@ -3633,6 +3631,27 @@ function TableInner({
3633
3631
  }
3634
3632
  event.preventDefault();
3635
3633
  const sourceCell = drag.sourceCell;
3634
+ const rootRect = rootRef.current?.getBoundingClientRect() ?? event.currentTarget.getBoundingClientRect();
3635
+ const sourceWidth = metrics[sourceCell.startIndex]?.width ?? 160;
3636
+ const sourceColumn = columns[sourceCell.startIndex];
3637
+ const previewContext = event.currentTarget.getContext("2d");
3638
+ const previewStyles = rootRef.current ? getComputedStyle(rootRef.current) : null;
3639
+ const previewFontSize = previewStyles ? readThemePixel(previewStyles, "--rvg-font-size-body", 13) : 13;
3640
+ if (previewContext) previewContext.font = `${previewFontSize}px Inter, ui-sans-serif, system-ui, sans-serif`;
3641
+ const measurePreviewText = (value) => previewContext?.measureText(value).width ?? value.length * previewFontSize * 0.58;
3642
+ const previewContentWidth = Math.max(
3643
+ measurePreviewText(sourceColumn?.title ?? ""),
3644
+ ...rows.slice(0, 100).map((_row, rowIndex) => measurePreviewText(getCellLabel(rowIndex, sourceCell.startIndex)))
3645
+ ) + 24;
3646
+ const previewWidth = Math.min(
3647
+ Math.max(sourceWidth, Math.ceil(previewContentWidth)),
3648
+ Math.max(60, Math.min(360, viewport.width - 16))
3649
+ );
3650
+ setColumnDragPreview({
3651
+ sourceIndex: sourceCell.startIndex,
3652
+ left: Math.max(4, Math.min(viewport.width - previewWidth - 4, event.clientX - rootRect.left - previewWidth / 2)),
3653
+ width: previewWidth
3654
+ });
3636
3655
  const hoveredColumnIndex = locateColumn(event.clientX);
3637
3656
  const targetCell = locateHeaderCell(event.clientX, event.clientY) ?? headerCells.find((cell) => hoveredColumnIndex >= cell.startIndex && hoveredColumnIndex <= cell.endIndex && cell.level === sourceCell.level && cell.leaf === sourceCell.leaf && cell.parentKey === sourceCell.parentKey && columns[cell.startIndex]?.fixed === columns[sourceCell.startIndex]?.fixed);
3638
3657
  if (!targetCell) {
@@ -3658,11 +3677,14 @@ function TableInner({
3658
3677
  columnEdge,
3659
3678
  columns.length
3660
3679
  );
3661
- columnDragPreviewRef.current = { sourceIndex: sourceCell.startIndex, targetIndex: destinationIndex };
3680
+ const compatibleHighlightCells = headerCells.filter((cell) => {
3681
+ const cellColumn = columns[cell.startIndex];
3682
+ return cellColumn && !cellColumn.rowSelection && !cellColumn.rowDragHandle && !cellColumn.rowNumber && cellColumn.fixed === targetColumn.fixed;
3683
+ });
3684
+ setColumnDropTarget(resolveColumnDropHighlightRange(targetCell, columnEdge, compatibleHighlightCells));
3685
+ setDragGuide(columnEdge === "right" ? targetLeft + targetWidth : targetLeft, headerRowOffsets[sourceCell.level] ?? 0);
3662
3686
  if (destinationIndex === sourceCell.startIndex) {
3663
3687
  validColumnDropRef.current = null;
3664
- setColumnDropTarget(null);
3665
- setDragGuide(null);
3666
3688
  return;
3667
3689
  }
3668
3690
  validColumnDropRef.current = {
@@ -3675,13 +3697,7 @@ function TableInner({
3675
3697
  fixed: targetColumn.fixed,
3676
3698
  columnEdge
3677
3699
  };
3678
- const compatibleHighlightCells = headerCells.filter((cell) => {
3679
- const cellColumn = columns[cell.startIndex];
3680
- return cellColumn && !cellColumn.rowSelection && !cellColumn.rowDragHandle && !cellColumn.rowNumber && cellColumn.fixed === targetColumn.fixed;
3681
- });
3682
- setColumnDropTarget(resolveColumnDropHighlightRange(targetCell, columnEdge, compatibleHighlightCells));
3683
- setDragGuide(columnEdge === "right" ? targetLeft + targetWidth : targetLeft, headerRowOffsets[sourceCell.level] ?? 0);
3684
- }, [columns, getHeaderCellLeft, getHeaderCellWidth, headerCells, headerRowOffsets, hideDragTooltips, locateColumn, locateHeaderCell, setDragGuide]);
3700
+ }, [columns, getCellLabel, getHeaderCellLeft, getHeaderCellWidth, headerCells, headerRowOffsets, hideDragTooltips, locateColumn, locateHeaderCell, metrics, rows, setDragGuide, viewport.width]);
3685
3701
  const finishColumnOrderPointerDrag = useCallback2((event, apply) => {
3686
3702
  const drag = columnOrderDragRef.current;
3687
3703
  if (!drag || drag.pointerId !== event.pointerId) return;
@@ -5193,6 +5209,34 @@ function TableInner({
5193
5209
  }
5194
5210
  ),
5195
5211
  /* @__PURE__ */ jsx7("div", { ref: dragGuideRef, className: "rvg-column-guide" }),
5212
+ columnDragPreview && /* @__PURE__ */ jsxs7(
5213
+ "div",
5214
+ {
5215
+ "aria-hidden": "true",
5216
+ className: "rvg-column-drag-preview",
5217
+ style: {
5218
+ left: columnDragPreview.left,
5219
+ top: 0,
5220
+ width: columnDragPreview.width,
5221
+ height: renderHeight
5222
+ },
5223
+ children: [
5224
+ /* @__PURE__ */ jsx7("div", { className: "rvg-column-drag-preview-header", style: { top: headerLeafTop, height: headerLeafHeight }, children: columns[columnDragPreview.sourceIndex]?.renderHeader?.(columns[columnDragPreview.sourceIndex]) ?? columns[columnDragPreview.sourceIndex]?.title }),
5225
+ rows.slice(domRange.rowStart, domRange.rowEnd).map((_row, visibleRowOffset) => {
5226
+ const rowIndex = domRange.rowStart + visibleRowOffset;
5227
+ return /* @__PURE__ */ jsx7(
5228
+ "div",
5229
+ {
5230
+ className: `rvg-column-drag-preview-cell${hasStripedRows && rowIndex % 2 === 1 ? " is-striped" : ""}`,
5231
+ style: { top: bodyTop + rowIndex * rowHeight - scrollRef.current.top, height: rowHeight },
5232
+ children: getCellLabel(rowIndex, columnDragPreview.sourceIndex)
5233
+ },
5234
+ `column-preview:${String(getRowKey(rows[rowIndex], rowIndex))}`
5235
+ );
5236
+ })
5237
+ ]
5238
+ }
5239
+ ),
5196
5240
  resizeGuideX !== null && /* @__PURE__ */ jsx7(
5197
5241
  "div",
5198
5242
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensui/lens-table",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "description": "A lightweight, canvas-rendered React table component for LensUI.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",