@flowerforce/flower-react 3.0.1-beta.1 → 3.0.1-beta.2
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
@@ -227,8 +227,9 @@ const FlowerClient = ({
|
|
227
227
|
}, [dispatch, flowName, current, isDisabled, store, wsDevtools, isInitialized]);
|
228
228
|
const contextValues = React.useMemo(() => ({
|
229
229
|
flowName,
|
230
|
+
initialData: _initialData,
|
230
231
|
currentNode: current
|
231
|
-
}), [flowName, current]);
|
232
|
+
}), [flowName, _initialData, current]);
|
232
233
|
return isInitialized ? ( /*#__PURE__*/React.createElement(Provider, {
|
233
234
|
value: contextValues
|
234
235
|
}, prevFlowerNodeId !== current && typeof prevFlowerNodeId === 'string' && nodeById[prevFlowerNodeId], !isDisabled && nodeById[current])) : null;
|
@@ -351,29 +352,22 @@ const component$6 = /*#__PURE__*/React.memo(FlowerRoute);
|
|
351
352
|
component$6.displayName = 'FlowerRoute';
|
352
353
|
|
353
354
|
function _extends() {
|
354
|
-
_extends = Object.assign ? Object.assign.bind() : function (
|
355
|
-
for (var
|
356
|
-
var
|
357
|
-
for (var
|
358
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
359
|
-
target[key] = source[key];
|
360
|
-
}
|
361
|
-
}
|
355
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
356
|
+
for (var e = 1; e < arguments.length; e++) {
|
357
|
+
var t = arguments[e];
|
358
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
362
359
|
}
|
363
|
-
return
|
364
|
-
};
|
365
|
-
return _extends.apply(this, arguments);
|
360
|
+
return n;
|
361
|
+
}, _extends.apply(null, arguments);
|
366
362
|
}
|
367
|
-
function _objectWithoutPropertiesLoose(
|
368
|
-
if (
|
369
|
-
var
|
370
|
-
for (var
|
371
|
-
if (
|
372
|
-
|
373
|
-
target[key] = source[key];
|
374
|
-
}
|
363
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
364
|
+
if (null == r) return {};
|
365
|
+
var t = {};
|
366
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
367
|
+
if (e.indexOf(n) >= 0) continue;
|
368
|
+
t[n] = r[n];
|
375
369
|
}
|
376
|
-
return
|
370
|
+
return t;
|
377
371
|
}
|
378
372
|
|
379
373
|
const FlowerRule = ({
|
@@ -789,15 +783,17 @@ component$3.displayName = 'FlowerValue';
|
|
789
783
|
|
790
784
|
const ACTION_TYPES = {
|
791
785
|
back: ['prev', 'prevToNode'],
|
792
|
-
reset: ['reset', 'initializeFromNode'],
|
793
786
|
jump: ['node', 'node'],
|
794
|
-
next: ['next', 'next']
|
787
|
+
next: ['next', 'next'],
|
788
|
+
restart: ['restart', 'restart'],
|
789
|
+
reset: ['reset', 'initializeFromNode']
|
795
790
|
};
|
796
791
|
const PAYLAOAD_KEYS_NEEDED = {
|
797
792
|
back: ['node'],
|
798
|
-
reset: ['node'],
|
799
793
|
jump: ['node', 'history'],
|
800
|
-
next: ['node', 'route', 'data']
|
794
|
+
next: ['node', 'route', 'data'],
|
795
|
+
restart: ['node'],
|
796
|
+
reset: ['node', 'initialData']
|
801
797
|
};
|
802
798
|
const makeActionPayload = (actions, keys) => (flowName, params) => {
|
803
799
|
const rest = typeof params === 'string' ? {
|
@@ -816,13 +812,15 @@ const makeActionPayloadOnPrev = makeActionPayload(ACTION_TYPES.back, PAYLAOAD_KE
|
|
816
812
|
const makeActionPayloadOnReset = makeActionPayload(ACTION_TYPES.reset, PAYLAOAD_KEYS_NEEDED.reset);
|
817
813
|
const makeActionPayloadOnNode = makeActionPayload(ACTION_TYPES.jump, PAYLAOAD_KEYS_NEEDED.jump);
|
818
814
|
const makeActionPayloadOnNext = makeActionPayload(ACTION_TYPES.next, PAYLAOAD_KEYS_NEEDED.next);
|
815
|
+
const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart, PAYLAOAD_KEYS_NEEDED.restart);
|
819
816
|
const useFlower = ({
|
820
817
|
flowName: customFlowName,
|
821
818
|
name
|
822
819
|
} = {}) => {
|
823
820
|
const dispatch = useDispatch();
|
824
821
|
const {
|
825
|
-
flowName: flowNameDefault
|
822
|
+
flowName: flowNameDefault,
|
823
|
+
initialData
|
826
824
|
} = React.useContext(context);
|
827
825
|
const flowName = customFlowName || name || flowNameDefault;
|
828
826
|
const nodeId = useSelector(makeSelectCurrentNodeId(flowName != null ? flowName : ''));
|
@@ -860,11 +858,11 @@ const useFlower = ({
|
|
860
858
|
payload
|
861
859
|
});
|
862
860
|
}, [dispatch, emitNavigateEvent, flowName]);
|
863
|
-
const
|
861
|
+
const restart = React.useCallback(param => {
|
864
862
|
const {
|
865
863
|
type,
|
866
864
|
payload
|
867
|
-
} =
|
865
|
+
} = makeActionPayloadOnRestart(flowName, param);
|
868
866
|
dispatch({
|
869
867
|
type: `flower/${type}`,
|
870
868
|
payload
|
@@ -874,6 +872,25 @@ const useFlower = ({
|
|
874
872
|
payload
|
875
873
|
});
|
876
874
|
}, [dispatch, emitNavigateEvent, flowName]);
|
875
|
+
const reset = React.useCallback(param => {
|
876
|
+
const {
|
877
|
+
type,
|
878
|
+
payload
|
879
|
+
} = makeActionPayloadOnReset(flowName, typeof param === 'string' ? {
|
880
|
+
node: param,
|
881
|
+
initialData
|
882
|
+
} : _extends({}, param, {
|
883
|
+
initialData
|
884
|
+
}));
|
885
|
+
dispatch({
|
886
|
+
type: `flower/${type}`,
|
887
|
+
payload
|
888
|
+
});
|
889
|
+
emitNavigateEvent({
|
890
|
+
type,
|
891
|
+
payload
|
892
|
+
});
|
893
|
+
}, [dispatch, emitNavigateEvent, flowName, initialData]);
|
877
894
|
const jump = React.useCallback(param => {
|
878
895
|
const {
|
879
896
|
type,
|
@@ -894,7 +911,8 @@ const useFlower = ({
|
|
894
911
|
next,
|
895
912
|
jump,
|
896
913
|
back,
|
897
|
-
reset
|
914
|
+
reset,
|
915
|
+
restart
|
898
916
|
};
|
899
917
|
};
|
900
918
|
|
@@ -912,7 +930,8 @@ const useFlowerNavigate = ({
|
|
912
930
|
next,
|
913
931
|
jump,
|
914
932
|
back,
|
915
|
-
reset
|
933
|
+
reset,
|
934
|
+
restart
|
916
935
|
} = useFlower({
|
917
936
|
flowName: name
|
918
937
|
});
|
@@ -930,11 +949,14 @@ const useFlowerNavigate = ({
|
|
930
949
|
case 'reset':
|
931
950
|
reset(node);
|
932
951
|
return;
|
952
|
+
case 'restart':
|
953
|
+
restart(node);
|
954
|
+
return;
|
933
955
|
default:
|
934
956
|
next();
|
935
957
|
return;
|
936
958
|
}
|
937
|
-
}, [next, jump, back, reset, node, route]);
|
959
|
+
}, [next, jump, back, reset, restart, node, route]);
|
938
960
|
return {
|
939
961
|
onNavigate,
|
940
962
|
flowName
|
package/dist/index.esm.js
CHANGED
@@ -225,8 +225,9 @@ const FlowerClient = ({
|
|
225
225
|
}, [dispatch, flowName, current, isDisabled, store, wsDevtools, isInitialized]);
|
226
226
|
const contextValues = useMemo(() => ({
|
227
227
|
flowName,
|
228
|
+
initialData: _initialData,
|
228
229
|
currentNode: current
|
229
|
-
}), [flowName, current]);
|
230
|
+
}), [flowName, _initialData, current]);
|
230
231
|
return isInitialized ? ( /*#__PURE__*/React.createElement(Provider, {
|
231
232
|
value: contextValues
|
232
233
|
}, prevFlowerNodeId !== current && typeof prevFlowerNodeId === 'string' && nodeById[prevFlowerNodeId], !isDisabled && nodeById[current])) : null;
|
@@ -349,29 +350,22 @@ const component$6 = /*#__PURE__*/React.memo(FlowerRoute);
|
|
349
350
|
component$6.displayName = 'FlowerRoute';
|
350
351
|
|
351
352
|
function _extends() {
|
352
|
-
_extends = Object.assign ? Object.assign.bind() : function (
|
353
|
-
for (var
|
354
|
-
var
|
355
|
-
for (var
|
356
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
357
|
-
target[key] = source[key];
|
358
|
-
}
|
359
|
-
}
|
353
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
354
|
+
for (var e = 1; e < arguments.length; e++) {
|
355
|
+
var t = arguments[e];
|
356
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
360
357
|
}
|
361
|
-
return
|
362
|
-
};
|
363
|
-
return _extends.apply(this, arguments);
|
358
|
+
return n;
|
359
|
+
}, _extends.apply(null, arguments);
|
364
360
|
}
|
365
|
-
function _objectWithoutPropertiesLoose(
|
366
|
-
if (
|
367
|
-
var
|
368
|
-
for (var
|
369
|
-
if (
|
370
|
-
|
371
|
-
target[key] = source[key];
|
372
|
-
}
|
361
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
362
|
+
if (null == r) return {};
|
363
|
+
var t = {};
|
364
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
365
|
+
if (e.indexOf(n) >= 0) continue;
|
366
|
+
t[n] = r[n];
|
373
367
|
}
|
374
|
-
return
|
368
|
+
return t;
|
375
369
|
}
|
376
370
|
|
377
371
|
const FlowerRule = ({
|
@@ -787,15 +781,17 @@ component$3.displayName = 'FlowerValue';
|
|
787
781
|
|
788
782
|
const ACTION_TYPES = {
|
789
783
|
back: ['prev', 'prevToNode'],
|
790
|
-
reset: ['reset', 'initializeFromNode'],
|
791
784
|
jump: ['node', 'node'],
|
792
|
-
next: ['next', 'next']
|
785
|
+
next: ['next', 'next'],
|
786
|
+
restart: ['restart', 'restart'],
|
787
|
+
reset: ['reset', 'initializeFromNode']
|
793
788
|
};
|
794
789
|
const PAYLAOAD_KEYS_NEEDED = {
|
795
790
|
back: ['node'],
|
796
|
-
reset: ['node'],
|
797
791
|
jump: ['node', 'history'],
|
798
|
-
next: ['node', 'route', 'data']
|
792
|
+
next: ['node', 'route', 'data'],
|
793
|
+
restart: ['node'],
|
794
|
+
reset: ['node', 'initialData']
|
799
795
|
};
|
800
796
|
const makeActionPayload = (actions, keys) => (flowName, params) => {
|
801
797
|
const rest = typeof params === 'string' ? {
|
@@ -814,13 +810,15 @@ const makeActionPayloadOnPrev = makeActionPayload(ACTION_TYPES.back, PAYLAOAD_KE
|
|
814
810
|
const makeActionPayloadOnReset = makeActionPayload(ACTION_TYPES.reset, PAYLAOAD_KEYS_NEEDED.reset);
|
815
811
|
const makeActionPayloadOnNode = makeActionPayload(ACTION_TYPES.jump, PAYLAOAD_KEYS_NEEDED.jump);
|
816
812
|
const makeActionPayloadOnNext = makeActionPayload(ACTION_TYPES.next, PAYLAOAD_KEYS_NEEDED.next);
|
813
|
+
const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart, PAYLAOAD_KEYS_NEEDED.restart);
|
817
814
|
const useFlower = ({
|
818
815
|
flowName: customFlowName,
|
819
816
|
name
|
820
817
|
} = {}) => {
|
821
818
|
const dispatch = useDispatch();
|
822
819
|
const {
|
823
|
-
flowName: flowNameDefault
|
820
|
+
flowName: flowNameDefault,
|
821
|
+
initialData
|
824
822
|
} = useContext(context);
|
825
823
|
const flowName = customFlowName || name || flowNameDefault;
|
826
824
|
const nodeId = useSelector(makeSelectCurrentNodeId(flowName != null ? flowName : ''));
|
@@ -858,11 +856,11 @@ const useFlower = ({
|
|
858
856
|
payload
|
859
857
|
});
|
860
858
|
}, [dispatch, emitNavigateEvent, flowName]);
|
861
|
-
const
|
859
|
+
const restart = useCallback(param => {
|
862
860
|
const {
|
863
861
|
type,
|
864
862
|
payload
|
865
|
-
} =
|
863
|
+
} = makeActionPayloadOnRestart(flowName, param);
|
866
864
|
dispatch({
|
867
865
|
type: `flower/${type}`,
|
868
866
|
payload
|
@@ -872,6 +870,25 @@ const useFlower = ({
|
|
872
870
|
payload
|
873
871
|
});
|
874
872
|
}, [dispatch, emitNavigateEvent, flowName]);
|
873
|
+
const reset = useCallback(param => {
|
874
|
+
const {
|
875
|
+
type,
|
876
|
+
payload
|
877
|
+
} = makeActionPayloadOnReset(flowName, typeof param === 'string' ? {
|
878
|
+
node: param,
|
879
|
+
initialData
|
880
|
+
} : _extends({}, param, {
|
881
|
+
initialData
|
882
|
+
}));
|
883
|
+
dispatch({
|
884
|
+
type: `flower/${type}`,
|
885
|
+
payload
|
886
|
+
});
|
887
|
+
emitNavigateEvent({
|
888
|
+
type,
|
889
|
+
payload
|
890
|
+
});
|
891
|
+
}, [dispatch, emitNavigateEvent, flowName, initialData]);
|
875
892
|
const jump = useCallback(param => {
|
876
893
|
const {
|
877
894
|
type,
|
@@ -892,7 +909,8 @@ const useFlower = ({
|
|
892
909
|
next,
|
893
910
|
jump,
|
894
911
|
back,
|
895
|
-
reset
|
912
|
+
reset,
|
913
|
+
restart
|
896
914
|
};
|
897
915
|
};
|
898
916
|
|
@@ -910,7 +928,8 @@ const useFlowerNavigate = ({
|
|
910
928
|
next,
|
911
929
|
jump,
|
912
930
|
back,
|
913
|
-
reset
|
931
|
+
reset,
|
932
|
+
restart
|
914
933
|
} = useFlower({
|
915
934
|
flowName: name
|
916
935
|
});
|
@@ -928,11 +947,14 @@ const useFlowerNavigate = ({
|
|
928
947
|
case 'reset':
|
929
948
|
reset(node);
|
930
949
|
return;
|
950
|
+
case 'restart':
|
951
|
+
restart(node);
|
952
|
+
return;
|
931
953
|
default:
|
932
954
|
next();
|
933
955
|
return;
|
934
956
|
}
|
935
|
-
}, [next, jump, back, reset, node, route]);
|
957
|
+
}, [next, jump, back, reset, restart, node, route]);
|
936
958
|
return {
|
937
959
|
onNavigate,
|
938
960
|
flowName
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Route, RouteNode, RoutePrev, RouteReset } from './FlowerNavigate';
|
1
|
+
import { Route, RouteNode, RoutePrev, RouteReset, RouteRestart } from './FlowerNavigate';
|
2
2
|
export type UseFlowerProps = {
|
3
3
|
[x in 'name' | 'flowName']?: string;
|
4
4
|
};
|
@@ -17,6 +17,7 @@ type useFlowerActions = {
|
|
17
17
|
back: (payload?: RoutePrev) => void;
|
18
18
|
reset: (payload?: RouteReset) => void;
|
19
19
|
jump: (payload: RouteNode) => void;
|
20
|
+
restart: (payload?: RouteRestart) => void;
|
20
21
|
};
|
21
22
|
export type UseFlower = (options?: UseFlowerProps) => useFlowerActions & {
|
22
23
|
flowName?: string;
|
@@ -5,9 +5,14 @@ export type RouteNode = string | {
|
|
5
5
|
flowName?: string;
|
6
6
|
history?: string[];
|
7
7
|
};
|
8
|
+
export type RouteRestart = string | {
|
9
|
+
node: string;
|
10
|
+
flowName?: string;
|
11
|
+
};
|
8
12
|
export type RouteReset = string | {
|
9
13
|
node: string;
|
10
14
|
flowName?: string;
|
15
|
+
initialData?: Record<string, any>;
|
11
16
|
};
|
12
17
|
export type RoutePrev = string | {
|
13
18
|
node: string;
|
@@ -34,4 +39,8 @@ export type FlowerNavigateProps = {
|
|
34
39
|
action?: 'jump';
|
35
40
|
node?: RouteNode;
|
36
41
|
route?: undefined;
|
42
|
+
} | {
|
43
|
+
action?: 'restart';
|
44
|
+
node?: RouteRestart;
|
45
|
+
route?: undefined;
|
37
46
|
});
|
package/dist/src/context.d.ts
CHANGED
@@ -3,6 +3,7 @@ export type FlowerContext = {
|
|
3
3
|
flowName?: string | undefined;
|
4
4
|
currentNode?: string | undefined;
|
5
5
|
autostart?: boolean | undefined;
|
6
|
+
initialData?: Record<string, any>;
|
6
7
|
};
|
7
8
|
export declare const context: React.Context<FlowerContext>;
|
8
9
|
export declare const Provider: React.Provider<FlowerContext>;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@flowerforce/flower-react",
|
3
|
-
"version": "3.0.1-beta.
|
3
|
+
"version": "3.0.1-beta.2",
|
4
4
|
"description": "FlowerJS components, hooks and utils for React.",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -22,8 +22,7 @@
|
|
22
22
|
},
|
23
23
|
"license": "ISC",
|
24
24
|
"peerDependencies": {
|
25
|
-
"react": ">=18"
|
26
|
-
"react-dom": ">=18"
|
25
|
+
"react": ">=18"
|
27
26
|
},
|
28
27
|
"devDependencies": {
|
29
28
|
"@testing-library/jest-dom": "^6.4.5",
|
@@ -35,7 +34,7 @@
|
|
35
34
|
"typescript": "^5.4.5"
|
36
35
|
},
|
37
36
|
"dependencies": {
|
38
|
-
"@flowerforce/flower-core": "3.0.
|
37
|
+
"@flowerforce/flower-core": "3.0.0",
|
39
38
|
"@reduxjs/toolkit": "^2.2.4",
|
40
39
|
"lodash": "^4.17.21",
|
41
40
|
"react-redux": "^9.1.2",
|