@atscript/ui 0.1.205 → 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.
Files changed (73) hide show
  1. package/dist/form/create-form-def.cjs +40 -58
  2. package/dist/form/create-form-def.d.cts +9 -0
  3. package/dist/form/create-form-def.d.mts +9 -0
  4. package/dist/form/create-form-def.mjs +39 -57
  5. package/dist/form/db-column.cjs +37 -0
  6. package/dist/form/db-column.mjs +35 -0
  7. package/dist/form/path-utils.cjs +20 -5
  8. package/dist/form/path-utils.d.cts +8 -1
  9. package/dist/form/path-utils.d.mts +8 -1
  10. package/dist/form/path-utils.mjs +20 -6
  11. package/dist/form/types.d.cts +1 -0
  12. package/dist/form/types.d.mts +1 -0
  13. package/dist/index.cjs +18 -3
  14. package/dist/index.d.cts +8 -5
  15. package/dist/index.d.mts +8 -5
  16. package/dist/index.mjs +11 -8
  17. package/dist/plugin/annotations.cjs +33 -14
  18. package/dist/plugin/annotations.mjs +34 -15
  19. package/dist/plugin/value-help-validation.cjs +26 -6
  20. package/dist/plugin/value-help-validation.mjs +26 -7
  21. package/dist/shared/annotation-keys.cjs +3 -0
  22. package/dist/shared/annotation-keys.mjs +3 -1
  23. package/dist/shared/meta-cache.cjs +5 -4
  24. package/dist/shared/meta-cache.d.cts +3 -2
  25. package/dist/shared/meta-cache.d.mts +3 -2
  26. package/dist/shared/meta-cache.mjs +5 -4
  27. package/dist/shared/value-label.cjs +14 -2
  28. package/dist/shared/value-label.d.cts +23 -6
  29. package/dist/shared/value-label.d.mts +23 -6
  30. package/dist/shared/value-label.mjs +14 -3
  31. package/dist/table/create-table-def.cjs +7 -1
  32. package/dist/table/create-table-def.mjs +7 -2
  33. package/dist/table/types.d.cts +1 -1
  34. package/dist/table/types.d.mts +1 -1
  35. package/dist/value-help/client-store.cjs +43 -0
  36. package/dist/value-help/client-store.d.mts +1 -0
  37. package/dist/value-help/client-store.mjs +40 -0
  38. package/dist/value-help/display-value.cjs +30 -0
  39. package/dist/value-help/display-value.d.cts +45 -0
  40. package/dist/value-help/display-value.d.mts +45 -0
  41. package/dist/value-help/display-value.mjs +30 -0
  42. package/dist/value-help/extract-ref.cjs +15 -4
  43. package/dist/value-help/extract-ref.d.cts +6 -1
  44. package/dist/value-help/extract-ref.d.mts +6 -1
  45. package/dist/value-help/extract-ref.mjs +16 -6
  46. package/dist/value-help/index.d.mts +6 -3
  47. package/dist/value-help/options.cjs +49 -8
  48. package/dist/value-help/options.d.cts +41 -4
  49. package/dist/value-help/options.d.mts +41 -4
  50. package/dist/value-help/options.mjs +47 -9
  51. package/dist/value-help/resolve-options.cjs +9 -7
  52. package/dist/value-help/resolve-options.d.cts +8 -9
  53. package/dist/value-help/resolve-options.d.mts +8 -9
  54. package/dist/value-help/resolve-options.mjs +9 -7
  55. package/dist/value-help/resolve.cjs +39 -8
  56. package/dist/value-help/resolve.d.cts +22 -5
  57. package/dist/value-help/resolve.d.mts +22 -5
  58. package/dist/value-help/resolve.mjs +40 -9
  59. package/dist/value-help/source.cjs +72 -0
  60. package/dist/value-help/source.d.cts +55 -0
  61. package/dist/value-help/source.d.mts +55 -0
  62. package/dist/value-help/source.mjs +71 -0
  63. package/dist/value-help/texts.cjs +315 -0
  64. package/dist/value-help/texts.d.cts +53 -0
  65. package/dist/value-help/texts.d.mts +53 -0
  66. package/dist/value-help/texts.mjs +310 -0
  67. package/dist/value-help/types.d.cts +10 -0
  68. package/dist/value-help/types.d.mts +10 -0
  69. package/dist/value-help/value-help-client.cjs +21 -19
  70. package/dist/value-help/value-help-client.d.cts +9 -5
  71. package/dist/value-help/value-help-client.d.mts +9 -5
  72. package/dist/value-help/value-help-client.mjs +19 -17
  73. package/package.json +10 -10
@@ -0,0 +1,40 @@
1
+ //#region src/value-help/client-store.ts
2
+ let stores = /* @__PURE__ */ new WeakMap();
3
+ /** Data drops of every client so far. */
4
+ let drops = 0;
5
+ /**
6
+ * The store of `client`, created on first use — and again after a data drop,
7
+ * keeping the texts of the store it replaces (one back) as `stale`.
8
+ */
9
+ function clientStore(client) {
10
+ const prev = stores.get(client);
11
+ if (prev?.drop === drops) return prev;
12
+ for (const texts of prev?.texts.values() ?? []) texts.stale = void 0;
13
+ const store = {
14
+ client,
15
+ drop: drops,
16
+ searches: /* @__PURE__ */ new Map(),
17
+ texts: /* @__PURE__ */ new Map(),
18
+ stale: prev?.texts
19
+ };
20
+ stores.set(client, store);
21
+ return store;
22
+ }
23
+ /** The data of `client`, or of every client, changed: its store is replaced on its next use. */
24
+ function staleClientStores(client) {
25
+ if (!client) drops++;
26
+ else {
27
+ const store = stores.get(client);
28
+ if (store) store.drop = -1;
29
+ }
30
+ }
31
+ /** Drop every client's store, stale texts too (`resetMetaCache`: another viewer). */
32
+ function dropClientStores() {
33
+ stores = /* @__PURE__ */ new WeakMap();
34
+ }
35
+ /** A monotonic clock (ms) where there is one. */
36
+ function now() {
37
+ return typeof performance === "undefined" ? Date.now() : performance.now();
38
+ }
39
+ //#endregion
40
+ export { clientStore, dropClientStores, now, staleClientStores };
@@ -0,0 +1,30 @@
1
+ const require_ui_texts = require("../i18n/ui-texts.cjs");
2
+ const require_resolve_options = require("./resolve-options.cjs");
3
+ const require_value_label = require("../shared/value-label.cjs");
4
+ //#region src/value-help/display-value.ts
5
+ /**
6
+ * The words a value shows as (since 0.1.207) — the one rule behind the table
7
+ * cells, the filter chips, the export and the read-only form fields, in this
8
+ * order:
9
+ *
10
+ * 1. the label of its option (`optionLabel`: `@ui.literalLabel`, a form
11
+ * field's own options);
12
+ * 2. `Yes` / `No` for a boolean;
13
+ * 3. a code (`codeOf`) with its text, arranged (`arrangeText`): its
14
+ * `@ui.valueLabel` sibling's (`opts.siblingText`), else its dictionary's
15
+ * (`opts.valueText`).
16
+ *
17
+ * `undefined` when none applies: the value shows as itself.
18
+ */
19
+ function displayValue(holder, value, opts = {}) {
20
+ if (value === null || value === void 0) return void 0;
21
+ const option = require_resolve_options.optionLabel(holder, value);
22
+ if (option !== void 0) return option;
23
+ if (typeof value === "boolean") return (opts.t ?? require_ui_texts.getUiTexts().t)(value ? "UI_YES" : "UI_NO");
24
+ const code = require_value_label.codeOf(value);
25
+ if (code === void 0) return void 0;
26
+ const found = opts.siblingText ?? opts.valueText?.();
27
+ return found && require_value_label.arrangeText(opts.keyText ?? code, found.text, found.arrangement);
28
+ }
29
+ //#endregion
30
+ exports.displayValue = displayValue;
@@ -0,0 +1,45 @@
1
+ import { ValueLabelArrangement, ValueText } from "../shared/value-label.cjs";
2
+ import { TFormEntryOptions } from "./types.cjs";
3
+ import { UiT } from "../i18n/ui-texts.cjs";
4
+
5
+ //#region src/value-help/display-value.d.ts
6
+ /** What {@link displayValue} reads besides the value. Since 0.1.207. */
7
+ interface DisplayValueOptions {
8
+ /** The code as the caller writes it (a cell's number in its locale). Default: the code itself. */
9
+ keyText?: string;
10
+ /**
11
+ * The text of the value's `@ui.valueLabel` sibling, read from its row, with
12
+ * the annotation's arrangement. Set for a field that declares one: it wins
13
+ * over the dictionary — also when empty, then the code shows alone.
14
+ */
15
+ siblingText?: {
16
+ text: unknown;
17
+ arrangement: ValueLabelArrangement;
18
+ };
19
+ /**
20
+ * The dictionary text of the code (`valueHelpText`). Called only when
21
+ * nothing before it applies, so a value an option labels sends no lookup.
22
+ */
23
+ valueText?: () => ValueText | undefined;
24
+ /** Words booleans (`UI_YES` / `UI_NO`). Default: the active UI texts. */
25
+ t?: UiT;
26
+ }
27
+ /**
28
+ * The words a value shows as (since 0.1.207) — the one rule behind the table
29
+ * cells, the filter chips, the export and the read-only form fields, in this
30
+ * order:
31
+ *
32
+ * 1. the label of its option (`optionLabel`: `@ui.literalLabel`, a form
33
+ * field's own options);
34
+ * 2. `Yes` / `No` for a boolean;
35
+ * 3. a code (`codeOf`) with its text, arranged (`arrangeText`): its
36
+ * `@ui.valueLabel` sibling's (`opts.siblingText`), else its dictionary's
37
+ * (`opts.valueText`).
38
+ *
39
+ * `undefined` when none applies: the value shows as itself.
40
+ */
41
+ declare function displayValue(holder: {
42
+ options?: readonly TFormEntryOptions[];
43
+ }, value: unknown, opts?: DisplayValueOptions): string | undefined;
44
+ //#endregion
45
+ export { DisplayValueOptions, displayValue };
@@ -0,0 +1,45 @@
1
+ import { ValueLabelArrangement, ValueText } from "../shared/value-label.mjs";
2
+ import { TFormEntryOptions } from "./types.mjs";
3
+ import { UiT } from "../i18n/ui-texts.mjs";
4
+
5
+ //#region src/value-help/display-value.d.ts
6
+ /** What {@link displayValue} reads besides the value. Since 0.1.207. */
7
+ interface DisplayValueOptions {
8
+ /** The code as the caller writes it (a cell's number in its locale). Default: the code itself. */
9
+ keyText?: string;
10
+ /**
11
+ * The text of the value's `@ui.valueLabel` sibling, read from its row, with
12
+ * the annotation's arrangement. Set for a field that declares one: it wins
13
+ * over the dictionary — also when empty, then the code shows alone.
14
+ */
15
+ siblingText?: {
16
+ text: unknown;
17
+ arrangement: ValueLabelArrangement;
18
+ };
19
+ /**
20
+ * The dictionary text of the code (`valueHelpText`). Called only when
21
+ * nothing before it applies, so a value an option labels sends no lookup.
22
+ */
23
+ valueText?: () => ValueText | undefined;
24
+ /** Words booleans (`UI_YES` / `UI_NO`). Default: the active UI texts. */
25
+ t?: UiT;
26
+ }
27
+ /**
28
+ * The words a value shows as (since 0.1.207) — the one rule behind the table
29
+ * cells, the filter chips, the export and the read-only form fields, in this
30
+ * order:
31
+ *
32
+ * 1. the label of its option (`optionLabel`: `@ui.literalLabel`, a form
33
+ * field's own options);
34
+ * 2. `Yes` / `No` for a boolean;
35
+ * 3. a code (`codeOf`) with its text, arranged (`arrangeText`): its
36
+ * `@ui.valueLabel` sibling's (`opts.siblingText`), else its dictionary's
37
+ * (`opts.valueText`).
38
+ *
39
+ * `undefined` when none applies: the value shows as itself.
40
+ */
41
+ declare function displayValue(holder: {
42
+ options?: readonly TFormEntryOptions[];
43
+ }, value: unknown, opts?: DisplayValueOptions): string | undefined;
44
+ //#endregion
45
+ export { DisplayValueOptions, displayValue };
@@ -0,0 +1,30 @@
1
+ import { getUiTexts } from "../i18n/ui-texts.mjs";
2
+ import { optionLabel } from "./resolve-options.mjs";
3
+ import { arrangeText, codeOf } from "../shared/value-label.mjs";
4
+ //#region src/value-help/display-value.ts
5
+ /**
6
+ * The words a value shows as (since 0.1.207) — the one rule behind the table
7
+ * cells, the filter chips, the export and the read-only form fields, in this
8
+ * order:
9
+ *
10
+ * 1. the label of its option (`optionLabel`: `@ui.literalLabel`, a form
11
+ * field's own options);
12
+ * 2. `Yes` / `No` for a boolean;
13
+ * 3. a code (`codeOf`) with its text, arranged (`arrangeText`): its
14
+ * `@ui.valueLabel` sibling's (`opts.siblingText`), else its dictionary's
15
+ * (`opts.valueText`).
16
+ *
17
+ * `undefined` when none applies: the value shows as itself.
18
+ */
19
+ function displayValue(holder, value, opts = {}) {
20
+ if (value === null || value === void 0) return void 0;
21
+ const option = optionLabel(holder, value);
22
+ if (option !== void 0) return option;
23
+ if (typeof value === "boolean") return (opts.t ?? getUiTexts().t)(value ? "UI_YES" : "UI_NO");
24
+ const code = codeOf(value);
25
+ if (code === void 0) return void 0;
26
+ const found = opts.siblingText ?? opts.valueText?.();
27
+ return found && arrangeText(opts.keyText ?? code, found.text, found.arrangement);
28
+ }
29
+ //#endregion
30
+ export { displayValue };
@@ -49,14 +49,17 @@ function bindingInfo(node) {
49
49
  return info;
50
50
  }
51
51
  /**
52
- * Adds a link's `@ui.valueHelp.column` list and — on the prop itself only
53
- * (`own`) — its `@ui.valueHelp.fill` list to `info` (since 0.1.190). A link
54
- * reached through a reference names fields of ANOTHER interface, so its fills
55
- * stay there; its columns name the target, so they come along.
52
+ * Adds a link's `@ui.valueHelp.column` list and `@ui.valueHelp.label` (since
53
+ * 0.1.207) and — on the prop itself only (`own`) — its `@ui.valueHelp.fill`
54
+ * list to `info` (since 0.1.190). A link reached through a reference names
55
+ * fields of ANOTHER interface, so its fills stay there; its columns and label
56
+ * name the target, so they come along.
56
57
  */
57
58
  function withExtras(info, node, own) {
58
59
  const columns = node.metadata.get(require_annotation_keys.UI_VALUE_HELP_COLUMN);
59
60
  if (columns && columns.length > 0) info.columns = [...columns];
61
+ const label = node.metadata.get(require_annotation_keys.UI_VALUE_HELP_LABEL);
62
+ if (label?.field) info.label = { ...label };
60
63
  const fills = own ? node.metadata.get(require_annotation_keys.UI_VALUE_HELP_FILL) : void 0;
61
64
  if (fills && fills.length > 0) info.fill = fills.map((f) => ({
62
65
  local: f.local,
@@ -113,6 +116,13 @@ function extractValueHelp(prop) {
113
116
  node = (target.type.kind === "object" ? target.type : void 0)?.props.get(ref.field);
114
117
  }
115
118
  }
119
+ /**
120
+ * The identity of a binding's dictionary and committed field (`url` and
121
+ * `targetField`) — what caches and per-binding state are keyed by. Since 0.1.207.
122
+ */
123
+ function valueHelpKey(info) {
124
+ return `${info.url}\0${info.targetField}`;
125
+ }
116
126
  /** Field types that still pick from the value help: the picker, a dropdown or radio group of the dictionary. */
117
127
  const PICKER_TYPES = new Set([
118
128
  "ref",
@@ -151,3 +161,4 @@ function isForeignKey(prop) {
151
161
  exports.extractValueHelp = extractValueHelp;
152
162
  exports.isForeignKey = isForeignKey;
153
163
  exports.isValueHelpPicker = isValueHelpPicker;
164
+ exports.valueHelpKey = valueHelpKey;
@@ -33,5 +33,10 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
33
33
  * resolved the chain).
34
34
  */
35
35
  declare function extractValueHelp(prop: TAtscriptAnnotatedType): ValueHelpInfo | undefined;
36
+ /**
37
+ * The identity of a binding's dictionary and committed field (`url` and
38
+ * `targetField`) — what caches and per-binding state are keyed by. Since 0.1.207.
39
+ */
40
+ declare function valueHelpKey(info: Pick<ValueHelpInfo, "url" | "targetField">): string;
36
41
  //#endregion
37
- export { extractValueHelp };
42
+ export { extractValueHelp, valueHelpKey };
@@ -33,5 +33,10 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
33
33
  * resolved the chain).
34
34
  */
35
35
  declare function extractValueHelp(prop: TAtscriptAnnotatedType): ValueHelpInfo | undefined;
36
+ /**
37
+ * The identity of a binding's dictionary and committed field (`url` and
38
+ * `targetField`) — what caches and per-binding state are keyed by. Since 0.1.207.
39
+ */
40
+ declare function valueHelpKey(info: Pick<ValueHelpInfo, "url" | "targetField">): string;
36
41
  //#endregion
37
- export { extractValueHelp };
42
+ export { extractValueHelp, valueHelpKey };
@@ -1,4 +1,4 @@
1
- import { DB_HTTP_PATH, UI_VALUE_HELP, UI_VALUE_HELP_COLUMN, UI_VALUE_HELP_FILL } from "../shared/annotation-keys.mjs";
1
+ import { DB_HTTP_PATH, UI_VALUE_HELP, UI_VALUE_HELP_COLUMN, UI_VALUE_HELP_FILL, UI_VALUE_HELP_LABEL } from "../shared/annotation-keys.mjs";
2
2
  import { valueHelpFilter } from "./filter-tree.mjs";
3
3
  //#region src/value-help/extract-ref.ts
4
4
  /**
@@ -49,14 +49,17 @@ function bindingInfo(node) {
49
49
  return info;
50
50
  }
51
51
  /**
52
- * Adds a link's `@ui.valueHelp.column` list and — on the prop itself only
53
- * (`own`) — its `@ui.valueHelp.fill` list to `info` (since 0.1.190). A link
54
- * reached through a reference names fields of ANOTHER interface, so its fills
55
- * stay there; its columns name the target, so they come along.
52
+ * Adds a link's `@ui.valueHelp.column` list and `@ui.valueHelp.label` (since
53
+ * 0.1.207) and — on the prop itself only (`own`) — its `@ui.valueHelp.fill`
54
+ * list to `info` (since 0.1.190). A link reached through a reference names
55
+ * fields of ANOTHER interface, so its fills stay there; its columns and label
56
+ * name the target, so they come along.
56
57
  */
57
58
  function withExtras(info, node, own) {
58
59
  const columns = node.metadata.get(UI_VALUE_HELP_COLUMN);
59
60
  if (columns && columns.length > 0) info.columns = [...columns];
61
+ const label = node.metadata.get(UI_VALUE_HELP_LABEL);
62
+ if (label?.field) info.label = { ...label };
60
63
  const fills = own ? node.metadata.get(UI_VALUE_HELP_FILL) : void 0;
61
64
  if (fills && fills.length > 0) info.fill = fills.map((f) => ({
62
65
  local: f.local,
@@ -113,6 +116,13 @@ function extractValueHelp(prop) {
113
116
  node = (target.type.kind === "object" ? target.type : void 0)?.props.get(ref.field);
114
117
  }
115
118
  }
119
+ /**
120
+ * The identity of a binding's dictionary and committed field (`url` and
121
+ * `targetField`) — what caches and per-binding state are keyed by. Since 0.1.207.
122
+ */
123
+ function valueHelpKey(info) {
124
+ return `${info.url}\0${info.targetField}`;
125
+ }
116
126
  /** Field types that still pick from the value help: the picker, a dropdown or radio group of the dictionary. */
117
127
  const PICKER_TYPES = new Set([
118
128
  "ref",
@@ -148,4 +158,4 @@ function isForeignKey(prop) {
148
158
  return false;
149
159
  }
150
160
  //#endregion
151
- export { extractValueHelp, isForeignKey, isValueHelpPicker };
161
+ export { extractValueHelp, isForeignKey, isValueHelpPicker, valueHelpKey };
@@ -1,10 +1,13 @@
1
1
  import { TFormEntryOptions, ValueHelpInfo } from "./types.mjs";
2
+ import { ValueHelpSource, ValueHelpSourceOptions, valueHelpColumns, valueHelpSource } from "./source.mjs";
2
3
  import { ResolvedValueHelp, resetValueHelpCache, resolveValueHelp } from "./resolve.mjs";
3
4
  import { ValueHelpClient, ValueHelpResult, ValueHelpSearchOptions, invalidateValueHelpCache, setValueHelpCacheTtl, valueHelpSelect } from "./value-help-client.mjs";
4
5
  import { valueHelpDictPaths } from "./dict-paths.mjs";
5
6
  import { DEFAULT_BOOLEAN_LABELS, extractFieldLiteralOptions, extractLiteralOptions, isPureLiteralUnion } from "./extract-literals.mjs";
6
- import { extractValueHelp } from "./extract-ref.mjs";
7
+ import { extractValueHelp, valueHelpKey } from "./extract-ref.mjs";
7
8
  import { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions } from "./resolve-options.mjs";
8
9
  import { ValueHelpFillWrite, ValueHelpScope, valueHelpFills, valueHelpScope } from "./scope.mjs";
9
- import { VALUE_HELP_OPTIONS_CAP, valueHelpOptions } from "./options.mjs";
10
- import { fetchDistinctValues, isPickerDeclined } from "./distinct-client.mjs";
10
+ import { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText } from "./options.mjs";
11
+ import { fetchDistinctValues, isPickerDeclined } from "./distinct-client.mjs";
12
+ import { ValueHelpTextOptions, loadValueHelpTexts, onValueHelpTexts, valueHelpText } from "./texts.mjs";
13
+ import { DisplayValueOptions, displayValue } from "./display-value.mjs";
@@ -1,3 +1,7 @@
1
+ require("../shared/annotation-keys.cjs");
2
+ const require_field_resolver = require("../shared/field-resolver.cjs");
3
+ const require_extract_literals = require("./extract-literals.cjs");
4
+ const require_value_label = require("../shared/value-label.cjs");
1
5
  //#region src/value-help/options.ts
2
6
  /**
3
7
  * Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
@@ -7,24 +11,61 @@
7
11
  */
8
12
  const VALUE_HELP_OPTIONS_CAP = 200;
9
13
  /**
14
+ * A dictionary row's text as a picker shows it (since 0.1.207): its label
15
+ * field's (`ResolvedValueHelp.labelField`) and its description, each a
16
+ * non-empty text or `undefined`. The one reader of a row's text — the
17
+ * reference field's list, the dropdown options and the texts of codes.
18
+ */
19
+ function valueHelpRowText(resolved, row) {
20
+ return {
21
+ label: require_value_label.codeOf(row[resolved.labelField]),
22
+ descr: resolved.descrField ? require_value_label.codeOf(row[resolved.descrField]) : void 0
23
+ };
24
+ }
25
+ /**
10
26
  * Dictionary rows as dropdown options (since 0.1.190): the committed
11
- * `targetField` value as the option's value, the label field's text (the key
12
- * when it has none) and the description after a dash.
27
+ * `targetField` value as the option's value, the row's text
28
+ * (`valueHelpRowText`; the key when it has none) and the description after a
29
+ * dash.
13
30
  */
14
31
  function valueHelpOptions(rows, resolved, info) {
15
32
  return rows.map((row) => {
16
33
  const value = row[info.targetField];
17
- const key = String(value);
18
- const label = row[resolved.labelField];
19
- const descr = resolved.descrField ? row[resolved.descrField] : void 0;
20
- const text = label === void 0 || label === null || label === "" ? key : String(label);
34
+ const { label, descr } = valueHelpRowText(resolved, row);
35
+ const text = label ?? String(value);
21
36
  return {
22
- key,
23
- label: descr ? `${text} — ${String(descr)}` : text,
37
+ key: String(value),
38
+ label: descr ? `${text} — ${descr}` : text,
24
39
  value
25
40
  };
26
41
  });
27
42
  }
43
+ /**
44
+ * The options of a dropdown that lists its dictionary (`listsDictionary`;
45
+ * since 0.1.207) from a read of `VALUE_HELP_OPTIONS_CAP + 1` rows in the
46
+ * binding's scope (`ValueHelpSource.search`, in a form with the host values):
47
+ * the rows as options (`valueHelpOptions`), or `undefined` when there are more
48
+ * than the cap — the field then keeps its search picker.
49
+ */
50
+ function valueHelpDropdown(rows, resolved, info) {
51
+ return rows.length > 200 ? void 0 : valueHelpOptions(rows, resolved, info);
52
+ }
53
+ /**
54
+ * Whether a form field or a column lists its dictionary's values as its
55
+ * options (since 0.1.207): bound to a dictionary (`valueHelpInfo`), typed
56
+ * `select` or `radio`, and with no options of its own — a form field none
57
+ * declared on its `prop` (`@ui.form.options`, `@ui.form.fn.options`, a
58
+ * literal union), a column none in `options`.
59
+ */
60
+ function listsDictionary(holder) {
61
+ if (!holder.valueHelpInfo || holder.type !== "select" && holder.type !== "radio") return false;
62
+ const prop = holder.prop;
63
+ if (!prop) return !holder.options?.length;
64
+ return !require_field_resolver.hasFieldMeta(prop, "ui.form.options") && !require_field_resolver.hasFieldMeta(prop, "ui.form.fn.options") && require_extract_literals.extractFieldLiteralOptions(prop) === void 0;
65
+ }
28
66
  //#endregion
29
67
  exports.VALUE_HELP_OPTIONS_CAP = VALUE_HELP_OPTIONS_CAP;
68
+ exports.listsDictionary = listsDictionary;
69
+ exports.valueHelpDropdown = valueHelpDropdown;
30
70
  exports.valueHelpOptions = valueHelpOptions;
71
+ exports.valueHelpRowText = valueHelpRowText;
@@ -1,7 +1,9 @@
1
1
  import { TFormEntryOptions, ValueHelpInfo } from "./types.cjs";
2
2
  import { ResolvedValueHelp } from "./resolve.cjs";
3
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
4
 
4
5
  //#region src/value-help/options.d.ts
6
+ type Row = Record<string, unknown>;
5
7
  /**
6
8
  * Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
7
9
  * `@ui.type 'select'` on a bound field, since 0.1.190). A read asks for one
@@ -9,11 +11,46 @@ import { ResolvedValueHelp } from "./resolve.cjs";
9
11
  * keeps its search picker.
10
12
  */
11
13
  declare const VALUE_HELP_OPTIONS_CAP = 200;
14
+ /**
15
+ * A dictionary row's text as a picker shows it (since 0.1.207): its label
16
+ * field's (`ResolvedValueHelp.labelField`) and its description, each a
17
+ * non-empty text or `undefined`. The one reader of a row's text — the
18
+ * reference field's list, the dropdown options and the texts of codes.
19
+ */
20
+ declare function valueHelpRowText(resolved: {
21
+ labelField: string;
22
+ descrField?: string;
23
+ }, row: Row): {
24
+ label?: string;
25
+ descr?: string;
26
+ };
12
27
  /**
13
28
  * Dictionary rows as dropdown options (since 0.1.190): the committed
14
- * `targetField` value as the option's value, the label field's text (the key
15
- * when it has none) and the description after a dash.
29
+ * `targetField` value as the option's value, the row's text
30
+ * (`valueHelpRowText`; the key when it has none) and the description after a
31
+ * dash.
32
+ */
33
+ declare function valueHelpOptions(rows: Row[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[];
34
+ /**
35
+ * The options of a dropdown that lists its dictionary (`listsDictionary`;
36
+ * since 0.1.207) from a read of `VALUE_HELP_OPTIONS_CAP + 1` rows in the
37
+ * binding's scope (`ValueHelpSource.search`, in a form with the host values):
38
+ * the rows as options (`valueHelpOptions`), or `undefined` when there are more
39
+ * than the cap — the field then keeps its search picker.
40
+ */
41
+ declare function valueHelpDropdown(rows: Row[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[] | undefined;
42
+ /**
43
+ * Whether a form field or a column lists its dictionary's values as its
44
+ * options (since 0.1.207): bound to a dictionary (`valueHelpInfo`), typed
45
+ * `select` or `radio`, and with no options of its own — a form field none
46
+ * declared on its `prop` (`@ui.form.options`, `@ui.form.fn.options`, a
47
+ * literal union), a column none in `options`.
16
48
  */
17
- declare function valueHelpOptions(rows: Record<string, unknown>[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[];
49
+ declare function listsDictionary(holder: {
50
+ valueHelpInfo?: ValueHelpInfo;
51
+ type: string;
52
+ prop?: TAtscriptAnnotatedType;
53
+ options?: readonly unknown[];
54
+ }): boolean;
18
55
  //#endregion
19
- export { VALUE_HELP_OPTIONS_CAP, valueHelpOptions };
56
+ export { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText };
@@ -1,7 +1,9 @@
1
1
  import { TFormEntryOptions, ValueHelpInfo } from "./types.mjs";
2
2
  import { ResolvedValueHelp } from "./resolve.mjs";
3
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
4
 
4
5
  //#region src/value-help/options.d.ts
6
+ type Row = Record<string, unknown>;
5
7
  /**
6
8
  * Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
7
9
  * `@ui.type 'select'` on a bound field, since 0.1.190). A read asks for one
@@ -9,11 +11,46 @@ import { ResolvedValueHelp } from "./resolve.mjs";
9
11
  * keeps its search picker.
10
12
  */
11
13
  declare const VALUE_HELP_OPTIONS_CAP = 200;
14
+ /**
15
+ * A dictionary row's text as a picker shows it (since 0.1.207): its label
16
+ * field's (`ResolvedValueHelp.labelField`) and its description, each a
17
+ * non-empty text or `undefined`. The one reader of a row's text — the
18
+ * reference field's list, the dropdown options and the texts of codes.
19
+ */
20
+ declare function valueHelpRowText(resolved: {
21
+ labelField: string;
22
+ descrField?: string;
23
+ }, row: Row): {
24
+ label?: string;
25
+ descr?: string;
26
+ };
12
27
  /**
13
28
  * Dictionary rows as dropdown options (since 0.1.190): the committed
14
- * `targetField` value as the option's value, the label field's text (the key
15
- * when it has none) and the description after a dash.
29
+ * `targetField` value as the option's value, the row's text
30
+ * (`valueHelpRowText`; the key when it has none) and the description after a
31
+ * dash.
32
+ */
33
+ declare function valueHelpOptions(rows: Row[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[];
34
+ /**
35
+ * The options of a dropdown that lists its dictionary (`listsDictionary`;
36
+ * since 0.1.207) from a read of `VALUE_HELP_OPTIONS_CAP + 1` rows in the
37
+ * binding's scope (`ValueHelpSource.search`, in a form with the host values):
38
+ * the rows as options (`valueHelpOptions`), or `undefined` when there are more
39
+ * than the cap — the field then keeps its search picker.
40
+ */
41
+ declare function valueHelpDropdown(rows: Row[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[] | undefined;
42
+ /**
43
+ * Whether a form field or a column lists its dictionary's values as its
44
+ * options (since 0.1.207): bound to a dictionary (`valueHelpInfo`), typed
45
+ * `select` or `radio`, and with no options of its own — a form field none
46
+ * declared on its `prop` (`@ui.form.options`, `@ui.form.fn.options`, a
47
+ * literal union), a column none in `options`.
16
48
  */
17
- declare function valueHelpOptions(rows: Record<string, unknown>[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[];
49
+ declare function listsDictionary(holder: {
50
+ valueHelpInfo?: ValueHelpInfo;
51
+ type: string;
52
+ prop?: TAtscriptAnnotatedType;
53
+ options?: readonly unknown[];
54
+ }): boolean;
18
55
  //#endregion
19
- export { VALUE_HELP_OPTIONS_CAP, valueHelpOptions };
56
+ export { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText };
@@ -1,3 +1,7 @@
1
+ import "../shared/annotation-keys.mjs";
2
+ import { hasFieldMeta } from "../shared/field-resolver.mjs";
3
+ import { extractFieldLiteralOptions } from "./extract-literals.mjs";
4
+ import { codeOf } from "../shared/value-label.mjs";
1
5
  //#region src/value-help/options.ts
2
6
  /**
3
7
  * Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
@@ -7,23 +11,57 @@
7
11
  */
8
12
  const VALUE_HELP_OPTIONS_CAP = 200;
9
13
  /**
14
+ * A dictionary row's text as a picker shows it (since 0.1.207): its label
15
+ * field's (`ResolvedValueHelp.labelField`) and its description, each a
16
+ * non-empty text or `undefined`. The one reader of a row's text — the
17
+ * reference field's list, the dropdown options and the texts of codes.
18
+ */
19
+ function valueHelpRowText(resolved, row) {
20
+ return {
21
+ label: codeOf(row[resolved.labelField]),
22
+ descr: resolved.descrField ? codeOf(row[resolved.descrField]) : void 0
23
+ };
24
+ }
25
+ /**
10
26
  * Dictionary rows as dropdown options (since 0.1.190): the committed
11
- * `targetField` value as the option's value, the label field's text (the key
12
- * when it has none) and the description after a dash.
27
+ * `targetField` value as the option's value, the row's text
28
+ * (`valueHelpRowText`; the key when it has none) and the description after a
29
+ * dash.
13
30
  */
14
31
  function valueHelpOptions(rows, resolved, info) {
15
32
  return rows.map((row) => {
16
33
  const value = row[info.targetField];
17
- const key = String(value);
18
- const label = row[resolved.labelField];
19
- const descr = resolved.descrField ? row[resolved.descrField] : void 0;
20
- const text = label === void 0 || label === null || label === "" ? key : String(label);
34
+ const { label, descr } = valueHelpRowText(resolved, row);
35
+ const text = label ?? String(value);
21
36
  return {
22
- key,
23
- label: descr ? `${text} — ${String(descr)}` : text,
37
+ key: String(value),
38
+ label: descr ? `${text} — ${descr}` : text,
24
39
  value
25
40
  };
26
41
  });
27
42
  }
43
+ /**
44
+ * The options of a dropdown that lists its dictionary (`listsDictionary`;
45
+ * since 0.1.207) from a read of `VALUE_HELP_OPTIONS_CAP + 1` rows in the
46
+ * binding's scope (`ValueHelpSource.search`, in a form with the host values):
47
+ * the rows as options (`valueHelpOptions`), or `undefined` when there are more
48
+ * than the cap — the field then keeps its search picker.
49
+ */
50
+ function valueHelpDropdown(rows, resolved, info) {
51
+ return rows.length > 200 ? void 0 : valueHelpOptions(rows, resolved, info);
52
+ }
53
+ /**
54
+ * Whether a form field or a column lists its dictionary's values as its
55
+ * options (since 0.1.207): bound to a dictionary (`valueHelpInfo`), typed
56
+ * `select` or `radio`, and with no options of its own — a form field none
57
+ * declared on its `prop` (`@ui.form.options`, `@ui.form.fn.options`, a
58
+ * literal union), a column none in `options`.
59
+ */
60
+ function listsDictionary(holder) {
61
+ if (!holder.valueHelpInfo || holder.type !== "select" && holder.type !== "radio") return false;
62
+ const prop = holder.prop;
63
+ if (!prop) return !holder.options?.length;
64
+ return !hasFieldMeta(prop, "ui.form.options") && !hasFieldMeta(prop, "ui.form.fn.options") && extractFieldLiteralOptions(prop) === void 0;
65
+ }
28
66
  //#endregion
29
- export { VALUE_HELP_OPTIONS_CAP, valueHelpOptions };
67
+ export { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText };
@@ -13,19 +13,21 @@ function optLabel(opt) {
13
13
  }
14
14
  const labelMaps = /* @__PURE__ */ new WeakMap();
15
15
  /**
16
- * The display label of a literal-union (or boolean) column's option (`@ui.literalLabel`) for
17
- * `value` — `undefined` when the column has no options or none matches. Map-backed
18
- * per options array, so rendering a table does not scan the options per cell.
19
- * The one lookup behind the table cell, the filter chips, export and a custom cell.
16
+ * The display label of the option holding `value` (`@ui.literalLabel`) — of a
17
+ * literal-union (or boolean) column, or of a form field's options (since
18
+ * 0.1.207; a plain string option is its own label). `undefined` when there
19
+ * are no options or none matches. Map-backed per options array, so rendering
20
+ * a table does not scan the options per cell. The one lookup behind the table
21
+ * cell, the filter chips, export, read-only form fields and a custom cell.
20
22
  * Since 0.1.148.
21
23
  */
22
- function optionLabel(column, value) {
23
- const options = column.options;
24
+ function optionLabel(holder, value) {
25
+ const options = holder.options;
24
26
  if (!options?.length) return void 0;
25
27
  if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") return;
26
28
  let labels = labelMaps.get(options);
27
29
  if (!labels) {
28
- labels = new Map(options.map((o) => [o.key, o.label]));
30
+ labels = new Map(options.map((o) => [optKey(o), optLabel(o)]));
29
31
  labelMaps.set(options, labels);
30
32
  }
31
33
  return labels.get(String(value));