easy-forms-core 1.1.5 → 1.1.6
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 +29 -0
- package/dist/easy-form.js +79 -13
- package/dist/easy-form.js.map +1 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +79 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/easy-form.d.ts
CHANGED
|
@@ -307,6 +307,19 @@ interface FormColors {
|
|
|
307
307
|
* Template names available
|
|
308
308
|
*/
|
|
309
309
|
type TemplateName = 'login' | 'register' | 'otp' | 'contact' | 'password-reset' | 'password-change' | 'profile' | 'checkout' | 'feedback' | 'subscription' | 'booking' | 'review';
|
|
310
|
+
/**
|
|
311
|
+
* Configuración del botón de submit
|
|
312
|
+
*/
|
|
313
|
+
interface SubmitButtonConfig {
|
|
314
|
+
/** Si false, no se muestra el botón (submit programático) */
|
|
315
|
+
visible?: boolean;
|
|
316
|
+
/** Texto del botón (default: "Enviar") */
|
|
317
|
+
text?: string;
|
|
318
|
+
/** Ancho del botón: "auto", "100%", "200px", etc. (default: "auto") */
|
|
319
|
+
width?: string;
|
|
320
|
+
/** Alineación: "left" | "center" | "right" (default: "left") */
|
|
321
|
+
align?: 'left' | 'center' | 'right';
|
|
322
|
+
}
|
|
310
323
|
/**
|
|
311
324
|
* Schema del formulario
|
|
312
325
|
*/
|
|
@@ -314,6 +327,8 @@ interface FormSchema {
|
|
|
314
327
|
fields?: Field[];
|
|
315
328
|
steps?: Step[];
|
|
316
329
|
initialData?: Record<string, any>;
|
|
330
|
+
/** Configuración del botón de submit (también puede definirse vía atributo submit-button) */
|
|
331
|
+
submitButton?: SubmitButtonConfig;
|
|
317
332
|
}
|
|
318
333
|
/**
|
|
319
334
|
* Componente personalizado para inyección
|
|
@@ -387,6 +402,15 @@ declare class EasyForm extends BrowserHTMLElement {
|
|
|
387
402
|
*/
|
|
388
403
|
get attemptsStorageKey(): string | null;
|
|
389
404
|
set attemptsStorageKey(value: string | null);
|
|
405
|
+
/**
|
|
406
|
+
* Configuración del botón de submit (desde atributo o schema)
|
|
407
|
+
*/
|
|
408
|
+
get submitButton(): SubmitButtonConfig | null;
|
|
409
|
+
set submitButton(value: SubmitButtonConfig | null);
|
|
410
|
+
/**
|
|
411
|
+
* Obtiene la configuración efectiva del botón submit (atributo > schema > defaults)
|
|
412
|
+
*/
|
|
413
|
+
private getSubmitButtonConfig;
|
|
390
414
|
/**
|
|
391
415
|
* Se llama cuando el componente se conecta al DOM
|
|
392
416
|
*/
|
|
@@ -515,6 +539,11 @@ declare class EasyForm extends BrowserHTMLElement {
|
|
|
515
539
|
* Retorna los milisegundos restantes del bloqueo, o 0 si no está bloqueado.
|
|
516
540
|
*/
|
|
517
541
|
getRemainingBlockTimeMs(): number;
|
|
542
|
+
/**
|
|
543
|
+
* Dispara el submit del formulario programáticamente.
|
|
544
|
+
* Útil cuando el botón submit está oculto (visible: false).
|
|
545
|
+
*/
|
|
546
|
+
requestSubmit(): void;
|
|
518
547
|
/**
|
|
519
548
|
* Limpia todos los valores del formulario
|
|
520
549
|
*/
|
package/dist/easy-form.js
CHANGED
|
@@ -265,6 +265,13 @@ function getBaseStyles(colors) {
|
|
|
265
265
|
.easy-form-submit:active {
|
|
266
266
|
transform: scale(0.98);
|
|
267
267
|
}
|
|
268
|
+
.easy-form-submit-wrapper {
|
|
269
|
+
margin-top: 1rem;
|
|
270
|
+
margin-bottom: 0.5rem;
|
|
271
|
+
}
|
|
272
|
+
.easy-form-submit-wrapper .easy-form-submit {
|
|
273
|
+
min-width: 100px;
|
|
274
|
+
}
|
|
268
275
|
input:not([type="checkbox"]):not([type="radio"]), textarea, select {
|
|
269
276
|
width: 100%;
|
|
270
277
|
padding: 0.5rem;
|
|
@@ -4772,7 +4779,8 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
4772
4779
|
"disabled",
|
|
4773
4780
|
"max-attempts",
|
|
4774
4781
|
"block-duration-minutes",
|
|
4775
|
-
"attempts-storage-key"
|
|
4782
|
+
"attempts-storage-key",
|
|
4783
|
+
"submit-button"
|
|
4776
4784
|
];
|
|
4777
4785
|
}
|
|
4778
4786
|
/**
|
|
@@ -4892,6 +4900,41 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
4892
4900
|
this.removeAttribute("attempts-storage-key");
|
|
4893
4901
|
}
|
|
4894
4902
|
}
|
|
4903
|
+
/**
|
|
4904
|
+
* Configuración del botón de submit (desde atributo o schema)
|
|
4905
|
+
*/
|
|
4906
|
+
get submitButton() {
|
|
4907
|
+
const attr = this.getAttribute("submit-button");
|
|
4908
|
+
if (attr) {
|
|
4909
|
+
try {
|
|
4910
|
+
return parseAttributeValue(attr);
|
|
4911
|
+
} catch {
|
|
4912
|
+
return null;
|
|
4913
|
+
}
|
|
4914
|
+
}
|
|
4915
|
+
return null;
|
|
4916
|
+
}
|
|
4917
|
+
set submitButton(value) {
|
|
4918
|
+
if (value && typeof value === "object") {
|
|
4919
|
+
this.setAttribute("submit-button", attributeValue(value));
|
|
4920
|
+
} else {
|
|
4921
|
+
this.removeAttribute("submit-button");
|
|
4922
|
+
}
|
|
4923
|
+
}
|
|
4924
|
+
/**
|
|
4925
|
+
* Obtiene la configuración efectiva del botón submit (atributo > schema > defaults)
|
|
4926
|
+
*/
|
|
4927
|
+
getSubmitButtonConfig(schema) {
|
|
4928
|
+
const fromAttr = this.submitButton;
|
|
4929
|
+
const fromSchema = schema?.submitButton;
|
|
4930
|
+
const merged = { ...fromSchema, ...fromAttr };
|
|
4931
|
+
return {
|
|
4932
|
+
visible: merged.visible ?? true,
|
|
4933
|
+
text: merged.text ?? "Enviar",
|
|
4934
|
+
width: merged.width ?? "auto",
|
|
4935
|
+
align: merged.align ?? "left"
|
|
4936
|
+
};
|
|
4937
|
+
}
|
|
4895
4938
|
/**
|
|
4896
4939
|
* Se llama cuando el componente se conecta al DOM
|
|
4897
4940
|
*/
|
|
@@ -4947,6 +4990,9 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
4947
4990
|
this.setupAttemptsLock();
|
|
4948
4991
|
this.updateLockOverlay();
|
|
4949
4992
|
}
|
|
4993
|
+
if (name === "submit-button" && newValue !== oldValue) {
|
|
4994
|
+
this.render();
|
|
4995
|
+
}
|
|
4950
4996
|
}
|
|
4951
4997
|
/**
|
|
4952
4998
|
* Configura el AttemptsLock según los atributos actuales
|
|
@@ -5060,17 +5106,25 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
5060
5106
|
newFormElement.classList.add("easy-form-disabled");
|
|
5061
5107
|
}
|
|
5062
5108
|
if (finalWizardState) {
|
|
5063
|
-
this.renderWizard(newFormElement);
|
|
5109
|
+
this.renderWizard(newFormElement, schema);
|
|
5064
5110
|
} else {
|
|
5065
5111
|
this.renderFields(newFormElement, schema.fields || []);
|
|
5066
|
-
const
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
submitButton
|
|
5112
|
+
const submitConfig = this.getSubmitButtonConfig(schema);
|
|
5113
|
+
if (submitConfig.visible) {
|
|
5114
|
+
const submitWrapper = document.createElement("div");
|
|
5115
|
+
submitWrapper.className = "easy-form-submit-wrapper";
|
|
5116
|
+
submitWrapper.style.textAlign = submitConfig.align;
|
|
5117
|
+
const submitButton = document.createElement("button");
|
|
5118
|
+
submitButton.type = "submit";
|
|
5119
|
+
submitButton.textContent = submitConfig.text;
|
|
5120
|
+
submitButton.className = "easy-form-submit";
|
|
5121
|
+
submitButton.style.width = submitConfig.width;
|
|
5122
|
+
if (this.disabled || this.loading) {
|
|
5123
|
+
submitButton.disabled = true;
|
|
5124
|
+
}
|
|
5125
|
+
submitWrapper.appendChild(submitButton);
|
|
5126
|
+
newFormElement.appendChild(submitWrapper);
|
|
5072
5127
|
}
|
|
5073
|
-
newFormElement.appendChild(submitButton);
|
|
5074
5128
|
}
|
|
5075
5129
|
const oldForm = this.shadow.querySelector("form");
|
|
5076
5130
|
if (oldForm && oldForm.parentNode === this.shadow && oldForm !== newFormElement) {
|
|
@@ -5432,14 +5486,13 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
5432
5486
|
/**
|
|
5433
5487
|
* Renderiza wizard
|
|
5434
5488
|
*/
|
|
5435
|
-
renderWizard(container) {
|
|
5489
|
+
renderWizard(container, schema) {
|
|
5436
5490
|
const wizardState = this.stateManager.getWizardState();
|
|
5437
5491
|
if (!wizardState) return;
|
|
5438
5492
|
const wizardContainer = document.createElement("div");
|
|
5439
5493
|
wizardContainer.className = "easy-form-wizard";
|
|
5440
5494
|
const stepsIndicator = document.createElement("div");
|
|
5441
5495
|
stepsIndicator.className = "easy-form-wizard-steps";
|
|
5442
|
-
const schema = this.schema;
|
|
5443
5496
|
if (schema?.steps) {
|
|
5444
5497
|
for (let i = 0; i < schema.steps.length; i++) {
|
|
5445
5498
|
const stepEl = document.createElement("div");
|
|
@@ -5524,11 +5577,13 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
5524
5577
|
}
|
|
5525
5578
|
navContainer.appendChild(nextButton);
|
|
5526
5579
|
}
|
|
5527
|
-
|
|
5580
|
+
const submitConfig = this.getSubmitButtonConfig(schema);
|
|
5581
|
+
if (wizardState.currentStep === wizardState.totalSteps - 1 && submitConfig.visible) {
|
|
5528
5582
|
const submitButton = document.createElement("button");
|
|
5529
5583
|
submitButton.type = "button";
|
|
5530
|
-
submitButton.textContent =
|
|
5584
|
+
submitButton.textContent = submitConfig.text;
|
|
5531
5585
|
submitButton.className = "easy-form-wizard-next";
|
|
5586
|
+
submitButton.style.width = submitConfig.width;
|
|
5532
5587
|
if (this.disabled || this.loading) {
|
|
5533
5588
|
submitButton.disabled = true;
|
|
5534
5589
|
} else {
|
|
@@ -5783,6 +5838,17 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
5783
5838
|
getRemainingBlockTimeMs() {
|
|
5784
5839
|
return this.attemptsLock?.getRemainingBlockTimeMs() ?? 0;
|
|
5785
5840
|
}
|
|
5841
|
+
/**
|
|
5842
|
+
* Dispara el submit del formulario programáticamente.
|
|
5843
|
+
* Útil cuando el botón submit está oculto (visible: false).
|
|
5844
|
+
*/
|
|
5845
|
+
requestSubmit() {
|
|
5846
|
+
const form = this.shadow.querySelector("form");
|
|
5847
|
+
if (form && typeof form.requestSubmit === "function") {
|
|
5848
|
+
;
|
|
5849
|
+
form.requestSubmit();
|
|
5850
|
+
}
|
|
5851
|
+
}
|
|
5786
5852
|
/**
|
|
5787
5853
|
* Limpia todos los valores del formulario
|
|
5788
5854
|
*/
|