@uvalib/web-components 1.8.5 → 1.10.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/CHANGELOG.md +48 -0
- package/README.md +719 -72
- package/bin/install-skill.mjs +174 -54
- package/dist/base/clipboard.d.ts +9 -0
- package/dist/base/clipboard.js +30 -0
- package/dist/base/clipboard.js.map +1 -0
- package/dist/base.css +301 -3
- package/dist/components/uvalib-citation/UvalibCitation.d.ts +124 -0
- package/dist/components/uvalib-citation/UvalibCitation.js +545 -0
- package/dist/components/uvalib-citation/UvalibCitation.js.map +1 -0
- package/dist/components/uvalib-citation/uvalib-citation.d.ts +1 -0
- package/dist/components/uvalib-citation/uvalib-citation.js +4 -0
- package/dist/components/uvalib-citation/uvalib-citation.js.map +1 -0
- package/dist/components/uvalib-dialog/UvalibDialog.d.ts +167 -0
- package/dist/components/uvalib-dialog/UvalibDialog.js +688 -0
- package/dist/components/uvalib-dialog/UvalibDialog.js.map +1 -0
- package/dist/components/uvalib-dialog/uvalib-dialog.d.ts +1 -0
- package/dist/components/uvalib-dialog/uvalib-dialog.js +4 -0
- package/dist/components/uvalib-dialog/uvalib-dialog.js.map +1 -0
- package/dist/components/uvalib-filter/UvalibFilter.d.ts +92 -9
- package/dist/components/uvalib-filter/UvalibFilter.js +748 -60
- package/dist/components/uvalib-filter/UvalibFilter.js.map +1 -1
- package/dist/components/uvalib-list-filter/UvalibListFilter.d.ts +162 -0
- package/dist/components/uvalib-list-filter/UvalibListFilter.js +685 -0
- package/dist/components/uvalib-list-filter/UvalibListFilter.js.map +1 -0
- package/dist/components/uvalib-list-filter/uvalib-list-filter.d.ts +1 -0
- package/dist/components/uvalib-list-filter/uvalib-list-filter.js +4 -0
- package/dist/components/uvalib-list-filter/uvalib-list-filter.js.map +1 -0
- package/dist/components/uvalib-metadata/UvalibMetadata.js +3 -4
- package/dist/components/uvalib-metadata/UvalibMetadata.js.map +1 -1
- package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.d.ts +28 -1
- package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js +139 -3
- package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js.map +1 -1
- package/dist/custom-elements.json +9503 -6086
- package/dist/edition.css +758 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/styles/base.js +112 -1
- package/dist/styles/base.js.map +1 -1
- package/dist/styles/color-scheme.js +4 -0
- package/dist/styles/color-scheme.js.map +1 -1
- package/dist/styles/controls.js +6 -0
- package/dist/styles/controls.js.map +1 -1
- package/dist/styles/edition.d.ts +1 -0
- package/dist/styles/edition.js +747 -0
- package/dist/styles/edition.js.map +1 -0
- package/dist/styles/field-text.d.ts +1 -0
- package/dist/styles/field-text.js +21 -0
- package/dist/styles/field-text.js.map +1 -0
- package/dist/styles/hidden.js +15 -1
- package/dist/styles/hidden.js.map +1 -1
- package/dist/styles/layout.d.ts +1 -0
- package/dist/styles/layout.js +92 -0
- package/dist/styles/layout.js.map +1 -0
- package/dist/styles/table.d.ts +1 -0
- package/dist/styles/table.js +164 -0
- package/dist/styles/table.js.map +1 -0
- package/dist/tokens.css +4 -0
- package/dist-cdn/base.css +301 -3
- package/dist-cdn/chunks/{base-B3tNX103.js → base-DXkGlSgH.js} +113 -2
- package/dist-cdn/chunks/base-DXkGlSgH.js.map +1 -0
- package/dist-cdn/chunks/clipboard-CNG7Y_5X.js +18 -0
- package/dist-cdn/chunks/clipboard-CNG7Y_5X.js.map +1 -0
- package/dist-cdn/chunks/if-defined-COiQb-gl.js +6 -0
- package/dist-cdn/chunks/if-defined-COiQb-gl.js.map +1 -0
- package/dist-cdn/chunks/{site-header-CEmNtmk5.js → site-header-B78a_ldi.js} +27 -22
- package/dist-cdn/chunks/site-header-B78a_ldi.js.map +1 -0
- package/dist-cdn/chunks/{site-main-nav-CAwKq_x5.js → site-main-nav-CmMq2t8t.js} +52 -51
- package/dist-cdn/chunks/site-main-nav-CmMq2t8t.js.map +1 -0
- package/dist-cdn/custom-elements.json +9503 -6086
- package/dist-cdn/edition.css +758 -0
- package/dist-cdn/manifest.json +7 -3
- package/dist-cdn/site-header.js +1 -1
- package/dist-cdn/site-main-nav.js +1 -1
- package/dist-cdn/site-page.js +3 -3
- package/dist-cdn/site-style.js +1 -1
- package/dist-cdn/skills/uvalib-web-components/SKILL.md +34 -10
- package/dist-cdn/skills/uvalib-web-components/reference/components.md +188 -9
- package/dist-cdn/tokens.css +4 -0
- package/dist-cdn/uvalib-citation.js +382 -0
- package/dist-cdn/uvalib-citation.js.map +1 -0
- package/dist-cdn/uvalib-dialog.js +419 -0
- package/dist-cdn/uvalib-dialog.js.map +1 -0
- package/dist-cdn/uvalib-filter.js +603 -69
- package/dist-cdn/uvalib-filter.js.map +1 -1
- package/dist-cdn/uvalib-list-filter.js +451 -0
- package/dist-cdn/uvalib-list-filter.js.map +1 -0
- package/dist-cdn/uvalib-metadata.js +49 -49
- package/dist-cdn/uvalib-metadata.js.map +1 -1
- package/dist-cdn/uvalib-pagefind-search.js +118 -48
- package/dist-cdn/uvalib-pagefind-search.js.map +1 -1
- package/package.json +14 -1
- package/skills/uvalib-web-components/SKILL.md +34 -10
- package/skills/uvalib-web-components/reference/components.md +188 -9
- package/dist-cdn/chunks/base-B3tNX103.js.map +0 -1
- package/dist-cdn/chunks/site-header-CEmNtmk5.js.map +0 -1
- package/dist-cdn/chunks/site-main-nav-CAwKq_x5.js.map +0 -1
|
@@ -0,0 +1,688 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { css, nothing, unsafeCSS } from 'lit';
|
|
8
|
+
import { html, unsafeStatic } from 'lit/static-html.js';
|
|
9
|
+
import { property } from 'lit/decorators.js';
|
|
10
|
+
import { trackEvent } from '../../base/analytics.js';
|
|
11
|
+
import { attachStateInternals, setState } from '../../base/states.js';
|
|
12
|
+
import { UvalibElement } from '../../base/UvalibElement.js';
|
|
13
|
+
const TAG = 'uvalib-dialog';
|
|
14
|
+
const DEFAULT_LABEL = 'Dialog';
|
|
15
|
+
const SIZES = { small: '30rem', medium: '40rem', large: '60rem' };
|
|
16
|
+
/** Openers anywhere in the document: `<button data-uvalib-dialog="<id>">`. */
|
|
17
|
+
const OPENER = 'data-uvalib-dialog';
|
|
18
|
+
/** Buttons inside the content that close it: `<button data-uvalib-dialog-close value="…">`. */
|
|
19
|
+
const CLOSER = 'data-uvalib-dialog-close';
|
|
20
|
+
/** Invoker commands (`commandfor` + `command`) that open or close it. */
|
|
21
|
+
const SHOW_COMMANDS = new Set(['show-modal', '--show-modal', '--show']);
|
|
22
|
+
const CLOSE_COMMANDS = new Set(['close', 'request-close', '--close']);
|
|
23
|
+
/** Closes the visitor makes (reported to analytics); script closes and removal are not. */
|
|
24
|
+
const VISITOR = new Set([
|
|
25
|
+
'close-button',
|
|
26
|
+
'button',
|
|
27
|
+
'escape',
|
|
28
|
+
'backdrop',
|
|
29
|
+
'form',
|
|
30
|
+
]);
|
|
31
|
+
const squash = (s) => (s ?? '').replace(/\s+/g, ' ').trim();
|
|
32
|
+
let instances = 0;
|
|
33
|
+
/** The focused element, through open shadow roots. */
|
|
34
|
+
function deepActive() {
|
|
35
|
+
let a = document.activeElement;
|
|
36
|
+
while (a?.shadowRoot?.activeElement)
|
|
37
|
+
a = a.shadowRoot.activeElement;
|
|
38
|
+
return a;
|
|
39
|
+
}
|
|
40
|
+
/** Move `node` into `parent` before `before`, keeping its state (`moveBefore`) where the browser can. */
|
|
41
|
+
function move(parent, node, before = null) {
|
|
42
|
+
const p = parent;
|
|
43
|
+
if (p.moveBefore && parent.isConnected && node.isConnected) {
|
|
44
|
+
try {
|
|
45
|
+
p.moveBefore(node, before);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Not movable atomically (another document, say): insert instead.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
parent.insertBefore(node, before);
|
|
53
|
+
}
|
|
54
|
+
/** Whether a click at (x, y) is outside `el`'s box: on the backdrop of a modal dialog. */
|
|
55
|
+
function outside(el, x, y) {
|
|
56
|
+
const r = el.getBoundingClientRect();
|
|
57
|
+
return x < r.left || x > r.right || y < r.top || y > r.bottom;
|
|
58
|
+
}
|
|
59
|
+
/** The first element in the event's path (across shadow roots) that has `attr`. */
|
|
60
|
+
function pathWith(e, attr) {
|
|
61
|
+
for (const n of e.composedPath()) {
|
|
62
|
+
if (n instanceof Element && n.hasAttribute(attr))
|
|
63
|
+
return n;
|
|
64
|
+
if (n === document)
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
/** The `<uvalib-dialog>` with `id`, in the opener's own root first, then the document. */
|
|
70
|
+
function dialogById(from, id) {
|
|
71
|
+
if (!id)
|
|
72
|
+
return undefined;
|
|
73
|
+
const root = from.getRootNode();
|
|
74
|
+
const el = root.getElementById?.(id) ?? document.getElementById(id);
|
|
75
|
+
return el instanceof UvalibDialog ? el : undefined;
|
|
76
|
+
}
|
|
77
|
+
/** One delegated click listener for every opener in the document, also those added later. */
|
|
78
|
+
let delegated = false;
|
|
79
|
+
function delegateOpeners() {
|
|
80
|
+
if (delegated)
|
|
81
|
+
return;
|
|
82
|
+
delegated = true;
|
|
83
|
+
document.addEventListener('click', (e) => {
|
|
84
|
+
if (e.defaultPrevented || e.button !== 0)
|
|
85
|
+
return;
|
|
86
|
+
const opener = pathWith(e, OPENER);
|
|
87
|
+
if (!opener)
|
|
88
|
+
return;
|
|
89
|
+
const dialog = dialogById(opener, squash(opener.getAttribute(OPENER)));
|
|
90
|
+
if (!dialog)
|
|
91
|
+
return;
|
|
92
|
+
if (opener instanceof HTMLAnchorElement)
|
|
93
|
+
e.preventDefault(); // never navigate
|
|
94
|
+
dialog.openFrom(opener);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A modal dialog for content and short forms: search tips, Cite, a sign-in prompt, a request
|
|
99
|
+
* form. Use it instead of a hand-built modal, a `role="dialog"` div or a framework's dialog.
|
|
100
|
+
*
|
|
101
|
+
* The children are the content. In shadow DOM they are slotted, never moved, so the page's CSS,
|
|
102
|
+
* ids, listeners and framework-rendered nodes keep working; with `no-shadow-dom` they are moved
|
|
103
|
+
* into the dialog (the same nodes, in the same document). It opens as a native `<dialog>` with
|
|
104
|
+
* `showModal()`: everything else on the page, `<site-page>`'s shadow header included, is inert
|
|
105
|
+
* while it is open, so focus stays inside without a trap script. The visible heading (`label`,
|
|
106
|
+
* an `<h2>` unless `heading-level` says otherwise) names it, and a 44px Close button is always
|
|
107
|
+
* shown; `description` (or a `slot="description"` child) is shown under the heading and is the
|
|
108
|
+
* dialog's description.
|
|
109
|
+
*
|
|
110
|
+
* Open it with a button anywhere in the page, `<button type="button" data-uvalib-dialog="<id>">`
|
|
111
|
+
* (one delegated listener, so buttons rendered later work too), with an invoker button
|
|
112
|
+
* (`commandfor="<id>" command="--show-modal"`) where the browser has invoker commands, with
|
|
113
|
+
* `show()`, or by setting `open`. On open, focus goes to the content's `[autofocus]` element
|
|
114
|
+
* when it has one (a form dialog: the first field), else to the heading, so a screen reader
|
|
115
|
+
* reads the dialog from the top and long content starts in view. On every close (Close,
|
|
116
|
+
* Escape, the backdrop, a `data-uvalib-dialog-close` button, a `<form method="dialog">`
|
|
117
|
+
* submitted, `close()`) focus returns to the element that opened it; if that is gone, to
|
|
118
|
+
* `return-focus` (a selector, or an element set as the property).
|
|
119
|
+
*
|
|
120
|
+
* Escape always closes it. A click on the backdrop closes it too (the native
|
|
121
|
+
* `closedby="any"`, or the same check in script where the browser lacks it), except with
|
|
122
|
+
* `persistent`, and never when a press starts inside the dialog and ends on the backdrop (a
|
|
123
|
+
* text selection or a drag). A `<form method="dialog">` in the content closes it on submit
|
|
124
|
+
* with the submitter's `value` as `returnValue`; other forms submit as usual.
|
|
125
|
+
*
|
|
126
|
+
* `size` is `small` (30rem), `medium` (the default, 40rem) or `large` (60rem) at most, and
|
|
127
|
+
* never wider or taller than the viewport less 16px on each side; the content scrolls inside
|
|
128
|
+
* it under a header that stays in view.
|
|
129
|
+
*
|
|
130
|
+
* @tagname uvalib-dialog
|
|
131
|
+
* @slot - The content: text, links, a form.
|
|
132
|
+
* @slot description - A short description under the heading, read as the dialog's description (instead of the `description` attribute).
|
|
133
|
+
* @fires uvalib-dialog-open - The dialog opened: `detail` is `{ reason }`, `button` (a visitor's opener) or `api` (`show()` or `open`). Bubbles and is composed.
|
|
134
|
+
* @fires uvalib-dialog-close - The dialog closed: `detail` is `{ reason, returnValue }`, `reason` one of `close-button`, `button` (a `data-uvalib-dialog-close` or invoker close button), `escape`, `backdrop`, `form` (a `<form method="dialog">`), `api` (`close()` or `open = false`) or `removed` (taken out of the page while open). Bubbles and is composed.
|
|
135
|
+
* @fires uvalib-analytics-event - For `<site-analytics>`: `['uvalib-dialog', 'open', '<label>']` when a visitor's button opens it, and `['uvalib-dialog', 'close', '<label>']` when the visitor closes it (Close, a close button, Escape, the backdrop or a dialog form); never on `show()`, `close()` or `open` from script, and never the content. Bubbles and is composed.
|
|
136
|
+
* @cssstate open - The dialog is open.
|
|
137
|
+
* @csspart dialog - The `<dialog>`.
|
|
138
|
+
* @csspart header - The heading row (the heading and Close).
|
|
139
|
+
* @csspart heading - The heading.
|
|
140
|
+
* @csspart close - The Close button.
|
|
141
|
+
* @csspart description - The description under the heading.
|
|
142
|
+
* @csspart body - The scrolling wrapper of the content.
|
|
143
|
+
* @cssprop --uvalib-dialog-width - The dialog's widest inline size, instead of `size`'s (still never wider than the viewport less 16px on each side).
|
|
144
|
+
* @cssprop --uva-color-surface - Dark-mode role token: dialog background (else #fff).
|
|
145
|
+
* @cssprop --uva-color-text - Dark-mode role token: dialog text (else `--uva-grey-darkest`, #2b2b2b).
|
|
146
|
+
* @cssprop --uva-color-text-muted - Dark-mode role token: the description (else #4b5563, 7.5:1 on white).
|
|
147
|
+
* @cssprop --uva-color-border - Dark-mode role token: dialog edge and heading rule (else #dadada).
|
|
148
|
+
* @cssprop --uva-color-button-bg - Dark-mode role token: Close's border and text (else `--uva-blue-alt`, #007bac).
|
|
149
|
+
* @cssprop --uva-color-button-hover-bg - Dark-mode role token: hovered Close (else `--uva-blue-alt-A`, #005679).
|
|
150
|
+
* @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).
|
|
151
|
+
*/
|
|
152
|
+
export class UvalibDialog extends UvalibElement {
|
|
153
|
+
constructor() {
|
|
154
|
+
super(...arguments);
|
|
155
|
+
/** The visible heading and the dialog's accessible name. */
|
|
156
|
+
this.label = '';
|
|
157
|
+
/** The heading's level, 1 to 6 (default 2). */
|
|
158
|
+
this.headingLevel = 2;
|
|
159
|
+
/** A short description under the heading (or a `slot="description"` child), read as the dialog's description. */
|
|
160
|
+
this.description = '';
|
|
161
|
+
/** The widest the dialog gets: `small` (30rem), `medium` (40rem) or `large` (60rem). */
|
|
162
|
+
this.size = 'medium';
|
|
163
|
+
/** Whether it is open. Reflected; setting it opens or closes the dialog (as `show()` and `close()`). */
|
|
164
|
+
this.open = false;
|
|
165
|
+
/** A click on the backdrop does not close it (Escape and Close still do). For forms that would lose typed text. */
|
|
166
|
+
this.persistent = false;
|
|
167
|
+
/** Where focus goes on close when the opener is gone: a selector (in the dialog's root, then the document) or an element. */
|
|
168
|
+
this.returnFocus = null;
|
|
169
|
+
/** The Close button's text. */
|
|
170
|
+
this.closeLabel = 'Close';
|
|
171
|
+
this.uid = `${TAG}-${++instances}`;
|
|
172
|
+
this.internals = attachStateInternals(this);
|
|
173
|
+
/** The element focused when it opened (or the button that opened it). */
|
|
174
|
+
this.opener = null;
|
|
175
|
+
/** Whether the dialog is showing, as far as this element has settled it. */
|
|
176
|
+
this.shown = false;
|
|
177
|
+
/** A press that started on the backdrop (not inside the dialog). */
|
|
178
|
+
this.downOnBackdrop = false;
|
|
179
|
+
/** Whether the last pointer press, rather than a key, came last: a cancel then is the backdrop. */
|
|
180
|
+
this.pointerLast = false;
|
|
181
|
+
/** Whether the last render had a description child. */
|
|
182
|
+
this.descChild = false;
|
|
183
|
+
// ------------------------------------------------------------------ events
|
|
184
|
+
/** Invoker commands aimed at this element (`commandfor="<id>"`). */
|
|
185
|
+
this.onCommand = (e) => {
|
|
186
|
+
const command = e.command ?? '';
|
|
187
|
+
if (SHOW_COMMANDS.has(command)) {
|
|
188
|
+
e.preventDefault();
|
|
189
|
+
const src = e.source ?? deepActive();
|
|
190
|
+
if (!this.shown)
|
|
191
|
+
this.reveal('button', src);
|
|
192
|
+
}
|
|
193
|
+
else if (CLOSE_COMMANDS.has(command)) {
|
|
194
|
+
e.preventDefault();
|
|
195
|
+
this.closeWith('button');
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
/** A `<form method="dialog">` in the content closes it with the submitter's value. */
|
|
199
|
+
this.onSubmit = (e) => {
|
|
200
|
+
if (e.defaultPrevented || !this.shown)
|
|
201
|
+
return;
|
|
202
|
+
const form = e.target;
|
|
203
|
+
if (!(form instanceof HTMLFormElement) || form.closest(TAG) !== this)
|
|
204
|
+
return;
|
|
205
|
+
const sub = e.submitter;
|
|
206
|
+
const method = sub?.hasAttribute('formmethod') ? sub.formMethod : form.method;
|
|
207
|
+
if (method !== 'dialog')
|
|
208
|
+
return;
|
|
209
|
+
e.preventDefault();
|
|
210
|
+
this.closeWith('form', sub?.hasAttribute('value') ? sub.value : undefined);
|
|
211
|
+
};
|
|
212
|
+
/** `data-uvalib-dialog-close` buttons in the content. */
|
|
213
|
+
this.onContentClick = (e) => {
|
|
214
|
+
if (!this.shown || e.defaultPrevented)
|
|
215
|
+
return;
|
|
216
|
+
const closer = pathWith(e, CLOSER);
|
|
217
|
+
if (!closer || closer.closest(TAG) !== this)
|
|
218
|
+
return;
|
|
219
|
+
if (closer.disabled)
|
|
220
|
+
return;
|
|
221
|
+
const value = closer.getAttribute(CLOSER) || closer.getAttribute('value') || undefined;
|
|
222
|
+
this.closeWith('button', value ?? undefined);
|
|
223
|
+
};
|
|
224
|
+
this.onCloseClick = () => this.closeWith('close-button');
|
|
225
|
+
/** Escape, or the native light dismiss (`closedby="any"`), asks to close. */
|
|
226
|
+
this.onCancel = () => {
|
|
227
|
+
this.closeReason = this.pointerLast && this.downOnBackdrop ? 'backdrop' : 'escape';
|
|
228
|
+
};
|
|
229
|
+
this.onKeydown = () => {
|
|
230
|
+
this.pointerLast = false;
|
|
231
|
+
};
|
|
232
|
+
this.onPointerDown = (e) => {
|
|
233
|
+
const dialog = this.dialog;
|
|
234
|
+
this.pointerLast = true;
|
|
235
|
+
this.downOnBackdrop = !!dialog && e.target === dialog && outside(dialog, e.clientX, e.clientY);
|
|
236
|
+
};
|
|
237
|
+
/** Without native `closedby`: a click whose press and release are both on the backdrop closes it. */
|
|
238
|
+
this.onDialogClick = (e) => {
|
|
239
|
+
const dialog = this.dialog;
|
|
240
|
+
if (!dialog || !this.shown || this.persistent || nativeLightDismiss())
|
|
241
|
+
return;
|
|
242
|
+
const started = this.downOnBackdrop;
|
|
243
|
+
this.downOnBackdrop = false;
|
|
244
|
+
if (!started || e.target !== dialog || !outside(dialog, e.clientX, e.clientY))
|
|
245
|
+
return;
|
|
246
|
+
this.closeWith('backdrop');
|
|
247
|
+
};
|
|
248
|
+
/** The dialog's own close event: settles Escape, the native backdrop close, or any close not made by this element. */
|
|
249
|
+
this.onDialogClose = () => {
|
|
250
|
+
if (this.dialog?.open)
|
|
251
|
+
return; // reopened before the event arrived
|
|
252
|
+
this.closed();
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
static { this.styles = css `
|
|
256
|
+
:host {
|
|
257
|
+
display: contents;
|
|
258
|
+
}
|
|
259
|
+
:host([hidden]) {
|
|
260
|
+
display: none;
|
|
261
|
+
}
|
|
262
|
+
.dlg {
|
|
263
|
+
--dlg-size: ${unsafeCSS(SIZES.medium)};
|
|
264
|
+
box-sizing: border-box;
|
|
265
|
+
inline-size: min(var(--uvalib-dialog-width, var(--dlg-size)), 100% - 32px);
|
|
266
|
+
max-inline-size: none;
|
|
267
|
+
max-block-size: calc(100% - 32px);
|
|
268
|
+
margin: auto;
|
|
269
|
+
padding: 0;
|
|
270
|
+
border: 1px solid var(--uva-color-border, #dadada);
|
|
271
|
+
background: var(--uva-color-surface, #fff);
|
|
272
|
+
color: var(--uva-color-text, var(--uva-grey-darkest, #2b2b2b));
|
|
273
|
+
font-size: 1rem;
|
|
274
|
+
line-height: 1.5;
|
|
275
|
+
overflow: hidden;
|
|
276
|
+
}
|
|
277
|
+
:host([size='small']) .dlg {
|
|
278
|
+
--dlg-size: ${unsafeCSS(SIZES.small)};
|
|
279
|
+
}
|
|
280
|
+
:host([size='large']) .dlg {
|
|
281
|
+
--dlg-size: ${unsafeCSS(SIZES.large)};
|
|
282
|
+
}
|
|
283
|
+
.dlg[open] {
|
|
284
|
+
display: flex;
|
|
285
|
+
flex-direction: column;
|
|
286
|
+
}
|
|
287
|
+
.dlg::backdrop {
|
|
288
|
+
background: rgb(0 0 0 / 0.5);
|
|
289
|
+
}
|
|
290
|
+
.dlg-head {
|
|
291
|
+
flex: none;
|
|
292
|
+
display: flex;
|
|
293
|
+
align-items: center;
|
|
294
|
+
justify-content: space-between;
|
|
295
|
+
gap: 1rem;
|
|
296
|
+
padding: 0.75rem 1rem 0.75rem 1.25rem;
|
|
297
|
+
border-block-end: 1px solid var(--uva-color-border, #dadada);
|
|
298
|
+
}
|
|
299
|
+
.dlg-heading {
|
|
300
|
+
margin: 0;
|
|
301
|
+
font-size: 1.25rem;
|
|
302
|
+
line-height: 1.2;
|
|
303
|
+
overflow-wrap: anywhere;
|
|
304
|
+
text-wrap: balance;
|
|
305
|
+
}
|
|
306
|
+
.dlg-heading:focus {
|
|
307
|
+
outline: none;
|
|
308
|
+
}
|
|
309
|
+
.dlg-heading:focus-visible {
|
|
310
|
+
outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
|
|
311
|
+
outline-offset: 2px;
|
|
312
|
+
}
|
|
313
|
+
.dlg-close {
|
|
314
|
+
flex: none;
|
|
315
|
+
display: inline-flex;
|
|
316
|
+
align-items: center;
|
|
317
|
+
justify-content: center;
|
|
318
|
+
box-sizing: border-box;
|
|
319
|
+
min-block-size: 44px;
|
|
320
|
+
min-inline-size: 44px;
|
|
321
|
+
margin: 0;
|
|
322
|
+
padding: 0.5rem 0.875rem;
|
|
323
|
+
border: 2px solid var(--uva-color-button-bg, var(--uva-blue-alt, #007bac));
|
|
324
|
+
border-radius: 5px;
|
|
325
|
+
background: transparent;
|
|
326
|
+
color: var(--uva-color-button-bg, var(--uva-blue-alt, #007bac));
|
|
327
|
+
font: inherit;
|
|
328
|
+
font-size: 1rem;
|
|
329
|
+
line-height: 1.2;
|
|
330
|
+
cursor: pointer;
|
|
331
|
+
}
|
|
332
|
+
.dlg-close:hover {
|
|
333
|
+
border-color: var(--uva-color-button-hover-bg, var(--uva-blue-alt-A, #005679));
|
|
334
|
+
color: var(--uva-color-button-hover-bg, var(--uva-blue-alt-A, #005679));
|
|
335
|
+
}
|
|
336
|
+
.dlg-close:focus-visible {
|
|
337
|
+
outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
|
|
338
|
+
outline-offset: 2px;
|
|
339
|
+
}
|
|
340
|
+
.dlg-body {
|
|
341
|
+
flex: 1 1 auto;
|
|
342
|
+
min-block-size: 0;
|
|
343
|
+
padding: 1rem 1.25rem 1.25rem;
|
|
344
|
+
overflow: auto;
|
|
345
|
+
overscroll-behavior: contain;
|
|
346
|
+
overflow-wrap: break-word;
|
|
347
|
+
}
|
|
348
|
+
.dlg-desc {
|
|
349
|
+
margin: 0 0 1rem;
|
|
350
|
+
color: var(--uva-color-text-muted, #4b5563);
|
|
351
|
+
}
|
|
352
|
+
.dlg-desc[hidden] {
|
|
353
|
+
display: none;
|
|
354
|
+
}
|
|
355
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
356
|
+
.dlg[open] {
|
|
357
|
+
animation: uvalib-dialog-in 0.15s ease-out;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
@keyframes uvalib-dialog-in {
|
|
361
|
+
from {
|
|
362
|
+
opacity: 0;
|
|
363
|
+
transform: translateY(0.5rem);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
@media (forced-colors: active) {
|
|
367
|
+
.dlg {
|
|
368
|
+
border: 2px solid CanvasText;
|
|
369
|
+
}
|
|
370
|
+
.dlg-close {
|
|
371
|
+
border-color: ButtonText;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
`; }
|
|
375
|
+
get root() {
|
|
376
|
+
return this.renderRoot;
|
|
377
|
+
}
|
|
378
|
+
get dialog() {
|
|
379
|
+
return this.root.querySelector('dialog.dlg');
|
|
380
|
+
}
|
|
381
|
+
get heading() {
|
|
382
|
+
return this.root.querySelector('.dlg-heading');
|
|
383
|
+
}
|
|
384
|
+
/** The dialog's return value: the submitter's `value` of a `<form method="dialog">`, or what `close()` was given. Empty on open. */
|
|
385
|
+
get returnValue() {
|
|
386
|
+
return this.dialog?.returnValue ?? '';
|
|
387
|
+
}
|
|
388
|
+
connectedCallback() {
|
|
389
|
+
super.connectedCallback();
|
|
390
|
+
delegateOpeners();
|
|
391
|
+
this.addEventListener('command', this.onCommand);
|
|
392
|
+
this.addEventListener('submit', this.onSubmit);
|
|
393
|
+
this.addEventListener('click', this.onContentClick);
|
|
394
|
+
if (this.lightDom && !this.content) {
|
|
395
|
+
const content = this.ownerDocument.createElement('div');
|
|
396
|
+
content.className = 'dlg-content';
|
|
397
|
+
this.content = content;
|
|
398
|
+
for (const n of [...this.childNodes])
|
|
399
|
+
move(content, n);
|
|
400
|
+
this.append(content);
|
|
401
|
+
}
|
|
402
|
+
if (this.lightDom && this.hasUpdated)
|
|
403
|
+
this.watchChildren();
|
|
404
|
+
}
|
|
405
|
+
/** Moved with `moveBefore()`: stay as it is (open or not). */
|
|
406
|
+
connectedMoveCallback() { }
|
|
407
|
+
disconnectedCallback() {
|
|
408
|
+
super.disconnectedCallback();
|
|
409
|
+
this.removeEventListener('command', this.onCommand);
|
|
410
|
+
this.removeEventListener('submit', this.onSubmit);
|
|
411
|
+
this.removeEventListener('click', this.onContentClick);
|
|
412
|
+
this.childObserver?.disconnect();
|
|
413
|
+
if (this.shown) {
|
|
414
|
+
this.closeReason = 'removed';
|
|
415
|
+
this.dialog?.close();
|
|
416
|
+
this.closed();
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
/** Open the dialog (modal). Focus returns to the element focused now when it closes. */
|
|
420
|
+
show() {
|
|
421
|
+
this.reveal('api', deepActive());
|
|
422
|
+
}
|
|
423
|
+
/** Close the dialog, with `returnValue` if given. Focus returns to the opener. */
|
|
424
|
+
close(returnValue) {
|
|
425
|
+
this.closeWith('api', returnValue);
|
|
426
|
+
}
|
|
427
|
+
/** @internal A visitor's button (`data-uvalib-dialog` or an invoker) opens it. */
|
|
428
|
+
openFrom(opener) {
|
|
429
|
+
if (this.shown)
|
|
430
|
+
return;
|
|
431
|
+
this.reveal('button', opener);
|
|
432
|
+
}
|
|
433
|
+
reveal(reason, opener) {
|
|
434
|
+
if (this.shown)
|
|
435
|
+
return;
|
|
436
|
+
const dialog = this.dialog;
|
|
437
|
+
if (!dialog || !this.isConnected) {
|
|
438
|
+
// Not rendered yet: open once it is.
|
|
439
|
+
this.pendingOpen = { reason, opener };
|
|
440
|
+
this.open = true;
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
this.pendingOpen = undefined;
|
|
444
|
+
try {
|
|
445
|
+
dialog.returnValue = '';
|
|
446
|
+
dialog.showModal();
|
|
447
|
+
}
|
|
448
|
+
catch (err) {
|
|
449
|
+
console.warn(`${TAG}: could not open the dialog.`, err);
|
|
450
|
+
this.open = false;
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
this.opener = opener && !this.contains(opener) ? opener : null;
|
|
454
|
+
this.shown = true;
|
|
455
|
+
this.closeReason = undefined;
|
|
456
|
+
this.downOnBackdrop = false;
|
|
457
|
+
this.pointerLast = false;
|
|
458
|
+
this.open = true;
|
|
459
|
+
setState(this.internals, 'open', true);
|
|
460
|
+
this.focusInitial();
|
|
461
|
+
if (reason === 'button')
|
|
462
|
+
trackEvent(this, [TAG, 'open', this.name]);
|
|
463
|
+
this.dispatchEvent(new CustomEvent('uvalib-dialog-open', {
|
|
464
|
+
detail: { reason },
|
|
465
|
+
bubbles: true,
|
|
466
|
+
composed: true,
|
|
467
|
+
}));
|
|
468
|
+
}
|
|
469
|
+
closeWith(reason, returnValue) {
|
|
470
|
+
if (!this.shown) {
|
|
471
|
+
this.pendingOpen = undefined;
|
|
472
|
+
this.open = false;
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
this.closeReason = reason;
|
|
476
|
+
const dialog = this.dialog;
|
|
477
|
+
if (dialog?.open) {
|
|
478
|
+
if (returnValue === undefined)
|
|
479
|
+
dialog.close();
|
|
480
|
+
else
|
|
481
|
+
dialog.close(returnValue);
|
|
482
|
+
}
|
|
483
|
+
this.closed();
|
|
484
|
+
}
|
|
485
|
+
/** The dialog has closed, however it happened: restore focus, report, tell the page. */
|
|
486
|
+
closed() {
|
|
487
|
+
if (!this.shown)
|
|
488
|
+
return;
|
|
489
|
+
// A close the browser made without a cancel event first is still a close request.
|
|
490
|
+
const reason = this.closeReason ?? 'escape';
|
|
491
|
+
this.closeReason = undefined;
|
|
492
|
+
this.shown = false;
|
|
493
|
+
this.open = false;
|
|
494
|
+
setState(this.internals, 'open', false);
|
|
495
|
+
this.restoreFocus();
|
|
496
|
+
if (VISITOR.has(reason))
|
|
497
|
+
trackEvent(this, [TAG, 'close', this.name]);
|
|
498
|
+
this.dispatchEvent(new CustomEvent('uvalib-dialog-close', {
|
|
499
|
+
detail: { reason, returnValue: this.returnValue },
|
|
500
|
+
bubbles: true,
|
|
501
|
+
composed: true,
|
|
502
|
+
}));
|
|
503
|
+
}
|
|
504
|
+
get name() {
|
|
505
|
+
return squash(this.label) || DEFAULT_LABEL;
|
|
506
|
+
}
|
|
507
|
+
/** The content's elements (slotted, or in the content wrapper in light mode). */
|
|
508
|
+
contentQuery(selector) {
|
|
509
|
+
const scope = this.lightDom ? this.content : this;
|
|
510
|
+
for (const el of scope?.querySelectorAll(selector) ?? []) {
|
|
511
|
+
if (el.closest(TAG) !== this)
|
|
512
|
+
continue; // a nested dialog's own content
|
|
513
|
+
if (el.getClientRects().length === 0)
|
|
514
|
+
continue;
|
|
515
|
+
return el;
|
|
516
|
+
}
|
|
517
|
+
return null;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* APG: focus the first field of a form dialog (mark it `autofocus`), else a static element at
|
|
521
|
+
* the top, the heading, so the start of the content stays in view and is read first.
|
|
522
|
+
*/
|
|
523
|
+
focusInitial() {
|
|
524
|
+
const auto = this.contentQuery('[autofocus]');
|
|
525
|
+
if (auto) {
|
|
526
|
+
auto.focus();
|
|
527
|
+
if (deepActive() === auto)
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
this.heading?.focus();
|
|
531
|
+
}
|
|
532
|
+
restoreFocus() {
|
|
533
|
+
const candidates = [this.opener, this.returnTarget()];
|
|
534
|
+
this.opener = null;
|
|
535
|
+
for (const c of candidates) {
|
|
536
|
+
if (!(c instanceof HTMLElement) || !c.isConnected)
|
|
537
|
+
continue;
|
|
538
|
+
c.focus();
|
|
539
|
+
if (deepActive() === c)
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
returnTarget() {
|
|
544
|
+
const r = this.returnFocus;
|
|
545
|
+
if (r instanceof Element)
|
|
546
|
+
return r;
|
|
547
|
+
const sel = squash(typeof r === 'string' ? r : '');
|
|
548
|
+
if (!sel)
|
|
549
|
+
return null;
|
|
550
|
+
try {
|
|
551
|
+
const root = this.getRootNode();
|
|
552
|
+
return root.querySelector(sel) ?? document.querySelector(sel);
|
|
553
|
+
}
|
|
554
|
+
catch {
|
|
555
|
+
console.warn(`${TAG}: return-focus "${sel}" is not a valid selector.`);
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
// ------------------------------------------------------------------ light DOM
|
|
560
|
+
/** Light mode: children the page adds later go into the content too. */
|
|
561
|
+
watchChildren() {
|
|
562
|
+
this.childObserver ??= new MutationObserver(() => this.adopt());
|
|
563
|
+
this.childObserver.observe(this, { childList: true });
|
|
564
|
+
this.adopt();
|
|
565
|
+
}
|
|
566
|
+
adopt() {
|
|
567
|
+
const content = this.content;
|
|
568
|
+
if (!content || !this.own)
|
|
569
|
+
return;
|
|
570
|
+
const desc = this.root.querySelector('.dlg-desc');
|
|
571
|
+
for (const n of [...this.childNodes]) {
|
|
572
|
+
if (this.own.has(n) || n === content)
|
|
573
|
+
continue;
|
|
574
|
+
if (n.nodeType === Node.COMMENT_NODE)
|
|
575
|
+
continue;
|
|
576
|
+
if (n.nodeType === Node.TEXT_NODE && !squash(n.textContent))
|
|
577
|
+
continue;
|
|
578
|
+
move(content, n);
|
|
579
|
+
}
|
|
580
|
+
// slot="description" children go under the heading.
|
|
581
|
+
let moved = false;
|
|
582
|
+
for (const n of [...content.children]) {
|
|
583
|
+
if (n.getAttribute('slot') === 'description' && desc) {
|
|
584
|
+
move(desc, n);
|
|
585
|
+
moved = true;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
if (moved)
|
|
589
|
+
this.descriptionChanged();
|
|
590
|
+
}
|
|
591
|
+
/** Re-render when a description child appears or goes. */
|
|
592
|
+
descriptionChanged() {
|
|
593
|
+
if (!!this.descriptionChild !== this.descChild)
|
|
594
|
+
this.requestUpdate();
|
|
595
|
+
}
|
|
596
|
+
/** A `slot="description"` child of this dialog (not of a nested one). */
|
|
597
|
+
get descriptionChild() {
|
|
598
|
+
for (const el of this.querySelectorAll('[slot="description"]'))
|
|
599
|
+
if (el.parentElement?.closest(TAG) === this)
|
|
600
|
+
return el;
|
|
601
|
+
return null;
|
|
602
|
+
}
|
|
603
|
+
firstUpdated() {
|
|
604
|
+
if (this.lightDom) {
|
|
605
|
+
const body = this.root.querySelector('.dlg-body');
|
|
606
|
+
if (body && this.content)
|
|
607
|
+
move(body, this.content);
|
|
608
|
+
this.own = new Set(this.childNodes);
|
|
609
|
+
this.watchChildren();
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
updated(changed) {
|
|
613
|
+
super.updated(changed);
|
|
614
|
+
if (!changed.has('open'))
|
|
615
|
+
return;
|
|
616
|
+
if (this.open && !this.shown) {
|
|
617
|
+
const pending = this.pendingOpen ?? { reason: 'api', opener: deepActive() };
|
|
618
|
+
this.reveal(pending.reason, pending.opener);
|
|
619
|
+
}
|
|
620
|
+
else if (!this.open && this.shown) {
|
|
621
|
+
this.closeWith('api');
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
render() {
|
|
625
|
+
const label = this.name;
|
|
626
|
+
const level = Math.min(6, Math.max(1, Math.trunc(this.headingLevel) || 2));
|
|
627
|
+
const h = unsafeStatic(`h${level}`);
|
|
628
|
+
const headingId = `${this.uid}-heading`;
|
|
629
|
+
const descId = `${this.uid}-desc`;
|
|
630
|
+
const desc = squash(this.description);
|
|
631
|
+
this.descChild = !!this.descriptionChild;
|
|
632
|
+
const hasDesc = !!desc || this.descChild;
|
|
633
|
+
return html `<dialog
|
|
634
|
+
class="dlg"
|
|
635
|
+
part="dialog"
|
|
636
|
+
aria-labelledby=${headingId}
|
|
637
|
+
aria-describedby=${hasDesc ? descId : nothing}
|
|
638
|
+
closedby=${this.persistent ? 'closerequest' : 'any'}
|
|
639
|
+
@cancel=${this.onCancel}
|
|
640
|
+
@close=${this.onDialogClose}
|
|
641
|
+
@click=${this.onDialogClick}
|
|
642
|
+
@pointerdown=${this.onPointerDown}
|
|
643
|
+
@keydown=${this.onKeydown}
|
|
644
|
+
>
|
|
645
|
+
<div class="dlg-head" part="header">
|
|
646
|
+
<${h} class="dlg-heading" part="heading" id=${headingId} tabindex="-1">${label}</${h}>
|
|
647
|
+
<button type="button" class="dlg-close" part="close" @click=${this.onCloseClick}>
|
|
648
|
+
${squash(this.closeLabel) || 'Close'}
|
|
649
|
+
</button>
|
|
650
|
+
</div>
|
|
651
|
+
<div class="dlg-body" part="body">
|
|
652
|
+
<p class="dlg-desc" part="description" id=${descId} ?hidden=${!hasDesc}>${desc}${this.lightDom
|
|
653
|
+
? nothing
|
|
654
|
+
: html `<slot name="description" @slotchange=${() => this.descriptionChanged()}></slot>`}</p>
|
|
655
|
+
${this.lightDom ? nothing : html `<slot></slot>`}
|
|
656
|
+
</div>
|
|
657
|
+
</dialog>`;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
__decorate([
|
|
661
|
+
property({ type: String })
|
|
662
|
+
], UvalibDialog.prototype, "label", void 0);
|
|
663
|
+
__decorate([
|
|
664
|
+
property({ type: Number, attribute: 'heading-level' })
|
|
665
|
+
], UvalibDialog.prototype, "headingLevel", void 0);
|
|
666
|
+
__decorate([
|
|
667
|
+
property({ type: String })
|
|
668
|
+
], UvalibDialog.prototype, "description", void 0);
|
|
669
|
+
__decorate([
|
|
670
|
+
property({ type: String, reflect: true })
|
|
671
|
+
], UvalibDialog.prototype, "size", void 0);
|
|
672
|
+
__decorate([
|
|
673
|
+
property({ type: Boolean, reflect: true })
|
|
674
|
+
], UvalibDialog.prototype, "open", void 0);
|
|
675
|
+
__decorate([
|
|
676
|
+
property({ type: Boolean })
|
|
677
|
+
], UvalibDialog.prototype, "persistent", void 0);
|
|
678
|
+
__decorate([
|
|
679
|
+
property({ attribute: 'return-focus' })
|
|
680
|
+
], UvalibDialog.prototype, "returnFocus", void 0);
|
|
681
|
+
__decorate([
|
|
682
|
+
property({ type: String, attribute: 'close-label' })
|
|
683
|
+
], UvalibDialog.prototype, "closeLabel", void 0);
|
|
684
|
+
/** Whether the browser closes a `closedby="any"` dialog on a backdrop click itself. */
|
|
685
|
+
function nativeLightDismiss() {
|
|
686
|
+
return 'closedBy' in HTMLDialogElement.prototype;
|
|
687
|
+
}
|
|
688
|
+
//# sourceMappingURL=UvalibDialog.js.map
|