@exmg/exm-drawer 1.1.26 → 1.1.28

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.
@@ -1,4 +1,3 @@
1
- import { PropertyValues } from 'lit';
2
1
  import { ExmgElement } from '@exmg/lit-base';
3
2
  export declare class ExmDrawerBase extends ExmgElement {
4
3
  /**
@@ -19,21 +18,17 @@ export declare class ExmDrawerBase extends ExmgElement {
19
18
  */
20
19
  disableEsc: boolean;
21
20
  dialogElement?: HTMLDialogElement;
21
+ private onBackdropPointerDown;
22
+ private onCancel;
23
+ protected firstUpdated(): void;
22
24
  disconnectedCallback(): void;
23
- protected firstUpdated(_changedProperties: PropertyValues): void;
24
25
  private handleOpenedChange;
25
26
  /**
26
27
  * Handle the backdrop click. Check if the clicked element is the dialog. If so close it.
27
28
  * In the dialog is a div.content element. When clicking this area, the target is not the dialog, so will not close the client
28
29
  */
29
30
  private handleBackdropClick;
30
- private catchEscKey;
31
- private handleCloseEvent;
32
- private handleOpenedChanged;
33
31
  openDialog(): void;
34
32
  closeDialog(): void;
35
- /**
36
- * The div.content in the render is needed for making the backdrop click work
37
- */
38
33
  render(): import("lit-html").TemplateResult<1>;
39
34
  }
@@ -22,31 +22,35 @@ export class ExmDrawerBase extends ExmgElement {
22
22
  * Prevent cancel on use of the escape key
23
23
  */
24
24
  this.disableEsc = false;
25
+ this.onBackdropPointerDown = (event) => this.handleBackdropClick(event);
26
+ this.onCancel = (event) => {
27
+ if (this.disableEsc) {
28
+ event.preventDefault();
29
+ }
30
+ };
31
+ }
32
+ firstUpdated() {
33
+ if (!this.dialogElement)
34
+ return;
35
+ this.dialogElement.addEventListener('pointerdown', this.onBackdropPointerDown);
36
+ this.dialogElement.addEventListener('cancel', this.onCancel);
25
37
  }
26
38
  disconnectedCallback() {
27
39
  var _a, _b;
28
- (_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.removeEventListener('close', this.handleCloseEvent.bind(this));
29
- (_b = this.dialogElement) === null || _b === void 0 ? void 0 : _b.removeEventListener('keydown', this.catchEscKey.bind(this));
40
+ (_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.removeEventListener('pointerdown', this.onBackdropPointerDown);
41
+ (_b = this.dialogElement) === null || _b === void 0 ? void 0 : _b.removeEventListener('cancel', this.onCancel);
30
42
  super.disconnectedCallback();
31
43
  }
32
- firstUpdated(_changedProperties) {
33
- var _a;
34
- (_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.addEventListener('close', this.handleCloseEvent.bind(this));
35
- }
36
- handleOpenedChange(opened) {
37
- var _a, _b, _c, _d;
44
+ async handleOpenedChange(opened) {
45
+ if (!this.dialogElement)
46
+ return;
38
47
  if (opened) {
39
- if (!this.noCancelOnOutsideClick) {
40
- (_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.addEventListener('click', this.handleBackdropClick.bind(this));
41
- }
42
- if (this.disableEsc) {
43
- (_b = this.dialogElement) === null || _b === void 0 ? void 0 : _b.addEventListener('keydown', this.catchEscKey.bind(this));
44
- }
45
- (_c = this.dialogElement) === null || _c === void 0 ? void 0 : _c.showModal();
48
+ this.dialogElement.showModal();
46
49
  }
47
50
  else {
48
- (_d = this.dialogElement) === null || _d === void 0 ? void 0 : _d.close();
51
+ this.dialogElement.close();
49
52
  }
53
+ this.fire('exm-drawer-opened-changed', { value: opened }, true);
50
54
  }
51
55
  /**
52
56
  * Handle the backdrop click. Check if the clicked element is the dialog. If so close it.
@@ -54,34 +58,19 @@ export class ExmDrawerBase extends ExmgElement {
54
58
  */
55
59
  handleBackdropClick(event) {
56
60
  var _a;
57
- if (event.target === this.dialogElement) {
61
+ if (!this.noCancelOnOutsideClick && event.target === this.dialogElement) {
58
62
  (_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.close();
59
63
  }
60
64
  }
61
- catchEscKey(event) {
62
- if (event.code === 'Escape') {
63
- event.preventDefault();
64
- }
65
- }
66
- handleCloseEvent() {
67
- this.handleOpenedChanged({ detail: { value: false } });
68
- }
69
- handleOpenedChanged(e) {
70
- this.opened = e.detail.value;
71
- this.fire('exm-drawer-opened-changed', this.opened, true);
72
- }
73
65
  openDialog() {
74
66
  this.opened = true;
75
67
  }
76
68
  closeDialog() {
77
69
  this.opened = false;
78
70
  }
79
- /**
80
- * The div.content in the render is needed for making the backdrop click work
81
- */
82
71
  render() {
83
72
  return html `
84
- <dialog class="${this.side}" @opened-changed="${this.handleOpenedChanged}">
73
+ <dialog class="${this.side}" @close=${() => (this.opened = false)}>
85
74
  <div class="content">
86
75
  <slot></slot>
87
76
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exmg/exm-drawer",
3
- "version": "1.1.26",
3
+ "version": "1.1.28",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "1a0a7807fcc13c157c95509b5efc28ef532334ec"
40
+ "gitHead": "c3d02f7e6fb8a3156b81c700e00ee9b28e3ba000"
41
41
  }