@form-instant/react-resolver-zod 1.18.12 → 2.0.0-rc.1

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 (34) hide show
  1. package/dist/components/FormInstantProvider.d.ts +10 -0
  2. package/dist/components/SchemaMapper.d.ts +24 -0
  3. package/dist/examples/completeExample.d.ts +6 -0
  4. package/dist/examples/fieldConfigExample.d.ts +158 -0
  5. package/dist/examples/formInstantExample.d.ts +6 -0
  6. package/dist/examples/legacyCompatibility.d.ts +30 -0
  7. package/dist/hooks/useSchemaMapping.d.ts +22 -0
  8. package/dist/hooks/useSchemaMetadata.d.ts +26 -0
  9. package/dist/hooks/useSchemaNavigation.d.ts +18 -0
  10. package/dist/index.d.ts +5 -6
  11. package/dist/index.js +2 -7
  12. package/dist/index.js.map +13 -0
  13. package/dist/types.d.ts +48 -0
  14. package/dist/utils/pathResolver.d.ts +26 -0
  15. package/dist/utils/schemaParser.d.ts +19 -0
  16. package/dist/utils/zodExtensions.d.ts +974 -0
  17. package/package.json +57 -58
  18. package/dist/context.d.ts +0 -2
  19. package/dist/funcs/default-values.d.ts +0 -4
  20. package/dist/funcs/field-config.d.ts +0 -11
  21. package/dist/funcs/field-type-inference.d.ts +0 -3
  22. package/dist/funcs/index.d.ts +0 -5
  23. package/dist/funcs/schema-parser.d.ts +0 -2
  24. package/dist/funcs/types.d.ts +0 -11
  25. package/dist/provider.d.ts +0 -6
  26. package/dist/react-resolver-zod.cjs.development.js +0 -416
  27. package/dist/react-resolver-zod.cjs.development.js.map +0 -1
  28. package/dist/react-resolver-zod.cjs.production.min.js +0 -2
  29. package/dist/react-resolver-zod.cjs.production.min.js.map +0 -1
  30. package/dist/react-resolver-zod.esm.js +0 -401
  31. package/dist/react-resolver-zod.esm.js.map +0 -1
  32. package/dist/type.d.ts +0 -2
  33. package/dist/useSchema.d.ts +0 -14
  34. /package/dist/{element.d.ts → components/FormInstantElement.d.ts} +0 -0
package/package.json CHANGED
@@ -1,83 +1,82 @@
1
1
  {
2
2
  "name": "@form-instant/react-resolver-zod",
3
- "version": "1.18.12",
4
- "license": "MIT",
3
+ "version": "2.0.0-rc.1",
5
4
  "author": {
6
5
  "name": "leomerida15",
7
6
  "email": "dimasmerida15@gmail.com",
8
7
  "url": "https://github.com/leomerida15"
9
8
  },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/leomerida15/form-instant-react-resolver-zod.git"
12
+ },
10
13
  "main": "dist/index.js",
11
- "module": "dist/react-input-mapping.esm.js",
12
- "typings": "dist/index.d.ts",
13
- "files": [
14
- "dist"
15
- ],
14
+ "module": "dist/index.js",
15
+ "types": "dist/index.d.ts",
16
16
  "scripts": {
17
17
  "analyze": "size-limit --why",
18
- "build": "dts build",
19
- "lint": "dts lint",
20
- "prepare": "dts build",
18
+ "build": "bun run build.ts",
19
+ "build:watch": "bun build ./src/index.ts --outdir ./dist --watch",
20
+ "build:types": "tsc --declaration --emitDeclarationOnly --outDir ./dist",
21
+ "dev": "bun --watch ./src/index.ts",
22
+ "lint": "eslint src --ext .ts,.tsx",
23
+ "lint:fix": "eslint src --ext .ts,.tsx --fix",
21
24
  "size": "size-limit",
22
- "start": "dts watch",
23
- "test": "dts test --passWithNoTests",
24
- "Up": "npm publish --access public"
25
- },
26
- "husky": {
27
- "hooks": {
28
- "pre-commit": "dts lint"
29
- }
30
- },
31
- "jest": {
32
- "testEnvironment": "jsdom"
33
- },
34
- "peerDependencies": {
35
- "@form-instant/react-input-mapping": "^1.5.0",
36
- "react": "^18.3.1"
37
- },
38
- "engines": {
39
- "node": ">=12"
40
- },
41
- "size-limit": [
42
- {
43
- "path": "dist/react-input-mapping.cjs.production.min.js",
44
- "limit": "10 KB"
45
- },
46
- {
47
- "path": "dist/react-input-mapping.esm.js",
48
- "limit": "10 KB"
49
- }
50
- ],
51
- "dependencies": {
52
- "use-context-selector": "^2.0.0"
25
+ "test": "bun test",
26
+ "test:coverage": "bun test --coverage",
27
+ "test:watch": "bun test --watch",
28
+ "type-check": "tsc --noEmit",
29
+ "up": "npm publish --access public",
30
+ "up:rc": "npm publish --access public --tag rc"
53
31
  },
54
32
  "devDependencies": {
55
- "@size-limit/preset-small-lib": "^11.1.6",
56
- "@tsconfig/recommended": "^1.0.8",
33
+ "@size-limit/preset-small-lib": "^11.2.0",
34
+ "@tsconfig/recommended": "^1.0.10",
57
35
  "@tsconfig/vite-react": "^3.4.0",
58
- "@types/bun": "^1.1.14",
59
- "@types/react": "^18.3.16",
60
- "@typescript-eslint/eslint-plugin": "^8.18.0",
61
- "@typescript-eslint/parser": "^8.18.0",
62
- "dts-cli": "^2.0.5",
63
- "eslint": "^9.17.0",
64
- "eslint-plugin-prettier": "^5.2.1",
36
+ "@types/bun": "^1.2.20",
37
+ "@types/react": "^19.1.9",
38
+ "@typescript-eslint/eslint-plugin": "^8.39.0",
39
+ "@typescript-eslint/parser": "^8.39.0",
40
+ "eslint": "^9.33.0",
41
+ "eslint-plugin-prettier": "^5.5.4",
65
42
  "husky": "^9.1.7",
66
- "nodemon": "^3.1.9",
67
- "prettier": "^3.4.2",
68
- "size-limit": "^11.1.6",
43
+ "minimatch": "^10.0.3",
44
+ "nodemon": "^3.1.10",
45
+ "prettier": "^3.6.2",
46
+ "size-limit": "^11.2.0",
69
47
  "tslib": "^2.8.1",
70
48
  "typescript": "~5.0.4",
71
- "zod": "^3.24.1"
49
+ "zod": "^4.0.17"
50
+ },
51
+ "peerDependencies": {
52
+ "@form-instant/react-input-mapping": "^1.8.0",
53
+ "react": "^19.1.1",
54
+ "react-dom": "^19.1.1"
55
+ },
56
+ "engines": {
57
+ "node": ">=18",
58
+ "bun": ">=1.0.0"
72
59
  },
60
+ "files": [
61
+ "dist"
62
+ ],
73
63
  "homepage": "https://leomerida15.github.io/form-instant-react-mapping",
74
- "repository": {
75
- "type": "git",
76
- "url": "git+https://github.com/leomerida15/form-instant-react-resolver-zod.git"
64
+ "husky": {
65
+ "hooks": {
66
+ "pre-commit": "bun run lint"
67
+ }
77
68
  },
78
69
  "keywords": [
79
70
  "@form-instant",
80
71
  "react",
81
- "mapping"
72
+ "mapping",
73
+ "zod"
74
+ ],
75
+ "license": "MIT",
76
+ "size-limit": [
77
+ {
78
+ "path": "dist/index.js",
79
+ "limit": "5 KB"
80
+ }
82
81
  ]
83
82
  }
package/dist/context.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { zodResolverProps } from './type';
2
- export declare const ZodResolverContext: import("use-context-selector").Context<zodResolverProps>;
@@ -1,4 +0,0 @@
1
- import { z } from 'zod';
2
- import { ZodObjectOrWrapped } from './types';
3
- export declare function getDefaultValueInZodStack(schema: z.ZodTypeAny): any;
4
- export declare function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any>;
@@ -1,11 +0,0 @@
1
- import { z } from 'zod';
2
- import { FieldConfig, SuperRefineFunction } from './types';
3
- export declare const FIELD_CONFIG_SYMBOL: unique symbol;
4
- declare module 'zod' {
5
- interface ZodType {
6
- fieldConfig<AdditionalRenderable = null, FieldTypes = string>(config: FieldConfig<AdditionalRenderable, FieldTypes>): this;
7
- }
8
- }
9
- export declare const extendZodWithFieldConfig: <AdditionalRenderable = null, FieldTypes = string>(zod: typeof z) => void;
10
- export declare const createZodSchemaFieldConfig: <AdditionalRenderable = null, FieldTypes = string>() => (config: FieldConfig<AdditionalRenderable, FieldTypes>) => SuperRefineFunction;
11
- export declare function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig;
@@ -1,3 +0,0 @@
1
- import { z } from 'zod';
2
- import { FieldConfig } from './types';
3
- export declare function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig['fieldType']): string;
@@ -1,5 +0,0 @@
1
- export * from './default-values';
2
- export * from './field-config';
3
- export * from './field-type-inference';
4
- export * from './schema-parser';
5
- export * from './types';
@@ -1,2 +0,0 @@
1
- import { ParsedSchema, ZodObjectOrWrapped } from './types';
2
- export declare const parseSchema: (S: ZodObjectOrWrapped) => ParsedSchema;
@@ -1,11 +0,0 @@
1
- import { ParsedField } from '@form-instant/react-input-mapping';
2
- import { ZodEffects, ZodObject } from 'zod';
3
- export type ZodObjectOrWrapped = ZodObject<any, any> | ZodEffects<ZodObject<any, any>>;
4
- export interface ParsedSchema<AdditionalRenderable = null, FieldTypes = string> {
5
- fields: Record<string, ParsedField<AdditionalRenderable, FieldTypes>>;
6
- }
7
- export type SuperRefineFunction = () => unknown;
8
- export type Renderable<AdditionalRenderable = null> = string | number | boolean | null | undefined | AdditionalRenderable;
9
- export type FieldConfig<AdditionalRenderable = object, FieldTypes = string> = {
10
- fieldType?: FieldTypes;
11
- } & AdditionalRenderable;
@@ -1,6 +0,0 @@
1
- import { FC, ReactNode } from 'react';
2
- import { zodResolverProps } from './type';
3
- export declare const FormInstantProvider: FC<{
4
- schema: zodResolverProps;
5
- children: ReactNode;
6
- }>;
@@ -1,416 +0,0 @@
1
- 'use strict';
2
-
3
- var useContextSelector = require('use-context-selector');
4
- var jsxRuntime = require('react/jsx-runtime');
5
- var reactInputMapping = require('@form-instant/react-input-mapping');
6
- var react = require('react');
7
- var zod = require('zod');
8
-
9
- var ZodResolverContext = /*#__PURE__*/useContextSelector.createContext({});
10
-
11
- function _extends() {
12
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
13
- for (var e = 1; e < arguments.length; e++) {
14
- var t = arguments[e];
15
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
16
- }
17
- return n;
18
- }, _extends.apply(null, arguments);
19
- }
20
- function _objectWithoutPropertiesLoose(r, e) {
21
- if (null == r) return {};
22
- var t = {};
23
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
24
- if (-1 !== e.indexOf(n)) continue;
25
- t[n] = r[n];
26
- }
27
- return t;
28
- }
29
-
30
- function getDefaultValueInZodStack(schema) {
31
- if (schema._def.typeName === 'ZodDefault') {
32
- return schema._def.defaultValue();
33
- }
34
- if (schema._def.typeName === 'ZodEffects') {
35
- return getDefaultValueInZodStack(schema.innerType());
36
- }
37
- return undefined;
38
- }
39
- function getDefaultValues(schema) {
40
- var objectSchema = schema instanceof zod.z.ZodEffects ? schema.innerType() : schema;
41
- var shape = objectSchema.shape;
42
- var defaultValues = {};
43
- for (var _i = 0, _Object$entries = Object.entries(shape); _i < _Object$entries.length; _i++) {
44
- var _Object$entries$_i = _Object$entries[_i],
45
- key = _Object$entries$_i[0],
46
- field = _Object$entries$_i[1];
47
- var defaultValue = getDefaultValueInZodStack(field);
48
- if (defaultValue !== undefined) {
49
- defaultValues[key] = defaultValue;
50
- }
51
- }
52
- return defaultValues;
53
- }
54
-
55
- var FIELD_CONFIG_SYMBOL = /*#__PURE__*/Symbol('GetFieldConfig');
56
- var extendZodWithFieldConfig = function extendZodWithFieldConfig(zod) {
57
- zod.ZodType.prototype.fieldConfig = function (config) {
58
- this._def.fieldConfig = config;
59
- return this;
60
- };
61
- var originalObject = zod.object;
62
- zod.object = function () {
63
- var schema = originalObject.apply(void 0, arguments);
64
- schema._def["default"] = function () {
65
- return {};
66
- };
67
- return schema;
68
- };
69
- var originalArray = zod.array;
70
- zod.array = function () {
71
- var schema = originalArray.apply(void 0, arguments);
72
- schema._def["default"] = function () {
73
- return [];
74
- };
75
- return schema;
76
- };
77
- };
78
- var createZodSchemaFieldConfig = function createZodSchemaFieldConfig() {
79
- return function (config) {
80
- var refinementFunction = function refinementFunction() {
81
- // Do nothing.
82
- };
83
- // @ts-expect-error This is a symbol and not a real value.
84
- refinementFunction[FIELD_CONFIG_SYMBOL] = config;
85
- return refinementFunction;
86
- };
87
- };
88
- function getFieldConfigInZodStack(schema) {
89
- // Verifica si el esquema tiene fieldConfig directamente
90
- if (schema._def.fieldConfig) {
91
- return schema._def.fieldConfig;
92
- }
93
- // Si el esquema es un ZodEffects, busca en el innerType
94
- if ('innerType' in schema._def) {
95
- return getFieldConfigInZodStack(schema._def.innerType);
96
- }
97
- // Si el esquema es un ZodEffects con un schema interno, busca en el schema
98
- if ('schema' in schema._def) {
99
- return getFieldConfigInZodStack(schema._def.schema);
100
- }
101
- // Si no se encuentra fieldConfig, retorna un objeto vacío
102
- return {};
103
- }
104
-
105
- function inferFieldType(schema, fieldType) {
106
- if (fieldType) {
107
- return fieldType;
108
- }
109
- var type = schema._def.typeName;
110
- var zodToInputType = new Map([['ZodObject', 'object'], ['ZodString', 'string'], ['ZodNumber', 'number'], ['ZodBoolean', 'boolean'], ['ZodDate', 'date'], ['ZodEnum', 'select'], ['ZodNativeEnum', 'select'], ['ZodArray', 'array']]);
111
- var match = zodToInputType.get(type);
112
- return match || 'string'; // Default to string for unknown types
113
- }
114
-
115
- var _excluded = ["fieldType"];
116
- var typeMapping = {
117
- ZodDiscriminatedUnion: function ZodDiscriminatedUnion(_ref) {
118
- var schema = _ref.schema,
119
- name = _ref.name,
120
- history = _ref.history,
121
- dependecys = _ref.dependecys;
122
- var _schema$_def = schema._def,
123
- optionsMap = _schema$_def.optionsMap,
124
- discriminator = _schema$_def.discriminator,
125
- fieldConfig = _schema$_def.fieldConfig;
126
- if (!Object.keys(dependecys).length) return [{}];
127
- var optionKey = dependecys[discriminator];
128
- var option = optionsMap.get(optionKey);
129
- if (!option) return [{}];
130
- var entries = Object.entries(option.shape);
131
- var fields = entries.filter(function (_ref2) {
132
- var key = _ref2[0];
133
- return key !== discriminator;
134
- }).map(function (_ref3) {
135
- var key = _ref3[0],
136
- field = _ref3[1];
137
- var historyFormat = (history ? [history, name] : [name]).join('.');
138
- if (historyFormat.charAt(0) === '.') historyFormat = historyFormat.substring(1);
139
- return parseField({
140
- name: key,
141
- schema: field,
142
- history: historyFormat,
143
- dependecys: dependecys
144
- });
145
- });
146
- var historyFormat = (history ? [history, name, discriminator] : [name, discriminator]).join('.');
147
- if (historyFormat.charAt(0) === '.') historyFormat = historyFormat.substring(1);
148
- fields.unshift({
149
- name: {
150
- current: discriminator,
151
- history: historyFormat
152
- },
153
- type: 'discriminator',
154
- required: true,
155
- "default": optionKey,
156
- fieldConfig: fieldConfig,
157
- options: Array.from(optionsMap.keys()).map(function (key) {
158
- return [String(key), String(key)];
159
- })
160
- });
161
- return fields;
162
- },
163
- ZodObject: function ZodObject(_ref4) {
164
- var schema = _ref4.schema,
165
- name = _ref4.name,
166
- history = _ref4.history,
167
- dependecys = _ref4.dependecys;
168
- var historyFormat = (history ? [history, name] : [name]).join('.');
169
- if (historyFormat.charAt(0) === '.') historyFormat = historyFormat.substring(1);
170
- return Object.entries(schema.shape).map(function (_ref5) {
171
- var key = _ref5[0],
172
- field = _ref5[1];
173
- return parseField({
174
- name: key,
175
- schema: field,
176
- history: historyFormat,
177
- dependecys: dependecys
178
- });
179
- });
180
- },
181
- ZodArray: function ZodArray(_ref6) {
182
- var schema = _ref6.schema,
183
- name = _ref6.name,
184
- history = _ref6.history,
185
- dependecys = _ref6.dependecys;
186
- var historyFormat = (history ? [history, name] : [name]).join('.');
187
- if (historyFormat.charAt(0) === '.') historyFormat = historyFormat.substring(1);
188
- return [parseField({
189
- name: '0',
190
- schema: schema._def.type,
191
- history: historyFormat,
192
- dependecys: dependecys
193
- })];
194
- }
195
- };
196
- function parseField(_ref7) {
197
- var _baseSchema$_def$minL, _baseSchema$_def$maxL;
198
- var name = _ref7.name,
199
- schema = _ref7.schema,
200
- history = _ref7.history,
201
- _ref7$dependecys = _ref7.dependecys,
202
- dependecys = _ref7$dependecys === void 0 ? {} : _ref7$dependecys;
203
- var baseSchema = getBaseSchema(schema);
204
- var _getFieldConfigInZodS = getFieldConfigInZodStack(schema),
205
- fieldType = _getFieldConfigInZodS.fieldType,
206
- fieldConfigBase = _objectWithoutPropertiesLoose(_getFieldConfigInZodS, _excluded);
207
- var type = inferFieldType(baseSchema, fieldType);
208
- var defaultValue = getDefaultValueInZodStack(schema);
209
- var fieldConfig = fieldConfigBase;
210
- // Enums
211
- var options = baseSchema._def.values;
212
- var optionValues = [];
213
- if (options) {
214
- if (!Array.isArray(options)) {
215
- optionValues = Object.entries(options);
216
- } else {
217
- optionValues = options.map(function (value) {
218
- return [value, value];
219
- });
220
- }
221
- }
222
- var typeName = baseSchema._def.typeName;
223
- // Arrays and objects
224
- var getSubSchema = typeMapping[typeName];
225
- var subSchema = getSubSchema == null ? void 0 : getSubSchema({
226
- name: name,
227
- schema: baseSchema,
228
- history: history,
229
- dependecys: dependecys
230
- });
231
- if (typeName === 'ZodDiscriminatedUnion') {
232
- var _baseSchema$_def = baseSchema._def,
233
- optionsMap = _baseSchema$_def.optionsMap,
234
- discriminator = _baseSchema$_def.discriminator;
235
- var optionKey = dependecys[discriminator];
236
- if (optionKey) {
237
- var option = optionsMap.get(optionKey);
238
- if (option._def.fieldConfig) {
239
- fieldConfig = _extends({}, fieldConfigBase, option._def.fieldConfig);
240
- }
241
- }
242
- }
243
- if (type === 'array') fieldConfig = _extends({
244
- min: ((_baseSchema$_def$minL = baseSchema._def.minLength) == null ? void 0 : _baseSchema$_def$minL.value) || 1,
245
- max: (_baseSchema$_def$maxL = baseSchema._def.maxLength) == null ? void 0 : _baseSchema$_def$maxL.value
246
- }, fieldConfig);
247
- var historyFormat = (history ? [history, name] : [name]).join('.');
248
- if (historyFormat.charAt(0) === '.') historyFormat = historyFormat.substring(1);
249
- var resp = {
250
- name: {
251
- current: name,
252
- history: historyFormat
253
- },
254
- type: type,
255
- required: !schema.isOptional(),
256
- "default": defaultValue,
257
- fieldConfig: fieldConfig,
258
- options: optionValues,
259
- schema: subSchema,
260
- description: baseSchema.description
261
- };
262
- return resp;
263
- }
264
- function getBaseSchema(schema) {
265
- if ('innerType' in schema._def) {
266
- return getBaseSchema(schema._def.innerType);
267
- }
268
- if ('schema' in schema._def) {
269
- return getBaseSchema(schema._def.schema);
270
- }
271
- return schema;
272
- }
273
- var parseSchema = function parseSchema(S) {
274
- var _objectSchema$_def$fi;
275
- var objectSchema = S instanceof zod.z.ZodEffects ? S.innerType() : S;
276
- var shape = objectSchema.shape;
277
- var dependecys = ((_objectSchema$_def$fi = objectSchema._def.fieldConfig) == null ? void 0 : _objectSchema$_def$fi.dp) || {};
278
- var fields = Object.fromEntries(Object.entries(shape).map(function (_ref8) {
279
- var key = _ref8[0],
280
- field = _ref8[1];
281
- return [key, parseField({
282
- name: key,
283
- schema: field,
284
- dependecys: dependecys
285
- })];
286
- }));
287
- return {
288
- fields: fields
289
- };
290
- };
291
-
292
- var useSchemaBase = function useSchemaBase() {
293
- return useContextSelector.useContext(ZodResolverContext);
294
- };
295
- var useFields = function useFields(key) {
296
- var S = useSchemaBase();
297
- var _parseSchema = parseSchema(S),
298
- fields = _parseSchema.fields;
299
- return fields[key];
300
- };
301
- var _generateInitialValues = function generateInitialValues(schema, dp) {
302
- try {
303
- var shape = function () {
304
- if (schema._def.typeName === 'ZodEffects') return schema.innerType().shape;
305
- if (schema._def.typeName === 'ZodObject') return schema.shape;
306
- var option = schema._def.optionsMap.get(dp[schema._def.discriminator]);
307
- console.log('option', option);
308
- if (!option) throw new Error('No option found');
309
- return option.shape;
310
- }();
311
- console.log('shape', shape);
312
- var initialValues = {};
313
- for (var _i = 0, _Object$keys = Object.keys(shape); _i < _Object$keys.length; _i++) {
314
- var key = _Object$keys[_i];
315
- var fieldSchema = shape[key];
316
- var result = fieldSchema.safeParse(undefined);
317
- // Si tiene valor por defecto
318
- if (result.success) {
319
- initialValues[key] = result.data;
320
- continue;
321
- }
322
- // Inferir tipo para campos requeridos sin default
323
- if (fieldSchema._def.typeName === 'ZodString') {
324
- initialValues[key] = '';
325
- } else if (fieldSchema._def.typeName === 'ZodNumber') {
326
- initialValues[key] = 0;
327
- } else if (fieldSchema._def.typeName === 'ZodBoolean') {
328
- initialValues[key] = false;
329
- } else if (fieldSchema._def.typeName === 'ZodDate') {
330
- initialValues[key] = null;
331
- } else if (fieldSchema._def.typeName === 'ZodArray') {
332
- initialValues[key] = [];
333
- } else if (fieldSchema._def.typeName === 'ZodObject') {
334
- initialValues[key] = _generateInitialValues(fieldSchema, dp);
335
- } else if (fieldSchema._def.typeName === 'ZodDiscriminatedUnion') {
336
- var option = fieldSchema._def.optionsMap.get(dp[fieldSchema._def.discriminator]);
337
- if (option) {
338
- initialValues[key] = _generateInitialValues(option, dp);
339
- } else {
340
- initialValues[key] = null;
341
- }
342
- } else {
343
- initialValues[key] = null;
344
- }
345
- }
346
- console.log('initialValues build', initialValues);
347
- return initialValues;
348
- } catch (error) {
349
- console.log('🔴 initialValues error', error);
350
- if (error instanceof Error) {
351
- console.log(error.cause);
352
- console.log(error.message);
353
- }
354
- return {};
355
- }
356
- };
357
- var useSchema = function useSchema(cbP, dp) {
358
- var schema = react.useMemo(function () {
359
- return cbP(dp).fieldConfig(_extends({
360
- dp: dp
361
- }, cbP(dp).fieldConfig));
362
- }, [cbP, dp]);
363
- var initialValues = react.useMemo(function () {
364
- return _generateInitialValues(schema, dp);
365
- }, [schema, dp]);
366
- console.log('initialValues', initialValues);
367
- return {
368
- schema: schema,
369
- initialValues: initialValues
370
- };
371
- };
372
-
373
- var FormInstantElement = function FormInstantElement(_ref) {
374
- var _field$fieldConfig;
375
- var name = _ref.name;
376
- var field = useFields(name);
377
- var id = react.useId();
378
- if ((_field$fieldConfig = field.fieldConfig) != null && _field$fieldConfig.type) return jsxRuntime.jsx(reactInputMapping.ElementMapping, {
379
- formProps: field
380
- });
381
- return jsxRuntime.jsx(jsxRuntime.Fragment, {
382
- children: Object.values(field.schema || {}).map(function (props) {
383
- var _props$name;
384
- return jsxRuntime.jsx(react.Fragment, {
385
- children: jsxRuntime.jsx(reactInputMapping.ElementMapping, {
386
- formProps: props
387
- })
388
- }, id + "-" + (((_props$name = props.name) == null ? void 0 : _props$name.history) || ''));
389
- })
390
- });
391
- };
392
-
393
- var FormInstantProvider = function FormInstantProvider(_ref) {
394
- var children = _ref.children,
395
- schema = _ref.schema;
396
- return jsxRuntime.jsx(ZodResolverContext.Provider, {
397
- value: schema,
398
- children: children
399
- });
400
- };
401
-
402
- exports.FIELD_CONFIG_SYMBOL = FIELD_CONFIG_SYMBOL;
403
- exports.FormInstantElement = FormInstantElement;
404
- exports.FormInstantProvider = FormInstantProvider;
405
- exports.ZodResolverContext = ZodResolverContext;
406
- exports.createZodSchemaFieldConfig = createZodSchemaFieldConfig;
407
- exports.extendZodWithFieldConfig = extendZodWithFieldConfig;
408
- exports.generateInitialValues = _generateInitialValues;
409
- exports.getDefaultValueInZodStack = getDefaultValueInZodStack;
410
- exports.getDefaultValues = getDefaultValues;
411
- exports.getFieldConfigInZodStack = getFieldConfigInZodStack;
412
- exports.inferFieldType = inferFieldType;
413
- exports.parseSchema = parseSchema;
414
- exports.useFields = useFields;
415
- exports.useSchema = useSchema;
416
- //# sourceMappingURL=react-resolver-zod.cjs.development.js.map