Module API for adding new file upload mechanisms (#33355)

* Initial reword of upload to MVVM.

* Update tests

* More incremental improvements

* Refactor tests to use helper method for composer uploads.

* Add drag and drop tests

* lint

* Add commentary

* fixup test

* More precise selector

* Retarget uploads

* lint

* fixup

* one more type

* update snap

* Fixup composerUploadFiles

* fix import

* lint

* Copy and paste fixes too

* Add tests for pasting

* Add tests for pasting files.

* Remove redundant fn

* rm comment

* tidy up

* Test cleanup

* More clean up

* another fix

* Begin fleshing out

* Park changes

* More stuff

* Use condensed version

* Cleanup tests

* more cleaning

* last bity

* Add a test for the composer

* Park up changes

* Rewrite Measured to be a functional component

* Add tests to cover narrow viewports

* lint

* breakpoint is optional

* Cleanup

* Support narrow mode

* fixup

* begone

* Provide default value

* add label

* fixup test

* update copyright

* cleanup

* Be a bit more lazy with FileDropTarget

* remove a debug statement

* Fixup

* fix two snaps

* Update screenshot

* and the other one

* Update snaps

* unfake CIDER

* update screens again

* remove extra test

* Undo accidental snapshots

* Bit of tidyup

* fixup

* even more tidyup

* may drag and drop file

* tidy up again

* snap snap snap

* Use load to make sonarQube happy

* Bunch of refactors

* More cleanup

* cleanup debug code

* tweaks

* remove a test we no longer need

* make it happy

* fix import

* fixup

* Update snaps

* typo

* one off

* Add tests

* lint

* remove only

* Reduce screenshot scope

* fix snapshot usage

* cleanup
This commit is contained in:
Will Hunt
2026-05-18 21:41:38 +00:00
committed by GitHub
parent 66b739fea9
commit 02b6520f09
30 changed files with 1627 additions and 831 deletions
+61 -3
View File
@@ -5,16 +5,74 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
Please see LICENSE files in the repository root for full details.
*/
import { ComponentType, SVGAttributes } from "react";
/**
* An option presented to the user for uploading a file.
* @alpha Unlikely to change
*/
export type ComposerApiFileUploadOption = {
/**
* An unique string to refer to the type of upload
* @example org.example.my_uploader
*/
type: string;
/**
* Human-readable string used in labelling for the option.
*/
label: string;
/**
* An icon to attach to the option. If omitted, no icon is shown.
*/
icon?: ComponentType<SVGAttributes<SVGElement>>;
/**
* Function called when the option is selected.
* @param roomId - The room ID of the room in focus.
* @param relation - Whether or not a thread and/or reply is in focus.
* @returns
*/
onSelected: (
roomId?: string,
view?: ComposerApiTarget,
relation?: {
inReplyToEventId?: string;
relType?: string;
},
) => Promise<void> | void;
};
/**
* When handling composer interactions, this represents the target composer.
* @alpha Likely to change. This is intentionally left as an object so it may be extended later.
*/
export type ComposerApiTarget = { view: "room" } | { view: "thread" };
/**
* API to interact with the message composer.
* @alpha Likely to change
*/
export interface ComposerApi {
/**
* Insert plaintext into the current composer.
* @param plaintext - The plain text to insert
* Add a new file upload option for the user.
* @throws If another option is already using the same `type`.
* @alpha Likely to change
*/
addFileUploadOption(option: ComposerApiFileUploadOption): void;
/**
* Open the file upload confirmation dialog. This may be used in conjunction
* with `addFileUploadOption` to support an alternative file upload kind.
* @param files - The files to prompt for
* @param view - The target view to send the file into. Defaults to `{ view: "room" }`
* @returns Returns immediately, does not await action.
* @alpha Likely to change
*/
insertPlaintextIntoComposer(plaintext: string): void;
openFileUploadConfirmation(files: File[], view: ComposerApiTarget): void;
/**
* Insert plaintext into the current composer.
* @param plaintext - The plain text to insert
* @param view - The target view to insert text into. Defaults to `{ view: "room" }`
* @returns Returns immediately, does not await action.
* @alpha Likely to change
*/
insertPlaintextIntoComposer(plaintext: string, view: ComposerApiTarget): void;
}