@react-aria/landmark 3.0.0-alpha.0 → 3.0.0-alpha.1

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 CHANGED
@@ -1,28 +1,11 @@
1
1
  var $8Ore6$react = require("react");
2
2
  var $8Ore6$reactariautils = require("@react-aria/utils");
3
3
 
4
- function $parcel$exportWildcard(dest, source) {
5
- Object.keys(source).forEach(function(key) {
6
- if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
7
- return;
8
- }
9
-
10
- Object.defineProperty(dest, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return source[key];
14
- }
15
- });
16
- });
17
-
18
- return dest;
19
- }
20
4
  function $parcel$export(e, n, v, s) {
21
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
22
6
  }
23
- var $202c109aedff6705$exports = {};
24
7
 
25
- $parcel$export($202c109aedff6705$exports, "useLandmark", () => $202c109aedff6705$export$4cc632584fd87fae);
8
+ $parcel$export(module.exports, "useLandmark", () => $202c109aedff6705$export$4cc632584fd87fae);
26
9
 
27
10
 
28
11
  class $202c109aedff6705$var$LandmarkManager {
@@ -296,7 +279,6 @@ function $202c109aedff6705$export$4cc632584fd87fae(props, ref) {
296
279
  }
297
280
 
298
281
 
299
- $parcel$exportWildcard(module.exports, $202c109aedff6705$exports);
300
282
 
301
283
 
302
284
  //# sourceMappingURL=main.js.map
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,IAAI,C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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 * 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} from '@react-types/shared';\nimport {HTMLAttributes, 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\ninterface LandmarkAria {\n landmarkProps: HTMLAttributes<HTMLElement>\n}\n\ntype Landmark = {\n ref: MutableRefObject<HTMLElement>,\n role: AriaLandmarkRole,\n label?: string,\n lastFocused?: HTMLElement,\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: HTMLElement) {\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<HTMLElement>) {\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: HTMLElement) {\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: HTMLElement, {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 HTMLElement, {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 HTMLElement);\n if (currentLandmark && currentLandmark.ref.current !== e.target) {\n this.updateLandmark({ref: currentLandmark.ref, lastFocused: e.target as HTMLElement});\n }\n let previousFocusedElement = e.relatedTarget as HTMLElement;\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 HTMLElement;\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<HTMLElement>): 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,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AAE,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":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,12 +1,6 @@
1
1
  import {useState as $TvsbU$useState, useCallback as $TvsbU$useCallback, useEffect as $TvsbU$useEffect} from "react";
2
2
  import {useLayoutEffect as $TvsbU$useLayoutEffect} from "@react-aria/utils";
3
3
 
4
- function $parcel$export(e, n, v, s) {
5
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
- }
7
- var $a86207c5d7f7e1fb$exports = {};
8
-
9
- $parcel$export($a86207c5d7f7e1fb$exports, "useLandmark", () => $a86207c5d7f7e1fb$export$4cc632584fd87fae);
10
4
 
11
5
 
12
6
  class $a86207c5d7f7e1fb$var$LandmarkManager {
@@ -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,gBAAg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BAAW,KAAO,CAAC;QAC5B,oBAAoB,CAAC,KAAK;IAC5B,CAAC,EAAE,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 * 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} from '@react-types/shared';\nimport {HTMLAttributes, 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\ninterface LandmarkAria {\n landmarkProps: HTMLAttributes<HTMLElement>\n}\n\ntype Landmark = {\n ref: MutableRefObject<HTMLElement>,\n role: AriaLandmarkRole,\n label?: string,\n lastFocused?: HTMLElement,\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: HTMLElement) {\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<HTMLElement>) {\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: HTMLElement) {\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: HTMLElement, {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 HTMLElement, {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 HTMLElement);\n if (currentLandmark && currentLandmark.ref.current !== e.target) {\n this.updateLandmark({ref: currentLandmark.ref, lastFocused: e.target as HTMLElement});\n }\n let previousFocusedElement = e.relatedTarget as HTMLElement;\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 HTMLElement;\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<HTMLElement>): 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":";;;;;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,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-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/dist/types.d.ts CHANGED
@@ -1,17 +1,17 @@
1
- import { AriaLabelingProps } from "@react-types/shared";
2
- import { HTMLAttributes, MutableRefObject } from "react";
1
+ import { AriaLabelingProps, DOMAttributes, FocusableElement } from "@react-types/shared";
2
+ import { MutableRefObject } from "react";
3
3
  export type AriaLandmarkRole = 'main' | 'region' | 'search' | 'navigation' | 'form' | 'banner' | 'contentinfo' | 'complementary';
4
4
  export interface AriaLandmarkProps extends AriaLabelingProps {
5
5
  role: AriaLandmarkRole;
6
6
  }
7
- interface LandmarkAria {
8
- landmarkProps: HTMLAttributes<HTMLElement>;
7
+ export interface LandmarkAria {
8
+ landmarkProps: DOMAttributes;
9
9
  }
10
10
  /**
11
11
  * Provides landmark navigation in an application. Call this with a role and label to register a landmark navigable with F6.
12
12
  * @param props - Props for the landmark.
13
13
  * @param ref - Ref to the landmark.
14
14
  */
15
- export function useLandmark(props: AriaLandmarkProps, ref: MutableRefObject<HTMLElement>): LandmarkAria;
15
+ export function useLandmark(props: AriaLandmarkProps, ref: MutableRefObject<FocusableElement>): LandmarkAria;
16
16
 
17
17
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"mappings":";;AAgBA,+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,CAAA;CACvB;AAED;IACE,aAAa,EAAE,eAAe,WAAW,CAAC,CAAA;CAC3C;AAqQD;;;;GAIG;AACH,4BAA4B,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,WAAW,CAAC,GAAG,YAAY,CA4CtG","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 * from './useLandmark';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;AAgBA,+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,CAAA;CACvB;AAED;IACE,aAAa,EAAE,aAAa,CAAA;CAC7B;AAqQD;;;;GAIG;AACH,4BAA4B,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,gBAAgB,CAAC,GAAG,YAAY,CA4C3G","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} from './useLandmark';\nexport {useLandmark} from './useLandmark';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/landmark",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-alpha.1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -18,9 +18,9 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.6.2",
21
- "@react-aria/focus": "^3.6.1",
22
- "@react-aria/utils": "^3.13.1",
23
- "@react-types/shared": "^3.13.1"
21
+ "@react-aria/focus": "^3.7.0",
22
+ "@react-aria/utils": "^3.13.2",
23
+ "@react-types/shared": "^3.14.0"
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": "715c3f563ccf8c2e0102d3e18403d9db21a05a71"
31
+ "gitHead": "cd7c0ec917122c7612f653c22f8ed558f8b66ecd"
32
32
  }
package/src/index.ts CHANGED
@@ -10,4 +10,5 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export * from './useLandmark';
13
+ export type {AriaLandmarkRole, AriaLandmarkProps, LandmarkAria} from './useLandmark';
14
+ export {useLandmark} from './useLandmark';
@@ -10,8 +10,8 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import {AriaLabelingProps} from '@react-types/shared';
14
- import {HTMLAttributes, MutableRefObject, useCallback, useEffect, useState} from 'react';
13
+ import {AriaLabelingProps, DOMAttributes, FocusableElement} from '@react-types/shared';
14
+ import {MutableRefObject, useCallback, useEffect, useState} from 'react';
15
15
  import {useLayoutEffect} from '@react-aria/utils';
16
16
 
17
17
  export type AriaLandmarkRole = 'main' | 'region' | 'search' | 'navigation' | 'form' | 'banner' | 'contentinfo' | 'complementary';
@@ -20,15 +20,15 @@ export interface AriaLandmarkProps extends AriaLabelingProps {
20
20
  role: AriaLandmarkRole
21
21
  }
22
22
 
23
- interface LandmarkAria {
24
- landmarkProps: HTMLAttributes<HTMLElement>
23
+ export interface LandmarkAria {
24
+ landmarkProps: DOMAttributes
25
25
  }
26
26
 
27
27
  type Landmark = {
28
- ref: MutableRefObject<HTMLElement>,
28
+ ref: MutableRefObject<Element>,
29
29
  role: AriaLandmarkRole,
30
30
  label?: string,
31
- lastFocused?: HTMLElement,
31
+ lastFocused?: FocusableElement,
32
32
  focus: () => void,
33
33
  blur: () => void
34
34
  };
@@ -66,7 +66,7 @@ class LandmarkManager {
66
66
  this.isListening = false;
67
67
  }
68
68
 
69
- private focusLandmark(landmark: HTMLElement) {
69
+ private focusLandmark(landmark: Element) {
70
70
  this.landmarks.find(l => l.ref.current === landmark)?.focus();
71
71
  }
72
72
 
@@ -129,7 +129,7 @@ class LandmarkManager {
129
129
  }
130
130
  }
131
131
 
132
- public removeLandmark(ref: MutableRefObject<HTMLElement>) {
132
+ public removeLandmark(ref: MutableRefObject<Element>) {
133
133
  this.landmarks = this.landmarks.filter(landmark => landmark.ref !== ref);
134
134
  if (this.landmarks.length === 0) {
135
135
  this.teardown();
@@ -169,7 +169,7 @@ class LandmarkManager {
169
169
  * Get the landmark that is the closest parent in the DOM.
170
170
  * Returns undefined if no parent is a landmark.
171
171
  */
172
- private closestLandmark(element: HTMLElement) {
172
+ private closestLandmark(element: Element) {
173
173
  let landmarkMap = new Map(this.landmarks.map(l => [l.ref.current, l]));
174
174
  let currentElement = element;
175
175
  while (!landmarkMap.has(currentElement) && currentElement !== document.body) {
@@ -184,7 +184,7 @@ class LandmarkManager {
184
184
  * If not inside a landmark, will return first landmark.
185
185
  * Returns undefined if there are no landmarks.
186
186
  */
187
- public getNextLandmark(element: HTMLElement, {backward}: {backward?: boolean }) {
187
+ public getNextLandmark(element: Element, {backward}: {backward?: boolean }) {
188
188
  if (this.landmarks.length === 0) {
189
189
  return undefined;
190
190
  }
@@ -216,7 +216,7 @@ class LandmarkManager {
216
216
  e.stopPropagation();
217
217
 
218
218
  let backward = e.shiftKey;
219
- let nextLandmark = this.getNextLandmark(e.target as HTMLElement, {backward});
219
+ let nextLandmark = this.getNextLandmark(e.target as Element, {backward});
220
220
 
221
221
  // If no landmarks, return
222
222
  if (!nextLandmark) {
@@ -253,11 +253,11 @@ class LandmarkManager {
253
253
  * Lets the last focused landmark know it was blurred if something else is focused.
254
254
  */
255
255
  public focusinHandler(e: FocusEvent) {
256
- let currentLandmark = this.closestLandmark(e.target as HTMLElement);
256
+ let currentLandmark = this.closestLandmark(e.target as Element);
257
257
  if (currentLandmark && currentLandmark.ref.current !== e.target) {
258
- this.updateLandmark({ref: currentLandmark.ref, lastFocused: e.target as HTMLElement});
258
+ this.updateLandmark({ref: currentLandmark.ref, lastFocused: e.target as FocusableElement});
259
259
  }
260
- let previousFocusedElement = e.relatedTarget as HTMLElement;
260
+ let previousFocusedElement = e.relatedTarget as Element;
261
261
  if (previousFocusedElement) {
262
262
  let closestPreviousLandmark = this.closestLandmark(previousFocusedElement);
263
263
  if (closestPreviousLandmark && closestPreviousLandmark.ref.current === previousFocusedElement) {
@@ -270,7 +270,7 @@ class LandmarkManager {
270
270
  * Track if the focus is lost to the body. If it is, do cleanup on the landmark that last had focus.
271
271
  */
272
272
  public focusoutHandler(e: FocusEvent) {
273
- let previousFocusedElement = e.target as HTMLElement;
273
+ let previousFocusedElement = e.target as Element;
274
274
  let nextFocusedElement = e.relatedTarget;
275
275
  // the === document seems to be a jest thing for focus to go there on generic blur event such as landmark.blur();
276
276
  // browsers appear to send focus instead to document.body and the relatedTarget is null when that happens
@@ -288,7 +288,7 @@ class LandmarkManager {
288
288
  * @param props - Props for the landmark.
289
289
  * @param ref - Ref to the landmark.
290
290
  */
291
- export function useLandmark(props: AriaLandmarkProps, ref: MutableRefObject<HTMLElement>): LandmarkAria {
291
+ export function useLandmark(props: AriaLandmarkProps, ref: MutableRefObject<FocusableElement>): LandmarkAria {
292
292
  const {
293
293
  role,
294
294
  'aria-label': ariaLabel,