Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion packages/element-web-module-api/element-web-module-api.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ export interface AccountAuthInfo {
userId: string;
}

// @public
export interface AccountDataApi {
delete(eventType: string): Promise<void>;
get(eventType: string): unknown;
set(eventType: string, content: unknown): Promise<void>;
}

// @public
export interface ActionsApi {
openRoom: (roomId: string) => void;
}

// @alpha @deprecated (undocumented)
export interface AliasCustomisations {
// (undocumented)
Expand All @@ -35,8 +47,10 @@ export interface AliasCustomisations {
//
// @public
export interface Api extends LegacyModuleApiExtension, LegacyCustomisationsApiExtension, DialogApiExtension, AccountAuthApiExtension, ProfileApiExtension {
readonly actions: ActionsApi;
// @alpha
readonly builtins: BuiltinsApi;
readonly client: ClientApi;
readonly config: ConfigApi;
createRoot(element: Element): Root;
// @alpha
Expand All @@ -46,11 +60,13 @@ export interface Api extends LegacyModuleApiExtension, LegacyCustomisationsApiEx
readonly i18n: I18nApi;
readonly navigation: NavigationApi;
readonly rootNode: HTMLElement;
readonly stores: StoresApi;
}

// @alpha
export interface BuiltinsApi {
getRoomViewComponent(): React.ComponentType<RoomViewProps>;
renderRoomAvatar(roomId: string, size?: string): React.ReactNode;
renderRoomView(roomId: string): React.ReactNode;
}

// @alpha @deprecated (undocumented)
Expand All @@ -64,6 +80,12 @@ export interface ChatExportCustomisations<ExportFormat, ExportType> {
};
}

// @public
export interface ClientApi {
getAccountDataApi: () => AccountDataApi;
getRoom: (id: string) => Room | null;
}

// @alpha @deprecated (undocumented)
export interface ComponentVisibilityCustomisations {
shouldShowComponent?(component: "UIComponent.sendInvites" | "UIComponent.roomCreation" | "UIComponent.spaceCreation" | "UIComponent.exploreRooms" | "UIComponent.addIntegrations" | "UIComponent.filterContainer" | "UIComponent.roomOptionsMenu"): boolean;
Expand Down Expand Up @@ -311,11 +333,24 @@ export interface ProfileApiExtension {
readonly profile: Watchable<Profile>;
}

// @public
export interface Room {
getLastActiveTimestamp: () => number;
id: string;
name: Watchable<string>;
}

// @alpha @deprecated (undocumented)
export interface RoomListCustomisations<Room> {
isRoomVisible?(room: Room): boolean;
}

// @public
export interface RoomListStoreApi {
getRooms(): Room[];
waitForReady(): Promise<void>;
}

// @alpha
export interface RoomViewProps {
roomId?: string;
Expand All @@ -334,6 +369,11 @@ export interface SpacePanelItemProps {
tooltip?: string;
}

// @public
export interface StoresApi {
getRoomListStore(): RoomListStoreApi;
}

// @public
export type Translations = Record<string, {
[ietfLanguageTag: string]: string;
Expand All @@ -359,6 +399,10 @@ export type Variables = {
// @public
export class Watchable<T> {
constructor(currentValue: T);
// Warning: (ae-forgotten-export) The symbol "WatchFn" needs to be exported by the entry point index.d.ts
//
// (undocumented)
protected readonly listeners: Set<WatchFn<T>>;
// (undocumented)
unwatch(listener: (value: T) => void): void;
// (undocumented)
Expand Down
18 changes: 18 additions & 0 deletions packages/element-web-module-api/src/api/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2025 New Vector Ltd.

SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/

/**
* Exposes certain action that can be performed on element-web.
* @public
*/
export interface ActionsApi {
/**
* Open a room in element-web.
* @param roomId - id of the room to open
*/
openRoom: (roomId: string) => void;
}
16 changes: 12 additions & 4 deletions packages/element-web-module-api/src/api/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ export interface RoomViewProps {
*/
export interface BuiltinsApi {
/**
* Returns the RoomView component used by Element Web to render a room such that
* modules can render it as part of their own custom room views.
* Render room avatar component from element-web.
*
* @alpha
* @returns The RoomView component.
* @param roomId - Id of the room
* @param size - Size of the avatar to render
*/
getRoomViewComponent(): React.ComponentType<RoomViewProps>;
renderRoomAvatar(roomId: string, size?: string): React.ReactNode;

/**
* Render room view component from element-web.
*
* @alpha
* @param roomId - Id of the room
*/
renderRoomView(roomId: string): React.ReactNode;
}
45 changes: 45 additions & 0 deletions packages/element-web-module-api/src/api/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright 2025 New Vector Ltd.

SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/

import type { Room } from "../models/Room";

/**
* Modify account data stored on the homeserver.
* @public
*/
export interface AccountDataApi {
/**
* Fetch account data stored from homeserver.
*/
get(eventType: string): unknown;
/**
* Sett account data on the homeserver.
*/
set(eventType: string, content: unknown): Promise<void>;
/**
* Delete account data from homeserver.
*/
delete(eventType: string): Promise<void>;
}

/**
* Access some limited functionality from the SDK.
* @public
*/
export interface ClientApi {
/**
* Use this to modify account data on the homeserver.
*/
getAccountDataApi: () => AccountDataApi;

/**
* Fetch room by id from SDK.
* @param id - Id of the room to get
* @returns Room object from SDK
*/
getRoom: (id: string) => Room | null;
}
18 changes: 18 additions & 0 deletions packages/element-web-module-api/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { AccountAuthApiExtension } from "./auth.ts";
import { ProfileApiExtension } from "./profile.ts";
import { ExtrasApi } from "./extras.ts";
import { BuiltinsApi } from "./builtins.ts";
import { StoresApi } from "./stores.ts";
import { ClientApi } from "./client.ts";
import { ActionsApi } from "./actions.ts";

/**
* Module interface for modules to implement.
Expand Down Expand Up @@ -123,6 +126,21 @@ export interface Api
*/
readonly extras: ExtrasApi;

/**
* Allows modules to access a limited functionality of certain stores from Element Web.
*/
readonly stores: StoresApi;

/**
* Access some very specific functionality from MatrixClient.
*/
readonly client: ClientApi;

/**
* Exposes certain predefined actions that can be performed on Element Web.
*/
readonly actions: ActionsApi;

/**
* Create a ReactDOM root for rendering React components.
* Exposed to allow modules to avoid needing to bundle their own ReactDOM.
Expand Down
35 changes: 35 additions & 0 deletions packages/element-web-module-api/src/api/stores.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2025 New Vector Ltd.

SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/

import type { Room } from "../models/Room";

/**
* Provides some basic functionality of the Room List Store from element-web.
* @public
*/
export interface RoomListStoreApi {
/**
* Get a flat list of sorted room from the RLS.
*/
getRooms(): Room[];

/**
* Returns a promise that resolves when RLS is ready.
*/
waitForReady(): Promise<void>;
}

/**
* Provides access to certain stores from element-web.
* @public
*/
export interface StoresApi {
/**
* Use this to access limited functionality of the RLS from element-web.
*/
getRoomListStore(): RoomListStoreApi;
}
2 changes: 1 addition & 1 deletion packages/element-web-module-api/src/api/watchable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function isObject(value: unknown): value is object {
* @public
*/
export class Watchable<T> {
private readonly listeners = new Set<WatchFn<T>>();
protected readonly listeners = new Set<WatchFn<T>>();

public constructor(private currentValue: T) {}

Expand Down
4 changes: 4 additions & 0 deletions packages/element-web-module-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type { Api, Module, ModuleFactory } from "./api";
export type { Config, ConfigApi } from "./api/config";
export type { I18nApi, Variables, Translations } from "./api/i18n";
export type * from "./models/event";
export type * from "./models/Room";
export type * from "./api/custom-components";
export type * from "./api/extras";
export type * from "./api/legacy-modules";
Expand All @@ -19,4 +20,7 @@ export type * from "./api/dialog";
export type * from "./api/profile";
export type * from "./api/navigation";
export type * from "./api/builtins";
export type * from "./api/stores";
export type * from "./api/client";
export type * from "./api/actions";
export * from "./api/watchable";
28 changes: 28 additions & 0 deletions packages/element-web-module-api/src/models/Room.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2025 New Vector Ltd.

SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/

import { Watchable } from "../api/watchable";

/**
* Represents a room from element-web.
* @public
*/
export interface Room {
/**
* Id of this room.
*/
id: string;
/**
* {@link Watchable} holding the name for this room.
*/
name: Watchable<string>;
/**
* Get the timestamp of the last message in this room.
* @returns last active timestamp
*/
getLastActiveTimestamp: () => number;
}