{
  "version": 3,
  "sources": ["../../src/dropdown/index.tsx"],
  "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n/**\n * WordPress dependencies\n */\nimport { useRef, useState } from '@wordpress/element';\nimport { useMergeRefs } from '@wordpress/compose';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { contextConnect, useContextSystem } from '../context';\nimport { useControlledValue } from '../utils/hooks';\nimport Popover from '../popover';\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst UnconnectedDropdown = (props, forwardedRef) => {\n  const {\n    renderContent,\n    renderToggle,\n    className,\n    contentClassName,\n    expandOnMobile,\n    headerTitle,\n    focusOnMount,\n    popoverProps,\n    onClose,\n    onToggle,\n    style,\n    open,\n    defaultOpen,\n    // Deprecated props\n    position,\n    // From context system\n    variant\n  } = useContextSystem(props, 'Dropdown');\n  if (position !== undefined) {\n    deprecated('`position` prop in wp.components.Dropdown', {\n      since: '6.2',\n      alternative: '`popoverProps.placement` prop',\n      hint: 'Note that the `position` prop will override any values passed through the `popoverProps.placement` prop.'\n    });\n  }\n\n  // Use internal state instead of a ref to make sure that the component\n  // re-renders when the popover's anchor updates.\n  const [fallbackPopoverAnchor, setFallbackPopoverAnchor] = useState(null);\n  const containerRef = useRef(null);\n  const [isOpen, setIsOpen] = useControlledValue({\n    defaultValue: defaultOpen,\n    value: open,\n    onChange: onToggle\n  });\n\n  /**\n   * Closes the popover when focus leaves it unless the toggle was pressed or\n   * focus has moved to a separate dialog. The former is to let the toggle\n   * handle closing the popover and the latter is to preserve presence in\n   * case a dialog has opened, allowing focus to return when it's dismissed.\n   */\n  function closeIfFocusOutside() {\n    if (!containerRef.current) {\n      return;\n    }\n    const {\n      ownerDocument\n    } = containerRef.current;\n    const dialog = ownerDocument?.activeElement?.closest('[role=\"dialog\"]');\n    if (!containerRef.current.contains(ownerDocument.activeElement) && (!dialog || dialog.contains(containerRef.current))) {\n      close();\n    }\n  }\n  function close() {\n    onClose?.();\n    setIsOpen(false);\n  }\n  const args = {\n    isOpen: !!isOpen,\n    onToggle: () => setIsOpen(!isOpen),\n    onClose: close\n  };\n  const popoverPropsHaveAnchor = !!popoverProps?.anchor ||\n  // Note: `anchorRef`, `getAnchorRect` and `anchorRect` are deprecated and\n  // be removed from `Popover` from WordPress 6.3\n  !!popoverProps?.anchorRef || !!popoverProps?.getAnchorRect || !!popoverProps?.anchorRect;\n  return /*#__PURE__*/_jsxs(\"div\", {\n    className: className,\n    ref: useMergeRefs([containerRef, forwardedRef, setFallbackPopoverAnchor])\n    // Some UAs focus the closest focusable parent when the toggle is\n    // clicked. Making this div focusable ensures such UAs will focus\n    // it and `closeIfFocusOutside` can tell if the toggle was clicked.\n    ,\n    tabIndex: -1,\n    style: style,\n    children: [renderToggle(args), isOpen && /*#__PURE__*/_jsx(Popover, {\n      position: position,\n      onClose: close,\n      onFocusOutside: closeIfFocusOutside,\n      expandOnMobile: expandOnMobile,\n      headerTitle: headerTitle,\n      focusOnMount: focusOnMount\n      // This value is used to ensure that the dropdowns\n      // align with the editor header by default.\n      ,\n      offset: 13,\n      anchor: !popoverPropsHaveAnchor ? fallbackPopoverAnchor : undefined,\n      variant: variant,\n      ...popoverProps,\n      className: clsx('components-dropdown__content', popoverProps?.className, contentClassName),\n      children: renderContent(args)\n    })]\n  });\n};\n\n/**\n * Renders a button that opens a floating content modal when clicked.\n *\n * ```jsx\n * import { Button, Dropdown } from '@wordpress/components';\n *\n * const MyDropdown = () => (\n *   <Dropdown\n *     className=\"my-container-class-name\"\n *     contentClassName=\"my-dropdown-content-classname\"\n *     popoverProps={ { placement: 'bottom-start' } }\n *     renderToggle={ ( { isOpen, onToggle } ) => (\n *       <Button\n *         variant=\"primary\"\n *         onClick={ onToggle }\n *         aria-expanded={ isOpen }\n *       >\n *         Toggle Dropdown!\n *       </Button>\n *     ) }\n *     renderContent={ () => <div>This is the content of the dropdown.</div> }\n *   />\n * );\n * ```\n */\nexport const Dropdown = contextConn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