@overmap-ai/core 1.0.35-fix-token-refresh-loop.2 → 1.0.35-fix-token-refresh-loop.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.
@@ -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>>>;
@@ -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 handlePatch = useCallback(
10234
+ const getDiff = useCallback(
10235
10235
  (values2) => {
10236
10236
  const diff = {};
10237
10237
  for (const key in values2) {
@@ -10240,11 +10240,18 @@ 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
- [initialValues2, onPatch, requiresDiff]
10254
+ [getDiff, onPatch, requiresDiff]
10248
10255
  );
10249
10256
  const validate = useCallback(
10250
10257
  (form) => {
@@ -10252,9 +10259,13 @@ const PatchFormProvider = memo(
10252
10259
  if (error2) {
10253
10260
  onError(error2);
10254
10261
  }
10262
+ if (onDirtyChange) {
10263
+ const diff = getDiff(form);
10264
+ onDirtyChange(hasKeys(diff));
10265
+ }
10255
10266
  return error2;
10256
10267
  },
10257
- [schema, onError]
10268
+ [schema, onDirtyChange, onError, getDiff]
10258
10269
  );
10259
10270
  const formik = useFormik({
10260
10271
  initialValues: initialValues2,