Iterate
This commit is contained in:
@@ -15,8 +15,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint:ts": "tsc --noEmit",
|
"lint:ts": "tsc --noEmit"
|
||||||
"lint:js": "eslint --max-warnings 0 src"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.10.7",
|
"@types/node": "^22.10.7",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Please see LICENSE files in the repository root for full details.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
// eslint-disable-next-line no-var
|
||||||
var __VERSION__: string; // injected by vite
|
var __VERSION__: string; // injected by vite
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const moduleExportSignature: Record<keyof ModuleExport, Type> = {
|
|||||||
|
|
||||||
type Type = "function" | "string" | "number" | "boolean" | "object";
|
type Type = "function" | "string" | "number" | "boolean" | "object";
|
||||||
|
|
||||||
export function isInterface<T>(obj: any, keys: Record<keyof T, Type>): obj is T {
|
export function isInterface<T>(obj: unknown, keys: Record<keyof T, Type>): obj is T {
|
||||||
if (obj === null || typeof obj !== "object") return false;
|
if (obj === null || typeof obj !== "object") return false;
|
||||||
for (const key in keys) {
|
for (const key in keys) {
|
||||||
if (typeof obj[key] !== keys[key]) return false;
|
if (typeof obj[key] !== keys[key]) return false;
|
||||||
@@ -45,7 +45,7 @@ export function isInterface<T>(obj: any, keys: Record<keyof T, Type>): obj is T
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isModule(module: any): module is ModuleExport {
|
export function isModule(module: unknown): module is ModuleExport {
|
||||||
return (
|
return (
|
||||||
isInterface(module, moduleExportSignature) &&
|
isInterface(module, moduleExportSignature) &&
|
||||||
isInterface(module.default, moduleFactorySignature) &&
|
isInterface(module.default, moduleFactorySignature) &&
|
||||||
|
|||||||
@@ -77,12 +77,12 @@ export interface Media {
|
|||||||
downloadSource(): Promise<Response>;
|
downloadSource(): Promise<Response>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MediaContructable {
|
export interface MediaContructable<Thumbnail, File> {
|
||||||
new (prepared: { mxc: string; thumbnail?: any; file?: any }): Media;
|
new (prepared: { mxc: string; thumbnail?: Thumbnail; file?: File }): Media;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MediaCustomisations<Content, Client> {
|
export interface MediaCustomisations<Content, Client, Thumbnail, File> {
|
||||||
readonly Media: MediaContructable;
|
readonly Media: MediaContructable<Thumbnail, File>;
|
||||||
mediaFromContent(content: Content, client?: Client): Media;
|
mediaFromContent(content: Content, client?: Client): Media;
|
||||||
mediaFromMxc(mxc?: string, client?: Client): Media;
|
mediaFromMxc(mxc?: string, client?: Client): Media;
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ export interface LegacyCustomisationsApiExtension {
|
|||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
readonly _registerLegacyChatExportCustomisations: LegacyCustomisations<ChatExportCustomisations<any, any>>;
|
readonly _registerLegacyChatExportCustomisations: LegacyCustomisations<ChatExportCustomisations<never, never>>;
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
@@ -182,11 +182,11 @@ export interface LegacyCustomisationsApiExtension {
|
|||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
readonly _registerLegacyMediaCustomisations: LegacyCustomisations<MediaCustomisations<any, any>>;
|
readonly _registerLegacyMediaCustomisations: LegacyCustomisations<MediaCustomisations<never, never, never, never>>;
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
readonly _registerLegacyRoomListCustomisations: LegacyCustomisations<RoomListCustomisations<any>>;
|
readonly _registerLegacyRoomListCustomisations: LegacyCustomisations<RoomListCustomisations<never>>;
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
@@ -195,7 +195,7 @@ export interface LegacyCustomisationsApiExtension {
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
readonly _registerLegacyWidgetPermissionsCustomisations: LegacyCustomisations<
|
readonly _registerLegacyWidgetPermissionsCustomisations: LegacyCustomisations<
|
||||||
WidgetPermissionsCustomisations<any, any>
|
WidgetPermissionsCustomisations<never, never>
|
||||||
>;
|
>;
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore -- optional interface, will gracefully degrade to `any` if `react-sdk-module-api` isn't installed
|
// @ts-ignore -- optional interface, will gracefully degrade to `any` if `react-sdk-module-api` isn't installed
|
||||||
import type { ModuleApi, RuntimeModule } from "@matrix-org/react-sdk-module-api";
|
import type { ModuleApi, RuntimeModule } from "@matrix-org/react-sdk-module-api";
|
||||||
|
|
||||||
export type RuntimeModuleConstructor = new (api: ModuleApi) => RuntimeModule;
|
export type RuntimeModuleConstructor = new (api: ModuleApi) => RuntimeModule;
|
||||||
|
|
||||||
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
export interface LegacyModuleApiExtension {
|
export interface LegacyModuleApiExtension {
|
||||||
/**
|
/**
|
||||||
* Register a legacy module based on @matrix-org/react-sdk-module-api
|
* Register a legacy module based on @matrix-org/react-sdk-module-api
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { satisfies } from "semver";
|
|||||||
import { Api, isModule, Module, ModuleExport } from "./api";
|
import { Api, isModule, Module, ModuleExport } from "./api";
|
||||||
|
|
||||||
export class ModuleIncompatibleError extends Error {
|
export class ModuleIncompatibleError extends Error {
|
||||||
constructor(pluginVersion: string) {
|
public constructor(pluginVersion: string) {
|
||||||
super(`Plugin version ${pluginVersion} is incompatible with engine version ${__VERSION__}`);
|
super(`Plugin version ${pluginVersion} is incompatible with engine version ${__VERSION__}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,8 @@ export class ModuleLoader {
|
|||||||
if (!satisfies(__VERSION__, moduleExport.default.moduleApiVersion)) {
|
if (!satisfies(__VERSION__, moduleExport.default.moduleApiVersion)) {
|
||||||
throw new ModuleIncompatibleError(moduleExport.default.moduleApiVersion);
|
throw new ModuleIncompatibleError(moduleExport.default.moduleApiVersion);
|
||||||
}
|
}
|
||||||
this.#modules.push(new moduleExport.default(this.api));
|
const { default: Module } = moduleExport;
|
||||||
|
this.#modules.push(new Module(this.api));
|
||||||
}
|
}
|
||||||
|
|
||||||
#started = false;
|
#started = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user