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