@ng-forge/dynamic-forms 0.3.1 → 0.5.0

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.
Files changed (22) hide show
  1. package/README.md +5 -1
  2. package/fesm2022/ng-forge-dynamic-forms-integration.mjs +37 -66
  3. package/fesm2022/ng-forge-dynamic-forms-integration.mjs.map +1 -1
  4. package/fesm2022/{ng-forge-dynamic-forms-ng-forge-dynamic-forms-D58rojQc.mjs → ng-forge-dynamic-forms-ng-forge-dynamic-forms-WGww2nXx.mjs} +3572 -346
  5. package/fesm2022/ng-forge-dynamic-forms-ng-forge-dynamic-forms-WGww2nXx.mjs.map +1 -0
  6. package/fesm2022/{ng-forge-dynamic-forms-page-field.component-m35XgkkL.mjs → ng-forge-dynamic-forms-page-field.component-CrO9WTDw.mjs} +5 -5
  7. package/fesm2022/{ng-forge-dynamic-forms-page-field.component-m35XgkkL.mjs.map → ng-forge-dynamic-forms-page-field.component-CrO9WTDw.mjs.map} +1 -1
  8. package/fesm2022/ng-forge-dynamic-forms-schema.mjs +92 -0
  9. package/fesm2022/ng-forge-dynamic-forms-schema.mjs.map +1 -0
  10. package/fesm2022/{ng-forge-dynamic-forms-text-field.component-CfDZFTyf.mjs → ng-forge-dynamic-forms-text-field.component-BcFx_kOz.mjs} +5 -5
  11. package/fesm2022/{ng-forge-dynamic-forms-text-field.component-CfDZFTyf.mjs.map → ng-forge-dynamic-forms-text-field.component-BcFx_kOz.mjs.map} +1 -1
  12. package/fesm2022/ng-forge-dynamic-forms.mjs +1 -1
  13. package/package.json +13 -12
  14. package/types/ng-forge-dynamic-forms-integration.d.ts +61 -32
  15. package/types/ng-forge-dynamic-forms-schema.d.ts +178 -0
  16. package/types/ng-forge-dynamic-forms.d.ts +1173 -240
  17. package/fesm2022/ng-forge-dynamic-forms-ng-forge-dynamic-forms-D58rojQc.mjs.map +0 -1
  18. package/fesm2022/ng-forge-dynamic-forms-testing-test-button.harness-0iXHLraC.mjs +0 -31
  19. package/fesm2022/ng-forge-dynamic-forms-testing-test-button.harness-0iXHLraC.mjs.map +0 -1
  20. package/fesm2022/ng-forge-dynamic-forms-testing.mjs +0 -971
  21. package/fesm2022/ng-forge-dynamic-forms-testing.mjs.map +0 -1
  22. package/types/ng-forge-dynamic-forms-testing.d.ts +0 -597
@@ -0,0 +1,178 @@
1
+ import { SchemaPath, SchemaPathTree } from '@angular/forms/signals';
2
+ import { StandardSchemaV1 } from '@standard-schema/spec';
3
+
4
+ /**
5
+ * Internal marker symbol to identify StandardSchemaMarker instances.
6
+ * Uses ɵ prefix following Angular's convention for internal APIs.
7
+ */
8
+ declare const STANDARD_SCHEMA_KIND: "standardSchema";
9
+ /**
10
+ * Angular schema callback function type.
11
+ * This is the raw callback that Angular's schema() function accepts.
12
+ *
13
+ * Use this when you want to write Angular schema validation directly
14
+ * without any wrapper. This is ideal for Angular-only projects that
15
+ * want full access to Angular's form validation APIs.
16
+ *
17
+ * @typeParam T - The form value type
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { FormConfig } from '@ng-forge/dynamic-forms';
22
+ * import { validateTree } from '@angular/forms/signals';
23
+ *
24
+ * const config = {
25
+ * // Raw callback - no wrapper needed!
26
+ * schema: (path) => {
27
+ * validateTree(path, (ctx) => {
28
+ * const { password, confirmPassword } = ctx.value();
29
+ * if (password !== confirmPassword) {
30
+ * return [{ kind: 'passwordMismatch', fieldTree: ctx.fieldTreeOf(path).confirmPassword }];
31
+ * }
32
+ * return null;
33
+ * });
34
+ * },
35
+ * fields: [
36
+ * { key: 'password', type: 'input', label: 'Password', required: true },
37
+ * { key: 'confirmPassword', type: 'input', label: 'Confirm', required: true,
38
+ * validationMessages: { passwordMismatch: 'Passwords must match' } },
39
+ * ],
40
+ * } as const satisfies FormConfig;
41
+ * ```
42
+ */
43
+ type AngularSchemaCallback<T = unknown> = (path: SchemaPath<T> & SchemaPathTree<T>) => void;
44
+ /**
45
+ * Wrapper interface that marks a schema as implementing the Standard Schema spec.
46
+ * This allows the dynamic forms system to identify and use standard-compliant schemas
47
+ * for validation without coupling to any specific schema library.
48
+ *
49
+ * The `out` variance modifier makes this type covariant in T, meaning a
50
+ * StandardSchemaMarker<SpecificType> is assignable to StandardSchemaMarker<BroaderType>.
51
+ * This enables Zod/Valibot schemas to be used with FormConfig's inferred TValue.
52
+ *
53
+ * @typeParam T - The inferred type that the schema validates to (covariant)
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * import { z } from 'zod';
58
+ * import { standardSchema } from '@ng-forge/dynamic-forms/schema';
59
+ *
60
+ * const userSchema = z.object({
61
+ * name: z.string(),
62
+ * email: z.string().email(),
63
+ * });
64
+ *
65
+ * // Wrap the Zod schema with standardSchema marker
66
+ * const formSchema = standardSchema(userSchema);
67
+ * ```
68
+ */
69
+ interface StandardSchemaMarker<out T = unknown> {
70
+ /**
71
+ * Internal marker identifying this as a standard schema wrapper.
72
+ * @internal
73
+ */
74
+ readonly ɵkind: typeof STANDARD_SCHEMA_KIND;
75
+ /**
76
+ * The underlying schema that implements the Standard Schema spec.
77
+ */
78
+ readonly schema: StandardSchemaV1<T>;
79
+ }
80
+ /**
81
+ * Type alias for form schemas that can be used with dynamic forms.
82
+ * Supports both Standard Schema compliant schemas (Zod, Valibot, ArkType)
83
+ * and raw Angular schema callbacks.
84
+ *
85
+ * The covariance from StandardSchemaMarker flows through, allowing
86
+ * schemas with specific types to be assigned to broader form value types.
87
+ *
88
+ * @typeParam T - The inferred type that the schema validates to
89
+ *
90
+ * @example Standard Schema (Zod)
91
+ * ```typescript
92
+ * import { z } from 'zod';
93
+ * import { standardSchema } from '@ng-forge/dynamic-forms/schema';
94
+ *
95
+ * const config = {
96
+ * schema: standardSchema(z.object({ ... })),
97
+ * fields: [...],
98
+ * };
99
+ * ```
100
+ *
101
+ * @example Angular Schema Callback
102
+ * ```typescript
103
+ * import { validateTree } from '@angular/forms/signals';
104
+ *
105
+ * const config = {
106
+ * schema: (path) => {
107
+ * validateTree(path, (ctx) => { ... });
108
+ * },
109
+ * fields: [...],
110
+ * };
111
+ * ```
112
+ */
113
+ type FormSchema<T = unknown> = StandardSchemaMarker<T> | AngularSchemaCallback<T>;
114
+ /**
115
+ * Wraps a Standard Schema compliant schema for use with dynamic forms.
116
+ *
117
+ * This function creates a marker wrapper around schemas that implement the
118
+ * Standard Schema spec (Zod, Valibot, ArkType, etc.), allowing the dynamic
119
+ * forms system to identify and use them for validation.
120
+ *
121
+ * @typeParam T - The inferred type that the schema validates to
122
+ * @param schema - A schema implementing the Standard Schema V1 spec
123
+ * @returns A wrapped schema marker that can be passed to dynamic form configuration
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * import { z } from 'zod';
128
+ * import { standardSchema } from '@ng-forge/dynamic-forms/schema';
129
+ *
130
+ * const loginSchema = z.object({
131
+ * email: z.string().email('Invalid email format'),
132
+ * password: z.string().min(8, 'Password must be at least 8 characters'),
133
+ * });
134
+ *
135
+ * // Wrap for use with dynamic forms
136
+ * const formSchema = standardSchema(loginSchema);
137
+ *
138
+ * // Use in form configuration
139
+ * const formConfig = {
140
+ * schema: formSchema,
141
+ * fields: [
142
+ * input({ key: 'email', label: 'Email' }),
143
+ * input({ key: 'password', label: 'Password', props: { type: 'password' } }),
144
+ * ],
145
+ * };
146
+ * ```
147
+ */
148
+ declare function standardSchema<T>(schema: StandardSchemaV1<T>): StandardSchemaMarker<T>;
149
+ /**
150
+ * Type guard to check if a value is a StandardSchemaMarker.
151
+ *
152
+ * This is useful when processing form configuration to determine if a schema
153
+ * has been provided and should be used for validation.
154
+ *
155
+ * @param value - The value to check
156
+ * @returns True if the value is a StandardSchemaMarker, false otherwise
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * import { isStandardSchemaMarker } from '@ng-forge/dynamic-forms/schema';
161
+ *
162
+ * function processFormConfig(config: FormConfig) {
163
+ * if (config.schema && isStandardSchemaMarker(config.schema)) {
164
+ * // Use the schema for validation
165
+ * const result = config.schema.schema['~standard'].validate(formValue);
166
+ * }
167
+ * }
168
+ * ```
169
+ */
170
+ declare function isStandardSchemaMarker(value: unknown): value is StandardSchemaMarker;
171
+ /**
172
+ * Extracts the output type from a Standard Schema.
173
+ * Works with Zod, Valibot, ArkType, and other Standard Schema compliant libraries.
174
+ */
175
+ type InferSchemaOutput<T> = T extends StandardSchemaV1<infer Output> ? Output : never;
176
+
177
+ export { isStandardSchemaMarker, standardSchema };
178
+ export type { AngularSchemaCallback, FormSchema, InferSchemaOutput, StandardSchemaMarker };