/** * Shared Actions is a system in Blockbench to allow actions (including in toolbars, menus, via action control, or keybinding) to run different code in different cases, such as in different modes or different panels. * As an example, the "Duplicate" action runs code to duplicate elements when used in the outliner, and duplicates textures when used in the textures panel. * * * Handlers can be added for existing actions like this: ### Example: * @example ```javascript // Duplicate layers when using "Duplicate" in the layers panel SharedActions.add('duplicate', { subject: 'layer', condition: () => Prop.active_panel == 'layers' && TextureLayer.selected, run() { let texture = Texture.selected; let original = texture.getActiveLayer(); let copy = original.getUndoCopy(true); copy.name += '-copy'; Undo.initEdit({textures: [texture]}); let layer = new TextureLayer(copy, texture); layer.addForEditing(); Undo.finishEdit('Duplicate layer'); } }) ``` * @module */ /** * Global Shared Actions namespace to access any functionality related to Shared Actions */ export declare const SharedActions: { /** * Add a method to handle a specific use case of a shared action * @param action_id Action ID * @param handler Handler options */ add(action_id: SharedActionID, handler: SharedActionHandler): Deletable; /** * Run the active handler for a specific subject manually * @param action_id Action ID * @param event Event that triggered the interaction * @param context Optional context variable */ run(action_id: SharedActionID, event?: Event, context?: any): boolean; /** * Run a specific handler manually * @param action_id Action ID * @param subject Subject to run on * @param event Event that triggered the interaction * @param context Optional context variable * @param force Force the specified handler to run and ignore its condition */ runSpecific(action_id: SharedActionID, subject: string, event?: Event, context?: any, force?: boolean): boolean; /** * Check if there is an active and available handler in the current situation for a shared action * @param action_id */ condition(action_id: SharedActionID): boolean; /** * Find the active handler in the current situation for a shared action * @param action_id * @param event * @param context */ find(action_id: SharedActionID, event?: Event, context?: any): SharedActionHandler | null; actions: Record; }; export interface SharedActionHandler { condition: ConditionResolvable; /** * Subject type */ subject: string; /** * Handler priority * Unset or 0 is typically used for relatively specific handlers, like those that check for a specific active panel. * Higher priorities are used for even more specific conditions, like when multiple handlers work in a panel. * Lower priorities are used for more fallback-like handlers, like deleting elements in edit mode, regardless of active panel. */ priority?: number; /** * Function running the handler */ run(event: Event, context: any): void; } type SharedActionID = string | 'rename' | 'delete' | 'duplicate' | 'select_all' | 'unselect_all' | 'invert_selection'; declare const global: { SharedActions: { /** * Add a method to handle a specific use case of a shared action * @param action_id Action ID * @param handler Handler options */ add(action_id: SharedActionID, handler: SharedActionHandler): Deletable; /** * Run the active handler for a specific subject manually * @param action_id Action ID * @param event Event that triggered the interaction * @param context Optional context variable */ run(action_id: SharedActionID, event?: Event, context?: any): boolean; /** * Run a specific handler manually * @param action_id Action ID * @param subject Subject to run on * @param event Event that triggered the interaction * @param context Optional context variable * @param force Force the specified handler to run and ignore its condition */ runSpecific(action_id: SharedActionID, subject: string, event?: Event, context?: any, force?: boolean): boolean; /** * Check if there is an active and available handler in the current situation for a shared action * @param action_id */ condition(action_id: SharedActionID): boolean; /** * Find the active handler in the current situation for a shared action * @param action_id * @param event * @param context */ find(action_id: SharedActionID, event?: Event, context?: any): SharedActionHandler | null; actions: Record; }; }; declare global { const SharedActions: typeof global.SharedActions; interface BarItemRegistry { rename: Action; delete: Action; duplicate: Action; select_all: Action; unselect_all: Action; invert_selection: Action; } } export {};