@flowerforce/flower-react 3.5.1-beta.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,19 +408,19 @@ 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(!hidden && 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));
417
- const errors = useSelector(makeSelectFieldError(flowName, id, hidden ? [] : validate), flowerCore.CoreUtils.allEqual);
417
+ const errors = useSelector(makeSelectFieldError(flowName, id, validate), flowerCore.CoreUtils.allEqual);
418
418
  const dirty = useSelector(makeSelectNodeFieldDirty(flowName, currentNode, id));
419
419
  const touched = useSelector(makeSelectNodeFieldTouched(flowName, currentNode, id));
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',
@@ -488,7 +488,7 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
488
488
  refValue.current = value;
489
489
  const hasValue = !flowerCore.MatchRules.utils.isEmpty(value);
490
490
  if (!hasValue) {
491
- setCustomAsyncErrors([asyncInitialError]);
491
+ setCustomAsyncErrors(asyncInitialError && [asyncInitialError]);
492
492
  setIsValidating(false);
493
493
  return;
494
494
  }
@@ -541,6 +541,24 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
541
541
  });
542
542
  };
543
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]);
544
562
  React.useEffect(() => {
545
563
  if (defaultValue && !dirty && !isEqual(value, defaultValue)) {
546
564
  onChange(defaultValue);
@@ -586,11 +604,11 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
586
604
  }
587
605
  return Component && React.createElement(Component, { ...newProps });
588
606
  }
589
- 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 }) => {
590
608
  const { flowName: flowNameContext, currentNode } = React.useContext(context);
591
609
  const name = flowName || flowNameContext;
592
610
  if (typeof children === 'function') {
593
- 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 }))));
594
612
  }
595
613
  return React.Children.map(children, (child, i) => {
596
614
  if (!React.isValidElement(child)) {
package/dist/index.esm.js CHANGED
@@ -406,19 +406,19 @@ 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(!hidden && 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));
415
- const errors = useSelector(makeSelectFieldError(flowName, id, hidden ? [] : validate), CoreUtils.allEqual);
415
+ const errors = useSelector(makeSelectFieldError(flowName, id, validate), CoreUtils.allEqual);
416
416
  const dirty = useSelector(makeSelectNodeFieldDirty(flowName, currentNode, id));
417
417
  const touched = useSelector(makeSelectNodeFieldTouched(flowName, currentNode, id));
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',
@@ -486,7 +486,7 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
486
486
  refValue.current = value;
487
487
  const hasValue = !MatchRules.utils.isEmpty(value);
488
488
  if (!hasValue) {
489
- setCustomAsyncErrors([asyncInitialError]);
489
+ setCustomAsyncErrors(asyncInitialError && [asyncInitialError]);
490
490
  setIsValidating(false);
491
491
  return;
492
492
  }
@@ -539,6 +539,24 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
539
539
  });
540
540
  };
541
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]);
542
560
  useEffect(() => {
543
561
  if (defaultValue && !dirty && !isEqual(value, defaultValue)) {
544
562
  onChange(defaultValue);
@@ -584,11 +602,11 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
584
602
  }
585
603
  return Component && React.createElement(Component, { ...newProps });
586
604
  }
587
- 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 }) => {
588
606
  const { flowName: flowNameContext, currentNode } = useContext(context);
589
607
  const name = flowName || flowNameContext;
590
608
  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 }))));
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 }))));
592
610
  }
593
611
  return React.Children.map(children, (child, i) => {
594
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.1-beta.0",
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.1-beta.0",
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",