@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,229 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, } from "react";
4
+ import { COUNTRY_CODES, countryName, LOCATION_PARTS, placeFormat, sameStoredValue, } from "@viewkitjs/fields";
5
+ import { loadRegions, regionLabel } from "@viewkitjs/fields/places";
6
+ import { placeWordKey } from "../contract.js";
7
+ import { useViews } from "../provider/context.js";
8
+ const GENERIC = ["line1", "line2", "postalCode", "city", "region"];
9
+ function folded(text) {
10
+ return text.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
11
+ }
12
+ function draftOf(initial) {
13
+ const draft = {};
14
+ for (const part of LOCATION_PARTS) {
15
+ const value = initial?.[part];
16
+ if (typeof value === "string")
17
+ draft[part] = value;
18
+ }
19
+ return draft;
20
+ }
21
+ export const LocationEditor = forwardRef(function LocationEditor({ field, initial, allowEmpty = false, conventions, onRequestClose }, ref) {
22
+ const views = useViews();
23
+ const locale = (conventions ?? views.conventions).locale;
24
+ const say = (message) => views.messages(message);
25
+ const { List, RowContent } = views.atoms;
26
+ const { Command } = views.components;
27
+ const boxRef = useRef(null);
28
+ const parts = field.parts ?? LOCATION_PARTS;
29
+ const takesCountry = parts.includes("countryCode");
30
+ const [draft, setDraftState] = useState(() => draftOf(initial));
31
+ const draftRef = useRef(draft);
32
+ const setDraft = (next) => {
33
+ draftRef.current = next;
34
+ setDraftState(next);
35
+ };
36
+ const country = draft.countryCode?.trim() || null;
37
+ const [choosingCountry, setChoosingCountry] = useState(takesCountry && !country);
38
+ const [countryQuery, setCountryQuery] = useState("");
39
+ const [choosingRegion, setChoosingRegion] = useState(false);
40
+ const [regionQuery, setRegionQuery] = useState("");
41
+ const [regions, setRegions] = useState(null);
42
+ const format = placeFormat(country, locale);
43
+ const editsRegion = parts.includes("region");
44
+ const wantsRegions = !choosingCountry && editsRegion && format.hasRegions && country !== null;
45
+ useEffect(() => {
46
+ if (!wantsRegions || !country)
47
+ return;
48
+ let live = true;
49
+ loadRegions(country).then((list) => live && setRegions({ country, list }), () => live && setRegions(null));
50
+ return () => {
51
+ live = false;
52
+ };
53
+ }, [wantsRegions, country]);
54
+ const regionList = regions && regions.country === country && regions.list.length > 0 ? regions.list : null;
55
+ const keptShown = useRef(new Set());
56
+ const lastFocused = useRef(null);
57
+ const rows = useMemo(() => {
58
+ const laidOut = new Set();
59
+ const lines = format.lines
60
+ .map((line) => line
61
+ .map((item) => item.part)
62
+ .filter((part) => {
63
+ laidOut.add(part);
64
+ return parts.includes(part);
65
+ }))
66
+ .filter((line) => line.length > 0);
67
+ const shown = (part) => {
68
+ if (field.parts)
69
+ return parts.includes(part);
70
+ if (draft[part]?.trim())
71
+ keptShown.current.add(part);
72
+ return keptShown.current.has(part);
73
+ };
74
+ for (const part of GENERIC)
75
+ if (!laidOut.has(part) && shown(part))
76
+ lines.push([part]);
77
+ return lines;
78
+ }, [format, parts, field.parts, draft]);
79
+ const countries = useMemo(() => COUNTRY_CODES.map((code) => ({ code, name: countryName(code, locale) })).sort((a, b) => a.name.localeCompare(b.name, locale)), [locale]);
80
+ const resolveClose = (reason) => {
81
+ if (reason === "escape")
82
+ return { kind: "cancel" };
83
+ const current = draftRef.current;
84
+ const next = {};
85
+ for (const part of parts) {
86
+ const value = current[part]?.trim() ?? "";
87
+ next[part] = value === "" ? null : value;
88
+ }
89
+ const place = next;
90
+ if (sameStoredValue(field, place, initial))
91
+ return { kind: "noop" };
92
+ if (Object.values(next).every((value) => value === null)) {
93
+ return allowEmpty ? { kind: "commit", payload: null } : { kind: "cancel" };
94
+ }
95
+ return { kind: "commit", payload: place };
96
+ };
97
+ useImperativeHandle(ref, () => ({ resolveClose }));
98
+ useEffect(() => {
99
+ const box = boxRef.current;
100
+ if (!box || box.contains(document.activeElement))
101
+ return;
102
+ const last = lastFocused.current
103
+ ? box.querySelector(`[data-place-part="${lastFocused.current}"]`)
104
+ : null;
105
+ (last ?? box.querySelector("[data-place-focus]"))?.focus();
106
+ }, [choosingCountry, choosingRegion, regionList]);
107
+ const pickCountry = (code) => {
108
+ const current = draftRef.current;
109
+ const next = { ...current, countryCode: code };
110
+ if (current.countryCode !== code) {
111
+ if (parts.includes("region"))
112
+ next.region = null;
113
+ if (parts.includes("regionCode"))
114
+ next.regionCode = null;
115
+ }
116
+ setDraft(next);
117
+ setCountryQuery("");
118
+ setChoosingCountry(false);
119
+ };
120
+ const pickRegion = (region) => {
121
+ const next = { ...draftRef.current, region: regionLabel(region, country ?? "", locale) };
122
+ if (parts.includes("regionCode"))
123
+ next.regionCode = region.code;
124
+ setDraft(next);
125
+ setRegionQuery("");
126
+ setChoosingRegion(false);
127
+ };
128
+ const type = (part, value) => {
129
+ const next = { ...draftRef.current, [part]: value };
130
+ if (part === "region" && parts.includes("regionCode"))
131
+ next.regionCode = null;
132
+ setDraft(next);
133
+ };
134
+ const keys = (e) => {
135
+ e.stopPropagation();
136
+ if (e.key === "Escape") {
137
+ onRequestClose("escape");
138
+ }
139
+ else if (e.key === "Enter" && e.target instanceof HTMLInputElement) {
140
+ e.preventDefault();
141
+ onRequestClose("enter");
142
+ }
143
+ else if (e.key === "Tab") {
144
+ e.preventDefault();
145
+ const controls = [
146
+ ...(boxRef.current?.querySelectorAll("[data-place-control]") ?? []),
147
+ ];
148
+ const to = controls[controls.indexOf(e.target) + (e.shiftKey ? -1 : 1)];
149
+ if (to)
150
+ to.focus();
151
+ else
152
+ onRequestClose(e.shiftKey ? "shift-tab" : "tab");
153
+ }
154
+ };
155
+ const blur = (e) => {
156
+ if (!boxRef.current?.contains(e.relatedTarget))
157
+ onRequestClose("blur");
158
+ };
159
+ const wordOf = (part) => {
160
+ if (part === "line1")
161
+ return say({ key: "views.editors.place-line1" });
162
+ if (part === "line2")
163
+ return say({ key: "views.editors.place-line2" });
164
+ if (part === "city")
165
+ return say({ key: placeWordKey("city", format.words.city) });
166
+ if (part === "region")
167
+ return say({ key: placeWordKey("region", format.words.region) });
168
+ return say({ key: placeWordKey("postal", format.words.postalCode) });
169
+ };
170
+ const labelOf = (part) => {
171
+ const word = wordOf(part);
172
+ return format.required.includes(part)
173
+ ? say({ key: "views.editors.place-required", values: { label: word } })
174
+ : word;
175
+ };
176
+ const required = (part, control) => format.required.includes(part)
177
+ ? control === "input"
178
+ ? { "aria-required": true, "data-required": "" }
179
+ : { "data-required": "" }
180
+ : {};
181
+ const input = "h-7 w-24 min-w-0 flex-1 select-text bg-transparent text-(length:--grid-text) text-(color:--vk-fg) outline-hidden";
182
+ const button = `${input} cursor-pointer truncate text-left`;
183
+ const search = (value, onChange, placeholder) => (_jsx(Command.Input, { value: value, onValueChange: onChange, placeholder: placeholder, autoFocus: true, className: "h-9 text-[13px]", onKeyDown: (e) => {
184
+ if (e.key === "Escape") {
185
+ e.stopPropagation();
186
+ if (choosingRegion)
187
+ setChoosingRegion(false);
188
+ else if (country)
189
+ setChoosingCountry(false);
190
+ else
191
+ onRequestClose("escape");
192
+ }
193
+ else if (e.key === "Tab") {
194
+ e.preventDefault();
195
+ e.stopPropagation();
196
+ onRequestClose(e.shiftKey ? "shift-tab" : "tab");
197
+ }
198
+ } }));
199
+ const list = (children) => (_jsxs(Command.List, { className: "max-h-64 overscroll-contain scrollbar-overlay", children: [children.length === 0 && (_jsx(Command.Empty, { className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: (conventions ?? views.conventions).messages({ key: "editor.nothing-matches" }) })), _jsx(Command.Group, { className: "p-0", children: _jsx(List, { children: children }) })] }));
200
+ let body;
201
+ if (choosingCountry) {
202
+ const needle = folded(countryQuery.trim());
203
+ const shown = countries.filter(({ code, name }) => needle === "" || folded(name).includes(needle) || code.toLowerCase() === needle);
204
+ body = (_jsxs(Command.Root, { shouldFilter: false, loop: true, label: say({ key: "views.editors.place-country" }), children: [search(countryQuery, setCountryQuery, say({ key: "views.editors.place-country-search" })), list(shown.map(({ code, name }) => (_jsx(Command.Item, { value: code, onSelect: () => pickCountry(code), chosen: code === country, children: _jsx(RowContent, { size: "compact", label: name, chosen: code === country, chosenTint: false }) }, code))))] }));
205
+ }
206
+ else if (choosingRegion && regionList) {
207
+ const needle = folded(regionQuery.trim());
208
+ const labelled = regionList.map((region) => ({
209
+ region,
210
+ label: regionLabel(region, country ?? "", locale),
211
+ }));
212
+ const shown = labelled.filter(({ label }) => needle === "" || folded(label).includes(needle));
213
+ body = (_jsxs(Command.Root, { shouldFilter: false, loop: true, label: wordOf("region"), children: [search(regionQuery, setRegionQuery, say({ key: "views.editors.place-region-search" })), list(shown.map(({ region, label }) => (_jsx(Command.Item, { value: region.code ?? region.name, onSelect: () => pickRegion(region), chosen: label === draft.region, children: _jsx(RowContent, { size: "compact", label: label, chosen: label === draft.region, chosenTint: false }) }, region.code ?? region.name))))] }));
214
+ }
215
+ else {
216
+ let focusSet = false;
217
+ const focus = () => {
218
+ if (focusSet)
219
+ return {};
220
+ focusSet = true;
221
+ return { "data-place-focus": "" };
222
+ };
223
+ body = (_jsxs(_Fragment, { children: [takesCountry && country && (_jsx("button", { type: "button", "data-place-control": "", "aria-label": `${say({ key: "views.editors.place-change-country" })}: ${countryName(country, locale)}`, onClick: () => setChoosingCountry(true), onKeyDown: keys, className: `${button} font-medium`, children: countryName(country, locale) })), rows.map((row) => (_jsx("span", { className: "flex min-w-0 items-center gap-1.5", children: row.map((part) => part === "region" && regionList ? (_jsx("button", { type: "button", "data-place-control": "", ...focus(), ...required(part, "button"), "data-place-part": part, "aria-label": draft.region ? `${labelOf(part)}: ${draft.region}` : labelOf(part), onFocus: () => (lastFocused.current = part), onClick: () => setChoosingRegion(true), onKeyDown: keys, className: `${button} ${draft.region ? "" : "text-(color:--vk-fg-subtle)"}`, children: draft.region || labelOf(part) }, part)) : (_jsx("input", { "data-place-control": "", ...focus(), ...required(part, "input"), "data-place-part": part, onFocus: () => (lastFocused.current = part), value: draft[part] ?? "", "aria-label": labelOf(part), placeholder: labelOf(part), onChange: (e) => type(part, e.target.value), onKeyDown: keys, onClick: (e) => e.stopPropagation(), className: input }, part))) }, row.join(" "))))] }));
224
+ }
225
+ return (_jsx("div", { ref: boxRef, onBlur: blur, onMouseDown: (e) => {
226
+ if (!(e.target instanceof HTMLInputElement))
227
+ e.preventDefault();
228
+ }, className: "flex w-full min-w-0 flex-col gap-1.5", children: body }));
229
+ });
@@ -0,0 +1,22 @@
1
+ import { type CloseReason, type CloseResolution, type FieldConventions, type NameValue } from "@viewkitjs/fields";
2
+ /**
3
+ * A NAME — three text boxes, given, family and full. Once a part is edited, the
4
+ * full box follows the parts ("given family") while nobody has typed in it, and
5
+ * stops once a person does: the library never builds a full name behind them,
6
+ * and an editor opened and closed untouched writes nothing, so Nagy Imre stays
7
+ * written family first. A full name already stored that the parts would not
8
+ * give is the person's own, and is left as it is. Tab walks the three boxes; a
9
+ * blur that lands on another box is not a close. Three empty boxes are a
10
+ * clear, committed only when the host allows one.
11
+ */
12
+ export type NameEditorHandle = {
13
+ resolveClose: (reason: CloseReason) => CloseResolution<NameValue | null>;
14
+ };
15
+ export declare const NameEditor: import("react").ForwardRefExoticComponent<{
16
+ initial: NameValue | null;
17
+ /** Type-to-replace: the character that opened the editor replaces the given box. */
18
+ seed?: string;
19
+ allowEmpty?: boolean;
20
+ conventions?: FieldConventions;
21
+ onRequestClose: (reason: CloseReason) => void;
22
+ } & import("react").RefAttributes<NameEditorHandle>>;
@@ -0,0 +1,91 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from "react";
4
+ import { isEmptyName, sameName, tidyName, } from "@viewkitjs/fields";
5
+ import { useViews } from "../provider/context.js";
6
+ const ORDER = ["given", "family", "full"];
7
+ const LABELS = {
8
+ given: "views.editors.name-given",
9
+ family: "views.editors.name-family",
10
+ full: "views.editors.name-full",
11
+ };
12
+ function fromParts(given, family) {
13
+ return [given.trim(), family.trim()].filter(Boolean).join(" ");
14
+ }
15
+ export const NameEditor = forwardRef(function NameEditor({ initial, seed, allowEmpty = false, onRequestClose }, ref) {
16
+ const views = useViews();
17
+ const boxRef = useRef(null);
18
+ const refs = {
19
+ given: useRef(null),
20
+ family: useRef(null),
21
+ full: useRef(null),
22
+ };
23
+ const [given, setGiven] = useState(seed ?? initial?.given ?? "");
24
+ const [family, setFamily] = useState(initial?.family ?? "");
25
+ const [ownFull, setOwnFull] = useState(() => {
26
+ const stored = initial?.full?.trim() ?? "";
27
+ return stored !== "" && stored !== fromParts(initial?.given ?? "", initial?.family ?? "");
28
+ });
29
+ const [typedFull, setTypedFull] = useState(initial?.full ?? "");
30
+ const [partsEdited, setPartsEdited] = useState(seed !== undefined);
31
+ const full = ownFull || !partsEdited ? typedFull : fromParts(given, family);
32
+ useEffect(() => {
33
+ const el = refs.given.current;
34
+ if (!el)
35
+ return;
36
+ el.focus();
37
+ el.setSelectionRange(el.value.length, el.value.length);
38
+ }, []);
39
+ const resolveClose = (reason) => {
40
+ if (reason === "escape")
41
+ return { kind: "cancel" };
42
+ const next = tidyName({ full, given, family });
43
+ if (sameName(next, initial))
44
+ return { kind: "noop" };
45
+ if (isEmptyName(next))
46
+ return allowEmpty ? { kind: "commit", payload: null } : { kind: "cancel" };
47
+ return { kind: "commit", payload: next };
48
+ };
49
+ useImperativeHandle(ref, () => ({ resolveClose }));
50
+ const keys = (which) => (e) => {
51
+ e.stopPropagation();
52
+ if (e.key === "Enter") {
53
+ e.preventDefault();
54
+ onRequestClose("enter");
55
+ }
56
+ else if (e.key === "Escape") {
57
+ onRequestClose("escape");
58
+ }
59
+ else if (e.key === "Tab") {
60
+ e.preventDefault();
61
+ const at = ORDER.indexOf(which) + (e.shiftKey ? -1 : 1);
62
+ const to = ORDER[at];
63
+ if (to)
64
+ refs[to].current?.focus();
65
+ else
66
+ onRequestClose(e.shiftKey ? "shift-tab" : "tab");
67
+ }
68
+ };
69
+ const blur = (e) => {
70
+ if (!boxRef.current?.contains(e.relatedTarget))
71
+ onRequestClose("blur");
72
+ };
73
+ const input = "h-full w-28 min-w-0 flex-1 select-text bg-transparent text-(length:--grid-text) text-(color:--vk-fg) outline-hidden";
74
+ const box = (which, value, onChange) => {
75
+ const label = views.messages({ key: LABELS[which] });
76
+ return (_jsx("input", { ref: refs[which], value: value, "aria-label": label, placeholder: label, onChange: (e) => onChange(e.target.value), onKeyDown: keys(which), onBlur: blur, onClick: (e) => e.stopPropagation(), className: input }));
77
+ };
78
+ return (_jsxs("span", { ref: boxRef, onMouseDown: (e) => {
79
+ if (!(e.target instanceof HTMLInputElement))
80
+ e.preventDefault();
81
+ }, className: "flex h-full w-full min-w-0 flex-col gap-1.5", children: [_jsxs("span", { className: "flex min-w-0 items-center gap-1.5", children: [box("given", given, (next) => {
82
+ setPartsEdited(true);
83
+ setGiven(next);
84
+ }), box("family", family, (next) => {
85
+ setPartsEdited(true);
86
+ setFamily(next);
87
+ })] }), box("full", full, (next) => {
88
+ setOwnFull(true);
89
+ setTypedFull(next);
90
+ })] }));
91
+ });
@@ -0,0 +1,67 @@
1
+ import { type CloseReason, type CloseResolution, type FieldConventions, type NumberCommit } from "@viewkitjs/fields";
2
+ import { type DurationUnit } from "@viewkitjs/fields/query";
3
+ /**
4
+ * THE number-editing core — a typed field, and the unit it is denominated in.
5
+ *
6
+ * INLINE, not anchored: it replaces the cell's own content rather than opening
7
+ * a panel over it, which is why its close reasons are the keyboard's and the
8
+ * blur's — enter · tab · shift-tab · escape · blur — and never `outside`.
9
+ *
10
+ * The unit chip is the exception it carries: a money value is a number AND its
11
+ * currency, so the chip picks one, and its own popover must never blur the
12
+ * input into a commit. That is why the blur decision lives here, in the core,
13
+ * rather than with the host — only this component knows the picker is open.
14
+ *
15
+ * A DURATION is the other denomination it speaks (spec §8.4): the field is
16
+ * edited as a person writes one — `2m 30s`, `90s`, a bare number of seconds —
17
+ * and committed in the unit the field is STORED in. The host names that unit
18
+ * (`durationUnit`) and reads back a number in it; the conversion is the core's.
19
+ */
20
+ /** What a number commits: the value, and the unit it is in. The host maps that
21
+ * onto its row — for a transaction, the sign becomes `direction` and the unit
22
+ * becomes `currency`. */
23
+ export type NumberEditValue = NumberCommit;
24
+ export type NumberEditorHandle = {
25
+ /** What this close means. Synchronous, idempotent, no timer. */
26
+ resolveClose: (reason: CloseReason) => CloseResolution<NumberEditValue>;
27
+ };
28
+ export declare const NumberEditor: import("react").ForwardRefExoticComponent<{
29
+ /** Signed raw value (e.g. -47.50 for an "out" transaction in its own currency). */
30
+ initial: number;
31
+ /** Type-to-replace: the character that opened this editor. Replaces the
32
+ * field's text only — `initial` stays the numeric baseline the dirty-check
33
+ * compares against, so seeding the same value still no-ops. */
34
+ seed?: string;
35
+ /** The row's current unit (currency). Undefined = plain number, no chip. */
36
+ unit?: string;
37
+ /** Selectable units — presence makes the chip a picker. */
38
+ unitOptions?: string[];
39
+ /** Rounding + initial formatting precision — in the STORED unit. An
40
+ * integer field passes 0 (spec §8.2). */
41
+ decimals?: number;
42
+ /**
43
+ * Present when the value is a DURATION: the unit it is stored in. The
44
+ * input then opens as human text (`1m 30s`) and what is typed is read the
45
+ * way the filter box reads it — units, compounds, a bare number of seconds
46
+ * — and committed in this unit.
47
+ */
48
+ durationUnit?: DurationUnit;
49
+ /** A blank input is a real null commit. Without this it remains a cancel. */
50
+ allowEmpty?: boolean;
51
+ /** Right-aligned columns put the chip on the LEFT so the number stays flush
52
+ * with the column's right edge. */
53
+ unitLeft?: boolean;
54
+ /**
55
+ * Which edge the figure sits against. `end` is the grid's — a spreadsheet
56
+ * column is right-aligned, and the input has to open where the cell's
57
+ * number already is. A drawer row reads left to right like every row above
58
+ * and below it, so it asks for `start`: the figure stays where the display
59
+ * drew it and the unit chip follows it, instead of the number jumping to
60
+ * the far edge of the row the moment it is clicked.
61
+ */
62
+ align?: "start" | "end";
63
+ /** The host's conventions — how its people write a number. Default: the provider's. */
64
+ conventions?: FieldConventions;
65
+ /** The core saw a key (or a blur) that means "done". */
66
+ onRequestClose: (reason: CloseReason) => void;
67
+ } & import("react").RefAttributes<NumberEditorHandle>>;
@@ -0,0 +1,86 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
4
+ import { formatNumberText, parseNumber, roundTo, } from "@viewkitjs/fields";
5
+ import { durationUnitToMs, formatDurationInput, msToDurationUnit, parseDurationInput, } from "@viewkitjs/fields/query";
6
+ import { cx } from "../internal/cx.js";
7
+ import { useViews } from "../provider/context.js";
8
+ export const NumberEditor = forwardRef(function NumberEditor({ initial, seed, unit, unitOptions, decimals = 2, durationUnit, allowEmpty = false, unitLeft = false, align = "end", conventions, onRequestClose, }, ref) {
9
+ const inputRef = useRef(null);
10
+ const chipRef = useRef(null);
11
+ const [currentUnit, setCurrentUnit] = useState(unit);
12
+ const [unitOpen, setUnitOpen] = useState(false);
13
+ const views = useViews();
14
+ const cv = conventions ?? views.conventions;
15
+ const { Popover } = views.components;
16
+ const { List, Row } = views.atoms;
17
+ useEffect(() => {
18
+ const el = inputRef.current;
19
+ if (!el)
20
+ return;
21
+ el.focus();
22
+ const len = el.value.length;
23
+ el.setSelectionRange(len, len);
24
+ }, []);
25
+ const round = (n) => roundTo(n, decimals);
26
+ const parse = (raw) => {
27
+ let n;
28
+ if (durationUnit) {
29
+ const ms = parseDurationInput(raw, cv);
30
+ n = ms == null ? null : msToDurationUnit(ms, durationUnit);
31
+ }
32
+ else {
33
+ n = parseNumber(raw, cv);
34
+ }
35
+ return n == null ? null : round(n);
36
+ };
37
+ const initialText = !Number.isFinite(initial)
38
+ ? ""
39
+ : durationUnit
40
+ ? formatDurationInput(durationUnitToMs(initial, durationUnit), cv)
41
+ : formatNumberText(initial, decimals, cv);
42
+ const resolveClose = (reason) => {
43
+ if (reason === "escape")
44
+ return { kind: "cancel" };
45
+ const raw = inputRef.current?.value ?? "";
46
+ if (raw.trim() === "") {
47
+ if (!allowEmpty)
48
+ return { kind: "cancel" };
49
+ if (!Number.isFinite(initial) && currentUnit === unit)
50
+ return { kind: "noop" };
51
+ return { kind: "commit", payload: { value: null, unit: currentUnit } };
52
+ }
53
+ const parsed = parse(raw);
54
+ if (parsed == null)
55
+ return { kind: "cancel" };
56
+ if (parsed === round(initial) && currentUnit === unit)
57
+ return { kind: "noop" };
58
+ return { kind: "commit", payload: { value: parsed, unit: currentUnit } };
59
+ };
60
+ useImperativeHandle(ref, () => ({ resolveClose }));
61
+ return (_jsxs("span", { className: "flex h-full w-full min-w-0 items-center gap-1.5", children: [_jsx("input", { ref: inputRef, defaultValue: seed ?? initialText, inputMode: durationUnit ? "text" : "decimal", onKeyDown: (e) => {
62
+ e.stopPropagation();
63
+ if (e.key === "Enter") {
64
+ e.preventDefault();
65
+ onRequestClose("enter");
66
+ }
67
+ else if (e.key === "Escape") {
68
+ onRequestClose("escape");
69
+ }
70
+ else if (e.key === "Tab") {
71
+ e.preventDefault();
72
+ onRequestClose(e.shiftKey ? "shift-tab" : "tab");
73
+ }
74
+ }, onBlur: () => {
75
+ if (!unitOpen)
76
+ onRequestClose("blur");
77
+ }, onClick: (e) => e.stopPropagation(), className: cx("h-full min-w-0 select-text bg-transparent tabular-nums text-(length:--grid-text) text-(color:--vk-fg) outline-hidden", align === "start" ? "w-40 flex-none text-left" : "w-full flex-1 text-right") }), unit &&
78
+ (unitOptions && unitOptions.length > 0 ? (_jsxs(_Fragment, { children: [_jsx("button", { ref: chipRef, type: "button", tabIndex: -1, onMouseDown: (e) => e.preventDefault(), onClick: (e) => {
79
+ e.stopPropagation();
80
+ setUnitOpen((o) => !o);
81
+ }, className: cx("shrink-0 text-xs font-normal text-(color:--vk-fg-subtle) transition-colors hover:text-(color:--vk-fg)", unitLeft && "order-first"), children: currentUnit }), _jsx(Popover, { open: unitOpen, onOpenChange: (next) => setUnitOpen(next), anchor: chipRef, side: "bottom", align: unitLeft ? "start" : "end", sideOffset: 6, initialFocus: false, onOutsidePress: (event) => (chipRef.current?.contains(event.target) ? false : undefined), onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "w-24", children: _jsx(List, { children: unitOptions.map((u) => (_jsx(Row, { label: u, chosen: u === currentUnit, onMouseDown: (e) => e.preventDefault(), onClick: () => {
82
+ setCurrentUnit(u);
83
+ setUnitOpen(false);
84
+ inputRef.current?.focus();
85
+ } }, u))) }) })] })) : (_jsx("span", { className: cx("shrink-0 text-xs font-normal text-(color:--vk-fg-subtlest)", unitLeft && "order-first"), children: unit })))] }));
86
+ });
@@ -0,0 +1,22 @@
1
+ import { type CloseReason, type CloseResolution, type FieldConventions, type RangeValue } from "@viewkitjs/fields";
2
+ /**
3
+ * A RANGE — two number boxes, low and high, inline like the number core. Tab
4
+ * moves from low to high inside the editor; a blur that lands on the other box
5
+ * is not a close. An empty box is an open end; two empty boxes are a clear,
6
+ * committed only when the host allows one.
7
+ */
8
+ export type RangeEditorHandle = {
9
+ resolveClose: (reason: CloseReason) => CloseResolution<RangeValue>;
10
+ };
11
+ export declare const RangeEditor: import("react").ForwardRefExoticComponent<{
12
+ initial: RangeValue | null;
13
+ /** Type-to-replace: the character that opened the editor replaces the low box. */
14
+ seed?: string;
15
+ decimals?: number;
16
+ allowEmpty?: boolean;
17
+ /** A unit drawn after the high box: "%", a currency code. */
18
+ suffix?: string;
19
+ align?: "start" | "end";
20
+ conventions?: FieldConventions;
21
+ onRequestClose: (reason: CloseReason) => void;
22
+ } & import("react").RefAttributes<RangeEditorHandle>>;
@@ -0,0 +1,70 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { forwardRef, useEffect, useImperativeHandle, useRef, } from "react";
4
+ import { formatNumberText, parseNumber, roundTo, } from "@viewkitjs/fields";
5
+ import { cx } from "../internal/cx.js";
6
+ import { useViews } from "../provider/context.js";
7
+ export const RangeEditor = forwardRef(function RangeEditor({ initial, seed, decimals = 0, allowEmpty = false, suffix, align = "end", conventions, onRequestClose, }, ref) {
8
+ const views = useViews();
9
+ const cv = conventions ?? views.conventions;
10
+ const boxRef = useRef(null);
11
+ const lowRef = useRef(null);
12
+ const highRef = useRef(null);
13
+ useEffect(() => {
14
+ const el = lowRef.current;
15
+ if (!el)
16
+ return;
17
+ el.focus();
18
+ el.setSelectionRange(el.value.length, el.value.length);
19
+ }, []);
20
+ const parse = (raw) => {
21
+ if (raw.trim() === "")
22
+ return null;
23
+ const n = parseNumber(raw, cv);
24
+ return n == null ? undefined : roundTo(n, decimals);
25
+ };
26
+ const text = (n) => n == null ? "" : formatNumberText(n, decimals, cv);
27
+ const resolveClose = (reason) => {
28
+ if (reason === "escape")
29
+ return { kind: "cancel" };
30
+ const low = parse(lowRef.current?.value ?? "");
31
+ const high = parse(highRef.current?.value ?? "");
32
+ if (low === undefined || high === undefined)
33
+ return { kind: "cancel" };
34
+ const shown = (n) => (n == null ? null : roundTo(n, decimals));
35
+ if (low === shown(initial?.low) && high === shown(initial?.high))
36
+ return { kind: "noop" };
37
+ if (low === null && high === null && !allowEmpty)
38
+ return { kind: "cancel" };
39
+ return { kind: "commit", payload: { low, high } };
40
+ };
41
+ useImperativeHandle(ref, () => ({ resolveClose }));
42
+ const keys = (which) => (e) => {
43
+ e.stopPropagation();
44
+ if (e.key === "Enter") {
45
+ e.preventDefault();
46
+ onRequestClose("enter");
47
+ }
48
+ else if (e.key === "Escape") {
49
+ onRequestClose("escape");
50
+ }
51
+ else if (e.key === "Tab") {
52
+ e.preventDefault();
53
+ if (which === "low" && !e.shiftKey)
54
+ highRef.current?.focus();
55
+ else if (which === "high" && e.shiftKey)
56
+ lowRef.current?.focus();
57
+ else
58
+ onRequestClose(e.shiftKey ? "shift-tab" : "tab");
59
+ }
60
+ };
61
+ const blur = (e) => {
62
+ if (!boxRef.current?.contains(e.relatedTarget))
63
+ onRequestClose("blur");
64
+ };
65
+ const input = cx("h-full w-16 min-w-0 flex-none select-text bg-transparent tabular-nums text-(length:--grid-text) text-(color:--vk-fg) outline-hidden", align === "end" ? "text-right" : "text-left");
66
+ return (_jsxs("span", { ref: boxRef, onMouseDown: (e) => {
67
+ if (!(e.target instanceof HTMLInputElement))
68
+ e.preventDefault();
69
+ }, className: cx("flex h-full w-full min-w-0 items-center gap-1.5", align === "end" && "justify-end"), children: [_jsx("input", { ref: lowRef, defaultValue: seed ?? text(initial?.low), inputMode: "decimal", "aria-label": views.messages({ key: "views.editors.range-low" }), placeholder: views.messages({ key: "views.editors.range-low" }), onKeyDown: keys("low"), onBlur: blur, onClick: (e) => e.stopPropagation(), className: input }), _jsx("span", { className: "shrink-0 text-xs text-(color:--vk-fg-subtle)", children: "\u2013" }), _jsx("input", { ref: highRef, defaultValue: text(initial?.high), inputMode: "decimal", "aria-label": views.messages({ key: "views.editors.range-high" }), placeholder: views.messages({ key: "views.editors.range-high" }), onKeyDown: keys("high"), onBlur: blur, onClick: (e) => e.stopPropagation(), className: input }), suffix && _jsx("span", { className: "shrink-0 text-xs text-(color:--vk-fg-subtlest)", children: suffix })] }));
70
+ });
@@ -0,0 +1,65 @@
1
+ import { type ReactNode } from "react";
2
+ import type { CloseReason, CloseResolution, FieldMessageResolver } from "@viewkitjs/fields";
3
+ import { type RelationSource } from "./relation-source.js";
4
+ export { RELATION_PAGE_SIZE, RELATION_SEARCH_DEBOUNCE_MS } from "./relation-source.js";
5
+ export type { RelationCandidate, RelationSearch, RelationSource } from "./relation-source.js";
6
+ /**
7
+ * THE relation-picking core — search the candidates, pick one, it REPLACES the
8
+ * link. Many-to-one, so there is nothing to accumulate.
9
+ *
10
+ * Built from the app's command list (the components map) rather than a
11
+ * combobox: a combobox owns a trigger button, and a cell editor has none — it
12
+ * is already open, anchored over a value that is already on screen. The host
13
+ * owns that mounting behaviour; what lives here is the panel, the search, and
14
+ * what a close MEANS for a relation: a pick is the commit, everything else
15
+ * discards. The panel also carries the way OUT when the row isn't there — the
16
+ * host's pinned create rows — and wears the kind's glyph the host names.
17
+ *
18
+ * The candidates are the HOST's, through a discriminated source: a STATIC list
19
+ * (every subscription you could link to, preloaded — the grid's shape, and any
20
+ * small set's) or a REMOTE search over thousands of rows (a client, a person,
21
+ * a deal). The core owns the remote branch's choreography — when to ask, what
22
+ * to drop, what to show meanwhile — and never the asking itself: the search
23
+ * function is the host's, which is what keeps workspace tenancy in the host's
24
+ * closure and in the routes.
25
+ */
26
+ /**
27
+ * A pinned row under the list for "it isn't in the list yet": the host opens
28
+ * its own create form with what was typed already filled. Pinned rather than
29
+ * appended to the results, because an affordance that only appears below a
30
+ * scrolled list is one nobody finds — and a button rather than a command item,
31
+ * because the filter would hide an item with no label to match while a query
32
+ * is typed, which is exactly when the row is wanted. A click is a `pick` that
33
+ * resolves `noop`: the host closes, nothing is written, then `onCreate` runs.
34
+ */
35
+ export type RelationCreate = {
36
+ /** The row's words; receives the trimmed query. */
37
+ label: (query: string) => string;
38
+ /** Runs AFTER the host has been asked to close, with the trimmed query. */
39
+ onCreate: (query: string) => void;
40
+ };
41
+ export type RelationEditorHandle = {
42
+ /** What this close means. Synchronous, idempotent, no timer — the host
43
+ * closes, waits its own exit gap, then applies the answer. */
44
+ resolveClose: (reason: CloseReason) => CloseResolution<string | null>;
45
+ };
46
+ export declare const RelationEditor: import("react").ForwardRefExoticComponent<{
47
+ candidates: RelationSource;
48
+ /** The linked id, or null when the value is empty. */
49
+ initial: string | null;
50
+ /** Offer "None" — only when the surface says the link is optional. */
51
+ clearable: boolean;
52
+ /** The user chose: the host closes, then asks `resolveClose("pick")`. */
53
+ onRequestClose: (reason: CloseReason) => void;
54
+ /** The kind's glyph, from the host (the app's entity registry — the core
55
+ * knows there is such a thing as a kind, never which kinds exist). Worn by
56
+ * every candidate that brought no icon of its own; given, the glyph lane
57
+ * is always drawn. */
58
+ kindGlyph?: ReactNode;
59
+ /** The surface's words for the unlink row. */
60
+ noneLabel?: string;
61
+ /** The host's words for this panel (fields' messages); default: the provider's conventions. */
62
+ message?: FieldMessageResolver;
63
+ /** The pinned create rows, in order. */
64
+ creates?: RelationCreate[];
65
+ } & import("react").RefAttributes<RelationEditorHandle>>;