@primer/view-components 0.15.1 → 0.16.0-rc.354ad89c
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/app/assets/javascripts/app/components/primer/alpha/action_bar_element.d.ts +3 -2
- package/app/assets/javascripts/app/components/primer/dialog_helper.d.ts +15 -0
- package/app/assets/javascripts/app/components/primer/primer.d.ts +1 -1
- package/app/assets/javascripts/primer_view_components.js +1 -1
- package/app/assets/javascripts/primer_view_components.js.map +1 -1
- package/app/assets/styles/primer_view_components.css +1 -1
- package/app/assets/styles/primer_view_components.css.map +1 -1
- package/app/components/primer/alpha/action_bar.css +1 -1
- package/app/components/primer/alpha/action_bar_element.d.ts +3 -2
- package/app/components/primer/alpha/action_bar_element.js +76 -99
- package/app/components/primer/alpha/action_menu/action_menu_element.js +8 -0
- package/app/components/primer/alpha/dialog.css +1 -1
- package/app/components/primer/alpha/dialog.css.json +2 -0
- package/app/components/primer/alpha/overlay.css +1 -1
- package/app/components/primer/alpha/overlay.css.json +3 -1
- package/app/components/primer/dialog_helper.d.ts +15 -0
- package/app/components/primer/dialog_helper.js +77 -0
- package/app/components/primer/primer.d.ts +1 -1
- package/app/components/primer/primer.js +1 -1
- package/package.json +2 -2
- package/app/assets/javascripts/app/components/primer/alpha/modal_dialog.d.ts +0 -18
- package/app/components/primer/alpha/modal_dialog.d.ts +0 -18
- package/app/components/primer/alpha/modal_dialog.js +0 -186
@@ -1,186 +0,0 @@
|
|
1
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
5
|
-
};
|
6
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
7
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
10
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
11
|
-
};
|
12
|
-
var _ModalDialogElement_instances, _ModalDialogElement_focusAbortController, _ModalDialogElement_overlayBackdrop_get, _ModalDialogElement_keydown;
|
13
|
-
import { focusTrap } from '@primer/behaviors';
|
14
|
-
import { getFocusableChild } from '@primer/behaviors/utils';
|
15
|
-
function focusIfNeeded(elem) {
|
16
|
-
if (document.activeElement !== elem) {
|
17
|
-
elem === null || elem === void 0 ? void 0 : elem.focus();
|
18
|
-
}
|
19
|
-
}
|
20
|
-
const overlayStack = [];
|
21
|
-
function clickHandler(event) {
|
22
|
-
const target = event.target;
|
23
|
-
const button = target === null || target === void 0 ? void 0 : target.closest('button');
|
24
|
-
if (!button || button.hasAttribute('disabled') || button.getAttribute('aria-disabled') === 'true')
|
25
|
-
return;
|
26
|
-
// If the user is clicking a valid dialog trigger
|
27
|
-
let dialogId = button === null || button === void 0 ? void 0 : button.getAttribute('data-show-dialog-id');
|
28
|
-
if (dialogId) {
|
29
|
-
event.stopPropagation();
|
30
|
-
const dialog = document.getElementById(dialogId);
|
31
|
-
if (dialog instanceof ModalDialogElement) {
|
32
|
-
dialog.openButton = button;
|
33
|
-
dialog.show();
|
34
|
-
// A buttons default behaviour in some browsers it to send a pointer event
|
35
|
-
// If the behaviour is allowed through the dialog will be shown but then
|
36
|
-
// quickly hidden- as if it were never shown. This prevents that.
|
37
|
-
event.preventDefault();
|
38
|
-
return;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
if (!overlayStack.length)
|
42
|
-
return;
|
43
|
-
dialogId = button.getAttribute('data-close-dialog-id') || button.getAttribute('data-submit-dialog-id');
|
44
|
-
if (dialogId) {
|
45
|
-
const dialog = document.getElementById(dialogId);
|
46
|
-
if (dialog instanceof ModalDialogElement) {
|
47
|
-
const dialogIndex = overlayStack.findIndex(ele => ele.id === dialogId);
|
48
|
-
overlayStack.splice(dialogIndex, 1);
|
49
|
-
dialog.close(button.hasAttribute('data-submit-dialog-id'));
|
50
|
-
}
|
51
|
-
}
|
52
|
-
}
|
53
|
-
function keydownHandler(event) {
|
54
|
-
if (!(event instanceof KeyboardEvent) ||
|
55
|
-
event.type !== 'keydown' ||
|
56
|
-
event.key !== 'Enter' ||
|
57
|
-
event.ctrlKey ||
|
58
|
-
event.altKey ||
|
59
|
-
event.metaKey ||
|
60
|
-
event.shiftKey)
|
61
|
-
return;
|
62
|
-
clickHandler(event);
|
63
|
-
}
|
64
|
-
function mousedownHandler(event) {
|
65
|
-
const target = event.target;
|
66
|
-
if (target === null || target === void 0 ? void 0 : target.closest('button'))
|
67
|
-
return;
|
68
|
-
// Find the top level dialog that is open.
|
69
|
-
const topLevelDialog = overlayStack[overlayStack.length - 1];
|
70
|
-
if (!topLevelDialog)
|
71
|
-
return;
|
72
|
-
// Check if the mousedown happened outside the boundary of the top level dialog
|
73
|
-
const mouseDownOutsideDialog = !target.closest(`#${topLevelDialog.getAttribute('id')}`);
|
74
|
-
// Only close dialog if it's a click outside the dialog and the dialog has a button?
|
75
|
-
if (mouseDownOutsideDialog) {
|
76
|
-
target.ownerDocument.addEventListener('mouseup', (upEvent) => {
|
77
|
-
if (upEvent.target === target) {
|
78
|
-
overlayStack.pop();
|
79
|
-
topLevelDialog.close();
|
80
|
-
}
|
81
|
-
}, { once: true });
|
82
|
-
}
|
83
|
-
}
|
84
|
-
export class ModalDialogElement extends HTMLElement {
|
85
|
-
constructor() {
|
86
|
-
super(...arguments);
|
87
|
-
_ModalDialogElement_instances.add(this);
|
88
|
-
//TODO: Do we remove the abortController from focusTrap?
|
89
|
-
_ModalDialogElement_focusAbortController.set(this, new AbortController());
|
90
|
-
}
|
91
|
-
get open() {
|
92
|
-
return this.hasAttribute('open');
|
93
|
-
}
|
94
|
-
set open(value) {
|
95
|
-
var _a, _b, _c, _d;
|
96
|
-
if (value) {
|
97
|
-
if (this.open)
|
98
|
-
return;
|
99
|
-
this.setAttribute('open', '');
|
100
|
-
this.setAttribute('aria-disabled', 'false');
|
101
|
-
document.body.style.paddingRight = `${window.innerWidth - document.body.clientWidth}px`;
|
102
|
-
document.body.style.overflow = 'hidden';
|
103
|
-
(_a = __classPrivateFieldGet(this, _ModalDialogElement_instances, "a", _ModalDialogElement_overlayBackdrop_get)) === null || _a === void 0 ? void 0 : _a.classList.remove('Overlay--hidden');
|
104
|
-
if (__classPrivateFieldGet(this, _ModalDialogElement_focusAbortController, "f").signal.aborted) {
|
105
|
-
__classPrivateFieldSet(this, _ModalDialogElement_focusAbortController, new AbortController(), "f");
|
106
|
-
}
|
107
|
-
focusTrap(this, this.querySelector('[autofocus]'), __classPrivateFieldGet(this, _ModalDialogElement_focusAbortController, "f").signal);
|
108
|
-
overlayStack.push(this);
|
109
|
-
}
|
110
|
-
else {
|
111
|
-
if (!this.open)
|
112
|
-
return;
|
113
|
-
this.removeAttribute('open');
|
114
|
-
this.setAttribute('aria-disabled', 'true');
|
115
|
-
(_b = __classPrivateFieldGet(this, _ModalDialogElement_instances, "a", _ModalDialogElement_overlayBackdrop_get)) === null || _b === void 0 ? void 0 : _b.classList.add('Overlay--hidden');
|
116
|
-
document.body.style.paddingRight = '0';
|
117
|
-
document.body.style.overflow = 'initial';
|
118
|
-
__classPrivateFieldGet(this, _ModalDialogElement_focusAbortController, "f").abort();
|
119
|
-
// if #openButton is a child of a menu, we need to focus a suitable child of the menu
|
120
|
-
// element since it is expected for the menu to close on click
|
121
|
-
const menu = ((_c = this.openButton) === null || _c === void 0 ? void 0 : _c.closest('details')) || ((_d = this.openButton) === null || _d === void 0 ? void 0 : _d.closest('action-menu'));
|
122
|
-
if (menu) {
|
123
|
-
focusIfNeeded(getFocusableChild(menu));
|
124
|
-
}
|
125
|
-
else {
|
126
|
-
focusIfNeeded(this.openButton);
|
127
|
-
}
|
128
|
-
this.openButton = null;
|
129
|
-
}
|
130
|
-
}
|
131
|
-
get showButtons() {
|
132
|
-
// Dialogs may also be opened from any arbitrary button with a matching show-dialog-id data attribute
|
133
|
-
return document.querySelectorAll(`button[data-show-dialog-id='${this.id}']`);
|
134
|
-
}
|
135
|
-
connectedCallback() {
|
136
|
-
if (!this.hasAttribute('role'))
|
137
|
-
this.setAttribute('role', 'dialog');
|
138
|
-
document.addEventListener('click', clickHandler);
|
139
|
-
document.addEventListener('keydown', keydownHandler);
|
140
|
-
document.addEventListener('mousedown', mousedownHandler);
|
141
|
-
this.addEventListener('keydown', e => __classPrivateFieldGet(this, _ModalDialogElement_instances, "m", _ModalDialogElement_keydown).call(this, e));
|
142
|
-
}
|
143
|
-
show() {
|
144
|
-
this.open = true;
|
145
|
-
}
|
146
|
-
close(closedNotCancelled = false) {
|
147
|
-
if (this.open === false)
|
148
|
-
return;
|
149
|
-
const eventType = closedNotCancelled ? 'close' : 'cancel';
|
150
|
-
const dialogEvent = new Event(eventType);
|
151
|
-
this.dispatchEvent(dialogEvent);
|
152
|
-
this.open = false;
|
153
|
-
}
|
154
|
-
}
|
155
|
-
_ModalDialogElement_focusAbortController = new WeakMap(), _ModalDialogElement_instances = new WeakSet(), _ModalDialogElement_overlayBackdrop_get = function _ModalDialogElement_overlayBackdrop_get() {
|
156
|
-
var _a;
|
157
|
-
if ((_a = this.parentElement) === null || _a === void 0 ? void 0 : _a.hasAttribute('data-modal-dialog-overlay')) {
|
158
|
-
return this.parentElement;
|
159
|
-
}
|
160
|
-
return null;
|
161
|
-
}, _ModalDialogElement_keydown = function _ModalDialogElement_keydown(event) {
|
162
|
-
if (!(event instanceof KeyboardEvent))
|
163
|
-
return;
|
164
|
-
if (event.isComposing)
|
165
|
-
return;
|
166
|
-
if (!this.open)
|
167
|
-
return;
|
168
|
-
switch (event.key) {
|
169
|
-
case 'Escape':
|
170
|
-
this.close();
|
171
|
-
event.preventDefault();
|
172
|
-
event.stopPropagation();
|
173
|
-
break;
|
174
|
-
case 'Enter': {
|
175
|
-
const target = event.target;
|
176
|
-
if (target.getAttribute('data-close-dialog-id') === this.id) {
|
177
|
-
event.stopPropagation();
|
178
|
-
}
|
179
|
-
break;
|
180
|
-
}
|
181
|
-
}
|
182
|
-
};
|
183
|
-
if (!window.customElements.get('modal-dialog')) {
|
184
|
-
window.ModalDialogElement = ModalDialogElement;
|
185
|
-
window.customElements.define('modal-dialog', ModalDialogElement);
|
186
|
-
}
|