@primer/behaviors 0.0.0-20221313210 → 0.0.0-20221313611
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primer/behaviors",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-20221313611",
|
|
4
4
|
"description": "Shared behaviors for JavaScript components",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -14,26 +14,18 @@
|
|
|
14
14
|
"types": "./dist/utils/index.d.ts",
|
|
15
15
|
"require": "./dist/cjs/utils/index.js",
|
|
16
16
|
"module": "./dist/esm/utils/index.js"
|
|
17
|
-
},
|
|
18
|
-
"./components/modal-dialog": {
|
|
19
|
-
"types": "./dist/components/modal-dialog.d.ts",
|
|
20
|
-
"require": "./dist/cjs/components/modal-dialog.js",
|
|
21
|
-
"module": "./dist/esm/components/modal-dialog.js"
|
|
22
17
|
}
|
|
23
18
|
},
|
|
24
19
|
"types": "dist/cjs/index.d.ts",
|
|
25
20
|
"files": [
|
|
26
21
|
"dist",
|
|
27
|
-
"utils"
|
|
28
|
-
"modal-dialog"
|
|
22
|
+
"utils"
|
|
29
23
|
],
|
|
30
24
|
"sideEffects": [
|
|
31
25
|
"dist/esm/focus-zone.js",
|
|
32
26
|
"dist/esm/focus-trap.js",
|
|
33
27
|
"dist/cjs/focus-zone.js",
|
|
34
|
-
"dist/cjs/focus-trap.js"
|
|
35
|
-
"dist/esm/components/modal-dialog.js",
|
|
36
|
-
"dist/cjs/components/modal-dialog.js"
|
|
28
|
+
"dist/cjs/focus-trap.js"
|
|
37
29
|
],
|
|
38
30
|
"scripts": {
|
|
39
31
|
"lint": "eslint src/",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
declare class ModalDialogElement extends HTMLElement {
|
|
2
|
-
private abortController;
|
|
3
|
-
constructor();
|
|
4
|
-
connectedCallback(): void;
|
|
5
|
-
disconnectedCallback(): void;
|
|
6
|
-
show(): void;
|
|
7
|
-
close(): void;
|
|
8
|
-
}
|
|
9
|
-
declare global {
|
|
10
|
-
interface Window {
|
|
11
|
-
ModalDialogElement: typeof ModalDialogElement;
|
|
12
|
-
}
|
|
13
|
-
interface HTMLElementTagNameMap {
|
|
14
|
-
'modal-dialog': ModalDialogElement;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export default ModalDialogElement;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const focus_trap_js_1 = require("../focus-trap.js");
|
|
4
|
-
class ModalDialogElement extends HTMLElement {
|
|
5
|
-
constructor() {
|
|
6
|
-
var _a, _b;
|
|
7
|
-
super();
|
|
8
|
-
(_a = this.querySelector('.close-button')) === null || _a === void 0 ? void 0 : _a.addEventListener('click', () => this.close());
|
|
9
|
-
(_b = document.body.querySelector(`.js-dialog-show-${this.id}`)) === null || _b === void 0 ? void 0 : _b.addEventListener('click', event => {
|
|
10
|
-
event.stopPropagation();
|
|
11
|
-
this.show();
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
connectedCallback() {
|
|
15
|
-
if (!this.hasAttribute('role'))
|
|
16
|
-
this.setAttribute('role', 'dialog');
|
|
17
|
-
const subscriptions = [
|
|
18
|
-
fromEvent(this, 'compositionstart', e => trackComposition(this, e)),
|
|
19
|
-
fromEvent(this, 'compositionend', e => trackComposition(this, e)),
|
|
20
|
-
fromEvent(this, 'keydown', e => keydown(this, e)),
|
|
21
|
-
fromEvent(window, 'click', e => clickToDismiss(this, e))
|
|
22
|
-
];
|
|
23
|
-
states.set(this, { subscriptions, loaded: false, isComposing: false });
|
|
24
|
-
}
|
|
25
|
-
disconnectedCallback() {
|
|
26
|
-
const state = states.get(this);
|
|
27
|
-
if (!state)
|
|
28
|
-
return;
|
|
29
|
-
states.delete(this);
|
|
30
|
-
for (const sub of state.subscriptions) {
|
|
31
|
-
sub.unsubscribe();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
show() {
|
|
35
|
-
var _a;
|
|
36
|
-
const isClosed = this.classList.contains('hidden');
|
|
37
|
-
if (!isClosed)
|
|
38
|
-
return;
|
|
39
|
-
this.classList.remove('hidden');
|
|
40
|
-
this.setAttribute('open', '');
|
|
41
|
-
if ((_a = this.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains('modal-dialog-backdrop')) {
|
|
42
|
-
this.parentElement.classList.add('active');
|
|
43
|
-
}
|
|
44
|
-
document.body.style.overflow = 'hidden';
|
|
45
|
-
this.abortController = (0, focus_trap_js_1.focusTrap)(this);
|
|
46
|
-
}
|
|
47
|
-
close() {
|
|
48
|
-
var _a, _b;
|
|
49
|
-
const isClosed = this.classList.contains('hidden');
|
|
50
|
-
if (isClosed)
|
|
51
|
-
return;
|
|
52
|
-
this.classList.add('hidden');
|
|
53
|
-
this.removeAttribute('open');
|
|
54
|
-
if ((_a = this.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains('modal-dialog-backdrop')) {
|
|
55
|
-
this.parentElement.classList.remove('active');
|
|
56
|
-
}
|
|
57
|
-
document.body.style.overflow = 'initial';
|
|
58
|
-
(_b = this.abortController) === null || _b === void 0 ? void 0 : _b.abort();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const states = new WeakMap();
|
|
62
|
-
function fromEvent(target, eventName, onNext, options = false) {
|
|
63
|
-
target.addEventListener(eventName, onNext, options);
|
|
64
|
-
return {
|
|
65
|
-
unsubscribe: () => {
|
|
66
|
-
target.removeEventListener(eventName, onNext, options);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function keydown(dialog, event) {
|
|
71
|
-
if (!(event instanceof KeyboardEvent))
|
|
72
|
-
return;
|
|
73
|
-
const state = states.get(dialog);
|
|
74
|
-
if (!state || state.isComposing)
|
|
75
|
-
return;
|
|
76
|
-
switch (event.key) {
|
|
77
|
-
case 'Escape':
|
|
78
|
-
if (dialog.hasAttribute('open')) {
|
|
79
|
-
dialog.close();
|
|
80
|
-
event.preventDefault();
|
|
81
|
-
event.stopPropagation();
|
|
82
|
-
}
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function trackComposition(dialog, event) {
|
|
87
|
-
const state = states.get(dialog);
|
|
88
|
-
if (!state)
|
|
89
|
-
return;
|
|
90
|
-
state.isComposing = event.type === 'compositionstart';
|
|
91
|
-
}
|
|
92
|
-
function clickToDismiss(dialog, event) {
|
|
93
|
-
const target = event.target;
|
|
94
|
-
if (dialog.hasAttribute('open') && target && !target.matches(`#${dialog.id}, #${dialog.id} *`)) {
|
|
95
|
-
dialog.close();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.default = ModalDialogElement;
|
|
99
|
-
if (!window.customElements.get('modal-dialog')) {
|
|
100
|
-
window.ModalDialogElement = ModalDialogElement;
|
|
101
|
-
window.customElements.define('modal-dialog', ModalDialogElement);
|
|
102
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
declare class ModalDialogElement extends HTMLElement {
|
|
2
|
-
private abortController;
|
|
3
|
-
constructor();
|
|
4
|
-
connectedCallback(): void;
|
|
5
|
-
disconnectedCallback(): void;
|
|
6
|
-
show(): void;
|
|
7
|
-
close(): void;
|
|
8
|
-
}
|
|
9
|
-
declare global {
|
|
10
|
-
interface Window {
|
|
11
|
-
ModalDialogElement: typeof ModalDialogElement;
|
|
12
|
-
}
|
|
13
|
-
interface HTMLElementTagNameMap {
|
|
14
|
-
'modal-dialog': ModalDialogElement;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export default ModalDialogElement;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { focusTrap } from '../focus-trap.js';
|
|
2
|
-
class ModalDialogElement extends HTMLElement {
|
|
3
|
-
constructor() {
|
|
4
|
-
var _a, _b;
|
|
5
|
-
super();
|
|
6
|
-
(_a = this.querySelector('.close-button')) === null || _a === void 0 ? void 0 : _a.addEventListener('click', () => this.close());
|
|
7
|
-
(_b = document.body.querySelector(`.js-dialog-show-${this.id}`)) === null || _b === void 0 ? void 0 : _b.addEventListener('click', event => {
|
|
8
|
-
event.stopPropagation();
|
|
9
|
-
this.show();
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
connectedCallback() {
|
|
13
|
-
if (!this.hasAttribute('role'))
|
|
14
|
-
this.setAttribute('role', 'dialog');
|
|
15
|
-
const subscriptions = [
|
|
16
|
-
fromEvent(this, 'compositionstart', e => trackComposition(this, e)),
|
|
17
|
-
fromEvent(this, 'compositionend', e => trackComposition(this, e)),
|
|
18
|
-
fromEvent(this, 'keydown', e => keydown(this, e)),
|
|
19
|
-
fromEvent(window, 'click', e => clickToDismiss(this, e))
|
|
20
|
-
];
|
|
21
|
-
states.set(this, { subscriptions, loaded: false, isComposing: false });
|
|
22
|
-
}
|
|
23
|
-
disconnectedCallback() {
|
|
24
|
-
const state = states.get(this);
|
|
25
|
-
if (!state)
|
|
26
|
-
return;
|
|
27
|
-
states.delete(this);
|
|
28
|
-
for (const sub of state.subscriptions) {
|
|
29
|
-
sub.unsubscribe();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
show() {
|
|
33
|
-
var _a;
|
|
34
|
-
const isClosed = this.classList.contains('hidden');
|
|
35
|
-
if (!isClosed)
|
|
36
|
-
return;
|
|
37
|
-
this.classList.remove('hidden');
|
|
38
|
-
this.setAttribute('open', '');
|
|
39
|
-
if ((_a = this.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains('modal-dialog-backdrop')) {
|
|
40
|
-
this.parentElement.classList.add('active');
|
|
41
|
-
}
|
|
42
|
-
document.body.style.overflow = 'hidden';
|
|
43
|
-
this.abortController = focusTrap(this);
|
|
44
|
-
}
|
|
45
|
-
close() {
|
|
46
|
-
var _a, _b;
|
|
47
|
-
const isClosed = this.classList.contains('hidden');
|
|
48
|
-
if (isClosed)
|
|
49
|
-
return;
|
|
50
|
-
this.classList.add('hidden');
|
|
51
|
-
this.removeAttribute('open');
|
|
52
|
-
if ((_a = this.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains('modal-dialog-backdrop')) {
|
|
53
|
-
this.parentElement.classList.remove('active');
|
|
54
|
-
}
|
|
55
|
-
document.body.style.overflow = 'initial';
|
|
56
|
-
(_b = this.abortController) === null || _b === void 0 ? void 0 : _b.abort();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const states = new WeakMap();
|
|
60
|
-
function fromEvent(target, eventName, onNext, options = false) {
|
|
61
|
-
target.addEventListener(eventName, onNext, options);
|
|
62
|
-
return {
|
|
63
|
-
unsubscribe: () => {
|
|
64
|
-
target.removeEventListener(eventName, onNext, options);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
function keydown(dialog, event) {
|
|
69
|
-
if (!(event instanceof KeyboardEvent))
|
|
70
|
-
return;
|
|
71
|
-
const state = states.get(dialog);
|
|
72
|
-
if (!state || state.isComposing)
|
|
73
|
-
return;
|
|
74
|
-
switch (event.key) {
|
|
75
|
-
case 'Escape':
|
|
76
|
-
if (dialog.hasAttribute('open')) {
|
|
77
|
-
dialog.close();
|
|
78
|
-
event.preventDefault();
|
|
79
|
-
event.stopPropagation();
|
|
80
|
-
}
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function trackComposition(dialog, event) {
|
|
85
|
-
const state = states.get(dialog);
|
|
86
|
-
if (!state)
|
|
87
|
-
return;
|
|
88
|
-
state.isComposing = event.type === 'compositionstart';
|
|
89
|
-
}
|
|
90
|
-
function clickToDismiss(dialog, event) {
|
|
91
|
-
const target = event.target;
|
|
92
|
-
if (dialog.hasAttribute('open') && target && !target.matches(`#${dialog.id}, #${dialog.id} *`)) {
|
|
93
|
-
dialog.close();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
export default ModalDialogElement;
|
|
97
|
-
if (!window.customElements.get('modal-dialog')) {
|
|
98
|
-
window.ModalDialogElement = ModalDialogElement;
|
|
99
|
-
window.customElements.define('modal-dialog', ModalDialogElement);
|
|
100
|
-
}
|