Add UI button registration API (registerButton, unregisterButton, getButtonsForLocation)

This commit is contained in:
2026-04-22 00:51:57 +10:00
parent 6f506c59a4
commit 6c389381df
20 changed files with 438 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
import type { Plugin, PluginContext, PluginCommand, MessageInterceptor, MessageContext, CustomRenderer, SettingsSchema, PluginTheme, PluginLogEntry } from './PluginInterfaces.js';
import type { Plugin, PluginContext, PluginCommand, MessageInterceptor, MessageContext, CustomRenderer, SettingsSchema, PluginTheme, PluginLogEntry, UIButtonDefinition, UILocation } from './PluginInterfaces.js';
import type { IPluginStorage } from './interfaces.js';
/**
* Configuration options for the PluginRegistry.
@@ -32,6 +32,7 @@ export declare class PluginRegistry {
private beforeSendInterceptors;
private receiveInterceptors;
private readonly renderers;
private readonly buttons;
private readonly settingsSchemas;
private readonly pluginSettings;
private readonly matrixHandlers;
@@ -52,7 +53,7 @@ export declare class PluginRegistry {
/** Remove a registered command by name. */
unregisterCommand(name: string): void;
/** Execute a command by name, passing raw argument string. */
executeCommand(name: string, rawArgs: string): Promise<string | void>;
executeCommand(name: string, rawArgs: string, roomId?: string): Promise<string | void>;
private parseCommandArgs;
/** Return all registered commands. */
getCommands(): Array<{
@@ -74,6 +75,22 @@ export declare class PluginRegistry {
unregisterRenderer(type: string): void;
/** Get the renderer for a given type, if any. */
getRenderer(type: string): CustomRenderer | undefined;
/** Register a UI button contributed by a plugin. */
registerButton(pluginId: string, button: UIButtonDefinition): void;
/** Remove a registered button by ID. */
unregisterButton(pluginId: string, buttonId: string): void;
/**
* Get all buttons for a specific UI location, sorted by position configuration.
* Returns buttons in the order they should be rendered.
*/
getButtonsForLocation(location: UILocation): UIButtonDefinition[];
/**
* Sort buttons according to their position configuration.
* - Buttons with position.before/after are positioned relative to existing buttons
* - Buttons in groups are kept together
* - Within groups, buttons are sorted by order property
*/
private sortButtonsByPosition;
/** Define the settings schema for a plugin and load persisted values. */
defineSettings(pluginId: string, schema: SettingsSchema): void;
/** Get a plugin setting value. */