@viewkitjs/views 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/CHANGELOG.md +641 -0
  2. package/README.md +3 -3
  3. package/dist/atoms/CommandMenu.d.ts +1 -1
  4. package/dist/atoms/CommandMenu.js +7 -3
  5. package/dist/atoms/DrillRows.d.ts +3 -0
  6. package/dist/atoms/DrillRows.js +25 -0
  7. package/dist/atoms/PanelRows.d.ts +5 -0
  8. package/dist/atoms/PanelRows.js +40 -0
  9. package/dist/atoms/PanelSearch.d.ts +2 -0
  10. package/dist/atoms/PanelSearch.js +21 -0
  11. package/dist/atoms/RelationRoles.d.ts +2 -0
  12. package/dist/atoms/RelationRoles.js +6 -0
  13. package/dist/atoms/Row.js +2 -1
  14. package/dist/atoms/RowMenu.js +2 -1
  15. package/dist/atoms/SelectionSheet.d.ts +3 -0
  16. package/dist/atoms/SelectionSheet.js +30 -0
  17. package/dist/atoms/StatusMarker.js +3 -1
  18. package/dist/atoms/Tag.js +2 -1
  19. package/dist/atoms/defaults.js +14 -0
  20. package/dist/atoms/types.d.ts +146 -8
  21. package/dist/cells/cell-values.js +4 -2
  22. package/dist/cells/relation-wrap.js +3 -1
  23. package/dist/contract.d.ts +212 -17
  24. package/dist/contract.js +208 -6
  25. package/dist/display/boolean.js +3 -1
  26. package/dist/display/date.d.ts +1 -1
  27. package/dist/display/date.js +4 -2
  28. package/dist/display/format.js +20 -4
  29. package/dist/display/link.js +4 -3
  30. package/dist/display/multi-value.js +2 -1
  31. package/dist/display/percent.js +2 -1
  32. package/dist/display/phone.js +2 -1
  33. package/dist/display/range.js +3 -13
  34. package/dist/display/relation.js +23 -8
  35. package/dist/display/rich-text.js +2 -1
  36. package/dist/editors/ChipsEditor.d.ts +5 -1
  37. package/dist/editors/ChipsEditor.js +15 -2
  38. package/dist/editors/DateEditor.d.ts +2 -0
  39. package/dist/editors/DateEditor.js +76 -10
  40. package/dist/editors/EditorPanel.d.ts +14 -4
  41. package/dist/editors/EditorPanel.js +21 -4
  42. package/dist/editors/LocationEditor.js +35 -3
  43. package/dist/editors/NumberEditor.js +3 -2
  44. package/dist/editors/RangeEditor.d.ts +8 -0
  45. package/dist/editors/RangeEditor.js +3 -2
  46. package/dist/editors/RelationEditor.d.ts +2 -0
  47. package/dist/editors/RelationEditor.js +16 -2
  48. package/dist/editors/RelationSetEditor.d.ts +4 -2
  49. package/dist/editors/RelationSetEditor.js +36 -2
  50. package/dist/editors/SelectEditor.d.ts +5 -2
  51. package/dist/editors/SelectEditor.js +31 -4
  52. package/dist/editors/TextEditor.js +3 -1
  53. package/dist/editors/ValueListEditor.d.ts +3 -0
  54. package/dist/editors/ValueListEditor.js +10 -4
  55. package/dist/editors/edit-session.d.ts +14 -2
  56. package/dist/editors/edit-session.js +13 -5
  57. package/dist/editors/escape-rule.d.ts +12 -0
  58. package/dist/editors/escape-rule.js +8 -0
  59. package/dist/editors/open-value.js +2 -1
  60. package/dist/editors/picker-slot.d.ts +25 -0
  61. package/dist/editors/picker-slot.js +37 -0
  62. package/dist/editors/relation-picker.d.ts +44 -0
  63. package/dist/editors/relation-picker.js +49 -0
  64. package/dist/editors/relation-source.d.ts +1 -0
  65. package/dist/editors/relation-source.js +7 -1
  66. package/dist/field-row/FieldNoteLine.js +2 -1
  67. package/dist/field-row/FieldRow.js +41 -6
  68. package/dist/field-row/FieldRowLane.js +3 -1
  69. package/dist/field-row/editors/RowChipsEditor.js +1 -1
  70. package/dist/field-row/editors/RowDateEditor.js +1 -1
  71. package/dist/field-row/editors/RowEditor.js +2 -1
  72. package/dist/field-row/editors/RowRangeEditor.js +2 -1
  73. package/dist/field-row/editors/RowRelationEditor.js +2 -2
  74. package/dist/field-row/editors/RowSelectEditor.d.ts +1 -1
  75. package/dist/field-row/editors/RowSelectEditor.js +2 -2
  76. package/dist/field-row/editors/RowValueListEditor.js +1 -1
  77. package/dist/field-row/editors/host.d.ts +3 -0
  78. package/dist/field-row/editors/row-session.js +4 -1
  79. package/dist/fields/menus.d.ts +2 -0
  80. package/dist/fields/range-unit.d.ts +7 -0
  81. package/dist/fields/range-unit.js +13 -0
  82. package/dist/figures.d.ts +5 -48
  83. package/dist/figures.js +1 -63
  84. package/dist/grid/chrome/GridAddColumn.d.ts +8 -0
  85. package/dist/grid/chrome/GridAddColumn.js +66 -9
  86. package/dist/grid/chrome/GridAggregateMenu.d.ts +5 -2
  87. package/dist/grid/chrome/GridAggregateMenu.js +33 -4
  88. package/dist/grid/chrome/GridCellEditors.d.ts +9 -2
  89. package/dist/grid/chrome/GridCellEditors.js +24 -5
  90. package/dist/grid/chrome/GridCellOutline.d.ts +3 -2
  91. package/dist/grid/chrome/GridCellOutline.js +11 -1
  92. package/dist/grid/chrome/GridChipsEditor.js +1 -1
  93. package/dist/grid/chrome/GridColumnColorSection.d.ts +2 -0
  94. package/dist/grid/chrome/GridColumnColorSection.js +2 -2
  95. package/dist/grid/chrome/GridColumnDateSection.d.ts +4 -0
  96. package/dist/grid/chrome/GridColumnDateSection.js +2 -2
  97. package/dist/grid/chrome/GridColumnDurationSection.d.ts +4 -0
  98. package/dist/grid/chrome/GridColumnDurationSection.js +2 -2
  99. package/dist/grid/chrome/GridColumnMenu.d.ts +10 -6
  100. package/dist/grid/chrome/GridColumnMenu.js +62 -24
  101. package/dist/grid/chrome/GridColumnNumberSection.d.ts +4 -0
  102. package/dist/grid/chrome/GridColumnNumberSection.js +2 -2
  103. package/dist/grid/chrome/GridColumnPercentSection.d.ts +1 -0
  104. package/dist/grid/chrome/GridColumnPercentSection.js +1 -1
  105. package/dist/grid/chrome/GridColumnSortSection.d.ts +3 -3
  106. package/dist/grid/chrome/GridDateEditor.js +1 -1
  107. package/dist/grid/chrome/GridFooter.js +7 -48
  108. package/dist/grid/chrome/GridGroupMenu.d.ts +11 -5
  109. package/dist/grid/chrome/GridGroupMenu.js +28 -13
  110. package/dist/grid/chrome/GridHeader.d.ts +3 -1
  111. package/dist/grid/chrome/GridHeader.js +8 -8
  112. package/dist/grid/chrome/GridNumberEditor.js +3 -24
  113. package/dist/grid/chrome/GridRangeEditor.js +3 -2
  114. package/dist/grid/chrome/GridRelationEditor.js +2 -2
  115. package/dist/grid/chrome/GridRow.d.ts +2 -1
  116. package/dist/grid/chrome/GridRow.js +13 -37
  117. package/dist/grid/chrome/GridRowActions.js +2 -1
  118. package/dist/grid/chrome/GridRowCells.js +9 -4
  119. package/dist/grid/chrome/GridSelectEditor.js +30 -20
  120. package/dist/grid/chrome/GridStructure.d.ts +11 -4
  121. package/dist/grid/chrome/GridStructure.js +19 -7
  122. package/dist/grid/chrome/GridTable.js +138 -16
  123. package/dist/grid/chrome/GridTableSurface.d.ts +25 -12
  124. package/dist/grid/chrome/GridTableSurface.js +13 -6
  125. package/dist/grid/chrome/GridTextEditor.js +3 -1
  126. package/dist/grid/chrome/GridValueListEditor.js +1 -1
  127. package/dist/grid/chrome/cell-clipboard.d.ts +1 -1
  128. package/dist/grid/chrome/cell-clipboard.js +1 -1
  129. package/dist/grid/chrome/checks.d.ts +10 -2
  130. package/dist/grid/chrome/checks.js +17 -11
  131. package/dist/grid/chrome/column-glyph.d.ts +2 -2
  132. package/dist/grid/chrome/column-glyph.js +4 -0
  133. package/dist/grid/chrome/grid-add-column-items.d.ts +13 -0
  134. package/dist/grid/chrome/grid-add-column-items.js +40 -0
  135. package/dist/grid/chrome/grid-cell-classes.d.ts +2 -0
  136. package/dist/grid/chrome/grid-cell-classes.js +10 -4
  137. package/dist/grid/chrome/grid-column-menu-items.d.ts +75 -0
  138. package/dist/grid/chrome/grid-column-menu-items.js +263 -0
  139. package/dist/grid/chrome/grid-edit-escape.d.ts +4 -0
  140. package/dist/grid/chrome/grid-edit-escape.js +12 -0
  141. package/dist/grid/chrome/grid-edit-session.d.ts +2 -1
  142. package/dist/grid/chrome/grid-edit-session.js +14 -1
  143. package/dist/grid/chrome/grid-figure-value.d.ts +25 -0
  144. package/dist/grid/chrome/grid-figure-value.js +40 -0
  145. package/dist/grid/chrome/grid-fitted-box.d.ts +15 -0
  146. package/dist/grid/chrome/grid-fitted-box.js +26 -0
  147. package/dist/grid/chrome/grid-group-menu-items.d.ts +31 -0
  148. package/dist/grid/chrome/grid-group-menu-items.js +75 -0
  149. package/dist/grid/chrome/grid-group-menu-parts.d.ts +27 -0
  150. package/dist/grid/chrome/grid-group-menu-parts.js +19 -0
  151. package/dist/grid/chrome/grid-hover.d.ts +1 -0
  152. package/dist/grid/chrome/grid-hover.js +13 -1
  153. package/dist/grid/chrome/grid-lab.d.ts +7 -0
  154. package/dist/grid/chrome/grid-lab.js +7 -0
  155. package/dist/grid/chrome/grid-menu-focus.d.ts +12 -0
  156. package/dist/grid/chrome/grid-menu-focus.js +13 -0
  157. package/dist/grid/chrome/{useGridRowContextMenu.d.ts → grid-row-menu-items.d.ts} +15 -4
  158. package/dist/grid/chrome/{useGridRowContextMenu.js → grid-row-menu-items.js} +15 -18
  159. package/dist/grid/chrome/grid-row-props.d.ts +3 -1
  160. package/dist/grid/chrome/grid-row-window.d.ts +15 -5
  161. package/dist/grid/chrome/grid-row-window.js +44 -10
  162. package/dist/grid/chrome/grid-rows-menu.d.ts +38 -0
  163. package/dist/grid/chrome/grid-rows-menu.js +83 -0
  164. package/dist/grid/chrome/grid-table-props.d.ts +53 -8
  165. package/dist/grid/chrome/useGridBandFigures.d.ts +26 -0
  166. package/dist/grid/chrome/useGridBandFigures.js +50 -0
  167. package/dist/grid/chrome/useGridBoxes.d.ts +22 -0
  168. package/dist/grid/chrome/useGridBoxes.js +22 -0
  169. package/dist/grid/chrome/useGridColumnLayout.js +29 -4
  170. package/dist/grid/chrome/useGridKeyboard.js +7 -2
  171. package/dist/grid/chrome/useGridPartColumns.d.ts +5 -0
  172. package/dist/grid/chrome/useGridPartColumns.js +9 -0
  173. package/dist/grid/chrome/useGridRangeGestures.js +2 -1
  174. package/dist/grid/chrome/useGridRecorder.d.ts +16 -0
  175. package/dist/grid/chrome/useGridRecorder.js +144 -0
  176. package/dist/grid/chrome/useGridRowOpener.d.ts +41 -0
  177. package/dist/grid/chrome/useGridRowOpener.js +83 -0
  178. package/dist/grid/chrome/useGridScrollArea.d.ts +38 -12
  179. package/dist/grid/chrome/useGridScrollArea.js +70 -17
  180. package/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -0
  181. package/dist/grid/chrome/useGridTableInteractionModel.js +67 -9
  182. package/dist/grid/core/clipboard-model.d.ts +11 -3
  183. package/dist/grid/core/clipboard-model.js +9 -4
  184. package/dist/grid/core/commit-model.d.ts +7 -0
  185. package/dist/grid/core/editing-controller.d.ts +31 -1
  186. package/dist/grid/core/editing-controller.js +65 -0
  187. package/dist/grid/core/grid-recorder.d.ts +111 -0
  188. package/dist/grid/core/grid-recorder.js +223 -0
  189. package/dist/grid/core/part-edits.d.ts +18 -0
  190. package/dist/grid/core/part-edits.js +48 -0
  191. package/dist/grid/core/pending-reconciliation.js +12 -3
  192. package/dist/grid/core/refusal-sentence.d.ts +3 -0
  193. package/dist/grid/core/refusal-sentence.js +15 -0
  194. package/dist/grid/core/row-opened-from.d.ts +21 -0
  195. package/dist/grid/core/row-opened-from.js +11 -0
  196. package/dist/grid/core/useGridEditing.d.ts +16 -2
  197. package/dist/grid/core/useGridEditing.js +10 -4
  198. package/dist/grid/core/value-equality.d.ts +19 -1
  199. package/dist/grid/core/value-equality.js +24 -0
  200. package/dist/grid/index.d.ts +4 -1
  201. package/dist/grid/index.js +1 -0
  202. package/dist/grid/useGridTablePrefs.d.ts +1 -1
  203. package/dist/grid-lab.d.ts +18 -0
  204. package/dist/grid-lab.js +16 -0
  205. package/dist/grouping/sort-groups.d.ts +6 -7
  206. package/dist/index.d.ts +1 -0
  207. package/dist/index.js +1 -0
  208. package/dist/internal/reset.d.ts +9 -0
  209. package/dist/internal/reset.js +1 -0
  210. package/dist/model/aggregates.d.ts +3 -3
  211. package/dist/model/aggregates.js +17 -71
  212. package/dist/model/column-capabilities.d.ts +29 -2
  213. package/dist/model/column-capabilities.js +27 -3
  214. package/dist/model/column-filters.js +24 -4
  215. package/dist/model/column-inspect.d.ts +2 -1
  216. package/dist/model/column-order.d.ts +2 -2
  217. package/dist/model/column-schema.d.ts +18 -7
  218. package/dist/model/column-state.d.ts +9 -20
  219. package/dist/model/column-state.js +1 -4
  220. package/dist/model/column-types.d.ts +1 -15
  221. package/dist/model/column-types.js +1 -1
  222. package/dist/model/part-columns.d.ts +17 -0
  223. package/dist/model/part-columns.js +67 -0
  224. package/dist/model/part-rows.d.ts +3 -10
  225. package/dist/model/part-rows.js +6 -11
  226. package/dist/model/part-write.d.ts +11 -0
  227. package/dist/model/part-write.js +52 -0
  228. package/dist/model/preferences.d.ts +3 -23
  229. package/dist/model/preferences.js +1 -17
  230. package/dist/model/prefs-buckets.d.ts +0 -27
  231. package/dist/model/prefs-buckets.js +1 -1
  232. package/dist/model/relation-filters.d.ts +0 -1
  233. package/dist/model/relation-filters.js +1 -1
  234. package/dist/model/row-icon.d.ts +5 -9
  235. package/dist/model/view-rules.d.ts +32 -6
  236. package/dist/model/view-rules.js +101 -21
  237. package/dist/provider/ViewsProvider.d.ts +22 -2
  238. package/dist/provider/ViewsProvider.js +21 -2
  239. package/dist/provider/components.d.ts +197 -9
  240. package/dist/provider/context.d.ts +12 -1
  241. package/dist/provider/desktop.d.ts +3 -0
  242. package/dist/provider/desktop.js +7 -4
  243. package/dist/provider/menu-groups.d.ts +3 -2
  244. package/dist/provider/menu-groups.js +13 -7
  245. package/dist/provider/missing-slot.d.ts +10 -0
  246. package/dist/provider/missing-slot.js +15 -0
  247. package/dist/provider/plain-input.d.ts +3 -2
  248. package/dist/provider/plain-input.js +3 -1
  249. package/dist/react.d.ts +3 -2
  250. package/dist/selection/SelectionBar.d.ts +18 -0
  251. package/dist/selection/SelectionBar.js +92 -0
  252. package/dist/selection/SelectionBarPhone.d.ts +3 -0
  253. package/dist/selection/SelectionBarPhone.js +14 -0
  254. package/dist/selection/bar-overflow.d.ts +12 -0
  255. package/dist/selection/bar-overflow.js +42 -0
  256. package/dist/selection/bar-parts.d.ts +15 -0
  257. package/dist/selection/bar-parts.js +17 -0
  258. package/dist/selection/index.d.ts +2 -0
  259. package/dist/selection/index.js +1 -0
  260. package/dist/selection/types.d.ts +3 -2
  261. package/dist/selection/verbs.d.ts +34 -0
  262. package/dist/selection/verbs.js +1 -0
  263. package/docs/contract.md +142 -39
  264. package/docs/getting-started.md +1 -1
  265. package/docs/guides/atoms.md +32 -4
  266. package/docs/guides/columns.md +1 -1
  267. package/docs/guides/display.md +1 -1
  268. package/docs/guides/editors.md +3 -3
  269. package/docs/guides/ports.md +1 -1
  270. package/docs/guides/selection.md +32 -20
  271. package/docs/guides/the-grid.md +43 -21
  272. package/docs/guides/the-provider.md +14 -4
  273. package/docs/index.md +2 -0
  274. package/docs/install.md +8 -1
  275. package/docs/reference/editors-date.md +2 -0
  276. package/docs/reference/editors-panel.md +4 -4
  277. package/docs/reference/editors-range.md +1 -1
  278. package/docs/reference/editors-relation.md +3 -3
  279. package/docs/reference/editors-select.md +1 -1
  280. package/docs/reference/editors-session.md +3 -2
  281. package/docs/reference/editors-value-list.md +1 -1
  282. package/docs/reference/field-row.md +2 -2
  283. package/docs/reference/grid.md +25 -6
  284. package/docs/reference/react.md +30 -8
  285. package/docs/reference/selection.md +10 -2
  286. package/docs/reference/views.md +42 -36
  287. package/package.json +22 -3
  288. package/skills/views/SKILL.md +3 -3
@@ -7,14 +7,20 @@ export const GRID_TITLE_LINK_CLASS = "**:data-cell-open:underline-offset-2 [&_[d
7
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
8
  export function gridCellClassName(state) {
9
9
  const { focused, editing, inRange, frozen, selected } = state;
10
- return cx(state.settlement === "requested" && GRID_CELL_REQUESTED, "group/gridcell", "outline-none", "flex min-w-0 border-b border-r border-(color:--vk-border-subtle) px-(--vk-px) text-(length:--vk-text)", "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
10
+ return cx(state.settlement === "requested" && GRID_CELL_REQUESTED, "group/gridcell", "outline-none", "flex min-w-0 border-b border-r border-(color:--vk-border-subtle) px-(--vk-px) text-(length:--vk-text)", "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
11
+ ? "[position:var(--vk-pin,sticky)]"
12
+ : focused || editing || inRange || state.isTitle || state.picker
13
+ ? "relative"
14
+ : "[@media(any-hover:hover)]:relative", focused || editing || inRange ? "overflow-visible" : "overflow-hidden", frozen
11
15
  ? focused || editing
12
16
  ? "z-9"
13
17
  : inRange
14
- ? "z-[calc(8*var(--vk-scrolled,0))]"
15
- : "z-[calc(7*var(--vk-scrolled,0))]"
18
+ ? "z-[calc(7*var(--vk-scrolled,0)+1)]"
19
+ : "z-[calc(6*var(--vk-scrolled,0)+1)]"
16
20
  : focused || editing
17
- ? "z-5"
21
+ ? editing
22
+ ? "z-5 has-data-grown:z-11"
23
+ : "z-5"
18
24
  : inRange
19
25
  ? "z-4"
20
26
  : undefined, frozen && gridFrozenBg(selected), editing && GRID_GROUND, !focused &&
@@ -0,0 +1,75 @@
1
+ import type { PercentDisplay } from "@viewkitjs/fields";
2
+ import type { ViewsMessageResolver } from "../../contract.js";
3
+ import type { useCellFormat } from "../../cells/use-cell-format.js";
4
+ import type { ViewsMenuItem } from "../../provider/components.js";
5
+ import type { ViewsIcons } from "../../provider/icons.js";
6
+ import type { ListColumn, ListSelectColor } from "../../model/column-schema.js";
7
+ import type { ListDateStyle, ListDurationStyle, ListNumberFormatState } from "../../model/column-format.js";
8
+ import type { GridGroupByState, GridSortState } from "./GridColumnMenu.js";
9
+ /** What the gates read from the column menu's props. */
10
+ export type GridColumnMenuOffer = {
11
+ values: string[];
12
+ viewBacked?: boolean;
13
+ sort?: GridSortState;
14
+ groupBy?: GridGroupByState;
15
+ formatsWritable?: boolean;
16
+ onOptionColorChange?: (key: string, value: string, color: ListSelectColor | null) => void;
17
+ onDateStyleChange?: (key: string, style: ListDateStyle) => void;
18
+ onDurationStyleChange?: (key: string, style: ListDurationStyle) => void;
19
+ onShowTimeChange?: (key: string, show: boolean) => void;
20
+ onPercentDisplayChange?: (key: string, display: PercentDisplay) => void;
21
+ onNumberFormatChange?: (key: string, patch: {
22
+ decimals?: number | null;
23
+ currency?: string;
24
+ }) => void;
25
+ onMoveLeft?: () => void;
26
+ onMoveRight?: () => void;
27
+ };
28
+ /** What a column's header menu offers, decided once for both routes. */
29
+ export type ColumnMenuGates = {
30
+ /** The field key every knob and colour writes under. */
31
+ key: string;
32
+ sortKey: string | undefined;
33
+ sortable: boolean;
34
+ groupable: boolean;
35
+ grouped: boolean;
36
+ canPercent: boolean;
37
+ canDate: boolean;
38
+ /** A date-time's Show time, beside its Format. */
39
+ canShowTime: boolean;
40
+ canDuration: boolean;
41
+ canDecimals: boolean;
42
+ canCurrency: boolean;
43
+ canColor: boolean;
44
+ canMove: boolean;
45
+ /** Any format knob at all: the knobs' block. */
46
+ canKnobs: boolean;
47
+ };
48
+ export declare function columnMenuGates<Row>(column: ListColumn<Row>, offer: GridColumnMenuOffer): ColumnMenuGates;
49
+ export type ColumnMenuItemsDeps = {
50
+ messages: ViewsMessageResolver;
51
+ icons: ViewsIcons;
52
+ /** The cell format in force (`useCellFormat()`): the date and duration samples read it. */
53
+ cellFormat: ReturnType<typeof useCellFormat>;
54
+ /** Closes the menu: every pick that closes on the popover route calls it. */
55
+ close: () => void;
56
+ };
57
+ /** What the rows read beyond the gates: the current choices, and the app's own rows already read. */
58
+ export type GridColumnMenuItemsProps = GridColumnMenuOffer & {
59
+ optionColors?: Record<string, ListSelectColor>;
60
+ dateStyle?: ListDateStyle;
61
+ showTime?: boolean;
62
+ durationStyle?: ListDurationStyle;
63
+ percentDisplay?: PercentDisplay;
64
+ numberFormat?: ListNumberFormatState;
65
+ onHide?: () => void;
66
+ /** The app's rows for this field (`columnMenuItems?.(key)`); null or empty for none. */
67
+ appItems: ViewsMenuItem[] | null;
68
+ };
69
+ /**
70
+ * THE COLUMN MENU AS DATA, for the `menu` route: the popover's rows in its order (sort · group · the knobs · the
71
+ * colours · move · the app's rows · hide), each block after the first behind a divider. Each knob and each option's
72
+ * colour is a group beside the menu, its current choice as its `detail`, its choices ticked rows that close; Show time
73
+ * is a tick that keeps the menu open. Every pick writes under the field key, as the popover's does.
74
+ */
75
+ export declare function gridColumnMenuItems<Row>(column: ListColumn<Row>, props: GridColumnMenuItemsProps, gates: ColumnMenuGates, deps: ColumnMenuItemsDeps): ViewsMenuItem[];
@@ -0,0 +1,263 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { resolveCategoryColor } from "@viewkitjs/fields/design/category-colors";
4
+ import { cx } from "../../internal/cx.js";
5
+ import { columnLabel } from "../../model/column-capabilities.js";
6
+ import { LIST_DECIMALS_CHOICES, prettifyOptionValue } from "../../model/column-state.js";
7
+ import { formatDate, formatNumber } from "./cells.js";
8
+ import { ALL_COLORS, COLOR_DOTS } from "./GridColumnColorSection.js";
9
+ import { DATE_STYLES, sampleDate } from "./GridColumnDateSection.js";
10
+ import { DURATION_SAMPLE_MS, DURATION_STYLES } from "./GridColumnDurationSection.js";
11
+ import { AUTOMATIC_SAMPLE, DECIMALS_SAMPLE } from "./GridColumnNumberSection.js";
12
+ import { DISPLAYS } from "./GridColumnPercentSection.js";
13
+ import { columnGroupable } from "../../model/column-order.js";
14
+ import { columnKnobs } from "../../model/column-knobs.js";
15
+ import { effectiveSortKey } from "../../model/column-sort.js";
16
+ import { fieldKeyOf } from "../../model/view-rules.js";
17
+ import { temporalKindOf } from "../../model/field-type-of.js";
18
+ export function columnMenuGates(column, offer) {
19
+ const { values, viewBacked = false, sort, groupBy, formatsWritable = true } = offer;
20
+ const key = fieldKeyOf(column);
21
+ const sortKey = effectiveSortKey(column, viewBacked);
22
+ const sortable = !!(sortKey && sort);
23
+ const groupable = !!groupBy && viewBacked && columnGroupable(column);
24
+ const grouped = groupable && groupBy.fieldKey === column.field.key;
25
+ const knobs = columnKnobs(column);
26
+ const canPercent = formatsWritable && knobs.has("percentDisplay") && !!offer.onPercentDisplayChange;
27
+ const canDate = formatsWritable && knobs.has("dateStyle") && !!offer.onDateStyleChange;
28
+ const canShowTime = canDate && knobs.has("showTime") && !!offer.onShowTimeChange && temporalKindOf(column) === "datetime";
29
+ const canDuration = formatsWritable && knobs.has("durationStyle") && !!offer.onDurationStyleChange;
30
+ const canDecimals = formatsWritable && knobs.has("decimals") && !!offer.onNumberFormatChange;
31
+ const canCurrency = knobs.has("currency") && !!offer.onNumberFormatChange;
32
+ const canColor = formatsWritable &&
33
+ (column.type === "select" || column.type === "multiselect") &&
34
+ !column.render &&
35
+ !!offer.onOptionColorChange &&
36
+ values.length > 0;
37
+ const canMove = !!offer.onMoveLeft || !!offer.onMoveRight;
38
+ const canKnobs = canPercent || canDate || canDuration || canDecimals || canCurrency;
39
+ return {
40
+ key,
41
+ sortKey,
42
+ sortable,
43
+ groupable,
44
+ grouped,
45
+ canPercent,
46
+ canDate,
47
+ canShowTime,
48
+ canDuration,
49
+ canDecimals,
50
+ canCurrency,
51
+ canColor,
52
+ canMove,
53
+ canKnobs,
54
+ };
55
+ }
56
+ export function gridColumnMenuItems(column, props, gates, deps) {
57
+ const { messages, icons, cellFormat, close } = deps;
58
+ const { key } = gates;
59
+ const glyph = (name) => {
60
+ const Glyph = icons[name];
61
+ return _jsx(Glyph, { className: "size-4" });
62
+ };
63
+ const then = (act) => () => {
64
+ act();
65
+ close();
66
+ };
67
+ const blocks = [];
68
+ if (gates.sortable) {
69
+ const sort = props.sort;
70
+ const active = sort.value === gates.sortKey;
71
+ const pick = (dir) => then(() => sort.onChange({ value: gates.sortKey, dir }));
72
+ blocks.push([
73
+ { key: "sort-asc", label: messages({ key: "views.menus.sort-asc" }), icon: glyph("sortRowsUp"), checked: active && sort.dir === "asc", onSelect: pick("asc") },
74
+ { key: "sort-desc", label: messages({ key: "views.menus.sort-desc" }), icon: glyph("sortRowsDown"), checked: active && sort.dir === "desc", onSelect: pick("desc") },
75
+ ...(active
76
+ ? [{ key: "sort-clear", label: messages({ key: "views.menus.sort-clear" }), icon: glyph("clearSort"), onSelect: then(() => sort.onChange({ value: "", dir: "asc" })) }]
77
+ : []),
78
+ ]);
79
+ }
80
+ if (gates.groupable) {
81
+ const groupBy = props.groupBy;
82
+ blocks.push([
83
+ gates.grouped
84
+ ? { key: "ungroup", label: messages({ key: "views.menus.ungroup" }), icon: glyph("group"), checked: true, onSelect: then(() => groupBy.onChange(null)) }
85
+ : {
86
+ key: "group-by",
87
+ label: messages({ key: "views.menus.group-by", values: { field: columnLabel(column) } }),
88
+ icon: glyph("group"),
89
+ onSelect: then(() => groupBy.onChange(column.field.key)),
90
+ },
91
+ ]);
92
+ }
93
+ const knobs = [];
94
+ if (gates.canPercent) {
95
+ const active = props.percentDisplay ?? column.format?.percentDisplay ?? "text";
96
+ const word = (display) => messages({ key: "views.menus.percent-display-option", values: { display } });
97
+ knobs.push({
98
+ key: "percent-display",
99
+ label: messages({ key: "views.menus.percent-display" }),
100
+ icon: glyph("progress"),
101
+ beside: true,
102
+ detail: word(active),
103
+ children: DISPLAYS.map((display) => ({
104
+ key: `percent-display:${display}`,
105
+ label: word(display),
106
+ checked: active === display,
107
+ onSelect: then(() => props.onPercentDisplayChange(key, display)),
108
+ })),
109
+ });
110
+ }
111
+ if (gates.canDate) {
112
+ const active = props.dateStyle ?? column.format?.dateStyle ?? "short";
113
+ const word = (style) => messages({ key: "views.menus.date-style", values: { style } });
114
+ const sample = sampleDate();
115
+ knobs.push({
116
+ key: "date-format",
117
+ label: messages({ key: "views.menus.format" }),
118
+ icon: glyph("calendar"),
119
+ beside: true,
120
+ detail: word(active),
121
+ children: DATE_STYLES.map((style) => ({
122
+ key: `date-format:${style}`,
123
+ label: word(style),
124
+ detail: formatDate(sample, column, style, false, cellFormat.viewer),
125
+ checked: active === style,
126
+ onSelect: then(() => props.onDateStyleChange(key, style)),
127
+ })),
128
+ });
129
+ if (gates.canShowTime) {
130
+ knobs.push({
131
+ key: "show-time",
132
+ label: messages({ key: "views.menus.show-time" }),
133
+ checked: !!props.showTime,
134
+ keepOpen: true,
135
+ onSelect: () => props.onShowTimeChange(key, !props.showTime),
136
+ });
137
+ }
138
+ }
139
+ if (gates.canDuration) {
140
+ const active = props.durationStyle ?? column.format?.durationStyle ?? "adaptive";
141
+ const word = (style) => messages({ key: "views.menus.duration-style", values: { style } });
142
+ knobs.push({
143
+ key: "duration-format",
144
+ label: messages({ key: "views.menus.format" }),
145
+ icon: glyph("duration"),
146
+ beside: true,
147
+ detail: word(active),
148
+ children: DURATION_STYLES.map((style) => ({
149
+ key: `duration-format:${style}`,
150
+ label: word(style),
151
+ detail: formatNumber(DURATION_SAMPLE_MS, column, { ...cellFormat, durationStyle: style }),
152
+ checked: active === style,
153
+ onSelect: then(() => props.onDurationStyleChange(key, style)),
154
+ })),
155
+ });
156
+ }
157
+ if (gates.canDecimals) {
158
+ const chosen = props.numberFormat?.decimals ?? undefined;
159
+ const declared = column.format?.decimals;
160
+ const shown = chosen ?? declared;
161
+ const automatic = messages({ key: "views.menus.automatic" });
162
+ knobs.push({
163
+ key: "decimals",
164
+ label: messages({ key: "views.menus.decimals" }),
165
+ icon: glyph("number"),
166
+ beside: true,
167
+ detail: shown === undefined ? automatic : String(shown),
168
+ children: [
169
+ {
170
+ key: "decimals:auto",
171
+ label: automatic,
172
+ detail: declared === undefined ? AUTOMATIC_SAMPLE : DECIMALS_SAMPLE.toFixed(declared),
173
+ checked: chosen === undefined,
174
+ onSelect: then(() => props.onNumberFormatChange(key, { decimals: null })),
175
+ },
176
+ ...LIST_DECIMALS_CHOICES.map((d) => ({
177
+ key: `decimals:${d}`,
178
+ label: String(d),
179
+ detail: DECIMALS_SAMPLE.toFixed(d),
180
+ checked: chosen === d,
181
+ onSelect: then(() => props.onNumberFormatChange(key, { decimals: d })),
182
+ })),
183
+ ],
184
+ });
185
+ }
186
+ const currencyOptions = props.numberFormat?.currencyOptions ?? [];
187
+ if (gates.canCurrency && currencyOptions.length > 0) {
188
+ const current = props.numberFormat?.currency;
189
+ const label = currencyOptions.find((c) => c.value === current)?.label;
190
+ knobs.push({
191
+ key: "currency",
192
+ label: messages({ key: "views.menus.currency" }),
193
+ icon: glyph("currency"),
194
+ beside: true,
195
+ ...(label !== undefined && { detail: label }),
196
+ children: currencyOptions.map((c) => ({
197
+ key: `currency:${c.value}`,
198
+ label: c.label,
199
+ checked: current === c.value,
200
+ onSelect: then(() => props.onNumberFormatChange(key, { currency: c.value })),
201
+ })),
202
+ });
203
+ }
204
+ if (knobs.length > 0)
205
+ blocks.push(knobs);
206
+ if (gates.canColor) {
207
+ const overrides = props.optionColors;
208
+ const swatch = (color) => color ? (_jsx("span", { className: cx("size-2.5 rounded-full", COLOR_DOTS[color]) })) : (_jsx("span", { className: "size-2.5 rounded-full border border-(color:--vk-border)" }));
209
+ const colours = props.values.map((value) => {
210
+ const resolved = resolveCategoryColor(value, column.options, overrides);
211
+ const own = overrides?.[value];
212
+ return {
213
+ key: `colour:${value}`,
214
+ label: column.options?.find((option) => option.value === value)?.label ?? prettifyOptionValue(value),
215
+ icon: swatch(resolved),
216
+ beside: true,
217
+ detail: messages({ key: "views.menus.colour", values: { colour: resolved } }),
218
+ children: [
219
+ {
220
+ key: `colour:${value}:auto`,
221
+ label: messages({ key: "views.menus.automatic" }),
222
+ icon: swatch(null),
223
+ checked: !own,
224
+ onSelect: then(() => props.onOptionColorChange(key, value, null)),
225
+ },
226
+ ...ALL_COLORS.map((color) => ({
227
+ key: `colour:${value}:${color}`,
228
+ label: messages({ key: "views.menus.colour", values: { colour: color } }),
229
+ icon: swatch(color),
230
+ checked: own === color,
231
+ onSelect: then(() => props.onOptionColorChange(key, value, color)),
232
+ })),
233
+ ],
234
+ };
235
+ });
236
+ if (overrides && Object.keys(overrides).length > 0) {
237
+ colours.push({
238
+ key: "colours-reset",
239
+ label: messages({ key: "views.menus.colours-reset" }),
240
+ separatorBefore: true,
241
+ onSelect: then(() => {
242
+ for (const value of Object.keys(overrides))
243
+ props.onOptionColorChange(key, value, null);
244
+ }),
245
+ });
246
+ }
247
+ blocks.push(colours);
248
+ }
249
+ if (gates.canMove) {
250
+ const move = [];
251
+ if (props.onMoveLeft)
252
+ move.push({ key: "move-left", label: messages({ key: "views.menus.move-left" }), icon: glyph("moveLeft"), onSelect: then(props.onMoveLeft) });
253
+ if (props.onMoveRight)
254
+ move.push({ key: "move-right", label: messages({ key: "views.menus.move-right" }), icon: glyph("moveRight"), onSelect: then(props.onMoveRight) });
255
+ blocks.push(move);
256
+ }
257
+ if (props.appItems && props.appItems.length > 0)
258
+ blocks.push(props.appItems);
259
+ if (props.onHide) {
260
+ blocks.push([{ key: "hide-column", label: messages({ key: "views.menus.hide-column" }), icon: glyph("hide"), onSelect: then(props.onHide) }]);
261
+ }
262
+ return blocks.flatMap((block, index) => block.map((item, at) => (index > 0 && at === 0 ? { ...item, separatorBefore: true } : item)));
263
+ }
@@ -0,0 +1,4 @@
1
+ /** Puts a keep session's Escape on the list while it is open. Returns its removal, safe to call twice. */
2
+ export declare function registerGridEditEscape(close: () => void): () => void;
3
+ /** The latest open keep session's Escape, or null when none is open. */
4
+ export declare function openGridEditEscape(): (() => void) | null;
@@ -0,0 +1,12 @@
1
+ const open = [];
2
+ export function registerGridEditEscape(close) {
3
+ open.push(close);
4
+ return () => {
5
+ const at = open.lastIndexOf(close);
6
+ if (at >= 0)
7
+ open.splice(at, 1);
8
+ };
9
+ }
10
+ export function openGridEditEscape() {
11
+ return open.at(-1) ?? null;
12
+ }
@@ -34,7 +34,8 @@ export type GridEditSession = {
34
34
  };
35
35
  /**
36
36
  * Runs one grid edit through the shared session, in its admitted mode. A close asks the editor for
37
- * its answer (Escape is always a discard); a commit the grid would refuse stays open with its reason.
37
+ * its answer (Escape is a discard, unless the cell's field type keeps: `ViewsProvider`'s `escape`); a commit
38
+ * the grid would refuse stays open with its reason.
38
39
  * An accepted answer is written at once by an in-place type-in on a desktop, and after the exit gap
39
40
  * otherwise, so the popover or the sheet plays out before the cell repaints; on a desktop, Enter or
40
41
  * Tab moves the focus at once all the same, and a key in the gap writes the answer first. Left mid-exit (the cell
@@ -1,7 +1,9 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useEffect, useRef, useState } from "react";
3
+ import { useContext, useEffect, useRef, useState } from "react";
4
4
  import { useAnchoredEditSession } from "../../editors/edit-session.js";
5
+ import { EditFieldTypeContext, useEscapeRule } from "../../editors/escape-rule.js";
6
+ import { registerGridEditEscape } from "./grid-edit-escape.js";
5
7
  import { useKeepInside } from "../../editors/keep-inside.js";
6
8
  import { useViews } from "../../provider/context.js";
7
9
  import { useDesktop } from "../../provider/desktop.js";
@@ -11,6 +13,7 @@ export function useGridEditSession(args) {
11
13
  const desktop = useDesktop();
12
14
  const { ports } = useViews();
13
15
  const [sheet] = useState(!desktop);
16
+ const escape = useEscapeRule(useContext(EditFieldTypeContext));
14
17
  const latest = useRef(args);
15
18
  useEffect(() => {
16
19
  latest.current = args;
@@ -63,6 +66,7 @@ export function useGridEditSession(args) {
63
66
  const session = useAnchoredEditSession({
64
67
  editorRef,
65
68
  mapPayload,
69
+ escape,
66
70
  exitMs: sheet ? GRID_SHEET_EXIT_MS : undefined,
67
71
  onAttempt: (answer) => {
68
72
  const reason = answer.kind === "commit" ? (latest.current.refuse?.(answer.payload) ?? null) : null;
@@ -93,6 +97,15 @@ export function useGridEditSession(args) {
93
97
  viaRef.current = reason;
94
98
  session.close(reason);
95
99
  };
100
+ const closeRef = useRef(close);
101
+ useEffect(() => {
102
+ closeRef.current = close;
103
+ });
104
+ useEffect(() => {
105
+ if (!session.open || !session.keeps)
106
+ return;
107
+ return registerGridEditEscape(() => closeRef.current("escape"));
108
+ }, [session.open, session.keeps]);
96
109
  const closeFromPanel = (reason) => {
97
110
  if (session.open)
98
111
  viaRef.current = null;
@@ -0,0 +1,25 @@
1
+ import type { ListGroup } from "../../grouping/types.js";
2
+ import type { DisplayCurrency } from "../../fields/currency.js";
3
+ import type { ListAggregateKind, ListColumn } from "../../model/column-schema.js";
4
+ import type { ListNumberFormatOverrides } from "../../model/column-format.js";
5
+ import type { useCellFormat } from "../../cells/use-cell-format.js";
6
+ /** A figure as written: its text, and the column's suffix after it where one applies. */
7
+ export type GridFigureValue = {
8
+ text: string;
9
+ suffix: string | null;
10
+ };
11
+ /**
12
+ * `column`'s `kind` for `group`, written in the column's own format: its decimals (the person's, from
13
+ * `numberFormats`), its currency, and a money column read in its original currencies totalled in
14
+ * `defaultCurrency`. A group that carries the database's `figures` is read from them, never from the rows in
15
+ * hand (a page is not the group). Null when there is nothing to write: `none`, a figure the source didn't count,
16
+ * or rows with no value.
17
+ */
18
+ export declare function gridFigureValue<Row>({ column, group, kind, numberFormats, defaultCurrency, cellFormat, }: {
19
+ column: ListColumn<Row>;
20
+ group: ListGroup<Row>;
21
+ kind: ListAggregateKind;
22
+ numberFormats?: ListNumberFormatOverrides;
23
+ defaultCurrency: DisplayCurrency;
24
+ cellFormat: ReturnType<typeof useCellFormat>;
25
+ }): GridFigureValue | null;
@@ -0,0 +1,40 @@
1
+ import { figureFor, ratioFigure } from "../../figures.js";
2
+ import { computeAggregate, figureKeyOf, moneyFigureCode, moneyTotal } from "../../model/aggregates.js";
3
+ import { fieldTypeOf } from "../../model/field-type-of.js";
4
+ import { fieldKeyOf } from "../../model/view-rules.js";
5
+ import { formatNumber } from "./cells.js";
6
+ function countsRows(kind) {
7
+ return kind === "count" || kind === "filled" || kind === "unique";
8
+ }
9
+ export function gridFigureValue({ column, group, kind, numberFormats, defaultCurrency, cellFormat, }) {
10
+ if (kind === "none")
11
+ return null;
12
+ const countLike = countsRows(kind);
13
+ const decimals = numberFormats?.[fieldKeyOf(column)]?.decimals;
14
+ const suffix = column.aggregateSuffix && !countLike && kind !== "ratio" ? column.aggregateSuffix : null;
15
+ const written = (text) => (text == null ? null : { text, suffix });
16
+ if (group.figures) {
17
+ const ratioParts = column.field?.type === "formula" ? column.field.ratio : undefined;
18
+ const fromSource = kind === "ratio" && ratioParts
19
+ ? ratioFigure(group.figures, ratioParts.numerator, ratioParts.denominator)
20
+ : figureFor(kind, group.figures, figureKeyOf(column, defaultCurrency));
21
+ const sourceCode = fromSource != null && !countLike && fieldTypeOf(column) === "currency"
22
+ ? moneyFigureCode(column, defaultCurrency)
23
+ : undefined;
24
+ if (fromSource == null || sourceCode === null)
25
+ return null;
26
+ return written(countLike
27
+ ? String(fromSource)
28
+ : formatNumber(fromSource, column, { ...cellFormat, decimals, currency: sourceCode }));
29
+ }
30
+ const money = moneyTotal(kind, column, group.items, defaultCurrency);
31
+ if (money) {
32
+ return written(formatNumber(money.amount, column, { ...cellFormat, decimals, currency: money.code }));
33
+ }
34
+ if (money === null)
35
+ return null;
36
+ const computed = computeAggregate(kind, column, group.items);
37
+ if (computed == null)
38
+ return null;
39
+ return written(countLike ? String(computed) : formatNumber(computed, column, { ...cellFormat, decimals }));
40
+ }
@@ -0,0 +1,15 @@
1
+ import { type ReactNode, type RefObject } from "react";
2
+ /**
3
+ * THE IN-PLACE EDITOR'S BOX, AS WIDE AS WHAT IS TYPED IN IT — an amount and its unit, or a line of
4
+ * text (a link, an email, a phone, a domain, plain text). It is the cell's width until the value doesn't
5
+ * fit; then it grows past the cell, away from the side the column aligns to (a right-aligned column's
6
+ * box grows left, its amount still flush with the column's edge; a text's grows right), up to a cap.
7
+ * Measured as it opens, before the panel brings it into view (a child's layout effect runs first), and
8
+ * again at every keystroke: the input says by how much its text overflows it, and the box takes that
9
+ * much more. Grown, it draws the editing cell's frame around itself, over the cell's own, so the editor
10
+ * reads as one box, and the cell rises over the frozen columns (`data-grown`, `gridCellClassName`).
11
+ */
12
+ export declare function GridFittedBox({ boxRef, children, }: {
13
+ boxRef: RefObject<HTMLSpanElement | null>;
14
+ children: ReactNode;
15
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,26 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useCallback, useLayoutEffect } from "react";
4
+ import { cx } from "../../internal/cx.js";
5
+ import { GRID_GROUND } from "./grid-styles.js";
6
+ const FITTED_MAX_PX = 320;
7
+ export function GridFittedBox({ boxRef, children, }) {
8
+ const fit = useCallback(() => {
9
+ const box = boxRef.current;
10
+ const input = box?.querySelector("input");
11
+ if (!box || !input)
12
+ return;
13
+ box.style.minWidth = "";
14
+ const over = input.scrollWidth - input.clientWidth;
15
+ const width = over > 0 ? Math.min(box.offsetWidth + over + 1, FITTED_MAX_PX) : 0;
16
+ if (width > box.offsetWidth) {
17
+ box.style.minWidth = `${width}px`;
18
+ box.dataset.grown = "";
19
+ }
20
+ else {
21
+ delete box.dataset.grown;
22
+ }
23
+ }, [boxRef]);
24
+ useLayoutEffect(fit, [fit]);
25
+ return (_jsxs("span", { ref: boxRef, onInput: fit, className: "group/fitted relative flex h-full w-full min-w-0 shrink-0 data-grown:z-2", children: [_jsx("span", { "aria-hidden": true, className: cx("pointer-events-none absolute inset-y-0 -inset-x-(--vk-px) -z-1 hidden rounded-sm border border-(color:--vk-border-brand) shadow-lg shadow-black/20 group-data-grown/fitted:block dark:shadow-black/50", GRID_GROUND) }), children] }));
26
+ }
@@ -0,0 +1,31 @@
1
+ import type { ReactNode } from "react";
2
+ import type { ViewsMessageResolver } from "../../contract.js";
3
+ import type { ListGroupSummaryPart } from "../../model/preferences.js";
4
+ import type { ViewsMenuItem } from "../../provider/components.js";
5
+ import type { ViewsIcons } from "../../provider/icons.js";
6
+ import type { GridSortState } from "./GridColumnMenu.js";
7
+ import type { GridGroupSortOption } from "./GridGroupMenu.js";
8
+ import type { GridGroupMenuParts } from "./grid-group-menu-parts.js";
9
+ /** A band figure as the menu lists it: its part, its label, and the label in words. */
10
+ export type GridGroupMenuFigure = {
11
+ part: ListGroupSummaryPart;
12
+ label: ReactNode;
13
+ text?: string;
14
+ };
15
+ /**
16
+ * The rows in today's order, each part after the first behind a divider: the sort choices a group beside the menu
17
+ * (the current one ticked and named as its detail; a pick of the ticked one flips its direction), with no search
18
+ * field; the Show figures a group in place, each a tick that keeps the menu open; Hide.
19
+ */
20
+ export declare function gridGroupMenuItems(parts: GridGroupMenuParts, input: {
21
+ sort?: GridSortState;
22
+ sortOptions: GridGroupSortOption[];
23
+ summary?: ListGroupSummaryPart[];
24
+ onSummaryChange?: (part: ListGroupSummaryPart, next: boolean) => void;
25
+ figures: GridGroupMenuFigure[];
26
+ onHide?: () => void;
27
+ }, deps: {
28
+ messages: ViewsMessageResolver;
29
+ icons: ViewsIcons;
30
+ close: () => void;
31
+ }): ViewsMenuItem[];
@@ -0,0 +1,75 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ const words = (figure) => figure.text ??
4
+ (typeof figure.label === "string" || typeof figure.label === "number" ? String(figure.label) : figure.part);
5
+ export function gridGroupMenuItems(parts, input, deps) {
6
+ const { messages, icons, close } = deps;
7
+ const glyph = (name) => {
8
+ const Glyph = icons[name];
9
+ return _jsx(Glyph, { className: "size-4" });
10
+ };
11
+ const blocks = [];
12
+ if (parts.sort && input.sort && input.sortOptions.length > 0) {
13
+ const sort = input.sort;
14
+ const current = input.sortOptions.find((opt) => opt.value === sort.value);
15
+ blocks.push([
16
+ {
17
+ key: "group-sort",
18
+ label: messages({ key: "views.menus.group-sort" }),
19
+ icon: glyph("sortRowsUp"),
20
+ beside: true,
21
+ ...(current && { detail: current.label }),
22
+ children: input.sortOptions.map((opt) => {
23
+ const active = sort.value === opt.value;
24
+ const dir = active ? (sort.dir === "asc" ? "desc" : "asc") : (opt.defaultDir ?? "asc");
25
+ return {
26
+ key: `group-sort:${opt.value}`,
27
+ label: opt.label,
28
+ icon: glyph(active && sort.dir === "desc" ? "sortRowsDown" : "sortRowsUp"),
29
+ checked: active,
30
+ onSelect: () => {
31
+ sort.onChange({ value: opt.value, dir });
32
+ close();
33
+ },
34
+ };
35
+ }),
36
+ },
37
+ ]);
38
+ }
39
+ if (parts.figures && input.onSummaryChange) {
40
+ const on = (part) => (input.summary ?? []).includes(part);
41
+ const toggle = input.onSummaryChange;
42
+ const shown = [
43
+ { part: "count", label: messages({ key: "views.menus.group-count" }) },
44
+ ...input.figures,
45
+ ];
46
+ blocks.push([
47
+ {
48
+ key: "group-show",
49
+ label: messages({ key: "views.menus.group-show" }),
50
+ children: shown.map((figure) => ({
51
+ key: `group-show:${figure.part}`,
52
+ label: words(figure),
53
+ checked: on(figure.part),
54
+ keepOpen: true,
55
+ onSelect: () => toggle(figure.part, !on(figure.part)),
56
+ })),
57
+ },
58
+ ]);
59
+ }
60
+ if (parts.hide && input.onHide) {
61
+ const hide = input.onHide;
62
+ blocks.push([
63
+ {
64
+ key: "group-hide",
65
+ label: messages({ key: "views.menus.group-hide" }),
66
+ icon: glyph("hide"),
67
+ onSelect: () => {
68
+ hide();
69
+ close();
70
+ },
71
+ },
72
+ ]);
73
+ }
74
+ return blocks.flatMap((block, index) => block.map((item, at) => (index > 0 && at === 0 ? { ...item, separatorBefore: true } : item)));
75
+ }