@visiion/forms-library 1.4.4 → 1.4.5
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/components/Inputs/DatePicker.d.ts +1 -0
- package/dist/index.esm.js +178 -20
- package/dist/index.js +178 -20
- package/dist/types/index.d.ts +1 -0
- package/package.json +5 -5
package/dist/index.esm.js
CHANGED
|
@@ -19637,8 +19637,8 @@ const identity = (arg) => arg;
|
|
|
19637
19637
|
function useStore(api, selector = identity) {
|
|
19638
19638
|
const slice = React.useSyncExternalStore(
|
|
19639
19639
|
api.subscribe,
|
|
19640
|
-
() => selector(api.getState()),
|
|
19641
|
-
() => selector(api.getInitialState())
|
|
19640
|
+
React.useCallback(() => selector(api.getState()), [api, selector]),
|
|
19641
|
+
React.useCallback(() => selector(api.getInitialState()), [api, selector])
|
|
19642
19642
|
);
|
|
19643
19643
|
React.useDebugValue(slice);
|
|
19644
19644
|
return slice;
|
|
@@ -19958,8 +19958,8 @@ var Alert = function (_a) {
|
|
|
19958
19958
|
};
|
|
19959
19959
|
|
|
19960
19960
|
var DatePicker = function (_a) {
|
|
19961
|
-
var id = _a.id, name = _a.name, label = _a.label, value = _a.value, onChange = _a.onChange, error = _a.error, disabled = _a.disabled, required = _a.required, placeholder = _a.placeholder;
|
|
19962
|
-
return (jsx(InputWrapper, { id: id, label: label, error: error, children: jsx("input", { id: id, name: name, type: "date", value: value || "", onChange: onChange, disabled: disabled, required: required, placeholder: placeholder, className: "w-full px-3 py-2 font-roboto font-normal text-gray-800 text-sm border rounded-md focus:outline-none focus:ring-2 focus:ring-orange-500 ".concat(error ? "border-red-500" : "border-gray-300", " ").concat(disabled ? "bg-gray-100 cursor-not-allowed" : "") }) }));
|
|
19961
|
+
var id = _a.id, name = _a.name, label = _a.label, value = _a.value, onChange = _a.onChange, error = _a.error, disabled = _a.disabled, required = _a.required, placeholder = _a.placeholder, props = _a.props;
|
|
19962
|
+
return (jsx(InputWrapper, { id: id, label: label, error: error, children: jsx("input", { id: id, name: name, type: "date", value: value || "", onChange: onChange, disabled: disabled, required: required, placeholder: placeholder, max: props === null || props === void 0 ? void 0 : props.maxDate, min: props === null || props === void 0 ? void 0 : props.minDate, className: "w-full px-3 py-2 font-roboto font-normal text-gray-800 text-sm border rounded-md focus:outline-none focus:ring-2 focus:ring-orange-500 ".concat(error ? "border-red-500" : "border-gray-300", " ").concat(disabled ? "bg-gray-100 cursor-not-allowed" : "") }) }));
|
|
19963
19963
|
};
|
|
19964
19964
|
|
|
19965
19965
|
var SwornDeclaration = function (_a) {
|
|
@@ -20031,6 +20031,7 @@ var Checklist = function (_a) {
|
|
|
20031
20031
|
var _c = useState(value), selectedOptions = _c[0], setSelectedOptions = _c[1];
|
|
20032
20032
|
var _d = useState(props.valueOtraMedida), otraMedida = _d[0], setOtraMedida = _d[1];
|
|
20033
20033
|
var options = field.options || [];
|
|
20034
|
+
var isOtraMedidaRequired = selectedOptions.includes("otra-medida");
|
|
20034
20035
|
useEffect(function () {
|
|
20035
20036
|
setSelectedOptions(value);
|
|
20036
20037
|
}, [value]);
|
|
@@ -20054,6 +20055,10 @@ var Checklist = function (_a) {
|
|
|
20054
20055
|
}
|
|
20055
20056
|
else {
|
|
20056
20057
|
newSelectedOptions = selectedOptions.filter(function (opt) { return opt !== optionValue; });
|
|
20058
|
+
// Si se deselecciona "otra-medida", limpiar el texto
|
|
20059
|
+
if (optionValue === "otra-medida") {
|
|
20060
|
+
setOtraMedida("");
|
|
20061
|
+
}
|
|
20057
20062
|
}
|
|
20058
20063
|
setSelectedOptions(newSelectedOptions);
|
|
20059
20064
|
onChange === null || onChange === void 0 ? void 0 : onChange(newSelectedOptions);
|
|
@@ -20062,17 +20067,17 @@ var Checklist = function (_a) {
|
|
|
20062
20067
|
var _a;
|
|
20063
20068
|
setOtraMedida(text);
|
|
20064
20069
|
// Actualizar el valor con la otra medida
|
|
20065
|
-
var updatedOptions = selectedOptions.filter(function (opt) { return opt
|
|
20070
|
+
var updatedOptions = selectedOptions.filter(function (opt) { return !opt.startsWith("otra-medida-value-"); });
|
|
20071
|
+
// Solo agregar "otra-medida" si hay texto
|
|
20066
20072
|
if (text.trim()) {
|
|
20067
|
-
updatedOptions.push("otra-medida");
|
|
20073
|
+
updatedOptions.push("otra-medida-value-".concat(text));
|
|
20068
20074
|
}
|
|
20069
20075
|
onChange === null || onChange === void 0 ? void 0 : onChange(updatedOptions);
|
|
20070
20076
|
(_a = props.onOtraMedidaChange) === null || _a === void 0 ? void 0 : _a.call(props, text);
|
|
20071
20077
|
};
|
|
20072
|
-
var isOtraMedidaRequired = selectedOptions.includes("otra-medida");
|
|
20073
20078
|
return (jsxs("div", { className: "space-y-4", children: [jsx("div", { className: "space-y-2", children: options.map(function (option) { return (jsxs("div", { className: "flex items-center gap-2", children: [jsx("input", { type: "checkbox", checked: selectedOptions.includes(option.value), onChange: function (e) {
|
|
20074
20079
|
return handleOptionChange(option.value, e.target.checked);
|
|
20075
|
-
}, className: "w-4 h-4 text-orange-600 border-gray-800 rounded focus:ring-orange-500 bg-white border-2" }), jsx("label", { className: "font-normal text-text font-roboto font-normal font-weight-400 text-sm leading-4 text-gray-600", children: option.label })] }, option.value)); }) }), isOtraMedidaRequired && (jsx("div", { className: "mt-4", children: jsx("
|
|
20080
|
+
}, className: "w-4 h-4 text-orange-600 border-gray-800 rounded focus:ring-orange-500 bg-white border-2" }), jsx("label", { className: "font-normal text-text font-roboto font-normal font-weight-400 text-sm leading-4 text-gray-600", children: option.label })] }, option.value)); }) }), isOtraMedidaRequired && (jsx("div", { className: "mt-4", children: jsx(TextareaInput, { id: "textarea-otra-medida", name: "textarea-otra-medida", label: "", value: otraMedida, onChange: function (e) { return handleOtraMedidaChange(e.target.value); }, placeholder: "Detalle cu\u00E1l es la medida de resguardo", maxLength: 100, rows: 2, error: error }) })), error && !isOtraMedidaRequired && (jsx("div", { className: "text-red-600 text-sm mt-2", children: error }))] }));
|
|
20076
20081
|
};
|
|
20077
20082
|
|
|
20078
20083
|
var Upload = function (_a) {
|
|
@@ -20857,19 +20862,20 @@ function createValidation(config) {
|
|
|
20857
20862
|
abortEarly = schema.spec.abortEarly,
|
|
20858
20863
|
disableStackTrace = schema.spec.disableStackTrace
|
|
20859
20864
|
} = options;
|
|
20860
|
-
|
|
20861
|
-
|
|
20862
|
-
|
|
20865
|
+
const resolveOptions = {
|
|
20866
|
+
value,
|
|
20867
|
+
parent,
|
|
20868
|
+
context
|
|
20869
|
+
};
|
|
20863
20870
|
function createError(overrides = {}) {
|
|
20864
|
-
const nextParams = Object.assign({
|
|
20871
|
+
const nextParams = resolveParams(Object.assign({
|
|
20865
20872
|
value,
|
|
20866
20873
|
originalValue,
|
|
20867
20874
|
label: schema.spec.label,
|
|
20868
20875
|
path: overrides.path || path,
|
|
20869
20876
|
spec: schema.spec,
|
|
20870
20877
|
disableStackTrace: overrides.disableStackTrace || disableStackTrace
|
|
20871
|
-
}, params, overrides.params);
|
|
20872
|
-
for (const key of Object.keys(nextParams)) nextParams[key] = resolve(nextParams[key]);
|
|
20878
|
+
}, params, overrides.params), resolveOptions);
|
|
20873
20879
|
const error = new ValidationError(ValidationError.formatError(overrides.message || message, nextParams), value, nextParams.path, overrides.type || name, nextParams.disableStackTrace);
|
|
20874
20880
|
error.params = nextParams;
|
|
20875
20881
|
return error;
|
|
@@ -20881,7 +20887,9 @@ function createValidation(config) {
|
|
|
20881
20887
|
type: name,
|
|
20882
20888
|
from: options.from,
|
|
20883
20889
|
createError,
|
|
20884
|
-
resolve
|
|
20890
|
+
resolve(item) {
|
|
20891
|
+
return resolveMaybeRef(item, resolveOptions);
|
|
20892
|
+
},
|
|
20885
20893
|
options,
|
|
20886
20894
|
originalValue,
|
|
20887
20895
|
schema
|
|
@@ -20916,6 +20924,18 @@ function createValidation(config) {
|
|
|
20916
20924
|
return validate;
|
|
20917
20925
|
}
|
|
20918
20926
|
|
|
20927
|
+
// Warning: mutates the input
|
|
20928
|
+
function resolveParams(params, options) {
|
|
20929
|
+
if (!params) return params;
|
|
20930
|
+
for (const key of Object.keys(params)) {
|
|
20931
|
+
params[key] = resolveMaybeRef(params[key], options);
|
|
20932
|
+
}
|
|
20933
|
+
return params;
|
|
20934
|
+
}
|
|
20935
|
+
function resolveMaybeRef(item, options) {
|
|
20936
|
+
return Reference.isRef(item) ? item.getValue(options.value, options.parent, options.context) : item;
|
|
20937
|
+
}
|
|
20938
|
+
|
|
20919
20939
|
function getIn(schema, path, value, context = value) {
|
|
20920
20940
|
let parent, lastPart, lastPartDebug;
|
|
20921
20941
|
|
|
@@ -21029,6 +21049,87 @@ function clone(src, seen = new Map()) {
|
|
|
21029
21049
|
return copy;
|
|
21030
21050
|
}
|
|
21031
21051
|
|
|
21052
|
+
/**
|
|
21053
|
+
* Copied from @standard-schema/spec to avoid having a dependency on it.
|
|
21054
|
+
* https://github.com/standard-schema/standard-schema/blob/main/packages/spec/src/index.ts
|
|
21055
|
+
*/
|
|
21056
|
+
|
|
21057
|
+
function createStandardPath(path) {
|
|
21058
|
+
if (!(path != null && path.length)) {
|
|
21059
|
+
return undefined;
|
|
21060
|
+
}
|
|
21061
|
+
|
|
21062
|
+
// Array to store the final path segments
|
|
21063
|
+
const segments = [];
|
|
21064
|
+
// Buffer for building the current segment
|
|
21065
|
+
let currentSegment = '';
|
|
21066
|
+
// Track if we're inside square brackets (array/property access)
|
|
21067
|
+
let inBrackets = false;
|
|
21068
|
+
// Track if we're inside quotes (for property names with special chars)
|
|
21069
|
+
let inQuotes = false;
|
|
21070
|
+
for (let i = 0; i < path.length; i++) {
|
|
21071
|
+
const char = path[i];
|
|
21072
|
+
if (char === '[' && !inQuotes) {
|
|
21073
|
+
// When entering brackets, push any accumulated segment after splitting on dots
|
|
21074
|
+
if (currentSegment) {
|
|
21075
|
+
segments.push(...currentSegment.split('.').filter(Boolean));
|
|
21076
|
+
currentSegment = '';
|
|
21077
|
+
}
|
|
21078
|
+
inBrackets = true;
|
|
21079
|
+
continue;
|
|
21080
|
+
}
|
|
21081
|
+
if (char === ']' && !inQuotes) {
|
|
21082
|
+
if (currentSegment) {
|
|
21083
|
+
// Handle numeric indices (e.g. arr[0])
|
|
21084
|
+
if (/^\d+$/.test(currentSegment)) {
|
|
21085
|
+
segments.push(currentSegment);
|
|
21086
|
+
} else {
|
|
21087
|
+
// Handle quoted property names (e.g. obj["foo.bar"])
|
|
21088
|
+
segments.push(currentSegment.replace(/^"|"$/g, ''));
|
|
21089
|
+
}
|
|
21090
|
+
currentSegment = '';
|
|
21091
|
+
}
|
|
21092
|
+
inBrackets = false;
|
|
21093
|
+
continue;
|
|
21094
|
+
}
|
|
21095
|
+
if (char === '"') {
|
|
21096
|
+
// Toggle quote state for handling quoted property names
|
|
21097
|
+
inQuotes = !inQuotes;
|
|
21098
|
+
continue;
|
|
21099
|
+
}
|
|
21100
|
+
if (char === '.' && !inBrackets && !inQuotes) {
|
|
21101
|
+
// On dots outside brackets/quotes, push current segment
|
|
21102
|
+
if (currentSegment) {
|
|
21103
|
+
segments.push(currentSegment);
|
|
21104
|
+
currentSegment = '';
|
|
21105
|
+
}
|
|
21106
|
+
continue;
|
|
21107
|
+
}
|
|
21108
|
+
currentSegment += char;
|
|
21109
|
+
}
|
|
21110
|
+
|
|
21111
|
+
// Push any remaining segment after splitting on dots
|
|
21112
|
+
if (currentSegment) {
|
|
21113
|
+
segments.push(...currentSegment.split('.').filter(Boolean));
|
|
21114
|
+
}
|
|
21115
|
+
return segments;
|
|
21116
|
+
}
|
|
21117
|
+
function createStandardIssues(error, parentPath) {
|
|
21118
|
+
const path = parentPath ? `${parentPath}.${error.path}` : error.path;
|
|
21119
|
+
return error.errors.map(err => ({
|
|
21120
|
+
message: err,
|
|
21121
|
+
path: createStandardPath(path)
|
|
21122
|
+
}));
|
|
21123
|
+
}
|
|
21124
|
+
function issuesFromValidationError(error, parentPath) {
|
|
21125
|
+
var _error$inner;
|
|
21126
|
+
if (!((_error$inner = error.inner) != null && _error$inner.length) && error.errors.length) {
|
|
21127
|
+
return createStandardIssues(error, parentPath);
|
|
21128
|
+
}
|
|
21129
|
+
const path = parentPath ? `${parentPath}.${error.path}` : error.path;
|
|
21130
|
+
return error.inner.flatMap(err => issuesFromValidationError(err, path));
|
|
21131
|
+
}
|
|
21132
|
+
|
|
21032
21133
|
// If `CustomSchemaMeta` isn't extended with any keys, we'll fall back to a
|
|
21033
21134
|
// loose Record definition allowing free form usage.
|
|
21034
21135
|
class Schema {
|
|
@@ -21596,13 +21697,41 @@ class Schema {
|
|
|
21596
21697
|
type: next.type,
|
|
21597
21698
|
oneOf: next._whitelist.describe(),
|
|
21598
21699
|
notOneOf: next._blacklist.describe(),
|
|
21599
|
-
tests: next.tests.map(fn =>
|
|
21600
|
-
|
|
21601
|
-
|
|
21602
|
-
|
|
21700
|
+
tests: next.tests.filter((n, idx, list) => list.findIndex(c => c.OPTIONS.name === n.OPTIONS.name) === idx).map(fn => {
|
|
21701
|
+
const params = fn.OPTIONS.params && options ? resolveParams(Object.assign({}, fn.OPTIONS.params), options) : fn.OPTIONS.params;
|
|
21702
|
+
return {
|
|
21703
|
+
name: fn.OPTIONS.name,
|
|
21704
|
+
params
|
|
21705
|
+
};
|
|
21706
|
+
})
|
|
21603
21707
|
};
|
|
21604
21708
|
return description;
|
|
21605
21709
|
}
|
|
21710
|
+
get ['~standard']() {
|
|
21711
|
+
const schema = this;
|
|
21712
|
+
const standard = {
|
|
21713
|
+
version: 1,
|
|
21714
|
+
vendor: 'yup',
|
|
21715
|
+
async validate(value) {
|
|
21716
|
+
try {
|
|
21717
|
+
const result = await schema.validate(value, {
|
|
21718
|
+
abortEarly: false
|
|
21719
|
+
});
|
|
21720
|
+
return {
|
|
21721
|
+
value: result
|
|
21722
|
+
};
|
|
21723
|
+
} catch (err) {
|
|
21724
|
+
if (err instanceof ValidationError) {
|
|
21725
|
+
return {
|
|
21726
|
+
issues: issuesFromValidationError(err)
|
|
21727
|
+
};
|
|
21728
|
+
}
|
|
21729
|
+
throw err;
|
|
21730
|
+
}
|
|
21731
|
+
}
|
|
21732
|
+
};
|
|
21733
|
+
return standard;
|
|
21734
|
+
}
|
|
21606
21735
|
}
|
|
21607
21736
|
// @ts-expect-error
|
|
21608
21737
|
Schema.prototype.__isYupSchema__ = true;
|
|
@@ -22586,7 +22715,10 @@ var createValidationSchema = function (fields) {
|
|
|
22586
22715
|
switch (field.type) {
|
|
22587
22716
|
case "checkbox":
|
|
22588
22717
|
case "checklist":
|
|
22589
|
-
fieldSchema_1 = create$2()
|
|
22718
|
+
fieldSchema_1 = create$2()
|
|
22719
|
+
.of(create$6())
|
|
22720
|
+
.min(1, field.validations[0].params[0] ||
|
|
22721
|
+
"El campo ".concat(field.label || field.name || "sin nombre", " es requerido"));
|
|
22590
22722
|
break;
|
|
22591
22723
|
case "upload":
|
|
22592
22724
|
fieldSchema_1 = create$8();
|
|
@@ -22630,6 +22762,24 @@ var createValidationSchema = function (fields) {
|
|
|
22630
22762
|
return validate(clean(value));
|
|
22631
22763
|
});
|
|
22632
22764
|
}
|
|
22765
|
+
else if (customValidator === "otra-medida") {
|
|
22766
|
+
fieldSchema_1 = fieldSchema_1.test("otra-medida", validation.params[1] ||
|
|
22767
|
+
"Debe detallar cuál es la medida de resguardo", function (value) {
|
|
22768
|
+
// Si no incluye "otra-medida", la validación pasa
|
|
22769
|
+
if (!value.includes("otra-medida"))
|
|
22770
|
+
return true;
|
|
22771
|
+
// Si incluye "otra-medida", debe tener "otra-medida-value-text" con texto
|
|
22772
|
+
var otraMedidaValue = value.find(function (opt) {
|
|
22773
|
+
return opt.startsWith("otra-medida-value-");
|
|
22774
|
+
});
|
|
22775
|
+
if (otraMedidaValue) {
|
|
22776
|
+
var text = otraMedidaValue.split("otra-medida-value-")[1];
|
|
22777
|
+
return text && text.trim() !== "";
|
|
22778
|
+
}
|
|
22779
|
+
// Si incluye "otra-medida" pero no tiene "otra-medida-value-text" con texto
|
|
22780
|
+
return false;
|
|
22781
|
+
});
|
|
22782
|
+
}
|
|
22633
22783
|
else {
|
|
22634
22784
|
fieldSchema_1 = fieldSchema_1.test("custom", validation.params[1] ||
|
|
22635
22785
|
"Validaci\u00F3n fallida para ".concat(field.label || field.name || "sin nombre"), function (value) {
|
|
@@ -22688,6 +22838,13 @@ var commonValidations = {
|
|
|
22688
22838
|
type: "pattern",
|
|
22689
22839
|
params: [regex, message || "Formato inválido"],
|
|
22690
22840
|
}); },
|
|
22841
|
+
otraMedidaRequired: function (message) { return ({
|
|
22842
|
+
type: "custom",
|
|
22843
|
+
params: [
|
|
22844
|
+
"otra-medida",
|
|
22845
|
+
message || "Debe detallar cuál es la medida de resguardo",
|
|
22846
|
+
],
|
|
22847
|
+
}); },
|
|
22691
22848
|
};
|
|
22692
22849
|
|
|
22693
22850
|
var FormStepper = function (_a) {
|
|
@@ -22821,6 +22978,7 @@ var GenericForm = function (_a) {
|
|
|
22821
22978
|
validationError_1 = _a.sent();
|
|
22822
22979
|
newErrors_1 = {};
|
|
22823
22980
|
if (validationError_1.inner) {
|
|
22981
|
+
console.log(validationError_1);
|
|
22824
22982
|
validationError_1.inner.forEach(function (error) {
|
|
22825
22983
|
newErrors_1[error.path] = error.message;
|
|
22826
22984
|
});
|
package/dist/index.js
CHANGED
|
@@ -19656,8 +19656,8 @@ const identity = (arg) => arg;
|
|
|
19656
19656
|
function useStore(api, selector = identity) {
|
|
19657
19657
|
const slice = React.useSyncExternalStore(
|
|
19658
19658
|
api.subscribe,
|
|
19659
|
-
() => selector(api.getState()),
|
|
19660
|
-
() => selector(api.getInitialState())
|
|
19659
|
+
React.useCallback(() => selector(api.getState()), [api, selector]),
|
|
19660
|
+
React.useCallback(() => selector(api.getInitialState()), [api, selector])
|
|
19661
19661
|
);
|
|
19662
19662
|
React.useDebugValue(slice);
|
|
19663
19663
|
return slice;
|
|
@@ -19977,8 +19977,8 @@ var Alert = function (_a) {
|
|
|
19977
19977
|
};
|
|
19978
19978
|
|
|
19979
19979
|
var DatePicker = function (_a) {
|
|
19980
|
-
var id = _a.id, name = _a.name, label = _a.label, value = _a.value, onChange = _a.onChange, error = _a.error, disabled = _a.disabled, required = _a.required, placeholder = _a.placeholder;
|
|
19981
|
-
return (jsxRuntime.jsx(InputWrapper, { id: id, label: label, error: error, children: jsxRuntime.jsx("input", { id: id, name: name, type: "date", value: value || "", onChange: onChange, disabled: disabled, required: required, placeholder: placeholder, className: "w-full px-3 py-2 font-roboto font-normal text-gray-800 text-sm border rounded-md focus:outline-none focus:ring-2 focus:ring-orange-500 ".concat(error ? "border-red-500" : "border-gray-300", " ").concat(disabled ? "bg-gray-100 cursor-not-allowed" : "") }) }));
|
|
19980
|
+
var id = _a.id, name = _a.name, label = _a.label, value = _a.value, onChange = _a.onChange, error = _a.error, disabled = _a.disabled, required = _a.required, placeholder = _a.placeholder, props = _a.props;
|
|
19981
|
+
return (jsxRuntime.jsx(InputWrapper, { id: id, label: label, error: error, children: jsxRuntime.jsx("input", { id: id, name: name, type: "date", value: value || "", onChange: onChange, disabled: disabled, required: required, placeholder: placeholder, max: props === null || props === void 0 ? void 0 : props.maxDate, min: props === null || props === void 0 ? void 0 : props.minDate, className: "w-full px-3 py-2 font-roboto font-normal text-gray-800 text-sm border rounded-md focus:outline-none focus:ring-2 focus:ring-orange-500 ".concat(error ? "border-red-500" : "border-gray-300", " ").concat(disabled ? "bg-gray-100 cursor-not-allowed" : "") }) }));
|
|
19982
19982
|
};
|
|
19983
19983
|
|
|
19984
19984
|
var SwornDeclaration = function (_a) {
|
|
@@ -20050,6 +20050,7 @@ var Checklist = function (_a) {
|
|
|
20050
20050
|
var _c = React.useState(value), selectedOptions = _c[0], setSelectedOptions = _c[1];
|
|
20051
20051
|
var _d = React.useState(props.valueOtraMedida), otraMedida = _d[0], setOtraMedida = _d[1];
|
|
20052
20052
|
var options = field.options || [];
|
|
20053
|
+
var isOtraMedidaRequired = selectedOptions.includes("otra-medida");
|
|
20053
20054
|
React.useEffect(function () {
|
|
20054
20055
|
setSelectedOptions(value);
|
|
20055
20056
|
}, [value]);
|
|
@@ -20073,6 +20074,10 @@ var Checklist = function (_a) {
|
|
|
20073
20074
|
}
|
|
20074
20075
|
else {
|
|
20075
20076
|
newSelectedOptions = selectedOptions.filter(function (opt) { return opt !== optionValue; });
|
|
20077
|
+
// Si se deselecciona "otra-medida", limpiar el texto
|
|
20078
|
+
if (optionValue === "otra-medida") {
|
|
20079
|
+
setOtraMedida("");
|
|
20080
|
+
}
|
|
20076
20081
|
}
|
|
20077
20082
|
setSelectedOptions(newSelectedOptions);
|
|
20078
20083
|
onChange === null || onChange === void 0 ? void 0 : onChange(newSelectedOptions);
|
|
@@ -20081,17 +20086,17 @@ var Checklist = function (_a) {
|
|
|
20081
20086
|
var _a;
|
|
20082
20087
|
setOtraMedida(text);
|
|
20083
20088
|
// Actualizar el valor con la otra medida
|
|
20084
|
-
var updatedOptions = selectedOptions.filter(function (opt) { return opt
|
|
20089
|
+
var updatedOptions = selectedOptions.filter(function (opt) { return !opt.startsWith("otra-medida-value-"); });
|
|
20090
|
+
// Solo agregar "otra-medida" si hay texto
|
|
20085
20091
|
if (text.trim()) {
|
|
20086
|
-
updatedOptions.push("otra-medida");
|
|
20092
|
+
updatedOptions.push("otra-medida-value-".concat(text));
|
|
20087
20093
|
}
|
|
20088
20094
|
onChange === null || onChange === void 0 ? void 0 : onChange(updatedOptions);
|
|
20089
20095
|
(_a = props.onOtraMedidaChange) === null || _a === void 0 ? void 0 : _a.call(props, text);
|
|
20090
20096
|
};
|
|
20091
|
-
var isOtraMedidaRequired = selectedOptions.includes("otra-medida");
|
|
20092
20097
|
return (jsxRuntime.jsxs("div", { className: "space-y-4", children: [jsxRuntime.jsx("div", { className: "space-y-2", children: options.map(function (option) { return (jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntime.jsx("input", { type: "checkbox", checked: selectedOptions.includes(option.value), onChange: function (e) {
|
|
20093
20098
|
return handleOptionChange(option.value, e.target.checked);
|
|
20094
|
-
}, className: "w-4 h-4 text-orange-600 border-gray-800 rounded focus:ring-orange-500 bg-white border-2" }), jsxRuntime.jsx("label", { className: "font-normal text-text font-roboto font-normal font-weight-400 text-sm leading-4 text-gray-600", children: option.label })] }, option.value)); }) }), isOtraMedidaRequired && (jsxRuntime.jsx("div", { className: "mt-4", children: jsxRuntime.jsx("
|
|
20099
|
+
}, className: "w-4 h-4 text-orange-600 border-gray-800 rounded focus:ring-orange-500 bg-white border-2" }), jsxRuntime.jsx("label", { className: "font-normal text-text font-roboto font-normal font-weight-400 text-sm leading-4 text-gray-600", children: option.label })] }, option.value)); }) }), isOtraMedidaRequired && (jsxRuntime.jsx("div", { className: "mt-4", children: jsxRuntime.jsx(TextareaInput, { id: "textarea-otra-medida", name: "textarea-otra-medida", label: "", value: otraMedida, onChange: function (e) { return handleOtraMedidaChange(e.target.value); }, placeholder: "Detalle cu\u00E1l es la medida de resguardo", maxLength: 100, rows: 2, error: error }) })), error && !isOtraMedidaRequired && (jsxRuntime.jsx("div", { className: "text-red-600 text-sm mt-2", children: error }))] }));
|
|
20095
20100
|
};
|
|
20096
20101
|
|
|
20097
20102
|
var Upload = function (_a) {
|
|
@@ -20876,19 +20881,20 @@ function createValidation(config) {
|
|
|
20876
20881
|
abortEarly = schema.spec.abortEarly,
|
|
20877
20882
|
disableStackTrace = schema.spec.disableStackTrace
|
|
20878
20883
|
} = options;
|
|
20879
|
-
|
|
20880
|
-
|
|
20881
|
-
|
|
20884
|
+
const resolveOptions = {
|
|
20885
|
+
value,
|
|
20886
|
+
parent,
|
|
20887
|
+
context
|
|
20888
|
+
};
|
|
20882
20889
|
function createError(overrides = {}) {
|
|
20883
|
-
const nextParams = Object.assign({
|
|
20890
|
+
const nextParams = resolveParams(Object.assign({
|
|
20884
20891
|
value,
|
|
20885
20892
|
originalValue,
|
|
20886
20893
|
label: schema.spec.label,
|
|
20887
20894
|
path: overrides.path || path,
|
|
20888
20895
|
spec: schema.spec,
|
|
20889
20896
|
disableStackTrace: overrides.disableStackTrace || disableStackTrace
|
|
20890
|
-
}, params, overrides.params);
|
|
20891
|
-
for (const key of Object.keys(nextParams)) nextParams[key] = resolve(nextParams[key]);
|
|
20897
|
+
}, params, overrides.params), resolveOptions);
|
|
20892
20898
|
const error = new ValidationError(ValidationError.formatError(overrides.message || message, nextParams), value, nextParams.path, overrides.type || name, nextParams.disableStackTrace);
|
|
20893
20899
|
error.params = nextParams;
|
|
20894
20900
|
return error;
|
|
@@ -20900,7 +20906,9 @@ function createValidation(config) {
|
|
|
20900
20906
|
type: name,
|
|
20901
20907
|
from: options.from,
|
|
20902
20908
|
createError,
|
|
20903
|
-
resolve
|
|
20909
|
+
resolve(item) {
|
|
20910
|
+
return resolveMaybeRef(item, resolveOptions);
|
|
20911
|
+
},
|
|
20904
20912
|
options,
|
|
20905
20913
|
originalValue,
|
|
20906
20914
|
schema
|
|
@@ -20935,6 +20943,18 @@ function createValidation(config) {
|
|
|
20935
20943
|
return validate;
|
|
20936
20944
|
}
|
|
20937
20945
|
|
|
20946
|
+
// Warning: mutates the input
|
|
20947
|
+
function resolveParams(params, options) {
|
|
20948
|
+
if (!params) return params;
|
|
20949
|
+
for (const key of Object.keys(params)) {
|
|
20950
|
+
params[key] = resolveMaybeRef(params[key], options);
|
|
20951
|
+
}
|
|
20952
|
+
return params;
|
|
20953
|
+
}
|
|
20954
|
+
function resolveMaybeRef(item, options) {
|
|
20955
|
+
return Reference.isRef(item) ? item.getValue(options.value, options.parent, options.context) : item;
|
|
20956
|
+
}
|
|
20957
|
+
|
|
20938
20958
|
function getIn(schema, path, value, context = value) {
|
|
20939
20959
|
let parent, lastPart, lastPartDebug;
|
|
20940
20960
|
|
|
@@ -21048,6 +21068,87 @@ function clone(src, seen = new Map()) {
|
|
|
21048
21068
|
return copy;
|
|
21049
21069
|
}
|
|
21050
21070
|
|
|
21071
|
+
/**
|
|
21072
|
+
* Copied from @standard-schema/spec to avoid having a dependency on it.
|
|
21073
|
+
* https://github.com/standard-schema/standard-schema/blob/main/packages/spec/src/index.ts
|
|
21074
|
+
*/
|
|
21075
|
+
|
|
21076
|
+
function createStandardPath(path) {
|
|
21077
|
+
if (!(path != null && path.length)) {
|
|
21078
|
+
return undefined;
|
|
21079
|
+
}
|
|
21080
|
+
|
|
21081
|
+
// Array to store the final path segments
|
|
21082
|
+
const segments = [];
|
|
21083
|
+
// Buffer for building the current segment
|
|
21084
|
+
let currentSegment = '';
|
|
21085
|
+
// Track if we're inside square brackets (array/property access)
|
|
21086
|
+
let inBrackets = false;
|
|
21087
|
+
// Track if we're inside quotes (for property names with special chars)
|
|
21088
|
+
let inQuotes = false;
|
|
21089
|
+
for (let i = 0; i < path.length; i++) {
|
|
21090
|
+
const char = path[i];
|
|
21091
|
+
if (char === '[' && !inQuotes) {
|
|
21092
|
+
// When entering brackets, push any accumulated segment after splitting on dots
|
|
21093
|
+
if (currentSegment) {
|
|
21094
|
+
segments.push(...currentSegment.split('.').filter(Boolean));
|
|
21095
|
+
currentSegment = '';
|
|
21096
|
+
}
|
|
21097
|
+
inBrackets = true;
|
|
21098
|
+
continue;
|
|
21099
|
+
}
|
|
21100
|
+
if (char === ']' && !inQuotes) {
|
|
21101
|
+
if (currentSegment) {
|
|
21102
|
+
// Handle numeric indices (e.g. arr[0])
|
|
21103
|
+
if (/^\d+$/.test(currentSegment)) {
|
|
21104
|
+
segments.push(currentSegment);
|
|
21105
|
+
} else {
|
|
21106
|
+
// Handle quoted property names (e.g. obj["foo.bar"])
|
|
21107
|
+
segments.push(currentSegment.replace(/^"|"$/g, ''));
|
|
21108
|
+
}
|
|
21109
|
+
currentSegment = '';
|
|
21110
|
+
}
|
|
21111
|
+
inBrackets = false;
|
|
21112
|
+
continue;
|
|
21113
|
+
}
|
|
21114
|
+
if (char === '"') {
|
|
21115
|
+
// Toggle quote state for handling quoted property names
|
|
21116
|
+
inQuotes = !inQuotes;
|
|
21117
|
+
continue;
|
|
21118
|
+
}
|
|
21119
|
+
if (char === '.' && !inBrackets && !inQuotes) {
|
|
21120
|
+
// On dots outside brackets/quotes, push current segment
|
|
21121
|
+
if (currentSegment) {
|
|
21122
|
+
segments.push(currentSegment);
|
|
21123
|
+
currentSegment = '';
|
|
21124
|
+
}
|
|
21125
|
+
continue;
|
|
21126
|
+
}
|
|
21127
|
+
currentSegment += char;
|
|
21128
|
+
}
|
|
21129
|
+
|
|
21130
|
+
// Push any remaining segment after splitting on dots
|
|
21131
|
+
if (currentSegment) {
|
|
21132
|
+
segments.push(...currentSegment.split('.').filter(Boolean));
|
|
21133
|
+
}
|
|
21134
|
+
return segments;
|
|
21135
|
+
}
|
|
21136
|
+
function createStandardIssues(error, parentPath) {
|
|
21137
|
+
const path = parentPath ? `${parentPath}.${error.path}` : error.path;
|
|
21138
|
+
return error.errors.map(err => ({
|
|
21139
|
+
message: err,
|
|
21140
|
+
path: createStandardPath(path)
|
|
21141
|
+
}));
|
|
21142
|
+
}
|
|
21143
|
+
function issuesFromValidationError(error, parentPath) {
|
|
21144
|
+
var _error$inner;
|
|
21145
|
+
if (!((_error$inner = error.inner) != null && _error$inner.length) && error.errors.length) {
|
|
21146
|
+
return createStandardIssues(error, parentPath);
|
|
21147
|
+
}
|
|
21148
|
+
const path = parentPath ? `${parentPath}.${error.path}` : error.path;
|
|
21149
|
+
return error.inner.flatMap(err => issuesFromValidationError(err, path));
|
|
21150
|
+
}
|
|
21151
|
+
|
|
21051
21152
|
// If `CustomSchemaMeta` isn't extended with any keys, we'll fall back to a
|
|
21052
21153
|
// loose Record definition allowing free form usage.
|
|
21053
21154
|
class Schema {
|
|
@@ -21615,13 +21716,41 @@ class Schema {
|
|
|
21615
21716
|
type: next.type,
|
|
21616
21717
|
oneOf: next._whitelist.describe(),
|
|
21617
21718
|
notOneOf: next._blacklist.describe(),
|
|
21618
|
-
tests: next.tests.map(fn =>
|
|
21619
|
-
|
|
21620
|
-
|
|
21621
|
-
|
|
21719
|
+
tests: next.tests.filter((n, idx, list) => list.findIndex(c => c.OPTIONS.name === n.OPTIONS.name) === idx).map(fn => {
|
|
21720
|
+
const params = fn.OPTIONS.params && options ? resolveParams(Object.assign({}, fn.OPTIONS.params), options) : fn.OPTIONS.params;
|
|
21721
|
+
return {
|
|
21722
|
+
name: fn.OPTIONS.name,
|
|
21723
|
+
params
|
|
21724
|
+
};
|
|
21725
|
+
})
|
|
21622
21726
|
};
|
|
21623
21727
|
return description;
|
|
21624
21728
|
}
|
|
21729
|
+
get ['~standard']() {
|
|
21730
|
+
const schema = this;
|
|
21731
|
+
const standard = {
|
|
21732
|
+
version: 1,
|
|
21733
|
+
vendor: 'yup',
|
|
21734
|
+
async validate(value) {
|
|
21735
|
+
try {
|
|
21736
|
+
const result = await schema.validate(value, {
|
|
21737
|
+
abortEarly: false
|
|
21738
|
+
});
|
|
21739
|
+
return {
|
|
21740
|
+
value: result
|
|
21741
|
+
};
|
|
21742
|
+
} catch (err) {
|
|
21743
|
+
if (err instanceof ValidationError) {
|
|
21744
|
+
return {
|
|
21745
|
+
issues: issuesFromValidationError(err)
|
|
21746
|
+
};
|
|
21747
|
+
}
|
|
21748
|
+
throw err;
|
|
21749
|
+
}
|
|
21750
|
+
}
|
|
21751
|
+
};
|
|
21752
|
+
return standard;
|
|
21753
|
+
}
|
|
21625
21754
|
}
|
|
21626
21755
|
// @ts-expect-error
|
|
21627
21756
|
Schema.prototype.__isYupSchema__ = true;
|
|
@@ -22605,7 +22734,10 @@ var createValidationSchema = function (fields) {
|
|
|
22605
22734
|
switch (field.type) {
|
|
22606
22735
|
case "checkbox":
|
|
22607
22736
|
case "checklist":
|
|
22608
|
-
fieldSchema_1 = create$2()
|
|
22737
|
+
fieldSchema_1 = create$2()
|
|
22738
|
+
.of(create$6())
|
|
22739
|
+
.min(1, field.validations[0].params[0] ||
|
|
22740
|
+
"El campo ".concat(field.label || field.name || "sin nombre", " es requerido"));
|
|
22609
22741
|
break;
|
|
22610
22742
|
case "upload":
|
|
22611
22743
|
fieldSchema_1 = create$8();
|
|
@@ -22649,6 +22781,24 @@ var createValidationSchema = function (fields) {
|
|
|
22649
22781
|
return validate(clean(value));
|
|
22650
22782
|
});
|
|
22651
22783
|
}
|
|
22784
|
+
else if (customValidator === "otra-medida") {
|
|
22785
|
+
fieldSchema_1 = fieldSchema_1.test("otra-medida", validation.params[1] ||
|
|
22786
|
+
"Debe detallar cuál es la medida de resguardo", function (value) {
|
|
22787
|
+
// Si no incluye "otra-medida", la validación pasa
|
|
22788
|
+
if (!value.includes("otra-medida"))
|
|
22789
|
+
return true;
|
|
22790
|
+
// Si incluye "otra-medida", debe tener "otra-medida-value-text" con texto
|
|
22791
|
+
var otraMedidaValue = value.find(function (opt) {
|
|
22792
|
+
return opt.startsWith("otra-medida-value-");
|
|
22793
|
+
});
|
|
22794
|
+
if (otraMedidaValue) {
|
|
22795
|
+
var text = otraMedidaValue.split("otra-medida-value-")[1];
|
|
22796
|
+
return text && text.trim() !== "";
|
|
22797
|
+
}
|
|
22798
|
+
// Si incluye "otra-medida" pero no tiene "otra-medida-value-text" con texto
|
|
22799
|
+
return false;
|
|
22800
|
+
});
|
|
22801
|
+
}
|
|
22652
22802
|
else {
|
|
22653
22803
|
fieldSchema_1 = fieldSchema_1.test("custom", validation.params[1] ||
|
|
22654
22804
|
"Validaci\u00F3n fallida para ".concat(field.label || field.name || "sin nombre"), function (value) {
|
|
@@ -22707,6 +22857,13 @@ var commonValidations = {
|
|
|
22707
22857
|
type: "pattern",
|
|
22708
22858
|
params: [regex, message || "Formato inválido"],
|
|
22709
22859
|
}); },
|
|
22860
|
+
otraMedidaRequired: function (message) { return ({
|
|
22861
|
+
type: "custom",
|
|
22862
|
+
params: [
|
|
22863
|
+
"otra-medida",
|
|
22864
|
+
message || "Debe detallar cuál es la medida de resguardo",
|
|
22865
|
+
],
|
|
22866
|
+
}); },
|
|
22710
22867
|
};
|
|
22711
22868
|
|
|
22712
22869
|
var FormStepper = function (_a) {
|
|
@@ -22840,6 +22997,7 @@ var GenericForm = function (_a) {
|
|
|
22840
22997
|
validationError_1 = _a.sent();
|
|
22841
22998
|
newErrors_1 = {};
|
|
22842
22999
|
if (validationError_1.inner) {
|
|
23000
|
+
console.log(validationError_1);
|
|
22843
23001
|
validationError_1.inner.forEach(function (error) {
|
|
22844
23002
|
newErrors_1[error.path] = error.message;
|
|
22845
23003
|
});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -121,4 +121,5 @@ export interface CommonValidations {
|
|
|
121
121
|
max: (length: number, message?: string) => ValidationRule;
|
|
122
122
|
email: (message?: string) => ValidationRule;
|
|
123
123
|
pattern: (regex: string, message?: string) => ValidationRule;
|
|
124
|
+
otraMedidaRequired: (message?: string) => ValidationRule;
|
|
124
125
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visiion/forms-library",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "Librería de componentes de formularios reutilizables",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"test": "jest",
|
|
20
20
|
"lint": "eslint src --ext .ts,.tsx",
|
|
21
21
|
"format": "prettier --write src/**/*.{ts,tsx}",
|
|
22
|
-
"prepare": "
|
|
22
|
+
"prepare": "npm run build"
|
|
23
23
|
},
|
|
24
24
|
"keywords": [
|
|
25
25
|
"react",
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"@typescript-eslint/eslint-plugin": "^8.31.0",
|
|
57
57
|
"@typescript-eslint/parser": "^8.31.0",
|
|
58
58
|
"autoprefixer": "^10.4.21",
|
|
59
|
-
"eslint": "^9.
|
|
60
|
-
"eslint-plugin-react": "^7.
|
|
61
|
-
"eslint-plugin-react-hooks": "^
|
|
59
|
+
"eslint": "^9.33.0",
|
|
60
|
+
"eslint-plugin-react": "^7.37.5",
|
|
61
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
62
62
|
"postcss": "^8.4.35",
|
|
63
63
|
"prettier": "^3.3.2",
|
|
64
64
|
"rollup": "^4.9.4",
|