import quip , { MenuCommand } from "quip-apps-api" ; import { AppData } from "./model/root" ; /**
 * Menu Actions are created at runtime based on a root record in
 * our Main component (since they can call actions on the main component and
 * trigger methods there). However, the menu is created before this component
 * and passed into it. The menuActions object is a lookup for menu actions
 * that may not exist yet but are guaranteed to exist at runtime.
 */ const err = ( name ) => ( ) => { throw new Error ( `MenuAction not implemented: ${ name }` ) ; } ; export interface MenuActions { toggleHighlight : ( ) => void ; } export const menuActions = { toggleHighlight : err ( "toggle-highlight" ) , } ; export class Menu { param data updateToolbar ( data ) { const subCommands = this . getMainMenuSubCommandIds_ ( data ) ; const menuCommands = subCommands . length ? [ { id : quip . apps . DocumentMenuCommands . MENU_MAIN , subCommands , } , ... this . allCommands_ , ] : this . allCommands_ ; quip . apps . updateToolbar ( { toolbarCommandIds : this . getToolbarCommandIds_ ( data ) , menuCommands , highlightedCommandIds : this . getHighlightedCommandIds_ ( data ) , disabledCommandIds : this . getDisabledCommandIds_ ( data ) , } ) ; } /**
     * This property defines all the available MenuCommands for the app.
     * The actual menu commands that appear on the app are defined
     * within the `updateToolbar` method in this class.
     */ private readonly allCommands_ : MenuCommand [ ] = [ { id : "toggle-highlight" , label : "Toggle Highlight" , handler : ( ) => menuActions . toggleHighlight ( ) , } , ] ; private getToolbarCommandIds_ ( data ) { const toolbarCommandIds_ = [ "toggle-highlight" ] ; return toolbarCommandIds_ ; } private getMainMenuSubCommandIds_ ( data ) { const mainMenuSubCommandIds = [ ] ; return mainMenuSubCommandIds ; } private getHighlightedCommandIds_ ( data ) { const { isHighlighted } = data ; const highlightedCommandIds = isHighlighted ? [ "toggle-highlight" ] : [ ] ; return highlightedCommandIds ; } private getDisabledCommandIds_ ( data ) { const disabledCommandIds = [ ] ; return disabledCommandIds ; } }