react-form-manage 1.0.6-beta.0 → 1.0.6-beta.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/dist/components/Form/FormCleanUp.js +46 -0
  3. package/dist/components/Form/FormItem.d.ts +11 -17
  4. package/dist/components/Form/FormItem.js +46 -0
  5. package/dist/components/Form/FormList.d.ts +23 -7
  6. package/dist/components/Form/FormList.js +11 -0
  7. package/dist/components/Form/InputWrapper.d.ts +10 -5
  8. package/dist/components/Form/InputWrapper.js +7 -0
  9. package/dist/components/Input.d.ts +4 -5
  10. package/dist/components/Input.js +8 -0
  11. package/dist/constants/validation.js +33 -0
  12. package/dist/contexts/FormContext.js +2 -0
  13. package/dist/hooks/useFormItemControl.js +390 -0
  14. package/dist/hooks/useFormListControl.js +280 -0
  15. package/dist/index.d.ts +8 -185
  16. package/dist/index.js +9 -0
  17. package/dist/providers/Form.d.ts +15 -10
  18. package/dist/providers/Form.js +322 -0
  19. package/dist/stores/formStore.js +304 -0
  20. package/dist/types/index.d.ts +1 -0
  21. package/dist/types/index.js +1 -0
  22. package/dist/types/public.d.ts +51 -0
  23. package/dist/utils/obj.util.js +24 -0
  24. package/package.json +30 -45
  25. package/src/App.css +49 -0
  26. package/src/App.tsx +36 -0
  27. package/src/assets/react.svg +1 -0
  28. package/src/components/Form/FormCleanUp.tsx +57 -0
  29. package/src/components/Form/FormItem.tsx +72 -0
  30. package/src/components/Form/FormList.tsx +22 -0
  31. package/src/components/Form/InputWrapper.tsx +24 -0
  32. package/src/components/Input.jsx +13 -0
  33. package/src/components/Input.tsx +21 -0
  34. package/src/constants/validation.ts +63 -0
  35. package/src/contexts/FormContext.ts +3 -0
  36. package/src/hooks/useFormItemControl.ts +558 -0
  37. package/src/hooks/useFormListControl.ts +378 -0
  38. package/src/index.css +68 -0
  39. package/src/index.ts +35 -0
  40. package/src/main.tsx +10 -0
  41. package/src/providers/Form.tsx +440 -0
  42. package/src/stores/formStore.ts +477 -0
  43. package/src/types/index.ts +1 -0
  44. package/src/types/public.ts +50 -0
  45. package/src/utils/obj.util.ts +42 -0
  46. package/dist/App.d.ts +0 -2
  47. package/dist/index.cjs +0 -2
  48. package/dist/index.cjs.d.ts +0 -1
  49. package/dist/index.cjs.map +0 -1
  50. package/dist/index.esm.d.ts +0 -1
  51. package/dist/index.esm.js +0 -2
  52. package/dist/index.esm.js.map +0 -1
  53. package/src/types/components.d.ts +0 -135
  54. /package/dist/{main.d.ts → types/public.js} +0 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,52 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [1.0.6-beta.2] - 2026-01-22
6
+
7
+ - Fix TypeScript prop types for all components
8
+ - Add FormProps interface with proper optional fields
9
+ - Add FormItemProps, FormListProps, InputWrapperProps interfaces
10
+ - Export type interfaces from package
11
+ - Fix type error where Form component required all props
12
+
13
+ ## [1.0.6-beta.1] - 2026-01-22
14
+
15
+ - Full TypeScript migration: Convert all source files from JS to TS
16
+ - Replace JS entrypoints (main.jsx, Input.jsx) with TypeScript versions
17
+ - Add proper type declarations generated from source
18
+ - Update build to emit both JS and .d.ts files
19
+ - Add @types/node for Node.js type support
20
+ - Remove legacy copy-types scripts
21
+ - Add antd, react, react-dom to devDependencies for local development
22
+
23
+ ## [1.0.1] - 2026-01-21
24
+
25
+ - Publish patch release v1.0.1
26
+ - Minor packaging and release metadata updates
27
+
28
+ ---
29
+
30
+ ## [1.0.0] - initial publish
31
+
32
+ - Initial public release `react-form-manage@1.0.0`.
33
+
34
+ ## [1.0.2] - 2026-01-21
35
+
36
+ - Add distributed TypeScript declaration `dist/index.d.ts` and update `package.json` `types` field.
37
+
38
+ ## [1.0.3] - 2026-01-21
39
+
40
+ - Provide `dist/index.esm.d.ts` and `dist/index.cjs.d.ts` re-exports so Node-style module resolution finds typings correctly.
41
+
42
+ ## [1.0.4] - 2026-01-21
43
+
44
+ - Add `build:types` script and `scripts/copy-types.js` to automatically copy `src/types/components.d.ts` into `dist/` during publish builds.
45
+
46
+ ## [1.0.5] - 2026-01-21
47
+
48
+ - Export `Form` as a named export in addition to default to improve import ergonomics for consumers.
49
+
50
+
51
+
52
+
@@ -0,0 +1,46 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect } from "react";
3
+ import { useShallow } from "zustand/react/shallow";
4
+ import { useFormCleanUp, useFormListeners, useFormStore, } from "../../stores/formStore";
5
+ const FormCleanUp = () => {
6
+ const { cleanUpStack, clearCleanUpStack } = useFormCleanUp(useShallow((state) => ({
7
+ cleanUpStack: state.cleanUpStack,
8
+ clearCleanUpStack: state.clearCleanUpStack,
9
+ })));
10
+ const { revokeListener } = useFormListeners(useShallow((state) => ({
11
+ revokeListener: state.revokeListener,
12
+ })));
13
+ const { clearObjKeyItem, clearArrItem } = useFormStore(useShallow((state) => {
14
+ return {
15
+ clearObjKeyItem: state.clearObjKeyItem,
16
+ clearArrItem: state.clearArrItem,
17
+ };
18
+ }));
19
+ useEffect(() => {
20
+ if (Array.isArray(cleanUpStack) && cleanUpStack?.length) {
21
+ // console.log("Trigger clean up: ", cleanUpStack);
22
+ cleanUpStack.forEach((c) => {
23
+ if (c.itemKey) {
24
+ console.log("Revoke in Clean up: ", c);
25
+ revokeListener(c.itemKey, (listener, same) => {
26
+ if (!same.length) {
27
+ console.log("Trigger after revoke: ", listener, same);
28
+ clearObjKeyItem(listener.formName, listener.name);
29
+ }
30
+ });
31
+ }
32
+ else {
33
+ if (c.type === "array") {
34
+ console.log(c);
35
+ clearArrItem(c.formName, c.name);
36
+ }
37
+ else {
38
+ }
39
+ }
40
+ });
41
+ clearCleanUpStack();
42
+ }
43
+ }, [cleanUpStack]);
44
+ return _jsx(_Fragment, {});
45
+ };
46
+ export default FormCleanUp;
@@ -1,18 +1,12 @@
1
- export default function FormItem({ children, name, formName, initialValue, formItemId: externalFormItemId, rules, valuePropName, getValueFromEvent, }: {
2
- children: any;
3
- name: any;
4
- formName: any;
5
- initialValue: any;
6
- formItemId: any;
7
- rules: any;
1
+ import type { ReactElement } from "react";
2
+ export interface FormItemProps {
3
+ children: ReactElement;
4
+ name: string;
5
+ formName?: string;
6
+ initialValue?: any;
7
+ formItemId?: string;
8
+ rules?: any[];
8
9
  valuePropName?: string;
9
- getValueFromEvent: any;
10
- }): import("react").DetailedReactHTMLElement<{
11
- [valuePropName]: any;
12
- onChange: (e: any) => void;
13
- isDirty: boolean;
14
- errors: any;
15
- onFocus: () => void;
16
- validateState: any;
17
- ref: import("react").RefObject<any>;
18
- }, HTMLElement>;
10
+ getValueFromEvent?: (event: any) => any;
11
+ }
12
+ export default function FormItem({ children, name, formName, initialValue, formItemId: externalFormItemId, rules, valuePropName, getValueFromEvent, }: FormItemProps): ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
@@ -0,0 +1,46 @@
1
+ import { cloneElement, useRef, useState } from "react";
2
+ import { v4 } from "uuid";
3
+ import useFormItemControl from "../../hooks/useFormItemControl";
4
+ export default function FormItem({ children, name, formName, initialValue, formItemId: externalFormItemId, rules, valuePropName = "value", getValueFromEvent, }) {
5
+ const elRef = useRef(null);
6
+ const [formItemId] = useState(externalFormItemId ?? v4());
7
+ const { value, onChange, errors, state, onFocus, isDirty } = useFormItemControl({
8
+ formName,
9
+ name,
10
+ initialValue,
11
+ formItemId,
12
+ rules,
13
+ elementRef: elRef,
14
+ });
15
+ // console.log("re-render", formName, name);
16
+ // useEffect(() => {
17
+ // console.log({ value });
18
+ // }, [value]);
19
+ return cloneElement(children, {
20
+ // ref: inputRef,
21
+ [valuePropName]: value,
22
+ onChange: (e) => {
23
+ let val = e;
24
+ if (getValueFromEvent && typeof getValueFromEvent === "function") {
25
+ val = getValueFromEvent(e);
26
+ }
27
+ else {
28
+ if (e && e.target) {
29
+ val = e.target.value;
30
+ }
31
+ }
32
+ onChange(val);
33
+ },
34
+ // onFocus: () => {
35
+ // setIsTouched(true);
36
+ // },
37
+ // isTouched: isTouched,
38
+ isDirty: isDirty,
39
+ // errors: errors,
40
+ // formState,
41
+ errors,
42
+ onFocus,
43
+ validateState: state,
44
+ ref: elRef,
45
+ });
46
+ }
@@ -1,8 +1,24 @@
1
- declare const FormList: ({ name, initialValues, form, formName, children }: {
2
- name: any;
3
- initialValues: any;
4
- form: any;
5
- formName: any;
6
- children: any;
7
- }) => any;
1
+ import type { FormInstance } from "../../stores/formStore";
2
+ export interface FormListProps<T = any> {
3
+ name: string;
4
+ initialValues?: T[];
5
+ form?: FormInstance;
6
+ formName?: string;
7
+ children: (fields: Array<{
8
+ name: string;
9
+ key: string;
10
+ }>, operations: {
11
+ add: (index: number) => void;
12
+ remove: (opts: {
13
+ index?: number;
14
+ key?: string;
15
+ }) => void;
16
+ move: (opts: {
17
+ from?: number;
18
+ fromKey?: string;
19
+ to: number;
20
+ }) => void;
21
+ }) => React.ReactNode;
22
+ }
23
+ declare const FormList: <T = any>({ name, initialValues, form, formName, children }: FormListProps<T>) => import("react").ReactNode;
8
24
  export default FormList;
@@ -0,0 +1,11 @@
1
+ import useTestRrenderListControl from "../../hooks/useFormListControl";
2
+ const FormList = ({ name, initialValues, form, formName, children }) => {
3
+ const { listFields, ...actions } = useTestRrenderListControl({
4
+ name,
5
+ initialValues,
6
+ form,
7
+ formName,
8
+ });
9
+ return children(listFields, { ...actions });
10
+ };
11
+ export default FormList;
@@ -1,6 +1,11 @@
1
- declare const InputWrapper: ({ children, errors, ...props }: {
2
- [x: string]: any;
3
- children: any;
4
- errors?: any[];
5
- }) => import("react/jsx-runtime").JSX.Element;
1
+ import type { ReactElement } from "react";
2
+ export interface InputWrapperProps {
3
+ children: ReactElement;
4
+ errors?: Array<{
5
+ ruleName: string;
6
+ message: string;
7
+ }>;
8
+ [key: string]: any;
9
+ }
10
+ declare const InputWrapper: ({ children, errors, ...props }: InputWrapperProps) => import("react/jsx-runtime").JSX.Element;
6
11
  export default InputWrapper;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cloneElement } from "react";
3
+ const InputWrapper = ({ children, errors = [], ...props }) => {
4
+ return (_jsxs("div", { children: [cloneElement(children, props), (props.isDirty || props.formState === "submitted") &&
5
+ errors?.map((r) => (_jsx("div", { children: r?.message }, `${props.name}-${props.formItemId}-${r.ruleName}`)))] }));
6
+ };
7
+ export default InputWrapper;
@@ -1,6 +1,5 @@
1
+ import { type InputHTMLAttributes } from "react";
2
+ declare const Input: import("react").ForwardRefExoticComponent<Omit<InputHTMLAttributes<HTMLInputElement>, "onChange"> & {
3
+ onChange?: (value: any) => void;
4
+ } & import("react").RefAttributes<HTMLInputElement>>;
1
5
  export default Input;
2
- declare function Input({ onChange, ref, ...props }: {
3
- [x: string]: any;
4
- onChange: any;
5
- ref: any;
6
- }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ const Input = forwardRef(({ onChange, ...props }, ref) => {
4
+ return (_jsx("input", { ref: ref, onChange: (e) => {
5
+ onChange?.(e.target.value);
6
+ }, ...props }));
7
+ });
8
+ export default Input;
@@ -0,0 +1,33 @@
1
+ // Rules regex
2
+ export const IS_STRING_NUMBER_REGEX = /^\d+$/;
3
+ export const IS_USERNAME_REGEX = /^[a-zA-Z0-9._]{3,16}$/;
4
+ export const IS_PASSWORD_REGEX = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
5
+ export const IS_POSITIVE_STRING_NUMBER_REGEX = /^[1-9]\d*$/;
6
+ export const IS_POSITIVE_INTEGER_STRING_NUMBER_REGEX = /^(?:0|[1-9]\d*)(?:\.\d+)?$/;
7
+ export const IS_VIETNAMESE_PHONE_NUMBER_REGEX = /^(?:\+84|0)[\s\-\.]?(?:3[2-9]|5[6|8|9]|7[06-9]|8[1-5]|9[0-9])[\s\-\.]?\d[\d\s\-\.]{6,8}$/;
8
+ export const IS_EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
9
+ export const IS_NAME_REGEX = /^[A-Za-zÀÁÂÃÈÉÊÌÍÒÓÔÕÙÚĂĐĨŨƠàáâãèéêìíòóôõùúăđĩũơƯĂÂÊÔƠƯăâêôơưÇçÝýỳỵỷỹ\s]{2,50}$/;
10
+ export const IS_NOSPACE_STRING_AND_NUMBER_REGEX = /^[A-Za-zÀ-ỹ0-9]+$/;
11
+ export const IS_STRING_AND_NUMBER_REGEX = /^[A-Za-zÀ-ỹ0-9][A-Za-zÀ-ỹ0-9\s]*$/;
12
+ export const IS_NO_SPACE_ALPHABET_STRING_AND_NUMBER_REGEX = /^[A-Za-z0-9]+$/;
13
+ export const IS_ALPHABET_STRING_AND_NUMBER_REGEX = /^[A-Za-z0-9]+(?:\s[A-Za-z0-9]+)*$/;
14
+ export const IS_NO_SPACE_ALPHABET_STRING_REGEX = /^[A-Za-z]+$/;
15
+ // default message
16
+ export const HANDLER_INVALID_MESSAGE = "Invalid value!";
17
+ export const MIN_INVALID_MESSAGE = "Min value invalid!";
18
+ export const MAX_INVALID_MESSAGE = "Max value invalid!";
19
+ export const MIN_INVALID_LENGTH_MESSAGE = "Max length invalid!";
20
+ export const MAX_INVALID_LENGTH_MESSAGE = "Max length invalid!";
21
+ export const IS_STRING_NUMBER_INVALID_MESSAGE = "Must be number!";
22
+ export const IS_USERNAME_INVALID_MESSAGE = `Username must be containes string, number, '.' or '_'!`;
23
+ export const IS_PASSWORD_INVALID_MESSAGE = "Password must be contains Minimum 8 characters, with uppercase, lowercase, number, special character!";
24
+ export const IS_POSITIVE_STRING_NUMBER_INVALID_MESSAGE = "Must be positive number!";
25
+ export const IS_POSITIVE_INTEGER_STRING_NUMBER_INVALID_MESSAGE = "Must be positive integer number!";
26
+ export const IS_VIETNAMESE_PHONE_NUMBER_INVALID_MESSAGE = "Invalid phone number format!";
27
+ export const IS_EMAIL_INVALID_MESSAGE = "Invalid email format!";
28
+ export const IS_NAME_INVALID_MESSAGE = "Invalid name format!";
29
+ export const IS_NOSPACE_STRING_AND_NUMBER_MESSAGE = "String must only includes string and number without whitespace!";
30
+ export const IS_STRING_AND_NUMBER_MESSAGE = "String must only includes string, number and whitespace!";
31
+ export const IS_NO_SPACE_ALPHABET_STRING_AND_NUMBER_MESSAGE = "String must only includes alphabet characters and numbers!";
32
+ export const IS_ALPHABET_STRING_AND_NUMBER_MESSAGE = "String must only includes alphabet charaters, numbers and whitespace";
33
+ export const IS_NO_SPACE_ALPHABET_STRING_MESSAGE = "String must only includes alphabet";
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export default createContext(undefined);