Ensure previews don't wrap text (#39)

This commit is contained in:
Evan Simkowitz 2024-06-11 14:51:35 -07:00 committed by GitHub
parent 525f20ba81
commit cff7a54507
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 17 deletions

View File

@ -31,10 +31,13 @@
justify-content: center;
background-color: var(--panel-bg-color);
user-select: none;
cursor: default;
.block-header-text {
padding: 0 5px;
flex-grow: 1;
user-select: none;
cursor: default;
}
.close-button {

View File

@ -47,6 +47,7 @@
border-bottom: 1px solid var(--border-color);
flex-shrink: 0;
user-select: none;
cursor: default;
.tab {
display: flex;

View File

@ -252,32 +252,17 @@ const TileNode = <T,>({
const previewRef = useRef<HTMLDivElement>(null);
// Register the node as a draggable item.
const [{ isDragging, dragItem }, drag, dragPreview] = useDrag(
const [{ isDragging }, drag, dragPreview] = useDrag(
() => ({
type: dragItemType,
item: () => layoutNode,
collect: (monitor) => ({
isDragging: monitor.isDragging(),
dragItem: monitor.getItem<LayoutNode<T>>(),
}),
}),
[layoutNode]
);
// TODO: remove debug effect
useEffect(() => {
if (isDragging) {
console.log("drag start", layoutNode.id, layoutNode, dragItem);
if (previewRef.current) {
toPng(previewRef.current).then((url) => {
const img = new Image();
img.src = url;
img.onload = () => dragPreview(img);
});
}
}
}, [isDragging]);
// Generate a preview div using the provided renderPreview function. This will be placed in the DOM so we can render an image from it, but it is pushed out of view so the user will not see it.
// No-op if not provided, meaning React-DnD will attempt to generate a preview from the DOM, which is very slow.
const preview = useMemo(() => {
@ -291,11 +276,11 @@ const TileNode = <T,>({
);
}, []);
// Ensure we only generate the preview image once
const [previewImageSet, setPreviewImageSet] = useState<boolean>(false);
// When a user first mouses over a node, generate a preview image and set it as the drag preview.
const generatePreviewImage = useCallback(() => {
console.log("generatePreviewImage", layoutNode.id);
if (!previewImageSet && previewRef.current) {
toPng(previewRef.current).then((url) => {
const img = new Image();

View File

@ -46,8 +46,11 @@
}
.tile-preview-container {
height: fit-content !important;
width: fit-content !important;
position: absolute;
top: 10000px;
white-space: nowrap !important;
}
}