@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,59 @@
|
|
|
1
|
+
import type { FieldSettlement } from "@viewkitjs/fields";
|
|
2
|
+
/**
|
|
3
|
+
* One body cell's class string.
|
|
4
|
+
*
|
|
5
|
+
* Extracted from `GridRowCells` because that file is held under the line ceiling
|
|
6
|
+
* and the policy there is split, not raise — and because this is the one part
|
|
7
|
+
* of the cell that is pure: a dozen booleans in, a string out. That makes the
|
|
8
|
+
* geometry testable without rendering a grid, which matters most for the wrap
|
|
9
|
+
* mode, whose whole contract is "the unwrapped string is unchanged".
|
|
10
|
+
*/
|
|
11
|
+
export type GridCellClassState = {
|
|
12
|
+
align?: "left" | "center" | "right";
|
|
13
|
+
/** The title column: an ordinary cell that holds the row-open hotspot (its
|
|
14
|
+
* rendered text), which the cell dresses as a link. */
|
|
15
|
+
isTitle: boolean;
|
|
16
|
+
/** Pinned to the left edge (inside the frozen block). */
|
|
17
|
+
frozen: boolean;
|
|
18
|
+
focused: boolean;
|
|
19
|
+
editing: boolean;
|
|
20
|
+
/** Inside the active multi-cell range. */
|
|
21
|
+
inRange: boolean;
|
|
22
|
+
/** The row is selected (frozen cells repaint the selection tint). */
|
|
23
|
+
selected: boolean;
|
|
24
|
+
/** Last visible column — its right border is always transparent. */
|
|
25
|
+
lastColumn: boolean;
|
|
26
|
+
verticalBorders: boolean;
|
|
27
|
+
/** Wrap mode: the cell grows with its content instead of clipping to one
|
|
28
|
+
* line, and its text top-aligns so line one still reads across the row. */
|
|
29
|
+
wrap: boolean;
|
|
30
|
+
/** The value is saved here but its provider has not accepted it yet (spec
|
|
31
|
+
* §11.2) — the one pending state the grid draws, beside `data-settlement`. */
|
|
32
|
+
settlement?: Extract<FieldSettlement, "requested">;
|
|
33
|
+
};
|
|
34
|
+
/** The row-open hotspot inside a title cell, dressed as a link on its own hover. */
|
|
35
|
+
export declare const GRID_TITLE_LINK_CLASS = "**:data-cell-open:underline-offset-2 [&_[data-cell-open]:hover]:text-(color:--vk-fg-brand) [&_[data-cell-open]:hover]:underline";
|
|
36
|
+
/** A ranged cell's tint: it covers the cell and reaches 1px past its trailing edges, bridging the
|
|
37
|
+
* hairlines between cells into one surface. `-z-1` lays it under the cell's value and over the
|
|
38
|
+
* cell's own ground, inside the stacking context every ranged cell is (its z, or sticky). */
|
|
39
|
+
export declare const GRID_RANGE_TINT_CLASS = "pointer-events-none absolute left-0 top-0 -bottom-px -right-px -z-1 bg-(color:--vk-brand-subtlest)";
|
|
40
|
+
export declare function gridCellClassName(state: GridCellClassState): string;
|
|
41
|
+
/** The row's own classes. A SELECTED row hovers brand, not neutral: hover and selected both write
|
|
42
|
+
* background-image, so the neutral tint would replace the selection, and the row would grey out
|
|
43
|
+
* under the pointer exactly where it should feel most active. A doubled brand mix keeps the hover
|
|
44
|
+
* a clear step up in the same colour. The host's class is the row's last word, as it was under the
|
|
45
|
+
* merge: where it paints the row's own ground (Domains' unregistered rows), the selected tint
|
|
46
|
+
* stands aside for it — only that one property conflicts; the hover is an image.
|
|
47
|
+
*
|
|
48
|
+
* The row owns the page gutter (px) — the checkbox reveals inside it at left-0 — so the table's
|
|
49
|
+
* left edge stays aligned with the page content; pl includes --vk-indent (grouped tables shift
|
|
50
|
+
* right as one unit). The hover tint is FLAT and full-bleed, a one-stop background-IMAGE rather
|
|
51
|
+
* than a colour so it layers OVER the selected ground; the same string as GRID_FROZEN_HOVER, so
|
|
52
|
+
* pinned and scrolling cells tint the same. In wrap mode `--vk-chrome-h` becomes the first-line
|
|
53
|
+
* strip, so the checkbox lane and the title's hover actions sit beside line one. */
|
|
54
|
+
export declare function gridRowClassName(state: {
|
|
55
|
+
selected: boolean;
|
|
56
|
+
selectable: boolean;
|
|
57
|
+
wrapCells: boolean;
|
|
58
|
+
hostClass?: string;
|
|
59
|
+
}): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ROW_NO_TEXT_SELECT } from "../../selection/row-click.js";
|
|
2
|
+
import { cx } from "../../internal/cx.js";
|
|
3
|
+
import { GRID_CELL_HOVER_SHADOW, gridFrozenBg } from "./GridCellOutline.js";
|
|
4
|
+
import { GRID_GROUND } from "./grid-styles.js";
|
|
5
|
+
const GRID_CELL_REQUESTED = "italic opacity-80";
|
|
6
|
+
export const GRID_TITLE_LINK_CLASS = "**:data-cell-open:underline-offset-2 [&_[data-cell-open]:hover]:text-(color:--vk-fg-brand) [&_[data-cell-open]:hover]:underline";
|
|
7
|
+
export const GRID_RANGE_TINT_CLASS = "pointer-events-none absolute left-0 top-0 -bottom-px -right-px -z-1 bg-(color:--vk-brand-subtlest)";
|
|
8
|
+
export function gridCellClassName(state) {
|
|
9
|
+
const { focused, editing, inRange, frozen, selected, wrap } = state;
|
|
10
|
+
return cx(state.settlement === "requested" && GRID_CELL_REQUESTED, "group/gridcell", "flex min-w-0 border-b border-r border-(color:--vk-border-subtle) px-(--vk-px) text-(length:--vk-text)", wrap
|
|
11
|
+
? "min-h-(--vk-row-h) items-start py-(--vk-cell-py) leading-(--vk-line-h) [&>*:not(.absolute)]:min-h-(--vk-line-h)"
|
|
12
|
+
: "h-(--vk-row-h) items-center whitespace-nowrap", "scroll-mt-(--vk-scroll-mt)", "scroll-ml-[calc(var(--vk-rail-w)+var(--vk-frozen-w,0px))]", (!state.verticalBorders || state.lastColumn) && "border-r-transparent", state.align === "right" && "justify-end text-right tabular-nums", state.align === "center" && "justify-center text-center", frozen ? "sticky" : "relative", focused || editing || inRange ? "overflow-visible" : "overflow-hidden", frozen
|
|
13
|
+
? focused || editing
|
|
14
|
+
? "z-9"
|
|
15
|
+
: inRange
|
|
16
|
+
? "z-[calc(8*var(--vk-scrolled,0))]"
|
|
17
|
+
: "z-[calc(7*var(--vk-scrolled,0))]"
|
|
18
|
+
: focused || editing
|
|
19
|
+
? "z-5"
|
|
20
|
+
: inRange
|
|
21
|
+
? "z-4"
|
|
22
|
+
: undefined, frozen && gridFrozenBg(selected), editing && GRID_GROUND, !focused && !editing && !inRange && !state.isTitle && GRID_CELL_HOVER_SHADOW, state.isTitle && GRID_TITLE_LINK_CLASS);
|
|
23
|
+
}
|
|
24
|
+
export function gridRowClassName(state) {
|
|
25
|
+
const { selected, selectable, wrapCells, hostClass } = state;
|
|
26
|
+
const hostPaintsGround = hostClass != null && /(?:^|\s)bg-/.test(hostClass);
|
|
27
|
+
return cx("group/gridrow relative grid cursor-pointer pl-[calc(var(--vk-gutter,0px)+var(--vk-indent,0px))] pr-(--vk-gutter,0px)", selectable && ROW_NO_TEXT_SELECT, wrapCells && "[--vk-chrome-h:var(--vk-row-h)]", selected
|
|
28
|
+
? "hover:bg-[linear-gradient(color-mix(in_oklab,_var(--vk-brand)_10%,_transparent),color-mix(in_oklab,_var(--vk-brand)_10%,_transparent))]"
|
|
29
|
+
: "hover:bg-[linear-gradient(var(--vk-hovered),var(--vk-hovered))]", selected && !hostPaintsGround && "bg-(color:--vk-brand-subtlest)", hostClass);
|
|
30
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** How many options a grid menu lists before it offers a search: a group band's Sort rows. */
|
|
2
|
+
export declare const GRID_MENU_SEARCH_AFTER = 8;
|
|
3
|
+
/** The options a grid menu lists for a search: every one while the search is empty, else those whose label
|
|
4
|
+
* holds it. */
|
|
5
|
+
export declare function matchMenuOptions<O extends {
|
|
6
|
+
label: string;
|
|
7
|
+
}>(options: readonly O[], query: string): O[];
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { ViewsRowMenuItem } from "../../atoms/types.js";
|
|
3
|
+
import type { FieldMenus } from "../../fields/menus.js";
|
|
4
|
+
import type { ListSettingsConfig } from "../../model/column-capabilities.js";
|
|
5
|
+
import type { ListCellAction, ListColumn, ListOptionColorOverrides, ListRelationValue } from "../../model/column-schema.js";
|
|
6
|
+
import type { ListDateStyleOverrides, ListDurationStyleOverrides, ListNumberFormatOverrides, ListPercentDisplayOverrides, ListShowTimeOverrides } from "../../model/column-format.js";
|
|
7
|
+
import type { ListRowIconAccessor } from "../../model/row-icon.js";
|
|
8
|
+
import type { GridRowRangeSpan } from "../core/useGridRange.js";
|
|
9
|
+
export type GridRowProps<Row> = {
|
|
10
|
+
row: Row;
|
|
11
|
+
/** The DATA id — what a write, the optimistic overlay and selection address.
|
|
12
|
+
* Shared by every copy of a row that is drawn more than once. */
|
|
13
|
+
id: string;
|
|
14
|
+
/** This RENDERED row's identity, unique even when the same record is drawn
|
|
15
|
+
* under several groups. Focus, the editor, arrows and ranges are in terms of
|
|
16
|
+
* it; see `GridCellPos`. */
|
|
17
|
+
rowKey: string;
|
|
18
|
+
gridTemplate: string;
|
|
19
|
+
columns: ListColumn<Row>[];
|
|
20
|
+
selectable: boolean;
|
|
21
|
+
selected: boolean;
|
|
22
|
+
/** The row directly above in the SAME rendered list is selected. Every
|
|
23
|
+
* selected row draws its own BOTTOM rule; the top one is drawn only to CAP a
|
|
24
|
+
* run, which is what leaves exactly one line at each boundary — with both
|
|
25
|
+
* ends unconditional, two adjacent rows would land a rule each on
|
|
26
|
+
* neighbouring pixels and read as a 2px line. Plain boolean on purpose: this
|
|
27
|
+
* row is `memo()`d with no comparator. */
|
|
28
|
+
selectedAbove: boolean;
|
|
29
|
+
selecting: boolean;
|
|
30
|
+
toggle: (id: string, next?: boolean) => void;
|
|
31
|
+
toggleRange: (id: string) => void;
|
|
32
|
+
contextMenu?: (row: Row) => ViewsRowMenuItem[];
|
|
33
|
+
rowClassName?: (row: Row) => string | undefined;
|
|
34
|
+
rowHref?: (row: Row) => string | undefined;
|
|
35
|
+
onOpenRow: (row: Row) => void;
|
|
36
|
+
onPrefetchRow?: (row: Row) => void;
|
|
37
|
+
onRowDelete?: (id: string) => Promise<void>;
|
|
38
|
+
deleteLabel?: string;
|
|
39
|
+
/** Per-row actions in the title cell's hover lane, before the built-in Edit. */
|
|
40
|
+
rowActions?: ListCellAction<Row>[];
|
|
41
|
+
/** Leading ICON at the START of the title cell — a bare glyph, never an
|
|
42
|
+
* avatar component (see GridTableProps.rowIcon). Undefined = the user
|
|
43
|
+
* turned the "Row icon" toggle off, or the list has no icon to draw. */
|
|
44
|
+
rowIcon?: ListRowIconAccessor<Row>;
|
|
45
|
+
verticalBorders?: boolean;
|
|
46
|
+
/** Cells wrap to at most 3 lines and the row grows to its tallest cell. */
|
|
47
|
+
wrapCells?: boolean;
|
|
48
|
+
optionColors?: ListOptionColorOverrides;
|
|
49
|
+
dateStyles?: ListDateStyleOverrides;
|
|
50
|
+
/** Per-field duration rendering (override → `format.durationStyle` → adaptive). */
|
|
51
|
+
durationStyles?: ListDurationStyleOverrides;
|
|
52
|
+
/** Per-field decimals / display-currency (host-owned, from the header menu). */
|
|
53
|
+
numberFormats?: ListNumberFormatOverrides;
|
|
54
|
+
/** Per-field show-time overrides for date columns. */
|
|
55
|
+
showTimeOverrides?: ListShowTimeOverrides;
|
|
56
|
+
/** Per-field percent drawing (text, bar, ring). */
|
|
57
|
+
percentDisplays?: ListPercentDisplayOverrides;
|
|
58
|
+
/** The grid has a commit handler — cells with editors may enter edit mode. */
|
|
59
|
+
editingEnabled: boolean;
|
|
60
|
+
/** Focused/editing column id — null unless it's THIS row's cell. */
|
|
61
|
+
focusedColId: string | null;
|
|
62
|
+
editingColId: string | null;
|
|
63
|
+
/** columnId → optimistic pending value (undefined when this row has none). */
|
|
64
|
+
pendingByCol?: Record<string, unknown>;
|
|
65
|
+
/** columnId → `requested` for a pending value saved here but not yet accepted
|
|
66
|
+
* by the provider that owns it (spec §11.2) — drawn as the cell's pending state. */
|
|
67
|
+
settlementByCol?: Record<string, "requested">;
|
|
68
|
+
/** columnId → option values for status/select editors (declared + discovered).
|
|
69
|
+
* One memo-stable object shared by every row. */
|
|
70
|
+
selectValues?: Record<string, string[]>;
|
|
71
|
+
/** THIS row's slices of the 2D range selection (visible-column indices),
|
|
72
|
+
* memo-stable (GridTable caches identity per row). Undefined when no
|
|
73
|
+
* multi-cell range touches the row — the common case renders as before. */
|
|
74
|
+
rowRange?: GridRowRangeSpan[];
|
|
75
|
+
/** How many LEADING columns are pinned to the left edge. A plain number, so a
|
|
76
|
+
* memoized row doesn't re-render on every scroll; the row computes its own
|
|
77
|
+
* sticky offsets from it. 0 = nothing frozen. */
|
|
78
|
+
frozenCount?: number;
|
|
79
|
+
/** Sticky `left` for the frozen column at visible index i — a calc() over the
|
|
80
|
+
* width vars, so live resize re-lays the frozen stack without React. */
|
|
81
|
+
frozenLeft?: (i: number) => string;
|
|
82
|
+
/** Workspace-settings capability locks (table read-only / per-column) — subtracts from
|
|
83
|
+
* what the columns declare. Memo-stable: threaded straight from the host. */
|
|
84
|
+
listConfig?: ListSettingsConfig;
|
|
85
|
+
onFocusCell: (rowId: string, columnId: string) => void;
|
|
86
|
+
onStartEdit: (rowId: string, columnId: string) => void;
|
|
87
|
+
/** A second click or a double-click on a cell that opens nothing: the grid
|
|
88
|
+
* says why it can't be edited (or nothing, when it can be written). */
|
|
89
|
+
onRefuseEdit?: (columnId: string) => void;
|
|
90
|
+
/** Tab out of an editor → next/prev cell in reading order (grid-owned so it
|
|
91
|
+
* matches Tab-while-focused; wraps rows). */
|
|
92
|
+
onEditorTab: (rowId: string, columnId: string, backwards: boolean) => void;
|
|
93
|
+
/** Enter out of an editor → advance one row down. */
|
|
94
|
+
onEditorEnter: (rowId: string, columnId: string) => void;
|
|
95
|
+
/** Type-to-replace seed: the character that opened THIS row's editor, or null.
|
|
96
|
+
* Used as the editor's initial value in place of the cell's own. */
|
|
97
|
+
editSeed?: string | null;
|
|
98
|
+
/** Shift-click: extend the active range to this cell (anchor stays). */
|
|
99
|
+
onExtendCell: (rowId: string, columnId: string) => void;
|
|
100
|
+
/** ⌘-click: add this cell as its own range. */
|
|
101
|
+
onAddCell: (rowId: string, columnId: string) => void;
|
|
102
|
+
onCommitCell: (row: Row, rowId: string, columnId: string, prev: unknown, next: unknown, opts?: {
|
|
103
|
+
overlay?: boolean;
|
|
104
|
+
}) => void;
|
|
105
|
+
/** Cell-scoped args make late (animation-deferred) cancels safe. */
|
|
106
|
+
onCancelEdit: (rowId?: string, columnId?: string) => void;
|
|
107
|
+
/** Open the entity a `relation` cell POINTS AT — a different entity from the
|
|
108
|
+
* one `onOpenRow` opens, which is why it can't reuse that handler. Omitted
|
|
109
|
+
* by a host with nowhere to send the click; the chip then renders inert
|
|
110
|
+
* rather than advertising a navigation it can't perform. */
|
|
111
|
+
onOpenRelation?: (value: ListRelationValue, columnId: string, row: Row) => void;
|
|
112
|
+
/** This app's glyph for an entity kind — see `GridCellOptions.entityIcon`. */
|
|
113
|
+
entityIcon?: (kind: string | undefined) => ReactNode;
|
|
114
|
+
/** The verbs a `command` column's cell opens, by field key — the host's, the
|
|
115
|
+
* same map the drawer's `FieldPanel` takes. Memo-stable: threaded straight
|
|
116
|
+
* from the host. See `GridCellOptions.commandItems`. */
|
|
117
|
+
commands?: FieldMenus<Row>;
|
|
118
|
+
/** Whether a cell sits inside the active MULTI-cell range — the context
|
|
119
|
+
* menu's verbs then act on the whole range instead of the one cell. */
|
|
120
|
+
inActiveRange: (rowId: string, columnId: string) => boolean;
|
|
121
|
+
/** Whether the active range holds any clearable column (greys Cut/Clear —
|
|
122
|
+
* required fields can't be emptied). */
|
|
123
|
+
rangeCanClear: () => boolean;
|
|
124
|
+
onRangeCopy: () => void;
|
|
125
|
+
onRangeCut: () => void;
|
|
126
|
+
onRangePaste: () => void;
|
|
127
|
+
onRangeClear: () => void;
|
|
128
|
+
/** Paste the clipboard MATRIX anchored at this cell (single-cell menu path
|
|
129
|
+
* when the clipboard holds a range copy). */
|
|
130
|
+
onPasteAtCell: (rowId: string, columnId: string) => void;
|
|
131
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const GRID_BLEED = "-mx-(--vk-gutter,0px)";
|
|
2
|
+
export declare const GRID_ROW_PAD = "px-(--vk-gutter,0px)";
|
|
3
|
+
export declare const GRID_CONTENT_PAD = "pl-[calc(var(--vk-gutter,0px)+var(--vk-indent,0px))] pr-(--vk-gutter,0px)";
|
|
4
|
+
/** A part that paints the ground it sits on — the editing cell, a frozen footer cell, the rail's
|
|
5
|
+
* checkboxes, an outlined row action, the header's drag ghost. The page's ground, without
|
|
6
|
+
* re-declaring its states: every host the grid mounts in carries the page's own. */
|
|
7
|
+
export declare const GRID_GROUND = "bg-(color:--vk-ground)";
|
|
8
|
+
/** THE endFill-tail ⋯ button look: each row's menu button. Its hover is the caller's: neutral, or
|
|
9
|
+
* brand on a selected row. */
|
|
10
|
+
export declare const GRID_TAIL_BUTTON_BASE = "inline-flex h-8 w-9 items-center justify-center rounded-sm text-(color:--vk-fg-subtle) hover:text-(color:--vk-fg)";
|
|
11
|
+
export declare const GRID_HEADER_BG = "bg-[linear-gradient(to_bottom,var(--vk-ground)_calc(100%-2px),transparent_calc(100%-2px))]";
|
|
12
|
+
/**
|
|
13
|
+
* A FROZEN header cell's OWN paint — the same band, alpha-gated on
|
|
14
|
+
* `--vk-scrolled` (0/1, from the scroll sync), like the frozen z-tier and the
|
|
15
|
+
* head fade. It needs to be opaque only while cells pass underneath it; at rest
|
|
16
|
+
* the strip's own GRID_HEADER_BG already covers the band.
|
|
17
|
+
*
|
|
18
|
+
* Load-bearing, not tidiness: painting it unconditionally fills GRID_HEADER_BG's
|
|
19
|
+
* deliberate 2px transparent sliver — the ONLY place the FIRST row's selection
|
|
20
|
+
* ring can draw its top edge (no row above it, and the band outranks every
|
|
21
|
+
* cell). Symptom: pin the identity columns, edit the first row's title, and the
|
|
22
|
+
* ring's top edge is missing.
|
|
23
|
+
*/
|
|
24
|
+
export declare const GRID_HEADER_BG_FROZEN = "bg-[linear-gradient(to_bottom,color-mix(in_oklab,_var(--vk-ground)_calc(var(--vk-scrolled,0)*100%),_transparent)_calc(100%-2px),transparent_calc(100%-2px))]";
|
|
25
|
+
/**
|
|
26
|
+
* The frozen cell's hover tint. GRID_HEADER_BG is a background-IMAGE and images
|
|
27
|
+
* paint over the background-COLOR — so the plain `hover:bg-(color:--vk-hovered)` the other
|
|
28
|
+
* header cells use is completely hidden underneath it, except in the 2px
|
|
29
|
+
* transparent sliver.
|
|
30
|
+
*
|
|
31
|
+
* So the hover tint has to be an image too, stacked ABOVE the same base — first
|
|
32
|
+
* layer wins in a background-image list. Non-frozen cells keep the simple
|
|
33
|
+
* colour version; only frozen cells need this. The base layer carries the same
|
|
34
|
+
* `--vk-scrolled` gate as GRID_HEADER_BG_FROZEN, so hovering a header at rest
|
|
35
|
+
* can't reintroduce the opacity the sliver depends on.
|
|
36
|
+
*/
|
|
37
|
+
export declare const GRID_HEADER_BG_FROZEN_HOVER = "hover:bg-[linear-gradient(var(--vk-hovered),var(--vk-hovered)),linear-gradient(to_bottom,color-mix(in_oklab,_var(--vk-ground)_calc(var(--vk-scrolled,0)*100%),_transparent)_calc(100%-2px),transparent_calc(100%-2px))]";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const GRID_BLEED = "-mx-(--vk-gutter,0px)";
|
|
2
|
+
export const GRID_ROW_PAD = "px-(--vk-gutter,0px)";
|
|
3
|
+
export const GRID_CONTENT_PAD = "pl-[calc(var(--vk-gutter,0px)+var(--vk-indent,0px))] pr-(--vk-gutter,0px)";
|
|
4
|
+
export const GRID_GROUND = "bg-(color:--vk-ground)";
|
|
5
|
+
export const GRID_TAIL_BUTTON_BASE = "inline-flex h-8 w-9 items-center justify-center rounded-sm text-(color:--vk-fg-subtle) hover:text-(color:--vk-fg)";
|
|
6
|
+
export const GRID_HEADER_BG = "bg-[linear-gradient(to_bottom,var(--vk-ground)_calc(100%-2px),transparent_calc(100%-2px))]";
|
|
7
|
+
export const GRID_HEADER_BG_FROZEN = "bg-[linear-gradient(to_bottom,color-mix(in_oklab,_var(--vk-ground)_calc(var(--vk-scrolled,0)*100%),_transparent)_calc(100%-2px),transparent_calc(100%-2px))]";
|
|
8
|
+
export const GRID_HEADER_BG_FROZEN_HOVER = "hover:bg-[linear-gradient(var(--vk-hovered),var(--vk-hovered)),linear-gradient(to_bottom,color-mix(in_oklab,_var(--vk-ground)_calc(var(--vk-scrolled,0)*100%),_transparent)_calc(100%-2px),transparent_calc(100%-2px))]";
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { DisplayCurrency } from "../../fields/currency.js";
|
|
3
|
+
import type { ViewsRowMenuItem } from "../../atoms/types.js";
|
|
4
|
+
import type { FieldMenus } from "../../fields/menus.js";
|
|
5
|
+
import type { ListGroup } from "../../grouping/types.js";
|
|
6
|
+
import type { ListSelectionConfig } from "../../selection/types.js";
|
|
7
|
+
import type { ListSettingsConfig } from "../../model/column-capabilities.js";
|
|
8
|
+
import type { ListAggregateKind, ListCellAction, ListColumn, ListOptionColorOverrides, ListRelationValue, ListSelectColor } from "../../model/column-schema.js";
|
|
9
|
+
import type { ListDateStyle, ListDateStyleOverrides, ListDurationStyle, ListDurationStyleOverrides, ListNumberFormatOverrides, ListPercentDisplayOverrides, ListShowTimeOverrides } from "../../model/column-format.js";
|
|
10
|
+
import type { ListColumnState, ListColumnsConfig } from "../../model/column-state.js";
|
|
11
|
+
import type { PercentDisplay } from "@viewkitjs/fields";
|
|
12
|
+
import type { ListGroupSummaryPart } from "../../model/preferences.js";
|
|
13
|
+
import type { ListRowIconAccessor } from "../../model/row-icon.js";
|
|
14
|
+
import type { GridCellCommitFn, GridCellsCommitFn } from "../core/commit-model.js";
|
|
15
|
+
import type { GridGroupByState, GridSortState } from "./GridColumnMenu.js";
|
|
16
|
+
import type { GridGroupSortOption } from "./GridGroupMenu.js";
|
|
17
|
+
/** A group count's noun, singular and plural ("company", "companies"): "2 companies". None: a bare
|
|
18
|
+
* count. */
|
|
19
|
+
export type GroupCountNoun = {
|
|
20
|
+
one: string;
|
|
21
|
+
other: string;
|
|
22
|
+
};
|
|
23
|
+
/** One figure a group header can show: the part that turns it on, its column's header (what the menu and
|
|
24
|
+
* the header call it), and how it draws for a group. */
|
|
25
|
+
export type GridGroupFigure<Row> = {
|
|
26
|
+
part: ListGroupSummaryPart;
|
|
27
|
+
label: ReactNode;
|
|
28
|
+
render: (group: ListGroup<Row>) => ReactNode;
|
|
29
|
+
};
|
|
30
|
+
/** A view's identity: when it changes, the whole body is replaced, and the grid shows its wait for
|
|
31
|
+
* one commit first. */
|
|
32
|
+
type GridTransitionKey = string | number | boolean | null | undefined;
|
|
33
|
+
export type GridTableProps<Row> = {
|
|
34
|
+
/** View/filter identity that replaces the whole collection body. */
|
|
35
|
+
transitionKey?: GridTransitionKey;
|
|
36
|
+
transitionPending?: boolean;
|
|
37
|
+
transitionLabel?: string;
|
|
38
|
+
groups: ListGroup<Row>[];
|
|
39
|
+
grouped: boolean;
|
|
40
|
+
getRowId: (row: Row) => string;
|
|
41
|
+
columns: ListColumn<Row>[];
|
|
42
|
+
isCollapsed?: (key: string) => boolean;
|
|
43
|
+
onToggleGroup?: (key: string) => void;
|
|
44
|
+
renderGroupLabel?: (group: ListGroup<Row>) => ReactNode;
|
|
45
|
+
/** Hide a group in the view, from its band's menu. Absent where a
|
|
46
|
+
* list cannot hide one. */
|
|
47
|
+
onHideGroup?: (key: string) => void;
|
|
48
|
+
/** Source-paged group continuation, rendered after this group's loaded rows. */
|
|
49
|
+
renderGroupFooter?: (group: ListGroup<Row>) => ReactNode;
|
|
50
|
+
renderAggregate?: (columnId: string, group: ListGroup<Row>) => ReactNode;
|
|
51
|
+
countOf?: (group: ListGroup<Row>) => number;
|
|
52
|
+
onOpenRow: (row: Row) => void;
|
|
53
|
+
/** Warm the row detail only from an actual primary pointer intent. */
|
|
54
|
+
onPrefetchRow?: (row: Row) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Open the entity a `relation` cell points at.
|
|
57
|
+
*
|
|
58
|
+
* ONE handler for the whole grid, mirroring `onOpenRow`, rather than a
|
|
59
|
+
* callback per column: column definitions stay declarative (a builder that
|
|
60
|
+
* needs a bag of callbacks is telling you those cells want to be real typed
|
|
61
|
+
* columns), and a stable array memoizes properly.
|
|
62
|
+
*
|
|
63
|
+
* The host gets the resolved value back, so `value.entity` is what tells it
|
|
64
|
+
* WHICH drawer to open — the grid deliberately knows nothing about routes or
|
|
65
|
+
* drawers. Omit it and relation cells render inert.
|
|
66
|
+
*/
|
|
67
|
+
onOpenRelation?: (value: ListRelationValue, columnId: string, row: Row) => void;
|
|
68
|
+
/**
|
|
69
|
+
* This app's glyph for an entity KIND, used by every `relation` cell that
|
|
70
|
+
* doesn't carry its own. Kept as a resolver so the grid never learns one
|
|
71
|
+
* application's vocabulary — see `GridCellOptions.entityIcon`.
|
|
72
|
+
*/
|
|
73
|
+
entityIcon?: (kind: string | undefined) => ReactNode;
|
|
74
|
+
/**
|
|
75
|
+
* The verbs a `command` column's cell opens, by field key (spec §5: "every
|
|
76
|
+
* surface opens the verb menu, the host supplies the verbs"). The SAME map a
|
|
77
|
+
* host hands the drawer's `FieldPanel`, so Mark won / Mark lost / Reopen are
|
|
78
|
+
* declared once and reached from the panel, the grid and the card alike.
|
|
79
|
+
* Omit it and a command column is a read-only badge.
|
|
80
|
+
*/
|
|
81
|
+
commands?: FieldMenus<Row>;
|
|
82
|
+
rowHref?: (row: Row) => string | undefined;
|
|
83
|
+
/** The row's action items. Named to match `ListViewProps.rowMenu` so a
|
|
84
|
+
* dual-renderer page passes ONE builder to both mounts. The grid has no
|
|
85
|
+
* kebab — these surface on right-click and in the row's ⋯ tail button — but
|
|
86
|
+
* the source of the items is the same, and a page that filled ListView's
|
|
87
|
+
* `rowMenu` and forgot the grid's used to silently lose every row action in
|
|
88
|
+
* the grid look. */
|
|
89
|
+
rowMenu?: (row: Row) => ViewsRowMenuItem[];
|
|
90
|
+
/** Override when the context menu must differ from `rowMenu`. Defaults to it. */
|
|
91
|
+
contextMenu?: (row: Row) => ViewsRowMenuItem[];
|
|
92
|
+
rowClassName?: (row: Row) => string | undefined;
|
|
93
|
+
onRowDelete?: (id: string) => Promise<void>;
|
|
94
|
+
deleteLabel?: string;
|
|
95
|
+
rowActions?: ListCellAction<Row>[];
|
|
96
|
+
/** The leading glyph in the title cell, as a DESCRIPTOR — the grid decides
|
|
97
|
+
* size and color from it. See `ListRowIconAccessor`. */
|
|
98
|
+
rowIcon?: ListRowIconAccessor<Row>;
|
|
99
|
+
showRowIcon?: boolean;
|
|
100
|
+
selection?: ListSelectionConfig;
|
|
101
|
+
loadMore?: {
|
|
102
|
+
hasMore: boolean;
|
|
103
|
+
onReveal: () => void;
|
|
104
|
+
label?: string;
|
|
105
|
+
};
|
|
106
|
+
emptyState?: ReactNode;
|
|
107
|
+
/** The reader's default currency: a money column read in Original totals in it. The host's
|
|
108
|
+
* answer (the portal: the reader's preference); default `DEFAULT_DISPLAY_CURRENCY`. */
|
|
109
|
+
defaultCurrency?: DisplayCurrency;
|
|
110
|
+
verticalBorders?: boolean;
|
|
111
|
+
sort?: GridSortState;
|
|
112
|
+
/** The view's group, for the header menu's Group by / Ungroup — present on
|
|
113
|
+
* view-backed lists only, the way `sort` is. */
|
|
114
|
+
groupBy?: GridGroupByState;
|
|
115
|
+
sortOptions?: GridGroupSortOption[];
|
|
116
|
+
/** Which figures ride beside a group name — a set, not a choice. */
|
|
117
|
+
groupSummary?: ListGroupSummaryPart[];
|
|
118
|
+
aggregates?: Record<string, ListAggregateKind>;
|
|
119
|
+
onAggregateChange?: (columnId: string, kind: ListAggregateKind) => void;
|
|
120
|
+
/** A saved view can change aggregate choices only for field-backed columns. */
|
|
121
|
+
viewBacked?: boolean;
|
|
122
|
+
onGroupSummaryChange?: (part: ListGroupSummaryPart, next: boolean) => void;
|
|
123
|
+
/** The figures a group header can show, in the list's order: each part, its column's header and its drawing. */
|
|
124
|
+
groupFigures?: GridGroupFigure<Row>[];
|
|
125
|
+
/** The group count's noun: "2 companies". None: a bare count. */
|
|
126
|
+
countNoun?: GroupCountNoun;
|
|
127
|
+
optionColors?: ListOptionColorOverrides;
|
|
128
|
+
onOptionColorChange?: (key: string, value: string, color: ListSelectColor | null) => void;
|
|
129
|
+
dateStyles?: ListDateStyleOverrides;
|
|
130
|
+
onDateStyleChange?: (key: string, style: ListDateStyle) => void;
|
|
131
|
+
durationStyles?: ListDurationStyleOverrides;
|
|
132
|
+
onDurationStyleChange?: (key: string, style: ListDurationStyle) => void;
|
|
133
|
+
numberFormats?: ListNumberFormatOverrides;
|
|
134
|
+
/** `decimals: null` = the field's own (Automatic). */
|
|
135
|
+
onNumberFormatChange?: (key: string, patch: {
|
|
136
|
+
decimals?: number | null;
|
|
137
|
+
currency?: string;
|
|
138
|
+
}) => void;
|
|
139
|
+
showTimeOverrides?: ListShowTimeOverrides;
|
|
140
|
+
onShowTimeChange?: (key: string, show: boolean) => void;
|
|
141
|
+
percentDisplays?: ListPercentDisplayOverrides;
|
|
142
|
+
onPercentDisplayChange?: (key: string, display: PercentDisplay) => void;
|
|
143
|
+
/** Whether a format knob can be stored (decimals, a date's style, a percent's display, an option's colour):
|
|
144
|
+
* false hides them from the column menu, where there is nothing to store them against. A reader's own
|
|
145
|
+
* currency reading stays. Default true. */
|
|
146
|
+
formatsWritable?: boolean;
|
|
147
|
+
/** The host's own "+ Add column", the header row's last cell (a field editor's, for an admin). Nothing, or a
|
|
148
|
+
* falsy answer, draws the grid's own: the columns the view hides. */
|
|
149
|
+
renderAddColumn?: (columns: ListColumnsConfig) => ReactNode;
|
|
150
|
+
/** The host's rows in a column's menu for the column's field, above Hide (a field editor's Edit field and
|
|
151
|
+
* Archive field); `close` shuts the menu. Null for a field the host adds nothing to. */
|
|
152
|
+
renderColumnMenuRows?: (fieldKey: string, close: () => void) => ReactNode;
|
|
153
|
+
columnState?: ListColumnState;
|
|
154
|
+
onColumnStateChange?: (next: ListColumnState) => void;
|
|
155
|
+
scale?: number;
|
|
156
|
+
onCellCommit?: GridCellCommitFn<Row>;
|
|
157
|
+
onCellsCommit?: GridCellsCommitFn<Row>;
|
|
158
|
+
/** Per-user "Freeze identity columns" toggle: pins every column through the
|
|
159
|
+
* title to the left edge while the rest scrolls under them. */
|
|
160
|
+
freezeIdentity?: boolean;
|
|
161
|
+
/** Per-user "Wrap columns" toggle: typed cells wrap to at most 3 lines and
|
|
162
|
+
* rows grow to fit their tallest cell, instead of one line per row. */
|
|
163
|
+
wrapCells?: boolean;
|
|
164
|
+
/** Per-user "Show checkboxes always" toggle: holds the checkbox rail open
|
|
165
|
+
* instead of revealing it on hover. Same state a live selection forces. */
|
|
166
|
+
alwaysCheckboxes?: boolean;
|
|
167
|
+
/** Workspace-settings capability config for THIS list (table read-only / per-column
|
|
168
|
+
* locks), inherited by every user. The CONFIG layer of
|
|
169
|
+
* `declaration → config → prefs` — it may only SUBTRACT from what the
|
|
170
|
+
* columns declare. UI constraint only; the host's API guards its own writes. */
|
|
171
|
+
listConfig?: ListSettingsConfig;
|
|
172
|
+
};
|
|
173
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ListBatchApi } from "../../selection/types.js";
|
|
2
|
+
import type { GridEditCell } from "../core/useGridEditing.js";
|
|
3
|
+
import type { ListSettingsConfig } from "../../model/column-capabilities.js";
|
|
4
|
+
import type { ListColumn } from "../../model/column-schema.js";
|
|
5
|
+
/**
|
|
6
|
+
* The batch bar's route into the grid's own write machinery.
|
|
7
|
+
*
|
|
8
|
+
* A verb like "set status on 12 rows" is not a different kind of write from
|
|
9
|
+
* editing one status cell — it is the same write, twelve times. Sending it
|
|
10
|
+
* through `commitBatchChecked` therefore buys everything the cell editors
|
|
11
|
+
* already have: the optimistic overlay (rows repaint on the click rather than
|
|
12
|
+
* when the server round-trip returns), ONE history entry so ⌘Z reverts the
|
|
13
|
+
* whole batch in a single step, and rollback if the write fails.
|
|
14
|
+
*
|
|
15
|
+
* Its own module rather than more lines in GridTable: that file sits under an
|
|
16
|
+
* oversized-debt ceiling whose policy says split the responsibility rather than
|
|
17
|
+
* raise the number.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useGridBatchApi<Row>({ enabled, columns, listConfig, rows, getRowId, pendingByRow, commitBatch, }: {
|
|
20
|
+
/** The grid can write at all (the host passed a commit handler). */
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
/** Visible columns — the id resolves against what the user can actually see. */
|
|
23
|
+
columns: ListColumn<Row>[];
|
|
24
|
+
listConfig: ListSettingsConfig | undefined;
|
|
25
|
+
/** Every loaded row, for resolving selected ids to row objects. */
|
|
26
|
+
rows: Row[];
|
|
27
|
+
getRowId: (row: Row) => string;
|
|
28
|
+
/** Optimistic values already in flight — the undo baseline reads through them
|
|
29
|
+
* so a second batch over the same cells doesn't record a stale `prev`. */
|
|
30
|
+
pendingByRow: ReadonlyMap<string, Record<string, unknown>>;
|
|
31
|
+
commitBatch: (edits: (GridEditCell<Row> & {
|
|
32
|
+
row: Row;
|
|
33
|
+
})[]) => Promise<boolean>;
|
|
34
|
+
}): ListBatchApi | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { cellEditBaseline, cellPrevPayload } from "./cell-clipboard.js";
|
|
4
|
+
import { columnEffectiveWritable } from "../../model/column-capabilities.js";
|
|
5
|
+
export function useGridBatchApi({ enabled, columns, listConfig, rows, getRowId, pendingByRow, commitBatch, }) {
|
|
6
|
+
return useMemo(() => {
|
|
7
|
+
if (!enabled)
|
|
8
|
+
return undefined;
|
|
9
|
+
return {
|
|
10
|
+
setColumnValue: (rowIds, columnId, value) => {
|
|
11
|
+
const col = columns.find((c) => c.id === columnId);
|
|
12
|
+
if (!col || !columnEffectiveWritable(col, listConfig))
|
|
13
|
+
return Promise.resolve(false);
|
|
14
|
+
const byId = new Map(rows.map((r) => [getRowId(r), r]));
|
|
15
|
+
const overlay = col.type !== "number" && col.type !== "date";
|
|
16
|
+
const edits = [];
|
|
17
|
+
for (const rowId of rowIds) {
|
|
18
|
+
const row = byId.get(rowId);
|
|
19
|
+
if (row == null)
|
|
20
|
+
continue;
|
|
21
|
+
edits.push({
|
|
22
|
+
row,
|
|
23
|
+
rowId,
|
|
24
|
+
columnId,
|
|
25
|
+
prev: cellPrevPayload(col, cellEditBaseline(col, row, pendingByRow.get(rowId)), col.editUnit?.value(row)),
|
|
26
|
+
next: value,
|
|
27
|
+
overlay,
|
|
28
|
+
rowSnapshot: row,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return commitBatch(edits);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}, [enabled, columns, listConfig, rows, getRowId, pendingByRow, commitBatch]);
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type PointerEvent as ReactPointerEvent, type RefObject } from "react";
|
|
2
|
+
import type { ListColumnsConfig } from "../../model/column-state.js";
|
|
3
|
+
import type { ListColumn } from "../../model/column-schema.js";
|
|
4
|
+
import { type ListColumnState } from "../../model/column-state.js";
|
|
5
|
+
export declare function useGridColumnLayout<Row>({ rootRef, columns, columnState, onColumnStateChange, scale, freezeIdentity, viewBacked, }: {
|
|
6
|
+
rootRef: RefObject<HTMLDivElement | null>;
|
|
7
|
+
columns: ListColumn<Row>[];
|
|
8
|
+
columnState?: ListColumnState;
|
|
9
|
+
onColumnStateChange?: (state: ListColumnState) => void;
|
|
10
|
+
scale: number;
|
|
11
|
+
/** Pin the identity columns (everything through the title) to the left edge. */
|
|
12
|
+
freezeIdentity?: boolean;
|
|
13
|
+
/** Saved views persist layout only for field-backed columns. */
|
|
14
|
+
viewBacked?: boolean;
|
|
15
|
+
}): {
|
|
16
|
+
visibleColumns: ListColumn<Row>[];
|
|
17
|
+
widthVarsStyle: import("react").CSSProperties;
|
|
18
|
+
frozenCount: number;
|
|
19
|
+
frozenLeft: (i: number) => string;
|
|
20
|
+
columnManager: ListColumnsConfig | null;
|
|
21
|
+
gridTemplate: string;
|
|
22
|
+
minWidth: string;
|
|
23
|
+
resizingId: string | null;
|
|
24
|
+
startResize: (col: ListColumn<Row>, event: ReactPointerEvent<HTMLElement>) => void;
|
|
25
|
+
moveResize: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
26
|
+
endResize: () => void;
|
|
27
|
+
resetColumnWidth: (col: ListColumn<Row>) => void;
|
|
28
|
+
hideColumn: (col: ListColumn<Row>) => void;
|
|
29
|
+
moveColumn: (col: ListColumn<Row>, direction: -1 | 1) => void;
|
|
30
|
+
};
|