@flowerforce/flower-react 3.1.1 → 3.1.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/dist/index.cjs.js +761 -1036
- package/dist/index.esm.js +762 -1037
- package/dist/src/components/Flower.d.ts +7 -1
- package/dist/src/components/types/DefaultNode.d.ts +17 -0
- package/dist/src/components/types/FlowerComponent.d.ts +2 -0
- package/dist/src/components/types/FlowerField.d.ts +78 -0
- package/dist/src/components/types/FlowerFlow.d.ts +10 -0
- package/dist/src/components/types/FlowerHooks.d.ts +25 -2
- package/dist/src/components/types/FlowerNavigate.d.ts +14 -0
- package/dist/src/components/types/FlowerNode.d.ts +10 -0
- package/dist/src/components/types/FlowerRoute.d.ts +17 -0
- package/dist/src/components/types/FlowerRule.d.ts +23 -0
- package/dist/src/components/types/FlowerServer.d.ts +2 -0
- package/dist/src/components/types/FlowerValue.d.ts +22 -0
- package/dist/src/components/useFlower.d.ts +18 -0
- package/dist/src/components/useFlowerForm.d.ts +17 -0
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
@@ -1,49 +1,46 @@
|
|
1
1
|
import React, { createContext, PureComponent, memo, useRef, useState, useMemo, Children, useEffect, useContext, useCallback, useLayoutEffect } from 'react';
|
2
2
|
import _keyBy from 'lodash/keyBy';
|
3
|
-
import { CoreUtils, FlowerCoreReducers, FlowerStateUtils, Selectors, Emitter, MatchRules } from '@flowerforce/flower-core';
|
3
|
+
import { CoreUtils, FlowerCoreReducers, FlowerStateUtils, Selectors, devtoolState, Emitter, MatchRules } from '@flowerforce/flower-core';
|
4
4
|
import _get from 'lodash/get';
|
5
5
|
import { createSlice, configureStore } from '@reduxjs/toolkit';
|
6
6
|
import { createSelector } from 'reselect';
|
7
7
|
import { createDispatchHook, createSelectorHook, createStoreHook, Provider as Provider$1 } from 'react-redux';
|
8
8
|
import debounce from 'lodash/debounce';
|
9
9
|
|
10
|
-
const _context =
|
10
|
+
const _context = createContext({});
|
11
11
|
const context = _context;
|
12
12
|
const Provider = _context.Provider;
|
13
13
|
const Consumer = _context.Consumer;
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
// eslint-disable-next-line import/prefer-default-export
|
16
|
+
const convertElements = (nodes) => {
|
17
|
+
const res = CoreUtils.generateNodesForFlowerJson(nodes);
|
18
|
+
return res;
|
18
19
|
};
|
19
20
|
|
20
21
|
const flowerReducer = createSlice({
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
name: 'flower',
|
23
|
+
initialState: {},
|
24
|
+
reducers: FlowerCoreReducers
|
24
25
|
});
|
25
|
-
const {
|
26
|
-
actions
|
27
|
-
} = flowerReducer;
|
26
|
+
const { actions } = flowerReducer;
|
28
27
|
const reducerFlower = {
|
29
|
-
|
28
|
+
flower: flowerReducer.reducer
|
30
29
|
};
|
31
30
|
|
32
|
-
const {
|
33
|
-
|
34
|
-
|
35
|
-
const {
|
36
|
-
selectGlobal
|
37
|
-
} = Selectors;
|
38
|
-
const selectFlower = name => createSelector(selectGlobal, Selectors.selectFlower(name));
|
31
|
+
const { getAllData: mapData } = FlowerStateUtils;
|
32
|
+
const { selectGlobal } = Selectors;
|
33
|
+
const selectFlower = (name) => createSelector(selectGlobal, Selectors.selectFlower(name));
|
39
34
|
const selectFlowerFormNode = (name, id) => createSelector(selectFlower(name), Selectors.selectFlowerFormNode(id));
|
40
|
-
const selectFlowerHistory = name => createSelector(selectFlower(name), Selectors.selectFlowerHistory);
|
41
|
-
const makeSelectNodesIds = name => createSelector(selectFlower(name), Selectors.makeSelectNodesIds);
|
42
|
-
const makeSelectStartNodeId = name => createSelector(selectFlower(name), Selectors.makeSelectStartNodeId);
|
43
|
-
const makeSelectCurrentNodeId = name => createSelector(selectFlower(name), makeSelectStartNodeId(name), Selectors.makeSelectCurrentNodeId);
|
44
|
-
const makeSelectPrevNodeRetain = name => createSelector(makeSelectNodesIds(name), selectFlowerHistory(name), makeSelectCurrentNodeId(name), Selectors.makeSelectPrevNodeRetain);
|
45
|
-
const makeSelectCurrentNodeDisabled = name => createSelector(makeSelectNodesIds(name), makeSelectCurrentNodeId(name), Selectors.makeSelectCurrentNodeDisabled);
|
46
|
-
|
35
|
+
const selectFlowerHistory = (name) => createSelector(selectFlower(name), Selectors.selectFlowerHistory);
|
36
|
+
const makeSelectNodesIds = (name) => createSelector(selectFlower(name), Selectors.makeSelectNodesIds);
|
37
|
+
const makeSelectStartNodeId = (name) => createSelector(selectFlower(name), Selectors.makeSelectStartNodeId);
|
38
|
+
const makeSelectCurrentNodeId = (name) => createSelector(selectFlower(name), makeSelectStartNodeId(name), Selectors.makeSelectCurrentNodeId);
|
39
|
+
const makeSelectPrevNodeRetain = (name) => createSelector(makeSelectNodesIds(name), selectFlowerHistory(name), makeSelectCurrentNodeId(name), Selectors.makeSelectPrevNodeRetain);
|
40
|
+
const makeSelectCurrentNodeDisabled = (name) => createSelector(makeSelectNodesIds(name), makeSelectCurrentNodeId(name), Selectors.makeSelectCurrentNodeDisabled);
|
41
|
+
// dati nel flow selezionato
|
42
|
+
const getDataByFlow = (name) => createSelector(selectFlower(name), Selectors.getDataByFlow);
|
43
|
+
// selettore per recuperare i dati di un flow specifico e id specifico
|
47
44
|
const getDataFromState = (name, id) => createSelector(getDataByFlow(name), Selectors.getDataFromState(id));
|
48
45
|
const makeSelectNodeErrors = (name, currentNodeId) => createSelector(selectFlowerFormNode(name, currentNodeId), Selectors.makeSelectNodeErrors);
|
49
46
|
const makeSelectNodeFormTouched = (name, currentNodeId) => createSelector(selectFlowerFormNode(name, currentNodeId), Selectors.makeSelectNodeFormTouched);
|
@@ -51,1101 +48,829 @@ const getAllData = createSelector(selectGlobal, mapData);
|
|
51
48
|
const makeSelectFieldError = (name, id, validate) => createSelector(getAllData, Selectors.makeSelectFieldError(name, id, validate));
|
52
49
|
const selectorRulesDisabled = (id, rules, keys, flowName, value, currentNode) => createSelector(getAllData, makeSelectNodeErrors(flowName, currentNode), Selectors.selectorRulesDisabled(id, rules, keys, flowName, value));
|
53
50
|
|
54
|
-
|
51
|
+
//TODO check reduxContext type due to remove all any types
|
52
|
+
const reduxContext = createContext(null);
|
55
53
|
const useDispatch = createDispatchHook(reduxContext);
|
56
54
|
const useSelector = createSelectorHook(reduxContext);
|
57
55
|
const useStore = createStoreHook(reduxContext);
|
58
|
-
const store = ({
|
59
|
-
|
60
|
-
}
|
61
|
-
reducer: reducerFlower,
|
62
|
-
devTools: enableDevtool ? {
|
63
|
-
name: 'flower'
|
64
|
-
} : false
|
56
|
+
const store = ({ enableDevtool }) => configureStore({
|
57
|
+
reducer: reducerFlower,
|
58
|
+
devTools: enableDevtool ? { name: 'flower' } : false
|
65
59
|
});
|
66
60
|
class FlowerProvider extends PureComponent {
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
children
|
76
|
-
} = this.props;
|
77
|
-
return /*#__PURE__*/React.createElement(Provider$1, {
|
78
|
-
context: reduxContext,
|
79
|
-
store: this.store
|
80
|
-
}, children);
|
81
|
-
}
|
61
|
+
constructor(props) {
|
62
|
+
super(props);
|
63
|
+
this.store = store({ enableDevtool: props.enableReduxDevtool });
|
64
|
+
}
|
65
|
+
render() {
|
66
|
+
const { children } = this.props;
|
67
|
+
return (React.createElement(Provider$1, { context: reduxContext, store: this.store }, children));
|
68
|
+
}
|
82
69
|
}
|
83
70
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
71
|
+
/* eslint-disable no-undef */
|
72
|
+
/* eslint-disable no-underscore-dangle */
|
73
|
+
/**
|
74
|
+
* FlowerClient
|
75
|
+
*/
|
76
|
+
const FlowerClient = ({ children, name, destroyOnUnmount = true, startId = null, initialData = {}, initialState = {} }) => {
|
77
|
+
const flowName = name;
|
78
|
+
const dispatch = useDispatch();
|
79
|
+
const one = useRef(false);
|
80
|
+
const [wsDevtools, setWsDevtools] = useState(devtoolState && _get(devtoolState, '__FLOWER_DEVTOOLS_INITIALIZED__', false));
|
81
|
+
// TODO rivedere il giro, potremmo fare le trasformazioni in CoreUtils.generateNodesForFlowerJson
|
82
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps, max-len
|
83
|
+
const nodes = useMemo(() => convertElements(Children.toArray(children)), [children]);
|
84
|
+
const nodeById = useMemo(() => _keyBy(Children.toArray(children), 'props.id'), [children]);
|
85
|
+
const isInitialized = useSelector(makeSelectStartNodeId(name));
|
86
|
+
const history = useSelector(selectFlowerHistory(name));
|
87
|
+
const current = useSelector(makeSelectCurrentNodeId(flowName));
|
88
|
+
const isDisabled = useSelector(makeSelectCurrentNodeDisabled(flowName));
|
89
|
+
const prevFlowerNodeId = useSelector(makeSelectPrevNodeRetain(flowName));
|
90
|
+
const store = useStore();
|
91
|
+
useEffect(() => {
|
92
|
+
if (nodes.length > 0 && one.current === false) {
|
93
|
+
one.current = true;
|
94
|
+
dispatch(actions.initNodes({
|
95
|
+
name: flowName,
|
96
|
+
// @ts-expect-error FIX ME
|
97
|
+
nodes,
|
98
|
+
startId: startId ?? '',
|
99
|
+
persist: destroyOnUnmount === false,
|
100
|
+
initialData,
|
101
|
+
initialState
|
102
|
+
}));
|
103
|
+
}
|
104
|
+
}, [
|
105
|
+
dispatch,
|
106
|
+
flowName,
|
108
107
|
nodes,
|
109
|
-
startId
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
value: msg.data
|
137
|
-
}));
|
138
|
-
}
|
139
|
-
};
|
140
|
-
if (global.window && _get(global.window, '__FLOWER_DEVTOOLS__')) {
|
141
|
-
Emitter.on('flower-devtool-to-client', eventCb);
|
142
|
-
}
|
143
|
-
return () => {
|
144
|
-
if (global.window && _get(global.window, '__FLOWER_DEVTOOLS__')) {
|
145
|
-
Emitter.off('flower-devtool-to-client', eventCb);
|
146
|
-
}
|
147
|
-
};
|
148
|
-
}, [dispatch, flowName]);
|
149
|
-
useEffect(() => () => {
|
150
|
-
if (_destroyOnUnmount && one.current === true) {
|
151
|
-
one.current = false;
|
152
|
-
dispatch(actions.destroy({
|
153
|
-
name: flowName
|
154
|
-
}));
|
155
|
-
}
|
156
|
-
}, [dispatch, flowName, _destroyOnUnmount]);
|
157
|
-
useEffect(() => {
|
158
|
-
if (isInitialized && wsDevtools && global.window && _get(global.window, '__FLOWER_DEVTOOLS__')) {
|
159
|
-
Emitter.emit('flower-devtool-from-client', {
|
160
|
-
source: 'flower-client',
|
161
|
-
action: 'FLOWER_CLIENT_INIT',
|
162
|
-
name: flowName,
|
163
|
-
time: new Date(),
|
164
|
-
nodeId: isInitialized,
|
165
|
-
getState: store.getState
|
166
|
-
});
|
167
|
-
}
|
168
|
-
}, [dispatch, flowName, wsDevtools, isInitialized, store]);
|
169
|
-
useEffect(() => {
|
170
|
-
if (isInitialized && wsDevtools && global.window && _get(global.window, '__FLOWER_DEVTOOLS__')) {
|
171
|
-
Emitter.emit('flower-devtool-from-client', {
|
172
|
-
source: 'flower-client',
|
173
|
-
action: 'SET_HISTORY',
|
174
|
-
name: flowName,
|
175
|
-
history
|
176
|
-
});
|
177
|
-
}
|
178
|
-
}, [dispatch, flowName, history, wsDevtools, isInitialized]);
|
179
|
-
useEffect(() => {
|
180
|
-
if (!current) return;
|
181
|
-
if (!isInitialized) return;
|
182
|
-
if (isInitialized && wsDevtools && global.window && _get(global.window, '__FLOWER_DEVTOOLS__')) {
|
183
|
-
Emitter.emit('flower-devtool-from-client', {
|
184
|
-
source: 'flower-client',
|
185
|
-
action: 'SET_CURRENT',
|
186
|
-
name: flowName,
|
187
|
-
current
|
188
|
-
});
|
189
|
-
}
|
190
|
-
}, [flowName, current, wsDevtools, isInitialized]);
|
191
|
-
useEffect(() => {
|
192
|
-
if (!current) return;
|
193
|
-
if (!isInitialized) return;
|
194
|
-
if (isDisabled) {
|
195
|
-
dispatch({
|
196
|
-
type: 'flower/next',
|
197
|
-
payload: {
|
198
|
-
flowName,
|
199
|
-
disabled: true
|
108
|
+
startId,
|
109
|
+
initialData,
|
110
|
+
destroyOnUnmount,
|
111
|
+
initialState
|
112
|
+
]);
|
113
|
+
useEffect(() => {
|
114
|
+
/* istanbul ignore next */
|
115
|
+
const eventCb = (msg) => {
|
116
|
+
if (msg.source !== 'flower-devtool')
|
117
|
+
return;
|
118
|
+
if (msg.action === 'FLOWER_EXTENSION_INIT' ||
|
119
|
+
msg.action === 'FLOWER_DEVTOOL_WEB_INIT') {
|
120
|
+
setWsDevtools(true);
|
121
|
+
}
|
122
|
+
if (msg.action === 'SELECTED_NODE' && msg.name === flowName) {
|
123
|
+
dispatch(actions.setCurrentNode({ name: msg.name, node: msg.id }));
|
124
|
+
}
|
125
|
+
if (msg.action === 'REPLACE_DATA' && msg.name === flowName) {
|
126
|
+
dispatch(actions.replaceData({ flowName: msg.name, value: msg.data }));
|
127
|
+
}
|
128
|
+
if (msg.action === 'ADD_DATA' && msg.name === flowName) {
|
129
|
+
dispatch(actions.addData({ flowName: msg.name, value: msg.data }));
|
130
|
+
}
|
131
|
+
};
|
132
|
+
/* istanbul ignore next */
|
133
|
+
if (devtoolState && _get(devtoolState, '__FLOWER_DEVTOOLS__')) {
|
134
|
+
Emitter.on('flower-devtool-to-client', eventCb);
|
200
135
|
}
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
action: 'FLOWER_NAVIGATE',
|
206
|
-
nodeId: current,
|
207
|
-
name: flowName,
|
208
|
-
time: new Date(),
|
209
|
-
params: {
|
210
|
-
action: 'next',
|
211
|
-
payload: {
|
212
|
-
flowName,
|
213
|
-
disabled: true
|
136
|
+
return () => {
|
137
|
+
/* istanbul ignore next */
|
138
|
+
if (devtoolState && _get(devtoolState, '__FLOWER_DEVTOOLS__')) {
|
139
|
+
Emitter.off('flower-devtool-to-client', eventCb);
|
214
140
|
}
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
141
|
+
};
|
142
|
+
}, [dispatch, flowName]);
|
143
|
+
useEffect(() => () => {
|
144
|
+
// unmount function
|
145
|
+
if (destroyOnUnmount && one.current === true) {
|
146
|
+
one.current = false;
|
147
|
+
dispatch(actions.destroy({ name: flowName }));
|
148
|
+
}
|
149
|
+
}, [dispatch, flowName, destroyOnUnmount]);
|
150
|
+
useEffect(() => {
|
151
|
+
/* istanbul ignore next */
|
152
|
+
if (isInitialized &&
|
153
|
+
wsDevtools &&
|
154
|
+
devtoolState &&
|
155
|
+
_get(devtoolState, '__FLOWER_DEVTOOLS__')) {
|
156
|
+
Emitter.emit('flower-devtool-from-client', {
|
157
|
+
source: 'flower-client',
|
158
|
+
action: 'FLOWER_CLIENT_INIT',
|
159
|
+
name: flowName,
|
160
|
+
time: new Date(),
|
161
|
+
nodeId: isInitialized,
|
162
|
+
getState: store.getState
|
163
|
+
});
|
164
|
+
}
|
165
|
+
}, [dispatch, flowName, wsDevtools, isInitialized, store]);
|
166
|
+
useEffect(() => {
|
167
|
+
/* istanbul ignore next */
|
168
|
+
if (isInitialized &&
|
169
|
+
wsDevtools &&
|
170
|
+
devtoolState &&
|
171
|
+
_get(devtoolState, '__FLOWER_DEVTOOLS__')) {
|
172
|
+
Emitter.emit('flower-devtool-from-client', {
|
173
|
+
source: 'flower-client',
|
174
|
+
action: 'SET_HISTORY',
|
175
|
+
name: flowName,
|
176
|
+
history
|
177
|
+
});
|
178
|
+
}
|
179
|
+
}, [dispatch, flowName, history, wsDevtools, isInitialized]);
|
180
|
+
useEffect(() => {
|
181
|
+
if (!current)
|
182
|
+
return;
|
183
|
+
/* istanbul ignore next */
|
184
|
+
if (!isInitialized)
|
185
|
+
return;
|
186
|
+
/* istanbul ignore next */
|
187
|
+
if (isInitialized &&
|
188
|
+
wsDevtools &&
|
189
|
+
devtoolState &&
|
190
|
+
_get(devtoolState, '__FLOWER_DEVTOOLS__')) {
|
191
|
+
Emitter.emit('flower-devtool-from-client', {
|
192
|
+
source: 'flower-client',
|
193
|
+
action: 'SET_CURRENT',
|
194
|
+
name: flowName,
|
195
|
+
current
|
196
|
+
});
|
197
|
+
}
|
198
|
+
}, [flowName, current, wsDevtools, isInitialized]);
|
199
|
+
useEffect(() => {
|
200
|
+
if (!current)
|
201
|
+
return;
|
202
|
+
/* istanbul ignore next */
|
203
|
+
if (!isInitialized)
|
204
|
+
return;
|
205
|
+
if (isDisabled) {
|
206
|
+
dispatch({ type: 'flower/next', payload: { flowName, disabled: true } });
|
207
|
+
// eslint-disable-next-line no-underscore-dangle, no-undef
|
208
|
+
/* istanbul ignore next */
|
209
|
+
if (wsDevtools &&
|
210
|
+
devtoolState &&
|
211
|
+
_get(devtoolState, '__FLOWER_DEVTOOLS__')) {
|
212
|
+
Emitter.emit('flower-devtool-from-client', {
|
213
|
+
source: 'flower-client',
|
214
|
+
action: 'FLOWER_NAVIGATE',
|
215
|
+
nodeId: current,
|
216
|
+
name: flowName,
|
217
|
+
time: new Date(),
|
218
|
+
params: { action: 'next', payload: { flowName, disabled: true } }
|
219
|
+
});
|
220
|
+
}
|
221
|
+
return;
|
222
|
+
}
|
223
|
+
// eslint-disable-next-line no-underscore-dangle, no-undef
|
224
|
+
/* istanbul ignore next */
|
225
|
+
if (wsDevtools &&
|
226
|
+
devtoolState &&
|
227
|
+
_get(devtoolState, '__FLOWER_DEVTOOLS__')) {
|
228
|
+
if (isInitialized === current)
|
229
|
+
return; // salto il primo evento
|
230
|
+
Emitter.emit('flower-devtool-from-client', {
|
231
|
+
source: 'flower-client',
|
232
|
+
action: 'SET_SELECTED',
|
233
|
+
nodeId: current,
|
234
|
+
name: flowName,
|
235
|
+
time: new Date()
|
236
|
+
});
|
237
|
+
}
|
238
|
+
}, [
|
239
|
+
dispatch,
|
240
|
+
flowName,
|
241
|
+
current,
|
242
|
+
isDisabled,
|
243
|
+
store,
|
244
|
+
wsDevtools,
|
245
|
+
isInitialized
|
246
|
+
]);
|
247
|
+
const contextValues = useMemo(() => ({
|
248
|
+
flowName,
|
249
|
+
initialData,
|
250
|
+
currentNode: current
|
251
|
+
}), [flowName, initialData, current]);
|
252
|
+
return isInitialized ? (React.createElement(Provider, { value: contextValues },
|
253
|
+
prevFlowerNodeId !== current &&
|
254
|
+
typeof prevFlowerNodeId === 'string' &&
|
255
|
+
nodeById[prevFlowerNodeId],
|
256
|
+
!isDisabled && nodeById[current])) : null;
|
239
257
|
};
|
240
|
-
const component$c =
|
258
|
+
const component$c = memo(FlowerClient);
|
241
259
|
|
242
|
-
const FlowerNode = ({
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
onEnter
|
249
|
-
return
|
250
|
-
onExit == null || onExit();
|
251
|
-
};
|
252
|
-
}, [onEnter, onExit]);
|
253
|
-
return children;
|
260
|
+
const FlowerNode = ({ children, onEnter, onExit }) => {
|
261
|
+
useEffect(() => {
|
262
|
+
onEnter?.();
|
263
|
+
return () => {
|
264
|
+
onExit?.();
|
265
|
+
};
|
266
|
+
}, [onEnter, onExit]);
|
267
|
+
return children;
|
254
268
|
};
|
255
|
-
const component$b =
|
269
|
+
const component$b = memo(FlowerNode);
|
256
270
|
component$b.displayName = 'FlowerNode';
|
257
271
|
|
258
|
-
const FlowAction = ({
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
onEnter
|
265
|
-
return
|
266
|
-
onExit == null || onExit();
|
267
|
-
};
|
268
|
-
}, [onEnter, onExit]);
|
269
|
-
return children;
|
272
|
+
const FlowAction = ({ children, onEnter, onExit }) => {
|
273
|
+
useEffect(() => {
|
274
|
+
onEnter?.();
|
275
|
+
return () => {
|
276
|
+
onExit?.();
|
277
|
+
};
|
278
|
+
}, [onEnter, onExit]);
|
279
|
+
return children;
|
270
280
|
};
|
271
|
-
const component$a =
|
281
|
+
const component$a = React.memo(FlowAction);
|
272
282
|
component$a.displayName = 'FlowerAction';
|
273
283
|
|
274
|
-
const FlowerServer = ({
|
275
|
-
|
276
|
-
}) => {
|
277
|
-
return children;
|
284
|
+
const FlowerServer = ({ children }) => {
|
285
|
+
return children;
|
278
286
|
};
|
279
|
-
const component$9 =
|
287
|
+
const component$9 = React.memo(FlowerServer);
|
280
288
|
component$9.displayName = 'FlowerServer';
|
281
289
|
|
282
|
-
const FlowerFlow = ({
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
onEnter
|
289
|
-
return
|
290
|
-
onExit == null || onExit();
|
291
|
-
};
|
292
|
-
}, [onEnter, onExit]);
|
293
|
-
return children;
|
290
|
+
const FlowerFlow = ({ children, onEnter, onExit }) => {
|
291
|
+
useEffect(() => {
|
292
|
+
onEnter?.();
|
293
|
+
return () => {
|
294
|
+
onExit?.();
|
295
|
+
};
|
296
|
+
}, [onEnter, onExit]);
|
297
|
+
return children;
|
294
298
|
};
|
295
|
-
const component$8 =
|
299
|
+
const component$8 = React.memo(FlowerFlow);
|
296
300
|
component$8.displayName = 'FlowerFlow';
|
297
301
|
|
298
302
|
function FlowerStart() {
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
flowName
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
303
|
+
const dispatch = useDispatch();
|
304
|
+
const one = useRef(false);
|
305
|
+
const { flowName, autostart = true, currentNode } = useContext(context);
|
306
|
+
const startNodeId = useSelector(makeSelectStartNodeId(flowName ?? ''));
|
307
|
+
useEffect(() => {
|
308
|
+
if (startNodeId === currentNode && autostart && one.current === false) {
|
309
|
+
one.current = true;
|
310
|
+
dispatch({ type: 'flower/next', payload: { flowName, isStart: true } });
|
311
|
+
// if (global.window
|
312
|
+
// // eslint-disable-next-line no-underscore-dangle, no-undef
|
313
|
+
// && global.window.__FLOWER_DEVTOOLS__ && global.window.__FLOWER_DEVTOOLS__AUTO) {
|
314
|
+
// Emitter.emit('flower-devtool-from-client', {
|
315
|
+
// source: 'flower-client',
|
316
|
+
// action: 'START_FLOWER',
|
317
|
+
// name: flowName,
|
318
|
+
// });
|
319
|
+
// }
|
315
320
|
}
|
316
|
-
|
317
|
-
|
318
|
-
}, [dispatch, autostart, startNodeId, currentNode, flowName]);
|
319
|
-
return null;
|
321
|
+
}, [dispatch, autostart, startNodeId, currentNode, flowName]);
|
322
|
+
return null;
|
320
323
|
}
|
321
|
-
const component$7 =
|
324
|
+
const component$7 = React.memo(FlowerStart);
|
322
325
|
component$7.displayName = 'FlowerStart';
|
323
326
|
|
324
|
-
const FlowerRoute = ({
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
onExit == null || onExit();
|
339
|
-
};
|
340
|
-
}, [onEnter, onExit]);
|
341
|
-
useEffect(() => {
|
342
|
-
if (_autostart && one.current === false) {
|
343
|
-
one.current = true;
|
344
|
-
dispatch({
|
345
|
-
type: 'flower/next',
|
346
|
-
payload: {
|
347
|
-
flowName
|
327
|
+
const FlowerRoute = ({ autostart = true, children, onEnter, onExit }) => {
|
328
|
+
const dispatch = useDispatch();
|
329
|
+
const one = useRef(false);
|
330
|
+
const { flowName } = useContext(context);
|
331
|
+
useEffect(() => {
|
332
|
+
onEnter?.();
|
333
|
+
return () => {
|
334
|
+
onExit?.();
|
335
|
+
};
|
336
|
+
}, [onEnter, onExit]);
|
337
|
+
useEffect(() => {
|
338
|
+
if (autostart && one.current === false) {
|
339
|
+
one.current = true;
|
340
|
+
dispatch({ type: 'flower/next', payload: { flowName } });
|
348
341
|
}
|
349
|
-
|
350
|
-
|
351
|
-
}, [dispatch, flowName, _autostart]);
|
352
|
-
return children;
|
342
|
+
}, [dispatch, flowName, autostart]);
|
343
|
+
return children;
|
353
344
|
};
|
354
|
-
const component$6 =
|
345
|
+
const component$6 = React.memo(FlowerRoute);
|
355
346
|
component$6.displayName = 'FlowerRoute';
|
356
347
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
}
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
}
|
375
|
-
|
376
|
-
const FlowerRule = ({
|
377
|
-
children,
|
378
|
-
rules,
|
379
|
-
value,
|
380
|
-
alwaysDisplay,
|
381
|
-
flowName,
|
382
|
-
id,
|
383
|
-
onUpdate
|
384
|
-
}) => {
|
385
|
-
const {
|
386
|
-
flowName: flowNameContext,
|
387
|
-
currentNode
|
388
|
-
} = useContext(context);
|
389
|
-
const name = flowName || flowNameContext;
|
390
|
-
const keys = MatchRules.utils.getKeys(rules, {
|
391
|
-
prefix: name
|
392
|
-
});
|
393
|
-
const hidden = useSelector(selectorRulesDisabled(id != null ? id : '', rules, keys != null ? keys : [], name != null ? name : '', value, currentNode != null ? currentNode : ''));
|
394
|
-
useEffect(() => {
|
395
|
-
if (onUpdate) {
|
396
|
-
onUpdate(hidden);
|
348
|
+
const FlowerRule = ({ children, rules, value, alwaysDisplay, flowName, id, onUpdate }) => {
|
349
|
+
const { flowName: flowNameContext, currentNode } = useContext(context);
|
350
|
+
const name = flowName || flowNameContext;
|
351
|
+
const keys = MatchRules.utils.getKeys(rules, { prefix: name });
|
352
|
+
const hidden = useSelector(selectorRulesDisabled(id ?? '', rules, keys ?? [], name ?? '', value, currentNode ?? ''));
|
353
|
+
useEffect(() => {
|
354
|
+
if (onUpdate) {
|
355
|
+
onUpdate(hidden);
|
356
|
+
}
|
357
|
+
}, [hidden, onUpdate]);
|
358
|
+
if (typeof children === 'function') {
|
359
|
+
if (alwaysDisplay && hidden) {
|
360
|
+
return children({ hidden });
|
361
|
+
}
|
362
|
+
if (hidden) {
|
363
|
+
return undefined;
|
364
|
+
}
|
365
|
+
return children({});
|
397
366
|
}
|
398
|
-
}, [hidden, onUpdate]);
|
399
|
-
if (typeof children === 'function') {
|
400
367
|
if (alwaysDisplay && hidden) {
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
if (alwaysDisplay && hidden) {
|
411
|
-
return React.Children.map(children, (child, i) => {
|
412
|
-
if ( /*#__PURE__*/React.isValidElement(child)) {
|
413
|
-
const {
|
414
|
-
props,
|
415
|
-
type
|
416
|
-
} = child;
|
417
|
-
const Component = type;
|
418
|
-
return Component && /*#__PURE__*/React.createElement(Component, _extends({
|
419
|
-
key: i,
|
420
|
-
hidden: true
|
421
|
-
}, props));
|
422
|
-
}
|
423
|
-
return child;
|
424
|
-
});
|
425
|
-
}
|
426
|
-
return hidden ? undefined : React.Children.map(children, (child, i) => {
|
427
|
-
if ( /*#__PURE__*/React.isValidElement(child)) {
|
428
|
-
const {
|
429
|
-
props,
|
430
|
-
type
|
431
|
-
} = child;
|
432
|
-
const Component = type;
|
433
|
-
return Component && /*#__PURE__*/React.createElement(Component, _extends({
|
434
|
-
key: i
|
435
|
-
}, props));
|
368
|
+
return React.Children.map(children, (child, i) => {
|
369
|
+
if (React.isValidElement(child)) {
|
370
|
+
const { props, type } = child;
|
371
|
+
const Component = type;
|
372
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
373
|
+
return Component && React.createElement(Component, { key: i, hidden: true, ...props });
|
374
|
+
}
|
375
|
+
return child;
|
376
|
+
});
|
436
377
|
}
|
437
|
-
return
|
438
|
-
|
378
|
+
return hidden
|
379
|
+
? undefined
|
380
|
+
: React.Children.map(children, (child, i) => {
|
381
|
+
if (React.isValidElement(child)) {
|
382
|
+
const { props, type } = child;
|
383
|
+
const Component = type;
|
384
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
385
|
+
return Component && React.createElement(Component, { key: i, ...props });
|
386
|
+
}
|
387
|
+
return child;
|
388
|
+
});
|
439
389
|
};
|
440
|
-
const component$5 =
|
390
|
+
const component$5 = React.memo(FlowerRule);
|
441
391
|
component$5.displayName = 'FlowerRule';
|
442
392
|
|
443
|
-
|
393
|
+
/* eslint-disable */
|
444
394
|
function isIntrinsicElement$1(x) {
|
445
|
-
|
395
|
+
return typeof x === 'string';
|
446
396
|
}
|
447
|
-
function
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
const dispatch = useDispatch();
|
466
|
-
const [touched, setTouched] = useState();
|
467
|
-
const [customErrors, setCustomErrors] = useState(asyncValidate && [asyncInitialError]);
|
468
|
-
const [isValidating, setIsValidating] = useState(undefined);
|
469
|
-
const {
|
470
|
-
flowNameFromPath = flowName,
|
471
|
-
path
|
472
|
-
} = useMemo(() => CoreUtils.getPath(id), [id]);
|
473
|
-
const value = useSelector(getDataFromState(flowNameFromPath, path));
|
474
|
-
const errors = useSelector(makeSelectFieldError(flowName, id, validate), CoreUtils.allEqual);
|
475
|
-
const refValue = useRef();
|
476
|
-
const one = useRef();
|
477
|
-
const validateFn = useCallback(async value => {
|
478
|
-
if (asyncWaitingError) {
|
479
|
-
setCustomErrors([asyncWaitingError]);
|
480
|
-
}
|
481
|
-
setIsValidating(true);
|
482
|
-
const state = FlowerStateUtils.getAllData(store);
|
483
|
-
const res = await asyncValidate(value, state, errors);
|
484
|
-
setIsValidating(false);
|
485
|
-
setCustomErrors(res);
|
486
|
-
}, [asyncWaitingError, errors]);
|
487
|
-
const debouncedValidation = useCallback(debounce(validateFn, asyncDebounce), [validateFn]);
|
488
|
-
useEffect(() => {
|
489
|
-
if (asyncValidate) {
|
490
|
-
if (refValue.current === value) return;
|
491
|
-
refValue.current = value;
|
492
|
-
const hasValue = !MatchRules.utils.isEmpty(value);
|
493
|
-
if (!hasValue) {
|
494
|
-
setCustomErrors([asyncInitialError]);
|
397
|
+
//TODO make types for wrapper function props
|
398
|
+
function Wrapper$1({ Component, id, flowName, currentNode, validate, asyncDebounce = 0, asyncValidate, asyncInitialError, asyncWaitingError, destroyValue, onBlur = (val) => null, hidden, onUpdate, defaultValue, ...props }) {
|
399
|
+
const dispatch = useDispatch();
|
400
|
+
const [touched, setTouched] = useState();
|
401
|
+
const [customErrors, setCustomErrors] = useState(asyncValidate && [asyncInitialError]);
|
402
|
+
const [isValidating, setIsValidating] = useState(undefined);
|
403
|
+
const { flowNameFromPath = flowName, path } = useMemo(() => CoreUtils.getPath(id), [id]);
|
404
|
+
const value = useSelector(getDataFromState(flowNameFromPath, path));
|
405
|
+
const errors = useSelector(makeSelectFieldError(flowName, id, validate), CoreUtils.allEqual);
|
406
|
+
const refValue = useRef();
|
407
|
+
const one = useRef();
|
408
|
+
const validateFn = useCallback(async (value) => {
|
409
|
+
if (asyncWaitingError) {
|
410
|
+
setCustomErrors([asyncWaitingError]);
|
411
|
+
}
|
412
|
+
setIsValidating(true);
|
413
|
+
const state = FlowerStateUtils.getAllData(store);
|
414
|
+
const res = await asyncValidate(value, state, errors);
|
495
415
|
setIsValidating(false);
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
dispatch({
|
525
|
-
type: 'flower/formAddErrors',
|
526
|
-
payload: {
|
527
|
-
name: flowName,
|
528
|
-
id,
|
529
|
-
currentNode,
|
530
|
-
errors: allErrors
|
531
|
-
}
|
532
|
-
});
|
533
|
-
}, [id, flowName, allErrors, currentNode]);
|
534
|
-
useEffect(() => {
|
535
|
-
dispatch({
|
536
|
-
type: 'flower/setFormIsValidating',
|
537
|
-
payload: {
|
538
|
-
name: flowName,
|
539
|
-
currentNode,
|
540
|
-
isValidating
|
541
|
-
}
|
542
|
-
});
|
543
|
-
}, [flowName, currentNode, isValidating]);
|
544
|
-
useLayoutEffect(() => {
|
545
|
-
return () => {
|
546
|
-
if (destroyValue) {
|
416
|
+
setCustomErrors(res);
|
417
|
+
}, [asyncWaitingError, errors]);
|
418
|
+
const debouncedValidation = useCallback(debounce(validateFn, asyncDebounce), [
|
419
|
+
validateFn
|
420
|
+
]);
|
421
|
+
useEffect(() => {
|
422
|
+
if (asyncValidate) {
|
423
|
+
if (refValue.current === value)
|
424
|
+
return;
|
425
|
+
refValue.current = value;
|
426
|
+
const hasValue = !MatchRules.utils.isEmpty(value);
|
427
|
+
if (!hasValue) {
|
428
|
+
setCustomErrors([asyncInitialError]);
|
429
|
+
setIsValidating(false);
|
430
|
+
return;
|
431
|
+
}
|
432
|
+
setTouched(true);
|
433
|
+
debouncedValidation(value);
|
434
|
+
}
|
435
|
+
}, [asyncValidate, asyncInitialError, value, debouncedValidation]);
|
436
|
+
const touchedForm = useSelector(makeSelectNodeFormTouched(flowName, currentNode));
|
437
|
+
const allErrors = useMemo(() => [...errors, ...(customErrors || []).filter(Boolean)], [errors, customErrors]);
|
438
|
+
useEffect(() => {
|
439
|
+
if (onUpdate) {
|
440
|
+
onUpdate(value);
|
441
|
+
}
|
442
|
+
}, [value, onUpdate]);
|
443
|
+
const onChange = useCallback((val) => {
|
547
444
|
dispatch({
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
445
|
+
type: `flower/addDataByPath`,
|
446
|
+
payload: {
|
447
|
+
flowName: flowNameFromPath,
|
448
|
+
id: path,
|
449
|
+
value: val
|
450
|
+
}
|
553
451
|
});
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
452
|
+
}, [flowNameFromPath, path, onBlur, dispatch]);
|
453
|
+
const onBlurInternal = useCallback((e) => {
|
454
|
+
setTouched(true);
|
455
|
+
onBlur && onBlur(e);
|
456
|
+
}, [onBlur]);
|
457
|
+
useLayoutEffect(() => {
|
458
|
+
dispatch({
|
459
|
+
type: 'flower/formAddErrors',
|
460
|
+
payload: {
|
461
|
+
name: flowName,
|
462
|
+
id,
|
463
|
+
currentNode,
|
464
|
+
errors: allErrors
|
465
|
+
}
|
466
|
+
});
|
467
|
+
}, [id, flowName, allErrors, currentNode]);
|
468
|
+
useEffect(() => {
|
469
|
+
dispatch({
|
470
|
+
type: 'flower/setFormIsValidating',
|
471
|
+
payload: {
|
472
|
+
name: flowName,
|
473
|
+
currentNode,
|
474
|
+
isValidating
|
475
|
+
}
|
476
|
+
});
|
477
|
+
}, [flowName, currentNode, isValidating]);
|
478
|
+
useLayoutEffect(() => {
|
479
|
+
// destroy
|
480
|
+
return () => {
|
481
|
+
if (destroyValue) {
|
482
|
+
dispatch({
|
483
|
+
type: `flower/unsetData`,
|
484
|
+
payload: { flowName: flowNameFromPath, id: path }
|
485
|
+
});
|
486
|
+
}
|
487
|
+
dispatch({
|
488
|
+
type: 'flower/formRemoveErrors',
|
489
|
+
payload: {
|
490
|
+
name: flowName,
|
491
|
+
id,
|
492
|
+
currentNode
|
493
|
+
}
|
494
|
+
});
|
495
|
+
};
|
496
|
+
}, [destroyValue]);
|
497
|
+
useEffect(() => {
|
498
|
+
if (defaultValue && !one.current) {
|
499
|
+
one.current = true;
|
500
|
+
onChange(defaultValue);
|
561
501
|
}
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
502
|
+
}, [defaultValue, onChange]);
|
503
|
+
const isTouched = touched || touchedForm;
|
504
|
+
const newProps = useMemo(() => ({
|
505
|
+
...props,
|
506
|
+
id,
|
507
|
+
value,
|
508
|
+
errors: isTouched && allErrors,
|
509
|
+
hasError: isTouched && !!allErrors.length,
|
510
|
+
onChange,
|
511
|
+
onBlur: onBlurInternal,
|
512
|
+
isTouched,
|
513
|
+
hidden,
|
514
|
+
isValidating
|
515
|
+
}), [
|
516
|
+
props,
|
517
|
+
id,
|
518
|
+
value,
|
519
|
+
allErrors,
|
520
|
+
isTouched,
|
521
|
+
onChange,
|
522
|
+
onBlurInternal,
|
523
|
+
hidden,
|
524
|
+
isValidating
|
525
|
+
]);
|
526
|
+
if (typeof Component === 'function') {
|
527
|
+
return Component(newProps);
|
528
|
+
}
|
529
|
+
// TODO si arriva in questa condizione quando si passa un componente primitivo es. div
|
530
|
+
// in questo caso non posso props custom di flower
|
531
|
+
if (isIntrinsicElement$1(Component)) {
|
532
|
+
return React.createElement(Component, { id: id, ...props });
|
569
533
|
}
|
570
|
-
|
571
|
-
const isTouched = touched || touchedForm;
|
572
|
-
const newProps = useMemo(() => _extends({}, props, {
|
573
|
-
id,
|
574
|
-
value,
|
575
|
-
errors: isTouched && allErrors,
|
576
|
-
hasError: isTouched && !!allErrors.length,
|
577
|
-
onChange,
|
578
|
-
onBlur: onBlurInternal,
|
579
|
-
isTouched,
|
580
|
-
hidden,
|
581
|
-
isValidating
|
582
|
-
}), [props, id, value, allErrors, isTouched, onChange, onBlurInternal, hidden, isValidating]);
|
583
|
-
if (typeof Component === 'function') {
|
584
|
-
return Component(newProps);
|
585
|
-
}
|
586
|
-
if (isIntrinsicElement$1(Component)) {
|
587
|
-
return /*#__PURE__*/React.createElement(Component, _extends({
|
588
|
-
id: id
|
589
|
-
}, props));
|
590
|
-
}
|
591
|
-
return Component && /*#__PURE__*/React.createElement(Component, _extends({}, newProps));
|
534
|
+
return Component && React.createElement(Component, { ...newProps });
|
592
535
|
}
|
593
|
-
const FlowerField = ({
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
asyncInitialError,
|
599
|
-
asyncWaitingError,
|
600
|
-
rules,
|
601
|
-
alwaysDisplay,
|
602
|
-
value,
|
603
|
-
children,
|
604
|
-
defaultValue,
|
605
|
-
destroyValue,
|
606
|
-
flowName,
|
607
|
-
onUpdate
|
608
|
-
}) => {
|
609
|
-
const {
|
610
|
-
flowName: flowNameContext,
|
611
|
-
currentNode
|
612
|
-
} = useContext(context);
|
613
|
-
const name = flowName || flowNameContext;
|
614
|
-
if (typeof children === 'function') {
|
615
|
-
return /*#__PURE__*/React.createElement(component$5, {
|
616
|
-
alwaysDisplay: alwaysDisplay,
|
617
|
-
rules: rules,
|
618
|
-
value: value,
|
619
|
-
flowName: name,
|
620
|
-
id: id
|
621
|
-
}, ({
|
622
|
-
hidden
|
623
|
-
}) => ( /*#__PURE__*/React.createElement(Wrapper$1, {
|
624
|
-
hidden: hidden,
|
625
|
-
id: id,
|
626
|
-
Component: children,
|
627
|
-
flowName: name,
|
628
|
-
currentNode: currentNode,
|
629
|
-
validate: validate,
|
630
|
-
asyncValidate: asyncValidate,
|
631
|
-
asyncDebounce: asyncDebounce,
|
632
|
-
asyncInitialError: asyncInitialError,
|
633
|
-
asyncWaitingError: asyncWaitingError,
|
634
|
-
destroyValue: destroyValue,
|
635
|
-
onUpdate: onUpdate,
|
636
|
-
defaultValue: defaultValue
|
637
|
-
})));
|
638
|
-
}
|
639
|
-
return React.Children.map(children, (child, i) => {
|
640
|
-
if (! /*#__PURE__*/React.isValidElement(child)) {
|
641
|
-
return child;
|
536
|
+
const FlowerField = ({ id, validate, asyncValidate, asyncDebounce, asyncInitialError, asyncWaitingError, rules, alwaysDisplay, value, children, defaultValue, destroyValue, flowName, onUpdate }) => {
|
537
|
+
const { flowName: flowNameContext, currentNode } = useContext(context);
|
538
|
+
const name = flowName || flowNameContext;
|
539
|
+
if (typeof children === 'function') {
|
540
|
+
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 }))));
|
642
541
|
}
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
rules: rules,
|
652
|
-
value: value,
|
653
|
-
flowName: name
|
654
|
-
}, ({
|
655
|
-
hidden
|
656
|
-
}) => ( /*#__PURE__*/React.createElement(Wrapper$1, _extends({}, props, {
|
657
|
-
hidden: hidden,
|
658
|
-
id: id,
|
659
|
-
Component: Component,
|
660
|
-
flowName: name,
|
661
|
-
currentNode: currentNode,
|
662
|
-
validate: validate,
|
663
|
-
asyncValidate: asyncValidate,
|
664
|
-
asyncDebounce: asyncDebounce,
|
665
|
-
asyncInitialError: asyncInitialError,
|
666
|
-
asyncWaitingError: asyncWaitingError,
|
667
|
-
destroyValue: destroyValue,
|
668
|
-
onUpdate: onUpdate,
|
669
|
-
defaultValue: defaultValue
|
670
|
-
}))));
|
671
|
-
});
|
542
|
+
return React.Children.map(children, (child, i) => {
|
543
|
+
if (!React.isValidElement(child)) {
|
544
|
+
return child;
|
545
|
+
}
|
546
|
+
const { type, props } = child;
|
547
|
+
const Component = type;
|
548
|
+
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 }))));
|
549
|
+
});
|
672
550
|
};
|
673
|
-
const component$4 =
|
551
|
+
const component$4 = React.memo(FlowerField);
|
674
552
|
component$4.displayName = 'FlowerField';
|
675
553
|
|
676
|
-
|
677
|
-
|
678
|
-
function Wrapper(
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
path
|
691
|
-
} = useMemo(() => CoreUtils.getPath(id), [id]);
|
692
|
-
const value = useSelector(getDataFromState(flowNameFromPath, path));
|
693
|
-
const values = spreadValue && typeof value === 'object' && !Array.isArray(value) ? value : {
|
694
|
-
value
|
695
|
-
};
|
696
|
-
useEffect(() => {
|
697
|
-
if (onUpdate) {
|
698
|
-
onUpdate(value);
|
699
|
-
}
|
700
|
-
}, [onUpdate, value]);
|
701
|
-
return /*#__PURE__*/React.createElement(Component, _extends({
|
702
|
-
id: id
|
703
|
-
}, props, {
|
704
|
-
flowName: flowName,
|
705
|
-
hidden: hidden
|
706
|
-
}, values));
|
554
|
+
/* eslint-disable */
|
555
|
+
//TODO make types for wrapper function
|
556
|
+
function Wrapper({ Component, id, flowName, spreadValue, hidden, onUpdate, ...props }) {
|
557
|
+
const { flowNameFromPath = flowName, path } = useMemo(() => CoreUtils.getPath(id), [id]);
|
558
|
+
const value = useSelector(getDataFromState(flowNameFromPath, path));
|
559
|
+
const values = spreadValue && typeof value === 'object' && !Array.isArray(value)
|
560
|
+
? value
|
561
|
+
: { value };
|
562
|
+
useEffect(() => {
|
563
|
+
if (onUpdate) {
|
564
|
+
onUpdate(value);
|
565
|
+
}
|
566
|
+
}, [onUpdate, value]);
|
567
|
+
return (React.createElement(Component, { id: id, ...props, flowName: flowName, hidden: hidden, ...values }));
|
707
568
|
}
|
708
|
-
const RenderRules$1 =
|
709
|
-
|
710
|
-
id,
|
711
|
-
alwaysDisplay,
|
712
|
-
rules,
|
713
|
-
value,
|
714
|
-
Component,
|
715
|
-
spreadValue,
|
716
|
-
flowName,
|
717
|
-
onUpdate
|
718
|
-
} = _ref2,
|
719
|
-
props = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
720
|
-
return /*#__PURE__*/React.createElement(component$5, {
|
721
|
-
alwaysDisplay: alwaysDisplay,
|
722
|
-
rules: rules,
|
723
|
-
value: value,
|
724
|
-
flowName: flowName,
|
725
|
-
id: id
|
726
|
-
}, ({
|
727
|
-
hidden
|
728
|
-
}) => ( /*#__PURE__*/React.createElement(Wrapper, _extends({}, props, {
|
729
|
-
hidden: hidden,
|
730
|
-
id: id,
|
731
|
-
Component: Component,
|
732
|
-
spreadValue: spreadValue,
|
733
|
-
flowName: flowName,
|
734
|
-
onUpdate: onUpdate
|
735
|
-
}))));
|
569
|
+
const RenderRules$1 = ({ id, alwaysDisplay, rules, value, Component, spreadValue, flowName, onUpdate, ...props }) => {
|
570
|
+
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 }))));
|
736
571
|
};
|
737
|
-
const FlowerValue = ({
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
}
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
const name = flowName || flowNameContext;
|
751
|
-
if (typeof children === 'function') {
|
752
|
-
return /*#__PURE__*/React.createElement(RenderRules$1, {
|
753
|
-
id: _id,
|
754
|
-
alwaysDisplay: alwaysDisplay,
|
755
|
-
rules: rules,
|
756
|
-
value: value,
|
757
|
-
spreadValue: spreadValue,
|
758
|
-
Component: children,
|
759
|
-
flowName: name,
|
760
|
-
onUpdate: onUpdate
|
572
|
+
const FlowerValue = ({ id = '*', rules, alwaysDisplay, value, children, spreadValue, flowName, onUpdate, }) => {
|
573
|
+
const { flowName: flowNameContext } = useContext(context);
|
574
|
+
const name = flowName || flowNameContext;
|
575
|
+
if (typeof children === 'function') {
|
576
|
+
return (React.createElement(RenderRules$1, { id: id, alwaysDisplay: alwaysDisplay, rules: rules, value: value, spreadValue: spreadValue, Component: children, flowName: name, onUpdate: onUpdate }));
|
577
|
+
}
|
578
|
+
return React.Children.map(children, (child, i) => {
|
579
|
+
if (!React.isValidElement(child))
|
580
|
+
return child;
|
581
|
+
const { type, props } = child;
|
582
|
+
const Component = type;
|
583
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
584
|
+
return (React.createElement(RenderRules$1, { key: i, id: id, alwaysDisplay: alwaysDisplay, rules: rules, value: value, spreadValue: spreadValue, flowName: name, Component: Component, ...props, onUpdate: onUpdate }));
|
761
585
|
});
|
762
|
-
}
|
763
|
-
return React.Children.map(children, (child, i) => {
|
764
|
-
if (! /*#__PURE__*/React.isValidElement(child)) return child;
|
765
|
-
const {
|
766
|
-
type,
|
767
|
-
props
|
768
|
-
} = child;
|
769
|
-
const Component = type;
|
770
|
-
return /*#__PURE__*/React.createElement(RenderRules$1, _extends({
|
771
|
-
key: i,
|
772
|
-
id: _id,
|
773
|
-
alwaysDisplay: alwaysDisplay,
|
774
|
-
rules: rules,
|
775
|
-
value: value,
|
776
|
-
spreadValue: spreadValue,
|
777
|
-
flowName: name,
|
778
|
-
Component: Component
|
779
|
-
}, props, {
|
780
|
-
onUpdate: onUpdate
|
781
|
-
}));
|
782
|
-
});
|
783
586
|
};
|
784
|
-
const component$3 =
|
587
|
+
const component$3 = React.memo(FlowerValue);
|
785
588
|
component$3.displayName = 'FlowerValue';
|
786
589
|
|
787
590
|
const ACTION_TYPES = {
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
591
|
+
back: ['prev', 'prevToNode'],
|
592
|
+
jump: ['node', 'node'],
|
593
|
+
next: ['next', 'next'],
|
594
|
+
restart: ['restart', 'restart'],
|
595
|
+
reset: ['reset', 'initializeFromNode']
|
793
596
|
};
|
794
597
|
const PAYLAOAD_KEYS_NEEDED = {
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
598
|
+
back: ['node'],
|
599
|
+
jump: ['node', 'history'],
|
600
|
+
next: ['node', 'route', 'data'],
|
601
|
+
restart: ['node'],
|
602
|
+
reset: ['node', 'initialData']
|
800
603
|
};
|
801
604
|
const makeActionPayload = (actions, keys) => (flowName, params) => {
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
};
|
605
|
+
const rest = typeof params === 'string' ? { node: params } : params;
|
606
|
+
const payload = {
|
607
|
+
flowName: params?.flowName || flowName,
|
608
|
+
...Object.fromEntries(Object.entries(rest ?? {}).filter(([k]) => keys.includes(k)))
|
609
|
+
};
|
610
|
+
const type = !params || !payload.node ? actions[0] : actions[1];
|
611
|
+
return {
|
612
|
+
type,
|
613
|
+
payload
|
614
|
+
};
|
813
615
|
};
|
814
616
|
const makeActionPayloadOnPrev = makeActionPayload(ACTION_TYPES.back, PAYLAOAD_KEYS_NEEDED.back);
|
815
617
|
const makeActionPayloadOnReset = makeActionPayload(ACTION_TYPES.reset, PAYLAOAD_KEYS_NEEDED.reset);
|
816
618
|
const makeActionPayloadOnNode = makeActionPayload(ACTION_TYPES.jump, PAYLAOAD_KEYS_NEEDED.jump);
|
817
619
|
const makeActionPayloadOnNext = makeActionPayload(ACTION_TYPES.next, PAYLAOAD_KEYS_NEEDED.next);
|
818
620
|
const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart, PAYLAOAD_KEYS_NEEDED.restart);
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
621
|
+
/** This hook allows you to read flow informations, such as the flowName and ID of the current node.
|
622
|
+
*
|
623
|
+
* It also exposes all the functions to navigate within the flow:
|
624
|
+
*
|
625
|
+
* - next
|
626
|
+
*
|
627
|
+
* - back
|
628
|
+
*
|
629
|
+
* - jump
|
630
|
+
*
|
631
|
+
* - reset
|
632
|
+
*
|
633
|
+
* - restart
|
634
|
+
*
|
635
|
+
* @param {string} flowName - first optional parameter
|
636
|
+
*
|
637
|
+
* @param {string} name - optional parameter, if flowName exist, name is not used
|
638
|
+
*/
|
639
|
+
const useFlower = ({ flowName: customFlowName, name } = {}) => {
|
640
|
+
const dispatch = useDispatch();
|
641
|
+
const { flowName: flowNameDefault, initialData } = useContext(context);
|
642
|
+
const flowName = customFlowName || name || flowNameDefault;
|
643
|
+
const nodeId = useSelector(makeSelectCurrentNodeId(flowName ?? ''));
|
644
|
+
const startId = useSelector(makeSelectStartNodeId(flowName ?? ''));
|
645
|
+
const emitNavigateEvent = useCallback(
|
646
|
+
//TODO check this function is needed
|
647
|
+
(params) => {
|
648
|
+
/* istanbul ignore next */
|
649
|
+
// eslint-disable-next-line no-underscore-dangle, no-undef
|
650
|
+
if (_get(devtoolState, '__FLOWER_DEVTOOLS__')) {
|
651
|
+
Emitter.emit('flower-devtool-from-client', {
|
652
|
+
source: 'flower-client',
|
653
|
+
action: 'FLOWER_NAVIGATE',
|
654
|
+
nodeId,
|
655
|
+
name: flowName,
|
656
|
+
time: new Date(),
|
657
|
+
params
|
658
|
+
});
|
659
|
+
}
|
660
|
+
}, [flowName, nodeId]);
|
661
|
+
const next = useCallback((param) => {
|
662
|
+
const params = typeof param === 'string' ? { route: param } : { data: param };
|
663
|
+
const { type, payload } = makeActionPayloadOnNext(flowName, params);
|
664
|
+
dispatch({
|
665
|
+
type: `flower/${type}`,
|
666
|
+
payload
|
667
|
+
});
|
668
|
+
emitNavigateEvent({ type, payload });
|
669
|
+
}, [dispatch, emitNavigateEvent, flowName]);
|
670
|
+
const back = useCallback((param) => {
|
671
|
+
const { type, payload } = makeActionPayloadOnPrev(flowName, param);
|
672
|
+
dispatch({ type: `flower/${type}`, payload });
|
673
|
+
emitNavigateEvent({ type, payload });
|
674
|
+
}, [dispatch, emitNavigateEvent, flowName]);
|
675
|
+
const restart = useCallback((param) => {
|
676
|
+
const { type, payload } = makeActionPayloadOnRestart(flowName, param);
|
677
|
+
dispatch({ type: `flower/${type}`, payload });
|
678
|
+
emitNavigateEvent({ type, payload });
|
679
|
+
}, [dispatch, emitNavigateEvent, flowName]);
|
680
|
+
const reset = useCallback((param) => {
|
681
|
+
const { type, payload } = makeActionPayloadOnReset(flowName, typeof param === 'string'
|
682
|
+
? { node: param, initialData }
|
683
|
+
: {
|
684
|
+
...param,
|
685
|
+
initialData
|
686
|
+
});
|
687
|
+
dispatch({ type: `flower/${type}`, payload });
|
688
|
+
emitNavigateEvent({ type, payload });
|
689
|
+
}, [dispatch, emitNavigateEvent, flowName, initialData]);
|
690
|
+
const jump = useCallback((param) => {
|
691
|
+
const { type, payload } = makeActionPayloadOnNode(flowName, param);
|
692
|
+
dispatch({ type: `flower/${type}`, payload });
|
693
|
+
emitNavigateEvent({ type, payload });
|
694
|
+
}, [dispatch, emitNavigateEvent, flowName]);
|
695
|
+
return {
|
696
|
+
flowName,
|
835
697
|
nodeId,
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
const next = useCallback(param => {
|
843
|
-
const params = typeof param === 'string' ? {
|
844
|
-
route: param
|
845
|
-
} : {
|
846
|
-
data: param
|
698
|
+
startId,
|
699
|
+
next,
|
700
|
+
jump,
|
701
|
+
back,
|
702
|
+
reset,
|
703
|
+
restart
|
847
704
|
};
|
848
|
-
const {
|
849
|
-
type,
|
850
|
-
payload
|
851
|
-
} = makeActionPayloadOnNext(flowName, params);
|
852
|
-
dispatch({
|
853
|
-
type: `flower/${type}`,
|
854
|
-
payload
|
855
|
-
});
|
856
|
-
emitNavigateEvent({
|
857
|
-
type,
|
858
|
-
payload
|
859
|
-
});
|
860
|
-
}, [dispatch, emitNavigateEvent, flowName]);
|
861
|
-
const back = useCallback(param => {
|
862
|
-
const {
|
863
|
-
type,
|
864
|
-
payload
|
865
|
-
} = makeActionPayloadOnPrev(flowName, param);
|
866
|
-
dispatch({
|
867
|
-
type: `flower/${type}`,
|
868
|
-
payload
|
869
|
-
});
|
870
|
-
emitNavigateEvent({
|
871
|
-
type,
|
872
|
-
payload
|
873
|
-
});
|
874
|
-
}, [dispatch, emitNavigateEvent, flowName]);
|
875
|
-
const restart = useCallback(param => {
|
876
|
-
const {
|
877
|
-
type,
|
878
|
-
payload
|
879
|
-
} = makeActionPayloadOnRestart(flowName, param);
|
880
|
-
dispatch({
|
881
|
-
type: `flower/${type}`,
|
882
|
-
payload
|
883
|
-
});
|
884
|
-
emitNavigateEvent({
|
885
|
-
type,
|
886
|
-
payload
|
887
|
-
});
|
888
|
-
}, [dispatch, emitNavigateEvent, flowName]);
|
889
|
-
const reset = useCallback(param => {
|
890
|
-
const {
|
891
|
-
type,
|
892
|
-
payload
|
893
|
-
} = makeActionPayloadOnReset(flowName, typeof param === 'string' ? {
|
894
|
-
node: param,
|
895
|
-
initialData
|
896
|
-
} : _extends({}, param, {
|
897
|
-
initialData
|
898
|
-
}));
|
899
|
-
dispatch({
|
900
|
-
type: `flower/${type}`,
|
901
|
-
payload
|
902
|
-
});
|
903
|
-
emitNavigateEvent({
|
904
|
-
type,
|
905
|
-
payload
|
906
|
-
});
|
907
|
-
}, [dispatch, emitNavigateEvent, flowName, initialData]);
|
908
|
-
const jump = useCallback(param => {
|
909
|
-
const {
|
910
|
-
type,
|
911
|
-
payload
|
912
|
-
} = makeActionPayloadOnNode(flowName, param);
|
913
|
-
dispatch({
|
914
|
-
type: `flower/${type}`,
|
915
|
-
payload
|
916
|
-
});
|
917
|
-
emitNavigateEvent({
|
918
|
-
type,
|
919
|
-
payload
|
920
|
-
});
|
921
|
-
}, [dispatch, emitNavigateEvent, flowName]);
|
922
|
-
return {
|
923
|
-
flowName,
|
924
|
-
nodeId,
|
925
|
-
next,
|
926
|
-
jump,
|
927
|
-
back,
|
928
|
-
reset,
|
929
|
-
restart
|
930
|
-
};
|
931
705
|
};
|
932
706
|
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
707
|
+
/* eslint-disable */
|
708
|
+
// {
|
709
|
+
// flowName?: string | undefined;
|
710
|
+
// action?: 'next' | 'back' | 'reset' | 'jump';
|
711
|
+
// } & (
|
712
|
+
// | {
|
713
|
+
// node?: undefined;
|
714
|
+
// route?: Route;
|
715
|
+
// }
|
716
|
+
// | {
|
717
|
+
// node?: RoutePrev;
|
718
|
+
// route?: undefined;
|
719
|
+
// }
|
720
|
+
// | {
|
721
|
+
// node?: RouteReset;
|
722
|
+
// route?: undefined;
|
723
|
+
// }
|
724
|
+
// | {
|
725
|
+
// node?: RouteNode;
|
726
|
+
// route?: undefined;
|
727
|
+
// }
|
728
|
+
// );
|
729
|
+
const useFlowerNavigate = ({ flowName, action, route, node }) => {
|
730
|
+
const { flowName: flowNameContext } = useContext(context);
|
731
|
+
const name = flowName || flowNameContext;
|
732
|
+
const { next, jump, back, reset, restart } = useFlower({ flowName: name });
|
733
|
+
const onNavigate = useCallback(() => {
|
734
|
+
switch (action) {
|
735
|
+
case 'next':
|
736
|
+
next(route);
|
737
|
+
return;
|
738
|
+
case 'jump':
|
739
|
+
jump(node);
|
740
|
+
return;
|
741
|
+
case 'back':
|
742
|
+
back(node);
|
743
|
+
return;
|
744
|
+
case 'reset':
|
745
|
+
reset(node);
|
746
|
+
return;
|
747
|
+
case 'restart':
|
748
|
+
restart(node);
|
749
|
+
return;
|
750
|
+
default:
|
751
|
+
next();
|
752
|
+
return;
|
753
|
+
}
|
754
|
+
}, [next, jump, back, reset, restart, node, route]);
|
755
|
+
return {
|
756
|
+
onNavigate,
|
757
|
+
flowName
|
758
|
+
};
|
978
759
|
};
|
979
760
|
|
980
|
-
|
761
|
+
/* eslint-disable */
|
981
762
|
function isIntrinsicElement(x) {
|
982
|
-
|
763
|
+
return typeof x === 'string';
|
983
764
|
}
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
props
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
return Component && /*#__PURE__*/React.createElement(Component, _extends({}, newProps));
|
765
|
+
//TODO type FlowerNavigateWrapper props
|
766
|
+
function FlowerNavigateWrapper({ hidden, Component, onNavigate, ...props }) {
|
767
|
+
const newProps = useMemo(() => ({
|
768
|
+
...props,
|
769
|
+
hidden,
|
770
|
+
onClick: onNavigate,
|
771
|
+
}), [props, onNavigate]);
|
772
|
+
if (typeof Component === 'function') {
|
773
|
+
return Component(newProps);
|
774
|
+
}
|
775
|
+
// TODO si arriva in questa condizione quando si passa un componente primitivo es. div
|
776
|
+
// in questo caso non posso props custom di flower
|
777
|
+
if (isIntrinsicElement(Component)) {
|
778
|
+
return React.createElement(Component, { ...props, onClick: onNavigate });
|
779
|
+
}
|
780
|
+
// TODO in questa condizione si arriva se nel progetto si utilizza Vite, in questo caso i componenti non sono Function ma Object,
|
781
|
+
// oppure nel caso di un testo semplice come children di questo componente
|
782
|
+
/* istanbul ignore next */
|
783
|
+
return Component && React.createElement(Component, { ...newProps });
|
1004
784
|
}
|
1005
|
-
const component$2 =
|
785
|
+
const component$2 = React.memo(FlowerNavigateWrapper);
|
1006
786
|
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
rules,
|
1012
|
-
Component,
|
1013
|
-
flowName,
|
1014
|
-
onNavigate
|
1015
|
-
} = _ref,
|
1016
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
1017
|
-
return /*#__PURE__*/React.createElement(component$5, {
|
1018
|
-
alwaysDisplay: alwaysDisplay,
|
1019
|
-
rules: rules,
|
1020
|
-
flowName: flowName
|
1021
|
-
}, ({
|
1022
|
-
hidden
|
1023
|
-
}) => /*#__PURE__*/React.createElement(component$2, _extends({}, props, {
|
1024
|
-
Component: Component,
|
1025
|
-
hidden: hidden,
|
1026
|
-
onNavigate: onNavigate
|
1027
|
-
})));
|
787
|
+
/* eslint-disable */
|
788
|
+
//TODO type RenderRules props
|
789
|
+
const RenderRules = ({ alwaysDisplay, rules, Component, flowName, onNavigate, ...props }) => {
|
790
|
+
return (React.createElement(component$5, { alwaysDisplay: alwaysDisplay, rules: rules, flowName: flowName }, ({ hidden }) => React.createElement(component$2, { ...props, Component: Component, hidden: hidden, onNavigate: onNavigate })));
|
1028
791
|
};
|
1029
|
-
const FlowerNavigate = ({
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
}
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
} = useFlowerNavigate({
|
1042
|
-
flowName: forceFlowName,
|
1043
|
-
action,
|
1044
|
-
route,
|
1045
|
-
node
|
1046
|
-
});
|
1047
|
-
if (typeof children === 'function') {
|
1048
|
-
return /*#__PURE__*/React.createElement(RenderRules, {
|
1049
|
-
alwaysDisplay: alwaysDisplay,
|
1050
|
-
rules: rules,
|
1051
|
-
Component: children,
|
1052
|
-
flowName: flowName,
|
1053
|
-
onNavigate: onNavigate
|
792
|
+
const FlowerNavigate = ({ children, flowName: forceFlowName, action, route, node, rules, alwaysDisplay, }) => {
|
793
|
+
const { onNavigate, flowName } = useFlowerNavigate({ flowName: forceFlowName, action, route, node });
|
794
|
+
if (typeof children === 'function') {
|
795
|
+
return React.createElement(RenderRules, { alwaysDisplay: alwaysDisplay, rules: rules, Component: children, flowName: flowName, onNavigate: onNavigate });
|
796
|
+
}
|
797
|
+
return React.Children.map(children, (child, i) => {
|
798
|
+
if (!React.isValidElement(child))
|
799
|
+
return child;
|
800
|
+
const { type, props } = child;
|
801
|
+
const Component = type;
|
802
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
803
|
+
return React.createElement(RenderRules, { key: i, alwaysDisplay: alwaysDisplay, rules: rules, Component: Component, flowName: flowName, onNavigate: onNavigate, ...props });
|
1054
804
|
});
|
1055
|
-
}
|
1056
|
-
return React.Children.map(children, (child, i) => {
|
1057
|
-
if (! /*#__PURE__*/React.isValidElement(child)) return child;
|
1058
|
-
const {
|
1059
|
-
type,
|
1060
|
-
props
|
1061
|
-
} = child;
|
1062
|
-
const Component = type;
|
1063
|
-
return /*#__PURE__*/React.createElement(RenderRules, _extends({
|
1064
|
-
key: i,
|
1065
|
-
alwaysDisplay: alwaysDisplay,
|
1066
|
-
rules: rules,
|
1067
|
-
Component: Component,
|
1068
|
-
flowName: flowName,
|
1069
|
-
onNavigate: onNavigate
|
1070
|
-
}, props));
|
1071
|
-
});
|
1072
805
|
};
|
1073
|
-
const component$1 =
|
806
|
+
const component$1 = React.memo(FlowerNavigate);
|
1074
807
|
component$1.displayName = 'FlowerNavigate';
|
1075
808
|
|
1076
|
-
const FlowerComponent = ({
|
1077
|
-
|
1078
|
-
}) => children;
|
1079
|
-
const component = /*#__PURE__*/memo(FlowerComponent);
|
809
|
+
const FlowerComponent = ({ children }) => children;
|
810
|
+
const component = memo(FlowerComponent);
|
1080
811
|
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
const {
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
isValidating,
|
1144
|
-
getData,
|
1145
|
-
setData,
|
1146
|
-
unsetData,
|
1147
|
-
replaceData
|
1148
|
-
};
|
812
|
+
/** This hook allows you to manage and retrieve information about Forms.
|
813
|
+
*
|
814
|
+
* It exposes details regarding the form's state and a set of methods for reading and writing within it:
|
815
|
+
*
|
816
|
+
* - getData
|
817
|
+
*
|
818
|
+
* - setData
|
819
|
+
*
|
820
|
+
* - unSetData
|
821
|
+
*
|
822
|
+
* - replaceData
|
823
|
+
*
|
824
|
+
* @param {string} flowName - first optional parameter
|
825
|
+
*
|
826
|
+
* @param {string} name - optional parameter, if flowName exist, name is not used
|
827
|
+
*
|
828
|
+
*/
|
829
|
+
const useFlowerForm = ({ flowName: customFlowName, name } = {}) => {
|
830
|
+
const { flowName: flowNameDefault } = useContext(context);
|
831
|
+
const dispatch = useDispatch();
|
832
|
+
const store = useStore();
|
833
|
+
const flowName = customFlowName || name || flowNameDefault || '';
|
834
|
+
const currentNode = useSelector(makeSelectCurrentNodeId(flowName));
|
835
|
+
const { errors, isValid, touched, isValidating } = useSelector(makeSelectNodeErrors(flowName, currentNode));
|
836
|
+
const getData = useCallback((path) => {
|
837
|
+
const { flowNameFromPath = flowName, path: newpath } = CoreUtils.getPath(path);
|
838
|
+
return _get(store.getState(), [
|
839
|
+
'flower',
|
840
|
+
flowNameFromPath,
|
841
|
+
'data',
|
842
|
+
...newpath
|
843
|
+
]);
|
844
|
+
}, [store, flowName]);
|
845
|
+
const setData = useCallback((val, path) => {
|
846
|
+
if (path) {
|
847
|
+
const { flowNameFromPath = flowName, path: newpath } = CoreUtils.getPath(path);
|
848
|
+
dispatch(actions.addDataByPath({
|
849
|
+
flowName: flowNameFromPath,
|
850
|
+
id: Array.isArray(newpath) ? newpath : [newpath],
|
851
|
+
value: val
|
852
|
+
}));
|
853
|
+
return;
|
854
|
+
}
|
855
|
+
dispatch(actions.addData({ flowName, value: val }));
|
856
|
+
}, [flowName, dispatch]);
|
857
|
+
const unsetData = useCallback((path) => {
|
858
|
+
const { flowNameFromPath = flowName, path: newpath } = CoreUtils.getPath(path);
|
859
|
+
dispatch(actions.unsetData({ flowName: flowNameFromPath, id: newpath }));
|
860
|
+
}, [flowName, dispatch]);
|
861
|
+
const replaceData = useCallback((val) => {
|
862
|
+
dispatch(actions.replaceData({ flowName, value: val }));
|
863
|
+
}, [flowName, dispatch]);
|
864
|
+
return {
|
865
|
+
touched,
|
866
|
+
errors,
|
867
|
+
isValid,
|
868
|
+
isValidating,
|
869
|
+
getData,
|
870
|
+
setData,
|
871
|
+
unsetData,
|
872
|
+
replaceData
|
873
|
+
};
|
1149
874
|
};
|
1150
875
|
|
1151
876
|
export { component$c as Flower, component$a as FlowerAction, component as FlowerComponent, context as FlowerContext, Consumer as FlowerContextConsumer, Provider as FlowerContextProvider, component$4 as FlowerField, component$8 as FlowerFlow, component$1 as FlowerNavigate, component$b as FlowerNode, FlowerProvider, component$6 as FlowerRoute, component$5 as FlowerRule, component$9 as FlowerServer, component$7 as FlowerStart, component$3 as FlowerValue, getDataByFlow, useFlower, useFlowerForm, useSelector };
|