diff --git a/components.json b/components.json index cc5046ed69..607f7adbdf 100644 --- a/components.json +++ b/components.json @@ -1,5 +1,7 @@ { "src/components/views/auth/AuthFooter.tsx": "src/components/views/auth/VectorAuthFooter.tsx", "src/components/views/auth/AuthHeaderLogo.tsx": "src/components/views/auth/VectorAuthHeaderLogo.tsx", - "src/components/views/auth/AuthPage.tsx": "src/components/views/auth/VectorAuthPage.tsx" + "src/components/views/auth/AuthPage.tsx": "src/components/views/auth/VectorAuthPage.tsx", + "src/components/views/rooms/Autocomplete.tsx": "src/components/views/rooms/Autocomplete.tsx", + "src/editor/commands.tsx": "src/editor/commands.tsx" } diff --git a/src/components/views/rooms/Autocomplete.tsx b/src/components/views/rooms/Autocomplete.tsx new file mode 100644 index 0000000000..d23fd170bc --- /dev/null +++ b/src/components/views/rooms/Autocomplete.tsx @@ -0,0 +1,31 @@ +import React from "react"; + +export const generateCompletionDomId = (n: number): string => `mx_Autocomplete_Completion_${n}`; + +export default class Autocomplete extends React.PureComponent { + public constructor(props: {} | Readonly<{}>) { + super(props); + + this.state = { + // list of completionResults, each containing completions + completions: [], + + // array of completions, so we can look up current selection by offset quickly + completionList: [], + + // how far down the completion list we are (THIS IS 1-INDEXED!) + selectionOffset: 1, + + // whether we should show completions if they're available + shouldShowCompletions: true, + + hide: false, + + forceComplete: false, + }; + } + + public render(): React.ReactNode { + return null; + } +} diff --git a/src/editor/commands.tsx b/src/editor/commands.tsx new file mode 100644 index 0000000000..e655e81171 --- /dev/null +++ b/src/editor/commands.tsx @@ -0,0 +1,34 @@ +import { IContent, MatrixClient } from "matrix-js-sdk/src/matrix"; +import { Command, getCommand } from "matrix-react-sdk/src/SlashCommands"; +import EditorModel from "matrix-react-sdk/src/editor/model"; +import { Type } from "matrix-react-sdk/src/editor/parts"; + +export function isSlashCommand(model: EditorModel): boolean { + return false; +} + +export function getSlashCommand(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 + if (part.type === Type.UserPill || part.type === Type.RoomPill) { + return text + part.resourceId; + } + return text + part.text; + }, ""); + const { cmd, args } = getCommand(commandText); + return [cmd, args, commandText]; +} + +export async function runSlashCommand( + matrixClient: MatrixClient, + cmd: Command, + args: string | undefined, + roomId: string, + threadId: string | null, +): Promise<[content: IContent | null, success: boolean]> { + return [null, false]; +} + +export async function shouldSendAnyway(commandText: string): Promise { + return true; +}