@atlaskit/editor-plugin-annotation 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +18 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +30 -0
- package/dist/cjs/commands/index.js +150 -0
- package/dist/cjs/commands/transform.js +86 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/nodeviews/index.js +59 -0
- package/dist/cjs/plugin.js +132 -0
- package/dist/cjs/pm-plugins/inline-comment.js +246 -0
- package/dist/cjs/pm-plugins/keymap.js +15 -0
- package/dist/cjs/pm-plugins/plugin-factory.js +107 -0
- package/dist/cjs/pm-plugins/reducer.js +84 -0
- package/dist/cjs/pm-plugins/types.js +17 -0
- package/dist/cjs/toolbar.js +59 -0
- package/dist/cjs/types.js +20 -0
- package/dist/cjs/ui/AnnotationViewWrapper.js +39 -0
- package/dist/cjs/ui/InlineCommentView.js +149 -0
- package/dist/cjs/utils.js +372 -0
- package/dist/es2019/commands/index.js +123 -0
- package/dist/es2019/commands/transform.js +64 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/nodeviews/index.js +31 -0
- package/dist/es2019/plugin.js +127 -0
- package/dist/es2019/pm-plugins/inline-comment.js +181 -0
- package/dist/es2019/pm-plugins/keymap.js +9 -0
- package/dist/es2019/pm-plugins/plugin-factory.js +108 -0
- package/dist/es2019/pm-plugins/reducer.js +94 -0
- package/dist/es2019/pm-plugins/types.js +11 -0
- package/dist/es2019/toolbar.js +53 -0
- package/dist/es2019/types.js +14 -0
- package/dist/es2019/ui/AnnotationViewWrapper.js +15 -0
- package/dist/es2019/ui/InlineCommentView.js +145 -0
- package/dist/es2019/utils.js +334 -0
- package/dist/esm/commands/index.js +143 -0
- package/dist/esm/commands/transform.js +80 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/nodeviews/index.js +52 -0
- package/dist/esm/plugin.js +120 -0
- package/dist/esm/pm-plugins/inline-comment.js +239 -0
- package/dist/esm/pm-plugins/keymap.js +9 -0
- package/dist/esm/pm-plugins/plugin-factory.js +101 -0
- package/dist/esm/pm-plugins/reducer.js +77 -0
- package/dist/esm/pm-plugins/types.js +11 -0
- package/dist/esm/toolbar.js +52 -0
- package/dist/esm/types.js +14 -0
- package/dist/esm/ui/AnnotationViewWrapper.js +32 -0
- package/dist/esm/ui/InlineCommentView.js +142 -0
- package/dist/esm/utils.js +345 -0
- package/dist/types/commands/index.d.ts +15 -0
- package/dist/types/commands/transform.d.ts +11 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/nodeviews/index.d.ts +11 -0
- package/dist/types/plugin.d.ts +6 -0
- package/dist/types/pm-plugins/inline-comment.d.ts +3 -0
- package/dist/types/pm-plugins/keymap.d.ts +3 -0
- package/dist/types/pm-plugins/plugin-factory.d.ts +2 -0
- package/dist/types/pm-plugins/reducer.d.ts +3 -0
- package/dist/types/pm-plugins/types.d.ts +78 -0
- package/dist/types/toolbar.d.ts +5 -0
- package/dist/types/types.d.ts +100 -0
- package/dist/types/ui/AnnotationViewWrapper.d.ts +10 -0
- package/dist/types/ui/InlineCommentView.d.ts +12 -0
- package/dist/types/utils.d.ts +44 -0
- package/dist/types-ts4.5/commands/index.d.ts +15 -0
- package/dist/types-ts4.5/commands/transform.d.ts +11 -0
- package/dist/types-ts4.5/index.d.ts +3 -0
- package/dist/types-ts4.5/nodeviews/index.d.ts +11 -0
- package/dist/types-ts4.5/plugin.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/inline-comment.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/plugin-factory.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/reducer.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/types.d.ts +78 -0
- package/dist/types-ts4.5/toolbar.d.ts +5 -0
- package/dist/types-ts4.5/types.d.ts +102 -0
- package/dist/types-ts4.5/ui/AnnotationViewWrapper.d.ts +10 -0
- package/dist/types-ts4.5/ui/InlineCommentView.d.ts +12 -0
- package/dist/types-ts4.5/utils.d.ts +44 -0
- package/package.json +106 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { EditorAnalyticsAPI, RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import type { Command } from '@atlaskit/editor-common/types';
|
|
5
|
+
import type { InlineCommentMap, InlineCommentMouseData } from '../pm-plugins/types';
|
|
6
|
+
export declare const updateInlineCommentResolvedState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (partialNewState: InlineCommentMap, resolveMethod?: RESOLVE_METHOD) => Command;
|
|
7
|
+
export declare const closeComponent: () => Command;
|
|
8
|
+
export declare const clearDirtyMark: () => Command;
|
|
9
|
+
export declare const removeInlineCommentNearSelection: (id: string) => Command;
|
|
10
|
+
export declare const setInlineCommentDraftState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (drafting: boolean, inputMethod?: INPUT_METHOD.TOOLBAR | INPUT_METHOD.SHORTCUT) => Command;
|
|
11
|
+
export declare const addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (id: string) => Command;
|
|
12
|
+
export declare const updateMouseState: (mouseData: InlineCommentMouseData) => Command;
|
|
13
|
+
export declare const setSelectedAnnotation: (id: string) => Command;
|
|
14
|
+
export declare const createAnnotation: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (id: string, annotationType?: AnnotationTypes) => Command;
|
|
15
|
+
export declare const setInlineCommentsVisibility: (isVisible: boolean) => Command;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import type { EditorAnalyticsAPI, RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
declare const _default: {
|
|
5
|
+
addAnnotationMark: (id: string) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
6
|
+
addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (id: string) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
7
|
+
addOpenCloseAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (drafting: boolean, method?: INPUT_METHOD.SHORTCUT | INPUT_METHOD.TOOLBAR) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
8
|
+
addInsertAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
9
|
+
addResolveAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (method?: RESOLVE_METHOD | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { annotationPlugin } from './plugin';
|
|
2
|
+
export type { AnnotationPlugin, AnnotationProviders, InlineCommentAnnotationProvider, AnnotationInfo, InlineCommentCreateComponentProps, InlineCommentViewComponentProps, AnnotationState, AnnotationTypeProvider, InlineCommentState, } from './types';
|
|
3
|
+
export type { InlineCommentMap, InlineCommentPluginState, InlineCommentPluginOptions, InlineCommentAction, } from './pm-plugins/types';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ForwardRef } from '@atlaskit/editor-common/react-node-view';
|
|
3
|
+
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
4
|
+
export declare class AnnotationNodeView extends ReactNodeView {
|
|
5
|
+
createDomRef(): HTMLSpanElement;
|
|
6
|
+
getContentDOM(): {
|
|
7
|
+
dom: HTMLSpanElement;
|
|
8
|
+
};
|
|
9
|
+
render(_props: {}, forwardRef: ForwardRef): JSX.Element;
|
|
10
|
+
}
|
|
11
|
+
export declare const getAnnotationViewClassname: (isUnresolved: boolean, hasFocus: boolean) => string | undefined;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { UpdateEvent } from '@atlaskit/editor-common/annotation';
|
|
2
|
+
import { AnnotationUpdateEmitter } from '@atlaskit/editor-common/annotation';
|
|
3
|
+
import type { AnnotationInfo, AnnotationPlugin, AnnotationProviders, AnnotationState, AnnotationTypeProvider, InlineCommentAnnotationProvider, InlineCommentCreateComponentProps, InlineCommentState, InlineCommentViewComponentProps } from './types';
|
|
4
|
+
export declare const annotationPlugin: AnnotationPlugin;
|
|
5
|
+
export { AnnotationUpdateEmitter };
|
|
6
|
+
export type { AnnotationProviders, InlineCommentAnnotationProvider, InlineCommentCreateComponentProps, InlineCommentViewComponentProps, AnnotationTypeProvider, AnnotationInfo, AnnotationState, InlineCommentState, UpdateEvent, };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { InlineCommentPluginState } from './types';
|
|
2
|
+
export declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: InlineCommentPluginState | ((state: import("prosemirror-state").EditorState) => InlineCommentPluginState)) => import("prosemirror-state").SafeStateField<InlineCommentPluginState>, createCommand: <A = import("./types").InlineCommentAction>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: ((tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) | undefined) => import("@atlaskit/editor-common/types").Command;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import type { Dispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
3
|
+
import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
|
|
4
|
+
import type { EditorState, SelectionBookmark } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
6
|
+
import type { AnnotationInfo, InlineCommentAnnotationProvider } from '../types';
|
|
7
|
+
export declare enum ACTIONS {
|
|
8
|
+
UPDATE_INLINE_COMMENT_STATE = 0,
|
|
9
|
+
SET_INLINE_COMMENT_DRAFT_STATE = 1,
|
|
10
|
+
INLINE_COMMENT_UPDATE_MOUSE_STATE = 2,
|
|
11
|
+
INLINE_COMMENT_CLEAR_DIRTY_MARK = 3,
|
|
12
|
+
ADD_INLINE_COMMENT = 4,
|
|
13
|
+
INLINE_COMMENT_SET_VISIBLE = 5,
|
|
14
|
+
CLOSE_COMPONENT = 6,
|
|
15
|
+
SET_SELECTED_ANNOTATION = 7
|
|
16
|
+
}
|
|
17
|
+
export interface InlineCommentPluginOptions {
|
|
18
|
+
dispatch: Dispatch;
|
|
19
|
+
eventDispatcher: EventDispatcher;
|
|
20
|
+
portalProviderAPI: PortalProviderAPI;
|
|
21
|
+
provider: InlineCommentAnnotationProvider;
|
|
22
|
+
editorAnalyticsAPI: EditorAnalyticsAPI | undefined;
|
|
23
|
+
}
|
|
24
|
+
export interface InlineCommentMouseData {
|
|
25
|
+
isSelecting: boolean;
|
|
26
|
+
}
|
|
27
|
+
export type InlineCommentMap = {
|
|
28
|
+
[key: string]: boolean;
|
|
29
|
+
};
|
|
30
|
+
export type InlineCommentAction = {
|
|
31
|
+
type: ACTIONS.UPDATE_INLINE_COMMENT_STATE;
|
|
32
|
+
data: InlineCommentMap;
|
|
33
|
+
} | {
|
|
34
|
+
type: ACTIONS.SET_INLINE_COMMENT_DRAFT_STATE;
|
|
35
|
+
data: {
|
|
36
|
+
drafting: boolean;
|
|
37
|
+
editorState: EditorState;
|
|
38
|
+
};
|
|
39
|
+
} | {
|
|
40
|
+
type: ACTIONS.INLINE_COMMENT_UPDATE_MOUSE_STATE;
|
|
41
|
+
data: {
|
|
42
|
+
mouseData: InlineCommentMouseData;
|
|
43
|
+
};
|
|
44
|
+
} | {
|
|
45
|
+
type: ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK;
|
|
46
|
+
} | {
|
|
47
|
+
type: ACTIONS.CLOSE_COMPONENT;
|
|
48
|
+
} | {
|
|
49
|
+
type: ACTIONS.ADD_INLINE_COMMENT;
|
|
50
|
+
data: {
|
|
51
|
+
drafting: boolean;
|
|
52
|
+
inlineComments: InlineCommentMap;
|
|
53
|
+
editorState: EditorState;
|
|
54
|
+
selectedAnnotations: AnnotationInfo[];
|
|
55
|
+
};
|
|
56
|
+
} | {
|
|
57
|
+
type: ACTIONS.INLINE_COMMENT_SET_VISIBLE;
|
|
58
|
+
data: {
|
|
59
|
+
isVisible: boolean;
|
|
60
|
+
};
|
|
61
|
+
} | {
|
|
62
|
+
type: ACTIONS.SET_SELECTED_ANNOTATION;
|
|
63
|
+
data: {
|
|
64
|
+
selectedAnnotations: AnnotationInfo[];
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export type InlineCommentPluginState = {
|
|
68
|
+
annotations: InlineCommentMap;
|
|
69
|
+
selectedAnnotations: AnnotationInfo[];
|
|
70
|
+
dirtyAnnotations?: boolean;
|
|
71
|
+
mouseData: InlineCommentMouseData;
|
|
72
|
+
draftDecorationSet?: DecorationSet;
|
|
73
|
+
bookmark?: SelectionBookmark;
|
|
74
|
+
disallowOnWhitespace: boolean;
|
|
75
|
+
isInlineCommentViewClosed: boolean;
|
|
76
|
+
isVisible: boolean;
|
|
77
|
+
skipSelectionHandling: boolean;
|
|
78
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IntlShape } from 'react-intl-next';
|
|
2
|
+
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import type { FloatingToolbarConfig } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
export declare const buildToolbar: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (state: EditorState, intl: IntlShape, isToolbarAbove?: boolean) => FloatingToolbarConfig | undefined;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
3
|
+
import type { AnnotationUpdateEmitter } from '@atlaskit/editor-common/annotation';
|
|
4
|
+
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
5
|
+
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
6
|
+
import type { Slice } from '@atlaskit/editor-prosemirror/model';
|
|
7
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
+
import type { InlineCommentPluginState } from './pm-plugins/types';
|
|
9
|
+
type StripNonExistingAnnotations = (slice: Slice, state: EditorState) => boolean | undefined;
|
|
10
|
+
export type AnnotationPlugin = NextEditorPlugin<'annotation', {
|
|
11
|
+
pluginConfiguration: AnnotationProviders | undefined;
|
|
12
|
+
sharedState: InlineCommentPluginState | undefined;
|
|
13
|
+
dependencies: [OptionalPlugin<AnalyticsPlugin>];
|
|
14
|
+
actions: {
|
|
15
|
+
stripNonExistingAnnotations: StripNonExistingAnnotations;
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
export type AnnotationInfo = {
|
|
19
|
+
id: string;
|
|
20
|
+
type: AnnotationTypes.INLINE_COMMENT;
|
|
21
|
+
};
|
|
22
|
+
type AnnotationComponentProps = {
|
|
23
|
+
/**
|
|
24
|
+
* Selected text (can be used when creating a comment)
|
|
25
|
+
*/
|
|
26
|
+
textSelection?: string;
|
|
27
|
+
/**
|
|
28
|
+
* DOM element around selected text (for positioning)
|
|
29
|
+
*/
|
|
30
|
+
dom?: HTMLElement;
|
|
31
|
+
/**
|
|
32
|
+
* Indicates that a draft comment was discarded/cancelled
|
|
33
|
+
*/
|
|
34
|
+
onClose?: () => void;
|
|
35
|
+
};
|
|
36
|
+
export type InlineCommentCreateComponentProps = AnnotationComponentProps & {
|
|
37
|
+
/**
|
|
38
|
+
* Creates an annotation mark in the document with the given id.
|
|
39
|
+
*/
|
|
40
|
+
onCreate: (id: string) => void;
|
|
41
|
+
};
|
|
42
|
+
export type InlineCommentViewComponentProps = AnnotationComponentProps & {
|
|
43
|
+
/**
|
|
44
|
+
* Existing annotations where the cursor is placed.
|
|
45
|
+
* These are provided in order, inner-most first.
|
|
46
|
+
*/
|
|
47
|
+
annotations: Array<AnnotationInfo>;
|
|
48
|
+
/**
|
|
49
|
+
* Resolves an annotation with the given ID around the selection.
|
|
50
|
+
*/
|
|
51
|
+
onResolve: (id: string) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Removes the annotation from the document
|
|
54
|
+
*/
|
|
55
|
+
onDelete?: (id: string) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Ordered list of annotation ids as shown in the document
|
|
58
|
+
*/
|
|
59
|
+
annotationsList?: string[];
|
|
60
|
+
};
|
|
61
|
+
export interface AnnotationState<Type, State> {
|
|
62
|
+
annotationType: Type;
|
|
63
|
+
id: string;
|
|
64
|
+
state: State;
|
|
65
|
+
}
|
|
66
|
+
export interface AnnotationTypeProvider<Type, State> {
|
|
67
|
+
getState: (annotationIds: string[]) => Promise<AnnotationState<Type, State>[]>;
|
|
68
|
+
updateSubscriber?: AnnotationUpdateEmitter;
|
|
69
|
+
disallowOnWhitespace?: boolean;
|
|
70
|
+
}
|
|
71
|
+
export type InlineCommentState = {
|
|
72
|
+
resolved: boolean;
|
|
73
|
+
};
|
|
74
|
+
export type InlineCommentAnnotationProvider = AnnotationTypeProvider<AnnotationTypes.INLINE_COMMENT, InlineCommentState> & {
|
|
75
|
+
createComponent?: React.ComponentType<InlineCommentCreateComponentProps>;
|
|
76
|
+
viewComponent?: React.ComponentType<InlineCommentViewComponentProps>;
|
|
77
|
+
isToolbarAbove?: boolean;
|
|
78
|
+
};
|
|
79
|
+
export interface AnnotationProviders {
|
|
80
|
+
inlineComment: InlineCommentAnnotationProvider;
|
|
81
|
+
}
|
|
82
|
+
export declare enum AnnotationSelectionType {
|
|
83
|
+
INVALID = "invalid",
|
|
84
|
+
DISABLED = "disabled",
|
|
85
|
+
VALID = "valid"
|
|
86
|
+
}
|
|
87
|
+
export declare const AnnotationTestIds: {
|
|
88
|
+
prefix: string;
|
|
89
|
+
floatingComponent: string;
|
|
90
|
+
floatingToolbarCreateButton: string;
|
|
91
|
+
componentSave: string;
|
|
92
|
+
componentClose: string;
|
|
93
|
+
};
|
|
94
|
+
export type CoordsAtPos = {
|
|
95
|
+
top: number;
|
|
96
|
+
bottom: number;
|
|
97
|
+
left: number;
|
|
98
|
+
right: number;
|
|
99
|
+
};
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type AnnotationViewWrapperProps = {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
onViewed?: () => void;
|
|
5
|
+
annotationText?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class AnnotationViewWrapper extends React.PureComponent<AnnotationViewWrapperProps> {
|
|
8
|
+
componentDidMount(): void;
|
|
9
|
+
render(): React.ReactNode;
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { DispatchAnalyticsEvent, EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import type { AnnotationProviders } from '../types';
|
|
5
|
+
interface InlineCommentViewProps {
|
|
6
|
+
providers: AnnotationProviders;
|
|
7
|
+
editorView: EditorView;
|
|
8
|
+
editorAnalyticsAPI: EditorAnalyticsAPI | undefined;
|
|
9
|
+
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
10
|
+
}
|
|
11
|
+
export declare function InlineCommentView({ providers, editorView, editorAnalyticsAPI, dispatchAnalyticsEvent, }: InlineCommentViewProps): JSX.Element | null;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AnalyticsEventPayloadCallback, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { containsAnyAnnotations, hasAnnotationMark } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import type { Mark, Node, ResolvedPos, Schema, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
+
import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import { AllSelection, PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
6
|
+
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
7
|
+
import type { InlineCommentPluginState } from './pm-plugins/types';
|
|
8
|
+
import type { AnnotationInfo } from './types';
|
|
9
|
+
import { AnnotationSelectionType } from './types';
|
|
10
|
+
export { hasAnnotationMark, containsAnyAnnotations };
|
|
11
|
+
/**
|
|
12
|
+
* Finds the marks in the nodes to the left and right.
|
|
13
|
+
* @param $pos Position to center search around
|
|
14
|
+
*/
|
|
15
|
+
export declare const surroundingMarks: ($pos: ResolvedPos) => (readonly Mark[])[];
|
|
16
|
+
export declare const getAllAnnotations: (doc: Node) => string[];
|
|
17
|
+
export declare const addDraftDecoration: (start: number, end: number) => Decoration;
|
|
18
|
+
export declare const getAnnotationViewKey: (annotations: AnnotationInfo[]) => string;
|
|
19
|
+
export declare const findAnnotationsInSelection: (selection: Selection, doc: Node) => AnnotationInfo[];
|
|
20
|
+
/**
|
|
21
|
+
* get selection from position to apply new comment for
|
|
22
|
+
* @return bookmarked positions if they exists, otherwise current selection positions
|
|
23
|
+
*/
|
|
24
|
+
export declare function getSelectionPositions(editorState: EditorState, inlineCommentState?: InlineCommentPluginState | null | undefined): Selection;
|
|
25
|
+
export declare const inlineCommentPluginKey: PluginKey<InlineCommentPluginState>;
|
|
26
|
+
export declare const getPluginState: (state: EditorState) => InlineCommentPluginState | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* get payload for the open/close analytics event
|
|
29
|
+
*/
|
|
30
|
+
export declare const getDraftCommandAnalyticsPayload: (drafting: boolean, inputMethod: INPUT_METHOD.TOOLBAR | INPUT_METHOD.SHORTCUT) => AnalyticsEventPayloadCallback;
|
|
31
|
+
export declare const isSelectionValid: (state: EditorState) => AnnotationSelectionType;
|
|
32
|
+
export declare const hasInvalidNodes: (state: EditorState) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if any of the nodes in a given selection are completely whitespace
|
|
35
|
+
* This is to conform to Confluence annotation specifications
|
|
36
|
+
*/
|
|
37
|
+
export declare function hasInvalidWhitespaceNode(selection: TextSelection | AllSelection, schema: Schema): boolean;
|
|
38
|
+
export declare function annotationExists(annotationId: string, state: EditorState): boolean;
|
|
39
|
+
export declare function stripNonExistingAnnotations(slice: Slice, state: EditorState): false | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Compares two sets of annotationInfos to see if the annotations have changed
|
|
42
|
+
* This function assumes annotations will have unique id's for simplicity
|
|
43
|
+
*/
|
|
44
|
+
export declare function isSelectedAnnotationsChanged(oldSelectedAnnotations: AnnotationInfo[], newSelectedAnnotations: AnnotationInfo[]): boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { EditorAnalyticsAPI, RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import type { Command } from '@atlaskit/editor-common/types';
|
|
5
|
+
import type { InlineCommentMap, InlineCommentMouseData } from '../pm-plugins/types';
|
|
6
|
+
export declare const updateInlineCommentResolvedState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (partialNewState: InlineCommentMap, resolveMethod?: RESOLVE_METHOD) => Command;
|
|
7
|
+
export declare const closeComponent: () => Command;
|
|
8
|
+
export declare const clearDirtyMark: () => Command;
|
|
9
|
+
export declare const removeInlineCommentNearSelection: (id: string) => Command;
|
|
10
|
+
export declare const setInlineCommentDraftState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (drafting: boolean, inputMethod?: INPUT_METHOD.TOOLBAR | INPUT_METHOD.SHORTCUT) => Command;
|
|
11
|
+
export declare const addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (id: string) => Command;
|
|
12
|
+
export declare const updateMouseState: (mouseData: InlineCommentMouseData) => Command;
|
|
13
|
+
export declare const setSelectedAnnotation: (id: string) => Command;
|
|
14
|
+
export declare const createAnnotation: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (id: string, annotationType?: AnnotationTypes) => Command;
|
|
15
|
+
export declare const setInlineCommentsVisibility: (isVisible: boolean) => Command;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import type { EditorAnalyticsAPI, RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
declare const _default: {
|
|
5
|
+
addAnnotationMark: (id: string) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
6
|
+
addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (id: string) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
7
|
+
addOpenCloseAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (drafting: boolean, method?: INPUT_METHOD.SHORTCUT | INPUT_METHOD.TOOLBAR) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
8
|
+
addInsertAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
9
|
+
addResolveAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (method?: RESOLVE_METHOD | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { annotationPlugin } from './plugin';
|
|
2
|
+
export type { AnnotationPlugin, AnnotationProviders, InlineCommentAnnotationProvider, AnnotationInfo, InlineCommentCreateComponentProps, InlineCommentViewComponentProps, AnnotationState, AnnotationTypeProvider, InlineCommentState, } from './types';
|
|
3
|
+
export type { InlineCommentMap, InlineCommentPluginState, InlineCommentPluginOptions, InlineCommentAction, } from './pm-plugins/types';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ForwardRef } from '@atlaskit/editor-common/react-node-view';
|
|
3
|
+
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
4
|
+
export declare class AnnotationNodeView extends ReactNodeView {
|
|
5
|
+
createDomRef(): HTMLSpanElement;
|
|
6
|
+
getContentDOM(): {
|
|
7
|
+
dom: HTMLSpanElement;
|
|
8
|
+
};
|
|
9
|
+
render(_props: {}, forwardRef: ForwardRef): JSX.Element;
|
|
10
|
+
}
|
|
11
|
+
export declare const getAnnotationViewClassname: (isUnresolved: boolean, hasFocus: boolean) => string | undefined;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { UpdateEvent } from '@atlaskit/editor-common/annotation';
|
|
2
|
+
import { AnnotationUpdateEmitter } from '@atlaskit/editor-common/annotation';
|
|
3
|
+
import type { AnnotationInfo, AnnotationPlugin, AnnotationProviders, AnnotationState, AnnotationTypeProvider, InlineCommentAnnotationProvider, InlineCommentCreateComponentProps, InlineCommentState, InlineCommentViewComponentProps } from './types';
|
|
4
|
+
export declare const annotationPlugin: AnnotationPlugin;
|
|
5
|
+
export { AnnotationUpdateEmitter };
|
|
6
|
+
export type { AnnotationProviders, InlineCommentAnnotationProvider, InlineCommentCreateComponentProps, InlineCommentViewComponentProps, AnnotationTypeProvider, AnnotationInfo, AnnotationState, InlineCommentState, UpdateEvent, };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { InlineCommentPluginState } from './types';
|
|
2
|
+
export declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: InlineCommentPluginState | ((state: import("prosemirror-state").EditorState) => InlineCommentPluginState)) => import("prosemirror-state").SafeStateField<InlineCommentPluginState>, createCommand: <A = import("./types").InlineCommentAction>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: ((tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) | undefined) => import("@atlaskit/editor-common/types").Command;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import type { Dispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
3
|
+
import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
|
|
4
|
+
import type { EditorState, SelectionBookmark } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
6
|
+
import type { AnnotationInfo, InlineCommentAnnotationProvider } from '../types';
|
|
7
|
+
export declare enum ACTIONS {
|
|
8
|
+
UPDATE_INLINE_COMMENT_STATE = 0,
|
|
9
|
+
SET_INLINE_COMMENT_DRAFT_STATE = 1,
|
|
10
|
+
INLINE_COMMENT_UPDATE_MOUSE_STATE = 2,
|
|
11
|
+
INLINE_COMMENT_CLEAR_DIRTY_MARK = 3,
|
|
12
|
+
ADD_INLINE_COMMENT = 4,
|
|
13
|
+
INLINE_COMMENT_SET_VISIBLE = 5,
|
|
14
|
+
CLOSE_COMPONENT = 6,
|
|
15
|
+
SET_SELECTED_ANNOTATION = 7
|
|
16
|
+
}
|
|
17
|
+
export interface InlineCommentPluginOptions {
|
|
18
|
+
dispatch: Dispatch;
|
|
19
|
+
eventDispatcher: EventDispatcher;
|
|
20
|
+
portalProviderAPI: PortalProviderAPI;
|
|
21
|
+
provider: InlineCommentAnnotationProvider;
|
|
22
|
+
editorAnalyticsAPI: EditorAnalyticsAPI | undefined;
|
|
23
|
+
}
|
|
24
|
+
export interface InlineCommentMouseData {
|
|
25
|
+
isSelecting: boolean;
|
|
26
|
+
}
|
|
27
|
+
export type InlineCommentMap = {
|
|
28
|
+
[key: string]: boolean;
|
|
29
|
+
};
|
|
30
|
+
export type InlineCommentAction = {
|
|
31
|
+
type: ACTIONS.UPDATE_INLINE_COMMENT_STATE;
|
|
32
|
+
data: InlineCommentMap;
|
|
33
|
+
} | {
|
|
34
|
+
type: ACTIONS.SET_INLINE_COMMENT_DRAFT_STATE;
|
|
35
|
+
data: {
|
|
36
|
+
drafting: boolean;
|
|
37
|
+
editorState: EditorState;
|
|
38
|
+
};
|
|
39
|
+
} | {
|
|
40
|
+
type: ACTIONS.INLINE_COMMENT_UPDATE_MOUSE_STATE;
|
|
41
|
+
data: {
|
|
42
|
+
mouseData: InlineCommentMouseData;
|
|
43
|
+
};
|
|
44
|
+
} | {
|
|
45
|
+
type: ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK;
|
|
46
|
+
} | {
|
|
47
|
+
type: ACTIONS.CLOSE_COMPONENT;
|
|
48
|
+
} | {
|
|
49
|
+
type: ACTIONS.ADD_INLINE_COMMENT;
|
|
50
|
+
data: {
|
|
51
|
+
drafting: boolean;
|
|
52
|
+
inlineComments: InlineCommentMap;
|
|
53
|
+
editorState: EditorState;
|
|
54
|
+
selectedAnnotations: AnnotationInfo[];
|
|
55
|
+
};
|
|
56
|
+
} | {
|
|
57
|
+
type: ACTIONS.INLINE_COMMENT_SET_VISIBLE;
|
|
58
|
+
data: {
|
|
59
|
+
isVisible: boolean;
|
|
60
|
+
};
|
|
61
|
+
} | {
|
|
62
|
+
type: ACTIONS.SET_SELECTED_ANNOTATION;
|
|
63
|
+
data: {
|
|
64
|
+
selectedAnnotations: AnnotationInfo[];
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export type InlineCommentPluginState = {
|
|
68
|
+
annotations: InlineCommentMap;
|
|
69
|
+
selectedAnnotations: AnnotationInfo[];
|
|
70
|
+
dirtyAnnotations?: boolean;
|
|
71
|
+
mouseData: InlineCommentMouseData;
|
|
72
|
+
draftDecorationSet?: DecorationSet;
|
|
73
|
+
bookmark?: SelectionBookmark;
|
|
74
|
+
disallowOnWhitespace: boolean;
|
|
75
|
+
isInlineCommentViewClosed: boolean;
|
|
76
|
+
isVisible: boolean;
|
|
77
|
+
skipSelectionHandling: boolean;
|
|
78
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IntlShape } from 'react-intl-next';
|
|
2
|
+
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import type { FloatingToolbarConfig } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
export declare const buildToolbar: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (state: EditorState, intl: IntlShape, isToolbarAbove?: boolean) => FloatingToolbarConfig | undefined;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
3
|
+
import type { AnnotationUpdateEmitter } from '@atlaskit/editor-common/annotation';
|
|
4
|
+
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
5
|
+
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
6
|
+
import type { Slice } from '@atlaskit/editor-prosemirror/model';
|
|
7
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
+
import type { InlineCommentPluginState } from './pm-plugins/types';
|
|
9
|
+
type StripNonExistingAnnotations = (slice: Slice, state: EditorState) => boolean | undefined;
|
|
10
|
+
export type AnnotationPlugin = NextEditorPlugin<'annotation', {
|
|
11
|
+
pluginConfiguration: AnnotationProviders | undefined;
|
|
12
|
+
sharedState: InlineCommentPluginState | undefined;
|
|
13
|
+
dependencies: [
|
|
14
|
+
OptionalPlugin<AnalyticsPlugin>
|
|
15
|
+
];
|
|
16
|
+
actions: {
|
|
17
|
+
stripNonExistingAnnotations: StripNonExistingAnnotations;
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
export type AnnotationInfo = {
|
|
21
|
+
id: string;
|
|
22
|
+
type: AnnotationTypes.INLINE_COMMENT;
|
|
23
|
+
};
|
|
24
|
+
type AnnotationComponentProps = {
|
|
25
|
+
/**
|
|
26
|
+
* Selected text (can be used when creating a comment)
|
|
27
|
+
*/
|
|
28
|
+
textSelection?: string;
|
|
29
|
+
/**
|
|
30
|
+
* DOM element around selected text (for positioning)
|
|
31
|
+
*/
|
|
32
|
+
dom?: HTMLElement;
|
|
33
|
+
/**
|
|
34
|
+
* Indicates that a draft comment was discarded/cancelled
|
|
35
|
+
*/
|
|
36
|
+
onClose?: () => void;
|
|
37
|
+
};
|
|
38
|
+
export type InlineCommentCreateComponentProps = AnnotationComponentProps & {
|
|
39
|
+
/**
|
|
40
|
+
* Creates an annotation mark in the document with the given id.
|
|
41
|
+
*/
|
|
42
|
+
onCreate: (id: string) => void;
|
|
43
|
+
};
|
|
44
|
+
export type InlineCommentViewComponentProps = AnnotationComponentProps & {
|
|
45
|
+
/**
|
|
46
|
+
* Existing annotations where the cursor is placed.
|
|
47
|
+
* These are provided in order, inner-most first.
|
|
48
|
+
*/
|
|
49
|
+
annotations: Array<AnnotationInfo>;
|
|
50
|
+
/**
|
|
51
|
+
* Resolves an annotation with the given ID around the selection.
|
|
52
|
+
*/
|
|
53
|
+
onResolve: (id: string) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Removes the annotation from the document
|
|
56
|
+
*/
|
|
57
|
+
onDelete?: (id: string) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Ordered list of annotation ids as shown in the document
|
|
60
|
+
*/
|
|
61
|
+
annotationsList?: string[];
|
|
62
|
+
};
|
|
63
|
+
export interface AnnotationState<Type, State> {
|
|
64
|
+
annotationType: Type;
|
|
65
|
+
id: string;
|
|
66
|
+
state: State;
|
|
67
|
+
}
|
|
68
|
+
export interface AnnotationTypeProvider<Type, State> {
|
|
69
|
+
getState: (annotationIds: string[]) => Promise<AnnotationState<Type, State>[]>;
|
|
70
|
+
updateSubscriber?: AnnotationUpdateEmitter;
|
|
71
|
+
disallowOnWhitespace?: boolean;
|
|
72
|
+
}
|
|
73
|
+
export type InlineCommentState = {
|
|
74
|
+
resolved: boolean;
|
|
75
|
+
};
|
|
76
|
+
export type InlineCommentAnnotationProvider = AnnotationTypeProvider<AnnotationTypes.INLINE_COMMENT, InlineCommentState> & {
|
|
77
|
+
createComponent?: React.ComponentType<InlineCommentCreateComponentProps>;
|
|
78
|
+
viewComponent?: React.ComponentType<InlineCommentViewComponentProps>;
|
|
79
|
+
isToolbarAbove?: boolean;
|
|
80
|
+
};
|
|
81
|
+
export interface AnnotationProviders {
|
|
82
|
+
inlineComment: InlineCommentAnnotationProvider;
|
|
83
|
+
}
|
|
84
|
+
export declare enum AnnotationSelectionType {
|
|
85
|
+
INVALID = "invalid",
|
|
86
|
+
DISABLED = "disabled",
|
|
87
|
+
VALID = "valid"
|
|
88
|
+
}
|
|
89
|
+
export declare const AnnotationTestIds: {
|
|
90
|
+
prefix: string;
|
|
91
|
+
floatingComponent: string;
|
|
92
|
+
floatingToolbarCreateButton: string;
|
|
93
|
+
componentSave: string;
|
|
94
|
+
componentClose: string;
|
|
95
|
+
};
|
|
96
|
+
export type CoordsAtPos = {
|
|
97
|
+
top: number;
|
|
98
|
+
bottom: number;
|
|
99
|
+
left: number;
|
|
100
|
+
right: number;
|
|
101
|
+
};
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type AnnotationViewWrapperProps = {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
onViewed?: () => void;
|
|
5
|
+
annotationText?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class AnnotationViewWrapper extends React.PureComponent<AnnotationViewWrapperProps> {
|
|
8
|
+
componentDidMount(): void;
|
|
9
|
+
render(): React.ReactNode;
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { DispatchAnalyticsEvent, EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import type { AnnotationProviders } from '../types';
|
|
5
|
+
interface InlineCommentViewProps {
|
|
6
|
+
providers: AnnotationProviders;
|
|
7
|
+
editorView: EditorView;
|
|
8
|
+
editorAnalyticsAPI: EditorAnalyticsAPI | undefined;
|
|
9
|
+
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
10
|
+
}
|
|
11
|
+
export declare function InlineCommentView({ providers, editorView, editorAnalyticsAPI, dispatchAnalyticsEvent, }: InlineCommentViewProps): JSX.Element | null;
|
|
12
|
+
export {};
|