@arquimedes.co/eureka-forms 2.0.17 → 2.0.19-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.
Files changed (56) hide show
  1. package/dist/@Types/Form.d.ts +1 -0
  2. package/dist/@Types/FormStep.d.ts +1 -0
  3. package/dist/App/AppFunctions.js +11 -11
  4. package/dist/Form/Section/MaterialSection/MaterialSection.js +1 -1
  5. package/dist/Form/Terms/Term/MaterialTerm/MaterialTerm.js +9 -1
  6. package/dist/FormSteps/@Construction/CBRElementStep/CBRElementStep.js +2 -2
  7. package/dist/FormSteps/@Construction/CBRIncidentsStep/MaterialCBRIncidentsStep/Incident/Incident.d.ts +1 -1
  8. package/dist/FormSteps/@Construction/CBRIncidentsStep/MaterialCBRIncidentsStep/Incident/Incident.js +2 -2
  9. package/dist/FormSteps/@Construction/CBRIncidentsStep/MaterialCBRIncidentsStep/MaterialCBRIncidentsStep.js +13 -13
  10. package/dist/FormSteps/ApiSelectorStep/MaterialApiSelectorStep/MaterialApiSelectorStep.d.ts +2 -2
  11. package/dist/FormSteps/ApiSelectorStep/MaterialApiSelectorStep/MaterialApiSelectorStep.js +20 -63
  12. package/dist/FormSteps/ApiSelectorStep/MaterialApiSelectorStep/MaterialApiSelectorStep.module.css +0 -16
  13. package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.d.ts +1 -1
  14. package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.js +21 -76
  15. package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.module.css +0 -28
  16. package/dist/FormSteps/ClassifierSelectorStep/MaterialClassifierSelectorStep/MaterialClassifierSelectorStep.d.ts +1 -1
  17. package/dist/FormSteps/ClassifierSelectorStep/MaterialClassifierSelectorStep/MaterialClassifierSelectorStep.js +39 -96
  18. package/dist/FormSteps/CollapsibleStep/MaterialTitleStep/MaterialCollapsibleStep.js +2 -2
  19. package/dist/FormSteps/DatePickerStep/MaterialDatePickerStep/MaterialDatePickerStep.js +7 -38
  20. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.d.ts +1 -1
  21. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +20 -74
  22. package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/MaterialFileUploadStep.d.ts +2 -2
  23. package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/MaterialFileUploadStep.js +18 -42
  24. package/dist/FormSteps/MapperStep/MaterialMapperStep/Element/MapperElementComponent.js +2 -2
  25. package/dist/FormSteps/MapperStep/MaterialMapperStep/MaterialMapperStep.js +9 -5
  26. package/dist/FormSteps/RatingStep/MaterialRatingStep/MaterialRatingStep.d.ts +1 -1
  27. package/dist/FormSteps/RatingStep/MaterialRatingStep/MaterialRatingStep.js +15 -43
  28. package/dist/FormSteps/SelectorStep/MaterialSelectorStep/MaterialSelectorStep.d.ts +2 -2
  29. package/dist/FormSteps/SelectorStep/MaterialSelectorStep/MaterialSelectorStep.js +22 -78
  30. package/dist/FormSteps/SelectorStep/MaterialSelectorStep/MaterialSelectorStep.module.css +0 -16
  31. package/dist/FormSteps/SmartSelectStep/MaterialSmartSelectStep/MaterialSmartSelectStep.d.ts +1 -9
  32. package/dist/FormSteps/SmartSelectStep/MaterialSmartSelectStep/MaterialSmartSelectStep.js +26 -57
  33. package/dist/FormSteps/Step.d.ts +0 -2
  34. package/dist/FormSteps/StepFunctions.d.ts +2 -1
  35. package/dist/FormSteps/StepFunctions.js +70 -63
  36. package/dist/FormSteps/StepHooks.d.ts +16 -0
  37. package/dist/FormSteps/StepHooks.js +58 -2
  38. package/dist/FormSteps/TextAreaStep/MaterialTextAreaStep/MaterialTextAreaEditorStep.js +1 -1
  39. package/dist/FormSteps/TextAreaStep/MaterialTextAreaStep/MaterialTextAreaStep.js +6 -37
  40. package/dist/FormSteps/TextInputStep/MaterialTextInputStep/MaterialTextInputStep.js +13 -39
  41. package/dist/FormSteps/TitleStep/MaterialTitleStep/MaterialTitleStep.d.ts +1 -1
  42. package/dist/FormSteps/TitleStep/MaterialTitleStep/MaterialTitleStep.js +4 -24
  43. package/dist/FormSteps/Utils/@StepFiller/StepFiller.d.ts +9 -0
  44. package/dist/FormSteps/Utils/@StepFiller/StepFiller.js +48 -0
  45. package/dist/FormSteps/{EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.module.css → Utils/@StepFiller/StepFiller.module.css} +16 -16
  46. package/dist/FormSteps/Utils/MaterialInputContainer/MaterialInputContainer.d.ts +11 -0
  47. package/dist/FormSteps/Utils/MaterialInputContainer/MaterialInputContainer.js +32 -0
  48. package/dist/FormSteps/{DatePickerStep/MaterialDatePickerStep/MaterialDatePickerStep.module.css → Utils/MaterialInputContainer/MaterialInputContainer.module.css} +9 -9
  49. package/dist/Shared/RoundedCheckBox/RoundedCheckBox.d.ts +3 -3
  50. package/dist/Shared/RoundedSmartSelect/RoundedSmartSelect.d.ts +1 -4
  51. package/dist/Shared/RoundedSmartSelect/RoundedSmartSelect.js +1 -3
  52. package/dist/States/SiteSlice.d.ts +2 -1
  53. package/dist/States/SiteSlice.js +25 -6
  54. package/package.json +1 -1
  55. package/dist/FormSteps/ClassifierSelectorStep/MaterialClassifierSelectorStep/MaterialClassifierSelectorStep.module.css +0 -25
  56. package/dist/FormSteps/SmartSelectStep/MaterialSmartSelectStep/MaterialSmartSelectStep.module.css +0 -9
@@ -9,34 +9,26 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- var __rest = (this && this.__rest) || function (s, e) {
13
- var t = {};
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
- t[p] = s[p];
16
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
- t[p[i]] = s[p[i]];
20
- }
21
- return t;
22
- };
23
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
13
  import styles from './MaterialRatingStep.module.css';
25
- import { useController, useFormContext } from 'react-hook-form';
26
- import React, { useCallback, useContext } from 'react';
14
+ import React, { useContext } from 'react';
27
15
  import Rating from '../../../Shared/Rating/Rating';
28
16
  import { RatingTypes } from '../../../constants/FormStepTypes';
29
17
  import StepComponent from '../../Step';
30
18
  import FormContext from '../../../Contexts/FormContext';
31
19
  import { useAppSelector } from '../../../hooks';
32
- import { useStepDependency } from '../../StepHooks';
33
- function MaterialRatingStep(_a) {
34
- var _b, _c, _d, _e, _f;
35
- var step = _a.step, value = _a.value, level = _a.level, onChange = _a.onChange, inputRef = _a.inputRef, editable = _a.editable;
20
+ import { useFormStep } from '../../StepHooks';
21
+ function RatingStep(_a) {
22
+ var _b, _c, _d, _e;
23
+ var step = _a.step, editable = _a.editable;
24
+ var _f = useFormStep(step, {
25
+ rules: {
26
+ required: step.required ? 'Este campo es obligatorio' : undefined,
27
+ },
28
+ }), ref = _f.ref, value = _f.value, onChange = _f.onChange, error = _f.error;
36
29
  var _g = useAppSelector(function (state) { return state.global; }), formStyle = _g.formStyle, postview = _g.postview;
37
30
  var form = useContext(FormContext);
38
31
  var widthStats = useAppSelector(function (state) { return state.widthStats; });
39
- var errors = useFormContext().formState.errors;
40
32
  var renderNestedOption = function () {
41
33
  var currentOption;
42
34
  if (value !== undefined && value !== null && step.nestedSteps) {
@@ -49,39 +41,19 @@ function MaterialRatingStep(_a) {
49
41
  if (currentOption && currentOption.length > 0) {
50
42
  return (_jsx(React.Fragment, { children: currentOption.map(function (idSubStep) {
51
43
  var subStep = form.steps[idSubStep];
52
- return (_jsx(StepComponent, { editable: editable, step: subStep, level: level + 1 }, idSubStep));
44
+ return (_jsx(StepComponent, { editable: editable, step: subStep }, idSubStep));
53
45
  }) }));
54
46
  }
55
47
  }
56
48
  };
57
49
  return (_jsxs(React.Fragment, { children: [_jsxs("div", __assign({ className: styles.container, style: {
58
50
  paddingBottom: step.description || step.required ? 0 : 15,
59
- } }, { children: [_jsx("div", __assign({ className: styles.labelLabel }, { children: step.label + (step.required ? ' *' : '') })), _jsx("div", __assign({ className: styles.ratingContainer }, { children: _jsx(Rating, { name: step.id, type: step.ratingType, isMobile: widthStats.isMobile, focusColor: (_b = formStyle.primaryColor) !== null && _b !== void 0 ? _b : '#3d5a7f', unSelectedColor: (_c = formStyle.outlineColor) !== null && _c !== void 0 ? _c : '#b8b8b8', disabled: !editable || postview, value: value, onChange: onChange, inputRef: inputRef }) })), (step.description || step.required) && (_jsx("div", __assign({ className: styles.stepDescriptionLabel, style: {
60
- color: !!errors[step.id] && value === null
51
+ } }, { children: [_jsx("div", __assign({ className: styles.labelLabel }, { children: step.label + (step.required ? ' *' : '') })), _jsx("div", __assign({ className: styles.ratingContainer }, { children: _jsx(Rating, { name: step.id, type: step.ratingType, isMobile: widthStats.isMobile, focusColor: (_b = formStyle.primaryColor) !== null && _b !== void 0 ? _b : '#3d5a7f', unSelectedColor: (_c = formStyle.outlineColor) !== null && _c !== void 0 ? _c : '#b8b8b8', disabled: !editable || postview, value: value, onChange: onChange, inputRef: ref }) })), (step.description || step.required) && (_jsx("div", __assign({ className: styles.stepDescriptionLabel, style: {
52
+ color: !!error && value === null
61
53
  ? (_d = formStyle.errorColor) !== null && _d !== void 0 ? _d : '#cc2936'
62
54
  : (_e = formStyle.descriptionTextColor) !== null && _e !== void 0 ? _e : '#989898',
63
- } }, { children: !!errors[step.id] && value === null
64
- ? (_f = errors[step.id]) === null || _f === void 0 ? void 0 : _f.message
55
+ } }, { children: !!error && value === null
56
+ ? error === null || error === void 0 ? void 0 : error.message
65
57
  : step.description })))] })), renderNestedOption()] }));
66
58
  }
67
- function RatingStep(props) {
68
- var step = props.step;
69
- var _a = useStepDependency(step), handleStepDep = _a.handleStepDep, originalValue = _a.originalValue;
70
- var _b = useController({
71
- name: step.id,
72
- shouldUnregister: true,
73
- rules: {
74
- required: step.required ? 'Este campo es obligatorio' : undefined,
75
- },
76
- defaultValue: originalValue,
77
- }).field, ref = _b.ref, field = __rest(_b, ["ref"]);
78
- var onChange = useCallback(function (value) {
79
- handleStepDep(value);
80
- field.onChange(value);
81
- }, [handleStepDep, field]);
82
- return (_jsx(MaterialRatingStep, __assign({}, props, field, { inputRef: ref, onChange: function (value) {
83
- handleStepDep(value);
84
- onChange(value);
85
- } })));
86
- }
87
59
  export default RatingStep;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { SelectorStepProps } from '../SelectorStep';
3
- declare function SelectorStep(props: SelectorStepProps): JSX.Element;
4
- export default SelectorStep;
3
+ declare function SelectorStepContainer(props: SelectorStepProps): JSX.Element;
4
+ export default SelectorStepContainer;
@@ -9,59 +9,27 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- var __rest = (this && this.__rest) || function (s, e) {
13
- var t = {};
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
- t[p] = s[p];
16
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
- t[p[i]] = s[p[i]];
20
- }
21
- return t;
22
- };
23
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
- import React, { useCallback, useContext, useState } from 'react';
13
+ import React, { useContext } from 'react';
25
14
  import { OptionTypes } from '../../../constants/FormStepTypes';
26
- import styles from './MaterialSelectorStep.module.css';
27
15
  import StepComponent from '../../Step';
28
- import { calcFillerSize, calcStepWidth } from '../../StepFunctions';
29
- import { useController, useFormContext } from 'react-hook-form';
30
16
  import RoundedSmartSelect from '../../../Shared/RoundedSmartSelect/RoundedSmartSelect';
31
17
  import FormContext from '../../../Contexts/FormContext';
32
- import { selectBreakPoint, useAppSelector } from '../../../hooks';
33
- import { useStepDependency } from '../../StepHooks';
34
- function Selector(_a) {
35
- var step = _a.step, value = _a.value, level = _a.level, onBlur = _a.onBlur, editable = _a.editable, onChange = _a.onChange, handleSizeChange = _a.handleSizeChange, inputRef = _a.inputRef;
18
+ import { useAppSelector } from '../../../hooks';
19
+ import { useFormStep } from '../../StepHooks';
20
+ import StepFillerContainer from '../../Utils/@StepFiller/StepFiller';
21
+ import MaterialInputContainer from '../../Utils/MaterialInputContainer/MaterialInputContainer';
22
+ function SelectorStep(_a) {
23
+ var _b, _c, _d;
24
+ var step = _a.step, editable = _a.editable;
25
+ var _e = useFormStep(step, {
26
+ rules: {
27
+ required: step.required ? 'Este campo es obligatorio' : undefined,
28
+ },
29
+ sizeChange: true,
30
+ }), ref = _e.ref, value = _e.value, onChange = _e.onChange, error = _e.error, field = _e.field;
36
31
  var form = useContext(FormContext);
37
- var _b = useAppSelector(function (state) { return state.global; }), postview = _b.postview, formStyle = _b.formStyle;
38
- var currentBreakPoint = useAppSelector(selectBreakPoint);
39
- var _c = useFormContext(), getValues = _c.getValues, errors = _c.formState.errors;
40
- var _d = useState(level === 0
41
- ? calcFillerSize(step, form.steps, getValues(), form.size)
42
- : 0), fillerSize = _d[0], setFillerSize = _d[1];
43
- var sizeChange = function () {
44
- handleSizeChange === null || handleSizeChange === void 0 ? void 0 : handleSizeChange();
45
- if (level === 0) {
46
- setFillerSize(calcFillerSize(step, form.steps, getValues(), form.size));
47
- }
48
- };
49
- var renderSelect = function () {
50
- var _a, _b, _c, _d;
51
- return (_jsx("div", __assign({ className: styles.container, style: {
52
- width: currentBreakPoint <= step.size
53
- ? '100%'
54
- : calcStepWidth(step.size, form.size),
55
- minHeight: step.description ||
56
- (!postview && editable && step.required)
57
- ? '55px'
58
- : '43px',
59
- } }, { children: _jsx(RoundedSmartSelect, { value: value, onBlur: onBlur, disabled: false, loading: false, options: step.options, inputRef: inputRef, cantEdit: !editable || postview, fullWidth: true, backgroundColor: (_a = formStyle.stepBackgroundColor) !== null && _a !== void 0 ? _a : 'white', label: step.label, required: step.required, height: '31px', searchable: step.searchable, icon: undefined, helperTextColor: formStyle.descriptionTextColor, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, errorColor: formStyle.errorColor, color: formStyle.textColor, containerMargin: "0px", handleUpdate: function (value) {
60
- onChange(value);
61
- }, getOptionSelected: function (option, value) {
62
- return (option === null || option === void 0 ? void 0 : option.value) === (value === null || value === void 0 ? void 0 : value.value);
63
- }, helperText: (_d = (_c = (_b = errors[step.id]) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : step.description, error: !!errors[step.id] }) })));
64
- };
32
+ var _f = useAppSelector(function (state) { return state.global; }), postview = _f.postview, formStyle = _f.formStyle;
65
33
  var mapNestedOption = function () {
66
34
  var currentOptionIndex = null;
67
35
  var currentOption = null;
@@ -76,39 +44,15 @@ function Selector(_a) {
76
44
  currentOptionIndex !== null) {
77
45
  return (_jsx(React.Fragment, { children: currentOption.steps.map(function (idSubStep) {
78
46
  var subStep = form.steps[idSubStep];
79
- return (_jsx(StepComponent, { editable: editable, step: subStep, level: level + 1, handleSizeChange: sizeChange }, idSubStep));
47
+ return (_jsx(StepComponent, { editable: editable, step: subStep }, idSubStep));
80
48
  }) }));
81
49
  }
82
50
  };
83
- if (level === 0 && step.maxSize && step.maxSize < form.size.blockNum) {
84
- return (_jsxs("div", __assign({ className: styles.firstLvlContainer, style: {
85
- width: currentBreakPoint <= step.size ? '100%' : 'fit-content',
86
- } }, { children: [renderSelect(), mapNestedOption(), level === 0 && step.maxSize < form.size.blockNum && (_jsx("div", { className: styles.smallSeparator, style: {
87
- width: fillerSize,
88
- } }))] })));
89
- }
90
- else {
91
- return (_jsxs(React.Fragment, { children: [renderSelect(), mapNestedOption(), level === 0 && step.maxSize && (_jsx("div", { className: styles.separator }))] }));
92
- }
51
+ return (_jsxs(React.Fragment, { children: [_jsx(MaterialInputContainer, __assign({ step: step, editable: editable }, { children: _jsx(RoundedSmartSelect, __assign({}, field, { value: value, inputRef: ref, handleUpdate: onChange, disabled: false, loading: false, options: step.options, cantEdit: !editable || postview, fullWidth: true, backgroundColor: (_b = formStyle.stepBackgroundColor) !== null && _b !== void 0 ? _b : 'white', label: step.label, required: step.required, height: '31px', searchable: step.searchable, icon: undefined, helperTextColor: formStyle.descriptionTextColor, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, errorColor: formStyle.errorColor, color: formStyle.textColor, containerMargin: "0px", getOptionSelected: function (option, value) {
52
+ return (option === null || option === void 0 ? void 0 : option.value) === (value === null || value === void 0 ? void 0 : value.value);
53
+ }, helperText: (_d = (_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : step.description, error: !!error })) })), value && mapNestedOption()] }));
93
54
  }
94
- function SelectorStep(props) {
95
- var step = props.step;
96
- var _a = useStepDependency(step), handleStepDep = _a.handleStepDep, originalValue = _a.originalValue;
97
- var _b = useController({
98
- name: step.id,
99
- rules: {
100
- required: step.required ? 'Este campo es obligatorio' : undefined,
101
- },
102
- shouldUnregister: true,
103
- defaultValue: originalValue,
104
- }).field, ref = _b.ref, field = __rest(_b, ["ref"]);
105
- var onChange = useCallback(function (value) {
106
- handleStepDep(value);
107
- field.onChange(value);
108
- }, [handleStepDep, field]);
109
- return (_jsx(Selector, __assign({}, props, field, { inputRef: ref, onChange: function (value) {
110
- handleStepDep(value);
111
- onChange(value);
112
- } })));
55
+ function SelectorStepContainer(props) {
56
+ return (_jsx(StepFillerContainer, __assign({ step: props.step }, { children: _jsx(SelectorStep, __assign({}, props)) })));
113
57
  }
114
- export default SelectorStep;
58
+ export default SelectorStepContainer;
@@ -7,19 +7,3 @@
7
7
  padding-top: 5px;
8
8
  margin-bottom: 0px;
9
9
  }
10
- .separator {
11
- flex-basis: 100%;
12
- height: 0;
13
- }
14
-
15
- .firstLvlContainer {
16
- max-width: 100%;
17
- display: flex;
18
- flex-flow: row wrap;
19
- }
20
-
21
- .smallSeparator {
22
- height: 0;
23
- max-width: 100%;
24
- flex-basis: 0;
25
- }
@@ -1,13 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { FieldError } from 'react-hook-form';
3
2
  import { SmartSelectStepProps } from '../SmartSelectStep';
4
3
  import { GSmartSelect } from '../../../@Types/GenericFormSteps';
5
- export declare function SmartSelect<StepType extends GSmartSelect>({ icon, step, value, error, onBlur, editable, onChange, inputRef, getOptions, calcDepError, valueOverwrite, getValueString, changeListener, getValueWarning, getOptionSelected, renderNestedSteps, }: SmartSelectStepProps<StepType> & {
6
- error: FieldError | undefined;
7
- onChange: any;
8
- onBlur: (event: any) => void;
9
- value: any;
10
- inputRef: any;
11
- }): JSX.Element;
12
- declare function SmartSelectStep(props: SmartSelectStepProps): JSX.Element;
4
+ declare function SmartSelectStep<StepType extends GSmartSelect>({ icon, step, editable, getOptions, calcDepError, defaultValue, valueOverwrite, getValueString, changeListener, getValueWarning, getOptionSelected, renderNestedSteps, }: SmartSelectStepProps<StepType>): JSX.Element;
13
5
  export default SmartSelectStep;
@@ -45,45 +45,42 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
- var __rest = (this && this.__rest) || function (s, e) {
49
- var t = {};
50
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
- t[p] = s[p];
52
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
- t[p[i]] = s[p[i]];
56
- }
57
- return t;
58
- };
59
48
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
60
- import styles from './MaterialSmartSelectStep.module.css';
61
- import { useController, useFormContext } from 'react-hook-form';
62
- import { calcStepWidth } from '../../StepFunctions';
49
+ import { useFormContext } from 'react-hook-form';
63
50
  import RoundedSmartSelect from '../../../Shared/RoundedSmartSelect/RoundedSmartSelect';
64
51
  import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
65
52
  import React from 'react';
66
53
  import FormContext from '../../../Contexts/FormContext';
67
- import { selectBreakPoint, useAppDispatch, useAppSelector, } from '../../../hooks';
54
+ import { useAppDispatch, useAppSelector } from '../../../hooks';
68
55
  import { focusStep, setEmptyDependency } from '../../../States/SiteSlice';
69
- import { selectDependencies, useStepDependency } from '../../StepHooks';
70
- export function SmartSelect(_a) {
56
+ import { selectDependencies, useFormStep } from '../../StepHooks';
57
+ import MaterialInputContainer from '../../Utils/MaterialInputContainer/MaterialInputContainer';
58
+ function SmartSelectStep(_a) {
71
59
  var _this = this;
72
60
  var _b, _c, _d, _e, _f, _g, _h;
73
- var icon = _a.icon, step = _a.step, value = _a.value, error = _a.error, onBlur = _a.onBlur, editable = _a.editable, onChange = _a.onChange, inputRef = _a.inputRef, getOptions = _a.getOptions, calcDepError = _a.calcDepError, valueOverwrite = _a.valueOverwrite, getValueString = _a.getValueString, changeListener = _a.changeListener, getValueWarning = _a.getValueWarning, getOptionSelected = _a.getOptionSelected, renderNestedSteps = _a.renderNestedSteps;
74
- var _j = useAppSelector(function (state) { return state.global; }), postview = _j.postview, formStyle = _j.formStyle, idOrganization = _j.idOrganization;
61
+ var icon = _a.icon, step = _a.step, editable = _a.editable, getOptions = _a.getOptions, calcDepError = _a.calcDepError, defaultValue = _a.defaultValue, valueOverwrite = _a.valueOverwrite, getValueString = _a.getValueString, changeListener = _a.changeListener, getValueWarning = _a.getValueWarning, getOptionSelected = _a.getOptionSelected, renderNestedSteps = _a.renderNestedSteps;
62
+ var _j = useFormStep(step, {
63
+ sizeChange: true,
64
+ defaultValue: defaultValue,
65
+ rules: {
66
+ required: step.required ? 'Este campo es obligatorio' : undefined,
67
+ },
68
+ }), ref = _j.ref, value = _j.value, error = _j.error, field = _j.field, handleChange = _j.onChange;
69
+ var onChange = useCallback(function (value) {
70
+ return handleChange(valueOverwrite ? valueOverwrite(value) : value);
71
+ }, [handleChange, valueOverwrite]);
72
+ var _k = useAppSelector(function (state) { return state.global; }), postview = _k.postview, formStyle = _k.formStyle, idOrganization = _k.idOrganization;
75
73
  var form = useContext(FormContext);
76
- var currentBreakPoint = useAppSelector(selectBreakPoint);
77
- var _k = useState(), options = _k[0], setOptions = _k[1];
78
- var _l = useState(false), loading = _l[0], setLoading = _l[1];
79
- var _m = useState(true), firstTime = _m[0], setFirstTime = _m[1];
80
- var _o = useState(false), touched = _o[0], setTouched = _o[1];
74
+ var _l = useState(), options = _l[0], setOptions = _l[1];
75
+ var _m = useState(false), loading = _m[0], setLoading = _m[1];
76
+ var _o = useState(true), firstTime = _o[0], setFirstTime = _o[1];
77
+ var _p = useState(false), touched = _p[0], setTouched = _p[1];
81
78
  var dispatch = useAppDispatch();
82
79
  var dependencyStore = useAppSelector(function (state) { return state.site.dependencies; });
83
- var _p = useAppSelector(function (state) {
80
+ var _q = useAppSelector(function (state) {
84
81
  return selectDependencies(state, step, form);
85
- }), emptyDep = _p.emptyDep, invalids = _p.invalids;
86
- var _q = useFormContext(), getValues = _q.getValues, setFocus = _q.setFocus;
82
+ }), emptyDep = _q.emptyDep, invalids = _q.invalids;
83
+ var _r = useFormContext(), getValues = _r.getValues, setFocus = _r.setFocus;
87
84
  var isEmpty = useAppSelector(function (state) { var _a; return (_a = state.site.dependencies[step.id]) === null || _a === void 0 ? void 0 : _a.empty; });
88
85
  var disabled = emptyDep;
89
86
  useEffect(function () {
@@ -118,7 +115,7 @@ export function SmartSelect(_a) {
118
115
  return getValueString(option) === getValueString(value);
119
116
  });
120
117
  if (!firstTime)
121
- onChange(newValue);
118
+ onChange(newValue !== null && newValue !== void 0 ? newValue : null);
122
119
  }
123
120
  else if (!firstTime)
124
121
  onChange(null);
@@ -174,9 +171,6 @@ export function SmartSelect(_a) {
174
171
  if (!touched)
175
172
  setTouched(true);
176
173
  }, [options, disabled, postview, editable, invalids, touched]);
177
- var handleUpdate = useCallback(function (value) {
178
- valueOverwrite ? onChange(valueOverwrite(value)) : onChange(value);
179
- }, [valueOverwrite, onChange]);
180
174
  var errorMsg = useMemo(function () {
181
175
  if (postview || loading)
182
176
  return undefined;
@@ -196,31 +190,6 @@ export function SmartSelect(_a) {
196
190
  }
197
191
  return undefined;
198
192
  }, [invalids, touched, value, options]);
199
- return (_jsxs(React.Fragment, { children: [_jsx("div", __assign({ className: styles.container, style: {
200
- width: currentBreakPoint <= step.size
201
- ? '100%'
202
- : calcStepWidth(step.size, form.size),
203
- minHeight: step.description ||
204
- (!postview && editable && step.required)
205
- ? '55px'
206
- : '43px',
207
- }, onClick: onFocus, "data-testid": step.id }, { children: _jsx(RoundedSmartSelect, { value: value, onBlur: onBlur, onFocus: onFocus, disabled: options === null || disabled, hidden: disabled, loading: loading, options: options !== null && options !== void 0 ? options : undefined, inputRef: inputRef, cantEdit: !editable || postview, fullWidth: true, backgroundColor: (_d = formStyle.stepBackgroundColor) !== null && _d !== void 0 ? _d : 'white', label: step.label, required: step.required, height: '31px', changeListener: changeListener, searchable: step.searchable, icon: step.showIcon ? icon : undefined, helperTextColor: formStyle.descriptionTextColor, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, errorColor: formStyle.errorColor, color: formStyle.textColor, containerMargin: "0px", handleUpdate: handleUpdate, getOptionSelected: getOptionSelected, getValueString: getValueString, helperText: (_h = (_g = (_e = errorMsg !== null && errorMsg !== void 0 ? errorMsg : warning) !== null && _e !== void 0 ? _e : (_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toString()) !== null && _g !== void 0 ? _g : step.description) !== null && _h !== void 0 ? _h : undefined, error: !!errorMsg || !!warning || !!error }) })), renderNestedSteps === null || renderNestedSteps === void 0 ? void 0 : renderNestedSteps(value)] }));
208
- }
209
- function SmartSelectStep(props) {
210
- var step = props.step, defaultValue = props.defaultValue;
211
- var _a = useStepDependency(step, defaultValue), handleStepDep = _a.handleStepDep, originalValue = _a.originalValue;
212
- var _b = useController({
213
- name: step.id,
214
- shouldUnregister: true,
215
- rules: {
216
- required: step.required ? 'Este campo es obligatorio' : undefined,
217
- },
218
- defaultValue: originalValue,
219
- }), _c = _b.field, ref = _c.ref, field = __rest(_c, ["ref"]), error = _b.fieldState.error;
220
- var onChange = useCallback(function (value) {
221
- handleStepDep(value);
222
- field.onChange(value);
223
- }, [handleStepDep, field]);
224
- return (_jsx(SmartSelect, __assign({}, props, field, { error: error, inputRef: ref, onChange: onChange })));
193
+ return (_jsxs(React.Fragment, { children: [_jsx(MaterialInputContainer, __assign({ step: step, onClick: onFocus, editable: editable }, { children: _jsx(RoundedSmartSelect, __assign({}, field, { inputRef: ref, value: value, handleUpdate: onChange, onFocus: onFocus, disabled: options === null || disabled, hidden: disabled, loading: loading, options: options !== null && options !== void 0 ? options : undefined, cantEdit: !editable || postview, fullWidth: true, backgroundColor: (_d = formStyle.stepBackgroundColor) !== null && _d !== void 0 ? _d : 'white', label: step.label, required: step.required, height: '31px', changeListener: changeListener, searchable: step.searchable, icon: step.showIcon ? icon : undefined, helperTextColor: formStyle.descriptionTextColor, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, errorColor: formStyle.errorColor, color: formStyle.textColor, containerMargin: "0px", getOptionSelected: getOptionSelected, getValueString: getValueString, helperText: (_h = (_g = (_e = errorMsg !== null && errorMsg !== void 0 ? errorMsg : warning) !== null && _e !== void 0 ? _e : (_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toString()) !== null && _g !== void 0 ? _g : step.description) !== null && _h !== void 0 ? _h : undefined, error: !!errorMsg || !!warning || !!error })) })), renderNestedSteps === null || renderNestedSteps === void 0 ? void 0 : renderNestedSteps(value)] }));
225
194
  }
226
195
  export default SmartSelectStep;
@@ -3,8 +3,6 @@ import { FormStep } from '../@Types/FormStep';
3
3
  export interface StepProps {
4
4
  step: FormStep;
5
5
  editable: boolean;
6
- handleSizeChange?: () => void;
7
- level: number;
8
6
  }
9
7
  declare function StepComponent({ step, ...props }: StepProps): JSX.Element;
10
8
  export default StepComponent;
@@ -1,7 +1,8 @@
1
1
  import { FormSize } from '../@Types/Form';
2
2
  import { ApiSelector, CheckBox, ClassifierSelector, EntityValuePicker, FormSelector, FormStep } from '../@Types/FormStep';
3
3
  import { CBRFormStep } from '../@Types/CBRFormStep';
4
- export declare function calcFillerSize(step: FormSelector | ClassifierSelector | EntityValuePicker | ApiSelector | CheckBox, steps: Record<string, FormStep>, values: Record<string, unknown>, size: FormSize): number;
4
+ export type FillerSteps = FormSelector | ClassifierSelector | EntityValuePicker | ApiSelector | CheckBox;
5
+ export declare function calcFillerSize(step: FillerSteps, steps: Record<string, FormStep>, values: Record<string, unknown>, size: FormSize): number;
5
6
  export declare function recursivelyCheckOpenSize(idStep: string, steps: Record<string, FormStep>, values: Record<string, any>): number;
6
7
  export declare const calcStepWidth: (stepSize: 1 | 2 | 3 | 4, size: FormSize) => number;
7
8
  export declare const calcDefaultValue: (step: FormStep | CBRFormStep) => any;
@@ -1,4 +1,4 @@
1
- import Types, { ApiSelectorOptionTypes, ClassifierOptionTypes, EntityValueDataTypes, EntityValueOptionTypes, OptionTypes, StepTypes, } from '../constants/FormStepTypes';
1
+ import { ApiSelectorOptionTypes, ClassifierOptionTypes, EntityValueDataTypes, EntityValueOptionTypes, OptionTypes, StepTypes, } from '../constants/FormStepTypes';
2
2
  import CBRFormStepTypes from '../constants/CBRFormStepTypes';
3
3
  import AYFFormStepTypes from '../constants/AYFFormStepTypes';
4
4
  import { getRawText } from '../Utils/DraftFunctions';
@@ -6,7 +6,8 @@ export function calcFillerSize(step, steps, values, size) {
6
6
  var _a;
7
7
  var maxSize = (_a = step.maxSize) !== null && _a !== void 0 ? _a : size.blockNum;
8
8
  if (maxSize < size.blockNum) {
9
- var stepSize = maxSize - recursivelyCheckOpenSize(step.id, steps, values);
9
+ var tsize = recursivelyCheckOpenSize(step.id, steps, values);
10
+ var stepSize = maxSize - tsize;
10
11
  return (size.blockSize * stepSize + size.spacingSize * (stepSize - 1) + 20);
11
12
  }
12
13
  else {
@@ -16,79 +17,85 @@ export function calcFillerSize(step, steps, values, size) {
16
17
  export function recursivelyCheckOpenSize(idStep, steps, values) {
17
18
  var step = steps[idStep];
18
19
  var value = values[idStep];
19
- if (step.type === Types.SELECTOR) {
20
- var size = step.size;
21
- if (value) {
22
- var currentOption = step.options.find(function (option) { return option.value === value; });
23
- if ((currentOption === null || currentOption === void 0 ? void 0 : currentOption.type) === OptionTypes.NESTED) {
24
- var optionSize = 0;
25
- for (var _i = 0, _a = currentOption.steps; _i < _a.length; _i++) {
26
- var pStepId = _a[_i];
27
- optionSize += recursivelyCheckOpenSize(pStepId, steps, values);
20
+ switch (step.type) {
21
+ case StepTypes.SELECTOR: {
22
+ var size = step.size;
23
+ if (value) {
24
+ var currentOption = step.options.find(function (option) { return option.value === value.value; });
25
+ if ((currentOption === null || currentOption === void 0 ? void 0 : currentOption.type) === OptionTypes.NESTED) {
26
+ var optionSize = 0;
27
+ for (var _i = 0, _a = currentOption.steps; _i < _a.length; _i++) {
28
+ var pStepId = _a[_i];
29
+ var temp = recursivelyCheckOpenSize(pStepId, steps, values);
30
+ optionSize += temp;
31
+ }
32
+ size += optionSize;
28
33
  }
29
- size += optionSize;
30
34
  }
35
+ return size;
31
36
  }
32
- return size;
33
- }
34
- else if (step.type === Types.CLASSIFIER_SELECTOR) {
35
- var size = step.size;
36
- if (value) {
37
- var currentOption = step.options[value];
38
- if ((currentOption === null || currentOption === void 0 ? void 0 : currentOption.type) === ClassifierOptionTypes.NESTED) {
39
- var optionSize = 0;
40
- for (var _b = 0, _c = currentOption.steps; _b < _c.length; _b++) {
41
- var pStepId = _c[_b];
42
- optionSize += recursivelyCheckOpenSize(pStepId, steps, values);
37
+ case StepTypes.CLASSIFIER_SELECTOR: {
38
+ var size = step.size;
39
+ if (value) {
40
+ var currentOption = step.options[value];
41
+ if ((currentOption === null || currentOption === void 0 ? void 0 : currentOption.type) === ClassifierOptionTypes.NESTED) {
42
+ var optionSize = 0;
43
+ for (var _b = 0, _c = currentOption.steps; _b < _c.length; _b++) {
44
+ var pStepId = _c[_b];
45
+ optionSize += recursivelyCheckOpenSize(pStepId, steps, values);
46
+ }
47
+ size += optionSize;
43
48
  }
44
- size += optionSize;
45
49
  }
50
+ return size;
46
51
  }
47
- return size;
48
- }
49
- else if (step.type === Types.ENTITYVALUEPICKER) {
50
- var size = step.size;
51
- if (value) {
52
- var currentOption = step.options[value];
53
- if ((currentOption === null || currentOption === void 0 ? void 0 : currentOption.type) === EntityValueOptionTypes.NESTED) {
54
- var optionSize = 0;
55
- for (var _d = 0, _e = currentOption.steps; _d < _e.length; _d++) {
56
- var pStepId = _e[_d];
57
- optionSize += recursivelyCheckOpenSize(pStepId, steps, values);
52
+ case StepTypes.ENTITYVALUEPICKER: {
53
+ var size = step.size;
54
+ if (value) {
55
+ var currentOption = step.options[value];
56
+ if ((currentOption === null || currentOption === void 0 ? void 0 : currentOption.type) === EntityValueOptionTypes.NESTED) {
57
+ var optionSize = 0;
58
+ for (var _d = 0, _e = currentOption.steps; _d < _e.length; _d++) {
59
+ var pStepId = _e[_d];
60
+ optionSize += recursivelyCheckOpenSize(pStepId, steps, values);
61
+ }
62
+ size += optionSize;
58
63
  }
59
- size += optionSize;
60
64
  }
65
+ return size;
61
66
  }
62
- return size;
63
- }
64
- else if (step.type === Types.API_SELECTOR) {
65
- var size = step.size;
66
- if (value) {
67
- var currentOption = step.options[value];
68
- if ((currentOption === null || currentOption === void 0 ? void 0 : currentOption.type) === ApiSelectorOptionTypes.NESTED) {
69
- var optionSize = 0;
70
- for (var _f = 0, _g = currentOption.steps; _f < _g.length; _f++) {
71
- var pStepId = _g[_f];
72
- optionSize += recursivelyCheckOpenSize(pStepId, steps, values);
67
+ case StepTypes.API_SELECTOR: {
68
+ var size = step.size;
69
+ if (value) {
70
+ var currentOption = step.options[value];
71
+ if ((currentOption === null || currentOption === void 0 ? void 0 : currentOption.type) === ApiSelectorOptionTypes.NESTED) {
72
+ var optionSize = 0;
73
+ for (var _f = 0, _g = currentOption.steps; _f < _g.length; _f++) {
74
+ var pStepId = _g[_f];
75
+ optionSize += recursivelyCheckOpenSize(pStepId, steps, values);
76
+ }
77
+ size += optionSize;
73
78
  }
74
- size += optionSize;
75
79
  }
80
+ return size;
76
81
  }
77
- return size;
78
- }
79
- if (step.type === Types.CHECKBOX) {
80
- var size = step.size;
81
- var stepSteps = value ? step.steps : step.uncheckedSteps;
82
- var optionSize = 0;
83
- for (var _h = 0, _j = stepSteps !== null && stepSteps !== void 0 ? stepSteps : []; _h < _j.length; _h++) {
84
- var pStepId = _j[_h];
85
- optionSize += recursivelyCheckOpenSize(pStepId, steps, values);
82
+ case StepTypes.CHECKBOX: {
83
+ var size = step.size;
84
+ var stepSteps = value ? step.steps : step.uncheckedSteps;
85
+ var optionSize = 0;
86
+ for (var _h = 0, _j = stepSteps !== null && stepSteps !== void 0 ? stepSteps : []; _h < _j.length; _h++) {
87
+ var pStepId = _j[_h];
88
+ optionSize += recursivelyCheckOpenSize(pStepId, steps, values);
89
+ }
90
+ size += optionSize;
91
+ return size;
86
92
  }
87
- size += optionSize;
88
- return size;
89
- }
90
- else {
91
- return 4;
93
+ case StepTypes.DATEPICKER:
94
+ case StepTypes.TEXTINPUT: {
95
+ return step.size;
96
+ }
97
+ default:
98
+ return 4;
92
99
  }
93
100
  }
94
101
  export var calcStepWidth = function (stepSize, size) {
@@ -131,7 +138,7 @@ export var calcDefaultValue = function (step) {
131
138
  export var iterateNestedSteps = function (idStep, steps, iteration) {
132
139
  var step = steps[idStep];
133
140
  iteration(step);
134
- if (step.type == StepTypes.MAPPER) {
141
+ if (step.type === StepTypes.MAPPER) {
135
142
  for (var _i = 0, _a = step.rootSteps; _i < _a.length; _i++) {
136
143
  var idStep_1 = _a[_i];
137
144
  iterateNestedSteps(idStep_1, step.steps, iteration);
@@ -3,6 +3,7 @@ import { ValuesStore } from '../States/SiteSlice';
3
3
  import { RootState } from '../Utils/store';
4
4
  import { Form } from '../@Types';
5
5
  import { DependencyStore } from '../Form/Form';
6
+ import { FieldError, RefCallBack, UseControllerProps, useController } from 'react-hook-form';
6
7
  export declare const selectOriginalValue: ((state: RootState, step: GBaseStep) => any) & import("reselect").OutputSelectorFields<(args_0: ValuesStore, args_1: GBaseStep) => any, {
7
8
  clearCache: () => void;
8
9
  }> & {
@@ -25,3 +26,18 @@ export declare const selectDependencies: ((state: RootState, step: GBaseStep, fo
25
26
  }> & {
26
27
  clearCache: () => void;
27
28
  };
29
+ export interface UseFormStepOptions<ValueType> {
30
+ defaultValue?: ValueType;
31
+ /** If true, will not trigger onChange until the user has finished typing */
32
+ debounce?: boolean;
33
+ rules?: UseControllerProps['rules'];
34
+ /** If the step should trigger a filler(root StepFiller) size change */
35
+ sizeChange?: boolean;
36
+ }
37
+ export declare const useFormStep: <ValueType = unknown>(step: GBaseStep, { rules, debounce, sizeChange, defaultValue, }?: UseFormStepOptions<ValueType>) => {
38
+ value: ValueType;
39
+ ref: RefCallBack;
40
+ onChange: (value: ValueType) => void;
41
+ error: FieldError | undefined;
42
+ field: Omit<ReturnType<typeof useController>['field'], 'ref' | 'value' | 'onChange'>;
43
+ };