@y14e/portal 1.3.7 → 1.3.8
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 +34 -34
- package/dist/index.bundle.js +34 -34
- package/dist/index.cjs +12 -12
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -12
- package/package.json +2 -2
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.8';
|
|
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.8/+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.8';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 📦 APIs
|
package/dist/index.bundle.cjs
CHANGED
|
@@ -61,13 +61,13 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
61
61
|
traverse2
|
|
62
62
|
);
|
|
63
63
|
} else {
|
|
64
|
-
for (const
|
|
64
|
+
for (const match of container.querySelectorAll(
|
|
65
65
|
skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
|
|
66
66
|
)) {
|
|
67
|
-
|
|
67
|
+
match && isFocusable(match, {
|
|
68
68
|
skipNegativeTabIndexCheck,
|
|
69
69
|
skipVisibilityCheck
|
|
70
|
-
}) && candidates.push(
|
|
70
|
+
}) && candidates.push(match);
|
|
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 element of elements) {
|
|
187
|
+
if (!(element instanceof HTMLInputElement)) {
|
|
188
188
|
continue;
|
|
189
189
|
}
|
|
190
|
-
if (!isUngroupedRadio(
|
|
190
|
+
if (!isUngroupedRadio(element)) {
|
|
191
191
|
continue;
|
|
192
192
|
}
|
|
193
193
|
if (!map) {
|
|
194
194
|
map = /* @__PURE__ */ new Map();
|
|
195
195
|
}
|
|
196
|
-
const root =
|
|
196
|
+
const root = element.getRootNode();
|
|
197
197
|
let groups = map.get(root);
|
|
198
198
|
if (!groups) {
|
|
199
199
|
groups = /* @__PURE__ */ new Map();
|
|
200
200
|
map.set(root, groups);
|
|
201
201
|
}
|
|
202
|
-
let group = groups.get(
|
|
202
|
+
let group = groups.get(element.form);
|
|
203
203
|
if (!group) {
|
|
204
204
|
group = /* @__PURE__ */ new Map();
|
|
205
|
-
groups.set(
|
|
205
|
+
groups.set(element.form, group);
|
|
206
206
|
}
|
|
207
|
-
let radios = group.get(
|
|
207
|
+
let radios = group.get(element.name);
|
|
208
208
|
if (!radios) {
|
|
209
209
|
radios = [];
|
|
210
|
-
group.set(
|
|
210
|
+
group.set(element.name, radios);
|
|
211
211
|
}
|
|
212
|
-
radios.push(
|
|
212
|
+
radios.push(element);
|
|
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 groups of map.values()) {
|
|
219
|
+
for (const group of groups.values()) {
|
|
220
|
+
for (const radios of group.values()) {
|
|
221
|
+
const radio = radios.find((r) => r.checked) ?? radios[0];
|
|
222
222
|
radio && placeholder.add(radio);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
-
return elements.filter((
|
|
227
|
-
if (!(
|
|
226
|
+
return elements.filter((element) => {
|
|
227
|
+
if (!(element instanceof HTMLInputElement)) {
|
|
228
228
|
return true;
|
|
229
229
|
}
|
|
230
|
-
return !isUngroupedRadio(
|
|
230
|
+
return !isUngroupedRadio(element) || placeholder.has(element);
|
|
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 element of elements) {
|
|
237
|
+
(getTabIndex(element) > 0 ? ordered : natural).push(element);
|
|
238
238
|
}
|
|
239
239
|
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
240
240
|
}
|
|
@@ -412,8 +412,8 @@ var Portal = class {
|
|
|
412
412
|
this.#update();
|
|
413
413
|
this.#controller = new AbortController();
|
|
414
414
|
const { signal } = this.#controller;
|
|
415
|
-
for (const
|
|
416
|
-
|
|
415
|
+
for (const sentinel of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
416
|
+
sentinel.addEventListener("focus", this.#onFocus, { signal });
|
|
417
417
|
}
|
|
418
418
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
419
419
|
this.#host.setAttribute("data-portaled", "");
|
|
@@ -472,17 +472,17 @@ var Portal = class {
|
|
|
472
472
|
...this.#getFocusables(),
|
|
473
473
|
...getFocusables(this.#host, { composed: true })
|
|
474
474
|
]);
|
|
475
|
-
for (const
|
|
476
|
-
if (!current.has(
|
|
477
|
-
restoreAttributes(
|
|
478
|
-
this.#focusables.delete(
|
|
475
|
+
for (const focusable of this.#focusables) {
|
|
476
|
+
if (!current.has(focusable)) {
|
|
477
|
+
restoreAttributes(focusable);
|
|
478
|
+
this.#focusables.delete(focusable);
|
|
479
479
|
}
|
|
480
480
|
}
|
|
481
|
-
for (const
|
|
482
|
-
if (!this.#focusables.has(
|
|
483
|
-
this.#focusables.add(
|
|
484
|
-
saveAttributes(
|
|
485
|
-
|
|
481
|
+
for (const focusable of current) {
|
|
482
|
+
if (!this.#focusables.has(focusable)) {
|
|
483
|
+
this.#focusables.add(focusable);
|
|
484
|
+
saveAttributes(focusable, "tabindex");
|
|
485
|
+
focusable.setAttribute("tabindex", "-1");
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
488
|
}
|
|
@@ -537,7 +537,7 @@ function resolveOptions2(options) {
|
|
|
537
537
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
538
538
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
539
539
|
*
|
|
540
|
-
* @version 1.3.
|
|
540
|
+
* @version 1.3.8
|
|
541
541
|
* @author Yusuke Kamiyamane
|
|
542
542
|
* @license MIT
|
|
543
543
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -562,7 +562,7 @@ power-focusable/dist/index.js:
|
|
|
562
562
|
* High-precision focus management utility with full composed tree support.
|
|
563
563
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
564
564
|
*
|
|
565
|
-
* @version 4.3.
|
|
565
|
+
* @version 4.3.33
|
|
566
566
|
* @author Yusuke Kamiyamane
|
|
567
567
|
* @license MIT
|
|
568
568
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.bundle.js
CHANGED
|
@@ -59,13 +59,13 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
59
59
|
traverse2
|
|
60
60
|
);
|
|
61
61
|
} else {
|
|
62
|
-
for (const
|
|
62
|
+
for (const match of container.querySelectorAll(
|
|
63
63
|
skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
|
|
64
64
|
)) {
|
|
65
|
-
|
|
65
|
+
match && isFocusable(match, {
|
|
66
66
|
skipNegativeTabIndexCheck,
|
|
67
67
|
skipVisibilityCheck
|
|
68
|
-
}) && candidates.push(
|
|
68
|
+
}) && candidates.push(match);
|
|
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 element of elements) {
|
|
185
|
+
if (!(element instanceof HTMLInputElement)) {
|
|
186
186
|
continue;
|
|
187
187
|
}
|
|
188
|
-
if (!isUngroupedRadio(
|
|
188
|
+
if (!isUngroupedRadio(element)) {
|
|
189
189
|
continue;
|
|
190
190
|
}
|
|
191
191
|
if (!map) {
|
|
192
192
|
map = /* @__PURE__ */ new Map();
|
|
193
193
|
}
|
|
194
|
-
const root =
|
|
194
|
+
const root = element.getRootNode();
|
|
195
195
|
let groups = map.get(root);
|
|
196
196
|
if (!groups) {
|
|
197
197
|
groups = /* @__PURE__ */ new Map();
|
|
198
198
|
map.set(root, groups);
|
|
199
199
|
}
|
|
200
|
-
let group = groups.get(
|
|
200
|
+
let group = groups.get(element.form);
|
|
201
201
|
if (!group) {
|
|
202
202
|
group = /* @__PURE__ */ new Map();
|
|
203
|
-
groups.set(
|
|
203
|
+
groups.set(element.form, group);
|
|
204
204
|
}
|
|
205
|
-
let radios = group.get(
|
|
205
|
+
let radios = group.get(element.name);
|
|
206
206
|
if (!radios) {
|
|
207
207
|
radios = [];
|
|
208
|
-
group.set(
|
|
208
|
+
group.set(element.name, radios);
|
|
209
209
|
}
|
|
210
|
-
radios.push(
|
|
210
|
+
radios.push(element);
|
|
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 groups of map.values()) {
|
|
217
|
+
for (const group of groups.values()) {
|
|
218
|
+
for (const radios of group.values()) {
|
|
219
|
+
const radio = radios.find((r) => r.checked) ?? radios[0];
|
|
220
220
|
radio && placeholder.add(radio);
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
return elements.filter((
|
|
225
|
-
if (!(
|
|
224
|
+
return elements.filter((element) => {
|
|
225
|
+
if (!(element instanceof HTMLInputElement)) {
|
|
226
226
|
return true;
|
|
227
227
|
}
|
|
228
|
-
return !isUngroupedRadio(
|
|
228
|
+
return !isUngroupedRadio(element) || placeholder.has(element);
|
|
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 element of elements) {
|
|
235
|
+
(getTabIndex(element) > 0 ? ordered : natural).push(element);
|
|
236
236
|
}
|
|
237
237
|
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
238
238
|
}
|
|
@@ -410,8 +410,8 @@ var Portal = class {
|
|
|
410
410
|
this.#update();
|
|
411
411
|
this.#controller = new AbortController();
|
|
412
412
|
const { signal } = this.#controller;
|
|
413
|
-
for (const
|
|
414
|
-
|
|
413
|
+
for (const sentinel of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
414
|
+
sentinel.addEventListener("focus", this.#onFocus, { signal });
|
|
415
415
|
}
|
|
416
416
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
417
417
|
this.#host.setAttribute("data-portaled", "");
|
|
@@ -470,17 +470,17 @@ var Portal = class {
|
|
|
470
470
|
...this.#getFocusables(),
|
|
471
471
|
...getFocusables(this.#host, { composed: true })
|
|
472
472
|
]);
|
|
473
|
-
for (const
|
|
474
|
-
if (!current.has(
|
|
475
|
-
restoreAttributes(
|
|
476
|
-
this.#focusables.delete(
|
|
473
|
+
for (const focusable of this.#focusables) {
|
|
474
|
+
if (!current.has(focusable)) {
|
|
475
|
+
restoreAttributes(focusable);
|
|
476
|
+
this.#focusables.delete(focusable);
|
|
477
477
|
}
|
|
478
478
|
}
|
|
479
|
-
for (const
|
|
480
|
-
if (!this.#focusables.has(
|
|
481
|
-
this.#focusables.add(
|
|
482
|
-
saveAttributes(
|
|
483
|
-
|
|
479
|
+
for (const focusable of current) {
|
|
480
|
+
if (!this.#focusables.has(focusable)) {
|
|
481
|
+
this.#focusables.add(focusable);
|
|
482
|
+
saveAttributes(focusable, "tabindex");
|
|
483
|
+
focusable.setAttribute("tabindex", "-1");
|
|
484
484
|
}
|
|
485
485
|
}
|
|
486
486
|
}
|
|
@@ -535,7 +535,7 @@ function resolveOptions2(options) {
|
|
|
535
535
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
536
536
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
537
537
|
*
|
|
538
|
-
* @version 1.3.
|
|
538
|
+
* @version 1.3.8
|
|
539
539
|
* @author Yusuke Kamiyamane
|
|
540
540
|
* @license MIT
|
|
541
541
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -560,7 +560,7 @@ power-focusable/dist/index.js:
|
|
|
560
560
|
* High-precision focus management utility with full composed tree support.
|
|
561
561
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
562
562
|
*
|
|
563
|
-
* @version 4.3.
|
|
563
|
+
* @version 4.3.33
|
|
564
564
|
* @author Yusuke Kamiyamane
|
|
565
565
|
* @license MIT
|
|
566
566
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.cjs
CHANGED
|
@@ -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 sentinel of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
91
|
+
sentinel.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 focusable of this.#focusables) {
|
|
151
|
+
if (!current.has(focusable)) {
|
|
152
|
+
utils__namespace.restoreAttributes(focusable);
|
|
153
|
+
this.#focusables.delete(focusable);
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
-
for (const
|
|
157
|
-
if (!this.#focusables.has(
|
|
158
|
-
this.#focusables.add(
|
|
159
|
-
utils__namespace.saveAttributes(
|
|
160
|
-
|
|
156
|
+
for (const focusable of current) {
|
|
157
|
+
if (!this.#focusables.has(focusable)) {
|
|
158
|
+
this.#focusables.add(focusable);
|
|
159
|
+
utils__namespace.saveAttributes(focusable, "tabindex");
|
|
160
|
+
focusable.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.8
|
|
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.8
|
|
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.8
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.js
CHANGED
|
@@ -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 sentinel of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
68
|
+
sentinel.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 focusable of this.#focusables) {
|
|
128
|
+
if (!current.has(focusable)) {
|
|
129
|
+
utils.restoreAttributes(focusable);
|
|
130
|
+
this.#focusables.delete(focusable);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
for (const
|
|
134
|
-
if (!this.#focusables.has(
|
|
135
|
-
this.#focusables.add(
|
|
136
|
-
utils.saveAttributes(
|
|
137
|
-
|
|
133
|
+
for (const focusable of current) {
|
|
134
|
+
if (!this.#focusables.has(focusable)) {
|
|
135
|
+
this.#focusables.add(focusable);
|
|
136
|
+
utils.saveAttributes(focusable, "tabindex");
|
|
137
|
+
focusable.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.8
|
|
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.8",
|
|
4
4
|
"description": "Lightweight DOM portal (teleport) utility with fully focus management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"a11y",
|
|
@@ -59,6 +59,6 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@y14e/attribute-utils": "^2.0.11",
|
|
62
|
-
"power-focusable": "^4.3.
|
|
62
|
+
"power-focusable": "^4.3.33"
|
|
63
63
|
}
|
|
64
64
|
}
|