@arquimedes.co/eureka-forms 2.0.103 → 2.0.107
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/@Types/GenericFormSteps.d.ts +1 -0
- package/dist/App/App.d.ts +3 -0
- package/dist/App/App.js +3 -1
- package/dist/App/AppFunctions.d.ts +4 -4
- package/dist/App/AppFunctions.js +21 -3
- package/dist/App/AppHooks.js +3 -2
- package/dist/Contexts/CustomContext.d.ts +3 -0
- package/dist/Form/Form.d.ts +2 -0
- package/dist/Form/FormFunctions.js +2 -0
- package/dist/FormSteps/StepFunctions.d.ts +1 -1
- package/dist/FormSteps/StepFunctions.js +7 -4
- package/dist/FormSteps/TitleStep/MaterialTitleStep/MaterialTitleStep.js +29 -17
- package/dist/Services/DraftService.d.ts +23 -0
- package/dist/Services/DraftService.js +83 -0
- package/dist/Shared/SmartDraftRenderer/FormDecorator.d.ts +13 -0
- package/dist/Shared/SmartDraftRenderer/FormDecorator.js +34 -0
- package/dist/Shared/SmartDraftRenderer/FormDecorator.module.css +30 -0
- package/dist/Shared/SmartDraftRenderer/SmartDraftRenderer.d.ts +12 -0
- package/dist/Shared/SmartDraftRenderer/SmartDraftRenderer.js +66 -0
- package/dist/States/GlobalSlice.d.ts +2 -0
- package/dist/Utils/AxiosAPI.d.ts +11 -0
- package/dist/Utils/AxiosAPI.js +72 -0
- package/dist/Utils/StoreContext.d.ts +2 -0
- package/dist/Utils/StoreContext.js +2 -0
- package/dist/Utils/TestUtils.d.ts +22 -2
- package/dist/Utils/TestUtils.js +11 -4
- package/dist/Utils/_api.d.ts +8 -0
- package/dist/Utils/_api.js +13 -0
- package/dist/Utils/store.d.ts +10 -2
- package/dist/Utils/store.js +12 -2
- package/dist/hooks.d.ts +0 -2
- package/dist/hooks.js +2 -3
- package/package.json +1 -1
package/dist/App/App.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import './App.css';
|
|
|
4
4
|
import { CustomStep, CustomStepProps } from '../FormSteps/CustomStep';
|
|
5
5
|
import { EditorState } from 'draft-js';
|
|
6
6
|
import { CountryCode } from 'libphonenumber-js';
|
|
7
|
+
import { EurekaDraft } from '../@Types/Draft/Draft';
|
|
7
8
|
export interface AppProps {
|
|
8
9
|
/** If the app is currently a widget */
|
|
9
10
|
isWidget?: boolean;
|
|
@@ -49,6 +50,8 @@ export interface AppProps {
|
|
|
49
50
|
customSubmitBtns?: null | ((onSubmit: () => Promise<Record<string, any> | void>, loading: boolean) => JSX.Element);
|
|
50
51
|
/** Function to call on postview to fetch the download url of a file */
|
|
51
52
|
fetchDownloadUrl?: (S3Key: string, fileName: string) => Promise<string>;
|
|
53
|
+
/** Function to call to map entities internally (postview, activities) */
|
|
54
|
+
mapDraftEntities?: (property: string, dependencies: Record<string, any>) => Promise<EurekaDraft>;
|
|
52
55
|
/** Function to call after the confimation dialog has been closed */
|
|
53
56
|
handleConfirmed?: () => void;
|
|
54
57
|
/** Function called to scroll to the top */
|
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 {
|
|
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"]);
|
|
@@ -71,6 +72,7 @@ function App(_a) {
|
|
|
71
72
|
return (_jsx(CustomContext.Provider, __assign({ value: {
|
|
72
73
|
customSteps: customSteps,
|
|
73
74
|
sendLabel: props.sendLabel,
|
|
75
|
+
mapDraftEntities: props.mapDraftEntities,
|
|
74
76
|
fetchDownloadUrl: props.fetchDownloadUrl,
|
|
75
77
|
customStepProps: (_g = props.customStepProps) !== null && _g !== void 0 ? _g : {},
|
|
76
78
|
customClientInfoStep: props.customClientInfoStep,
|
|
@@ -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
|
|
10
|
-
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
|
|
21
|
-
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'>;
|
package/dist/App/AppFunctions.js
CHANGED
|
@@ -182,8 +182,9 @@ export var mapOriginalValue = function (orgInfo, step, value, values, form, path
|
|
|
182
182
|
case FormStepTypes.CLASSIFIER_SELECTOR: return [3 /*break*/, 8];
|
|
183
183
|
case FormStepTypes.ENTITYVALUEPICKER: return [3 /*break*/, 9];
|
|
184
184
|
case FormStepTypes.TEXTINPUT: return [3 /*break*/, 12];
|
|
185
|
+
case FormStepTypes.TITLE: return [3 /*break*/, 13];
|
|
185
186
|
}
|
|
186
|
-
return [3 /*break*/,
|
|
187
|
+
return [3 /*break*/, 14];
|
|
187
188
|
case 1:
|
|
188
189
|
elements = value;
|
|
189
190
|
mappedElements = [];
|
|
@@ -297,7 +298,7 @@ export var mapOriginalValue = function (orgInfo, step, value, values, form, path
|
|
|
297
298
|
classifier = (_h = form.classifiers) === null || _h === void 0 ? void 0 : _h[value];
|
|
298
299
|
return [2 /*return*/, { value: value, label: classifier === null || classifier === void 0 ? void 0 : classifier.name }];
|
|
299
300
|
}
|
|
300
|
-
return [3 /*break*/,
|
|
301
|
+
return [3 /*break*/, 15];
|
|
301
302
|
}
|
|
302
303
|
_o.label = 9;
|
|
303
304
|
case 9:
|
|
@@ -335,13 +336,30 @@ export var mapOriginalValue = function (orgInfo, step, value, values, form, path
|
|
|
335
336
|
}
|
|
336
337
|
_o.label = 13;
|
|
337
338
|
case 13:
|
|
339
|
+
{
|
|
340
|
+
if (value.title) {
|
|
341
|
+
step.title =
|
|
342
|
+
typeof value.title === 'string'
|
|
343
|
+
? stringToDraft(value.title)
|
|
344
|
+
: value.title;
|
|
345
|
+
}
|
|
346
|
+
if (value.description) {
|
|
347
|
+
step.description =
|
|
348
|
+
typeof value.description === 'string'
|
|
349
|
+
? stringToDraft(value.description)
|
|
350
|
+
: value.description;
|
|
351
|
+
}
|
|
352
|
+
return [2 /*return*/, undefined];
|
|
353
|
+
}
|
|
354
|
+
_o.label = 14;
|
|
355
|
+
case 14:
|
|
338
356
|
if (step.type.startsWith('CBR_') &&
|
|
339
357
|
(value === null || value === void 0 ? void 0 : value.id) &&
|
|
340
358
|
typeof value.id === 'number') {
|
|
341
359
|
return [2 /*return*/, __assign(__assign({}, value), { id: value.id.toString() })];
|
|
342
360
|
}
|
|
343
361
|
return [2 /*return*/, value];
|
|
344
|
-
case
|
|
362
|
+
case 15: return [2 /*return*/];
|
|
345
363
|
}
|
|
346
364
|
});
|
|
347
365
|
});
|
package/dist/App/AppHooks.js
CHANGED
|
@@ -155,8 +155,9 @@ export var useSetupApp = function (isEmbedded, _a) {
|
|
|
155
155
|
var _loop_1 = function (section) {
|
|
156
156
|
for (var _b = 0, _c = section.steps; _b < _c.length; _b++) {
|
|
157
157
|
var idStep = _c[_b];
|
|
158
|
-
iterateNestedSteps(idStep, form.steps, function (step) {
|
|
158
|
+
iterateNestedSteps(idStep, form.steps, function (step, path) {
|
|
159
159
|
step.idSection = section.id;
|
|
160
|
+
step.stepPath = path;
|
|
160
161
|
});
|
|
161
162
|
}
|
|
162
163
|
};
|
|
@@ -177,7 +178,7 @@ export var useSetupApp = function (isEmbedded, _a) {
|
|
|
177
178
|
return [4 /*yield*/, calcValuesStore({ idOrganization: idOrganization, countryCode: countryCode }, form, valuesData, postview, customSteps)];
|
|
178
179
|
case 5:
|
|
179
180
|
values = _g.sent();
|
|
180
|
-
dispatch(reset(__assign(__assign({ formStyle: internal
|
|
181
|
+
dispatch(reset(__assign(__assign({ apiKey: apiKey, formStyle: internal
|
|
181
182
|
? InternalFormStyle
|
|
182
183
|
: __assign(__assign({}, InternalFormStyle), ((_d = form === null || form === void 0 ? void 0 : form.style) !== null && _d !== void 0 ? _d : {})), confirmation: {
|
|
183
184
|
confirmationMessage: (_e = form.confirmationMessage) !== null && _e !== void 0 ? _e : BaseConfirmationMessage,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CustomStep, CustomStepProps } from '../FormSteps/CustomStep';
|
|
3
|
+
import { EurekaDraft } from '../@Types/Draft/Draft';
|
|
3
4
|
export interface CustomContextData {
|
|
4
5
|
sendLabel?: string;
|
|
5
6
|
customStepProps: Record<string, unknown>;
|
|
@@ -7,6 +8,8 @@ export interface CustomContextData {
|
|
|
7
8
|
customClientInfoStep?: (props: CustomStepProps) => JSX.Element;
|
|
8
9
|
/** Function to call on postview to fetch the download url of a file */
|
|
9
10
|
fetchDownloadUrl?: (S3Key: string, fileName: string) => Promise<string>;
|
|
11
|
+
/** Function to call to map entities internally (postview, activities) */
|
|
12
|
+
mapDraftEntities?: (property: string, dependencies: Record<string, any>) => Promise<EurekaDraft>;
|
|
10
13
|
}
|
|
11
14
|
declare const CustomContext: import("react").Context<CustomContextData>;
|
|
12
15
|
export default CustomContext;
|
package/dist/Form/Form.d.ts
CHANGED
|
@@ -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.stepPath[0],
|
|
226
228
|
value: calcStepDependencyValue(depStep, originalValue, customSteps),
|
|
227
229
|
dependents: [],
|
|
228
230
|
};
|
|
@@ -9,7 +9,7 @@ export type FillerSteps = FormSelector | ClassifierSelector | EntityValuePicker
|
|
|
9
9
|
export declare function calcFillerSize(step: FillerSteps, steps: Record<string, FormStep>, values: Record<string, unknown>, size: FormSize): number;
|
|
10
10
|
export declare const calcStepWidth: (stepSize: 1 | 2 | 3 | 4, size: FormSize) => number;
|
|
11
11
|
export declare const calcDefaultValue: (step: FormStep | CBRFormStep) => any;
|
|
12
|
-
export declare const iterateNestedSteps: (idStep: string, steps: Record<string, FormStep>, iteration: (step: FormStep) => void) => void;
|
|
12
|
+
export declare const iterateNestedSteps: (idStep: string, steps: Record<string, FormStep>, iteration: (step: FormStep, path: string[]) => void, path?: string[]) => void;
|
|
13
13
|
/**
|
|
14
14
|
* Utility function to calc the substeps of a step
|
|
15
15
|
* @param step step to calc the substeps
|
|
@@ -150,23 +150,26 @@ export var calcDefaultValue = function (step) {
|
|
|
150
150
|
return undefined;
|
|
151
151
|
}
|
|
152
152
|
};
|
|
153
|
-
export var iterateNestedSteps = function (idStep, steps, iteration) {
|
|
153
|
+
export var iterateNestedSteps = function (idStep, steps, iteration, path) {
|
|
154
|
+
if (path === void 0) { path = [idStep]; }
|
|
154
155
|
var step = steps[idStep];
|
|
155
156
|
if (!step) {
|
|
156
157
|
console.error('Missing Step:', idStep);
|
|
157
158
|
return;
|
|
158
159
|
}
|
|
159
|
-
iteration(step);
|
|
160
|
+
iteration(step, path);
|
|
160
161
|
if (step.type === FormStepTypes.MAPPER) {
|
|
161
162
|
for (var _i = 0, _a = step.rootSteps; _i < _a.length; _i++) {
|
|
162
163
|
var idStep_1 = _a[_i];
|
|
163
|
-
iterateNestedSteps(idStep_1, step.steps, iteration)
|
|
164
|
+
iterateNestedSteps(idStep_1, step.steps, iteration, __spreadArray(__spreadArray([], path, true), [
|
|
165
|
+
step.id,
|
|
166
|
+
], false));
|
|
164
167
|
}
|
|
165
168
|
}
|
|
166
169
|
else {
|
|
167
170
|
for (var _b = 0, _c = calcSubSteps(step.id, steps); _b < _c.length; _b++) {
|
|
168
171
|
var idSubStep = _c[_b];
|
|
169
|
-
iterateNestedSteps(idSubStep, steps, iteration);
|
|
172
|
+
iterateNestedSteps(idSubStep, steps, iteration, __spreadArray(__spreadArray([], path, true), [step.id], false));
|
|
170
173
|
}
|
|
171
174
|
}
|
|
172
175
|
};
|
|
@@ -14,39 +14,51 @@ 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';
|
|
20
19
|
import { stringToDraft } from '../../../Utils/DraftFunctions';
|
|
21
|
-
import
|
|
20
|
+
import SmartDraftRenderer from '../../../Shared/SmartDraftRenderer/SmartDraftRenderer';
|
|
21
|
+
//**Pendientes a mejorar, esperar antes de enviar, en local (actividades), usar el value envez de el draft en actividades, esperar a que dejen de escribir, optimizar para que use lo que tiene en local y si necesita ahi si pregunte. */
|
|
22
22
|
function TitleStep(_a) {
|
|
23
|
-
var _b
|
|
23
|
+
var _b;
|
|
24
24
|
var step = _a.step;
|
|
25
|
-
var
|
|
25
|
+
var _c = useFormStep(step, {
|
|
26
26
|
defaultValue: undefined,
|
|
27
|
-
}).value;
|
|
27
|
+
}), value = _c.value, onChange = _c.onChange;
|
|
28
28
|
var formStyle = useAppSelector(function (state) { return state.global; }).formStyle;
|
|
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 =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
var title = useMemo(function () { return calcBaseDraft(step.title); }, [step.title]);
|
|
33
|
+
var description = useMemo(function () { return calcBaseDraft(step.description); }, [step.description]);
|
|
34
|
+
var dependencies = useAppSelector(function (state) {
|
|
35
|
+
return selectDependencies(state, step.dependencies);
|
|
36
|
+
});
|
|
37
|
+
var values = useMemo(function () {
|
|
38
|
+
var values = {};
|
|
39
|
+
for (var _i = 0, _a = Object.values(dependencies); _i < _a.length; _i++) {
|
|
40
|
+
var _b = _a[_i], idOriginal = _b.idOriginal, value_1 = _b.value;
|
|
41
|
+
values[idOriginal] = value_1;
|
|
42
|
+
}
|
|
43
|
+
return values;
|
|
44
|
+
}, [dependencies]);
|
|
38
45
|
return (_jsxs("div", __assign({ className: styles.container, style: {
|
|
39
46
|
color: formStyle.textColor,
|
|
40
47
|
width: widthStats.currentBreakPoint <= size
|
|
41
48
|
? '100%'
|
|
42
49
|
: calcStepWidth(size, form.size),
|
|
43
|
-
} }, { children: [
|
|
50
|
+
} }, { children: [_jsx("div", __assign({ className: styles.titleLbl, style: {
|
|
44
51
|
textAlign: widthStats.isMobile &&
|
|
45
52
|
widthStats.currentBreakPoint <= size
|
|
46
53
|
? 'center'
|
|
47
54
|
: 'start',
|
|
48
|
-
} }, { children: _jsx(
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
} }, { children: _jsx(SmartDraftRenderer, { draft: title, dependencies: values, property: "".concat(step.stepPath.join('.'), ".title"), onChange: function (title) { return onChange(__assign(__assign({}, value), { title: title })); } }) })), _jsx("div", __assign({ className: styles.descriptionPar }, { children: _jsx(SmartDraftRenderer, { draft: description, dependencies: values, margin: title ? '10px 0px' : '0px 0px 5px 0px', property: "".concat(step.stepPath.join('.'), ".description"), onChange: function (description) {
|
|
56
|
+
return onChange(__assign(__assign({}, value), { description: description }));
|
|
57
|
+
} }) }))] })));
|
|
51
58
|
}
|
|
52
59
|
export default TitleStep;
|
|
60
|
+
function calcBaseDraft(value) {
|
|
61
|
+
return typeof value === 'string'
|
|
62
|
+
? stringToDraft(value)
|
|
63
|
+
: value !== null && value !== void 0 ? value : stringToDraft('');
|
|
64
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
property: string;
|
|
13
|
+
dependencies: Record<string, any>;
|
|
14
|
+
mapDraftEntities?: ((property: string, dependencies: Record<string, any>) => Promise<EurekaDraft>) | undefined;
|
|
15
|
+
}, import("@reduxjs/toolkit/query").BaseQueryFn<{
|
|
16
|
+
url: string;
|
|
17
|
+
timeout?: number | undefined;
|
|
18
|
+
method?: string | undefined;
|
|
19
|
+
body?: any;
|
|
20
|
+
params?: any;
|
|
21
|
+
headers?: Record<string, any> | undefined;
|
|
22
|
+
}, unknown, unknown, {}, {}>, never, EurekaDraft | undefined, "api">;
|
|
23
|
+
}, "api", never, typeof import("@reduxjs/toolkit/query").coreModuleName | typeof import("@reduxjs/toolkit/dist/query/react").reactHooksModuleName>;
|
|
@@ -0,0 +1,83 @@
|
|
|
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, property = _a.property, mapDraftEntities = _a.mapDraftEntities;
|
|
45
|
+
var getState = _b.getState;
|
|
46
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
+
var idOrganization, apiKey, response;
|
|
48
|
+
var _c;
|
|
49
|
+
return __generator(this, function (_d) {
|
|
50
|
+
switch (_d.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
idOrganization = getState().forms[idForm]
|
|
53
|
+
.global.idOrganization;
|
|
54
|
+
if (!mapDraftEntities) return [3 /*break*/, 2];
|
|
55
|
+
_c = {};
|
|
56
|
+
return [4 /*yield*/, mapDraftEntities(property, dependencies)];
|
|
57
|
+
case 1: return [2 /*return*/, (_c.data = _d.sent(),
|
|
58
|
+
_c)];
|
|
59
|
+
case 2:
|
|
60
|
+
apiKey = getState().forms[idForm].global
|
|
61
|
+
.apiKey;
|
|
62
|
+
if (!apiKey)
|
|
63
|
+
return [2 /*return*/, { data: undefined }];
|
|
64
|
+
if (!idOrganization) return [3 /*break*/, 4];
|
|
65
|
+
return [4 /*yield*/, widgetInstance.post("/form/draft/".concat(apiKey, "?idOrganization=").concat(idOrganization), {
|
|
66
|
+
property: property,
|
|
67
|
+
dependencies: dependencies,
|
|
68
|
+
})];
|
|
69
|
+
case 3:
|
|
70
|
+
response = _d.sent();
|
|
71
|
+
return [3 /*break*/, 6];
|
|
72
|
+
case 4: return [4 /*yield*/, axiosInstance.post("/form/draft/".concat(apiKey), dependencies)];
|
|
73
|
+
case 5:
|
|
74
|
+
response = _d.sent();
|
|
75
|
+
_d.label = 6;
|
|
76
|
+
case 6: return [2 /*return*/, { data: response.data }];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
}),
|
|
82
|
+
}); },
|
|
83
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ContentState } from 'draft-js';
|
|
3
|
+
export interface DecoratorComponentProps {
|
|
4
|
+
children: JSX.Element;
|
|
5
|
+
contentState: ContentState;
|
|
6
|
+
entityKey: string;
|
|
7
|
+
blockKey: string;
|
|
8
|
+
start: number;
|
|
9
|
+
end: number;
|
|
10
|
+
editable?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function FormDecorator({ children, entityKey, }: DecoratorComponentProps): JSX.Element;
|
|
13
|
+
export declare function FormDecoratorsStrategy(contentBlock: any, callback: any, contentState: any): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { useContext } from 'react';
|
|
14
|
+
import { DraftEntityTypes } from '../../constants/Draft/DraftEntityTypes';
|
|
15
|
+
import { DraftLoadingContext } from './SmartDraftRenderer';
|
|
16
|
+
import styles from './FormDecorator.module.css';
|
|
17
|
+
export function FormDecorator(_a) {
|
|
18
|
+
var children = _a.children, entityKey = _a.entityKey;
|
|
19
|
+
var loading = useContext(DraftLoadingContext);
|
|
20
|
+
return (_jsx("span", __assign({ id: entityKey, className: loading ? styles.loadingDecorator : styles.decorator, style: {
|
|
21
|
+
overflow: 'hidden',
|
|
22
|
+
position: 'relative',
|
|
23
|
+
padding: '0px 3px',
|
|
24
|
+
borderRadius: 12,
|
|
25
|
+
} }, { children: children })));
|
|
26
|
+
}
|
|
27
|
+
export function FormDecoratorsStrategy(contentBlock, callback, contentState) {
|
|
28
|
+
contentBlock.findEntityRanges(function (character) {
|
|
29
|
+
var entityKey = character.getEntity();
|
|
30
|
+
return (entityKey !== null &&
|
|
31
|
+
contentState.getEntity(entityKey).getType() ===
|
|
32
|
+
DraftEntityTypes.EUREKA);
|
|
33
|
+
}, callback);
|
|
34
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
.loadingDecorator {
|
|
2
|
+
position: absolute;
|
|
3
|
+
animation-duration: 3s;
|
|
4
|
+
animation-fill-mode: forwards;
|
|
5
|
+
animation-iteration-count: infinite;
|
|
6
|
+
animation-name: loading;
|
|
7
|
+
animation-timing-function: linear;
|
|
8
|
+
background: linear-gradient(
|
|
9
|
+
to right,
|
|
10
|
+
#d6d6d6 2%,
|
|
11
|
+
rgba(255, 255, 255, 0.3) 20%,
|
|
12
|
+
#d6d6d6 50%
|
|
13
|
+
);
|
|
14
|
+
background-size: 800px 100px;
|
|
15
|
+
height: 100%;
|
|
16
|
+
width: 100%;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.decorator {
|
|
20
|
+
background-color: #d6d6d6;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@keyframes loading {
|
|
24
|
+
0% {
|
|
25
|
+
background-position: -800px 0;
|
|
26
|
+
}
|
|
27
|
+
100% {
|
|
28
|
+
background-position: 800px 0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { EurekaDraft } from '../../@Types/Draft/Draft';
|
|
3
|
+
export declare const DraftLoadingContext: React.Context<boolean>;
|
|
4
|
+
interface SmartDraftRendererProps {
|
|
5
|
+
property: string;
|
|
6
|
+
draft: EurekaDraft;
|
|
7
|
+
margin?: React.CSSProperties['margin'];
|
|
8
|
+
dependencies: Record<string, any>;
|
|
9
|
+
onChange?: (value: EurekaDraft) => void;
|
|
10
|
+
}
|
|
11
|
+
declare function SmartDraftRenderer({ draft, margin, onChange, property, dependencies, }: SmartDraftRendererProps): JSX.Element;
|
|
12
|
+
export default SmartDraftRenderer;
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { createContext, useContext, useEffect, useMemo } from 'react';
|
|
14
|
+
import { IdFormContext } from '../../App/App';
|
|
15
|
+
import { DraftApi } from '../../Services/DraftService';
|
|
16
|
+
import { convertFromRaw, EditorState } from 'draft-js';
|
|
17
|
+
import { Editor } from 'react-draft-wysiwyg';
|
|
18
|
+
import { produce } from 'immer';
|
|
19
|
+
import CustomContext from '../../Contexts/CustomContext';
|
|
20
|
+
import { FormDecoratorsStrategy, FormDecorator } from './FormDecorator';
|
|
21
|
+
import { skipToken } from '@reduxjs/toolkit/query';
|
|
22
|
+
import { useAppSelector } from '../../hooks';
|
|
23
|
+
export var DraftLoadingContext = createContext(true);
|
|
24
|
+
function SmartDraftRenderer(_a) {
|
|
25
|
+
var draft = _a.draft, margin = _a.margin, onChange = _a.onChange, property = _a.property, dependencies = _a.dependencies;
|
|
26
|
+
var idForm = useContext(IdFormContext);
|
|
27
|
+
var mapDraftEntities = useContext(CustomContext).mapDraftEntities;
|
|
28
|
+
var postview = useAppSelector(function (state) { return state.global.postview; });
|
|
29
|
+
var hasEntities = useMemo(function () { return Object.keys(draft.entityMap).length > 0; }, [draft]);
|
|
30
|
+
var _b = DraftApi.useMapDraftQuery(!hasEntities || postview
|
|
31
|
+
? skipToken
|
|
32
|
+
: {
|
|
33
|
+
idForm: idForm,
|
|
34
|
+
property: property,
|
|
35
|
+
dependencies: dependencies,
|
|
36
|
+
mapDraftEntities: mapDraftEntities,
|
|
37
|
+
}), mapped = _b.data, isFetching = _b.isFetching;
|
|
38
|
+
useEffect(function () {
|
|
39
|
+
if (mapped && !postview)
|
|
40
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(mapped);
|
|
41
|
+
}, [mapped]);
|
|
42
|
+
var editorState = useMemo(function () {
|
|
43
|
+
return EditorState.createWithContent(convertFromRaw(cleanUpDraftParams(isFetching ? draft : mapped !== null && mapped !== void 0 ? mapped : draft)));
|
|
44
|
+
}, [mapped, draft, isFetching]);
|
|
45
|
+
return (_jsx("div", __assign({ style: { margin: margin } }, { children: _jsx(DraftLoadingContext.Provider, __assign({ value: !postview && isFetching }, { children: _jsx(Editor, { readOnly: true, toolbarHidden: true, editorState: editorState, editorClassName: 'Erk-Forms-Draft', customDecorators: customDecorators }) })) })));
|
|
46
|
+
}
|
|
47
|
+
export default SmartDraftRenderer;
|
|
48
|
+
function cleanUpDraftParams(draft) {
|
|
49
|
+
return produce(draft, function (draft) {
|
|
50
|
+
for (var _i = 0, _a = draft.blocks; _i < _a.length; _i++) {
|
|
51
|
+
var block = _a[_i];
|
|
52
|
+
for (var _b = 0, _c = block.entityRanges; _b < _c.length; _b++) {
|
|
53
|
+
var entity = _c[_b];
|
|
54
|
+
var offset = entity.offset, length_1 = entity.length;
|
|
55
|
+
//Change text into spaces
|
|
56
|
+
block.text = block.text.replace(block.text.substring(offset, offset + length_1), ' '.repeat(length_1));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
var customDecorators = [
|
|
62
|
+
{
|
|
63
|
+
strategy: FormDecoratorsStrategy,
|
|
64
|
+
component: FormDecorator,
|
|
65
|
+
},
|
|
66
|
+
];
|
|
@@ -4,6 +4,7 @@ import { SiteState } from './SiteSlice';
|
|
|
4
4
|
import { EurekaDraft } from '../@Types/Draft/Draft';
|
|
5
5
|
import { CountryCode } from 'libphonenumber-js';
|
|
6
6
|
export interface GlobalState {
|
|
7
|
+
apiKey?: string;
|
|
7
8
|
idOrganization: string;
|
|
8
9
|
idCurrentAgent?: string;
|
|
9
10
|
countryCode: CountryCode;
|
|
@@ -30,6 +31,7 @@ export declare const GlobalSlice: import("@reduxjs/toolkit").Slice<GlobalState,
|
|
|
30
31
|
preview: boolean;
|
|
31
32
|
idOrganization: string;
|
|
32
33
|
idCurrentAgent?: string | undefined;
|
|
34
|
+
apiKey?: string | undefined;
|
|
33
35
|
countryCode: CountryCode;
|
|
34
36
|
confirmation: {
|
|
35
37
|
confirmationMessage: EurekaDraft;
|
package/dist/Utils/AxiosAPI.d.ts
CHANGED
|
@@ -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>;
|
package/dist/Utils/AxiosAPI.js
CHANGED
|
@@ -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
|
+
};
|
|
@@ -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("
|
|
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("
|
|
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 {};
|
package/dist/Utils/TestUtils.js
CHANGED
|
@@ -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 {
|
|
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:
|
|
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:
|
|
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
|
+
});
|
package/dist/Utils/store.d.ts
CHANGED
|
@@ -8,11 +8,18 @@ export interface RootState {
|
|
|
8
8
|
widthStats: WidthStats;
|
|
9
9
|
}
|
|
10
10
|
export declare const defaultRootState: RootState;
|
|
11
|
-
|
|
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<
|
|
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 {};
|
package/dist/Utils/store.js
CHANGED
|
@@ -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:
|
|
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
|
|
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