Skip to content

Commit 38e1082

Browse files
committed
Add some experimental module interfaces
...with somewhat placeholder names as they're the best I can think of right now: * 'Extras': To add new bits of UI to places (specifically the space panel) * 'Builtins': For modules to render components that are part of Element Web * 'Navigation': For modules to add paths to the URL router
1 parent 016883d commit 38e1082

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
export interface RoomViewProps {
9+
roomId?: string;
10+
}
11+
12+
/**
13+
* Exposes components that are part of Element Web to allow modules to render them
14+
* as part of their custom components (because they can't import the components from
15+
* Element Web since it would cause a dependency cycle)
16+
*/
17+
export interface BuiltinsApi {
18+
getRoomViewComponent(): React.ComponentType<RoomViewProps>;
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
interface SpacePanelItemProps {
11+
isPanelCollapsed: boolean;
12+
}
13+
14+
export type SpacePanelItemRenderFunction = (props: SpacePanelItemProps) => JSX.Element;
15+
16+
export interface ExtrasApi {
17+
addSpacePanelItem(renderer: SpacePanelItemRenderFunction): void;
18+
}

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

Lines changed: 6 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,16 @@ export interface Api
103105
*/
104106
readonly customComponents: CustomComponentsApi;
105107

108+
readonly builtins: BuiltinsApi;
109+
106110
/**
107111
* API to navigate the application.
108112
* @public
109113
*/
110114
readonly navigation: NavigationApi;
111115

116+
readonly extras: ExtrasApi;
117+
112118
/**
113119
* Create a ReactDOM root for rendering React components.
114120
* Exposed to allow modules to avoid needing to bundle their own ReactDOM.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ 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+
export type LocationRenderFunction = () => JSX.Element;
11+
812
/**
913
* API methods to navigate the application.
1014
* @public
@@ -16,4 +20,6 @@ export interface NavigationApi {
1620
* @param join - If true, the user will be made to attempt to join the room/space if they are not already a member.
1721
*/
1822
toMatrixToLink(link: string, join?: boolean): Promise<void>;
23+
24+
registerLocationRenderer(path: string, renderer: LocationRenderFunction): void;
1925
}

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)