@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
@@ -1,5 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { cx } from "../internal/cx.js";
4
+ import { ELEMENT_RESET } from "../internal/reset.js";
3
5
  import { useViews } from "../provider/context.js";
4
6
  export function renderBoolean(field, value, opts) {
5
7
  const truthy = Boolean(value);
@@ -39,5 +41,5 @@ function renderToggle(child, truthy, field, opts) {
39
41
  return (_jsx("button", { type: "button", role: "switch", "aria-checked": truthy, "aria-label": field.label, disabled: opts.booleanDisabled, onClick: (event) => {
40
42
  event.stopPropagation();
41
43
  opts.onToggle?.(!truthy);
42
- }, className: "flex items-center rounded-sm transition-opacity hover:opacity-80", children: child }));
44
+ }, className: cx(ELEMENT_RESET, "flex items-center rounded-sm transition-opacity hover:opacity-80"), children: child }));
43
45
  }
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from "react";
1
+ import { type ReactNode } from "react";
2
2
  import type { FieldDefOf } from "@viewkitjs/fields";
3
3
  import type { DisplayOptions } from "./options.js";
4
4
  /**
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useState } from "react";
3
4
  import { fromDayKey } from "@viewkitjs/fields/query";
4
5
  import { cx } from "../internal/cx.js";
5
6
  import { useViews } from "../provider/context.js";
@@ -12,14 +13,15 @@ export function renderDate(field, value, opts) {
12
13
  function DateValue({ field, value, opts: given, }) {
13
14
  const opts = useDisplayOptions(given);
14
15
  const { Tooltip } = useViews().components;
16
+ const [pointed, setPointed] = useState(false);
15
17
  const withTime = opts.withTime ?? (field.type === "datetime" ? field.format?.withTime : false);
16
- const cell = (_jsx("span", { className: cx(cellTextClass(opts.wrap), "tabular-nums text-(color:--vk-fg)"), children: formatDateValue(value, opts.dateStyle ?? field.format?.dateStyle, withTime, field.type, opts) }));
18
+ const cell = (_jsx("span", { className: cx(cellTextClass(opts.wrap), "tabular-nums text-(color:--vk-fg)"), onPointerEnter: pointed ? undefined : (event) => event.pointerType !== "touch" && setPointed(true), children: formatDateValue(value, opts.dateStyle ?? field.format?.dateStyle, withTime, field.type, opts) }));
17
19
  const d = field.type === "date" && typeof value === "string"
18
20
  ? fromDayKey(value)
19
21
  : value instanceof Date
20
22
  ? value
21
23
  : new Date(String(value));
22
- if (!d || Number.isNaN(d.getTime()))
24
+ if (!pointed || !d || Number.isNaN(d.getTime()))
23
25
  return cell;
24
26
  const full = formatDateValue(value, "long", field.type === "datetime", field.type, opts);
25
27
  return (_jsx(Tooltip, { content: full, side: "bottom", align: "start", delayMs: 1000, className: "tabular-nums", children: cell }));
@@ -35,8 +35,24 @@ function relative(input, context) {
35
35
  : daySpan(Math.floor(hours / 24));
36
36
  return spanWords(span, diff < 0, context);
37
37
  }
38
+ const DATE_FORMATS = new Map();
39
+ const NUMBER_FORMATS = new Map();
40
+ function dateFormat(locale, options) {
41
+ const key = `${locale}|${JSON.stringify(options)}`;
42
+ let format = DATE_FORMATS.get(key);
43
+ if (!format)
44
+ DATE_FORMATS.set(key, (format = new Intl.DateTimeFormat(locale, options)));
45
+ return format;
46
+ }
47
+ function numberFormat(locale, options) {
48
+ const key = `${locale ?? ""}|${JSON.stringify(options)}`;
49
+ let format = NUMBER_FORMATS.get(key);
50
+ if (!format)
51
+ NUMBER_FORMATS.set(key, (format = new Intl.NumberFormat(locale, options)));
52
+ return format;
53
+ }
38
54
  function viewerToday(context) {
39
- const parts = new Intl.DateTimeFormat("en-US", {
55
+ const parts = dateFormat("en-US", {
40
56
  timeZone: context.timeZone ?? DEFAULT_CONVENTIONS.timeZone,
41
57
  year: "numeric",
42
58
  month: "numeric",
@@ -73,7 +89,7 @@ function absoluteDay({ year, month, day }, style, today, context, time) {
73
89
  return time ? `${date}, ${time}` : date;
74
90
  }
75
91
  function instantParts(instant, timeZone) {
76
- const parts = new Intl.DateTimeFormat("en-GB", {
92
+ const parts = dateFormat("en-GB", {
77
93
  timeZone: timeZone ?? DEFAULT_CONVENTIONS.timeZone,
78
94
  year: "numeric",
79
95
  month: "numeric",
@@ -95,11 +111,11 @@ export const DEFAULT_FIELD_PRESENTATION = {
95
111
  number: ({ value, format, decimals, currency, context }) => {
96
112
  const style = format?.style ?? "plain";
97
113
  if (style === "percent")
98
- return `${new Intl.NumberFormat(context.locale, {
114
+ return `${numberFormat(context.locale, {
99
115
  minimumFractionDigits: decimals ?? 0,
100
116
  maximumFractionDigits: decimals ?? 0,
101
117
  }).format(value)}%`;
102
- return new Intl.NumberFormat(context.locale, {
118
+ return numberFormat(context.locale, {
103
119
  ...(style === "currency" ? { style: "currency", currency: currency ?? "EUR" } : {}),
104
120
  minimumFractionDigits: decimals ?? (style === "currency" ? 2 : 0),
105
121
  maximumFractionDigits: decimals ?? 2,
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useContext } from "react";
4
4
  import { linkPlatform } from "@viewkitjs/fields";
5
5
  import { cx } from "../internal/cx.js";
6
+ import { ELEMENT_RESET } from "../internal/reset.js";
6
7
  import { ViewsContext } from "../provider/context.js";
7
8
  import { cellLinkProps } from "./link-click.js";
8
9
  import { cellTextClass } from "./text-class.js";
@@ -20,7 +21,7 @@ function WebAddress({ address, opts }) {
20
21
  const views = useContext(ViewsContext);
21
22
  const label = address.replace(/^https?:\/\//, "");
22
23
  const href = webHref(address);
23
- const link = opts?.slotOwnsClick || href === null ? (_jsx("span", { className: cellTextClass(opts?.wrap), children: label })) : (_jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", ...(cellLinkProps(opts) ?? { "data-no-nav": true }), className: cx(cellTextClass(opts?.wrap), "text-(color:--vk-fg-brand) hover:underline"), children: label }));
24
+ const link = opts?.slotOwnsClick || href === null ? (_jsx("span", { className: cellTextClass(opts?.wrap), children: label })) : (_jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", ...(cellLinkProps(opts) ?? { "data-no-nav": true }), className: cx(ELEMENT_RESET, cellTextClass(opts?.wrap), "text-(color:--vk-fg-brand) hover:underline"), children: label }));
24
25
  const platform = views && href !== null ? linkPlatform(address, views.conventions) : null;
25
26
  if (!platform || !views)
26
27
  return link;
@@ -35,7 +36,7 @@ function domainLink(domain, opts) {
35
36
  const href = webHref(domain);
36
37
  if (opts?.slotOwnsClick || href === null)
37
38
  return _jsx("span", { className: cellTextClass(opts?.wrap), children: domain });
38
- return (_jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", ...(cellLinkProps(opts) ?? { "data-no-nav": true }), className: cx(cellTextClass(opts?.wrap), "text-(color:--vk-fg-brand) hover:underline"), children: domain }));
39
+ return (_jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", ...(cellLinkProps(opts) ?? { "data-no-nav": true }), className: cx(ELEMENT_RESET, cellTextClass(opts?.wrap), "text-(color:--vk-fg-brand) hover:underline"), children: domain }));
39
40
  }
40
41
  export function renderEmail(_field, value, opts) {
41
42
  if (Array.isArray(value))
@@ -50,5 +51,5 @@ function renderEmailAddress(address, opts) {
50
51
  return (_jsx("a", { href: `mailto:${address}`, ...(cellLinkProps(opts) ?? {
51
52
  "data-no-nav": true,
52
53
  onClick: (event) => event.stopPropagation(),
53
- }), className: "text-(color:--vk-fg) underline decoration-dotted decoration-(color:--vk-fg-subtle)/40 decoration-1 underline-offset-[3px] transition-colors hover:decoration-(color:--vk-fg-subtle)/60", children: address }));
54
+ }), className: cx(ELEMENT_RESET, "text-(color:--vk-fg) underline decoration-dotted decoration-(color:--vk-fg-subtle)/40 decoration-1 underline-offset-[3px] transition-colors hover:decoration-(color:--vk-fg-subtle)/60"), children: address }));
54
55
  }
@@ -2,6 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { useRef, useState } from "react";
4
4
  import { cx } from "../internal/cx.js";
5
+ import { ELEMENT_RESET } from "../internal/reset.js";
5
6
  import { useViews } from "../provider/context.js";
6
7
  const VISIBLE_FLAT = 1;
7
8
  const VISIBLE_WRAPPED = 3;
@@ -19,7 +20,7 @@ export function MultiValueCell({ items, details, wrap, title, slotOwnsClick, })
19
20
  (slotOwnsClick ? (_jsxs("span", { className: "shrink-0 text-[10px] leading-[0.9rem] text-(color:--vk-fg-subtle)", children: ["+", hidden] })) : (_jsxs("button", { ref: trigger, type: "button", tabIndex: -1, "data-no-nav": true, "aria-label": messages({ key: "views.display.show-all", values: { count: items.length } }), "aria-haspopup": "dialog", "aria-expanded": open, onClick: (event) => {
20
21
  event.stopPropagation();
21
22
  setOpen((current) => !current);
22
- }, className: cx("shrink-0 rounded-md [corner-shape:squircle] border border-(color:--vk-border)", "bg-(color:--vk-ground) px-1 text-[10px] leading-[0.9rem] text-(color:--vk-fg-subtle) shadow-xs", "transition-colors hover:bg-(color:--vk-hovered) hover:text-(color:--vk-fg)"), children: ["+", hidden] })))] }));
23
+ }, className: cx(ELEMENT_RESET, "shrink-0 rounded-md [corner-shape:squircle] border border-(color:--vk-border)", "bg-(color:--vk-ground) px-1 text-[10px] leading-[0.9rem] text-(color:--vk-fg-subtle) shadow-xs", "transition-colors hover:bg-(color:--vk-hovered) hover:text-(color:--vk-fg)"), children: ["+", hidden] })))] }));
23
24
  if (hidden === 0 || slotOwnsClick)
24
25
  return content;
25
26
  const { Popover } = components;
@@ -30,7 +30,8 @@ function PercentValue({ field, n, opts: given }) {
30
30
  ? { width: "max-content", minWidth: `min(${figureSlot}, ${figureRoom})`, maxWidth: figureRoom }
31
31
  : { width: figureSlot }, children: [figure, _jsx(CellSuffix, { children: "%" })] }));
32
32
  if (display === "bar") {
33
- return (_jsxs("span", { className: "flex h-lh w-full min-w-0 flex-1 flex-row-reverse flex-wrap content-start items-center gap-x-2 overflow-y-clip", style: { maxWidth: `calc(6rem + 0.5rem + ${figureSlot})` }, children: [figureNode(true), _jsx("span", { className: "h-1.5 min-w-6 flex-1 overflow-hidden rounded-full bg-(color:--vk-neutral)", "aria-hidden": true, children: _jsx("span", { className: "block h-full bg-(color:--vk-brand)", style: { width: `${clamped}%` } }) })] }));
33
+ const box = `calc(6rem + 0.5rem + ${figureSlot})`;
34
+ return (_jsxs("span", { className: "flex h-lh min-w-0 flex-1 flex-row-reverse flex-wrap content-start items-center gap-x-2 overflow-y-clip", style: { width: box, maxWidth: `min(${box}, 100%)` }, children: [figureNode(true), _jsx("span", { className: "h-1.5 min-w-6 flex-1 overflow-hidden rounded-full bg-(color:--vk-neutral)", "aria-hidden": true, children: _jsx("span", { className: "block h-full bg-(color:--vk-brand)", style: { width: `${clamped}%` } }) })] }));
34
35
  }
35
36
  return (_jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [_jsx("span", { className: "h-4 w-4 shrink-0 rounded-full", style: {
36
37
  background: `conic-gradient(var(--vk-brand) ${clamped}%, var(--vk-neutral) 0)`,
@@ -3,6 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { phoneHref, phoneText, readPhone } from "@viewkitjs/fields/phone";
4
4
  import { resolveViewsMessage } from "../contract.js";
5
5
  import { cx } from "../internal/cx.js";
6
+ import { ELEMENT_RESET } from "../internal/reset.js";
6
7
  import { CHIP_INTERACTIVE } from "../internal/chip.js";
7
8
  import { cellLinkProps } from "./link-click.js";
8
9
  import { cellTextClass } from "./text-class.js";
@@ -43,5 +44,5 @@ function phoneNode(value, opts) {
43
44
  return (_jsx("span", { className: cellTextClass(opts?.wrap), ...asTyped, children: text }));
44
45
  }
45
46
  const owned = cellLinkProps(opts);
46
- return (_jsx("a", { href: phoneHref(value) ?? undefined, ...(owned ?? { "data-no-nav": true, onClick: (event) => event.stopPropagation() }), className: CHIP_INTERACTIVE, ...asTyped, children: _jsx("span", { className: cx("min-w-0", cellTextClass(opts?.wrap)), children: text }) }));
47
+ return (_jsx("a", { href: phoneHref(value) ?? undefined, ...(owned ?? { "data-no-nav": true, onClick: (event) => event.stopPropagation() }), className: cx(ELEMENT_RESET, CHIP_INTERACTIVE), ...asTyped, children: _jsx("span", { className: cx("min-w-0", cellTextClass(opts?.wrap)), children: text }) }));
47
48
  }
@@ -1,16 +1,10 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { rangeText } from "@viewkitjs/fields";
4
+ import { rangePeriodShort, rangeUnit } from "../fields/range-unit.js";
4
5
  import { useViews } from "../provider/context.js";
5
6
  import { CellSuffix } from "./format.js";
6
7
  import { cellTextClass } from "./text-class.js";
7
- const PERIOD_SHORT = {
8
- hour: "/h",
9
- day: "/day",
10
- week: "/wk",
11
- month: "/mo",
12
- year: "/yr",
13
- };
14
8
  export function renderRange(field, value, opts) {
15
9
  return _jsx(RangeValueCell, { field: field, value: value, opts: opts });
16
10
  }
@@ -19,11 +13,7 @@ function RangeValueCell({ field, value, opts, }) {
19
13
  const text = rangeText(field, value, conventions);
20
14
  if (!text)
21
15
  return null;
22
- const unit = field.of === "percent"
23
- ? "%"
24
- : field.of === "currency"
25
- ? field.code?.fixed
26
- : field.format?.suffix;
27
- const period = field.period ? PERIOD_SHORT[field.period] : undefined;
16
+ const unit = rangeUnit(field);
17
+ const period = rangePeriodShort(field);
28
18
  return (_jsxs("span", { className: cellTextClass(opts?.wrap), title: text, children: [_jsx("span", { className: "tabular-nums", children: text }), unit && _jsx(CellSuffix, { children: unit }), period && _jsx(CellSuffix, { children: period })] }));
29
19
  }
@@ -1,11 +1,23 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { orderLinks, relationKinds, resolveRelationValue, } from "@viewkitjs/fields";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { orderLinks, relationKinds, relationRolesOf, resolveRelationValue, } from "@viewkitjs/fields";
4
4
  import { CHIP_BASE } from "../internal/chip.js";
5
5
  import { useViews } from "../provider/context.js";
6
6
  import { EntityChipIdentity } from "./entity-chip.js";
7
7
  import { MultiValueCell } from "./multi-value.js";
8
8
  import { cellTextClass } from "./text-class.js";
9
+ function roleLabels(field, relation) {
10
+ if (field.cardinality !== "many" || !field.links)
11
+ return [];
12
+ const declared = field.links.roles ?? [];
13
+ return relationRolesOf(relation).map((value) => ({
14
+ value,
15
+ label: declared.find((option) => option.value === value)?.label ?? value,
16
+ }));
17
+ }
18
+ function chipTitle(relation, roles) {
19
+ return roles.length ? `${relation.label} · ${roles.map((role) => role.label).join(", ")}` : relation.label;
20
+ }
9
21
  export function renderRelation(field, value, opts) {
10
22
  if (Array.isArray(value)) {
11
23
  const chips = orderLinks(field, value
@@ -13,17 +25,20 @@ export function renderRelation(field, value, opts) {
13
25
  .filter((entry) => entry != null));
14
26
  if (chips.length === 0)
15
27
  return null;
16
- return (_jsx(MultiValueCell, { items: chips.map((chip) => _jsx(RelationChip, { relation: chip, opts: opts }, `${chip.entity ?? ""}:${chip.id}`)), wrap: !!opts?.wrap, title: chips.map((chip) => chip.label).join(", "), slotOwnsClick: opts?.slotOwnsClick }));
28
+ return (_jsx(MultiValueCell, { items: chips.map((chip) => (_jsx(RelationChip, { field: field, relation: chip, opts: opts }, `${chip.entity ?? ""}:${chip.id}`))), wrap: !!opts?.wrap, title: chips.map((chip) => chipTitle(chip, roleLabels(field, chip))).join(", "), slotOwnsClick: opts?.slotOwnsClick }));
17
29
  }
18
30
  const relation = resolveRelationValue(value, relationKinds(field)[0]);
19
31
  if (!relation)
20
32
  return null;
21
- return _jsx(RelationChip, { relation: relation, opts: opts });
33
+ return _jsx(RelationChip, { field: field, relation: relation, opts: opts });
22
34
  }
23
- function RelationChip({ relation, opts }) {
24
- const Glyph = useViews().icons.relation;
25
- const chip = (_jsx(EntityChipIdentity, { label: relation.label, avatarUrl: relation.avatarUrl, iconOverride: relation.icon ?? opts?.entityIcon?.(relation.entity), fallbackIcon: _jsx(Glyph, { className: "h-3 w-3 shrink-0 text-(color:--vk-fg-subtlest)" }), labelClassName: cellTextClass(opts?.wrap) }));
35
+ function RelationChip({ field, relation, opts, }) {
36
+ const views = useViews();
37
+ const Glyph = views.icons.relation;
38
+ const { RelationRoles } = views.atoms;
39
+ const roles = roleLabels(field, relation);
40
+ const chip = (_jsxs(_Fragment, { children: [_jsx(EntityChipIdentity, { label: relation.label, avatarUrl: relation.avatarUrl, iconOverride: relation.icon ?? opts?.entityIcon?.(relation.entity), fallbackIcon: _jsx(Glyph, { className: "h-3 w-3 shrink-0 text-(color:--vk-fg-subtlest)" }), labelClassName: cellTextClass(opts?.wrap) }), roles.length > 0 ? _jsx(RelationRoles, { relation: relation, roles: roles }) : null] }));
26
41
  if (opts?.relationWrap)
27
42
  return opts.relationWrap(relation, chip);
28
- return (_jsx("span", { className: CHIP_BASE, title: relation.label, children: chip }));
43
+ return (_jsx("span", { className: CHIP_BASE, title: chipTitle(relation, roles), children: chip }));
29
44
  }
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useLayoutEffect, useRef, useState } from "react";
4
4
  import { markdownFirstLine, markdownPlainText } from "@viewkitjs/fields";
5
5
  import { cx } from "../internal/cx.js";
6
+ import { ELEMENT_RESET } from "../internal/reset.js";
6
7
  import { useViews } from "../provider/context.js";
7
8
  import { cellTextClass } from "./text-class.js";
8
9
  const FOLDED_PX = 160;
@@ -30,5 +31,5 @@ function RichTextBlock({ source }) {
30
31
  return (_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { ref: boxRef, className: cx("relative min-w-0 overflow-hidden", !open && tall && "max-h-40"), children: [_jsx(Markdown, { source: source }), !open && tall && (_jsx("div", { className: "pointer-events-none absolute inset-x-0 bottom-0 h-10 bg-linear-to-t from-(color:--vk-ground) to-transparent" }))] }), tall && (_jsx("button", { type: "button", "data-no-nav": true, onClick: (event) => {
31
32
  event.stopPropagation();
32
33
  setOpen((was) => !was);
33
- }, className: "mt-1 text-xs text-(color:--vk-fg-subtle) hover:text-(color:--vk-fg)", children: messages({ key: open ? "views.display.show-less" : "views.display.show-more" }) }))] }));
34
+ }, className: cx(ELEMENT_RESET, "mt-1 text-xs text-(color:--vk-fg-subtle) hover:text-(color:--vk-fg)"), children: messages({ key: open ? "views.display.show-less" : "views.display.show-more" }) }))] }));
34
35
  }
@@ -54,11 +54,15 @@ export declare const ChipsEditor: import("react").ForwardRefExoticComponent<{
54
54
  * added value goes through it on the way in — the same function the route
55
55
  * applies, so `Ops Team` and `ops-team` cannot come apart. */
56
56
  normalize?: (raw: string) => string;
57
- /** The core saw a key that means "done" (Escape, Tab, Shift-Tab). Picks never close it. */
57
+ /** The core saw a key that means "done" (Escape, Tab, Shift-Tab), or an app's own `Picker` said it is done.
58
+ * Its own list's picks never close it. */
58
59
  onRequestClose: (reason: CloseReason) => void;
59
60
  /** The host's words for this panel (fields' messages); default: the provider's conventions. */
60
61
  message?: FieldMessageResolver;
61
62
  /** Offer a row that adds the typed text when nothing held or offered is it. Default true; a closed
62
63
  * vocabulary passes false, and its search only filters what it offers. */
63
64
  creatable?: boolean;
65
+ /** The field's name, for an app's own `Picker` (its list's accessible name). Default: the field's
66
+ * placeholder words. */
67
+ label?: string;
64
68
  } & import("react").RefAttributes<ChipsEditorHandle>>;
@@ -3,14 +3,16 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, } from "react";
4
4
  import { sameListValue, } from "@viewkitjs/fields";
5
5
  import { useViews } from "../provider/context.js";
6
- export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions, resolve, normalize, onRequestClose, message, creatable = true }, ref) {
6
+ import { PickerFrame, pickerItemOf, typedPick, usePickerForm } from "./picker-slot.js";
7
+ export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions, resolve, normalize, onRequestClose, message, creatable = true, label }, ref) {
7
8
  const [draft, setDraft] = useState(values);
8
9
  const [search, setSearch] = useState("");
9
10
  const inputRef = useRef(null);
10
11
  const draftRef = useRef(values);
11
12
  const views = useViews();
12
13
  const words = message ?? views.conventions.messages;
13
- const { Command } = views.components;
14
+ const { Command, Picker } = views.components;
15
+ const form = usePickerForm();
14
16
  const { List, RowContent, Tag } = views.atoms;
15
17
  const Add = views.icons.add;
16
18
  const resolveClose = (reason) => {
@@ -27,6 +29,8 @@ export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions
27
29
  setDraft(next);
28
30
  };
29
31
  useEffect(() => {
32
+ if (Picker)
33
+ return;
30
34
  inputRef.current?.focus({ preventScroll: true });
31
35
  }, []);
32
36
  const clean = (raw) => (normalize ? normalize(raw) : raw.trim());
@@ -54,6 +58,15 @@ export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions
54
58
  remove(draft[draft.length - 1]);
55
59
  }
56
60
  };
61
+ if (Picker) {
62
+ const offered = [...suggestions, ...draft.filter((value) => !suggestions.includes(value))];
63
+ return (_jsx(PickerFrame, { onTab: (reason) => onRequestClose(reason), onKey: (event) => {
64
+ if (event.key === "Escape")
65
+ onRequestClose("escape");
66
+ }, children: _jsx(Picker, { label: label ?? words({ key: "chips.add-placeholder" }), items: offered.map((value) => pickerItemOf(resolve(value))), multiple: true, value: draft, onValueChange: (next) => setBoth([...new Set(Array.isArray(next) ? next : [])].filter((value) => value !== "" && (creatable || offered.includes(value)))), onDone: () => onRequestClose("pick"), search: words({ key: "chips.add-placeholder" }), onCreate: creatable
67
+ ? (typed) => typedPick(clean(typed), [...draftRef.current, ...suggestions], "")
68
+ : undefined, autoFocus: true, form: form }) }));
69
+ }
57
70
  return (_jsxs(Command.Root, { shouldFilter: false, loop: true, children: [_jsxs("div", { className: "flex flex-wrap items-center gap-1 border-b border-(color:--vk-border) px-2 py-2", onMouseDown: (event) => {
58
71
  if (event.target === event.currentTarget) {
59
72
  event.preventDefault();
@@ -37,4 +37,6 @@ export declare const DateEditor: import("react").ForwardRefExoticComponent<{
37
37
  message?: FieldMessageResolver;
38
38
  /** The calendar takes the panel's whole width (a phone's sheet), rather than its own. Default false. */
39
39
  fill?: boolean;
40
+ /** The field's name, for an app's `DateBody`. Default: the date box's words. */
41
+ label?: string;
40
42
  } & import("react").RefAttributes<DateEditorHandle>>;
@@ -4,8 +4,10 @@ import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from "r
4
4
  import { formatChipDate, normalizeTime, parseDateText, toYmd, } from "@viewkitjs/fields";
5
5
  import { fromDayKey, toDayKey } from "@viewkitjs/fields/query";
6
6
  import { cx } from "../internal/cx.js";
7
+ import { ELEMENT_RESET } from "../internal/reset.js";
7
8
  import { useViews } from "../provider/context.js";
8
9
  import { isDesktopNow } from "../provider/desktop.js";
10
+ import { usePickerForm } from "./picker-slot.js";
9
11
  const QUICK_DAYS = [
10
12
  { key: "date.today", offset: () => 0 },
11
13
  { key: "date.tomorrow", offset: () => 1 },
@@ -35,17 +37,29 @@ function readStored(iso) {
35
37
  const parsed = fromDayKey(iso) ?? new Date(iso);
36
38
  return Number.isNaN(parsed.getTime()) ? undefined : parsed;
37
39
  }
40
+ function readBodyValue(value) {
41
+ const day = fromDayKey(value.slice(0, 10));
42
+ if (!day)
43
+ return null;
44
+ if (value.length === 10)
45
+ return { day, time: null };
46
+ if (value[10] !== "T")
47
+ return null;
48
+ const time = normalizeTime(value.slice(11));
49
+ return time ? { day, time } : null;
50
+ }
51
+ const DATE_BODY_PICKS = ["today", "tomorrow", "next-monday"];
38
52
  function initialHasTime(iso, parsed) {
39
53
  if (!iso || !parsed)
40
54
  return false;
41
55
  return /T/.test(iso);
42
56
  }
43
- export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional = false, dayOnly = false, clearable = false, seed, focusDate = false, onRequestClose, message, fill = false, }, ref) {
57
+ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional = false, dayOnly = false, clearable = false, seed, focusDate = false, onRequestClose, message, fill = false, label, }, ref) {
44
58
  const timeRef = useRef(null);
45
59
  const dateRef = useRef(null);
46
60
  const views = useViews();
47
61
  const words = message ?? views.conventions.messages;
48
- const { Calendar, Input } = views.components;
62
+ const { Calendar, Input, DateBody } = views.components;
49
63
  const { List, Row } = views.atoms;
50
64
  const DateGlyph = views.icons.date;
51
65
  const TimeGlyph = views.icons.time;
@@ -61,7 +75,7 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
61
75
  ? ""
62
76
  : "00:00";
63
77
  const [timeVal, setTimeVal] = useState(initialTime);
64
- const [dateVal, setDateVal] = useState(() => seed ?? formatChipDate(valid ?? new Date()));
78
+ const [dateVal, setDateVal] = useState(() => seed ?? (valid ? formatChipDate(valid) : ""));
65
79
  const touchedRef = useRef(seed != null);
66
80
  const dayRef = useRef(valid);
67
81
  const dateTextRef = useRef(dateVal);
@@ -100,8 +114,8 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
100
114
  box?.setSelectionRange(seed.length, seed.length);
101
115
  }, []);
102
116
  const applyDateText = () => {
103
- const base = dayRef.current ?? valid ?? new Date();
104
- const typed = parseDateText(dateTextRef.current, base.getFullYear());
117
+ const current = dayRef.current ?? valid;
118
+ const typed = parseDateText(dateTextRef.current, (current ?? new Date()).getFullYear());
105
119
  if (typed) {
106
120
  dayRef.current = typed;
107
121
  setDay(typed);
@@ -109,7 +123,7 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
109
123
  writeDateText(formatChipDate(typed));
110
124
  return typed;
111
125
  }
112
- writeDateText(formatChipDate(base));
126
+ writeDateText(current ? formatChipDate(current) : "");
113
127
  return undefined;
114
128
  };
115
129
  const resolveClose = (reason) => {
@@ -140,18 +154,70 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
140
154
  if (timeOpen)
141
155
  activeTimeRef.current?.scrollIntoView({ block: "center" });
142
156
  }, [timeOpen]);
157
+ const tabbingRef = useRef(null);
143
158
  const onTabOut = (event) => {
144
159
  if (event.key !== "Tab" || event.altKey || event.ctrlKey || event.metaKey)
145
160
  return;
146
161
  const { first, last } = tabEnds(event.currentTarget);
147
162
  const leaving = event.shiftKey ? event.target === first : event.target === last;
148
- if (!leaving)
163
+ if (!leaving) {
164
+ tabbingRef.current = event.shiftKey ? "shift-tab" : "tab";
165
+ setTimeout(() => (tabbingRef.current = null), 0);
149
166
  return;
167
+ }
150
168
  event.preventDefault();
151
169
  event.stopPropagation();
152
170
  onRequestClose(event.shiftKey ? "shift-tab" : "tab");
153
171
  };
154
- return (_jsxs("div", { "data-slot": "vk-date-editor", className: "contents", onKeyDownCapture: onTabOut, children: [_jsxs("div", { className: "flex items-center gap-1.5 border-b border-(color:--vk-border) p-2", children: [_jsxs("div", { className: "flex h-8 min-w-0 flex-1 items-center gap-2 rounded-lg bg-(color:--vk-neutral) px-2.5 focus-within:bg-(color:--vk-neutral-hovered)", children: [_jsx(DateGlyph, { className: "h-3.5 w-3.5 shrink-0 text-(color:--vk-fg-subtlest)" }), _jsx(Input, { ref: dateRef, type: "text", value: dateVal, onChange: (e) => {
172
+ const onTabAway = (event) => {
173
+ const via = tabbingRef.current;
174
+ if (!via)
175
+ return;
176
+ const to = event.relatedTarget;
177
+ if (to && event.currentTarget.contains(to))
178
+ return;
179
+ tabbingRef.current = null;
180
+ onRequestClose(via);
181
+ };
182
+ const form = usePickerForm();
183
+ const bodyStart = !valid ? null : dayOnly || !initialTime ? toYmd(valid) : `${toYmd(valid)}T${initialTime}`;
184
+ const [bodyValue, setBodyValue] = useState(bodyStart);
185
+ if (DateBody) {
186
+ const takeBodyValue = (value) => {
187
+ if (value === null) {
188
+ if (!clearable)
189
+ return;
190
+ clearedRef.current = true;
191
+ setBodyValue(null);
192
+ return;
193
+ }
194
+ const read = readBodyValue(value);
195
+ if (!read)
196
+ return;
197
+ touchedRef.current = true;
198
+ dayRef.current = read.day;
199
+ setDay(read.day);
200
+ setMonth(read.day);
201
+ writeDateText(formatChipDate(read.day));
202
+ if (read.time)
203
+ writeTime(read.time);
204
+ else if (timeOptional)
205
+ writeTime("");
206
+ const time = dayOnly ? null : (read.time ?? (timeOptional ? null : (normalizeTime(timeTextRef.current) ?? initialTime)));
207
+ setBodyValue(time ? `${toYmd(read.day)}T${time}` : toYmd(read.day));
208
+ };
209
+ const onBodyKey = (event) => {
210
+ if (event.key === "Escape" && !event.altKey && !event.ctrlKey && !event.metaKey) {
211
+ event.preventDefault();
212
+ event.stopPropagation();
213
+ onRequestClose("escape");
214
+ return;
215
+ }
216
+ onTabOut(event);
217
+ };
218
+ return (_jsx("div", { "data-slot": "vk-date-editor", className: "contents", onKeyDownCapture: onBodyKey, onBlurCapture: onTabAway, children: _jsx(DateBody, { label: label ?? words({ key: "date.label" }), value: bodyValue, onValueChange: takeBodyValue, onDone: () => onRequestClose("pick"), time: !dayOnly, empty: clearable, picks: clearable ? [...DATE_BODY_PICKS, "none"] : [...DATE_BODY_PICKS], today: toDayKey(new Date()), typed: seed, autoFocus: focusDate || seed != null, form: form }) }));
219
+ }
220
+ return (_jsxs("div", { "data-slot": "vk-date-editor", className: "contents", onKeyDownCapture: onTabOut, onBlurCapture: onTabAway, children: [_jsxs("div", { className: "flex items-center gap-1.5 border-b border-(color:--vk-border) p-2", children: [_jsxs("div", { className: "flex h-8 min-w-0 flex-1 items-center gap-2 rounded-lg bg-(color:--vk-neutral) px-2.5 focus-within:bg-(color:--vk-neutral-hovered)", children: [_jsx(DateGlyph, { className: "h-3.5 w-3.5 shrink-0 text-(color:--vk-fg-subtlest)" }), _jsx(Input, { ref: dateRef, type: "text", value: dateVal, onChange: (e) => {
155
221
  touchedRef.current = true;
156
222
  writeDateText(e.target.value);
157
223
  }, onBlur: applyDateText, onFocus: () => setTimeOpen(false), placeholder: words({ key: "date.placeholder" }), "aria-label": words({ key: "date.label" }), onClick: (e) => e.stopPropagation(), onKeyDown: (e) => {
@@ -193,11 +259,11 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
193
259
  writeTime(t);
194
260
  setTimeOpen(false);
195
261
  timeRef.current?.focus();
196
- }, className: cx("w-full px-3 py-1.5 text-left text-sm tabular-nums hover:bg-(color:--vk-hovered)", active ? "bg-(color:--vk-neutral) font-medium text-(color:--vk-fg)" : "text-(color:--vk-fg-subtle)"), children: t }, t));
262
+ }, className: cx(ELEMENT_RESET, "w-full px-3 py-1.5 text-left text-sm tabular-nums hover:bg-(color:--vk-hovered)", active ? "bg-(color:--vk-neutral) font-medium text-(color:--vk-fg)" : "text-(color:--vk-fg-subtle)"), children: t }, t));
197
263
  }) }))] }))] }), _jsx("div", { className: "flex gap-1 px-2 pt-2", children: QUICK_DAYS.map((quick) => (_jsx("button", { type: "button", onClick: (e) => {
198
264
  e.stopPropagation();
199
265
  chooseDay(quickDay(quick.offset));
200
- }, className: "h-7 rounded-md bg-(color:--vk-neutral) px-2 text-xs text-(color:--vk-fg-subtle) hover:bg-(color:--vk-neutral-hovered) hover:text-(color:--vk-fg)", children: words({ key: quick.key }) }, quick.key))) }), _jsx(Calendar, { locale: views.conventions.locale, ...(fill ? { className: "w-full" } : {}), value: (day ?? valid) ? toDayKey((day ?? valid)) : null, onChange: (picked) => {
266
+ }, className: cx(ELEMENT_RESET, "h-7 rounded-md bg-(color:--vk-neutral) px-2 text-xs text-(color:--vk-fg-subtle) hover:bg-(color:--vk-neutral-hovered) hover:text-(color:--vk-fg)"), children: words({ key: quick.key }) }, quick.key))) }), _jsx(Calendar, { locale: views.conventions.locale, ...(fill ? { className: "w-full" } : {}), value: (day ?? valid) ? toDayKey((day ?? valid)) : null, onChange: (picked) => {
201
267
  const d = picked ? fromDayKey(picked) : null;
202
268
  if (d)
203
269
  chooseDay(d);
@@ -7,12 +7,15 @@ import type { EditSession } from "./edit-session.js";
7
7
  * stands. The editor inside never reads which.
8
8
  *
9
9
  * It owns what each surface's dismissals MEAN, so no host decides them: on a desktop the popover's
10
- * Escape discards (unless it comes from an inner level the editor marked, `EDITOR_INNER_ESCAPE`,
10
+ * Escape is the session's, a discard unless the field's type keeps (the session's `escape`), save one from
11
+ * an inner level the editor marked (`EDITOR_INNER_ESCAPE`,
11
12
  * which the editor closes itself), its outside press is the editor's own rule, and a focus leaving it
12
13
  * closes as a blur; on a phone every way a sheet
13
- * goes away (a swipe, its backdrop, Escape, the bar's ✕) discards, and the bar's ✓ closes as done.
14
+ * goes away (a swipe, its backdrop, Escape, the ✕) discards, and the ✓ closes as done: the ✕ and ✓
15
+ * stand in the panel's own bar, or in the app's Sheet's head when the provider says `sheetActions: "head"`.
14
16
  * A refusal the host gave stays on screen under the editor, in the popover and the sheet; in
15
- * place, the host's own box draws it.
17
+ * place, the host's own box draws it, and an editor that draws it itself says so
18
+ * (`editorDrawsRefusal`).
16
19
  *
17
20
  * The surface is chosen ONCE, when the session opens: a window crossing the desktop width
18
21
  * mid-edit keeps the panel it opened in until the session ends.
@@ -45,6 +48,13 @@ export type EditorPanelProps = {
45
48
  /** A click inside the popover or the sheet. The sheet keeps every press to itself after this; the
46
49
  * popover leaves that to the host (a grid host stops it here). */
47
50
  onPanelClick?: (event: ReactMouseEvent<HTMLDivElement>) => void;
51
+ /** The editor draws the session's refusal itself (a range with bands, between its boxes and its
52
+ * bands), so the panel draws none under it. Default false. */
53
+ editorDrawsRefusal?: boolean;
54
+ /** The body saves on its pick (a pick of one), so it needs no ✓: an app's Sheet that draws the
55
+ * panel's buttons in its head (the provider's `sheetActions: "head"`) is handed no `done`. The
56
+ * panel's own bar keeps its ✓. Default false. */
57
+ savesOnPick?: boolean;
48
58
  /** The editor, or a function of the surface the panel chose, for a type-in host that draws
49
59
  * differently in place (its own refusal, say) than in the sheet. */
50
60
  children: ReactNode | ((surface: EditorSurface) => ReactNode);
@@ -58,4 +68,4 @@ export type EditorPanelProps = {
58
68
  export declare const EDITOR_INNER_ESCAPE = "data-vk-inner-escape";
59
69
  /** Where the panel opened its editor: the app's popover, its sheet, or where the value stands. */
60
70
  export type EditorSurface = "popover" | "sheet" | "in-place";
61
- export declare function EditorPanel({ session, title, anchor, inPlace, sheetOnPhone, snap, panelData, children, ...popover }: EditorPanelProps): ReactNode;
71
+ export declare function EditorPanel({ session, title, anchor, inPlace, sheetOnPhone, snap, panelData, editorDrawsRefusal, savesOnPick, children, ...popover }: EditorPanelProps): ReactNode;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useLayoutEffect, useState, } from "react";
3
+ import { useLayoutEffect, useRef, useState, } from "react";
4
4
  import { useDesktop } from "../provider/desktop.js";
5
5
  import { useViews } from "../provider/context.js";
6
6
  export const EDITOR_INNER_ESCAPE = "data-vk-inner-escape";
@@ -8,7 +8,7 @@ function innerEscape(event) {
8
8
  const target = event.target;
9
9
  return target instanceof Element && target.closest(`[${EDITOR_INNER_ESCAPE}]`) !== null;
10
10
  }
11
- export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPhone = false, snap = "auto", panelData, children, ...popover }) {
11
+ export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPhone = false, snap = "auto", panelData, editorDrawsRefusal = false, savesOnPick = false, children, ...popover }) {
12
12
  const views = useViews();
13
13
  const { Popover, Sheet, Button } = views.components;
14
14
  const Discard = views.icons.close;
@@ -16,6 +16,7 @@ export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPh
16
16
  const desktop = useDesktop();
17
17
  const [surface] = useState(() => desktop ? (inPlace ? "in-place" : "popover") : inPlace && !sheetOnPhone ? "in-place" : "sheet");
18
18
  const { open, close, refusal } = session;
19
+ const escapedRef = useRef(false);
19
20
  const editor = typeof children === "function" ? children(surface) : children;
20
21
  useLayoutEffect(() => {
21
22
  if (surface !== "in-place")
@@ -25,11 +26,15 @@ export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPh
25
26
  }, []);
26
27
  if (surface === "in-place")
27
28
  return editor;
28
- const reason = refusal ? (_jsx("p", { role: "alert", "data-slot": "vk-editor-refusal", className: "px-2 pb-2 text-xs text-(color:--vk-danger)", children: refusal })) : null;
29
+ const reason = refusal && !editorDrawsRefusal ? (_jsx("p", { role: "alert", "data-slot": "vk-editor-refusal", className: "px-2 pb-2 text-xs text-(color:--vk-danger)", children: refusal })) : null;
29
30
  if (surface === "popover") {
30
31
  return (_jsxs(Popover, { ...popover, open: open, onOpenChange: (next, details) => {
31
32
  if (next || details?.reason === "outside-press")
32
33
  return;
34
+ if (details?.reason === "escape-key" && escapedRef.current) {
35
+ escapedRef.current = false;
36
+ return;
37
+ }
33
38
  if (details?.reason === "focus-out")
34
39
  close("blur");
35
40
  else
@@ -37,6 +42,10 @@ export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPh
37
42
  }, anchor: anchor, onEscape: (event) => {
38
43
  if (innerEscape(event))
39
44
  return false;
45
+ escapedRef.current = true;
46
+ window.setTimeout(() => {
47
+ escapedRef.current = false;
48
+ }, 0);
40
49
  close("escape");
41
50
  }, onOutsidePress: () => {
42
51
  if (open)
@@ -44,11 +53,19 @@ export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPh
44
53
  }, panelData: { "data-slot": "vk-editor-panel", ...panelData }, children: [editor, reason] }));
45
54
  }
46
55
  const keep = (event) => event.stopPropagation();
56
+ const discardLabel = views.messages({ key: "views.editors.discard" });
57
+ const saveLabel = views.messages({ key: "views.editors.save" });
58
+ const actions = views.sheetActions === "head"
59
+ ? {
60
+ close: { label: discardLabel, onPress: () => close("escape") },
61
+ ...(!savesOnPick && { done: { label: saveLabel, onPress: () => close("enter") } }),
62
+ }
63
+ : undefined;
47
64
  return (_jsx("span", { className: "contents", onClick: (event) => {
48
65
  popover.onPanelClick?.(event);
49
66
  event.stopPropagation();
50
67
  }, onDoubleClick: keep, onContextMenu: keep, children: _jsx(Sheet, { open: open, onOpenChange: (next) => {
51
68
  if (!next)
52
69
  close("escape");
53
- }, title: title, snap: snap, children: _jsxs("div", { "data-slot": "vk-editor-panel", children: [_jsxs("div", { "data-slot": "vk-editor-bar", className: "flex items-center justify-between px-2 pb-1", children: [_jsx(Button, { variant: "ghost", size: "icon", "aria-label": views.messages({ key: "views.editors.discard" }), onClick: () => close("escape"), children: _jsx(Discard, { className: "size-4" }) }), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": views.messages({ key: "views.editors.save" }), onClick: () => close("enter"), children: _jsx(Save, { className: "size-4" }) })] }), editor, reason] }) }) }));
70
+ }, title: title, ...(typeof title === "string" || typeof title === "number" ? { label: String(title) } : {}), ...(actions && { actions }), snap: snap, children: _jsxs("div", { "data-slot": "vk-editor-panel", children: [actions ? null : (_jsxs("div", { "data-slot": "vk-editor-bar", className: "flex items-center justify-between px-2 pb-1", children: [_jsx(Button, { variant: "ghost", size: "icon", "aria-label": discardLabel, onClick: () => close("escape"), children: _jsx(Discard, { className: "size-4" }) }), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": saveLabel, onClick: () => close("enter"), children: _jsx(Save, { className: "size-4" }) })] })), editor, reason] }) }) }));
54
71
  }