@flowerforce/flower-react 3.1.1 → 3.1.2-beta.1

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.
@@ -1,9 +1,15 @@
1
1
  import React, { PropsWithChildren } from 'react';
2
+ type FlowerInitalState = {
3
+ startId?: string;
4
+ current?: string;
5
+ history?: string[];
6
+ };
2
7
  type FlowerClientProps = PropsWithChildren & {
3
8
  name: string;
4
9
  destroyOnUnmount?: boolean;
5
10
  startId?: string | null;
6
11
  initialData?: any;
12
+ initialState?: FlowerInitalState;
7
13
  };
8
- declare const component: React.MemoExoticComponent<({ children, name, destroyOnUnmount, startId, initialData }: FlowerClientProps) => React.JSX.Element | null>;
14
+ declare const component: React.MemoExoticComponent<({ children, name, destroyOnUnmount, startId, initialData, initialState }: FlowerClientProps) => React.JSX.Element | null>;
9
15
  export default component;
@@ -1,8 +1,25 @@
1
1
  export type FlowerNodeDefaultProps = {
2
+ /** Unique identifier for the node inside the Flow */
2
3
  id: string;
4
+ /** An object containing the informations about the node's links.
5
+ *
6
+ * Example: to={{ step2: { rules: { $and: [{ name: { $eq: 'John' } }] } } }}
7
+ *
8
+ * In that case, the FlowerNode is linked to the node with the ID 'step2'
9
+ *
10
+ * You can move from the current node to the step2 node only if the rules are satisfied
11
+ *
12
+ * Set it to null when you don't have rules
13
+ *
14
+ * Example: to={{ step2: null}
15
+ */
3
16
  to?: Record<string, any>;
17
+ /** The children of the FlowerNode */
4
18
  children?: React.ReactNode;
19
+ /** The function executed when you enter into this FlowerNode */
5
20
  onEnter?: () => void;
21
+ /** The function executed when you leave this FlowerNode */
6
22
  onExit?: () => void;
23
+ /** When set to true, the FlowerNode is ignored and skipped */
7
24
  disabled?: boolean;
8
25
  };
@@ -1,4 +1,6 @@
1
1
  export type FlowerComponentProps = {
2
+ /** The name of the component */
2
3
  name: string;
4
+ /** The component's children */
3
5
  children: React.ReactNode;
4
6
  };
@@ -1,30 +1,108 @@
1
1
  import { FunctionRule, RulesObject } from '@flowerforce/flower-core';
2
2
  export type FlowerFieldProps<T extends Record<string, any> = Record<string, any>> = {
3
+ /** The path to the value you want to read from the flow's data
4
+ *
5
+ * Example: id="loginForm.name"
6
+ *
7
+ * The FlowerField component reads the value of the key "name" of the loginForm object in the flow's data
8
+ */
3
9
  id?: string;
10
+ /** The FlowerField's children */
4
11
  children: React.ReactNode | ((props: {
12
+ /** The string passed to the "id" FlowerField's prop */
5
13
  id: string;
14
+ /** The value found at the "id" key in the flow data
15
+ *
16
+ * Example: id="loginForm.name"
17
+ *
18
+ * This parameter will hold the value found at the key 'name' of the loginForm object in the flow's data.
19
+ */
6
20
  value: any;
21
+ /** An array of strings containing error messages associated with validation rules that are not satisfied. */
7
22
  errors: undefined | string[];
23
+ /** This parameter will notify you when there are validation errors. */
8
24
  hasError: undefined | boolean;
25
+ /** Use this function to write a new value at the "id" key
26
+ *
27
+ * Example: id="loginForm.name"
28
+ *
29
+ * onChange("John") will write "John" at the key 'name' of the loginForm object in the flow's data.
30
+ */
9
31
  onChange: (props: any) => void;
32
+ /** The function executed to test all the validation rules*/
10
33
  onBlur: () => void;
34
+ /** This parameter will notify you whether the form field has been touched */
11
35
  isTouched: boolean;
36
+ /** true when some of the display rules are not satisfied, and you have passed true to the "alwaysDisplay" FlowerField's prop*/
12
37
  hidden: boolean;
38
+ /** true when you have an async validation in progress */
13
39
  isValidating: boolean | undefined;
14
40
  }) => React.ReactNode | React.ReactElement | undefined);
41
+ /**The validation rules for that field
42
+ *
43
+ * Example: validate={[
44
+ *
45
+ * {
46
+ * rules: {
47
+ * $self: {
48
+ * $regex:
49
+ * '^([A-Z]{6}[0-9LMNPQRSTUV]{2}[ABCDEHLMPRST]{1}[0-9LMNPQRSTUV]{2}[A-Z]{1}[0-9LMNPQRSTUV]{3}[A-Z]{1})$|([0-9]{11})$',
50
+ * },
51
+ * },
52
+ * message: 'Value not valid',
53
+ * },
54
+ * {
55
+ * // Don't use promises
56
+ * rules: (data)=> {
57
+ * return data.name === 'Andrea'
58
+ * },
59
+ * message: 'Value not valid',
60
+ * }
61
+ * ]}
62
+ *
63
+ * For every rule you can pass an error message, that Flower returns when that condition is note satisfied
64
+ */
15
65
  validate?: Record<string, any>[] | string[];
66
+ /** A function to perform an async validation */
16
67
  asyncValidate?: (value: any, data?: Record<string, any>, errors?: undefined | string[]) => string[] | undefined | Promise<string[]> | {
17
68
  message: string;
18
69
  }[] | boolean | Promise<boolean>;
70
+ /** Use this to set a debounce for the async validation
71
+ *
72
+ * The default value is 0
73
+ */
19
74
  asyncDebounce?: number;
75
+ /** The initial error message when you have an async validation
76
+ *
77
+ * The default value is undefined
78
+ */
20
79
  asyncInitialError?: string;
80
+ /** The message that the FlowerField returns while validating*/
21
81
  asyncWaitingError?: string;
82
+ /** An object containing the display rules of that component. When the conditions are not satisfied, the children is hidden.
83
+ *
84
+ * Example: rules={{ $and: [{ name: { $exist: true } }] }}
85
+ */
22
86
  rules?: RulesObject<T> | FunctionRule;
87
+ /** The name of the flow from which read the data
88
+ *
89
+ * - note: the default value is the name of the flow where the component is used
90
+ */
23
91
  flowName?: string;
92
+ /** Initial value field */
24
93
  defaultValue?: unknown;
25
94
  destroyValue?: boolean;
26
95
  value?: any;
96
+ /** When set to true, the children is shown even if the rules are not satisfied
97
+ *
98
+ * The FlowerField returns the boolean variable "hidden" to notify you if the conditions are satisfied or not
99
+ */
27
100
  alwaysDisplay?: boolean;
101
+ /** The function executed when the value found at the path passed to the "id" prop changes */
28
102
  onUpdate?: (value: any) => void;
103
+ /** The function executed at the "onBlur" event, for example for Input components
104
+ *
105
+ * The onBlur function will test all the validation rules
106
+ */
29
107
  onBlur?: (e: any) => void;
30
108
  };
@@ -1,4 +1,14 @@
1
1
  import { FlowerNodeDefaultProps } from './DefaultNode';
2
2
  export type FlowerFlowProps = FlowerNodeDefaultProps & {
3
+ /** A Flower node is visible only when is the current node in the navigation history of the flow.
4
+ *
5
+ * By setting this prop to true, you have the ability to view this node even when it is not the current node.
6
+ *
7
+ * This can only be set to true for FlowerNode and FlowerFlow components.
8
+ *
9
+ * An example use case is when transitioning from a FlowerNode containing a particular screen to an action node.
10
+ *
11
+ * The node with retain set to true will continue to be displayed until a new FlowerNode or FlowerFlow is added to the history
12
+ * */
3
13
  retain?: boolean;
4
14
  };
@@ -3,25 +3,48 @@ export type UseFlowerProps = {
3
3
  [x in 'name' | 'flowName']?: string;
4
4
  };
5
5
  export type UseFlowerForm = (options?: UseFlowerProps) => {
6
+ /** This value is set to true when the form has been touched at least once. */
6
7
  touched: boolean;
8
+ /** An object containing all the form errors */
7
9
  errors: Record<string, any>;
10
+ /** This value is set to true when all the validation rules are satisfied and the form is valid*/
8
11
  isValid: boolean;
12
+ /** This value is set to true during asynchronous validation.*/
9
13
  isValidating: boolean | undefined;
14
+ /** Use this function to read values from the flow's data. */
10
15
  getData: (path?: string) => any;
11
- setData: (value: any, path?: string) => void;
12
- unsetData: (path: string) => void;
16
+ /** Use this function to set values in the flow's data. */
17
+ setData: (
18
+ /** The value that you want to set */
19
+ value: any,
20
+ /** Specify the target path to set the value*/
21
+ path?: string) => void;
22
+ /** Use this function to unset values in the flow's data. */
23
+ unsetData: (
24
+ /** Specify the target path to the value tha you want to unset*/
25
+ path: string) => void;
26
+ /** Use this function to replace a value in the flow's data. */
13
27
  replaceData: (value: any) => void;
14
28
  };
15
29
  type useFlowerActions = {
30
+ /** Use this function to move to the next node inside the flow*/
16
31
  next: (payload?: Route) => void;
32
+ /**Use this function to move to the previous node inside the flow*/
17
33
  back: (payload?: RoutePrev) => void;
34
+ /**Use this function to return to the first node and restore history */
18
35
  reset: (payload?: RouteReset) => void;
36
+ /**Use this function to move to a specific node*/
19
37
  jump: (payload: RouteNode) => void;
38
+ /**Use this function to reset the flow data and history */
20
39
  restart: (payload?: RouteRestart) => void;
21
40
  };
22
41
  export type UseFlower = (options?: UseFlowerProps) => useFlowerActions & {
42
+ /**The flow in which the hook is used.*/
23
43
  flowName?: string;
44
+ /**Current node id*/
24
45
  nodeId: string;
46
+ /**Initial start node id*/
47
+ startId: string;
25
48
  };
26
49
  export type NavigateFunctionParams = string | Record<string, any>;
27
50
  export {};
@@ -3,6 +3,10 @@ export type Route = string | Record<string, any>;
3
3
  export type RouteNode = string | {
4
4
  node: string;
5
5
  flowName?: string;
6
+ /**
7
+ * The flow's history on server component
8
+ * @experimental
9
+ */
6
10
  history?: string[];
7
11
  };
8
12
  export type RouteRestart = string | {
@@ -19,9 +23,19 @@ export type RoutePrev = string | {
19
23
  flowName?: string;
20
24
  };
21
25
  export type FlowerNavigateProps = {
26
+ /** The name of the flow from which read the data
27
+ *
28
+ * - note: the default value is the name of the flow where the component is used
29
+ */
22
30
  flowName?: string | undefined;
31
+ /** The FlowerNavigate's children */
23
32
  children: React.ReactNode | ((props: Record<string, any>) => React.ReactNode | React.ReactElement | undefined);
33
+ /** An object containing the display rules of that component. When the conditions are not satisfied, the children is hidden. */
24
34
  rules?: RulesObject<Record<string, any>> | Record<string, RulesObject<any>>;
35
+ /** When set to true, the children is shown even if the rules are not satisfied
36
+ *
37
+ * The FlowerValue returns the boolean variable "hidden" to notify you if the conditions are satisfied or not
38
+ */
25
39
  alwaysDisplay?: boolean;
26
40
  } & ({
27
41
  action?: 'next';
@@ -1,4 +1,14 @@
1
1
  import { FlowerNodeDefaultProps } from './DefaultNode';
2
2
  export type FlowerNodeProps = FlowerNodeDefaultProps & {
3
+ /** A Flower node is visible only when is the current node in the navigation history of the flow.
4
+ *
5
+ * By setting this prop to true, you have the ability to view this node even when it is not the current node.
6
+ *
7
+ * This can only be set to true for FlowerNode and FlowerFlow components.
8
+ *
9
+ * An example use case is when transitioning from a FlowerNode containing a particular screen to an action node.
10
+ *
11
+ * The node with retain set to true will continue to be displayed until a new FlowerNode or FlowerFlow is added to the history
12
+ * */
3
13
  retain?: boolean;
4
14
  };
@@ -1,8 +1,25 @@
1
1
  export type FlowerRouteProps = {
2
+ /** Unique identifier for the node inside the Flow */
2
3
  id: string;
4
+ /** TODO document what this props does */
3
5
  autostart?: boolean;
6
+ /** An object containing the informations about the node's links.
7
+ *
8
+ * Example: to={{ step2: { rules: { $and: [{ name: { $eq: 'John' } }] } } }}
9
+ *
10
+ * In that case, the FlowerRoute is linked to the node with the ID 'step2'
11
+ *
12
+ * You can move from the current node to the step2 node only if the rules are satisfied
13
+ *
14
+ * Set it to null when you don't have rules
15
+ *
16
+ * Example: to={{ step2: null}
17
+ */
4
18
  to?: Record<string, any>;
19
+ /** The children of the FlowerRoute */
5
20
  children?: React.ReactNode;
21
+ /** The function executed when you enter into this FlowerRoute */
6
22
  onEnter?: () => void;
23
+ /** The function executed when you leave this FlowerRoute */
7
24
  onExit?: () => void;
8
25
  };
@@ -1,11 +1,34 @@
1
1
  import { FunctionRule, RulesObject } from '@flowerforce/flower-core';
2
2
  export type FlowerRuleProps = {
3
+ /** The path to the value you want to read from the flow's data
4
+ *
5
+ * Example: id="loginForm.name"
6
+ *
7
+ * The FlowerRule component reads the value of the key "name" of the loginForm object in the flow's data
8
+ */
3
9
  id?: string;
10
+ /** */
4
11
  value?: any;
12
+ /** An object or function containing the display rules of that component. When the conditions are not satisfied, the children is hidden.
13
+ *
14
+ * Example: rules={{ $and: [{ name: { $exist: true } }] }}
15
+ * Example: rules={(state) => state... === true}
16
+ * if missing it is always visible
17
+ */
5
18
  rules?: RulesObject<any> | FunctionRule;
19
+ /** The name of the flow from which read the data
20
+ *
21
+ * - note: the default value is the name of the flow where the component is used
22
+ */
6
23
  flowName?: string;
24
+ /** When set to true, the children is shown even if the rules are not satisfied
25
+ *
26
+ * The FlowerRule returns the boolean variable "hidden" to notify you if the conditions are satisfied or not
27
+ */
7
28
  alwaysDisplay?: boolean;
29
+ /** The function executed when the value found at the path passed to the "id" prop changes */
8
30
  onUpdate?: (hidden: boolean) => void;
31
+ /** The children of the FlowerRule*/
9
32
  children?: React.ReactNode | ((props: {
10
33
  hidden?: boolean;
11
34
  }) => React.ReactNode | React.ReactElement | undefined);
@@ -1,7 +1,9 @@
1
1
  import { FlowerNodeProps } from './FlowerNode';
2
2
  export type FlowerServerProps = {
3
3
  action?: {
4
+ /** The type of the action */
4
5
  type: string;
6
+ /** The parameters passed to the action */
5
7
  props?: Record<string, any>;
6
8
  };
7
9
  } & FlowerNodeProps;
@@ -1,11 +1,33 @@
1
1
  import { FunctionRule, RulesObject } from '@flowerforce/flower-core';
2
2
  export type FlowerValueProps = {
3
+ /** The path to the value you want to read from the flow's data
4
+ *
5
+ * Example: id="loginForm.name"
6
+ *
7
+ * The FlowerValue component reads the value of the key "name" of the loginForm object in the flow's data
8
+ * If missing, I return all values, which is equivalent to setting id='*'
9
+ */
3
10
  id?: string;
4
11
  value?: any;
12
+ /** An object containing the display rules of that component. When the conditions are not satisfied, the children is hidden.
13
+ *
14
+ * Example: rules={{ $and: [{ name: { $exist: true } }] }}
15
+ */
5
16
  rules?: RulesObject<any> | FunctionRule;
17
+ /** The FlowerValue's children */
6
18
  children: React.ReactNode | ((props: Record<string, any>) => React.ReactNode | React.ReactElement | undefined);
19
+ /** Set this value to true to spread the value into separate values in case it is an object. */
7
20
  spreadValue?: boolean;
21
+ /** The name of the flow from which read the data
22
+ *
23
+ * - note: the default value is the name of the flow where the component is used
24
+ */
8
25
  flowName?: string;
26
+ /** When set to true, the children is shown even if the rules are not satisfied
27
+ *
28
+ * The FlowerValue returns the boolean variable "hidden" to notify you if the conditions are satisfied or not
29
+ */
9
30
  alwaysDisplay?: boolean;
31
+ /** The function executed when the value found at the path passed to the "id" prop changes */
10
32
  onUpdate?: (value: any) => void;
11
33
  };
@@ -1,3 +1,21 @@
1
1
  import { UseFlower } from './types/FlowerHooks';
2
+ /** This hook allows you to read flow informations, such as the flowName and ID of the current node.
3
+ *
4
+ * It also exposes all the functions to navigate within the flow:
5
+ *
6
+ * - next
7
+ *
8
+ * - back
9
+ *
10
+ * - jump
11
+ *
12
+ * - reset
13
+ *
14
+ * - restart
15
+ *
16
+ * @param {string} flowName - first optional parameter
17
+ *
18
+ * @param {string} name - optional parameter, if flowName exist, name is not used
19
+ */
2
20
  declare const useFlower: UseFlower;
3
21
  export default useFlower;
@@ -1,3 +1,20 @@
1
1
  import { UseFlowerForm } from './types/FlowerHooks';
2
+ /** This hook allows you to manage and retrieve information about Forms.
3
+ *
4
+ * It exposes details regarding the form's state and a set of methods for reading and writing within it:
5
+ *
6
+ * - getData
7
+ *
8
+ * - setData
9
+ *
10
+ * - unSetData
11
+ *
12
+ * - replaceData
13
+ *
14
+ * @param {string} flowName - first optional parameter
15
+ *
16
+ * @param {string} name - optional parameter, if flowName exist, name is not used
17
+ *
18
+ */
2
19
  declare const useFlowerForm: UseFlowerForm;
3
20
  export default useFlowerForm;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flower-react",
3
- "version": "3.1.1",
3
+ "version": "3.1.2-beta.1",
4
4
  "description": "FlowerJS components, hooks and utils for React.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,7 +34,7 @@
34
34
  "typescript": "^5.4.5"
35
35
  },
36
36
  "dependencies": {
37
- "@flowerforce/flower-core": "3.1.1",
37
+ "@flowerforce/flower-core": "*",
38
38
  "@reduxjs/toolkit": "^2.2.4",
39
39
  "lodash": "^4.17.21",
40
40
  "react-redux": "^9.1.2",