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