@y14e/portal 1.2.2 → 1.2.4
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.cjs +51 -23
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +51 -23
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// node_modules/@y14e/attributes-utils/dist/index.js
|
|
4
|
+
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
function restoreAttributes(elements) {
|
|
6
|
+
elements.forEach((element) => {
|
|
7
|
+
const snapshot = snapshots.get(element);
|
|
8
|
+
if (!snapshot) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
for (const [attribute, value] of snapshot.entries()) {
|
|
12
|
+
if (value === null) {
|
|
13
|
+
element.removeAttribute(attribute);
|
|
14
|
+
} else {
|
|
15
|
+
element.setAttribute(attribute, value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
snapshots.delete(element);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function saveAttributes(elements, attributes) {
|
|
22
|
+
elements.forEach((element) => {
|
|
23
|
+
let snapshot = snapshots.get(element);
|
|
24
|
+
if (!snapshot) {
|
|
25
|
+
snapshot = /* @__PURE__ */ new Map();
|
|
26
|
+
snapshots.set(element, snapshot);
|
|
27
|
+
}
|
|
28
|
+
attributes.forEach((attribute) => {
|
|
29
|
+
snapshot.set(attribute, element.getAttribute(attribute));
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
3
34
|
// node_modules/power-focusable/dist/index.js
|
|
4
35
|
var FOCUSABLE_SELECTOR = `:is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])`;
|
|
5
36
|
function getFocusables(container = document.body, options = {}) {
|
|
@@ -296,7 +327,6 @@ var Portal = class {
|
|
|
296
327
|
#entranceSentinel;
|
|
297
328
|
#exitSentinel;
|
|
298
329
|
#focusables = /* @__PURE__ */ new Set();
|
|
299
|
-
#tabIndexes = /* @__PURE__ */ new Map();
|
|
300
330
|
#controller = null;
|
|
301
331
|
#isDestroyed = false;
|
|
302
332
|
constructor(host, container) {
|
|
@@ -313,16 +343,8 @@ var Portal = class {
|
|
|
313
343
|
this.#isDestroyed = true;
|
|
314
344
|
this.#controller?.abort();
|
|
315
345
|
this.#controller = null;
|
|
316
|
-
this.#focusables
|
|
317
|
-
const index = this.#tabIndexes.get(focusable);
|
|
318
|
-
if (index == null) {
|
|
319
|
-
focusable.removeAttribute("tabindex");
|
|
320
|
-
} else {
|
|
321
|
-
focusable.setAttribute("tabindex", index);
|
|
322
|
-
}
|
|
323
|
-
});
|
|
346
|
+
restoreAttributes([...this.#focusables]);
|
|
324
347
|
this.#focusables.clear();
|
|
325
|
-
this.#tabIndexes.clear();
|
|
326
348
|
this.#exitSentinel.after(this.#host);
|
|
327
349
|
this.#entranceSentinel.remove();
|
|
328
350
|
this.#exitSentinel.remove();
|
|
@@ -370,7 +392,8 @@ var Portal = class {
|
|
|
370
392
|
}
|
|
371
393
|
};
|
|
372
394
|
#onKeyDown = (event) => {
|
|
373
|
-
|
|
395
|
+
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
396
|
+
if (key !== "Tab" || altKey || ctrlKey || metaKey) {
|
|
374
397
|
return;
|
|
375
398
|
}
|
|
376
399
|
const active = getActiveElement2();
|
|
@@ -384,7 +407,7 @@ var Portal = class {
|
|
|
384
407
|
const focusables = this.#getFocusables();
|
|
385
408
|
if (!focusables.length) {
|
|
386
409
|
event.preventDefault();
|
|
387
|
-
this.#focusSentinel(
|
|
410
|
+
this.#focusSentinel(shiftKey);
|
|
388
411
|
return;
|
|
389
412
|
}
|
|
390
413
|
const index = focusables.indexOf(active);
|
|
@@ -392,11 +415,11 @@ var Portal = class {
|
|
|
392
415
|
return;
|
|
393
416
|
}
|
|
394
417
|
event.preventDefault();
|
|
395
|
-
const focusable = focusables[index + (
|
|
418
|
+
const focusable = focusables[index + (shiftKey ? -1 : 1)];
|
|
396
419
|
if (focusable) {
|
|
397
420
|
focusElement(focusable);
|
|
398
421
|
} else {
|
|
399
|
-
this.#focusSentinel(
|
|
422
|
+
this.#focusSentinel(shiftKey);
|
|
400
423
|
}
|
|
401
424
|
};
|
|
402
425
|
#update() {
|
|
@@ -409,22 +432,16 @@ var Portal = class {
|
|
|
409
432
|
return;
|
|
410
433
|
}
|
|
411
434
|
if (focusable.isConnected) {
|
|
412
|
-
|
|
413
|
-
if (index == null) {
|
|
414
|
-
focusable.removeAttribute("tabindex");
|
|
415
|
-
} else {
|
|
416
|
-
focusable.setAttribute("tabindex", index);
|
|
417
|
-
}
|
|
435
|
+
restoreAttributes([focusable]);
|
|
418
436
|
}
|
|
419
437
|
this.#focusables.delete(focusable);
|
|
420
|
-
this.#tabIndexes.delete(focusable);
|
|
421
438
|
});
|
|
422
439
|
current.forEach((c) => {
|
|
423
440
|
if (this.#focusables.has(c)) {
|
|
424
441
|
return;
|
|
425
442
|
}
|
|
426
443
|
this.#focusables.add(c);
|
|
427
|
-
|
|
444
|
+
saveAttributes([c], ["tabindex"]);
|
|
428
445
|
c.setAttribute("tabindex", "-1");
|
|
429
446
|
});
|
|
430
447
|
}
|
|
@@ -481,7 +498,7 @@ function getActiveElement2() {
|
|
|
481
498
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
482
499
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
483
500
|
*
|
|
484
|
-
* @version 1.2.
|
|
501
|
+
* @version 1.2.4
|
|
485
502
|
* @author Yusuke Kamiyamane
|
|
486
503
|
* @license MIT
|
|
487
504
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -489,6 +506,17 @@ function getActiveElement2() {
|
|
|
489
506
|
*/
|
|
490
507
|
/*! Bundled license information:
|
|
491
508
|
|
|
509
|
+
@y14e/attributes-utils/dist/index.js:
|
|
510
|
+
(**
|
|
511
|
+
* Attributes Utils
|
|
512
|
+
*
|
|
513
|
+
* @version 1.0.0
|
|
514
|
+
* @author Yusuke Kamiyamane
|
|
515
|
+
* @license MIT
|
|
516
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
517
|
+
* @see {@link https://github.com/y14e/attributes-utils}
|
|
518
|
+
*)
|
|
519
|
+
|
|
492
520
|
power-focusable/dist/index.js:
|
|
493
521
|
(**
|
|
494
522
|
* Power Focusable
|
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.2.
|
|
6
|
+
* @version 1.2.4
|
|
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.2.
|
|
6
|
+
* @version 1.2.4
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
// node_modules/@y14e/attributes-utils/dist/index.js
|
|
2
|
+
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function restoreAttributes(elements) {
|
|
4
|
+
elements.forEach((element) => {
|
|
5
|
+
const snapshot = snapshots.get(element);
|
|
6
|
+
if (!snapshot) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
for (const [attribute, value] of snapshot.entries()) {
|
|
10
|
+
if (value === null) {
|
|
11
|
+
element.removeAttribute(attribute);
|
|
12
|
+
} else {
|
|
13
|
+
element.setAttribute(attribute, value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
snapshots.delete(element);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function saveAttributes(elements, attributes) {
|
|
20
|
+
elements.forEach((element) => {
|
|
21
|
+
let snapshot = snapshots.get(element);
|
|
22
|
+
if (!snapshot) {
|
|
23
|
+
snapshot = /* @__PURE__ */ new Map();
|
|
24
|
+
snapshots.set(element, snapshot);
|
|
25
|
+
}
|
|
26
|
+
attributes.forEach((attribute) => {
|
|
27
|
+
snapshot.set(attribute, element.getAttribute(attribute));
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
1
32
|
// node_modules/power-focusable/dist/index.js
|
|
2
33
|
var FOCUSABLE_SELECTOR = `:is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])`;
|
|
3
34
|
function getFocusables(container = document.body, options = {}) {
|
|
@@ -294,7 +325,6 @@ var Portal = class {
|
|
|
294
325
|
#entranceSentinel;
|
|
295
326
|
#exitSentinel;
|
|
296
327
|
#focusables = /* @__PURE__ */ new Set();
|
|
297
|
-
#tabIndexes = /* @__PURE__ */ new Map();
|
|
298
328
|
#controller = null;
|
|
299
329
|
#isDestroyed = false;
|
|
300
330
|
constructor(host, container) {
|
|
@@ -311,16 +341,8 @@ var Portal = class {
|
|
|
311
341
|
this.#isDestroyed = true;
|
|
312
342
|
this.#controller?.abort();
|
|
313
343
|
this.#controller = null;
|
|
314
|
-
this.#focusables
|
|
315
|
-
const index = this.#tabIndexes.get(focusable);
|
|
316
|
-
if (index == null) {
|
|
317
|
-
focusable.removeAttribute("tabindex");
|
|
318
|
-
} else {
|
|
319
|
-
focusable.setAttribute("tabindex", index);
|
|
320
|
-
}
|
|
321
|
-
});
|
|
344
|
+
restoreAttributes([...this.#focusables]);
|
|
322
345
|
this.#focusables.clear();
|
|
323
|
-
this.#tabIndexes.clear();
|
|
324
346
|
this.#exitSentinel.after(this.#host);
|
|
325
347
|
this.#entranceSentinel.remove();
|
|
326
348
|
this.#exitSentinel.remove();
|
|
@@ -368,7 +390,8 @@ var Portal = class {
|
|
|
368
390
|
}
|
|
369
391
|
};
|
|
370
392
|
#onKeyDown = (event) => {
|
|
371
|
-
|
|
393
|
+
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
394
|
+
if (key !== "Tab" || altKey || ctrlKey || metaKey) {
|
|
372
395
|
return;
|
|
373
396
|
}
|
|
374
397
|
const active = getActiveElement2();
|
|
@@ -382,7 +405,7 @@ var Portal = class {
|
|
|
382
405
|
const focusables = this.#getFocusables();
|
|
383
406
|
if (!focusables.length) {
|
|
384
407
|
event.preventDefault();
|
|
385
|
-
this.#focusSentinel(
|
|
408
|
+
this.#focusSentinel(shiftKey);
|
|
386
409
|
return;
|
|
387
410
|
}
|
|
388
411
|
const index = focusables.indexOf(active);
|
|
@@ -390,11 +413,11 @@ var Portal = class {
|
|
|
390
413
|
return;
|
|
391
414
|
}
|
|
392
415
|
event.preventDefault();
|
|
393
|
-
const focusable = focusables[index + (
|
|
416
|
+
const focusable = focusables[index + (shiftKey ? -1 : 1)];
|
|
394
417
|
if (focusable) {
|
|
395
418
|
focusElement(focusable);
|
|
396
419
|
} else {
|
|
397
|
-
this.#focusSentinel(
|
|
420
|
+
this.#focusSentinel(shiftKey);
|
|
398
421
|
}
|
|
399
422
|
};
|
|
400
423
|
#update() {
|
|
@@ -407,22 +430,16 @@ var Portal = class {
|
|
|
407
430
|
return;
|
|
408
431
|
}
|
|
409
432
|
if (focusable.isConnected) {
|
|
410
|
-
|
|
411
|
-
if (index == null) {
|
|
412
|
-
focusable.removeAttribute("tabindex");
|
|
413
|
-
} else {
|
|
414
|
-
focusable.setAttribute("tabindex", index);
|
|
415
|
-
}
|
|
433
|
+
restoreAttributes([focusable]);
|
|
416
434
|
}
|
|
417
435
|
this.#focusables.delete(focusable);
|
|
418
|
-
this.#tabIndexes.delete(focusable);
|
|
419
436
|
});
|
|
420
437
|
current.forEach((c) => {
|
|
421
438
|
if (this.#focusables.has(c)) {
|
|
422
439
|
return;
|
|
423
440
|
}
|
|
424
441
|
this.#focusables.add(c);
|
|
425
|
-
|
|
442
|
+
saveAttributes([c], ["tabindex"]);
|
|
426
443
|
c.setAttribute("tabindex", "-1");
|
|
427
444
|
});
|
|
428
445
|
}
|
|
@@ -479,7 +496,7 @@ function getActiveElement2() {
|
|
|
479
496
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
480
497
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
481
498
|
*
|
|
482
|
-
* @version 1.2.
|
|
499
|
+
* @version 1.2.4
|
|
483
500
|
* @author Yusuke Kamiyamane
|
|
484
501
|
* @license MIT
|
|
485
502
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -487,6 +504,17 @@ function getActiveElement2() {
|
|
|
487
504
|
*/
|
|
488
505
|
/*! Bundled license information:
|
|
489
506
|
|
|
507
|
+
@y14e/attributes-utils/dist/index.js:
|
|
508
|
+
(**
|
|
509
|
+
* Attributes Utils
|
|
510
|
+
*
|
|
511
|
+
* @version 1.0.0
|
|
512
|
+
* @author Yusuke Kamiyamane
|
|
513
|
+
* @license MIT
|
|
514
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
515
|
+
* @see {@link https://github.com/y14e/attributes-utils}
|
|
516
|
+
*)
|
|
517
|
+
|
|
490
518
|
power-focusable/dist/index.js:
|
|
491
519
|
(**
|
|
492
520
|
* Power Focusable
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/portal",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "Lightweight DOM portal (teleport) utility with fully focus management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"homepage": "https://github.com/y14e/portal#readme",
|
|
49
49
|
"devDependencies": {
|
|
50
|
+
"@y14e/attributes-utils": "^1.0.0",
|
|
50
51
|
"bun-types": "latest",
|
|
51
52
|
"power-focusable": "^4.1.5",
|
|
52
53
|
"tsup": "^8.0.0",
|