@flowerforce/flower-core 3.2.3 → 3.2.4-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/dist/index.cjs.js CHANGED
@@ -442,6 +442,7 @@ const createFormData = (form) => {
442
442
  return {
443
443
  isSubmitted: form?.isSubmitted || false,
444
444
  isDirty: form?.isDirty || false,
445
+ hasFocus: form?.hasFocus,
445
446
  errors: form?.errors,
446
447
  customErrors: form?.customErrors,
447
448
  isValidating: form?.isValidating,
@@ -634,6 +635,13 @@ const FlowerCoreReducers = {
634
635
  formFieldTouch: (state, { payload }) => {
635
636
  _set(state, [payload.name, 'form', payload.currentNode, 'touches', payload.id], payload.touched);
636
637
  },
638
+ formFieldFocus: (state, { payload }) => {
639
+ if (!payload.focused) {
640
+ _unset(state, [payload.name, 'form', payload.currentNode, 'hasFocus']);
641
+ return;
642
+ }
643
+ _set(state, [payload.name, 'form', payload.currentNode, 'hasFocus'], payload.id);
644
+ },
637
645
  addData: (state, { payload }) => {
638
646
  const prevData = _get(state, [payload.flowName, 'data']);
639
647
  _set(state, [payload.flowName, 'data'], { ...prevData, ...payload.value });
@@ -781,6 +789,9 @@ const FlowerCoreStateSelectors = {
781
789
  getDataFromState: (id) => (data) => (id === '*' ? data : _get(data, id)),
782
790
  makeSelectNodeFormSubmitted: (form) => form && form.isSubmitted,
783
791
  makeSelectNodeFormFieldTouched: (id) => (form) => form && form.touches && form.touches[id],
792
+ makeSelectNodeFormFieldFocused: (id) => (form) => {
793
+ return form && form.hasFocus === id ? id : undefined;
794
+ },
784
795
  makeSelectNodeFormFieldDirty: (id) => (form) => form && form.dirty && form.dirty[id],
785
796
  makeSelectCurrentNodeId: (flower, startNodeId) => _get(flower, ['current']) || startNodeId,
786
797
  makeSelectCurrentNodeDisabled: (nodes, current) => !!_get(nodes, [current, 'disabled']),
package/dist/index.esm.js CHANGED
@@ -440,6 +440,7 @@ const createFormData = (form) => {
440
440
  return {
441
441
  isSubmitted: form?.isSubmitted || false,
442
442
  isDirty: form?.isDirty || false,
443
+ hasFocus: form?.hasFocus,
443
444
  errors: form?.errors,
444
445
  customErrors: form?.customErrors,
445
446
  isValidating: form?.isValidating,
@@ -632,6 +633,13 @@ const FlowerCoreReducers = {
632
633
  formFieldTouch: (state, { payload }) => {
633
634
  _set(state, [payload.name, 'form', payload.currentNode, 'touches', payload.id], payload.touched);
634
635
  },
636
+ formFieldFocus: (state, { payload }) => {
637
+ if (!payload.focused) {
638
+ _unset(state, [payload.name, 'form', payload.currentNode, 'hasFocus']);
639
+ return;
640
+ }
641
+ _set(state, [payload.name, 'form', payload.currentNode, 'hasFocus'], payload.id);
642
+ },
635
643
  addData: (state, { payload }) => {
636
644
  const prevData = _get(state, [payload.flowName, 'data']);
637
645
  _set(state, [payload.flowName, 'data'], { ...prevData, ...payload.value });
@@ -779,6 +787,9 @@ const FlowerCoreStateSelectors = {
779
787
  getDataFromState: (id) => (data) => (id === '*' ? data : _get(data, id)),
780
788
  makeSelectNodeFormSubmitted: (form) => form && form.isSubmitted,
781
789
  makeSelectNodeFormFieldTouched: (id) => (form) => form && form.touches && form.touches[id],
790
+ makeSelectNodeFormFieldFocused: (id) => (form) => {
791
+ return form && form.hasFocus === id ? id : undefined;
792
+ },
782
793
  makeSelectNodeFormFieldDirty: (id) => (form) => form && form.dirty && form.dirty[id],
783
794
  makeSelectCurrentNodeId: (flower, startNodeId) => _get(flower, ['current']) || startNodeId,
784
795
  makeSelectCurrentNodeDisabled: (nodes, current) => !!_get(nodes, [current, 'disabled']),
@@ -3,6 +3,7 @@ export declare const FlowerStateUtils: CoreStateUtils;
3
3
  export declare const createFormData: (form: Record<string, any>) => {
4
4
  isSubmitted: any;
5
5
  isDirty: any;
6
+ hasFocus: any;
6
7
  errors: any;
7
8
  customErrors: any;
8
9
  isValidating: any;
@@ -5,7 +5,7 @@ export type ActionWithPayload<T> = {
5
5
  payload: 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
- export type ActionsTypes = 'historyAdd' | 'historyPrevToNode' | 'setFormTouched' | 'forceAddHistory' | 'historyPop' | 'restoreHistory' | 'replaceNode' | 'initializeFromNode' | 'forceResetHistory' | 'destroy' | 'initNodes' | 'setCurrentNode' | 'formAddErrors' | 'formRemoveErrors' | 'addData' | 'addDataByPath' | 'replaceData' | 'unsetData' | 'setFormIsValidating' | 'resetForm' | 'formFieldTouch' | 'node' | 'prevToNode' | 'next' | 'prev' | 'reset';
8
+ export type ActionsTypes = 'historyAdd' | 'historyPrevToNode' | 'setFormTouched' | 'forceAddHistory' | 'historyPop' | 'restoreHistory' | 'replaceNode' | 'initializeFromNode' | 'forceResetHistory' | 'destroy' | 'initNodes' | 'setCurrentNode' | 'formAddErrors' | 'formRemoveErrors' | 'addData' | 'addDataByPath' | 'replaceData' | 'unsetData' | 'setFormIsValidating' | 'resetForm' | 'formFieldTouch' | 'formFieldFocus' | 'node' | 'prevToNode' | 'next' | 'prev' | 'reset';
9
9
  /**
10
10
  * These functions are Redux reducers used in a Flux architecture for managing state transitions and updates in a Flower application.
11
11
  */
@@ -206,6 +206,20 @@ export type ReducersFunctions<T extends Record<string, any> = Record<string, Flo
206
206
  id: string;
207
207
  touched?: boolean;
208
208
  }>;
209
+ /**
210
+ * @param state
211
+ * @param action
212
+ *
213
+ * Set touch form single field
214
+ *
215
+ * @returns state
216
+ */
217
+ formFieldFocus: ReducerFunctionSign<T, {
218
+ name: string;
219
+ currentNode: string;
220
+ id: string;
221
+ focused?: boolean;
222
+ }>;
209
223
  /**
210
224
  * @param state
211
225
  * @param action
@@ -67,6 +67,7 @@ export interface ISelectors {
67
67
  makeSelectNodeErrors<T extends Record<string, any>>(form: Form<T> | undefined): {
68
68
  isSubmitted: boolean;
69
69
  isDirty: boolean;
70
+ hasFocus: string | undefined;
70
71
  errors: any;
71
72
  customErrors: any;
72
73
  isValid: boolean;
@@ -77,6 +78,11 @@ export interface ISelectors {
77
78
  * @returns
78
79
  */
79
80
  makeSelectNodeFormFieldTouched<T extends Record<string, any>>(id: string): (form: Form<T> | undefined) => boolean | undefined;
81
+ /**
82
+ * @param form
83
+ * @returns
84
+ */
85
+ makeSelectNodeFormFieldFocused<T extends Record<string, any>>(id: string): (form: Form<T> | undefined) => string | undefined;
80
86
  /**
81
87
  * @param form
82
88
  * @returns
@@ -29,6 +29,7 @@ export interface INode {
29
29
  export type Form<T> = {
30
30
  isSubmitted?: boolean;
31
31
  isDirty?: boolean;
32
+ hasFocus?: string;
32
33
  isValidating?: boolean;
33
34
  errors?: {
34
35
  [K in keyof T]: Array<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flower-core",
3
- "version": "3.2.3",
3
+ "version": "3.2.4-beta.0",
4
4
  "description": "Core functions for flowerJS",
5
5
  "repository": {
6
6
  "type": "git",