import { Plugin, EditorState, Transaction } from "prosemirror-state"; import { Schema } from "prosemirror-model"; import { DecorationSet, EditorView } from "prosemirror-view"; import { CommonmarkParserFeatures } from "../view"; import { ManagedInterfaceKey, PluginInterfaceView } from "./interface-manager"; /** * Async image upload callback that is passed the uploaded file and returns a resolvable path to the image * @param {File} file The uploaded image file or user entered image url * @returns {string} The resolvable path to where the file was uploaded */ type ImageUploadHandlerCallback = (file: File | string) => Promise; /** * Image upload options */ export interface ImageUploadOptions { /** * A function handling file uploads. Will receive the file to upload * as the `file` parameter and needs to return a resolved promise with the URL of the uploaded file */ handler?: ImageUploadHandlerCallback; /** * The html to insert into the image uploader to designate the image storage provider * NOTE: this is injected as-is and can potentially be a XSS hazard! */ brandingHtml?: string; /** * The html to insert into the image uploader to alert users of the uploaded image content policy * NOTE: this is injected as-is and can potentially be a XSS hazard! */ contentPolicyHtml?: string; /** * If provided, will insert the html into a warning notice at the top of the image uploader * NOTE: this is injected as-is and can potentially be a XSS hazard! */ warningNoticeHtml?: string; /** * If true, wraps all images in links that point to the uploaded image url */ wrapImagesInLinks?: boolean; /** * If true, all uploaded images will embedded as links to the image, rather than the image itself * NOTE: this is only supported for images that are uploaded via the image uploader */ embedImagesAsLinks?: boolean; /** * If true, allow users to add images via an external url */ allowExternalUrls?: boolean; /** * An array of strings containing the accepted file types for the image uploader. * See https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types for appropriate image * file types. */ acceptedFileTypes?: string[]; /** * The maximum file size in MiB that the image uploader will accept */ sizeLimitMib?: number; } /** * Default image upload callback that posts to `/image/upload`, * expecting a json response like `{ UploadedImage: "https://www.example.com/path/to/file" }` * and returns `UploadedImage`'s value * @param file The file to upload */ export declare function defaultImageUploadHandler(file: File): Promise; declare enum ValidationResult { Ok = 0, FileTooLarge = 1, InvalidFileType = 2 } /** * Callback function to generate a transaction for the ImageUploader * to dispatch when an image has been uploaded * @param state The current state of the plugin * @param url The url to where the image was uploaded * @param position The position in the document where any added entities should be inserted */ type addTransactionDispatcher = (state: EditorState, url: string, position: number) => Transaction; export declare class ImageUploader extends PluginInterfaceView { uploadOptions?: ImageUploadOptions; uploadContainer: HTMLElement; uploadField: HTMLInputElement; image: File; isVisible: boolean; private validateLink; private addTransactionDispatcher; constructor(view: EditorView, uploadOptions: ImageUploadOptions, validateLink: CommonmarkParserFeatures["validateLink"], addTransactionDispatcher: addTransactionDispatcher); highlightDropArea(event: DragEvent): void; unhighlightDropArea(event: DragEvent): void; getCaptionElement(text: string, maxFileSizeMib: number): HTMLElement; handleFileSelection(view: EditorView): void; handleDrop(event: DragEvent, view: EditorView): void; handlePaste(event: ClipboardEvent, view: EditorView): void; validateImage(image: File): ValidationResult; showValidationError(errorMessage: string, level?: string): void; hideValidationError(): void; showImagePreview(file: File): Promise; private showImagePreviewAsync; toggleExternalUrlInput(show: boolean): void; validateExternalUrl(url: string): void; resetImagePreview(): void; resetUploader(): void; addImagePlaceholder(view: EditorView, id: unknown): void; removeImagePlaceholder(view: EditorView, id: unknown, transaction?: Transaction): void; handleUploadTrigger(event: Event, file: File, view: EditorView): Promise; startImageUpload(view: EditorView, file: File | string): Promise; update(view: EditorView): void; destroy(): void; buildInterface(container: Element): void; destroyInterface(container: Element): void; } /** * Hides the image uploader * @param view The current editor view */ export declare function hideImageUploader(view: EditorView): void; /** Shows the image uploader * @param view The current editor view * @param file The file to upload */ export declare function showImageUploader(view: EditorView, file?: File): void; /** * Checks if the image-upload functionality is enabled * @param state The current editor state */ export declare function imageUploaderEnabled(state: EditorState): boolean; /** The state of the image uploader plugin */ type ImageUploadState = { add?: { id: unknown; pos: number; }; decorations?: DecorationSet; file: File | null; remove?: { id: unknown; }; shouldShow: boolean; }; /** Singleton instance of the plugin key for exported show/hide methods to reference */ declare const INTERFACE_KEY: ManagedInterfaceKey; /** * Adds image uploading capabilities to the editor. * With this plugin, you'll be able to show a popover that allows you to * browse for files on your file system, or use drag & drop to select images * to upload. * * On upload, this plugin will call the provided uploadOptions.handler function * @see defaultImageUploadHandler for an example * * @param uploadOptions The imageUpload options * @param containerFn A function that returns the container to insert the plugin's UI into */ export declare function richTextImageUpload(uploadOptions: ImageUploadOptions, validateLink: CommonmarkParserFeatures["validateLink"], schema: Schema): Plugin; /** * Adds image uploading capabilities to the editor. * With this plugin, you'll be able to show a popover that allows you to * browse for files on your file system, or use drag & drop to select images * to upload. * * On upload, this plugin will call the provided uploadOptions.handler function * @see defaultImageUploadHandler for an example * * @param uploadHandler The imageUpload options * @param containerFn A function that returns the container to insert the plugin's UI into */ export declare function commonmarkImageUpload(uploadOptions: ImageUploadOptions, validateLink: CommonmarkParserFeatures["validateLink"]): Plugin; export {};