@helpwave/hightide 0.6.0 → 0.6.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.d.mts CHANGED
@@ -241,6 +241,7 @@ declare class FormStore<T extends FormValue> {
241
241
  getTouched(key: keyof T): boolean;
242
242
  setTouched(key: keyof T, isTouched?: boolean): void;
243
243
  getHasError(): boolean;
244
+ getErrors(): Partial<Record<keyof T, ReactNode>>;
244
245
  getError(key: keyof T): ReactNode;
245
246
  private setError;
246
247
  changeValidationBehavoir(validationBehaviour: FormValidationBehaviour): void;
@@ -284,10 +285,13 @@ type UseCreateFormResult<T extends FormValue> = {
284
285
  store: FormStore<T>;
285
286
  reset: () => void;
286
287
  submit: () => void;
287
- update: (value: Partial<T>) => void;
288
+ update: (updater: Partial<T> | ((current: T) => Partial<T>)) => void;
288
289
  validateAll: () => void;
289
290
  getDataProps: <K extends keyof T>(key: K) => FormFieldDataHandling<T[K]>;
290
291
  getError: (key: keyof T) => ReactNode;
292
+ getErrors: () => Partial<Record<keyof T, ReactNode>>;
293
+ getIsValid: () => boolean;
294
+ getValues: () => T;
291
295
  getValue: <K extends keyof T>(key: K) => T[K];
292
296
  registerRef: (key: keyof T) => (el: HTMLElement | null) => void;
293
297
  };
package/dist/index.d.ts CHANGED
@@ -241,6 +241,7 @@ declare class FormStore<T extends FormValue> {
241
241
  getTouched(key: keyof T): boolean;
242
242
  setTouched(key: keyof T, isTouched?: boolean): void;
243
243
  getHasError(): boolean;
244
+ getErrors(): Partial<Record<keyof T, ReactNode>>;
244
245
  getError(key: keyof T): ReactNode;
245
246
  private setError;
246
247
  changeValidationBehavoir(validationBehaviour: FormValidationBehaviour): void;
@@ -284,10 +285,13 @@ type UseCreateFormResult<T extends FormValue> = {
284
285
  store: FormStore<T>;
285
286
  reset: () => void;
286
287
  submit: () => void;
287
- update: (value: Partial<T>) => void;
288
+ update: (updater: Partial<T> | ((current: T) => Partial<T>)) => void;
288
289
  validateAll: () => void;
289
290
  getDataProps: <K extends keyof T>(key: K) => FormFieldDataHandling<T[K]>;
290
291
  getError: (key: keyof T) => ReactNode;
292
+ getErrors: () => Partial<Record<keyof T, ReactNode>>;
293
+ getIsValid: () => boolean;
294
+ getValues: () => T;
291
295
  getValue: <K extends keyof T>(key: K) => T[K];
292
296
  registerRef: (key: keyof T) => (el: HTMLElement | null) => void;
293
297
  };
package/dist/index.js CHANGED
@@ -7548,6 +7548,9 @@ var FormStore = class {
7548
7548
  getHasError() {
7549
7549
  return Object.values(this.errors).some((value) => value !== void 0 && value !== null);
7550
7550
  }
7551
+ getErrors() {
7552
+ return { ...this.errors };
7553
+ }
7551
7554
  getError(key) {
7552
7555
  return this.errors[key];
7553
7556
  }
@@ -7726,15 +7729,27 @@ function useCreateForm({
7726
7729
  }
7727
7730
  };
7728
7731
  }, []);
7729
- return {
7730
- store: storeRef.current,
7732
+ const callbacks = (0, import_react7.useMemo)(() => ({
7731
7733
  reset: () => storeRef.current.reset(),
7732
7734
  submit: () => storeRef.current.submit(),
7733
- update: (value) => storeRef.current.setValues(value),
7735
+ update: (updater) => {
7736
+ if (typeof updater === "function") {
7737
+ storeRef.current.setValues(updater(storeRef.current.getAllValues()));
7738
+ } else {
7739
+ storeRef.current.setValues(updater);
7740
+ }
7741
+ },
7734
7742
  validateAll: () => storeRef.current.validateAll(),
7735
- getDataProps,
7736
7743
  getError: (key) => storeRef.current.getError(key),
7744
+ getErrors: () => storeRef.current.getErrors(),
7745
+ getIsValid: () => !storeRef.current.getHasError(),
7737
7746
  getValue: (key) => storeRef.current.getValue(key),
7747
+ getValues: () => storeRef.current.getAllValues()
7748
+ }), []);
7749
+ return {
7750
+ store: storeRef.current,
7751
+ ...callbacks,
7752
+ getDataProps,
7738
7753
  registerRef
7739
7754
  };
7740
7755
  }