@goodie-forms/react 1.2.5-alpha → 1.3.0

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.
Files changed (39) hide show
  1. package/README.md +61 -0
  2. package/dist/components/FieldRenderer.d.ts +9 -13
  3. package/dist/components/FieldRenderer.d.ts.map +1 -1
  4. package/dist/hooks/useFieldIssues.d.ts +4 -0
  5. package/dist/hooks/useFieldIssues.d.ts.map +1 -0
  6. package/dist/hooks/useFieldValue.d.ts +1 -1
  7. package/dist/hooks/useFieldValue.d.ts.map +1 -1
  8. package/dist/hooks/useForm.d.ts +18 -6
  9. package/dist/hooks/useForm.d.ts.map +1 -1
  10. package/dist/hooks/useFormField.d.ts +3 -2
  11. package/dist/hooks/useFormField.d.ts.map +1 -1
  12. package/dist/hooks/useSyncMutableStore.d.ts +2 -0
  13. package/dist/hooks/useSyncMutableStore.d.ts.map +1 -0
  14. package/dist/index.d.ts +1 -4
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +140 -169
  17. package/dist/index.js.map +1 -1
  18. package/package.json +15 -2
  19. package/dist/hooks/useFieldErrors.d.ts +0 -4
  20. package/dist/hooks/useFieldErrors.d.ts.map +0 -1
  21. package/dist/hooks/useFormErrorObserver.d.ts +0 -7
  22. package/dist/hooks/useFormErrorObserver.d.ts.map +0 -1
  23. package/dist/hooks/useFormValuesObserver.d.ts +0 -7
  24. package/dist/hooks/useFormValuesObserver.d.ts.map +0 -1
  25. package/dist/hooks/useRenderControl.d.ts +0 -5
  26. package/dist/hooks/useRenderControl.d.ts.map +0 -1
  27. package/src/components/FieldRenderer.tsx +0 -166
  28. package/src/hooks/useFieldErrors.ts +0 -31
  29. package/src/hooks/useFieldValue.ts +0 -31
  30. package/src/hooks/useForm.tsx +0 -50
  31. package/src/hooks/useFormErrorObserver.ts +0 -45
  32. package/src/hooks/useFormField.tsx +0 -63
  33. package/src/hooks/useFormValuesObserver.ts +0 -50
  34. package/src/hooks/useRenderControl.tsx +0 -26
  35. package/src/index.ts +0 -9
  36. package/src/utils/composeFns.ts +0 -7
  37. package/src/utils/groupBy.ts +0 -13
  38. package/tsconfig.json +0 -8
  39. package/vite.config.ts +0 -23
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ <!-- Logo -->
2
+ <p align="center">
3
+ <img src="https://raw.githubusercontent.com/iGoodie/goodie-forms/master/.github/assets/logo.svg" height="200px" alt="Logo"/>
4
+ </p>
5
+
6
+ <!-- Slogan -->
7
+ <p align="center">
8
+ An unopinionated modern form state and data management library
9
+ </p>
10
+ <!-- Badges -->
11
+ <p align="center">
12
+
13
+ <!-- Main Badges -->
14
+ <img src="https://raw.githubusercontent.com/iGoodie/paper-editor/master/.github/assets/main-badge.svg" height="20px"/>
15
+ <a href="https://www.npmjs.com/package/@goodie-forms/react">
16
+ <img src="https://img.shields.io/npm/v/@goodie-forms/react"/>
17
+ </a>
18
+ <a href="https://github.com/iGoodie/goodie-forms/tags">
19
+ <img src="https://img.shields.io/github/v/tag/iGoodie/goodie-forms"/>
20
+ </a>
21
+ <a href="https://github.com/iGoodie/goodie-forms">
22
+ <img src="https://img.shields.io/github/languages/top/iGoodie/goodie-forms"/>
23
+ </a>
24
+
25
+ <br/>
26
+
27
+ <!-- Github Badges -->
28
+ <img src="https://raw.githubusercontent.com/iGoodie/paper-editor/master/.github/assets/github-badge.svg" height="20px"/>
29
+ <a href="https://github.com/iGoodie/goodie-forms/commits/master">
30
+ <img src="https://img.shields.io/github/last-commit/iGoodie/goodie-forms"/>
31
+ </a>
32
+ <a href="https://github.com/iGoodie/goodie-forms/issues">
33
+ <img src="https://img.shields.io/github/issues/iGoodie/goodie-forms"/>
34
+ </a>
35
+ <a href="https://github.com/iGoodie/goodie-forms/tree/master/src">
36
+ <img src="https://img.shields.io/github/languages/code-size/iGoodie/goodie-forms"/>
37
+ </a>
38
+
39
+ <br/>
40
+
41
+ <!-- Support Badges -->
42
+ <img src="https://raw.githubusercontent.com/iGoodie/paper-editor/master/.github/assets/support-badge.svg" height="20px"/>
43
+ <a href="https://discord.gg/KNxxdvN">
44
+ <img src="https://img.shields.io/discord/610497509437210624?label=discord"/>
45
+ </a>
46
+ <a href="https://www.patreon.com/iGoodie">
47
+ <img src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3DiGoodie%26type%3Dpatrons"/>
48
+ </a>
49
+ </p>
50
+
51
+ # Description
52
+
53
+ React package of Goodie Forms.
54
+
55
+ ## License
56
+
57
+ &copy; 2026 Taha Anılcan Metinyurt (iGoodie)
58
+
59
+ For any part of this work for which the license is applicable, this work is licensed under the [Attribution-ShareAlike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/) license. (See LICENSE).
60
+
61
+ <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a>
@@ -1,29 +1,25 @@
1
- import { FieldPath, FormField, NonnullFormField } from '../../../core/src';
1
+ import { DeepReadonly, FieldPath, FormField, Suppliable } from '../../../core/src';
2
2
  import { ChangeEvent, ReactNode, Ref } from 'react';
3
3
  import { UseForm } from '../hooks/useForm';
4
4
  export interface RenderParams<TOutput extends object, TValue> {
5
5
  fieldProps: {
6
6
  ref: Ref<any | null>;
7
- value: TValue | undefined;
7
+ name: string;
8
+ value: DeepReadonly<TValue> | undefined;
8
9
  onChange: (event: ChangeEvent<EventTarget> | TValue) => void;
9
10
  onFocus: () => void;
10
11
  onBlur: () => void;
11
12
  };
12
- field: undefined extends TValue ? FormField<TOutput, TValue> : NonnullFormField<TOutput, TValue>;
13
+ field: FormField<TOutput, TValue>;
13
14
  form: UseForm<TOutput>;
14
15
  }
15
- type DefaultValueProps<TValue> = undefined extends TValue ? {
16
- defaultValue?: TValue | (() => TValue);
17
- } : {
18
- defaultValue: TValue | (() => TValue);
19
- };
20
- export type FieldRendererProps<TOutput extends object, TPath extends FieldPath.Segments> = {
16
+ export interface FieldRendererProps<TOutput extends object, TPath extends FieldPath.Segments> {
21
17
  form: UseForm<TOutput>;
22
18
  path: TPath;
19
+ defaultValue?: Suppliable<FieldPath.Resolve<TOutput, TPath>>;
23
20
  overrideInitialValue?: boolean;
24
- unbindOnUnmount?: boolean;
25
- render: (params: RenderParams<TOutput, FieldPath.Resolve<TOutput, NoInfer<TPath>>>) => ReactNode;
26
- } & DefaultValueProps<FieldPath.Resolve<TOutput, NoInfer<TPath>>>;
21
+ unregisterOnUnmount?: boolean;
22
+ render: (params: RenderParams<TOutput, FieldPath.Resolve<TOutput, TPath>>) => ReactNode;
23
+ }
27
24
  export declare function FieldRenderer<TOutput extends object, const TPath extends FieldPath.Segments>(props: FieldRendererProps<TOutput, TPath>): import("react/jsx-runtime").JSX.Element;
28
- export {};
29
25
  //# sourceMappingURL=FieldRenderer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FieldRenderer.d.ts","sourceRoot":"","sources":["../../src/components/FieldRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,EAAqB,MAAM,OAAO,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAI3C,MAAM,WAAW,YAAY,CAAC,OAAO,SAAS,MAAM,EAAE,MAAM;IAC1D,UAAU,EAAE;QACV,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;QAErB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;QAE1B,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,WAAW,CAAC,GAAG,MAAM,KAAK,IAAI,CAAC;QAC7D,OAAO,EAAE,MAAM,IAAI,CAAC;QACpB,MAAM,EAAE,MAAM,IAAI,CAAC;KACpB,CAAC;IAEF,KAAK,EAAE,SAAS,SA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AO,EAAE,KAAK,CAAC,2CAqF1C"}
@@ -0,0 +1,4 @@
1
+ import { FieldPath } from '../../../core/src';
2
+ import { UseForm } from './useForm';
3
+ export declare function useFieldIssues<TOutput extends object, TPath extends FieldPath.Segments>(form: UseForm<TOutput>, path: TPath): import("@standard-schema/spec").StandardSchemaV1.Issue[];
4
+ //# sourceMappingURL=useFieldIssues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFieldIssues.d.ts","sourceRoot":"","sources":["../../src/hooks/useFieldIssues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,wBAAgB,cAAc,CAC5B,OAAO,SAAS,MAAM,EACtB,KAAK,SAAS,SAAS,CAAC,QAAQ,EAChC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,4DAiCpC"}
@@ -1,4 +1,4 @@
1
1
  import { FieldPath } from '../../../core/src';
2
2
  import { UseForm } from '../hooks/useForm';
3
- export declare function useFieldValue<TOutput extends object, TPath extends FieldPath.Segments>(form: UseForm<TOutput>, path: TPath): FieldPath.Resolve<TOutput, TPath> | undefined;
3
+ export declare function useFieldValue<TOutput extends object, TPath extends FieldPath.Segments>(form: UseForm<TOutput>, path: TPath): import('../../../core/src').DeepReadonly<FieldPath.Resolve<TOutput, TPath>> | undefined;
4
4
  //# sourceMappingURL=useFieldValue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFieldValue.d.ts","sourceRoot":"","sources":["../../src/hooks/useFieldValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAI3C,wBAAgB,aAAa,CAC3B,OAAO,SAAS,MAAM,EACtB,KAAK,SAAS,SAAS,CAAC,QAAQ,EAChC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,iDAqBpC"}
1
+ {"version":3,"file":"useFieldValue.d.ts","sourceRoot":"","sources":["../../src/hooks/useFieldValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAG3C,wBAAgB,aAAa,CAC3B,OAAO,SAAS,MAAM,EACtB,KAAK,SAAS,SAAS,CAAC,QAAQ,EAChC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,4FAoCpC"}
@@ -1,19 +1,31 @@
1
- import { FieldPathBuilder, FormController } from '../../../core/src';
1
+ import { FormController } from '../../../core/src';
2
2
  export declare function useForm<TOutput extends object>(formConfigs: FormController.Configs<TOutput>, hookConfigs?: {
3
3
  validateMode?: "onChange" | "onBlur" | "onSubmit";
4
4
  revalidateMode?: "onChange" | "onBlur" | "onSubmit";
5
- watchIssues?: boolean;
6
- watchValues?: boolean;
7
5
  }): {
8
6
  formConfigs: FormController.Configs<TOutput>;
9
- paths: FieldPathBuilder<TOutput>;
10
7
  hookConfigs: {
11
8
  validateMode?: "onChange" | "onBlur" | "onSubmit";
12
9
  revalidateMode?: "onChange" | "onBlur" | "onSubmit";
13
- watchIssues?: boolean;
14
- watchValues?: boolean;
15
10
  } | undefined;
16
11
  controller: FormController<TOutput>;
12
+ path: import('../../../core/src').FieldPathBuilder<TOutput>;
13
+ watchValues: () => import('../../../core/src').DeepReadonly<import('../../../core/src').DeepPartial<TOutput>>;
14
+ watchIssues: () => readonly import("@standard-schema/spec").StandardSchemaV1.Issue[];
15
+ watchEvent: <E extends "fieldTouchUpdated" | "submissionStatusChange" | "validationStatusChange" | "fieldRegistered" | "fieldUnregistered" | "fieldDirtyUpdated" | "fieldIssuesUpdated" | "fieldReset" | "elementBound" | "elementUnbound" | "fieldValidationTriggered" | "fieldValueChanged">(eventName: E, listener?: NonNullable<Partial<{
16
+ submissionStatusChange: ((isSubmitting: boolean) => void)[];
17
+ validationStatusChange: ((isValidating: boolean) => void)[];
18
+ fieldRegistered: ((fieldPath: import("@goodie-forms/core").FieldPath.Segments) => void)[];
19
+ fieldUnregistered: ((fieldPath: import("@goodie-forms/core").FieldPath.Segments) => void)[];
20
+ fieldTouchUpdated: ((path: import("@goodie-forms/core").FieldPath.Segments) => void)[];
21
+ fieldDirtyUpdated: ((path: import("@goodie-forms/core").FieldPath.Segments) => void)[];
22
+ fieldIssuesUpdated: ((fieldPath: import("@goodie-forms/core").FieldPath.Segments) => void)[];
23
+ fieldReset: ((fieldPath: import("@goodie-forms/core").FieldPath.Segments) => void)[];
24
+ elementBound: ((fieldPath: import("@goodie-forms/core").FieldPath.Segments, el: HTMLElement) => void)[];
25
+ elementUnbound: ((fieldPath: import("@goodie-forms/core").FieldPath.Segments) => void)[];
26
+ fieldValidationTriggered: ((fieldPath: import("@goodie-forms/core").FieldPath.Segments) => void)[];
27
+ fieldValueChanged: ((fieldPath: import("@goodie-forms/core").FieldPath.Segments, newValue: {} | undefined, oldValue: {} | undefined) => void)[];
28
+ }>[E]>[number]) => undefined;
17
29
  };
18
30
  export type UseForm<TOutput extends object> = ReturnType<typeof useForm<TOutput>>;
19
31
  //# sourceMappingURL=useForm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../src/hooks/useForm.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAKtE,wBAAgB,OAAO,CAAC,OAAO,SAAS,MAAM,EAC5C,WAAW,EAAE,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,EAC5C,WAAW,CAAC,EAAE;IACZ,YAAY,CAAC,EAAE,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC;IAClD,cAAc,CAAC,EAAE,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC;IACpD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;;;;uBAJgB,UAAU,GAAG,QAAQ,GAAG,UAAU;yBAChC,UAAU,GAAG,QAAQ,GAAG,UAAU;sBACrC,OAAO;sBACP,OAAO;;;EAkCxB;AAED,MAAM,MAAM,OAAO,CAAC,OAAO,SAAS,MAAM,IAAI,UAAU,CACtD,OAAO,OAAO,CAAC,OAAO,CAAC,CACxB,CAAC"}
1
+ {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../src/hooks/useForm.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIpD,wBAAgB,OAAO,CAAC,OAAO,SAAS,MAAM,EAC5C,WAAW,EAAE,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,EAC5C,WAAW,CAAC,EAAE;IACZ,YAAY,CAAC,EAAE,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC;IAClD,cAAc,CAAC,EAAE,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC;CACrD;;;uBAFgB,UAAU,GAAG,QAAQ,GAAG,UAAU;yBAChC,UAAU,GAAG,QAAQ,GAAG,UAAU;;;;;;iBAgC9B,CAAC,4RACX,CAAC,aACD,WAAW;;;;;;;;;;;;;UAAsC,CAAC,MAAM,CAAC;EAqBvE;AAED,MAAM,MAAM,OAAO,CAAC,OAAO,SAAS,MAAM,IAAI,UAAU,CACtD,OAAO,OAAO,CAAC,OAAO,CAAC,CACxB,CAAC"}
@@ -1,4 +1,5 @@
1
- import { FieldPath } from '../../../core/src';
1
+ import { FieldPath, FormField } from '../../../core/src';
2
2
  import { UseForm } from '../hooks/useForm';
3
- export declare function useFormField<TOutput extends object, TPath extends FieldPath.Segments>(form: UseForm<TOutput>, path: TPath, bindingConfig?: Parameters<typeof form.controller.bindField<TPath>>[1]): import('../../../core/src').FormField<TOutput, FieldPath.Resolve<TOutput, TPath>> | undefined;
3
+ export declare function useFormField<TOutput extends object, TPath extends FieldPath.Segments>(form: UseForm<TOutput>, path: TPath): FormField<TOutput, FieldPath.Resolve<TOutput, TPath>> | undefined;
4
+ export declare function useFormField<TOutput extends object, TPath extends FieldPath.Segments>(form: UseForm<TOutput>, path: TPath, registerConfig: Parameters<typeof form.controller.registerField<TPath>>[1]): FormField<TOutput, FieldPath.Resolve<TOutput, TPath>>;
4
5
  //# sourceMappingURL=useFormField.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFormField.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAI3C,wBAAgB,YAAY,CAC1B,OAAO,SAAS,MAAM,EACtB,KAAK,SAAS,SAAS,CAAC,QAAQ,EAEhC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,EACtB,IAAI,EAAE,KAAK,EACX,aAAa,CAAC,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,kGAkDvE"}
1
+ {"version":3,"file":"useFormField.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAI3C,wBAAgB,YAAY,CAC1B,OAAO,SAAS,MAAM,EACtB,KAAK,SAAS,SAAS,CAAC,QAAQ,EAEhC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,EACtB,IAAI,EAAE,KAAK,GACV,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,GAAG,SAAS,CAAC;AAErE,wBAAgB,YAAY,CAC1B,OAAO,SAAS,MAAM,EACtB,KAAK,SAAS,SAAS,CAAC,QAAQ,EAEhC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,EACtB,IAAI,EAAE,KAAK,EACX,cAAc,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GACzE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function useSyncMutableStore<T>(subscribe: (onVersionChange: () => void) => () => void, getValue: () => T): T;
2
+ //# sourceMappingURL=useSyncMutableStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSyncMutableStore.d.ts","sourceRoot":"","sources":["../../src/hooks/useSyncMutableStore.ts"],"names":[],"mappings":"AAEA,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,SAAS,EAAE,CAAC,eAAe,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,EACtD,QAAQ,EAAE,MAAM,CAAC,KAqBlB"}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,6 @@
1
1
  export * from './hooks/useForm';
2
2
  export * from './hooks/useFormField';
3
3
  export * from './hooks/useFieldValue';
4
- export * from './hooks/useFieldErrors';
5
- export * from './hooks/useFormValuesObserver';
6
- export * from './hooks/useFormErrorObserver';
7
- export * from './hooks/useRenderControl';
4
+ export * from './hooks/useFieldIssues';
8
5
  export * from './components/FieldRenderer';
9
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,4BAA4B,CAAC"}
package/dist/index.js CHANGED
@@ -1,200 +1,171 @@
1
- import { FormController as F, FieldPathBuilder as m, FieldPath as u } from "@goodie-forms/core";
2
- import { useState as f, useRef as v, startTransition as C, useEffect as c } from "react";
3
- import { jsx as R, Fragment as g } from "react/jsx-runtime";
4
- function a() {
5
- const [, e] = f(0), n = v(0), t = v(!1);
6
- n.current++;
7
- const o = () => {
8
- t.current || (t.current = !0, queueMicrotask(() => {
9
- C(() => {
10
- e((r) => r + 1);
11
- }), t.current = !1;
12
- }));
13
- };
1
+ import { FormController as V, FieldPath as i } from "@goodie-forms/core";
2
+ import { useRef as v, useCallback as d, useSyncExternalStore as f, useState as g, useEffect as m } from "react";
3
+ import { jsx as U, Fragment as I } from "react/jsx-runtime";
4
+ function a(u, n) {
5
+ const e = v(0), l = d(
6
+ (r) => u(() => {
7
+ e.current++, r();
8
+ }),
9
+ [u]
10
+ ), o = d(() => e.current, []);
11
+ return f(l, o, o), n();
12
+ }
13
+ function M(u, n) {
14
+ const [e] = g(() => new V(u)), l = d(
15
+ (t) => e.events.on("submissionStatusChange", t),
16
+ [e]
17
+ );
18
+ a(l, () => e);
19
+ const o = () => f(
20
+ (t) => e.events.on("fieldValueChanged", t),
21
+ () => e.data,
22
+ () => e.data
23
+ ), r = () => f(
24
+ (t) => e.events.on("fieldIssuesUpdated", t),
25
+ () => e.issues,
26
+ () => e.issues
27
+ ), s = (t, F) => a(
28
+ (b) => e.events.on(t, (...q) => {
29
+ F?.(...q), b();
30
+ }),
31
+ () => {
32
+ }
33
+ );
14
34
  return {
15
- renderCount: n.current,
16
- forceRerender: o
35
+ formConfigs: u,
36
+ hookConfigs: n,
37
+ controller: e,
38
+ path: e.path,
39
+ watchValues: o,
40
+ watchIssues: r,
41
+ watchEvent: s
17
42
  };
18
43
  }
19
- function i(...e) {
44
+ function c(...u) {
20
45
  return () => {
21
- for (const n of e)
46
+ for (const n of u)
22
47
  n();
23
48
  };
24
49
  }
25
- function U(e, n) {
26
- const [t] = f(() => new F(e)), [o] = f(() => new m()), r = a();
27
- return c(() => {
28
- const l = () => {
29
- };
30
- return i(
31
- t.events.on("submissionStatusChange", () => {
32
- r.forceRerender();
33
- }),
34
- n?.watchIssues ? t.events.on(
35
- "fieldIssuesUpdated",
36
- () => r.forceRerender()
37
- ) : l,
38
- n?.watchValues ? t.events.on(
39
- "valueChanged",
40
- () => r.forceRerender()
41
- ) : l
42
- );
43
- }, [t]), {
44
- formConfigs: e,
45
- paths: o,
46
- hookConfigs: n,
47
- controller: t
48
- };
49
- }
50
- function h(e, n, t) {
51
- const o = a(), [r, l] = f(() => {
52
- let d = e.controller.getField(n);
53
- return d == null && t != null && (d = e.controller.bindField(n, t)), d;
54
- });
55
- return c(() => {
56
- const { events: d } = e.controller;
57
- return l(e.controller.getField(n)), i(
58
- d.on("fieldBound", (s) => {
59
- u.equals(s, n) && l(e.controller.getField(n));
60
- }),
61
- d.on("fieldUnbound", (s) => {
62
- u.equals(s, n) && l(void 0);
63
- }),
64
- d.on("valueChanged", (s) => {
65
- (u.equals(s, n) || u.isDescendant(s, n)) && o.forceRerender();
66
- }),
67
- d.on("fieldTouchUpdated", (s) => {
68
- u.equals(s, n) && o.forceRerender();
69
- }),
70
- d.on("fieldDirtyUpdated", (s) => {
71
- u.equals(s, n) && o.forceRerender();
72
- }),
73
- d.on("fieldIssuesUpdated", (s) => {
74
- u.equals(s, n) && o.forceRerender();
75
- })
76
- );
77
- }, []), r;
78
- }
79
- function w(e, n) {
80
- const t = a(), o = e.controller.getField(n)?.value;
81
- return c(() => i(
82
- e.controller.events.on("fieldBound", (r) => {
83
- u.equals(n, r) && t.forceRerender();
84
- }),
85
- e.controller.events.on("valueChanged", (r) => {
86
- u.equals(n, r) && t.forceRerender();
87
- })
88
- ), []), o;
89
- }
90
- function B(e, n) {
91
- const t = a(), o = e.controller.getField(n)?.issues;
92
- return c(() => i(
93
- e.controller.events.on("fieldBound", (r) => {
94
- u.equals(n, r) && t.forceRerender();
95
- }),
96
- e.controller.events.on("fieldIssuesUpdated", (r) => {
97
- u.equals(n, r) && t.forceRerender();
98
- })
99
- ), []), o;
100
- }
101
- function y(e, n) {
102
- const t = a(), o = n?.include == null ? e.controller._data : n.include.reduce((r, l) => {
103
- const d = u.getValue(
104
- e.controller._data,
105
- l
106
- );
107
- return u.setValue(r, l, d), r;
108
- }, {});
109
- return c(() => {
110
- const { events: r } = e.controller;
111
- return i(
112
- r.on("valueChanged", (l) => {
113
- (n?.include == null || n.include.some(
114
- (s) => u.equals(s, l) || u.isDescendant(s, l)
115
- )) && t.forceRerender();
116
- })
117
- );
118
- }, []), o;
50
+ function R(u, n, e) {
51
+ const { controller: l } = u;
52
+ g(() => (!l.getField(n) && e && l.registerField(n, e), null));
53
+ const o = d(
54
+ (r) => {
55
+ const { events: s } = l;
56
+ return c(
57
+ s.on("fieldRegistered", (t) => {
58
+ i.equals(t, n) && r();
59
+ }),
60
+ s.on("fieldUnregistered", (t) => {
61
+ i.equals(t, n) && r();
62
+ }),
63
+ s.on("fieldValueChanged", (t) => {
64
+ (i.equals(t, n) || i.isDescendant(t, n)) && r();
65
+ }),
66
+ s.on("fieldTouchUpdated", (t) => {
67
+ i.equals(t, n) && r();
68
+ }),
69
+ s.on("fieldDirtyUpdated", (t) => {
70
+ i.equals(t, n) && r();
71
+ }),
72
+ s.on("fieldIssuesUpdated", (t) => {
73
+ i.equals(t, n) && r();
74
+ })
75
+ );
76
+ },
77
+ [l, n]
78
+ );
79
+ return a(o, () => l.getField(n));
119
80
  }
120
- function q(e, n) {
121
- const t = {};
122
- for (const o of e) {
123
- const r = n(o);
124
- (t[r] ??= []).push(o);
125
- }
126
- return t;
81
+ function S(u, n) {
82
+ const { controller: e } = u, l = d(
83
+ (r) => {
84
+ const { events: s } = e;
85
+ return c(
86
+ s.on("fieldRegistered", (t) => {
87
+ i.equals(n, t) && r();
88
+ }),
89
+ s.on("fieldUnregistered", (t) => {
90
+ i.equals(n, t) && r();
91
+ }),
92
+ s.on("fieldValueChanged", (t) => {
93
+ (i.equals(t, n) || i.isDescendant(t, n)) && r();
94
+ })
95
+ );
96
+ },
97
+ [e, n]
98
+ ), o = d(() => e.getField(n)?.value, [e, n]);
99
+ return f(l, o, o);
127
100
  }
128
- function D(e, n) {
129
- const t = a(), o = e.controller._issues.filter((r) => {
130
- if (n?.include == null) return !0;
131
- const l = u.normalize(r.path);
132
- return n.include.some(
133
- (d) => u.equals(d, l)
134
- );
135
- });
136
- return c(() => {
137
- const { events: r } = e.controller;
138
- return i(
139
- r.on("fieldIssuesUpdated", (l) => {
140
- (n?.include?.includes?.(l) ?? !0) && t.forceRerender();
141
- })
142
- );
143
- }, []), q(
144
- o,
145
- (r) => r.path == null ? "$" : u.toStringPath(u.normalize(r.path))
146
- );
101
+ function k(u, n) {
102
+ const { controller: e } = u, l = d(
103
+ (r) => {
104
+ const { events: s } = e;
105
+ return c(
106
+ s.on("fieldRegistered", (t) => {
107
+ i.equals(n, t) && r();
108
+ }),
109
+ s.on("fieldUnregistered", (t) => {
110
+ i.equals(n, t) && r();
111
+ }),
112
+ s.on("fieldIssuesUpdated", (t) => {
113
+ i.equals(n, t) && r();
114
+ })
115
+ );
116
+ },
117
+ [e, n]
118
+ ), o = d(() => e.getField(n)?.issues ?? [], [e, n]);
119
+ return f(l, o, o);
147
120
  }
148
- function E(e) {
149
- const n = v(null), t = h(e.form, e.path, {
150
- overrideInitialValue: e.overrideInitialValue ?? !0,
151
- defaultValue: typeof e.defaultValue == "function" ? e.defaultValue() : e.defaultValue
152
- }), o = e.render({
121
+ function w(u) {
122
+ const n = v(null), e = R(u.form, u.path, {
123
+ overrideInitialValue: u.overrideInitialValue ?? !0,
124
+ defaultValue: u.defaultValue
125
+ }), l = u.form.controller.triedSubmitting ? u.form.hookConfigs?.revalidateMode ?? u.form.hookConfigs?.validateMode : u.form.hookConfigs?.validateMode, o = u.render({
153
126
  fieldProps: {
154
127
  ref: n,
155
- value: t.value,
128
+ name: e.stringPath,
129
+ value: e.value,
156
130
  onChange(r) {
157
- let l;
131
+ let s;
158
132
  if (typeof r == "object" && "target" in r) {
159
- const { target: d } = r;
160
- if (d !== t.boundElement || !("value" in d) || typeof d.value != "string") return;
161
- l = d.value;
133
+ const { target: t } = r;
134
+ if (t !== e.boundElement || !("value" in t) || typeof t.value != "string") return;
135
+ s = t.value;
162
136
  } else
163
- l = r;
164
- t.setValue(l, {
137
+ s = r;
138
+ e.setValue(s, {
165
139
  shouldTouch: !0,
166
140
  shouldMarkDirty: !0
167
141
  });
168
142
  },
169
143
  onFocus() {
170
- t.touch();
144
+ e.touch();
171
145
  },
172
146
  onBlur() {
173
- (e.form.hookConfigs?.validateMode === "onBlur" || e.form.hookConfigs?.validateMode === "onChange") && e.form.controller.validateField(e.path);
147
+ (e.issues.length !== 0 || l === "onBlur" || l === "onChange") && u.form.controller.validateField(u.path);
174
148
  }
175
149
  },
176
- field: t,
177
- form: e.form
150
+ field: e,
151
+ form: u.form
178
152
  });
179
- return c(() => {
180
- const { events: r } = e.form.controller;
181
- return i(
182
- r.on("valueChanged", (l) => {
183
- !u.equals(l, e.path) && !u.isDescendant(l, e.path) || e.form.hookConfigs?.validateMode === "onChange" && e.form.controller.validateField(e.path);
153
+ return m(() => {
154
+ const { events: r } = u.form.controller;
155
+ return c(
156
+ r.on("fieldValueChanged", (s) => {
157
+ !i.equals(s, u.path) && !i.isDescendant(s, u.path) || (e.issues.length !== 0 || l === "onChange") && u.form.controller.validateField(u.path);
184
158
  })
185
159
  );
186
- }, []), c(() => (t.bindElement(n.current), () => {
187
- e.unbindOnUnmount && e.form.controller.unbindField(e.path);
188
- }), []), /* @__PURE__ */ R(g, { children: o });
160
+ }, [l]), m(() => (e.bindElement(n.current), () => {
161
+ u.unregisterOnUnmount && u.form.controller.unregisterField(u.path);
162
+ }), []), /* @__PURE__ */ U(I, { children: o });
189
163
  }
190
164
  export {
191
- E as FieldRenderer,
192
- B as useFieldErrors,
193
- w as useFieldValue,
194
- U as useForm,
195
- D as useFormErrorObserver,
196
- h as useFormField,
197
- y as useFormValuesObserver,
198
- a as useRenderControl
165
+ w as FieldRenderer,
166
+ k as useFieldIssues,
167
+ S as useFieldValue,
168
+ M as useForm,
169
+ R as useFormField
199
170
  };
200
171
  //# sourceMappingURL=index.js.map