@flowerforce/flower-react 3.4.0 → 3.4.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
@@ -252,6 +252,7 @@ const FlowerClient = ({ children, name, destroyOnUnmount = true, startId = null,
252
252
  wsDevtools,
253
253
  isInitialized
254
254
  ]);
255
+ const currentNodeId = prevFlowerNodeId || current;
255
256
  const contextValues = React.useMemo(() => ({
256
257
  flowName,
257
258
  initialData,
@@ -260,11 +261,11 @@ const FlowerClient = ({ children, name, destroyOnUnmount = true, startId = null,
260
261
  const prevContextValues = React.useMemo(() => ({
261
262
  flowName,
262
263
  initialData,
263
- currentNode: prevFlowerNodeId
264
- }), [flowName, initialData, prevFlowerNodeId]);
264
+ currentNode: currentNodeId
265
+ }), [flowName, initialData, currentNodeId]);
265
266
  return isInitialized ? (React.createElement(React.Fragment, null,
266
- prevFlowerNodeId !== current && typeof prevFlowerNodeId === 'string' && (React.createElement(Provider, { value: prevContextValues }, nodeById[prevFlowerNodeId])),
267
- React.createElement(Provider, { value: contextValues }, !isDisabled && nodeById[current]))) : null;
267
+ React.createElement(Provider, { value: prevContextValues }, nodeById[currentNodeId]),
268
+ React.createElement(Provider, { value: contextValues }, !isDisabled && current !== currentNodeId && nodeById[current]))) : null;
268
269
  };
269
270
  const component$c = React.memo(FlowerClient);
270
271
 
@@ -406,7 +407,7 @@ function isIntrinsicElement$1(x) {
406
407
  return typeof x === 'string';
407
408
  }
408
409
  //TODO make types for wrapper function props
409
- function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDebounce = 0, asyncValidate, asyncInitialError, asyncWaitingError, destroyValue, onBlur = (val) => null, hidden, onUpdate, defaultValue, ...props }) {
410
+ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDebounce = 0, asyncValidate, asyncInitialError, asyncWaitingError, destroyValue, onBlur, hidden, onUpdate, defaultValue, ...props }) {
410
411
  const dispatch = useDispatch();
411
412
  const [customAsyncErrors, setCustomAsyncErrors] = React.useState(asyncValidate && [asyncInitialError]);
412
413
  const [isValidating, setIsValidating] = React.useState(undefined);
@@ -455,7 +456,7 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
455
456
  dirty: defaultValue ? !isEqual(val, defaultValue) : true
456
457
  }
457
458
  });
458
- }, [flowNameFromPath, id, onBlur, dispatch, setCustomAsyncErrors, asyncValidate, asyncWaitingError]);
459
+ }, [flowNameFromPath, id, dispatch, setCustomAsyncErrors, asyncValidate, asyncWaitingError]);
459
460
  const onBlurInternal = React.useCallback((e) => {
460
461
  setTouched(true);
461
462
  onBlur && onBlur(e);
@@ -667,7 +668,8 @@ const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart, PAYLA
667
668
  const useFlower = ({ flowName: customFlowName, name } = {}) => {
668
669
  const dispatch = useDispatch();
669
670
  const { flowName: flowNameDefault, initialData } = React.useContext(context);
670
- const flowName = customFlowName || name || flowNameDefault;
671
+ const store = useStore();
672
+ const flowName = (customFlowName || name || flowNameDefault);
671
673
  const nodeId = useSelector(makeSelectCurrentNodeId(flowName ?? ''));
672
674
  const startId = useSelector(makeSelectStartNodeId(flowName ?? ''));
673
675
  const emitNavigateEvent = React.useCallback(
@@ -720,9 +722,17 @@ const useFlower = ({ flowName: customFlowName, name } = {}) => {
720
722
  dispatch({ type: `flower/${type}`, payload });
721
723
  emitNavigateEvent({ type, payload });
722
724
  }, [dispatch, emitNavigateEvent, flowName]);
725
+ const getCurrentNodeId = React.useCallback((customFlowName) => {
726
+ return _get(store.getState(), [
727
+ 'flower',
728
+ customFlowName || flowName,
729
+ 'current'
730
+ ]);
731
+ }, [store, flowName]);
723
732
  return {
724
733
  flowName,
725
734
  nodeId,
735
+ getCurrentNodeId,
726
736
  startId,
727
737
  next,
728
738
  jump,
package/dist/index.esm.js CHANGED
@@ -250,6 +250,7 @@ const FlowerClient = ({ children, name, destroyOnUnmount = true, startId = null,
250
250
  wsDevtools,
251
251
  isInitialized
252
252
  ]);
253
+ const currentNodeId = prevFlowerNodeId || current;
253
254
  const contextValues = useMemo(() => ({
254
255
  flowName,
255
256
  initialData,
@@ -258,11 +259,11 @@ const FlowerClient = ({ children, name, destroyOnUnmount = true, startId = null,
258
259
  const prevContextValues = useMemo(() => ({
259
260
  flowName,
260
261
  initialData,
261
- currentNode: prevFlowerNodeId
262
- }), [flowName, initialData, prevFlowerNodeId]);
262
+ currentNode: currentNodeId
263
+ }), [flowName, initialData, currentNodeId]);
263
264
  return isInitialized ? (React.createElement(React.Fragment, null,
264
- prevFlowerNodeId !== current && typeof prevFlowerNodeId === 'string' && (React.createElement(Provider, { value: prevContextValues }, nodeById[prevFlowerNodeId])),
265
- React.createElement(Provider, { value: contextValues }, !isDisabled && nodeById[current]))) : null;
265
+ React.createElement(Provider, { value: prevContextValues }, nodeById[currentNodeId]),
266
+ React.createElement(Provider, { value: contextValues }, !isDisabled && current !== currentNodeId && nodeById[current]))) : null;
266
267
  };
267
268
  const component$c = memo(FlowerClient);
268
269
 
@@ -404,7 +405,7 @@ function isIntrinsicElement$1(x) {
404
405
  return typeof x === 'string';
405
406
  }
406
407
  //TODO make types for wrapper function props
407
- function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDebounce = 0, asyncValidate, asyncInitialError, asyncWaitingError, destroyValue, onBlur = (val) => null, hidden, onUpdate, defaultValue, ...props }) {
408
+ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDebounce = 0, asyncValidate, asyncInitialError, asyncWaitingError, destroyValue, onBlur, hidden, onUpdate, defaultValue, ...props }) {
408
409
  const dispatch = useDispatch();
409
410
  const [customAsyncErrors, setCustomAsyncErrors] = useState(asyncValidate && [asyncInitialError]);
410
411
  const [isValidating, setIsValidating] = useState(undefined);
@@ -453,7 +454,7 @@ function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDeboun
453
454
  dirty: defaultValue ? !isEqual(val, defaultValue) : true
454
455
  }
455
456
  });
456
- }, [flowNameFromPath, id, onBlur, dispatch, setCustomAsyncErrors, asyncValidate, asyncWaitingError]);
457
+ }, [flowNameFromPath, id, dispatch, setCustomAsyncErrors, asyncValidate, asyncWaitingError]);
457
458
  const onBlurInternal = useCallback((e) => {
458
459
  setTouched(true);
459
460
  onBlur && onBlur(e);
@@ -665,7 +666,8 @@ const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart, PAYLA
665
666
  const useFlower = ({ flowName: customFlowName, name } = {}) => {
666
667
  const dispatch = useDispatch();
667
668
  const { flowName: flowNameDefault, initialData } = useContext(context);
668
- const flowName = customFlowName || name || flowNameDefault;
669
+ const store = useStore();
670
+ const flowName = (customFlowName || name || flowNameDefault);
669
671
  const nodeId = useSelector(makeSelectCurrentNodeId(flowName ?? ''));
670
672
  const startId = useSelector(makeSelectStartNodeId(flowName ?? ''));
671
673
  const emitNavigateEvent = useCallback(
@@ -718,9 +720,17 @@ const useFlower = ({ flowName: customFlowName, name } = {}) => {
718
720
  dispatch({ type: `flower/${type}`, payload });
719
721
  emitNavigateEvent({ type, payload });
720
722
  }, [dispatch, emitNavigateEvent, flowName]);
723
+ const getCurrentNodeId = useCallback((customFlowName) => {
724
+ return _get(store.getState(), [
725
+ 'flower',
726
+ customFlowName || flowName,
727
+ 'current'
728
+ ]);
729
+ }, [store, flowName]);
721
730
  return {
722
731
  flowName,
723
732
  nodeId,
733
+ getCurrentNodeId,
724
734
  startId,
725
735
  next,
726
736
  jump,
@@ -55,6 +55,8 @@ type useFlowerActions = {
55
55
  jump: (payload: RouteNode) => void;
56
56
  /**Use this function to reset the flow data and history */
57
57
  restart: (payload?: RouteRestart) => void;
58
+ /**Get current node by flowName or current flow */
59
+ getCurrentNodeId: (flowName?: string) => void;
58
60
  };
59
61
  export type UseFlower = (options?: UseFlowerProps) => useFlowerActions & {
60
62
  /**The flow in which the hook is used.*/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flower-react",
3
- "version": "3.4.0",
3
+ "version": "3.4.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.2.2",
37
+ "@flowerforce/flower-core": "3.2.3-beta.5",
38
38
  "@reduxjs/toolkit": "^2.2.4",
39
39
  "lodash": "^4.17.21",
40
40
  "react-redux": "^9.1.2",