@visiion/forms-library 1.4.3 → 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/index.esm.js
CHANGED
|
@@ -10345,14 +10345,14 @@ var RutInput = function (_a) {
|
|
|
10345
10345
|
// Manejar búsqueda
|
|
10346
10346
|
var handleSearch = function () {
|
|
10347
10347
|
if (onSearch && value && isValidRut) {
|
|
10348
|
-
onSearch(clean(displayValue));
|
|
10348
|
+
onSearch({ value: clean(displayValue) });
|
|
10349
10349
|
}
|
|
10350
10350
|
};
|
|
10351
10351
|
// Manejar tecla Enter para búsqueda
|
|
10352
10352
|
var handleKeyDown = function (e) {
|
|
10353
10353
|
if (e.key === "Enter" && onSearch && value && isValidRut) {
|
|
10354
10354
|
e.preventDefault();
|
|
10355
|
-
onSearch(clean(displayValue));
|
|
10355
|
+
onSearch({ value: clean(displayValue) });
|
|
10356
10356
|
}
|
|
10357
10357
|
};
|
|
10358
10358
|
return (jsxs("div", { className: "flex flex-col gap-1", children: [jsx("label", { htmlFor: field.id, className: "font-medium text-gray-700", children: field.label }), jsxs("div", { className: "flex", children: [jsx("input", { ref: inputRef, id: field.id, name: field.name, type: "text", value: displayValue || "", onChange: handleRutChange, onKeyDown: handleKeyDown, placeholder: placeholder, minLength: minLength, maxLength: maxLength, disabled: disabled, className: "flex-1 px-3 py-2 border rounded-l-md focus:outline-none focus:ring-2 focus:ring-orange-500 h-10 ".concat(error ? "border-red-500" : "border-gray-300", " ").concat(disabled ? "bg-gray-100 cursor-not-allowed" : "") }), onSearch && (jsx(Button, { type: "button", color: "blue", className: "flex items-center justify-center w-10 h-10 rounded-none rounded-tr-md rounded-br-md border-l-0", onClick: handleSearch, disabled: !isValidRut || disabled, children: jsx(IoMdSearch, { className: "w-5 h-5" }) }))] }), error && jsx("span", { className: "text-red-500 text-sm", children: error }), displayValue && !error && (jsx("span", { className: "text-sm ".concat(isValidRut ? "text-green-600" : "text-orange-600"), children: isValidRut ? "✓ RUT válido" : "⚠ Verificar formato del RUT" }))] }));
|
|
@@ -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;
|
|
@@ -19751,7 +19751,9 @@ var AddressInput = function (_a) {
|
|
|
19751
19751
|
localStorage.setItem("lastLocation", JSON.stringify(newLocation));
|
|
19752
19752
|
var addressComponents = extractAddressComponents(place, newLocation);
|
|
19753
19753
|
if (onSearch) {
|
|
19754
|
-
onSearch(
|
|
19754
|
+
onSearch({
|
|
19755
|
+
value: __assign(__assign({}, addressComponents), { address: place.formatted_address }),
|
|
19756
|
+
});
|
|
19755
19757
|
}
|
|
19756
19758
|
}
|
|
19757
19759
|
}
|
|
@@ -19789,7 +19791,9 @@ var AddressInput = function (_a) {
|
|
|
19789
19791
|
if (address) {
|
|
19790
19792
|
addressComponents = extractAddressComponents(address, newLocation);
|
|
19791
19793
|
if (onSearch) {
|
|
19792
|
-
onSearch(
|
|
19794
|
+
onSearch({
|
|
19795
|
+
value: __assign(__assign({}, addressComponents), { address: address.formatted_address }),
|
|
19796
|
+
});
|
|
19793
19797
|
}
|
|
19794
19798
|
}
|
|
19795
19799
|
return [3 /*break*/, 4];
|
|
@@ -19826,7 +19830,9 @@ var AddressInput = function (_a) {
|
|
|
19826
19830
|
if (response.results[0]) {
|
|
19827
19831
|
addressComponents = extractAddressComponents(response.results[0], newLocation);
|
|
19828
19832
|
if (onSearch) {
|
|
19829
|
-
onSearch(
|
|
19833
|
+
onSearch({
|
|
19834
|
+
value: __assign(__assign({}, addressComponents), { address: response.results[0].formatted_address }),
|
|
19835
|
+
});
|
|
19830
19836
|
}
|
|
19831
19837
|
}
|
|
19832
19838
|
return [3 /*break*/, 4];
|
|
@@ -19952,8 +19958,8 @@ var Alert = function (_a) {
|
|
|
19952
19958
|
};
|
|
19953
19959
|
|
|
19954
19960
|
var DatePicker = function (_a) {
|
|
19955
|
-
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;
|
|
19956
|
-
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" : "") }) }));
|
|
19957
19963
|
};
|
|
19958
19964
|
|
|
19959
19965
|
var SwornDeclaration = function (_a) {
|
|
@@ -19982,7 +19988,7 @@ var SwornDeclaration = function (_a) {
|
|
|
19982
19988
|
};
|
|
19983
19989
|
|
|
19984
19990
|
var StatusScreen = function (_a) {
|
|
19985
|
-
var title = _a.title, message = _a.message, _b = _a.type, type = _b === void 0 ? "info" : _b, leftButton = _a.leftButton, rightButton = _a.rightButton;
|
|
19991
|
+
var title = _a.title, message = _a.message, _b = _a.type, type = _b === void 0 ? "info" : _b, leftButton = _a.leftButton, rightButton = _a.rightButton, onSearch = _a.onSearch;
|
|
19986
19992
|
var getStatusStyles = function () {
|
|
19987
19993
|
switch (type) {
|
|
19988
19994
|
case "success":
|
|
@@ -20007,7 +20013,11 @@ var StatusScreen = function (_a) {
|
|
|
20007
20013
|
return (jsx("svg", { className: "w-28 h-28 text-blue-600", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }));
|
|
20008
20014
|
}
|
|
20009
20015
|
};
|
|
20010
|
-
return (jsx("div", { className: "col-span-12", children: jsxs("div", { className: "flex flex-col items-center p-8 ".concat(getStatusStyles()), children: [jsx("div", { className: "mb-4", children: getIcon() }), title && (jsx("h2", { className: "text-2xl font-bold text-center mb-4", children: title })), message && jsx("p", { className: "text-center mb-6 max-w-md", children: message }), (leftButton || rightButton) && (jsxs("div", { className: "flex space-x-4", children: [leftButton && (jsx("button", { onClick:
|
|
20016
|
+
return (jsx("div", { className: "col-span-12", children: jsxs("div", { className: "flex flex-col items-center p-8 ".concat(getStatusStyles()), children: [jsx("div", { className: "mb-4", children: getIcon() }), title && (jsx("h2", { className: "text-2xl font-bold text-center mb-4", children: title })), message && jsx("p", { className: "text-center mb-6 max-w-md", children: message }), (leftButton || rightButton) && (jsxs("div", { className: "flex space-x-4", children: [leftButton && (jsx("button", { onClick: function () {
|
|
20017
|
+
onSearch === null || onSearch === void 0 ? void 0 : onSearch({ value: "LEFT" });
|
|
20018
|
+
}, className: "px-6 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-gray-500", children: leftButton.label })), rightButton && (jsx("button", { onClick: function () {
|
|
20019
|
+
onSearch === null || onSearch === void 0 ? void 0 : onSearch({ value: "RIGHT" });
|
|
20020
|
+
}, className: "px-6 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500", children: rightButton.label }))] }))] }) }));
|
|
20011
20021
|
};
|
|
20012
20022
|
|
|
20013
20023
|
var Typography = function (_a) {
|
|
@@ -20021,6 +20031,7 @@ var Checklist = function (_a) {
|
|
|
20021
20031
|
var _c = useState(value), selectedOptions = _c[0], setSelectedOptions = _c[1];
|
|
20022
20032
|
var _d = useState(props.valueOtraMedida), otraMedida = _d[0], setOtraMedida = _d[1];
|
|
20023
20033
|
var options = field.options || [];
|
|
20034
|
+
var isOtraMedidaRequired = selectedOptions.includes("otra-medida");
|
|
20024
20035
|
useEffect(function () {
|
|
20025
20036
|
setSelectedOptions(value);
|
|
20026
20037
|
}, [value]);
|
|
@@ -20044,6 +20055,10 @@ var Checklist = function (_a) {
|
|
|
20044
20055
|
}
|
|
20045
20056
|
else {
|
|
20046
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
|
+
}
|
|
20047
20062
|
}
|
|
20048
20063
|
setSelectedOptions(newSelectedOptions);
|
|
20049
20064
|
onChange === null || onChange === void 0 ? void 0 : onChange(newSelectedOptions);
|
|
@@ -20052,17 +20067,17 @@ var Checklist = function (_a) {
|
|
|
20052
20067
|
var _a;
|
|
20053
20068
|
setOtraMedida(text);
|
|
20054
20069
|
// Actualizar el valor con la otra medida
|
|
20055
|
-
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
|
|
20056
20072
|
if (text.trim()) {
|
|
20057
|
-
updatedOptions.push("otra-medida");
|
|
20073
|
+
updatedOptions.push("otra-medida-value-".concat(text));
|
|
20058
20074
|
}
|
|
20059
20075
|
onChange === null || onChange === void 0 ? void 0 : onChange(updatedOptions);
|
|
20060
20076
|
(_a = props.onOtraMedidaChange) === null || _a === void 0 ? void 0 : _a.call(props, text);
|
|
20061
20077
|
};
|
|
20062
|
-
var isOtraMedidaRequired = selectedOptions.includes("otra-medida");
|
|
20063
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) {
|
|
20064
20079
|
return handleOptionChange(option.value, e.target.checked);
|
|
20065
|
-
}, 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 }))] }));
|
|
20066
20081
|
};
|
|
20067
20082
|
|
|
20068
20083
|
var Upload = function (_a) {
|
|
@@ -20847,19 +20862,20 @@ function createValidation(config) {
|
|
|
20847
20862
|
abortEarly = schema.spec.abortEarly,
|
|
20848
20863
|
disableStackTrace = schema.spec.disableStackTrace
|
|
20849
20864
|
} = options;
|
|
20850
|
-
|
|
20851
|
-
|
|
20852
|
-
|
|
20865
|
+
const resolveOptions = {
|
|
20866
|
+
value,
|
|
20867
|
+
parent,
|
|
20868
|
+
context
|
|
20869
|
+
};
|
|
20853
20870
|
function createError(overrides = {}) {
|
|
20854
|
-
const nextParams = Object.assign({
|
|
20871
|
+
const nextParams = resolveParams(Object.assign({
|
|
20855
20872
|
value,
|
|
20856
20873
|
originalValue,
|
|
20857
20874
|
label: schema.spec.label,
|
|
20858
20875
|
path: overrides.path || path,
|
|
20859
20876
|
spec: schema.spec,
|
|
20860
20877
|
disableStackTrace: overrides.disableStackTrace || disableStackTrace
|
|
20861
|
-
}, params, overrides.params);
|
|
20862
|
-
for (const key of Object.keys(nextParams)) nextParams[key] = resolve(nextParams[key]);
|
|
20878
|
+
}, params, overrides.params), resolveOptions);
|
|
20863
20879
|
const error = new ValidationError(ValidationError.formatError(overrides.message || message, nextParams), value, nextParams.path, overrides.type || name, nextParams.disableStackTrace);
|
|
20864
20880
|
error.params = nextParams;
|
|
20865
20881
|
return error;
|
|
@@ -20871,7 +20887,9 @@ function createValidation(config) {
|
|
|
20871
20887
|
type: name,
|
|
20872
20888
|
from: options.from,
|
|
20873
20889
|
createError,
|
|
20874
|
-
resolve
|
|
20890
|
+
resolve(item) {
|
|
20891
|
+
return resolveMaybeRef(item, resolveOptions);
|
|
20892
|
+
},
|
|
20875
20893
|
options,
|
|
20876
20894
|
originalValue,
|
|
20877
20895
|
schema
|
|
@@ -20906,6 +20924,18 @@ function createValidation(config) {
|
|
|
20906
20924
|
return validate;
|
|
20907
20925
|
}
|
|
20908
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
|
+
|
|
20909
20939
|
function getIn(schema, path, value, context = value) {
|
|
20910
20940
|
let parent, lastPart, lastPartDebug;
|
|
20911
20941
|
|
|
@@ -21019,6 +21049,87 @@ function clone(src, seen = new Map()) {
|
|
|
21019
21049
|
return copy;
|
|
21020
21050
|
}
|
|
21021
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
|
+
|
|
21022
21133
|
// If `CustomSchemaMeta` isn't extended with any keys, we'll fall back to a
|
|
21023
21134
|
// loose Record definition allowing free form usage.
|
|
21024
21135
|
class Schema {
|
|
@@ -21586,13 +21697,41 @@ class Schema {
|
|
|
21586
21697
|
type: next.type,
|
|
21587
21698
|
oneOf: next._whitelist.describe(),
|
|
21588
21699
|
notOneOf: next._blacklist.describe(),
|
|
21589
|
-
tests: next.tests.map(fn =>
|
|
21590
|
-
|
|
21591
|
-
|
|
21592
|
-
|
|
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
|
+
})
|
|
21593
21707
|
};
|
|
21594
21708
|
return description;
|
|
21595
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
|
+
}
|
|
21596
21735
|
}
|
|
21597
21736
|
// @ts-expect-error
|
|
21598
21737
|
Schema.prototype.__isYupSchema__ = true;
|
|
@@ -22576,7 +22715,10 @@ var createValidationSchema = function (fields) {
|
|
|
22576
22715
|
switch (field.type) {
|
|
22577
22716
|
case "checkbox":
|
|
22578
22717
|
case "checklist":
|
|
22579
|
-
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"));
|
|
22580
22722
|
break;
|
|
22581
22723
|
case "upload":
|
|
22582
22724
|
fieldSchema_1 = create$8();
|
|
@@ -22620,6 +22762,24 @@ var createValidationSchema = function (fields) {
|
|
|
22620
22762
|
return validate(clean(value));
|
|
22621
22763
|
});
|
|
22622
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
|
+
}
|
|
22623
22783
|
else {
|
|
22624
22784
|
fieldSchema_1 = fieldSchema_1.test("custom", validation.params[1] ||
|
|
22625
22785
|
"Validaci\u00F3n fallida para ".concat(field.label || field.name || "sin nombre"), function (value) {
|
|
@@ -22678,6 +22838,13 @@ var commonValidations = {
|
|
|
22678
22838
|
type: "pattern",
|
|
22679
22839
|
params: [regex, message || "Formato inválido"],
|
|
22680
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
|
+
}); },
|
|
22681
22848
|
};
|
|
22682
22849
|
|
|
22683
22850
|
var FormStepper = function (_a) {
|
|
@@ -22811,6 +22978,7 @@ var GenericForm = function (_a) {
|
|
|
22811
22978
|
validationError_1 = _a.sent();
|
|
22812
22979
|
newErrors_1 = {};
|
|
22813
22980
|
if (validationError_1.inner) {
|
|
22981
|
+
console.log(validationError_1);
|
|
22814
22982
|
validationError_1.inner.forEach(function (error) {
|
|
22815
22983
|
newErrors_1[error.path] = error.message;
|
|
22816
22984
|
});
|
|
@@ -22855,14 +23023,13 @@ var GenericForm = function (_a) {
|
|
|
22855
23023
|
// Prioridad: field.value > formData > getFieldValue
|
|
22856
23024
|
var fieldValue = (_b = (_a = formData[field.name]) !== null && _a !== void 0 ? _a : field.value) !== null && _b !== void 0 ? _b : getFieldValue(field);
|
|
22857
23025
|
// Preparar el campo con las funciones de búsqueda si están disponibles
|
|
22858
|
-
var fieldWithHandlers = __assign(__assign({}, field), {
|
|
22859
|
-
|
|
23026
|
+
var fieldWithHandlers = __assign(__assign({}, field), {
|
|
23027
|
+
// ... existing code ...
|
|
23028
|
+
onSearch: function (_a) {
|
|
23029
|
+
var _b;
|
|
23030
|
+
_a.field; var value = _a.value; _a.formData;
|
|
22860
23031
|
if (field.onSearch) {
|
|
22861
|
-
|
|
22862
|
-
field: searchField || field,
|
|
22863
|
-
value: value,
|
|
22864
|
-
formData: searchFormData || __assign(__assign({}, stepperData), formData),
|
|
22865
|
-
});
|
|
23032
|
+
(_b = config === null || config === void 0 ? void 0 : config.onSearch) === null || _b === void 0 ? void 0 : _b.call(config, field, value !== null && value !== void 0 ? value : "", __assign(__assign({}, stepperData), formData));
|
|
22866
23033
|
}
|
|
22867
23034
|
} });
|
|
22868
23035
|
return (jsx("div", { className: (_c = field.className) !== null && _c !== void 0 ? _c : "col-span-12 md:col-span-6", children: jsx(DynamicInput, { field: fieldWithHandlers, value: fieldValue, onChange: handleInputChange, error: errors[field.name], formData: formData }) }, field.id));
|
package/dist/index.js
CHANGED
|
@@ -10364,14 +10364,14 @@ var RutInput = function (_a) {
|
|
|
10364
10364
|
// Manejar búsqueda
|
|
10365
10365
|
var handleSearch = function () {
|
|
10366
10366
|
if (onSearch && value && isValidRut) {
|
|
10367
|
-
onSearch(clean(displayValue));
|
|
10367
|
+
onSearch({ value: clean(displayValue) });
|
|
10368
10368
|
}
|
|
10369
10369
|
};
|
|
10370
10370
|
// Manejar tecla Enter para búsqueda
|
|
10371
10371
|
var handleKeyDown = function (e) {
|
|
10372
10372
|
if (e.key === "Enter" && onSearch && value && isValidRut) {
|
|
10373
10373
|
e.preventDefault();
|
|
10374
|
-
onSearch(clean(displayValue));
|
|
10374
|
+
onSearch({ value: clean(displayValue) });
|
|
10375
10375
|
}
|
|
10376
10376
|
};
|
|
10377
10377
|
return (jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [jsxRuntime.jsx("label", { htmlFor: field.id, className: "font-medium text-gray-700", children: field.label }), jsxRuntime.jsxs("div", { className: "flex", children: [jsxRuntime.jsx("input", { ref: inputRef, id: field.id, name: field.name, type: "text", value: displayValue || "", onChange: handleRutChange, onKeyDown: handleKeyDown, placeholder: placeholder, minLength: minLength, maxLength: maxLength, disabled: disabled, className: "flex-1 px-3 py-2 border rounded-l-md focus:outline-none focus:ring-2 focus:ring-orange-500 h-10 ".concat(error ? "border-red-500" : "border-gray-300", " ").concat(disabled ? "bg-gray-100 cursor-not-allowed" : "") }), onSearch && (jsxRuntime.jsx(flowbiteReact.Button, { type: "button", color: "blue", className: "flex items-center justify-center w-10 h-10 rounded-none rounded-tr-md rounded-br-md border-l-0", onClick: handleSearch, disabled: !isValidRut || disabled, children: jsxRuntime.jsx(IoMdSearch, { className: "w-5 h-5" }) }))] }), error && jsxRuntime.jsx("span", { className: "text-red-500 text-sm", children: error }), displayValue && !error && (jsxRuntime.jsx("span", { className: "text-sm ".concat(isValidRut ? "text-green-600" : "text-orange-600"), children: isValidRut ? "✓ RUT válido" : "⚠ Verificar formato del RUT" }))] }));
|
|
@@ -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;
|
|
@@ -19770,7 +19770,9 @@ var AddressInput = function (_a) {
|
|
|
19770
19770
|
localStorage.setItem("lastLocation", JSON.stringify(newLocation));
|
|
19771
19771
|
var addressComponents = extractAddressComponents(place, newLocation);
|
|
19772
19772
|
if (onSearch) {
|
|
19773
|
-
onSearch(
|
|
19773
|
+
onSearch({
|
|
19774
|
+
value: __assign(__assign({}, addressComponents), { address: place.formatted_address }),
|
|
19775
|
+
});
|
|
19774
19776
|
}
|
|
19775
19777
|
}
|
|
19776
19778
|
}
|
|
@@ -19808,7 +19810,9 @@ var AddressInput = function (_a) {
|
|
|
19808
19810
|
if (address) {
|
|
19809
19811
|
addressComponents = extractAddressComponents(address, newLocation);
|
|
19810
19812
|
if (onSearch) {
|
|
19811
|
-
onSearch(
|
|
19813
|
+
onSearch({
|
|
19814
|
+
value: __assign(__assign({}, addressComponents), { address: address.formatted_address }),
|
|
19815
|
+
});
|
|
19812
19816
|
}
|
|
19813
19817
|
}
|
|
19814
19818
|
return [3 /*break*/, 4];
|
|
@@ -19845,7 +19849,9 @@ var AddressInput = function (_a) {
|
|
|
19845
19849
|
if (response.results[0]) {
|
|
19846
19850
|
addressComponents = extractAddressComponents(response.results[0], newLocation);
|
|
19847
19851
|
if (onSearch) {
|
|
19848
|
-
onSearch(
|
|
19852
|
+
onSearch({
|
|
19853
|
+
value: __assign(__assign({}, addressComponents), { address: response.results[0].formatted_address }),
|
|
19854
|
+
});
|
|
19849
19855
|
}
|
|
19850
19856
|
}
|
|
19851
19857
|
return [3 /*break*/, 4];
|
|
@@ -19971,8 +19977,8 @@ var Alert = function (_a) {
|
|
|
19971
19977
|
};
|
|
19972
19978
|
|
|
19973
19979
|
var DatePicker = function (_a) {
|
|
19974
|
-
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;
|
|
19975
|
-
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" : "") }) }));
|
|
19976
19982
|
};
|
|
19977
19983
|
|
|
19978
19984
|
var SwornDeclaration = function (_a) {
|
|
@@ -20001,7 +20007,7 @@ var SwornDeclaration = function (_a) {
|
|
|
20001
20007
|
};
|
|
20002
20008
|
|
|
20003
20009
|
var StatusScreen = function (_a) {
|
|
20004
|
-
var title = _a.title, message = _a.message, _b = _a.type, type = _b === void 0 ? "info" : _b, leftButton = _a.leftButton, rightButton = _a.rightButton;
|
|
20010
|
+
var title = _a.title, message = _a.message, _b = _a.type, type = _b === void 0 ? "info" : _b, leftButton = _a.leftButton, rightButton = _a.rightButton, onSearch = _a.onSearch;
|
|
20005
20011
|
var getStatusStyles = function () {
|
|
20006
20012
|
switch (type) {
|
|
20007
20013
|
case "success":
|
|
@@ -20026,7 +20032,11 @@ var StatusScreen = function (_a) {
|
|
|
20026
20032
|
return (jsxRuntime.jsx("svg", { className: "w-28 h-28 text-blue-600", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }));
|
|
20027
20033
|
}
|
|
20028
20034
|
};
|
|
20029
|
-
return (jsxRuntime.jsx("div", { className: "col-span-12", children: jsxRuntime.jsxs("div", { className: "flex flex-col items-center p-8 ".concat(getStatusStyles()), children: [jsxRuntime.jsx("div", { className: "mb-4", children: getIcon() }), title && (jsxRuntime.jsx("h2", { className: "text-2xl font-bold text-center mb-4", children: title })), message && jsxRuntime.jsx("p", { className: "text-center mb-6 max-w-md", children: message }), (leftButton || rightButton) && (jsxRuntime.jsxs("div", { className: "flex space-x-4", children: [leftButton && (jsxRuntime.jsx("button", { onClick:
|
|
20035
|
+
return (jsxRuntime.jsx("div", { className: "col-span-12", children: jsxRuntime.jsxs("div", { className: "flex flex-col items-center p-8 ".concat(getStatusStyles()), children: [jsxRuntime.jsx("div", { className: "mb-4", children: getIcon() }), title && (jsxRuntime.jsx("h2", { className: "text-2xl font-bold text-center mb-4", children: title })), message && jsxRuntime.jsx("p", { className: "text-center mb-6 max-w-md", children: message }), (leftButton || rightButton) && (jsxRuntime.jsxs("div", { className: "flex space-x-4", children: [leftButton && (jsxRuntime.jsx("button", { onClick: function () {
|
|
20036
|
+
onSearch === null || onSearch === void 0 ? void 0 : onSearch({ value: "LEFT" });
|
|
20037
|
+
}, className: "px-6 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-gray-500", children: leftButton.label })), rightButton && (jsxRuntime.jsx("button", { onClick: function () {
|
|
20038
|
+
onSearch === null || onSearch === void 0 ? void 0 : onSearch({ value: "RIGHT" });
|
|
20039
|
+
}, className: "px-6 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500", children: rightButton.label }))] }))] }) }));
|
|
20030
20040
|
};
|
|
20031
20041
|
|
|
20032
20042
|
var Typography = function (_a) {
|
|
@@ -20040,6 +20050,7 @@ var Checklist = function (_a) {
|
|
|
20040
20050
|
var _c = React.useState(value), selectedOptions = _c[0], setSelectedOptions = _c[1];
|
|
20041
20051
|
var _d = React.useState(props.valueOtraMedida), otraMedida = _d[0], setOtraMedida = _d[1];
|
|
20042
20052
|
var options = field.options || [];
|
|
20053
|
+
var isOtraMedidaRequired = selectedOptions.includes("otra-medida");
|
|
20043
20054
|
React.useEffect(function () {
|
|
20044
20055
|
setSelectedOptions(value);
|
|
20045
20056
|
}, [value]);
|
|
@@ -20063,6 +20074,10 @@ var Checklist = function (_a) {
|
|
|
20063
20074
|
}
|
|
20064
20075
|
else {
|
|
20065
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
|
+
}
|
|
20066
20081
|
}
|
|
20067
20082
|
setSelectedOptions(newSelectedOptions);
|
|
20068
20083
|
onChange === null || onChange === void 0 ? void 0 : onChange(newSelectedOptions);
|
|
@@ -20071,17 +20086,17 @@ var Checklist = function (_a) {
|
|
|
20071
20086
|
var _a;
|
|
20072
20087
|
setOtraMedida(text);
|
|
20073
20088
|
// Actualizar el valor con la otra medida
|
|
20074
|
-
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
|
|
20075
20091
|
if (text.trim()) {
|
|
20076
|
-
updatedOptions.push("otra-medida");
|
|
20092
|
+
updatedOptions.push("otra-medida-value-".concat(text));
|
|
20077
20093
|
}
|
|
20078
20094
|
onChange === null || onChange === void 0 ? void 0 : onChange(updatedOptions);
|
|
20079
20095
|
(_a = props.onOtraMedidaChange) === null || _a === void 0 ? void 0 : _a.call(props, text);
|
|
20080
20096
|
};
|
|
20081
|
-
var isOtraMedidaRequired = selectedOptions.includes("otra-medida");
|
|
20082
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) {
|
|
20083
20098
|
return handleOptionChange(option.value, e.target.checked);
|
|
20084
|
-
}, 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 }))] }));
|
|
20085
20100
|
};
|
|
20086
20101
|
|
|
20087
20102
|
var Upload = function (_a) {
|
|
@@ -20866,19 +20881,20 @@ function createValidation(config) {
|
|
|
20866
20881
|
abortEarly = schema.spec.abortEarly,
|
|
20867
20882
|
disableStackTrace = schema.spec.disableStackTrace
|
|
20868
20883
|
} = options;
|
|
20869
|
-
|
|
20870
|
-
|
|
20871
|
-
|
|
20884
|
+
const resolveOptions = {
|
|
20885
|
+
value,
|
|
20886
|
+
parent,
|
|
20887
|
+
context
|
|
20888
|
+
};
|
|
20872
20889
|
function createError(overrides = {}) {
|
|
20873
|
-
const nextParams = Object.assign({
|
|
20890
|
+
const nextParams = resolveParams(Object.assign({
|
|
20874
20891
|
value,
|
|
20875
20892
|
originalValue,
|
|
20876
20893
|
label: schema.spec.label,
|
|
20877
20894
|
path: overrides.path || path,
|
|
20878
20895
|
spec: schema.spec,
|
|
20879
20896
|
disableStackTrace: overrides.disableStackTrace || disableStackTrace
|
|
20880
|
-
}, params, overrides.params);
|
|
20881
|
-
for (const key of Object.keys(nextParams)) nextParams[key] = resolve(nextParams[key]);
|
|
20897
|
+
}, params, overrides.params), resolveOptions);
|
|
20882
20898
|
const error = new ValidationError(ValidationError.formatError(overrides.message || message, nextParams), value, nextParams.path, overrides.type || name, nextParams.disableStackTrace);
|
|
20883
20899
|
error.params = nextParams;
|
|
20884
20900
|
return error;
|
|
@@ -20890,7 +20906,9 @@ function createValidation(config) {
|
|
|
20890
20906
|
type: name,
|
|
20891
20907
|
from: options.from,
|
|
20892
20908
|
createError,
|
|
20893
|
-
resolve
|
|
20909
|
+
resolve(item) {
|
|
20910
|
+
return resolveMaybeRef(item, resolveOptions);
|
|
20911
|
+
},
|
|
20894
20912
|
options,
|
|
20895
20913
|
originalValue,
|
|
20896
20914
|
schema
|
|
@@ -20925,6 +20943,18 @@ function createValidation(config) {
|
|
|
20925
20943
|
return validate;
|
|
20926
20944
|
}
|
|
20927
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
|
+
|
|
20928
20958
|
function getIn(schema, path, value, context = value) {
|
|
20929
20959
|
let parent, lastPart, lastPartDebug;
|
|
20930
20960
|
|
|
@@ -21038,6 +21068,87 @@ function clone(src, seen = new Map()) {
|
|
|
21038
21068
|
return copy;
|
|
21039
21069
|
}
|
|
21040
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
|
+
|
|
21041
21152
|
// If `CustomSchemaMeta` isn't extended with any keys, we'll fall back to a
|
|
21042
21153
|
// loose Record definition allowing free form usage.
|
|
21043
21154
|
class Schema {
|
|
@@ -21605,13 +21716,41 @@ class Schema {
|
|
|
21605
21716
|
type: next.type,
|
|
21606
21717
|
oneOf: next._whitelist.describe(),
|
|
21607
21718
|
notOneOf: next._blacklist.describe(),
|
|
21608
|
-
tests: next.tests.map(fn =>
|
|
21609
|
-
|
|
21610
|
-
|
|
21611
|
-
|
|
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
|
+
})
|
|
21612
21726
|
};
|
|
21613
21727
|
return description;
|
|
21614
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
|
+
}
|
|
21615
21754
|
}
|
|
21616
21755
|
// @ts-expect-error
|
|
21617
21756
|
Schema.prototype.__isYupSchema__ = true;
|
|
@@ -22595,7 +22734,10 @@ var createValidationSchema = function (fields) {
|
|
|
22595
22734
|
switch (field.type) {
|
|
22596
22735
|
case "checkbox":
|
|
22597
22736
|
case "checklist":
|
|
22598
|
-
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"));
|
|
22599
22741
|
break;
|
|
22600
22742
|
case "upload":
|
|
22601
22743
|
fieldSchema_1 = create$8();
|
|
@@ -22639,6 +22781,24 @@ var createValidationSchema = function (fields) {
|
|
|
22639
22781
|
return validate(clean(value));
|
|
22640
22782
|
});
|
|
22641
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
|
+
}
|
|
22642
22802
|
else {
|
|
22643
22803
|
fieldSchema_1 = fieldSchema_1.test("custom", validation.params[1] ||
|
|
22644
22804
|
"Validaci\u00F3n fallida para ".concat(field.label || field.name || "sin nombre"), function (value) {
|
|
@@ -22697,6 +22857,13 @@ var commonValidations = {
|
|
|
22697
22857
|
type: "pattern",
|
|
22698
22858
|
params: [regex, message || "Formato inválido"],
|
|
22699
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
|
+
}); },
|
|
22700
22867
|
};
|
|
22701
22868
|
|
|
22702
22869
|
var FormStepper = function (_a) {
|
|
@@ -22830,6 +22997,7 @@ var GenericForm = function (_a) {
|
|
|
22830
22997
|
validationError_1 = _a.sent();
|
|
22831
22998
|
newErrors_1 = {};
|
|
22832
22999
|
if (validationError_1.inner) {
|
|
23000
|
+
console.log(validationError_1);
|
|
22833
23001
|
validationError_1.inner.forEach(function (error) {
|
|
22834
23002
|
newErrors_1[error.path] = error.message;
|
|
22835
23003
|
});
|
|
@@ -22874,14 +23042,13 @@ var GenericForm = function (_a) {
|
|
|
22874
23042
|
// Prioridad: field.value > formData > getFieldValue
|
|
22875
23043
|
var fieldValue = (_b = (_a = formData[field.name]) !== null && _a !== void 0 ? _a : field.value) !== null && _b !== void 0 ? _b : getFieldValue(field);
|
|
22876
23044
|
// Preparar el campo con las funciones de búsqueda si están disponibles
|
|
22877
|
-
var fieldWithHandlers = __assign(__assign({}, field), {
|
|
22878
|
-
|
|
23045
|
+
var fieldWithHandlers = __assign(__assign({}, field), {
|
|
23046
|
+
// ... existing code ...
|
|
23047
|
+
onSearch: function (_a) {
|
|
23048
|
+
var _b;
|
|
23049
|
+
_a.field; var value = _a.value; _a.formData;
|
|
22879
23050
|
if (field.onSearch) {
|
|
22880
|
-
|
|
22881
|
-
field: searchField || field,
|
|
22882
|
-
value: value,
|
|
22883
|
-
formData: searchFormData || __assign(__assign({}, stepperData), formData),
|
|
22884
|
-
});
|
|
23051
|
+
(_b = config === null || config === void 0 ? void 0 : config.onSearch) === null || _b === void 0 ? void 0 : _b.call(config, field, value !== null && value !== void 0 ? value : "", __assign(__assign({}, stepperData), formData));
|
|
22885
23052
|
}
|
|
22886
23053
|
} });
|
|
22887
23054
|
return (jsxRuntime.jsx("div", { className: (_c = field.className) !== null && _c !== void 0 ? _c : "col-span-12 md:col-span-6", children: jsxRuntime.jsx(DynamicInput, { field: fieldWithHandlers, value: fieldValue, onChange: handleInputChange, error: errors[field.name], formData: formData }) }, field.id));
|
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",
|
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
"@googlemaps/js-api-loader": "^1.16.6",
|
|
39
39
|
"@react-google-maps/api": "^2.19.3",
|
|
40
40
|
"@react-pdf/renderer": "^4.3.0",
|
|
41
|
+
"classnames": "^2.5.1",
|
|
42
|
+
"debounce": "^2.2.0",
|
|
41
43
|
"flowbite-react": "0.10.1",
|
|
42
44
|
"framer-motion": "^11.3.8",
|
|
43
45
|
"react-icons": "^5.5.0",
|
|
@@ -54,9 +56,9 @@
|
|
|
54
56
|
"@typescript-eslint/eslint-plugin": "^8.31.0",
|
|
55
57
|
"@typescript-eslint/parser": "^8.31.0",
|
|
56
58
|
"autoprefixer": "^10.4.21",
|
|
57
|
-
"eslint": "^9.
|
|
58
|
-
"eslint-plugin-react": "^7.
|
|
59
|
-
"eslint-plugin-react-hooks": "^
|
|
59
|
+
"eslint": "^9.33.0",
|
|
60
|
+
"eslint-plugin-react": "^7.37.5",
|
|
61
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
60
62
|
"postcss": "^8.4.35",
|
|
61
63
|
"prettier": "^3.3.2",
|
|
62
64
|
"rollup": "^4.9.4",
|
|
@@ -73,4 +75,4 @@
|
|
|
73
75
|
"url": "https://github.com/Kuantaz/forms-library/issues"
|
|
74
76
|
},
|
|
75
77
|
"homepage": "https://github.com/Kuantaz/forms-library#readme"
|
|
76
|
-
}
|
|
78
|
+
}
|