@atlaskit/editor-plugin-annotation 2.8.2 → 2.9.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/editor-commands/index.js +50 -1
  3. package/dist/cjs/pm-plugins/annotation-manager-hooks.js +166 -4
  4. package/dist/cjs/pm-plugins/inline-comment.js +169 -30
  5. package/dist/cjs/pm-plugins/plugin-factory.js +51 -1
  6. package/dist/cjs/pm-plugins/reducer.js +18 -1
  7. package/dist/cjs/pm-plugins/toolbar.js +10 -7
  8. package/dist/cjs/pm-plugins/types.js +2 -0
  9. package/dist/cjs/ui/InlineCommentView.js +14 -1
  10. package/dist/es2019/editor-commands/index.js +42 -0
  11. package/dist/es2019/pm-plugins/annotation-manager-hooks.js +160 -5
  12. package/dist/es2019/pm-plugins/inline-comment.js +146 -9
  13. package/dist/es2019/pm-plugins/plugin-factory.js +51 -1
  14. package/dist/es2019/pm-plugins/reducer.js +22 -1
  15. package/dist/es2019/pm-plugins/toolbar.js +10 -8
  16. package/dist/es2019/pm-plugins/types.js +2 -0
  17. package/dist/es2019/ui/InlineCommentView.js +11 -1
  18. package/dist/esm/editor-commands/index.js +49 -0
  19. package/dist/esm/pm-plugins/annotation-manager-hooks.js +167 -5
  20. package/dist/esm/pm-plugins/inline-comment.js +159 -20
  21. package/dist/esm/pm-plugins/plugin-factory.js +51 -1
  22. package/dist/esm/pm-plugins/reducer.js +18 -1
  23. package/dist/esm/pm-plugins/toolbar.js +10 -7
  24. package/dist/esm/pm-plugins/types.js +2 -0
  25. package/dist/esm/ui/InlineCommentView.js +11 -1
  26. package/dist/types/editor-commands/index.d.ts +5 -0
  27. package/dist/types/pm-plugins/annotation-manager-hooks.d.ts +4 -1
  28. package/dist/types/pm-plugins/plugin-factory.d.ts +4 -0
  29. package/dist/types/pm-plugins/types.d.ts +26 -1
  30. package/dist/types/types/index.d.ts +1 -0
  31. package/dist/types-ts4.5/editor-commands/index.d.ts +5 -0
  32. package/dist/types-ts4.5/pm-plugins/annotation-manager-hooks.d.ts +4 -1
  33. package/dist/types-ts4.5/pm-plugins/plugin-factory.d.ts +4 -0
  34. package/dist/types-ts4.5/pm-plugins/types.d.ts +26 -1
  35. package/dist/types-ts4.5/types/index.d.ts +1 -0
  36. package/package.json +7 -4
@@ -1,5 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import React from 'react';
2
+ import React, { useRef } from 'react';
3
3
  import { AnnotationTypes } from '@atlaskit/adf-schema';
4
4
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, CONTENT_COMPONENT, EVENT_TYPE, RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
5
5
  import { sharedPluginStateHookMigratorFactory } from '@atlaskit/editor-common/hooks';
@@ -72,6 +72,7 @@ export function InlineCommentView(_ref3) {
72
72
  var inlineCommentProvider = providers.inlineComment;
73
73
  var state = editorView.state,
74
74
  dispatch = editorView.dispatch;
75
+ var lastSelectedAnnotationId = useRef();
75
76
  var CreateComponent = inlineCommentProvider.createComponent,
76
77
  ViewComponent = inlineCommentProvider.viewComponent;
77
78
  var _useInlineCommentView = useInlineCommentViewPluginState({
@@ -124,9 +125,17 @@ export function InlineCommentView(_ref3) {
124
125
 
125
126
  // Create Component
126
127
  if (bookmark) {
128
+ var _selectedAnnotations$;
127
129
  if (!CreateComponent) {
128
130
  return null;
129
131
  }
132
+ var currentlySelectedAnnotation = selectedAnnotations === null || selectedAnnotations === void 0 || (_selectedAnnotations$ = selectedAnnotations[0]) === null || _selectedAnnotations$ === void 0 ? void 0 : _selectedAnnotations$.id;
133
+ var isAnnotationSelectionChanged = currentlySelectedAnnotation !== lastSelectedAnnotationId.current;
134
+
135
+ // Update the last selected annotation ID if the selection was updated
136
+ if (isAnnotationSelectionChanged) {
137
+ lastSelectedAnnotationId.current = currentlySelectedAnnotation;
138
+ }
130
139
  var inlineNodeTypes = getRangeInlineNodeNames({
131
140
  doc: state.doc,
132
141
  pos: selection
@@ -140,6 +149,7 @@ export function InlineCommentView(_ref3) {
140
149
  }, /*#__PURE__*/React.createElement(CreateComponent, {
141
150
  dom: dom,
142
151
  textSelection: textSelection,
152
+ wasNewAnnotationSelected: !!currentlySelectedAnnotation && isAnnotationSelectionChanged,
143
153
  onCreate: function onCreate(id) {
144
154
  if (!fg('platform_editor_comments_api_manager')) {
145
155
  var createAnnotationResult = createAnnotation(editorAnalyticsAPI, editorAPI)(id, AnnotationTypes.INLINE_COMMENT, inlineCommentProvider.supportedBlockNodes)(editorView.state, editorView.dispatch);
@@ -9,10 +9,15 @@ import type { InlineCommentInputMethod, TargetType } from '../types';
9
9
  export declare const updateInlineCommentResolvedState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (partialNewState: InlineCommentMap, resolveMethod?: RESOLVE_METHOD) => Command;
10
10
  export declare const closeComponent: () => Command;
11
11
  export declare const clearDirtyMark: () => Command;
12
+ export declare const flushPendingSelections: (canSetAsSelectedAnnotations: boolean) => Command;
13
+ export declare const setPendingSelectedAnnotation: (id: string) => Command;
12
14
  export declare const removeInlineCommentNearSelection: (id: string, supportedNodes?: string[]) => Command;
15
+ export declare const removeInlineCommentFromDoc: (id: string, supportedNodes?: string[]) => Command;
13
16
  /**
14
17
  * Show active inline comments for a given block node, otherwise,
15
18
  * return false if the node has no comments or no unresolved comments.
19
+ * @param supportedBlockNodes
20
+ * @example
16
21
  */
17
22
  export declare const showInlineCommentForBlockNode: (supportedBlockNodes?: string[]) => (node: PMNode | null, viewMethod?: VIEW_METHOD, isOpeningMediaCommentFromToolbar?: boolean) => Command;
18
23
  export declare const setInlineCommentDraftState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, supportedBlockNodes?: string[]) => (drafting: boolean, inputMethod?: InlineCommentInputMethod, targetType?: TargetType, targetNodeId?: string | undefined, isOpeningMediaCommentFromToolbar?: boolean) => Command;
@@ -1,5 +1,5 @@
1
1
  import { type AnnotationId } from '@atlaskit/adf-schema';
2
- import type { ApplyDraftResult, ClearDraftResult, GetDraftResult, StartDraftResult } from '@atlaskit/editor-common/annotation';
2
+ import type { ApplyDraftResult, ClearAnnotationResult, ClearDraftResult, GetDraftResult, HoverAnnotationResult, SelectAnnotationResult, StartDraftResult } from '@atlaskit/editor-common/annotation';
3
3
  import { type EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
  import type { InlineCommentPluginOptions } from './types';
5
5
  export declare const allowAnnotation: (editorView: EditorView, options: InlineCommentPluginOptions) => () => boolean;
@@ -7,3 +7,6 @@ export declare const startDraft: (editorView: EditorView, options: InlineComment
7
7
  export declare const clearDraft: (editorView: EditorView, options: InlineCommentPluginOptions) => () => ClearDraftResult;
8
8
  export declare const applyDraft: (editorView: EditorView, options: InlineCommentPluginOptions) => (id: AnnotationId) => ApplyDraftResult;
9
9
  export declare const getDraft: (editorView: EditorView, options: InlineCommentPluginOptions) => () => GetDraftResult;
10
+ export declare const setIsAnnotationSelected: (editorView: EditorView, options: InlineCommentPluginOptions) => (id: AnnotationId, isSelected: boolean) => SelectAnnotationResult;
11
+ export declare const setIsAnnotationHovered: (editorView: EditorView, options: InlineCommentPluginOptions) => (id: AnnotationId, isHovered: boolean) => HoverAnnotationResult;
12
+ export declare const clearAnnotation: (editorView: EditorView, options: InlineCommentPluginOptions) => (id: AnnotationId) => ClearAnnotationResult;
@@ -4,6 +4,10 @@ import type { InlineCommentPluginState } from './types';
4
4
  * We clear bookmark on the following conditions:
5
5
  * 1. if current selection is an empty selection, or
6
6
  * 2. if the current selection and bookmark selection are different
7
+ * @param tr
8
+ * @param editorState
9
+ * @param bookmark
10
+ * @example
7
11
  */
8
12
  export declare const shouldClearBookMarkCheck: (tr: ReadonlyTransaction | Transaction, editorState: EditorState, bookmark?: SelectionBookmark) => boolean;
9
13
  export declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch, initialState: InlineCommentPluginState | ((state: EditorState) => InlineCommentPluginState)) => import("prosemirror-state").SafeStateField<InlineCommentPluginState>, createCommand: <A = import("./types").InlineCommentAction>(action: A | ((state: Readonly<EditorState>) => false | A), transform?: ((tr: Transaction, state: EditorState) => Transaction) | undefined) => import("@atlaskit/editor-common/types").Command;
@@ -15,7 +15,9 @@ export declare enum ACTIONS {
15
15
  INLINE_COMMENT_SET_VISIBLE = 5,
16
16
  CLOSE_COMPONENT = 6,
17
17
  SET_SELECTED_ANNOTATION = 7,
18
- SET_HOVERED_ANNOTATION = 8
18
+ SET_HOVERED_ANNOTATION = 8,
19
+ FLUSH_PENDING_SELECTIONS = 9,
20
+ SET_PENDING_SELECTIONS = 10
19
21
  }
20
22
  export interface InlineCommentPluginOptions {
21
23
  dispatch: Dispatch;
@@ -80,6 +82,16 @@ export type InlineCommentAction = {
80
82
  hoveredAnnotations: AnnotationInfo[];
81
83
  selectAnnotationMethod?: VIEW_METHOD;
82
84
  };
85
+ } | {
86
+ type: ACTIONS.FLUSH_PENDING_SELECTIONS;
87
+ data: {
88
+ canSetAsSelectedAnnotations: boolean;
89
+ };
90
+ } | {
91
+ type: ACTIONS.SET_PENDING_SELECTIONS;
92
+ data: {
93
+ selectedAnnotations: AnnotationInfo[];
94
+ };
83
95
  };
84
96
  export type InlineCommentPluginState = {
85
97
  /**
@@ -137,4 +149,17 @@ export type InlineCommentPluginState = {
137
149
  selectAnnotationMethod?: VIEW_METHOD;
138
150
  isOpeningMediaCommentFromToolbar?: boolean;
139
151
  selectCommentExperience?: AnnotationProviders['selectCommentExperience'];
152
+ /**
153
+ * This is a list of annotations which are to be selected. This is updated all the time when the selection changes, and
154
+ * are periodically flushed to selectedAnnotations. This flush event results in the annotations being selected in the editor.
155
+ * This functionality has come about due to the fact that the editor can select annotations in 3 different ways. And the fact
156
+ * that we need to introduce a preemptive gate check which is async and can block annotations from being selected before they're
157
+ * selected.
158
+ */
159
+ pendingSelectedAnnotations: AnnotationInfo[];
160
+ /**
161
+ * This is a count of the number of times the pendingSelectedAnnotations has been updated. This can be used to determine
162
+ * if the pendingSelectedAnnotations has been updated since the last time it was flushed to selectedAnnotations.
163
+ */
164
+ pendingSelectedAnnotationsUpdateCount: number;
140
165
  };
@@ -45,6 +45,7 @@ export type InlineCommentCreateComponentProps = AnnotationComponentProps & {
45
45
  * Indicates whether we're opening the media comment box from the media toolbar so we can scroll the media into view
46
46
  */
47
47
  isOpeningMediaCommentFromToolbar?: boolean;
48
+ wasNewAnnotationSelected?: boolean;
48
49
  };
49
50
  export type InlineCommentViewComponentProps = AnnotationComponentProps & {
50
51
  /**
@@ -9,10 +9,15 @@ import type { InlineCommentInputMethod, TargetType } from '../types';
9
9
  export declare const updateInlineCommentResolvedState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (partialNewState: InlineCommentMap, resolveMethod?: RESOLVE_METHOD) => Command;
10
10
  export declare const closeComponent: () => Command;
11
11
  export declare const clearDirtyMark: () => Command;
12
+ export declare const flushPendingSelections: (canSetAsSelectedAnnotations: boolean) => Command;
13
+ export declare const setPendingSelectedAnnotation: (id: string) => Command;
12
14
  export declare const removeInlineCommentNearSelection: (id: string, supportedNodes?: string[]) => Command;
15
+ export declare const removeInlineCommentFromDoc: (id: string, supportedNodes?: string[]) => Command;
13
16
  /**
14
17
  * Show active inline comments for a given block node, otherwise,
15
18
  * return false if the node has no comments or no unresolved comments.
19
+ * @param supportedBlockNodes
20
+ * @example
16
21
  */
17
22
  export declare const showInlineCommentForBlockNode: (supportedBlockNodes?: string[]) => (node: PMNode | null, viewMethod?: VIEW_METHOD, isOpeningMediaCommentFromToolbar?: boolean) => Command;
18
23
  export declare const setInlineCommentDraftState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, supportedBlockNodes?: string[]) => (drafting: boolean, inputMethod?: InlineCommentInputMethod, targetType?: TargetType, targetNodeId?: string | undefined, isOpeningMediaCommentFromToolbar?: boolean) => Command;
@@ -1,5 +1,5 @@
1
1
  import { type AnnotationId } from '@atlaskit/adf-schema';
2
- import type { ApplyDraftResult, ClearDraftResult, GetDraftResult, StartDraftResult } from '@atlaskit/editor-common/annotation';
2
+ import type { ApplyDraftResult, ClearAnnotationResult, ClearDraftResult, GetDraftResult, HoverAnnotationResult, SelectAnnotationResult, StartDraftResult } from '@atlaskit/editor-common/annotation';
3
3
  import { type EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
  import type { InlineCommentPluginOptions } from './types';
5
5
  export declare const allowAnnotation: (editorView: EditorView, options: InlineCommentPluginOptions) => () => boolean;
@@ -7,3 +7,6 @@ export declare const startDraft: (editorView: EditorView, options: InlineComment
7
7
  export declare const clearDraft: (editorView: EditorView, options: InlineCommentPluginOptions) => () => ClearDraftResult;
8
8
  export declare const applyDraft: (editorView: EditorView, options: InlineCommentPluginOptions) => (id: AnnotationId) => ApplyDraftResult;
9
9
  export declare const getDraft: (editorView: EditorView, options: InlineCommentPluginOptions) => () => GetDraftResult;
10
+ export declare const setIsAnnotationSelected: (editorView: EditorView, options: InlineCommentPluginOptions) => (id: AnnotationId, isSelected: boolean) => SelectAnnotationResult;
11
+ export declare const setIsAnnotationHovered: (editorView: EditorView, options: InlineCommentPluginOptions) => (id: AnnotationId, isHovered: boolean) => HoverAnnotationResult;
12
+ export declare const clearAnnotation: (editorView: EditorView, options: InlineCommentPluginOptions) => (id: AnnotationId) => ClearAnnotationResult;
@@ -4,6 +4,10 @@ import type { InlineCommentPluginState } from './types';
4
4
  * We clear bookmark on the following conditions:
5
5
  * 1. if current selection is an empty selection, or
6
6
  * 2. if the current selection and bookmark selection are different
7
+ * @param tr
8
+ * @param editorState
9
+ * @param bookmark
10
+ * @example
7
11
  */
8
12
  export declare const shouldClearBookMarkCheck: (tr: ReadonlyTransaction | Transaction, editorState: EditorState, bookmark?: SelectionBookmark) => boolean;
9
13
  export declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch, initialState: InlineCommentPluginState | ((state: EditorState) => InlineCommentPluginState)) => import("prosemirror-state").SafeStateField<InlineCommentPluginState>, createCommand: <A = import("./types").InlineCommentAction>(action: A | ((state: Readonly<EditorState>) => false | A), transform?: ((tr: Transaction, state: EditorState) => Transaction) | undefined) => import("@atlaskit/editor-common/types").Command;
@@ -15,7 +15,9 @@ export declare enum ACTIONS {
15
15
  INLINE_COMMENT_SET_VISIBLE = 5,
16
16
  CLOSE_COMPONENT = 6,
17
17
  SET_SELECTED_ANNOTATION = 7,
18
- SET_HOVERED_ANNOTATION = 8
18
+ SET_HOVERED_ANNOTATION = 8,
19
+ FLUSH_PENDING_SELECTIONS = 9,
20
+ SET_PENDING_SELECTIONS = 10
19
21
  }
20
22
  export interface InlineCommentPluginOptions {
21
23
  dispatch: Dispatch;
@@ -80,6 +82,16 @@ export type InlineCommentAction = {
80
82
  hoveredAnnotations: AnnotationInfo[];
81
83
  selectAnnotationMethod?: VIEW_METHOD;
82
84
  };
85
+ } | {
86
+ type: ACTIONS.FLUSH_PENDING_SELECTIONS;
87
+ data: {
88
+ canSetAsSelectedAnnotations: boolean;
89
+ };
90
+ } | {
91
+ type: ACTIONS.SET_PENDING_SELECTIONS;
92
+ data: {
93
+ selectedAnnotations: AnnotationInfo[];
94
+ };
83
95
  };
84
96
  export type InlineCommentPluginState = {
85
97
  /**
@@ -137,4 +149,17 @@ export type InlineCommentPluginState = {
137
149
  selectAnnotationMethod?: VIEW_METHOD;
138
150
  isOpeningMediaCommentFromToolbar?: boolean;
139
151
  selectCommentExperience?: AnnotationProviders['selectCommentExperience'];
152
+ /**
153
+ * This is a list of annotations which are to be selected. This is updated all the time when the selection changes, and
154
+ * are periodically flushed to selectedAnnotations. This flush event results in the annotations being selected in the editor.
155
+ * This functionality has come about due to the fact that the editor can select annotations in 3 different ways. And the fact
156
+ * that we need to introduce a preemptive gate check which is async and can block annotations from being selected before they're
157
+ * selected.
158
+ */
159
+ pendingSelectedAnnotations: AnnotationInfo[];
160
+ /**
161
+ * This is a count of the number of times the pendingSelectedAnnotations has been updated. This can be used to determine
162
+ * if the pendingSelectedAnnotations has been updated since the last time it was flushed to selectedAnnotations.
163
+ */
164
+ pendingSelectedAnnotationsUpdateCount: number;
140
165
  };
@@ -45,6 +45,7 @@ export type InlineCommentCreateComponentProps = AnnotationComponentProps & {
45
45
  * Indicates whether we're opening the media comment box from the media toolbar so we can scroll the media into view
46
46
  */
47
47
  isOpeningMediaCommentFromToolbar?: boolean;
48
+ wasNewAnnotationSelected?: boolean;
48
49
  };
49
50
  export type InlineCommentViewComponentProps = AnnotationComponentProps & {
50
51
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-annotation",
3
- "version": "2.8.2",
3
+ "version": "2.9.0",
4
4
  "description": "Annotation plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,16 +33,16 @@
33
33
  "dependencies": {
34
34
  "@atlaskit/adf-schema": "^47.6.0",
35
35
  "@atlaskit/analytics-next": "^11.0.0",
36
- "@atlaskit/editor-common": "^105.8.0",
36
+ "@atlaskit/editor-common": "^105.11.0",
37
37
  "@atlaskit/editor-plugin-analytics": "^2.3.0",
38
38
  "@atlaskit/editor-plugin-connectivity": "^2.0.0",
39
39
  "@atlaskit/editor-plugin-editor-viewmode-effects": "^2.0.0",
40
40
  "@atlaskit/editor-plugin-feature-flags": "^1.4.0",
41
41
  "@atlaskit/editor-prosemirror": "7.0.0",
42
- "@atlaskit/icon": "^26.1.0",
42
+ "@atlaskit/icon": "^26.3.0",
43
43
  "@atlaskit/onboarding": "^14.1.0",
44
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
45
- "@atlaskit/tmp-editor-statsig": "^4.24.0",
45
+ "@atlaskit/tmp-editor-statsig": "^5.1.0",
46
46
  "@babel/runtime": "^7.0.0"
47
47
  },
48
48
  "peerDependencies": {
@@ -97,6 +97,9 @@
97
97
  "platform_editor_comments_api_manager": {
98
98
  "type": "boolean"
99
99
  },
100
+ "platform_editor_comments_api_manager_select": {
101
+ "type": "boolean"
102
+ },
100
103
  "editor_inline_comments_on_inline_nodes": {
101
104
  "type": "boolean"
102
105
  },