easy-forms-core 1.0.11 → 1.1.0
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/easy-form.js +85 -7
- package/dist/easy-form.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +85 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/easy-form.js
CHANGED
|
@@ -2019,6 +2019,26 @@ var StateManager = class {
|
|
|
2019
2019
|
}
|
|
2020
2020
|
return allFields;
|
|
2021
2021
|
}
|
|
2022
|
+
/**
|
|
2023
|
+
* Encuentra el path completo de un campo dentro de grupos
|
|
2024
|
+
*/
|
|
2025
|
+
findFieldPath(fieldName, fields, parentPath = "") {
|
|
2026
|
+
for (const field of fields) {
|
|
2027
|
+
const currentPath = parentPath ? `${parentPath}.${field.name}` : field.name;
|
|
2028
|
+
if (field.name === fieldName) {
|
|
2029
|
+
return currentPath;
|
|
2030
|
+
}
|
|
2031
|
+
if (field.type === "group" && "fields" in field) {
|
|
2032
|
+
const found = this.findFieldPath(fieldName, field.fields, currentPath);
|
|
2033
|
+
if (found) return found;
|
|
2034
|
+
}
|
|
2035
|
+
if (field.type === "row" && "fields" in field) {
|
|
2036
|
+
const found = this.findFieldPath(fieldName, field.fields, currentPath);
|
|
2037
|
+
if (found) return found;
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
return null;
|
|
2041
|
+
}
|
|
2022
2042
|
/**
|
|
2023
2043
|
* Construye el mapa de dependencias para optimizar re-evaluaciones
|
|
2024
2044
|
*/
|
|
@@ -2201,6 +2221,7 @@ var StateManager = class {
|
|
|
2201
2221
|
*/
|
|
2202
2222
|
setValueWithoutValidation(fieldName, value) {
|
|
2203
2223
|
setNestedValue(this.state.values, fieldName, value);
|
|
2224
|
+
this.invalidateDependencyCache(fieldName);
|
|
2204
2225
|
}
|
|
2205
2226
|
/**
|
|
2206
2227
|
* Valida un campo específico
|
|
@@ -2233,6 +2254,13 @@ var StateManager = class {
|
|
|
2233
2254
|
*/
|
|
2234
2255
|
getActiveValidations(field) {
|
|
2235
2256
|
let validations = [...field.validations || []];
|
|
2257
|
+
const isRequired = this.getFieldRequired(field.name);
|
|
2258
|
+
const hasRequiredValidation = validations.some((v) => v.type === "required");
|
|
2259
|
+
if (isRequired && !hasRequiredValidation) {
|
|
2260
|
+
validations = [{ type: "required" }, ...validations];
|
|
2261
|
+
} else if (!isRequired && hasRequiredValidation) {
|
|
2262
|
+
validations = validations.filter((v) => v.type !== "required");
|
|
2263
|
+
}
|
|
2236
2264
|
if (field.conditionalValidations) {
|
|
2237
2265
|
for (const conditional of field.conditionalValidations) {
|
|
2238
2266
|
const conditionMet = this.conditionEngine.evaluateConditions(
|
|
@@ -2365,13 +2393,41 @@ var StateManager = class {
|
|
|
2365
2393
|
if (!this.schema) return true;
|
|
2366
2394
|
const topLevelFields = this.schema.isWizard ? this.schema.steps.flatMap((step) => step.fields) : this.schema.fields || [];
|
|
2367
2395
|
const allFields = this.extractAllFields(topLevelFields);
|
|
2368
|
-
|
|
2396
|
+
let field = allFields.find((f) => {
|
|
2397
|
+
const fullPath = this.findFieldPath(f.name, topLevelFields);
|
|
2398
|
+
return fullPath === fieldName || f.name === fieldName;
|
|
2399
|
+
});
|
|
2400
|
+
if (!field) {
|
|
2401
|
+
field = allFields.find((f) => f.name === fieldName);
|
|
2402
|
+
}
|
|
2369
2403
|
if (!field || !field.dependencies) {
|
|
2370
2404
|
return !field?.hidden;
|
|
2371
2405
|
}
|
|
2406
|
+
const fieldFullPath = this.findFieldPath(field.name, topLevelFields) || field.name;
|
|
2407
|
+
const groupPath = fieldFullPath.includes(".") ? fieldFullPath.split(".").slice(0, -1).join(".") : "";
|
|
2408
|
+
let valuesContext = { ...this.state.values };
|
|
2409
|
+
if (groupPath && field.dependencies) {
|
|
2410
|
+
const groupValues = getNestedValue(this.state.values, groupPath);
|
|
2411
|
+
if (groupValues && typeof groupValues === "object") {
|
|
2412
|
+
const createRelativeContext = (obj, prefix = "") => {
|
|
2413
|
+
const result2 = {};
|
|
2414
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2415
|
+
const relativeKey = prefix ? `${prefix}.${key}` : key;
|
|
2416
|
+
if (value && typeof value === "object" && !Array.isArray(value) && value !== null) {
|
|
2417
|
+
Object.assign(result2, createRelativeContext(value, relativeKey));
|
|
2418
|
+
} else {
|
|
2419
|
+
result2[relativeKey] = value;
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
return result2;
|
|
2423
|
+
};
|
|
2424
|
+
const relativeContext = createRelativeContext(groupValues);
|
|
2425
|
+
valuesContext = { ...this.state.values, ...relativeContext };
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2372
2428
|
const result = this.conditionEngine.evaluateDependencies(
|
|
2373
2429
|
field.dependencies,
|
|
2374
|
-
|
|
2430
|
+
valuesContext
|
|
2375
2431
|
);
|
|
2376
2432
|
this.dependencyCache.set(fieldName, result);
|
|
2377
2433
|
return result.visible && !field.hidden;
|
|
@@ -2446,7 +2502,15 @@ var BaseInput = class {
|
|
|
2446
2502
|
*/
|
|
2447
2503
|
createFieldContainer(input) {
|
|
2448
2504
|
const container = document.createElement("div");
|
|
2449
|
-
|
|
2505
|
+
const inputClasses = Array.from(input.classList);
|
|
2506
|
+
const componentContainerClasses = inputClasses.filter(
|
|
2507
|
+
(cls) => cls.startsWith("easy-form-") && cls !== "easy-form-field" && (cls.includes("-container") || cls.includes("-wrapper"))
|
|
2508
|
+
);
|
|
2509
|
+
if (componentContainerClasses.length > 0) {
|
|
2510
|
+
container.className = `easy-form-field ${componentContainerClasses.join(" ")}`;
|
|
2511
|
+
} else {
|
|
2512
|
+
container.className = "easy-form-field";
|
|
2513
|
+
}
|
|
2450
2514
|
if (this.field.label) {
|
|
2451
2515
|
const label = document.createElement("label");
|
|
2452
2516
|
label.className = "easy-form-label";
|
|
@@ -2693,7 +2757,18 @@ var MaskEngine = class {
|
|
|
2693
2757
|
return value;
|
|
2694
2758
|
}
|
|
2695
2759
|
const customMask = this.getCustomMask(mask);
|
|
2696
|
-
const
|
|
2760
|
+
const editableTokens = tokens.filter((t) => t.editable);
|
|
2761
|
+
const acceptedTypes = new Set(editableTokens.map((t) => t.type));
|
|
2762
|
+
let unformatted = "";
|
|
2763
|
+
for (const char of value) {
|
|
2764
|
+
if (acceptedTypes.has("any")) {
|
|
2765
|
+
unformatted += char;
|
|
2766
|
+
} else if (acceptedTypes.has("digit") && /\d/.test(char)) {
|
|
2767
|
+
unformatted += char;
|
|
2768
|
+
} else if (acceptedTypes.has("letter") && /[a-zA-Z]/.test(char)) {
|
|
2769
|
+
unformatted += char;
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2697
2772
|
let formatted = formatValue(unformatted, tokens);
|
|
2698
2773
|
if (customMask.transform) {
|
|
2699
2774
|
formatted = customMask.transform(formatted);
|
|
@@ -2828,7 +2903,9 @@ var TextInput = class extends BaseInput {
|
|
|
2828
2903
|
}
|
|
2829
2904
|
input.value = displayValue;
|
|
2830
2905
|
this.applyCommonProps(input);
|
|
2831
|
-
if (this.
|
|
2906
|
+
if (this.field.placeholder) {
|
|
2907
|
+
input.placeholder = this.field.placeholder;
|
|
2908
|
+
} else if (this.maskEngine && this.field.mask) {
|
|
2832
2909
|
const maskPlaceholder = this.maskEngine.getMaskPlaceholder(this.field.mask);
|
|
2833
2910
|
if (maskPlaceholder) {
|
|
2834
2911
|
input.placeholder = maskPlaceholder;
|
|
@@ -2940,7 +3017,6 @@ var NumberInput = class extends BaseInput {
|
|
|
2940
3017
|
input.type = "number";
|
|
2941
3018
|
input.value = this.value ?? "";
|
|
2942
3019
|
}
|
|
2943
|
-
input.placeholder = this.field.placeholder || "";
|
|
2944
3020
|
const numberField = this.field;
|
|
2945
3021
|
if (!this.maskEngine && input.type === "number") {
|
|
2946
3022
|
if (numberField.min !== void 0) {
|
|
@@ -2954,7 +3030,9 @@ var NumberInput = class extends BaseInput {
|
|
|
2954
3030
|
}
|
|
2955
3031
|
}
|
|
2956
3032
|
this.applyCommonProps(input);
|
|
2957
|
-
if (this.
|
|
3033
|
+
if (this.field.placeholder) {
|
|
3034
|
+
input.placeholder = this.field.placeholder;
|
|
3035
|
+
} else if (this.maskEngine && this.field.mask) {
|
|
2958
3036
|
const maskPlaceholder = this.maskEngine.getMaskPlaceholder(this.field.mask);
|
|
2959
3037
|
if (maskPlaceholder) {
|
|
2960
3038
|
input.placeholder = maskPlaceholder;
|