@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
103 lines (102 loc) • 4.81 kB
TypeScript
import type { RichMediaLayout } from '@atlaskit/adf-schema';
import type { Node as PMNode, ResolvedPos } from '@atlaskit/editor-prosemirror/model';
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
/**
* Convert media node width to pixel
*
* for legacy experience, image is aligned inside resize handle bar with a gap. So gutterOffset is used to for this use case.
* for new experience, image is aligned with resize handle bar, so gutterOffset is 0
*
* @param width - media single node width
* @param editorWidth - width of editor
* @param widthType - width type is defined in the adf document for mediaSingle node, and it is associated with the `width`
* @param gutterOffset - resize handle bar offset, determines whether align with resize handle bar
* @returns pixel number for media single node
*/
export declare function getMediaSinglePixelWidth(width: number, editorWidth: number, widthType?: string, gutterOffset?: number): number;
export interface calcMediaSinglePixelWidthProps {
width?: number;
widthType?: 'percentage' | 'pixel';
origWidth: number;
layout: RichMediaLayout;
contentWidth?: number;
containerWidth: number;
gutterOffset: number;
}
/**
* Convert width attribute to pixel value for legacy (resized or not resisized) and new media single node for new experience
* @param width node width attribute
* @param widthType node widthType attribute
* @param origWidth original media width
* @param layout node layout attribute
* @param contentWidth editor content width
* @param containerWidth editor container width
* @param gutterOffset gap between resizer handle and media
* @returns pixel width of the node
*/
export declare const calcMediaSinglePixelWidth: ({ width, widthType, origWidth, layout, contentWidth, containerWidth, gutterOffset, }: calcMediaSinglePixelWidthProps) => number;
/**
* Calculate maximum width allowed for media single node in fix-width editor in new experience
* @param containerWidth width of editor container
*/
export declare const calcMediaSingleMaxWidth: (containerWidth: number) => number;
/**
* Calculate initial media single pixel width.
* Make it fall between max width and min width
* @param origWidth original width of image (media node width)
* @param maxWidth default to akEditorDefaultLayoutWidth (760)
* @param minWidth default to MEDIA_SINGLE_DEFAULT_MIN_PIXEL_WIDTH (24)
*/
export declare const getMediaSingleInitialWidth: (origWidth?: number, maxWidth?: number, minWidth?: number) => number;
export declare function calculateOffsetLeft(insideInlineLike: boolean, insideLayout: boolean, pmViewDom: Element, wrapper?: HTMLElement): number;
/**
* Returns the number rounded to the nearest interval.
* @param {number} value The number to round
* @param {number} interval The numeric interval to round to, default to 0.5
* @return {number} the rounded number
*/
export declare const roundToNearest: (value: number, interval?: number) => number;
/**
* Retuns minimum value for media single node
* @param isVideoFile is child media of video type
* @param contentWidth parent content width
*/
export declare const calcMinWidth: (isVideoFile: boolean, contentWidth: number) => number;
/**
* Get parent width for a nested media single node
* @param view Editor view
* @param pos node position
*/
export declare const getMaxWidthForNestedNode: (view: EditorView, pos: number | undefined) => number | null;
/**
* Get parent width for a nested media single node for new experience
* We don't check for mediaSingle selection in this function.
* @param view Editor view
* @param pos node position
* @param forInsertion for insertion
*/
export declare const getMaxWidthForNestedNodeNext: (view: EditorView, pos: number | undefined, forInsertion?: boolean) => number | null;
/**
* Get parent content width for nested media single node.
* @param resolvedPos resolved Position of the node
* @param view editor view
* @returns parent content width for nested node
*/
export declare const getParentWidthForNestedMediaSingleNode: (resolvedPos: ResolvedPos, view: EditorView) => number | null;
/**
* Get parent width for nested media single nodes
* @param resolvedPos resolved Position of the node
* @param view editor view
* @returns parent width used for media single initial width on insertion
*/
export declare const getParentWidthForNestedMediaSingleNodeForInsertion: (resolvedPos: ResolvedPos, view: EditorView) => number | null;
/**
*
* @param editorState current editor state
* @returns selected media node (child of mediaSingle only) with position
*/
export declare const currentMediaNodeWithPos: (editorState: EditorState) => {
node: PMNode;
pos: number;
} | undefined;