@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.
- package/dist/client-factory.cjs +27 -0
- package/dist/client-factory.d.cts +58 -0
- package/dist/client-factory.d.mts +58 -0
- package/dist/client-factory.mjs +25 -0
- package/dist/form/apply.cjs +38 -0
- package/dist/form/apply.d.cts +36 -0
- package/dist/form/apply.d.mts +36 -0
- package/dist/form/apply.mjs +38 -0
- package/dist/form/clone.cjs +30 -0
- package/dist/form/clone.d.cts +23 -0
- package/dist/form/clone.d.mts +23 -0
- package/dist/form/clone.mjs +30 -0
- package/dist/form/create-form-def.cjs +462 -0
- package/dist/form/create-form-def.d.cts +67 -0
- package/dist/form/create-form-def.d.mts +67 -0
- package/dist/form/create-form-def.mjs +460 -0
- package/dist/form/decimal-format.cjs +324 -0
- package/dist/form/decimal-format.d.cts +86 -0
- package/dist/form/decimal-format.d.mts +86 -0
- package/dist/form/decimal-format.mjs +315 -0
- package/dist/form/diff.cjs +458 -0
- package/dist/form/diff.d.cts +80 -0
- package/dist/form/diff.d.mts +80 -0
- package/dist/form/diff.mjs +457 -0
- package/dist/form/dirty.cjs +65 -0
- package/dist/form/dirty.d.cts +47 -0
- package/dist/form/dirty.d.mts +47 -0
- package/dist/form/dirty.mjs +64 -0
- package/dist/form/error-utils.cjs +97 -0
- package/dist/form/error-utils.d.cts +58 -0
- package/dist/form/error-utils.d.mts +58 -0
- package/dist/form/error-utils.mjs +92 -0
- package/dist/form/form-actions.cjs +30 -0
- package/dist/form/form-actions.d.cts +17 -0
- package/dist/form/form-actions.d.mts +17 -0
- package/dist/form/form-actions.mjs +30 -0
- package/dist/form/grid.cjs +69 -0
- package/dist/form/grid.d.cts +49 -0
- package/dist/form/grid.d.mts +49 -0
- package/dist/form/grid.mjs +64 -0
- package/dist/form/labels.cjs +13 -0
- package/dist/form/labels.d.cts +11 -0
- package/dist/form/labels.d.mts +11 -0
- package/dist/form/labels.mjs +13 -0
- package/dist/form/measurement.cjs +20 -0
- package/dist/form/measurement.d.cts +29 -0
- package/dist/form/measurement.d.mts +29 -0
- package/dist/form/measurement.mjs +20 -0
- package/dist/form/path-utils.cjs +182 -0
- package/dist/form/path-utils.d.cts +47 -0
- package/dist/form/path-utils.d.mts +47 -0
- package/dist/form/path-utils.mjs +175 -0
- package/dist/form/rebase.cjs +89 -0
- package/dist/form/rebase.d.cts +61 -0
- package/dist/form/rebase.d.mts +61 -0
- package/dist/form/rebase.mjs +89 -0
- package/dist/form/skipped-nav.cjs +100 -0
- package/dist/form/skipped-nav.d.cts +13 -0
- package/dist/form/skipped-nav.d.mts +13 -0
- package/dist/form/skipped-nav.mjs +98 -0
- package/dist/form/types.cjs +40 -0
- package/dist/form/types.d.cts +147 -0
- package/dist/form/types.d.mts +147 -0
- package/dist/form/types.mjs +36 -0
- package/dist/form/union-detect.cjs +46 -0
- package/dist/form/union-detect.d.cts +22 -0
- package/dist/form/union-detect.d.mts +22 -0
- package/dist/form/union-detect.mjs +46 -0
- package/dist/form/validate.cjs +186 -0
- package/dist/form/validate.d.cts +81 -0
- package/dist/form/validate.d.mts +81 -0
- package/dist/form/validate.mjs +182 -0
- package/dist/i18n/ui-texts.cjs +135 -0
- package/dist/i18n/ui-texts.d.cts +81 -0
- package/dist/i18n/ui-texts.d.mts +81 -0
- package/dist/i18n/ui-texts.mjs +132 -0
- package/dist/index.cjs +223 -3360
- package/dist/index.d.cts +39 -1693
- package/dist/index.d.mts +39 -1693
- package/dist/index.mjs +36 -3179
- package/dist/messages.cjs +301 -0
- package/dist/messages.d.cts +302 -0
- package/dist/messages.d.mts +302 -0
- package/dist/messages.mjs +300 -0
- package/dist/nav/model-routes.cjs +59 -0
- package/dist/nav/model-routes.d.cts +33 -0
- package/dist/nav/model-routes.d.mts +33 -0
- package/dist/nav/model-routes.mjs +59 -0
- package/dist/plugin/annotations.cjs +592 -0
- package/dist/plugin/annotations.mjs +592 -0
- package/dist/plugin/primitives.cjs +30 -0
- package/dist/plugin/primitives.mjs +30 -0
- package/dist/plugin/value-help-validation.cjs +429 -0
- package/dist/plugin/value-help-validation.mjs +423 -0
- package/dist/plugin.cjs +4 -1001
- package/dist/plugin.mjs +2 -999
- package/dist/shared/annotation-keys.cjs +189 -0
- package/dist/shared/annotation-keys.d.cts +82 -0
- package/dist/shared/annotation-keys.d.mts +82 -0
- package/dist/shared/annotation-keys.mjs +97 -0
- package/dist/shared/field-resolver.cjs +123 -0
- package/dist/shared/field-resolver.d.cts +77 -0
- package/dist/shared/field-resolver.d.mts +77 -0
- package/dist/shared/field-resolver.mjs +110 -0
- package/dist/shared/meta-cache.cjs +282 -0
- package/dist/shared/meta-cache.d.cts +130 -0
- package/dist/shared/meta-cache.d.mts +130 -0
- package/dist/shared/meta-cache.mjs +275 -0
- package/dist/shared/str.cjs +19 -0
- package/dist/shared/str.d.cts +7 -0
- package/dist/shared/str.d.mts +7 -0
- package/dist/shared/str.mjs +17 -0
- package/dist/table/column-resolver.cjs +17 -0
- package/dist/table/column-resolver.d.cts +11 -0
- package/dist/table/column-resolver.d.mts +11 -0
- package/dist/table/column-resolver.mjs +15 -0
- package/dist/table/create-table-def.cjs +242 -0
- package/dist/table/create-table-def.d.cts +19 -0
- package/dist/table/create-table-def.d.mts +19 -0
- package/dist/table/create-table-def.mjs +242 -0
- package/dist/table/navigate-href.cjs +45 -0
- package/dist/table/navigate-href.d.cts +31 -0
- package/dist/table/navigate-href.d.mts +31 -0
- package/dist/table/navigate-href.mjs +45 -0
- package/dist/table/types.d.cts +290 -0
- package/dist/table/types.d.mts +290 -0
- package/dist/table/value-kind.cjs +20 -0
- package/dist/table/value-kind.d.cts +16 -0
- package/dist/table/value-kind.d.mts +16 -0
- package/dist/table/value-kind.mjs +19 -0
- package/dist/value-help/dict-paths.cjs +17 -0
- package/dist/value-help/dict-paths.d.cts +11 -0
- package/dist/value-help/dict-paths.d.mts +11 -0
- package/dist/value-help/dict-paths.mjs +17 -0
- package/dist/value-help/distinct-client.cjs +51 -0
- package/dist/value-help/distinct-client.d.cts +40 -0
- package/dist/value-help/distinct-client.d.mts +40 -0
- package/dist/value-help/distinct-client.mjs +50 -0
- package/dist/value-help/extract-literals.cjs +115 -0
- package/dist/value-help/extract-literals.d.cts +44 -0
- package/dist/value-help/extract-literals.d.mts +44 -0
- package/dist/value-help/extract-literals.mjs +111 -0
- package/dist/value-help/extract-ref.cjs +100 -0
- package/dist/value-help/extract-ref.d.cts +37 -0
- package/dist/value-help/extract-ref.d.mts +37 -0
- package/dist/value-help/extract-ref.mjs +100 -0
- package/dist/value-help/filter-tree.cjs +45 -0
- package/dist/value-help/filter-tree.mjs +45 -0
- package/dist/value-help/index.d.mts +8 -0
- package/dist/value-help/resolve-options.cjs +68 -0
- package/dist/value-help/resolve-options.d.cts +40 -0
- package/dist/value-help/resolve-options.d.mts +40 -0
- package/dist/value-help/resolve-options.mjs +64 -0
- package/dist/value-help/resolve.cjs +66 -0
- package/dist/value-help/resolve.d.cts +36 -0
- package/dist/value-help/resolve.d.mts +36 -0
- package/dist/value-help/resolve.mjs +65 -0
- package/dist/value-help/types.d.cts +41 -0
- package/dist/value-help/types.d.mts +41 -0
- package/dist/value-help/value-help-client.cjs +136 -0
- package/dist/value-help/value-help-client.d.cts +67 -0
- package/dist/value-help/value-help-client.d.mts +67 -0
- package/dist/value-help/value-help-client.mjs +134 -0
- package/package.json +15 -10
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "../shared/annotation-keys.mjs";
|
|
2
|
+
import { getFieldMeta } from "../shared/field-resolver.mjs";
|
|
3
|
+
import { getUiTexts } from "../i18n/ui-texts.mjs";
|
|
4
|
+
//#region src/form/labels.ts
|
|
5
|
+
/**
|
|
6
|
+
* Singular label for an array field (used by AsArray for "Add <singular>"):
|
|
7
|
+
* `@ui.form.label.singular`, else `t("UI_ITEM")` ("item").
|
|
8
|
+
*/
|
|
9
|
+
function resolveSingularLabel(meta, t = getUiTexts().t) {
|
|
10
|
+
return meta && getFieldMeta(meta, "ui.form.label.singular") || t("UI_ITEM");
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { resolveSingularLabel };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const require_annotation_keys = require("../shared/annotation-keys.cjs");
|
|
2
|
+
const require_field_resolver = require("../shared/field-resolver.cjs");
|
|
3
|
+
//#region src/form/measurement.ts
|
|
4
|
+
/**
|
|
5
|
+
* Read measurement annotations off a single field prop. Returns `undefined`
|
|
6
|
+
* for any annotation that's absent — callers can spread the result into a
|
|
7
|
+
* larger record.
|
|
8
|
+
*/
|
|
9
|
+
function extractMeasurement(prop) {
|
|
10
|
+
const precisionMeta = require_field_resolver.getFieldMeta(prop, require_annotation_keys.DB_COLUMN_PRECISION);
|
|
11
|
+
return {
|
|
12
|
+
currencyCode: require_field_resolver.getFieldMeta(prop, require_annotation_keys.DB_AMOUNT_CURRENCY),
|
|
13
|
+
currencyRefField: require_field_resolver.getFieldMeta(prop, require_annotation_keys.DB_AMOUNT_CURRENCY_REF),
|
|
14
|
+
unitCode: require_field_resolver.getFieldMeta(prop, require_annotation_keys.DB_UNIT),
|
|
15
|
+
unitRefField: require_field_resolver.getFieldMeta(prop, require_annotation_keys.DB_UNIT_REF),
|
|
16
|
+
precisionScale: precisionMeta?.scale
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.extractMeasurement = extractMeasurement;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
2
|
+
|
|
3
|
+
//#region src/form/measurement.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolved measurement annotations — currency / unit-of-measure / numeric
|
|
6
|
+
* precision. Read once at form/table-def construction time and surfaced as
|
|
7
|
+
* already-resolved values so downstream renderers (cells, default form
|
|
8
|
+
* components, custom inputs) never re-read annotation metadata.
|
|
9
|
+
*/
|
|
10
|
+
interface MeasurementInfo {
|
|
11
|
+
/** Literal currency code from `@db.amount.currency 'EUR'`. */
|
|
12
|
+
currencyCode?: string;
|
|
13
|
+
/** Sibling-field path from `@db.amount.currency.ref 'fieldName'`. */
|
|
14
|
+
currencyRefField?: string;
|
|
15
|
+
/** Literal unit-of-measure from `@db.unit 'kg'`. */
|
|
16
|
+
unitCode?: string;
|
|
17
|
+
/** Sibling-field path from `@db.unit.ref 'fieldName'`. */
|
|
18
|
+
unitRefField?: string;
|
|
19
|
+
/** Decimal scale (fraction digits) — second arg of `@db.column.precision precision, scale`. */
|
|
20
|
+
precisionScale?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Read measurement annotations off a single field prop. Returns `undefined`
|
|
24
|
+
* for any annotation that's absent — callers can spread the result into a
|
|
25
|
+
* larger record.
|
|
26
|
+
*/
|
|
27
|
+
declare function extractMeasurement(prop: TAtscriptAnnotatedType): MeasurementInfo;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { MeasurementInfo, extractMeasurement };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
2
|
+
|
|
3
|
+
//#region src/form/measurement.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolved measurement annotations — currency / unit-of-measure / numeric
|
|
6
|
+
* precision. Read once at form/table-def construction time and surfaced as
|
|
7
|
+
* already-resolved values so downstream renderers (cells, default form
|
|
8
|
+
* components, custom inputs) never re-read annotation metadata.
|
|
9
|
+
*/
|
|
10
|
+
interface MeasurementInfo {
|
|
11
|
+
/** Literal currency code from `@db.amount.currency 'EUR'`. */
|
|
12
|
+
currencyCode?: string;
|
|
13
|
+
/** Sibling-field path from `@db.amount.currency.ref 'fieldName'`. */
|
|
14
|
+
currencyRefField?: string;
|
|
15
|
+
/** Literal unit-of-measure from `@db.unit 'kg'`. */
|
|
16
|
+
unitCode?: string;
|
|
17
|
+
/** Sibling-field path from `@db.unit.ref 'fieldName'`. */
|
|
18
|
+
unitRefField?: string;
|
|
19
|
+
/** Decimal scale (fraction digits) — second arg of `@db.column.precision precision, scale`. */
|
|
20
|
+
precisionScale?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Read measurement annotations off a single field prop. Returns `undefined`
|
|
24
|
+
* for any annotation that's absent — callers can spread the result into a
|
|
25
|
+
* larger record.
|
|
26
|
+
*/
|
|
27
|
+
declare function extractMeasurement(prop: TAtscriptAnnotatedType): MeasurementInfo;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { MeasurementInfo, extractMeasurement };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_UNIT, DB_UNIT_REF } from "../shared/annotation-keys.mjs";
|
|
2
|
+
import { getFieldMeta } from "../shared/field-resolver.mjs";
|
|
3
|
+
//#region src/form/measurement.ts
|
|
4
|
+
/**
|
|
5
|
+
* Read measurement annotations off a single field prop. Returns `undefined`
|
|
6
|
+
* for any annotation that's absent — callers can spread the result into a
|
|
7
|
+
* larger record.
|
|
8
|
+
*/
|
|
9
|
+
function extractMeasurement(prop) {
|
|
10
|
+
const precisionMeta = getFieldMeta(prop, DB_COLUMN_PRECISION);
|
|
11
|
+
return {
|
|
12
|
+
currencyCode: getFieldMeta(prop, DB_AMOUNT_CURRENCY),
|
|
13
|
+
currencyRefField: getFieldMeta(prop, DB_AMOUNT_CURRENCY_REF),
|
|
14
|
+
unitCode: getFieldMeta(prop, DB_UNIT),
|
|
15
|
+
unitRefField: getFieldMeta(prop, DB_UNIT_REF),
|
|
16
|
+
precisionScale: precisionMeta?.scale
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { extractMeasurement };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
const require_annotation_keys = require("../shared/annotation-keys.cjs");
|
|
2
|
+
const require_field_resolver = require("../shared/field-resolver.cjs");
|
|
3
|
+
let _atscript_typescript_utils = require("@atscript/typescript/utils");
|
|
4
|
+
//#region src/form/path-utils.ts
|
|
5
|
+
/**
|
|
6
|
+
* Joins a dot-separated path prefix with a segment. Empty-safe on both
|
|
7
|
+
* sides: an empty segment returns the prefix as-is, an empty prefix
|
|
8
|
+
* returns the segment as-is (no leading/trailing dots).
|
|
9
|
+
*/
|
|
10
|
+
function joinPath(prefix, segment) {
|
|
11
|
+
if (!segment) return prefix;
|
|
12
|
+
return prefix ? `${prefix}.${segment}` : segment;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Gets a nested value by dot-separated path.
|
|
16
|
+
* Always dereferences `obj.value` first (form data is wrapped in `{ value: domainData }`).
|
|
17
|
+
* When `path` is empty, returns the root domain data (`obj.value`).
|
|
18
|
+
*/
|
|
19
|
+
function getByPath(obj, path) {
|
|
20
|
+
const root = obj.value;
|
|
21
|
+
if (!path) return root;
|
|
22
|
+
const keys = path.split(".");
|
|
23
|
+
let current = root;
|
|
24
|
+
for (const key of keys) {
|
|
25
|
+
if (current === null || current === void 0 || typeof current !== "object") return void 0;
|
|
26
|
+
current = current[key];
|
|
27
|
+
}
|
|
28
|
+
return current;
|
|
29
|
+
}
|
|
30
|
+
/** A non-null, non-array object. */
|
|
31
|
+
function isPlainObject(v) {
|
|
32
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
33
|
+
}
|
|
34
|
+
/** An array index path segment. */
|
|
35
|
+
const INDEX_RE = /^\d+$/;
|
|
36
|
+
/**
|
|
37
|
+
* Sets a nested value by dot-separated path.
|
|
38
|
+
* Always dereferences `obj.value` first (form data is wrapped in `{ value: domainData }`).
|
|
39
|
+
* When `path` is empty, sets the root domain data (`obj.value = value`).
|
|
40
|
+
* Creates missing containers on the way, the root included: an array where
|
|
41
|
+
* the next segment is an index (`items.0.name`), else an object.
|
|
42
|
+
*/
|
|
43
|
+
function setByPath(obj, path, value) {
|
|
44
|
+
if (!path) {
|
|
45
|
+
obj.value = value;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const keys = path.split(".");
|
|
49
|
+
const last = keys.pop();
|
|
50
|
+
if (last === void 0) return;
|
|
51
|
+
const containerFor = (next) => INDEX_RE.test(next) ? [] : {};
|
|
52
|
+
if (obj.value === null || typeof obj.value !== "object") obj.value = containerFor(keys[0] ?? last);
|
|
53
|
+
let current = obj.value;
|
|
54
|
+
for (let i = 0; i < keys.length; i++) {
|
|
55
|
+
const key = keys[i];
|
|
56
|
+
if (current[key] === null || current[key] === void 0 || typeof current[key] !== "object") current[key] = containerFor(keys[i + 1] ?? last);
|
|
57
|
+
current = current[key];
|
|
58
|
+
}
|
|
59
|
+
current[last] = value;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Deletes the own key at a dot-separated path (form-data wrapper aware — derefs
|
|
63
|
+
* `obj.value` first). Walks to the parent WITHOUT vivifying intermediate nodes:
|
|
64
|
+
* if any ancestor is missing, the call is a no-op (nothing to delete).
|
|
65
|
+
*
|
|
66
|
+
* Unlike `setByPath(obj, path, undefined)`, this leaves NO own key behind — the
|
|
67
|
+
* leaf reads as absent (`'k' in parent === false`), which keeps `deepEqual`
|
|
68
|
+
* structural comparisons in sync (a present `undefined` own-key and an absent
|
|
69
|
+
* key are NOT structurally equal under the own-key walk). Used by
|
|
70
|
+
* {@link applyFormChanges} to apply a clear-to-`undefined` change as a delete.
|
|
71
|
+
*
|
|
72
|
+
* Empty path clears the root domain value (`obj.value = undefined`).
|
|
73
|
+
*/
|
|
74
|
+
function deleteByPath(obj, path) {
|
|
75
|
+
if (!path) {
|
|
76
|
+
obj.value = void 0;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const keys = path.split(".");
|
|
80
|
+
const last = keys.pop();
|
|
81
|
+
if (last === void 0) return;
|
|
82
|
+
let current = obj.value;
|
|
83
|
+
for (const key of keys) {
|
|
84
|
+
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
85
|
+
current = current[key];
|
|
86
|
+
}
|
|
87
|
+
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
88
|
+
delete current[last];
|
|
89
|
+
}
|
|
90
|
+
function parseStaticDefault(raw, prop) {
|
|
91
|
+
if (typeof raw !== "string") return raw;
|
|
92
|
+
if (prop.type.kind === "" && prop.type.designType === "string") return raw;
|
|
93
|
+
try {
|
|
94
|
+
return JSON.parse(raw);
|
|
95
|
+
} catch {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** Cached default resolver — reused when no resolver is provided. */
|
|
100
|
+
const defaultValueResolver = createFormValueResolver();
|
|
101
|
+
function createFormValueResolver(data = {}, context = {}) {
|
|
102
|
+
return (prop, _path) => {
|
|
103
|
+
return require_field_resolver.resolveFieldProp(prop, require_annotation_keys.UI_FORM_FN_VALUE, require_annotation_keys.META_DEFAULT, {
|
|
104
|
+
v: void 0,
|
|
105
|
+
data,
|
|
106
|
+
context,
|
|
107
|
+
entry: void 0
|
|
108
|
+
}, { transform: (raw) => parseStaticDefault(raw, prop) });
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Type-appropriate "defined-but-empty" fallback for primitive design types
|
|
113
|
+
* whose structural default in atscript's `finalDefault` table is
|
|
114
|
+
* `undefined`. Without this, `createFormData` on an optional `decimal`
|
|
115
|
+
* field (or any other primitive missed by atscript's table) returns
|
|
116
|
+
* `undefined` — but `createFormData` is called from "explicit add"
|
|
117
|
+
* contexts (optional-toggle, array-add, tuple-pad, union-pick) where the
|
|
118
|
+
* caller's intent is "give me a value the renderer can edit", not "no
|
|
119
|
+
* value yet". Returning `undefined` leaves the empty-state placeholder
|
|
120
|
+
* stuck in AsFieldShell.
|
|
121
|
+
*
|
|
122
|
+
* `decimal → "0"` mirrors the `number → 0` default — the atscript runtime
|
|
123
|
+
* validator (≥ 0.1.54) rejects `""` for decimal fields, so committing the
|
|
124
|
+
* canonical zero is the only init that survives a submit-without-edit.
|
|
125
|
+
* `useAsDecimal` pads the display to the field's effective scale, so the
|
|
126
|
+
* user sees `0.00` / `0.000` per the `@db.column.precision` annotation.
|
|
127
|
+
*/
|
|
128
|
+
function primitiveInitFallback(prop) {
|
|
129
|
+
if (prop.type.kind !== "") return void 0;
|
|
130
|
+
switch (prop.type.designType) {
|
|
131
|
+
case "decimal": return "0";
|
|
132
|
+
default: return;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function createFormData(type, resolver) {
|
|
136
|
+
let value = (0, _atscript_typescript_utils.createDataFromAnnotatedType)(type, { mode: resolver ?? defaultValueResolver });
|
|
137
|
+
if (value === void 0) value = primitiveInitFallback(type);
|
|
138
|
+
return { value };
|
|
139
|
+
}
|
|
140
|
+
const variantValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
141
|
+
function getVariantValidator(variant) {
|
|
142
|
+
let v = variantValidatorCache.get(variant.type);
|
|
143
|
+
if (!v) {
|
|
144
|
+
v = variant.type.validator();
|
|
145
|
+
variantValidatorCache.set(variant.type, v);
|
|
146
|
+
}
|
|
147
|
+
return v;
|
|
148
|
+
}
|
|
149
|
+
const variantsDiscriminatorCache = /* @__PURE__ */ new WeakMap();
|
|
150
|
+
function getVariantsDiscriminator(variants) {
|
|
151
|
+
let cached = variantsDiscriminatorCache.get(variants);
|
|
152
|
+
if (cached === void 0) {
|
|
153
|
+
cached = (0, _atscript_typescript_utils.detectDiscriminator)(variants.map((v) => v.type));
|
|
154
|
+
variantsDiscriminatorCache.set(variants, cached);
|
|
155
|
+
}
|
|
156
|
+
return cached;
|
|
157
|
+
}
|
|
158
|
+
function detectUnionVariant(value, variants) {
|
|
159
|
+
if (variants.length <= 1) return 0;
|
|
160
|
+
const disc = getVariantsDiscriminator(variants);
|
|
161
|
+
if (disc && value !== null && typeof value === "object") {
|
|
162
|
+
const tag = value[disc.propertyName];
|
|
163
|
+
const key = String(tag);
|
|
164
|
+
if (Object.prototype.hasOwnProperty.call(disc.indexMapping, key)) {
|
|
165
|
+
const idx = disc.indexMapping[key];
|
|
166
|
+
if (idx !== void 0) return idx;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
for (let i = 0; i < variants.length; i++) try {
|
|
170
|
+
if (getVariantValidator(variants[i]).validate(value, true)) return i;
|
|
171
|
+
} catch {}
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
exports.createFormData = createFormData;
|
|
176
|
+
exports.createFormValueResolver = createFormValueResolver;
|
|
177
|
+
exports.deleteByPath = deleteByPath;
|
|
178
|
+
exports.detectUnionVariant = detectUnionVariant;
|
|
179
|
+
exports.getByPath = getByPath;
|
|
180
|
+
exports.isPlainObject = isPlainObject;
|
|
181
|
+
exports.joinPath = joinPath;
|
|
182
|
+
exports.setByPath = setByPath;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { FormUnionVariant } from "./types.cjs";
|
|
2
|
+
import { TAtscriptAnnotatedType, TAtscriptDataType } from "@atscript/typescript/utils";
|
|
3
|
+
|
|
4
|
+
//#region src/form/path-utils.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Joins a dot-separated path prefix with a segment. Empty-safe on both
|
|
7
|
+
* sides: an empty segment returns the prefix as-is, an empty prefix
|
|
8
|
+
* returns the segment as-is (no leading/trailing dots).
|
|
9
|
+
*/
|
|
10
|
+
declare function joinPath(prefix: string, segment: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Gets a nested value by dot-separated path.
|
|
13
|
+
* Always dereferences `obj.value` first (form data is wrapped in `{ value: domainData }`).
|
|
14
|
+
* When `path` is empty, returns the root domain data (`obj.value`).
|
|
15
|
+
*/
|
|
16
|
+
declare function getByPath(obj: Record<string, unknown>, path: string): unknown;
|
|
17
|
+
/**
|
|
18
|
+
* Sets a nested value by dot-separated path.
|
|
19
|
+
* Always dereferences `obj.value` first (form data is wrapped in `{ value: domainData }`).
|
|
20
|
+
* When `path` is empty, sets the root domain data (`obj.value = value`).
|
|
21
|
+
* Creates missing containers on the way, the root included: an array where
|
|
22
|
+
* the next segment is an index (`items.0.name`), else an object.
|
|
23
|
+
*/
|
|
24
|
+
declare function setByPath(obj: Record<string, unknown>, path: string, value: unknown): void;
|
|
25
|
+
/**
|
|
26
|
+
* Deletes the own key at a dot-separated path (form-data wrapper aware — derefs
|
|
27
|
+
* `obj.value` first). Walks to the parent WITHOUT vivifying intermediate nodes:
|
|
28
|
+
* if any ancestor is missing, the call is a no-op (nothing to delete).
|
|
29
|
+
*
|
|
30
|
+
* Unlike `setByPath(obj, path, undefined)`, this leaves NO own key behind — the
|
|
31
|
+
* leaf reads as absent (`'k' in parent === false`), which keeps `deepEqual`
|
|
32
|
+
* structural comparisons in sync (a present `undefined` own-key and an absent
|
|
33
|
+
* key are NOT structurally equal under the own-key walk). Used by
|
|
34
|
+
* {@link applyFormChanges} to apply a clear-to-`undefined` change as a delete.
|
|
35
|
+
*
|
|
36
|
+
* Empty path clears the root domain value (`obj.value = undefined`).
|
|
37
|
+
*/
|
|
38
|
+
declare function deleteByPath(obj: Record<string, unknown>, path: string): void;
|
|
39
|
+
/** Value resolver function type — created once per form, reused across calls. */
|
|
40
|
+
type TFormValueResolver = (prop: TAtscriptAnnotatedType, path: string) => unknown;
|
|
41
|
+
declare function createFormValueResolver(data?: Record<string, unknown>, context?: Record<string, unknown>): TFormValueResolver;
|
|
42
|
+
declare function createFormData<T extends TAtscriptAnnotatedType>(type: T, resolver?: TFormValueResolver): {
|
|
43
|
+
value: TAtscriptDataType<T>;
|
|
44
|
+
};
|
|
45
|
+
declare function detectUnionVariant(value: unknown, variants: FormUnionVariant[]): number;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { TFormValueResolver, createFormData, createFormValueResolver, deleteByPath, detectUnionVariant, getByPath, joinPath, setByPath };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { FormUnionVariant } from "./types.mjs";
|
|
2
|
+
import { TAtscriptAnnotatedType, TAtscriptDataType } from "@atscript/typescript/utils";
|
|
3
|
+
|
|
4
|
+
//#region src/form/path-utils.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Joins a dot-separated path prefix with a segment. Empty-safe on both
|
|
7
|
+
* sides: an empty segment returns the prefix as-is, an empty prefix
|
|
8
|
+
* returns the segment as-is (no leading/trailing dots).
|
|
9
|
+
*/
|
|
10
|
+
declare function joinPath(prefix: string, segment: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Gets a nested value by dot-separated path.
|
|
13
|
+
* Always dereferences `obj.value` first (form data is wrapped in `{ value: domainData }`).
|
|
14
|
+
* When `path` is empty, returns the root domain data (`obj.value`).
|
|
15
|
+
*/
|
|
16
|
+
declare function getByPath(obj: Record<string, unknown>, path: string): unknown;
|
|
17
|
+
/**
|
|
18
|
+
* Sets a nested value by dot-separated path.
|
|
19
|
+
* Always dereferences `obj.value` first (form data is wrapped in `{ value: domainData }`).
|
|
20
|
+
* When `path` is empty, sets the root domain data (`obj.value = value`).
|
|
21
|
+
* Creates missing containers on the way, the root included: an array where
|
|
22
|
+
* the next segment is an index (`items.0.name`), else an object.
|
|
23
|
+
*/
|
|
24
|
+
declare function setByPath(obj: Record<string, unknown>, path: string, value: unknown): void;
|
|
25
|
+
/**
|
|
26
|
+
* Deletes the own key at a dot-separated path (form-data wrapper aware — derefs
|
|
27
|
+
* `obj.value` first). Walks to the parent WITHOUT vivifying intermediate nodes:
|
|
28
|
+
* if any ancestor is missing, the call is a no-op (nothing to delete).
|
|
29
|
+
*
|
|
30
|
+
* Unlike `setByPath(obj, path, undefined)`, this leaves NO own key behind — the
|
|
31
|
+
* leaf reads as absent (`'k' in parent === false`), which keeps `deepEqual`
|
|
32
|
+
* structural comparisons in sync (a present `undefined` own-key and an absent
|
|
33
|
+
* key are NOT structurally equal under the own-key walk). Used by
|
|
34
|
+
* {@link applyFormChanges} to apply a clear-to-`undefined` change as a delete.
|
|
35
|
+
*
|
|
36
|
+
* Empty path clears the root domain value (`obj.value = undefined`).
|
|
37
|
+
*/
|
|
38
|
+
declare function deleteByPath(obj: Record<string, unknown>, path: string): void;
|
|
39
|
+
/** Value resolver function type — created once per form, reused across calls. */
|
|
40
|
+
type TFormValueResolver = (prop: TAtscriptAnnotatedType, path: string) => unknown;
|
|
41
|
+
declare function createFormValueResolver(data?: Record<string, unknown>, context?: Record<string, unknown>): TFormValueResolver;
|
|
42
|
+
declare function createFormData<T extends TAtscriptAnnotatedType>(type: T, resolver?: TFormValueResolver): {
|
|
43
|
+
value: TAtscriptDataType<T>;
|
|
44
|
+
};
|
|
45
|
+
declare function detectUnionVariant(value: unknown, variants: FormUnionVariant[]): number;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { TFormValueResolver, createFormData, createFormValueResolver, deleteByPath, detectUnionVariant, getByPath, joinPath, setByPath };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { META_DEFAULT, UI_FORM_FN_VALUE } from "../shared/annotation-keys.mjs";
|
|
2
|
+
import { resolveFieldProp } from "../shared/field-resolver.mjs";
|
|
3
|
+
import { createDataFromAnnotatedType, detectDiscriminator } from "@atscript/typescript/utils";
|
|
4
|
+
//#region src/form/path-utils.ts
|
|
5
|
+
/**
|
|
6
|
+
* Joins a dot-separated path prefix with a segment. Empty-safe on both
|
|
7
|
+
* sides: an empty segment returns the prefix as-is, an empty prefix
|
|
8
|
+
* returns the segment as-is (no leading/trailing dots).
|
|
9
|
+
*/
|
|
10
|
+
function joinPath(prefix, segment) {
|
|
11
|
+
if (!segment) return prefix;
|
|
12
|
+
return prefix ? `${prefix}.${segment}` : segment;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Gets a nested value by dot-separated path.
|
|
16
|
+
* Always dereferences `obj.value` first (form data is wrapped in `{ value: domainData }`).
|
|
17
|
+
* When `path` is empty, returns the root domain data (`obj.value`).
|
|
18
|
+
*/
|
|
19
|
+
function getByPath(obj, path) {
|
|
20
|
+
const root = obj.value;
|
|
21
|
+
if (!path) return root;
|
|
22
|
+
const keys = path.split(".");
|
|
23
|
+
let current = root;
|
|
24
|
+
for (const key of keys) {
|
|
25
|
+
if (current === null || current === void 0 || typeof current !== "object") return void 0;
|
|
26
|
+
current = current[key];
|
|
27
|
+
}
|
|
28
|
+
return current;
|
|
29
|
+
}
|
|
30
|
+
/** A non-null, non-array object. */
|
|
31
|
+
function isPlainObject(v) {
|
|
32
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
33
|
+
}
|
|
34
|
+
/** An array index path segment. */
|
|
35
|
+
const INDEX_RE = /^\d+$/;
|
|
36
|
+
/**
|
|
37
|
+
* Sets a nested value by dot-separated path.
|
|
38
|
+
* Always dereferences `obj.value` first (form data is wrapped in `{ value: domainData }`).
|
|
39
|
+
* When `path` is empty, sets the root domain data (`obj.value = value`).
|
|
40
|
+
* Creates missing containers on the way, the root included: an array where
|
|
41
|
+
* the next segment is an index (`items.0.name`), else an object.
|
|
42
|
+
*/
|
|
43
|
+
function setByPath(obj, path, value) {
|
|
44
|
+
if (!path) {
|
|
45
|
+
obj.value = value;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const keys = path.split(".");
|
|
49
|
+
const last = keys.pop();
|
|
50
|
+
if (last === void 0) return;
|
|
51
|
+
const containerFor = (next) => INDEX_RE.test(next) ? [] : {};
|
|
52
|
+
if (obj.value === null || typeof obj.value !== "object") obj.value = containerFor(keys[0] ?? last);
|
|
53
|
+
let current = obj.value;
|
|
54
|
+
for (let i = 0; i < keys.length; i++) {
|
|
55
|
+
const key = keys[i];
|
|
56
|
+
if (current[key] === null || current[key] === void 0 || typeof current[key] !== "object") current[key] = containerFor(keys[i + 1] ?? last);
|
|
57
|
+
current = current[key];
|
|
58
|
+
}
|
|
59
|
+
current[last] = value;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Deletes the own key at a dot-separated path (form-data wrapper aware — derefs
|
|
63
|
+
* `obj.value` first). Walks to the parent WITHOUT vivifying intermediate nodes:
|
|
64
|
+
* if any ancestor is missing, the call is a no-op (nothing to delete).
|
|
65
|
+
*
|
|
66
|
+
* Unlike `setByPath(obj, path, undefined)`, this leaves NO own key behind — the
|
|
67
|
+
* leaf reads as absent (`'k' in parent === false`), which keeps `deepEqual`
|
|
68
|
+
* structural comparisons in sync (a present `undefined` own-key and an absent
|
|
69
|
+
* key are NOT structurally equal under the own-key walk). Used by
|
|
70
|
+
* {@link applyFormChanges} to apply a clear-to-`undefined` change as a delete.
|
|
71
|
+
*
|
|
72
|
+
* Empty path clears the root domain value (`obj.value = undefined`).
|
|
73
|
+
*/
|
|
74
|
+
function deleteByPath(obj, path) {
|
|
75
|
+
if (!path) {
|
|
76
|
+
obj.value = void 0;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const keys = path.split(".");
|
|
80
|
+
const last = keys.pop();
|
|
81
|
+
if (last === void 0) return;
|
|
82
|
+
let current = obj.value;
|
|
83
|
+
for (const key of keys) {
|
|
84
|
+
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
85
|
+
current = current[key];
|
|
86
|
+
}
|
|
87
|
+
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
88
|
+
delete current[last];
|
|
89
|
+
}
|
|
90
|
+
function parseStaticDefault(raw, prop) {
|
|
91
|
+
if (typeof raw !== "string") return raw;
|
|
92
|
+
if (prop.type.kind === "" && prop.type.designType === "string") return raw;
|
|
93
|
+
try {
|
|
94
|
+
return JSON.parse(raw);
|
|
95
|
+
} catch {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** Cached default resolver — reused when no resolver is provided. */
|
|
100
|
+
const defaultValueResolver = createFormValueResolver();
|
|
101
|
+
function createFormValueResolver(data = {}, context = {}) {
|
|
102
|
+
return (prop, _path) => {
|
|
103
|
+
return resolveFieldProp(prop, UI_FORM_FN_VALUE, META_DEFAULT, {
|
|
104
|
+
v: void 0,
|
|
105
|
+
data,
|
|
106
|
+
context,
|
|
107
|
+
entry: void 0
|
|
108
|
+
}, { transform: (raw) => parseStaticDefault(raw, prop) });
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Type-appropriate "defined-but-empty" fallback for primitive design types
|
|
113
|
+
* whose structural default in atscript's `finalDefault` table is
|
|
114
|
+
* `undefined`. Without this, `createFormData` on an optional `decimal`
|
|
115
|
+
* field (or any other primitive missed by atscript's table) returns
|
|
116
|
+
* `undefined` — but `createFormData` is called from "explicit add"
|
|
117
|
+
* contexts (optional-toggle, array-add, tuple-pad, union-pick) where the
|
|
118
|
+
* caller's intent is "give me a value the renderer can edit", not "no
|
|
119
|
+
* value yet". Returning `undefined` leaves the empty-state placeholder
|
|
120
|
+
* stuck in AsFieldShell.
|
|
121
|
+
*
|
|
122
|
+
* `decimal → "0"` mirrors the `number → 0` default — the atscript runtime
|
|
123
|
+
* validator (≥ 0.1.54) rejects `""` for decimal fields, so committing the
|
|
124
|
+
* canonical zero is the only init that survives a submit-without-edit.
|
|
125
|
+
* `useAsDecimal` pads the display to the field's effective scale, so the
|
|
126
|
+
* user sees `0.00` / `0.000` per the `@db.column.precision` annotation.
|
|
127
|
+
*/
|
|
128
|
+
function primitiveInitFallback(prop) {
|
|
129
|
+
if (prop.type.kind !== "") return void 0;
|
|
130
|
+
switch (prop.type.designType) {
|
|
131
|
+
case "decimal": return "0";
|
|
132
|
+
default: return;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function createFormData(type, resolver) {
|
|
136
|
+
let value = createDataFromAnnotatedType(type, { mode: resolver ?? defaultValueResolver });
|
|
137
|
+
if (value === void 0) value = primitiveInitFallback(type);
|
|
138
|
+
return { value };
|
|
139
|
+
}
|
|
140
|
+
const variantValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
141
|
+
function getVariantValidator(variant) {
|
|
142
|
+
let v = variantValidatorCache.get(variant.type);
|
|
143
|
+
if (!v) {
|
|
144
|
+
v = variant.type.validator();
|
|
145
|
+
variantValidatorCache.set(variant.type, v);
|
|
146
|
+
}
|
|
147
|
+
return v;
|
|
148
|
+
}
|
|
149
|
+
const variantsDiscriminatorCache = /* @__PURE__ */ new WeakMap();
|
|
150
|
+
function getVariantsDiscriminator(variants) {
|
|
151
|
+
let cached = variantsDiscriminatorCache.get(variants);
|
|
152
|
+
if (cached === void 0) {
|
|
153
|
+
cached = detectDiscriminator(variants.map((v) => v.type));
|
|
154
|
+
variantsDiscriminatorCache.set(variants, cached);
|
|
155
|
+
}
|
|
156
|
+
return cached;
|
|
157
|
+
}
|
|
158
|
+
function detectUnionVariant(value, variants) {
|
|
159
|
+
if (variants.length <= 1) return 0;
|
|
160
|
+
const disc = getVariantsDiscriminator(variants);
|
|
161
|
+
if (disc && value !== null && typeof value === "object") {
|
|
162
|
+
const tag = value[disc.propertyName];
|
|
163
|
+
const key = String(tag);
|
|
164
|
+
if (Object.prototype.hasOwnProperty.call(disc.indexMapping, key)) {
|
|
165
|
+
const idx = disc.indexMapping[key];
|
|
166
|
+
if (idx !== void 0) return idx;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
for (let i = 0; i < variants.length; i++) try {
|
|
170
|
+
if (getVariantValidator(variants[i]).validate(value, true)) return i;
|
|
171
|
+
} catch {}
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
export { createFormData, createFormValueResolver, deleteByPath, detectUnionVariant, getByPath, isPlainObject, joinPath, setByPath };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const require_clone = require("./clone.cjs");
|
|
2
|
+
const require_path_utils = require("./path-utils.cjs");
|
|
3
|
+
const require_diff = require("./diff.cjs");
|
|
4
|
+
const require_apply = require("./apply.cjs");
|
|
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 = require_diff.buildFormDiff(def, baseline, current, diffOptions).changes;
|
|
27
|
+
const upstreamChanges = require_diff.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 = require_clone.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") require_path_utils.setByPath(next, clearedAncestor, require_clone.deepClone(require_path_utils.getByPath(current, clearedAncestor)));
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const uc = upstreamByPath.get(lc.path);
|
|
40
|
+
if (uc !== void 0) {
|
|
41
|
+
if (require_diff.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 = require_diff.buildFormDiff(def, upstream, require_clone.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
|
+
require_apply.applyFormChanges(def, next, [{
|
|
66
|
+
...lc,
|
|
67
|
+
after: require_clone.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 = require_path_utils.getByPath(baseline, acc);
|
|
83
|
+
if (typeof base !== "object" || base === null) continue;
|
|
84
|
+
const up = require_path_utils.getByPath(upstream, acc);
|
|
85
|
+
if (up === null || up === void 0) return acc;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
exports.buildFormRebase = buildFormRebase;
|