@narrative.io/jsonforms-provider-protocols 3.0.0-beta.11 → 3.0.0-beta.12
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProjection.d.ts","sourceRoot":"","sources":["../../../src/vue/composables/useProjection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"useProjection.d.ts","sourceRoot":"","sources":["../../../src/vue/composables/useProjection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAQnE,UAAU,iBAAiB;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,QAAQ,EAAE;QAAE,OAAO,CAAC,EAAE;YAAE,UAAU,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAE,CAAA;KAAE,CAAC;CACzE;AA8FD,MAAM,WAAW,gBAAgB;IAC/B,sDAAsD;IACtD,aAAa,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACpC,gEAAgE;IAEhE,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IAClD,8DAA8D;IAC9D,qBAAqB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9D,mCAAmC;IACnC,aAAa,EAAE,OAAO,CAAC;IACvB,sFAAsF;IACtF,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACpC,qEAAqE;IACrE,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACtC;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,GAAG,CAAC,iBAAiB,CAAC,EAC/B,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,GACnD,gBAAgB,CAyFlB"}
|
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import { computed, inject } from "vue";
|
|
2
|
-
import { getProjectedValue, getProjectedSchema, setProjectedValue } from "../../core/projection.js";
|
|
3
|
-
function resolveLabel(ctrl, schemaTitle) {
|
|
4
|
-
|
|
2
|
+
import { getProjectedValue, getProjectedSchema, parseProjectionPath, setProjectedValue } from "../../core/projection.js";
|
|
3
|
+
function resolveLabel(ctrl, schemaTitle, required) {
|
|
4
|
+
const base = ctrl.uischema?.options?.label ?? schemaTitle ?? ctrl.label ?? "";
|
|
5
|
+
if (!base) return base;
|
|
6
|
+
return required ? `${base} *` : base;
|
|
7
|
+
}
|
|
8
|
+
function isProjectedFieldRequired(schema, path) {
|
|
9
|
+
const segments = parseProjectionPath(path);
|
|
10
|
+
if (segments.length === 0) return false;
|
|
11
|
+
let current = schema;
|
|
12
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
13
|
+
const seg = segments[i];
|
|
14
|
+
if (typeof seg === "number") {
|
|
15
|
+
current = current?.items;
|
|
16
|
+
} else {
|
|
17
|
+
current = current?.properties?.[seg];
|
|
18
|
+
}
|
|
19
|
+
if (!current) return false;
|
|
20
|
+
}
|
|
21
|
+
const last = segments[segments.length - 1];
|
|
22
|
+
if (typeof last !== "string") return false;
|
|
23
|
+
return Array.isArray(current?.required) && current.required.includes(last);
|
|
5
24
|
}
|
|
6
25
|
function normalizeErrors(errors) {
|
|
7
26
|
if (!errors) return errors;
|
|
@@ -21,7 +40,9 @@ function getErrorPath(error) {
|
|
|
21
40
|
function useProjection(control, handleChange) {
|
|
22
41
|
const projection = control.value.uischema?.options?.projection;
|
|
23
42
|
if (!projection) {
|
|
24
|
-
const label2 = computed(
|
|
43
|
+
const label2 = computed(
|
|
44
|
+
() => resolveLabel(control.value, void 0, control.value.required)
|
|
45
|
+
);
|
|
25
46
|
return {
|
|
26
47
|
projectedData: computed(() => control.value.data),
|
|
27
48
|
projectedSchema: computed(() => control.value.schema),
|
|
@@ -47,8 +68,15 @@ function useProjection(control, handleChange) {
|
|
|
47
68
|
const projectedSchema = computed(
|
|
48
69
|
() => getProjectedSchema(control.value.schema, projection)
|
|
49
70
|
);
|
|
71
|
+
const projectedRequired = computed(
|
|
72
|
+
() => isProjectedFieldRequired(control.value.schema, projection)
|
|
73
|
+
);
|
|
50
74
|
const label = computed(
|
|
51
|
-
() => resolveLabel(
|
|
75
|
+
() => resolveLabel(
|
|
76
|
+
control.value,
|
|
77
|
+
projectedSchema.value?.title,
|
|
78
|
+
projectedRequired.value
|
|
79
|
+
)
|
|
52
80
|
);
|
|
53
81
|
const projectedErrors = computed(() => {
|
|
54
82
|
const baseErrors = normalizeErrors(control.value.errors || "");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProjection.js","sources":["../../../src/vue/composables/useProjection.ts"],"sourcesContent":["import { computed, inject, type ComputedRef, type Ref } from \"vue\";\nimport {\n getProjectedValue,\n setProjectedValue,\n getProjectedSchema,\n} from \"../../core/projection\";\n\ninterface ProjectionControl {\n data: unknown;\n path: string;\n errors: string;\n label?: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: Record<string, any>;\n uischema: { options?: { projection?: string; [key: string]: unknown } };\n}\n\n// Minimal AJV ErrorObject shape for filtering\ninterface ErrorLike {\n instancePath?: string;\n keyword?: string;\n message?: string;\n params?: { missingProperty?: string };\n}\n\n/**\n * Resolve the display label for a control.\n * Priority: uischema options.label → schemaTitle (projected sub-schema) → control.label.\n */\nfunction resolveLabel(ctrl: ProjectionControl, schemaTitle?: string): string {\n return (\n (ctrl.uischema?.options?.label as string) ?? schemaTitle ?? ctrl.label ?? \"\"\n );\n}\n\n/**\n * Normalize AJV error message fragments into user-friendly text.\n * e.g. \"is a required property\" → \"is required\"\n */\nfunction normalizeErrors(errors: string): string {\n if (!errors) return errors;\n return errors\n .replace(/is a required property/g, \"is required\")\n .replace(/must have required property '[^']*'/g, \"is required\");\n}\n\n/**\n * Prefix each error message line with the field label so that AJV fragments\n * like \"is required\" become \"Name is required\".\n */\nfunction prefixErrors(label: string, errors: string): string {\n if (!label || !errors) return errors;\n return errors\n .split(\"\\n\")\n .map((line) => `${label} ${line}`)\n .join(\"\\n\");\n}\n\n/**\n * Convert an AJV ErrorObject's instancePath to a dot-separated control path.\n * Replicates the logic from @jsonforms/core getControlPath.\n */\nfunction getErrorPath(error: ErrorLike): string {\n let p = (error.instancePath || \"\").replace(/\\//g, \".\").replace(/^\\./, \"\");\n if (error.keyword === \"required\" && error.params?.missingProperty) {\n p = p\n ? p + \".\" + error.params.missingProperty\n : error.params.missingProperty;\n }\n return p;\n}\n\nexport interface ProjectionResult {\n /** The value at the projected path (for rendering) */\n projectedData: ComputedRef<unknown>;\n /** The schema at the projected path (for renderer selection) */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n projectedSchema: ComputedRef<Record<string, any>>;\n /** Wrapped handleChange that writes through the projection */\n handleProjectedChange: (path: string, value: unknown) => void;\n /** Whether projection is active */\n hasProjection: boolean;\n /** Resolved display label (options.label → projected schema title → control.label) */\n projectedLabel: ComputedRef<string>;\n /** Error string combining base-path and projected sub-path errors */\n projectedErrors: ComputedRef<string>;\n}\n\n/**\n * Composable that wraps a JSON Forms control with projection support.\n *\n * When `options.projection` is set on the uischema, this composable:\n * - Reads the projected sub-value from the control data\n * - Resolves the projected sub-schema for renderer type resolution\n * - Wraps handleChange to write back through the projection path (preserving siblings)\n *\n * When no projection is set, it passes through control data/schema/handleChange unchanged.\n */\nexport function useProjection(\n control: Ref<ProjectionControl>,\n handleChange: (path: string, value: unknown) => void,\n): ProjectionResult {\n const projection = control.value.uischema?.options?.projection as\n | string\n | undefined;\n\n if (!projection) {\n const label = computed(() => resolveLabel(control.value));\n return {\n projectedData: computed(() => control.value.data),\n projectedSchema: computed(() => control.value.schema),\n handleProjectedChange: handleChange,\n hasProjection: false,\n projectedLabel: label,\n projectedErrors: computed(() =>\n prefixErrors(\n label.value.replace(/\\*$/, \"\").trim(),\n normalizeErrors(control.value.errors),\n ),\n ),\n };\n }\n\n // Inject JSONForms state to access raw AJV errors for projected sub-paths.\n // control.errors only contains errors at the exact control path (e.g. \"data_rates\"),\n // but projected fields need errors at the full path (e.g. \"data_rates.0.video_rate_usd\").\n const jsonforms = inject<{ core?: { errors?: ErrorLike[] } } | null>(\n \"jsonforms\",\n null,\n );\n\n const fullProjectedPath = control.value.path + \".\" + projection;\n\n const projectedData = computed(() =>\n getProjectedValue(control.value.data, projection),\n );\n\n const projectedSchema = computed(() =>\n getProjectedSchema(control.value.schema, projection),\n );\n\n const label = computed(() =>\n resolveLabel(control.value, projectedSchema.value?.title),\n );\n\n const projectedErrors = computed(() => {\n const baseErrors = normalizeErrors(control.value.errors || \"\");\n\n const rawErrors = jsonforms?.core?.errors ?? [];\n const matching = rawErrors.filter(\n (err) => getErrorPath(err) === fullProjectedPath,\n );\n\n let errStr: string;\n if (matching.length === 0) {\n errStr = baseErrors;\n } else {\n const projMsg = matching\n .map((e) => (e.keyword === \"required\" ? \"is required\" : e.message))\n .filter(Boolean)\n .join(\"\\n\");\n errStr = [baseErrors, projMsg].filter(Boolean).join(\"\\n\");\n }\n\n return prefixErrors(label.value.replace(/\\*$/, \"\").trim(), errStr);\n });\n\n const handleProjectedChange = (path: string, value: unknown) => {\n const fullValue = setProjectedValue(control.value.data, projection, value);\n handleChange(path, fullValue);\n };\n\n return {\n projectedData,\n projectedSchema,\n handleProjectedChange,\n hasProjection: true,\n projectedLabel: label,\n projectedErrors,\n };\n}\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type Ref } from \"vue\";\nimport {\n getProjectedValue,\n setProjectedValue,\n getProjectedSchema,\n parseProjectionPath,\n} from \"../../core/projection\";\n\ninterface ProjectionControl {\n data: unknown;\n path: string;\n errors: string;\n label?: string;\n required?: boolean;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: Record<string, any>;\n uischema: { options?: { projection?: string; [key: string]: unknown } };\n}\n\n// Minimal AJV ErrorObject shape for filtering\ninterface ErrorLike {\n instancePath?: string;\n keyword?: string;\n message?: string;\n params?: { missingProperty?: string };\n}\n\n/**\n * Resolve the display label for a control.\n * Priority: uischema options.label → schemaTitle (projected sub-schema) → control.label.\n * Appends a trailing asterisk when the control is for a required property.\n */\nfunction resolveLabel(\n ctrl: ProjectionControl,\n schemaTitle?: string,\n required?: boolean,\n): string {\n const base =\n (ctrl.uischema?.options?.label as string) ??\n schemaTitle ??\n ctrl.label ??\n \"\";\n if (!base) return base;\n return required ? `${base} *` : base;\n}\n\n/**\n * Determine whether the leaf of a projection path is listed in its parent\n * schema's `required` array. Numeric leaf segments (array indices) are not\n * considered \"required properties\".\n */\nfunction isProjectedFieldRequired(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: Record<string, any>,\n path: string,\n): boolean {\n const segments = parseProjectionPath(path);\n if (segments.length === 0) return false;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let current: Record<string, any> = schema;\n for (let i = 0; i < segments.length - 1; i++) {\n const seg = segments[i]!;\n if (typeof seg === \"number\") {\n current = current?.items;\n } else {\n current = current?.properties?.[seg];\n }\n if (!current) return false;\n }\n const last = segments[segments.length - 1];\n if (typeof last !== \"string\") return false;\n return Array.isArray(current?.required) && current.required.includes(last);\n}\n\n/**\n * Normalize AJV error message fragments into user-friendly text.\n * e.g. \"is a required property\" → \"is required\"\n */\nfunction normalizeErrors(errors: string): string {\n if (!errors) return errors;\n return errors\n .replace(/is a required property/g, \"is required\")\n .replace(/must have required property '[^']*'/g, \"is required\");\n}\n\n/**\n * Prefix each error message line with the field label so that AJV fragments\n * like \"is required\" become \"Name is required\".\n */\nfunction prefixErrors(label: string, errors: string): string {\n if (!label || !errors) return errors;\n return errors\n .split(\"\\n\")\n .map((line) => `${label} ${line}`)\n .join(\"\\n\");\n}\n\n/**\n * Convert an AJV ErrorObject's instancePath to a dot-separated control path.\n * Replicates the logic from @jsonforms/core getControlPath.\n */\nfunction getErrorPath(error: ErrorLike): string {\n let p = (error.instancePath || \"\").replace(/\\//g, \".\").replace(/^\\./, \"\");\n if (error.keyword === \"required\" && error.params?.missingProperty) {\n p = p\n ? p + \".\" + error.params.missingProperty\n : error.params.missingProperty;\n }\n return p;\n}\n\nexport interface ProjectionResult {\n /** The value at the projected path (for rendering) */\n projectedData: ComputedRef<unknown>;\n /** The schema at the projected path (for renderer selection) */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n projectedSchema: ComputedRef<Record<string, any>>;\n /** Wrapped handleChange that writes through the projection */\n handleProjectedChange: (path: string, value: unknown) => void;\n /** Whether projection is active */\n hasProjection: boolean;\n /** Resolved display label (options.label → projected schema title → control.label) */\n projectedLabel: ComputedRef<string>;\n /** Error string combining base-path and projected sub-path errors */\n projectedErrors: ComputedRef<string>;\n}\n\n/**\n * Composable that wraps a JSON Forms control with projection support.\n *\n * When `options.projection` is set on the uischema, this composable:\n * - Reads the projected sub-value from the control data\n * - Resolves the projected sub-schema for renderer type resolution\n * - Wraps handleChange to write back through the projection path (preserving siblings)\n *\n * When no projection is set, it passes through control data/schema/handleChange unchanged.\n */\nexport function useProjection(\n control: Ref<ProjectionControl>,\n handleChange: (path: string, value: unknown) => void,\n): ProjectionResult {\n const projection = control.value.uischema?.options?.projection as\n | string\n | undefined;\n\n if (!projection) {\n const label = computed(() =>\n resolveLabel(control.value, undefined, control.value.required),\n );\n return {\n projectedData: computed(() => control.value.data),\n projectedSchema: computed(() => control.value.schema),\n handleProjectedChange: handleChange,\n hasProjection: false,\n projectedLabel: label,\n projectedErrors: computed(() =>\n prefixErrors(\n label.value.replace(/\\*$/, \"\").trim(),\n normalizeErrors(control.value.errors),\n ),\n ),\n };\n }\n\n // Inject JSONForms state to access raw AJV errors for projected sub-paths.\n // control.errors only contains errors at the exact control path (e.g. \"data_rates\"),\n // but projected fields need errors at the full path (e.g. \"data_rates.0.video_rate_usd\").\n const jsonforms = inject<{ core?: { errors?: ErrorLike[] } } | null>(\n \"jsonforms\",\n null,\n );\n\n const fullProjectedPath = control.value.path + \".\" + projection;\n\n const projectedData = computed(() =>\n getProjectedValue(control.value.data, projection),\n );\n\n const projectedSchema = computed(() =>\n getProjectedSchema(control.value.schema, projection),\n );\n\n const projectedRequired = computed(() =>\n isProjectedFieldRequired(control.value.schema, projection),\n );\n\n const label = computed(() =>\n resolveLabel(\n control.value,\n projectedSchema.value?.title,\n projectedRequired.value,\n ),\n );\n\n const projectedErrors = computed(() => {\n const baseErrors = normalizeErrors(control.value.errors || \"\");\n\n const rawErrors = jsonforms?.core?.errors ?? [];\n const matching = rawErrors.filter(\n (err) => getErrorPath(err) === fullProjectedPath,\n );\n\n let errStr: string;\n if (matching.length === 0) {\n errStr = baseErrors;\n } else {\n const projMsg = matching\n .map((e) => (e.keyword === \"required\" ? \"is required\" : e.message))\n .filter(Boolean)\n .join(\"\\n\");\n errStr = [baseErrors, projMsg].filter(Boolean).join(\"\\n\");\n }\n\n return prefixErrors(label.value.replace(/\\*$/, \"\").trim(), errStr);\n });\n\n const handleProjectedChange = (path: string, value: unknown) => {\n const fullValue = setProjectedValue(control.value.data, projection, value);\n handleChange(path, fullValue);\n };\n\n return {\n projectedData,\n projectedSchema,\n handleProjectedChange,\n hasProjection: true,\n projectedLabel: label,\n projectedErrors,\n };\n}\n"],"names":["label"],"mappings":";;AAgCA,SAAS,aACP,MACA,aACA,UACQ;AACR,QAAM,OACH,KAAK,UAAU,SAAS,SACzB,eACA,KAAK,SACL;AACF,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,WAAW,GAAG,IAAI,OAAO;AAClC;AAOA,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E,OAAO,OAAO,EACd,KAAK,IAAI;AACZ,eAAS,CAAC,YAAY,OAAO,EAAE,OAAO,OAAO,EAAE,KAAK,IAAI;AAAA,IAC1D;AAEA,WAAO,aAAa,MAAM,MAAM,QAAQ,OAAO,EAAE,EAAE,KAAA,GAAQ,MAAM;AAAA,EACnE,CAAC;AAED,QAAM,wBAAwB,CAAC,MAAc,UAAmB;AAC9D,UAAM,YAAY,kBAAkB,QAAQ,MAAM,MAAM,YAAY,KAAK;AACzE,iBAAa,MAAM,SAAS;AAAA,EAC9B;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf,gBAAgB;AAAA,IAChB;AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
getProjectedValue,
|
|
4
4
|
setProjectedValue,
|
|
5
5
|
getProjectedSchema,
|
|
6
|
+
parseProjectionPath,
|
|
6
7
|
} from "../../core/projection";
|
|
7
8
|
|
|
8
9
|
interface ProjectionControl {
|
|
@@ -10,6 +11,7 @@ interface ProjectionControl {
|
|
|
10
11
|
path: string;
|
|
11
12
|
errors: string;
|
|
12
13
|
label?: string;
|
|
14
|
+
required?: boolean;
|
|
13
15
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
16
|
schema: Record<string, any>;
|
|
15
17
|
uischema: { options?: { projection?: string; [key: string]: unknown } };
|
|
@@ -26,11 +28,48 @@ interface ErrorLike {
|
|
|
26
28
|
/**
|
|
27
29
|
* Resolve the display label for a control.
|
|
28
30
|
* Priority: uischema options.label → schemaTitle (projected sub-schema) → control.label.
|
|
31
|
+
* Appends a trailing asterisk when the control is for a required property.
|
|
29
32
|
*/
|
|
30
|
-
function resolveLabel(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
function resolveLabel(
|
|
34
|
+
ctrl: ProjectionControl,
|
|
35
|
+
schemaTitle?: string,
|
|
36
|
+
required?: boolean,
|
|
37
|
+
): string {
|
|
38
|
+
const base =
|
|
39
|
+
(ctrl.uischema?.options?.label as string) ??
|
|
40
|
+
schemaTitle ??
|
|
41
|
+
ctrl.label ??
|
|
42
|
+
"";
|
|
43
|
+
if (!base) return base;
|
|
44
|
+
return required ? `${base} *` : base;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Determine whether the leaf of a projection path is listed in its parent
|
|
49
|
+
* schema's `required` array. Numeric leaf segments (array indices) are not
|
|
50
|
+
* considered "required properties".
|
|
51
|
+
*/
|
|
52
|
+
function isProjectedFieldRequired(
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
+
schema: Record<string, any>,
|
|
55
|
+
path: string,
|
|
56
|
+
): boolean {
|
|
57
|
+
const segments = parseProjectionPath(path);
|
|
58
|
+
if (segments.length === 0) return false;
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
+
let current: Record<string, any> = schema;
|
|
61
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
62
|
+
const seg = segments[i]!;
|
|
63
|
+
if (typeof seg === "number") {
|
|
64
|
+
current = current?.items;
|
|
65
|
+
} else {
|
|
66
|
+
current = current?.properties?.[seg];
|
|
67
|
+
}
|
|
68
|
+
if (!current) return false;
|
|
69
|
+
}
|
|
70
|
+
const last = segments[segments.length - 1];
|
|
71
|
+
if (typeof last !== "string") return false;
|
|
72
|
+
return Array.isArray(current?.required) && current.required.includes(last);
|
|
34
73
|
}
|
|
35
74
|
|
|
36
75
|
/**
|
|
@@ -105,7 +144,9 @@ export function useProjection(
|
|
|
105
144
|
| undefined;
|
|
106
145
|
|
|
107
146
|
if (!projection) {
|
|
108
|
-
const label = computed(() =>
|
|
147
|
+
const label = computed(() =>
|
|
148
|
+
resolveLabel(control.value, undefined, control.value.required),
|
|
149
|
+
);
|
|
109
150
|
return {
|
|
110
151
|
projectedData: computed(() => control.value.data),
|
|
111
152
|
projectedSchema: computed(() => control.value.schema),
|
|
@@ -139,8 +180,16 @@ export function useProjection(
|
|
|
139
180
|
getProjectedSchema(control.value.schema, projection),
|
|
140
181
|
);
|
|
141
182
|
|
|
183
|
+
const projectedRequired = computed(() =>
|
|
184
|
+
isProjectedFieldRequired(control.value.schema, projection),
|
|
185
|
+
);
|
|
186
|
+
|
|
142
187
|
const label = computed(() =>
|
|
143
|
-
resolveLabel(
|
|
188
|
+
resolveLabel(
|
|
189
|
+
control.value,
|
|
190
|
+
projectedSchema.value?.title,
|
|
191
|
+
projectedRequired.value,
|
|
192
|
+
),
|
|
144
193
|
);
|
|
145
194
|
|
|
146
195
|
const projectedErrors = computed(() => {
|