@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
@@ -1,7 +1,10 @@
1
1
  import { TFormEntryOptions, ValueHelpInfo } from "./types.cjs";
2
+ import { ColumnDef } from "../table/types.cjs";
2
3
  import { ResolvedValueHelp } from "./resolve.cjs";
4
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
5
 
4
6
  //#region src/value-help/options.d.ts
7
+ type Row = Record<string, unknown>;
5
8
  /**
6
9
  * Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
7
10
  * `@ui.type 'select'` on a bound field, since 0.1.190). A read asks for one
@@ -9,11 +12,61 @@ import { ResolvedValueHelp } from "./resolve.cjs";
9
12
  * keeps its search picker.
10
13
  */
11
14
  declare const VALUE_HELP_OPTIONS_CAP = 200;
15
+ /**
16
+ * A dictionary row's text as a picker shows it (since 0.1.207): its label
17
+ * field's (`ResolvedValueHelp.labelField`) and its description, each a
18
+ * non-empty text or `undefined`. The one reader of a row's text — the
19
+ * reference field's list, the dropdown options and the texts of codes.
20
+ */
21
+ declare function valueHelpRowText(resolved: {
22
+ labelField: string;
23
+ descrField?: string;
24
+ }, row: Row): {
25
+ label?: string;
26
+ descr?: string;
27
+ };
12
28
  /**
13
29
  * 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.
30
+ * `targetField` value as the option's value, the row's text
31
+ * (`valueHelpRowText`; the key when it has none) and the description after a
32
+ * dash.
33
+ */
34
+ declare function valueHelpOptions(rows: Row[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[];
35
+ /**
36
+ * The options of a dropdown that lists its dictionary (`listsDictionary`;
37
+ * since 0.1.207) from a read of `VALUE_HELP_OPTIONS_CAP + 1` rows in the
38
+ * binding's scope (`ValueHelpSource.search`, in a form with the host values):
39
+ * the rows as options (`valueHelpOptions`), or `undefined` when there are more
40
+ * than the cap — the field then keeps its search picker.
41
+ */
42
+ declare function valueHelpDropdown(rows: Row[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[] | undefined;
43
+ /**
44
+ * Whether a form field or a column lists its dictionary's values as its
45
+ * options (since 0.1.207): bound to a dictionary (`valueHelpInfo`), typed
46
+ * `select` or `radio`, and with no options of its own — a form field none
47
+ * declared on its `prop` (`@ui.form.options`, `@ui.form.fn.options`, a
48
+ * literal union), a column none in `options`.
49
+ */
50
+ declare function listsDictionary(holder: {
51
+ valueHelpInfo?: ValueHelpInfo;
52
+ type: string;
53
+ prop?: TAtscriptAnnotatedType;
54
+ options?: readonly unknown[];
55
+ }): boolean;
56
+ /** The picker a column's value filter offers — see {@link valuePickerMode}. */
57
+ type ValuePickerMode = "dictionary" | "options" | "distinct";
58
+ /**
59
+ * The picker a column's value filter offers (since 0.1.208) — the one rule of
60
+ * the inline filter field, the filter dialog and a custom filter:
61
+ * `"dictionary"` (a `@ui.valueHelp` binding or a foreign key, unless its
62
+ * {@link valueHelpKey} is in `declined` — the server answered 4xx), else
63
+ * `"options"` (a literal union, a boolean's Yes / No, a dictionary's values
64
+ * loaded as options), else `"distinct"` (`@ui.valueHelp.distinct`);
65
+ * `undefined` — no picker: the column takes typed conditions. Only a column
66
+ * the server filters by value with `$eq` (what a pick sends; several picks are
67
+ * an `$or` of them) has one: an existence-only (JSON-stored) column takes the
68
+ * empty / not-empty conditions instead.
16
69
  */
17
- declare function valueHelpOptions(rows: Record<string, unknown>[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[];
70
+ declare function valuePickerMode(column: Pick<ColumnDef, "filterable" | "filterOps" | "valueHelpInfo" | "options" | "distinct">, declined?: ReadonlySet<string>): ValuePickerMode | undefined;
18
71
  //#endregion
19
- export { VALUE_HELP_OPTIONS_CAP, valueHelpOptions };
72
+ export { VALUE_HELP_OPTIONS_CAP, ValuePickerMode, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText, valuePickerMode };
@@ -1,7 +1,10 @@
1
1
  import { TFormEntryOptions, ValueHelpInfo } from "./types.mjs";
2
+ import { ColumnDef } from "../table/types.mjs";
2
3
  import { ResolvedValueHelp } from "./resolve.mjs";
4
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
5
 
4
6
  //#region src/value-help/options.d.ts
7
+ type Row = Record<string, unknown>;
5
8
  /**
6
9
  * Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
7
10
  * `@ui.type 'select'` on a bound field, since 0.1.190). A read asks for one
@@ -9,11 +12,61 @@ import { ResolvedValueHelp } from "./resolve.mjs";
9
12
  * keeps its search picker.
10
13
  */
11
14
  declare const VALUE_HELP_OPTIONS_CAP = 200;
15
+ /**
16
+ * A dictionary row's text as a picker shows it (since 0.1.207): its label
17
+ * field's (`ResolvedValueHelp.labelField`) and its description, each a
18
+ * non-empty text or `undefined`. The one reader of a row's text — the
19
+ * reference field's list, the dropdown options and the texts of codes.
20
+ */
21
+ declare function valueHelpRowText(resolved: {
22
+ labelField: string;
23
+ descrField?: string;
24
+ }, row: Row): {
25
+ label?: string;
26
+ descr?: string;
27
+ };
12
28
  /**
13
29
  * 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.
30
+ * `targetField` value as the option's value, the row's text
31
+ * (`valueHelpRowText`; the key when it has none) and the description after a
32
+ * dash.
33
+ */
34
+ declare function valueHelpOptions(rows: Row[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[];
35
+ /**
36
+ * The options of a dropdown that lists its dictionary (`listsDictionary`;
37
+ * since 0.1.207) from a read of `VALUE_HELP_OPTIONS_CAP + 1` rows in the
38
+ * binding's scope (`ValueHelpSource.search`, in a form with the host values):
39
+ * the rows as options (`valueHelpOptions`), or `undefined` when there are more
40
+ * than the cap — the field then keeps its search picker.
41
+ */
42
+ declare function valueHelpDropdown(rows: Row[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[] | undefined;
43
+ /**
44
+ * Whether a form field or a column lists its dictionary's values as its
45
+ * options (since 0.1.207): bound to a dictionary (`valueHelpInfo`), typed
46
+ * `select` or `radio`, and with no options of its own — a form field none
47
+ * declared on its `prop` (`@ui.form.options`, `@ui.form.fn.options`, a
48
+ * literal union), a column none in `options`.
49
+ */
50
+ declare function listsDictionary(holder: {
51
+ valueHelpInfo?: ValueHelpInfo;
52
+ type: string;
53
+ prop?: TAtscriptAnnotatedType;
54
+ options?: readonly unknown[];
55
+ }): boolean;
56
+ /** The picker a column's value filter offers — see {@link valuePickerMode}. */
57
+ type ValuePickerMode = "dictionary" | "options" | "distinct";
58
+ /**
59
+ * The picker a column's value filter offers (since 0.1.208) — the one rule of
60
+ * the inline filter field, the filter dialog and a custom filter:
61
+ * `"dictionary"` (a `@ui.valueHelp` binding or a foreign key, unless its
62
+ * {@link valueHelpKey} is in `declined` — the server answered 4xx), else
63
+ * `"options"` (a literal union, a boolean's Yes / No, a dictionary's values
64
+ * loaded as options), else `"distinct"` (`@ui.valueHelp.distinct`);
65
+ * `undefined` — no picker: the column takes typed conditions. Only a column
66
+ * the server filters by value with `$eq` (what a pick sends; several picks are
67
+ * an `$or` of them) has one: an existence-only (JSON-stored) column takes the
68
+ * empty / not-empty conditions instead.
16
69
  */
17
- declare function valueHelpOptions(rows: Record<string, unknown>[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[];
70
+ declare function valuePickerMode(column: Pick<ColumnDef, "filterable" | "filterOps" | "valueHelpInfo" | "options" | "distinct">, declined?: ReadonlySet<string>): ValuePickerMode | undefined;
18
71
  //#endregion
19
- export { VALUE_HELP_OPTIONS_CAP, valueHelpOptions };
72
+ export { VALUE_HELP_OPTIONS_CAP, ValuePickerMode, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText, valuePickerMode };
@@ -1,3 +1,8 @@
1
+ import "../shared/annotation-keys.mjs";
2
+ import { hasFieldMeta } from "../shared/field-resolver.mjs";
3
+ import { extractFieldLiteralOptions } from "./extract-literals.mjs";
4
+ import { valueHelpKey } from "./extract-ref.mjs";
5
+ import { codeOf } from "../shared/value-label.mjs";
1
6
  //#region src/value-help/options.ts
2
7
  /**
3
8
  * Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
@@ -7,23 +12,76 @@
7
12
  */
8
13
  const VALUE_HELP_OPTIONS_CAP = 200;
9
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
+ function valueHelpRowText(resolved, row) {
21
+ return {
22
+ label: codeOf(row[resolved.labelField]),
23
+ descr: resolved.descrField ? codeOf(row[resolved.descrField]) : void 0
24
+ };
25
+ }
26
+ /**
10
27
  * 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.
28
+ * `targetField` value as the option's value, the row's text
29
+ * (`valueHelpRowText`; the key when it has none) and the description after a
30
+ * dash.
13
31
  */
14
32
  function valueHelpOptions(rows, resolved, info) {
15
33
  return rows.map((row) => {
16
34
  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);
35
+ const { label, descr } = valueHelpRowText(resolved, row);
36
+ const text = label ?? String(value);
21
37
  return {
22
- key,
23
- label: descr ? `${text} — ${String(descr)}` : text,
38
+ key: String(value),
39
+ label: descr ? `${text} — ${descr}` : text,
24
40
  value
25
41
  };
26
42
  });
27
43
  }
44
+ /**
45
+ * The options of a dropdown that lists its dictionary (`listsDictionary`;
46
+ * since 0.1.207) from a read of `VALUE_HELP_OPTIONS_CAP + 1` rows in the
47
+ * binding's scope (`ValueHelpSource.search`, in a form with the host values):
48
+ * the rows as options (`valueHelpOptions`), or `undefined` when there are more
49
+ * than the cap — the field then keeps its search picker.
50
+ */
51
+ function valueHelpDropdown(rows, resolved, info) {
52
+ return rows.length > 200 ? void 0 : valueHelpOptions(rows, resolved, info);
53
+ }
54
+ /**
55
+ * Whether a form field or a column lists its dictionary's values as its
56
+ * options (since 0.1.207): bound to a dictionary (`valueHelpInfo`), typed
57
+ * `select` or `radio`, and with no options of its own — a form field none
58
+ * declared on its `prop` (`@ui.form.options`, `@ui.form.fn.options`, a
59
+ * literal union), a column none in `options`.
60
+ */
61
+ function listsDictionary(holder) {
62
+ if (!holder.valueHelpInfo || holder.type !== "select" && holder.type !== "radio") return false;
63
+ const prop = holder.prop;
64
+ if (!prop) return !holder.options?.length;
65
+ return !hasFieldMeta(prop, "ui.form.options") && !hasFieldMeta(prop, "ui.form.fn.options") && extractFieldLiteralOptions(prop) === void 0;
66
+ }
67
+ /**
68
+ * The picker a column's value filter offers (since 0.1.208) — the one rule of
69
+ * the inline filter field, the filter dialog and a custom filter:
70
+ * `"dictionary"` (a `@ui.valueHelp` binding or a foreign key, unless its
71
+ * {@link valueHelpKey} is in `declined` — the server answered 4xx), else
72
+ * `"options"` (a literal union, a boolean's Yes / No, a dictionary's values
73
+ * loaded as options), else `"distinct"` (`@ui.valueHelp.distinct`);
74
+ * `undefined` — no picker: the column takes typed conditions. Only a column
75
+ * the server filters by value with `$eq` (what a pick sends; several picks are
76
+ * an `$or` of them) has one: an existence-only (JSON-stored) column takes the
77
+ * empty / not-empty conditions instead.
78
+ */
79
+ function valuePickerMode(column, declined) {
80
+ if (!column.filterable || column.filterOps && !column.filterOps.includes("$eq")) return;
81
+ const info = column.valueHelpInfo;
82
+ if (info && !declined?.has(valueHelpKey(info))) return "dictionary";
83
+ if (column.options?.length) return "options";
84
+ if (column.distinct) return "distinct";
85
+ }
28
86
  //#endregion
29
- export { VALUE_HELP_OPTIONS_CAP, valueHelpOptions };
87
+ export { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText, valuePickerMode };
@@ -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));
@@ -9,17 +9,16 @@ declare function optKey(opt: TFormEntryOptions): string;
9
9
  /** Extracts the display label from an option entry. */
10
10
  declare function optLabel(opt: TFormEntryOptions): string;
11
11
  /**
12
- * The display label of a literal-union (or boolean) column's option (`@ui.literalLabel`) for
13
- * `value` — `undefined` when the column has no options or none matches. Map-backed
14
- * per options array, so rendering a table does not scan the options per cell.
15
- * The one lookup behind the table cell, the filter chips, export and a custom cell.
12
+ * The display label of the option holding `value` (`@ui.literalLabel`) — of a
13
+ * literal-union (or boolean) column, or of a form field's options (since
14
+ * 0.1.207; a plain string option is its own label). `undefined` when there
15
+ * are no options or none matches. Map-backed per options array, so rendering
16
+ * a table does not scan the options per cell. The one lookup behind the table
17
+ * cell, the filter chips, export, read-only form fields and a custom cell.
16
18
  * Since 0.1.148.
17
19
  */
18
- declare function optionLabel(column: {
19
- options?: {
20
- key: string;
21
- label: string;
22
- }[];
20
+ declare function optionLabel(holder: {
21
+ options?: readonly TFormEntryOptions[];
23
22
  }, value: unknown): string | undefined;
24
23
  /**
25
24
  * Converts raw option annotation value to a normalized array. `t` translates
@@ -9,17 +9,16 @@ declare function optKey(opt: TFormEntryOptions): string;
9
9
  /** Extracts the display label from an option entry. */
10
10
  declare function optLabel(opt: TFormEntryOptions): string;
11
11
  /**
12
- * The display label of a literal-union (or boolean) column's option (`@ui.literalLabel`) for
13
- * `value` — `undefined` when the column has no options or none matches. Map-backed
14
- * per options array, so rendering a table does not scan the options per cell.
15
- * The one lookup behind the table cell, the filter chips, export and a custom cell.
12
+ * The display label of the option holding `value` (`@ui.literalLabel`) — of a
13
+ * literal-union (or boolean) column, or of a form field's options (since
14
+ * 0.1.207; a plain string option is its own label). `undefined` when there
15
+ * are no options or none matches. Map-backed per options array, so rendering
16
+ * a table does not scan the options per cell. The one lookup behind the table
17
+ * cell, the filter chips, export, read-only form fields and a custom cell.
16
18
  * Since 0.1.148.
17
19
  */
18
- declare function optionLabel(column: {
19
- options?: {
20
- key: string;
21
- label: string;
22
- }[];
20
+ declare function optionLabel(holder: {
21
+ options?: readonly TFormEntryOptions[];
23
22
  }, value: unknown): string | undefined;
24
23
  /**
25
24
  * Converts raw option annotation value to a normalized array. `t` translates
@@ -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));
@@ -1,6 +1,9 @@
1
1
  const require_annotation_keys = require("../shared/annotation-keys.cjs");
2
+ const require_create_table_def = require("../table/create-table-def.cjs");
2
3
  const require_meta_cache = require("../shared/meta-cache.cjs");
3
4
  //#region src/value-help/resolve.ts
5
+ /** Per meta-cache entry: the dictionary resolved for each binding's label. */
6
+ const byBinding = /* @__PURE__ */ new WeakMap();
4
7
  /**
5
8
  * Lazily fetch and extract value-help metadata for the given URL.
6
9
  *
@@ -14,13 +17,32 @@ const require_meta_cache = require("../shared/meta-cache.cjs");
14
17
  * by default. `options.clientFactory` — the factory the host (a form's or a
15
18
  * table's `clientFactory`) builds its clients with: it seeds the client when
16
19
  * this call creates the entry for the URL and locale (default: the app-wide
17
- * one). Since 0.1.168.
20
+ * one). Since 0.1.168. `options.info` — the binding resolved for: its
21
+ * `@ui.valueHelp.label` becomes the `label` and the `labelField`, resolved
22
+ * once per entry and label (since 0.1.207).
18
23
  */
19
24
  function resolveValueHelp(url, options) {
20
25
  const entry = require_meta_cache.getMetaEntry(url, options?.clientFactory, { texts: options?.texts });
21
- if (entry.resolved) return entry.resolved;
22
- entry.resolved = Promise.all([entry.meta, entry.type]).then(([meta, type]) => buildResolved(url, meta, type));
23
- return entry.resolved;
26
+ entry.resolved ??= Promise.all([entry.meta, entry.type]).then(([meta, type]) => buildResolved(url, meta, type));
27
+ const own = options?.info?.label;
28
+ if (!own) return entry.resolved;
29
+ let bindings = byBinding.get(entry);
30
+ if (!bindings) byBinding.set(entry, bindings = /* @__PURE__ */ new Map());
31
+ const id = `${own.field}\0${own.arrangement ?? ""}`;
32
+ let resolved = bindings.get(id);
33
+ if (!resolved) {
34
+ resolved = Promise.all([entry.meta, entry.resolved]).then(([meta, base]) => {
35
+ if (!base.targetType.type.props?.has(own.field)) return base;
36
+ const label = require_create_table_def.readableLabel(meta, own.field, own.arrangement ?? base.label?.arrangement);
37
+ return label ? {
38
+ ...base,
39
+ label,
40
+ labelField: label.field
41
+ } : base;
42
+ });
43
+ bindings.set(id, resolved);
44
+ }
45
+ return resolved;
24
46
  }
25
47
  /** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
26
48
  function resetValueHelpCache() {
@@ -30,7 +52,7 @@ function buildResolved(url, meta, targetType) {
30
52
  const objectType = targetType.type.kind === "object" ? targetType.type : void 0;
31
53
  const versionColumn = meta.versionColumn;
32
54
  const primaryKeys = [];
33
- let labelField;
55
+ const label = require_create_table_def.dictLabelOf(meta, targetType);
34
56
  let descrField;
35
57
  const attrFields = [];
36
58
  let firstStringField;
@@ -38,13 +60,11 @@ function buildResolved(url, meta, targetType) {
38
60
  if (name === versionColumn) continue;
39
61
  const isPK = fieldProp.metadata.has(require_annotation_keys.META_ID);
40
62
  if (isPK) primaryKeys.push(name);
41
- if (fieldProp.metadata.has("ui.dict.label")) labelField = name;
42
63
  if (fieldProp.metadata.has("ui.dict.descr")) descrField = name;
43
64
  if (fieldProp.metadata.has("ui.dict.attr")) attrFields.push(name);
44
65
  if (!firstStringField && !isPK && fieldProp.type.kind === "" && fieldProp.type.designType === "string") firstStringField = name;
45
66
  }
46
- if (!labelField) labelField = firstStringField;
47
- if (!labelField) labelField = primaryKeys[0] ?? "id";
67
+ const labelField = label?.field ?? firstStringField ?? primaryKeys[0] ?? "id";
48
68
  const filterableFields = [];
49
69
  const sortableFields = [];
50
70
  if (meta.fields) for (const [name, fm] of Object.entries(meta.fields)) {
@@ -55,6 +75,7 @@ function buildResolved(url, meta, targetType) {
55
75
  return {
56
76
  url,
57
77
  primaryKeys,
78
+ ...label && { label },
58
79
  labelField,
59
80
  descrField,
60
81
  attrFields,
@@ -1,5 +1,6 @@
1
- import { ClientFactory } from "../client-factory.cjs";
2
- import { MetaEntryOptions } from "../shared/meta-cache.cjs";
1
+ import { ValueLabel } from "../shared/value-label.cjs";
2
+ import { ValueHelpInfo } from "./types.cjs";
3
+ import { ValueHelpSourceOptions } from "./source.cjs";
3
4
  import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
4
5
 
5
6
  //#region src/value-help/resolve.d.ts
@@ -10,6 +11,20 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
10
11
  interface ResolvedValueHelp {
11
12
  url: string;
12
13
  primaryKeys: string[];
14
+ /**
15
+ * The declared label of the codes bound to this dictionary: the binding's
16
+ * `@ui.valueHelp.label` (when resolved with its `info`), else the
17
+ * dictionary's `@ui.dict.label` — with its arrangement. A binding's label
18
+ * the caller cannot read (not in the served type, not listed in `/meta`
19
+ * `fields`, or write-only) counts as absent: the dictionary's applies.
20
+ * `undefined` when neither is declared and readable. Codes show its text
21
+ * only when it is set (`valueHelpText`). Since 0.1.207.
22
+ */
23
+ label?: ValueLabel;
24
+ /**
25
+ * The field a picker shows as each row's text: `label.field`, else the
26
+ * first string field that is not a key, else the key.
27
+ */
13
28
  labelField: string;
14
29
  descrField: string | undefined;
15
30
  attrFields: string[];
@@ -31,10 +46,12 @@ interface ResolvedValueHelp {
31
46
  * by default. `options.clientFactory` — the factory the host (a form's or a
32
47
  * table's `clientFactory`) builds its clients with: it seeds the client when
33
48
  * this call creates the entry for the URL and locale (default: the app-wide
34
- * one). Since 0.1.168.
49
+ * one). Since 0.1.168. `options.info` — the binding resolved for: its
50
+ * `@ui.valueHelp.label` becomes the `label` and the `labelField`, resolved
51
+ * once per entry and label (since 0.1.207).
35
52
  */
36
- declare function resolveValueHelp(url: string, options?: Pick<MetaEntryOptions, "texts"> & {
37
- clientFactory?: ClientFactory;
53
+ declare function resolveValueHelp(url: string, options?: ValueHelpSourceOptions & {
54
+ info?: Pick<ValueHelpInfo, "label">;
38
55
  }): Promise<ResolvedValueHelp>;
39
56
  /** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
40
57
  declare function resetValueHelpCache(): void;
@@ -1,5 +1,6 @@
1
- import { ClientFactory } from "../client-factory.mjs";
2
- import { MetaEntryOptions } from "../shared/meta-cache.mjs";
1
+ import { ValueLabel } from "../shared/value-label.mjs";
2
+ import { ValueHelpInfo } from "./types.mjs";
3
+ import { ValueHelpSourceOptions } from "./source.mjs";
3
4
  import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
4
5
 
5
6
  //#region src/value-help/resolve.d.ts
@@ -10,6 +11,20 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
10
11
  interface ResolvedValueHelp {
11
12
  url: string;
12
13
  primaryKeys: string[];
14
+ /**
15
+ * The declared label of the codes bound to this dictionary: the binding's
16
+ * `@ui.valueHelp.label` (when resolved with its `info`), else the
17
+ * dictionary's `@ui.dict.label` — with its arrangement. A binding's label
18
+ * the caller cannot read (not in the served type, not listed in `/meta`
19
+ * `fields`, or write-only) counts as absent: the dictionary's applies.
20
+ * `undefined` when neither is declared and readable. Codes show its text
21
+ * only when it is set (`valueHelpText`). Since 0.1.207.
22
+ */
23
+ label?: ValueLabel;
24
+ /**
25
+ * The field a picker shows as each row's text: `label.field`, else the
26
+ * first string field that is not a key, else the key.
27
+ */
13
28
  labelField: string;
14
29
  descrField: string | undefined;
15
30
  attrFields: string[];
@@ -31,10 +46,12 @@ interface ResolvedValueHelp {
31
46
  * by default. `options.clientFactory` — the factory the host (a form's or a
32
47
  * table's `clientFactory`) builds its clients with: it seeds the client when
33
48
  * this call creates the entry for the URL and locale (default: the app-wide
34
- * one). Since 0.1.168.
49
+ * one). Since 0.1.168. `options.info` — the binding resolved for: its
50
+ * `@ui.valueHelp.label` becomes the `label` and the `labelField`, resolved
51
+ * once per entry and label (since 0.1.207).
35
52
  */
36
- declare function resolveValueHelp(url: string, options?: Pick<MetaEntryOptions, "texts"> & {
37
- clientFactory?: ClientFactory;
53
+ declare function resolveValueHelp(url: string, options?: ValueHelpSourceOptions & {
54
+ info?: Pick<ValueHelpInfo, "label">;
38
55
  }): Promise<ResolvedValueHelp>;
39
56
  /** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
40
57
  declare function resetValueHelpCache(): void;
@@ -1,6 +1,9 @@
1
1
  import { META_ID } from "../shared/annotation-keys.mjs";
2
+ import { dictLabelOf, readableLabel } from "../table/create-table-def.mjs";
2
3
  import { getMetaEntry, resetMetaCache } from "../shared/meta-cache.mjs";
3
4
  //#region src/value-help/resolve.ts
5
+ /** Per meta-cache entry: the dictionary resolved for each binding's label. */
6
+ const byBinding = /* @__PURE__ */ new WeakMap();
4
7
  /**
5
8
  * Lazily fetch and extract value-help metadata for the given URL.
6
9
  *
@@ -14,13 +17,32 @@ import { getMetaEntry, resetMetaCache } from "../shared/meta-cache.mjs";
14
17
  * by default. `options.clientFactory` — the factory the host (a form's or a
15
18
  * table's `clientFactory`) builds its clients with: it seeds the client when
16
19
  * this call creates the entry for the URL and locale (default: the app-wide
17
- * one). Since 0.1.168.
20
+ * one). Since 0.1.168. `options.info` — the binding resolved for: its
21
+ * `@ui.valueHelp.label` becomes the `label` and the `labelField`, resolved
22
+ * once per entry and label (since 0.1.207).
18
23
  */
19
24
  function resolveValueHelp(url, options) {
20
25
  const entry = getMetaEntry(url, options?.clientFactory, { texts: options?.texts });
21
- if (entry.resolved) return entry.resolved;
22
- entry.resolved = Promise.all([entry.meta, entry.type]).then(([meta, type]) => buildResolved(url, meta, type));
23
- return entry.resolved;
26
+ entry.resolved ??= Promise.all([entry.meta, entry.type]).then(([meta, type]) => buildResolved(url, meta, type));
27
+ const own = options?.info?.label;
28
+ if (!own) return entry.resolved;
29
+ let bindings = byBinding.get(entry);
30
+ if (!bindings) byBinding.set(entry, bindings = /* @__PURE__ */ new Map());
31
+ const id = `${own.field}\0${own.arrangement ?? ""}`;
32
+ let resolved = bindings.get(id);
33
+ if (!resolved) {
34
+ resolved = Promise.all([entry.meta, entry.resolved]).then(([meta, base]) => {
35
+ if (!base.targetType.type.props?.has(own.field)) return base;
36
+ const label = readableLabel(meta, own.field, own.arrangement ?? base.label?.arrangement);
37
+ return label ? {
38
+ ...base,
39
+ label,
40
+ labelField: label.field
41
+ } : base;
42
+ });
43
+ bindings.set(id, resolved);
44
+ }
45
+ return resolved;
24
46
  }
25
47
  /** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
26
48
  function resetValueHelpCache() {
@@ -30,7 +52,7 @@ function buildResolved(url, meta, targetType) {
30
52
  const objectType = targetType.type.kind === "object" ? targetType.type : void 0;
31
53
  const versionColumn = meta.versionColumn;
32
54
  const primaryKeys = [];
33
- let labelField;
55
+ const label = dictLabelOf(meta, targetType);
34
56
  let descrField;
35
57
  const attrFields = [];
36
58
  let firstStringField;
@@ -38,13 +60,11 @@ function buildResolved(url, meta, targetType) {
38
60
  if (name === versionColumn) continue;
39
61
  const isPK = fieldProp.metadata.has(META_ID);
40
62
  if (isPK) primaryKeys.push(name);
41
- if (fieldProp.metadata.has("ui.dict.label")) labelField = name;
42
63
  if (fieldProp.metadata.has("ui.dict.descr")) descrField = name;
43
64
  if (fieldProp.metadata.has("ui.dict.attr")) attrFields.push(name);
44
65
  if (!firstStringField && !isPK && fieldProp.type.kind === "" && fieldProp.type.designType === "string") firstStringField = name;
45
66
  }
46
- if (!labelField) labelField = firstStringField;
47
- if (!labelField) labelField = primaryKeys[0] ?? "id";
67
+ const labelField = label?.field ?? firstStringField ?? primaryKeys[0] ?? "id";
48
68
  const filterableFields = [];
49
69
  const sortableFields = [];
50
70
  if (meta.fields) for (const [name, fm] of Object.entries(meta.fields)) {
@@ -55,6 +75,7 @@ function buildResolved(url, meta, targetType) {
55
75
  return {
56
76
  url,
57
77
  primaryKeys,
78
+ ...label && { label },
58
79
  labelField,
59
80
  descrField,
60
81
  attrFields,
@@ -1,3 +1,4 @@
1
+ const require_merge_filters = require("../shared/merge-filters.cjs");
1
2
  //#region src/value-help/scope.ts
2
3
  /**
3
4
  * A host value the picker can filter by: one scalar. Empty (`undefined`,
@@ -24,14 +25,9 @@ function valueHelpScope(info, read) {
24
25
  conditions.push({ [target]: value });
25
26
  if (!pinned.includes(target)) pinned.push(target);
26
27
  }
27
- if (conditions.length === 0) return {
28
- ...info.filter && { filter: info.filter },
29
- pinned
30
- };
31
- const base = info.filter;
32
- const all = base ? [...Array.isArray(base.$and) ? base.$and : [info.filter], ...conditions] : conditions;
28
+ const filter = require_merge_filters.mergeFilters(info.filter, ...conditions);
33
29
  return {
34
- filter: all.length === 1 ? all[0] : { $and: all },
30
+ ...filter && { filter },
35
31
  pinned
36
32
  };
37
33
  }