@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/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 = /*#__PURE__*/React.createContext({});
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
- const res = flowerCore.CoreUtils.generateNodesForFlowerJson(nodes);
20
- return res;
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
- name: 'flower',
25
- initialState: {},
26
- reducers: flowerCore.FlowerCoreReducers
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
- flower: flowerReducer.reducer
30
+ flower: flowerReducer.reducer
33
31
  };
34
32
 
35
- const {
36
- getAllData: mapData
37
- } = flowerCore.FlowerStateUtils;
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 = /*#__PURE__*/React.createContext(null);
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
- enableDevtool
66
- }) => toolkit.configureStore({
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
- constructor(props) {
74
- super(props);
75
- this.store = store({
76
- enableDevtool: props.enableReduxDevtool
77
- });
78
- }
79
- render() {
80
- const {
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
- children,
97
- name,
98
- destroyOnUnmount: _destroyOnUnmount = true,
99
- startId: _startId = null,
100
- initialData: _initialData = {}
101
- }) => {
102
- const flowName = name;
103
- const dispatch = useDispatch();
104
- const one = React.useRef(false);
105
- const [wsDevtools, setWsDevtools] = React.useState(flowerCore.devtoolState && _get(flowerCore.devtoolState, '__FLOWER_DEVTOOLS_INITIALIZED__', false));
106
- // TODO rivedere il giro, potremmo fare le trasformazioni in CoreUtils.generateNodesForFlowerJson
107
- // eslint-disable-next-line react-hooks/exhaustive-deps, max-len
108
- const nodes = React.useMemo(() => convertElements(React.Children.toArray(children)), [children]);
109
- const nodeById = React.useMemo(() => _keyBy(React.Children.toArray(children), 'props.id'), [children]);
110
- const isInitialized = useSelector(makeSelectStartNodeId(name));
111
- const history = useSelector(selectFlowerHistory(name));
112
- const current = useSelector(makeSelectCurrentNodeId(flowName));
113
- const isDisabled = useSelector(makeSelectCurrentNodeDisabled(flowName));
114
- const prevFlowerNodeId = useSelector(makeSelectPrevNodeRetain(flowName));
115
- const store = useStore();
116
- React.useEffect(() => {
117
- if (nodes.length > 0 && one.current === false) {
118
- one.current = true;
119
- dispatch(actions.initNodes({
120
- name: flowName,
121
- // @ts-expect-error FIX ME
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: _startId != null ? _startId : '',
124
- persist: _destroyOnUnmount === false,
125
- initialData: _initialData
126
- }));
127
- }
128
- }, [dispatch, flowName, nodes, _startId, _initialData, _destroyOnUnmount]);
129
- React.useEffect(() => {
130
- /* istanbul ignore next */
131
- const eventCb = msg => {
132
- if (msg.source !== 'flower-devtool') return;
133
- if (msg.action === 'FLOWER_EXTENSION_INIT' || msg.action === 'FLOWER_DEVTOOL_WEB_INIT') {
134
- setWsDevtools(true);
135
- }
136
- if (msg.action === 'SELECTED_NODE' && msg.name === flowName) {
137
- dispatch(actions.setCurrentNode({
138
- name: msg.name,
139
- node: msg.id
140
- }));
141
- }
142
- if (msg.action === 'REPLACE_DATA' && msg.name === flowName) {
143
- dispatch(actions.replaceData({
144
- flowName: msg.name,
145
- value: msg.data
146
- }));
147
- }
148
- if (msg.action === 'ADD_DATA' && msg.name === flowName) {
149
- dispatch(actions.addData({
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
- // eslint-disable-next-line no-underscore-dangle, no-undef
226
- /* istanbul ignore next */
227
- if (wsDevtools && flowerCore.devtoolState && _get(flowerCore.devtoolState, '__FLOWER_DEVTOOLS__')) {
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
- return;
244
- }
245
- // eslint-disable-next-line no-underscore-dangle, no-undef
246
- /* istanbul ignore next */
247
- if (wsDevtools && flowerCore.devtoolState && _get(flowerCore.devtoolState, '__FLOWER_DEVTOOLS__')) {
248
- if (isInitialized === current) return; // salto il primo evento
249
- flowerCore.Emitter.emit('flower-devtool-from-client', {
250
- source: 'flower-client',
251
- action: 'SET_SELECTED',
252
- nodeId: current,
253
- name: flowName,
254
- time: new Date()
255
- });
256
- }
257
- }, [dispatch, flowName, current, isDisabled, store, wsDevtools, isInitialized]);
258
- const contextValues = React.useMemo(() => ({
259
- flowName,
260
- initialData: _initialData,
261
- currentNode: current
262
- }), [flowName, _initialData, current]);
263
- return isInitialized ? ( /*#__PURE__*/React.createElement(Provider, {
264
- value: contextValues
265
- }, prevFlowerNodeId !== current && typeof prevFlowerNodeId === 'string' && nodeById[prevFlowerNodeId], !isDisabled && nodeById[current])) : null;
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 = /*#__PURE__*/React.memo(FlowerClient);
260
+ const component$c = React.memo(FlowerClient);
268
261
 
269
- const FlowerNode = ({
270
- children,
271
- onEnter,
272
- onExit
273
- }) => {
274
- React.useEffect(() => {
275
- onEnter == null || 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 = /*#__PURE__*/React.memo(FlowerNode);
271
+ const component$b = React.memo(FlowerNode);
283
272
  component$b.displayName = 'FlowerNode';
284
273
 
285
- const FlowAction = ({
286
- children,
287
- onEnter,
288
- onExit
289
- }) => {
290
- React.useEffect(() => {
291
- onEnter == null || 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 = /*#__PURE__*/React.memo(FlowAction);
283
+ const component$a = React.memo(FlowAction);
299
284
  component$a.displayName = 'FlowerAction';
300
285
 
301
- const FlowerServer = ({
302
- children
303
- }) => {
304
- return children;
286
+ const FlowerServer = ({ children }) => {
287
+ return children;
305
288
  };
306
- const component$9 = /*#__PURE__*/React.memo(FlowerServer);
289
+ const component$9 = React.memo(FlowerServer);
307
290
  component$9.displayName = 'FlowerServer';
308
291
 
309
- const FlowerFlow = ({
310
- children,
311
- onEnter,
312
- onExit
313
- }) => {
314
- React.useEffect(() => {
315
- onEnter == null || 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 = /*#__PURE__*/React.memo(FlowerFlow);
301
+ const component$8 = React.memo(FlowerFlow);
323
302
  component$8.displayName = 'FlowerFlow';
324
303
 
325
304
  function FlowerStart() {
326
- const dispatch = useDispatch();
327
- const one = React.useRef(false);
328
- const {
329
- flowName,
330
- autostart = true,
331
- currentNode
332
- } = React.useContext(context);
333
- const startNodeId = useSelector(makeSelectStartNodeId(flowName != null ? flowName : ''));
334
- React.useEffect(() => {
335
- if (startNodeId === currentNode && autostart && one.current === false) {
336
- one.current = true;
337
- dispatch({
338
- type: 'flower/next',
339
- payload: {
340
- flowName,
341
- isStart: true
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
- // if (global.window
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 = /*#__PURE__*/React.memo(FlowerStart);
326
+ const component$7 = React.memo(FlowerStart);
358
327
  component$7.displayName = 'FlowerStart';
359
328
 
360
- const FlowerRoute = ({
361
- autostart: _autostart = true,
362
- children,
363
- onEnter,
364
- onExit
365
- }) => {
366
- const dispatch = useDispatch();
367
- const one = React.useRef(false);
368
- const {
369
- flowName
370
- } = React.useContext(context);
371
- React.useEffect(() => {
372
- onEnter == null || onEnter();
373
- return () => {
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 = /*#__PURE__*/React.memo(FlowerRoute);
347
+ const component$6 = React.memo(FlowerRoute);
391
348
  component$6.displayName = 'FlowerRoute';
392
349
 
393
- function _extends() {
394
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
395
- for (var e = 1; e < arguments.length; e++) {
396
- var t = arguments[e];
397
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
398
- }
399
- return n;
400
- }, _extends.apply(null, arguments);
401
- }
402
- function _objectWithoutPropertiesLoose(r, e) {
403
- if (null == r) return {};
404
- var t = {};
405
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
406
- if (e.indexOf(n) >= 0) continue;
407
- t[n] = r[n];
408
- }
409
- return t;
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
- return children({
438
- hidden
439
- });
440
- }
441
- if (hidden) {
442
- return undefined;
443
- }
444
- return children({});
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 child;
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 = /*#__PURE__*/React.memo(FlowerRule);
392
+ const component$5 = React.memo(FlowerRule);
479
393
  component$5.displayName = 'FlowerRule';
480
394
 
481
- const _excluded$3 = ["Component", "id", "flowName", "currentNode", "validate", "asyncDebounce", "asyncValidate", "asyncInitialError", "asyncWaitingError", "destroyValue", "onBlur", "hidden", "onUpdate", "defaultValue"];
395
+ /* eslint-disable */
482
396
  function isIntrinsicElement$1(x) {
483
- return typeof x === 'string';
397
+ return typeof x === 'string';
484
398
  }
485
399
  //TODO make types for wrapper function props
486
- function Wrapper$1(_ref) {
487
- let {
488
- Component,
489
- id,
490
- flowName,
491
- currentNode,
492
- validate,
493
- asyncDebounce = 0,
494
- asyncValidate,
495
- asyncInitialError,
496
- asyncWaitingError,
497
- destroyValue,
498
- onBlur = val => null,
499
- hidden,
500
- onUpdate,
501
- defaultValue
502
- } = _ref,
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
- return;
536
- }
537
- setTouched(true);
538
- debouncedValidation(value);
539
- }
540
- }, [asyncValidate, asyncInitialError, value, debouncedValidation]);
541
- const touchedForm = useSelector(makeSelectNodeFormTouched(flowName, currentNode));
542
- const allErrors = React.useMemo(() => [...errors, ...(customErrors || []).filter(Boolean)], [errors, customErrors]);
543
- React.useEffect(() => {
544
- if (onUpdate) {
545
- onUpdate(value);
546
- }
547
- }, [value, onUpdate]);
548
- const onChange = React.useCallback(val => {
549
- dispatch({
550
- type: `flower/addDataByPath`,
551
- payload: {
552
- flowName: flowNameFromPath,
553
- id: path,
554
- value: val
555
- }
556
- });
557
- }, [flowNameFromPath, path, onBlur, dispatch]);
558
- const onBlurInternal = React.useCallback(e => {
559
- setTouched(true);
560
- onBlur && onBlur(e);
561
- }, [onBlur]);
562
- React.useLayoutEffect(() => {
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
- type: `flower/unsetData`,
589
- payload: {
590
- flowName: flowNameFromPath,
591
- id: path
592
- }
447
+ type: `flower/addDataByPath`,
448
+ payload: {
449
+ flowName: flowNameFromPath,
450
+ id: path,
451
+ value: val
452
+ }
593
453
  });
594
- }
595
- dispatch({
596
- type: 'flower/formRemoveErrors',
597
- payload: {
598
- name: flowName,
599
- id,
600
- currentNode
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
- }, [destroyValue]);
605
- React.useEffect(() => {
606
- if (defaultValue && !one.current) {
607
- one.current = true;
608
- onChange(defaultValue);
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
- }, [defaultValue, onChange]);
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
- id,
637
- validate,
638
- asyncValidate,
639
- asyncDebounce,
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
- const {
686
- type,
687
- props
688
- } = child;
689
- const Component = type;
690
- return /*#__PURE__*/React.createElement(component$5, {
691
- key: i,
692
- alwaysDisplay: alwaysDisplay,
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 = /*#__PURE__*/React.memo(FlowerField);
553
+ const component$4 = React.memo(FlowerField);
716
554
  component$4.displayName = 'FlowerField';
717
555
 
718
- const _excluded$2 = ["Component", "id", "flowName", "spreadValue", "hidden", "onUpdate"],
719
- _excluded2 = ["id", "alwaysDisplay", "rules", "value", "Component", "spreadValue", "flowName", "onUpdate"];
556
+ /* eslint-disable */
720
557
  //TODO make types for wrapper function
721
- function Wrapper(_ref) {
722
- let {
723
- Component,
724
- id,
725
- flowName,
726
- spreadValue,
727
- hidden,
728
- onUpdate
729
- } = _ref,
730
- props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
731
- const {
732
- flowNameFromPath = flowName,
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 = _ref2 => {
752
- let {
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
- id: _id = '*',
782
- rules,
783
- alwaysDisplay,
784
- value,
785
- children,
786
- spreadValue,
787
- flowName,
788
- onUpdate
789
- }) => {
790
- const {
791
- flowName: flowNameContext
792
- } = React.useContext(context);
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 = /*#__PURE__*/React.memo(FlowerValue);
589
+ const component$3 = React.memo(FlowerValue);
829
590
  component$3.displayName = 'FlowerValue';
830
591
 
831
592
  const ACTION_TYPES = {
832
- back: ['prev', 'prevToNode'],
833
- jump: ['node', 'node'],
834
- next: ['next', 'next'],
835
- restart: ['restart', 'restart'],
836
- reset: ['reset', 'initializeFromNode']
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
- back: ['node'],
840
- jump: ['node', 'history'],
841
- next: ['node', 'route', 'data'],
842
- restart: ['node'],
843
- reset: ['node', 'initialData']
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
- const rest = typeof params === 'string' ? {
847
- node: params
848
- } : params;
849
- const payload = _extends({
850
- flowName: (params == null ? void 0 : params.flowName) || flowName
851
- }, Object.fromEntries(Object.entries(rest != null ? rest : {}).filter(([k]) => keys.includes(k))));
852
- const type = !params || !payload.node ? actions[0] : actions[1];
853
- return {
854
- type,
855
- payload
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
- flowName: customFlowName,
883
- name
884
- } = {}) => {
885
- const dispatch = useDispatch();
886
- const {
887
- flowName: flowNameDefault,
888
- initialData
889
- } = React.useContext(context);
890
- const flowName = customFlowName || name || flowNameDefault;
891
- const nodeId = useSelector(makeSelectCurrentNodeId(flowName != null ? flowName : ''));
892
- const startId = useSelector(makeSelectStartNodeId(flowName != null ? flowName : ''));
893
- const emitNavigateEvent = React.useCallback(
894
- //TODO check this function is needed
895
- params => {
896
- /* istanbul ignore next */
897
- // eslint-disable-next-line no-underscore-dangle, no-undef
898
- if (_get(flowerCore.devtoolState, '__FLOWER_DEVTOOLS__')) {
899
- flowerCore.Emitter.emit('flower-devtool-from-client', {
900
- source: 'flower-client',
901
- action: 'FLOWER_NAVIGATE',
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
- name: flowName,
904
- time: new Date(),
905
- params
906
- });
907
- }
908
- }, [flowName, nodeId]);
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
- flowName,
1025
- action,
1026
- route,
1027
- node
1028
- }) => {
1029
- const {
1030
- flowName: flowNameContext
1031
- } = React.useContext(context);
1032
- const name = flowName || flowNameContext;
1033
- const {
1034
- next,
1035
- jump,
1036
- back,
1037
- reset,
1038
- restart
1039
- } = useFlower({
1040
- flowName: name
1041
- });
1042
- const onNavigate = React.useCallback(() => {
1043
- switch (action) {
1044
- case 'next':
1045
- next(route);
1046
- return;
1047
- case 'jump':
1048
- jump(node);
1049
- return;
1050
- case 'back':
1051
- back(node);
1052
- return;
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
- const _excluded$1 = ["hidden", "Component", "onNavigate"];
763
+ /* eslint-disable */
1071
764
  function isIntrinsicElement(x) {
1072
- return typeof x === 'string';
765
+ return typeof x === 'string';
1073
766
  }
1074
767
  //TODO type FlowerNavigateWrapper props
1075
- function FlowerNavigateWrapper(_ref) {
1076
- let {
1077
- hidden,
1078
- Component,
1079
- onNavigate
1080
- } = _ref,
1081
- props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
1082
- const newProps = React.useMemo(() => _extends({}, props, {
1083
- hidden,
1084
- onClick: onNavigate
1085
- }), [props, onNavigate]);
1086
- if (typeof Component === 'function') {
1087
- return Component(newProps);
1088
- }
1089
- // TODO si arriva in questa condizione quando si passa un componente primitivo es. div
1090
- // in questo caso non posso props custom di flower
1091
- if (isIntrinsicElement(Component)) {
1092
- return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
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 = /*#__PURE__*/React.memo(FlowerNavigateWrapper);
787
+ const component$2 = React.memo(FlowerNavigateWrapper);
1102
788
 
1103
- const _excluded = ["alwaysDisplay", "rules", "Component", "flowName", "onNavigate"];
789
+ /* eslint-disable */
1104
790
  //TODO type RenderRules props
1105
- const RenderRules = _ref => {
1106
- let {
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
- children,
1128
- flowName: forceFlowName,
1129
- action,
1130
- route,
1131
- node,
1132
- rules,
1133
- alwaysDisplay
1134
- }) => {
1135
- const {
1136
- onNavigate,
1137
- flowName
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 = /*#__PURE__*/React.memo(FlowerNavigate);
808
+ const component$1 = React.memo(FlowerNavigate);
1172
809
  component$1.displayName = 'FlowerNavigate';
1173
810
 
1174
- const FlowerComponent = ({
1175
- children
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
- flowName: customFlowName,
1198
- name
1199
- } = {}) => {
1200
- const {
1201
- flowName: flowNameDefault
1202
- } = React.useContext(context);
1203
- const dispatch = useDispatch();
1204
- const store = useStore();
1205
- const flowName = customFlowName || name || flowNameDefault || '';
1206
- const currentNode = useSelector(makeSelectCurrentNodeId(flowName));
1207
- const {
1208
- errors,
1209
- isValid,
1210
- touched,
1211
- isValidating
1212
- } = useSelector(makeSelectNodeErrors(flowName, currentNode));
1213
- const getData = React.useCallback(path => {
1214
- const {
1215
- flowNameFromPath = flowName,
1216
- path: newpath
1217
- } = flowerCore.CoreUtils.getPath(path);
1218
- return _get(store.getState(), ['flower', flowNameFromPath, 'data', ...newpath]);
1219
- }, [store, flowName]);
1220
- const setData = React.useCallback((val, path) => {
1221
- if (path) {
1222
- const {
1223
- flowNameFromPath = flowName,
1224
- path: newpath
1225
- } = flowerCore.CoreUtils.getPath(path);
1226
- dispatch(actions.addDataByPath({
1227
- flowName: flowNameFromPath,
1228
- id: Array.isArray(newpath) ? newpath : [newpath],
1229
- value: val
1230
- }));
1231
- return;
1232
- }
1233
- dispatch(actions.addData({
1234
- flowName,
1235
- value: val
1236
- }));
1237
- }, [flowName, dispatch]);
1238
- const unsetData = React.useCallback(path => {
1239
- const {
1240
- flowNameFromPath = flowName,
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;