@atlaskit/editor-plugin-annotation 3.1.4 → 3.2.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,21 @@
1
1
  # @atlaskit/editor-plugin-annotation
2
2
 
3
+ ## 3.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#197019](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/197019)
8
+ [`96717455eea97`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/96717455eea97) -
9
+ Create a new toolbar export from editor-common, add useEditorToolbar and EditorToolbarProvider
10
+ react context components to pass editorView to children toolbar components.
11
+
12
+ Add `@atlaskit/editor-plugin-toolbar`, `@atlaskit/editor-toolbar` and
13
+ `@atlaskit/editor-toolbar-model` as depedencies.
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies
18
+
3
19
  ## 3.1.4
4
20
 
5
21
  ### Patch Changes
@@ -17,6 +17,7 @@ var _keymap = require("./pm-plugins/keymap");
17
17
  var _toolbar = require("./pm-plugins/toolbar");
18
18
  var _utils = require("./pm-plugins/utils");
19
19
  var _InlineCommentView = require("./ui/InlineCommentView");
20
+ var _toolbarComponents = require("./ui/toolbar-components");
20
21
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
21
22
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
22
23
  var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref) {
@@ -24,6 +25,10 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
24
25
  var annotationProviders = _ref.config,
25
26
  api = _ref.api;
26
27
  var featureFlags = api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState();
28
+ if ((0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc', 'isEnabled', true)) {
29
+ var _api$toolbar;
30
+ api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents((0, _toolbarComponents.getToolbarComponents)(api, annotationProviders));
31
+ }
27
32
  return {
28
33
  name: 'annotation',
29
34
  marks: function marks() {
@@ -90,6 +95,9 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
90
95
  }
91
96
  },
92
97
  selectionToolbar: function selectionToolbar(state, intl) {
98
+ if ((0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc', 'isEnabled', true)) {
99
+ return;
100
+ }
93
101
  if (!annotationProviders) {
94
102
  return;
95
103
  }
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.CommentButton = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _messages = require("@atlaskit/editor-common/messages");
11
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
12
+ var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
13
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
14
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
15
+ var _utils = require("../../pm-plugins/utils");
16
+ var _types = require("../../types");
17
+ var _hooks = require("./hooks");
18
+ var _utils2 = require("./utils");
19
+ var CommentButton = exports.CommentButton = function CommentButton(_ref) {
20
+ var api = _ref.api,
21
+ annotationProviders = _ref.annotationProviders;
22
+ var isVisible = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'annotation.isVisible');
23
+ var bookmark = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'annotation.bookmark');
24
+ var _useEditorToolbar = (0, _toolbar.useEditorToolbar)(),
25
+ editorView = _useEditorToolbar.editorView;
26
+ var _ref2 = editorView !== null && editorView !== void 0 ? editorView : {
27
+ state: null,
28
+ dispatch: null
29
+ },
30
+ state = _ref2.state,
31
+ dispatch = _ref2.dispatch;
32
+ var annotationSelectionType = state ? (0, _utils.isSelectionValid)(state) : _types.AnnotationSelectionType.INVALID;
33
+ (0, _hooks.useCommentButtonMount)({
34
+ state: state,
35
+ annotationProviders: annotationProviders,
36
+ api: api,
37
+ annotationSelectionType: annotationSelectionType,
38
+ bookmark: bookmark
39
+ });
40
+ var intl = (0, _reactIntlNext.useIntl)();
41
+ var onClick = function onClick() {
42
+ if (!api || !state || !dispatch || !annotationProviders) {
43
+ return;
44
+ }
45
+ (0, _utils2.fireOnClickAnalyticsEvent)({
46
+ api: api
47
+ });
48
+ (0, _utils2.startCommentExperience)({
49
+ annotationProviders: annotationProviders,
50
+ api: api,
51
+ state: state,
52
+ dispatch: dispatch
53
+ });
54
+ };
55
+ if (!(0, _utils2.shouldShowCommentButton)({
56
+ state: state,
57
+ isVisible: isVisible,
58
+ annotationSelectionType: annotationSelectionType
59
+ })) {
60
+ return null;
61
+ }
62
+ var commentMessage = intl.formatMessage(_messages.annotationMessages.createComment);
63
+ var commentDisabledMessage = intl.formatMessage((0, _platformFeatureFlags.fg)('editor_inline_comments_on_inline_nodes') ? _messages.annotationMessages.createCommentDisabled : _messages.annotationMessages.createCommentInvalid);
64
+ var isDisabled = (0, _utils2.isButtonDisabled)({
65
+ state: state,
66
+ api: api
67
+ });
68
+ return (
69
+ /*#__PURE__*/
70
+ // TODO: ED-28743 - add keyboard shortcut here
71
+ _react.default.createElement(_editorToolbar.ToolbarTooltip, {
72
+ content: isDisabled ? commentDisabledMessage : commentMessage
73
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarButton, {
74
+ iconBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.CommentIcon, {
75
+ label: ""
76
+ }),
77
+ onClick: onClick,
78
+ testId: _types.AnnotationTestIds.floatingToolbarCreateButton,
79
+ isDisabled: isDisabled
80
+ }, commentMessage))
81
+ );
82
+ };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useCommentButtonMount = void 0;
7
+ var _react = require("react");
8
+ var _utils = require("@atlaskit/editor-common/utils");
9
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
+ var _utils2 = require("../../pm-plugins/utils");
11
+ var _utils3 = require("./utils");
12
+ var useCommentButtonMount = exports.useCommentButtonMount = function useCommentButtonMount(_ref) {
13
+ var state = _ref.state,
14
+ annotationProviders = _ref.annotationProviders,
15
+ api = _ref.api,
16
+ annotationSelectionType = _ref.annotationSelectionType,
17
+ bookmark = _ref.bookmark;
18
+ (0, _react.useEffect)(function () {
19
+ var _getRangeInlineNodeNa;
20
+ if (!state) {
21
+ return;
22
+ }
23
+ if (annotationProviders !== null && annotationProviders !== void 0 && annotationProviders.inlineComment && (0, _platformFeatureFlags.fg)('confluence_frontend_preload_inline_comment_editor')) {
24
+ var _annotationProviders$, _annotationProviders$2;
25
+ (_annotationProviders$ = (_annotationProviders$2 = annotationProviders.inlineComment).onCommentButtonMount) === null || _annotationProviders$ === void 0 || _annotationProviders$.call(_annotationProviders$2);
26
+ }
27
+ // Check if the selection includes an non-text inline node
28
+ var inlineNodeNames = (_getRangeInlineNodeNa = (0, _utils.getRangeInlineNodeNames)({
29
+ doc: state.doc,
30
+ pos: (0, _utils2.resolveDraftBookmark)(state, bookmark)
31
+ })) !== null && _getRangeInlineNodeNa !== void 0 ? _getRangeInlineNodeNa : [];
32
+ var isNonTextInlineNodeInludedInComment = inlineNodeNames.filter(function (nodeName) {
33
+ return nodeName !== 'text';
34
+ }).length > 0;
35
+ (0, _utils3.fireCommentButtonViewedAnalyticsEvent)({
36
+ api: api,
37
+ isNonTextInlineNodeInludedInComment: isNonTextInlineNodeInludedInComment,
38
+ annotationSelectionType: annotationSelectionType
39
+ });
40
+ // for now trying to replicate current onMount logic
41
+ // eslint-disable-next-line react-hooks/exhaustive-deps
42
+ }, []);
43
+ };
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.startCommentExperience = exports.shouldShowCommentButton = exports.isButtonDisabled = exports.fireOnClickAnalyticsEvent = exports.fireCommentButtonViewedAnalyticsEvent = exports.fireAnnotationErrorAnalyticsEvent = void 0;
7
+ var _analytics = require("@atlaskit/editor-common/analytics");
8
+ var _mediaSingle = require("@atlaskit/editor-common/media-single");
9
+ var _editorCommands = require("../../editor-commands");
10
+ var _utils = require("../../pm-plugins/utils");
11
+ var _types = require("../../types");
12
+ var isButtonDisabled = exports.isButtonDisabled = function isButtonDisabled(_ref) {
13
+ var _api$connectivity;
14
+ var state = _ref.state,
15
+ api = _ref.api;
16
+ var annotationSelectionType = state ? (0, _utils.isSelectionValid)(state) : _types.AnnotationSelectionType.INVALID;
17
+ return annotationSelectionType === _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';
18
+ };
19
+ var shouldShowCommentButton = exports.shouldShowCommentButton = function shouldShowCommentButton(_ref2) {
20
+ var state = _ref2.state,
21
+ isVisible = _ref2.isVisible,
22
+ annotationSelectionType = _ref2.annotationSelectionType;
23
+ var isMediaSelected = state ? (0, _mediaSingle.currentMediaNodeWithPos)(state) : false;
24
+
25
+ // comments on media can only be added via media floating toolbar
26
+ if (isMediaSelected || annotationSelectionType === _types.AnnotationSelectionType.INVALID || !isVisible) {
27
+ return false;
28
+ }
29
+ return true;
30
+ };
31
+ var fireOnClickAnalyticsEvent = exports.fireOnClickAnalyticsEvent = function fireOnClickAnalyticsEvent(_ref3) {
32
+ var _api$analytics;
33
+ var api = _ref3.api;
34
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
35
+ action: _analytics.ACTION.CLICKED,
36
+ actionSubject: _analytics.ACTION_SUBJECT.BUTTON,
37
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.CREATE_INLINE_COMMENT_FROM_HIGHLIGHT_ACTIONS_MENU,
38
+ eventType: _analytics.EVENT_TYPE.UI,
39
+ attributes: {
40
+ source: 'highlightActionsMenu',
41
+ pageMode: 'edit'
42
+ }
43
+ });
44
+ };
45
+ var fireAnnotationErrorAnalyticsEvent = exports.fireAnnotationErrorAnalyticsEvent = function fireAnnotationErrorAnalyticsEvent(_ref4) {
46
+ var _api$analytics2;
47
+ var api = _ref4.api,
48
+ errorReason = _ref4.errorReason;
49
+ (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || (_api$analytics2 = _api$analytics2.actions) === null || _api$analytics2 === void 0 || _api$analytics2.fireAnalyticsEvent({
50
+ action: _analytics.ACTION.ERROR,
51
+ actionSubject: _analytics.ACTION_SUBJECT.ANNOTATION,
52
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.INLINE_COMMENT,
53
+ eventType: _analytics.EVENT_TYPE.OPERATIONAL,
54
+ attributes: {
55
+ errorReason: errorReason
56
+ }
57
+ });
58
+ };
59
+ var fireCommentButtonViewedAnalyticsEvent = exports.fireCommentButtonViewedAnalyticsEvent = function fireCommentButtonViewedAnalyticsEvent(_ref5) {
60
+ var _api$analytics3;
61
+ var api = _ref5.api,
62
+ isNonTextInlineNodeInludedInComment = _ref5.isNonTextInlineNodeInludedInComment,
63
+ annotationSelectionType = _ref5.annotationSelectionType;
64
+ api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || _api$analytics3.actions.fireAnalyticsEvent({
65
+ action: _analytics.ACTION.VIEWED,
66
+ actionSubject: _analytics.ACTION_SUBJECT.BUTTON,
67
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.INLINE_COMMENT,
68
+ eventType: _analytics.EVENT_TYPE.UI,
69
+ attributes: {
70
+ isNonTextInlineNodeInludedInComment: isNonTextInlineNodeInludedInComment,
71
+ isDisabled: annotationSelectionType === _types.AnnotationSelectionType.DISABLED,
72
+ inputMethod: _analytics.INPUT_METHOD.FLOATING_TB,
73
+ mode: _analytics.MODE.EDITOR
74
+ }
75
+ });
76
+ };
77
+ var startCommentExperience = exports.startCommentExperience = function startCommentExperience(_ref6) {
78
+ var annotationProviders = _ref6.annotationProviders,
79
+ api = _ref6.api,
80
+ state = _ref6.state,
81
+ dispatch = _ref6.dispatch;
82
+ var annotationManager = annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.annotationManager;
83
+ if (annotationManager) {
84
+ annotationManager.checkPreemptiveGate().then(function (canStartDraft) {
85
+ if (canStartDraft) {
86
+ var _annotationProviders$, _annotationProviders$2;
87
+ (_annotationProviders$ = annotationProviders.createCommentExperience) === null || _annotationProviders$ === void 0 || _annotationProviders$.start({
88
+ attributes: {
89
+ pageClass: 'editor',
90
+ commentType: 'inline'
91
+ }
92
+ });
93
+ (_annotationProviders$2 = annotationProviders.createCommentExperience) === null || _annotationProviders$2 === void 0 || _annotationProviders$2.initExperience.start();
94
+ var result = annotationManager.startDraft();
95
+ if (!result.success) {
96
+ // Fire an analytics event to indicate that the user has clicked the button
97
+ // but the action was not completed, the result should contain a reason.
98
+ fireAnnotationErrorAnalyticsEvent({
99
+ api: api,
100
+ errorReason: "toolbar-start-draft-failed/".concat(result.reason)
101
+ });
102
+ }
103
+ }
104
+ }).catch(function () {
105
+ fireAnnotationErrorAnalyticsEvent({
106
+ api: api,
107
+ errorReason: "toolbar-start-draft-preemptive-gate-error"
108
+ });
109
+ });
110
+ return true;
111
+ } else {
112
+ var _annotationProviders$3, _annotationProviders$4, _api$analytics4;
113
+ annotationProviders === null || annotationProviders === void 0 || (_annotationProviders$3 = annotationProviders.createCommentExperience) === null || _annotationProviders$3 === void 0 || _annotationProviders$3.start({
114
+ attributes: {
115
+ pageClass: 'editor',
116
+ commentType: 'inline'
117
+ }
118
+ });
119
+ annotationProviders === null || annotationProviders === void 0 || (_annotationProviders$4 = annotationProviders.createCommentExperience) === null || _annotationProviders$4 === void 0 || _annotationProviders$4.initExperience.start();
120
+ return (0, _editorCommands.setInlineCommentDraftState)(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)(true)(state, dispatch);
121
+ }
122
+ };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getToolbarComponents = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
10
+ var _CommentButton = require("./CommentButton/CommentButton");
11
+ var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents(api, annotationProviders) {
12
+ return [{
13
+ type: _toolbar.COLLAB_SECTION.type,
14
+ key: _toolbar.COLLAB_SECTION.key,
15
+ parents: [{
16
+ type: 'toolbar',
17
+ key: _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR,
18
+ rank: _toolbar.TOOLBAR_RANK[_toolbar.COLLAB_SECTION.key]
19
+ }]
20
+ }, {
21
+ type: _toolbar.COMMENT_GROUP.type,
22
+ key: _toolbar.COMMENT_GROUP.key,
23
+ parents: [{
24
+ type: _toolbar.COLLAB_SECTION.type,
25
+ key: _toolbar.COLLAB_SECTION.key,
26
+ rank: _toolbar.TOOLBAR_RANK[_toolbar.COLLAB_SECTION.key]
27
+ }]
28
+ }, {
29
+ type: _toolbar.COMMENT_HERO_BUTTON.type,
30
+ key: _toolbar.COMMENT_HERO_BUTTON.key,
31
+ parents: [{
32
+ type: _toolbar.COMMENT_GROUP.type,
33
+ key: _toolbar.COMMENT_GROUP.key,
34
+ rank: _toolbar.COLLAB_SECTION_RANK[_toolbar.COMMENT_GROUP.key]
35
+ }],
36
+ component: function component() {
37
+ return /*#__PURE__*/_react.default.createElement(_CommentButton.CommentButton, {
38
+ api: api,
39
+ annotationProviders: annotationProviders
40
+ });
41
+ }
42
+ }];
43
+ };
@@ -9,12 +9,17 @@ import { keymapPlugin } from './pm-plugins/keymap';
9
9
  import { buildSuppressedToolbar, buildToolbar, shouldSuppressFloatingToolbar } from './pm-plugins/toolbar';
10
10
  import { getPluginState, hasAnyUnResolvedAnnotationInPage, stripNonExistingAnnotations } from './pm-plugins/utils';
11
11
  import { InlineCommentView } from './ui/InlineCommentView';
12
+ import { getToolbarComponents } from './ui/toolbar-components';
12
13
  export const annotationPlugin = ({
13
14
  config: annotationProviders,
14
15
  api
15
16
  }) => {
16
17
  var _api$featureFlags, _api$analytics;
17
18
  const featureFlags = api === null || api === void 0 ? void 0 : (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState();
19
+ if (expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true)) {
20
+ var _api$toolbar;
21
+ api === null || api === void 0 ? void 0 : (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.registerComponents(getToolbarComponents(api, annotationProviders));
22
+ }
18
23
  return {
19
24
  name: 'annotation',
20
25
  marks() {
@@ -80,6 +85,9 @@ export const annotationPlugin = ({
80
85
  }
81
86
  },
82
87
  selectionToolbar(state, intl) {
88
+ if (expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true)) {
89
+ return;
90
+ }
83
91
  if (!annotationProviders) {
84
92
  return;
85
93
  }
@@ -0,0 +1,78 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { annotationMessages } from '@atlaskit/editor-common/messages';
4
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
5
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
+ import { ToolbarButton, CommentIcon as NewCommentIcon, ToolbarTooltip } from '@atlaskit/editor-toolbar';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
8
+ import { isSelectionValid } from '../../pm-plugins/utils';
9
+ import { AnnotationSelectionType, AnnotationTestIds } from '../../types';
10
+ import { useCommentButtonMount } from './hooks';
11
+ import { fireOnClickAnalyticsEvent, isButtonDisabled, shouldShowCommentButton, startCommentExperience } from './utils';
12
+ export const CommentButton = ({
13
+ api,
14
+ annotationProviders
15
+ }) => {
16
+ const isVisible = useSharedPluginStateSelector(api, 'annotation.isVisible');
17
+ const bookmark = useSharedPluginStateSelector(api, 'annotation.bookmark');
18
+ const {
19
+ editorView
20
+ } = useEditorToolbar();
21
+ const {
22
+ state,
23
+ dispatch
24
+ } = editorView !== null && editorView !== void 0 ? editorView : {
25
+ state: null,
26
+ dispatch: null
27
+ };
28
+ const annotationSelectionType = state ? isSelectionValid(state) : AnnotationSelectionType.INVALID;
29
+ useCommentButtonMount({
30
+ state,
31
+ annotationProviders,
32
+ api,
33
+ annotationSelectionType,
34
+ bookmark
35
+ });
36
+ const intl = useIntl();
37
+ const onClick = () => {
38
+ if (!api || !state || !dispatch || !annotationProviders) {
39
+ return;
40
+ }
41
+ fireOnClickAnalyticsEvent({
42
+ api
43
+ });
44
+ startCommentExperience({
45
+ annotationProviders,
46
+ api,
47
+ state,
48
+ dispatch
49
+ });
50
+ };
51
+ if (!shouldShowCommentButton({
52
+ state,
53
+ isVisible,
54
+ annotationSelectionType
55
+ })) {
56
+ return null;
57
+ }
58
+ const commentMessage = intl.formatMessage(annotationMessages.createComment);
59
+ const commentDisabledMessage = intl.formatMessage(fg('editor_inline_comments_on_inline_nodes') ? annotationMessages.createCommentDisabled : annotationMessages.createCommentInvalid);
60
+ const isDisabled = isButtonDisabled({
61
+ state,
62
+ api
63
+ });
64
+ return (
65
+ /*#__PURE__*/
66
+ // TODO: ED-28743 - add keyboard shortcut here
67
+ React.createElement(ToolbarTooltip, {
68
+ content: isDisabled ? commentDisabledMessage : commentMessage
69
+ }, /*#__PURE__*/React.createElement(ToolbarButton, {
70
+ iconBefore: /*#__PURE__*/React.createElement(NewCommentIcon, {
71
+ label: ""
72
+ }),
73
+ onClick: onClick,
74
+ testId: AnnotationTestIds.floatingToolbarCreateButton,
75
+ isDisabled: isDisabled
76
+ }, commentMessage))
77
+ );
78
+ };
@@ -0,0 +1,36 @@
1
+ import { useEffect } from 'react';
2
+ import { getRangeInlineNodeNames } from '@atlaskit/editor-common/utils';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
4
+ import { resolveDraftBookmark } from '../../pm-plugins/utils';
5
+ import { fireCommentButtonViewedAnalyticsEvent } from './utils';
6
+ export const useCommentButtonMount = ({
7
+ state,
8
+ annotationProviders,
9
+ api,
10
+ annotationSelectionType,
11
+ bookmark
12
+ }) => {
13
+ useEffect(() => {
14
+ var _getRangeInlineNodeNa;
15
+ if (!state) {
16
+ return;
17
+ }
18
+ if (annotationProviders !== null && annotationProviders !== void 0 && annotationProviders.inlineComment && fg('confluence_frontend_preload_inline_comment_editor')) {
19
+ var _annotationProviders$, _annotationProviders$2;
20
+ (_annotationProviders$ = (_annotationProviders$2 = annotationProviders.inlineComment).onCommentButtonMount) === null || _annotationProviders$ === void 0 ? void 0 : _annotationProviders$.call(_annotationProviders$2);
21
+ }
22
+ // Check if the selection includes an non-text inline node
23
+ const inlineNodeNames = (_getRangeInlineNodeNa = getRangeInlineNodeNames({
24
+ doc: state.doc,
25
+ pos: resolveDraftBookmark(state, bookmark)
26
+ })) !== null && _getRangeInlineNodeNa !== void 0 ? _getRangeInlineNodeNa : [];
27
+ const isNonTextInlineNodeInludedInComment = inlineNodeNames.filter(nodeName => nodeName !== 'text').length > 0;
28
+ fireCommentButtonViewedAnalyticsEvent({
29
+ api,
30
+ isNonTextInlineNodeInludedInComment,
31
+ annotationSelectionType
32
+ });
33
+ // for now trying to replicate current onMount logic
34
+ // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ }, []);
36
+ };
@@ -0,0 +1,122 @@
1
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, MODE } from '@atlaskit/editor-common/analytics';
2
+ import { currentMediaNodeWithPos } from '@atlaskit/editor-common/media-single';
3
+ import { setInlineCommentDraftState } from '../../editor-commands';
4
+ import { isSelectionValid } from '../../pm-plugins/utils';
5
+ import { AnnotationSelectionType } from '../../types';
6
+ export const isButtonDisabled = ({
7
+ state,
8
+ api
9
+ }) => {
10
+ var _api$connectivity, _api$connectivity$sha, _api$connectivity$sha2;
11
+ const annotationSelectionType = state ? isSelectionValid(state) : AnnotationSelectionType.INVALID;
12
+ return annotationSelectionType === 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';
13
+ };
14
+ export const shouldShowCommentButton = ({
15
+ state,
16
+ isVisible,
17
+ annotationSelectionType
18
+ }) => {
19
+ const isMediaSelected = state ? currentMediaNodeWithPos(state) : false;
20
+
21
+ // comments on media can only be added via media floating toolbar
22
+ if (isMediaSelected || annotationSelectionType === AnnotationSelectionType.INVALID || !isVisible) {
23
+ return false;
24
+ }
25
+ return true;
26
+ };
27
+ export const fireOnClickAnalyticsEvent = ({
28
+ api
29
+ }) => {
30
+ var _api$analytics;
31
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent({
32
+ action: ACTION.CLICKED,
33
+ actionSubject: ACTION_SUBJECT.BUTTON,
34
+ actionSubjectId: ACTION_SUBJECT_ID.CREATE_INLINE_COMMENT_FROM_HIGHLIGHT_ACTIONS_MENU,
35
+ eventType: EVENT_TYPE.UI,
36
+ attributes: {
37
+ source: 'highlightActionsMenu',
38
+ pageMode: 'edit'
39
+ }
40
+ });
41
+ };
42
+ export const fireAnnotationErrorAnalyticsEvent = ({
43
+ api,
44
+ errorReason
45
+ }) => {
46
+ var _api$analytics2, _api$analytics2$actio;
47
+ (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : (_api$analytics2$actio = _api$analytics2.actions) === null || _api$analytics2$actio === void 0 ? void 0 : _api$analytics2$actio.fireAnalyticsEvent({
48
+ action: ACTION.ERROR,
49
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
50
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
51
+ eventType: EVENT_TYPE.OPERATIONAL,
52
+ attributes: {
53
+ errorReason
54
+ }
55
+ });
56
+ };
57
+ export const fireCommentButtonViewedAnalyticsEvent = ({
58
+ api,
59
+ isNonTextInlineNodeInludedInComment,
60
+ annotationSelectionType
61
+ }) => {
62
+ var _api$analytics3;
63
+ api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.fireAnalyticsEvent({
64
+ action: ACTION.VIEWED,
65
+ actionSubject: ACTION_SUBJECT.BUTTON,
66
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
67
+ eventType: EVENT_TYPE.UI,
68
+ attributes: {
69
+ isNonTextInlineNodeInludedInComment,
70
+ isDisabled: annotationSelectionType === AnnotationSelectionType.DISABLED,
71
+ inputMethod: INPUT_METHOD.FLOATING_TB,
72
+ mode: MODE.EDITOR
73
+ }
74
+ });
75
+ };
76
+ export const startCommentExperience = ({
77
+ annotationProviders,
78
+ api,
79
+ state,
80
+ dispatch
81
+ }) => {
82
+ const annotationManager = annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.annotationManager;
83
+ if (annotationManager) {
84
+ annotationManager.checkPreemptiveGate().then(canStartDraft => {
85
+ if (canStartDraft) {
86
+ var _annotationProviders$, _annotationProviders$2;
87
+ (_annotationProviders$ = annotationProviders.createCommentExperience) === null || _annotationProviders$ === void 0 ? void 0 : _annotationProviders$.start({
88
+ attributes: {
89
+ pageClass: 'editor',
90
+ commentType: 'inline'
91
+ }
92
+ });
93
+ (_annotationProviders$2 = annotationProviders.createCommentExperience) === null || _annotationProviders$2 === void 0 ? void 0 : _annotationProviders$2.initExperience.start();
94
+ const result = annotationManager.startDraft();
95
+ if (!result.success) {
96
+ // Fire an analytics event to indicate that the user has clicked the button
97
+ // but the action was not completed, the result should contain a reason.
98
+ fireAnnotationErrorAnalyticsEvent({
99
+ api,
100
+ errorReason: `toolbar-start-draft-failed/${result.reason}`
101
+ });
102
+ }
103
+ }
104
+ }).catch(() => {
105
+ fireAnnotationErrorAnalyticsEvent({
106
+ api,
107
+ errorReason: `toolbar-start-draft-preemptive-gate-error`
108
+ });
109
+ });
110
+ return true;
111
+ } else {
112
+ var _annotationProviders$3, _annotationProviders$4, _api$analytics4;
113
+ annotationProviders === null || annotationProviders === void 0 ? void 0 : (_annotationProviders$3 = annotationProviders.createCommentExperience) === null || _annotationProviders$3 === void 0 ? void 0 : _annotationProviders$3.start({
114
+ attributes: {
115
+ pageClass: 'editor',
116
+ commentType: 'inline'
117
+ }
118
+ });
119
+ annotationProviders === null || annotationProviders === void 0 ? void 0 : (_annotationProviders$4 = annotationProviders.createCommentExperience) === null || _annotationProviders$4 === void 0 ? void 0 : _annotationProviders$4.initExperience.start();
120
+ return setInlineCommentDraftState(api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)(true)(state, dispatch);
121
+ }
122
+ };
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { TOOLBARS, COLLAB_SECTION, TOOLBAR_RANK, COMMENT_GROUP, COLLAB_SECTION_RANK, COMMENT_HERO_BUTTON } from '@atlaskit/editor-common/toolbar';
3
+ import { CommentButton } from './CommentButton/CommentButton';
4
+ export const getToolbarComponents = (api, annotationProviders) => {
5
+ return [{
6
+ type: COLLAB_SECTION.type,
7
+ key: COLLAB_SECTION.key,
8
+ parents: [{
9
+ type: 'toolbar',
10
+ key: TOOLBARS.INLINE_TEXT_TOOLBAR,
11
+ rank: TOOLBAR_RANK[COLLAB_SECTION.key]
12
+ }]
13
+ }, {
14
+ type: COMMENT_GROUP.type,
15
+ key: COMMENT_GROUP.key,
16
+ parents: [{
17
+ type: COLLAB_SECTION.type,
18
+ key: COLLAB_SECTION.key,
19
+ rank: TOOLBAR_RANK[COLLAB_SECTION.key]
20
+ }]
21
+ }, {
22
+ type: COMMENT_HERO_BUTTON.type,
23
+ key: COMMENT_HERO_BUTTON.key,
24
+ parents: [{
25
+ type: COMMENT_GROUP.type,
26
+ key: COMMENT_GROUP.key,
27
+ rank: COLLAB_SECTION_RANK[COMMENT_GROUP.key]
28
+ }],
29
+ component: () => {
30
+ return /*#__PURE__*/React.createElement(CommentButton, {
31
+ api: api,
32
+ annotationProviders: annotationProviders
33
+ });
34
+ }
35
+ }];
36
+ };
@@ -12,11 +12,16 @@ import { keymapPlugin } from './pm-plugins/keymap';
12
12
  import { buildSuppressedToolbar, buildToolbar, shouldSuppressFloatingToolbar } from './pm-plugins/toolbar';
13
13
  import { getPluginState, hasAnyUnResolvedAnnotationInPage, stripNonExistingAnnotations } from './pm-plugins/utils';
14
14
  import { InlineCommentView } from './ui/InlineCommentView';
15
+ import { getToolbarComponents } from './ui/toolbar-components';
15
16
  export var annotationPlugin = function annotationPlugin(_ref) {
16
17
  var _api$featureFlags, _api$analytics;
17
18
  var annotationProviders = _ref.config,
18
19
  api = _ref.api;
19
20
  var featureFlags = api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState();
21
+ if (expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true)) {
22
+ var _api$toolbar;
23
+ api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents(getToolbarComponents(api, annotationProviders));
24
+ }
20
25
  return {
21
26
  name: 'annotation',
22
27
  marks: function marks() {
@@ -83,6 +88,9 @@ export var annotationPlugin = function annotationPlugin(_ref) {
83
88
  }
84
89
  },
85
90
  selectionToolbar: function selectionToolbar(state, intl) {
91
+ if (expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true)) {
92
+ return;
93
+ }
86
94
  if (!annotationProviders) {
87
95
  return;
88
96
  }
@@ -0,0 +1,75 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { annotationMessages } from '@atlaskit/editor-common/messages';
4
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
5
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
+ import { ToolbarButton, CommentIcon as NewCommentIcon, ToolbarTooltip } from '@atlaskit/editor-toolbar';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
8
+ import { isSelectionValid } from '../../pm-plugins/utils';
9
+ import { AnnotationSelectionType, AnnotationTestIds } from '../../types';
10
+ import { useCommentButtonMount } from './hooks';
11
+ import { fireOnClickAnalyticsEvent, isButtonDisabled, shouldShowCommentButton, startCommentExperience } from './utils';
12
+ export var CommentButton = function CommentButton(_ref) {
13
+ var api = _ref.api,
14
+ annotationProviders = _ref.annotationProviders;
15
+ var isVisible = useSharedPluginStateSelector(api, 'annotation.isVisible');
16
+ var bookmark = useSharedPluginStateSelector(api, 'annotation.bookmark');
17
+ var _useEditorToolbar = useEditorToolbar(),
18
+ editorView = _useEditorToolbar.editorView;
19
+ var _ref2 = editorView !== null && editorView !== void 0 ? editorView : {
20
+ state: null,
21
+ dispatch: null
22
+ },
23
+ state = _ref2.state,
24
+ dispatch = _ref2.dispatch;
25
+ var annotationSelectionType = state ? isSelectionValid(state) : AnnotationSelectionType.INVALID;
26
+ useCommentButtonMount({
27
+ state: state,
28
+ annotationProviders: annotationProviders,
29
+ api: api,
30
+ annotationSelectionType: annotationSelectionType,
31
+ bookmark: bookmark
32
+ });
33
+ var intl = useIntl();
34
+ var onClick = function onClick() {
35
+ if (!api || !state || !dispatch || !annotationProviders) {
36
+ return;
37
+ }
38
+ fireOnClickAnalyticsEvent({
39
+ api: api
40
+ });
41
+ startCommentExperience({
42
+ annotationProviders: annotationProviders,
43
+ api: api,
44
+ state: state,
45
+ dispatch: dispatch
46
+ });
47
+ };
48
+ if (!shouldShowCommentButton({
49
+ state: state,
50
+ isVisible: isVisible,
51
+ annotationSelectionType: annotationSelectionType
52
+ })) {
53
+ return null;
54
+ }
55
+ var commentMessage = intl.formatMessage(annotationMessages.createComment);
56
+ var commentDisabledMessage = intl.formatMessage(fg('editor_inline_comments_on_inline_nodes') ? annotationMessages.createCommentDisabled : annotationMessages.createCommentInvalid);
57
+ var isDisabled = isButtonDisabled({
58
+ state: state,
59
+ api: api
60
+ });
61
+ return (
62
+ /*#__PURE__*/
63
+ // TODO: ED-28743 - add keyboard shortcut here
64
+ React.createElement(ToolbarTooltip, {
65
+ content: isDisabled ? commentDisabledMessage : commentMessage
66
+ }, /*#__PURE__*/React.createElement(ToolbarButton, {
67
+ iconBefore: /*#__PURE__*/React.createElement(NewCommentIcon, {
68
+ label: ""
69
+ }),
70
+ onClick: onClick,
71
+ testId: AnnotationTestIds.floatingToolbarCreateButton,
72
+ isDisabled: isDisabled
73
+ }, commentMessage))
74
+ );
75
+ };
@@ -0,0 +1,37 @@
1
+ import { useEffect } from 'react';
2
+ import { getRangeInlineNodeNames } from '@atlaskit/editor-common/utils';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
4
+ import { resolveDraftBookmark } from '../../pm-plugins/utils';
5
+ import { fireCommentButtonViewedAnalyticsEvent } from './utils';
6
+ export var useCommentButtonMount = function useCommentButtonMount(_ref) {
7
+ var state = _ref.state,
8
+ annotationProviders = _ref.annotationProviders,
9
+ api = _ref.api,
10
+ annotationSelectionType = _ref.annotationSelectionType,
11
+ bookmark = _ref.bookmark;
12
+ useEffect(function () {
13
+ var _getRangeInlineNodeNa;
14
+ if (!state) {
15
+ return;
16
+ }
17
+ if (annotationProviders !== null && annotationProviders !== void 0 && annotationProviders.inlineComment && fg('confluence_frontend_preload_inline_comment_editor')) {
18
+ var _annotationProviders$, _annotationProviders$2;
19
+ (_annotationProviders$ = (_annotationProviders$2 = annotationProviders.inlineComment).onCommentButtonMount) === null || _annotationProviders$ === void 0 || _annotationProviders$.call(_annotationProviders$2);
20
+ }
21
+ // Check if the selection includes an non-text inline node
22
+ var inlineNodeNames = (_getRangeInlineNodeNa = getRangeInlineNodeNames({
23
+ doc: state.doc,
24
+ pos: resolveDraftBookmark(state, bookmark)
25
+ })) !== null && _getRangeInlineNodeNa !== void 0 ? _getRangeInlineNodeNa : [];
26
+ var isNonTextInlineNodeInludedInComment = inlineNodeNames.filter(function (nodeName) {
27
+ return nodeName !== 'text';
28
+ }).length > 0;
29
+ fireCommentButtonViewedAnalyticsEvent({
30
+ api: api,
31
+ isNonTextInlineNodeInludedInComment: isNonTextInlineNodeInludedInComment,
32
+ annotationSelectionType: annotationSelectionType
33
+ });
34
+ // for now trying to replicate current onMount logic
35
+ // eslint-disable-next-line react-hooks/exhaustive-deps
36
+ }, []);
37
+ };
@@ -0,0 +1,116 @@
1
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, MODE } from '@atlaskit/editor-common/analytics';
2
+ import { currentMediaNodeWithPos } from '@atlaskit/editor-common/media-single';
3
+ import { setInlineCommentDraftState } from '../../editor-commands';
4
+ import { isSelectionValid } from '../../pm-plugins/utils';
5
+ import { AnnotationSelectionType } from '../../types';
6
+ export var isButtonDisabled = function isButtonDisabled(_ref) {
7
+ var _api$connectivity;
8
+ var state = _ref.state,
9
+ api = _ref.api;
10
+ var annotationSelectionType = state ? isSelectionValid(state) : AnnotationSelectionType.INVALID;
11
+ return annotationSelectionType === 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';
12
+ };
13
+ export var shouldShowCommentButton = function shouldShowCommentButton(_ref2) {
14
+ var state = _ref2.state,
15
+ isVisible = _ref2.isVisible,
16
+ annotationSelectionType = _ref2.annotationSelectionType;
17
+ var isMediaSelected = state ? currentMediaNodeWithPos(state) : false;
18
+
19
+ // comments on media can only be added via media floating toolbar
20
+ if (isMediaSelected || annotationSelectionType === AnnotationSelectionType.INVALID || !isVisible) {
21
+ return false;
22
+ }
23
+ return true;
24
+ };
25
+ export var fireOnClickAnalyticsEvent = function fireOnClickAnalyticsEvent(_ref3) {
26
+ var _api$analytics;
27
+ var api = _ref3.api;
28
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
29
+ action: ACTION.CLICKED,
30
+ actionSubject: ACTION_SUBJECT.BUTTON,
31
+ actionSubjectId: ACTION_SUBJECT_ID.CREATE_INLINE_COMMENT_FROM_HIGHLIGHT_ACTIONS_MENU,
32
+ eventType: EVENT_TYPE.UI,
33
+ attributes: {
34
+ source: 'highlightActionsMenu',
35
+ pageMode: 'edit'
36
+ }
37
+ });
38
+ };
39
+ export var fireAnnotationErrorAnalyticsEvent = function fireAnnotationErrorAnalyticsEvent(_ref4) {
40
+ var _api$analytics2;
41
+ var api = _ref4.api,
42
+ errorReason = _ref4.errorReason;
43
+ (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || (_api$analytics2 = _api$analytics2.actions) === null || _api$analytics2 === void 0 || _api$analytics2.fireAnalyticsEvent({
44
+ action: ACTION.ERROR,
45
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
46
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
47
+ eventType: EVENT_TYPE.OPERATIONAL,
48
+ attributes: {
49
+ errorReason: errorReason
50
+ }
51
+ });
52
+ };
53
+ export var fireCommentButtonViewedAnalyticsEvent = function fireCommentButtonViewedAnalyticsEvent(_ref5) {
54
+ var _api$analytics3;
55
+ var api = _ref5.api,
56
+ isNonTextInlineNodeInludedInComment = _ref5.isNonTextInlineNodeInludedInComment,
57
+ annotationSelectionType = _ref5.annotationSelectionType;
58
+ api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || _api$analytics3.actions.fireAnalyticsEvent({
59
+ action: ACTION.VIEWED,
60
+ actionSubject: ACTION_SUBJECT.BUTTON,
61
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
62
+ eventType: EVENT_TYPE.UI,
63
+ attributes: {
64
+ isNonTextInlineNodeInludedInComment: isNonTextInlineNodeInludedInComment,
65
+ isDisabled: annotationSelectionType === AnnotationSelectionType.DISABLED,
66
+ inputMethod: INPUT_METHOD.FLOATING_TB,
67
+ mode: MODE.EDITOR
68
+ }
69
+ });
70
+ };
71
+ export var startCommentExperience = function startCommentExperience(_ref6) {
72
+ var annotationProviders = _ref6.annotationProviders,
73
+ api = _ref6.api,
74
+ state = _ref6.state,
75
+ dispatch = _ref6.dispatch;
76
+ var annotationManager = annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.annotationManager;
77
+ if (annotationManager) {
78
+ annotationManager.checkPreemptiveGate().then(function (canStartDraft) {
79
+ if (canStartDraft) {
80
+ var _annotationProviders$, _annotationProviders$2;
81
+ (_annotationProviders$ = annotationProviders.createCommentExperience) === null || _annotationProviders$ === void 0 || _annotationProviders$.start({
82
+ attributes: {
83
+ pageClass: 'editor',
84
+ commentType: 'inline'
85
+ }
86
+ });
87
+ (_annotationProviders$2 = annotationProviders.createCommentExperience) === null || _annotationProviders$2 === void 0 || _annotationProviders$2.initExperience.start();
88
+ var result = annotationManager.startDraft();
89
+ if (!result.success) {
90
+ // Fire an analytics event to indicate that the user has clicked the button
91
+ // but the action was not completed, the result should contain a reason.
92
+ fireAnnotationErrorAnalyticsEvent({
93
+ api: api,
94
+ errorReason: "toolbar-start-draft-failed/".concat(result.reason)
95
+ });
96
+ }
97
+ }
98
+ }).catch(function () {
99
+ fireAnnotationErrorAnalyticsEvent({
100
+ api: api,
101
+ errorReason: "toolbar-start-draft-preemptive-gate-error"
102
+ });
103
+ });
104
+ return true;
105
+ } else {
106
+ var _annotationProviders$3, _annotationProviders$4, _api$analytics4;
107
+ annotationProviders === null || annotationProviders === void 0 || (_annotationProviders$3 = annotationProviders.createCommentExperience) === null || _annotationProviders$3 === void 0 || _annotationProviders$3.start({
108
+ attributes: {
109
+ pageClass: 'editor',
110
+ commentType: 'inline'
111
+ }
112
+ });
113
+ annotationProviders === null || annotationProviders === void 0 || (_annotationProviders$4 = annotationProviders.createCommentExperience) === null || _annotationProviders$4 === void 0 || _annotationProviders$4.initExperience.start();
114
+ return setInlineCommentDraftState(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)(true)(state, dispatch);
115
+ }
116
+ };
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { TOOLBARS, COLLAB_SECTION, TOOLBAR_RANK, COMMENT_GROUP, COLLAB_SECTION_RANK, COMMENT_HERO_BUTTON } from '@atlaskit/editor-common/toolbar';
3
+ import { CommentButton } from './CommentButton/CommentButton';
4
+ export var getToolbarComponents = function getToolbarComponents(api, annotationProviders) {
5
+ return [{
6
+ type: COLLAB_SECTION.type,
7
+ key: COLLAB_SECTION.key,
8
+ parents: [{
9
+ type: 'toolbar',
10
+ key: TOOLBARS.INLINE_TEXT_TOOLBAR,
11
+ rank: TOOLBAR_RANK[COLLAB_SECTION.key]
12
+ }]
13
+ }, {
14
+ type: COMMENT_GROUP.type,
15
+ key: COMMENT_GROUP.key,
16
+ parents: [{
17
+ type: COLLAB_SECTION.type,
18
+ key: COLLAB_SECTION.key,
19
+ rank: TOOLBAR_RANK[COLLAB_SECTION.key]
20
+ }]
21
+ }, {
22
+ type: COMMENT_HERO_BUTTON.type,
23
+ key: COMMENT_HERO_BUTTON.key,
24
+ parents: [{
25
+ type: COMMENT_GROUP.type,
26
+ key: COMMENT_GROUP.key,
27
+ rank: COLLAB_SECTION_RANK[COMMENT_GROUP.key]
28
+ }],
29
+ component: function component() {
30
+ return /*#__PURE__*/React.createElement(CommentButton, {
31
+ api: api,
32
+ annotationProviders: annotationProviders
33
+ });
34
+ }
35
+ }];
36
+ };
@@ -4,6 +4,7 @@ import type { ConnectivityPlugin } from '@atlaskit/editor-plugin-connectivity';
4
4
  import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
5
5
  import type { EditorViewModeEffectsPlugin } from '@atlaskit/editor-plugin-editor-viewmode-effects';
6
6
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
7
+ import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
7
8
  import type { Slice } from '@atlaskit/editor-prosemirror/model';
8
9
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
9
10
  import type { showInlineCommentForBlockNode } from './editor-commands';
@@ -18,7 +19,8 @@ export type AnnotationPluginDependencies = [
18
19
  OptionalPlugin<EditorViewModeEffectsPlugin>,
19
20
  OptionalPlugin<EditorViewModePlugin>,
20
21
  OptionalPlugin<FeatureFlagsPlugin>,
21
- OptionalPlugin<ConnectivityPlugin>
22
+ OptionalPlugin<ConnectivityPlugin>,
23
+ OptionalPlugin<ToolbarPlugin>
22
24
  ];
23
25
  export type AnnotationPluginOptions = AnnotationProviders;
24
26
  export type AnnotationPlugin = NextEditorPlugin<'annotation', {
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { AnnotationPlugin } from '../../annotationPluginType';
4
+ import { type AnnotationProviders } from '../../types';
5
+ type CommentButtonProps = {
6
+ api?: ExtractInjectionAPI<AnnotationPlugin>;
7
+ annotationProviders?: AnnotationProviders;
8
+ };
9
+ export declare const CommentButton: ({ api, annotationProviders }: CommentButtonProps) => React.JSX.Element | null;
10
+ export {};
@@ -0,0 +1,22 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import { type EditorState, type SelectionBookmark } from '@atlaskit/editor-prosemirror/state';
3
+ import type { AnnotationPlugin } from '../../annotationPluginType';
4
+ import type { AnnotationSelectionType } from '../../types';
5
+ import { type AnnotationProviders } from '../../types';
6
+ export declare const useCommentButtonMount: ({ state, annotationProviders, api, annotationSelectionType, bookmark, }: {
7
+ state: EditorState | null;
8
+ annotationProviders?: AnnotationProviders | undefined;
9
+ api?: import("@atlaskit/editor-common/types").EditorInjectionAPI<"annotation", {
10
+ pluginConfiguration: AnnotationProviders | undefined;
11
+ sharedState: import("../..").InlineCommentPluginState | undefined;
12
+ dependencies: import("../../annotationPluginType").AnnotationPluginDependencies;
13
+ actions: {
14
+ stripNonExistingAnnotations: (slice: import("prosemirror-model").Slice, state: EditorState) => boolean | undefined;
15
+ setInlineCommentDraftState: (drafting: boolean, inputMethod: import("../../types").InlineCommentInputMethod, targetType?: import("../../types").TargetType | undefined, targetNodeId?: string | undefined, isOpeningMediaCommentFromToolbar?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
16
+ showCommentForBlockNode: (node: import("prosemirror-model").Node | null, viewMethod?: import("@atlaskit/editor-common/analytics").VIEW_METHOD | undefined, isOpeningMediaCommentFromToolbar?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
17
+ hasAnyUnResolvedAnnotationInPage: (state: EditorState) => boolean;
18
+ };
19
+ }> | undefined;
20
+ annotationSelectionType: AnnotationSelectionType;
21
+ bookmark?: SelectionBookmark | undefined;
22
+ }) => void;
@@ -0,0 +1,52 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import { type EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
+ import type { AnnotationPlugin } from '../../annotationPluginType';
5
+ import { AnnotationSelectionType, type AnnotationProviders } from '../../types';
6
+ export declare const isButtonDisabled: ({ state, api, }: {
7
+ state: EditorState | null;
8
+ api?: import("@atlaskit/editor-common/types").EditorInjectionAPI<"annotation", {
9
+ pluginConfiguration: AnnotationProviders | undefined;
10
+ sharedState: import("../..").InlineCommentPluginState | undefined;
11
+ dependencies: import("../../annotationPluginType").AnnotationPluginDependencies;
12
+ actions: {
13
+ stripNonExistingAnnotations: (slice: import("prosemirror-model").Slice, state: EditorState) => boolean | undefined;
14
+ setInlineCommentDraftState: (drafting: boolean, inputMethod: import("../../types").InlineCommentInputMethod, targetType?: import("../../types").TargetType | undefined, targetNodeId?: string | undefined, isOpeningMediaCommentFromToolbar?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
15
+ showCommentForBlockNode: (node: import("prosemirror-model").Node | null, viewMethod?: import("@atlaskit/editor-common/analytics").VIEW_METHOD | undefined, isOpeningMediaCommentFromToolbar?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
16
+ hasAnyUnResolvedAnnotationInPage: (state: EditorState) => boolean;
17
+ };
18
+ }> | undefined;
19
+ }) => boolean;
20
+ export declare const shouldShowCommentButton: ({ state, isVisible, annotationSelectionType, }: {
21
+ state: EditorState | null;
22
+ isVisible?: boolean | undefined;
23
+ annotationSelectionType: AnnotationSelectionType;
24
+ }) => boolean;
25
+ export declare const fireOnClickAnalyticsEvent: ({ api, }: {
26
+ api: ExtractInjectionAPI<AnnotationPlugin>;
27
+ }) => void;
28
+ export declare const fireAnnotationErrorAnalyticsEvent: ({ api, errorReason, }: {
29
+ api: ExtractInjectionAPI<AnnotationPlugin>;
30
+ errorReason: string;
31
+ }) => void;
32
+ export declare const fireCommentButtonViewedAnalyticsEvent: ({ api, isNonTextInlineNodeInludedInComment, annotationSelectionType, }: {
33
+ api?: import("@atlaskit/editor-common/types").EditorInjectionAPI<"annotation", {
34
+ pluginConfiguration: AnnotationProviders | undefined;
35
+ sharedState: import("../..").InlineCommentPluginState | undefined;
36
+ dependencies: import("../../annotationPluginType").AnnotationPluginDependencies;
37
+ actions: {
38
+ stripNonExistingAnnotations: (slice: import("prosemirror-model").Slice, state: EditorState) => boolean | undefined;
39
+ setInlineCommentDraftState: (drafting: boolean, inputMethod: import("../../types").InlineCommentInputMethod, targetType?: import("../../types").TargetType | undefined, targetNodeId?: string | undefined, isOpeningMediaCommentFromToolbar?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
40
+ showCommentForBlockNode: (node: import("prosemirror-model").Node | null, viewMethod?: import("@atlaskit/editor-common/analytics").VIEW_METHOD | undefined, isOpeningMediaCommentFromToolbar?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
41
+ hasAnyUnResolvedAnnotationInPage: (state: EditorState) => boolean;
42
+ };
43
+ }> | undefined;
44
+ isNonTextInlineNodeInludedInComment: boolean;
45
+ annotationSelectionType: AnnotationSelectionType;
46
+ }) => void;
47
+ export declare const startCommentExperience: ({ annotationProviders, api, state, dispatch, }: {
48
+ annotationProviders: AnnotationProviders;
49
+ api: ExtractInjectionAPI<AnnotationPlugin>;
50
+ state: EditorState;
51
+ dispatch: EditorView['dispatch'];
52
+ }) => boolean;
@@ -0,0 +1,5 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
3
+ import type { AnnotationPlugin } from '../annotationPluginType';
4
+ import { type AnnotationProviders } from '../types';
5
+ export declare const getToolbarComponents: (api?: ExtractInjectionAPI<AnnotationPlugin>, annotationProviders?: AnnotationProviders) => RegisterComponent[];
@@ -4,6 +4,7 @@ import type { ConnectivityPlugin } from '@atlaskit/editor-plugin-connectivity';
4
4
  import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
5
5
  import type { EditorViewModeEffectsPlugin } from '@atlaskit/editor-plugin-editor-viewmode-effects';
6
6
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
7
+ import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
7
8
  import type { Slice } from '@atlaskit/editor-prosemirror/model';
8
9
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
9
10
  import type { showInlineCommentForBlockNode } from './editor-commands';
@@ -18,7 +19,8 @@ export type AnnotationPluginDependencies = [
18
19
  OptionalPlugin<EditorViewModeEffectsPlugin>,
19
20
  OptionalPlugin<EditorViewModePlugin>,
20
21
  OptionalPlugin<FeatureFlagsPlugin>,
21
- OptionalPlugin<ConnectivityPlugin>
22
+ OptionalPlugin<ConnectivityPlugin>,
23
+ OptionalPlugin<ToolbarPlugin>
22
24
  ];
23
25
  export type AnnotationPluginOptions = AnnotationProviders;
24
26
  export type AnnotationPlugin = NextEditorPlugin<'annotation', {
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { AnnotationPlugin } from '../../annotationPluginType';
4
+ import { type AnnotationProviders } from '../../types';
5
+ type CommentButtonProps = {
6
+ api?: ExtractInjectionAPI<AnnotationPlugin>;
7
+ annotationProviders?: AnnotationProviders;
8
+ };
9
+ export declare const CommentButton: ({ api, annotationProviders }: CommentButtonProps) => React.JSX.Element | null;
10
+ export {};
@@ -0,0 +1,22 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import { type EditorState, type SelectionBookmark } from '@atlaskit/editor-prosemirror/state';
3
+ import type { AnnotationPlugin } from '../../annotationPluginType';
4
+ import type { AnnotationSelectionType } from '../../types';
5
+ import { type AnnotationProviders } from '../../types';
6
+ export declare const useCommentButtonMount: ({ state, annotationProviders, api, annotationSelectionType, bookmark, }: {
7
+ state: EditorState | null;
8
+ annotationProviders?: AnnotationProviders | undefined;
9
+ api?: import("@atlaskit/editor-common/types").EditorInjectionAPI<"annotation", {
10
+ pluginConfiguration: AnnotationProviders | undefined;
11
+ sharedState: import("../..").InlineCommentPluginState | undefined;
12
+ dependencies: import("../../annotationPluginType").AnnotationPluginDependencies;
13
+ actions: {
14
+ stripNonExistingAnnotations: (slice: import("prosemirror-model").Slice, state: EditorState) => boolean | undefined;
15
+ setInlineCommentDraftState: (drafting: boolean, inputMethod: import("../../types").InlineCommentInputMethod, targetType?: import("../../types").TargetType | undefined, targetNodeId?: string | undefined, isOpeningMediaCommentFromToolbar?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
16
+ showCommentForBlockNode: (node: import("prosemirror-model").Node | null, viewMethod?: import("@atlaskit/editor-common/analytics").VIEW_METHOD | undefined, isOpeningMediaCommentFromToolbar?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
17
+ hasAnyUnResolvedAnnotationInPage: (state: EditorState) => boolean;
18
+ };
19
+ }> | undefined;
20
+ annotationSelectionType: AnnotationSelectionType;
21
+ bookmark?: SelectionBookmark | undefined;
22
+ }) => void;
@@ -0,0 +1,52 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import { type EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
+ import type { AnnotationPlugin } from '../../annotationPluginType';
5
+ import { AnnotationSelectionType, type AnnotationProviders } from '../../types';
6
+ export declare const isButtonDisabled: ({ state, api, }: {
7
+ state: EditorState | null;
8
+ api?: import("@atlaskit/editor-common/types").EditorInjectionAPI<"annotation", {
9
+ pluginConfiguration: AnnotationProviders | undefined;
10
+ sharedState: import("../..").InlineCommentPluginState | undefined;
11
+ dependencies: import("../../annotationPluginType").AnnotationPluginDependencies;
12
+ actions: {
13
+ stripNonExistingAnnotations: (slice: import("prosemirror-model").Slice, state: EditorState) => boolean | undefined;
14
+ setInlineCommentDraftState: (drafting: boolean, inputMethod: import("../../types").InlineCommentInputMethod, targetType?: import("../../types").TargetType | undefined, targetNodeId?: string | undefined, isOpeningMediaCommentFromToolbar?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
15
+ showCommentForBlockNode: (node: import("prosemirror-model").Node | null, viewMethod?: import("@atlaskit/editor-common/analytics").VIEW_METHOD | undefined, isOpeningMediaCommentFromToolbar?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
16
+ hasAnyUnResolvedAnnotationInPage: (state: EditorState) => boolean;
17
+ };
18
+ }> | undefined;
19
+ }) => boolean;
20
+ export declare const shouldShowCommentButton: ({ state, isVisible, annotationSelectionType, }: {
21
+ state: EditorState | null;
22
+ isVisible?: boolean | undefined;
23
+ annotationSelectionType: AnnotationSelectionType;
24
+ }) => boolean;
25
+ export declare const fireOnClickAnalyticsEvent: ({ api, }: {
26
+ api: ExtractInjectionAPI<AnnotationPlugin>;
27
+ }) => void;
28
+ export declare const fireAnnotationErrorAnalyticsEvent: ({ api, errorReason, }: {
29
+ api: ExtractInjectionAPI<AnnotationPlugin>;
30
+ errorReason: string;
31
+ }) => void;
32
+ export declare const fireCommentButtonViewedAnalyticsEvent: ({ api, isNonTextInlineNodeInludedInComment, annotationSelectionType, }: {
33
+ api?: import("@atlaskit/editor-common/types").EditorInjectionAPI<"annotation", {
34
+ pluginConfiguration: AnnotationProviders | undefined;
35
+ sharedState: import("../..").InlineCommentPluginState | undefined;
36
+ dependencies: import("../../annotationPluginType").AnnotationPluginDependencies;
37
+ actions: {
38
+ stripNonExistingAnnotations: (slice: import("prosemirror-model").Slice, state: EditorState) => boolean | undefined;
39
+ setInlineCommentDraftState: (drafting: boolean, inputMethod: import("../../types").InlineCommentInputMethod, targetType?: import("../../types").TargetType | undefined, targetNodeId?: string | undefined, isOpeningMediaCommentFromToolbar?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
40
+ showCommentForBlockNode: (node: import("prosemirror-model").Node | null, viewMethod?: import("@atlaskit/editor-common/analytics").VIEW_METHOD | undefined, isOpeningMediaCommentFromToolbar?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
41
+ hasAnyUnResolvedAnnotationInPage: (state: EditorState) => boolean;
42
+ };
43
+ }> | undefined;
44
+ isNonTextInlineNodeInludedInComment: boolean;
45
+ annotationSelectionType: AnnotationSelectionType;
46
+ }) => void;
47
+ export declare const startCommentExperience: ({ annotationProviders, api, state, dispatch, }: {
48
+ annotationProviders: AnnotationProviders;
49
+ api: ExtractInjectionAPI<AnnotationPlugin>;
50
+ state: EditorState;
51
+ dispatch: EditorView['dispatch'];
52
+ }) => boolean;
@@ -0,0 +1,5 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
3
+ import type { AnnotationPlugin } from '../annotationPluginType';
4
+ import { type AnnotationProviders } from '../types';
5
+ export declare const getToolbarComponents: (api?: ExtractInjectionAPI<AnnotationPlugin>, annotationProviders?: AnnotationProviders) => RegisterComponent[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-annotation",
3
- "version": "3.1.4",
3
+ "version": "3.2.0",
4
4
  "description": "Annotation plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -36,15 +36,19 @@
36
36
  "@atlaskit/editor-plugin-connectivity": "^3.1.0",
37
37
  "@atlaskit/editor-plugin-editor-viewmode-effects": "^3.0.0",
38
38
  "@atlaskit/editor-plugin-feature-flags": "^2.0.0",
39
+ "@atlaskit/editor-plugin-toolbar": "^0.0.6",
39
40
  "@atlaskit/editor-prosemirror": "7.0.0",
41
+ "@atlaskit/editor-toolbar": "^0.0.10",
42
+ "@atlaskit/editor-toolbar-model": "^0.0.4",
40
43
  "@atlaskit/icon": "^27.9.0",
41
44
  "@atlaskit/onboarding": "^14.3.0",
42
45
  "@atlaskit/platform-feature-flags": "^1.1.0",
43
- "@atlaskit/tmp-editor-statsig": "^9.23.0",
44
- "@babel/runtime": "^7.0.0"
46
+ "@atlaskit/tmp-editor-statsig": "^9.25.0",
47
+ "@babel/runtime": "^7.0.0",
48
+ "react-intl-next": "npm:react-intl@^5.18.1"
45
49
  },
46
50
  "peerDependencies": {
47
- "@atlaskit/editor-common": "^107.16.0",
51
+ "@atlaskit/editor-common": "^107.18.0",
48
52
  "react": "^18.2.0",
49
53
  "react-dom": "^18.2.0"
50
54
  },
@@ -54,7 +58,6 @@
54
58
  "@atlaskit/ssr": "workspace:^",
55
59
  "@atlaskit/visual-regression": "workspace:^",
56
60
  "@testing-library/react": "^13.4.0",
57
- "typescript": "~5.4.2",
58
61
  "wait-for-expect": "^1.2.0"
59
62
  },
60
63
  "techstack": {