Skip to content

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.

1.0 KB
Raw Blame
import { isGalleryItemDragData } from '@features/gallery/utility';

export type WorkflowMediaKind = 'image' | 'video';

export interface WorkflowMediaDropItem {
  kind: WorkflowMediaKind;
  name: string;
}

export const getWorkflowMediaFieldDropId = (fieldKey: string): string => `workflow-media-field:${fieldKey}`;

/** Every dragged gallery item of `kind`; empty when the drag carries anything else. */
export const getWorkflowMediaFieldDropItems = (
  activeData: unknown,
  kind: WorkflowMediaKind
): WorkflowMediaDropItem[] =>
  isGalleryItemDragData(activeData) && activeData.items.every((item) => item.kind === kind)
    ? activeData.items.map((item) => ({ kind, name: item.name }))
    : [];

/** Reject multi-item drags for single-value media fields instead of silently taking the first. */
export const getWorkflowMediaFieldDropItem = (
  activeData: unknown,
  kind: WorkflowMediaKind
): WorkflowMediaDropItem | null => {
  const items = getWorkflowMediaFieldDropItems(activeData, kind);

  return items.length === 1 ? (items[0] ?? null) : null;
};