@arquimedes.co/eureka-forms 1.9.71-test → 1.9.73-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.
- package/dist/App.d.ts +1 -0
- package/dist/App.js +1 -0
- package/dist/FormComponents/Form/ColumnForm/ColumnForm.d.ts +2 -1
- package/dist/FormComponents/Form/ColumnForm/ColumnForm.js +17 -7
- package/dist/FormComponents/Step/MapperStep/MaterialMapperStep/MaterialMapperStep.d.ts +7 -0
- package/dist/FormComponents/Step/MapperStep/MaterialMapperStep/MaterialMapperStep.js +30 -13
- package/dist/FormComponents/Step/Step.js +3 -3
- package/package.json +1 -1
package/dist/App.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export interface CustomStep {
|
|
|
40
40
|
componentProps?: Record<string, any>;
|
|
41
41
|
component: ReactNode;
|
|
42
42
|
calcValue?: (step: any, value: any) => any;
|
|
43
|
+
calcDependencyValue?: (step: any, value: any) => any;
|
|
43
44
|
}
|
|
44
45
|
declare function App({ apiKey, domain, preview, partial, formData, postview, editable, isWidget, internal, valuesData, customSend, customSteps, classifiers, handleConfirmed, ...others }: AppProps): JSX.Element;
|
|
45
46
|
export default App;
|
package/dist/App.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { FormComponentProps } from '../Form';
|
|
3
|
+
import { CustomStep } from '../../../App';
|
|
3
4
|
import { FormStep } from '../../../@Types/FormStep';
|
|
4
5
|
declare function ColumnForm({ form, apiKey, reload, domain, postview, internal, formStyle, sendLabel, widthStats, customSteps, customSend, customSubmit, handleLoaded, originalValues, ...others }: FormComponentProps): JSX.Element;
|
|
5
6
|
export default ColumnForm;
|
|
6
|
-
export declare function calcStepDependencyValue(depStep: FormStep, originalValues: Record<string, any>): any;
|
|
7
|
+
export declare function calcStepDependencyValue(depStep: FormStep, originalValues: Record<string, any>, customSteps?: Record<string, CustomStep>): any;
|
|
@@ -74,7 +74,7 @@ function ColumnForm(_a) {
|
|
|
74
74
|
var _this = this;
|
|
75
75
|
var form = _a.form, apiKey = _a.apiKey, reload = _a.reload, domain = _a.domain, postview = _a.postview, internal = _a.internal, formStyle = _a.formStyle, sendLabel = _a.sendLabel, widthStats = _a.widthStats, customSteps = _a.customSteps, customSend = _a.customSend, customSubmit = _a.customSubmit, handleLoaded = _a.handleLoaded, originalValues = _a.originalValues, others = __rest(_a, ["form", "apiKey", "reload", "domain", "postview", "internal", "formStyle", "sendLabel", "widthStats", "customSteps", "customSend", "customSubmit", "handleLoaded", "originalValues"]);
|
|
76
76
|
var _b = useState(false), tempError = _b[0], setTempError = _b[1];
|
|
77
|
-
var _c = useState(calcDependencies(form.steps, originalValues)), dependencyStore = _c[0], setDependencyStore = _c[1];
|
|
77
|
+
var _c = useState(calcDependencies(form.steps, originalValues, customSteps)), dependencyStore = _c[0], setDependencyStore = _c[1];
|
|
78
78
|
var _d = useForm({
|
|
79
79
|
defaultValues: originalValues,
|
|
80
80
|
mode: 'onTouched',
|
|
@@ -272,6 +272,7 @@ var calcValue = function (idStep, steps, values, customSteps, deleteIds, value)
|
|
|
272
272
|
var element = elements_1[_i];
|
|
273
273
|
var newValue = {
|
|
274
274
|
id: element.id,
|
|
275
|
+
value: element.value,
|
|
275
276
|
};
|
|
276
277
|
for (var _c = 0, _d = Object.keys(step.steps); _c < _d.length; _c++) {
|
|
277
278
|
var idStep_1 = _d[_c];
|
|
@@ -311,8 +312,9 @@ function stringToDraft(text) {
|
|
|
311
312
|
});
|
|
312
313
|
return draftStructure;
|
|
313
314
|
}
|
|
314
|
-
function calcDependencies(steps, originalValues, allSteps, dependencies) {
|
|
315
|
+
function calcDependencies(steps, originalValues, customSteps, allSteps, dependencies) {
|
|
315
316
|
var _a, _b;
|
|
317
|
+
if (customSteps === void 0) { customSteps = {}; }
|
|
316
318
|
if (allSteps === void 0) { allSteps = steps; }
|
|
317
319
|
if (dependencies === void 0) { dependencies = {}; }
|
|
318
320
|
for (var _i = 0, _c = Object.values(steps); _i < _c.length; _i++) {
|
|
@@ -322,7 +324,7 @@ function calcDependencies(steps, originalValues, allSteps, dependencies) {
|
|
|
322
324
|
var idDep = _e[_d];
|
|
323
325
|
var depStep = allSteps[idDep];
|
|
324
326
|
if (depStep && dependencies[idDep] === undefined) {
|
|
325
|
-
dependencies[idDep] = calcStepDependencyValue(depStep, originalValues);
|
|
327
|
+
dependencies[idDep] = calcStepDependencyValue(depStep, customSteps, originalValues);
|
|
326
328
|
}
|
|
327
329
|
else if (dependencies[idDep] === undefined) {
|
|
328
330
|
dependencies[idDep] = originalValues[idDep];
|
|
@@ -347,13 +349,18 @@ function calcDependencies(steps, originalValues, allSteps, dependencies) {
|
|
|
347
349
|
if (elements.length === 0) {
|
|
348
350
|
newSteps = step.steps;
|
|
349
351
|
}
|
|
350
|
-
calcDependencies(newSteps, originalValues, __assign(__assign({}, allSteps), newSteps), dependencies);
|
|
352
|
+
calcDependencies(newSteps, originalValues, customSteps, __assign(__assign({}, allSteps), newSteps), dependencies);
|
|
351
353
|
}
|
|
352
354
|
}
|
|
353
355
|
return dependencies;
|
|
354
356
|
}
|
|
355
|
-
export function calcStepDependencyValue(depStep, originalValues) {
|
|
356
|
-
var _a, _b;
|
|
357
|
+
export function calcStepDependencyValue(depStep, originalValues, customSteps) {
|
|
358
|
+
var _a, _b, _c, _d;
|
|
359
|
+
if (customSteps === void 0) { customSteps = {}; }
|
|
360
|
+
var custom = customSteps[depStep === null || depStep === void 0 ? void 0 : depStep.type];
|
|
361
|
+
if (custom.calcDependencyValue) {
|
|
362
|
+
return custom.calcDependencyValue(depStep, originalValues[depStep.id]);
|
|
363
|
+
}
|
|
357
364
|
switch (depStep.type) {
|
|
358
365
|
case Types.TEXTAREA: {
|
|
359
366
|
if (depStep.hasTextEditor) {
|
|
@@ -363,7 +370,10 @@ export function calcStepDependencyValue(depStep, originalValues) {
|
|
|
363
370
|
return (_a = originalValues[depStep.id]) === null || _a === void 0 ? void 0 : _a.value;
|
|
364
371
|
}
|
|
365
372
|
}
|
|
373
|
+
case Types.MAPPER: {
|
|
374
|
+
return ((_c = (_b = originalValues[depStep.id]) === null || _b === void 0 ? void 0 : _b.map(function (mapperValue) { var _a; return (_a = mapperValue.value) !== null && _a !== void 0 ? _a : mapperValue; })) !== null && _c !== void 0 ? _c : null);
|
|
375
|
+
}
|
|
366
376
|
default:
|
|
367
|
-
return (
|
|
377
|
+
return (_d = originalValues[depStep.id]) !== null && _d !== void 0 ? _d : null;
|
|
368
378
|
}
|
|
369
379
|
}
|
|
@@ -4,6 +4,13 @@ export interface MapperElement {
|
|
|
4
4
|
ids: Record<string, string>;
|
|
5
5
|
id: string;
|
|
6
6
|
deleted?: boolean;
|
|
7
|
+
value?: any;
|
|
7
8
|
}
|
|
9
|
+
export declare function ElementsComponent({ step, form, inputRef, editable, postview, elements, formStyle, customAdd, dependencyStore, setDependencyStore, ...others }: MapperStepProps & {
|
|
10
|
+
onChange: (elements: MapperElement[]) => void;
|
|
11
|
+
elements: MapperElement[];
|
|
12
|
+
inputRef: any;
|
|
13
|
+
customAdd?: JSX.Element;
|
|
14
|
+
}): JSX.Element;
|
|
8
15
|
declare function MapperStep(props: MapperStepProps): JSX.Element;
|
|
9
16
|
export default MapperStep;
|
|
@@ -30,7 +30,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
30
30
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
31
31
|
};
|
|
32
32
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
33
|
-
import { useState, useEffect } from 'react';
|
|
33
|
+
import { useState, useEffect, cloneElement } from 'react';
|
|
34
34
|
import styles from './MaterialMapperStep.module.css';
|
|
35
35
|
import { Controller } from 'react-hook-form';
|
|
36
36
|
import StepTypes, { ClassifierOptionTypes, MapperStyleTypes, OptionTypes, } from '../../../../constants/FormStepTypes';
|
|
@@ -40,14 +40,20 @@ import { calcStepDependencyValue } from '../../../Form/ColumnForm/ColumnForm';
|
|
|
40
40
|
import MapperElementComponent from './Element/MapperElement';
|
|
41
41
|
import AYFFormStepTypes from '../../../../constants/AYFFormStepTypes';
|
|
42
42
|
import CBRFormStepTypes from '../../../../constants/CBRFormStepTypes';
|
|
43
|
-
function
|
|
44
|
-
var
|
|
45
|
-
var
|
|
43
|
+
export function ElementsComponent(_a) {
|
|
44
|
+
var _b, _c;
|
|
45
|
+
var step = _a.step, form = _a.form, inputRef = _a.inputRef, editable = _a.editable, postview = _a.postview, elements = _a.elements, formStyle = _a.formStyle, customAdd = _a.customAdd, dependencyStore = _a.dependencyStore, setDependencyStore = _a.setDependencyStore, others = __rest(_a, ["step", "form", "inputRef", "editable", "postview", "elements", "formStyle", "customAdd", "dependencyStore", "setDependencyStore"]);
|
|
46
|
+
var _d = useState(true), firstRender = _d[0], setFirstRender = _d[1];
|
|
46
47
|
/** Mapper Steps to pass down */
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
var _e = useState(), localSteps = _e[0], setLocalSteps = _e[1];
|
|
49
|
+
var onChange = function (elements) {
|
|
50
|
+
var _a;
|
|
51
|
+
var _b;
|
|
52
|
+
if (dependencyStore[step.id] !== undefined && customAdd) {
|
|
53
|
+
setDependencyStore(__assign(__assign({}, dependencyStore), (_a = {}, _a[step.id] = (_b = elements.map(function (element) { return element.value; })) !== null && _b !== void 0 ? _b : null, _a)));
|
|
54
|
+
}
|
|
55
|
+
others.onChange(elements);
|
|
56
|
+
};
|
|
51
57
|
useEffect(function () {
|
|
52
58
|
var _a;
|
|
53
59
|
if (firstRender) {
|
|
@@ -73,13 +79,18 @@ function Elements(_a) {
|
|
|
73
79
|
else if (elements.length === 0 && !postview && editable) {
|
|
74
80
|
handleAddElement();
|
|
75
81
|
}
|
|
82
|
+
setFirstRender(false);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
onChange([]);
|
|
76
86
|
}
|
|
77
|
-
}, [
|
|
78
|
-
var handleAddElement = function () {
|
|
87
|
+
}, __spreadArray([], ((_c = (_b = step.dependencies) === null || _b === void 0 ? void 0 : _b.map(function (dep) { return dependencyStore[dep]; })) !== null && _c !== void 0 ? _c : []), true));
|
|
88
|
+
var handleAddElement = function (value) {
|
|
79
89
|
var idElement = nanoid();
|
|
80
90
|
var newElement = {
|
|
81
91
|
ids: {},
|
|
82
92
|
id: idElement,
|
|
93
|
+
value: value,
|
|
83
94
|
};
|
|
84
95
|
var newSteps = {};
|
|
85
96
|
for (var _i = 0, _a = Object.keys(step.steps); _i < _a.length; _i++) {
|
|
@@ -116,11 +127,17 @@ function Elements(_a) {
|
|
|
116
127
|
var tempElements = __spreadArray([], elements, true);
|
|
117
128
|
tempElements[index].deleted = true;
|
|
118
129
|
onChange(tempElements);
|
|
119
|
-
} }, others), element.id)); }), _jsxs("div", __assign({ className: styles.btnContainer }, { children: [_jsx("input", { ref:
|
|
130
|
+
} }, others), element.id)); }), _jsxs("div", __assign({ className: styles.btnContainer }, { children: [_jsx("input", { ref: inputRef, className: styles.hiddenInput }), step.creatable !== false && !customAdd && (_jsx(RoundedButton, { disabled: !editable || postview, text: step.addBtnLabel, color: formStyle.primaryContrastColor, backgroundColor: formStyle.primaryColor, fontSize: '1rem', padding: '5px 15px 5px 15px', onClick: function () {
|
|
120
131
|
if (editable && !postview) {
|
|
121
132
|
handleAddElement();
|
|
122
133
|
}
|
|
123
|
-
} }))
|
|
134
|
+
} })), step.creatable !== false &&
|
|
135
|
+
customAdd &&
|
|
136
|
+
cloneElement(customAdd, {
|
|
137
|
+
inputRef: inputRef,
|
|
138
|
+
disabled: !editable || postview,
|
|
139
|
+
handleAddElement: handleAddElement,
|
|
140
|
+
})] }))] })));
|
|
124
141
|
}
|
|
125
142
|
function MapperStep(props) {
|
|
126
143
|
return (_jsx(Controller, { name: props.step.id, control: props.control, defaultValue: [], rules: {
|
|
@@ -129,7 +146,7 @@ function MapperStep(props) {
|
|
|
129
146
|
: undefined,
|
|
130
147
|
}, shouldUnregister: true, render: function (_a) {
|
|
131
148
|
var _b = _a.field, ref = _b.ref, value = _b.value, field = __rest(_b, ["ref", "value"]);
|
|
132
|
-
return (_jsx(
|
|
149
|
+
return (_jsx(ElementsComponent, __assign({}, props, field, { elements: value, inputRef: ref })));
|
|
133
150
|
} }));
|
|
134
151
|
}
|
|
135
152
|
export default MapperStep;
|
|
@@ -46,14 +46,14 @@ function StepComponent(_a) {
|
|
|
46
46
|
}
|
|
47
47
|
var customStep = props.customSteps[step.type];
|
|
48
48
|
var editable = props.globalEditable ? (_b = step.editable) !== null && _b !== void 0 ? _b : true : false;
|
|
49
|
-
if (customStep) {
|
|
50
|
-
return customStep.component(__assign(__assign(__assign({}, props), ((_c = customStep.componentProps) !== null && _c !== void 0 ? _c : {})), { step: step, editable: editable }));
|
|
51
|
-
}
|
|
52
49
|
if ((props.postview || !editable) &&
|
|
53
50
|
(props.partial || step.partial) &&
|
|
54
51
|
props.originalValues[step.id] === undefined) {
|
|
55
52
|
return _jsx("div", {});
|
|
56
53
|
}
|
|
54
|
+
if (customStep) {
|
|
55
|
+
return customStep.component(__assign(__assign(__assign({}, props), ((_c = customStep.componentProps) !== null && _c !== void 0 ? _c : {})), { step: step, editable: editable }));
|
|
56
|
+
}
|
|
57
57
|
switch (step.type) {
|
|
58
58
|
case Types.TITLE: {
|
|
59
59
|
return (_jsx(TitleStep, __assign({}, props, { step: step, editable: editable })));
|
package/package.json
CHANGED