Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(webv2): drag videos from the preview frame like images
Lincoln Stein811c40da96c0
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex b5e13492c0..438d249876 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -1942,6 +1942,7 @@"copyCurrentFrameUnsupported": "This browser cannot copy video frames","copyCurrentFrameWriteFailed": "Could not write the current video frame to the clipboard","details": "Details",+ "dragVideo": "Drag video","dropToCompare": "Drop to compare","editOnCanvas": "Edit on Canvas","emptyDescription": "Generate to Gallery, then select a thumbnail in the Gallery widget to inspect it here.",diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsxindex 844903550c..77635ac6c5 100644--- a/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx@@ -123,7 +123,10 @@ const areSourceClipsEquivalent = (left: VideoSourceClip | null, right: VideoSour(left === null && right === null) ||(left?.video_name === right?.video_name &&left?.startFrame === right?.startFrame &&- left?.endFrame === right?.endFrame);+ left?.endFrame === right?.endFrame &&+ // The bound thumbnails seek at frame/fps, so a same-name clip hydrated+ // with a different probed rate must re-render.+ left?.fps === right?.fps);export const VideoSourceClipField = memo(function VideoSourceClipField({diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsxindex 0c2bcf5ee9..2f40b95582 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx@@ -8,6 +8,7 @@ import { getGalleryItemDragData, getGalleryItemDragId } from '@features/gallery/import { getAuthSession, refreshProtectedMediaCookie } from '@features/identity';import { useMountEffect } from '@platform/react/useMountEffect';import { Button } from '@platform/ui/Button';+import { GripVerticalIcon } from 'lucide-react';import {useCallback,useId,@@ -59,6 +60,7 @@ export const PreviewFrame = (props: PreviewFrameProps) => {return (<PreviewVideokey={props.source.itemKey}+ dragItem={props.dragItem}frameHeight={props.frameHeight}frameWidth={props.frameWidth}isItemCurrent={props.isItemCurrent}@@ -218,6 +220,7 @@ const PreviewImageFrame = ({};const PreviewVideo = ({+ dragItem,frameHeight,frameWidth,isItemCurrent,@@ -228,6 +231,7 @@ const PreviewVideo = ({source,videoControllerRef,}: {+ dragItem?: GalleryItemRef;frameHeight: number;frameWidth: number;isItemCurrent?: (itemKey: GalleryItemKey) => boolean;@@ -240,6 +244,22 @@ const PreviewVideo = ({}) => {const { t } = useTranslation();const videoRef = useRef<HTMLVideoElement | null>(null);+ // The `<video controls>` surface cannot be the drag handle the way the image+ // frame is: the pointer-move activation threshold would turn every native+ // seek-bar scrub into a drag. A corner grip carries the same gallery-item+ // payload instead, so the preview and the gallery thumbnail drop the same+ // thing everywhere.+ const dragData = useMemo(() => (dragItem ? getGalleryItemDragData([dragItem]) : undefined), [dragItem]);+ const disabledDragId = useId();+ const {+ isDragging,+ listeners,+ setNodeRef: setDragHandleRef,+ } = useDraggable({+ data: dragData,+ disabled: !dragItem,+ id: dragItem ? getGalleryItemDragId(dragItem, 'preview-frame') : `preview-frame:disabled:${disabledDragId}`,+ });const automaticRefreshUsedRef = useRef(false);const pendingRefreshRef = useRef<Promise<boolean> | null>(null);const [hasFailed, setHasFailed] = useState(false);@@ -448,8 +468,32 @@ const PreviewVideo = ({bg="black"frameHeight={frameHeight}frameWidth={frameWidth}+ opacity={isDragging ? 0.55 : undefined}onContextMenu={onContextMenu ? handleContextMenu : undefined}>+ {dragItem ? (+ // Not a button: like the gallery thumbnail and the image frame, the+ // drag surface must stay unfocusable — a focusable activator lets the+ // KeyboardSensor start an invisible drag on Enter/Space that Tab then+ // DROPS on the closest-center droppable.+ <Badge+ ref={setDragHandleRef}+ {...listeners}+ cursor={isDragging ? 'grabbing' : 'grab'}+ insetInlineStart="2"+ position="absolute"+ size="xs"+ title={t('widgets.preview.dragVideo')}+ top="2"+ touchAction="none"+ variant="solid"+ // Above the failure overlay: a clip that cannot play can still be+ // dragged into an input, which only needs its name.+ zIndex="2"+ >+ <GripVerticalIcon aria-hidden="true" size={12} />+ </Badge>+ ) : null}{/* User-provided gallery videos do not include a caption-track contract. */}{/* oxlint-disable-next-line jsx-a11y/media-has-caption */}<videodiff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameDrag.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameDrag.browser.test.tsxindex a4fe432d33..649893e50c 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameDrag.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameDrag.browser.test.tsx@@ -11,7 +11,7 @@ import {useSensors,type DragEndEvent,} from '@dnd-kit/core';-import { isGalleryImageDragData } from '@features/gallery/utility';+import { isGalleryImageDragData, isGalleryItemDragData } from '@features/gallery/utility';import { system } from '@theme/system';import { widgetCollisionDetection } from '@workbench/widgetDnd';import { createInstance } from 'i18next';@@ -28,7 +28,11 @@ void i18n.use(initReactI18next).init({initAsync: false,lng: 'en',resources: {- en: { translation: { widgets: { preview: { dropToCompare: 'Drop to compare', resetZoom: 'Reset zoom' } } } },+ en: {+ translation: {+ widgets: { preview: { dragVideo: 'Drag video', dropToCompare: 'Drop to compare', resetZoom: 'Reset zoom' } },+ },+ },},});@@ -77,7 +81,7 @@ const DragMonitor = ({return null;};-const renderHarness = async () => {+const renderHarness = async (media: 'image' | 'video' = 'image') => {const onDrop = vi.fn();const Harness = () => {const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 6 } }));@@ -86,15 +90,33 @@ const renderHarness = async () => {<DndContext collisionDetection={widgetCollisionDetection} sensors={sensors}><DragMonitor onDrop={onDrop} /><div style={{ display: 'flex', height: 220, left: 40, position: 'fixed', top: 40, width: 220 }}>- <PreviewFrame- dragItem={{ kind: 'image', name: 'preview.png' }}- frameHeight={128}- frameWidth={128}- isLive={false}- shouldAntialiasLiveImage- source={{ itemKey: 'image:preview.png', kind: 'image', source }}- variant="framed"- />+ {media === 'image' ? (+ <PreviewFrame+ dragItem={{ kind: 'image', name: 'preview.png' }}+ frameHeight={128}+ frameWidth={128}+ isLive={false}+ shouldAntialiasLiveImage+ source={{ itemKey: 'image:preview.png', kind: 'image', source }}+ variant="framed"+ />+ ) : (+ <PreviewFrame+ dragItem={{ kind: 'video', name: 'preview.mp4' }}+ frameHeight={128}+ frameWidth={128}+ isLive={false}+ shouldAntialiasLiveImage+ source={{+ itemKey: 'video:preview.mp4',+ kind: 'video',+ label: 'Video preview.mp4',+ poster: source.src,+ src: source.src,+ }}+ variant="framed"+ />+ )}</div><DropTarget /></DndContext>@@ -171,3 +193,35 @@ describe('PreviewFrame image drag', () => {expect(onDrop.mock.calls[0]?.[0]?.overId).toBeNull();});});++describe('PreviewFrame video drag', () => {+ it('drags the shared gallery-item payload from the corner grip handle', async () => {+ const onDrop = await renderHarness('video');+ const handle = host!.querySelector<HTMLElement>('[title="Drag video"]')!;++ expect(handle).not.toBeNull();+ // Unfocusable by design: a focusable activator would let the shell's+ // KeyboardSensor start an invisible Enter/Space drag that Tab then drops+ // on the closest-center droppable.+ expect(handle.tabIndex).toBeLessThan(0);+ expect(handle.closest('button')).toBeNull();+ const rect = handle.getBoundingClientRect();+ const startX = rect.left + rect.width / 2;+ const startY = rect.top + rect.height / 2;++ await interact(() => pointer('pointerdown', handle, startX, startY));+ await interact(() => pointer('pointermove', handle.ownerDocument, startX + 30, startY));+ await interact(() => pointer('pointermove', handle.ownerDocument, 410, 130));+ await interact(() => pointer('pointerup', handle.ownerDocument, 410, 130));++ expect(onDrop).toHaveBeenCalledOnce();+ const result = onDrop.mock.calls[0]?.[0];++ expect(result?.overId).toBe('test-image-drop');+ expect(isGalleryItemDragData(result?.activeData)).toBe(true);+ expect(result?.activeData).toEqual({+ items: [{ kind: 'video', name: 'preview.mp4' }],+ kind: 'gallery-item',+ });+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsxindex 9aa929ec24..d44a4826b8 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx@@ -671,7 +671,14 @@ const SelectedVideoPreview = ({);return (- <SelectedMediaPreview {...props} frameHeight={item.height} frameWidth={item.width} item={item} source={source} />+ <SelectedMediaPreview+ {...props}+ dragItem={toGalleryItemRef(item)}+ frameHeight={item.height}+ frameWidth={item.width}+ item={item}+ source={source}+ />);};