Skip to content

Commit 3bdb8a5

Browse files
committed
Iterate
1 parent 5b64008 commit 3bdb8a5

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ export type OriginalMessageComponentProps = {
283283
// @public
284284
export interface Profile {
285285
displayName?: string;
286+
isGuest?: boolean;
286287
userId?: string;
287288
}
288289

@@ -312,6 +313,9 @@ export interface UserIdentifierCustomisations {
312313
}): string | null;
313314
}
314315

316+
// @public
317+
export function useWatchable<T>(watchable: Watchable<T>): T;
318+
315319
// @public
316320
export type Variables = {
317321
count?: number;

packages/element-web-module-api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@types/semver": "^7.5.8",
4040
"@vitest/coverage-v8": "^3.0.4",
4141
"matrix-web-i18n": "^3.3.0",
42+
"rollup-plugin-external-globals": "^0.13.0",
4243
"semver": "^7.6.3",
4344
"typescript": "^5.7.3",
4445
"vite": "^6.1.6",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import { Watchable } from "./watchable.ts";
1212
* @public
1313
*/
1414
export interface Profile {
15+
/**
16+
* Indicates whether the user is a guest user.
17+
*/
18+
isGuest?: boolean;
1519
/**
1620
* The user ID of the logged-in user, if undefined then no user is logged in.
1721
*/

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ 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 { useEffect, useState } from "react";
9+
810
type WatchFn<T> = (value: T) => void;
911

1012
function shallowCompare<T extends object>(obj1: T, obj2: T): boolean {
@@ -55,3 +57,21 @@ export class Watchable<T> {
5557
this.listeners.delete(listener);
5658
}
5759
}
60+
61+
/**
62+
* A React hook to use an updated Watchable value.
63+
* @param watchable - The Watchable instance to watch.
64+
* @returns The live value of the Watchable.
65+
* @public
66+
*/
67+
export function useWatchable<T>(watchable: Watchable<T>): T {
68+
const [value, setValue] = useState<T>(watchable.value);
69+
useEffect(() => {
70+
setValue(watchable.value);
71+
watchable.watch(setValue);
72+
return (): void => {
73+
watchable.unwatch(setValue);
74+
};
75+
}, [watchable]);
76+
return value;
77+
}

packages/element-web-module-api/vite.config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { dirname, resolve } from "node:path";
99
import { fileURLToPath } from "node:url";
1010
import { defineConfig } from "vite";
1111
import dts from "vite-plugin-dts";
12+
import externalGlobals from "rollup-plugin-external-globals";
1213

1314
const __dirname = dirname(fileURLToPath(import.meta.url));
1415

@@ -23,9 +24,18 @@ export default defineConfig({
2324
target: "esnext",
2425
sourcemap: true,
2526
},
26-
plugins: [dts()],
27+
plugins: [
28+
dts(),
29+
externalGlobals({
30+
// Reuse React from the host app
31+
react: "window.React",
32+
}),
33+
],
2734
define: {
2835
__VERSION__: JSON.stringify(process.env.npm_package_version),
36+
// Use production mode for the build as it is tested against production builds of Element Web,
37+
// this is required for React JSX versions to be compatible.
38+
process: { env: { NODE_ENV: "production" } },
2939
},
3040
test: {
3141
coverage: {

packages/element-web-playwright-common/src/testcontainers/synapse.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ const DEFAULT_CONFIG = {
174174
include_offline_users_on_sync: true,
175175
},
176176
room_list_publication_rules: [{ action: "allow" }],
177+
modules: [] as Array<{ module: string; config?: Record<string, unknown> }>,
177178
};
178179

179180
/**

0 commit comments

Comments
 (0)