easy-forms-core 1.1.18 → 1.2.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.d.ts +6 -0
- package/dist/easy-form.js +70 -19
- package/dist/easy-form.js.map +1 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +70 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/easy-form.d.ts
CHANGED
|
@@ -445,6 +445,7 @@ declare class EasyForm extends BrowserHTMLElement {
|
|
|
445
445
|
* Se inicializan una sola vez y se clonan en cada render.
|
|
446
446
|
*/
|
|
447
447
|
private slotTemplates;
|
|
448
|
+
private skipPreserveValuesOnNextRender;
|
|
448
449
|
static get observedAttributes(): string[];
|
|
449
450
|
constructor();
|
|
450
451
|
/**
|
|
@@ -585,6 +586,11 @@ declare class EasyForm extends BrowserHTMLElement {
|
|
|
585
586
|
*/
|
|
586
587
|
private handleFieldChange;
|
|
587
588
|
private dependencyRenderTimeout;
|
|
589
|
+
/**
|
|
590
|
+
* Re-renderiza un campo array cuando se añaden o eliminan ítems.
|
|
591
|
+
* Retorna true si se reemplazó, false si no se encontró el contenedor.
|
|
592
|
+
*/
|
|
593
|
+
private rerenderArrayField;
|
|
588
594
|
/**
|
|
589
595
|
* Re-renderiza campos dependientes
|
|
590
596
|
*/
|
package/dist/easy-form.js
CHANGED
|
@@ -1174,7 +1174,7 @@ function getPlanoStyles(_colors) {
|
|
|
1174
1174
|
}
|
|
1175
1175
|
.easy-form-array-item {
|
|
1176
1176
|
border: none;
|
|
1177
|
-
border-bottom: 1px solid var(--easy-form-border);
|
|
1177
|
+
border-bottom: 1px solid var(--easy-form-group-border);
|
|
1178
1178
|
border-radius: 0;
|
|
1179
1179
|
}
|
|
1180
1180
|
`;
|
|
@@ -1211,7 +1211,7 @@ function getTradicionalStyles(_colors) {
|
|
|
1211
1211
|
border-color: var(--easy-form-primary);
|
|
1212
1212
|
}
|
|
1213
1213
|
.easy-form-array-item {
|
|
1214
|
-
border: 2px solid var(--easy-form-border);
|
|
1214
|
+
border: 2px solid var(--easy-form-group-border);
|
|
1215
1215
|
border-radius: 4px;
|
|
1216
1216
|
background: #f8f9fa;
|
|
1217
1217
|
}
|
|
@@ -1261,7 +1261,7 @@ function getMaterialStyles(_colors) {
|
|
|
1261
1261
|
.easy-form-array-item {
|
|
1262
1262
|
border: none;
|
|
1263
1263
|
border-radius: 4px;
|
|
1264
|
-
background:
|
|
1264
|
+
background: var(--easy-form-group-background);
|
|
1265
1265
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
|
|
1266
1266
|
}
|
|
1267
1267
|
`;
|
|
@@ -1306,10 +1306,10 @@ function getRoundedShadowStyles(_colors) {
|
|
|
1306
1306
|
box-shadow: 0 4px 16px rgba(0, 123, 255, 0.3);
|
|
1307
1307
|
}
|
|
1308
1308
|
.easy-form-array-item {
|
|
1309
|
-
border: 1px solid var(--easy-form-border);
|
|
1309
|
+
border: 1px solid var(--easy-form-group-border);
|
|
1310
1310
|
border-radius: 12px;
|
|
1311
1311
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
|
1312
|
-
background:
|
|
1312
|
+
background: var(--easy-form-group-background);
|
|
1313
1313
|
}
|
|
1314
1314
|
`;
|
|
1315
1315
|
}
|
|
@@ -1369,7 +1369,7 @@ function getLinesStyles(_colors) {
|
|
|
1369
1369
|
}
|
|
1370
1370
|
.easy-form-array-item {
|
|
1371
1371
|
border: none;
|
|
1372
|
-
border-bottom: 1px solid var(--easy-form-border);
|
|
1372
|
+
border-bottom: 1px solid var(--easy-form-group-border);
|
|
1373
1373
|
border-radius: 0;
|
|
1374
1374
|
}
|
|
1375
1375
|
`;
|
|
@@ -1451,7 +1451,7 @@ function getShadcnStyles(_colors) {
|
|
|
1451
1451
|
.easy-form-array-item {
|
|
1452
1452
|
border: 1.5px solid #e4e4e7;
|
|
1453
1453
|
border-radius: 8px;
|
|
1454
|
-
background:
|
|
1454
|
+
background: var(--easy-form-group-background);
|
|
1455
1455
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
|
|
1456
1456
|
}
|
|
1457
1457
|
`;
|
|
@@ -1550,7 +1550,7 @@ function getChakraStyles(_colors) {
|
|
|
1550
1550
|
transition: all 0.25s ease;
|
|
1551
1551
|
}
|
|
1552
1552
|
.easy-form-array-item:hover {
|
|
1553
|
-
border-color: var(--easy-form-
|
|
1553
|
+
border-color: var(--easy-form-group-border);
|
|
1554
1554
|
box-shadow: 0 2px 8px rgba(0, 123, 255, 0.15);
|
|
1555
1555
|
}
|
|
1556
1556
|
`;
|
|
@@ -1628,9 +1628,9 @@ function getMantineStyles(_colors) {
|
|
|
1628
1628
|
transform: translateY(-3px) scale(1.05);
|
|
1629
1629
|
}
|
|
1630
1630
|
.easy-form-array-item {
|
|
1631
|
-
border: 1px solid
|
|
1631
|
+
border: 1px solid var(--easy-form-group-border);
|
|
1632
1632
|
border-radius: 12px;
|
|
1633
|
-
background: var(--easy-form-background);
|
|
1633
|
+
background: var(--easy-form-group-background);
|
|
1634
1634
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.8);
|
|
1635
1635
|
}
|
|
1636
1636
|
`;
|
|
@@ -1814,9 +1814,9 @@ function getBorderedStyles(_colors) {
|
|
|
1814
1814
|
transform: translate(-4px, -4px);
|
|
1815
1815
|
}
|
|
1816
1816
|
.easy-form-array-item {
|
|
1817
|
-
border: 3px solid
|
|
1817
|
+
border: 3px solid var(--easy-form-group-border);
|
|
1818
1818
|
border-radius: 0;
|
|
1819
|
-
background: var(--easy-form-background);
|
|
1819
|
+
background: var(--easy-form-group-background);
|
|
1820
1820
|
box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.1);
|
|
1821
1821
|
}
|
|
1822
1822
|
`;
|
|
@@ -1944,7 +1944,7 @@ function getMinimalStyles(_colors) {
|
|
|
1944
1944
|
}
|
|
1945
1945
|
.easy-form-array-item {
|
|
1946
1946
|
border: none;
|
|
1947
|
-
border-bottom: 1px solid
|
|
1947
|
+
border-bottom: 1px solid var(--easy-form-group-border);
|
|
1948
1948
|
border-radius: 0;
|
|
1949
1949
|
background: transparent;
|
|
1950
1950
|
padding-bottom: 1.5rem;
|
|
@@ -2683,7 +2683,8 @@ var StateManager = class {
|
|
|
2683
2683
|
this.buildDependencyMap();
|
|
2684
2684
|
}
|
|
2685
2685
|
/**
|
|
2686
|
-
* Extrae todos los campos recursivamente (incluyendo groups, rows
|
|
2686
|
+
* Extrae todos los campos recursivamente (incluyendo groups, rows).
|
|
2687
|
+
* Los campos de array.itemSchema NO se incluyen como top-level: viven dentro de cada ítem.
|
|
2687
2688
|
*/
|
|
2688
2689
|
extractAllFields(fields) {
|
|
2689
2690
|
const allFields = [];
|
|
@@ -2695,12 +2696,27 @@ var StateManager = class {
|
|
|
2695
2696
|
if (field.type === "row" && "fields" in field) {
|
|
2696
2697
|
allFields.push(...this.extractAllFields(field.fields));
|
|
2697
2698
|
}
|
|
2698
|
-
if (field.type === "array" && "itemSchema" in field && field.itemSchema.fields) {
|
|
2699
|
-
allFields.push(...this.extractAllFields(field.itemSchema.fields));
|
|
2700
|
-
}
|
|
2701
2699
|
}
|
|
2702
2700
|
return allFields;
|
|
2703
2701
|
}
|
|
2702
|
+
/**
|
|
2703
|
+
* Devuelve los nombres de campos que solo existen dentro de itemSchema de arrays
|
|
2704
|
+
* y NO como campos top-level. Estos NO deben aparecer como claves en la raíz de values.
|
|
2705
|
+
*/
|
|
2706
|
+
getArrayItemOnlyFieldNames(fields) {
|
|
2707
|
+
const topLevelNames = new Set(fields.map((f) => f.name));
|
|
2708
|
+
const arrayItemNames = /* @__PURE__ */ new Set();
|
|
2709
|
+
for (const field of fields) {
|
|
2710
|
+
if (field.type === "array" && "itemSchema" in field && field.itemSchema?.fields) {
|
|
2711
|
+
for (const sub of field.itemSchema.fields) {
|
|
2712
|
+
if (!topLevelNames.has(sub.name)) {
|
|
2713
|
+
arrayItemNames.add(sub.name);
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
return arrayItemNames;
|
|
2719
|
+
}
|
|
2704
2720
|
/**
|
|
2705
2721
|
* Encuentra el path completo de un campo dentro de grupos
|
|
2706
2722
|
*/
|
|
@@ -2795,7 +2811,9 @@ var StateManager = class {
|
|
|
2795
2811
|
this.initializeFieldValue(field, values);
|
|
2796
2812
|
}
|
|
2797
2813
|
}
|
|
2814
|
+
const arrayItemOnlyNames = this.getArrayItemOnlyFieldNames(topLevelFields);
|
|
2798
2815
|
for (const key in existingValues) {
|
|
2816
|
+
if (arrayItemOnlyNames.has(key)) continue;
|
|
2799
2817
|
if (!(key in values)) {
|
|
2800
2818
|
values[key] = existingValues[key];
|
|
2801
2819
|
}
|
|
@@ -2820,6 +2838,11 @@ var StateManager = class {
|
|
|
2820
2838
|
}
|
|
2821
2839
|
}
|
|
2822
2840
|
}
|
|
2841
|
+
for (const name of arrayItemOnlyNames) {
|
|
2842
|
+
if (name in values) {
|
|
2843
|
+
delete values[name];
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2823
2846
|
this.state.values = values;
|
|
2824
2847
|
}
|
|
2825
2848
|
/**
|
|
@@ -5771,6 +5794,7 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
5771
5794
|
* Se inicializan una sola vez y se clonan en cada render.
|
|
5772
5795
|
*/
|
|
5773
5796
|
this.slotTemplates = null;
|
|
5797
|
+
this.skipPreserveValuesOnNextRender = false;
|
|
5774
5798
|
this.dependencyRenderTimeout = null;
|
|
5775
5799
|
this.stateManager = new StateManager();
|
|
5776
5800
|
this.shadow = this.attachShadow({ mode: "open" });
|
|
@@ -6086,7 +6110,9 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
6086
6110
|
}
|
|
6087
6111
|
return;
|
|
6088
6112
|
}
|
|
6089
|
-
const
|
|
6113
|
+
const isArrayRefresh = this.skipPreserveValuesOnNextRender;
|
|
6114
|
+
const preservedValues = isArrayRefresh ? {} : this.preserveCurrentValues();
|
|
6115
|
+
this.skipPreserveValuesOnNextRender = false;
|
|
6090
6116
|
const previousWizardState = this.stateManager.getWizardState();
|
|
6091
6117
|
if (preservedValues && Object.keys(preservedValues).length > 0) {
|
|
6092
6118
|
for (const [key, value] of Object.entries(preservedValues)) {
|
|
@@ -6096,7 +6122,7 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
6096
6122
|
const initialData = this.initialData;
|
|
6097
6123
|
const wasWizard = previousWizardState !== null;
|
|
6098
6124
|
const isWizard = schema.steps && schema.steps.length > 0;
|
|
6099
|
-
const shouldReinitialize = !previousWizardState || !wasWizard || !isWizard || previousWizardState && schema.steps && previousWizardState.totalSteps !== schema.steps.length;
|
|
6125
|
+
const shouldReinitialize = !isArrayRefresh && (!previousWizardState || !wasWizard || !isWizard || previousWizardState && schema.steps && previousWizardState.totalSteps !== schema.steps.length);
|
|
6100
6126
|
if (shouldReinitialize) {
|
|
6101
6127
|
this.stateManager.initializeSchema(schema, initialData || void 0);
|
|
6102
6128
|
if (wasWizard && isWizard && previousWizardState) {
|
|
@@ -6633,6 +6659,7 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
6633
6659
|
renderArray(field) {
|
|
6634
6660
|
const arrayContainer = document.createElement("div");
|
|
6635
6661
|
arrayContainer.className = "easy-form-array";
|
|
6662
|
+
arrayContainer.setAttribute("data-field-name", field.name);
|
|
6636
6663
|
if (field.label) {
|
|
6637
6664
|
const label = document.createElement("label");
|
|
6638
6665
|
label.className = "easy-form-label";
|
|
@@ -6890,6 +6917,17 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
6890
6917
|
*/
|
|
6891
6918
|
async handleFieldChange(fieldName, value) {
|
|
6892
6919
|
await this.stateManager.setValue(fieldName, value);
|
|
6920
|
+
const schema = this.schema;
|
|
6921
|
+
if (schema) {
|
|
6922
|
+
const field = this.findFieldInSchema(schema, fieldName);
|
|
6923
|
+
if (field?.type === "array") {
|
|
6924
|
+
const replaced = this.rerenderArrayField(field);
|
|
6925
|
+
if (!replaced) {
|
|
6926
|
+
this.skipPreserveValuesOnNextRender = true;
|
|
6927
|
+
requestAnimationFrame(() => this.render());
|
|
6928
|
+
}
|
|
6929
|
+
}
|
|
6930
|
+
}
|
|
6893
6931
|
const dependentFields = this.stateManager.getDependentFields(fieldName);
|
|
6894
6932
|
if (dependentFields.length > 0) {
|
|
6895
6933
|
if (this.dependencyRenderTimeout) {
|
|
@@ -6911,6 +6949,19 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
6911
6949
|
});
|
|
6912
6950
|
this.dispatchEvent(changeEvent);
|
|
6913
6951
|
}
|
|
6952
|
+
/**
|
|
6953
|
+
* Re-renderiza un campo array cuando se añaden o eliminan ítems.
|
|
6954
|
+
* Retorna true si se reemplazó, false si no se encontró el contenedor.
|
|
6955
|
+
*/
|
|
6956
|
+
rerenderArrayField(field) {
|
|
6957
|
+
const arrayContainer = this.shadow.querySelector(
|
|
6958
|
+
`[data-field-name="${field.name}"].easy-form-array`
|
|
6959
|
+
);
|
|
6960
|
+
if (!arrayContainer?.parentNode) return false;
|
|
6961
|
+
const newArrayElement = this.renderArray(field);
|
|
6962
|
+
arrayContainer.parentNode.replaceChild(newArrayElement, arrayContainer);
|
|
6963
|
+
return true;
|
|
6964
|
+
}
|
|
6914
6965
|
/**
|
|
6915
6966
|
* Re-renderiza campos dependientes
|
|
6916
6967
|
*/
|