@react-aria/landmark 3.0.0-alpha.3 → 3.0.0-alpha.5
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/main.js +57 -47
- package/dist/main.js.map +1 -1
- package/dist/module.js +54 -47
- package/dist/module.js.map +1 -1
- package/package.json +6 -6
package/dist/main.js
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
|
+
var $8Ore6$swchelperslib_define_propertyjs = require("@swc/helpers/lib/_define_property.js");
|
|
1
2
|
var $8Ore6$react = require("react");
|
|
2
3
|
var $8Ore6$reactariautils = require("@react-aria/utils");
|
|
3
4
|
|
|
4
5
|
function $parcel$export(e, n, v, s) {
|
|
5
6
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
7
|
}
|
|
8
|
+
function $parcel$interopDefault(a) {
|
|
9
|
+
return a && a.__esModule ? a.default : a;
|
|
10
|
+
}
|
|
7
11
|
|
|
8
12
|
$parcel$export(module.exports, "useLandmark", () => $202c109aedff6705$export$4cc632584fd87fae);
|
|
13
|
+
/*
|
|
14
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
15
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
16
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
17
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
20
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
21
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
22
|
+
* governing permissions and limitations under the License.
|
|
23
|
+
*/ /*
|
|
24
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
25
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
26
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
27
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
28
|
+
*
|
|
29
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
30
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
31
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
32
|
+
* governing permissions and limitations under the License.
|
|
33
|
+
*/
|
|
9
34
|
|
|
10
35
|
|
|
11
36
|
class $202c109aedff6705$var$LandmarkManager {
|
|
@@ -14,52 +39,47 @@ class $202c109aedff6705$var$LandmarkManager {
|
|
|
14
39
|
return $202c109aedff6705$var$LandmarkManager.instance;
|
|
15
40
|
}
|
|
16
41
|
setup() {
|
|
17
|
-
document.addEventListener(
|
|
42
|
+
document.addEventListener("keydown", this.f6Handler, {
|
|
18
43
|
capture: true
|
|
19
44
|
});
|
|
20
|
-
document.addEventListener(
|
|
45
|
+
document.addEventListener("focusin", this.focusinHandler, {
|
|
21
46
|
capture: true
|
|
22
47
|
});
|
|
23
|
-
document.addEventListener(
|
|
48
|
+
document.addEventListener("focusout", this.focusoutHandler, {
|
|
24
49
|
capture: true
|
|
25
50
|
});
|
|
26
51
|
this.isListening = true;
|
|
27
52
|
}
|
|
28
53
|
teardown() {
|
|
29
|
-
document.removeEventListener(
|
|
54
|
+
document.removeEventListener("keydown", this.f6Handler, {
|
|
30
55
|
capture: true
|
|
31
56
|
});
|
|
32
|
-
document.removeEventListener(
|
|
57
|
+
document.removeEventListener("focusin", this.focusinHandler, {
|
|
33
58
|
capture: true
|
|
34
59
|
});
|
|
35
|
-
document.removeEventListener(
|
|
60
|
+
document.removeEventListener("focusout", this.focusoutHandler, {
|
|
36
61
|
capture: true
|
|
37
62
|
});
|
|
38
63
|
this.isListening = false;
|
|
39
64
|
}
|
|
40
65
|
focusLandmark(landmark) {
|
|
41
|
-
var
|
|
42
|
-
(
|
|
43
|
-
)) === null || ref === void 0 ? void 0 : ref.focus();
|
|
66
|
+
var _this_landmarks_find;
|
|
67
|
+
(_this_landmarks_find = this.landmarks.find((l)=>l.ref.current === landmark)) === null || _this_landmarks_find === void 0 ? void 0 : _this_landmarks_find.focus();
|
|
44
68
|
}
|
|
45
69
|
/**
|
|
46
70
|
* Return set of landmarks with a specific role.
|
|
47
71
|
*/ getLandmarksByRole(role) {
|
|
48
|
-
return new Set(this.landmarks.filter((l)=>l.role === role
|
|
49
|
-
));
|
|
72
|
+
return new Set(this.landmarks.filter((l)=>l.role === role));
|
|
50
73
|
}
|
|
51
74
|
/**
|
|
52
75
|
* Return first landmark with a specific role.
|
|
53
76
|
*/ getLandmarkByRole(role) {
|
|
54
|
-
return this.landmarks.find((l)=>l.role === role
|
|
55
|
-
);
|
|
77
|
+
return this.landmarks.find((l)=>l.role === role);
|
|
56
78
|
}
|
|
57
79
|
addLandmark(newLandmark) {
|
|
58
80
|
if (!this.isListening) this.setup();
|
|
59
|
-
if (this.landmarks.find((landmark)=>landmark.ref === newLandmark.ref
|
|
60
|
-
))
|
|
61
|
-
if (this.landmarks.filter((landmark)=>landmark.role === 'main'
|
|
62
|
-
).length > 1) console.error('Page can contain no more than one landmark with the role "main".');
|
|
81
|
+
if (this.landmarks.find((landmark)=>landmark.ref === newLandmark.ref)) return;
|
|
82
|
+
if (this.landmarks.filter((landmark)=>landmark.role === "main").length > 1) console.error('Page can contain no more than one landmark with the role "main".');
|
|
63
83
|
if (this.landmarks.length === 0) {
|
|
64
84
|
this.landmarks = [
|
|
65
85
|
newLandmark
|
|
@@ -80,8 +100,7 @@ class $202c109aedff6705$var$LandmarkManager {
|
|
|
80
100
|
this.landmarks.splice(start, 0, newLandmark);
|
|
81
101
|
}
|
|
82
102
|
updateLandmark(landmark) {
|
|
83
|
-
let index = this.landmarks.findIndex((l)=>l.ref === landmark.ref
|
|
84
|
-
);
|
|
103
|
+
let index = this.landmarks.findIndex((l)=>l.ref === landmark.ref);
|
|
85
104
|
if (index >= 0) {
|
|
86
105
|
this.landmarks[index] = {
|
|
87
106
|
...this.landmarks[index],
|
|
@@ -91,8 +110,7 @@ class $202c109aedff6705$var$LandmarkManager {
|
|
|
91
110
|
}
|
|
92
111
|
}
|
|
93
112
|
removeLandmark(ref) {
|
|
94
|
-
this.landmarks = this.landmarks.filter((landmark)=>landmark.ref !== ref
|
|
95
|
-
);
|
|
113
|
+
this.landmarks = this.landmarks.filter((landmark)=>landmark.ref !== ref);
|
|
96
114
|
if (this.landmarks.length === 0) this.teardown();
|
|
97
115
|
}
|
|
98
116
|
/**
|
|
@@ -105,23 +123,17 @@ class $202c109aedff6705$var$LandmarkManager {
|
|
|
105
123
|
if (landmarksWithRole.size > 1) {
|
|
106
124
|
let duplicatesWithoutLabel = [
|
|
107
125
|
...landmarksWithRole
|
|
108
|
-
].filter((landmark)=>!landmark.label
|
|
109
|
-
);
|
|
110
|
-
if (duplicatesWithoutLabel.length > 0) console.warn(`Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute: `, duplicatesWithoutLabel.map((landmark)=>landmark.ref.current
|
|
111
|
-
));
|
|
126
|
+
].filter((landmark)=>!landmark.label);
|
|
127
|
+
if (duplicatesWithoutLabel.length > 0) console.warn(`Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute: `, duplicatesWithoutLabel.map((landmark)=>landmark.ref.current));
|
|
112
128
|
else {
|
|
113
129
|
let labels = [
|
|
114
130
|
...landmarksWithRole
|
|
115
|
-
].map((landmark)=>landmark.label
|
|
116
|
-
);
|
|
117
|
-
let duplicateLabels = labels.filter((item, index)=>labels.indexOf(item) !== index
|
|
118
|
-
);
|
|
131
|
+
].map((landmark)=>landmark.label);
|
|
132
|
+
let duplicateLabels = labels.filter((item, index)=>labels.indexOf(item) !== index);
|
|
119
133
|
duplicateLabels.forEach((label)=>{
|
|
120
134
|
console.warn(`Page contains more than one landmark with the '${role}' role and '${label}' label. If two or more landmarks on a page share the same role, they must have unique labels: `, [
|
|
121
135
|
...landmarksWithRole
|
|
122
|
-
].filter((landmark)=>landmark.label === label
|
|
123
|
-
).map((landmark)=>landmark.ref.current
|
|
124
|
-
));
|
|
136
|
+
].filter((landmark)=>landmark.label === label).map((landmark)=>landmark.ref.current));
|
|
125
137
|
});
|
|
126
138
|
}
|
|
127
139
|
}
|
|
@@ -133,8 +145,7 @@ class $202c109aedff6705$var$LandmarkManager {
|
|
|
133
145
|
let landmarkMap = new Map(this.landmarks.map((l)=>[
|
|
134
146
|
l.ref.current,
|
|
135
147
|
l
|
|
136
|
-
]
|
|
137
|
-
));
|
|
148
|
+
]));
|
|
138
149
|
let currentElement = element;
|
|
139
150
|
while(!landmarkMap.has(currentElement) && currentElement !== document.body)currentElement = currentElement.parentElement;
|
|
140
151
|
return landmarkMap.get(currentElement);
|
|
@@ -148,8 +159,7 @@ class $202c109aedff6705$var$LandmarkManager {
|
|
|
148
159
|
if (this.landmarks.length === 0) return undefined;
|
|
149
160
|
let currentLandmark = this.closestLandmark(element);
|
|
150
161
|
let nextLandmarkIndex = backward ? -1 : 0;
|
|
151
|
-
if (currentLandmark) nextLandmarkIndex = this.landmarks.findIndex((landmark)=>landmark === currentLandmark
|
|
152
|
-
) + (backward ? -1 : 1);
|
|
162
|
+
if (currentLandmark) nextLandmarkIndex = this.landmarks.findIndex((landmark)=>landmark === currentLandmark) + (backward ? -1 : 1);
|
|
153
163
|
// Wrap if necessary
|
|
154
164
|
if (nextLandmarkIndex < 0) nextLandmarkIndex = this.landmarks.length - 1;
|
|
155
165
|
else if (nextLandmarkIndex >= this.landmarks.length) nextLandmarkIndex = 0;
|
|
@@ -160,7 +170,7 @@ class $202c109aedff6705$var$LandmarkManager {
|
|
|
160
170
|
* If not, focus the landmark itself.
|
|
161
171
|
* If no landmarks at all, or none with focusable elements, don't move focus.
|
|
162
172
|
*/ f6Handler(e) {
|
|
163
|
-
if (e.key ===
|
|
173
|
+
if (e.key === "F6") {
|
|
164
174
|
e.preventDefault();
|
|
165
175
|
e.stopPropagation();
|
|
166
176
|
let backward = e.shiftKey;
|
|
@@ -171,7 +181,7 @@ class $202c109aedff6705$var$LandmarkManager {
|
|
|
171
181
|
if (!nextLandmark) return;
|
|
172
182
|
// If alt key pressed, focus main landmark
|
|
173
183
|
if (e.altKey) {
|
|
174
|
-
let main = this.getLandmarkByRole(
|
|
184
|
+
let main = this.getLandmarkByRole("main");
|
|
175
185
|
if (main && document.contains(main.ref.current)) this.focusLandmark(main.ref.current);
|
|
176
186
|
return;
|
|
177
187
|
}
|
|
@@ -215,29 +225,29 @@ class $202c109aedff6705$var$LandmarkManager {
|
|
|
215
225
|
}
|
|
216
226
|
}
|
|
217
227
|
constructor(){
|
|
218
|
-
this
|
|
219
|
-
this
|
|
228
|
+
(0, ($parcel$interopDefault($8Ore6$swchelperslib_define_propertyjs)))(this, "landmarks", []);
|
|
229
|
+
(0, ($parcel$interopDefault($8Ore6$swchelperslib_define_propertyjs)))(this, "isListening", false);
|
|
220
230
|
this.f6Handler = this.f6Handler.bind(this);
|
|
221
231
|
this.focusinHandler = this.focusinHandler.bind(this);
|
|
222
232
|
this.focusoutHandler = this.focusoutHandler.bind(this);
|
|
223
233
|
}
|
|
224
234
|
}
|
|
225
235
|
function $202c109aedff6705$export$4cc632584fd87fae(props, ref) {
|
|
226
|
-
const { role: role ,
|
|
236
|
+
const { role: role , "aria-label": ariaLabel , "aria-labelledby": ariaLabelledby } = props;
|
|
227
237
|
let manager = $202c109aedff6705$var$LandmarkManager.getInstance();
|
|
228
238
|
let label = ariaLabel || ariaLabelledby;
|
|
229
|
-
let [isLandmarkFocused, setIsLandmarkFocused] = $8Ore6$react.useState(false);
|
|
230
|
-
let focus = $8Ore6$react.useCallback(()=>{
|
|
239
|
+
let [isLandmarkFocused, setIsLandmarkFocused] = (0, $8Ore6$react.useState)(false);
|
|
240
|
+
let focus = (0, $8Ore6$react.useCallback)(()=>{
|
|
231
241
|
setIsLandmarkFocused(true);
|
|
232
242
|
}, [
|
|
233
243
|
setIsLandmarkFocused
|
|
234
244
|
]);
|
|
235
|
-
let blur = $8Ore6$react.useCallback(()=>{
|
|
245
|
+
let blur = (0, $8Ore6$react.useCallback)(()=>{
|
|
236
246
|
setIsLandmarkFocused(false);
|
|
237
247
|
}, [
|
|
238
248
|
setIsLandmarkFocused
|
|
239
249
|
]);
|
|
240
|
-
$8Ore6$reactariautils.useLayoutEffect(()=>{
|
|
250
|
+
(0, $8Ore6$reactariautils.useLayoutEffect)(()=>{
|
|
241
251
|
manager.addLandmark({
|
|
242
252
|
ref: ref,
|
|
243
253
|
role: role,
|
|
@@ -250,7 +260,7 @@ function $202c109aedff6705$export$4cc632584fd87fae(props, ref) {
|
|
|
250
260
|
};
|
|
251
261
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
252
262
|
}, []);
|
|
253
|
-
$8Ore6$reactariautils.useLayoutEffect(()=>{
|
|
263
|
+
(0, $8Ore6$reactariautils.useLayoutEffect)(()=>{
|
|
254
264
|
manager.updateLandmark({
|
|
255
265
|
ref: ref,
|
|
256
266
|
label: label,
|
|
@@ -264,7 +274,7 @@ function $202c109aedff6705$export$4cc632584fd87fae(props, ref) {
|
|
|
264
274
|
ref,
|
|
265
275
|
role
|
|
266
276
|
]);
|
|
267
|
-
$8Ore6$react.useEffect(()=>{
|
|
277
|
+
(0, $8Ore6$react.useEffect)(()=>{
|
|
268
278
|
if (isLandmarkFocused) ref.current.focus();
|
|
269
279
|
}, [
|
|
270
280
|
isLandmarkFocused,
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;MCmCM,qCAAe;WAWL,WAAW,GAAoB,CAAC;QAC5C,EAAE,GAAG,qCAAe,CAAC,QAAQ,EAC3B,qCAAe,CAAC,QAAQ,GAAG,GAAG,CAAC,qCAAe;QAGhD,MAAM,CAAC,qCAAe,CAAC,QAAQ;IACjC,CAAC;IAEO,KAAK,GAAG,CAAC;QACf,QAAQ,CAAC,gBAAgB,CAAC,CAAS,UAAE,IA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AE,oBAAoB,IAAI,qBAAQ,CAAC,KAAK;IAE9D,GAAG,CAAC,KAAK,GAAG,wBAAW,KAAO,CAAC;QAC7B,oBAAoB,CAAC,IAAI;IAC3B,CAAC,EAAE,CAAC;QAAA,oBAAoB;IAAA,CAAC;IAEzB,GAAG,CAAC,IAAI,GAAG,wBAAW,KAAO,CAAC;QAC5B,oBAAoB,CAAC,KAAK;IAC5B,CAAC,EAAE,CAAC;QAAA,oBAAoB;IAAA,CAAC;IAEzB,qCAAe,KAAO,CAAC;QACrB,OAAO,CAAC,WAAW,CAAC,CAAC;iBAAA,GAAG;kBAAE,IAAI;mBAAE,KAAK;mBAAE,KAAK;kBAAE,IAAI;QAAA,CAAC;QAEnD,MAAM,KAAO,CAAC;YACZ,OAAO,CAAC,cAAc,CAAC,GAAG;QAC5B,CAAC;IACH,EAAuD,AAAvD,qDAAuD;IACvD,CAAC,EAAE,CAAC,CAAC;IAEL,qCAAe,KAAO,CAAC;QACrB,OAAO,CAAC,cAAc,CAAC,CAAC;iBAAA,GAAG;mBAAE,KAAK;kBAAE,IAAI;mBAAE,KAAK;kBAAE,IAAI;QAAA,CAAC;IACxD,EAAuD,AAAvD,qDAAuD;IACvD,CAAC,EAAE,CAAC;QAAA,KAAK;QAAE,GAAG;QAAE,IAAI;IAAA,CAAC;IAErB,sBAAS,KAAO,CAAC;QACf,EAAE,EAAE,iBAAiB,EACnB,GAAG,CAAC,OAAO,CAAC,KAAK;IAErB,CAAC,EAAE,CAAC;QAAA,iBAAiB;QAAE,GAAG;IAAA,CAAC;IAE3B,MAAM,CAAC,CAAC;QACN,aAAa,EAAE,CAAC;kBACd,IAAI;YACJ,QAAQ,EAAE,iBAAiB,GAAG,EAAE,GAAG,SAAS;QAC9C,CAAC;IACH,CAAC;AACH,CAAC","sources":["packages/@react-aria/landmark/src/index.ts","packages/@react-aria/landmark/src/useLandmark.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {AriaLandmarkRole, AriaLandmarkProps, LandmarkAria} from './useLandmark';\nexport {useLandmark} from './useLandmark';\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {MutableRefObject, useCallback, useEffect, useState} from 'react';\nimport {useLayoutEffect} from '@react-aria/utils';\n\nexport type AriaLandmarkRole = 'main' | 'region' | 'search' | 'navigation' | 'form' | 'banner' | 'contentinfo' | 'complementary';\n\nexport interface AriaLandmarkProps extends AriaLabelingProps {\n role: AriaLandmarkRole\n}\n\nexport interface LandmarkAria {\n landmarkProps: DOMAttributes\n}\n\ntype Landmark = {\n ref: MutableRefObject<Element>,\n role: AriaLandmarkRole,\n label?: string,\n lastFocused?: FocusableElement,\n focus: () => void,\n blur: () => void\n};\n\nclass LandmarkManager {\n private landmarks: Array<Landmark> = [];\n private static instance: LandmarkManager;\n private isListening = false;\n\n private constructor() {\n this.f6Handler = this.f6Handler.bind(this);\n this.focusinHandler = this.focusinHandler.bind(this);\n this.focusoutHandler = this.focusoutHandler.bind(this);\n }\n\n public static getInstance(): LandmarkManager {\n if (!LandmarkManager.instance) {\n LandmarkManager.instance = new LandmarkManager();\n }\n\n return LandmarkManager.instance;\n }\n\n private setup() {\n document.addEventListener('keydown', this.f6Handler, {capture: true});\n document.addEventListener('focusin', this.focusinHandler, {capture: true});\n document.addEventListener('focusout', this.focusoutHandler, {capture: true});\n this.isListening = true;\n }\n\n private teardown() {\n document.removeEventListener('keydown', this.f6Handler, {capture: true});\n document.removeEventListener('focusin', this.focusinHandler, {capture: true});\n document.removeEventListener('focusout', this.focusoutHandler, {capture: true});\n this.isListening = false;\n }\n\n private focusLandmark(landmark: Element) {\n this.landmarks.find(l => l.ref.current === landmark)?.focus();\n }\n\n /**\n * Return set of landmarks with a specific role.\n */\n public getLandmarksByRole(role: AriaLandmarkRole) {\n return new Set(this.landmarks.filter(l => l.role === role));\n }\n\n /**\n * Return first landmark with a specific role.\n */\n public getLandmarkByRole(role: AriaLandmarkRole) {\n return this.landmarks.find(l => l.role === role);\n }\n\n public addLandmark(newLandmark: Landmark) {\n if (!this.isListening) {\n this.setup();\n }\n if (this.landmarks.find(landmark => landmark.ref === newLandmark.ref)) {\n return;\n }\n\n if (this.landmarks.filter(landmark => landmark.role === 'main').length > 1) {\n console.error('Page can contain no more than one landmark with the role \"main\".');\n }\n\n if (this.landmarks.length === 0) {\n this.landmarks = [newLandmark];\n return;\n }\n\n\n // Binary search to insert new landmark based on position in document relative to existing landmarks.\n // https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition\n let start = 0;\n let end = this.landmarks.length - 1;\n while (start <= end) {\n let mid = Math.floor((start + end) / 2);\n let comparedPosition = newLandmark.ref.current.compareDocumentPosition(this.landmarks[mid].ref.current as Node);\n let isNewAfterExisting = Boolean((comparedPosition & Node.DOCUMENT_POSITION_PRECEDING) || (comparedPosition & Node.DOCUMENT_POSITION_CONTAINS));\n\n if (isNewAfterExisting) {\n start = mid + 1;\n } else {\n end = mid - 1;\n }\n }\n\n this.landmarks.splice(start, 0, newLandmark);\n }\n\n public updateLandmark(landmark: Pick<Landmark, 'ref'> & Partial<Landmark>) {\n let index = this.landmarks.findIndex(l => l.ref === landmark.ref);\n if (index >= 0) {\n this.landmarks[index] = {...this.landmarks[index], ...landmark};\n this.checkLabels(this.landmarks[index].role);\n }\n }\n\n public removeLandmark(ref: MutableRefObject<Element>) {\n this.landmarks = this.landmarks.filter(landmark => landmark.ref !== ref);\n if (this.landmarks.length === 0) {\n this.teardown();\n }\n }\n\n /**\n * Warn if there are 2+ landmarks with the same role but no label.\n * Labels for landmarks with the same role must also be unique.\n *\n * See https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/.\n */\n private checkLabels(role: AriaLandmarkRole) {\n let landmarksWithRole = this.getLandmarksByRole(role);\n if (landmarksWithRole.size > 1) {\n let duplicatesWithoutLabel = [...landmarksWithRole].filter(landmark => !landmark.label);\n if (duplicatesWithoutLabel.length > 0) {\n console.warn(\n `Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute: `,\n duplicatesWithoutLabel.map(landmark => landmark.ref.current)\n );\n } else {\n let labels = [...landmarksWithRole].map(landmark => landmark.label);\n let duplicateLabels = labels.filter((item, index) => labels.indexOf(item) !== index);\n\n duplicateLabels.forEach((label) => {\n console.warn(\n `Page contains more than one landmark with the '${role}' role and '${label}' label. If two or more landmarks on a page share the same role, they must have unique labels: `,\n [...landmarksWithRole].filter(landmark => landmark.label === label).map(landmark => landmark.ref.current)\n );\n });\n }\n }\n }\n\n /**\n * Get the landmark that is the closest parent in the DOM.\n * Returns undefined if no parent is a landmark.\n */\n private closestLandmark(element: Element) {\n let landmarkMap = new Map(this.landmarks.map(l => [l.ref.current, l]));\n let currentElement = element;\n while (!landmarkMap.has(currentElement) && currentElement !== document.body) {\n currentElement = currentElement.parentElement;\n }\n return landmarkMap.get(currentElement);\n }\n\n /**\n * Gets the next landmark, in DOM focus order, or previous if backwards is specified.\n * If last landmark, next should be the first landmark.\n * If not inside a landmark, will return first landmark.\n * Returns undefined if there are no landmarks.\n */\n public getNextLandmark(element: Element, {backward}: {backward?: boolean }) {\n if (this.landmarks.length === 0) {\n return undefined;\n }\n\n let currentLandmark = this.closestLandmark(element);\n let nextLandmarkIndex = backward ? -1 : 0;\n if (currentLandmark) {\n nextLandmarkIndex = this.landmarks.findIndex(landmark => landmark === currentLandmark) + (backward ? -1 : 1);\n }\n\n // Wrap if necessary\n if (nextLandmarkIndex < 0) {\n nextLandmarkIndex = this.landmarks.length - 1;\n } else if (nextLandmarkIndex >= this.landmarks.length) {\n nextLandmarkIndex = 0;\n }\n\n return this.landmarks[nextLandmarkIndex];\n }\n\n /**\n * Look at next landmark. If an element was previously focused inside, restore focus there.\n * If not, focus the landmark itself.\n * If no landmarks at all, or none with focusable elements, don't move focus.\n */\n public f6Handler(e: KeyboardEvent) {\n if (e.key === 'F6') {\n e.preventDefault();\n e.stopPropagation();\n\n let backward = e.shiftKey;\n let nextLandmark = this.getNextLandmark(e.target as Element, {backward});\n\n // If no landmarks, return\n if (!nextLandmark) {\n return;\n }\n\n // If alt key pressed, focus main landmark\n if (e.altKey) {\n let main = this.getLandmarkByRole('main');\n if (main && document.contains(main.ref.current)) {\n this.focusLandmark(main.ref.current);\n }\n return;\n }\n\n // If something was previously focused in the next landmark, then return focus to it\n if (nextLandmark.lastFocused) {\n let lastFocused = nextLandmark.lastFocused;\n if (document.body.contains(lastFocused)) {\n lastFocused.focus();\n return;\n }\n }\n\n // Otherwise, focus the landmark itself\n if (document.contains(nextLandmark.ref.current)) {\n this.focusLandmark(nextLandmark.ref.current);\n }\n }\n }\n\n /**\n * Sets lastFocused for a landmark, if focus is moved within that landmark.\n * Lets the last focused landmark know it was blurred if something else is focused.\n */\n public focusinHandler(e: FocusEvent) {\n let currentLandmark = this.closestLandmark(e.target as Element);\n if (currentLandmark && currentLandmark.ref.current !== e.target) {\n this.updateLandmark({ref: currentLandmark.ref, lastFocused: e.target as FocusableElement});\n }\n let previousFocusedElement = e.relatedTarget as Element;\n if (previousFocusedElement) {\n let closestPreviousLandmark = this.closestLandmark(previousFocusedElement);\n if (closestPreviousLandmark && closestPreviousLandmark.ref.current === previousFocusedElement) {\n closestPreviousLandmark.blur();\n }\n }\n }\n\n /**\n * Track if the focus is lost to the body. If it is, do cleanup on the landmark that last had focus.\n */\n public focusoutHandler(e: FocusEvent) {\n let previousFocusedElement = e.target as Element;\n let nextFocusedElement = e.relatedTarget;\n // the === document seems to be a jest thing for focus to go there on generic blur event such as landmark.blur();\n // browsers appear to send focus instead to document.body and the relatedTarget is null when that happens\n if (!nextFocusedElement || nextFocusedElement === document) {\n let closestPreviousLandmark = this.closestLandmark(previousFocusedElement);\n if (closestPreviousLandmark && closestPreviousLandmark.ref.current === previousFocusedElement) {\n closestPreviousLandmark.blur();\n }\n }\n }\n}\n\n/**\n * Provides landmark navigation in an application. Call this with a role and label to register a landmark navigable with F6.\n * @param props - Props for the landmark.\n * @param ref - Ref to the landmark.\n */\nexport function useLandmark(props: AriaLandmarkProps, ref: MutableRefObject<FocusableElement>): LandmarkAria {\n const {\n role,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n } = props;\n let manager = LandmarkManager.getInstance();\n let label = ariaLabel || ariaLabelledby;\n let [isLandmarkFocused, setIsLandmarkFocused] = useState(false);\n\n let focus = useCallback(() => {\n setIsLandmarkFocused(true);\n }, [setIsLandmarkFocused]);\n\n let blur = useCallback(() => {\n setIsLandmarkFocused(false);\n }, [setIsLandmarkFocused]);\n\n useLayoutEffect(() => {\n manager.addLandmark({ref, role, label, focus, blur});\n\n return () => {\n manager.removeLandmark(ref);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useLayoutEffect(() => {\n manager.updateLandmark({ref, label, role, focus, blur});\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [label, ref, role]);\n\n useEffect(() => {\n if (isLandmarkFocused) {\n ref.current.focus();\n }\n }, [isLandmarkFocused, ref]);\n\n return {\n landmarkProps: {\n role,\n tabIndex: isLandmarkFocused ? -1 : undefined\n }\n };\n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landmark/src/index.ts","packages/@react-aria/landmark/src/useLandmark.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {AriaLandmarkRole, AriaLandmarkProps, LandmarkAria} from './useLandmark';\nexport {useLandmark} from './useLandmark';\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {MutableRefObject, useCallback, useEffect, useState} from 'react';\nimport {useLayoutEffect} from '@react-aria/utils';\n\nexport type AriaLandmarkRole = 'main' | 'region' | 'search' | 'navigation' | 'form' | 'banner' | 'contentinfo' | 'complementary';\n\nexport interface AriaLandmarkProps extends AriaLabelingProps {\n role: AriaLandmarkRole\n}\n\nexport interface LandmarkAria {\n landmarkProps: DOMAttributes\n}\n\ntype Landmark = {\n ref: MutableRefObject<Element>,\n role: AriaLandmarkRole,\n label?: string,\n lastFocused?: FocusableElement,\n focus: () => void,\n blur: () => void\n};\n\nclass LandmarkManager {\n private landmarks: Array<Landmark> = [];\n private static instance: LandmarkManager;\n private isListening = false;\n\n private constructor() {\n this.f6Handler = this.f6Handler.bind(this);\n this.focusinHandler = this.focusinHandler.bind(this);\n this.focusoutHandler = this.focusoutHandler.bind(this);\n }\n\n public static getInstance(): LandmarkManager {\n if (!LandmarkManager.instance) {\n LandmarkManager.instance = new LandmarkManager();\n }\n\n return LandmarkManager.instance;\n }\n\n private setup() {\n document.addEventListener('keydown', this.f6Handler, {capture: true});\n document.addEventListener('focusin', this.focusinHandler, {capture: true});\n document.addEventListener('focusout', this.focusoutHandler, {capture: true});\n this.isListening = true;\n }\n\n private teardown() {\n document.removeEventListener('keydown', this.f6Handler, {capture: true});\n document.removeEventListener('focusin', this.focusinHandler, {capture: true});\n document.removeEventListener('focusout', this.focusoutHandler, {capture: true});\n this.isListening = false;\n }\n\n private focusLandmark(landmark: Element) {\n this.landmarks.find(l => l.ref.current === landmark)?.focus();\n }\n\n /**\n * Return set of landmarks with a specific role.\n */\n public getLandmarksByRole(role: AriaLandmarkRole) {\n return new Set(this.landmarks.filter(l => l.role === role));\n }\n\n /**\n * Return first landmark with a specific role.\n */\n public getLandmarkByRole(role: AriaLandmarkRole) {\n return this.landmarks.find(l => l.role === role);\n }\n\n public addLandmark(newLandmark: Landmark) {\n if (!this.isListening) {\n this.setup();\n }\n if (this.landmarks.find(landmark => landmark.ref === newLandmark.ref)) {\n return;\n }\n\n if (this.landmarks.filter(landmark => landmark.role === 'main').length > 1) {\n console.error('Page can contain no more than one landmark with the role \"main\".');\n }\n\n if (this.landmarks.length === 0) {\n this.landmarks = [newLandmark];\n return;\n }\n\n\n // Binary search to insert new landmark based on position in document relative to existing landmarks.\n // https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition\n let start = 0;\n let end = this.landmarks.length - 1;\n while (start <= end) {\n let mid = Math.floor((start + end) / 2);\n let comparedPosition = newLandmark.ref.current.compareDocumentPosition(this.landmarks[mid].ref.current as Node);\n let isNewAfterExisting = Boolean((comparedPosition & Node.DOCUMENT_POSITION_PRECEDING) || (comparedPosition & Node.DOCUMENT_POSITION_CONTAINS));\n\n if (isNewAfterExisting) {\n start = mid + 1;\n } else {\n end = mid - 1;\n }\n }\n\n this.landmarks.splice(start, 0, newLandmark);\n }\n\n public updateLandmark(landmark: Pick<Landmark, 'ref'> & Partial<Landmark>) {\n let index = this.landmarks.findIndex(l => l.ref === landmark.ref);\n if (index >= 0) {\n this.landmarks[index] = {...this.landmarks[index], ...landmark};\n this.checkLabels(this.landmarks[index].role);\n }\n }\n\n public removeLandmark(ref: MutableRefObject<Element>) {\n this.landmarks = this.landmarks.filter(landmark => landmark.ref !== ref);\n if (this.landmarks.length === 0) {\n this.teardown();\n }\n }\n\n /**\n * Warn if there are 2+ landmarks with the same role but no label.\n * Labels for landmarks with the same role must also be unique.\n *\n * See https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/.\n */\n private checkLabels(role: AriaLandmarkRole) {\n let landmarksWithRole = this.getLandmarksByRole(role);\n if (landmarksWithRole.size > 1) {\n let duplicatesWithoutLabel = [...landmarksWithRole].filter(landmark => !landmark.label);\n if (duplicatesWithoutLabel.length > 0) {\n console.warn(\n `Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute: `,\n duplicatesWithoutLabel.map(landmark => landmark.ref.current)\n );\n } else {\n let labels = [...landmarksWithRole].map(landmark => landmark.label);\n let duplicateLabels = labels.filter((item, index) => labels.indexOf(item) !== index);\n\n duplicateLabels.forEach((label) => {\n console.warn(\n `Page contains more than one landmark with the '${role}' role and '${label}' label. If two or more landmarks on a page share the same role, they must have unique labels: `,\n [...landmarksWithRole].filter(landmark => landmark.label === label).map(landmark => landmark.ref.current)\n );\n });\n }\n }\n }\n\n /**\n * Get the landmark that is the closest parent in the DOM.\n * Returns undefined if no parent is a landmark.\n */\n private closestLandmark(element: Element) {\n let landmarkMap = new Map(this.landmarks.map(l => [l.ref.current, l]));\n let currentElement = element;\n while (!landmarkMap.has(currentElement) && currentElement !== document.body) {\n currentElement = currentElement.parentElement;\n }\n return landmarkMap.get(currentElement);\n }\n\n /**\n * Gets the next landmark, in DOM focus order, or previous if backwards is specified.\n * If last landmark, next should be the first landmark.\n * If not inside a landmark, will return first landmark.\n * Returns undefined if there are no landmarks.\n */\n public getNextLandmark(element: Element, {backward}: {backward?: boolean }) {\n if (this.landmarks.length === 0) {\n return undefined;\n }\n\n let currentLandmark = this.closestLandmark(element);\n let nextLandmarkIndex = backward ? -1 : 0;\n if (currentLandmark) {\n nextLandmarkIndex = this.landmarks.findIndex(landmark => landmark === currentLandmark) + (backward ? -1 : 1);\n }\n\n // Wrap if necessary\n if (nextLandmarkIndex < 0) {\n nextLandmarkIndex = this.landmarks.length - 1;\n } else if (nextLandmarkIndex >= this.landmarks.length) {\n nextLandmarkIndex = 0;\n }\n\n return this.landmarks[nextLandmarkIndex];\n }\n\n /**\n * Look at next landmark. If an element was previously focused inside, restore focus there.\n * If not, focus the landmark itself.\n * If no landmarks at all, or none with focusable elements, don't move focus.\n */\n public f6Handler(e: KeyboardEvent) {\n if (e.key === 'F6') {\n e.preventDefault();\n e.stopPropagation();\n\n let backward = e.shiftKey;\n let nextLandmark = this.getNextLandmark(e.target as Element, {backward});\n\n // If no landmarks, return\n if (!nextLandmark) {\n return;\n }\n\n // If alt key pressed, focus main landmark\n if (e.altKey) {\n let main = this.getLandmarkByRole('main');\n if (main && document.contains(main.ref.current)) {\n this.focusLandmark(main.ref.current);\n }\n return;\n }\n\n // If something was previously focused in the next landmark, then return focus to it\n if (nextLandmark.lastFocused) {\n let lastFocused = nextLandmark.lastFocused;\n if (document.body.contains(lastFocused)) {\n lastFocused.focus();\n return;\n }\n }\n\n // Otherwise, focus the landmark itself\n if (document.contains(nextLandmark.ref.current)) {\n this.focusLandmark(nextLandmark.ref.current);\n }\n }\n }\n\n /**\n * Sets lastFocused for a landmark, if focus is moved within that landmark.\n * Lets the last focused landmark know it was blurred if something else is focused.\n */\n public focusinHandler(e: FocusEvent) {\n let currentLandmark = this.closestLandmark(e.target as Element);\n if (currentLandmark && currentLandmark.ref.current !== e.target) {\n this.updateLandmark({ref: currentLandmark.ref, lastFocused: e.target as FocusableElement});\n }\n let previousFocusedElement = e.relatedTarget as Element;\n if (previousFocusedElement) {\n let closestPreviousLandmark = this.closestLandmark(previousFocusedElement);\n if (closestPreviousLandmark && closestPreviousLandmark.ref.current === previousFocusedElement) {\n closestPreviousLandmark.blur();\n }\n }\n }\n\n /**\n * Track if the focus is lost to the body. If it is, do cleanup on the landmark that last had focus.\n */\n public focusoutHandler(e: FocusEvent) {\n let previousFocusedElement = e.target as Element;\n let nextFocusedElement = e.relatedTarget;\n // the === document seems to be a jest thing for focus to go there on generic blur event such as landmark.blur();\n // browsers appear to send focus instead to document.body and the relatedTarget is null when that happens\n if (!nextFocusedElement || nextFocusedElement === document) {\n let closestPreviousLandmark = this.closestLandmark(previousFocusedElement);\n if (closestPreviousLandmark && closestPreviousLandmark.ref.current === previousFocusedElement) {\n closestPreviousLandmark.blur();\n }\n }\n }\n}\n\n/**\n * Provides landmark navigation in an application. Call this with a role and label to register a landmark navigable with F6.\n * @param props - Props for the landmark.\n * @param ref - Ref to the landmark.\n */\nexport function useLandmark(props: AriaLandmarkProps, ref: MutableRefObject<FocusableElement>): LandmarkAria {\n const {\n role,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n } = props;\n let manager = LandmarkManager.getInstance();\n let label = ariaLabel || ariaLabelledby;\n let [isLandmarkFocused, setIsLandmarkFocused] = useState(false);\n\n let focus = useCallback(() => {\n setIsLandmarkFocused(true);\n }, [setIsLandmarkFocused]);\n\n let blur = useCallback(() => {\n setIsLandmarkFocused(false);\n }, [setIsLandmarkFocused]);\n\n useLayoutEffect(() => {\n manager.addLandmark({ref, role, label, focus, blur});\n\n return () => {\n manager.removeLandmark(ref);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useLayoutEffect(() => {\n manager.updateLandmark({ref, label, role, focus, blur});\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [label, ref, role]);\n\n useEffect(() => {\n if (isLandmarkFocused) {\n ref.current.focus();\n }\n }, [isLandmarkFocused, ref]);\n\n return {\n landmarkProps: {\n role,\n tabIndex: isLandmarkFocused ? -1 : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
|
+
import $TvsbU$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
|
|
1
2
|
import {useState as $TvsbU$useState, useCallback as $TvsbU$useCallback, useEffect as $TvsbU$useEffect} from "react";
|
|
2
3
|
import {useLayoutEffect as $TvsbU$useLayoutEffect} from "@react-aria/utils";
|
|
3
4
|
|
|
5
|
+
/*
|
|
6
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
7
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
9
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
+
* governing permissions and limitations under the License.
|
|
15
|
+
*/ /*
|
|
16
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
17
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
18
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
19
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
20
|
+
*
|
|
21
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
22
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
23
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
24
|
+
* governing permissions and limitations under the License.
|
|
25
|
+
*/
|
|
4
26
|
|
|
5
27
|
|
|
6
28
|
class $a86207c5d7f7e1fb$var$LandmarkManager {
|
|
@@ -9,52 +31,47 @@ class $a86207c5d7f7e1fb$var$LandmarkManager {
|
|
|
9
31
|
return $a86207c5d7f7e1fb$var$LandmarkManager.instance;
|
|
10
32
|
}
|
|
11
33
|
setup() {
|
|
12
|
-
document.addEventListener(
|
|
34
|
+
document.addEventListener("keydown", this.f6Handler, {
|
|
13
35
|
capture: true
|
|
14
36
|
});
|
|
15
|
-
document.addEventListener(
|
|
37
|
+
document.addEventListener("focusin", this.focusinHandler, {
|
|
16
38
|
capture: true
|
|
17
39
|
});
|
|
18
|
-
document.addEventListener(
|
|
40
|
+
document.addEventListener("focusout", this.focusoutHandler, {
|
|
19
41
|
capture: true
|
|
20
42
|
});
|
|
21
43
|
this.isListening = true;
|
|
22
44
|
}
|
|
23
45
|
teardown() {
|
|
24
|
-
document.removeEventListener(
|
|
46
|
+
document.removeEventListener("keydown", this.f6Handler, {
|
|
25
47
|
capture: true
|
|
26
48
|
});
|
|
27
|
-
document.removeEventListener(
|
|
49
|
+
document.removeEventListener("focusin", this.focusinHandler, {
|
|
28
50
|
capture: true
|
|
29
51
|
});
|
|
30
|
-
document.removeEventListener(
|
|
52
|
+
document.removeEventListener("focusout", this.focusoutHandler, {
|
|
31
53
|
capture: true
|
|
32
54
|
});
|
|
33
55
|
this.isListening = false;
|
|
34
56
|
}
|
|
35
57
|
focusLandmark(landmark) {
|
|
36
|
-
var
|
|
37
|
-
(
|
|
38
|
-
)) === null || ref === void 0 ? void 0 : ref.focus();
|
|
58
|
+
var _this_landmarks_find;
|
|
59
|
+
(_this_landmarks_find = this.landmarks.find((l)=>l.ref.current === landmark)) === null || _this_landmarks_find === void 0 ? void 0 : _this_landmarks_find.focus();
|
|
39
60
|
}
|
|
40
61
|
/**
|
|
41
62
|
* Return set of landmarks with a specific role.
|
|
42
63
|
*/ getLandmarksByRole(role) {
|
|
43
|
-
return new Set(this.landmarks.filter((l)=>l.role === role
|
|
44
|
-
));
|
|
64
|
+
return new Set(this.landmarks.filter((l)=>l.role === role));
|
|
45
65
|
}
|
|
46
66
|
/**
|
|
47
67
|
* Return first landmark with a specific role.
|
|
48
68
|
*/ getLandmarkByRole(role) {
|
|
49
|
-
return this.landmarks.find((l)=>l.role === role
|
|
50
|
-
);
|
|
69
|
+
return this.landmarks.find((l)=>l.role === role);
|
|
51
70
|
}
|
|
52
71
|
addLandmark(newLandmark) {
|
|
53
72
|
if (!this.isListening) this.setup();
|
|
54
|
-
if (this.landmarks.find((landmark)=>landmark.ref === newLandmark.ref
|
|
55
|
-
))
|
|
56
|
-
if (this.landmarks.filter((landmark)=>landmark.role === 'main'
|
|
57
|
-
).length > 1) console.error('Page can contain no more than one landmark with the role "main".');
|
|
73
|
+
if (this.landmarks.find((landmark)=>landmark.ref === newLandmark.ref)) return;
|
|
74
|
+
if (this.landmarks.filter((landmark)=>landmark.role === "main").length > 1) console.error('Page can contain no more than one landmark with the role "main".');
|
|
58
75
|
if (this.landmarks.length === 0) {
|
|
59
76
|
this.landmarks = [
|
|
60
77
|
newLandmark
|
|
@@ -75,8 +92,7 @@ class $a86207c5d7f7e1fb$var$LandmarkManager {
|
|
|
75
92
|
this.landmarks.splice(start, 0, newLandmark);
|
|
76
93
|
}
|
|
77
94
|
updateLandmark(landmark) {
|
|
78
|
-
let index = this.landmarks.findIndex((l)=>l.ref === landmark.ref
|
|
79
|
-
);
|
|
95
|
+
let index = this.landmarks.findIndex((l)=>l.ref === landmark.ref);
|
|
80
96
|
if (index >= 0) {
|
|
81
97
|
this.landmarks[index] = {
|
|
82
98
|
...this.landmarks[index],
|
|
@@ -86,8 +102,7 @@ class $a86207c5d7f7e1fb$var$LandmarkManager {
|
|
|
86
102
|
}
|
|
87
103
|
}
|
|
88
104
|
removeLandmark(ref) {
|
|
89
|
-
this.landmarks = this.landmarks.filter((landmark)=>landmark.ref !== ref
|
|
90
|
-
);
|
|
105
|
+
this.landmarks = this.landmarks.filter((landmark)=>landmark.ref !== ref);
|
|
91
106
|
if (this.landmarks.length === 0) this.teardown();
|
|
92
107
|
}
|
|
93
108
|
/**
|
|
@@ -100,23 +115,17 @@ class $a86207c5d7f7e1fb$var$LandmarkManager {
|
|
|
100
115
|
if (landmarksWithRole.size > 1) {
|
|
101
116
|
let duplicatesWithoutLabel = [
|
|
102
117
|
...landmarksWithRole
|
|
103
|
-
].filter((landmark)=>!landmark.label
|
|
104
|
-
);
|
|
105
|
-
if (duplicatesWithoutLabel.length > 0) console.warn(`Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute: `, duplicatesWithoutLabel.map((landmark)=>landmark.ref.current
|
|
106
|
-
));
|
|
118
|
+
].filter((landmark)=>!landmark.label);
|
|
119
|
+
if (duplicatesWithoutLabel.length > 0) console.warn(`Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute: `, duplicatesWithoutLabel.map((landmark)=>landmark.ref.current));
|
|
107
120
|
else {
|
|
108
121
|
let labels = [
|
|
109
122
|
...landmarksWithRole
|
|
110
|
-
].map((landmark)=>landmark.label
|
|
111
|
-
);
|
|
112
|
-
let duplicateLabels = labels.filter((item, index)=>labels.indexOf(item) !== index
|
|
113
|
-
);
|
|
123
|
+
].map((landmark)=>landmark.label);
|
|
124
|
+
let duplicateLabels = labels.filter((item, index)=>labels.indexOf(item) !== index);
|
|
114
125
|
duplicateLabels.forEach((label)=>{
|
|
115
126
|
console.warn(`Page contains more than one landmark with the '${role}' role and '${label}' label. If two or more landmarks on a page share the same role, they must have unique labels: `, [
|
|
116
127
|
...landmarksWithRole
|
|
117
|
-
].filter((landmark)=>landmark.label === label
|
|
118
|
-
).map((landmark)=>landmark.ref.current
|
|
119
|
-
));
|
|
128
|
+
].filter((landmark)=>landmark.label === label).map((landmark)=>landmark.ref.current));
|
|
120
129
|
});
|
|
121
130
|
}
|
|
122
131
|
}
|
|
@@ -128,8 +137,7 @@ class $a86207c5d7f7e1fb$var$LandmarkManager {
|
|
|
128
137
|
let landmarkMap = new Map(this.landmarks.map((l)=>[
|
|
129
138
|
l.ref.current,
|
|
130
139
|
l
|
|
131
|
-
]
|
|
132
|
-
));
|
|
140
|
+
]));
|
|
133
141
|
let currentElement = element;
|
|
134
142
|
while(!landmarkMap.has(currentElement) && currentElement !== document.body)currentElement = currentElement.parentElement;
|
|
135
143
|
return landmarkMap.get(currentElement);
|
|
@@ -143,8 +151,7 @@ class $a86207c5d7f7e1fb$var$LandmarkManager {
|
|
|
143
151
|
if (this.landmarks.length === 0) return undefined;
|
|
144
152
|
let currentLandmark = this.closestLandmark(element);
|
|
145
153
|
let nextLandmarkIndex = backward ? -1 : 0;
|
|
146
|
-
if (currentLandmark) nextLandmarkIndex = this.landmarks.findIndex((landmark)=>landmark === currentLandmark
|
|
147
|
-
) + (backward ? -1 : 1);
|
|
154
|
+
if (currentLandmark) nextLandmarkIndex = this.landmarks.findIndex((landmark)=>landmark === currentLandmark) + (backward ? -1 : 1);
|
|
148
155
|
// Wrap if necessary
|
|
149
156
|
if (nextLandmarkIndex < 0) nextLandmarkIndex = this.landmarks.length - 1;
|
|
150
157
|
else if (nextLandmarkIndex >= this.landmarks.length) nextLandmarkIndex = 0;
|
|
@@ -155,7 +162,7 @@ class $a86207c5d7f7e1fb$var$LandmarkManager {
|
|
|
155
162
|
* If not, focus the landmark itself.
|
|
156
163
|
* If no landmarks at all, or none with focusable elements, don't move focus.
|
|
157
164
|
*/ f6Handler(e) {
|
|
158
|
-
if (e.key ===
|
|
165
|
+
if (e.key === "F6") {
|
|
159
166
|
e.preventDefault();
|
|
160
167
|
e.stopPropagation();
|
|
161
168
|
let backward = e.shiftKey;
|
|
@@ -166,7 +173,7 @@ class $a86207c5d7f7e1fb$var$LandmarkManager {
|
|
|
166
173
|
if (!nextLandmark) return;
|
|
167
174
|
// If alt key pressed, focus main landmark
|
|
168
175
|
if (e.altKey) {
|
|
169
|
-
let main = this.getLandmarkByRole(
|
|
176
|
+
let main = this.getLandmarkByRole("main");
|
|
170
177
|
if (main && document.contains(main.ref.current)) this.focusLandmark(main.ref.current);
|
|
171
178
|
return;
|
|
172
179
|
}
|
|
@@ -210,29 +217,29 @@ class $a86207c5d7f7e1fb$var$LandmarkManager {
|
|
|
210
217
|
}
|
|
211
218
|
}
|
|
212
219
|
constructor(){
|
|
213
|
-
this
|
|
214
|
-
this
|
|
220
|
+
(0, $TvsbU$swchelperssrc_define_propertymjs)(this, "landmarks", []);
|
|
221
|
+
(0, $TvsbU$swchelperssrc_define_propertymjs)(this, "isListening", false);
|
|
215
222
|
this.f6Handler = this.f6Handler.bind(this);
|
|
216
223
|
this.focusinHandler = this.focusinHandler.bind(this);
|
|
217
224
|
this.focusoutHandler = this.focusoutHandler.bind(this);
|
|
218
225
|
}
|
|
219
226
|
}
|
|
220
227
|
function $a86207c5d7f7e1fb$export$4cc632584fd87fae(props, ref) {
|
|
221
|
-
const { role: role ,
|
|
228
|
+
const { role: role , "aria-label": ariaLabel , "aria-labelledby": ariaLabelledby } = props;
|
|
222
229
|
let manager = $a86207c5d7f7e1fb$var$LandmarkManager.getInstance();
|
|
223
230
|
let label = ariaLabel || ariaLabelledby;
|
|
224
|
-
let [isLandmarkFocused, setIsLandmarkFocused] = $TvsbU$useState(false);
|
|
225
|
-
let focus = $TvsbU$useCallback(()=>{
|
|
231
|
+
let [isLandmarkFocused, setIsLandmarkFocused] = (0, $TvsbU$useState)(false);
|
|
232
|
+
let focus = (0, $TvsbU$useCallback)(()=>{
|
|
226
233
|
setIsLandmarkFocused(true);
|
|
227
234
|
}, [
|
|
228
235
|
setIsLandmarkFocused
|
|
229
236
|
]);
|
|
230
|
-
let blur = $TvsbU$useCallback(()=>{
|
|
237
|
+
let blur = (0, $TvsbU$useCallback)(()=>{
|
|
231
238
|
setIsLandmarkFocused(false);
|
|
232
239
|
}, [
|
|
233
240
|
setIsLandmarkFocused
|
|
234
241
|
]);
|
|
235
|
-
$TvsbU$useLayoutEffect(()=>{
|
|
242
|
+
(0, $TvsbU$useLayoutEffect)(()=>{
|
|
236
243
|
manager.addLandmark({
|
|
237
244
|
ref: ref,
|
|
238
245
|
role: role,
|
|
@@ -245,7 +252,7 @@ function $a86207c5d7f7e1fb$export$4cc632584fd87fae(props, ref) {
|
|
|
245
252
|
};
|
|
246
253
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
247
254
|
}, []);
|
|
248
|
-
$TvsbU$useLayoutEffect(()=>{
|
|
255
|
+
(0, $TvsbU$useLayoutEffect)(()=>{
|
|
249
256
|
manager.updateLandmark({
|
|
250
257
|
ref: ref,
|
|
251
258
|
label: label,
|
|
@@ -259,7 +266,7 @@ function $a86207c5d7f7e1fb$export$4cc632584fd87fae(props, ref) {
|
|
|
259
266
|
ref,
|
|
260
267
|
role
|
|
261
268
|
]);
|
|
262
|
-
$TvsbU$useEffect(()=>{
|
|
269
|
+
(0, $TvsbU$useEffect)(()=>{
|
|
263
270
|
if (isLandmarkFocused) ref.current.focus();
|
|
264
271
|
}, [
|
|
265
272
|
isLandmarkFocused,
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;MCmCM,qCAAe;WAWL,WAAW,GAAoB,CAAC;QAC5C,EAAE,GAAG,qCAAe,CAAC,QAAQ,EAC3B,qCAAe,CAAC,QAAQ,GAAG,GAAG,CAAC,qCAAe;QAGhD,MAAM,CAAC,qCAAe,CAAC,QAAQ;IACjC,CAAC;IAEO,KAAK,GAAG,CAAC;QACf,QAAQ,CAAC,gBAAgB,CAAC,CAAS,UAAE,IAAI,CAAC,SAAS,EAAE,CAAC;YAAA,OAAO,EAAE,IAAI;QAAA,CAAC;QACpE,QAAQ,CAAC,gBAAgB,CAAC,CAAS,UAAE,IAAI,CAAC,cAAc,EAAE,CAAC;YAAA,OAAO,EAAE,IAAI;QAAA,CAAC;QACzE,QAAQ,CAAC,gBAAgB,CAAC,CAAU,WAAE,IAAI,CAAC,eAAe,EAAE,CAAC;YAAA,OAAO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E,CAAC;QAAA,oBAAoB;IAAA,CAAC;IAEzB,sBAAe,KAAO,CAAC;QACrB,OAAO,CAAC,WAAW,CAAC,CAAC;iBAAA,GAAG;kBAAE,IAAI;mBAAE,KAAK;mBAAE,KAAK;kBAAE,IAAI;QAAA,CAAC;QAEnD,MAAM,KAAO,CAAC;YACZ,OAAO,CAAC,cAAc,CAAC,GAAG;QAC5B,CAAC;IACH,EAAuD,AAAvD,qDAAuD;IACvD,CAAC,EAAE,CAAC,CAAC;IAEL,sBAAe,KAAO,CAAC;QACrB,OAAO,CAAC,cAAc,CAAC,CAAC;iBAAA,GAAG;mBAAE,KAAK;kBAAE,IAAI;mBAAE,KAAK;kBAAE,IAAI;QAAA,CAAC;IACxD,EAAuD,AAAvD,qDAAuD;IACvD,CAAC,EAAE,CAAC;QAAA,KAAK;QAAE,GAAG;QAAE,IAAI;IAAA,CAAC;IAErB,gBAAS,KAAO,CAAC;QACf,EAAE,EAAE,iBAAiB,EACnB,GAAG,CAAC,OAAO,CAAC,KAAK;IAErB,CAAC,EAAE,CAAC;QAAA,iBAAiB;QAAE,GAAG;IAAA,CAAC;IAE3B,MAAM,CAAC,CAAC;QACN,aAAa,EAAE,CAAC;kBACd,IAAI;YACJ,QAAQ,EAAE,iBAAiB,GAAG,EAAE,GAAG,SAAS;QAC9C,CAAC;IACH,CAAC;AACH,CAAC","sources":["packages/@react-aria/landmark/src/index.ts","packages/@react-aria/landmark/src/useLandmark.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {AriaLandmarkRole, AriaLandmarkProps, LandmarkAria} from './useLandmark';\nexport {useLandmark} from './useLandmark';\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {MutableRefObject, useCallback, useEffect, useState} from 'react';\nimport {useLayoutEffect} from '@react-aria/utils';\n\nexport type AriaLandmarkRole = 'main' | 'region' | 'search' | 'navigation' | 'form' | 'banner' | 'contentinfo' | 'complementary';\n\nexport interface AriaLandmarkProps extends AriaLabelingProps {\n role: AriaLandmarkRole\n}\n\nexport interface LandmarkAria {\n landmarkProps: DOMAttributes\n}\n\ntype Landmark = {\n ref: MutableRefObject<Element>,\n role: AriaLandmarkRole,\n label?: string,\n lastFocused?: FocusableElement,\n focus: () => void,\n blur: () => void\n};\n\nclass LandmarkManager {\n private landmarks: Array<Landmark> = [];\n private static instance: LandmarkManager;\n private isListening = false;\n\n private constructor() {\n this.f6Handler = this.f6Handler.bind(this);\n this.focusinHandler = this.focusinHandler.bind(this);\n this.focusoutHandler = this.focusoutHandler.bind(this);\n }\n\n public static getInstance(): LandmarkManager {\n if (!LandmarkManager.instance) {\n LandmarkManager.instance = new LandmarkManager();\n }\n\n return LandmarkManager.instance;\n }\n\n private setup() {\n document.addEventListener('keydown', this.f6Handler, {capture: true});\n document.addEventListener('focusin', this.focusinHandler, {capture: true});\n document.addEventListener('focusout', this.focusoutHandler, {capture: true});\n this.isListening = true;\n }\n\n private teardown() {\n document.removeEventListener('keydown', this.f6Handler, {capture: true});\n document.removeEventListener('focusin', this.focusinHandler, {capture: true});\n document.removeEventListener('focusout', this.focusoutHandler, {capture: true});\n this.isListening = false;\n }\n\n private focusLandmark(landmark: Element) {\n this.landmarks.find(l => l.ref.current === landmark)?.focus();\n }\n\n /**\n * Return set of landmarks with a specific role.\n */\n public getLandmarksByRole(role: AriaLandmarkRole) {\n return new Set(this.landmarks.filter(l => l.role === role));\n }\n\n /**\n * Return first landmark with a specific role.\n */\n public getLandmarkByRole(role: AriaLandmarkRole) {\n return this.landmarks.find(l => l.role === role);\n }\n\n public addLandmark(newLandmark: Landmark) {\n if (!this.isListening) {\n this.setup();\n }\n if (this.landmarks.find(landmark => landmark.ref === newLandmark.ref)) {\n return;\n }\n\n if (this.landmarks.filter(landmark => landmark.role === 'main').length > 1) {\n console.error('Page can contain no more than one landmark with the role \"main\".');\n }\n\n if (this.landmarks.length === 0) {\n this.landmarks = [newLandmark];\n return;\n }\n\n\n // Binary search to insert new landmark based on position in document relative to existing landmarks.\n // https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition\n let start = 0;\n let end = this.landmarks.length - 1;\n while (start <= end) {\n let mid = Math.floor((start + end) / 2);\n let comparedPosition = newLandmark.ref.current.compareDocumentPosition(this.landmarks[mid].ref.current as Node);\n let isNewAfterExisting = Boolean((comparedPosition & Node.DOCUMENT_POSITION_PRECEDING) || (comparedPosition & Node.DOCUMENT_POSITION_CONTAINS));\n\n if (isNewAfterExisting) {\n start = mid + 1;\n } else {\n end = mid - 1;\n }\n }\n\n this.landmarks.splice(start, 0, newLandmark);\n }\n\n public updateLandmark(landmark: Pick<Landmark, 'ref'> & Partial<Landmark>) {\n let index = this.landmarks.findIndex(l => l.ref === landmark.ref);\n if (index >= 0) {\n this.landmarks[index] = {...this.landmarks[index], ...landmark};\n this.checkLabels(this.landmarks[index].role);\n }\n }\n\n public removeLandmark(ref: MutableRefObject<Element>) {\n this.landmarks = this.landmarks.filter(landmark => landmark.ref !== ref);\n if (this.landmarks.length === 0) {\n this.teardown();\n }\n }\n\n /**\n * Warn if there are 2+ landmarks with the same role but no label.\n * Labels for landmarks with the same role must also be unique.\n *\n * See https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/.\n */\n private checkLabels(role: AriaLandmarkRole) {\n let landmarksWithRole = this.getLandmarksByRole(role);\n if (landmarksWithRole.size > 1) {\n let duplicatesWithoutLabel = [...landmarksWithRole].filter(landmark => !landmark.label);\n if (duplicatesWithoutLabel.length > 0) {\n console.warn(\n `Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute: `,\n duplicatesWithoutLabel.map(landmark => landmark.ref.current)\n );\n } else {\n let labels = [...landmarksWithRole].map(landmark => landmark.label);\n let duplicateLabels = labels.filter((item, index) => labels.indexOf(item) !== index);\n\n duplicateLabels.forEach((label) => {\n console.warn(\n `Page contains more than one landmark with the '${role}' role and '${label}' label. If two or more landmarks on a page share the same role, they must have unique labels: `,\n [...landmarksWithRole].filter(landmark => landmark.label === label).map(landmark => landmark.ref.current)\n );\n });\n }\n }\n }\n\n /**\n * Get the landmark that is the closest parent in the DOM.\n * Returns undefined if no parent is a landmark.\n */\n private closestLandmark(element: Element) {\n let landmarkMap = new Map(this.landmarks.map(l => [l.ref.current, l]));\n let currentElement = element;\n while (!landmarkMap.has(currentElement) && currentElement !== document.body) {\n currentElement = currentElement.parentElement;\n }\n return landmarkMap.get(currentElement);\n }\n\n /**\n * Gets the next landmark, in DOM focus order, or previous if backwards is specified.\n * If last landmark, next should be the first landmark.\n * If not inside a landmark, will return first landmark.\n * Returns undefined if there are no landmarks.\n */\n public getNextLandmark(element: Element, {backward}: {backward?: boolean }) {\n if (this.landmarks.length === 0) {\n return undefined;\n }\n\n let currentLandmark = this.closestLandmark(element);\n let nextLandmarkIndex = backward ? -1 : 0;\n if (currentLandmark) {\n nextLandmarkIndex = this.landmarks.findIndex(landmark => landmark === currentLandmark) + (backward ? -1 : 1);\n }\n\n // Wrap if necessary\n if (nextLandmarkIndex < 0) {\n nextLandmarkIndex = this.landmarks.length - 1;\n } else if (nextLandmarkIndex >= this.landmarks.length) {\n nextLandmarkIndex = 0;\n }\n\n return this.landmarks[nextLandmarkIndex];\n }\n\n /**\n * Look at next landmark. If an element was previously focused inside, restore focus there.\n * If not, focus the landmark itself.\n * If no landmarks at all, or none with focusable elements, don't move focus.\n */\n public f6Handler(e: KeyboardEvent) {\n if (e.key === 'F6') {\n e.preventDefault();\n e.stopPropagation();\n\n let backward = e.shiftKey;\n let nextLandmark = this.getNextLandmark(e.target as Element, {backward});\n\n // If no landmarks, return\n if (!nextLandmark) {\n return;\n }\n\n // If alt key pressed, focus main landmark\n if (e.altKey) {\n let main = this.getLandmarkByRole('main');\n if (main && document.contains(main.ref.current)) {\n this.focusLandmark(main.ref.current);\n }\n return;\n }\n\n // If something was previously focused in the next landmark, then return focus to it\n if (nextLandmark.lastFocused) {\n let lastFocused = nextLandmark.lastFocused;\n if (document.body.contains(lastFocused)) {\n lastFocused.focus();\n return;\n }\n }\n\n // Otherwise, focus the landmark itself\n if (document.contains(nextLandmark.ref.current)) {\n this.focusLandmark(nextLandmark.ref.current);\n }\n }\n }\n\n /**\n * Sets lastFocused for a landmark, if focus is moved within that landmark.\n * Lets the last focused landmark know it was blurred if something else is focused.\n */\n public focusinHandler(e: FocusEvent) {\n let currentLandmark = this.closestLandmark(e.target as Element);\n if (currentLandmark && currentLandmark.ref.current !== e.target) {\n this.updateLandmark({ref: currentLandmark.ref, lastFocused: e.target as FocusableElement});\n }\n let previousFocusedElement = e.relatedTarget as Element;\n if (previousFocusedElement) {\n let closestPreviousLandmark = this.closestLandmark(previousFocusedElement);\n if (closestPreviousLandmark && closestPreviousLandmark.ref.current === previousFocusedElement) {\n closestPreviousLandmark.blur();\n }\n }\n }\n\n /**\n * Track if the focus is lost to the body. If it is, do cleanup on the landmark that last had focus.\n */\n public focusoutHandler(e: FocusEvent) {\n let previousFocusedElement = e.target as Element;\n let nextFocusedElement = e.relatedTarget;\n // the === document seems to be a jest thing for focus to go there on generic blur event such as landmark.blur();\n // browsers appear to send focus instead to document.body and the relatedTarget is null when that happens\n if (!nextFocusedElement || nextFocusedElement === document) {\n let closestPreviousLandmark = this.closestLandmark(previousFocusedElement);\n if (closestPreviousLandmark && closestPreviousLandmark.ref.current === previousFocusedElement) {\n closestPreviousLandmark.blur();\n }\n }\n }\n}\n\n/**\n * Provides landmark navigation in an application. Call this with a role and label to register a landmark navigable with F6.\n * @param props - Props for the landmark.\n * @param ref - Ref to the landmark.\n */\nexport function useLandmark(props: AriaLandmarkProps, ref: MutableRefObject<FocusableElement>): LandmarkAria {\n const {\n role,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n } = props;\n let manager = LandmarkManager.getInstance();\n let label = ariaLabel || ariaLabelledby;\n let [isLandmarkFocused, setIsLandmarkFocused] = useState(false);\n\n let focus = useCallback(() => {\n setIsLandmarkFocused(true);\n }, [setIsLandmarkFocused]);\n\n let blur = useCallback(() => {\n setIsLandmarkFocused(false);\n }, [setIsLandmarkFocused]);\n\n useLayoutEffect(() => {\n manager.addLandmark({ref, role, label, focus, blur});\n\n return () => {\n manager.removeLandmark(ref);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useLayoutEffect(() => {\n manager.updateLandmark({ref, label, role, focus, blur});\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [label, ref, role]);\n\n useEffect(() => {\n if (isLandmarkFocused) {\n ref.current.focus();\n }\n }, [isLandmarkFocused, ref]);\n\n return {\n landmarkProps: {\n role,\n tabIndex: isLandmarkFocused ? -1 : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;;AAuBA,MAAM;IAWJ,OAAc,cAA+B;QAC3C,IAAI,CAAC,sCAAgB,QAAQ,EAC3B,sCAAgB,QAAQ,GAAG,IAAI;QAGjC,OAAO,sCAAgB,QAAQ;IACjC;IAEQ,QAAQ;QACd,SA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AAI,EACJ,cAAc,UAAS,EACvB,mBAAmB,eAAc,EAClC,GAAG;IACJ,IAAI,UAAU,sCAAgB,WAAW;IACzC,IAAI,QAAQ,aAAa;IACzB,IAAI,CAAC,mBAAmB,qBAAqB,GAAG,CAAA,GAAA,eAAO,EAAE,KAAK;IAE9D,IAAI,QAAQ,CAAA,GAAA,kBAAU,EAAE,IAAM;QAC5B,qBAAqB,IAAI;IAC3B,GAAG;QAAC;KAAqB;IAEzB,IAAI,OAAO,CAAA,GAAA,kBAAU,EAAE,IAAM;QAC3B,qBAAqB,KAAK;IAC5B,GAAG;QAAC;KAAqB;IAEzB,CAAA,GAAA,sBAAe,AAAD,EAAE,IAAM;QACpB,QAAQ,WAAW,CAAC;iBAAC;kBAAK;mBAAM;mBAAO;kBAAO;QAAI;QAElD,OAAO,IAAM;YACX,QAAQ,cAAc,CAAC;QACzB;IACF,uDAAuD;IACvD,GAAG,EAAE;IAEL,CAAA,GAAA,sBAAe,AAAD,EAAE,IAAM;QACpB,QAAQ,cAAc,CAAC;iBAAC;mBAAK;kBAAO;mBAAM;kBAAO;QAAI;IACvD,uDAAuD;IACvD,GAAG;QAAC;QAAO;QAAK;KAAK;IAErB,CAAA,GAAA,gBAAS,AAAD,EAAE,IAAM;QACd,IAAI,mBACF,IAAI,OAAO,CAAC,KAAK;IAErB,GAAG;QAAC;QAAmB;KAAI;IAE3B,OAAO;QACL,eAAe;kBACb;YACA,UAAU,oBAAoB,KAAK,SAAS;QAC9C;IACF;AACF;;CDpUC,GAED","sources":["packages/@react-aria/landmark/src/index.ts","packages/@react-aria/landmark/src/useLandmark.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {AriaLandmarkRole, AriaLandmarkProps, LandmarkAria} from './useLandmark';\nexport {useLandmark} from './useLandmark';\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {MutableRefObject, useCallback, useEffect, useState} from 'react';\nimport {useLayoutEffect} from '@react-aria/utils';\n\nexport type AriaLandmarkRole = 'main' | 'region' | 'search' | 'navigation' | 'form' | 'banner' | 'contentinfo' | 'complementary';\n\nexport interface AriaLandmarkProps extends AriaLabelingProps {\n role: AriaLandmarkRole\n}\n\nexport interface LandmarkAria {\n landmarkProps: DOMAttributes\n}\n\ntype Landmark = {\n ref: MutableRefObject<Element>,\n role: AriaLandmarkRole,\n label?: string,\n lastFocused?: FocusableElement,\n focus: () => void,\n blur: () => void\n};\n\nclass LandmarkManager {\n private landmarks: Array<Landmark> = [];\n private static instance: LandmarkManager;\n private isListening = false;\n\n private constructor() {\n this.f6Handler = this.f6Handler.bind(this);\n this.focusinHandler = this.focusinHandler.bind(this);\n this.focusoutHandler = this.focusoutHandler.bind(this);\n }\n\n public static getInstance(): LandmarkManager {\n if (!LandmarkManager.instance) {\n LandmarkManager.instance = new LandmarkManager();\n }\n\n return LandmarkManager.instance;\n }\n\n private setup() {\n document.addEventListener('keydown', this.f6Handler, {capture: true});\n document.addEventListener('focusin', this.focusinHandler, {capture: true});\n document.addEventListener('focusout', this.focusoutHandler, {capture: true});\n this.isListening = true;\n }\n\n private teardown() {\n document.removeEventListener('keydown', this.f6Handler, {capture: true});\n document.removeEventListener('focusin', this.focusinHandler, {capture: true});\n document.removeEventListener('focusout', this.focusoutHandler, {capture: true});\n this.isListening = false;\n }\n\n private focusLandmark(landmark: Element) {\n this.landmarks.find(l => l.ref.current === landmark)?.focus();\n }\n\n /**\n * Return set of landmarks with a specific role.\n */\n public getLandmarksByRole(role: AriaLandmarkRole) {\n return new Set(this.landmarks.filter(l => l.role === role));\n }\n\n /**\n * Return first landmark with a specific role.\n */\n public getLandmarkByRole(role: AriaLandmarkRole) {\n return this.landmarks.find(l => l.role === role);\n }\n\n public addLandmark(newLandmark: Landmark) {\n if (!this.isListening) {\n this.setup();\n }\n if (this.landmarks.find(landmark => landmark.ref === newLandmark.ref)) {\n return;\n }\n\n if (this.landmarks.filter(landmark => landmark.role === 'main').length > 1) {\n console.error('Page can contain no more than one landmark with the role \"main\".');\n }\n\n if (this.landmarks.length === 0) {\n this.landmarks = [newLandmark];\n return;\n }\n\n\n // Binary search to insert new landmark based on position in document relative to existing landmarks.\n // https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition\n let start = 0;\n let end = this.landmarks.length - 1;\n while (start <= end) {\n let mid = Math.floor((start + end) / 2);\n let comparedPosition = newLandmark.ref.current.compareDocumentPosition(this.landmarks[mid].ref.current as Node);\n let isNewAfterExisting = Boolean((comparedPosition & Node.DOCUMENT_POSITION_PRECEDING) || (comparedPosition & Node.DOCUMENT_POSITION_CONTAINS));\n\n if (isNewAfterExisting) {\n start = mid + 1;\n } else {\n end = mid - 1;\n }\n }\n\n this.landmarks.splice(start, 0, newLandmark);\n }\n\n public updateLandmark(landmark: Pick<Landmark, 'ref'> & Partial<Landmark>) {\n let index = this.landmarks.findIndex(l => l.ref === landmark.ref);\n if (index >= 0) {\n this.landmarks[index] = {...this.landmarks[index], ...landmark};\n this.checkLabels(this.landmarks[index].role);\n }\n }\n\n public removeLandmark(ref: MutableRefObject<Element>) {\n this.landmarks = this.landmarks.filter(landmark => landmark.ref !== ref);\n if (this.landmarks.length === 0) {\n this.teardown();\n }\n }\n\n /**\n * Warn if there are 2+ landmarks with the same role but no label.\n * Labels for landmarks with the same role must also be unique.\n *\n * See https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/.\n */\n private checkLabels(role: AriaLandmarkRole) {\n let landmarksWithRole = this.getLandmarksByRole(role);\n if (landmarksWithRole.size > 1) {\n let duplicatesWithoutLabel = [...landmarksWithRole].filter(landmark => !landmark.label);\n if (duplicatesWithoutLabel.length > 0) {\n console.warn(\n `Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute: `,\n duplicatesWithoutLabel.map(landmark => landmark.ref.current)\n );\n } else {\n let labels = [...landmarksWithRole].map(landmark => landmark.label);\n let duplicateLabels = labels.filter((item, index) => labels.indexOf(item) !== index);\n\n duplicateLabels.forEach((label) => {\n console.warn(\n `Page contains more than one landmark with the '${role}' role and '${label}' label. If two or more landmarks on a page share the same role, they must have unique labels: `,\n [...landmarksWithRole].filter(landmark => landmark.label === label).map(landmark => landmark.ref.current)\n );\n });\n }\n }\n }\n\n /**\n * Get the landmark that is the closest parent in the DOM.\n * Returns undefined if no parent is a landmark.\n */\n private closestLandmark(element: Element) {\n let landmarkMap = new Map(this.landmarks.map(l => [l.ref.current, l]));\n let currentElement = element;\n while (!landmarkMap.has(currentElement) && currentElement !== document.body) {\n currentElement = currentElement.parentElement;\n }\n return landmarkMap.get(currentElement);\n }\n\n /**\n * Gets the next landmark, in DOM focus order, or previous if backwards is specified.\n * If last landmark, next should be the first landmark.\n * If not inside a landmark, will return first landmark.\n * Returns undefined if there are no landmarks.\n */\n public getNextLandmark(element: Element, {backward}: {backward?: boolean }) {\n if (this.landmarks.length === 0) {\n return undefined;\n }\n\n let currentLandmark = this.closestLandmark(element);\n let nextLandmarkIndex = backward ? -1 : 0;\n if (currentLandmark) {\n nextLandmarkIndex = this.landmarks.findIndex(landmark => landmark === currentLandmark) + (backward ? -1 : 1);\n }\n\n // Wrap if necessary\n if (nextLandmarkIndex < 0) {\n nextLandmarkIndex = this.landmarks.length - 1;\n } else if (nextLandmarkIndex >= this.landmarks.length) {\n nextLandmarkIndex = 0;\n }\n\n return this.landmarks[nextLandmarkIndex];\n }\n\n /**\n * Look at next landmark. If an element was previously focused inside, restore focus there.\n * If not, focus the landmark itself.\n * If no landmarks at all, or none with focusable elements, don't move focus.\n */\n public f6Handler(e: KeyboardEvent) {\n if (e.key === 'F6') {\n e.preventDefault();\n e.stopPropagation();\n\n let backward = e.shiftKey;\n let nextLandmark = this.getNextLandmark(e.target as Element, {backward});\n\n // If no landmarks, return\n if (!nextLandmark) {\n return;\n }\n\n // If alt key pressed, focus main landmark\n if (e.altKey) {\n let main = this.getLandmarkByRole('main');\n if (main && document.contains(main.ref.current)) {\n this.focusLandmark(main.ref.current);\n }\n return;\n }\n\n // If something was previously focused in the next landmark, then return focus to it\n if (nextLandmark.lastFocused) {\n let lastFocused = nextLandmark.lastFocused;\n if (document.body.contains(lastFocused)) {\n lastFocused.focus();\n return;\n }\n }\n\n // Otherwise, focus the landmark itself\n if (document.contains(nextLandmark.ref.current)) {\n this.focusLandmark(nextLandmark.ref.current);\n }\n }\n }\n\n /**\n * Sets lastFocused for a landmark, if focus is moved within that landmark.\n * Lets the last focused landmark know it was blurred if something else is focused.\n */\n public focusinHandler(e: FocusEvent) {\n let currentLandmark = this.closestLandmark(e.target as Element);\n if (currentLandmark && currentLandmark.ref.current !== e.target) {\n this.updateLandmark({ref: currentLandmark.ref, lastFocused: e.target as FocusableElement});\n }\n let previousFocusedElement = e.relatedTarget as Element;\n if (previousFocusedElement) {\n let closestPreviousLandmark = this.closestLandmark(previousFocusedElement);\n if (closestPreviousLandmark && closestPreviousLandmark.ref.current === previousFocusedElement) {\n closestPreviousLandmark.blur();\n }\n }\n }\n\n /**\n * Track if the focus is lost to the body. If it is, do cleanup on the landmark that last had focus.\n */\n public focusoutHandler(e: FocusEvent) {\n let previousFocusedElement = e.target as Element;\n let nextFocusedElement = e.relatedTarget;\n // the === document seems to be a jest thing for focus to go there on generic blur event such as landmark.blur();\n // browsers appear to send focus instead to document.body and the relatedTarget is null when that happens\n if (!nextFocusedElement || nextFocusedElement === document) {\n let closestPreviousLandmark = this.closestLandmark(previousFocusedElement);\n if (closestPreviousLandmark && closestPreviousLandmark.ref.current === previousFocusedElement) {\n closestPreviousLandmark.blur();\n }\n }\n }\n}\n\n/**\n * Provides landmark navigation in an application. Call this with a role and label to register a landmark navigable with F6.\n * @param props - Props for the landmark.\n * @param ref - Ref to the landmark.\n */\nexport function useLandmark(props: AriaLandmarkProps, ref: MutableRefObject<FocusableElement>): LandmarkAria {\n const {\n role,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n } = props;\n let manager = LandmarkManager.getInstance();\n let label = ariaLabel || ariaLabelledby;\n let [isLandmarkFocused, setIsLandmarkFocused] = useState(false);\n\n let focus = useCallback(() => {\n setIsLandmarkFocused(true);\n }, [setIsLandmarkFocused]);\n\n let blur = useCallback(() => {\n setIsLandmarkFocused(false);\n }, [setIsLandmarkFocused]);\n\n useLayoutEffect(() => {\n manager.addLandmark({ref, role, label, focus, blur});\n\n return () => {\n manager.removeLandmark(ref);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useLayoutEffect(() => {\n manager.updateLandmark({ref, label, role, focus, blur});\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [label, ref, role]);\n\n useEffect(() => {\n if (isLandmarkFocused) {\n ref.current.focus();\n }\n }, [isLandmarkFocused, ref]);\n\n return {\n landmarkProps: {\n role,\n tabIndex: isLandmarkFocused ? -1 : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/landmark",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.5",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"url": "https://github.com/adobe/react-spectrum"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@react-aria/
|
|
22
|
-
"@react-
|
|
23
|
-
"@
|
|
20
|
+
"@react-aria/focus": "^3.10.1",
|
|
21
|
+
"@react-aria/utils": "^3.14.2",
|
|
22
|
+
"@react-types/shared": "^3.16.0",
|
|
23
|
+
"@swc/helpers": "^0.4.14"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "5480d76bd815e239366f92852c76b6831ad2a4fd"
|
|
32
32
|
}
|