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.

2.1 KB
Raw Blame
import type { FlexProps } from '@invoke-ai/ui-library';
import { ContextMenu, Flex, MenuList } from '@invoke-ai/ui-library';
import { ControlLayerMenuItems } from 'features/controlLayers/components/ControlLayer/ControlLayerMenuItems';
import { InpaintMaskMenuItems } from 'features/controlLayers/components/InpaintMask/InpaintMaskMenuItems';
import { RasterLayerMenuItems } from 'features/controlLayers/components/RasterLayer/RasterLayerMenuItems';
import { IPAdapterMenuItems } from 'features/controlLayers/components/RefImage/IPAdapterMenuItems';
import { RegionalGuidanceMenuItems } from 'features/controlLayers/components/RegionalGuidance/RegionalGuidanceMenuItems';
import { useEntityIdentifierContext } from 'features/controlLayers/contexts/EntityIdentifierContext';
import { memo, useCallback } from 'react';
import { assert } from 'tsafe';

export const CanvasEntityHeader = memo(({ children, ...rest }: FlexProps) => {
  const entityIdentifier = useEntityIdentifierContext();
  const renderMenu = useCallback(() => {
    if (entityIdentifier.type === 'regional_guidance') {
      return (
        <MenuList>
          <RegionalGuidanceMenuItems />
        </MenuList>
      );
    }

    if (entityIdentifier.type === 'inpaint_mask') {
      return (
        <MenuList>
          <InpaintMaskMenuItems />
        </MenuList>
      );
    }

    if (entityIdentifier.type === 'raster_layer') {
      return (
        <MenuList>
          <RasterLayerMenuItems />
        </MenuList>
      );
    }

    if (entityIdentifier.type === 'control_layer') {
      return (
        <MenuList>
          <ControlLayerMenuItems />
        </MenuList>
      );
    }

    if (entityIdentifier.type === 'reference_image') {
      return (
        <MenuList>
          <IPAdapterMenuItems />
        </MenuList>
      );
    }

    assert(false, 'Unhandled entity type');
  }, [entityIdentifier]);

  return (
    <ContextMenu renderMenu={renderMenu}>
      {(ref) => (
        <Flex ref={ref} gap={2} alignItems="center" p={2} {...rest}>
          {children}
        </Flex>
      )}
    </ContextMenu>
  );
});

CanvasEntityHeader.displayName = 'CanvasEntityHeader';