@digital-realty/ix-dialog 1.0.30-alpha.0 → 1.0.30
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/dist/IxDialog.d.ts +21 -21
- package/dist/IxDialog.js +43 -43
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/dialog.d.ts +107 -107
- package/dist/internal/dialog.js +391 -391
- package/dist/internal/dialog.js.map +1 -1
- package/dist/ix-dialog.d.ts +4 -4
- package/dist/ix-dialog.js +6 -6
- package/dist/md-dialog.d.ts +6 -6
- package/dist/md-dialog.js +7 -7
- package/dist/react/IxDialog.d.ts +2 -2
- package/dist/react/IxDialog.js +9 -9
- package/dist/react/IxDialog.js.map +1 -1
- package/package.json +2 -2
package/dist/internal/dialog.js
CHANGED
|
@@ -1,215 +1,215 @@
|
|
|
1
|
-
/* eslint-disable no-shadow */
|
|
2
|
-
/* eslint-disable class-methods-use-this */
|
|
3
|
-
/**
|
|
4
|
-
* @license
|
|
5
|
-
* Copyright 2023 Google LLC
|
|
6
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
-
*/
|
|
8
|
-
import { __decorate } from "tslib";
|
|
9
|
-
import '@material/web/divider/divider.js';
|
|
10
|
-
import { html, isServer, LitElement, nothing } from 'lit';
|
|
11
|
-
import { property, query, state } from 'lit/decorators.js';
|
|
12
|
-
import { classMap } from 'lit/directives/class-map.js';
|
|
13
|
-
import { requestUpdateOnAriaChange } from '@material/web/internal/aria/delegate.js';
|
|
14
|
-
import { redispatchEvent } from '@material/web/internal/events/redispatch-event.js';
|
|
15
|
-
import { DIALOG_DEFAULT_CLOSE_ANIMATION, DIALOG_DEFAULT_OPEN_ANIMATION, } from '@material/web/dialog/internal/animations.js';
|
|
16
|
-
/**
|
|
17
|
-
* A dialog component.
|
|
18
|
-
*
|
|
19
|
-
* @fires open {Event} Dispatched when the dialog is opening before any animations.
|
|
20
|
-
* @fires opened {Event} Dispatched when the dialog has opened after any animations.
|
|
21
|
-
* @fires close {Event} Dispatched when the dialog is closing before any animations.
|
|
22
|
-
* @fires closed {Event} Dispatched when the dialog has closed after any animations.
|
|
23
|
-
* @fires cancel {Event} Dispatched when the dialog has been canceled by clicking
|
|
24
|
-
* on the scrim or pressing Escape.
|
|
25
|
-
*/
|
|
26
|
-
export class Dialog extends LitElement {
|
|
27
|
-
/**
|
|
28
|
-
* Opens the dialog when set to `true` and closes it when set to `false`.
|
|
29
|
-
*/
|
|
30
|
-
get open() {
|
|
31
|
-
return this.isOpen;
|
|
32
|
-
}
|
|
33
|
-
set open(open) {
|
|
34
|
-
if (open === this.isOpen) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
this.isOpen = open;
|
|
38
|
-
if (open) {
|
|
39
|
-
this.setAttribute('open', '');
|
|
40
|
-
this.show();
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
this.removeAttribute('open');
|
|
44
|
-
this.close();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
constructor() {
|
|
48
|
-
super();
|
|
49
|
-
/**
|
|
50
|
-
* Gets or sets the dialog's return value, usually to indicate which button
|
|
51
|
-
* a user pressed to close it.
|
|
52
|
-
*
|
|
53
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/returnValue
|
|
54
|
-
*/
|
|
55
|
-
this.returnValue = '';
|
|
56
|
-
/**
|
|
57
|
-
* Gets the opening animation for a dialog. Set to a new function to customize
|
|
58
|
-
* the animation.
|
|
59
|
-
*/
|
|
60
|
-
this.getOpenAnimation = () => DIALOG_DEFAULT_OPEN_ANIMATION;
|
|
61
|
-
/**
|
|
62
|
-
* Gets the closing animation for a dialog. Set to a new function to customize
|
|
63
|
-
* the animation.
|
|
64
|
-
*/
|
|
65
|
-
this.getCloseAnimation = () => DIALOG_DEFAULT_CLOSE_ANIMATION;
|
|
66
|
-
this.isOpen = false;
|
|
67
|
-
this.isOpening = false;
|
|
68
|
-
this.isConnectedPromise = this.getIsConnectedPromise();
|
|
69
|
-
this.isAtScrollTop = false;
|
|
70
|
-
this.isAtScrollBottom = false;
|
|
71
|
-
this.nextClickIsFromContent = false;
|
|
72
|
-
// Dialogs should not be SSR'd while open, so we can just use runtime checks.
|
|
73
|
-
this.hasHeadline = false;
|
|
74
|
-
this.hasActions = false;
|
|
75
|
-
this.hasIcon = false;
|
|
76
|
-
// See https://bugs.chromium.org/p/chromium/issues/detail?id=1512224
|
|
77
|
-
// Chrome v120 has a bug where escape keys do not trigger cancels. If we get
|
|
78
|
-
// a dialog "close" event that is triggered without a "cancel" after an escape
|
|
79
|
-
// keydown, then we need to manually trigger our closing logic.
|
|
80
|
-
//
|
|
81
|
-
// This bug occurs when pressing escape to close a dialog without first
|
|
82
|
-
// interacting with the dialog's content.
|
|
83
|
-
//
|
|
84
|
-
// Cleanup tracking:
|
|
85
|
-
// https://github.com/material-components/material-web/issues/5330
|
|
86
|
-
// This can be removed when full CloseWatcher support added and the above bug
|
|
87
|
-
// in Chromium is fixed to fire 'cancel' with one escape press and close with
|
|
88
|
-
// multiple.
|
|
89
|
-
this.escapePressedWithoutCancel = false;
|
|
90
|
-
if (!isServer) {
|
|
91
|
-
this.addEventListener('submit', this.handleSubmit);
|
|
92
|
-
// We do not use `delegatesFocus: true` due to a Chromium bug with
|
|
93
|
-
// selecting text.
|
|
94
|
-
// See https://bugs.chromium.org/p/chromium/issues/detail?id=950357
|
|
95
|
-
//
|
|
96
|
-
// Material requires using focus trapping within the dialog (see
|
|
97
|
-
// b/314840853 for the bug to add it). This would normally mean we don't
|
|
98
|
-
// care about delegating focus since the `<dialog>` never receives it.
|
|
99
|
-
// However, we still need to handle situations when a user has not
|
|
100
|
-
// provided an focusable child in the content. When that happens, the
|
|
101
|
-
// `<dialog>` itself is focused.
|
|
102
|
-
//
|
|
103
|
-
// Listen to focus/blur instead of focusin/focusout since those can bubble
|
|
104
|
-
// from content.
|
|
105
|
-
this.addEventListener('focus', () => {
|
|
106
|
-
var _a;
|
|
107
|
-
(_a = this.dialog) === null || _a === void 0 ? void 0 : _a.focus();
|
|
108
|
-
});
|
|
109
|
-
this.addEventListener('blur', () => {
|
|
110
|
-
var _a;
|
|
111
|
-
(_a = this.dialog) === null || _a === void 0 ? void 0 : _a.blur();
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Opens the dialog and fires a cancelable `open` event. After a dialog's
|
|
117
|
-
* animation, an `opened` event is fired.
|
|
118
|
-
*
|
|
119
|
-
* Add an `autocomplete` attribute to a child of the dialog that should
|
|
120
|
-
* receive focus after opening.
|
|
121
|
-
*
|
|
122
|
-
* @return A Promise that resolves after the animation is finished and the
|
|
123
|
-
* `opened` event was fired.
|
|
124
|
-
*/
|
|
125
|
-
async show() {
|
|
126
|
-
var _a;
|
|
127
|
-
this.isOpening = true;
|
|
128
|
-
// Dialogs can be opened before being attached to the DOM, so we need to
|
|
129
|
-
// wait until we're connected before calling `showModal()`.
|
|
130
|
-
await this.isConnectedPromise;
|
|
131
|
-
await this.updateComplete;
|
|
132
|
-
const dialog = this.dialog;
|
|
133
|
-
// Check if already opened or if `dialog.close()` was called while awaiting.
|
|
134
|
-
if (dialog.open || !this.isOpening) {
|
|
135
|
-
this.isOpening = false;
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const preventOpen = !this.dispatchEvent(new Event('open', { cancelable: true }));
|
|
139
|
-
if (preventOpen) {
|
|
140
|
-
this.open = false;
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
// All Material dialogs are modal.
|
|
144
|
-
dialog.showModal();
|
|
145
|
-
this.open = true;
|
|
146
|
-
// Reset scroll position if re-opening a dialog with the same content.
|
|
147
|
-
if (this.scroller) {
|
|
148
|
-
this.scroller.scrollTop = 0;
|
|
149
|
-
}
|
|
150
|
-
// Native modal dialogs ignore autofocus and instead force focus to the
|
|
151
|
-
// first focusable child. Override this behavior if there is a child with
|
|
152
|
-
// an autofocus attribute.
|
|
153
|
-
(_a = this.querySelector('[autofocus]')) === null || _a === void 0 ? void 0 : _a.focus();
|
|
154
|
-
await this.animateDialog(this.getOpenAnimation());
|
|
155
|
-
this.dispatchEvent(new Event('opened'));
|
|
156
|
-
this.isOpening = false;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Closes the dialog and fires a cancelable `close` event. After a dialog's
|
|
160
|
-
* animation, a `closed` event is fired.
|
|
161
|
-
*
|
|
162
|
-
* @param returnValue A return value usually indicating which button was used
|
|
163
|
-
* to close a dialog. If a dialog is canceled by clicking the scrim or
|
|
164
|
-
* pressing Escape, it will not change the return value after closing.
|
|
165
|
-
* @return A Promise that resolves after the animation is finished and the
|
|
166
|
-
* `closed` event was fired.
|
|
167
|
-
*/
|
|
168
|
-
async close(returnValue = this.returnValue) {
|
|
169
|
-
this.isOpening = false;
|
|
170
|
-
if (!this.isConnected) {
|
|
171
|
-
// Disconnected dialogs do not fire close events or animate.
|
|
172
|
-
this.open = false;
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
await this.updateComplete;
|
|
176
|
-
const dialog = this.dialog;
|
|
177
|
-
// Check if already closed or if `dialog.show()` was called while awaiting.
|
|
178
|
-
if (!dialog.open || this.isOpening) {
|
|
179
|
-
this.open = false;
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
const prevReturnValue = this.returnValue;
|
|
183
|
-
this.returnValue = returnValue;
|
|
184
|
-
const preventClose = !this.dispatchEvent(new Event('close', { cancelable: true }));
|
|
185
|
-
if (preventClose) {
|
|
186
|
-
this.returnValue = prevReturnValue;
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
await this.animateDialog(this.getCloseAnimation());
|
|
190
|
-
dialog.close(returnValue);
|
|
191
|
-
this.open = false;
|
|
192
|
-
this.dispatchEvent(new Event('closed'));
|
|
193
|
-
}
|
|
194
|
-
connectedCallback() {
|
|
195
|
-
super.connectedCallback();
|
|
196
|
-
this.isConnectedPromiseResolve();
|
|
197
|
-
}
|
|
198
|
-
disconnectedCallback() {
|
|
199
|
-
super.disconnectedCallback();
|
|
200
|
-
this.isConnectedPromise = this.getIsConnectedPromise();
|
|
201
|
-
}
|
|
202
|
-
render() {
|
|
203
|
-
const scrollable = this.open && !(this.isAtScrollTop && this.isAtScrollBottom);
|
|
204
|
-
const classes = {
|
|
205
|
-
'has-headline': this.hasHeadline,
|
|
206
|
-
'has-actions': this.hasActions,
|
|
207
|
-
'has-icon': this.hasIcon,
|
|
208
|
-
scrollable
|
|
209
|
-
'show-top-divider': scrollable && !this.isAtScrollTop,
|
|
210
|
-
'show-bottom-divider': scrollable && !this.isAtScrollBottom,
|
|
211
|
-
};
|
|
212
|
-
const { ariaLabel } = this;
|
|
1
|
+
/* eslint-disable no-shadow */
|
|
2
|
+
/* eslint-disable class-methods-use-this */
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2023 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
import { __decorate } from "tslib";
|
|
9
|
+
import '@material/web/divider/divider.js';
|
|
10
|
+
import { html, isServer, LitElement, nothing } from 'lit';
|
|
11
|
+
import { property, query, state } from 'lit/decorators.js';
|
|
12
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
13
|
+
import { requestUpdateOnAriaChange } from '@material/web/internal/aria/delegate.js';
|
|
14
|
+
import { redispatchEvent } from '@material/web/internal/events/redispatch-event.js';
|
|
15
|
+
import { DIALOG_DEFAULT_CLOSE_ANIMATION, DIALOG_DEFAULT_OPEN_ANIMATION, } from '@material/web/dialog/internal/animations.js';
|
|
16
|
+
/**
|
|
17
|
+
* A dialog component.
|
|
18
|
+
*
|
|
19
|
+
* @fires open {Event} Dispatched when the dialog is opening before any animations.
|
|
20
|
+
* @fires opened {Event} Dispatched when the dialog has opened after any animations.
|
|
21
|
+
* @fires close {Event} Dispatched when the dialog is closing before any animations.
|
|
22
|
+
* @fires closed {Event} Dispatched when the dialog has closed after any animations.
|
|
23
|
+
* @fires cancel {Event} Dispatched when the dialog has been canceled by clicking
|
|
24
|
+
* on the scrim or pressing Escape.
|
|
25
|
+
*/
|
|
26
|
+
export class Dialog extends LitElement {
|
|
27
|
+
/**
|
|
28
|
+
* Opens the dialog when set to `true` and closes it when set to `false`.
|
|
29
|
+
*/
|
|
30
|
+
get open() {
|
|
31
|
+
return this.isOpen;
|
|
32
|
+
}
|
|
33
|
+
set open(open) {
|
|
34
|
+
if (open === this.isOpen) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.isOpen = open;
|
|
38
|
+
if (open) {
|
|
39
|
+
this.setAttribute('open', '');
|
|
40
|
+
this.show();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.removeAttribute('open');
|
|
44
|
+
this.close();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
constructor() {
|
|
48
|
+
super();
|
|
49
|
+
/**
|
|
50
|
+
* Gets or sets the dialog's return value, usually to indicate which button
|
|
51
|
+
* a user pressed to close it.
|
|
52
|
+
*
|
|
53
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/returnValue
|
|
54
|
+
*/
|
|
55
|
+
this.returnValue = '';
|
|
56
|
+
/**
|
|
57
|
+
* Gets the opening animation for a dialog. Set to a new function to customize
|
|
58
|
+
* the animation.
|
|
59
|
+
*/
|
|
60
|
+
this.getOpenAnimation = () => DIALOG_DEFAULT_OPEN_ANIMATION;
|
|
61
|
+
/**
|
|
62
|
+
* Gets the closing animation for a dialog. Set to a new function to customize
|
|
63
|
+
* the animation.
|
|
64
|
+
*/
|
|
65
|
+
this.getCloseAnimation = () => DIALOG_DEFAULT_CLOSE_ANIMATION;
|
|
66
|
+
this.isOpen = false;
|
|
67
|
+
this.isOpening = false;
|
|
68
|
+
this.isConnectedPromise = this.getIsConnectedPromise();
|
|
69
|
+
this.isAtScrollTop = false;
|
|
70
|
+
this.isAtScrollBottom = false;
|
|
71
|
+
this.nextClickIsFromContent = false;
|
|
72
|
+
// Dialogs should not be SSR'd while open, so we can just use runtime checks.
|
|
73
|
+
this.hasHeadline = false;
|
|
74
|
+
this.hasActions = false;
|
|
75
|
+
this.hasIcon = false;
|
|
76
|
+
// See https://bugs.chromium.org/p/chromium/issues/detail?id=1512224
|
|
77
|
+
// Chrome v120 has a bug where escape keys do not trigger cancels. If we get
|
|
78
|
+
// a dialog "close" event that is triggered without a "cancel" after an escape
|
|
79
|
+
// keydown, then we need to manually trigger our closing logic.
|
|
80
|
+
//
|
|
81
|
+
// This bug occurs when pressing escape to close a dialog without first
|
|
82
|
+
// interacting with the dialog's content.
|
|
83
|
+
//
|
|
84
|
+
// Cleanup tracking:
|
|
85
|
+
// https://github.com/material-components/material-web/issues/5330
|
|
86
|
+
// This can be removed when full CloseWatcher support added and the above bug
|
|
87
|
+
// in Chromium is fixed to fire 'cancel' with one escape press and close with
|
|
88
|
+
// multiple.
|
|
89
|
+
this.escapePressedWithoutCancel = false;
|
|
90
|
+
if (!isServer) {
|
|
91
|
+
this.addEventListener('submit', this.handleSubmit);
|
|
92
|
+
// We do not use `delegatesFocus: true` due to a Chromium bug with
|
|
93
|
+
// selecting text.
|
|
94
|
+
// See https://bugs.chromium.org/p/chromium/issues/detail?id=950357
|
|
95
|
+
//
|
|
96
|
+
// Material requires using focus trapping within the dialog (see
|
|
97
|
+
// b/314840853 for the bug to add it). This would normally mean we don't
|
|
98
|
+
// care about delegating focus since the `<dialog>` never receives it.
|
|
99
|
+
// However, we still need to handle situations when a user has not
|
|
100
|
+
// provided an focusable child in the content. When that happens, the
|
|
101
|
+
// `<dialog>` itself is focused.
|
|
102
|
+
//
|
|
103
|
+
// Listen to focus/blur instead of focusin/focusout since those can bubble
|
|
104
|
+
// from content.
|
|
105
|
+
this.addEventListener('focus', () => {
|
|
106
|
+
var _a;
|
|
107
|
+
(_a = this.dialog) === null || _a === void 0 ? void 0 : _a.focus();
|
|
108
|
+
});
|
|
109
|
+
this.addEventListener('blur', () => {
|
|
110
|
+
var _a;
|
|
111
|
+
(_a = this.dialog) === null || _a === void 0 ? void 0 : _a.blur();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Opens the dialog and fires a cancelable `open` event. After a dialog's
|
|
117
|
+
* animation, an `opened` event is fired.
|
|
118
|
+
*
|
|
119
|
+
* Add an `autocomplete` attribute to a child of the dialog that should
|
|
120
|
+
* receive focus after opening.
|
|
121
|
+
*
|
|
122
|
+
* @return A Promise that resolves after the animation is finished and the
|
|
123
|
+
* `opened` event was fired.
|
|
124
|
+
*/
|
|
125
|
+
async show() {
|
|
126
|
+
var _a;
|
|
127
|
+
this.isOpening = true;
|
|
128
|
+
// Dialogs can be opened before being attached to the DOM, so we need to
|
|
129
|
+
// wait until we're connected before calling `showModal()`.
|
|
130
|
+
await this.isConnectedPromise;
|
|
131
|
+
await this.updateComplete;
|
|
132
|
+
const dialog = this.dialog;
|
|
133
|
+
// Check if already opened or if `dialog.close()` was called while awaiting.
|
|
134
|
+
if (dialog.open || !this.isOpening) {
|
|
135
|
+
this.isOpening = false;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const preventOpen = !this.dispatchEvent(new Event('open', { cancelable: true }));
|
|
139
|
+
if (preventOpen) {
|
|
140
|
+
this.open = false;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
// All Material dialogs are modal.
|
|
144
|
+
dialog.showModal();
|
|
145
|
+
this.open = true;
|
|
146
|
+
// Reset scroll position if re-opening a dialog with the same content.
|
|
147
|
+
if (this.scroller) {
|
|
148
|
+
this.scroller.scrollTop = 0;
|
|
149
|
+
}
|
|
150
|
+
// Native modal dialogs ignore autofocus and instead force focus to the
|
|
151
|
+
// first focusable child. Override this behavior if there is a child with
|
|
152
|
+
// an autofocus attribute.
|
|
153
|
+
(_a = this.querySelector('[autofocus]')) === null || _a === void 0 ? void 0 : _a.focus();
|
|
154
|
+
await this.animateDialog(this.getOpenAnimation());
|
|
155
|
+
this.dispatchEvent(new Event('opened'));
|
|
156
|
+
this.isOpening = false;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Closes the dialog and fires a cancelable `close` event. After a dialog's
|
|
160
|
+
* animation, a `closed` event is fired.
|
|
161
|
+
*
|
|
162
|
+
* @param returnValue A return value usually indicating which button was used
|
|
163
|
+
* to close a dialog. If a dialog is canceled by clicking the scrim or
|
|
164
|
+
* pressing Escape, it will not change the return value after closing.
|
|
165
|
+
* @return A Promise that resolves after the animation is finished and the
|
|
166
|
+
* `closed` event was fired.
|
|
167
|
+
*/
|
|
168
|
+
async close(returnValue = this.returnValue) {
|
|
169
|
+
this.isOpening = false;
|
|
170
|
+
if (!this.isConnected) {
|
|
171
|
+
// Disconnected dialogs do not fire close events or animate.
|
|
172
|
+
this.open = false;
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
await this.updateComplete;
|
|
176
|
+
const dialog = this.dialog;
|
|
177
|
+
// Check if already closed or if `dialog.show()` was called while awaiting.
|
|
178
|
+
if (!dialog.open || this.isOpening) {
|
|
179
|
+
this.open = false;
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const prevReturnValue = this.returnValue;
|
|
183
|
+
this.returnValue = returnValue;
|
|
184
|
+
const preventClose = !this.dispatchEvent(new Event('close', { cancelable: true }));
|
|
185
|
+
if (preventClose) {
|
|
186
|
+
this.returnValue = prevReturnValue;
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
await this.animateDialog(this.getCloseAnimation());
|
|
190
|
+
dialog.close(returnValue);
|
|
191
|
+
this.open = false;
|
|
192
|
+
this.dispatchEvent(new Event('closed'));
|
|
193
|
+
}
|
|
194
|
+
connectedCallback() {
|
|
195
|
+
super.connectedCallback();
|
|
196
|
+
this.isConnectedPromiseResolve();
|
|
197
|
+
}
|
|
198
|
+
disconnectedCallback() {
|
|
199
|
+
super.disconnectedCallback();
|
|
200
|
+
this.isConnectedPromise = this.getIsConnectedPromise();
|
|
201
|
+
}
|
|
202
|
+
render() {
|
|
203
|
+
const scrollable = this.open && !(this.isAtScrollTop && this.isAtScrollBottom);
|
|
204
|
+
const classes = {
|
|
205
|
+
'has-headline': this.hasHeadline,
|
|
206
|
+
'has-actions': this.hasActions,
|
|
207
|
+
'has-icon': this.hasIcon,
|
|
208
|
+
scrollable,
|
|
209
|
+
'show-top-divider': scrollable && !this.isAtScrollTop,
|
|
210
|
+
'show-bottom-divider': scrollable && !this.isAtScrollBottom,
|
|
211
|
+
};
|
|
212
|
+
const { ariaLabel } = this;
|
|
213
213
|
return html `
|
|
214
214
|
<div class="scrim"></div>
|
|
215
215
|
<dialog
|
|
@@ -249,183 +249,183 @@ export class Dialog extends LitElement {
|
|
|
249
249
|
</div>
|
|
250
250
|
</div>
|
|
251
251
|
</dialog>
|
|
252
|
-
`;
|
|
253
|
-
}
|
|
254
|
-
firstUpdated() {
|
|
255
|
-
this.intersectionObserver = new IntersectionObserver(entries => {
|
|
256
|
-
for (const entry of entries) {
|
|
257
|
-
this.handleAnchorIntersection(entry);
|
|
258
|
-
}
|
|
259
|
-
}, { root: this.scroller });
|
|
260
|
-
this.intersectionObserver.observe(this.topAnchor);
|
|
261
|
-
this.intersectionObserver.observe(this.bottomAnchor);
|
|
262
|
-
}
|
|
263
|
-
handleDialogClick() {
|
|
264
|
-
if (this.nextClickIsFromContent) {
|
|
265
|
-
// Avoid doing a layout calculation below if we know the click came from
|
|
266
|
-
// content.
|
|
267
|
-
this.nextClickIsFromContent = false;
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
// Click originated on the backdrop. Native `<dialog>`s will not cancel,
|
|
271
|
-
// but Material dialogs do.
|
|
272
|
-
const preventDefault = !this.dispatchEvent(new Event('cancel', { cancelable: true }));
|
|
273
|
-
if (preventDefault) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
this.close();
|
|
277
|
-
}
|
|
278
|
-
handleContentClick() {
|
|
279
|
-
this.nextClickIsFromContent = true;
|
|
280
|
-
}
|
|
281
|
-
handleSubmit(event) {
|
|
282
|
-
var _a;
|
|
283
|
-
const form = event.target;
|
|
284
|
-
const { submitter } = event;
|
|
285
|
-
if (form.method !== 'dialog' || !submitter) {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
// Close reason is the submitter's value attribute, or the dialog's
|
|
289
|
-
// `returnValue` if there is no attribute.
|
|
290
|
-
this.close((_a = submitter.getAttribute('value')) !== null && _a !== void 0 ? _a : this.returnValue);
|
|
291
|
-
}
|
|
292
|
-
handleCancel(event) {
|
|
293
|
-
if (event.target !== this.dialog) {
|
|
294
|
-
// Ignore any cancel events dispatched by content.
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
this.escapePressedWithoutCancel = false;
|
|
298
|
-
const preventDefault = !redispatchEvent(this, event);
|
|
299
|
-
// We always prevent default on the original dialog event since we'll
|
|
300
|
-
// animate closing it before it actually closes.
|
|
301
|
-
event.preventDefault();
|
|
302
|
-
if (preventDefault) {
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
this.close();
|
|
306
|
-
}
|
|
307
|
-
handleClose() {
|
|
308
|
-
var _a;
|
|
309
|
-
if (!this.escapePressedWithoutCancel) {
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
this.escapePressedWithoutCancel = false;
|
|
313
|
-
(_a = this.dialog) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new Event('cancel', { cancelable: true }));
|
|
314
|
-
}
|
|
315
|
-
handleKeydown(event) {
|
|
316
|
-
if (event.key !== 'Escape') {
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
// An escape key was pressed. If a "close" event fires next without a
|
|
320
|
-
// "cancel" event first, then we know we're in the Chrome v120 bug.
|
|
321
|
-
this.escapePressedWithoutCancel = true;
|
|
322
|
-
// Wait a full task for the cancel/close event listeners to fire, then
|
|
323
|
-
// reset the flag.
|
|
324
|
-
setTimeout(() => {
|
|
325
|
-
this.escapePressedWithoutCancel = false;
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
async animateDialog(animation) {
|
|
329
|
-
const { dialog, scrim, container, headline, content, actions } = this;
|
|
330
|
-
if (!dialog || !scrim || !container || !headline || !content || !actions) {
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
const { container: containerAnimate, dialog: dialogAnimate, scrim: scrimAnimate, headline: headlineAnimate, content: contentAnimate, actions: actionsAnimate, } = animation;
|
|
334
|
-
const elementAndAnimation = [
|
|
335
|
-
[dialog, dialogAnimate !== null && dialogAnimate !== void 0 ? dialogAnimate : []],
|
|
336
|
-
[scrim, scrimAnimate !== null && scrimAnimate !== void 0 ? scrimAnimate : []],
|
|
337
|
-
[container, containerAnimate !== null && containerAnimate !== void 0 ? containerAnimate : []],
|
|
338
|
-
[headline, headlineAnimate !== null && headlineAnimate !== void 0 ? headlineAnimate : []],
|
|
339
|
-
[content, contentAnimate !== null && contentAnimate !== void 0 ? contentAnimate : []],
|
|
340
|
-
[actions, actionsAnimate !== null && actionsAnimate !== void 0 ? actionsAnimate : []],
|
|
341
|
-
];
|
|
342
|
-
const animations = [];
|
|
343
|
-
for (const [element, animation] of elementAndAnimation) {
|
|
344
|
-
for (const animateArgs of animation) {
|
|
345
|
-
animations.push(element.animate(...animateArgs));
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
await Promise.all(animations.map(animation => animation.finished));
|
|
349
|
-
}
|
|
350
|
-
handleHeadlineChange(event) {
|
|
351
|
-
const slot = event.target;
|
|
352
|
-
this.hasHeadline = slot.assignedElements().length > 0;
|
|
353
|
-
}
|
|
354
|
-
handleActionsChange(event) {
|
|
355
|
-
const slot = event.target;
|
|
356
|
-
this.hasActions = slot.assignedElements().length > 0;
|
|
357
|
-
}
|
|
358
|
-
handleIconChange(event) {
|
|
359
|
-
const slot = event.target;
|
|
360
|
-
this.hasIcon = slot.assignedElements().length > 0;
|
|
361
|
-
}
|
|
362
|
-
handleAnchorIntersection(entry) {
|
|
363
|
-
const { target, isIntersecting } = entry;
|
|
364
|
-
if (target === this.topAnchor) {
|
|
365
|
-
this.isAtScrollTop = isIntersecting;
|
|
366
|
-
}
|
|
367
|
-
if (target === this.bottomAnchor) {
|
|
368
|
-
this.isAtScrollBottom = isIntersecting;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
getIsConnectedPromise() {
|
|
372
|
-
return new Promise(resolve => {
|
|
373
|
-
this.isConnectedPromiseResolve = resolve;
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
(() => {
|
|
378
|
-
requestUpdateOnAriaChange(Dialog);
|
|
379
|
-
})();
|
|
380
|
-
__decorate([
|
|
381
|
-
property({ type: Boolean })
|
|
382
|
-
], Dialog.prototype, "open", null);
|
|
383
|
-
__decorate([
|
|
384
|
-
property({ attribute: false })
|
|
385
|
-
], Dialog.prototype, "returnValue", void 0);
|
|
386
|
-
__decorate([
|
|
387
|
-
property()
|
|
388
|
-
], Dialog.prototype, "type", void 0);
|
|
389
|
-
__decorate([
|
|
390
|
-
query('dialog')
|
|
391
|
-
], Dialog.prototype, "dialog", void 0);
|
|
392
|
-
__decorate([
|
|
393
|
-
query('.scrim')
|
|
394
|
-
], Dialog.prototype, "scrim", void 0);
|
|
395
|
-
__decorate([
|
|
396
|
-
query('.container')
|
|
397
|
-
], Dialog.prototype, "container", void 0);
|
|
398
|
-
__decorate([
|
|
399
|
-
query('.headline')
|
|
400
|
-
], Dialog.prototype, "headline", void 0);
|
|
401
|
-
__decorate([
|
|
402
|
-
query('.content')
|
|
403
|
-
], Dialog.prototype, "content", void 0);
|
|
404
|
-
__decorate([
|
|
405
|
-
query('.actions')
|
|
406
|
-
], Dialog.prototype, "actions", void 0);
|
|
407
|
-
__decorate([
|
|
408
|
-
state()
|
|
409
|
-
], Dialog.prototype, "isAtScrollTop", void 0);
|
|
410
|
-
__decorate([
|
|
411
|
-
state()
|
|
412
|
-
], Dialog.prototype, "isAtScrollBottom", void 0);
|
|
413
|
-
__decorate([
|
|
414
|
-
query('.scroller')
|
|
415
|
-
], Dialog.prototype, "scroller", void 0);
|
|
416
|
-
__decorate([
|
|
417
|
-
query('.top.anchor')
|
|
418
|
-
], Dialog.prototype, "topAnchor", void 0);
|
|
419
|
-
__decorate([
|
|
420
|
-
query('.bottom.anchor')
|
|
421
|
-
], Dialog.prototype, "bottomAnchor", void 0);
|
|
422
|
-
__decorate([
|
|
423
|
-
state()
|
|
424
|
-
], Dialog.prototype, "hasHeadline", void 0);
|
|
425
|
-
__decorate([
|
|
426
|
-
state()
|
|
427
|
-
], Dialog.prototype, "hasActions", void 0);
|
|
428
|
-
__decorate([
|
|
429
|
-
state()
|
|
430
|
-
], Dialog.prototype, "hasIcon", void 0);
|
|
252
|
+
`;
|
|
253
|
+
}
|
|
254
|
+
firstUpdated() {
|
|
255
|
+
this.intersectionObserver = new IntersectionObserver(entries => {
|
|
256
|
+
for (const entry of entries) {
|
|
257
|
+
this.handleAnchorIntersection(entry);
|
|
258
|
+
}
|
|
259
|
+
}, { root: this.scroller });
|
|
260
|
+
this.intersectionObserver.observe(this.topAnchor);
|
|
261
|
+
this.intersectionObserver.observe(this.bottomAnchor);
|
|
262
|
+
}
|
|
263
|
+
handleDialogClick() {
|
|
264
|
+
if (this.nextClickIsFromContent) {
|
|
265
|
+
// Avoid doing a layout calculation below if we know the click came from
|
|
266
|
+
// content.
|
|
267
|
+
this.nextClickIsFromContent = false;
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
// Click originated on the backdrop. Native `<dialog>`s will not cancel,
|
|
271
|
+
// but Material dialogs do.
|
|
272
|
+
const preventDefault = !this.dispatchEvent(new Event('cancel', { cancelable: true }));
|
|
273
|
+
if (preventDefault) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
this.close();
|
|
277
|
+
}
|
|
278
|
+
handleContentClick() {
|
|
279
|
+
this.nextClickIsFromContent = true;
|
|
280
|
+
}
|
|
281
|
+
handleSubmit(event) {
|
|
282
|
+
var _a;
|
|
283
|
+
const form = event.target;
|
|
284
|
+
const { submitter } = event;
|
|
285
|
+
if (form.method !== 'dialog' || !submitter) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
// Close reason is the submitter's value attribute, or the dialog's
|
|
289
|
+
// `returnValue` if there is no attribute.
|
|
290
|
+
this.close((_a = submitter.getAttribute('value')) !== null && _a !== void 0 ? _a : this.returnValue);
|
|
291
|
+
}
|
|
292
|
+
handleCancel(event) {
|
|
293
|
+
if (event.target !== this.dialog) {
|
|
294
|
+
// Ignore any cancel events dispatched by content.
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
this.escapePressedWithoutCancel = false;
|
|
298
|
+
const preventDefault = !redispatchEvent(this, event);
|
|
299
|
+
// We always prevent default on the original dialog event since we'll
|
|
300
|
+
// animate closing it before it actually closes.
|
|
301
|
+
event.preventDefault();
|
|
302
|
+
if (preventDefault) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
this.close();
|
|
306
|
+
}
|
|
307
|
+
handleClose() {
|
|
308
|
+
var _a;
|
|
309
|
+
if (!this.escapePressedWithoutCancel) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
this.escapePressedWithoutCancel = false;
|
|
313
|
+
(_a = this.dialog) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new Event('cancel', { cancelable: true }));
|
|
314
|
+
}
|
|
315
|
+
handleKeydown(event) {
|
|
316
|
+
if (event.key !== 'Escape') {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
// An escape key was pressed. If a "close" event fires next without a
|
|
320
|
+
// "cancel" event first, then we know we're in the Chrome v120 bug.
|
|
321
|
+
this.escapePressedWithoutCancel = true;
|
|
322
|
+
// Wait a full task for the cancel/close event listeners to fire, then
|
|
323
|
+
// reset the flag.
|
|
324
|
+
setTimeout(() => {
|
|
325
|
+
this.escapePressedWithoutCancel = false;
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
async animateDialog(animation) {
|
|
329
|
+
const { dialog, scrim, container, headline, content, actions } = this;
|
|
330
|
+
if (!dialog || !scrim || !container || !headline || !content || !actions) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const { container: containerAnimate, dialog: dialogAnimate, scrim: scrimAnimate, headline: headlineAnimate, content: contentAnimate, actions: actionsAnimate, } = animation;
|
|
334
|
+
const elementAndAnimation = [
|
|
335
|
+
[dialog, dialogAnimate !== null && dialogAnimate !== void 0 ? dialogAnimate : []],
|
|
336
|
+
[scrim, scrimAnimate !== null && scrimAnimate !== void 0 ? scrimAnimate : []],
|
|
337
|
+
[container, containerAnimate !== null && containerAnimate !== void 0 ? containerAnimate : []],
|
|
338
|
+
[headline, headlineAnimate !== null && headlineAnimate !== void 0 ? headlineAnimate : []],
|
|
339
|
+
[content, contentAnimate !== null && contentAnimate !== void 0 ? contentAnimate : []],
|
|
340
|
+
[actions, actionsAnimate !== null && actionsAnimate !== void 0 ? actionsAnimate : []],
|
|
341
|
+
];
|
|
342
|
+
const animations = [];
|
|
343
|
+
for (const [element, animation] of elementAndAnimation) {
|
|
344
|
+
for (const animateArgs of animation) {
|
|
345
|
+
animations.push(element.animate(...animateArgs));
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
await Promise.all(animations.map(animation => animation.finished));
|
|
349
|
+
}
|
|
350
|
+
handleHeadlineChange(event) {
|
|
351
|
+
const slot = event.target;
|
|
352
|
+
this.hasHeadline = slot.assignedElements().length > 0;
|
|
353
|
+
}
|
|
354
|
+
handleActionsChange(event) {
|
|
355
|
+
const slot = event.target;
|
|
356
|
+
this.hasActions = slot.assignedElements().length > 0;
|
|
357
|
+
}
|
|
358
|
+
handleIconChange(event) {
|
|
359
|
+
const slot = event.target;
|
|
360
|
+
this.hasIcon = slot.assignedElements().length > 0;
|
|
361
|
+
}
|
|
362
|
+
handleAnchorIntersection(entry) {
|
|
363
|
+
const { target, isIntersecting } = entry;
|
|
364
|
+
if (target === this.topAnchor) {
|
|
365
|
+
this.isAtScrollTop = isIntersecting;
|
|
366
|
+
}
|
|
367
|
+
if (target === this.bottomAnchor) {
|
|
368
|
+
this.isAtScrollBottom = isIntersecting;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
getIsConnectedPromise() {
|
|
372
|
+
return new Promise(resolve => {
|
|
373
|
+
this.isConnectedPromiseResolve = resolve;
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
(() => {
|
|
378
|
+
requestUpdateOnAriaChange(Dialog);
|
|
379
|
+
})();
|
|
380
|
+
__decorate([
|
|
381
|
+
property({ type: Boolean })
|
|
382
|
+
], Dialog.prototype, "open", null);
|
|
383
|
+
__decorate([
|
|
384
|
+
property({ attribute: false })
|
|
385
|
+
], Dialog.prototype, "returnValue", void 0);
|
|
386
|
+
__decorate([
|
|
387
|
+
property()
|
|
388
|
+
], Dialog.prototype, "type", void 0);
|
|
389
|
+
__decorate([
|
|
390
|
+
query('dialog')
|
|
391
|
+
], Dialog.prototype, "dialog", void 0);
|
|
392
|
+
__decorate([
|
|
393
|
+
query('.scrim')
|
|
394
|
+
], Dialog.prototype, "scrim", void 0);
|
|
395
|
+
__decorate([
|
|
396
|
+
query('.container')
|
|
397
|
+
], Dialog.prototype, "container", void 0);
|
|
398
|
+
__decorate([
|
|
399
|
+
query('.headline')
|
|
400
|
+
], Dialog.prototype, "headline", void 0);
|
|
401
|
+
__decorate([
|
|
402
|
+
query('.content')
|
|
403
|
+
], Dialog.prototype, "content", void 0);
|
|
404
|
+
__decorate([
|
|
405
|
+
query('.actions')
|
|
406
|
+
], Dialog.prototype, "actions", void 0);
|
|
407
|
+
__decorate([
|
|
408
|
+
state()
|
|
409
|
+
], Dialog.prototype, "isAtScrollTop", void 0);
|
|
410
|
+
__decorate([
|
|
411
|
+
state()
|
|
412
|
+
], Dialog.prototype, "isAtScrollBottom", void 0);
|
|
413
|
+
__decorate([
|
|
414
|
+
query('.scroller')
|
|
415
|
+
], Dialog.prototype, "scroller", void 0);
|
|
416
|
+
__decorate([
|
|
417
|
+
query('.top.anchor')
|
|
418
|
+
], Dialog.prototype, "topAnchor", void 0);
|
|
419
|
+
__decorate([
|
|
420
|
+
query('.bottom.anchor')
|
|
421
|
+
], Dialog.prototype, "bottomAnchor", void 0);
|
|
422
|
+
__decorate([
|
|
423
|
+
state()
|
|
424
|
+
], Dialog.prototype, "hasHeadline", void 0);
|
|
425
|
+
__decorate([
|
|
426
|
+
state()
|
|
427
|
+
], Dialog.prototype, "hasActions", void 0);
|
|
428
|
+
__decorate([
|
|
429
|
+
state()
|
|
430
|
+
], Dialog.prototype, "hasIcon", void 0);
|
|
431
431
|
//# sourceMappingURL=dialog.js.map
|