@fuf-stack/uniform 0.0.2 → 0.0.3
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 +45 -165
- package/dist/Form/index.cjs.map +1 -1
- package/dist/Form/index.d.cts +26 -6
- package/dist/Form/index.d.ts +26 -6
- package/dist/Form/index.js +141 -7
- package/dist/Form/index.js.map +1 -1
- package/dist/Grid/index.cjs +7 -40
- package/dist/Grid/index.cjs.map +1 -1
- package/dist/Grid/index.d.cts +14 -4
- package/dist/Grid/index.d.ts +14 -4
- package/dist/Grid/index.js +11 -3
- package/dist/Grid/index.js.map +1 -1
- package/dist/SubmitButton/index.cjs +14 -129
- package/dist/SubmitButton/index.cjs.map +1 -1
- package/dist/SubmitButton/index.d.cts +21 -5
- package/dist/SubmitButton/index.d.ts +21 -5
- package/dist/SubmitButton/index.js +36 -6
- package/dist/SubmitButton/index.js.map +1 -1
- 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-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/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/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 +35 -8
- package/dist/Form/Form.cjs +0 -269
- package/dist/Form/Form.cjs.map +0 -1
- package/dist/Form/Form.d.cts +0 -34
- package/dist/Form/Form.d.ts +0 -34
- 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/FormContext.js.map +0 -1
- 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.d.cts +0 -17
- package/dist/Grid/Grid.d.ts +0 -17
- 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 +0 -82
- 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 +0 -16
- 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/index.cjs
CHANGED
|
@@ -1,198 +1,75 @@
|
|
|
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}); 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; }
|
|
29
2
|
|
|
30
|
-
// src/Form/index.ts
|
|
31
|
-
var Form_exports = {};
|
|
32
|
-
__export(Form_exports, {
|
|
33
|
-
default: () => Form_default2
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(Form_exports);
|
|
36
3
|
|
|
37
|
-
|
|
38
|
-
var import_react4 = require("react");
|
|
39
|
-
var import_react_hook_form3 = require("react-hook-form");
|
|
40
|
-
var import_classnames2 = __toESM(require("classnames"), 1);
|
|
4
|
+
var _chunkWQRM7G4Ccjs = require('../chunk-WQRM7G4C.cjs');
|
|
41
5
|
|
|
42
|
-
// src/helpers/slugify.ts
|
|
43
|
-
var import_slug = __toESM(require("slug"), 1);
|
|
44
|
-
var slugify_default = (string, options) => {
|
|
45
|
-
const replacement = options?.replacement || "_";
|
|
46
|
-
return (0, import_slug.default)(string, {
|
|
47
|
-
...import_slug.default.defaults.modes.rfc3986,
|
|
48
|
-
charmap: {
|
|
49
|
-
...import_slug.default.defaults.modes.rfc3986.charmap,
|
|
50
|
-
// allow dots by default
|
|
51
|
-
".": ".",
|
|
52
|
-
// convert hyphens to underscores (when replacement is not hyphen)
|
|
53
|
-
...replacement !== "-" ? { "-": "_" } : {}
|
|
54
|
-
},
|
|
55
|
-
replacement,
|
|
56
|
-
...options || {}
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
6
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
children,
|
|
67
|
-
validation = void 0,
|
|
68
|
-
...hookFormProps
|
|
69
|
-
}) => {
|
|
70
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ValidationSchemaContext.Provider, { value: validation, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_hook_form.FormProvider, { ...hookFormProps, children }) });
|
|
71
|
-
};
|
|
72
|
-
var FormContext_default = FormProvider;
|
|
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);
|
|
73
13
|
|
|
74
14
|
// src/Form/subcomponents/FormDebugViewer.tsx
|
|
75
|
-
var import_react3 = require("react");
|
|
76
|
-
var import_fa = require("react-icons/fa");
|
|
77
|
-
var import_fa6 = require("react-icons/fa6");
|
|
78
|
-
var import_classnames = __toESM(require("classnames"), 1);
|
|
79
|
-
var import_Button = __toESM(require("@fuf-stack/pixels/Button"), 1);
|
|
80
|
-
var import_Card = __toESM(require("@fuf-stack/pixels/Card"), 1);
|
|
81
|
-
var import_useLocalStorage = __toESM(require("@fuf-stack/pixels/hooks/useLocalStorage"), 1);
|
|
82
|
-
var import_Json = __toESM(require("@fuf-stack/pixels/Json"), 1);
|
|
83
15
|
|
|
84
|
-
|
|
85
|
-
var
|
|
86
|
-
var import_react_hook_form2 = require("react-hook-form");
|
|
87
|
-
var recursiveSearchInnerType = (schema) => {
|
|
88
|
-
if (schema?._def?.innerType) {
|
|
89
|
-
if (schema?._def?.innerType?._def?.typeName === "ZodOptional") {
|
|
90
|
-
return schema?._def?.innerType?._def?.typeName !== "ZodOptional";
|
|
91
|
-
}
|
|
92
|
-
return recursiveSearchInnerType(schema?._def?.innerType);
|
|
93
|
-
}
|
|
94
|
-
return true;
|
|
95
|
-
};
|
|
96
|
-
var recursiveFieldKeySearch = (schema, path) => {
|
|
97
|
-
const [current, ...rest] = path;
|
|
98
|
-
let currentSchema = schema;
|
|
99
|
-
if (schema?._def?.typeName === "ZodOptional") {
|
|
100
|
-
currentSchema = schema.unwrap();
|
|
101
|
-
} else if (schema?._def?.typeName === "ZodEffects") {
|
|
102
|
-
return recursiveFieldKeySearch(schema._def?.schema, path);
|
|
103
|
-
}
|
|
104
|
-
if (currentSchema?._def?.typeName === "ZodIntersection") {
|
|
105
|
-
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));
|
|
106
|
-
}
|
|
107
|
-
const shape = currentSchema?.shape ?? currentSchema?.element?.shape;
|
|
108
|
-
if (shape && shape[current]) {
|
|
109
|
-
if (rest.length === 0) {
|
|
110
|
-
return shape[current]?._def?.typeName !== "ZodOptional" && recursiveSearchInnerType(shape[current]);
|
|
111
|
-
}
|
|
112
|
-
return recursiveFieldKeySearch(shape[current], rest);
|
|
113
|
-
}
|
|
114
|
-
return null;
|
|
115
|
-
};
|
|
116
|
-
var useFormContext = () => {
|
|
117
|
-
const {
|
|
118
|
-
// https://react-hook-form.com/docs/useform/getfieldstate
|
|
119
|
-
// for getFieldState a subscription to formState properties is needed!
|
|
120
|
-
formState,
|
|
121
|
-
getFieldState: getFieldStateOrig,
|
|
122
|
-
...otherMethods
|
|
123
|
-
} = (0, import_react_hook_form2.useFormContext)();
|
|
124
|
-
const validation = (0, import_react2.useContext)(ValidationSchemaContext);
|
|
125
|
-
const getFieldState = (name, testId) => {
|
|
126
|
-
const fieldPath = typeof name === "string" ? name.replace(/\[\d+\]/g, "").split(".") : name;
|
|
127
|
-
const required = validation && recursiveFieldKeySearch(validation.schema, fieldPath) || false;
|
|
128
|
-
const { error, ...rest } = getFieldStateOrig(name, formState);
|
|
129
|
-
return {
|
|
130
|
-
...rest,
|
|
131
|
-
error,
|
|
132
|
-
// TODO: change to correct type @Hannes ;)
|
|
133
|
-
required,
|
|
134
|
-
testId: slugify_default(testId || name)
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
return {
|
|
138
|
-
...otherMethods,
|
|
139
|
-
getFieldState,
|
|
140
|
-
validation,
|
|
141
|
-
formState
|
|
142
|
-
};
|
|
143
|
-
};
|
|
16
|
+
var _fa = require('react-icons/fa');
|
|
17
|
+
var _fa6 = require('react-icons/fa6');
|
|
144
18
|
|
|
145
|
-
|
|
146
|
-
var
|
|
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');
|
|
147
24
|
var LOCALSTORAGE_DEBUG_KEY = "uniform:form-debug-enabled";
|
|
148
25
|
var FormDebugViewer = ({ className = void 0 }) => {
|
|
149
26
|
const {
|
|
150
27
|
watch,
|
|
151
28
|
formState: { dirtyFields, isValid, isSubmitting },
|
|
152
29
|
validation
|
|
153
|
-
} = useFormContext();
|
|
154
|
-
const [debug, setDebug] = (0,
|
|
155
|
-
const [validationErrors, setValidationErrors] = (0,
|
|
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);
|
|
156
33
|
const formValues = watch();
|
|
157
|
-
(0,
|
|
34
|
+
_react.useEffect.call(void 0, () => {
|
|
158
35
|
const updateValidationErrors = async () => {
|
|
159
36
|
if (validation) {
|
|
160
|
-
const validateResult = await validation
|
|
161
|
-
setValidationErrors(validateResult
|
|
37
|
+
const validateResult = await _optionalChain([validation, 'optionalAccess', _ => _.validateAsync, 'call', _2 => _2(formValues)]);
|
|
38
|
+
setValidationErrors(_optionalChain([validateResult, 'optionalAccess', _3 => _3.errors]));
|
|
162
39
|
}
|
|
163
40
|
};
|
|
164
41
|
updateValidationErrors();
|
|
165
42
|
}, [JSON.stringify(formValues)]);
|
|
166
43
|
if (!debug) {
|
|
167
|
-
return /* @__PURE__ */ (0,
|
|
168
|
-
|
|
44
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
45
|
+
_Button2.default,
|
|
169
46
|
{
|
|
170
47
|
ariaLabel: "Enable form debug mode",
|
|
171
48
|
onClick: () => setDebug(!debug),
|
|
172
49
|
className: "absolute bottom-2.5 right-2.5 w-5 text-default-400",
|
|
173
50
|
variant: "light",
|
|
174
|
-
icon: /* @__PURE__ */ (0,
|
|
51
|
+
icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _fa6.FaBug, {})
|
|
175
52
|
}
|
|
176
53
|
);
|
|
177
54
|
}
|
|
178
|
-
return /* @__PURE__ */ (0,
|
|
179
|
-
|
|
55
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
56
|
+
_Card2.default,
|
|
180
57
|
{
|
|
181
|
-
className: (0,
|
|
182
|
-
header: /* @__PURE__ */ (0,
|
|
183
|
-
/* @__PURE__ */ (0,
|
|
184
|
-
/* @__PURE__ */ (0,
|
|
185
|
-
|
|
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,
|
|
186
63
|
{
|
|
187
|
-
icon: /* @__PURE__ */ (0,
|
|
64
|
+
icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _fa.FaTimes, { className: "text-danger" }),
|
|
188
65
|
onClick: () => setDebug(false),
|
|
189
66
|
size: "sm",
|
|
190
67
|
variant: "flat"
|
|
191
68
|
}
|
|
192
69
|
)
|
|
193
70
|
] }),
|
|
194
|
-
children: /* @__PURE__ */ (0,
|
|
195
|
-
|
|
71
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
72
|
+
_Json2.default,
|
|
196
73
|
{
|
|
197
74
|
value: {
|
|
198
75
|
values: formValues,
|
|
@@ -209,7 +86,7 @@ var FormDebugViewer = ({ className = void 0 }) => {
|
|
|
209
86
|
var FormDebugViewer_default = FormDebugViewer;
|
|
210
87
|
|
|
211
88
|
// src/Form/Form.tsx
|
|
212
|
-
|
|
89
|
+
|
|
213
90
|
var removeNullishFields = (obj) => {
|
|
214
91
|
return JSON.parse(
|
|
215
92
|
JSON.stringify(obj, (_key, value) => {
|
|
@@ -227,7 +104,7 @@ var Form = ({
|
|
|
227
104
|
validation = void 0,
|
|
228
105
|
validationTrigger = "all"
|
|
229
106
|
}) => {
|
|
230
|
-
const methods = (0,
|
|
107
|
+
const methods = _reacthookform.useForm.call(void 0,
|
|
231
108
|
validation ? {
|
|
232
109
|
defaultValues: initialValues,
|
|
233
110
|
resolver: async (values) => {
|
|
@@ -243,27 +120,30 @@ var Form = ({
|
|
|
243
120
|
defaultValues: initialValues
|
|
244
121
|
}
|
|
245
122
|
);
|
|
246
|
-
(0,
|
|
123
|
+
_react.useEffect.call(void 0, () => {
|
|
247
124
|
if (validationTrigger === "all-instant") {
|
|
248
125
|
methods.trigger();
|
|
249
126
|
}
|
|
250
127
|
}, []);
|
|
251
|
-
return /* @__PURE__ */ (0,
|
|
252
|
-
/* @__PURE__ */ (0,
|
|
128
|
+
return /* @__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: [
|
|
129
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
253
130
|
"form",
|
|
254
131
|
{
|
|
255
|
-
className: (0,
|
|
256
|
-
"data-testid":
|
|
132
|
+
className: _classnames2.default.call(void 0, "flex-grow", className),
|
|
133
|
+
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0, testId || name || ""),
|
|
257
134
|
name,
|
|
258
135
|
onSubmit: methods.handleSubmit(onSubmit),
|
|
259
136
|
children
|
|
260
137
|
}
|
|
261
138
|
),
|
|
262
|
-
/* @__PURE__ */ (0,
|
|
139
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, FormDebugViewer_default, { className: "w-96 flex-shrink" })
|
|
263
140
|
] }) });
|
|
264
141
|
};
|
|
265
142
|
var Form_default = Form;
|
|
266
143
|
|
|
267
144
|
// src/Form/index.ts
|
|
268
145
|
var Form_default2 = Form_default;
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
exports.default = Form_default2;
|
|
269
149
|
//# sourceMappingURL=index.cjs.map
|
package/dist/Form/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Form/index.ts","../../src/Form/Form.tsx","../../src/helpers/slugify.ts","../../src/Form/subcomponents/FormContext.tsx","../../src/Form/subcomponents/FormDebugViewer.tsx","../../src/hooks/useFormContext/useFormContext.ts"],"sourcesContent":["import Form from './Form';\n\nexport default Form;\n","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/slugify';\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\ninterface 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 if (validationTrigger === 'all-instant') {\n methods.trigger();\n }\n }, []);\n\n return (\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 { Options as SlugOptions } from 'slug';\n\nimport slug from 'slug';\n\nexport default (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","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","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 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/slugify';\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,iBAAAA;AAAA;AAAA;;;ACIA,IAAAC,gBAA0B;AAC1B,IAAAC,0BAAwB;AAExB,IAAAC,qBAAe;;;ACLf,kBAAiB;AAEjB,IAAO,kBAAQ,CAAC,QAAgB,YAA0B;AACxD,QAAM,cAAc,SAAS,eAAe;AAC5C,aAAO,YAAAC,SAAK,QAAQ;AAAA,IAClB,GAAG,YAAAA,QAAK,SAAS,MAAM;AAAA,IACvB,SAAS;AAAA,MACP,GAAG,YAAAA,QAAK,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;;;ACfA,mBAAkB;AAClB,6BAAiD;AAoB3C;AAlBC,IAAM,0BAA0B,aAAAC,QAAM,cAE3C,MAAS;AASX,IAAM,eAAe,CAAC;AAAA,EACpB;AAAA,EACA,aAAa;AAAA,EACb,GAAG;AACL,MAAyB;AACvB,SACE,4CAAC,wBAAwB,UAAxB,EAAiC,OAAO,YACvC,sDAAC,uBAAAC,cAAA,EAAkB,GAAG,eAAgB,UAAS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KAAK,IAAI,MAAM,WAAW;AAAA,UACjD,oBAAoB,MAAM;AAAA,QAC9B;AAEE,eAAO,EAAE,QAAQ,QAAQ,CAAC,GAAG,QAAQ,UAAU,CAAC,GAAG,GAAG,KAAK;AAAA,MAC7D;AAAA;AAAA;AAAA,MAGA,MAAM,sBAAsB,gBAAgB,QAAQ;AAAA,IACtD,IACA;AAAA,MACE,eAAe;AAAA,IACjB;AAAA,EACN;AAEA,+BAAU,MAAM;AACd,QAAI,sBAAsB,eAAe;AACvC,cAAQ,QAAQ;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SACE,6CAAC,uBAAc,GAAG,SAAS,YACzB,wDAAC,SAAI,WAAU,8CACb;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,eAAW,mBAAAC,SAAG,aAAa,SAAS;AAAA,QACpC,eAAa,gBAAQ,UAAU,QAAQ,EAAE;AAAA,QACzC;AAAA,QACA,UAAU,QAAQ,aAAa,QAAQ;AAAA,QAEtC;AAAA;AAAA,IACH;AAAA,IACA,6CAAC,2BAAgB,WAAU,oBAAmB;AAAA,KAChD,GACF;AAEJ;AAEA,IAAO,eAAQ;;;ADxGf,IAAOC,gBAAQ;","names":["Form_default","import_react","import_react_hook_form","import_classnames","slug","React","HookFormProvider","import_react","import_react","import_react_hook_form","useHookFormContext","import_jsx_runtime","useLocalStorage","Button","Card","cn","Json","import_jsx_runtime","cn","Form_default"]}
|
|
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,SAAS,eAAe;AAExB,OAAOC,SAAQ;;;ACLf,SAAS,WAAW,gBAAgB;AACpC,SAAS,eAAe;AACxB,SAAS,aAAa;AAEtB,OAAO,QAAQ;AAEf,OAAO,YAAY;AACnB,OAAO,UAAU;AACjB,OAAO,qBAAq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gB,WAAU,oBAAmB;AAAA,KAChD,GACF;AAEJ;AAEA,IAAO,eAAQ;;;AExGf,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\ninterface 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 if (validationTrigger === 'all-instant') {\n methods.trigger();\n }\n }, []);\n\n return (\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 default Form;\n"]}
|
package/dist/Form/index.d.cts
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import '
|
|
3
|
-
import '
|
|
4
|
-
import 'react';
|
|
5
|
-
import 'react-hook-form';
|
|
6
|
-
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { VetoInstance } from '@fuf-stack/veto';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { FieldValues, SubmitHandler } from 'react-hook-form';
|
|
7
5
|
|
|
6
|
+
interface FormProps {
|
|
7
|
+
/** form children */
|
|
8
|
+
children: ReactNode | ReactNode[];
|
|
9
|
+
/** CSS class name */
|
|
10
|
+
className?: string | string[];
|
|
11
|
+
/** initial form values */
|
|
12
|
+
initialValues?: FieldValues;
|
|
13
|
+
/** name of the form */
|
|
14
|
+
name?: string;
|
|
15
|
+
/** form submit handler */
|
|
16
|
+
onSubmit: SubmitHandler<FieldValues>;
|
|
17
|
+
/** HTML data-testid attribute used in e2e tests */
|
|
18
|
+
testId?: string;
|
|
19
|
+
/** veto validation schema */
|
|
20
|
+
validation?: VetoInstance;
|
|
21
|
+
/** when the validation should be triggered */
|
|
22
|
+
validationTrigger?: 'onChange' | 'onBlur' | 'onSubmit' | 'onTouched' | 'all' | 'all-instant';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Form component that has to wrap every uniform
|
|
26
|
+
*/
|
|
27
|
+
declare const Form: ({ children, className, initialValues, name, onSubmit, testId, validation, validationTrigger, }: FormProps) => react_jsx_runtime.JSX.Element;
|
|
8
28
|
|
|
9
29
|
export { Form as default };
|
package/dist/Form/index.d.ts
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import '
|
|
3
|
-
import '
|
|
4
|
-
import 'react';
|
|
5
|
-
import 'react-hook-form';
|
|
6
|
-
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { VetoInstance } from '@fuf-stack/veto';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { FieldValues, SubmitHandler } from 'react-hook-form';
|
|
7
5
|
|
|
6
|
+
interface FormProps {
|
|
7
|
+
/** form children */
|
|
8
|
+
children: ReactNode | ReactNode[];
|
|
9
|
+
/** CSS class name */
|
|
10
|
+
className?: string | string[];
|
|
11
|
+
/** initial form values */
|
|
12
|
+
initialValues?: FieldValues;
|
|
13
|
+
/** name of the form */
|
|
14
|
+
name?: string;
|
|
15
|
+
/** form submit handler */
|
|
16
|
+
onSubmit: SubmitHandler<FieldValues>;
|
|
17
|
+
/** HTML data-testid attribute used in e2e tests */
|
|
18
|
+
testId?: string;
|
|
19
|
+
/** veto validation schema */
|
|
20
|
+
validation?: VetoInstance;
|
|
21
|
+
/** when the validation should be triggered */
|
|
22
|
+
validationTrigger?: 'onChange' | 'onBlur' | 'onSubmit' | 'onTouched' | 'all' | 'all-instant';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Form component that has to wrap every uniform
|
|
26
|
+
*/
|
|
27
|
+
declare const Form: ({ children, className, initialValues, name, onSubmit, testId, validation, validationTrigger, }: FormProps) => react_jsx_runtime.JSX.Element;
|
|
8
28
|
|
|
9
29
|
export { Form as default };
|
package/dist/Form/index.js
CHANGED
|
@@ -1,11 +1,145 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
FormContext_default,
|
|
3
|
+
useFormContext
|
|
4
|
+
} from "../chunk-BCMPSLSG.js";
|
|
5
|
+
import {
|
|
6
|
+
slugify
|
|
7
|
+
} from "../chunk-V46BHM2U.js";
|
|
8
|
+
|
|
9
|
+
// src/Form/Form.tsx
|
|
10
|
+
import { useEffect as useEffect2 } from "react";
|
|
11
|
+
import { useForm } from "react-hook-form";
|
|
12
|
+
import cn2 from "classnames";
|
|
13
|
+
|
|
14
|
+
// src/Form/subcomponents/FormDebugViewer.tsx
|
|
15
|
+
import { useEffect, useState } from "react";
|
|
16
|
+
import { FaTimes } from "react-icons/fa";
|
|
17
|
+
import { FaBug } from "react-icons/fa6";
|
|
18
|
+
import cn from "classnames";
|
|
19
|
+
import Button from "@fuf-stack/pixels/Button";
|
|
20
|
+
import Card from "@fuf-stack/pixels/Card";
|
|
21
|
+
import useLocalStorage from "@fuf-stack/pixels/hooks/useLocalStorage";
|
|
22
|
+
import Json from "@fuf-stack/pixels/Json";
|
|
23
|
+
import { jsx, jsxs } from "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
|
+
} = useFormContext();
|
|
31
|
+
const [debug, setDebug] = useLocalStorage(LOCALSTORAGE_DEBUG_KEY, false);
|
|
32
|
+
const [validationErrors, setValidationErrors] = useState(null);
|
|
33
|
+
const formValues = watch();
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const updateValidationErrors = async () => {
|
|
36
|
+
if (validation) {
|
|
37
|
+
const validateResult = await validation?.validateAsync(formValues);
|
|
38
|
+
setValidationErrors(validateResult?.errors);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
updateValidationErrors();
|
|
42
|
+
}, [JSON.stringify(formValues)]);
|
|
43
|
+
if (!debug) {
|
|
44
|
+
return /* @__PURE__ */ jsx(
|
|
45
|
+
Button,
|
|
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__ */ jsx(FaBug, {})
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return /* @__PURE__ */ jsx(
|
|
56
|
+
Card,
|
|
57
|
+
{
|
|
58
|
+
className: cn(className),
|
|
59
|
+
header: /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-row justify-between", children: [
|
|
60
|
+
/* @__PURE__ */ jsx("span", { className: "text-lg", children: "Debug Mode" }),
|
|
61
|
+
/* @__PURE__ */ jsx(
|
|
62
|
+
Button,
|
|
63
|
+
{
|
|
64
|
+
icon: /* @__PURE__ */ jsx(FaTimes, { className: "text-danger" }),
|
|
65
|
+
onClick: () => setDebug(false),
|
|
66
|
+
size: "sm",
|
|
67
|
+
variant: "flat"
|
|
68
|
+
}
|
|
69
|
+
)
|
|
70
|
+
] }),
|
|
71
|
+
children: /* @__PURE__ */ jsx(
|
|
72
|
+
Json,
|
|
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
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
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 = useForm(
|
|
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
|
+
useEffect2(() => {
|
|
124
|
+
if (validationTrigger === "all-instant") {
|
|
125
|
+
methods.trigger();
|
|
126
|
+
}
|
|
127
|
+
}, []);
|
|
128
|
+
return /* @__PURE__ */ jsx2(FormContext_default, { ...methods, validation, children: /* @__PURE__ */ jsxs2("div", { className: "flex w-full flex-row justify-between gap-6", children: [
|
|
129
|
+
/* @__PURE__ */ jsx2(
|
|
130
|
+
"form",
|
|
131
|
+
{
|
|
132
|
+
className: cn2("flex-grow", className),
|
|
133
|
+
"data-testid": slugify(testId || name || ""),
|
|
134
|
+
name,
|
|
135
|
+
onSubmit: methods.handleSubmit(onSubmit),
|
|
136
|
+
children
|
|
137
|
+
}
|
|
138
|
+
),
|
|
139
|
+
/* @__PURE__ */ jsx2(FormDebugViewer_default, { className: "w-96 flex-shrink" })
|
|
140
|
+
] }) });
|
|
141
|
+
};
|
|
142
|
+
var Form_default = Form;
|
|
9
143
|
|
|
10
144
|
// src/Form/index.ts
|
|
11
145
|
var Form_default2 = Form_default;
|
package/dist/Form/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Form/index.ts"],"sourcesContent":["import Form from './Form';\n\nexport default Form;\n"],"mappings":"
|
|
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 { 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\ninterface 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 if (validationTrigger === 'all-instant') {\n methods.trigger();\n }\n }, []);\n\n return (\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 default Form;\n"],"mappings":";;;;;;;;;AAIA,SAAS,aAAAA,kBAAiB;AAC1B,SAAS,eAAe;AAExB,OAAOC,SAAQ;;;ACLf,SAAS,WAAW,gBAAgB;AACpC,SAAS,eAAe;AACxB,SAAS,aAAa;AAEtB,OAAO,QAAQ;AAEf,OAAO,YAAY;AACnB,OAAO,UAAU;AACjB,OAAO,qBAAqB;AAC5B,OAAO,UAAU;AA4CH,cASN,YATM;AAnCd,IAAM,yBAAyB;AAG/B,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;AAEvE,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAE9C,IAAI;AAEN,QAAM,aAAa,MAAM;AAEzB,YAAU,MAAM;AACd,UAAM,yBAAyB,YAAY;AACzC,UAAI,YAAY;AACd,cAAM,iBAAiB,MAAM,YAAY,cAAc,UAAU;AACjE,4BAAoB,gBAAgB,MAAM;AAAA,MAC5C;AAAA,IACF;AAC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