@atscript/ui 0.1.206 → 0.1.208
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 +16 -18
- package/dist/form/create-form-def.mjs +15 -17
- package/dist/form/decimal-format.cjs +8 -3
- package/dist/form/decimal-format.d.cts +8 -2
- package/dist/form/decimal-format.d.mts +8 -2
- package/dist/form/decimal-format.mjs +8 -3
- package/dist/form/form-actions.cjs +9 -0
- package/dist/form/form-actions.d.cts +7 -1
- package/dist/form/form-actions.d.mts +7 -1
- package/dist/form/form-actions.mjs +9 -1
- package/dist/form/measurement.cjs +58 -0
- package/dist/form/measurement.d.cts +36 -1
- package/dist/form/measurement.d.mts +36 -1
- package/dist/form/measurement.mjs +57 -2
- package/dist/form/omit-derived.cjs +11 -0
- package/dist/form/omit-derived.d.cts +8 -1
- package/dist/form/omit-derived.d.mts +8 -1
- package/dist/form/omit-derived.mjs +11 -1
- package/dist/form/optional-mode.cjs +7 -7
- package/dist/form/optional-mode.d.cts +2 -1
- package/dist/form/optional-mode.d.mts +2 -1
- package/dist/form/optional-mode.mjs +8 -8
- package/dist/form/path-utils.cjs +10 -0
- package/dist/form/path-utils.d.cts +8 -1
- package/dist/form/path-utils.d.mts +8 -1
- package/dist/form/path-utils.mjs +10 -1
- package/dist/form/types.cjs +5 -0
- package/dist/form/types.d.cts +14 -0
- package/dist/form/types.d.mts +14 -0
- package/dist/form/types.mjs +5 -1
- package/dist/form/validate.cjs +56 -5
- package/dist/form/validate.d.cts +30 -2
- package/dist/form/validate.d.mts +30 -2
- package/dist/form/validate.mjs +56 -6
- package/dist/index.cjs +42 -6
- package/dist/index.d.cts +20 -12
- package/dist/index.d.mts +20 -12
- package/dist/index.mjs +23 -15
- package/dist/plugin/annotations.cjs +33 -14
- package/dist/plugin/annotations.mjs +34 -15
- package/dist/plugin/value-help-validation.cjs +26 -6
- package/dist/plugin/value-help-validation.mjs +26 -7
- package/dist/shared/annotation-keys.cjs +3 -0
- package/dist/shared/annotation-keys.d.cts +2 -1
- package/dist/shared/annotation-keys.d.mts +2 -1
- package/dist/shared/annotation-keys.mjs +3 -1
- package/dist/shared/dev.cjs +22 -0
- package/dist/shared/dev.d.cts +4 -0
- package/dist/shared/dev.d.mts +4 -0
- package/dist/shared/dev.mjs +22 -0
- package/dist/shared/field-resolver.cjs +21 -1
- package/dist/shared/field-resolver.d.cts +15 -1
- package/dist/shared/field-resolver.d.mts +15 -1
- package/dist/shared/field-resolver.mjs +20 -2
- package/dist/shared/merge-filters.cjs +28 -0
- package/dist/shared/merge-filters.d.cts +13 -0
- package/dist/shared/merge-filters.d.mts +13 -0
- package/dist/shared/merge-filters.mjs +28 -0
- package/dist/shared/meta-cache.cjs +5 -4
- package/dist/shared/meta-cache.d.cts +3 -2
- package/dist/shared/meta-cache.d.mts +3 -2
- package/dist/shared/meta-cache.mjs +5 -4
- package/dist/shared/resolve-component.cjs +27 -0
- package/dist/shared/resolve-component.d.cts +22 -0
- package/dist/shared/resolve-component.d.mts +22 -0
- package/dist/shared/resolve-component.mjs +27 -0
- package/dist/shared/stable-key.cjs +28 -0
- package/dist/shared/stable-key.d.cts +13 -0
- package/dist/shared/stable-key.d.mts +13 -0
- package/dist/shared/stable-key.mjs +28 -0
- package/dist/shared/to-date.cjs +65 -0
- package/dist/shared/to-date.d.cts +35 -0
- package/dist/shared/to-date.d.mts +35 -0
- package/dist/shared/to-date.mjs +64 -0
- package/dist/shared/value-label.cjs +14 -2
- package/dist/shared/value-label.d.cts +23 -6
- package/dist/shared/value-label.d.mts +23 -6
- package/dist/shared/value-label.mjs +14 -3
- package/dist/table/create-table-def.cjs +53 -13
- package/dist/table/create-table-def.mjs +53 -15
- package/dist/table/types.d.cts +15 -13
- package/dist/table/types.d.mts +15 -13
- package/dist/value-help/client-store.cjs +43 -0
- package/dist/value-help/client-store.d.mts +1 -0
- package/dist/value-help/client-store.mjs +40 -0
- package/dist/value-help/display-value.cjs +30 -0
- package/dist/value-help/display-value.d.cts +45 -0
- package/dist/value-help/display-value.d.mts +45 -0
- package/dist/value-help/display-value.mjs +30 -0
- package/dist/value-help/distinct-client.cjs +80 -7
- package/dist/value-help/distinct-client.d.cts +31 -36
- package/dist/value-help/distinct-client.d.mts +31 -36
- package/dist/value-help/distinct-client.mjs +80 -7
- package/dist/value-help/extract-ref.cjs +15 -4
- package/dist/value-help/extract-ref.d.cts +6 -1
- package/dist/value-help/extract-ref.d.mts +6 -1
- package/dist/value-help/extract-ref.mjs +16 -6
- package/dist/value-help/index.d.mts +6 -3
- package/dist/value-help/options.cjs +70 -8
- package/dist/value-help/options.d.cts +57 -4
- package/dist/value-help/options.d.mts +57 -4
- package/dist/value-help/options.mjs +67 -9
- package/dist/value-help/resolve-options.cjs +9 -7
- package/dist/value-help/resolve-options.d.cts +8 -9
- package/dist/value-help/resolve-options.d.mts +8 -9
- package/dist/value-help/resolve-options.mjs +9 -7
- package/dist/value-help/resolve.cjs +29 -8
- package/dist/value-help/resolve.d.cts +22 -5
- package/dist/value-help/resolve.d.mts +22 -5
- package/dist/value-help/resolve.mjs +29 -8
- package/dist/value-help/scope.cjs +3 -7
- package/dist/value-help/scope.mjs +3 -7
- package/dist/value-help/source.cjs +72 -0
- package/dist/value-help/source.d.cts +55 -0
- package/dist/value-help/source.d.mts +55 -0
- package/dist/value-help/source.mjs +71 -0
- package/dist/value-help/texts.cjs +318 -0
- package/dist/value-help/texts.d.cts +53 -0
- package/dist/value-help/texts.d.mts +53 -0
- package/dist/value-help/texts.mjs +313 -0
- package/dist/value-help/types.d.cts +10 -0
- package/dist/value-help/types.d.mts +10 -0
- package/dist/value-help/value-help-client.cjs +24 -20
- package/dist/value-help/value-help-client.d.cts +10 -5
- package/dist/value-help/value-help-client.d.mts +10 -5
- package/dist/value-help/value-help-client.mjs +22 -18
- package/package.json +10 -10
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { FormDef } from "./types.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/form/omit-derived.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* What a form sends of its data `value` (the unwrapped domain data of `def`'s
|
|
6
|
+
* type, normalized) — `<AsForm>`'s submit data and an action's: without the
|
|
7
|
+
* navigation fields the form leaves out ({@link omitSkippedNavFields}) and the
|
|
8
|
+
* fields the server owns ({@link omitDerivedFields}). Since 0.1.208.
|
|
9
|
+
*/
|
|
10
|
+
declare function formPayload<T>(def: FormDef, value: T): T;
|
|
4
11
|
/**
|
|
5
12
|
* Form data `value` (the unwrapped domain data of `def`'s type) without the
|
|
6
13
|
* fields the server owns — the root fields `createFormDef` marked `derived`: a
|
|
@@ -14,4 +21,4 @@ import { FormDef } from "./types.mjs";
|
|
|
14
21
|
*/
|
|
15
22
|
declare function omitDerivedFields<T>(def: FormDef, value: T): T;
|
|
16
23
|
//#endregion
|
|
17
|
-
export { omitDerivedFields };
|
|
24
|
+
export { formPayload, omitDerivedFields };
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { isPlainObject } from "./path-utils.mjs";
|
|
2
|
+
import { omitSkippedNavFields } from "./skipped-nav.mjs";
|
|
2
3
|
//#region src/form/omit-derived.ts
|
|
3
4
|
/**
|
|
5
|
+
* What a form sends of its data `value` (the unwrapped domain data of `def`'s
|
|
6
|
+
* type, normalized) — `<AsForm>`'s submit data and an action's: without the
|
|
7
|
+
* navigation fields the form leaves out ({@link omitSkippedNavFields}) and the
|
|
8
|
+
* fields the server owns ({@link omitDerivedFields}). Since 0.1.208.
|
|
9
|
+
*/
|
|
10
|
+
function formPayload(def, value) {
|
|
11
|
+
return omitDerivedFields(def, omitSkippedNavFields(def, value));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
4
14
|
* Form data `value` (the unwrapped domain data of `def`'s type) without the
|
|
5
15
|
* fields the server owns — the root fields `createFormDef` marked `derived`: a
|
|
6
16
|
* served field `/meta` marks `readOnly`, a writable view's own field, a
|
|
@@ -35,4 +45,4 @@ function without(obj, keys, i) {
|
|
|
35
45
|
return rest;
|
|
36
46
|
}
|
|
37
47
|
//#endregion
|
|
38
|
-
export { omitDerivedFields };
|
|
48
|
+
export { formPayload, omitDerivedFields };
|
|
@@ -24,7 +24,7 @@ function getDefaultOptionalMode() {
|
|
|
24
24
|
* included), tuple or union field is always `"technical"`. Since 0.1.205.
|
|
25
25
|
*/
|
|
26
26
|
function resolveOptionalMode(field, formMode) {
|
|
27
|
-
if (require_types.
|
|
27
|
+
if (require_types.holdsFields(field)) return "technical";
|
|
28
28
|
const own = require_field_resolver.getFieldMeta(field.prop, require_annotation_keys.UI_FORM_OPTIONAL_MODE);
|
|
29
29
|
if (own === "business" || own === "technical") return own;
|
|
30
30
|
return formMode ?? defaultOptionalMode;
|
|
@@ -63,18 +63,18 @@ function takesEmptyText(prop) {
|
|
|
63
63
|
* - a set-only field (`@db.writeOnly`): always `undefined` — an empty input
|
|
64
64
|
* keeps the stored secret.
|
|
65
65
|
*
|
|
66
|
-
* A required field: `
|
|
66
|
+
* A required field: `false` for a boolean (since 0.1.208; was `null`), `""`
|
|
67
|
+
* for text and a string key, else `null`.
|
|
67
68
|
*/
|
|
68
69
|
function emptiedValue(field, opts) {
|
|
69
70
|
const prop = field.prop;
|
|
70
71
|
const dt = prop.type.kind === "" ? prop.type.designType : void 0;
|
|
71
72
|
const key = !!field.valueHelpInfo || field.type === "ref" || require_extract_ref.isForeignKey(prop);
|
|
72
73
|
const text = TEXT.has(field.type) && !key && !require_exact_number.isExactNumberText(prop);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
74
|
+
const unset = opts?.mode === "technical" || !opts?.edit || prop.metadata.has("db.writeOnly");
|
|
75
|
+
if (prop.optional && unset) return void 0;
|
|
76
|
+
if (dt === "boolean") return false;
|
|
77
|
+
if (prop.optional) return text && takesEmptyText(prop) ? "" : null;
|
|
78
78
|
if (key) return dt === "string" ? "" : null;
|
|
79
79
|
return text ? "" : null;
|
|
80
80
|
}
|
|
@@ -48,7 +48,8 @@ declare function resolveOptionalMode(field: FormFieldDef, formMode?: TOptionalMo
|
|
|
48
48
|
* - a set-only field (`@db.writeOnly`): always `undefined` — an empty input
|
|
49
49
|
* keeps the stored secret.
|
|
50
50
|
*
|
|
51
|
-
* A required field: `
|
|
51
|
+
* A required field: `false` for a boolean (since 0.1.208; was `null`), `""`
|
|
52
|
+
* for text and a string key, else `null`.
|
|
52
53
|
*/
|
|
53
54
|
declare function emptiedValue(field: FormFieldDef, opts?: {
|
|
54
55
|
mode?: TOptionalMode;
|
|
@@ -48,7 +48,8 @@ declare function resolveOptionalMode(field: FormFieldDef, formMode?: TOptionalMo
|
|
|
48
48
|
* - a set-only field (`@db.writeOnly`): always `undefined` — an empty input
|
|
49
49
|
* keeps the stored secret.
|
|
50
50
|
*
|
|
51
|
-
* A required field: `
|
|
51
|
+
* A required field: `false` for a boolean (since 0.1.208; was `null`), `""`
|
|
52
|
+
* for text and a string key, else `null`.
|
|
52
53
|
*/
|
|
53
54
|
declare function emptiedValue(field: FormFieldDef, opts?: {
|
|
54
55
|
mode?: TOptionalMode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UI_FORM_OPTIONAL_MODE } from "../shared/annotation-keys.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { holdsFields } from "./types.mjs";
|
|
3
3
|
import { getFieldMeta } from "../shared/field-resolver.mjs";
|
|
4
4
|
import { isForeignKey } from "../value-help/extract-ref.mjs";
|
|
5
5
|
import { isExactNumberText } from "../shared/exact-number.mjs";
|
|
@@ -24,7 +24,7 @@ function getDefaultOptionalMode() {
|
|
|
24
24
|
* included), tuple or union field is always `"technical"`. Since 0.1.205.
|
|
25
25
|
*/
|
|
26
26
|
function resolveOptionalMode(field, formMode) {
|
|
27
|
-
if (
|
|
27
|
+
if (holdsFields(field)) return "technical";
|
|
28
28
|
const own = getFieldMeta(field.prop, UI_FORM_OPTIONAL_MODE);
|
|
29
29
|
if (own === "business" || own === "technical") return own;
|
|
30
30
|
return formMode ?? defaultOptionalMode;
|
|
@@ -63,18 +63,18 @@ function takesEmptyText(prop) {
|
|
|
63
63
|
* - a set-only field (`@db.writeOnly`): always `undefined` — an empty input
|
|
64
64
|
* keeps the stored secret.
|
|
65
65
|
*
|
|
66
|
-
* A required field: `
|
|
66
|
+
* A required field: `false` for a boolean (since 0.1.208; was `null`), `""`
|
|
67
|
+
* for text and a string key, else `null`.
|
|
67
68
|
*/
|
|
68
69
|
function emptiedValue(field, opts) {
|
|
69
70
|
const prop = field.prop;
|
|
70
71
|
const dt = prop.type.kind === "" ? prop.type.designType : void 0;
|
|
71
72
|
const key = !!field.valueHelpInfo || field.type === "ref" || isForeignKey(prop);
|
|
72
73
|
const text = TEXT.has(field.type) && !key && !isExactNumberText(prop);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
74
|
+
const unset = opts?.mode === "technical" || !opts?.edit || prop.metadata.has("db.writeOnly");
|
|
75
|
+
if (prop.optional && unset) return void 0;
|
|
76
|
+
if (dt === "boolean") return false;
|
|
77
|
+
if (prop.optional) return text && takesEmptyText(prop) ? "" : null;
|
|
78
78
|
if (key) return dt === "string" ? "" : null;
|
|
79
79
|
return text ? "" : null;
|
|
80
80
|
}
|
package/dist/form/path-utils.cjs
CHANGED
|
@@ -15,6 +15,15 @@ function joinPath(prefix, segment) {
|
|
|
15
15
|
return prefix ? `${prefix}.${segment}` : segment;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
+
* The path of the object holding `path`, with its trailing dot — `""` at the
|
|
19
|
+
* top: where a field's siblings are (`shipping.city` → `shipping.`).
|
|
20
|
+
*
|
|
21
|
+
* @internal Shared with `@atscript/vue-form`.
|
|
22
|
+
*/
|
|
23
|
+
function parentPrefix(path) {
|
|
24
|
+
return path.slice(0, path.lastIndexOf(".") + 1);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
18
27
|
* Gets a nested value by dot-separated path.
|
|
19
28
|
* Always dereferences `obj.value` first (form data is wrapped in `{ value: domainData }`).
|
|
20
29
|
* When `path` is empty, returns the root domain data (`obj.value`).
|
|
@@ -195,4 +204,5 @@ exports.detectUnionVariant = detectUnionVariant;
|
|
|
195
204
|
exports.getByPath = getByPath;
|
|
196
205
|
exports.isPlainObject = isPlainObject;
|
|
197
206
|
exports.joinPath = joinPath;
|
|
207
|
+
exports.parentPrefix = parentPrefix;
|
|
198
208
|
exports.setByPath = setByPath;
|
|
@@ -8,6 +8,13 @@ import { TAtscriptAnnotatedType, TAtscriptDataType } from "@atscript/typescript/
|
|
|
8
8
|
* returns the segment as-is (no leading/trailing dots).
|
|
9
9
|
*/
|
|
10
10
|
declare function joinPath(prefix: string, segment: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* The path of the object holding `path`, with its trailing dot — `""` at the
|
|
13
|
+
* top: where a field's siblings are (`shipping.city` → `shipping.`).
|
|
14
|
+
*
|
|
15
|
+
* @internal Shared with `@atscript/vue-form`.
|
|
16
|
+
*/
|
|
17
|
+
declare function parentPrefix(path: string): string;
|
|
11
18
|
/**
|
|
12
19
|
* Gets a nested value by dot-separated path.
|
|
13
20
|
* Always dereferences `obj.value` first (form data is wrapped in `{ value: domainData }`).
|
|
@@ -43,4 +50,4 @@ declare function createFormData<T extends TAtscriptAnnotatedType>(type: T, resol
|
|
|
43
50
|
};
|
|
44
51
|
declare function detectUnionVariant(value: unknown, variants: FormUnionVariant[]): number;
|
|
45
52
|
//#endregion
|
|
46
|
-
export { TFormValueResolver, createFormData, createFormValueResolver, deleteByPath, detectUnionVariant, getByPath, joinPath, setByPath };
|
|
53
|
+
export { TFormValueResolver, createFormData, createFormValueResolver, deleteByPath, detectUnionVariant, getByPath, joinPath, parentPrefix, setByPath };
|
|
@@ -8,6 +8,13 @@ import { TAtscriptAnnotatedType, TAtscriptDataType } from "@atscript/typescript/
|
|
|
8
8
|
* returns the segment as-is (no leading/trailing dots).
|
|
9
9
|
*/
|
|
10
10
|
declare function joinPath(prefix: string, segment: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* The path of the object holding `path`, with its trailing dot — `""` at the
|
|
13
|
+
* top: where a field's siblings are (`shipping.city` → `shipping.`).
|
|
14
|
+
*
|
|
15
|
+
* @internal Shared with `@atscript/vue-form`.
|
|
16
|
+
*/
|
|
17
|
+
declare function parentPrefix(path: string): string;
|
|
11
18
|
/**
|
|
12
19
|
* Gets a nested value by dot-separated path.
|
|
13
20
|
* Always dereferences `obj.value` first (form data is wrapped in `{ value: domainData }`).
|
|
@@ -43,4 +50,4 @@ declare function createFormData<T extends TAtscriptAnnotatedType>(type: T, resol
|
|
|
43
50
|
};
|
|
44
51
|
declare function detectUnionVariant(value: unknown, variants: FormUnionVariant[]): number;
|
|
45
52
|
//#endregion
|
|
46
|
-
export { TFormValueResolver, createFormData, createFormValueResolver, deleteByPath, detectUnionVariant, getByPath, joinPath, setByPath };
|
|
53
|
+
export { TFormValueResolver, createFormData, createFormValueResolver, deleteByPath, detectUnionVariant, getByPath, joinPath, parentPrefix, setByPath };
|
package/dist/form/path-utils.mjs
CHANGED
|
@@ -15,6 +15,15 @@ function joinPath(prefix, segment) {
|
|
|
15
15
|
return prefix ? `${prefix}.${segment}` : segment;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
+
* The path of the object holding `path`, with its trailing dot — `""` at the
|
|
19
|
+
* top: where a field's siblings are (`shipping.city` → `shipping.`).
|
|
20
|
+
*
|
|
21
|
+
* @internal Shared with `@atscript/vue-form`.
|
|
22
|
+
*/
|
|
23
|
+
function parentPrefix(path) {
|
|
24
|
+
return path.slice(0, path.lastIndexOf(".") + 1);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
18
27
|
* Gets a nested value by dot-separated path.
|
|
19
28
|
* Always dereferences `obj.value` first (form data is wrapped in `{ value: domainData }`).
|
|
20
29
|
* When `path` is empty, returns the root domain data (`obj.value`).
|
|
@@ -188,4 +197,4 @@ function detectUnionVariant(value, variants) {
|
|
|
188
197
|
return 0;
|
|
189
198
|
}
|
|
190
199
|
//#endregion
|
|
191
|
-
export { createFormData, createFormValueResolver, deleteByPath, detectUnionVariant, getByPath, isPlainObject, joinPath, setByPath };
|
|
200
|
+
export { createFormData, createFormValueResolver, deleteByPath, detectUnionVariant, getByPath, isPlainObject, joinPath, parentPrefix, setByPath };
|
package/dist/form/types.cjs
CHANGED
|
@@ -15,6 +15,10 @@ function isUnionField(field) {
|
|
|
15
15
|
function isTupleField(field) {
|
|
16
16
|
return field.type === "tuple";
|
|
17
17
|
}
|
|
18
|
+
/** An object, array, tuple or union field: one holding other fields, which no input empties. */
|
|
19
|
+
function holdsFields(field) {
|
|
20
|
+
return isObjectField(field) || isArrayField(field) || isTupleField(field) || isUnionField(field);
|
|
21
|
+
}
|
|
18
22
|
/**
|
|
19
23
|
* The field defs directly below `field`: an object's fields, an array's item,
|
|
20
24
|
* a tuple's items, each union variant's fields and item. A recursive type's
|
|
@@ -34,6 +38,7 @@ function childFields(field) {
|
|
|
34
38
|
}
|
|
35
39
|
//#endregion
|
|
36
40
|
exports.childFields = childFields;
|
|
41
|
+
exports.holdsFields = holdsFields;
|
|
37
42
|
exports.isArrayField = isArrayField;
|
|
38
43
|
exports.isObjectField = isObjectField;
|
|
39
44
|
exports.isTupleField = isTupleField;
|
package/dist/form/types.d.cts
CHANGED
|
@@ -38,6 +38,12 @@ interface FormFieldDef {
|
|
|
38
38
|
* consumer to attach a flat custom widget to e.g. a `string[]`.
|
|
39
39
|
*/
|
|
40
40
|
customType?: string;
|
|
41
|
+
/**
|
|
42
|
+
* `@ui.form.component` — the name of the component that renders the field
|
|
43
|
+
* (`components[name]`, first in `resolveComponent`'s order), read once
|
|
44
|
+
* while the def is built. Since 0.1.208.
|
|
45
|
+
*/
|
|
46
|
+
component?: string;
|
|
41
47
|
phantom: boolean;
|
|
42
48
|
name: string;
|
|
43
49
|
/** True when no `ui.fn.*` metadata keys exist. Vue perf flag. */
|
|
@@ -151,6 +157,14 @@ interface FormArrayFieldDef extends FormFieldDef {
|
|
|
151
157
|
itemType: TAtscriptAnnotatedType;
|
|
152
158
|
/** Pre-built template field def for items (path=''). */
|
|
153
159
|
itemField: FormFieldDef;
|
|
160
|
+
/**
|
|
161
|
+
* `@expect.array.uniqueItems` — its own, or its union's on a `T[] | null`
|
|
162
|
+
* variant: a control that takes free entries (`tags`) refuses a duplicate.
|
|
163
|
+
* Since 0.1.208.
|
|
164
|
+
*/
|
|
165
|
+
uniqueItems: boolean;
|
|
166
|
+
/** The items are numbers: a free-entry control converts the typed text. Since 0.1.208. */
|
|
167
|
+
numericItems: boolean;
|
|
154
168
|
}
|
|
155
169
|
/** Extended field def for object (interface/type) nested fields. */
|
|
156
170
|
interface FormObjectFieldDef extends FormFieldDef {
|
package/dist/form/types.d.mts
CHANGED
|
@@ -38,6 +38,12 @@ interface FormFieldDef {
|
|
|
38
38
|
* consumer to attach a flat custom widget to e.g. a `string[]`.
|
|
39
39
|
*/
|
|
40
40
|
customType?: string;
|
|
41
|
+
/**
|
|
42
|
+
* `@ui.form.component` — the name of the component that renders the field
|
|
43
|
+
* (`components[name]`, first in `resolveComponent`'s order), read once
|
|
44
|
+
* while the def is built. Since 0.1.208.
|
|
45
|
+
*/
|
|
46
|
+
component?: string;
|
|
41
47
|
phantom: boolean;
|
|
42
48
|
name: string;
|
|
43
49
|
/** True when no `ui.fn.*` metadata keys exist. Vue perf flag. */
|
|
@@ -151,6 +157,14 @@ interface FormArrayFieldDef extends FormFieldDef {
|
|
|
151
157
|
itemType: TAtscriptAnnotatedType;
|
|
152
158
|
/** Pre-built template field def for items (path=''). */
|
|
153
159
|
itemField: FormFieldDef;
|
|
160
|
+
/**
|
|
161
|
+
* `@expect.array.uniqueItems` — its own, or its union's on a `T[] | null`
|
|
162
|
+
* variant: a control that takes free entries (`tags`) refuses a duplicate.
|
|
163
|
+
* Since 0.1.208.
|
|
164
|
+
*/
|
|
165
|
+
uniqueItems: boolean;
|
|
166
|
+
/** The items are numbers: a free-entry control converts the typed text. Since 0.1.208. */
|
|
167
|
+
numericItems: boolean;
|
|
154
168
|
}
|
|
155
169
|
/** Extended field def for object (interface/type) nested fields. */
|
|
156
170
|
interface FormObjectFieldDef extends FormFieldDef {
|
package/dist/form/types.mjs
CHANGED
|
@@ -15,6 +15,10 @@ function isUnionField(field) {
|
|
|
15
15
|
function isTupleField(field) {
|
|
16
16
|
return field.type === "tuple";
|
|
17
17
|
}
|
|
18
|
+
/** An object, array, tuple or union field: one holding other fields, which no input empties. */
|
|
19
|
+
function holdsFields(field) {
|
|
20
|
+
return isObjectField(field) || isArrayField(field) || isTupleField(field) || isUnionField(field);
|
|
21
|
+
}
|
|
18
22
|
/**
|
|
19
23
|
* The field defs directly below `field`: an object's fields, an array's item,
|
|
20
24
|
* a tuple's items, each union variant's fields and item. A recursive type's
|
|
@@ -33,4 +37,4 @@ function childFields(field) {
|
|
|
33
37
|
return children;
|
|
34
38
|
}
|
|
35
39
|
//#endregion
|
|
36
|
-
export { childFields, isArrayField, isObjectField, isTupleField, isUnionField };
|
|
40
|
+
export { childFields, holdsFields, isArrayField, isObjectField, isTupleField, isUnionField };
|
package/dist/form/validate.cjs
CHANGED
|
@@ -4,6 +4,7 @@ const require_ui_texts = require("../i18n/ui-texts.cjs");
|
|
|
4
4
|
const require_extract_ref = require("../value-help/extract-ref.cjs");
|
|
5
5
|
const require_skipped_nav = require("./skipped-nav.cjs");
|
|
6
6
|
const require_create_form_def = require("./create-form-def.cjs");
|
|
7
|
+
const require_optional_mode = require("./optional-mode.cjs");
|
|
7
8
|
const require_error_utils = require("./error-utils.cjs");
|
|
8
9
|
let _atscript_typescript_utils = require("@atscript/typescript/utils");
|
|
9
10
|
let _atscript_db_validator = require("@atscript/db/validator");
|
|
@@ -245,6 +246,17 @@ function isContainerKind(kind) {
|
|
|
245
246
|
return kind === "object" || kind === "array" || kind === "tuple";
|
|
246
247
|
}
|
|
247
248
|
/**
|
|
249
|
+
* The plugins a field's own value is judged with: the server-managed rules,
|
|
250
|
+
* `rules`, then a value-help picker left unpicked (`picker`).
|
|
251
|
+
*/
|
|
252
|
+
function fieldPlugins(prop, picker, rules) {
|
|
253
|
+
return [
|
|
254
|
+
serverManagedPlugin,
|
|
255
|
+
...rules,
|
|
256
|
+
...picker ? [missingPickPlugin(new Set([prop]))] : []
|
|
257
|
+
];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
248
260
|
* Creates a cached validator function for a single ATScript prop.
|
|
249
261
|
*
|
|
250
262
|
* The `Validator` instance is created lazily on first call and reused.
|
|
@@ -255,6 +267,8 @@ function isContainerKind(kind) {
|
|
|
255
267
|
* judges it (the value itself is not changed).
|
|
256
268
|
* With `rootOnly`, an object / array / tuple prop is validated at its root
|
|
257
269
|
* only (descendants are not walked — their errors would be discarded anyway).
|
|
270
|
+
* `externalCtx.path` is where the value sits in the form data — the path a
|
|
271
|
+
* `@ui.form.validate` rule's `entry.field` starts from (since 0.1.208).
|
|
258
272
|
*/
|
|
259
273
|
function createFieldValidator(prop, opts) {
|
|
260
274
|
let cached;
|
|
@@ -267,11 +281,7 @@ function createFieldValidator(prop, opts) {
|
|
|
267
281
|
skipDescendantsPlugin,
|
|
268
282
|
serverManagedPlugin,
|
|
269
283
|
...defaultValidatorPlugins
|
|
270
|
-
] :
|
|
271
|
-
serverManagedPlugin,
|
|
272
|
-
...defaultValidatorPlugins,
|
|
273
|
-
...opts?.picker ? [missingPickPlugin(new Set([prop]))] : []
|
|
274
|
-
] };
|
|
284
|
+
] : fieldPlugins(prop, opts?.picker, defaultValidatorPlugins) };
|
|
275
285
|
cached = new _atscript_typescript_utils.Validator(prop, options);
|
|
276
286
|
}
|
|
277
287
|
const judged = skipNormalize ? value : (0, _atscript_typescript_utils.normalizeForType)(prop, value, options);
|
|
@@ -286,10 +296,51 @@ function createFieldValidator(prop, opts) {
|
|
|
286
296
|
return error && messageIn(error, t, served) || t("UI_INVALID_VALUE");
|
|
287
297
|
};
|
|
288
298
|
}
|
|
299
|
+
/** Per prop: whether its type refuses an emptied value, keyed by value (and the picker rule). */
|
|
300
|
+
const refusedCache = /* @__PURE__ */ new WeakMap();
|
|
301
|
+
/**
|
|
302
|
+
* Whether `field` shows as required — the `*` of its label, `aria-required`
|
|
303
|
+
* (since 0.1.208): the value the field is left with once the user empties it
|
|
304
|
+
* is one the type's own rules refuse — its kind, `@expect.*`,
|
|
305
|
+
* `@meta.required`, a value-help picker left unpicked; not a
|
|
306
|
+
* `@ui.form.validate` rule, which may read other fields. That value is
|
|
307
|
+
* {@link emptiedValue} (per `opts.mode`, the field's `resolveOptionalMode`,
|
|
308
|
+
* and `opts.edit`, the form's `FormDef.edit`); `[]` for a required array;
|
|
309
|
+
* for a required union, the emptied value of the variant it shows
|
|
310
|
+
* (`opts.variant`), judged by the union's rules. Never for a phantom,
|
|
311
|
+
* server-owned (`derived`) or read-only field, an object or a tuple, an
|
|
312
|
+
* optional array or union, nor a union without `opts.variant`.
|
|
313
|
+
* `opts.readonly` is the field's read-only state when the caller resolved it
|
|
314
|
+
* (`@ui.form.fn.readonly`, an enclosing field's lock); `@meta.readonly` when
|
|
315
|
+
* left out.
|
|
316
|
+
*/
|
|
317
|
+
function isFieldRequired(field, opts) {
|
|
318
|
+
if ((opts?.readonly ?? field.prop.metadata.has("meta.readonly")) || field.phantom || field.derived) return false;
|
|
319
|
+
const value = leftEmpty(field, opts);
|
|
320
|
+
if (value === void 0) return false;
|
|
321
|
+
const prop = field.prop;
|
|
322
|
+
let byValue = refusedCache.get(prop);
|
|
323
|
+
if (!byValue) refusedCache.set(prop, byValue = /* @__PURE__ */ new Map());
|
|
324
|
+
const key = `${field.picker ? "picker:" : ""}${JSON.stringify(value)}`;
|
|
325
|
+
let refused = byValue.get(key);
|
|
326
|
+
if (refused === void 0) {
|
|
327
|
+
refused = !new _atscript_typescript_utils.Validator(prop, { plugins: fieldPlugins(prop, field.picker, []) }).validate(value, true);
|
|
328
|
+
byValue.set(key, refused);
|
|
329
|
+
}
|
|
330
|
+
return refused;
|
|
331
|
+
}
|
|
332
|
+
/** The value {@link isFieldRequired} judges: `undefined` for one no input leaves. */
|
|
333
|
+
function leftEmpty(field, opts) {
|
|
334
|
+
if (require_types.isObjectField(field) || require_types.isTupleField(field)) return void 0;
|
|
335
|
+
if (require_types.isUnionField(field)) return opts?.variant && !field.prop.optional ? leftEmpty(opts.variant) : void 0;
|
|
336
|
+
if (require_types.isArrayField(field)) return field.prop.optional ? void 0 : [];
|
|
337
|
+
return require_optional_mode.emptiedValue(field, opts);
|
|
338
|
+
}
|
|
289
339
|
//#endregion
|
|
290
340
|
exports.UI_FORM_VALIDATE_ERROR_CODE = UI_FORM_VALIDATE_ERROR_CODE;
|
|
291
341
|
exports.createFieldValidator = createFieldValidator;
|
|
292
342
|
exports.getDefaultValidatorPlugins = getDefaultValidatorPlugins;
|
|
293
343
|
exports.getFormValidator = getFormValidator;
|
|
294
344
|
exports.isContainerKind = isContainerKind;
|
|
345
|
+
exports.isFieldRequired = isFieldRequired;
|
|
295
346
|
exports.setDefaultValidatorPlugins = setDefaultValidatorPlugins;
|
package/dist/form/validate.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { FormDef } from "./types.cjs";
|
|
1
|
+
import { FormDef, FormFieldDef } from "./types.cjs";
|
|
2
|
+
import { TOptionalMode } from "./optional-mode.cjs";
|
|
2
3
|
import { UiT } from "../i18n/ui-texts.cjs";
|
|
3
4
|
import { TAtscriptAnnotatedType, TValidatorOptions, TValidatorPlugin } from "@atscript/typescript/utils";
|
|
4
5
|
|
|
@@ -87,11 +88,38 @@ declare function isContainerKind(kind: string): boolean;
|
|
|
87
88
|
* judges it (the value itself is not changed).
|
|
88
89
|
* With `rootOnly`, an object / array / tuple prop is validated at its root
|
|
89
90
|
* only (descendants are not walked — their errors would be discarded anyway).
|
|
91
|
+
* `externalCtx.path` is where the value sits in the form data — the path a
|
|
92
|
+
* `@ui.form.validate` rule's `entry.field` starts from (since 0.1.208).
|
|
90
93
|
*/
|
|
91
94
|
declare function createFieldValidator(prop: TAtscriptAnnotatedType, opts?: TFieldValidatorOptions): (value: unknown, externalCtx?: {
|
|
92
95
|
data: unknown;
|
|
93
96
|
context: unknown;
|
|
94
97
|
t?: UiT;
|
|
98
|
+
path?: string;
|
|
95
99
|
}) => true | string;
|
|
100
|
+
/** Options of {@link isFieldRequired}. */
|
|
101
|
+
interface TFieldRequiredOptions {
|
|
102
|
+
mode?: TOptionalMode;
|
|
103
|
+
edit?: boolean;
|
|
104
|
+
readonly?: boolean;
|
|
105
|
+
variant?: FormFieldDef;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Whether `field` shows as required — the `*` of its label, `aria-required`
|
|
109
|
+
* (since 0.1.208): the value the field is left with once the user empties it
|
|
110
|
+
* is one the type's own rules refuse — its kind, `@expect.*`,
|
|
111
|
+
* `@meta.required`, a value-help picker left unpicked; not a
|
|
112
|
+
* `@ui.form.validate` rule, which may read other fields. That value is
|
|
113
|
+
* {@link emptiedValue} (per `opts.mode`, the field's `resolveOptionalMode`,
|
|
114
|
+
* and `opts.edit`, the form's `FormDef.edit`); `[]` for a required array;
|
|
115
|
+
* for a required union, the emptied value of the variant it shows
|
|
116
|
+
* (`opts.variant`), judged by the union's rules. Never for a phantom,
|
|
117
|
+
* server-owned (`derived`) or read-only field, an object or a tuple, an
|
|
118
|
+
* optional array or union, nor a union without `opts.variant`.
|
|
119
|
+
* `opts.readonly` is the field's read-only state when the caller resolved it
|
|
120
|
+
* (`@ui.form.fn.readonly`, an enclosing field's lock); `@meta.readonly` when
|
|
121
|
+
* left out.
|
|
122
|
+
*/
|
|
123
|
+
declare function isFieldRequired(field: FormFieldDef, opts?: TFieldRequiredOptions): boolean;
|
|
96
124
|
//#endregion
|
|
97
|
-
export { FormValidator, TFieldValidatorOptions, TFormValidatorCallOptions, UI_FORM_VALIDATE_ERROR_CODE, createFieldValidator, getDefaultValidatorPlugins, getFormValidator, isContainerKind, setDefaultValidatorPlugins };
|
|
125
|
+
export { FormValidator, TFieldValidatorOptions, TFormValidatorCallOptions, UI_FORM_VALIDATE_ERROR_CODE, createFieldValidator, getDefaultValidatorPlugins, getFormValidator, isContainerKind, isFieldRequired, setDefaultValidatorPlugins };
|
package/dist/form/validate.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { FormDef } from "./types.mjs";
|
|
1
|
+
import { FormDef, FormFieldDef } from "./types.mjs";
|
|
2
|
+
import { TOptionalMode } from "./optional-mode.mjs";
|
|
2
3
|
import { UiT } from "../i18n/ui-texts.mjs";
|
|
3
4
|
import { TAtscriptAnnotatedType, TValidatorOptions, TValidatorPlugin } from "@atscript/typescript/utils";
|
|
4
5
|
|
|
@@ -87,11 +88,38 @@ declare function isContainerKind(kind: string): boolean;
|
|
|
87
88
|
* judges it (the value itself is not changed).
|
|
88
89
|
* With `rootOnly`, an object / array / tuple prop is validated at its root
|
|
89
90
|
* only (descendants are not walked — their errors would be discarded anyway).
|
|
91
|
+
* `externalCtx.path` is where the value sits in the form data — the path a
|
|
92
|
+
* `@ui.form.validate` rule's `entry.field` starts from (since 0.1.208).
|
|
90
93
|
*/
|
|
91
94
|
declare function createFieldValidator(prop: TAtscriptAnnotatedType, opts?: TFieldValidatorOptions): (value: unknown, externalCtx?: {
|
|
92
95
|
data: unknown;
|
|
93
96
|
context: unknown;
|
|
94
97
|
t?: UiT;
|
|
98
|
+
path?: string;
|
|
95
99
|
}) => true | string;
|
|
100
|
+
/** Options of {@link isFieldRequired}. */
|
|
101
|
+
interface TFieldRequiredOptions {
|
|
102
|
+
mode?: TOptionalMode;
|
|
103
|
+
edit?: boolean;
|
|
104
|
+
readonly?: boolean;
|
|
105
|
+
variant?: FormFieldDef;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Whether `field` shows as required — the `*` of its label, `aria-required`
|
|
109
|
+
* (since 0.1.208): the value the field is left with once the user empties it
|
|
110
|
+
* is one the type's own rules refuse — its kind, `@expect.*`,
|
|
111
|
+
* `@meta.required`, a value-help picker left unpicked; not a
|
|
112
|
+
* `@ui.form.validate` rule, which may read other fields. That value is
|
|
113
|
+
* {@link emptiedValue} (per `opts.mode`, the field's `resolveOptionalMode`,
|
|
114
|
+
* and `opts.edit`, the form's `FormDef.edit`); `[]` for a required array;
|
|
115
|
+
* for a required union, the emptied value of the variant it shows
|
|
116
|
+
* (`opts.variant`), judged by the union's rules. Never for a phantom,
|
|
117
|
+
* server-owned (`derived`) or read-only field, an object or a tuple, an
|
|
118
|
+
* optional array or union, nor a union without `opts.variant`.
|
|
119
|
+
* `opts.readonly` is the field's read-only state when the caller resolved it
|
|
120
|
+
* (`@ui.form.fn.readonly`, an enclosing field's lock); `@meta.readonly` when
|
|
121
|
+
* left out.
|
|
122
|
+
*/
|
|
123
|
+
declare function isFieldRequired(field: FormFieldDef, opts?: TFieldRequiredOptions): boolean;
|
|
96
124
|
//#endregion
|
|
97
|
-
export { FormValidator, TFieldValidatorOptions, TFormValidatorCallOptions, UI_FORM_VALIDATE_ERROR_CODE, createFieldValidator, getDefaultValidatorPlugins, getFormValidator, isContainerKind, setDefaultValidatorPlugins };
|
|
125
|
+
export { FormValidator, TFieldValidatorOptions, TFormValidatorCallOptions, UI_FORM_VALIDATE_ERROR_CODE, createFieldValidator, getDefaultValidatorPlugins, getFormValidator, isContainerKind, isFieldRequired, setDefaultValidatorPlugins };
|
package/dist/form/validate.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { getUiTexts } from "../i18n/ui-texts.mjs";
|
|
|
4
4
|
import { isForeignKey, isValueHelpPicker } from "../value-help/extract-ref.mjs";
|
|
5
5
|
import { isSkippedNavField } from "./skipped-nav.mjs";
|
|
6
6
|
import { isServerComputed, resolveOriginalProp } from "./create-form-def.mjs";
|
|
7
|
+
import { emptiedValue } from "./optional-mode.mjs";
|
|
7
8
|
import { validatorErrorsToMap } from "./error-utils.mjs";
|
|
8
9
|
import { VALIDATOR_MESSAGES, Validator, localizeErrors, normalizeForType } from "@atscript/typescript/utils";
|
|
9
10
|
import { createDbValidatorPlugin } from "@atscript/db/validator";
|
|
@@ -245,6 +246,17 @@ function isContainerKind(kind) {
|
|
|
245
246
|
return kind === "object" || kind === "array" || kind === "tuple";
|
|
246
247
|
}
|
|
247
248
|
/**
|
|
249
|
+
* The plugins a field's own value is judged with: the server-managed rules,
|
|
250
|
+
* `rules`, then a value-help picker left unpicked (`picker`).
|
|
251
|
+
*/
|
|
252
|
+
function fieldPlugins(prop, picker, rules) {
|
|
253
|
+
return [
|
|
254
|
+
serverManagedPlugin,
|
|
255
|
+
...rules,
|
|
256
|
+
...picker ? [missingPickPlugin(new Set([prop]))] : []
|
|
257
|
+
];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
248
260
|
* Creates a cached validator function for a single ATScript prop.
|
|
249
261
|
*
|
|
250
262
|
* The `Validator` instance is created lazily on first call and reused.
|
|
@@ -255,6 +267,8 @@ function isContainerKind(kind) {
|
|
|
255
267
|
* judges it (the value itself is not changed).
|
|
256
268
|
* With `rootOnly`, an object / array / tuple prop is validated at its root
|
|
257
269
|
* only (descendants are not walked — their errors would be discarded anyway).
|
|
270
|
+
* `externalCtx.path` is where the value sits in the form data — the path a
|
|
271
|
+
* `@ui.form.validate` rule's `entry.field` starts from (since 0.1.208).
|
|
258
272
|
*/
|
|
259
273
|
function createFieldValidator(prop, opts) {
|
|
260
274
|
let cached;
|
|
@@ -267,11 +281,7 @@ function createFieldValidator(prop, opts) {
|
|
|
267
281
|
skipDescendantsPlugin,
|
|
268
282
|
serverManagedPlugin,
|
|
269
283
|
...defaultValidatorPlugins
|
|
270
|
-
] :
|
|
271
|
-
serverManagedPlugin,
|
|
272
|
-
...defaultValidatorPlugins,
|
|
273
|
-
...opts?.picker ? [missingPickPlugin(new Set([prop]))] : []
|
|
274
|
-
] };
|
|
284
|
+
] : fieldPlugins(prop, opts?.picker, defaultValidatorPlugins) };
|
|
275
285
|
cached = new Validator(prop, options);
|
|
276
286
|
}
|
|
277
287
|
const judged = skipNormalize ? value : normalizeForType(prop, value, options);
|
|
@@ -286,5 +296,45 @@ function createFieldValidator(prop, opts) {
|
|
|
286
296
|
return error && messageIn(error, t, served) || t("UI_INVALID_VALUE");
|
|
287
297
|
};
|
|
288
298
|
}
|
|
299
|
+
/** Per prop: whether its type refuses an emptied value, keyed by value (and the picker rule). */
|
|
300
|
+
const refusedCache = /* @__PURE__ */ new WeakMap();
|
|
301
|
+
/**
|
|
302
|
+
* Whether `field` shows as required — the `*` of its label, `aria-required`
|
|
303
|
+
* (since 0.1.208): the value the field is left with once the user empties it
|
|
304
|
+
* is one the type's own rules refuse — its kind, `@expect.*`,
|
|
305
|
+
* `@meta.required`, a value-help picker left unpicked; not a
|
|
306
|
+
* `@ui.form.validate` rule, which may read other fields. That value is
|
|
307
|
+
* {@link emptiedValue} (per `opts.mode`, the field's `resolveOptionalMode`,
|
|
308
|
+
* and `opts.edit`, the form's `FormDef.edit`); `[]` for a required array;
|
|
309
|
+
* for a required union, the emptied value of the variant it shows
|
|
310
|
+
* (`opts.variant`), judged by the union's rules. Never for a phantom,
|
|
311
|
+
* server-owned (`derived`) or read-only field, an object or a tuple, an
|
|
312
|
+
* optional array or union, nor a union without `opts.variant`.
|
|
313
|
+
* `opts.readonly` is the field's read-only state when the caller resolved it
|
|
314
|
+
* (`@ui.form.fn.readonly`, an enclosing field's lock); `@meta.readonly` when
|
|
315
|
+
* left out.
|
|
316
|
+
*/
|
|
317
|
+
function isFieldRequired(field, opts) {
|
|
318
|
+
if ((opts?.readonly ?? field.prop.metadata.has("meta.readonly")) || field.phantom || field.derived) return false;
|
|
319
|
+
const value = leftEmpty(field, opts);
|
|
320
|
+
if (value === void 0) return false;
|
|
321
|
+
const prop = field.prop;
|
|
322
|
+
let byValue = refusedCache.get(prop);
|
|
323
|
+
if (!byValue) refusedCache.set(prop, byValue = /* @__PURE__ */ new Map());
|
|
324
|
+
const key = `${field.picker ? "picker:" : ""}${JSON.stringify(value)}`;
|
|
325
|
+
let refused = byValue.get(key);
|
|
326
|
+
if (refused === void 0) {
|
|
327
|
+
refused = !new Validator(prop, { plugins: fieldPlugins(prop, field.picker, []) }).validate(value, true);
|
|
328
|
+
byValue.set(key, refused);
|
|
329
|
+
}
|
|
330
|
+
return refused;
|
|
331
|
+
}
|
|
332
|
+
/** The value {@link isFieldRequired} judges: `undefined` for one no input leaves. */
|
|
333
|
+
function leftEmpty(field, opts) {
|
|
334
|
+
if (isObjectField(field) || isTupleField(field)) return void 0;
|
|
335
|
+
if (isUnionField(field)) return opts?.variant && !field.prop.optional ? leftEmpty(opts.variant) : void 0;
|
|
336
|
+
if (isArrayField(field)) return field.prop.optional ? void 0 : [];
|
|
337
|
+
return emptiedValue(field, opts);
|
|
338
|
+
}
|
|
289
339
|
//#endregion
|
|
290
|
-
export { UI_FORM_VALIDATE_ERROR_CODE, createFieldValidator, getDefaultValidatorPlugins, getFormValidator, isContainerKind, setDefaultValidatorPlugins };
|
|
340
|
+
export { UI_FORM_VALIDATE_ERROR_CODE, createFieldValidator, getDefaultValidatorPlugins, getFormValidator, isContainerKind, isFieldRequired, setDefaultValidatorPlugins };
|