{"version":3,"file":"chunk-Dialog.mjs","names":["DialogPrimitive","ScrollArea.Root","ScrollArea.Viewport"],"sources":["../../src/components/Dialog/Dialog.tsx"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { Dialog as DialogPrimitive, useDialogContext } from '@ark-ui/react/dialog';\nimport { Portal } from '@ark-ui/react/portal';\nimport React, {\n  type ComponentPropsWithoutRef,\n  type ReactNode,\n  type RefObject,\n  createContext,\n  forwardRef,\n  useContext,\n  useEffect,\n  useState,\n} from 'react';\n\nimport { mx } from '@dxos/ui-theme';\nimport { type ThemedClassName } from '@dxos/ui-types';\n\nimport { recipes } from '../../recipes.ts';\nimport { type Size } from '../../sizes.ts';\nimport { Button } from '../Button/Button.tsx';\nimport { Container, type ContainerProps, DefaultGutterProvider } from '../Container/Container.tsx';\nimport { Group } from '../Group/Group.tsx';\nimport { usePopupSize } from '../ScrollArea/PopupScroll.tsx';\nimport * as ScrollArea from '../ScrollArea/ScrollArea.tsx';\n\n/**\n * Marks the control a dialog focuses when it opens (the current constant's role); zag's own initial-focus lookup reads\n * it, ahead of the first tabbable control.\n */\nexport const DIALOG_AUTOFOCUS_ATTRIBUTE = 'data-autofocus';\n\n//\n// Root\n//\n\ntype DialogPlacement = 'start' | 'center' | 'end';\n\ntype DialogRootProps = DialogPrimitive.RootProps & {\n  /**\n   * Where the Content sits unless it says otherwise: a host that opens dialogs it does not render (a layout showing\n   * a surface's Content) places them here.\n   */\n  placement?: DialogPlacement;\n};\n\n/** Lets the Content keep the dialog open on an outside click, since a surface often renders the Content alone. */\nconst OutsideDismissContext = createContext<((dismissable: boolean) => void) | undefined>(undefined);\n\nconst PlacementContext = createContext<DialogPlacement | undefined>(undefined);\n\n/** Ark dialog; content mounts on first open and unmounts on close unless the caller opts out. */\nconst DialogRoot = ({\n  lazyMount = true,\n  unmountOnExit = true,\n  closeOnInteractOutside = true,\n  placement,\n  ...props\n}: DialogRootProps) => {\n  const [contentDismissable, setContentDismissable] = useState(true);\n  return (\n    <PlacementContext.Provider value={placement}>\n      <OutsideDismissContext.Provider value={setContentDismissable}>\n        <DialogPrimitive.Root\n          {...props}\n          closeOnInteractOutside={closeOnInteractOutside && contentDismissable}\n          lazyMount={lazyMount}\n          unmountOnExit={unmountOnExit}\n        />\n      </OutsideDismissContext.Provider>\n    </PlacementContext.Provider>\n  );\n};\n\nDialogRoot.displayName = 'Dialog.Root';\n\n//\n// Trigger\n//\n\ntype DialogTriggerProps = DialogPrimitive.TriggerProps;\n\n/** Use `asChild` to open the dialog from a `Button`. */\nconst DialogTrigger = forwardRef<HTMLButtonElement, DialogTriggerProps>((props, forwardedRef) => (\n  <DialogPrimitive.Trigger {...props} ref={forwardedRef} />\n));\n\nDialogTrigger.displayName = 'Dialog.Trigger';\n\n//\n// Content\n//\n\ntype DialogContentProps = ThemedClassName<DialogPrimitive.ContentProps> & {\n  /** Overrides the size inherited from the trigger's nearest sized ancestor (Phase 4 decision 2); `md` without one. */\n  size?: Size;\n  /** Portals into this element instead of the body (e.g. a sized scope, AUDIT 2.2). */\n  container?: RefObject<HTMLElement | null>;\n  /**\n   * `end` docks the dialog at the viewport's block end (e.g. a chat panel) and `start` hangs it from the top (e.g. a\n   * picker whose list grows downward) instead of centring it; the Root's `placement` otherwise.\n   */\n  placement?: DialogPlacement;\n  /**\n   * `false` drops the scrim and lets pointer events through around the dialog, for a non-modal (`modal={false}`)\n   * dialog that leaves the page usable.\n   */\n  scrim?: boolean;\n  /** `false` keeps the dialog open on a click outside, e.g. while it holds unsaved input; Escape still closes it. */\n  closeOnInteractOutside?: boolean;\n};\n\n/** Portalled surface at `level='raised'` over a scrim, centred in the viewport: a column of Header, Body and Footer. */\nconst DialogContent = forwardRef<HTMLDivElement, DialogContentProps>(\n  (\n    { classNames, size, container, placement: placementProp, scrim = true, closeOnInteractOutside, children, ...props },\n    forwardedRef,\n  ) => {\n    const dialog = useDialogContext();\n    const rootPlacement = useContext(PlacementContext);\n    const placement = placementProp ?? rootPlacement ?? 'center';\n    const setDismissable = useContext(OutsideDismissContext);\n    useEffect(() => {\n      if (closeOnInteractOutside !== false || !setDismissable) {\n        return;\n      }\n      setDismissable(false);\n      return () => setDismissable(true);\n    }, [closeOnInteractOutside, setDismissable]);\n    const dialogSize = usePopupSize(size, dialog.open, [dialog.getTriggerProps().id], 'md');\n    return (\n      <Portal container={container}>\n        {scrim && <DialogPrimitive.Backdrop className={recipes.dialogBackdrop()} />}\n        <DialogPrimitive.Positioner\n          className={recipes.dialogPositioner()}\n          data-placement={placement}\n          data-scrim={scrim ? undefined : 'none'}\n        >\n          <DialogPrimitive.Content\n            {...props}\n            data-surface='raised'\n            data-size={dialogSize}\n            className={mx(recipes.dialogContent(), classNames)}\n            ref={forwardedRef}\n          >\n            {children}\n          </DialogPrimitive.Content>\n        </DialogPrimitive.Positioner>\n      </Portal>\n    );\n  },\n);\n\nDialogContent.displayName = 'Dialog.Content';\n\n//\n// Header\n//\n\ntype DialogHeaderProps = ThemedClassName<ComponentPropsWithoutRef<'div'>>;\n\n/** A block row holding the Title and an optional trailing CloseTrigger. */\nconst DialogHeader = forwardRef<HTMLDivElement, DialogHeaderProps>(({ classNames, ...props }, forwardedRef) => (\n  <div\n    {...props}\n    data-scope='dialog'\n    data-part='header'\n    className={mx(recipes.dialogHeader(), classNames)}\n    ref={forwardedRef}\n  />\n));\n\nDialogHeader.displayName = 'Dialog.Header';\n\n//\n// Title\n//\n\ntype DialogTitleProps = ThemedClassName<DialogPrimitive.TitleProps> & {\n  /** Names the dialog for assistive tech without showing a heading. */\n  srOnly?: boolean;\n};\n\nconst DialogTitle = forwardRef<HTMLHeadingElement, DialogTitleProps>(\n  ({ classNames, srOnly, ...props }, forwardedRef) => (\n    <DialogPrimitive.Title\n      {...props}\n      data-sr-only={srOnly ? '' : undefined}\n      className={mx(recipes.dialogTitle(), classNames)}\n      ref={forwardedRef}\n    />\n  ),\n);\n\nDialogTitle.displayName = 'Dialog.Title';\n\n//\n// Description\n//\n\ntype DialogDescriptionProps = ThemedClassName<DialogPrimitive.DescriptionProps> & {\n  /** Describes the dialog for assistive tech without showing the text. */\n  srOnly?: boolean;\n};\n\nconst DialogDescription = forwardRef<HTMLParagraphElement, DialogDescriptionProps>(\n  ({ classNames, srOnly, ...props }, forwardedRef) => (\n    <DialogPrimitive.Description\n      {...props}\n      data-sr-only={srOnly ? '' : undefined}\n      className={mx(recipes.dialogDescription(), classNames)}\n      ref={forwardedRef}\n    />\n  ),\n);\n\nDialogDescription.displayName = 'Dialog.Description';\n\n//\n// CloseTrigger\n//\n\ntype DialogCloseTriggerProps = Omit<DialogPrimitive.CloseTriggerProps, 'children'> & {\n  /** With `asChild`, the child (e.g. a Cancel `Button`) closes the dialog instead of the default icon button. */\n  children?: ReactNode;\n  icon?: string;\n  label?: string;\n};\n\nconst DialogCloseTrigger = forwardRef<HTMLButtonElement, DialogCloseTriggerProps>(\n  ({ asChild, children, icon = 'ph--x--regular', label = 'Close', ...props }, forwardedRef) =>\n    asChild ? (\n      <DialogPrimitive.CloseTrigger {...props} asChild ref={forwardedRef}>\n        {children}\n      </DialogPrimitive.CloseTrigger>\n    ) : (\n      <DialogPrimitive.CloseTrigger {...props} asChild ref={forwardedRef}>\n        <Button icon={icon} label={label} iconOnly />\n      </DialogPrimitive.CloseTrigger>\n    ),\n);\n\nDialogCloseTrigger.displayName = 'Dialog.CloseTrigger';\n\n//\n// Body\n//\n\ntype DialogBodyProps = ThemedClassName<Pick<ScrollArea.RootProps, 'mode' | 'width' | 'native'>> &\n  Pick<ContainerProps, 'gap'> & {\n    /** `center` holds the content in the middle of the Body, both ways, rather than at its start. */\n    align?: 'start' | 'center';\n    children?: ReactNode;\n  };\n\n/**\n * Composed scroll (decision 5): a `gutter='md'` Container as the viewport, so the thumb sits in the end gutter; `gap`\n * spaces its rows, since they are the Container's own items.\n * The element carries ScrollArea's `data-scope`, since parts cannot rescope a composed child (finding 10).\n */\nconst DialogBody = forwardRef<HTMLDivElement, DialogBodyProps>(\n  ({ classNames, gap, align, children, ...props }, forwardedRef) => (\n    <ScrollArea.Root {...props} data-align={align} classNames={mx(recipes.dialogBody(), classNames)} ref={forwardedRef}>\n      <ScrollArea.Viewport asChild>\n        <Container gutter='md' gap={gap}>\n          {/* Its direct content (a form's Viewport) joins these rails rather than nesting a second inset. */}\n          <DefaultGutterProvider gutter='inherit'>{children}</DefaultGutterProvider>\n        </Container>\n      </ScrollArea.Viewport>\n    </ScrollArea.Root>\n  ),\n);\n\nDialogBody.displayName = 'Dialog.Body';\n\n//\n// Footer\n//\n\ntype DialogFooterProps = ThemedClassName<ComponentPropsWithoutRef<'div'>>;\n\n/**\n * An end-justified `Group` of actions; the child div wins the merge, so the part keeps the dialog scope. The\n * actions stay regular-sized in a small dialog, since they are the dialog's primary targets.\n */\nconst DialogFooter = forwardRef<HTMLDivElement, DialogFooterProps>(({ classNames, ...props }, forwardedRef) => (\n  <Group asChild justify='end'>\n    <div\n      data-size='md'\n      {...props}\n      data-scope='dialog'\n      data-part='footer'\n      className={mx(recipes.dialogFooter(), classNames)}\n      ref={forwardedRef}\n    />\n  </Group>\n));\n\nDialogFooter.displayName = 'Dialog.Footer';\nexport type {\n  DialogBodyProps as BodyProps,\n  DialogCloseTriggerProps as CloseTriggerProps,\n  DialogContentProps as ContentProps,\n  DialogDescriptionProps as DescriptionProps,\n  DialogFooterProps as FooterProps,\n  DialogHeaderProps as HeaderProps,\n  DialogPlacement as Placement,\n  DialogRootProps as RootProps,\n  DialogTitleProps as TitleProps,\n  DialogTriggerProps as TriggerProps,\n};\n\nexport {\n  DialogBody as Body,\n  DialogCloseTrigger as CloseTrigger,\n  DialogContent as Content,\n  DialogDescription as Description,\n  DialogFooter as Footer,\n  DialogHeader as Header,\n  DialogRoot as Root,\n  DialogTitle as Title,\n  DialogTrigger as Trigger,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,6BAA6B;;AAiB1C,IAAM,wBAAwB,cAA4D,KAA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