@saas-ui/forms 2.0.0-rc.26 → 2.0.0-rc.27
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +8 -0
- package/dist/index.d.ts +109 -100
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.ts +96 -69
- package/dist/yup/index.js +242 -3
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.mjs +220 -4
- package/dist/yup/index.mjs.map +1 -1
- package/dist/zod/index.d.ts +92 -63
- package/dist/zod/index.js +242 -5
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs +220 -5
- package/dist/zod/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/default-fields.tsx +2 -0
- package/src/types.ts +30 -9
package/dist/zod/index.js
CHANGED
@@ -1,10 +1,50 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
var zod = require('@hookform/resolvers/zod');
|
4
|
-
var
|
4
|
+
var utils_star = require('@chakra-ui/utils');
|
5
5
|
var forms = require('@saas-ui/forms');
|
6
|
+
var React = require('react');
|
7
|
+
var react = require('@chakra-ui/react');
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
6
9
|
|
7
|
-
|
10
|
+
function _interopNamespace(e) {
|
11
|
+
if (e && e.__esModule) return e;
|
12
|
+
var n = Object.create(null);
|
13
|
+
if (e) {
|
14
|
+
Object.keys(e).forEach(function (k) {
|
15
|
+
if (k !== 'default') {
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
18
|
+
enumerable: true,
|
19
|
+
get: function () { return e[k]; }
|
20
|
+
});
|
21
|
+
}
|
22
|
+
});
|
23
|
+
}
|
24
|
+
n.default = e;
|
25
|
+
return Object.freeze(n);
|
26
|
+
}
|
27
|
+
|
28
|
+
var utils_star__namespace = /*#__PURE__*/_interopNamespace(utils_star);
|
29
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
30
|
+
|
31
|
+
var __defProp = Object.defineProperty;
|
32
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
33
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
34
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
35
|
+
var __export = (target, all) => {
|
36
|
+
for (var name in all)
|
37
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
38
|
+
};
|
39
|
+
var __copyProps = (to, from, except, desc) => {
|
40
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
41
|
+
for (let key of __getOwnPropNames(from))
|
42
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
43
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
44
|
+
}
|
45
|
+
return to;
|
46
|
+
};
|
47
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
8
48
|
var getType = (field) => {
|
9
49
|
switch (field._def.typeName) {
|
10
50
|
case "ZodArray":
|
@@ -52,7 +92,7 @@ var getFieldsFromSchema = (schema) => {
|
|
52
92
|
return fields;
|
53
93
|
};
|
54
94
|
var getNestedSchema = (schema, path) => {
|
55
|
-
return
|
95
|
+
return utils_star.get(schema._def.shape(), path);
|
56
96
|
};
|
57
97
|
var zodFieldResolver = (schema) => {
|
58
98
|
return {
|
@@ -84,6 +124,200 @@ var createZodForm = (options) => {
|
|
84
124
|
ZodForm.id = "ZodForm";
|
85
125
|
return ZodForm;
|
86
126
|
};
|
127
|
+
|
128
|
+
// ../saas-ui-react-utils/dist/index.mjs
|
129
|
+
var dist_exports = {};
|
130
|
+
__export(dist_exports, {
|
131
|
+
getChildOfType: () => getChildOfType,
|
132
|
+
getChildrenOfType: () => getChildrenOfType,
|
133
|
+
useResponsiveValue: () => useResponsiveValue
|
134
|
+
});
|
135
|
+
__reExport(dist_exports, utils_star__namespace);
|
136
|
+
function getChildOfType(children, type) {
|
137
|
+
return React__namespace.Children.toArray(children).find(
|
138
|
+
(item) => item.type === type
|
139
|
+
);
|
140
|
+
}
|
141
|
+
function getChildrenOfType(children, type) {
|
142
|
+
return React__namespace.Children.toArray(children).filter(
|
143
|
+
(item) => Array.isArray(type) ? type.some((component) => component === item.type) : item.type === type
|
144
|
+
);
|
145
|
+
}
|
146
|
+
var normalize = (variant, toArray) => {
|
147
|
+
if (Array.isArray(variant))
|
148
|
+
return variant;
|
149
|
+
else if (typeof variant === "object")
|
150
|
+
return toArray == null ? void 0 : toArray(variant);
|
151
|
+
if (variant != null)
|
152
|
+
return [variant];
|
153
|
+
return [];
|
154
|
+
};
|
155
|
+
var useResponsiveValue = (value, options) => {
|
156
|
+
var _a;
|
157
|
+
const theme = react.useTheme();
|
158
|
+
const normalized = normalize(value, (_a = theme.__breakpoints) == null ? void 0 : _a.toArrayValue);
|
159
|
+
return react.useBreakpointValue(normalized, options);
|
160
|
+
};
|
161
|
+
var BaseModal = (props) => {
|
162
|
+
const {
|
163
|
+
title,
|
164
|
+
footer,
|
165
|
+
children,
|
166
|
+
isOpen,
|
167
|
+
onClose,
|
168
|
+
hideCloseButton,
|
169
|
+
hideOverlay,
|
170
|
+
headerProps,
|
171
|
+
contentProps,
|
172
|
+
footerProps,
|
173
|
+
...rest
|
174
|
+
} = props;
|
175
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.Modal, { isOpen, onClose, ...rest, children: [
|
176
|
+
!hideOverlay && /* @__PURE__ */ jsxRuntime.jsx(react.ModalOverlay, {}),
|
177
|
+
/* @__PURE__ */ jsxRuntime.jsxs(react.ModalContent, { ...contentProps, children: [
|
178
|
+
title && /* @__PURE__ */ jsxRuntime.jsx(react.ModalHeader, { ...headerProps, children: title }),
|
179
|
+
!hideCloseButton && /* @__PURE__ */ jsxRuntime.jsx(react.ModalCloseButton, {}),
|
180
|
+
utils_star.runIfFn(children, {
|
181
|
+
isOpen,
|
182
|
+
onClose
|
183
|
+
}),
|
184
|
+
footer && /* @__PURE__ */ jsxRuntime.jsx(react.ModalFooter, { ...footerProps, children: footer })
|
185
|
+
] })
|
186
|
+
] });
|
187
|
+
};
|
188
|
+
var [StylesProvider] = react.createStylesContext("SuiMenuDialog");
|
189
|
+
react.forwardRef(
|
190
|
+
(props, forwardedRef) => {
|
191
|
+
const {
|
192
|
+
rootProps,
|
193
|
+
title,
|
194
|
+
footer,
|
195
|
+
initialFocusRef,
|
196
|
+
hideCloseButton,
|
197
|
+
motionPreset = "slideInBottom",
|
198
|
+
isCentered: isCenteredProp,
|
199
|
+
...rest
|
200
|
+
} = props;
|
201
|
+
const { isOpen, onClose, menuRef } = react.useMenuContext();
|
202
|
+
const { ref, ...ownProps } = react.useMenuList(rest, forwardedRef);
|
203
|
+
const styles = react.useMultiStyleConfig("Menu", props);
|
204
|
+
const isCentered = react.useBreakpointValue({ base: true, md: false });
|
205
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
206
|
+
BaseModal,
|
207
|
+
{
|
208
|
+
isOpen,
|
209
|
+
onClose,
|
210
|
+
initialFocusRef: initialFocusRef || menuRef,
|
211
|
+
title,
|
212
|
+
hideCloseButton,
|
213
|
+
motionPreset,
|
214
|
+
isCentered: isCenteredProp != null ? isCenteredProp : isCentered,
|
215
|
+
contentProps: { mx: 4 },
|
216
|
+
children: [
|
217
|
+
/* @__PURE__ */ jsxRuntime.jsx(StylesProvider, { value: styles, children: /* @__PURE__ */ jsxRuntime.jsx(
|
218
|
+
react.chakra.div,
|
219
|
+
{
|
220
|
+
...ownProps,
|
221
|
+
ref,
|
222
|
+
__css: {
|
223
|
+
outline: 0,
|
224
|
+
maxHeight: "80vh",
|
225
|
+
// can override this in theme
|
226
|
+
overflowY: "auto",
|
227
|
+
// can override this in theme
|
228
|
+
...styles.list,
|
229
|
+
boxShadow: "none",
|
230
|
+
border: 0,
|
231
|
+
_dark: {
|
232
|
+
/* @ts-expect-error */
|
233
|
+
...styles.list._dark || {},
|
234
|
+
boxShadow: "none"
|
235
|
+
}
|
236
|
+
}
|
237
|
+
}
|
238
|
+
) }),
|
239
|
+
footer && /* @__PURE__ */ jsxRuntime.jsx(react.ModalFooter, { children: footer })
|
240
|
+
]
|
241
|
+
}
|
242
|
+
);
|
243
|
+
}
|
244
|
+
);
|
245
|
+
var useFormProps = (props) => {
|
246
|
+
const {
|
247
|
+
schema,
|
248
|
+
resolver,
|
249
|
+
fieldResolver,
|
250
|
+
defaultValues,
|
251
|
+
values,
|
252
|
+
context,
|
253
|
+
onChange,
|
254
|
+
onSubmit,
|
255
|
+
onError,
|
256
|
+
mode,
|
257
|
+
reValidateMode,
|
258
|
+
shouldFocusError = true,
|
259
|
+
shouldUnregister,
|
260
|
+
shouldUseNativeValidation,
|
261
|
+
criteriaMode,
|
262
|
+
delayError = 100,
|
263
|
+
fields,
|
264
|
+
...modalProps
|
265
|
+
} = props;
|
266
|
+
const formProps = {
|
267
|
+
schema,
|
268
|
+
resolver,
|
269
|
+
defaultValues,
|
270
|
+
values,
|
271
|
+
context,
|
272
|
+
onChange,
|
273
|
+
onSubmit,
|
274
|
+
onError,
|
275
|
+
mode,
|
276
|
+
reValidateMode,
|
277
|
+
shouldFocusError,
|
278
|
+
shouldUnregister,
|
279
|
+
shouldUseNativeValidation,
|
280
|
+
criteriaMode,
|
281
|
+
delayError,
|
282
|
+
fields
|
283
|
+
};
|
284
|
+
return { modalProps, formProps, fields };
|
285
|
+
};
|
286
|
+
function createFormDialog(Form22) {
|
287
|
+
const Dialog = react.forwardRef((props, ref) => {
|
288
|
+
const { isOpen, onClose, footer, children, ...rest } = props;
|
289
|
+
const { modalProps, formProps, fields } = useFormProps(rest);
|
290
|
+
return /* @__PURE__ */ jsxRuntime.jsx(BaseModal, { ...modalProps, isOpen, onClose, children: /* @__PURE__ */ jsxRuntime.jsx(Form22, { ref, ...formProps, children: (form) => {
|
291
|
+
var _a, _b;
|
292
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
293
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.ModalBody, { children: (0, dist_exports.runIfFn)(children, form) || /* @__PURE__ */ jsxRuntime.jsx(forms.AutoFields, {}) }),
|
294
|
+
footer || /* @__PURE__ */ jsxRuntime.jsxs(react.ModalFooter, { children: [
|
295
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
296
|
+
react.Button,
|
297
|
+
{
|
298
|
+
variant: "ghost",
|
299
|
+
mr: 3,
|
300
|
+
onClick: onClose,
|
301
|
+
...fields == null ? void 0 : fields.cancel,
|
302
|
+
children: (_b = (_a = fields == null ? void 0 : fields.cancel) == null ? void 0 : _a.children) != null ? _b : "Cancel"
|
303
|
+
}
|
304
|
+
),
|
305
|
+
/* @__PURE__ */ jsxRuntime.jsx(forms.SubmitButton, { ...fields == null ? void 0 : fields.submit })
|
306
|
+
] })
|
307
|
+
] });
|
308
|
+
} }) });
|
309
|
+
});
|
310
|
+
Dialog.displayName = `${Form22.displayName || Form22.name}Dialog`;
|
311
|
+
Dialog.id = Form22.id;
|
312
|
+
return Dialog;
|
313
|
+
}
|
314
|
+
createFormDialog(forms.Form);
|
315
|
+
React__namespace.createContext(null);
|
316
|
+
|
317
|
+
// zod/src/create-zod-dialog.ts
|
318
|
+
function createZodFormDialog(Form3) {
|
319
|
+
return createFormDialog(Form3);
|
320
|
+
}
|
87
321
|
var createZodStepForm = (options) => {
|
88
322
|
const ZodStepForm = forms.createStepForm({
|
89
323
|
resolver: (schema) => zod.zodResolver(schema, options == null ? void 0 : options.schemaOptions, options == null ? void 0 : options.resolverOptions),
|
@@ -96,16 +330,19 @@ var createZodStepForm = (options) => {
|
|
96
330
|
};
|
97
331
|
|
98
332
|
// zod/src/index.ts
|
99
|
-
var
|
333
|
+
var Form2 = createZodForm();
|
100
334
|
var StepForm = createZodStepForm();
|
335
|
+
var FormDialog2 = createZodFormDialog(Form2);
|
101
336
|
|
102
337
|
Object.defineProperty(exports, 'zodResolver', {
|
103
338
|
enumerable: true,
|
104
339
|
get: function () { return zod.zodResolver; }
|
105
340
|
});
|
106
|
-
exports.Form =
|
341
|
+
exports.Form = Form2;
|
342
|
+
exports.FormDialog = FormDialog2;
|
107
343
|
exports.StepForm = StepForm;
|
108
344
|
exports.createZodForm = createZodForm;
|
345
|
+
exports.createZodFormDialog = createZodFormDialog;
|
109
346
|
exports.getFieldsFromSchema = getFieldsFromSchema;
|
110
347
|
exports.getNestedSchema = getNestedSchema;
|
111
348
|
exports.zodFieldResolver = zodFieldResolver;
|
package/dist/zod/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../zod/src/zod-resolver.ts","../../zod/src/create-zod-form.ts","../../zod/src/create-zod-step-form.ts","../../zod/src/index.ts"],"names":[],"mappings":";AACA,SAAS,mBAAmB;AAC5B,SAAS,WAAW;AAUpB,IAAM,UAAU,CAAC,UAAwB;AACvC,UAAQ,MAAM,KAAK,UAAU;AAAA,IAC3B,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL;AACE,aAAO;AAAA,EACX;AACF;AAEA,IAAM,iBAAiB,CAAC,OAAY,SAAiB;AA5BrD;AA6BE,UAAO,WAAM,KAAK,IAAI,MAAf,mBAAkB;AAC3B;AAQO,IAAM,sBAAsB,CAAC,WAAuC;AACzE,QAAM,SAAuB,CAAC;AAE9B,MAAI,eAAoC,CAAC;AACzC,MAAI,OAAO,KAAK,aAAa,YAAY;AACvC,mBAAe,OAAO,KAAK,KAAK;AAAA,EAClC,WAAW,OAAO,KAAK,aAAa,aAAa;AAC/C,mBAAe,OAAO,KAAK,MAAM;AAAA,EACnC,OAAO;AACL,WAAO;AAAA,EACT;AAEA,aAAW,QAAQ,cAAc;AAC/B,UAAM,QAAQ,aAAa,IAAI;AAE/B,UAAM,UAAmB,CAAC;AAC1B,QAAI,MAAM,KAAK,aAAa,YAAY;AACtC,cAAQ,MAAM,eAAe,OAA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AAG;AAAA,EACL,CAAC;AAED,cAAY,cAAc;AAC1B,cAAY,KAAK;AAEjB,SAAO;AACT;;;AClDO,IAAM,OAAO,cAAc;AAE3B,IAAM,WAAW,kBAAkB","sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport interface ZodMeta {\n label: string\n type?: string\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n","import {\n createForm,\n CreateFormProps,\n WithFields,\n FormProps,\n FieldValues,\n} from '@saas-ui/forms'\nimport { zodFieldResolver, zodResolver } from './zod-resolver'\nimport { z } from 'zod'\n\ntype ResolverArgs = Parameters<typeof zodResolver>\n\nexport interface CreateZodFormProps<FieldDefs>\n extends CreateFormProps<FieldDefs> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\nexport type ZodFormType<\n FieldDefs,\n ExtraProps = object,\n ExtraOverrides = object,\n Type extends 'zod' = 'zod'\n> = (<\n TSchema extends z.AnyZodObject = z.AnyZodObject,\n TFieldValues extends z.infer<TSchema> = z.infer<TSchema>,\n TContext extends object = object\n>(\n props: WithFields<\n FormProps<TSchema, TFieldValues, TContext>,\n FieldDefs,\n ExtraOverrides\n > & {\n ref?: React.ForwardedRef<HTMLFormElement>\n } & ExtraProps\n) => React.ReactElement) & {\n displayName?: string\n id?: string\n}\n\nexport const createZodForm = <FieldDefs>(\n options?: CreateZodFormProps<FieldDefs>\n) => {\n const ZodForm = createForm({\n resolver: (schema: any) =>\n zodResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: zodFieldResolver,\n ...options,\n })\n\n ZodForm.displayName = 'ZodForm'\n ZodForm.id = 'ZodForm'\n\n return ZodForm as ZodFormType<FieldDefs>\n}\n","import {\n CreateFormProps,\n createStepForm,\n StepsOptions,\n UseStepFormProps,\n} from '@saas-ui/forms'\nimport { zodFieldResolver, zodResolver } from './zod-resolver'\nimport { AnyZodObject, z } from 'zod'\nimport React from 'react'\n\ntype ResolverArgs = Parameters<typeof zodResolver>\n\nexport interface CreateZodFormProps<FieldDefs>\n extends CreateFormProps<FieldDefs> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\ntype InferStepType<T extends Required<StepsOptions<AnyZodObject>>> = T extends [\n infer Step,\n ...infer Rest\n]\n ? Step extends { schema: AnyZodObject }\n ? z.infer<Step['schema']> &\n (Rest extends Required<StepsOptions<AnyZodObject>>\n ? InferStepType<Rest>\n : object)\n : object\n : object\n\ntype ZodStepFormType<\n FieldDefs,\n ExtraProps = object,\n ExtraOverrides = object\n> = (<\n TSteps extends Required<StepsOptions<AnyZodObject>> = Required<\n StepsOptions<AnyZodObject>\n >,\n TFieldValues extends InferStepType<TSteps> = InferStepType<TSteps>,\n TContext extends object = object\n>(\n props: UseStepFormProps<TSteps, TFieldValues, TContext> & {\n steps: TSteps\n ref?: React.ForwardedRef<HTMLFormElement>\n }\n) => React.ReactElement) & {\n displayName?: string\n id?: string\n}\n\nexport const createZodStepForm = <FieldDefs>(\n options?: CreateZodFormProps<FieldDefs>\n) => {\n const ZodStepForm = createStepForm<any, any, any, any>({\n resolver: (schema: any) =>\n zodResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: zodFieldResolver,\n ...options,\n })\n\n ZodStepForm.displayName = 'ZodStepForm'\n ZodStepForm.id = 'ZodStepForm'\n\n return ZodStepForm as ZodStepFormType<FieldDefs>\n}\n","export {\n zodResolver,\n getFieldsFromSchema,\n getNestedSchema,\n zodFieldResolver,\n zodMeta,\n zodParseMeta,\n} from './zod-resolver'\nexport type { Options, ZodMeta } from './zod-resolver'\nexport { createZodForm, type ZodFormType } from './create-zod-form'\n\nimport { createZodForm } from './create-zod-form'\nimport { createZodStepForm } from './create-zod-step-form'\n\nexport const Form = createZodForm()\n\nexport const StepForm = createZodStepForm()\n"]}
|
1
|
+
{"version":3,"sources":["../../zod/src/zod-resolver.ts","../../zod/src/create-zod-form.ts","../../../saas-ui-modals/src/dialog.tsx","../../../saas-ui-react-utils/src/get-child-of-type.ts","../../../saas-ui-react-utils/src/get-children-of-type.ts","../../../saas-ui-react-utils/src/use-responsive-value.ts","../../../saas-ui-modals/src/drawer.tsx","../../../saas-ui-modals/src/modal.tsx","../../../saas-ui-modals/src/menu.tsx","../../../saas-ui-modals/src/form.tsx","../../zod/src/create-zod-dialog.ts","../../zod/src/create-zod-step-form.ts","../../zod/src/index.ts"],"names":["useBreakpointValue","runIfFn","jsx","ModalFooter","Form2","ModalBody","Button","Form","FormDialog"],"mappings":";;;;;;;;;;;;;;;;;;;AACA,SAAS,mBAAmB;AAC5B,SAAS,WAAW;AAUpB,IAAM,UAAU,CAAC,UAAwB;AACvC,UAAQ,MAAM,KAAK,UAAU;AAAA,IAC3B,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL;AACE,aAAO;AAAA,EACX;AACF;AAEA,IAAM,iBAAiB,CAAC,OAAY,SAAiB;AA5BrD;AA6BE,UAAO,WAAM,KAAK,IAAI,MAAf,mBAAkB;AAC3B;AAQO,IAAM,sBAAsB,CAAC,WAAuC;AACzE,QAAM,SAAuB,CAAC;AAE9B,MAAI,eAAoC,CAAC;AACzC,MAAI,OAAO,KAAK,aAAa,YAAY;AACvC,mBAAe,OAAO,KAAK,KAAK;AAAA,EAClC,WAAW,OAAO,KAAK,aAAa,aAAa;AAC/C,mBAAe,OAAO,KAAK,MAAM;AAAA,EACnC,OAAO;AACL,WAAO;AAAA,EACT;AAEA,aAAW,QAAQ,cAAc;AAC/B,UAAM,QAAQ,aAAa,IAAI;AAE/B,UAAM,UAAmB,CAAC;AAC1B,QAAI,MAAM,KAAK,aAAa,YAAY;AACtC,cAAQ,MAAM,eAAe,OAAO,WAAW;AAC/C,cAAQ,MAAM,eAAe,OAAO,WAAW;AAAA,IACjD;AAEA,UAAM,OAAO,MAAM,eAAe,aAAa,MAAM,WAAW;AAEhE,WAAO,KAAK;AAAA,MACV;AAAA,MACA,QAAO,6BAAM,UAAS,MAAM,eAAe;AAAA,MAC3C,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AA,cAAAA,aAAAA,SAAAA,UAAAA,IAAAA,KAAAA,oBAAAA,YAAAA,CAAAA,CAAAA,EAAAA,CAAAA;QACA,UAAAF,qBAAAA,aAAAA,EAAAA,UAAAA;UACAG;YACA;YAEK;cACE,SAAAL;cAET,IAAA;cACE,SAAA;cACA,GAAA,UAAA,OAAA,SAAA,OAAA;cACA,WAAA,MAAA,KAAA,UAAA,OAAA,SAAA,OAAA,WAAA,OAAA,SAAA,GAAA,aAAA,OAAA,KAAA;YAOK;UAsJK;UArGU,oBAA2B,cAAA,EAAA,GAAA,UAAA,OAAA,SAAA,OAAA,OAAA,CAAA;QACzC,EAAA,CAAA;MACJ,EAAA,CAAA;IACA,EAAA,CAAA,EAAA,CAAA;EAAA,CAAA;AACA,SACA,cAAA,GAAAG,OAAA,eAAAA,OAAA;AAAA,SACA,KAAAA,OAAA;AAAA,SACA;AAAA;AACA,IACA,aAAA,iBAAA,IAAA;AAUG,IACL,gBAAI,qBAAA,IAAA;;;ACnFC,SAAS,oBAIdG,OAA0D;AAC1D,SAAO,iBAAiBA,KAAI;AAK9B;;;ACjBA;AAAA,EAEE;AAAA,OAGK;AA6CA,IAAM,oBAAoB,CAC/B,YACG;AACH,QAAM,cAAc,eAAmC;AAAA,IACrD,UAAU,CAAC,WACT,YAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,eAAe;AAAA,IACf,GAAG;AAAA,EACL,CAAC;AAED,cAAY,cAAc;AAC1B,cAAY,KAAK;AAEjB,SAAO;AACT;;;AChDO,IAAMA,QAAO,cAAc;AAE3B,IAAM,WAAW,kBAAkB;AAEnC,IAAMC,cAAa,oBAAoBD,KAAI","sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport interface ZodMeta {\n /**\n * The label of the field\n */\n label: string\n /**\n * The type of the field\n */\n type?: string\n /**\n * Object field column count\n */\n columns?: number\n /**\n * Array field min rows\n */\n min?: number\n /**\n * Array field max rows\n */\n max?: number\n [key: string]: any\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n","import {\n createForm,\n CreateFormProps,\n WithFields,\n FormProps,\n} from '@saas-ui/forms'\nimport { zodFieldResolver, zodResolver } from './zod-resolver'\nimport { z } from 'zod'\n\ntype ResolverArgs = Parameters<typeof zodResolver>\n\nexport interface CreateZodFormProps<FieldDefs>\n extends CreateFormProps<FieldDefs> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\nexport type ZodFormType<\n FieldDefs,\n ExtraProps = object,\n ExtraOverrides = object,\n Type extends 'zod' = 'zod'\n> = (<\n TSchema extends z.AnyZodObject = z.AnyZodObject,\n TFieldValues extends z.infer<TSchema> = z.infer<TSchema>,\n TContext extends object = object\n>(\n props: WithFields<\n FormProps<TSchema, TFieldValues, TContext>,\n FieldDefs,\n ExtraOverrides\n > & {\n ref?: React.ForwardedRef<HTMLFormElement>\n } & ExtraProps\n) => React.ReactElement) & {\n displayName?: string\n id?: string\n}\n\nexport const createZodForm = <FieldDefs>(\n options?: CreateZodFormProps<FieldDefs>\n) => {\n const ZodForm = createForm({\n resolver: (schema: any) =>\n zodResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: zodFieldResolver,\n ...options,\n })\n\n ZodForm.displayName = 'ZodForm'\n ZodForm.id = 'ZodForm'\n\n return ZodForm as ZodFormType<FieldDefs>\n}\n","import * as React from 'react'\n\nimport {\n AlertDialog,\n AlertDialogBody,\n AlertDialogFooter,\n AlertDialogHeader,\n AlertDialogContent,\n AlertDialogOverlay,\n AlertDialogProps,\n ButtonGroup,\n ButtonGroupProps,\n Button,\n ButtonProps,\n} from '@chakra-ui/react'\n\nexport interface ConfirmDialogProps\n extends Omit<AlertDialogProps, 'leastDestructiveRef'> {\n /**\n * The dialog title\n */\n title?: React.ReactNode\n /**\n * The cancel button label\n */\n cancelLabel?: React.ReactNode\n /**\n * The confirm button label\n */\n confirmLabel?: React.ReactNode\n /**\n * The cancel button props\n */\n cancelProps?: ButtonProps\n /**\n * The confirm button props\n */\n confirmProps?: ButtonProps\n /**\n * The button group props\n */\n buttonGroupProps?: ButtonGroupProps\n /**\n * Close the dialog on cancel\n * @default true\n */\n closeOnCancel?: boolean\n /**\n * Close the dialog on confirm\n * @default true\n */\n closeOnConfirm?: boolean\n /**\n * Defines which button gets initial focus\n * https://www.w3.org/TR/wai-aria-practices/#alertdialog\n */\n leastDestructiveFocus?: 'cancel' | 'confirm'\n /**\n * Function that's called when cancel is clicked\n */\n onCancel?: () => void\n /**\n * Function that's called when confirm is clicked.\n */\n onConfirm?: () => Promise<void> | void\n}\n\nexport const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {\n const {\n title,\n cancelLabel = 'Cancel',\n confirmLabel = 'Confirm',\n cancelProps,\n confirmProps,\n buttonGroupProps,\n isOpen,\n closeOnCancel = true,\n closeOnConfirm = true,\n leastDestructiveFocus = 'cancel',\n onClose,\n onCancel,\n onConfirm,\n children,\n ...rest\n } = props\n\n const cancelRef = React.useRef(null)\n const confirmRef = React.useRef(null)\n const [isLoading, setIsLoading] = React.useState(false)\n\n const handleConfirm = async () => {\n try {\n const result = onConfirm?.()\n if (typeof result?.then === 'function') {\n setIsLoading(true)\n await result\n }\n\n closeOnConfirm && onClose()\n /* eslint-disable no-useless-catch */\n } catch (e: any) {\n throw e\n } finally {\n setIsLoading(false)\n }\n /* eslint-enable */\n }\n console.log(isLoading)\n return (\n <AlertDialog\n isOpen={isOpen}\n onClose={onClose}\n {...rest}\n leastDestructiveRef={\n leastDestructiveFocus === 'cancel' ? cancelRef : confirmRef\n }\n >\n <AlertDialogOverlay>\n <AlertDialogContent>\n <AlertDialogHeader>{title}</AlertDialogHeader>\n\n <AlertDialogBody>{children}</AlertDialogBody>\n\n <AlertDialogFooter>\n <ButtonGroup {...buttonGroupProps}>\n <Button\n ref={cancelRef}\n {...cancelProps}\n onClick={() => {\n onCancel?.()\n\n closeOnCancel && onClose()\n }}\n >\n {cancelProps?.children || cancelLabel}\n </Button>\n <Button\n ref={confirmRef}\n isLoading={isLoading}\n {...confirmProps}\n onClick={handleConfirm}\n >\n {confirmProps?.children || confirmLabel}\n </Button>\n </ButtonGroup>\n </AlertDialogFooter>\n </AlertDialogContent>\n </AlertDialogOverlay>\n </AlertDialog>\n )\n}\n","import * as React from 'react'\n\n/**\n * Get the first child of a specific type.\n * @param children The children\n * @param type The component type\n */\nexport function getChildOfType(\n children: React.ReactNode,\n type: React.JSXElementConstructor<any>\n) {\n return (React.Children.toArray(children) as React.ReactElement[]).find(\n (item) => item.type === type\n )\n}\n","import * as React from 'react'\n\n/**\n * Get all children of a specific type.\n * @param children The children\n * @param type The component type\n */\nexport function getChildrenOfType(\n children: React.ReactNode,\n type: React.JSXElementConstructor<any> | React.JSXElementConstructor<any>[]\n) {\n return (React.Children.toArray(children) as React.ReactElement[]).filter(\n (item) =>\n Array.isArray(type)\n ? type.some((component) => component === item.type)\n : item.type === type\n )\n}\n","import {\n ResponsiveValue,\n UseBreakpointOptions,\n useTheme,\n useBreakpointValue,\n} from '@chakra-ui/react'\n\nconst normalize = (variant: any, toArray?: (value: any) => any) => {\n if (Array.isArray(variant)) return variant\n else if (typeof variant === 'object') return toArray?.(variant)\n if (variant != null) return [variant]\n return []\n}\n\nexport const useResponsiveValue = (\n value: ResponsiveValue<any>,\n options?: UseBreakpointOptions\n) => {\n const theme = useTheme()\n const normalized = normalize(value, theme.__breakpoints?.toArrayValue)\n return useBreakpointValue(normalized, options)\n}\n","import * as React from 'react'\n\nimport {\n Drawer as ChakraDrawer,\n DrawerOverlay,\n DrawerContent,\n DrawerHeader,\n DrawerFooter,\n DrawerBody,\n DrawerCloseButton,\n DrawerProps as ChakraDrawerProps,\n ModalHeaderProps,\n ModalContentProps,\n ModalFooterProps,\n} from '@chakra-ui/react'\nimport { MaybeRenderProp } from '@chakra-ui/react-utils'\nimport { runIfFn } from '@chakra-ui/utils'\n\nexport interface BaseDrawerProps extends Omit<ChakraDrawerProps, 'children'> {\n /**\n * The drawer title\n */\n title: React.ReactNode\n /**\n * The modal children\n */\n children: MaybeRenderProp<{\n isOpen: boolean\n onClose: () => void\n }>\n /**\n * The modal footer\n */\n footer?: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overflow\n */\n hideOverlay?: boolean\n /**\n * Props for the modal header\n */\n headerProps?: ModalHeaderProps\n /**\n * Props for the modal content\n */\n contentProps?: ModalContentProps\n /**\n * Props for the modal footer\n */\n footerProps?: ModalFooterProps\n}\n\nexport const BaseDrawer: React.FC<BaseDrawerProps> = (props) => {\n const {\n title,\n children,\n footer,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n headerProps,\n contentProps,\n footerProps,\n ...rest\n } = props\n return (\n <ChakraDrawer isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <DrawerOverlay />}\n <DrawerContent {...contentProps}>\n {title && <DrawerHeader {...headerProps}>{title}</DrawerHeader>}\n {!hideCloseButton && <DrawerCloseButton />}\n {runIfFn(children, {\n isOpen,\n onClose,\n })}\n {footer && <DrawerFooter {...footerProps}>{footer}</DrawerFooter>}\n </DrawerContent>\n </ChakraDrawer>\n )\n}\n\nexport interface DrawerProps extends BaseDrawerProps {\n /**\n * Drawer footer content, wrapped with `DrawerFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const Drawer: React.FC<DrawerProps> = (props) => {\n const { children, isOpen, onClose, ...rest } = props\n return (\n <BaseDrawer isOpen={isOpen} onClose={onClose} {...rest}>\n <DrawerBody>\n {runIfFn(children, {\n isOpen,\n onClose,\n })}\n </DrawerBody>\n </BaseDrawer>\n )\n}\n","import * as React from 'react'\n\nimport {\n Modal as ChakraModal,\n ModalOverlay,\n ModalContent,\n ModalHeader,\n ModalFooter,\n ModalBody,\n ModalCloseButton,\n ModalProps as ChakraModalProps,\n ModalContentProps,\n ModalHeaderProps,\n ModalFooterProps,\n} from '@chakra-ui/react'\nimport { MaybeRenderProp } from '@chakra-ui/react-utils'\nimport { runIfFn } from '@chakra-ui/utils'\n\nexport interface BaseModalProps extends Omit<ChakraModalProps, 'children'> {\n /**\n * The modal title\n */\n title?: React.ReactNode\n /**\n * The modal children\n */\n children: MaybeRenderProp<{\n isOpen: boolean\n onClose: () => void\n }>\n /**\n * The modal footer\n */\n footer?: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overlay\n */\n hideOverlay?: boolean\n /**\n * Props for the modal header\n */\n headerProps?: ModalHeaderProps\n /**\n * Props for the modal content\n */\n contentProps?: ModalContentProps\n /**\n * Props for the modal footer\n */\n footerProps?: ModalFooterProps\n}\n\nexport const BaseModal: React.FC<BaseModalProps> = (props) => {\n const {\n title,\n footer,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n headerProps,\n contentProps,\n footerProps,\n ...rest\n } = props\n return (\n <ChakraModal isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <ModalOverlay />}\n <ModalContent {...contentProps}>\n {title && <ModalHeader {...headerProps}>{title}</ModalHeader>}\n {!hideCloseButton && <ModalCloseButton />}\n {runIfFn(children, {\n isOpen,\n onClose,\n })}\n {footer && <ModalFooter {...footerProps}>{footer}</ModalFooter>}\n </ModalContent>\n </ChakraModal>\n )\n}\n\nexport const Modal: React.FC<BaseModalProps> = (props) => {\n const { children, isOpen, onClose, ...rest } = props\n return (\n <BaseModal {...rest} isOpen={isOpen} onClose={onClose}>\n <ModalBody>\n {runIfFn(children, {\n isOpen,\n onClose,\n })}\n </ModalBody>\n </BaseModal>\n )\n}\n","import * as React from 'react'\n\nimport {\n ModalFooter,\n chakra,\n forwardRef,\n useMenuContext,\n useMenuList,\n createStylesContext,\n useMultiStyleConfig,\n Menu,\n MenuListProps,\n useBreakpointValue,\n} from '@chakra-ui/react'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nconst [StylesProvider] = createStylesContext('SuiMenuDialog')\n\nexport interface MenuDialogProps extends BaseModalProps {\n /**\n * The modal footer, wrapped with `ModalFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const MenuDialog: React.FC<MenuDialogProps> = (props) => {\n const { onClose, onCloseComplete, ...rest } = props\n\n return (\n <Menu\n variant=\"dialog\"\n onClose={() => {\n onClose?.()\n // Not supported in Menu, so we call it here instead\n // @todo Refactor this in v2?\n onCloseComplete?.()\n }}\n {...rest}\n />\n )\n}\n\nexport interface MenuDialogListProps\n extends Omit<\n BaseModalProps,\n 'isOpen' | 'onClose' | 'children' | 'scrollBehavior'\n >,\n Omit<MenuListProps, 'title'> {}\n\nexport const MenuDialogList = forwardRef<MenuDialogListProps, 'div'>(\n (props, forwardedRef) => {\n const {\n rootProps,\n title,\n footer,\n initialFocusRef,\n hideCloseButton,\n motionPreset = 'slideInBottom',\n isCentered: isCenteredProp,\n ...rest\n } = props\n\n const { isOpen, onClose, menuRef } = useMenuContext()\n\n const { ref, ...ownProps } = useMenuList(rest, forwardedRef)\n\n const styles = useMultiStyleConfig('Menu', props)\n\n const isCentered = useBreakpointValue({ base: true, md: false })\n\n return (\n <BaseModal\n isOpen={isOpen}\n onClose={onClose}\n initialFocusRef={initialFocusRef || menuRef}\n title={title}\n hideCloseButton={hideCloseButton}\n motionPreset={motionPreset}\n isCentered={isCenteredProp ?? isCentered}\n contentProps={{ mx: 4 }}\n >\n {/* We forward the styles again, otherwise the modal styles will be picked up */}\n <StylesProvider value={styles}>\n <chakra.div\n {...ownProps}\n ref={ref as React.Ref<HTMLDivElement>}\n __css={{\n outline: 0,\n maxHeight: '80vh', // can override this in theme\n overflowY: 'auto', // can override this in theme\n ...styles.list,\n boxShadow: 'none',\n border: 0,\n _dark: {\n /* @ts-expect-error */\n ...(styles.list._dark || {}),\n boxShadow: 'none',\n },\n }}\n />\n </StylesProvider>\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </BaseModal>\n )\n }\n)\n","import * as React from 'react'\n\nimport {\n ModalBody,\n ModalFooter,\n Button,\n forwardRef,\n ButtonProps,\n} from '@chakra-ui/react'\nimport { runIfFn } from '@saas-ui/react-utils'\n\nimport {\n Form,\n AutoFields,\n SubmitButton,\n FormProps,\n FieldValues,\n FieldResolver,\n FieldProps,\n FormType,\n DefaultFieldOverrides,\n} from '@saas-ui/forms'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nexport type FormDialogFieldOverrides = DefaultFieldOverrides & {\n cancel?: ButtonProps\n}\n\nexport interface FormDialogProps<\n TSchema = any,\n TFieldValues extends FieldValues = FieldValues,\n TContext extends object = object,\n TFieldTypes = FieldProps<TFieldValues>\n> extends Omit<BaseModalProps, 'children'>,\n Pick<\n FormProps<TSchema, TFieldValues, TContext, TFieldTypes>,\n | 'schema'\n | 'defaultValues'\n | 'values'\n | 'context'\n | 'onChange'\n | 'onSubmit'\n | 'onError'\n | 'resolver'\n | 'mode'\n | 'reValidateMode'\n | 'shouldFocusError'\n | 'shouldUnregister'\n | 'shouldUseNativeValidation'\n | 'criteriaMode'\n | 'delayError'\n | 'resetOptions'\n | 'children'\n > {\n /**\n * The modal footer, will be wrapped with `ModalFooter`.\n * Defaults to a cancel and submit button.\n */\n footer?: React.ReactNode\n /**\n * A schema field resolver used to auto generate form fields.\n */\n fieldResolver?: FieldResolver\n /**\n * Field overrides\n */\n fields?: FormDialogFieldOverrides\n}\n\nconst useFormProps = (props: FormDialogProps) => {\n const {\n schema,\n resolver,\n fieldResolver,\n defaultValues,\n values,\n context,\n onChange,\n onSubmit,\n onError,\n mode,\n reValidateMode,\n shouldFocusError = true,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError = 100,\n fields,\n ...modalProps\n } = props\n\n const formProps = {\n schema,\n resolver,\n defaultValues,\n values,\n context,\n onChange,\n onSubmit,\n onError,\n mode,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n fields,\n }\n\n return { modalProps, formProps, fields }\n}\n\n/**\n * @todo make this dynamic to support other schema types\n */\ntype MergeDialogProps<T> = T extends FormType<\n infer FieldDefs,\n infer ExtraProps,\n infer ExtraOverrides\n>\n ? FormType<\n FieldDefs,\n ExtraProps & Omit<BaseModalProps, 'children'>,\n ExtraOverrides & FormDialogFieldOverrides\n >\n : never\n\ntype IsSchemaType<T, Schema, FieldDefs> = T extends DefaultFormType<FieldDefs>\n ? T extends (\n props: FormProps<infer TSchema, infer TFieldValues, infer TContext>\n ) => any\n ? Schema extends TSchema\n ? true\n : false\n : false\n : false\n\nexport type DefaultFormType<\n FieldDefs = any,\n ExtraProps = object,\n ExtraOverrides = FormDialogFieldOverrides\n> = (<\n TSchema = unknown,\n TFieldValues extends Record<string, any> = any,\n TContext extends object = object\n>(\n props: any\n) => React.ReactElement) & {\n displayName?: string\n id?: string\n}\n\nexport function createFormDialog<\n FieldDefs = any,\n ExtraProps = object,\n ExtraOverrides = FormDialogFieldOverrides,\n TFormType extends DefaultFormType<\n FieldDefs,\n ExtraProps,\n ExtraOverrides\n > = DefaultFormType<FieldDefs, ExtraProps, ExtraOverrides>\n>(Form: TFormType) {\n const Dialog = forwardRef<any, 'div'>((props, ref) => {\n const { isOpen, onClose, footer, children, ...rest } = props\n const { modalProps, formProps, fields } = useFormProps(rest)\n return (\n <BaseModal {...modalProps} isOpen={isOpen} onClose={onClose}>\n <Form ref={ref} {...(formProps as any)}>\n {(form: any) => (\n <>\n <ModalBody>{runIfFn(children, form) || <AutoFields />}</ModalBody>\n\n {footer || (\n <ModalFooter>\n <Button\n variant=\"ghost\"\n mr={3}\n onClick={onClose}\n {...fields?.cancel}\n >\n {fields?.cancel?.children ?? 'Cancel'}\n </Button>\n <SubmitButton {...fields?.submit} />\n </ModalFooter>\n )}\n </>\n )}\n </Form>\n </BaseModal>\n )\n }) as MergeDialogProps<TFormType>\n\n Dialog.displayName = `${Form.displayName || Form.name}Dialog`\n Dialog.id = Form.id\n\n return Dialog\n}\n\n/**\n * Can be used to quickly request information from people without leaving the current page.\n *\n * @see Docs https://saas-ui.dev/docs/components/overlay/form-dialog\n */\nexport const FormDialog = createFormDialog(Form)\n","import {\n createFormDialog,\n BaseModalProps,\n FormDialogFieldOverrides,\n} from '@saas-ui/modals'\nimport { ZodFormType } from './create-zod-form'\n\nexport function createZodFormDialog<\n FieldDefs = any,\n ExtraProps = object,\n ExtraOverrides = object\n>(Form: ZodFormType<FieldDefs, ExtraProps, ExtraOverrides>) {\n return createFormDialog(Form) as unknown as ZodFormType<\n FieldDefs,\n ExtraProps & Omit<BaseModalProps, 'children'>,\n ExtraOverrides & FormDialogFieldOverrides\n >\n}\n","import {\n CreateFormProps,\n createStepForm,\n StepsOptions,\n UseStepFormProps,\n} from '@saas-ui/forms'\nimport { zodFieldResolver, zodResolver } from './zod-resolver'\nimport { AnyZodObject, z } from 'zod'\nimport React from 'react'\n\ntype ResolverArgs = Parameters<typeof zodResolver>\n\nexport interface CreateZodFormProps<FieldDefs>\n extends CreateFormProps<FieldDefs> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\ntype InferStepType<T extends Required<StepsOptions<AnyZodObject>>> = T extends [\n infer Step,\n ...infer Rest\n]\n ? Step extends { schema: AnyZodObject }\n ? z.infer<Step['schema']> &\n (Rest extends Required<StepsOptions<AnyZodObject>>\n ? InferStepType<Rest>\n : object)\n : object\n : object\n\ntype ZodStepFormType<\n FieldDefs,\n ExtraProps = object,\n ExtraOverrides = object\n> = (<\n TSteps extends Required<StepsOptions<AnyZodObject>> = Required<\n StepsOptions<AnyZodObject>\n >,\n TFieldValues extends InferStepType<TSteps> = InferStepType<TSteps>,\n TContext extends object = object\n>(\n props: UseStepFormProps<TSteps, TFieldValues, TContext> & {\n steps: TSteps\n ref?: React.ForwardedRef<HTMLFormElement>\n }\n) => React.ReactElement) & {\n displayName?: string\n id?: string\n}\n\nexport const createZodStepForm = <FieldDefs>(\n options?: CreateZodFormProps<FieldDefs>\n) => {\n const ZodStepForm = createStepForm<any, any, any, any>({\n resolver: (schema: any) =>\n zodResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: zodFieldResolver,\n ...options,\n })\n\n ZodStepForm.displayName = 'ZodStepForm'\n ZodStepForm.id = 'ZodStepForm'\n\n return ZodStepForm as ZodStepFormType<FieldDefs>\n}\n","export {\n zodResolver,\n getFieldsFromSchema,\n getNestedSchema,\n zodFieldResolver,\n zodMeta,\n zodParseMeta,\n} from './zod-resolver'\nexport type { Options, ZodMeta } from './zod-resolver'\nexport { createZodForm, type ZodFormType } from './create-zod-form'\nexport { createZodFormDialog } from './create-zod-dialog'\n\nimport { createZodForm } from './create-zod-form'\nimport { createZodStepForm } from './create-zod-step-form'\nimport { createZodFormDialog } from './create-zod-dialog'\n\nexport const Form = createZodForm()\n\nexport const StepForm = createZodStepForm()\n\nexport const FormDialog = createZodFormDialog(Form)\n"]}
|
package/dist/zod/index.mjs
CHANGED
@@ -1,9 +1,29 @@
|
|
1
1
|
import { zodResolver } from '@hookform/resolvers/zod';
|
2
2
|
export { zodResolver } from '@hookform/resolvers/zod';
|
3
|
-
import
|
4
|
-
import {
|
3
|
+
import * as utils_star from '@chakra-ui/utils';
|
4
|
+
import { get, runIfFn } from '@chakra-ui/utils';
|
5
|
+
import { createForm, AutoFields, SubmitButton, Form, createStepForm } from '@saas-ui/forms';
|
6
|
+
import * as React from 'react';
|
7
|
+
import { createStylesContext, forwardRef, useMenuContext, useMenuList, useMultiStyleConfig, useBreakpointValue, chakra, ModalFooter, useTheme, Modal, ModalOverlay, ModalContent, ModalHeader, ModalCloseButton, ModalBody, Button } from '@chakra-ui/react';
|
8
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
5
9
|
|
6
|
-
|
10
|
+
var __defProp = Object.defineProperty;
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
14
|
+
var __export = (target, all) => {
|
15
|
+
for (var name in all)
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
17
|
+
};
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
20
|
+
for (let key of __getOwnPropNames(from))
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
23
|
+
}
|
24
|
+
return to;
|
25
|
+
};
|
26
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
7
27
|
var getType = (field) => {
|
8
28
|
switch (field._def.typeName) {
|
9
29
|
case "ZodArray":
|
@@ -83,6 +103,200 @@ var createZodForm = (options) => {
|
|
83
103
|
ZodForm.id = "ZodForm";
|
84
104
|
return ZodForm;
|
85
105
|
};
|
106
|
+
|
107
|
+
// ../saas-ui-react-utils/dist/index.mjs
|
108
|
+
var dist_exports = {};
|
109
|
+
__export(dist_exports, {
|
110
|
+
getChildOfType: () => getChildOfType,
|
111
|
+
getChildrenOfType: () => getChildrenOfType,
|
112
|
+
useResponsiveValue: () => useResponsiveValue
|
113
|
+
});
|
114
|
+
__reExport(dist_exports, utils_star);
|
115
|
+
function getChildOfType(children, type) {
|
116
|
+
return React.Children.toArray(children).find(
|
117
|
+
(item) => item.type === type
|
118
|
+
);
|
119
|
+
}
|
120
|
+
function getChildrenOfType(children, type) {
|
121
|
+
return React.Children.toArray(children).filter(
|
122
|
+
(item) => Array.isArray(type) ? type.some((component) => component === item.type) : item.type === type
|
123
|
+
);
|
124
|
+
}
|
125
|
+
var normalize = (variant, toArray) => {
|
126
|
+
if (Array.isArray(variant))
|
127
|
+
return variant;
|
128
|
+
else if (typeof variant === "object")
|
129
|
+
return toArray == null ? void 0 : toArray(variant);
|
130
|
+
if (variant != null)
|
131
|
+
return [variant];
|
132
|
+
return [];
|
133
|
+
};
|
134
|
+
var useResponsiveValue = (value, options) => {
|
135
|
+
var _a;
|
136
|
+
const theme = useTheme();
|
137
|
+
const normalized = normalize(value, (_a = theme.__breakpoints) == null ? void 0 : _a.toArrayValue);
|
138
|
+
return useBreakpointValue(normalized, options);
|
139
|
+
};
|
140
|
+
var BaseModal = (props) => {
|
141
|
+
const {
|
142
|
+
title,
|
143
|
+
footer,
|
144
|
+
children,
|
145
|
+
isOpen,
|
146
|
+
onClose,
|
147
|
+
hideCloseButton,
|
148
|
+
hideOverlay,
|
149
|
+
headerProps,
|
150
|
+
contentProps,
|
151
|
+
footerProps,
|
152
|
+
...rest
|
153
|
+
} = props;
|
154
|
+
return /* @__PURE__ */ jsxs(Modal, { isOpen, onClose, ...rest, children: [
|
155
|
+
!hideOverlay && /* @__PURE__ */ jsx(ModalOverlay, {}),
|
156
|
+
/* @__PURE__ */ jsxs(ModalContent, { ...contentProps, children: [
|
157
|
+
title && /* @__PURE__ */ jsx(ModalHeader, { ...headerProps, children: title }),
|
158
|
+
!hideCloseButton && /* @__PURE__ */ jsx(ModalCloseButton, {}),
|
159
|
+
runIfFn(children, {
|
160
|
+
isOpen,
|
161
|
+
onClose
|
162
|
+
}),
|
163
|
+
footer && /* @__PURE__ */ jsx(ModalFooter, { ...footerProps, children: footer })
|
164
|
+
] })
|
165
|
+
] });
|
166
|
+
};
|
167
|
+
var [StylesProvider] = createStylesContext("SuiMenuDialog");
|
168
|
+
forwardRef(
|
169
|
+
(props, forwardedRef) => {
|
170
|
+
const {
|
171
|
+
rootProps,
|
172
|
+
title,
|
173
|
+
footer,
|
174
|
+
initialFocusRef,
|
175
|
+
hideCloseButton,
|
176
|
+
motionPreset = "slideInBottom",
|
177
|
+
isCentered: isCenteredProp,
|
178
|
+
...rest
|
179
|
+
} = props;
|
180
|
+
const { isOpen, onClose, menuRef } = useMenuContext();
|
181
|
+
const { ref, ...ownProps } = useMenuList(rest, forwardedRef);
|
182
|
+
const styles = useMultiStyleConfig("Menu", props);
|
183
|
+
const isCentered = useBreakpointValue({ base: true, md: false });
|
184
|
+
return /* @__PURE__ */ jsxs(
|
185
|
+
BaseModal,
|
186
|
+
{
|
187
|
+
isOpen,
|
188
|
+
onClose,
|
189
|
+
initialFocusRef: initialFocusRef || menuRef,
|
190
|
+
title,
|
191
|
+
hideCloseButton,
|
192
|
+
motionPreset,
|
193
|
+
isCentered: isCenteredProp != null ? isCenteredProp : isCentered,
|
194
|
+
contentProps: { mx: 4 },
|
195
|
+
children: [
|
196
|
+
/* @__PURE__ */ jsx(StylesProvider, { value: styles, children: /* @__PURE__ */ jsx(
|
197
|
+
chakra.div,
|
198
|
+
{
|
199
|
+
...ownProps,
|
200
|
+
ref,
|
201
|
+
__css: {
|
202
|
+
outline: 0,
|
203
|
+
maxHeight: "80vh",
|
204
|
+
// can override this in theme
|
205
|
+
overflowY: "auto",
|
206
|
+
// can override this in theme
|
207
|
+
...styles.list,
|
208
|
+
boxShadow: "none",
|
209
|
+
border: 0,
|
210
|
+
_dark: {
|
211
|
+
/* @ts-expect-error */
|
212
|
+
...styles.list._dark || {},
|
213
|
+
boxShadow: "none"
|
214
|
+
}
|
215
|
+
}
|
216
|
+
}
|
217
|
+
) }),
|
218
|
+
footer && /* @__PURE__ */ jsx(ModalFooter, { children: footer })
|
219
|
+
]
|
220
|
+
}
|
221
|
+
);
|
222
|
+
}
|
223
|
+
);
|
224
|
+
var useFormProps = (props) => {
|
225
|
+
const {
|
226
|
+
schema,
|
227
|
+
resolver,
|
228
|
+
fieldResolver,
|
229
|
+
defaultValues,
|
230
|
+
values,
|
231
|
+
context,
|
232
|
+
onChange,
|
233
|
+
onSubmit,
|
234
|
+
onError,
|
235
|
+
mode,
|
236
|
+
reValidateMode,
|
237
|
+
shouldFocusError = true,
|
238
|
+
shouldUnregister,
|
239
|
+
shouldUseNativeValidation,
|
240
|
+
criteriaMode,
|
241
|
+
delayError = 100,
|
242
|
+
fields,
|
243
|
+
...modalProps
|
244
|
+
} = props;
|
245
|
+
const formProps = {
|
246
|
+
schema,
|
247
|
+
resolver,
|
248
|
+
defaultValues,
|
249
|
+
values,
|
250
|
+
context,
|
251
|
+
onChange,
|
252
|
+
onSubmit,
|
253
|
+
onError,
|
254
|
+
mode,
|
255
|
+
reValidateMode,
|
256
|
+
shouldFocusError,
|
257
|
+
shouldUnregister,
|
258
|
+
shouldUseNativeValidation,
|
259
|
+
criteriaMode,
|
260
|
+
delayError,
|
261
|
+
fields
|
262
|
+
};
|
263
|
+
return { modalProps, formProps, fields };
|
264
|
+
};
|
265
|
+
function createFormDialog(Form22) {
|
266
|
+
const Dialog = forwardRef((props, ref) => {
|
267
|
+
const { isOpen, onClose, footer, children, ...rest } = props;
|
268
|
+
const { modalProps, formProps, fields } = useFormProps(rest);
|
269
|
+
return /* @__PURE__ */ jsx(BaseModal, { ...modalProps, isOpen, onClose, children: /* @__PURE__ */ jsx(Form22, { ref, ...formProps, children: (form) => {
|
270
|
+
var _a, _b;
|
271
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
272
|
+
/* @__PURE__ */ jsx(ModalBody, { children: (0, dist_exports.runIfFn)(children, form) || /* @__PURE__ */ jsx(AutoFields, {}) }),
|
273
|
+
footer || /* @__PURE__ */ jsxs(ModalFooter, { children: [
|
274
|
+
/* @__PURE__ */ jsx(
|
275
|
+
Button,
|
276
|
+
{
|
277
|
+
variant: "ghost",
|
278
|
+
mr: 3,
|
279
|
+
onClick: onClose,
|
280
|
+
...fields == null ? void 0 : fields.cancel,
|
281
|
+
children: (_b = (_a = fields == null ? void 0 : fields.cancel) == null ? void 0 : _a.children) != null ? _b : "Cancel"
|
282
|
+
}
|
283
|
+
),
|
284
|
+
/* @__PURE__ */ jsx(SubmitButton, { ...fields == null ? void 0 : fields.submit })
|
285
|
+
] })
|
286
|
+
] });
|
287
|
+
} }) });
|
288
|
+
});
|
289
|
+
Dialog.displayName = `${Form22.displayName || Form22.name}Dialog`;
|
290
|
+
Dialog.id = Form22.id;
|
291
|
+
return Dialog;
|
292
|
+
}
|
293
|
+
createFormDialog(Form);
|
294
|
+
React.createContext(null);
|
295
|
+
|
296
|
+
// zod/src/create-zod-dialog.ts
|
297
|
+
function createZodFormDialog(Form3) {
|
298
|
+
return createFormDialog(Form3);
|
299
|
+
}
|
86
300
|
var createZodStepForm = (options) => {
|
87
301
|
const ZodStepForm = createStepForm({
|
88
302
|
resolver: (schema) => zodResolver(schema, options == null ? void 0 : options.schemaOptions, options == null ? void 0 : options.resolverOptions),
|
@@ -95,9 +309,10 @@ var createZodStepForm = (options) => {
|
|
95
309
|
};
|
96
310
|
|
97
311
|
// zod/src/index.ts
|
98
|
-
var
|
312
|
+
var Form2 = createZodForm();
|
99
313
|
var StepForm = createZodStepForm();
|
314
|
+
var FormDialog2 = createZodFormDialog(Form2);
|
100
315
|
|
101
|
-
export { Form, StepForm, createZodForm, getFieldsFromSchema, getNestedSchema, zodFieldResolver, zodMeta, zodParseMeta };
|
316
|
+
export { Form2 as Form, FormDialog2 as FormDialog, StepForm, createZodForm, createZodFormDialog, getFieldsFromSchema, getNestedSchema, zodFieldResolver, zodMeta, zodParseMeta };
|
102
317
|
//# sourceMappingURL=out.js.map
|
103
318
|
//# sourceMappingURL=index.mjs.map
|