@atscript/ui 0.1.203 → 0.1.205
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/form/create-form-def.cjs +52 -21
- package/dist/form/create-form-def.d.cts +23 -18
- package/dist/form/create-form-def.d.mts +23 -18
- package/dist/form/create-form-def.mjs +52 -21
- package/dist/form/decimal-format.cjs +9 -11
- package/dist/form/decimal-format.mjs +9 -11
- package/dist/form/diff.cjs +32 -14
- package/dist/form/diff.d.cts +7 -4
- package/dist/form/diff.d.mts +7 -4
- package/dist/form/diff.mjs +32 -14
- package/dist/form/loaded-empty.cjs +56 -0
- package/dist/form/loaded-empty.d.cts +25 -0
- package/dist/form/loaded-empty.d.mts +25 -0
- package/dist/form/loaded-empty.mjs +56 -0
- package/dist/form/omit-derived.cjs +38 -0
- package/dist/form/omit-derived.d.cts +17 -0
- package/dist/form/omit-derived.d.mts +17 -0
- package/dist/form/omit-derived.mjs +38 -0
- package/dist/form/optional-mode.cjs +85 -0
- package/dist/form/optional-mode.d.cts +58 -0
- package/dist/form/optional-mode.d.mts +58 -0
- package/dist/form/optional-mode.mjs +82 -0
- package/dist/form/path-utils.cjs +4 -5
- package/dist/form/path-utils.mjs +4 -5
- package/dist/form/types.d.cts +15 -14
- package/dist/form/types.d.mts +15 -14
- package/dist/form/validate.cjs +2 -2
- package/dist/form/validate.mjs +2 -2
- package/dist/index.cjs +23 -4
- package/dist/index.d.cts +7 -3
- package/dist/index.d.mts +7 -3
- package/dist/index.mjs +10 -6
- package/dist/plugin/annotations.cjs +12 -0
- package/dist/plugin/annotations.mjs +13 -1
- package/dist/plugin/value-help-validation.cjs +25 -1
- package/dist/plugin/value-help-validation.mjs +25 -2
- package/dist/shared/annotation-keys.cjs +3 -0
- package/dist/shared/annotation-keys.d.cts +3 -1
- package/dist/shared/annotation-keys.d.mts +3 -1
- package/dist/shared/annotation-keys.mjs +3 -1
- package/dist/shared/exact-number.cjs +12 -0
- package/dist/shared/exact-number.mjs +12 -0
- package/dist/shared/meta-cache.cjs +1 -1
- package/dist/shared/meta-cache.mjs +1 -1
- package/dist/table/create-table-def.cjs +4 -1
- package/dist/table/create-table-def.mjs +4 -2
- package/dist/table/types.d.cts +23 -16
- package/dist/table/types.d.mts +23 -16
- package/dist/table/value-kind.cjs +37 -2
- package/dist/table/value-kind.d.cts +22 -2
- package/dist/table/value-kind.d.mts +22 -2
- package/dist/table/value-kind.mjs +36 -3
- package/dist/value-help/distinct-client.cjs +5 -4
- package/dist/value-help/distinct-client.d.cts +8 -2
- package/dist/value-help/distinct-client.d.mts +8 -2
- package/dist/value-help/distinct-client.mjs +5 -4
- package/dist/value-help/value-help-client.cjs +45 -9
- package/dist/value-help/value-help-client.mjs +45 -9
- package/package.json +11 -12
|
@@ -6,6 +6,7 @@ const require_extract_literals = require("../value-help/extract-literals.cjs");
|
|
|
6
6
|
const require_extract_ref = require("../value-help/extract-ref.cjs");
|
|
7
7
|
const require_skipped_nav = require("./skipped-nav.cjs");
|
|
8
8
|
let _atscript_typescript_utils = require("@atscript/typescript/utils");
|
|
9
|
+
let _atscript_db_meta = require("@atscript/db/meta");
|
|
9
10
|
let _atscript_db_validator = require("@atscript/db/validator");
|
|
10
11
|
//#region src/form/create-form-def.ts
|
|
11
12
|
/** Known atscript primitive extension tags that map directly to field types. */
|
|
@@ -50,9 +51,14 @@ function unnamed(field) {
|
|
|
50
51
|
*
|
|
51
52
|
* A server-computed field — `@db.column.derived`, a computed view column
|
|
52
53
|
* (`@db.compute`) or a host-computed one (`@db.compute.host`) — is marked
|
|
53
|
-
* `derived` straight from its metadata; a served field
|
|
54
|
-
* `opts.metaFields`; an update-stamped field (see
|
|
55
|
-
* when `opts.mode` is `"edit"`.
|
|
54
|
+
* `derived` straight from its metadata; a served field `/meta` marks
|
|
55
|
+
* `readOnly`, from `opts.metaFields`; an update-stamped field (see
|
|
56
|
+
* `CreateFormDefOptions.mode`), when `opts.mode` is `"edit"`. Over a compiled
|
|
57
|
+
* `@db.view.writable` view type, a field the view declares itself (a join
|
|
58
|
+
* column, a computed field) is `derived` as well — its controller drops it
|
|
59
|
+
* from every write. A `readOnly` or own field the form writes stays an
|
|
60
|
+
* ordinary one (a pick's fill target, a `@ui.form.fn.value` or
|
|
61
|
+
* `@ui.form.fn.readonly` field). Since 0.1.204; `readOnly` since 0.1.205.
|
|
56
62
|
*
|
|
57
63
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
58
64
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -63,8 +69,10 @@ function unnamed(field) {
|
|
|
63
69
|
* becomes a nested object field, since inlining it would never end.
|
|
64
70
|
*/
|
|
65
71
|
function createFormDef(type, opts) {
|
|
66
|
-
const
|
|
72
|
+
const edit = opts?.mode === "edit";
|
|
73
|
+
const def = buildFormDef(type, edit, opts ?? {});
|
|
67
74
|
if (require_model_texts.isServedType(type)) def.served = true;
|
|
75
|
+
if (edit) def.edit = true;
|
|
68
76
|
return def;
|
|
69
77
|
}
|
|
70
78
|
/**
|
|
@@ -159,39 +167,62 @@ function collectFields(objectType, flatMap, edit, opts) {
|
|
|
159
167
|
pushDown: require_field_resolver.getFieldMeta(originalProp, require_annotation_keys.UI_FORM_PUSH_DOWN) !== void 0
|
|
160
168
|
});
|
|
161
169
|
}
|
|
162
|
-
if (opts
|
|
170
|
+
if (opts) markServerOwned(fields, objectType, opts.metaFields);
|
|
163
171
|
keepWritableFills(fields);
|
|
164
172
|
return fields;
|
|
165
173
|
}
|
|
166
174
|
/**
|
|
167
|
-
* Marks `derived` the fields
|
|
168
|
-
*
|
|
169
|
-
* `
|
|
170
|
-
*
|
|
171
|
-
* the
|
|
172
|
-
*
|
|
173
|
-
* type's field defs may be shared with nested defs.
|
|
175
|
+
* Marks `derived` the fields the server owns although their own metadata does
|
|
176
|
+
* not say so — unless the form writes them ({@link writtenByForm}): a field
|
|
177
|
+
* `/meta` marks `readOnly` (`metaFields`; see {@link servedReadOnly}), and a field a compiled
|
|
178
|
+
* `@db.view.writable` view declares itself (`writableViewReadOnlyFields`, with
|
|
179
|
+
* the leaves of one rendered inline). Root def only: only the root form is
|
|
180
|
+
* written through the endpoint, and `metaFields` keys are root paths. The def
|
|
181
|
+
* gets a copy: a recursive type's field defs may be shared with nested defs.
|
|
174
182
|
*/
|
|
175
|
-
function
|
|
183
|
+
function markServerOwned(fields, type, metaFields) {
|
|
184
|
+
const own = (0, _atscript_db_meta.writableViewReadOnlyFields)(type);
|
|
185
|
+
if (own.size === 0 && !metaFields) return;
|
|
176
186
|
const filled = /* @__PURE__ */ new Set();
|
|
177
187
|
for (const { field } of fields) {
|
|
178
188
|
const parent = parentPrefix(field.path);
|
|
179
189
|
for (const f of field.valueHelpInfo?.fill ?? []) filled.add(parent + f.local);
|
|
180
190
|
}
|
|
181
191
|
for (const c of fields) {
|
|
182
|
-
const { path,
|
|
183
|
-
if (derived) continue;
|
|
184
|
-
|
|
192
|
+
const { path, derived } = c.field;
|
|
193
|
+
if (derived || writtenByForm(c.field, filled)) continue;
|
|
194
|
+
const head = path.split(".", 1)[0];
|
|
195
|
+
if (own.has(head) || metaFields && (servedReadOnly(metaFields, path) || head !== path && servedReadOnly(metaFields, head))) c.field = {
|
|
185
196
|
...c.field,
|
|
186
197
|
derived: true
|
|
187
198
|
};
|
|
188
|
-
else if (!path.includes(".") && require_field_resolver.getFieldMeta(prop, "meta.readonly") !== void 0 && !filled.has(path) && require_field_resolver.getFieldMeta(prop, "ui.form.fn.value") === void 0 && require_field_resolver.getFieldMeta(prop, "ui.form.fn.readonly") === void 0) c.field = {
|
|
189
|
-
...c.field,
|
|
190
|
-
derived: true,
|
|
191
|
-
servedReadonly: true
|
|
192
|
-
};
|
|
193
199
|
}
|
|
194
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Whether `/meta` marks `path` read-only: its own entry, or — an object field
|
|
203
|
+
* (`/meta` lists the leaves only) — every leaf under it. Every leaf, not one: a
|
|
204
|
+
* permission layer may mark a single leaf read-only.
|
|
205
|
+
*/
|
|
206
|
+
function servedReadOnly(metaFields, path) {
|
|
207
|
+
const entry = metaFields[path];
|
|
208
|
+
if (entry) return entry.readOnly === true;
|
|
209
|
+
const prefix = `${path}.`;
|
|
210
|
+
let leaves = 0;
|
|
211
|
+
for (const key in metaFields) {
|
|
212
|
+
if (!key.startsWith(prefix)) continue;
|
|
213
|
+
if (!metaFields[key]?.readOnly) return false;
|
|
214
|
+
leaves++;
|
|
215
|
+
}
|
|
216
|
+
return leaves > 0;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* A server-owned field the form writes all the same: a pick fills it, a
|
|
220
|
+
* `@ui.form.fn.value` computes it, or a `@ui.form.fn.readonly` can make it
|
|
221
|
+
* editable.
|
|
222
|
+
*/
|
|
223
|
+
function writtenByForm(field, filled) {
|
|
224
|
+
return filled.has(field.path) || require_field_resolver.getFieldMeta(field.prop, "ui.form.fn.value") !== void 0 || require_field_resolver.getFieldMeta(field.prop, "ui.form.fn.readonly") !== void 0;
|
|
225
|
+
}
|
|
195
226
|
/** The path of the object holding `path`, with its trailing dot — `""` at the top. */
|
|
196
227
|
function parentPrefix(path) {
|
|
197
228
|
return path.slice(0, path.lastIndexOf(".") + 1);
|
|
@@ -14,23 +14,19 @@ interface CreateFormDefOptions {
|
|
|
14
14
|
versionColumn?: string;
|
|
15
15
|
/**
|
|
16
16
|
* `meta.fields` of the `/meta` the type came from — pass it for a form over
|
|
17
|
-
* a served type.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* `@ui.form.fn.value` computes, and one `@ui.form.fn.readonly` can make
|
|
28
|
-
* editable. Root-table concept; not propagated into nested recursive calls.
|
|
29
|
-
* Since 0.1.147; `@meta.readonly` since 0.1.203 (`@atscript/db` 0.1.205
|
|
30
|
-
* serves it).
|
|
17
|
+
* a served type. A field it marks `readOnly` (`@atscript/db` ≥ 0.1.209: a
|
|
18
|
+
* field not in the endpoint's write model — derived, computed, a writable
|
|
19
|
+
* view's own field, or one a permission overlay marks) is `derived`:
|
|
20
|
+
* read-only, never validated, never required, never sent. A read-only field
|
|
21
|
+
* the form writes itself stays an ordinary one — one a pick fills
|
|
22
|
+
* (`@ui.valueHelp.fill`), one `@ui.form.fn.value` computes, one
|
|
23
|
+
* `@ui.form.fn.readonly` can make editable: it is sent, and the server drops
|
|
24
|
+
* the key. Root-table concept; not propagated into nested recursive calls.
|
|
25
|
+
* Since 0.1.147; `readOnly` since 0.1.205 (before, the `computed` flag and a
|
|
26
|
+
* served `@meta.readonly`).
|
|
31
27
|
*/
|
|
32
28
|
metaFields?: Record<string, {
|
|
33
|
-
|
|
29
|
+
readOnly?: boolean;
|
|
34
30
|
}>;
|
|
35
31
|
/**
|
|
36
32
|
* What the form is for. `"edit"` — the form edits a stored row and is sent
|
|
@@ -45,6 +41,10 @@ interface CreateFormDefOptions {
|
|
|
45
41
|
* server only fills it when the value is left out and it has
|
|
46
42
|
* `@db.default.now`, or is an `@db.onUpdate.inc` counter (`0`). Since
|
|
47
43
|
* 0.1.154; `@db.onUpdate.inc` since 0.1.159.
|
|
44
|
+
*
|
|
45
|
+
* `"edit"` also sets `FormDef.edit`: an emptied optional field then holds
|
|
46
|
+
* its empty value (`""`, `null` or `false`; business mode, see
|
|
47
|
+
* `emptiedValue`), so a whole-record update clears it too. Since 0.1.205.
|
|
48
48
|
*/
|
|
49
49
|
mode?: "create" | "edit";
|
|
50
50
|
}
|
|
@@ -57,9 +57,14 @@ interface CreateFormDefOptions {
|
|
|
57
57
|
*
|
|
58
58
|
* A server-computed field — `@db.column.derived`, a computed view column
|
|
59
59
|
* (`@db.compute`) or a host-computed one (`@db.compute.host`) — is marked
|
|
60
|
-
* `derived` straight from its metadata; a served field
|
|
61
|
-
* `opts.metaFields`; an update-stamped field (see
|
|
62
|
-
* when `opts.mode` is `"edit"`.
|
|
60
|
+
* `derived` straight from its metadata; a served field `/meta` marks
|
|
61
|
+
* `readOnly`, from `opts.metaFields`; an update-stamped field (see
|
|
62
|
+
* `CreateFormDefOptions.mode`), when `opts.mode` is `"edit"`. Over a compiled
|
|
63
|
+
* `@db.view.writable` view type, a field the view declares itself (a join
|
|
64
|
+
* column, a computed field) is `derived` as well — its controller drops it
|
|
65
|
+
* from every write. A `readOnly` or own field the form writes stays an
|
|
66
|
+
* ordinary one (a pick's fill target, a `@ui.form.fn.value` or
|
|
67
|
+
* `@ui.form.fn.readonly` field). Since 0.1.204; `readOnly` since 0.1.205.
|
|
63
68
|
*
|
|
64
69
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
65
70
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -14,23 +14,19 @@ interface CreateFormDefOptions {
|
|
|
14
14
|
versionColumn?: string;
|
|
15
15
|
/**
|
|
16
16
|
* `meta.fields` of the `/meta` the type came from — pass it for a form over
|
|
17
|
-
* a served type.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* `@ui.form.fn.value` computes, and one `@ui.form.fn.readonly` can make
|
|
28
|
-
* editable. Root-table concept; not propagated into nested recursive calls.
|
|
29
|
-
* Since 0.1.147; `@meta.readonly` since 0.1.203 (`@atscript/db` 0.1.205
|
|
30
|
-
* serves it).
|
|
17
|
+
* a served type. A field it marks `readOnly` (`@atscript/db` ≥ 0.1.209: a
|
|
18
|
+
* field not in the endpoint's write model — derived, computed, a writable
|
|
19
|
+
* view's own field, or one a permission overlay marks) is `derived`:
|
|
20
|
+
* read-only, never validated, never required, never sent. A read-only field
|
|
21
|
+
* the form writes itself stays an ordinary one — one a pick fills
|
|
22
|
+
* (`@ui.valueHelp.fill`), one `@ui.form.fn.value` computes, one
|
|
23
|
+
* `@ui.form.fn.readonly` can make editable: it is sent, and the server drops
|
|
24
|
+
* the key. Root-table concept; not propagated into nested recursive calls.
|
|
25
|
+
* Since 0.1.147; `readOnly` since 0.1.205 (before, the `computed` flag and a
|
|
26
|
+
* served `@meta.readonly`).
|
|
31
27
|
*/
|
|
32
28
|
metaFields?: Record<string, {
|
|
33
|
-
|
|
29
|
+
readOnly?: boolean;
|
|
34
30
|
}>;
|
|
35
31
|
/**
|
|
36
32
|
* What the form is for. `"edit"` — the form edits a stored row and is sent
|
|
@@ -45,6 +41,10 @@ interface CreateFormDefOptions {
|
|
|
45
41
|
* server only fills it when the value is left out and it has
|
|
46
42
|
* `@db.default.now`, or is an `@db.onUpdate.inc` counter (`0`). Since
|
|
47
43
|
* 0.1.154; `@db.onUpdate.inc` since 0.1.159.
|
|
44
|
+
*
|
|
45
|
+
* `"edit"` also sets `FormDef.edit`: an emptied optional field then holds
|
|
46
|
+
* its empty value (`""`, `null` or `false`; business mode, see
|
|
47
|
+
* `emptiedValue`), so a whole-record update clears it too. Since 0.1.205.
|
|
48
48
|
*/
|
|
49
49
|
mode?: "create" | "edit";
|
|
50
50
|
}
|
|
@@ -57,9 +57,14 @@ interface CreateFormDefOptions {
|
|
|
57
57
|
*
|
|
58
58
|
* A server-computed field — `@db.column.derived`, a computed view column
|
|
59
59
|
* (`@db.compute`) or a host-computed one (`@db.compute.host`) — is marked
|
|
60
|
-
* `derived` straight from its metadata; a served field
|
|
61
|
-
* `opts.metaFields`; an update-stamped field (see
|
|
62
|
-
* when `opts.mode` is `"edit"`.
|
|
60
|
+
* `derived` straight from its metadata; a served field `/meta` marks
|
|
61
|
+
* `readOnly`, from `opts.metaFields`; an update-stamped field (see
|
|
62
|
+
* `CreateFormDefOptions.mode`), when `opts.mode` is `"edit"`. Over a compiled
|
|
63
|
+
* `@db.view.writable` view type, a field the view declares itself (a join
|
|
64
|
+
* column, a computed field) is `derived` as well — its controller drops it
|
|
65
|
+
* from every write. A `readOnly` or own field the form writes stays an
|
|
66
|
+
* ordinary one (a pick's fill target, a `@ui.form.fn.value` or
|
|
67
|
+
* `@ui.form.fn.readonly` field). Since 0.1.204; `readOnly` since 0.1.205.
|
|
63
68
|
*
|
|
64
69
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
65
70
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -6,6 +6,7 @@ import { isEmptyMember, isPureLiteralUnion } from "../value-help/extract-literal
|
|
|
6
6
|
import { extractValueHelp, isValueHelpPicker } from "../value-help/extract-ref.mjs";
|
|
7
7
|
import { isSkippedNavField } from "./skipped-nav.mjs";
|
|
8
8
|
import { flattenAnnotatedType } from "@atscript/typescript/utils";
|
|
9
|
+
import { writableViewReadOnlyFields } from "@atscript/db/meta";
|
|
9
10
|
import { isNavRelation, isServerStampedOnUpdate } from "@atscript/db/validator";
|
|
10
11
|
//#region src/form/create-form-def.ts
|
|
11
12
|
/** Known atscript primitive extension tags that map directly to field types. */
|
|
@@ -50,9 +51,14 @@ function unnamed(field) {
|
|
|
50
51
|
*
|
|
51
52
|
* A server-computed field — `@db.column.derived`, a computed view column
|
|
52
53
|
* (`@db.compute`) or a host-computed one (`@db.compute.host`) — is marked
|
|
53
|
-
* `derived` straight from its metadata; a served field
|
|
54
|
-
* `opts.metaFields`; an update-stamped field (see
|
|
55
|
-
* when `opts.mode` is `"edit"`.
|
|
54
|
+
* `derived` straight from its metadata; a served field `/meta` marks
|
|
55
|
+
* `readOnly`, from `opts.metaFields`; an update-stamped field (see
|
|
56
|
+
* `CreateFormDefOptions.mode`), when `opts.mode` is `"edit"`. Over a compiled
|
|
57
|
+
* `@db.view.writable` view type, a field the view declares itself (a join
|
|
58
|
+
* column, a computed field) is `derived` as well — its controller drops it
|
|
59
|
+
* from every write. A `readOnly` or own field the form writes stays an
|
|
60
|
+
* ordinary one (a pick's fill target, a `@ui.form.fn.value` or
|
|
61
|
+
* `@ui.form.fn.readonly` field). Since 0.1.204; `readOnly` since 0.1.205.
|
|
56
62
|
*
|
|
57
63
|
* A navigation field (`@db.rel.from` / `.to` / `.via` / `.store`) is left out unless it
|
|
58
64
|
* carries a `@ui.form.*` annotation of its own (see {@link isSkippedNavField}).
|
|
@@ -63,8 +69,10 @@ function unnamed(field) {
|
|
|
63
69
|
* becomes a nested object field, since inlining it would never end.
|
|
64
70
|
*/
|
|
65
71
|
function createFormDef(type, opts) {
|
|
66
|
-
const
|
|
72
|
+
const edit = opts?.mode === "edit";
|
|
73
|
+
const def = buildFormDef(type, edit, opts ?? {});
|
|
67
74
|
if (isServedType(type)) def.served = true;
|
|
75
|
+
if (edit) def.edit = true;
|
|
68
76
|
return def;
|
|
69
77
|
}
|
|
70
78
|
/**
|
|
@@ -159,39 +167,62 @@ function collectFields(objectType, flatMap, edit, opts) {
|
|
|
159
167
|
pushDown: getFieldMeta(originalProp, UI_FORM_PUSH_DOWN) !== void 0
|
|
160
168
|
});
|
|
161
169
|
}
|
|
162
|
-
if (opts
|
|
170
|
+
if (opts) markServerOwned(fields, objectType, opts.metaFields);
|
|
163
171
|
keepWritableFills(fields);
|
|
164
172
|
return fields;
|
|
165
173
|
}
|
|
166
174
|
/**
|
|
167
|
-
* Marks `derived` the fields
|
|
168
|
-
*
|
|
169
|
-
* `
|
|
170
|
-
*
|
|
171
|
-
* the
|
|
172
|
-
*
|
|
173
|
-
* type's field defs may be shared with nested defs.
|
|
175
|
+
* Marks `derived` the fields the server owns although their own metadata does
|
|
176
|
+
* not say so — unless the form writes them ({@link writtenByForm}): a field
|
|
177
|
+
* `/meta` marks `readOnly` (`metaFields`; see {@link servedReadOnly}), and a field a compiled
|
|
178
|
+
* `@db.view.writable` view declares itself (`writableViewReadOnlyFields`, with
|
|
179
|
+
* the leaves of one rendered inline). Root def only: only the root form is
|
|
180
|
+
* written through the endpoint, and `metaFields` keys are root paths. The def
|
|
181
|
+
* gets a copy: a recursive type's field defs may be shared with nested defs.
|
|
174
182
|
*/
|
|
175
|
-
function
|
|
183
|
+
function markServerOwned(fields, type, metaFields) {
|
|
184
|
+
const own = writableViewReadOnlyFields(type);
|
|
185
|
+
if (own.size === 0 && !metaFields) return;
|
|
176
186
|
const filled = /* @__PURE__ */ new Set();
|
|
177
187
|
for (const { field } of fields) {
|
|
178
188
|
const parent = parentPrefix(field.path);
|
|
179
189
|
for (const f of field.valueHelpInfo?.fill ?? []) filled.add(parent + f.local);
|
|
180
190
|
}
|
|
181
191
|
for (const c of fields) {
|
|
182
|
-
const { path,
|
|
183
|
-
if (derived) continue;
|
|
184
|
-
|
|
192
|
+
const { path, derived } = c.field;
|
|
193
|
+
if (derived || writtenByForm(c.field, filled)) continue;
|
|
194
|
+
const head = path.split(".", 1)[0];
|
|
195
|
+
if (own.has(head) || metaFields && (servedReadOnly(metaFields, path) || head !== path && servedReadOnly(metaFields, head))) c.field = {
|
|
185
196
|
...c.field,
|
|
186
197
|
derived: true
|
|
187
198
|
};
|
|
188
|
-
else if (!path.includes(".") && getFieldMeta(prop, "meta.readonly") !== void 0 && !filled.has(path) && getFieldMeta(prop, "ui.form.fn.value") === void 0 && getFieldMeta(prop, "ui.form.fn.readonly") === void 0) c.field = {
|
|
189
|
-
...c.field,
|
|
190
|
-
derived: true,
|
|
191
|
-
servedReadonly: true
|
|
192
|
-
};
|
|
193
199
|
}
|
|
194
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Whether `/meta` marks `path` read-only: its own entry, or — an object field
|
|
203
|
+
* (`/meta` lists the leaves only) — every leaf under it. Every leaf, not one: a
|
|
204
|
+
* permission layer may mark a single leaf read-only.
|
|
205
|
+
*/
|
|
206
|
+
function servedReadOnly(metaFields, path) {
|
|
207
|
+
const entry = metaFields[path];
|
|
208
|
+
if (entry) return entry.readOnly === true;
|
|
209
|
+
const prefix = `${path}.`;
|
|
210
|
+
let leaves = 0;
|
|
211
|
+
for (const key in metaFields) {
|
|
212
|
+
if (!key.startsWith(prefix)) continue;
|
|
213
|
+
if (!metaFields[key]?.readOnly) return false;
|
|
214
|
+
leaves++;
|
|
215
|
+
}
|
|
216
|
+
return leaves > 0;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* A server-owned field the form writes all the same: a pick fills it, a
|
|
220
|
+
* `@ui.form.fn.value` computes it, or a `@ui.form.fn.readonly` can make it
|
|
221
|
+
* editable.
|
|
222
|
+
*/
|
|
223
|
+
function writtenByForm(field, filled) {
|
|
224
|
+
return filled.has(field.path) || getFieldMeta(field.prop, "ui.form.fn.value") !== void 0 || getFieldMeta(field.prop, "ui.form.fn.readonly") !== void 0;
|
|
225
|
+
}
|
|
195
226
|
/** The path of the object holding `path`, with its trailing dot — `""` at the top. */
|
|
196
227
|
function parentPrefix(path) {
|
|
197
228
|
return path.slice(0, path.lastIndexOf(".") + 1);
|
|
@@ -267,24 +267,22 @@ function formatDecimalForDisplay(opts) {
|
|
|
267
267
|
} else canonical = value;
|
|
268
268
|
if (!/^[+-]?\d*(\.\d*)?$/.test(canonical) || canonical === "." || canonical === "-") return canonical;
|
|
269
269
|
if (scale !== void 0 && scale >= 0) canonical = enforceScale(canonical, scale);
|
|
270
|
-
const parts = splitDecimalString(canonical);
|
|
271
|
-
const asNumber = Number(canonical);
|
|
272
|
-
const intlSafe = Number.isFinite(asNumber);
|
|
273
270
|
if (currency) {
|
|
274
|
-
|
|
275
|
-
|
|
271
|
+
const parts = splitDecimalString(canonical);
|
|
272
|
+
const digits = scale ?? Math.min(Math.max(getCurrencyDecimals(currency, locale) ?? 0, parts.decimal.length), 100);
|
|
273
|
+
if (Number.isFinite(Number(canonical))) try {
|
|
274
|
+
return getNumberFormat(locale, {
|
|
276
275
|
style: "currency",
|
|
277
276
|
currency,
|
|
278
277
|
currencyDisplay: "narrowSymbol",
|
|
279
|
-
minimumFractionDigits:
|
|
280
|
-
maximumFractionDigits:
|
|
278
|
+
minimumFractionDigits: digits,
|
|
279
|
+
maximumFractionDigits: digits,
|
|
281
280
|
useGrouping
|
|
282
|
-
});
|
|
283
|
-
if (intlSafe) return fmt.format(asNumber);
|
|
281
|
+
}).format(canonical);
|
|
284
282
|
} catch {}
|
|
285
|
-
return `${currency} ${formatPlain(parts,
|
|
283
|
+
return `${currency} ${formatPlain(parts, digits, locale, useGrouping)}`;
|
|
286
284
|
}
|
|
287
|
-
const base = formatPlain(
|
|
285
|
+
const base = formatPlain(splitDecimalString(canonical), scale, locale, useGrouping);
|
|
288
286
|
return unit ? `${base} ${unit}` : base;
|
|
289
287
|
}
|
|
290
288
|
function formatPlain(parts, scale, locale, useGrouping) {
|
|
@@ -267,24 +267,22 @@ function formatDecimalForDisplay(opts) {
|
|
|
267
267
|
} else canonical = value;
|
|
268
268
|
if (!/^[+-]?\d*(\.\d*)?$/.test(canonical) || canonical === "." || canonical === "-") return canonical;
|
|
269
269
|
if (scale !== void 0 && scale >= 0) canonical = enforceScale(canonical, scale);
|
|
270
|
-
const parts = splitDecimalString(canonical);
|
|
271
|
-
const asNumber = Number(canonical);
|
|
272
|
-
const intlSafe = Number.isFinite(asNumber);
|
|
273
270
|
if (currency) {
|
|
274
|
-
|
|
275
|
-
|
|
271
|
+
const parts = splitDecimalString(canonical);
|
|
272
|
+
const digits = scale ?? Math.min(Math.max(getCurrencyDecimals(currency, locale) ?? 0, parts.decimal.length), 100);
|
|
273
|
+
if (Number.isFinite(Number(canonical))) try {
|
|
274
|
+
return getNumberFormat(locale, {
|
|
276
275
|
style: "currency",
|
|
277
276
|
currency,
|
|
278
277
|
currencyDisplay: "narrowSymbol",
|
|
279
|
-
minimumFractionDigits:
|
|
280
|
-
maximumFractionDigits:
|
|
278
|
+
minimumFractionDigits: digits,
|
|
279
|
+
maximumFractionDigits: digits,
|
|
281
280
|
useGrouping
|
|
282
|
-
});
|
|
283
|
-
if (intlSafe) return fmt.format(asNumber);
|
|
281
|
+
}).format(canonical);
|
|
284
282
|
} catch {}
|
|
285
|
-
return `${currency} ${formatPlain(parts,
|
|
283
|
+
return `${currency} ${formatPlain(parts, digits, locale, useGrouping)}`;
|
|
286
284
|
}
|
|
287
|
-
const base = formatPlain(
|
|
285
|
+
const base = formatPlain(splitDecimalString(canonical), scale, locale, useGrouping);
|
|
288
286
|
return unit ? `${base} ${unit}` : base;
|
|
289
287
|
}
|
|
290
288
|
function formatPlain(parts, scale, locale, useGrouping) {
|
package/dist/form/diff.cjs
CHANGED
|
@@ -15,7 +15,11 @@ let _atscript_db_validator = require("@atscript/db/validator");
|
|
|
15
15
|
* (`{ value: domainData }`) so this reuses {@link getByPath}.
|
|
16
16
|
*
|
|
17
17
|
* Revert-aware: a value edited back to its baseline produces no change and no
|
|
18
|
-
* patch entry.
|
|
18
|
+
* patch entry. A value stored unset (`null` / absent) that the form now holds
|
|
19
|
+
* as `""` is no change either, at any depth — a field typed into and emptied
|
|
20
|
+
* again, an optional text emptied on an edit form (since 0.1.205). The reverse
|
|
21
|
+
* is a change: a stored `""` that is now unset is sent as `null`. Emptying a
|
|
22
|
+
* stored value is a change to `""` / `null` / `false`.
|
|
19
23
|
*
|
|
20
24
|
* Snapshot contract: the result is NOT a deep copy. `$insert` items, `$replace`
|
|
21
25
|
* arrays, scalar leaf values, and `changes[].before/after` all hold live
|
|
@@ -76,7 +80,7 @@ function isNavKey(def, key) {
|
|
|
76
80
|
*/
|
|
77
81
|
function diffFields(fields, prefix, baseline, current, changes, patch, mergePaths, versionColumn) {
|
|
78
82
|
for (const field of fields) {
|
|
79
|
-
if (field.phantom || field.derived
|
|
83
|
+
if (field.phantom || field.derived || versionColumn !== void 0 && !prefix && field.path === versionColumn) continue;
|
|
80
84
|
const fullPath = prefix ? `${prefix}.${field.path}` : field.path;
|
|
81
85
|
if (require_types.isArrayField(field)) {
|
|
82
86
|
diffArrayField(field, fullPath, baseline, current, changes, patch, mergePaths);
|
|
@@ -111,7 +115,7 @@ function diffLeafRoot(def, baseline, current, changes, patch) {
|
|
|
111
115
|
const field = def.rootField;
|
|
112
116
|
const before = require_path_utils.getByPath(baseline, "");
|
|
113
117
|
const after = require_path_utils.getByPath(current, "");
|
|
114
|
-
if (
|
|
118
|
+
if (sameStored(before, after)) return;
|
|
115
119
|
const mergePaths = leafRootMergePaths(def.type);
|
|
116
120
|
if (require_types.isArrayField(field)) {
|
|
117
121
|
const arrayPatch = diffArray(field, before, after, mergePaths.has(LEAF_ROOT_KEY));
|
|
@@ -137,7 +141,7 @@ function diffLeafRoot(def, baseline, current, changes, patch) {
|
|
|
137
141
|
function diffScalarField(field, fullPath, baseline, current, changes, patch, mergePaths) {
|
|
138
142
|
const before = require_path_utils.getByPath(baseline, fullPath);
|
|
139
143
|
const after = require_path_utils.getByPath(current, fullPath);
|
|
140
|
-
if (
|
|
144
|
+
if (sameStored(before, after)) return;
|
|
141
145
|
changes.push({
|
|
142
146
|
path: fullPath,
|
|
143
147
|
kind: "set",
|
|
@@ -225,7 +229,7 @@ function diffObjectField(field, fullPath, baseline, current, changes, patch, mer
|
|
|
225
229
|
function diffArrayField(field, fullPath, baseline, current, changes, patch, mergePaths) {
|
|
226
230
|
const before = require_path_utils.getByPath(baseline, fullPath);
|
|
227
231
|
const after = require_path_utils.getByPath(current, fullPath);
|
|
228
|
-
if (
|
|
232
|
+
if (sameStored(before, after)) return;
|
|
229
233
|
const value = require_field_resolver.getFieldMeta(field.prop, "db.json") !== void 0 || require_field_resolver.getFieldMeta(field.prop, "db.encrypted") !== void 0 ? after ?? null : diffArray(field, before, after, mergePaths.has(fullPath));
|
|
230
234
|
if (value === void 0) return;
|
|
231
235
|
changes.push({
|
|
@@ -318,7 +322,7 @@ function diffKeyedArray(before, after, keyProps, merge) {
|
|
|
318
322
|
continue;
|
|
319
323
|
}
|
|
320
324
|
if (afterKeys[kept++] !== k) return { $replace: after };
|
|
321
|
-
if (
|
|
325
|
+
if (sameStored(prev, el)) continue;
|
|
322
326
|
const partial = buildKeyedUpdate(prev, el, keyProps);
|
|
323
327
|
if (!partial) continue;
|
|
324
328
|
if (incomplete(el)) return { $replace: after };
|
|
@@ -347,7 +351,7 @@ function buildKeyedUpdate(prev, next, keyProps) {
|
|
|
347
351
|
if (keyProps.includes(k)) continue;
|
|
348
352
|
const a = prev[k];
|
|
349
353
|
const b = next[k];
|
|
350
|
-
if (!
|
|
354
|
+
if (!sameStored(a, b)) {
|
|
351
355
|
partial[k] = b === void 0 ? null : b;
|
|
352
356
|
changed = true;
|
|
353
357
|
}
|
|
@@ -487,13 +491,27 @@ function stableKey(v) {
|
|
|
487
491
|
* unchanged. The patch cannot tell them apart either: it sends a cleared value
|
|
488
492
|
* as `null`.
|
|
489
493
|
*
|
|
490
|
-
* The single comparator shared across the form engine
|
|
491
|
-
* detection ({@link buildFormRebase})
|
|
492
|
-
* reimplement equality elsewhere.
|
|
494
|
+
* The single comparator shared across the form engine — the diff and conflict
|
|
495
|
+
* detection ({@link buildFormRebase}) — never reimplement equality elsewhere.
|
|
493
496
|
*/
|
|
494
497
|
function deepEqual(a, b) {
|
|
498
|
+
return equal(a, b, false);
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Whether the form's `after` leaves the stored `before` unchanged: {@link deepEqual},
|
|
502
|
+
* and a value stored unset (`null` / `undefined` / absent) that now holds `""` is
|
|
503
|
+
* unchanged too, at any depth — a field the user typed into and emptied again, an
|
|
504
|
+
* optional text emptied on an edit form (business mode), a field switched on and
|
|
505
|
+
* left empty. Asymmetric: a stored `""` that is now unset is a change. Since 0.1.205.
|
|
506
|
+
*/
|
|
507
|
+
function sameStored(before, after) {
|
|
508
|
+
return equal(before, after, true);
|
|
509
|
+
}
|
|
510
|
+
/** {@link deepEqual}; with `emptyText`, also `b === ""` over an unset `a` ({@link sameStored}). */
|
|
511
|
+
function equal(a, b, emptyText) {
|
|
495
512
|
if (a === b) return true;
|
|
496
|
-
|
|
513
|
+
const aUnset = a === null || a === void 0;
|
|
514
|
+
if (aUnset || b === null || b === void 0) return aUnset && (b === null || b === void 0 || emptyText && b === "");
|
|
497
515
|
if (typeof a === "number" && typeof b === "number") return Number.isNaN(a) && Number.isNaN(b);
|
|
498
516
|
if (typeof a !== "object" || typeof b !== "object") return false;
|
|
499
517
|
const aIsArr = Array.isArray(a);
|
|
@@ -501,13 +519,13 @@ function deepEqual(a, b) {
|
|
|
501
519
|
if (aIsArr !== bIsArr) return false;
|
|
502
520
|
if (aIsArr && bIsArr) {
|
|
503
521
|
if (a.length !== b.length) return false;
|
|
504
|
-
for (let i = 0; i < a.length; i++) if (!
|
|
522
|
+
for (let i = 0; i < a.length; i++) if (!equal(a[i], b[i], emptyText)) return false;
|
|
505
523
|
return true;
|
|
506
524
|
}
|
|
507
525
|
const ao = a;
|
|
508
526
|
const bo = b;
|
|
509
|
-
for (const k of Object.keys(ao)) if (!
|
|
510
|
-
for (const k of Object.keys(bo)) if (!Object.hasOwn(ao, k) &&
|
|
527
|
+
for (const k of Object.keys(ao)) if (!equal(ao[k], Object.hasOwn(bo, k) ? bo[k] : void 0, emptyText)) return false;
|
|
528
|
+
for (const k of Object.keys(bo)) if (!Object.hasOwn(ao, k) && !equal(void 0, bo[k], emptyText)) return false;
|
|
511
529
|
return true;
|
|
512
530
|
}
|
|
513
531
|
//#endregion
|
package/dist/form/diff.d.cts
CHANGED
|
@@ -60,7 +60,11 @@ interface FormDiffResult {
|
|
|
60
60
|
* (`{ value: domainData }`) so this reuses {@link getByPath}.
|
|
61
61
|
*
|
|
62
62
|
* Revert-aware: a value edited back to its baseline produces no change and no
|
|
63
|
-
* patch entry.
|
|
63
|
+
* patch entry. A value stored unset (`null` / absent) that the form now holds
|
|
64
|
+
* as `""` is no change either, at any depth — a field typed into and emptied
|
|
65
|
+
* again, an optional text emptied on an edit form (since 0.1.205). The reverse
|
|
66
|
+
* is a change: a stored `""` that is now unset is sent as `null`. Emptying a
|
|
67
|
+
* stored value is a change to `""` / `null` / `false`.
|
|
64
68
|
*
|
|
65
69
|
* Snapshot contract: the result is NOT a deep copy. `$insert` items, `$replace`
|
|
66
70
|
* arrays, scalar leaf values, and `changes[].before/after` all hold live
|
|
@@ -80,9 +84,8 @@ declare function buildFormDiff(def: FormDef, baseline: Record<string, unknown>,
|
|
|
80
84
|
* unchanged. The patch cannot tell them apart either: it sends a cleared value
|
|
81
85
|
* as `null`.
|
|
82
86
|
*
|
|
83
|
-
* The single comparator shared across the form engine
|
|
84
|
-
* detection ({@link buildFormRebase})
|
|
85
|
-
* reimplement equality elsewhere.
|
|
87
|
+
* The single comparator shared across the form engine — the diff and conflict
|
|
88
|
+
* detection ({@link buildFormRebase}) — never reimplement equality elsewhere.
|
|
86
89
|
*/
|
|
87
90
|
declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
88
91
|
//#endregion
|
package/dist/form/diff.d.mts
CHANGED
|
@@ -60,7 +60,11 @@ interface FormDiffResult {
|
|
|
60
60
|
* (`{ value: domainData }`) so this reuses {@link getByPath}.
|
|
61
61
|
*
|
|
62
62
|
* Revert-aware: a value edited back to its baseline produces no change and no
|
|
63
|
-
* patch entry.
|
|
63
|
+
* patch entry. A value stored unset (`null` / absent) that the form now holds
|
|
64
|
+
* as `""` is no change either, at any depth — a field typed into and emptied
|
|
65
|
+
* again, an optional text emptied on an edit form (since 0.1.205). The reverse
|
|
66
|
+
* is a change: a stored `""` that is now unset is sent as `null`. Emptying a
|
|
67
|
+
* stored value is a change to `""` / `null` / `false`.
|
|
64
68
|
*
|
|
65
69
|
* Snapshot contract: the result is NOT a deep copy. `$insert` items, `$replace`
|
|
66
70
|
* arrays, scalar leaf values, and `changes[].before/after` all hold live
|
|
@@ -80,9 +84,8 @@ declare function buildFormDiff(def: FormDef, baseline: Record<string, unknown>,
|
|
|
80
84
|
* unchanged. The patch cannot tell them apart either: it sends a cleared value
|
|
81
85
|
* as `null`.
|
|
82
86
|
*
|
|
83
|
-
* The single comparator shared across the form engine
|
|
84
|
-
* detection ({@link buildFormRebase})
|
|
85
|
-
* reimplement equality elsewhere.
|
|
87
|
+
* The single comparator shared across the form engine — the diff and conflict
|
|
88
|
+
* detection ({@link buildFormRebase}) — never reimplement equality elsewhere.
|
|
86
89
|
*/
|
|
87
90
|
declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
88
91
|
//#endregion
|