@arquimedes.co/eureka-forms 2.0.57 → 2.0.59

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.
@@ -129,7 +129,7 @@ function stringToDraft(text) {
129
129
  return draftStructure;
130
130
  }
131
131
  export function calcDependencies(steps, customSteps, allSteps, dependencies, values, addDependents) {
132
- var _a, _b;
132
+ var _a, _b, _c;
133
133
  if (customSteps === void 0) { customSteps = {}; }
134
134
  if (allSteps === void 0) { allSteps = steps; }
135
135
  if (dependencies === void 0) { dependencies = {}; }
@@ -140,8 +140,8 @@ export function calcDependencies(steps, customSteps, allSteps, dependencies, val
140
140
  if (addDependents === void 0) { addDependents = true; }
141
141
  var _loop_1 = function (step) {
142
142
  var idDeps = calcStepDeps(step);
143
- for (var _d = 0, idDeps_1 = idDeps; _d < idDeps_1.length; _d++) {
144
- var idDep = idDeps_1[_d];
143
+ for (var _e = 0, idDeps_1 = idDeps; _e < idDeps_1.length; _e++) {
144
+ var idDep = idDeps_1[_e];
145
145
  if (dependencies[idDep] === undefined &&
146
146
  (addDependents || allSteps[idDep]))
147
147
  dependencies[idDep] = calcStepDependency(idDep, allSteps, values, customSteps);
@@ -150,8 +150,8 @@ export function calcDependencies(steps, customSteps, allSteps, dependencies, val
150
150
  dependencies[idDep].dependents.push(step);
151
151
  }
152
152
  if (step.type === StepTypes.ENTITYVALUEPICKER) {
153
- for (var _e = 0, _f = __spreadArray(__spreadArray([], step.path, true), step.filters, true); _e < _f.length; _e++) {
154
- var dep = _f[_e];
153
+ for (var _f = 0, _g = __spreadArray(__spreadArray([], step.path, true), step.filters, true); _f < _g.length; _f++) {
154
+ var dep = _g[_f];
155
155
  if (dep.type !== EntityValueDataTypes.STEP)
156
156
  continue;
157
157
  if ((_a = step.dependencies) === null || _a === void 0 ? void 0 : _a.includes(dep.idStep))
@@ -165,13 +165,13 @@ export function calcDependencies(steps, customSteps, allSteps, dependencies, val
165
165
  }
166
166
  }
167
167
  if (step.type === StepTypes.MAPPER) {
168
- var subSteps = calcMapperSubSteps(step, (_b = values.sections[step.idSection]) === null || _b === void 0 ? void 0 : _b[step.id].elements, customSteps);
168
+ var subSteps = calcMapperSubSteps(step, (_c = (_b = values.sections[step.idSection]) === null || _b === void 0 ? void 0 : _b[step.id]) === null || _c === void 0 ? void 0 : _c.elements, customSteps);
169
169
  var hasSubSteps = Object.keys(subSteps).length > 0;
170
170
  calcDependencies(hasSubSteps ? subSteps : step.steps, customSteps, __assign(__assign({}, allSteps), subSteps), dependencies, values, hasSubSteps);
171
171
  }
172
172
  };
173
- for (var _i = 0, _c = Object.values(steps); _i < _c.length; _i++) {
174
- var step = _c[_i];
173
+ for (var _i = 0, _d = Object.values(steps); _i < _d.length; _i++) {
174
+ var step = _d[_i];
175
175
  _loop_1(step);
176
176
  }
177
177
  return dependencies;
@@ -51,10 +51,14 @@ import styles from './ColumnForm.module.css';
51
51
  import React from 'react';
52
52
  import Terms from '../../Terms/Terms';
53
53
  import { useFormContext } from 'react-hook-form';
54
- import { useAppSelector } from '../../../hooks';
54
+ import { useAppDispatch, useAppSelector } from '../../../hooks';
55
55
  import Section from '../../Section/Section';
56
56
  import CustomContext from '../../../Contexts/CustomContext';
57
57
  import CustomBtn from '../../../Shared/CustomBtn/CustomBtn';
58
+ import FormContext from '../../../Contexts/FormContext';
59
+ import { addPagedValues } from '../../../States/SiteSlice';
60
+ import { getAppState } from '../../../Utils/store';
61
+ import { IdFormContext } from '../../../App/App';
58
62
  function ColumnForm(_a) {
59
63
  var _this = this;
60
64
  var onSubmit = _a.onSubmit, customSubmitBtns = _a.customSubmitBtns;
@@ -62,14 +66,18 @@ function ColumnForm(_a) {
62
66
  var _c = useAppSelector(function (state) { return state.global; }), postview = _c.postview, editable = _c.editable, formStyle = _c.formStyle;
63
67
  var _d = useFormContext(), trigger = _d.trigger, getValues = _d.getValues, handleSubmit = _d.handleSubmit;
64
68
  var sendLabel = useContext(CustomContext).sendLabel;
69
+ var form = useContext(FormContext);
70
+ var dispatch = useAppDispatch();
71
+ var idForm = useContext(IdFormContext);
65
72
  var previous = useAppSelector(function (state) { return state.site.previousSections; });
66
73
  var next = useAppSelector(function (state) { return state.site.nextSections; });
74
+ var idCurrent = useAppSelector(function (state) { return state.site.idCurrentSection; });
67
75
  /** Esto se usa para no tener que escuchar todo el tiempo los errores del formulario */
68
76
  var handleErrors = handleSubmit(function () { }, function (errors) {
69
77
  console.error('Errors:', errors);
70
78
  });
71
79
  var submit = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
72
- var valid, values;
80
+ var valid, values, state;
73
81
  return __generator(this, function (_a) {
74
82
  switch (_a.label) {
75
83
  case 0:
@@ -82,8 +90,15 @@ function ColumnForm(_a) {
82
90
  handleErrors();
83
91
  return [2 /*return*/, setLoading(false)];
84
92
  }
85
- return [4 /*yield*/, onSubmit(getValues())];
93
+ values = getValues();
94
+ if (!idCurrent) return [3 /*break*/, 3];
95
+ return [4 /*yield*/, dispatch(getAppState({ idForm: idForm })).unwrap()];
86
96
  case 2:
97
+ state = _a.sent();
98
+ addPagedValues(form.steps, values, state.site.values.sections[idCurrent]);
99
+ _a.label = 3;
100
+ case 3: return [4 /*yield*/, onSubmit(values)];
101
+ case 4:
87
102
  values = _a.sent();
88
103
  setLoading(false);
89
104
  return [2 /*return*/, values];
@@ -58,6 +58,7 @@ import { getAppState } from '../../../Utils/store';
58
58
  import { IdFormContext } from '../../../App/App';
59
59
  import CustomBtn from '../../../Shared/CustomBtn/CustomBtn';
60
60
  import FormContext from '../../../Contexts/FormContext';
61
+ import { addPagedValues } from '../../../States/SiteSlice';
61
62
  function StepperForm(_a) {
62
63
  var _this = this;
63
64
  var _b, _c;
@@ -108,6 +109,9 @@ function StepperForm(_a) {
108
109
  values = state.site.previousSections.reduce(function (v, idSection) { return (__assign(__assign({}, v), state.site.values.sections[idSection])); }, {});
109
110
  /** Add the current section's values */
110
111
  values = __assign(__assign({}, values), getValues());
112
+ if (idCurrent) {
113
+ addPagedValues(form.steps, values, state.site.values.sections[idCurrent]);
114
+ }
111
115
  return [4 /*yield*/, onSubmit(values)];
112
116
  case 3:
113
117
  response = _a.sent();
@@ -67,6 +67,7 @@ function PagedMapperElement(_a) {
67
67
  var _c = useAppSelector(function (state) { return state.global; }), formStyle = _c.formStyle, postview = _c.postview;
68
68
  var totalElements = elements.filter(function (elem) { return !elem.deleted; });
69
69
  var position = totalElements.findIndex(function (e) { return e.id == element.id; });
70
+ var containerRef = React.useRef(null);
70
71
  var pagingRef = React.useRef(null);
71
72
  var _d = useFormContext(), getValues = _d.getValues, trigger = _d.trigger, handleSubmit = _d.handleSubmit;
72
73
  var nextIndex = useMemo(function () {
@@ -93,11 +94,12 @@ function PagedMapperElement(_a) {
93
94
  });
94
95
  var handleChangePage = useCallback(function (index) { return __awaiter(_this, void 0, void 0, function () {
95
96
  var valid, values, nestedValues, _i, _a, _b, key, value_1;
96
- return __generator(this, function (_c) {
97
- switch (_c.label) {
97
+ var _c;
98
+ return __generator(this, function (_d) {
99
+ switch (_d.label) {
98
100
  case 0: return [4 /*yield*/, trigger(undefined, { shouldFocus: true })];
99
101
  case 1:
100
- valid = _c.sent();
102
+ valid = _d.sent();
101
103
  /** Imprimir errores si no es valido */
102
104
  if (!valid) {
103
105
  handleErrors();
@@ -115,7 +117,7 @@ function PagedMapperElement(_a) {
115
117
  key: step.id + '-' + element.id,
116
118
  values: nestedValues,
117
119
  }));
118
- location.href = '#' + step.id;
120
+ (_c = containerRef.current) === null || _c === void 0 ? void 0 : _c.scrollIntoView({ behavior: 'smooth' });
119
121
  //Updated the nestedValues in the values store.
120
122
  onChange({
121
123
  elements: elements,
@@ -136,7 +138,7 @@ function PagedMapperElement(_a) {
136
138
  var _a, _b, _c;
137
139
  return (_jsx("div", __assign({ className: widthStats.isMobile
138
140
  ? styles.mobileContainer
139
- : styles.container }, { children: _jsxs("div", __assign({ className: styles.contentContainer, style: {
141
+ : styles.container, ref: containerRef }, { children: _jsxs("div", __assign({ className: styles.contentContainer, style: {
140
142
  width: (size.blockSize + size.spacingSize) *
141
143
  ((_b = (_a = step.style) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : size.blockNum - 1),
142
144
  } }, { children: [name && (_jsx("div", __assign({ className: styles.titleLbl, style: { color: formStyle.textColor } }, { children: loading ? 'Cargando...' : name + ':' }))), _jsxs("div", __assign({ className: styles.btnsContainer }, { children: [renderElementButtons === null || renderElementButtons === void 0 ? void 0 : renderElementButtons(element), (deletable || !element.isOriginal) && (_jsx("div", __assign({ className: !editable || postview
@@ -92,3 +92,4 @@ export declare const focusStep: import("@reduxjs/toolkit").ActionCreatorWithOpti
92
92
  values: Record<string, any>;
93
93
  }, "site/updateNestedValues">;
94
94
  export default SiteSlice;
95
+ export declare function addPagedValues(steps: Record<string, FormStep>, values: Record<string, any>, original: Record<string, any>, path?: string): void;
@@ -144,7 +144,7 @@ export var SiteSlice = createSlice({
144
144
  });
145
145
  export var focusStep = (_a = SiteSlice.actions, _a.focusStep), clearDependency = _a.clearDependency, setStepDependency = _a.setStepDependency, addStepsDependencies = _a.addStepsDependencies, setEmptyDependency = _a.setEmptyDependency, handlePrevious = _a.handlePrevious, handleNext = _a.handleNext, updateNestedValues = _a.updateNestedValues;
146
146
  export default SiteSlice;
147
- function addPagedValues(steps, values, original, path) {
147
+ export function addPagedValues(steps, values, original, path) {
148
148
  if (path === void 0) { path = ''; }
149
149
  for (var _i = 0, _a = Object.values(steps); _i < _a.length; _i++) {
150
150
  var step = _a[_i];
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.57",
4
+ "version": "2.0.59",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",