@coldsmirk/ledger-mantine 0.5.0 → 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 +106 -26
- 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 +106 -26
- package/dist/index.js.map +1 -1
- package/dist/styles.css +32 -16
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -452,6 +452,8 @@ function useRowReorder({ onRowReorder, labels, viewportRef, getCenterRows, nameR
|
|
|
452
452
|
body.append(rowClone);
|
|
453
453
|
ghostTable.append(colgroup, body);
|
|
454
454
|
element.replaceChildren(ghostTable);
|
|
455
|
+
const surface = getComputedStyle(source).getPropertyValue("--ledger-body-bg").trim();
|
|
456
|
+
if (surface !== "") element.style.setProperty("--ledger-body-bg", surface);
|
|
455
457
|
const rowRect = source.getBoundingClientRect();
|
|
456
458
|
ghostOrigin.current = {
|
|
457
459
|
x: rowRect.left - ghostPosition.current.x,
|
|
@@ -1591,6 +1593,66 @@ function warnOnce(key, message) {
|
|
|
1591
1593
|
console.warn(`[ledger] ${message}`);
|
|
1592
1594
|
}
|
|
1593
1595
|
//#endregion
|
|
1596
|
+
//#region src/interactive.ts
|
|
1597
|
+
/**
|
|
1598
|
+
* An element that handles a click or a key itself: links, buttons, form controls and the labels
|
|
1599
|
+
* that forward to them, a disclosure's summary, editable content, and the interactive roles.
|
|
1600
|
+
*/
|
|
1601
|
+
const INTERACTIVE = [
|
|
1602
|
+
"a[href]",
|
|
1603
|
+
"area[href]",
|
|
1604
|
+
"button",
|
|
1605
|
+
"input",
|
|
1606
|
+
"select",
|
|
1607
|
+
"textarea",
|
|
1608
|
+
"label",
|
|
1609
|
+
"summary",
|
|
1610
|
+
"[contenteditable]:not([contenteditable=\"false\"])",
|
|
1611
|
+
...[
|
|
1612
|
+
"button",
|
|
1613
|
+
"checkbox",
|
|
1614
|
+
"combobox",
|
|
1615
|
+
"link",
|
|
1616
|
+
"menuitem",
|
|
1617
|
+
"menuitemcheckbox",
|
|
1618
|
+
"menuitemradio",
|
|
1619
|
+
"option",
|
|
1620
|
+
"radio",
|
|
1621
|
+
"searchbox",
|
|
1622
|
+
"slider",
|
|
1623
|
+
"spinbutton",
|
|
1624
|
+
"switch",
|
|
1625
|
+
"tab",
|
|
1626
|
+
"textbox",
|
|
1627
|
+
"treeitem"
|
|
1628
|
+
].map((role) => `[role="${role}"]`)
|
|
1629
|
+
].join(", ");
|
|
1630
|
+
/**
|
|
1631
|
+
* Whether an event belongs to `boundary` itself — the row a click reached, the body viewport a
|
|
1632
|
+
* key reached — rather than to something inside it that handles input of its own
|
|
1633
|
+
* (docs/rows.md#row-interaction):
|
|
1634
|
+
*
|
|
1635
|
+
* - it happened in the boundary's own DOM: React bubbles a portal's events through the tree
|
|
1636
|
+
* that rendered it, so a click on the item of a menu opened from a cell would otherwise reach
|
|
1637
|
+
* the row the menu's trigger sits in;
|
|
1638
|
+
* - and not on, or inside, an interactive element within the boundary, which owns it.
|
|
1639
|
+
*/
|
|
1640
|
+
function isOwnEvent(event, boundary) {
|
|
1641
|
+
const { target } = event;
|
|
1642
|
+
if (!(target instanceof Node) || !boundary.contains(target)) return false;
|
|
1643
|
+
const interactive = (target instanceof Element ? target : target.parentElement)?.closest(INTERACTIVE);
|
|
1644
|
+
return !interactive || interactive === boundary || !boundary.contains(interactive);
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* Whether a click is the end of a text selection made inside `boundary`: the pointer went down,
|
|
1648
|
+
* dragged across text and came up there, which selected the text and chose nothing. (A
|
|
1649
|
+
* double-click selects the word it lands on as its own effect, so it is not asked.)
|
|
1650
|
+
*/
|
|
1651
|
+
function endsTextSelection(boundary) {
|
|
1652
|
+
const selection = boundary.ownerDocument.getSelection();
|
|
1653
|
+
return selection !== null && !selection.isCollapsed && boundary.contains(selection.anchorNode);
|
|
1654
|
+
}
|
|
1655
|
+
//#endregion
|
|
1594
1656
|
//#region src/ledger-commands.ts
|
|
1595
1657
|
function ledgerCommands(meta) {
|
|
1596
1658
|
return meta;
|
|
@@ -2593,17 +2655,20 @@ function DataCell({ cell, editing, rowEditing, isFirstDataCell, depth, rowSpan,
|
|
|
2593
2655
|
children: content
|
|
2594
2656
|
});
|
|
2595
2657
|
}
|
|
2596
|
-
function DataRowImpl({ row, dataIndex, last, rowsBelow, editingColumnId, editingRow, dragging, dropSide, selected, active, expanded, depth, spanning, columnWindow, pinnedPosition, pinnedOffset, virtualIndex, measureRef, ariaRowIndex }) {
|
|
2658
|
+
function DataRowImpl({ row, dataIndex, last, rowsBelow, editingColumnId, editingRow, dragging, dropSide, selected, active, activatable, expanded, depth, spanning, columnWindow, pinnedPosition, pinnedOffset, virtualIndex, measureRef, ariaRowIndex }) {
|
|
2597
2659
|
const { getStyles, onRowClick, onRowActivate, onRowDoubleClick, onRowContextMenu, rowProps, activeRowEnabled, setActiveRow } = useDataTableContext();
|
|
2598
2660
|
const cells = row.getVisibleCells();
|
|
2599
2661
|
const firstDataCellIndex = cells.findIndex((cell) => !isInternalColumn(cell.column.id));
|
|
2600
2662
|
const pinnedStyle = pinnedPosition === "top" ? { top: `${pinnedOffset ?? 0}px` } : pinnedPosition === "bottom" ? { bottom: `${pinnedOffset ?? 0}px` } : void 0;
|
|
2601
|
-
const handler = (callback) => callback ? (event) =>
|
|
2602
|
-
|
|
2603
|
-
if (activeRowEnabled) setActiveRow?.(row.id);
|
|
2604
|
-
onRowClick?.(row, event);
|
|
2605
|
-
onRowActivate?.(row, event);
|
|
2663
|
+
const handler = (callback, selecting) => callback ? (event) => {
|
|
2664
|
+
if (isOwnEvent(event, event.currentTarget) && !(selecting && endsTextSelection(event.currentTarget))) callback(row, event);
|
|
2606
2665
|
} : void 0;
|
|
2666
|
+
const activates = !activeRowEnabled || activatable;
|
|
2667
|
+
const handleClick = handler(onRowClick || onRowActivate && activates || activeRowEnabled && activatable ? (_, event) => {
|
|
2668
|
+
if (activeRowEnabled && activatable) setActiveRow?.(row.id);
|
|
2669
|
+
onRowClick?.(row, event);
|
|
2670
|
+
if (activates) onRowActivate?.(row, event);
|
|
2671
|
+
} : void 0, true);
|
|
2607
2672
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Table.Tr, {
|
|
2608
2673
|
ref: measureRef,
|
|
2609
2674
|
...mergeElementProps(resolveElementProps(rowProps, row), {
|
|
@@ -2624,8 +2689,8 @@ function DataRowImpl({ row, dataIndex, last, rowsBelow, editingColumnId, editing
|
|
|
2624
2689
|
"data-selected": selected || void 0,
|
|
2625
2690
|
role: "row",
|
|
2626
2691
|
onClick: handleClick,
|
|
2627
|
-
onContextMenu: handler(onRowContextMenu),
|
|
2628
|
-
onDoubleClick: handler(onRowDoubleClick),
|
|
2692
|
+
onContextMenu: handler(onRowContextMenu, true),
|
|
2693
|
+
onDoubleClick: handler(onRowDoubleClick, false),
|
|
2629
2694
|
...getStyles("row", { style: pinnedStyle })
|
|
2630
2695
|
}),
|
|
2631
2696
|
children: renderRowCells()
|
|
@@ -2867,6 +2932,7 @@ function TableBody({ table, virtualization, columnWindow, viewportRef, loading,
|
|
|
2867
2932
|
const dropSide = reorderTarget?.rowId === row.id && !(reorderTarget.side === "after" && withDetailPanels && row.getIsExpanded()) ? reorderTarget.side : null;
|
|
2868
2933
|
const spanKey = spanningActive ? row.getVisibleCells().map((cell) => cell.getIsCovered() ? "x" : `${cell.getRowSpan()}:${cell.getColSpan()}`).join(" ") : "";
|
|
2869
2934
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataRow, {
|
|
2935
|
+
activatable: ledger?.activeRow.canActivate(row) ?? true,
|
|
2870
2936
|
active: activeRowId === row.id,
|
|
2871
2937
|
ariaRowIndex,
|
|
2872
2938
|
columnsKey,
|
|
@@ -2898,7 +2964,7 @@ function TableBody({ table, virtualization, columnWindow, viewportRef, loading,
|
|
|
2898
2964
|
const firstItem = items[0];
|
|
2899
2965
|
const lastItem = items.at(-1);
|
|
2900
2966
|
const topSpace = firstItem ? firstItem.start : 0;
|
|
2901
|
-
const bottomSpace = lastItem ? virtualizer.getTotalSize() - lastItem.end :
|
|
2967
|
+
const bottomSpace = lastItem ? virtualizer.getTotalSize() - lastItem.end : virtualizer.getTotalSize();
|
|
2902
2968
|
center = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
2903
2969
|
topSpace > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
|
|
2904
2970
|
"aria-hidden": true,
|
|
@@ -3876,9 +3942,13 @@ const builtInFilterFns = {
|
|
|
3876
3942
|
weakEquals: _tanstack_react_table.filterFn_weakEquals
|
|
3877
3943
|
};
|
|
3878
3944
|
/**
|
|
3879
|
-
* Typed through the exported definitions on purpose
|
|
3880
|
-
*
|
|
3881
|
-
*
|
|
3945
|
+
* Typed through the exported definitions on purpose. Since 9.2.5 TanStack's published `.d.ts`
|
|
3946
|
+
* files no longer end in an `export { … }` list (rolldown-plugin-dts 0.28 inlines the exports and
|
|
3947
|
+
* drops the marker), so TypeScript treats every top-level declaration in them as exported: the
|
|
3948
|
+
* private `RangeValue` alias behind the min/max/extent value types becomes nameable only by a
|
|
3949
|
+
* deep path the package's `exports` map hides, and an inferred registry fails declaration emit
|
|
3950
|
+
* (TS2883). Naming each definition by its public export emits the type the upstream fix will
|
|
3951
|
+
* emit anyway. Upstream: TanStack/table#6619, sxzz/rolldown-plugin-dts#312 (fix: #310).
|
|
3882
3952
|
*/
|
|
3883
3953
|
const builtInAggregationFns = {
|
|
3884
3954
|
count: _tanstack_react_table.aggregationFn_count,
|
|
@@ -5898,6 +5968,10 @@ const NO_ROW_PINNING = {
|
|
|
5898
5968
|
top: [],
|
|
5899
5969
|
bottom: []
|
|
5900
5970
|
};
|
|
5971
|
+
/**
|
|
5972
|
+
* `enableActiveRow` without a predicate: the cursor can rest on any row.
|
|
5973
|
+
*/
|
|
5974
|
+
const everyRow = () => true;
|
|
5901
5975
|
const DEFAULT_PAGINATION = {
|
|
5902
5976
|
pageIndex: 0,
|
|
5903
5977
|
pageSize: 20
|
|
@@ -6119,9 +6193,10 @@ function useDataTable(options) {
|
|
|
6119
6193
|
renderDetailPanel,
|
|
6120
6194
|
selectAllScope,
|
|
6121
6195
|
activeRow: {
|
|
6122
|
-
enabled: enableActiveRow,
|
|
6196
|
+
enabled: enableActiveRow !== false,
|
|
6123
6197
|
id: activeRowId,
|
|
6124
|
-
set: setActiveRowId
|
|
6198
|
+
set: setActiveRowId,
|
|
6199
|
+
canActivate: typeof enableActiveRow === "function" ? enableActiveRow : everyRow
|
|
6125
6200
|
},
|
|
6126
6201
|
enableColumnOrdering,
|
|
6127
6202
|
enableColumnResizing,
|
|
@@ -7096,7 +7171,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7096
7171
|
]);
|
|
7097
7172
|
const handleActiveRowKeyDown = useEventCallback((event) => {
|
|
7098
7173
|
if (!activeRowEnabled || !setActiveRow) return;
|
|
7099
|
-
if (event
|
|
7174
|
+
if (!isOwnEvent(event, event.currentTarget)) return;
|
|
7100
7175
|
if (event.key === "F2") {
|
|
7101
7176
|
if (!editing || activeRowId === null) return;
|
|
7102
7177
|
const rowMode = editing.mode === "row";
|
|
@@ -7111,35 +7186,40 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7111
7186
|
return;
|
|
7112
7187
|
}
|
|
7113
7188
|
const rows = displaySnapshot.ordered;
|
|
7114
|
-
|
|
7189
|
+
const canActivate = ledger?.activeRow.canActivate;
|
|
7190
|
+
if (rows.length === 0 || !canActivate) return;
|
|
7115
7191
|
const currentIndex = activeRowId === null ? -1 : rows.findIndex((row) => row.id === activeRowId);
|
|
7116
|
-
const
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7192
|
+
const moveFrom = (from, step) => {
|
|
7193
|
+
for (let index = from; index >= 0 && index < rows.length; index += step) {
|
|
7194
|
+
const row = rows[index];
|
|
7195
|
+
if (canActivate(row)) {
|
|
7196
|
+
setActiveRow(row.id);
|
|
7197
|
+
scrollRowIntoView(row.id);
|
|
7198
|
+
return;
|
|
7199
|
+
}
|
|
7121
7200
|
}
|
|
7201
|
+
if (currentIndex !== -1 && activeRowId !== null) scrollRowIntoView(activeRowId);
|
|
7122
7202
|
};
|
|
7123
7203
|
switch (event.key) {
|
|
7124
7204
|
case "ArrowDown":
|
|
7125
7205
|
event.preventDefault();
|
|
7126
|
-
|
|
7206
|
+
moveFrom(currentIndex + 1, 1);
|
|
7127
7207
|
break;
|
|
7128
7208
|
case "ArrowUp":
|
|
7129
7209
|
event.preventDefault();
|
|
7130
|
-
|
|
7210
|
+
moveFrom(currentIndex === -1 ? 0 : currentIndex - 1, currentIndex === -1 ? 1 : -1);
|
|
7131
7211
|
break;
|
|
7132
7212
|
case "Home":
|
|
7133
7213
|
event.preventDefault();
|
|
7134
|
-
|
|
7214
|
+
moveFrom(0, 1);
|
|
7135
7215
|
break;
|
|
7136
7216
|
case "End":
|
|
7137
7217
|
event.preventDefault();
|
|
7138
|
-
|
|
7218
|
+
moveFrom(rows.length - 1, -1);
|
|
7139
7219
|
break;
|
|
7140
7220
|
case "Enter": {
|
|
7141
7221
|
const row = currentIndex >= 0 ? rows[currentIndex] : null;
|
|
7142
|
-
if (row && onRowActivate) {
|
|
7222
|
+
if (row && onRowActivate && canActivate(row)) {
|
|
7143
7223
|
event.preventDefault();
|
|
7144
7224
|
onRowActivate(row, event);
|
|
7145
7225
|
}
|