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/index.d.ts
CHANGED
|
@@ -494,6 +494,7 @@ declare class EasyForm extends BrowserHTMLElement {
|
|
|
494
494
|
* Se inicializan una sola vez y se clonan en cada render.
|
|
495
495
|
*/
|
|
496
496
|
private slotTemplates;
|
|
497
|
+
private skipPreserveValuesOnNextRender;
|
|
497
498
|
static get observedAttributes(): string[];
|
|
498
499
|
constructor();
|
|
499
500
|
/**
|
|
@@ -634,6 +635,11 @@ declare class EasyForm extends BrowserHTMLElement {
|
|
|
634
635
|
*/
|
|
635
636
|
private handleFieldChange;
|
|
636
637
|
private dependencyRenderTimeout;
|
|
638
|
+
/**
|
|
639
|
+
* Re-renderiza un campo array cuando se añaden o eliminan ítems.
|
|
640
|
+
* Retorna true si se reemplazó, false si no se encontró el contenedor.
|
|
641
|
+
*/
|
|
642
|
+
private rerenderArrayField;
|
|
637
643
|
/**
|
|
638
644
|
* Re-renderiza campos dependientes
|
|
639
645
|
*/
|
|
@@ -804,9 +810,15 @@ declare class StateManager {
|
|
|
804
810
|
*/
|
|
805
811
|
initializeSchema(schema: FormSchema, initialData?: Record<string, any>): void;
|
|
806
812
|
/**
|
|
807
|
-
* Extrae todos los campos recursivamente (incluyendo groups, rows
|
|
813
|
+
* Extrae todos los campos recursivamente (incluyendo groups, rows).
|
|
814
|
+
* Los campos de array.itemSchema NO se incluyen como top-level: viven dentro de cada ítem.
|
|
808
815
|
*/
|
|
809
816
|
private extractAllFields;
|
|
817
|
+
/**
|
|
818
|
+
* Devuelve los nombres de campos que solo existen dentro de itemSchema de arrays
|
|
819
|
+
* y NO como campos top-level. Estos NO deben aparecer como claves en la raíz de values.
|
|
820
|
+
*/
|
|
821
|
+
private getArrayItemOnlyFieldNames;
|
|
810
822
|
/**
|
|
811
823
|
* Encuentra el path completo de un campo dentro de grupos
|
|
812
824
|
*/
|
package/dist/index.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;
|
|
@@ -2689,7 +2689,8 @@ var StateManager = class {
|
|
|
2689
2689
|
this.buildDependencyMap();
|
|
2690
2690
|
}
|
|
2691
2691
|
/**
|
|
2692
|
-
* Extrae todos los campos recursivamente (incluyendo groups, rows
|
|
2692
|
+
* Extrae todos los campos recursivamente (incluyendo groups, rows).
|
|
2693
|
+
* Los campos de array.itemSchema NO se incluyen como top-level: viven dentro de cada ítem.
|
|
2693
2694
|
*/
|
|
2694
2695
|
extractAllFields(fields) {
|
|
2695
2696
|
const allFields = [];
|
|
@@ -2701,12 +2702,27 @@ var StateManager = class {
|
|
|
2701
2702
|
if (field.type === "row" && "fields" in field) {
|
|
2702
2703
|
allFields.push(...this.extractAllFields(field.fields));
|
|
2703
2704
|
}
|
|
2704
|
-
if (field.type === "array" && "itemSchema" in field && field.itemSchema.fields) {
|
|
2705
|
-
allFields.push(...this.extractAllFields(field.itemSchema.fields));
|
|
2706
|
-
}
|
|
2707
2705
|
}
|
|
2708
2706
|
return allFields;
|
|
2709
2707
|
}
|
|
2708
|
+
/**
|
|
2709
|
+
* Devuelve los nombres de campos que solo existen dentro de itemSchema de arrays
|
|
2710
|
+
* y NO como campos top-level. Estos NO deben aparecer como claves en la raíz de values.
|
|
2711
|
+
*/
|
|
2712
|
+
getArrayItemOnlyFieldNames(fields) {
|
|
2713
|
+
const topLevelNames = new Set(fields.map((f) => f.name));
|
|
2714
|
+
const arrayItemNames = /* @__PURE__ */ new Set();
|
|
2715
|
+
for (const field of fields) {
|
|
2716
|
+
if (field.type === "array" && "itemSchema" in field && field.itemSchema?.fields) {
|
|
2717
|
+
for (const sub of field.itemSchema.fields) {
|
|
2718
|
+
if (!topLevelNames.has(sub.name)) {
|
|
2719
|
+
arrayItemNames.add(sub.name);
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
return arrayItemNames;
|
|
2725
|
+
}
|
|
2710
2726
|
/**
|
|
2711
2727
|
* Encuentra el path completo de un campo dentro de grupos
|
|
2712
2728
|
*/
|
|
@@ -2801,7 +2817,9 @@ var StateManager = class {
|
|
|
2801
2817
|
this.initializeFieldValue(field, values);
|
|
2802
2818
|
}
|
|
2803
2819
|
}
|
|
2820
|
+
const arrayItemOnlyNames = this.getArrayItemOnlyFieldNames(topLevelFields);
|
|
2804
2821
|
for (const key in existingValues) {
|
|
2822
|
+
if (arrayItemOnlyNames.has(key)) continue;
|
|
2805
2823
|
if (!(key in values)) {
|
|
2806
2824
|
values[key] = existingValues[key];
|
|
2807
2825
|
}
|
|
@@ -2826,6 +2844,11 @@ var StateManager = class {
|
|
|
2826
2844
|
}
|
|
2827
2845
|
}
|
|
2828
2846
|
}
|
|
2847
|
+
for (const name of arrayItemOnlyNames) {
|
|
2848
|
+
if (name in values) {
|
|
2849
|
+
delete values[name];
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2829
2852
|
this.state.values = values;
|
|
2830
2853
|
}
|
|
2831
2854
|
/**
|
|
@@ -5780,6 +5803,7 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
5780
5803
|
* Se inicializan una sola vez y se clonan en cada render.
|
|
5781
5804
|
*/
|
|
5782
5805
|
this.slotTemplates = null;
|
|
5806
|
+
this.skipPreserveValuesOnNextRender = false;
|
|
5783
5807
|
this.dependencyRenderTimeout = null;
|
|
5784
5808
|
this.stateManager = new StateManager();
|
|
5785
5809
|
this.shadow = this.attachShadow({ mode: "open" });
|
|
@@ -6095,7 +6119,9 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
6095
6119
|
}
|
|
6096
6120
|
return;
|
|
6097
6121
|
}
|
|
6098
|
-
const
|
|
6122
|
+
const isArrayRefresh = this.skipPreserveValuesOnNextRender;
|
|
6123
|
+
const preservedValues = isArrayRefresh ? {} : this.preserveCurrentValues();
|
|
6124
|
+
this.skipPreserveValuesOnNextRender = false;
|
|
6099
6125
|
const previousWizardState = this.stateManager.getWizardState();
|
|
6100
6126
|
if (preservedValues && Object.keys(preservedValues).length > 0) {
|
|
6101
6127
|
for (const [key, value] of Object.entries(preservedValues)) {
|
|
@@ -6105,7 +6131,7 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
6105
6131
|
const initialData = this.initialData;
|
|
6106
6132
|
const wasWizard = previousWizardState !== null;
|
|
6107
6133
|
const isWizard = schema.steps && schema.steps.length > 0;
|
|
6108
|
-
const shouldReinitialize = !previousWizardState || !wasWizard || !isWizard || previousWizardState && schema.steps && previousWizardState.totalSteps !== schema.steps.length;
|
|
6134
|
+
const shouldReinitialize = !isArrayRefresh && (!previousWizardState || !wasWizard || !isWizard || previousWizardState && schema.steps && previousWizardState.totalSteps !== schema.steps.length);
|
|
6109
6135
|
if (shouldReinitialize) {
|
|
6110
6136
|
this.stateManager.initializeSchema(schema, initialData || void 0);
|
|
6111
6137
|
if (wasWizard && isWizard && previousWizardState) {
|
|
@@ -6642,6 +6668,7 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
6642
6668
|
renderArray(field) {
|
|
6643
6669
|
const arrayContainer = document.createElement("div");
|
|
6644
6670
|
arrayContainer.className = "easy-form-array";
|
|
6671
|
+
arrayContainer.setAttribute("data-field-name", field.name);
|
|
6645
6672
|
if (field.label) {
|
|
6646
6673
|
const label = document.createElement("label");
|
|
6647
6674
|
label.className = "easy-form-label";
|
|
@@ -6899,6 +6926,17 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
6899
6926
|
*/
|
|
6900
6927
|
async handleFieldChange(fieldName, value) {
|
|
6901
6928
|
await this.stateManager.setValue(fieldName, value);
|
|
6929
|
+
const schema = this.schema;
|
|
6930
|
+
if (schema) {
|
|
6931
|
+
const field = this.findFieldInSchema(schema, fieldName);
|
|
6932
|
+
if (field?.type === "array") {
|
|
6933
|
+
const replaced = this.rerenderArrayField(field);
|
|
6934
|
+
if (!replaced) {
|
|
6935
|
+
this.skipPreserveValuesOnNextRender = true;
|
|
6936
|
+
requestAnimationFrame(() => this.render());
|
|
6937
|
+
}
|
|
6938
|
+
}
|
|
6939
|
+
}
|
|
6902
6940
|
const dependentFields = this.stateManager.getDependentFields(fieldName);
|
|
6903
6941
|
if (dependentFields.length > 0) {
|
|
6904
6942
|
if (this.dependencyRenderTimeout) {
|
|
@@ -6920,6 +6958,19 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
6920
6958
|
});
|
|
6921
6959
|
this.dispatchEvent(changeEvent);
|
|
6922
6960
|
}
|
|
6961
|
+
/**
|
|
6962
|
+
* Re-renderiza un campo array cuando se añaden o eliminan ítems.
|
|
6963
|
+
* Retorna true si se reemplazó, false si no se encontró el contenedor.
|
|
6964
|
+
*/
|
|
6965
|
+
rerenderArrayField(field) {
|
|
6966
|
+
const arrayContainer = this.shadow.querySelector(
|
|
6967
|
+
`[data-field-name="${field.name}"].easy-form-array`
|
|
6968
|
+
);
|
|
6969
|
+
if (!arrayContainer?.parentNode) return false;
|
|
6970
|
+
const newArrayElement = this.renderArray(field);
|
|
6971
|
+
arrayContainer.parentNode.replaceChild(newArrayElement, arrayContainer);
|
|
6972
|
+
return true;
|
|
6973
|
+
}
|
|
6923
6974
|
/**
|
|
6924
6975
|
* Re-renderiza campos dependientes
|
|
6925
6976
|
*/
|