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GAAG;QAAC;QAAmB;KAAI;IAE3B,OAAO;QACL,eAAe;kBACb;YACA,UAAU,oBAAoB,KAAK;YACnC,cAAc;YACd,mBAAmB;QACrB;IACF;AACF","sources":["packages/react-aria/src/landmark/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\nimport {AriaLabelingProps, DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\nimport {getEventTarget, nodeContains} from '../utils/shadowdom/DOMFunctions';\nimport {useCallback, useEffect, useState} from 'react';\nimport {useLayoutEffect} from '../utils/useLayoutEffect';\nimport {useSyncExternalStore} from 'use-sync-external-store/shim/index.js';\n\nexport type AriaLandmarkRole = 'main' | 'region' | 'search' | 'navigation' | 'form' | 'banner' | 'contentinfo' | 'complementary';\n\nexport interface AriaLandmarkProps extends AriaLabelingProps {\n  role: AriaLandmarkRole,\n  focus?: (direction: 'forward' | 'backward') => void\n}\n\nexport interface LandmarkAria {\n  landmarkProps: DOMAttributes\n}\n\n// Increment this version number whenever the\n// LandmarkManagerApi or Landmark interfaces change.\nconst LANDMARK_API_VERSION = 1;\n\n// Minimal API for LandmarkManager that must continue to work between versions.\n// Changes to this interface are considered breaking. New methods/properties are\n// safe to add, but changes or removals are not allowed (same as public APIs).\ninterface LandmarkManagerApi {\n  version: number,\n  createLandmarkController(): LandmarkController,\n  registerLandmark(landmark: Landmark): () => void\n}\n\n// Changes to this interface are considered breaking.\n// New properties MUST be optional so that registering a landmark\n// from an older version of useLandmark against a newer version of\n// LandmarkManager does not crash.\ninterface Landmark {\n  ref: RefObject<FocusableElement | null>,\n  role: AriaLandmarkRole,\n  label?: string,\n  lastFocused?: FocusableElement,\n  focus: (direction: 'forward' | 'backward') => void,\n  blur: () => void\n}\n\nexport interface LandmarkControllerOptions {\n  /**\n   * The element from which to start navigating.\n   * @default document.activeElement\n   */\n  from?: FocusableElement\n}\n\n/** A LandmarkController allows programmatic navigation of landmarks. */\nexport interface LandmarkController {\n  /** Moves focus to the next landmark. */\n  focusNext(opts?: LandmarkControllerOptions): boolean,\n  /** Moves focus to the previous landmark. */\n  focusPrevious(opts?: LandmarkControllerOptions): boolean,\n  /** Moves focus to the main landmark. */\n  focusMain(): boolean,\n  /** Moves focus either forward or backward in the landmark sequence. */\n  navigate(direction: 'forward' | 'backward', opts?: LandmarkControllerOptions): boolean,\n  /**\n   * Disposes the landmark controller. When no landmarks are registered, and no\n   * controllers are active, the landmark keyboard listeners are removed from the page.\n   */\n  dispose(): void\n}\n\n// Symbol under which the singleton landmark manager instance is attached to the document.\nconst landmarkSymbol = Symbol.for('react-aria-landmark-manager');\n\nfunction subscribe(fn: () => void) {\n  document.addEventListener('react-aria-landmark-manager-change', fn);\n  return () => document.removeEventListener('react-aria-landmark-manager-change', fn);\n}\n\nfunction getLandmarkManager(): LandmarkManagerApi | null {\n  if (typeof document === 'undefined') {\n    return null;\n  }\n\n  // Reuse an existing instance if it has the same or greater version.\n  let instance = document[landmarkSymbol];\n  if (instance && instance.version >= LANDMARK_API_VERSION) {\n    return instance;\n  }\n\n  // Otherwise, create a new instance and dispatch an event so anything using the existing\n  // instance updates and re-registers their landmarks with the new one.\n  document[landmarkSymbol] = new LandmarkManager();\n  document.dispatchEvent(new CustomEvent('react-aria-landmark-manager-change'));\n  return document[landmarkSymbol];\n}\n\n// Subscribes a React component to the current landmark manager instance.\nfunction useLandmarkManager(): LandmarkManagerApi | null {\n  return useSyncExternalStore(subscribe, getLandmarkManager, getLandmarkManager);\n}\n\nclass LandmarkManager implements LandmarkManagerApi {\n  private landmarks: Array<Landmark> = [];\n  private isListening = false;\n  private refCount = 0;\n  public version = LANDMARK_API_VERSION;\n\n  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  private setupIfNeeded() {\n    if (this.isListening) {\n      return;\n    }\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 teardownIfNeeded() {\n    if (!this.isListening || this.landmarks.length > 0 || this.refCount > 0) {\n      return;\n    }\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: FocusableElement, direction: 'forward' | 'backward') {\n    this.landmarks.find(l => l.ref.current === landmark)?.focus?.(direction);\n  }\n\n  /**\n   * Return set of landmarks with a specific role.\n   */\n  private 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  private getLandmarkByRole(role: AriaLandmarkRole) {\n    return this.landmarks.find(l => l.role === role);\n  }\n\n  private addLandmark(newLandmark: Landmark) {\n    this.setupIfNeeded();\n    if (this.landmarks.find(landmark => landmark.ref === newLandmark.ref) || !newLandmark.ref.current) {\n      return;\n    }\n\n    if (this.landmarks.filter(landmark => landmark.role === 'main').length > 1 && process.env.NODE_ENV !== 'production') {\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      this.checkLabels(newLandmark.role);\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    this.checkLabels(newLandmark.role);\n  }\n\n  private 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  private removeLandmark(ref: RefObject<Element | null>) {\n    this.landmarks = this.landmarks.filter(landmark => landmark.ref !== ref);\n    this.teardownIfNeeded();\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 && process.env.NODE_ENV !== 'production') {\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 if (process.env.NODE_ENV !== 'production') {\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: FocusableElement) {\n    let landmarkMap = new Map(this.landmarks.map(l => [l.ref.current, l]));\n    let currentElement = element;\n    while (currentElement && !landmarkMap.has(currentElement) && currentElement !== document.body && currentElement.parentElement) {\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  private getNextLandmark(element: FocusableElement, {backward}: {backward?: boolean }) {\n    let currentLandmark = this.closestLandmark(element);\n    let nextLandmarkIndex = backward ? this.landmarks.length - 1 : 0;\n    if (currentLandmark) {\n      nextLandmarkIndex = this.landmarks.indexOf(currentLandmark) + (backward ? -1 : 1);\n    }\n\n    let wrapIfNeeded = () => {\n      // When we reach the end of the landmark sequence, fire a custom event that can be listened for by applications.\n      // If this event is canceled, we return immediately. This can be used to implement landmark navigation across iframes.\n      if (nextLandmarkIndex < 0) {\n        if (!element.dispatchEvent(new CustomEvent('react-aria-landmark-navigation', {detail: {direction: 'backward'}, bubbles: true, cancelable: true}))) {\n          return true;\n        }\n\n        nextLandmarkIndex = this.landmarks.length - 1;\n      } else if (nextLandmarkIndex >= this.landmarks.length) {\n        if (!element.dispatchEvent(new CustomEvent('react-aria-landmark-navigation', {detail: {direction: 'forward'}, bubbles: true, cancelable: true}))) {\n          return true;\n        }\n\n        nextLandmarkIndex = 0;\n      }\n\n      if (nextLandmarkIndex < 0 || nextLandmarkIndex >= this.landmarks.length) {\n        return true;\n      }\n\n      return false;\n    };\n\n    if (wrapIfNeeded()) {\n      return undefined;\n    }\n\n    // Skip over hidden landmarks.\n    let i = nextLandmarkIndex;\n    while (this.landmarks[nextLandmarkIndex].ref.current?.closest('[aria-hidden=true]')) {\n      nextLandmarkIndex += backward ? -1 : 1;\n      if (wrapIfNeeded()) {\n        return undefined;\n      }\n\n      if (nextLandmarkIndex === i) {\n        break;\n      }\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  private f6Handler(e: KeyboardEvent) {\n    if (e.key === 'F6') {\n      // If alt key pressed, focus main landmark, otherwise navigate forward or backward based on shift key.\n      let handled = e.altKey ? this.focusMain() : this.navigate(getEventTarget(e) as FocusableElement, e.shiftKey);\n      if (handled) {\n        e.preventDefault();\n        e.stopPropagation();\n      }\n    }\n  }\n\n  private focusMain() {\n    let main = this.getLandmarkByRole('main');\n    if (main && main.ref.current && main.ref.current.isConnected) {\n      this.focusLandmark(main.ref.current, 'forward');\n      return true;\n    }\n\n    return false;\n  }\n\n  private navigate(from: FocusableElement, backward: boolean) {\n    let nextLandmark = this.getNextLandmark(from, {\n      backward\n    });\n\n    if (!nextLandmark) {\n      return false;\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 (nodeContains(document.body, lastFocused)) {\n        lastFocused.focus();\n        return true;\n      }\n    }\n\n    // Otherwise, focus the landmark itself\n    if (nextLandmark.ref.current && nextLandmark.ref.current.isConnected) {\n      this.focusLandmark(nextLandmark.ref.current, backward ? 'backward' : 'forward');\n      return true;\n    }\n\n    return false;\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  private focusinHandler(e: FocusEvent) {\n    let currentLandmark = this.closestLandmark(getEventTarget(e) as FocusableElement);\n    if (currentLandmark && currentLandmark.ref.current !== getEventTarget(e)) {\n      this.updateLandmark({ref: currentLandmark.ref, lastFocused: getEventTarget(e) as FocusableElement});\n    }\n    let previousFocusedElement = e.relatedTarget as FocusableElement;\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  private focusoutHandler(e: FocusEvent) {\n    let previousFocusedElement = getEventTarget(e) as FocusableElement;\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  public createLandmarkController(): LandmarkController {\n    let instance: LandmarkManager | null = this;\n    instance.refCount++;\n    instance.setupIfNeeded();\n    return {\n      navigate(direction, opts) {\n        let element = opts?.from || (document!.activeElement as FocusableElement);\n        return instance!.navigate(element, direction === 'backward');\n      },\n      focusNext(opts) {\n        let element = opts?.from || (document!.activeElement as FocusableElement);\n        return instance!.navigate(element, false);\n      },\n      focusPrevious(opts) {\n        let element = opts?.from || (document!.activeElement as FocusableElement);\n        return instance!.navigate(element, true);\n      },\n      focusMain() {\n        return instance!.focusMain();\n      },\n      dispose() {\n        if (instance) {\n          instance.refCount--;\n          instance.teardownIfNeeded();\n          instance = null;\n        }\n      }\n    };\n  }\n\n  public registerLandmark(landmark: Landmark): () => void {\n    if (this.landmarks.find(l => l.ref === landmark.ref)) {\n      this.updateLandmark(landmark);\n    } else {\n      this.addLandmark(landmark);\n    }\n\n    return () => this.removeLandmark(landmark.ref);\n  }\n}\n\n/** Creates a LandmarkController, which allows programmatic navigation of landmarks. */\nexport function UNSTABLE_createLandmarkController(): LandmarkController {\n  // Get the current landmark manager and create a controller using it.\n  let instance: LandmarkManagerApi | null = getLandmarkManager();\n  let controller = instance?.createLandmarkController();\n\n  let unsubscribe = subscribe(() => {\n    // If the landmark manager changes, dispose the old\n    // controller and create a new one.\n    controller?.dispose();\n    instance = getLandmarkManager();\n    controller = instance?.createLandmarkController();\n  });\n\n  // Return a wrapper that proxies requests to the current controller instance.\n  return {\n    navigate(direction, opts) {\n      return controller!.navigate(direction, opts);\n    },\n    focusNext(opts) {\n      return controller!.focusNext(opts);\n    },\n    focusPrevious(opts) {\n      return controller!.focusPrevious(opts);\n    },\n    focusMain() {\n      return controller!.focusMain();\n    },\n    dispose() {\n      controller?.dispose();\n      unsubscribe();\n      controller = undefined;\n      instance = null;\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: RefObject<FocusableElement | null>): LandmarkAria {\n  const {\n    role,\n    'aria-label': ariaLabel,\n    'aria-labelledby': ariaLabelledby,\n    focus\n  } = props;\n  let manager = useLandmarkManager();\n  let label = ariaLabel || ariaLabelledby;\n  let [isLandmarkFocused, setIsLandmarkFocused] = useState(false);\n\n  let defaultFocus = useCallback(() => {\n    setIsLandmarkFocused(true);\n  }, [setIsLandmarkFocused]);\n\n  let blur = useCallback(() => {\n    setIsLandmarkFocused(false);\n  }, [setIsLandmarkFocused]);\n\n  useLayoutEffect(() => {\n    if (manager) {\n      return manager.registerLandmark({ref, label, role, focus: focus || defaultFocus, blur});\n    }\n  }, [manager, label, ref, role, focus, defaultFocus, blur]);\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      'aria-label': ariaLabel,\n      'aria-labelledby': ariaLabelledby\n    }\n  };\n}\n"],"names":[],"version":3,"file":"useLandmark.cjs.map"}