@y14e/portal 1.4.6 → 1.4.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/dist/index.bundle.cjs +15 -27
- package/dist/index.bundle.js +15 -27
- package/dist/index.cjs +10 -14
- package/dist/index.js +10 -14
- package/package.json +3 -3
package/dist/index.bundle.cjs
CHANGED
|
@@ -230,7 +230,7 @@ function normalizeRadioGroup(elements) {
|
|
|
230
230
|
(radios.get(name) ?? radios.set(name, []).get(name))?.push(element);
|
|
231
231
|
}
|
|
232
232
|
if (!map) {
|
|
233
|
-
return elements;
|
|
233
|
+
return elements.slice();
|
|
234
234
|
}
|
|
235
235
|
const placeholder = /* @__PURE__ */ new Set();
|
|
236
236
|
for (const v of map.values()) {
|
|
@@ -241,20 +241,12 @@ function normalizeRadioGroup(elements) {
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
|
-
return elements.filter(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
return !isUngroupedRadio(element) || placeholder.has(element);
|
|
249
|
-
});
|
|
244
|
+
return elements.filter(
|
|
245
|
+
(e) => !(e instanceof HTMLInputElement) || !isUngroupedRadio(e) || placeholder.has(e)
|
|
246
|
+
);
|
|
250
247
|
}
|
|
251
248
|
function sortByTabIndex(elements) {
|
|
252
|
-
|
|
253
|
-
const natural = [];
|
|
254
|
-
for (const element of elements) {
|
|
255
|
-
(getTabIndex(element) > 0 ? ordered : natural).push(element);
|
|
256
|
-
}
|
|
257
|
-
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
249
|
+
return elements.filter((e) => getTabIndex(e) > 0).sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(elements.filter((e) => getTabIndex(e) <= 0));
|
|
258
250
|
}
|
|
259
251
|
function getFocusables(container = document.body, options = {}) {
|
|
260
252
|
if (!(container instanceof Element)) {
|
|
@@ -404,21 +396,21 @@ var Portal = class {
|
|
|
404
396
|
}
|
|
405
397
|
if (target === this.#entranceSentinel) {
|
|
406
398
|
if (this.#host.contains(previous)) {
|
|
407
|
-
this.#moveFocus(
|
|
399
|
+
this.#moveFocus(true);
|
|
408
400
|
return;
|
|
409
401
|
}
|
|
410
402
|
this.#update();
|
|
411
403
|
const first = [...this.#focusables][0];
|
|
412
|
-
first ? focusElement(first) : this.#moveFocus(
|
|
404
|
+
first ? focusElement(first) : this.#moveFocus(false);
|
|
413
405
|
return;
|
|
414
406
|
}
|
|
415
407
|
if (this.#host.contains(previous)) {
|
|
416
|
-
this.#moveFocus(
|
|
408
|
+
this.#moveFocus(false);
|
|
417
409
|
return;
|
|
418
410
|
}
|
|
419
411
|
this.#update();
|
|
420
412
|
const last = [...this.#focusables].at(-1);
|
|
421
|
-
last ? focusElement(last) : this.#moveFocus(
|
|
413
|
+
last ? focusElement(last) : this.#moveFocus(true);
|
|
422
414
|
};
|
|
423
415
|
#onKeyDown = (event) => {
|
|
424
416
|
if (!(event instanceof KeyboardEvent)) {
|
|
@@ -444,7 +436,7 @@ var Portal = class {
|
|
|
444
436
|
return;
|
|
445
437
|
}
|
|
446
438
|
event.preventDefault();
|
|
447
|
-
this.#moveFocus(shiftKey
|
|
439
|
+
this.#moveFocus(shiftKey);
|
|
448
440
|
};
|
|
449
441
|
#update() {
|
|
450
442
|
const current = /* @__PURE__ */ new Set([
|
|
@@ -479,17 +471,13 @@ var Portal = class {
|
|
|
479
471
|
(isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
|
|
480
472
|
}
|
|
481
473
|
#getFocusables() {
|
|
482
|
-
return getFocusables(this.#host, {
|
|
483
|
-
composed: true,
|
|
484
|
-
include: (element) => this.#focusables.has(element)
|
|
485
|
-
});
|
|
474
|
+
return getFocusables(this.#host, { composed: true, include: (e) => this.#focusables.has(e) });
|
|
486
475
|
}
|
|
487
|
-
#moveFocus(
|
|
488
|
-
const
|
|
489
|
-
anchor:
|
|
476
|
+
#moveFocus(isPrevious) {
|
|
477
|
+
const focusable = (isPrevious ? getPreviousFocusable : getNextFocusable)(document.body, {
|
|
478
|
+
anchor: isPrevious ? this.#entranceSentinel : this.#exitSentinel,
|
|
490
479
|
composed: true
|
|
491
|
-
};
|
|
492
|
-
const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
|
|
480
|
+
});
|
|
493
481
|
focusable && focusElement(focusable);
|
|
494
482
|
}
|
|
495
483
|
};
|
package/dist/index.bundle.js
CHANGED
|
@@ -228,7 +228,7 @@ function normalizeRadioGroup(elements) {
|
|
|
228
228
|
(radios.get(name) ?? radios.set(name, []).get(name))?.push(element);
|
|
229
229
|
}
|
|
230
230
|
if (!map) {
|
|
231
|
-
return elements;
|
|
231
|
+
return elements.slice();
|
|
232
232
|
}
|
|
233
233
|
const placeholder = /* @__PURE__ */ new Set();
|
|
234
234
|
for (const v of map.values()) {
|
|
@@ -239,20 +239,12 @@ function normalizeRadioGroup(elements) {
|
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
|
-
return elements.filter(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
return !isUngroupedRadio(element) || placeholder.has(element);
|
|
247
|
-
});
|
|
242
|
+
return elements.filter(
|
|
243
|
+
(e) => !(e instanceof HTMLInputElement) || !isUngroupedRadio(e) || placeholder.has(e)
|
|
244
|
+
);
|
|
248
245
|
}
|
|
249
246
|
function sortByTabIndex(elements) {
|
|
250
|
-
|
|
251
|
-
const natural = [];
|
|
252
|
-
for (const element of elements) {
|
|
253
|
-
(getTabIndex(element) > 0 ? ordered : natural).push(element);
|
|
254
|
-
}
|
|
255
|
-
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
247
|
+
return elements.filter((e) => getTabIndex(e) > 0).sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(elements.filter((e) => getTabIndex(e) <= 0));
|
|
256
248
|
}
|
|
257
249
|
function getFocusables(container = document.body, options = {}) {
|
|
258
250
|
if (!(container instanceof Element)) {
|
|
@@ -402,21 +394,21 @@ var Portal = class {
|
|
|
402
394
|
}
|
|
403
395
|
if (target === this.#entranceSentinel) {
|
|
404
396
|
if (this.#host.contains(previous)) {
|
|
405
|
-
this.#moveFocus(
|
|
397
|
+
this.#moveFocus(true);
|
|
406
398
|
return;
|
|
407
399
|
}
|
|
408
400
|
this.#update();
|
|
409
401
|
const first = [...this.#focusables][0];
|
|
410
|
-
first ? focusElement(first) : this.#moveFocus(
|
|
402
|
+
first ? focusElement(first) : this.#moveFocus(false);
|
|
411
403
|
return;
|
|
412
404
|
}
|
|
413
405
|
if (this.#host.contains(previous)) {
|
|
414
|
-
this.#moveFocus(
|
|
406
|
+
this.#moveFocus(false);
|
|
415
407
|
return;
|
|
416
408
|
}
|
|
417
409
|
this.#update();
|
|
418
410
|
const last = [...this.#focusables].at(-1);
|
|
419
|
-
last ? focusElement(last) : this.#moveFocus(
|
|
411
|
+
last ? focusElement(last) : this.#moveFocus(true);
|
|
420
412
|
};
|
|
421
413
|
#onKeyDown = (event) => {
|
|
422
414
|
if (!(event instanceof KeyboardEvent)) {
|
|
@@ -442,7 +434,7 @@ var Portal = class {
|
|
|
442
434
|
return;
|
|
443
435
|
}
|
|
444
436
|
event.preventDefault();
|
|
445
|
-
this.#moveFocus(shiftKey
|
|
437
|
+
this.#moveFocus(shiftKey);
|
|
446
438
|
};
|
|
447
439
|
#update() {
|
|
448
440
|
const current = /* @__PURE__ */ new Set([
|
|
@@ -477,17 +469,13 @@ var Portal = class {
|
|
|
477
469
|
(isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
|
|
478
470
|
}
|
|
479
471
|
#getFocusables() {
|
|
480
|
-
return getFocusables(this.#host, {
|
|
481
|
-
composed: true,
|
|
482
|
-
include: (element) => this.#focusables.has(element)
|
|
483
|
-
});
|
|
472
|
+
return getFocusables(this.#host, { composed: true, include: (e) => this.#focusables.has(e) });
|
|
484
473
|
}
|
|
485
|
-
#moveFocus(
|
|
486
|
-
const
|
|
487
|
-
anchor:
|
|
474
|
+
#moveFocus(isPrevious) {
|
|
475
|
+
const focusable = (isPrevious ? getPreviousFocusable : getNextFocusable)(document.body, {
|
|
476
|
+
anchor: isPrevious ? this.#entranceSentinel : this.#exitSentinel,
|
|
488
477
|
composed: true
|
|
489
|
-
};
|
|
490
|
-
const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
|
|
478
|
+
});
|
|
491
479
|
focusable && focusElement(focusable);
|
|
492
480
|
}
|
|
493
481
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -93,21 +93,21 @@ var Portal = class {
|
|
|
93
93
|
}
|
|
94
94
|
if (target === this.#entranceSentinel) {
|
|
95
95
|
if (this.#host.contains(previous)) {
|
|
96
|
-
this.#moveFocus(
|
|
96
|
+
this.#moveFocus(true);
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
99
|
this.#update();
|
|
100
100
|
const first = [...this.#focusables][0];
|
|
101
|
-
first ? powerFocusable.focusElement(first) : this.#moveFocus(
|
|
101
|
+
first ? powerFocusable.focusElement(first) : this.#moveFocus(false);
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
104
|
if (this.#host.contains(previous)) {
|
|
105
|
-
this.#moveFocus(
|
|
105
|
+
this.#moveFocus(false);
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
108
|
this.#update();
|
|
109
109
|
const last = [...this.#focusables].at(-1);
|
|
110
|
-
last ? powerFocusable.focusElement(last) : this.#moveFocus(
|
|
110
|
+
last ? powerFocusable.focusElement(last) : this.#moveFocus(true);
|
|
111
111
|
};
|
|
112
112
|
#onKeyDown = (event) => {
|
|
113
113
|
if (!(event instanceof KeyboardEvent)) {
|
|
@@ -133,7 +133,7 @@ var Portal = class {
|
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
135
|
event.preventDefault();
|
|
136
|
-
this.#moveFocus(shiftKey
|
|
136
|
+
this.#moveFocus(shiftKey);
|
|
137
137
|
};
|
|
138
138
|
#update() {
|
|
139
139
|
const current = /* @__PURE__ */ new Set([
|
|
@@ -168,17 +168,13 @@ var Portal = class {
|
|
|
168
168
|
(isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
|
|
169
169
|
}
|
|
170
170
|
#getFocusables() {
|
|
171
|
-
return powerFocusable.getFocusables(this.#host, {
|
|
172
|
-
composed: true,
|
|
173
|
-
include: (element) => this.#focusables.has(element)
|
|
174
|
-
});
|
|
171
|
+
return powerFocusable.getFocusables(this.#host, { composed: true, include: (e) => this.#focusables.has(e) });
|
|
175
172
|
}
|
|
176
|
-
#moveFocus(
|
|
177
|
-
const
|
|
178
|
-
anchor:
|
|
173
|
+
#moveFocus(isPrevious) {
|
|
174
|
+
const focusable = (isPrevious ? powerFocusable.getPreviousFocusable : powerFocusable.getNextFocusable)(document.body, {
|
|
175
|
+
anchor: isPrevious ? this.#entranceSentinel : this.#exitSentinel,
|
|
179
176
|
composed: true
|
|
180
|
-
};
|
|
181
|
-
const focusable = direction === "previous" ? powerFocusable.getPreviousFocusable(document.body, options) : powerFocusable.getNextFocusable(document.body, options);
|
|
177
|
+
});
|
|
182
178
|
focusable && powerFocusable.focusElement(focusable);
|
|
183
179
|
}
|
|
184
180
|
};
|
package/dist/index.js
CHANGED
|
@@ -91,21 +91,21 @@ var Portal = class {
|
|
|
91
91
|
}
|
|
92
92
|
if (target === this.#entranceSentinel) {
|
|
93
93
|
if (this.#host.contains(previous)) {
|
|
94
|
-
this.#moveFocus(
|
|
94
|
+
this.#moveFocus(true);
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
this.#update();
|
|
98
98
|
const first = [...this.#focusables][0];
|
|
99
|
-
first ? focusElement(first) : this.#moveFocus(
|
|
99
|
+
first ? focusElement(first) : this.#moveFocus(false);
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
if (this.#host.contains(previous)) {
|
|
103
|
-
this.#moveFocus(
|
|
103
|
+
this.#moveFocus(false);
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
106
|
this.#update();
|
|
107
107
|
const last = [...this.#focusables].at(-1);
|
|
108
|
-
last ? focusElement(last) : this.#moveFocus(
|
|
108
|
+
last ? focusElement(last) : this.#moveFocus(true);
|
|
109
109
|
};
|
|
110
110
|
#onKeyDown = (event) => {
|
|
111
111
|
if (!(event instanceof KeyboardEvent)) {
|
|
@@ -131,7 +131,7 @@ var Portal = class {
|
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
133
133
|
event.preventDefault();
|
|
134
|
-
this.#moveFocus(shiftKey
|
|
134
|
+
this.#moveFocus(shiftKey);
|
|
135
135
|
};
|
|
136
136
|
#update() {
|
|
137
137
|
const current = /* @__PURE__ */ new Set([
|
|
@@ -166,17 +166,13 @@ var Portal = class {
|
|
|
166
166
|
(isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
|
|
167
167
|
}
|
|
168
168
|
#getFocusables() {
|
|
169
|
-
return getFocusables(this.#host, {
|
|
170
|
-
composed: true,
|
|
171
|
-
include: (element) => this.#focusables.has(element)
|
|
172
|
-
});
|
|
169
|
+
return getFocusables(this.#host, { composed: true, include: (e) => this.#focusables.has(e) });
|
|
173
170
|
}
|
|
174
|
-
#moveFocus(
|
|
175
|
-
const
|
|
176
|
-
anchor:
|
|
171
|
+
#moveFocus(isPrevious) {
|
|
172
|
+
const focusable = (isPrevious ? getPreviousFocusable : getNextFocusable)(document.body, {
|
|
173
|
+
anchor: isPrevious ? this.#entranceSentinel : this.#exitSentinel,
|
|
177
174
|
composed: true
|
|
178
|
-
};
|
|
179
|
-
const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
|
|
175
|
+
});
|
|
180
176
|
focusable && focusElement(focusable);
|
|
181
177
|
}
|
|
182
178
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/portal",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.8",
|
|
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.5.
|
|
61
|
+
"@y14e/attribute-utils": "^2.0.21",
|
|
62
|
+
"power-focusable": "^4.5.12"
|
|
63
63
|
}
|
|
64
64
|
}
|