@duskmoon-dev/el-dialog 1.6.0 → 1.7.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/README.md +28 -16
- package/dist/cjs/index.js +146 -134
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/register.js +146 -134
- package/dist/cjs/register.js.map +3 -3
- package/dist/esm/index.js +147 -135
- package/dist/esm/index.js.map +3 -3
- package/dist/esm/register.js +147 -135
- package/dist/esm/register.js.map +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/el-dm-dialog.d.ts +30 -8
- package/dist/types/el-dm-dialog.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @duskmoon-dev/el-dialog
|
|
2
2
|
|
|
3
|
-
A modal dialog
|
|
3
|
+
A modal dialog custom element built on the native HTML `<dialog>` element, styled with `@duskmoon-dev/core`. HTML Invoker Commands are forwarded to the inner native dialog.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -17,6 +17,8 @@ import '@duskmoon-dev/el-dialog/register';
|
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
```html
|
|
20
|
+
<button command="show-modal" commandfor="myDialog">Open Dialog</button>
|
|
21
|
+
|
|
20
22
|
<el-dm-dialog id="myDialog">
|
|
21
23
|
<span slot="header">Dialog Title</span>
|
|
22
24
|
<p>Dialog content goes here.</p>
|
|
@@ -46,6 +48,7 @@ customElements.define('my-dialog', ElDmDialog);
|
|
|
46
48
|
| `sm` | Small dialog |
|
|
47
49
|
| `md` | Medium dialog (default) |
|
|
48
50
|
| `lg` | Large dialog |
|
|
51
|
+
| `xl` | Extra large dialog |
|
|
49
52
|
| `full` | Full-screen dialog |
|
|
50
53
|
|
|
51
54
|
## Attributes
|
|
@@ -53,9 +56,19 @@ customElements.define('my-dialog', ElDmDialog);
|
|
|
53
56
|
| Attribute | Type | Default | Description |
|
|
54
57
|
|-----------|------|---------|-------------|
|
|
55
58
|
| `open` | `boolean` | `false` | Whether the dialog is open |
|
|
56
|
-
| `size` | `string` | `'md'` | Size: `sm`, `md`, `lg`, `full` |
|
|
57
|
-
| `dismissible` | `boolean` | `true` | Allow closing via backdrop/
|
|
58
|
-
| `no-
|
|
59
|
+
| `size` | `string` | `'md'` | Size: `sm`, `md`, `lg`, `xl`, `full` |
|
|
60
|
+
| `dismissible` | `boolean` | `true` | Allow closing via backdrop/Escape |
|
|
61
|
+
| `no-dismiss` | `boolean` | `false` | Prevent closing via backdrop or Escape |
|
|
62
|
+
| `no-backdrop` | `boolean` | `false` | Open as non-modal (`show()` instead of `showModal()`) |
|
|
63
|
+
|
|
64
|
+
## Methods
|
|
65
|
+
|
|
66
|
+
| Method | Description |
|
|
67
|
+
|--------|-------------|
|
|
68
|
+
| `show()` | Opens the dialog as a modal |
|
|
69
|
+
| `showModal()` | Alias for `show()` |
|
|
70
|
+
| `close()` | Closes the dialog |
|
|
71
|
+
| `toggle()` | Toggles the dialog state |
|
|
59
72
|
|
|
60
73
|
## Slots
|
|
61
74
|
|
|
@@ -69,14 +82,16 @@ customElements.define('my-dialog', ElDmDialog);
|
|
|
69
82
|
|
|
70
83
|
| Part | Description |
|
|
71
84
|
|------|-------------|
|
|
72
|
-
| `dialog` | The dialog element |
|
|
73
|
-
| `
|
|
74
|
-
| `content` | The content wrapper |
|
|
85
|
+
| `dialog` | The native `<dialog>` element |
|
|
86
|
+
| `box` | Inner `dialog-box` container |
|
|
75
87
|
| `header` | The header section |
|
|
88
|
+
| `title` | The title wrapper |
|
|
76
89
|
| `body` | The body section |
|
|
77
90
|
| `footer` | The footer section |
|
|
78
91
|
| `close` | The close button |
|
|
79
92
|
|
|
93
|
+
The backdrop is the native `::backdrop` pseudo-element. Tune it with `--color-scrim`.
|
|
94
|
+
|
|
80
95
|
## Events
|
|
81
96
|
|
|
82
97
|
| Event | Detail | Description |
|
|
@@ -89,7 +104,7 @@ customElements.define('my-dialog', ElDmDialog);
|
|
|
89
104
|
### Basic Dialog
|
|
90
105
|
|
|
91
106
|
```html
|
|
92
|
-
<el-dm-button onclick="document.querySelector('#dialog').
|
|
107
|
+
<el-dm-button onclick="document.querySelector('#dialog').show()">
|
|
93
108
|
Open Dialog
|
|
94
109
|
</el-dm-button>
|
|
95
110
|
|
|
@@ -97,7 +112,7 @@ customElements.define('my-dialog', ElDmDialog);
|
|
|
97
112
|
<span slot="header">Confirmation</span>
|
|
98
113
|
<p>Are you sure you want to proceed?</p>
|
|
99
114
|
<div slot="footer">
|
|
100
|
-
<el-dm-button variant="ghost" onclick="this.closest('el-dm-dialog').
|
|
115
|
+
<el-dm-button variant="ghost" onclick="this.closest('el-dm-dialog').close()">
|
|
101
116
|
Cancel
|
|
102
117
|
</el-dm-button>
|
|
103
118
|
<el-dm-button variant="primary">
|
|
@@ -113,13 +128,14 @@ customElements.define('my-dialog', ElDmDialog);
|
|
|
113
128
|
<el-dm-dialog size="sm">Small dialog</el-dm-dialog>
|
|
114
129
|
<el-dm-dialog size="md">Medium dialog</el-dm-dialog>
|
|
115
130
|
<el-dm-dialog size="lg">Large dialog</el-dm-dialog>
|
|
131
|
+
<el-dm-dialog size="xl">Extra large dialog</el-dm-dialog>
|
|
116
132
|
<el-dm-dialog size="full">Full-screen dialog</el-dm-dialog>
|
|
117
133
|
```
|
|
118
134
|
|
|
119
135
|
### Non-Dismissible
|
|
120
136
|
|
|
121
137
|
```html
|
|
122
|
-
<el-dm-dialog
|
|
138
|
+
<el-dm-dialog no-dismiss>
|
|
123
139
|
<span slot="header">Required Action</span>
|
|
124
140
|
<p>You must complete this action.</p>
|
|
125
141
|
<div slot="footer">
|
|
@@ -133,13 +149,9 @@ customElements.define('my-dialog', ElDmDialog);
|
|
|
133
149
|
```javascript
|
|
134
150
|
const dialog = document.querySelector('el-dm-dialog');
|
|
135
151
|
|
|
136
|
-
|
|
137
|
-
dialog.
|
|
138
|
-
|
|
139
|
-
// Close
|
|
140
|
-
dialog.open = false;
|
|
152
|
+
dialog.show();
|
|
153
|
+
dialog.close();
|
|
141
154
|
|
|
142
|
-
// Listen for events
|
|
143
155
|
dialog.addEventListener('close', () => {
|
|
144
156
|
console.log('Dialog closed');
|
|
145
157
|
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -66,111 +66,9 @@ var styles = import_el_base.css`
|
|
|
66
66
|
|
|
67
67
|
${coreStyles}
|
|
68
68
|
|
|
69
|
-
.dialog
|
|
70
|
-
position: fixed;
|
|
71
|
-
inset: 0;
|
|
72
|
-
z-index: 1000;
|
|
73
|
-
display: flex;
|
|
74
|
-
align-items: center;
|
|
75
|
-
justify-content: center;
|
|
76
|
-
opacity: 0;
|
|
77
|
-
visibility: hidden;
|
|
78
|
-
transition:
|
|
79
|
-
opacity 200ms ease,
|
|
80
|
-
visibility 200ms ease;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
.dialog-wrapper.open {
|
|
84
|
-
opacity: 1;
|
|
85
|
-
visibility: visible;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
.dialog-backdrop {
|
|
89
|
-
position: absolute;
|
|
90
|
-
inset: 0;
|
|
91
|
-
background-color: rgba(0, 0, 0, 0.5);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
.dialog {
|
|
95
|
-
position: relative;
|
|
96
|
-
display: flex;
|
|
97
|
-
flex-direction: column;
|
|
98
|
-
max-height: 90vh;
|
|
99
|
-
max-width: 90vw;
|
|
100
|
-
min-width: 320px;
|
|
101
|
-
background-color: var(--color-surface);
|
|
102
|
-
border-radius: 1rem;
|
|
103
|
-
box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
|
|
104
|
-
transform: scale(0.95);
|
|
105
|
-
transition: transform 200ms ease;
|
|
69
|
+
dialog.dialog {
|
|
106
70
|
font-family: inherit;
|
|
107
71
|
}
|
|
108
|
-
|
|
109
|
-
.dialog-wrapper.open .dialog {
|
|
110
|
-
transform: scale(1);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
.dialog-sm {
|
|
114
|
-
max-width: 400px;
|
|
115
|
-
}
|
|
116
|
-
.dialog-lg {
|
|
117
|
-
max-width: 800px;
|
|
118
|
-
}
|
|
119
|
-
.dialog-xl {
|
|
120
|
-
max-width: 1140px;
|
|
121
|
-
}
|
|
122
|
-
.dialog-fullscreen {
|
|
123
|
-
max-width: 100vw;
|
|
124
|
-
max-height: 100vh;
|
|
125
|
-
width: 100vw;
|
|
126
|
-
height: 100vh;
|
|
127
|
-
border-radius: 0;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
.dialog-header {
|
|
131
|
-
display: flex;
|
|
132
|
-
align-items: center;
|
|
133
|
-
justify-content: space-between;
|
|
134
|
-
padding: 1rem 1.5rem;
|
|
135
|
-
border-bottom: 1px solid var(--color-outline);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
.dialog-body {
|
|
139
|
-
flex: 1;
|
|
140
|
-
padding: 1.5rem;
|
|
141
|
-
overflow-y: auto;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
.dialog-footer {
|
|
145
|
-
display: flex;
|
|
146
|
-
align-items: center;
|
|
147
|
-
justify-content: flex-end;
|
|
148
|
-
gap: 0.5rem;
|
|
149
|
-
padding: 1rem 1.5rem;
|
|
150
|
-
border-top: 1px solid var(--color-outline);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
.dialog-close {
|
|
154
|
-
display: flex;
|
|
155
|
-
align-items: center;
|
|
156
|
-
justify-content: center;
|
|
157
|
-
width: 2rem;
|
|
158
|
-
height: 2rem;
|
|
159
|
-
border: none;
|
|
160
|
-
background: transparent;
|
|
161
|
-
border-radius: 0.5rem;
|
|
162
|
-
cursor: pointer;
|
|
163
|
-
color: var(--color-on-surface);
|
|
164
|
-
opacity: 0.7;
|
|
165
|
-
transition:
|
|
166
|
-
opacity 150ms ease,
|
|
167
|
-
background-color 150ms ease;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
.dialog-close:hover {
|
|
171
|
-
opacity: 1;
|
|
172
|
-
background-color: var(--color-surface-variant);
|
|
173
|
-
}
|
|
174
72
|
`;
|
|
175
73
|
|
|
176
74
|
class ElDmDialog extends import_el_base.BaseElement {
|
|
@@ -181,23 +79,29 @@ class ElDmDialog extends import_el_base.BaseElement {
|
|
|
181
79
|
noDismiss: { type: Boolean, reflect: true, attribute: "no-dismiss" },
|
|
182
80
|
noBackdrop: { type: Boolean, reflect: true, attribute: "no-backdrop" }
|
|
183
81
|
};
|
|
82
|
+
_syncing = false;
|
|
83
|
+
_structureKey = "";
|
|
184
84
|
constructor() {
|
|
185
85
|
super();
|
|
186
|
-
this.attachStyles(
|
|
86
|
+
this.attachStyles(styles);
|
|
87
|
+
}
|
|
88
|
+
connectedCallback() {
|
|
89
|
+
super.connectedCallback();
|
|
90
|
+
this.addEventListener("command", this._handleCommand);
|
|
91
|
+
}
|
|
92
|
+
disconnectedCallback() {
|
|
93
|
+
super.disconnectedCallback?.();
|
|
94
|
+
this.removeEventListener("command", this._handleCommand);
|
|
187
95
|
}
|
|
188
96
|
_canDismiss() {
|
|
189
97
|
return this.dismissible && !this.noDismiss;
|
|
190
98
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
99
|
+
_getDialog() {
|
|
100
|
+
return this.query("dialog");
|
|
101
|
+
}
|
|
102
|
+
_getStructureKey() {
|
|
103
|
+
return [this.size ?? "", this.dismissible ? "1" : "0", this.noDismiss ? "1" : "0"].join("|");
|
|
195
104
|
}
|
|
196
|
-
_handleKeyDown = (event) => {
|
|
197
|
-
if (event.key === "Escape" && this._canDismiss()) {
|
|
198
|
-
this.close();
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
105
|
_getDialogClasses() {
|
|
202
106
|
const classes = ["dialog"];
|
|
203
107
|
if (this.size && SIZE_CLASSES[this.size]) {
|
|
@@ -205,16 +109,119 @@ class ElDmDialog extends import_el_base.BaseElement {
|
|
|
205
109
|
}
|
|
206
110
|
return classes.join(" ");
|
|
207
111
|
}
|
|
112
|
+
_handleCancel = (event) => {
|
|
113
|
+
if (!this._canDismiss()) {
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
_handleNativeClose = () => {
|
|
118
|
+
if (this._syncing)
|
|
119
|
+
return;
|
|
120
|
+
if (!this.open)
|
|
121
|
+
return;
|
|
122
|
+
this.open = false;
|
|
123
|
+
this.emit("close");
|
|
124
|
+
};
|
|
125
|
+
_handleBackdropClick = (event) => {
|
|
126
|
+
if (this._canDismiss() && event.target === event.currentTarget) {
|
|
127
|
+
this.close();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
_handleCloseClick = () => {
|
|
131
|
+
this.close();
|
|
132
|
+
};
|
|
133
|
+
_handleCommand = (event) => {
|
|
134
|
+
const dialog = this._getDialog();
|
|
135
|
+
if (!dialog)
|
|
136
|
+
return;
|
|
137
|
+
const command = "command" in event ? String(event.command) : "";
|
|
138
|
+
switch (command) {
|
|
139
|
+
case "show-modal":
|
|
140
|
+
this._openNativeDialog(dialog, true);
|
|
141
|
+
break;
|
|
142
|
+
case "show":
|
|
143
|
+
this._openNativeDialog(dialog, false);
|
|
144
|
+
break;
|
|
145
|
+
case "close":
|
|
146
|
+
if (dialog.open) {
|
|
147
|
+
dialog.close();
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
case "request-close":
|
|
151
|
+
this._requestNativeClose(dialog);
|
|
152
|
+
break;
|
|
153
|
+
case "toggle":
|
|
154
|
+
if (dialog.open) {
|
|
155
|
+
dialog.close();
|
|
156
|
+
} else {
|
|
157
|
+
this._openNativeDialog(dialog, !this.noBackdrop);
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
default:
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
_openNativeDialog(dialog, modal) {
|
|
165
|
+
if (!dialog.open) {
|
|
166
|
+
if (modal) {
|
|
167
|
+
dialog.showModal();
|
|
168
|
+
} else {
|
|
169
|
+
dialog.show();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (!this.open) {
|
|
173
|
+
this.open = true;
|
|
174
|
+
this.emit("open");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
_requestNativeClose(dialog) {
|
|
178
|
+
if (!dialog.open)
|
|
179
|
+
return;
|
|
180
|
+
const requestClose = dialog.requestClose;
|
|
181
|
+
if (typeof requestClose === "function") {
|
|
182
|
+
requestClose.call(dialog);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const cancel = new Event("cancel", { cancelable: true });
|
|
186
|
+
const allowed = dialog.dispatchEvent(cancel);
|
|
187
|
+
if (allowed && !cancel.defaultPrevented) {
|
|
188
|
+
dialog.close();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
_bindDialog() {
|
|
192
|
+
const dialog = this._getDialog();
|
|
193
|
+
if (!dialog)
|
|
194
|
+
return;
|
|
195
|
+
dialog.addEventListener("cancel", this._handleCancel);
|
|
196
|
+
dialog.addEventListener("close", this._handleNativeClose);
|
|
197
|
+
dialog.addEventListener("click", this._handleBackdropClick);
|
|
198
|
+
this.query(".dialog-close")?.addEventListener("click", this._handleCloseClick);
|
|
199
|
+
}
|
|
200
|
+
_syncNativeDialog() {
|
|
201
|
+
const dialog = this._getDialog();
|
|
202
|
+
if (!dialog)
|
|
203
|
+
return;
|
|
204
|
+
if (this.open && !dialog.open) {
|
|
205
|
+
if (this.noBackdrop) {
|
|
206
|
+
dialog.show();
|
|
207
|
+
} else {
|
|
208
|
+
dialog.showModal();
|
|
209
|
+
}
|
|
210
|
+
} else if (!this.open && dialog.open) {
|
|
211
|
+
dialog.close();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
208
214
|
show() {
|
|
209
215
|
this.open = true;
|
|
210
|
-
document.addEventListener("keydown", this._handleKeyDown);
|
|
211
|
-
document.body.style.overflow = "hidden";
|
|
212
216
|
this.emit("open");
|
|
213
217
|
}
|
|
218
|
+
showModal() {
|
|
219
|
+
this.show();
|
|
220
|
+
}
|
|
214
221
|
close() {
|
|
222
|
+
if (!this.open)
|
|
223
|
+
return;
|
|
215
224
|
this.open = false;
|
|
216
|
-
document.removeEventListener("keydown", this._handleKeyDown);
|
|
217
|
-
document.body.style.overflow = "";
|
|
218
225
|
this.emit("close");
|
|
219
226
|
}
|
|
220
227
|
toggle() {
|
|
@@ -224,20 +231,16 @@ class ElDmDialog extends import_el_base.BaseElement {
|
|
|
224
231
|
this.show();
|
|
225
232
|
}
|
|
226
233
|
}
|
|
227
|
-
disconnectedCallback() {
|
|
228
|
-
super.disconnectedCallback?.();
|
|
229
|
-
document.removeEventListener("keydown", this._handleKeyDown);
|
|
230
|
-
document.body.style.overflow = "";
|
|
231
|
-
}
|
|
232
234
|
render() {
|
|
233
235
|
const dialogClasses = this._getDialogClasses();
|
|
234
236
|
return `
|
|
235
|
-
<
|
|
236
|
-
|
|
237
|
-
<div class="${dialogClasses}" role="dialog" aria-modal="true" part="dialog">
|
|
237
|
+
<dialog class="${dialogClasses}" part="dialog">
|
|
238
|
+
<div class="dialog-box" part="box">
|
|
238
239
|
<div class="dialog-header" part="header">
|
|
239
|
-
<
|
|
240
|
-
|
|
240
|
+
<div class="dialog-title" part="title">
|
|
241
|
+
<slot name="header"></slot>
|
|
242
|
+
</div>
|
|
243
|
+
${this._canDismiss() ? '<button type="button" class="dialog-close" part="close" aria-label="Close">×</button>' : ""}
|
|
241
244
|
</div>
|
|
242
245
|
<div class="dialog-body" part="body">
|
|
243
246
|
<slot></slot>
|
|
@@ -246,15 +249,24 @@ class ElDmDialog extends import_el_base.BaseElement {
|
|
|
246
249
|
<slot name="footer"></slot>
|
|
247
250
|
</div>
|
|
248
251
|
</div>
|
|
249
|
-
</
|
|
252
|
+
</dialog>
|
|
250
253
|
`;
|
|
251
254
|
}
|
|
252
255
|
update() {
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
256
|
+
const key = this._getStructureKey();
|
|
257
|
+
const dialog = this._getDialog();
|
|
258
|
+
const needsRender = !dialog || key !== this._structureKey;
|
|
259
|
+
this._syncing = true;
|
|
260
|
+
try {
|
|
261
|
+
if (needsRender) {
|
|
262
|
+
super.update();
|
|
263
|
+
this._structureKey = key;
|
|
264
|
+
this._bindDialog();
|
|
265
|
+
}
|
|
266
|
+
this._syncNativeDialog();
|
|
267
|
+
} finally {
|
|
268
|
+
this._syncing = false;
|
|
269
|
+
}
|
|
258
270
|
}
|
|
259
271
|
}
|
|
260
272
|
|
|
@@ -265,5 +277,5 @@ function register() {
|
|
|
265
277
|
}
|
|
266
278
|
}
|
|
267
279
|
|
|
268
|
-
//# debugId=
|
|
280
|
+
//# debugId=0EA2037F8549C1FA64756E2164756E21
|
|
269
281
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/el-dm-dialog.ts", "../../src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * DuskMoon Dialog Element\n *\n * A modal dialog
|
|
5
|
+
"/**\n * DuskMoon Dialog Element\n *\n * A modal dialog built on the native HTML <dialog> element.\n * Uses styles from @duskmoon-dev/core for consistent theming.\n * HTML Invoker Commands (`command` / `commandfor`) are forwarded to the\n * inner native dialog so built-in show-modal / close / request-close work.\n *\n * @element el-dm-dialog\n *\n * @attr {boolean} open - Whether the dialog is open\n * @attr {string} size - Dialog size: sm, md, lg, xl, full\n * @attr {boolean} dismissible - Whether clicking backdrop closes dialog\n * @attr {boolean} no-dismiss - Prevents closing via backdrop click or Escape key\n * @attr {boolean} no-backdrop - Open as a non-modal dialog (no ::backdrop)\n *\n * @slot - Default slot for dialog content\n * @slot header - Dialog header/title\n * @slot footer - Dialog footer/actions\n *\n * @csspart dialog - The native dialog element\n * @csspart box - The inner dialog-box container\n * @csspart header - The header section\n * @csspart title - The title wrapper\n * @csspart body - The body section\n * @csspart footer - The footer section\n * @csspart close - The close button\n *\n * @fires open - Fired when dialog opens\n * @fires close - Fired when dialog closes\n */\n\nimport { BaseElement, css } from '@duskmoon-dev/el-base';\nimport { css as dialogCSS } from '@duskmoon-dev/core/components/dialog';\n\nconst SIZE_CLASSES: Record<string, string> = {\n sm: 'dialog-sm',\n md: '',\n lg: 'dialog-lg',\n xl: 'dialog-xl',\n full: 'dialog-fullscreen',\n};\n\nexport type DialogSize = 'sm' | 'md' | 'lg' | 'xl' | 'full';\n\nconst coreStyles = dialogCSS.replace(/@layer\\s+components\\s*\\{/, '').replace(/\\}\\s*$/, '');\n\nconst styles = css`\n :host {\n display: contents;\n }\n\n :host([hidden]) {\n display: none !important;\n }\n\n ${coreStyles}\n\n dialog.dialog {\n font-family: inherit;\n }\n`;\n\nexport class ElDmDialog extends BaseElement {\n static properties = {\n open: { type: Boolean, reflect: true },\n size: { type: String, reflect: true },\n dismissible: { type: Boolean, reflect: true, default: true },\n noDismiss: { type: Boolean, reflect: true, attribute: 'no-dismiss' },\n noBackdrop: { type: Boolean, reflect: true, attribute: 'no-backdrop' },\n };\n\n declare open: boolean;\n declare size: DialogSize;\n declare dismissible: boolean;\n declare noDismiss: boolean;\n declare noBackdrop: boolean;\n\n /** Ignore native close events fired while shadow DOM is being rebuilt. */\n private _syncing = false;\n\n /** Structural template key — open changes must not rebuild the dialog. */\n private _structureKey = '';\n\n constructor() {\n super();\n this.attachStyles(styles);\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener('command', this._handleCommand);\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback?.();\n this.removeEventListener('command', this._handleCommand);\n }\n\n private _canDismiss(): boolean {\n return this.dismissible && !this.noDismiss;\n }\n\n private _getDialog(): HTMLDialogElement | null {\n return this.query<HTMLDialogElement>('dialog');\n }\n\n private _getStructureKey(): string {\n return [this.size ?? '', this.dismissible ? '1' : '0', this.noDismiss ? '1' : '0'].join('|');\n }\n\n private _getDialogClasses(): string {\n const classes = ['dialog'];\n if (this.size && SIZE_CLASSES[this.size]) {\n classes.push(SIZE_CLASSES[this.size]);\n }\n return classes.join(' ');\n }\n\n private _handleCancel = (event: Event): void => {\n if (!this._canDismiss()) {\n event.preventDefault();\n }\n };\n\n private _handleNativeClose = (): void => {\n if (this._syncing) return;\n if (!this.open) return;\n this.open = false;\n this.emit('close');\n };\n\n private _handleBackdropClick = (event: Event): void => {\n if (this._canDismiss() && event.target === event.currentTarget) {\n this.close();\n }\n };\n\n private _handleCloseClick = (): void => {\n this.close();\n };\n\n /**\n * Forward Invoker Commands to the native <dialog>.\n * commandfor points at this host; built-in dialog commands must run on the\n * inner HTMLDialogElement, not via a full show()/close() re-render cycle.\n */\n private _handleCommand = (event: Event): void => {\n const dialog = this._getDialog();\n if (!dialog) return;\n\n const command = 'command' in event ? String((event as { command: string }).command) : '';\n\n switch (command) {\n case 'show-modal':\n this._openNativeDialog(dialog, true);\n break;\n case 'show':\n this._openNativeDialog(dialog, false);\n break;\n case 'close':\n if (dialog.open) {\n dialog.close();\n }\n break;\n case 'request-close':\n this._requestNativeClose(dialog);\n break;\n case 'toggle':\n if (dialog.open) {\n dialog.close();\n } else {\n this._openNativeDialog(dialog, !this.noBackdrop);\n }\n break;\n default:\n break;\n }\n };\n\n private _openNativeDialog(dialog: HTMLDialogElement, modal: boolean): void {\n if (!dialog.open) {\n if (modal) {\n dialog.showModal();\n } else {\n dialog.show();\n }\n }\n\n if (!this.open) {\n this.open = true;\n this.emit('open');\n }\n }\n\n private _requestNativeClose(dialog: HTMLDialogElement): void {\n if (!dialog.open) return;\n\n const requestClose = (dialog as HTMLDialogElement & { requestClose?: () => void }).requestClose;\n\n if (typeof requestClose === 'function') {\n requestClose.call(dialog);\n return;\n }\n\n const cancel = new Event('cancel', { cancelable: true });\n const allowed = dialog.dispatchEvent(cancel);\n if (allowed && !cancel.defaultPrevented) {\n dialog.close();\n }\n }\n\n private _bindDialog(): void {\n const dialog = this._getDialog();\n if (!dialog) return;\n\n dialog.addEventListener('cancel', this._handleCancel);\n dialog.addEventListener('close', this._handleNativeClose);\n dialog.addEventListener('click', this._handleBackdropClick);\n this.query('.dialog-close')?.addEventListener('click', this._handleCloseClick);\n }\n\n private _syncNativeDialog(): void {\n const dialog = this._getDialog();\n if (!dialog) return;\n\n if (this.open && !dialog.open) {\n if (this.noBackdrop) {\n dialog.show();\n } else {\n dialog.showModal();\n }\n } else if (!this.open && dialog.open) {\n dialog.close();\n }\n }\n\n show(): void {\n this.open = true;\n this.emit('open');\n }\n\n showModal(): void {\n this.show();\n }\n\n close(): void {\n if (!this.open) return;\n this.open = false;\n this.emit('close');\n }\n\n toggle(): void {\n if (this.open) {\n this.close();\n } else {\n this.show();\n }\n }\n\n render(): string {\n const dialogClasses = this._getDialogClasses();\n\n return `\n <dialog class=\"${dialogClasses}\" part=\"dialog\">\n <div class=\"dialog-box\" part=\"box\">\n <div class=\"dialog-header\" part=\"header\">\n <div class=\"dialog-title\" part=\"title\">\n <slot name=\"header\"></slot>\n </div>\n ${\n this._canDismiss()\n ? '<button type=\"button\" class=\"dialog-close\" part=\"close\" aria-label=\"Close\">×</button>'\n : ''\n }\n </div>\n <div class=\"dialog-body\" part=\"body\">\n <slot></slot>\n </div>\n <div class=\"dialog-footer\" part=\"footer\">\n <slot name=\"footer\"></slot>\n </div>\n </div>\n </dialog>\n `;\n }\n\n update(): void {\n const key = this._getStructureKey();\n const dialog = this._getDialog();\n const needsRender = !dialog || key !== this._structureKey;\n\n this._syncing = true;\n try {\n if (needsRender) {\n super.update();\n this._structureKey = key;\n this._bindDialog();\n }\n this._syncNativeDialog();\n } finally {\n this._syncing = false;\n }\n }\n}\n",
|
|
6
6
|
"import { ElDmDialog } from './el-dm-dialog.js';\n\nexport { ElDmDialog };\nexport type { DialogSize } from './el-dm-dialog.js';\n\nexport function register(): void {\n if (!customElements.get('el-dm-dialog')) {\n customElements.define('el-dm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