gform-react 1.0.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.
package/README.md ADDED
@@ -0,0 +1,298 @@
1
+ # GForm
2
+ ![npm bundle size](https://img.shields.io/bundlephobia/min/gform-react)
3
+ ![npm peer dependency version](https://img.shields.io/npm/dependency-version/gform-react/peer/react)
4
+ ![npm peer dependency version](https://img.shields.io/npm/dependency-version/gform-react/peer/react-dom)
5
+ ![NPM](https://img.shields.io/npm/l/gform-react)
6
+
7
+ #### A generic form builder for react-based applications.
8
+ it doesn't matter which UI library you're using,
9
+ it only cares about the form and the inputs inside.
10
+
11
+ ## Installation
12
+ npm:
13
+ ```shell
14
+ npm install gform-react
15
+ ```
16
+
17
+ yarn:
18
+ ```shell
19
+ yarn add gform-react
20
+ ```
21
+
22
+ #### NOTE:
23
+ react >=16.7.0, react-dom >=16.7.0 are peer dependecies
24
+
25
+
26
+ ## Quickstart - Native
27
+
28
+ ```tsx
29
+ import { GForm, GInput, IForm } from "gform-react";
30
+
31
+ //the interface that represents a form
32
+ interface SignInForm extends IForm {
33
+ email: GInputState<string>;
34
+ password: GInputState<string>;
35
+ }
36
+
37
+ const App: FC = () => {
38
+ const onSubmit = (formState) => {
39
+ console.log(formState);
40
+ };
41
+
42
+ return (
43
+ <div>
44
+ ...
45
+ <GForm<SignInForm> className='some-class' onSubmit={onSubmit}>
46
+ <div className='some-formgroup'>
47
+ <GInput formKey='email' required/>
48
+ </div>
49
+ <div className='some-formgroup'>
50
+ <GInput formKey='password' required type='password'/>
51
+ </div>
52
+ <button>Submit</button>
53
+ </GForm>
54
+ </div>
55
+ );
56
+ };
57
+
58
+ ```
59
+
60
+ ## Quickstart - Prime React
61
+
62
+ ```tsx
63
+ import { InputText } from "primereact/inputtext";
64
+ import { Button } from 'primereact/button';
65
+ import { GForm, GInput, IForm } from "gform-react";
66
+
67
+ type SignInForm = IForm<{
68
+ email: GInputState<string>;
69
+ password: GInputState<string>;
70
+ }>;
71
+
72
+ const App: FC = () => {
73
+ return (
74
+ <div>
75
+ ...
76
+ <GForm className='some-class'>
77
+ <GInput formKey={'email'} required minLength={7}
78
+ element={(input, props) => <div>
79
+ <label htmlFor="email">Email</label>
80
+ <InputText {...props} id="email" aria-describedby="email-help" className={input.error ? "p-invalid" : ''} />
81
+ {input.error && <small id="email-help" className="p-error">{input.errorText}</small>}
82
+ </div>}
83
+ />
84
+
85
+ <GInput formKey={'password'} required
86
+ element={(input, props) => <div>
87
+ <label htmlFor="password">Password</label>
88
+ <InputText {...props} id="password" aria-describedby="password-help" className={input.error ? "p-invalid" : ''} />
89
+ {input.error && <small id="password-help" className="p-error">{input.errorText}</small>}
90
+ </div>}
91
+ />
92
+
93
+ <Button label="Submit" aria-label="Submit" />
94
+ </GForm>
95
+ </div>
96
+ );
97
+ };
98
+
99
+ ```
100
+
101
+ ## Quickstart - MUI
102
+
103
+ ```tsx
104
+ import { Button, TextField } from '@mui/material';
105
+ import { GForm, GInput, IForm } from "gform-react";
106
+
107
+ interface SignInForm extends IForm {
108
+ email: GInputState<string>;
109
+ password: GInputState<string>;
110
+ }
111
+
112
+ const App: FC = () => {
113
+ return (
114
+ <div>
115
+ ...
116
+ <GForm<SignInForm> className='some-class'>
117
+ <GInput type='text' formKey={'email'}
118
+ element={(input, props) => <div>
119
+ <TextField inputProps={props} variant='filled' label='first name' error={input.error} helperText={input.errorText} />
120
+ </div>}
121
+ />
122
+ <GInput formKey={'password'} required minLength={4}
123
+ element={(input, props) => <div>
124
+ <TextField inputProps={props} variant='filled' label='first name' error={input.error} helperText={input.errorText} />
125
+ </div>}
126
+ />
127
+
128
+ <Button variant='contained' type='submit'>submit</Button>
129
+ </GForm>
130
+ </div>
131
+ );
132
+ };
133
+
134
+ ```
135
+
136
+ # Form State
137
+
138
+ `GForm` will expose the current form state on the following cases:
139
+ #### 1 - the form is valid and submited
140
+ ```tsx
141
+ <GForm<SignInForm>>onSubmit={(formState, e) => {}}
142
+ <GInput formKey='email' required minLength={5}/>
143
+ <GInput formKey='password' required type='password'/>
144
+ <button>submit</button>
145
+ </GForm>
146
+ ```
147
+
148
+ #### 2 - pass a children function
149
+ ```tsx
150
+ <GForm<SignInForm>>
151
+ {
152
+ (formState) => <>
153
+ <div className='some-formgroup'>
154
+ <GInput formKey='email' required minLength={5}/>
155
+ </div>
156
+ <div className='some-formgroup'>
157
+ <GInput formKey='password' required type='password'/>
158
+ </div>
159
+ <button disabled={formState.isInvalid}>submit</button>
160
+ </>
161
+ }
162
+ </GForm>
163
+ ```
164
+
165
+ ### Form State Object
166
+ the `GFormState<T>` is a generic type and the argument is the form interface (the shape of the form)
167
+
168
+ on the examples above the arguemnt is `SignInForm` (`<GForm<SignInForm>>`)
169
+
170
+ the state is simple object:
171
+ ```typescript
172
+ export type GFormState<T extends IForm<T>> = T
173
+ &
174
+ {
175
+ isValid: boolean;
176
+ isInvalid: boolean;
177
+ loading: boolean;
178
+ toRawData: () => RawData<T>;
179
+ toFormData: (options?: ToFormDataOptions<T>) => FormData;
180
+ toURLSearchParams: (options?: ToURLSearchParamsOptions<T>) => URLSearchParams;
181
+ setLoading: Dispatch<SetStateAction<boolean>>;
182
+ updateValidity: () => void;
183
+ };
184
+ ```
185
+
186
+ # Constraint Validation API & Custom validations
187
+ > **Note:** There are several errors that will prevent the form from being submitted, including: badInput, patternMismatch, rangeOverflow or rangeUnderflow, stepMismatch, tooLong or tooShort, typeMismatch, valueMissing, or a customError.
188
+
189
+ `GForm` is based on the native [Constraint Validation API](https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation)
190
+
191
+ which includes `required`, `minLength`, `maxLength`, `min`, `max`, `step` ... [see all here](https://developer.mozilla.org/en-US/docs/Web/API/ValidityState)
192
+
193
+ While you can also add __any__ custom validation(s) you need
194
+
195
+
196
+ ## Example - Constraint Validation
197
+ ```tsx
198
+ const validators: GValidators<SignInForm> = {
199
+ email: new GValidator().withRequiredMessage('this field is required')
200
+ .withMinLengthMessage((input) => `${input.formKey} must contain atleast ${input.minLength} chars`),
201
+
202
+ password: new GValidator().withRequiredMessage('this field is required')
203
+ };
204
+
205
+ ...
206
+
207
+ <GForm<SignInForm> validators={validators}>
208
+ <div className='some-formgroup'>
209
+ <GInput formKey='email' required minLength={5}/>
210
+ </div>
211
+ <div className='some-formgroup'>
212
+ <GInput formKey='password' required type='password'/>
213
+ </div>
214
+ <button>Submit</button>
215
+ </GForm>
216
+ ```
217
+
218
+ #### you can also refer to another input validator (with prop `validatorKey`, see code below)
219
+ ```tsx
220
+ const validators: GValidators<SignInForm> = {
221
+ email: new GValidator().withRequiredMessage('this field is required')
222
+ };
223
+
224
+ ...
225
+
226
+ <GForm<SignInForm> validators={validators}>
227
+ <GInput formKey='email' required minLength={5}/>
228
+ <GInput formKey='password' validatorKey='email' required type='password'/>
229
+ <button>Submit</button>
230
+ </GForm>
231
+ ```
232
+
233
+ #### you can also extend validators
234
+ ```tsx
235
+
236
+ const baseValidator = new GValidator().withRequiredMessage('this field is required')
237
+
238
+ const validators: GValidators<SignInForm> = {
239
+ email: new GValidator(baseValidator).withMinLengthMessage('...'),
240
+ password: baseValidator
241
+ };
242
+
243
+ ...
244
+
245
+ <GForm<SignInForm> validators={validators}>
246
+ <GInput formKey='email' required minLength={5}/>
247
+ <GInput formKey='password' required type='password'/>
248
+ <button>Submit</button>
249
+ </GForm>
250
+ ```
251
+
252
+ ## Example - Adding Custom Validations
253
+ ```tsx
254
+ const validators: GValidators<SignUpForm> = {
255
+ email: new GValidator()
256
+ .withRequiredMessage('this field is required')
257
+ .withMinLengthMessage((input) => `${input.formKey} must contain atleast ${input.minLength} chars`),
258
+ password: new GValidator()
259
+ .withRequiredMessage('this field is required')
260
+ .withCustomValidation((input) => {
261
+ input.errorText = `${input.formKey} must contain special char`; // the message that will be displayed if the test has failed
262
+ return /[^a-zA-Z0-9]+/; // the test
263
+ })
264
+ .withCustomValidation((input, validityKey, fields) => {
265
+ fields.confirmPassword.checkValidity(); // update the confirmPassword field in case of match
266
+
267
+ input.errorText = `the password and confirm password doesnt match`; // the message that will be displayed if the test has failed
268
+ return fields.confirmPassword.value !== fields.password.value; // the test
269
+ }),
270
+ confirmPassword: new GValidator()
271
+ .withCustomValidation((input, validityKey, fields) => {
272
+ fields.password.checkValidity(); // update the password field in case of match
273
+
274
+ input.errorText = `the password and confirm password doesnt match`; // the message that will be displayed if the test has failed
275
+ return fields.confirmPassword.value !== fields.password.value; // the test
276
+ })
277
+ };
278
+
279
+ ...
280
+
281
+ <GForm<SignUpForm> validators={validators}>
282
+ <div className='some-formgroup'>
283
+ <GInput formKey='email' required minLength={5}/>
284
+ </div>
285
+ <div className='some-formgroup'>
286
+ <GInput formKey='password' required type='password'/>
287
+ </div>
288
+ <div className='some-formgroup'>
289
+ <GInput formKey='confirmPassword' type='password'/>
290
+ </div>
291
+ <button>Submit</button>
292
+ </GForm>
293
+ ```
294
+
295
+ # Next
296
+ * Nested forms
297
+
298
+
@@ -0,0 +1,171 @@
1
+ import type { ReactNode, MutableRefObject, HTMLAttributes, FormEvent, ChangeEvent, FC, Dispatch, SetStateAction } from "react";
2
+
3
+ type BaseForm = {
4
+ [key: string]: GInputState;
5
+ };
6
+ export type IForm<T extends BaseForm = BaseForm> = {
7
+ [key in keyof T]: T[key];
8
+ };
9
+ type BaseFormEvent = {
10
+ target: {
11
+ value?: string;
12
+ };
13
+ };
14
+ type GFormEvent = FormEvent<HTMLInputElement | HTMLTextAreaElement | HTMLFormElement | unknown>;
15
+ type GFormChangeEvent = ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLFormElement | unknown>;
16
+
17
+ type ToURLSearchParamsOptions<T extends IForm> = {
18
+ exclude?: (keyof T)[];
19
+ include?: (keyof T)[];
20
+ };
21
+ type ToFormDataOptions<T extends IForm> = ToURLSearchParamsOptions<T>;
22
+
23
+ type BaseGenericFieldProps = {
24
+ formKey: string;
25
+ validatorKey?: string;
26
+ type?: 'text' | 'password' | 'email' | 'tel' | 'checkbox' | 'number' | 'range' | 'color' | 'file' | 'date' | 'month' | 'week' | 'time' | 'search' | 'select';
27
+ };
28
+ type FieldWithError<T extends BaseGenericFieldProps = GInputState> = T & {
29
+ error: boolean;
30
+ errorText: string;
31
+ checkValidity: () => boolean;
32
+ };
33
+
34
+ export type GConstraintValidatorHandler = (input: FieldWithError<GInputState>) => string;
35
+ export type GValidatorHandler<F extends IForm = IForm> = RegExp | ((input: FieldWithError<GInputState>, validityKey: keyof ValidityState | undefined, fields: F) => RegExp | boolean);
36
+ export type GValidators<T extends IForm> = {
37
+ [key in keyof T]?: GValidator | GValidatorHandler<T>[];
38
+ };
39
+ export declare class GValidator {
40
+ readonly handlers: GValidatorHandler[];
41
+ constructor(baseValidator?: GValidator);
42
+ withRequiredMessage(message: string | GConstraintValidatorHandler): GValidator;
43
+ withMaxLengthMessage(message: string | GConstraintValidatorHandler): GValidator;
44
+ withMinLengthMessage(message: string | GConstraintValidatorHandler): GValidator;
45
+ withPatternMismatchMessage(message: string | GConstraintValidatorHandler): GValidator;
46
+ withBadInputMessage(message: string | GConstraintValidatorHandler): GValidator;
47
+ withRangeUnderflowMessage(message: string | GConstraintValidatorHandler): GValidator;
48
+ withRangeOverflowMessage(message: string | GConstraintValidatorHandler): GValidator;
49
+ withTypeMismatchMessage(message: string | GConstraintValidatorHandler): GValidator;
50
+ withStepMismatchMessage(message: string | GConstraintValidatorHandler): GValidator;
51
+ withCustomValidation(handler: GValidatorHandler): GValidator;
52
+ private __addConstraintValidationHandler;
53
+ }
54
+
55
+ export type ToRawDataSetter<T = GInputState['value']> = (field: GInputState) => T;
56
+ export type RawData<T> = {
57
+ [key in keyof T]: string | number | boolean;
58
+ };
59
+ export type GFormState<T extends IForm<T>> = T & {
60
+ isValid: boolean;
61
+ isInvalid: boolean;
62
+ loading: boolean;
63
+ toRawData: () => RawData<T>;
64
+ toFormData: (options?: ToFormDataOptions<T>) => FormData;
65
+ toURLSearchParams: (options?: ToURLSearchParamsOptions<T>) => URLSearchParams;
66
+ setLoading: Dispatch<SetStateAction<boolean>>;
67
+ updateValidity: () => void;
68
+ };
69
+
70
+ type GElementProps = {
71
+ name: string;
72
+ };
73
+ export type GInputState<T extends string | number | boolean = string | number | boolean> = FieldWithError<BaseGenericFieldProps & {
74
+ checkValidity: () => boolean;
75
+ rows: number;
76
+ value: T;
77
+ required?: boolean;
78
+ }>;
79
+ type NonNativeHandlers = {
80
+ onChange: (e: {
81
+ target: {
82
+ value?: string;
83
+ };
84
+ } | ChangeEvent<unknown>) => void;
85
+ };
86
+ type GInputInitialProps = BaseGenericFieldProps & {
87
+ required?: boolean;
88
+ } & ({
89
+ type?: 'text' | 'password' | 'email' | 'tel' | 'url' | 'search';
90
+ minLength?: number;
91
+ maxLength?: number;
92
+ pattern?: string;
93
+ defaultValue?: string;
94
+ element?: (input: GInputState<string>, props: GElementProps, handlers: NonNativeHandlers) => JSX.Element;
95
+ } | {
96
+ type: 'checkbox';
97
+ defaultChecked?: boolean;
98
+ element?: (input: GInputState<boolean>, props: GElementProps, handlers: NonNativeHandlers) => JSX.Element;
99
+ } | {
100
+ type: 'color';
101
+ defaultValue?: string;
102
+ element?: (input: GInputState<string>, props: GElementProps, handlers: NonNativeHandlers) => JSX.Element;
103
+ } | {
104
+ type: 'number' | 'range' | 'date' | 'time' | 'week';
105
+ defaultValue?: number;
106
+ min?: number;
107
+ max?: number;
108
+ step?: number;
109
+ element?: (input: GInputState<number>, props: GElementProps, handlers: NonNativeHandlers) => JSX.Element;
110
+ } | {
111
+ type: 'file';
112
+ defaultValue?: string;
113
+ element?: (input: GInputState<string>, props: GElementProps, handlers: NonNativeHandlers) => JSX.Element;
114
+ } | {
115
+ type: 'select';
116
+ defaultValue?: string;
117
+ element?: (input: GInputState<string>, props: GElementProps, handlers: NonNativeHandlers) => JSX.Element;
118
+ });
119
+ export declare const GInput: FC<GInputInitialProps>;
120
+
121
+ export type GFormProps<T extends IForm> = Omit<HTMLAttributes<HTMLFormElement>, 'children' | 'onSubmit' | 'onChange'> & {
122
+ loader?: ReactNode;
123
+ stateRef?: MutableRefObject<GFormState<T> | undefined>;
124
+ onSubmit?: (state: GFormState<T>, e: FormEvent<HTMLFormElement>) => void;
125
+ children?: JSX.Element | JSX.Element[] | ((state: GFormState<T>) => JSX.Element | JSX.Element[]);
126
+ validators?: GValidators<T>;
127
+ };
128
+ /**
129
+ * build dynammic forms with validations.
130
+ *
131
+ * @example
132
+ * import { InputText } from "primereact/inputtext";
133
+ * import { Button } from 'primereact/button';
134
+ * import { GForm, GInput, IForm } from "gform-react";
135
+ *
136
+ * type SignInForm = IForm<{
137
+ * email: GInputState<string>;
138
+ * password: GInputState<string>;
139
+ * }>;
140
+ *
141
+ * const App: FC = () => {
142
+ * return (
143
+ * <div>
144
+ * ...
145
+ * <GForm className='some-class'>
146
+ * <GInput formKey={'email'} required minLength={7}
147
+ * element={(input, props) => <div>
148
+ * <label htmlFor="email">Email</label>
149
+ * <InputText {...props} id="email" aria-describedby="email-help" className={input.error ? "p-invalid" : ''} />
150
+ * {input.error && <small id="email-help" className="p-error">{input.errorText}</small>}
151
+ * </div>}
152
+ * />
153
+
154
+ * <GInput formKey={'password'} required
155
+ * element={(input, props) => <div>
156
+ * <label htmlFor="password">Password</label>
157
+ * <InputText {...props} id="password" aria-describedby="password-help" className={input.error ? "p-invalid" : ''} />
158
+ * {input.error && <small id="password-help" className="p-error">{input.errorText}</small>}
159
+ * </div>}
160
+ * />
161
+
162
+ * <Button label="Submit" aria-label="Submit" />
163
+ * </GForm>
164
+ * </div>
165
+ * );
166
+ * };
167
+ *
168
+ * @param validators - for handling validations (optional).
169
+ * @param loader - a component to display while loading (optional).
170
+ */
171
+ export declare const GForm: <T extends IForm>({ loader, stateRef, onSubmit, children, validators, ...rest }: GFormProps<T>) => JSX.Element;
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ !function(n,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"));else if("function"==typeof define&&define.amd)define(["react"],t);else{var e="object"==typeof exports?t(require("react")):t(n.React);for(var i in e)("object"==typeof exports?exports:n)[i]=e[i]}}(self,(n=>{return t={292:function(n,t,e){var i=this&&this.t||function(){return i=Object.assign||function(n){for(var t,e=1,i=arguments.length;e<i;e++)for(var r in t=arguments[e])Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},i.apply(this,arguments)},r=this&&this.i||(Object.create?function(n,t,e,i){void 0===i&&(i=e);var r=Object.getOwnPropertyDescriptor(t,e);r&&!("get"in r?!t.u:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,i,r)}:function(n,t,e,i){void 0===i&&(i=e),n[i]=t[e]}),u=this&&this.o||(Object.create?function(n,t){Object.defineProperty(n,"default",{enumerable:!0,value:t})}:function(n,t){n.default=t}),o=this&&this.l||function(n){if(n&&n.u)return n;var t={};if(null!=n)for(var e in n)"default"!==e&&Object.prototype.hasOwnProperty.call(n,e)&&r(t,n,e);return u(t,n),t},a=this&&this.v||function(n,t){var e={};for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&t.indexOf(i)<0&&(e[i]=n[i]);if(null!=n&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(n);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(n,i[r])&&(e[i[r]]=n[i[r]])}return e};Object.defineProperty(t,"u",{value:!0}),t.GForm=void 0;var c=o(e(244)),f=e(464),l=e(886),v=e(173);t.GForm=function(n){var t=n.loader,e=void 0===t?c.default.createElement("div",null,"loading"):t,r=n.stateRef,u=n.onSubmit,o=n.children,s=n.validators,d=a(n,["loader","stateRef","onSubmit","children","validators"]),h=(0,c.useRef)(null),b=(0,c.useMemo)((function(){return(0,l.buildFormInitialValues)("function"==typeof o?o({}):o)}),[]),j=(0,f.useForm)(b,s),O=j.fields,p=j.updateInputHandler,m=j.validateInputHandler,y=(0,c.useState)(!1),g=y[0],_=y[1],M=(0,c.useMemo)((function(){var n=(0,l.isFormValid)(O),t=i(i({},O),{isValid:n,isInvalid:!n,loading:g,toRawData:function(n){return(0,l.toRawData)(O,n)},toFormData:function(){return(0,l.toFormData)(h.current)},toURLSearchParams:l.toURLSearchParams,updateValidity:function(){var n;this.isValid=(null===(n=h.current)||void 0===n?void 0:n.checkValidity())||!1,this.isInvalid=!this.isValid},setLoading:_});return r&&(r.current=t),t}),[O]),I=(0,c.useMemo)((function(){return c.default.createElement("form",i({},d,{ref:h,onChange:function(n){return p(n.target.name,n)},onBlur:function(n){return m(O[n.target.name],n)},onInvalid:function(n){n.preventDefault(),m(O[n.target.name],n)},onSubmit:function(n){n.preventDefault(),null==u||u(M,n)}}),"function"==typeof o?o(M):o)}),[M]);return c.default.createElement(v.GFormContext.Provider,{value:j},g?e:I)}},173:(n,t,e)=>{Object.defineProperty(t,"u",{value:!0}),t.useGenericFormContext=t.GFormContext=void 0;var i=e(244);t.GFormContext=(0,i.createContext)({fields:{},updateInputHandler:function(){return null},validateInputHandler:function(){return null}}),t.useGenericFormContext=function(){return(0,i.useContext)(t.GFormContext)}},100:function(n,t,e){var i=this&&this.t||function(){return i=Object.assign||function(n){for(var t,e=1,i=arguments.length;e<i;e++)for(var r in t=arguments[e])Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},i.apply(this,arguments)},r=this&&this.i||(Object.create?function(n,t,e,i){void 0===i&&(i=e);var r=Object.getOwnPropertyDescriptor(t,e);r&&!("get"in r?!t.u:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,i,r)}:function(n,t,e,i){void 0===i&&(i=e),n[i]=t[e]}),u=this&&this.o||(Object.create?function(n,t){Object.defineProperty(n,"default",{enumerable:!0,value:t})}:function(n,t){n.default=t}),o=this&&this.l||function(n){if(n&&n.u)return n;var t={};if(null!=n)for(var e in n)"default"!==e&&Object.prototype.hasOwnProperty.call(n,e)&&r(t,n,e);return u(t,n),t},a=this&&this.v||function(n,t){var e={};for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&t.indexOf(i)<0&&(e[i]=n[i]);if(null!=n&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(n);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(n,i[r])&&(e[i[r]]=n[i[r]])}return e};Object.defineProperty(t,"u",{value:!0}),t.GInput=void 0;var c=o(e(244)),f=e(173);t.GInput=function(n){var t=n.formKey,e=n.element,r=n.type,u=void 0===r?"text":r,o=(n.validatorKey,a(n,["formKey","element","type","validatorKey"])),l=(0,f.useGenericFormContext)(),v=l.fields,s=l.updateInputHandler,d=v[t];return(0,c.useMemo)((function(){var n=i(i({},o),{type:u,name:t});return e?e(d,n,{onChange:function(n){s(t,n)}}):c.default.createElement("input",i({},n))}),[d.value,d.error,d.errorText])}},107:function(n,t,e){var i=this&&this.i||(Object.create?function(n,t,e,i){void 0===i&&(i=e);var r=Object.getOwnPropertyDescriptor(t,e);r&&!("get"in r?!t.u:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,i,r)}:function(n,t,e,i){void 0===i&&(i=e),n[i]=t[e]}),r=this&&this.h||function(n,t){for(var e in n)"default"===e||Object.prototype.hasOwnProperty.call(t,e)||i(t,n,e)};Object.defineProperty(t,"u",{value:!0}),r(e(100),t)},217:(n,t)=>{Object.defineProperty(t,"u",{value:!0})},886:function(n,t){var e=this&&this.t||function(){return e=Object.assign||function(n){for(var t,e=1,i=arguments.length;e<i;e++)for(var r in t=arguments[e])Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},e.apply(this,arguments)};Object.defineProperty(t,"u",{value:!0}),t.toURLSearchParams=t.toFormData=t.toRawData=t.isFormValid=t.findValidityKey=t.buildFormInitialValues=t.isGFInput=void 0;var i={text:{value:""},file:{value:""},datepicker:{value:""},checkbox:{value:!1}};t.isGFInput=function(n){return Boolean(n.formKey)},t.buildFormInitialValues=function(n){void 0===n&&(n=[]);var t={};return Array.isArray(n)||(n=[n]),console.log("[buildFormInitialValues] -","building initial values for ",n),n.forEach((function(n){var u=r(n);u&&u.forEach((function(n){console.log("[buildFormInitialValues] -","building input","(".concat(n.formKey,")"),n),t[n.formKey]&&console.warn("[Duplicate Keys].\nfield with key '".concat(n.formKey,"' has already been defined."));var r=i[n.type||"text"]||i.text,u=n.defaultValue||r.value;t[n.formKey]=e(e(e({},r),n),{value:u}),delete t[n.formKey].element}))})),t};var r=function(n,t){var e,i;return void 0===t&&(t=[]),n?Array.isArray(n)?(n.forEach((function(n){return r(n,t)})),t):(null===(e=n.props)||void 0===e?void 0:e.formKey)?(console.log("[findInputs] -","input config found","(".concat(n.props.formKey,")")),t.push(n.props),t):r(null===(i=n.props)||void 0===i?void 0:i.children,t):t};t.findValidityKey=function(n){for(var t in n)if("valid"!==t&&n[t])return console.log("[findValidityKey] -","found validity key:",t),t},t.isFormValid=function(n){for(var t in n)if(n[t].error)return!1;return!0},t.toRawData=function(n,t){void 0===t&&(t=function(n){return n.value});var e={};for(var i in n)e[i]=t(n[i]);return e},t.toFormData=function(n,t){if(!n)return new FormData;if(t){var e,i=t.exclude,r=t.include;if(r)return e=new FormData,r.forEach((function(t){return e.set(t,n[t].value)})),e;if(i)return e=new FormData(n),i.forEach((function(n){return e.delete(n)})),e}return new FormData(n)},t.toURLSearchParams=function(n){var t=this;if(n){var e,i=n.exclude,r=n.include;return r?(e={},r.forEach((function(n){return e[n]=t[n].value}))):(e=this.toRawData(),null==i||i.forEach((function(n){return delete e[n]}))),new URLSearchParams(e)}return new URLSearchParams(this.toRawData())}},820:function(n,t,e){var i=this&&this.i||(Object.create?function(n,t,e,i){void 0===i&&(i=e);var r=Object.getOwnPropertyDescriptor(t,e);r&&!("get"in r?!t.u:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,i,r)}:function(n,t,e,i){void 0===i&&(i=e),n[i]=t[e]}),r=this&&this.h||function(n,t){for(var e in n)"default"===e||Object.prototype.hasOwnProperty.call(t,e)||i(t,n,e)};Object.defineProperty(t,"u",{value:!0}),r(e(292),t),r(e(217),t),r(e(929),t),r(e(107),t),r(e(351),t)},929:(n,t)=>{Object.defineProperty(t,"u",{value:!0})},464:function(n,t,e){var i=this&&this.t||function(){return i=Object.assign||function(n){for(var t,e=1,i=arguments.length;e<i;e++)for(var r in t=arguments[e])Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},i.apply(this,arguments)};Object.defineProperty(t,"u",{value:!0}),t.useForm=void 0;var r=e(244),u=e(886),o=e(841);t.useForm=function(n,t){void 0===t&&(t={});var e=(0,r.useState)(n),a=e[0],c=e[1],f=function(n,t){if(n)if(n.checkValidity||(n.checkValidity=function(){return t.target.checkValidity()}),t.target instanceof HTMLInputElement||t.target instanceof HTMLTextAreaElement||t.target instanceof HTMLSelectElement){t.target.setCustomValidity("");var e=t.target.validity,i=(0,u.findValidityKey)(e);l(n,i),!i&&n.error&&t.target.setCustomValidity("GFCustomValidation")}else console.log("[validateInputHandler] -","the input '".concat(n.formKey,"' is not a native element\nevent:"),t),l(n,n.required&&!n.value?"valueMissing":void 0)},l=function(n,e){var r,u=t[n.validatorKey||n.formKey],f=u instanceof o.GValidator?u.handlers:u;console.log("[validateInput] -","validating input:",n.formKey,"(".concat(e||"custom",")")),s(n,f,e),c(i(i({},a),((r={})[n.formKey]=n,r)))},v=function(n,t){a[n].value=t},s=function(n,t,e){var i=function(){n.error=Boolean(e)};if(!t)return i();try{console.log("[_validateInput] -","validating input with handlers:",t),n.error=t.some((function(t,i){var r="function"==typeof t?t(n,e,a):t,u="boolean"==typeof r?r:!r.test(String(n.value));return console.log("[_validateInput] -","validation results for handler (".concat(i,"):\n"),t,"\n\nvalidator result:",r,"\nviolation:",u,"(".concat(u?"failed":"passed",")")),u})),n.error||(n.errorText="")}catch(n){i()}};return{fields:a,updateInputHandler:function(n,t){var e="checkbox"===a[n].type?t.target.checked:t.target.value;v(n,e),f(a[n],t)},validateInputHandler:f}}},841:(n,t)=>{Object.defineProperty(t,"u",{value:!0}),t.GValidator=void 0;var e=function(){function n(n){var t=(null==n?void 0:n.handlers)||[];this.handlers=(new Array).concat(t)}return n.prototype.withRequiredMessage=function(n){return this.j("valueMissing",n)},n.prototype.withMaxLengthMessage=function(n){return this.j("tooLong",n)},n.prototype.withMinLengthMessage=function(n){return this.j("tooShort",n)},n.prototype.withPatternMismatchMessage=function(n){return this.j("patternMismatch",n)},n.prototype.withBadInputMessage=function(n){return this.j("badInput",n)},n.prototype.withRangeUnderflowMessage=function(n){return this.j("rangeUnderflow",n)},n.prototype.withRangeOverflowMessage=function(n){return this.j("rangeOverflow",n)},n.prototype.withTypeMismatchMessage=function(n){return this.j("typeMismatch",n)},n.prototype.withStepMismatchMessage=function(n){return this.j("stepMismatch",n)},n.prototype.withCustomValidation=function(n){return this.handlers.push(n),this},n.prototype.j=function(n,t){return this.handlers.push((function(e,i){return i===n&&(e.errorText="string"==typeof t?t:t(e),!0)})),this},n}();t.GValidator=e},351:function(n,t,e){var i=this&&this.i||(Object.create?function(n,t,e,i){void 0===i&&(i=e);var r=Object.getOwnPropertyDescriptor(t,e);r&&!("get"in r?!t.u:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,i,r)}:function(n,t,e,i){void 0===i&&(i=e),n[i]=t[e]}),r=this&&this.h||function(n,t){for(var e in n)"default"===e||Object.prototype.hasOwnProperty.call(t,e)||i(t,n,e)};Object.defineProperty(t,"u",{value:!0}),r(e(841),t)},244:t=>{t.exports=n}},e={},function n(i){var r=e[i];if(void 0!==r)return r.exports;var u=e[i]={exports:{}};return t[i].call(u.exports,u,u.exports,n),u.exports}(820);var t,e}));
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAChD,GAAsB,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,EAAQG,QAA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AAQA,EAAOD,QAAS4I,GAGpE3I,EAAOD,OACf,CCnB0B4I,CAAoB,K,MDF1CD,C","sources":["webpack://gform-react/webpack/universalModuleDefinition","webpack://gform-react/./src/GForm.tsx","webpack://gform-react/./src/context.ts","webpack://gform-react/./src/fields/GInput.tsx","webpack://gform-react/./src/fields/index.ts","webpack://gform-react/./src/helpers.ts","webpack://gform-react/./src/index.ts","webpack://gform-react/./src/useForm.ts","webpack://gform-react/./src/validations/GValidator.ts","webpack://gform-react/./src/validations/index.ts","webpack://gform-react/external umd {\"root\":\"React\",\"commonjs2\":\"react\",\"commonjs\":\"react\",\"amd\":\"react\",\"umd\":\"react\"}","webpack://gform-react/webpack/bootstrap","webpack://gform-react/webpack/startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"react\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"react\"], factory);\n\telse {\n\t\tvar a = typeof exports === 'object' ? factory(require(\"react\")) : factory(root[\"React\"]);\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(self, (__WEBPACK_EXTERNAL_MODULE__244__) => {\nreturn ","import React, { ReactNode, useMemo, useState, MutableRefObject, HTMLAttributes, useRef, ChangeEvent, FormEvent } from \"react\";\r\n\r\nimport { useForm } from \"./useForm\";\r\nimport { buildFormInitialValues, toRawData, toFormData, isFormValid, toURLSearchParams } from \"./helpers\";\r\nimport { GFormContext } from \"./context\";\r\nimport { GFormState, ToRawDataSetter } from \"./state\";\r\nimport { GValidators } from \"./validations\";\r\nimport { IForm } from \"./form\";\r\n\r\nexport type GFormProps<T extends IForm> = Omit<HTMLAttributes<HTMLFormElement>, 'children' | 'onSubmit' | 'onChange'> & {\r\n loader?: ReactNode;\r\n stateRef?: MutableRefObject<GFormState<T> | undefined>;\r\n onChange?: (state: GFormState<T>, e: FormEvent<HTMLFormElement>) => void;\r\n onSubmit?: (state: GFormState<T>, e: FormEvent<HTMLFormElement>) => void;\r\n children?: JSX.Element | JSX.Element[] | ((state: GFormState<T>) => JSX.Element | JSX.Element[]);\r\n validators?: GValidators<T>;\r\n};\r\n\r\n/**\r\n * build dynammic forms with validations.\r\n *\r\n * @example\r\n * import { InputText } from \"primereact/inputtext\";\r\n * import { Button } from 'primereact/button';\r\n * import { GForm, GInput, IForm } from \"gform-react\";\r\n * \r\n * type SignInForm = IForm<{\r\n * email: GInputState<string>;\r\n * password: GInputState<string>;\r\n * }>;\r\n *\r\n * const App: FC = () => {\r\n * return (\r\n * <div>\r\n * ...\r\n * <GForm className='some-class'>\r\n * <GInput formKey={'email'} required minLength={7}\r\n * element={(input, props) => <div>\r\n * <label htmlFor=\"email\">Email</label>\r\n * <InputText {...props} id=\"email\" aria-describedby=\"email-help\" className={input.error ? \"p-invalid\" : ''} />\r\n * {input.error && <small id=\"email-help\" className=\"p-error\">{input.errorText}</small>}\r\n * </div>}\r\n * />\r\n \r\n * <GInput formKey={'password'} required \r\n * element={(input, props) => <div>\r\n * <label htmlFor=\"password\">Password</label>\r\n * <InputText {...props} id=\"password\" aria-describedby=\"password-help\" className={input.error ? \"p-invalid\" : ''} />\r\n * {input.error && <small id=\"password-help\" className=\"p-error\">{input.errorText}</small>}\r\n * </div>}\r\n * />\r\n \r\n * <Button label=\"Submit\" aria-label=\"Submit\" />\r\n * </GForm>\r\n * </div>\r\n * );\r\n * };\r\n *\r\n * @param validators - for handling validations (optional).\r\n * @param loader - a component to display while loading (optional).\r\n */\r\nexport const GForm = <T extends IForm>({\r\n loader = <div>loading</div>,\r\n stateRef,\r\n onSubmit,\r\n children,\r\n validators,\r\n ...rest\r\n}: GFormProps<T>): JSX.Element => {\r\n const formRef = useRef<HTMLFormElement>(null);\r\n const initialValues = useMemo(() => buildFormInitialValues<T>(typeof children === 'function' ? children({} as GFormState<T>) : children), []);\r\n const values = useForm(initialValues, validators);\r\n const { fields, updateInputHandler, validateInputHandler } = values;\r\n const [loading, setLoading] = useState(false);\r\n\r\n const formState = useMemo(() => {\r\n const _isFormValid = isFormValid(fields);\r\n\r\n const formState: GFormState<T> = {\r\n ...fields,\r\n isValid: _isFormValid,\r\n isInvalid: !_isFormValid,\r\n loading,\r\n toRawData: (setter?: ToRawDataSetter) => toRawData(fields, setter),\r\n toFormData: () => toFormData(formRef.current),\r\n toURLSearchParams: toURLSearchParams,\r\n updateValidity: function () { // it has to be function in order to refer to 'this'\r\n this.isValid = formRef.current?.checkValidity() || false;\r\n this.isInvalid = !this.isValid;\r\n },\r\n setLoading\r\n };\r\n\r\n if (stateRef) stateRef.current = formState;\r\n\r\n return formState;\r\n }, [fields]);\r\n\r\n const form = useMemo(() => <form {...rest} ref={formRef}\r\n onChange={(e: ChangeEvent<HTMLFormElement>) => updateInputHandler(e.target.name, e)}\r\n onBlur={(e) => validateInputHandler(fields[e.target.name], e)}\r\n onInvalid={(e: ChangeEvent<HTMLFormElement>) => {\r\n e.preventDefault(); // hide default browser validation tooltip\r\n validateInputHandler(fields[e.target.name], e);\r\n }}\r\n onSubmit={(e) => {\r\n e.preventDefault();\r\n onSubmit?.(formState, e);\r\n }}>\r\n {typeof children === 'function' ? children(formState) : children}\r\n </form>, [formState]);\r\n\r\n return (\r\n <GFormContext.Provider value={values}>\r\n {\r\n loading\r\n ?\r\n loader\r\n :\r\n form\r\n }\r\n </GFormContext.Provider>\r\n );\r\n};","import {createContext, useContext} from \"react\";\r\nimport { IForm } from \"./form\";\r\nimport { useForm } from \"./useForm\";\r\n\r\nexport type GContext<T> = ReturnType<T & typeof useForm>;\r\n\r\nexport const GFormContext = createContext<GContext<IForm>>(\r\n {\r\n fields: {},\r\n updateInputHandler: () => null,\r\n validateInputHandler: () => null\r\n }\r\n);\r\n\r\nexport const useGenericFormContext = () => useContext<GContext<IForm>>(GFormContext);","import React, { ChangeEvent, FC, useMemo } from 'react';\r\nimport { useGenericFormContext } from \"../context\";\r\nimport { BaseGenericFieldProps, FieldWithError } from \".\";\r\n\r\ntype GElementProps = {\r\n name: string;\r\n};\r\n\r\nexport type GInputState<T extends string | number | boolean = string | number | boolean> = FieldWithError<BaseGenericFieldProps & {\r\n checkValidity: () => boolean;\r\n rows: number;\r\n value: T;\r\n required?: boolean;\r\n}>;\r\n\r\ntype NonNativeHandlers = {\r\n onChange: (e: {target: {value?: string;}} | ChangeEvent<unknown>) => void;\r\n};\r\n\r\nexport type GInputInitialProps = BaseGenericFieldProps & {\r\n required?: boolean;\r\n} & (\r\n {\r\n type?: 'text' | 'password' | 'email' | 'tel' | 'url' | 'search';\r\n minLength?: number;\r\n maxLength?: number;\r\n pattern?: string;\r\n defaultValue?: string;\r\n element?: (input: GInputState<string>, props: GElementProps, handlers: NonNativeHandlers) => JSX.Element;\r\n }\r\n |\r\n {\r\n type: 'checkbox';\r\n defaultChecked?: boolean;\r\n element?: (input: GInputState<boolean>, props: GElementProps, handlers: NonNativeHandlers) => JSX.Element;\r\n }\r\n |\r\n {\r\n type: 'color';\r\n defaultValue?: string;\r\n element?: (input: GInputState<string>, props: GElementProps, handlers: NonNativeHandlers) => JSX.Element;\r\n }\r\n |\r\n {\r\n type: 'number' | 'range' | 'date' | 'time' | 'week';\r\n defaultValue?: number;\r\n min?: number;\r\n max?: number;\r\n step?: number;\r\n element?: (input: GInputState<number>, props: GElementProps, handlers: NonNativeHandlers) => JSX.Element;\r\n }\r\n |\r\n {\r\n type: 'file';\r\n defaultValue?: string;\r\n element?: (input: GInputState<string>, props: GElementProps, handlers: NonNativeHandlers) => JSX.Element;\r\n }\r\n |\r\n {\r\n type: 'select';\r\n defaultValue?: string;\r\n element?: (input: GInputState<string>, props: GElementProps, handlers: NonNativeHandlers) => JSX.Element;\r\n }\r\n );\r\n\r\nexport const GInput: FC<GInputInitialProps> = ({ formKey, element, type = 'text', validatorKey, ...rest }) => {\r\n const { fields, updateInputHandler } = useGenericFormContext();\r\n const inputState = fields[formKey];\r\n\r\n const _element = useMemo(() => {\r\n const _props = {\r\n ...rest,\r\n type,\r\n name: formKey\r\n };\r\n\r\n if (element) {\r\n const nonNativeHandlers: NonNativeHandlers = {\r\n onChange: (e) => {\r\n updateInputHandler(formKey, e);\r\n }\r\n };\r\n return (element as (input: GInputState, props: GElementProps, handlers: NonNativeHandlers) => JSX.Element)(inputState, _props, nonNativeHandlers);\r\n }\r\n\r\n return (\r\n <input {..._props} />\r\n );\r\n }, [inputState.value, inputState.error, inputState.errorText]);\r\n\r\n return _element;\r\n};","import { GInputState } from \"./GInput\";\r\n\r\nexport * from './GInput';\r\n\r\nexport type BaseGenericFieldProps = {\r\n formKey: string;\r\n validatorKey?: string;\r\n type?: 'text' | 'password' | 'email' | 'tel' | 'checkbox' | 'number' | 'range' | 'color' | 'file' | 'date' | 'month' | 'week' | 'time' | 'search' | 'select';\r\n};\r\n\r\nexport type FieldWithError<T extends BaseGenericFieldProps = GInputState> = T & {\r\n error: boolean;\r\n errorText: string;\r\n checkValidity: () => boolean;\r\n};","import { BaseGenericFieldProps, GInputInitialProps, GInputState } from './fields';\r\nimport { IForm } from './form';\r\nimport { GFormState, RawData, ToRawDataSetter } from './state';\r\n\r\n/* =======================================================\r\n * reminder: `$DEF_DEBUG` blocks are excluded from bundle!\r\n * =====================================================*/\r\n\r\ntype GInputInitialPropsWithValue = GInputInitialProps & {\r\n value?: string | number | boolean;\r\n defaultValue?: string | number | boolean;\r\n};\r\n\r\nconst defaultFieldProps: { [key: string]: {value: string | number | boolean} } = {\r\n text: { value: '' },\r\n file: { value: '' },\r\n datepicker: {\r\n value: '',\r\n },\r\n checkbox: { value: false }\r\n};\r\n\r\nexport const isGFInput = (input: BaseGenericFieldProps): input is GInputState<string | number | boolean> => Boolean(input.formKey);\r\n\r\nexport const buildFormInitialValues = <T extends IForm>(rows: JSX.Element | JSX.Element[] = []): T => {\r\n const fieldsSchema = {} as { [key: string]: Omit<GInputInitialPropsWithValue, 'formKey'> };\r\n\r\n if (!Array.isArray(rows)) rows = [rows];\r\n\r\n if ($DEF_DEBUG) {\r\n console.log('[buildFormInitialValues] -', 'building initial values for ', rows);\r\n }\r\n\r\n rows.forEach(row => {\r\n const inputConfigs = findInputs(row);\r\n\r\n if (inputConfigs) {\r\n inputConfigs.forEach(config => {\r\n if ($DEF_DEBUG) {\r\n console.log('[buildFormInitialValues] -', 'building input', `(${config.formKey})`,config);\r\n }\r\n\r\n if (fieldsSchema[config.formKey]) {\r\n console.warn(`[Duplicate Keys].\\nfield with key '${config.formKey}' has already been defined.`);\r\n }\r\n\r\n const defaultProps = defaultFieldProps[config.type || 'text'] || defaultFieldProps.text;\r\n const inputValue = config.defaultValue || defaultProps.value;\r\n\r\n fieldsSchema[config.formKey] = {\r\n ...defaultProps,\r\n ...config,\r\n value: inputValue\r\n };\r\n\r\n delete fieldsSchema[config.formKey].element;\r\n });\r\n }\r\n });\r\n return fieldsSchema as T;\r\n};\r\n\r\nconst findInputs = (root?: JSX.Element | JSX.Element[], total: GInputInitialPropsWithValue[] = []): GInputInitialPropsWithValue[] => {\r\n if (!root) return total;\r\n\r\n if (Array.isArray(root)) {\r\n root.forEach(element => findInputs(element, total));\r\n return total;\r\n }\r\n\r\n if (root.props?.formKey) {\r\n if ($DEF_DEBUG) {\r\n console.log('[findInputs] -', 'input config found', `(${root.props.formKey})`);\r\n }\r\n total.push(root.props);\r\n return total;\r\n }\r\n\r\n return findInputs(root.props?.children, total);\r\n};\r\n\r\nexport const findValidityKey = (validity: ValidityState): keyof ValidityState | undefined => {\r\n for (const key in validity) {\r\n if (key !== 'valid' && validity[key as keyof ValidityState]) {\r\n if ($DEF_DEBUG) {\r\n console.log('[findValidityKey] -', 'found validity key:', key);\r\n }\r\n return key as keyof ValidityState;\r\n }\r\n }\r\n};\r\n\r\nexport const isFormValid = (fields: IForm): boolean => {\r\n for (const f in fields) {\r\n if (fields[f].error) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n};\r\n\r\nexport const toRawData = <T extends IForm>(fields: T, setter: ToRawDataSetter = (field) => field.value): RawData<T> => {\r\n const data = {} as RawData<T>;\r\n for (const f in fields) {\r\n data[f] = setter(fields[f]);\r\n }\r\n return data;\r\n};\r\n\r\nexport type ToFormDataOptions<T extends IForm> = ToURLSearchParamsOptions<T>;\r\n\r\nexport const toFormData = <T extends IForm>(form: HTMLFormElement | null, options?: ToFormDataOptions<T>): FormData => {\r\n if (!form) return new FormData();\r\n\r\n if (options) {\r\n const { exclude, include } = options;\r\n let formData: FormData;\r\n\r\n if (include) {\r\n formData = new FormData();\r\n include.forEach(key => formData.set(key as string, form[key as string].value));\r\n return formData;\r\n }\r\n else if (exclude) {\r\n formData = new FormData(form);\r\n exclude.forEach(key => formData.delete(key as string));\r\n return formData;\r\n }\r\n }\r\n\r\n return new FormData(form);\r\n};\r\n\r\n\r\nexport type ToURLSearchParamsOptions<T extends IForm> = {\r\n exclude?: (keyof T)[];\r\n include?: (keyof T)[];\r\n};\r\n\r\nexport function toURLSearchParams<T extends IForm>(this: GFormState<T>, options?: ToURLSearchParamsOptions<T>): URLSearchParams {\r\n\r\n if (options) {\r\n let data: RawData<T>;\r\n\r\n const { exclude, include } = options;\r\n if (include) {\r\n data = {} as RawData<T>;\r\n include.forEach(key => (data[key] = this[key].value));\r\n }\r\n else {\r\n data = this.toRawData();\r\n exclude?.forEach(key => delete data[key]);\r\n }\r\n\r\n return new URLSearchParams(data as Record<string, string>);\r\n } \r\n\r\n return new URLSearchParams(this.toRawData() as Record<string, string>); // this is ok because URLSearchParams will stringify the values (boolean/number)\r\n}","export * from './GForm';\r\nexport * from './form';\r\nexport * from './state';\r\nexport * from './fields';\r\nexport * from './validations';","import { useState } from \"react\";\r\n\r\nimport { GInputState } from \"./fields\";\r\nimport { findValidityKey } from \"./helpers\";\r\nimport { GValidator } from \"./validations/GValidator\";\r\nimport { GValidatorHandler, GValidators } from \"./validations\";\r\nimport { BaseFormEvent, IForm, GFormChangeEvent, GFormEvent } from \"./form\";\r\n\r\nexport function useForm<T extends IForm>(initialValues: T, validators: GValidators<T> = {}) {\r\n const [fields, setFields] = useState(initialValues);\r\n\r\n /**\r\n * handler for validating a form input\r\n * @param input the input to be validated\r\n * @param e the event object\r\n */\r\n const validateInputHandler = (input: GInputState, e: GFormEvent | BaseFormEvent): void => {\r\n if (!input) return;\r\n if (!input.checkValidity) input.checkValidity = () => (e.target as HTMLInputElement).checkValidity();\r\n\r\n if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement || e.target instanceof HTMLSelectElement) {\r\n e.target.setCustomValidity(''); //reset any previous error (custom)\r\n\r\n const validity = e.target.validity;\r\n const validityKey = findValidityKey(validity);\r\n\r\n validateInput(input, validityKey);\r\n\r\n if (!validityKey && input.error) {\r\n e.target.setCustomValidity('GFCustomValidation');\r\n }\r\n } else {\r\n if ($DEF_DEBUG) {\r\n console.log('[validateInputHandler] -', `the input '${input.formKey}' is not a native element\\nevent:`, e);\r\n }\r\n //fallback - validate the input for 'required' constraint validation (valueMissing)\r\n //TODO - add the rest of constraint validations\r\n validateInput(input, input.required && !input.value ? 'valueMissing' : undefined);\r\n }\r\n };\r\n\r\n /**\r\n * handler for updating and validating a form input\r\n * @param key the key used to identify the input (`formKey`)\r\n * @param e the event object\r\n */\r\n const updateInputHandler = (key: string, e: GFormChangeEvent | GFormEvent | BaseFormEvent): void => {\r\n const value = fields[key].type === 'checkbox' ? (e.target as HTMLInputElement).checked : (e.target as HTMLInputElement).value;\r\n updateInput(key, value);\r\n validateInputHandler(fields[key], e);\r\n };\r\n\r\n /**\r\n * Validates the input and updates the state with the result\r\n * @param input the input to be validated\r\n * @param validityKey the `Constraint Validation` key\r\n */\r\n const validateInput = (input: GInputState, validityKey?: keyof ValidityState): void => {\r\n const inputValidator = validators[(input.validatorKey || input.formKey)];\r\n const handlers = inputValidator instanceof GValidator ? inputValidator.handlers : inputValidator;\r\n if ($DEF_DEBUG) {\r\n console.log('[validateInput] -', 'validating input:', input.formKey, `(${validityKey ? validityKey : 'custom'})`);\r\n }\r\n _validateInput(input, handlers as Required<GValidatorHandler<T>[]> , validityKey);\r\n setFields({ ...fields, [input.formKey]: input });\r\n };\r\n\r\n /**\r\n * update the input state.\r\n * @param key the key used to identify the input (`formKey`)\r\n * @param value the new value\r\n */\r\n const updateInput = (key: string, value: GInputState['value']) => {\r\n const input = fields[key];\r\n input.value = value;\r\n };\r\n\r\n /**\r\n * @internal\r\n */\r\n const _validateInput = (input: GInputState, handlers: GValidatorHandler<T>[], validityKey?: keyof ValidityState): void => {\r\n const fallback = () => {\r\n input.error = Boolean(validityKey);\r\n };\r\n\r\n if (!handlers) return fallback();\r\n\r\n const validate = (validatorHandler: GValidatorHandler<T>, index: number): boolean => {\r\n const result = typeof validatorHandler === 'function' ? validatorHandler(input, validityKey, fields) : validatorHandler;\r\n const isInvalid = typeof result === 'boolean' ? result : !result.test(String(input.value));\r\n\r\n if ($DEF_DEBUG) {\r\n console.log('[_validateInput] -', `validation results for handler (${index}):\\n`, validatorHandler, '\\n\\nvalidator result:', result, '\\nviolation:', isInvalid, `(${isInvalid ? 'failed' : 'passed'})`);\r\n }\r\n\r\n return isInvalid;\r\n };\r\n\r\n try {\r\n if ($DEF_DEBUG) {\r\n console.log('[_validateInput] -', 'validating input with handlers:', handlers);\r\n }\r\n input.error = handlers.some(validate);\r\n if (!input.error) input.errorText = '';\r\n }\r\n catch (e) {\r\n if (process.env.NODE_ENV !== 'production')\r\n console.warn(`DEV only: cannot validate input with key '${input.formKey}'\\nfalling back with basic input validation.\\nreason:\\n`, e);\r\n fallback();\r\n }\r\n };\r\n\r\n return { fields, updateInputHandler, validateInputHandler };\r\n}","import type { GConstraintValidatorHandler, GValidatorHandler } from \".\";\r\n\r\nexport class GValidator {\r\n public readonly handlers: GValidatorHandler[];\r\n\r\n constructor (baseValidator?: GValidator) {\r\n const baseHandlers = baseValidator?.handlers || [];\r\n this.handlers = new Array<GValidatorHandler>().concat(baseHandlers);\r\n }\r\n\r\n withRequiredMessage(message: string | GConstraintValidatorHandler): GValidator {\r\n return this.__addConstraintValidationHandler('valueMissing', message);\r\n }\r\n\r\n withMaxLengthMessage(message: string | GConstraintValidatorHandler): GValidator {\r\n return this.__addConstraintValidationHandler('tooLong', message);\r\n }\r\n\r\n withMinLengthMessage(message: string | GConstraintValidatorHandler): GValidator {\r\n return this.__addConstraintValidationHandler('tooShort', message);\r\n }\r\n\r\n withPatternMismatchMessage(message: string | GConstraintValidatorHandler): GValidator {\r\n return this.__addConstraintValidationHandler('patternMismatch', message);\r\n }\r\n\r\n withBadInputMessage(message: string | GConstraintValidatorHandler): GValidator {\r\n return this.__addConstraintValidationHandler('badInput', message);\r\n }\r\n\r\n withRangeUnderflowMessage(message: string | GConstraintValidatorHandler): GValidator {\r\n return this.__addConstraintValidationHandler('rangeUnderflow', message);\r\n }\r\n\r\n withRangeOverflowMessage(message: string | GConstraintValidatorHandler): GValidator {\r\n return this.__addConstraintValidationHandler('rangeOverflow', message);\r\n }\r\n\r\n withTypeMismatchMessage(message: string | GConstraintValidatorHandler): GValidator {\r\n return this.__addConstraintValidationHandler('typeMismatch', message);\r\n }\r\n\r\n withStepMismatchMessage(message: string | GConstraintValidatorHandler): GValidator {\r\n return this.__addConstraintValidationHandler('stepMismatch', message);\r\n }\r\n\r\n withCustomValidation(handler: GValidatorHandler): GValidator {\r\n this.handlers.push(handler);\r\n return this;\r\n }\r\n\r\n private __addConstraintValidationHandler(validityKey: keyof ValidityState, message: string | GConstraintValidatorHandler): GValidator {\r\n this.handlers.push((input, key) => {\r\n if (key === validityKey) {\r\n input.errorText = typeof message === 'string' ? message : message(input);\r\n return true;\r\n }\r\n return false;\r\n });\r\n\r\n return this;\r\n }\r\n}","import { IForm } from \"..\";\r\nimport type { FieldWithError, GInputState } from \"../fields\";\r\nimport type { GValidator } from \"./GValidator\";\r\n\r\nexport type GConstraintValidatorHandler = (input: FieldWithError<GInputState>) => string;\r\n\r\nexport type GValidatorHandler<F extends IForm = IForm> = RegExp |\r\n ((input: FieldWithError<GInputState>, validityKey: keyof ValidityState | undefined, fields: F) => RegExp | boolean);\r\n\r\nexport type GValidators<T extends IForm> = {\r\n [key in keyof T]?: GValidator | GValidatorHandler<T>[];\r\n};\r\n\r\nexport * from './GValidator';","module.exports = __WEBPACK_EXTERNAL_MODULE__244__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(820);\n"],"names":["root","factory","exports","module","require","define","amd","a","i","self","__WEBPACK_EXTERNAL_MODULE__244__","_a","loader","react_1","stateRef","onSubmit","children","validators","rest","formRef","useRef","initialValues","useMemo","buildFormInitialValues","values","useForm","fields","updateInputHandler","validateInputHandler","useState","loading","setLoading","formState","_isFormValid","isFormValid","isValid","isInvalid","toRawData","setter","toFormData","current","toURLSearchParams","helpers_1","updateValidity","this","checkValidity","form","ref","onChange","e","target","name","onBlur","onInvalid","preventDefault","context_1","Provider","value","createContext","useContext","formKey","element","_b","type","useGenericFormContext","inputState","_props","error","errorText","__exportStar","defaultFieldProps","text","file","datepicker","checkbox","input","Boolean","rows","fieldsSchema","Array","isArray","console","log","forEach","row","inputConfigs","findInputs","config","warn","defaultProps","inputValue","defaultValue","total","props","push","validity","key","f","field","data","options","FormData","formData_1","exclude","include","set","delete","data_1","_this","URLSearchParams","setFields","HTMLInputElement","HTMLTextAreaElement","HTMLSelectElement","setCustomValidity","validityKey","findValidityKey","validateInput","required","undefined","inputValidator","validatorKey","handlers","GValidator_1","_validateInput","updateInput","fallback","some","validatorHandler","index","result","test","String","checked","baseValidator","baseHandlers","concat","GValidator","message","__addConstraintValidationHandler","handler","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__","call"],"sourceRoot":""}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "gform-react",
3
+ "version": "1.0.0",
4
+ "description": "A generic form builder for react-based applications",
5
+ "author": "Tal Maman, Arkady Birko",
6
+ "license": "MIT",
7
+ "scripts": {
8
+ "dev": "webpack serve --env development --config webpack.dev.js --open",
9
+ "debug": "webpack serve --env development --env debug --config webpack.dev.js --open",
10
+ "strict": "webpack serve --env development --env debug --env strict --config webpack.dev.js --open",
11
+ "build": "webpack --config webpack.prod.js",
12
+ "build:prod": "npm run tscheck && npm run lint && npm run security:check && npm run build",
13
+ "tscheck": "tsc --noEmit",
14
+ "security:check": "npm audit --production --audit-level high",
15
+ "lint": "eslint src --ext .ts --ext .tsx",
16
+ "lint:fix": "eslint src --ext .ts --ext .tsx --fix",
17
+ "test": "echo \"Error: no test specified\" && exit 1"
18
+ },
19
+ "main": "dist/index.js",
20
+ "typings": "dist/index.d.ts",
21
+ "files": [
22
+ "dist/"
23
+ ],
24
+ "peerDependencies": {
25
+ "react": ">=16.7.0",
26
+ "react-dom": ">=16.7.0"
27
+ },
28
+ "devDependencies": {
29
+ "webpack": "5.75.0",
30
+ "webpack-bundle-analyzer": "^4.7.0",
31
+ "webpack-cli": "5.0.1",
32
+ "webpack-dev-server": "4.11.1",
33
+ "webpack-merge": "5.8.0",
34
+ "style-loader": "3.3.1",
35
+ "babel-loader": "9.1.2",
36
+ "css-loader": "6.7.3",
37
+ "ts-loader": "9.4.2",
38
+ "html-webpack-plugin": "5.5.0",
39
+ "terser-webpack-plugin": "5.3.1",
40
+ "@babel/core": "7.20.12",
41
+ "@babel/preset-env": "7.20.2",
42
+ "@babel/preset-react": "7.18.6",
43
+ "@babel/preset-typescript": "7.18.6",
44
+ "typescript": "4.9.5",
45
+ "@types/react": "18.0.26",
46
+ "@types/react-dom": "18.0.10",
47
+ "@typescript-eslint/eslint-plugin": "^5.18.0",
48
+ "@typescript-eslint/parser": "^5.18.0",
49
+ "eslint": "^8.12.0",
50
+ "primeicons": "^6.0.1",
51
+ "primereact": "^8.7.3",
52
+ "@mui/material": "^5.10.2",
53
+ "@emotion/react": "^11.10.0",
54
+ "@emotion/styled": "^11.10.0"
55
+ }
56
+ }