import React, { useEffect, useState, useCallback } from "react"; // editor import { EditorMenuItemNames, EditorRefApi } from "@plane/document-editor"; // ui import { Tooltip } from "@plane/ui"; // constants import { TOOLBAR_ITEMS, ToolbarMenuItem } from "@/constants/editor"; // helpers import { cn } from "@/helpers/common.helper"; type Props = { editorRef: EditorRefApi; }; type ToolbarButtonProps = { item: ToolbarMenuItem; isActive: boolean; executeCommand: (commandName: EditorMenuItemNames) => void; }; const ToolbarButton: React.FC = React.memo((props) => { const { item, isActive, executeCommand } = props; return ( {item.name} {item.shortcut && {item.shortcut.join(" + ")}}

} >
); }); ToolbarButton.displayName = "ToolbarButton"; const toolbarItems = TOOLBAR_ITEMS.document; export const PageToolbar: React.FC = ({ editorRef }) => { const [activeStates, setActiveStates] = useState>({}); const updateActiveStates = useCallback(() => { const newActiveStates: Record = {}; Object.values(toolbarItems) .flat() .forEach((item) => { newActiveStates[item.key] = editorRef.isMenuItemActive(item.key); }); setActiveStates(newActiveStates); }, [editorRef]); useEffect(() => { const unsubscribe = editorRef.onStateChange(updateActiveStates); updateActiveStates(); return () => unsubscribe(); }, [editorRef, updateActiveStates]); return (
{Object.keys(toolbarItems).map((key) => (
{toolbarItems[key].map((item) => ( ))}
))}
); };