@goodie-forms/react 1.0.0-alpha → 1.1.0-alpha

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.
@@ -1,12 +1,26 @@
1
- import { useRef, useState } from "react";
2
-
3
- export function useRenderControl() {
4
- const [, rerender] = useState(0);
5
- const renderCount = useRef(0);
6
- renderCount.current++;
7
-
8
- return {
9
- renderCount: renderCount.current,
10
- forceRerender: () => rerender((i) => i + 1),
11
- };
12
- }
1
+ import { startTransition, useRef, useState } from "react";
2
+
3
+ export function useRenderControl() {
4
+ const [, rerender] = useState(0);
5
+ const renderCount = useRef(0);
6
+ const renderScheduled = useRef(false);
7
+ renderCount.current++;
8
+
9
+ const scheduleRerender = () => {
10
+ if (renderScheduled.current) return;
11
+ renderScheduled.current = true;
12
+
13
+ queueMicrotask(() => {
14
+ startTransition(() => {
15
+ rerender((i) => i + 1);
16
+ });
17
+
18
+ renderScheduled.current = false;
19
+ });
20
+ };
21
+
22
+ return {
23
+ renderCount: renderCount.current,
24
+ forceRerender: scheduleRerender,
25
+ };
26
+ }
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from "./hooks/useForm";
2
- export * from "./hooks/useFormField";
3
- export * from "./hooks/useFormValuesObserver";
4
- export * from "./hooks/useFormErrorObserver";
5
- export * from "./hooks/useRenderControl";
6
-
7
- export * from "./components/FieldRenderer";
1
+ export * from "./hooks/useForm";
2
+ export * from "./hooks/useFormField";
3
+ export * from "./hooks/useFormValuesObserver";
4
+ export * from "./hooks/useFormErrorObserver";
5
+ export * from "./hooks/useRenderControl";
6
+
7
+ export * from "./components/FieldRenderer";
@@ -1,7 +1,7 @@
1
- export function composeFns<TFns extends (() => void)[]>(...fns: TFns) {
2
- return () => {
3
- for (const fn of fns) {
4
- fn();
5
- }
6
- };
7
- }
1
+ export function composeFns<TFns extends (() => void)[]>(...fns: TFns) {
2
+ return () => {
3
+ for (const fn of fns) {
4
+ fn();
5
+ }
6
+ };
7
+ }
@@ -1,13 +1,13 @@
1
- export function groupBy<T, K extends PropertyKey>(
2
- items: readonly T[],
3
- key: (item: T) => K,
4
- ): Record<K, T[]> {
5
- const result = {} as Record<K, T[]>;
6
-
7
- for (const item of items) {
8
- const k = key(item);
9
- (result[k] ??= []).push(item);
10
- }
11
-
12
- return result;
13
- }
1
+ export function groupBy<T, K extends PropertyKey>(
2
+ items: readonly T[],
3
+ key: (item: T) => K,
4
+ ): Record<K, T[]> {
5
+ const result = {} as Record<K, T[]>;
6
+
7
+ for (const item of items) {
8
+ const k = key(item);
9
+ (result[k] ??= []).push(item);
10
+ }
11
+
12
+ return result;
13
+ }
package/tsconfig.json CHANGED
@@ -1,8 +1,8 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "jsx": "react-jsx"
6
- },
7
- "include": ["src"]
8
- }
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "jsx": "react-jsx"
6
+ },
7
+ "include": ["src"]
8
+ }
package/vite.config.ts CHANGED
@@ -1,23 +1,23 @@
1
- import { defineConfig } from "vite";
2
- import react from "@vitejs/plugin-react";
3
- import dts from "vite-plugin-dts";
4
-
5
- export default defineConfig({
6
- plugins: [
7
- react(),
8
- dts({
9
- entryRoot: "src",
10
- }),
11
- ],
12
- build: {
13
- lib: {
14
- entry: "src/index.ts",
15
- formats: ["es"],
16
- fileName: "index",
17
- },
18
- rollupOptions: {
19
- external: ["react", "react-dom", "@goodie-forms/core"],
20
- },
21
- sourcemap: true,
22
- },
23
- });
1
+ import { defineConfig } from "vite";
2
+ import react from "@vitejs/plugin-react";
3
+ import dts from "vite-plugin-dts";
4
+
5
+ export default defineConfig({
6
+ plugins: [
7
+ react(),
8
+ dts({
9
+ entryRoot: "src",
10
+ }),
11
+ ],
12
+ build: {
13
+ lib: {
14
+ entry: "src/index.ts",
15
+ formats: ["es"],
16
+ fileName: "index",
17
+ },
18
+ rollupOptions: {
19
+ external: ["react", "react-dom", "@goodie-forms/core"],
20
+ },
21
+ sourcemap: true,
22
+ },
23
+ });
@@ -1,22 +0,0 @@
1
- import { Field, FormField } from '../../../core/src';
2
- import { ChangeEvent, FocusEvent, ReactNode, Ref } from 'react';
3
- import { UseForm } from '../hooks/useForm';
4
- export interface RenderParams<TShape extends object, TPath extends Field.Paths<TShape>> {
5
- ref: Ref<any | null>;
6
- value: Field.GetValue<TShape, TPath> | undefined;
7
- handlers: {
8
- onChange: (event: ChangeEvent<EventTarget>) => void;
9
- onFocus: (event: FocusEvent) => void;
10
- onBlur: (event: FocusEvent) => void;
11
- };
12
- field: FormField<TShape, TPath>;
13
- }
14
- export interface FieldRendererProps<TShape extends object, TPath extends Field.Paths<TShape>> {
15
- form: UseForm<TShape>;
16
- path: TPath;
17
- resetOnUnmount?: boolean;
18
- defaultValue?: Field.GetValue<TShape, TPath>;
19
- render: (params: RenderParams<TShape, TPath>) => ReactNode;
20
- }
21
- export declare function FieldRenderer<TShape extends object, TPath extends Field.Paths<TShape>>(props: FieldRendererProps<TShape, TPath>): import("react/jsx-runtime").JSX.Element;
22
- //# sourceMappingURL=FieldRenderer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FieldRenderer.d.ts","sourceRoot":"","sources":["../../src/components/FieldRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,WAAW,EACX,UAAU,EACV,SAAS,EACT,GAAG,EAGJ,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAI3C,MAAM,WAAW,YAAY,CAC3B,MAAM,SAAS,MAAM,EACrB,KAAK,SAAS,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;IAEjC,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;IAErB,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,SAAS,CAAC;IAEjD,QAAQ,EAAE;QACR,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;QACpD,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;QACrC,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;KACrC,CAAC;IAEF,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,kBAAkB,CACjC,MAAM,SAAS,MAAM,EACrB,KAAK,SAAS,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;IAEjC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACtB,IAAI,EAAE,KAAK,CAAC;IACZ,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC7C,MAAM,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,SAAS,CAAC;CAC5D;AAED,wBAAgB,aAAa,CAC3B,MAAM,SAAS,MAAM,EACrB,KAAK,SAAS,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EACjC,KAAK,EAAE,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,2CA8DzC"}
@@ -1,22 +0,0 @@
1
- import { FormController, Form } from '../../../core/src';
2
- export declare function useForm<TShape extends object>(formConfigs: Form.FormConfigs<TShape>, hookConfigs?: {
3
- validateMode?: "onChange" | "onBlur" | "onSubmit";
4
- revalidateMode?: "onChange" | "onBlur" | "onSubmit";
5
- watchIssues?: boolean;
6
- watchValues?: boolean;
7
- }): {
8
- formConfigs: {
9
- initialData?: import('packages/core/src/types/DeepPartial').DeepPartial<TShape> | undefined;
10
- validationSchema?: import('@standard-schema/spec').StandardSchemaV1<TShape, TShape> | undefined;
11
- equalityComparators?: Record<any, (a: any, b: any) => boolean>;
12
- };
13
- hookConfigs: {
14
- validateMode?: "onChange" | "onBlur" | "onSubmit";
15
- revalidateMode?: "onChange" | "onBlur" | "onSubmit";
16
- watchIssues?: boolean;
17
- watchValues?: boolean;
18
- } | undefined;
19
- controller: FormController<TShape>;
20
- };
21
- export type UseForm<TShape extends object> = ReturnType<typeof useForm<TShape>>;
22
- //# sourceMappingURL=useForm.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../src/hooks/useForm.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAK/D,wBAAgB,OAAO,CAAC,MAAM,SAAS,MAAM,EAC3C,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EACrC,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;;;EAqCxB;AAED,MAAM,MAAM,OAAO,CAAC,MAAM,SAAS,MAAM,IAAI,UAAU,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC"}
@@ -1,6 +0,0 @@
1
- import { Field } from '../../../core/src';
2
- import { UseForm } from './useForm';
3
- export declare function useFormErrorObserver<TShape extends object>(form: UseForm<TShape>, options?: {
4
- include?: Field.Paths<TShape>[];
5
- }): Record<Field.Paths<TShape>, import("@standard-schema/spec").StandardSchemaV1.Issue[]>;
6
- //# sourceMappingURL=useFormErrorObserver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useFormErrorObserver.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormErrorObserver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAIhD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,wBAAgB,oBAAoB,CAAC,MAAM,SAAS,MAAM,EACxD,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EACrB,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;CACjC,yFA0BF"}
@@ -1,4 +0,0 @@
1
- import { Field } from '../../../core/src';
2
- import { UseForm } from '../hooks/useForm';
3
- export declare function useFormField<TShape extends object, TPath extends Field.Paths<TShape>>(form: UseForm<TShape>, path: TPath, defaultValue?: Field.GetValue<TShape, TPath>): import('../../../core/src').FormField<TShape, TPath>;
4
- //# sourceMappingURL=useFormField.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useFormField.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAI3C,wBAAgB,YAAY,CAC1B,MAAM,SAAS,MAAM,EACrB,KAAK,SAAS,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAEjC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EACrB,IAAI,EAAE,KAAK,EACX,YAAY,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,yDAiC7C"}
@@ -1,6 +0,0 @@
1
- import { Field } from '../../../core/src';
2
- import { UseForm } from './useForm';
3
- export declare function useFormValuesObserver<TShape extends object>(form: UseForm<TShape>, options?: {
4
- include?: Field.Paths<TShape>[];
5
- }): import('packages/core/src/types/DeepPartial').DeepPartial<TShape>;
6
- //# sourceMappingURL=useFormValuesObserver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useFormValuesObserver.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormValuesObserver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,wBAAgB,qBAAqB,CAAC,MAAM,SAAS,MAAM,EACzD,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EACrB,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;CACjC,qEAuBF"}
@@ -1,5 +0,0 @@
1
- export declare function useRenderControl(): {
2
- renderCount: number;
3
- forceRerender: () => void;
4
- };
5
- //# sourceMappingURL=useRenderControl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useRenderControl.d.ts","sourceRoot":"","sources":["../../src/hooks/useRenderControl.tsx"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB;;;EAS/B"}
package/dist/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- export * from './hooks/useForm';
2
- export * from './hooks/useFormField';
3
- export * from './hooks/useFormValuesObserver';
4
- export * from './hooks/useFormErrorObserver';
5
- export * from './hooks/useRenderControl';
6
- export * from './components/FieldRenderer';
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,4BAA4B,CAAC"}