@y14e/portal 1.4.6 → 1.4.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/dist/index.bundle.cjs +14 -23
- package/dist/index.bundle.js +14 -23
- package/dist/index.cjs +9 -10
- package/dist/index.js +9 -10
- 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([
|
|
@@ -484,12 +476,11 @@ var Portal = class {
|
|
|
484
476
|
include: (element) => this.#focusables.has(element)
|
|
485
477
|
});
|
|
486
478
|
}
|
|
487
|
-
#moveFocus(
|
|
488
|
-
const
|
|
489
|
-
anchor:
|
|
479
|
+
#moveFocus(isPrevious) {
|
|
480
|
+
const focusable = (isPrevious ? getPreviousFocusable : getNextFocusable)(document.body, {
|
|
481
|
+
anchor: isPrevious ? this.#entranceSentinel : this.#exitSentinel,
|
|
490
482
|
composed: true
|
|
491
|
-
};
|
|
492
|
-
const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
|
|
483
|
+
});
|
|
493
484
|
focusable && focusElement(focusable);
|
|
494
485
|
}
|
|
495
486
|
};
|
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([
|
|
@@ -482,12 +474,11 @@ var Portal = class {
|
|
|
482
474
|
include: (element) => this.#focusables.has(element)
|
|
483
475
|
});
|
|
484
476
|
}
|
|
485
|
-
#moveFocus(
|
|
486
|
-
const
|
|
487
|
-
anchor:
|
|
477
|
+
#moveFocus(isPrevious) {
|
|
478
|
+
const focusable = (isPrevious ? getPreviousFocusable : getNextFocusable)(document.body, {
|
|
479
|
+
anchor: isPrevious ? this.#entranceSentinel : this.#exitSentinel,
|
|
488
480
|
composed: true
|
|
489
|
-
};
|
|
490
|
-
const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
|
|
481
|
+
});
|
|
491
482
|
focusable && focusElement(focusable);
|
|
492
483
|
}
|
|
493
484
|
};
|
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([
|
|
@@ -173,12 +173,11 @@ var Portal = class {
|
|
|
173
173
|
include: (element) => this.#focusables.has(element)
|
|
174
174
|
});
|
|
175
175
|
}
|
|
176
|
-
#moveFocus(
|
|
177
|
-
const
|
|
178
|
-
anchor:
|
|
176
|
+
#moveFocus(isPrevious) {
|
|
177
|
+
const focusable = (isPrevious ? powerFocusable.getPreviousFocusable : powerFocusable.getNextFocusable)(document.body, {
|
|
178
|
+
anchor: isPrevious ? this.#entranceSentinel : this.#exitSentinel,
|
|
179
179
|
composed: true
|
|
180
|
-
};
|
|
181
|
-
const focusable = direction === "previous" ? powerFocusable.getPreviousFocusable(document.body, options) : powerFocusable.getNextFocusable(document.body, options);
|
|
180
|
+
});
|
|
182
181
|
focusable && powerFocusable.focusElement(focusable);
|
|
183
182
|
}
|
|
184
183
|
};
|
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([
|
|
@@ -171,12 +171,11 @@ var Portal = class {
|
|
|
171
171
|
include: (element) => this.#focusables.has(element)
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
|
-
#moveFocus(
|
|
175
|
-
const
|
|
176
|
-
anchor:
|
|
174
|
+
#moveFocus(isPrevious) {
|
|
175
|
+
const focusable = (isPrevious ? getPreviousFocusable : getNextFocusable)(document.body, {
|
|
176
|
+
anchor: isPrevious ? this.#entranceSentinel : this.#exitSentinel,
|
|
177
177
|
composed: true
|
|
178
|
-
};
|
|
179
|
-
const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
|
|
178
|
+
});
|
|
180
179
|
focusable && focusElement(focusable);
|
|
181
180
|
}
|
|
182
181
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/portal",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.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.5.
|
|
61
|
+
"@y14e/attribute-utils": "^2.0.21",
|
|
62
|
+
"power-focusable": "^4.5.12"
|
|
63
63
|
}
|
|
64
64
|
}
|