@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,460 @@
1
+ import { META_DESCRIPTION, META_LABEL, UI_FORM_COMPONENT, UI_FORM_PUSH_DOWN, UI_TYPE } from "../shared/annotation-keys.mjs";
2
+ import { getFieldMeta, hasComputedAnnotations } from "../shared/field-resolver.mjs";
3
+ import { AS_UI_MESSAGES } from "../messages.mjs";
4
+ import { isEmptyMember, isPureLiteralUnion } from "../value-help/extract-literals.mjs";
5
+ import { extractValueHelp } from "../value-help/extract-ref.mjs";
6
+ import { isSkippedNavField } from "./skipped-nav.mjs";
7
+ import { flattenAnnotatedType } from "@atscript/typescript/utils";
8
+ import { isNavRelation, isServerStampedOnUpdate } from "@atscript/db/validator";
9
+ //#region src/form/create-form-def.ts
10
+ /** Known atscript primitive extension tags that map directly to field types. */
11
+ const UI_TAGS = new Set([
12
+ "action",
13
+ "paragraph",
14
+ "select",
15
+ "radio",
16
+ "checkbox"
17
+ ]);
18
+ /**
19
+ * The object defs, and the array / union / tuple field defs, under
20
+ * construction (innermost last). A recursive type reached again inside its own
21
+ * build reuses the def being built, so the def graph gets a cycle instead of
22
+ * an endless expansion: a tree's `children` items are the same def at every
23
+ * depth, built once. A field def is reused only at the same path relative to
24
+ * its object def, so a reused field always sits where it was built. Both are
25
+ * per mode (`edit`), which shapes the defs.
26
+ */
27
+ const defsInProgress = [];
28
+ const fieldsInProgress = [];
29
+ /**
30
+ * `field` without its name (a tuple item). A field def still under
31
+ * construction (a recursion back to it) gets a copy filled when it is built.
32
+ */
33
+ function unnamed(field) {
34
+ const building = fieldsInProgress.find((e) => e.field === field);
35
+ if (!building) return {
36
+ ...field,
37
+ name: ""
38
+ };
39
+ const copy = { name: "" };
40
+ building.copies.push(copy);
41
+ return copy;
42
+ }
43
+ /**
44
+ * Converts an ATScript annotated type into a FormDef.
45
+ *
46
+ * - **Object types** (`kind === 'object'`): produces an object root with nested fields.
47
+ * - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
48
+ * with `path: ''`.
49
+ *
50
+ * A `@db.column.derived` field is marked `derived` straight from its metadata;
51
+ * a computed view column, from `opts.metaFields`; an update-stamped field
52
+ * (see `CreateFormDefOptions.mode`), when `opts.mode` is `"edit"`.
53
+ *
54
+ * A navigation field (`@db.rel.from` / `.to` / `.via`) is left out unless it
55
+ * carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
56
+ *
57
+ * Recursive types are safe at any depth: a type reached again inside its own
58
+ * build reuses the def being built (the def graph is cyclic, not infinite).
59
+ * A recursive object that would otherwise render inline (no `@ui.form.*`)
60
+ * becomes a nested object field, since inlining it would never end.
61
+ */
62
+ function createFormDef(type, opts) {
63
+ return buildFormDef(type, opts?.mode === "edit", opts ?? {});
64
+ }
65
+ /**
66
+ * The def of an object (or a leaf) type. `root`: the caller's options, for the
67
+ * form's own type only — nested objects get none of the root-table ones.
68
+ */
69
+ function buildFormDef(type, edit, root) {
70
+ if (type.type.kind !== "object") {
71
+ const rootField = createFieldDef("", type, edit);
72
+ const fields = [rootField];
73
+ return {
74
+ type,
75
+ rootField,
76
+ fields,
77
+ mainFields: fields,
78
+ pushDownFields: [],
79
+ flatMap: /* @__PURE__ */ new Map()
80
+ };
81
+ }
82
+ if (!root) {
83
+ const reached = defsInProgress.find((e) => e.type === type && e.edit === edit);
84
+ if (reached) return reached.def;
85
+ }
86
+ const objectType = type;
87
+ const flatMap = flattenAnnotatedType(objectType, { excludePhantomTypes: false });
88
+ const opts = root && {
89
+ ...root,
90
+ versionColumn: root.versionColumn ?? (edit ? findVersionColumn(flatMap) : void 0)
91
+ };
92
+ const fields = [];
93
+ const rootField = {
94
+ path: "",
95
+ prop: type,
96
+ type: "object",
97
+ phantom: false,
98
+ name: "",
99
+ allStatic: false,
100
+ pushDown: false
101
+ };
102
+ const def = {
103
+ type,
104
+ rootField,
105
+ fields,
106
+ mainFields: fields,
107
+ pushDownFields: [],
108
+ flatMap
109
+ };
110
+ rootField.objectDef = def;
111
+ let collected;
112
+ if (!root) defsInProgress.push({
113
+ type,
114
+ edit,
115
+ def
116
+ });
117
+ try {
118
+ collected = collectFields(objectType, flatMap, edit, opts);
119
+ } finally {
120
+ if (!root) defsInProgress.pop();
121
+ }
122
+ collected.sort((a, b) => a.order - b.order);
123
+ for (const c of collected) fields.push(c.field);
124
+ if (collected.some((c) => c.pushDown)) {
125
+ def.mainFields = [];
126
+ for (const c of collected) (c.pushDown ? def.pushDownFields : def.mainFields).push(c.field);
127
+ }
128
+ return def;
129
+ }
130
+ /** Builds the top-level fields of an object def from its flattened props, unsorted. */
131
+ function collectFields(objectType, flatMap, edit, opts) {
132
+ const fields = [];
133
+ const structuredPrefixes = /* @__PURE__ */ new Set();
134
+ for (const [path, prop] of flatMap.entries()) {
135
+ if (path === "") continue;
136
+ if (path === opts?.versionColumn) continue;
137
+ if (isChildOfStructured(path, structuredPrefixes)) continue;
138
+ const originalProp = resolveOriginalProp(objectType, path) ?? prop;
139
+ const kind = originalProp.type.kind;
140
+ if (isSkippedNavField(originalProp)) {
141
+ structuredPrefixes.add(path + ".");
142
+ continue;
143
+ }
144
+ if (kind === "object" && !isStructuredObject(originalProp) && !isNavRelation(originalProp) && !isUnexpandedObject(path, originalProp, flatMap)) continue;
145
+ if (kind === "array") {
146
+ if (originalProp.type.of.type.kind === "array" && !getFieldMeta(originalProp, "ui.form.component")) continue;
147
+ }
148
+ if (kind === "array" || kind === "object" || kind === "union" || kind === "tuple") structuredPrefixes.add(path + ".");
149
+ const field = createFieldDef(path, originalProp, edit);
150
+ fields.push({
151
+ field: opts?.metaFields?.[path]?.computed ? {
152
+ ...field,
153
+ derived: true
154
+ } : field,
155
+ order: getFieldMeta(originalProp, "ui.form.order") ?? Infinity,
156
+ pushDown: getFieldMeta(originalProp, UI_FORM_PUSH_DOWN) !== void 0
157
+ });
158
+ }
159
+ return fields;
160
+ }
161
+ /**
162
+ * Creates a FormFieldDef from any ATScript annotated type. `edit`: the form
163
+ * edits a stored row (`CreateFormDefOptions.mode`).
164
+ *
165
+ * An array, union or tuple reached again at the same path inside its own
166
+ * build (an array item, a union variant or a tuple item of a recursive alias)
167
+ * gets the field def under construction. Every other recursion passes an
168
+ * object def, which `defsInProgress` catches, so the build always ends.
169
+ */
170
+ function createFieldDef(path, prop, edit) {
171
+ const kind = prop.type.kind;
172
+ if (kind === "" || kind === "object") return buildFieldDef(path, prop, edit);
173
+ const reached = fieldsInProgress.find((e) => e.prop === prop && e.path === path && e.edit === edit);
174
+ if (reached) return reached.field;
175
+ const building = {
176
+ prop,
177
+ path,
178
+ edit,
179
+ field: {},
180
+ copies: []
181
+ };
182
+ fieldsInProgress.push(building);
183
+ try {
184
+ const field = Object.assign(building.field, buildFieldDef(path, prop, edit));
185
+ for (const copy of building.copies) Object.assign(copy, field, { name: "" });
186
+ return field;
187
+ } finally {
188
+ fieldsInProgress.pop();
189
+ }
190
+ }
191
+ function buildFieldDef(path, prop, edit) {
192
+ const kind = prop.type.kind;
193
+ const name = path.slice(path.lastIndexOf(".") + 1);
194
+ const allStatic = !hasComputedAnnotations(prop);
195
+ const declaredType = getFieldMeta(prop, "ui.form.type") ?? getFieldMeta(prop, "ui.type");
196
+ const uiType = declaredType === "tags" && kind !== "array" ? void 0 : declaredType;
197
+ const pushDown = getFieldMeta(prop, UI_FORM_PUSH_DOWN) !== void 0;
198
+ const valueHelpInfo = extractValueHelp(prop);
199
+ const derived = getFieldMeta(prop, "db.column.derived") !== void 0 || edit && path !== "" && isUpdateStamped(prop);
200
+ const base = {
201
+ path,
202
+ prop,
203
+ phantom: false,
204
+ name,
205
+ allStatic,
206
+ pushDown,
207
+ valueHelpInfo,
208
+ ...derived && { derived: true }
209
+ };
210
+ const customType = uiType;
211
+ if (kind === "array") {
212
+ const arrayType = prop.type;
213
+ const hasOptions = getFieldMeta(prop, "ui.form.options") !== void 0 || getFieldMeta(prop, "ui.form.fn.options") !== void 0 || isPureLiteralUnion(arrayType.of);
214
+ const isTags = customType === "tags" || customType === "multiselect" && !hasOptions;
215
+ const isMultiselect = customType === "multiselect" || hasOptions;
216
+ return {
217
+ ...base,
218
+ type: "array",
219
+ customType: isTags ? "tags" : isMultiselect ? "multiselect" : customType,
220
+ itemType: arrayType.of,
221
+ itemField: labelledBy(createFieldDef("", arrayType.of, edit), prop)
222
+ };
223
+ }
224
+ if (kind === "object") return {
225
+ ...base,
226
+ type: "object",
227
+ customType,
228
+ objectDef: buildFormDef(prop, edit)
229
+ };
230
+ if (kind === "union") {
231
+ if (isPureLiteralUnion(prop)) return {
232
+ ...base,
233
+ type: uiType ?? "select"
234
+ };
235
+ const unionVariants = createUnionVariants(prop, edit && soleValueMember(prop) !== void 0);
236
+ if (unionVariants.length > 1) return {
237
+ ...base,
238
+ type: "union",
239
+ customType,
240
+ unionVariants
241
+ };
242
+ const v = unionVariants[0];
243
+ if (v?.itemField) return {
244
+ ...v.itemField,
245
+ path,
246
+ name,
247
+ allStatic,
248
+ pushDown,
249
+ ...derived && { derived: true }
250
+ };
251
+ if (v?.def) return {
252
+ ...base,
253
+ type: "object",
254
+ customType,
255
+ objectDef: v.def
256
+ };
257
+ }
258
+ if (kind === "tuple") {
259
+ const tupleType = prop.type;
260
+ return {
261
+ ...base,
262
+ type: "tuple",
263
+ customType,
264
+ itemFields: tupleType.items.map((item, i) => unnamed(createFieldDef(String(i), item, false)))
265
+ };
266
+ }
267
+ if (valueHelpInfo) return {
268
+ ...base,
269
+ type: uiType ?? "ref"
270
+ };
271
+ const tags = kind === "" ? prop.type.tags : void 0;
272
+ let uiTag;
273
+ let isTimestamp = false;
274
+ if (tags) for (const t of tags) {
275
+ if (uiTag === void 0 && UI_TAGS.has(t)) uiTag = t;
276
+ if (t === "timestamp") isTimestamp = true;
277
+ }
278
+ const dt = kind === "" ? prop.type.designType : void 0;
279
+ let numericType;
280
+ if (kind === "") {
281
+ const hasCurrency = getFieldMeta(prop, "db.amount.currency") !== void 0 || getFieldMeta(prop, "db.amount.currency.ref") !== void 0;
282
+ const isDecimalDesign = dt === "decimal";
283
+ if (hasCurrency) numericType = "decimal";
284
+ else if (isDecimalDesign) numericType = "decimal";
285
+ else if (dt === "number") {
286
+ const hasUnit = getFieldMeta(prop, "db.unit") !== void 0 || getFieldMeta(prop, "db.unit.ref") !== void 0;
287
+ const hasPrefix = getFieldMeta(prop, "ui.form.prefix") !== void 0 || getFieldMeta(prop, "ui.form.prefix.ref") !== void 0 || getFieldMeta(prop, "ui.form.prefix.icon") !== void 0;
288
+ const hasSuffix = getFieldMeta(prop, "ui.form.suffix") !== void 0 || getFieldMeta(prop, "ui.form.suffix.ref") !== void 0 || getFieldMeta(prop, "ui.form.suffix.icon") !== void 0;
289
+ if (hasUnit || hasPrefix || hasSuffix) numericType = "number";
290
+ }
291
+ }
292
+ const tagType = isTimestamp ? "datetime" : void 0;
293
+ return {
294
+ ...base,
295
+ type: uiType ?? uiTag ?? numericType ?? tagType ?? (dt === "number" ? "number" : dt === "boolean" ? "checkbox" : "text"),
296
+ phantom: kind === "" && dt === "phantom"
297
+ };
298
+ }
299
+ /** Non-`ui.form.*` keys that still address the object itself. */
300
+ const OBJECT_IDENTITY_KEYS = new Set([
301
+ META_LABEL,
302
+ META_DESCRIPTION,
303
+ UI_TYPE
304
+ ]);
305
+ /** `ui.form.*` keys that place a field rather than give it an identity. */
306
+ const UI_FORM_PLACEMENT_NS = "ui.form.grid.";
307
+ /**
308
+ * Whether an object prop renders as a field of its own rather than being
309
+ * flattened into its parent.
310
+ *
311
+ * Any `@ui.form.*` annotation (plus `@meta.label` / `@meta.description` /
312
+ * `@ui.type`) means the author addressed the object itself, so it needs a
313
+ * field to carry that instruction to a renderer — a collapsible section, or
314
+ * whatever `@ui.form.component` / `@ui.form.type` names. An object with none
315
+ * of them is a pure namespace: it is dropped and its children render inline
316
+ * in the parent grid, which keeps DB-flattened structs (`addr.street` stored
317
+ * as `addr__street`) from growing chrome nobody asked for. `@db.*`,
318
+ * `@expect.*` and the rest of `@meta.*` stay out for exactly that reason —
319
+ * they are what such a struct carries.
320
+ *
321
+ * Placement keys (`@ui.form.order`, `@ui.form.grid.*`) are excluded: they
322
+ * position a field among its siblings, and a namespace has no position of its
323
+ * own — its children carry their own.
324
+ *
325
+ * A prefix rule rather than a list because the list was wrong the moment it
326
+ * was written. Matching on `@meta.label` and `@ui.form.component` alone left
327
+ * every other key to be read off a prop that never became a field: a
328
+ * `@meta.description` went missing, a `@ui.form.type` component silently
329
+ * never mounted, `@ui.form.pushDown` never pushed down, and — the one that
330
+ * mattered — `@ui.form.hidden` on a struct left every child on screen.
331
+ */
332
+ function isStructuredObject(prop) {
333
+ for (const key of prop.metadata.keys()) {
334
+ if (OBJECT_IDENTITY_KEYS.has(key)) return true;
335
+ if (!key.startsWith("ui.form.")) continue;
336
+ if (key === "ui.form.order" || key.startsWith(UI_FORM_PLACEMENT_NS)) continue;
337
+ return true;
338
+ }
339
+ return false;
340
+ }
341
+ /** The top-level `@db.column.version` field of a flattened type, if any. */
342
+ function findVersionColumn(flatMap) {
343
+ for (const [path, prop] of flatMap) if (path && !path.includes(".") && prop.metadata.has("db.column.version")) return path;
344
+ }
345
+ /**
346
+ * An object prop that `flattenAnnotatedType` listed without expanding it: a
347
+ * recursive type reached again. Its children are absent from the flat map.
348
+ */
349
+ function isUnexpandedObject(path, prop, flatMap) {
350
+ const first = prop.type.props.keys().next();
351
+ return !first.done && !flatMap.has(`${path}.${first.value}`);
352
+ }
353
+ /** Resolves the original annotated type from the type hierarchy by path. */
354
+ function resolveOriginalProp(type, path) {
355
+ const parts = path.split(".");
356
+ let current = type.type;
357
+ for (let i = 0; i < parts.length - 1; i++) {
358
+ const prop = current.props.get(parts[i]);
359
+ if (!prop || prop.type.kind !== "object") return void 0;
360
+ current = prop.type;
361
+ }
362
+ return current.props.get(parts[parts.length - 1]);
363
+ }
364
+ /** Check if a path is a child of any structured prefix (prefixes are pre-suffixed with "."). */
365
+ function isChildOfStructured(path, prefixes) {
366
+ for (const prefix of prefixes) if (path.startsWith(prefix)) return true;
367
+ return false;
368
+ }
369
+ /**
370
+ * Builds union variant definitions from a union annotated type.
371
+ * Iterates top-level items directly — one variant per item.
372
+ */
373
+ function buildUnionVariants(typeDef) {
374
+ return createUnionVariants(typeDef, false);
375
+ }
376
+ /**
377
+ * A scalar field inside `outer` (an array item, a union variant) also takes `outer`'s
378
+ * `@ui.literalLabel` labels — `flags: boolean[]`, `active: boolean | null`.
379
+ */
380
+ function labelledBy(field, outer) {
381
+ if (field.prop?.type.kind === "" && outer.metadata.has("ui.literalLabel")) field.labelsFrom = outer;
382
+ return field;
383
+ }
384
+ function createUnionVariants(typeDef, edit) {
385
+ const items = typeDef.type.items ?? [typeDef];
386
+ const variants = [];
387
+ for (const item of items) {
388
+ const v = createVariant(item, edit);
389
+ if (v.itemField) labelledBy(v.itemField, typeDef);
390
+ if (items.length > 1) v.label = `${String(variants.length + 1)}. ${v.label}`;
391
+ variants.push(v);
392
+ }
393
+ return variants;
394
+ }
395
+ /** Creates a single union variant from an annotated type item. */
396
+ function createVariant(def, edit) {
397
+ const kind = def.type.kind;
398
+ if (kind === "object") {
399
+ const label = getFieldMeta(def, META_LABEL);
400
+ const hasComponent = getFieldMeta(def, UI_FORM_COMPONENT) !== void 0;
401
+ return {
402
+ ...label === void 0 ? typeLabel("object") : { label },
403
+ type: def,
404
+ def: buildFormDef(def, edit),
405
+ itemField: hasComponent ? createFieldDef("", def, edit) : void 0
406
+ };
407
+ }
408
+ if (kind === "") {
409
+ const dt = def.type.designType;
410
+ return {
411
+ ...typeLabel(dt === "phantom" ? "item" : dt),
412
+ type: def,
413
+ itemField: createFieldDef("", def, edit),
414
+ designType: dt
415
+ };
416
+ }
417
+ return {
418
+ ...typeLabel(kind),
419
+ type: def,
420
+ itemField: createFieldDef("", def, edit)
421
+ };
422
+ }
423
+ /**
424
+ * An update-stamped field (see `CreateFormDefOptions.mode`). Read off the prop,
425
+ * or — as `@atscript/db` does — off the one value member of `T | null`, unless
426
+ * the prop references another field.
427
+ */
428
+ function isUpdateStamped(prop) {
429
+ if (isServerStampedOnUpdate(prop.metadata)) return true;
430
+ const member = prop.ref?.field ? void 0 : soleValueMember(prop);
431
+ return member !== void 0 && isServerStampedOnUpdate(member.metadata);
432
+ }
433
+ /** The one non-`null` / `undefined` member of a (nested) union, if there is exactly one. */
434
+ function soleValueMember(prop) {
435
+ if (prop.type.kind !== "union") return void 0;
436
+ const members = /* @__PURE__ */ new Set();
437
+ const visit = (t) => {
438
+ if (t.type.kind === "union") for (const item of t.type.items) visit(item);
439
+ else if (!isEmptyMember(t)) members.add(t);
440
+ };
441
+ visit(prop);
442
+ return members.size === 1 ? members.values().next().value : void 0;
443
+ }
444
+ function capitalize(s) {
445
+ return s.charAt(0).toUpperCase() + s.slice(1);
446
+ }
447
+ /**
448
+ * A union variant's name for its type when it has no `@meta.label`: the
449
+ * English text of `UI_FORM_TYPE_*` with that code, worded at render time in
450
+ * the UI locale (a definition is built once, for every locale).
451
+ */
452
+ function typeLabel(kind) {
453
+ const code = `UI_FORM_TYPE_${kind.toUpperCase()}`;
454
+ return Object.hasOwn(AS_UI_MESSAGES, code) ? {
455
+ label: AS_UI_MESSAGES[code],
456
+ labelCode: code
457
+ } : { label: capitalize(kind) };
458
+ }
459
+ //#endregion
460
+ export { buildUnionVariants, createFormDef, findVersionColumn };