easy-forms-core 1.1.0 → 1.1.1
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 +150 -42
- package/dist/easy-form.js.map +1 -1
- package/dist/index.js +150 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -382,7 +382,41 @@ function getBaseStyles(colors) {
|
|
|
382
382
|
.easy-form-wizard-nav {
|
|
383
383
|
display: flex;
|
|
384
384
|
gap: 1rem;
|
|
385
|
-
margin-top:
|
|
385
|
+
margin-top: 2rem;
|
|
386
|
+
justify-content: flex-end;
|
|
387
|
+
align-items: center;
|
|
388
|
+
}
|
|
389
|
+
.easy-form-wizard-prev,
|
|
390
|
+
.easy-form-wizard-next {
|
|
391
|
+
padding: 0.75rem 1.5rem;
|
|
392
|
+
background: var(--easy-form-primary);
|
|
393
|
+
color: white;
|
|
394
|
+
border: none;
|
|
395
|
+
border-radius: 4px;
|
|
396
|
+
font-size: 1rem;
|
|
397
|
+
font-weight: 600;
|
|
398
|
+
cursor: pointer;
|
|
399
|
+
transition: all 0.2s ease;
|
|
400
|
+
font-family: inherit;
|
|
401
|
+
min-width: 120px;
|
|
402
|
+
}
|
|
403
|
+
.easy-form-wizard-prev:hover:not(:disabled),
|
|
404
|
+
.easy-form-wizard-next:hover:not(:disabled) {
|
|
405
|
+
opacity: 0.9;
|
|
406
|
+
transform: translateY(-1px);
|
|
407
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
408
|
+
}
|
|
409
|
+
.easy-form-wizard-prev:disabled {
|
|
410
|
+
opacity: 0.5;
|
|
411
|
+
cursor: not-allowed;
|
|
412
|
+
}
|
|
413
|
+
.easy-form-wizard-prev {
|
|
414
|
+
background: var(--easy-form-secondary);
|
|
415
|
+
order: 1;
|
|
416
|
+
}
|
|
417
|
+
.easy-form-wizard-next {
|
|
418
|
+
background: var(--easy-form-primary);
|
|
419
|
+
order: 2;
|
|
386
420
|
}
|
|
387
421
|
.easy-form-array-item {
|
|
388
422
|
padding: 1rem;
|
|
@@ -1737,7 +1771,20 @@ var ValidationEngine = class {
|
|
|
1737
1771
|
if (!value) {
|
|
1738
1772
|
return { isValid: true };
|
|
1739
1773
|
}
|
|
1740
|
-
|
|
1774
|
+
let regex;
|
|
1775
|
+
if (pattern instanceof RegExp) {
|
|
1776
|
+
regex = pattern;
|
|
1777
|
+
} else if (typeof pattern === "string") {
|
|
1778
|
+
try {
|
|
1779
|
+
regex = new RegExp(pattern);
|
|
1780
|
+
} catch (e) {
|
|
1781
|
+
console.warn("Invalid regex pattern:", pattern);
|
|
1782
|
+
return { isValid: true };
|
|
1783
|
+
}
|
|
1784
|
+
} else {
|
|
1785
|
+
console.warn("Pattern validation expects string or RegExp, got:", typeof pattern, pattern);
|
|
1786
|
+
return { isValid: true };
|
|
1787
|
+
}
|
|
1741
1788
|
const isValid = regex.test(String(value));
|
|
1742
1789
|
return {
|
|
1743
1790
|
isValid,
|
|
@@ -4611,26 +4658,45 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
4611
4658
|
return;
|
|
4612
4659
|
}
|
|
4613
4660
|
const preservedValues = this.preserveCurrentValues();
|
|
4661
|
+
const previousWizardState = this.stateManager.getWizardState();
|
|
4614
4662
|
if (preservedValues && Object.keys(preservedValues).length > 0) {
|
|
4615
4663
|
for (const [key, value] of Object.entries(preservedValues)) {
|
|
4616
4664
|
this.stateManager.setValueWithoutValidation(key, value);
|
|
4617
4665
|
}
|
|
4618
4666
|
}
|
|
4619
4667
|
const initialData = this.initialData;
|
|
4620
|
-
|
|
4621
|
-
const
|
|
4668
|
+
const wasWizard = previousWizardState !== null;
|
|
4669
|
+
const isWizard = schema.steps && schema.steps.length > 0;
|
|
4670
|
+
const shouldReinitialize = !previousWizardState || !wasWizard || !isWizard || previousWizardState && schema.steps && previousWizardState.totalSteps !== schema.steps.length;
|
|
4671
|
+
if (shouldReinitialize) {
|
|
4672
|
+
this.stateManager.initializeSchema(schema, initialData || void 0);
|
|
4673
|
+
if (wasWizard && isWizard && previousWizardState) {
|
|
4674
|
+
const wizardState = this.stateManager.getWizardState();
|
|
4675
|
+
if (wizardState && previousWizardState.totalSteps === wizardState.totalSteps) {
|
|
4676
|
+
if (previousWizardState.currentStep >= 0 && previousWizardState.currentStep < wizardState.totalSteps) {
|
|
4677
|
+
this.stateManager.goToStep(previousWizardState.currentStep);
|
|
4678
|
+
}
|
|
4679
|
+
for (const completedStep of previousWizardState.completedSteps) {
|
|
4680
|
+
if (completedStep >= 0 && completedStep < wizardState.totalSteps) {
|
|
4681
|
+
this.stateManager.completeStep(completedStep);
|
|
4682
|
+
}
|
|
4683
|
+
}
|
|
4684
|
+
}
|
|
4685
|
+
}
|
|
4686
|
+
}
|
|
4687
|
+
const finalWizardState = this.stateManager.getWizardState();
|
|
4622
4688
|
const newFormElement = document.createElement("form");
|
|
4623
4689
|
newFormElement.addEventListener("submit", (e) => this.handleSubmit(e));
|
|
4624
|
-
if (
|
|
4625
|
-
this.renderWizard(newFormElement
|
|
4690
|
+
if (finalWizardState) {
|
|
4691
|
+
this.renderWizard(newFormElement);
|
|
4626
4692
|
} else {
|
|
4627
4693
|
this.renderFields(newFormElement, schema.fields || []);
|
|
4694
|
+
const submitButton = document.createElement("button");
|
|
4695
|
+
submitButton.type = "submit";
|
|
4696
|
+
submitButton.textContent = "Enviar";
|
|
4697
|
+
submitButton.className = "easy-form-submit";
|
|
4698
|
+
newFormElement.appendChild(submitButton);
|
|
4628
4699
|
}
|
|
4629
|
-
const submitButton = document.createElement("button");
|
|
4630
|
-
submitButton.type = "submit";
|
|
4631
|
-
submitButton.textContent = "Enviar";
|
|
4632
|
-
submitButton.className = "easy-form-submit";
|
|
4633
|
-
newFormElement.appendChild(submitButton);
|
|
4634
4700
|
const oldForm = this.shadow.querySelector("form");
|
|
4635
4701
|
if (oldForm && oldForm.parentNode === this.shadow && oldForm !== newFormElement) {
|
|
4636
4702
|
try {
|
|
@@ -4919,7 +4985,9 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
4919
4985
|
/**
|
|
4920
4986
|
* Renderiza wizard
|
|
4921
4987
|
*/
|
|
4922
|
-
renderWizard(container
|
|
4988
|
+
renderWizard(container) {
|
|
4989
|
+
const wizardState = this.stateManager.getWizardState();
|
|
4990
|
+
if (!wizardState) return;
|
|
4923
4991
|
const wizardContainer = document.createElement("div");
|
|
4924
4992
|
wizardContainer.className = "easy-form-wizard";
|
|
4925
4993
|
const stepsIndicator = document.createElement("div");
|
|
@@ -4952,43 +5020,83 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
4952
5020
|
wizardContainer.appendChild(fieldsContainer);
|
|
4953
5021
|
const navContainer = document.createElement("div");
|
|
4954
5022
|
navContainer.className = "easy-form-wizard-nav";
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
this.
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
5023
|
+
if (wizardState.currentStep > 0) {
|
|
5024
|
+
const prevButton = document.createElement("button");
|
|
5025
|
+
prevButton.type = "button";
|
|
5026
|
+
prevButton.textContent = "Anterior";
|
|
5027
|
+
prevButton.className = "easy-form-wizard-prev";
|
|
5028
|
+
prevButton.addEventListener("click", () => {
|
|
5029
|
+
const currentState = this.stateManager.getWizardState();
|
|
5030
|
+
if (currentState && this.stateManager.previousStep()) {
|
|
5031
|
+
this.render();
|
|
5032
|
+
this.emitStepChange();
|
|
5033
|
+
}
|
|
5034
|
+
});
|
|
5035
|
+
navContainer.appendChild(prevButton);
|
|
5036
|
+
}
|
|
5037
|
+
if (wizardState.currentStep < wizardState.totalSteps - 1) {
|
|
5038
|
+
const nextButton = document.createElement("button");
|
|
5039
|
+
nextButton.type = "button";
|
|
5040
|
+
nextButton.textContent = "Siguiente";
|
|
5041
|
+
nextButton.className = "easy-form-wizard-next";
|
|
5042
|
+
nextButton.addEventListener("click", async () => {
|
|
5043
|
+
const currentState = this.stateManager.getWizardState();
|
|
5044
|
+
if (!currentState) return;
|
|
4975
5045
|
const currentFields2 = this.stateManager.getCurrentStepFields();
|
|
4976
|
-
const
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
5046
|
+
for (const field of currentFields2) {
|
|
5047
|
+
if (this.stateManager.getFieldVisibility(field.name)) {
|
|
5048
|
+
await this.stateManager.validateField(field.name);
|
|
5049
|
+
}
|
|
5050
|
+
}
|
|
5051
|
+
const allErrors = this.stateManager.getAllErrors();
|
|
5052
|
+
const stepErrors = {};
|
|
5053
|
+
for (const field of currentFields2) {
|
|
5054
|
+
if (allErrors[field.name] && allErrors[field.name].length > 0) {
|
|
5055
|
+
stepErrors[field.name] = allErrors[field.name];
|
|
5056
|
+
}
|
|
5057
|
+
}
|
|
5058
|
+
const hasErrors = Object.keys(stepErrors).length > 0;
|
|
4980
5059
|
if (!hasErrors) {
|
|
4981
|
-
this.stateManager.completeStep(
|
|
4982
|
-
|
|
5060
|
+
this.stateManager.completeStep(currentState.currentStep);
|
|
5061
|
+
const moved = this.stateManager.nextStep();
|
|
5062
|
+
if (moved) {
|
|
4983
5063
|
this.render();
|
|
4984
5064
|
this.emitStepChange();
|
|
4985
5065
|
}
|
|
4986
5066
|
} else {
|
|
4987
|
-
this.emitError(
|
|
5067
|
+
this.emitError(stepErrors);
|
|
4988
5068
|
}
|
|
4989
|
-
}
|
|
4990
|
-
|
|
4991
|
-
|
|
5069
|
+
});
|
|
5070
|
+
navContainer.appendChild(nextButton);
|
|
5071
|
+
}
|
|
5072
|
+
if (wizardState.currentStep === wizardState.totalSteps - 1) {
|
|
5073
|
+
const submitButton = document.createElement("button");
|
|
5074
|
+
submitButton.type = "button";
|
|
5075
|
+
submitButton.textContent = "Enviar";
|
|
5076
|
+
submitButton.className = "easy-form-wizard-next";
|
|
5077
|
+
submitButton.addEventListener("click", async () => {
|
|
5078
|
+
const currentFields2 = this.stateManager.getCurrentStepFields();
|
|
5079
|
+
for (const field of currentFields2) {
|
|
5080
|
+
if (this.stateManager.getFieldVisibility(field.name)) {
|
|
5081
|
+
await this.stateManager.validateField(field.name);
|
|
5082
|
+
}
|
|
5083
|
+
}
|
|
5084
|
+
const allErrors = this.stateManager.getAllErrors();
|
|
5085
|
+
const stepErrors = {};
|
|
5086
|
+
for (const field of currentFields2) {
|
|
5087
|
+
if (allErrors[field.name] && allErrors[field.name].length > 0) {
|
|
5088
|
+
stepErrors[field.name] = allErrors[field.name];
|
|
5089
|
+
}
|
|
5090
|
+
}
|
|
5091
|
+
const hasErrors = Object.keys(stepErrors).length > 0;
|
|
5092
|
+
if (!hasErrors) {
|
|
5093
|
+
await this.handleSubmit(new Event("submit"));
|
|
5094
|
+
} else {
|
|
5095
|
+
this.emitError(stepErrors);
|
|
5096
|
+
}
|
|
5097
|
+
});
|
|
5098
|
+
navContainer.appendChild(submitButton);
|
|
5099
|
+
}
|
|
4992
5100
|
wizardContainer.appendChild(navContainer);
|
|
4993
5101
|
container.appendChild(wizardContainer);
|
|
4994
5102
|
}
|