@flowerforce/flower-react 3.1.1-beta.1 β 3.1.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +85 -10
- package/dist/index.cjs.js +126 -13
- package/dist/index.esm.js +128 -15
- package/dist/src/components/types/DefaultNode.d.ts +17 -0
- package/dist/src/components/types/FlowerComponent.d.ts +2 -0
- package/dist/src/components/types/FlowerField.d.ts +78 -0
- package/dist/src/components/types/FlowerFlow.d.ts +10 -0
- package/dist/src/components/types/FlowerHooks.d.ts +25 -2
- package/dist/src/components/types/FlowerNavigate.d.ts +14 -0
- package/dist/src/components/types/FlowerNode.d.ts +10 -0
- package/dist/src/components/types/FlowerRoute.d.ts +17 -0
- package/dist/src/components/types/FlowerRule.d.ts +23 -0
- package/dist/src/components/types/FlowerServer.d.ts +2 -0
- package/dist/src/components/types/FlowerValue.d.ts +22 -0
- package/dist/src/components/useFlower.d.ts +18 -0
- package/dist/src/components/useFlowerForm.d.ts +17 -0
- package/dist/src/provider.d.ts +7 -5
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
@@ -59,6 +59,7 @@ function Root() {
|
|
59
59
|
)
|
60
60
|
}
|
61
61
|
```
|
62
|
+
> You can pass the prop `enableReduxDevtool` to the `FlowerProvider` to show the Flower Store data inside the redux devtool of your browser.
|
62
63
|
|
63
64
|
## How to use
|
64
65
|
|
@@ -121,7 +122,8 @@ import {
|
|
121
122
|
export const Page = () => {
|
122
123
|
return (
|
123
124
|
<Flower name="demo">
|
124
|
-
|
125
|
+
{/* autonext */}
|
126
|
+
<FlowerRoute id="start" to={{ step1: null }} />
|
125
127
|
<FlowerNode
|
126
128
|
id="step1"
|
127
129
|
to={{
|
@@ -225,7 +227,7 @@ export const Page = () => {
|
|
225
227
|
id="step1"
|
226
228
|
to={{
|
227
229
|
step3: {
|
228
|
-
rules
|
230
|
+
rules: { $and: [{ skipStep2: { $eq: true } }] }
|
229
231
|
},
|
230
232
|
step2: null
|
231
233
|
}}
|
@@ -432,7 +434,14 @@ export const Page = () => {
|
|
432
434
|
<>
|
433
435
|
<button onClick={() => next()}>click me and go next</button>
|
434
436
|
|
435
|
-
<Flower name="demo"
|
437
|
+
<Flower name="demo">
|
438
|
+
<FlowerNode id="step1" to={{ step2: null }}>
|
439
|
+
...
|
440
|
+
<button onClick={() => next()}>click me and go next</button>
|
441
|
+
</FlowerNode>
|
442
|
+
|
443
|
+
<FlowerNode id="step2">...</FlowerNode>
|
444
|
+
</Flower>
|
436
445
|
</>
|
437
446
|
)
|
438
447
|
}
|
@@ -816,7 +825,7 @@ Devtool({
|
|
816
825
|
```jsx
|
817
826
|
Devtool({
|
818
827
|
remote: 'passKey',
|
819
|
-
sourceMap: require('./.flower.
|
828
|
+
sourceMap: require('./.flower.sourcemap.json')
|
820
829
|
})
|
821
830
|
```
|
822
831
|
|
@@ -824,20 +833,86 @@ To generate the source maps, add the command flower-sourcemap to your package.
|
|
824
833
|
|
825
834
|
```json
|
826
835
|
"scripts": {
|
827
|
-
"build-sourcemap": "flower generate-sourcemap
|
836
|
+
"build-sourcemap": "flower generate-sourcemap"
|
828
837
|
},
|
829
838
|
```
|
830
839
|
|
831
840
|
|
832
841
|
```bash
|
833
|
-
flower sourcemap --help
|
842
|
+
flower generate-sourcemap --help
|
843
|
+
|
844
|
+
-p, --pattern <type> Add glob for search <Flower/> files (default: "src/**/*.{js,ts,tsx,jsx}")
|
845
|
+
-d, --dirsave <type> The directory where to save the sourcemap (default: "src")
|
846
|
+
-h, --help Quick overview of usage options
|
847
|
+
-w, --watch Watch for files changes
|
848
|
+
```
|
849
|
+
|
850
|
+
|
851
|
+
> When you execute this command, you will receive the secretKey, which must be inserted into the `remote` field within the Devtool function.
|
852
|
+
|
853
|
+
# Using React components with the VS Code extension
|
854
|
+
|
855
|
+
With Flower, you can configure and use your components through a **graphical interface**. After creating the component in code, you need to associate it with a `JSON configuration file`. This file will be used by Flower to provide users the ability to configure each component's props via a graphical interface, **without writing code**.
|
856
|
+
|
857
|
+
|
858
|
+
For example, let's configure a `Text` component so that it can be used through Flower's graphical interface.
|
859
|
+
|
860
|
+
## Step-by-Step Guide
|
861
|
+
|
862
|
+
1) `Create the JSON File`
|
863
|
+
|
864
|
+
First, create the JSON file at the same level as the component file.
|
865
|
+
|
866
|
+
```
|
867
|
+
src
|
868
|
+
β
|
869
|
+
β
|
870
|
+
ββββcomponents
|
871
|
+
β β
|
872
|
+
β ββββText
|
873
|
+
β β index.tsx
|
874
|
+
β β text.flower.json
|
875
|
+
β β ...
|
876
|
+
...
|
877
|
+
```
|
878
|
+
|
879
|
+
2) `Insert the Basic Structure`
|
880
|
+
|
881
|
+
Once the file is created, insert the basic structure of the JSON file, which will be common to any component:
|
834
882
|
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
883
|
+
```json
|
884
|
+
{
|
885
|
+
"type": "component",
|
886
|
+
"name": "Text",
|
887
|
+
"category": "UI",
|
888
|
+
"description": "This is the Text component",
|
889
|
+
"editing": []
|
890
|
+
}
|
839
891
|
```
|
840
892
|
|
893
|
+
The keys in the JSON file have the following purposes:
|
894
|
+
- `type`: indicates what is being described with this JSON file, in this case, a component
|
895
|
+
- `name`: the name of the component being configured
|
896
|
+
- `category`: components are grouped into categories in Flower's graphical interface, so you can choose a category to which the component belongs
|
897
|
+
- `description`: a brief description of the component that will be displayed in the graphical interface. This is particularly useful for understanding the functionality of a specific component without reading the code
|
898
|
+
- `editing`: in this key, we will insert the options that will allow us to configure the component's behavior directly from the graphical interface
|
899
|
+
|
900
|
+
Once you have completed these two steps, you will be able to use your `Text component` through the graphical interface.
|
901
|
+
|
902
|
+
## Configuring the editing Field
|
903
|
+
|
904
|
+
Within the editing field, you can insert a series of entries that will allow us to choose the values of the props to pass to the component.
|
905
|
+
|
906
|
+
The editing field is an array of objects, one for each prop we want to configure, which contain the following keys:
|
907
|
+
|
908
|
+
1) `type`: Represents the type of field that will be used within the graphical interface. Possible basic values are `Input`, `Select`, `Switch`, `ButtonGroup`. In addition to these basic types, you can choose the `Rules` type, which allows you to insert rules directly from the graphical interface, and the `SelectNode` type, which allows you to have a Select populated with the nodes present in the flow.
|
909
|
+
2) `id`: Represents the name of the prop being configured
|
910
|
+
3) `label`: The label that will be displayed above the field in the graphical interface
|
911
|
+
4) `default`: Specifies a default value for that prop in case no value is configured on the graphical interface
|
912
|
+
5) `options`: An array of objects with keys `label` and `value` for the `Select` type, and `name` and `value` for the `ButtonGroup` type
|
913
|
+
|
914
|
+
In any case, there is a JSON schema that will guide you in writing the file associated with each component.
|
915
|
+
|
841
916
|
|
842
917
|
# Documentation
|
843
918
|
|
package/dist/index.cjs.js
CHANGED
@@ -14,6 +14,7 @@ const context = _context;
|
|
14
14
|
const Provider = _context.Provider;
|
15
15
|
const Consumer = _context.Consumer;
|
16
16
|
|
17
|
+
// eslint-disable-next-line import/prefer-default-export
|
17
18
|
const convertElements = nodes => {
|
18
19
|
const res = flowerCore.CoreUtils.generateNodesForFlowerJson(nodes);
|
19
20
|
return res;
|
@@ -45,7 +46,9 @@ const makeSelectStartNodeId = name => reselect.createSelector(selectFlower(name)
|
|
45
46
|
const makeSelectCurrentNodeId = name => reselect.createSelector(selectFlower(name), makeSelectStartNodeId(name), flowerCore.Selectors.makeSelectCurrentNodeId);
|
46
47
|
const makeSelectPrevNodeRetain = name => reselect.createSelector(makeSelectNodesIds(name), selectFlowerHistory(name), makeSelectCurrentNodeId(name), flowerCore.Selectors.makeSelectPrevNodeRetain);
|
47
48
|
const makeSelectCurrentNodeDisabled = name => reselect.createSelector(makeSelectNodesIds(name), makeSelectCurrentNodeId(name), flowerCore.Selectors.makeSelectCurrentNodeDisabled);
|
49
|
+
// dati nel flow selezionato
|
48
50
|
const getDataByFlow = name => reselect.createSelector(selectFlower(name), flowerCore.Selectors.getDataByFlow);
|
51
|
+
// selettore per recuperare i dati di un flow specifico e id specifico
|
49
52
|
const getDataFromState = (name, id) => reselect.createSelector(getDataByFlow(name), flowerCore.Selectors.getDataFromState(id));
|
50
53
|
const makeSelectNodeErrors = (name, currentNodeId) => reselect.createSelector(selectFlowerFormNode(name, currentNodeId), flowerCore.Selectors.makeSelectNodeErrors);
|
51
54
|
const makeSelectNodeFormTouched = (name, currentNodeId) => reselect.createSelector(selectFlowerFormNode(name, currentNodeId), flowerCore.Selectors.makeSelectNodeFormTouched);
|
@@ -53,6 +56,7 @@ const getAllData = reselect.createSelector(selectGlobal, mapData);
|
|
53
56
|
const makeSelectFieldError = (name, id, validate) => reselect.createSelector(getAllData, flowerCore.Selectors.makeSelectFieldError(name, id, validate));
|
54
57
|
const selectorRulesDisabled = (id, rules, keys, flowName, value, currentNode) => reselect.createSelector(getAllData, makeSelectNodeErrors(flowName, currentNode), flowerCore.Selectors.selectorRulesDisabled(id, rules, keys, flowName, value));
|
55
58
|
|
59
|
+
//TODO check reduxContext type due to remove all any types
|
56
60
|
const reduxContext = /*#__PURE__*/React.createContext(null);
|
57
61
|
const useDispatch = reactRedux.createDispatchHook(reduxContext);
|
58
62
|
const useSelector = reactRedux.createSelectorHook(reduxContext);
|
@@ -65,11 +69,11 @@ const store = ({
|
|
65
69
|
name: 'flower'
|
66
70
|
} : false
|
67
71
|
});
|
68
|
-
class FlowerProvider extends React.
|
72
|
+
class FlowerProvider extends React.PureComponent {
|
69
73
|
constructor(props) {
|
70
74
|
super(props);
|
71
75
|
this.store = store({
|
72
|
-
enableDevtool: props.
|
76
|
+
enableDevtool: props.enableReduxDevtool
|
73
77
|
});
|
74
78
|
}
|
75
79
|
render() {
|
@@ -83,6 +87,11 @@ class FlowerProvider extends React.Component {
|
|
83
87
|
}
|
84
88
|
}
|
85
89
|
|
90
|
+
/* eslint-disable no-undef */
|
91
|
+
/* eslint-disable no-underscore-dangle */
|
92
|
+
/**
|
93
|
+
* FlowerClient
|
94
|
+
*/
|
86
95
|
const FlowerClient = ({
|
87
96
|
children,
|
88
97
|
name,
|
@@ -93,7 +102,9 @@ const FlowerClient = ({
|
|
93
102
|
const flowName = name;
|
94
103
|
const dispatch = useDispatch();
|
95
104
|
const one = React.useRef(false);
|
96
|
-
const [wsDevtools, setWsDevtools] = React.useState(
|
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
|
97
108
|
const nodes = React.useMemo(() => convertElements(React.Children.toArray(children)), [children]);
|
98
109
|
const nodeById = React.useMemo(() => _keyBy(React.Children.toArray(children), 'props.id'), [children]);
|
99
110
|
const isInitialized = useSelector(makeSelectStartNodeId(name));
|
@@ -107,6 +118,7 @@ const FlowerClient = ({
|
|
107
118
|
one.current = true;
|
108
119
|
dispatch(actions.initNodes({
|
109
120
|
name: flowName,
|
121
|
+
// @ts-expect-error FIX ME
|
110
122
|
nodes,
|
111
123
|
startId: _startId != null ? _startId : '',
|
112
124
|
persist: _destroyOnUnmount === false,
|
@@ -115,6 +127,7 @@ const FlowerClient = ({
|
|
115
127
|
}
|
116
128
|
}, [dispatch, flowName, nodes, _startId, _initialData, _destroyOnUnmount]);
|
117
129
|
React.useEffect(() => {
|
130
|
+
/* istanbul ignore next */
|
118
131
|
const eventCb = msg => {
|
119
132
|
if (msg.source !== 'flower-devtool') return;
|
120
133
|
if (msg.action === 'FLOWER_EXTENSION_INIT' || msg.action === 'FLOWER_DEVTOOL_WEB_INIT') {
|
@@ -139,16 +152,19 @@ const FlowerClient = ({
|
|
139
152
|
}));
|
140
153
|
}
|
141
154
|
};
|
142
|
-
|
155
|
+
/* istanbul ignore next */
|
156
|
+
if (flowerCore.devtoolState && _get(flowerCore.devtoolState, '__FLOWER_DEVTOOLS__')) {
|
143
157
|
flowerCore.Emitter.on('flower-devtool-to-client', eventCb);
|
144
158
|
}
|
145
159
|
return () => {
|
146
|
-
|
160
|
+
/* istanbul ignore next */
|
161
|
+
if (flowerCore.devtoolState && _get(flowerCore.devtoolState, '__FLOWER_DEVTOOLS__')) {
|
147
162
|
flowerCore.Emitter.off('flower-devtool-to-client', eventCb);
|
148
163
|
}
|
149
164
|
};
|
150
165
|
}, [dispatch, flowName]);
|
151
166
|
React.useEffect(() => () => {
|
167
|
+
// unmount function
|
152
168
|
if (_destroyOnUnmount && one.current === true) {
|
153
169
|
one.current = false;
|
154
170
|
dispatch(actions.destroy({
|
@@ -157,7 +173,8 @@ const FlowerClient = ({
|
|
157
173
|
}
|
158
174
|
}, [dispatch, flowName, _destroyOnUnmount]);
|
159
175
|
React.useEffect(() => {
|
160
|
-
|
176
|
+
/* istanbul ignore next */
|
177
|
+
if (isInitialized && wsDevtools && flowerCore.devtoolState && _get(flowerCore.devtoolState, '__FLOWER_DEVTOOLS__')) {
|
161
178
|
flowerCore.Emitter.emit('flower-devtool-from-client', {
|
162
179
|
source: 'flower-client',
|
163
180
|
action: 'FLOWER_CLIENT_INIT',
|
@@ -169,7 +186,8 @@ const FlowerClient = ({
|
|
169
186
|
}
|
170
187
|
}, [dispatch, flowName, wsDevtools, isInitialized, store]);
|
171
188
|
React.useEffect(() => {
|
172
|
-
|
189
|
+
/* istanbul ignore next */
|
190
|
+
if (isInitialized && wsDevtools && flowerCore.devtoolState && _get(flowerCore.devtoolState, '__FLOWER_DEVTOOLS__')) {
|
173
191
|
flowerCore.Emitter.emit('flower-devtool-from-client', {
|
174
192
|
source: 'flower-client',
|
175
193
|
action: 'SET_HISTORY',
|
@@ -180,8 +198,10 @@ const FlowerClient = ({
|
|
180
198
|
}, [dispatch, flowName, history, wsDevtools, isInitialized]);
|
181
199
|
React.useEffect(() => {
|
182
200
|
if (!current) return;
|
201
|
+
/* istanbul ignore next */
|
183
202
|
if (!isInitialized) return;
|
184
|
-
|
203
|
+
/* istanbul ignore next */
|
204
|
+
if (isInitialized && wsDevtools && flowerCore.devtoolState && _get(flowerCore.devtoolState, '__FLOWER_DEVTOOLS__')) {
|
185
205
|
flowerCore.Emitter.emit('flower-devtool-from-client', {
|
186
206
|
source: 'flower-client',
|
187
207
|
action: 'SET_CURRENT',
|
@@ -192,6 +212,7 @@ const FlowerClient = ({
|
|
192
212
|
}, [flowName, current, wsDevtools, isInitialized]);
|
193
213
|
React.useEffect(() => {
|
194
214
|
if (!current) return;
|
215
|
+
/* istanbul ignore next */
|
195
216
|
if (!isInitialized) return;
|
196
217
|
if (isDisabled) {
|
197
218
|
dispatch({
|
@@ -201,7 +222,9 @@ const FlowerClient = ({
|
|
201
222
|
disabled: true
|
202
223
|
}
|
203
224
|
});
|
204
|
-
|
225
|
+
// eslint-disable-next-line no-underscore-dangle, no-undef
|
226
|
+
/* istanbul ignore next */
|
227
|
+
if (wsDevtools && flowerCore.devtoolState && _get(flowerCore.devtoolState, '__FLOWER_DEVTOOLS__')) {
|
205
228
|
flowerCore.Emitter.emit('flower-devtool-from-client', {
|
206
229
|
source: 'flower-client',
|
207
230
|
action: 'FLOWER_NAVIGATE',
|
@@ -219,8 +242,10 @@ const FlowerClient = ({
|
|
219
242
|
}
|
220
243
|
return;
|
221
244
|
}
|
222
|
-
|
223
|
-
|
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
|
224
249
|
flowerCore.Emitter.emit('flower-devtool-from-client', {
|
225
250
|
source: 'flower-client',
|
226
251
|
action: 'SET_SELECTED',
|
@@ -316,6 +341,15 @@ function FlowerStart() {
|
|
316
341
|
isStart: true
|
317
342
|
}
|
318
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
|
+
// }
|
319
353
|
}
|
320
354
|
}, [dispatch, autostart, startNodeId, currentNode, flowName]);
|
321
355
|
return null;
|
@@ -417,6 +451,7 @@ const FlowerRule = ({
|
|
417
451
|
type
|
418
452
|
} = child;
|
419
453
|
const Component = type;
|
454
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
420
455
|
return Component && /*#__PURE__*/React.createElement(Component, _extends({
|
421
456
|
key: i,
|
422
457
|
hidden: true
|
@@ -432,6 +467,7 @@ const FlowerRule = ({
|
|
432
467
|
type
|
433
468
|
} = child;
|
434
469
|
const Component = type;
|
470
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
435
471
|
return Component && /*#__PURE__*/React.createElement(Component, _extends({
|
436
472
|
key: i
|
437
473
|
}, props));
|
@@ -446,6 +482,7 @@ const _excluded$3 = ["Component", "id", "flowName", "currentNode", "validate", "
|
|
446
482
|
function isIntrinsicElement$1(x) {
|
447
483
|
return typeof x === 'string';
|
448
484
|
}
|
485
|
+
//TODO make types for wrapper function props
|
449
486
|
function Wrapper$1(_ref) {
|
450
487
|
let {
|
451
488
|
Component,
|
@@ -544,6 +581,7 @@ function Wrapper$1(_ref) {
|
|
544
581
|
});
|
545
582
|
}, [flowName, currentNode, isValidating]);
|
546
583
|
React.useLayoutEffect(() => {
|
584
|
+
// destroy
|
547
585
|
return () => {
|
548
586
|
if (destroyValue) {
|
549
587
|
dispatch({
|
@@ -585,6 +623,8 @@ function Wrapper$1(_ref) {
|
|
585
623
|
if (typeof Component === 'function') {
|
586
624
|
return Component(newProps);
|
587
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
|
588
628
|
if (isIntrinsicElement$1(Component)) {
|
589
629
|
return /*#__PURE__*/React.createElement(Component, _extends({
|
590
630
|
id: id
|
@@ -677,6 +717,7 @@ component$4.displayName = 'FlowerField';
|
|
677
717
|
|
678
718
|
const _excluded$2 = ["Component", "id", "flowName", "spreadValue", "hidden", "onUpdate"],
|
679
719
|
_excluded2 = ["id", "alwaysDisplay", "rules", "value", "Component", "spreadValue", "flowName", "onUpdate"];
|
720
|
+
//TODO make types for wrapper function
|
680
721
|
function Wrapper(_ref) {
|
681
722
|
let {
|
682
723
|
Component,
|
@@ -769,6 +810,7 @@ const FlowerValue = ({
|
|
769
810
|
props
|
770
811
|
} = child;
|
771
812
|
const Component = type;
|
813
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
772
814
|
return /*#__PURE__*/React.createElement(RenderRules$1, _extends({
|
773
815
|
key: i,
|
774
816
|
id: _id,
|
@@ -818,6 +860,24 @@ const makeActionPayloadOnReset = makeActionPayload(ACTION_TYPES.reset, PAYLAOAD_
|
|
818
860
|
const makeActionPayloadOnNode = makeActionPayload(ACTION_TYPES.jump, PAYLAOAD_KEYS_NEEDED.jump);
|
819
861
|
const makeActionPayloadOnNext = makeActionPayload(ACTION_TYPES.next, PAYLAOAD_KEYS_NEEDED.next);
|
820
862
|
const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart, PAYLAOAD_KEYS_NEEDED.restart);
|
863
|
+
/** This hook allows you to read flow informations, such as the flowName and ID of the current node.
|
864
|
+
*
|
865
|
+
* It also exposes all the functions to navigate within the flow:
|
866
|
+
*
|
867
|
+
* - next
|
868
|
+
*
|
869
|
+
* - back
|
870
|
+
*
|
871
|
+
* - jump
|
872
|
+
*
|
873
|
+
* - reset
|
874
|
+
*
|
875
|
+
* - restart
|
876
|
+
*
|
877
|
+
* @param {string} flowName - first optional parameter
|
878
|
+
*
|
879
|
+
* @param {string} name - optional parameter, if flowName exist, name is not used
|
880
|
+
*/
|
821
881
|
const useFlower = ({
|
822
882
|
flowName: customFlowName,
|
823
883
|
name
|
@@ -829,8 +889,13 @@ const useFlower = ({
|
|
829
889
|
} = React.useContext(context);
|
830
890
|
const flowName = customFlowName || name || flowNameDefault;
|
831
891
|
const nodeId = useSelector(makeSelectCurrentNodeId(flowName != null ? flowName : ''));
|
832
|
-
const
|
833
|
-
|
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__')) {
|
834
899
|
flowerCore.Emitter.emit('flower-devtool-from-client', {
|
835
900
|
source: 'flower-client',
|
836
901
|
action: 'FLOWER_NAVIGATE',
|
@@ -924,6 +989,7 @@ const useFlower = ({
|
|
924
989
|
return {
|
925
990
|
flowName,
|
926
991
|
nodeId,
|
992
|
+
startId,
|
927
993
|
next,
|
928
994
|
jump,
|
929
995
|
back,
|
@@ -932,6 +998,28 @@ const useFlower = ({
|
|
932
998
|
};
|
933
999
|
};
|
934
1000
|
|
1001
|
+
/* eslint-disable */
|
1002
|
+
// {
|
1003
|
+
// flowName?: string | undefined;
|
1004
|
+
// action?: 'next' | 'back' | 'reset' | 'jump';
|
1005
|
+
// } & (
|
1006
|
+
// | {
|
1007
|
+
// node?: undefined;
|
1008
|
+
// route?: Route;
|
1009
|
+
// }
|
1010
|
+
// | {
|
1011
|
+
// node?: RoutePrev;
|
1012
|
+
// route?: undefined;
|
1013
|
+
// }
|
1014
|
+
// | {
|
1015
|
+
// node?: RouteReset;
|
1016
|
+
// route?: undefined;
|
1017
|
+
// }
|
1018
|
+
// | {
|
1019
|
+
// node?: RouteNode;
|
1020
|
+
// route?: undefined;
|
1021
|
+
// }
|
1022
|
+
// );
|
935
1023
|
const useFlowerNavigate = ({
|
936
1024
|
flowName,
|
937
1025
|
action,
|
@@ -983,6 +1071,7 @@ const _excluded$1 = ["hidden", "Component", "onNavigate"];
|
|
983
1071
|
function isIntrinsicElement(x) {
|
984
1072
|
return typeof x === 'string';
|
985
1073
|
}
|
1074
|
+
//TODO type FlowerNavigateWrapper props
|
986
1075
|
function FlowerNavigateWrapper(_ref) {
|
987
1076
|
let {
|
988
1077
|
hidden,
|
@@ -997,16 +1086,22 @@ function FlowerNavigateWrapper(_ref) {
|
|
997
1086
|
if (typeof Component === 'function') {
|
998
1087
|
return Component(newProps);
|
999
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
|
1000
1091
|
if (isIntrinsicElement(Component)) {
|
1001
1092
|
return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
|
1002
1093
|
onClick: onNavigate
|
1003
1094
|
}));
|
1004
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 */
|
1005
1099
|
return Component && /*#__PURE__*/React.createElement(Component, _extends({}, newProps));
|
1006
1100
|
}
|
1007
1101
|
const component$2 = /*#__PURE__*/React.memo(FlowerNavigateWrapper);
|
1008
1102
|
|
1009
1103
|
const _excluded = ["alwaysDisplay", "rules", "Component", "flowName", "onNavigate"];
|
1104
|
+
//TODO type RenderRules props
|
1010
1105
|
const RenderRules = _ref => {
|
1011
1106
|
let {
|
1012
1107
|
alwaysDisplay,
|
@@ -1062,6 +1157,7 @@ const FlowerNavigate = ({
|
|
1062
1157
|
props
|
1063
1158
|
} = child;
|
1064
1159
|
const Component = type;
|
1160
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
1065
1161
|
return /*#__PURE__*/React.createElement(RenderRules, _extends({
|
1066
1162
|
key: i,
|
1067
1163
|
alwaysDisplay: alwaysDisplay,
|
@@ -1080,6 +1176,23 @@ const FlowerComponent = ({
|
|
1080
1176
|
}) => children;
|
1081
1177
|
const component = /*#__PURE__*/React.memo(FlowerComponent);
|
1082
1178
|
|
1179
|
+
/** This hook allows you to manage and retrieve information about Forms.
|
1180
|
+
*
|
1181
|
+
* It exposes details regarding the form's state and a set of methods for reading and writing within it:
|
1182
|
+
*
|
1183
|
+
* - getData
|
1184
|
+
*
|
1185
|
+
* - setData
|
1186
|
+
*
|
1187
|
+
* - unSetData
|
1188
|
+
*
|
1189
|
+
* - replaceData
|
1190
|
+
*
|
1191
|
+
* @param {string} flowName - first optional parameter
|
1192
|
+
*
|
1193
|
+
* @param {string} name - optional parameter, if flowName exist, name is not used
|
1194
|
+
*
|
1195
|
+
*/
|
1083
1196
|
const useFlowerForm = ({
|
1084
1197
|
flowName: customFlowName,
|
1085
1198
|
name
|