@viewkitjs/views 0.1.0 → 0.2.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/CHANGELOG.md +196 -1
- package/README.md +90 -41
- package/dist/atoms/Row.js +1 -1
- package/dist/atoms/RowMenu.d.ts +1 -1
- package/dist/atoms/RowMenu.js +15 -4
- package/dist/atoms/types.d.ts +4 -4
- package/dist/contract.d.ts +37 -7
- package/dist/contract.js +24 -5
- package/dist/display/format.d.ts +16 -1
- package/dist/display/format.js +10 -1
- package/dist/display/index.d.ts +1 -1
- package/dist/display/index.js +1 -1
- package/dist/display/link.js +5 -3
- package/dist/display/location.d.ts +4 -3
- package/dist/display/location.js +12 -5
- package/dist/display/options.d.ts +1 -1
- package/dist/display/percent.js +10 -3
- package/dist/display/phone.d.ts +2 -1
- package/dist/display/phone.js +8 -1
- package/dist/display/relation.js +1 -1
- package/dist/editors/ChipsEditor.js +1 -1
- package/dist/editors/LocationEditor.js +16 -17
- package/dist/editors/NameEditor.js +5 -4
- package/dist/editors/NumberEditor.js +2 -2
- package/dist/editors/RangeEditor.js +2 -2
- package/dist/editors/ValueListEditor.d.ts +2 -2
- package/dist/editors/ValueListEditor.js +8 -8
- package/dist/editors/edit-cores.d.ts +1 -1
- package/dist/fields/binding.d.ts +1 -1
- package/dist/fields/currency.d.ts +0 -10
- package/dist/fields/currency.js +0 -14
- package/dist/fields/money.d.ts +1 -0
- package/dist/fields/money.js +1 -0
- package/dist/filters/filter-model.d.ts +0 -1
- package/dist/filters/registry.d.ts +3 -36
- package/dist/filters/registry.js +0 -38
- package/dist/grid/chrome/GridAddColumn.d.ts +11 -0
- package/dist/grid/chrome/GridAddColumn.js +29 -0
- package/dist/grid/chrome/GridAggregateMenu.d.ts +31 -0
- package/dist/grid/chrome/GridAggregateMenu.js +27 -0
- package/dist/grid/chrome/GridCellEditors.d.ts +64 -0
- package/dist/grid/chrome/GridCellEditors.js +55 -0
- package/dist/grid/chrome/GridCellOutline.d.ts +70 -0
- package/dist/grid/chrome/GridCellOutline.js +21 -0
- package/dist/grid/chrome/GridChipsEditor.d.ts +28 -0
- package/dist/grid/chrome/GridChipsEditor.js +40 -0
- package/dist/grid/chrome/GridColumnColorSection.d.ts +11 -0
- package/dist/grid/chrome/GridColumnColorSection.js +40 -0
- package/dist/grid/chrome/GridColumnDateSection.d.ts +23 -0
- package/dist/grid/chrome/GridColumnDateSection.js +23 -0
- package/dist/grid/chrome/GridColumnDurationSection.d.ts +19 -0
- package/dist/grid/chrome/GridColumnDurationSection.js +24 -0
- package/dist/grid/chrome/GridColumnMenu.d.ts +101 -0
- package/dist/grid/chrome/GridColumnMenu.js +99 -0
- package/dist/grid/chrome/GridColumnNumberSection.d.ts +25 -0
- package/dist/grid/chrome/GridColumnNumberSection.js +27 -0
- package/dist/grid/chrome/GridColumnPercentSection.d.ts +15 -0
- package/dist/grid/chrome/GridColumnPercentSection.js +16 -0
- package/dist/grid/chrome/GridColumnSortSection.d.ts +18 -0
- package/dist/grid/chrome/GridColumnSortSection.js +16 -0
- package/dist/grid/chrome/GridDateEditor.d.ts +22 -0
- package/dist/grid/chrome/GridDateEditor.js +31 -0
- package/dist/grid/chrome/GridFlyout.d.ts +44 -0
- package/dist/grid/chrome/GridFlyout.js +80 -0
- package/dist/grid/chrome/GridFooter.d.ts +23 -0
- package/dist/grid/chrome/GridFooter.js +81 -0
- package/dist/grid/chrome/GridGroupMenu.d.ts +37 -0
- package/dist/grid/chrome/GridGroupMenu.js +57 -0
- package/dist/grid/chrome/GridHeader.d.ts +61 -0
- package/dist/grid/chrome/GridHeader.js +37 -0
- package/dist/grid/chrome/GridLongTextEditor.d.ts +36 -0
- package/dist/grid/chrome/GridLongTextEditor.js +127 -0
- package/dist/grid/chrome/GridMenuRow.d.ts +15 -0
- package/dist/grid/chrome/GridMenuRow.js +15 -0
- package/dist/grid/chrome/GridNameEditor.d.ts +19 -0
- package/dist/grid/chrome/GridNameEditor.js +36 -0
- package/dist/grid/chrome/GridNumberEditor.d.ts +35 -0
- package/dist/grid/chrome/GridNumberEditor.js +25 -0
- package/dist/grid/chrome/GridRangeEditor.d.ts +20 -0
- package/dist/grid/chrome/GridRangeEditor.js +25 -0
- package/dist/grid/chrome/GridRelationEditor.d.ts +21 -0
- package/dist/grid/chrome/GridRelationEditor.js +30 -0
- package/dist/grid/chrome/GridResizeHandle.d.ts +19 -0
- package/dist/grid/chrome/GridResizeHandle.js +19 -0
- package/dist/grid/chrome/GridRow.d.ts +25 -0
- package/dist/grid/chrome/GridRow.js +136 -0
- package/dist/grid/chrome/GridRowActions.d.ts +32 -0
- package/dist/grid/chrome/GridRowActions.js +25 -0
- package/dist/grid/chrome/GridRowCells.d.ts +4 -0
- package/dist/grid/chrome/GridRowCells.js +133 -0
- package/dist/grid/chrome/GridRowGlyph.d.ts +12 -0
- package/dist/grid/chrome/GridRowGlyph.js +13 -0
- package/dist/grid/chrome/GridSelectEditor.d.ts +18 -0
- package/dist/grid/chrome/GridSelectEditor.js +49 -0
- package/dist/grid/chrome/GridStructure.d.ts +48 -0
- package/dist/grid/chrome/GridStructure.js +45 -0
- package/dist/grid/chrome/GridTable.d.ts +4 -0
- package/dist/grid/chrome/GridTable.js +125 -0
- package/dist/grid/chrome/GridTableSurface.d.ts +15 -0
- package/dist/grid/chrome/GridTableSurface.js +6 -0
- package/dist/grid/chrome/GridTextEditor.d.ts +11 -0
- package/dist/grid/chrome/GridTextEditor.js +40 -0
- package/dist/grid/chrome/GridValueListEditor.d.ts +18 -0
- package/dist/grid/chrome/GridValueListEditor.js +36 -0
- package/dist/grid/chrome/StuckMarker.d.ts +16 -0
- package/dist/grid/chrome/StuckMarker.js +34 -0
- package/dist/grid/chrome/cell-clipboard.d.ts +9 -0
- package/dist/grid/chrome/cell-clipboard.js +28 -0
- package/dist/grid/chrome/cells.d.ts +21 -0
- package/dist/grid/chrome/cells.js +20 -0
- package/dist/grid/chrome/checks.d.ts +35 -0
- package/dist/grid/chrome/checks.js +22 -0
- package/dist/grid/chrome/column-glyph.d.ts +14 -0
- package/dist/grid/chrome/column-glyph.js +44 -0
- package/dist/grid/chrome/editors.d.ts +9 -0
- package/dist/grid/chrome/editors.js +10 -0
- package/dist/grid/chrome/grid-cell-classes.d.ts +59 -0
- package/dist/grid/chrome/grid-cell-classes.js +30 -0
- package/dist/grid/chrome/grid-menu-search.d.ts +7 -0
- package/dist/grid/chrome/grid-menu-search.js +7 -0
- package/dist/grid/chrome/grid-row-props.d.ts +131 -0
- package/dist/grid/chrome/grid-row-props.js +1 -0
- package/dist/grid/chrome/grid-styles.d.ts +37 -0
- package/dist/grid/chrome/grid-styles.js +8 -0
- package/dist/grid/chrome/grid-table-props.d.ts +173 -0
- package/dist/grid/chrome/grid-table-props.js +1 -0
- package/dist/grid/chrome/useGridBatchApi.d.ts +34 -0
- package/dist/grid/chrome/useGridBatchApi.js +35 -0
- package/dist/grid/chrome/useGridColumnLayout.d.ts +30 -0
- package/dist/grid/chrome/useGridColumnLayout.js +206 -0
- package/dist/grid/chrome/useGridHeaderDrag.d.ts +20 -0
- package/dist/grid/chrome/useGridHeaderDrag.js +37 -0
- package/dist/grid/chrome/useGridKeyboard.d.ts +47 -0
- package/dist/grid/chrome/useGridKeyboard.js +274 -0
- package/dist/grid/chrome/useGridPendingReconciliation.d.ts +12 -0
- package/dist/grid/chrome/useGridPendingReconciliation.js +32 -0
- package/dist/grid/chrome/useGridRailReveal.d.ts +57 -0
- package/dist/grid/chrome/useGridRailReveal.js +67 -0
- package/dist/grid/chrome/useGridRangeActions.d.ts +49 -0
- package/dist/grid/chrome/useGridRangeActions.js +188 -0
- package/dist/grid/chrome/useGridRangeGestures.d.ts +32 -0
- package/dist/grid/chrome/useGridRangeGestures.js +190 -0
- package/dist/grid/chrome/useGridRowContextMenu.d.ts +35 -0
- package/dist/grid/chrome/useGridRowContextMenu.js +127 -0
- package/dist/grid/chrome/useGridScaleStyles.d.ts +1 -0
- package/dist/grid/chrome/useGridScaleStyles.js +29 -0
- package/dist/grid/chrome/useGridScrollSync.d.ts +38 -0
- package/dist/grid/chrome/useGridScrollSync.js +176 -0
- package/dist/grid/chrome/useGridTableInteractionModel.d.ts +55 -0
- package/dist/grid/chrome/useGridTableInteractionModel.js +197 -0
- package/dist/grid/chrome/useGridTableSelection.d.ts +29 -0
- package/dist/grid/chrome/useGridTableSelection.js +55 -0
- package/dist/grid/chrome/useHeaderDragReorder.d.ts +21 -0
- package/dist/grid/chrome/useHeaderDragReorder.js +216 -0
- package/dist/grid/core/clipboard-model.d.ts +81 -0
- package/dist/grid/core/clipboard-model.js +291 -0
- package/dist/grid/core/column-values.d.ts +27 -0
- package/dist/grid/core/column-values.js +76 -0
- package/dist/grid/core/commit-model.d.ts +34 -0
- package/dist/grid/core/commit-model.js +3 -0
- package/dist/grid/core/coordinates.d.ts +48 -0
- package/dist/grid/core/coordinates.js +27 -0
- package/dist/grid/core/edit-values.d.ts +9 -0
- package/dist/grid/core/edit-values.js +1 -0
- package/dist/grid/core/editing-controller.d.ts +59 -0
- package/dist/grid/core/editing-controller.js +240 -0
- package/dist/grid/core/editing-model.d.ts +78 -0
- package/dist/grid/core/editing-model.js +136 -0
- package/dist/grid/core/grid-scale.d.ts +14 -0
- package/dist/grid/core/grid-scale.js +8 -0
- package/dist/grid/core/nav.d.ts +94 -0
- package/dist/grid/core/nav.js +92 -0
- package/dist/grid/core/pending-reconciliation.d.ts +50 -0
- package/dist/grid/core/pending-reconciliation.js +49 -0
- package/dist/grid/core/range-model.d.ts +25 -0
- package/dist/grid/core/range-model.js +59 -0
- package/dist/grid/core/spreadsheet-operations.d.ts +85 -0
- package/dist/grid/core/spreadsheet-operations.js +253 -0
- package/dist/grid/core/useGridEditing.d.ts +43 -0
- package/dist/grid/core/useGridEditing.js +90 -0
- package/dist/grid/core/useGridRange.d.ts +20 -0
- package/dist/grid/core/useGridRange.js +24 -0
- package/dist/grid/core/value-equality.d.ts +32 -0
- package/dist/grid/core/value-equality.js +34 -0
- package/dist/grid/index.d.ts +18 -0
- package/dist/grid/index.js +5 -0
- package/dist/grid/useGridTablePrefs.d.ts +50 -0
- package/dist/grid/useGridTablePrefs.js +101 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/internal/viewport.d.ts +5 -0
- package/dist/internal/viewport.js +29 -0
- package/dist/model/column-capabilities.d.ts +2 -2
- package/dist/model/column-state.d.ts +1 -1
- package/dist/model/density.js +3 -3
- package/dist/model/filter-capabilities.d.ts +1 -1
- package/dist/model/filter-capabilities.js +1 -1
- package/dist/model/index.d.ts +4 -6
- package/dist/model/index.js +0 -1
- package/dist/model/preferences.d.ts +7 -3
- package/dist/provider/ViewsProvider.d.ts +1 -1
- package/dist/provider/ViewsProvider.js +5 -1
- package/dist/provider/components.d.ts +16 -8
- package/dist/provider/context.d.ts +3 -2
- package/dist/provider/menu-groups.d.ts +8 -0
- package/dist/provider/menu-groups.js +38 -0
- package/dist/provider/ports.d.ts +22 -0
- package/dist/provider/ports.js +1 -0
- package/dist/react.d.ts +1 -1
- package/docs/contract.md +128 -56
- package/docs/getting-started.md +250 -0
- package/docs/guides/atoms.md +245 -0
- package/docs/guides/cells.md +302 -0
- package/docs/guides/columns.md +412 -0
- package/docs/guides/display.md +203 -0
- package/docs/guides/editors.md +404 -0
- package/docs/guides/ports.md +246 -0
- package/docs/guides/selection.md +270 -0
- package/docs/guides/the-grid.md +677 -0
- package/docs/guides/the-provider.md +446 -0
- package/docs/index.md +50 -0
- package/docs/install.md +9 -47
- package/docs/reference/cells.md +28 -0
- package/docs/reference/display.md +42 -0
- package/docs/reference/editors-chips.md +6 -0
- package/docs/reference/editors-date.md +6 -0
- package/docs/reference/editors-location.md +10 -0
- package/docs/reference/editors-name.md +6 -0
- package/docs/reference/editors-number.md +11 -0
- package/docs/reference/editors-open-values.md +9 -0
- package/docs/reference/editors-range.md +6 -0
- package/docs/reference/editors-relation.md +9 -0
- package/docs/reference/editors-select.md +8 -0
- package/docs/reference/editors-session.md +9 -0
- package/docs/reference/editors-value-list.md +6 -0
- package/docs/reference/editors.md +5 -0
- package/docs/reference/grid.md +39 -0
- package/docs/reference/react.md +86 -0
- package/docs/reference/selection.md +33 -0
- package/docs/reference/views.md +601 -0
- package/package.json +7 -3
- package/skills/views/SKILL.md +20 -5
- package/dist/filters/types.d.ts +0 -27
- package/dist/filters/types.js +0 -1
- package/dist/model/filter-pushdown.d.ts +0 -106
- package/dist/model/filter-pushdown.js +0 -147
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* When the checkbox rail holds its space, and how it is asked to.
|
|
4
|
+
*
|
|
5
|
+
* The rail is not free: parking it reserves `--vk-rail-w` at the table's left
|
|
6
|
+
* edge and stops the columns there. So it parks only when it is earning that,
|
|
7
|
+
* and otherwise travels off with its row so the table can run clean to the edge.
|
|
8
|
+
*
|
|
9
|
+
* Two sources, one signal — `data-rail` on the table root, which every rail slot
|
|
10
|
+
* reads through `group-data-[rail=on]/gridtable`:
|
|
11
|
+
*
|
|
12
|
+
* · EARNED — a selection is running, so every checkbox has to stay reachable
|
|
13
|
+
* whatever the pointer is doing.
|
|
14
|
+
* · HOVERED — the pointer is in the strip the rail parks in, AND the rail is
|
|
15
|
+
* actually parked there. Both halves matter: unscrolled, that strip is empty
|
|
16
|
+
* space with the checkboxes still out at the page gutter, so reacting to it
|
|
17
|
+
* would be reacting to a hover over nothing.
|
|
18
|
+
*
|
|
19
|
+
* A FROZEN BLOCK IS NOT ONE OF THEM. It parks at `--vk-rail-w` regardless,
|
|
20
|
+
* which keeps the checkbox's slot open ahead of it — but an open slot is not a
|
|
21
|
+
* reason to fill it. Treating "this table has a pinned column" as earned meant
|
|
22
|
+
* every such table showed a full column of checkboxes at rest, permanently.
|
|
23
|
+
*
|
|
24
|
+
* NONE of this touches the per-row reveal: pointing at a row always shows THAT
|
|
25
|
+
* row's checkbox, rail or no rail. This is only the "show me all of them" state.
|
|
26
|
+
*
|
|
27
|
+
* ONE attribute rather than React state, and that is the point. The hover half
|
|
28
|
+
* flips on every pass of the pointer, and this grid has no virtualisation — a
|
|
29
|
+
* re-render is every row of a possibly thousand-row table. Flipping an attribute
|
|
30
|
+
* re-renders nothing and lets CSS fade the lane in.
|
|
31
|
+
*/
|
|
32
|
+
export declare function useGridRailReveal({ rootRef, earned, }: {
|
|
33
|
+
rootRef: RefObject<HTMLElement | null>;
|
|
34
|
+
/** The rail must show regardless of the pointer — a live selection. */
|
|
35
|
+
earned: boolean;
|
|
36
|
+
}): {
|
|
37
|
+
probeRef: RefObject<HTMLSpanElement | null>;
|
|
38
|
+
rootProps: {
|
|
39
|
+
onPointerEnter: () => void;
|
|
40
|
+
onPointerMove: (event: React.PointerEvent) => void;
|
|
41
|
+
onWheel: () => void;
|
|
42
|
+
onPointerLeave: () => void;
|
|
43
|
+
} | {
|
|
44
|
+
onPointerEnter?: undefined;
|
|
45
|
+
onPointerMove?: undefined;
|
|
46
|
+
onWheel?: undefined;
|
|
47
|
+
onPointerLeave?: undefined;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The strip the rail parks in, laid out but never painted or hit — its only job
|
|
52
|
+
* is to be measured, so the boundary follows the CSS instead of being
|
|
53
|
+
* duplicated in JS.
|
|
54
|
+
*/
|
|
55
|
+
export declare function GridRailProbe({ probeRef }: {
|
|
56
|
+
probeRef: RefObject<HTMLSpanElement | null>;
|
|
57
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
4
|
+
import { useHasHover } from "../../internal/viewport.js";
|
|
5
|
+
export function useGridRailReveal({ rootRef, earned, }) {
|
|
6
|
+
const hoverable = useHasHover();
|
|
7
|
+
const earnedRef = useRef(earned);
|
|
8
|
+
const onRef = useRef(false);
|
|
9
|
+
const edgeRef = useRef(0);
|
|
10
|
+
const probeRef = useRef(null);
|
|
11
|
+
const setRail = useCallback((on) => {
|
|
12
|
+
if (onRef.current === on)
|
|
13
|
+
return;
|
|
14
|
+
onRef.current = on;
|
|
15
|
+
rootRef.current?.setAttribute("data-rail", on ? "on" : "off");
|
|
16
|
+
}, [rootRef]);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
earnedRef.current = earned;
|
|
19
|
+
if (earned)
|
|
20
|
+
setRail(true);
|
|
21
|
+
else
|
|
22
|
+
setRail(false);
|
|
23
|
+
}, [earned, setRail]);
|
|
24
|
+
const measure = useCallback(() => {
|
|
25
|
+
const probe = probeRef.current;
|
|
26
|
+
if (probe)
|
|
27
|
+
edgeRef.current = probe.getBoundingClientRect().right;
|
|
28
|
+
}, []);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const probe = probeRef.current;
|
|
31
|
+
if (!probe)
|
|
32
|
+
return;
|
|
33
|
+
measure();
|
|
34
|
+
const observer = new ResizeObserver(measure);
|
|
35
|
+
observer.observe(probe);
|
|
36
|
+
window.addEventListener("resize", measure);
|
|
37
|
+
return () => {
|
|
38
|
+
observer.disconnect();
|
|
39
|
+
window.removeEventListener("resize", measure);
|
|
40
|
+
};
|
|
41
|
+
}, [measure]);
|
|
42
|
+
const pointerXRef = useRef(Number.POSITIVE_INFINITY);
|
|
43
|
+
const evaluate = useCallback(() => {
|
|
44
|
+
if (earnedRef.current)
|
|
45
|
+
return setRail(true);
|
|
46
|
+
const parked = rootRef.current?.style.getPropertyValue("--vk-parked") === "1";
|
|
47
|
+
setRail(parked && pointerXRef.current <= edgeRef.current);
|
|
48
|
+
}, [rootRef, setRail]);
|
|
49
|
+
const rootProps = hoverable
|
|
50
|
+
? {
|
|
51
|
+
onPointerEnter: measure,
|
|
52
|
+
onPointerMove: (event) => {
|
|
53
|
+
pointerXRef.current = event.clientX;
|
|
54
|
+
evaluate();
|
|
55
|
+
},
|
|
56
|
+
onWheel: evaluate,
|
|
57
|
+
onPointerLeave: () => {
|
|
58
|
+
pointerXRef.current = Number.POSITIVE_INFINITY;
|
|
59
|
+
evaluate();
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
: {};
|
|
63
|
+
return { probeRef, rootProps };
|
|
64
|
+
}
|
|
65
|
+
export function GridRailProbe({ probeRef }) {
|
|
66
|
+
return (_jsx("span", { "aria-hidden": true, ref: probeRef, className: "pointer-events-none absolute top-0 h-0 w-(--vk-rail-w)", style: { left: "calc(-1 * var(--vk-gutter,0px))" } }));
|
|
67
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { GridCellPos } from "../core/coordinates.js";
|
|
2
|
+
import type { GridEditCell } from "../core/editing-model.js";
|
|
3
|
+
import { type GridCellRange } from "../core/range-model.js";
|
|
4
|
+
import { type GridSpreadsheetModel } from "../core/spreadsheet-operations.js";
|
|
5
|
+
import type { ListColumn } from "../../model/column-schema.js";
|
|
6
|
+
import { type GridPasteSource } from "./cell-clipboard.js";
|
|
7
|
+
export type GridRangeVerbs = {
|
|
8
|
+
copyRange: () => void;
|
|
9
|
+
cutRange: () => void;
|
|
10
|
+
clearRange: () => void;
|
|
11
|
+
pasteMatrix: (matrix: GridPasteSource[][], anchor: {
|
|
12
|
+
rowIdx: number;
|
|
13
|
+
colIdx: number;
|
|
14
|
+
}) => void;
|
|
15
|
+
pasteAtCell: (rowId: string, columnId: string) => void;
|
|
16
|
+
pasteAtRangeOrigin: () => void;
|
|
17
|
+
activeRangeIsMulti: () => boolean;
|
|
18
|
+
activeRangeHasClearable: () => boolean;
|
|
19
|
+
cellInActiveRange: (rowId: string, columnId: string) => boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare function useGridRangeActions<Row>({ ranges, focusedCell, editingCell, editingEnabled, fillTargetRow, visibleRowIds, visibleColumns, spreadsheetModel, commitBatch, focusCell, rangeSetRect, rangeExtendTo, }: {
|
|
22
|
+
ranges: GridCellRange[];
|
|
23
|
+
focusedCell: GridCellPos | null;
|
|
24
|
+
editingCell: GridCellPos | null;
|
|
25
|
+
editingEnabled: boolean;
|
|
26
|
+
fillTargetRow: string | null;
|
|
27
|
+
visibleRowIds: string[];
|
|
28
|
+
visibleColumns: ListColumn<Row>[];
|
|
29
|
+
spreadsheetModel: GridSpreadsheetModel<Row>;
|
|
30
|
+
commitBatch: (edits: (GridEditCell<Row> & {
|
|
31
|
+
row: Row;
|
|
32
|
+
})[]) => void;
|
|
33
|
+
focusCell: (rowId: string, columnId: string) => void;
|
|
34
|
+
rangeSetRect: (anchor: GridCellPos, head: GridCellPos) => void;
|
|
35
|
+
rangeExtendTo: (pos: GridCellPos, fallbackAnchor?: GridCellPos) => void;
|
|
36
|
+
}): {
|
|
37
|
+
visibleColIds: string[];
|
|
38
|
+
rowSpansMap: Map<string, import("../core/range-model.js").GridRowRangeSpan[]>;
|
|
39
|
+
selectValuesByColumn: Record<string, string[]>;
|
|
40
|
+
finishFill: (targetRowId: string) => void;
|
|
41
|
+
onRangeCopy: () => void | undefined;
|
|
42
|
+
onRangeCut: () => void | undefined;
|
|
43
|
+
onRangeClear: () => void | undefined;
|
|
44
|
+
onRangePaste: () => void | undefined;
|
|
45
|
+
onPasteAtCell: (rowId: string, columnId: string) => void | undefined;
|
|
46
|
+
inActiveRange: (rowId: string, columnId: string) => boolean;
|
|
47
|
+
rangeCanClear: () => boolean;
|
|
48
|
+
rangeVerbsRef: import("react").RefObject<GridRangeVerbs | null>;
|
|
49
|
+
};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
3
|
+
import { useViews } from "../../provider/context.js";
|
|
4
|
+
import { gridRectContains, gridRectIsMulti } from "../core/coordinates.js";
|
|
5
|
+
import { computeRowRangeSpans } from "../core/range-model.js";
|
|
6
|
+
import { resolveActiveRangeRect } from "../core/range-model.js";
|
|
7
|
+
import { deriveGridSelectValues } from "../core/column-values.js";
|
|
8
|
+
import { buildGridCopyMatrix, extendGridFillPreview, gridRectHasClearable, planGridClear, planGridFill, planGridPaste, } from "../core/spreadsheet-operations.js";
|
|
9
|
+
import { copyCells, getGridClipboard, parseTsvText } from "./cell-clipboard.js";
|
|
10
|
+
export function useGridRangeActions({ ranges, focusedCell, editingCell, editingEnabled, fillTargetRow, visibleRowIds, visibleColumns, spreadsheetModel, commitBatch, focusCell, rangeSetRect, rangeExtendTo, }) {
|
|
11
|
+
const { ports, messages } = useViews();
|
|
12
|
+
const visibleColIds = useMemo(() => visibleColumns.map((col) => col.id), [visibleColumns]);
|
|
13
|
+
const spanRanges = useMemo(() => extendGridFillPreview(ranges, fillTargetRow, visibleRowIds, visibleColIds), [fillTargetRow, ranges, visibleColIds, visibleRowIds]);
|
|
14
|
+
const rowSpansMap = useMemo(() => computeRowRangeSpans(spanRanges, visibleRowIds, visibleColIds), [spanRanges, visibleColIds, visibleRowIds]);
|
|
15
|
+
const selectValuesByColumn = useMemo(() => deriveGridSelectValues(visibleColumns, spreadsheetModel.rows), [spreadsheetModel.rows, visibleColumns]);
|
|
16
|
+
const sayRefusals = useCallback((verb, plan) => {
|
|
17
|
+
if (plan.targetCount === 1 && plan.refusals.length === 1) {
|
|
18
|
+
ports.toast.error(plan.refusals[0].reason);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
for (const { reason, count } of plan.refusals) {
|
|
22
|
+
ports.toast.error(messages({ key: verb === "paste" ? "views.grid.paste-skipped" : "views.grid.fill-skipped", values: { count, reason } }));
|
|
23
|
+
}
|
|
24
|
+
}, [messages, ports]);
|
|
25
|
+
const finishFill = useCallback((targetRowId) => {
|
|
26
|
+
if (!editingEnabled)
|
|
27
|
+
return;
|
|
28
|
+
const plan = planGridFill(spreadsheetModel, ranges, focusedCell, targetRowId);
|
|
29
|
+
if (plan.edits.length > 0)
|
|
30
|
+
commitBatch(plan.edits);
|
|
31
|
+
if (plan.selectionHead)
|
|
32
|
+
rangeExtendTo(plan.selectionHead);
|
|
33
|
+
sayRefusals("fill", plan);
|
|
34
|
+
}, [commitBatch, editingEnabled, focusedCell, rangeExtendTo, ranges, sayRefusals, spreadsheetModel]);
|
|
35
|
+
const rangeVerbs = useMemo(() => {
|
|
36
|
+
const rectOfActiveRange = () => resolveActiveRangeRect(ranges, focusedCell, visibleRowIds, visibleColIds);
|
|
37
|
+
const activeRangeIsMulti = () => {
|
|
38
|
+
const rect = rectOfActiveRange();
|
|
39
|
+
return !!rect && gridRectIsMulti(rect);
|
|
40
|
+
};
|
|
41
|
+
const cellInActiveRange = (rowId, columnId) => {
|
|
42
|
+
if (!activeRangeIsMulti())
|
|
43
|
+
return false;
|
|
44
|
+
const rect = rectOfActiveRange();
|
|
45
|
+
return gridRectContains(rect, visibleRowIds.indexOf(rowId), visibleColIds.indexOf(columnId));
|
|
46
|
+
};
|
|
47
|
+
const copyRange = () => {
|
|
48
|
+
const rect = rectOfActiveRange();
|
|
49
|
+
if (!rect)
|
|
50
|
+
return;
|
|
51
|
+
const matrix = buildGridCopyMatrix(spreadsheetModel, rect);
|
|
52
|
+
if (matrix.length > 0)
|
|
53
|
+
void copyCells(ports.clipboard.writeText, matrix);
|
|
54
|
+
};
|
|
55
|
+
const activeRangeHasClearable = () => {
|
|
56
|
+
if (!editingEnabled)
|
|
57
|
+
return false;
|
|
58
|
+
const rect = rectOfActiveRange();
|
|
59
|
+
return !!rect && gridRectHasClearable(visibleColumns, rect);
|
|
60
|
+
};
|
|
61
|
+
const clearRange = () => {
|
|
62
|
+
if (!editingEnabled)
|
|
63
|
+
return;
|
|
64
|
+
const rect = rectOfActiveRange();
|
|
65
|
+
if (!rect)
|
|
66
|
+
return;
|
|
67
|
+
if (!activeRangeHasClearable()) {
|
|
68
|
+
ports.toast.error(messages({ key: "views.grid.clear-none" }));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const edits = planGridClear(spreadsheetModel, rect);
|
|
72
|
+
if (edits.length > 0)
|
|
73
|
+
commitBatch(edits);
|
|
74
|
+
};
|
|
75
|
+
const cutRange = () => {
|
|
76
|
+
copyRange();
|
|
77
|
+
if (activeRangeHasClearable())
|
|
78
|
+
clearRange();
|
|
79
|
+
};
|
|
80
|
+
const pasteMatrix = (matrix, anchor) => {
|
|
81
|
+
if (!editingEnabled)
|
|
82
|
+
return;
|
|
83
|
+
const plan = planGridPaste(spreadsheetModel, matrix, anchor, rectOfActiveRange(), selectValuesByColumn);
|
|
84
|
+
if (plan.edits.length > 0) {
|
|
85
|
+
commitBatch(plan.edits);
|
|
86
|
+
if (plan.selection) {
|
|
87
|
+
focusCell(plan.selection.anchor.rowId, plan.selection.anchor.columnId);
|
|
88
|
+
rangeSetRect(plan.selection.anchor, plan.selection.head);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
sayRefusals("paste", plan);
|
|
92
|
+
};
|
|
93
|
+
const pasteAtCell = (rowId, columnId) => {
|
|
94
|
+
const clipboard = getGridClipboard();
|
|
95
|
+
if (!clipboard)
|
|
96
|
+
return;
|
|
97
|
+
const rowIdx = visibleRowIds.indexOf(rowId);
|
|
98
|
+
const colIdx = visibleColIds.indexOf(columnId);
|
|
99
|
+
if (rowIdx < 0 || colIdx < 0)
|
|
100
|
+
return;
|
|
101
|
+
pasteMatrix(clipboard.matrix ?? [[clipboard]], { rowIdx, colIdx });
|
|
102
|
+
};
|
|
103
|
+
const pasteAtRangeOrigin = () => {
|
|
104
|
+
const rect = rectOfActiveRange();
|
|
105
|
+
if (rect)
|
|
106
|
+
pasteAtCell(visibleRowIds[rect.r1], visibleColIds[rect.c1]);
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
copyRange,
|
|
110
|
+
cutRange,
|
|
111
|
+
clearRange,
|
|
112
|
+
pasteMatrix,
|
|
113
|
+
pasteAtCell,
|
|
114
|
+
pasteAtRangeOrigin,
|
|
115
|
+
activeRangeIsMulti,
|
|
116
|
+
activeRangeHasClearable,
|
|
117
|
+
cellInActiveRange,
|
|
118
|
+
};
|
|
119
|
+
}, [
|
|
120
|
+
commitBatch,
|
|
121
|
+
editingEnabled,
|
|
122
|
+
focusCell,
|
|
123
|
+
focusedCell,
|
|
124
|
+
messages,
|
|
125
|
+
ports,
|
|
126
|
+
rangeSetRect,
|
|
127
|
+
ranges,
|
|
128
|
+
sayRefusals,
|
|
129
|
+
selectValuesByColumn,
|
|
130
|
+
spreadsheetModel,
|
|
131
|
+
visibleColIds,
|
|
132
|
+
visibleColumns,
|
|
133
|
+
visibleRowIds,
|
|
134
|
+
]);
|
|
135
|
+
const rangeVerbsRef = useRef(null);
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
rangeVerbsRef.current = rangeVerbs;
|
|
138
|
+
}, [rangeVerbs]);
|
|
139
|
+
const onRangeCopy = useCallback(() => rangeVerbsRef.current?.copyRange(), []);
|
|
140
|
+
const onRangeCut = useCallback(() => rangeVerbsRef.current?.cutRange(), []);
|
|
141
|
+
const onRangeClear = useCallback(() => rangeVerbsRef.current?.clearRange(), []);
|
|
142
|
+
const onRangePaste = useCallback(() => rangeVerbsRef.current?.pasteAtRangeOrigin(), []);
|
|
143
|
+
const onPasteAtCell = useCallback((rowId, columnId) => rangeVerbsRef.current?.pasteAtCell(rowId, columnId), []);
|
|
144
|
+
const inActiveRange = useCallback((rowId, columnId) => rangeVerbsRef.current?.cellInActiveRange(rowId, columnId) ?? false, []);
|
|
145
|
+
const rangeCanClear = useCallback(() => rangeVerbsRef.current?.activeRangeHasClearable() ?? false, []);
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (!focusedCell || editingCell || !editingEnabled)
|
|
148
|
+
return;
|
|
149
|
+
const onPaste = (event) => {
|
|
150
|
+
const target = event.target;
|
|
151
|
+
if (target?.closest?.('input, textarea, select, [contenteditable="true"], [role="menu"]')) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const text = event.clipboardData?.getData("text/plain") ?? "";
|
|
155
|
+
const clipboard = getGridClipboard();
|
|
156
|
+
const internal = clipboard && (clipboard.text === text || text === "") ? clipboard : null;
|
|
157
|
+
if (!internal && text === "")
|
|
158
|
+
return;
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
const matrix = internal
|
|
161
|
+
? (internal.matrix ?? [[internal]])
|
|
162
|
+
: parseTsvText(text);
|
|
163
|
+
if (matrix.length === 0)
|
|
164
|
+
return;
|
|
165
|
+
const rowIdx = visibleRowIds.indexOf(focusedCell.rowId);
|
|
166
|
+
const colIdx = visibleColIds.indexOf(focusedCell.columnId);
|
|
167
|
+
if (rowIdx < 0 || colIdx < 0)
|
|
168
|
+
return;
|
|
169
|
+
rangeVerbsRef.current?.pasteMatrix(matrix, { rowIdx, colIdx });
|
|
170
|
+
};
|
|
171
|
+
window.addEventListener("paste", onPaste);
|
|
172
|
+
return () => window.removeEventListener("paste", onPaste);
|
|
173
|
+
}, [editingCell, editingEnabled, focusedCell, visibleColIds, visibleRowIds]);
|
|
174
|
+
return {
|
|
175
|
+
visibleColIds,
|
|
176
|
+
rowSpansMap,
|
|
177
|
+
selectValuesByColumn,
|
|
178
|
+
finishFill,
|
|
179
|
+
onRangeCopy,
|
|
180
|
+
onRangeCut,
|
|
181
|
+
onRangeClear,
|
|
182
|
+
onRangePaste,
|
|
183
|
+
onPasteAtCell,
|
|
184
|
+
inActiveRange,
|
|
185
|
+
rangeCanClear,
|
|
186
|
+
rangeVerbsRef,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import type { GridCellPos } from "../core/coordinates.js";
|
|
3
|
+
/**
|
|
4
|
+
* Whether a pointer event on a scrolling element landed on one of its
|
|
5
|
+
* scrollbars rather than its content. A scrollbar is drawn inside the border
|
|
6
|
+
* box but outside the client box, so a pointer past `clientWidth` /
|
|
7
|
+
* `clientHeight` (measured from the padding edge) is on the bar.
|
|
8
|
+
*/
|
|
9
|
+
export declare function onScrollbar(el: HTMLElement, event: {
|
|
10
|
+
clientX: number;
|
|
11
|
+
clientY: number;
|
|
12
|
+
}): boolean;
|
|
13
|
+
export declare function useGridRangeGestures({ rootRef, focusedCell, editingCell, editingEnabled, selecting, focusCell, clearFocus, rangeBeginDrag, rangeExtendTo, rangeAddCell, finishFillRef, }: {
|
|
14
|
+
rootRef: RefObject<HTMLDivElement | null>;
|
|
15
|
+
focusedCell: GridCellPos | null;
|
|
16
|
+
editingCell: GridCellPos | null;
|
|
17
|
+
editingEnabled: boolean;
|
|
18
|
+
selecting: boolean;
|
|
19
|
+
focusCell: (rowId: string, columnId: string) => void;
|
|
20
|
+
clearFocus: () => void;
|
|
21
|
+
rangeBeginDrag: (pos: GridCellPos, additive: boolean) => void;
|
|
22
|
+
rangeExtendTo: (pos: GridCellPos, fallbackAnchor?: GridCellPos) => void;
|
|
23
|
+
rangeAddCell: (pos: GridCellPos) => void;
|
|
24
|
+
finishFillRef: RefObject<(targetRowId: string) => void>;
|
|
25
|
+
}): {
|
|
26
|
+
fillTargetRow: string | null;
|
|
27
|
+
onExtendCell: (rowId: string, columnId: string) => void;
|
|
28
|
+
onAddCell: (rowId: string, columnId: string) => void;
|
|
29
|
+
handleRootPointerDown: (event: React.PointerEvent) => void;
|
|
30
|
+
handleRootPointerDownCapture: (event: React.PointerEvent) => void;
|
|
31
|
+
handleRootClickCapture: (event: React.MouseEvent) => void;
|
|
32
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { ROW_INTERACTIVE_SELECTOR } from "../../selection/row-click.js";
|
|
4
|
+
const MOUSE_DRAG_SELECT = false;
|
|
5
|
+
function setBodySelectionDisabled(disabled) {
|
|
6
|
+
document.body.style.userSelect = disabled ? "none" : "";
|
|
7
|
+
}
|
|
8
|
+
export function onScrollbar(el, event) {
|
|
9
|
+
if (!el.clientWidth || !el.clientHeight)
|
|
10
|
+
return false;
|
|
11
|
+
const rect = el.getBoundingClientRect();
|
|
12
|
+
const x = event.clientX - rect.left - el.clientLeft;
|
|
13
|
+
const y = event.clientY - rect.top - el.clientTop;
|
|
14
|
+
return x >= el.clientWidth || y >= el.clientHeight;
|
|
15
|
+
}
|
|
16
|
+
export function useGridRangeGestures({ rootRef, focusedCell, editingCell, editingEnabled, selecting, focusCell, clearFocus, rangeBeginDrag, rangeExtendTo, rangeAddCell, finishFillRef, }) {
|
|
17
|
+
const focusedRef = useRef(focusedCell);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
focusedRef.current = focusedCell;
|
|
20
|
+
}, [focusedCell]);
|
|
21
|
+
const onExtendCell = useCallback((rowId, columnId) => {
|
|
22
|
+
const pos = { rowId, columnId };
|
|
23
|
+
rangeExtendTo(pos, focusedRef.current ?? pos);
|
|
24
|
+
if (!focusedRef.current)
|
|
25
|
+
focusCell(rowId, columnId);
|
|
26
|
+
}, [focusCell, rangeExtendTo]);
|
|
27
|
+
const onAddCell = useCallback((rowId, columnId) => {
|
|
28
|
+
rangeAddCell({ rowId, columnId });
|
|
29
|
+
focusCell(rowId, columnId);
|
|
30
|
+
}, [focusCell, rangeAddCell]);
|
|
31
|
+
const cellDragRef = useRef(null);
|
|
32
|
+
const didCellDragRef = useRef(false);
|
|
33
|
+
const fillDragRef = useRef(false);
|
|
34
|
+
const [fillTargetRow, setFillTargetRow] = useState(null);
|
|
35
|
+
const fillTargetRef = useRef(null);
|
|
36
|
+
const handleRootPointerDown = (event) => {
|
|
37
|
+
if (event.button !== 0 || event.pointerType !== "mouse")
|
|
38
|
+
return;
|
|
39
|
+
if (selecting || editingCell)
|
|
40
|
+
return;
|
|
41
|
+
const target = event.target;
|
|
42
|
+
if (editingEnabled && target.closest("[data-fill-dot]")) {
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
fillDragRef.current = true;
|
|
45
|
+
setBodySelectionDisabled(true);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (!MOUSE_DRAG_SELECT)
|
|
49
|
+
return;
|
|
50
|
+
if (target.closest(ROW_INTERACTIVE_SELECTOR) || target.closest("[data-action-menu]"))
|
|
51
|
+
return;
|
|
52
|
+
const cell = target.closest("[data-col-id]");
|
|
53
|
+
const row = target.closest("[data-row-id]");
|
|
54
|
+
if (!cell || !row)
|
|
55
|
+
return;
|
|
56
|
+
cellDragRef.current = {
|
|
57
|
+
startX: event.clientX,
|
|
58
|
+
startY: event.clientY,
|
|
59
|
+
rowId: row.getAttribute("data-row-id"),
|
|
60
|
+
columnId: cell.getAttribute("data-col-id"),
|
|
61
|
+
additive: event.metaKey || event.ctrlKey,
|
|
62
|
+
extend: event.shiftKey,
|
|
63
|
+
active: false,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const handleRootClickCapture = (event) => {
|
|
67
|
+
if (!didCellDragRef.current)
|
|
68
|
+
return;
|
|
69
|
+
didCellDragRef.current = false;
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
event.stopPropagation();
|
|
72
|
+
};
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
const onMove = (event) => {
|
|
75
|
+
if (fillDragRef.current) {
|
|
76
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
77
|
+
const row = element?.closest?.("[data-row-id]");
|
|
78
|
+
if (row && rootRef.current?.contains(row)) {
|
|
79
|
+
const rowId = row.getAttribute("data-row-id");
|
|
80
|
+
if (rowId !== fillTargetRef.current) {
|
|
81
|
+
fillTargetRef.current = rowId;
|
|
82
|
+
setFillTargetRow(rowId);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const drag = cellDragRef.current;
|
|
88
|
+
if (!drag)
|
|
89
|
+
return;
|
|
90
|
+
if (!drag.active) {
|
|
91
|
+
if (Math.abs(event.clientX - drag.startX) < 4 &&
|
|
92
|
+
Math.abs(event.clientY - drag.startY) < 4) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
drag.active = true;
|
|
96
|
+
setBodySelectionDisabled(true);
|
|
97
|
+
const start = { rowId: drag.rowId, columnId: drag.columnId };
|
|
98
|
+
if (drag.extend) {
|
|
99
|
+
rangeExtendTo(start, focusedRef.current ?? start);
|
|
100
|
+
if (!focusedRef.current)
|
|
101
|
+
focusCell(start.rowId, start.columnId);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
rangeBeginDrag(start, drag.additive);
|
|
105
|
+
focusCell(start.rowId, start.columnId);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
109
|
+
const cell = element?.closest?.("[data-col-id]");
|
|
110
|
+
const row = element?.closest?.("[data-row-id]");
|
|
111
|
+
if (cell && row && rootRef.current?.contains(row)) {
|
|
112
|
+
rangeExtendTo({
|
|
113
|
+
rowId: row.getAttribute("data-row-id"),
|
|
114
|
+
columnId: cell.getAttribute("data-col-id"),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const onUp = () => {
|
|
119
|
+
if (fillDragRef.current) {
|
|
120
|
+
fillDragRef.current = false;
|
|
121
|
+
setBodySelectionDisabled(false);
|
|
122
|
+
const target = fillTargetRef.current;
|
|
123
|
+
fillTargetRef.current = null;
|
|
124
|
+
setFillTargetRow(null);
|
|
125
|
+
if (target) {
|
|
126
|
+
didCellDragRef.current = true;
|
|
127
|
+
finishFillRef.current(target);
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const drag = cellDragRef.current;
|
|
132
|
+
cellDragRef.current = null;
|
|
133
|
+
if (drag?.active) {
|
|
134
|
+
didCellDragRef.current = true;
|
|
135
|
+
setBodySelectionDisabled(false);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
window.addEventListener("pointermove", onMove);
|
|
139
|
+
window.addEventListener("pointerup", onUp);
|
|
140
|
+
return () => {
|
|
141
|
+
window.removeEventListener("pointermove", onMove);
|
|
142
|
+
window.removeEventListener("pointerup", onUp);
|
|
143
|
+
};
|
|
144
|
+
}, [finishFillRef, focusCell, rangeBeginDrag, rangeExtendTo, rootRef]);
|
|
145
|
+
const editingRef = useRef(editingCell);
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
editingRef.current = editingCell;
|
|
148
|
+
}, [editingCell]);
|
|
149
|
+
const treePressRef = useRef(null);
|
|
150
|
+
const handleRootPointerDownCapture = (event) => {
|
|
151
|
+
treePressRef.current = event.nativeEvent;
|
|
152
|
+
};
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (!focusedCell)
|
|
155
|
+
return;
|
|
156
|
+
const onPointerDown = (event) => {
|
|
157
|
+
const inTree = treePressRef.current === event;
|
|
158
|
+
treePressRef.current = null;
|
|
159
|
+
const target = event.target;
|
|
160
|
+
if (!target)
|
|
161
|
+
return;
|
|
162
|
+
if (inTree && !rootRef.current?.contains(target))
|
|
163
|
+
return;
|
|
164
|
+
if (rootRef.current?.contains(target)) {
|
|
165
|
+
if (target.closest?.("[data-col-id]"))
|
|
166
|
+
return;
|
|
167
|
+
if (target.dataset?.gridScroller != null && onScrollbar(target, event))
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (editingRef.current) {
|
|
171
|
+
window.setTimeout(() => {
|
|
172
|
+
if (!editingRef.current)
|
|
173
|
+
clearFocus();
|
|
174
|
+
}, 0);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
clearFocus();
|
|
178
|
+
};
|
|
179
|
+
window.addEventListener("pointerdown", onPointerDown);
|
|
180
|
+
return () => window.removeEventListener("pointerdown", onPointerDown);
|
|
181
|
+
}, [clearFocus, focusedCell, rootRef]);
|
|
182
|
+
return {
|
|
183
|
+
fillTargetRow,
|
|
184
|
+
onExtendCell,
|
|
185
|
+
onAddCell,
|
|
186
|
+
handleRootPointerDown,
|
|
187
|
+
handleRootPointerDownCapture,
|
|
188
|
+
handleRootClickCapture,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ViewsRowMenuItem } from "../../atoms/types.js";
|
|
2
|
+
import type { ListColumn } from "../../model/column-schema.js";
|
|
3
|
+
import type { GridRowRangeSpan } from "../core/useGridRange.js";
|
|
4
|
+
export declare function useGridRowContextMenu<Row>({ row, id, rowKey, columns, selecting, selectable, selected, toggle, editingEnabled, pendingByCol, selectValues, rowRange, contextMenu, inActiveRange, rangeCanClear, onRangeCopy, onRangeCut, onRangePaste, onRangeClear, onPasteAtCell, onCommitCell, onFocusCell, }: {
|
|
5
|
+
row: Row;
|
|
6
|
+
/** The DATA id — what a commit and the selection toggle address. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** This RENDERED row's identity — what a position (range, focus, paste
|
|
9
|
+
* target) is in terms of. See `GridCellPos`. */
|
|
10
|
+
rowKey: string;
|
|
11
|
+
columns: ListColumn<Row>[];
|
|
12
|
+
selecting: boolean;
|
|
13
|
+
selectable: boolean;
|
|
14
|
+
selected: boolean;
|
|
15
|
+
toggle: (id: string, next?: boolean) => void;
|
|
16
|
+
editingEnabled: boolean;
|
|
17
|
+
pendingByCol?: Record<string, unknown>;
|
|
18
|
+
selectValues?: Record<string, string[]>;
|
|
19
|
+
rowRange?: GridRowRangeSpan[];
|
|
20
|
+
contextMenu?: (row: Row) => ViewsRowMenuItem[];
|
|
21
|
+
inActiveRange: (rowId: string, columnId: string) => boolean;
|
|
22
|
+
rangeCanClear: () => boolean;
|
|
23
|
+
onRangeCopy: () => void;
|
|
24
|
+
onRangeCut: () => void;
|
|
25
|
+
onRangePaste: () => void;
|
|
26
|
+
onRangeClear: () => void;
|
|
27
|
+
onPasteAtCell: (rowId: string, columnId: string) => void;
|
|
28
|
+
onCommitCell: (row: Row, rowId: string, columnId: string, previous: unknown, next: unknown, options?: {
|
|
29
|
+
overlay?: boolean;
|
|
30
|
+
}) => void;
|
|
31
|
+
onFocusCell: (rowId: string, columnId: string) => void;
|
|
32
|
+
}): {
|
|
33
|
+
contextItems: ViewsRowMenuItem[];
|
|
34
|
+
handleContextMenu: (event: React.MouseEvent<HTMLElement>) => void;
|
|
35
|
+
};
|