@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,61 @@
1
+ import { FormDef } from "./types.cjs";
2
+ import { FormDiffOptions, FormFieldChange } from "./diff.cjs";
3
+
4
+ //#region src/form/rebase.d.ts
5
+ /** Options for {@link buildFormRebase}. */
6
+ interface FormRebaseOptions {
7
+ /**
8
+ * How to resolve a field changed on BOTH sides (local edit vs. upstream
9
+ * edit) to a different value:
10
+ * - `'ours'` (default) — keep the local edit, discard upstream's value.
11
+ * - `'theirs'` — take upstream's value, discard the local edit.
12
+ *
13
+ * A field changed on both sides to the SAME value is never a conflict.
14
+ */
15
+ conflict?: "ours" | "theirs";
16
+ }
17
+ /** Result of {@link buildFormRebase}. */
18
+ interface FormRebaseResult {
19
+ /**
20
+ * The rebased WRAPPED form-data container (`{ value }`). Always a fresh deep
21
+ * clone of `upstream` with the local diff reapplied — never aliases any
22
+ * input container.
23
+ */
24
+ next: Record<string, unknown>;
25
+ /**
26
+ * Paths that were changed on both sides to different values (same-path
27
+ * conflicts), plus ancestor paths whose subtree upstream cleared while local
28
+ * still edited a leaf under it (ancestor-clear conflicts). De-duplicated.
29
+ */
30
+ conflicts: string[];
31
+ /**
32
+ * The diff of `next` against the NEW baseline (`upstream`) — i.e. exactly the
33
+ * changes that survive on top of upstream. Empty `[]` when the rebased form
34
+ * equals upstream (a fully clean / fully reverted rebase).
35
+ *
36
+ * The returned `reapplied` does NOT alias the returned `next`, so installing
37
+ * `next` as live form data never retroactively mutates the returned change set.
38
+ */
39
+ reapplied: FormFieldChange[];
40
+ }
41
+ /**
42
+ * Pure 3-way rebase for a change-tracked form. Given the current baseline `B0`,
43
+ * the live form `C`, and a fresh upstream `U`, produces the form rewritten as
44
+ * `U` + the local diff (`C` vs `B0`) reapplied on top:
45
+ *
46
+ * - Fields the user never touched adopt upstream's value.
47
+ * - Local edits survive (reapplied onto the upstream clone).
48
+ * - Fields changed on BOTH sides to different values are conflicts, resolved by
49
+ * `opts.conflict` (`'ours'` keeps local, `'theirs'` takes upstream).
50
+ *
51
+ * All inputs are WRAPPED form-data containers (`{ value: domainData }`). The
52
+ * result `next` is a fresh container; no input is mutated.
53
+ *
54
+ * `diffOptions` are forwarded to BOTH internal `buildFormDiff` passes so the
55
+ * same field exclusions apply (notably the `@db.column.version` column and the
56
+ * `$cas` policy) on the local and upstream sides — keep them identical to the
57
+ * options the caller uses for its own change tracking.
58
+ */
59
+ declare function buildFormRebase(def: FormDef, baseline: Record<string, unknown>, current: Record<string, unknown>, upstream: Record<string, unknown>, opts?: FormRebaseOptions, diffOptions?: FormDiffOptions): FormRebaseResult;
60
+ //#endregion
61
+ export { FormRebaseOptions, FormRebaseResult, buildFormRebase };
@@ -0,0 +1,61 @@
1
+ import { FormDef } from "./types.mjs";
2
+ import { FormDiffOptions, FormFieldChange } from "./diff.mjs";
3
+
4
+ //#region src/form/rebase.d.ts
5
+ /** Options for {@link buildFormRebase}. */
6
+ interface FormRebaseOptions {
7
+ /**
8
+ * How to resolve a field changed on BOTH sides (local edit vs. upstream
9
+ * edit) to a different value:
10
+ * - `'ours'` (default) — keep the local edit, discard upstream's value.
11
+ * - `'theirs'` — take upstream's value, discard the local edit.
12
+ *
13
+ * A field changed on both sides to the SAME value is never a conflict.
14
+ */
15
+ conflict?: "ours" | "theirs";
16
+ }
17
+ /** Result of {@link buildFormRebase}. */
18
+ interface FormRebaseResult {
19
+ /**
20
+ * The rebased WRAPPED form-data container (`{ value }`). Always a fresh deep
21
+ * clone of `upstream` with the local diff reapplied — never aliases any
22
+ * input container.
23
+ */
24
+ next: Record<string, unknown>;
25
+ /**
26
+ * Paths that were changed on both sides to different values (same-path
27
+ * conflicts), plus ancestor paths whose subtree upstream cleared while local
28
+ * still edited a leaf under it (ancestor-clear conflicts). De-duplicated.
29
+ */
30
+ conflicts: string[];
31
+ /**
32
+ * The diff of `next` against the NEW baseline (`upstream`) — i.e. exactly the
33
+ * changes that survive on top of upstream. Empty `[]` when the rebased form
34
+ * equals upstream (a fully clean / fully reverted rebase).
35
+ *
36
+ * The returned `reapplied` does NOT alias the returned `next`, so installing
37
+ * `next` as live form data never retroactively mutates the returned change set.
38
+ */
39
+ reapplied: FormFieldChange[];
40
+ }
41
+ /**
42
+ * Pure 3-way rebase for a change-tracked form. Given the current baseline `B0`,
43
+ * the live form `C`, and a fresh upstream `U`, produces the form rewritten as
44
+ * `U` + the local diff (`C` vs `B0`) reapplied on top:
45
+ *
46
+ * - Fields the user never touched adopt upstream's value.
47
+ * - Local edits survive (reapplied onto the upstream clone).
48
+ * - Fields changed on BOTH sides to different values are conflicts, resolved by
49
+ * `opts.conflict` (`'ours'` keeps local, `'theirs'` takes upstream).
50
+ *
51
+ * All inputs are WRAPPED form-data containers (`{ value: domainData }`). The
52
+ * result `next` is a fresh container; no input is mutated.
53
+ *
54
+ * `diffOptions` are forwarded to BOTH internal `buildFormDiff` passes so the
55
+ * same field exclusions apply (notably the `@db.column.version` column and the
56
+ * `$cas` policy) on the local and upstream sides — keep them identical to the
57
+ * options the caller uses for its own change tracking.
58
+ */
59
+ declare function buildFormRebase(def: FormDef, baseline: Record<string, unknown>, current: Record<string, unknown>, upstream: Record<string, unknown>, opts?: FormRebaseOptions, diffOptions?: FormDiffOptions): FormRebaseResult;
60
+ //#endregion
61
+ export { FormRebaseOptions, FormRebaseResult, buildFormRebase };
@@ -0,0 +1,89 @@
1
+ import { deepClone } from "./clone.mjs";
2
+ import { getByPath, setByPath } from "./path-utils.mjs";
3
+ import { buildFormDiff, deepEqual } from "./diff.mjs";
4
+ import { applyFormChanges } from "./apply.mjs";
5
+ //#region src/form/rebase.ts
6
+ /**
7
+ * Pure 3-way rebase for a change-tracked form. Given the current baseline `B0`,
8
+ * the live form `C`, and a fresh upstream `U`, produces the form rewritten as
9
+ * `U` + the local diff (`C` vs `B0`) reapplied on top:
10
+ *
11
+ * - Fields the user never touched adopt upstream's value.
12
+ * - Local edits survive (reapplied onto the upstream clone).
13
+ * - Fields changed on BOTH sides to different values are conflicts, resolved by
14
+ * `opts.conflict` (`'ours'` keeps local, `'theirs'` takes upstream).
15
+ *
16
+ * All inputs are WRAPPED form-data containers (`{ value: domainData }`). The
17
+ * result `next` is a fresh container; no input is mutated.
18
+ *
19
+ * `diffOptions` are forwarded to BOTH internal `buildFormDiff` passes so the
20
+ * same field exclusions apply (notably the `@db.column.version` column and the
21
+ * `$cas` policy) on the local and upstream sides — keep them identical to the
22
+ * options the caller uses for its own change tracking.
23
+ */
24
+ function buildFormRebase(def, baseline, current, upstream, opts, diffOptions) {
25
+ const conflictMode = opts?.conflict ?? "ours";
26
+ const local = buildFormDiff(def, baseline, current, diffOptions).changes;
27
+ const upstreamChanges = buildFormDiff(def, baseline, upstream, diffOptions).changes;
28
+ const upstreamByPath = /* @__PURE__ */ new Map();
29
+ for (const uc of upstreamChanges) upstreamByPath.set(uc.path, uc);
30
+ const next = deepClone(upstream);
31
+ const conflicts = [];
32
+ for (const lc of local) {
33
+ const clearedAncestor = findClearedAncestor(lc.path, baseline, upstream);
34
+ if (clearedAncestor !== void 0) {
35
+ conflicts.push(clearedAncestor);
36
+ if (conflictMode === "ours") setByPath(next, clearedAncestor, deepClone(getByPath(current, clearedAncestor)));
37
+ continue;
38
+ }
39
+ const uc = upstreamByPath.get(lc.path);
40
+ if (uc !== void 0) {
41
+ if (deepEqual(lc.after, uc.after)) continue;
42
+ conflicts.push(lc.path);
43
+ if (conflictMode === "ours") reapply(def, next, lc);
44
+ continue;
45
+ }
46
+ reapply(def, next, lc);
47
+ }
48
+ const reapplied = buildFormDiff(def, upstream, deepClone(next), diffOptions).changes;
49
+ return {
50
+ next,
51
+ conflicts: [...new Set(conflicts)],
52
+ reapplied
53
+ };
54
+ }
55
+ /**
56
+ * Reapplies a single local change onto `next`, DEEP-CLONING its `after` value
57
+ * first. `lc.after` is a LIVE reference into `current` (buildFormDiff holds live
58
+ * refs), so for a `kind:'array'` or whole-object/union `set` change a raw apply
59
+ * would make `next.value`'s node `===` `current.value`'s node — violating the
60
+ * `FormRebaseResult.next` contract ("never aliases any input container"). The
61
+ * ancestor-clear branch already deep-clones before writing; this keeps the two
62
+ * leaf-reapply sites consistent.
63
+ */
64
+ function reapply(def, next, lc) {
65
+ applyFormChanges(def, next, [{
66
+ ...lc,
67
+ after: deepClone(lc.after)
68
+ }]);
69
+ }
70
+ /**
71
+ * Returns the SHALLOWEST strict ancestor of `leafPath` that was an object/array
72
+ * in `baseline` but is `null`/`undefined` in `upstream` (upstream cleared the
73
+ * subtree), or `undefined` when no ancestor was cleared. The leaf path itself is
74
+ * never considered an ancestor.
75
+ */
76
+ function findClearedAncestor(leafPath, baseline, upstream) {
77
+ if (!leafPath.includes(".")) return void 0;
78
+ const segs = leafPath.split(".");
79
+ let acc = "";
80
+ for (let i = 0; i < segs.length - 1; i++) {
81
+ acc = acc ? `${acc}.${segs[i]}` : segs[i];
82
+ const base = getByPath(baseline, acc);
83
+ if (typeof base !== "object" || base === null) continue;
84
+ const up = getByPath(upstream, acc);
85
+ if (up === null || up === void 0) return acc;
86
+ }
87
+ }
88
+ //#endregion
89
+ export { buildFormRebase };
@@ -0,0 +1,100 @@
1
+ require("../shared/annotation-keys.cjs");
2
+ const require_types = require("./types.cjs");
3
+ const require_clone = require("./clone.cjs");
4
+ const require_path_utils = require("./path-utils.cjs");
5
+ let _atscript_db_validator = require("@atscript/db/validator");
6
+ //#region src/form/skipped-nav.ts
7
+ /**
8
+ * Whether a form leaves this prop out: a navigation field (`@db.rel.from` /
9
+ * `.to` / `.via`) without a `@ui.form.*` annotation of its own. Navigation
10
+ * fields hold related rows (loaded with `$with`), not data the row's own form
11
+ * edits, and a two-way pair points back at the form's own type. Annotating one
12
+ * (`@ui.form.order`, `@ui.form.component`, …) opts it in.
13
+ */
14
+ function isSkippedNavField(prop) {
15
+ if (!(0, _atscript_db_validator.isNavRelation)(prop)) return false;
16
+ for (const key of prop.metadata.keys()) if (key.startsWith("ui.form.")) return false;
17
+ return true;
18
+ }
19
+ /** Per def: the paths of its own skipped navigation fields. */
20
+ const ownSkippedNav = /* @__PURE__ */ new WeakMap();
21
+ /** Per def: whether a skipped navigation field is reachable below its own props. */
22
+ const nestedSkippedNav = /* @__PURE__ */ new WeakMap();
23
+ /**
24
+ * The paths of `def`'s own props that are navigation fields the form leaves
25
+ * out — none below another one, which goes with it. Cached per def.
26
+ */
27
+ function ownSkippedNavPaths(def) {
28
+ let paths = ownSkippedNav.get(def);
29
+ if (!paths) {
30
+ paths = [];
31
+ for (const [path, prop] of def.flatMap) {
32
+ if (!path || paths.some((p) => path.startsWith(`${p}.`))) continue;
33
+ if (isSkippedNavField(prop)) paths.push(path);
34
+ }
35
+ ownSkippedNav.set(def, paths);
36
+ }
37
+ return paths;
38
+ }
39
+ /**
40
+ * Whether a def nested in `def` (an object field, an array item, a union
41
+ * variant, …) has a navigation field the form leaves out (see
42
+ * `isSkippedNavField`) — data a whole-value patch entry could carry. Cached
43
+ * per def; cycle-safe.
44
+ */
45
+ function hasNestedSkippedNavFields(def) {
46
+ const known = nestedSkippedNav.get(def);
47
+ if (known !== void 0) return known;
48
+ const hasOwn = (d) => d !== void 0 && ownSkippedNavPaths(d).length > 0;
49
+ const seen = /* @__PURE__ */ new Set();
50
+ const reaches = (f) => {
51
+ if (seen.has(f)) return false;
52
+ seen.add(f);
53
+ if (require_types.isObjectField(f) && hasOwn(f.objectDef)) return true;
54
+ if (require_types.isUnionField(f) && f.unionVariants.some((v) => hasOwn(v.def))) return true;
55
+ return require_types.childFields(f).some(reaches);
56
+ };
57
+ const result = def.fields.some(reaches);
58
+ nestedSkippedNav.set(def, result);
59
+ return result;
60
+ }
61
+ /**
62
+ * A deep copy of form data `value` (the unwrapped domain data of `def`'s type)
63
+ * without the navigation fields the form leaves out, at any depth: related
64
+ * rows loaded with `$with` that the form neither renders nor validates are
65
+ * never sent. Returns `value` itself when `def` reaches no such field.
66
+ */
67
+ function omitSkippedNavFields(def, value) {
68
+ if (!hasNestedSkippedNavFields(def) && ownSkippedNavPaths(def).length === 0) return value;
69
+ const copy = require_clone.deepClone(value);
70
+ stripDef(def, copy);
71
+ return copy;
72
+ }
73
+ function stripDef(def, value) {
74
+ if (!require_path_utils.isPlainObject(value)) return;
75
+ const data = { value };
76
+ for (const path of ownSkippedNavPaths(def)) {
77
+ const dot = path.lastIndexOf(".");
78
+ const parent = dot < 0 ? value : require_path_utils.getByPath(data, path.slice(0, dot));
79
+ if (require_path_utils.isPlainObject(parent)) delete parent[path.slice(dot + 1)];
80
+ }
81
+ if (!hasNestedSkippedNavFields(def)) return;
82
+ for (const f of def.fields) if (f.path) stripField(f, require_path_utils.getByPath(data, f.path));
83
+ }
84
+ function stripField(field, value) {
85
+ if (value === null || typeof value !== "object") return;
86
+ if (require_types.isObjectField(field)) stripDef(field.objectDef, value);
87
+ else if (require_types.isArrayField(field)) {
88
+ if (Array.isArray(value)) for (const item of value) stripField(field.itemField, item);
89
+ } else if (require_types.isTupleField(field)) {
90
+ if (Array.isArray(value)) field.itemFields.forEach((f, i) => stripField(f, value[i]));
91
+ } else if (require_types.isUnionField(field)) {
92
+ const v = field.unionVariants[require_path_utils.detectUnionVariant(value, field.unionVariants)];
93
+ if (v?.def) stripDef(v.def, value);
94
+ else if (v?.itemField) stripField(v.itemField, value);
95
+ }
96
+ }
97
+ //#endregion
98
+ exports.hasNestedSkippedNavFields = hasNestedSkippedNavFields;
99
+ exports.isSkippedNavField = isSkippedNavField;
100
+ exports.omitSkippedNavFields = omitSkippedNavFields;
@@ -0,0 +1,13 @@
1
+ import { FormDef } from "./types.cjs";
2
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
+
4
+ //#region src/form/skipped-nav.d.ts
5
+ /**
6
+ * A deep copy of form data `value` (the unwrapped domain data of `def`'s type)
7
+ * without the navigation fields the form leaves out, at any depth: related
8
+ * rows loaded with `$with` that the form neither renders nor validates are
9
+ * never sent. Returns `value` itself when `def` reaches no such field.
10
+ */
11
+ declare function omitSkippedNavFields<T>(def: FormDef, value: T): T;
12
+ //#endregion
13
+ export { omitSkippedNavFields };
@@ -0,0 +1,13 @@
1
+ import { FormDef } from "./types.mjs";
2
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
+
4
+ //#region src/form/skipped-nav.d.ts
5
+ /**
6
+ * A deep copy of form data `value` (the unwrapped domain data of `def`'s type)
7
+ * without the navigation fields the form leaves out, at any depth: related
8
+ * rows loaded with `$with` that the form neither renders nor validates are
9
+ * never sent. Returns `value` itself when `def` reaches no such field.
10
+ */
11
+ declare function omitSkippedNavFields<T>(def: FormDef, value: T): T;
12
+ //#endregion
13
+ export { omitSkippedNavFields };
@@ -0,0 +1,98 @@
1
+ import "../shared/annotation-keys.mjs";
2
+ import { childFields, isArrayField, isObjectField, isTupleField, isUnionField } from "./types.mjs";
3
+ import { deepClone } from "./clone.mjs";
4
+ import { detectUnionVariant, getByPath, isPlainObject } from "./path-utils.mjs";
5
+ import { isNavRelation } from "@atscript/db/validator";
6
+ //#region src/form/skipped-nav.ts
7
+ /**
8
+ * Whether a form leaves this prop out: a navigation field (`@db.rel.from` /
9
+ * `.to` / `.via`) without a `@ui.form.*` annotation of its own. Navigation
10
+ * fields hold related rows (loaded with `$with`), not data the row's own form
11
+ * edits, and a two-way pair points back at the form's own type. Annotating one
12
+ * (`@ui.form.order`, `@ui.form.component`, …) opts it in.
13
+ */
14
+ function isSkippedNavField(prop) {
15
+ if (!isNavRelation(prop)) return false;
16
+ for (const key of prop.metadata.keys()) if (key.startsWith("ui.form.")) return false;
17
+ return true;
18
+ }
19
+ /** Per def: the paths of its own skipped navigation fields. */
20
+ const ownSkippedNav = /* @__PURE__ */ new WeakMap();
21
+ /** Per def: whether a skipped navigation field is reachable below its own props. */
22
+ const nestedSkippedNav = /* @__PURE__ */ new WeakMap();
23
+ /**
24
+ * The paths of `def`'s own props that are navigation fields the form leaves
25
+ * out — none below another one, which goes with it. Cached per def.
26
+ */
27
+ function ownSkippedNavPaths(def) {
28
+ let paths = ownSkippedNav.get(def);
29
+ if (!paths) {
30
+ paths = [];
31
+ for (const [path, prop] of def.flatMap) {
32
+ if (!path || paths.some((p) => path.startsWith(`${p}.`))) continue;
33
+ if (isSkippedNavField(prop)) paths.push(path);
34
+ }
35
+ ownSkippedNav.set(def, paths);
36
+ }
37
+ return paths;
38
+ }
39
+ /**
40
+ * Whether a def nested in `def` (an object field, an array item, a union
41
+ * variant, …) has a navigation field the form leaves out (see
42
+ * `isSkippedNavField`) — data a whole-value patch entry could carry. Cached
43
+ * per def; cycle-safe.
44
+ */
45
+ function hasNestedSkippedNavFields(def) {
46
+ const known = nestedSkippedNav.get(def);
47
+ if (known !== void 0) return known;
48
+ const hasOwn = (d) => d !== void 0 && ownSkippedNavPaths(d).length > 0;
49
+ const seen = /* @__PURE__ */ new Set();
50
+ const reaches = (f) => {
51
+ if (seen.has(f)) return false;
52
+ seen.add(f);
53
+ if (isObjectField(f) && hasOwn(f.objectDef)) return true;
54
+ if (isUnionField(f) && f.unionVariants.some((v) => hasOwn(v.def))) return true;
55
+ return childFields(f).some(reaches);
56
+ };
57
+ const result = def.fields.some(reaches);
58
+ nestedSkippedNav.set(def, result);
59
+ return result;
60
+ }
61
+ /**
62
+ * A deep copy of form data `value` (the unwrapped domain data of `def`'s type)
63
+ * without the navigation fields the form leaves out, at any depth: related
64
+ * rows loaded with `$with` that the form neither renders nor validates are
65
+ * never sent. Returns `value` itself when `def` reaches no such field.
66
+ */
67
+ function omitSkippedNavFields(def, value) {
68
+ if (!hasNestedSkippedNavFields(def) && ownSkippedNavPaths(def).length === 0) return value;
69
+ const copy = deepClone(value);
70
+ stripDef(def, copy);
71
+ return copy;
72
+ }
73
+ function stripDef(def, value) {
74
+ if (!isPlainObject(value)) return;
75
+ const data = { value };
76
+ for (const path of ownSkippedNavPaths(def)) {
77
+ const dot = path.lastIndexOf(".");
78
+ const parent = dot < 0 ? value : getByPath(data, path.slice(0, dot));
79
+ if (isPlainObject(parent)) delete parent[path.slice(dot + 1)];
80
+ }
81
+ if (!hasNestedSkippedNavFields(def)) return;
82
+ for (const f of def.fields) if (f.path) stripField(f, getByPath(data, f.path));
83
+ }
84
+ function stripField(field, value) {
85
+ if (value === null || typeof value !== "object") return;
86
+ if (isObjectField(field)) stripDef(field.objectDef, value);
87
+ else if (isArrayField(field)) {
88
+ if (Array.isArray(value)) for (const item of value) stripField(field.itemField, item);
89
+ } else if (isTupleField(field)) {
90
+ if (Array.isArray(value)) field.itemFields.forEach((f, i) => stripField(f, value[i]));
91
+ } else if (isUnionField(field)) {
92
+ const v = field.unionVariants[detectUnionVariant(value, field.unionVariants)];
93
+ if (v?.def) stripDef(v.def, value);
94
+ else if (v?.itemField) stripField(v.itemField, value);
95
+ }
96
+ }
97
+ //#endregion
98
+ export { hasNestedSkippedNavFields, isSkippedNavField, omitSkippedNavFields };
@@ -0,0 +1,40 @@
1
+ //#region src/form/types.ts
2
+ /** Type guard: checks if a field def is an array field. */
3
+ function isArrayField(field) {
4
+ return field.type === "array";
5
+ }
6
+ /** Type guard: checks if a field def is an object field. */
7
+ function isObjectField(field) {
8
+ return field.type === "object";
9
+ }
10
+ /** Type guard: checks if a field def is a union field. */
11
+ function isUnionField(field) {
12
+ return field.type === "union";
13
+ }
14
+ /** Type guard: checks if a field def is a tuple field. */
15
+ function isTupleField(field) {
16
+ return field.type === "tuple";
17
+ }
18
+ /**
19
+ * The field defs directly below `field`: an object's fields, an array's item,
20
+ * a tuple's items, each union variant's fields and item. A recursive type's
21
+ * def graph is cyclic: a walk over it tracks the fields it has seen.
22
+ */
23
+ function childFields(field) {
24
+ if (isObjectField(field)) return field.objectDef.fields;
25
+ if (isArrayField(field)) return [field.itemField];
26
+ if (isTupleField(field)) return field.itemFields;
27
+ if (!isUnionField(field)) return [];
28
+ const children = [];
29
+ for (const v of field.unionVariants) {
30
+ if (v.def) children.push(...v.def.fields);
31
+ if (v.itemField) children.push(v.itemField);
32
+ }
33
+ return children;
34
+ }
35
+ //#endregion
36
+ exports.childFields = childFields;
37
+ exports.isArrayField = isArrayField;
38
+ exports.isObjectField = isObjectField;
39
+ exports.isTupleField = isTupleField;
40
+ exports.isUnionField = isUnionField;
@@ -0,0 +1,147 @@
1
+ import { TFormEntryOptions, ValueHelpInfo } from "../value-help/types.cjs";
2
+ import { AsUiMessageCode } from "../messages.cjs";
3
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
4
+
5
+ //#region src/form/types.d.ts
6
+ /** Form action metadata — the action id and display label. */
7
+ interface TFormAction {
8
+ id: string;
9
+ label: string;
10
+ }
11
+ /**
12
+ * A single form field definition — thin pointer to the ATScript prop.
13
+ *
14
+ * All metadata (label, disabled, options, etc.) lives in `prop.metadata`
15
+ * and is resolved on demand via resolve utilities.
16
+ */
17
+ interface FormFieldDef {
18
+ /** Dot-separated path relative to the parent data context. `''` = root. */
19
+ path: string;
20
+ prop: TAtscriptAnnotatedType;
21
+ /**
22
+ * Render-key the renderer dispatches on. For structured kinds (array,
23
+ * object, tuple, multi-variant union) this stays the kind name so that
24
+ * `isArrayField`/`isObjectField`/`isUnionField`/`isTupleField` keep
25
+ * working downstream (validator resetValue, child path provide, AsArray
26
+ * recursion). Primitives may store an `@ui.form.type`/`@ui.type`
27
+ * override here directly — for those there is no structural behaviour
28
+ * to preserve.
29
+ */
30
+ type: string;
31
+ /**
32
+ * Optional `@ui.form.type` (or `@ui.type`) override for structured
33
+ * kinds. When set, the renderer looks this up in the `types` map FIRST
34
+ * and falls back to `type` only when the map has no entry. Letting the
35
+ * override live in a separate field keeps the structural type guards
36
+ * (`isArrayField` et al.) on `type` honest while still allowing a
37
+ * consumer to attach a flat custom widget to e.g. a `string[]`.
38
+ */
39
+ customType?: string;
40
+ phantom: boolean;
41
+ name: string;
42
+ /** True when no `ui.fn.*` metadata keys exist. Vue perf flag. */
43
+ allStatic: boolean;
44
+ /**
45
+ * `@ui.form.pushDown` — render this field below the submit button in its
46
+ * own grid, instead of in the main field grid above submit. Set on
47
+ * top-level form fields (typically secondary `ui.action` links). The field
48
+ * stays in `fields[]` for validation/data; only its render slot moves.
49
+ */
50
+ pushDown: boolean;
51
+ /**
52
+ * Value-help target for an FK field — `{ url, targetField }` resolved once by
53
+ * `extractValueHelp` while the def is built (since 0.1.134; mirrors
54
+ * `ColumnDef.valueHelpInfo` on the table side). `undefined` for every field
55
+ * that is not an FK. Renderers read this instead of re-walking the
56
+ * annotations per field, which also keeps the annotation dependency out of
57
+ * the component layer.
58
+ */
59
+ valueHelpInfo?: ValueHelpInfo;
60
+ /**
61
+ * Server-owned field: a `@db.column.derived` one (read from the type
62
+ * metadata), a computed view column (`CreateFormDefOptions.metaFields`) or,
63
+ * in an edit form, an update-stamped one (see `CreateFormDefOptions.mode`).
64
+ * Rendered read-only, exempt from form validation and never sent by
65
+ * `buildFormDiff` (the server drops or overwrites a written value anyway).
66
+ * Since 0.1.144.
67
+ */
68
+ derived?: true;
69
+ /**
70
+ * The enclosing prop whose `@ui.literalLabel` labels also apply to this
71
+ * field's values: the array prop of an item field (`flags: boolean[]`) or the
72
+ * union prop of a variant (`active: boolean | null`). Set only when that prop
73
+ * declares labels; pass it to `resolveOptions` as `labelsFrom`. Since 0.1.165.
74
+ */
75
+ labelsFrom?: TAtscriptAnnotatedType;
76
+ }
77
+ /**
78
+ * Complete form definition — produced by createFormDef().
79
+ * Form-level metadata (title, submit) resolved on demand via resolveFormProp.
80
+ */
81
+ interface FormDef {
82
+ type: TAtscriptAnnotatedType;
83
+ /** Root field representing the entire form. For interface types this is `type='object'`; for single-type forms it is a leaf field. */
84
+ rootField: FormFieldDef;
85
+ fields: FormFieldDef[];
86
+ /**
87
+ * Render partition of `fields` by `@ui.form.pushDown`, precomputed once so
88
+ * the renderer never re-scans per frame. `mainFields` (above submit) plus
89
+ * `pushDownFields` (below submit) cover `fields` exactly once. In the common
90
+ * case nothing is pushed down: `mainFields === fields` (same ref) and
91
+ * `pushDownFields` is empty.
92
+ */
93
+ mainFields: FormFieldDef[];
94
+ pushDownFields: FormFieldDef[];
95
+ flatMap: Map<string, TAtscriptAnnotatedType>;
96
+ }
97
+ /** One branch of a union type — used by union fields and union array items. */
98
+ interface FormUnionVariant {
99
+ /** Display label — from @meta.label or auto-generated (e.g. "1. String") */
100
+ label: string;
101
+ /**
102
+ * The UI text code of an auto-generated label's type name
103
+ * (`UI_FORM_TYPE_STRING`); `label` ends with its English text. Render the
104
+ * name in the UI locale with it. Since 0.1.165.
105
+ */
106
+ labelCode?: AsUiMessageCode;
107
+ /** The annotated type for this variant */
108
+ type: TAtscriptAnnotatedType;
109
+ /** Pre-built FormDef for object variants (undefined for primitives) */
110
+ def?: FormDef;
111
+ /** Pre-built field def for primitive variants (undefined for objects) */
112
+ itemField?: FormFieldDef;
113
+ /** Design type for primitive variants ('string', 'number', 'boolean') */
114
+ designType?: string;
115
+ }
116
+ /** Extended field def for array-typed fields. */
117
+ interface FormArrayFieldDef extends FormFieldDef {
118
+ /** ATScript annotated type of array items (from TAtscriptTypeArray.of) */
119
+ itemType: TAtscriptAnnotatedType;
120
+ /** Pre-built template field def for items (path=''). */
121
+ itemField: FormFieldDef;
122
+ }
123
+ /** Extended field def for object (interface/type) nested fields. */
124
+ interface FormObjectFieldDef extends FormFieldDef {
125
+ /** Pre-built FormDef for the nested object's fields */
126
+ objectDef: FormDef;
127
+ }
128
+ /** Extended field def for union fields — standalone union props and union array items. */
129
+ interface FormUnionFieldDef extends FormFieldDef {
130
+ /** Available union branches. */
131
+ unionVariants: FormUnionVariant[];
132
+ }
133
+ /** Extended field def for tuple fields — fixed-length with typed positions. */
134
+ interface FormTupleFieldDef extends FormFieldDef {
135
+ /** Pre-built field defs, one per tuple position. */
136
+ itemFields: FormFieldDef[];
137
+ }
138
+ /** Type guard: checks if a field def is an array field. */
139
+ declare function isArrayField(field: FormFieldDef): field is FormArrayFieldDef;
140
+ /** Type guard: checks if a field def is an object field. */
141
+ declare function isObjectField(field: FormFieldDef): field is FormObjectFieldDef;
142
+ /** Type guard: checks if a field def is a union field. */
143
+ declare function isUnionField(field: FormFieldDef): field is FormUnionFieldDef;
144
+ /** Type guard: checks if a field def is a tuple field. */
145
+ declare function isTupleField(field: FormFieldDef): field is FormTupleFieldDef;
146
+ //#endregion
147
+ export { FormArrayFieldDef, FormDef, FormFieldDef, FormObjectFieldDef, FormTupleFieldDef, FormUnionFieldDef, FormUnionVariant, TFormAction, isArrayField, isObjectField, isTupleField, isUnionField };