@y14e/portal 1.3.8 → 1.4.0
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 +1 -1
- package/dist/index.bundle.js +1 -1
- package/dist/index.cjs +14 -35
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -14
- package/package.json +1 -1
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.
|
|
16
|
+
import { createPortal } from 'https://esm.sh/@y14e/portal@1.4.0';
|
|
17
17
|
// or
|
|
18
|
-
import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.
|
|
18
|
+
import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.4.0/+esm';
|
|
19
19
|
// or
|
|
20
|
-
import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.
|
|
20
|
+
import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.4.0';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 📦 APIs
|
package/dist/index.bundle.cjs
CHANGED
|
@@ -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.
|
|
540
|
+
* @version 1.4.0
|
|
541
541
|
* @author Yusuke Kamiyamane
|
|
542
542
|
* @license MIT
|
|
543
543
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.bundle.js
CHANGED
|
@@ -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.
|
|
538
|
+
* @version 1.4.0
|
|
539
539
|
* @author Yusuke Kamiyamane
|
|
540
540
|
* @license MIT
|
|
541
541
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.cjs
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
function _interopNamespace(e) {
|
|
7
|
-
if (e && e.__esModule) return e;
|
|
8
|
-
var n = Object.create(null);
|
|
9
|
-
if (e) {
|
|
10
|
-
Object.keys(e).forEach(function (k) {
|
|
11
|
-
if (k !== 'default') {
|
|
12
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () { return e[k]; }
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
n.default = e;
|
|
21
|
-
return Object.freeze(n);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
var utils__namespace = /*#__PURE__*/_interopNamespace(utils);
|
|
25
|
-
var pf__namespace = /*#__PURE__*/_interopNamespace(pf);
|
|
3
|
+
var attributeUtils = require('@y14e/attribute-utils');
|
|
4
|
+
var powerFocusable = require('power-focusable');
|
|
26
5
|
|
|
27
6
|
// src/index.ts
|
|
28
7
|
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;";
|
|
@@ -73,7 +52,7 @@ var Portal = class {
|
|
|
73
52
|
this.#isDestroyed = true;
|
|
74
53
|
this.#controller?.abort();
|
|
75
54
|
this.#controller = null;
|
|
76
|
-
|
|
55
|
+
attributeUtils.restoreAttributes([...this.#focusables]);
|
|
77
56
|
this.#focusables.clear();
|
|
78
57
|
this.#exitSentinel.after(this.#host);
|
|
79
58
|
this.#entranceSentinel.remove();
|
|
@@ -105,7 +84,7 @@ var Portal = class {
|
|
|
105
84
|
}
|
|
106
85
|
this.#update();
|
|
107
86
|
const first = [...this.#focusables][0];
|
|
108
|
-
first ?
|
|
87
|
+
first ? powerFocusable.focusElement(first) : this.#moveFocus("next");
|
|
109
88
|
} else {
|
|
110
89
|
if (this.#host.contains(previous)) {
|
|
111
90
|
this.#moveFocus("next");
|
|
@@ -113,7 +92,7 @@ var Portal = class {
|
|
|
113
92
|
}
|
|
114
93
|
this.#update();
|
|
115
94
|
const last = [...this.#focusables].at(-1);
|
|
116
|
-
last ?
|
|
95
|
+
last ? powerFocusable.focusElement(last) : this.#moveFocus("previous");
|
|
117
96
|
}
|
|
118
97
|
};
|
|
119
98
|
#onKeyDown = (event) => {
|
|
@@ -124,7 +103,7 @@ var Portal = class {
|
|
|
124
103
|
if (key !== "Tab" || altKey || ctrlKey || metaKey) {
|
|
125
104
|
return;
|
|
126
105
|
}
|
|
127
|
-
const active =
|
|
106
|
+
const active = powerFocusable.getActiveElement();
|
|
128
107
|
if (!(active instanceof Element)) {
|
|
129
108
|
return;
|
|
130
109
|
}
|
|
@@ -135,7 +114,7 @@ var Portal = class {
|
|
|
135
114
|
if (index >= 0) {
|
|
136
115
|
event.preventDefault();
|
|
137
116
|
const focusable = focusables[index + (shiftKey ? -1 : 1)];
|
|
138
|
-
focusable ?
|
|
117
|
+
focusable ? powerFocusable.focusElement(focusable) : this.#focusSentinel(shiftKey);
|
|
139
118
|
}
|
|
140
119
|
} else {
|
|
141
120
|
event.preventDefault();
|
|
@@ -145,18 +124,18 @@ var Portal = class {
|
|
|
145
124
|
#update() {
|
|
146
125
|
const current = /* @__PURE__ */ new Set([
|
|
147
126
|
...this.#getFocusables(),
|
|
148
|
-
...
|
|
127
|
+
...powerFocusable.getFocusables(this.#host, { composed: true })
|
|
149
128
|
]);
|
|
150
129
|
for (const focusable of this.#focusables) {
|
|
151
130
|
if (!current.has(focusable)) {
|
|
152
|
-
|
|
131
|
+
attributeUtils.restoreAttributes(focusable);
|
|
153
132
|
this.#focusables.delete(focusable);
|
|
154
133
|
}
|
|
155
134
|
}
|
|
156
135
|
for (const focusable of current) {
|
|
157
136
|
if (!this.#focusables.has(focusable)) {
|
|
158
137
|
this.#focusables.add(focusable);
|
|
159
|
-
|
|
138
|
+
attributeUtils.saveAttributes(focusable, "tabindex");
|
|
160
139
|
focusable.setAttribute("tabindex", "-1");
|
|
161
140
|
}
|
|
162
141
|
}
|
|
@@ -175,7 +154,7 @@ var Portal = class {
|
|
|
175
154
|
(isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
|
|
176
155
|
}
|
|
177
156
|
#getFocusables() {
|
|
178
|
-
return
|
|
157
|
+
return powerFocusable.getFocusables(this.#host, {
|
|
179
158
|
composed: true,
|
|
180
159
|
include: (element) => this.#focusables.has(element)
|
|
181
160
|
});
|
|
@@ -185,8 +164,8 @@ var Portal = class {
|
|
|
185
164
|
anchor: direction === "previous" ? this.#entranceSentinel : this.#exitSentinel,
|
|
186
165
|
composed: true
|
|
187
166
|
};
|
|
188
|
-
const focusable = direction === "previous" ?
|
|
189
|
-
focusable &&
|
|
167
|
+
const focusable = direction === "previous" ? powerFocusable.getPreviousFocusable(document.body, options) : powerFocusable.getNextFocusable(document.body, options);
|
|
168
|
+
focusable && powerFocusable.focusElement(focusable);
|
|
190
169
|
}
|
|
191
170
|
};
|
|
192
171
|
function containsComposed(container, element) {
|
|
@@ -212,7 +191,7 @@ function resolveOptions(options) {
|
|
|
212
191
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
213
192
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
214
193
|
*
|
|
215
|
-
* @version 1.
|
|
194
|
+
* @version 1.4.0
|
|
216
195
|
* @author Yusuke Kamiyamane
|
|
217
196
|
* @license MIT
|
|
218
197
|
* @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.
|
|
6
|
+
* @version 1.4.0
|
|
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.
|
|
6
|
+
* @version 1.4.0
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { restoreAttributes, saveAttributes } from '@y14e/attribute-utils';
|
|
2
|
+
import { focusElement, getActiveElement, getFocusables, getPreviousFocusable, getNextFocusable } from 'power-focusable';
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
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;";
|
|
@@ -50,7 +50,7 @@ var Portal = class {
|
|
|
50
50
|
this.#isDestroyed = true;
|
|
51
51
|
this.#controller?.abort();
|
|
52
52
|
this.#controller = null;
|
|
53
|
-
|
|
53
|
+
restoreAttributes([...this.#focusables]);
|
|
54
54
|
this.#focusables.clear();
|
|
55
55
|
this.#exitSentinel.after(this.#host);
|
|
56
56
|
this.#entranceSentinel.remove();
|
|
@@ -82,7 +82,7 @@ var Portal = class {
|
|
|
82
82
|
}
|
|
83
83
|
this.#update();
|
|
84
84
|
const first = [...this.#focusables][0];
|
|
85
|
-
first ?
|
|
85
|
+
first ? focusElement(first) : this.#moveFocus("next");
|
|
86
86
|
} else {
|
|
87
87
|
if (this.#host.contains(previous)) {
|
|
88
88
|
this.#moveFocus("next");
|
|
@@ -90,7 +90,7 @@ var Portal = class {
|
|
|
90
90
|
}
|
|
91
91
|
this.#update();
|
|
92
92
|
const last = [...this.#focusables].at(-1);
|
|
93
|
-
last ?
|
|
93
|
+
last ? focusElement(last) : this.#moveFocus("previous");
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
#onKeyDown = (event) => {
|
|
@@ -101,7 +101,7 @@ var Portal = class {
|
|
|
101
101
|
if (key !== "Tab" || altKey || ctrlKey || metaKey) {
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
|
-
const active =
|
|
104
|
+
const active = getActiveElement();
|
|
105
105
|
if (!(active instanceof Element)) {
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
@@ -112,7 +112,7 @@ var Portal = class {
|
|
|
112
112
|
if (index >= 0) {
|
|
113
113
|
event.preventDefault();
|
|
114
114
|
const focusable = focusables[index + (shiftKey ? -1 : 1)];
|
|
115
|
-
focusable ?
|
|
115
|
+
focusable ? focusElement(focusable) : this.#focusSentinel(shiftKey);
|
|
116
116
|
}
|
|
117
117
|
} else {
|
|
118
118
|
event.preventDefault();
|
|
@@ -122,18 +122,18 @@ var Portal = class {
|
|
|
122
122
|
#update() {
|
|
123
123
|
const current = /* @__PURE__ */ new Set([
|
|
124
124
|
...this.#getFocusables(),
|
|
125
|
-
...
|
|
125
|
+
...getFocusables(this.#host, { composed: true })
|
|
126
126
|
]);
|
|
127
127
|
for (const focusable of this.#focusables) {
|
|
128
128
|
if (!current.has(focusable)) {
|
|
129
|
-
|
|
129
|
+
restoreAttributes(focusable);
|
|
130
130
|
this.#focusables.delete(focusable);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
for (const focusable of current) {
|
|
134
134
|
if (!this.#focusables.has(focusable)) {
|
|
135
135
|
this.#focusables.add(focusable);
|
|
136
|
-
|
|
136
|
+
saveAttributes(focusable, "tabindex");
|
|
137
137
|
focusable.setAttribute("tabindex", "-1");
|
|
138
138
|
}
|
|
139
139
|
}
|
|
@@ -152,7 +152,7 @@ var Portal = class {
|
|
|
152
152
|
(isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
|
|
153
153
|
}
|
|
154
154
|
#getFocusables() {
|
|
155
|
-
return
|
|
155
|
+
return getFocusables(this.#host, {
|
|
156
156
|
composed: true,
|
|
157
157
|
include: (element) => this.#focusables.has(element)
|
|
158
158
|
});
|
|
@@ -162,8 +162,8 @@ var Portal = class {
|
|
|
162
162
|
anchor: direction === "previous" ? this.#entranceSentinel : this.#exitSentinel,
|
|
163
163
|
composed: true
|
|
164
164
|
};
|
|
165
|
-
const focusable = direction === "previous" ?
|
|
166
|
-
focusable &&
|
|
165
|
+
const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
|
|
166
|
+
focusable && focusElement(focusable);
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
169
|
function containsComposed(container, element) {
|
|
@@ -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.
|
|
192
|
+
* @version 1.4.0
|
|
193
193
|
* @author Yusuke Kamiyamane
|
|
194
194
|
* @license MIT
|
|
195
195
|
* @copyright Copyright (c) Yusuke Kamiyamane
|