{"version":3,"file":"command-dialog.cjs","sources":["../../../components/command/command-dialog.tsx"],"sourcesContent":["'use client';\n\nimport { Dialog as DialogPrimitive } from '@base-ui/react/dialog';\nimport { cx } from 'class-variance-authority';\nimport { forwardRef, useRef } from 'react';\nimport styles from './command.module.css';\n\nexport const CommandDialog = (props: DialogPrimitive.Root.Props) => (\n  <DialogPrimitive.Root {...props} />\n);\nCommandDialog.displayName = 'Command.Dialog';\n\nexport const CommandDialogTrigger = forwardRef<\n  HTMLButtonElement,\n  DialogPrimitive.Trigger.Props\n>((props, ref) => (\n  <DialogPrimitive.Trigger\n    ref={ref}\n    data-slot='command-dialog-trigger'\n    {...props}\n  />\n));\nCommandDialogTrigger.displayName = 'Command.DialogTrigger';\n\nexport interface CommandDialogContentProps extends DialogPrimitive.Popup.Props {\n  width?: string | number;\n}\n\nexport function CommandDialogContent({\n  className,\n  children,\n  width,\n  style,\n  ...props\n}: CommandDialogContentProps) {\n  const popupRef = useRef<HTMLDivElement>(null);\n  /* Remember what had focus before the palette opened. Base UI otherwise\n     always returns focus to the trigger on close, so the trigger shows a focus\n     ring even when the palette was opened by a keyboard shortcut (the trigger\n     was never focused). Restoring the real origin matches how command palettes\n     usually behave: focus goes back to the trigger only when you opened it by\n     clicking the trigger. */\n  const originRef = useRef<HTMLElement | null>(null);\n\n  return (\n    <DialogPrimitive.Portal>\n      <DialogPrimitive.Viewport\n        data-slot='command-dialog-viewport'\n        className={styles.viewport}\n      >\n        <DialogPrimitive.Popup\n          ref={popupRef}\n          data-slot='command-dialog-content'\n          className={cx(styles.dialogPopup, className)}\n          style={{ width, ...style }}\n          initialFocus={openType => {\n            /* Runs before focus moves into the popup, so activeElement is\n               still the element focused before opening. */\n            originRef.current = document.activeElement as HTMLElement | null;\n            /* Keep Base UI's default: focus the popup on touch to avoid\n               popping the on-screen keyboard, otherwise the first tabbable. */\n            return openType === 'touch' ? popupRef.current : true;\n          }}\n          finalFocus={() => {\n            const origin = originRef.current;\n            /* Only restore to a real, still-connected element. Returning false\n               skips focus return (Base UI would otherwise fall back to the\n               trigger or the page's first tabbable). */\n            return origin && origin !== document.body && origin.isConnected\n              ? origin\n              : false;\n          }}\n          {...props}\n        >\n          {children}\n        </DialogPrimitive.Popup>\n      </DialogPrimitive.Viewport>\n    </DialogPrimitive.Portal>\n  );\n}\nCommandDialogContent.displayName = 'Command.DialogContent';\n"],"names":[],"mappings":";;;;;;;;;AAOa;AAGb;AAEO;AAUP;AAMgB;AAOd;AACA;;;;;AAK2B;AAC3B;;AAcU;AAC+C;AAC/C;AACA;AACmE;AACnE;AACF;AAEE;AACA;;AAE4C;;AAE1C;;;AAUd;AACA;;;;"}