@atlaskit/editor-plugin-annotation 6.2.13 → 6.3.1

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,22 @@
1
1
  # @atlaskit/editor-plugin-annotation
2
2
 
3
+ ## 6.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 6.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`2bab449c372a5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2bab449c372a5) -
14
+ sync annotations state when delete and undo
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies
19
+
3
20
  ## 6.2.13
4
21
 
5
22
  ### Patch Changes
@@ -9,6 +9,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
9
9
  var _utils = require("@atlaskit/editor-common/utils");
10
10
  var _state = require("@atlaskit/editor-prosemirror/state");
11
11
  var _view = require("@atlaskit/editor-prosemirror/view");
12
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
12
13
  var _reducer = _interopRequireDefault(require("./reducer"));
13
14
  var _utils2 = require("./utils");
14
15
  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; }
@@ -22,6 +23,60 @@ var handleDocChanged = function handleDocChanged(tr, prevPluginState) {
22
23
  });
23
24
  };
24
25
 
26
+ /**
27
+ * Creates a handleDocChanged function with its own deleted annotations cache.
28
+ * This ensures each editor instance has its own cache, avoiding cross-contamination.
29
+ */
30
+ var createHandleDocChanged = function createHandleDocChanged() {
31
+ // Cache for preserving deleted annotation resolved states through delete/undo cycles
32
+ // This lives in closure scope per editor instance to avoid serialization and reduce state size
33
+ var deletedAnnotationsCache = {};
34
+ return function (tr, prevPluginState) {
35
+ if (tr.getMeta('replaceDocument')) {
36
+ return _objectSpread(_objectSpread({}, prevPluginState), {}, {
37
+ dirtyAnnotations: true
38
+ });
39
+ }
40
+ var updatedState = getSelectionChangedHandler(false)(tr, prevPluginState);
41
+
42
+ // Collect annotation IDs currently in the document
43
+ var annotationIdsInDocument = new Set();
44
+ tr.doc.descendants(function (node) {
45
+ node.marks.forEach(function (mark) {
46
+ if (mark.type.name === 'annotation') {
47
+ annotationIdsInDocument.add(mark.attrs.id);
48
+ }
49
+ });
50
+ });
51
+ var annotationIdsInState = Object.keys(prevPluginState.annotations);
52
+
53
+ // Early return if annotations haven't changed
54
+ var annotationsHaveChanged = annotationIdsInDocument.size !== annotationIdsInState.length || annotationIdsInState.some(function (id) {
55
+ return !annotationIdsInDocument.has(id);
56
+ });
57
+ if (!annotationsHaveChanged) {
58
+ return updatedState;
59
+ }
60
+
61
+ // Cache deleted annotations to be able to restore their resolved states on undo
62
+ var updatedAnnotations = {};
63
+ annotationIdsInState.forEach(function (id) {
64
+ if (!annotationIdsInDocument.has(id)) {
65
+ deletedAnnotationsCache[id] = prevPluginState.annotations[id];
66
+ }
67
+ });
68
+
69
+ // Update annotations to match document state, preserving resolved states through delete/undo
70
+ annotationIdsInDocument.forEach(function (id) {
71
+ var _ref, _prevPluginState$anno;
72
+ updatedAnnotations[id] = (_ref = (_prevPluginState$anno = prevPluginState.annotations[id]) !== null && _prevPluginState$anno !== void 0 ? _prevPluginState$anno : deletedAnnotationsCache[id]) !== null && _ref !== void 0 ? _ref : false;
73
+ });
74
+ return _objectSpread(_objectSpread({}, updatedState), {}, {
75
+ annotations: updatedAnnotations
76
+ });
77
+ };
78
+ };
79
+
25
80
  /**
26
81
  * We clear bookmark on the following conditions:
27
82
  * 1. if current selection is an empty selection, or
@@ -145,9 +200,19 @@ var getSelectionChangedHandler = function getSelectionChangedHandler(reopenComme
145
200
  getSelectionChangeHandlerOld(reopenCommentView)(tr, pluginState);
146
201
  };
147
202
  };
203
+
204
+ // Create the handler with cache once at module level
205
+ var handleDocChangedWithSync = createHandleDocChanged();
206
+ var getDocChangedHandler = function getDocChangedHandler(tr, prevPluginState) {
207
+ // Check feature flag at runtime to support test variants
208
+ if ((0, _expValEquals.expValEquals)('platform_editor_annotations_sync_on_docchange', 'isEnabled', true)) {
209
+ return handleDocChangedWithSync(tr, prevPluginState);
210
+ }
211
+ return handleDocChanged(tr, prevPluginState);
212
+ };
148
213
  var _pluginFactory = (0, _utils.pluginFactory)(_utils2.inlineCommentPluginKey, _reducer.default, {
149
214
  onSelectionChanged: getSelectionChangedHandler(true),
150
- onDocChanged: handleDocChanged,
215
+ onDocChanged: getDocChangedHandler,
151
216
  mapping: function mapping(tr, pluginState, editorState) {
152
217
  var draftDecorationSet = pluginState.draftDecorationSet,
153
218
  bookmark = pluginState.bookmark;
@@ -1,6 +1,7 @@
1
1
  import { pluginFactory } from '@atlaskit/editor-common/utils';
2
2
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
5
  import reducer from './reducer';
5
6
  import { decorationKey, findAnnotationsInSelection, inlineCommentPluginKey, isBlockNodeAnnotationsSelected, isSelectedAnnotationsChanged } from './utils';
6
7
  const handleDocChanged = (tr, prevPluginState) => {
@@ -13,6 +14,60 @@ const handleDocChanged = (tr, prevPluginState) => {
13
14
  };
14
15
  };
15
16
 
17
+ /**
18
+ * Creates a handleDocChanged function with its own deleted annotations cache.
19
+ * This ensures each editor instance has its own cache, avoiding cross-contamination.
20
+ */
21
+ const createHandleDocChanged = () => {
22
+ // Cache for preserving deleted annotation resolved states through delete/undo cycles
23
+ // This lives in closure scope per editor instance to avoid serialization and reduce state size
24
+ const deletedAnnotationsCache = {};
25
+ return (tr, prevPluginState) => {
26
+ if (tr.getMeta('replaceDocument')) {
27
+ return {
28
+ ...prevPluginState,
29
+ dirtyAnnotations: true
30
+ };
31
+ }
32
+ const updatedState = getSelectionChangedHandler(false)(tr, prevPluginState);
33
+
34
+ // Collect annotation IDs currently in the document
35
+ const annotationIdsInDocument = new Set();
36
+ tr.doc.descendants(node => {
37
+ node.marks.forEach(mark => {
38
+ if (mark.type.name === 'annotation') {
39
+ annotationIdsInDocument.add(mark.attrs.id);
40
+ }
41
+ });
42
+ });
43
+ const annotationIdsInState = Object.keys(prevPluginState.annotations);
44
+
45
+ // Early return if annotations haven't changed
46
+ const annotationsHaveChanged = annotationIdsInDocument.size !== annotationIdsInState.length || annotationIdsInState.some(id => !annotationIdsInDocument.has(id));
47
+ if (!annotationsHaveChanged) {
48
+ return updatedState;
49
+ }
50
+
51
+ // Cache deleted annotations to be able to restore their resolved states on undo
52
+ const updatedAnnotations = {};
53
+ annotationIdsInState.forEach(id => {
54
+ if (!annotationIdsInDocument.has(id)) {
55
+ deletedAnnotationsCache[id] = prevPluginState.annotations[id];
56
+ }
57
+ });
58
+
59
+ // Update annotations to match document state, preserving resolved states through delete/undo
60
+ annotationIdsInDocument.forEach(id => {
61
+ var _ref, _prevPluginState$anno;
62
+ updatedAnnotations[id] = (_ref = (_prevPluginState$anno = prevPluginState.annotations[id]) !== null && _prevPluginState$anno !== void 0 ? _prevPluginState$anno : deletedAnnotationsCache[id]) !== null && _ref !== void 0 ? _ref : false;
63
+ });
64
+ return {
65
+ ...updatedState,
66
+ annotations: updatedAnnotations
67
+ };
68
+ };
69
+ };
70
+
16
71
  /**
17
72
  * We clear bookmark on the following conditions:
18
73
  * 1. if current selection is an empty selection, or
@@ -144,12 +199,22 @@ const getSelectionChangedHandler = reopenCommentView => (tr, pluginState) => plu
144
199
  getSelectionChangeHandlerNew(reopenCommentView)(tr, pluginState) :
145
200
  // else if platform_editor_comments_api_manager == false
146
201
  getSelectionChangeHandlerOld(reopenCommentView)(tr, pluginState);
202
+
203
+ // Create the handler with cache once at module level
204
+ const handleDocChangedWithSync = createHandleDocChanged();
205
+ const getDocChangedHandler = (tr, prevPluginState) => {
206
+ // Check feature flag at runtime to support test variants
207
+ if (expValEquals('platform_editor_annotations_sync_on_docchange', 'isEnabled', true)) {
208
+ return handleDocChangedWithSync(tr, prevPluginState);
209
+ }
210
+ return handleDocChanged(tr, prevPluginState);
211
+ };
147
212
  export const {
148
213
  createPluginState,
149
214
  createCommand
150
215
  } = pluginFactory(inlineCommentPluginKey, reducer, {
151
216
  onSelectionChanged: getSelectionChangedHandler(true),
152
- onDocChanged: handleDocChanged,
217
+ onDocChanged: getDocChangedHandler,
153
218
  mapping: (tr, pluginState, editorState) => {
154
219
  const {
155
220
  draftDecorationSet,
@@ -4,6 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  import { pluginFactory } from '@atlaskit/editor-common/utils';
5
5
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
6
6
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
7
8
  import reducer from './reducer';
8
9
  import { decorationKey, findAnnotationsInSelection, inlineCommentPluginKey, isBlockNodeAnnotationsSelected, isSelectedAnnotationsChanged } from './utils';
9
10
  var handleDocChanged = function handleDocChanged(tr, prevPluginState) {
@@ -15,6 +16,60 @@ var handleDocChanged = function handleDocChanged(tr, prevPluginState) {
15
16
  });
16
17
  };
17
18
 
19
+ /**
20
+ * Creates a handleDocChanged function with its own deleted annotations cache.
21
+ * This ensures each editor instance has its own cache, avoiding cross-contamination.
22
+ */
23
+ var createHandleDocChanged = function createHandleDocChanged() {
24
+ // Cache for preserving deleted annotation resolved states through delete/undo cycles
25
+ // This lives in closure scope per editor instance to avoid serialization and reduce state size
26
+ var deletedAnnotationsCache = {};
27
+ return function (tr, prevPluginState) {
28
+ if (tr.getMeta('replaceDocument')) {
29
+ return _objectSpread(_objectSpread({}, prevPluginState), {}, {
30
+ dirtyAnnotations: true
31
+ });
32
+ }
33
+ var updatedState = getSelectionChangedHandler(false)(tr, prevPluginState);
34
+
35
+ // Collect annotation IDs currently in the document
36
+ var annotationIdsInDocument = new Set();
37
+ tr.doc.descendants(function (node) {
38
+ node.marks.forEach(function (mark) {
39
+ if (mark.type.name === 'annotation') {
40
+ annotationIdsInDocument.add(mark.attrs.id);
41
+ }
42
+ });
43
+ });
44
+ var annotationIdsInState = Object.keys(prevPluginState.annotations);
45
+
46
+ // Early return if annotations haven't changed
47
+ var annotationsHaveChanged = annotationIdsInDocument.size !== annotationIdsInState.length || annotationIdsInState.some(function (id) {
48
+ return !annotationIdsInDocument.has(id);
49
+ });
50
+ if (!annotationsHaveChanged) {
51
+ return updatedState;
52
+ }
53
+
54
+ // Cache deleted annotations to be able to restore their resolved states on undo
55
+ var updatedAnnotations = {};
56
+ annotationIdsInState.forEach(function (id) {
57
+ if (!annotationIdsInDocument.has(id)) {
58
+ deletedAnnotationsCache[id] = prevPluginState.annotations[id];
59
+ }
60
+ });
61
+
62
+ // Update annotations to match document state, preserving resolved states through delete/undo
63
+ annotationIdsInDocument.forEach(function (id) {
64
+ var _ref, _prevPluginState$anno;
65
+ updatedAnnotations[id] = (_ref = (_prevPluginState$anno = prevPluginState.annotations[id]) !== null && _prevPluginState$anno !== void 0 ? _prevPluginState$anno : deletedAnnotationsCache[id]) !== null && _ref !== void 0 ? _ref : false;
66
+ });
67
+ return _objectSpread(_objectSpread({}, updatedState), {}, {
68
+ annotations: updatedAnnotations
69
+ });
70
+ };
71
+ };
72
+
18
73
  /**
19
74
  * We clear bookmark on the following conditions:
20
75
  * 1. if current selection is an empty selection, or
@@ -138,9 +193,19 @@ var getSelectionChangedHandler = function getSelectionChangedHandler(reopenComme
138
193
  getSelectionChangeHandlerOld(reopenCommentView)(tr, pluginState);
139
194
  };
140
195
  };
196
+
197
+ // Create the handler with cache once at module level
198
+ var handleDocChangedWithSync = createHandleDocChanged();
199
+ var getDocChangedHandler = function getDocChangedHandler(tr, prevPluginState) {
200
+ // Check feature flag at runtime to support test variants
201
+ if (expValEquals('platform_editor_annotations_sync_on_docchange', 'isEnabled', true)) {
202
+ return handleDocChangedWithSync(tr, prevPluginState);
203
+ }
204
+ return handleDocChanged(tr, prevPluginState);
205
+ };
141
206
  var _pluginFactory = pluginFactory(inlineCommentPluginKey, reducer, {
142
207
  onSelectionChanged: getSelectionChangedHandler(true),
143
- onDocChanged: handleDocChanged,
208
+ onDocChanged: getDocChangedHandler,
144
209
  mapping: function mapping(tr, pluginState, editorState) {
145
210
  var draftDecorationSet = pluginState.draftDecorationSet,
146
211
  bookmark = pluginState.bookmark;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-annotation",
3
- "version": "6.2.13",
3
+ "version": "6.3.1",
4
4
  "description": "Annotation plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -39,12 +39,12 @@
39
39
  "@atlaskit/editor-toolbar-model": "^0.2.0",
40
40
  "@atlaskit/icon": "^29.0.0",
41
41
  "@atlaskit/platform-feature-flags": "^1.1.0",
42
- "@atlaskit/tmp-editor-statsig": "^14.5.0",
42
+ "@atlaskit/tmp-editor-statsig": "^15.0.0",
43
43
  "@babel/runtime": "^7.0.0",
44
44
  "react-intl-next": "npm:react-intl@^5.18.1"
45
45
  },
46
46
  "peerDependencies": {
47
- "@atlaskit/editor-common": "^110.38.0",
47
+ "@atlaskit/editor-common": "^110.40.0",
48
48
  "react": "^18.2.0",
49
49
  "react-dom": "^18.2.0"
50
50
  },