@atlaskit/editor-plugin-annotation 1.2.0 → 1.2.2

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,17 @@
1
1
  # @atlaskit/editor-plugin-annotation
2
2
 
3
+ ## 1.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#79658](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/79658) [`4b195011d7c1`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4b195011d7c1) - ED-22112 support remove annotation from supported nodes
8
+
9
+ ## 1.2.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#78577](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/78577) [`207fbd3685dc`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/207fbd3685dc) - ED-22111 add supported nodes option to annotation plugin
14
+
3
15
  ## 1.2.0
4
16
 
5
17
  ### Minor Changes
@@ -8,6 +8,7 @@ exports.updateMouseState = exports.updateInlineCommentResolvedState = exports.se
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _adfSchema = require("@atlaskit/adf-schema");
10
10
  var _analytics = require("@atlaskit/editor-common/analytics");
11
+ var _state = require("@atlaskit/editor-prosemirror/state");
11
12
  var _pluginFactory = require("../pm-plugins/plugin-factory");
12
13
  var _types = require("../pm-plugins/types");
13
14
  var _types2 = require("../types");
@@ -38,10 +39,48 @@ var clearDirtyMark = exports.clearDirtyMark = function clearDirtyMark() {
38
39
  type: _types.ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK
39
40
  });
40
41
  };
42
+ var removeInlineCommentFromNode = function removeInlineCommentFromNode(id) {
43
+ var supportedBlockNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
44
+ var state = arguments.length > 2 ? arguments[2] : undefined;
45
+ var dispatch = arguments.length > 3 ? arguments[3] : undefined;
46
+ var tr = state.tr,
47
+ selection = state.selection;
48
+ if (selection instanceof _state.NodeSelection && (0, _utils.isSupportedBlockNode)(selection.node, supportedBlockNodes)) {
49
+ var $from = selection.$from;
50
+ var currNode = selection.node;
51
+ var from = $from.start();
52
+
53
+ // for media annotation, the selection is on media Single
54
+ if (currNode.type === state.schema.nodes.mediaSingle && currNode.firstChild) {
55
+ currNode = currNode.firstChild;
56
+ from = from + 1;
57
+ }
58
+ var annotationMarkType = state.schema.marks.annotation;
59
+ var hasAnnotation = currNode.marks.some(function (mark) {
60
+ return mark.type === annotationMarkType;
61
+ });
62
+ if (!hasAnnotation) {
63
+ return false;
64
+ }
65
+ tr.removeNodeMark(from, annotationMarkType.create({
66
+ id: id,
67
+ type: _adfSchema.AnnotationTypes.INLINE_COMMENT
68
+ }));
69
+ if (dispatch) {
70
+ dispatch(tr);
71
+ }
72
+ return true;
73
+ }
74
+ return false;
75
+ };
41
76
  var removeInlineCommentNearSelection = exports.removeInlineCommentNearSelection = function removeInlineCommentNearSelection(id) {
77
+ var supportedNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
42
78
  return function (state, dispatch) {
43
79
  var tr = state.tr,
44
80
  $from = state.selection.$from;
81
+ if (removeInlineCommentFromNode(id, supportedNodes, state, dispatch)) {
82
+ return true;
83
+ }
45
84
  var annotationMarkType = state.schema.marks.annotation;
46
85
  var hasAnnotation = $from.marks().some(function (mark) {
47
86
  return mark.type === annotationMarkType;
@@ -14,7 +14,7 @@ var _react = _interopRequireDefault(require("react"));
14
14
  var _reactNodeView = _interopRequireDefault(require("@atlaskit/editor-common/react-node-view"));
15
15
  var _styles = require("@atlaskit/editor-common/styles");
16
16
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
17
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
17
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
18
18
  var AnnotationNodeView = exports.AnnotationNodeView = /*#__PURE__*/function (_ReactNodeView) {
19
19
  (0, _inherits2.default)(AnnotationNodeView, _ReactNodeView);
20
20
  var _super = _createSuper(AnnotationNodeView);
@@ -19,6 +19,7 @@ var buildToolbar = exports.buildToolbar = function buildToolbar(editorAnalyticsA
19
19
  return function (state, intl) {
20
20
  var isToolbarAbove = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
21
21
  var isCommentOnMediaOn = arguments.length > 3 ? arguments[3] : undefined;
22
+ var _supportedNodes = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
22
23
  var schema = state.schema;
23
24
  var selectionValid = (0, _utils2.isSelectionValid)(state, isCommentOnMediaOn);
24
25
  var isMediaSelected = isCommentOnMediaOn && (0, _mediaSingle.currentMediaNodeWithPos)(state);
@@ -57,7 +58,6 @@ var buildToolbar = exports.buildToolbar = function buildToolbar(editorAnalyticsA
57
58
  },
58
59
  supportsViewMode: true // TODO: MODES-3950 Clean up this floating toolbar view mode logic
59
60
  };
60
-
61
61
  var annotation = schema.marks.annotation;
62
62
  var validNodes = Object.keys(schema.nodes).reduce(function (acc, current) {
63
63
  var type = schema.nodes[current];
@@ -12,7 +12,7 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
12
12
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
13
  var _react = _interopRequireDefault(require("react"));
14
14
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
15
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
16
16
  // eslint-disable-next-line @repo/internal/react/no-class-components
17
17
  var AnnotationViewWrapper = exports.AnnotationViewWrapper = /*#__PURE__*/function (_React$PureComponent) {
18
18
  (0, _inherits2.default)(AnnotationViewWrapper, _React$PureComponent);
@@ -137,7 +137,7 @@ function InlineCommentView(_ref) {
137
137
  annotations: activeAnnotations,
138
138
  dom: dom,
139
139
  onDelete: function onDelete(id) {
140
- return (0, _commands.removeInlineCommentNearSelection)(id)(state, dispatch);
140
+ return (0, _commands.removeInlineCommentNearSelection)(id, inlineCommentProvider.supportedBlockNodes)(state, dispatch);
141
141
  },
142
142
  onResolve: function onResolve(id) {
143
143
  return (0, _commands.updateInlineCommentResolvedState)(editorAnalyticsAPI)((0, _defineProperty2.default)({}, id, true), _analytics.RESOLVE_METHOD.COMPONENT)(editorView.state, editorView.dispatch);
package/dist/cjs/utils.js CHANGED
@@ -23,7 +23,7 @@ exports.hasInvalidNodes = void 0;
23
23
  exports.hasInvalidWhitespaceNode = hasInvalidWhitespaceNode;
24
24
  exports.inlineCommentPluginKey = void 0;
25
25
  exports.isSelectedAnnotationsChanged = isSelectedAnnotationsChanged;
26
- exports.isSelectionValid = void 0;
26
+ exports.isSupportedBlockNode = exports.isSelectionValid = void 0;
27
27
  exports.stripNonExistingAnnotations = stripNonExistingAnnotations;
28
28
  exports.surroundingMarks = void 0;
29
29
  var _adfSchema = require("@atlaskit/adf-schema");
@@ -237,6 +237,7 @@ var getDraftCommandAnalyticsPayload = exports.getDraftCommandAnalyticsPayload =
237
237
  };
238
238
  var isSelectionValid = exports.isSelectionValid = function isSelectionValid(state, isCommentOnMediaOn) {
239
239
  var _currentMediaNodeWith;
240
+ var _supportedNodes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
240
241
  var selection = state.selection;
241
242
  var _ref3 = getPluginState(state) || {},
242
243
  disallowOnWhitespace = _ref3.disallowOnWhitespace;
@@ -298,6 +299,10 @@ function isEmptyTextSelection(selection, schema) {
298
299
  });
299
300
  return !hasContent;
300
301
  }
302
+ var isSupportedBlockNode = exports.isSupportedBlockNode = function isSupportedBlockNode(node) {
303
+ var supportedBlockNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
304
+ return supportedBlockNodes.indexOf(node.type.name) >= 0 || node.type.name === 'mediaSingle' && supportedBlockNodes.indexOf('media') >= 0;
305
+ };
301
306
 
302
307
  /**
303
308
  * Checks if any of the nodes in a given selection are completely whitespace
@@ -1,9 +1,10 @@
1
1
  import { AnnotationTypes } from '@atlaskit/adf-schema';
2
2
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
4
  import { createCommand } from '../pm-plugins/plugin-factory';
4
5
  import { ACTIONS } from '../pm-plugins/types';
5
6
  import { AnnotationSelectionType } from '../types';
6
- import { getPluginState, isSelectionValid } from '../utils';
7
+ import { getPluginState, isSelectionValid, isSupportedBlockNode } from '../utils';
7
8
  import transform from './transform';
8
9
  export const updateInlineCommentResolvedState = editorAnalyticsAPI => (partialNewState, resolveMethod) => {
9
10
  const command = {
@@ -22,13 +23,51 @@ export const closeComponent = () => createCommand({
22
23
  export const clearDirtyMark = () => createCommand({
23
24
  type: ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK
24
25
  });
25
- export const removeInlineCommentNearSelection = id => (state, dispatch) => {
26
+ const removeInlineCommentFromNode = (id, supportedBlockNodes = [], state, dispatch) => {
27
+ const {
28
+ tr,
29
+ selection
30
+ } = state;
31
+ if (selection instanceof NodeSelection && isSupportedBlockNode(selection.node, supportedBlockNodes)) {
32
+ const {
33
+ $from
34
+ } = selection;
35
+ let currNode = selection.node;
36
+ let from = $from.start();
37
+
38
+ // for media annotation, the selection is on media Single
39
+ if (currNode.type === state.schema.nodes.mediaSingle && currNode.firstChild) {
40
+ currNode = currNode.firstChild;
41
+ from = from + 1;
42
+ }
43
+ const {
44
+ annotation: annotationMarkType
45
+ } = state.schema.marks;
46
+ const hasAnnotation = currNode.marks.some(mark => mark.type === annotationMarkType);
47
+ if (!hasAnnotation) {
48
+ return false;
49
+ }
50
+ tr.removeNodeMark(from, annotationMarkType.create({
51
+ id,
52
+ type: AnnotationTypes.INLINE_COMMENT
53
+ }));
54
+ if (dispatch) {
55
+ dispatch(tr);
56
+ }
57
+ return true;
58
+ }
59
+ return false;
60
+ };
61
+ export const removeInlineCommentNearSelection = (id, supportedNodes = []) => (state, dispatch) => {
26
62
  const {
27
63
  tr,
28
64
  selection: {
29
65
  $from
30
66
  }
31
67
  } = state;
68
+ if (removeInlineCommentFromNode(id, supportedNodes, state, dispatch)) {
69
+ return true;
70
+ }
32
71
  const {
33
72
  annotation: annotationMarkType
34
73
  } = state.schema.marks;
@@ -8,7 +8,7 @@ import CommentIcon from '@atlaskit/icon/glyph/comment';
8
8
  import { setInlineCommentDraftState } from './commands';
9
9
  import { AnnotationSelectionType, AnnotationTestIds } from './types';
10
10
  import { isSelectionValid } from './utils';
11
- export const buildToolbar = editorAnalyticsAPI => (state, intl, isToolbarAbove = false, isCommentOnMediaOn) => {
11
+ export const buildToolbar = editorAnalyticsAPI => (state, intl, isToolbarAbove = false, isCommentOnMediaOn, _supportedNodes = []) => {
12
12
  const {
13
13
  schema
14
14
  } = state;
@@ -49,7 +49,6 @@ export const buildToolbar = editorAnalyticsAPI => (state, intl, isToolbarAbove =
49
49
  },
50
50
  supportsViewMode: true // TODO: MODES-3950 Clean up this floating toolbar view mode logic
51
51
  };
52
-
53
52
  const {
54
53
  annotation
55
54
  } = schema.marks;
@@ -134,7 +134,7 @@ export function InlineCommentView({
134
134
  annotationsList: annotationsList,
135
135
  annotations: activeAnnotations,
136
136
  dom: dom,
137
- onDelete: id => removeInlineCommentNearSelection(id)(state, dispatch),
137
+ onDelete: id => removeInlineCommentNearSelection(id, inlineCommentProvider.supportedBlockNodes)(state, dispatch),
138
138
  onResolve: id => updateInlineCommentResolvedState(editorAnalyticsAPI)({
139
139
  [id]: true
140
140
  }, RESOLVE_METHOD.COMPONENT)(editorView.state, editorView.dispatch),
@@ -194,7 +194,7 @@ export const getDraftCommandAnalyticsPayload = (drafting, inputMethod) => {
194
194
  };
195
195
  return payload;
196
196
  };
197
- export const isSelectionValid = (state, isCommentOnMediaOn) => {
197
+ export const isSelectionValid = (state, isCommentOnMediaOn, _supportedNodes = []) => {
198
198
  var _currentMediaNodeWith;
199
199
  const {
200
200
  selection
@@ -263,6 +263,9 @@ function isEmptyTextSelection(selection, schema) {
263
263
  });
264
264
  return !hasContent;
265
265
  }
266
+ export const isSupportedBlockNode = (node, supportedBlockNodes = []) => {
267
+ return supportedBlockNodes.indexOf(node.type.name) >= 0 || node.type.name === 'mediaSingle' && supportedBlockNodes.indexOf('media') >= 0;
268
+ };
266
269
 
267
270
  /**
268
271
  * Checks if any of the nodes in a given selection are completely whitespace
@@ -1,10 +1,11 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { AnnotationTypes } from '@atlaskit/adf-schema';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
4
5
  import { createCommand } from '../pm-plugins/plugin-factory';
5
6
  import { ACTIONS } from '../pm-plugins/types';
6
7
  import { AnnotationSelectionType } from '../types';
7
- import { getPluginState, isSelectionValid } from '../utils';
8
+ import { getPluginState, isSelectionValid, isSupportedBlockNode } from '../utils';
8
9
  import transform from './transform';
9
10
  export var updateInlineCommentResolvedState = function updateInlineCommentResolvedState(editorAnalyticsAPI) {
10
11
  return function (partialNewState, resolveMethod) {
@@ -31,10 +32,48 @@ export var clearDirtyMark = function clearDirtyMark() {
31
32
  type: ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK
32
33
  });
33
34
  };
35
+ var removeInlineCommentFromNode = function removeInlineCommentFromNode(id) {
36
+ var supportedBlockNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
37
+ var state = arguments.length > 2 ? arguments[2] : undefined;
38
+ var dispatch = arguments.length > 3 ? arguments[3] : undefined;
39
+ var tr = state.tr,
40
+ selection = state.selection;
41
+ if (selection instanceof NodeSelection && isSupportedBlockNode(selection.node, supportedBlockNodes)) {
42
+ var $from = selection.$from;
43
+ var currNode = selection.node;
44
+ var from = $from.start();
45
+
46
+ // for media annotation, the selection is on media Single
47
+ if (currNode.type === state.schema.nodes.mediaSingle && currNode.firstChild) {
48
+ currNode = currNode.firstChild;
49
+ from = from + 1;
50
+ }
51
+ var annotationMarkType = state.schema.marks.annotation;
52
+ var hasAnnotation = currNode.marks.some(function (mark) {
53
+ return mark.type === annotationMarkType;
54
+ });
55
+ if (!hasAnnotation) {
56
+ return false;
57
+ }
58
+ tr.removeNodeMark(from, annotationMarkType.create({
59
+ id: id,
60
+ type: AnnotationTypes.INLINE_COMMENT
61
+ }));
62
+ if (dispatch) {
63
+ dispatch(tr);
64
+ }
65
+ return true;
66
+ }
67
+ return false;
68
+ };
34
69
  export var removeInlineCommentNearSelection = function removeInlineCommentNearSelection(id) {
70
+ var supportedNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
35
71
  return function (state, dispatch) {
36
72
  var tr = state.tr,
37
73
  $from = state.selection.$from;
74
+ if (removeInlineCommentFromNode(id, supportedNodes, state, dispatch)) {
75
+ return true;
76
+ }
38
77
  var annotationMarkType = state.schema.marks.annotation;
39
78
  var hasAnnotation = $from.marks().some(function (mark) {
40
79
  return mark.type === annotationMarkType;
@@ -4,7 +4,7 @@ import _inherits from "@babel/runtime/helpers/inherits";
4
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
6
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
7
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
7
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
8
  import React from 'react';
9
9
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
10
10
  import { AnnotationSharedClassNames } from '@atlaskit/editor-common/styles';
@@ -12,6 +12,7 @@ export var buildToolbar = function buildToolbar(editorAnalyticsAPI) {
12
12
  return function (state, intl) {
13
13
  var isToolbarAbove = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
14
14
  var isCommentOnMediaOn = arguments.length > 3 ? arguments[3] : undefined;
15
+ var _supportedNodes = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
15
16
  var schema = state.schema;
16
17
  var selectionValid = isSelectionValid(state, isCommentOnMediaOn);
17
18
  var isMediaSelected = isCommentOnMediaOn && currentMediaNodeWithPos(state);
@@ -50,7 +51,6 @@ export var buildToolbar = function buildToolbar(editorAnalyticsAPI) {
50
51
  },
51
52
  supportsViewMode: true // TODO: MODES-3950 Clean up this floating toolbar view mode logic
52
53
  };
53
-
54
54
  var annotation = schema.marks.annotation;
55
55
  var validNodes = Object.keys(schema.nodes).reduce(function (acc, current) {
56
56
  var type = schema.nodes[current];
@@ -4,7 +4,7 @@ import _inherits from "@babel/runtime/helpers/inherits";
4
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
6
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
7
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
7
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
8
  import React from 'react';
9
9
  // eslint-disable-next-line @repo/internal/react/no-class-components
10
10
  export var AnnotationViewWrapper = /*#__PURE__*/function (_React$PureComponent) {
@@ -130,7 +130,7 @@ export function InlineCommentView(_ref) {
130
130
  annotations: activeAnnotations,
131
131
  dom: dom,
132
132
  onDelete: function onDelete(id) {
133
- return removeInlineCommentNearSelection(id)(state, dispatch);
133
+ return removeInlineCommentNearSelection(id, inlineCommentProvider.supportedBlockNodes)(state, dispatch);
134
134
  },
135
135
  onResolve: function onResolve(id) {
136
136
  return updateInlineCommentResolvedState(editorAnalyticsAPI)(_defineProperty({}, id, true), RESOLVE_METHOD.COMPONENT)(editorView.state, editorView.dispatch);
package/dist/esm/utils.js CHANGED
@@ -210,6 +210,7 @@ export var getDraftCommandAnalyticsPayload = function getDraftCommandAnalyticsPa
210
210
  };
211
211
  export var isSelectionValid = function isSelectionValid(state, isCommentOnMediaOn) {
212
212
  var _currentMediaNodeWith;
213
+ var _supportedNodes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
213
214
  var selection = state.selection;
214
215
  var _ref3 = getPluginState(state) || {},
215
216
  disallowOnWhitespace = _ref3.disallowOnWhitespace;
@@ -271,6 +272,10 @@ function isEmptyTextSelection(selection, schema) {
271
272
  });
272
273
  return !hasContent;
273
274
  }
275
+ export var isSupportedBlockNode = function isSupportedBlockNode(node) {
276
+ var supportedBlockNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
277
+ return supportedBlockNodes.indexOf(node.type.name) >= 0 || node.type.name === 'mediaSingle' && supportedBlockNodes.indexOf('media') >= 0;
278
+ };
274
279
 
275
280
  /**
276
281
  * Checks if any of the nodes in a given selection are completely whitespace
@@ -6,7 +6,7 @@ import type { AnnotationPlugin, InlineCommentInputMethod, TargetType } from '../
6
6
  export declare const updateInlineCommentResolvedState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (partialNewState: InlineCommentMap, resolveMethod?: RESOLVE_METHOD) => Command;
7
7
  export declare const closeComponent: () => Command;
8
8
  export declare const clearDirtyMark: () => Command;
9
- export declare const removeInlineCommentNearSelection: (id: string) => Command;
9
+ export declare const removeInlineCommentNearSelection: (id: string, supportedNodes?: string[]) => Command;
10
10
  export declare const setInlineCommentDraftState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (drafting: boolean, inputMethod?: InlineCommentInputMethod, targetType?: TargetType, isCommentOnMediaOn?: boolean) => Command;
11
11
  export declare const addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string) => Command;
12
12
  export declare const updateMouseState: (mouseData: InlineCommentMouseData) => Command;
@@ -2,4 +2,4 @@ import type { IntlShape } from 'react-intl-next';
2
2
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
3
  import type { FloatingToolbarConfig } from '@atlaskit/editor-common/types';
4
4
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
- export declare const buildToolbar: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (state: EditorState, intl: IntlShape, isToolbarAbove?: boolean, isCommentOnMediaOn?: boolean) => FloatingToolbarConfig | undefined;
5
+ export declare const buildToolbar: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (state: EditorState, intl: IntlShape, isToolbarAbove?: boolean, isCommentOnMediaOn?: boolean, _supportedNodes?: string[]) => FloatingToolbarConfig | undefined;
@@ -97,6 +97,16 @@ export type InlineCommentAnnotationProvider = AnnotationTypeProvider<AnnotationT
97
97
  createComponent?: React.ComponentType<InlineCommentCreateComponentProps>;
98
98
  viewComponent?: React.ComponentType<InlineCommentViewComponentProps>;
99
99
  isToolbarAbove?: boolean;
100
+ /**
101
+ * @experimental Still under development. Do not use.
102
+ *
103
+ * A list of supported editor node names for inline comment,
104
+ * Note 1: value is the type name of the node, e.g. media, mediaInline
105
+ * Invalid node names, nodes does not support annotation
106
+ * or nodes not supported by current ADF schema will be ignored.
107
+ * Note 2: text is supported by default.
108
+ */
109
+ supportedBlockNodes?: string[];
100
110
  };
101
111
  export interface AnnotationProviders {
102
112
  inlineComment: InlineCommentAnnotationProvider;
@@ -28,8 +28,9 @@ export declare const getPluginState: (state: EditorState) => InlineCommentPlugin
28
28
  * get payload for the open/close analytics event
29
29
  */
30
30
  export declare const getDraftCommandAnalyticsPayload: (drafting: boolean, inputMethod: InlineCommentInputMethod) => AnalyticsEventPayloadCallback;
31
- export declare const isSelectionValid: (state: EditorState, isCommentOnMediaOn?: boolean) => AnnotationSelectionType;
31
+ export declare const isSelectionValid: (state: EditorState, isCommentOnMediaOn?: boolean, _supportedNodes?: string[]) => AnnotationSelectionType;
32
32
  export declare const hasInvalidNodes: (state: EditorState) => boolean;
33
+ export declare const isSupportedBlockNode: (node: Node, supportedBlockNodes?: string[]) => boolean;
33
34
  /**
34
35
  * Checks if any of the nodes in a given selection are completely whitespace
35
36
  * This is to conform to Confluence annotation specifications
@@ -6,7 +6,7 @@ import type { AnnotationPlugin, InlineCommentInputMethod, TargetType } from '../
6
6
  export declare const updateInlineCommentResolvedState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (partialNewState: InlineCommentMap, resolveMethod?: RESOLVE_METHOD) => Command;
7
7
  export declare const closeComponent: () => Command;
8
8
  export declare const clearDirtyMark: () => Command;
9
- export declare const removeInlineCommentNearSelection: (id: string) => Command;
9
+ export declare const removeInlineCommentNearSelection: (id: string, supportedNodes?: string[]) => Command;
10
10
  export declare const setInlineCommentDraftState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (drafting: boolean, inputMethod?: InlineCommentInputMethod, targetType?: TargetType, isCommentOnMediaOn?: boolean) => Command;
11
11
  export declare const addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string) => Command;
12
12
  export declare const updateMouseState: (mouseData: InlineCommentMouseData) => Command;
@@ -2,4 +2,4 @@ import type { IntlShape } from 'react-intl-next';
2
2
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
3
  import type { FloatingToolbarConfig } from '@atlaskit/editor-common/types';
4
4
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
- export declare const buildToolbar: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (state: EditorState, intl: IntlShape, isToolbarAbove?: boolean, isCommentOnMediaOn?: boolean) => FloatingToolbarConfig | undefined;
5
+ export declare const buildToolbar: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (state: EditorState, intl: IntlShape, isToolbarAbove?: boolean, isCommentOnMediaOn?: boolean, _supportedNodes?: string[]) => FloatingToolbarConfig | undefined;
@@ -97,6 +97,16 @@ export type InlineCommentAnnotationProvider = AnnotationTypeProvider<AnnotationT
97
97
  createComponent?: React.ComponentType<InlineCommentCreateComponentProps>;
98
98
  viewComponent?: React.ComponentType<InlineCommentViewComponentProps>;
99
99
  isToolbarAbove?: boolean;
100
+ /**
101
+ * @experimental Still under development. Do not use.
102
+ *
103
+ * A list of supported editor node names for inline comment,
104
+ * Note 1: value is the type name of the node, e.g. media, mediaInline
105
+ * Invalid node names, nodes does not support annotation
106
+ * or nodes not supported by current ADF schema will be ignored.
107
+ * Note 2: text is supported by default.
108
+ */
109
+ supportedBlockNodes?: string[];
100
110
  };
101
111
  export interface AnnotationProviders {
102
112
  inlineComment: InlineCommentAnnotationProvider;
@@ -28,8 +28,9 @@ export declare const getPluginState: (state: EditorState) => InlineCommentPlugin
28
28
  * get payload for the open/close analytics event
29
29
  */
30
30
  export declare const getDraftCommandAnalyticsPayload: (drafting: boolean, inputMethod: InlineCommentInputMethod) => AnalyticsEventPayloadCallback;
31
- export declare const isSelectionValid: (state: EditorState, isCommentOnMediaOn?: boolean) => AnnotationSelectionType;
31
+ export declare const isSelectionValid: (state: EditorState, isCommentOnMediaOn?: boolean, _supportedNodes?: string[]) => AnnotationSelectionType;
32
32
  export declare const hasInvalidNodes: (state: EditorState) => boolean;
33
+ export declare const isSupportedBlockNode: (node: Node, supportedBlockNodes?: string[]) => boolean;
33
34
  /**
34
35
  * Checks if any of the nodes in a given selection are completely whitespace
35
36
  * This is to conform to Confluence annotation specifications
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-annotation",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Annotation plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",