medium-proeditor
Version:
A powerful & customizable Medium-style rich text editor
87 lines • 2.88 kB
TypeScript
import type { Command } from 'prosemirror-state';
import { Feature } from '../../Feature';
import { type MediaLayout } from './helpers';
import type { EmbedMedia } from '../../types';
declare module '../../types' {
interface Commands {
setEmbedPlaceholder: (options: {
message: string;
className?: string;
}) => Command;
}
}
export interface MediaOptions {
/**
* Uploads an image file and returns its URL.
* @param file - The image file to upload.
* @returns A promise with the image URL and optional ID.
*
* @example
* uploadImage: async ({ file }) => {
* return { url: `https://cdn.example.com/${file.name}` };
* }
*/
uploadImage?: ({ file }: {
file: File;
}) => Promise<{
url: string;
imageId?: string;
} | undefined | null>;
/**
* handle embedded content requests
*
* @param url - The URL of the media to embed.
* @returns An object containing the media metadata.
*
* @example
* fetchMediaEmbedData: ({ url }) => {
* return { mediaId: 'abc123', iframeSrc: url, title: 'Video title' };
* }
*/
fetchMediaEmbedData?: ({ url }: {
url: string;
}) => Promise<EmbedMedia | undefined | null>;
/**
* Generates an optimized image URL.
*
* @param {Object} params - Image optimization parameters.
* @param {string} params.src - Original image URL.
* @param {number} [params.originalWidth] - Original image width.
* @param {MediaLayout} [params.layout] - Layout type (e.g., "inset-center", "grid").
* @param {number} [params.width] - Desired width.
* @param {string} [params.format] - Image format (e.g., "webp").
* @returns {string | undefined | null} Optimized image URL or null if invalid.
*/
getOptimizedImageUrl?: (params: {
src: string;
originalWidth?: number;
layout?: MediaLayout;
width?: number;
format?: string;
}) => string | undefined | null;
/**
* Maximum allowed image file size in bytes.
* Triggers `onMaxFileSizeError` if exceeded.
* @default 26214400 // 25mb
*/
maxImageSizeBytes?: number;
/**
* Called when a file exceeds the maximum size limit.
* @param file - The oversized file.
*/
onMaxFileSizeError?: (file: File) => void;
/**
* Vertical margin to trigger scrolling to media
* @default 0
*/
mediaFocusOffset?: number;
/**
* Scroll behavior when the selected media is off-screen.
* @default "smooth"
*/
mediaFocusScrollBehavior?: ScrollBehavior;
}
type MediaStorage = Pick<MediaOptions, 'mediaFocusOffset' | 'mediaFocusScrollBehavior' | 'uploadImage'>;
export declare const Media: Feature<MediaOptions, MediaStorage>;
export {};
//# sourceMappingURL=index.d.ts.map