@react-aria/landmark 3.0.9 → 3.1.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/dist/import.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import {UNSTABLE_createLandmarkController as $a86207c5d7f7e1fb$export$a8e2debc6521490c, useLandmark as $a86207c5d7f7e1fb$export$4cc632584fd87fae} from "./useLandmark.mjs";
1
+ import {useLandmark as $a37d901c6eb3c947$re_export$useLandmark} from "react-aria/useLandmark";
2
+ import {UNSTABLE_createLandmarkController as $a37d901c6eb3c947$re_export$UNSTABLE_createLandmarkController} from "react-aria/private/landmark/useLandmark";
2
3
 
3
4
  /*
4
5
  * Copyright 2022 Adobe. All rights reserved.
@@ -13,5 +14,6 @@ import {UNSTABLE_createLandmarkController as $a86207c5d7f7e1fb$export$a8e2debc65
13
14
  */
14
15
 
15
16
 
16
- export {$a86207c5d7f7e1fb$export$4cc632584fd87fae as useLandmark, $a86207c5d7f7e1fb$export$a8e2debc6521490c as UNSTABLE_createLandmarkController};
17
+
18
+ export {$a37d901c6eb3c947$re_export$useLandmark as useLandmark, $a37d901c6eb3c947$re_export$UNSTABLE_createLandmarkController as UNSTABLE_createLandmarkController};
17
19
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,12 +1,13 @@
1
- var $202c109aedff6705$exports = require("./useLandmark.main.js");
1
+ var $6uX34$reactariauseLandmark = require("react-aria/useLandmark");
2
+ var $6uX34$reactariaprivatelandmarkuseLandmark = require("react-aria/private/landmark/useLandmark");
2
3
 
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
  }
7
8
 
8
- $parcel$export(module.exports, "useLandmark", () => $202c109aedff6705$exports.useLandmark);
9
- $parcel$export(module.exports, "UNSTABLE_createLandmarkController", () => $202c109aedff6705$exports.UNSTABLE_createLandmarkController);
9
+ $parcel$export(module.exports, "useLandmark", function () { return $6uX34$reactariauseLandmark.useLandmark; });
10
+ $parcel$export(module.exports, "UNSTABLE_createLandmarkController", function () { return $6uX34$reactariaprivatelandmarkuseLandmark.UNSTABLE_createLandmarkController; });
10
11
  /*
11
12
  * Copyright 2022 Adobe. All rights reserved.
12
13
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -20,4 +21,5 @@ $parcel$export(module.exports, "UNSTABLE_createLandmarkController", () => $202c1
20
21
  */
21
22
 
22
23
 
24
+
23
25
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/landmark/src/index.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, LandmarkController} from './useLandmark';\nexport {useLandmark, UNSTABLE_createLandmarkController} from './useLandmark';\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/landmark/src/index.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 {useLandmark} from 'react-aria/useLandmark';\n\nexport {UNSTABLE_createLandmarkController} from 'react-aria/private/landmark/useLandmark';\nexport type {AriaLandmarkRole, AriaLandmarkProps, LandmarkAria, LandmarkController} from 'react-aria/useLandmark';\nexport type {LandmarkControllerOptions} from 'react-aria/private/landmark/useLandmark';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,5 @@
1
- import {UNSTABLE_createLandmarkController as $a86207c5d7f7e1fb$export$a8e2debc6521490c, useLandmark as $a86207c5d7f7e1fb$export$4cc632584fd87fae} from "./useLandmark.module.js";
1
+ import {useLandmark as $a37d901c6eb3c947$re_export$useLandmark} from "react-aria/useLandmark";
2
+ import {UNSTABLE_createLandmarkController as $a37d901c6eb3c947$re_export$UNSTABLE_createLandmarkController} from "react-aria/private/landmark/useLandmark";
2
3
 
3
4
  /*
4
5
  * Copyright 2022 Adobe. All rights reserved.
@@ -13,5 +14,6 @@ import {UNSTABLE_createLandmarkController as $a86207c5d7f7e1fb$export$a8e2debc65
13
14
  */
14
15
 
15
16
 
16
- export {$a86207c5d7f7e1fb$export$4cc632584fd87fae as useLandmark, $a86207c5d7f7e1fb$export$a8e2debc6521490c as UNSTABLE_createLandmarkController};
17
+
18
+ export {$a37d901c6eb3c947$re_export$useLandmark as useLandmark, $a37d901c6eb3c947$re_export$UNSTABLE_createLandmarkController as UNSTABLE_createLandmarkController};
17
19
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/landmark/src/index.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, LandmarkController} from './useLandmark';\nexport {useLandmark, UNSTABLE_createLandmarkController} from './useLandmark';\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/landmark/src/index.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 {useLandmark} from 'react-aria/useLandmark';\n\nexport {UNSTABLE_createLandmarkController} from 'react-aria/private/landmark/useLandmark';\nexport type {AriaLandmarkRole, AriaLandmarkProps, LandmarkAria, LandmarkController} from 'react-aria/useLandmark';\nexport type {LandmarkControllerOptions} from 'react-aria/private/landmark/useLandmark';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,4 @@
1
+ export { useLandmark } from 'react-aria/useLandmark';
2
+ export { UNSTABLE_createLandmarkController } from 'react-aria/private/landmark/useLandmark';
3
+ export type { AriaLandmarkRole, AriaLandmarkProps, LandmarkAria, LandmarkController } from 'react-aria/useLandmark';
4
+ export type { LandmarkControllerOptions } from 'react-aria/private/landmark/useLandmark';
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@react-aria/landmark",
3
- "version": "3.0.9",
3
+ "version": "3.1.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
8
  "exports": {
9
- "source": "./src/index.ts",
10
- "types": [
11
- "./dist/types.d.ts",
12
- "./src/index.ts"
13
- ],
14
- "import": "./dist/import.mjs",
15
- "require": "./dist/main.js"
9
+ ".": {
10
+ "source": "./src/index.ts",
11
+ "types": "./dist/types/src/index.d.ts",
12
+ "import": "./dist/import.mjs",
13
+ "require": "./dist/main.js"
14
+ },
15
+ "./package.json": "./package.json"
16
16
  },
17
- "types": "dist/types.d.ts",
17
+ "types": "dist/types/src/index.d.ts",
18
18
  "source": "src/index.ts",
19
19
  "files": [
20
20
  "dist",
@@ -26,10 +26,8 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-aria/utils": "^3.33.0",
30
- "@react-types/shared": "^3.33.0",
31
29
  "@swc/helpers": "^0.5.0",
32
- "use-sync-external-store": "^1.6.0"
30
+ "react-aria": "3.48.0"
33
31
  },
34
32
  "peerDependencies": {
35
33
  "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
@@ -38,5 +36,8 @@
38
36
  "publishConfig": {
39
37
  "access": "public"
40
38
  },
41
- "gitHead": "66e51757606b43a89ed02c574ca24517323a2ab9"
39
+ "targets": {
40
+ "types": false
41
+ },
42
+ "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
42
43
  }
package/src/index.ts CHANGED
@@ -10,5 +10,8 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export type {AriaLandmarkRole, AriaLandmarkProps, LandmarkAria, LandmarkController} from './useLandmark';
14
- export {useLandmark, UNSTABLE_createLandmarkController} from './useLandmark';
13
+ export {useLandmark} from 'react-aria/useLandmark';
14
+
15
+ export {UNSTABLE_createLandmarkController} from 'react-aria/private/landmark/useLandmark';
16
+ export type {AriaLandmarkRole, AriaLandmarkProps, LandmarkAria, LandmarkController} from 'react-aria/useLandmark';
17
+ export type {LandmarkControllerOptions} from 'react-aria/private/landmark/useLandmark';
package/dist/types.d.ts DELETED
@@ -1,42 +0,0 @@
1
- import { AriaLabelingProps, DOMAttributes, FocusableElement, RefObject } from "@react-types/shared";
2
- export type AriaLandmarkRole = 'main' | 'region' | 'search' | 'navigation' | 'form' | 'banner' | 'contentinfo' | 'complementary';
3
- export interface AriaLandmarkProps extends AriaLabelingProps {
4
- role: AriaLandmarkRole;
5
- focus?: (direction: 'forward' | 'backward') => void;
6
- }
7
- export interface LandmarkAria {
8
- landmarkProps: DOMAttributes;
9
- }
10
- interface LandmarkControllerOptions {
11
- /**
12
- * The element from which to start navigating.
13
- * @default document.activeElement
14
- */
15
- from?: FocusableElement;
16
- }
17
- /** A LandmarkController allows programmatic navigation of landmarks. */
18
- export interface LandmarkController {
19
- /** Moves focus to the next landmark. */
20
- focusNext(opts?: LandmarkControllerOptions): boolean;
21
- /** Moves focus to the previous landmark. */
22
- focusPrevious(opts?: LandmarkControllerOptions): boolean;
23
- /** Moves focus to the main landmark. */
24
- focusMain(): boolean;
25
- /** Moves focus either forward or backward in the landmark sequence. */
26
- navigate(direction: 'forward' | 'backward', opts?: LandmarkControllerOptions): boolean;
27
- /**
28
- * Disposes the landmark controller. When no landmarks are registered, and no
29
- * controllers are active, the landmark keyboard listeners are removed from the page.
30
- */
31
- dispose(): void;
32
- }
33
- /** Creates a LandmarkController, which allows programmatic navigation of landmarks. */
34
- export function UNSTABLE_createLandmarkController(): LandmarkController;
35
- /**
36
- * Provides landmark navigation in an application. Call this with a role and label to register a landmark navigable with F6.
37
- * @param props - Props for the landmark.
38
- * @param ref - Ref to the landmark.
39
- */
40
- export function useLandmark(props: AriaLandmarkProps, ref: RefObject<FocusableElement | null>): LandmarkAria;
41
-
42
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":";AAiBA,+BAA+B,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,YAAY,GAAG,MAAM,GAAG,QAAQ,GAAG,aAAa,GAAG,eAAe,CAAC;AAEjI,kCAAmC,SAAQ,iBAAiB;IAC1D,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,UAAU,KAAK,IAAI,CAAA;CACpD;AAED;IACE,aAAa,EAAE,aAAa,CAAA;CAC7B;AA4BD;IACE;;;OAGG;IACH,IAAI,CAAC,EAAE,gBAAgB,CAAA;CACxB;AAED,wEAAwE;AACxE;IACE,wCAAwC;IACxC,SAAS,CAAC,IAAI,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC;IACrD,4CAA4C;IAC5C,aAAa,CAAC,IAAI,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC;IACzD,wCAAwC;IACxC,SAAS,IAAI,OAAO,CAAC;IACrB,uEAAuE;IACvE,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,UAAU,EAAE,IAAI,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC;IACvF;;;OAGG;IACH,OAAO,IAAI,IAAI,CAAA;CAChB;AAwWD,uFAAuF;AACvF,qDAAqD,kBAAkB,CAkCtE;AAED;;;;GAIG;AACH,4BAA4B,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,YAAY,CAuC3G","sources":["packages/@react-aria/landmark/src/packages/@react-aria/landmark/src/useLandmark.ts","packages/@react-aria/landmark/src/packages/@react-aria/landmark/src/index.ts","packages/@react-aria/landmark/src/index.ts"],"sourcesContent":[null,null,"/*\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, LandmarkController} from './useLandmark';\nexport {useLandmark, UNSTABLE_createLandmarkController} from './useLandmark';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -1,407 +0,0 @@
1
- var $iIApB$reactariautils = require("@react-aria/utils");
2
- var $iIApB$react = require("react");
3
- var $iIApB$usesyncexternalstoreshimindexjs = require("use-sync-external-store/shim/index.js");
4
-
5
-
6
- function $parcel$export(e, n, v, s) {
7
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
- }
9
-
10
- $parcel$export(module.exports, "UNSTABLE_createLandmarkController", () => $202c109aedff6705$export$a8e2debc6521490c);
11
- $parcel$export(module.exports, "useLandmark", () => $202c109aedff6705$export$4cc632584fd87fae);
12
- /*
13
- * Copyright 2022 Adobe. All rights reserved.
14
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
15
- * you may not use this file except in compliance with the License. You may obtain a copy
16
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
17
- *
18
- * Unless required by applicable law or agreed to in writing, software distributed under
19
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
20
- * OF ANY KIND, either express or implied. See the License for the specific language
21
- * governing permissions and limitations under the License.
22
- */
23
-
24
-
25
- // Increment this version number whenever the
26
- // LandmarkManagerApi or Landmark interfaces change.
27
- const $202c109aedff6705$var$LANDMARK_API_VERSION = 1;
28
- // Symbol under which the singleton landmark manager instance is attached to the document.
29
- const $202c109aedff6705$var$landmarkSymbol = Symbol.for('react-aria-landmark-manager');
30
- function $202c109aedff6705$var$subscribe(fn) {
31
- document.addEventListener('react-aria-landmark-manager-change', fn);
32
- return ()=>document.removeEventListener('react-aria-landmark-manager-change', fn);
33
- }
34
- function $202c109aedff6705$var$getLandmarkManager() {
35
- if (typeof document === 'undefined') return null;
36
- // Reuse an existing instance if it has the same or greater version.
37
- let instance = document[$202c109aedff6705$var$landmarkSymbol];
38
- if (instance && instance.version >= $202c109aedff6705$var$LANDMARK_API_VERSION) return instance;
39
- // Otherwise, create a new instance and dispatch an event so anything using the existing
40
- // instance updates and re-registers their landmarks with the new one.
41
- document[$202c109aedff6705$var$landmarkSymbol] = new $202c109aedff6705$var$LandmarkManager();
42
- document.dispatchEvent(new CustomEvent('react-aria-landmark-manager-change'));
43
- return document[$202c109aedff6705$var$landmarkSymbol];
44
- }
45
- // Subscribes a React component to the current landmark manager instance.
46
- function $202c109aedff6705$var$useLandmarkManager() {
47
- return (0, $iIApB$usesyncexternalstoreshimindexjs.useSyncExternalStore)($202c109aedff6705$var$subscribe, $202c109aedff6705$var$getLandmarkManager, $202c109aedff6705$var$getLandmarkManager);
48
- }
49
- class $202c109aedff6705$var$LandmarkManager {
50
- setupIfNeeded() {
51
- if (this.isListening) return;
52
- document.addEventListener('keydown', this.f6Handler, {
53
- capture: true
54
- });
55
- document.addEventListener('focusin', this.focusinHandler, {
56
- capture: true
57
- });
58
- document.addEventListener('focusout', this.focusoutHandler, {
59
- capture: true
60
- });
61
- this.isListening = true;
62
- }
63
- teardownIfNeeded() {
64
- if (!this.isListening || this.landmarks.length > 0 || this.refCount > 0) return;
65
- document.removeEventListener('keydown', this.f6Handler, {
66
- capture: true
67
- });
68
- document.removeEventListener('focusin', this.focusinHandler, {
69
- capture: true
70
- });
71
- document.removeEventListener('focusout', this.focusoutHandler, {
72
- capture: true
73
- });
74
- this.isListening = false;
75
- }
76
- focusLandmark(landmark, direction) {
77
- var _this_landmarks_find_focus, _this_landmarks_find;
78
- (_this_landmarks_find = this.landmarks.find((l)=>l.ref.current === landmark)) === null || _this_landmarks_find === void 0 ? void 0 : (_this_landmarks_find_focus = _this_landmarks_find.focus) === null || _this_landmarks_find_focus === void 0 ? void 0 : _this_landmarks_find_focus.call(_this_landmarks_find, direction);
79
- }
80
- /**
81
- * Return set of landmarks with a specific role.
82
- */ getLandmarksByRole(role) {
83
- return new Set(this.landmarks.filter((l)=>l.role === role));
84
- }
85
- /**
86
- * Return first landmark with a specific role.
87
- */ getLandmarkByRole(role) {
88
- return this.landmarks.find((l)=>l.role === role);
89
- }
90
- addLandmark(newLandmark) {
91
- this.setupIfNeeded();
92
- if (this.landmarks.find((landmark)=>landmark.ref === newLandmark.ref) || !newLandmark.ref.current) return;
93
- if (this.landmarks.filter((landmark)=>landmark.role === 'main').length > 1 && process.env.NODE_ENV !== 'production') console.error('Page can contain no more than one landmark with the role "main".');
94
- if (this.landmarks.length === 0) {
95
- this.landmarks = [
96
- newLandmark
97
- ];
98
- this.checkLabels(newLandmark.role);
99
- return;
100
- }
101
- // Binary search to insert new landmark based on position in document relative to existing landmarks.
102
- // https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
103
- let start = 0;
104
- let end = this.landmarks.length - 1;
105
- while(start <= end){
106
- let mid = Math.floor((start + end) / 2);
107
- let comparedPosition = newLandmark.ref.current.compareDocumentPosition(this.landmarks[mid].ref.current);
108
- let isNewAfterExisting = Boolean(comparedPosition & Node.DOCUMENT_POSITION_PRECEDING || comparedPosition & Node.DOCUMENT_POSITION_CONTAINS);
109
- if (isNewAfterExisting) start = mid + 1;
110
- else end = mid - 1;
111
- }
112
- this.landmarks.splice(start, 0, newLandmark);
113
- this.checkLabels(newLandmark.role);
114
- }
115
- updateLandmark(landmark) {
116
- let index = this.landmarks.findIndex((l)=>l.ref === landmark.ref);
117
- if (index >= 0) {
118
- this.landmarks[index] = {
119
- ...this.landmarks[index],
120
- ...landmark
121
- };
122
- this.checkLabels(this.landmarks[index].role);
123
- }
124
- }
125
- removeLandmark(ref) {
126
- this.landmarks = this.landmarks.filter((landmark)=>landmark.ref !== ref);
127
- this.teardownIfNeeded();
128
- }
129
- /**
130
- * Warn if there are 2+ landmarks with the same role but no label.
131
- * Labels for landmarks with the same role must also be unique.
132
- *
133
- * See https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/.
134
- */ checkLabels(role) {
135
- let landmarksWithRole = this.getLandmarksByRole(role);
136
- if (landmarksWithRole.size > 1) {
137
- let duplicatesWithoutLabel = [
138
- ...landmarksWithRole
139
- ].filter((landmark)=>!landmark.label);
140
- if (duplicatesWithoutLabel.length > 0 && process.env.NODE_ENV !== 'production') 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));
141
- else if (process.env.NODE_ENV !== 'production') {
142
- let labels = [
143
- ...landmarksWithRole
144
- ].map((landmark)=>landmark.label);
145
- let duplicateLabels = labels.filter((item, index)=>labels.indexOf(item) !== index);
146
- duplicateLabels.forEach((label)=>{
147
- 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: `, [
148
- ...landmarksWithRole
149
- ].filter((landmark)=>landmark.label === label).map((landmark)=>landmark.ref.current));
150
- });
151
- }
152
- }
153
- }
154
- /**
155
- * Get the landmark that is the closest parent in the DOM.
156
- * Returns undefined if no parent is a landmark.
157
- */ closestLandmark(element) {
158
- let landmarkMap = new Map(this.landmarks.map((l)=>[
159
- l.ref.current,
160
- l
161
- ]));
162
- let currentElement = element;
163
- while(currentElement && !landmarkMap.has(currentElement) && currentElement !== document.body && currentElement.parentElement)currentElement = currentElement.parentElement;
164
- return landmarkMap.get(currentElement);
165
- }
166
- /**
167
- * Gets the next landmark, in DOM focus order, or previous if backwards is specified.
168
- * If last landmark, next should be the first landmark.
169
- * If not inside a landmark, will return first landmark.
170
- * Returns undefined if there are no landmarks.
171
- */ getNextLandmark(element, { backward: backward }) {
172
- var _this_landmarks_nextLandmarkIndex_ref_current;
173
- let currentLandmark = this.closestLandmark(element);
174
- let nextLandmarkIndex = backward ? this.landmarks.length - 1 : 0;
175
- if (currentLandmark) nextLandmarkIndex = this.landmarks.indexOf(currentLandmark) + (backward ? -1 : 1);
176
- let wrapIfNeeded = ()=>{
177
- // When we reach the end of the landmark sequence, fire a custom event that can be listened for by applications.
178
- // If this event is canceled, we return immediately. This can be used to implement landmark navigation across iframes.
179
- if (nextLandmarkIndex < 0) {
180
- if (!element.dispatchEvent(new CustomEvent('react-aria-landmark-navigation', {
181
- detail: {
182
- direction: 'backward'
183
- },
184
- bubbles: true,
185
- cancelable: true
186
- }))) return true;
187
- nextLandmarkIndex = this.landmarks.length - 1;
188
- } else if (nextLandmarkIndex >= this.landmarks.length) {
189
- if (!element.dispatchEvent(new CustomEvent('react-aria-landmark-navigation', {
190
- detail: {
191
- direction: 'forward'
192
- },
193
- bubbles: true,
194
- cancelable: true
195
- }))) return true;
196
- nextLandmarkIndex = 0;
197
- }
198
- if (nextLandmarkIndex < 0 || nextLandmarkIndex >= this.landmarks.length) return true;
199
- return false;
200
- };
201
- if (wrapIfNeeded()) return undefined;
202
- // Skip over hidden landmarks.
203
- let i = nextLandmarkIndex;
204
- while((_this_landmarks_nextLandmarkIndex_ref_current = this.landmarks[nextLandmarkIndex].ref.current) === null || _this_landmarks_nextLandmarkIndex_ref_current === void 0 ? void 0 : _this_landmarks_nextLandmarkIndex_ref_current.closest('[aria-hidden=true]')){
205
- nextLandmarkIndex += backward ? -1 : 1;
206
- if (wrapIfNeeded()) return undefined;
207
- if (nextLandmarkIndex === i) break;
208
- }
209
- return this.landmarks[nextLandmarkIndex];
210
- }
211
- /**
212
- * Look at next landmark. If an element was previously focused inside, restore focus there.
213
- * If not, focus the landmark itself.
214
- * If no landmarks at all, or none with focusable elements, don't move focus.
215
- */ f6Handler(e) {
216
- if (e.key === 'F6') {
217
- // If alt key pressed, focus main landmark, otherwise navigate forward or backward based on shift key.
218
- let handled = e.altKey ? this.focusMain() : this.navigate(e.target, e.shiftKey);
219
- if (handled) {
220
- e.preventDefault();
221
- e.stopPropagation();
222
- }
223
- }
224
- }
225
- focusMain() {
226
- let main = this.getLandmarkByRole('main');
227
- if (main && main.ref.current && (0, $iIApB$reactariautils.nodeContains)(document, main.ref.current)) {
228
- this.focusLandmark(main.ref.current, 'forward');
229
- return true;
230
- }
231
- return false;
232
- }
233
- navigate(from, backward) {
234
- let nextLandmark = this.getNextLandmark(from, {
235
- backward: backward
236
- });
237
- if (!nextLandmark) return false;
238
- // If something was previously focused in the next landmark, then return focus to it
239
- if (nextLandmark.lastFocused) {
240
- let lastFocused = nextLandmark.lastFocused;
241
- if ((0, $iIApB$reactariautils.nodeContains)(document.body, lastFocused)) {
242
- lastFocused.focus();
243
- return true;
244
- }
245
- }
246
- // Otherwise, focus the landmark itself
247
- if (nextLandmark.ref.current && (0, $iIApB$reactariautils.nodeContains)(document, nextLandmark.ref.current)) {
248
- this.focusLandmark(nextLandmark.ref.current, backward ? 'backward' : 'forward');
249
- return true;
250
- }
251
- return false;
252
- }
253
- /**
254
- * Sets lastFocused for a landmark, if focus is moved within that landmark.
255
- * Lets the last focused landmark know it was blurred if something else is focused.
256
- */ focusinHandler(e) {
257
- let currentLandmark = this.closestLandmark(e.target);
258
- if (currentLandmark && currentLandmark.ref.current !== e.target) this.updateLandmark({
259
- ref: currentLandmark.ref,
260
- lastFocused: e.target
261
- });
262
- let previousFocusedElement = e.relatedTarget;
263
- if (previousFocusedElement) {
264
- let closestPreviousLandmark = this.closestLandmark(previousFocusedElement);
265
- if (closestPreviousLandmark && closestPreviousLandmark.ref.current === previousFocusedElement) closestPreviousLandmark.blur();
266
- }
267
- }
268
- /**
269
- * Track if the focus is lost to the body. If it is, do cleanup on the landmark that last had focus.
270
- */ focusoutHandler(e) {
271
- let previousFocusedElement = e.target;
272
- let nextFocusedElement = e.relatedTarget;
273
- // the === document seems to be a jest thing for focus to go there on generic blur event such as landmark.blur();
274
- // browsers appear to send focus instead to document.body and the relatedTarget is null when that happens
275
- if (!nextFocusedElement || nextFocusedElement === document) {
276
- let closestPreviousLandmark = this.closestLandmark(previousFocusedElement);
277
- if (closestPreviousLandmark && closestPreviousLandmark.ref.current === previousFocusedElement) closestPreviousLandmark.blur();
278
- }
279
- }
280
- createLandmarkController() {
281
- let instance = this;
282
- instance.refCount++;
283
- instance.setupIfNeeded();
284
- return {
285
- navigate (direction, opts) {
286
- let element = (opts === null || opts === void 0 ? void 0 : opts.from) || document.activeElement;
287
- return instance.navigate(element, direction === 'backward');
288
- },
289
- focusNext (opts) {
290
- let element = (opts === null || opts === void 0 ? void 0 : opts.from) || document.activeElement;
291
- return instance.navigate(element, false);
292
- },
293
- focusPrevious (opts) {
294
- let element = (opts === null || opts === void 0 ? void 0 : opts.from) || document.activeElement;
295
- return instance.navigate(element, true);
296
- },
297
- focusMain () {
298
- return instance.focusMain();
299
- },
300
- dispose () {
301
- if (instance) {
302
- instance.refCount--;
303
- instance.teardownIfNeeded();
304
- instance = null;
305
- }
306
- }
307
- };
308
- }
309
- registerLandmark(landmark) {
310
- if (this.landmarks.find((l)=>l.ref === landmark.ref)) this.updateLandmark(landmark);
311
- else this.addLandmark(landmark);
312
- return ()=>this.removeLandmark(landmark.ref);
313
- }
314
- constructor(){
315
- this.landmarks = [];
316
- this.isListening = false;
317
- this.refCount = 0;
318
- this.version = $202c109aedff6705$var$LANDMARK_API_VERSION;
319
- this.f6Handler = this.f6Handler.bind(this);
320
- this.focusinHandler = this.focusinHandler.bind(this);
321
- this.focusoutHandler = this.focusoutHandler.bind(this);
322
- }
323
- }
324
- function $202c109aedff6705$export$a8e2debc6521490c() {
325
- // Get the current landmark manager and create a controller using it.
326
- let instance = $202c109aedff6705$var$getLandmarkManager();
327
- let controller = instance === null || instance === void 0 ? void 0 : instance.createLandmarkController();
328
- let unsubscribe = $202c109aedff6705$var$subscribe(()=>{
329
- // If the landmark manager changes, dispose the old
330
- // controller and create a new one.
331
- controller === null || controller === void 0 ? void 0 : controller.dispose();
332
- instance = $202c109aedff6705$var$getLandmarkManager();
333
- controller = instance === null || instance === void 0 ? void 0 : instance.createLandmarkController();
334
- });
335
- // Return a wrapper that proxies requests to the current controller instance.
336
- return {
337
- navigate (direction, opts) {
338
- return controller.navigate(direction, opts);
339
- },
340
- focusNext (opts) {
341
- return controller.focusNext(opts);
342
- },
343
- focusPrevious (opts) {
344
- return controller.focusPrevious(opts);
345
- },
346
- focusMain () {
347
- return controller.focusMain();
348
- },
349
- dispose () {
350
- controller === null || controller === void 0 ? void 0 : controller.dispose();
351
- unsubscribe();
352
- controller = undefined;
353
- instance = null;
354
- }
355
- };
356
- }
357
- function $202c109aedff6705$export$4cc632584fd87fae(props, ref) {
358
- const { role: role, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, focus: focus } = props;
359
- let manager = $202c109aedff6705$var$useLandmarkManager();
360
- let label = ariaLabel || ariaLabelledby;
361
- let [isLandmarkFocused, setIsLandmarkFocused] = (0, $iIApB$react.useState)(false);
362
- let defaultFocus = (0, $iIApB$react.useCallback)(()=>{
363
- setIsLandmarkFocused(true);
364
- }, [
365
- setIsLandmarkFocused
366
- ]);
367
- let blur = (0, $iIApB$react.useCallback)(()=>{
368
- setIsLandmarkFocused(false);
369
- }, [
370
- setIsLandmarkFocused
371
- ]);
372
- (0, $iIApB$reactariautils.useLayoutEffect)(()=>{
373
- if (manager) return manager.registerLandmark({
374
- ref: ref,
375
- label: label,
376
- role: role,
377
- focus: focus || defaultFocus,
378
- blur: blur
379
- });
380
- }, [
381
- manager,
382
- label,
383
- ref,
384
- role,
385
- focus,
386
- defaultFocus,
387
- blur
388
- ]);
389
- (0, $iIApB$react.useEffect)(()=>{
390
- var _ref_current;
391
- if (isLandmarkFocused) (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
392
- }, [
393
- isLandmarkFocused,
394
- ref
395
- ]);
396
- return {
397
- landmarkProps: {
398
- role: role,
399
- tabIndex: isLandmarkFocused ? -1 : undefined,
400
- 'aria-label': ariaLabel,
401
- 'aria-labelledby': ariaLabelledby
402
- }
403
- };
404
- }
405
-
406
-
407
- //# sourceMappingURL=useLandmark.main.js.map