diff --git a/README.md b/README.md index a9b8b36a..005ec30d 100644 --- a/README.md +++ b/README.md @@ -869,11 +869,9 @@ So the idea is that we have a `uiCommands` object and at a point, there will be - save: this function saves the given text, locale and caption type - addLocale: this function sends a locale to be added to the available options - - presentation: - - upload: uploads a new presentation to BigBlueButton; - - - presentation: - - upload: uploads a new presentation to BigBlueButton; +- presentation: + - upload: uploads a new presentation to BigBlueButton; + - insertPages: inserts pages into the current presentation at a given 1-based position (out-of-range values are clamped by the server: 1 prepends, totalPages + 1 appends). The content is the file to convert into pages; omitting it (or passing null) inserts a single blank page; **Example usage:** @@ -933,6 +931,15 @@ So the idea is that we have a `uiCommands` object and at a point, there will be }); }, }), + new ActionButtonDropdownOption({ + label: 'Insert pages', + icon: 'copy', + onClick: () => { + // Insert the pages of a PDF file at position 2 of the current presentation + // (pdfFile is a File object, e.g. taken from an input of type file) + pluginApi.serverCommands.presentation.insertPages(2, { file: pdfFile }); + }, + }), ]); }, []); diff --git a/src/server-commands/index.ts b/src/server-commands/index.ts index 9c50b54b..15c8efd7 100644 --- a/src/server-commands/index.ts +++ b/src/server-commands/index.ts @@ -1,9 +1,12 @@ export { CaptionCommandsEnum, CaptionsTypeEnum } from './caption/enum'; export { ChatCommandsEnum } from './chat/enum'; +export { PresentationCommandsEnum } from './presentation/enum'; export { UploadPresentationBase64Content, UploadPresentationBlobContent, UploadPresentationFileContent, UploadPresentationDataUrlContent, UploadPresentationContent, + UploadPresentationCommandArguments, + InsertPagesCommandArguments, } from './presentation/types'; diff --git a/src/server-commands/presentation/commands.ts b/src/server-commands/presentation/commands.ts index 41039252..a95cc3e9 100644 --- a/src/server-commands/presentation/commands.ts +++ b/src/server-commands/presentation/commands.ts @@ -1,5 +1,9 @@ import { PresentationCommandsEnum } from './enum'; -import { UploadPresentationCommandArguments } from './types'; +import { + InsertPagesCommandArguments, + UploadPresentationCommandArguments, + UploadPresentationContent, +} from './types'; export const presentation = { /** @@ -17,4 +21,35 @@ export const presentation = { }), ); }, + + /** + * Inserts pages into the current presentation at a given position (if presenter, + * ignores otherwise). + * + * @param position 1-based position where the pages are inserted. Out-of-range + * values are clamped by the server (1 prepends, totalPages + 1 appends). + * @param content The file to convert into pages. Pass `null` (or omit) to insert a + * single blank page. + * @param mimeType Optional mime type of the content (e.g. `application/pdf`). + * @param filename Optional original filename. + */ + insertPages: ( + position: number, + content?: UploadPresentationContent | null, + mimeType?: string, + filename?: string, + ) => { + window.dispatchEvent( + new CustomEvent< + InsertPagesCommandArguments + >(PresentationCommandsEnum.INSERT_PAGES, { + detail: { + position, + content: content ?? null, + mimeType, + filename, + }, + }), + ); + }, }; diff --git a/src/server-commands/presentation/enum.ts b/src/server-commands/presentation/enum.ts index 39ddae1d..acf42b71 100644 --- a/src/server-commands/presentation/enum.ts +++ b/src/server-commands/presentation/enum.ts @@ -1,3 +1,4 @@ export enum PresentationCommandsEnum { UPLOAD = 'PRESENTATION_UPLOAD_COMMAND', + INSERT_PAGES = 'PRESENTATION_INSERT_PAGES_COMMAND', } diff --git a/src/server-commands/presentation/types.ts b/src/server-commands/presentation/types.ts index 4b03582b..c9a320fe 100644 --- a/src/server-commands/presentation/types.ts +++ b/src/server-commands/presentation/types.ts @@ -26,6 +26,22 @@ export interface UploadPresentationCommandArguments { filename?: string; } +export interface InsertPagesCommandArguments { + // 1-based position where the new pages are inserted. Out-of-range values are + // clamped by the server (1 -> prepend, totalPages + 1 -> append). + position: number; + // The file to convert into pages. `null` inserts a single blank page. + content: UploadPresentationContent | null; + mimeType?: string; + filename?: string; +} + export interface ServerCommandsPresentationObject { upload: (uploadPresentationCommandArguments: UploadPresentationCommandArguments) => void; + insertPages: ( + position: number, + content?: UploadPresentationContent | null, + mimeType?: string, + filename?: string, + ) => void; }