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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: lift a carried model picker row like a sidebar chat, and lighten both drag copies (#12622)
Daniel Hand0b00b2971eb
diff --git a/studio/frontend/src/features/chat/hooks/use-sidebar-drag.ts b/studio/frontend/src/features/chat/hooks/use-sidebar-drag.tsindex f15da6fa9cc..9a4c6799048 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,32 @@ 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;+ 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 +269,13 @@ function liftRow(row: HTMLElement, pressY: number, view: Element): RowGhost | nufontFamily: 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 +316,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.tsindex 0223d26aada..f2999221ae0 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.tsxindex 389d5e7a316..813cf653a69 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,7 @@ export function HubModelPicker({<divkey={key}{...drag.rowProps(key)}- className={cn("relative", edge && PINNED_DROP_CUE[edge])}+ className={cn("relative", edge && [DROP_CUE_CLASS, PINNED_DROP_CUE[edge]])}style={drag.draggingKey === key ? { opacity: 0.4 } : undefined}>{row}@@ -8295,7 +8296,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"><ModelRowlabel={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.tsindex ebd298e266d..1657b6aea31 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@@ -6,7 +6,15 @@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 +27,22 @@ const KEY_ATTR = "data-pinned-drop-key";const NO_DRAG_SELECTOR ="button:not([data-model-picker-option]), a[href], [role='menuitem']";+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;++const SETTLE_MS = 180;+/** How far outside a row the pointer still aims at it. */const NEAR_ROW_PX = 12;@@ -45,6 +69,47 @@ 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";++const faceOf = (row: Element): HTMLElement =>+ row.querySelector<HTMLElement>(`[${ROW_FACE_ATTR}]`) ??+ (row.firstElementChild as HTMLElement | null) ??+ (row as HTMLElement);++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 +190,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 +204,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 +314,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 +352,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 +382,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.cssindex 518a457d991..99286ece1cd 100644--- a/studio/frontend/src/index.css+++ b/studio/frontend/src/index.css@@ -4759,25 +4759,69 @@ 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;}+.sidebar-section-ghost {+ --row-ghost-surface: var(--sidebar);+ display: flex;+ align-items: center;+ border-radius: 10px;+ will-change: transform;+}++:is(.sidebar-row-ghost, .sidebar-section-ghost, .model-picker-row-ghost) {+ background: color-mix(in oklab, color-mix(in oklab, var(--row-ghost-surface), black 4%) 62%, transparent);+ -webkit-backdrop-filter: blur(0.5px) saturate(1.05);+ backdrop-filter: blur(0.5px) saturate(1.05);+ box-shadow:+ 0 0 0 1px rgb(0 0 0 / 0.06),+ 0 4px 12px -4px rgb(0 0 0 / 0.12);+}++.dark :is(.sidebar-row-ghost, .sidebar-section-ghost, .model-picker-row-ghost) {+ background: color-mix(in oklab, color-mix(in oklab, var(--row-ghost-surface), black 22%) 62%, transparent);+ box-shadow:+ 0 0 0 1px rgb(255 255 255 / 0.045),+ 0 6px 16px -6px rgb(0 0 0 / 0.5);+}+.sidebar-section-ghost > *,.sidebar-row-ghost * {pointer-events: none;}+.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;+}++/* Margin dropped: the pill was sized without it, so a Connected row's ml-4 would offset the copy. */+.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;@@ -4787,7 +4831,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.tsnew file mode 100644index 00000000000..8e436a90cd4--- /dev/null+++ b/studio/frontend/tests/model-picker-pinned-drag-preview.test.ts@@ -0,0 +1,74 @@+// 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";++// Pinned picker rows lift through the sidebar's helpers so the two never drift.++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);+ }+ 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\);/);+ 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("every copy is a faintly frosted shade darker than the list it came from", () => {+ const ghosts = String.raw`:is\(\.sidebar-row-ghost, \.sidebar-section-ghost, \.model-picker-row-ghost\)`;+ const light = new RegExp(String.raw`\n${ghosts} \{([^}]*)\}`).exec(CSS);+ const dark = new RegExp(String.raw`\.dark ${ghosts} \{([^}]*)\}`).exec(CSS);+ assert.ok(light, "shared ghost look");+ assert.ok(dark, "shared ghost look in dark mode");+ assert.match(light[1], /background: color-mix\(in oklab, color-mix\(in oklab, var\(--row-ghost-surface\), black 4%\) 62%, transparent\);/);+ assert.match(dark[1], /background: color-mix\(in oklab, color-mix\(in oklab, var\(--row-ghost-surface\), black 22%\) 62%, transparent\);/);+ assert.match(light[1], /\bbackdrop-filter: blur\(0\.5px\) saturate\(1\.05\);/);+ assert.match(light[1], /0 0 0 1px rgb\(0 0 0 \/ 0\.06\)/);+ assert.match(dark[1], /0 0 0 1px rgb\(255 255 255 \/ 0\.045\)/);+ assert.match(CSS, /\.sidebar-row-ghost \{\n\t--row-ghost-surface: var\(--sidebar\);/);+ assert.match(CSS, /\.sidebar-section-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", () => {+ assert.match(CSS, /\.model-picker-row-ghost > \* \{\n[^}]*margin: 0;/);+ 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=""/,+ );+});