@ohmygame/plugin-ui 2.4.0 → 2.35.0
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 +7 -0
- package/index.d.ts +197 -2
- package/index.js +196 -0
- package/package.json +1 -1
- package/plugin-ui.css +5 -0
- package/ui/1/base.js +17 -0
- package/ui/1/controls.js +85 -2
- package/ui/1/custom-elements.json +2190 -746
- package/ui/1/data.js +238 -0
- package/ui/1/feedback.js +5 -4
- package/ui/1/floating.js +111 -0
- package/ui/1/forms.js +440 -39
- package/ui/1/index.d.ts +313 -1
- package/ui/1/index.js +2 -0
- package/ui/1/layout.js +36 -6
- package/ui/1/media.js +77 -0
- package/ui/1/overlays.js +465 -0
package/ui/1/overlays.js
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OmgElement,
|
|
3
|
+
css,
|
|
4
|
+
define,
|
|
5
|
+
text,
|
|
6
|
+
activeElement,
|
|
7
|
+
containsFocus,
|
|
8
|
+
filled,
|
|
9
|
+
} from "./base.js";
|
|
10
|
+
import { Floating, FLOATING } from "./floating.js";
|
|
11
|
+
|
|
12
|
+
const TRIGGER = css(`
|
|
13
|
+
:host { display: inline-block; min-width: 0; max-width: 100%; }
|
|
14
|
+
.trigger {
|
|
15
|
+
display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
|
|
16
|
+
min-height: 30px; max-width: 100%; padding: 0 var(--space-2); border: 0;
|
|
17
|
+
border-radius: var(--radius-md); background: transparent; color: var(--color-text);
|
|
18
|
+
font: inherit; font-weight: var(--weight-medium); cursor: pointer;
|
|
19
|
+
}
|
|
20
|
+
.trigger:hover, .trigger[aria-expanded="true"] { background: var(--color-hover); }
|
|
21
|
+
.trigger:disabled { opacity: .4; cursor: default; }
|
|
22
|
+
.content { padding: var(--space-2); min-width: min(240px, calc(100vw - 16px)); }
|
|
23
|
+
`);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* `<omg-popover label>`: a non-modal panel opened by its labelled button.
|
|
27
|
+
* Content remains mounted. Esc returns focus; outside clicks and Tab leave it
|
|
28
|
+
* where the person moved. Floating content stays within the plugin viewport.
|
|
29
|
+
*
|
|
30
|
+
* @attr {string} label - Trigger and panel accessible name.
|
|
31
|
+
* @attr {boolean} open - Shows the panel.
|
|
32
|
+
* @attr {boolean} disabled - Disables the trigger and closes the panel.
|
|
33
|
+
* @attr {"bottom-start" | "bottom-end" | "top-start" | "top" | "bottom"} placement - Preferred placement, bottom-start by default.
|
|
34
|
+
* @prop {boolean} open - Showing state; programmatic changes are silent.
|
|
35
|
+
* @fires {{ open: boolean }} omg-toggle - User opened or dismissed the panel.
|
|
36
|
+
* @slot trigger - Optional text or decorative icon inside the trigger; no interactive children.
|
|
37
|
+
* @part label - Default trigger label.
|
|
38
|
+
* @part button - Trigger button.
|
|
39
|
+
* @part panel - Floating panel.
|
|
40
|
+
*/
|
|
41
|
+
class OmgOverlay extends OmgElement {
|
|
42
|
+
static observedAttributes = ["label", "open", "disabled", "placement"];
|
|
43
|
+
static styles = [FLOATING, TRIGGER];
|
|
44
|
+
static template = `<button class="trigger" part="button" type="button" aria-haspopup="dialog" aria-controls="panel"><slot name="trigger"><span part="label"></span></slot></button><div class="floating content" id="panel" part="panel" role="dialog" popover="manual" tabindex="-1" hidden><slot></slot></div>`;
|
|
45
|
+
|
|
46
|
+
constructor() {
|
|
47
|
+
super();
|
|
48
|
+
this.floating = new Floating(
|
|
49
|
+
this,
|
|
50
|
+
this.part("button"),
|
|
51
|
+
this.part("panel"),
|
|
52
|
+
(focus) => this.toggle(false, focus),
|
|
53
|
+
() => this.getAttribute("placement") || "bottom-start",
|
|
54
|
+
);
|
|
55
|
+
this.part("button").addEventListener("click", () => {
|
|
56
|
+
if (!this.hasAttribute("disabled")) this.toggle(!this.open, true);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get open() {
|
|
61
|
+
return this.hasAttribute("open");
|
|
62
|
+
}
|
|
63
|
+
set open(value) {
|
|
64
|
+
this.toggleAttribute("open", Boolean(value));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
toggle(open, focus = false) {
|
|
68
|
+
if (this.open === open) return;
|
|
69
|
+
this.open = open;
|
|
70
|
+
if (focus) (open ? this.part("panel") : this.part("button")).focus();
|
|
71
|
+
this.dispatchEvent(
|
|
72
|
+
new CustomEvent("omg-toggle", {
|
|
73
|
+
bubbles: true,
|
|
74
|
+
composed: true,
|
|
75
|
+
detail: { open },
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
disconnectedCallback() {
|
|
81
|
+
this.floating.hide();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
update() {
|
|
85
|
+
const button = this.part("button");
|
|
86
|
+
const panel = this.part("panel");
|
|
87
|
+
button.disabled = this.hasAttribute("disabled");
|
|
88
|
+
if (button.disabled && this.open) {
|
|
89
|
+
this.open = false;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const label = this.getAttribute("label") || "";
|
|
93
|
+
text(this.part("label"), label);
|
|
94
|
+
button.setAttribute("aria-label", label);
|
|
95
|
+
button.setAttribute("aria-expanded", String(this.open));
|
|
96
|
+
panel.setAttribute("aria-label", label);
|
|
97
|
+
if (this.open) this.floating.show();
|
|
98
|
+
else {
|
|
99
|
+
if (
|
|
100
|
+
!panel.hidden &&
|
|
101
|
+
containsFocus(this) &&
|
|
102
|
+
activeElement() !== button &&
|
|
103
|
+
!button.disabled
|
|
104
|
+
)
|
|
105
|
+
button.focus();
|
|
106
|
+
this.floating.hide();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* `<omg-popover label>`: a non-modal panel with a labelled trigger.
|
|
113
|
+
*
|
|
114
|
+
* @slot - Panel content, retained while closed.
|
|
115
|
+
*/
|
|
116
|
+
class OmgPopover extends OmgOverlay {}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* `<omg-menu label>`: an action menu. Arrow keys, Home/End and typeahead move
|
|
120
|
+
* through enabled actions. Enter/Space selects, Esc returns to the trigger.
|
|
121
|
+
*
|
|
122
|
+
* @prop {Array<{ value: string; label: string; description?: string; disabled?: boolean; danger?: boolean; checked?: boolean }>} items - Actions; values must be unique. Setting items preserves the focused action by value when possible.
|
|
123
|
+
* @fires {{ value: string }} omg-select - Selected action, after closing the menu.
|
|
124
|
+
*/
|
|
125
|
+
class OmgMenu extends OmgOverlay {
|
|
126
|
+
static styles = [
|
|
127
|
+
...OmgOverlay.styles,
|
|
128
|
+
css(`
|
|
129
|
+
.content { min-width: min(200px, calc(100vw - 16px)); padding: var(--space-1); }
|
|
130
|
+
.item { display: flex; align-items: center; gap: var(--space-2); width: 100%; min-height: 30px; padding: 5px var(--space-2); border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--color-text); font: inherit; text-align: start; cursor: pointer; }
|
|
131
|
+
.item:hover, .item:focus-visible { outline: none; background: var(--color-hover); }
|
|
132
|
+
.item:disabled { color: var(--color-text-tertiary); cursor: default; }
|
|
133
|
+
.item.danger { color: var(--color-danger); }
|
|
134
|
+
.words { flex: 1; min-width: 0; overflow-wrap: anywhere; }
|
|
135
|
+
small { display: block; color: var(--color-text-secondary); font-size: var(--text-sm); }
|
|
136
|
+
`),
|
|
137
|
+
];
|
|
138
|
+
static template = `<button class="trigger" part="button" type="button" aria-haspopup="menu" aria-controls="panel"><slot name="trigger"><span part="label"></span></slot></button><div class="floating content" id="panel" part="panel" role="menu" popover="manual" tabindex="-1" hidden></div>`;
|
|
139
|
+
#items = [];
|
|
140
|
+
#search = "";
|
|
141
|
+
#typedAt = 0;
|
|
142
|
+
|
|
143
|
+
constructor() {
|
|
144
|
+
super();
|
|
145
|
+
this.part("button").addEventListener("keydown", (event) => {
|
|
146
|
+
if (
|
|
147
|
+
["ArrowDown", "ArrowUp"].includes(event.key) &&
|
|
148
|
+
!this.hasAttribute("disabled")
|
|
149
|
+
) {
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
this.toggle(true);
|
|
152
|
+
this.#buttons()[
|
|
153
|
+
event.key === "ArrowUp" ? this.#buttons().length - 1 : 0
|
|
154
|
+
]?.focus();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
this.part("panel").addEventListener("keydown", (event) => {
|
|
158
|
+
const buttons = this.#buttons();
|
|
159
|
+
const index = buttons.indexOf(this.shadowRoot.activeElement);
|
|
160
|
+
let next;
|
|
161
|
+
if (event.key === "ArrowDown") next = (index + 1) % buttons.length;
|
|
162
|
+
if (event.key === "ArrowUp")
|
|
163
|
+
next = (index - 1 + buttons.length) % buttons.length;
|
|
164
|
+
if (event.key === "Home") next = 0;
|
|
165
|
+
if (event.key === "End") next = buttons.length - 1;
|
|
166
|
+
if (
|
|
167
|
+
event.key.length === 1 &&
|
|
168
|
+
event.key !== " " &&
|
|
169
|
+
!event.ctrlKey &&
|
|
170
|
+
!event.metaKey &&
|
|
171
|
+
!event.altKey
|
|
172
|
+
) {
|
|
173
|
+
this.#search =
|
|
174
|
+
Date.now() - this.#typedAt > 500
|
|
175
|
+
? event.key
|
|
176
|
+
: this.#search + event.key;
|
|
177
|
+
this.#typedAt = Date.now();
|
|
178
|
+
next = buttons.findIndex((button) =>
|
|
179
|
+
button.textContent
|
|
180
|
+
.toLowerCase()
|
|
181
|
+
.startsWith(this.#search.toLowerCase()),
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
if (next !== undefined) {
|
|
185
|
+
event.preventDefault();
|
|
186
|
+
buttons[next]?.focus();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
get items() {
|
|
192
|
+
return this.#items;
|
|
193
|
+
}
|
|
194
|
+
set items(value) {
|
|
195
|
+
this.#items = value;
|
|
196
|
+
const focused = this.shadowRoot.activeElement?.dataset.value;
|
|
197
|
+
this.part("panel").replaceChildren(
|
|
198
|
+
...value.map((item) => {
|
|
199
|
+
const button = document.createElement("button");
|
|
200
|
+
button.type = "button";
|
|
201
|
+
button.className = `item${item.danger ? " danger" : ""}`;
|
|
202
|
+
button.dataset.value = item.value;
|
|
203
|
+
button.disabled = Boolean(item.disabled);
|
|
204
|
+
button.setAttribute(
|
|
205
|
+
"role",
|
|
206
|
+
item.checked === undefined ? "menuitem" : "menuitemcheckbox",
|
|
207
|
+
);
|
|
208
|
+
if (item.checked !== undefined)
|
|
209
|
+
button.setAttribute("aria-checked", String(item.checked));
|
|
210
|
+
const words = document.createElement("span");
|
|
211
|
+
words.className = "words";
|
|
212
|
+
words.textContent = item.label;
|
|
213
|
+
if (item.description) {
|
|
214
|
+
const small = document.createElement("small");
|
|
215
|
+
small.textContent = item.description;
|
|
216
|
+
words.append(small);
|
|
217
|
+
}
|
|
218
|
+
button.append(words);
|
|
219
|
+
if (item.checked) {
|
|
220
|
+
const check = document.createElement("span");
|
|
221
|
+
check.textContent = "✓";
|
|
222
|
+
check.setAttribute("aria-hidden", "true");
|
|
223
|
+
button.append(check);
|
|
224
|
+
}
|
|
225
|
+
button.addEventListener("click", () => {
|
|
226
|
+
if (button.disabled) return;
|
|
227
|
+
this.toggle(false, true);
|
|
228
|
+
this.dispatchEvent(
|
|
229
|
+
new CustomEvent("omg-select", {
|
|
230
|
+
bubbles: true,
|
|
231
|
+
composed: true,
|
|
232
|
+
detail: { value: item.value },
|
|
233
|
+
}),
|
|
234
|
+
);
|
|
235
|
+
});
|
|
236
|
+
return button;
|
|
237
|
+
}),
|
|
238
|
+
);
|
|
239
|
+
if (focused !== undefined && this.open)
|
|
240
|
+
(
|
|
241
|
+
this.#buttons().find((button) => button.dataset.value === focused) ??
|
|
242
|
+
this.#buttons()[0] ??
|
|
243
|
+
this.part("panel")
|
|
244
|
+
).focus();
|
|
245
|
+
if (this.open) this.floating.position();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
#buttons() {
|
|
249
|
+
return [...this.part("panel").querySelectorAll("button:not(:disabled)")];
|
|
250
|
+
}
|
|
251
|
+
toggle(open, focus = false) {
|
|
252
|
+
super.toggle(open, focus);
|
|
253
|
+
if (open) this.#buttons()[0]?.focus();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* `<omg-tooltip content>` around a focusable control: a brief non-interactive
|
|
259
|
+
* hint immediately on hover or focus. Activation and Esc dismiss it. The text
|
|
260
|
+
* is also attached as aria-description to the actual focused control, across
|
|
261
|
+
* custom-element shadow roots, preserving any existing description.
|
|
262
|
+
*
|
|
263
|
+
* @attr {string} content - Plain text hint; never essential instructions.
|
|
264
|
+
* @attr {"top" | "bottom" | "top-start" | "bottom-start" | "bottom-end"} placement - Preferred placement; top by default.
|
|
265
|
+
* @slot - One focusable control.
|
|
266
|
+
* @part tooltip - Floating hint.
|
|
267
|
+
*/
|
|
268
|
+
class OmgTooltip extends OmgElement {
|
|
269
|
+
static observedAttributes = ["content", "placement"];
|
|
270
|
+
static styles = [
|
|
271
|
+
FLOATING,
|
|
272
|
+
css(`
|
|
273
|
+
:host { display: inline-flex; max-width: 100%; }
|
|
274
|
+
.floating { max-width: min(260px, calc(100vw - 16px)); padding: 5px var(--space-2); border-radius: var(--radius-sm); background: var(--color-ink); color: var(--color-on-ink); font-size: var(--text-sm); line-height: 1.4; pointer-events: none; box-shadow: none; }
|
|
275
|
+
`),
|
|
276
|
+
];
|
|
277
|
+
static template = `<slot></slot><div class="floating" part="tooltip" role="tooltip" popover="manual" hidden></div>`;
|
|
278
|
+
#described;
|
|
279
|
+
#previous;
|
|
280
|
+
#description;
|
|
281
|
+
|
|
282
|
+
constructor() {
|
|
283
|
+
super();
|
|
284
|
+
this.floating = new Floating(
|
|
285
|
+
this,
|
|
286
|
+
this,
|
|
287
|
+
this.part("tooltip"),
|
|
288
|
+
() => this.#hide(),
|
|
289
|
+
() => this.getAttribute("placement") || "top",
|
|
290
|
+
);
|
|
291
|
+
this.addEventListener("pointerenter", () => {
|
|
292
|
+
this.#show();
|
|
293
|
+
});
|
|
294
|
+
this.addEventListener("pointerleave", () => {
|
|
295
|
+
this.#hide();
|
|
296
|
+
});
|
|
297
|
+
this.addEventListener("focusin", (event) => {
|
|
298
|
+
this.#restore();
|
|
299
|
+
this.#described = event.composedPath()[0];
|
|
300
|
+
this.#previous = this.#described.getAttribute("aria-description");
|
|
301
|
+
this.#describe();
|
|
302
|
+
this.#show();
|
|
303
|
+
});
|
|
304
|
+
this.addEventListener("click", () => this.#hide());
|
|
305
|
+
this.addEventListener("focusout", () => {
|
|
306
|
+
this.#restore();
|
|
307
|
+
this.#hide();
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
#describe() {
|
|
312
|
+
if (!this.#described) return;
|
|
313
|
+
this.#description = [this.#previous, this.getAttribute("content")]
|
|
314
|
+
.filter(Boolean)
|
|
315
|
+
.join(". ");
|
|
316
|
+
this.#described.setAttribute("aria-description", this.#description);
|
|
317
|
+
}
|
|
318
|
+
#restore() {
|
|
319
|
+
if (
|
|
320
|
+
this.#described &&
|
|
321
|
+
this.#described.getAttribute("aria-description") === this.#description
|
|
322
|
+
) {
|
|
323
|
+
if (this.#previous === null)
|
|
324
|
+
this.#described.removeAttribute("aria-description");
|
|
325
|
+
else this.#described.setAttribute("aria-description", this.#previous);
|
|
326
|
+
}
|
|
327
|
+
this.#described = undefined;
|
|
328
|
+
}
|
|
329
|
+
#show() {
|
|
330
|
+
if (this.isConnected && this.getAttribute("content")) this.floating.show();
|
|
331
|
+
}
|
|
332
|
+
#hide() {
|
|
333
|
+
this.floating.hide();
|
|
334
|
+
}
|
|
335
|
+
disconnectedCallback() {
|
|
336
|
+
this.#hide();
|
|
337
|
+
this.#restore();
|
|
338
|
+
}
|
|
339
|
+
update() {
|
|
340
|
+
this.part("tooltip").textContent = this.getAttribute("content") || "";
|
|
341
|
+
this.#describe();
|
|
342
|
+
if (!this.getAttribute("content")) this.#hide();
|
|
343
|
+
else if (!this.part("tooltip").hidden) this.floating.position();
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
define("omg-popover", OmgPopover);
|
|
348
|
+
define("omg-menu", OmgMenu);
|
|
349
|
+
define("omg-tooltip", OmgTooltip);
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* `<omg-dialog heading open>`: custom modal content inside the plugin iframe.
|
|
353
|
+
* Native dialog owns focus trapping and Escape; content remains mounted.
|
|
354
|
+
* Programmatic open changes are silent. Simple host confirmations still use ui.confirm.
|
|
355
|
+
*
|
|
356
|
+
* @attr {string} heading - Dialog title and accessible name.
|
|
357
|
+
* @attr {string} description - Optional description below the title.
|
|
358
|
+
* @attr {boolean} open - Shows the modal.
|
|
359
|
+
* @attr {string} close-label - Close button name; defaults to Close.
|
|
360
|
+
* @prop {boolean} open - Modal visibility.
|
|
361
|
+
* @fires {{ reason: "escape" | "backdrop" | "button" }} omg-close - Cancelable user close request; preventDefault keeps the dialog open.
|
|
362
|
+
* @slot - Modal content, retained while closed.
|
|
363
|
+
* @slot footer - Action buttons, aligned at the end.
|
|
364
|
+
* @part panel - Native modal; set max-width for custom sizing.
|
|
365
|
+
* @part heading - Title.
|
|
366
|
+
* @part description - Optional description.
|
|
367
|
+
* @part body - Scrollable content area.
|
|
368
|
+
* @part footer - Action area, hidden when empty.
|
|
369
|
+
* @part close - Close button.
|
|
370
|
+
*/
|
|
371
|
+
class OmgDialog extends OmgElement {
|
|
372
|
+
static observedAttributes = ["heading", "description", "open", "close-label"];
|
|
373
|
+
static styles = [
|
|
374
|
+
css(`
|
|
375
|
+
:host { display: contents; }
|
|
376
|
+
dialog { width: calc(100% - 32px); max-width: 520px; max-height: calc(100% - 32px); margin: auto; padding: 0; border: 0; border-radius: 14px; background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-float); font: inherit; overflow: hidden; }
|
|
377
|
+
dialog[open] { display: flex; flex-direction: column; }
|
|
378
|
+
dialog::backdrop { background: rgb(0 0 0 / 45%); }
|
|
379
|
+
header { display: flex; flex: none; align-items: flex-start; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-4) var(--space-2); }
|
|
380
|
+
h2 { margin: 0; font-size: var(--text-lg); font-weight: var(--weight-semibold); overflow-wrap: anywhere; }
|
|
381
|
+
p { margin: var(--space-1) 0 0; color: var(--color-text-secondary); font-size: var(--text-md); line-height: 1.55; }
|
|
382
|
+
.body { display: flex; flex-direction: column; gap: var(--space-4); min-height: 0; padding: var(--space-2) var(--space-4) var(--space-4); overflow: auto; scrollbar-gutter: stable; }
|
|
383
|
+
footer { display: flex; flex: none; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-top: 1px solid var(--color-border); }
|
|
384
|
+
button { flex: none; display: grid; place-items: center; width: 26px; height: 26px; padding: 0; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--color-text-secondary); cursor: pointer; }
|
|
385
|
+
button:hover { background: var(--color-hover); color: var(--color-text); }
|
|
386
|
+
button svg { width: 16px; height: 16px; }
|
|
387
|
+
`),
|
|
388
|
+
];
|
|
389
|
+
static template = `<dialog part="panel" aria-labelledby="heading"><header><div><h2 id="heading" part="heading"></h2><p id="description" part="description"></p></div><button type="button" part="close"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="m6 6 12 12M18 6 6 18"/></svg></button></header><div class="body" part="body"><slot></slot></div><footer part="footer"><slot name="footer"></slot></footer></dialog>`;
|
|
390
|
+
#opener;
|
|
391
|
+
|
|
392
|
+
constructor() {
|
|
393
|
+
super();
|
|
394
|
+
const panel = this.part("panel");
|
|
395
|
+
this.part("close").addEventListener("click", () => this.#dismiss("button"));
|
|
396
|
+
panel.addEventListener("cancel", (event) => {
|
|
397
|
+
event.preventDefault();
|
|
398
|
+
this.#dismiss("escape");
|
|
399
|
+
});
|
|
400
|
+
panel.addEventListener("pointerdown", (event) => {
|
|
401
|
+
if (event.target !== panel) return;
|
|
402
|
+
const bounds = panel.getBoundingClientRect();
|
|
403
|
+
if (
|
|
404
|
+
event.clientX < bounds.left ||
|
|
405
|
+
event.clientX > bounds.right ||
|
|
406
|
+
event.clientY < bounds.top ||
|
|
407
|
+
event.clientY > bounds.bottom
|
|
408
|
+
)
|
|
409
|
+
this.#dismiss("backdrop");
|
|
410
|
+
});
|
|
411
|
+
panel.addEventListener("close", () => {
|
|
412
|
+
if (this.isConnected && !panel.open) this.open = false;
|
|
413
|
+
});
|
|
414
|
+
this.shadowRoot.addEventListener("slotchange", () => this.update());
|
|
415
|
+
}
|
|
416
|
+
get open() {
|
|
417
|
+
return this.hasAttribute("open");
|
|
418
|
+
}
|
|
419
|
+
set open(value) {
|
|
420
|
+
this.toggleAttribute("open", Boolean(value));
|
|
421
|
+
}
|
|
422
|
+
#dismiss(reason) {
|
|
423
|
+
if (
|
|
424
|
+
this.dispatchEvent(
|
|
425
|
+
new CustomEvent("omg-close", {
|
|
426
|
+
bubbles: true,
|
|
427
|
+
composed: true,
|
|
428
|
+
cancelable: true,
|
|
429
|
+
detail: { reason },
|
|
430
|
+
}),
|
|
431
|
+
)
|
|
432
|
+
)
|
|
433
|
+
this.open = false;
|
|
434
|
+
}
|
|
435
|
+
disconnectedCallback() {
|
|
436
|
+
this.part("panel").close();
|
|
437
|
+
this.#opener = undefined;
|
|
438
|
+
}
|
|
439
|
+
update() {
|
|
440
|
+
const panel = this.part("panel");
|
|
441
|
+
text(this.part("heading"), this.getAttribute("heading"));
|
|
442
|
+
text(this.part("description"), this.getAttribute("description"));
|
|
443
|
+
if (this.getAttribute("description"))
|
|
444
|
+
panel.setAttribute("aria-describedby", "description");
|
|
445
|
+
else panel.removeAttribute("aria-describedby");
|
|
446
|
+
this.part("close").setAttribute(
|
|
447
|
+
"aria-label",
|
|
448
|
+
this.getAttribute("close-label") || "Close",
|
|
449
|
+
);
|
|
450
|
+
this.part("footer").hidden = !filled(
|
|
451
|
+
this.shadowRoot.querySelector('slot[name="footer"]'),
|
|
452
|
+
);
|
|
453
|
+
if (this.open && !panel.open) {
|
|
454
|
+
this.#opener = activeElement(this.ownerDocument);
|
|
455
|
+
panel.showModal();
|
|
456
|
+
} else if (!this.open && panel.open) {
|
|
457
|
+
panel.close();
|
|
458
|
+
if (this.#opener?.isConnected)
|
|
459
|
+
this.#opener.focus({ preventScroll: true });
|
|
460
|
+
this.#opener = undefined;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
define("omg-dialog", OmgDialog);
|