import React, { CSSProperties, memo } from "react"; import { XYCoord } from "react-dnd"; import { useTreeApi } from "../context"; import { DragPreviewProps } from "../types/renderers"; import { IdObj } from "../types/utils"; const layerStyles: CSSProperties = { position: "fixed", pointerEvents: "none", zIndex: 100, left: 0, top: 0, width: "100%", height: "100%", }; const getStyle = (offset: XYCoord | null) => { if (!offset) return { display: "none" }; const { x, y } = offset; return { transform: `translate(${x}px, ${y}px)` }; }; const getCountStyle = (offset: XYCoord | null) => { if (!offset) return { display: "none" }; const { x, y } = offset; return { transform: `translate(${x + 10}px, ${y + 10}px)` }; }; export function DefaultDragPreview({ offset, mouse, id, dragIds, isDragging, }: DragPreviewProps) { return ( ); } const Overlay = memo(function Overlay(props: { children: JSX.Element[]; isDragging: boolean; }) { if (!props.isDragging) return null; return
{props.children}
; }); function Position(props: { children: JSX.Element; offset: XYCoord | null }) { return (
{props.children}
); } function Count(props: { count: number; mouse: XYCoord | null }) { const { count, mouse } = props; if (count > 1) return (
{count}
); else return null; } const PreviewNode = memo(function PreviewNode(props: { id: string | null; dragIds: string[]; }) { const tree = useTreeApi(); const node = tree.get(props.id); if (!node) return null; return ( ); });