@viewkitjs/views 0.0.0-stage → 0.1.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 (270) hide show
  1. package/CHANGELOG.md +420 -0
  2. package/LICENSE.md +7 -0
  3. package/README.md +50 -2
  4. package/dist/atoms/CommandMenu.d.ts +2 -0
  5. package/dist/atoms/CommandMenu.js +20 -0
  6. package/dist/atoms/List.d.ts +2 -0
  7. package/dist/atoms/List.js +6 -0
  8. package/dist/atoms/LoadMore.d.ts +2 -0
  9. package/dist/atoms/LoadMore.js +25 -0
  10. package/dist/atoms/Loading.d.ts +2 -0
  11. package/dist/atoms/Loading.js +7 -0
  12. package/dist/atoms/PlatformMark.d.ts +2 -0
  13. package/dist/atoms/PlatformMark.js +4 -0
  14. package/dist/atoms/RelationLink.d.ts +2 -0
  15. package/dist/atoms/RelationLink.js +6 -0
  16. package/dist/atoms/Row.d.ts +3 -0
  17. package/dist/atoms/Row.js +30 -0
  18. package/dist/atoms/RowMenu.d.ts +2 -0
  19. package/dist/atoms/RowMenu.js +101 -0
  20. package/dist/atoms/StatusBadge.d.ts +2 -0
  21. package/dist/atoms/StatusBadge.js +7 -0
  22. package/dist/atoms/StatusMarker.d.ts +2 -0
  23. package/dist/atoms/StatusMarker.js +19 -0
  24. package/dist/atoms/Tag.d.ts +2 -0
  25. package/dist/atoms/Tag.js +13 -0
  26. package/dist/atoms/TickBox.d.ts +2 -0
  27. package/dist/atoms/TickBox.js +8 -0
  28. package/dist/atoms/defaults.d.ts +2 -0
  29. package/dist/atoms/defaults.js +27 -0
  30. package/dist/atoms/tones.d.ts +5 -0
  31. package/dist/atoms/tones.js +28 -0
  32. package/dist/atoms/types.d.ts +178 -0
  33. package/dist/atoms/types.js +3 -0
  34. package/dist/cells/cell-format.d.ts +138 -0
  35. package/dist/cells/cell-format.js +16 -0
  36. package/dist/cells/cell-title.d.ts +17 -0
  37. package/dist/cells/cell-title.js +8 -0
  38. package/dist/cells/cell-values.d.ts +28 -0
  39. package/dist/cells/cell-values.js +87 -0
  40. package/dist/cells/index.d.ts +4 -0
  41. package/dist/cells/index.js +4 -0
  42. package/dist/cells/legacy-field.d.ts +52 -0
  43. package/dist/cells/legacy-field.js +164 -0
  44. package/dist/cells/relation-wrap.d.ts +3 -0
  45. package/dist/cells/relation-wrap.js +24 -0
  46. package/dist/cells/use-cell-format.d.ts +5 -0
  47. package/dist/cells/use-cell-format.js +10 -0
  48. package/dist/contract.d.ts +431 -0
  49. package/dist/contract.js +663 -0
  50. package/dist/display/actor.d.ts +4 -0
  51. package/dist/display/actor.js +26 -0
  52. package/dist/display/boolean.d.ts +18 -0
  53. package/dist/display/boolean.js +43 -0
  54. package/dist/display/breakdown.d.ts +15 -0
  55. package/dist/display/breakdown.js +32 -0
  56. package/dist/display/currency.d.ts +9 -0
  57. package/dist/display/currency.js +29 -0
  58. package/dist/display/date.d.ts +12 -0
  59. package/dist/display/date.js +26 -0
  60. package/dist/display/display-cores.d.ts +31 -0
  61. package/dist/display/display-cores.js +57 -0
  62. package/dist/display/entity-chip.d.ts +26 -0
  63. package/dist/display/entity-chip.js +9 -0
  64. package/dist/display/format.d.ts +51 -0
  65. package/dist/display/format.js +181 -0
  66. package/dist/display/index.d.ts +8 -0
  67. package/dist/display/index.js +7 -0
  68. package/dist/display/link.d.ts +29 -0
  69. package/dist/display/link.js +48 -0
  70. package/dist/display/location.d.ts +7 -0
  71. package/dist/display/location.js +15 -0
  72. package/dist/display/multi-value.d.ts +18 -0
  73. package/dist/display/multi-value.js +28 -0
  74. package/dist/display/name.d.ts +6 -0
  75. package/dist/display/name.js +14 -0
  76. package/dist/display/number.d.ts +11 -0
  77. package/dist/display/number.js +27 -0
  78. package/dist/display/options.d.ts +153 -0
  79. package/dist/display/options.js +1 -0
  80. package/dist/display/percent.d.ts +4 -0
  81. package/dist/display/percent.js +33 -0
  82. package/dist/display/phone.d.ts +10 -0
  83. package/dist/display/phone.js +38 -0
  84. package/dist/display/range.d.ts +6 -0
  85. package/dist/display/range.js +29 -0
  86. package/dist/display/relation.d.ts +4 -0
  87. package/dist/display/relation.js +29 -0
  88. package/dist/display/rich-text.d.ts +10 -0
  89. package/dist/display/rich-text.js +34 -0
  90. package/dist/display/select.d.ts +6 -0
  91. package/dist/display/select.js +38 -0
  92. package/dist/display/text-class.d.ts +23 -0
  93. package/dist/display/text-class.js +5 -0
  94. package/dist/display/text.d.ts +19 -0
  95. package/dist/display/text.js +8 -0
  96. package/dist/display/use-display-options.d.ts +2 -0
  97. package/dist/display/use-display-options.js +14 -0
  98. package/dist/display/user.d.ts +11 -0
  99. package/dist/display/user.js +10 -0
  100. package/dist/display/value-list.d.ts +10 -0
  101. package/dist/display/value-list.js +12 -0
  102. package/dist/display/viewer.d.ts +4 -0
  103. package/dist/display/viewer.js +11 -0
  104. package/dist/display/web-href.d.ts +8 -0
  105. package/dist/display/web-href.js +12 -0
  106. package/dist/editors/ChipsEditor.d.ts +59 -0
  107. package/dist/editors/ChipsEditor.js +73 -0
  108. package/dist/editors/DateEditor.d.ts +25 -0
  109. package/dist/editors/DateEditor.js +122 -0
  110. package/dist/editors/LocationEditor.d.ts +22 -0
  111. package/dist/editors/LocationEditor.js +229 -0
  112. package/dist/editors/NameEditor.d.ts +22 -0
  113. package/dist/editors/NameEditor.js +91 -0
  114. package/dist/editors/NumberEditor.d.ts +67 -0
  115. package/dist/editors/NumberEditor.js +86 -0
  116. package/dist/editors/RangeEditor.d.ts +22 -0
  117. package/dist/editors/RangeEditor.js +70 -0
  118. package/dist/editors/RelationEditor.d.ts +65 -0
  119. package/dist/editors/RelationEditor.js +64 -0
  120. package/dist/editors/SelectEditor.d.ts +72 -0
  121. package/dist/editors/SelectEditor.js +59 -0
  122. package/dist/editors/ValueListEditor.d.ts +38 -0
  123. package/dist/editors/ValueListEditor.js +217 -0
  124. package/dist/editors/edit-cores.d.ts +83 -0
  125. package/dist/editors/edit-cores.js +38 -0
  126. package/dist/editors/edit-session.d.ts +74 -0
  127. package/dist/editors/edit-session.js +35 -0
  128. package/dist/editors/open-values.d.ts +28 -0
  129. package/dist/editors/open-values.js +26 -0
  130. package/dist/editors/relation-source.d.ts +66 -0
  131. package/dist/editors/relation-source.js +102 -0
  132. package/dist/fields/binding.d.ts +87 -0
  133. package/dist/fields/binding.js +117 -0
  134. package/dist/fields/currency.d.ts +92 -0
  135. package/dist/fields/currency.js +55 -0
  136. package/dist/fields/denomination.d.ts +42 -0
  137. package/dist/fields/denomination.js +11 -0
  138. package/dist/fields/edit-core-types.d.ts +40 -0
  139. package/dist/fields/edit-core-types.js +29 -0
  140. package/dist/fields/format-knobs.d.ts +34 -0
  141. package/dist/fields/format-knobs.js +36 -0
  142. package/dist/fields/menus.d.ts +28 -0
  143. package/dist/fields/menus.js +1 -0
  144. package/dist/fields/money.d.ts +59 -0
  145. package/dist/fields/money.js +77 -0
  146. package/dist/fields/number-edit.d.ts +11 -0
  147. package/dist/fields/number-edit.js +17 -0
  148. package/dist/fields/prepare-write.d.ts +55 -0
  149. package/dist/fields/prepare-write.js +67 -0
  150. package/dist/fields/relation-source-types.d.ts +54 -0
  151. package/dist/fields/relation-source-types.js +1 -0
  152. package/dist/figures.d.ts +52 -0
  153. package/dist/figures.js +63 -0
  154. package/dist/filters/date-filter.d.ts +2 -0
  155. package/dist/filters/date-filter.js +1 -0
  156. package/dist/filters/filter-model.d.ts +177 -0
  157. package/dist/filters/filter-model.js +41 -0
  158. package/dist/filters/number-filter.d.ts +2 -0
  159. package/dist/filters/number-filter.js +1 -0
  160. package/dist/filters/range-filter.d.ts +2 -0
  161. package/dist/filters/range-filter.js +1 -0
  162. package/dist/filters/registry.d.ts +136 -0
  163. package/dist/filters/registry.js +46 -0
  164. package/dist/filters/relation-filter.d.ts +16 -0
  165. package/dist/filters/relation-filter.js +53 -0
  166. package/dist/filters/text-filter.d.ts +2 -0
  167. package/dist/filters/text-filter.js +1 -0
  168. package/dist/filters/types.d.ts +27 -0
  169. package/dist/filters/types.js +1 -0
  170. package/dist/grouping/sort-groups.d.ts +18 -0
  171. package/dist/grouping/sort-groups.js +33 -0
  172. package/dist/grouping/types.d.ts +10 -0
  173. package/dist/grouping/types.js +1 -0
  174. package/dist/index.d.ts +29 -0
  175. package/dist/index.js +29 -0
  176. package/dist/internal/chip.d.ts +4 -0
  177. package/dist/internal/chip.js +3 -0
  178. package/dist/internal/cx.d.ts +3 -0
  179. package/dist/internal/cx.js +3 -0
  180. package/dist/model/aggregates.d.ts +59 -0
  181. package/dist/model/aggregates.js +186 -0
  182. package/dist/model/card-density.d.ts +8 -0
  183. package/dist/model/card-density.js +10 -0
  184. package/dist/model/card-layout.d.ts +85 -0
  185. package/dist/model/card-layout.js +90 -0
  186. package/dist/model/column-capabilities.d.ts +162 -0
  187. package/dist/model/column-capabilities.js +233 -0
  188. package/dist/model/column-filters.d.ts +106 -0
  189. package/dist/model/column-filters.js +321 -0
  190. package/dist/model/column-format.d.ts +103 -0
  191. package/dist/model/column-format.js +1 -0
  192. package/dist/model/column-from.d.ts +28 -0
  193. package/dist/model/column-from.js +160 -0
  194. package/dist/model/column-inspect.d.ts +18 -0
  195. package/dist/model/column-inspect.js +6 -0
  196. package/dist/model/column-knobs.d.ts +20 -0
  197. package/dist/model/column-knobs.js +16 -0
  198. package/dist/model/column-money.d.ts +13 -0
  199. package/dist/model/column-money.js +27 -0
  200. package/dist/model/column-order.d.ts +36 -0
  201. package/dist/model/column-order.js +68 -0
  202. package/dist/model/column-schema.d.ts +335 -0
  203. package/dist/model/column-schema.js +1 -0
  204. package/dist/model/column-sort.d.ts +17 -0
  205. package/dist/model/column-sort.js +11 -0
  206. package/dist/model/column-state.d.ts +77 -0
  207. package/dist/model/column-state.js +95 -0
  208. package/dist/model/column-types.d.ts +109 -0
  209. package/dist/model/column-types.js +50 -0
  210. package/dist/model/column-warnings.d.ts +44 -0
  211. package/dist/model/column-warnings.js +24 -0
  212. package/dist/model/density.d.ts +3 -0
  213. package/dist/model/density.js +13 -0
  214. package/dist/model/field-type-of.d.ts +21 -0
  215. package/dist/model/field-type-of.js +11 -0
  216. package/dist/model/filter-capabilities.d.ts +1 -0
  217. package/dist/model/filter-capabilities.js +1 -0
  218. package/dist/model/filter-pushdown.d.ts +106 -0
  219. package/dist/model/filter-pushdown.js +147 -0
  220. package/dist/model/index.d.ts +40 -0
  221. package/dist/model/index.js +21 -0
  222. package/dist/model/part-rows.d.ts +28 -0
  223. package/dist/model/part-rows.js +40 -0
  224. package/dist/model/preferences.d.ts +151 -0
  225. package/dist/model/preferences.js +84 -0
  226. package/dist/model/prefs-buckets.d.ts +173 -0
  227. package/dist/model/prefs-buckets.js +71 -0
  228. package/dist/model/relation-filters.d.ts +45 -0
  229. package/dist/model/relation-filters.js +78 -0
  230. package/dist/model/render-count.d.ts +2 -0
  231. package/dist/model/render-count.js +24 -0
  232. package/dist/model/row-icon.d.ts +23 -0
  233. package/dist/model/row-icon.js +5 -0
  234. package/dist/model/view-rules.d.ts +73 -0
  235. package/dist/model/view-rules.js +216 -0
  236. package/dist/provider/ViewsProvider.d.ts +26 -0
  237. package/dist/provider/ViewsProvider.js +12 -0
  238. package/dist/provider/components.d.ts +222 -0
  239. package/dist/provider/components.js +3 -0
  240. package/dist/provider/context.d.ts +19 -0
  241. package/dist/provider/context.js +10 -0
  242. package/dist/provider/icons.d.ts +6 -0
  243. package/dist/provider/icons.js +1 -0
  244. package/dist/provider/ports.d.ts +35 -0
  245. package/dist/provider/ports.js +8 -0
  246. package/dist/react.d.ts +9 -0
  247. package/dist/react.js +4 -0
  248. package/dist/selection/SelectCheckbox.d.ts +17 -0
  249. package/dist/selection/SelectCheckbox.js +11 -0
  250. package/dist/selection/index.d.ts +7 -0
  251. package/dist/selection/index.js +6 -0
  252. package/dist/selection/model.d.ts +55 -0
  253. package/dist/selection/model.js +86 -0
  254. package/dist/selection/row-click.d.ts +35 -0
  255. package/dist/selection/row-click.js +20 -0
  256. package/dist/selection/types.d.ts +17 -0
  257. package/dist/selection/types.js +1 -0
  258. package/dist/selection/useCheckDragSelect.d.ts +61 -0
  259. package/dist/selection/useCheckDragSelect.js +165 -0
  260. package/dist/selection/useListSelection.d.ts +39 -0
  261. package/dist/selection/useListSelection.js +48 -0
  262. package/dist/selection/useListSelectionShortcuts.d.ts +6 -0
  263. package/dist/selection/useListSelectionShortcuts.js +14 -0
  264. package/dist/selection/useRestIntent.d.ts +18 -0
  265. package/dist/selection/useRestIntent.js +35 -0
  266. package/docs/contract.md +453 -0
  267. package/docs/install.md +105 -0
  268. package/docs/reshaping.md +19 -0
  269. package/package.json +114 -3
  270. package/skills/views/SKILL.md +87 -0
@@ -0,0 +1,19 @@
1
+ import type { ReactNode } from "react";
2
+ import type { FieldDefOf } from "@viewkitjs/fields";
3
+ import type { DisplayOptions } from "./options.js";
4
+ /**
5
+ * Plain text — the value, clipped to the space it has, with itself on the hover.
6
+ *
7
+ * `title` is the escape hatch for a clipped value. A grid row is one line by
8
+ * design, so without it a long value (a note, a description) is
9
+ * visible-but-unreadable: you can see that something is there and have no way to
10
+ * get at it. The native tooltip is deliberately plain — a hover card here would
11
+ * fight the surrounding cell's own hover affordance.
12
+ *
13
+ * `format.long` picks the EDITOR (the grid's anchored panel over a one-line
14
+ * input) and drops the tooltip — the panel is where a paragraph is read, and a
15
+ * browser tooltip over one is the thing it replaces. It is still what tells a
16
+ * HOST with room that this value is worth `wrap: "full"` — the reading is the
17
+ * host's, made where the surface is known, and never made here.
18
+ */
19
+ export declare function renderText(field: FieldDefOf<"text">, value: unknown, opts?: DisplayOptions): ReactNode;
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { cellTextClass } from "./text-class.js";
4
+ export function renderText(field, value, opts) {
5
+ const shown = String(value);
6
+ const title = field.format?.long ? undefined : shown;
7
+ return (_jsx("span", { className: cellTextClass(opts?.wrap), title: title, children: shown }));
8
+ }
@@ -0,0 +1,2 @@
1
+ import type { DisplayOptions } from "./options.js";
2
+ export declare function useDisplayOptions(opts: DisplayOptions | undefined): DisplayOptions;
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ import { useMemo } from "react";
3
+ import { useViews } from "../provider/context.js";
4
+ import { DEFAULT_FIELD_PRESENTATION } from "./format.js";
5
+ import { viewerFrom } from "./viewer.js";
6
+ export function useDisplayOptions(opts) {
7
+ const { conventions, messages, presentation } = useViews();
8
+ const appPresentation = useMemo(() => presentation?.(DEFAULT_FIELD_PRESENTATION), [presentation]);
9
+ return {
10
+ ...opts,
11
+ presentation: opts?.presentation ?? appPresentation,
12
+ viewer: opts?.viewer ?? viewerFrom(conventions, messages),
13
+ };
14
+ }
@@ -0,0 +1,11 @@
1
+ import type { ReactNode } from "react";
2
+ import type { FieldDefOf } from "@viewkitjs/fields";
3
+ import type { DisplayOptions } from "./options.js";
4
+ /**
5
+ * A workspace member — a pointer at a user row, so it IS the relation chip.
6
+ *
7
+ * The relation core draws `{ id, label, avatarUrl }` and resolves the `user`
8
+ * glyph through `opts.entityIcon`; this core exists so a `user` field needs no
9
+ * `relation` block of its own and the two can never draw a member differently.
10
+ */
11
+ export declare function renderUser(field: FieldDefOf<"user">, value: unknown, opts?: DisplayOptions): ReactNode;
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import { renderRelation } from "./relation.js";
3
+ export function renderUser(field, value, opts) {
4
+ const asRelation = {
5
+ ...field,
6
+ type: "relation",
7
+ relation: { kind: "user" },
8
+ };
9
+ return renderRelation(asRelation, value, opts);
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { ReactNode } from "react";
2
+ import type { DisplayOptions } from "./options.js";
3
+ /**
4
+ * Several values of one kind (VK-58's `{ value, label, main }`, or a plain list read as items, the first main):
5
+ * the main one first and the rest in stored order, each drawn by its type's own renderer for one value. The cell
6
+ * shows the main one and a count; each value's label is drawn beside it behind the count, never in the cell.
7
+ */
8
+ export declare function renderValueList(value: unknown[], one: (value: unknown) => ReactNode, opts?: DisplayOptions,
9
+ /** One value as plain text, for the native hover. */
10
+ text?: (value: unknown) => string): ReactNode;
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { valueItems } from "@viewkitjs/fields";
4
+ import { MultiValueCell } from "./multi-value.js";
5
+ export function renderValueList(value, one, opts, text = String) {
6
+ const items = valueItems(value);
7
+ const main = items.find((item) => item.main);
8
+ if (!main)
9
+ return null;
10
+ const ordered = [main, ...items.filter((item) => item !== main)];
11
+ return (_jsx(MultiValueCell, { items: ordered.map((item) => one(item.value)), details: ordered.map((item) => item.label), wrap: !!opts?.wrap, title: ordered.map((item) => text(item.value)).join(", "), slotOwnsClick: opts?.slotOwnsClick }));
12
+ }
@@ -0,0 +1,4 @@
1
+ import type { FieldConventions } from "@viewkitjs/fields";
2
+ import { type ViewsMessageResolver } from "../contract.js";
3
+ import type { FieldViewerContext } from "./options.js";
4
+ export declare function viewerFrom(conventions: FieldConventions, messages?: ViewsMessageResolver, now?: Date): FieldViewerContext;
@@ -0,0 +1,11 @@
1
+ import { resolveViewsMessage } from "../contract.js";
2
+ export function viewerFrom(conventions, messages = resolveViewsMessage, now = new Date()) {
3
+ return {
4
+ locale: conventions.locale,
5
+ timeZone: conventions.timeZone,
6
+ ...(conventions.region ? { region: conventions.region } : {}),
7
+ now,
8
+ fieldMessages: conventions.messages,
9
+ messages,
10
+ };
11
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Where a web address goes (POR-1310): the stored text, trimmed, when its scheme
3
+ * is http, https or ftp; `https://` before a host stored bare, so it opens the
4
+ * site, never a path on the app; null for any other scheme (`javascript:`,
5
+ * `data:`), which is no link. Plain, so a server module reaches it through the
6
+ * display door as it reaches the formatters.
7
+ */
8
+ export declare function webHref(value: string): string | null;
@@ -0,0 +1,12 @@
1
+ export function webHref(value) {
2
+ const text = value.trim();
3
+ if (!text)
4
+ return null;
5
+ if (/^(https?|ftp):\/\//i.test(text))
6
+ return text;
7
+ if (text.startsWith("//"))
8
+ return `https:${text}`;
9
+ if (/^[a-z][a-z\d+.-]*:/i.test(text))
10
+ return null;
11
+ return `https://${text}`;
12
+ }
@@ -0,0 +1,59 @@
1
+ import { type CloseReason, type CloseResolution, type FieldMessageResolver } from "@viewkitjs/fields";
2
+ import type { PickerOption } from "./SelectEditor.js";
3
+ /**
4
+ * THE editor for a value that is SEVERAL values.
5
+ *
6
+ * ## The field holds the values — that is the whole point
7
+ *
8
+ * A multi-value cell is not a select that happens to allow two answers. What
9
+ * you are editing is a SET, so the set has to be on screen while you edit it:
10
+ * the panel's top zone is a FIELD carrying the chosen values as the very badges
11
+ * the cell draws, each with its own remove control, and the text input sits
12
+ * inline among them. You add and remove in the same place you can see them.
13
+ *
14
+ * A tick in a list is what this must NOT be. A tick reports the state of the
15
+ * row you are looking at; it does not show you the set you have built, and on a
16
+ * panel that covers its own cell that leaves you editing blind.
17
+ *
18
+ * ## It is a draft
19
+ *
20
+ * Adds and removes accumulate here and the whole array commits ONCE, when the
21
+ * host closes the panel. Five tags are one PATCH, one history entry and one
22
+ * toast, where a per-value commit would be five of each and ⌘Z would walk back
23
+ * through them. That is also why a pick does NOT close this core — it is the
24
+ * one that never sees the `pick` reason.
25
+ *
26
+ * ## Its close rule is the odd one out
27
+ *
28
+ * An outside click COMMITS (you built a set; leaving keeps it) and Escape
29
+ * DISCARDS. Every other core cancels on both. Closing unchanged is a noop —
30
+ * the dirty check is `sameListValue`, the same one the commit path uses, so
31
+ * opening a cell to look at it never writes to it.
32
+ */
33
+ export type ChipsEditorHandle = {
34
+ /** What this close means. Synchronous, idempotent, no timer. */
35
+ resolveClose: (reason: CloseReason) => CloseResolution<string[]>;
36
+ };
37
+ export declare const ChipsEditor: import("react").ForwardRefExoticComponent<{
38
+ /** The values the cell currently holds. */
39
+ values: string[];
40
+ /** What this column already contains — the same list the Filter panel
41
+ * offers, so a value you can set is one you can then filter for. */
42
+ suggestions: string[];
43
+ /**
44
+ * One value's label and colour, resolved by the HOST.
45
+ *
46
+ * A resolver rather than a ready `PickerOption[]`, because a chips panel
47
+ * must dress values that are not in the vocabulary yet — someone has just
48
+ * typed one — and a fixed array cannot answer for those.
49
+ */
50
+ resolve: (value: string) => PickerOption;
51
+ /** A column whose values are not free-form states its rule here, and every
52
+ * added value goes through it on the way in — the same function the route
53
+ * applies, so `Ops Team` and `ops-team` cannot come apart. */
54
+ normalize?: (raw: string) => string;
55
+ /** The core saw a key that means "done" (Escape). Picks never close it. */
56
+ onRequestClose: (reason: CloseReason) => void;
57
+ /** The host's words for this panel (fields' messages); default: the provider's conventions. */
58
+ message?: FieldMessageResolver;
59
+ } & import("react").RefAttributes<ChipsEditorHandle>>;
@@ -0,0 +1,73 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, } from "react";
4
+ import { sameListValue, } from "@viewkitjs/fields";
5
+ import { useViews } from "../provider/context.js";
6
+ export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions, resolve, normalize, onRequestClose, message }, ref) {
7
+ const [draft, setDraft] = useState(values);
8
+ const [search, setSearch] = useState("");
9
+ const inputRef = useRef(null);
10
+ const draftRef = useRef(values);
11
+ const views = useViews();
12
+ const words = message ?? views.conventions.messages;
13
+ const { Command } = views.components;
14
+ const { List, RowContent, Tag } = views.atoms;
15
+ const Add = views.icons.add;
16
+ const resolveClose = (reason) => {
17
+ if (reason === "escape")
18
+ return { kind: "cancel" };
19
+ const next = draftRef.current;
20
+ if (sameListValue(next, values))
21
+ return { kind: "noop" };
22
+ return { kind: "commit", payload: next };
23
+ };
24
+ useImperativeHandle(ref, () => ({ resolveClose }));
25
+ const setBoth = (next) => {
26
+ draftRef.current = next;
27
+ setDraft(next);
28
+ };
29
+ useEffect(() => {
30
+ inputRef.current?.focus();
31
+ }, []);
32
+ const clean = (raw) => (normalize ? normalize(raw) : raw.trim());
33
+ const rows = useMemo(() => suggestions.filter((value) => !draft.includes(value)), [suggestions, draft]);
34
+ const query = search.trim().toLowerCase();
35
+ const visible = query
36
+ ? rows.filter((value) => resolve(value).label.toLowerCase().includes(query))
37
+ : rows;
38
+ const typed = clean(search);
39
+ const needle = typed.toLowerCase();
40
+ const canAdd = typed !== "" && ![...draft, ...rows].some((value) => value.toLowerCase() === needle);
41
+ const add = (value) => {
42
+ if (!draftRef.current.includes(value))
43
+ setBoth([...draftRef.current, value]);
44
+ setSearch("");
45
+ inputRef.current?.focus();
46
+ };
47
+ const remove = (value) => {
48
+ setBoth(draftRef.current.filter((entry) => entry !== value));
49
+ inputRef.current?.focus();
50
+ };
51
+ const onFieldKeyDown = (event) => {
52
+ if (event.key === "Backspace" && search === "" && draft.length > 0) {
53
+ event.preventDefault();
54
+ remove(draft[draft.length - 1]);
55
+ }
56
+ };
57
+ 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
+ if (event.target === event.currentTarget) {
59
+ event.preventDefault();
60
+ inputRef.current?.focus();
61
+ }
62
+ }, children: [draft.map((value) => {
63
+ const option = resolve(value);
64
+ return (_jsx(Tag, { label: option.label, color: option.color ?? "gray", onRemove: () => remove(value) }, value));
65
+ }), _jsx(Command.Input, { chrome: "bare", ref: inputRef, value: search, onValueChange: setSearch, onKeyDown: (event) => {
66
+ onFieldKeyDown(event);
67
+ if (event.key === "Escape")
68
+ onRequestClose("escape");
69
+ }, placeholder: draft.length === 0 ? words({ key: "chips.add-placeholder" }) : "", className: "h-5 min-w-20 flex-1 bg-transparent text-[13px] outline-hidden placeholder:text-(color:--vk-fg-subtlest)" })] }), _jsxs(Command.List, { className: "max-h-64 overscroll-contain scrollbar-overlay", children: [visible.length === 0 && !canAdd && (_jsx(Command.Empty, { className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: rows.length === 0 ? words({ key: "chips.everything-picked" }) : words({ key: "editor.nothing-matches" }) })), _jsx(Command.Group, { className: "p-0", children: _jsxs(List, { children: [visible.map((value) => {
70
+ const option = resolve(value);
71
+ return (_jsx(Command.Item, { value: value, onSelect: () => add(value), children: _jsx(RowContent, { size: "compact", label: _jsx(Tag, { label: option.label, color: option.color ?? "gray" }) }) }, value));
72
+ }), canAdd && (_jsx(Command.Item, { value: `__add__${typed}`, onSelect: () => add(typed), children: _jsx(RowContent, { size: "compact", tone: "muted", leading: _jsx(Add, { className: "h-4 w-4 shrink-0 text-(color:--vk-fg-subtle)" }), label: words({ key: "chips.add", values: { value: typed } }) }) }))] }) })] })] }));
73
+ });
@@ -0,0 +1,25 @@
1
+ import { type CloseReason, type CloseResolution, type FieldMessageResolver } from "@viewkitjs/fields";
2
+ export type DateEditorHandle = {
3
+ /**
4
+ * THE close handshake (lib/fields/close): the host learned that a close
5
+ * happened and asks what it means. For a date every reason is the same —
6
+ * commit the draft when dirty, else nothing — so the reason is taken and
7
+ * not read; it is the host's to distinguish. Pure and idempotent: no state
8
+ * moves, no timer runs, nothing is called back. The host closes its
9
+ * popover, waits its own exit gap, and then applies the answer.
10
+ */
11
+ resolveClose: (reason: CloseReason) => CloseResolution<string>;
12
+ };
13
+ export declare const DateEditor: import("react").ForwardRefExoticComponent<{
14
+ /** The stored value — full ISO or "YYYY-MM-DD"; selects day + opening month. */
15
+ initial?: string;
16
+ /** Time chip starts empty and stays out of the commit until set (form
17
+ * mode). Without it, the chip carries the stored time or 00:00 and every
18
+ * commit includes one (the grid's original behavior). */
19
+ timeOptional?: boolean;
20
+ /** The panel saw a key that means "done" (Enter) or "leave" (Escape). It
21
+ * never closes itself — the host closes, then asks `resolveClose`. */
22
+ onRequestClose: (reason: CloseReason) => void;
23
+ /** The host's words for this panel (fields' messages); default: the provider's conventions. */
24
+ message?: FieldMessageResolver;
25
+ } & import("react").RefAttributes<DateEditorHandle>>;
@@ -0,0 +1,122 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
4
+ import { formatChipDate, normalizeTime, parseDateText, toYmd, } from "@viewkitjs/fields";
5
+ import { fromDayKey, toDayKey } from "@viewkitjs/fields/query";
6
+ import { cx } from "../internal/cx.js";
7
+ import { useViews } from "../provider/context.js";
8
+ const CALENDAR_START = "1900-01";
9
+ const CALENDAR_END = `${new Date().getFullYear() + 10}-12`;
10
+ const TIME_OPTIONS = Array.from({ length: 96 }, (_, i) => {
11
+ const hh = String(Math.floor(i / 4)).padStart(2, "0");
12
+ const mm = String((i % 4) * 15).padStart(2, "0");
13
+ return `${hh}:${mm}`;
14
+ });
15
+ function initialHasTime(iso, parsed) {
16
+ if (!iso || !parsed)
17
+ return false;
18
+ return /T/.test(iso);
19
+ }
20
+ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional = false, onRequestClose, message }, ref) {
21
+ const timeRef = useRef(null);
22
+ const views = useViews();
23
+ const words = message ?? views.conventions.messages;
24
+ const { Calendar } = views.components;
25
+ const DateGlyph = views.icons.date;
26
+ const TimeGlyph = views.icons.time;
27
+ const [timeOpen, setTimeOpen] = useState(false);
28
+ const activeTimeRef = useRef(null);
29
+ const parsed = initial ? new Date(initial) : undefined;
30
+ const valid = parsed && !Number.isNaN(parsed.getTime()) ? parsed : undefined;
31
+ const [day, setDay] = useState(valid);
32
+ const [month, setMonth] = useState(valid);
33
+ const hadTime = initialHasTime(initial, valid);
34
+ const initialTime = valid && (!timeOptional || hadTime)
35
+ ? `${String(valid.getHours()).padStart(2, "0")}:${String(valid.getMinutes()).padStart(2, "0")}`
36
+ : timeOptional
37
+ ? ""
38
+ : "00:00";
39
+ const [timeVal, setTimeVal] = useState(initialTime);
40
+ const [dateVal, setDateVal] = useState(() => formatChipDate(valid ?? new Date()));
41
+ const touchedRef = useRef(false);
42
+ const applyDateText = () => {
43
+ const base = day ?? valid ?? new Date();
44
+ const typed = parseDateText(dateVal, base.getFullYear());
45
+ if (typed) {
46
+ setDay(typed);
47
+ setMonth(typed);
48
+ setDateVal(formatChipDate(typed));
49
+ return typed;
50
+ }
51
+ setDateVal(formatChipDate(base));
52
+ return undefined;
53
+ };
54
+ const resolveClose = () => {
55
+ const typed = parseDateText(dateVal, (day ?? valid ?? new Date()).getFullYear());
56
+ const d = typed ?? day ?? valid;
57
+ const time = normalizeTime(timeVal) ?? (timeOptional ? null : initialTime);
58
+ const timePart = timeOptional ? time : (time ?? initialTime);
59
+ const dirty = d != null &&
60
+ (valid ? toYmd(d) !== toYmd(valid) || (timePart ?? "") !== initialTime : touchedRef.current);
61
+ if (!dirty || !d)
62
+ return { kind: "noop" };
63
+ return { kind: "commit", payload: timePart ? `${toYmd(d)}T${timePart}` : toYmd(d) };
64
+ };
65
+ useImperativeHandle(ref, () => ({ resolveClose }));
66
+ const nearest = normalizeTime(timeVal) ?? (initialTime || "00:00");
67
+ const [nh, nm] = nearest.split(":").map(Number);
68
+ const nearestTime = TIME_OPTIONS[Math.min(95, Math.round((nh * 60 + nm) / 15))];
69
+ useEffect(() => {
70
+ if (timeOpen)
71
+ activeTimeRef.current?.scrollIntoView({ block: "center" });
72
+ }, [timeOpen]);
73
+ return (_jsxs(_Fragment, { 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", { type: "text", value: dateVal, onChange: (e) => {
74
+ touchedRef.current = true;
75
+ setDateVal(e.target.value);
76
+ }, onBlur: applyDateText, onFocus: () => setTimeOpen(false), placeholder: words({ key: "date.placeholder" }), "aria-label": words({ key: "date.label" }), onClick: (e) => e.stopPropagation(), onKeyDown: (e) => {
77
+ e.stopPropagation();
78
+ if (e.key === "Enter") {
79
+ e.preventDefault();
80
+ onRequestClose("enter");
81
+ }
82
+ else if (e.key === "Escape") {
83
+ onRequestClose("escape");
84
+ }
85
+ }, className: "w-0 min-w-0 flex-1 select-text bg-transparent text-sm tabular-nums text-(color:--vk-fg) outline-hidden placeholder:text-(color:--vk-fg-subtlest)" })] }), _jsxs("div", { className: "relative shrink-0", children: [_jsxs("div", { className: "flex h-8 cursor-text items-center gap-2 rounded-lg bg-(color:--vk-neutral) px-2.5 focus-within:bg-(color:--vk-neutral-hovered)", onClick: (e) => {
86
+ e.stopPropagation();
87
+ setTimeOpen(true);
88
+ timeRef.current?.focus();
89
+ }, children: [_jsx(TimeGlyph, { className: "h-3.5 w-3.5 text-(color:--vk-fg-subtlest)" }), _jsx("input", { ref: timeRef, type: "text", inputMode: "numeric", value: timeVal, onChange: (e) => {
90
+ touchedRef.current = true;
91
+ setTimeVal(e.target.value);
92
+ }, onFocus: () => setTimeOpen(true), placeholder: words({ key: "time.placeholder" }), "aria-label": words({ key: "time.label" }), onKeyDown: (e) => {
93
+ e.stopPropagation();
94
+ if (e.key === "Enter") {
95
+ e.preventDefault();
96
+ onRequestClose("enter");
97
+ }
98
+ else if (e.key === "Escape") {
99
+ if (timeOpen)
100
+ setTimeOpen(false);
101
+ else
102
+ onRequestClose("escape");
103
+ }
104
+ }, className: "w-12 select-text bg-transparent text-sm tabular-nums text-(color:--vk-fg) outline-hidden placeholder:text-(color:--vk-fg-subtlest)" })] }), timeOpen && (_jsx("div", { className: "absolute right-0 top-full z-10 mt-1 max-h-56 w-24 overflow-y-auto overscroll-contain rounded-lg border border-(color:--vk-border) bg-(color:--vk-overlay) py-1 shadow-lg", children: TIME_OPTIONS.map((t) => {
105
+ const active = t === nearestTime;
106
+ return (_jsx("button", { ref: active ? activeTimeRef : undefined, type: "button", onClick: (e) => {
107
+ e.stopPropagation();
108
+ touchedRef.current = true;
109
+ setTimeVal(t);
110
+ setTimeOpen(false);
111
+ timeRef.current?.focus();
112
+ }, 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));
113
+ }) }))] })] }), _jsx(Calendar, { locale: views.conventions.locale, value: (day ?? valid) ? toDayKey((day ?? valid)) : null, onChange: (picked) => {
114
+ const d = picked ? fromDayKey(picked) : null;
115
+ if (!d)
116
+ return;
117
+ touchedRef.current = true;
118
+ setDay(d);
119
+ setDateVal(formatChipDate(d));
120
+ setTimeOpen(false);
121
+ }, month: month ? toDayKey(month).slice(0, 7) : undefined, onMonthChange: (next) => setMonth(fromDayKey(`${next}-01`) ?? undefined), captionLayout: "dropdown", startMonth: CALENDAR_START, endMonth: CALENDAR_END })] }));
122
+ });
@@ -0,0 +1,22 @@
1
+ import { type CloseReason, type CloseResolution, type FieldConventions, type FieldDefOf, type LocationValue } from "@viewkitjs/fields";
2
+ /**
3
+ * A PLACE — the country first, then that country's own parts. A field that takes the country opens on the
4
+ * country list when its place has none; once one is picked, the editor shows the country's parts in its own
5
+ * order with its own words (Romania's postal code, county and city on one line; Hungary's city first; County,
6
+ * State, ZIP code), the parts the country asks for marked, never refused. Where the country has a region
7
+ * list, the region is picked from it, which stores the region's name and its ISO 3166-2 code; the list loads
8
+ * when the editor lands on that country. A field limited to some parts edits only those, and never loses a
9
+ * part it names that the country's format has no place for (Japan's has no city); those come after, in the
10
+ * generic order, as does a part a stored place holds that its country's format has no place for.
11
+ * Picking another country clears the region and its code. An editor closed untouched writes nothing.
12
+ */
13
+ export type LocationEditorHandle = {
14
+ resolveClose: (reason: CloseReason) => CloseResolution<LocationValue | null>;
15
+ };
16
+ export declare const LocationEditor: import("react").ForwardRefExoticComponent<{
17
+ field: FieldDefOf<"location">;
18
+ initial: LocationValue | null;
19
+ allowEmpty?: boolean;
20
+ conventions?: FieldConventions;
21
+ onRequestClose: (reason: CloseReason) => void;
22
+ } & import("react").RefAttributes<LocationEditorHandle>>;