@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.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,
|
|
@@ -3882,7 +3948,7 @@ const builtInFilterFns = {
|
|
|
3882
3948
|
* private `RangeValue` alias behind the min/max/extent value types becomes nameable only by a
|
|
3883
3949
|
* deep path the package's `exports` map hides, and an inferred registry fails declaration emit
|
|
3884
3950
|
* (TS2883). Naming each definition by its public export emits the type the upstream fix will
|
|
3885
|
-
* emit anyway. Upstream: sxzz/rolldown-plugin-dts#312 (fix: #310)
|
|
3951
|
+
* emit anyway. Upstream: TanStack/table#6619, sxzz/rolldown-plugin-dts#312 (fix: #310).
|
|
3886
3952
|
*/
|
|
3887
3953
|
const builtInAggregationFns = {
|
|
3888
3954
|
count: _tanstack_react_table.aggregationFn_count,
|
|
@@ -5902,6 +5968,10 @@ const NO_ROW_PINNING = {
|
|
|
5902
5968
|
top: [],
|
|
5903
5969
|
bottom: []
|
|
5904
5970
|
};
|
|
5971
|
+
/**
|
|
5972
|
+
* `enableActiveRow` without a predicate: the cursor can rest on any row.
|
|
5973
|
+
*/
|
|
5974
|
+
const everyRow = () => true;
|
|
5905
5975
|
const DEFAULT_PAGINATION = {
|
|
5906
5976
|
pageIndex: 0,
|
|
5907
5977
|
pageSize: 20
|
|
@@ -6123,9 +6193,10 @@ function useDataTable(options) {
|
|
|
6123
6193
|
renderDetailPanel,
|
|
6124
6194
|
selectAllScope,
|
|
6125
6195
|
activeRow: {
|
|
6126
|
-
enabled: enableActiveRow,
|
|
6196
|
+
enabled: enableActiveRow !== false,
|
|
6127
6197
|
id: activeRowId,
|
|
6128
|
-
set: setActiveRowId
|
|
6198
|
+
set: setActiveRowId,
|
|
6199
|
+
canActivate: typeof enableActiveRow === "function" ? enableActiveRow : everyRow
|
|
6129
6200
|
},
|
|
6130
6201
|
enableColumnOrdering,
|
|
6131
6202
|
enableColumnResizing,
|
|
@@ -7100,7 +7171,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7100
7171
|
]);
|
|
7101
7172
|
const handleActiveRowKeyDown = useEventCallback((event) => {
|
|
7102
7173
|
if (!activeRowEnabled || !setActiveRow) return;
|
|
7103
|
-
if (event
|
|
7174
|
+
if (!isOwnEvent(event, event.currentTarget)) return;
|
|
7104
7175
|
if (event.key === "F2") {
|
|
7105
7176
|
if (!editing || activeRowId === null) return;
|
|
7106
7177
|
const rowMode = editing.mode === "row";
|
|
@@ -7115,35 +7186,40 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7115
7186
|
return;
|
|
7116
7187
|
}
|
|
7117
7188
|
const rows = displaySnapshot.ordered;
|
|
7118
|
-
|
|
7189
|
+
const canActivate = ledger?.activeRow.canActivate;
|
|
7190
|
+
if (rows.length === 0 || !canActivate) return;
|
|
7119
7191
|
const currentIndex = activeRowId === null ? -1 : rows.findIndex((row) => row.id === activeRowId);
|
|
7120
|
-
const
|
|
7121
|
-
|
|
7122
|
-
|
|
7123
|
-
|
|
7124
|
-
|
|
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
|
+
}
|
|
7125
7200
|
}
|
|
7201
|
+
if (currentIndex !== -1 && activeRowId !== null) scrollRowIntoView(activeRowId);
|
|
7126
7202
|
};
|
|
7127
7203
|
switch (event.key) {
|
|
7128
7204
|
case "ArrowDown":
|
|
7129
7205
|
event.preventDefault();
|
|
7130
|
-
|
|
7206
|
+
moveFrom(currentIndex + 1, 1);
|
|
7131
7207
|
break;
|
|
7132
7208
|
case "ArrowUp":
|
|
7133
7209
|
event.preventDefault();
|
|
7134
|
-
|
|
7210
|
+
moveFrom(currentIndex === -1 ? 0 : currentIndex - 1, currentIndex === -1 ? 1 : -1);
|
|
7135
7211
|
break;
|
|
7136
7212
|
case "Home":
|
|
7137
7213
|
event.preventDefault();
|
|
7138
|
-
|
|
7214
|
+
moveFrom(0, 1);
|
|
7139
7215
|
break;
|
|
7140
7216
|
case "End":
|
|
7141
7217
|
event.preventDefault();
|
|
7142
|
-
|
|
7218
|
+
moveFrom(rows.length - 1, -1);
|
|
7143
7219
|
break;
|
|
7144
7220
|
case "Enter": {
|
|
7145
7221
|
const row = currentIndex >= 0 ? rows[currentIndex] : null;
|
|
7146
|
-
if (row && onRowActivate) {
|
|
7222
|
+
if (row && onRowActivate && canActivate(row)) {
|
|
7147
7223
|
event.preventDefault();
|
|
7148
7224
|
onRowActivate(row, event);
|
|
7149
7225
|
}
|