@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,19 @@
|
|
|
1
|
+
import type { ListColumn } from "../../model/column-schema.js";
|
|
2
|
+
import type { ListDurationStyle } from "../../model/column-format.js";
|
|
3
|
+
import { type GridFlyouts } from "./GridFlyout.js";
|
|
4
|
+
/**
|
|
5
|
+
* The duration-column row in the header menu — one Format row whose flyout
|
|
6
|
+
* holds the styles — split out of GridColumnMenu because that file is held
|
|
7
|
+
* under the component ratchet's line ceiling rather than grown to hold them;
|
|
8
|
+
* the policy there is split, not raise (the same reason GridColumnColorSection
|
|
9
|
+
* is its own file rather than inline).
|
|
10
|
+
*/
|
|
11
|
+
export declare function GridColumnDurationSection<Row>({ column, durationStyle, onDurationStyleChange, flyouts, onClose, }: {
|
|
12
|
+
column: ListColumn<Row>;
|
|
13
|
+
/** This column's duration-rendering override. */
|
|
14
|
+
durationStyle?: ListDurationStyle;
|
|
15
|
+
/** Called with the FIELD key — the format map's key on every surface. */
|
|
16
|
+
onDurationStyleChange: (key: string, style: ListDurationStyle) => void;
|
|
17
|
+
flyouts: GridFlyouts;
|
|
18
|
+
onClose: () => void;
|
|
19
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { fieldKeyOf } from "../../model/view-rules.js";
|
|
4
|
+
import { formatNumber } from "./cells.js";
|
|
5
|
+
import { useCellFormat } from "../../cells/use-cell-format.js";
|
|
6
|
+
import { useViews } from "../../provider/context.js";
|
|
7
|
+
import { GridFlyoutRow } from "./GridFlyout.js";
|
|
8
|
+
import { KnobGlyph } from "./GridMenuRow.js";
|
|
9
|
+
const DURATION_STYLES = ["adaptive", "clock", "units"];
|
|
10
|
+
const DURATION_SAMPLE_MS = 5_904_000;
|
|
11
|
+
export function GridColumnDurationSection({ column, durationStyle, onDurationStyleChange, flyouts, onClose, }) {
|
|
12
|
+
const activeDurationStyle = durationStyle ?? column.format?.durationStyle ?? "adaptive";
|
|
13
|
+
const cellFormat = useCellFormat();
|
|
14
|
+
const { atoms, messages } = useViews();
|
|
15
|
+
const { Row } = atoms;
|
|
16
|
+
const styleLabel = (style) => messages({ key: "views.menus.duration-style", values: { style } });
|
|
17
|
+
return (_jsx(GridFlyoutRow, { id: "duration-format", flyouts: flyouts, label: messages({ key: "views.menus.format" }), detail: styleLabel(activeDurationStyle), leading: _jsx(KnobGlyph, { name: "duration" }), children: DURATION_STYLES.map((style) => (_jsx(Row, { chosen: activeDurationStyle === style, label: styleLabel(style), detail: _jsx("span", { className: "max-w-30 truncate", children: formatNumber(DURATION_SAMPLE_MS, column, {
|
|
18
|
+
...cellFormat,
|
|
19
|
+
durationStyle: style,
|
|
20
|
+
}) }), onClick: () => {
|
|
21
|
+
onDurationStyleChange(fieldKeyOf(column), style);
|
|
22
|
+
onClose();
|
|
23
|
+
} }, style))) }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { type MouseEvent as ReactMouseEvent, type ReactElement, type ReactNode, type Ref } from "react";
|
|
2
|
+
import type { PercentDisplay } from "@viewkitjs/fields";
|
|
3
|
+
import type { OrderDir } from "../../grouping/sort-groups.js";
|
|
4
|
+
import type { ListColumn, ListSelectColor } from "../../model/column-schema.js";
|
|
5
|
+
import type { ListDateStyle, ListDurationStyle, ListNumberFormatState } from "../../model/column-format.js";
|
|
6
|
+
/** What the menu sets on the header cell it opens from. */
|
|
7
|
+
type TriggerProps = {
|
|
8
|
+
ref?: Ref<HTMLElement>;
|
|
9
|
+
onClick?: (event: ReactMouseEvent<HTMLElement>) => void;
|
|
10
|
+
role?: "button";
|
|
11
|
+
"aria-haspopup"?: "dialog";
|
|
12
|
+
"aria-expanded"?: boolean;
|
|
13
|
+
};
|
|
14
|
+
/** The list's sort state, threaded from its controller — the menu is a second
|
|
15
|
+
* remote control for the SAME persisted sort the view-options popover drives. */
|
|
16
|
+
export type GridSortState = {
|
|
17
|
+
value: string;
|
|
18
|
+
dir: OrderDir;
|
|
19
|
+
onChange: (next: {
|
|
20
|
+
value: string;
|
|
21
|
+
dir: OrderDir;
|
|
22
|
+
}) => void;
|
|
23
|
+
};
|
|
24
|
+
/** The view's group, as the header asks it: which field, and a writer that
|
|
25
|
+
* takes a field key (or null to ungroup). */
|
|
26
|
+
export type GridGroupByState = {
|
|
27
|
+
fieldKey: string | null;
|
|
28
|
+
onChange: (fieldKey: string | null) => void;
|
|
29
|
+
};
|
|
30
|
+
/** The cheap OUTER gate: action columns declare "no header menu knobs" by
|
|
31
|
+
* contract, so they never get one. Everything else may — whether it actually
|
|
32
|
+
* does is `hasContent` inside the component, which is the only place that knows
|
|
33
|
+
* every per-knob gate. Two levels because this one runs per header cell per
|
|
34
|
+
* render and the other needs the full prop set. */
|
|
35
|
+
export declare function gridColumnMenuEnabled<Row>(col: ListColumn<Row>): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* THE HEADER MENU — sort · group · the type's knobs · move · hide, in that
|
|
38
|
+
* order, every block derived and none by hand:
|
|
39
|
+
*
|
|
40
|
+
* - Sort is offered where `effectiveSortKey` names a key (a declared
|
|
41
|
+
* `sortKey`, or the field itself on a saved view). Clear sort appears only
|
|
42
|
+
* while this column IS the sort.
|
|
43
|
+
* - Group by is offered on a saved view for a field whose type groups
|
|
44
|
+
* (`columnGroupable`, the rule the toolbar's Group menu reads too); Ungroup
|
|
45
|
+
* while it is the group.
|
|
46
|
+
* - The knobs are `columnKnobs`' answer — the same one the Columns drill-in
|
|
47
|
+
* reads, so the two doors cannot disagree. Every knob writes under the
|
|
48
|
+
* FIELD key: it is the workspace's setting for the field, shared by every
|
|
49
|
+
* surface that draws it. Each knob is ONE row — its name, its current
|
|
50
|
+
* value, a chevron — whose choices fly out beside the menu (`GridFlyoutRow`),
|
|
51
|
+
* so a money column's menu is a short list of settings, not every choice
|
|
52
|
+
* of every setting.
|
|
53
|
+
* - Move left / right swap with the visible neighbour; hide is last.
|
|
54
|
+
* - The host's rows for this column's field (a field editor's Edit field,
|
|
55
|
+
* Archive field) sit just above hide (`renderColumnMenuRows`).
|
|
56
|
+
*
|
|
57
|
+
* No admin block: a lock is the workspace's rule about who may WRITE a field,
|
|
58
|
+
* and it lives in Settings → Modules → Tables and the Columns drill-in, not
|
|
59
|
+
* beside the knobs about how the field READS.
|
|
60
|
+
*/
|
|
61
|
+
export declare function GridColumnMenu<Row>({ column, values, viewBacked, sort, groupBy, optionColors, onOptionColorChange, dateStyle, onDateStyleChange, durationStyle, onDurationStyleChange, showTime, onShowTimeChange, percentDisplay, onPercentDisplayChange, numberFormat, onNumberFormatChange, onMoveLeft, onMoveRight, onHide, formatsWritable, renderColumnMenuRows, children, }: {
|
|
62
|
+
column: ListColumn<Row>;
|
|
63
|
+
/** Distinct option values for select columns (declared + discovered), in display order. */
|
|
64
|
+
values: string[];
|
|
65
|
+
/** On a saved view a bound column sorts and groups by its field. */
|
|
66
|
+
viewBacked?: boolean;
|
|
67
|
+
sort?: GridSortState;
|
|
68
|
+
groupBy?: GridGroupByState;
|
|
69
|
+
/** The workspace's colour overrides for this column's option values. */
|
|
70
|
+
optionColors?: Record<string, ListSelectColor>;
|
|
71
|
+
onOptionColorChange?: (key: string, value: string, color: ListSelectColor | null) => void;
|
|
72
|
+
dateStyle?: ListDateStyle;
|
|
73
|
+
onDateStyleChange?: (key: string, style: ListDateStyle) => void;
|
|
74
|
+
durationStyle?: ListDurationStyle;
|
|
75
|
+
onDurationStyleChange?: (key: string, style: ListDurationStyle) => void;
|
|
76
|
+
showTime?: boolean;
|
|
77
|
+
onShowTimeChange?: (key: string, show: boolean) => void;
|
|
78
|
+
percentDisplay?: PercentDisplay;
|
|
79
|
+
onPercentDisplayChange?: (key: string, display: PercentDisplay) => void;
|
|
80
|
+
/** Number columns: current decimals / display-currency state (host-owned). */
|
|
81
|
+
numberFormat?: ListNumberFormatState;
|
|
82
|
+
/** `decimals: null` = the field's own (Automatic). */
|
|
83
|
+
onNumberFormatChange?: (key: string, patch: {
|
|
84
|
+
decimals?: number | null;
|
|
85
|
+
currency?: string;
|
|
86
|
+
}) => void;
|
|
87
|
+
/** Present when there is a visible neighbour on that side. */
|
|
88
|
+
onMoveLeft?: () => void;
|
|
89
|
+
onMoveRight?: () => void;
|
|
90
|
+
/** Renders the "Hide from view" row. The grid passes it only when hiding is
|
|
91
|
+
* allowed (hideable column, more than one visible, host persists state). */
|
|
92
|
+
onHide?: () => void;
|
|
93
|
+
/** Whether a format knob can be stored; the reader's own currency reading stays either way. */
|
|
94
|
+
formatsWritable?: boolean;
|
|
95
|
+
/** The host's rows for this column's field, above Hide; null for a field it adds nothing to. */
|
|
96
|
+
renderColumnMenuRows?: (fieldKey: string, close: () => void) => ReactNode;
|
|
97
|
+
/** The header cell: the menu's anchor, and a press on it opens or closes the menu. The menu
|
|
98
|
+
* sets its `ref`, so it must carry none of its own. */
|
|
99
|
+
children: ReactElement<TriggerProps>;
|
|
100
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
101
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cloneElement, useState, } from "react";
|
|
4
|
+
import { columnGroupable } from "../../model/column-order.js";
|
|
5
|
+
import { columnLabel } from "../../model/column-capabilities.js";
|
|
6
|
+
import { columnKnobs } from "../../model/column-knobs.js";
|
|
7
|
+
import { effectiveSortKey } from "../../model/column-sort.js";
|
|
8
|
+
import { fieldKeyOf } from "../../model/view-rules.js";
|
|
9
|
+
import { useViews } from "../../provider/context.js";
|
|
10
|
+
import { GridColumnColorSection } from "./GridColumnColorSection.js";
|
|
11
|
+
import { GridColumnDateSection } from "./GridColumnDateSection.js";
|
|
12
|
+
import { GridColumnDurationSection } from "./GridColumnDurationSection.js";
|
|
13
|
+
import { GridColumnNumberSection } from "./GridColumnNumberSection.js";
|
|
14
|
+
import { GridColumnPercentSection } from "./GridColumnPercentSection.js";
|
|
15
|
+
import { GridColumnSortSection } from "./GridColumnSortSection.js";
|
|
16
|
+
import { insideGridFlyout, useGridFlyouts } from "./GridFlyout.js";
|
|
17
|
+
import { GridMenuRow, GridMenuSeparator } from "./GridMenuRow.js";
|
|
18
|
+
export function gridColumnMenuEnabled(col) {
|
|
19
|
+
return !col.actions;
|
|
20
|
+
}
|
|
21
|
+
export function GridColumnMenu({ column, values, viewBacked = false, sort, groupBy, optionColors, onOptionColorChange, dateStyle, onDateStyleChange, durationStyle, onDurationStyleChange, showTime, onShowTimeChange, percentDisplay, onPercentDisplayChange, numberFormat, onNumberFormatChange, onMoveLeft, onMoveRight, onHide, formatsWritable = true, renderColumnMenuRows, children, }) {
|
|
22
|
+
const [open, setOpen] = useState(false);
|
|
23
|
+
const flyouts = useGridFlyouts();
|
|
24
|
+
const [anchor, setAnchor] = useState(null);
|
|
25
|
+
const { atoms, components, messages } = useViews();
|
|
26
|
+
const { Popover } = components;
|
|
27
|
+
const { List } = atoms;
|
|
28
|
+
const key = fieldKeyOf(column);
|
|
29
|
+
const sortKey = effectiveSortKey(column, viewBacked);
|
|
30
|
+
const sortable = !!(sortKey && sort);
|
|
31
|
+
const groupable = !!groupBy && viewBacked && columnGroupable(column);
|
|
32
|
+
const grouped = groupable && groupBy.fieldKey === column.field.key;
|
|
33
|
+
const knobs = columnKnobs(column);
|
|
34
|
+
const canPercent = formatsWritable && knobs.has("percentDisplay") && !!onPercentDisplayChange;
|
|
35
|
+
const canDate = formatsWritable && knobs.has("dateStyle") && !!onDateStyleChange;
|
|
36
|
+
const canDuration = formatsWritable && knobs.has("durationStyle") && !!onDurationStyleChange;
|
|
37
|
+
const canDecimals = formatsWritable && knobs.has("decimals") && !!onNumberFormatChange;
|
|
38
|
+
const canCurrency = knobs.has("currency") && !!onNumberFormatChange;
|
|
39
|
+
const canColor = formatsWritable &&
|
|
40
|
+
(column.type === "select" || column.type === "multiselect") &&
|
|
41
|
+
!column.render &&
|
|
42
|
+
!!onOptionColorChange &&
|
|
43
|
+
values.length > 0;
|
|
44
|
+
const canMove = !!onMoveLeft || !!onMoveRight;
|
|
45
|
+
const close = () => {
|
|
46
|
+
flyouts.close();
|
|
47
|
+
setOpen(false);
|
|
48
|
+
};
|
|
49
|
+
const handleOpenChange = (next) => (next ? setOpen(true) : close());
|
|
50
|
+
const editorRows = renderColumnMenuRows?.(key, close) ?? null;
|
|
51
|
+
const hasContent = sortable ||
|
|
52
|
+
groupable ||
|
|
53
|
+
canPercent ||
|
|
54
|
+
canDate ||
|
|
55
|
+
canDuration ||
|
|
56
|
+
canDecimals ||
|
|
57
|
+
canCurrency ||
|
|
58
|
+
canColor ||
|
|
59
|
+
canMove ||
|
|
60
|
+
!!editorRows ||
|
|
61
|
+
!!onHide;
|
|
62
|
+
if (!hasContent)
|
|
63
|
+
return _jsx(_Fragment, { children: children });
|
|
64
|
+
const canKnobs = canPercent || canDate || canDuration || canDecimals || canCurrency;
|
|
65
|
+
const present = [sortable, groupable, canKnobs, canColor, canMove, !!editorRows, !!onHide];
|
|
66
|
+
const divider = (i) => (present.slice(0, i).some(Boolean) ? _jsx(GridMenuSeparator, {}) : null);
|
|
67
|
+
const trigger = cloneElement(children, {
|
|
68
|
+
ref: setAnchor,
|
|
69
|
+
onClick: (event) => {
|
|
70
|
+
children.props.onClick?.(event);
|
|
71
|
+
if (open)
|
|
72
|
+
close();
|
|
73
|
+
else
|
|
74
|
+
setOpen(true);
|
|
75
|
+
},
|
|
76
|
+
role: "button",
|
|
77
|
+
"aria-haspopup": "dialog",
|
|
78
|
+
"aria-expanded": open,
|
|
79
|
+
});
|
|
80
|
+
return (_jsxs(_Fragment, { children: [trigger, _jsx(Popover, { open: open, onOpenChange: handleOpenChange, anchor: anchor, side: "bottom", align: "start", sideOffset: 2, initialFocus: false, chrome: "menu", panelData: { "data-slot": "vk-grid-column-menu" }, className: "w-52", onOutsidePress: (event) => anchor?.contains(event.target) || insideGridFlyout(event) ? false : undefined, children: _jsx("div", { onPointerOver: flyouts.onListPointerOver, children: _jsxs(List, { children: [sortable && (_jsxs(_Fragment, { children: [divider(0), _jsx(GridColumnSortSection, { sortKey: sortKey, value: sort.value, dir: sort.dir, onChange: sort.onChange, onClose: close })] })), groupable && (_jsxs(_Fragment, { children: [divider(1), grouped ? (_jsx(GridMenuRow, { label: messages({ key: "views.menus.ungroup" }), icon: "group", active: true, onClick: () => {
|
|
81
|
+
groupBy.onChange(null);
|
|
82
|
+
close();
|
|
83
|
+
} })) : (_jsx(GridMenuRow, { label: messages({
|
|
84
|
+
key: "views.menus.group-by",
|
|
85
|
+
values: { field: columnLabel(column) },
|
|
86
|
+
}), icon: "group", onClick: () => {
|
|
87
|
+
groupBy.onChange(column.field.key);
|
|
88
|
+
close();
|
|
89
|
+
} }))] })), canKnobs && divider(2), canPercent && (_jsx(GridColumnPercentSection, { column: column, fieldKey: key, percentDisplay: percentDisplay, onPercentDisplayChange: onPercentDisplayChange, flyouts: flyouts, onClose: close })), canDate && (_jsx(GridColumnDateSection, { column: column, dateStyle: dateStyle, onDateStyleChange: onDateStyleChange, showTime: showTime, onShowTimeChange: knobs.has("showTime") ? onShowTimeChange : undefined, flyouts: flyouts, onClose: close })), canDuration && (_jsx(GridColumnDurationSection, { column: column, durationStyle: durationStyle, onDurationStyleChange: onDurationStyleChange, flyouts: flyouts, onClose: close })), (canDecimals || canCurrency) && (_jsx(GridColumnNumberSection, { column: column, fieldKey: key, decimals: canDecimals, currency: canCurrency, numberFormat: numberFormat, onNumberFormatChange: onNumberFormatChange, flyouts: flyouts, onClose: close })), canColor && (_jsxs(_Fragment, { children: [divider(3), _jsx(GridColumnColorSection, { column: column, values: values, optionColors: optionColors, flyouts: flyouts, onOptionColorChange: onOptionColorChange, onClose: close })] })), canMove && (_jsxs(_Fragment, { children: [divider(4), onMoveLeft && (_jsx(GridMenuRow, { label: messages({ key: "views.menus.move-left" }), icon: "moveLeft", onClick: () => {
|
|
90
|
+
onMoveLeft();
|
|
91
|
+
close();
|
|
92
|
+
} })), onMoveRight && (_jsx(GridMenuRow, { label: messages({ key: "views.menus.move-right" }), icon: "moveRight", onClick: () => {
|
|
93
|
+
onMoveRight();
|
|
94
|
+
close();
|
|
95
|
+
} }))] })), editorRows && (_jsxs(_Fragment, { children: [divider(5), editorRows] })), onHide && (_jsxs(_Fragment, { children: [divider(6), _jsx(GridMenuRow, { label: messages({ key: "views.menus.hide-column" }), icon: "hide", onClick: () => {
|
|
96
|
+
onHide();
|
|
97
|
+
close();
|
|
98
|
+
} })] }))] }) }) })] }));
|
|
99
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ListColumn } from "../../model/column-schema.js";
|
|
2
|
+
import type { ListNumberFormatState } from "../../model/column-format.js";
|
|
3
|
+
import { type GridFlyouts } from "./GridFlyout.js";
|
|
4
|
+
/**
|
|
5
|
+
* The number rows in the header menu — Decimals, and Currency on a column
|
|
6
|
+
* whose binding states rates (Original · EUR · USD · RON), each one row whose
|
|
7
|
+
* choices fly out. Lifted out of GridColumnMenu for the line ceiling; the
|
|
8
|
+
* policy is split, not raise. Writes under the FIELD key.
|
|
9
|
+
*/
|
|
10
|
+
export declare function GridColumnNumberSection<Row>({ column, fieldKey, decimals, currency, numberFormat, onNumberFormatChange, flyouts, onClose, }: {
|
|
11
|
+
column: ListColumn<Row>;
|
|
12
|
+
fieldKey: string;
|
|
13
|
+
/** Offer the Decimals row. */
|
|
14
|
+
decimals: boolean;
|
|
15
|
+
/** Offer the Currency row (the column carries rates — `columnKnobs`). */
|
|
16
|
+
currency: boolean;
|
|
17
|
+
numberFormat?: ListNumberFormatState;
|
|
18
|
+
/** `decimals: null` = the field's own (Automatic). */
|
|
19
|
+
onNumberFormatChange: (key: string, patch: {
|
|
20
|
+
decimals?: number | null;
|
|
21
|
+
currency?: string;
|
|
22
|
+
}) => void;
|
|
23
|
+
flyouts: GridFlyouts;
|
|
24
|
+
onClose: () => void;
|
|
25
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { LIST_DECIMALS_CHOICES } from "../../model/column-state.js";
|
|
4
|
+
import { useViews } from "../../provider/context.js";
|
|
5
|
+
import { GridFlyoutRow } from "./GridFlyout.js";
|
|
6
|
+
import { KnobGlyph } from "./GridMenuRow.js";
|
|
7
|
+
const DECIMALS_SAMPLE = 1234.567;
|
|
8
|
+
const AUTOMATIC_SAMPLE = String(Number(DECIMALS_SAMPLE.toFixed(2)));
|
|
9
|
+
export function GridColumnNumberSection({ column, fieldKey, decimals, currency, numberFormat, onNumberFormatChange, flyouts, onClose, }) {
|
|
10
|
+
const chosen = numberFormat?.decimals ?? undefined;
|
|
11
|
+
const declared = column.format?.decimals;
|
|
12
|
+
const shown = chosen ?? declared;
|
|
13
|
+
const currencyOptions = numberFormat?.currencyOptions ?? [];
|
|
14
|
+
const { atoms, messages } = useViews();
|
|
15
|
+
const { Row } = atoms;
|
|
16
|
+
const automatic = messages({ key: "views.menus.automatic" });
|
|
17
|
+
return (_jsxs(_Fragment, { children: [decimals && (_jsxs(GridFlyoutRow, { id: "decimals", flyouts: flyouts, label: messages({ key: "views.menus.decimals" }), detail: shown ?? automatic, leading: _jsx(KnobGlyph, { name: "number" }), children: [_jsx(Row, { chosen: chosen === undefined, label: automatic, detail: _jsx("span", { className: "tabular-nums", children: declared === undefined ? AUTOMATIC_SAMPLE : DECIMALS_SAMPLE.toFixed(declared) }), onClick: () => {
|
|
18
|
+
onNumberFormatChange(fieldKey, { decimals: null });
|
|
19
|
+
onClose();
|
|
20
|
+
} }), LIST_DECIMALS_CHOICES.map((d) => (_jsx(Row, { chosen: chosen === d, label: d, detail: _jsx("span", { className: "tabular-nums", children: DECIMALS_SAMPLE.toFixed(d) }), onClick: () => {
|
|
21
|
+
onNumberFormatChange(fieldKey, { decimals: d });
|
|
22
|
+
onClose();
|
|
23
|
+
} }, d)))] })), currency && currencyOptions.length > 0 && (_jsx(GridFlyoutRow, { id: "currency", flyouts: flyouts, label: messages({ key: "views.menus.currency" }), detail: currencyOptions.find((c) => c.value === numberFormat?.currency)?.label, leading: _jsx(KnobGlyph, { name: "currency" }), children: currencyOptions.map((c) => (_jsx(Row, { chosen: numberFormat?.currency === c.value, label: c.label, onClick: () => {
|
|
24
|
+
onNumberFormatChange(fieldKey, { currency: c.value });
|
|
25
|
+
onClose();
|
|
26
|
+
} }, c.value))) }))] }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PercentDisplay } from "@viewkitjs/fields";
|
|
2
|
+
import type { ListColumn } from "../../model/column-schema.js";
|
|
3
|
+
import { type GridFlyouts } from "./GridFlyout.js";
|
|
4
|
+
/** The percent row in the header menu — how the figure is drawn, one row
|
|
5
|
+
* whose choices fly out. Split out of GridColumnMenu for the line ceiling;
|
|
6
|
+
* the policy is split, not raise. */
|
|
7
|
+
export declare function GridColumnPercentSection<Row>({ column, percentDisplay, onPercentDisplayChange, fieldKey, flyouts, onClose, }: {
|
|
8
|
+
column: ListColumn<Row>;
|
|
9
|
+
/** The workspace's choice for this field, when one is stored. */
|
|
10
|
+
percentDisplay?: PercentDisplay;
|
|
11
|
+
onPercentDisplayChange: (fieldKey: string, display: PercentDisplay) => void;
|
|
12
|
+
fieldKey: string;
|
|
13
|
+
flyouts: GridFlyouts;
|
|
14
|
+
onClose: () => void;
|
|
15
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useViews } from "../../provider/context.js";
|
|
4
|
+
import { GridFlyoutRow } from "./GridFlyout.js";
|
|
5
|
+
import { KnobGlyph } from "./GridMenuRow.js";
|
|
6
|
+
const DISPLAYS = ["text", "bar", "ring"];
|
|
7
|
+
export function GridColumnPercentSection({ column, percentDisplay, onPercentDisplayChange, fieldKey, flyouts, onClose, }) {
|
|
8
|
+
const active = percentDisplay ?? column.format?.percentDisplay ?? "text";
|
|
9
|
+
const { atoms, messages } = useViews();
|
|
10
|
+
const { Row } = atoms;
|
|
11
|
+
const displayLabel = (display) => messages({ key: "views.menus.percent-display-option", values: { display } });
|
|
12
|
+
return (_jsx(GridFlyoutRow, { id: "percent-display", flyouts: flyouts, label: messages({ key: "views.menus.percent-display" }), detail: displayLabel(active), leading: _jsx(KnobGlyph, { name: "progress" }), children: DISPLAYS.map((display) => (_jsx(Row, { chosen: active === display, label: displayLabel(display), onClick: () => {
|
|
13
|
+
onPercentDisplayChange(fieldKey, display);
|
|
14
|
+
onClose();
|
|
15
|
+
} }, display))) }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OrderDir } from "../../grouping/sort-groups.js";
|
|
2
|
+
/**
|
|
3
|
+
* The sort rows in the header menu — ascending, descending, and Clear sort
|
|
4
|
+
* while this column IS the sort. Split out of GridColumnMenu for the line
|
|
5
|
+
* ceiling; the policy is split, not raise.
|
|
6
|
+
*/
|
|
7
|
+
export declare function GridColumnSortSection({ sortKey, value, dir, onChange, onClose, }: {
|
|
8
|
+
/** The key this column sorts by (`effectiveSortKey`). */
|
|
9
|
+
sortKey: string;
|
|
10
|
+
/** The list's current sort key and direction. */
|
|
11
|
+
value: string;
|
|
12
|
+
dir: OrderDir;
|
|
13
|
+
onChange: (next: {
|
|
14
|
+
value: string;
|
|
15
|
+
dir: OrderDir;
|
|
16
|
+
}) => void;
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useViews } from "../../provider/context.js";
|
|
4
|
+
import { GridMenuRow } from "./GridMenuRow.js";
|
|
5
|
+
export function GridColumnSortSection({ sortKey, value, dir, onChange, onClose, }) {
|
|
6
|
+
const { messages } = useViews();
|
|
7
|
+
const active = value === sortKey;
|
|
8
|
+
const pick = (next) => {
|
|
9
|
+
onChange({ value: sortKey, dir: next });
|
|
10
|
+
onClose();
|
|
11
|
+
};
|
|
12
|
+
return (_jsxs(_Fragment, { children: [_jsx(GridMenuRow, { label: messages({ key: "views.menus.sort-asc" }), icon: "sortRowsUp", active: active && dir === "asc", onClick: () => pick("asc") }), _jsx(GridMenuRow, { label: messages({ key: "views.menus.sort-desc" }), icon: "sortRowsDown", active: active && dir === "desc", onClick: () => pick("desc") }), active && (_jsx(GridMenuRow, { label: messages({ key: "views.menus.sort-clear" }), icon: "clearSort", onClick: () => {
|
|
13
|
+
onChange({ value: "", dir: "asc" });
|
|
14
|
+
onClose();
|
|
15
|
+
} }))] }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The GRID's host around the shared `DateEditor` (`@viewkitjs/views/editors/date`) —
|
|
3
|
+
* the editing core is one component across every surface; this host only owns
|
|
4
|
+
* the grid's mechanics: anchor to the cell rect, open on mount, WHICH close
|
|
5
|
+
* happened, the exit animation gap, and the write. The core answers what the
|
|
6
|
+
* close means (`resolveClose`); the host applies it after the popover has
|
|
7
|
+
* played out. Time is present in the payload ("YYYY-MM-DDTHH:MM") unless the
|
|
8
|
+
* column is a calendar-day field (`dayOnly`), preserving the editor's original
|
|
9
|
+
* grid behavior — the column's Show-time setting is display only.
|
|
10
|
+
*/
|
|
11
|
+
export declare function GridDateEditor({ initial, dayOnly, onCommit, onCancel, }: {
|
|
12
|
+
/** The stored value (ISO string) — selects the day + opening month. */
|
|
13
|
+
initial?: string;
|
|
14
|
+
/** The column presents a calendar-day field (`date`): the commit is the day
|
|
15
|
+
* alone — the shape the row stores and the write gate judges through
|
|
16
|
+
* `zodFor`. The panel still shows its time chip; a day field's row has no
|
|
17
|
+
* clock for it to land in. */
|
|
18
|
+
dayOnly?: boolean;
|
|
19
|
+
/** "YYYY-MM-DDTHH:MM" (local); "YYYY-MM-DD" when `dayOnly`. */
|
|
20
|
+
onCommit: (value: string) => void;
|
|
21
|
+
onCancel: () => void;
|
|
22
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { useViews } from "../../provider/context.js";
|
|
5
|
+
import { DateEditor } from "../../editors/DateEditor.js";
|
|
6
|
+
export function GridDateEditor({ initial, dayOnly = false, onCommit, onCancel, }) {
|
|
7
|
+
const { Popover } = useViews().components;
|
|
8
|
+
const [open, setOpen] = useState(true);
|
|
9
|
+
const editorRef = useRef(null);
|
|
10
|
+
const anchorRef = useRef(null);
|
|
11
|
+
const closedRef = useRef(false);
|
|
12
|
+
const EXIT_MS = 160;
|
|
13
|
+
const close = (reason) => {
|
|
14
|
+
if (closedRef.current)
|
|
15
|
+
return;
|
|
16
|
+
closedRef.current = true;
|
|
17
|
+
const resolution = editorRef.current?.resolveClose(reason) ?? { kind: "noop" };
|
|
18
|
+
setOpen(false);
|
|
19
|
+
window.setTimeout(() => {
|
|
20
|
+
if (resolution.kind === "commit") {
|
|
21
|
+
onCommit(dayOnly ? resolution.payload.slice(0, 10) : resolution.payload);
|
|
22
|
+
}
|
|
23
|
+
else
|
|
24
|
+
onCancel();
|
|
25
|
+
}, EXIT_MS);
|
|
26
|
+
};
|
|
27
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(Popover, { open: open, onOpenChange: (next) => {
|
|
28
|
+
if (!next)
|
|
29
|
+
close("outside");
|
|
30
|
+
}, anchor: anchorRef, align: "start", sideOffset: 4, onEscape: () => close("escape"), onOutsidePress: () => close("outside"), initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "z-90 w-auto", children: _jsx(DateEditor, { ref: editorRef, initial: initial, onRequestClose: close }) })] }));
|
|
31
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type PointerEvent as ReactPointerEvent, type ReactElement, type ReactNode } from "react";
|
|
2
|
+
/** How long the pointer rests on a row before its flyout opens: a sweep down the list opens none. */
|
|
3
|
+
export declare const GRID_FLYOUT_HOVER_MS = 150;
|
|
4
|
+
export type GridFlyouts = {
|
|
5
|
+
/** The flyout showing now, by row id. */
|
|
6
|
+
openId: string | null;
|
|
7
|
+
/** Opens `id` after the hover delay; `null` closes whatever is open. */
|
|
8
|
+
hoverTo: (id: string | null) => void;
|
|
9
|
+
/** Drops a pending hover; an open flyout stays (the pointer is usually on its way in). */
|
|
10
|
+
cancelHover: () => void;
|
|
11
|
+
toggle: (id: string) => void;
|
|
12
|
+
/** Opens `id` at once, dropping a pending hover; never closes it. */
|
|
13
|
+
open: (id: string) => void;
|
|
14
|
+
close: () => void;
|
|
15
|
+
/** For the list that holds the rows: resting on a plain row closes the open flyout. */
|
|
16
|
+
onListPointerOver: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
17
|
+
/** A flyout row hands its pointer events here, its popup's too through the React tree, so the list leaves them be. */
|
|
18
|
+
claim: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* THE FLYOUTS' STATE — one open at a time across every `GridFlyoutRow` in a menu. The menu
|
|
22
|
+
* that holds the rows owns it and calls `close()` when it closes itself.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useGridFlyouts(): GridFlyouts;
|
|
25
|
+
/** Whether a press landed inside a grid flyout, read from its slot: the menu that opened it stays open. */
|
|
26
|
+
export declare function insideGridFlyout(event: Event): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* A menu row that opens its choices BESIDE the menu: the map's Popover anchored on the row.
|
|
29
|
+
* A resting pointer opens it after a short delay; a mouse click opens it at once and never
|
|
30
|
+
* closes it (the hover usually got there first); a tap toggles it, the only way in on a phone.
|
|
31
|
+
* The row and its popup sit inside one element, so the popup's pointer events reach `claim`
|
|
32
|
+
* through the React tree, and the menu's list leaves the flyout open while the pointer is in it.
|
|
33
|
+
*/
|
|
34
|
+
export declare function GridFlyoutRow({ id, flyouts, label, detail, leading, title, children, }: {
|
|
35
|
+
id: string;
|
|
36
|
+
flyouts: GridFlyouts;
|
|
37
|
+
label: ReactNode;
|
|
38
|
+
/** The current choice, the row's right-hand detail. */
|
|
39
|
+
detail?: ReactNode;
|
|
40
|
+
leading?: ReactNode;
|
|
41
|
+
title?: string;
|
|
42
|
+
/** The flyout's rows. */
|
|
43
|
+
children: ReactNode;
|
|
44
|
+
}): ReactElement;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState, } from "react";
|
|
4
|
+
import { useViews } from "../../provider/context.js";
|
|
5
|
+
export const GRID_FLYOUT_HOVER_MS = 150;
|
|
6
|
+
export function useGridFlyouts() {
|
|
7
|
+
const [openId, setOpenId] = useState(null);
|
|
8
|
+
const timerRef = useRef(null);
|
|
9
|
+
const claimed = useRef(new WeakSet());
|
|
10
|
+
const cancelHover = () => {
|
|
11
|
+
if (timerRef.current != null) {
|
|
12
|
+
window.clearTimeout(timerRef.current);
|
|
13
|
+
timerRef.current = null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
useEffect(() => cancelHover, []);
|
|
17
|
+
const hoverTo = (id) => {
|
|
18
|
+
cancelHover();
|
|
19
|
+
timerRef.current = window.setTimeout(() => {
|
|
20
|
+
timerRef.current = null;
|
|
21
|
+
setOpenId(id);
|
|
22
|
+
}, GRID_FLYOUT_HOVER_MS);
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
openId,
|
|
26
|
+
hoverTo,
|
|
27
|
+
cancelHover,
|
|
28
|
+
toggle: (id) => {
|
|
29
|
+
cancelHover();
|
|
30
|
+
setOpenId((current) => (current === id ? null : id));
|
|
31
|
+
},
|
|
32
|
+
open: (id) => {
|
|
33
|
+
cancelHover();
|
|
34
|
+
setOpenId(id);
|
|
35
|
+
},
|
|
36
|
+
close: () => {
|
|
37
|
+
cancelHover();
|
|
38
|
+
setOpenId(null);
|
|
39
|
+
},
|
|
40
|
+
onListPointerOver: (event) => {
|
|
41
|
+
if (claimed.current.has(event.nativeEvent))
|
|
42
|
+
return;
|
|
43
|
+
if (openId != null)
|
|
44
|
+
hoverTo(null);
|
|
45
|
+
},
|
|
46
|
+
claim: (event) => {
|
|
47
|
+
claimed.current.add(event.nativeEvent);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export function insideGridFlyout(event) {
|
|
52
|
+
const target = event.target;
|
|
53
|
+
return target?.closest?.('[data-slot="vk-grid-flyout"]') != null;
|
|
54
|
+
}
|
|
55
|
+
export function GridFlyoutRow({ id, flyouts, label, detail, leading, title, children, }) {
|
|
56
|
+
const { atoms, components, icons } = useViews();
|
|
57
|
+
const { Row, List } = atoms;
|
|
58
|
+
const { Popover } = components;
|
|
59
|
+
const ChevronRight = icons.chevronRight;
|
|
60
|
+
const anchor = useRef(null);
|
|
61
|
+
const pressedWith = useRef(null);
|
|
62
|
+
const open = flyouts.openId === id;
|
|
63
|
+
return (_jsxs("div", { ref: anchor, onPointerOver: flyouts.claim, onPointerDown: (event) => {
|
|
64
|
+
if (anchor.current?.contains(event.target))
|
|
65
|
+
pressedWith.current = event.pointerType;
|
|
66
|
+
}, onMouseEnter: () => flyouts.hoverTo(id), onMouseLeave: () => {
|
|
67
|
+
pressedWith.current = null;
|
|
68
|
+
flyouts.cancelHover();
|
|
69
|
+
}, children: [_jsx(Row, { label: label, detail: detail, leading: leading, title: title, opens: true, open: open, trailing: _jsx(ChevronRight, { className: "size-3.5 shrink-0 text-(color:--vk-fg-subtlest)" }), onClick: () => {
|
|
70
|
+
const pointer = pressedWith.current;
|
|
71
|
+
pressedWith.current = null;
|
|
72
|
+
if (pointer === "mouse")
|
|
73
|
+
flyouts.open(id);
|
|
74
|
+
else
|
|
75
|
+
flyouts.toggle(id);
|
|
76
|
+
} }), _jsx(Popover, { open: open, onOpenChange: (next) => {
|
|
77
|
+
if (!next && flyouts.openId === id)
|
|
78
|
+
flyouts.close();
|
|
79
|
+
}, anchor: anchor, side: "right", align: "start", sideOffset: -2, alignOffset: -4, initialFocus: false, chrome: "menu", panelData: { "data-slot": "vk-grid-flyout" }, className: "min-w-32 max-w-80", onOutsidePress: (event) => anchor.current?.contains(event.target) ? false : undefined, children: _jsx(List, { children: children }) })] }));
|
|
80
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { ListGroup } from "../../grouping/types.js";
|
|
3
|
+
import { type DisplayCurrency } from "../../fields/currency.js";
|
|
4
|
+
import type { ListAggregateKind, ListColumn } from "../../model/column-schema.js";
|
|
5
|
+
import type { ListNumberFormatOverrides } from "../../model/column-format.js";
|
|
6
|
+
export declare function GridFooter<Row>({ group, columns, gridTemplate, selecting, aggregates, numberFormats, renderAggregate, onAggregateChange, viewBacked, frozenCount, frozenLeft, continuation, defaultCurrency, }: {
|
|
7
|
+
group: ListGroup<Row>;
|
|
8
|
+
columns: ListColumn<Row>[];
|
|
9
|
+
gridTemplate: string;
|
|
10
|
+
selecting: boolean;
|
|
11
|
+
aggregates?: Record<string, ListAggregateKind>;
|
|
12
|
+
numberFormats?: ListNumberFormatOverrides;
|
|
13
|
+
renderAggregate?: (columnId: string, group: ListGroup<Row>) => ReactNode;
|
|
14
|
+
onAggregateChange?: (columnId: string, kind: ListAggregateKind) => void;
|
|
15
|
+
viewBacked?: boolean;
|
|
16
|
+
/** How many LEADING columns are pinned to the left edge (0 = nothing). */
|
|
17
|
+
frozenCount?: number;
|
|
18
|
+
/** Sticky `left` for the frozen column at visible index i. */
|
|
19
|
+
frozenLeft?: (i: number) => string;
|
|
20
|
+
continuation?: ReactNode;
|
|
21
|
+
/** The reader's default currency (the host's answer): a money column read in Original totals in it. */
|
|
22
|
+
defaultCurrency?: DisplayCurrency;
|
|
23
|
+
}): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
|