@coldsmirk/ledger-mantine 0.5.1 → 0.6.0
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 +100 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +100 -24
- package/dist/index.js.map +1 -1
- package/dist/styles.css +17 -10
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -487,9 +487,12 @@ interface UseDataTableOptions<TData extends RowData$1> {
|
|
|
487
487
|
onRowEditCommit?: (change: DataTableRowEditCommit<TData>) => void | Promise<void>;
|
|
488
488
|
/**
|
|
489
489
|
* A single keyboard-reachable current row (row click or ↑/↓/Home/End on the focused body;
|
|
490
|
-
* Enter fires `
|
|
490
|
+
* Enter fires `onRowActivate`), independent from checkbox selection. Off by default. A
|
|
491
|
+
* predicate keeps the rows it rejects out of the cursor's reach — the keys pass over them and
|
|
492
|
+
* a click leaves the current row where it was — and so out of activation too: what the
|
|
493
|
+
* keyboard cannot reach, a click does not activate ([rows.md](../docs/rows.md#active-row)).
|
|
491
494
|
*/
|
|
492
|
-
enableActiveRow?: boolean;
|
|
495
|
+
enableActiveRow?: boolean | ((row: Row<TData>) => boolean);
|
|
493
496
|
/**
|
|
494
497
|
* Drag-and-drop row reordering through an injected handle column. Row order IS data order —
|
|
495
498
|
* there is no order state — so a completed drag hands the move to `onRowReorder` and the
|
|
@@ -809,6 +812,11 @@ interface LedgerMeta<TData extends RowData$1> {
|
|
|
809
812
|
enabled: boolean;
|
|
810
813
|
id: string | null;
|
|
811
814
|
set: (id: string | null) => void;
|
|
815
|
+
/**
|
|
816
|
+
* Whether a row can be the current row, and so be activated: `enableActiveRow`'s predicate,
|
|
817
|
+
* or every row.
|
|
818
|
+
*/
|
|
819
|
+
canActivate: (row: Row<TData>) => boolean;
|
|
812
820
|
};
|
|
813
821
|
/**
|
|
814
822
|
* Header drag-reorder affordance (ledger-owned; TanStack has state but no switch).
|
package/dist/index.d.ts
CHANGED
|
@@ -487,9 +487,12 @@ interface UseDataTableOptions<TData extends RowData$1> {
|
|
|
487
487
|
onRowEditCommit?: (change: DataTableRowEditCommit<TData>) => void | Promise<void>;
|
|
488
488
|
/**
|
|
489
489
|
* A single keyboard-reachable current row (row click or ↑/↓/Home/End on the focused body;
|
|
490
|
-
* Enter fires `
|
|
490
|
+
* Enter fires `onRowActivate`), independent from checkbox selection. Off by default. A
|
|
491
|
+
* predicate keeps the rows it rejects out of the cursor's reach — the keys pass over them and
|
|
492
|
+
* a click leaves the current row where it was — and so out of activation too: what the
|
|
493
|
+
* keyboard cannot reach, a click does not activate ([rows.md](../docs/rows.md#active-row)).
|
|
491
494
|
*/
|
|
492
|
-
enableActiveRow?: boolean;
|
|
495
|
+
enableActiveRow?: boolean | ((row: Row<TData>) => boolean);
|
|
493
496
|
/**
|
|
494
497
|
* Drag-and-drop row reordering through an injected handle column. Row order IS data order —
|
|
495
498
|
* there is no order state — so a completed drag hands the move to `onRowReorder` and the
|
|
@@ -809,6 +812,11 @@ interface LedgerMeta<TData extends RowData$1> {
|
|
|
809
812
|
enabled: boolean;
|
|
810
813
|
id: string | null;
|
|
811
814
|
set: (id: string | null) => void;
|
|
815
|
+
/**
|
|
816
|
+
* Whether a row can be the current row, and so be activated: `enableActiveRow`'s predicate,
|
|
817
|
+
* or every row.
|
|
818
|
+
*/
|
|
819
|
+
canActivate: (row: Row<TData>) => boolean;
|
|
812
820
|
};
|
|
813
821
|
/**
|
|
814
822
|
* Header drag-reorder affordance (ledger-owned; TanStack has state but no switch).
|
package/dist/index.js
CHANGED
|
@@ -428,6 +428,8 @@ function useRowReorder({ onRowReorder, labels, viewportRef, getCenterRows, nameR
|
|
|
428
428
|
body.append(rowClone);
|
|
429
429
|
ghostTable.append(colgroup, body);
|
|
430
430
|
element.replaceChildren(ghostTable);
|
|
431
|
+
const surface = getComputedStyle(source).getPropertyValue("--ledger-body-bg").trim();
|
|
432
|
+
if (surface !== "") element.style.setProperty("--ledger-body-bg", surface);
|
|
431
433
|
const rowRect = source.getBoundingClientRect();
|
|
432
434
|
ghostOrigin.current = {
|
|
433
435
|
x: rowRect.left - ghostPosition.current.x,
|
|
@@ -1567,6 +1569,66 @@ function warnOnce(key, message) {
|
|
|
1567
1569
|
console.warn(`[ledger] ${message}`);
|
|
1568
1570
|
}
|
|
1569
1571
|
//#endregion
|
|
1572
|
+
//#region src/interactive.ts
|
|
1573
|
+
/**
|
|
1574
|
+
* An element that handles a click or a key itself: links, buttons, form controls and the labels
|
|
1575
|
+
* that forward to them, a disclosure's summary, editable content, and the interactive roles.
|
|
1576
|
+
*/
|
|
1577
|
+
const INTERACTIVE = [
|
|
1578
|
+
"a[href]",
|
|
1579
|
+
"area[href]",
|
|
1580
|
+
"button",
|
|
1581
|
+
"input",
|
|
1582
|
+
"select",
|
|
1583
|
+
"textarea",
|
|
1584
|
+
"label",
|
|
1585
|
+
"summary",
|
|
1586
|
+
"[contenteditable]:not([contenteditable=\"false\"])",
|
|
1587
|
+
...[
|
|
1588
|
+
"button",
|
|
1589
|
+
"checkbox",
|
|
1590
|
+
"combobox",
|
|
1591
|
+
"link",
|
|
1592
|
+
"menuitem",
|
|
1593
|
+
"menuitemcheckbox",
|
|
1594
|
+
"menuitemradio",
|
|
1595
|
+
"option",
|
|
1596
|
+
"radio",
|
|
1597
|
+
"searchbox",
|
|
1598
|
+
"slider",
|
|
1599
|
+
"spinbutton",
|
|
1600
|
+
"switch",
|
|
1601
|
+
"tab",
|
|
1602
|
+
"textbox",
|
|
1603
|
+
"treeitem"
|
|
1604
|
+
].map((role) => `[role="${role}"]`)
|
|
1605
|
+
].join(", ");
|
|
1606
|
+
/**
|
|
1607
|
+
* Whether an event belongs to `boundary` itself — the row a click reached, the body viewport a
|
|
1608
|
+
* key reached — rather than to something inside it that handles input of its own
|
|
1609
|
+
* (docs/rows.md#row-interaction):
|
|
1610
|
+
*
|
|
1611
|
+
* - it happened in the boundary's own DOM: React bubbles a portal's events through the tree
|
|
1612
|
+
* that rendered it, so a click on the item of a menu opened from a cell would otherwise reach
|
|
1613
|
+
* the row the menu's trigger sits in;
|
|
1614
|
+
* - and not on, or inside, an interactive element within the boundary, which owns it.
|
|
1615
|
+
*/
|
|
1616
|
+
function isOwnEvent(event, boundary) {
|
|
1617
|
+
const { target } = event;
|
|
1618
|
+
if (!(target instanceof Node) || !boundary.contains(target)) return false;
|
|
1619
|
+
const interactive = (target instanceof Element ? target : target.parentElement)?.closest(INTERACTIVE);
|
|
1620
|
+
return !interactive || interactive === boundary || !boundary.contains(interactive);
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Whether a click is the end of a text selection made inside `boundary`: the pointer went down,
|
|
1624
|
+
* dragged across text and came up there, which selected the text and chose nothing. (A
|
|
1625
|
+
* double-click selects the word it lands on as its own effect, so it is not asked.)
|
|
1626
|
+
*/
|
|
1627
|
+
function endsTextSelection(boundary) {
|
|
1628
|
+
const selection = boundary.ownerDocument.getSelection();
|
|
1629
|
+
return selection !== null && !selection.isCollapsed && boundary.contains(selection.anchorNode);
|
|
1630
|
+
}
|
|
1631
|
+
//#endregion
|
|
1570
1632
|
//#region src/ledger-commands.ts
|
|
1571
1633
|
function ledgerCommands(meta) {
|
|
1572
1634
|
return meta;
|
|
@@ -2569,17 +2631,20 @@ function DataCell({ cell, editing, rowEditing, isFirstDataCell, depth, rowSpan,
|
|
|
2569
2631
|
children: content
|
|
2570
2632
|
});
|
|
2571
2633
|
}
|
|
2572
|
-
function DataRowImpl({ row, dataIndex, last, rowsBelow, editingColumnId, editingRow, dragging, dropSide, selected, active, expanded, depth, spanning, columnWindow, pinnedPosition, pinnedOffset, virtualIndex, measureRef, ariaRowIndex }) {
|
|
2634
|
+
function DataRowImpl({ row, dataIndex, last, rowsBelow, editingColumnId, editingRow, dragging, dropSide, selected, active, activatable, expanded, depth, spanning, columnWindow, pinnedPosition, pinnedOffset, virtualIndex, measureRef, ariaRowIndex }) {
|
|
2573
2635
|
const { getStyles, onRowClick, onRowActivate, onRowDoubleClick, onRowContextMenu, rowProps, activeRowEnabled, setActiveRow } = useDataTableContext();
|
|
2574
2636
|
const cells = row.getVisibleCells();
|
|
2575
2637
|
const firstDataCellIndex = cells.findIndex((cell) => !isInternalColumn(cell.column.id));
|
|
2576
2638
|
const pinnedStyle = pinnedPosition === "top" ? { top: `${pinnedOffset ?? 0}px` } : pinnedPosition === "bottom" ? { bottom: `${pinnedOffset ?? 0}px` } : void 0;
|
|
2577
|
-
const handler = (callback) => callback ? (event) =>
|
|
2578
|
-
|
|
2579
|
-
if (activeRowEnabled) setActiveRow?.(row.id);
|
|
2580
|
-
onRowClick?.(row, event);
|
|
2581
|
-
onRowActivate?.(row, event);
|
|
2639
|
+
const handler = (callback, selecting) => callback ? (event) => {
|
|
2640
|
+
if (isOwnEvent(event, event.currentTarget) && !(selecting && endsTextSelection(event.currentTarget))) callback(row, event);
|
|
2582
2641
|
} : void 0;
|
|
2642
|
+
const activates = !activeRowEnabled || activatable;
|
|
2643
|
+
const handleClick = handler(onRowClick || onRowActivate && activates || activeRowEnabled && activatable ? (_, event) => {
|
|
2644
|
+
if (activeRowEnabled && activatable) setActiveRow?.(row.id);
|
|
2645
|
+
onRowClick?.(row, event);
|
|
2646
|
+
if (activates) onRowActivate?.(row, event);
|
|
2647
|
+
} : void 0, true);
|
|
2583
2648
|
return /* @__PURE__ */ jsx(Table.Tr, {
|
|
2584
2649
|
ref: measureRef,
|
|
2585
2650
|
...mergeElementProps(resolveElementProps(rowProps, row), {
|
|
@@ -2600,8 +2665,8 @@ function DataRowImpl({ row, dataIndex, last, rowsBelow, editingColumnId, editing
|
|
|
2600
2665
|
"data-selected": selected || void 0,
|
|
2601
2666
|
role: "row",
|
|
2602
2667
|
onClick: handleClick,
|
|
2603
|
-
onContextMenu: handler(onRowContextMenu),
|
|
2604
|
-
onDoubleClick: handler(onRowDoubleClick),
|
|
2668
|
+
onContextMenu: handler(onRowContextMenu, true),
|
|
2669
|
+
onDoubleClick: handler(onRowDoubleClick, false),
|
|
2605
2670
|
...getStyles("row", { style: pinnedStyle })
|
|
2606
2671
|
}),
|
|
2607
2672
|
children: renderRowCells()
|
|
@@ -2843,6 +2908,7 @@ function TableBody({ table, virtualization, columnWindow, viewportRef, loading,
|
|
|
2843
2908
|
const dropSide = reorderTarget?.rowId === row.id && !(reorderTarget.side === "after" && withDetailPanels && row.getIsExpanded()) ? reorderTarget.side : null;
|
|
2844
2909
|
const spanKey = spanningActive ? row.getVisibleCells().map((cell) => cell.getIsCovered() ? "x" : `${cell.getRowSpan()}:${cell.getColSpan()}`).join(" ") : "";
|
|
2845
2910
|
return /* @__PURE__ */ jsx(DataRow, {
|
|
2911
|
+
activatable: ledger?.activeRow.canActivate(row) ?? true,
|
|
2846
2912
|
active: activeRowId === row.id,
|
|
2847
2913
|
ariaRowIndex,
|
|
2848
2914
|
columnsKey,
|
|
@@ -2874,7 +2940,7 @@ function TableBody({ table, virtualization, columnWindow, viewportRef, loading,
|
|
|
2874
2940
|
const firstItem = items[0];
|
|
2875
2941
|
const lastItem = items.at(-1);
|
|
2876
2942
|
const topSpace = firstItem ? firstItem.start : 0;
|
|
2877
|
-
const bottomSpace = lastItem ? virtualizer.getTotalSize() - lastItem.end :
|
|
2943
|
+
const bottomSpace = lastItem ? virtualizer.getTotalSize() - lastItem.end : virtualizer.getTotalSize();
|
|
2878
2944
|
center = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2879
2945
|
topSpace > 0 && /* @__PURE__ */ jsx("tr", {
|
|
2880
2946
|
"aria-hidden": true,
|
|
@@ -3858,7 +3924,7 @@ const builtInFilterFns = {
|
|
|
3858
3924
|
* private `RangeValue` alias behind the min/max/extent value types becomes nameable only by a
|
|
3859
3925
|
* deep path the package's `exports` map hides, and an inferred registry fails declaration emit
|
|
3860
3926
|
* (TS2883). Naming each definition by its public export emits the type the upstream fix will
|
|
3861
|
-
* emit anyway. Upstream: sxzz/rolldown-plugin-dts#312 (fix: #310)
|
|
3927
|
+
* emit anyway. Upstream: TanStack/table#6619, sxzz/rolldown-plugin-dts#312 (fix: #310).
|
|
3862
3928
|
*/
|
|
3863
3929
|
const builtInAggregationFns = {
|
|
3864
3930
|
count: aggregationFn_count,
|
|
@@ -5878,6 +5944,10 @@ const NO_ROW_PINNING = {
|
|
|
5878
5944
|
top: [],
|
|
5879
5945
|
bottom: []
|
|
5880
5946
|
};
|
|
5947
|
+
/**
|
|
5948
|
+
* `enableActiveRow` without a predicate: the cursor can rest on any row.
|
|
5949
|
+
*/
|
|
5950
|
+
const everyRow = () => true;
|
|
5881
5951
|
const DEFAULT_PAGINATION = {
|
|
5882
5952
|
pageIndex: 0,
|
|
5883
5953
|
pageSize: 20
|
|
@@ -6099,9 +6169,10 @@ function useDataTable(options) {
|
|
|
6099
6169
|
renderDetailPanel,
|
|
6100
6170
|
selectAllScope,
|
|
6101
6171
|
activeRow: {
|
|
6102
|
-
enabled: enableActiveRow,
|
|
6172
|
+
enabled: enableActiveRow !== false,
|
|
6103
6173
|
id: activeRowId,
|
|
6104
|
-
set: setActiveRowId
|
|
6174
|
+
set: setActiveRowId,
|
|
6175
|
+
canActivate: typeof enableActiveRow === "function" ? enableActiveRow : everyRow
|
|
6105
6176
|
},
|
|
6106
6177
|
enableColumnOrdering,
|
|
6107
6178
|
enableColumnResizing,
|
|
@@ -7076,7 +7147,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7076
7147
|
]);
|
|
7077
7148
|
const handleActiveRowKeyDown = useEventCallback((event) => {
|
|
7078
7149
|
if (!activeRowEnabled || !setActiveRow) return;
|
|
7079
|
-
if (event
|
|
7150
|
+
if (!isOwnEvent(event, event.currentTarget)) return;
|
|
7080
7151
|
if (event.key === "F2") {
|
|
7081
7152
|
if (!editing || activeRowId === null) return;
|
|
7082
7153
|
const rowMode = editing.mode === "row";
|
|
@@ -7091,35 +7162,40 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7091
7162
|
return;
|
|
7092
7163
|
}
|
|
7093
7164
|
const rows = displaySnapshot.ordered;
|
|
7094
|
-
|
|
7165
|
+
const canActivate = ledger?.activeRow.canActivate;
|
|
7166
|
+
if (rows.length === 0 || !canActivate) return;
|
|
7095
7167
|
const currentIndex = activeRowId === null ? -1 : rows.findIndex((row) => row.id === activeRowId);
|
|
7096
|
-
const
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7168
|
+
const moveFrom = (from, step) => {
|
|
7169
|
+
for (let index = from; index >= 0 && index < rows.length; index += step) {
|
|
7170
|
+
const row = rows[index];
|
|
7171
|
+
if (canActivate(row)) {
|
|
7172
|
+
setActiveRow(row.id);
|
|
7173
|
+
scrollRowIntoView(row.id);
|
|
7174
|
+
return;
|
|
7175
|
+
}
|
|
7101
7176
|
}
|
|
7177
|
+
if (currentIndex !== -1 && activeRowId !== null) scrollRowIntoView(activeRowId);
|
|
7102
7178
|
};
|
|
7103
7179
|
switch (event.key) {
|
|
7104
7180
|
case "ArrowDown":
|
|
7105
7181
|
event.preventDefault();
|
|
7106
|
-
|
|
7182
|
+
moveFrom(currentIndex + 1, 1);
|
|
7107
7183
|
break;
|
|
7108
7184
|
case "ArrowUp":
|
|
7109
7185
|
event.preventDefault();
|
|
7110
|
-
|
|
7186
|
+
moveFrom(currentIndex === -1 ? 0 : currentIndex - 1, currentIndex === -1 ? 1 : -1);
|
|
7111
7187
|
break;
|
|
7112
7188
|
case "Home":
|
|
7113
7189
|
event.preventDefault();
|
|
7114
|
-
|
|
7190
|
+
moveFrom(0, 1);
|
|
7115
7191
|
break;
|
|
7116
7192
|
case "End":
|
|
7117
7193
|
event.preventDefault();
|
|
7118
|
-
|
|
7194
|
+
moveFrom(rows.length - 1, -1);
|
|
7119
7195
|
break;
|
|
7120
7196
|
case "Enter": {
|
|
7121
7197
|
const row = currentIndex >= 0 ? rows[currentIndex] : null;
|
|
7122
|
-
if (row && onRowActivate) {
|
|
7198
|
+
if (row && onRowActivate && canActivate(row)) {
|
|
7123
7199
|
event.preventDefault();
|
|
7124
7200
|
onRowActivate(row, event);
|
|
7125
7201
|
}
|