@atlaskit/editor-plugin-track-changes 2.7.13 → 2.7.14

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,13 @@
1
1
  # @atlaskit/editor-plugin-track-changes
2
2
 
3
+ ## 2.7.14
4
+
5
+ ### Patch Changes
6
+
7
+ - [`66ad6c1d02200`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/66ad6c1d02200) -
8
+ Catch issues with tracked changes
9
+ - Updated dependencies
10
+
3
11
  ## 2.7.13
4
12
 
5
13
  ### Patch Changes
@@ -21,22 +21,27 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
21
21
  var trackChangesPluginKey = exports.trackChangesPluginKey = new _state.PluginKey('trackChangesPlugin');
22
22
  // Exported for test purposes
23
23
  var getBaselineFromSteps = exports.getBaselineFromSteps = function getBaselineFromSteps(doc, steps) {
24
- var _iterator = _createForOfIteratorHelper(steps.slice().reverse()),
25
- _step;
26
24
  try {
27
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
28
- var step = _step.value;
29
- var result = step.inverted.apply(doc);
30
- if (result.failed === null && result.doc) {
31
- doc = result.doc;
25
+ var _iterator = _createForOfIteratorHelper(steps.slice().reverse()),
26
+ _step;
27
+ try {
28
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
29
+ var step = _step.value;
30
+ var result = step.inverted.apply(doc);
31
+ if (result.failed === null && result.doc) {
32
+ doc = result.doc;
33
+ }
32
34
  }
35
+ } catch (err) {
36
+ _iterator.e(err);
37
+ } finally {
38
+ _iterator.f();
33
39
  }
34
- } catch (err) {
35
- _iterator.e(err);
36
- } finally {
37
- _iterator.f();
40
+ return doc;
41
+ } catch (e) {
42
+ // Temporary - we need to understand how this happens - but we want to unblock issues where this crashes the editor
43
+ return undefined;
38
44
  }
39
- return doc;
40
45
  };
41
46
  var createTrackChangesPlugin = exports.createTrackChangesPlugin = function createTrackChangesPlugin(api) {
42
47
  // Mark the state to be reset on next time the document has a meaningful change
@@ -70,11 +75,7 @@ var createTrackChangesPlugin = exports.createTrackChangesPlugin = function creat
70
75
  var isDocChanged = tr.docChanged && tr.steps.some(function (step) {
71
76
  return step instanceof _transform.ReplaceStep || step instanceof _transform.ReplaceAroundStep || step instanceof _transform.AddMarkStep || step instanceof _transform.RemoveMarkStep;
72
77
  });
73
- if (!isDocChanged) {
74
- // If no document changes, return the old changeSet
75
- return state;
76
- }
77
- if (tr.getMeta('isRemote') || tr.getMeta('replaceDocument')) {
78
+ if (!isDocChanged || tr.getMeta('isRemote') || tr.getMeta('replaceDocument')) {
78
79
  // If the transaction is remote, we need to map the steps to the current document
79
80
  return _objectSpread(_objectSpread({}, state), {}, {
80
81
  steps: state.steps.map(function (s) {
@@ -106,7 +107,7 @@ var createTrackChangesPlugin = exports.createTrackChangesPlugin = function creat
106
107
 
107
108
  // Calculate if there are actual changes by comparing current doc with baseline
108
109
  var baselineDoc = getBaselineFromSteps(tr.doc, steps);
109
- var hasChangesFromBaseline = !tr.doc.eq(baselineDoc);
110
+ var hasChangesFromBaseline = baselineDoc ? !tr.doc.eq(baselineDoc) : false;
110
111
 
111
112
  // Create a new ChangeSet based on document changes
112
113
  return _objectSpread(_objectSpread({}, state), {}, {
@@ -125,14 +126,18 @@ var createTrackChangesPlugin = exports.createTrackChangesPlugin = function creat
125
126
  var currentPluginState = trackChangesPluginKey.getState(view.state);
126
127
  var currentShouldChangesBeDisplayed = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.shouldChangesBeDisplayed;
127
128
  if (prevShouldChangesBeDisplayed === false && currentShouldChangesBeDisplayed === true) {
128
- var _currentPluginState$s, _api$core, _api$showDiff;
129
+ var _currentPluginState$s;
129
130
  var steps = (_currentPluginState$s = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.steps) !== null && _currentPluginState$s !== void 0 ? _currentPluginState$s : [];
130
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 || (_api$showDiff = _api$showDiff.commands) === null || _api$showDiff === void 0 ? void 0 : _api$showDiff.showDiff({
131
- originalDoc: getBaselineFromSteps(view.state.doc, steps),
132
- steps: steps.map(function (s) {
133
- return s.step;
134
- })
135
- }));
131
+ var originalDoc = getBaselineFromSteps(view.state.doc, steps);
132
+ if (originalDoc) {
133
+ var _api$core, _api$showDiff;
134
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 || (_api$showDiff = _api$showDiff.commands) === null || _api$showDiff === void 0 ? void 0 : _api$showDiff.showDiff({
135
+ originalDoc: originalDoc,
136
+ steps: steps.map(function (s) {
137
+ return s.step;
138
+ })
139
+ }));
140
+ }
136
141
  } else if (currentShouldChangesBeDisplayed === false && prevShouldChangesBeDisplayed === true) {
137
142
  var _api$core2, _api$showDiff2;
138
143
  api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(api === null || api === void 0 || (_api$showDiff2 = api.showDiff) === null || _api$showDiff2 === void 0 || (_api$showDiff2 = _api$showDiff2.commands) === null || _api$showDiff2 === void 0 ? void 0 : _api$showDiff2.hideDiff);
@@ -7,13 +7,18 @@ import { TOGGLE_TRACK_CHANGES_ACTION as ACTION } from './types';
7
7
  export const trackChangesPluginKey = new PluginKey('trackChangesPlugin');
8
8
  // Exported for test purposes
9
9
  export const getBaselineFromSteps = (doc, steps) => {
10
- for (const step of steps.slice().reverse()) {
11
- const result = step.inverted.apply(doc);
12
- if (result.failed === null && result.doc) {
13
- doc = result.doc;
10
+ try {
11
+ for (const step of steps.slice().reverse()) {
12
+ const result = step.inverted.apply(doc);
13
+ if (result.failed === null && result.doc) {
14
+ doc = result.doc;
15
+ }
14
16
  }
17
+ return doc;
18
+ } catch (e) {
19
+ // Temporary - we need to understand how this happens - but we want to unblock issues where this crashes the editor
20
+ return undefined;
15
21
  }
16
- return doc;
17
22
  };
18
23
  export const createTrackChangesPlugin = api => {
19
24
  // Mark the state to be reset on next time the document has a meaningful change
@@ -47,11 +52,7 @@ export const createTrackChangesPlugin = api => {
47
52
  };
48
53
  }
49
54
  const isDocChanged = tr.docChanged && tr.steps.some(step => step instanceof ReplaceStep || step instanceof ReplaceAroundStep || step instanceof AddMarkStep || step instanceof RemoveMarkStep);
50
- if (!isDocChanged) {
51
- // If no document changes, return the old changeSet
52
- return state;
53
- }
54
- if (tr.getMeta('isRemote') || tr.getMeta('replaceDocument')) {
55
+ if (!isDocChanged || tr.getMeta('isRemote') || tr.getMeta('replaceDocument')) {
55
56
  // If the transaction is remote, we need to map the steps to the current document
56
57
  return {
57
58
  ...state,
@@ -81,7 +82,7 @@ export const createTrackChangesPlugin = api => {
81
82
 
82
83
  // Calculate if there are actual changes by comparing current doc with baseline
83
84
  const baselineDoc = getBaselineFromSteps(tr.doc, steps);
84
- const hasChangesFromBaseline = !tr.doc.eq(baselineDoc);
85
+ const hasChangesFromBaseline = baselineDoc ? !tr.doc.eq(baselineDoc) : false;
85
86
 
86
87
  // Create a new ChangeSet based on document changes
87
88
  return {
@@ -101,12 +102,16 @@ export const createTrackChangesPlugin = api => {
101
102
  const currentPluginState = trackChangesPluginKey.getState(view.state);
102
103
  const currentShouldChangesBeDisplayed = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.shouldChangesBeDisplayed;
103
104
  if (prevShouldChangesBeDisplayed === false && currentShouldChangesBeDisplayed === true) {
104
- var _currentPluginState$s, _api$core, _api$showDiff, _api$showDiff$command;
105
+ var _currentPluginState$s;
105
106
  const steps = (_currentPluginState$s = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.steps) !== null && _currentPluginState$s !== void 0 ? _currentPluginState$s : [];
106
- api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 ? void 0 : (_api$showDiff$command = _api$showDiff.commands) === null || _api$showDiff$command === void 0 ? void 0 : _api$showDiff$command.showDiff({
107
- originalDoc: getBaselineFromSteps(view.state.doc, steps),
108
- steps: steps.map(s => s.step)
109
- }));
107
+ const originalDoc = getBaselineFromSteps(view.state.doc, steps);
108
+ if (originalDoc) {
109
+ var _api$core, _api$showDiff, _api$showDiff$command;
110
+ api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 ? void 0 : (_api$showDiff$command = _api$showDiff.commands) === null || _api$showDiff$command === void 0 ? void 0 : _api$showDiff$command.showDiff({
111
+ originalDoc,
112
+ steps: steps.map(s => s.step)
113
+ }));
114
+ }
110
115
  } else if (currentShouldChangesBeDisplayed === false && prevShouldChangesBeDisplayed === true) {
111
116
  var _api$core2, _api$showDiff2, _api$showDiff2$comman;
112
117
  api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(api === null || api === void 0 ? void 0 : (_api$showDiff2 = api.showDiff) === null || _api$showDiff2 === void 0 ? void 0 : (_api$showDiff2$comman = _api$showDiff2.commands) === null || _api$showDiff2$comman === void 0 ? void 0 : _api$showDiff2$comman.hideDiff);
@@ -14,22 +14,27 @@ import { TOGGLE_TRACK_CHANGES_ACTION as ACTION } from './types';
14
14
  export var trackChangesPluginKey = new PluginKey('trackChangesPlugin');
15
15
  // Exported for test purposes
16
16
  export var getBaselineFromSteps = function getBaselineFromSteps(doc, steps) {
17
- var _iterator = _createForOfIteratorHelper(steps.slice().reverse()),
18
- _step;
19
17
  try {
20
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
21
- var step = _step.value;
22
- var result = step.inverted.apply(doc);
23
- if (result.failed === null && result.doc) {
24
- doc = result.doc;
18
+ var _iterator = _createForOfIteratorHelper(steps.slice().reverse()),
19
+ _step;
20
+ try {
21
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
22
+ var step = _step.value;
23
+ var result = step.inverted.apply(doc);
24
+ if (result.failed === null && result.doc) {
25
+ doc = result.doc;
26
+ }
25
27
  }
28
+ } catch (err) {
29
+ _iterator.e(err);
30
+ } finally {
31
+ _iterator.f();
26
32
  }
27
- } catch (err) {
28
- _iterator.e(err);
29
- } finally {
30
- _iterator.f();
33
+ return doc;
34
+ } catch (e) {
35
+ // Temporary - we need to understand how this happens - but we want to unblock issues where this crashes the editor
36
+ return undefined;
31
37
  }
32
- return doc;
33
38
  };
34
39
  export var createTrackChangesPlugin = function createTrackChangesPlugin(api) {
35
40
  // Mark the state to be reset on next time the document has a meaningful change
@@ -63,11 +68,7 @@ export var createTrackChangesPlugin = function createTrackChangesPlugin(api) {
63
68
  var isDocChanged = tr.docChanged && tr.steps.some(function (step) {
64
69
  return step instanceof ReplaceStep || step instanceof ReplaceAroundStep || step instanceof AddMarkStep || step instanceof RemoveMarkStep;
65
70
  });
66
- if (!isDocChanged) {
67
- // If no document changes, return the old changeSet
68
- return state;
69
- }
70
- if (tr.getMeta('isRemote') || tr.getMeta('replaceDocument')) {
71
+ if (!isDocChanged || tr.getMeta('isRemote') || tr.getMeta('replaceDocument')) {
71
72
  // If the transaction is remote, we need to map the steps to the current document
72
73
  return _objectSpread(_objectSpread({}, state), {}, {
73
74
  steps: state.steps.map(function (s) {
@@ -99,7 +100,7 @@ export var createTrackChangesPlugin = function createTrackChangesPlugin(api) {
99
100
 
100
101
  // Calculate if there are actual changes by comparing current doc with baseline
101
102
  var baselineDoc = getBaselineFromSteps(tr.doc, steps);
102
- var hasChangesFromBaseline = !tr.doc.eq(baselineDoc);
103
+ var hasChangesFromBaseline = baselineDoc ? !tr.doc.eq(baselineDoc) : false;
103
104
 
104
105
  // Create a new ChangeSet based on document changes
105
106
  return _objectSpread(_objectSpread({}, state), {}, {
@@ -118,14 +119,18 @@ export var createTrackChangesPlugin = function createTrackChangesPlugin(api) {
118
119
  var currentPluginState = trackChangesPluginKey.getState(view.state);
119
120
  var currentShouldChangesBeDisplayed = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.shouldChangesBeDisplayed;
120
121
  if (prevShouldChangesBeDisplayed === false && currentShouldChangesBeDisplayed === true) {
121
- var _currentPluginState$s, _api$core, _api$showDiff;
122
+ var _currentPluginState$s;
122
123
  var steps = (_currentPluginState$s = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.steps) !== null && _currentPluginState$s !== void 0 ? _currentPluginState$s : [];
123
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 || (_api$showDiff = _api$showDiff.commands) === null || _api$showDiff === void 0 ? void 0 : _api$showDiff.showDiff({
124
- originalDoc: getBaselineFromSteps(view.state.doc, steps),
125
- steps: steps.map(function (s) {
126
- return s.step;
127
- })
128
- }));
124
+ var originalDoc = getBaselineFromSteps(view.state.doc, steps);
125
+ if (originalDoc) {
126
+ var _api$core, _api$showDiff;
127
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 || (_api$showDiff = _api$showDiff.commands) === null || _api$showDiff === void 0 ? void 0 : _api$showDiff.showDiff({
128
+ originalDoc: originalDoc,
129
+ steps: steps.map(function (s) {
130
+ return s.step;
131
+ })
132
+ }));
133
+ }
129
134
  } else if (currentShouldChangesBeDisplayed === false && prevShouldChangesBeDisplayed === true) {
130
135
  var _api$core2, _api$showDiff2;
131
136
  api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(api === null || api === void 0 || (_api$showDiff2 = api.showDiff) === null || _api$showDiff2 === void 0 || (_api$showDiff2 = _api$showDiff2.commands) === null || _api$showDiff2 === void 0 ? void 0 : _api$showDiff2.hideDiff);
@@ -11,6 +11,6 @@ type TrackChangesPluginState = {
11
11
  shouldChangesBeDisplayed: boolean;
12
12
  steps: InvertableStep[];
13
13
  };
14
- export declare const getBaselineFromSteps: (doc: PMNode, steps: InvertableStep[]) => PMNode;
14
+ export declare const getBaselineFromSteps: (doc: PMNode, steps: InvertableStep[]) => PMNode | undefined;
15
15
  export declare const createTrackChangesPlugin: (api: ExtractInjectionAPI<TrackChangesPlugin> | undefined) => SafePlugin<TrackChangesPluginState>;
16
16
  export {};
@@ -11,6 +11,6 @@ type TrackChangesPluginState = {
11
11
  shouldChangesBeDisplayed: boolean;
12
12
  steps: InvertableStep[];
13
13
  };
14
- export declare const getBaselineFromSteps: (doc: PMNode, steps: InvertableStep[]) => PMNode;
14
+ export declare const getBaselineFromSteps: (doc: PMNode, steps: InvertableStep[]) => PMNode | undefined;
15
15
  export declare const createTrackChangesPlugin: (api: ExtractInjectionAPI<TrackChangesPlugin> | undefined) => SafePlugin<TrackChangesPluginState>;
16
16
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-track-changes",
3
- "version": "2.7.13",
3
+ "version": "2.7.14",
4
4
  "description": "ShowDiff plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -37,12 +37,12 @@
37
37
  "@atlaskit/editor-toolbar": "^0.6.0",
38
38
  "@atlaskit/editor-toolbar-model": "^0.2.0",
39
39
  "@atlaskit/icon-lab": "^5.7.0",
40
- "@atlaskit/tmp-editor-statsig": "^11.11.0",
40
+ "@atlaskit/tmp-editor-statsig": "^11.12.0",
41
41
  "@babel/runtime": "^7.0.0",
42
42
  "react-intl-next": "npm:react-intl@^5.18.1"
43
43
  },
44
44
  "peerDependencies": {
45
- "@atlaskit/editor-common": "^107.34.0",
45
+ "@atlaskit/editor-common": "^107.35.0",
46
46
  "react": "^18.2.0"
47
47
  },
48
48
  "techstack": {