tldraw
Version:
A tiny little drawing editor.
64 lines (63 loc) • 2.21 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { useContainer, useValue } from "@tldraw/editor";
import { Dialog as _Dialog } from "radix-ui";
import { memo, useCallback, useRef } from "react";
import { useDialogs } from "../context/dialogs.mjs";
const TldrawUiDialog = ({ id, component: ModalContent, preventBackgroundClose }) => {
const { removeDialog } = useDialogs();
const mouseDownInsideContentRef = useRef(false);
const container = useContainer();
const handleOpenChange = useCallback(
(isOpen) => {
if (!isOpen) {
removeDialog(id);
}
},
[id, removeDialog]
);
return /* @__PURE__ */ jsx(_Dialog.Root, { onOpenChange: handleOpenChange, defaultOpen: true, children: /* @__PURE__ */ jsx(_Dialog.Portal, { container, children: /* @__PURE__ */ jsx(
_Dialog.Overlay,
{
dir: "ltr",
className: "tlui-dialog__overlay",
onClick: (e) => {
if (mouseDownInsideContentRef.current) return;
if (!preventBackgroundClose && e.target === e.currentTarget) handleOpenChange(false);
},
children: /* @__PURE__ */ jsx(
_Dialog.Content,
{
dir: "ltr",
className: "tlui-dialog__content",
"aria-describedby": void 0,
onMouseDown: () => mouseDownInsideContentRef.current = true,
onMouseUp: () => mouseDownInsideContentRef.current = false,
onInteractOutside: (e) => {
mouseDownInsideContentRef.current = false;
if (preventBackgroundClose) {
e.preventDefault();
}
},
children: /* @__PURE__ */ jsx(
ModalContent,
{
onClose: () => {
mouseDownInsideContentRef.current = false;
handleOpenChange(false);
}
}
)
}
)
}
) }) });
};
const DefaultDialogs = memo(function DefaultDialogs2() {
const { dialogs } = useDialogs();
const dialogsArray = useValue("dialogs", () => dialogs.get(), [dialogs]);
return dialogsArray.map((dialog) => /* @__PURE__ */ jsx(TldrawUiDialog, { ...dialog }, dialog.id));
});
export {
DefaultDialogs
};
//# sourceMappingURL=Dialogs.mjs.map