@arquimedes.co/eureka-forms 2.0.42 → 2.0.43

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.
@@ -9,6 +9,15 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
12
21
  import { nanoid } from 'nanoid';
13
22
  import StepTypes, { FormTypes } from '../constants/FormStepTypes';
14
23
  import { getRawText, stringToDraft } from '../Utils/DraftFunctions';
@@ -133,7 +142,7 @@ export var calcRecursiveCondition = function (condition, ids) {
133
142
  }
134
143
  };
135
144
  export var mapOriginalValue = function (step, value, values, form) {
136
- var _a, _b, _c, _d, _e, _f;
145
+ var _a, _b, _c, _d, _e, _f, _g;
137
146
  if (!value)
138
147
  return value;
139
148
  switch (step === null || step === void 0 ? void 0 : step.type) {
@@ -152,8 +161,8 @@ export var mapOriginalValue = function (step, value, values, form) {
152
161
  if (element.value) {
153
162
  mappedElement.value = element.value;
154
163
  }
155
- for (var _g = 0, _h = Object.keys(step.steps); _g < _h.length; _g++) {
156
- var idStep = _h[_g];
164
+ for (var _h = 0, _j = Object.keys(step.steps); _h < _j.length; _h++) {
165
+ var idStep = _j[_h];
157
166
  var newIdStep = step.id + '-' + idStep + '-' + idElement;
158
167
  mappedElement.ids[idStep] = newIdStep;
159
168
  var value_1 = mapOriginalValue(step.steps[idStep], element[idStep], values, form);
@@ -163,8 +172,25 @@ export var mapOriginalValue = function (step, value, values, form) {
163
172
  values.sections[step.idSection][newIdStep] = value_1;
164
173
  }
165
174
  }
166
- for (var _j = 0, _k = Object.keys(element); _j < _k.length; _j++) {
167
- var key = _k[_j];
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; });
180
+ }
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
+ }
190
+ }
191
+ }
192
+ for (var _o = 0, _p = Object.keys(element); _o < _p.length; _o++) {
193
+ var key = _p[_o];
168
194
  if (step.steps[key] || key === 'id')
169
195
  continue;
170
196
  mappedElement.originalValues[key] = element[key];
@@ -180,12 +206,12 @@ export var mapOriginalValue = function (step, value, values, form) {
180
206
  }
181
207
  return getRawText(value === null || value === void 0 ? void 0 : value.draft, value === null || value === void 0 ? void 0 : value.text);
182
208
  }
183
- var defaultValue = (_b = value.value) !== null && _b !== void 0 ? _b : value;
209
+ var defaultValue = (_c = value.value) !== null && _c !== void 0 ? _c : value;
184
210
  if (typeof defaultValue === 'string') {
185
211
  return defaultValue;
186
212
  }
187
213
  else {
188
- return (_c = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.text) !== null && _c !== void 0 ? _c : '';
214
+ return (_d = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.text) !== null && _d !== void 0 ? _d : '';
189
215
  }
190
216
  }
191
217
  case StepTypes.SELECTOR: {
@@ -195,9 +221,9 @@ export var mapOriginalValue = function (step, value, values, form) {
195
221
  return value;
196
222
  }
197
223
  case StepTypes.CLASSIFIER_SELECTOR: {
198
- var stepClassifier = (_d = form === null || form === void 0 ? void 0 : form.classifiers) === null || _d === void 0 ? void 0 : _d[(_e = step.idClassifier) !== null && _e !== void 0 ? _e : ''];
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 : ''];
199
225
  if (stepClassifier && !value.value) {
200
- var classifier = (_f = form.classifiers) === null || _f === void 0 ? void 0 : _f[value];
226
+ var classifier = (_g = form.classifiers) === null || _g === void 0 ? void 0 : _g[value];
201
227
  return { value: value, label: classifier === null || classifier === void 0 ? void 0 : classifier.name };
202
228
  }
203
229
  break;
@@ -211,6 +237,22 @@ export var mapOriginalValue = function (step, value, values, form) {
211
237
  return value;
212
238
  }
213
239
  };
240
+ function calcNestedConditionSteps(condition) {
241
+ var steps = [];
242
+ if (!condition)
243
+ return steps;
244
+ switch (condition.type) {
245
+ case ConditionTypes.EXPRESSION:
246
+ return condition.conditions
247
+ .map(function (condition) { return calcNestedConditionSteps(condition); })
248
+ .flat();
249
+ case ConditionTypes.FORM_STEP:
250
+ return [condition.idStep];
251
+ default:
252
+ break;
253
+ }
254
+ return steps;
255
+ }
214
256
  export var calcInitialSections = function (form) {
215
257
  var previousSections = [];
216
258
  var nextSections = calcNextSections(form.firstSection, form);
@@ -191,8 +191,9 @@ function calcStepDependency(idStep, steps, values, customSteps) {
191
191
  var _a;
192
192
  var depStep = steps[idStep];
193
193
  if (!depStep) {
194
- console.error('Missing Step Dependency:', idStep);
195
194
  var originalValue_1 = values.global[idStep];
195
+ if (!originalValue_1)
196
+ console.error('Missing Step Dependency:', idStep);
196
197
  return {
197
198
  type: originalValue_1 ? 'ORIGINAL' : 'MISSING',
198
199
  value: originalValue_1 !== null && originalValue_1 !== void 0 ? originalValue_1 : null,
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  };
23
23
  import { createElement as _createElement } from "react";
24
24
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
25
- import React, { useContext, useEffect } from 'react';
25
+ import React, { useContext, useEffect, useState } from 'react';
26
26
  import styles from './MaterialCollapsibleStep.module.css';
27
27
  import { Controller, useFormContext } from 'react-hook-form';
28
28
  import StepComponent from '../../Step';
@@ -31,8 +31,9 @@ import ExpandLessRoundedIcon from '@material-ui/icons/ExpandLessRounded';
31
31
  import FormContext from '../../../Contexts/FormContext';
32
32
  import { useAppSelector } from '../../../hooks';
33
33
  function Collapsible(_a) {
34
- var _b, _c, _d, _e;
34
+ var _b, _c, _d;
35
35
  var step = _a.step, open = _a.open, setOpen = _a.setOpen, others = __rest(_a, ["step", "open", "setOpen"]);
36
+ var _e = useState(true), firstTime = _e[0], setFirstTime = _e[1];
36
37
  var formStyle = useAppSelector(function (state) { return state.global; }).formStyle;
37
38
  var form = useContext(FormContext);
38
39
  var errors = useFormContext().formState.errors;
@@ -47,15 +48,19 @@ function Collapsible(_a) {
47
48
  color: formStyle.textColor,
48
49
  borderColor: formStyle.primaryColor,
49
50
  } }, { children: [_jsx("div", __assign({ className: styles.collapsibleLabel, onClick: function () {
51
+ if (firstTime)
52
+ setFirstTime(false);
50
53
  setOpen(!open);
51
54
  } }, { children: step.label })), _jsx("div", __assign({ className: styles.expand, onClick: function () {
55
+ if (firstTime)
56
+ setFirstTime(false);
52
57
  setOpen(!open);
53
58
  } }, { children: _jsx("div", __assign({ className: styles.expandIcon }, { children: open ? (_jsx(ExpandLessRoundedIcon, { fontSize: "inherit" })) : (_jsx(ExpandMoreRoundedIcon, { fontSize: "inherit" })) })) }))] })), _jsx("div", __assign({ className: styles.content, style: {
54
- height: open === 'TRUE'
55
- ? 'auto'
56
- : open
57
- ? (_e = (_d = contentRef.current) === null || _d === void 0 ? void 0 : _d.offsetHeight) !== null && _e !== void 0 ? _e : 'auto'
58
- : 0,
59
+ height: open
60
+ ? firstTime
61
+ ? 'auto'
62
+ : (_d = contentRef.current) === null || _d === void 0 ? void 0 : _d.offsetHeight
63
+ : 0,
59
64
  } }, { children: _jsx("div", __assign({ className: styles.contentContainer, ref: contentRef }, { children: step.steps.map(function (idSubStep) {
60
65
  var subStep = form.steps[idSubStep];
61
66
  return (_createElement(StepComponent, __assign({}, others, { step: subStep, key: idSubStep })));
@@ -67,7 +72,7 @@ function CollapsibleStep(props) {
67
72
  var _a;
68
73
  var postview = useAppSelector(function (state) { return state.global; }).postview;
69
74
  var _b = useFormContext(), clearErrors = _b.clearErrors, errors = _b.formState.errors;
70
- return (_jsx(Controller, { name: props.step.id, defaultValue: ((_a = props.step.defaultValue) !== null && _a !== void 0 ? _a : postview) ? false : true, render: function (_a) {
75
+ return (_jsx(Controller, { name: props.step.id, defaultValue: (_a = props.step.defaultValue) !== null && _a !== void 0 ? _a : (postview ? false : true), render: function (_a) {
71
76
  var _b = _a.field, value = _b.value, onChange = _b.onChange;
72
77
  return (_jsx(Collapsible, __assign({}, props, { open: value, setOpen: function (open) {
73
78
  var _a;
@@ -60,3 +60,9 @@
60
60
  margin-bottom: 10px;
61
61
  border-radius: 20px;
62
62
  }
63
+
64
+ @media print {
65
+ .content {
66
+ height: auto !important;
67
+ }
68
+ }
@@ -300,6 +300,7 @@ export var evaluateCondition = function (condition, dependencies) {
300
300
  return boolFactor;
301
301
  return !boolFactor;
302
302
  }
303
+ var dependency = dependencies[condition.idStep];
303
304
  var value = dependencies[condition.idStep].value;
304
305
  switch (condition.stepType) {
305
306
  // case FormStepTypes.AGENTPICKER:
@@ -332,11 +333,12 @@ export var evaluateCondition = function (condition, dependencies) {
332
333
  }
333
334
  }
334
335
  case FormStepTypes.SELECTOR: {
336
+ var val = dependency.type === 'ORIGINAL' ? value : value.value;
335
337
  if (condition.operator === OperatorTypes.EQUAL) {
336
- return condition.value === (value === null || value === void 0 ? void 0 : value.value);
338
+ return condition.value === val;
337
339
  }
338
340
  else {
339
- return !(condition.value === (value === null || value === void 0 ? void 0 : value.value));
341
+ return !(condition.value === val);
340
342
  }
341
343
  }
342
344
  case FormStepTypes.TEXTINPUT: {
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.42",
4
+ "version": "2.0.43",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",