@flowerforce/flower-react 3.4.1-beta.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:
|
264
|
-
}), [flowName, initialData,
|
264
|
+
currentNode: currentNodeId
|
265
|
+
}), [flowName, initialData, currentNodeId]);
|
265
266
|
return isInitialized ? (React.createElement(React.Fragment, null,
|
266
|
-
|
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
|
|
@@ -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
|
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:
|
262
|
-
}), [flowName, initialData,
|
262
|
+
currentNode: currentNodeId
|
263
|
+
}), [flowName, initialData, currentNodeId]);
|
263
264
|
return isInitialized ? (React.createElement(React.Fragment, null,
|
264
|
-
|
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
|
|
@@ -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
|
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.1-beta.
|
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.3-beta.
|
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",
|