@refinedev/react-hook-form 5.0.0 → 5.0.2
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/index.cjs +417 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +404 -1
- package/dist/index.mjs.map +1 -1
- package/dist/useModalForm/index.d.cts.map +1 -1
- package/dist/useModalForm/index.d.ts.map +1 -1
- package/package.json +7 -8
- package/src/useForm/index.spec.tsx +2 -2
- package/src/useModalForm/index.spec.ts +27 -6
- package/src/useModalForm/index.ts +18 -4
- package/src/useStepsForm/index.spec.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,419 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
var
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var src_exports = {};
|
|
33
|
+
__export(src_exports, {
|
|
34
|
+
useForm: () => useForm,
|
|
35
|
+
useModalForm: () => useModalForm,
|
|
36
|
+
useStepsForm: () => useStepsForm
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(src_exports);
|
|
39
|
+
|
|
40
|
+
// src/useForm/index.ts
|
|
41
|
+
var import_react = require("react");
|
|
42
|
+
var import_get = __toESM(require("lodash/get"));
|
|
43
|
+
var import_has = __toESM(require("lodash/has"));
|
|
44
|
+
var import_react_hook_form = require("react-hook-form");
|
|
45
|
+
var import_core = require("@refinedev/core");
|
|
46
|
+
var useForm = /* @__PURE__ */ __name(({
|
|
47
|
+
refineCoreProps,
|
|
48
|
+
warnWhenUnsavedChanges: warnWhenUnsavedChangesProp,
|
|
49
|
+
disableServerSideValidation: disableServerSideValidationProp = false,
|
|
50
|
+
...rest
|
|
51
|
+
} = {}) => {
|
|
52
|
+
const { options } = (0, import_core.useRefineContext)();
|
|
53
|
+
const disableServerSideValidation = (options == null ? void 0 : options.disableServerSideValidation) || disableServerSideValidationProp;
|
|
54
|
+
const translate = (0, import_core.useTranslate)();
|
|
55
|
+
const { warnWhenUnsavedChanges: warnWhenUnsavedChangesRefine, setWarnWhen } = (0, import_core.useWarnAboutChange)();
|
|
56
|
+
const warnWhenUnsavedChanges = warnWhenUnsavedChangesProp ?? warnWhenUnsavedChangesRefine;
|
|
57
|
+
const useHookFormResult = (0, import_react_hook_form.useForm)({
|
|
58
|
+
...rest
|
|
59
|
+
});
|
|
60
|
+
const {
|
|
61
|
+
watch,
|
|
62
|
+
setValue,
|
|
63
|
+
getValues,
|
|
64
|
+
handleSubmit: handleSubmitReactHookForm,
|
|
65
|
+
setError
|
|
66
|
+
} = useHookFormResult;
|
|
67
|
+
const useFormCoreResult = (0, import_core.useForm)({
|
|
68
|
+
...refineCoreProps,
|
|
69
|
+
onMutationError: (error, _variables, _context) => {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
if (disableServerSideValidation) {
|
|
72
|
+
(_a = refineCoreProps == null ? void 0 : refineCoreProps.onMutationError) == null ? void 0 : _a.call(refineCoreProps, error, _variables, _context);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const errors = error == null ? void 0 : error.errors;
|
|
76
|
+
for (const key in errors) {
|
|
77
|
+
const isKeyInVariables = Object.keys(
|
|
78
|
+
(0, import_core.flattenObjectKeys)(_variables)
|
|
79
|
+
).includes(key);
|
|
80
|
+
if (!isKeyInVariables) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const fieldError = errors[key];
|
|
84
|
+
let newError = "";
|
|
85
|
+
if (Array.isArray(fieldError)) {
|
|
86
|
+
newError = fieldError.join(" ");
|
|
87
|
+
}
|
|
88
|
+
if (typeof fieldError === "string") {
|
|
89
|
+
newError = fieldError;
|
|
90
|
+
}
|
|
91
|
+
if (typeof fieldError === "boolean" && fieldError) {
|
|
92
|
+
newError = "Field is not valid.";
|
|
93
|
+
}
|
|
94
|
+
if (typeof fieldError === "object" && "key" in fieldError) {
|
|
95
|
+
const translatedMessage = translate(
|
|
96
|
+
fieldError.key,
|
|
97
|
+
fieldError.message
|
|
98
|
+
);
|
|
99
|
+
newError = translatedMessage;
|
|
100
|
+
}
|
|
101
|
+
setError(key, {
|
|
102
|
+
message: newError
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
(_b = refineCoreProps == null ? void 0 : refineCoreProps.onMutationError) == null ? void 0 : _b.call(refineCoreProps, error, _variables, _context);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
const { query, onFinish, formLoading, onFinishAutoSave } = useFormCoreResult;
|
|
109
|
+
(0, import_react.useEffect)(() => {
|
|
110
|
+
var _a;
|
|
111
|
+
const data = (_a = query == null ? void 0 : query.data) == null ? void 0 : _a.data;
|
|
112
|
+
if (!data)
|
|
113
|
+
return;
|
|
114
|
+
const registeredFields = Object.keys((0, import_core.flattenObjectKeys)(getValues()));
|
|
115
|
+
registeredFields.forEach((path) => {
|
|
116
|
+
const hasValue = (0, import_has.default)(data, path);
|
|
117
|
+
const dataValue = (0, import_get.default)(data, path);
|
|
118
|
+
if (hasValue) {
|
|
119
|
+
setValue(path, dataValue);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}, [query == null ? void 0 : query.data, setValue, getValues]);
|
|
123
|
+
(0, import_react.useEffect)(() => {
|
|
124
|
+
const subscription = watch((values, { type }) => {
|
|
125
|
+
if (type === "change") {
|
|
126
|
+
onValuesChange(values);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return () => subscription.unsubscribe();
|
|
130
|
+
}, [watch]);
|
|
131
|
+
const onValuesChange = /* @__PURE__ */ __name((changeValues) => {
|
|
132
|
+
var _a, _b;
|
|
133
|
+
if (warnWhenUnsavedChanges) {
|
|
134
|
+
setWarnWhen(true);
|
|
135
|
+
}
|
|
136
|
+
if ((_a = refineCoreProps == null ? void 0 : refineCoreProps.autoSave) == null ? void 0 : _a.enabled) {
|
|
137
|
+
setWarnWhen(false);
|
|
138
|
+
const onFinishProps = ((_b = refineCoreProps.autoSave) == null ? void 0 : _b.onFinish) ?? ((values) => values);
|
|
139
|
+
return onFinishAutoSave(onFinishProps(changeValues)).catch(
|
|
140
|
+
(error) => error
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return changeValues;
|
|
144
|
+
}, "onValuesChange");
|
|
145
|
+
const handleSubmit = /* @__PURE__ */ __name((onValid, onInvalid) => async (e) => {
|
|
146
|
+
setWarnWhen(false);
|
|
147
|
+
return handleSubmitReactHookForm(onValid, onInvalid)(e);
|
|
148
|
+
}, "handleSubmit");
|
|
149
|
+
const saveButtonProps = {
|
|
150
|
+
disabled: formLoading,
|
|
151
|
+
onClick: (e) => {
|
|
152
|
+
handleSubmit(
|
|
153
|
+
(v) => onFinish(v).catch(() => {
|
|
154
|
+
}),
|
|
155
|
+
() => false
|
|
156
|
+
)(e);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
return {
|
|
160
|
+
...useHookFormResult,
|
|
161
|
+
handleSubmit,
|
|
162
|
+
refineCore: useFormCoreResult,
|
|
163
|
+
saveButtonProps
|
|
164
|
+
};
|
|
165
|
+
}, "useForm");
|
|
166
|
+
|
|
167
|
+
// src/useStepsForm/index.ts
|
|
168
|
+
var import_react2 = require("react");
|
|
169
|
+
var import_get2 = __toESM(require("lodash/get"));
|
|
170
|
+
var useStepsForm = /* @__PURE__ */ __name(({
|
|
171
|
+
stepsProps,
|
|
172
|
+
...rest
|
|
173
|
+
} = {}) => {
|
|
174
|
+
const { defaultStep = 0, isBackValidate = false } = stepsProps ?? {};
|
|
175
|
+
const [current, setCurrent] = (0, import_react2.useState)(defaultStep);
|
|
176
|
+
const useHookFormResult = useForm({
|
|
177
|
+
...rest
|
|
178
|
+
});
|
|
179
|
+
const {
|
|
180
|
+
trigger,
|
|
181
|
+
getValues,
|
|
182
|
+
setValue,
|
|
183
|
+
formState: { dirtyFields },
|
|
184
|
+
refineCore: { query }
|
|
185
|
+
} = useHookFormResult;
|
|
186
|
+
(0, import_react2.useEffect)(() => {
|
|
187
|
+
var _a;
|
|
188
|
+
const data = (_a = query == null ? void 0 : query.data) == null ? void 0 : _a.data;
|
|
189
|
+
if (!data)
|
|
190
|
+
return;
|
|
191
|
+
const registeredFields = Object.keys(getValues());
|
|
192
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
193
|
+
const name = key;
|
|
194
|
+
if (registeredFields.includes(name)) {
|
|
195
|
+
if (!(0, import_get2.default)(dirtyFields, name)) {
|
|
196
|
+
setValue(name, value);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}, [query == null ? void 0 : query.data, current, setValue, getValues]);
|
|
201
|
+
const go = /* @__PURE__ */ __name((step) => {
|
|
202
|
+
let targetStep = step;
|
|
203
|
+
if (step < 0) {
|
|
204
|
+
targetStep = 0;
|
|
205
|
+
}
|
|
206
|
+
setCurrent(targetStep);
|
|
207
|
+
}, "go");
|
|
208
|
+
const gotoStep = /* @__PURE__ */ __name(async (step) => {
|
|
209
|
+
if (step === current) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (step < current && !isBackValidate) {
|
|
213
|
+
go(step);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const isValid = await trigger();
|
|
217
|
+
if (isValid) {
|
|
218
|
+
go(step);
|
|
219
|
+
}
|
|
220
|
+
}, "gotoStep");
|
|
221
|
+
return {
|
|
222
|
+
...useHookFormResult,
|
|
223
|
+
steps: {
|
|
224
|
+
currentStep: current,
|
|
225
|
+
gotoStep
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}, "useStepsForm");
|
|
229
|
+
|
|
230
|
+
// src/useModalForm/index.ts
|
|
231
|
+
var import_react3 = require("react");
|
|
232
|
+
var import_core2 = require("@refinedev/core");
|
|
233
|
+
var import_react4 = __toESM(require("react"));
|
|
234
|
+
var useModalForm = /* @__PURE__ */ __name(({
|
|
235
|
+
modalProps,
|
|
236
|
+
refineCoreProps,
|
|
237
|
+
syncWithLocation,
|
|
238
|
+
...rest
|
|
239
|
+
} = {}) => {
|
|
240
|
+
var _a, _b;
|
|
241
|
+
const invalidate = (0, import_core2.useInvalidate)();
|
|
242
|
+
const [initiallySynced, setInitiallySynced] = import_react4.default.useState(false);
|
|
243
|
+
const translate = (0, import_core2.useTranslate)();
|
|
244
|
+
const { resource: resourceProp, action: actionProp } = refineCoreProps ?? {};
|
|
245
|
+
const { resource, identifier } = (0, import_core2.useResourceParams)({
|
|
246
|
+
resource: resourceProp
|
|
247
|
+
});
|
|
248
|
+
const { action: actionFromParams } = (0, import_core2.useResourceParams)({
|
|
249
|
+
resource: resourceProp,
|
|
250
|
+
action: actionProp
|
|
251
|
+
});
|
|
252
|
+
const parsed = (0, import_core2.useParsed)();
|
|
253
|
+
const go = (0, import_core2.useGo)();
|
|
254
|
+
const getUserFriendlyName = (0, import_core2.useUserFriendlyName)();
|
|
255
|
+
const action = actionProp ?? actionFromParams ?? "";
|
|
256
|
+
const syncingId = !(typeof syncWithLocation === "object" && (syncWithLocation == null ? void 0 : syncWithLocation.syncId) === false);
|
|
257
|
+
const syncWithLocationKey = typeof syncWithLocation === "object" && "key" in syncWithLocation ? syncWithLocation.key : resource && action && syncWithLocation ? `modal-${identifier}-${action}` : void 0;
|
|
258
|
+
const {
|
|
259
|
+
defaultVisible = false,
|
|
260
|
+
autoSubmitClose = true,
|
|
261
|
+
autoResetForm = true,
|
|
262
|
+
autoResetFormWhenClose = true
|
|
263
|
+
} = modalProps ?? {};
|
|
264
|
+
const useHookFormResult = useForm({
|
|
265
|
+
refineCoreProps: {
|
|
266
|
+
...refineCoreProps,
|
|
267
|
+
meta: {
|
|
268
|
+
...syncWithLocationKey ? { [syncWithLocationKey]: void 0 } : {},
|
|
269
|
+
...refineCoreProps == null ? void 0 : refineCoreProps.meta
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
...rest
|
|
273
|
+
});
|
|
274
|
+
const {
|
|
275
|
+
reset,
|
|
276
|
+
refineCore: { onFinish, id, setId, autoSaveProps, query },
|
|
277
|
+
saveButtonProps,
|
|
278
|
+
handleSubmit
|
|
279
|
+
} = useHookFormResult;
|
|
280
|
+
const { visible, show, close } = (0, import_core2.useModal)({
|
|
281
|
+
defaultVisible
|
|
282
|
+
});
|
|
283
|
+
import_react4.default.useEffect(() => {
|
|
284
|
+
var _a2;
|
|
285
|
+
if (!visible || !((_a2 = query == null ? void 0 : query.data) == null ? void 0 : _a2.data))
|
|
286
|
+
return;
|
|
287
|
+
const formData = query.data.data;
|
|
288
|
+
if (!formData)
|
|
289
|
+
return;
|
|
290
|
+
reset(formData, {
|
|
291
|
+
...!autoResetFormWhenClose && {
|
|
292
|
+
keepDirtyValues: true
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}, [visible, (_a = query == null ? void 0 : query.data) == null ? void 0 : _a.data, autoResetFormWhenClose]);
|
|
296
|
+
import_react4.default.useEffect(() => {
|
|
297
|
+
var _a2, _b2, _c, _d;
|
|
298
|
+
if (initiallySynced === false && syncWithLocationKey) {
|
|
299
|
+
const openStatus = (_b2 = (_a2 = parsed == null ? void 0 : parsed.params) == null ? void 0 : _a2[syncWithLocationKey]) == null ? void 0 : _b2.open;
|
|
300
|
+
if (typeof openStatus === "boolean") {
|
|
301
|
+
if (openStatus) {
|
|
302
|
+
show();
|
|
303
|
+
}
|
|
304
|
+
} else if (typeof openStatus === "string") {
|
|
305
|
+
if (openStatus === "true") {
|
|
306
|
+
show();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (syncingId) {
|
|
310
|
+
const idFromParams = (_d = (_c = parsed == null ? void 0 : parsed.params) == null ? void 0 : _c[syncWithLocationKey]) == null ? void 0 : _d.id;
|
|
311
|
+
if (idFromParams) {
|
|
312
|
+
setId == null ? void 0 : setId(idFromParams);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
setInitiallySynced(true);
|
|
316
|
+
}
|
|
317
|
+
}, [syncWithLocationKey, parsed, syncingId, setId]);
|
|
318
|
+
import_react4.default.useEffect(() => {
|
|
319
|
+
var _a2;
|
|
320
|
+
if (initiallySynced === true) {
|
|
321
|
+
if (visible && syncWithLocationKey) {
|
|
322
|
+
go({
|
|
323
|
+
query: {
|
|
324
|
+
[syncWithLocationKey]: {
|
|
325
|
+
...(_a2 = parsed == null ? void 0 : parsed.params) == null ? void 0 : _a2[syncWithLocationKey],
|
|
326
|
+
open: true,
|
|
327
|
+
...syncingId && id && { id }
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
options: { keepQuery: true },
|
|
331
|
+
type: "replace"
|
|
332
|
+
});
|
|
333
|
+
} else if (syncWithLocationKey && !visible) {
|
|
334
|
+
go({
|
|
335
|
+
query: {
|
|
336
|
+
[syncWithLocationKey]: void 0
|
|
337
|
+
},
|
|
338
|
+
options: { keepQuery: true },
|
|
339
|
+
type: "replace"
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}, [id, visible, show, syncWithLocationKey, syncingId]);
|
|
344
|
+
const submit = /* @__PURE__ */ __name(async (values) => {
|
|
345
|
+
await onFinish(values);
|
|
346
|
+
if (autoSubmitClose) {
|
|
347
|
+
close();
|
|
348
|
+
}
|
|
349
|
+
if (autoResetForm) {
|
|
350
|
+
reset();
|
|
351
|
+
}
|
|
352
|
+
}, "submit");
|
|
353
|
+
const { warnWhen, setWarnWhen } = (0, import_core2.useWarnAboutChange)();
|
|
354
|
+
const handleClose = (0, import_react3.useCallback)(() => {
|
|
355
|
+
var _a2;
|
|
356
|
+
if (autoSaveProps.status === "success" && ((_a2 = refineCoreProps == null ? void 0 : refineCoreProps.autoSave) == null ? void 0 : _a2.invalidateOnClose)) {
|
|
357
|
+
invalidate({
|
|
358
|
+
id,
|
|
359
|
+
invalidates: refineCoreProps.invalidates || ["list", "many", "detail"],
|
|
360
|
+
dataProviderName: refineCoreProps.dataProviderName,
|
|
361
|
+
resource: identifier
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
if (warnWhen) {
|
|
365
|
+
const warnWhenConfirm = window.confirm(
|
|
366
|
+
translate(
|
|
367
|
+
"warnWhenUnsavedChanges",
|
|
368
|
+
"Are you sure you want to leave? You have unsaved changes."
|
|
369
|
+
)
|
|
370
|
+
);
|
|
371
|
+
if (warnWhenConfirm) {
|
|
372
|
+
setWarnWhen(false);
|
|
373
|
+
} else {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
setId == null ? void 0 : setId(void 0);
|
|
378
|
+
close();
|
|
379
|
+
if (autoResetFormWhenClose) {
|
|
380
|
+
reset();
|
|
381
|
+
}
|
|
382
|
+
}, [warnWhen, autoSaveProps.status]);
|
|
383
|
+
const handleShow = (0, import_react3.useCallback)(
|
|
384
|
+
(showId) => {
|
|
385
|
+
if (typeof showId !== "undefined") {
|
|
386
|
+
setId == null ? void 0 : setId(showId);
|
|
387
|
+
}
|
|
388
|
+
const needsIdToOpen = action === "edit" || action === "clone";
|
|
389
|
+
const hasId = typeof showId !== "undefined" || typeof id !== "undefined";
|
|
390
|
+
if (needsIdToOpen ? hasId : true) {
|
|
391
|
+
show();
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
[id]
|
|
395
|
+
);
|
|
396
|
+
const title = translate(
|
|
397
|
+
`${identifier}.titles.${actionProp}`,
|
|
398
|
+
void 0,
|
|
399
|
+
`${getUserFriendlyName(
|
|
400
|
+
`${actionProp} ${((_b = resource == null ? void 0 : resource.meta) == null ? void 0 : _b.label) ?? identifier}`,
|
|
401
|
+
"singular"
|
|
402
|
+
)}`
|
|
403
|
+
);
|
|
404
|
+
return {
|
|
405
|
+
modal: {
|
|
406
|
+
submit,
|
|
407
|
+
close: handleClose,
|
|
408
|
+
show: handleShow,
|
|
409
|
+
visible,
|
|
410
|
+
title
|
|
411
|
+
},
|
|
412
|
+
...useHookFormResult,
|
|
413
|
+
saveButtonProps: {
|
|
414
|
+
...saveButtonProps,
|
|
415
|
+
onClick: (e) => handleSubmit(submit)(e)
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
}, "useModalForm");
|
|
3
419
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/useForm/index.ts","../src/useStepsForm/index.ts","../src/useModalForm/index.ts"],"sourcesContent":["export { useForm, UseFormProps, UseFormReturnType } from \"./useForm/index.js\";\nexport {\n useStepsForm,\n UseStepsFormProps,\n UseStepsFormReturnType,\n} from \"./useStepsForm/index.js\";\nexport {\n useModalForm,\n UseModalFormProps,\n UseModalFormReturnType,\n} from \"./useModalForm/index.js\";\n","import React, { useEffect } from \"react\";\nimport get from \"lodash/get\";\nimport has from \"lodash/has\";\n\nimport {\n useForm as useHookForm,\n type UseFormProps as UseHookFormProps,\n type UseFormReturn,\n type FieldValues,\n type UseFormHandleSubmit,\n type Path,\n} from \"react-hook-form\";\nimport {\n type BaseRecord,\n type HttpError,\n useForm as useFormCore,\n useWarnAboutChange,\n type UseFormProps as UseFormCoreProps,\n type UseFormReturnType as UseFormReturnTypeCore,\n useTranslate,\n useRefineContext,\n flattenObjectKeys,\n} from \"@refinedev/core\";\n\nexport type UseFormReturnType<\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n> = UseFormReturn<TVariables, TContext> & {\n refineCore: UseFormReturnTypeCore<\n TQueryFnData,\n TError,\n TVariables,\n TData,\n TResponse,\n TResponseError\n >;\n saveButtonProps: {\n disabled: boolean;\n onClick: (e: React.BaseSyntheticEvent) => void;\n };\n};\n\nexport type UseFormProps<\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n> = {\n /**\n * Configuration object for the core of the [useForm](/docs/api-reference/core/hooks/useForm/)\n * @type [`UseFormCoreProps<TQueryFnData, TError, TVariables, TData, TResponse, TResponseError>`](/docs/api-reference/core/hooks/useForm/#properties)\n */\n refineCoreProps?: UseFormCoreProps<\n TQueryFnData,\n TError,\n TVariables,\n TData,\n TResponse,\n TResponseError\n >;\n /**\n * When you have unsaved changes and try to leave the current page, **refine** shows a confirmation modal box.\n * @default `false*`\n */\n warnWhenUnsavedChanges?: boolean;\n /**\n * Disables server-side validation\n * @default false\n * @see {@link https://refine.dev/docs/advanced-tutorials/forms/server-side-form-validation/}\n */\n disableServerSideValidation?: boolean;\n} & UseHookFormProps<TVariables, TContext>;\n\nexport const useForm = <\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n>({\n refineCoreProps,\n warnWhenUnsavedChanges: warnWhenUnsavedChangesProp,\n disableServerSideValidation: disableServerSideValidationProp = false,\n ...rest\n}: UseFormProps<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> = {}): UseFormReturnType<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> => {\n const { options } = useRefineContext();\n const disableServerSideValidation =\n options?.disableServerSideValidation || disableServerSideValidationProp;\n\n const translate = useTranslate();\n\n const { warnWhenUnsavedChanges: warnWhenUnsavedChangesRefine, setWarnWhen } =\n useWarnAboutChange();\n const warnWhenUnsavedChanges =\n warnWhenUnsavedChangesProp ?? warnWhenUnsavedChangesRefine;\n\n const useHookFormResult = useHookForm<TVariables, TContext>({\n ...rest,\n });\n\n const {\n watch,\n setValue,\n getValues,\n handleSubmit: handleSubmitReactHookForm,\n setError,\n } = useHookFormResult;\n\n const useFormCoreResult = useFormCore<\n TQueryFnData,\n TError,\n TVariables,\n TData,\n TResponse,\n TResponseError\n >({\n ...refineCoreProps,\n onMutationError: (error, _variables, _context) => {\n if (disableServerSideValidation) {\n refineCoreProps?.onMutationError?.(error, _variables, _context);\n return;\n }\n\n const errors = error?.errors;\n\n for (const key in errors) {\n // when the key is not registered in the form, react-hook-form not working\n const isKeyInVariables = Object.keys(\n flattenObjectKeys(_variables),\n ).includes(key);\n\n if (!isKeyInVariables) {\n continue;\n }\n\n const fieldError = errors[key];\n\n let newError = \"\";\n\n if (Array.isArray(fieldError)) {\n newError = fieldError.join(\" \");\n }\n\n if (typeof fieldError === \"string\") {\n newError = fieldError;\n }\n\n if (typeof fieldError === \"boolean\" && fieldError) {\n newError = \"Field is not valid.\";\n }\n\n if (typeof fieldError === \"object\" && \"key\" in fieldError) {\n const translatedMessage = translate(\n fieldError.key,\n fieldError.message,\n );\n\n newError = translatedMessage;\n }\n\n setError(key as Path<TVariables>, {\n message: newError,\n });\n }\n\n refineCoreProps?.onMutationError?.(error, _variables, _context);\n },\n });\n\n const { query, onFinish, formLoading, onFinishAutoSave } = useFormCoreResult;\n\n useEffect(() => {\n const data = query?.data?.data;\n if (!data) return;\n\n /**\n * get registered fields from react-hook-form\n */\n const registeredFields = Object.keys(flattenObjectKeys(getValues()));\n\n /**\n * set values from query result as default values\n */\n registeredFields.forEach((path) => {\n const hasValue = has(data, path);\n const dataValue = get(data, path);\n\n /**\n * set value if the path exists in the query result even if the value is null\n */\n if (hasValue) {\n setValue(path as Path<TVariables>, dataValue);\n }\n });\n }, [query?.data, setValue, getValues]);\n\n useEffect(() => {\n const subscription = watch((values: any, { type }: { type?: any }) => {\n if (type === \"change\") {\n onValuesChange(values);\n }\n });\n return () => subscription.unsubscribe();\n }, [watch]);\n\n const onValuesChange = (changeValues: TVariables) => {\n if (warnWhenUnsavedChanges) {\n setWarnWhen(true);\n }\n\n if (refineCoreProps?.autoSave?.enabled) {\n setWarnWhen(false);\n\n const onFinishProps =\n refineCoreProps.autoSave?.onFinish ?? ((values: TVariables) => values);\n\n return onFinishAutoSave(onFinishProps(changeValues)).catch(\n (error) => error,\n );\n }\n\n return changeValues;\n };\n\n const handleSubmit: UseFormHandleSubmit<TVariables> =\n (onValid, onInvalid) => async (e) => {\n setWarnWhen(false);\n return handleSubmitReactHookForm(onValid, onInvalid)(e);\n };\n\n const saveButtonProps = {\n disabled: formLoading,\n onClick: (e: React.BaseSyntheticEvent) => {\n handleSubmit(\n (v) => onFinish(v).catch(() => {}),\n () => false,\n )(e);\n },\n };\n\n return {\n ...useHookFormResult,\n handleSubmit,\n refineCore: useFormCoreResult,\n saveButtonProps,\n };\n};\n","import { useEffect, useState } from \"react\";\nimport type { FieldValues, Path } from \"react-hook-form\";\nimport type { BaseRecord, HttpError } from \"@refinedev/core\";\nimport get from \"lodash/get\";\n\nimport { useForm, type UseFormProps, type UseFormReturnType } from \"../useForm\";\n\nexport type UseStepsFormReturnType<\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n> = UseFormReturnType<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> & {\n steps: {\n currentStep: number;\n gotoStep: (step: number) => void;\n };\n};\n\nexport type UseStepsFormProps<\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n> = UseFormProps<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> & {\n /**\n * @description Configuration object for the steps.\n * `defaultStep`: Allows you to set the initial step.\n * \n * `isBackValidate`: Whether to validation the current step when going back.\n * @type `{\n defaultStep?: number;\n isBackValidate?: boolean;\n }`\n * @default `defaultStep = 0` `isBackValidate = false`\n */\n stepsProps?: {\n defaultStep?: number;\n isBackValidate?: boolean;\n };\n};\n\nexport const useStepsForm = <\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n>({\n stepsProps,\n ...rest\n}: UseStepsFormProps<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> = {}): UseStepsFormReturnType<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> => {\n const { defaultStep = 0, isBackValidate = false } = stepsProps ?? {};\n const [current, setCurrent] = useState(defaultStep);\n\n const useHookFormResult = useForm<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n >({\n ...rest,\n });\n\n const {\n trigger,\n getValues,\n setValue,\n formState: { dirtyFields },\n refineCore: { query },\n } = useHookFormResult;\n\n useEffect(() => {\n const data = query?.data?.data;\n if (!data) return;\n\n const registeredFields = Object.keys(getValues());\n\n Object.entries(data).forEach(([key, value]) => {\n const name = key as Path<TVariables>;\n\n if (registeredFields.includes(name)) {\n if (!get(dirtyFields, name)) {\n setValue(name, value);\n }\n }\n });\n }, [query?.data, current, setValue, getValues]);\n\n const go = (step: number) => {\n let targetStep = step;\n\n if (step < 0) {\n targetStep = 0;\n }\n\n setCurrent(targetStep);\n };\n\n const gotoStep = async (step: number) => {\n if (step === current) {\n return;\n }\n\n if (step < current && !isBackValidate) {\n go(step);\n return;\n }\n\n const isValid = await trigger();\n if (isValid) {\n go(step);\n }\n };\n\n return {\n ...useHookFormResult,\n steps: {\n currentStep: current,\n gotoStep,\n },\n };\n};\n","import { useCallback } from \"react\";\nimport {\n type BaseKey,\n type BaseRecord,\n type FormWithSyncWithLocationParams,\n type HttpError,\n useGo,\n useModal,\n useParsed,\n useUserFriendlyName,\n useTranslate,\n useWarnAboutChange,\n useInvalidate,\n useResourceParams,\n} from \"@refinedev/core\";\nimport type { FieldValues } from \"react-hook-form\";\n\nimport { useForm, type UseFormProps, type UseFormReturnType } from \"../useForm\";\nimport React from \"react\";\n\nexport type UseModalFormReturnType<\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n> = UseFormReturnType<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> & {\n modal: {\n submit: (values: TVariables) => void;\n close: () => void;\n show: (id?: BaseKey) => void;\n visible: boolean;\n title: string;\n };\n};\n\nexport type UseModalFormProps<\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n> = UseFormProps<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> & {\n /**\n * @description Configuration object for the modal.\n * `defaultVisible`: Initial visibility state of the modal.\n * \n * `autoSubmitClose`: Whether the form should be submitted when the modal is closed.\n * \n * `autoResetForm`: Whether the form should be reset when the form is submitted.\n * \n * `autoResetFormWhenClose`: Whether the form should be reset to defaultValues when the modal is closed.\n * @type `{\n defaultVisible?: boolean;\n autoSubmitClose?: boolean;\n autoResetForm?: boolean;\n autoResetFormWhenClose?: boolean;\n }`\n * @default `defaultVisible = false` `autoSubmitClose = true` `autoResetForm = true` `autoResetFormWhenClose = true`\n */\n modalProps?: {\n defaultVisible?: boolean;\n autoSubmitClose?: boolean;\n autoResetForm?: boolean;\n autoResetFormWhenClose?: boolean;\n };\n} & FormWithSyncWithLocationParams;\n\nexport const useModalForm = <\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n>({\n modalProps,\n refineCoreProps,\n syncWithLocation,\n ...rest\n}: UseModalFormProps<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> = {}): UseModalFormReturnType<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> => {\n const invalidate = useInvalidate();\n const [initiallySynced, setInitiallySynced] = React.useState(false);\n\n const translate = useTranslate();\n\n const { resource: resourceProp, action: actionProp } = refineCoreProps ?? {};\n\n const { resource, identifier } = useResourceParams({\n resource: resourceProp,\n });\n const { action: actionFromParams } = useResourceParams({\n resource: resourceProp,\n action: actionProp,\n });\n\n const parsed = useParsed();\n const go = useGo();\n const getUserFriendlyName = useUserFriendlyName();\n\n const action = actionProp ?? actionFromParams ?? \"\";\n\n const syncingId = !(\n typeof syncWithLocation === \"object\" && syncWithLocation?.syncId === false\n );\n\n const syncWithLocationKey =\n typeof syncWithLocation === \"object\" && \"key\" in syncWithLocation\n ? syncWithLocation.key\n : resource && action && syncWithLocation\n ? `modal-${identifier}-${action}`\n : undefined;\n\n const {\n defaultVisible = false,\n autoSubmitClose = true,\n autoResetForm = true,\n autoResetFormWhenClose = true,\n } = modalProps ?? {};\n\n const useHookFormResult = useForm<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n >({\n refineCoreProps: {\n ...refineCoreProps,\n meta: {\n ...(syncWithLocationKey ? { [syncWithLocationKey]: undefined } : {}),\n ...refineCoreProps?.meta,\n },\n },\n ...rest,\n });\n\n const {\n reset,\n refineCore: { onFinish, id, setId, autoSaveProps },\n saveButtonProps,\n handleSubmit,\n } = useHookFormResult;\n\n const { visible, show, close } = useModal({\n defaultVisible,\n });\n\n React.useEffect(() => {\n if (initiallySynced === false && syncWithLocationKey) {\n const openStatus = parsed?.params?.[syncWithLocationKey]?.open;\n if (typeof openStatus === \"boolean\") {\n if (openStatus) {\n show();\n }\n } else if (typeof openStatus === \"string\") {\n if (openStatus === \"true\") {\n show();\n }\n }\n\n if (syncingId) {\n const idFromParams = parsed?.params?.[syncWithLocationKey]?.id;\n if (idFromParams) {\n setId?.(idFromParams);\n }\n }\n\n setInitiallySynced(true);\n }\n }, [syncWithLocationKey, parsed, syncingId, setId]);\n\n React.useEffect(() => {\n if (initiallySynced === true) {\n if (visible && syncWithLocationKey) {\n go({\n query: {\n [syncWithLocationKey]: {\n ...parsed?.params?.[syncWithLocationKey],\n open: true,\n ...(syncingId && id && { id }),\n },\n },\n options: { keepQuery: true },\n type: \"replace\",\n });\n } else if (syncWithLocationKey && !visible) {\n go({\n query: {\n [syncWithLocationKey]: undefined,\n },\n options: { keepQuery: true },\n type: \"replace\",\n });\n }\n }\n }, [id, visible, show, syncWithLocationKey, syncingId]);\n\n const submit = async (values: TVariables) => {\n await onFinish(values);\n\n if (autoSubmitClose) {\n close();\n }\n\n if (autoResetForm) {\n reset();\n }\n };\n\n const { warnWhen, setWarnWhen } = useWarnAboutChange();\n const handleClose = useCallback(() => {\n if (\n autoSaveProps.status === \"success\" &&\n refineCoreProps?.autoSave?.invalidateOnClose\n ) {\n invalidate({\n id,\n invalidates: refineCoreProps.invalidates || [\"list\", \"many\", \"detail\"],\n dataProviderName: refineCoreProps.dataProviderName,\n resource: identifier,\n });\n }\n\n if (warnWhen) {\n const warnWhenConfirm = window.confirm(\n translate(\n \"warnWhenUnsavedChanges\",\n \"Are you sure you want to leave? You have unsaved changes.\",\n ),\n );\n\n if (warnWhenConfirm) {\n setWarnWhen(false);\n } else {\n return;\n }\n }\n\n setId?.(undefined);\n close();\n\n if (autoResetFormWhenClose) {\n reset();\n }\n }, [warnWhen, autoSaveProps.status]);\n\n const handleShow = useCallback(\n (showId?: BaseKey) => {\n if (typeof showId !== \"undefined\") {\n setId?.(showId);\n }\n const needsIdToOpen = action === \"edit\" || action === \"clone\";\n const hasId = typeof showId !== \"undefined\" || typeof id !== \"undefined\";\n if (needsIdToOpen ? hasId : true) {\n show();\n }\n },\n [id],\n );\n\n const title = translate(\n `${identifier}.titles.${actionProp}`,\n undefined,\n `${getUserFriendlyName(\n `${actionProp} ${resource?.meta?.label ?? identifier}`,\n \"singular\",\n )}`,\n );\n\n return {\n modal: {\n submit,\n close: handleClose,\n show: handleShow,\n visible,\n title,\n },\n ...useHookFormResult,\n saveButtonProps: {\n ...saveButtonProps,\n onClick: (e) => handleSubmit(submit)(e),\n },\n };\n};\n"],"mappings":";4mBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,aAAAE,EAAA,iBAAAC,GAAA,iBAAAC,KAAA,eAAAC,GAAAL,ICAA,IAAAM,EAAiC,iBACjCC,GAAgB,yBAChBC,GAAgB,yBAEhBC,GAOO,2BACPC,EAUO,2BA2DA,IAAMC,EAAUC,EAAA,CAQrB,CACA,gBAAAC,EACA,uBAAwBC,EACxB,4BAA6BC,EAAkC,GAC/D,GAAGC,CACL,EAQI,CAAC,IAQA,CACH,GAAM,CAAE,QAAAC,CAAQ,KAAI,oBAAiB,EAC/BC,GACJD,GAAA,YAAAA,EAAS,8BAA+BF,EAEpCI,KAAY,gBAAa,EAEzB,CAAE,uBAAwBC,EAA8B,YAAAC,CAAY,KACxE,sBAAmB,EACfC,EACJR,GAA8BM,EAE1BG,KAAoB,GAAAC,SAAkC,CAC1D,GAAGR,CACL,CAAC,EAEK,CACJ,MAAAS,EACA,SAAAC,EACA,UAAAC,EACA,aAAcC,EACd,SAAAC,CACF,EAAIN,EAEEO,KAAoB,EAAAC,SAOxB,CACA,GAAGlB,EACH,gBAAiB,CAACmB,EAAOC,EAAYC,IAAa,CA/ItD,IAAAC,EAAAC,EAgJM,GAAIlB,EAA6B,EAC/BiB,EAAAtB,GAAA,YAAAA,EAAiB,kBAAjB,MAAAsB,EAAA,KAAAtB,EAAmCmB,EAAOC,EAAYC,GACtD,OAGF,IAAMG,EAASL,GAAA,YAAAA,EAAO,OAEtB,QAAWM,KAAOD,EAAQ,CAMxB,GAAI,CAJqB,OAAO,QAC9B,qBAAkBJ,CAAU,CAC9B,EAAE,SAASK,CAAG,EAGZ,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B,GAAQxC,EACZ,GAAGI,YAAqBF,IACxB,OACA,GAAGM,EACD,GAAGN,OAAcP,EAAAQ,GAAA,YAAAA,EAAU,OAAV,YAAAR,EAAgB,QAASS,IAC1C,UACF,GACF,EAEA,MAAO,CACL,MAAO,CACL,OAAA6B,EACA,MAAOI,GACP,KAAMC,GACN,QAAAb,EACA,MAAAe,EACF,EACA,GAAGxB,EACH,gBAAiB,CACf,GAAGO,EACH,QAAUkB,GAAMjB,EAAaS,CAAM,EAAEQ,CAAC,CACxC,CACF,CACF,EA3O4B","names":["src_exports","__export","useForm","useModalForm","useStepsForm","__toCommonJS","import_react","import_get","import_has","import_react_hook_form","import_core","useForm","__name","refineCoreProps","warnWhenUnsavedChangesProp","disableServerSideValidationProp","rest","options","disableServerSideValidation","translate","warnWhenUnsavedChangesRefine","setWarnWhen","warnWhenUnsavedChanges","useHookFormResult","useHookForm","watch","setValue","getValues","handleSubmitReactHookForm","setError","useFormCoreResult","useFormCore","error","_variables","_context","_a","_b","errors","key","fieldError","newError","query","onFinish","formLoading","onFinishAutoSave","data","path","hasValue","has","dataValue","get","subscription","values","type","onValuesChange","changeValues","onFinishProps","handleSubmit","onValid","onInvalid","e","v","import_react","import_get","useStepsForm","__name","stepsProps","rest","defaultStep","isBackValidate","current","setCurrent","useHookFormResult","useForm","trigger","getValues","setValue","dirtyFields","query","_a","data","registeredFields","key","value","name","get","go","step","targetStep","import_react","import_core","import_react","useModalForm","__name","modalProps","refineCoreProps","syncWithLocation","rest","_a","invalidate","initiallySynced","setInitiallySynced","React","translate","resourceProp","actionProp","resource","identifier","actionFromParams","parsed","go","getUserFriendlyName","action","syncingId","syncWithLocationKey","defaultVisible","autoSubmitClose","autoResetForm","autoResetFormWhenClose","useHookFormResult","useForm","reset","onFinish","id","setId","autoSaveProps","saveButtonProps","handleSubmit","visible","show","close","_b","_c","_d","openStatus","idFromParams","submit","values","warnWhen","setWarnWhen","handleClose","handleShow","showId","title","e"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/useForm/index.ts","../src/useStepsForm/index.ts","../src/useModalForm/index.ts"],"sourcesContent":["export { useForm, UseFormProps, UseFormReturnType } from \"./useForm/index.js\";\nexport {\n useStepsForm,\n UseStepsFormProps,\n UseStepsFormReturnType,\n} from \"./useStepsForm/index.js\";\nexport {\n useModalForm,\n UseModalFormProps,\n UseModalFormReturnType,\n} from \"./useModalForm/index.js\";\n","import React, { useEffect } from \"react\";\nimport get from \"lodash/get\";\nimport has from \"lodash/has\";\n\nimport {\n useForm as useHookForm,\n type UseFormProps as UseHookFormProps,\n type UseFormReturn,\n type FieldValues,\n type UseFormHandleSubmit,\n type Path,\n} from \"react-hook-form\";\nimport {\n type BaseRecord,\n type HttpError,\n useForm as useFormCore,\n useWarnAboutChange,\n type UseFormProps as UseFormCoreProps,\n type UseFormReturnType as UseFormReturnTypeCore,\n useTranslate,\n useRefineContext,\n flattenObjectKeys,\n} from \"@refinedev/core\";\n\nexport type UseFormReturnType<\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n> = UseFormReturn<TVariables, TContext> & {\n refineCore: UseFormReturnTypeCore<\n TQueryFnData,\n TError,\n TVariables,\n TData,\n TResponse,\n TResponseError\n >;\n saveButtonProps: {\n disabled: boolean;\n onClick: (e: React.BaseSyntheticEvent) => void;\n };\n};\n\nexport type UseFormProps<\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n> = {\n /**\n * Configuration object for the core of the [useForm](/docs/api-reference/core/hooks/useForm/)\n * @type [`UseFormCoreProps<TQueryFnData, TError, TVariables, TData, TResponse, TResponseError>`](/docs/api-reference/core/hooks/useForm/#properties)\n */\n refineCoreProps?: UseFormCoreProps<\n TQueryFnData,\n TError,\n TVariables,\n TData,\n TResponse,\n TResponseError\n >;\n /**\n * When you have unsaved changes and try to leave the current page, **refine** shows a confirmation modal box.\n * @default `false*`\n */\n warnWhenUnsavedChanges?: boolean;\n /**\n * Disables server-side validation\n * @default false\n * @see {@link https://refine.dev/docs/advanced-tutorials/forms/server-side-form-validation/}\n */\n disableServerSideValidation?: boolean;\n} & UseHookFormProps<TVariables, TContext>;\n\nexport const useForm = <\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n>({\n refineCoreProps,\n warnWhenUnsavedChanges: warnWhenUnsavedChangesProp,\n disableServerSideValidation: disableServerSideValidationProp = false,\n ...rest\n}: UseFormProps<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> = {}): UseFormReturnType<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> => {\n const { options } = useRefineContext();\n const disableServerSideValidation =\n options?.disableServerSideValidation || disableServerSideValidationProp;\n\n const translate = useTranslate();\n\n const { warnWhenUnsavedChanges: warnWhenUnsavedChangesRefine, setWarnWhen } =\n useWarnAboutChange();\n const warnWhenUnsavedChanges =\n warnWhenUnsavedChangesProp ?? warnWhenUnsavedChangesRefine;\n\n const useHookFormResult = useHookForm<TVariables, TContext>({\n ...rest,\n });\n\n const {\n watch,\n setValue,\n getValues,\n handleSubmit: handleSubmitReactHookForm,\n setError,\n } = useHookFormResult;\n\n const useFormCoreResult = useFormCore<\n TQueryFnData,\n TError,\n TVariables,\n TData,\n TResponse,\n TResponseError\n >({\n ...refineCoreProps,\n onMutationError: (error, _variables, _context) => {\n if (disableServerSideValidation) {\n refineCoreProps?.onMutationError?.(error, _variables, _context);\n return;\n }\n\n const errors = error?.errors;\n\n for (const key in errors) {\n // when the key is not registered in the form, react-hook-form not working\n const isKeyInVariables = Object.keys(\n flattenObjectKeys(_variables),\n ).includes(key);\n\n if (!isKeyInVariables) {\n continue;\n }\n\n const fieldError = errors[key];\n\n let newError = \"\";\n\n if (Array.isArray(fieldError)) {\n newError = fieldError.join(\" \");\n }\n\n if (typeof fieldError === \"string\") {\n newError = fieldError;\n }\n\n if (typeof fieldError === \"boolean\" && fieldError) {\n newError = \"Field is not valid.\";\n }\n\n if (typeof fieldError === \"object\" && \"key\" in fieldError) {\n const translatedMessage = translate(\n fieldError.key,\n fieldError.message,\n );\n\n newError = translatedMessage;\n }\n\n setError(key as Path<TVariables>, {\n message: newError,\n });\n }\n\n refineCoreProps?.onMutationError?.(error, _variables, _context);\n },\n });\n\n const { query, onFinish, formLoading, onFinishAutoSave } = useFormCoreResult;\n\n useEffect(() => {\n const data = query?.data?.data;\n if (!data) return;\n\n /**\n * get registered fields from react-hook-form\n */\n const registeredFields = Object.keys(flattenObjectKeys(getValues()));\n\n /**\n * set values from query result as default values\n */\n registeredFields.forEach((path) => {\n const hasValue = has(data, path);\n const dataValue = get(data, path);\n\n /**\n * set value if the path exists in the query result even if the value is null\n */\n if (hasValue) {\n setValue(path as Path<TVariables>, dataValue);\n }\n });\n }, [query?.data, setValue, getValues]);\n\n useEffect(() => {\n const subscription = watch((values: any, { type }: { type?: any }) => {\n if (type === \"change\") {\n onValuesChange(values);\n }\n });\n return () => subscription.unsubscribe();\n }, [watch]);\n\n const onValuesChange = (changeValues: TVariables) => {\n if (warnWhenUnsavedChanges) {\n setWarnWhen(true);\n }\n\n if (refineCoreProps?.autoSave?.enabled) {\n setWarnWhen(false);\n\n const onFinishProps =\n refineCoreProps.autoSave?.onFinish ?? ((values: TVariables) => values);\n\n return onFinishAutoSave(onFinishProps(changeValues)).catch(\n (error) => error,\n );\n }\n\n return changeValues;\n };\n\n const handleSubmit: UseFormHandleSubmit<TVariables> =\n (onValid, onInvalid) => async (e) => {\n setWarnWhen(false);\n return handleSubmitReactHookForm(onValid, onInvalid)(e);\n };\n\n const saveButtonProps = {\n disabled: formLoading,\n onClick: (e: React.BaseSyntheticEvent) => {\n handleSubmit(\n (v) => onFinish(v).catch(() => {}),\n () => false,\n )(e);\n },\n };\n\n return {\n ...useHookFormResult,\n handleSubmit,\n refineCore: useFormCoreResult,\n saveButtonProps,\n };\n};\n","import { useEffect, useState } from \"react\";\nimport type { FieldValues, Path } from \"react-hook-form\";\nimport type { BaseRecord, HttpError } from \"@refinedev/core\";\nimport get from \"lodash/get\";\n\nimport { useForm, type UseFormProps, type UseFormReturnType } from \"../useForm\";\n\nexport type UseStepsFormReturnType<\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n> = UseFormReturnType<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> & {\n steps: {\n currentStep: number;\n gotoStep: (step: number) => void;\n };\n};\n\nexport type UseStepsFormProps<\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n> = UseFormProps<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> & {\n /**\n * @description Configuration object for the steps.\n * `defaultStep`: Allows you to set the initial step.\n * \n * `isBackValidate`: Whether to validation the current step when going back.\n * @type `{\n defaultStep?: number;\n isBackValidate?: boolean;\n }`\n * @default `defaultStep = 0` `isBackValidate = false`\n */\n stepsProps?: {\n defaultStep?: number;\n isBackValidate?: boolean;\n };\n};\n\nexport const useStepsForm = <\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n>({\n stepsProps,\n ...rest\n}: UseStepsFormProps<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> = {}): UseStepsFormReturnType<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> => {\n const { defaultStep = 0, isBackValidate = false } = stepsProps ?? {};\n const [current, setCurrent] = useState(defaultStep);\n\n const useHookFormResult = useForm<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n >({\n ...rest,\n });\n\n const {\n trigger,\n getValues,\n setValue,\n formState: { dirtyFields },\n refineCore: { query },\n } = useHookFormResult;\n\n useEffect(() => {\n const data = query?.data?.data;\n if (!data) return;\n\n const registeredFields = Object.keys(getValues());\n\n Object.entries(data).forEach(([key, value]) => {\n const name = key as Path<TVariables>;\n\n if (registeredFields.includes(name)) {\n if (!get(dirtyFields, name)) {\n setValue(name, value);\n }\n }\n });\n }, [query?.data, current, setValue, getValues]);\n\n const go = (step: number) => {\n let targetStep = step;\n\n if (step < 0) {\n targetStep = 0;\n }\n\n setCurrent(targetStep);\n };\n\n const gotoStep = async (step: number) => {\n if (step === current) {\n return;\n }\n\n if (step < current && !isBackValidate) {\n go(step);\n return;\n }\n\n const isValid = await trigger();\n if (isValid) {\n go(step);\n }\n };\n\n return {\n ...useHookFormResult,\n steps: {\n currentStep: current,\n gotoStep,\n },\n };\n};\n","import { useCallback } from \"react\";\nimport {\n type BaseKey,\n type BaseRecord,\n type FormWithSyncWithLocationParams,\n type HttpError,\n useGo,\n useModal,\n useParsed,\n useUserFriendlyName,\n useTranslate,\n useWarnAboutChange,\n useInvalidate,\n useResourceParams,\n} from \"@refinedev/core\";\nimport type { FieldValues } from \"react-hook-form\";\n\nimport { useForm, type UseFormProps, type UseFormReturnType } from \"../useForm\";\nimport React from \"react\";\n\nexport type UseModalFormReturnType<\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n> = UseFormReturnType<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> & {\n modal: {\n submit: (values: TVariables) => void;\n close: () => void;\n show: (id?: BaseKey) => void;\n visible: boolean;\n title: string;\n };\n};\n\nexport type UseModalFormProps<\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n> = UseFormProps<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> & {\n /**\n * @description Configuration object for the modal.\n * `defaultVisible`: Initial visibility state of the modal.\n *\n * `autoSubmitClose`: Whether the form should be submitted when the modal is closed.\n *\n * `autoResetForm`: Whether the form should be reset when the form is submitted.\n *\n * `autoResetFormWhenClose`: Whether the form should be reset to defaultValues when the modal is closed.\n * @type `{\n defaultVisible?: boolean;\n autoSubmitClose?: boolean;\n autoResetForm?: boolean;\n autoResetFormWhenClose?: boolean;\n }`\n * @default `defaultVisible = false` `autoSubmitClose = true` `autoResetForm = true` `autoResetFormWhenClose = true`\n */\n modalProps?: {\n defaultVisible?: boolean;\n autoSubmitClose?: boolean;\n autoResetForm?: boolean;\n autoResetFormWhenClose?: boolean;\n };\n} & FormWithSyncWithLocationParams;\n\nexport const useModalForm = <\n TQueryFnData extends BaseRecord = BaseRecord,\n TError extends HttpError = HttpError,\n TVariables extends FieldValues = FieldValues,\n TContext extends object = {},\n TData extends BaseRecord = TQueryFnData,\n TResponse extends BaseRecord = TData,\n TResponseError extends HttpError = TError,\n>({\n modalProps,\n refineCoreProps,\n syncWithLocation,\n ...rest\n}: UseModalFormProps<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> = {}): UseModalFormReturnType<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n> => {\n const invalidate = useInvalidate();\n const [initiallySynced, setInitiallySynced] = React.useState(false);\n\n const translate = useTranslate();\n\n const { resource: resourceProp, action: actionProp } = refineCoreProps ?? {};\n\n const { resource, identifier } = useResourceParams({\n resource: resourceProp,\n });\n const { action: actionFromParams } = useResourceParams({\n resource: resourceProp,\n action: actionProp,\n });\n\n const parsed = useParsed();\n const go = useGo();\n const getUserFriendlyName = useUserFriendlyName();\n\n const action = actionProp ?? actionFromParams ?? \"\";\n\n const syncingId = !(\n typeof syncWithLocation === \"object\" && syncWithLocation?.syncId === false\n );\n\n const syncWithLocationKey =\n typeof syncWithLocation === \"object\" && \"key\" in syncWithLocation\n ? syncWithLocation.key\n : resource && action && syncWithLocation\n ? `modal-${identifier}-${action}`\n : undefined;\n\n const {\n defaultVisible = false,\n autoSubmitClose = true,\n autoResetForm = true,\n autoResetFormWhenClose = true,\n } = modalProps ?? {};\n\n const useHookFormResult = useForm<\n TQueryFnData,\n TError,\n TVariables,\n TContext,\n TData,\n TResponse,\n TResponseError\n >({\n refineCoreProps: {\n ...refineCoreProps,\n meta: {\n ...(syncWithLocationKey ? { [syncWithLocationKey]: undefined } : {}),\n ...refineCoreProps?.meta,\n },\n },\n ...rest,\n });\n\n const {\n reset,\n refineCore: { onFinish, id, setId, autoSaveProps, query },\n saveButtonProps,\n handleSubmit,\n } = useHookFormResult;\n\n const { visible, show, close } = useModal({\n defaultVisible,\n });\n\n // compensate for setting of initial form values in useForm since it doesnt track modal visibility\n React.useEffect(() => {\n if (!visible || !query?.data?.data) return;\n\n const formData = query.data.data;\n if (!formData) return;\n\n reset(formData as any, {\n ...(!autoResetFormWhenClose && {\n keepDirtyValues: true,\n }),\n });\n }, [visible, query?.data?.data, autoResetFormWhenClose]);\n\n React.useEffect(() => {\n if (initiallySynced === false && syncWithLocationKey) {\n const openStatus = parsed?.params?.[syncWithLocationKey]?.open;\n if (typeof openStatus === \"boolean\") {\n if (openStatus) {\n show();\n }\n } else if (typeof openStatus === \"string\") {\n if (openStatus === \"true\") {\n show();\n }\n }\n\n if (syncingId) {\n const idFromParams = parsed?.params?.[syncWithLocationKey]?.id;\n if (idFromParams) {\n setId?.(idFromParams);\n }\n }\n\n setInitiallySynced(true);\n }\n }, [syncWithLocationKey, parsed, syncingId, setId]);\n\n React.useEffect(() => {\n if (initiallySynced === true) {\n if (visible && syncWithLocationKey) {\n go({\n query: {\n [syncWithLocationKey]: {\n ...parsed?.params?.[syncWithLocationKey],\n open: true,\n ...(syncingId && id && { id }),\n },\n },\n options: { keepQuery: true },\n type: \"replace\",\n });\n } else if (syncWithLocationKey && !visible) {\n go({\n query: {\n [syncWithLocationKey]: undefined,\n },\n options: { keepQuery: true },\n type: \"replace\",\n });\n }\n }\n }, [id, visible, show, syncWithLocationKey, syncingId]);\n\n const submit = async (values: TVariables) => {\n await onFinish(values);\n\n if (autoSubmitClose) {\n close();\n }\n\n if (autoResetForm) {\n reset();\n }\n };\n\n const { warnWhen, setWarnWhen } = useWarnAboutChange();\n const handleClose = useCallback(() => {\n if (\n autoSaveProps.status === \"success\" &&\n refineCoreProps?.autoSave?.invalidateOnClose\n ) {\n invalidate({\n id,\n invalidates: refineCoreProps.invalidates || [\"list\", \"many\", \"detail\"],\n dataProviderName: refineCoreProps.dataProviderName,\n resource: identifier,\n });\n }\n\n if (warnWhen) {\n const warnWhenConfirm = window.confirm(\n translate(\n \"warnWhenUnsavedChanges\",\n \"Are you sure you want to leave? You have unsaved changes.\",\n ),\n );\n\n if (warnWhenConfirm) {\n setWarnWhen(false);\n } else {\n return;\n }\n }\n\n setId?.(undefined);\n close();\n\n if (autoResetFormWhenClose) {\n reset();\n }\n }, [warnWhen, autoSaveProps.status]);\n\n const handleShow = useCallback(\n (showId?: BaseKey) => {\n if (typeof showId !== \"undefined\") {\n setId?.(showId);\n }\n const needsIdToOpen = action === \"edit\" || action === \"clone\";\n const hasId = typeof showId !== \"undefined\" || typeof id !== \"undefined\";\n if (needsIdToOpen ? hasId : true) {\n show();\n }\n },\n [id],\n );\n\n const title = translate(\n `${identifier}.titles.${actionProp}`,\n undefined,\n `${getUserFriendlyName(\n `${actionProp} ${resource?.meta?.label ?? identifier}`,\n \"singular\",\n )}`,\n );\n\n return {\n modal: {\n submit,\n close: handleClose,\n show: handleShow,\n visible,\n title,\n },\n ...useHookFormResult,\n saveButtonProps: {\n ...saveButtonProps,\n onClick: (e) => handleSubmit(submit)(e),\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAiC;AACjC,iBAAgB;AAChB,iBAAgB;AAEhB,6BAOO;AACP,kBAUO;AA2DA,IAAM,UAAU,wBAQrB;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,EACxB,6BAA6B,kCAAkC;AAAA,EAC/D,GAAG;AACL,IAQI,CAAC,MAQA;AACH,QAAM,EAAE,QAAQ,QAAI,8BAAiB;AACrC,QAAM,+BACJ,mCAAS,gCAA+B;AAE1C,QAAM,gBAAY,0BAAa;AAE/B,QAAM,EAAE,wBAAwB,8BAA8B,YAAY,QACxE,gCAAmB;AACrB,QAAM,yBACJ,8BAA8B;AAEhC,QAAM,wBAAoB,uBAAAA,SAAkC;AAAA,IAC1D,GAAG;AAAA,EACL,CAAC;AAED,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,EACF,IAAI;AAEJ,QAAM,wBAAoB,YAAAC,SAOxB;AAAA,IACA,GAAG;AAAA,IACH,iBAAiB,CAAC,OAAO,YAAY,aAAa;AA/ItD;AAgJM,UAAI,6BAA6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gBAAgB,WAAW,UAAU,WAAW;AACtD,YAAM,QAAQ,OAAO,WAAW,eAAe,OAAO,OAAO;AAC7D,UAAI,gBAAgB,QAAQ,MAAM;AAChC,aAAK;AAAA,MACP;AAAA,IACF;AAAA,IACA,CAAC,EAAE;AAAA,EACL;AAEA,QAAM,QAAQ;AAAA,IACZ,GAAG,qBAAqB;AAAA,IACxB;AAAA,IACA,GAAG;AAAA,MACD,GAAG,gBAAc,0CAAU,SAAV,mBAAgB,UAAS;AAAA,MAC1C;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO;AAAA,MACL;AAAA,MACA,OAAO;AAAA,MACP,MAAM;AAAA,MACN;AAAA,MACA;AAAA,IACF;AAAA,IACA,GAAG;AAAA,IACH,iBAAiB;AAAA,MACf,GAAG;AAAA,MACH,SAAS,CAAC,MAAM,aAAa,MAAM,EAAE,CAAC;AAAA,IACxC;AAAA,EACF;AACF,GAzP4B;","names":["useHookForm","useFormCore","has","get","import_react","import_get","get","import_react","import_core","import_react","React","_a","_b"]}
|