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

@@ -148,6 +148,8 @@ export interface PluginContext {
ui: {
registerRenderer: (type: string, renderer: CustomRenderer) => void;
unregisterRenderer: (type: string) => void;
registerButton: (button: UIButtonDefinition) => void;
unregisterButton: (buttonId: string) => void;
};
/** Settings API */
@@ -211,7 +213,55 @@ export type UILocation =
| 'message-actions'
| 'user-menu'
| 'room-menu'
| 'composer-actions';
| 'composer-actions'
| 'channel-list'
| 'direct-messages'
| 'home-section'
| 'search-notification-section'
| 'text-composer-toolbar'
| 'sidebar-actions';
/**
* Button positioning configuration for plugins.
* Allows buttons to be placed before or after existing elements or groups.
*/
export interface UIButtonPosition {
/** Place button before this element/group ID */
before?: string;
/** Place button after this element/group ID */
after?: string;
/**
* Optional group ID this button belongs to.
* Buttons in the same group are rendered together.
*/
group?: string;
/** Order within the group (lower numbers appear first) */
order?: number;
}
/**
* Definition for a UI button registered by a plugin.
* Framework-agnostic - the component/element is passed as unknown.
*/
export interface UIButtonDefinition {
/** Unique ID for this button */
id: string;
/** Location where the button should appear */
location: UILocation;
/** Button label or tooltip */
label: string;
/** Optional icon identifier */
icon?: string;
/** Positioning configuration */
position?: UIButtonPosition;
/**
* The actual button component or render function.
* Framework-agnostic - hosts using React should cast to ReactNode.
*/
component: unknown;
/** Optional callback when clicked (if component doesn't handle it) */
onClick?: () => void | Promise<void>;
}
/**
* The main plugin interface that all plugins must implement.