Add ts docs

This commit is contained in:
David Langley 2025-10-23 17:24:43 +01:00
parent 0a41186632
commit 484f87d672
4 changed files with 38 additions and 0 deletions

View File

@ -13,6 +13,11 @@ import { type Command, CommandCategories, Commands } from "../../../SlashCommand
import InfoDialog from "./InfoDialog";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
/**
* Props for {@link SlashCommandHelpDialog}
* @param roomId - The room ID to check whether commands are enabled
* @param onFinished - Callback called when the dialog is closed
*/
interface IProps {
roomId: string;
onFinished(): void;

View File

@ -38,6 +38,12 @@ export function isSlashCommand(model: EditorModel): boolean {
return false;
}
/**
* Get the slash command and its arguments from the editor model
* @param roomId - The room ID to check whether the command is enabled
* @param model - The editor model
* @returns A tuple of the command (or undefined if not found), the arguments (or undefined), and the full command text
*/
export function getSlashCommand(roomId: string, model: EditorModel): [Command | undefined, string | undefined, string] {
const commandText = model.parts.reduce((text, part) => {
// use mxid to textify user pills in a command and room alias/id for room pills

View File

@ -18,6 +18,14 @@ import { _t, type TranslationKey, UserFriendlyError } from "../languageHandler";
import { PosthogAnalytics } from "../PosthogAnalytics";
import { CommandCategories, type RunResult } from "./interface";
/**
* The function signature for the run function of a {@link Command}
* @param matrixClient - The Matrix client
* @param roomId - The room ID where the command is run
* @param threadId - The thread ID where the command is run, or null for room timeline
* @param args - The arguments passed to the command
* @returns The result of running the command
*/
type RunFn = (
this: Command,
matrixClient: MatrixClient,
@ -26,6 +34,19 @@ type RunFn = (
args?: string,
) => RunResult;
/**
* Options for {@link Command}
* @param command - The command name, e.g. "me" for the /me command
* @param aliases - Alternative names for the command
* @param args - The arguments for the command, e.g. "<message>" for the /me command
* @param description - A translation key describing the command
* @param analyticsName - The name to use for analytics tracking
* @param runFn - The function to execute when the command is run
* @param category - The category of the command, e.g. CommandCategories.emoji
* @param hideCompletionAfterSpace - Whether to hide autocomplete after a space is typed
* @param isEnabled - A function to determine if the command is enabled in a given context
* @param renderingTypes - The rendering types (room/thread) where this command is valid
*/
interface ICommandOpts {
command: string;
aliases?: string[];

View File

@ -29,6 +29,12 @@ export function successSync(value: any): RunResult {
return success(Promise.resolve(value));
}
/**
* Check whether the user can affect power levels in the given room
* @param cli - The Matrix client
* @param roomId - The room ID
* @returns True if the user can affect power levels, false otherwise
*/
export const canAffectPowerlevels = (cli: MatrixClient | null, roomId: string | null): boolean => {
if (!cli || !roomId) return false;
const room = cli?.getRoom(roomId);