@atlaskit/editor-plugin-local-id
Version:
LocalId plugin for @atlaskit/editor-core
42 lines (41 loc) • 2.4 kB
TypeScript
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
import type { CollabEditPlugin } from '@atlaskit/editor-plugin-collab-edit';
import type { CompositionPlugin } from '@atlaskit/editor-plugin-composition';
import type { LimitedModePlugin } from '@atlaskit/editor-plugin-limited-mode';
import type { Node } from '@atlaskit/editor-prosemirror/model';
import type { NodeWithPos } from '@atlaskit/editor-prosemirror/utils';
export type ActionProps = {
localId: string;
};
export type LocalIdStatusCode = 'current' | 'localChangeByAttr' | 'localChangeBySetAttrs' | 'localChangeByBatchAttrs' | 'localChangeByReplace' | 'localChangeByDelete' | 'localChangeByReplaceAround' | 'localChangeByUnknown' | 'remoteChangeByAttr' | 'remoteChangeBySetAttrs' | 'remoteChangeByBatchAttrs' | 'remoteChangeByReplace' | 'remoteChangeByDelete' | 'remoteChangeByReplaceAround' | 'remoteChangeByUnknown' | 'AIChangeByAttr' | 'AIChangeBySetAttrs' | 'AIChangeByBatchAttrs' | 'AIChangeByReplace' | 'AIChangeByDelete' | 'AIChangeByReplaceAround' | 'AIChangeByUnknown' | 'docChangeByAttr' | 'docChangeBySetAttrs' | 'docChangeByBatchAttrs' | 'docChangeByReplace' | 'docChangeByDelete' | 'docChangeByReplaceAround' | 'docChangeByUnknown';
export interface LocalIdSharedState {
localIdStatus: Map<string, LocalIdStatusCode> | undefined;
localIdWatchmenEnabled: boolean | undefined;
}
export type LocalIdPlugin = NextEditorPlugin<'localId', {
actions: {
/**
* Get the node with its position in the document
*
* @param props.localId Local id of the node in question
* @returns { node: ProsemirrorNode, pos: number } Object containing prosemirror node and position in the document
*/
getNode: (props: ActionProps) => NodeWithPos | undefined;
/**
* Replace the node in the document by its local id
*
* @param props.localId Local id of the node in question
* @param props.value Prosemirror node to replace the node with
* @returns boolean if the replace was successful
*/
replaceNode: (props: ActionProps & {
value: Node;
}) => boolean;
};
dependencies: [
CompositionPlugin,
OptionalPlugin<CollabEditPlugin>,
OptionalPlugin<LimitedModePlugin>
];
sharedState: LocalIdSharedState | undefined;
}>;