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
import type { GraphPreviewInvoke } from '@features/workflow/contracts';
import type { GraphBearingSurfaceContract } from '@workbench/widgetContracts';
import { ensureModelsLoaded, useModelsSelector } from '@features/models';
import { GraphPreviewDialog } from '@features/workflow/preview';
import { ensureInvocationTemplatesLoaded, useInvocationTemplatesSnapshot } from '@features/workflow/react';
import { useMountEffect } from '@platform/react/useMountEffect';
import { useActiveProjectSelector, useActiveProjectSettingsSelector } from '@workbench/WorkbenchContext';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { buildGraphPreviewSource } from './graphPreviewSource';
/** Subscribe to the whole project only while the preview is open so graph compilation follows settings edits. */
export const GraphPreviewHost = ({
invoke,
isOpen,
surface,
onExitComplete,
onOpenChange,
}: {
/** The top bar's Invoke for this surface (`GraphPreviewInvokeScopeContext`); none without a shell to provide it. */
invoke?: GraphPreviewInvoke;
isOpen: boolean;
surface: GraphBearingSurfaceContract;
/** Fires when the close transition has played out — the menu drops the mount here. */
onExitComplete: () => void;
onOpenChange: (isOpen: boolean) => void;
}) => {
const { t } = useTranslation();
const project = useActiveProjectSelector((activeProject) => activeProject);
const projectSettings = useActiveProjectSettingsSelector((settings) => settings, Object.is);
const modelsStatus = useModelsSelector((snapshot) => snapshot.status);
const models = useModelsSelector((snapshot) => snapshot.models);
const templates = useInvocationTemplatesSnapshot();
const availabilityModels = modelsStatus === 'loaded' ? models : undefined;
const source = useMemo(
() => buildGraphPreviewSource({ models: availabilityModels, project, projectSettings, surface, t, templates }),
[availabilityModels, project, projectSettings, surface, t, templates]
);
useMountEffect(() => {
void ensureModelsLoaded();
ensureInvocationTemplatesLoaded();
});
return (
<GraphPreviewDialog
graphId={surface.graphId}
invoke={invoke}
isOpen={isOpen}
source={source}
sourceId={surface.sourceId}
sourceLabel={surface.label}
onExitComplete={onExitComplete}
onOpenChange={onOpenChange}
/>
);
};
export default GraphPreviewHost;