@fuf-stack/uniform 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CheckboxGroup/index.cjs +4 -4
- package/dist/CheckboxGroup/index.js +3 -3
- package/dist/FieldArray/index.cjs +4 -4
- package/dist/FieldArray/index.js +3 -3
- package/dist/Form/index.cjs +3 -3
- package/dist/Form/index.js +2 -2
- package/dist/Input/index.cjs +4 -4
- package/dist/Input/index.js +3 -3
- package/dist/RadioGroup/index.cjs +4 -4
- package/dist/RadioGroup/index.js +3 -3
- package/dist/Select/index.cjs +4 -4
- package/dist/Select/index.js +3 -3
- package/dist/SubmitButton/index.cjs +3 -3
- package/dist/SubmitButton/index.js +2 -2
- package/dist/Switch/index.cjs +4 -4
- package/dist/Switch/index.js +3 -3
- package/dist/TextArea/index.cjs +4 -4
- package/dist/TextArea/index.js +3 -3
- package/dist/chunk-B24NXJTR.js +129 -0
- package/dist/chunk-B24NXJTR.js.map +1 -0
- package/dist/{chunk-6NDSWWW7.cjs → chunk-DZPPA4BG.cjs} +5 -5
- package/dist/{chunk-6NDSWWW7.cjs.map → chunk-DZPPA4BG.cjs.map} +1 -1
- package/dist/{chunk-VXVDNHDV.cjs → chunk-ENVGJAWA.cjs} +5 -5
- package/dist/{chunk-VXVDNHDV.cjs.map → chunk-ENVGJAWA.cjs.map} +1 -1
- package/dist/{chunk-36F7BWKL.js → chunk-FYP5BTHS.js} +5 -5
- package/dist/{chunk-OFKYZAVG.cjs → chunk-J23BIH72.cjs} +5 -5
- package/dist/{chunk-OFKYZAVG.cjs.map → chunk-J23BIH72.cjs.map} +1 -1
- package/dist/{chunk-2BQWUW2F.cjs → chunk-JI7GA5XH.cjs} +5 -5
- package/dist/{chunk-2BQWUW2F.cjs.map → chunk-JI7GA5XH.cjs.map} +1 -1
- package/dist/{chunk-LIKSUWSM.js → chunk-OD5BASYZ.js} +5 -5
- package/dist/chunk-OL5DXVY4.cjs +129 -0
- package/dist/chunk-OL5DXVY4.cjs.map +1 -0
- package/dist/{chunk-UDRSTJBU.js → chunk-PDXVHUGH.js} +5 -5
- package/dist/{chunk-MV4JFCOJ.cjs → chunk-QP7FUODS.cjs} +5 -5
- package/dist/{chunk-MV4JFCOJ.cjs.map → chunk-QP7FUODS.cjs.map} +1 -1
- package/dist/{chunk-R7XP72I5.js → chunk-RULU2SJ5.js} +5 -5
- package/dist/{chunk-QD6IQL6U.js → chunk-TN6ZHEXV.js} +2 -2
- package/dist/{chunk-KGHLS6DM.js → chunk-UIVSMVUT.js} +5 -5
- package/dist/{chunk-G7FQPNDQ.cjs → chunk-VGJQLCH3.cjs} +5 -5
- package/dist/{chunk-G7FQPNDQ.cjs.map → chunk-VGJQLCH3.cjs.map} +1 -1
- package/dist/{chunk-XJ3JTLXZ.cjs → chunk-VN4U7FEE.cjs} +3 -3
- package/dist/{chunk-XJ3JTLXZ.cjs.map → chunk-VN4U7FEE.cjs.map} +1 -1
- package/dist/{chunk-ZVBX5EKB.cjs → chunk-WR2PNNMP.cjs} +6 -6
- package/dist/{chunk-ZVBX5EKB.cjs.map → chunk-WR2PNNMP.cjs.map} +1 -1
- package/dist/{chunk-Y4CFVCUN.js → chunk-X4CGRHLI.js} +22 -40
- package/dist/chunk-X4CGRHLI.js.map +1 -0
- package/dist/{chunk-EHPYBNHC.js → chunk-YTHRKULG.js} +5 -5
- package/dist/{chunk-Y5JGQJI7.js → chunk-ZLLK6TCU.js} +5 -5
- package/dist/{chunk-JFCOC5TW.cjs → chunk-ZWRZZGMZ.cjs} +23 -41
- package/dist/chunk-ZWRZZGMZ.cjs.map +1 -0
- package/dist/hooks/index.cjs +2 -2
- package/dist/hooks/index.d.cts +10 -9
- package/dist/hooks/index.d.ts +10 -9
- package/dist/hooks/index.js +1 -1
- package/dist/index.cjs +13 -13
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +17 -17
- package/package.json +7 -7
- package/dist/chunk-BCMPSLSG.js +0 -87
- package/dist/chunk-BCMPSLSG.js.map +0 -1
- package/dist/chunk-JFCOC5TW.cjs.map +0 -1
- package/dist/chunk-WQRM7G4C.cjs +0 -87
- package/dist/chunk-WQRM7G4C.cjs.map +0 -1
- package/dist/chunk-Y4CFVCUN.js.map +0 -1
- /package/dist/{chunk-36F7BWKL.js.map → chunk-FYP5BTHS.js.map} +0 -0
- /package/dist/{chunk-LIKSUWSM.js.map → chunk-OD5BASYZ.js.map} +0 -0
- /package/dist/{chunk-UDRSTJBU.js.map → chunk-PDXVHUGH.js.map} +0 -0
- /package/dist/{chunk-R7XP72I5.js.map → chunk-RULU2SJ5.js.map} +0 -0
- /package/dist/{chunk-QD6IQL6U.js.map → chunk-TN6ZHEXV.js.map} +0 -0
- /package/dist/{chunk-KGHLS6DM.js.map → chunk-UIVSMVUT.js.map} +0 -0
- /package/dist/{chunk-EHPYBNHC.js.map → chunk-YTHRKULG.js.map} +0 -0
- /package/dist/{chunk-Y5JGQJI7.js.map → chunk-ZLLK6TCU.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
SubmitButton_default
|
|
3
|
+
} from "./chunk-TN6ZHEXV.js";
|
|
4
4
|
import {
|
|
5
5
|
Switch_default
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-OD5BASYZ.js";
|
|
7
7
|
import {
|
|
8
8
|
TextArea_default
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-PDXVHUGH.js";
|
|
10
10
|
import {
|
|
11
11
|
CheckboxGroup_default
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import {
|
|
14
|
-
FieldArray_default
|
|
15
|
-
} from "./chunk-R7XP72I5.js";
|
|
12
|
+
} from "./chunk-UIVSMVUT.js";
|
|
16
13
|
import {
|
|
17
14
|
Form_default
|
|
18
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-X4CGRHLI.js";
|
|
19
16
|
import {
|
|
20
17
|
Grid_default
|
|
21
18
|
} from "./chunk-PDCEKC3G.js";
|
|
19
|
+
import {
|
|
20
|
+
FieldArray_default
|
|
21
|
+
} from "./chunk-RULU2SJ5.js";
|
|
22
|
+
import {
|
|
23
|
+
Input_default
|
|
24
|
+
} from "./chunk-ZLLK6TCU.js";
|
|
22
25
|
import {
|
|
23
26
|
RadioGroup_default
|
|
24
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-FYP5BTHS.js";
|
|
25
28
|
import {
|
|
26
29
|
Select_default
|
|
27
|
-
} from "./chunk-
|
|
28
|
-
import {
|
|
29
|
-
FieldValidationError_default
|
|
30
|
-
} from "./chunk-DBLODROX.js";
|
|
30
|
+
} from "./chunk-YTHRKULG.js";
|
|
31
31
|
import {
|
|
32
32
|
FieldCopyTestIdButton_default
|
|
33
33
|
} from "./chunk-T3CCNJHK.js";
|
|
34
34
|
import {
|
|
35
|
-
|
|
36
|
-
} from "./chunk-
|
|
35
|
+
FieldValidationError_default
|
|
36
|
+
} from "./chunk-DBLODROX.js";
|
|
37
37
|
import {
|
|
38
38
|
recursiveFieldKeySearch,
|
|
39
39
|
useFormContext
|
|
40
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-B24NXJTR.js";
|
|
41
41
|
import {
|
|
42
42
|
slugify
|
|
43
43
|
} from "./chunk-V46BHM2U.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fuf-stack/uniform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "fuf react form library",
|
|
5
5
|
"author": "Hannes Tiede",
|
|
6
6
|
"homepage": "https://github.com/fuf-stack/uniform#readme",
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"@dnd-kit/sortable": "8.0.0",
|
|
112
112
|
"@dnd-kit/utilities": "3.2.2",
|
|
113
113
|
"@nextui-org/button": "2.0.34",
|
|
114
|
-
"@nextui-org/checkbox": "2.1.
|
|
114
|
+
"@nextui-org/checkbox": "2.1.5",
|
|
115
115
|
"@nextui-org/input": "2.2.2",
|
|
116
116
|
"@nextui-org/radio": "2.1.2",
|
|
117
117
|
"@nextui-org/select": "2.2.2",
|
|
@@ -124,20 +124,20 @@
|
|
|
124
124
|
"react-select": "5.8.1",
|
|
125
125
|
"slug": "9.1.0",
|
|
126
126
|
"@fuf-stack/pixel-utils": "0.1.0",
|
|
127
|
-
"@fuf-stack/
|
|
128
|
-
"@fuf-stack/
|
|
127
|
+
"@fuf-stack/pixels": "0.23.0",
|
|
128
|
+
"@fuf-stack/veto": "0.5.0"
|
|
129
129
|
},
|
|
130
130
|
"devDependencies": {
|
|
131
131
|
"@types/debug": "4.1.12",
|
|
132
|
-
"@types/react": "18.3.
|
|
132
|
+
"@types/react": "18.3.11",
|
|
133
133
|
"@types/react-dom": "18.3.0",
|
|
134
134
|
"@types/slug": "5.0.9",
|
|
135
135
|
"react": "18.3.1",
|
|
136
136
|
"react-dom": "18.3.1",
|
|
137
|
-
"@repo/storybook-config": "0.0.1",
|
|
138
137
|
"@repo/tsup-config": "0.0.1",
|
|
138
|
+
"@repo/tailwind-config": "0.0.1",
|
|
139
139
|
"@repo/vite-config": "0.0.1",
|
|
140
|
-
"@repo/
|
|
140
|
+
"@repo/storybook-config": "0.0.1"
|
|
141
141
|
},
|
|
142
142
|
"scripts": {
|
|
143
143
|
"build": "tsup --config node_modules/@repo/tsup-config/config.ts",
|
package/dist/chunk-BCMPSLSG.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
slugify
|
|
3
|
-
} from "./chunk-V46BHM2U.js";
|
|
4
|
-
|
|
5
|
-
// src/hooks/useFormContext/useFormContext.ts
|
|
6
|
-
import { useContext } from "react";
|
|
7
|
-
import { useFormContext as useHookFormContext } from "react-hook-form";
|
|
8
|
-
|
|
9
|
-
// src/Form/subcomponents/FormContext.tsx
|
|
10
|
-
import React from "react";
|
|
11
|
-
import { FormProvider as HookFormProvider } from "react-hook-form";
|
|
12
|
-
import { jsx } from "react/jsx-runtime";
|
|
13
|
-
var ValidationSchemaContext = React.createContext(void 0);
|
|
14
|
-
var FormProvider = ({
|
|
15
|
-
children,
|
|
16
|
-
validation = void 0,
|
|
17
|
-
...hookFormProps
|
|
18
|
-
}) => {
|
|
19
|
-
return /* @__PURE__ */ jsx(ValidationSchemaContext.Provider, { value: validation, children: /* @__PURE__ */ jsx(HookFormProvider, { ...hookFormProps, children }) });
|
|
20
|
-
};
|
|
21
|
-
var FormContext_default = FormProvider;
|
|
22
|
-
|
|
23
|
-
// src/hooks/useFormContext/useFormContext.ts
|
|
24
|
-
var recursiveSearchInnerType = (schema) => {
|
|
25
|
-
if (schema?._def?.innerType) {
|
|
26
|
-
if (schema?._def?.innerType?._def?.typeName === "ZodOptional") {
|
|
27
|
-
return schema?._def?.innerType?._def?.typeName !== "ZodOptional";
|
|
28
|
-
}
|
|
29
|
-
return recursiveSearchInnerType(schema?._def?.innerType);
|
|
30
|
-
}
|
|
31
|
-
return true;
|
|
32
|
-
};
|
|
33
|
-
var recursiveFieldKeySearch = (schema, path) => {
|
|
34
|
-
const [current, ...rest] = path;
|
|
35
|
-
let currentSchema = schema;
|
|
36
|
-
if (schema?._def?.typeName === "ZodOptional") {
|
|
37
|
-
currentSchema = schema.unwrap();
|
|
38
|
-
} else if (schema?._def?.typeName === "ZodEffects") {
|
|
39
|
-
return recursiveFieldKeySearch(schema._def?.schema, path);
|
|
40
|
-
}
|
|
41
|
-
if (currentSchema?._def?.typeName === "ZodIntersection") {
|
|
42
|
-
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));
|
|
43
|
-
}
|
|
44
|
-
const shape = currentSchema?.shape ?? currentSchema?.element?.shape;
|
|
45
|
-
if (shape && shape[current]) {
|
|
46
|
-
if (rest.length === 0) {
|
|
47
|
-
return shape[current]?._def?.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
|
-
} = useHookFormContext();
|
|
61
|
-
const validation = useContext(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: slugify(testId || name)
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
return {
|
|
75
|
-
...otherMethods,
|
|
76
|
-
getFieldState,
|
|
77
|
-
validation,
|
|
78
|
-
formState
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export {
|
|
83
|
-
FormContext_default,
|
|
84
|
-
recursiveFieldKeySearch,
|
|
85
|
-
useFormContext
|
|
86
|
-
};
|
|
87
|
-
//# sourceMappingURL=chunk-BCMPSLSG.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useFormContext/useFormContext.ts","../src/Form/subcomponents/FormContext.tsx"],"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"],"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;AAA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M,iBAAiB,MAAM;AAClC,QAAM;AAAA;AAAA;AAAA,IAGJ;AAAA,IACA,eAAe;AAAA,IACf,GAAG;AAAA,EACL,IAAI,mBAAmB;AACvB,QAAM,aAAa,WAAW,uBAAuB;AAGrD,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;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-JFCOC5TW.cjs","../src/Form/Form.tsx","../src/Form/subcomponents/FormDebugViewer.tsx","../src/Form/index.ts"],"names":["jsx","jsxs","cn","Form_default"],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,gDAAwB;AAExB,oDAAmB;ADKnB;AACA;AEVA,8BAAoC;AACpC,oCAAwB;AACxB,sCAAkC;AAElC;AACA,2CAAoD;AAqDtC,+CAAA;AA5Cd,IAAM,uBAAA,EAAyB,4BAAA;AAC/B,IAAM,8BAAA,EAAgC,yCAAA;AAGtC,IAAM,gBAAA,EAAkB,CAAC,EAAE,UAAA,EAAY,KAAA,EAAU,CAAA,EAAA,GAA4B;AAC3E,EAAA,MAAM;AAAA,IACJ,KAAA;AAAA,IACA,SAAA,EAAW,EAAE,WAAA,EAAa,OAAA,EAAS,aAAa,CAAA;AA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AAA,EAAU,4CAAA,EACb,QAAA,EAAA;AAAA,sBAAAD,6BAAAA;AAAA,QAAC,MAAA;AAAA,QAAA;AAAA,UACC,SAAA,EAAWE,4BAAAA,WAAG,EAAa,SAAS,CAAA;AAAA,UACpC,aAAA,EAAa,uCAAA,OAAQ,GAAU,KAAA,GAAQ,EAAE,CAAA;AAAA,UACzC,IAAA;AAAA,UACA,QAAA,EAAU,OAAA,CAAQ,YAAA,CAAa,QAAQ,CAAA;AAAA,UAEtC;AAAA,QAAA;AAAA,MACH,CAAA;AAAA,sBACAF,6BAAAA,uBAAC,EAAA,EAAgB,SAAA,EAAU,mBAAA,CAAmB;AAAA,IAAA,EAAA,CAChD,EAAA,CACF;AAAA,EAAA,CAAA;AAEJ,CAAA;AAEA,IAAO,aAAA,EAAQ,IAAA;AD+Df;AACA;AGxJA,IAAOG,cAAAA,EAAQ,YAAA;AH0Jf;AACA;AACE;AACA;AACF,2EAAC","file":"/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-JFCOC5TW.cjs","sourcesContent":[null,"import type { VetoInstance } from '@fuf-stack/veto';\nimport type { ReactNode } from 'react';\nimport type { FieldValues, SubmitHandler } from 'react-hook-form';\n\nimport { useForm } from 'react-hook-form';\n\nimport { cn } from '@fuf-stack/pixel-utils';\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?: 'onChange' | 'onBlur' | 'onSubmit' | 'onTouched' | 'all';\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,\n }\n : {\n defaultValues: initialValues,\n },\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, FaBullseye } from 'react-icons/fa6';\n\nimport { cn } from '@fuf-stack/pixel-utils';\nimport { Button, Card, Json, useLocalStorage } from '@fuf-stack/pixels';\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';\nconst LOCALSTORAGE_COPY_TEST_ID_KEY = 'uniform:form-debug-copy-test-id-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 const [copyTestId, setCopyTestId] = useLocalStorage(\n LOCALSTORAGE_COPY_TEST_ID_KEY,\n false,\n );\n\n const [validationErrors, setValidationErrors] = useState<\n VetoError['errors'] | null\n >(null);\n\n const formValues = watch();\n\n useEffect(\n () => {\n const updateValidationErrors = async () => {\n if (validation) {\n const validateResult = await validation?.validateAsync(formValues);\n setValidationErrors(validateResult?.errors);\n }\n };\n updateValidationErrors();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [JSON.stringify(formValues)],\n );\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 <Button\n variant={copyTestId ? 'solid' : 'light'}\n icon={<FaBullseye />}\n className=\"mb-4 ml-auto mr-auto\"\n onClick={() => setCopyTestId(!copyTestId)}\n >\n {copyTestId ? 'Hide CopyButton' : 'Show CopyButton'}\n </Button>\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"]}
|
package/dist/chunk-WQRM7G4C.cjs
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-WQRM7G4C.cjs","../src/hooks/useFormContext/useFormContext.ts","../src/Form/subcomponents/FormContext.tsx"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACDA,4EAA2B;AAC3B,gDAAqD;ADGrD;AACA;AELA;AACA;AAoBM,+CAAA;AAlBC,IAAM,wBAAA,EAA0B,eAAA,CAAM,aAAA,CAE3C,KAAA,CAAS,CAAA;AASX,IAAM,aAAA,EAAe,CAAC;AAAA,EACpB,QAAA;AAAA,EACA,WAAA,EAAa,KAAA,CAAA;AAAA,EACb,GAAG;AACL,CAAA,EAAA,GAAyB;AACvB,EAAA,uBACE,6BAAA,uBAAC,CAAwB,QAAA,EAAxB,EAAiC,KAAA,EAAO,UAAA,EACvC,QAAA,kBAAA,6BAAA,2BAAC,EAAA,EAAkB,GAAG,aAAA,EAAgB,SAAA,CAAS,EAAA,CACjD,CAAA;AAEJ,CAAA;AAEA,IAAO,oBAAA,EAAQ,YAAA;AFRf;AACA;ACZA,IAAM,yBAAA,EAA2B,CAAC,MAAA,EAAA,GAAgC;AAChE,EAAA,GAAA,iBAAI,MAAA,2BAAQ,IAAA,6BAAM,WAAA,EAAW;AAC3B,IAAA,GAAA,iBAAI,MAAA,6BAAQ,IAAA,6BAAM,SAAA,6BAAW,IAAA,6BAAM,WAAA,IAAa,aAAA,EAAe;AAC7D,MAAA,uBAAO,MAAA,6BAAQ,IAAA,6BAAM,SAAA,6BAAW,IAAA,+BAAM,WAAA,IAAa,aAAA;AAAA,IACrD;AACA,IAAA,OAAO,wBAAA,iBAAyB,MAAA,+BAAQ,IAAA,+BAAM,WAAS,CAAA;AAAA,EACzD;AACA,EAAA,OAAO,IAAA;AACT,CAAA;AAGO,IAAM,wBAAA,EAA0B,CACrC,MAAA,EACA,IAAA,EAAA,GACmB;AACnB,EAAA,MAAM,CAA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,"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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Form/Form.tsx","../src/Form/subcomponents/FormDebugViewer.tsx","../src/Form/index.ts"],"sourcesContent":["import type { VetoInstance } from '@fuf-stack/veto';\nimport type { ReactNode } from 'react';\nimport type { FieldValues, SubmitHandler } from 'react-hook-form';\n\nimport { useForm } from 'react-hook-form';\n\nimport { cn } from '@fuf-stack/pixel-utils';\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?: 'onChange' | 'onBlur' | 'onSubmit' | 'onTouched' | 'all';\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,\n }\n : {\n defaultValues: initialValues,\n },\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, FaBullseye } from 'react-icons/fa6';\n\nimport { cn } from '@fuf-stack/pixel-utils';\nimport { Button, Card, Json, useLocalStorage } from '@fuf-stack/pixels';\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';\nconst LOCALSTORAGE_COPY_TEST_ID_KEY = 'uniform:form-debug-copy-test-id-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 const [copyTestId, setCopyTestId] = useLocalStorage(\n LOCALSTORAGE_COPY_TEST_ID_KEY,\n false,\n );\n\n const [validationErrors, setValidationErrors] = useState<\n VetoError['errors'] | null\n >(null);\n\n const formValues = watch();\n\n useEffect(\n () => {\n const updateValidationErrors = async () => {\n if (validation) {\n const validateResult = await validation?.validateAsync(formValues);\n setValidationErrors(validateResult?.errors);\n }\n };\n updateValidationErrors();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [JSON.stringify(formValues)],\n );\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 <Button\n variant={copyTestId ? 'solid' : 'light'}\n icon={<FaBullseye />}\n className=\"mb-4 ml-auto mr-auto\"\n onClick={() => setCopyTestId(!copyTestId)}\n >\n {copyTestId ? 'Hide CopyButton' : 'Show CopyButton'}\n </Button>\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"],"mappings":";;;;;;;;;AAIA,SAAS,eAAe;AAExB,SAAS,MAAAA,WAAU;;;ACJnB,SAAS,WAAW,gBAAgB;AACpC,SAAS,eAAe;AACxB,SAAS,OAAO,kBAAkB;AAElC,SAAS,UAAU;AACnB,SAAS,QAAQ,MAAM,MAAM,uBAAuB;AAqDtC,cASN,YATM;AA5Cd,IAAM,yBAAyB;AAC/B,IAAM,gCAAgC;AAGtC,IAAM,kBAAkB,CAAC,EAAE,YAAY,OAAU,MAA4B;AAC3E,QAAM;AAAA,IACJ;AAAA,IACA,WAAW,EAAE,aAAa,SAAS,aAAa;AAAA,IAChD;AAAA,EACF,IAAI,eAAe;AAEnB,QAAM,CAAC,OAAO,QAAQ,IAAI,gBAAgB,wBAAwB,KAAK;AACvE,QAAM,CAAC,YAAY,aAAa,IAAI;AAAA,IAClC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAE9C,IAAI;AAEN,QAAM,aAAa,MAAM;AAEzB;AAAA,IACE,MAAM;AACJ,YAAM,yBAAyB,YAAY;AACzC,YAAI,YAAY;AACd,gBAAM,iBAAiB,MAAM,YAAY,cAAc,UAAU;AACjE,8BAAoB,gBAAgB,MAAM;AAAA,QAC5C;AAAA,MACF;AACA,6BAAuB;AAAA,IACzB;AAAA;AAAA,IAEA,CAAC,KAAK,UAAU,UAAU,CAAC;AAAA,EAC7B;AAEA,MAAI,CAAC,OAAO;AACV,WACE;AAAA,MAAC;AAA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AiB;AACf,QAAM,UAAU;AAAA,IACd,aACI;AAAA,MACE,eAAe;AAAA,MACf,UAAU,OAAO,WAAW;AAC1B,cAAM,EAAE,MAAM,QAAQ,GAAG,KAAK,IAAI,MAAM,WAAW;AAAA,UACjD,oBAAoB,MAAM;AAAA,QAC5B;AAEA,eAAO,EAAE,QAAQ,QAAQ,CAAC,GAAG,QAAQ,UAAU,CAAC,GAAG,GAAG,KAAK;AAAA,MAC7D;AAAA;AAAA;AAAA,MAGA,MAAM;AAAA,IACR,IACA;AAAA,MACE,eAAe;AAAA,IACjB;AAAA,EACN;AAEA;AAAA;AAAA,IAEE,gBAAAD,KAAC,uBAAc,GAAG,SAAS,YACzB,0BAAAC,MAAC,SAAI,WAAU,8CACb;AAAA,sBAAAD;AAAA,QAAC;AAAA;AAAA,UACC,WAAWE,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,gBAAAF,KAAC,2BAAgB,WAAU,oBAAmB;AAAA,OAChD,GACF;AAAA;AAEJ;AAEA,IAAO,eAAQ;;;AExFf,IAAOG,gBAAQ;","names":["cn","jsx","jsxs","cn","Form_default"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|