@flowerforce/flower-react 3.5.1-beta.1 → 4.0.3-beta.0
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/README.md +261 -202
- package/dist/index.cjs.js +214 -616
- package/dist/index.esm.js +184 -590
- package/dist/src/components/Flower.d.ts +7 -7
- package/dist/src/components/FlowerAction.d.ts +2 -3
- package/dist/src/components/FlowerComponent.d.ts +2 -4
- package/dist/src/components/FlowerFlow.d.ts +2 -3
- package/dist/src/components/FlowerNavigate/FlowerNavigate.d.ts +3 -0
- package/dist/src/components/FlowerNavigate/WrapperComponent.d.ts +3 -3
- package/dist/src/components/FlowerNavigate/index.d.ts +2 -4
- package/dist/src/components/FlowerNavigate/useFlowerNavigate.d.ts +1 -1
- package/dist/src/components/FlowerNode.d.ts +2 -3
- package/dist/src/components/FlowerRoute.d.ts +2 -3
- package/dist/src/components/FlowerServer.d.ts +2 -3
- package/dist/src/components/FlowerStart.d.ts +3 -4
- package/dist/src/components/index.d.ts +10 -0
- package/dist/src/components/useFlower/utils.d.ts +20 -0
- package/dist/src/components/useFlower.d.ts +2 -3
- package/dist/src/features/index.d.ts +2 -0
- package/dist/src/features/reducer/flowerReducer.d.ts +6 -0
- package/dist/src/{selectors.d.ts → features/selectors/selectors.d.ts} +474 -363
- package/dist/src/index.d.ts +5 -33
- package/dist/src/provider/index.d.ts +1 -0
- package/dist/src/provider/provider.d.ts +8 -0
- package/dist/src/types/FlowContext.d.ts +6 -0
- package/dist/src/types/FlowerHooks.d.ts +27 -0
- package/dist/src/{components/types → types}/FlowerProvider.d.ts +3 -3
- package/dist/src/types/index.d.ts +10 -0
- package/package.json +5 -2
- package/dist/src/components/FlowerField.d.ts +0 -4
- package/dist/src/components/FlowerRule.d.ts +0 -4
- package/dist/src/components/FlowerValue.d.ts +0 -4
- package/dist/src/components/types/FlowerField.d.ts +0 -124
- package/dist/src/components/types/FlowerHooks.d.ts +0 -72
- package/dist/src/components/types/FlowerRule.d.ts +0 -35
- package/dist/src/components/types/FlowerValue.d.ts +0 -33
- package/dist/src/components/useFlowerForm.d.ts +0 -26
- package/dist/src/context.d.ts +0 -10
- package/dist/src/provider.d.ts +0 -25
- package/dist/src/reducer.d.ts +0 -7
- /package/dist/src/{components/types → types}/DefaultNode.d.ts +0 -0
- /package/dist/src/{components/types → types}/FlowerComponent.d.ts +0 -0
- /package/dist/src/{components/types → types}/FlowerFlow.d.ts +0 -0
- /package/dist/src/{components/types → types}/FlowerNavigate.d.ts +0 -0
- /package/dist/src/{components/types → types}/FlowerNode.d.ts +0 -0
- /package/dist/src/{components/types → types}/FlowerRoute.d.ts +0 -0
- /package/dist/src/{components/types → types}/FlowerServer.d.ts +0 -0
package/dist/index.cjs.js
CHANGED
@@ -3,17 +3,12 @@
|
|
3
3
|
var React = require('react');
|
4
4
|
var _keyBy = require('lodash/keyBy');
|
5
5
|
var flowerCore = require('@flowerforce/flower-core');
|
6
|
+
var flowerReactContext = require('@flowerforce/flower-react-context');
|
6
7
|
var _get = require('lodash/get');
|
7
8
|
var toolkit = require('@reduxjs/toolkit');
|
8
9
|
var reselect = require('reselect');
|
9
|
-
var
|
10
|
-
var
|
11
|
-
var isEqual = require('lodash/isEqual');
|
12
|
-
|
13
|
-
const _context = React.createContext({});
|
14
|
-
const context = _context;
|
15
|
-
const Provider = _context.Provider;
|
16
|
-
const Consumer = _context.Consumer;
|
10
|
+
var flowerReactStore = require('@flowerforce/flower-react-store');
|
11
|
+
var flowerReactShared = require('@flowerforce/flower-react-shared');
|
17
12
|
|
18
13
|
// eslint-disable-next-line import/prefer-default-export
|
19
14
|
const convertElements = (nodes) => {
|
@@ -22,102 +17,80 @@ const convertElements = (nodes) => {
|
|
22
17
|
};
|
23
18
|
|
24
19
|
const flowerReducer = toolkit.createSlice({
|
25
|
-
name:
|
20
|
+
name: flowerCore.REDUCER_NAME.FLOWER_FLOW,
|
26
21
|
initialState: {},
|
27
|
-
reducers: flowerCore.
|
22
|
+
reducers: flowerCore.FlowerCoreBaseReducers
|
28
23
|
});
|
29
|
-
const
|
24
|
+
const flowerActions = flowerReducer.actions;
|
25
|
+
const flowerFlowReducer = flowerReducer.reducer;
|
30
26
|
const reducerFlower = {
|
31
|
-
|
27
|
+
[flowerCore.REDUCER_NAME.FLOWER_FLOW]: flowerFlowReducer
|
32
28
|
};
|
33
29
|
|
34
|
-
const {
|
35
|
-
const
|
36
|
-
const
|
37
|
-
const selectFlowerFormNode = (name
|
38
|
-
|
39
|
-
const makeSelectNodesIds = (name) => reselect.createSelector(selectFlower(name), flowerCore.Selectors.makeSelectNodesIds);
|
40
|
-
const makeSelectStartNodeId = (name) => reselect.createSelector(selectFlower(name), flowerCore.Selectors.makeSelectStartNodeId);
|
41
|
-
const makeSelectCurrentNodeId = (name) => reselect.createSelector(selectFlower(name), makeSelectStartNodeId(name), flowerCore.Selectors.makeSelectCurrentNodeId);
|
42
|
-
const makeSelectPrevNodeRetain = (name) => reselect.createSelector(makeSelectNodesIds(name), selectFlowerHistory(name), makeSelectCurrentNodeId(name), flowerCore.Selectors.makeSelectPrevNodeRetain);
|
43
|
-
const makeSelectCurrentNodeDisabled = (name) => reselect.createSelector(makeSelectNodesIds(name), makeSelectCurrentNodeId(name), flowerCore.Selectors.makeSelectCurrentNodeDisabled);
|
44
|
-
// dati nel flow selezionato
|
45
|
-
const getDataByFlow = (name) => reselect.createSelector(selectFlower(name), flowerCore.Selectors.getDataByFlow);
|
46
|
-
// selettore per recuperare i dati di un flow specifico e id specifico
|
47
|
-
const getDataFromState = (name, id) => reselect.createSelector(getDataByFlow(name), flowerCore.Selectors.getDataFromState(id));
|
48
|
-
const makeSelectNodeErrors = (name, currentNodeId) => reselect.createSelector(selectFlowerFormNode(name, currentNodeId), flowerCore.Selectors.makeSelectNodeErrors);
|
49
|
-
const makeSelectNodeFieldTouched = (name, currentNodeId, fieldId) => reselect.createSelector(selectFlowerFormNode(name, currentNodeId), flowerCore.Selectors.makeSelectNodeFormFieldTouched(fieldId));
|
50
|
-
const makeSelectNodeFieldFocused = (name, currentNodeId, fieldId) => reselect.createSelector(selectFlowerFormNode(name, currentNodeId), flowerCore.Selectors.makeSelectNodeFormFieldFocused(fieldId));
|
51
|
-
const makeSelectNodeFieldDirty = (name, currentNodeId, fieldId) => reselect.createSelector(selectFlowerFormNode(name, currentNodeId), flowerCore.Selectors.makeSelectNodeFormFieldDirty(fieldId));
|
52
|
-
const makeSelectNodeFormSubmitted = (name, currentNodeId) => reselect.createSelector(selectFlowerFormNode(name, currentNodeId), flowerCore.Selectors.makeSelectNodeFormSubmitted);
|
53
|
-
const getAllData = reselect.createSelector(selectGlobal, mapData);
|
54
|
-
const selectFlowerFormCurrentNode = (name) => reselect.createSelector(selectFlower(name), makeSelectCurrentNodeId(name), (data, current) => {
|
55
|
-
return _get(data, ['form', current]);
|
56
|
-
});
|
57
|
-
const makeSelectFieldError = (name, id, validate) => reselect.createSelector(getAllData, selectFlowerFormCurrentNode(name), flowerCore.Selectors.makeSelectFieldError(name, id, validate));
|
58
|
-
const selectorRulesDisabled = (id, rules, keys, flowName, value, currentNode) => reselect.createSelector(getAllData, makeSelectNodeErrors(flowName, currentNode), flowerCore.Selectors.selectorRulesDisabled(id, rules, keys, flowName, value));
|
59
|
-
|
60
|
-
//TODO check reduxContext type due to remove all any types
|
61
|
-
const reduxContext = React.createContext(null);
|
62
|
-
const useDispatch = reactRedux.createDispatchHook(reduxContext);
|
63
|
-
const useSelector = reactRedux.createSelectorHook(reduxContext);
|
64
|
-
const useStore = reactRedux.createStoreHook(reduxContext);
|
65
|
-
const store = ({ enableDevtool }) => toolkit.configureStore({
|
66
|
-
reducer: reducerFlower,
|
67
|
-
devTools: enableDevtool ? { name: 'flower' } : false
|
30
|
+
const { selectGlobal, selectGlobalForm } = flowerCore.FlowerCoreStateSelectors;
|
31
|
+
const selectFlower = (name) => reselect.createSelector(selectGlobal, flowerCore.FlowerCoreStateSelectors.selectFlower(name));
|
32
|
+
const selectFlowerForm = selectGlobalForm;
|
33
|
+
const selectFlowerFormNode = (name) => reselect.createSelector(selectFlowerForm, (data) => {
|
34
|
+
return data[name];
|
68
35
|
});
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
}
|
36
|
+
const selectFlowerHistory = (name) => reselect.createSelector(selectFlower(name), flowerCore.FlowerCoreStateSelectors.selectFlowerHistory);
|
37
|
+
const makeSelectNodesIds = (name) => reselect.createSelector(selectFlower(name), flowerCore.FlowerCoreStateSelectors.makeSelectNodesIds);
|
38
|
+
const makeSelectStartNodeId = (name) => reselect.createSelector(selectFlower(name), flowerCore.FlowerCoreStateSelectors.makeSelectStartNodeId);
|
39
|
+
const makeSelectCurrentNodeId = (name) => reselect.createSelector(selectFlower(name), makeSelectStartNodeId(name), flowerCore.FlowerCoreStateSelectors.makeSelectCurrentNodeId);
|
40
|
+
const makeSelectPrevNodeRetain = (name) => reselect.createSelector(makeSelectNodesIds(name), selectFlowerHistory(name), makeSelectCurrentNodeId(name), flowerCore.FlowerCoreStateSelectors.makeSelectPrevNodeRetain);
|
41
|
+
const makeSelectCurrentNodeDisabled = (name) => reselect.createSelector(makeSelectNodesIds(name), makeSelectCurrentNodeId(name), flowerCore.FlowerCoreStateSelectors.makeSelectCurrentNodeDisabled);
|
42
|
+
// dati nel flow selezionato
|
43
|
+
const makeSelectFormData = (name) => reselect.createSelector(selectFlowerFormNode(name), (data) => data?.data ?? {});
|
44
|
+
reselect.createSelector(selectGlobalForm, flowerCore.FlowerStateUtils.getAllData);
|
79
45
|
|
80
46
|
/* eslint-disable no-undef */
|
81
47
|
/* eslint-disable no-underscore-dangle */
|
82
|
-
|
48
|
+
/*
|
83
49
|
* FlowerClient
|
84
50
|
*/
|
85
|
-
const FlowerClient = ({ children, name, destroyOnUnmount = true, startId = null,
|
51
|
+
const FlowerClient = ({ children, name, destroyOnUnmount = true, startId = null, initialState = {}, initialData }) => {
|
86
52
|
const flowName = name;
|
87
|
-
const dispatch = useDispatch();
|
53
|
+
const dispatch = flowerReactStore.useDispatch();
|
88
54
|
const one = React.useRef(false);
|
89
55
|
const [wsDevtools, setWsDevtools] = React.useState(flowerCore.devtoolState && _get(flowerCore.devtoolState, '__FLOWER_DEVTOOLS_INITIALIZED__', false));
|
90
|
-
// TODO
|
56
|
+
// TODO could make that transformation in CoreUtils.generateNodesForFlowerJson
|
91
57
|
// eslint-disable-next-line react-hooks/exhaustive-deps, max-len
|
92
|
-
const nodes = React.useMemo(
|
58
|
+
const nodes = React.useMemo(
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
60
|
+
() => convertElements(React.Children.toArray(children)), [children]);
|
93
61
|
const nodeById = React.useMemo(() => _keyBy(React.Children.toArray(children), 'props.id'), [children]);
|
94
|
-
const isInitialized = useSelector(makeSelectStartNodeId(name));
|
95
|
-
const history = useSelector(selectFlowerHistory(name));
|
96
|
-
const current = useSelector(makeSelectCurrentNodeId(flowName));
|
97
|
-
const isDisabled = useSelector(makeSelectCurrentNodeDisabled(flowName));
|
98
|
-
const prevFlowerNodeId = useSelector(makeSelectPrevNodeRetain(flowName));
|
99
|
-
const store = useStore();
|
62
|
+
const isInitialized = flowerReactStore.useSelector(makeSelectStartNodeId(name));
|
63
|
+
const history = flowerReactStore.useSelector(selectFlowerHistory(name));
|
64
|
+
const current = flowerReactStore.useSelector(makeSelectCurrentNodeId(flowName));
|
65
|
+
const isDisabled = flowerReactStore.useSelector(makeSelectCurrentNodeDisabled(flowName));
|
66
|
+
const prevFlowerNodeId = flowerReactStore.useSelector(makeSelectPrevNodeRetain(flowName));
|
67
|
+
const store = flowerReactStore.useStore();
|
100
68
|
React.useEffect(() => {
|
101
69
|
if (nodes.length > 0 && one.current === false) {
|
102
70
|
one.current = true;
|
103
|
-
dispatch(
|
71
|
+
dispatch(flowerActions.initNodes({
|
104
72
|
name: flowName,
|
105
73
|
// @ts-expect-error FIX ME
|
106
74
|
nodes,
|
107
75
|
startId: startId ?? '',
|
108
76
|
persist: destroyOnUnmount === false,
|
109
|
-
initialData,
|
110
77
|
initialState
|
111
78
|
}));
|
79
|
+
if (initialData) {
|
80
|
+
dispatch(flowerReactStore.flowerDataActions.initForm({
|
81
|
+
formName: flowName,
|
82
|
+
initialData: initialData ?? {}
|
83
|
+
}));
|
84
|
+
}
|
112
85
|
}
|
113
86
|
}, [
|
114
87
|
dispatch,
|
115
88
|
flowName,
|
116
89
|
nodes,
|
117
90
|
startId,
|
118
|
-
initialData,
|
119
91
|
destroyOnUnmount,
|
120
|
-
initialState
|
92
|
+
initialState,
|
93
|
+
initialData
|
121
94
|
]);
|
122
95
|
React.useEffect(() => {
|
123
96
|
/* istanbul ignore next */
|
@@ -129,14 +102,16 @@ const FlowerClient = ({ children, name, destroyOnUnmount = true, startId = null,
|
|
129
102
|
setWsDevtools(true);
|
130
103
|
}
|
131
104
|
if (msg.action === 'SELECTED_NODE' && msg.name === flowName) {
|
132
|
-
dispatch(
|
133
|
-
}
|
134
|
-
if (msg.action === 'REPLACE_DATA' && msg.name === flowName) {
|
135
|
-
dispatch(actions.replaceData({ flowName: msg.name, value: msg.data }));
|
136
|
-
}
|
137
|
-
if (msg.action === 'ADD_DATA' && msg.name === flowName) {
|
138
|
-
dispatch(actions.addData({ flowName: msg.name, value: msg.data }));
|
105
|
+
dispatch(flowerActions.setCurrentNode({ name: msg.name, node: msg.id }));
|
139
106
|
}
|
107
|
+
// if (msg.action === 'REPLACE_DATA' && msg.name === flowName) {
|
108
|
+
// dispatch(
|
109
|
+
// formActions.replaceData({ flowName: msg.name, value: msg.data })
|
110
|
+
// )
|
111
|
+
// }
|
112
|
+
// if (msg.action === 'ADD_DATA' && msg.name === flowName) {
|
113
|
+
// dispatch(formActions.addData({ flowName: msg.name, value: msg.data }))
|
114
|
+
// }
|
140
115
|
};
|
141
116
|
/* istanbul ignore next */
|
142
117
|
if (flowerCore.devtoolState && _get(flowerCore.devtoolState, '__FLOWER_DEVTOOLS__')) {
|
@@ -153,7 +128,7 @@ const FlowerClient = ({ children, name, destroyOnUnmount = true, startId = null,
|
|
153
128
|
// unmount function
|
154
129
|
if (destroyOnUnmount && one.current === true) {
|
155
130
|
one.current = false;
|
156
|
-
dispatch(
|
131
|
+
dispatch(flowerActions.destroy({ name: flowName }));
|
157
132
|
}
|
158
133
|
}, [dispatch, flowName, destroyOnUnmount]);
|
159
134
|
React.useEffect(() => {
|
@@ -212,7 +187,7 @@ const FlowerClient = ({ children, name, destroyOnUnmount = true, startId = null,
|
|
212
187
|
if (!isInitialized)
|
213
188
|
return;
|
214
189
|
if (isDisabled) {
|
215
|
-
dispatch(
|
190
|
+
dispatch(flowerActions.next({ flowName }));
|
216
191
|
// eslint-disable-next-line no-underscore-dangle, no-undef
|
217
192
|
/* istanbul ignore next */
|
218
193
|
if (wsDevtools &&
|
@@ -235,7 +210,7 @@ const FlowerClient = ({ children, name, destroyOnUnmount = true, startId = null,
|
|
235
210
|
flowerCore.devtoolState &&
|
236
211
|
_get(flowerCore.devtoolState, '__FLOWER_DEVTOOLS__')) {
|
237
212
|
if (isInitialized === current)
|
238
|
-
return; // salto il primo
|
213
|
+
return; // salto il primo event
|
239
214
|
flowerCore.Emitter.emit('flower-devtool-from-client', {
|
240
215
|
source: 'flower-client',
|
241
216
|
action: 'SET_SELECTED',
|
@@ -255,32 +230,21 @@ const FlowerClient = ({ children, name, destroyOnUnmount = true, startId = null,
|
|
255
230
|
]);
|
256
231
|
const currentNodeId = prevFlowerNodeId || current;
|
257
232
|
const contextValues = React.useMemo(() => ({
|
258
|
-
flowName,
|
259
|
-
initialData,
|
233
|
+
name: flowName,
|
260
234
|
currentNode: current
|
261
|
-
}), [flowName,
|
235
|
+
}), [flowName, current]);
|
262
236
|
const prevContextValues = React.useMemo(() => ({
|
263
|
-
flowName,
|
264
|
-
initialData,
|
237
|
+
name: flowName,
|
265
238
|
currentNode: currentNodeId
|
266
|
-
}), [flowName,
|
239
|
+
}), [flowName, currentNodeId]);
|
267
240
|
return isInitialized ? (React.createElement(React.Fragment, null,
|
268
|
-
React.createElement(
|
269
|
-
React.createElement(
|
241
|
+
React.createElement(flowerReactContext.FlowerReactProvider, { value: prevContextValues }, nodeById[currentNodeId]),
|
242
|
+
React.createElement(flowerReactContext.FlowerReactProvider, { value: contextValues }, !isDisabled && current !== currentNodeId && nodeById[current]))) : null;
|
270
243
|
};
|
271
|
-
const component$
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
onEnter?.();
|
276
|
-
return () => {
|
277
|
-
onExit?.();
|
278
|
-
};
|
279
|
-
}, [onEnter, onExit]);
|
280
|
-
return children;
|
281
|
-
};
|
282
|
-
const component$b = React.memo(FlowerNode);
|
283
|
-
component$b.displayName = 'FlowerNode';
|
244
|
+
const component$9 = React.memo(FlowerClient);
|
245
|
+
component$9.displayName = 'Flower';
|
246
|
+
// workaround for let typescript read JSX component as a valid JSX element using react 19(?)
|
247
|
+
const Flower = component$9;
|
284
248
|
|
285
249
|
const FlowAction = ({ children, onEnter, onExit }) => {
|
286
250
|
React.useEffect(() => {
|
@@ -289,374 +253,28 @@ const FlowAction = ({ children, onEnter, onExit }) => {
|
|
289
253
|
onExit?.();
|
290
254
|
};
|
291
255
|
}, [onEnter, onExit]);
|
292
|
-
return children;
|
293
|
-
};
|
294
|
-
const component$a = React.memo(FlowAction);
|
295
|
-
component$a.displayName = 'FlowerAction';
|
296
|
-
|
297
|
-
const FlowerServer = ({ children }) => {
|
298
|
-
return children;
|
299
|
-
};
|
300
|
-
const component$9 = React.memo(FlowerServer);
|
301
|
-
component$9.displayName = 'FlowerServer';
|
302
|
-
|
303
|
-
const FlowerFlow = ({ children, onEnter, onExit }) => {
|
304
|
-
React.useEffect(() => {
|
305
|
-
onEnter?.();
|
306
|
-
return () => {
|
307
|
-
onExit?.();
|
308
|
-
};
|
309
|
-
}, [onEnter, onExit]);
|
310
|
-
return children;
|
256
|
+
return React.createElement(React.Fragment, null, children);
|
311
257
|
};
|
312
|
-
const component$8 = React.memo(
|
313
|
-
component$8.displayName = '
|
258
|
+
const component$8 = React.memo(FlowAction);
|
259
|
+
component$8.displayName = 'FlowerAction';
|
260
|
+
const FlowerAction = component$8;
|
314
261
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
const { flowName, autostart = true, currentNode } = React.useContext(context);
|
319
|
-
const startNodeId = useSelector(makeSelectStartNodeId(flowName ?? ''));
|
320
|
-
React.useEffect(() => {
|
321
|
-
if (startNodeId === currentNode && autostart && one.current === false) {
|
322
|
-
one.current = true;
|
323
|
-
dispatch({ type: 'flower/next', payload: { flowName, isStart: true } });
|
324
|
-
// if (global.window
|
325
|
-
// // eslint-disable-next-line no-underscore-dangle, no-undef
|
326
|
-
// && global.window.__FLOWER_DEVTOOLS__ && global.window.__FLOWER_DEVTOOLS__AUTO) {
|
327
|
-
// Emitter.emit('flower-devtool-from-client', {
|
328
|
-
// source: 'flower-client',
|
329
|
-
// action: 'START_FLOWER',
|
330
|
-
// name: flowName,
|
331
|
-
// });
|
332
|
-
// }
|
333
|
-
}
|
334
|
-
}, [dispatch, autostart, startNodeId, currentNode, flowName]);
|
335
|
-
return null;
|
336
|
-
}
|
337
|
-
const component$7 = React.memo(FlowerStart);
|
338
|
-
component$7.displayName = 'FlowerStart';
|
262
|
+
const _FlowerComponent = ({ children }) => children;
|
263
|
+
const component$7 = React.memo(_FlowerComponent);
|
264
|
+
const FlowerComponent = component$7;
|
339
265
|
|
340
|
-
const
|
341
|
-
const dispatch = useDispatch();
|
342
|
-
const one = React.useRef(false);
|
343
|
-
const { flowName } = React.useContext(context);
|
266
|
+
const _FlowerFlow = ({ children, onEnter, onExit }) => {
|
344
267
|
React.useEffect(() => {
|
345
268
|
onEnter?.();
|
346
269
|
return () => {
|
347
270
|
onExit?.();
|
348
271
|
};
|
349
272
|
}, [onEnter, onExit]);
|
350
|
-
React.
|
351
|
-
if (autostart && one.current === false) {
|
352
|
-
one.current = true;
|
353
|
-
dispatch({ type: 'flower/next', payload: { flowName } });
|
354
|
-
}
|
355
|
-
}, [dispatch, flowName, autostart]);
|
356
|
-
return children;
|
357
|
-
};
|
358
|
-
const component$6 = React.memo(FlowerRoute);
|
359
|
-
component$6.displayName = 'FlowerRoute';
|
360
|
-
|
361
|
-
const FlowerRule = ({ children, rules, value, alwaysDisplay, flowName, id, onUpdate }) => {
|
362
|
-
const { flowName: flowNameContext, currentNode } = React.useContext(context);
|
363
|
-
const name = flowName || flowNameContext;
|
364
|
-
const keys = flowerCore.MatchRules.utils.getKeys(rules, { prefix: name });
|
365
|
-
const hidden = useSelector(selectorRulesDisabled(id ?? '', rules, keys ?? [], name ?? '', value, currentNode ?? ''));
|
366
|
-
React.useEffect(() => {
|
367
|
-
if (onUpdate) {
|
368
|
-
onUpdate(hidden);
|
369
|
-
}
|
370
|
-
}, [hidden, onUpdate]);
|
371
|
-
if (typeof children === 'function') {
|
372
|
-
if (alwaysDisplay && hidden) {
|
373
|
-
return children({ hidden });
|
374
|
-
}
|
375
|
-
if (hidden) {
|
376
|
-
return undefined;
|
377
|
-
}
|
378
|
-
return children({});
|
379
|
-
}
|
380
|
-
if (alwaysDisplay && hidden) {
|
381
|
-
return React.Children.map(children, (child, i) => {
|
382
|
-
if (React.isValidElement(child)) {
|
383
|
-
const { props, type } = child;
|
384
|
-
const Component = type;
|
385
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
386
|
-
return Component && React.createElement(Component, { key: i, hidden: true, ...props });
|
387
|
-
}
|
388
|
-
return child;
|
389
|
-
});
|
390
|
-
}
|
391
|
-
return hidden
|
392
|
-
? undefined
|
393
|
-
: React.Children.map(children, (child, i) => {
|
394
|
-
if (React.isValidElement(child)) {
|
395
|
-
const { props, type } = child;
|
396
|
-
const Component = type;
|
397
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
398
|
-
return Component && React.createElement(Component, { key: i, ...props });
|
399
|
-
}
|
400
|
-
return child;
|
401
|
-
});
|
402
|
-
};
|
403
|
-
const component$5 = React.memo(FlowerRule);
|
404
|
-
component$5.displayName = 'FlowerRule';
|
405
|
-
|
406
|
-
/* eslint-disable */
|
407
|
-
function isIntrinsicElement$1(x) {
|
408
|
-
return typeof x === 'string';
|
409
|
-
}
|
410
|
-
//TODO make types for wrapper function props
|
411
|
-
function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDebounce = 0, asyncValidate, asyncInitialError, asyncWaitingError, destroyValue, destroyOnHide, onBlur, onFocus, hidden, onUpdate, defaultValue, ...props }) {
|
412
|
-
const dispatch = useDispatch();
|
413
|
-
const [customAsyncErrors, setCustomAsyncErrors] = React.useState(asyncValidate && asyncInitialError && [asyncInitialError]);
|
414
|
-
const [isValidating, setIsValidating] = React.useState(undefined);
|
415
|
-
const { flowNameFromPath = flowName, path } = React.useMemo(() => flowerCore.CoreUtils.getPath(id), [id]);
|
416
|
-
const value = useSelector(getDataFromState(flowNameFromPath, path));
|
417
|
-
const errors = useSelector(makeSelectFieldError(flowName, id, validate), flowerCore.CoreUtils.allEqual);
|
418
|
-
const dirty = useSelector(makeSelectNodeFieldDirty(flowName, currentNode, id));
|
419
|
-
const touched = useSelector(makeSelectNodeFieldTouched(flowName, currentNode, id));
|
420
|
-
const focused = useSelector(makeSelectNodeFieldFocused(flowName, currentNode, id));
|
421
|
-
const refValue = React.useRef();
|
422
|
-
const isSubmitted = useSelector(makeSelectNodeFormSubmitted(flowName, currentNode));
|
423
|
-
const allErrors = React.useMemo(() => hidden ? [] : [...errors, ...(customAsyncErrors || []).filter(Boolean)], [errors, hidden, customAsyncErrors]);
|
424
|
-
const setTouched = React.useCallback((touched) => {
|
425
|
-
dispatch({
|
426
|
-
type: 'flower/formFieldTouch',
|
427
|
-
payload: {
|
428
|
-
name: flowName,
|
429
|
-
id,
|
430
|
-
currentNode,
|
431
|
-
touched
|
432
|
-
}
|
433
|
-
});
|
434
|
-
}, [dispatch, flowName, currentNode, id]);
|
435
|
-
const setFocus = React.useCallback((focused) => {
|
436
|
-
dispatch({
|
437
|
-
type: 'flower/formFieldFocus',
|
438
|
-
payload: {
|
439
|
-
name: flowName,
|
440
|
-
id,
|
441
|
-
currentNode,
|
442
|
-
focused
|
443
|
-
}
|
444
|
-
});
|
445
|
-
}, [dispatch, flowName, currentNode, id]);
|
446
|
-
const validateFn = React.useCallback(async (value) => {
|
447
|
-
if (asyncWaitingError) {
|
448
|
-
setCustomAsyncErrors([asyncWaitingError]);
|
449
|
-
}
|
450
|
-
setIsValidating(true);
|
451
|
-
const state = flowerCore.FlowerStateUtils.getAllData(store);
|
452
|
-
const res = await asyncValidate(value, state, errors);
|
453
|
-
setIsValidating(false);
|
454
|
-
setCustomAsyncErrors(res);
|
455
|
-
}, [asyncWaitingError, errors]);
|
456
|
-
const debouncedValidation = React.useCallback(debounce(validateFn, asyncDebounce), [
|
457
|
-
validateFn
|
458
|
-
]);
|
459
|
-
const onChange = React.useCallback((val) => {
|
460
|
-
if (asyncValidate && asyncWaitingError) {
|
461
|
-
setCustomAsyncErrors([asyncWaitingError]);
|
462
|
-
}
|
463
|
-
dispatch({
|
464
|
-
type: `flower/addDataByPath`,
|
465
|
-
payload: {
|
466
|
-
flowName: flowNameFromPath,
|
467
|
-
id,
|
468
|
-
value: val,
|
469
|
-
dirty: defaultValue ? !isEqual(val, defaultValue) : true
|
470
|
-
}
|
471
|
-
});
|
472
|
-
}, [flowNameFromPath, id, dispatch, setCustomAsyncErrors, asyncValidate, asyncWaitingError]);
|
473
|
-
const onBlurInternal = React.useCallback((e) => {
|
474
|
-
setTouched(true);
|
475
|
-
setFocus(false);
|
476
|
-
onBlur && onBlur(e);
|
477
|
-
}, [onBlur, setTouched, setFocus]);
|
478
|
-
const onFocusInternal = React.useCallback((e) => {
|
479
|
-
setFocus(true);
|
480
|
-
onFocus && onFocus(e);
|
481
|
-
}, [onFocus, setFocus]);
|
482
|
-
React.useEffect(() => {
|
483
|
-
if (hidden)
|
484
|
-
return;
|
485
|
-
if (asyncValidate) {
|
486
|
-
if (refValue.current === value)
|
487
|
-
return;
|
488
|
-
refValue.current = value;
|
489
|
-
const hasValue = !flowerCore.MatchRules.utils.isEmpty(value);
|
490
|
-
if (!hasValue) {
|
491
|
-
setCustomAsyncErrors(asyncInitialError && [asyncInitialError]);
|
492
|
-
setIsValidating(false);
|
493
|
-
return;
|
494
|
-
}
|
495
|
-
setTouched(true);
|
496
|
-
debouncedValidation(value);
|
497
|
-
}
|
498
|
-
}, [asyncValidate, asyncInitialError, value, debouncedValidation, setTouched, hidden]);
|
499
|
-
React.useEffect(() => {
|
500
|
-
if (onUpdate) {
|
501
|
-
onUpdate(value);
|
502
|
-
}
|
503
|
-
}, [value, onUpdate]);
|
504
|
-
React.useEffect(() => {
|
505
|
-
dispatch({
|
506
|
-
type: 'flower/formAddErrors',
|
507
|
-
payload: {
|
508
|
-
name: flowName,
|
509
|
-
id,
|
510
|
-
currentNode,
|
511
|
-
errors: allErrors
|
512
|
-
}
|
513
|
-
});
|
514
|
-
}, [id, flowName, allErrors, currentNode, touched]);
|
515
|
-
React.useEffect(() => {
|
516
|
-
dispatch({
|
517
|
-
type: 'flower/setFormIsValidating',
|
518
|
-
payload: {
|
519
|
-
name: flowName,
|
520
|
-
currentNode,
|
521
|
-
isValidating
|
522
|
-
}
|
523
|
-
});
|
524
|
-
}, [flowName, currentNode, isValidating]);
|
525
|
-
React.useEffect(() => {
|
526
|
-
// destroy
|
527
|
-
return () => {
|
528
|
-
if (destroyValue) {
|
529
|
-
dispatch({
|
530
|
-
type: `flower/unsetData`,
|
531
|
-
payload: { flowName: flowNameFromPath, id: path }
|
532
|
-
});
|
533
|
-
}
|
534
|
-
dispatch({
|
535
|
-
type: 'flower/formRemoveErrors',
|
536
|
-
payload: {
|
537
|
-
name: flowName,
|
538
|
-
id,
|
539
|
-
currentNode
|
540
|
-
}
|
541
|
-
});
|
542
|
-
};
|
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]);
|
562
|
-
React.useEffect(() => {
|
563
|
-
if (defaultValue && !dirty && !isEqual(value, defaultValue)) {
|
564
|
-
onChange(defaultValue);
|
565
|
-
}
|
566
|
-
}, [defaultValue, value, dirty, onChange]);
|
567
|
-
const newProps = React.useMemo(() => ({
|
568
|
-
...props,
|
569
|
-
id,
|
570
|
-
value,
|
571
|
-
errors: allErrors,
|
572
|
-
hasError: !!allErrors.length,
|
573
|
-
onChange,
|
574
|
-
onBlur: onBlurInternal,
|
575
|
-
onFocus: onFocusInternal,
|
576
|
-
focused: !!focused,
|
577
|
-
touched,
|
578
|
-
dirty,
|
579
|
-
hidden,
|
580
|
-
isValidating,
|
581
|
-
isSubmitted,
|
582
|
-
}), [
|
583
|
-
props,
|
584
|
-
id,
|
585
|
-
value,
|
586
|
-
allErrors,
|
587
|
-
touched,
|
588
|
-
dirty,
|
589
|
-
onChange,
|
590
|
-
onBlurInternal,
|
591
|
-
onFocusInternal,
|
592
|
-
hidden,
|
593
|
-
isValidating,
|
594
|
-
isSubmitted,
|
595
|
-
focused
|
596
|
-
]);
|
597
|
-
if (typeof Component === 'function') {
|
598
|
-
return Component(newProps);
|
599
|
-
}
|
600
|
-
// TODO si arriva in questa condizione quando si passa un componente primitivo es. div
|
601
|
-
// in questo caso non posso props custom di flower
|
602
|
-
if (isIntrinsicElement$1(Component)) {
|
603
|
-
return React.createElement(Component, { id: id, ...props });
|
604
|
-
}
|
605
|
-
return Component && React.createElement(Component, { ...newProps });
|
606
|
-
}
|
607
|
-
const FlowerField = ({ id, validate, asyncValidate, asyncDebounce, asyncInitialError, asyncWaitingError, rules, alwaysDisplay, value, children, defaultValue, destroyOnHide, destroyValue, flowName, onUpdate }) => {
|
608
|
-
const { flowName: flowNameContext, currentNode } = React.useContext(context);
|
609
|
-
const name = flowName || flowNameContext;
|
610
|
-
if (typeof children === 'function') {
|
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 }))));
|
612
|
-
}
|
613
|
-
return React.Children.map(children, (child, i) => {
|
614
|
-
if (!React.isValidElement(child)) {
|
615
|
-
return child;
|
616
|
-
}
|
617
|
-
const { type, props } = child;
|
618
|
-
const Component = type;
|
619
|
-
return (React.createElement(component$5, { key: i, alwaysDisplay: alwaysDisplay, rules: rules, value: value, flowName: name }, ({ hidden }) => (React.createElement(Wrapper$1, { ...props, hidden: hidden, id: id, Component: Component, flowName: name, currentNode: currentNode, validate: validate, asyncValidate: asyncValidate, asyncDebounce: asyncDebounce, asyncInitialError: asyncInitialError, asyncWaitingError: asyncWaitingError, destroyValue: destroyValue, onUpdate: onUpdate, defaultValue: defaultValue }))));
|
620
|
-
});
|
273
|
+
return React.createElement(React.Fragment, null, children);
|
621
274
|
};
|
622
|
-
const component$
|
623
|
-
component$
|
624
|
-
|
625
|
-
/* eslint-disable */
|
626
|
-
//TODO make types for wrapper function
|
627
|
-
function Wrapper({ Component, id, flowName, spreadValue, hidden, onUpdate, ...props }) {
|
628
|
-
const { flowNameFromPath = flowName, path } = React.useMemo(() => flowerCore.CoreUtils.getPath(id), [id]);
|
629
|
-
const value = useSelector(getDataFromState(flowNameFromPath, path));
|
630
|
-
const values = spreadValue && typeof value === 'object' && !Array.isArray(value)
|
631
|
-
? value
|
632
|
-
: { value };
|
633
|
-
React.useEffect(() => {
|
634
|
-
if (onUpdate) {
|
635
|
-
onUpdate(value);
|
636
|
-
}
|
637
|
-
}, [onUpdate, value]);
|
638
|
-
return (React.createElement(Component, { id: id, ...props, flowName: flowName, hidden: hidden, ...values }));
|
639
|
-
}
|
640
|
-
const RenderRules$1 = ({ id, alwaysDisplay, rules, value, Component, spreadValue, flowName, onUpdate, ...props }) => {
|
641
|
-
return (React.createElement(component$5, { alwaysDisplay: alwaysDisplay, rules: rules, value: value, flowName: flowName, id: id }, ({ hidden }) => (React.createElement(Wrapper, { ...props, hidden: hidden, id: id, Component: Component, spreadValue: spreadValue, flowName: flowName, onUpdate: onUpdate }))));
|
642
|
-
};
|
643
|
-
const FlowerValue = ({ id = '*', rules, alwaysDisplay, value, children, spreadValue, flowName, onUpdate, }) => {
|
644
|
-
const { flowName: flowNameContext } = React.useContext(context);
|
645
|
-
const name = flowName || flowNameContext;
|
646
|
-
if (typeof children === 'function') {
|
647
|
-
return (React.createElement(RenderRules$1, { id: id, alwaysDisplay: alwaysDisplay, rules: rules, value: value, spreadValue: spreadValue, Component: children, flowName: name, onUpdate: onUpdate }));
|
648
|
-
}
|
649
|
-
return React.Children.map(children, (child, i) => {
|
650
|
-
if (!React.isValidElement(child))
|
651
|
-
return child;
|
652
|
-
const { type, props } = child;
|
653
|
-
const Component = type;
|
654
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
655
|
-
return (React.createElement(RenderRules$1, { key: i, id: id, alwaysDisplay: alwaysDisplay, rules: rules, value: value, spreadValue: spreadValue, flowName: name, Component: Component, ...props, onUpdate: onUpdate }));
|
656
|
-
});
|
657
|
-
};
|
658
|
-
const component$3 = React.memo(FlowerValue);
|
659
|
-
component$3.displayName = 'FlowerValue';
|
275
|
+
const component$6 = React.memo(_FlowerFlow);
|
276
|
+
component$6.displayName = 'FlowerFlow';
|
277
|
+
const FlowerFlow = component$6;
|
660
278
|
|
661
279
|
const ACTION_TYPES = {
|
662
280
|
back: ['prev', 'prevToNode'],
|
@@ -665,10 +283,10 @@ const ACTION_TYPES = {
|
|
665
283
|
restart: ['restart', 'restart'],
|
666
284
|
reset: ['reset', 'initializeFromNode']
|
667
285
|
};
|
668
|
-
const
|
286
|
+
const PAYLOAD_KEYS_NEEDED = {
|
669
287
|
back: ['node'],
|
670
288
|
jump: ['node', 'history'],
|
671
|
-
next: ['node', 'route', 'data'],
|
289
|
+
next: ['node', 'route', 'data', 'dataIn'],
|
672
290
|
restart: ['node'],
|
673
291
|
reset: ['node', 'initialData']
|
674
292
|
};
|
@@ -684,11 +302,11 @@ const makeActionPayload = (actions, keys) => (flowName, params) => {
|
|
684
302
|
payload
|
685
303
|
};
|
686
304
|
};
|
687
|
-
const makeActionPayloadOnPrev = makeActionPayload(ACTION_TYPES.back,
|
688
|
-
const makeActionPayloadOnReset = makeActionPayload(ACTION_TYPES.reset,
|
689
|
-
const makeActionPayloadOnNode = makeActionPayload(ACTION_TYPES.jump,
|
690
|
-
const makeActionPayloadOnNext = makeActionPayload(ACTION_TYPES.next,
|
691
|
-
const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart,
|
305
|
+
const makeActionPayloadOnPrev = makeActionPayload(ACTION_TYPES.back, PAYLOAD_KEYS_NEEDED.back);
|
306
|
+
const makeActionPayloadOnReset = makeActionPayload(ACTION_TYPES.reset, PAYLOAD_KEYS_NEEDED.reset);
|
307
|
+
const makeActionPayloadOnNode = makeActionPayload(ACTION_TYPES.jump, PAYLOAD_KEYS_NEEDED.jump);
|
308
|
+
const makeActionPayloadOnNext = makeActionPayload(ACTION_TYPES.next, PAYLOAD_KEYS_NEEDED.next);
|
309
|
+
const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart, PAYLOAD_KEYS_NEEDED.restart);
|
692
310
|
/** This hook allows you to read flow informations, such as the flowName and ID of the current node.
|
693
311
|
*
|
694
312
|
* It also exposes all the functions to navigate within the flow:
|
@@ -708,12 +326,12 @@ const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart, PAYLA
|
|
708
326
|
* @param {string} name - optional parameter, if flowName exist, name is not used
|
709
327
|
*/
|
710
328
|
const useFlower = ({ flowName: customFlowName, name } = {}) => {
|
711
|
-
const dispatch = useDispatch();
|
712
|
-
const {
|
713
|
-
const store = useStore();
|
329
|
+
const dispatch = flowerReactStore.useDispatch();
|
330
|
+
const { name: flowNameDefault, initialData } = React.useContext(flowerReactContext.FlowerReactContext);
|
331
|
+
const store = flowerReactStore.useStore();
|
714
332
|
const flowName = (customFlowName || name || flowNameDefault);
|
715
|
-
const nodeId = useSelector(makeSelectCurrentNodeId(flowName ?? ''));
|
716
|
-
const startId = useSelector(makeSelectStartNodeId(flowName ?? ''));
|
333
|
+
const nodeId = flowerReactStore.useSelector(makeSelectCurrentNodeId(flowName ?? ''));
|
334
|
+
const startId = flowerReactStore.useSelector(makeSelectStartNodeId(flowName ?? ''));
|
717
335
|
const emitNavigateEvent = React.useCallback(
|
718
336
|
//TODO check this function is needed
|
719
337
|
(params) => {
|
@@ -731,22 +349,25 @@ const useFlower = ({ flowName: customFlowName, name } = {}) => {
|
|
731
349
|
}
|
732
350
|
}, [flowName, nodeId]);
|
733
351
|
const next = React.useCallback((param) => {
|
734
|
-
const params = typeof param === 'string' ? { route: param } : {
|
352
|
+
const params = typeof param === 'string' ? { route: param } : { dataIn: param };
|
735
353
|
const { type, payload } = makeActionPayloadOnNext(flowName, params);
|
736
354
|
dispatch({
|
737
|
-
type:
|
738
|
-
payload
|
355
|
+
type: `${flowerCore.REDUCER_NAME.FLOWER_FLOW}/${type}`,
|
356
|
+
payload: {
|
357
|
+
...payload,
|
358
|
+
data: store.getState()
|
359
|
+
}
|
739
360
|
});
|
740
361
|
emitNavigateEvent({ type, payload });
|
741
|
-
}, [dispatch, emitNavigateEvent, flowName]);
|
362
|
+
}, [dispatch, emitNavigateEvent, flowName, store]);
|
742
363
|
const back = React.useCallback((param) => {
|
743
364
|
const { type, payload } = makeActionPayloadOnPrev(flowName, param);
|
744
|
-
dispatch({ type:
|
365
|
+
dispatch({ type: `${flowerCore.REDUCER_NAME.FLOWER_FLOW}/${type}`, payload });
|
745
366
|
emitNavigateEvent({ type, payload });
|
746
367
|
}, [dispatch, emitNavigateEvent, flowName]);
|
747
368
|
const restart = React.useCallback((param) => {
|
748
369
|
const { type, payload } = makeActionPayloadOnRestart(flowName, param);
|
749
|
-
dispatch({ type:
|
370
|
+
dispatch({ type: `${flowerCore.REDUCER_NAME.FLOWER_FLOW}/${type}`, payload });
|
750
371
|
emitNavigateEvent({ type, payload });
|
751
372
|
}, [dispatch, emitNavigateEvent, flowName]);
|
752
373
|
const reset = React.useCallback((param) => {
|
@@ -756,17 +377,17 @@ const useFlower = ({ flowName: customFlowName, name } = {}) => {
|
|
756
377
|
...param,
|
757
378
|
initialData
|
758
379
|
});
|
759
|
-
dispatch({ type:
|
380
|
+
dispatch({ type: `${flowerCore.REDUCER_NAME.FLOWER_FLOW}/${type}`, payload });
|
760
381
|
emitNavigateEvent({ type, payload });
|
761
382
|
}, [dispatch, emitNavigateEvent, flowName, initialData]);
|
762
383
|
const jump = React.useCallback((param) => {
|
763
384
|
const { type, payload } = makeActionPayloadOnNode(flowName, param);
|
764
|
-
dispatch({ type:
|
385
|
+
dispatch({ type: `${flowerCore.REDUCER_NAME.FLOWER_FLOW}/${type}`, payload });
|
765
386
|
emitNavigateEvent({ type, payload });
|
766
387
|
}, [dispatch, emitNavigateEvent, flowName]);
|
767
388
|
const getCurrentNodeId = React.useCallback((customFlowName) => {
|
768
389
|
return _get(store.getState(), [
|
769
|
-
|
390
|
+
flowerCore.REDUCER_NAME.FLOWER_FLOW,
|
770
391
|
customFlowName || flowName,
|
771
392
|
'current'
|
772
393
|
]);
|
@@ -807,7 +428,7 @@ const useFlower = ({ flowName: customFlowName, name } = {}) => {
|
|
807
428
|
// }
|
808
429
|
// );
|
809
430
|
const useFlowerNavigate = ({ flowName, action, route, node }) => {
|
810
|
-
const {
|
431
|
+
const { name: flowNameContext } = React.useContext(flowerReactContext.FlowerReactContext);
|
811
432
|
const name = flowName || flowNameContext;
|
812
433
|
const { next, jump, back, reset, restart } = useFlower({ flowName: name });
|
813
434
|
const onNavigate = React.useCallback(() => {
|
@@ -843,7 +464,7 @@ function isIntrinsicElement(x) {
|
|
843
464
|
return typeof x === 'string';
|
844
465
|
}
|
845
466
|
//TODO type FlowerNavigateWrapper props
|
846
|
-
function
|
467
|
+
function _FlowerNavigateWrapper({ hidden, Component, onNavigate, ...props }) {
|
847
468
|
const newProps = React.useMemo(() => ({
|
848
469
|
...props,
|
849
470
|
hidden,
|
@@ -862,155 +483,132 @@ function FlowerNavigateWrapper({ hidden, Component, onNavigate, ...props }) {
|
|
862
483
|
/* istanbul ignore next */
|
863
484
|
return Component && React.createElement(Component, { ...newProps });
|
864
485
|
}
|
865
|
-
const component$
|
486
|
+
const component$5 = React.memo(_FlowerNavigateWrapper);
|
487
|
+
const FlowerNavigateWrapper = component$5;
|
866
488
|
|
867
489
|
/* eslint-disable */
|
868
490
|
//TODO type RenderRules props
|
491
|
+
// ! Probably in this scenario we must replace `FlowerRule` or refactor `FlowerNavigate`
|
869
492
|
const RenderRules = ({ alwaysDisplay, rules, Component, flowName, onNavigate, ...props }) => {
|
870
|
-
return (React.createElement(
|
493
|
+
return (React.createElement(flowerReactShared.FlowerRule, { alwaysDisplay: alwaysDisplay, rules: rules, formName: flowName }, ({ hidden }) => (React.createElement(FlowerNavigateWrapper, { ...props, Component: Component, hidden: hidden, onNavigate: onNavigate }))));
|
871
494
|
};
|
872
|
-
const
|
873
|
-
const { onNavigate, flowName } = useFlowerNavigate({
|
495
|
+
const _FlowerNavigate = ({ children, flowName: forceFlowName, action, route, node, rules, alwaysDisplay }) => {
|
496
|
+
const { onNavigate, flowName } = useFlowerNavigate({
|
497
|
+
flowName: forceFlowName,
|
498
|
+
action,
|
499
|
+
route,
|
500
|
+
node
|
501
|
+
});
|
874
502
|
if (typeof children === 'function') {
|
875
|
-
return React.createElement(RenderRules, { alwaysDisplay: alwaysDisplay, rules: rules, Component: children, flowName: flowName, onNavigate: onNavigate });
|
503
|
+
return (React.createElement(RenderRules, { alwaysDisplay: alwaysDisplay, rules: rules, Component: children, flowName: flowName, onNavigate: onNavigate }));
|
876
504
|
}
|
877
|
-
return React.Children.map(children, (child, i) => {
|
505
|
+
return (React.createElement(React.Fragment, null, React.Children.map(children, (child, i) => {
|
878
506
|
if (!React.isValidElement(child))
|
879
507
|
return child;
|
880
508
|
const { type, props } = child;
|
881
509
|
const Component = type;
|
882
|
-
|
883
|
-
|
884
|
-
});
|
510
|
+
return (React.createElement(RenderRules, { key: i, alwaysDisplay: alwaysDisplay, rules: rules, Component: Component, flowName: flowName, onNavigate: onNavigate, ...props }));
|
511
|
+
})));
|
885
512
|
};
|
886
|
-
const component$
|
887
|
-
component$
|
513
|
+
const component$4 = React.memo(_FlowerNavigate);
|
514
|
+
component$4.displayName = 'FlowerNavigate';
|
515
|
+
const FlowerNavigate = component$4;
|
888
516
|
|
889
|
-
const
|
890
|
-
|
517
|
+
const _FlowerNode = ({ children, onEnter, onExit }) => {
|
518
|
+
React.useEffect(() => {
|
519
|
+
onEnter?.();
|
520
|
+
return () => {
|
521
|
+
onExit?.();
|
522
|
+
};
|
523
|
+
}, [onEnter, onExit]);
|
524
|
+
return React.createElement(React.Fragment, null, children);
|
525
|
+
};
|
526
|
+
const component$3 = React.memo(_FlowerNode);
|
527
|
+
component$3.displayName = 'FlowerNode';
|
528
|
+
const FlowerNode = component$3;
|
891
529
|
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
* - reset,
|
907
|
-
* - setCustomErrors
|
908
|
-
* - getFormStatus
|
909
|
-
*
|
910
|
-
* @param {string} flowName - first optional parameter
|
911
|
-
*
|
912
|
-
* @param {string} name - alias optional parameter, if flowName exist, name is not used
|
913
|
-
*
|
914
|
-
*/
|
915
|
-
const useFlowerForm = ({ flowName: customFlowName, name } = {}) => {
|
916
|
-
const { flowName: flowNameDefault } = React.useContext(context);
|
917
|
-
const dispatch = useDispatch();
|
918
|
-
const store = useStore();
|
919
|
-
const flowName = customFlowName || name || flowNameDefault || '';
|
920
|
-
const currentNode = useSelector(makeSelectCurrentNodeId(flowName));
|
921
|
-
const { errors, customErrors, isValid, isSubmitted, isDirty, hasFocus, isValidating } = useSelector(makeSelectNodeErrors(flowName, currentNode));
|
922
|
-
const getData = React.useCallback((path) => {
|
923
|
-
const { flowNameFromPath = flowName, path: newpath } = flowerCore.CoreUtils.getPath(path);
|
924
|
-
return _get(store.getState(), [
|
925
|
-
'flower',
|
926
|
-
flowNameFromPath,
|
927
|
-
'data',
|
928
|
-
...newpath
|
929
|
-
]);
|
930
|
-
}, [store, flowName]);
|
931
|
-
const getFormStatus = React.useCallback((path) => {
|
932
|
-
const { flowNameFromPath = flowName, path: newpath } = flowerCore.CoreUtils.getPath(path);
|
933
|
-
return _get(store.getState(), [
|
934
|
-
'flower',
|
935
|
-
flowNameFromPath,
|
936
|
-
'form',
|
937
|
-
...newpath
|
938
|
-
]);
|
939
|
-
}, [store, flowName]);
|
940
|
-
const setDataField = React.useCallback((id, val, dirty = true) => {
|
941
|
-
const { flowNameFromPath = flowName } = flowerCore.CoreUtils.getPath(id);
|
942
|
-
dispatch(actions.addDataByPath({
|
943
|
-
flowName: flowNameFromPath,
|
944
|
-
id,
|
945
|
-
value: val,
|
946
|
-
dirty
|
947
|
-
}));
|
948
|
-
return;
|
949
|
-
}, [flowName, dispatch]);
|
950
|
-
const setData = React.useCallback((val, id) => {
|
951
|
-
if (id) {
|
952
|
-
setDataField(id, val);
|
953
|
-
return;
|
530
|
+
const _FlowerRoute = ({ autostart = true, children, onEnter, onExit }) => {
|
531
|
+
const dispatch = flowerReactStore.useDispatch();
|
532
|
+
const one = React.useRef(false);
|
533
|
+
const { name } = React.useContext(flowerReactContext.FlowerReactContext);
|
534
|
+
React.useEffect(() => {
|
535
|
+
onEnter?.();
|
536
|
+
return () => {
|
537
|
+
onExit?.();
|
538
|
+
};
|
539
|
+
}, [onEnter, onExit]);
|
540
|
+
React.useEffect(() => {
|
541
|
+
if (autostart && one.current === false) {
|
542
|
+
one.current = true;
|
543
|
+
dispatch(flowerActions.next({ flowName: name }));
|
954
544
|
}
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
const reset = React.useCallback((nodeId) => {
|
965
|
-
dispatch(actions.resetForm({ flowName, id: nodeId || currentNode }));
|
966
|
-
}, [flowName, currentNode, dispatch]);
|
967
|
-
const setCustomErrors = React.useCallback((field, errors, nodeId) => {
|
968
|
-
dispatch({
|
969
|
-
type: 'flower/formAddCustomErrors',
|
970
|
-
payload: {
|
971
|
-
name: flowName,
|
972
|
-
id: field,
|
973
|
-
currentNode: nodeId || currentNode,
|
974
|
-
errors
|
975
|
-
}
|
976
|
-
});
|
977
|
-
}, [flowName, currentNode, dispatch]);
|
978
|
-
return {
|
979
|
-
isSubmitted,
|
980
|
-
isDirty,
|
981
|
-
hasFocus,
|
982
|
-
errors,
|
983
|
-
customErrors,
|
984
|
-
isValid,
|
985
|
-
isValidating,
|
986
|
-
getData,
|
987
|
-
setData,
|
988
|
-
setDataField,
|
989
|
-
unsetData,
|
990
|
-
replaceData,
|
991
|
-
reset,
|
992
|
-
setCustomErrors,
|
993
|
-
getFormStatus
|
994
|
-
};
|
545
|
+
}, [dispatch, name, autostart]);
|
546
|
+
return React.createElement(React.Fragment, null, children);
|
547
|
+
};
|
548
|
+
const component$2 = React.memo(_FlowerRoute);
|
549
|
+
component$2.displayName = 'FlowerRoute';
|
550
|
+
const FlowerRoute = component$2;
|
551
|
+
|
552
|
+
const _FlowerServer = ({ children }) => {
|
553
|
+
return React.createElement(React.Fragment, null, children);
|
995
554
|
};
|
555
|
+
const component$1 = React.memo(_FlowerServer);
|
556
|
+
component$1.displayName = 'FlowerServer';
|
557
|
+
const FlowerServer = component$1;
|
558
|
+
|
559
|
+
function _FlowerStart() {
|
560
|
+
const dispatch = flowerReactStore.useDispatch();
|
561
|
+
const one = React.useRef(false);
|
562
|
+
const { name, autostart = true, currentNode } = React.useContext(flowerReactContext.FlowerReactContext);
|
563
|
+
const startNodeId = flowerReactStore.useSelector(makeSelectStartNodeId(name ?? ''));
|
564
|
+
React.useEffect(() => {
|
565
|
+
if (startNodeId === currentNode && autostart && one.current === false) {
|
566
|
+
one.current = true;
|
567
|
+
dispatch(flowerActions.next({ flowName: name, isStart: true }));
|
568
|
+
// if (global.window
|
569
|
+
// // eslint-disable-next-line no-underscore-dangle, no-undef
|
570
|
+
// && global.window.__FLOWER_DEVTOOLS__ && global.window.__FLOWER_DEVTOOLS__AUTO) {
|
571
|
+
// Emitter.emit('flower-devtool-from-client', {
|
572
|
+
// source: 'flower-client',
|
573
|
+
// action: 'START_FLOWER',
|
574
|
+
// name: flowName,
|
575
|
+
// });
|
576
|
+
// }
|
577
|
+
}
|
578
|
+
}, [dispatch, autostart, startNodeId, currentNode, name]);
|
579
|
+
return null;
|
580
|
+
}
|
581
|
+
const component = React.memo(_FlowerStart);
|
582
|
+
component.displayName = 'FlowerStart';
|
583
|
+
const FlowerStart = component;
|
584
|
+
|
585
|
+
const FlowerProvider = ({ children, enableReduxDevtool, configureStoreOptions, reducers }) => (React.createElement(flowerReactStore.ReduxFlowerProvider, { reducer: { ...reducerFlower, ...(reducers ?? {}) }, config: {
|
586
|
+
...configureStoreOptions,
|
587
|
+
devTools: enableReduxDevtool ?? configureStoreOptions?.devTools
|
588
|
+
} }, children));
|
996
589
|
|
997
|
-
exports
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
exports
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
exports
|
1006
|
-
|
590
|
+
Object.defineProperty(exports, "useDispatch", {
|
591
|
+
enumerable: true,
|
592
|
+
get: function () { return flowerReactStore.useDispatch; }
|
593
|
+
});
|
594
|
+
Object.defineProperty(exports, "useSelector", {
|
595
|
+
enumerable: true,
|
596
|
+
get: function () { return flowerReactStore.useSelector; }
|
597
|
+
});
|
598
|
+
Object.defineProperty(exports, "useStore", {
|
599
|
+
enumerable: true,
|
600
|
+
get: function () { return flowerReactStore.useStore; }
|
601
|
+
});
|
602
|
+
exports.Flower = Flower;
|
603
|
+
exports.FlowerAction = FlowerAction;
|
604
|
+
exports.FlowerComponent = FlowerComponent;
|
605
|
+
exports.FlowerFlow = FlowerFlow;
|
606
|
+
exports.FlowerNavigate = FlowerNavigate;
|
607
|
+
exports.FlowerNode = FlowerNode;
|
1007
608
|
exports.FlowerProvider = FlowerProvider;
|
1008
|
-
exports.FlowerRoute =
|
1009
|
-
exports.
|
1010
|
-
exports.
|
1011
|
-
exports.
|
1012
|
-
exports.FlowerValue = component$3;
|
1013
|
-
exports.getDataByFlow = getDataByFlow;
|
609
|
+
exports.FlowerRoute = FlowerRoute;
|
610
|
+
exports.FlowerServer = FlowerServer;
|
611
|
+
exports.FlowerStart = FlowerStart;
|
612
|
+
exports.makeSelectFormData = makeSelectFormData;
|
1014
613
|
exports.useFlower = useFlower;
|
1015
|
-
exports.
|
1016
|
-
exports.useSelector = useSelector;
|
614
|
+
exports.useFlowerNavigate = useFlowerNavigate;
|