UNPKG

@atlaskit/editor-plugin-annotation

Version:

Annotation plugin for @atlaskit/editor-core

94 lines (93 loc) • 5.37 kB
import type { AnnotationManager } from '@atlaskit/editor-common/annotation'; import type { Command } from '@atlaskit/editor-common/types/command'; import type { ExtractInjectionAPI, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types/next-editor-plugin'; import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics/analyticsPluginType'; import type { ConnectivityPlugin } from '@atlaskit/editor-plugin-connectivity/connectivityPluginType'; import type { EditorViewModeEffectsPlugin } from '@atlaskit/editor-plugin-editor-viewmode-effects/editorViewmodeEffectsPluginType'; import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode/editorViewmodePluginType'; import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags/featureFlagsPluginType'; import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar/toolbar-plugin-type'; import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent/user-intent-plugin-type'; import type { Node, Slice } from '@atlaskit/editor-prosemirror/model'; import type { EditorState } from '@atlaskit/editor-prosemirror/state'; import type { showInlineCommentForBlockNode } from './editor-commands'; import type { InlineCommentPluginState } from './pm-plugins/types'; import type { AnnotationProviders, InlineCommentInputMethod, TargetType } from './types'; type StripNonExistingAnnotations = (slice: Slice, state: EditorState) => boolean | undefined; type SetInlineCommentDraftState = (drafting: boolean, inputMethod: InlineCommentInputMethod, /** @default 'inline' */ targetType?: TargetType, targetNodeId?: string, isOpeningMediaCommentFromToolbar?: boolean) => Command; export type AnnotationPluginDependencies = [ OptionalPlugin<AnalyticsPlugin>, OptionalPlugin<EditorViewModeEffectsPlugin>, OptionalPlugin<EditorViewModePlugin>, OptionalPlugin<FeatureFlagsPlugin>, OptionalPlugin<ConnectivityPlugin>, OptionalPlugin<ToolbarPlugin>, OptionalPlugin<UserIntentPlugin> ]; export type AnnotationPluginOptions = AnnotationProviders; /** Inline comment plugin state, plus the manager so other plugins (e.g. media) can use it. */ export type AnnotationSharedState = InlineCommentPluginState & { annotationManager?: AnnotationManager; }; export type AnnotationPlugin = NextEditorPlugin<'annotation', { actions: { /** * Applies the current inline-comment draft as an annotation mark on the * bookmarked selection. Callers must start a draft first via * `setInlineCommentDraftState`. * @returns A command that returns true when the draft is applied. */ applyInlineCommentDraft: (annotationId: string) => Command; /** * Whether the current user can add comments, from the provider's * `getCanAddComments` (defaults to true), and the provider's content type * for the no-permission message. */ getAddCommentPermission: () => { canAddComments: boolean; contentType?: string; }; hasAnyUnResolvedAnnotationInPage: (state: EditorState) => boolean; /** Whether the configured provider supports block comments on this node. */ isBlockNodeSupported: (node: Node) => boolean; /** * Removes an inline-comment annotation mark from the document by id. * @returns A command that returns true when the remove transaction is dispatched. */ removeInlineCommentAnnotation: (annotationId: string) => Command; /** * Requests that the active inline comment or comment draft be closed. * Runs the provider's close guard before closing when one is configured. * @returns `true` when the caller may continue because the comment closed or no close * capability is configured; otherwise `false`. */ requestCloseInlineComment: () => Promise<boolean>; setInlineCommentDraftState: SetInlineCommentDraftState; /** * Sets a pending selected annotation, opening its comment popup or panel. * Equivalent to clicking the annotation mark in the WYSIWYG view. * Use when the annotation manager (comments panel) IS enabled. */ setPendingSelectedAnnotation: (annotationId: string) => Command; /** * Selects the given annotation, opening its comment popup or panel. * Equivalent to clicking the annotation mark in the WYSIWYG view. * Use when the annotation manager (comments panel) is NOT enabled. */ setSelectedAnnotation: (annotationId: string) => Command; /** * This function attempts to display the inline comment popup for a given node. * @returns A command function that returns true if the given node is supported and has resolved annotation mark(s); * otherwise, it will return false. */ showCommentForBlockNode: ReturnType<typeof showInlineCommentForBlockNode>; stripNonExistingAnnotations: StripNonExistingAnnotations; }; dependencies: AnnotationPluginDependencies; pluginConfiguration: AnnotationPluginOptions | undefined; sharedState: AnnotationSharedState | undefined; }>; export type AnnotationPluginInjectionAPI = ExtractInjectionAPI<AnnotationPlugin> | undefined; export {};