@flowerforce/flower-core 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.
@@ -113,18 +113,105 @@ export type GenerateRulesName = (nextRules: RulesWithName[]) => {
113
113
  [X: string]: string;
114
114
  };
115
115
  export interface CoreUtilitiesFunctions {
116
+ /**
117
+ *
118
+ * Generates rule names from a set of rules.
119
+ * @param nextRules
120
+ *
121
+ * @returns
122
+ *
123
+ */
116
124
  generateRulesName: GenerateRulesName;
125
+ /**
126
+ * Recursively maps keys of an object using a callback function.
127
+ * @param obj
128
+ * @param cb
129
+ * @param isRecursive
130
+ *
131
+ * @returns
132
+ */
117
133
  mapKeysDeepLodash: MapKeysDeepLodash;
134
+ /**
135
+ * Generates a object of nodes from an array of nodes, using nodeId as keys
136
+ * @param nodes
137
+ * @returns
138
+ */
118
139
  generateNodes: GenerateNodes;
140
+ /**
141
+ * Converts nodes into an object with node IDs as keys and their respective rules as values.
142
+ * @param nodes
143
+ *
144
+ * @returns
145
+ */
119
146
  makeObjectRules: MakeObjectRules;
147
+ /**
148
+ * Checks if a node exists within a specific state.
149
+ * @param state
150
+ * @param name
151
+ * @param node
152
+ *
153
+ * @returns
154
+ */
120
155
  hasNode: HasNode;
156
+ /**
157
+ * Checks if a set of rules is empty.
158
+ * @param rules
159
+ *
160
+ * @returns
161
+ */
121
162
  isEmptyRules: IsEmptyRules;
163
+ /**
164
+ * Maps edges and sorts them moving empty rules to the bottom.
165
+ * @param nextNode
166
+ *
167
+ * @returns
168
+ */
122
169
  mapEdge: MapEdge;
170
+ /**
171
+ * Converts a rules object into an array of rule objects.
172
+ * @param rules
173
+ *
174
+ * @returns
175
+ */
123
176
  makeRules: MakeRules;
177
+ /**
178
+ * Generates nodes for a flower JSON structure, extracting rules and other properties.
179
+ * @param nodes
180
+ *
181
+ * @returns
182
+ */
124
183
  generateNodesForFlowerJson: GenerateNodesForFlowerJson;
184
+ /**
185
+ * Removes specified characters from the beginning of a string (default char -> '^').
186
+ * @param name
187
+ * @param char
188
+ *
189
+ * @returns
190
+ */
125
191
  cleanPath: CleanPath;
192
+ /**
193
+ * Creates a valid path from idValue
194
+ * @param idValue
195
+ *
196
+ * @returns
197
+ */
126
198
  getPath: GetPath;
199
+ /**
200
+ * Checks if two arrays are equal in length and have the same elements.
201
+ * @param arr
202
+ * @param arr2
203
+ *
204
+ * @returns
205
+ */
127
206
  allEqual: AllEqual;
207
+ /**
208
+ * Finds the first valid rule for a given value within a set of rules.
209
+ * @param nextRules
210
+ * @param value
211
+ * @param prefix
212
+ *
213
+ * @returns
214
+ */
128
215
  findValidRule: FindValidRule;
129
216
  }
130
217
  export {};
@@ -6,47 +6,138 @@ export type ActionWithPayload<T> = {
6
6
  };
7
7
  type ReducerFunctionSign<T extends object, R> = (state: Record<string, Flower<T>>, action: ActionWithPayload<R>) => Record<string, Flower<T>> | void;
8
8
  export type ActionsTypes = 'historyAdd' | 'historyPrevToNode' | 'setFormTouched' | 'forceAddHistory' | 'historyPop' | 'restoreHistory' | 'replaceNode' | 'initializeFromNode' | 'forceResetHistory' | 'destroy' | 'initNodes' | 'setCurrentNode' | 'formAddErrors' | 'formRemoveErrors' | 'addData' | 'addDataByPath' | 'replaceData' | 'unsetData' | 'setFormIsValidating' | 'node' | 'prevToNode' | 'next' | 'prev' | 'reset';
9
+ /**
10
+ * These functions are Redux reducers used in a Flux architecture for managing state transitions and updates in a Flower application.
11
+ */
9
12
  export type ReducersFunctions<T extends Record<string, any> = Record<string, Flower<Record<string, any>>>> = {
13
+ /**
14
+ * @param state
15
+ * @param action
16
+ *
17
+ * Adds a node to the history of a specific flow if the node exists.
18
+ *
19
+ * @returns state
20
+ */
10
21
  historyAdd: ReducerFunctionSign<T, {
11
22
  name: string;
12
23
  node: string;
13
24
  }>;
25
+ /**
26
+ * @param state
27
+ * @param action
28
+ *
29
+ * Navigates to a specific node in the history of a flow.
30
+ *
31
+ * @returns state
32
+ */
14
33
  historyPrevToNode: ReducerFunctionSign<T, {
15
34
  name: string;
16
35
  node: string;
17
36
  } | string>;
37
+ /**
38
+ * @param state
39
+ * @param action
40
+ *
41
+ * Sets the "touched" state of a form node in a flow.
42
+ *
43
+ * @returns state
44
+ */
18
45
  setFormTouched: ReducerFunctionSign<T, {
19
46
  flowName: string;
20
47
  currentNode: string;
21
48
  } | string>;
49
+ /**
50
+ * @param state
51
+ * @param action
52
+ *
53
+ * Adds multiple nodes to the history of a flow, starting from a specified index.
54
+ *
55
+ * @returns state
56
+ */
22
57
  forceAddHistory: ReducerFunctionSign<T, {
23
58
  history: string[];
24
59
  name?: string;
25
60
  flowName?: string;
26
61
  }>;
62
+ /**
63
+ * @param state
64
+ * @param action
65
+ *
66
+ * Removes the current node from the history of a flow.
67
+ *
68
+ * @returns state
69
+ */
27
70
  historyPop: ReducerFunctionSign<T, {
28
71
  name: string;
29
72
  }>;
73
+ /**
74
+ * @param state
75
+ * @param action
76
+ *
77
+ * Restores the history of a flow to its initial state.
78
+ *
79
+ * @returns state
80
+ */
30
81
  restoreHistory: ReducerFunctionSign<T, {
31
82
  name: string;
32
83
  }>;
84
+ /**
85
+ * @param state
86
+ * @param action
87
+ *
88
+ * Replaces the current node in a flow with a specified node.
89
+ *
90
+ * @returns state
91
+ */
33
92
  replaceNode: ReducerFunctionSign<T, {
34
93
  node: string;
35
94
  name?: string;
36
95
  flowName?: string;
37
96
  }>;
97
+ /**
98
+ * @param state
99
+ * @param action
100
+ *
101
+ * Initializes a flow from a specific node.
102
+ *
103
+ * @returns state
104
+ */
38
105
  initializeFromNode: ReducerFunctionSign<T, {
39
106
  node: string;
40
107
  name?: string;
41
108
  flowName?: string;
42
109
  }>;
110
+ /**
111
+ * @param state
112
+ * @param action
113
+ *
114
+ * Resets the history of a flow forcefully.
115
+ *
116
+ * @returns state
117
+ */
43
118
  forceResetHistory: ReducerFunctionSign<T, {
44
119
  name?: string;
45
120
  flowName?: string;
46
121
  }>;
122
+ /**
123
+ * @param state
124
+ * @param action
125
+ *
126
+ * Destroys a flow by removing it from the state.
127
+ *
128
+ * @returns state
129
+ */
47
130
  destroy: ReducerFunctionSign<T, {
48
131
  name: string;
49
132
  }>;
133
+ /**
134
+ * @param state
135
+ * @param action
136
+ *
137
+ * Initializes the nodes of a flow, setting its initial state and generating necessary data structures.
138
+ *
139
+ * @returns state
140
+ */
50
141
  initNodes: ReducerFunctionSign<T, {
51
142
  name: string;
52
143
  startId: string;
@@ -54,10 +145,26 @@ export type ReducersFunctions<T extends Record<string, any> = Record<string, Flo
54
145
  nodes: Node[];
55
146
  initialData: any;
56
147
  }>;
148
+ /**
149
+ * @param state
150
+ * @param action
151
+ *
152
+ * Sets the current node of a flow to a specified node.
153
+ *
154
+ * @returns state
155
+ */
57
156
  setCurrentNode: ReducerFunctionSign<T, {
58
157
  name: string;
59
158
  node: string;
60
159
  }>;
160
+ /**
161
+ * @param state
162
+ * @param action
163
+ *
164
+ * Adds errors to a form node in a flow.
165
+ *
166
+ * @returns state
167
+ */
61
168
  formAddErrors: ReducerFunctionSign<T, {
62
169
  name: string;
63
170
  currentNode: string;
@@ -66,33 +173,89 @@ export type ReducersFunctions<T extends Record<string, any> = Record<string, Flo
66
173
  [x: string]: string[];
67
174
  } | string[];
68
175
  }>;
176
+ /**
177
+ * @param state
178
+ * @param action
179
+ *
180
+ * Removes errors from a form node in a flow.
181
+ *
182
+ * @returns state
183
+ */
69
184
  formRemoveErrors: ReducerFunctionSign<T, {
70
185
  name: string;
71
186
  currentNode: string;
72
187
  id: string;
73
188
  }>;
189
+ /**
190
+ * @param state
191
+ * @param action
192
+ *
193
+ * Adds data to a flow.
194
+ *
195
+ * @returns state
196
+ */
74
197
  addData: ReducerFunctionSign<T, {
75
198
  flowName: string;
76
199
  value: T;
77
200
  }>;
201
+ /**
202
+ * @param state
203
+ * @param action
204
+ *
205
+ * Adds data to a flow at a specific path.
206
+ *
207
+ * @returns state
208
+ */
78
209
  addDataByPath: ReducerFunctionSign<T, {
79
210
  id: string[];
80
211
  flowName: string;
81
212
  value: T | string;
82
213
  }>;
214
+ /**
215
+ * @param state
216
+ * @param action
217
+ *
218
+ * Replaces the data of a flow with new data.
219
+ *
220
+ * @returns state
221
+ */
83
222
  replaceData: ReducerFunctionSign<T, {
84
223
  flowName: string;
85
224
  value: T;
86
225
  }>;
226
+ /**
227
+ * @param state
228
+ * @param action
229
+ *
230
+ * Unsets data from a flow at a specific path.
231
+ *
232
+ * @returns state
233
+ */
87
234
  unsetData: ReducerFunctionSign<T, {
88
235
  id: string[] | string;
89
236
  flowName: string;
90
237
  }>;
238
+ /**
239
+ * @param state
240
+ * @param action
241
+ *
242
+ * Sets the "isValidating" state of a form node in a flow.
243
+ *
244
+ * @returns state
245
+ */
91
246
  setFormIsValidating: ReducerFunctionSign<T, {
92
247
  name: string;
93
248
  currentNode: string;
94
249
  isValidating?: boolean;
95
250
  }>;
251
+ /**
252
+ * @param state
253
+ * @param action
254
+ *
255
+ * Handles node transitions in a flow, updating history and form states accordingly.
256
+ *
257
+ * @returns state
258
+ */
96
259
  node: ReducerFunctionSign<T, {
97
260
  name: string;
98
261
  flowName?: string;
@@ -100,25 +263,65 @@ export type ReducersFunctions<T extends Record<string, any> = Record<string, Flo
100
263
  node?: string;
101
264
  history: string[];
102
265
  }>;
266
+ /**
267
+ * @param state
268
+ * @param action
269
+ *
270
+ * Navigates to a specific node in the history of a flow.
271
+ *
272
+ * @returns state
273
+ */
103
274
  prevToNode: ReducerFunctionSign<T, {
104
275
  name?: string;
105
276
  flowName?: string;
106
277
  node: string;
107
278
  }>;
279
+ /**
280
+ * @param state
281
+ * @param action
282
+ *
283
+ * Moves to the next node in a flow based on validation rules and current state.
284
+ *
285
+ * @returns state
286
+ */
108
287
  next: ReducerFunctionSign<T, {
109
288
  name?: string;
110
289
  flowName?: string;
111
290
  data: T;
112
291
  route?: string;
113
292
  }>;
293
+ /**
294
+ * @param state
295
+ * @param action
296
+ *
297
+ * Moves to the previous node in a flow.
298
+ *
299
+ * @returns state
300
+ */
114
301
  prev: ReducerFunctionSign<T, {
115
302
  name?: string;
116
303
  flowName?: string;
117
304
  }>;
305
+ /**
306
+ * @param state
307
+ * @param action
308
+ *
309
+ * Return back to the first node and resets history.
310
+ *
311
+ * @returns state
312
+ */
118
313
  restart: ReducerFunctionSign<T, {
119
314
  name?: string;
120
315
  flowName?: string;
121
316
  }>;
317
+ /**
318
+ * @param state
319
+ * @param action
320
+ *
321
+ * Returns back to the first node, resets history and clean all previous data from flow.
322
+ *
323
+ * @returns state
324
+ */
122
325
  reset: ReducerFunctionSign<T, {
123
326
  name?: string;
124
327
  flowName?: string;
@@ -1,6 +1,10 @@
1
1
  import { RulesObject } from './CoreInterface';
2
2
  import { Flower, Form, INode } from './Store';
3
3
  export interface ISelectors {
4
+ /**
5
+ * @param state
6
+ * @returns
7
+ */
4
8
  selectGlobal<T extends Record<string, any>>(state: {
5
9
  flower: {
6
10
  [x: string]: Flower<T>;
@@ -8,31 +12,97 @@ export interface ISelectors {
8
12
  }): {
9
13
  [x: string]: Flower<T>;
10
14
  };
15
+ /**
16
+ * @param name
17
+ * @returns
18
+ */
11
19
  selectFlower<T extends Record<string, any>>(name: string): (state: {
12
20
  [x: string]: Flower<T>;
13
21
  }) => Flower<T>;
22
+ /**
23
+ * @param id
24
+ * @returns
25
+ */
14
26
  selectFlowerFormNode<T extends Record<string, any>>(id: string): (state: Flower<T>) => Form<T>;
27
+ /**
28
+ * @param flower
29
+ * @returns
30
+ */
15
31
  selectFlowerHistory<T extends Record<string, any>>(flower: Flower<T>): Array<string>;
32
+ /**
33
+ * @param flower
34
+ * @returns
35
+ */
16
36
  makeSelectNodesIds<T extends Record<string, any>>(flower: Flower<T>): Flower<T>['nodes'];
37
+ /**
38
+ * @param flower
39
+ * @returns
40
+ */
17
41
  makeSelectStartNodeId<T extends Record<string, any>>(flower: Flower<T>): string;
42
+ /**
43
+ * @param flower
44
+ * @param startNodeId
45
+ * @returns
46
+ */
18
47
  makeSelectCurrentNodeId<T extends Record<string, any>>(flower: Flower<T>, startNodeId: Flower<T>['startId']): string;
48
+ /**
49
+ * @param nodes
50
+ * @param history
51
+ * @param current
52
+ * @returns
53
+ */
19
54
  makeSelectPrevNodeRetain<T extends Record<string, any>>(nodes: Flower<T>['nodes'], history: Flower<T>['history'], current: Flower<T>['current']): boolean | string | undefined;
55
+ /**
56
+ * @param nodes
57
+ * @param current
58
+ * @returns
59
+ */
20
60
  makeSelectCurrentNodeDisabled<T extends Record<string, any>>(nodes: {
21
61
  [x: string]: Partial<INode>;
22
62
  }, current: Flower<T>['current']): boolean;
63
+ /**
64
+ * @param form
65
+ * @returns
66
+ */
23
67
  makeSelectNodeErrors<T extends Record<string, any>>(form: Form<T> | undefined): {
24
68
  touched: boolean;
25
69
  errors: any;
26
70
  isValid: boolean;
27
71
  isValidating?: boolean;
28
72
  };
73
+ /**
74
+ * @param flower
75
+ * @returns
76
+ */
29
77
  getDataByFlow<T extends Record<string, any>>(flower: Flower<T>): T;
78
+ /**
79
+ * @param id
80
+ * @returns
81
+ */
30
82
  getDataFromState<T extends Record<string, any>>(id: string | string[]): (data: T) => Partial<T>;
83
+ /**
84
+ * @param form
85
+ * @returns
86
+ */
31
87
  makeSelectNodeFormTouched<T extends Record<string, any>>(form: Form<T>): boolean | undefined;
88
+ /**
89
+ * @param name
90
+ * @param id
91
+ * @param validate
92
+ * @returns
93
+ */
32
94
  makeSelectFieldError<T extends Record<string, any>>(name: string, id: string, validate: {
33
95
  rules?: RulesObject<any>;
34
96
  message?: string;
35
97
  }[] | null): (data?: T) => Array<string>;
98
+ /**
99
+ * @param id
100
+ * @param rules
101
+ * @param keys
102
+ * @param flowName
103
+ * @param value
104
+ * @returns
105
+ */
36
106
  selectorRulesDisabled<T extends Record<string, any>>(id: string, rules: any, keys: string[] | null, flowName: string, value: any): (data: T | undefined, form: {
37
107
  touched: boolean;
38
108
  errors: any;
@@ -1,8 +1,45 @@
1
1
  export interface CoreStateUtils {
2
+ /**
3
+ * @param state
4
+ *
5
+ * Extracts data from all flows in the state object.
6
+ * It iterates through each flow and retrieves its data property.
7
+ */
2
8
  getAllData<T extends object>(state: T | undefined): Record<string, any> | undefined;
9
+ /**
10
+ *
11
+ * @param name
12
+ * @param id
13
+ *
14
+ * Selects the form node with a specific ID from a given flow.
15
+ * It returns a selector function that accepts the state as an argument and retrieves the form node
16
+ */
3
17
  selectFlowerFormNode<T extends object>(name: string, id: string): (state: T) => Record<string, any>;
18
+ /**
19
+ *
20
+ * @param name
21
+ *
22
+ * Creates a selector function that selects the next rules for the current node in a given flow.
23
+ * It retrieves the next rules from the state
24
+ */
4
25
  makeSelectCurrentNodeId<T extends object>(name: string): (state: T) => string;
26
+ /**
27
+ *
28
+ * @param name
29
+ *
30
+ * Creates a selector function that selects the ID of the current node in a given flow.
31
+ * It first retrieves the sub-state of the specified flow, then checks if there's a current node ID;
32
+ * if not, it falls back to the start ID.
33
+ */
5
34
  makeSelectCurrentNextRules<T extends object>(name: string): (state: T) => any;
35
+ /**
36
+ *
37
+ * @param name
38
+ * @param currentNodeId
39
+ *
40
+ * Creates a selector function that selects error-related information for a specific node in a given flow.
41
+ * It retrieves the form node using selectFlowerFormNode, then extracts information about touched state, errors, validation status, and validity.
42
+ */
6
43
  makeSelectNodeErrors<T extends object>(name: string, currentNodeId: string): (state: T) => {
7
44
  touched: boolean;
8
45
  errors: any;