@atlaskit/editor-plugin-annotation 3.2.2 → 3.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/editor-plugin-annotation
2
2
 
3
+ ## 3.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`5b6e41650fd59`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5b6e41650fd59) -
8
+ [ux] Introduce two new properties (getCanAddComments and contentType) which are used to disable
9
+ the toolbar's Comment button when the user doesn't have create comment permissions
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 3.2.3
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies
20
+
3
21
  ## 3.2.2
4
22
 
5
23
  ### Patch Changes
@@ -106,7 +106,9 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
106
106
  var _api$analytics4;
107
107
  var _annotationProviders$ = annotationProviders.inlineComment,
108
108
  isToolbarAbove = _annotationProviders$.isToolbarAbove,
109
- onCommentButtonMount = _annotationProviders$.onCommentButtonMount;
109
+ onCommentButtonMount = _annotationProviders$.onCommentButtonMount,
110
+ getCanAddComments = _annotationProviders$.getCanAddComments,
111
+ contentType = _annotationProviders$.contentType;
110
112
  var toolbarConfig = (0, _toolbar.buildToolbar)(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)({
111
113
  state: state,
112
114
  intl: intl,
@@ -114,7 +116,9 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
114
116
  api: api,
115
117
  createCommentExperience: annotationProviders.createCommentExperience,
116
118
  annotationManager: annotationProviders.annotationManager,
117
- onCommentButtonMount: onCommentButtonMount
119
+ onCommentButtonMount: onCommentButtonMount,
120
+ getCanAddComments: getCanAddComments,
121
+ contentType: contentType
118
122
  });
119
123
  if (!toolbarConfig) {
120
124
  return undefined;
@@ -68,7 +68,12 @@ var buildToolbar = exports.buildToolbar = function buildToolbar(editorAnalyticsA
68
68
  api = _ref2.api,
69
69
  createCommentExperience = _ref2.createCommentExperience,
70
70
  annotationManager = _ref2.annotationManager,
71
- onCommentButtonMount = _ref2.onCommentButtonMount;
71
+ onCommentButtonMount = _ref2.onCommentButtonMount,
72
+ _ref2$getCanAddCommen = _ref2.getCanAddComments,
73
+ getCanAddComments = _ref2$getCanAddCommen === void 0 ? function () {
74
+ return true;
75
+ } : _ref2$getCanAddCommen,
76
+ contentType = _ref2.contentType;
72
77
  var selectionValid = (0, _utils2.isSelectionValid)(state);
73
78
  var isMediaSelected = (0, _mediaSingle.currentMediaNodeWithPos)(state);
74
79
 
@@ -78,15 +83,20 @@ var buildToolbar = exports.buildToolbar = function buildToolbar(editorAnalyticsA
78
83
  }
79
84
  var createCommentMessage = intl.formatMessage(_messages.annotationMessages.createComment);
80
85
  var commentDisabledMessage = intl.formatMessage((0, _platformFeatureFlags.fg)('editor_inline_comments_on_inline_nodes') ? _messages.annotationMessages.createCommentDisabled : _messages.annotationMessages.createCommentInvalid);
86
+ var canAddComments = getCanAddComments();
87
+ var isCommentButtonDisabled = !canAddComments || selectionValid === _types.AnnotationSelectionType.DISABLED;
88
+ var disabledTooltipContent = !canAddComments ? intl.formatMessage(_messages.annotationMessages.noPermissionToAddComment, {
89
+ contentType: contentType
90
+ }) : commentDisabledMessage;
81
91
  var createComment = {
82
92
  type: 'button',
83
93
  showTitle: true,
84
- disabled: selectionValid === _types.AnnotationSelectionType.DISABLED || (api === null || api === void 0 || (_api$connectivity = api.connectivity) === null || _api$connectivity === void 0 || (_api$connectivity = _api$connectivity.sharedState) === null || _api$connectivity === void 0 || (_api$connectivity = _api$connectivity.currentState()) === null || _api$connectivity === void 0 ? void 0 : _api$connectivity.mode) === 'offline',
94
+ disabled: isCommentButtonDisabled || (api === null || api === void 0 || (_api$connectivity = api.connectivity) === null || _api$connectivity === void 0 || (_api$connectivity = _api$connectivity.sharedState) === null || _api$connectivity === void 0 || (_api$connectivity = _api$connectivity.currentState()) === null || _api$connectivity === void 0 ? void 0 : _api$connectivity.mode) === 'offline',
85
95
  testId: _types.AnnotationTestIds.floatingToolbarCreateButton,
86
96
  interactionName: 'start-inline-comment-action',
87
97
  icon: _comment.default,
88
98
  iconFallback: _comment.default,
89
- tooltipContent: selectionValid === _types.AnnotationSelectionType.DISABLED ? commentDisabledMessage : /*#__PURE__*/_react.default.createElement(_keymaps.ToolTipContent, {
99
+ tooltipContent: isCommentButtonDisabled ? disabledTooltipContent : /*#__PURE__*/_react.default.createElement(_keymaps.ToolTipContent, {
90
100
  description: createCommentMessage,
91
101
  keymap: _keymaps.addInlineComment
92
102
  }),
@@ -96,7 +96,9 @@ export const annotationPlugin = ({
96
96
  var _api$analytics4;
97
97
  const {
98
98
  isToolbarAbove,
99
- onCommentButtonMount
99
+ onCommentButtonMount,
100
+ getCanAddComments,
101
+ contentType
100
102
  } = annotationProviders.inlineComment;
101
103
  const toolbarConfig = buildToolbar(api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)({
102
104
  state,
@@ -105,7 +107,9 @@ export const annotationPlugin = ({
105
107
  api,
106
108
  createCommentExperience: annotationProviders.createCommentExperience,
107
109
  annotationManager: annotationProviders.annotationManager,
108
- onCommentButtonMount
110
+ onCommentButtonMount,
111
+ getCanAddComments,
112
+ contentType
109
113
  });
110
114
  if (!toolbarConfig) {
111
115
  return undefined;
@@ -64,7 +64,9 @@ export const buildToolbar = editorAnalyticsAPI => ({
64
64
  api,
65
65
  createCommentExperience,
66
66
  annotationManager,
67
- onCommentButtonMount
67
+ onCommentButtonMount,
68
+ getCanAddComments = () => true,
69
+ contentType
68
70
  }) => {
69
71
  var _api$connectivity, _api$connectivity$sha, _api$connectivity$sha2;
70
72
  const selectionValid = isSelectionValid(state);
@@ -76,15 +78,20 @@ export const buildToolbar = editorAnalyticsAPI => ({
76
78
  }
77
79
  const createCommentMessage = intl.formatMessage(annotationMessages.createComment);
78
80
  const commentDisabledMessage = intl.formatMessage(fg('editor_inline_comments_on_inline_nodes') ? annotationMessages.createCommentDisabled : annotationMessages.createCommentInvalid);
81
+ const canAddComments = getCanAddComments();
82
+ const isCommentButtonDisabled = !canAddComments || selectionValid === AnnotationSelectionType.DISABLED;
83
+ const disabledTooltipContent = !canAddComments ? intl.formatMessage(annotationMessages.noPermissionToAddComment, {
84
+ contentType
85
+ }) : commentDisabledMessage;
79
86
  const createComment = {
80
87
  type: 'button',
81
88
  showTitle: true,
82
- disabled: selectionValid === AnnotationSelectionType.DISABLED || (api === null || api === void 0 ? void 0 : (_api$connectivity = api.connectivity) === null || _api$connectivity === void 0 ? void 0 : (_api$connectivity$sha = _api$connectivity.sharedState) === null || _api$connectivity$sha === void 0 ? void 0 : (_api$connectivity$sha2 = _api$connectivity$sha.currentState()) === null || _api$connectivity$sha2 === void 0 ? void 0 : _api$connectivity$sha2.mode) === 'offline',
89
+ disabled: isCommentButtonDisabled || (api === null || api === void 0 ? void 0 : (_api$connectivity = api.connectivity) === null || _api$connectivity === void 0 ? void 0 : (_api$connectivity$sha = _api$connectivity.sharedState) === null || _api$connectivity$sha === void 0 ? void 0 : (_api$connectivity$sha2 = _api$connectivity$sha.currentState()) === null || _api$connectivity$sha2 === void 0 ? void 0 : _api$connectivity$sha2.mode) === 'offline',
83
90
  testId: AnnotationTestIds.floatingToolbarCreateButton,
84
91
  interactionName: 'start-inline-comment-action',
85
92
  icon: CommentIcon,
86
93
  iconFallback: CommentIcon,
87
- tooltipContent: selectionValid === AnnotationSelectionType.DISABLED ? commentDisabledMessage : /*#__PURE__*/React.createElement(ToolTipContent, {
94
+ tooltipContent: isCommentButtonDisabled ? disabledTooltipContent : /*#__PURE__*/React.createElement(ToolTipContent, {
88
95
  description: createCommentMessage,
89
96
  keymap: addInlineComment
90
97
  }),
@@ -99,7 +99,9 @@ export var annotationPlugin = function annotationPlugin(_ref) {
99
99
  var _api$analytics4;
100
100
  var _annotationProviders$ = annotationProviders.inlineComment,
101
101
  isToolbarAbove = _annotationProviders$.isToolbarAbove,
102
- onCommentButtonMount = _annotationProviders$.onCommentButtonMount;
102
+ onCommentButtonMount = _annotationProviders$.onCommentButtonMount,
103
+ getCanAddComments = _annotationProviders$.getCanAddComments,
104
+ contentType = _annotationProviders$.contentType;
103
105
  var toolbarConfig = buildToolbar(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)({
104
106
  state: state,
105
107
  intl: intl,
@@ -107,7 +109,9 @@ export var annotationPlugin = function annotationPlugin(_ref) {
107
109
  api: api,
108
110
  createCommentExperience: annotationProviders.createCommentExperience,
109
111
  annotationManager: annotationProviders.annotationManager,
110
- onCommentButtonMount: onCommentButtonMount
112
+ onCommentButtonMount: onCommentButtonMount,
113
+ getCanAddComments: getCanAddComments,
114
+ contentType: contentType
111
115
  });
112
116
  if (!toolbarConfig) {
113
117
  return undefined;
@@ -61,7 +61,12 @@ export var buildToolbar = function buildToolbar(editorAnalyticsAPI) {
61
61
  api = _ref2.api,
62
62
  createCommentExperience = _ref2.createCommentExperience,
63
63
  annotationManager = _ref2.annotationManager,
64
- onCommentButtonMount = _ref2.onCommentButtonMount;
64
+ onCommentButtonMount = _ref2.onCommentButtonMount,
65
+ _ref2$getCanAddCommen = _ref2.getCanAddComments,
66
+ getCanAddComments = _ref2$getCanAddCommen === void 0 ? function () {
67
+ return true;
68
+ } : _ref2$getCanAddCommen,
69
+ contentType = _ref2.contentType;
65
70
  var selectionValid = isSelectionValid(state);
66
71
  var isMediaSelected = currentMediaNodeWithPos(state);
67
72
 
@@ -71,15 +76,20 @@ export var buildToolbar = function buildToolbar(editorAnalyticsAPI) {
71
76
  }
72
77
  var createCommentMessage = intl.formatMessage(annotationMessages.createComment);
73
78
  var commentDisabledMessage = intl.formatMessage(fg('editor_inline_comments_on_inline_nodes') ? annotationMessages.createCommentDisabled : annotationMessages.createCommentInvalid);
79
+ var canAddComments = getCanAddComments();
80
+ var isCommentButtonDisabled = !canAddComments || selectionValid === AnnotationSelectionType.DISABLED;
81
+ var disabledTooltipContent = !canAddComments ? intl.formatMessage(annotationMessages.noPermissionToAddComment, {
82
+ contentType: contentType
83
+ }) : commentDisabledMessage;
74
84
  var createComment = {
75
85
  type: 'button',
76
86
  showTitle: true,
77
- disabled: selectionValid === AnnotationSelectionType.DISABLED || (api === null || api === void 0 || (_api$connectivity = api.connectivity) === null || _api$connectivity === void 0 || (_api$connectivity = _api$connectivity.sharedState) === null || _api$connectivity === void 0 || (_api$connectivity = _api$connectivity.currentState()) === null || _api$connectivity === void 0 ? void 0 : _api$connectivity.mode) === 'offline',
87
+ disabled: isCommentButtonDisabled || (api === null || api === void 0 || (_api$connectivity = api.connectivity) === null || _api$connectivity === void 0 || (_api$connectivity = _api$connectivity.sharedState) === null || _api$connectivity === void 0 || (_api$connectivity = _api$connectivity.currentState()) === null || _api$connectivity === void 0 ? void 0 : _api$connectivity.mode) === 'offline',
78
88
  testId: AnnotationTestIds.floatingToolbarCreateButton,
79
89
  interactionName: 'start-inline-comment-action',
80
90
  icon: CommentIcon,
81
91
  iconFallback: CommentIcon,
82
- tooltipContent: selectionValid === AnnotationSelectionType.DISABLED ? commentDisabledMessage : /*#__PURE__*/React.createElement(ToolTipContent, {
92
+ tooltipContent: isCommentButtonDisabled ? disabledTooltipContent : /*#__PURE__*/React.createElement(ToolTipContent, {
83
93
  description: createCommentMessage,
84
94
  keymap: addInlineComment
85
95
  }),
@@ -17,6 +17,8 @@ interface BuildToolbarOptions {
17
17
  createCommentExperience?: AnnotationProviders['createCommentExperience'];
18
18
  annotationManager?: AnnotationProviders['annotationManager'];
19
19
  onCommentButtonMount?: () => void;
20
+ getCanAddComments?: () => boolean;
21
+ contentType?: string;
20
22
  }
21
23
  export declare const getValidNodes: (state: EditorState) => NodeType[];
22
24
  type ShouldSuppressFloatingToolbarOptions = {
@@ -40,7 +42,7 @@ export declare const buildSuppressedToolbar: (state: EditorState) => {
40
42
  title: string;
41
43
  __suppressAllToolbars: boolean;
42
44
  };
43
- export declare const buildToolbar: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => ({ state, intl, isToolbarAbove, _supportedNodes, api, createCommentExperience, annotationManager, onCommentButtonMount, }: BuildToolbarOptions) => {
45
+ export declare const buildToolbar: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => ({ state, intl, isToolbarAbove, _supportedNodes, api, createCommentExperience, annotationManager, onCommentButtonMount, getCanAddComments, contentType, }: BuildToolbarOptions) => {
44
46
  title: string;
45
47
  nodeType: NodeType[];
46
48
  items: FloatingToolbarButton<Command>[];
@@ -107,6 +107,8 @@ export type InlineCommentAnnotationProvider = AnnotationTypeProvider<AnnotationT
107
107
  */
108
108
  supportedBlockNodes?: string[];
109
109
  onCommentButtonMount?: () => void;
110
+ getCanAddComments?: () => boolean;
111
+ contentType?: string;
110
112
  };
111
113
  export interface AnnotationProviders {
112
114
  inlineComment: InlineCommentAnnotationProvider;
@@ -17,6 +17,8 @@ interface BuildToolbarOptions {
17
17
  createCommentExperience?: AnnotationProviders['createCommentExperience'];
18
18
  annotationManager?: AnnotationProviders['annotationManager'];
19
19
  onCommentButtonMount?: () => void;
20
+ getCanAddComments?: () => boolean;
21
+ contentType?: string;
20
22
  }
21
23
  export declare const getValidNodes: (state: EditorState) => NodeType[];
22
24
  type ShouldSuppressFloatingToolbarOptions = {
@@ -40,7 +42,7 @@ export declare const buildSuppressedToolbar: (state: EditorState) => {
40
42
  title: string;
41
43
  __suppressAllToolbars: boolean;
42
44
  };
43
- export declare const buildToolbar: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => ({ state, intl, isToolbarAbove, _supportedNodes, api, createCommentExperience, annotationManager, onCommentButtonMount, }: BuildToolbarOptions) => {
45
+ export declare const buildToolbar: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => ({ state, intl, isToolbarAbove, _supportedNodes, api, createCommentExperience, annotationManager, onCommentButtonMount, getCanAddComments, contentType, }: BuildToolbarOptions) => {
44
46
  title: string;
45
47
  nodeType: NodeType[];
46
48
  items: FloatingToolbarButton<Command>[];
@@ -107,6 +107,8 @@ export type InlineCommentAnnotationProvider = AnnotationTypeProvider<AnnotationT
107
107
  */
108
108
  supportedBlockNodes?: string[];
109
109
  onCommentButtonMount?: () => void;
110
+ getCanAddComments?: () => boolean;
111
+ contentType?: string;
110
112
  };
111
113
  export interface AnnotationProviders {
112
114
  inlineComment: InlineCommentAnnotationProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-annotation",
3
- "version": "3.2.2",
3
+ "version": "3.3.0",
4
4
  "description": "Annotation plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -38,17 +38,17 @@
38
38
  "@atlaskit/editor-plugin-feature-flags": "^2.0.0",
39
39
  "@atlaskit/editor-plugin-toolbar": "^0.2.0",
40
40
  "@atlaskit/editor-prosemirror": "7.0.0",
41
- "@atlaskit/editor-toolbar": "^0.2.0",
41
+ "@atlaskit/editor-toolbar": "^0.3.0",
42
42
  "@atlaskit/editor-toolbar-model": "^0.1.0",
43
- "@atlaskit/icon": "^27.11.0",
43
+ "@atlaskit/icon": "^27.12.0",
44
44
  "@atlaskit/onboarding": "^14.3.0",
45
45
  "@atlaskit/platform-feature-flags": "^1.1.0",
46
- "@atlaskit/tmp-editor-statsig": "^9.27.0",
46
+ "@atlaskit/tmp-editor-statsig": "^9.29.0",
47
47
  "@babel/runtime": "^7.0.0",
48
48
  "react-intl-next": "npm:react-intl@^5.18.1"
49
49
  },
50
50
  "peerDependencies": {
51
- "@atlaskit/editor-common": "^107.20.0",
51
+ "@atlaskit/editor-common": "^107.24.0",
52
52
  "react": "^18.2.0",
53
53
  "react-dom": "^18.2.0"
54
54
  },