{
  "version": 3,
  "sources": ["../../../../src/lib/ui/components/Dialogs.tsx"],
  "sourcesContent": ["import { useContainer, useValue } from '@tldraw/editor'\nimport { Dialog as _Dialog } from 'radix-ui'\nimport { memo, useCallback, useRef } from 'react'\nimport { TLUiDialog, useDialogs } from '../context/dialogs'\nimport { useDirection } from '../hooks/useTranslation/useTranslation'\n\n/** @internal */\nconst TldrawUiDialog = ({ id, component: ModalContent, preventBackgroundClose }: TLUiDialog) => {\n\tconst { removeDialog } = useDialogs()\n\n\tconst container = useContainer()\n\tconst dir = useDirection()\n\tconst contentRef = useRef<HTMLDivElement>(null)\n\n\tconst handleOpenChange = useCallback(\n\t\t(isOpen: boolean) => {\n\t\t\tif (!isOpen) {\n\t\t\t\tremoveDialog(id)\n\t\t\t}\n\t\t},\n\t\t[id, removeDialog]\n\t)\n\n\treturn (\n\t\t<_Dialog.Root onOpenChange={handleOpenChange} defaultOpen>\n\t\t\t<_Dialog.Portal container={container}>\n\t\t\t\t{/* Radix renders the scrim and content as siblings. The positioner sits on\n\t\t\t\t    top of the scrim and centers the content, scrolling and padding it when\n\t\t\t\t    it's taller than the viewport. */}\n\t\t\t\t<_Dialog.Overlay dir={dir} className=\"tlui-dialog__overlay\" />\n\t\t\t\t<div dir={dir} className=\"tlui-dialog__positioner\">\n\t\t\t\t\t<_Dialog.Content\n\t\t\t\t\t\tref={contentRef}\n\t\t\t\t\t\tdir={dir}\n\t\t\t\t\t\tclassName=\"tlui-dialog__content\"\n\t\t\t\t\t\taria-describedby={undefined}\n\t\t\t\t\t\tonInteractOutside={(e) => {\n\t\t\t\t\t\t\t// Radix's dismissable layers are layer-aware: an interaction outside the\n\t\t\t\t\t\t\t// topmost layer dismisses only that layer \u2014 an open select, or a dialog\n\t\t\t\t\t\t\t// stacked on top \u2014 leaving lower layers open. onInteractOutside fires for\n\t\t\t\t\t\t\t// both a pointer press and a focus shift outside the dialog; opt out of both\n\t\t\t\t\t\t\t// when the dialog asks to stay open on background interactions (escape still\n\t\t\t\t\t\t\t// closes it).\n\n\t\t\t\t\t\t\t// A touch press is checked against the layers at the following click rather\n\t\t\t\t\t\t\t// than at the press itself, so a press that closes a dialog stacked on top of\n\t\t\t\t\t\t\t// this one arrives here once this one is topmost, and reads as a press\n\t\t\t\t\t\t\t// outside it. A press inside another dialog is never outside this one, and\n\t\t\t\t\t\t\t// stays so after that dialog unmounts and takes the press's target with it.\n\t\t\t\t\t\t\tconst target = e.detail.originalEvent.target\n\t\t\t\t\t\t\tconst pressedDialog =\n\t\t\t\t\t\t\t\ttarget instanceof Element ? target.closest('.tlui-dialog__content') : null\n\t\t\t\t\t\t\tif (pressedDialog && pressedDialog !== contentRef.current) {\n\t\t\t\t\t\t\t\te.preventDefault()\n\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (preventBackgroundClose) {\n\t\t\t\t\t\t\t\te.preventDefault()\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ModalContent onClose={() => handleOpenChange(false)} />\n\t\t\t\t\t</_Dialog.Content>\n\t\t\t\t</div>\n\t\t\t</_Dialog.Portal>\n\t\t</_Dialog.Root>\n\t)\n}\n\n/** @public @react */\nexport const DefaultDialogs = memo(function DefaultDialogs() {\n\tconst { dialogs } = useDialogs()\n\tconst dialogsArray = useValue('dialogs', () => dialogs.get(), [dialogs])\n\t// Every stacked dialog stays modal (Radix's default). That's what keeps dismiss\n\t// layer-aware: a background press or escape closes only the topmost layer, because\n\t// Radix's focus-scope stack pauses lower dialogs rather than dismissing them. Don't\n\t// make a lower dialog non-modal to work around anything \u2014 without a focus scope it\n\t// dismisses on the focus shift when a nested dialog or select opens, collapsing the\n\t// whole stack.\n\treturn dialogsArray.map((dialog) => <TldrawUiDialog key={dialog.id} {...dialog} />)\n})\n"],
  "mappings": "AAyBG,SAIC,KAJD;AAzBH,SAAS,cAAc,gBAAgB;AACvC,SAAS,UAAU,eAAe;AAClC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