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T,SAAS,cACT,oDAAoD;YACpD,SAAS,SACT,SAAS,WACT,SAAS,eAET,QAAQ,IAAI,CAAC,CAAC,2DAA2D,EAAE,KAAK,EAAE,CAAC;QAEvF;IACF,GAAG;QAAC;QAAK,MAAM,UAAU;KAAC;IAE1B,aAAa;IACb,IAAI,WAAW,SAAS,CAAA,GAAA,YAAI,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG;IAE7E,qBAAO,CAAA,GAAA,YAAI,EAAE,YAAY,CAAC,OAAO;QAC/B,GAAG,CAAA,GAAA,yCAAS,EAAE,gBAAgB,MAAM,KAAK,CAAC;QAC1C,aAAa;QACb,KAAK,CAAA,GAAA,yCAAQ,EAAE,UAAU;IAC3B;AACF","sources":["packages/react-aria/src/interactions/useFocusable.tsx"],"sourcesContent":["/*\n * Copyright 2020 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 {\n  DOMAttributes,\n  FocusableDOMProps,\n  FocusableElement,\n  FocusableProps,\n  RefObject\n} from '@react-types/shared';\nimport {focusSafely} from './focusSafely';\nimport {getOwnerWindow} from '../utils/domHelpers';\nimport {isFocusable} from '../utils/isFocusable';\nimport {mergeProps} from '../utils/mergeProps';\nimport {mergeRefs} from '../utils/mergeRefs';\nimport React, {\n  ForwardedRef,\n  forwardRef,\n  MutableRefObject,\n  ReactElement,\n  ReactNode,\n  useContext,\n  useEffect,\n  useRef\n} from 'react';\nimport {useFocus} from './useFocus';\nimport {useKeyboard} from './useKeyboard';\nimport {useObjectRef} from '../utils/useObjectRef';\nimport {useSyncRef} from '../utils/useSyncRef';\n\nexport interface FocusableOptions<T = FocusableElement>\n  extends FocusableProps<T>, FocusableDOMProps {\n  /** Whether focus should be disabled. */\n  isDisabled?: boolean;\n}\n\nexport interface FocusableProviderProps extends DOMAttributes {\n  /** The child element to provide DOM props to. */\n  children?: ReactNode;\n}\n\ninterface FocusableContextValue extends FocusableProviderProps {\n  ref?: MutableRefObject<FocusableElement | null>;\n}\n\n// Exported for @react-aria/collections, which forwards this context.\n/** @private */\nexport let FocusableContext: React.Context<FocusableContextValue | null> =\n  React.createContext<FocusableContextValue | null>(null);\n\nfunction useFocusableContext(ref: RefObject<FocusableElement | null>): FocusableContextValue {\n  let context = useContext(FocusableContext) || {};\n  useSyncRef(context, ref);\n\n  // eslint-disable-next-line\n  let {ref: _, ...otherProps} = context;\n  return otherProps;\n}\n\n/**\n * Provides DOM props to the nearest focusable child.\n */\nexport const FocusableProvider: React.ForwardRefExoticComponent<\n  FocusableProviderProps & React.RefAttributes<FocusableElement>\n> = React.forwardRef(function FocusableProvider(\n  props: FocusableProviderProps,\n  ref: ForwardedRef<FocusableElement>\n) {\n  let {children, ...otherProps} = props;\n  let objRef = useObjectRef(ref);\n  let context = {\n    ...otherProps,\n    ref: objRef\n  };\n\n  return <FocusableContext.Provider value={context}>{children}</FocusableContext.Provider>;\n});\n\nexport interface FocusableAria {\n  /** Props for the focusable element. */\n  focusableProps: DOMAttributes;\n}\n\n/**\n * Used to make an element focusable and capable of auto focus.\n */\nexport function useFocusable<T extends FocusableElement = FocusableElement>(\n  props: FocusableOptions<T>,\n  domRef: RefObject<FocusableElement | null>\n): FocusableAria {\n  let {focusProps} = useFocus(props);\n  let {keyboardProps} = useKeyboard(props);\n  let interactions = mergeProps(focusProps, keyboardProps);\n  let domProps = useFocusableContext(domRef);\n  let interactionProps = props.isDisabled ? {} : domProps;\n  let autoFocusRef = useRef(props.autoFocus);\n\n  useEffect(() => {\n    if (autoFocusRef.current && domRef.current) {\n      focusSafely(domRef.current);\n    }\n    autoFocusRef.current = false;\n  }, [domRef]);\n\n  // Always set a tabIndex so that Safari allows focusing native buttons and inputs.\n  let tabIndex: number | undefined = props.excludeFromTabOrder ? -1 : 0;\n  if (props.isDisabled) {\n    tabIndex = undefined;\n  }\n\n  return {\n    focusableProps: mergeProps(\n      {\n        ...interactions,\n        tabIndex\n      },\n      interactionProps\n    )\n  };\n}\n\nexport interface FocusableComponentProps extends FocusableOptions {\n  children: ReactElement<DOMAttributes, string>;\n}\n\nexport const Focusable: React.ForwardRefExoticComponent<\n  FocusableComponentProps & React.RefAttributes<FocusableElement>\n> = forwardRef(\n  ({children, ...props}: FocusableComponentProps, ref: ForwardedRef<FocusableElement>) => {\n    ref = useObjectRef(ref);\n    let {focusableProps} = useFocusable(props, ref);\n    let child = React.Children.only(children);\n\n    useEffect(() => {\n      if (process.env.NODE_ENV === 'production') {\n        return;\n      }\n\n      let el = ref.current;\n      if (!el || !(el instanceof getOwnerWindow(el).Element)) {\n        console.error('<Focusable> child must forward its ref to a DOM element.');\n        return;\n      }\n\n      if (!props.isDisabled && !isFocusable(el)) {\n        console.warn(\n          '<Focusable> child must be focusable. Please ensure the tabIndex prop is passed through.'\n        );\n        return;\n      }\n\n      if (\n        el.localName !== 'button' &&\n        el.localName !== 'input' &&\n        el.localName !== 'select' &&\n        el.localName !== 'textarea' &&\n        el.localName !== 'a' &&\n        el.localName !== 'area' &&\n        el.localName !== 'summary' &&\n        el.localName !== 'img' &&\n        el.localName !== 'svg'\n      ) {\n        let role = el.getAttribute('role');\n        if (!role) {\n          console.warn('<Focusable> child must have an interactive ARIA role.');\n        } else if (\n          // https://w3c.github.io/aria/#widget_roles\n          role !== 'application' &&\n          role !== 'button' &&\n          role !== 'checkbox' &&\n          role !== 'combobox' &&\n          role !== 'gridcell' &&\n          role !== 'link' &&\n          role !== 'menuitem' &&\n          role !== 'menuitemcheckbox' &&\n          role !== 'menuitemradio' &&\n          role !== 'option' &&\n          role !== 'radio' &&\n          role !== 'searchbox' &&\n          role !== 'separator' &&\n          role !== 'slider' &&\n          role !== 'spinbutton' &&\n          role !== 'switch' &&\n          role !== 'tab' &&\n          role !== 'tabpanel' &&\n          role !== 'textbox' &&\n          role !== 'treeitem' &&\n          // aria-describedby is also announced on these roles\n          role !== 'img' &&\n          role !== 'meter' &&\n          role !== 'progressbar'\n        ) {\n          console.warn(`<Focusable> child must have an interactive ARIA role. Got \"${role}\".`);\n        }\n      }\n    }, [ref, props.isDisabled]);\n\n    // @ts-ignore\n    let childRef = parseInt(React.version, 10) < 19 ? child.ref : child.props.ref;\n\n    return React.cloneElement(child, {\n      ...mergeProps(focusableProps, child.props),\n      // @ts-ignore\n      ref: mergeRefs(childRef, ref)\n    });\n  }\n);\n"],"names":[],"version":3,"file":"useFocusable.mjs.map"}