@moni-labs/moni-ui 0.4.16 → 0.4.18

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.
@@ -208,6 +208,16 @@ export class MoniBottomSheet extends MoniElement {
208
208
  }
209
209
  }
210
210
  }
211
+ if (changed.has('open') && !this.open && this._dialog && typeof this._dialog.close === 'function') {
212
+ // Cierra el <dialog> nativo ANTES de que render() retire ?open:
213
+ // close() sin el atributo open es no-op por spec y el top layer
214
+ // quedaría varado (diálogo fantasma que se traga los taps).
215
+ try {
216
+ this._dialog.close();
217
+ } catch {
218
+ // Ya estaba cerrado.
219
+ }
220
+ }
211
221
  }
212
222
 
213
223
  private async _animateAndClose() {
@@ -444,6 +454,18 @@ export class MoniBottomSheet extends MoniElement {
444
454
  this._lastDeltaY = 0;
445
455
  }
446
456
 
457
+ /**
458
+ * Maneja la cancelación nativa del <dialog> (tecla Escape).
459
+ * Sin esto el browser cerraría el diálogo por su cuenta y la
460
+ * propiedad `open` quedaría desincronizada (sheet invisible con
461
+ * open=true). Se previene el cierre nativo y se conduce el flujo
462
+ * propio con animación y eventos. Mismo patrón que moni-side-sheet.
463
+ */
464
+ private _onCancel(e: Event) {
465
+ e.preventDefault();
466
+ void this.close();
467
+ }
468
+
447
469
  /**
448
470
  * Maneja la cancelación del puntero o interrupción del SO.
449
471
  * Si el usuario ya lo había arrastrado hacia abajo o hacia fuera de la pantalla,
@@ -536,6 +558,60 @@ export class MoniBottomSheet extends MoniElement {
536
558
  this._originalSibling = null;
537
559
  }
538
560
  }
561
+
562
+ // Sincroniza el estado declarativo (open/modal) con la API
563
+ // imperativa del <dialog> nativo. Sin esto el ?open del template
564
+ // solo abre el diálogo como no-modal: sin top layer, sin
565
+ // ::backdrop y sin bloqueo del fondo. Mismo patrón que
566
+ // moni-dialog y moni-side-sheet, con guards typeof para
567
+ // entornos sin HTMLDialogElement (jsdom).
568
+ //
569
+ // NOTA: no se lee dialog.open como guarda porque render() ya
570
+ // aplicó ?open antes de updated() y siempre reflejaría el nuevo
571
+ // estado. Se decide por la transición (changed): close() sobre
572
+ // un diálogo ya cerrado es no-op por spec, igual que showModal()
573
+ // sobre uno ya modal lanza InvalidStateError (tolerado).
574
+ if (this._dialog) {
575
+ const nativo = this._dialog as HTMLDialogElement & {
576
+ showModal?: () => void;
577
+ show?: () => void;
578
+ close?: () => void;
579
+ };
580
+ if (this.open) {
581
+ if (this.modal && typeof nativo.showModal === 'function') {
582
+ let yaEsModal = false;
583
+ try {
584
+ yaEsModal = this._dialog.matches(':modal');
585
+ } catch {
586
+ yaEsModal = false;
587
+ }
588
+ if (!yaEsModal) {
589
+ try {
590
+ nativo.showModal();
591
+ } catch {
592
+ // Otro actor ya lo abrió.
593
+ }
594
+ }
595
+ } else if (!this.modal && typeof nativo.show === 'function') {
596
+ try {
597
+ nativo.show();
598
+ } catch {
599
+ // Otro actor ya lo abrió.
600
+ }
601
+ } else if (
602
+ (this.modal && typeof nativo.showModal !== 'function') ||
603
+ (!this.modal && typeof nativo.show !== 'function')
604
+ ) {
605
+ this._dialog.open = true;
606
+ }
607
+ } else if (typeof nativo.close === 'function') {
608
+ try {
609
+ nativo.close();
610
+ } catch {
611
+ // Ya estaba cerrado.
612
+ }
613
+ }
614
+ }
539
615
  }
540
616
  }
541
617
 
@@ -591,6 +667,10 @@ export class MoniBottomSheet extends MoniElement {
591
667
  transform: translateY(0);
592
668
  }
593
669
 
670
+ dialog::backdrop {
671
+ background-color: rgb(0 0 0 / 0.5);
672
+ }
673
+
594
674
  dialog.fixed {
595
675
  position: fixed;
596
676
  inset: auto 0 0 0;
@@ -711,6 +791,7 @@ export class MoniBottomSheet extends MoniElement {
711
791
  ?open=${this.open}
712
792
  class=${dialogClasses}
713
793
  @click=${this._onDialogClick}
794
+ @cancel=${this._onCancel}
714
795
  @pointerdown=${this._onPointerDown}
715
796
  @pointermove=${this._onPointerMove}
716
797
  @pointerup=${this._onPointerUp}