@atscript/ui 0.1.163 → 0.1.165

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 (164) hide show
  1. package/dist/client-factory.cjs +27 -0
  2. package/dist/client-factory.d.cts +58 -0
  3. package/dist/client-factory.d.mts +58 -0
  4. package/dist/client-factory.mjs +25 -0
  5. package/dist/form/apply.cjs +38 -0
  6. package/dist/form/apply.d.cts +36 -0
  7. package/dist/form/apply.d.mts +36 -0
  8. package/dist/form/apply.mjs +38 -0
  9. package/dist/form/clone.cjs +30 -0
  10. package/dist/form/clone.d.cts +23 -0
  11. package/dist/form/clone.d.mts +23 -0
  12. package/dist/form/clone.mjs +30 -0
  13. package/dist/form/create-form-def.cjs +462 -0
  14. package/dist/form/create-form-def.d.cts +67 -0
  15. package/dist/form/create-form-def.d.mts +67 -0
  16. package/dist/form/create-form-def.mjs +460 -0
  17. package/dist/form/decimal-format.cjs +324 -0
  18. package/dist/form/decimal-format.d.cts +86 -0
  19. package/dist/form/decimal-format.d.mts +86 -0
  20. package/dist/form/decimal-format.mjs +315 -0
  21. package/dist/form/diff.cjs +458 -0
  22. package/dist/form/diff.d.cts +80 -0
  23. package/dist/form/diff.d.mts +80 -0
  24. package/dist/form/diff.mjs +457 -0
  25. package/dist/form/dirty.cjs +65 -0
  26. package/dist/form/dirty.d.cts +47 -0
  27. package/dist/form/dirty.d.mts +47 -0
  28. package/dist/form/dirty.mjs +64 -0
  29. package/dist/form/error-utils.cjs +97 -0
  30. package/dist/form/error-utils.d.cts +58 -0
  31. package/dist/form/error-utils.d.mts +58 -0
  32. package/dist/form/error-utils.mjs +92 -0
  33. package/dist/form/form-actions.cjs +30 -0
  34. package/dist/form/form-actions.d.cts +17 -0
  35. package/dist/form/form-actions.d.mts +17 -0
  36. package/dist/form/form-actions.mjs +30 -0
  37. package/dist/form/grid.cjs +69 -0
  38. package/dist/form/grid.d.cts +49 -0
  39. package/dist/form/grid.d.mts +49 -0
  40. package/dist/form/grid.mjs +64 -0
  41. package/dist/form/labels.cjs +13 -0
  42. package/dist/form/labels.d.cts +11 -0
  43. package/dist/form/labels.d.mts +11 -0
  44. package/dist/form/labels.mjs +13 -0
  45. package/dist/form/measurement.cjs +20 -0
  46. package/dist/form/measurement.d.cts +29 -0
  47. package/dist/form/measurement.d.mts +29 -0
  48. package/dist/form/measurement.mjs +20 -0
  49. package/dist/form/path-utils.cjs +182 -0
  50. package/dist/form/path-utils.d.cts +47 -0
  51. package/dist/form/path-utils.d.mts +47 -0
  52. package/dist/form/path-utils.mjs +175 -0
  53. package/dist/form/rebase.cjs +89 -0
  54. package/dist/form/rebase.d.cts +61 -0
  55. package/dist/form/rebase.d.mts +61 -0
  56. package/dist/form/rebase.mjs +89 -0
  57. package/dist/form/skipped-nav.cjs +100 -0
  58. package/dist/form/skipped-nav.d.cts +13 -0
  59. package/dist/form/skipped-nav.d.mts +13 -0
  60. package/dist/form/skipped-nav.mjs +98 -0
  61. package/dist/form/types.cjs +40 -0
  62. package/dist/form/types.d.cts +147 -0
  63. package/dist/form/types.d.mts +147 -0
  64. package/dist/form/types.mjs +36 -0
  65. package/dist/form/union-detect.cjs +46 -0
  66. package/dist/form/union-detect.d.cts +22 -0
  67. package/dist/form/union-detect.d.mts +22 -0
  68. package/dist/form/union-detect.mjs +46 -0
  69. package/dist/form/validate.cjs +186 -0
  70. package/dist/form/validate.d.cts +81 -0
  71. package/dist/form/validate.d.mts +81 -0
  72. package/dist/form/validate.mjs +182 -0
  73. package/dist/i18n/ui-texts.cjs +135 -0
  74. package/dist/i18n/ui-texts.d.cts +81 -0
  75. package/dist/i18n/ui-texts.d.mts +81 -0
  76. package/dist/i18n/ui-texts.mjs +132 -0
  77. package/dist/index.cjs +223 -3360
  78. package/dist/index.d.cts +39 -1693
  79. package/dist/index.d.mts +39 -1693
  80. package/dist/index.mjs +36 -3179
  81. package/dist/messages.cjs +301 -0
  82. package/dist/messages.d.cts +302 -0
  83. package/dist/messages.d.mts +302 -0
  84. package/dist/messages.mjs +300 -0
  85. package/dist/nav/model-routes.cjs +59 -0
  86. package/dist/nav/model-routes.d.cts +33 -0
  87. package/dist/nav/model-routes.d.mts +33 -0
  88. package/dist/nav/model-routes.mjs +59 -0
  89. package/dist/plugin/annotations.cjs +592 -0
  90. package/dist/plugin/annotations.mjs +592 -0
  91. package/dist/plugin/primitives.cjs +30 -0
  92. package/dist/plugin/primitives.mjs +30 -0
  93. package/dist/plugin/value-help-validation.cjs +429 -0
  94. package/dist/plugin/value-help-validation.mjs +423 -0
  95. package/dist/plugin.cjs +4 -1001
  96. package/dist/plugin.mjs +2 -999
  97. package/dist/shared/annotation-keys.cjs +189 -0
  98. package/dist/shared/annotation-keys.d.cts +82 -0
  99. package/dist/shared/annotation-keys.d.mts +82 -0
  100. package/dist/shared/annotation-keys.mjs +97 -0
  101. package/dist/shared/field-resolver.cjs +123 -0
  102. package/dist/shared/field-resolver.d.cts +77 -0
  103. package/dist/shared/field-resolver.d.mts +77 -0
  104. package/dist/shared/field-resolver.mjs +110 -0
  105. package/dist/shared/meta-cache.cjs +282 -0
  106. package/dist/shared/meta-cache.d.cts +130 -0
  107. package/dist/shared/meta-cache.d.mts +130 -0
  108. package/dist/shared/meta-cache.mjs +275 -0
  109. package/dist/shared/str.cjs +19 -0
  110. package/dist/shared/str.d.cts +7 -0
  111. package/dist/shared/str.d.mts +7 -0
  112. package/dist/shared/str.mjs +17 -0
  113. package/dist/table/column-resolver.cjs +17 -0
  114. package/dist/table/column-resolver.d.cts +11 -0
  115. package/dist/table/column-resolver.d.mts +11 -0
  116. package/dist/table/column-resolver.mjs +15 -0
  117. package/dist/table/create-table-def.cjs +242 -0
  118. package/dist/table/create-table-def.d.cts +19 -0
  119. package/dist/table/create-table-def.d.mts +19 -0
  120. package/dist/table/create-table-def.mjs +242 -0
  121. package/dist/table/navigate-href.cjs +45 -0
  122. package/dist/table/navigate-href.d.cts +31 -0
  123. package/dist/table/navigate-href.d.mts +31 -0
  124. package/dist/table/navigate-href.mjs +45 -0
  125. package/dist/table/types.d.cts +290 -0
  126. package/dist/table/types.d.mts +290 -0
  127. package/dist/table/value-kind.cjs +20 -0
  128. package/dist/table/value-kind.d.cts +16 -0
  129. package/dist/table/value-kind.d.mts +16 -0
  130. package/dist/table/value-kind.mjs +19 -0
  131. package/dist/value-help/dict-paths.cjs +17 -0
  132. package/dist/value-help/dict-paths.d.cts +11 -0
  133. package/dist/value-help/dict-paths.d.mts +11 -0
  134. package/dist/value-help/dict-paths.mjs +17 -0
  135. package/dist/value-help/distinct-client.cjs +51 -0
  136. package/dist/value-help/distinct-client.d.cts +40 -0
  137. package/dist/value-help/distinct-client.d.mts +40 -0
  138. package/dist/value-help/distinct-client.mjs +50 -0
  139. package/dist/value-help/extract-literals.cjs +115 -0
  140. package/dist/value-help/extract-literals.d.cts +44 -0
  141. package/dist/value-help/extract-literals.d.mts +44 -0
  142. package/dist/value-help/extract-literals.mjs +111 -0
  143. package/dist/value-help/extract-ref.cjs +100 -0
  144. package/dist/value-help/extract-ref.d.cts +37 -0
  145. package/dist/value-help/extract-ref.d.mts +37 -0
  146. package/dist/value-help/extract-ref.mjs +100 -0
  147. package/dist/value-help/filter-tree.cjs +45 -0
  148. package/dist/value-help/filter-tree.mjs +45 -0
  149. package/dist/value-help/index.d.mts +8 -0
  150. package/dist/value-help/resolve-options.cjs +68 -0
  151. package/dist/value-help/resolve-options.d.cts +40 -0
  152. package/dist/value-help/resolve-options.d.mts +40 -0
  153. package/dist/value-help/resolve-options.mjs +64 -0
  154. package/dist/value-help/resolve.cjs +66 -0
  155. package/dist/value-help/resolve.d.cts +36 -0
  156. package/dist/value-help/resolve.d.mts +36 -0
  157. package/dist/value-help/resolve.mjs +65 -0
  158. package/dist/value-help/types.d.cts +41 -0
  159. package/dist/value-help/types.d.mts +41 -0
  160. package/dist/value-help/value-help-client.cjs +136 -0
  161. package/dist/value-help/value-help-client.d.cts +67 -0
  162. package/dist/value-help/value-help-client.d.mts +67 -0
  163. package/dist/value-help/value-help-client.mjs +134 -0
  164. package/package.json +15 -10
@@ -0,0 +1,37 @@
1
+ import { ValueHelpInfo } from "./types.mjs";
2
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
+
4
+ //#region src/value-help/extract-ref.d.ts
5
+ /**
6
+ * Synchronous probe. Returns `{ url, targetField }` for the first link of the
7
+ * reference chain starting at `prop` that carries a `@ui.valueHelp` binding
8
+ * (since 0.1.148 — an explicit binding beats `@db.rel.FK`, and also supplies
9
+ * the static `filter` / `pinned` fields), or that satisfies all three conditions:
10
+ *
11
+ * 1. the link carries `@db.rel.FK`,
12
+ * 2. the link has a `.ref`,
13
+ * 3. the ref's target metadata carries `@db.http.path`.
14
+ *
15
+ * Since 0.1.134 the probe follows **reference chains**: when a link does not
16
+ * qualify, it hops onto the referenced field (`ref.type()` → that object's
17
+ * `props[ref.field]`) and re-tests. A view field declared as
18
+ * `errorCode: Issue.errorCode`, where `Issue.errorCode: ErrorCode.code` is the
19
+ * link carrying `@db.rel.FK`, therefore keeps its value help instead of losing
20
+ * the dictionary.
21
+ *
22
+ * This mirrors what the server already does on the `/meta` path: since
23
+ * `@atscript/db` 0.1.128 the serialized meta collapses such chains onto the
24
+ * terminal field (`ref` → terminal, `db.rel.FK: true`), so a form def built
25
+ * from `/meta` and one built from the compiled `.as` type land on the same
26
+ * dictionary.
27
+ *
28
+ * The walk is bounded ({@link MAX_REF_CHAIN_DEPTH}), which is also what makes a
29
+ * cyclic chain terminate (it runs out of hops and gives up instead of looping).
30
+ * It stops as soon as a link has no `.ref`, or the referenced
31
+ * field cannot be found — e.g. behind a shallow `{ id, metadata }` ref target
32
+ * from `/meta`, which carries no props (and needs none: the server already
33
+ * resolved the chain).
34
+ */
35
+ declare function extractValueHelp(prop: TAtscriptAnnotatedType): ValueHelpInfo | undefined;
36
+ //#endregion
37
+ export { extractValueHelp };
@@ -0,0 +1,100 @@
1
+ import { DB_HTTP_PATH, UI_VALUE_HELP } from "../shared/annotation-keys.mjs";
2
+ import { valueHelpFilter } from "./filter-tree.mjs";
3
+ //#region src/value-help/extract-ref.ts
4
+ /**
5
+ * Hard cap on how many `.ref` hops the chain walk follows. Real chains are one
6
+ * or two hops (view field → table field → dictionary); the cap is a backstop,
7
+ * not a modelling limit — and it is also what terminates a cyclic chain.
8
+ */
9
+ const MAX_REF_CHAIN_DEPTH = 8;
10
+ /**
11
+ * `@db.http.path` of a binding target. Two producers, two shapes — `/meta`
12
+ * deserialization does not normalize annotation values, so both are read here:
13
+ *
14
+ * - compiled `.as` (the atscript runtime): the annotated type itself (a class
15
+ * with a `metadata` Map) or a getter `() => Type` for a cross-file ref;
16
+ * - `/meta` (the serialized type): a shallow target `{ id, metadata }` whose
17
+ * `metadata` is a plain record.
18
+ *
19
+ * Also accepts `{ type: () => Type }`.
20
+ */
21
+ function bindingTargetPath(target) {
22
+ if (target === null || typeof target !== "object" && typeof target !== "function") return;
23
+ const t = target;
24
+ if (typeof target === "function" && t.metadata === void 0) return bindingTargetPath(target());
25
+ if (t.metadata instanceof Map) return t.metadata.get(DB_HTTP_PATH);
26
+ if (t.metadata && typeof t.metadata === "object") return t.metadata[DB_HTTP_PATH];
27
+ return t.type === void 0 ? void 0 : bindingTargetPath(t.type);
28
+ }
29
+ /**
30
+ * The `@ui.valueHelp` binding of a node, when its target is served by a
31
+ * controller (`@db.http.path`). Without a path the binding is ignored and the
32
+ * caller falls back to the FK walk.
33
+ */
34
+ function bindingInfo(node) {
35
+ const binding = node.metadata.get(UI_VALUE_HELP);
36
+ if (!binding?.field) return void 0;
37
+ const url = bindingTargetPath(binding.target);
38
+ if (!url) return void 0;
39
+ const info = {
40
+ url,
41
+ targetField: binding.field
42
+ };
43
+ if (binding.filter) {
44
+ const { filter, pinned } = valueHelpFilter(binding.filter);
45
+ info.filter = filter;
46
+ if (pinned.length > 0) info.pinned = pinned;
47
+ }
48
+ return info;
49
+ }
50
+ /**
51
+ * Synchronous probe. Returns `{ url, targetField }` for the first link of the
52
+ * reference chain starting at `prop` that carries a `@ui.valueHelp` binding
53
+ * (since 0.1.148 — an explicit binding beats `@db.rel.FK`, and also supplies
54
+ * the static `filter` / `pinned` fields), or that satisfies all three conditions:
55
+ *
56
+ * 1. the link carries `@db.rel.FK`,
57
+ * 2. the link has a `.ref`,
58
+ * 3. the ref's target metadata carries `@db.http.path`.
59
+ *
60
+ * Since 0.1.134 the probe follows **reference chains**: when a link does not
61
+ * qualify, it hops onto the referenced field (`ref.type()` → that object's
62
+ * `props[ref.field]`) and re-tests. A view field declared as
63
+ * `errorCode: Issue.errorCode`, where `Issue.errorCode: ErrorCode.code` is the
64
+ * link carrying `@db.rel.FK`, therefore keeps its value help instead of losing
65
+ * the dictionary.
66
+ *
67
+ * This mirrors what the server already does on the `/meta` path: since
68
+ * `@atscript/db` 0.1.128 the serialized meta collapses such chains onto the
69
+ * terminal field (`ref` → terminal, `db.rel.FK: true`), so a form def built
70
+ * from `/meta` and one built from the compiled `.as` type land on the same
71
+ * dictionary.
72
+ *
73
+ * The walk is bounded ({@link MAX_REF_CHAIN_DEPTH}), which is also what makes a
74
+ * cyclic chain terminate (it runs out of hops and gives up instead of looping).
75
+ * It stops as soon as a link has no `.ref`, or the referenced
76
+ * field cannot be found — e.g. behind a shallow `{ id, metadata }` ref target
77
+ * from `/meta`, which carries no props (and needs none: the server already
78
+ * resolved the chain).
79
+ */
80
+ function extractValueHelp(prop) {
81
+ let node = prop;
82
+ for (let depth = 0; node && depth < MAX_REF_CHAIN_DEPTH; depth++) {
83
+ const bound = bindingInfo(node);
84
+ if (bound) return bound;
85
+ const ref = node.ref;
86
+ if (!ref) return void 0;
87
+ const target = ref.type();
88
+ if (!target) return void 0;
89
+ if (node.metadata.has("db.rel.FK")) {
90
+ const url = target.metadata.get(DB_HTTP_PATH);
91
+ if (url) return {
92
+ url,
93
+ targetField: ref.field
94
+ };
95
+ }
96
+ node = (target.type.kind === "object" ? target.type : void 0)?.props.get(ref.field);
97
+ }
98
+ }
99
+ //#endregion
100
+ export { extractValueHelp };
@@ -0,0 +1,45 @@
1
+ //#region src/value-help/filter-tree.ts
2
+ function isFieldRef(value) {
3
+ return value !== null && typeof value === "object" && "field" in value;
4
+ }
5
+ /**
6
+ * A deliberate copy of `translateQueryTree` from `@atscript/db`: that module is a
7
+ * server-side runtime, and importing it would pull `@atscript/db` into the browser
8
+ * bundle. `filter-tree.spec.ts` guards the two against drift.
9
+ */
10
+ function translate(node) {
11
+ if (Array.isArray(node.$and)) return { $and: node.$and.map(translate) };
12
+ if (Array.isArray(node.$or)) return { $or: node.$or.map(translate) };
13
+ if (node.$not && typeof node.$not === "object") return { $not: translate(node.$not) };
14
+ const left = node.left.field;
15
+ const op = node.op;
16
+ const right = node.right;
17
+ if (isFieldRef(right)) return { [left]: { [op]: { $field: right.field } } };
18
+ if (op === "$exists") return { [left]: { $exists: right !== false } };
19
+ return { [left]: { [op]: right } };
20
+ }
21
+ /**
22
+ * Fields the tree pins to one value (`=` comparison against a literal) at its top-level
23
+ * `and` chain. The runtime twin of `pinnedFields` in `plugin/value-help-validation.ts`
24
+ * (which reads the source predicate) — keep the two rules in step.
25
+ */
26
+ function pinnedOf(node, out) {
27
+ if (Array.isArray(node.$and)) for (const n of node.$and) pinnedOf(n, out);
28
+ else if (node.left && node.op === "$eq" && !isFieldRef(node.right)) out.push(node.left.field);
29
+ }
30
+ /**
31
+ * Translates the static `filter` of a `@ui.valueHelp` binding into a Uniquery
32
+ * `FilterExpr` (mirrors `translateQueryTree` of `@atscript/db`, with refs
33
+ * resolved to the plain field path), plus the target fields it pins with `=` —
34
+ * constant inside the picker, so their columns are hidden. Since 0.1.148.
35
+ */
36
+ function valueHelpFilter(tree) {
37
+ const pinned = [];
38
+ pinnedOf(tree, pinned);
39
+ return {
40
+ filter: translate(tree),
41
+ pinned: [...new Set(pinned)]
42
+ };
43
+ }
44
+ //#endregion
45
+ exports.valueHelpFilter = valueHelpFilter;
@@ -0,0 +1,45 @@
1
+ //#region src/value-help/filter-tree.ts
2
+ function isFieldRef(value) {
3
+ return value !== null && typeof value === "object" && "field" in value;
4
+ }
5
+ /**
6
+ * A deliberate copy of `translateQueryTree` from `@atscript/db`: that module is a
7
+ * server-side runtime, and importing it would pull `@atscript/db` into the browser
8
+ * bundle. `filter-tree.spec.ts` guards the two against drift.
9
+ */
10
+ function translate(node) {
11
+ if (Array.isArray(node.$and)) return { $and: node.$and.map(translate) };
12
+ if (Array.isArray(node.$or)) return { $or: node.$or.map(translate) };
13
+ if (node.$not && typeof node.$not === "object") return { $not: translate(node.$not) };
14
+ const left = node.left.field;
15
+ const op = node.op;
16
+ const right = node.right;
17
+ if (isFieldRef(right)) return { [left]: { [op]: { $field: right.field } } };
18
+ if (op === "$exists") return { [left]: { $exists: right !== false } };
19
+ return { [left]: { [op]: right } };
20
+ }
21
+ /**
22
+ * Fields the tree pins to one value (`=` comparison against a literal) at its top-level
23
+ * `and` chain. The runtime twin of `pinnedFields` in `plugin/value-help-validation.ts`
24
+ * (which reads the source predicate) — keep the two rules in step.
25
+ */
26
+ function pinnedOf(node, out) {
27
+ if (Array.isArray(node.$and)) for (const n of node.$and) pinnedOf(n, out);
28
+ else if (node.left && node.op === "$eq" && !isFieldRef(node.right)) out.push(node.left.field);
29
+ }
30
+ /**
31
+ * Translates the static `filter` of a `@ui.valueHelp` binding into a Uniquery
32
+ * `FilterExpr` (mirrors `translateQueryTree` of `@atscript/db`, with refs
33
+ * resolved to the plain field path), plus the target fields it pins with `=` —
34
+ * constant inside the picker, so their columns are hidden. Since 0.1.148.
35
+ */
36
+ function valueHelpFilter(tree) {
37
+ const pinned = [];
38
+ pinnedOf(tree, pinned);
39
+ return {
40
+ filter: translate(tree),
41
+ pinned: [...new Set(pinned)]
42
+ };
43
+ }
44
+ //#endregion
45
+ export { valueHelpFilter };
@@ -0,0 +1,8 @@
1
+ import { TFormEntryOptions, ValueHelpInfo } from "./types.mjs";
2
+ import { ResolvedValueHelp, resetValueHelpCache, resolveValueHelp } from "./resolve.mjs";
3
+ import { ValueHelpClient, ValueHelpResult, ValueHelpSearchOptions, invalidateValueHelpCache, setValueHelpCacheTtl } from "./value-help-client.mjs";
4
+ import { valueHelpDictPaths } from "./dict-paths.mjs";
5
+ import { DEFAULT_BOOLEAN_LABELS, extractFieldLiteralOptions, extractLiteralOptions, isPureLiteralUnion } from "./extract-literals.mjs";
6
+ import { extractValueHelp } from "./extract-ref.mjs";
7
+ import { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions } from "./resolve-options.mjs";
8
+ import { fetchDistinctValues, isPickerDeclined } from "./distinct-client.mjs";
@@ -0,0 +1,68 @@
1
+ const require_annotation_keys = 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
+ //#region src/value-help/resolve-options.ts
5
+ /** Extracts the key from an option entry. */
6
+ function optKey(opt) {
7
+ return typeof opt === "string" ? opt : opt.key;
8
+ }
9
+ /** Extracts the display label from an option entry. */
10
+ function optLabel(opt) {
11
+ return typeof opt === "string" ? opt : opt.label;
12
+ }
13
+ const labelMaps = /* @__PURE__ */ new WeakMap();
14
+ /**
15
+ * The display label of a literal-union (or boolean) column's option (`@ui.literalLabel`) for
16
+ * `value` — `undefined` when the column has no options or none matches. Map-backed
17
+ * per options array, so rendering a table does not scan the options per cell.
18
+ * The one lookup behind the table cell, the filter chips, export and a custom cell.
19
+ * Since 0.1.148.
20
+ */
21
+ function optionLabel(column, value) {
22
+ const options = column.options;
23
+ if (!options?.length) return void 0;
24
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") return;
25
+ let labels = labelMaps.get(options);
26
+ if (!labels) {
27
+ labels = new Map(options.map((o) => [o.key, o.label]));
28
+ labelMaps.set(options, labels);
29
+ }
30
+ return labels.get(String(value));
31
+ }
32
+ /**
33
+ * Converts raw option annotation value to a normalized array.
34
+ */
35
+ function parseStaticOptions(raw) {
36
+ return require_field_resolver.asArray(raw).map((item) => {
37
+ if (typeof item === "object" && item !== null && "label" in item) {
38
+ const { label, value } = item;
39
+ return value !== void 0 ? {
40
+ key: value,
41
+ label
42
+ } : label;
43
+ }
44
+ return String(item);
45
+ });
46
+ }
47
+ /**
48
+ * Resolves options from metadata with a fallback chain:
49
+ * 1. `@ui.form.fn.options` (dynamic, compiled by ui-fns)
50
+ * 2. `@ui.form.options` (static annotation)
51
+ * 3. Literal union / boolean extraction (auto-derived from type); `labelsFrom`
52
+ * (`FormFieldDef.labelsFrom`, since 0.1.165) adds an enclosing prop's labels
53
+ * 4. Future: dictionary / value-help lookup
54
+ *
55
+ * `t` words the default boolean labels (`UI_YES` / `UI_NO`); the active UI
56
+ * texts when omitted — a component passes its app's (`useAsLocale().t`).
57
+ */
58
+ function resolveOptions(prop, scope, labelsFrom, t) {
59
+ const resolved = require_field_resolver.resolveFieldProp(prop, require_annotation_keys.UI_FORM_FN_OPTIONS, require_annotation_keys.UI_FORM_OPTIONS, scope, { transform: parseStaticOptions });
60
+ if (resolved !== void 0) return resolved;
61
+ return labelsFrom ? require_extract_literals.extractLiteralOptions(prop, labelsFrom, t) : require_extract_literals.extractFieldLiteralOptions(prop, t);
62
+ }
63
+ //#endregion
64
+ exports.optKey = optKey;
65
+ exports.optLabel = optLabel;
66
+ exports.optionLabel = optionLabel;
67
+ exports.parseStaticOptions = parseStaticOptions;
68
+ exports.resolveOptions = resolveOptions;
@@ -0,0 +1,40 @@
1
+ import { TFormEntryOptions } from "./types.cjs";
2
+ import { UiT } from "../i18n/ui-texts.cjs";
3
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
4
+
5
+ //#region src/value-help/resolve-options.d.ts
6
+ /** Extracts the key from an option entry. */
7
+ declare function optKey(opt: TFormEntryOptions): string;
8
+ /** Extracts the display label from an option entry. */
9
+ declare function optLabel(opt: TFormEntryOptions): string;
10
+ /**
11
+ * The display label of a literal-union (or boolean) column's option (`@ui.literalLabel`) for
12
+ * `value` — `undefined` when the column has no options or none matches. Map-backed
13
+ * per options array, so rendering a table does not scan the options per cell.
14
+ * The one lookup behind the table cell, the filter chips, export and a custom cell.
15
+ * Since 0.1.148.
16
+ */
17
+ declare function optionLabel(column: {
18
+ options?: {
19
+ key: string;
20
+ label: string;
21
+ }[];
22
+ }, value: unknown): string | undefined;
23
+ /**
24
+ * Converts raw option annotation value to a normalized array.
25
+ */
26
+ declare function parseStaticOptions(raw: unknown): TFormEntryOptions[];
27
+ /**
28
+ * Resolves options from metadata with a fallback chain:
29
+ * 1. `@ui.form.fn.options` (dynamic, compiled by ui-fns)
30
+ * 2. `@ui.form.options` (static annotation)
31
+ * 3. Literal union / boolean extraction (auto-derived from type); `labelsFrom`
32
+ * (`FormFieldDef.labelsFrom`, since 0.1.165) adds an enclosing prop's labels
33
+ * 4. Future: dictionary / value-help lookup
34
+ *
35
+ * `t` words the default boolean labels (`UI_YES` / `UI_NO`); the active UI
36
+ * texts when omitted — a component passes its app's (`useAsLocale().t`).
37
+ */
38
+ declare function resolveOptions(prop: TAtscriptAnnotatedType, scope: Record<string, unknown>, labelsFrom?: TAtscriptAnnotatedType, t?: UiT): TFormEntryOptions[] | undefined;
39
+ //#endregion
40
+ export { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions };
@@ -0,0 +1,40 @@
1
+ import { TFormEntryOptions } from "./types.mjs";
2
+ import { UiT } from "../i18n/ui-texts.mjs";
3
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
4
+
5
+ //#region src/value-help/resolve-options.d.ts
6
+ /** Extracts the key from an option entry. */
7
+ declare function optKey(opt: TFormEntryOptions): string;
8
+ /** Extracts the display label from an option entry. */
9
+ declare function optLabel(opt: TFormEntryOptions): string;
10
+ /**
11
+ * The display label of a literal-union (or boolean) column's option (`@ui.literalLabel`) for
12
+ * `value` — `undefined` when the column has no options or none matches. Map-backed
13
+ * per options array, so rendering a table does not scan the options per cell.
14
+ * The one lookup behind the table cell, the filter chips, export and a custom cell.
15
+ * Since 0.1.148.
16
+ */
17
+ declare function optionLabel(column: {
18
+ options?: {
19
+ key: string;
20
+ label: string;
21
+ }[];
22
+ }, value: unknown): string | undefined;
23
+ /**
24
+ * Converts raw option annotation value to a normalized array.
25
+ */
26
+ declare function parseStaticOptions(raw: unknown): TFormEntryOptions[];
27
+ /**
28
+ * Resolves options from metadata with a fallback chain:
29
+ * 1. `@ui.form.fn.options` (dynamic, compiled by ui-fns)
30
+ * 2. `@ui.form.options` (static annotation)
31
+ * 3. Literal union / boolean extraction (auto-derived from type); `labelsFrom`
32
+ * (`FormFieldDef.labelsFrom`, since 0.1.165) adds an enclosing prop's labels
33
+ * 4. Future: dictionary / value-help lookup
34
+ *
35
+ * `t` words the default boolean labels (`UI_YES` / `UI_NO`); the active UI
36
+ * texts when omitted — a component passes its app's (`useAsLocale().t`).
37
+ */
38
+ declare function resolveOptions(prop: TAtscriptAnnotatedType, scope: Record<string, unknown>, labelsFrom?: TAtscriptAnnotatedType, t?: UiT): TFormEntryOptions[] | undefined;
39
+ //#endregion
40
+ export { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions };
@@ -0,0 +1,64 @@
1
+ import { UI_FORM_FN_OPTIONS, UI_FORM_OPTIONS } from "../shared/annotation-keys.mjs";
2
+ import { asArray, resolveFieldProp } from "../shared/field-resolver.mjs";
3
+ import { extractFieldLiteralOptions, extractLiteralOptions } from "./extract-literals.mjs";
4
+ //#region src/value-help/resolve-options.ts
5
+ /** Extracts the key from an option entry. */
6
+ function optKey(opt) {
7
+ return typeof opt === "string" ? opt : opt.key;
8
+ }
9
+ /** Extracts the display label from an option entry. */
10
+ function optLabel(opt) {
11
+ return typeof opt === "string" ? opt : opt.label;
12
+ }
13
+ const labelMaps = /* @__PURE__ */ new WeakMap();
14
+ /**
15
+ * The display label of a literal-union (or boolean) column's option (`@ui.literalLabel`) for
16
+ * `value` — `undefined` when the column has no options or none matches. Map-backed
17
+ * per options array, so rendering a table does not scan the options per cell.
18
+ * The one lookup behind the table cell, the filter chips, export and a custom cell.
19
+ * Since 0.1.148.
20
+ */
21
+ function optionLabel(column, value) {
22
+ const options = column.options;
23
+ if (!options?.length) return void 0;
24
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") return;
25
+ let labels = labelMaps.get(options);
26
+ if (!labels) {
27
+ labels = new Map(options.map((o) => [o.key, o.label]));
28
+ labelMaps.set(options, labels);
29
+ }
30
+ return labels.get(String(value));
31
+ }
32
+ /**
33
+ * Converts raw option annotation value to a normalized array.
34
+ */
35
+ function parseStaticOptions(raw) {
36
+ return asArray(raw).map((item) => {
37
+ if (typeof item === "object" && item !== null && "label" in item) {
38
+ const { label, value } = item;
39
+ return value !== void 0 ? {
40
+ key: value,
41
+ label
42
+ } : label;
43
+ }
44
+ return String(item);
45
+ });
46
+ }
47
+ /**
48
+ * Resolves options from metadata with a fallback chain:
49
+ * 1. `@ui.form.fn.options` (dynamic, compiled by ui-fns)
50
+ * 2. `@ui.form.options` (static annotation)
51
+ * 3. Literal union / boolean extraction (auto-derived from type); `labelsFrom`
52
+ * (`FormFieldDef.labelsFrom`, since 0.1.165) adds an enclosing prop's labels
53
+ * 4. Future: dictionary / value-help lookup
54
+ *
55
+ * `t` words the default boolean labels (`UI_YES` / `UI_NO`); the active UI
56
+ * texts when omitted — a component passes its app's (`useAsLocale().t`).
57
+ */
58
+ function resolveOptions(prop, scope, labelsFrom, t) {
59
+ const resolved = resolveFieldProp(prop, UI_FORM_FN_OPTIONS, UI_FORM_OPTIONS, scope, { transform: parseStaticOptions });
60
+ if (resolved !== void 0) return resolved;
61
+ return labelsFrom ? extractLiteralOptions(prop, labelsFrom, t) : extractFieldLiteralOptions(prop, t);
62
+ }
63
+ //#endregion
64
+ export { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions };
@@ -0,0 +1,66 @@
1
+ const require_annotation_keys = require("../shared/annotation-keys.cjs");
2
+ const require_meta_cache = require("../shared/meta-cache.cjs");
3
+ //#region src/value-help/resolve.ts
4
+ /**
5
+ * Lazily fetch and extract value-help metadata for the given URL.
6
+ *
7
+ * - Issues exactly one `GET {url}/meta` per URL and UI locale across the
8
+ * session (shared via meta-cache).
9
+ * - Concurrent callers with the same URL share the in-flight promise.
10
+ * - If the underlying fetch rejects, the cache entry is evicted so a later
11
+ * retry performs a fresh fetch.
12
+ *
13
+ * `options.texts` — the app's UI texts (see `getMetaEntry`); the active ones
14
+ * by default.
15
+ */
16
+ function resolveValueHelp(url, options) {
17
+ const entry = require_meta_cache.getMetaEntry(url, void 0, options);
18
+ if (entry.resolved) return entry.resolved;
19
+ entry.resolved = Promise.all([entry.meta, entry.type]).then(([meta, type]) => buildResolved(url, meta, type));
20
+ return entry.resolved;
21
+ }
22
+ /** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
23
+ function resetValueHelpCache() {
24
+ require_meta_cache.resetMetaCache();
25
+ }
26
+ function buildResolved(url, meta, targetType) {
27
+ const objectType = targetType.type.kind === "object" ? targetType.type : void 0;
28
+ const versionColumn = meta.versionColumn;
29
+ const primaryKeys = [];
30
+ let labelField;
31
+ let descrField;
32
+ const attrFields = [];
33
+ let firstStringField;
34
+ if (objectType) for (const [name, fieldProp] of objectType.props) {
35
+ if (name === versionColumn) continue;
36
+ const isPK = fieldProp.metadata.has(require_annotation_keys.META_ID);
37
+ if (isPK) primaryKeys.push(name);
38
+ if (fieldProp.metadata.has("ui.dict.label")) labelField = name;
39
+ if (fieldProp.metadata.has("ui.dict.descr")) descrField = name;
40
+ if (fieldProp.metadata.has("ui.dict.attr")) attrFields.push(name);
41
+ if (!firstStringField && !isPK && fieldProp.type.kind === "" && fieldProp.type.designType === "string") firstStringField = name;
42
+ }
43
+ if (!labelField) labelField = firstStringField;
44
+ if (!labelField) labelField = primaryKeys[0] ?? "id";
45
+ const filterableFields = [];
46
+ const sortableFields = [];
47
+ if (meta.fields) for (const [name, fm] of Object.entries(meta.fields)) {
48
+ if (name === versionColumn) continue;
49
+ if (fm?.filterable) filterableFields.push(name);
50
+ if (fm?.sortable) sortableFields.push(name);
51
+ }
52
+ return {
53
+ url,
54
+ primaryKeys,
55
+ labelField,
56
+ descrField,
57
+ attrFields,
58
+ filterableFields,
59
+ sortableFields,
60
+ searchable: !!meta.searchable,
61
+ targetType
62
+ };
63
+ }
64
+ //#endregion
65
+ exports.resetValueHelpCache = resetValueHelpCache;
66
+ exports.resolveValueHelp = resolveValueHelp;
@@ -0,0 +1,36 @@
1
+ import { MetaEntryOptions } from "../shared/meta-cache.cjs";
2
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
+
4
+ //#region src/value-help/resolve.d.ts
5
+ /**
6
+ * Field-role + capability metadata for a value-help target, lazily resolved
7
+ * from the target's own `/meta` endpoint.
8
+ */
9
+ interface ResolvedValueHelp {
10
+ url: string;
11
+ primaryKeys: string[];
12
+ labelField: string;
13
+ descrField: string | undefined;
14
+ attrFields: string[];
15
+ filterableFields: string[];
16
+ sortableFields: string[];
17
+ searchable: boolean;
18
+ targetType: TAtscriptAnnotatedType;
19
+ }
20
+ /**
21
+ * Lazily fetch and extract value-help metadata for the given URL.
22
+ *
23
+ * - Issues exactly one `GET {url}/meta` per URL and UI locale across the
24
+ * session (shared via meta-cache).
25
+ * - Concurrent callers with the same URL share the in-flight promise.
26
+ * - If the underlying fetch rejects, the cache entry is evicted so a later
27
+ * retry performs a fresh fetch.
28
+ *
29
+ * `options.texts` — the app's UI texts (see `getMetaEntry`); the active ones
30
+ * by default.
31
+ */
32
+ declare function resolveValueHelp(url: string, options?: Pick<MetaEntryOptions, "texts">): Promise<ResolvedValueHelp>;
33
+ /** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
34
+ declare function resetValueHelpCache(): void;
35
+ //#endregion
36
+ export { ResolvedValueHelp, resetValueHelpCache, resolveValueHelp };
@@ -0,0 +1,36 @@
1
+ import { MetaEntryOptions } from "../shared/meta-cache.mjs";
2
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
+
4
+ //#region src/value-help/resolve.d.ts
5
+ /**
6
+ * Field-role + capability metadata for a value-help target, lazily resolved
7
+ * from the target's own `/meta` endpoint.
8
+ */
9
+ interface ResolvedValueHelp {
10
+ url: string;
11
+ primaryKeys: string[];
12
+ labelField: string;
13
+ descrField: string | undefined;
14
+ attrFields: string[];
15
+ filterableFields: string[];
16
+ sortableFields: string[];
17
+ searchable: boolean;
18
+ targetType: TAtscriptAnnotatedType;
19
+ }
20
+ /**
21
+ * Lazily fetch and extract value-help metadata for the given URL.
22
+ *
23
+ * - Issues exactly one `GET {url}/meta` per URL and UI locale across the
24
+ * session (shared via meta-cache).
25
+ * - Concurrent callers with the same URL share the in-flight promise.
26
+ * - If the underlying fetch rejects, the cache entry is evicted so a later
27
+ * retry performs a fresh fetch.
28
+ *
29
+ * `options.texts` — the app's UI texts (see `getMetaEntry`); the active ones
30
+ * by default.
31
+ */
32
+ declare function resolveValueHelp(url: string, options?: Pick<MetaEntryOptions, "texts">): Promise<ResolvedValueHelp>;
33
+ /** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
34
+ declare function resetValueHelpCache(): void;
35
+ //#endregion
36
+ export { ResolvedValueHelp, resetValueHelpCache, resolveValueHelp };
@@ -0,0 +1,65 @@
1
+ import { META_ID } from "../shared/annotation-keys.mjs";
2
+ import { getMetaEntry, resetMetaCache } from "../shared/meta-cache.mjs";
3
+ //#region src/value-help/resolve.ts
4
+ /**
5
+ * Lazily fetch and extract value-help metadata for the given URL.
6
+ *
7
+ * - Issues exactly one `GET {url}/meta` per URL and UI locale across the
8
+ * session (shared via meta-cache).
9
+ * - Concurrent callers with the same URL share the in-flight promise.
10
+ * - If the underlying fetch rejects, the cache entry is evicted so a later
11
+ * retry performs a fresh fetch.
12
+ *
13
+ * `options.texts` — the app's UI texts (see `getMetaEntry`); the active ones
14
+ * by default.
15
+ */
16
+ function resolveValueHelp(url, options) {
17
+ const entry = getMetaEntry(url, void 0, options);
18
+ if (entry.resolved) return entry.resolved;
19
+ entry.resolved = Promise.all([entry.meta, entry.type]).then(([meta, type]) => buildResolved(url, meta, type));
20
+ return entry.resolved;
21
+ }
22
+ /** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
23
+ function resetValueHelpCache() {
24
+ resetMetaCache();
25
+ }
26
+ function buildResolved(url, meta, targetType) {
27
+ const objectType = targetType.type.kind === "object" ? targetType.type : void 0;
28
+ const versionColumn = meta.versionColumn;
29
+ const primaryKeys = [];
30
+ let labelField;
31
+ let descrField;
32
+ const attrFields = [];
33
+ let firstStringField;
34
+ if (objectType) for (const [name, fieldProp] of objectType.props) {
35
+ if (name === versionColumn) continue;
36
+ const isPK = fieldProp.metadata.has(META_ID);
37
+ if (isPK) primaryKeys.push(name);
38
+ if (fieldProp.metadata.has("ui.dict.label")) labelField = name;
39
+ if (fieldProp.metadata.has("ui.dict.descr")) descrField = name;
40
+ if (fieldProp.metadata.has("ui.dict.attr")) attrFields.push(name);
41
+ if (!firstStringField && !isPK && fieldProp.type.kind === "" && fieldProp.type.designType === "string") firstStringField = name;
42
+ }
43
+ if (!labelField) labelField = firstStringField;
44
+ if (!labelField) labelField = primaryKeys[0] ?? "id";
45
+ const filterableFields = [];
46
+ const sortableFields = [];
47
+ if (meta.fields) for (const [name, fm] of Object.entries(meta.fields)) {
48
+ if (name === versionColumn) continue;
49
+ if (fm?.filterable) filterableFields.push(name);
50
+ if (fm?.sortable) sortableFields.push(name);
51
+ }
52
+ return {
53
+ url,
54
+ primaryKeys,
55
+ labelField,
56
+ descrField,
57
+ attrFields,
58
+ filterableFields,
59
+ sortableFields,
60
+ searchable: !!meta.searchable,
61
+ targetType
62
+ };
63
+ }
64
+ //#endregion
65
+ export { resetValueHelpCache, resolveValueHelp };