@fuf-stack/uniform 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Form/index.cjs +5 -263
- package/dist/Form/index.cjs.map +1 -1
- package/dist/Form/index.d.cts +3 -2
- package/dist/Form/index.d.ts +3 -2
- package/dist/Form/index.js +6 -10
- package/dist/Form/index.js.map +1 -1
- package/dist/{Form/Form.d.cts → Form-Bv0R3QNk.d.cts} +1 -6
- package/dist/{Form/Form.d.ts → Form-Bv0R3QNk.d.ts} +1 -6
- package/dist/Grid/index.cjs +5 -47
- package/dist/Grid/index.cjs.map +1 -1
- package/dist/Grid/index.d.cts +3 -2
- package/dist/Grid/index.d.ts +3 -2
- package/dist/Grid/index.js +4 -5
- package/dist/Grid/index.js.map +1 -1
- package/dist/{Grid/Grid.d.cts → Grid-DF3L9NF3.d.cts} +1 -1
- package/dist/{Grid/Grid.d.ts → Grid-DF3L9NF3.d.ts} +1 -1
- package/dist/SubmitButton/index.cjs +15 -129
- package/dist/SubmitButton/index.cjs.map +1 -1
- package/dist/SubmitButton/index.d.cts +22 -6
- package/dist/SubmitButton/index.d.ts +22 -6
- package/dist/SubmitButton/index.js +37 -6
- package/dist/SubmitButton/index.js.map +1 -1
- package/dist/{chunk-KY2KCXOO.js → chunk-4MEKDDB2.js} +6 -2
- package/dist/chunk-4MEKDDB2.js.map +1 -0
- package/dist/chunk-BBB4FEY6.cjs +22 -0
- package/dist/chunk-BBB4FEY6.cjs.map +1 -0
- package/dist/{chunk-PMNBGDEZ.js → chunk-BCMPSLSG.js} +21 -7
- package/dist/chunk-BCMPSLSG.js.map +1 -0
- package/dist/{chunk-AV26PIKH.js → chunk-BQUVQMFA.js} +79 -3
- package/dist/chunk-BQUVQMFA.js.map +1 -0
- package/dist/chunk-II57W3V2.cjs +158 -0
- package/dist/chunk-II57W3V2.cjs.map +1 -0
- package/dist/{chunk-WIY7KIHU.js → chunk-V46BHM2U.js} +4 -4
- package/dist/chunk-V46BHM2U.js.map +1 -0
- package/dist/chunk-WQRM7G4C.cjs +87 -0
- package/dist/chunk-WQRM7G4C.cjs.map +1 -0
- package/dist/chunk-ZPFKVKGV.cjs +20 -0
- package/dist/chunk-ZPFKVKGV.cjs.map +1 -0
- package/dist/helpers/index.cjs +7 -0
- package/dist/helpers/index.cjs.map +1 -0
- package/dist/helpers/index.d.cts +5 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.js +7 -0
- package/dist/hooks/index.cjs +4 -123
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +40 -4
- package/dist/hooks/index.d.ts +40 -4
- package/dist/hooks/index.js +2 -4
- package/dist/index.cjs +13 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +13 -0
- package/dist/partials/FieldCopyTestIdButton/index.cjs +14 -47
- package/dist/partials/FieldCopyTestIdButton/index.cjs.map +1 -1
- package/dist/partials/FieldCopyTestIdButton/index.d.cts +6 -3
- package/dist/partials/FieldCopyTestIdButton/index.d.ts +6 -3
- package/dist/partials/FieldCopyTestIdButton/index.js +29 -3
- package/dist/partials/FieldCopyTestIdButton/index.js.map +1 -1
- package/dist/partials/FieldValidationError/index.cjs +9 -56
- package/dist/partials/FieldValidationError/index.cjs.map +1 -1
- package/dist/partials/FieldValidationError/index.d.cts +10 -4
- package/dist/partials/FieldValidationError/index.d.ts +10 -4
- package/dist/partials/FieldValidationError/index.js +35 -3
- package/dist/partials/FieldValidationError/index.js.map +1 -1
- package/package.json +45 -10
- package/dist/Form/Form.cjs +0 -269
- package/dist/Form/Form.cjs.map +0 -1
- package/dist/Form/Form.js +0 -14
- package/dist/Form/subcomponents/FormContext.cjs +0 -53
- package/dist/Form/subcomponents/FormContext.cjs.map +0 -1
- package/dist/Form/subcomponents/FormContext.d.cts +0 -20
- package/dist/Form/subcomponents/FormContext.d.ts +0 -20
- package/dist/Form/subcomponents/FormContext.js +0 -9
- package/dist/Form/subcomponents/FormDebugViewer.cjs +0 -197
- package/dist/Form/subcomponents/FormDebugViewer.cjs.map +0 -1
- package/dist/Form/subcomponents/FormDebugViewer.d.cts +0 -10
- package/dist/Form/subcomponents/FormDebugViewer.d.ts +0 -10
- package/dist/Form/subcomponents/FormDebugViewer.js +0 -11
- package/dist/Form/subcomponents/FormDebugViewer.js.map +0 -1
- package/dist/Grid/Grid.cjs +0 -46
- package/dist/Grid/Grid.cjs.map +0 -1
- package/dist/Grid/Grid.js +0 -7
- package/dist/Grid/Grid.js.map +0 -1
- package/dist/SubmitButton/SubmitButton.cjs +0 -154
- package/dist/SubmitButton/SubmitButton.cjs.map +0 -1
- package/dist/SubmitButton/SubmitButton.d.cts +0 -24
- package/dist/SubmitButton/SubmitButton.d.ts +0 -24
- package/dist/SubmitButton/SubmitButton.js +0 -11
- package/dist/SubmitButton/SubmitButton.js.map +0 -1
- package/dist/chunk-AV26PIKH.js.map +0 -1
- package/dist/chunk-BJ36HK7L.js +0 -42
- package/dist/chunk-BJ36HK7L.js.map +0 -1
- package/dist/chunk-EDUZKOTL.js +0 -41
- package/dist/chunk-EDUZKOTL.js.map +0 -1
- package/dist/chunk-GATZOHQ6.js +0 -1
- package/dist/chunk-GATZOHQ6.js.map +0 -1
- package/dist/chunk-IQVKBQ7W.js +0 -19
- package/dist/chunk-IQVKBQ7W.js.map +0 -1
- package/dist/chunk-KY2KCXOO.js.map +0 -1
- package/dist/chunk-PMNBGDEZ.js.map +0 -1
- package/dist/chunk-UMTFPEVF.js +0 -34
- package/dist/chunk-UMTFPEVF.js.map +0 -1
- package/dist/chunk-WIY7KIHU.js.map +0 -1
- package/dist/chunk-X4VXTRJB.js +0 -74
- package/dist/chunk-X4VXTRJB.js.map +0 -1
- package/dist/helpers/slugify.cjs +0 -52
- package/dist/helpers/slugify.cjs.map +0 -1
- package/dist/helpers/slugify.d.cts +0 -5
- package/dist/helpers/slugify.d.ts +0 -5
- package/dist/helpers/slugify.js +0 -7
- package/dist/helpers/slugify.js.map +0 -1
- package/dist/hooks/useFormContext/useFormContext.cjs +0 -127
- package/dist/hooks/useFormContext/useFormContext.cjs.map +0 -1
- package/dist/hooks/useFormContext/useFormContext.d.cts +0 -40
- package/dist/hooks/useFormContext/useFormContext.d.ts +0 -40
- package/dist/hooks/useFormContext/useFormContext.js +0 -11
- package/dist/hooks/useFormContext/useFormContext.js.map +0 -1
- package/dist/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.cjs +0 -64
- package/dist/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.cjs.map +0 -1
- package/dist/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.d.cts +0 -9
- package/dist/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.d.ts +0 -9
- package/dist/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.js +0 -7
- package/dist/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.js.map +0 -1
- package/dist/partials/FieldValidationError/FieldValidationError.cjs +0 -87
- package/dist/partials/FieldValidationError/FieldValidationError.cjs.map +0 -1
- package/dist/partials/FieldValidationError/FieldValidationError.d.cts +0 -13
- package/dist/partials/FieldValidationError/FieldValidationError.d.ts +0 -13
- package/dist/partials/FieldValidationError/FieldValidationError.js +0 -8
- package/dist/partials/FieldValidationError/FieldValidationError.js.map +0 -1
- /package/dist/{Form/Form.js.map → helpers/index.js.map} +0 -0
- /package/dist/{Form/subcomponents/FormContext.js.map → index.js.map} +0 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkWQRM7G4Ccjs = require('./chunk-WQRM7G4C.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkBBB4FEY6cjs = require('./chunk-BBB4FEY6.cjs');
|
|
8
|
+
|
|
9
|
+
// src/Form/Form.tsx
|
|
10
|
+
var _react = require('react');
|
|
11
|
+
var _reacthookform = require('react-hook-form');
|
|
12
|
+
var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames);
|
|
13
|
+
|
|
14
|
+
// src/Form/subcomponents/FormDebugViewer.tsx
|
|
15
|
+
|
|
16
|
+
var _fa = require('react-icons/fa');
|
|
17
|
+
var _fa6 = require('react-icons/fa6');
|
|
18
|
+
|
|
19
|
+
var _Button = require('@fuf-stack/pixels/Button'); var _Button2 = _interopRequireDefault(_Button);
|
|
20
|
+
var _Card = require('@fuf-stack/pixels/Card'); var _Card2 = _interopRequireDefault(_Card);
|
|
21
|
+
var _useLocalStorage = require('@fuf-stack/pixels/hooks/useLocalStorage'); var _useLocalStorage2 = _interopRequireDefault(_useLocalStorage);
|
|
22
|
+
var _Json = require('@fuf-stack/pixels/Json'); var _Json2 = _interopRequireDefault(_Json);
|
|
23
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
24
|
+
var LOCALSTORAGE_DEBUG_KEY = "uniform:form-debug-enabled";
|
|
25
|
+
var FormDebugViewer = ({ className = void 0 }) => {
|
|
26
|
+
const {
|
|
27
|
+
watch,
|
|
28
|
+
formState: { dirtyFields, isValid, isSubmitting },
|
|
29
|
+
validation
|
|
30
|
+
} = _chunkWQRM7G4Ccjs.useFormContext.call(void 0, );
|
|
31
|
+
const [debug, setDebug] = _useLocalStorage2.default.call(void 0, LOCALSTORAGE_DEBUG_KEY, false);
|
|
32
|
+
const [validationErrors, setValidationErrors] = _react.useState.call(void 0, null);
|
|
33
|
+
const formValues = watch();
|
|
34
|
+
_react.useEffect.call(void 0, () => {
|
|
35
|
+
const updateValidationErrors = async () => {
|
|
36
|
+
if (validation) {
|
|
37
|
+
const validateResult = await _optionalChain([validation, 'optionalAccess', _ => _.validateAsync, 'call', _2 => _2(formValues)]);
|
|
38
|
+
setValidationErrors(_optionalChain([validateResult, 'optionalAccess', _3 => _3.errors]));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
updateValidationErrors();
|
|
42
|
+
}, [JSON.stringify(formValues)]);
|
|
43
|
+
if (!debug) {
|
|
44
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
45
|
+
_Button2.default,
|
|
46
|
+
{
|
|
47
|
+
ariaLabel: "Enable form debug mode",
|
|
48
|
+
onClick: () => setDebug(!debug),
|
|
49
|
+
className: "absolute bottom-2.5 right-2.5 w-5 text-default-400",
|
|
50
|
+
variant: "light",
|
|
51
|
+
icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _fa6.FaBug, {})
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
56
|
+
_Card2.default,
|
|
57
|
+
{
|
|
58
|
+
className: _classnames2.default.call(void 0, className),
|
|
59
|
+
header: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex w-full flex-row justify-between", children: [
|
|
60
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-lg", children: "Debug Mode" }),
|
|
61
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
62
|
+
_Button2.default,
|
|
63
|
+
{
|
|
64
|
+
icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _fa.FaTimes, { className: "text-danger" }),
|
|
65
|
+
onClick: () => setDebug(false),
|
|
66
|
+
size: "sm",
|
|
67
|
+
variant: "flat"
|
|
68
|
+
}
|
|
69
|
+
)
|
|
70
|
+
] }),
|
|
71
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
72
|
+
_Json2.default,
|
|
73
|
+
{
|
|
74
|
+
value: {
|
|
75
|
+
values: formValues,
|
|
76
|
+
errors: validationErrors,
|
|
77
|
+
dirtyFields,
|
|
78
|
+
isValid,
|
|
79
|
+
isSubmitting
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
var FormDebugViewer_default = FormDebugViewer;
|
|
87
|
+
|
|
88
|
+
// src/Form/Form.tsx
|
|
89
|
+
|
|
90
|
+
var removeNullishFields = (obj) => {
|
|
91
|
+
return JSON.parse(
|
|
92
|
+
JSON.stringify(obj, (_key, value) => {
|
|
93
|
+
return value === null ? void 0 : value;
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
var Form = ({
|
|
98
|
+
children,
|
|
99
|
+
className = void 0,
|
|
100
|
+
initialValues = void 0,
|
|
101
|
+
name = void 0,
|
|
102
|
+
onSubmit,
|
|
103
|
+
testId = void 0,
|
|
104
|
+
validation = void 0,
|
|
105
|
+
validationTrigger = "all"
|
|
106
|
+
}) => {
|
|
107
|
+
const methods = _reacthookform.useForm.call(void 0,
|
|
108
|
+
validation ? {
|
|
109
|
+
defaultValues: initialValues,
|
|
110
|
+
resolver: async (values) => {
|
|
111
|
+
const { data, errors, ...rest } = await validation.validateAsync(
|
|
112
|
+
removeNullishFields(values)
|
|
113
|
+
);
|
|
114
|
+
return { values: data || {}, errors: errors || {}, ...rest };
|
|
115
|
+
},
|
|
116
|
+
// set rhf mode
|
|
117
|
+
// see: https://react-hook-form.com/docs/useform#mode
|
|
118
|
+
mode: validationTrigger === "all-instant" ? "all" : validationTrigger
|
|
119
|
+
} : {
|
|
120
|
+
defaultValues: initialValues
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
_react.useEffect.call(void 0,
|
|
124
|
+
() => {
|
|
125
|
+
if (validationTrigger === "all-instant") {
|
|
126
|
+
methods.trigger();
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
130
|
+
[validationTrigger]
|
|
131
|
+
);
|
|
132
|
+
return (
|
|
133
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
134
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkWQRM7G4Ccjs.FormContext_default, { ...methods, validation, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex w-full flex-row justify-between gap-6", children: [
|
|
135
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
136
|
+
"form",
|
|
137
|
+
{
|
|
138
|
+
className: _classnames2.default.call(void 0, "flex-grow", className),
|
|
139
|
+
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0, testId || name || ""),
|
|
140
|
+
name,
|
|
141
|
+
onSubmit: methods.handleSubmit(onSubmit),
|
|
142
|
+
children
|
|
143
|
+
}
|
|
144
|
+
),
|
|
145
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, FormDebugViewer_default, { className: "w-96 flex-shrink" })
|
|
146
|
+
] }) })
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
var Form_default = Form;
|
|
150
|
+
|
|
151
|
+
// src/Form/index.ts
|
|
152
|
+
var Form_default2 = Form_default;
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
exports.Form_default = Form_default; exports.Form_default2 = Form_default2;
|
|
158
|
+
//# sourceMappingURL=chunk-II57W3V2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Form/Form.tsx","../src/Form/subcomponents/FormDebugViewer.tsx","../src/Form/index.ts"],"names":["useEffect","cn","jsx","jsxs","Form_default"],"mappings":";;;;;;;;;AAIA,SAAS,aAAAA,kBAAiB;AAC1B,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,sBAAAD;AAAA,QAAC;AAAA;AAAA,UACC,WAAWD,IAAG,aAAa,SAAS;AAAA,UACpC,eAAa,QAAQ,UAAU,QAAQ,EAAE;AAAA,UACzC;AAAA,UACA,UAAU,QAAQ,aAAa,QAAQ;AAAA,UAEtC;AAAA;AAAA,MACH;AAAA,MACA,gBAAAC,KAAC,2BAAgB,WAAU,oBAAmB;AAAA,OAChD,GACF;AAAA;AAEJ;AAEA,IAAO,eAAQ;;;AEzGf,IAAOE,gBAAQ","sourcesContent":["import type { VetoInstance } from '@fuf-stack/veto';\nimport type { ReactNode } from 'react';\nimport type { FieldValues, SubmitHandler } from 'react-hook-form';\n\nimport { useEffect } from 'react';\nimport { useForm } from 'react-hook-form';\n\nimport cn from 'classnames';\n\nimport { slugify } from '../helpers';\nimport FormProvider from './subcomponents/FormContext';\nimport FormDebugViewer from './subcomponents/FormDebugViewer';\n\n/**\n * recursively removes all fields that are null or undefined before\n * the form data is passed to the veto validation function\n */\nexport const removeNullishFields = (obj: Record<string, unknown>) => {\n return JSON.parse(\n JSON.stringify(obj, (_key, value) => {\n return value === null ? undefined : value;\n }),\n );\n};\n\nexport interface FormProps {\n /** form children */\n children: ReactNode | ReactNode[];\n /** CSS class name */\n className?: string | string[];\n /** initial form values */\n initialValues?: FieldValues;\n /** name of the form */\n name?: string;\n /** form submit handler */\n onSubmit: SubmitHandler<FieldValues>;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** veto validation schema */\n validation?: VetoInstance;\n /** when the validation should be triggered */\n validationTrigger?:\n | 'onChange'\n | 'onBlur'\n | 'onSubmit'\n | 'onTouched'\n | 'all'\n | 'all-instant';\n}\n\n/**\n * Form component that has to wrap every uniform\n */\nconst Form = ({\n children,\n className = undefined,\n initialValues = undefined,\n name = undefined,\n onSubmit,\n testId = undefined,\n validation = undefined,\n validationTrigger = 'all',\n}: FormProps) => {\n const methods = useForm(\n validation\n ? {\n defaultValues: initialValues,\n resolver: async (values) => {\n const { data, errors, ...rest } = await validation.validateAsync(\n removeNullishFields(values),\n );\n // https://github.com/react-hook-form/resolvers/blob/master/zod/src/zod.ts\n return { values: data || {}, errors: errors || {}, ...rest };\n },\n // set rhf mode\n // see: https://react-hook-form.com/docs/useform#mode\n mode: validationTrigger === 'all-instant' ? 'all' : validationTrigger,\n }\n : {\n defaultValues: initialValues,\n },\n );\n\n useEffect(\n () => {\n if (validationTrigger === 'all-instant') {\n methods.trigger();\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [validationTrigger],\n );\n\n return (\n // eslint-disable-next-line react/jsx-props-no-spreading\n <FormProvider {...methods} validation={validation}>\n <div className=\"flex w-full flex-row justify-between gap-6\">\n <form\n className={cn('flex-grow', className)}\n data-testid={slugify(testId || name || '')}\n name={name}\n onSubmit={methods.handleSubmit(onSubmit)}\n >\n {children}\n </form>\n <FormDebugViewer className=\"w-96 flex-shrink\" />\n </div>\n </FormProvider>\n );\n};\n\nexport default Form;\n","import type { VetoError } from '@fuf-stack/veto';\n\nimport { useEffect, useState } from 'react';\nimport { FaTimes } from 'react-icons/fa';\nimport { FaBug } from 'react-icons/fa6';\n\nimport cn from 'classnames';\n\nimport Button from '@fuf-stack/pixels/Button';\nimport Card from '@fuf-stack/pixels/Card';\nimport useLocalStorage from '@fuf-stack/pixels/hooks/useLocalStorage';\nimport Json from '@fuf-stack/pixels/Json';\n\nimport { useFormContext } from '../../hooks';\n\ninterface FormDebugViewerProps {\n /** CSS class name */\n className?: string;\n}\n\nconst LOCALSTORAGE_DEBUG_KEY = 'uniform:form-debug-enabled';\n\n/** Renders a form debug panel with information about the current form state */\nconst FormDebugViewer = ({ className = undefined }: FormDebugViewerProps) => {\n const {\n watch,\n formState: { dirtyFields, isValid, isSubmitting },\n validation,\n } = useFormContext();\n\n const [debug, setDebug] = useLocalStorage(LOCALSTORAGE_DEBUG_KEY, false);\n\n const [validationErrors, setValidationErrors] = useState<\n VetoError['errors'] | null\n >(null);\n\n const formValues = watch();\n\n useEffect(() => {\n const updateValidationErrors = async () => {\n if (validation) {\n const validateResult = await validation?.validateAsync(formValues);\n setValidationErrors(validateResult?.errors);\n }\n };\n updateValidationErrors();\n }, [JSON.stringify(formValues)]);\n\n if (!debug) {\n return (\n <Button\n ariaLabel=\"Enable form debug mode\"\n onClick={() => setDebug(!debug)}\n className=\"absolute bottom-2.5 right-2.5 w-5 text-default-400\"\n variant=\"light\"\n icon={<FaBug />}\n />\n );\n }\n\n return (\n <Card\n className={cn(className)}\n header={\n <div className=\"flex w-full flex-row justify-between\">\n <span className=\"text-lg\">Debug Mode</span>\n <Button\n icon={<FaTimes className=\"text-danger\" />}\n onClick={() => setDebug(false)}\n size=\"sm\"\n variant=\"flat\"\n />\n </div>\n }\n >\n <Json\n value={{\n values: formValues,\n errors: validationErrors,\n dirtyFields,\n isValid,\n isSubmitting,\n }}\n />\n </Card>\n );\n};\nexport default FormDebugViewer;\n","import Form from './Form';\n\nexport type { FormProps } from './Form';\n\nexport { Form };\n\nexport default Form;\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// src/helpers/slugify.ts
|
|
1
|
+
// src/helpers/slugify/slugify.ts
|
|
2
2
|
import slug from "slug";
|
|
3
|
-
var
|
|
3
|
+
var slugify = (string, options) => {
|
|
4
4
|
const replacement = options?.replacement || "_";
|
|
5
5
|
return slug(string, {
|
|
6
6
|
...slug.defaults.modes.rfc3986,
|
|
@@ -17,6 +17,6 @@ var slugify_default = (string, options) => {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
export {
|
|
20
|
-
|
|
20
|
+
slugify
|
|
21
21
|
};
|
|
22
|
-
//# sourceMappingURL=chunk-
|
|
22
|
+
//# sourceMappingURL=chunk-V46BHM2U.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers/slugify/slugify.ts"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\n\nimport type { Options as SlugOptions } from 'slug';\n\nimport slug from 'slug';\n\nexport const slugify = (string: string, options?: SlugOptions) => {\n const replacement = options?.replacement || '_';\n return slug(string, {\n ...slug.defaults.modes.rfc3986,\n charmap: {\n ...slug.defaults.modes.rfc3986.charmap,\n // allow dots by default\n '.': '.',\n // convert hyphens to underscores (when replacement is not hyphen)\n ...(replacement !== '-' ? { '-': '_' } : {}),\n },\n replacement,\n ...(options || {}),\n });\n};\n"],"mappings":";AAIA,OAAO,UAAU;AAEV,IAAM,UAAU,CAAC,QAAgB,YAA0B;AAChE,QAAM,cAAc,SAAS,eAAe;AAC5C,SAAO,KAAK,QAAQ;AAAA,IAClB,GAAG,KAAK,SAAS,MAAM;AAAA,IACvB,SAAS;AAAA,MACP,GAAG,KAAK,SAAS,MAAM,QAAQ;AAAA;AAAA,MAE/B,KAAK;AAAA;AAAA,MAEL,GAAI,gBAAgB,MAAM,EAAE,KAAK,IAAI,IAAI,CAAC;AAAA,IAC5C;AAAA,IACA;AAAA,IACA,GAAI,WAAW,CAAC;AAAA,EAClB,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkBBB4FEY6cjs = require('./chunk-BBB4FEY6.cjs');
|
|
4
|
+
|
|
5
|
+
// src/hooks/useFormContext/useFormContext.ts
|
|
6
|
+
var _react = require('react'); var _react2 = _interopRequireDefault(_react);
|
|
7
|
+
var _reacthookform = require('react-hook-form');
|
|
8
|
+
|
|
9
|
+
// src/Form/subcomponents/FormContext.tsx
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
13
|
+
var ValidationSchemaContext = _react2.default.createContext(void 0);
|
|
14
|
+
var FormProvider = ({
|
|
15
|
+
children,
|
|
16
|
+
validation = void 0,
|
|
17
|
+
...hookFormProps
|
|
18
|
+
}) => {
|
|
19
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ValidationSchemaContext.Provider, { value: validation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacthookform.FormProvider, { ...hookFormProps, children }) });
|
|
20
|
+
};
|
|
21
|
+
var FormContext_default = FormProvider;
|
|
22
|
+
|
|
23
|
+
// src/hooks/useFormContext/useFormContext.ts
|
|
24
|
+
var recursiveSearchInnerType = (schema) => {
|
|
25
|
+
if (_optionalChain([schema, 'optionalAccess', _ => _._def, 'optionalAccess', _2 => _2.innerType])) {
|
|
26
|
+
if (_optionalChain([schema, 'optionalAccess', _3 => _3._def, 'optionalAccess', _4 => _4.innerType, 'optionalAccess', _5 => _5._def, 'optionalAccess', _6 => _6.typeName]) === "ZodOptional") {
|
|
27
|
+
return _optionalChain([schema, 'optionalAccess', _7 => _7._def, 'optionalAccess', _8 => _8.innerType, 'optionalAccess', _9 => _9._def, 'optionalAccess', _10 => _10.typeName]) !== "ZodOptional";
|
|
28
|
+
}
|
|
29
|
+
return recursiveSearchInnerType(_optionalChain([schema, 'optionalAccess', _11 => _11._def, 'optionalAccess', _12 => _12.innerType]));
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
};
|
|
33
|
+
var recursiveFieldKeySearch = (schema, path) => {
|
|
34
|
+
const [current, ...rest] = path;
|
|
35
|
+
let currentSchema = schema;
|
|
36
|
+
if (_optionalChain([schema, 'optionalAccess', _13 => _13._def, 'optionalAccess', _14 => _14.typeName]) === "ZodOptional") {
|
|
37
|
+
currentSchema = schema.unwrap();
|
|
38
|
+
} else if (_optionalChain([schema, 'optionalAccess', _15 => _15._def, 'optionalAccess', _16 => _16.typeName]) === "ZodEffects") {
|
|
39
|
+
return recursiveFieldKeySearch(_optionalChain([schema, 'access', _17 => _17._def, 'optionalAccess', _18 => _18.schema]), path);
|
|
40
|
+
}
|
|
41
|
+
if (_optionalChain([currentSchema, 'optionalAccess', _19 => _19._def, 'optionalAccess', _20 => _20.typeName]) === "ZodIntersection") {
|
|
42
|
+
return (_optionalChain([currentSchema, 'access', _21 => _21._def, 'access', _22 => _22.left, 'optionalAccess', _23 => _23.schema]) ? recursiveFieldKeySearch(currentSchema._def.left.schema, path) : recursiveFieldKeySearch(currentSchema._def.left, path)) || (_optionalChain([currentSchema, 'access', _24 => _24._def, 'access', _25 => _25.right, 'optionalAccess', _26 => _26.schema]) ? recursiveFieldKeySearch(currentSchema._def.right.schema, path) : recursiveFieldKeySearch(currentSchema._def.right, path));
|
|
43
|
+
}
|
|
44
|
+
const shape = _nullishCoalesce(_optionalChain([currentSchema, 'optionalAccess', _27 => _27.shape]), () => ( _optionalChain([currentSchema, 'optionalAccess', _28 => _28.element, 'optionalAccess', _29 => _29.shape])));
|
|
45
|
+
if (shape && shape[current]) {
|
|
46
|
+
if (rest.length === 0) {
|
|
47
|
+
return _optionalChain([shape, 'access', _30 => _30[current], 'optionalAccess', _31 => _31._def, 'optionalAccess', _32 => _32.typeName]) !== "ZodOptional" && recursiveSearchInnerType(shape[current]);
|
|
48
|
+
}
|
|
49
|
+
return recursiveFieldKeySearch(shape[current], rest);
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
};
|
|
53
|
+
var useFormContext = () => {
|
|
54
|
+
const {
|
|
55
|
+
// https://react-hook-form.com/docs/useform/getfieldstate
|
|
56
|
+
// for getFieldState a subscription to formState properties is needed!
|
|
57
|
+
formState,
|
|
58
|
+
getFieldState: getFieldStateOrig,
|
|
59
|
+
...otherMethods
|
|
60
|
+
} = _reacthookform.useFormContext.call(void 0, );
|
|
61
|
+
const validation = _react.useContext.call(void 0, ValidationSchemaContext);
|
|
62
|
+
const getFieldState = (name, testId) => {
|
|
63
|
+
const fieldPath = typeof name === "string" ? name.replace(/\[\d+\]/g, "").split(".") : name;
|
|
64
|
+
const required = validation && recursiveFieldKeySearch(validation.schema, fieldPath) || false;
|
|
65
|
+
const { error, ...rest } = getFieldStateOrig(name, formState);
|
|
66
|
+
return {
|
|
67
|
+
...rest,
|
|
68
|
+
error,
|
|
69
|
+
// TODO: change to correct type @Hannes ;)
|
|
70
|
+
required,
|
|
71
|
+
testId: _chunkBBB4FEY6cjs.slugify.call(void 0, testId || name)
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
...otherMethods,
|
|
76
|
+
getFieldState,
|
|
77
|
+
validation,
|
|
78
|
+
formState
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
exports.FormContext_default = FormContext_default; exports.recursiveFieldKeySearch = recursiveFieldKeySearch; exports.useFormContext = useFormContext;
|
|
87
|
+
//# sourceMappingURL=chunk-WQRM7G4C.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useFormContext/useFormContext.ts","../src/Form/subcomponents/FormContext.tsx"],"names":[],"mappings":";;;;;AAGA,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB,0BAA0B;;;ACDrD,OAAO,WAAW;AAClB,SAAS,gBAAgB,wBAAwB;AAoB3C;AAlBC,IAAM,0BAA0B,MAAM,cAE3C,MAAS;AASX,IAAM,eAAe,CAAC;AAAA,EACpB;AAAA,EACA,aAAa;AAAA,EACb,GAAG;AACL,MAAyB;AACvB,SACE,oBAAC,wBAAwB,UAAxB,EAAiC,OAAO,YACvC,8BAAC,oBAAkB,GAAG,eAAgB,UAAS,GACjD;AAEJ;AAEA,I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D,QAAM,gBAAgB,CAAC,MAAc,WAAoB;AACvD,UAAM,YACJ,OAAO,SAAS,WAAW,KAAK,QAAQ,YAAY,EAAE,EAAE,MAAM,GAAG,IAAI;AACvE,UAAM,WACH,cAAc,wBAAwB,WAAW,QAAQ,SAAS,KACnE;AACF,UAAM,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,MAAM,SAAS;AAC5D,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA;AAAA,MACA;AAAA,MACA,QAAQ,QAAQ,UAAU,IAAI;AAAA,IAChC;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF","sourcesContent":["import type { VetoSchema } from '@fuf-stack/veto';\nimport type { FieldError } from 'react-hook-form';\n\nimport { useContext } from 'react';\nimport { useFormContext as useHookFormContext } from 'react-hook-form';\n\nimport { ValidationSchemaContext } from '../../Form/subcomponents/FormContext';\nimport { slugify } from '../../helpers';\n\n// FIX: This fixes the problem that the innerType is not checked for optionals...\nconst recursiveSearchInnerType = (schema: VetoSchema): boolean => {\n if (schema?._def?.innerType) {\n if (schema?._def?.innerType?._def?.typeName === 'ZodOptional') {\n return schema?._def?.innerType?._def?.typeName !== 'ZodOptional';\n }\n return recursiveSearchInnerType(schema?._def?.innerType);\n }\n return true;\n};\n\n// TODO: Fix problem \".optional().nullable()\" is required, \".nullable().optional()\" is not required...\nexport const recursiveFieldKeySearch = (\n schema: VetoSchema,\n path: string[],\n): boolean | null => {\n const [current, ...rest] = path;\n // ignore optionals on the path to the desired field\n\n let currentSchema = schema;\n\n if (schema?._def?.typeName === 'ZodOptional') {\n // @ts-expect-error not sure here\n currentSchema = schema.unwrap();\n } else if (schema?._def?.typeName === 'ZodEffects') {\n // in case of an effect, unwrap the effect and call with schema (clould be optional) and complete path.\n return recursiveFieldKeySearch(schema._def?.schema, path);\n }\n\n // TODO: This needs further investigation. It is nor yet completely clear how to handle intersections!\n if (currentSchema?._def?.typeName === 'ZodIntersection') {\n return (\n (currentSchema._def.left?.schema\n ? recursiveFieldKeySearch(currentSchema._def.left.schema, path)\n : recursiveFieldKeySearch(currentSchema._def.left, path)) ||\n (currentSchema._def.right?.schema\n ? recursiveFieldKeySearch(currentSchema._def.right.schema, path)\n : recursiveFieldKeySearch(currentSchema._def.right, path))\n );\n }\n\n // get shape of an object or objects of an array\n // @ts-expect-error not sure here\n const shape = currentSchema?.shape ?? currentSchema?.element?.shape; // ??\n\n if (shape && shape[current]) {\n // currentSchema?._def.schema.unwrap()?.shape;\n if (rest.length === 0) {\n // At the end of the path check if the field is optional or required\n return (\n shape[current]?._def?.typeName !== 'ZodOptional' &&\n recursiveSearchInnerType(shape[current])\n );\n }\n return recursiveFieldKeySearch(shape[current], rest);\n }\n\n return null; // field not found\n};\n\n/** TODO: add description */\nexport const useFormContext = () => {\n const {\n // https://react-hook-form.com/docs/useform/getfieldstate\n // for getFieldState a subscription to formState properties is needed!\n formState,\n getFieldState: getFieldStateOrig,\n ...otherMethods\n } = useHookFormContext();\n const validation = useContext(ValidationSchemaContext);\n\n // update getFieldState\n const getFieldState = (name: string, testId?: string) => {\n const fieldPath =\n typeof name === 'string' ? name.replace(/\\[\\d+\\]/g, '').split('.') : name;\n const required =\n (validation && recursiveFieldKeySearch(validation.schema, fieldPath)) ||\n false;\n const { error, ...rest } = getFieldStateOrig(name, formState);\n return {\n ...rest,\n error: error as FieldError[] | undefined, // TODO: change to correct type @Hannes ;)\n required,\n testId: slugify(testId || name),\n };\n };\n\n return {\n ...otherMethods,\n getFieldState,\n validation,\n formState,\n };\n};\n","import type { VetoInstance } from '@fuf-stack/veto';\nimport type { FormProviderProps as HookFormProviderProps } from 'react-hook-form';\n\nimport React from 'react';\nimport { FormProvider as HookFormProvider } from 'react-hook-form';\n\nexport const ValidationSchemaContext = React.createContext<\n VetoInstance | undefined\n>(undefined);\n\ninterface FormProviderProps\n extends HookFormProviderProps<Record<string, any>, any, undefined> {\n /** veto validation schema */\n validation?: VetoInstance;\n}\n\n/** Provides the veto validation context to the form */\nconst FormProvider = ({\n children,\n validation = undefined,\n ...hookFormProps\n}: FormProviderProps) => {\n return (\n <ValidationSchemaContext.Provider value={validation}>\n <HookFormProvider {...hookFormProps}>{children}</HookFormProvider>\n </ValidationSchemaContext.Provider>\n );\n};\n\nexport default FormProvider;\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/Grid/Grid.tsx
|
|
2
|
+
var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames);
|
|
3
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
4
|
+
var Grid = ({
|
|
5
|
+
children = null,
|
|
6
|
+
className = void 0,
|
|
7
|
+
testId = void 0
|
|
8
|
+
}) => {
|
|
9
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: _classnames2.default.call(void 0, "grid gap-6", className), "data-testid": testId, children });
|
|
10
|
+
};
|
|
11
|
+
var Grid_default = Grid;
|
|
12
|
+
|
|
13
|
+
// src/Grid/index.ts
|
|
14
|
+
var Grid_default2 = Grid_default;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
exports.Grid_default = Grid_default; exports.Grid_default2 = Grid_default2;
|
|
20
|
+
//# sourceMappingURL=chunk-ZPFKVKGV.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Grid/Grid.tsx","../src/Grid/index.ts"],"names":["Grid_default"],"mappings":";AAEA,OAAO,QAAQ;AAoBX;AANJ,IAAM,OAAO,CAAC;AAAA,EACZ,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,SAAS;AACX,MAAiB;AACf,SACE,oBAAC,SAAI,WAAW,GAAG,cAAc,SAAS,GAAG,eAAa,QACvD,UACH;AAEJ;AAEA,IAAO,eAAQ;;;ACtBf,IAAOA,gBAAQ","sourcesContent":["import type { ReactNode } from 'react';\n\nimport cn from 'classnames';\n\nexport interface GridProps {\n /** child components */\n children?: ReactNode;\n /** CSS class name */\n className?: string;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n}\n\n/**\n * Defines the default grid for form components\n */\nconst Grid = ({\n children = null,\n className = undefined,\n testId = undefined,\n}: GridProps) => {\n return (\n <div className={cn('grid gap-6', className)} data-testid={testId}>\n {children}\n </div>\n );\n};\n\nexport default Grid;\n","import Grid from './Grid';\n\nexport type { GridProps } from './Grid';\n\nexport { Grid };\n\nexport default Grid;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/hooks/index.cjs
CHANGED
|
@@ -1,129 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
29
2
|
|
|
30
|
-
// src/hooks/index.ts
|
|
31
|
-
var hooks_exports = {};
|
|
32
|
-
__export(hooks_exports, {
|
|
33
|
-
recursiveFieldKeySearch: () => recursiveFieldKeySearch,
|
|
34
|
-
useFormContext: () => useFormContext
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(hooks_exports);
|
|
37
3
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var import_react_hook_form2 = require("react-hook-form");
|
|
4
|
+
var _chunkWQRM7G4Ccjs = require('../chunk-WQRM7G4C.cjs');
|
|
5
|
+
require('../chunk-BBB4FEY6.cjs');
|
|
41
6
|
|
|
42
|
-
// src/Form/subcomponents/FormContext.tsx
|
|
43
|
-
var import_react = __toESM(require("react"), 1);
|
|
44
|
-
var import_react_hook_form = require("react-hook-form");
|
|
45
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
46
|
-
var ValidationSchemaContext = import_react.default.createContext(void 0);
|
|
47
7
|
|
|
48
|
-
// src/helpers/slugify.ts
|
|
49
|
-
var import_slug = __toESM(require("slug"), 1);
|
|
50
|
-
var slugify_default = (string, options) => {
|
|
51
|
-
const replacement = options?.replacement || "_";
|
|
52
|
-
return (0, import_slug.default)(string, {
|
|
53
|
-
...import_slug.default.defaults.modes.rfc3986,
|
|
54
|
-
charmap: {
|
|
55
|
-
...import_slug.default.defaults.modes.rfc3986.charmap,
|
|
56
|
-
// allow dots by default
|
|
57
|
-
".": ".",
|
|
58
|
-
// convert hyphens to underscores (when replacement is not hyphen)
|
|
59
|
-
...replacement !== "-" ? { "-": "_" } : {}
|
|
60
|
-
},
|
|
61
|
-
replacement,
|
|
62
|
-
...options || {}
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
8
|
|
|
66
|
-
|
|
67
|
-
var recursiveSearchInnerType = (schema) => {
|
|
68
|
-
if (schema?._def?.innerType) {
|
|
69
|
-
if (schema?._def?.innerType?._def?.typeName === "ZodOptional") {
|
|
70
|
-
return schema?._def?.innerType?._def?.typeName !== "ZodOptional";
|
|
71
|
-
}
|
|
72
|
-
return recursiveSearchInnerType(schema?._def?.innerType);
|
|
73
|
-
}
|
|
74
|
-
return true;
|
|
75
|
-
};
|
|
76
|
-
var recursiveFieldKeySearch = (schema, path) => {
|
|
77
|
-
const [current, ...rest] = path;
|
|
78
|
-
let currentSchema = schema;
|
|
79
|
-
if (schema?._def?.typeName === "ZodOptional") {
|
|
80
|
-
currentSchema = schema.unwrap();
|
|
81
|
-
} else if (schema?._def?.typeName === "ZodEffects") {
|
|
82
|
-
return recursiveFieldKeySearch(schema._def?.schema, path);
|
|
83
|
-
}
|
|
84
|
-
if (currentSchema?._def?.typeName === "ZodIntersection") {
|
|
85
|
-
return (currentSchema._def.left?.schema ? recursiveFieldKeySearch(currentSchema._def.left.schema, path) : recursiveFieldKeySearch(currentSchema._def.left, path)) || (currentSchema._def.right?.schema ? recursiveFieldKeySearch(currentSchema._def.right.schema, path) : recursiveFieldKeySearch(currentSchema._def.right, path));
|
|
86
|
-
}
|
|
87
|
-
const shape = currentSchema?.shape ?? currentSchema?.element?.shape;
|
|
88
|
-
if (shape && shape[current]) {
|
|
89
|
-
if (rest.length === 0) {
|
|
90
|
-
return shape[current]?._def?.typeName !== "ZodOptional" && recursiveSearchInnerType(shape[current]);
|
|
91
|
-
}
|
|
92
|
-
return recursiveFieldKeySearch(shape[current], rest);
|
|
93
|
-
}
|
|
94
|
-
return null;
|
|
95
|
-
};
|
|
96
|
-
var useFormContext = () => {
|
|
97
|
-
const {
|
|
98
|
-
// https://react-hook-form.com/docs/useform/getfieldstate
|
|
99
|
-
// for getFieldState a subscription to formState properties is needed!
|
|
100
|
-
formState,
|
|
101
|
-
getFieldState: getFieldStateOrig,
|
|
102
|
-
...otherMethods
|
|
103
|
-
} = (0, import_react_hook_form2.useFormContext)();
|
|
104
|
-
const validation = (0, import_react2.useContext)(ValidationSchemaContext);
|
|
105
|
-
const getFieldState = (name, testId) => {
|
|
106
|
-
const fieldPath = typeof name === "string" ? name.replace(/\[\d+\]/g, "").split(".") : name;
|
|
107
|
-
const required = validation && recursiveFieldKeySearch(validation.schema, fieldPath) || false;
|
|
108
|
-
const { error, ...rest } = getFieldStateOrig(name, formState);
|
|
109
|
-
return {
|
|
110
|
-
...rest,
|
|
111
|
-
error,
|
|
112
|
-
// TODO: change to correct type @Hannes ;)
|
|
113
|
-
required,
|
|
114
|
-
testId: slugify_default(testId || name)
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
return {
|
|
118
|
-
...otherMethods,
|
|
119
|
-
getFieldState,
|
|
120
|
-
validation,
|
|
121
|
-
formState
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
125
|
-
0 && (module.exports = {
|
|
126
|
-
recursiveFieldKeySearch,
|
|
127
|
-
useFormContext
|
|
128
|
-
});
|
|
9
|
+
exports.recursiveFieldKeySearch = _chunkWQRM7G4Ccjs.recursiveFieldKeySearch; exports.useFormContext = _chunkWQRM7G4Ccjs.useFormContext;
|
|
129
10
|
//# sourceMappingURL=index.cjs.map
|
package/dist/hooks/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/hooks/index.d.cts
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
import 'react-hook-form';
|
|
3
|
-
import '@fuf-stack/veto';
|
|
4
|
-
import '
|
|
1
|
+
import * as react_hook_form from 'react-hook-form';
|
|
2
|
+
import { FieldError } from 'react-hook-form';
|
|
3
|
+
import * as _fuf_stack_veto from '@fuf-stack/veto';
|
|
4
|
+
import { VetoSchema } from '@fuf-stack/veto';
|
|
5
|
+
import * as zod from 'zod';
|
|
6
|
+
|
|
7
|
+
declare const recursiveFieldKeySearch: (schema: VetoSchema, path: string[]) => boolean | null;
|
|
8
|
+
/** TODO: add description */
|
|
9
|
+
declare const useFormContext: () => {
|
|
10
|
+
getFieldState: (name: string, testId?: string) => {
|
|
11
|
+
error: FieldError[] | undefined;
|
|
12
|
+
required: boolean;
|
|
13
|
+
testId: string;
|
|
14
|
+
invalid: boolean;
|
|
15
|
+
isDirty: boolean;
|
|
16
|
+
isTouched: boolean;
|
|
17
|
+
isValidating: boolean;
|
|
18
|
+
};
|
|
19
|
+
validation: {
|
|
20
|
+
schema: zod.ZodTypeAny;
|
|
21
|
+
validate: <InputType extends _fuf_stack_veto.VetoInput>(input: InputType) => _fuf_stack_veto.VetoError | _fuf_stack_veto.VetoSuccess<any>;
|
|
22
|
+
validateAsync: <InputType_1 extends _fuf_stack_veto.VetoInput>(input: InputType_1) => Promise<_fuf_stack_veto.VetoError | _fuf_stack_veto.VetoSuccess<any>>;
|
|
23
|
+
} | undefined;
|
|
24
|
+
formState: react_hook_form.FormState<react_hook_form.FieldValues>;
|
|
25
|
+
watch: react_hook_form.UseFormWatch<react_hook_form.FieldValues>;
|
|
26
|
+
getValues: react_hook_form.UseFormGetValues<react_hook_form.FieldValues>;
|
|
27
|
+
setError: react_hook_form.UseFormSetError<react_hook_form.FieldValues>;
|
|
28
|
+
clearErrors: react_hook_form.UseFormClearErrors<react_hook_form.FieldValues>;
|
|
29
|
+
setValue: react_hook_form.UseFormSetValue<react_hook_form.FieldValues>;
|
|
30
|
+
trigger: react_hook_form.UseFormTrigger<react_hook_form.FieldValues>;
|
|
31
|
+
resetField: react_hook_form.UseFormResetField<react_hook_form.FieldValues>;
|
|
32
|
+
reset: react_hook_form.UseFormReset<react_hook_form.FieldValues>;
|
|
33
|
+
handleSubmit: react_hook_form.UseFormHandleSubmit<react_hook_form.FieldValues, undefined>;
|
|
34
|
+
unregister: react_hook_form.UseFormUnregister<react_hook_form.FieldValues>;
|
|
35
|
+
control: react_hook_form.Control<react_hook_form.FieldValues, any>;
|
|
36
|
+
register: react_hook_form.UseFormRegister<react_hook_form.FieldValues>;
|
|
37
|
+
setFocus: react_hook_form.UseFormSetFocus<react_hook_form.FieldValues>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { recursiveFieldKeySearch, useFormContext };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
import 'react-hook-form';
|
|
3
|
-
import '@fuf-stack/veto';
|
|
4
|
-
import '
|
|
1
|
+
import * as react_hook_form from 'react-hook-form';
|
|
2
|
+
import { FieldError } from 'react-hook-form';
|
|
3
|
+
import * as _fuf_stack_veto from '@fuf-stack/veto';
|
|
4
|
+
import { VetoSchema } from '@fuf-stack/veto';
|
|
5
|
+
import * as zod from 'zod';
|
|
6
|
+
|
|
7
|
+
declare const recursiveFieldKeySearch: (schema: VetoSchema, path: string[]) => boolean | null;
|
|
8
|
+
/** TODO: add description */
|
|
9
|
+
declare const useFormContext: () => {
|
|
10
|
+
getFieldState: (name: string, testId?: string) => {
|
|
11
|
+
error: FieldError[] | undefined;
|
|
12
|
+
required: boolean;
|
|
13
|
+
testId: string;
|
|
14
|
+
invalid: boolean;
|
|
15
|
+
isDirty: boolean;
|
|
16
|
+
isTouched: boolean;
|
|
17
|
+
isValidating: boolean;
|
|
18
|
+
};
|
|
19
|
+
validation: {
|
|
20
|
+
schema: zod.ZodTypeAny;
|
|
21
|
+
validate: <InputType extends _fuf_stack_veto.VetoInput>(input: InputType) => _fuf_stack_veto.VetoError | _fuf_stack_veto.VetoSuccess<any>;
|
|
22
|
+
validateAsync: <InputType_1 extends _fuf_stack_veto.VetoInput>(input: InputType_1) => Promise<_fuf_stack_veto.VetoError | _fuf_stack_veto.VetoSuccess<any>>;
|
|
23
|
+
} | undefined;
|
|
24
|
+
formState: react_hook_form.FormState<react_hook_form.FieldValues>;
|
|
25
|
+
watch: react_hook_form.UseFormWatch<react_hook_form.FieldValues>;
|
|
26
|
+
getValues: react_hook_form.UseFormGetValues<react_hook_form.FieldValues>;
|
|
27
|
+
setError: react_hook_form.UseFormSetError<react_hook_form.FieldValues>;
|
|
28
|
+
clearErrors: react_hook_form.UseFormClearErrors<react_hook_form.FieldValues>;
|
|
29
|
+
setValue: react_hook_form.UseFormSetValue<react_hook_form.FieldValues>;
|
|
30
|
+
trigger: react_hook_form.UseFormTrigger<react_hook_form.FieldValues>;
|
|
31
|
+
resetField: react_hook_form.UseFormResetField<react_hook_form.FieldValues>;
|
|
32
|
+
reset: react_hook_form.UseFormReset<react_hook_form.FieldValues>;
|
|
33
|
+
handleSubmit: react_hook_form.UseFormHandleSubmit<react_hook_form.FieldValues, undefined>;
|
|
34
|
+
unregister: react_hook_form.UseFormUnregister<react_hook_form.FieldValues>;
|
|
35
|
+
control: react_hook_form.Control<react_hook_form.FieldValues, any>;
|
|
36
|
+
register: react_hook_form.UseFormRegister<react_hook_form.FieldValues>;
|
|
37
|
+
setFocus: react_hook_form.UseFormSetFocus<react_hook_form.FieldValues>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { recursiveFieldKeySearch, useFormContext };
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import "../chunk-GATZOHQ6.js";
|
|
2
1
|
import {
|
|
3
2
|
recursiveFieldKeySearch,
|
|
4
3
|
useFormContext
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-WIY7KIHU.js";
|
|
4
|
+
} from "../chunk-BCMPSLSG.js";
|
|
5
|
+
import "../chunk-V46BHM2U.js";
|
|
8
6
|
export {
|
|
9
7
|
recursiveFieldKeySearch,
|
|
10
8
|
useFormContext
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkII57W3V2cjs = require('./chunk-II57W3V2.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkZPFKVKGVcjs = require('./chunk-ZPFKVKGV.cjs');
|
|
7
|
+
require('./chunk-WQRM7G4C.cjs');
|
|
8
|
+
require('./chunk-BBB4FEY6.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.Form = _chunkII57W3V2cjs.Form_default; exports.Grid = _chunkZPFKVKGVcjs.Grid_default;
|
|
13
|
+
//# sourceMappingURL=index.cjs.map
|