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