@flowerforce/flower-react 3.5.1-beta.2 → 4.0.3-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/README.md +261 -202
- package/dist/index.cjs.js +214 -630
- package/dist/index.esm.js +184 -604
- package/dist/src/components/Flower.d.ts +7 -7
- package/dist/src/components/FlowerAction.d.ts +2 -3
- package/dist/src/components/FlowerComponent.d.ts +2 -4
- package/dist/src/components/FlowerFlow.d.ts +2 -3
- package/dist/src/components/FlowerNavigate/FlowerNavigate.d.ts +3 -0
- package/dist/src/components/FlowerNavigate/WrapperComponent.d.ts +3 -3
- package/dist/src/components/FlowerNavigate/index.d.ts +2 -4
- package/dist/src/components/FlowerNavigate/useFlowerNavigate.d.ts +1 -1
- package/dist/src/components/FlowerNode.d.ts +2 -3
- package/dist/src/components/FlowerRoute.d.ts +2 -3
- package/dist/src/components/FlowerServer.d.ts +2 -3
- package/dist/src/components/FlowerStart.d.ts +3 -4
- package/dist/src/components/index.d.ts +10 -0
- package/dist/src/components/useFlower/utils.d.ts +20 -0
- package/dist/src/components/useFlower.d.ts +2 -3
- package/dist/src/features/index.d.ts +2 -0
- package/dist/src/features/reducer/flowerReducer.d.ts +6 -0
- package/dist/src/{selectors.d.ts → features/selectors/selectors.d.ts} +474 -363
- package/dist/src/index.d.ts +5 -33
- package/dist/src/provider/index.d.ts +1 -0
- package/dist/src/provider/provider.d.ts +8 -0
- package/dist/src/types/FlowContext.d.ts +6 -0
- package/dist/src/types/FlowerHooks.d.ts +27 -0
- package/dist/src/{components/types → types}/FlowerProvider.d.ts +3 -3
- package/dist/src/types/index.d.ts +10 -0
- package/package.json +5 -2
- package/dist/src/components/FlowerField.d.ts +0 -4
- package/dist/src/components/FlowerRule.d.ts +0 -4
- package/dist/src/components/FlowerValue.d.ts +0 -4
- package/dist/src/components/types/FlowerField.d.ts +0 -124
- package/dist/src/components/types/FlowerHooks.d.ts +0 -72
- package/dist/src/components/types/FlowerRule.d.ts +0 -35
- package/dist/src/components/types/FlowerValue.d.ts +0 -33
- package/dist/src/components/useFlowerForm.d.ts +0 -26
- package/dist/src/context.d.ts +0 -10
- package/dist/src/provider.d.ts +0 -25
- package/dist/src/reducer.d.ts +0 -7
- /package/dist/src/{components/types → types}/DefaultNode.d.ts +0 -0
- /package/dist/src/{components/types → types}/FlowerComponent.d.ts +0 -0
- /package/dist/src/{components/types → types}/FlowerFlow.d.ts +0 -0
- /package/dist/src/{components/types → types}/FlowerNavigate.d.ts +0 -0
- /package/dist/src/{components/types → types}/FlowerNode.d.ts +0 -0
- /package/dist/src/{components/types → types}/FlowerRoute.d.ts +0 -0
- /package/dist/src/{components/types → types}/FlowerServer.d.ts +0 -0
package/README.md
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
<a alt="Flower logo" href="https://flowerjs.it/" target="_blank" rel="noreferrer"><img src="https://flowerjs.it/_next/static/media/flower-logo.bb32f863.svg" width="50"></a>
|
4
4
|
|
5
|
-
Flower React is a front-end development library built on top of Flower Core, specifically designed for React applications.
|
5
|
+
Flower React is a front-end development library built on top of Flower Core, specifically designed for React applications.
|
6
|
+
It seamlessly integrates Flower's powerful capabilities into React projects, providing a user-friendly interface to create, modify, and monitor workflows.
|
6
7
|
|
7
8
|
For more info [flowerjs.it/](https://flowerjs.it/)
|
8
9
|
|
@@ -10,13 +11,11 @@ For more info [flowerjs.it/](https://flowerjs.it/)
|
|
10
11
|
|
11
12
|
## Features
|
12
13
|
|
13
|
-
- **Workflow Management**: Comprehensive API
|
14
|
+
- **Workflow Management**: Comprehensive API to create, update, and manage workflows programmatically.
|
14
15
|
- **Node and Connection Handling**: Functions to manage nodes and connections, including adding, removing, and editing.
|
15
16
|
- **State Management**: Built-in state management to keep track of workflow changes and updates.
|
16
17
|
- **Event System**: Customizable event handling to respond to user interactions and changes within the workflow.
|
17
18
|
- **Serialization**: Convert workflows to JSON for easy storage and retrieval. (only server side flow)
|
18
|
-
- **Validation**: Ensure workflows follow predefined rules and constraints to maintain integrity.
|
19
|
-
- **Form Validation**: Built-in functionalities to validate form inputs within nodes, ensuring data integrity and correctness.
|
20
19
|
- **History Management**: Internal management of flow history, tracking node traversal and changes for debugging and visualization purposes.
|
21
20
|
|
22
21
|
### Installation
|
@@ -45,7 +44,7 @@ yarn add @flowerforce/flower-react
|
|
45
44
|
|
46
45
|
## Configuration
|
47
46
|
|
48
|
-
The **FlowerProvider** component wraps the entire application, providing a global context
|
47
|
+
The **FlowerProvider** component wraps the entire application, providing a global redux context to manage the application flow.
|
49
48
|
|
50
49
|
```jsx
|
51
50
|
import React from 'react'
|
@@ -59,13 +58,45 @@ function Root() {
|
|
59
58
|
)
|
60
59
|
}
|
61
60
|
```
|
61
|
+
> FlowerProvider accepts some properties such as `reducers` and `configureStoreOptions` in order to inject custom reducers into redux instance provided by FlowerProvider component.
|
62
|
+
N.B.: actions and selectors from your custom reducers must use `useSelector` and `useDispatch` provided by flower-react
|
63
|
+
```jsx
|
64
|
+
import React from 'react'
|
65
|
+
import { customReducer, customReducer2 } from 'my-custom-reducers'
|
66
|
+
import { Flower, FlowerProvider } from '@flowerforce/flower-react'
|
67
|
+
|
68
|
+
const reducers = {
|
69
|
+
customReducer: customReducer.reducer,
|
70
|
+
customReducer2: customReducer2.reducer
|
71
|
+
}
|
72
|
+
|
73
|
+
function Root() {
|
74
|
+
return (
|
75
|
+
<FlowerProvider reducers={reducers}>
|
76
|
+
<App />
|
77
|
+
</FlowerProvider>
|
78
|
+
)
|
79
|
+
}
|
80
|
+
```
|
62
81
|
> You can pass the prop `enableReduxDevtool` to the `FlowerProvider` to show the Flower Store data inside the redux devtool of your browser.
|
82
|
+
```jsx
|
83
|
+
import React from 'react'
|
84
|
+
import { customReducer, customReducer2 } from 'my-custom-reducers'
|
85
|
+
import { Flower, FlowerProvider } from '@flowerforce/flower-react'
|
63
86
|
|
87
|
+
function Root() {
|
88
|
+
return (
|
89
|
+
<FlowerProvider enableReduxDevtool>
|
90
|
+
<App />
|
91
|
+
</FlowerProvider>
|
92
|
+
)
|
93
|
+
}
|
94
|
+
```
|
64
95
|
## How to use
|
65
96
|
|
66
97
|
### Simple Example
|
67
98
|
|
68
|
-
The **Flower** component defines an application flow with a specific name, which serves as a unique identifier for the flow. It is the main component
|
99
|
+
The **Flower** component defines an application flow with a specific name, which serves as a unique identifier for the flow. It is the main component to define the application flow, accepting a required "name" property and an initialData field to prepopulate values.
|
69
100
|
|
70
101
|
The **FlowerNode** component represents a UI state or a step within the application flow. Transitions between nodes can be specified using the **to** object.
|
71
102
|
|
@@ -106,7 +137,7 @@ export const Page = () => {
|
|
106
137
|
Edit on [codesandbox/](https://codesandbox.io/p/sandbox/flower-react-example-1-9wsjv7)
|
107
138
|
|
108
139
|
|
109
|
-
> In addition you can pass the prop ***initialState*** to the `<Flower>` component
|
140
|
+
> In addition you can pass the prop ***initialState*** to the `<Flower>` component
|
110
141
|
|
111
142
|
This prop allows you to configure the following fields:
|
112
143
|
|
@@ -133,7 +164,7 @@ export const Page = () => {
|
|
133
164
|
return (
|
134
165
|
<Flower name="demo">
|
135
166
|
{/* autonext */}
|
136
|
-
<FlowerRoute id="start" to={{ step1: null }} />
|
167
|
+
<FlowerRoute id="start" to={{ step1: null }} />
|
137
168
|
<FlowerNode
|
138
169
|
id="step1"
|
139
170
|
to={{
|
@@ -210,64 +241,6 @@ export const Page = () => {
|
|
210
241
|
|
211
242
|
Edit on [codesandbox/](https://codesandbox.io/p/sandbox/flower-react-example-1-forked-5c4rs4)
|
212
243
|
|
213
|
-
### Basic WRITE | READ State
|
214
|
-
|
215
|
-
To modify the internal state of Flower, besides passing initialData as a prop, we can always modify and read the state through the components **FlowerField** and **FlowerValue**.
|
216
|
-
|
217
|
-
_FlowerField_ pass two props, onChange and value, to properly modify and read the value from the state of Flower.
|
218
|
-
_FlowerValue_ pass value, to properly read the value from the state of Flower.
|
219
|
-
|
220
|
-
Here's an example of how it works:
|
221
|
-
|
222
|
-
```jsx
|
223
|
-
import React from 'react'
|
224
|
-
import {
|
225
|
-
Flower,
|
226
|
-
FlowerRoute,
|
227
|
-
FlowerNavigate,
|
228
|
-
FlowerNode,
|
229
|
-
FlowerField,
|
230
|
-
FlowerValue
|
231
|
-
} from '@flowerforce/flower-react'
|
232
|
-
|
233
|
-
export const Page = () => {
|
234
|
-
return (
|
235
|
-
<Flower name="demo">
|
236
|
-
<FlowerNode
|
237
|
-
id="step1"
|
238
|
-
to={{
|
239
|
-
step3: {
|
240
|
-
rules: { $and: [{ skipStep2: { $eq: true } }] }
|
241
|
-
},
|
242
|
-
step2: null
|
243
|
-
}}
|
244
|
-
>
|
245
|
-
...
|
246
|
-
|
247
|
-
<FlowerField id="skipStep2">
|
248
|
-
{({ onChange, value }) => <input type="checkbox" checked={value} onChange={e => onChange(e.target.checked)} />}
|
249
|
-
</FlowerField>
|
250
|
-
|
251
|
-
<FlowerNavigate action="next">
|
252
|
-
<button>click me to go next</button>
|
253
|
-
</FlowerNavigate>
|
254
|
-
</FlowerNode>
|
255
|
-
|
256
|
-
<FlowerNode id="step2">...</FlowerNode>
|
257
|
-
|
258
|
-
<FlowerNode id="step3">
|
259
|
-
<FlowerValue id="enableFinal">
|
260
|
-
{({ value }) => <span>skipStep2: {String(!!value)}</span>}
|
261
|
-
</FlowerValue>
|
262
|
-
</FlowerNode>
|
263
|
-
|
264
|
-
</Flower>
|
265
|
-
)
|
266
|
-
}
|
267
|
-
|
268
|
-
```
|
269
|
-
|
270
|
-
Edit on [codesandbox/](https://codesandbox.io/p/sandbox/flower-react-example-3-forked-r3hgnj)
|
271
244
|
|
272
245
|
### Action Node
|
273
246
|
|
@@ -424,7 +397,7 @@ export const Page = () => {
|
|
424
397
|
|
425
398
|
Edit on [codesandbox/](https://codesandbox.io/p/sandbox/flower-react-example-1-forked-6wj3l9)
|
426
399
|
|
427
|
-
#### External use
|
400
|
+
#### External use of useFlower
|
428
401
|
|
429
402
|
```jsx
|
430
403
|
import React from 'react'
|
@@ -461,9 +434,9 @@ Edit on [codesandbox/](https://codesandbox.io/p/sandbox/flower-react-example-1-f
|
|
461
434
|
|
462
435
|
### Utils Callback onEnter - onExit
|
463
436
|
|
464
|
-
onEnter (function): A callback function that is executed when entering the node state. It's useful
|
437
|
+
onEnter (function): A callback function that is executed when entering the node state. It's useful to perform specific operations when the user transitions to this state.
|
465
438
|
|
466
|
-
onExit (function): A callback function that is executed when exiting the node state. It's useful
|
439
|
+
onExit (function): A callback function that is executed when exiting the node state. It's useful to perform specific operations when the user leaves this state.
|
467
440
|
|
468
441
|
```jsx
|
469
442
|
import React from 'react'
|
@@ -499,24 +472,230 @@ export const Page = () => {
|
|
499
472
|
}
|
500
473
|
```
|
501
474
|
|
502
|
-
## Form
|
503
475
|
|
504
|
-
Flower enables the quick creation of forms.
|
505
476
|
|
506
|
-
It keeps track of the form's validity status. This status not only facilitates displaying error messages to the user but can also be leveraged for implementing flow rules.
|
507
477
|
|
508
|
-
|
478
|
+
## Operators Rules
|
479
|
+
|
480
|
+
The "rules" in Flower are used to define conditions and conditional behaviors within the workflow. These rules allow to dynamically change the display or behavior of certain fields or components based on specific conditions.
|
481
|
+
|
482
|
+
The rules schema follows the MongoDB style, below is the list of available operators:
|
483
|
+
|
484
|
+
- $exists: Checks if a value exists or not.
|
485
|
+
- $eq: Checks if two values are equal.
|
486
|
+
- $ne: Checks if two values are not equal.
|
487
|
+
- $gt: Checks if the first value is greater than the second.
|
488
|
+
- $gte: Checks if the first value is greater than or equal to the second.
|
489
|
+
- $lt: Checks if the first value is less than the second.
|
490
|
+
- $lte: Checks if the first value is less than or equal to the second.
|
491
|
+
- $strGt: Checks if the length of a string is greater than the specified value.
|
492
|
+
- $strGte: Checks if the length of a string is greater than or equal to the specified value.
|
493
|
+
- $strLt: Checks if the length of a string is less than the specified value.
|
494
|
+
- $strLte: Checks if the length of a string is less than or equal to the specified value.
|
495
|
+
- $in: Checks if a value is present in a given array.
|
496
|
+
- $nin: Checks if a value is not present in a given array.
|
497
|
+
- $all: Checks if all values are present in a given array.
|
498
|
+
- $regex: Checks if a string matches a regular expression.
|
499
|
+
|
500
|
+
### Examples
|
501
|
+
|
502
|
+
Rules in $and | $or
|
503
|
+
|
504
|
+
```jsx
|
505
|
+
<FlowerNode id="node"
|
506
|
+
to={{
|
507
|
+
node2: {
|
508
|
+
rules: { $and: [
|
509
|
+
{ myValue: { $exists: true } },
|
510
|
+
{ myValue: { $strGt: 6 } }
|
511
|
+
|
512
|
+
]}
|
513
|
+
}
|
514
|
+
}}>
|
515
|
+
...
|
516
|
+
</Flower>
|
517
|
+
|
518
|
+
<FlowerNode id="node"
|
519
|
+
to={{
|
520
|
+
node2: {
|
521
|
+
rules: { $or: [
|
522
|
+
{ myValue: { $exists: false } },
|
523
|
+
{ myValue: { $strGt: 6 } }
|
524
|
+
|
525
|
+
]}
|
526
|
+
}
|
527
|
+
}}>
|
528
|
+
...
|
529
|
+
</Flower>
|
530
|
+
|
531
|
+
```
|
532
|
+
|
533
|
+
Compare state value, use '$ref:'
|
534
|
+
|
535
|
+
```jsx
|
536
|
+
<Flower name="demo" initialData={{ myValue1: 'test', myValue2: 'test2' }}>
|
537
|
+
<FlowerNode id="node"
|
538
|
+
to={{
|
539
|
+
node2: {
|
540
|
+
rules: [
|
541
|
+
{ myValue1: { $eq: '$ref:myValue2' } }
|
542
|
+
]}
|
543
|
+
}}>
|
544
|
+
...
|
545
|
+
</Flower>
|
546
|
+
```
|
547
|
+
|
548
|
+
## Display Rules
|
549
|
+
|
550
|
+
Showing or Hiding Fields: You can use rules to show or hide specific fields based on user choices. For example, hiding a "Buttons" unless the user selects a certain option.
|
551
|
+
|
552
|
+
We can use the FlowerRule component to hide a part of the UI according to certain rules.
|
553
|
+
|
554
|
+
If the "alwaysDisplay" property is passed, however, the component will not be automatically hidden, but a "hidden" property will be provided when the rules are not met.
|
555
|
+
|
556
|
+
### Example
|
509
557
|
|
510
558
|
```jsx
|
559
|
+
import React from 'react'
|
511
560
|
import {
|
512
561
|
Flower,
|
562
|
+
FlowerRoute,
|
563
|
+
FlowerNode,
|
564
|
+
FlowerRule,
|
565
|
+
FlowerNavigate
|
566
|
+
} from '@flowerforce/flower-react'
|
567
|
+
|
568
|
+
export const Page = () => {
|
569
|
+
return (
|
570
|
+
<Flower name="demo" initialData={{ enableNav: true }}>
|
571
|
+
<FlowerNode id="step1" to={{ step2: null }}>
|
572
|
+
...
|
573
|
+
{/* show / hidden based on rule */}
|
574
|
+
<FlowerRule rules={{ enableNav: { $eq: true } }}>
|
575
|
+
<p>Buttons nav are enabled</p>
|
576
|
+
</FlowerRule>
|
577
|
+
{/* always visible component, hidden prop is true when rule is not matched */}
|
578
|
+
<FlowerNavigate
|
579
|
+
action="next"
|
580
|
+
rules={{ enableNav: { $eq: true } }}
|
581
|
+
alwaysDisplay
|
582
|
+
>
|
583
|
+
{({ onClick, hidden }) => (
|
584
|
+
<button disabled={hidden} onClick={onClick}>
|
585
|
+
Next →
|
586
|
+
</button>
|
587
|
+
)}
|
588
|
+
</FlowerNavigate>
|
589
|
+
{/* visible only when rule is matched */}
|
590
|
+
<FlowerNavigate action="reset" rules={{ enableNav: { $eq: true } }}>
|
591
|
+
<button>Reset</button>
|
592
|
+
</FlowerNavigate>
|
593
|
+
</FlowerNode>
|
594
|
+
...
|
595
|
+
</Flower>
|
596
|
+
)
|
597
|
+
}
|
598
|
+
```
|
599
|
+
|
600
|
+
Edit on [codesandbox/](https://codesandbox.io/p/sandbox/flower-react-example-1-forked-sfn6ml)
|
601
|
+
|
602
|
+
|
603
|
+
# FlowerForm Integrations
|
604
|
+
Next to FlowerReact, we find FlowerForm, another library designed to manage data and forms independently from the flow process.
|
605
|
+
(add link to new form documentation)
|
606
|
+
|
607
|
+
### Basic WRITE | READ State - move this in form
|
608
|
+
|
609
|
+
To modify the internal state of Flower, besides passing initialData as a prop, we can always modify and read the state through the components **FlowerField** and **FlowerValue**.
|
610
|
+
|
611
|
+
N.B.: We must use FlowerField component provided by `@flowerforce/flower-react-form`
|
612
|
+
N.B.: We must use FlowerValue component provided by `@flowerforce/flower-react-shared`
|
613
|
+
|
614
|
+
|
615
|
+
_FlowerField_ pass two props, onChange and value, to properly modify and read the value from the state of Flower.
|
616
|
+
_FlowerValue_ pass value, to properly read the value from the state of Flower.
|
617
|
+
|
618
|
+
Here's an example of how it works:
|
619
|
+
|
620
|
+
```jsx
|
621
|
+
import React from 'react'
|
622
|
+
import {
|
623
|
+
Flower,
|
624
|
+
FlowerRoute,
|
513
625
|
FlowerNavigate,
|
514
626
|
FlowerNode,
|
515
627
|
FlowerField,
|
628
|
+
} from '@flowerforce/flower-react'
|
629
|
+
|
630
|
+
|
631
|
+
import {
|
632
|
+
FlowerField,
|
633
|
+
} from '@flowerforce/flower-react-form'
|
634
|
+
|
635
|
+
import { FlowerValue } from '@flowerforce/flower-react-shared'
|
636
|
+
|
637
|
+
|
638
|
+
export const Page = () => {
|
639
|
+
return (
|
640
|
+
<Flower name="demo">
|
641
|
+
<FlowerNode
|
642
|
+
id="step1"
|
643
|
+
to={{
|
644
|
+
step3: {
|
645
|
+
rules: { $and: [{ skipStep2: { $eq: true } }] }
|
646
|
+
},
|
647
|
+
step2: null
|
648
|
+
}}
|
649
|
+
>
|
650
|
+
...
|
651
|
+
|
652
|
+
<FlowerField id="skipStep2">
|
653
|
+
{({ onChange, value }) => <input type="checkbox" checked={value} onChange={e => onChange(e.target.checked)} />}
|
654
|
+
</FlowerField>
|
655
|
+
|
656
|
+
<FlowerNavigate action="next">
|
657
|
+
<button>click me to go next</button>
|
658
|
+
</FlowerNavigate>
|
659
|
+
</FlowerNode>
|
660
|
+
|
661
|
+
<FlowerNode id="step2">...</FlowerNode>
|
662
|
+
|
663
|
+
<FlowerNode id="step3">
|
664
|
+
<FlowerValue id="enableFinal">
|
665
|
+
{({ value }) => <span>skipStep2: {String(!!value)}</span>}
|
666
|
+
</FlowerValue>
|
667
|
+
</FlowerNode>
|
668
|
+
|
669
|
+
</Flower>
|
670
|
+
)
|
671
|
+
}
|
672
|
+
|
673
|
+
```
|
674
|
+
|
675
|
+
Edit on [codesandbox/](https://codesandbox.io/p/sandbox/flower-react-example-3-forked-r3hgnj)
|
676
|
+
|
677
|
+
## Form - move this in form
|
678
|
+
N.B.: `@flowerforce/flower-react-form` provides its own provider `FormProvider` and an equivalent of `<Flower>` component called `<FlowerForm>`
|
679
|
+
In this case we don't need to use it as form components reads from <Flower> context and mantains consistency between flowname and formname
|
680
|
+
|
681
|
+
For more info [flowerjs.it/flower-react-form](https://flowerjs.it/flower-react-form) /// we must generate pages in website for specific documentation
|
682
|
+
|
683
|
+
### Basic Usage
|
684
|
+
|
685
|
+
```jsx
|
686
|
+
import {
|
687
|
+
Flower,
|
688
|
+
FlowerNavigate,
|
689
|
+
FlowerNode,
|
516
690
|
FlowerAction,
|
517
|
-
useFlower
|
518
|
-
useFlowerForm
|
691
|
+
useFlower
|
519
692
|
} from '@flowerforce/flower-react'
|
693
|
+
|
694
|
+
import {
|
695
|
+
FlowerField,
|
696
|
+
useFlowerForm
|
697
|
+
} from '@flowerforce/flower-react-form'
|
698
|
+
|
520
699
|
import { useEffect } from 'react'
|
521
700
|
import './styles.css'
|
522
701
|
|
@@ -610,7 +789,7 @@ export default function App() {
|
|
610
789
|
|
611
790
|
<FlowerNavigate
|
612
791
|
action="next"
|
613
|
-
rules={{ $and: [{ '$
|
792
|
+
rules={{ $and: [{ '$data.isValid': { $eq: true } }] }}
|
614
793
|
alwaysDisplay
|
615
794
|
>
|
616
795
|
{({ onClick, hidden }) => (
|
@@ -656,130 +835,6 @@ export default function App() {
|
|
656
835
|
|
657
836
|
Edit on [codesandbox/](https://codesandbox.io/p/sandbox/flower-react-example-1-forked-2f43gh)
|
658
837
|
|
659
|
-
## Operators Rules
|
660
|
-
|
661
|
-
The "rules" in Flower are used to define conditions and conditional behaviors within the workflow. These rules allow for dynamically changing the display or behavior of certain fields or components based on specific conditions.
|
662
|
-
|
663
|
-
The rules schema follows the MongoDB style, below is the list of available operators:
|
664
|
-
|
665
|
-
- $exists: Checks if a value exists or not.
|
666
|
-
- $eq: Checks if two values are equal.
|
667
|
-
- $ne: Checks if two values are not equal.
|
668
|
-
- $gt: Checks if the first value is greater than the second.
|
669
|
-
- $gte: Checks if the first value is greater than or equal to the second.
|
670
|
-
- $lt: Checks if the first value is less than the second.
|
671
|
-
- $lte: Checks if the first value is less than or equal to the second.
|
672
|
-
- $strGt: Checks if the length of a string is greater than the specified value.
|
673
|
-
- $strGte: Checks if the length of a string is greater than or equal to the specified value.
|
674
|
-
- $strLt: Checks if the length of a string is less than the specified value.
|
675
|
-
- $strLte: Checks if the length of a string is less than or equal to the specified value.
|
676
|
-
- $in: Checks if a value is present in a given array.
|
677
|
-
- $nin: Checks if a value is not present in a given array.
|
678
|
-
- $all: Checks if all values are present in a given array.
|
679
|
-
- $regex: Checks if a string matches a regular expression.
|
680
|
-
|
681
|
-
### Examples
|
682
|
-
|
683
|
-
Rules in $and | $or
|
684
|
-
|
685
|
-
```jsx
|
686
|
-
<FlowerNode id="node"
|
687
|
-
to={{
|
688
|
-
node2: {
|
689
|
-
rules: { $and: [
|
690
|
-
{ myValue: { $exists: true } },
|
691
|
-
{ myValue: { $strGt: 6 } }
|
692
|
-
|
693
|
-
]}
|
694
|
-
}
|
695
|
-
}}>
|
696
|
-
...
|
697
|
-
</Flower>
|
698
|
-
|
699
|
-
<FlowerNode id="node"
|
700
|
-
to={{
|
701
|
-
node2: {
|
702
|
-
rules: { $or: [
|
703
|
-
{ myValue: { $exists: false } },
|
704
|
-
{ myValue: { $strGt: 6 } }
|
705
|
-
|
706
|
-
]}
|
707
|
-
}
|
708
|
-
}}>
|
709
|
-
...
|
710
|
-
</Flower>
|
711
|
-
|
712
|
-
```
|
713
|
-
|
714
|
-
Compare state value, use '$ref:'
|
715
|
-
|
716
|
-
```jsx
|
717
|
-
<Flower name="demo" initialData={{ myValue1: 'test', myValue2: 'test2' }}>
|
718
|
-
<FlowerNode id="node"
|
719
|
-
to={{
|
720
|
-
node2: {
|
721
|
-
rules: [
|
722
|
-
{ myValue1: { $eq: '$ref:myValue2' } }
|
723
|
-
]}
|
724
|
-
}}>
|
725
|
-
...
|
726
|
-
</Flower>
|
727
|
-
```
|
728
|
-
|
729
|
-
## Display Rules
|
730
|
-
|
731
|
-
Showing or Hiding Fields: You can use rules to show or hide specific fields based on user choices. For example, hiding a "Buttons" unless the user selects a certain option.
|
732
|
-
|
733
|
-
We can use the FlowerRule component to hide a part of the UI according to certain rules.
|
734
|
-
|
735
|
-
If the "alwaysDisplay" property is passed, however, the component will not be automatically hidden, but a "hidden" property will be provided when the rules are not met.
|
736
|
-
|
737
|
-
### Example
|
738
|
-
|
739
|
-
```jsx
|
740
|
-
import React from 'react'
|
741
|
-
import {
|
742
|
-
Flower,
|
743
|
-
FlowerRoute,
|
744
|
-
FlowerNode,
|
745
|
-
FlowerRule,
|
746
|
-
FlowerNavigate
|
747
|
-
} from '@flowerforce/flower-react'
|
748
|
-
|
749
|
-
export const Page = () => {
|
750
|
-
return (
|
751
|
-
<Flower name="demo" initialData={{ enableNav: true }}>
|
752
|
-
<FlowerNode id="step1" to={{ step2: null }}>
|
753
|
-
...
|
754
|
-
{/* show / hidden based on rule */}
|
755
|
-
<FlowerRule rules={{ enableNav: { $eq: true } }}>
|
756
|
-
<p>Buttons nav are enabled</p>
|
757
|
-
</FlowerRule>
|
758
|
-
{/* always visible component, hidden prop is true when rule is not matched */}
|
759
|
-
<FlowerNavigate
|
760
|
-
action="next"
|
761
|
-
rules={{ enableNav: { $eq: true } }}
|
762
|
-
alwaysDisplay
|
763
|
-
>
|
764
|
-
{({ onClick, hidden }) => (
|
765
|
-
<button disabled={hidden} onClick={onClick}>
|
766
|
-
Next →
|
767
|
-
</button>
|
768
|
-
)}
|
769
|
-
</FlowerNavigate>
|
770
|
-
{/* visible only when rule is matched */}
|
771
|
-
<FlowerNavigate action="reset" rules={{ enableNav: { $eq: true } }}>
|
772
|
-
<button>Reset</button>
|
773
|
-
</FlowerNavigate>
|
774
|
-
</FlowerNode>
|
775
|
-
...
|
776
|
-
</Flower>
|
777
|
-
)
|
778
|
-
}
|
779
|
-
```
|
780
|
-
|
781
|
-
Edit on [codesandbox/](https://codesandbox.io/p/sandbox/flower-react-example-1-forked-sfn6ml)
|
782
|
-
|
783
838
|
|
784
839
|
# Debugging Your Flower Application with @flowerforce/devtool
|
785
840
|
To enhance the debugging process of your Flower application, we offer a specialized library named @flowerforce/devtool. This tool is designed to provide a more convenient and powerful debugging experience.
|
@@ -875,7 +930,7 @@ First, create the JSON file at the same level as the component file.
|
|
875
930
|
|
876
931
|
```
|
877
932
|
src
|
878
|
-
│
|
933
|
+
│
|
879
934
|
│
|
880
935
|
└───components
|
881
936
|
│ │
|
@@ -904,7 +959,7 @@ The keys in the JSON file have the following purposes:
|
|
904
959
|
- `type`: indicates what is being described with this JSON file, in this case, a component
|
905
960
|
- `name`: the name of the component being configured
|
906
961
|
- `category`: components are grouped into categories in Flower's graphical interface, so you can choose a category to which the component belongs
|
907
|
-
- `description`: a brief description of the component that will be displayed in the graphical interface. This is particularly useful
|
962
|
+
- `description`: a brief description of the component that will be displayed in the graphical interface. This is particularly useful to understand the functionality of a specific component without reading the code
|
908
963
|
- `editing`: in this key, we will insert the options that will allow us to configure the component's behavior directly from the graphical interface
|
909
964
|
|
910
965
|
Once you have completed these two steps, you will be able to use your `Text component` through the graphical interface.
|
@@ -927,3 +982,7 @@ In any case, there is a JSON schema that will guide you in writing the file asso
|
|
927
982
|
# Documentation
|
928
983
|
|
929
984
|
The Flower React docs are published at [flowerjs.it/](https://flowerjs.it)
|
985
|
+
|
986
|
+
|
987
|
+
|
988
|
+
|