Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: drop an Images strip tile onto an image picker to use it (#14166)

Michael Han4531eb559dc9
diff --git a/studio/frontend/src/components/image-dropzone.tsx b/studio/frontend/src/components/image-dropzone.tsx
index e98d0ba5579..89415328419 100644
--- a/studio/frontend/src/components/image-dropzone.tsx
+++ b/studio/frontend/src/components/image-dropzone.tsx
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+import type React from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import { Delete02Icon, ImageAdd02Icon, ImageCropIcon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
@@ -17,12 +18,30 @@ import {
useNativeDropTarget,
} from "@/features/native-intents";
import { useImageCrop } from "@/hooks/use-image-crop";
+import { GALLERY_ITEM_DRAG_TYPE } from "@/hooks/use-strip-reorder";
import { MAX_UPLOAD_IMAGE_SIDE, fitImageDataUrl } from "@/lib/image-fit";
import { cn } from "@/lib/utils";
import { toast } from "@/lib/toast";
const NATIVE_IMAGE_EXTS = ["jpg", "jpeg", "png", "webp", "gif"];
+type GalleryImageSource = (id: string) => Promise<Blob | null>;
+let gallerySource: GalleryImageSource | null = null;
+
+/** Lets every ImageDropzone on the page accept a tile dragged from this page's gallery strip. */
+export function useGalleryImageDropSource(source: GalleryImageSource) {
+ useEffect(() => {
+ gallerySource = source;
+ return () => {
+ if (gallerySource === source) gallerySource = null;
+ };
+ }, [source]);
+}
+
+function isGalleryDrag(event: React.DragEvent): boolean {
+ return gallerySource !== null && event.dataTransfer.types.includes(GALLERY_ITEM_DRAG_TYPE);
+}
+
/** Shared image picker that returns a data URL. */
export function ImageDropzone({
value,
@@ -69,7 +88,7 @@ export function ImageDropzone({
}, [value]);
const readFile = useCallback(
- (file: File | undefined | null) => {
+ (file: Blob | undefined | null) => {
if (!file || !file.type.startsWith("image/")) {
if (file) toast.error("Please choose an image file");
return;
@@ -93,6 +112,25 @@ export function ImageDropzone({
[onChange, maxSide],
);
+ const readGalleryItem = useCallback(
+ async (id: string) => {
+ const source = gallerySource;
+ if (!source) return;
+ selection.current += 1;
+ const claimed = selection.current;
+ try {
+ const blob = await source(id);
+ if (!blob || !mounted.current || claimed !== selection.current) return;
+ readFile(blob);
+ } catch (error) {
+ toast.error("Could not read the image", {
+ description: error instanceof Error ? error.message : String(error),
+ });
+ }
+ },
+ [readFile],
+ );
+
// Tauri suppresses the webview drop event, so desktop drops arrive as paths
// that the native side registers and reads for this picker.
const readNativePath = useCallback(
@@ -204,13 +242,17 @@ export function ImageDropzone({
onClick={() => inputRef.current?.click()}
onDragOver={(e) => {
e.preventDefault();
+ // The strip offers copy or move; without this the cursor reads as a move.
+ if (isGalleryDrag(e)) e.dataTransfer.dropEffect = "copy";
setDragging(true);
}}
onDragLeave={() => setDragging(false)}
onDrop={(e) => {
e.preventDefault();
setDragging(false);
- readFile(e.dataTransfer.files?.[0]);
+ const galleryId = isGalleryDrag(e) ? e.dataTransfer.getData(GALLERY_ITEM_DRAG_TYPE) : "";
+ if (galleryId) void readGalleryItem(galleryId);
+ else readFile(e.dataTransfer.files?.[0]);
}}
className={cn(
"flex h-28 w-full flex-col items-center justify-center gap-1 rounded-xl border border-dashed text-xs transition-colors",
diff --git a/studio/frontend/src/features/images/images-page.tsx b/studio/frontend/src/features/images/images-page.tsx
index 6ff0cbfeb6e..8de9e48ec02 100644
--- a/studio/frontend/src/features/images/images-page.tsx
+++ b/studio/frontend/src/features/images/images-page.tsx
@@ -33,7 +33,7 @@ import { MessageCircleIcon, TestTubeOutlineIcon } from "@/lib/hugeicons-derived"
import { MediaViewer } from "@/components/media-viewer";
import { shortPrompt } from "@/lib/prompt-text";
-import { ImageDropzone } from "@/components/image-dropzone";
+import { ImageDropzone, useGalleryImageDropSource } from "@/components/image-dropzone";
import {
readNativeAttachmentFile,
registerNativeAttachmentPath,
@@ -2502,6 +2502,14 @@ export function ImagesPage({
[srcById],
);
const stripReorder = useStripReorder((id, afterId) => void handleMove(id, afterId));
+ const imagesRef = useRef(images);
+ imagesRef.current = images;
+ useGalleryImageDropSource(
+ useCallback(async (id: string) => {
+ const image = imagesRef.current.find((item) => item.id === id);
+ return image ? fetchGalleryBlob(image.url) : null;
+ }, []),
+ );
const handleArchive = useCallback(
async (id: string) => {
diff --git a/studio/frontend/src/hooks/use-strip-reorder.ts b/studio/frontend/src/hooks/use-strip-reorder.ts
index 7285fd5e75e..b9f02f6b6a7 100644
--- a/studio/frontend/src/hooks/use-strip-reorder.ts
+++ b/studio/frontend/src/hooks/use-strip-reorder.ts
@@ -11,7 +11,7 @@ export interface StripDropCue {
}
// Custom type so other drop targets do not read the drag as a file or link.
-const DRAG_TYPE = "application/x-unsloth-gallery-item";
+export const GALLERY_ITEM_DRAG_TYPE = "application/x-unsloth-gallery-item";
/** Whether the event came from the tile's own DOM, not a portalled menu or dialog inside it. */
function fromTile(event: React.SyntheticEvent<HTMLElement>): boolean {
@@ -102,8 +102,8 @@ export function useStripReorder(
if (!fromTile(event)) return;
dragIdRef.current = id;
setDraggingId(id);
- event.dataTransfer.effectAllowed = "move";
- event.dataTransfer.setData(DRAG_TYPE, id);
+ event.dataTransfer.effectAllowed = "copyMove";
+ event.dataTransfer.setData(GALLERY_ITEM_DRAG_TYPE, id);
},
onDragEnd: end,
onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => {