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