UNPKG

@atlaskit/editor-plugin-card

Version:

Card plugin for @atlaskit/editor-core

87 lines (86 loc) 4.4 kB
import React from 'react'; import type { ComponentProps } from 'react'; import type { RichMediaLayout } from '@atlaskit/adf-schema'; import ReactNodeView from '@atlaskit/editor-common/react-node-view'; import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types'; import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model'; import type { EditorView } from '@atlaskit/editor-prosemirror/view'; import type { cardPlugin } from '../index'; import type { SmartCardProps } from './genericCard'; export type EmbedCardState = { hasPreview: boolean; initialAspectRatio?: number; liveHeight?: number; }; export declare class EmbedCardComponent extends React.PureComponent<SmartCardProps & { id?: string; }, EmbedCardState> { private scrollContainer?; private embedIframeRef; constructor(props: SmartCardProps & { id?: string; }); state: EmbedCardState; private getPosSafely; onResolve: (data: { aspectRatio?: number; title?: string; url?: string; }) => void; updateSize: (pctWidth: number | null, layout: RichMediaLayout) => true | undefined; /** * Defers line-length measurement until the embed card DOM has fully rendered. * * When put embed in the expand, reload the page and open that expand, the embed was collapsed. * Because the `.rich-media-item` can temporarily report `offsetWidth = 1`, as proportional width styles have not been applied yet. * Measuring at that moment would cache the bogus width and break resize calculations. * Scheduling a measurement on the next animation frame ensures layout has * settled. We then force the node view to re-render so `getLineLength` * re-runs and captures the correct width. */ private scheduleLineLengthRemeasureRaf; private getLineLength; /** * Even though render is capable of listening and reacting to iframely wrapper iframe sent `resize` events * it's good idea to store latest actual height in ADF, so that when renderer (well, editor as well) is loading * we will show embed window of appropriate size and avoid unnecessary content jumping. */ saveOriginalDimensionsAttributes: (height: number, width: number | undefined) => void; onHeightUpdate: (height: number) => void; onError: ({ err }: { err?: Error; }) => void; componentWillUnmount(): void; private removeCardDispatched; private removeCard; render(): React.JSX.Element; } export declare const EmbedOrBlockCardComponent: (props: ComponentProps<typeof EmbedCardComponent>) => React.JSX.Element; export type EmbedCardNodeViewProps = Pick<SmartCardProps, 'eventDispatcher' | 'allowResizing' | 'fullWidthMode' | 'dispatchAnalyticsEvent' | 'pluginInjectionApi' | 'actionOptions' | 'onClickCallback' | 'isPageSSRed' | 'provider' | 'CompetitorPrompt'>; export declare class EmbedCard extends ReactNodeView<EmbedCardNodeViewProps> { private id; unsubscribe: (() => void) | undefined; viewShouldUpdate(nextNode: PMNode): boolean; createDomRef(): HTMLElement; private updateContentEditable; render(): React.JSX.Element; /** * Prevent ProseMirror from handling drag events on the smart-element-link, * allowing native drag to work so SmartLinkDraggable can intercept it. * @see {@link https://prosemirror.net/docs/ref/#view.NodeView.stopEvent} */ stopEvent(event: Event): boolean; destroy(): void; } export interface EmbedCardNodeViewProperties { actionOptions: EmbedCardNodeViewProps['actionOptions']; allowResizing: EmbedCardNodeViewProps['allowResizing']; CompetitorPrompt?: EmbedCardNodeViewProps['CompetitorPrompt']; fullWidthMode: EmbedCardNodeViewProps['fullWidthMode']; isPageSSRed: EmbedCardNodeViewProps['isPageSSRed']; onClickCallback: EmbedCardNodeViewProps['onClickCallback']; pluginInjectionApi: ExtractInjectionAPI<typeof cardPlugin> | undefined; pmPluginFactoryParams: PMPluginFactoryParams; provider: EmbedCardNodeViewProps['provider']; } export declare const embedCardNodeView: ({ allowResizing, fullWidthMode, pmPluginFactoryParams, pluginInjectionApi, actionOptions, onClickCallback, CompetitorPrompt, isPageSSRed, provider, }: EmbedCardNodeViewProperties) => (node: PMNode, view: EditorView, getPos: () => number | undefined) => EmbedCard;