@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.
Files changed (246) hide show
  1. package/CHANGELOG.md +196 -1
  2. package/README.md +90 -41
  3. package/dist/atoms/Row.js +1 -1
  4. package/dist/atoms/RowMenu.d.ts +1 -1
  5. package/dist/atoms/RowMenu.js +15 -4
  6. package/dist/atoms/types.d.ts +4 -4
  7. package/dist/contract.d.ts +37 -7
  8. package/dist/contract.js +24 -5
  9. package/dist/display/format.d.ts +16 -1
  10. package/dist/display/format.js +10 -1
  11. package/dist/display/index.d.ts +1 -1
  12. package/dist/display/index.js +1 -1
  13. package/dist/display/link.js +5 -3
  14. package/dist/display/location.d.ts +4 -3
  15. package/dist/display/location.js +12 -5
  16. package/dist/display/options.d.ts +1 -1
  17. package/dist/display/percent.js +10 -3
  18. package/dist/display/phone.d.ts +2 -1
  19. package/dist/display/phone.js +8 -1
  20. package/dist/display/relation.js +1 -1
  21. package/dist/editors/ChipsEditor.js +1 -1
  22. package/dist/editors/LocationEditor.js +16 -17
  23. package/dist/editors/NameEditor.js +5 -4
  24. package/dist/editors/NumberEditor.js +2 -2
  25. package/dist/editors/RangeEditor.js +2 -2
  26. package/dist/editors/ValueListEditor.d.ts +2 -2
  27. package/dist/editors/ValueListEditor.js +8 -8
  28. package/dist/editors/edit-cores.d.ts +1 -1
  29. package/dist/fields/binding.d.ts +1 -1
  30. package/dist/fields/currency.d.ts +0 -10
  31. package/dist/fields/currency.js +0 -14
  32. package/dist/fields/money.d.ts +1 -0
  33. package/dist/fields/money.js +1 -0
  34. package/dist/filters/filter-model.d.ts +0 -1
  35. package/dist/filters/registry.d.ts +3 -36
  36. package/dist/filters/registry.js +0 -38
  37. package/dist/grid/chrome/GridAddColumn.d.ts +11 -0
  38. package/dist/grid/chrome/GridAddColumn.js +29 -0
  39. package/dist/grid/chrome/GridAggregateMenu.d.ts +31 -0
  40. package/dist/grid/chrome/GridAggregateMenu.js +27 -0
  41. package/dist/grid/chrome/GridCellEditors.d.ts +64 -0
  42. package/dist/grid/chrome/GridCellEditors.js +55 -0
  43. package/dist/grid/chrome/GridCellOutline.d.ts +70 -0
  44. package/dist/grid/chrome/GridCellOutline.js +21 -0
  45. package/dist/grid/chrome/GridChipsEditor.d.ts +28 -0
  46. package/dist/grid/chrome/GridChipsEditor.js +40 -0
  47. package/dist/grid/chrome/GridColumnColorSection.d.ts +11 -0
  48. package/dist/grid/chrome/GridColumnColorSection.js +40 -0
  49. package/dist/grid/chrome/GridColumnDateSection.d.ts +23 -0
  50. package/dist/grid/chrome/GridColumnDateSection.js +23 -0
  51. package/dist/grid/chrome/GridColumnDurationSection.d.ts +19 -0
  52. package/dist/grid/chrome/GridColumnDurationSection.js +24 -0
  53. package/dist/grid/chrome/GridColumnMenu.d.ts +101 -0
  54. package/dist/grid/chrome/GridColumnMenu.js +99 -0
  55. package/dist/grid/chrome/GridColumnNumberSection.d.ts +25 -0
  56. package/dist/grid/chrome/GridColumnNumberSection.js +27 -0
  57. package/dist/grid/chrome/GridColumnPercentSection.d.ts +15 -0
  58. package/dist/grid/chrome/GridColumnPercentSection.js +16 -0
  59. package/dist/grid/chrome/GridColumnSortSection.d.ts +18 -0
  60. package/dist/grid/chrome/GridColumnSortSection.js +16 -0
  61. package/dist/grid/chrome/GridDateEditor.d.ts +22 -0
  62. package/dist/grid/chrome/GridDateEditor.js +31 -0
  63. package/dist/grid/chrome/GridFlyout.d.ts +44 -0
  64. package/dist/grid/chrome/GridFlyout.js +80 -0
  65. package/dist/grid/chrome/GridFooter.d.ts +23 -0
  66. package/dist/grid/chrome/GridFooter.js +81 -0
  67. package/dist/grid/chrome/GridGroupMenu.d.ts +37 -0
  68. package/dist/grid/chrome/GridGroupMenu.js +57 -0
  69. package/dist/grid/chrome/GridHeader.d.ts +61 -0
  70. package/dist/grid/chrome/GridHeader.js +37 -0
  71. package/dist/grid/chrome/GridLongTextEditor.d.ts +36 -0
  72. package/dist/grid/chrome/GridLongTextEditor.js +127 -0
  73. package/dist/grid/chrome/GridMenuRow.d.ts +15 -0
  74. package/dist/grid/chrome/GridMenuRow.js +15 -0
  75. package/dist/grid/chrome/GridNameEditor.d.ts +19 -0
  76. package/dist/grid/chrome/GridNameEditor.js +36 -0
  77. package/dist/grid/chrome/GridNumberEditor.d.ts +35 -0
  78. package/dist/grid/chrome/GridNumberEditor.js +25 -0
  79. package/dist/grid/chrome/GridRangeEditor.d.ts +20 -0
  80. package/dist/grid/chrome/GridRangeEditor.js +25 -0
  81. package/dist/grid/chrome/GridRelationEditor.d.ts +21 -0
  82. package/dist/grid/chrome/GridRelationEditor.js +30 -0
  83. package/dist/grid/chrome/GridResizeHandle.d.ts +19 -0
  84. package/dist/grid/chrome/GridResizeHandle.js +19 -0
  85. package/dist/grid/chrome/GridRow.d.ts +25 -0
  86. package/dist/grid/chrome/GridRow.js +136 -0
  87. package/dist/grid/chrome/GridRowActions.d.ts +32 -0
  88. package/dist/grid/chrome/GridRowActions.js +25 -0
  89. package/dist/grid/chrome/GridRowCells.d.ts +4 -0
  90. package/dist/grid/chrome/GridRowCells.js +133 -0
  91. package/dist/grid/chrome/GridRowGlyph.d.ts +12 -0
  92. package/dist/grid/chrome/GridRowGlyph.js +13 -0
  93. package/dist/grid/chrome/GridSelectEditor.d.ts +18 -0
  94. package/dist/grid/chrome/GridSelectEditor.js +49 -0
  95. package/dist/grid/chrome/GridStructure.d.ts +48 -0
  96. package/dist/grid/chrome/GridStructure.js +45 -0
  97. package/dist/grid/chrome/GridTable.d.ts +4 -0
  98. package/dist/grid/chrome/GridTable.js +125 -0
  99. package/dist/grid/chrome/GridTableSurface.d.ts +15 -0
  100. package/dist/grid/chrome/GridTableSurface.js +6 -0
  101. package/dist/grid/chrome/GridTextEditor.d.ts +11 -0
  102. package/dist/grid/chrome/GridTextEditor.js +40 -0
  103. package/dist/grid/chrome/GridValueListEditor.d.ts +18 -0
  104. package/dist/grid/chrome/GridValueListEditor.js +36 -0
  105. package/dist/grid/chrome/StuckMarker.d.ts +16 -0
  106. package/dist/grid/chrome/StuckMarker.js +34 -0
  107. package/dist/grid/chrome/cell-clipboard.d.ts +9 -0
  108. package/dist/grid/chrome/cell-clipboard.js +28 -0
  109. package/dist/grid/chrome/cells.d.ts +21 -0
  110. package/dist/grid/chrome/cells.js +20 -0
  111. package/dist/grid/chrome/checks.d.ts +35 -0
  112. package/dist/grid/chrome/checks.js +22 -0
  113. package/dist/grid/chrome/column-glyph.d.ts +14 -0
  114. package/dist/grid/chrome/column-glyph.js +44 -0
  115. package/dist/grid/chrome/editors.d.ts +9 -0
  116. package/dist/grid/chrome/editors.js +10 -0
  117. package/dist/grid/chrome/grid-cell-classes.d.ts +59 -0
  118. package/dist/grid/chrome/grid-cell-classes.js +30 -0
  119. package/dist/grid/chrome/grid-menu-search.d.ts +7 -0
  120. package/dist/grid/chrome/grid-menu-search.js +7 -0
  121. package/dist/grid/chrome/grid-row-props.d.ts +131 -0
  122. package/dist/grid/chrome/grid-row-props.js +1 -0
  123. package/dist/grid/chrome/grid-styles.d.ts +37 -0
  124. package/dist/grid/chrome/grid-styles.js +8 -0
  125. package/dist/grid/chrome/grid-table-props.d.ts +173 -0
  126. package/dist/grid/chrome/grid-table-props.js +1 -0
  127. package/dist/grid/chrome/useGridBatchApi.d.ts +34 -0
  128. package/dist/grid/chrome/useGridBatchApi.js +35 -0
  129. package/dist/grid/chrome/useGridColumnLayout.d.ts +30 -0
  130. package/dist/grid/chrome/useGridColumnLayout.js +206 -0
  131. package/dist/grid/chrome/useGridHeaderDrag.d.ts +20 -0
  132. package/dist/grid/chrome/useGridHeaderDrag.js +37 -0
  133. package/dist/grid/chrome/useGridKeyboard.d.ts +47 -0
  134. package/dist/grid/chrome/useGridKeyboard.js +274 -0
  135. package/dist/grid/chrome/useGridPendingReconciliation.d.ts +12 -0
  136. package/dist/grid/chrome/useGridPendingReconciliation.js +32 -0
  137. package/dist/grid/chrome/useGridRailReveal.d.ts +57 -0
  138. package/dist/grid/chrome/useGridRailReveal.js +67 -0
  139. package/dist/grid/chrome/useGridRangeActions.d.ts +49 -0
  140. package/dist/grid/chrome/useGridRangeActions.js +188 -0
  141. package/dist/grid/chrome/useGridRangeGestures.d.ts +32 -0
  142. package/dist/grid/chrome/useGridRangeGestures.js +190 -0
  143. package/dist/grid/chrome/useGridRowContextMenu.d.ts +35 -0
  144. package/dist/grid/chrome/useGridRowContextMenu.js +127 -0
  145. package/dist/grid/chrome/useGridScaleStyles.d.ts +1 -0
  146. package/dist/grid/chrome/useGridScaleStyles.js +29 -0
  147. package/dist/grid/chrome/useGridScrollSync.d.ts +38 -0
  148. package/dist/grid/chrome/useGridScrollSync.js +176 -0
  149. package/dist/grid/chrome/useGridTableInteractionModel.d.ts +55 -0
  150. package/dist/grid/chrome/useGridTableInteractionModel.js +197 -0
  151. package/dist/grid/chrome/useGridTableSelection.d.ts +29 -0
  152. package/dist/grid/chrome/useGridTableSelection.js +55 -0
  153. package/dist/grid/chrome/useHeaderDragReorder.d.ts +21 -0
  154. package/dist/grid/chrome/useHeaderDragReorder.js +216 -0
  155. package/dist/grid/core/clipboard-model.d.ts +81 -0
  156. package/dist/grid/core/clipboard-model.js +291 -0
  157. package/dist/grid/core/column-values.d.ts +27 -0
  158. package/dist/grid/core/column-values.js +76 -0
  159. package/dist/grid/core/commit-model.d.ts +34 -0
  160. package/dist/grid/core/commit-model.js +3 -0
  161. package/dist/grid/core/coordinates.d.ts +48 -0
  162. package/dist/grid/core/coordinates.js +27 -0
  163. package/dist/grid/core/edit-values.d.ts +9 -0
  164. package/dist/grid/core/edit-values.js +1 -0
  165. package/dist/grid/core/editing-controller.d.ts +59 -0
  166. package/dist/grid/core/editing-controller.js +240 -0
  167. package/dist/grid/core/editing-model.d.ts +78 -0
  168. package/dist/grid/core/editing-model.js +136 -0
  169. package/dist/grid/core/grid-scale.d.ts +14 -0
  170. package/dist/grid/core/grid-scale.js +8 -0
  171. package/dist/grid/core/nav.d.ts +94 -0
  172. package/dist/grid/core/nav.js +92 -0
  173. package/dist/grid/core/pending-reconciliation.d.ts +50 -0
  174. package/dist/grid/core/pending-reconciliation.js +49 -0
  175. package/dist/grid/core/range-model.d.ts +25 -0
  176. package/dist/grid/core/range-model.js +59 -0
  177. package/dist/grid/core/spreadsheet-operations.d.ts +85 -0
  178. package/dist/grid/core/spreadsheet-operations.js +253 -0
  179. package/dist/grid/core/useGridEditing.d.ts +43 -0
  180. package/dist/grid/core/useGridEditing.js +90 -0
  181. package/dist/grid/core/useGridRange.d.ts +20 -0
  182. package/dist/grid/core/useGridRange.js +24 -0
  183. package/dist/grid/core/value-equality.d.ts +32 -0
  184. package/dist/grid/core/value-equality.js +34 -0
  185. package/dist/grid/index.d.ts +18 -0
  186. package/dist/grid/index.js +5 -0
  187. package/dist/grid/useGridTablePrefs.d.ts +50 -0
  188. package/dist/grid/useGridTablePrefs.js +101 -0
  189. package/dist/index.d.ts +0 -1
  190. package/dist/index.js +0 -1
  191. package/dist/internal/viewport.d.ts +5 -0
  192. package/dist/internal/viewport.js +29 -0
  193. package/dist/model/column-capabilities.d.ts +2 -2
  194. package/dist/model/column-state.d.ts +1 -1
  195. package/dist/model/density.js +3 -3
  196. package/dist/model/filter-capabilities.d.ts +1 -1
  197. package/dist/model/filter-capabilities.js +1 -1
  198. package/dist/model/index.d.ts +4 -6
  199. package/dist/model/index.js +0 -1
  200. package/dist/model/preferences.d.ts +7 -3
  201. package/dist/provider/ViewsProvider.d.ts +1 -1
  202. package/dist/provider/ViewsProvider.js +5 -1
  203. package/dist/provider/components.d.ts +16 -8
  204. package/dist/provider/context.d.ts +3 -2
  205. package/dist/provider/menu-groups.d.ts +8 -0
  206. package/dist/provider/menu-groups.js +38 -0
  207. package/dist/provider/ports.d.ts +22 -0
  208. package/dist/provider/ports.js +1 -0
  209. package/dist/react.d.ts +1 -1
  210. package/docs/contract.md +128 -56
  211. package/docs/getting-started.md +250 -0
  212. package/docs/guides/atoms.md +245 -0
  213. package/docs/guides/cells.md +302 -0
  214. package/docs/guides/columns.md +412 -0
  215. package/docs/guides/display.md +203 -0
  216. package/docs/guides/editors.md +404 -0
  217. package/docs/guides/ports.md +246 -0
  218. package/docs/guides/selection.md +270 -0
  219. package/docs/guides/the-grid.md +677 -0
  220. package/docs/guides/the-provider.md +446 -0
  221. package/docs/index.md +50 -0
  222. package/docs/install.md +9 -47
  223. package/docs/reference/cells.md +28 -0
  224. package/docs/reference/display.md +42 -0
  225. package/docs/reference/editors-chips.md +6 -0
  226. package/docs/reference/editors-date.md +6 -0
  227. package/docs/reference/editors-location.md +10 -0
  228. package/docs/reference/editors-name.md +6 -0
  229. package/docs/reference/editors-number.md +11 -0
  230. package/docs/reference/editors-open-values.md +9 -0
  231. package/docs/reference/editors-range.md +6 -0
  232. package/docs/reference/editors-relation.md +9 -0
  233. package/docs/reference/editors-select.md +8 -0
  234. package/docs/reference/editors-session.md +9 -0
  235. package/docs/reference/editors-value-list.md +6 -0
  236. package/docs/reference/editors.md +5 -0
  237. package/docs/reference/grid.md +39 -0
  238. package/docs/reference/react.md +86 -0
  239. package/docs/reference/selection.md +33 -0
  240. package/docs/reference/views.md +601 -0
  241. package/package.json +7 -3
  242. package/skills/views/SKILL.md +20 -5
  243. package/dist/filters/types.d.ts +0 -27
  244. package/dist/filters/types.js +0 -1
  245. package/dist/model/filter-pushdown.d.ts +0 -106
  246. package/dist/model/filter-pushdown.js +0 -147
@@ -25,6 +25,7 @@ export function readMoneyColumn(column, reading) {
25
25
  return column;
26
26
  const next = { ...column, reading };
27
27
  const format = { ...(column.format ?? {}) };
28
+ next.editAccessor = column.editAccessor ?? money.amount;
28
29
  if (reading === ORIGINAL_READING) {
29
30
  delete format.currency;
30
31
  next.accessor = money.amount;
@@ -25,7 +25,6 @@ export type FilterConfigBase = {
25
25
  /** Drives the default row icon via the shared kind-to-icon map. */
26
26
  kind?: FilterKind;
27
27
  countsAsFilter?: boolean;
28
- renderAs?: "filter" | "timeScope";
29
28
  /**
30
29
  * The dimension is LISTED but not openable — it has no editor on this
31
30
  * surface yet. Used by the column-derived filter list so a table's full set
@@ -80,22 +80,14 @@ export type GridFilterEntry = {
80
80
  };
81
81
  /** Keyed by GRID column id, never by database column. */
82
82
  export type ListFilterRegistry = Record<string, GridFilterEntry>;
83
- /** One explicit answer per column for hosts that opt into complete filtering
84
- * coverage. Legacy hosts omit the map and keep the existing local/source split. */
83
+ /** A column's answer in the Filter panel (`buildColumnFilters`): the column shows greyed with
84
+ * its reason (a saved view's column with no field behind it), so a stale rule can be cleared.
85
+ * A column with no entry filters as any column does. */
85
86
  export type ListFilterCapability = {
86
- mode: "server";
87
- } | {
88
- mode: "local";
89
- } | {
90
87
  mode: "unavailable";
91
88
  reason: string;
92
89
  };
93
90
  export type ListFilterCapabilities = Record<string, ListFilterCapability>;
94
- export declare class ListFilterCapabilityError extends Error {
95
- constructor(message: string);
96
- }
97
- /** Complete coverage and exact agreement with the source registry. */
98
- export declare function validateFilterCapabilities(columnIds: readonly string[], capabilities: ListFilterCapabilities, serverFilters?: ListFilterRegistry): ListFilterCapabilities;
99
91
  /** The shorthand a list actually writes: a bare string when the grid's column id
100
92
  * and the database column differ only in name, an object when they don't. */
101
93
  export type GridFilterRegistryInput = Record<string, string | GridFilterEntry>;
@@ -109,28 +101,3 @@ export declare const RESOLVED_AT_SOURCE: GridFilterEntry;
109
101
  * the source".
110
102
  */
111
103
  export declare function defineGridFilters(input: GridFilterRegistryInput): ListFilterRegistry;
112
- /** The column ids this list can filter at the source — what the client needs in
113
- * order to split its rules, and all it needs. It never sees the mapping. */
114
- export declare function gridFilterSupport(registry: ListFilterRegistry): string[];
115
- /**
116
- * The drift check, for a one-line test per list.
117
- *
118
- * Two failures it exists to catch, both silent in production:
119
- * - a registry naming a column id that no longer exists (renamed, removed) —
120
- * the rule then never pushes down and the page quietly under-fills again;
121
- * - a NEW column landing client-side because nobody decided either way.
122
- *
123
- * The second is why `expectedLocal` is required rather than optional: a list
124
- * states which of its columns are deliberately browser-only, so adding a column
125
- * forces a decision instead of defaulting to one.
126
- */
127
- export declare function auditGridFilters({ columnIds, registry, expectedLocal, }: {
128
- columnIds: readonly string[];
129
- registry: ListFilterRegistry;
130
- /** Column ids that filter in the browser ON PURPOSE — a derived value, a
131
- * joined label, anything the query can't reach. */
132
- expectedLocal: readonly string[];
133
- }): {
134
- unknown: string[];
135
- undecided: string[];
136
- };
@@ -1,29 +1,3 @@
1
- export class ListFilterCapabilityError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.name = "ListFilterCapabilityError";
5
- }
6
- }
7
- export function validateFilterCapabilities(columnIds, capabilities, serverFilters) {
8
- const columns = new Set(columnIds);
9
- const unknown = Object.keys(capabilities).filter((id) => !columns.has(id));
10
- const missing = columnIds.filter((id) => !capabilities[id]);
11
- if (unknown.length || missing.length) {
12
- throw new ListFilterCapabilityError(`filter capability coverage mismatch (missing: ${missing.join(", ") || "none"}; unknown: ${unknown.join(", ") || "none"})`);
13
- }
14
- const registryIds = new Set(Object.keys(serverFilters ?? {}));
15
- const missingSource = columnIds.filter((id) => capabilities[id]?.mode === "server" && !registryIds.has(id));
16
- const unexpectedSource = [...registryIds].filter((id) => !columns.has(id) || capabilities[id]?.mode !== "server");
17
- if (missingSource.length || unexpectedSource.length) {
18
- throw new ListFilterCapabilityError(`server filter registry mismatch (missing: ${missingSource.join(", ") || "none"}; unexpected: ${unexpectedSource.join(", ") || "none"})`);
19
- }
20
- for (const [id, capability] of Object.entries(capabilities)) {
21
- if (capability.mode === "unavailable" && !capability.reason.trim()) {
22
- throw new ListFilterCapabilityError(`unavailable filter capability "${id}" needs a reason`);
23
- }
24
- }
25
- return capabilities;
26
- }
27
1
  export const RESOLVED_AT_SOURCE = { resolved: true };
28
2
  export function defineGridFilters(input) {
29
3
  const out = {};
@@ -32,15 +6,3 @@ export function defineGridFilters(input) {
32
6
  }
33
7
  return out;
34
8
  }
35
- export function gridFilterSupport(registry) {
36
- return Object.keys(registry);
37
- }
38
- export function auditGridFilters({ columnIds, registry, expectedLocal, }) {
39
- const known = new Set(columnIds);
40
- const declared = new Set(Object.keys(registry));
41
- const intended = new Set(expectedLocal);
42
- return {
43
- unknown: Object.keys(registry).filter((id) => !known.has(id)),
44
- undecided: columnIds.filter((id) => !declared.has(id) && !intended.has(id)),
45
- };
46
- }
@@ -0,0 +1,11 @@
1
+ import type { ListColumnsConfig } from "../../model/column-state.js";
2
+ /**
3
+ * "+ ADD COLUMN" ON EVERY GRID: the header row's last cell, for anyone who reads the list. It lists the columns
4
+ * this view hides and can show, and shows the one picked: a choice about the reader's own view, never a change
5
+ * to a field, so it needs no admin and no server. Where a host mounts its own field editor, the header draws
6
+ * the host's instead (a relation's ›, Create new field), in the same look. Hiding is a column's own menu, the
7
+ * order is dragging the header, and the whole list is the host's column list.
8
+ */
9
+ export declare function GridAddColumn({ columns }: {
10
+ columns: ListColumnsConfig;
11
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,29 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useCallback, useState } from "react";
4
+ import { useViews } from "../../provider/context.js";
5
+ import { cx } from "../../internal/cx.js";
6
+ export function GridAddColumn({ columns }) {
7
+ const [open, setOpen] = useState(false);
8
+ const [query, setQuery] = useState("");
9
+ const [anchor, setAnchor] = useState(null);
10
+ const { atoms, components, icons, messages } = useViews();
11
+ const { Popover, Command } = components;
12
+ const { List, RowContent } = atoms;
13
+ const Add = icons.add;
14
+ const wanted = query.trim().toLowerCase();
15
+ const rows = columns.items.filter((item) => item.hidden && !item.fixed && item.label.toLowerCase().includes(wanted));
16
+ const close = (reason = "none") => {
17
+ setOpen(false);
18
+ setQuery("");
19
+ if (reason !== "outside-press" && reason !== "focus-out")
20
+ anchor?.focus({ preventScroll: true });
21
+ };
22
+ const focusSearch = useCallback((el) => el?.focus({ preventScroll: true }), []);
23
+ return (_jsxs(_Fragment, { children: [_jsxs("button", { ref: setAnchor, type: "button", "aria-haspopup": "dialog", "aria-expanded": open, onClick: () => (open ? close() : setOpen(true)), className: cx("flex h-full w-(--vk-tail-w) min-w-0 max-w-full flex-none items-center gap-1.5 px-(--vk-px) text-(length:--vk-head-text) hover:bg-(color:--vk-hovered)", open ? "bg-(color:--vk-pressed) text-(color:--vk-fg)" : "text-(color:--vk-fg-subtle)"), children: [_jsx(Add, { className: "h-(--vk-head-glyph) w-(--vk-head-glyph) shrink-0 opacity-70" }), _jsx("span", { className: "truncate", children: messages({ key: "views.grid.add-column" }) })] }), _jsx(Popover, { open: open, onOpenChange: (next, details) => (next ? setOpen(true) : close(details?.reason)), anchor: anchor, side: "bottom", align: "end", sideOffset: 4, chrome: "menu", initialFocus: false, className: "flex w-60 flex-col", onOutsidePress: (event) => (anchor?.contains(event.target) ? false : undefined), children: _jsxs(Command.Root, { shouldFilter: false, loop: true, label: messages({ key: "views.menus.add-column-search" }), children: [_jsx("div", { className: "flex h-10 shrink-0 items-center border-b border-(color:--vk-border)", children: _jsx(Command.Input, { chrome: "bare", value: query, onValueChange: setQuery, placeholder: messages({ key: "views.menus.add-column-search" }), ref: focusSearch, className: "h-full min-w-0 flex-1 bg-transparent px-3.5 text-base text-(color:--vk-fg) outline-hidden placeholder:text-(color:--vk-fg-subtlest) md:text-sm" }) }), _jsx(Command.List, { className: "max-h-80 min-h-0 overflow-y-auto overscroll-contain", children: _jsx(Command.Group, { className: "p-0", children: _jsxs(List, { children: [rows.map((item) => (_jsx(Command.Item, { value: item.id, onSelect: () => {
24
+ columns.onToggleHidden(item.id, false);
25
+ close("item-press");
26
+ }, children: _jsx(RowContent, { label: item.label, leading: _jsx("span", { className: "flex size-4 shrink-0 items-center justify-center text-(color:--vk-fg-subtle)", children: item.icon }) }) }, item.id))), rows.length === 0 && (_jsx("p", { className: "px-2 py-2 text-sm text-(color:--vk-fg-subtle)", children: wanted
27
+ ? messages({ key: "views.menus.add-column-no-match", values: { query: query.trim() } })
28
+ : messages({ key: "views.menus.add-column-all-shown" }) }))] }) }) })] }) })] }));
29
+ }
@@ -0,0 +1,31 @@
1
+ import { type MouseEvent as ReactMouseEvent, type ReactElement, type Ref } from "react";
2
+ import type { ListAggregateKind, ListColumn } from "../../model/column-schema.js";
3
+ /** What the menu sets on the footer cell it opens from. */
4
+ type TriggerProps = {
5
+ ref?: Ref<HTMLElement>;
6
+ onClick?: (event: ReactMouseEvent<HTMLElement>) => void;
7
+ role?: "button";
8
+ "aria-haspopup"?: "dialog";
9
+ "aria-expanded"?: boolean;
10
+ };
11
+ /**
12
+ * The footer cell's Calculate popover — pick the aggregate function for one
13
+ * column (numeric columns get sum/avg/min/max/count; everything else
14
+ * count/filled/unique; a source list's footer offers what the database answers,
15
+ * handed in as `options`). The trigger is the WHOLE footer cell, passed as the
16
+ * child: the map's popover anchors on it, in its slot; selection commits
17
+ * through the host's persisted `gridAggregates` pref.
18
+ */
19
+ export declare function GridAggregateMenu<Row>({ column, options, current, onChange, align, children, }: {
20
+ column: ListColumn<Row>;
21
+ /** The picks to offer — a source list's footer offers what the database
22
+ * answers (`aggregateOptions(column, sourced)`). Default: the column's own. */
23
+ options?: ListAggregateKind[];
24
+ current: ListAggregateKind;
25
+ onChange: (kind: ListAggregateKind) => void;
26
+ /** Match the column's alignment so the popover hugs the value. */
27
+ align: "start" | "center" | "end";
28
+ /** The footer cell. The menu sets its `ref`, so it must carry none of its own. */
29
+ children: ReactElement<TriggerProps>;
30
+ }): import("react/jsx-runtime").JSX.Element;
31
+ export {};
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { cloneElement, useState, } from "react";
4
+ import { aggregateLabel, aggregateOptions } from "../../model/aggregates.js";
5
+ import { useViews } from "../../provider/context.js";
6
+ export function GridAggregateMenu({ column, options, current, onChange, align, children, }) {
7
+ const [open, setOpen] = useState(false);
8
+ const [anchor, setAnchor] = useState(null);
9
+ const { atoms, components, messages } = useViews();
10
+ const { Popover } = components;
11
+ const { List, Row } = atoms;
12
+ const trigger = cloneElement(children, {
13
+ ref: setAnchor,
14
+ onClick: (event) => {
15
+ children.props.onClick?.(event);
16
+ setOpen((was) => !was);
17
+ },
18
+ role: "button",
19
+ "aria-haspopup": "dialog",
20
+ "aria-expanded": open,
21
+ });
22
+ return (_jsxs(_Fragment, { children: [trigger, _jsx(Popover, { open: open, onOpenChange: setOpen, anchor: anchor, side: "bottom", align: align, sideOffset: 4, chrome: "menu", panelData: { "data-slot": "vk-grid-aggregate-menu" }, className: "w-40", onOutsidePress: (event) => (anchor?.contains(event.target) ? false : undefined), children: _jsx(List, { children: (options ?? aggregateOptions(column)).map((kind) => (_jsx(Row, { chosen: kind === current, label: aggregateLabel(kind, messages), onClick: () => {
23
+ setOpen(false);
24
+ if (kind !== current)
25
+ onChange(kind);
26
+ } }, kind))) }) })] }));
27
+ }
@@ -0,0 +1,64 @@
1
+ import { type ReactNode } from "react";
2
+ import type { GridEditorId } from "../../model/column-types.js";
3
+ import type { ListColumn, ListSelectColor } from "../../model/column-schema.js";
4
+ /** Everything an editor needs about the cell it is mounting into. */
5
+ export type GridCellEditorContext<Row> = {
6
+ row: Row;
7
+ rowId: string;
8
+ col: ListColumn<Row>;
9
+ editorKind: GridEditorId | null;
10
+ /** The cell opened to be READ, not written: a long text the column, the
11
+ * workspace or the list will not let this user edit. The panel shows the
12
+ * value read-only and never commits. */
13
+ readOnly: boolean;
14
+ /** The value the editor opens on — pending overlay applied. */
15
+ baseline: unknown;
16
+ /** Type-to-replace seed: the character that opened this editor, or null. */
17
+ editSeed?: string | null;
18
+ decimals?: number;
19
+ selectValues?: string[];
20
+ optionColors?: Record<string, ListSelectColor>;
21
+ /** This app's glyph for an entity kind — the relation picker dresses its
22
+ * candidates with it, so a row in the list carries the same icon the cell
23
+ * will show once it is picked. */
24
+ entityIcon?: (kind: string | undefined) => ReactNode;
25
+ onCommitCell: (row: Row, rowId: string, columnId: string, prev: unknown, next: unknown, opts?: {
26
+ overlay?: boolean;
27
+ }) => void;
28
+ onCancel: () => void;
29
+ onTab: (backwards: boolean) => void;
30
+ onEnter: () => void;
31
+ };
32
+ /**
33
+ * The INLINE editors — the ones that replace the cell's own content while open.
34
+ *
35
+ * Returns null for every other case so the caller can fall through to the
36
+ * cell's normal render. In particular `text` is matched explicitly, never as a
37
+ * bare else: it is the last arm of the chain, and an unguarded fallback would
38
+ * mount a text input on top of an open picker, and on any editor-less type that
39
+ * ever reaches `editing`.
40
+ */
41
+ export declare function GridCellInlineEditor<Row>({ ctx }: {
42
+ ctx: GridCellEditorContext<Row>;
43
+ }): ReactNode;
44
+ /**
45
+ * The ANCHORED editors (select popover, date calendar). They hang off the END
46
+ * of the cell rather than wrapping its value, because the value has to keep its
47
+ * DOM NODE across the editing boundary.
48
+ *
49
+ * Both leave the cell's own content on screen behind an anchored overlay, so
50
+ * the natural shape is `<>{value}{editor}</>` while editing and a bare
51
+ * `{value}` otherwise. Those are different element types at the same position:
52
+ * React tears the value's node down on every commit and mounts a fresh one
53
+ * already showing the new value — so `transition-colors` on a status/category
54
+ * badge has no "from" state and the change SNAPS instead of fading. (The batch
55
+ * path never enters an editor, which is why it always faded.) Rendered as a
56
+ * sibling, the value's branch is identical whether or not the cell is editing,
57
+ * the node survives, and the commit is a plain className change it can animate.
58
+ *
59
+ * Position is free: both are absolutely-anchored and portal their content, so
60
+ * they contribute no layout. Do not "tidy" them back into the inline chain.
61
+ */
62
+ export declare function GridCellAnchoredEditor<Row>({ ctx, }: {
63
+ ctx: GridCellEditorContext<Row>;
64
+ }): ReactNode;
@@ -0,0 +1,55 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useMemo } from "react";
4
+ import { numberEditDecimals } from "../../fields/number-edit.js";
5
+ import { isIntegerField, isMultipleType, isNameValue, isRangeValue, rangeDecimals, relationIdOf } from "@viewkitjs/fields";
6
+ import { GridNameEditor } from "./GridNameEditor.js";
7
+ import { GridValueListEditor } from "./GridValueListEditor.js";
8
+ import { cellPrevPayload } from "./cell-clipboard.js";
9
+ import { GridChipsEditor, GridDateEditor, GridLongTextEditor, GridNumberEditor, GridRangeEditor, GridRelationEditor, GridSelectEditor, GridTextEditor, } from "./editors.js";
10
+ import { isLongTextColumn } from "../../model/column-inspect.js";
11
+ import { gridRelationSource } from "../../model/column-types.js";
12
+ export function GridCellInlineEditor({ ctx }) {
13
+ const { row, rowId, col, baseline, onCommitCell, onCancel, onTab, onEnter } = ctx;
14
+ if (ctx.editorKind === "number") {
15
+ const integer = col.field ? isIntegerField(col.field) : false;
16
+ const fallback = col.field ? numberEditDecimals(col.field) : (col.format?.decimals ?? 2);
17
+ const durationUnit = col.format?.style === "duration" ? (col.format.unit ?? "ms") : undefined;
18
+ return (_jsx(GridNumberEditor, { initial: typeof baseline === "number" ? baseline : Number.NaN, seed: ctx.editSeed ?? undefined, unit: col.editUnit?.value(row), unitOptions: col.editUnit?.options, decimals: integer ? 0 : (ctx.decimals ?? fallback), durationUnit: durationUnit, allowEmpty: !!col.clearable, unitLeft: col.align === "right", onCommit: (payload) => onCommitCell(row, rowId, col.id, cellPrevPayload(col, baseline, col.editUnit?.value(row)), payload, { overlay: false }), onCancel: onCancel, onTab: onTab, onEnter: onEnter }));
19
+ }
20
+ if (ctx.editorKind === "range") {
21
+ const def = col.field?.type === "range" ? col.field : undefined;
22
+ return (_jsx(GridRangeEditor, { initial: isRangeValue(baseline) ? baseline : null, seed: ctx.editSeed ?? undefined, decimals: def ? rangeDecimals(def) : 0, allowEmpty: !!col.clearable, suffix: def?.of === "percent" ? "%" : def?.of === "currency" ? def.code?.fixed : undefined, onCommit: (payload) => onCommitCell(row, rowId, col.id, baseline, payload, { overlay: false }), onCancel: onCancel, onTab: onTab, onEnter: onEnter }));
23
+ }
24
+ if (ctx.editorKind === "text" && !isLongTextColumn(col)) {
25
+ return (_jsx(GridTextEditor, { initial: ctx.editSeed ?? String(baseline ?? ""), strong: col.type === "title", onCommit: (value) => onCommitCell(row, rowId, col.id, String(baseline ?? ""), value), onCancel: onCancel, onTab: onTab, onEnter: onEnter }));
26
+ }
27
+ return null;
28
+ }
29
+ export function GridCellAnchoredEditor({ ctx, }) {
30
+ const { row, rowId, col, baseline, onCommitCell, onCancel } = ctx;
31
+ const relationSource = useMemo(() => gridRelationSource(col, ctx.entityIcon), [col, ctx.entityIcon]);
32
+ if (ctx.editorKind === "text" && isLongTextColumn(col)) {
33
+ return (_jsx(GridLongTextEditor, { initial: String(baseline ?? ""), seed: ctx.editSeed ?? undefined, readOnly: ctx.readOnly, markdown: col.type === "rich_text", onCommit: (value) => onCommitCell(row, rowId, col.id, String(baseline ?? ""), value), onCancel: onCancel, onTab: ctx.onTab, onEnter: ctx.onEnter }));
34
+ }
35
+ if (ctx.editorKind === "select") {
36
+ return (_jsx(GridSelectEditor, { column: col, values: ctx.selectValues ?? (col.options ?? []).map((o) => o.value), current: String(baseline ?? ""), optionColors: ctx.optionColors, onCommit: (value) => onCommitCell(row, rowId, col.id, String(baseline ?? ""), value), onCancel: onCancel }));
37
+ }
38
+ if (ctx.editorKind === "chips") {
39
+ const current = Array.isArray(baseline) ? baseline.map(String) : [];
40
+ return (_jsx(GridChipsEditor, { column: col, values: current, suggestions: ctx.selectValues ?? (col.options ?? []).map((option) => option.value), optionColors: ctx.optionColors, onCommit: (next) => onCommitCell(row, rowId, col.id, current, next), onCancel: onCancel }));
41
+ }
42
+ if (ctx.editorKind === "relation") {
43
+ return (_jsx(GridRelationEditor, { candidates: relationSource, current: relationIdOf(baseline), clearable: !!col.clearable, onCommit: (id) => onCommitCell(row, rowId, col.id, relationIdOf(baseline), id, { overlay: false }), onCancel: onCancel }));
44
+ }
45
+ if (ctx.editorKind === "name") {
46
+ return (_jsx(GridNameEditor, { initial: isNameValue(baseline) ? baseline : null, seed: ctx.editSeed ?? undefined, allowEmpty: !!col.clearable, onCommit: (payload) => onCommitCell(row, rowId, col.id, baseline, payload, { overlay: false }), onCancel: onCancel, onTab: ctx.onTab, onEnter: ctx.onEnter }));
47
+ }
48
+ if (ctx.editorKind === "values" && col.field && isMultipleType(col.field.type)) {
49
+ return (_jsx(GridValueListEditor, { field: col.field, initial: baseline, labels: col.labels !== false, allowEmpty: !!col.clearable, onCommit: (payload) => onCommitCell(row, rowId, col.id, baseline, payload, { overlay: false }), onCancel: onCancel, onTab: ctx.onTab, onEnter: ctx.onEnter }));
50
+ }
51
+ if (ctx.editorKind === "date") {
52
+ return (_jsx(GridDateEditor, { initial: String(baseline ?? "") || undefined, dayOnly: col.field?.type === "date", onCommit: (ymd) => onCommitCell(row, rowId, col.id, cellPrevPayload(col, baseline), ymd, { overlay: false }), onCancel: onCancel }));
53
+ }
54
+ return null;
55
+ }
@@ -0,0 +1,70 @@
1
+ /** A frozen cell's paint for its row's state: the ground and the row's hover, or, on a selected
2
+ * row, the ground with the selection tint and its own hover. One answer per state, so no class has
3
+ * to beat another (`cx` joins, it does not merge). */
4
+ export declare function gridFrozenBg(selected: boolean): string;
5
+ /**
6
+ * NOTE: the frozen block has NO edge treatment on ANY surface — header, rows and
7
+ * footer all end flat, and a frozen cell renders exactly like an unfrozen one.
8
+ * Nothing advertises that a column is pinned.
9
+ *
10
+ * The header used to fade its last frozen cell out over 72px (a mask, so the
11
+ * cell's whole output ramped down together — background, hover tint, border and
12
+ * label). It was removed: rows and footer were always flat, so the soft edge
13
+ * made the header the odd one out, and the mask took the resize hairline with it
14
+ * (alpha ~0 at the cell's right edge, where the handle lives).
15
+ *
16
+ * Rows had already rejected the same idea for their own reason: a mask fades the
17
+ * row's `border-b` and hover tint too, leaving a notch in every horizontal rule
18
+ * and a pale patch in the highlight at the Name column's edge — multiplied by
19
+ * the row count.
20
+ */
21
+ /**
22
+ * The freeze boundary — ONE shadow cast by the pinned block over the columns
23
+ * sliding under it.
24
+ *
25
+ * A shadow rather than a rule, because the boundary is a DEPTH statement: the
26
+ * pinned columns are floating above the ones passing beneath, and that is
27
+ * exactly what the eye reads from a cast shadow. A 1px line said "divider",
28
+ * which is the one thing every other column edge already says.
29
+ *
30
+ * ONE PER SURFACE, NOT ONE PER CELL. This started as a `box-shadow` on the last
31
+ * frozen cell, which is wrong at the first glance you give it: every row casts
32
+ * its own, so the band breaks at every row boundary and reads as a stack of
33
+ * short shadows rather than one edge. A table has ONE lit edge. So it lives
34
+ * outside the scrolled content — an overlay spanning the full height of its
35
+ * surface — and the rows know nothing about it.
36
+ *
37
+ * Its x is a fixed viewport position, which is what makes this work at all: the
38
+ * whole point of freezing is that the boundary does not move. So the overlay
39
+ * sits OUTSIDE the scroller and needs no sticky positioning, no transform, and
40
+ * no per-frame JS — the same `--vk-frozen-w` the layout already publishes puts
41
+ * it exactly where the block ends, and a live column resize re-lays it for free.
42
+ *
43
+ * Short and strong, not wide and soft: ~8px of travel, so it hugs the edge
44
+ * instead of smearing across the next column, with the alpha carrying the
45
+ * weight. A long faint gradient reads as a rendering artefact at this size.
46
+ * Alpha is roughly doubled in dark mode — the same asymmetry
47
+ * GRID_CELL_HOVER_SHADOW uses, because a shadow that reads on white disappears
48
+ * on a dark surface, where it is nearly the only depth cue available.
49
+ *
50
+ * Visible only when there is something to explain, via two flags multiplied
51
+ * together in the opacity:
52
+ * - `--vk-parked` (0/1, from the scroll sync) — the block has REACHED its
53
+ * stop. Not `--vk-scrolled`, which is the weaker "has moved at all": this
54
+ * band is drawn at the parked x, but the block travels for the first ~24px of
55
+ * scroll before it gets there. Gated on the weaker flag, the shadow appeared
56
+ * immediately and hung in open space while the title column was still sliding
57
+ * toward it. The two flags share a threshold with the block's own sticky
58
+ * stop, so on this one the band and the column's edge arrive together.
59
+ * - `--vk-frozen-on` (0/1, from the column layout) — with the freeze pref off
60
+ * or no title column there is no block, and the band would be a seam between
61
+ * two perfectly ordinary columns.
62
+ * Both are CSS vars rather than props on purpose: neither one re-renders a row.
63
+ */
64
+ export declare function GridFrozenShadow(): import("react/jsx-runtime").JSX.Element;
65
+ export declare const GRID_CELL_HOVER_SHADOW = "hover:shadow-[0_1px_2px_rgb(0_0_0/0.05)] dark:hover:shadow-[0_1px_2px_rgb(0_0_0/0.22)]";
66
+ export declare function GridCellOutline({ tone, editing, }: {
67
+ tone: "focus" | "hover";
68
+ /** `focus` only: lifts the cell with a drop shadow to read as a live input. */
69
+ editing?: boolean;
70
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx } from "../../internal/cx.js";
3
+ import { GRID_GROUND } from "./grid-styles.js";
4
+ const GRID_FROZEN_HOVER = "group-hover/gridrow:bg-[linear-gradient(var(--vk-hovered),var(--vk-hovered))]";
5
+ const GRID_FROZEN_BG_SELECTED = "bg-[linear-gradient(var(--vk-brand-subtlest),var(--vk-brand-subtlest))]";
6
+ const GRID_FROZEN_BG_SELECTED_HOVER = "group-hover/gridrow:bg-[linear-gradient(color-mix(in_oklab,_var(--vk-brand)_10%,_transparent),color-mix(in_oklab,_var(--vk-brand)_10%,_transparent)),linear-gradient(var(--vk-brand-subtlest),var(--vk-brand-subtlest))]";
7
+ export function gridFrozenBg(selected) {
8
+ return selected
9
+ ? cx(GRID_GROUND, GRID_FROZEN_BG_SELECTED, GRID_FROZEN_BG_SELECTED_HOVER)
10
+ : cx(GRID_GROUND, GRID_FROZEN_HOVER);
11
+ }
12
+ export function GridFrozenShadow() {
13
+ return (_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-y-0 z-8 w-1.5 bg-linear-to-r from-black/15 to-transparent opacity-[calc(var(--vk-parked,0)*var(--vk-frozen-on,0))] transition-opacity duration-150 dark:from-black/60", style: { left: "calc(var(--vk-rail-w) + var(--vk-frozen-w,0px))" } }));
14
+ }
15
+ export const GRID_CELL_HOVER_SHADOW = "hover:shadow-[0_1px_2px_rgb(0_0_0/0.05)] dark:hover:shadow-[0_1px_2px_rgb(0_0_0/0.22)]";
16
+ export function GridCellOutline({ tone, editing = false, }) {
17
+ if (tone === "hover") {
18
+ return (_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 z-1 rounded-sm border border-(color:--vk-border-bold) opacity-0 group-hover/gridcell:opacity-100" }));
19
+ }
20
+ return (_jsx("span", { "aria-hidden": true, "data-slot": "vk-grid-outline", className: cx("pointer-events-none absolute inset-0 z-1 rounded-sm border", editing ? "border-(color:--vk-border-brand)" : "border-(color:--vk-fg-subtle) group-hover/gridcell:border-(color:--vk-border-brand)", editing && "shadow-lg shadow-black/20 dark:shadow-black/50") }));
21
+ }
@@ -0,0 +1,28 @@
1
+ import type { ListColumn, ListSelectColor } from "../../model/column-schema.js";
2
+ /**
3
+ * The GRID's host around the shared `ChipsEditor` (`@viewkitjs/views/editors/chips`) —
4
+ * the set-editing panel is one component across every surface; this host owns
5
+ * the grid's mechanics: anchor to the cell rect, open on mount, WHICH close
6
+ * happened, the exit animation gap, and the write.
7
+ *
8
+ * Telling Escape from an outside click matters more here than anywhere else,
9
+ * because the two mean OPPOSITE things for a set: Escape discards the session,
10
+ * an outside click keeps what you built. Radix funnels both into one
11
+ * `onOpenChange`, so they are caught by the content's own handlers first.
12
+ */
13
+ export declare function GridChipsEditor<Row>({ column, values, suggestions, optionColors, onCommit, onCancel, }: {
14
+ /** Read for its declared `options` — the labels and colours the cell uses. */
15
+ column: ListColumn<Row>;
16
+ /** The cell's current values. */
17
+ values: string[];
18
+ /** What this column holds on screen, from `deriveGridSelectValues`. An open
19
+ * field's values the list's source answers come first (`useOpenValues`), as
20
+ * the Filter panel offers them, so a value you can set is one you can then
21
+ * filter for. */
22
+ suggestions: string[];
23
+ /** This column's per-user colour overrides, so a badge here is the badge the
24
+ * cell draws. */
25
+ optionColors?: Record<string, ListSelectColor>;
26
+ onCommit: (next: string[]) => void;
27
+ onCancel: () => void;
28
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useRef, useState } from "react";
4
+ import { useViews } from "../../provider/context.js";
5
+ import { ChipsEditor } from "../../editors/ChipsEditor.js";
6
+ import { resolveCategoryColor } from "@viewkitjs/fields/design/category-colors";
7
+ import { prettifyOptionValue } from "../../model/column-state.js";
8
+ import { offeredValues, useOpenValues } from "../../editors/open-values.js";
9
+ export function GridChipsEditor({ column, values, suggestions, optionColors, onCommit, onCancel, }) {
10
+ const { Popover } = useViews().components;
11
+ const [open, setOpen] = useState(true);
12
+ const editorRef = useRef(null);
13
+ const anchorRef = useRef(null);
14
+ const closedRef = useRef(false);
15
+ const known = useOpenValues(column.field);
16
+ const offered = column.field ? offeredValues(column.field, known, suggestions) : suggestions;
17
+ const EXIT_MS = 160;
18
+ const close = (reason) => {
19
+ if (closedRef.current)
20
+ return;
21
+ closedRef.current = true;
22
+ const resolution = editorRef.current?.resolveClose(reason) ?? { kind: "noop" };
23
+ setOpen(false);
24
+ window.setTimeout(() => {
25
+ if (resolution.kind === "commit")
26
+ onCommit(resolution.payload);
27
+ else
28
+ onCancel();
29
+ }, EXIT_MS);
30
+ };
31
+ const resolve = (value) => ({
32
+ value,
33
+ label: column.options?.find((option) => option.value === value)?.label ?? prettifyOptionValue(value),
34
+ color: resolveCategoryColor(value, column.options, optionColors),
35
+ });
36
+ return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(Popover, { open: open, onOpenChange: (next) => {
37
+ if (!next)
38
+ close("outside");
39
+ }, anchor: anchorRef, align: "start", sideOffset: 4, onEscape: () => close("escape"), onOutsidePress: () => close("outside"), initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (event) => event.stopPropagation(), chrome: "menu", className: "w-64 z-90", children: _jsx(ChipsEditor, { ref: editorRef, values: values, suggestions: offered, resolve: resolve, normalize: column.chips?.normalize, onRequestClose: close }) })] }));
40
+ }
@@ -0,0 +1,11 @@
1
+ import type { ListColumn, ListSelectColor } from "../../model/column-schema.js";
2
+ import { type GridFlyouts } from "./GridFlyout.js";
3
+ export declare function GridColumnColorSection<Row>({ column, values, optionColors, flyouts, onOptionColorChange, onClose, }: {
4
+ column: ListColumn<Row>;
5
+ values: string[];
6
+ optionColors?: Record<string, ListSelectColor>;
7
+ flyouts: GridFlyouts;
8
+ /** Called with the FIELD key — the format map's key on every surface. */
9
+ onOptionColorChange: (key: string, value: string, color: ListSelectColor | null) => void;
10
+ onClose: () => void;
11
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { CATEGORY_DOT_CLASSES, resolveCategoryColor, } from "@viewkitjs/fields/design/category-colors";
4
+ import { prettifyOptionValue } from "../../model/column-state.js";
5
+ import { fieldKeyOf } from "../../model/view-rules.js";
6
+ import { useViews } from "../../provider/context.js";
7
+ import { cx } from "../../internal/cx.js";
8
+ import { GridFlyoutRow } from "./GridFlyout.js";
9
+ import { GridMenuSeparator } from "./GridMenuRow.js";
10
+ const COLOR_DOTS = CATEGORY_DOT_CLASSES;
11
+ const ALL_COLORS = [
12
+ "gray",
13
+ "blue",
14
+ "green",
15
+ "amber",
16
+ "red",
17
+ "purple",
18
+ "pink",
19
+ "teal",
20
+ ];
21
+ export function GridColumnColorSection({ column, values, optionColors, flyouts, onOptionColorChange, onClose, }) {
22
+ const { atoms, messages } = useViews();
23
+ const { Row, Tag } = atoms;
24
+ return (_jsxs(_Fragment, { children: [_jsx("div", { className: "max-h-72 overflow-y-auto overscroll-contain", children: values.map((value) => {
25
+ const resolved = resolveCategoryColor(value, column.options, optionColors);
26
+ return (_jsxs(GridFlyoutRow, { id: `color:${value}`, flyouts: flyouts, title: prettifyOptionValue(value), label: _jsx(Tag, { label: column.options?.find((option) => option.value === value)?.label ??
27
+ prettifyOptionValue(value), color: resolved }), children: [_jsx(Row, { chosen: !optionColors?.[value], label: messages({ key: "views.menus.automatic" }), leading: _jsx("span", { className: "h-2.5 w-2.5 rounded-full border border-(color:--vk-border)" }), onClick: () => {
28
+ onOptionColorChange(fieldKeyOf(column), value, null);
29
+ flyouts.close();
30
+ } }), ALL_COLORS.map((color) => (_jsx(Row, { chosen: resolved === color, label: messages({ key: "views.menus.colour", values: { colour: color } }), leading: _jsx("span", { className: cx("h-2.5 w-2.5 rounded-full", COLOR_DOTS[color]) }), onClick: () => {
31
+ onOptionColorChange(fieldKeyOf(column), value, color);
32
+ flyouts.close();
33
+ } }, color)))] }, value));
34
+ }) }), optionColors && Object.keys(optionColors).length > 0 && (_jsxs(_Fragment, { children: [_jsx(GridMenuSeparator, {}), _jsx(Row, { label: messages({ key: "views.menus.colours-reset" }), onClick: () => {
35
+ for (const value of Object.keys(optionColors)) {
36
+ onOptionColorChange(fieldKeyOf(column), value, null);
37
+ }
38
+ onClose();
39
+ } })] }))] }));
40
+ }
@@ -0,0 +1,23 @@
1
+ import type { ListColumn } from "../../model/column-schema.js";
2
+ import type { ListDateStyle } from "../../model/column-format.js";
3
+ import { type GridFlyouts } from "./GridFlyout.js";
4
+ /**
5
+ * The date-column row in the header menu — one Format row whose flyout holds
6
+ * the styles (each beside a live sample) and, on a date-time, Show time —
7
+ * split out of GridColumnMenu because that file is held under the component
8
+ * ratchet's line ceiling rather than grown to hold them; the policy there is
9
+ * split, not raise (the same reason GridColumnColorSection and
10
+ * GridColumnDurationSection are their own files rather than inline).
11
+ */
12
+ export declare function GridColumnDateSection<Row>({ column, dateStyle, onDateStyleChange, showTime, onShowTimeChange, flyouts, onClose, }: {
13
+ column: ListColumn<Row>;
14
+ /** This column's date-style override. */
15
+ dateStyle?: ListDateStyle;
16
+ /** Both handlers are called with the FIELD key — the format map's key. */
17
+ onDateStyleChange: (key: string, style: ListDateStyle) => void;
18
+ /** Resolved show-time (override → declared `format.withTime`). */
19
+ showTime?: boolean;
20
+ onShowTimeChange?: (key: string, show: boolean) => void;
21
+ flyouts: GridFlyouts;
22
+ onClose: () => void;
23
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { temporalKindOf } from "../../model/field-type-of.js";
4
+ import { fieldKeyOf } from "../../model/view-rules.js";
5
+ import { formatDate } from "./cells.js";
6
+ import { useCellFormat } from "../../cells/use-cell-format.js";
7
+ import { useViews } from "../../provider/context.js";
8
+ import { GridFlyoutRow } from "./GridFlyout.js";
9
+ import { GridMenuSeparator, KnobGlyph } from "./GridMenuRow.js";
10
+ const DATE_STYLES = ["short", "long", "numeric", "relative"];
11
+ const sampleDate = () => new Date(Date.now() - 3 * 86_400_000);
12
+ export function GridColumnDateSection({ column, dateStyle, onDateStyleChange, showTime, onShowTimeChange, flyouts, onClose, }) {
13
+ const activeDateStyle = dateStyle ?? column.format?.dateStyle ?? "short";
14
+ const sample = sampleDate();
15
+ const { viewer } = useCellFormat();
16
+ const { atoms, messages } = useViews();
17
+ const { Row } = atoms;
18
+ const styleLabel = (style) => messages({ key: "views.menus.date-style", values: { style } });
19
+ return (_jsxs(GridFlyoutRow, { id: "date-format", flyouts: flyouts, label: messages({ key: "views.menus.format" }), detail: styleLabel(activeDateStyle), leading: _jsx(KnobGlyph, { name: "calendar" }), children: [DATE_STYLES.map((style) => (_jsx(Row, { chosen: activeDateStyle === style, label: styleLabel(style), detail: _jsx("span", { className: "max-w-30 truncate", children: formatDate(sample, column, style, false, viewer) }), onClick: () => {
20
+ onDateStyleChange(fieldKeyOf(column), style);
21
+ onClose();
22
+ } }, style))), onShowTimeChange && temporalKindOf(column) === "datetime" && (_jsxs(_Fragment, { children: [_jsx(GridMenuSeparator, {}), _jsx(Row, { chosen: !!showTime, label: messages({ key: "views.menus.show-time" }), onClick: () => onShowTimeChange(fieldKeyOf(column), !showTime) })] }))] }));
23
+ }