@overmap-ai/core 1.0.35-fix-token-refresh-loop.2 → 1.0.35-fix-token-refresh-loop.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -21,6 +21,8 @@ interface PatchFormProviderProps {
|
|
|
21
21
|
className?: string;
|
|
22
22
|
/** If true, the form will only submit if there are changes. */
|
|
23
23
|
requiresDiff?: boolean;
|
|
24
|
+
/** Called when the form's dirty state changes. */
|
|
25
|
+
onDirtyChange?: (dirty: boolean) => void;
|
|
24
26
|
}
|
|
25
27
|
/** Use PatchForms to create patch edits to existing forms rather than editing the entire form. */
|
|
26
28
|
export declare const PatchFormProvider: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<PatchFormProviderProps & import("react").RefAttributes<HTMLFormElement>>>;
|
package/dist/overmap-core.js
CHANGED
|
@@ -10229,9 +10229,9 @@ const PatchField = memo((props) => {
|
|
|
10229
10229
|
PatchField.displayName = "PatchField";
|
|
10230
10230
|
const PatchFormProvider = memo(
|
|
10231
10231
|
forwardRef((props, ref) => {
|
|
10232
|
-
const { children, schema, values, onPatch, onError, requiresDiff = true, ...rest } = props;
|
|
10232
|
+
const { children, schema, values, onPatch, onError, requiresDiff = true, onDirtyChange, ...rest } = props;
|
|
10233
10233
|
const initialValues2 = useMemo(() => initialFormValues(schema.fields, values), [schema.fields, values]);
|
|
10234
|
-
const
|
|
10234
|
+
const getDiff = useCallback(
|
|
10235
10235
|
(values2) => {
|
|
10236
10236
|
const diff = {};
|
|
10237
10237
|
for (const key in values2) {
|
|
@@ -10240,21 +10240,33 @@ const PatchFormProvider = memo(
|
|
|
10240
10240
|
diff[key] = value;
|
|
10241
10241
|
}
|
|
10242
10242
|
}
|
|
10243
|
+
return diff;
|
|
10244
|
+
},
|
|
10245
|
+
[initialValues2]
|
|
10246
|
+
);
|
|
10247
|
+
const handlePatch = useCallback(
|
|
10248
|
+
(values2) => {
|
|
10249
|
+
const diff = getDiff(values2);
|
|
10243
10250
|
if (requiresDiff && !hasKeys(diff))
|
|
10244
10251
|
return;
|
|
10245
10252
|
onPatch(diff);
|
|
10246
10253
|
},
|
|
10247
|
-
[
|
|
10254
|
+
[getDiff, onPatch, requiresDiff]
|
|
10248
10255
|
);
|
|
10249
10256
|
const validate = useCallback(
|
|
10250
10257
|
(form) => {
|
|
10258
|
+
console.debug("VALIDATING FORM:", form);
|
|
10251
10259
|
const error2 = validateForm(schema, form);
|
|
10252
10260
|
if (error2) {
|
|
10253
10261
|
onError(error2);
|
|
10254
10262
|
}
|
|
10263
|
+
if (onDirtyChange) {
|
|
10264
|
+
const diff = getDiff(form);
|
|
10265
|
+
onDirtyChange(hasKeys(diff));
|
|
10266
|
+
}
|
|
10255
10267
|
return error2;
|
|
10256
10268
|
},
|
|
10257
|
-
[schema, onError]
|
|
10269
|
+
[schema, onDirtyChange, onError, getDiff]
|
|
10258
10270
|
);
|
|
10259
10271
|
const formik = useFormik({
|
|
10260
10272
|
initialValues: initialValues2,
|
|
@@ -10264,13 +10276,21 @@ const PatchFormProvider = memo(
|
|
|
10264
10276
|
validateOnBlur: false,
|
|
10265
10277
|
validateOnChange: false
|
|
10266
10278
|
});
|
|
10279
|
+
const handleBlur = useCallback(() => {
|
|
10280
|
+
if (onDirtyChange) {
|
|
10281
|
+
const diff = getDiff(formik.values);
|
|
10282
|
+
if (hasKeys(diff)) {
|
|
10283
|
+
onDirtyChange(true);
|
|
10284
|
+
}
|
|
10285
|
+
}
|
|
10286
|
+
}, [formik.values, getDiff, onDirtyChange]);
|
|
10267
10287
|
const { errors, resetForm } = formik;
|
|
10268
10288
|
useEffect(() => {
|
|
10269
10289
|
if (hasKeys(errors)) {
|
|
10270
10290
|
resetForm({ values: initialValues2, errors: {} });
|
|
10271
10291
|
}
|
|
10272
10292
|
}, [errors, initialValues2, resetForm]);
|
|
10273
|
-
return /* @__PURE__ */ jsx(FormikProvider, { value: formik, children: /* @__PURE__ */ jsx("form", { ...rest, ref, onSubmit: formik.handleSubmit, children }) });
|
|
10293
|
+
return /* @__PURE__ */ jsx(FormikProvider, { value: formik, children: /* @__PURE__ */ jsx("form", { ...rest, ref, onSubmit: formik.handleSubmit, onBlur: handleBlur, children }) });
|
|
10274
10294
|
})
|
|
10275
10295
|
);
|
|
10276
10296
|
const typeBadge$1 = "_typeBadge_an5ff_1";
|