@arquimedes.co/eureka-forms 2.0.103 → 2.0.104

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.
@@ -2,6 +2,7 @@ import { Condition } from './Condition';
2
2
  export interface GBaseStep {
3
3
  id: string;
4
4
  idSection: string;
5
+ idOriginal: string;
5
6
  type: string;
6
7
  editable?: boolean;
7
8
  partial?: boolean;
package/dist/App/App.js CHANGED
@@ -29,9 +29,10 @@ import FormComponent from '../Form/Form';
29
29
  import { Provider } from 'react-redux';
30
30
  import { store } from '../Utils/store';
31
31
  import { useSetupApp } from './AppHooks';
32
- import { StoreContext, useAppSelector } from '../hooks';
32
+ import { useAppSelector } from '../hooks';
33
33
  import CustomContext from '../Contexts/CustomContext';
34
34
  import { nanoid } from '@reduxjs/toolkit';
35
+ import { StoreContext } from '../Utils/StoreContext';
35
36
  export var IdFormContext = createContext('');
36
37
  function AppComponent(_a) {
37
38
  var formData = _a.formData, valuesData = _a.valuesData, props = __rest(_a, ["formData", "valuesData"]);
@@ -6,8 +6,8 @@ import { MapperElement } from '../@Types/MapperElement';
6
6
  import { MapperValue } from '../FormSteps/MapperStep/MaterialMapperStep/MaterialMapperStep';
7
7
  import { CountryCode } from 'libphonenumber-js/max';
8
8
  export declare const calcValuesStore: (orgInfo: {
9
- idOrganization: string;
10
- countryCode: CountryCode;
9
+ idOrganization?: string;
10
+ countryCode?: CountryCode;
11
11
  }, form: Readonly<Form>, originalValues?: Record<string, any>, postview?: boolean, customSteps?: Record<string, CustomStep>) => Promise<ValuesStore>;
12
12
  export declare const addMapperStep: <Type>(step: Mapper, customSteps: Record<string, CustomStep>, path?: string) => {
13
13
  element: MapperElement<Type>;
@@ -17,7 +17,7 @@ export declare const addMapperStep: <Type>(step: Mapper, customSteps: Record<str
17
17
  steps: Record<string, FormStep>;
18
18
  };
19
19
  export declare const mapOriginalValue: (orgInfo: {
20
- idOrganization: string;
21
- countryCode: CountryCode;
20
+ idOrganization?: string;
21
+ countryCode?: CountryCode;
22
22
  }, step: FormStep, value: any, values: ValuesStore, form?: Readonly<Form>, path?: string) => Promise<any>;
23
23
  export declare const calcInitialSections: (form: Form) => Pick<SiteState, 'previousSections' | 'idCurrentSection' | 'nextSections'>;
@@ -157,6 +157,7 @@ export var useSetupApp = function (isEmbedded, _a) {
157
157
  var idStep = _c[_b];
158
158
  iterateNestedSteps(idStep, form.steps, function (step) {
159
159
  step.idSection = section.id;
160
+ step.idOriginal = step.id;
160
161
  });
161
162
  }
162
163
  };
@@ -9,6 +9,8 @@ import { FormStep } from '../@Types/FormStep';
9
9
  import { CBRFormStep } from '../@Types/CBRFormStep';
10
10
  export declare const getLocale: () => any;
11
11
  export interface StepDependency {
12
+ /** The id of the step before it was mapped */
13
+ idOriginal: string;
12
14
  dependents: (FormStep | CBRFormStep)[];
13
15
  value: any | undefined;
14
16
  type: FormStepTypes | CBRFormStepTypes | 'ORIGINAL';
@@ -215,6 +215,7 @@ function calcStepDependency(idStep, steps, values, customSteps) {
215
215
  if (!originalValue_1)
216
216
  console.error('Missing Step Dependency:', idStep);
217
217
  return {
218
+ idOriginal: idStep,
218
219
  type: originalValue_1 ? 'ORIGINAL' : 'MISSING',
219
220
  value: originalValue_1 !== null && originalValue_1 !== void 0 ? originalValue_1 : null,
220
221
  dependents: [],
@@ -223,6 +224,7 @@ function calcStepDependency(idStep, steps, values, customSteps) {
223
224
  var originalValue = (_b = (_a = values.sections[depStep.idSection]) === null || _a === void 0 ? void 0 : _a[depStep.id]) !== null && _b !== void 0 ? _b : values.global[depStep.id];
224
225
  return {
225
226
  type: depStep.type,
227
+ idOriginal: depStep.idOriginal,
226
228
  value: calcStepDependencyValue(depStep, originalValue, customSteps),
227
229
  dependents: [],
228
230
  };
@@ -14,13 +14,13 @@ import { calcStepWidth } from '../../StepFunctions';
14
14
  import styles from './MaterialTitleStep.module.css';
15
15
  import { useAppSelector } from '../../../hooks';
16
16
  import FormContext from '../../../Contexts/FormContext';
17
- import { useContext } from 'react';
18
- import { useFormStep } from '../../StepHooks';
19
- import { convertFromRaw, EditorState } from 'draft-js';
17
+ import { useContext, useMemo } from 'react';
18
+ import { selectDependencies, useFormStep } from '../../StepHooks';
19
+ import { convertFromRaw } from 'draft-js';
20
20
  import { stringToDraft } from '../../../Utils/DraftFunctions';
21
- import { Editor } from 'react-draft-wysiwyg';
21
+ import SmartDraftRenderer from '../../../Shared/SmartDraftRenderer';
22
22
  function TitleStep(_a) {
23
- var _b, _c, _d;
23
+ var _b;
24
24
  var step = _a.step;
25
25
  var value = useFormStep(step, {
26
26
  defaultValue: undefined,
@@ -29,24 +29,38 @@ function TitleStep(_a) {
29
29
  var form = useContext(FormContext);
30
30
  var widthStats = useAppSelector(function (state) { return state.widthStats; });
31
31
  var size = (_b = step.size) !== null && _b !== void 0 ? _b : form.size.blockNum;
32
- var title = convertFromRaw((value === null || value === void 0 ? void 0 : value.title)
33
- ? stringToDraft(value.title)
34
- : (_c = step.title) !== null && _c !== void 0 ? _c : stringToDraft(''));
35
- var description = convertFromRaw((value === null || value === void 0 ? void 0 : value.description)
36
- ? stringToDraft(value.description)
37
- : (_d = step.description) !== null && _d !== void 0 ? _d : stringToDraft(''));
32
+ var title = useMemo(function () { return calcBaseDraft(value === null || value === void 0 ? void 0 : value.title, step.title); }, [value === null || value === void 0 ? void 0 : value.title, step.title]);
33
+ var hasTitle = useMemo(function () { return convertFromRaw(title).getPlainText().length > 0; }, [title]);
34
+ var description = useMemo(function () { return calcBaseDraft(value === null || value === void 0 ? void 0 : value.description, step.description); }, [value === null || value === void 0 ? void 0 : value.description, step.description]);
35
+ var hasDescription = useMemo(function () { return convertFromRaw(description).getPlainText().length > 0; }, [description]);
36
+ var dependencies = useAppSelector(function (state) {
37
+ return selectDependencies(state, step.dependencies);
38
+ });
39
+ var values = useMemo(function () {
40
+ var values = {};
41
+ for (var _i = 0, _a = Object.values(dependencies); _i < _a.length; _i++) {
42
+ var _b = _a[_i], idOriginal = _b.idOriginal, value_1 = _b.value;
43
+ values[idOriginal] = value_1;
44
+ }
45
+ return values;
46
+ }, [dependencies]);
38
47
  return (_jsxs("div", __assign({ className: styles.container, style: {
39
48
  color: formStyle.textColor,
40
49
  width: widthStats.currentBreakPoint <= size
41
50
  ? '100%'
42
51
  : calcStepWidth(size, form.size),
43
- } }, { children: [title.getPlainText().length > 0 && (_jsx("div", __assign({ className: styles.titleLbl, style: {
52
+ } }, { children: [hasTitle && (_jsx("div", __assign({ className: styles.titleLbl, style: {
44
53
  textAlign: widthStats.isMobile &&
45
54
  widthStats.currentBreakPoint <= size
46
55
  ? 'center'
47
56
  : 'start',
48
- } }, { children: _jsx(Editor, { editorClassName: 'Erk-Forms-Draft', editorState: EditorState.createWithContent(title), readOnly: true, toolbarHidden: true }) }))), description.getPlainText().length > 0 && (_jsx("div", __assign({ className: styles.descriptionPar, style: {
57
+ } }, { children: _jsx(SmartDraftRenderer, { draft: title, dependencies: values }) }))), hasDescription && (_jsx("div", __assign({ className: styles.descriptionPar, style: {
49
58
  margin: title ? '10px 0px' : '0px 0px 5px 0px',
50
- } }, { children: _jsx(Editor, { editorClassName: 'Erk-Forms-Draft', editorState: EditorState.createWithContent(description), readOnly: true, toolbarHidden: true }) })))] })));
59
+ } }, { children: _jsx(SmartDraftRenderer, { draft: description, dependencies: values }) })))] })));
51
60
  }
52
61
  export default TitleStep;
62
+ function calcBaseDraft(value, draft) {
63
+ return value
64
+ ? stringToDraft(value)
65
+ : draft !== null && draft !== void 0 ? draft : stringToDraft('');
66
+ }
@@ -0,0 +1,21 @@
1
+ import { EurekaDraft } from '../@Types/Draft/Draft';
2
+ export declare const DraftApi: import("@reduxjs/toolkit/query").Api<import("@reduxjs/toolkit/query").BaseQueryFn<{
3
+ url: string;
4
+ timeout?: number | undefined;
5
+ method?: string | undefined;
6
+ body?: any;
7
+ params?: any;
8
+ headers?: Record<string, any> | undefined;
9
+ }, unknown, unknown, {}, {}>, {
10
+ mapDraft: import("@reduxjs/toolkit/query").QueryDefinition<{
11
+ idForm: string;
12
+ dependencies: Record<string, any>;
13
+ }, import("@reduxjs/toolkit/query").BaseQueryFn<{
14
+ url: string;
15
+ timeout?: number | undefined;
16
+ method?: string | undefined;
17
+ body?: any;
18
+ params?: any;
19
+ headers?: Record<string, any> | undefined;
20
+ }, unknown, unknown, {}, {}>, never, EurekaDraft | undefined, "api">;
21
+ }, "api", never, typeof import("@reduxjs/toolkit/query").coreModuleName | typeof import("@reduxjs/toolkit/dist/query/react").reactHooksModuleName>;
@@ -0,0 +1,71 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { RootApi } from '../Utils/_api';
38
+ import axiosInstance from '../Utils/AxiosAPI';
39
+ import widgetInstance from '../Utils/AxiosWidget';
40
+ export var DraftApi = RootApi.injectEndpoints({
41
+ endpoints: function (build) { return ({
42
+ mapDraft: build.query({
43
+ queryFn: function (_a, _b) {
44
+ var idForm = _a.idForm, dependencies = _a.dependencies;
45
+ var getState = _b.getState;
46
+ return __awaiter(void 0, void 0, void 0, function () {
47
+ var idOrganization, response;
48
+ return __generator(this, function (_c) {
49
+ switch (_c.label) {
50
+ case 0:
51
+ idOrganization = getState().forms[idForm]
52
+ .global.idOrganization;
53
+ if (idOrganization != 'AAA')
54
+ return [2 /*return*/, { data: undefined }];
55
+ if (!idOrganization) return [3 /*break*/, 2];
56
+ return [4 /*yield*/, widgetInstance.post("/form/draft?idOrganization=".concat(idOrganization), dependencies)];
57
+ case 1:
58
+ response = _c.sent();
59
+ return [3 /*break*/, 4];
60
+ case 2: return [4 /*yield*/, axiosInstance.post('/form/draft', dependencies)];
61
+ case 3:
62
+ response = _c.sent();
63
+ _c.label = 4;
64
+ case 4: return [2 /*return*/, { data: response.data }];
65
+ }
66
+ });
67
+ });
68
+ },
69
+ }),
70
+ }); },
71
+ });
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { EurekaDraft } from '../@Types/Draft/Draft';
3
+ interface SmartDraftRendererProps {
4
+ draft: EurekaDraft;
5
+ dependencies: Record<string, any>;
6
+ }
7
+ declare function SmartDraftRenderer({ draft, dependencies, }: SmartDraftRendererProps): JSX.Element;
8
+ export default SmartDraftRenderer;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useContext, useMemo } from 'react';
3
+ import { IdFormContext } from '../App/App';
4
+ import { DraftApi } from '../Services/DraftService';
5
+ import { convertFromRaw, EditorState } from 'draft-js';
6
+ import { Editor } from 'react-draft-wysiwyg';
7
+ function SmartDraftRenderer(_a) {
8
+ var draft = _a.draft, dependencies = _a.dependencies;
9
+ var idForm = useContext(IdFormContext);
10
+ var mapped = DraftApi.useMapDraftQuery({
11
+ idForm: idForm,
12
+ dependencies: dependencies,
13
+ }).data;
14
+ var editorState = useMemo(function () { return EditorState.createWithContent(convertFromRaw(mapped !== null && mapped !== void 0 ? mapped : draft)); }, [mapped, draft]);
15
+ return (_jsx(Editor, { editorClassName: 'Erk-Forms-Draft', editorState: editorState, readOnly: true, toolbarHidden: true }));
16
+ }
17
+ export default SmartDraftRenderer;
@@ -1,2 +1,13 @@
1
+ import { BaseQueryFn } from '@reduxjs/toolkit/query';
2
+ import { AxiosRequestConfig } from 'axios';
3
+ declare const headers: {};
1
4
  declare const axiosInstance: import("axios").AxiosInstance;
2
5
  export default axiosInstance;
6
+ export declare const axiosBaseQuery: () => BaseQueryFn<{
7
+ url: string;
8
+ timeout?: AxiosRequestConfig['timeout'];
9
+ method?: AxiosRequestConfig['method'];
10
+ body?: AxiosRequestConfig['data'];
11
+ params?: AxiosRequestConfig['params'];
12
+ headers?: Record<string, any>;
13
+ }, unknown, unknown>;
@@ -1,3 +1,39 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
1
37
  import axios from 'axios';
2
38
  var headers = {};
3
39
  var axiosInstance = axios.create({
@@ -6,3 +42,39 @@ var axiosInstance = axios.create({
6
42
  headers: headers,
7
43
  });
8
44
  export default axiosInstance;
45
+ export var axiosBaseQuery = function () {
46
+ return function (_a) {
47
+ var url = _a.url, method = _a.method, body = _a.body, params = _a.params, timeout = _a.timeout, headers = _a.headers;
48
+ return __awaiter(void 0, void 0, void 0, function () {
49
+ var result, axiosError_1, err;
50
+ var _b, _c;
51
+ return __generator(this, function (_d) {
52
+ switch (_d.label) {
53
+ case 0:
54
+ _d.trys.push([0, 2, , 3]);
55
+ return [4 /*yield*/, axiosInstance({
56
+ url: url,
57
+ method: method,
58
+ data: body,
59
+ params: params,
60
+ headers: headers,
61
+ timeout: timeout,
62
+ })];
63
+ case 1:
64
+ result = _d.sent();
65
+ return [2 /*return*/, { data: result.data }];
66
+ case 2:
67
+ axiosError_1 = _d.sent();
68
+ err = axiosError_1;
69
+ return [2 /*return*/, {
70
+ error: {
71
+ status: (_b = err.response) === null || _b === void 0 ? void 0 : _b.status,
72
+ data: ((_c = err.response) === null || _c === void 0 ? void 0 : _c.data) || err.message,
73
+ },
74
+ }];
75
+ case 3: return [2 /*return*/];
76
+ }
77
+ });
78
+ });
79
+ };
80
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const StoreContext: React.Context<any>;
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export var StoreContext = React.createContext({});
@@ -60,7 +60,17 @@ export declare function renderWithProviders(ui: React.ReactElement, { store, ...
60
60
  queryAllByTestId: (id: import("@testing-library/react").Matcher, options?: import("@testing-library/react").MatcherOptions | undefined) => HTMLElement[];
61
61
  findByTestId: (id: import("@testing-library/react").Matcher, options?: import("@testing-library/react").MatcherOptions | undefined, waitForElementOptions?: import("@testing-library/react").waitForOptions | undefined) => Promise<HTMLElement>;
62
62
  findAllByTestId: (id: import("@testing-library/react").Matcher, options?: import("@testing-library/react").MatcherOptions | undefined, waitForElementOptions?: import("@testing-library/react").waitForOptions | undefined) => Promise<HTMLElement[]>;
63
- store: import("@reduxjs/toolkit/dist/configureStore").ToolkitStore<import("./store").EurekaFormsState, import("redux").AnyAction, [import("@reduxjs/toolkit").ThunkMiddleware<import("./store").EurekaFormsState, import("redux").AnyAction, undefined>]>;
63
+ store: import("@reduxjs/toolkit/dist/configureStore").ToolkitStore<import("redux").EmptyObject & {
64
+ forms: {
65
+ [x: string]: import("./store").RootState;
66
+ };
67
+ api: import("@reduxjs/toolkit/query").CombinedState<{}, never, "api">;
68
+ }, import("redux").AnyAction, import("@reduxjs/toolkit").MiddlewareArray<[import("@reduxjs/toolkit").ThunkMiddleware<import("redux").CombinedState<{
69
+ forms: {
70
+ [x: string]: import("./store").RootState;
71
+ };
72
+ api: import("@reduxjs/toolkit/query").CombinedState<{}, never, "api">;
73
+ }>, import("redux").AnyAction, undefined>, import("redux").Middleware<{}, import("@reduxjs/toolkit/query").RootState<{}, string, "api">, import("@reduxjs/toolkit").ThunkDispatch<any, any, import("redux").AnyAction>>]>>;
64
74
  };
65
75
  interface ExtendedRenderHookOptions<TProps> extends Omit<RenderHookOptions<TProps>, 'wrapper'> {
66
76
  store?: AppStore;
@@ -72,6 +82,16 @@ export declare function renderHookWithProviders<TProps, TResult>(callback: (prop
72
82
  waitFor: import("@testing-library/react-hooks").WaitFor;
73
83
  waitForValueToChange: import("@testing-library/react-hooks").WaitForValueToChange;
74
84
  waitForNextUpdate: import("@testing-library/react-hooks").WaitForNextUpdate;
75
- store: import("@reduxjs/toolkit/dist/configureStore").ToolkitStore<import("./store").EurekaFormsState, import("redux").AnyAction, [import("@reduxjs/toolkit").ThunkMiddleware<import("./store").EurekaFormsState, import("redux").AnyAction, undefined>]>;
85
+ store: import("@reduxjs/toolkit/dist/configureStore").ToolkitStore<import("redux").EmptyObject & {
86
+ forms: {
87
+ [x: string]: import("./store").RootState;
88
+ };
89
+ api: import("@reduxjs/toolkit/query").CombinedState<{}, never, "api">;
90
+ }, import("redux").AnyAction, import("@reduxjs/toolkit").MiddlewareArray<[import("@reduxjs/toolkit").ThunkMiddleware<import("redux").CombinedState<{
91
+ forms: {
92
+ [x: string]: import("./store").RootState;
93
+ };
94
+ api: import("@reduxjs/toolkit/query").CombinedState<{}, never, "api">;
95
+ }>, import("redux").AnyAction, undefined>, import("redux").Middleware<{}, import("@reduxjs/toolkit/query").RootState<{}, string, "api">, import("@reduxjs/toolkit").ThunkDispatch<any, any, import("redux").AnyAction>>]>>;
76
96
  };
77
97
  export {};
@@ -23,13 +23,14 @@ var __rest = (this && this.__rest) || function (s, e) {
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
24
  import React from 'react';
25
25
  import { render } from '@testing-library/react';
26
- import { configureStore, nanoid } from '@reduxjs/toolkit';
26
+ import { combineReducers, configureStore, nanoid } from '@reduxjs/toolkit';
27
27
  import { Provider } from 'react-redux';
28
28
  // As a basic setup, import your same slice reducers
29
29
  import { EurekaFormsReducer } from './store';
30
30
  import { renderHook } from '@testing-library/react-hooks';
31
31
  import { IdFormContext } from '../App/App';
32
- import { StoreContext } from '../hooks';
32
+ import { RootApi } from './_api';
33
+ import { StoreContext } from './StoreContext';
33
34
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
34
35
  export function renderWithProviders(ui, _a) {
35
36
  if (_a === void 0) { _a = {}; }
@@ -38,7 +39,10 @@ export function renderWithProviders(ui, _a) {
38
39
  _b = _a.store,
39
40
  // Automatically create a store instance if no store was passed in
40
41
  store = _b === void 0 ? configureStore({
41
- reducer: EurekaFormsReducer,
42
+ reducer: combineReducers({
43
+ forms: EurekaFormsReducer,
44
+ api: RootApi.reducer,
45
+ }),
42
46
  }) : _b, renderOptions = __rest(_a, ["store"]);
43
47
  // eslint-disable-next-line @typescript-eslint/ban-types
44
48
  function Wrapper(_a) {
@@ -52,7 +56,10 @@ export function renderWithProviders(ui, _a) {
52
56
  export function renderHookWithProviders(callback, _a) {
53
57
  if (_a === void 0) { _a = {}; }
54
58
  var _b = _a.store, store = _b === void 0 ? configureStore({
55
- reducer: EurekaFormsReducer,
59
+ reducer: combineReducers({
60
+ forms: EurekaFormsReducer,
61
+ api: RootApi.reducer,
62
+ }),
56
63
  }) : _b, renderHookOptions = __rest(_a, ["store"]);
57
64
  // eslint-disable-next-line @typescript-eslint/ban-types
58
65
  function Wrapper(_a) {
@@ -0,0 +1,8 @@
1
+ export declare const RootApi: import("@reduxjs/toolkit/query/react").Api<import("@reduxjs/toolkit/query/react").BaseQueryFn<{
2
+ url: string;
3
+ timeout?: number | undefined;
4
+ method?: string | undefined;
5
+ body?: any;
6
+ params?: any;
7
+ headers?: Record<string, any> | undefined;
8
+ }, unknown, unknown, {}, {}>, {}, "api", never, typeof import("@reduxjs/toolkit/query/react").coreModuleName | typeof import("@reduxjs/toolkit/query/react").reactHooksModuleName>;
@@ -0,0 +1,13 @@
1
+ import { buildCreateApi, coreModule, reactHooksModule, } from '@reduxjs/toolkit/query/react';
2
+ import { axiosBaseQuery } from './AxiosAPI';
3
+ import { createDispatchHook, createSelectorHook, createStoreHook, } from 'react-redux';
4
+ import { StoreContext } from './StoreContext';
5
+ var customCreateApi = buildCreateApi(coreModule(), reactHooksModule({
6
+ useDispatch: createDispatchHook(StoreContext),
7
+ useSelector: createSelectorHook(StoreContext),
8
+ useStore: createStoreHook(StoreContext),
9
+ }));
10
+ export var RootApi = customCreateApi({
11
+ baseQuery: axiosBaseQuery(),
12
+ endpoints: function () { return ({}); },
13
+ });
@@ -8,11 +8,18 @@ export interface RootState {
8
8
  widthStats: WidthStats;
9
9
  }
10
10
  export declare const defaultRootState: RootState;
11
- export type EurekaFormsState = Record<string, RootState>;
11
+ type EurekaFormsState = Record<string, RootState>;
12
12
  export declare function EurekaFormsReducer(state: EurekaFormsState | undefined, action: AnyAction): EurekaFormsState;
13
- export declare const store: import("@reduxjs/toolkit/dist/configureStore").ToolkitStore<EurekaFormsState, AnyAction, [import("@reduxjs/toolkit").ThunkMiddleware<EurekaFormsState, AnyAction, undefined>]>;
13
+ export declare const store: import("@reduxjs/toolkit/dist/configureStore").ToolkitStore<import("redux").EmptyObject & {
14
+ forms: EurekaFormsState;
15
+ api: import("@reduxjs/toolkit/query").CombinedState<{}, never, "api">;
16
+ }, AnyAction, import("@reduxjs/toolkit").MiddlewareArray<[import("@reduxjs/toolkit").ThunkMiddleware<import("redux").CombinedState<{
17
+ forms: EurekaFormsState;
18
+ api: import("@reduxjs/toolkit/query").CombinedState<{}, never, "api">;
19
+ }>, AnyAction, undefined>, import("redux").Middleware<{}, import("@reduxjs/toolkit/query").RootState<{}, string, "api">, import("@reduxjs/toolkit").ThunkDispatch<any, any, AnyAction>>]>>;
14
20
  export type AppDispatch = typeof store.dispatch;
15
21
  export type AppStore = typeof store;
22
+ export type AppState = ReturnType<typeof store.getState>;
16
23
  export declare const getAppState: import("@reduxjs/toolkit").AsyncThunk<RootState, {
17
24
  idForm: string;
18
25
  }, {
@@ -25,3 +32,4 @@ export declare const getAppState: import("@reduxjs/toolkit").AsyncThunk<RootStat
25
32
  fulfilledMeta?: unknown;
26
33
  rejectedMeta?: unknown;
27
34
  }>;
35
+ export {};
@@ -45,15 +45,22 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
+ var _a;
48
49
  import { combineReducers, configureStore, createAsyncThunk, } from '@reduxjs/toolkit';
49
50
  import GlobalSlice from '../States/GlobalSlice';
50
51
  import SiteSlice from '../States/SiteSlice';
51
52
  import WidthStatsSlice from '../States/WidthStatsSlice';
53
+ import { RootApi } from './_api';
52
54
  export var defaultRootState = {
53
55
  global: GlobalSlice.getInitialState(),
54
56
  site: SiteSlice.getInitialState(),
55
57
  widthStats: WidthStatsSlice.getInitialState(),
56
58
  };
59
+ var reducer = combineReducers((_a = {
60
+ forms: EurekaFormsReducer
61
+ },
62
+ _a[RootApi.reducerPath] = RootApi.reducer,
63
+ _a));
57
64
  var FormReducer = combineReducers({
58
65
  global: GlobalSlice.reducer,
59
66
  site: SiteSlice.reducer,
@@ -72,13 +79,16 @@ export function EurekaFormsReducer(state, action) {
72
79
  return __assign(__assign({}, state), (_b = {}, _b[idForm] = FormReducer(state[idForm], action), _b));
73
80
  }
74
81
  export var store = configureStore({
75
- reducer: EurekaFormsReducer,
82
+ reducer: reducer,
83
+ middleware: function (getDefaultMiddleware) {
84
+ return getDefaultMiddleware().concat(RootApi.middleware);
85
+ },
76
86
  });
77
87
  export var getAppState = createAsyncThunk('get/state', function (_a, thunkAPI) {
78
88
  var idForm = _a.idForm;
79
89
  return __awaiter(void 0, void 0, void 0, function () {
80
90
  return __generator(this, function (_b) {
81
- return [2 /*return*/, thunkAPI.getState()[idForm]];
91
+ return [2 /*return*/, thunkAPI.getState().forms[idForm]];
82
92
  });
83
93
  });
84
94
  });
package/dist/hooks.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import type { TypedUseSelectorHook } from 'react-redux';
2
2
  import { type RootState, type AppDispatch } from './Utils/store';
3
- import React from 'react';
4
- export declare const StoreContext: React.Context<any>;
5
3
  export declare const useAppDispatch: () => AppDispatch;
6
4
  export declare const useAppSelector: TypedUseSelectorHook<RootState>;
7
5
  export declare const selectBreakPoint: (state: RootState) => number;
package/dist/hooks.js CHANGED
@@ -2,8 +2,7 @@ import { createDispatchHook, createSelectorHook } from 'react-redux';
2
2
  import { defaultRootState, } from './Utils/store';
3
3
  import { useContext } from 'react';
4
4
  import { IdFormContext } from './App/App';
5
- import React from 'react';
6
- export var StoreContext = React.createContext({});
5
+ import { StoreContext } from './Utils/StoreContext';
7
6
  var useSelector = createSelectorHook(StoreContext);
8
7
  var useDispatch = createDispatchHook(StoreContext);
9
8
  // Use throughout your app instead of plain `useDispatch` and `useSelector`
@@ -18,7 +17,7 @@ export var useAppDispatch = function () {
18
17
  };
19
18
  export var useAppSelector = function (selector, options) {
20
19
  var idForm = useContext(IdFormContext);
21
- return useSelector(function (state) { var _a; return selector((_a = state[idForm]) !== null && _a !== void 0 ? _a : defaultRootState); }, options);
20
+ return useSelector(function (state) { var _a; return selector((_a = state.forms[idForm]) !== null && _a !== void 0 ? _a : defaultRootState); }, options);
22
21
  };
23
22
  export var selectBreakPoint = function (state) {
24
23
  return state.widthStats.currentBreakPoint;
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.103",
4
+ "version": "2.0.104",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",