@arquimedes.co/eureka-forms 2.0.44 → 2.0.45-test

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ import { SiteState, ValuesStore } from '../States/SiteSlice';
4
4
  import { CustomStep } from '../FormSteps/CustomStep';
5
5
  import { MapperElement } from '../@Types/MapperElement';
6
6
  import { Condition } from '../@Types/Condition';
7
- export declare const calcValuesStore: (form: Readonly<Form>, originalValues?: Record<string, any>, postview?: boolean, customSteps?: Record<string, CustomStep>) => ValuesStore;
7
+ export declare const calcValuesStore: (idOrganization: string, form: Readonly<Form>, originalValues?: Record<string, any>, postview?: boolean, customSteps?: Record<string, CustomStep>) => Promise<ValuesStore>;
8
8
  export declare const addMapperStep: <Type>(step: Mapper, customSteps: Record<string, CustomStep>) => {
9
9
  element: MapperElement<Type>;
10
10
  /** Record of all the new mapper values created */
@@ -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: (step: FormStep, value: any, values: ValuesStore, form?: Readonly<Form>) => any;
17
+ export declare const mapOriginalValue: (idOrganization: string, step: FormStep, value: any, values: ValuesStore, form?: Readonly<Form>) => Promise<any>;
18
18
  export declare const calcInitialSections: (form: Form) => Pick<SiteState, 'previousSections' | 'idCurrentSection' | 'nextSections'>;
@@ -9,6 +9,42 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ 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;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
12
48
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
49
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
50
  if (ar || !(i in from)) {
@@ -19,52 +55,72 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
55
  return to.concat(ar || Array.prototype.slice.call(from));
20
56
  };
21
57
  import { nanoid } from 'nanoid';
22
- import StepTypes, { FormTypes } from '../constants/FormStepTypes';
58
+ import StepTypes, { EntityValueOptionTypes, FormTypes, } from '../constants/FormStepTypes';
23
59
  import { getRawText, stringToDraft } from '../Utils/DraftFunctions';
24
60
  import { calcSubSteps } from '../FormSteps/StepFunctions';
25
61
  import ConditionTypes from '../constants/ConditionTypes';
26
- export var calcValuesStore = function (form, originalValues, postview, customSteps) {
27
- var _a;
28
- var _b, _c;
62
+ import widgetInstance from '../Utils/AxiosWidget';
63
+ export var calcValuesStore = function (idOrganization, form, originalValues, postview, customSteps) {
29
64
  if (originalValues === void 0) { originalValues = {}; }
30
65
  if (postview === void 0) { postview = false; }
31
66
  if (customSteps === void 0) { customSteps = {}; }
32
- var values = {
33
- global: {},
34
- sections: {},
35
- };
36
- for (var _i = 0, _d = Object.keys(originalValues); _i < _d.length; _i++) {
37
- var idValue = _d[_i];
38
- var step = form.steps[idValue];
39
- if (step && !((_b = form.hiddenSteps) === null || _b === void 0 ? void 0 : _b.includes(step.id))) {
40
- var value = mapOriginalValue(step, originalValues[step.id], values, form);
41
- if (value !== undefined) {
42
- if (!values.sections[step.idSection])
43
- values.sections[step.idSection] = {};
44
- values.sections[step.idSection][step.id] = value;
67
+ return __awaiter(void 0, void 0, void 0, function () {
68
+ var values, _i, _a, section, _b, _c, idStep, step, _d, element, mappers;
69
+ var _e;
70
+ var _f;
71
+ return __generator(this, function (_g) {
72
+ switch (_g.label) {
73
+ case 0:
74
+ values = {
75
+ global: {},
76
+ sections: {},
77
+ };
78
+ return [4 /*yield*/, Promise.all(Object.keys(originalValues).map(function (idValue) { return __awaiter(void 0, void 0, void 0, function () {
79
+ var step, value;
80
+ var _a;
81
+ return __generator(this, function (_b) {
82
+ switch (_b.label) {
83
+ case 0:
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];
86
+ return [4 /*yield*/, mapOriginalValue(idOrganization, step, originalValues[step.id], values, form)];
87
+ case 1:
88
+ value = _b.sent();
89
+ if (value !== undefined) {
90
+ if (!values.sections[step.idSection])
91
+ values.sections[step.idSection] = {};
92
+ values.sections[step.idSection][step.id] = value;
93
+ }
94
+ return [3 /*break*/, 3];
95
+ case 2:
96
+ values.global[idValue] = originalValues[idValue];
97
+ _b.label = 3;
98
+ case 3: return [2 /*return*/];
99
+ }
100
+ });
101
+ }); }))];
102
+ case 1:
103
+ _g.sent();
104
+ if (postview)
105
+ return [2 /*return*/, values];
106
+ for (_i = 0, _a = Object.values(form.sections); _i < _a.length; _i++) {
107
+ section = _a[_i];
108
+ for (_b = 0, _c = section.steps; _b < _c.length; _b++) {
109
+ idStep = _c[_b];
110
+ step = form.steps[idStep];
111
+ if (step.type !== StepTypes.MAPPER ||
112
+ ((_f = values.sections[step.idSection]) === null || _f === void 0 ? void 0 : _f[step.id]))
113
+ continue;
114
+ if (!values.sections[step.idSection])
115
+ values.sections[step.idSection] = {};
116
+ _d = addMapperStep(step, customSteps), element = _d.element, mappers = _d.mappers;
117
+ values.sections[step.idSection] = __assign(__assign(__assign({}, values.sections[step.idSection]), mappers), (_e = {}, _e[step.id] = [element], _e));
118
+ }
119
+ }
120
+ return [2 /*return*/, values];
45
121
  }
46
- }
47
- else {
48
- values.global[idValue] = originalValues[idValue];
49
- }
50
- }
51
- if (postview)
52
- return values;
53
- for (var _e = 0, _f = Object.values(form.sections); _e < _f.length; _e++) {
54
- var section = _f[_e];
55
- for (var _g = 0, _h = section.steps; _g < _h.length; _g++) {
56
- var idStep = _h[_g];
57
- var step = form.steps[idStep];
58
- if (step.type !== StepTypes.MAPPER ||
59
- ((_c = values.sections[step.idSection]) === null || _c === void 0 ? void 0 : _c[step.id]))
60
- continue;
61
- if (!values.sections[step.idSection])
62
- values.sections[step.idSection] = {};
63
- var _j = addMapperStep(step, customSteps), element = _j.element, mappers = _j.mappers;
64
- values.sections[step.idSection] = __assign(__assign(__assign({}, values.sections[step.idSection]), mappers), (_a = {}, _a[step.id] = [element], _a));
65
- }
66
- }
67
- return values;
122
+ });
123
+ });
68
124
  };
69
125
  export var addMapperStep = function (step, customSteps) {
70
126
  var idElement = nanoid();
@@ -141,102 +197,165 @@ export var calcRecursiveCondition = function (condition, ids) {
141
197
  break;
142
198
  }
143
199
  };
144
- export var mapOriginalValue = function (step, value, values, form) {
145
- var _a, _b, _c, _d, _e, _f, _g;
146
- if (!value)
147
- return value;
148
- switch (step === null || step === void 0 ? void 0 : step.type) {
149
- case StepTypes.MAPPER: {
150
- var elements = value;
151
- var mappedElements = [];
152
- for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
153
- var element = elements_1[_i];
154
- var idElement = (_a = element.id) !== null && _a !== void 0 ? _a : nanoid();
155
- var mappedElement = {
156
- id: idElement,
157
- ids: {},
158
- originalValues: {},
159
- isOriginal: true,
160
- };
161
- if (element.value) {
162
- mappedElement.value = element.value;
200
+ export var mapOriginalValue = function (idOrganization, step, value, values, form) { return __awaiter(void 0, void 0, void 0, function () {
201
+ var _a, elements, mappedElements, _loop_1, _i, elements_1, element, defaultValue, option, stepClassifier, classifier, params, url, entityValues, entityValue;
202
+ var _b, _c, _d, _e, _f, _g, _h, _j;
203
+ return __generator(this, function (_k) {
204
+ switch (_k.label) {
205
+ case 0:
206
+ if (!value)
207
+ return [2 /*return*/, value];
208
+ _a = step === null || step === void 0 ? void 0 : step.type;
209
+ switch (_a) {
210
+ case StepTypes.MAPPER: return [3 /*break*/, 1];
211
+ case StepTypes.TEXTAREA: return [3 /*break*/, 6];
212
+ case StepTypes.SELECTOR: return [3 /*break*/, 7];
213
+ case StepTypes.CLASSIFIER_SELECTOR: return [3 /*break*/, 8];
214
+ case StepTypes.ENTITYVALUEPICKER: return [3 /*break*/, 9];
163
215
  }
164
- for (var _h = 0, _j = Object.keys(step.steps); _h < _j.length; _h++) {
165
- var idStep = _j[_h];
166
- var newIdStep = step.id + '-' + idStep + '-' + idElement;
167
- mappedElement.ids[idStep] = newIdStep;
168
- var value_1 = mapOriginalValue(step.steps[idStep], element[idStep], values, form);
169
- if (value_1 !== undefined) {
170
- if (!values.sections[step.idSection])
171
- values.sections[step.idSection] = {};
172
- values.sections[step.idSection][newIdStep] = value_1;
216
+ return [3 /*break*/, 12];
217
+ case 1:
218
+ elements = value;
219
+ mappedElements = [];
220
+ _loop_1 = function (element) {
221
+ var idElement, mappedElement, _l, _m, subStep, dependencies, _o, dependencies_1, idDep, mappedIdDep, _p, _q, key;
222
+ return __generator(this, function (_r) {
223
+ switch (_r.label) {
224
+ case 0:
225
+ idElement = (_b = element.id) !== null && _b !== void 0 ? _b : nanoid();
226
+ mappedElement = {
227
+ id: idElement,
228
+ ids: {},
229
+ originalValues: {},
230
+ isOriginal: true,
231
+ };
232
+ if (element.value) {
233
+ mappedElement.value = element.value;
234
+ }
235
+ return [4 /*yield*/, Promise.all(Object.keys(step.steps).map(function (idStep) { return __awaiter(void 0, void 0, void 0, function () {
236
+ var newIdStep, value;
237
+ return __generator(this, function (_a) {
238
+ switch (_a.label) {
239
+ case 0:
240
+ newIdStep = step.id + '-' + idStep + '-' + idElement;
241
+ mappedElement.ids[idStep] = newIdStep;
242
+ return [4 /*yield*/, mapOriginalValue(idOrganization, step.steps[idStep], element[idStep], values, form)];
243
+ case 1:
244
+ value = _a.sent();
245
+ if (value !== undefined) {
246
+ if (!values.sections[step.idSection])
247
+ values.sections[step.idSection] = {};
248
+ values.sections[step.idSection][newIdStep] = value;
249
+ }
250
+ return [2 /*return*/];
251
+ }
252
+ });
253
+ }); }))];
254
+ case 1:
255
+ _r.sent();
256
+ for (_l = 0, _m = Object.values(step.steps); _l < _m.length; _l++) {
257
+ subStep = _m[_l];
258
+ dependencies = (_c = subStep.dependencies) !== null && _c !== void 0 ? _c : [];
259
+ if (subStep.condition) {
260
+ dependencies = __spreadArray(__spreadArray([], dependencies, true), calcNestedConditionSteps(subStep.condition), true).filter(function (item, i, ar) { return ar.indexOf(item) === i; });
261
+ }
262
+ for (_o = 0, dependencies_1 = dependencies; _o < dependencies_1.length; _o++) {
263
+ idDep = dependencies_1[_o];
264
+ mappedIdDep = step.id + '-' + idDep + '-' + idElement;
265
+ if (!values.sections[step.idSection][idDep] &&
266
+ !values.global[mappedIdDep] &&
267
+ element[idDep]) {
268
+ values.global[mappedIdDep] = element[idDep];
269
+ mappedElement.ids[idDep] = mappedIdDep;
270
+ }
271
+ }
272
+ }
273
+ for (_p = 0, _q = Object.keys(element); _p < _q.length; _p++) {
274
+ key = _q[_p];
275
+ if (step.steps[key] || key === 'id')
276
+ continue;
277
+ mappedElement.originalValues[key] = element[key];
278
+ }
279
+ mappedElements.push(mappedElement);
280
+ return [2 /*return*/];
281
+ }
282
+ });
283
+ };
284
+ _i = 0, elements_1 = elements;
285
+ _k.label = 2;
286
+ case 2:
287
+ if (!(_i < elements_1.length)) return [3 /*break*/, 5];
288
+ element = elements_1[_i];
289
+ return [5 /*yield**/, _loop_1(element)];
290
+ case 3:
291
+ _k.sent();
292
+ _k.label = 4;
293
+ case 4:
294
+ _i++;
295
+ return [3 /*break*/, 2];
296
+ case 5: return [2 /*return*/, mappedElements];
297
+ case 6:
298
+ {
299
+ if (step.hasTextEditor) {
300
+ if (typeof value === 'string') {
301
+ return [2 /*return*/, stringToDraft(value)];
302
+ }
303
+ return [2 /*return*/, getRawText(value === null || value === void 0 ? void 0 : value.draft, value === null || value === void 0 ? void 0 : value.text)];
173
304
  }
174
- }
175
- for (var _k = 0, _l = Object.values(step.steps); _k < _l.length; _k++) {
176
- var subStep = _l[_k];
177
- var dependencies = (_b = subStep.dependencies) !== null && _b !== void 0 ? _b : [];
178
- if (subStep.condition) {
179
- dependencies = __spreadArray(__spreadArray([], dependencies, true), calcNestedConditionSteps(subStep.condition), true).filter(function (item, i, ar) { return ar.indexOf(item) === i; });
305
+ defaultValue = (_d = value.value) !== null && _d !== void 0 ? _d : value;
306
+ if (typeof defaultValue === 'string') {
307
+ return [2 /*return*/, defaultValue];
180
308
  }
181
- for (var _m = 0, dependencies_1 = dependencies; _m < dependencies_1.length; _m++) {
182
- var idDep = dependencies_1[_m];
183
- var mappedIdDep = step.id + '-' + idDep + '-' + idElement;
184
- if (!values.sections[step.idSection][idDep] &&
185
- !values.global[mappedIdDep] &&
186
- element[idDep]) {
187
- values.global[mappedIdDep] = element[idDep];
188
- mappedElement.ids[idDep] = mappedIdDep;
189
- }
309
+ else {
310
+ return [2 /*return*/, (_e = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.text) !== null && _e !== void 0 ? _e : ''];
190
311
  }
191
312
  }
192
- for (var _o = 0, _p = Object.keys(element); _o < _p.length; _o++) {
193
- var key = _p[_o];
194
- if (step.steps[key] || key === 'id')
195
- continue;
196
- mappedElement.originalValues[key] = element[key];
313
+ _k.label = 7;
314
+ case 7:
315
+ {
316
+ option = step.options.find(function (option) { return option.value === value; });
317
+ if (!(value === null || value === void 0 ? void 0 : value.value))
318
+ return [2 /*return*/, option];
319
+ return [2 /*return*/, value];
197
320
  }
198
- mappedElements.push(mappedElement);
199
- }
200
- return mappedElements;
201
- }
202
- case StepTypes.TEXTAREA: {
203
- if (step.hasTextEditor) {
204
- if (typeof value === 'string') {
205
- return stringToDraft(value);
321
+ _k.label = 8;
322
+ case 8:
323
+ {
324
+ 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 : ''];
325
+ if (stepClassifier && !value.value) {
326
+ classifier = (_h = form.classifiers) === null || _h === void 0 ? void 0 : _h[value];
327
+ return [2 /*return*/, { value: value, label: classifier === null || classifier === void 0 ? void 0 : classifier.name }];
328
+ }
329
+ return [3 /*break*/, 13];
206
330
  }
207
- return getRawText(value === null || value === void 0 ? void 0 : value.draft, value === null || value === void 0 ? void 0 : value.text);
208
- }
209
- var defaultValue = (_c = value.value) !== null && _c !== void 0 ? _c : value;
210
- if (typeof defaultValue === 'string') {
211
- return defaultValue;
212
- }
213
- else {
214
- return (_d = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.text) !== null && _d !== void 0 ? _d : '';
215
- }
216
- }
217
- case StepTypes.SELECTOR: {
218
- var option = step.options.find(function (option) { return option.value === value; });
219
- if (!(value === null || value === void 0 ? void 0 : value.value))
220
- return option;
221
- return value;
222
- }
223
- case StepTypes.CLASSIFIER_SELECTOR: {
224
- var stepClassifier = (_e = form === null || form === void 0 ? void 0 : form.classifiers) === null || _e === void 0 ? void 0 : _e[(_f = step.idClassifier) !== null && _f !== void 0 ? _f : ''];
225
- if (stepClassifier && !value.value) {
226
- var classifier = (_g = form.classifiers) === null || _g === void 0 ? void 0 : _g[value];
227
- return { value: value, label: classifier === null || classifier === void 0 ? void 0 : classifier.name };
228
- }
229
- break;
331
+ _k.label = 9;
332
+ case 9:
333
+ if (!!value._id) return [3 /*break*/, 11];
334
+ params = new URLSearchParams(value);
335
+ url = "".concat(idOrganization, "/entities/").concat(step.idEntity, "?").concat(params.toString());
336
+ return [4 /*yield*/, widgetInstance.get(url)];
337
+ case 10:
338
+ entityValues = (_k.sent()).data;
339
+ if (entityValues.length === 1) {
340
+ entityValue = entityValues[0];
341
+ if (((_j = step.options[entityValue._id]) === null || _j === void 0 ? void 0 : _j.type) ===
342
+ EntityValueOptionTypes.HIDE)
343
+ return [2 /*return*/, undefined];
344
+ return [2 /*return*/, entityValues[0]];
345
+ }
346
+ return [2 /*return*/, null];
347
+ case 11: return [2 /*return*/, value];
348
+ case 12:
349
+ if (step.type.startsWith('CBR_') &&
350
+ (value === null || value === void 0 ? void 0 : value.id) &&
351
+ typeof value.id === 'number') {
352
+ return [2 /*return*/, __assign(__assign({}, value), { id: value.id.toString() })];
353
+ }
354
+ return [2 /*return*/, value];
355
+ case 13: return [2 /*return*/];
230
356
  }
231
- default:
232
- if (step.type.startsWith('CBR_') &&
233
- (value === null || value === void 0 ? void 0 : value.id) &&
234
- typeof value.id === 'number') {
235
- return __assign(__assign({}, value), { id: value.id.toString() });
236
- }
237
- return value;
238
- }
239
- };
357
+ });
358
+ }); };
240
359
  function calcNestedConditionSteps(condition) {
241
360
  var steps = [];
242
361
  if (!condition)
@@ -177,7 +177,9 @@ export var useSetupApp = function (isEmbedded, _a) {
177
177
  if (!form || !idOrganization)
178
178
  return [2 /*return*/];
179
179
  dependencies = {};
180
- values = calcValuesStore(form, valuesData, postview, customSteps);
180
+ return [4 /*yield*/, calcValuesStore(idOrganization, form, valuesData, postview, customSteps)];
181
+ case 5:
182
+ values = _c.sent();
181
183
  dispatch(reset(__assign(__assign({ formStyle: internal
182
184
  ? InternalFormStyle
183
185
  : __assign(__assign({}, InternalFormStyle), ((_b = form === null || form === void 0 ? void 0 : form.style) !== null && _b !== void 0 ? _b : {})), internal: !!internal, idOrganization: idOrganization, preview: !!preview, partial: !!partial, postview: !!postview, editable: !!(editable !== null && editable !== void 0 ? editable : true), values: values }, calcInitialSections(form)), { dependencies: calcDependencies(form.steps, customSteps, form.steps, dependencies, values) })));
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.44",
4
+ "version":"2.0.45-test",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",