@arquimedes.co/eureka-forms 2.0.8-test → 2.0.10-test

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/App/App.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { Classifier, Form } from '../@Types/Form';
3
3
  import './App.css';
4
4
  import { CustomStep } from '../FormSteps/CustomStep';
@@ -40,5 +40,6 @@ export interface AppProps {
40
40
  /** Function to call after the confimation dialog has been closed */
41
41
  handleConfirmed?: () => void;
42
42
  }
43
+ export declare const IdFormContext: React.Context<string>;
43
44
  declare function AppComponent({ formData, valuesData, ...props }: AppProps): JSX.Element;
44
45
  export default AppComponent;
package/dist/App/App.js CHANGED
@@ -21,7 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  return t;
22
22
  };
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
- import { useRef } from 'react';
24
+ import React, { createContext, useRef } from 'react';
25
25
  import Loader from '../Shared/Loader/Loader';
26
26
  import styles from './App.module.css';
27
27
  import './App.css';
@@ -31,9 +31,12 @@ import { store } from '../Utils/store';
31
31
  import { useLogRocket, useSetupApp } from './AppHooks';
32
32
  import { useAppSelector } from '../hooks';
33
33
  import CustomContext from '../Contexts/CustomContext';
34
+ import { nanoid } from '@reduxjs/toolkit';
35
+ export var IdFormContext = createContext('');
34
36
  function AppComponent(_a) {
35
37
  var formData = _a.formData, valuesData = _a.valuesData, props = __rest(_a, ["formData", "valuesData"]);
36
- return (_jsx(Provider, __assign({ store: store }, { children: _jsx(App, __assign({ formData: formData, valuesData: valuesData }, props)) })));
38
+ var idForm = React.useState(nanoid(6))[0];
39
+ return (_jsx(IdFormContext.Provider, __assign({ value: idForm }, { children: _jsx(Provider, __assign({ store: store }, { children: _jsx(App, __assign({ formData: formData, valuesData: valuesData }, props)) })) })));
37
40
  }
38
41
  export default AppComponent;
39
42
  function App(_a) {
@@ -1,6 +1,6 @@
1
1
  import { Form } from '../@Types';
2
2
  import { FormStep, Mapper } from '../@Types/FormStep';
3
- import { SiteState, ValuesStore } from '../States/SiteStateReducer';
3
+ import { SiteState, ValuesStore } from '../States/SiteSlice';
4
4
  import { DependencyStore } from '../Form/Form';
5
5
  import { CustomStep } from '../FormSteps/CustomStep';
6
6
  import { MapperElement } from '../@Types/MapperElement';
@@ -57,7 +57,7 @@ var __rest = (this && this.__rest) || function (s, e) {
57
57
  return t;
58
58
  };
59
59
  import { useCallback, useEffect, useState } from 'react';
60
- import { reset } from '../States/GlobalStateReducer';
60
+ import { reset } from '../States/GlobalSlice';
61
61
  import { fetchOrganization } from '../Services/OrganizationService';
62
62
  import { fetchForm } from '../Services/FormService';
63
63
  import { calcCbrForm } from '../Utils/CBRFunctions';
@@ -181,6 +181,9 @@ export var useSetupApp = function (isEmbedded, _a) {
181
181
  }); };
182
182
  useEffect(function () {
183
183
  loadData();
184
+ return function () {
185
+ dispatch({ type: 'CLEAR' });
186
+ };
184
187
  }, []);
185
188
  var reload = useCallback(function () {
186
189
  if (!form)
package/dist/Form/Form.js CHANGED
@@ -62,11 +62,12 @@ import axiosInstance from '../Utils/AxiosAPI';
62
62
  import ReCAPTCHA from 'react-google-recaptcha';
63
63
  import ConfirmationDialog from './ConfirmationDialog/ConfirmationDialog';
64
64
  import MaterialProviders from '../Utils/MaterialProviders';
65
- import { useWidthStats } from '../States/WidthStatsStateReducer';
65
+ import { useWidthStats } from './Hooks';
66
+ import { IdFormContext } from '../App/App';
66
67
  import { useAppDispatch, useAppSelector } from '../hooks';
67
68
  import FormContext from '../Contexts/FormContext';
68
69
  import { getAppState } from '../Utils/store';
69
- import { focusStep } from '../States/SiteStateReducer';
70
+ import { focusStep } from '../States/SiteSlice';
70
71
  var localeMap = {
71
72
  en: enLocale,
72
73
  'en-US': enLocale,
@@ -89,6 +90,7 @@ function FormComponent(_a) {
89
90
  mode: 'onTouched',
90
91
  shouldFocusError: true,
91
92
  });
93
+ var idForm = useContext(IdFormContext);
92
94
  var recaptchaRef = useRef();
93
95
  var dispatch = useAppDispatch();
94
96
  var _m = useState(), showConfirmation = _m[0], setShowConfirmation = _m[1];
@@ -118,7 +120,7 @@ function FormComponent(_a) {
118
120
  _c.label = 3;
119
121
  case 3:
120
122
  _c.trys.push([3, 8, , 9]);
121
- return [4 /*yield*/, dispatch(getAppState()).unwrap()];
123
+ return [4 /*yield*/, dispatch(getAppState({ idForm: idForm })).unwrap()];
122
124
  case 4:
123
125
  state = _c.sent();
124
126
  newValues = __assign({}, state.site.values.global);
@@ -159,7 +161,7 @@ function FormComponent(_a) {
159
161
  case 9: return [2 /*return*/];
160
162
  }
161
163
  });
162
- }); }, [customSteps, internal, customSubmit, idOrganization]);
164
+ }); }, [customSteps, internal, customSubmit, idOrganization, idForm]);
163
165
  useWidthStats(containerRef, form, postview, internal);
164
166
  var isResponsive = useAppSelector(function (state) { return state.widthStats.isResponsive; });
165
167
  var renderForm = function () {
@@ -2,6 +2,6 @@ import { FormStep } from '../@Types/FormStep';
2
2
  import { DependencyStore } from './Form';
3
3
  import { CustomStep } from '../FormSteps/CustomStep';
4
4
  import { CBRFormStep } from '../@Types/CBRFormStep';
5
- import { ValuesStore } from '../States/SiteStateReducer';
5
+ import { ValuesStore } from '../States/SiteSlice';
6
6
  export declare const calcValue: (idStep: string, steps: Record<string, FormStep>, values: Record<string, any>, customSteps: Record<string, CustomStep> | undefined, deleteIds: string[], value?: any) => any;
7
7
  export declare function calcDependencies(steps: Record<string, FormStep | CBRFormStep>, customSteps?: Record<string, CustomStep>, allSteps?: Record<string, FormStep | CBRFormStep>, dependencies?: DependencyStore, values?: ValuesStore): DependencyStore;
@@ -54,8 +54,9 @@ import { useFormContext } from 'react-hook-form';
54
54
  import { useAppDispatch, useAppSelector } from '../../../hooks';
55
55
  import Section from '../../Section/Section';
56
56
  import CustomContext from '../../../Contexts/CustomContext';
57
- import * as SiteReducer from '../../../States/SiteStateReducer';
57
+ import * as SiteReducer from '../../../States/SiteSlice';
58
58
  import { getAppState } from '../../../Utils/store';
59
+ import { IdFormContext } from '../../../App/App';
59
60
  function StepperForm(_a) {
60
61
  var _this = this;
61
62
  var onSubmit = _a.onSubmit;
@@ -66,6 +67,7 @@ function StepperForm(_a) {
66
67
  var dispatch = useAppDispatch();
67
68
  var previous = useAppSelector(function (state) { return state.site.previousSections; });
68
69
  var idCurrent = useAppSelector(function (state) { return state.site.idCurrentSection; });
70
+ var idForm = useContext(IdFormContext);
69
71
  var next = useAppSelector(function (state) { return state.site.nextSections; });
70
72
  /** Esto se usa para no tener que escuchar todo el tiempo los errores del formulario */
71
73
  var handleErrors = handleSubmit(function () { }, function (errors) {
@@ -92,7 +94,7 @@ function StepperForm(_a) {
92
94
  dispatch(SiteReducer.handleNext(getValues()));
93
95
  return [2 /*return*/, setLoading(undefined)];
94
96
  }
95
- return [4 /*yield*/, dispatch(getAppState()).unwrap()];
97
+ return [4 /*yield*/, dispatch(getAppState({ idForm: idForm })).unwrap()];
96
98
  case 2:
97
99
  state = _a.sent();
98
100
  values = state.site.previousSections.reduce(function (v, idSection) { return (__assign(__assign({}, v), state.site.values.sections[idSection])); }, {});
@@ -1,9 +1,9 @@
1
- export declare const selectCurrentValues: ((state: {
2
- global: import("../States/GlobalStateReducer").GlobalState;
3
- site: import("../States/SiteStateReducer").SiteState;
4
- widthStats: import("./Form").WidthStats;
5
- }) => Record<string, any>) & import("reselect").OutputSelectorFields<(args_0: string | null, args_1: Record<string, Record<string, any>>) => Record<string, any>, {
1
+ /// <reference types="react" />
2
+ import { RootState } from '../Utils/store';
3
+ import { Form } from '../@Types';
4
+ export declare const selectCurrentValues: ((state: RootState) => Record<string, any>) & import("reselect").OutputSelectorFields<(args_0: string | null, args_1: Record<string, Record<string, any>>) => Record<string, any>, {
6
5
  clearCache: () => void;
7
6
  }> & {
8
7
  clearCache: () => void;
9
8
  };
9
+ export declare function useWidthStats(containerRef: React.RefObject<HTMLDivElement>, form: Form, postview: boolean, internal: boolean): void;
@@ -1,7 +1,49 @@
1
1
  import { createSelector } from 'reselect';
2
+ import { useCallback, useLayoutEffect } from 'react';
3
+ import { updateWidthStats } from '../States/WidthStatsSlice';
4
+ import { useAppDispatch } from '../hooks';
2
5
  export var selectCurrentValues = createSelector([
3
6
  function (state) { return state.site.idCurrentSection; },
4
7
  function (state) {
5
8
  return state.site.values.sections;
6
9
  },
7
10
  ], function (idCurrent, values) { var _a; return (_a = values[idCurrent !== null && idCurrent !== void 0 ? idCurrent : '']) !== null && _a !== void 0 ? _a : {}; });
11
+ export function useWidthStats(containerRef, form, postview, internal) {
12
+ var calcWidthStats = useCallback(function (currentWidth) {
13
+ var currentBreakPoint = form.size.blockNum;
14
+ var padding = postview || internal || !form.isStandAlone ? 0 : 40;
15
+ while (currentWidth <
16
+ (form.size.blockSize + form.size.spacingSize) *
17
+ currentBreakPoint +
18
+ padding) {
19
+ currentBreakPoint--;
20
+ }
21
+ return {
22
+ isResponsive: currentWidth <
23
+ (form.size.blockSize + form.size.spacingSize) *
24
+ form.size.blockNum +
25
+ padding,
26
+ isMobile: currentWidth <
27
+ (form.size.blockSize + form.size.spacingSize) * 2 + padding,
28
+ currentBreakPoint: currentBreakPoint,
29
+ };
30
+ }, [form, postview, internal]);
31
+ var dispatch = useAppDispatch();
32
+ /** Calcs the currentBreakPoint and if is mobile */
33
+ useLayoutEffect(function () {
34
+ var handleResize = function () {
35
+ var _a;
36
+ var currentWidth = (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth;
37
+ if (currentWidth !== undefined) {
38
+ var current = calcWidthStats(currentWidth);
39
+ dispatch(updateWidthStats(current));
40
+ }
41
+ };
42
+ /** On load add a resize listener to calc the currentBreakpoint */
43
+ window.addEventListener('resize', handleResize);
44
+ handleResize();
45
+ return function () {
46
+ window.removeEventListener('resize', handleResize);
47
+ };
48
+ }, []);
49
+ }
@@ -38,7 +38,7 @@ import styles from './MaterialCBRIncidentsStep.module.css';
38
38
  import { nanoid } from 'nanoid';
39
39
  import RoundedButton from '../../../../Shared/RoundedButton/RoundedButton';
40
40
  import FormContext from '../../../../Contexts/FormContext';
41
- import { addStepsDependencies } from '../../../../States/SiteStateReducer';
41
+ import { addStepsDependencies } from '../../../../States/SiteSlice';
42
42
  import { useAppDispatch, useAppSelector } from '../../../../hooks';
43
43
  import CustomContext from '../../../../Contexts/CustomContext';
44
44
  import { Controller } from 'react-hook-form';
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { StepProps } from './Step';
3
3
  import { Form } from '../@Types';
4
- import { GlobalState } from '../States/GlobalStateReducer';
4
+ import { GlobalState } from '../States/GlobalSlice';
5
5
  import { WidthStats } from '../Form/Form';
6
6
  import { StepDependency } from './StepHooks';
7
- import { SiteState } from '../States/SiteStateReducer';
7
+ import { SiteState } from '../States/SiteSlice';
8
8
  export interface CustomStepProps extends StepProps, GlobalState, StepDependency {
9
9
  form: Form;
10
10
  dependencyStore: SiteState['dependencies'];
@@ -30,7 +30,7 @@ function CustomStepComponent(_a) {
30
30
  var customStep = _a.customStep, props = __rest(_a, ["customStep"]);
31
31
  var form = useContext(FormContext);
32
32
  var global = useAppSelector(function (state) { return state.global; });
33
- var customStepProps = useContext(CustomStepPropsContext);
33
+ var customStepProps = useContext(CustomStepPropsContext).customStepProps;
34
34
  var dependencyStore = useAppSelector(function (state) { return state.site.dependencies; });
35
35
  var widthStats = useAppSelector(function (state) { return state.widthStats; });
36
36
  var dependencyInfo = useStepDependency(props.step);
@@ -37,7 +37,7 @@ import { Controller, useFormContext } from 'react-hook-form';
37
37
  import { MapperStyleTypes } from '../../../constants/FormStepTypes';
38
38
  import RoundedButton from '../../../Shared/RoundedButton/RoundedButton';
39
39
  import MapperElementComponent from './Element/MapperElementComponent';
40
- import { addStepsDependencies } from '../../../States/SiteStateReducer';
40
+ import { addStepsDependencies } from '../../../States/SiteSlice';
41
41
  import FormContext from '../../../Contexts/FormContext';
42
42
  import { useAppDispatch, useAppSelector } from '../../../hooks';
43
43
  import CustomContext from '../../../Contexts/CustomContext';
@@ -65,7 +65,7 @@ import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
65
65
  import React from 'react';
66
66
  import FormContext from '../../../Contexts/FormContext';
67
67
  import { selectBreakPoint, useAppDispatch, useAppSelector, } from '../../../hooks';
68
- import { focusStep, setEmptyDependency, } from '../../../States/SiteStateReducer';
68
+ import { focusStep, setEmptyDependency } from '../../../States/SiteSlice';
69
69
  import { selectDependencies, useStepDependency } from '../../StepHooks';
70
70
  export function SmartSelect(_a) {
71
71
  var _this = this;
@@ -1,4 +1,5 @@
1
1
  import { GBaseStep } from '../@Types/GenericFormSteps';
2
+ import { RootState } from '../Utils/store';
2
3
  import { Form } from '../@Types';
3
4
  import { DependencyStore } from '../Form/Form';
4
5
  export interface StepDependency {
@@ -7,11 +8,7 @@ export interface StepDependency {
7
8
  handleStepDep: (value: any | undefined) => void;
8
9
  }
9
10
  export declare const useStepDependency: (step: GBaseStep, defaultValue?: any) => StepDependency;
10
- export declare const selectDependencies: ((state: {
11
- global: import("../States/GlobalStateReducer").GlobalState;
12
- site: import("../States/SiteStateReducer").SiteState;
13
- widthStats: import("../Form/Form").WidthStats;
14
- }, step: GBaseStep, form: Form) => {
11
+ export declare const selectDependencies: ((state: RootState, step: GBaseStep, form: Form) => {
15
12
  invalids: string[];
16
13
  emptyDep: boolean;
17
14
  }) & import("reselect").OutputSelectorFields<(args_0: DependencyStore, args_1: GBaseStep, args_2: Form) => {
@@ -9,7 +9,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
9
9
  };
10
10
  import { useCallback, useEffect } from 'react';
11
11
  import { useAppSelector, useAppDispatch } from '../hooks';
12
- import { setStepDependency } from '../States/SiteStateReducer';
12
+ import { setStepDependency } from '../States/SiteSlice';
13
13
  import { createSelector } from '@reduxjs/toolkit';
14
14
  import { calcDefaultValue } from './StepFunctions';
15
15
  var selectIsDependency = createSelector([
@@ -1,6 +1,6 @@
1
1
  import { FormStyle } from '../@Types/Form';
2
2
  import type { PayloadAction } from '@reduxjs/toolkit';
3
- import { SiteState } from './SiteStateReducer';
3
+ import { SiteState } from './SiteSlice';
4
4
  export interface GlobalState {
5
5
  idOrganization: string;
6
6
  formStyle: FormStyle;
@@ -15,15 +15,15 @@ export interface GlobalState {
15
15
  export declare const GlobalSlice: import("@reduxjs/toolkit").Slice<GlobalState, {
16
16
  reset: (state: import("immer/dist/internal").WritableDraft<GlobalState>, action: PayloadAction<Omit<GlobalState, 'loaded'> & SiteState>) => {
17
17
  loaded: true;
18
- idOrganization: string;
19
- formStyle: FormStyle;
20
18
  editable: boolean;
21
- preview: boolean;
22
- postview: boolean;
23
19
  partial: boolean;
20
+ postview: boolean;
21
+ formStyle: FormStyle;
22
+ preview: boolean;
23
+ idOrganization: string;
24
24
  internal: boolean;
25
25
  dependencies: import("../Form/Form").DependencyStore;
26
- values: import("./SiteStateReducer").ValuesStore;
26
+ values: import("./SiteSlice").ValuesStore;
27
27
  idCurrentSection: string | null;
28
28
  previousSections: string[];
29
29
  nextSections: string[];
@@ -31,5 +31,4 @@ export declare const GlobalSlice: import("@reduxjs/toolkit").Slice<GlobalState,
31
31
  };
32
32
  }, "global">;
33
33
  export declare const reset: import("@reduxjs/toolkit").ActionCreatorWithPayload<Omit<GlobalState, "loaded"> & SiteState, "global/reset">;
34
- declare const _default: import("redux").Reducer<GlobalState, import("redux").AnyAction>;
35
- export default _default;
34
+ export default GlobalSlice;
@@ -31,4 +31,4 @@ export var GlobalSlice = createSlice({
31
31
  },
32
32
  });
33
33
  export var reset = GlobalSlice.actions.reset;
34
- export default GlobalSlice.reducer;
34
+ export default GlobalSlice;
@@ -59,5 +59,4 @@ export declare const focusStep: import("@reduxjs/toolkit").ActionCreatorWithOpti
59
59
  step: GBaseStep;
60
60
  empty: StepDependency['empty'];
61
61
  }, "site/setEmptyDependency">, handlePrevious: import("@reduxjs/toolkit").ActionCreatorWithPayload<Record<string, any>, "site/handlePrevious">, handleNext: import("@reduxjs/toolkit").ActionCreatorWithPayload<Record<string, any>, "site/handleNext">;
62
- declare const _default: import("redux").Reducer<SiteState, import("redux").AnyAction>;
63
- export default _default;
62
+ export default SiteSlice;
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  var _a;
13
13
  import { createSlice } from '@reduxjs/toolkit';
14
- import { reset } from './GlobalStateReducer';
14
+ import { reset } from './GlobalSlice';
15
15
  import { calcDependencies } from '../Form/FormFunctions';
16
16
  import { calcDefaultValue } from '../FormSteps/StepFunctions';
17
17
  var initialState = {
@@ -107,4 +107,4 @@ export var SiteSlice = createSlice({
107
107
  },
108
108
  });
109
109
  export var focusStep = (_a = SiteSlice.actions, _a.focusStep), setStepDependency = _a.setStepDependency, addStepsDependencies = _a.addStepsDependencies, setEmptyDependency = _a.setEmptyDependency, handlePrevious = _a.handlePrevious, handleNext = _a.handleNext;
110
- export default SiteSlice.reducer;
110
+ export default SiteSlice;
@@ -0,0 +1,7 @@
1
+ import { WidthStats } from '../Form/Form';
2
+ import type { PayloadAction } from '@reduxjs/toolkit';
3
+ export declare const WidthStatsSlice: import("@reduxjs/toolkit").Slice<WidthStats, {
4
+ updateWidthStats: (state: import("immer/dist/internal").WritableDraft<WidthStats>, { payload }: PayloadAction<WidthStats>) => WidthStats;
5
+ }, "widthStats">;
6
+ export declare const updateWidthStats: import("@reduxjs/toolkit").ActionCreatorWithPayload<WidthStats, "widthStats/updateWidthStats">;
7
+ export default WidthStatsSlice;
@@ -0,0 +1,23 @@
1
+ import { createSlice } from '@reduxjs/toolkit';
2
+ var initialState = {
3
+ currentBreakPoint: 0,
4
+ isMobile: false,
5
+ isResponsive: false,
6
+ };
7
+ export var WidthStatsSlice = createSlice({
8
+ name: 'widthStats',
9
+ initialState: initialState,
10
+ reducers: {
11
+ updateWidthStats: function (state, _a) {
12
+ var payload = _a.payload;
13
+ if (payload.isMobile !== (state === null || state === void 0 ? void 0 : state.isMobile) ||
14
+ payload.isResponsive !== (state === null || state === void 0 ? void 0 : state.isResponsive) ||
15
+ payload.currentBreakPoint !== (state === null || state === void 0 ? void 0 : state.currentBreakPoint))
16
+ return payload;
17
+ else
18
+ return state;
19
+ },
20
+ },
21
+ });
22
+ export var updateWidthStats = WidthStatsSlice.actions.updateWidthStats;
23
+ export default WidthStatsSlice;
@@ -1,21 +1,21 @@
1
- export declare const store: import("@reduxjs/toolkit/dist/configureStore").ToolkitStore<{
2
- global: import("../States/GlobalStateReducer").GlobalState;
3
- site: import("../States/SiteStateReducer").SiteState;
4
- widthStats: import("../Form/Form").WidthStats;
5
- }, import("redux").AnyAction, [import("@reduxjs/toolkit").ThunkMiddleware<{
6
- global: import("../States/GlobalStateReducer").GlobalState;
7
- site: import("../States/SiteStateReducer").SiteState;
8
- widthStats: import("../Form/Form").WidthStats;
9
- }, import("redux").AnyAction, undefined>]>;
10
- export type RootState = ReturnType<typeof store.getState>;
1
+ import { AnyAction } from '@reduxjs/toolkit';
2
+ import { GlobalState } from '../States/GlobalSlice';
3
+ import { SiteState } from '../States/SiteSlice';
4
+ import { WidthStats } from '../Form/Form';
5
+ export interface RootState {
6
+ global: GlobalState;
7
+ site: SiteState;
8
+ widthStats: WidthStats;
9
+ }
10
+ export declare const defaultRootState: RootState;
11
+ export type EurekaFormsState = Record<string, RootState>;
12
+ export declare const store: import("@reduxjs/toolkit/dist/configureStore").ToolkitStore<EurekaFormsState, AnyAction, [import("@reduxjs/toolkit").ThunkMiddleware<EurekaFormsState, AnyAction, undefined>]>;
11
13
  export type AppDispatch = typeof store.dispatch;
12
- export declare const getAppState: import("@reduxjs/toolkit").AsyncThunk<{
13
- global: import("../States/GlobalStateReducer").GlobalState;
14
- site: import("../States/SiteStateReducer").SiteState;
15
- widthStats: import("../Form/Form").WidthStats;
16
- }, void, {
14
+ export declare const getAppState: import("@reduxjs/toolkit").AsyncThunk<RootState, {
15
+ idForm: string;
16
+ }, {
17
17
  state?: unknown;
18
- dispatch?: import("redux").Dispatch<import("redux").AnyAction> | undefined;
18
+ dispatch?: import("redux").Dispatch<AnyAction> | undefined;
19
19
  extra?: unknown;
20
20
  rejectValue?: unknown;
21
21
  serializedErrorType?: unknown;
@@ -1,3 +1,14 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
13
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
14
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -34,19 +45,40 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
46
  }
36
47
  };
37
- import { configureStore, createAsyncThunk } from '@reduxjs/toolkit';
38
- import GlobalStateReducer from '../States/GlobalStateReducer';
39
- import SiteStateReducer from '../States/SiteStateReducer';
40
- import WidthStatsStateReducer from '../States/WidthStatsStateReducer';
48
+ import { combineReducers, configureStore, createAsyncThunk, } from '@reduxjs/toolkit';
49
+ import GlobalSlice from '../States/GlobalSlice';
50
+ import SiteSlice from '../States/SiteSlice';
51
+ import WidthStatsSlice from '../States/WidthStatsSlice';
52
+ export var defaultRootState = {
53
+ global: GlobalSlice.getInitialState(),
54
+ site: SiteSlice.getInitialState(),
55
+ widthStats: WidthStatsSlice.getInitialState(),
56
+ };
57
+ var FormReducer = combineReducers({
58
+ global: GlobalSlice.reducer,
59
+ site: SiteSlice.reducer,
60
+ widthStats: WidthStatsSlice.reducer,
61
+ });
62
+ function EurekaFormsReducer(state, action) {
63
+ var _a, _b;
64
+ var _c;
65
+ if (state === void 0) { state = {}; }
66
+ var idForm = (_c = action.meta) === null || _c === void 0 ? void 0 : _c.idForm;
67
+ if (!idForm)
68
+ return state;
69
+ if (action.type === 'CLEAR') {
70
+ return __assign(__assign({}, state), (_a = {}, _a[idForm] = undefined, _a));
71
+ }
72
+ return __assign(__assign({}, state), (_b = {}, _b[idForm] = FormReducer(state[idForm], action), _b));
73
+ }
41
74
  export var store = configureStore({
42
- reducer: {
43
- global: GlobalStateReducer,
44
- site: SiteStateReducer,
45
- widthStats: WidthStatsStateReducer,
46
- },
75
+ reducer: EurekaFormsReducer,
47
76
  });
48
- export var getAppState = createAsyncThunk('get/state', function (payload, thunkAPI) { return __awaiter(void 0, void 0, void 0, function () {
49
- return __generator(this, function (_a) {
50
- return [2 /*return*/, thunkAPI.getState()];
77
+ export var getAppState = createAsyncThunk('get/state', function (_a, thunkAPI) {
78
+ var idForm = _a.idForm;
79
+ return __awaiter(void 0, void 0, void 0, function () {
80
+ return __generator(this, function (_b) {
81
+ return [2 /*return*/, thunkAPI.getState()[idForm]];
82
+ });
51
83
  });
52
- }); });
84
+ });
package/dist/hooks.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { TypedUseSelectorHook } from 'react-redux';
2
- import type { RootState, AppDispatch } from './Utils/store';
2
+ import { type RootState, type AppDispatch } from './Utils/store';
3
3
  export declare const useAppDispatch: () => AppDispatch;
4
4
  export declare const useAppSelector: TypedUseSelectorHook<RootState>;
5
5
  export declare const selectBreakPoint: (state: RootState) => number;
package/dist/hooks.js CHANGED
@@ -1,7 +1,21 @@
1
1
  import { useDispatch, useSelector } from 'react-redux';
2
+ import { defaultRootState, } from './Utils/store';
3
+ import { useContext } from 'react';
4
+ import { IdFormContext } from './App/App';
2
5
  // Use throughout your app instead of plain `useDispatch` and `useSelector`
3
- export var useAppDispatch = useDispatch;
4
- export var useAppSelector = useSelector;
6
+ export var useAppDispatch = function () {
7
+ var idForm = useContext(IdFormContext);
8
+ var dispatch = useDispatch();
9
+ var appDispatch = function (action) {
10
+ action.meta = { idForm: idForm };
11
+ return dispatch(action);
12
+ };
13
+ return appDispatch;
14
+ };
15
+ export var useAppSelector = function (selector, options) {
16
+ var idForm = useContext(IdFormContext);
17
+ return useSelector(function (state) { var _a; return selector((_a = state[idForm]) !== null && _a !== void 0 ? _a : defaultRootState); }, options);
18
+ };
5
19
  export var selectBreakPoint = function (state) {
6
20
  return state.widthStats.currentBreakPoint;
7
21
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arquimedes.co/eureka-forms",
3
3
  "repository": "git://github.com/Arquimede5/Eureka-Forms.git",
4
- "version":"2.0.8-test",
4
+ "version":"2.0.10-test",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",
@@ -1,11 +0,0 @@
1
- /// <reference types="react" />
2
- import { WidthStats } from '../Form/Form';
3
- import { Form } from '../@Types';
4
- import type { PayloadAction } from '@reduxjs/toolkit';
5
- export declare const WidthStatsSlice: import("@reduxjs/toolkit").Slice<WidthStats, {
6
- updateWidthStats: (state: import("immer/dist/internal").WritableDraft<WidthStats>, { payload }: PayloadAction<WidthStats>) => WidthStats;
7
- }, "widthstats">;
8
- export declare const updateWidthStats: import("@reduxjs/toolkit").ActionCreatorWithPayload<WidthStats, "widthstats/updateWidthStats">;
9
- declare const _default: import("redux").Reducer<WidthStats, import("redux").AnyAction>;
10
- export default _default;
11
- export declare function useWidthStats(containerRef: React.RefObject<HTMLDivElement>, form: Form, postview: boolean, internal: boolean): void;
@@ -1,64 +0,0 @@
1
- import { useCallback, useLayoutEffect } from 'react';
2
- import { createSlice } from '@reduxjs/toolkit';
3
- import { useDispatch } from 'react-redux';
4
- var initialState = {
5
- currentBreakPoint: 0,
6
- isMobile: false,
7
- isResponsive: false,
8
- };
9
- export var WidthStatsSlice = createSlice({
10
- name: 'widthstats',
11
- initialState: initialState,
12
- reducers: {
13
- updateWidthStats: function (state, _a) {
14
- var payload = _a.payload;
15
- if (payload.isMobile !== (state === null || state === void 0 ? void 0 : state.isMobile) ||
16
- payload.isResponsive !== (state === null || state === void 0 ? void 0 : state.isResponsive) ||
17
- payload.currentBreakPoint !== (state === null || state === void 0 ? void 0 : state.currentBreakPoint))
18
- return payload;
19
- else
20
- return state;
21
- },
22
- },
23
- });
24
- export var updateWidthStats = WidthStatsSlice.actions.updateWidthStats;
25
- export default WidthStatsSlice.reducer;
26
- export function useWidthStats(containerRef, form, postview, internal) {
27
- var calcWidthStats = useCallback(function (currentWidth) {
28
- var currentBreakPoint = form.size.blockNum;
29
- var padding = postview || internal || !form.isStandAlone ? 0 : 40;
30
- while (currentWidth <
31
- (form.size.blockSize + form.size.spacingSize) *
32
- currentBreakPoint +
33
- padding) {
34
- currentBreakPoint--;
35
- }
36
- return {
37
- isResponsive: currentWidth <
38
- (form.size.blockSize + form.size.spacingSize) *
39
- form.size.blockNum +
40
- padding,
41
- isMobile: currentWidth <
42
- (form.size.blockSize + form.size.spacingSize) * 2 + padding,
43
- currentBreakPoint: currentBreakPoint,
44
- };
45
- }, [form, postview, internal]);
46
- var dispatch = useDispatch();
47
- /** Calcs the currentBreakPoint and if is mobile */
48
- useLayoutEffect(function () {
49
- var handleResize = function () {
50
- var _a;
51
- var currentWidth = (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth;
52
- if (currentWidth !== undefined) {
53
- var current = calcWidthStats(currentWidth);
54
- dispatch(updateWidthStats(current));
55
- }
56
- };
57
- /** On load add a resize listener to calc the currentBreakpoint */
58
- window.addEventListener('resize', handleResize);
59
- handleResize();
60
- return function () {
61
- window.removeEventListener('resize', handleResize);
62
- };
63
- }, []);
64
- }