Skip to content

Commit 39d670d

Browse files
authored
Merge pull request #79 from element-hq/dbkr/module_experiments
Add some module interfaces
2 parents 2823795 + 1d5a6db commit 39d670d

File tree

6 files changed

+161
-0
lines changed

6 files changed

+161
-0
lines changed

packages/element-web-module-api/element-web-module-api.api.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,24 @@ export interface AliasCustomisations {
3535
//
3636
// @public
3737
export interface Api extends LegacyModuleApiExtension, LegacyCustomisationsApiExtension, DialogApiExtension, AccountAuthApiExtension, ProfileApiExtension {
38+
// @alpha
39+
readonly builtins: BuiltinsApi;
3840
readonly config: ConfigApi;
3941
createRoot(element: Element): Root;
4042
// @alpha
4143
readonly customComponents: CustomComponentsApi;
44+
// @alpha
45+
readonly extras: ExtrasApi;
4246
readonly i18n: I18nApi;
4347
readonly navigation: NavigationApi;
4448
readonly rootNode: HTMLElement;
4549
}
4650

51+
// @alpha
52+
export interface BuiltinsApi {
53+
getRoomViewComponent(): React.ComponentType<RoomViewProps>;
54+
}
55+
4756
// @alpha @deprecated (undocumented)
4857
export interface ChatExportCustomisations<ExportFormat, ExportType> {
4958
getForceChatExportParameters(): {
@@ -140,6 +149,11 @@ export interface DirectoryCustomisations {
140149
requireCanonicalAliasAccessToPublish?(): boolean;
141150
}
142151

152+
// @alpha
153+
export interface ExtrasApi {
154+
setSpacePanelItem(spaceKey: string, props: SpacePanelItemProps): void;
155+
}
156+
143157
// @public
144158
export interface I18nApi {
145159
get language(): string;
@@ -186,6 +200,9 @@ export interface LifecycleCustomisations {
186200
onLoggedOutAndStorageCleared?(): void;
187201
}
188202

203+
// @alpha
204+
export type LocationRenderFunction = () => JSX.Element;
205+
189206
// @alpha
190207
export interface MatrixEvent {
191208
content: Record<string, unknown>;
@@ -272,6 +289,8 @@ export class ModuleLoader {
272289

273290
// @public
274291
export interface NavigationApi {
292+
// @alpha
293+
registerLocationRenderer(path: string, renderer: LocationRenderFunction): void;
275294
toMatrixToLink(link: string, join?: boolean): Promise<void>;
276295
}
277296

@@ -297,9 +316,24 @@ export interface RoomListCustomisations<Room> {
297316
isRoomVisible?(room: Room): boolean;
298317
}
299318

319+
// @alpha
320+
export interface RoomViewProps {
321+
roomId?: string;
322+
}
323+
300324
// @alpha @deprecated (undocumented)
301325
export type RuntimeModuleConstructor = new (api: ModuleApi) => RuntimeModule;
302326

327+
// @alpha
328+
export interface SpacePanelItemProps {
329+
className?: string;
330+
icon?: JSX.Element;
331+
label: string;
332+
onSelected: () => void;
333+
style?: React.CSSProperties;
334+
tooltip?: string;
335+
}
336+
303337
// @public
304338
export type Translations = Record<string, {
305339
[ietfLanguageTag: string]: string;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2025 New Vector Ltd.
3+
4+
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5+
Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
/**
9+
* The props that must be passed to a RoomView component.
10+
* @alpha Subject to change.
11+
*/
12+
export interface RoomViewProps {
13+
/**
14+
* The ID of the room to render.
15+
*/
16+
roomId?: string;
17+
}
18+
19+
/**
20+
* Exposes components and classes that are part of Element Web to allow modules to
21+
* render the components as part of their custom components or use the classes
22+
* (because they can't import the components from Element Web since it would cause
23+
* a dependency cycle)
24+
* @alpha
25+
*/
26+
export interface BuiltinsApi {
27+
/**
28+
* Returns the RoomView component used by Element Web to render a room such that
29+
* modules can render it as part of their own custom room views.
30+
*
31+
* @alpha
32+
* @returns The RoomView component.
33+
*/
34+
getRoomViewComponent(): React.ComponentType<RoomViewProps>;
35+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright 2025 New Vector Ltd.
3+
4+
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5+
Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
import { JSX } from "react";
9+
10+
/**
11+
* Properties of an item added to the Space panel
12+
* @alpha
13+
*/
14+
export interface SpacePanelItemProps {
15+
/**
16+
* A CSS class name for the item
17+
*/
18+
className?: string;
19+
20+
/**
21+
* An icon to show in the item. If not provided, no icon will be shown.
22+
*/
23+
icon?: JSX.Element;
24+
25+
/**
26+
* The label to show in the item
27+
*/
28+
label: string;
29+
30+
/**
31+
* A tooltip to show when hovering over the item
32+
*/
33+
tooltip?: string;
34+
35+
/**
36+
* Styles to apply to the item
37+
*/
38+
style?: React.CSSProperties;
39+
40+
/**
41+
* Callback when the item is selected
42+
*/
43+
onSelected: () => void;
44+
}
45+
46+
/**
47+
* API for inserting extra UI into Element Web.
48+
* @alpha Subject to change.
49+
*/
50+
export interface ExtrasApi {
51+
/**
52+
* Inserts an item into the space panel as if it were a space button, below
53+
* buttons for other spaces.
54+
* If called again with the same spaceKey, will update the existing item.
55+
* @param spaceKey - A key to identify this space-like item.
56+
* @param props - Properties of the item to add.
57+
*/
58+
setSpacePanelItem(spaceKey: string, props: SpacePanelItemProps): void;
59+
}

packages/element-web-module-api/src/api/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { NavigationApi } from "./navigation.ts";
1515
import { DialogApiExtension } from "./dialog.ts";
1616
import { AccountAuthApiExtension } from "./auth.ts";
1717
import { ProfileApiExtension } from "./profile.ts";
18+
import { ExtrasApi } from "./extras.ts";
19+
import { BuiltinsApi } from "./builtins.ts";
1820

1921
/**
2022
* Module interface for modules to implement.
@@ -103,12 +105,24 @@ export interface Api
103105
*/
104106
readonly customComponents: CustomComponentsApi;
105107

108+
/**
109+
* Allows modules to render components that are part of Element Web.
110+
* @alpha
111+
*/
112+
readonly builtins: BuiltinsApi;
113+
106114
/**
107115
* API to navigate the application.
108116
* @public
109117
*/
110118
readonly navigation: NavigationApi;
111119

120+
/**
121+
* Allows modules to insert extra UI into Element Web.
122+
* @alpha
123+
*/
124+
readonly extras: ExtrasApi;
125+
112126
/**
113127
* Create a ReactDOM root for rendering React components.
114128
* Exposed to allow modules to avoid needing to bundle their own ReactDOM.

packages/element-web-module-api/src/api/navigation.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
55
Please see LICENSE files in the repository root for full details.
66
*/
77

8+
import { JSX } from "react";
9+
10+
/**
11+
* A function called to render a component when a user navigates to the corresponding
12+
* location. Currently renders alongside just the SpacePanel.
13+
* @alpha
14+
*/
15+
export type LocationRenderFunction = () => JSX.Element;
16+
817
/**
918
* API methods to navigate the application.
1019
* @public
@@ -16,4 +25,12 @@ export interface NavigationApi {
1625
* @param join - If true, the user will be made to attempt to join the room/space if they are not already a member.
1726
*/
1827
toMatrixToLink(link: string, join?: boolean): Promise<void>;
28+
29+
/**
30+
* Register a renderer for a given location path.
31+
* @param path - The location path to register the renderer for.
32+
* @param renderer - The function that will render the component for the location.
33+
* @alpha
34+
*/
35+
registerLocationRenderer(path: string, renderer: LocationRenderFunction): void;
1936
}

packages/element-web-module-api/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ export type { Config, ConfigApi } from "./api/config";
1111
export type { I18nApi, Variables, Translations } from "./api/i18n";
1212
export type * from "./models/event";
1313
export type * from "./api/custom-components";
14+
export type * from "./api/extras";
1415
export type * from "./api/legacy-modules";
1516
export type * from "./api/legacy-customisations";
1617
export type * from "./api/auth";
1718
export type * from "./api/dialog";
1819
export type * from "./api/profile";
1920
export type * from "./api/navigation";
21+
export type * from "./api/builtins";
2022
export * from "./api/watchable";

0 commit comments

Comments
 (0)