@atlaskit/editor-plugin-annotation
Version:
Annotation plugin for @atlaskit/editor-core
175 lines (174 loc) • 6.84 kB
TypeScript
import type { EditorAnalyticsAPI, VIEW_METHOD } from '@atlaskit/editor-common/analytics';
import type { AnnotationManager } from '@atlaskit/editor-common/annotation';
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
import type { FeatureFlags } from '@atlaskit/editor-common/types';
import type { EditorState, SelectionBookmark } from '@atlaskit/editor-prosemirror/state';
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
import type { AnnotationPluginInjectionAPI } from '../annotationPluginType';
import type { AnnotationInfo, AnnotationProviders, InlineCommentAnnotationProvider, TargetType } from '../types';
export declare enum ACTIONS {
UPDATE_INLINE_COMMENT_STATE = 0,
SET_INLINE_COMMENT_DRAFT_STATE = 1,
INLINE_COMMENT_UPDATE_MOUSE_STATE = 2,
INLINE_COMMENT_CLEAR_DIRTY_MARK = 3,
ADD_INLINE_COMMENT = 4,
INLINE_COMMENT_SET_VISIBLE = 5,
CLOSE_COMPONENT = 6,
SET_SELECTED_ANNOTATION = 7,
SET_HOVERED_ANNOTATION = 8,
FLUSH_PENDING_SELECTIONS = 9,
SET_PENDING_SELECTIONS = 10,
SET_INLINE_COMMENTS_FETCHED = 11
}
export interface InlineCommentPluginOptions {
annotationManager?: AnnotationManager;
api?: AnnotationPluginInjectionAPI;
dispatch: Dispatch;
editorAnalyticsAPI: EditorAnalyticsAPI | undefined;
featureFlagsPluginState?: FeatureFlags;
provider: InlineCommentAnnotationProvider;
selectCommentExperience?: AnnotationProviders['selectCommentExperience'];
viewInlineCommentTraceUFOPress?: AnnotationProviders['viewInlineCommentTraceUFOPress'];
}
export interface InlineCommentMouseData {
isSelecting: boolean;
}
export type InlineCommentMap = {
[key: string]: boolean;
};
export type InlineCommentAction = {
data: InlineCommentMap;
type: ACTIONS.UPDATE_INLINE_COMMENT_STATE;
} | {
data: {
drafting: boolean;
editorState: EditorState;
isOpeningMediaCommentFromToolbar?: boolean;
supportedBlockNodes?: string[];
targetNodeId?: string;
targetType?: TargetType;
};
type: ACTIONS.SET_INLINE_COMMENT_DRAFT_STATE;
} | {
data: {
mouseData: InlineCommentMouseData;
};
type: ACTIONS.INLINE_COMMENT_UPDATE_MOUSE_STATE;
} | {
type: ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK;
} | {
type: ACTIONS.CLOSE_COMPONENT;
} | {
data: {
drafting: boolean;
editorState: EditorState;
inlineComments: InlineCommentMap;
selectedAnnotations: AnnotationInfo[];
};
type: ACTIONS.ADD_INLINE_COMMENT;
} | {
data: {
isVisible: boolean;
};
type: ACTIONS.INLINE_COMMENT_SET_VISIBLE;
} | {
data: {
isOpeningMediaCommentFromToolbar?: boolean;
selectAnnotationMethod?: VIEW_METHOD;
selectedAnnotations: AnnotationInfo[];
};
type: ACTIONS.SET_SELECTED_ANNOTATION;
} | {
data: {
hoveredAnnotations: AnnotationInfo[];
selectAnnotationMethod?: VIEW_METHOD;
};
type: ACTIONS.SET_HOVERED_ANNOTATION;
} | {
data: {
canSetAsSelectedAnnotations: boolean;
};
type: ACTIONS.FLUSH_PENDING_SELECTIONS;
} | {
data: {
selectedAnnotations: AnnotationInfo[];
};
type: ACTIONS.SET_PENDING_SELECTIONS;
} | {
type: ACTIONS.SET_INLINE_COMMENTS_FETCHED;
};
export type InlineCommentPluginState = {
annotationsLoaded: boolean;
/**
* The resolved state of the annotations.
*
* The keys are the annotation ids, and the values are booleans indicating whether the annotation is resolved or not.
*
* The annotation is only considered unresolved if the value is false. An undefined value is treated as resolved.
* This is because the editor does not know yet the resolved state of the annotation, and so it is treated as resolved until
* the editor receives the resolved state from the server. (see dirtyAnnotations for more details)
*
* Example value
* ```
* {
* // resolved comments
* 'annotation-id': true,
* 'annotation-id-3': undefined,
* // unresolved comment
* 'annotation-id-2': false,
* }
* ```
*/
annotations: InlineCommentMap;
bookmark?: SelectionBookmark;
/**
* Indicates the document has annotations which it does not currently know the resolved state of.
* This can happen when the annotations are loaded via ncs, and the editor has not received the
* resolved state of the annotations yet (as the resolved state comes from a separate service).
*/
dirtyAnnotations?: boolean;
disallowOnWhitespace: boolean;
draftDecorationSet?: DecorationSet;
featureFlagsPluginState?: FeatureFlags;
/**
* Warning: This is not the state of annotations which are currently being hovered over,
* but rather the annotations which have been given a selected like visual state from an
* editor api.
* The Comment consumer does this when browsing comments in the sidebar, where it sets
* a "hovered" state on the annotation, while the comment is hovered in the sidebar.
*/
hoveredAnnotations?: AnnotationInfo[];
/**
* A simple toggle to indicate if the annotation manager is enabled.
*/
isAnnotationManagerEnabled: boolean;
isDrafting: boolean;
isInlineCommentViewClosed: boolean;
isOpeningMediaCommentFromToolbar?: boolean;
isVisible: boolean;
mouseData: InlineCommentMouseData;
/**
* This is a list of annotations which are to be selected. This is updated all the time when the selection changes, and
* are periodically flushed to selectedAnnotations. This flush event results in the annotations being selected in the editor.
* This functionality has come about due to the fact that the editor can select annotations in 3 different ways. And the fact
* that we need to introduce a preemptive gate check which is async and can block annotations from being selected before they're
* selected.
*/
pendingSelectedAnnotations: AnnotationInfo[];
/**
* This is a count of the number of times the pendingSelectedAnnotations has been updated. This can be used to determine
* if the pendingSelectedAnnotations has been updated since the last time it was flushed to selectedAnnotations.
*/
pendingSelectedAnnotationsUpdateCount: number;
selectAnnotationMethod?: VIEW_METHOD;
selectCommentExperience?: AnnotationProviders['selectCommentExperience'];
/**
* A list of the annotations at the current selection.
*
* While this is a list, consumers only make use of the first element, and from the
* user perspective, there is only one annotation selected at a time.
*/
selectedAnnotations: AnnotationInfo[];
skipSelectionHandling: boolean;
targetNodeId?: string;
};