Make the drag preview always use the tech frame (#87)

Overrides the frameless block frame if generating a drag preview. Also
fixes a type issue with BlockFrame_Tech
This commit is contained in:
Evan Simkowitz 2024-06-27 15:26:40 -07:00 committed by GitHub
parent c9cf88eb5e
commit f1c8d63ab2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -210,8 +210,15 @@ interface BlockFrameProps {
dragHandleRef?: React.RefObject<HTMLDivElement>;
}
const BlockFrame_Tech = React.memo(
({ blockId, onClose, onClick, preview, blockRef, dragHandleRef, children }: BlockFrameProps) => {
const BlockFrame_Tech_Component = ({
blockId,
onClose,
onClick,
preview,
blockRef,
dragHandleRef,
children,
}: BlockFrameProps) => {
const [blockData] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
const settingsConfig = jotai.useAtomValue(atoms.settingsConfigAtom);
const isFocusedAtom = useBlockAtom<boolean>(blockId, "isFocused", () => {
@ -257,8 +264,9 @@ const BlockFrame_Tech = React.memo(
{preview ? <div className="block-frame-preview" /> : children}
</div>
);
}
);
};
const BlockFrame_Tech = React.memo(BlockFrame_Tech_Component) as typeof BlockFrame_Tech_Component;
const BlockFrame_Frameless = ({
blockId,
@ -343,6 +351,8 @@ const BlockFrame = React.memo((props: BlockFrameProps) => {
return null;
}
let FrameElem = BlockFrame_Tech;
// Preview should always render as the full tech frame
if (!props.preview) {
// if 0 or 1 blocks, use frameless, otherwise use tech
const numBlocks = tabData?.blockids?.length ?? 0;
if (numBlocks <= 1) {
@ -353,6 +363,7 @@ const BlockFrame = React.memo((props: BlockFrameProps) => {
} else if (blockData?.meta?.["frame"] === "frameless") {
FrameElem = BlockFrame_Frameless;
}
}
return <FrameElem {...props} />;
});