@viewkitjs/views 0.3.0 → 0.5.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 +641 -0
- package/README.md +3 -3
- package/dist/atoms/CommandMenu.d.ts +1 -1
- package/dist/atoms/CommandMenu.js +7 -3
- package/dist/atoms/DrillRows.d.ts +3 -0
- package/dist/atoms/DrillRows.js +25 -0
- package/dist/atoms/PanelRows.d.ts +5 -0
- package/dist/atoms/PanelRows.js +40 -0
- package/dist/atoms/PanelSearch.d.ts +2 -0
- package/dist/atoms/PanelSearch.js +21 -0
- package/dist/atoms/RelationRoles.d.ts +2 -0
- package/dist/atoms/RelationRoles.js +6 -0
- package/dist/atoms/Row.js +2 -1
- package/dist/atoms/RowMenu.js +2 -1
- package/dist/atoms/SelectionSheet.d.ts +3 -0
- package/dist/atoms/SelectionSheet.js +30 -0
- package/dist/atoms/StatusMarker.js +3 -1
- package/dist/atoms/Tag.js +2 -1
- package/dist/atoms/defaults.js +14 -0
- package/dist/atoms/types.d.ts +146 -8
- package/dist/cells/cell-values.js +4 -2
- package/dist/cells/relation-wrap.js +3 -1
- package/dist/contract.d.ts +212 -17
- package/dist/contract.js +208 -6
- package/dist/display/boolean.js +3 -1
- package/dist/display/date.d.ts +1 -1
- package/dist/display/date.js +4 -2
- package/dist/display/format.js +20 -4
- package/dist/display/link.js +4 -3
- package/dist/display/multi-value.js +2 -1
- package/dist/display/percent.js +2 -1
- package/dist/display/phone.js +2 -1
- package/dist/display/range.js +3 -13
- package/dist/display/relation.js +23 -8
- package/dist/display/rich-text.js +2 -1
- package/dist/editors/ChipsEditor.d.ts +5 -1
- package/dist/editors/ChipsEditor.js +15 -2
- package/dist/editors/DateEditor.d.ts +2 -0
- package/dist/editors/DateEditor.js +76 -10
- package/dist/editors/EditorPanel.d.ts +14 -4
- package/dist/editors/EditorPanel.js +21 -4
- package/dist/editors/LocationEditor.js +35 -3
- package/dist/editors/NumberEditor.js +3 -2
- package/dist/editors/RangeEditor.d.ts +8 -0
- package/dist/editors/RangeEditor.js +3 -2
- package/dist/editors/RelationEditor.d.ts +2 -0
- package/dist/editors/RelationEditor.js +16 -2
- package/dist/editors/RelationSetEditor.d.ts +4 -2
- package/dist/editors/RelationSetEditor.js +36 -2
- package/dist/editors/SelectEditor.d.ts +5 -2
- package/dist/editors/SelectEditor.js +31 -4
- package/dist/editors/TextEditor.js +3 -1
- package/dist/editors/ValueListEditor.d.ts +3 -0
- package/dist/editors/ValueListEditor.js +10 -4
- package/dist/editors/edit-session.d.ts +14 -2
- package/dist/editors/edit-session.js +13 -5
- package/dist/editors/escape-rule.d.ts +12 -0
- package/dist/editors/escape-rule.js +8 -0
- package/dist/editors/open-value.js +2 -1
- package/dist/editors/picker-slot.d.ts +25 -0
- package/dist/editors/picker-slot.js +37 -0
- package/dist/editors/relation-picker.d.ts +44 -0
- package/dist/editors/relation-picker.js +49 -0
- package/dist/editors/relation-source.d.ts +1 -0
- package/dist/editors/relation-source.js +7 -1
- package/dist/field-row/FieldNoteLine.js +2 -1
- package/dist/field-row/FieldRow.js +41 -6
- package/dist/field-row/FieldRowLane.js +3 -1
- package/dist/field-row/editors/RowChipsEditor.js +1 -1
- package/dist/field-row/editors/RowDateEditor.js +1 -1
- package/dist/field-row/editors/RowEditor.js +2 -1
- package/dist/field-row/editors/RowRangeEditor.js +2 -1
- package/dist/field-row/editors/RowRelationEditor.js +2 -2
- package/dist/field-row/editors/RowSelectEditor.d.ts +1 -1
- package/dist/field-row/editors/RowSelectEditor.js +2 -2
- package/dist/field-row/editors/RowValueListEditor.js +1 -1
- package/dist/field-row/editors/host.d.ts +3 -0
- package/dist/field-row/editors/row-session.js +4 -1
- package/dist/fields/menus.d.ts +2 -0
- package/dist/fields/range-unit.d.ts +7 -0
- package/dist/fields/range-unit.js +13 -0
- package/dist/figures.d.ts +5 -48
- package/dist/figures.js +1 -63
- package/dist/grid/chrome/GridAddColumn.d.ts +8 -0
- package/dist/grid/chrome/GridAddColumn.js +66 -9
- package/dist/grid/chrome/GridAggregateMenu.d.ts +5 -2
- package/dist/grid/chrome/GridAggregateMenu.js +33 -4
- package/dist/grid/chrome/GridCellEditors.d.ts +9 -2
- package/dist/grid/chrome/GridCellEditors.js +24 -5
- package/dist/grid/chrome/GridCellOutline.d.ts +3 -2
- package/dist/grid/chrome/GridCellOutline.js +11 -1
- package/dist/grid/chrome/GridChipsEditor.js +1 -1
- package/dist/grid/chrome/GridColumnColorSection.d.ts +2 -0
- package/dist/grid/chrome/GridColumnColorSection.js +2 -2
- package/dist/grid/chrome/GridColumnDateSection.d.ts +4 -0
- package/dist/grid/chrome/GridColumnDateSection.js +2 -2
- package/dist/grid/chrome/GridColumnDurationSection.d.ts +4 -0
- package/dist/grid/chrome/GridColumnDurationSection.js +2 -2
- package/dist/grid/chrome/GridColumnMenu.d.ts +10 -6
- package/dist/grid/chrome/GridColumnMenu.js +62 -24
- package/dist/grid/chrome/GridColumnNumberSection.d.ts +4 -0
- package/dist/grid/chrome/GridColumnNumberSection.js +2 -2
- package/dist/grid/chrome/GridColumnPercentSection.d.ts +1 -0
- package/dist/grid/chrome/GridColumnPercentSection.js +1 -1
- package/dist/grid/chrome/GridColumnSortSection.d.ts +3 -3
- package/dist/grid/chrome/GridDateEditor.js +1 -1
- package/dist/grid/chrome/GridFooter.js +7 -48
- package/dist/grid/chrome/GridGroupMenu.d.ts +11 -5
- package/dist/grid/chrome/GridGroupMenu.js +28 -13
- package/dist/grid/chrome/GridHeader.d.ts +3 -1
- package/dist/grid/chrome/GridHeader.js +8 -8
- package/dist/grid/chrome/GridNumberEditor.js +3 -24
- package/dist/grid/chrome/GridRangeEditor.js +3 -2
- package/dist/grid/chrome/GridRelationEditor.js +2 -2
- package/dist/grid/chrome/GridRow.d.ts +2 -1
- package/dist/grid/chrome/GridRow.js +13 -37
- package/dist/grid/chrome/GridRowActions.js +2 -1
- package/dist/grid/chrome/GridRowCells.js +9 -4
- package/dist/grid/chrome/GridSelectEditor.js +30 -20
- package/dist/grid/chrome/GridStructure.d.ts +11 -4
- package/dist/grid/chrome/GridStructure.js +19 -7
- package/dist/grid/chrome/GridTable.js +138 -16
- package/dist/grid/chrome/GridTableSurface.d.ts +25 -12
- package/dist/grid/chrome/GridTableSurface.js +13 -6
- package/dist/grid/chrome/GridTextEditor.js +3 -1
- package/dist/grid/chrome/GridValueListEditor.js +1 -1
- package/dist/grid/chrome/cell-clipboard.d.ts +1 -1
- package/dist/grid/chrome/cell-clipboard.js +1 -1
- package/dist/grid/chrome/checks.d.ts +10 -2
- package/dist/grid/chrome/checks.js +17 -11
- package/dist/grid/chrome/column-glyph.d.ts +2 -2
- package/dist/grid/chrome/column-glyph.js +4 -0
- package/dist/grid/chrome/grid-add-column-items.d.ts +13 -0
- package/dist/grid/chrome/grid-add-column-items.js +40 -0
- package/dist/grid/chrome/grid-cell-classes.d.ts +2 -0
- package/dist/grid/chrome/grid-cell-classes.js +10 -4
- package/dist/grid/chrome/grid-column-menu-items.d.ts +75 -0
- package/dist/grid/chrome/grid-column-menu-items.js +263 -0
- package/dist/grid/chrome/grid-edit-escape.d.ts +4 -0
- package/dist/grid/chrome/grid-edit-escape.js +12 -0
- package/dist/grid/chrome/grid-edit-session.d.ts +2 -1
- package/dist/grid/chrome/grid-edit-session.js +14 -1
- package/dist/grid/chrome/grid-figure-value.d.ts +25 -0
- package/dist/grid/chrome/grid-figure-value.js +40 -0
- package/dist/grid/chrome/grid-fitted-box.d.ts +15 -0
- package/dist/grid/chrome/grid-fitted-box.js +26 -0
- package/dist/grid/chrome/grid-group-menu-items.d.ts +31 -0
- package/dist/grid/chrome/grid-group-menu-items.js +75 -0
- package/dist/grid/chrome/grid-group-menu-parts.d.ts +27 -0
- package/dist/grid/chrome/grid-group-menu-parts.js +19 -0
- package/dist/grid/chrome/grid-hover.d.ts +1 -0
- package/dist/grid/chrome/grid-hover.js +13 -1
- package/dist/grid/chrome/grid-lab.d.ts +7 -0
- package/dist/grid/chrome/grid-lab.js +7 -0
- package/dist/grid/chrome/grid-menu-focus.d.ts +12 -0
- package/dist/grid/chrome/grid-menu-focus.js +13 -0
- package/dist/grid/chrome/{useGridRowContextMenu.d.ts → grid-row-menu-items.d.ts} +15 -4
- package/dist/grid/chrome/{useGridRowContextMenu.js → grid-row-menu-items.js} +15 -18
- package/dist/grid/chrome/grid-row-props.d.ts +3 -1
- package/dist/grid/chrome/grid-row-window.d.ts +15 -5
- package/dist/grid/chrome/grid-row-window.js +44 -10
- package/dist/grid/chrome/grid-rows-menu.d.ts +38 -0
- package/dist/grid/chrome/grid-rows-menu.js +83 -0
- package/dist/grid/chrome/grid-table-props.d.ts +53 -8
- package/dist/grid/chrome/useGridBandFigures.d.ts +26 -0
- package/dist/grid/chrome/useGridBandFigures.js +50 -0
- package/dist/grid/chrome/useGridBoxes.d.ts +22 -0
- package/dist/grid/chrome/useGridBoxes.js +22 -0
- package/dist/grid/chrome/useGridColumnLayout.js +29 -4
- package/dist/grid/chrome/useGridKeyboard.js +7 -2
- package/dist/grid/chrome/useGridPartColumns.d.ts +5 -0
- package/dist/grid/chrome/useGridPartColumns.js +9 -0
- package/dist/grid/chrome/useGridRangeGestures.js +2 -1
- package/dist/grid/chrome/useGridRecorder.d.ts +16 -0
- package/dist/grid/chrome/useGridRecorder.js +144 -0
- package/dist/grid/chrome/useGridRowOpener.d.ts +41 -0
- package/dist/grid/chrome/useGridRowOpener.js +83 -0
- package/dist/grid/chrome/useGridScrollArea.d.ts +38 -12
- package/dist/grid/chrome/useGridScrollArea.js +70 -17
- package/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -0
- package/dist/grid/chrome/useGridTableInteractionModel.js +67 -9
- package/dist/grid/core/clipboard-model.d.ts +11 -3
- package/dist/grid/core/clipboard-model.js +9 -4
- package/dist/grid/core/commit-model.d.ts +7 -0
- package/dist/grid/core/editing-controller.d.ts +31 -1
- package/dist/grid/core/editing-controller.js +65 -0
- package/dist/grid/core/grid-recorder.d.ts +111 -0
- package/dist/grid/core/grid-recorder.js +223 -0
- package/dist/grid/core/part-edits.d.ts +18 -0
- package/dist/grid/core/part-edits.js +48 -0
- package/dist/grid/core/pending-reconciliation.js +12 -3
- package/dist/grid/core/refusal-sentence.d.ts +3 -0
- package/dist/grid/core/refusal-sentence.js +15 -0
- package/dist/grid/core/row-opened-from.d.ts +21 -0
- package/dist/grid/core/row-opened-from.js +11 -0
- package/dist/grid/core/useGridEditing.d.ts +16 -2
- package/dist/grid/core/useGridEditing.js +10 -4
- package/dist/grid/core/value-equality.d.ts +19 -1
- package/dist/grid/core/value-equality.js +24 -0
- package/dist/grid/index.d.ts +4 -1
- package/dist/grid/index.js +1 -0
- package/dist/grid/useGridTablePrefs.d.ts +1 -1
- package/dist/grid-lab.d.ts +18 -0
- package/dist/grid-lab.js +16 -0
- package/dist/grouping/sort-groups.d.ts +6 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/reset.d.ts +9 -0
- package/dist/internal/reset.js +1 -0
- package/dist/model/aggregates.d.ts +3 -3
- package/dist/model/aggregates.js +17 -71
- package/dist/model/column-capabilities.d.ts +29 -2
- package/dist/model/column-capabilities.js +27 -3
- package/dist/model/column-filters.js +24 -4
- package/dist/model/column-inspect.d.ts +2 -1
- package/dist/model/column-order.d.ts +2 -2
- package/dist/model/column-schema.d.ts +18 -7
- package/dist/model/column-state.d.ts +9 -20
- package/dist/model/column-state.js +1 -4
- package/dist/model/column-types.d.ts +1 -15
- package/dist/model/column-types.js +1 -1
- package/dist/model/part-columns.d.ts +17 -0
- package/dist/model/part-columns.js +67 -0
- package/dist/model/part-rows.d.ts +3 -10
- package/dist/model/part-rows.js +6 -11
- package/dist/model/part-write.d.ts +11 -0
- package/dist/model/part-write.js +52 -0
- package/dist/model/preferences.d.ts +3 -23
- package/dist/model/preferences.js +1 -17
- package/dist/model/prefs-buckets.d.ts +0 -27
- package/dist/model/prefs-buckets.js +1 -1
- package/dist/model/relation-filters.d.ts +0 -1
- package/dist/model/relation-filters.js +1 -1
- package/dist/model/row-icon.d.ts +5 -9
- package/dist/model/view-rules.d.ts +32 -6
- package/dist/model/view-rules.js +101 -21
- package/dist/provider/ViewsProvider.d.ts +22 -2
- package/dist/provider/ViewsProvider.js +21 -2
- package/dist/provider/components.d.ts +197 -9
- package/dist/provider/context.d.ts +12 -1
- package/dist/provider/desktop.d.ts +3 -0
- package/dist/provider/desktop.js +7 -4
- package/dist/provider/menu-groups.d.ts +3 -2
- package/dist/provider/menu-groups.js +13 -7
- package/dist/provider/missing-slot.d.ts +10 -0
- package/dist/provider/missing-slot.js +15 -0
- package/dist/provider/plain-input.d.ts +3 -2
- package/dist/provider/plain-input.js +3 -1
- package/dist/react.d.ts +3 -2
- package/dist/selection/SelectionBar.d.ts +18 -0
- package/dist/selection/SelectionBar.js +92 -0
- package/dist/selection/SelectionBarPhone.d.ts +3 -0
- package/dist/selection/SelectionBarPhone.js +14 -0
- package/dist/selection/bar-overflow.d.ts +12 -0
- package/dist/selection/bar-overflow.js +42 -0
- package/dist/selection/bar-parts.d.ts +15 -0
- package/dist/selection/bar-parts.js +17 -0
- package/dist/selection/index.d.ts +2 -0
- package/dist/selection/index.js +1 -0
- package/dist/selection/types.d.ts +3 -2
- package/dist/selection/verbs.d.ts +34 -0
- package/dist/selection/verbs.js +1 -0
- package/docs/contract.md +142 -39
- package/docs/getting-started.md +1 -1
- package/docs/guides/atoms.md +32 -4
- package/docs/guides/columns.md +1 -1
- package/docs/guides/display.md +1 -1
- package/docs/guides/editors.md +3 -3
- package/docs/guides/ports.md +1 -1
- package/docs/guides/selection.md +32 -20
- package/docs/guides/the-grid.md +43 -21
- package/docs/guides/the-provider.md +14 -4
- package/docs/index.md +2 -0
- package/docs/install.md +8 -1
- package/docs/reference/editors-date.md +2 -0
- package/docs/reference/editors-panel.md +4 -4
- package/docs/reference/editors-range.md +1 -1
- package/docs/reference/editors-relation.md +3 -3
- package/docs/reference/editors-select.md +1 -1
- package/docs/reference/editors-session.md +3 -2
- package/docs/reference/editors-value-list.md +1 -1
- package/docs/reference/field-row.md +2 -2
- package/docs/reference/grid.md +25 -6
- package/docs/reference/react.md +30 -8
- package/docs/reference/selection.md +10 -2
- package/docs/reference/views.md +42 -36
- package/package.json +22 -3
- package/skills/views/SKILL.md +3 -3
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** A part of a group band's ⋯ menu: its sort choices, the band's figure toggles (the count and each figure),
|
|
2
|
+
* Hide. */
|
|
3
|
+
export type GridGroupMenuPart = "sort" | "figures" | "hide";
|
|
4
|
+
/** The parts a band's ⋯ holds, whether its sort list searches through the app's `Command`, and whether there is
|
|
5
|
+
* a ⋯ at all. */
|
|
6
|
+
export type GridGroupMenuParts = {
|
|
7
|
+
sort: boolean;
|
|
8
|
+
figures: boolean;
|
|
9
|
+
hide: boolean;
|
|
10
|
+
command: boolean;
|
|
11
|
+
open: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Without `groupMenu`, the rule every grid had before it: sort choices or Hide open the ⋯, the figure toggles
|
|
15
|
+
* ride along whenever the menu is drawn, and the sort list searches through `Command` past eight choices. With it, each part
|
|
16
|
+
* it lists that the grid can fill (sort needs a sort and its choices, the figures need figures and a way to turn
|
|
17
|
+
* them on, Hide a way to hide), and the sort list always searches through `Command`. `command` is read on the
|
|
18
|
+
* `popover` route only: on the `menu` route the sort choices open beside the menu with no search.
|
|
19
|
+
*/
|
|
20
|
+
export declare function groupMenuParts({ groupMenu, hasSort, sortCount, figureCount, canToggleFigures, canHide, }: {
|
|
21
|
+
groupMenu?: readonly GridGroupMenuPart[];
|
|
22
|
+
hasSort: boolean;
|
|
23
|
+
sortCount: number;
|
|
24
|
+
figureCount: number;
|
|
25
|
+
canToggleFigures: boolean;
|
|
26
|
+
canHide: boolean;
|
|
27
|
+
}): GridGroupMenuParts;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { GRID_MENU_SEARCH_AFTER } from "./grid-menu-search.js";
|
|
2
|
+
export function groupMenuParts({ groupMenu, hasSort, sortCount, figureCount, canToggleFigures, canHide, }) {
|
|
3
|
+
const sortable = hasSort && sortCount > 0;
|
|
4
|
+
const toggles = figureCount > 0 && canToggleFigures;
|
|
5
|
+
if (!groupMenu) {
|
|
6
|
+
const open = sortable || canHide;
|
|
7
|
+
return {
|
|
8
|
+
sort: sortable,
|
|
9
|
+
figures: toggles,
|
|
10
|
+
hide: canHide,
|
|
11
|
+
command: sortable && sortCount > GRID_MENU_SEARCH_AFTER,
|
|
12
|
+
open,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const sort = groupMenu.includes("sort") && sortable;
|
|
16
|
+
const figures = groupMenu.includes("figures") && toggles;
|
|
17
|
+
const hide = groupMenu.includes("hide") && canHide;
|
|
18
|
+
return { sort, figures, hide, command: sort, open: sort || figures || hide };
|
|
19
|
+
}
|
|
@@ -22,6 +22,7 @@ export type GridHoverStore = {
|
|
|
22
22
|
};
|
|
23
23
|
export declare function createGridHoverStore(): GridHoverStore;
|
|
24
24
|
export declare const GridHoverContext: import("react").Context<GridHoverStore | null>;
|
|
25
|
+
export declare function useAnyHover(): boolean;
|
|
25
26
|
/** Whether the pointer is over this row. */
|
|
26
27
|
export declare function useGridRowHovered(rowKey: string): boolean;
|
|
27
28
|
/** Whether the pointer is over this cell. */
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useContext, useSyncExternalStore, } from "react";
|
|
4
4
|
import { cx } from "../../internal/cx.js";
|
|
5
|
+
import { ELEMENT_RESET } from "../../internal/reset.js";
|
|
5
6
|
import { useDesktop } from "../../provider/desktop.js";
|
|
6
7
|
import { useViews } from "../../provider/context.js";
|
|
7
8
|
import { GridRowActions } from "./GridRowActions.js";
|
|
@@ -24,6 +25,17 @@ export function createGridHoverStore() {
|
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
27
|
export const GridHoverContext = createContext(null);
|
|
28
|
+
const ANY_HOVER = "(any-hover: hover)";
|
|
29
|
+
function subscribeAnyHover(onChange) {
|
|
30
|
+
if (typeof window === "undefined" || !window.matchMedia)
|
|
31
|
+
return () => { };
|
|
32
|
+
const query = window.matchMedia(ANY_HOVER);
|
|
33
|
+
query.addEventListener?.("change", onChange);
|
|
34
|
+
return () => query.removeEventListener?.("change", onChange);
|
|
35
|
+
}
|
|
36
|
+
export function useAnyHover() {
|
|
37
|
+
return useSyncExternalStore(subscribeAnyHover, () => (typeof window === "undefined" || !window.matchMedia ? true : window.matchMedia(ANY_HOVER).matches), () => true);
|
|
38
|
+
}
|
|
27
39
|
const NO_STORE = () => () => { };
|
|
28
40
|
function useHovered(answer) {
|
|
29
41
|
const store = useContext(GridHoverContext);
|
|
@@ -77,5 +89,5 @@ function PickerCaretButton({ editing, onOpen }) {
|
|
|
77
89
|
e.stopPropagation();
|
|
78
90
|
if (!editing)
|
|
79
91
|
onOpen();
|
|
80
|
-
}, className: cx("absolute right-1 top-1/2 flex h-5 w-5 -translate-y-1/2 items-center justify-center hover:text-(color:--vk-fg)", editing ? "text-(color:--vk-fg)" : "text-(color:--vk-fg-subtlest)"), children: _jsx(icons.caretDown, { className: cx("h-3 w-3 transition-transform duration-100", editing && "rotate-180") }) }));
|
|
92
|
+
}, className: cx(ELEMENT_RESET, "absolute right-1 top-1/2 flex h-5 w-5 -translate-y-1/2 items-center justify-center hover:text-(color:--vk-fg)", editing ? "text-(color:--vk-fg)" : "text-(color:--vk-fg-subtlest)"), children: _jsx(icons.caretDown, { className: cx("h-3 w-3 transition-transform duration-100", editing && "rotate-180") }) }));
|
|
81
93
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type GridLab } from "../../grid-lab.js";
|
|
2
|
+
/**
|
|
3
|
+
* The grid's side of the page's lab (`src/grid-lab.ts`): the hook every grid reads it through. Null is the grid
|
|
4
|
+
* exactly as without a lab (`useGridRecorder`).
|
|
5
|
+
*/
|
|
6
|
+
export type { GridLab } from "../../grid-lab.js";
|
|
7
|
+
export declare function useGridLab(): GridLab | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
import { getGridLab, subscribeGridLab } from "../../grid-lab.js";
|
|
4
|
+
const serverLab = () => null;
|
|
5
|
+
export function useGridLab() {
|
|
6
|
+
return useSyncExternalStore(subscribeGridLab, getGridLab, serverLab);
|
|
7
|
+
}
|
|
@@ -31,6 +31,18 @@ export declare function gridMenuArrows(event: ReactKeyboardEvent<HTMLElement>, s
|
|
|
31
31
|
* names none keeps its arrows, and Tab leaves it.
|
|
32
32
|
*/
|
|
33
33
|
export declare function gridMenuSearchArrows(event: ReactKeyboardEvent<HTMLElement>, box: HTMLElement | null): void;
|
|
34
|
+
/**
|
|
35
|
+
* A press on a menu's own cell while the menu is open: noted on the press, read on the click it ends in. On the Menu
|
|
36
|
+
* route the app's menu may close on that press as a press outside it; the click that follows must not open it again.
|
|
37
|
+
*/
|
|
38
|
+
export declare function useGridMenuPress(open: boolean): {
|
|
39
|
+
/** The cell's `onPointerDownCapture`: notes whether the menu was open as the press began. */
|
|
40
|
+
notePress: () => void;
|
|
41
|
+
/** Read once, in the cell's click: whether the press that ended in this click began on an open menu. A click a key
|
|
42
|
+
* sent (`event.detail === 0`) answers false, so a press dragged off the cell, which ends in no click and leaves its
|
|
43
|
+
* note, never swallows the next Enter. */
|
|
44
|
+
pressedOpen: (event: ReactMouseEvent) => boolean;
|
|
45
|
+
};
|
|
34
46
|
/**
|
|
35
47
|
* Focus for a menu the grid's chrome opens (a column's menu, a footer's figure picker, a group's ⋯): opened by a key
|
|
36
48
|
* (a click with no pointer behind it, `detail === 0`, which is what the grid's Enter and Space send), it opens with
|
|
@@ -74,6 +74,19 @@ export function gridMenuSearchArrows(event, box) {
|
|
|
74
74
|
event.preventDefault();
|
|
75
75
|
(down ? rows[0] : rows[rows.length - 1]).focus();
|
|
76
76
|
}
|
|
77
|
+
export function useGridMenuPress(open) {
|
|
78
|
+
const note = useRef(false);
|
|
79
|
+
return {
|
|
80
|
+
notePress: () => {
|
|
81
|
+
note.current = open;
|
|
82
|
+
},
|
|
83
|
+
pressedOpen: (event) => {
|
|
84
|
+
const pressed = note.current;
|
|
85
|
+
note.current = false;
|
|
86
|
+
return pressed && event.detail !== 0;
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
77
90
|
export function useGridMenuFocus(open, anchor) {
|
|
78
91
|
const [byKey, setByKey] = useState(false);
|
|
79
92
|
const wasOpen = useRef(false);
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import type { useViews } from "../../provider/context.js";
|
|
1
2
|
import type { ViewsRowMenuItem } from "../../atoms/types.js";
|
|
2
3
|
import type { ListCellAction, ListColumn } from "../../model/column-schema.js";
|
|
3
4
|
import type { GridRowRangeSpan } from "../core/useGridRange.js";
|
|
4
|
-
|
|
5
|
+
/** What the menu's items read from the provider. */
|
|
6
|
+
export type GridRowMenuViews = Pick<ReturnType<typeof useViews>, "conventions" | "ports" | "messages" | "icons">;
|
|
7
|
+
/** The fields of a row's props its menu reads (`GridRowProps` carries them all). */
|
|
8
|
+
export type GridRowMenuRow<Row> = {
|
|
5
9
|
row: Row;
|
|
6
10
|
/** The DATA id — what a commit and the selection toggle address. */
|
|
7
11
|
id: string;
|
|
@@ -31,7 +35,14 @@ export declare function useGridRowContextMenu<Row>({ row, id, rowKey, columns, r
|
|
|
31
35
|
overlay?: boolean;
|
|
32
36
|
}) => void;
|
|
33
37
|
onFocusCell: (rowId: string, columnId: string) => void;
|
|
34
|
-
}): {
|
|
35
|
-
contextItems: ViewsRowMenuItem[];
|
|
36
|
-
handleContextMenu: (event: React.MouseEvent<HTMLElement>) => void;
|
|
37
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* The column a right-click landed on, and the focus it moves: a click outside the range focuses
|
|
41
|
+
* the cell, as a left-click would, so the menu's cell rows act on what the person sees selected.
|
|
42
|
+
*/
|
|
43
|
+
export declare function gridRowMenuColumnAt<Row>(menuRow: GridRowMenuRow<Row>, target: Element | null): string | null;
|
|
44
|
+
/**
|
|
45
|
+
* One row's menu: the cell's rows (copy, cut, paste, clear, or the range's), Select, the name's
|
|
46
|
+
* actions, then the host's own. Built only for the row a menu opens on, never for every drawn row.
|
|
47
|
+
*/
|
|
48
|
+
export declare function gridRowMenuItems<Row>(menuRow: GridRowMenuRow<Row>, menuColumnId: string | null, { conventions, ports, messages, icons }: GridRowMenuViews): ViewsRowMenuItem[];
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
import { useViews } from "../../provider/context.js";
|
|
5
3
|
import { gridColumnHasEditor } from "../../model/column-capabilities.js";
|
|
6
4
|
import { cellClearPrev, cellEditBaseline, cellPrevPayload, coercePaste, copyCell, getGridClipboard, rowHoldsCurrency, } from "./cell-clipboard.js";
|
|
7
5
|
function nameActionItems(row, actions, hostItems) {
|
|
@@ -23,13 +21,24 @@ function nameActionItems(row, actions, hostItems) {
|
|
|
23
21
|
}
|
|
24
22
|
return items.length > 0 ? [...items, { separator: true }] : [];
|
|
25
23
|
}
|
|
26
|
-
export function
|
|
27
|
-
const {
|
|
24
|
+
export function gridRowMenuColumnAt(menuRow, target) {
|
|
25
|
+
const { columns, selecting, rowRange, rowKey, onFocusCell } = menuRow;
|
|
26
|
+
const columnId = target?.closest("[data-col-id]")?.getAttribute("data-col-id");
|
|
27
|
+
const column = columnId ? columns.find((item) => item.id === columnId) : undefined;
|
|
28
|
+
if (column && !selecting) {
|
|
29
|
+
const index = columns.findIndex((item) => item.id === column.id);
|
|
30
|
+
const inRange = rowRange?.some((span) => index >= span.startCol && index <= span.endCol);
|
|
31
|
+
if (!inRange)
|
|
32
|
+
onFocusCell(rowKey, column.id);
|
|
33
|
+
}
|
|
34
|
+
return column?.id ?? null;
|
|
35
|
+
}
|
|
36
|
+
export function gridRowMenuItems(menuRow, menuColumnId, { conventions, ports, messages, icons }) {
|
|
37
|
+
const { row, id, rowKey, columns, rowActions, selecting, selectable, selected, toggle, editingEnabled, pendingByCol, selectValues, contextMenu, inActiveRange, rangeCanClear, onRangeCopy, onRangeCut, onRangePaste, onRangeClear, onPasteAtCell, onCommitCell, } = menuRow;
|
|
28
38
|
const copyLabel = messages({ key: "views.menus.copy" });
|
|
29
39
|
const cutLabel = messages({ key: "views.menus.cut" });
|
|
30
40
|
const pasteLabel = messages({ key: "views.menus.paste" });
|
|
31
41
|
const clearLabel = messages({ key: "views.menus.clear" });
|
|
32
|
-
const [menuColumnId, setMenuColumnId] = useState(null);
|
|
33
42
|
const menuColumn = menuColumnId
|
|
34
43
|
? columns.find((column) => column.id === menuColumnId)
|
|
35
44
|
: undefined;
|
|
@@ -137,17 +146,5 @@ export function useGridRowContextMenu({ row, id, rowKey, columns, rowActions, se
|
|
|
137
146
|
...nameActionItems(row, rowActions, hostItems),
|
|
138
147
|
...hostItems,
|
|
139
148
|
];
|
|
140
|
-
|
|
141
|
-
const target = event.target;
|
|
142
|
-
const columnId = target.closest("[data-col-id]")?.getAttribute("data-col-id");
|
|
143
|
-
const column = columnId ? columns.find((item) => item.id === columnId) : undefined;
|
|
144
|
-
setMenuColumnId(column?.id ?? null);
|
|
145
|
-
if (column && !selecting) {
|
|
146
|
-
const index = columns.findIndex((item) => item.id === column.id);
|
|
147
|
-
const inRange = rowRange?.some((span) => index >= span.startCol && index <= span.endCol);
|
|
148
|
-
if (!inRange)
|
|
149
|
-
onFocusCell(rowKey, column.id);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
return { contextItems, handleContextMenu };
|
|
149
|
+
return contextItems;
|
|
153
150
|
}
|
|
@@ -6,6 +6,7 @@ import type { ListCellAction, ListColumn, ListOptionColorOverrides, ListRelation
|
|
|
6
6
|
import type { ListDateStyleOverrides, ListDurationStyleOverrides, ListNumberFormatOverrides, ListPercentDisplayOverrides, ListShowTimeOverrides } from "../../model/column-format.js";
|
|
7
7
|
import type { ListRowIconAccessor } from "../../model/row-icon.js";
|
|
8
8
|
import type { GridRowRangeSpan } from "../core/useGridRange.js";
|
|
9
|
+
import type { GridCellPos } from "../core/coordinates.js";
|
|
9
10
|
export type GridRowProps<Row> = {
|
|
10
11
|
row: Row;
|
|
11
12
|
/** The DATA id — what a write, the optimistic overlay and selection address.
|
|
@@ -31,7 +32,8 @@ export type GridRowProps<Row> = {
|
|
|
31
32
|
contextMenu?: (row: Row) => ViewsRowMenuItem[];
|
|
32
33
|
rowClassName?: (row: Row) => string | undefined;
|
|
33
34
|
rowHref?: (row: Row) => string | undefined;
|
|
34
|
-
|
|
35
|
+
/** Opens the row from the cell at `at` (its key and column), which the grid's opener turns into the app's `from`. */
|
|
36
|
+
onOpenRow: (row: Row, at: GridCellPos) => void;
|
|
35
37
|
onPrefetchRow?: (row: Row) => void;
|
|
36
38
|
onRowDelete?: (id: string) => Promise<void>;
|
|
37
39
|
deleteLabel?: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type ReactNode, type RefObject } from "react";
|
|
1
|
+
import { type HTMLAttributes, type ReactNode, type Ref, type RefObject } from "react";
|
|
2
2
|
import type { GridFlatRows, GridRowPlace } from "../core/flat-rows.js";
|
|
3
3
|
import { type GridRowRange } from "../core/row-window.js";
|
|
4
|
+
import type { GridRecorder } from "../core/grid-recorder.js";
|
|
4
5
|
/**
|
|
5
6
|
* THE ROWS ON SCREEN. Each group draws only the rows its scroll owner shows, plus `GRID_WINDOW_OVERSCAN` each side,
|
|
6
7
|
* in flow between spacers as tall as the rows they stand for, so every group's box stays as tall as the group and its
|
|
@@ -8,8 +9,9 @@ import { type GridRowRange } from "../core/row-window.js";
|
|
|
8
9
|
* are their own runs between spacers.
|
|
9
10
|
*
|
|
10
11
|
* One store per table, like the hover store: a scroll anywhere (one capture listener on the document, which hears the
|
|
11
|
-
* grid's own area and the page alike)
|
|
12
|
-
* own, so a scroll redraws only the rows lists whose range changed:
|
|
12
|
+
* grid's own area and the page alike), a resize and the grid's area crossing the window's edge write each group's
|
|
13
|
+
* range, and each group's rows subscribe to their own, so a scroll redraws only the rows lists whose range changed:
|
|
14
|
+
* never the table, a head or a footer.
|
|
13
15
|
*/
|
|
14
16
|
/** A group's window. `range` is undefined until the first measure writes one: its rows draw their fallback. */
|
|
15
17
|
export type GridRowWindowSnapshot = {
|
|
@@ -35,11 +37,15 @@ export declare function fallbackRange(count: number, collapsed: boolean): GridRo
|
|
|
35
37
|
* `revealRow`). Positions are read in the content box's coordinates: a group's rows start at its region's top, and
|
|
36
38
|
* its region ends where its box does, so a collapsing group draws only what its clip still shows.
|
|
37
39
|
*/
|
|
38
|
-
export declare function useGridRowWindow<Row>({ rootRef, flat, rowHeight, }: {
|
|
40
|
+
export declare function useGridRowWindow<Row>({ rootRef, flat, rowHeight, recorderRef, boxes, }: {
|
|
39
41
|
rootRef: RefObject<HTMLDivElement | null>;
|
|
40
42
|
flat: GridFlatRows<Row>;
|
|
43
|
+
/** The grid's mode: its boxes are drawn anew when it changes, and the listeners and the measure follow them. */
|
|
44
|
+
boxes?: 1 | 2;
|
|
41
45
|
/** One row's height in px: `GRID_ROW_PX` times the grid's scale, what `--vk-row-h` resolves to. */
|
|
42
46
|
rowHeight: number;
|
|
47
|
+
/** The lab's recorder, when one runs: each scroll of the grid's own area is written into it. */
|
|
48
|
+
recorderRef?: RefObject<GridRecorder | null>;
|
|
43
49
|
}): {
|
|
44
50
|
store: GridRowWindowStore;
|
|
45
51
|
revealRow: (rowKey: string, columnId?: string) => void;
|
|
@@ -50,7 +56,7 @@ export declare function useGridRowWindow<Row>({ rootRef, flat, rowHeight, }: {
|
|
|
50
56
|
*/
|
|
51
57
|
export declare const GRID_GAP_LINES = "repeating-linear-gradient(to bottom, transparent 0 calc(var(--vk-row-h) - 1px), var(--vk-border-subtle) calc(var(--vk-row-h) - 1px) var(--vk-row-h))";
|
|
52
58
|
/** One section's rows: its window's rows and the kept ones between spacers, inside its rows region. */
|
|
53
|
-
export declare function GridWindowRows<Row>({ groupKey, items, collapsed, kept, renderRow, }: {
|
|
59
|
+
export declare function GridWindowRows<Row>({ groupKey, items, collapsed, kept, renderRow, ...container }: {
|
|
54
60
|
groupKey: string;
|
|
55
61
|
items: Row[];
|
|
56
62
|
/** A shut group: before the first measure it draws none. */
|
|
@@ -58,4 +64,8 @@ export declare function GridWindowRows<Row>({ groupKey, items, collapsed, kept,
|
|
|
58
64
|
/** Indices drawn wherever they are: the focused and the editing row. */
|
|
59
65
|
kept: readonly number[];
|
|
60
66
|
renderRow: (row: Row, index: number, items: Row[], groupKey: string) => ReactNode;
|
|
67
|
+
} & Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
|
|
68
|
+
/** What the row menu's trigger hands the rows' container (its handlers, its state, its ref) goes on to it: the
|
|
69
|
+
* menu wraps this element, and as the window moves only this element re-renders (`GridRowsMenu`). */
|
|
70
|
+
ref?: Ref<HTMLDivElement>;
|
|
61
71
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useCallback, useContext, useLayoutEffect, useRef, useState, useSyncExternalStore, } from "react";
|
|
4
4
|
import { flushSync } from "react-dom";
|
|
5
5
|
import { GRID_WINDOW_FALLBACK_ROWS, gridGroupRange, gridRowSegments, } from "../core/row-window.js";
|
|
6
|
+
import { cx } from "../../internal/cx.js";
|
|
7
|
+
import { GridFrozenEdge } from "./checks.js";
|
|
6
8
|
import { findGridScrollOwner, gridVisibleBox } from "./grid-scroll-owner.js";
|
|
7
9
|
const sameRange = (a, b) => a === b || (a != null && b != null && a.start === b.start && a.end === b.end);
|
|
8
10
|
export function createGridRowWindowStore() {
|
|
@@ -76,7 +78,7 @@ export function fallbackRange(count, collapsed) {
|
|
|
76
78
|
return { start: 0, end: Math.min(count, GRID_WINDOW_FALLBACK_ROWS) };
|
|
77
79
|
}
|
|
78
80
|
const ROWS_SELECTOR = '[data-slot="vk-grid-rows"]';
|
|
79
|
-
export function useGridRowWindow({ rootRef, flat, rowHeight, }) {
|
|
81
|
+
export function useGridRowWindow({ rootRef, flat, rowHeight, recorderRef, boxes = 1, }) {
|
|
80
82
|
const flatRef = useRef(flat);
|
|
81
83
|
useLayoutEffect(() => {
|
|
82
84
|
flatRef.current = flat;
|
|
@@ -146,22 +148,45 @@ export function useGridRowWindow({ rootRef, flat, rowHeight, }) {
|
|
|
146
148
|
useLayoutEffect(() => {
|
|
147
149
|
measure();
|
|
148
150
|
store.setRanges(ranges());
|
|
149
|
-
}, [flat, measure, ranges, store]);
|
|
151
|
+
}, [flat, measure, ranges, store, boxes]);
|
|
150
152
|
useLayoutEffect(() => {
|
|
151
153
|
const area = rootRef.current?.querySelector('[data-slot="vk-grid-scroll"]');
|
|
154
|
+
const pan = rootRef.current?.querySelector('[data-slot="vk-grid-pan"]') ?? null;
|
|
152
155
|
const box = content();
|
|
153
156
|
if (!area || !box)
|
|
154
157
|
return;
|
|
155
|
-
const
|
|
156
|
-
const next = ranges();
|
|
158
|
+
const apply = (next) => {
|
|
157
159
|
for (const [groupKey, range] of next) {
|
|
158
160
|
if (!sameRange(store.get(groupKey).range, range)) {
|
|
159
161
|
flushSync(() => store.setRanges(next));
|
|
160
|
-
return;
|
|
162
|
+
return true;
|
|
161
163
|
}
|
|
162
164
|
}
|
|
165
|
+
return false;
|
|
166
|
+
};
|
|
167
|
+
const redraw = () => {
|
|
168
|
+
apply(ranges());
|
|
169
|
+
};
|
|
170
|
+
const onScroll = (event) => {
|
|
171
|
+
const recorder = recorderRef?.current;
|
|
172
|
+
if (!recorder || (event.target !== area && event.target !== pan)) {
|
|
173
|
+
redraw();
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const scrollHeight = area.scrollHeight;
|
|
177
|
+
const top = area.scrollTop;
|
|
178
|
+
const left = area.scrollLeft + (pan?.scrollLeft ?? 0);
|
|
179
|
+
const at = performance.now();
|
|
180
|
+
const next = ranges();
|
|
181
|
+
const rendered = apply(next);
|
|
182
|
+
const handlerMs = performance.now() - at;
|
|
183
|
+
let drawn = 0;
|
|
184
|
+
next.forEach((range) => {
|
|
185
|
+
if (range)
|
|
186
|
+
drawn += range.end - range.start;
|
|
187
|
+
});
|
|
188
|
+
recorder.scroll(at, top, left, handlerMs, rendered, drawn, scrollHeight);
|
|
163
189
|
};
|
|
164
|
-
const onScroll = () => redraw();
|
|
165
190
|
document.addEventListener("scroll", onScroll, { capture: true, passive: true });
|
|
166
191
|
window.addEventListener("resize", onScroll, { passive: true });
|
|
167
192
|
let observer = null;
|
|
@@ -173,12 +198,21 @@ export function useGridRowWindow({ rootRef, flat, rowHeight, }) {
|
|
|
173
198
|
observer.observe(area);
|
|
174
199
|
observer.observe(box);
|
|
175
200
|
}
|
|
201
|
+
let view = null;
|
|
202
|
+
if (typeof IntersectionObserver !== "undefined") {
|
|
203
|
+
view = new IntersectionObserver(() => {
|
|
204
|
+
measure();
|
|
205
|
+
redraw();
|
|
206
|
+
});
|
|
207
|
+
view.observe(area);
|
|
208
|
+
}
|
|
176
209
|
return () => {
|
|
177
210
|
document.removeEventListener("scroll", onScroll, { capture: true });
|
|
178
211
|
window.removeEventListener("resize", onScroll);
|
|
179
212
|
observer?.disconnect();
|
|
213
|
+
view?.disconnect();
|
|
180
214
|
};
|
|
181
|
-
}, [content, measure, ranges, rootRef, store]);
|
|
215
|
+
}, [content, measure, ranges, rootRef, store, recorderRef, boxes]);
|
|
182
216
|
const revealRow = useCallback((rowKey, columnId) => {
|
|
183
217
|
const place = flatRef.current.place.get(rowKey);
|
|
184
218
|
if (!place)
|
|
@@ -193,7 +227,7 @@ export function useGridRowWindow({ rootRef, flat, rowHeight, }) {
|
|
|
193
227
|
return { store, revealRow };
|
|
194
228
|
}
|
|
195
229
|
export const GRID_GAP_LINES = "repeating-linear-gradient(to bottom, transparent 0 calc(var(--vk-row-h) - 1px), var(--vk-border-subtle) calc(var(--vk-row-h) - 1px) var(--vk-row-h))";
|
|
196
|
-
export function GridWindowRows({ groupKey, items, collapsed, kept, renderRow, }) {
|
|
230
|
+
export function GridWindowRows({ groupKey, items, collapsed, kept, renderRow, ...container }) {
|
|
197
231
|
const snapshot = useGridGroupWindow(groupKey);
|
|
198
232
|
const range = snapshot.range === undefined ? fallbackRange(items.length, collapsed) : snapshot.range;
|
|
199
233
|
const { revealed } = snapshot;
|
|
@@ -208,5 +242,5 @@ export function GridWindowRows({ groupKey, items, collapsed, kept, renderRow, })
|
|
|
208
242
|
children.push(renderRow(items[index], index, items, groupKey));
|
|
209
243
|
}
|
|
210
244
|
}
|
|
211
|
-
return (
|
|
245
|
+
return (_jsxs("div", { ...container, "data-slot": "vk-grid-rows", "data-group-key": groupKey, className: cx("relative", container.className), children: [children, _jsx(GridFrozenEdge, {})] }));
|
|
212
246
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type MouseEvent as ReactMouseEvent, type PointerEvent as ReactPointerEvent, type ReactElement } from "react";
|
|
2
|
+
import type { GridRowProps } from "./grid-row-props.js";
|
|
3
|
+
/** What the rows' container takes from the menu: the handlers that aim it, merged with the atom's own. */
|
|
4
|
+
export type GridRowsMenuTarget = {
|
|
5
|
+
onPointerDownCapture?: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
6
|
+
onPointerUpCapture?: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
7
|
+
onPointerCancelCapture?: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
8
|
+
onContextMenu?: (event: ReactMouseEvent<HTMLElement>) => void;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A row's way to aim its section's menu at itself on a right-click (`GridRow`'s `onContextMenu`). The row
|
|
12
|
+
* answers, not the container's DOM: a right-click inside something the row drew in a portal (a "+N"
|
|
13
|
+
* list, a picker, a card) bubbles through the row in React though not in the page, and opens the row's
|
|
14
|
+
* menu as it always did. Stable for the menu's life, so a row never redraws for it.
|
|
15
|
+
*/
|
|
16
|
+
export declare const GridRowMenuAimContext: import("react").Context<((rowKey: string, event: ReactMouseEvent<HTMLElement>) => void) | null>;
|
|
17
|
+
/**
|
|
18
|
+
* THE ROW'S MENU, ONE PER ROWS CONTAINER. The app's `RowMenu` atom wraps a section's rows' container once,
|
|
19
|
+
* not each row: a drawn row then carries none of the menu's machinery (a host's menu root, its dialog, its
|
|
20
|
+
* long-press), which every window move used to mount for each new row.
|
|
21
|
+
*
|
|
22
|
+
* The menu is AIMED at the row a press or a right-click came from: a right-click aims it at its row (the
|
|
23
|
+
* row's own handler, `GridRowMenuAimContext`) in the same event the atom opens on, so the atom's first
|
|
24
|
+
* render after it carries that row's id, items, link and delete; the ⋯ and the keyboard's menu key reach
|
|
25
|
+
* it the same way, each a right-click from inside its row. A mouse press aims it at once; a touch once it
|
|
26
|
+
* has stayed down `TOUCH_AIM_MS` (a long-press selects the row it is on), so a flick redraws nothing. A
|
|
27
|
+
* right-click on the container but on no row (a stretch still to be drawn) opens no menu.
|
|
28
|
+
*
|
|
29
|
+
* The rows' container is `children`: one element whose rows re-render on their own as the window moves
|
|
30
|
+
* (`GridWindowRows`), so a move redraws neither the menu nor the atom.
|
|
31
|
+
*/
|
|
32
|
+
export declare function GridRowsMenu<Row>({ rowPropsFor, selectable, children, }: {
|
|
33
|
+
/** The props the grid draws a row with, by its key; null for a row it no longer has. */
|
|
34
|
+
rowPropsFor: (rowKey: string) => GridRowProps<Row> | null;
|
|
35
|
+
/** Rows can be selected: a touch long-press selects the row it is on. */
|
|
36
|
+
selectable: boolean;
|
|
37
|
+
children: ReactElement<GridRowsMenuTarget>;
|
|
38
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { cloneElement, createContext, useEffect, useLayoutEffect, useRef, useState, } from "react";
|
|
4
|
+
import { useViews } from "../../provider/context.js";
|
|
5
|
+
import { gridRowMenuColumnAt, gridRowMenuItems } from "./grid-row-menu-items.js";
|
|
6
|
+
const ROW = '[data-slot="vk-grid-row"]';
|
|
7
|
+
function rowKeyAt(container, target) {
|
|
8
|
+
const row = target instanceof Element ? target.closest(ROW) : null;
|
|
9
|
+
return row && container.contains(row) ? row.getAttribute("data-row-id") : null;
|
|
10
|
+
}
|
|
11
|
+
export const GridRowMenuAimContext = createContext(null);
|
|
12
|
+
const AIMED = new WeakSet();
|
|
13
|
+
const TOUCH_AIM_MS = 250;
|
|
14
|
+
export function GridRowsMenu({ rowPropsFor, selectable, children, }) {
|
|
15
|
+
const views = useViews();
|
|
16
|
+
const RowMenu = views.atoms.RowMenu;
|
|
17
|
+
const [aim, setAim] = useState(null);
|
|
18
|
+
const [menuColumnId, setMenuColumnId] = useState(null);
|
|
19
|
+
const aimRef = useRef(null);
|
|
20
|
+
const touchTimer = useRef(null);
|
|
21
|
+
const settle = () => {
|
|
22
|
+
if (touchTimer.current != null)
|
|
23
|
+
clearTimeout(touchTimer.current);
|
|
24
|
+
touchTimer.current = null;
|
|
25
|
+
};
|
|
26
|
+
useEffect(() => settle, []);
|
|
27
|
+
const aimAt = (key, columnId) => {
|
|
28
|
+
settle();
|
|
29
|
+
aimRef.current = key;
|
|
30
|
+
setAim(key);
|
|
31
|
+
setMenuColumnId(columnId);
|
|
32
|
+
};
|
|
33
|
+
const latest = useRef({ rowPropsFor, aimAt, aim });
|
|
34
|
+
useLayoutEffect(() => {
|
|
35
|
+
latest.current = { rowPropsFor, aimAt, aim };
|
|
36
|
+
});
|
|
37
|
+
const [aimByRow] = useState(() => (rowKey, event) => {
|
|
38
|
+
const aimed = latest.current.rowPropsFor(rowKey);
|
|
39
|
+
if (!aimed)
|
|
40
|
+
return;
|
|
41
|
+
AIMED.add(event.nativeEvent);
|
|
42
|
+
latest.current.aimAt(rowKey, gridRowMenuColumnAt(aimed, event.target instanceof Element ? event.target : null));
|
|
43
|
+
});
|
|
44
|
+
const props = aim != null ? rowPropsFor(aim) : null;
|
|
45
|
+
const items = props ? gridRowMenuItems(props, menuColumnId, views) : [];
|
|
46
|
+
const [target] = useState(() => ({
|
|
47
|
+
onPointerDownCapture: (event) => {
|
|
48
|
+
const key = rowKeyAt(event.currentTarget, event.target);
|
|
49
|
+
if (key == null)
|
|
50
|
+
return;
|
|
51
|
+
aimRef.current = key;
|
|
52
|
+
if (event.pointerType !== "touch") {
|
|
53
|
+
if (key !== latest.current.aim)
|
|
54
|
+
latest.current.aimAt(key, null);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
settle();
|
|
58
|
+
touchTimer.current = setTimeout(() => {
|
|
59
|
+
touchTimer.current = null;
|
|
60
|
+
if (aimRef.current === key)
|
|
61
|
+
latest.current.aimAt(key, null);
|
|
62
|
+
}, TOUCH_AIM_MS);
|
|
63
|
+
},
|
|
64
|
+
onPointerUpCapture: settle,
|
|
65
|
+
onPointerCancelCapture: settle,
|
|
66
|
+
onContextMenu: (event) => {
|
|
67
|
+
if (AIMED.has(event.nativeEvent))
|
|
68
|
+
return;
|
|
69
|
+
if (event.target instanceof Node && event.currentTarget.contains(event.target)) {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
event.stopPropagation();
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
}));
|
|
75
|
+
const rows = cloneElement(children, target);
|
|
76
|
+
return (_jsx(GridRowMenuAimContext.Provider, { value: aimByRow, children: _jsx(RowMenu, { rowId: props?.id ?? "", items: items, openHref: props ? props.rowHref?.(props.row) : undefined, onDelete: props?.onRowDelete, deleteLabel: props?.deleteLabel, onToggleSelect: selectable
|
|
77
|
+
? () => {
|
|
78
|
+
const pressed = aimRef.current != null ? rowPropsFor(aimRef.current) : null;
|
|
79
|
+
if (pressed)
|
|
80
|
+
pressed.toggle(pressed.id, !pressed.selected);
|
|
81
|
+
}
|
|
82
|
+
: undefined, children: rows }) }));
|
|
83
|
+
}
|