@atscript/ui 0.1.163 → 0.1.164
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 +53 -0
- package/dist/client-factory.d.mts +53 -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 +440 -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 +438 -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 +10 -0
- package/dist/form/labels.d.cts +7 -0
- package/dist/form/labels.d.mts +7 -0
- package/dist/form/labels.mjs +10 -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 +133 -0
- package/dist/form/types.d.mts +133 -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 +150 -0
- package/dist/form/validate.d.cts +50 -0
- package/dist/form/validate.d.mts +50 -0
- package/dist/form/validate.mjs +147 -0
- package/dist/index.cjs +217 -3360
- package/dist/index.d.cts +38 -1693
- package/dist/index.d.mts +38 -1693
- package/dist/index.mjs +35 -3179
- 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 +577 -0
- package/dist/plugin/annotations.mjs +577 -0
- package/dist/plugin/primitives.cjs +30 -0
- package/dist/plugin/primitives.mjs +30 -0
- package/dist/plugin/value-help-validation.cjs +419 -0
- package/dist/plugin/value-help-validation.mjs +413 -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 +244 -0
- package/dist/shared/meta-cache.d.cts +110 -0
- package/dist/shared/meta-cache.d.mts +110 -0
- package/dist/shared/meta-cache.mjs +237 -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 +233 -0
- package/dist/table/create-table-def.d.cts +15 -0
- package/dist/table/create-table-def.d.mts +15 -0
- package/dist/table/create-table-def.mjs +233 -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 +287 -0
- package/dist/table/types.d.mts +287 -0
- package/dist/table/value-kind.cjs +20 -0
- package/dist/table/value-kind.d.cts +15 -0
- package/dist/table/value-kind.d.mts +15 -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 +76 -0
- package/dist/value-help/extract-literals.d.cts +32 -0
- package/dist/value-help/extract-literals.d.mts +32 -0
- package/dist/value-help/extract-literals.mjs +74 -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 +64 -0
- package/dist/value-help/resolve-options.d.cts +35 -0
- package/dist/value-help/resolve-options.d.mts +35 -0
- package/dist/value-help/resolve-options.mjs +60 -0
- package/dist/value-help/resolve.cjs +62 -0
- package/dist/value-help/resolve.d.cts +31 -0
- package/dist/value-help/resolve.d.mts +31 -0
- package/dist/value-help/resolve.mjs +61 -0
- package/dist/value-help/types.d.cts +36 -0
- package/dist/value-help/types.d.mts +36 -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 +10 -10
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
let _atscript_db_client = require("@atscript/db-client");
|
|
2
|
+
//#region src/client-factory.ts
|
|
3
|
+
const builtin = (url, options) => new _atscript_db_client.Client(url, options);
|
|
4
|
+
let _default = builtin;
|
|
5
|
+
/**
|
|
6
|
+
* Override the app-wide default factory. Call once at startup (e.g. in
|
|
7
|
+
* `entry-client.ts`) to wire shared fetch, credentials, error handling, etc.
|
|
8
|
+
* Every table, value-help picker, and other client consumer will pick it up.
|
|
9
|
+
*/
|
|
10
|
+
function setDefaultClientFactory(factory) {
|
|
11
|
+
_default = factory;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Current app-wide default factory. Falls back to `new Client(url, options)`.
|
|
15
|
+
* Pass the model to get a typed client: `getDefaultClientFactory()<typeof Product>(url)`.
|
|
16
|
+
*/
|
|
17
|
+
function getDefaultClientFactory() {
|
|
18
|
+
return _default;
|
|
19
|
+
}
|
|
20
|
+
/** Reset the default factory to the built-in one (primarily for tests). */
|
|
21
|
+
function resetDefaultClientFactory() {
|
|
22
|
+
_default = builtin;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.getDefaultClientFactory = getDefaultClientFactory;
|
|
26
|
+
exports.resetDefaultClientFactory = resetDefaultClientFactory;
|
|
27
|
+
exports.setDefaultClientFactory = setDefaultClientFactory;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AtscriptClientShape, Client, ClientOptions } from "@atscript/db-client";
|
|
2
|
+
|
|
3
|
+
//#region src/client-factory.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Client options the library itself may ask a {@link ClientFactory} for —
|
|
6
|
+
* spread them into the `Client` options your factory builds:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* setDefaultClientFactory((url, opts) => new Client(url, { ...opts, fetch: myFetch }))
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* - `metaKey` — the store key for `/meta` revalidation, set when a table is
|
|
13
|
+
* given `metaKey` (e.g. the route template of a parametric mount). Since 0.1.153.
|
|
14
|
+
* - `metaStore` — `false` during server rendering, so `/meta` bodies are never
|
|
15
|
+
* kept in a process-wide store shared by every viewer. Since 0.1.153.
|
|
16
|
+
*/
|
|
17
|
+
type ClientFactoryOptions = Pick<ClientOptions, "metaKey" | "metaStore">;
|
|
18
|
+
/**
|
|
19
|
+
* Factory that creates a `Client` for a given URL.
|
|
20
|
+
*
|
|
21
|
+
* Single contract shared by every atscript-ui primitive that needs to talk
|
|
22
|
+
* to an atscript-db-compatible endpoint: table composables, FK value-help,
|
|
23
|
+
* and any future consumer. Produces a `Client` configured with whatever
|
|
24
|
+
* transport / auth wiring the host application wants. Forward the optional
|
|
25
|
+
* second argument ({@link ClientFactoryOptions}) into the `Client` options.
|
|
26
|
+
*
|
|
27
|
+
* Any function returning a `Client` fits — one that builds a new client or
|
|
28
|
+
* one that hands back a cached one.
|
|
29
|
+
*/
|
|
30
|
+
type ClientFactory = (url: string, options?: ClientFactoryOptions) => Client;
|
|
31
|
+
/**
|
|
32
|
+
* The app-wide factory as {@link getDefaultClientFactory} returns it: generic
|
|
33
|
+
* like `Client`. `factory<typeof Product>(url)` is a `Client<typeof Product>`
|
|
34
|
+
* with typed reads and writes; without a type argument it is the untyped
|
|
35
|
+
* `Client`. The type argument only types the client — nothing is checked at
|
|
36
|
+
* runtime.
|
|
37
|
+
*/
|
|
38
|
+
type TypedClientFactory = <T extends AtscriptClientShape = AtscriptClientShape>(url: string, options?: ClientFactoryOptions) => Client<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Override the app-wide default factory. Call once at startup (e.g. in
|
|
41
|
+
* `entry-client.ts`) to wire shared fetch, credentials, error handling, etc.
|
|
42
|
+
* Every table, value-help picker, and other client consumer will pick it up.
|
|
43
|
+
*/
|
|
44
|
+
declare function setDefaultClientFactory(factory: ClientFactory): void;
|
|
45
|
+
/**
|
|
46
|
+
* Current app-wide default factory. Falls back to `new Client(url, options)`.
|
|
47
|
+
* Pass the model to get a typed client: `getDefaultClientFactory()<typeof Product>(url)`.
|
|
48
|
+
*/
|
|
49
|
+
declare function getDefaultClientFactory(): TypedClientFactory;
|
|
50
|
+
/** Reset the default factory to the built-in one (primarily for tests). */
|
|
51
|
+
declare function resetDefaultClientFactory(): void;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { ClientFactory, ClientFactoryOptions, TypedClientFactory, getDefaultClientFactory, resetDefaultClientFactory, setDefaultClientFactory };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AtscriptClientShape, Client, ClientOptions } from "@atscript/db-client";
|
|
2
|
+
|
|
3
|
+
//#region src/client-factory.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Client options the library itself may ask a {@link ClientFactory} for —
|
|
6
|
+
* spread them into the `Client` options your factory builds:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* setDefaultClientFactory((url, opts) => new Client(url, { ...opts, fetch: myFetch }))
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* - `metaKey` — the store key for `/meta` revalidation, set when a table is
|
|
13
|
+
* given `metaKey` (e.g. the route template of a parametric mount). Since 0.1.153.
|
|
14
|
+
* - `metaStore` — `false` during server rendering, so `/meta` bodies are never
|
|
15
|
+
* kept in a process-wide store shared by every viewer. Since 0.1.153.
|
|
16
|
+
*/
|
|
17
|
+
type ClientFactoryOptions = Pick<ClientOptions, "metaKey" | "metaStore">;
|
|
18
|
+
/**
|
|
19
|
+
* Factory that creates a `Client` for a given URL.
|
|
20
|
+
*
|
|
21
|
+
* Single contract shared by every atscript-ui primitive that needs to talk
|
|
22
|
+
* to an atscript-db-compatible endpoint: table composables, FK value-help,
|
|
23
|
+
* and any future consumer. Produces a `Client` configured with whatever
|
|
24
|
+
* transport / auth wiring the host application wants. Forward the optional
|
|
25
|
+
* second argument ({@link ClientFactoryOptions}) into the `Client` options.
|
|
26
|
+
*
|
|
27
|
+
* Any function returning a `Client` fits — one that builds a new client or
|
|
28
|
+
* one that hands back a cached one.
|
|
29
|
+
*/
|
|
30
|
+
type ClientFactory = (url: string, options?: ClientFactoryOptions) => Client;
|
|
31
|
+
/**
|
|
32
|
+
* The app-wide factory as {@link getDefaultClientFactory} returns it: generic
|
|
33
|
+
* like `Client`. `factory<typeof Product>(url)` is a `Client<typeof Product>`
|
|
34
|
+
* with typed reads and writes; without a type argument it is the untyped
|
|
35
|
+
* `Client`. The type argument only types the client — nothing is checked at
|
|
36
|
+
* runtime.
|
|
37
|
+
*/
|
|
38
|
+
type TypedClientFactory = <T extends AtscriptClientShape = AtscriptClientShape>(url: string, options?: ClientFactoryOptions) => Client<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Override the app-wide default factory. Call once at startup (e.g. in
|
|
41
|
+
* `entry-client.ts`) to wire shared fetch, credentials, error handling, etc.
|
|
42
|
+
* Every table, value-help picker, and other client consumer will pick it up.
|
|
43
|
+
*/
|
|
44
|
+
declare function setDefaultClientFactory(factory: ClientFactory): void;
|
|
45
|
+
/**
|
|
46
|
+
* Current app-wide default factory. Falls back to `new Client(url, options)`.
|
|
47
|
+
* Pass the model to get a typed client: `getDefaultClientFactory()<typeof Product>(url)`.
|
|
48
|
+
*/
|
|
49
|
+
declare function getDefaultClientFactory(): TypedClientFactory;
|
|
50
|
+
/** Reset the default factory to the built-in one (primarily for tests). */
|
|
51
|
+
declare function resetDefaultClientFactory(): void;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { ClientFactory, ClientFactoryOptions, TypedClientFactory, getDefaultClientFactory, resetDefaultClientFactory, setDefaultClientFactory };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Client } from "@atscript/db-client";
|
|
2
|
+
//#region src/client-factory.ts
|
|
3
|
+
const builtin = (url, options) => new Client(url, options);
|
|
4
|
+
let _default = builtin;
|
|
5
|
+
/**
|
|
6
|
+
* Override the app-wide default factory. Call once at startup (e.g. in
|
|
7
|
+
* `entry-client.ts`) to wire shared fetch, credentials, error handling, etc.
|
|
8
|
+
* Every table, value-help picker, and other client consumer will pick it up.
|
|
9
|
+
*/
|
|
10
|
+
function setDefaultClientFactory(factory) {
|
|
11
|
+
_default = factory;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Current app-wide default factory. Falls back to `new Client(url, options)`.
|
|
15
|
+
* Pass the model to get a typed client: `getDefaultClientFactory()<typeof Product>(url)`.
|
|
16
|
+
*/
|
|
17
|
+
function getDefaultClientFactory() {
|
|
18
|
+
return _default;
|
|
19
|
+
}
|
|
20
|
+
/** Reset the default factory to the built-in one (primarily for tests). */
|
|
21
|
+
function resetDefaultClientFactory() {
|
|
22
|
+
_default = builtin;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { getDefaultClientFactory, resetDefaultClientFactory, setDefaultClientFactory };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const require_path_utils = require("./path-utils.cjs");
|
|
2
|
+
//#region src/form/apply.ts
|
|
3
|
+
/**
|
|
4
|
+
* Applies a {@link FormFieldChange} list onto a WRAPPED form-data container
|
|
5
|
+
* (`{ value: domainData }`), mutating it in place and returning the same
|
|
6
|
+
* reference. The inverse direction of {@link buildFormDiff}: where the diff
|
|
7
|
+
* READS `(baseline, current)` into changes, this WRITES changes onto data.
|
|
8
|
+
*
|
|
9
|
+
* IMPORTANT: pass a CLONE, never the live fetched row — every write mutates
|
|
10
|
+
* `data` directly. Callers that need the original intact should
|
|
11
|
+
* `deepClone(data)` first (see {@link deepClone}).
|
|
12
|
+
*
|
|
13
|
+
* Per-change semantics (the single place the apply rules live, so
|
|
14
|
+
* {@link buildFormRebase} stays consistent):
|
|
15
|
+
*
|
|
16
|
+
* - `kind: 'set'`:
|
|
17
|
+
* - `change.after === undefined` → DELETE the own key at `change.path` (walk
|
|
18
|
+
* to parent, `delete`). A cleared field must read as ABSENT, not as a
|
|
19
|
+
* present `undefined` own-key — otherwise a re-diff sees a structural
|
|
20
|
+
* mismatch where the form intends "no value". `setByPath(…, undefined)`
|
|
21
|
+
* leaves an own key behind, so we use {@link deleteByPath} instead.
|
|
22
|
+
* - otherwise → `setByPath(data, change.path, change.after)`.
|
|
23
|
+
* - `kind: 'array'`: whole-array set via `setByPath(data, change.path,
|
|
24
|
+
* change.after)` (LOCKED Option A — no per-element merge; the diff already
|
|
25
|
+
* carried the full after-array).
|
|
26
|
+
*
|
|
27
|
+
* The `def` is currently unused by the apply walk (paths fully describe the
|
|
28
|
+
* write target) but is part of the signature for parity with
|
|
29
|
+
* `buildFormDiff`/`buildFormRebase`, so the rebase engine threads one `def`
|
|
30
|
+
* uniformly through diff + apply.
|
|
31
|
+
*/
|
|
32
|
+
function applyFormChanges(_def, data, changes) {
|
|
33
|
+
for (const change of changes) if (change.kind === "set" && change.after === void 0) require_path_utils.deleteByPath(data, change.path);
|
|
34
|
+
else require_path_utils.setByPath(data, change.path, change.after);
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.applyFormChanges = applyFormChanges;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FormDef } from "./types.cjs";
|
|
2
|
+
import { FormFieldChange } from "./diff.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/form/apply.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Applies a {@link FormFieldChange} list onto a WRAPPED form-data container
|
|
7
|
+
* (`{ value: domainData }`), mutating it in place and returning the same
|
|
8
|
+
* reference. The inverse direction of {@link buildFormDiff}: where the diff
|
|
9
|
+
* READS `(baseline, current)` into changes, this WRITES changes onto data.
|
|
10
|
+
*
|
|
11
|
+
* IMPORTANT: pass a CLONE, never the live fetched row — every write mutates
|
|
12
|
+
* `data` directly. Callers that need the original intact should
|
|
13
|
+
* `deepClone(data)` first (see {@link deepClone}).
|
|
14
|
+
*
|
|
15
|
+
* Per-change semantics (the single place the apply rules live, so
|
|
16
|
+
* {@link buildFormRebase} stays consistent):
|
|
17
|
+
*
|
|
18
|
+
* - `kind: 'set'`:
|
|
19
|
+
* - `change.after === undefined` → DELETE the own key at `change.path` (walk
|
|
20
|
+
* to parent, `delete`). A cleared field must read as ABSENT, not as a
|
|
21
|
+
* present `undefined` own-key — otherwise a re-diff sees a structural
|
|
22
|
+
* mismatch where the form intends "no value". `setByPath(…, undefined)`
|
|
23
|
+
* leaves an own key behind, so we use {@link deleteByPath} instead.
|
|
24
|
+
* - otherwise → `setByPath(data, change.path, change.after)`.
|
|
25
|
+
* - `kind: 'array'`: whole-array set via `setByPath(data, change.path,
|
|
26
|
+
* change.after)` (LOCKED Option A — no per-element merge; the diff already
|
|
27
|
+
* carried the full after-array).
|
|
28
|
+
*
|
|
29
|
+
* The `def` is currently unused by the apply walk (paths fully describe the
|
|
30
|
+
* write target) but is part of the signature for parity with
|
|
31
|
+
* `buildFormDiff`/`buildFormRebase`, so the rebase engine threads one `def`
|
|
32
|
+
* uniformly through diff + apply.
|
|
33
|
+
*/
|
|
34
|
+
declare function applyFormChanges(_def: FormDef, data: Record<string, unknown>, changes: FormFieldChange[]): Record<string, unknown>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { applyFormChanges };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FormDef } from "./types.mjs";
|
|
2
|
+
import { FormFieldChange } from "./diff.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/form/apply.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Applies a {@link FormFieldChange} list onto a WRAPPED form-data container
|
|
7
|
+
* (`{ value: domainData }`), mutating it in place and returning the same
|
|
8
|
+
* reference. The inverse direction of {@link buildFormDiff}: where the diff
|
|
9
|
+
* READS `(baseline, current)` into changes, this WRITES changes onto data.
|
|
10
|
+
*
|
|
11
|
+
* IMPORTANT: pass a CLONE, never the live fetched row — every write mutates
|
|
12
|
+
* `data` directly. Callers that need the original intact should
|
|
13
|
+
* `deepClone(data)` first (see {@link deepClone}).
|
|
14
|
+
*
|
|
15
|
+
* Per-change semantics (the single place the apply rules live, so
|
|
16
|
+
* {@link buildFormRebase} stays consistent):
|
|
17
|
+
*
|
|
18
|
+
* - `kind: 'set'`:
|
|
19
|
+
* - `change.after === undefined` → DELETE the own key at `change.path` (walk
|
|
20
|
+
* to parent, `delete`). A cleared field must read as ABSENT, not as a
|
|
21
|
+
* present `undefined` own-key — otherwise a re-diff sees a structural
|
|
22
|
+
* mismatch where the form intends "no value". `setByPath(…, undefined)`
|
|
23
|
+
* leaves an own key behind, so we use {@link deleteByPath} instead.
|
|
24
|
+
* - otherwise → `setByPath(data, change.path, change.after)`.
|
|
25
|
+
* - `kind: 'array'`: whole-array set via `setByPath(data, change.path,
|
|
26
|
+
* change.after)` (LOCKED Option A — no per-element merge; the diff already
|
|
27
|
+
* carried the full after-array).
|
|
28
|
+
*
|
|
29
|
+
* The `def` is currently unused by the apply walk (paths fully describe the
|
|
30
|
+
* write target) but is part of the signature for parity with
|
|
31
|
+
* `buildFormDiff`/`buildFormRebase`, so the rebase engine threads one `def`
|
|
32
|
+
* uniformly through diff + apply.
|
|
33
|
+
*/
|
|
34
|
+
declare function applyFormChanges(_def: FormDef, data: Record<string, unknown>, changes: FormFieldChange[]): Record<string, unknown>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { applyFormChanges };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { deleteByPath, setByPath } from "./path-utils.mjs";
|
|
2
|
+
//#region src/form/apply.ts
|
|
3
|
+
/**
|
|
4
|
+
* Applies a {@link FormFieldChange} list onto a WRAPPED form-data container
|
|
5
|
+
* (`{ value: domainData }`), mutating it in place and returning the same
|
|
6
|
+
* reference. The inverse direction of {@link buildFormDiff}: where the diff
|
|
7
|
+
* READS `(baseline, current)` into changes, this WRITES changes onto data.
|
|
8
|
+
*
|
|
9
|
+
* IMPORTANT: pass a CLONE, never the live fetched row — every write mutates
|
|
10
|
+
* `data` directly. Callers that need the original intact should
|
|
11
|
+
* `deepClone(data)` first (see {@link deepClone}).
|
|
12
|
+
*
|
|
13
|
+
* Per-change semantics (the single place the apply rules live, so
|
|
14
|
+
* {@link buildFormRebase} stays consistent):
|
|
15
|
+
*
|
|
16
|
+
* - `kind: 'set'`:
|
|
17
|
+
* - `change.after === undefined` → DELETE the own key at `change.path` (walk
|
|
18
|
+
* to parent, `delete`). A cleared field must read as ABSENT, not as a
|
|
19
|
+
* present `undefined` own-key — otherwise a re-diff sees a structural
|
|
20
|
+
* mismatch where the form intends "no value". `setByPath(…, undefined)`
|
|
21
|
+
* leaves an own key behind, so we use {@link deleteByPath} instead.
|
|
22
|
+
* - otherwise → `setByPath(data, change.path, change.after)`.
|
|
23
|
+
* - `kind: 'array'`: whole-array set via `setByPath(data, change.path,
|
|
24
|
+
* change.after)` (LOCKED Option A — no per-element merge; the diff already
|
|
25
|
+
* carried the full after-array).
|
|
26
|
+
*
|
|
27
|
+
* The `def` is currently unused by the apply walk (paths fully describe the
|
|
28
|
+
* write target) but is part of the signature for parity with
|
|
29
|
+
* `buildFormDiff`/`buildFormRebase`, so the rebase engine threads one `def`
|
|
30
|
+
* uniformly through diff + apply.
|
|
31
|
+
*/
|
|
32
|
+
function applyFormChanges(_def, data, changes) {
|
|
33
|
+
for (const change of changes) if (change.kind === "set" && change.after === void 0) deleteByPath(data, change.path);
|
|
34
|
+
else setByPath(data, change.path, change.after);
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { applyFormChanges };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/form/clone.ts
|
|
2
|
+
/**
|
|
3
|
+
* Structural deep clone of plain JSON-ish data (objects / arrays / primitives /
|
|
4
|
+
* `Date`). Walks OWN-ENUMERABLE keys only (matches the own-key discipline in
|
|
5
|
+
* `diff.ts` — never copies an accidental prototype) and copies leaves by value.
|
|
6
|
+
*
|
|
7
|
+
* `structuredClone` is deliberately NOT used: it throws on functions and on Vue
|
|
8
|
+
* reactive proxies. The optional `unwrap` hook lets a framework caller
|
|
9
|
+
* de-proxy each value first (vue-form passes `toRaw`); the core omits it.
|
|
10
|
+
*
|
|
11
|
+
* The SINGLE deep-clone primitive for the form engine — used by
|
|
12
|
+
* `applyFormChanges`, `buildFormRebase`, and vue-form's baseline snapshot. Do
|
|
13
|
+
* not reimplement structural cloning elsewhere.
|
|
14
|
+
*/
|
|
15
|
+
function deepClone(value, unwrap) {
|
|
16
|
+
const v = unwrap ? unwrap(value) : value;
|
|
17
|
+
if (v === null || typeof v !== "object") return v;
|
|
18
|
+
if (v instanceof Date) return new Date(v.getTime());
|
|
19
|
+
if (Array.isArray(v)) {
|
|
20
|
+
const out = [];
|
|
21
|
+
for (let i = 0; i < v.length; i++) out.push(deepClone(v[i], unwrap));
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
const src = v;
|
|
25
|
+
const out = {};
|
|
26
|
+
for (const k of Object.keys(src)) out[k] = deepClone(src[k], unwrap);
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.deepClone = deepClone;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/form/clone.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Optional per-value unwrap hook. Lets a framework caller strip a reactive
|
|
4
|
+
* proxy off every visited value before it is copied (e.g. Vue's `toRaw`). The
|
|
5
|
+
* core never needs it — it is `undefined` here and the value passes through.
|
|
6
|
+
*/
|
|
7
|
+
type CloneUnwrap = (value: unknown) => unknown;
|
|
8
|
+
/**
|
|
9
|
+
* Structural deep clone of plain JSON-ish data (objects / arrays / primitives /
|
|
10
|
+
* `Date`). Walks OWN-ENUMERABLE keys only (matches the own-key discipline in
|
|
11
|
+
* `diff.ts` — never copies an accidental prototype) and copies leaves by value.
|
|
12
|
+
*
|
|
13
|
+
* `structuredClone` is deliberately NOT used: it throws on functions and on Vue
|
|
14
|
+
* reactive proxies. The optional `unwrap` hook lets a framework caller
|
|
15
|
+
* de-proxy each value first (vue-form passes `toRaw`); the core omits it.
|
|
16
|
+
*
|
|
17
|
+
* The SINGLE deep-clone primitive for the form engine — used by
|
|
18
|
+
* `applyFormChanges`, `buildFormRebase`, and vue-form's baseline snapshot. Do
|
|
19
|
+
* not reimplement structural cloning elsewhere.
|
|
20
|
+
*/
|
|
21
|
+
declare function deepClone<T>(value: T, unwrap?: CloneUnwrap): T;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { CloneUnwrap, deepClone };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/form/clone.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Optional per-value unwrap hook. Lets a framework caller strip a reactive
|
|
4
|
+
* proxy off every visited value before it is copied (e.g. Vue's `toRaw`). The
|
|
5
|
+
* core never needs it — it is `undefined` here and the value passes through.
|
|
6
|
+
*/
|
|
7
|
+
type CloneUnwrap = (value: unknown) => unknown;
|
|
8
|
+
/**
|
|
9
|
+
* Structural deep clone of plain JSON-ish data (objects / arrays / primitives /
|
|
10
|
+
* `Date`). Walks OWN-ENUMERABLE keys only (matches the own-key discipline in
|
|
11
|
+
* `diff.ts` — never copies an accidental prototype) and copies leaves by value.
|
|
12
|
+
*
|
|
13
|
+
* `structuredClone` is deliberately NOT used: it throws on functions and on Vue
|
|
14
|
+
* reactive proxies. The optional `unwrap` hook lets a framework caller
|
|
15
|
+
* de-proxy each value first (vue-form passes `toRaw`); the core omits it.
|
|
16
|
+
*
|
|
17
|
+
* The SINGLE deep-clone primitive for the form engine — used by
|
|
18
|
+
* `applyFormChanges`, `buildFormRebase`, and vue-form's baseline snapshot. Do
|
|
19
|
+
* not reimplement structural cloning elsewhere.
|
|
20
|
+
*/
|
|
21
|
+
declare function deepClone<T>(value: T, unwrap?: CloneUnwrap): T;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { CloneUnwrap, deepClone };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/form/clone.ts
|
|
2
|
+
/**
|
|
3
|
+
* Structural deep clone of plain JSON-ish data (objects / arrays / primitives /
|
|
4
|
+
* `Date`). Walks OWN-ENUMERABLE keys only (matches the own-key discipline in
|
|
5
|
+
* `diff.ts` — never copies an accidental prototype) and copies leaves by value.
|
|
6
|
+
*
|
|
7
|
+
* `structuredClone` is deliberately NOT used: it throws on functions and on Vue
|
|
8
|
+
* reactive proxies. The optional `unwrap` hook lets a framework caller
|
|
9
|
+
* de-proxy each value first (vue-form passes `toRaw`); the core omits it.
|
|
10
|
+
*
|
|
11
|
+
* The SINGLE deep-clone primitive for the form engine — used by
|
|
12
|
+
* `applyFormChanges`, `buildFormRebase`, and vue-form's baseline snapshot. Do
|
|
13
|
+
* not reimplement structural cloning elsewhere.
|
|
14
|
+
*/
|
|
15
|
+
function deepClone(value, unwrap) {
|
|
16
|
+
const v = unwrap ? unwrap(value) : value;
|
|
17
|
+
if (v === null || typeof v !== "object") return v;
|
|
18
|
+
if (v instanceof Date) return new Date(v.getTime());
|
|
19
|
+
if (Array.isArray(v)) {
|
|
20
|
+
const out = [];
|
|
21
|
+
for (let i = 0; i < v.length; i++) out.push(deepClone(v[i], unwrap));
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
const src = v;
|
|
25
|
+
const out = {};
|
|
26
|
+
for (const k of Object.keys(src)) out[k] = deepClone(src[k], unwrap);
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { deepClone };
|