@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,81 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { cx } from "../../internal/cx.js";
|
|
4
|
+
import { CellSuffix } from "../../display/format.js";
|
|
5
|
+
import { figureFor, ratioFigure } from "../../figures.js";
|
|
6
|
+
import { aggregateLabel, aggregateOptions, computeAggregate, figureKeyOf, moneyFigureCode, moneyTotal, resolveAggregateKind, } from "../../model/aggregates.js";
|
|
7
|
+
import { DEFAULT_DISPLAY_CURRENCY } from "../../fields/currency.js";
|
|
8
|
+
import { fieldTypeOf } from "../../model/field-type-of.js";
|
|
9
|
+
import { fieldKeyOf } from "../../model/view-rules.js";
|
|
10
|
+
import { formatNumber } from "./cells.js";
|
|
11
|
+
import { useCellFormat } from "../../cells/use-cell-format.js";
|
|
12
|
+
import { useViews } from "../../provider/context.js";
|
|
13
|
+
import { GridAggregateMenu } from "./GridAggregateMenu.js";
|
|
14
|
+
import { GridRailSpacer } from "./checks.js";
|
|
15
|
+
import { GRID_CONTENT_PAD, GRID_GROUND } from "./grid-styles.js";
|
|
16
|
+
export function GridFooter({ group, columns, gridTemplate, selecting, aggregates, numberFormats, renderAggregate, onAggregateChange, viewBacked = false, frozenCount = 0, frozenLeft, continuation, defaultCurrency = DEFAULT_DISPLAY_CURRENCY, }) {
|
|
17
|
+
const interactive = !!onAggregateChange;
|
|
18
|
+
const cellFormat = useCellFormat();
|
|
19
|
+
const { messages } = useViews();
|
|
20
|
+
const hostCells = columns.map((column) => renderAggregate?.(column.id, group) ?? null);
|
|
21
|
+
const sourced = group.figures
|
|
22
|
+
? { totalled: new Set(Object.keys(group.figures.fields)), defaultCurrency }
|
|
23
|
+
: undefined;
|
|
24
|
+
if (!interactive && hostCells.every((cell) => cell == null))
|
|
25
|
+
return continuation;
|
|
26
|
+
const footer = (_jsxs("div", { "data-slot": "vk-grid-footer", className: cx("grid", GRID_CONTENT_PAD), style: { gridTemplateColumns: gridTemplate }, children: [_jsx(GridRailSpacer, { selecting: selecting }), columns.map((column, index) => {
|
|
27
|
+
const kind = resolveAggregateKind(column, aggregates, sourced);
|
|
28
|
+
const columnInteractive = interactive && (!viewBacked || column.field != null);
|
|
29
|
+
const host = hostCells[index];
|
|
30
|
+
const ratioParts = column.field?.type === "formula" ? column.field.ratio : undefined;
|
|
31
|
+
const fromSource = host == null && kind !== "none" && group.figures
|
|
32
|
+
? kind === "ratio" && ratioParts
|
|
33
|
+
? ratioFigure(group.figures, ratioParts.numerator, ratioParts.denominator)
|
|
34
|
+
: figureFor(kind, group.figures, figureKeyOf(column, defaultCurrency))
|
|
35
|
+
: undefined;
|
|
36
|
+
const money = host == null && kind !== "none" && !group.figures
|
|
37
|
+
? moneyTotal(kind, column, group.items, defaultCurrency)
|
|
38
|
+
: undefined;
|
|
39
|
+
const computed = host == null && kind !== "none" && !group.figures && money === undefined
|
|
40
|
+
? computeAggregate(kind, column, group.items)
|
|
41
|
+
: null;
|
|
42
|
+
const countLike = kind === "count" || kind === "filled" || kind === "unique";
|
|
43
|
+
const decimals = numberFormats?.[fieldKeyOf(column)]?.decimals;
|
|
44
|
+
const sourceCode = fromSource != null && !countLike && fieldTypeOf(column) === "currency"
|
|
45
|
+
? moneyFigureCode(column, defaultCurrency)
|
|
46
|
+
: undefined;
|
|
47
|
+
const value = host != null
|
|
48
|
+
? host
|
|
49
|
+
: fromSource !== undefined
|
|
50
|
+
? fromSource == null || sourceCode === null
|
|
51
|
+
? null
|
|
52
|
+
: countLike
|
|
53
|
+
? String(fromSource)
|
|
54
|
+
: formatNumber(fromSource, column, {
|
|
55
|
+
...cellFormat,
|
|
56
|
+
decimals,
|
|
57
|
+
currency: sourceCode,
|
|
58
|
+
})
|
|
59
|
+
: money
|
|
60
|
+
? formatNumber(money.amount, column, {
|
|
61
|
+
...cellFormat,
|
|
62
|
+
decimals,
|
|
63
|
+
currency: money.code,
|
|
64
|
+
})
|
|
65
|
+
: computed != null
|
|
66
|
+
? countLike
|
|
67
|
+
? String(computed)
|
|
68
|
+
: formatNumber(computed, column, { ...cellFormat, decimals })
|
|
69
|
+
: null;
|
|
70
|
+
const label = host == null && kind !== "none" ? aggregateLabel(kind, messages) : null;
|
|
71
|
+
const suffix = host == null && column.aggregateSuffix && !countLike && kind !== "ratio"
|
|
72
|
+
? column.aggregateSuffix
|
|
73
|
+
: null;
|
|
74
|
+
const frozen = index < frozenCount && !!frozenLeft;
|
|
75
|
+
const cell = (_jsx("div", { "data-slot": "vk-grid-footer-cell", style: frozen ? { left: frozenLeft(index) } : undefined, className: cx("group/gridagg flex h-(--vk-footer-h) min-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap px-(--vk-px)", column.align === "right" && "justify-end", column.align === "center" && "justify-center", columnInteractive && "cursor-pointer select-none hover:bg-(color:--vk-hovered)", frozen ? cx("sticky z-7", GRID_GROUND) : "relative"), children: value != null ? (_jsxs(_Fragment, { children: [label && (_jsx("span", { className: "text-(length:--vk-text-10) uppercase tracking-wide text-(color:--vk-fg-subtlest)", children: label })), _jsxs("span", { className: "text-(length:--vk-text) font-medium tabular-nums", children: [value, suffix && _jsx(CellSuffix, { children: suffix })] })] })) : columnInteractive ? (_jsx("span", { className: "text-(length:--vk-text-10) uppercase tracking-wide text-(color:--vk-fg-subtlest) opacity-0 group-hover/gridagg:opacity-100", children: messages({ key: "views.grid.figure-pick" }) })) : null }, column.id));
|
|
76
|
+
if (!columnInteractive)
|
|
77
|
+
return cell;
|
|
78
|
+
return (_jsx(GridAggregateMenu, { column: column, options: aggregateOptions(column, sourced), current: kind, onChange: (next) => onAggregateChange(column.id, next), align: column.align === "right" ? "end" : column.align === "center" ? "center" : "start", children: cell }, column.id));
|
|
79
|
+
}), _jsx("div", { "data-slot": "vk-grid-tail", className: "h-(--vk-footer-h)" })] }));
|
|
80
|
+
return (_jsxs(_Fragment, { children: [footer, continuation] }));
|
|
81
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { OrderDir } from "../../grouping/sort-groups.js";
|
|
3
|
+
import type { GridSortState } from "./GridColumnMenu.js";
|
|
4
|
+
import type { ListGroupSummaryPart } from "../../model/preferences.js";
|
|
5
|
+
/** A sortable column, mirrored from the list's SortConfig options. */
|
|
6
|
+
export type GridGroupSortOption = {
|
|
7
|
+
value: string;
|
|
8
|
+
label: string;
|
|
9
|
+
defaultDir?: OrderDir;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The group-header `…` menu — a second remote for the list's row sort (all
|
|
13
|
+
* groups at once), surfaced on the group band. Reveals on hover of the group
|
|
14
|
+
* label; opens the map's popover, in its slot, of the same sortable columns the
|
|
15
|
+
* view-options Sort panel drives. Clicks stop propagation so the group's
|
|
16
|
+
* collapse toggle stays put.
|
|
17
|
+
*/
|
|
18
|
+
export declare function GridGroupMenu({ sort, sortOptions, summary, onSummaryChange, figures, onHide, }: {
|
|
19
|
+
/** Absent when the list offers no row sort here — the menu then carries only
|
|
20
|
+
* what else it has (Hide group). */
|
|
21
|
+
sort?: GridSortState;
|
|
22
|
+
sortOptions: GridGroupSortOption[];
|
|
23
|
+
/** Hides this group in the view — what the host's group panel's eye does.
|
|
24
|
+
* Absent where a list cannot hide one. */
|
|
25
|
+
onHide?: () => void;
|
|
26
|
+
/** Which figures the group header shows next to the name. A SET — count and
|
|
27
|
+
* total answer different questions and are wanted together. */
|
|
28
|
+
summary?: ListGroupSummaryPart[];
|
|
29
|
+
onSummaryChange?: (part: ListGroupSummaryPart, next: boolean) => void;
|
|
30
|
+
/** The figures the header can show beside its count, in the list's order, each named by its COLUMN — "People",
|
|
31
|
+
* not "Total". A generic label made the option unreadable: you could not tell what a group would show
|
|
32
|
+
* without picking it and looking. None: no Show rows. */
|
|
33
|
+
figures?: {
|
|
34
|
+
part: ListGroupSummaryPart;
|
|
35
|
+
label: ReactNode;
|
|
36
|
+
}[];
|
|
37
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { useViews } from "../../provider/context.js";
|
|
5
|
+
import { cx } from "../../internal/cx.js";
|
|
6
|
+
import { GridMenuRow, GridMenuSeparator } from "./GridMenuRow.js";
|
|
7
|
+
import { GRID_MENU_SEARCH_AFTER, matchMenuOptions } from "./grid-menu-search.js";
|
|
8
|
+
const EYEBROW = "px-2 pb-1 pt-2 text-[11px] font-medium uppercase tracking-wide text-(color:--vk-fg-subtle)";
|
|
9
|
+
export function GridGroupMenu({ sort, sortOptions, summary, onSummaryChange, figures = [], onHide, }) {
|
|
10
|
+
const [open, setOpen] = useState(false);
|
|
11
|
+
const [anchor, setAnchor] = useState(null);
|
|
12
|
+
const { atoms, components, icons, messages } = useViews();
|
|
13
|
+
const { Popover, Command } = components;
|
|
14
|
+
const { List, Row, RowContent } = atoms;
|
|
15
|
+
const More = icons.more;
|
|
16
|
+
const [query, setQuery] = useState("");
|
|
17
|
+
const close = () => {
|
|
18
|
+
setOpen(false);
|
|
19
|
+
setQuery("");
|
|
20
|
+
};
|
|
21
|
+
const offered = sort ? sortOptions : [];
|
|
22
|
+
const searchable = offered.length > GRID_MENU_SEARCH_AFTER;
|
|
23
|
+
const sorts = matchMenuOptions(offered, query);
|
|
24
|
+
const pick = (opt) => {
|
|
25
|
+
if (!sort)
|
|
26
|
+
return;
|
|
27
|
+
const active = sort.value === opt.value;
|
|
28
|
+
const dir = active
|
|
29
|
+
? sort.dir === "asc"
|
|
30
|
+
? "desc"
|
|
31
|
+
: "asc"
|
|
32
|
+
: (opt.defaultDir ?? "asc");
|
|
33
|
+
sort.onChange({ value: opt.value, dir });
|
|
34
|
+
close();
|
|
35
|
+
};
|
|
36
|
+
const sortGlyph = (opt) => {
|
|
37
|
+
const active = sort.value === opt.value;
|
|
38
|
+
const Glyph = active && sort.dir === "desc" ? icons.sortRowsDown : icons.sortRowsUp;
|
|
39
|
+
return (_jsx(Glyph, { className: cx("size-3.5", active ? "text-(color:--vk-fg-brand)" : "text-(color:--vk-fg-subtlest)") }));
|
|
40
|
+
};
|
|
41
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { ref: setAnchor, type: "button", "aria-label": messages({ key: "views.menus.group-options" }), "aria-haspopup": "dialog", "aria-expanded": open, onClick: (e) => {
|
|
42
|
+
e.stopPropagation();
|
|
43
|
+
if (open)
|
|
44
|
+
close();
|
|
45
|
+
else
|
|
46
|
+
setOpen(true);
|
|
47
|
+
}, className: cx("inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-(color:--vk-fg-subtle)", "transition-opacity hover:bg-(color:--vk-hovered) hover:text-(color:--vk-fg)", "md:opacity-0 md:group-hover/gridlabel:opacity-100 aria-expanded:opacity-100"), children: _jsx(More, { className: "h-3.5 w-3.5" }) }), _jsx(Popover, { open: open, onOpenChange: (next) => (next ? setOpen(true) : close()), anchor: anchor, side: "bottom", align: "start", sideOffset: 4, initialFocus: false, chrome: "menu", panelData: { "data-slot": "vk-grid-group-menu" }, onPanelClick: (e) => e.stopPropagation(), className: "w-52", onOutsidePress: (event) => (anchor?.contains(event.target) ? false : undefined), children: _jsxs(List, { children: [offered.length > 0 && _jsx("div", { className: EYEBROW, children: messages({ key: "views.menus.group-sort" }) }), searchable ? (_jsxs(Command.Root, { shouldFilter: false, loop: true, label: messages({ key: "views.menus.search" }), children: [_jsx(Command.Input, { value: query, onValueChange: setQuery, placeholder: messages({ key: "views.menus.search" }) }), _jsx(Command.List, { className: "max-h-64 overscroll-contain", children: _jsx(Command.Group, { className: "p-0", children: sorts.map((opt) => {
|
|
48
|
+
const active = sort.value === opt.value;
|
|
49
|
+
return (_jsx(Command.Item, { value: opt.value, onSelect: () => pick(opt), chosen: active, children: _jsx(RowContent, { label: opt.label, leading: sortGlyph(opt), chosen: active }) }, opt.value));
|
|
50
|
+
}) }) })] })) : (sorts.map((opt) => (_jsx(Row, { chosen: sort.value === opt.value, label: opt.label, leading: sortGlyph(opt), onClick: () => pick(opt) }, opt.value)))), figures.length > 0 && onSummaryChange && (_jsxs(_Fragment, { children: [offered.length > 0 && _jsx(GridMenuSeparator, {}), _jsx("div", { className: EYEBROW, children: messages({ key: "views.menus.group-show" }) }), [
|
|
51
|
+
{ part: "count", label: messages({ key: "views.menus.group-count" }) },
|
|
52
|
+
...figures,
|
|
53
|
+
].map((s) => (_jsx(Row, { chosen: (summary ?? []).includes(s.part), label: s.label, onClick: () => onSummaryChange(s.part, !(summary ?? []).includes(s.part)) }, s.part)))] })), onHide && (_jsxs(_Fragment, { children: [(offered.length > 0 || (figures.length > 0 && onSummaryChange)) && _jsx(GridMenuSeparator, {}), _jsx(GridMenuRow, { label: messages({ key: "views.menus.group-hide" }), icon: "hide", onClick: () => {
|
|
54
|
+
onHide();
|
|
55
|
+
close();
|
|
56
|
+
} })] }))] }) })] }));
|
|
57
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { ListColumnsConfig } from "../../model/column-state.js";
|
|
3
|
+
import type { ListSettingsConfig } from "../../model/column-capabilities.js";
|
|
4
|
+
import type { ListColumn, ListOptionColorOverrides, ListSelectColor } from "../../model/column-schema.js";
|
|
5
|
+
import type { ListDateStyle, ListDateStyleOverrides, ListDurationStyle, ListDurationStyleOverrides, ListNumberFormatOverrides, ListPercentDisplayOverrides, ListShowTimeOverrides } from "../../model/column-format.js";
|
|
6
|
+
import type { PercentDisplay } from "@viewkitjs/fields";
|
|
7
|
+
import { type GridGroupByState, type GridSortState } from "./GridColumnMenu.js";
|
|
8
|
+
import type { useHeaderDragReorder } from "./useHeaderDragReorder.js";
|
|
9
|
+
type HeaderDrag = ReturnType<typeof useHeaderDragReorder>;
|
|
10
|
+
export declare function GridHeader<Row>({ inline, showAddColumn, checkbox, columns, columnManager, gridTemplate, minWidth, sort, selectValues, optionColors, onOptionColorChange, dateStyles, onDateStyleChange, durationStyles, onDurationStyleChange, numberFormats, onNumberFormatChange, showTimeOverrides, onShowTimeChange, percentDisplays, onPercentDisplayChange, columnStateEnabled, listConfig, groupBy, resizingId, startResize, moveResize, endResize, resetColumnWidth, hideColumn, moveColumn, headerDrag, registerHeader, frozenCount, frozenLeft, viewBacked, formatsWritable, renderAddColumn, renderColumnMenuRows, }: {
|
|
11
|
+
inline: boolean;
|
|
12
|
+
/** The table sized the tail for "+ Add column": the desktop strip of a grid with column state. */
|
|
13
|
+
showAddColumn?: boolean;
|
|
14
|
+
checkbox?: ReactNode;
|
|
15
|
+
columns: ListColumn<Row>[];
|
|
16
|
+
columnManager: ListColumnsConfig | null;
|
|
17
|
+
gridTemplate: string;
|
|
18
|
+
minWidth: string;
|
|
19
|
+
sort?: GridSortState;
|
|
20
|
+
selectValues: Record<string, string[]>;
|
|
21
|
+
optionColors?: ListOptionColorOverrides;
|
|
22
|
+
onOptionColorChange?: (key: string, value: string, color: ListSelectColor | null) => void;
|
|
23
|
+
dateStyles?: ListDateStyleOverrides;
|
|
24
|
+
onDateStyleChange?: (key: string, style: ListDateStyle) => void;
|
|
25
|
+
durationStyles?: ListDurationStyleOverrides;
|
|
26
|
+
onDurationStyleChange?: (key: string, style: ListDurationStyle) => void;
|
|
27
|
+
numberFormats?: ListNumberFormatOverrides;
|
|
28
|
+
onNumberFormatChange?: (key: string, patch: {
|
|
29
|
+
decimals?: number | null;
|
|
30
|
+
currency?: string;
|
|
31
|
+
}) => void;
|
|
32
|
+
showTimeOverrides?: ListShowTimeOverrides;
|
|
33
|
+
onShowTimeChange?: (key: string, show: boolean) => void;
|
|
34
|
+
percentDisplays?: ListPercentDisplayOverrides;
|
|
35
|
+
onPercentDisplayChange?: (key: string, display: PercentDisplay) => void;
|
|
36
|
+
columnStateEnabled: boolean;
|
|
37
|
+
/** Workspace list config — the read-only indicator reads its `readOnly`. */
|
|
38
|
+
listConfig?: ListSettingsConfig;
|
|
39
|
+
/** The view's group, for the header menu's Group by / Ungroup row. */
|
|
40
|
+
groupBy?: GridGroupByState;
|
|
41
|
+
resizingId: string | null;
|
|
42
|
+
startResize: (column: ListColumn<Row>, event: React.PointerEvent<HTMLElement>) => void;
|
|
43
|
+
moveResize: (event: React.PointerEvent<HTMLElement>) => void;
|
|
44
|
+
endResize: () => void;
|
|
45
|
+
resetColumnWidth: (column: ListColumn<Row>) => void;
|
|
46
|
+
hideColumn: (column: ListColumn<Row>) => void;
|
|
47
|
+
moveColumn: (column: ListColumn<Row>, direction: -1 | 1) => void;
|
|
48
|
+
headerDrag: HeaderDrag;
|
|
49
|
+
registerHeader: (element: HTMLElement | null) => (() => void) | undefined;
|
|
50
|
+
/** How many LEADING columns are pinned to the left edge (0 = nothing). */
|
|
51
|
+
frozenCount?: number;
|
|
52
|
+
/** Sticky `left` for the frozen column at visible index i — a calc() over the
|
|
53
|
+
* width vars, so live resize re-lays the frozen stack without React. */
|
|
54
|
+
frozenLeft?: (i: number) => string;
|
|
55
|
+
viewBacked?: boolean;
|
|
56
|
+
/** The host's rules and slots, passed on from the grid's props (grid-table-props). */
|
|
57
|
+
formatsWritable?: boolean;
|
|
58
|
+
renderAddColumn?: (columns: ListColumnsConfig) => ReactNode;
|
|
59
|
+
renderColumnMenuRows?: (fieldKey: string, close: () => void) => ReactNode;
|
|
60
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { cx } from "../../internal/cx.js";
|
|
4
|
+
import { columnHideable } from "../../model/column-state.js";
|
|
5
|
+
import { fieldKeyOf } from "../../model/view-rules.js";
|
|
6
|
+
import { GridFrozenShadow } from "./GridCellOutline.js";
|
|
7
|
+
import { GridRailSpacer } from "./checks.js";
|
|
8
|
+
import { GridAddColumn } from "./GridAddColumn.js";
|
|
9
|
+
import { GridColumnMenu, gridColumnMenuEnabled, } from "./GridColumnMenu.js";
|
|
10
|
+
import { GridResizeHandle } from "./GridResizeHandle.js";
|
|
11
|
+
import { GRID_BLEED, GRID_CONTENT_PAD, GRID_HEADER_BG, GRID_HEADER_BG_FROZEN, GRID_HEADER_BG_FROZEN_HOVER, } from "./grid-styles.js";
|
|
12
|
+
import { useViews } from "../../provider/context.js";
|
|
13
|
+
import { gridColumnGlyph } from "./column-glyph.js";
|
|
14
|
+
import { columnPlacedByView } from "../../model/column-capabilities.js";
|
|
15
|
+
export function GridHeader({ inline, showAddColumn = false, checkbox, columns, columnManager, gridTemplate, minWidth, sort, selectValues, optionColors, onOptionColorChange, dateStyles, onDateStyleChange, durationStyles, onDurationStyleChange, numberFormats, onNumberFormatChange, showTimeOverrides, onShowTimeChange, percentDisplays, onPercentDisplayChange, columnStateEnabled, listConfig, groupBy, resizingId, startResize, moveResize, endResize, resetColumnWidth, hideColumn, moveColumn, headerDrag, registerHeader, frozenCount = 0, frozenLeft, viewBacked = false, formatsWritable, renderAddColumn, renderColumnMenuRows, }) {
|
|
16
|
+
const { icons, components, messages } = useViews();
|
|
17
|
+
const addColumn = columnManager && showAddColumn
|
|
18
|
+
? renderAddColumn?.(columnManager) || _jsx(GridAddColumn, { columns: columnManager })
|
|
19
|
+
: null;
|
|
20
|
+
const cells = (_jsxs(_Fragment, { children: [checkbox ?? _jsx(GridRailSpacer, { selecting: false, bordered: true }), columns.map((column, index) => {
|
|
21
|
+
const canMove = columnStateEnabled && (!viewBacked || columnPlacedByView(column));
|
|
22
|
+
const canHide = canMove && columnHideable(column) && columns.length > 1;
|
|
23
|
+
const menuEnabled = gridColumnMenuEnabled(column);
|
|
24
|
+
const frozen = index < frozenCount && !!frozenLeft;
|
|
25
|
+
const cell = (_jsxs("div", { "data-slot": "vk-grid-header-cell", "data-headcell": column.id, style: {
|
|
26
|
+
...headerDrag.cellStyle(column.id, index),
|
|
27
|
+
...(frozen ? { left: frozenLeft(index) } : null),
|
|
28
|
+
}, onPointerDown: headerDrag.onCellPointerDown(column.id, index), onPointerMove: headerDrag.onCellPointerMove, onPointerUp: headerDrag.onCellPointerUp, onPointerCancel: headerDrag.onCellPointerCancel, onClickCapture: headerDrag.onCellClickCapture, className: cx("flex h-(--vk-head-h) min-w-0 select-none items-center gap-1.5 overflow-hidden whitespace-nowrap border-b border-(color:--vk-border-subtle) px-(--vk-px) text-(length:--vk-head-text) text-(color:--vk-fg-subtle)", !frozen && "hover:bg-(color:--vk-hovered)", column.align === "center" && "justify-center", menuEnabled ? "cursor-pointer" : "cursor-default", "translate-x-(--vk-drag-shift,0px)", frozen ? cx("sticky z-7", GRID_HEADER_BG_FROZEN, GRID_HEADER_BG_FROZEN_HOVER) : "relative"), children: [gridColumnGlyph({ icons, AppIcon: components.AppIcon }, column, "h-(--vk-head-glyph) w-(--vk-head-glyph) shrink-0 opacity-70"), column.header ? _jsx("span", { className: "truncate", children: column.header }) : null, columnStateEnabled && (_jsx(GridResizeHandle, { active: resizingId === column.id, onResizeStart: (event) => startResize(column, event), onResizeMove: moveResize, onResizeEnd: endResize, onReset: () => resetColumnWidth(column) }))] }, column.id));
|
|
29
|
+
if (!menuEnabled)
|
|
30
|
+
return cell;
|
|
31
|
+
return (_jsx(GridColumnMenu, { column: column, values: selectValues[column.id] ?? [], viewBacked: viewBacked, sort: sort, groupBy: groupBy, optionColors: optionColors?.[fieldKeyOf(column)], onOptionColorChange: onOptionColorChange, dateStyle: dateStyles?.[fieldKeyOf(column)], onDateStyleChange: onDateStyleChange, durationStyle: durationStyles?.[fieldKeyOf(column)], onDurationStyleChange: onDurationStyleChange, numberFormat: numberFormats?.[fieldKeyOf(column)], onNumberFormatChange: onNumberFormatChange, showTime: showTimeOverrides?.[fieldKeyOf(column)] ?? column.format?.withTime ?? false, onShowTimeChange: column.type === "datetime" ? onShowTimeChange : undefined, percentDisplay: percentDisplays?.[fieldKeyOf(column)], onPercentDisplayChange: onPercentDisplayChange, onMoveLeft: canMove && index > 0 ? () => moveColumn(column, -1) : undefined, onMoveRight: canMove && index < columns.length - 1 ? () => moveColumn(column, 1) : undefined, onHide: canHide ? () => hideColumn(column) : undefined, formatsWritable: formatsWritable, renderColumnMenuRows: renderColumnMenuRows, children: cell }, column.id));
|
|
32
|
+
}), _jsxs("div", { "data-slot": "vk-grid-tail", className: cx("flex h-(--vk-head-h) min-w-0 items-center gap-2 border-b border-(color:--vk-border-subtle)", addColumn ? "pl-0" : "pl-(--vk-px)"), children: [listConfig?.readOnly && (_jsxs("span", { title: messages({ key: "views.grid.read-only-why" }), className: cx("inline-flex shrink-0 items-center gap-1 whitespace-nowrap text-(length:--vk-head-text) text-(color:--vk-fg-subtle)", !!addColumn && "pl-(--vk-px)"), children: [_jsx(icons.lock, { className: "h-3 w-3" }), messages({ key: "views.grid.read-only" })] })), addColumn && _jsx("div", { className: "flex h-full min-w-0 flex-1 items-stretch", children: addColumn })] })] }));
|
|
33
|
+
if (inline) {
|
|
34
|
+
return (_jsx("div", { "data-slot": "vk-grid-header", className: cx("group/gridhead grid", GRID_CONTENT_PAD), style: { gridTemplateColumns: gridTemplate, minWidth }, children: cells }));
|
|
35
|
+
}
|
|
36
|
+
return (_jsxs("div", { className: cx("group/gridhead relative", GRID_HEADER_BG, GRID_BLEED), children: [_jsx("div", { ref: registerHeader, className: "overflow-x-hidden", children: _jsx("div", { "data-slot": "vk-grid-header", className: cx("grid", GRID_CONTENT_PAD), style: { gridTemplateColumns: gridTemplate, minWidth }, children: cells }) }), _jsx(GridFrozenShadow, {})] }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The GRID's long-text panel — reading and editing a paragraph in ONE surface.
|
|
3
|
+
*
|
|
4
|
+
* A `format.long` text is a paragraph, and a paragraph in a 37px cell is one
|
|
5
|
+
* clipped line with no way in. So editing it does not swap the cell for a
|
|
6
|
+
* one-line input: it opens a panel ON the cell (top-left on the cell's
|
|
7
|
+
* top-left, the column's width) holding the whole value in a textarea, the
|
|
8
|
+
* caret at the end — Attio's model. Inspection is the same panel with the
|
|
9
|
+
* textarea read-only: the value is selectable, copyable, and never written.
|
|
10
|
+
*
|
|
11
|
+
* Anchored like the select and date editors: the cell's own content stays on
|
|
12
|
+
* screen behind the popover, `useAnchoredEditSession` owns the one-answer
|
|
13
|
+
* guard and the exit gap, and Radix owns the viewport — with no room below
|
|
14
|
+
* the panel opens above the cell.
|
|
15
|
+
*
|
|
16
|
+
* Keys are a paragraph's: Enter is a newline; ⌘-Enter commits and advances;
|
|
17
|
+
* Tab commits and moves; Escape cancels; an outside click commits. The host
|
|
18
|
+
* grid's click-away listener clears the cell's focus after that commit.
|
|
19
|
+
*/
|
|
20
|
+
export declare function GridLongTextEditor({ initial, seed, readOnly, markdown, onCommit, onCancel, onTab, onEnter, }: {
|
|
21
|
+
/** The stored value the session opens on ("" when unset). */
|
|
22
|
+
initial: string;
|
|
23
|
+
/** Type-to-replace: the character that opened this editor replaces the value. */
|
|
24
|
+
seed?: string;
|
|
25
|
+
/** Inspection: the panel shows the value, selectable, and never commits. */
|
|
26
|
+
readOnly?: boolean;
|
|
27
|
+
/** Markdown keeps its first line's indent: it is tidied only at its edges
|
|
28
|
+
* (`normalizeMarkdown`), where plain long text is trimmed. */
|
|
29
|
+
markdown?: boolean;
|
|
30
|
+
onCommit: (value: string) => void;
|
|
31
|
+
onCancel: () => void;
|
|
32
|
+
/** Commit happened via Tab — move to the next cell in reading order. */
|
|
33
|
+
onTab?: (backwards: boolean) => void;
|
|
34
|
+
/** Commit happened via ⌘-Enter — advance one row down. */
|
|
35
|
+
onEnter?: () => void;
|
|
36
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
4
|
+
import { useAnchoredEditSession } from "../../editors/edit-session.js";
|
|
5
|
+
import { useViews } from "../../provider/context.js";
|
|
6
|
+
import { cx } from "../../internal/cx.js";
|
|
7
|
+
import { normalizeMarkdown } from "@viewkitjs/fields";
|
|
8
|
+
const MIN_W = 320;
|
|
9
|
+
const MAX_W = 512;
|
|
10
|
+
const MAX_LINES = 12;
|
|
11
|
+
export function GridLongTextEditor({ initial, seed, readOnly = false, markdown = false, onCommit, onCancel, onTab, onEnter, }) {
|
|
12
|
+
const { components, messages } = useViews();
|
|
13
|
+
const { Popover } = components;
|
|
14
|
+
const anchorRef = useRef(null);
|
|
15
|
+
const areaRef = useRef(null);
|
|
16
|
+
const [cell, setCell] = useState(null);
|
|
17
|
+
useLayoutEffect(() => {
|
|
18
|
+
const anchor = anchorRef.current;
|
|
19
|
+
if (anchor)
|
|
20
|
+
setCell(measureCell(anchor));
|
|
21
|
+
}, []);
|
|
22
|
+
const handleRef = useRef({
|
|
23
|
+
resolveClose: (reason) => {
|
|
24
|
+
if (readOnly)
|
|
25
|
+
return { kind: "noop" };
|
|
26
|
+
if (reason === "escape")
|
|
27
|
+
return { kind: "cancel" };
|
|
28
|
+
const tidy = markdown ? normalizeMarkdown : (text) => text.trim();
|
|
29
|
+
const next = tidy(areaRef.current?.value ?? "");
|
|
30
|
+
return next === tidy(initial) ? { kind: "noop" } : { kind: "commit", payload: next };
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
const viaRef = useRef(null);
|
|
34
|
+
const { open, close } = useAnchoredEditSession({
|
|
35
|
+
editorRef: handleRef,
|
|
36
|
+
onDone: (resolution) => {
|
|
37
|
+
if (resolution.kind === "commit") {
|
|
38
|
+
onCommit(resolution.payload);
|
|
39
|
+
if (viaRef.current === "enter")
|
|
40
|
+
onEnter?.();
|
|
41
|
+
if (viaRef.current === "tab")
|
|
42
|
+
onTab?.(false);
|
|
43
|
+
if (viaRef.current === "shift-tab")
|
|
44
|
+
onTab?.(true);
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
onCancel();
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
const closeVia = (reason) => {
|
|
51
|
+
viaRef.current = reason;
|
|
52
|
+
close(reason);
|
|
53
|
+
};
|
|
54
|
+
const attach = useCallback((el) => {
|
|
55
|
+
areaRef.current = el;
|
|
56
|
+
if (!el)
|
|
57
|
+
return;
|
|
58
|
+
el.focus({ preventScroll: true });
|
|
59
|
+
el.setSelectionRange(el.value.length, el.value.length);
|
|
60
|
+
grow(el);
|
|
61
|
+
}, []);
|
|
62
|
+
const onKeyDown = (event) => {
|
|
63
|
+
event.stopPropagation();
|
|
64
|
+
if (event.key === "Escape") {
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
closeVia("escape");
|
|
67
|
+
}
|
|
68
|
+
else if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
closeVia("enter");
|
|
71
|
+
}
|
|
72
|
+
else if (event.key === "Tab") {
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
closeVia(event.shiftKey ? "shift-tab" : "tab");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const width = cell ? Math.min(MAX_W, Math.max(MIN_W, cell.width)) : MIN_W;
|
|
78
|
+
const padY = cell ? Math.max(0, (cell.height - cell.lineHeight) / 2 - 1) : 8;
|
|
79
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(Popover, { open: open, onOpenChange: (next) => {
|
|
80
|
+
if (!next)
|
|
81
|
+
closeVia("outside");
|
|
82
|
+
}, anchor: anchorRef, align: "start", sideOffset: cell ? -cell.height : 0, onEscape: () => closeVia("escape"), onOutsidePress: () => closeVia("outside"), initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: cx("z-90 rounded-sm p-0", readOnly ? "border-(color:--vk-border)" : "border-(color:--vk-border-brand)"), style: { width }, children: _jsx("textarea", { ref: attach, "data-grid-editor": true, "aria-label": messages({ key: readOnly ? "views.grid.value" : "views.grid.edit-value" }), defaultValue: seed ?? initial, readOnly: readOnly, rows: 1, onKeyDown: onKeyDown, onInput: (e) => grow(e.currentTarget), style: cell
|
|
83
|
+
? {
|
|
84
|
+
paddingLeft: cell.paddingX,
|
|
85
|
+
paddingRight: cell.paddingX,
|
|
86
|
+
paddingTop: padY,
|
|
87
|
+
paddingBottom: padY,
|
|
88
|
+
fontSize: cell.fontSize,
|
|
89
|
+
lineHeight: `${cell.lineHeight}px`,
|
|
90
|
+
}
|
|
91
|
+
: undefined, className: cx("block w-full resize-none select-text bg-transparent text-(color:--vk-fg) outline-hidden", "overflow-y-auto overscroll-contain") }) })] }));
|
|
92
|
+
}
|
|
93
|
+
function measureCell(anchor) {
|
|
94
|
+
const box = anchor.getBoundingClientRect();
|
|
95
|
+
const cell = anchor.parentElement ?? anchor;
|
|
96
|
+
const style = getComputedStyle(cell);
|
|
97
|
+
const lineVar = style.getPropertyValue("--vk-line-h").trim();
|
|
98
|
+
return {
|
|
99
|
+
width: box.width,
|
|
100
|
+
height: box.height,
|
|
101
|
+
paddingX: parseFloat(style.paddingLeft) || 12,
|
|
102
|
+
fontSize: style.fontSize || "14px",
|
|
103
|
+
lineHeight: resolveLength(cell, lineVar) || 22,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function resolveLength(host, value) {
|
|
107
|
+
if (!value)
|
|
108
|
+
return 0;
|
|
109
|
+
const direct = parseFloat(value);
|
|
110
|
+
if (!Number.isNaN(direct) && /^-?[\d.]+px$/.test(value))
|
|
111
|
+
return direct;
|
|
112
|
+
const probe = document.createElement("div");
|
|
113
|
+
probe.style.position = "absolute";
|
|
114
|
+
probe.style.visibility = "hidden";
|
|
115
|
+
probe.style.height = value;
|
|
116
|
+
host.appendChild(probe);
|
|
117
|
+
const px = probe.getBoundingClientRect().height;
|
|
118
|
+
host.removeChild(probe);
|
|
119
|
+
return px;
|
|
120
|
+
}
|
|
121
|
+
function grow(el) {
|
|
122
|
+
el.style.height = "auto";
|
|
123
|
+
const style = getComputedStyle(el);
|
|
124
|
+
const line = parseFloat(style.lineHeight) || 22;
|
|
125
|
+
const pad = (parseFloat(style.paddingTop) || 0) + (parseFloat(style.paddingBottom) || 0);
|
|
126
|
+
el.style.height = `${Math.min(el.scrollHeight, line * MAX_LINES + pad)}px`;
|
|
127
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { ViewsIconName } from "../../contract.js";
|
|
3
|
+
/** A knob row's leading glyph, by meaning, in the subtle ink every verb row's glyph wears at rest. */
|
|
4
|
+
export declare function KnobGlyph({ name }: {
|
|
5
|
+
name: ViewsIconName;
|
|
6
|
+
}): ReactElement;
|
|
7
|
+
/** One verb row in a grid menu: a glyph, a label, the chosen mark while active (its glyph then in the brand ink). */
|
|
8
|
+
export declare function GridMenuRow({ label, icon, onClick, active, }: {
|
|
9
|
+
label: string;
|
|
10
|
+
icon: ViewsIconName;
|
|
11
|
+
onClick: () => void;
|
|
12
|
+
active?: boolean;
|
|
13
|
+
}): ReactElement;
|
|
14
|
+
/** The divider between a grid menu's blocks. */
|
|
15
|
+
export declare function GridMenuSeparator(): ReactElement;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useViews } from "../../provider/context.js";
|
|
4
|
+
export function KnobGlyph({ name }) {
|
|
5
|
+
const Glyph = useViews().icons[name];
|
|
6
|
+
return _jsx(Glyph, { className: "size-4 text-(color:--vk-fg-subtle)" });
|
|
7
|
+
}
|
|
8
|
+
export function GridMenuRow({ label, icon, onClick, active = false, }) {
|
|
9
|
+
const { atoms, icons } = useViews();
|
|
10
|
+
const Glyph = icons[icon];
|
|
11
|
+
return (_jsx(atoms.Row, { label: label, chosen: active, leading: _jsx(Glyph, { className: active ? "size-4 text-(color:--vk-fg-brand)" : "size-4 text-(color:--vk-fg-subtle)" }), onClick: onClick }));
|
|
12
|
+
}
|
|
13
|
+
export function GridMenuSeparator() {
|
|
14
|
+
return _jsx("div", { role: "separator", className: "-mx-1 my-1.5 h-px bg-(color:--vk-border)" });
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { NameValue } from "@viewkitjs/fields";
|
|
2
|
+
/**
|
|
3
|
+
* The GRID's host around the shared `NameEditor`. Anchored, like the select and
|
|
4
|
+
* date editors: three boxes do not fit a cell, so they open in a panel under it
|
|
5
|
+
* while the cell's own name stays on screen. `useAnchoredEditSession` owns the
|
|
6
|
+
* one-answer guard and the exit gap; the core's own blur ends the session,
|
|
7
|
+
* since a blur onto another box is not a close.
|
|
8
|
+
*/
|
|
9
|
+
export declare function GridNameEditor({ initial, seed, allowEmpty, onCommit, onCancel, onTab, onEnter, }: {
|
|
10
|
+
initial: NameValue | null;
|
|
11
|
+
/** Type-to-replace: the character that opened this editor replaces the given box. */
|
|
12
|
+
seed?: string;
|
|
13
|
+
allowEmpty?: boolean;
|
|
14
|
+
onCommit: (payload: NameValue | null) => void;
|
|
15
|
+
onCancel: () => void;
|
|
16
|
+
onTab?: (backwards: boolean) => void;
|
|
17
|
+
/** Commit happened via Enter — advance one row down. */
|
|
18
|
+
onEnter?: () => void;
|
|
19
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import { useAnchoredEditSession } from "../../editors/edit-session.js";
|
|
5
|
+
import { NameEditor } from "../../editors/NameEditor.js";
|
|
6
|
+
import { useViews } from "../../provider/context.js";
|
|
7
|
+
export function GridNameEditor({ initial, seed, allowEmpty = false, onCommit, onCancel, onTab, onEnter, }) {
|
|
8
|
+
const { Popover } = useViews().components;
|
|
9
|
+
const anchorRef = useRef(null);
|
|
10
|
+
const editorRef = useRef(null);
|
|
11
|
+
const viaRef = useRef(null);
|
|
12
|
+
const { open, close } = useAnchoredEditSession({
|
|
13
|
+
editorRef,
|
|
14
|
+
onDone: (resolution) => {
|
|
15
|
+
if (resolution.kind === "commit") {
|
|
16
|
+
onCommit(resolution.payload);
|
|
17
|
+
if (viaRef.current === "enter")
|
|
18
|
+
onEnter?.();
|
|
19
|
+
if (viaRef.current === "tab")
|
|
20
|
+
onTab?.(false);
|
|
21
|
+
if (viaRef.current === "shift-tab")
|
|
22
|
+
onTab?.(true);
|
|
23
|
+
}
|
|
24
|
+
else
|
|
25
|
+
onCancel();
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const closeVia = (reason) => {
|
|
29
|
+
viaRef.current = reason;
|
|
30
|
+
close(reason);
|
|
31
|
+
};
|
|
32
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(Popover, { open: open, onOpenChange: (next) => {
|
|
33
|
+
if (!next)
|
|
34
|
+
closeVia("outside");
|
|
35
|
+
}, anchor: anchorRef, align: "start", sideOffset: 4, onEscape: () => closeVia("escape"), onOutsidePress: () => closeVia("outside"), initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "z-90 w-80 p-2", children: _jsx(NameEditor, { ref: editorRef, initial: initial, seed: seed, allowEmpty: allowEmpty, onRequestClose: closeVia }) })] }));
|
|
36
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { DurationUnit } from "@viewkitjs/fields/query";
|
|
2
|
+
import type { GridNumberEditValue } from "../core/edit-values.js";
|
|
3
|
+
/**
|
|
4
|
+
* The GRID's host around the shared `NumberEditor` (`@viewkitjs/views/editors/number`) —
|
|
5
|
+
* the typed field and its unit chip are one component across every surface;
|
|
6
|
+
* this host owns only the grid's mechanics: WHICH close happened, the write,
|
|
7
|
+
* and the focus move that follows it.
|
|
8
|
+
*
|
|
9
|
+
* No exit gap, unlike the anchored editors: this one is INLINE — it replaces
|
|
10
|
+
* the cell's content rather than opening a popover over it, so there is no
|
|
11
|
+
* animation to play out and the commit lands at once, before the focus moves.
|
|
12
|
+
*/
|
|
13
|
+
export declare function GridNumberEditor({ initial, seed, unit, unitOptions, decimals, durationUnit, allowEmpty, unitLeft, onCommit, onCancel, onTab, onEnter, }: {
|
|
14
|
+
/** Signed raw value (e.g. -47.50 for an "out" transaction in its own currency). */
|
|
15
|
+
initial: number;
|
|
16
|
+
/** Type-to-replace: the character that opened this editor. */
|
|
17
|
+
seed?: string;
|
|
18
|
+
/** The row's current unit (currency). Undefined = plain number, no chip. */
|
|
19
|
+
unit?: string;
|
|
20
|
+
/** Selectable units — presence makes the chip a picker. */
|
|
21
|
+
unitOptions?: string[];
|
|
22
|
+
/** Rounding + initial formatting precision. */
|
|
23
|
+
decimals?: number;
|
|
24
|
+
/** A duration column's STORED unit — the core edits it as human text. */
|
|
25
|
+
durationUnit?: DurationUnit;
|
|
26
|
+
allowEmpty?: boolean;
|
|
27
|
+
/** Right-aligned columns put the chip on the LEFT so the number stays flush
|
|
28
|
+
* with the column's right edge. */
|
|
29
|
+
unitLeft?: boolean;
|
|
30
|
+
onCommit: (payload: GridNumberEditValue) => void;
|
|
31
|
+
onCancel: () => void;
|
|
32
|
+
onTab?: (backwards: boolean) => void;
|
|
33
|
+
/** Commit happened via Enter — advance one row down (Sheets). */
|
|
34
|
+
onEnter?: () => void;
|
|
35
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import { NumberEditor } from "../../editors/NumberEditor.js";
|
|
5
|
+
export function GridNumberEditor({ initial, seed, unit, unitOptions, decimals = 2, durationUnit, allowEmpty = false, unitLeft = false, onCommit, onCancel, onTab, onEnter, }) {
|
|
6
|
+
const editorRef = useRef(null);
|
|
7
|
+
const closedRef = useRef(false);
|
|
8
|
+
const close = (reason) => {
|
|
9
|
+
if (closedRef.current)
|
|
10
|
+
return;
|
|
11
|
+
closedRef.current = true;
|
|
12
|
+
const resolution = editorRef.current?.resolveClose(reason) ?? { kind: "noop" };
|
|
13
|
+
if (resolution.kind === "commit")
|
|
14
|
+
onCommit(resolution.payload);
|
|
15
|
+
else
|
|
16
|
+
onCancel();
|
|
17
|
+
if (reason === "enter")
|
|
18
|
+
onEnter?.();
|
|
19
|
+
if (reason === "tab")
|
|
20
|
+
onTab?.(false);
|
|
21
|
+
if (reason === "shift-tab")
|
|
22
|
+
onTab?.(true);
|
|
23
|
+
};
|
|
24
|
+
return (_jsx("span", { "data-slot": "vk-grid-editor", className: "flex h-full w-full min-w-0", children: _jsx(NumberEditor, { ref: editorRef, initial: initial, seed: seed, unit: unit, unitOptions: unitOptions, decimals: decimals, durationUnit: durationUnit, allowEmpty: allowEmpty, unitLeft: unitLeft, onRequestClose: close }) }));
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RangeValue } from "@viewkitjs/fields";
|
|
2
|
+
/**
|
|
3
|
+
* The GRID's host around the shared `RangeEditor` — inline, like the number
|
|
4
|
+
* host: the two boxes replace the cell's content, the write lands at once, and
|
|
5
|
+
* only then does focus move.
|
|
6
|
+
*/
|
|
7
|
+
export declare function GridRangeEditor({ initial, seed, decimals, allowEmpty, suffix, onCommit, onCancel, onTab, onEnter, }: {
|
|
8
|
+
initial: RangeValue | null;
|
|
9
|
+
/** Type-to-replace: the character that opened this editor replaces the low box. */
|
|
10
|
+
seed?: string;
|
|
11
|
+
decimals?: number;
|
|
12
|
+
allowEmpty?: boolean;
|
|
13
|
+
/** "%", a currency code — drawn after the high box. */
|
|
14
|
+
suffix?: string;
|
|
15
|
+
onCommit: (payload: RangeValue) => void;
|
|
16
|
+
onCancel: () => void;
|
|
17
|
+
onTab?: (backwards: boolean) => void;
|
|
18
|
+
/** Commit happened via Enter — advance one row down. */
|
|
19
|
+
onEnter?: () => void;
|
|
20
|
+
}): import("react/jsx-runtime").JSX.Element;
|