@maif/react-forms 1.1.2 → 1.1.3
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/lib/esm/index.js +15 -10
- package/lib/index.d.ts +16 -13
- package/lib/index.js +14 -8
- package/package.json +3 -1
package/lib/esm/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as yup from 'yup';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import React__default, { useState, useRef, useEffect, useImperativeHandle } from 'react';
|
|
3
|
+
import React__default, { useState, useRef, useEffect, useCallback, useImperativeHandle } from 'react';
|
|
4
4
|
import { yupResolver } from '@hookform/resolvers/yup';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
6
|
import deepEqual from 'fast-deep-equal';
|
|
7
7
|
import { Eye, EyeOff, PlusCircle, MinusCircle, Trash2, ChevronDown, ChevronUp, HelpCircle, Loader, Upload } from 'react-feather';
|
|
8
|
-
import { useFormContext, useController, useForm, FormProvider, Controller, useFieldArray
|
|
8
|
+
import { useFormContext, useController, useWatch, useForm, FormProvider, Controller, useFieldArray } from 'react-hook-form';
|
|
9
9
|
import { DatePicker } from 'react-rainbow-components';
|
|
10
10
|
import ReactToolTip from 'react-tooltip';
|
|
11
11
|
import { v4 } from 'uuid';
|
|
12
|
+
import debounce from 'lodash.debounce';
|
|
12
13
|
import CreatableSelect from 'react-select/creatable';
|
|
13
14
|
import Select from 'react-select';
|
|
14
15
|
import hash$1 from 'object-hash';
|
|
@@ -278,7 +279,7 @@ const useHashEffect = (func, deps) => {
|
|
|
278
279
|
const depsHash = cleanHash(deps);
|
|
279
280
|
const prevDepsHash = cleanHash(prevDeps.current);
|
|
280
281
|
if (depsHash !== prevDepsHash) {
|
|
281
|
-
prevDeps.current = deps;
|
|
282
|
+
prevDeps.current = Object.assign({}, deps);
|
|
282
283
|
func();
|
|
283
284
|
}
|
|
284
285
|
}, deps); /* FIXME deps or [deps] ? */
|
|
@@ -28107,16 +28108,18 @@ const validate = (flow, schema, value) => {
|
|
|
28107
28108
|
abortEarly: false
|
|
28108
28109
|
});
|
|
28109
28110
|
};
|
|
28110
|
-
const Watcher = ({ options, control, schema, onSubmit, handleSubmit }) => {
|
|
28111
|
+
const Watcher = React__default.memo(({ options, control, schema, onSubmit, handleSubmit }) => {
|
|
28111
28112
|
const data = useWatch({ control });
|
|
28113
|
+
const realSubmit = (d) => handleSubmit(() => {
|
|
28114
|
+
onSubmit(d);
|
|
28115
|
+
})();
|
|
28116
|
+
const debouncedSubmit = useCallback(debounce(realSubmit, 250, { leading: true }), []);
|
|
28112
28117
|
useHashEffect(() => {
|
|
28113
|
-
if (options.autosubmit) {
|
|
28114
|
-
|
|
28115
|
-
onSubmit(cleanOutputArray(data, schema));
|
|
28116
|
-
})();
|
|
28118
|
+
if (options === null || options === void 0 ? void 0 : options.autosubmit) {
|
|
28119
|
+
debouncedSubmit(data);
|
|
28117
28120
|
}
|
|
28118
28121
|
}, [data]);
|
|
28119
|
-
if (options.watch) {
|
|
28122
|
+
if (options === null || options === void 0 ? void 0 : options.watch) {
|
|
28120
28123
|
if (typeof options.watch === 'function') {
|
|
28121
28124
|
options.watch(cleanOutputArray(data, schema));
|
|
28122
28125
|
}
|
|
@@ -28127,7 +28130,9 @@ const Watcher = ({ options, control, schema, onSubmit, handleSubmit }) => {
|
|
|
28127
28130
|
}
|
|
28128
28131
|
}
|
|
28129
28132
|
return null;
|
|
28130
|
-
}
|
|
28133
|
+
}, () => {
|
|
28134
|
+
return true;
|
|
28135
|
+
});
|
|
28131
28136
|
const Form = React__default.forwardRef(function Form({ schema, flow, value, inputWrapper, onSubmit, onError = () => { }, footer, style = {}, className, options = {}, nostyle }, ref) {
|
|
28132
28137
|
const formFlow = flow || Object.keys(schema);
|
|
28133
28138
|
const maybeCustomHttpClient = (url, method) => {
|
package/lib/index.d.ts
CHANGED
|
@@ -138,7 +138,7 @@ declare type SelectOption = {
|
|
|
138
138
|
declare const SelectInput: <T extends {
|
|
139
139
|
[x: string]: any;
|
|
140
140
|
}>(props: {
|
|
141
|
-
possibleValues
|
|
141
|
+
possibleValues?: T[] | undefined;
|
|
142
142
|
transformer?: {
|
|
143
143
|
label: string;
|
|
144
144
|
value: string;
|
|
@@ -146,10 +146,10 @@ declare const SelectInput: <T extends {
|
|
|
146
146
|
value?: any;
|
|
147
147
|
defaultValue?: any;
|
|
148
148
|
isMulti?: boolean | undefined;
|
|
149
|
-
optionsFrom
|
|
149
|
+
optionsFrom?: string | Promise<T[]> | ((param: {
|
|
150
150
|
rawValues: object;
|
|
151
151
|
value: any;
|
|
152
|
-
}) => string | Promise<T[]>);
|
|
152
|
+
}) => string | Promise<T[]>) | undefined;
|
|
153
153
|
fetchCondition?: (() => boolean) | undefined;
|
|
154
154
|
id?: string | undefined;
|
|
155
155
|
httpClient?: ((url: string, method: string) => Promise<Response>) | undefined;
|
|
@@ -302,24 +302,24 @@ interface SchemaEntry {
|
|
|
302
302
|
className?: string;
|
|
303
303
|
style?: object;
|
|
304
304
|
onChange?: (param: object) => void;
|
|
305
|
-
render
|
|
305
|
+
render?: SchemaRenderType;
|
|
306
306
|
itemRender?: SchemaRenderType;
|
|
307
|
-
props
|
|
308
|
-
options
|
|
307
|
+
props?: object;
|
|
308
|
+
options?: Array<any | {
|
|
309
309
|
label: string;
|
|
310
310
|
value: any;
|
|
311
311
|
}>;
|
|
312
|
-
optionsFrom
|
|
313
|
-
transformer
|
|
312
|
+
optionsFrom?: string;
|
|
313
|
+
transformer?: ((v: any) => SelectOption) | {
|
|
314
314
|
label: string;
|
|
315
315
|
value: string;
|
|
316
316
|
};
|
|
317
|
-
conditionalSchema
|
|
318
|
-
constraints
|
|
317
|
+
conditionalSchema?: ConditionnalSchema;
|
|
318
|
+
constraints?: Array<Constraint | {
|
|
319
319
|
type: TConstraintType;
|
|
320
320
|
message?: string;
|
|
321
321
|
}>;
|
|
322
|
-
flow
|
|
322
|
+
flow?: Array<string | FlowObject>;
|
|
323
323
|
onAfterChange?: (obj: {
|
|
324
324
|
entry: string;
|
|
325
325
|
value: object;
|
|
@@ -331,7 +331,7 @@ interface SchemaEntry {
|
|
|
331
331
|
informations?: Informations;
|
|
332
332
|
}) => void;
|
|
333
333
|
visibleOnCollapse?: boolean;
|
|
334
|
-
addableDefaultValue
|
|
334
|
+
addableDefaultValue?: any;
|
|
335
335
|
collapsed?: boolean;
|
|
336
336
|
collapsable?: boolean;
|
|
337
337
|
}
|
|
@@ -354,7 +354,10 @@ declare const Form: React.ForwardRefExoticComponent<{
|
|
|
354
354
|
inputWrapper?: ((props: object) => JSX.Element) | undefined;
|
|
355
355
|
onSubmit: (obj: object) => void;
|
|
356
356
|
onError?: (() => void) | undefined;
|
|
357
|
-
footer?: ((props:
|
|
357
|
+
footer?: ((props: {
|
|
358
|
+
reset: () => void;
|
|
359
|
+
valid: () => void;
|
|
360
|
+
}) => JSX.Element) | undefined;
|
|
358
361
|
style?: object | undefined;
|
|
359
362
|
className?: string | undefined;
|
|
360
363
|
options?: Option | undefined;
|
package/lib/index.js
CHANGED
|
@@ -12,6 +12,7 @@ var reactHookForm = require('react-hook-form');
|
|
|
12
12
|
var reactRainbowComponents = require('react-rainbow-components');
|
|
13
13
|
var ReactToolTip = require('react-tooltip');
|
|
14
14
|
var uuid$1 = require('uuid');
|
|
15
|
+
var debounce = require('lodash.debounce');
|
|
15
16
|
var CreatableSelect = require('react-select/creatable');
|
|
16
17
|
var Select = require('react-select');
|
|
17
18
|
var hash$1 = require('object-hash');
|
|
@@ -46,6 +47,7 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
46
47
|
var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
|
|
47
48
|
var deepEqual__default = /*#__PURE__*/_interopDefaultLegacy(deepEqual);
|
|
48
49
|
var ReactToolTip__default = /*#__PURE__*/_interopDefaultLegacy(ReactToolTip);
|
|
50
|
+
var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
|
|
49
51
|
var CreatableSelect__default = /*#__PURE__*/_interopDefaultLegacy(CreatableSelect);
|
|
50
52
|
var Select__default = /*#__PURE__*/_interopDefaultLegacy(Select);
|
|
51
53
|
var hash__default = /*#__PURE__*/_interopDefaultLegacy(hash$1);
|
|
@@ -313,7 +315,7 @@ const useHashEffect = (func, deps) => {
|
|
|
313
315
|
const depsHash = cleanHash(deps);
|
|
314
316
|
const prevDepsHash = cleanHash(prevDeps.current);
|
|
315
317
|
if (depsHash !== prevDepsHash) {
|
|
316
|
-
prevDeps.current = deps;
|
|
318
|
+
prevDeps.current = Object.assign({}, deps);
|
|
317
319
|
func();
|
|
318
320
|
}
|
|
319
321
|
}, deps); /* FIXME deps or [deps] ? */
|
|
@@ -28142,16 +28144,18 @@ const validate = (flow, schema, value) => {
|
|
|
28142
28144
|
abortEarly: false
|
|
28143
28145
|
});
|
|
28144
28146
|
};
|
|
28145
|
-
const Watcher = ({ options, control, schema, onSubmit, handleSubmit }) => {
|
|
28147
|
+
const Watcher = React__default["default"].memo(({ options, control, schema, onSubmit, handleSubmit }) => {
|
|
28146
28148
|
const data = reactHookForm.useWatch({ control });
|
|
28149
|
+
const realSubmit = (d) => handleSubmit(() => {
|
|
28150
|
+
onSubmit(d);
|
|
28151
|
+
})();
|
|
28152
|
+
const debouncedSubmit = React.useCallback(debounce__default["default"](realSubmit, 250, { leading: true }), []);
|
|
28147
28153
|
useHashEffect(() => {
|
|
28148
|
-
if (options.autosubmit) {
|
|
28149
|
-
|
|
28150
|
-
onSubmit(cleanOutputArray(data, schema));
|
|
28151
|
-
})();
|
|
28154
|
+
if (options === null || options === void 0 ? void 0 : options.autosubmit) {
|
|
28155
|
+
debouncedSubmit(data);
|
|
28152
28156
|
}
|
|
28153
28157
|
}, [data]);
|
|
28154
|
-
if (options.watch) {
|
|
28158
|
+
if (options === null || options === void 0 ? void 0 : options.watch) {
|
|
28155
28159
|
if (typeof options.watch === 'function') {
|
|
28156
28160
|
options.watch(cleanOutputArray(data, schema));
|
|
28157
28161
|
}
|
|
@@ -28162,7 +28166,9 @@ const Watcher = ({ options, control, schema, onSubmit, handleSubmit }) => {
|
|
|
28162
28166
|
}
|
|
28163
28167
|
}
|
|
28164
28168
|
return null;
|
|
28165
|
-
}
|
|
28169
|
+
}, () => {
|
|
28170
|
+
return true;
|
|
28171
|
+
});
|
|
28166
28172
|
const Form = React__default["default"].forwardRef(function Form({ schema, flow, value, inputWrapper, onSubmit, onError = () => { }, footer, style = {}, className, options = {}, nostyle }, ref) {
|
|
28167
28173
|
const formFlow = flow || Object.keys(schema);
|
|
28168
28174
|
const maybeCustomHttpClient = (url, method) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maif/react-forms",
|
|
3
3
|
"description": "Build react safe forms as fast as possible",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.3",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"@testing-library/react": "^11.1.0",
|
|
73
73
|
"@testing-library/user-event": "^12.1.10",
|
|
74
74
|
"@types/jest": "^26.0.24",
|
|
75
|
+
"@types/lodash.debounce": "4.0.7",
|
|
75
76
|
"@types/node": "^16.3.0",
|
|
76
77
|
"@types/react": "^17.0.14",
|
|
77
78
|
"@types/react-dom": "^17.0.9",
|
|
@@ -118,6 +119,7 @@
|
|
|
118
119
|
"classnames": "2.3.0",
|
|
119
120
|
"fast-deep-equal": "^3.1.3",
|
|
120
121
|
"highlight.js": "^11.5.1",
|
|
122
|
+
"lodash.debounce": "4.0.8",
|
|
121
123
|
"moment": "2.29.1",
|
|
122
124
|
"object-hash": "3.0.0",
|
|
123
125
|
"react-feather": "2.0.9",
|