@flowerforce/flower-react 3.0.1-beta.6 → 3.1.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 CHANGED
@@ -1,3 +1,25 @@
1
+ ## 3.1.0 (2024-06-06)
2
+
3
+
4
+ ### 🚀 Features
5
+
6
+ - add restart action in flower hooks, pass initial data in context ([adbc859](https://github.com/flowerforce/flower/commit/adbc859))
7
+
8
+ - add devtool to demo - remove duplicated export type ([88117d6](https://github.com/flowerforce/flower/commit/88117d6))
9
+
10
+ - allow custom functions when defining rules and navigation between nodes ([b35f5da](https://github.com/flowerforce/flower/commit/b35f5da))
11
+
12
+
13
+ ### 🩹 Fixes
14
+
15
+ - add types exports from index ([b7a2c3b](https://github.com/flowerforce/flower/commit/b7a2c3b))
16
+
17
+ - pass initial data to reset function in useFlower ([2177578](https://github.com/flowerforce/flower/commit/2177578))
18
+
19
+ - payload creator for reset action fixed ([389fe15](https://github.com/flowerforce/flower/commit/389fe15))
20
+
21
+ - align packages ([210a284](https://github.com/flowerforce/flower/commit/210a284))
22
+
1
23
  ## 3.0.0 (2024-05-20)
2
24
 
3
25
  This was a version bump only for flower-react to align it with other projects, there were no code changes.
package/README.md CHANGED
@@ -14,7 +14,7 @@ For more info [flowerjs.it/](https://flowerjs.it/)
14
14
  - **Node and Connection Handling**: Functions to manage nodes and connections, including adding, removing, and editing.
15
15
  - **State Management**: Built-in state management to keep track of workflow changes and updates.
16
16
  - **Event System**: Customizable event handling to respond to user interactions and changes within the workflow.
17
- - **Serialization**: Convert workflows to and from different formats (e.g., JSON) for easy storage and retrieval.
17
+ - **Serialization**: Convert workflows to JSON for easy storage and retrieval. (only server side flow)
18
18
  - **Validation**: Ensure workflows follow predefined rules and constraints to maintain integrity.
19
19
  - **Form Validation**: Built-in functionalities to validate form inputs within nodes, ensuring data integrity and correctness.
20
20
  - **History Management**: Internal management of flow history, tracking node traversal and changes for debugging and visualization purposes.
@@ -30,7 +30,7 @@ Flower React can be installed via npm or yarn for use in any JavaScript project.
30
30
 
31
31
  ```bash
32
32
  #NPM
33
- npm install @flowerforce/flower-core
33
+ npm install @flowerforce/flower-react
34
34
  ```
35
35
 
36
36
  ### Using yarn
@@ -40,7 +40,7 @@ npm install @flowerforce/flower-core
40
40
 
41
41
  ```bash
42
42
  #YARN
43
- yarn add @flowerforce/flower-core
43
+ yarn add @flowerforce/flower-react
44
44
  ```
45
45
 
46
46
  ## Configuration
@@ -811,6 +811,34 @@ Devtool({
811
811
  })
812
812
  ```
813
813
 
814
+ #### Devtool remote
815
+
816
+ ```jsx
817
+ Devtool({
818
+ remote: 'passKey',
819
+ sourceMap: require('./.flower.source-map.json')
820
+ })
821
+ ```
822
+
823
+ To generate the source maps, add the command flower-sourcemap to your package.
824
+
825
+ ```json
826
+ "scripts": {
827
+ "build-sourcemap": "flower generate-sourcemap -p NEWPASSKEY"
828
+ },
829
+ ```
830
+
831
+
832
+ ```bash
833
+ flower sourcemap --help
834
+
835
+ -p, --passKey <type> Choose pass key for devtool inspect (default: "RANDOM STRING")
836
+ -f, --pattern <type> Add glob for search <Flower/> files (default: "src/**/*.{js,ts,tsx,jsx}")
837
+ -s, --dirsave <type> Directory on save sourcemap (default: "src")
838
+ -h, --help Display help for command
839
+ ```
840
+
841
+
814
842
  # Documentation
815
843
 
816
844
  The Flower React docs are published at [flowerjs.it/](https://flowerjs.it)
package/dist/index.cjs.js CHANGED
@@ -57,16 +57,20 @@ const reduxContext = /*#__PURE__*/React.createContext(null);
57
57
  const useDispatch = reactRedux.createDispatchHook(reduxContext);
58
58
  const useSelector = reactRedux.createSelectorHook(reduxContext);
59
59
  const useStore = reactRedux.createStoreHook(reduxContext);
60
- const store = toolkit.configureStore({
60
+ const store = ({
61
+ enableDevtool
62
+ }) => toolkit.configureStore({
61
63
  reducer: reducerFlower,
62
- devTools: {
64
+ devTools: enableDevtool ? {
63
65
  name: 'flower'
64
- }
66
+ } : false
65
67
  });
66
68
  class FlowerProvider extends React.Component {
67
69
  constructor(props) {
68
70
  super(props);
69
- this.store = store;
71
+ this.store = store({
72
+ enableDevtool: props.enableDevtool
73
+ });
70
74
  }
71
75
  render() {
72
76
  const {
@@ -159,10 +163,11 @@ const FlowerClient = ({
159
163
  action: 'FLOWER_CLIENT_INIT',
160
164
  name: flowName,
161
165
  time: new Date(),
162
- nodeId: isInitialized
166
+ nodeId: isInitialized,
167
+ getState: store.getState
163
168
  });
164
169
  }
165
- }, [dispatch, flowName, wsDevtools, isInitialized]);
170
+ }, [dispatch, flowName, wsDevtools, isInitialized, store]);
166
171
  React.useEffect(() => {
167
172
  if (isInitialized && wsDevtools && global.window && _get(global.window, '__FLOWER_DEVTOOLS__')) {
168
173
  flowerCore.Emitter.emit('flower-devtool-from-client', {
@@ -824,7 +829,18 @@ const useFlower = ({
824
829
  } = React.useContext(context);
825
830
  const flowName = customFlowName || name || flowNameDefault;
826
831
  const nodeId = useSelector(makeSelectCurrentNodeId(flowName != null ? flowName : ''));
827
- const emitNavigateEvent = React.useCallback(params => {}, [flowName, nodeId]);
832
+ const emitNavigateEvent = React.useCallback(params => {
833
+ if (_get(global.window, '__FLOWER_DEVTOOLS__')) {
834
+ flowerCore.Emitter.emit('flower-devtool-from-client', {
835
+ source: 'flower-client',
836
+ action: 'FLOWER_NAVIGATE',
837
+ nodeId,
838
+ name: flowName,
839
+ time: new Date(),
840
+ params
841
+ });
842
+ }
843
+ }, [flowName, nodeId]);
828
844
  const next = React.useCallback(param => {
829
845
  const params = typeof param === 'string' ? {
830
846
  route: param
package/dist/index.esm.js CHANGED
@@ -55,16 +55,20 @@ const reduxContext = /*#__PURE__*/createContext(null);
55
55
  const useDispatch = createDispatchHook(reduxContext);
56
56
  const useSelector = createSelectorHook(reduxContext);
57
57
  const useStore = createStoreHook(reduxContext);
58
- const store = configureStore({
58
+ const store = ({
59
+ enableDevtool
60
+ }) => configureStore({
59
61
  reducer: reducerFlower,
60
- devTools: {
62
+ devTools: enableDevtool ? {
61
63
  name: 'flower'
62
- }
64
+ } : false
63
65
  });
64
66
  class FlowerProvider extends Component {
65
67
  constructor(props) {
66
68
  super(props);
67
- this.store = store;
69
+ this.store = store({
70
+ enableDevtool: props.enableDevtool
71
+ });
68
72
  }
69
73
  render() {
70
74
  const {
@@ -157,10 +161,11 @@ const FlowerClient = ({
157
161
  action: 'FLOWER_CLIENT_INIT',
158
162
  name: flowName,
159
163
  time: new Date(),
160
- nodeId: isInitialized
164
+ nodeId: isInitialized,
165
+ getState: store.getState
161
166
  });
162
167
  }
163
- }, [dispatch, flowName, wsDevtools, isInitialized]);
168
+ }, [dispatch, flowName, wsDevtools, isInitialized, store]);
164
169
  useEffect(() => {
165
170
  if (isInitialized && wsDevtools && global.window && _get(global.window, '__FLOWER_DEVTOOLS__')) {
166
171
  Emitter.emit('flower-devtool-from-client', {
@@ -822,7 +827,18 @@ const useFlower = ({
822
827
  } = useContext(context);
823
828
  const flowName = customFlowName || name || flowNameDefault;
824
829
  const nodeId = useSelector(makeSelectCurrentNodeId(flowName != null ? flowName : ''));
825
- const emitNavigateEvent = useCallback(params => {}, [flowName, nodeId]);
830
+ const emitNavigateEvent = useCallback(params => {
831
+ if (_get(global.window, '__FLOWER_DEVTOOLS__')) {
832
+ Emitter.emit('flower-devtool-from-client', {
833
+ source: 'flower-client',
834
+ action: 'FLOWER_NAVIGATE',
835
+ nodeId,
836
+ name: flowName,
837
+ time: new Date(),
838
+ params
839
+ });
840
+ }
841
+ }, [flowName, nodeId]);
826
842
  const next = useCallback(param => {
827
843
  const params = typeof param === 'string' ? {
828
844
  route: param
@@ -1,4 +1,4 @@
1
- import { RulesObject } from '@flowerforce/flower-core';
1
+ import { FunctionRule, RulesObject } from '@flowerforce/flower-core';
2
2
  export type FlowerFieldProps<T extends Record<string, any> = Record<string, any>> = {
3
3
  id?: string;
4
4
  children: React.ReactNode | ((props: {
@@ -19,7 +19,7 @@ export type FlowerFieldProps<T extends Record<string, any> = Record<string, any>
19
19
  asyncDebounce?: number;
20
20
  asyncInitialError?: string;
21
21
  asyncWaitingError?: string;
22
- rules?: RulesObject<T>;
22
+ rules?: RulesObject<T> | FunctionRule;
23
23
  flowName?: string;
24
24
  defaultValue?: unknown;
25
25
  destroyValue?: boolean;
@@ -1,8 +1,8 @@
1
- import { RulesObject } from '@flowerforce/flower-core';
1
+ import { FunctionRule, RulesObject } from '@flowerforce/flower-core';
2
2
  export type FlowerRuleProps = {
3
3
  id?: string;
4
4
  value?: any;
5
- rules?: RulesObject<any>;
5
+ rules?: RulesObject<any> | FunctionRule;
6
6
  flowName?: string;
7
7
  alwaysDisplay?: boolean;
8
8
  onUpdate?: (hidden: boolean) => void;
@@ -1,8 +1,8 @@
1
- import { RulesObject } from '@flowerforce/flower-core';
1
+ import { FunctionRule, RulesObject } from '@flowerforce/flower-core';
2
2
  export type FlowerValueProps = {
3
3
  id?: string;
4
4
  value?: any;
5
- rules?: RulesObject<any>;
5
+ rules?: RulesObject<any> | FunctionRule;
6
6
  children: React.ReactNode | ((props: Record<string, any>) => React.ReactNode | React.ReactElement | undefined);
7
7
  spreadValue?: boolean;
8
8
  flowName?: string;
@@ -4,7 +4,9 @@ import { FlowerProviderProps } from './components/types/FlowerProvider';
4
4
  export declare const useDispatch: import("react-redux").UseDispatch<import("redux").Dispatch<Action>>;
5
5
  export declare const useSelector: import("react-redux").UseSelector<unknown>;
6
6
  export declare const useStore: import("react-redux").UseStore<import("redux").Store<any, Action, {}>>;
7
- export declare const store: import("@reduxjs/toolkit").EnhancedStore<{
7
+ export declare const store: ({ enableDevtool }: {
8
+ enableDevtool?: boolean;
9
+ }) => import("@reduxjs/toolkit").EnhancedStore<{
8
10
  flower: Record<string, import("packages/flower-core/dist/src").Flower<Record<string, any>>>;
9
11
  }, import("redux").UnknownAction, import("@reduxjs/toolkit").Tuple<[import("redux").StoreEnhancer<{
10
12
  dispatch: import("redux-thunk").ThunkDispatch<{
@@ -13,7 +15,9 @@ export declare const store: import("@reduxjs/toolkit").EnhancedStore<{
13
15
  }>, import("redux").StoreEnhancer]>>;
14
16
  declare class FlowerProvider extends Component<PropsWithChildren, FlowerProviderProps> {
15
17
  private store;
16
- constructor(props: PropsWithChildren);
18
+ constructor(props: PropsWithChildren & {
19
+ enableDevtool?: boolean;
20
+ });
17
21
  render(): React.JSX.Element;
18
22
  }
19
23
  export default FlowerProvider;
@@ -1,4 +1,4 @@
1
- import { RulesObject } from '@flowerforce/flower-core';
1
+ import { RulesObject, FunctionRule } from '@flowerforce/flower-core';
2
2
  declare const selectFlowerHistory: (name: string) => ((state: {
3
3
  flower: {
4
4
  [x: string]: import("@flowerforce/flower-core").Flower<Record<string, any>>;
@@ -63,24 +63,24 @@ declare const makeSelectNodesIds: (name: string) => ((state: {
63
63
  [x: string]: import("@flowerforce/flower-core").Flower<Record<string, any>>;
64
64
  };
65
65
  }) => {
66
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
66
+ [x: string]: import("@flowerforce/flower-core").INode;
67
67
  }) & {
68
68
  clearCache: () => void;
69
69
  resultsCount: () => number;
70
70
  resetResultsCount: () => void;
71
71
  } & {
72
72
  resultFunc: (resultFuncArgs_0: import("@flowerforce/flower-core").Flower<Record<string, any>>) => {
73
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
73
+ [x: string]: import("@flowerforce/flower-core").INode;
74
74
  };
75
75
  memoizedResultFunc: ((resultFuncArgs_0: import("@flowerforce/flower-core").Flower<Record<string, any>>) => {
76
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
76
+ [x: string]: import("@flowerforce/flower-core").INode;
77
77
  }) & {
78
78
  clearCache: () => void;
79
79
  resultsCount: () => number;
80
80
  resetResultsCount: () => void;
81
81
  };
82
82
  lastResult: () => {
83
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
83
+ [x: string]: import("@flowerforce/flower-core").INode;
84
84
  };
85
85
  dependencies: [((state: {
86
86
  flower: {
@@ -311,10 +311,10 @@ declare const makeSelectPrevNodeRetain: (name: string) => ((state: {
311
311
  resetResultsCount: () => void;
312
312
  } & {
313
313
  resultFunc: (resultFuncArgs_0: {
314
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
314
+ [x: string]: import("@flowerforce/flower-core").INode;
315
315
  }, resultFuncArgs_1: string[], resultFuncArgs_2: string) => string | boolean | undefined;
316
316
  memoizedResultFunc: ((resultFuncArgs_0: {
317
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
317
+ [x: string]: import("@flowerforce/flower-core").INode;
318
318
  }, resultFuncArgs_1: string[], resultFuncArgs_2: string) => string | boolean | undefined) & {
319
319
  clearCache: () => void;
320
320
  resultsCount: () => number;
@@ -326,24 +326,24 @@ declare const makeSelectPrevNodeRetain: (name: string) => ((state: {
326
326
  [x: string]: import("@flowerforce/flower-core").Flower<Record<string, any>>;
327
327
  };
328
328
  }) => {
329
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
329
+ [x: string]: import("@flowerforce/flower-core").INode;
330
330
  }) & {
331
331
  clearCache: () => void;
332
332
  resultsCount: () => number;
333
333
  resetResultsCount: () => void;
334
334
  } & {
335
335
  resultFunc: (resultFuncArgs_0: import("@flowerforce/flower-core").Flower<Record<string, any>>) => {
336
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
336
+ [x: string]: import("@flowerforce/flower-core").INode;
337
337
  };
338
338
  memoizedResultFunc: ((resultFuncArgs_0: import("@flowerforce/flower-core").Flower<Record<string, any>>) => {
339
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
339
+ [x: string]: import("@flowerforce/flower-core").INode;
340
340
  }) & {
341
341
  clearCache: () => void;
342
342
  resultsCount: () => number;
343
343
  resetResultsCount: () => void;
344
344
  };
345
345
  lastResult: () => {
346
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
346
+ [x: string]: import("@flowerforce/flower-core").INode;
347
347
  };
348
348
  dependencies: [((state: {
349
349
  flower: {
@@ -580,10 +580,10 @@ declare const makeSelectCurrentNodeDisabled: (name: string) => ((state: {
580
580
  resetResultsCount: () => void;
581
581
  } & {
582
582
  resultFunc: (resultFuncArgs_0: {
583
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
583
+ [x: string]: import("@flowerforce/flower-core").INode;
584
584
  }, resultFuncArgs_1: string) => boolean;
585
585
  memoizedResultFunc: ((resultFuncArgs_0: {
586
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
586
+ [x: string]: import("@flowerforce/flower-core").INode;
587
587
  }, resultFuncArgs_1: string) => boolean) & {
588
588
  clearCache: () => void;
589
589
  resultsCount: () => number;
@@ -595,24 +595,24 @@ declare const makeSelectCurrentNodeDisabled: (name: string) => ((state: {
595
595
  [x: string]: import("@flowerforce/flower-core").Flower<Record<string, any>>;
596
596
  };
597
597
  }) => {
598
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
598
+ [x: string]: import("@flowerforce/flower-core").INode;
599
599
  }) & {
600
600
  clearCache: () => void;
601
601
  resultsCount: () => number;
602
602
  resetResultsCount: () => void;
603
603
  } & {
604
604
  resultFunc: (resultFuncArgs_0: import("@flowerforce/flower-core").Flower<Record<string, any>>) => {
605
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
605
+ [x: string]: import("@flowerforce/flower-core").INode;
606
606
  };
607
607
  memoizedResultFunc: ((resultFuncArgs_0: import("@flowerforce/flower-core").Flower<Record<string, any>>) => {
608
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
608
+ [x: string]: import("@flowerforce/flower-core").INode;
609
609
  }) & {
610
610
  clearCache: () => void;
611
611
  resultsCount: () => number;
612
612
  resetResultsCount: () => void;
613
613
  };
614
614
  lastResult: () => {
615
- [x: string]: import("packages/flower-core/dist/src/interfaces/Store").Node;
615
+ [x: string]: import("@flowerforce/flower-core").INode;
616
616
  };
617
617
  dependencies: [((state: {
618
618
  flower: {
@@ -1203,7 +1203,7 @@ declare const makeSelectFieldError: (name: string, id: string, validate: any) =>
1203
1203
  argsMemoize: typeof import("reselect").weakMapMemoize;
1204
1204
  memoize: typeof import("reselect").weakMapMemoize;
1205
1205
  };
1206
- export declare const selectorRulesDisabled: (id: string, rules: RulesObject<any>, keys: string[], flowName: string, value: any, currentNode: string) => ((state: {
1206
+ export declare const selectorRulesDisabled: (id: string, rules: RulesObject<any> | FunctionRule, keys: string[], flowName: string, value: any, currentNode: string) => ((state: {
1207
1207
  flower: {
1208
1208
  [x: string]: import("@flowerforce/flower-core").Flower<Record<string, any>>;
1209
1209
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flower-react",
3
- "version": "3.0.1-beta.6",
3
+ "version": "3.1.0",
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.0.0",
37
+ "@flowerforce/flower-core": "3.1.0",
38
38
  "@reduxjs/toolkit": "^2.2.4",
39
39
  "lodash": "^4.17.21",
40
40
  "react-redux": "^9.1.2",