@coldsmirk/ledger-mantine 0.5.1 → 0.7.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 +105 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +105 -26
- package/dist/index.js.map +1 -1
- package/dist/{labels-D-6FCakH.d.ts → labels-D6GC8goU.d.cts} +10 -4
- package/dist/{labels-D-6FCakH.d.cts → labels-D6GC8goU.d.ts} +10 -4
- package/dist/locales.cjs +2 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.d.cts +1 -1
- package/dist/locales.d.ts +1 -1
- package/dist/locales.js +2 -1
- package/dist/locales.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,
|
|
@@ -1095,7 +1097,8 @@ const defaultLabels = {
|
|
|
1095
1097
|
selectRow: "Select row",
|
|
1096
1098
|
selectedCount: (count) => `${count} selected`,
|
|
1097
1099
|
clearSelection: "Clear selection",
|
|
1098
|
-
|
|
1100
|
+
rows: "Rows",
|
|
1101
|
+
rowNavigation: "Use the arrow keys to move between rows",
|
|
1099
1102
|
currentRow: (row, index, count) => `${row}, row ${index} of ${count}`,
|
|
1100
1103
|
expandRow: "Expand row",
|
|
1101
1104
|
collapseRow: "Collapse row",
|
|
@@ -1591,6 +1594,66 @@ function warnOnce(key, message) {
|
|
|
1591
1594
|
console.warn(`[ledger] ${message}`);
|
|
1592
1595
|
}
|
|
1593
1596
|
//#endregion
|
|
1597
|
+
//#region src/interactive.ts
|
|
1598
|
+
/**
|
|
1599
|
+
* An element that handles a click or a key itself: links, buttons, form controls and the labels
|
|
1600
|
+
* that forward to them, a disclosure's summary, editable content, and the interactive roles.
|
|
1601
|
+
*/
|
|
1602
|
+
const INTERACTIVE = [
|
|
1603
|
+
"a[href]",
|
|
1604
|
+
"area[href]",
|
|
1605
|
+
"button",
|
|
1606
|
+
"input",
|
|
1607
|
+
"select",
|
|
1608
|
+
"textarea",
|
|
1609
|
+
"label",
|
|
1610
|
+
"summary",
|
|
1611
|
+
"[contenteditable]:not([contenteditable=\"false\"])",
|
|
1612
|
+
...[
|
|
1613
|
+
"button",
|
|
1614
|
+
"checkbox",
|
|
1615
|
+
"combobox",
|
|
1616
|
+
"link",
|
|
1617
|
+
"menuitem",
|
|
1618
|
+
"menuitemcheckbox",
|
|
1619
|
+
"menuitemradio",
|
|
1620
|
+
"option",
|
|
1621
|
+
"radio",
|
|
1622
|
+
"searchbox",
|
|
1623
|
+
"slider",
|
|
1624
|
+
"spinbutton",
|
|
1625
|
+
"switch",
|
|
1626
|
+
"tab",
|
|
1627
|
+
"textbox",
|
|
1628
|
+
"treeitem"
|
|
1629
|
+
].map((role) => `[role="${role}"]`)
|
|
1630
|
+
].join(", ");
|
|
1631
|
+
/**
|
|
1632
|
+
* Whether an event belongs to `boundary` itself — the row a click reached, the body viewport a
|
|
1633
|
+
* key reached — rather than to something inside it that handles input of its own
|
|
1634
|
+
* (docs/rows.md#row-interaction):
|
|
1635
|
+
*
|
|
1636
|
+
* - it happened in the boundary's own DOM: React bubbles a portal's events through the tree
|
|
1637
|
+
* that rendered it, so a click on the item of a menu opened from a cell would otherwise reach
|
|
1638
|
+
* the row the menu's trigger sits in;
|
|
1639
|
+
* - and not on, or inside, an interactive element within the boundary, which owns it.
|
|
1640
|
+
*/
|
|
1641
|
+
function isOwnEvent(event, boundary) {
|
|
1642
|
+
const { target } = event;
|
|
1643
|
+
if (!(target instanceof Node) || !boundary.contains(target)) return false;
|
|
1644
|
+
const interactive = (target instanceof Element ? target : target.parentElement)?.closest(INTERACTIVE);
|
|
1645
|
+
return !interactive || interactive === boundary || !boundary.contains(interactive);
|
|
1646
|
+
}
|
|
1647
|
+
/**
|
|
1648
|
+
* Whether a click is the end of a text selection made inside `boundary`: the pointer went down,
|
|
1649
|
+
* dragged across text and came up there, which selected the text and chose nothing. (A
|
|
1650
|
+
* double-click selects the word it lands on as its own effect, so it is not asked.)
|
|
1651
|
+
*/
|
|
1652
|
+
function endsTextSelection(boundary) {
|
|
1653
|
+
const selection = boundary.ownerDocument.getSelection();
|
|
1654
|
+
return selection !== null && !selection.isCollapsed && boundary.contains(selection.anchorNode);
|
|
1655
|
+
}
|
|
1656
|
+
//#endregion
|
|
1594
1657
|
//#region src/ledger-commands.ts
|
|
1595
1658
|
function ledgerCommands(meta) {
|
|
1596
1659
|
return meta;
|
|
@@ -2593,17 +2656,20 @@ function DataCell({ cell, editing, rowEditing, isFirstDataCell, depth, rowSpan,
|
|
|
2593
2656
|
children: content
|
|
2594
2657
|
});
|
|
2595
2658
|
}
|
|
2596
|
-
function DataRowImpl({ row, dataIndex, last, rowsBelow, editingColumnId, editingRow, dragging, dropSide, selected, active, expanded, depth, spanning, columnWindow, pinnedPosition, pinnedOffset, virtualIndex, measureRef, ariaRowIndex }) {
|
|
2659
|
+
function DataRowImpl({ row, dataIndex, last, rowsBelow, editingColumnId, editingRow, dragging, dropSide, selected, active, activatable, expanded, depth, spanning, columnWindow, pinnedPosition, pinnedOffset, virtualIndex, measureRef, ariaRowIndex }) {
|
|
2597
2660
|
const { getStyles, onRowClick, onRowActivate, onRowDoubleClick, onRowContextMenu, rowProps, activeRowEnabled, setActiveRow } = useDataTableContext();
|
|
2598
2661
|
const cells = row.getVisibleCells();
|
|
2599
2662
|
const firstDataCellIndex = cells.findIndex((cell) => !isInternalColumn(cell.column.id));
|
|
2600
2663
|
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);
|
|
2664
|
+
const handler = (callback, selecting) => callback ? (event) => {
|
|
2665
|
+
if (isOwnEvent(event, event.currentTarget) && !(selecting && endsTextSelection(event.currentTarget))) callback(row, event);
|
|
2606
2666
|
} : void 0;
|
|
2667
|
+
const activates = !activeRowEnabled || activatable;
|
|
2668
|
+
const handleClick = handler(onRowClick || onRowActivate && activates || activeRowEnabled && activatable ? (_, event) => {
|
|
2669
|
+
if (activeRowEnabled && activatable) setActiveRow?.(row.id);
|
|
2670
|
+
onRowClick?.(row, event);
|
|
2671
|
+
if (activates) onRowActivate?.(row, event);
|
|
2672
|
+
} : void 0, true);
|
|
2607
2673
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Table.Tr, {
|
|
2608
2674
|
ref: measureRef,
|
|
2609
2675
|
...mergeElementProps(resolveElementProps(rowProps, row), {
|
|
@@ -2624,8 +2690,8 @@ function DataRowImpl({ row, dataIndex, last, rowsBelow, editingColumnId, editing
|
|
|
2624
2690
|
"data-selected": selected || void 0,
|
|
2625
2691
|
role: "row",
|
|
2626
2692
|
onClick: handleClick,
|
|
2627
|
-
onContextMenu: handler(onRowContextMenu),
|
|
2628
|
-
onDoubleClick: handler(onRowDoubleClick),
|
|
2693
|
+
onContextMenu: handler(onRowContextMenu, true),
|
|
2694
|
+
onDoubleClick: handler(onRowDoubleClick, false),
|
|
2629
2695
|
...getStyles("row", { style: pinnedStyle })
|
|
2630
2696
|
}),
|
|
2631
2697
|
children: renderRowCells()
|
|
@@ -2867,6 +2933,7 @@ function TableBody({ table, virtualization, columnWindow, viewportRef, loading,
|
|
|
2867
2933
|
const dropSide = reorderTarget?.rowId === row.id && !(reorderTarget.side === "after" && withDetailPanels && row.getIsExpanded()) ? reorderTarget.side : null;
|
|
2868
2934
|
const spanKey = spanningActive ? row.getVisibleCells().map((cell) => cell.getIsCovered() ? "x" : `${cell.getRowSpan()}:${cell.getColSpan()}`).join(" ") : "";
|
|
2869
2935
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataRow, {
|
|
2936
|
+
activatable: ledger?.activeRow.canActivate(row) ?? true,
|
|
2870
2937
|
active: activeRowId === row.id,
|
|
2871
2938
|
ariaRowIndex,
|
|
2872
2939
|
columnsKey,
|
|
@@ -2898,7 +2965,7 @@ function TableBody({ table, virtualization, columnWindow, viewportRef, loading,
|
|
|
2898
2965
|
const firstItem = items[0];
|
|
2899
2966
|
const lastItem = items.at(-1);
|
|
2900
2967
|
const topSpace = firstItem ? firstItem.start : 0;
|
|
2901
|
-
const bottomSpace = lastItem ? virtualizer.getTotalSize() - lastItem.end :
|
|
2968
|
+
const bottomSpace = lastItem ? virtualizer.getTotalSize() - lastItem.end : virtualizer.getTotalSize();
|
|
2902
2969
|
center = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
2903
2970
|
topSpace > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
|
|
2904
2971
|
"aria-hidden": true,
|
|
@@ -3882,7 +3949,7 @@ const builtInFilterFns = {
|
|
|
3882
3949
|
* private `RangeValue` alias behind the min/max/extent value types becomes nameable only by a
|
|
3883
3950
|
* deep path the package's `exports` map hides, and an inferred registry fails declaration emit
|
|
3884
3951
|
* (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)
|
|
3952
|
+
* emit anyway. Upstream: TanStack/table#6619, sxzz/rolldown-plugin-dts#312 (fix: #310).
|
|
3886
3953
|
*/
|
|
3887
3954
|
const builtInAggregationFns = {
|
|
3888
3955
|
count: _tanstack_react_table.aggregationFn_count,
|
|
@@ -5902,6 +5969,10 @@ const NO_ROW_PINNING = {
|
|
|
5902
5969
|
top: [],
|
|
5903
5970
|
bottom: []
|
|
5904
5971
|
};
|
|
5972
|
+
/**
|
|
5973
|
+
* `enableActiveRow` without a predicate: the cursor can rest on any row.
|
|
5974
|
+
*/
|
|
5975
|
+
const everyRow = () => true;
|
|
5905
5976
|
const DEFAULT_PAGINATION = {
|
|
5906
5977
|
pageIndex: 0,
|
|
5907
5978
|
pageSize: 20
|
|
@@ -6123,9 +6194,10 @@ function useDataTable(options) {
|
|
|
6123
6194
|
renderDetailPanel,
|
|
6124
6195
|
selectAllScope,
|
|
6125
6196
|
activeRow: {
|
|
6126
|
-
enabled: enableActiveRow,
|
|
6197
|
+
enabled: enableActiveRow !== false,
|
|
6127
6198
|
id: activeRowId,
|
|
6128
|
-
set: setActiveRowId
|
|
6199
|
+
set: setActiveRowId,
|
|
6200
|
+
canActivate: typeof enableActiveRow === "function" ? enableActiveRow : everyRow
|
|
6129
6201
|
},
|
|
6130
6202
|
enableColumnOrdering,
|
|
6131
6203
|
enableColumnResizing,
|
|
@@ -7071,6 +7143,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7071
7143
|
]);
|
|
7072
7144
|
const activeRowAnnouncer = (0, react.useRef)(null);
|
|
7073
7145
|
const rowNavigationHintId = `${instanceId}-row-navigation`;
|
|
7146
|
+
const viewportFocusStop = activeRowEnabled || viewportOverflows;
|
|
7074
7147
|
const viewportDescribedBy = activeRowEnabled ? [viewportProps?.["aria-describedby"], rowNavigationHintId].filter(Boolean).join(" ") : viewportProps?.["aria-describedby"];
|
|
7075
7148
|
const announceActiveRow = useEventCallback(() => {
|
|
7076
7149
|
const target = activeRowAnnouncer.current;
|
|
@@ -7100,7 +7173,7 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7100
7173
|
]);
|
|
7101
7174
|
const handleActiveRowKeyDown = useEventCallback((event) => {
|
|
7102
7175
|
if (!activeRowEnabled || !setActiveRow) return;
|
|
7103
|
-
if (event
|
|
7176
|
+
if (!isOwnEvent(event, event.currentTarget)) return;
|
|
7104
7177
|
if (event.key === "F2") {
|
|
7105
7178
|
if (!editing || activeRowId === null) return;
|
|
7106
7179
|
const rowMode = editing.mode === "row";
|
|
@@ -7115,35 +7188,40 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7115
7188
|
return;
|
|
7116
7189
|
}
|
|
7117
7190
|
const rows = displaySnapshot.ordered;
|
|
7118
|
-
|
|
7191
|
+
const canActivate = ledger?.activeRow.canActivate;
|
|
7192
|
+
if (rows.length === 0 || !canActivate) return;
|
|
7119
7193
|
const currentIndex = activeRowId === null ? -1 : rows.findIndex((row) => row.id === activeRowId);
|
|
7120
|
-
const
|
|
7121
|
-
|
|
7122
|
-
|
|
7123
|
-
|
|
7124
|
-
|
|
7194
|
+
const moveFrom = (from, step) => {
|
|
7195
|
+
for (let index = from; index >= 0 && index < rows.length; index += step) {
|
|
7196
|
+
const row = rows[index];
|
|
7197
|
+
if (canActivate(row)) {
|
|
7198
|
+
setActiveRow(row.id);
|
|
7199
|
+
scrollRowIntoView(row.id);
|
|
7200
|
+
return;
|
|
7201
|
+
}
|
|
7125
7202
|
}
|
|
7203
|
+
if (currentIndex !== -1 && activeRowId !== null) scrollRowIntoView(activeRowId);
|
|
7126
7204
|
};
|
|
7127
7205
|
switch (event.key) {
|
|
7128
7206
|
case "ArrowDown":
|
|
7129
7207
|
event.preventDefault();
|
|
7130
|
-
|
|
7208
|
+
moveFrom(currentIndex + 1, 1);
|
|
7131
7209
|
break;
|
|
7132
7210
|
case "ArrowUp":
|
|
7133
7211
|
event.preventDefault();
|
|
7134
|
-
|
|
7212
|
+
moveFrom(currentIndex === -1 ? 0 : currentIndex - 1, currentIndex === -1 ? 1 : -1);
|
|
7135
7213
|
break;
|
|
7136
7214
|
case "Home":
|
|
7137
7215
|
event.preventDefault();
|
|
7138
|
-
|
|
7216
|
+
moveFrom(0, 1);
|
|
7139
7217
|
break;
|
|
7140
7218
|
case "End":
|
|
7141
7219
|
event.preventDefault();
|
|
7142
|
-
|
|
7220
|
+
moveFrom(rows.length - 1, -1);
|
|
7143
7221
|
break;
|
|
7144
7222
|
case "Enter": {
|
|
7145
7223
|
const row = currentIndex >= 0 ? rows[currentIndex] : null;
|
|
7146
|
-
if (row && onRowActivate) {
|
|
7224
|
+
if (row && onRowActivate && canActivate(row)) {
|
|
7147
7225
|
event.preventDefault();
|
|
7148
7226
|
onRowActivate(row, event);
|
|
7149
7227
|
}
|
|
@@ -7309,8 +7387,9 @@ function DataTableCore({ presentation, stylesProps, table }) {
|
|
|
7309
7387
|
viewportProps: mergeElementProps(viewportProps, {
|
|
7310
7388
|
style: { overscrollBehavior: "none" },
|
|
7311
7389
|
role: "rowgroup",
|
|
7390
|
+
"aria-label": viewportProps?.["aria-label"] ?? (viewportFocusStop ? labels.rows : void 0),
|
|
7312
7391
|
"aria-describedby": viewportDescribedBy,
|
|
7313
|
-
tabIndex:
|
|
7392
|
+
tabIndex: viewportFocusStop ? 0 : void 0,
|
|
7314
7393
|
...activeRowEnabled && { onKeyDown: handleActiveRowKeyDown }
|
|
7315
7394
|
}),
|
|
7316
7395
|
onScrollPositionChange: handleScrollPositionChange,
|