@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
71 lines (70 loc) • 2.97 kB
TypeScript
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
import type { FireAnalyticsCallback } from '../analytics';
import type { EditorAppearance } from '../types';
import type { BasePluginDependenciesAPI, CorePlugin, NextEditorPlugin, PluginDependenciesAPI } from '../types/next-editor-plugin';
type NextEditorPluginInitializedType = ReturnType<NextEditorPlugin<any>>;
type SharedStateAPIProps = {
getEditorState: () => EditorState | undefined;
};
interface PluginInjectionAPIProps extends SharedStateAPIProps {
appearance?: EditorAppearance;
fireAnalyticsEvent?: FireAnalyticsCallback;
getEditorView: () => EditorView | undefined;
}
export type EditorStateDiff = {
readonly newEditorState: EditorState;
readonly oldEditorState: EditorState | undefined;
};
export declare class PluginsData {
}
export declare class SharedStateAPI {
private getEditorState;
private listeners;
constructor({ getEditorState }: SharedStateAPIProps);
createAPI(plugin: NextEditorPluginInitializedType | undefined): PluginDependenciesAPI<NextEditorPlugin<any, any>>['sharedState'];
private cleanupSubscription;
removePluginListeners(pluginName: string): void;
private updatesToNotifyQueue;
notifyListeners({ newEditorState, oldEditorState, plugins, }: EditorStateDiff & Record<'plugins', Map<string, NextEditorPluginInitializedType>>): void;
destroy(): void;
}
type EditorStateDelta = {
readonly newEditorState: EditorState;
readonly oldEditorState: EditorState;
};
interface PluginInjectionAPIDefinition {
api: () => {
[key: string]: BasePluginDependenciesAPI<any>;
};
onEditorPluginInitialized: (plugin: NextEditorPluginInitializedType) => void;
onEditorViewUpdated: (props: EditorStateDelta) => void;
}
type GenericAPIWithCore = {
[key: string]: BasePluginDependenciesAPI<any>;
core: PluginDependenciesAPI<CorePlugin>;
};
export declare class EditorPluginInjectionAPI implements PluginInjectionAPIDefinition {
private sharedStateAPI;
private actionsAPI;
private commandsAPI;
private plugins;
constructor({ getEditorState, getEditorView, fireAnalyticsEvent, appearance, }: PluginInjectionAPIProps);
/**
* Returns PM plugins from internally-registered plugins (e.g. the core plugin)
* that are not processed through the normal preset builder flow.
*/
getInternalPMPlugins(): Array<{
name: string;
plugin: (...args: any[]) => any;
}>;
private createAPI;
api(): GenericAPIWithCore;
onEditorViewUpdated: ({ newEditorState, oldEditorState }: EditorStateDiff) => void;
onEditorPluginInitialized: (plugin: NextEditorPluginInitializedType) => void;
retainPlugins: (keptPluginNames: ReadonlySet<string>) => string[];
getRegisteredPluginNames: () => string[];
private addPlugin;
private getPluginByName;
}
export {};