@flowerforce/flower-react 3.5.0 → 3.5.1-beta.1
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/dist/index.cjs.js
CHANGED
@@ -408,9 +408,9 @@ function isIntrinsicElement$1(x) {
|
|
408
408
|
return typeof x === 'string';
|
409
409
|
}
|
410
410
|
//TODO make types for wrapper function props
|
411
|
-
function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDebounce = 0, asyncValidate, asyncInitialError, asyncWaitingError, destroyValue, onBlur, onFocus, hidden, onUpdate, defaultValue, ...props }) {
|
411
|
+
function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDebounce = 0, asyncValidate, asyncInitialError, asyncWaitingError, destroyValue, destroyOnHide, onBlur, onFocus, hidden, onUpdate, defaultValue, ...props }) {
|
412
412
|
const dispatch = useDispatch();
|
413
|
-
const [customAsyncErrors, setCustomAsyncErrors] = React.useState(asyncValidate && [asyncInitialError]);
|
413
|
+
const [customAsyncErrors, setCustomAsyncErrors] = React.useState(asyncValidate && asyncInitialError && [asyncInitialError]);
|
414
414
|
const [isValidating, setIsValidating] = React.useState(undefined);
|
415
415
|
const { flowNameFromPath = flowName, path } = React.useMemo(() => flowerCore.CoreUtils.getPath(id), [id]);
|
416
416
|
const value = useSelector(getDataFromState(flowNameFromPath, path));
|
@@ -420,7 +420,7 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
|
|
420
420
|
const focused = useSelector(makeSelectNodeFieldFocused(flowName, currentNode, id));
|
421
421
|
const refValue = React.useRef();
|
422
422
|
const isSubmitted = useSelector(makeSelectNodeFormSubmitted(flowName, currentNode));
|
423
|
-
const allErrors = React.useMemo(() => [...errors, ...(customAsyncErrors || []).filter(Boolean)], [errors, customAsyncErrors]);
|
423
|
+
const allErrors = React.useMemo(() => hidden ? [] : [...errors, ...(customAsyncErrors || []).filter(Boolean)], [errors, hidden, customAsyncErrors]);
|
424
424
|
const setTouched = React.useCallback((touched) => {
|
425
425
|
dispatch({
|
426
426
|
type: 'flower/formFieldTouch',
|
@@ -480,20 +480,22 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
|
|
480
480
|
onFocus && onFocus(e);
|
481
481
|
}, [onFocus, setFocus]);
|
482
482
|
React.useEffect(() => {
|
483
|
+
if (hidden)
|
484
|
+
return;
|
483
485
|
if (asyncValidate) {
|
484
486
|
if (refValue.current === value)
|
485
487
|
return;
|
486
488
|
refValue.current = value;
|
487
489
|
const hasValue = !flowerCore.MatchRules.utils.isEmpty(value);
|
488
490
|
if (!hasValue) {
|
489
|
-
setCustomAsyncErrors([asyncInitialError]);
|
491
|
+
setCustomAsyncErrors(asyncInitialError && [asyncInitialError]);
|
490
492
|
setIsValidating(false);
|
491
493
|
return;
|
492
494
|
}
|
493
495
|
setTouched(true);
|
494
496
|
debouncedValidation(value);
|
495
497
|
}
|
496
|
-
}, [asyncValidate, asyncInitialError, value, debouncedValidation, setTouched]);
|
498
|
+
}, [asyncValidate, asyncInitialError, value, debouncedValidation, setTouched, hidden]);
|
497
499
|
React.useEffect(() => {
|
498
500
|
if (onUpdate) {
|
499
501
|
onUpdate(value);
|
@@ -539,6 +541,24 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
|
|
539
541
|
});
|
540
542
|
};
|
541
543
|
}, [destroyValue, id, flowNameFromPath, path, currentNode]);
|
544
|
+
React.useEffect(() => {
|
545
|
+
if (hidden) {
|
546
|
+
if (destroyOnHide) {
|
547
|
+
dispatch({
|
548
|
+
type: `flower/unsetData`,
|
549
|
+
payload: { flowName: flowNameFromPath, id: path }
|
550
|
+
});
|
551
|
+
}
|
552
|
+
dispatch({
|
553
|
+
type: 'flower/formRemoveErrors',
|
554
|
+
payload: {
|
555
|
+
name: flowName,
|
556
|
+
id,
|
557
|
+
currentNode
|
558
|
+
}
|
559
|
+
});
|
560
|
+
}
|
561
|
+
}, [destroyOnHide, hidden, id, flowNameFromPath, path, currentNode]);
|
542
562
|
React.useEffect(() => {
|
543
563
|
if (defaultValue && !dirty && !isEqual(value, defaultValue)) {
|
544
564
|
onChange(defaultValue);
|
@@ -584,11 +604,11 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
|
|
584
604
|
}
|
585
605
|
return Component && React.createElement(Component, { ...newProps });
|
586
606
|
}
|
587
|
-
const FlowerField = ({ id, validate, asyncValidate, asyncDebounce, asyncInitialError, asyncWaitingError, rules, alwaysDisplay, value, children, defaultValue, destroyValue, flowName, onUpdate }) => {
|
607
|
+
const FlowerField = ({ id, validate, asyncValidate, asyncDebounce, asyncInitialError, asyncWaitingError, rules, alwaysDisplay, value, children, defaultValue, destroyOnHide, destroyValue, flowName, onUpdate }) => {
|
588
608
|
const { flowName: flowNameContext, currentNode } = React.useContext(context);
|
589
609
|
const name = flowName || flowNameContext;
|
590
610
|
if (typeof children === 'function') {
|
591
|
-
return (React.createElement(component$5, { alwaysDisplay: alwaysDisplay, rules: rules, value: value, flowName: name, id: id }, ({ hidden }) => (React.createElement(Wrapper$1, { hidden: hidden, id: id, Component: children, flowName: name, currentNode: currentNode, validate: validate, asyncValidate: asyncValidate, asyncDebounce: asyncDebounce, asyncInitialError: asyncInitialError, asyncWaitingError: asyncWaitingError, destroyValue: destroyValue, onUpdate: onUpdate, defaultValue: defaultValue }))));
|
611
|
+
return (React.createElement(component$5, { alwaysDisplay: alwaysDisplay, rules: rules, value: value, flowName: name, id: id }, ({ hidden }) => (React.createElement(Wrapper$1, { hidden: hidden, id: id, Component: children, flowName: name, currentNode: currentNode, validate: validate, asyncValidate: asyncValidate, asyncDebounce: asyncDebounce, asyncInitialError: asyncInitialError, asyncWaitingError: asyncWaitingError, destroyValue: destroyValue, onUpdate: onUpdate, defaultValue: defaultValue, destroyOnHide: destroyOnHide }))));
|
592
612
|
}
|
593
613
|
return React.Children.map(children, (child, i) => {
|
594
614
|
if (!React.isValidElement(child)) {
|
package/dist/index.esm.js
CHANGED
@@ -406,9 +406,9 @@ function isIntrinsicElement$1(x) {
|
|
406
406
|
return typeof x === 'string';
|
407
407
|
}
|
408
408
|
//TODO make types for wrapper function props
|
409
|
-
function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDebounce = 0, asyncValidate, asyncInitialError, asyncWaitingError, destroyValue, onBlur, onFocus, hidden, onUpdate, defaultValue, ...props }) {
|
409
|
+
function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDebounce = 0, asyncValidate, asyncInitialError, asyncWaitingError, destroyValue, destroyOnHide, onBlur, onFocus, hidden, onUpdate, defaultValue, ...props }) {
|
410
410
|
const dispatch = useDispatch();
|
411
|
-
const [customAsyncErrors, setCustomAsyncErrors] = useState(asyncValidate && [asyncInitialError]);
|
411
|
+
const [customAsyncErrors, setCustomAsyncErrors] = useState(asyncValidate && asyncInitialError && [asyncInitialError]);
|
412
412
|
const [isValidating, setIsValidating] = useState(undefined);
|
413
413
|
const { flowNameFromPath = flowName, path } = useMemo(() => CoreUtils.getPath(id), [id]);
|
414
414
|
const value = useSelector(getDataFromState(flowNameFromPath, path));
|
@@ -418,7 +418,7 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
|
|
418
418
|
const focused = useSelector(makeSelectNodeFieldFocused(flowName, currentNode, id));
|
419
419
|
const refValue = useRef();
|
420
420
|
const isSubmitted = useSelector(makeSelectNodeFormSubmitted(flowName, currentNode));
|
421
|
-
const allErrors = useMemo(() => [...errors, ...(customAsyncErrors || []).filter(Boolean)], [errors, customAsyncErrors]);
|
421
|
+
const allErrors = useMemo(() => hidden ? [] : [...errors, ...(customAsyncErrors || []).filter(Boolean)], [errors, hidden, customAsyncErrors]);
|
422
422
|
const setTouched = useCallback((touched) => {
|
423
423
|
dispatch({
|
424
424
|
type: 'flower/formFieldTouch',
|
@@ -478,20 +478,22 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
|
|
478
478
|
onFocus && onFocus(e);
|
479
479
|
}, [onFocus, setFocus]);
|
480
480
|
useEffect(() => {
|
481
|
+
if (hidden)
|
482
|
+
return;
|
481
483
|
if (asyncValidate) {
|
482
484
|
if (refValue.current === value)
|
483
485
|
return;
|
484
486
|
refValue.current = value;
|
485
487
|
const hasValue = !MatchRules.utils.isEmpty(value);
|
486
488
|
if (!hasValue) {
|
487
|
-
setCustomAsyncErrors([asyncInitialError]);
|
489
|
+
setCustomAsyncErrors(asyncInitialError && [asyncInitialError]);
|
488
490
|
setIsValidating(false);
|
489
491
|
return;
|
490
492
|
}
|
491
493
|
setTouched(true);
|
492
494
|
debouncedValidation(value);
|
493
495
|
}
|
494
|
-
}, [asyncValidate, asyncInitialError, value, debouncedValidation, setTouched]);
|
496
|
+
}, [asyncValidate, asyncInitialError, value, debouncedValidation, setTouched, hidden]);
|
495
497
|
useEffect(() => {
|
496
498
|
if (onUpdate) {
|
497
499
|
onUpdate(value);
|
@@ -537,6 +539,24 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
|
|
537
539
|
});
|
538
540
|
};
|
539
541
|
}, [destroyValue, id, flowNameFromPath, path, currentNode]);
|
542
|
+
useEffect(() => {
|
543
|
+
if (hidden) {
|
544
|
+
if (destroyOnHide) {
|
545
|
+
dispatch({
|
546
|
+
type: `flower/unsetData`,
|
547
|
+
payload: { flowName: flowNameFromPath, id: path }
|
548
|
+
});
|
549
|
+
}
|
550
|
+
dispatch({
|
551
|
+
type: 'flower/formRemoveErrors',
|
552
|
+
payload: {
|
553
|
+
name: flowName,
|
554
|
+
id,
|
555
|
+
currentNode
|
556
|
+
}
|
557
|
+
});
|
558
|
+
}
|
559
|
+
}, [destroyOnHide, hidden, id, flowNameFromPath, path, currentNode]);
|
540
560
|
useEffect(() => {
|
541
561
|
if (defaultValue && !dirty && !isEqual(value, defaultValue)) {
|
542
562
|
onChange(defaultValue);
|
@@ -582,11 +602,11 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
|
|
582
602
|
}
|
583
603
|
return Component && React.createElement(Component, { ...newProps });
|
584
604
|
}
|
585
|
-
const FlowerField = ({ id, validate, asyncValidate, asyncDebounce, asyncInitialError, asyncWaitingError, rules, alwaysDisplay, value, children, defaultValue, destroyValue, flowName, onUpdate }) => {
|
605
|
+
const FlowerField = ({ id, validate, asyncValidate, asyncDebounce, asyncInitialError, asyncWaitingError, rules, alwaysDisplay, value, children, defaultValue, destroyOnHide, destroyValue, flowName, onUpdate }) => {
|
586
606
|
const { flowName: flowNameContext, currentNode } = useContext(context);
|
587
607
|
const name = flowName || flowNameContext;
|
588
608
|
if (typeof children === 'function') {
|
589
|
-
return (React.createElement(component$5, { alwaysDisplay: alwaysDisplay, rules: rules, value: value, flowName: name, id: id }, ({ hidden }) => (React.createElement(Wrapper$1, { hidden: hidden, id: id, Component: children, flowName: name, currentNode: currentNode, validate: validate, asyncValidate: asyncValidate, asyncDebounce: asyncDebounce, asyncInitialError: asyncInitialError, asyncWaitingError: asyncWaitingError, destroyValue: destroyValue, onUpdate: onUpdate, defaultValue: defaultValue }))));
|
609
|
+
return (React.createElement(component$5, { alwaysDisplay: alwaysDisplay, rules: rules, value: value, flowName: name, id: id }, ({ hidden }) => (React.createElement(Wrapper$1, { hidden: hidden, id: id, Component: children, flowName: name, currentNode: currentNode, validate: validate, asyncValidate: asyncValidate, asyncDebounce: asyncDebounce, asyncInitialError: asyncInitialError, asyncWaitingError: asyncWaitingError, destroyValue: destroyValue, onUpdate: onUpdate, defaultValue: defaultValue, destroyOnHide: destroyOnHide }))));
|
590
610
|
}
|
591
611
|
return React.Children.map(children, (child, i) => {
|
592
612
|
if (!React.isValidElement(child)) {
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { FlowerFieldProps } from './types/FlowerField';
|
3
|
-
declare const component: React.MemoExoticComponent<({ id, validate, asyncValidate, asyncDebounce, asyncInitialError, asyncWaitingError, rules, alwaysDisplay, value, children, defaultValue, destroyValue, flowName, onUpdate }: FlowerFieldProps) => React.JSX.Element | (string | number | Iterable<React.ReactNode> | React.JSX.Element)[] | null | undefined>;
|
3
|
+
declare const component: React.MemoExoticComponent<({ id, validate, asyncValidate, asyncDebounce, asyncInitialError, asyncWaitingError, rules, alwaysDisplay, value, children, defaultValue, destroyOnHide, destroyValue, flowName, onUpdate }: FlowerFieldProps) => React.JSX.Element | (string | number | Iterable<React.ReactNode> | React.JSX.Element)[] | null | undefined>;
|
4
4
|
export default component;
|
@@ -99,7 +99,10 @@ export type FlowerFieldProps<T extends Record<string, any> = Record<string, any>
|
|
99
99
|
flowName?: string;
|
100
100
|
/** Initial value field */
|
101
101
|
defaultValue?: unknown;
|
102
|
+
/** Remove value from data on destroy element */
|
102
103
|
destroyValue?: boolean;
|
104
|
+
/** Remove value from data on hide element */
|
105
|
+
destroyOnHide?: boolean;
|
103
106
|
value?: any;
|
104
107
|
/** When set to true, the children is shown even if the rules are not satisfied
|
105
108
|
*
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@flowerforce/flower-react",
|
3
|
-
"version": "3.5.
|
3
|
+
"version": "3.5.1-beta.1",
|
4
4
|
"description": "FlowerJS components, hooks and utils for React.",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -34,7 +34,7 @@
|
|
34
34
|
"typescript": "^5.4.5"
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@flowerforce/flower-core": "3.3.
|
37
|
+
"@flowerforce/flower-core": "3.3.1-beta.1",
|
38
38
|
"@reduxjs/toolkit": "^2.2.4",
|
39
39
|
"lodash": "^4.17.21",
|
40
40
|
"react-redux": "^9.1.2",
|