medium-proeditor
Version:
A powerful & customizable Medium-style rich text editor
66 lines • 3.19 kB
TypeScript
import { type EditorState, type Transaction } from 'prosemirror-state';
import type { Node as ProseMirrorNode } from 'prosemirror-model';
export type MediaLayout = 'inset-center' | 'outset-center' | 'fill-width' | 'grid';
/**
* Gets the appropriate width for a given layout, considering media width.
*
* @param {string} [layout] - The layout type.
* @param {number} [mediaWidth] - The original width of the media.
* @returns {number | null} - The calculated layout width, or `null` if it should take full width.
*/
export declare function getLayoutWidth(layout?: string, mediaWidth?: number): number | null;
/**
* Calculates the layout width, height, and aspect ratio fill percentage.
*
* @param {Object} params - The function parameters.
* @param {string} [params.layout] - The layout type.
* @param {number} [params.mediaWidth] - The original width of the media.
* @param {number} [params.mediaHeight] - The original height of the media.
* @returns {Object} - An object containing:
* - `layoutWidth` (number | null): The calculated width.
* - `layoutHeight` (number | undefined): The calculated height if applicable.
* - `aspectRatioFill` (number | undefined): The aspect ratio percentage for placeholders.
*/
export declare function getAspectRatioLayout({ layout, mediaWidth, mediaHeight, }: {
layout?: string;
mediaWidth?: number;
mediaHeight?: number;
}): {
layoutWidth?: number | null;
layoutHeight?: number;
aspectRatioFill?: number;
};
export declare function newLineAfterFigure(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
export declare function resetFigureNode(figure: ProseMirrorNode): ProseMirrorNode;
/**
* Calculates the total aspect ratio from an iterable or an object with a `forEach` method.
* @param items - An iterable collection or an object with a `forEach` method.
* @param getDimensions - A function to extract width and height from each item.
* @returns The total aspect ratio.
*/
export declare function calculateTotalAspectRatio<T>(items: Iterable<T> | {
forEach(callback: (item: T) => void): void;
}, getDimensions: (item: T) => {
width: number;
height: number;
}): number;
/**
* Distributes width evenly based on aspect ratios.
* @returns The calculated width for the item.
*/
export declare function getDistributedWidth(width: number, height: number, totalAspectRatio: number, itemsInRow: number): number;
/**
* Checks if the selected media node has the specified media layout.
*/
export declare function isMediaLayoutActive(state: EditorState, layout: MediaLayout): boolean;
/**
* Sets the specified media layout on the currently selected image node.
*/
export declare const applyMediaLayout: (layout: MediaLayout) => (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
/**
* Determines whether the given media layout can be applied to the currently selected image.
*/
export declare function canApplyMediaLayout(state: EditorState, layout: MediaLayout): boolean;
export declare function isImageHaveAlt(state: EditorState): boolean;
export declare function isImageSelection(state: EditorState): boolean;
//# sourceMappingURL=helpers.d.ts.map