@atscript/ui 0.1.206 → 0.1.208

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 (127) hide show
  1. package/dist/form/create-form-def.cjs +16 -18
  2. package/dist/form/create-form-def.mjs +15 -17
  3. package/dist/form/decimal-format.cjs +8 -3
  4. package/dist/form/decimal-format.d.cts +8 -2
  5. package/dist/form/decimal-format.d.mts +8 -2
  6. package/dist/form/decimal-format.mjs +8 -3
  7. package/dist/form/form-actions.cjs +9 -0
  8. package/dist/form/form-actions.d.cts +7 -1
  9. package/dist/form/form-actions.d.mts +7 -1
  10. package/dist/form/form-actions.mjs +9 -1
  11. package/dist/form/measurement.cjs +58 -0
  12. package/dist/form/measurement.d.cts +36 -1
  13. package/dist/form/measurement.d.mts +36 -1
  14. package/dist/form/measurement.mjs +57 -2
  15. package/dist/form/omit-derived.cjs +11 -0
  16. package/dist/form/omit-derived.d.cts +8 -1
  17. package/dist/form/omit-derived.d.mts +8 -1
  18. package/dist/form/omit-derived.mjs +11 -1
  19. package/dist/form/optional-mode.cjs +7 -7
  20. package/dist/form/optional-mode.d.cts +2 -1
  21. package/dist/form/optional-mode.d.mts +2 -1
  22. package/dist/form/optional-mode.mjs +8 -8
  23. package/dist/form/path-utils.cjs +10 -0
  24. package/dist/form/path-utils.d.cts +8 -1
  25. package/dist/form/path-utils.d.mts +8 -1
  26. package/dist/form/path-utils.mjs +10 -1
  27. package/dist/form/types.cjs +5 -0
  28. package/dist/form/types.d.cts +14 -0
  29. package/dist/form/types.d.mts +14 -0
  30. package/dist/form/types.mjs +5 -1
  31. package/dist/form/validate.cjs +56 -5
  32. package/dist/form/validate.d.cts +30 -2
  33. package/dist/form/validate.d.mts +30 -2
  34. package/dist/form/validate.mjs +56 -6
  35. package/dist/index.cjs +42 -6
  36. package/dist/index.d.cts +20 -12
  37. package/dist/index.d.mts +20 -12
  38. package/dist/index.mjs +23 -15
  39. package/dist/plugin/annotations.cjs +33 -14
  40. package/dist/plugin/annotations.mjs +34 -15
  41. package/dist/plugin/value-help-validation.cjs +26 -6
  42. package/dist/plugin/value-help-validation.mjs +26 -7
  43. package/dist/shared/annotation-keys.cjs +3 -0
  44. package/dist/shared/annotation-keys.d.cts +2 -1
  45. package/dist/shared/annotation-keys.d.mts +2 -1
  46. package/dist/shared/annotation-keys.mjs +3 -1
  47. package/dist/shared/dev.cjs +22 -0
  48. package/dist/shared/dev.d.cts +4 -0
  49. package/dist/shared/dev.d.mts +4 -0
  50. package/dist/shared/dev.mjs +22 -0
  51. package/dist/shared/field-resolver.cjs +21 -1
  52. package/dist/shared/field-resolver.d.cts +15 -1
  53. package/dist/shared/field-resolver.d.mts +15 -1
  54. package/dist/shared/field-resolver.mjs +20 -2
  55. package/dist/shared/merge-filters.cjs +28 -0
  56. package/dist/shared/merge-filters.d.cts +13 -0
  57. package/dist/shared/merge-filters.d.mts +13 -0
  58. package/dist/shared/merge-filters.mjs +28 -0
  59. package/dist/shared/meta-cache.cjs +5 -4
  60. package/dist/shared/meta-cache.d.cts +3 -2
  61. package/dist/shared/meta-cache.d.mts +3 -2
  62. package/dist/shared/meta-cache.mjs +5 -4
  63. package/dist/shared/resolve-component.cjs +27 -0
  64. package/dist/shared/resolve-component.d.cts +22 -0
  65. package/dist/shared/resolve-component.d.mts +22 -0
  66. package/dist/shared/resolve-component.mjs +27 -0
  67. package/dist/shared/stable-key.cjs +28 -0
  68. package/dist/shared/stable-key.d.cts +13 -0
  69. package/dist/shared/stable-key.d.mts +13 -0
  70. package/dist/shared/stable-key.mjs +28 -0
  71. package/dist/shared/to-date.cjs +65 -0
  72. package/dist/shared/to-date.d.cts +35 -0
  73. package/dist/shared/to-date.d.mts +35 -0
  74. package/dist/shared/to-date.mjs +64 -0
  75. package/dist/shared/value-label.cjs +14 -2
  76. package/dist/shared/value-label.d.cts +23 -6
  77. package/dist/shared/value-label.d.mts +23 -6
  78. package/dist/shared/value-label.mjs +14 -3
  79. package/dist/table/create-table-def.cjs +53 -13
  80. package/dist/table/create-table-def.mjs +53 -15
  81. package/dist/table/types.d.cts +15 -13
  82. package/dist/table/types.d.mts +15 -13
  83. package/dist/value-help/client-store.cjs +43 -0
  84. package/dist/value-help/client-store.d.mts +1 -0
  85. package/dist/value-help/client-store.mjs +40 -0
  86. package/dist/value-help/display-value.cjs +30 -0
  87. package/dist/value-help/display-value.d.cts +45 -0
  88. package/dist/value-help/display-value.d.mts +45 -0
  89. package/dist/value-help/display-value.mjs +30 -0
  90. package/dist/value-help/distinct-client.cjs +80 -7
  91. package/dist/value-help/distinct-client.d.cts +31 -36
  92. package/dist/value-help/distinct-client.d.mts +31 -36
  93. package/dist/value-help/distinct-client.mjs +80 -7
  94. package/dist/value-help/extract-ref.cjs +15 -4
  95. package/dist/value-help/extract-ref.d.cts +6 -1
  96. package/dist/value-help/extract-ref.d.mts +6 -1
  97. package/dist/value-help/extract-ref.mjs +16 -6
  98. package/dist/value-help/index.d.mts +6 -3
  99. package/dist/value-help/options.cjs +70 -8
  100. package/dist/value-help/options.d.cts +57 -4
  101. package/dist/value-help/options.d.mts +57 -4
  102. package/dist/value-help/options.mjs +67 -9
  103. package/dist/value-help/resolve-options.cjs +9 -7
  104. package/dist/value-help/resolve-options.d.cts +8 -9
  105. package/dist/value-help/resolve-options.d.mts +8 -9
  106. package/dist/value-help/resolve-options.mjs +9 -7
  107. package/dist/value-help/resolve.cjs +29 -8
  108. package/dist/value-help/resolve.d.cts +22 -5
  109. package/dist/value-help/resolve.d.mts +22 -5
  110. package/dist/value-help/resolve.mjs +29 -8
  111. package/dist/value-help/scope.cjs +3 -7
  112. package/dist/value-help/scope.mjs +3 -7
  113. package/dist/value-help/source.cjs +72 -0
  114. package/dist/value-help/source.d.cts +55 -0
  115. package/dist/value-help/source.d.mts +55 -0
  116. package/dist/value-help/source.mjs +71 -0
  117. package/dist/value-help/texts.cjs +318 -0
  118. package/dist/value-help/texts.d.cts +53 -0
  119. package/dist/value-help/texts.d.mts +53 -0
  120. package/dist/value-help/texts.mjs +313 -0
  121. package/dist/value-help/types.d.cts +10 -0
  122. package/dist/value-help/types.d.mts +10 -0
  123. package/dist/value-help/value-help-client.cjs +24 -20
  124. package/dist/value-help/value-help-client.d.cts +10 -5
  125. package/dist/value-help/value-help-client.d.mts +10 -5
  126. package/dist/value-help/value-help-client.mjs +22 -18
  127. package/package.json +10 -10
@@ -0,0 +1,53 @@
1
+ import { ValueText } from "../shared/value-label.mjs";
2
+ import { ValueHelpInfo } from "./types.mjs";
3
+ import { ValueHelpSourceOptions } from "./source.mjs";
4
+ import { ClientLike, FilterExpr } from "@atscript/db-client";
5
+
6
+ //#region src/value-help/texts.d.ts
7
+ /** How {@link valueHelpText} reads (since 0.1.207). */
8
+ type ValueHelpTextOptions = ValueHelpSourceOptions & {
9
+ /**
10
+ * Only a text already known — no lookup: for a value still being typed (a
11
+ * draft filter chip). The rows the pickers read are known.
12
+ */
13
+ peek?: boolean;
14
+ };
15
+ /**
16
+ * The dictionary text of a code bound by `info` (since 0.1.207): its row's
17
+ * value of the binding's label — `@ui.valueHelp.label`, else the
18
+ * dictionary's `@ui.dict.label` — in the binding's scope (its static
19
+ * `@ui.valueHelp` filter), with the arrangement to show it in
20
+ * (`displayValue` puts the two together). `undefined` while it loads, and for
21
+ * good when neither label is declared, the label field is not readable, the
22
+ * dictionary is keyed by more than one field, the binding's filter refers to
23
+ * host values and its key is not the dictionary's single primary key, its
24
+ * `/meta` cannot be read, no row holds the code, several rows hold it with
25
+ * different texts, or its text is empty: the code then shows alone. A failed
26
+ * lookup is asked again after a while.
27
+ *
28
+ * A miss asks for it: the misses of one tick are read in one request per
29
+ * dictionary and scope (`$filter` the key `$in` the codes, AND the scope;
30
+ * `$select` the key and the label field), through the binding's
31
+ * `valueHelpSource` (`options`); the rows the pickers read fill the same
32
+ * cache. `options.peek` reads only the texts already known: no lookup. After a
33
+ * data drop (`invalidateValueHelpCache`) a code keeps its text until read
34
+ * again. {@link onValueHelpTexts} reports arrivals, so a view can read again.
35
+ * In the browser only: a server render shows codes.
36
+ */
37
+ declare function valueHelpText(info: ValueHelpInfo, value: unknown, options?: ValueHelpTextOptions): ValueText | undefined;
38
+ /**
39
+ * Loads the texts of `values` bound by `info` in one batched read (since
40
+ * 0.1.207): resolves once {@link valueHelpText} knows each of them — before
41
+ * an export writes its rows, or as a table's rows land. Without a code among
42
+ * them it reads nothing, not even the dictionary's `/meta`. Never rejects.
43
+ */
44
+ declare function loadValueHelpTexts(info: ValueHelpInfo, values: Iterable<unknown>, options?: ValueHelpSourceOptions): Promise<void>;
45
+ /**
46
+ * Run `listener` whenever texts arrive or are dropped, so a view reading
47
+ * {@link valueHelpText} reads again: with the binding whose texts arrived
48
+ * (`valueHelpKey`), with none when the cache was dropped. Returns the
49
+ * unsubscribe function. Since 0.1.207.
50
+ */
51
+ declare function onValueHelpTexts(listener: (binding?: string) => void): () => void;
52
+ //#endregion
53
+ export { ValueHelpTextOptions, loadValueHelpTexts, onValueHelpTexts, valueHelpText };
@@ -0,0 +1,313 @@
1
+ import { valueHelpKey } from "./extract-ref.mjs";
2
+ import { mergeFilters } from "../shared/merge-filters.mjs";
3
+ import { codeOf } from "../shared/value-label.mjs";
4
+ import { clientStore, dropClientStores, staleClientStores } from "./client-store.mjs";
5
+ import { valueHelpRowText } from "./options.mjs";
6
+ import { valueHelpSource } from "./source.mjs";
7
+ //#region src/value-help/texts.ts
8
+ /** Codes per request: a lookup is a GET, the codes travel in its URL. */
9
+ const LOOKUP_BATCH = 50;
10
+ /** Texts kept per dictionary, binding scope and label field; the least recently read go first. */
11
+ const MAX_TEXTS = 1e4;
12
+ /** A failed lookup (no access, no network) asks again after this long (ms). */
13
+ const RETRY_MS = 3e4;
14
+ /**
15
+ * Per binding (`labelId`): the label its codes show; `null` for none — also
16
+ * when the dictionary's `/meta` failed, so no read asks for it again until
17
+ * the cache is dropped; a promise while resolving.
18
+ */
19
+ let labels = /* @__PURE__ */ new Map();
20
+ /** The sources texts were read through: their `/meta` failing fails their binding's label. */
21
+ const watched = /* @__PURE__ */ new WeakSet();
22
+ const listeners = /* @__PURE__ */ new Set();
23
+ /** What a binding's label depends on: its dictionary and key, its own label, its host scope. */
24
+ function labelId(info) {
25
+ const { label } = info;
26
+ const host = info.hostFilter ? "host" : "";
27
+ return `${valueHelpKey(info)}\0${label?.field ?? ""}\0${label?.arrangement ?? ""}\0${host}`;
28
+ }
29
+ /** The texts of the codes `info` binds, in its scope, read through `store`'s client from `field`. */
30
+ function textsOf(store, info, field) {
31
+ const scope = info.filter ? JSON.stringify(info.filter) : "";
32
+ const id = `${info.targetField}\0${field}\0${scope}`;
33
+ let texts = store.texts.get(id);
34
+ if (!texts) {
35
+ texts = {
36
+ client: store.client,
37
+ binding: valueHelpKey(info),
38
+ key: info.targetField,
39
+ field,
40
+ filter: info.filter,
41
+ slots: /* @__PURE__ */ new Map(),
42
+ stale: store.stale?.get(id)?.slots
43
+ };
44
+ store.texts.set(id, texts);
45
+ }
46
+ return texts;
47
+ }
48
+ /**
49
+ * {@link textsOf} the client `info`'s source reads with. A dictionary entry
50
+ * made again (evicted, another UI locale) whose `/meta` fails ends the label
51
+ * of every binding read through it: their codes show alone until the next
52
+ * drop, never asked again on each read.
53
+ */
54
+ function textsFor(info, id, label, options) {
55
+ const source = valueHelpSource(info, options);
56
+ if (!watched.has(source)) {
57
+ watched.add(source);
58
+ const map = labels;
59
+ source.entry.meta.catch(() => map.set(id, null));
60
+ }
61
+ return textsOf(clientStore(source.entry.client), info, label.field);
62
+ }
63
+ /**
64
+ * The label a binding's codes show by key: none for a dictionary keyed by
65
+ * more than one field, nor for a binding scoped by host values
66
+ * (`ValueHelpInfo.hostFilter`) whose key is not the dictionary's single
67
+ * primary key — such a code names no one row a batched lookup can find.
68
+ */
69
+ function codeLabel(resolved, info) {
70
+ const keys = resolved.primaryKeys;
71
+ if (keys.length > 1 || info.hostFilter && keys[0] !== info.targetField) return void 0;
72
+ return resolved.label;
73
+ }
74
+ function notify(binding) {
75
+ for (const listener of listeners) listener(binding);
76
+ }
77
+ /**
78
+ * The label a binding's codes show, resolved once per binding: its
79
+ * `ResolvedValueHelp.label`; `null` without one, after a failed `/meta` read,
80
+ * or when its codes cannot be read by key (`codeLabel`).
81
+ */
82
+ function labelOf(info, id, options) {
83
+ let label = labels.get(id);
84
+ if (label === void 0) {
85
+ const pending = valueHelpSource(info, options).resolve().then((r) => codeLabel(r, info) ?? null, () => null);
86
+ labels.set(id, label = pending);
87
+ pending.then((resolved) => {
88
+ if (labels.get(id) !== pending) return;
89
+ labels.set(id, resolved);
90
+ if (resolved) notify(valueHelpKey(info));
91
+ });
92
+ }
93
+ return label;
94
+ }
95
+ /** Sets the slot of `code` as the most recently read. */
96
+ function touch(slots, code, slot) {
97
+ slots.delete(code);
98
+ slots.set(code, slot);
99
+ }
100
+ /** Drops the least recently read settled texts beyond {@link MAX_TEXTS}. */
101
+ function trim(slots) {
102
+ if (slots.size <= MAX_TEXTS) return;
103
+ for (const [code, slot] of slots) {
104
+ if (!(slot instanceof Promise)) slots.delete(code);
105
+ if (slots.size <= MAX_TEXTS) return;
106
+ }
107
+ }
108
+ /**
109
+ * The texts `rows` give their codes (`key`) from `field`: a code several rows
110
+ * give different texts is ambiguous and gets none (`null`) — never the first
111
+ * row's. A row without the field gives nothing.
112
+ */
113
+ function rowTexts(rows, key, field) {
114
+ const texts = /* @__PURE__ */ new Map();
115
+ for (const row of rows) {
116
+ const code = codeOf(row[key]);
117
+ if (code === void 0 || !(field in row)) continue;
118
+ const text = valueHelpRowText({ labelField: field }, row).label ?? null;
119
+ const known = texts.get(code);
120
+ texts.set(code, known === void 0 || known === text ? text : null);
121
+ }
122
+ return texts;
123
+ }
124
+ /**
125
+ * Ask for the text of `code`: it joins this tick's batch of `texts`, read
126
+ * once the tick's reads have queued their codes. Nothing while a failed
127
+ * lookup waits to retry. Returns what the code's slot waits on.
128
+ */
129
+ function ask(texts, code, value) {
130
+ if (texts.retry !== void 0) return void 0;
131
+ let batch = texts.batch;
132
+ if (!batch) {
133
+ let settle;
134
+ const done = new Promise((resolve) => settle = resolve);
135
+ const created = {
136
+ values: /* @__PURE__ */ new Map(),
137
+ done,
138
+ settle
139
+ };
140
+ texts.batch = batch = created;
141
+ queueMicrotask(() => {
142
+ texts.batch = void 0;
143
+ lookup(texts, created);
144
+ });
145
+ }
146
+ batch.values.set(code, value);
147
+ texts.slots.set(code, batch.done);
148
+ return batch.done;
149
+ }
150
+ async function lookup(texts, batch) {
151
+ const { client, key, field, filter, slots } = texts;
152
+ const { done } = batch;
153
+ const entries = [...batch.values];
154
+ const select = key === field ? [key] : [key, field];
155
+ let failed = false;
156
+ let landed = false;
157
+ const requests = [];
158
+ for (let i = 0; i < entries.length; i += LOOKUP_BATCH) {
159
+ const chunk = entries.slice(i, i + LOOKUP_BATCH);
160
+ const request = {
161
+ filter: mergeFilters(filter, { [key]: { $in: chunk.map(([, value]) => value) } }),
162
+ controls: {
163
+ $select: select,
164
+ $limit: chunk.length * 2
165
+ }
166
+ };
167
+ requests.push(Promise.resolve().then(() => client.query(request)).then((rows) => {
168
+ const found = rowTexts(rows, key, field);
169
+ for (const [code] of chunk) {
170
+ if (slots.get(code) !== done) continue;
171
+ const text = found.get(code) ?? null;
172
+ slots.set(code, text);
173
+ if (text !== null) landed = true;
174
+ }
175
+ }).catch(() => {
176
+ failed = true;
177
+ for (const [code] of chunk) if (slots.get(code) === done) slots.delete(code);
178
+ }));
179
+ }
180
+ await Promise.all(requests);
181
+ if (failed) texts.retry ??= setTimeout(() => {
182
+ texts.retry = void 0;
183
+ notify(texts.binding);
184
+ }, RETRY_MS);
185
+ trim(slots);
186
+ batch.settle();
187
+ if (landed) notify(texts.binding);
188
+ }
189
+ /**
190
+ * The dictionary text of a code bound by `info` (since 0.1.207): its row's
191
+ * value of the binding's label — `@ui.valueHelp.label`, else the
192
+ * dictionary's `@ui.dict.label` — in the binding's scope (its static
193
+ * `@ui.valueHelp` filter), with the arrangement to show it in
194
+ * (`displayValue` puts the two together). `undefined` while it loads, and for
195
+ * good when neither label is declared, the label field is not readable, the
196
+ * dictionary is keyed by more than one field, the binding's filter refers to
197
+ * host values and its key is not the dictionary's single primary key, its
198
+ * `/meta` cannot be read, no row holds the code, several rows hold it with
199
+ * different texts, or its text is empty: the code then shows alone. A failed
200
+ * lookup is asked again after a while.
201
+ *
202
+ * A miss asks for it: the misses of one tick are read in one request per
203
+ * dictionary and scope (`$filter` the key `$in` the codes, AND the scope;
204
+ * `$select` the key and the label field), through the binding's
205
+ * `valueHelpSource` (`options`); the rows the pickers read fill the same
206
+ * cache. `options.peek` reads only the texts already known: no lookup. After a
207
+ * data drop (`invalidateValueHelpCache`) a code keeps its text until read
208
+ * again. {@link onValueHelpTexts} reports arrivals, so a view can read again.
209
+ * In the browser only: a server render shows codes.
210
+ */
211
+ function valueHelpText(info, value, options) {
212
+ const code = codeOf(value);
213
+ if (code === void 0 || typeof window === "undefined") return void 0;
214
+ const id = labelId(info);
215
+ const label = labelOf(info, id, options);
216
+ if (!label || label instanceof Promise) return void 0;
217
+ const texts = textsFor(info, id, label, options);
218
+ const slot = texts.slots.get(code);
219
+ if (slot === void 0 && !options?.peek) ask(texts, code, value);
220
+ const text = slot === void 0 || slot instanceof Promise ? texts.stale?.get(code) : slot;
221
+ if (typeof text !== "string") return void 0;
222
+ if (text === slot) touch(texts.slots, code, slot);
223
+ return {
224
+ text,
225
+ arrangement: label.arrangement
226
+ };
227
+ }
228
+ /**
229
+ * Loads the texts of `values` bound by `info` in one batched read (since
230
+ * 0.1.207): resolves once {@link valueHelpText} knows each of them — before
231
+ * an export writes its rows, or as a table's rows land. Without a code among
232
+ * them it reads nothing, not even the dictionary's `/meta`. Never rejects.
233
+ */
234
+ async function loadValueHelpTexts(info, values, options) {
235
+ if (typeof window === "undefined") return;
236
+ const codes = /* @__PURE__ */ new Map();
237
+ for (const value of values) {
238
+ const code = codeOf(value);
239
+ if (code !== void 0) codes.set(code, value);
240
+ }
241
+ if (codes.size === 0) return;
242
+ const id = labelId(info);
243
+ const label = await labelOf(info, id, options);
244
+ if (!label) return;
245
+ const texts = textsFor(info, id, label, options);
246
+ const waits = /* @__PURE__ */ new Set();
247
+ for (const [code, value] of codes) {
248
+ const slot = texts.slots.get(code);
249
+ const wait = slot === void 0 ? ask(texts, code, value) : slot;
250
+ if (wait instanceof Promise) waits.add(wait);
251
+ }
252
+ await Promise.all(waits);
253
+ }
254
+ /**
255
+ * Run `listener` whenever texts arrive or are dropped, so a view reading
256
+ * {@link valueHelpText} reads again: with the binding whose texts arrived
257
+ * (`valueHelpKey`), with none when the cache was dropped. Returns the
258
+ * unsubscribe function. Since 0.1.207.
259
+ */
260
+ function onValueHelpTexts(listener) {
261
+ listeners.add(listener);
262
+ return () => {
263
+ listeners.delete(listener);
264
+ };
265
+ }
266
+ /**
267
+ * Picker rows fill the cache: the rows of a binding's search or picker page,
268
+ * with its label field, land in the texts of that binding's scope in `store`
269
+ * — the client's store when the read began, so rows read before a data drop
270
+ * land in the stale one.
271
+ *
272
+ * @internal
273
+ */
274
+ function feedValueHelpTexts(store, info, resolved, rows) {
275
+ const label = codeLabel(resolved, info);
276
+ if (!label || !Array.isArray(rows)) return;
277
+ const { slots } = textsOf(store, info, label.field);
278
+ let changed = false;
279
+ for (const [code, text] of rowTexts(rows, info.targetField, label.field)) {
280
+ const prev = slots.get(code);
281
+ if (prev === text) continue;
282
+ touch(slots, code, text);
283
+ if (prev !== void 0) changed = true;
284
+ }
285
+ trim(slots);
286
+ if (changed) notify(valueHelpKey(info));
287
+ }
288
+ /**
289
+ * The data of `client`'s dictionary, or of every one, changed
290
+ * (`invalidateValueHelpCache`): its store goes stale (`staleClientStores`:
291
+ * its searches go, its texts show until read again), the labels stay — a
292
+ * binding whose label failed is asked again; mounted views read again.
293
+ *
294
+ * @internal
295
+ */
296
+ function staleValueHelpTexts(client) {
297
+ staleClientStores(client);
298
+ for (const [id, label] of labels) if (label === null) labels.delete(id);
299
+ notify();
300
+ }
301
+ /**
302
+ * A reset (`resetMetaCache`: another viewer): every client's store and every
303
+ * binding's label go; mounted views read again.
304
+ *
305
+ * @internal
306
+ */
307
+ function resetValueHelpTexts() {
308
+ dropClientStores();
309
+ labels = /* @__PURE__ */ new Map();
310
+ notify();
311
+ }
312
+ //#endregion
313
+ export { feedValueHelpTexts, loadValueHelpTexts, onValueHelpTexts, resetValueHelpTexts, staleValueHelpTexts, valueHelpText };
@@ -1,3 +1,4 @@
1
+ import { ValueLabelArrangement } from "../shared/value-label.cjs";
1
2
  import { FilterExpr } from "@atscript/db-client";
2
3
 
3
4
  //#region src/value-help/types.d.ts
@@ -64,6 +65,15 @@ interface ValueHelpInfo {
64
65
  * order, instead of the dictionary view. Since 0.1.190.
65
66
  */
66
67
  columns?: string[];
68
+ /**
69
+ * `@ui.valueHelp.label`: the dictionary field holding the text of this
70
+ * binding's codes, instead of the dictionary's `@ui.dict.label`, and the
71
+ * arrangement they show in (the dictionary's when left out). Since 0.1.207.
72
+ */
73
+ label?: {
74
+ field: string;
75
+ arrangement?: ValueLabelArrangement;
76
+ };
67
77
  }
68
78
  //#endregion
69
79
  export { TFormEntryOptions, ValueHelpInfo };
@@ -1,3 +1,4 @@
1
+ import { ValueLabelArrangement } from "../shared/value-label.mjs";
1
2
  import { FilterExpr } from "@atscript/db-client";
2
3
 
3
4
  //#region src/value-help/types.d.ts
@@ -64,6 +65,15 @@ interface ValueHelpInfo {
64
65
  * order, instead of the dictionary view. Since 0.1.190.
65
66
  */
66
67
  columns?: string[];
68
+ /**
69
+ * `@ui.valueHelp.label`: the dictionary field holding the text of this
70
+ * binding's codes, instead of the dictionary's `@ui.dict.label`, and the
71
+ * arrangement they show in (the dictionary's when left out). Since 0.1.207.
72
+ */
73
+ label?: {
74
+ field: string;
75
+ arrangement?: ValueLabelArrangement;
76
+ };
67
77
  }
68
78
  //#endregion
69
79
  export { TFormEntryOptions, ValueHelpInfo };
@@ -1,9 +1,12 @@
1
+ const require_dict_paths = require("./dict-paths.cjs");
2
+ const require_merge_filters = require("../shared/merge-filters.cjs");
1
3
  const require_str = require("../shared/str.cjs");
2
4
  const require_create_table_def = require("../table/create-table-def.cjs");
3
5
  const require_value_kind = require("../table/value-kind.cjs");
6
+ const require_client_store = require("./client-store.cjs");
7
+ const require_texts = require("./texts.cjs");
4
8
  //#region src/value-help/value-help-client.ts
5
9
  let cacheTtl = 5e3;
6
- let searches = /* @__PURE__ */ new WeakMap();
7
10
  /**
8
11
  * How long (ms) a settled value-help search is reused for an identical
9
12
  * search on the same client. Default 5000. `0` shares only searches still in
@@ -14,16 +17,17 @@ function setValueHelpCacheTtl(ms) {
14
17
  cacheTtl = ms;
15
18
  }
16
19
  /**
17
- * Drop shared value-help search results — for one `client`, or for every
18
- * client when omitted. Call after writing to a dictionary outside the
19
- * built-in table actions to make pickers refetch at once.
20
+ * The dictionaries' data changed: drop shared value-help search results — for
21
+ * one `client`, or for every client when omitted — and (since 0.1.207) mark
22
+ * the texts of codes read from them stale: a code keeps its text until it is
23
+ * read again (one batched request), then the new text replaces it. The
24
+ * labels the bindings resolved stay (they are metadata); a dictionary whose
25
+ * `/meta` failed is asked again. Mounted views read their texts again, and a
26
+ * distinct-values pager its first page (since 0.1.208). Call after writing to
27
+ * a dictionary outside the built-in table actions.
20
28
  */
21
29
  function invalidateValueHelpCache(client) {
22
- if (client) searches.get(client)?.clear();
23
- else searches = /* @__PURE__ */ new WeakMap();
24
- }
25
- function now() {
26
- return typeof performance === "undefined" ? Date.now() : performance.now();
30
+ require_texts.staleValueHelpTexts(client);
27
31
  }
28
32
  /** Cache key of a plain-JSON request; `undefined` when it holds anything else (never shared). */
29
33
  function requestKey(request) {
@@ -47,12 +51,11 @@ function sharedQuery(client, request) {
47
51
  if (cacheTtl < 0 || typeof window === "undefined") return run();
48
52
  const key = requestKey(request);
49
53
  if (key === void 0) return run();
50
- let byKey = searches.get(client);
51
- if (!byKey) searches.set(client, byKey = /* @__PURE__ */ new Map());
54
+ const byKey = require_client_store.clientStore(client).searches;
52
55
  const hit = byKey.get(key);
53
- if (hit && (hit.settledAt === void 0 || now() - hit.settledAt < cacheTtl)) return hit.promise;
56
+ if (hit && (hit.settledAt === void 0 || require_client_store.now() - hit.settledAt < cacheTtl)) return hit.promise;
54
57
  const entry = { promise: run().then((items) => {
55
- entry.settledAt = now();
58
+ entry.settledAt = require_client_store.now();
56
59
  return items;
57
60
  }, (err) => {
58
61
  if (byKey.get(key) === entry) byKey.delete(key);
@@ -67,8 +70,8 @@ function sharedQuery(client, request) {
67
70
  * $select scoping).
68
71
  *
69
72
  * Consumers resolve the target's metadata once via `resolveValueHelp(url)`
70
- * and pass the resulting `ResolvedValueHelp` to `search()`. Label resolution
71
- * for cells is deliberately unsupported — cells always display raw ids.
73
+ * and pass the resulting `ResolvedValueHelp` to `search()`. A binding's
74
+ * `valueHelpSource` searches through it and fills the texts of its codes.
72
75
  *
73
76
  * Identical searches on the same `Client` are shared (see
74
77
  * {@link setValueHelpCacheTtl}).
@@ -104,7 +107,7 @@ var ValueHelpClient = class {
104
107
  const keyField = valueField ?? resolved.primaryKeys[0] ?? resolved.labelField;
105
108
  const search = buildOrFilter(text, computeSelectFields(resolved, mode, valueField), keyField, resolved.targetType);
106
109
  if (!search) return { items: [] };
107
- filter = scope ? { $and: [scope, search] } : search;
110
+ filter = require_merge_filters.mergeFilters(scope, search);
108
111
  }
109
112
  const items = await sharedQuery(this._client, {
110
113
  ...filter && { filter },
@@ -128,14 +131,15 @@ function valueHelpSelect(resolved, info, mode = "form", valueField = info?.targe
128
131
  return [...new Set(fields)];
129
132
  }
130
133
  /**
131
- * The dictionary's own fields of a value-help query — always including the
132
- * `valueField` the picker commits (a unique non-PK field is otherwise never fetched).
134
+ * The dictionary's own fields of a value-help query: in `"filter"` mode its
135
+ * dictionary view (`valueHelpDictPaths`), in `"form"` mode its keys, label and
136
+ * description — always including the `valueField` the picker commits (a
137
+ * unique non-PK field is otherwise never fetched).
133
138
  */
134
139
  function computeSelectFields(resolved, mode, valueField) {
135
- const fields = [...resolved.primaryKeys, resolved.labelField];
140
+ const fields = mode === "filter" ? [...require_dict_paths.valueHelpDictPaths(resolved)] : [...resolved.primaryKeys, resolved.labelField];
136
141
  if (valueField) fields.push(valueField);
137
142
  if (resolved.descrField) fields.push(resolved.descrField);
138
- if (mode === "filter") fields.push(...resolved.attrFields);
139
143
  return [...new Set(fields)];
140
144
  }
141
145
  /** Storage kinds the server matches text against (`$regex`): strings and whole numbers. */
@@ -46,9 +46,14 @@ interface ValueHelpResult {
46
46
  */
47
47
  declare function setValueHelpCacheTtl(ms: number): void;
48
48
  /**
49
- * Drop shared value-help search results — for one `client`, or for every
50
- * client when omitted. Call after writing to a dictionary outside the
51
- * built-in table actions to make pickers refetch at once.
49
+ * The dictionaries' data changed: drop shared value-help search results — for
50
+ * one `client`, or for every client when omitted — and (since 0.1.207) mark
51
+ * the texts of codes read from them stale: a code keeps its text until it is
52
+ * read again (one batched request), then the new text replaces it. The
53
+ * labels the bindings resolved stay (they are metadata); a dictionary whose
54
+ * `/meta` failed is asked again. Mounted views read their texts again, and a
55
+ * distinct-values pager its first page (since 0.1.208). Call after writing to
56
+ * a dictionary outside the built-in table actions.
52
57
  */
53
58
  declare function invalidateValueHelpCache(client?: ClientLike): void;
54
59
  /**
@@ -57,8 +62,8 @@ declare function invalidateValueHelpCache(client?: ClientLike): void;
57
62
  * $select scoping).
58
63
  *
59
64
  * Consumers resolve the target's metadata once via `resolveValueHelp(url)`
60
- * and pass the resulting `ResolvedValueHelp` to `search()`. Label resolution
61
- * for cells is deliberately unsupported — cells always display raw ids.
65
+ * and pass the resulting `ResolvedValueHelp` to `search()`. A binding's
66
+ * `valueHelpSource` searches through it and fills the texts of its codes.
62
67
  *
63
68
  * Identical searches on the same `Client` are shared (see
64
69
  * {@link setValueHelpCacheTtl}).
@@ -46,9 +46,14 @@ interface ValueHelpResult {
46
46
  */
47
47
  declare function setValueHelpCacheTtl(ms: number): void;
48
48
  /**
49
- * Drop shared value-help search results — for one `client`, or for every
50
- * client when omitted. Call after writing to a dictionary outside the
51
- * built-in table actions to make pickers refetch at once.
49
+ * The dictionaries' data changed: drop shared value-help search results — for
50
+ * one `client`, or for every client when omitted — and (since 0.1.207) mark
51
+ * the texts of codes read from them stale: a code keeps its text until it is
52
+ * read again (one batched request), then the new text replaces it. The
53
+ * labels the bindings resolved stay (they are metadata); a dictionary whose
54
+ * `/meta` failed is asked again. Mounted views read their texts again, and a
55
+ * distinct-values pager its first page (since 0.1.208). Call after writing to
56
+ * a dictionary outside the built-in table actions.
52
57
  */
53
58
  declare function invalidateValueHelpCache(client?: ClientLike): void;
54
59
  /**
@@ -57,8 +62,8 @@ declare function invalidateValueHelpCache(client?: ClientLike): void;
57
62
  * $select scoping).
58
63
  *
59
64
  * Consumers resolve the target's metadata once via `resolveValueHelp(url)`
60
- * and pass the resulting `ResolvedValueHelp` to `search()`. Label resolution
61
- * for cells is deliberately unsupported — cells always display raw ids.
65
+ * and pass the resulting `ResolvedValueHelp` to `search()`. A binding's
66
+ * `valueHelpSource` searches through it and fills the texts of its codes.
62
67
  *
63
68
  * Identical searches on the same `Client` are shared (see
64
69
  * {@link setValueHelpCacheTtl}).
@@ -1,9 +1,12 @@
1
+ import { valueHelpDictPaths } from "./dict-paths.mjs";
2
+ import { mergeFilters } from "../shared/merge-filters.mjs";
1
3
  import { escapeRegex } from "../shared/str.mjs";
2
4
  import { inferValueKind } from "../table/create-table-def.mjs";
3
5
  import { coerceNumericText } from "../table/value-kind.mjs";
6
+ import { clientStore, now } from "./client-store.mjs";
7
+ import { staleValueHelpTexts } from "./texts.mjs";
4
8
  //#region src/value-help/value-help-client.ts
5
9
  let cacheTtl = 5e3;
6
- let searches = /* @__PURE__ */ new WeakMap();
7
10
  /**
8
11
  * How long (ms) a settled value-help search is reused for an identical
9
12
  * search on the same client. Default 5000. `0` shares only searches still in
@@ -14,16 +17,17 @@ function setValueHelpCacheTtl(ms) {
14
17
  cacheTtl = ms;
15
18
  }
16
19
  /**
17
- * Drop shared value-help search results — for one `client`, or for every
18
- * client when omitted. Call after writing to a dictionary outside the
19
- * built-in table actions to make pickers refetch at once.
20
+ * The dictionaries' data changed: drop shared value-help search results — for
21
+ * one `client`, or for every client when omitted — and (since 0.1.207) mark
22
+ * the texts of codes read from them stale: a code keeps its text until it is
23
+ * read again (one batched request), then the new text replaces it. The
24
+ * labels the bindings resolved stay (they are metadata); a dictionary whose
25
+ * `/meta` failed is asked again. Mounted views read their texts again, and a
26
+ * distinct-values pager its first page (since 0.1.208). Call after writing to
27
+ * a dictionary outside the built-in table actions.
20
28
  */
21
29
  function invalidateValueHelpCache(client) {
22
- if (client) searches.get(client)?.clear();
23
- else searches = /* @__PURE__ */ new WeakMap();
24
- }
25
- function now() {
26
- return typeof performance === "undefined" ? Date.now() : performance.now();
30
+ staleValueHelpTexts(client);
27
31
  }
28
32
  /** Cache key of a plain-JSON request; `undefined` when it holds anything else (never shared). */
29
33
  function requestKey(request) {
@@ -47,8 +51,7 @@ function sharedQuery(client, request) {
47
51
  if (cacheTtl < 0 || typeof window === "undefined") return run();
48
52
  const key = requestKey(request);
49
53
  if (key === void 0) return run();
50
- let byKey = searches.get(client);
51
- if (!byKey) searches.set(client, byKey = /* @__PURE__ */ new Map());
54
+ const byKey = clientStore(client).searches;
52
55
  const hit = byKey.get(key);
53
56
  if (hit && (hit.settledAt === void 0 || now() - hit.settledAt < cacheTtl)) return hit.promise;
54
57
  const entry = { promise: run().then((items) => {
@@ -67,8 +70,8 @@ function sharedQuery(client, request) {
67
70
  * $select scoping).
68
71
  *
69
72
  * Consumers resolve the target's metadata once via `resolveValueHelp(url)`
70
- * and pass the resulting `ResolvedValueHelp` to `search()`. Label resolution
71
- * for cells is deliberately unsupported — cells always display raw ids.
73
+ * and pass the resulting `ResolvedValueHelp` to `search()`. A binding's
74
+ * `valueHelpSource` searches through it and fills the texts of its codes.
72
75
  *
73
76
  * Identical searches on the same `Client` are shared (see
74
77
  * {@link setValueHelpCacheTtl}).
@@ -104,7 +107,7 @@ var ValueHelpClient = class {
104
107
  const keyField = valueField ?? resolved.primaryKeys[0] ?? resolved.labelField;
105
108
  const search = buildOrFilter(text, computeSelectFields(resolved, mode, valueField), keyField, resolved.targetType);
106
109
  if (!search) return { items: [] };
107
- filter = scope ? { $and: [scope, search] } : search;
110
+ filter = mergeFilters(scope, search);
108
111
  }
109
112
  const items = await sharedQuery(this._client, {
110
113
  ...filter && { filter },
@@ -128,14 +131,15 @@ function valueHelpSelect(resolved, info, mode = "form", valueField = info?.targe
128
131
  return [...new Set(fields)];
129
132
  }
130
133
  /**
131
- * The dictionary's own fields of a value-help query — always including the
132
- * `valueField` the picker commits (a unique non-PK field is otherwise never fetched).
134
+ * The dictionary's own fields of a value-help query: in `"filter"` mode its
135
+ * dictionary view (`valueHelpDictPaths`), in `"form"` mode its keys, label and
136
+ * description — always including the `valueField` the picker commits (a
137
+ * unique non-PK field is otherwise never fetched).
133
138
  */
134
139
  function computeSelectFields(resolved, mode, valueField) {
135
- const fields = [...resolved.primaryKeys, resolved.labelField];
140
+ const fields = mode === "filter" ? [...valueHelpDictPaths(resolved)] : [...resolved.primaryKeys, resolved.labelField];
136
141
  if (valueField) fields.push(valueField);
137
142
  if (resolved.descrField) fields.push(resolved.descrField);
138
- if (mode === "filter") fields.push(...resolved.attrFields);
139
143
  return [...new Set(fields)];
140
144
  }
141
145
  /** Storage kinds the server matches text against (`$regex`): strings and whole numbers. */