@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
57 lines (56 loc) • 3.25 kB
TypeScript
import React from 'react';
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
import type { Decoration, DecorationSource, EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
import type { EventDispatcher } from '../event-dispatcher';
import type { PortalProviderAPI } from '../ui/PortalProvider';
import type { ForwardRef, getPosHandler, ProsemirrorGetPosHandler, ReactComponentProps, shouldUpdate } from './types';
export type { getPosHandler, ReactComponentProps, shouldUpdate, ProsemirrorGetPosHandler, ForwardRef, };
export type { InlineNodeViewComponentProps } from './getInlineNodeViewProducer';
export { getInlineNodeViewProducer, inlineNodeViewClassname, } from './getInlineNodeViewProducer';
export default class ReactNodeView<P = ReactComponentProps> implements NodeView {
private domRef?;
private contentDOMWrapper?;
private reactComponent?;
private portalProviderAPI;
private hasAnalyticsContext;
private _viewShouldUpdate?;
protected eventDispatcher?: EventDispatcher;
private hasIntlContext;
protected decorations: ReadonlyArray<Decoration>;
reactComponentProps: P;
view: EditorView;
getPos: getPosHandler;
contentDOM: HTMLElement | null | undefined;
node: PMNode;
constructor(node: PMNode, view: EditorView, getPos: getPosHandler, portalProviderAPI: PortalProviderAPI, eventDispatcher: EventDispatcher, reactComponentProps?: P, reactComponent?: React.ComponentType<React.PropsWithChildren<any>>, hasAnalyticsContext?: boolean, viewShouldUpdate?: shouldUpdate, hasIntlContext?: boolean);
/**
* This method exists to move initialization logic out of the constructor,
* so object can be initialized properly before calling render first time.
*
* Example:
* Instance properties get added to an object only after super call in
* constructor, which leads to some methods being undefined during the
* first render.
*/
init(): this;
private renderReactComponent;
createDomRef(): HTMLElement;
getContentDOM(): {
dom: HTMLElement;
contentDOM?: HTMLElement | null | undefined;
} | undefined;
handleRef: (node: HTMLElement | null) => void;
private _handleRef;
render(props: P, forwardRef?: ForwardRef): React.ReactElement<any> | null;
update(node: PMNode, decorations: ReadonlyArray<Decoration>, _innerDecorations?: DecorationSource, validUpdate?: (currentNode: PMNode, newNode: PMNode) => boolean): boolean;
viewShouldUpdate(nextNode: PMNode, decorations?: Array<Decoration>): boolean;
/**
* Copies the attributes from a ProseMirror Node to a DOM node.
* @param node The Prosemirror Node from which to source the attributes
*/
setDomAttrs(node: PMNode, element: HTMLElement): void;
get dom(): HTMLElement;
destroy(): void;
private dispatchAnalyticsEvent;
static fromComponent(component: React.ComponentType<React.PropsWithChildren<any>>, portalProviderAPI: PortalProviderAPI, eventDispatcher: EventDispatcher, props?: ReactComponentProps, viewShouldUpdate?: (nextNode: PMNode) => boolean, hasIntlContext?: boolean): (node: PMNode, view: EditorView, getPos: getPosHandler) => ReactNodeView<ReactComponentProps>;
}