import type { ReactNode } from "react"; import type { SlideElement } from "@/components/slide-editor/types"; import type { TemplateFontOption } from "@/components/slide-editor/text/google-fonts"; import type { TextSelectionRange } from "@/components/slide-editor/text/text-runs"; import type { TableCellSelection } from "@/components/slide-editor/state/state"; import type { ComponentActionsMenuActions } from "@/components/slide-editor/selection/ComponentActionsMenu"; import { BulletsToolbar } from "@/components/slide-editor/text/BulletsToolbar"; import { ChartToolbar } from "@/components/slide-editor/charts/ChartToolbar"; import { DesignVariablesToolbar } from "@/components/slide-editor/toolbar/DesignVariablesToolbar"; import { ImageToolbar } from "@/components/slide-editor/images/ImageToolbar"; import { LineToolbar } from "@/components/slide-editor/shapes/LineToolbar"; import { ShapeToolbar } from "@/components/slide-editor/shapes/ShapeToolbar"; import { TableToolbar } from "@/components/slide-editor/tables/TableToolbar"; import { TextToolbar } from "@/components/slide-editor/text/TextToolbar"; type ElementToolbarProps = { element: SlideElement; index: number; anchorBox?: { x: number; y: number; width: number; height: number; } | null; path: string; scale: number; componentActions?: ComponentActionsMenuActions | null; selectedTableCell: TableCellSelection | null; templateFonts?: TemplateFontOption[]; textSelectionRange?: TextSelectionRange | null; onChange: (index: number, element: SlideElement, path?: string) => void; onEditImage: (index: number, path?: string) => void; onEditText?: (index: number, path?: string) => void; }; type ToolbarRenderer = (props: ElementToolbarProps) => ReactNode; const TOOLBAR_RENDERERS: Partial< Record > = { text: ({ element, anchorBox, index, onChange, path, scale, componentActions, templateFonts, textSelectionRange, }) => element.type === "text" ? ( onChange(index, element, path)} /> ) : null, "text-list": ({ element, anchorBox, index, onChange, path, scale, componentActions, templateFonts, textSelectionRange, }) => element.type === "text-list" ? ( onChange(index, element, path)} /> ) : null, image: ({ anchorBox, element, index, onChange, onEditImage, path, scale }) => element.type === "image" ? ( onChange(index, element, path)} onUpload={(index) => onEditImage(index, path)} /> ) : null, rectangle: ({ anchorBox, componentActions, element, index, onChange, path, scale }) => element.type === "rectangle" || element.type === "ellipse" ? ( onChange(index, element, path)} /> ) : null, ellipse: ({ anchorBox, componentActions, element, index, onChange, path, scale }) => element.type === "rectangle" || element.type === "ellipse" ? ( onChange(index, element, path)} /> ) : null, line: ({ anchorBox, componentActions, element, index, onChange, path, scale }) => element.type === "line" ? ( onChange(index, element, path)} /> ) : null, chart: ({ anchorBox, element, index, onChange, path, scale }) => element.type === "chart" ? ( onChange(index, element, path)} /> ) : null, table: ({ anchorBox, element, index, onChange, path, scale, selectedTableCell, }) => element.type === "table" ? ( onChange(index, element, path)} /> ) : null, }; export function ElementToolbar(props: ElementToolbarProps) { if (props.element.design_variables?.length) { return ( props.onChange(index, element, props.path) } /> ); } const renderToolbar = TOOLBAR_RENDERERS[props.element.type]; return renderToolbar ? renderToolbar(props) : null; }