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: lift a carried model picker row like a sidebar chat, and lighten both drag copies (#12499)

Michael Han9838541fcbfb
diff --git a/studio/frontend/src/features/chat/hooks/use-sidebar-drag.ts b/studio/frontend/src/features/chat/hooks/use-sidebar-drag.ts
index f15da6fa9cc..12455fd7d8a 100644
--- a/studio/frontend/src/features/chat/hooks/use-sidebar-drag.ts
+++ b/studio/frontend/src/features/chat/hooks/use-sidebar-drag.ts
@@ -215,7 +215,7 @@ const GHOST_DROPPED_ATTRS = [
"data-thread-type",
] as const;
-interface RowGhost {
+export interface RowGhost {
element: HTMLElement;
/** Where on the row the press landed, so the copy does not jump when it lifts. */
grab: number;
@@ -231,16 +231,33 @@ interface RowGhost {
function liftRow(row: HTMLElement, pressY: number, view: Element): RowGhost | null {
const face = row.querySelector<HTMLElement>(ROW_FACE_SELECTOR);
if (!face) return null;
+ const ghost = liftCopy(face, pressY, view, ROW_GHOST_CLASS, GHOST_DROPPED_ATTRS);
+ // The icon size is the sidebar's own variable, which the copy leaves behind on the body.
+ const iconSize = getComputedStyle(face).getPropertyValue("--icon-size");
+ if (iconSize) ghost.element.style.setProperty("--icon-size", iconSize);
+ return ghost;
+}
+
+/** A copy of `face` on a pill over where it sits. Also used by the model picker. */
+export function liftCopy(
+ face: HTMLElement,
+ pressY: number,
+ view: Element,
+ className: string,
+ dropped: readonly string[],
+): RowGhost {
const rect = face.getBoundingClientRect();
const style = getComputedStyle(face);
const copy = face.cloneNode(true) as HTMLElement;
for (const node of [copy, ...copy.querySelectorAll<HTMLElement>("*")]) {
- for (const name of GHOST_DROPPED_ATTRS) node.removeAttribute(name);
+ for (const name of dropped) node.removeAttribute(name);
}
copy.tabIndex = -1;
const element = document.createElement("div");
element.setAttribute("aria-hidden", "true");
- element.className = ROW_GHOST_CLASS;
+ // A picture, not controls.
+ element.inert = true;
+ element.className = className;
element.append(copy);
// Lifted where the row is, so a frame drawn before its first transform lands shows it there,
// not at the top of the window.
@@ -253,16 +270,13 @@ function liftRow(row: HTMLElement, pressY: number, view: Element): RowGhost | nu
fontFamily: style.fontFamily,
color: style.color,
});
- // The icon size is the sidebar's own variable, which the copy leaves behind on the body.
- const iconSize = style.getPropertyValue("--icon-size");
- if (iconSize) element.style.setProperty("--icon-size", iconSize);
dragLayer().append(element);
return { element, grab: pressY - rect.top, view, top: rect.top, cues: [] };
}
/** Draws each cue painted under the copy again over it: its border only, since the tint under
* the copy would otherwise double where the two meet. Clipped to the list, as the cue is. */
-function placeCue(ghost: RowGhost) {
+export function placeCue(ghost: RowGhost) {
const view = ghost.view.getBoundingClientRect();
let shown = 0;
for (const cue of document.querySelectorAll<HTMLElement>(`.${DROP_CUE_CLASS}`)) {
@@ -303,7 +317,7 @@ function placeCue(ghost: RowGhost) {
}
/** Keeps the copy under the pointer, inside the list it came from. */
-function placeGhost(ghost: RowGhost, y: number) {
+export function placeGhost(ghost: RowGhost, y: number) {
const view = ghost.view.getBoundingClientRect();
const height = ghost.element.offsetHeight;
const top = Math.min(Math.max(y - ghost.grab, view.top), view.bottom - height);
diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.ts
index f81bc57314b..32d1ab1d922 100644
--- a/studio/frontend/src/features/chat/index.ts
+++ b/studio/frontend/src/features/chat/index.ts
@@ -144,6 +144,10 @@ export {
DRAG_THRESHOLD_PX,
markDragging,
DROP_CUE_CLASS,
+ liftCopy,
+ placeCue,
+ placeGhost,
+ type RowGhost,
} from "./hooks/use-sidebar-drag";
export {
useSectionDrag,
diff --git a/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx b/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx
index 389d5e7a316..6c814199a4d 100644
--- a/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx
+++ b/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx
@@ -29,6 +29,7 @@ import {
} from "@/features/chat";
import {
chatModelLoaded,
+ DROP_CUE_CLASS,
isExternalModelId,
modelCatalogVersion,
parseExternalModelId,
@@ -5802,7 +5803,8 @@ export function HubModelPicker({
<div
key={key}
{...drag.rowProps(key)}
- className={cn("relative", edge && PINNED_DROP_CUE[edge])}
+ // DROP_CUE_CLASS: the drag redraws the line above the carried copy.
+ className={cn("relative", edge && [DROP_CUE_CLASS, PINNED_DROP_CUE[edge]])}
style={drag.draggingKey === key ? { opacity: 0.4 } : undefined}
>
{row}
@@ -8295,7 +8297,11 @@ function FineTunedRows({
: tag;
return (
<div key={adapter.id}>
- <div className={downloadedRowShellClassName(value === adapter.id)}>
+ <div
+ className={downloadedRowShellClassName(value === adapter.id)}
+ // The pill a Pinned drag lifts, not this wrapper (use-pinned-row-drag.ts).
+ data-pinned-row-face=""
+ >
<div className="min-w-0 flex-1">
<ModelRow
label={adapter.name}
diff --git a/studio/frontend/src/features/model-picker/components/model-selector/use-pinned-row-drag.ts b/studio/frontend/src/features/model-picker/components/model-selector/use-pinned-row-drag.ts
index ebd298e266d..b69af683125 100644
--- a/studio/frontend/src/features/model-picker/components/model-selector/use-pinned-row-drag.ts
+++ b/studio/frontend/src/features/model-picker/components/model-selector/use-pinned-row-drag.ts
@@ -3,10 +3,19 @@
// Drag to reorder a Pinned group in the model selector, like pinned chats in the sidebar.
// Pointer events, not HTML5 drag: the desktop webview never forwards dragover or drop.
+// The carried row lifts as a copy that follows the pointer, as in the sidebar.
import { useCallback, useEffect, useRef, useState } from "react";
-import { DRAG_THRESHOLD_PX, markDragging } from "@/features/chat";
+import {
+ DRAG_THRESHOLD_PX,
+ liftCopy,
+ markDragging,
+ placeCue,
+ placeGhost,
+ type RowGhost,
+} from "@/features/chat";
+import { prefersReducedMotion } from "@/features/settings";
export type PinnedDropEdge = "top" | "bottom";
@@ -19,6 +28,24 @@ const KEY_ATTR = "data-pinned-drop-key";
const NO_DRAG_SELECTOR =
"button:not([data-model-picker-option]), a[href], [role='menuitem']";
+/** The raised copy of a carried row. */
+const ROW_GHOST_CLASS = "model-picker-row-ghost";
+
+/** Attributes the copy drops, so nothing finds it as an option or drop target. */
+const GHOST_DROPPED_ATTRS = [
+ "id",
+ SCOPE_ATTR,
+ KEY_ATTR,
+ "data-model-picker-option",
+ "data-model-picker-active-option",
+ "aria-current",
+ "data-state",
+ "data-slot",
+] as const;
+
+/** How long a dropped row takes to slide into its slot. */
+const SETTLE_MS = 180;
+
/** How far outside a row the pointer still aims at it. */
const NEAR_ROW_PX = 12;
@@ -45,6 +72,49 @@ function scrollerOf(element: Element | null): HTMLElement | null {
return null;
}
+/** The list the copy stays inside, even one too short to scroll. */
+function viewOf(row: HTMLElement): Element {
+ for (let node = row.parentElement; node; node = node.parentElement) {
+ const overflow = getComputedStyle(node).overflowY;
+ if (overflow === "auto" || overflow === "scroll") return node;
+ }
+ return row.parentElement ?? document.documentElement;
+}
+
+/** Marks a row's pill when it is not the wrapper's first child (a fine-tuned row nests it). */
+const ROW_FACE_ATTR = "data-pinned-row-face";
+
+/** The row itself, inside the wrapper that holds the drop marks. */
+const faceOf = (row: Element): HTMLElement =>
+ row.querySelector<HTMLElement>(`[${ROW_FACE_ATTR}]`) ??
+ (row.firstElementChild as HTMLElement | null) ??
+ (row as HTMLElement);
+
+/** Slides a dropped row from where it was let go into its slot. */
+function settleRow(scope: string, key: string, from: number) {
+ // Two frames: measured after the drop re-renders the list.
+ requestAnimationFrame(() =>
+ requestAnimationFrame(() => {
+ const row = document.querySelector<HTMLElement>(
+ `[${SCOPE_ATTR}="${CSS.escape(scope)}"][${KEY_ATTR}="${CSS.escape(key)}"]`,
+ );
+ if (!row) return;
+ const delta = from - faceOf(row).getBoundingClientRect().top;
+ if (Math.abs(delta) < 2) return;
+ row.style.transition = "none";
+ row.style.transform = `translateY(${delta}px)`;
+ row.style.zIndex = "1";
+ row.getBoundingClientRect();
+ row.style.transition = `transform ${SETTLE_MS}ms cubic-bezier(0.2, 0.8, 0.2, 1)`;
+ row.style.transform = "";
+ window.setTimeout(() => {
+ row.style.transition = "";
+ row.style.zIndex = "";
+ }, SETTLE_MS + 20);
+ }),
+ );
+}
+
function edgeAt(rect: DOMRect, y: number): PinnedDropEdge {
return y < rect.top + rect.height / 2 ? "top" : "bottom";
}
@@ -125,6 +195,7 @@ export function usePinnedRowDrag(
const draggingRef = useRef<string | null>(null);
const targetRef = useRef<PinnedRowDrop | null>(null);
const scroller = useRef<HTMLElement | null>(null);
+ const ghost = useRef<RowGhost | null>(null);
/** The gesture in flight, so a second press cannot overlap it. */
const press = useRef<{ end: () => void } | null>(null);
@@ -138,6 +209,9 @@ export function usePinnedRowDrag(
const clear = useCallback(() => {
draggingRef.current = null;
scroller.current = null;
+ ghost.current?.element.remove();
+ for (const overlay of ghost.current?.cues ?? []) overlay.remove();
+ ghost.current = null;
markDragging(null, false);
setDraggingKey(null);
showTarget(null);
@@ -245,7 +319,10 @@ export function usePinnedRowDrag(
list.scrollTop += EDGE_STEP_PX;
}
}
+ if (ghost.current) placeGhost(ghost.current, at.y);
showTarget(aim(at.x, at.y));
+ // Redraw the drop line above the copy.
+ if (ghost.current) placeCue(ghost.current);
};
const self = {
end: () => {
@@ -280,6 +357,14 @@ export function usePinnedRowDrag(
}
started = true;
scroller.current = scrollerOf(row);
+ ghost.current = liftCopy(
+ faceOf(row),
+ startY,
+ scroller.current ?? viewOf(row),
+ ROW_GHOST_CLASS,
+ GHOST_DROPPED_ATTRS,
+ );
+ placeGhost(ghost.current, moved.clientY);
// The picker's own list, not the body: see markDragging.
markDragging(scroller.current ?? row.parentElement, true);
try {
@@ -302,8 +387,13 @@ export function usePinnedRowDrag(
swallowClick();
if (escaped) return;
const drop = aim(released.clientX, released.clientY);
+ const from = ghost.current?.element.getBoundingClientRect().top ?? null;
clear();
- if (drop) optionsRef.current.onDrop(key, drop);
+ if (!drop) return;
+ optionsRef.current.onDrop(key, drop);
+ if (from !== null && !prefersReducedMotion()) {
+ settleRow(optionsRef.current.scope, key, from);
+ }
}
function onCancel(aborted: PointerEvent) {
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index e669c9d642d..0ee2c170fc5 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -4755,25 +4755,57 @@ html[data-chat-font] .aui-root {
}
.sidebar-row-ghost {
+ --row-ghost-surface: var(--sidebar);
position: fixed;
top: 0;
z-index: 60;
display: flex;
align-items: center;
border-radius: 10px;
- background: var(--sidebar-accent);
- box-shadow:
- 0 0 0 1px color-mix(in oklab, var(--foreground) 8%, transparent),
- 0 8px 24px -8px rgb(0 0 0 / 0.35);
pointer-events: none;
will-change: transform;
}
+/* A carried row: a translucent shade off its list. */
+:is(.sidebar-row-ghost, .model-picker-row-ghost) {
+ background: color-mix(in oklab, color-mix(in oklab, var(--row-ghost-surface), var(--foreground) 5%) 85%, transparent);
+ -webkit-backdrop-filter: blur(8px);
+ backdrop-filter: blur(8px);
+ box-shadow:
+ 0 0 0 1px color-mix(in oklab, var(--foreground) 7%, transparent),
+ 0 4px 14px -6px rgb(0 0 0 / 0.16);
+}
+
.sidebar-section-ghost > *,
.sidebar-row-ghost * {
pointer-events: none;
}
+/* A Pinned row carried in the model picker (use-pinned-row-drag.ts). */
+.model-picker-row-ghost {
+ --row-ghost-surface: var(--popover);
+ position: fixed;
+ top: 0;
+ z-index: 60;
+ display: flex;
+ align-items: center;
+ pointer-events: none;
+ will-change: transform;
+}
+
+.model-picker-row-ghost * {
+ pointer-events: none;
+}
+
+/* The row fills the pill, which paints the tint. Its margin stays behind: the pill was sized
+ without it, so a Connected row's ml-4 would push the copy off its own pill. */
+.model-picker-row-ghost > * {
+ width: 100%;
+ height: 100%;
+ margin: 0;
+ background: transparent;
+}
+
/* The drop cue under a carried row's copy, drawn again above it (use-sidebar-drag.ts). */
.sidebar-drop-cue-overlay {
position: fixed;
@@ -4783,7 +4815,7 @@ html[data-chat-font] .aui-root {
pointer-events: none;
}
-/* A row's copy is its face as drawn, lit like a hovered row but never like the open chat. */
+/* A row's copy is its face as drawn, never lit like the open chat. */
.sidebar-row-ghost > [data-sidebar="menu-button"] {
width: 100%;
height: 100%;
diff --git a/studio/frontend/tests/model-picker-pinned-drag-preview.test.ts b/studio/frontend/tests/model-picker-pinned-drag-preview.test.ts
new file mode 100644
index 00000000000..8161a70804c
--- /dev/null
+++ b/studio/frontend/tests/model-picker-pinned-drag-preview.test.ts
@@ -0,0 +1,73 @@
+// 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 assert from "node:assert/strict";
+import test from "node:test";
+
+import { readSrc } from "./helpers/kit.ts";
+
+// A Pinned row carried in the model picker lifts as a copy under the pointer, as a sidebar chat
+// does, through the same helpers so the two never drift. Every tab (Chat, Images, Audio, Video)
+// draws its picker with HubModelPicker, so they all carry rows this way.
+
+const HOOK = readSrc("features/model-picker/components/model-selector/use-pinned-row-drag.ts");
+const SIDEBAR = readSrc("features/chat/hooks/use-sidebar-drag.ts");
+const PICKERS = readSrc("features/model-picker/components/model-selector/pickers.tsx");
+const CSS = readSrc("index.css");
+
+test("the sidebar's lift, follow and cue helpers are shared", () => {
+ for (const name of ["liftCopy", "placeGhost", "placeCue"]) {
+ assert.match(SIDEBAR, new RegExp(`export function ${name}\\(`), name);
+ }
+ // The sidebar still lifts its rows through the shared copy.
+ assert.match(SIDEBAR, /liftCopy\(face, pressY, view, ROW_GHOST_CLASS, GHOST_DROPPED_ATTRS\)/);
+});
+
+test("a carried Pinned row lifts a copy that follows the pointer", () => {
+ assert.match(
+ HOOK,
+ /started = true;\n\s*scroller\.current = scrollerOf\(row\);\n\s*ghost\.current = liftCopy\(\n\s*faceOf\(row\),/,
+ );
+ assert.match(HOOK, /if \(ghost\.current\) placeGhost\(ghost\.current, at\.y\);/);
+ // A picture only: never an option the list's keys, the drop hit test or a tooltip finds.
+ for (const attr of ['"id"', "SCOPE_ATTR", "KEY_ATTR", '"data-model-picker-option"', '"data-state"']) {
+ assert.match(HOOK, new RegExp(`GHOST_DROPPED_ATTRS = \\[[^\\]]*${attr.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`), attr);
+ }
+ assert.match(CSS, /\.model-picker-row-ghost \{\n[^}]*position: fixed;[^}]*z-index: 60;/);
+ assert.match(CSS, /\.model-picker-row-ghost \* \{\n\tpointer-events: none;/);
+});
+
+test("both copies are a translucent shade off the list they came from", () => {
+ const look = /:is\(\.sidebar-row-ghost, \.model-picker-row-ghost\) \{([^}]*)\}/.exec(CSS);
+ assert.ok(look, "shared ghost look");
+ assert.match(look[1], /background: color-mix\(in oklab, color-mix\(in oklab, var\(--row-ghost-surface\), var\(--foreground\) 5%\) 85%, transparent\);/);
+ assert.match(look[1], /backdrop-filter: blur\(8px\);/);
+ assert.match(CSS, /\.sidebar-row-ghost \{\n\t--row-ghost-surface: var\(--sidebar\);/);
+ assert.match(CSS, /\.model-picker-row-ghost \{\n\t--row-ghost-surface: var\(--popover\);/);
+});
+
+test("the drop line is drawn again above the copy", () => {
+ // Read at render: the chat barrel imports the picker back, so a module-scope read is undefined.
+ assert.match(PICKERS, /className=\{cn\("relative", edge && \[DROP_CUE_CLASS, PINNED_DROP_CUE\[edge\]\]\)\}/);
+ assert.match(HOOK, /showTarget\(aim\(at\.x, at\.y\)\);\n[^\n]*\n\s*if \(ghost\.current\) placeCue\(ghost\.current\);/);
+});
+
+test("every way a drag ends takes the copy down, and a drop settles into place", () => {
+ assert.match(
+ HOOK,
+ /const clear = useCallback\(\(\) => \{[^]*?ghost\.current\?\.element\.remove\(\);\n\s*for \(const overlay of ghost\.current\?\.cues \?\? \[\]\) overlay\.remove\(\);\n\s*ghost\.current = null;/,
+ );
+ assert.match(HOOK, /if \(from !== null && !prefersReducedMotion\(\)\) \{\n\s*settleRow\(optionsRef\.current\.scope, key, from\);/);
+});
+
+test("the copy sits on its own pill for every Pinned row kind", () => {
+ // A Connected row's ml-4 is not part of the pill the copy is sized to, so it must not carry over.
+ assert.match(CSS, /\.model-picker-row-ghost > \* \{\n[^}]*margin: 0;/);
+ // A fine-tuned row nests its pill in a keyed wrapper; the drag lifts the marked pill instead.
+ assert.match(HOOK, /const ROW_FACE_ATTR = "data-pinned-row-face";/);
+ assert.match(HOOK, /const faceOf = \(row: Element\): HTMLElement =>\n\s*row\.querySelector<HTMLElement>\(`\[\$\{ROW_FACE_ATTR\}\]`\) \?\?/);
+ assert.match(
+ PICKERS,
+ /<div key=\{adapter\.id\}>\n\s*<div\n\s*className=\{downloadedRowShellClassName\(value === adapter\.id\)\}\n[^\n]*\n\s*data-pinned-row-face=""/,
+ );
+});