@atlaskit/editor-plugin-annotation 1.3.2 → 1.4.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,11 @@
1
1
  # @atlaskit/editor-plugin-annotation
2
2
 
3
+ ## 1.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#81394](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81394) [`2798f5546fb7`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2798f5546fb7) - [ux] ED-22118 implemented annotation style for block node (media)
8
+
3
9
  ## 1.3.2
4
10
 
5
11
  ### Patch Changes
@@ -11,6 +11,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
11
11
  var _adfSchema = require("@atlaskit/adf-schema");
12
12
  var _analytics = require("@atlaskit/editor-common/analytics");
13
13
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
14
+ var _styles = require("@atlaskit/editor-common/styles");
14
15
  var _view = require("@atlaskit/editor-prosemirror/view");
15
16
  var _commands = require("../commands");
16
17
  var _nodeviews = require("../nodeviews");
@@ -223,18 +224,30 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
223
224
  var decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : _view.DecorationSet.empty;
224
225
  var focusDecorations = [];
225
226
  state.doc.descendants(function (node, pos) {
227
+ var _provider$supportedBl;
228
+ var isSupportedBlockNode = node.isBlock && ((_provider$supportedBl = provider.supportedBlockNodes) === null || _provider$supportedBl === void 0 ? void 0 : _provider$supportedBl.includes(node.type.name));
226
229
  node.marks.filter(function (mark) {
227
230
  return mark.type === state.schema.marks.annotation;
228
231
  }).forEach(function (mark) {
229
- var isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
230
- return selectedAnnotation.id === mark.attrs.id;
231
- }));
232
- var isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
233
232
  if (isVisible) {
234
- focusDecorations.push(_view.Decoration.inline(pos, pos + node.nodeSize, {
235
- class: "".concat((0, _nodeviews.getAnnotationViewClassname)(isUnresolved, isSelected), " ").concat(isUnresolved),
236
- nodeName: 'span'
237
- }));
233
+ var isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
234
+ if (isSupportedBlockNode) {
235
+ var isBlockNodeSelected = (0, _utils.isCurrentBlockNodeSelected)(state, node);
236
+ var attrs = isUnresolved ? {
237
+ class: isBlockNodeSelected ? "".concat(_styles.BlockAnnotationSharedClassNames.focus) : "".concat(_styles.BlockAnnotationSharedClassNames.blur)
238
+ } : {};
239
+ focusDecorations.push(_view.Decoration.node(pos, pos + node.nodeSize, attrs, {
240
+ key: _utils.decorationKey.block
241
+ }));
242
+ } else {
243
+ var isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
244
+ return selectedAnnotation.id === mark.attrs.id;
245
+ }));
246
+ focusDecorations.push(_view.Decoration.inline(pos, pos + node.nodeSize, {
247
+ class: "".concat((0, _nodeviews.getAnnotationViewClassname)(isUnresolved, isSelected), " ").concat(isUnresolved),
248
+ nodeName: 'span'
249
+ }));
250
+ }
238
251
  }
239
252
  });
240
253
  });
package/dist/cjs/utils.js CHANGED
@@ -21,7 +21,7 @@ Object.defineProperty(exports, "hasAnnotationMark", {
21
21
  });
22
22
  exports.hasInvalidNodes = void 0;
23
23
  exports.hasInvalidWhitespaceNode = hasInvalidWhitespaceNode;
24
- exports.inlineCommentPluginKey = void 0;
24
+ exports.isCurrentBlockNodeSelected = exports.inlineCommentPluginKey = void 0;
25
25
  exports.isSelectedAnnotationsChanged = isSelectedAnnotationsChanged;
26
26
  exports.resolveDraftBookmark = exports.isSupportedBlockNode = exports.isSelectionValid = void 0;
27
27
  exports.stripNonExistingAnnotations = stripNonExistingAnnotations;
@@ -155,6 +155,18 @@ var getAnnotationViewKey = exports.getAnnotationViewKey = function getAnnotation
155
155
  }).join('_');
156
156
  return "view-annotation-wrapper_".concat(keys);
157
157
  };
158
+ var isCurrentBlockNodeSelected = exports.isCurrentBlockNodeSelected = function isCurrentBlockNodeSelected(state, node) {
159
+ var selection = state.selection;
160
+ if (selection instanceof _state.NodeSelection) {
161
+ if (selection.node === node) {
162
+ return true;
163
+ }
164
+ if (node.type.name === 'media' && selection.node.firstChild === node) {
165
+ return true;
166
+ }
167
+ }
168
+ return false;
169
+ };
158
170
  var findAnnotationsInSelection = exports.findAnnotationsInSelection = function findAnnotationsInSelection(selection, doc) {
159
171
  var empty = selection.empty,
160
172
  $anchor = selection.$anchor,
@@ -169,7 +181,7 @@ var findAnnotationsInSelection = exports.findAnnotationsInSelection = function f
169
181
  }
170
182
  var annotationMark = doc.type.schema.marks.annotation;
171
183
  var nodeBefore = $anchor.nodeBefore;
172
- var anchorAnnotationMarks = node && node.marks || [];
184
+ var anchorAnnotationMarks = (node === null || node === void 0 ? void 0 : node.marks) || [];
173
185
  var marks = [];
174
186
  if (annotationMark.isInSet(anchorAnnotationMarks)) {
175
187
  marks = anchorAnnotationMarks;
@@ -1,10 +1,11 @@
1
1
  import { AnnotationTypes } from '@atlaskit/adf-schema';
2
2
  import { RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
+ import { BlockAnnotationSharedClassNames } from '@atlaskit/editor-common/styles';
4
5
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
6
  import { clearDirtyMark, closeComponent, setInlineCommentsVisibility, setSelectedAnnotation, updateInlineCommentResolvedState, updateMouseState } from '../commands';
6
7
  import { AnnotationNodeView, getAnnotationViewClassname } from '../nodeviews';
7
- import { getAllAnnotations, getPluginState, inlineCommentPluginKey } from '../utils';
8
+ import { decorationKey, getAllAnnotations, getPluginState, inlineCommentPluginKey, isCurrentBlockNodeSelected } from '../utils';
8
9
  import { createPluginState } from './plugin-factory';
9
10
  const fetchProviderStates = async (provider, annotationIds) => {
10
11
  const data = await provider.getState(annotationIds);
@@ -163,14 +164,26 @@ export const inlineCommentPlugin = options => {
163
164
  let decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : DecorationSet.empty;
164
165
  const focusDecorations = [];
165
166
  state.doc.descendants((node, pos) => {
167
+ var _provider$supportedBl;
168
+ const isSupportedBlockNode = node.isBlock && ((_provider$supportedBl = provider.supportedBlockNodes) === null || _provider$supportedBl === void 0 ? void 0 : _provider$supportedBl.includes(node.type.name));
166
169
  node.marks.filter(mark => mark.type === state.schema.marks.annotation).forEach(mark => {
167
- const isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(selectedAnnotation => selectedAnnotation.id === mark.attrs.id));
168
- const isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
169
170
  if (isVisible) {
170
- focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
171
- class: `${getAnnotationViewClassname(isUnresolved, isSelected)} ${isUnresolved}`,
172
- nodeName: 'span'
173
- }));
171
+ const isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
172
+ if (isSupportedBlockNode) {
173
+ const isBlockNodeSelected = isCurrentBlockNodeSelected(state, node);
174
+ const attrs = isUnresolved ? {
175
+ class: isBlockNodeSelected ? `${BlockAnnotationSharedClassNames.focus}` : `${BlockAnnotationSharedClassNames.blur}`
176
+ } : {};
177
+ focusDecorations.push(Decoration.node(pos, pos + node.nodeSize, attrs, {
178
+ key: decorationKey.block
179
+ }));
180
+ } else {
181
+ const isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(selectedAnnotation => selectedAnnotation.id === mark.attrs.id));
182
+ focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
183
+ class: `${getAnnotationViewClassname(isUnresolved, isSelected)} ${isUnresolved}`,
184
+ nodeName: 'span'
185
+ }));
186
+ }
174
187
  }
175
188
  });
176
189
  });
@@ -114,6 +114,20 @@ export const getAnnotationViewKey = annotations => {
114
114
  const keys = annotations.map(mark => mark.id).join('_');
115
115
  return `view-annotation-wrapper_${keys}`;
116
116
  };
117
+ export const isCurrentBlockNodeSelected = (state, node) => {
118
+ const {
119
+ selection
120
+ } = state;
121
+ if (selection instanceof NodeSelection) {
122
+ if (selection.node === node) {
123
+ return true;
124
+ }
125
+ if (node.type.name === 'media' && selection.node.firstChild === node) {
126
+ return true;
127
+ }
128
+ }
129
+ return false;
130
+ };
117
131
  export const findAnnotationsInSelection = (selection, doc) => {
118
132
  const {
119
133
  empty,
@@ -130,7 +144,7 @@ export const findAnnotationsInSelection = (selection, doc) => {
130
144
  }
131
145
  const annotationMark = doc.type.schema.marks.annotation;
132
146
  const nodeBefore = $anchor.nodeBefore;
133
- const anchorAnnotationMarks = node && node.marks || [];
147
+ const anchorAnnotationMarks = (node === null || node === void 0 ? void 0 : node.marks) || [];
134
148
  let marks = [];
135
149
  if (annotationMark.isInSet(anchorAnnotationMarks)) {
136
150
  marks = anchorAnnotationMarks;
@@ -4,10 +4,11 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import { AnnotationTypes } from '@atlaskit/adf-schema';
5
5
  import { RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
6
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
+ import { BlockAnnotationSharedClassNames } from '@atlaskit/editor-common/styles';
7
8
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
9
  import { clearDirtyMark, closeComponent, setInlineCommentsVisibility, setSelectedAnnotation, updateInlineCommentResolvedState, updateMouseState } from '../commands';
9
10
  import { AnnotationNodeView, getAnnotationViewClassname } from '../nodeviews';
10
- import { getAllAnnotations, getPluginState, inlineCommentPluginKey } from '../utils';
11
+ import { decorationKey, getAllAnnotations, getPluginState, inlineCommentPluginKey, isCurrentBlockNodeSelected } from '../utils';
11
12
  import { createPluginState } from './plugin-factory';
12
13
  var fetchProviderStates = /*#__PURE__*/function () {
13
14
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(provider, annotationIds) {
@@ -216,18 +217,30 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
216
217
  var decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : DecorationSet.empty;
217
218
  var focusDecorations = [];
218
219
  state.doc.descendants(function (node, pos) {
220
+ var _provider$supportedBl;
221
+ var isSupportedBlockNode = node.isBlock && ((_provider$supportedBl = provider.supportedBlockNodes) === null || _provider$supportedBl === void 0 ? void 0 : _provider$supportedBl.includes(node.type.name));
219
222
  node.marks.filter(function (mark) {
220
223
  return mark.type === state.schema.marks.annotation;
221
224
  }).forEach(function (mark) {
222
- var isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
223
- return selectedAnnotation.id === mark.attrs.id;
224
- }));
225
- var isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
226
225
  if (isVisible) {
227
- focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
228
- class: "".concat(getAnnotationViewClassname(isUnresolved, isSelected), " ").concat(isUnresolved),
229
- nodeName: 'span'
230
- }));
226
+ var isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
227
+ if (isSupportedBlockNode) {
228
+ var isBlockNodeSelected = isCurrentBlockNodeSelected(state, node);
229
+ var attrs = isUnresolved ? {
230
+ class: isBlockNodeSelected ? "".concat(BlockAnnotationSharedClassNames.focus) : "".concat(BlockAnnotationSharedClassNames.blur)
231
+ } : {};
232
+ focusDecorations.push(Decoration.node(pos, pos + node.nodeSize, attrs, {
233
+ key: decorationKey.block
234
+ }));
235
+ } else {
236
+ var isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
237
+ return selectedAnnotation.id === mark.attrs.id;
238
+ }));
239
+ focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
240
+ class: "".concat(getAnnotationViewClassname(isUnresolved, isSelected), " ").concat(isUnresolved),
241
+ nodeName: 'span'
242
+ }));
243
+ }
231
244
  }
232
245
  });
233
246
  });
package/dist/esm/utils.js CHANGED
@@ -128,6 +128,18 @@ export var getAnnotationViewKey = function getAnnotationViewKey(annotations) {
128
128
  }).join('_');
129
129
  return "view-annotation-wrapper_".concat(keys);
130
130
  };
131
+ export var isCurrentBlockNodeSelected = function isCurrentBlockNodeSelected(state, node) {
132
+ var selection = state.selection;
133
+ if (selection instanceof NodeSelection) {
134
+ if (selection.node === node) {
135
+ return true;
136
+ }
137
+ if (node.type.name === 'media' && selection.node.firstChild === node) {
138
+ return true;
139
+ }
140
+ }
141
+ return false;
142
+ };
131
143
  export var findAnnotationsInSelection = function findAnnotationsInSelection(selection, doc) {
132
144
  var empty = selection.empty,
133
145
  $anchor = selection.$anchor,
@@ -142,7 +154,7 @@ export var findAnnotationsInSelection = function findAnnotationsInSelection(sele
142
154
  }
143
155
  var annotationMark = doc.type.schema.marks.annotation;
144
156
  var nodeBefore = $anchor.nodeBefore;
145
- var anchorAnnotationMarks = node && node.marks || [];
157
+ var anchorAnnotationMarks = (node === null || node === void 0 ? void 0 : node.marks) || [];
146
158
  var marks = [];
147
159
  if (annotationMark.isInSet(anchorAnnotationMarks)) {
148
160
  marks = anchorAnnotationMarks;
@@ -20,6 +20,7 @@ export declare const decorationKey: {
20
20
  };
21
21
  export declare const addDraftDecoration: (start: number, end: number, targetType?: TargetType) => Decoration;
22
22
  export declare const getAnnotationViewKey: (annotations: AnnotationInfo[]) => string;
23
+ export declare const isCurrentBlockNodeSelected: (state: EditorState, node: Node) => boolean;
23
24
  export declare const findAnnotationsInSelection: (selection: Selection, doc: Node) => AnnotationInfo[];
24
25
  export declare const resolveDraftBookmark: (editorState: EditorState, bookmark: SelectionBookmark, supportedBlockNodes?: string[]) => DraftBookmark;
25
26
  /**
@@ -20,6 +20,7 @@ export declare const decorationKey: {
20
20
  };
21
21
  export declare const addDraftDecoration: (start: number, end: number, targetType?: TargetType) => Decoration;
22
22
  export declare const getAnnotationViewKey: (annotations: AnnotationInfo[]) => string;
23
+ export declare const isCurrentBlockNodeSelected: (state: EditorState, node: Node) => boolean;
23
24
  export declare const findAnnotationsInSelection: (selection: Selection, doc: Node) => AnnotationInfo[];
24
25
  export declare const resolveDraftBookmark: (editorState: EditorState, bookmark: SelectionBookmark, supportedBlockNodes?: string[]) => DraftBookmark;
25
26
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-annotation",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "description": "Annotation plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@atlaskit/adf-schema": "^35.6.0",
36
- "@atlaskit/editor-common": "^78.12.0",
36
+ "@atlaskit/editor-common": "^78.14.0",
37
37
  "@atlaskit/editor-plugin-analytics": "^1.0.0",
38
38
  "@atlaskit/editor-plugin-editor-viewmode": "^1.0.0",
39
39
  "@atlaskit/editor-plugin-feature-flags": "^1.0.0",
@@ -80,11 +80,9 @@
80
80
  "ui-components": [
81
81
  "lite-mode"
82
82
  ],
83
- "deprecation": [
84
- "no-deprecated-imports"
85
- ],
83
+ "deprecation": "no-deprecated-imports",
86
84
  "styling": [
87
- "static",
85
+ "emotion",
88
86
  "emotion"
89
87
  ],
90
88
  "imports": [
@@ -101,4 +99,4 @@
101
99
  "type": "boolean"
102
100
  }
103
101
  }
104
- }
102
+ }