@y14e/portal 1.3.6 → 1.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.bundle.cjs +60 -67
- package/dist/index.bundle.js +60 -67
- package/dist/index.cjs +13 -13
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -13
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,11 +13,11 @@ npm i @y14e/portal
|
|
|
13
13
|
import { createPortal } from '@y14e/portal';
|
|
14
14
|
|
|
15
15
|
// CDNs
|
|
16
|
-
import { createPortal } from 'https://esm.sh/@y14e/portal@1.3.
|
|
16
|
+
import { createPortal } from 'https://esm.sh/@y14e/portal@1.3.7';
|
|
17
17
|
// or
|
|
18
|
-
import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.3.
|
|
18
|
+
import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.3.7/+esm';
|
|
19
19
|
// or
|
|
20
|
-
import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.3.
|
|
20
|
+
import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.3.7';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 📦 APIs
|
package/dist/index.bundle.cjs
CHANGED
|
@@ -3,27 +3,27 @@
|
|
|
3
3
|
// node_modules/@y14e/attribute-utils/dist/index.js
|
|
4
4
|
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
5
5
|
function restoreAttributes(element_or_elements) {
|
|
6
|
-
for (const
|
|
7
|
-
const snapshot = snapshots.get(
|
|
6
|
+
for (const e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
|
|
7
|
+
const snapshot = snapshots.get(e);
|
|
8
8
|
if (!snapshot) {
|
|
9
9
|
continue;
|
|
10
10
|
}
|
|
11
|
-
for (const [
|
|
12
|
-
|
|
11
|
+
for (const [n, v] of snapshot.entries()) {
|
|
12
|
+
v === null ? e.removeAttribute(n) : e.setAttribute(n, v);
|
|
13
13
|
}
|
|
14
|
-
snapshots.delete(
|
|
14
|
+
snapshots.delete(e);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
function saveAttributes(element_or_elements, name_or_names) {
|
|
18
18
|
const names = Array.isArray(name_or_names) ? name_or_names : [name_or_names];
|
|
19
|
-
for (const
|
|
20
|
-
let snapshot = snapshots.get(
|
|
19
|
+
for (const e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
|
|
20
|
+
let snapshot = snapshots.get(e);
|
|
21
21
|
if (!snapshot) {
|
|
22
22
|
snapshot = /* @__PURE__ */ new Map();
|
|
23
|
-
snapshots.set(
|
|
23
|
+
snapshots.set(e, snapshot);
|
|
24
24
|
}
|
|
25
|
-
for (const
|
|
26
|
-
snapshot.set(
|
|
25
|
+
for (const n of names) {
|
|
26
|
+
snapshot.set(n, e.getAttribute(n));
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -53,21 +53,21 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
53
53
|
skipNegativeTabIndexCheck,
|
|
54
54
|
skipVisibilityCheck
|
|
55
55
|
}) || include?.(node)) {
|
|
56
|
-
candidates
|
|
56
|
+
candidates.push(node);
|
|
57
57
|
}
|
|
58
|
-
(composed ? getComposedChildren(node) :
|
|
58
|
+
(composed ? getComposedChildren(node) : [...node.children]).map(traverse2);
|
|
59
59
|
};
|
|
60
|
-
(composed ? getComposedChildren(container) :
|
|
60
|
+
(composed ? getComposedChildren(container) : [...container.children]).map(
|
|
61
61
|
traverse2
|
|
62
62
|
);
|
|
63
63
|
} else {
|
|
64
|
-
for (const
|
|
64
|
+
for (const m of container.querySelectorAll(
|
|
65
65
|
skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
|
|
66
66
|
)) {
|
|
67
|
-
|
|
67
|
+
m && isFocusable(m, {
|
|
68
68
|
skipNegativeTabIndexCheck,
|
|
69
69
|
skipVisibilityCheck
|
|
70
|
-
}) && candidates.push(
|
|
70
|
+
}) && candidates.push(m);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
return normalizeRadioGroup(
|
|
@@ -183,58 +183,58 @@ function isDisabledDeep(element) {
|
|
|
183
183
|
}
|
|
184
184
|
function normalizeRadioGroup(elements) {
|
|
185
185
|
let map = null;
|
|
186
|
-
for (const
|
|
187
|
-
if (!(
|
|
186
|
+
for (const e of elements) {
|
|
187
|
+
if (!(e instanceof HTMLInputElement)) {
|
|
188
188
|
continue;
|
|
189
189
|
}
|
|
190
|
-
if (!isUngroupedRadio(
|
|
190
|
+
if (!isUngroupedRadio(e)) {
|
|
191
191
|
continue;
|
|
192
192
|
}
|
|
193
193
|
if (!map) {
|
|
194
194
|
map = /* @__PURE__ */ new Map();
|
|
195
195
|
}
|
|
196
|
-
const root =
|
|
197
|
-
let
|
|
198
|
-
if (!
|
|
199
|
-
|
|
200
|
-
map.set(root,
|
|
196
|
+
const root = e.getRootNode();
|
|
197
|
+
let groups = map.get(root);
|
|
198
|
+
if (!groups) {
|
|
199
|
+
groups = /* @__PURE__ */ new Map();
|
|
200
|
+
map.set(root, groups);
|
|
201
201
|
}
|
|
202
|
-
let
|
|
203
|
-
if (!
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
let group = groups.get(e.form);
|
|
203
|
+
if (!group) {
|
|
204
|
+
group = /* @__PURE__ */ new Map();
|
|
205
|
+
groups.set(e.form, group);
|
|
206
206
|
}
|
|
207
|
-
let
|
|
208
|
-
if (!
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
let radios = group.get(e.name);
|
|
208
|
+
if (!radios) {
|
|
209
|
+
radios = [];
|
|
210
|
+
group.set(e.name, radios);
|
|
211
211
|
}
|
|
212
|
-
|
|
212
|
+
radios.push(e);
|
|
213
213
|
}
|
|
214
214
|
if (!map) {
|
|
215
215
|
return elements;
|
|
216
216
|
}
|
|
217
217
|
const placeholder = /* @__PURE__ */ new Set();
|
|
218
|
-
for (const
|
|
219
|
-
for (const
|
|
220
|
-
for (const
|
|
221
|
-
const radio =
|
|
218
|
+
for (const v of map.values()) {
|
|
219
|
+
for (const w of v.values()) {
|
|
220
|
+
for (const x of w.values()) {
|
|
221
|
+
const radio = x.find((r) => r.checked) ?? x[0];
|
|
222
222
|
radio && placeholder.add(radio);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
-
return elements.filter((
|
|
227
|
-
if (!(
|
|
226
|
+
return elements.filter((e) => {
|
|
227
|
+
if (!(e instanceof HTMLInputElement)) {
|
|
228
228
|
return true;
|
|
229
229
|
}
|
|
230
|
-
return !isUngroupedRadio(
|
|
230
|
+
return !isUngroupedRadio(e) || placeholder.has(e);
|
|
231
231
|
});
|
|
232
232
|
}
|
|
233
233
|
function sortByTabIndex(elements) {
|
|
234
234
|
const ordered = [];
|
|
235
235
|
const natural = [];
|
|
236
|
-
for (const
|
|
237
|
-
(getTabIndex(
|
|
236
|
+
for (const e of elements) {
|
|
237
|
+
(getTabIndex(e) > 0 ? ordered : natural).push(e);
|
|
238
238
|
}
|
|
239
239
|
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
240
240
|
}
|
|
@@ -251,7 +251,7 @@ function containsComposed(container, element) {
|
|
|
251
251
|
}
|
|
252
252
|
function getComposedChildren(node) {
|
|
253
253
|
if (node instanceof ShadowRoot) {
|
|
254
|
-
return
|
|
254
|
+
return [...node.children];
|
|
255
255
|
}
|
|
256
256
|
if (!(node instanceof Element)) {
|
|
257
257
|
return [];
|
|
@@ -263,9 +263,9 @@ function getComposedChildren(node) {
|
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
266
|
-
return
|
|
266
|
+
return [...node.shadowRoot.children];
|
|
267
267
|
}
|
|
268
|
-
return
|
|
268
|
+
return [...node.children];
|
|
269
269
|
}
|
|
270
270
|
function focusElement(element) {
|
|
271
271
|
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
@@ -277,13 +277,6 @@ function getActiveElement() {
|
|
|
277
277
|
}
|
|
278
278
|
return current;
|
|
279
279
|
}
|
|
280
|
-
function getChildren(node) {
|
|
281
|
-
const elements = [];
|
|
282
|
-
for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
|
|
283
|
-
elements[elements.length] = child;
|
|
284
|
-
}
|
|
285
|
-
return elements;
|
|
286
|
-
}
|
|
287
280
|
function getTabIndex(element) {
|
|
288
281
|
return "tabIndex" in element ? Number(element.tabIndex) : 0;
|
|
289
282
|
}
|
|
@@ -357,7 +350,7 @@ function resolveOptions(options) {
|
|
|
357
350
|
}
|
|
358
351
|
|
|
359
352
|
// src/index.ts
|
|
360
|
-
var VISUALLY_HIDDEN_CSS =
|
|
353
|
+
var VISUALLY_HIDDEN_CSS = "border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; user-select: none; white-space: nowrap; width: 1px;";
|
|
361
354
|
function createPortal(host, container = document.body, options = {}) {
|
|
362
355
|
if (!(host instanceof Element)) {
|
|
363
356
|
console.warn("Invalid host element");
|
|
@@ -419,8 +412,8 @@ var Portal = class {
|
|
|
419
412
|
this.#update();
|
|
420
413
|
this.#controller = new AbortController();
|
|
421
414
|
const { signal } = this.#controller;
|
|
422
|
-
for (const
|
|
423
|
-
|
|
415
|
+
for (const s of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
416
|
+
s.addEventListener("focus", this.#onFocus, { signal });
|
|
424
417
|
}
|
|
425
418
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
426
419
|
this.#host.setAttribute("data-portaled", "");
|
|
@@ -479,17 +472,17 @@ var Portal = class {
|
|
|
479
472
|
...this.#getFocusables(),
|
|
480
473
|
...getFocusables(this.#host, { composed: true })
|
|
481
474
|
]);
|
|
482
|
-
for (const
|
|
483
|
-
if (!current.has(
|
|
484
|
-
restoreAttributes(
|
|
485
|
-
this.#focusables.delete(
|
|
475
|
+
for (const f of this.#focusables) {
|
|
476
|
+
if (!current.has(f)) {
|
|
477
|
+
restoreAttributes(f);
|
|
478
|
+
this.#focusables.delete(f);
|
|
486
479
|
}
|
|
487
480
|
}
|
|
488
|
-
for (const
|
|
489
|
-
if (!this.#focusables.has(
|
|
490
|
-
this.#focusables.add(
|
|
491
|
-
saveAttributes(
|
|
492
|
-
|
|
481
|
+
for (const f of current) {
|
|
482
|
+
if (!this.#focusables.has(f)) {
|
|
483
|
+
this.#focusables.add(f);
|
|
484
|
+
saveAttributes(f, "tabindex");
|
|
485
|
+
f.setAttribute("tabindex", "-1");
|
|
493
486
|
}
|
|
494
487
|
}
|
|
495
488
|
}
|
|
@@ -544,7 +537,7 @@ function resolveOptions2(options) {
|
|
|
544
537
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
545
538
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
546
539
|
*
|
|
547
|
-
* @version 1.3.
|
|
540
|
+
* @version 1.3.7
|
|
548
541
|
* @author Yusuke Kamiyamane
|
|
549
542
|
* @license MIT
|
|
550
543
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -556,7 +549,7 @@ function resolveOptions2(options) {
|
|
|
556
549
|
(**
|
|
557
550
|
* Attribute Utils
|
|
558
551
|
*
|
|
559
|
-
* @version 2.0.
|
|
552
|
+
* @version 2.0.11
|
|
560
553
|
* @author Yusuke Kamiyamane
|
|
561
554
|
* @license MIT
|
|
562
555
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -569,7 +562,7 @@ power-focusable/dist/index.js:
|
|
|
569
562
|
* High-precision focus management utility with full composed tree support.
|
|
570
563
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
571
564
|
*
|
|
572
|
-
* @version 4.3.
|
|
565
|
+
* @version 4.3.31
|
|
573
566
|
* @author Yusuke Kamiyamane
|
|
574
567
|
* @license MIT
|
|
575
568
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.bundle.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
// node_modules/@y14e/attribute-utils/dist/index.js
|
|
2
2
|
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
3
3
|
function restoreAttributes(element_or_elements) {
|
|
4
|
-
for (const
|
|
5
|
-
const snapshot = snapshots.get(
|
|
4
|
+
for (const e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
|
|
5
|
+
const snapshot = snapshots.get(e);
|
|
6
6
|
if (!snapshot) {
|
|
7
7
|
continue;
|
|
8
8
|
}
|
|
9
|
-
for (const [
|
|
10
|
-
|
|
9
|
+
for (const [n, v] of snapshot.entries()) {
|
|
10
|
+
v === null ? e.removeAttribute(n) : e.setAttribute(n, v);
|
|
11
11
|
}
|
|
12
|
-
snapshots.delete(
|
|
12
|
+
snapshots.delete(e);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
function saveAttributes(element_or_elements, name_or_names) {
|
|
16
16
|
const names = Array.isArray(name_or_names) ? name_or_names : [name_or_names];
|
|
17
|
-
for (const
|
|
18
|
-
let snapshot = snapshots.get(
|
|
17
|
+
for (const e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
|
|
18
|
+
let snapshot = snapshots.get(e);
|
|
19
19
|
if (!snapshot) {
|
|
20
20
|
snapshot = /* @__PURE__ */ new Map();
|
|
21
|
-
snapshots.set(
|
|
21
|
+
snapshots.set(e, snapshot);
|
|
22
22
|
}
|
|
23
|
-
for (const
|
|
24
|
-
snapshot.set(
|
|
23
|
+
for (const n of names) {
|
|
24
|
+
snapshot.set(n, e.getAttribute(n));
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -51,21 +51,21 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
51
51
|
skipNegativeTabIndexCheck,
|
|
52
52
|
skipVisibilityCheck
|
|
53
53
|
}) || include?.(node)) {
|
|
54
|
-
candidates
|
|
54
|
+
candidates.push(node);
|
|
55
55
|
}
|
|
56
|
-
(composed ? getComposedChildren(node) :
|
|
56
|
+
(composed ? getComposedChildren(node) : [...node.children]).map(traverse2);
|
|
57
57
|
};
|
|
58
|
-
(composed ? getComposedChildren(container) :
|
|
58
|
+
(composed ? getComposedChildren(container) : [...container.children]).map(
|
|
59
59
|
traverse2
|
|
60
60
|
);
|
|
61
61
|
} else {
|
|
62
|
-
for (const
|
|
62
|
+
for (const m of container.querySelectorAll(
|
|
63
63
|
skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
|
|
64
64
|
)) {
|
|
65
|
-
|
|
65
|
+
m && isFocusable(m, {
|
|
66
66
|
skipNegativeTabIndexCheck,
|
|
67
67
|
skipVisibilityCheck
|
|
68
|
-
}) && candidates.push(
|
|
68
|
+
}) && candidates.push(m);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
return normalizeRadioGroup(
|
|
@@ -181,58 +181,58 @@ function isDisabledDeep(element) {
|
|
|
181
181
|
}
|
|
182
182
|
function normalizeRadioGroup(elements) {
|
|
183
183
|
let map = null;
|
|
184
|
-
for (const
|
|
185
|
-
if (!(
|
|
184
|
+
for (const e of elements) {
|
|
185
|
+
if (!(e instanceof HTMLInputElement)) {
|
|
186
186
|
continue;
|
|
187
187
|
}
|
|
188
|
-
if (!isUngroupedRadio(
|
|
188
|
+
if (!isUngroupedRadio(e)) {
|
|
189
189
|
continue;
|
|
190
190
|
}
|
|
191
191
|
if (!map) {
|
|
192
192
|
map = /* @__PURE__ */ new Map();
|
|
193
193
|
}
|
|
194
|
-
const root =
|
|
195
|
-
let
|
|
196
|
-
if (!
|
|
197
|
-
|
|
198
|
-
map.set(root,
|
|
194
|
+
const root = e.getRootNode();
|
|
195
|
+
let groups = map.get(root);
|
|
196
|
+
if (!groups) {
|
|
197
|
+
groups = /* @__PURE__ */ new Map();
|
|
198
|
+
map.set(root, groups);
|
|
199
199
|
}
|
|
200
|
-
let
|
|
201
|
-
if (!
|
|
202
|
-
|
|
203
|
-
|
|
200
|
+
let group = groups.get(e.form);
|
|
201
|
+
if (!group) {
|
|
202
|
+
group = /* @__PURE__ */ new Map();
|
|
203
|
+
groups.set(e.form, group);
|
|
204
204
|
}
|
|
205
|
-
let
|
|
206
|
-
if (!
|
|
207
|
-
|
|
208
|
-
|
|
205
|
+
let radios = group.get(e.name);
|
|
206
|
+
if (!radios) {
|
|
207
|
+
radios = [];
|
|
208
|
+
group.set(e.name, radios);
|
|
209
209
|
}
|
|
210
|
-
|
|
210
|
+
radios.push(e);
|
|
211
211
|
}
|
|
212
212
|
if (!map) {
|
|
213
213
|
return elements;
|
|
214
214
|
}
|
|
215
215
|
const placeholder = /* @__PURE__ */ new Set();
|
|
216
|
-
for (const
|
|
217
|
-
for (const
|
|
218
|
-
for (const
|
|
219
|
-
const radio =
|
|
216
|
+
for (const v of map.values()) {
|
|
217
|
+
for (const w of v.values()) {
|
|
218
|
+
for (const x of w.values()) {
|
|
219
|
+
const radio = x.find((r) => r.checked) ?? x[0];
|
|
220
220
|
radio && placeholder.add(radio);
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
return elements.filter((
|
|
225
|
-
if (!(
|
|
224
|
+
return elements.filter((e) => {
|
|
225
|
+
if (!(e instanceof HTMLInputElement)) {
|
|
226
226
|
return true;
|
|
227
227
|
}
|
|
228
|
-
return !isUngroupedRadio(
|
|
228
|
+
return !isUngroupedRadio(e) || placeholder.has(e);
|
|
229
229
|
});
|
|
230
230
|
}
|
|
231
231
|
function sortByTabIndex(elements) {
|
|
232
232
|
const ordered = [];
|
|
233
233
|
const natural = [];
|
|
234
|
-
for (const
|
|
235
|
-
(getTabIndex(
|
|
234
|
+
for (const e of elements) {
|
|
235
|
+
(getTabIndex(e) > 0 ? ordered : natural).push(e);
|
|
236
236
|
}
|
|
237
237
|
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
238
238
|
}
|
|
@@ -249,7 +249,7 @@ function containsComposed(container, element) {
|
|
|
249
249
|
}
|
|
250
250
|
function getComposedChildren(node) {
|
|
251
251
|
if (node instanceof ShadowRoot) {
|
|
252
|
-
return
|
|
252
|
+
return [...node.children];
|
|
253
253
|
}
|
|
254
254
|
if (!(node instanceof Element)) {
|
|
255
255
|
return [];
|
|
@@ -261,9 +261,9 @@ function getComposedChildren(node) {
|
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
264
|
-
return
|
|
264
|
+
return [...node.shadowRoot.children];
|
|
265
265
|
}
|
|
266
|
-
return
|
|
266
|
+
return [...node.children];
|
|
267
267
|
}
|
|
268
268
|
function focusElement(element) {
|
|
269
269
|
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
@@ -275,13 +275,6 @@ function getActiveElement() {
|
|
|
275
275
|
}
|
|
276
276
|
return current;
|
|
277
277
|
}
|
|
278
|
-
function getChildren(node) {
|
|
279
|
-
const elements = [];
|
|
280
|
-
for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
|
|
281
|
-
elements[elements.length] = child;
|
|
282
|
-
}
|
|
283
|
-
return elements;
|
|
284
|
-
}
|
|
285
278
|
function getTabIndex(element) {
|
|
286
279
|
return "tabIndex" in element ? Number(element.tabIndex) : 0;
|
|
287
280
|
}
|
|
@@ -355,7 +348,7 @@ function resolveOptions(options) {
|
|
|
355
348
|
}
|
|
356
349
|
|
|
357
350
|
// src/index.ts
|
|
358
|
-
var VISUALLY_HIDDEN_CSS =
|
|
351
|
+
var VISUALLY_HIDDEN_CSS = "border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; user-select: none; white-space: nowrap; width: 1px;";
|
|
359
352
|
function createPortal(host, container = document.body, options = {}) {
|
|
360
353
|
if (!(host instanceof Element)) {
|
|
361
354
|
console.warn("Invalid host element");
|
|
@@ -417,8 +410,8 @@ var Portal = class {
|
|
|
417
410
|
this.#update();
|
|
418
411
|
this.#controller = new AbortController();
|
|
419
412
|
const { signal } = this.#controller;
|
|
420
|
-
for (const
|
|
421
|
-
|
|
413
|
+
for (const s of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
414
|
+
s.addEventListener("focus", this.#onFocus, { signal });
|
|
422
415
|
}
|
|
423
416
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
424
417
|
this.#host.setAttribute("data-portaled", "");
|
|
@@ -477,17 +470,17 @@ var Portal = class {
|
|
|
477
470
|
...this.#getFocusables(),
|
|
478
471
|
...getFocusables(this.#host, { composed: true })
|
|
479
472
|
]);
|
|
480
|
-
for (const
|
|
481
|
-
if (!current.has(
|
|
482
|
-
restoreAttributes(
|
|
483
|
-
this.#focusables.delete(
|
|
473
|
+
for (const f of this.#focusables) {
|
|
474
|
+
if (!current.has(f)) {
|
|
475
|
+
restoreAttributes(f);
|
|
476
|
+
this.#focusables.delete(f);
|
|
484
477
|
}
|
|
485
478
|
}
|
|
486
|
-
for (const
|
|
487
|
-
if (!this.#focusables.has(
|
|
488
|
-
this.#focusables.add(
|
|
489
|
-
saveAttributes(
|
|
490
|
-
|
|
479
|
+
for (const f of current) {
|
|
480
|
+
if (!this.#focusables.has(f)) {
|
|
481
|
+
this.#focusables.add(f);
|
|
482
|
+
saveAttributes(f, "tabindex");
|
|
483
|
+
f.setAttribute("tabindex", "-1");
|
|
491
484
|
}
|
|
492
485
|
}
|
|
493
486
|
}
|
|
@@ -542,7 +535,7 @@ function resolveOptions2(options) {
|
|
|
542
535
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
543
536
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
544
537
|
*
|
|
545
|
-
* @version 1.3.
|
|
538
|
+
* @version 1.3.7
|
|
546
539
|
* @author Yusuke Kamiyamane
|
|
547
540
|
* @license MIT
|
|
548
541
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -554,7 +547,7 @@ function resolveOptions2(options) {
|
|
|
554
547
|
(**
|
|
555
548
|
* Attribute Utils
|
|
556
549
|
*
|
|
557
|
-
* @version 2.0.
|
|
550
|
+
* @version 2.0.11
|
|
558
551
|
* @author Yusuke Kamiyamane
|
|
559
552
|
* @license MIT
|
|
560
553
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -567,7 +560,7 @@ power-focusable/dist/index.js:
|
|
|
567
560
|
* High-precision focus management utility with full composed tree support.
|
|
568
561
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
569
562
|
*
|
|
570
|
-
* @version 4.3.
|
|
563
|
+
* @version 4.3.31
|
|
571
564
|
* @author Yusuke Kamiyamane
|
|
572
565
|
* @license MIT
|
|
573
566
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.cjs
CHANGED
|
@@ -25,7 +25,7 @@ var utils__namespace = /*#__PURE__*/_interopNamespace(utils);
|
|
|
25
25
|
var pf__namespace = /*#__PURE__*/_interopNamespace(pf);
|
|
26
26
|
|
|
27
27
|
// src/index.ts
|
|
28
|
-
var VISUALLY_HIDDEN_CSS =
|
|
28
|
+
var VISUALLY_HIDDEN_CSS = "border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; user-select: none; white-space: nowrap; width: 1px;";
|
|
29
29
|
function createPortal(host, container = document.body, options = {}) {
|
|
30
30
|
if (!(host instanceof Element)) {
|
|
31
31
|
console.warn("Invalid host element");
|
|
@@ -87,8 +87,8 @@ var Portal = class {
|
|
|
87
87
|
this.#update();
|
|
88
88
|
this.#controller = new AbortController();
|
|
89
89
|
const { signal } = this.#controller;
|
|
90
|
-
for (const
|
|
91
|
-
|
|
90
|
+
for (const s of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
91
|
+
s.addEventListener("focus", this.#onFocus, { signal });
|
|
92
92
|
}
|
|
93
93
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
94
94
|
this.#host.setAttribute("data-portaled", "");
|
|
@@ -147,17 +147,17 @@ var Portal = class {
|
|
|
147
147
|
...this.#getFocusables(),
|
|
148
148
|
...pf__namespace.getFocusables(this.#host, { composed: true })
|
|
149
149
|
]);
|
|
150
|
-
for (const
|
|
151
|
-
if (!current.has(
|
|
152
|
-
utils__namespace.restoreAttributes(
|
|
153
|
-
this.#focusables.delete(
|
|
150
|
+
for (const f of this.#focusables) {
|
|
151
|
+
if (!current.has(f)) {
|
|
152
|
+
utils__namespace.restoreAttributes(f);
|
|
153
|
+
this.#focusables.delete(f);
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
-
for (const
|
|
157
|
-
if (!this.#focusables.has(
|
|
158
|
-
this.#focusables.add(
|
|
159
|
-
utils__namespace.saveAttributes(
|
|
160
|
-
|
|
156
|
+
for (const f of current) {
|
|
157
|
+
if (!this.#focusables.has(f)) {
|
|
158
|
+
this.#focusables.add(f);
|
|
159
|
+
utils__namespace.saveAttributes(f, "tabindex");
|
|
160
|
+
f.setAttribute("tabindex", "-1");
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
}
|
|
@@ -212,7 +212,7 @@ function resolveOptions(options) {
|
|
|
212
212
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
213
213
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
214
214
|
*
|
|
215
|
-
* @version 1.3.
|
|
215
|
+
* @version 1.3.7
|
|
216
216
|
* @author Yusuke Kamiyamane
|
|
217
217
|
* @license MIT
|
|
218
218
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
4
4
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
5
5
|
*
|
|
6
|
-
* @version 1.3.
|
|
6
|
+
* @version 1.3.7
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
4
4
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
5
5
|
*
|
|
6
|
-
* @version 1.3.
|
|
6
|
+
* @version 1.3.7
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import * as utils from '@y14e/attribute-utils';
|
|
|
2
2
|
import * as pf from 'power-focusable';
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
|
-
var VISUALLY_HIDDEN_CSS =
|
|
5
|
+
var VISUALLY_HIDDEN_CSS = "border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; user-select: none; white-space: nowrap; width: 1px;";
|
|
6
6
|
function createPortal(host, container = document.body, options = {}) {
|
|
7
7
|
if (!(host instanceof Element)) {
|
|
8
8
|
console.warn("Invalid host element");
|
|
@@ -64,8 +64,8 @@ var Portal = class {
|
|
|
64
64
|
this.#update();
|
|
65
65
|
this.#controller = new AbortController();
|
|
66
66
|
const { signal } = this.#controller;
|
|
67
|
-
for (const
|
|
68
|
-
|
|
67
|
+
for (const s of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
68
|
+
s.addEventListener("focus", this.#onFocus, { signal });
|
|
69
69
|
}
|
|
70
70
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
71
71
|
this.#host.setAttribute("data-portaled", "");
|
|
@@ -124,17 +124,17 @@ var Portal = class {
|
|
|
124
124
|
...this.#getFocusables(),
|
|
125
125
|
...pf.getFocusables(this.#host, { composed: true })
|
|
126
126
|
]);
|
|
127
|
-
for (const
|
|
128
|
-
if (!current.has(
|
|
129
|
-
utils.restoreAttributes(
|
|
130
|
-
this.#focusables.delete(
|
|
127
|
+
for (const f of this.#focusables) {
|
|
128
|
+
if (!current.has(f)) {
|
|
129
|
+
utils.restoreAttributes(f);
|
|
130
|
+
this.#focusables.delete(f);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
for (const
|
|
134
|
-
if (!this.#focusables.has(
|
|
135
|
-
this.#focusables.add(
|
|
136
|
-
utils.saveAttributes(
|
|
137
|
-
|
|
133
|
+
for (const f of current) {
|
|
134
|
+
if (!this.#focusables.has(f)) {
|
|
135
|
+
this.#focusables.add(f);
|
|
136
|
+
utils.saveAttributes(f, "tabindex");
|
|
137
|
+
f.setAttribute("tabindex", "-1");
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -189,7 +189,7 @@ function resolveOptions(options) {
|
|
|
189
189
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
190
190
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
191
191
|
*
|
|
192
|
-
* @version 1.3.
|
|
192
|
+
* @version 1.3.7
|
|
193
193
|
* @author Yusuke Kamiyamane
|
|
194
194
|
* @license MIT
|
|
195
195
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/portal",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.7",
|
|
4
4
|
"description": "Lightweight DOM portal (teleport) utility with fully focus management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"a11y",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"esbuild": true
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@y14e/attribute-utils": "^2.0.
|
|
62
|
-
"power-focusable": "^4.3.
|
|
61
|
+
"@y14e/attribute-utils": "^2.0.11",
|
|
62
|
+
"power-focusable": "^4.3.31"
|
|
63
63
|
}
|
|
64
64
|
}
|