@atlaskit/editor-plugin-media
Version:
Media plugin for @atlaskit/editor-core
142 lines (141 loc) • 7.39 kB
TypeScript
import type { IntlShape } from 'react-intl';
import type { RichMediaLayout as MediaSingleLayout } from '@atlaskit/adf-schema';
import type { InsertMediaVia } from '@atlaskit/editor-common/analytics';
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
import type { PortalProviderAPI } from '@atlaskit/editor-common/portal';
import type { ContextIdentifierProvider, MediaProvider } from '@atlaskit/editor-common/provider-factory';
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
import { type Identifier } from '@atlaskit/media-client';
import type { MediaClientConfig } from '@atlaskit/media-core';
import type { MediaNextEditorPluginType } from '../mediaPluginType';
import type { getPosHandlerNode as ProsemirrorGetPosHandler, MediaOptions, MediaState, MediaStateEventSubscriber } from '../types';
import type { MediaPluginOptions } from '../types/media-plugin-options';
import PickerFacade from './picker-facade';
import type { MediaNodeWithPosHandler, MediaPluginState } from './types';
export declare const MEDIA_CONTENT_WRAP_CLASS_NAME = "media-content-wrap";
export declare const MEDIA_PLUGIN_IS_RESIZING_KEY = "mediaSinglePlugin.isResizing";
export declare const MEDIA_PLUGIN_RESIZING_WIDTH_KEY = "mediaSinglePlugin.resizing-width";
export declare class MediaPluginStateImplementation implements MediaPluginState {
allowsUploads: boolean;
mediaClientConfig?: MediaClientConfig;
uploadMediaClientConfig?: MediaClientConfig;
ignoreLinks: boolean;
waitForMediaUpload: boolean;
allUploadsFinished: boolean;
showDropzone: boolean;
isFullscreen: boolean;
element?: HTMLElement;
layout: MediaSingleLayout;
mediaNodes: MediaNodeWithPosHandler[];
options: MediaPluginOptions;
mediaProvider?: MediaProvider;
isResizing: boolean;
resizingWidth: number;
currentMaxWidth?: number;
allowInlineImages: boolean;
uploadInProgressSubscriptions: {
(isUploading: boolean): void;
}[];
uploadInProgressSubscriptionsNotified: boolean;
lastAddedMediaSingleFileIds: {
id: string;
selectionPosition: number;
}[];
private view;
private destroyed;
private errorReporter;
private customPicker?;
private removeOnCloseListener;
private openMediaPickerBrowser?;
private onPopupToggleCallback;
private identifierCount;
private outOfEditorScopeIdentifierMap;
private taskManager;
pickers: PickerFacade[];
pickerPromises: Array<Promise<PickerFacade>>;
editingMediaSinglePos?: number;
showEditingDialog?: boolean;
mediaOptions?: MediaOptions;
dispatch?: Dispatch;
pluginInjectionApi: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined;
singletonCreatedAt: number;
constructor(state: EditorState, options: MediaPluginOptions, mediaOptions: MediaOptions | undefined, dispatch: Dispatch | undefined, pluginInjectionApi: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined);
clone(): MediaPluginStateImplementation;
subscribeToUploadInProgressState(fn: (isUploading: boolean) => void): void;
unsubscribeFromUploadInProgressState(fn: (isUploading: boolean) => void): void;
private previousMediaProvider;
setMediaProvider(mediaProvider?: Promise<MediaProvider> | MediaProvider): Promise<void>;
getMediaOptions: () => MediaPluginOptions;
setIsResizing(isResizing: boolean): void;
setResizingWidth(width: number): void;
updateElement(): void;
private isMediaSchemaNode;
private getDomElement;
get contextIdentifierProvider(): ContextIdentifierProvider | undefined;
onNodeInserted: (id: string, selectionPosition: number) => void;
/**
* we insert a new file by inserting a initial state for that file.
*
* called when we insert a new file via the picker (connected via pickerfacade)
*/
insertFile: (mediaState: MediaState, onMediaStateChanged: MediaStateEventSubscriber, pickerType?: string, insertMediaVia?: InsertMediaVia) => void;
private selectLastAddedMediaNode;
addPendingTask: (task: Promise<any>) => void;
splitMediaGroup: () => boolean;
onPopupPickerClose: () => void;
showMediaPicker: () => void;
setBrowseFn: (browseFn: () => void) => void;
onPopupToggle: (onPopupToggleCallback: (isOpen: boolean) => void) => void;
/**
* Returns a promise that is resolved after all pending operations have been finished.
* An optional timeout will cause the promise to reject if the operation takes too long
*
* NOTE: The promise will resolve even if some of the media have failed to process.
*/
waitForPendingTasks: (timeout?: number, lastTask?: Promise<MediaState | null>) => Promise<MediaState | null>;
setView(view: EditorView): void;
/**
* Called from React UI Component when user clicks on "Delete" icon
* inside of it
*/
handleMediaNodeRemoval: (node: PMNode | undefined, getPos: ProsemirrorGetPosHandler) => void;
private getIdentifierKey;
trackMediaNodeAddition: (node: PMNode) => void;
trackMediaNodeRemoval: (node: PMNode) => void;
isIdentifierInEditorScope: (identifier: Identifier) => boolean;
/**
* This is used in on Paste of media, this tracks which if the pasted media originated from a outside the editor
* i.e. the pasted media was not uplaoded to the current editor.
* This is to enable mediaShallowCopySope to enable only shallow copying media referenced within the edtior
*/
trackOutOfScopeIdentifier: (identifier: Identifier) => void;
/**
* Called from React UI Component on componentDidMount
*/
handleMediaNodeMount: (node: PMNode, getPos: ProsemirrorGetPosHandler) => void;
/**
* Called from React UI Component on componentWillUnmount and UNSAFE_componentWillReceiveProps
* when React component's underlying node property is replaced with a new node
*/
handleMediaNodeUnmount: (oldNode: PMNode) => void;
handleMediaGroupUpdate: (oldNodes: PMNode[], newNodes: PMNode[]) => void;
destroy(): void;
findMediaNode: (id: string) => MediaNodeWithPosHandler | null;
private destroyAllPickers;
private destroyPickers;
private initPickers;
private getInputMethod;
updateMediaSingleNodeAttrs: (id: string, attrs: object) => boolean | undefined;
private collectionFromProvider;
private handleMediaState;
removeSelectedMediaContainer: () => boolean;
selectedMediaContainerNode: () => PMNode | undefined;
handleDrag: (dragState: "enter" | "leave") => void;
updateAndDispatch(props: Partial<Pick<this, 'allowsUploads' | 'allUploadsFinished' | 'isFullscreen'>>): void;
}
export declare const getMediaPluginState: (state: EditorState) => MediaPluginState;
export declare const createPlugin: (_schema: Schema, options: MediaPluginOptions, getIntl: () => IntlShape, pluginInjectionApi: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined, nodeViewPortalProviderAPI: PortalProviderAPI, dispatch?: Dispatch, mediaOptions?: MediaOptions) => SafePlugin<MediaPluginState>;