@arquimedes.co/eureka-forms 2.0.54 → 2.0.56

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.
Files changed (58) hide show
  1. package/dist/@Types/Condition.d.ts +54 -2
  2. package/dist/@Types/Draft/Draft.d.ts +12 -0
  3. package/dist/@Types/Draft/Draft.js +1 -0
  4. package/dist/@Types/Draft/DraftEntityData.d.ts +50 -0
  5. package/dist/@Types/Draft/DraftEntityData.js +1 -0
  6. package/dist/@Types/Entity.d.ts +33 -0
  7. package/dist/@Types/Entity.js +1 -0
  8. package/dist/@Types/Form.d.ts +7 -0
  9. package/dist/@Types/FormStep.d.ts +7 -0
  10. package/dist/App/App.css +14 -0
  11. package/dist/App/AppFunctions.d.ts +2 -2
  12. package/dist/App/AppFunctions.js +167 -156
  13. package/dist/App/AppHooks.js +12 -8
  14. package/dist/Contexts/FormContext.d.ts +2 -0
  15. package/dist/Contexts/FormContext.js +49 -0
  16. package/dist/Form/ConfirmationDialog/ConfirmationDialog.js +30 -5
  17. package/dist/Form/ConfirmationDialog/ConfirmationDialog.module.css +5 -3
  18. package/dist/Form/Form.js +1 -1
  19. package/dist/Form/FormFunctions.js +15 -12
  20. package/dist/Form/FormTypes/StepperForm/StepperForm.js +10 -7
  21. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValueDialog/MaterialEntityValueDialog.d.ts +12 -0
  22. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValueDialog/MaterialEntityValueDialog.js +49 -0
  23. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValueDialog/MaterialEntityValueDialog.module.css +60 -0
  24. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +103 -49
  25. package/dist/FormSteps/MapperStep/MaterialMapperStep/Element/MapperElementComponent.d.ts +3 -0
  26. package/dist/FormSteps/MapperStep/MaterialMapperStep/Element/MapperElementComponent.js +3 -0
  27. package/dist/FormSteps/MapperStep/MaterialMapperStep/Element/PagedMapperElement/PagedMapperElement.d.ts +5 -0
  28. package/dist/FormSteps/MapperStep/MaterialMapperStep/Element/PagedMapperElement/PagedMapperElement.js +204 -0
  29. package/dist/FormSteps/MapperStep/MaterialMapperStep/Element/PagedMapperElement/PagedMapperElement.module.css +75 -0
  30. package/dist/FormSteps/MapperStep/MaterialMapperStep/MaterialMapperStep.d.ts +6 -2
  31. package/dist/FormSteps/MapperStep/MaterialMapperStep/MaterialMapperStep.js +44 -14
  32. package/dist/FormSteps/StepFunctions.d.ts +11 -1
  33. package/dist/FormSteps/StepFunctions.js +146 -1
  34. package/dist/FormSteps/StepHooks.js +12 -4
  35. package/dist/Shared/CustomBtn/CustomBtn.d.ts +7 -2
  36. package/dist/Shared/CustomBtn/CustomBtn.js +14 -5
  37. package/dist/Shared/CustomBtn/CustomBtn.module.css +0 -2
  38. package/dist/States/GlobalSlice.d.ts +9 -0
  39. package/dist/States/GlobalSlice.js +5 -0
  40. package/dist/States/SiteSlice.d.ts +32 -3
  41. package/dist/States/SiteSlice.js +50 -5
  42. package/dist/Utils/DraftFunctions.d.ts +21 -0
  43. package/dist/Utils/DraftFunctions.js +239 -0
  44. package/dist/constants/ConditionTypes.d.ts +6 -1
  45. package/dist/constants/ConditionTypes.js +5 -0
  46. package/dist/constants/Draft/DraftEntityDataTypes.d.ts +10 -0
  47. package/dist/constants/Draft/DraftEntityDataTypes.js +12 -0
  48. package/dist/constants/Draft/DraftEntityTypes.d.ts +3 -0
  49. package/dist/constants/Draft/DraftEntityTypes.js +4 -0
  50. package/dist/constants/Draft/DraftStyleTypes.d.ts +7 -0
  51. package/dist/constants/Draft/DraftStyleTypes.js +8 -0
  52. package/dist/constants/EntityPropertyTypes.d.ts +9 -0
  53. package/dist/constants/EntityPropertyTypes.js +10 -0
  54. package/dist/constants/FormStepTypes.d.ts +1 -0
  55. package/dist/constants/FormStepTypes.js +1 -0
  56. package/dist/constants/TicketPropertyTypes.d.ts +3 -0
  57. package/dist/constants/TicketPropertyTypes.js +4 -0
  58. package/package.json +2 -2
@@ -1,9 +1,10 @@
1
1
  import ConditionTypes, { ExpressionTypes, OperatorTypes } from '../constants/ConditionTypes';
2
+ import EntityPropertyTypes from '../constants/EntityPropertyTypes';
2
3
  import FormStepTypes from '../constants/FormStepTypes';
3
- export type Condition = ExpressionCondition | FormStepCondition;
4
+ export type Condition = ExpressionCondition | FormStepCondition | EntityValueCondition;
4
5
  export interface ExpressionCondition<Type extends Condition = Condition> {
5
6
  type: ConditionTypes.EXPRESSION;
6
- conditions: (Type | ExpressionCondition<Type>)[];
7
+ conditions: (Type | ExpressionCondition)[];
7
8
  expression: ExpressionTypes;
8
9
  }
9
10
  export type FormStepCondition = ExistanceFormStepCondition | CheckBoxFormStepCondition | ClassifierSelectorFormStepCondition | DatePickerFormStepCondition | EntityValuePickerFormStepCondition | RatingFormStepCondition | SelectorFormStepCondition | TextAreaFormStepCondition | TextInputFormStepCondition;
@@ -57,4 +58,55 @@ export interface TextInputFormStepCondition extends BaseFormStepCondition {
57
58
  operator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL | OperatorTypes.INCLUDES | OperatorTypes.NOTINCLUDES;
58
59
  value: string;
59
60
  }
61
+ export type EntityValueCondition = EntityEqualsCondition | EntityPropertyCondition;
62
+ export type EntityPropertyCondition = EntityPropertyExistsCondition | EntitySelectorCondition | EntityTextInputCondition | EntityTextAreaCondition | EntityCheckboxCondition | EntityDateCondition | EntityRelativeDateCondition;
63
+ export interface EntityEqualsCondition {
64
+ type: ConditionTypes.ENTITYVALUE;
65
+ idEntity: string;
66
+ operator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL;
67
+ values: string[];
68
+ }
69
+ export interface EntityPropertyConditionBase {
70
+ type: ConditionTypes.ENTITYVALUE;
71
+ idEntity: string;
72
+ operator: OperatorTypes.INCLUDES | OperatorTypes.NOTINCLUDES;
73
+ idProperty: string;
74
+ }
75
+ export interface EntityPropertyExistsCondition extends EntityPropertyConditionBase {
76
+ propertyType: EntityPropertyTypes;
77
+ propertyOperator: OperatorTypes.EXISTS | OperatorTypes.NOTEXISTS;
78
+ }
79
+ export interface EntitySelectorCondition extends EntityPropertyConditionBase {
80
+ propertyType: EntityPropertyTypes.SELECTOR;
81
+ propertyOperator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL;
82
+ propertyValue: string;
83
+ }
84
+ export interface EntityTextInputCondition extends EntityPropertyConditionBase {
85
+ propertyType: EntityPropertyTypes.TEXTINPUT | EntityPropertyTypes.NAME;
86
+ propertyOperator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL;
87
+ propertyValue: string;
88
+ }
89
+ export interface EntityTextAreaCondition extends EntityPropertyConditionBase {
90
+ propertyType: EntityPropertyTypes.TEXTAREA;
91
+ propertyOperator: OperatorTypes.INCLUDES | OperatorTypes.NOTINCLUDES;
92
+ propertyValues: string[];
93
+ }
94
+ export interface EntityCheckboxCondition extends EntityPropertyConditionBase {
95
+ propertyType: EntityPropertyTypes.CHECKBOX;
96
+ propertyOperator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL;
97
+ propertyValue: boolean;
98
+ }
99
+ export interface EntityDateCondition extends EntityPropertyConditionBase {
100
+ propertyType: EntityPropertyTypes.DATEPICKER;
101
+ propertyOperator: OperatorTypes.EQUAL | OperatorTypes.NOTEQUAL | OperatorTypes.LESS | OperatorTypes.MORE;
102
+ propertyValue: Date;
103
+ }
104
+ export interface EntityRelativeDateCondition extends EntityPropertyConditionBase {
105
+ propertyType: EntityPropertyTypes.DATEPICKER;
106
+ propertyOperator: OperatorTypes.PAST_RELATIVE_LESS | OperatorTypes.PAST_RELATIVE_MORE | OperatorTypes.FUTURE_RELATIVE_LESS | OperatorTypes.FUTURE_RELATIVE_MORE;
107
+ days: number;
108
+ hours: number;
109
+ minutes: number;
110
+ working: boolean;
111
+ }
60
112
  export {};
@@ -0,0 +1,12 @@
1
+ import { RawDraftContentState } from 'draft-js';
2
+ import { DraftEntityTypes } from '../../constants/Draft/DraftEntityTypes';
3
+ import { DraftEntityData } from './DraftEntityData';
4
+ export interface EurekaDraft extends Omit<RawDraftContentState, 'entityMap'> {
5
+ entityMap: DraftEntityMap;
6
+ }
7
+ export type DraftEntityMap = Record<string, EurekaDraftEntity>;
8
+ export interface EurekaDraftEntity {
9
+ type: DraftEntityTypes.EUREKA;
10
+ mutability: 'IMMUTABLE';
11
+ data: DraftEntityData;
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ import { RawDraftContentBlock } from 'draft-js';
2
+ import { DraftEntityDataTypes, DraftEntityDataMappingTypes } from '../../constants/Draft/DraftEntityDataTypes';
3
+ import { DraftEntityMap } from './Draft';
4
+ import { Condition } from '../Condition';
5
+ import { TicketPropertyTypes } from '../../constants/TicketPropertyTypes';
6
+ export type DraftEntityData = CompanyDraftEntityData | ConditionMetDraftEntityData | DateDraftEntityData | TicketDraftEntityData | MappableDraftEntityData;
7
+ export interface BaseDraftEntityData {
8
+ type: DraftEntityDataTypes | DraftEntityDataMappingTypes;
9
+ prefix?: string;
10
+ suffix?: string;
11
+ fallback?: string;
12
+ condition?: Condition;
13
+ }
14
+ interface CompanyDraftEntityData extends BaseDraftEntityData {
15
+ type: DraftEntityDataTypes.COMPANY;
16
+ idProperty: string;
17
+ }
18
+ interface ConditionMetDraftEntityData extends BaseDraftEntityData {
19
+ type: DraftEntityDataTypes.CONDITION_MET;
20
+ condition: Condition;
21
+ ifTrue?: string;
22
+ ifFalse?: string;
23
+ }
24
+ export interface DateDraftEntityData extends BaseDraftEntityData {
25
+ type: DraftEntityDataTypes.DATE;
26
+ days: number;
27
+ hours: number;
28
+ minutes: number;
29
+ working: boolean;
30
+ /** date-fns formats */
31
+ format?: string;
32
+ }
33
+ export interface TicketDraftEntityData extends BaseDraftEntityData {
34
+ type: DraftEntityDataTypes.TICKET;
35
+ property: TicketPropertyTypes.CASENUMBER;
36
+ }
37
+ export type MappableDraftEntityData = NestedDraftEntityData | EntityValueMappingDraftEntityData;
38
+ export interface BaseMappableDraftEntityData extends BaseDraftEntityData {
39
+ block: RawDraftContentBlock;
40
+ entityMap: DraftEntityMap;
41
+ }
42
+ export interface NestedDraftEntityData extends BaseMappableDraftEntityData {
43
+ type: DraftEntityDataTypes.NESTED;
44
+ }
45
+ export interface EntityValueMappingDraftEntityData extends BaseDraftEntityData {
46
+ type: DraftEntityDataMappingTypes.ENTITYVALUE_MAPPING;
47
+ idEntity: string;
48
+ idProperty: string;
49
+ }
50
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ import EntityPropertyTypes from '../constants/EntityPropertyTypes';
2
+ import { FormSelector } from './FormStep';
3
+ import * as GSteps from './GenericFormSteps';
4
+ export interface Entity {
5
+ _id: string;
6
+ name: string;
7
+ steps: Record<string, EntityProperty>;
8
+ rootSteps: string[];
9
+ }
10
+ export type EntityProperty = Name | CheckBox | TextArea | TextInput | EntitySelector | DatePicker;
11
+ interface BaseProperty {
12
+ required: boolean;
13
+ }
14
+ export interface Name extends Omit<GSteps.GTitle, 'title'>, BaseProperty {
15
+ type: EntityPropertyTypes.NAME;
16
+ label: string;
17
+ }
18
+ export interface CheckBox extends GSteps.GCheckBox, BaseProperty {
19
+ type: EntityPropertyTypes.CHECKBOX;
20
+ }
21
+ export interface TextArea extends GSteps.GTextArea, BaseProperty {
22
+ type: EntityPropertyTypes.TEXTAREA;
23
+ }
24
+ export interface TextInput extends GSteps.GTextInput, BaseProperty {
25
+ type: EntityPropertyTypes.TEXTINPUT;
26
+ }
27
+ export interface DatePicker extends GSteps.GDatePicker, BaseProperty {
28
+ type: EntityPropertyTypes.DATEPICKER;
29
+ }
30
+ export interface EntitySelector extends Omit<FormSelector, 'type'>, BaseProperty {
31
+ type: EntityPropertyTypes.SELECTOR;
32
+ }
33
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,8 @@
1
1
  import { FormStyleTypes, FormTypes } from '../constants/FormStepTypes';
2
2
  import { Branding } from './Branding';
3
3
  import { FormStep } from './FormStep';
4
+ import { Entity } from './Entity';
5
+ import { EurekaDraft } from './Draft/Draft';
4
6
  export interface Form {
5
7
  apiKey?: string;
6
8
  name?: string;
@@ -14,8 +16,13 @@ export interface Form {
14
16
  style?: FormStyle;
15
17
  branding?: Branding;
16
18
  classifiers?: Record<string, Classifier>;
19
+ entities?: Record<string, Entity>;
17
20
  terms?: Term[];
18
21
  hiddenSteps?: string[];
22
+ confirmationMessage?: EurekaDraft;
23
+ showLink?: boolean;
24
+ nextSectionLabel?: string;
25
+ prevSectionLabel?: string;
19
26
  }
20
27
  export interface FormSize {
21
28
  blockNum: 1 | 2 | 3 | 4;
@@ -1,5 +1,6 @@
1
1
  import Types, { ClassifierOptionTypes, OptionTypes, RatingTypes, MapperStyleTypes, EntityValueOptionTypes, EntityValueDataTypes, ApiSelectorOptionTypes, ApiSelectorParamTypes } from '../constants/FormStepTypes';
2
2
  import { Condition } from './Condition';
3
+ import { EurekaDraft } from './Draft/Draft';
3
4
  import * as GSteps from './GenericFormSteps';
4
5
  export type FormStep = Title | Rating | CheckBox | TextArea | TextInput | DatePicker | FileUpload | Separator | FormSelector | ClassifierSelector | Collapsible | EntityValuePicker | ApiSelector | Mapper;
5
6
  export interface Title extends GSteps.GBaseStep {
@@ -107,8 +108,14 @@ export interface EntityValuePicker extends GSteps.GSmartSelect {
107
108
  path: EntityValuePickerPath[];
108
109
  options: Record<string, FormEntityValuePickerOption>;
109
110
  maxSize?: number;
111
+ dialogs?: EntityValuePickerDialog[];
110
112
  }
111
113
  export type FormEntityValuePickerOption = DefaultEntityValuePickerOption | NestedEntityValuePickerOption | HideFormEntityValuePickerOption;
114
+ export interface EntityValuePickerDialog {
115
+ type: 'WARNING' | 'INFO';
116
+ message: EurekaDraft;
117
+ condition?: Condition;
118
+ }
112
119
  interface DefaultEntityValuePickerOption {
113
120
  type: EntityValueOptionTypes.DEFAULT;
114
121
  idEntityValue: string;
package/dist/App/App.css CHANGED
@@ -4,3 +4,17 @@
4
4
  padding: 0;
5
5
  border-width: 0;
6
6
  }
7
+
8
+ .Erk-Forms-Confirmation {
9
+ text-align: center;
10
+ pointer-events: none;
11
+ }
12
+
13
+ .Erk-Forms-Confirmation {
14
+ .public-DraftStyleDefault-block {
15
+ margin: 0;
16
+ }
17
+ div {
18
+ text-align: center;
19
+ }
20
+ }
@@ -5,7 +5,7 @@ import { CustomStep } from '../FormSteps/CustomStep';
5
5
  import { MapperElement } from '../@Types/MapperElement';
6
6
  import { Condition } from '../@Types/Condition';
7
7
  export declare const calcValuesStore: (idOrganization: string, form: Readonly<Form>, originalValues?: Record<string, any>, postview?: boolean, customSteps?: Record<string, CustomStep>) => Promise<ValuesStore>;
8
- export declare const addMapperStep: <Type>(step: Mapper, customSteps: Record<string, CustomStep>) => {
8
+ export declare const addMapperStep: <Type>(step: Mapper, customSteps: Record<string, CustomStep>, path?: string) => {
9
9
  element: MapperElement<Type>;
10
10
  /** Record of all the new mapper values created */
11
11
  mappers: Record<string, MapperElement<Type>[]>;
@@ -14,5 +14,5 @@ export declare const addMapperStep: <Type>(step: Mapper, customSteps: Record<str
14
14
  };
15
15
  export declare function calcRecursiveData<Type>(element: Readonly<MapperElement<Type>>, newSteps: Record<string, FormStep>, customSteps: Record<string, CustomStep>): void;
16
16
  export declare const calcRecursiveCondition: (condition: Condition, ids: Record<string, string>) => void;
17
- export declare const mapOriginalValue: (idOrganization: string, step: FormStep, value: any, values: ValuesStore, form?: Readonly<Form>) => Promise<any>;
17
+ export declare const mapOriginalValue: (idOrganization: string, step: FormStep, value: any, values: ValuesStore, form?: Readonly<Form>, path?: string) => Promise<any>;
18
18
  export declare const calcInitialSections: (form: Form) => Pick<SiteState, 'previousSections' | 'idCurrentSection' | 'nextSections'>;
@@ -82,14 +82,19 @@ export var calcValuesStore = function (idOrganization, form, originalValues, pos
82
82
  switch (_b.label) {
83
83
  case 0:
84
84
  step = form.steps[idValue];
85
- if (!(step && !((_a = form.hiddenSteps) === null || _a === void 0 ? void 0 : _a.includes(step.id)))) return [3 /*break*/, 2];
85
+ if (!step) return [3 /*break*/, 2];
86
86
  return [4 /*yield*/, mapOriginalValue(idOrganization, step, originalValues[step.id], values, form)];
87
87
  case 1:
88
88
  value = _b.sent();
89
89
  if (value !== undefined) {
90
- if (!values.sections[step.idSection])
91
- values.sections[step.idSection] = {};
92
- values.sections[step.idSection][step.id] = value;
90
+ if (!((_a = form.hiddenSteps) === null || _a === void 0 ? void 0 : _a.includes(step.id))) {
91
+ if (!values.sections[step.idSection])
92
+ values.sections[step.idSection] = {};
93
+ values.sections[step.idSection][step.id] = value;
94
+ }
95
+ else {
96
+ values.global[idValue] = value;
97
+ }
93
98
  }
94
99
  return [3 /*break*/, 3];
95
100
  case 2:
@@ -122,7 +127,8 @@ export var calcValuesStore = function (idOrganization, form, originalValues, pos
122
127
  });
123
128
  });
124
129
  };
125
- export var addMapperStep = function (step, customSteps) {
130
+ export var addMapperStep = function (step, customSteps, path) {
131
+ if (path === void 0) { path = ''; }
126
132
  var idElement = nanoid();
127
133
  var element = {
128
134
  ids: {},
@@ -132,10 +138,11 @@ export var addMapperStep = function (step, customSteps) {
132
138
  };
133
139
  var steps = {};
134
140
  var mappers = {};
141
+ var base = path ? path + '-' : '';
135
142
  for (var _i = 0, _a = Object.keys(step.steps); _i < _a.length; _i++) {
136
143
  var idStep = _a[_i];
137
144
  var baseStep = JSON.parse(JSON.stringify(step.steps[idStep]));
138
- var newIdStep = step.id + '-' + idStep + '-' + idElement;
145
+ var newIdStep = base + step.id + '-' + idElement + '-' + idStep;
139
146
  baseStep.id = newIdStep;
140
147
  element.ids[idStep] = newIdStep;
141
148
  steps[newIdStep] = baseStep;
@@ -144,7 +151,7 @@ export var addMapperStep = function (step, customSteps) {
144
151
  for (var _b = 0, _c = Object.values(step.steps); _b < _c.length; _b++) {
145
152
  var nestedStep = _c[_b];
146
153
  if (nestedStep.type === StepTypes.MAPPER) {
147
- var nested = addMapperStep(nestedStep, customSteps);
154
+ var nested = addMapperStep(nestedStep, customSteps, base + step.id + '-' + idElement);
148
155
  steps = __assign(__assign({}, steps), nested.steps);
149
156
  mappers = __assign(__assign({}, mappers), nested.mappers);
150
157
  mappers[element.ids[nestedStep.id]] = [nested.element];
@@ -196,165 +203,169 @@ export var calcRecursiveCondition = function (condition, ids) {
196
203
  break;
197
204
  }
198
205
  };
199
- export var mapOriginalValue = function (idOrganization, step, value, values, form) { return __awaiter(void 0, void 0, void 0, function () {
200
- var _a, elements, mappedElements, _loop_1, _i, elements_1, element, defaultValue, option, stepClassifier, classifier, params, url, entityValues, entityValue;
201
- var _b, _c, _d, _e, _f, _g, _h, _j;
202
- return __generator(this, function (_k) {
203
- switch (_k.label) {
204
- case 0:
205
- if (!value)
206
- return [2 /*return*/, value];
207
- _a = step === null || step === void 0 ? void 0 : step.type;
208
- switch (_a) {
209
- case StepTypes.MAPPER: return [3 /*break*/, 1];
210
- case StepTypes.TEXTAREA: return [3 /*break*/, 6];
211
- case StepTypes.SELECTOR: return [3 /*break*/, 7];
212
- case StepTypes.CLASSIFIER_SELECTOR: return [3 /*break*/, 8];
213
- case StepTypes.ENTITYVALUEPICKER: return [3 /*break*/, 9];
214
- }
215
- return [3 /*break*/, 12];
216
- case 1:
217
- elements = value;
218
- mappedElements = [];
219
- _loop_1 = function (element) {
220
- var idElement, mappedElement, _l, _m, subStep, dependencies, _o, dependencies_1, idDep, mappedIdDep, _p, _q, key;
221
- return __generator(this, function (_r) {
222
- switch (_r.label) {
223
- case 0:
224
- idElement = (_b = element.id) !== null && _b !== void 0 ? _b : nanoid();
225
- mappedElement = {
226
- id: idElement,
227
- ids: {},
228
- originalValues: {},
229
- isOriginal: true,
230
- };
231
- if (element.value) {
232
- mappedElement.value = element.value;
233
- }
234
- return [4 /*yield*/, Promise.all(Object.keys(step.steps).map(function (idStep) { return __awaiter(void 0, void 0, void 0, function () {
235
- var newIdStep, value;
236
- return __generator(this, function (_a) {
237
- switch (_a.label) {
238
- case 0:
239
- newIdStep = step.id + '-' + idStep + '-' + idElement;
240
- mappedElement.ids[idStep] = newIdStep;
241
- return [4 /*yield*/, mapOriginalValue(idOrganization, step.steps[idStep], element[idStep], values, form)];
242
- case 1:
243
- value = _a.sent();
244
- if (value !== undefined) {
245
- if (!values.sections[step.idSection])
246
- values.sections[step.idSection] = {};
247
- values.sections[step.idSection][newIdStep] = value;
248
- }
249
- return [2 /*return*/];
250
- }
251
- });
252
- }); }))];
253
- case 1:
254
- _r.sent();
255
- for (_l = 0, _m = Object.values(step.steps); _l < _m.length; _l++) {
256
- subStep = _m[_l];
257
- dependencies = (_c = subStep.dependencies) !== null && _c !== void 0 ? _c : [];
258
- if (subStep.condition) {
259
- dependencies = __spreadArray(__spreadArray([], dependencies, true), calcNestedConditionSteps(subStep.condition), true).filter(function (item, i, ar) { return ar.indexOf(item) === i; });
206
+ export var mapOriginalValue = function (idOrganization, step, value, values, form, path) {
207
+ if (path === void 0) { path = ''; }
208
+ return __awaiter(void 0, void 0, void 0, function () {
209
+ var _a, elements, mappedElements, _loop_1, _i, elements_1, element, defaultValue, option, stepClassifier, classifier, params, url, entityValues, entityValue;
210
+ var _b, _c, _d, _e, _f, _g, _h, _j;
211
+ return __generator(this, function (_k) {
212
+ switch (_k.label) {
213
+ case 0:
214
+ if (!value)
215
+ return [2 /*return*/, value];
216
+ _a = step === null || step === void 0 ? void 0 : step.type;
217
+ switch (_a) {
218
+ case StepTypes.MAPPER: return [3 /*break*/, 1];
219
+ case StepTypes.TEXTAREA: return [3 /*break*/, 6];
220
+ case StepTypes.SELECTOR: return [3 /*break*/, 7];
221
+ case StepTypes.CLASSIFIER_SELECTOR: return [3 /*break*/, 8];
222
+ case StepTypes.ENTITYVALUEPICKER: return [3 /*break*/, 9];
223
+ }
224
+ return [3 /*break*/, 12];
225
+ case 1:
226
+ elements = value;
227
+ mappedElements = [];
228
+ _loop_1 = function (element) {
229
+ var idElement, mappedElement, base, _l, _m, subStep, dependencies, _o, dependencies_1, idDep, mappedIdDep, _p, _q, key;
230
+ return __generator(this, function (_r) {
231
+ switch (_r.label) {
232
+ case 0:
233
+ idElement = (_b = element.id) !== null && _b !== void 0 ? _b : nanoid();
234
+ mappedElement = {
235
+ id: idElement,
236
+ ids: {},
237
+ originalValues: {},
238
+ isOriginal: true,
239
+ };
240
+ if (element.value) {
241
+ mappedElement.value = element.value;
260
242
  }
261
- for (_o = 0, dependencies_1 = dependencies; _o < dependencies_1.length; _o++) {
262
- idDep = dependencies_1[_o];
263
- mappedIdDep = step.id + '-' + idDep + '-' + idElement;
264
- if (!values.sections[step.idSection][idDep] &&
265
- !values.global[mappedIdDep] &&
266
- element[idDep]) {
267
- values.global[mappedIdDep] = element[idDep];
268
- mappedElement.ids[idDep] = mappedIdDep;
243
+ base = path ? path + '-' : '';
244
+ return [4 /*yield*/, Promise.all(Object.keys(step.steps).map(function (idStep) { return __awaiter(void 0, void 0, void 0, function () {
245
+ var newIdStep, value;
246
+ return __generator(this, function (_a) {
247
+ switch (_a.label) {
248
+ case 0:
249
+ newIdStep = base + step.id + '-' + idElement + '-' + idStep;
250
+ mappedElement.ids[idStep] = newIdStep;
251
+ return [4 /*yield*/, mapOriginalValue(idOrganization, step.steps[idStep], element[idStep], values, form, base + step.id + '-' + idElement)];
252
+ case 1:
253
+ value = _a.sent();
254
+ if (value !== undefined) {
255
+ if (!values.sections[step.idSection])
256
+ values.sections[step.idSection] = {};
257
+ values.sections[step.idSection][newIdStep] = value;
258
+ }
259
+ return [2 /*return*/];
260
+ }
261
+ });
262
+ }); }))];
263
+ case 1:
264
+ _r.sent();
265
+ for (_l = 0, _m = Object.values(step.steps); _l < _m.length; _l++) {
266
+ subStep = _m[_l];
267
+ dependencies = (_c = subStep.dependencies) !== null && _c !== void 0 ? _c : [];
268
+ if (subStep.condition) {
269
+ dependencies = __spreadArray(__spreadArray([], dependencies, true), calcNestedConditionSteps(subStep.condition), true).filter(function (item, i, ar) { return ar.indexOf(item) === i; });
270
+ }
271
+ for (_o = 0, dependencies_1 = dependencies; _o < dependencies_1.length; _o++) {
272
+ idDep = dependencies_1[_o];
273
+ mappedIdDep = base + step.id + '-' + idElement + '-' + idDep;
274
+ if (!values.sections[step.idSection][idDep] &&
275
+ !values.global[mappedIdDep] &&
276
+ element[idDep]) {
277
+ values.global[mappedIdDep] = element[idDep];
278
+ mappedElement.ids[idDep] = mappedIdDep;
279
+ }
269
280
  }
270
281
  }
271
- }
272
- for (_p = 0, _q = Object.keys(element); _p < _q.length; _p++) {
273
- key = _q[_p];
274
- if (step.steps[key] || key === 'id')
275
- continue;
276
- mappedElement.originalValues[key] = element[key];
277
- }
278
- mappedElements.push(mappedElement);
279
- return [2 /*return*/];
282
+ for (_p = 0, _q = Object.keys(element); _p < _q.length; _p++) {
283
+ key = _q[_p];
284
+ if (step.steps[key] || key === 'id')
285
+ continue;
286
+ mappedElement.originalValues[key] = element[key];
287
+ }
288
+ mappedElements.push(mappedElement);
289
+ return [2 /*return*/];
290
+ }
291
+ });
292
+ };
293
+ _i = 0, elements_1 = elements;
294
+ _k.label = 2;
295
+ case 2:
296
+ if (!(_i < elements_1.length)) return [3 /*break*/, 5];
297
+ element = elements_1[_i];
298
+ return [5 /*yield**/, _loop_1(element)];
299
+ case 3:
300
+ _k.sent();
301
+ _k.label = 4;
302
+ case 4:
303
+ _i++;
304
+ return [3 /*break*/, 2];
305
+ case 5: return [2 /*return*/, { elements: mappedElements, page: 0 }];
306
+ case 6:
307
+ {
308
+ if (step.hasTextEditor) {
309
+ if (typeof value === 'string') {
310
+ return [2 /*return*/, stringToDraft(value)];
311
+ }
312
+ return [2 /*return*/, getRawText(value === null || value === void 0 ? void 0 : value.draft, value === null || value === void 0 ? void 0 : value.text)];
313
+ }
314
+ defaultValue = (_d = value.value) !== null && _d !== void 0 ? _d : value;
315
+ if (typeof defaultValue === 'string') {
316
+ return [2 /*return*/, defaultValue];
280
317
  }
281
- });
282
- };
283
- _i = 0, elements_1 = elements;
284
- _k.label = 2;
285
- case 2:
286
- if (!(_i < elements_1.length)) return [3 /*break*/, 5];
287
- element = elements_1[_i];
288
- return [5 /*yield**/, _loop_1(element)];
289
- case 3:
290
- _k.sent();
291
- _k.label = 4;
292
- case 4:
293
- _i++;
294
- return [3 /*break*/, 2];
295
- case 5: return [2 /*return*/, mappedElements];
296
- case 6:
297
- {
298
- if (step.hasTextEditor) {
299
- if (typeof value === 'string') {
300
- return [2 /*return*/, stringToDraft(value)];
318
+ else {
319
+ return [2 /*return*/, (_e = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.text) !== null && _e !== void 0 ? _e : ''];
301
320
  }
302
- return [2 /*return*/, getRawText(value === null || value === void 0 ? void 0 : value.draft, value === null || value === void 0 ? void 0 : value.text)];
303
321
  }
304
- defaultValue = (_d = value.value) !== null && _d !== void 0 ? _d : value;
305
- if (typeof defaultValue === 'string') {
306
- return [2 /*return*/, defaultValue];
322
+ _k.label = 7;
323
+ case 7:
324
+ {
325
+ option = step.options.find(function (option) { return option.value === value; });
326
+ if (!(value === null || value === void 0 ? void 0 : value.value))
327
+ return [2 /*return*/, option];
328
+ return [2 /*return*/, value];
307
329
  }
308
- else {
309
- return [2 /*return*/, (_e = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.text) !== null && _e !== void 0 ? _e : ''];
330
+ _k.label = 8;
331
+ case 8:
332
+ {
333
+ stepClassifier = (_f = form === null || form === void 0 ? void 0 : form.classifiers) === null || _f === void 0 ? void 0 : _f[(_g = step.idClassifier) !== null && _g !== void 0 ? _g : ''];
334
+ if (stepClassifier && !value.value) {
335
+ classifier = (_h = form.classifiers) === null || _h === void 0 ? void 0 : _h[value];
336
+ return [2 /*return*/, { value: value, label: classifier === null || classifier === void 0 ? void 0 : classifier.name }];
337
+ }
338
+ return [3 /*break*/, 13];
310
339
  }
311
- }
312
- _k.label = 7;
313
- case 7:
314
- {
315
- option = step.options.find(function (option) { return option.value === value; });
316
- if (!(value === null || value === void 0 ? void 0 : value.value))
317
- return [2 /*return*/, option];
318
- return [2 /*return*/, value];
319
- }
320
- _k.label = 8;
321
- case 8:
322
- {
323
- stepClassifier = (_f = form === null || form === void 0 ? void 0 : form.classifiers) === null || _f === void 0 ? void 0 : _f[(_g = step.idClassifier) !== null && _g !== void 0 ? _g : ''];
324
- if (stepClassifier && !value.value) {
325
- classifier = (_h = form.classifiers) === null || _h === void 0 ? void 0 : _h[value];
326
- return [2 /*return*/, { value: value, label: classifier === null || classifier === void 0 ? void 0 : classifier.name }];
340
+ _k.label = 9;
341
+ case 9:
342
+ if (!!value._id) return [3 /*break*/, 11];
343
+ params = new URLSearchParams(value);
344
+ url = "".concat(idOrganization, "/entities/").concat(step.idEntity, "?").concat(params.toString());
345
+ return [4 /*yield*/, widgetInstance.get(url)];
346
+ case 10:
347
+ entityValues = (_k.sent()).data;
348
+ if (entityValues.length === 1) {
349
+ entityValue = entityValues[0];
350
+ if (((_j = step.options[entityValue._id]) === null || _j === void 0 ? void 0 : _j.type) ===
351
+ EntityValueOptionTypes.HIDE)
352
+ return [2 /*return*/, undefined];
353
+ return [2 /*return*/, entityValues[0]];
327
354
  }
328
- return [3 /*break*/, 13];
329
- }
330
- _k.label = 9;
331
- case 9:
332
- if (!!value._id) return [3 /*break*/, 11];
333
- params = new URLSearchParams(value);
334
- url = "".concat(idOrganization, "/entities/").concat(step.idEntity, "?").concat(params.toString());
335
- return [4 /*yield*/, widgetInstance.get(url)];
336
- case 10:
337
- entityValues = (_k.sent()).data;
338
- if (entityValues.length === 1) {
339
- entityValue = entityValues[0];
340
- if (((_j = step.options[entityValue._id]) === null || _j === void 0 ? void 0 : _j.type) ===
341
- EntityValueOptionTypes.HIDE)
342
- return [2 /*return*/, undefined];
343
- return [2 /*return*/, entityValues[0]];
344
- }
345
- return [2 /*return*/, null];
346
- case 11: return [2 /*return*/, value];
347
- case 12:
348
- if (step.type.startsWith('CBR_') &&
349
- (value === null || value === void 0 ? void 0 : value.id) &&
350
- typeof value.id === 'number') {
351
- return [2 /*return*/, __assign(__assign({}, value), { id: value.id.toString() })];
352
- }
353
- return [2 /*return*/, value];
354
- case 13: return [2 /*return*/];
355
- }
355
+ return [2 /*return*/, null];
356
+ case 11: return [2 /*return*/, value];
357
+ case 12:
358
+ if (step.type.startsWith('CBR_') &&
359
+ (value === null || value === void 0 ? void 0 : value.id) &&
360
+ typeof value.id === 'number') {
361
+ return [2 /*return*/, __assign(__assign({}, value), { id: value.id.toString() })];
362
+ }
363
+ return [2 /*return*/, value];
364
+ case 13: return [2 /*return*/];
365
+ }
366
+ });
356
367
  });
357
- }); };
368
+ };
358
369
  function calcNestedConditionSteps(condition) {
359
370
  var steps = [];
360
371
  if (!condition)