@flowerforce/flower-react 3.5.1-beta.2 → 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 -630
- package/dist/index.esm.js +184 -604
- 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,388 +252,28 @@ const FlowAction = ({ children, onEnter, onExit }) => {
|
|
287
252
|
onExit?.();
|
288
253
|
};
|
289
254
|
}, [onEnter, onExit]);
|
290
|
-
return children;
|
255
|
+
return React.createElement(React.Fragment, null, children);
|
291
256
|
};
|
292
|
-
const component$
|
293
|
-
component$
|
257
|
+
const component$8 = React.memo(FlowAction);
|
258
|
+
component$8.displayName = 'FlowerAction';
|
259
|
+
const FlowerAction = component$8;
|
294
260
|
|
295
|
-
const
|
296
|
-
|
297
|
-
|
298
|
-
const component$9 = React.memo(FlowerServer);
|
299
|
-
component$9.displayName = 'FlowerServer';
|
261
|
+
const _FlowerComponent = ({ children }) => children;
|
262
|
+
const component$7 = memo(_FlowerComponent);
|
263
|
+
const FlowerComponent = component$7;
|
300
264
|
|
301
|
-
const
|
265
|
+
const _FlowerFlow = ({ children, onEnter, onExit }) => {
|
302
266
|
useEffect(() => {
|
303
267
|
onEnter?.();
|
304
268
|
return () => {
|
305
269
|
onExit?.();
|
306
270
|
};
|
307
271
|
}, [onEnter, onExit]);
|
308
|
-
return children;
|
309
|
-
};
|
310
|
-
const component$8 = React.memo(FlowerFlow);
|
311
|
-
component$8.displayName = 'FlowerFlow';
|
312
|
-
|
313
|
-
function FlowerStart() {
|
314
|
-
const dispatch = useDispatch();
|
315
|
-
const one = useRef(false);
|
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';
|
337
|
-
|
338
|
-
const FlowerRoute = ({ autostart = true, children, onEnter, onExit }) => {
|
339
|
-
const dispatch = useDispatch();
|
340
|
-
const one = useRef(false);
|
341
|
-
const { flowName } = useContext(context);
|
342
|
-
useEffect(() => {
|
343
|
-
onEnter?.();
|
344
|
-
return () => {
|
345
|
-
onExit?.();
|
346
|
-
};
|
347
|
-
}, [onEnter, onExit]);
|
348
|
-
useEffect(() => {
|
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
|
-
});
|
272
|
+
return React.createElement(React.Fragment, null, children);
|
400
273
|
};
|
401
|
-
const component$
|
402
|
-
component$
|
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
|
-
const resetField = useCallback(() => {
|
524
|
-
dispatch({
|
525
|
-
type: 'flower/formFieldTouch',
|
526
|
-
payload: {
|
527
|
-
name: flowName,
|
528
|
-
id,
|
529
|
-
currentNode,
|
530
|
-
touched: false
|
531
|
-
}
|
532
|
-
});
|
533
|
-
dispatch({
|
534
|
-
type: 'flower/formFieldDirty',
|
535
|
-
payload: {
|
536
|
-
name: flowName,
|
537
|
-
id,
|
538
|
-
currentNode,
|
539
|
-
dirty: false
|
540
|
-
}
|
541
|
-
});
|
542
|
-
dispatch({
|
543
|
-
type: 'flower/formRemoveErrors',
|
544
|
-
payload: {
|
545
|
-
name: flowName,
|
546
|
-
id,
|
547
|
-
currentNode
|
548
|
-
}
|
549
|
-
});
|
550
|
-
}, [currentNode, id, flowName]);
|
551
|
-
useEffect(() => {
|
552
|
-
// destroy
|
553
|
-
return () => {
|
554
|
-
if (destroyValue) {
|
555
|
-
dispatch({
|
556
|
-
type: `flower/unsetData`,
|
557
|
-
payload: { flowName: flowNameFromPath, id: path }
|
558
|
-
});
|
559
|
-
}
|
560
|
-
resetField();
|
561
|
-
};
|
562
|
-
}, [destroyValue, id, flowNameFromPath, path, resetField]);
|
563
|
-
useEffect(() => {
|
564
|
-
if (hidden) {
|
565
|
-
if (destroyOnHide) {
|
566
|
-
dispatch({
|
567
|
-
type: `flower/unsetData`,
|
568
|
-
payload: { flowName: flowNameFromPath, id: path }
|
569
|
-
});
|
570
|
-
resetField();
|
571
|
-
}
|
572
|
-
}
|
573
|
-
}, [destroyOnHide, hidden, flowNameFromPath, path, resetField]);
|
574
|
-
useEffect(() => {
|
575
|
-
if (defaultValue && !dirty && !isEqual(value, defaultValue)) {
|
576
|
-
onChange(defaultValue);
|
577
|
-
}
|
578
|
-
}, [defaultValue, value, dirty, onChange]);
|
579
|
-
const newProps = useMemo(() => ({
|
580
|
-
...props,
|
581
|
-
id,
|
582
|
-
value,
|
583
|
-
errors: allErrors,
|
584
|
-
hasError: !!allErrors.length,
|
585
|
-
onChange,
|
586
|
-
onBlur: onBlurInternal,
|
587
|
-
onFocus: onFocusInternal,
|
588
|
-
focused: !!focused,
|
589
|
-
touched,
|
590
|
-
dirty,
|
591
|
-
hidden,
|
592
|
-
isValidating,
|
593
|
-
isSubmitted,
|
594
|
-
}), [
|
595
|
-
props,
|
596
|
-
id,
|
597
|
-
value,
|
598
|
-
allErrors,
|
599
|
-
touched,
|
600
|
-
dirty,
|
601
|
-
onChange,
|
602
|
-
onBlurInternal,
|
603
|
-
onFocusInternal,
|
604
|
-
hidden,
|
605
|
-
isValidating,
|
606
|
-
isSubmitted,
|
607
|
-
focused
|
608
|
-
]);
|
609
|
-
if (typeof Component === 'function') {
|
610
|
-
return Component(newProps);
|
611
|
-
}
|
612
|
-
// TODO si arriva in questa condizione quando si passa un componente primitivo es. div
|
613
|
-
// in questo caso non posso props custom di flower
|
614
|
-
if (isIntrinsicElement$1(Component)) {
|
615
|
-
return React.createElement(Component, { id: id, ...props });
|
616
|
-
}
|
617
|
-
return Component && React.createElement(Component, { ...newProps });
|
618
|
-
}
|
619
|
-
const FlowerField = ({ id, validate, asyncValidate, asyncDebounce, asyncInitialError, asyncWaitingError, rules, alwaysDisplay, value, children, defaultValue, destroyOnHide, destroyValue, flowName, onUpdate }) => {
|
620
|
-
const { flowName: flowNameContext, currentNode } = useContext(context);
|
621
|
-
const name = flowName || flowNameContext;
|
622
|
-
if (typeof children === 'function') {
|
623
|
-
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 }))));
|
624
|
-
}
|
625
|
-
return React.Children.map(children, (child, i) => {
|
626
|
-
if (!React.isValidElement(child)) {
|
627
|
-
return child;
|
628
|
-
}
|
629
|
-
const { type, props } = child;
|
630
|
-
const Component = type;
|
631
|
-
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 }))));
|
632
|
-
});
|
633
|
-
};
|
634
|
-
const component$4 = React.memo(FlowerField);
|
635
|
-
component$4.displayName = 'FlowerField';
|
636
|
-
|
637
|
-
/* eslint-disable */
|
638
|
-
//TODO make types for wrapper function
|
639
|
-
function Wrapper({ Component, id, flowName, spreadValue, hidden, onUpdate, ...props }) {
|
640
|
-
const { flowNameFromPath = flowName, path } = useMemo(() => CoreUtils.getPath(id), [id]);
|
641
|
-
const value = useSelector(getDataFromState(flowNameFromPath, path));
|
642
|
-
const values = spreadValue && typeof value === 'object' && !Array.isArray(value)
|
643
|
-
? value
|
644
|
-
: { value };
|
645
|
-
useEffect(() => {
|
646
|
-
if (onUpdate) {
|
647
|
-
onUpdate(value);
|
648
|
-
}
|
649
|
-
}, [onUpdate, value]);
|
650
|
-
return (React.createElement(Component, { id: id, ...props, flowName: flowName, hidden: hidden, ...values }));
|
651
|
-
}
|
652
|
-
const RenderRules$1 = ({ id, alwaysDisplay, rules, value, Component, spreadValue, flowName, onUpdate, ...props }) => {
|
653
|
-
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 }))));
|
654
|
-
};
|
655
|
-
const FlowerValue = ({ id = '*', rules, alwaysDisplay, value, children, spreadValue, flowName, onUpdate, }) => {
|
656
|
-
const { flowName: flowNameContext } = useContext(context);
|
657
|
-
const name = flowName || flowNameContext;
|
658
|
-
if (typeof children === 'function') {
|
659
|
-
return (React.createElement(RenderRules$1, { id: id, alwaysDisplay: alwaysDisplay, rules: rules, value: value, spreadValue: spreadValue, Component: children, flowName: name, onUpdate: onUpdate }));
|
660
|
-
}
|
661
|
-
return React.Children.map(children, (child, i) => {
|
662
|
-
if (!React.isValidElement(child))
|
663
|
-
return child;
|
664
|
-
const { type, props } = child;
|
665
|
-
const Component = type;
|
666
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
667
|
-
return (React.createElement(RenderRules$1, { key: i, id: id, alwaysDisplay: alwaysDisplay, rules: rules, value: value, spreadValue: spreadValue, flowName: name, Component: Component, ...props, onUpdate: onUpdate }));
|
668
|
-
});
|
669
|
-
};
|
670
|
-
const component$3 = React.memo(FlowerValue);
|
671
|
-
component$3.displayName = 'FlowerValue';
|
274
|
+
const component$6 = React.memo(_FlowerFlow);
|
275
|
+
component$6.displayName = 'FlowerFlow';
|
276
|
+
const FlowerFlow = component$6;
|
672
277
|
|
673
278
|
const ACTION_TYPES = {
|
674
279
|
back: ['prev', 'prevToNode'],
|
@@ -677,10 +282,10 @@ const ACTION_TYPES = {
|
|
677
282
|
restart: ['restart', 'restart'],
|
678
283
|
reset: ['reset', 'initializeFromNode']
|
679
284
|
};
|
680
|
-
const
|
285
|
+
const PAYLOAD_KEYS_NEEDED = {
|
681
286
|
back: ['node'],
|
682
287
|
jump: ['node', 'history'],
|
683
|
-
next: ['node', 'route', 'data'],
|
288
|
+
next: ['node', 'route', 'data', 'dataIn'],
|
684
289
|
restart: ['node'],
|
685
290
|
reset: ['node', 'initialData']
|
686
291
|
};
|
@@ -696,11 +301,11 @@ const makeActionPayload = (actions, keys) => (flowName, params) => {
|
|
696
301
|
payload
|
697
302
|
};
|
698
303
|
};
|
699
|
-
const makeActionPayloadOnPrev = makeActionPayload(ACTION_TYPES.back,
|
700
|
-
const makeActionPayloadOnReset = makeActionPayload(ACTION_TYPES.reset,
|
701
|
-
const makeActionPayloadOnNode = makeActionPayload(ACTION_TYPES.jump,
|
702
|
-
const makeActionPayloadOnNext = makeActionPayload(ACTION_TYPES.next,
|
703
|
-
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);
|
704
309
|
/** This hook allows you to read flow informations, such as the flowName and ID of the current node.
|
705
310
|
*
|
706
311
|
* It also exposes all the functions to navigate within the flow:
|
@@ -721,7 +326,7 @@ const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart, PAYLA
|
|
721
326
|
*/
|
722
327
|
const useFlower = ({ flowName: customFlowName, name } = {}) => {
|
723
328
|
const dispatch = useDispatch();
|
724
|
-
const {
|
329
|
+
const { name: flowNameDefault, initialData } = useContext(FlowerReactContext);
|
725
330
|
const store = useStore();
|
726
331
|
const flowName = (customFlowName || name || flowNameDefault);
|
727
332
|
const nodeId = useSelector(makeSelectCurrentNodeId(flowName ?? ''));
|
@@ -743,22 +348,25 @@ const useFlower = ({ flowName: customFlowName, name } = {}) => {
|
|
743
348
|
}
|
744
349
|
}, [flowName, nodeId]);
|
745
350
|
const next = useCallback((param) => {
|
746
|
-
const params = typeof param === 'string' ? { route: param } : {
|
351
|
+
const params = typeof param === 'string' ? { route: param } : { dataIn: param };
|
747
352
|
const { type, payload } = makeActionPayloadOnNext(flowName, params);
|
748
353
|
dispatch({
|
749
|
-
type:
|
750
|
-
payload
|
354
|
+
type: `${REDUCER_NAME.FLOWER_FLOW}/${type}`,
|
355
|
+
payload: {
|
356
|
+
...payload,
|
357
|
+
data: store.getState()
|
358
|
+
}
|
751
359
|
});
|
752
360
|
emitNavigateEvent({ type, payload });
|
753
|
-
}, [dispatch, emitNavigateEvent, flowName]);
|
361
|
+
}, [dispatch, emitNavigateEvent, flowName, store]);
|
754
362
|
const back = useCallback((param) => {
|
755
363
|
const { type, payload } = makeActionPayloadOnPrev(flowName, param);
|
756
|
-
dispatch({ type:
|
364
|
+
dispatch({ type: `${REDUCER_NAME.FLOWER_FLOW}/${type}`, payload });
|
757
365
|
emitNavigateEvent({ type, payload });
|
758
366
|
}, [dispatch, emitNavigateEvent, flowName]);
|
759
367
|
const restart = useCallback((param) => {
|
760
368
|
const { type, payload } = makeActionPayloadOnRestart(flowName, param);
|
761
|
-
dispatch({ type:
|
369
|
+
dispatch({ type: `${REDUCER_NAME.FLOWER_FLOW}/${type}`, payload });
|
762
370
|
emitNavigateEvent({ type, payload });
|
763
371
|
}, [dispatch, emitNavigateEvent, flowName]);
|
764
372
|
const reset = useCallback((param) => {
|
@@ -768,17 +376,17 @@ const useFlower = ({ flowName: customFlowName, name } = {}) => {
|
|
768
376
|
...param,
|
769
377
|
initialData
|
770
378
|
});
|
771
|
-
dispatch({ type:
|
379
|
+
dispatch({ type: `${REDUCER_NAME.FLOWER_FLOW}/${type}`, payload });
|
772
380
|
emitNavigateEvent({ type, payload });
|
773
381
|
}, [dispatch, emitNavigateEvent, flowName, initialData]);
|
774
382
|
const jump = useCallback((param) => {
|
775
383
|
const { type, payload } = makeActionPayloadOnNode(flowName, param);
|
776
|
-
dispatch({ type:
|
384
|
+
dispatch({ type: `${REDUCER_NAME.FLOWER_FLOW}/${type}`, payload });
|
777
385
|
emitNavigateEvent({ type, payload });
|
778
386
|
}, [dispatch, emitNavigateEvent, flowName]);
|
779
387
|
const getCurrentNodeId = useCallback((customFlowName) => {
|
780
388
|
return _get(store.getState(), [
|
781
|
-
|
389
|
+
REDUCER_NAME.FLOWER_FLOW,
|
782
390
|
customFlowName || flowName,
|
783
391
|
'current'
|
784
392
|
]);
|
@@ -819,7 +427,7 @@ const useFlower = ({ flowName: customFlowName, name } = {}) => {
|
|
819
427
|
// }
|
820
428
|
// );
|
821
429
|
const useFlowerNavigate = ({ flowName, action, route, node }) => {
|
822
|
-
const {
|
430
|
+
const { name: flowNameContext } = useContext(FlowerReactContext);
|
823
431
|
const name = flowName || flowNameContext;
|
824
432
|
const { next, jump, back, reset, restart } = useFlower({ flowName: name });
|
825
433
|
const onNavigate = useCallback(() => {
|
@@ -855,7 +463,7 @@ function isIntrinsicElement(x) {
|
|
855
463
|
return typeof x === 'string';
|
856
464
|
}
|
857
465
|
//TODO type FlowerNavigateWrapper props
|
858
|
-
function
|
466
|
+
function _FlowerNavigateWrapper({ hidden, Component, onNavigate, ...props }) {
|
859
467
|
const newProps = useMemo(() => ({
|
860
468
|
...props,
|
861
469
|
hidden,
|
@@ -874,136 +482,108 @@ function FlowerNavigateWrapper({ hidden, Component, onNavigate, ...props }) {
|
|
874
482
|
/* istanbul ignore next */
|
875
483
|
return Component && React.createElement(Component, { ...newProps });
|
876
484
|
}
|
877
|
-
const component$
|
485
|
+
const component$5 = React.memo(_FlowerNavigateWrapper);
|
486
|
+
const FlowerNavigateWrapper = component$5;
|
878
487
|
|
879
488
|
/* eslint-disable */
|
880
489
|
//TODO type RenderRules props
|
490
|
+
// ! Probably in this scenario we must replace `FlowerRule` or refactor `FlowerNavigate`
|
881
491
|
const RenderRules = ({ alwaysDisplay, rules, Component, flowName, onNavigate, ...props }) => {
|
882
|
-
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 }))));
|
883
493
|
};
|
884
|
-
const
|
885
|
-
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
|
+
});
|
886
501
|
if (typeof children === 'function') {
|
887
|
-
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 }));
|
888
503
|
}
|
889
|
-
return React.Children.map(children, (child, i) => {
|
504
|
+
return (React.createElement(React.Fragment, null, React.Children.map(children, (child, i) => {
|
890
505
|
if (!React.isValidElement(child))
|
891
506
|
return child;
|
892
507
|
const { type, props } = child;
|
893
508
|
const Component = type;
|
894
|
-
|
895
|
-
|
896
|
-
});
|
509
|
+
return (React.createElement(RenderRules, { key: i, alwaysDisplay: alwaysDisplay, rules: rules, Component: Component, flowName: flowName, onNavigate: onNavigate, ...props }));
|
510
|
+
})));
|
897
511
|
};
|
898
|
-
const component$
|
899
|
-
component$
|
512
|
+
const component$4 = React.memo(_FlowerNavigate);
|
513
|
+
component$4.displayName = 'FlowerNavigate';
|
514
|
+
const FlowerNavigate = component$4;
|
900
515
|
|
901
|
-
const
|
902
|
-
|
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;
|
903
528
|
|
904
|
-
|
905
|
-
*
|
906
|
-
* It exposes details regarding the form's state and a set of methods for reading and writing within it:
|
907
|
-
*
|
908
|
-
* - isSubmitted,
|
909
|
-
* - isDirty,
|
910
|
-
* - errors,
|
911
|
-
* - customErrors,
|
912
|
-
* - isValid,
|
913
|
-
* - isValidating,
|
914
|
-
* - getData,
|
915
|
-
* - setData,
|
916
|
-
* - unsetData,
|
917
|
-
* - replaceData,
|
918
|
-
* - reset,
|
919
|
-
* - setCustomErrors
|
920
|
-
* - getFormStatus
|
921
|
-
*
|
922
|
-
* @param {string} flowName - first optional parameter
|
923
|
-
*
|
924
|
-
* @param {string} name - alias optional parameter, if flowName exist, name is not used
|
925
|
-
*
|
926
|
-
*/
|
927
|
-
const useFlowerForm = ({ flowName: customFlowName, name } = {}) => {
|
928
|
-
const { flowName: flowNameDefault } = useContext(context);
|
529
|
+
const _FlowerRoute = ({ autostart = true, children, onEnter, onExit }) => {
|
929
530
|
const dispatch = useDispatch();
|
930
|
-
const
|
931
|
-
const
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
}, [store, flowName]);
|
943
|
-
const getFormStatus = useCallback((path) => {
|
944
|
-
const { flowNameFromPath = flowName, path: newpath } = CoreUtils.getPath(path);
|
945
|
-
return _get(store.getState(), [
|
946
|
-
'flower',
|
947
|
-
flowNameFromPath,
|
948
|
-
'form',
|
949
|
-
...newpath
|
950
|
-
]);
|
951
|
-
}, [store, flowName]);
|
952
|
-
const setDataField = useCallback((id, val, dirty = true) => {
|
953
|
-
const { flowNameFromPath = flowName } = CoreUtils.getPath(id);
|
954
|
-
dispatch(actions.addDataByPath({
|
955
|
-
flowName: flowNameFromPath,
|
956
|
-
id,
|
957
|
-
value: val,
|
958
|
-
dirty
|
959
|
-
}));
|
960
|
-
return;
|
961
|
-
}, [flowName, dispatch]);
|
962
|
-
const setData = useCallback((val, id) => {
|
963
|
-
if (id) {
|
964
|
-
setDataField(id, val);
|
965
|
-
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 }));
|
966
543
|
}
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
const reset = useCallback((nodeId) => {
|
977
|
-
dispatch(actions.resetForm({ flowName, id: nodeId || currentNode }));
|
978
|
-
}, [flowName, currentNode, dispatch]);
|
979
|
-
const setCustomErrors = useCallback((field, errors, nodeId) => {
|
980
|
-
dispatch({
|
981
|
-
type: 'flower/formAddCustomErrors',
|
982
|
-
payload: {
|
983
|
-
name: flowName,
|
984
|
-
id: field,
|
985
|
-
currentNode: nodeId || currentNode,
|
986
|
-
errors
|
987
|
-
}
|
988
|
-
});
|
989
|
-
}, [flowName, currentNode, dispatch]);
|
990
|
-
return {
|
991
|
-
isSubmitted,
|
992
|
-
isDirty,
|
993
|
-
hasFocus,
|
994
|
-
errors,
|
995
|
-
customErrors,
|
996
|
-
isValid,
|
997
|
-
isValidating,
|
998
|
-
getData,
|
999
|
-
setData,
|
1000
|
-
setDataField,
|
1001
|
-
unsetData,
|
1002
|
-
replaceData,
|
1003
|
-
reset,
|
1004
|
-
setCustomErrors,
|
1005
|
-
getFormStatus
|
1006
|
-
};
|
544
|
+
}, [dispatch, name, autostart]);
|
545
|
+
return React.createElement(React.Fragment, null, children);
|
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);
|
1007
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));
|
1008
588
|
|
1009
|
-
export {
|
589
|
+
export { Flower, FlowerAction, FlowerComponent, FlowerFlow, FlowerNavigate, FlowerNode, FlowerProvider, FlowerRoute, FlowerServer, FlowerStart, makeSelectFormData, useFlower, useFlowerNavigate };
|