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],"sourcesContent":["/*\n * Copyright 2023 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 {classNames} from '../utils/classNames';\n\nimport {DOMRefValue, ItemProps, Key} from '@react-types/shared';\nimport {FocusScope} from 'react-aria/FocusScope';\nimport {getInteractionModality} from 'react-aria/private/interactions/useFocusVisible';\nimport helpStyles from '@adobe/spectrum-css-temp/components/contextualhelp/vars.css';\nimport {isFocusWithin, nodeContains} from 'react-aria/private/utils/shadowdom/DOMFunctions';\nimport {Popover} from '../overlays/Popover';\nimport React, {JSX, KeyboardEventHandler, ReactElement, useEffect, useRef, useState} from 'react';\nimport ReactDOM from 'react-dom';\nimport {SlotProvider} from '../utils/Slots';\nimport styles from '@adobe/spectrum-css-temp/components/menu/vars.css';\nimport {SubmenuTriggerContext, useMenuStateContext} from './context';\nimport {TrayHeaderWrapper} from './Menu';\nimport {unwrapDOMRef} from '../utils/useDOMRef';\nimport {useIsMobileDevice} from '../utils/useIsMobileDevice';\nimport {useSubmenuTrigger} from 'react-aria/useMenu';\nimport {useSubmenuTriggerState} from 'react-stately/useMenuTriggerState';\n\ninterface MenuDialogTriggerProps {\n  /** Whether the menu item is currently unavailable. */\n  isUnavailable?: boolean;\n  /** The triggering Item and the Dialog, respectively. */\n  children: [ReactElement, ReactElement];\n}\n\ninterface InternalMenuDialogTriggerProps extends MenuDialogTriggerProps {\n  targetKey: Key;\n}\n\nexport interface SpectrumMenuDialogTriggerProps extends MenuDialogTriggerProps {}\n\nfunction ContextualHelpTrigger(props: InternalMenuDialogTriggerProps): ReactElement {\n  let {isUnavailable = false, targetKey} = props;\n\n  let triggerRef = useRef<HTMLLIElement>(null);\n  let popoverRef = useRef<DOMRefValue<HTMLDivElement> | null>(null);\n  let {\n    popoverContainer,\n    trayContainerRef,\n    rootMenuTriggerState,\n    menu: parentMenuRef,\n    state\n  } = useMenuStateContext()!;\n  let submenuTriggerState = useSubmenuTriggerState(\n    {triggerKey: targetKey},\n    {...rootMenuTriggerState!, ...state}\n  );\n  let submenuRef = unwrapDOMRef(popoverRef);\n  let {submenuTriggerProps, popoverProps} = useSubmenuTrigger(\n    {\n      parentMenuRef,\n      submenuRef,\n      type: 'dialog',\n      isDisabled: !isUnavailable\n    },\n    submenuTriggerState,\n    triggerRef\n  );\n  let isMobile = useIsMobileDevice();\n  let [traySubmenuAnimation, setTraySubmenuAnimation] = useState('');\n  useEffect(() => {\n    if (submenuTriggerState.isOpen) {\n      setTraySubmenuAnimation('spectrum-TraySubmenu-enter');\n    }\n  }, [submenuTriggerState.isOpen]);\n  let slots = {};\n  if (isUnavailable) {\n    slots = {\n      dialog: {\n        UNSAFE_className: classNames(\n          helpStyles,\n          'react-spectrum-ContextualHelp-dialog',\n          {\n            'react-spectrum-ContextualHelp-dialog--isMobile': isMobile\n          },\n          classNames(styles, {\n            'spectrum-Menu-subdialog': !isMobile,\n            [traySubmenuAnimation]: isMobile\n          })\n        )\n      },\n      content: {UNSAFE_className: helpStyles['react-spectrum-ContextualHelp-content']},\n      footer: {UNSAFE_className: helpStyles['react-spectrum-ContextualHelp-footer']}\n    };\n  }\n  let [trigger] = React.Children.toArray(props.children);\n  let [, content] = props.children as [ReactElement, ReactElement];\n\n  let onBlurWithin = e => {\n    if (\n      e.relatedTarget &&\n      popoverRef.current &&\n      !nodeContains(popoverRef.current.UNSAFE_getDOMNode(), e.relatedTarget) &&\n      !(e.relatedTarget === triggerRef.current && getInteractionModality() === 'pointer')\n    ) {\n      if (submenuTriggerState.isOpen) {\n        submenuTriggerState.close();\n      }\n    }\n  };\n\n  let overlay;\n  let tray;\n  let onBackButtonPress = () => {\n    setTraySubmenuAnimation('spectrum-TraySubmenu-exit');\n    setTimeout(() => {\n      submenuTriggerState.close();\n      if (parentMenuRef.current && !isFocusWithin(parentMenuRef.current)) {\n        parentMenuRef.current.focus();\n      }\n    }, 220); // Matches transition duration\n  };\n\n  if (isMobile) {\n    delete submenuTriggerProps.onBlur;\n    delete submenuTriggerProps.onHoverChange;\n    if (trayContainerRef.current && submenuTriggerState.isOpen) {\n      let subDialogKeyDown: KeyboardEventHandler = e => {\n        switch (e.key) {\n          case 'Escape':\n            e.stopPropagation();\n            onBackButtonPress();\n            break;\n        }\n      };\n\n      tray = (\n        <TrayHeaderWrapper\n          isSubmenu\n          parentMenuTreeState={state}\n          rootMenuTriggerState={rootMenuTriggerState}\n          wrapperKeyDown={subDialogKeyDown}\n          onBackButtonPress={onBackButtonPress}>\n          {content}\n        </TrayHeaderWrapper>\n      );\n\n      overlay = ReactDOM.createPortal(tray, trayContainerRef.current);\n    }\n  } else {\n    let onDismissButtonPress = () => {\n      submenuTriggerState.close();\n      parentMenuRef.current?.focus();\n    };\n\n    overlay = (\n      <Popover\n        {...popoverProps}\n        UNSAFE_style={{clipPath: 'unset', overflow: 'visible', filter: 'unset', borderWidth: '0px'}}\n        UNSAFE_className={classNames(styles, 'spectrum-Submenu-popover')}\n        onDismissButtonPress={onDismissButtonPress}\n        onBlurWithin={onBlurWithin}\n        container={popoverContainer!}\n        state={submenuTriggerState}\n        ref={popoverRef}\n        triggerRef={triggerRef}\n        placement=\"end top\"\n        containerPadding={0}\n        hideArrow\n        enableBothDismissButtons>\n        <FocusScope restoreFocus contain>\n          {content}\n        </FocusScope>\n      </Popover>\n    );\n  }\n\n  return (\n    <>\n      <SubmenuTriggerContext.Provider value={{isUnavailable, triggerRef, ...submenuTriggerProps}}>\n        {trigger}\n      </SubmenuTriggerContext.Provider>\n      <SlotProvider slots={slots}>{submenuTriggerState.isOpen && overlay}</SlotProvider>\n    </>\n  );\n}\n\nContextualHelpTrigger.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>) {\n  let childArray: ReactElement[] = [];\n  React.Children.forEach(props.children, child => {\n    if (React.isValidElement(child)) {\n      childArray.push(child);\n    }\n  });\n  let [trigger] = childArray;\n  let [, content] = props.children as [ReactElement, ReactElement];\n\n  yield {\n    element: React.cloneElement(trigger, {\n      ...(trigger.props as any),\n      hasChildItems: true,\n      isTrigger: true\n    }),\n    wrapper: element => (\n      <ContextualHelpTrigger key={element.key} targetKey={element.key} {...props}>\n        {element}\n        {content}\n      </ContextualHelpTrigger>\n    )\n  };\n};\n\nlet _Item = ContextualHelpTrigger as unknown as (\n  props: SpectrumMenuDialogTriggerProps\n) => JSX.Element;\nexport {_Item as ContextualHelpTrigger};\n"],"names":[],"version":3,"file":"ContextualHelpTrigger.mjs.map"}