@atlaskit/editor-plugin-show-diff 8.1.0 → 8.1.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,13 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 8.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b26874dcf4a79`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b26874dcf4a79) -
8
+ Show granular inline diffs when the replace step is for a paragraph.
9
+ - Updated dependencies
10
+
3
11
  ## 8.1.0
4
12
 
5
13
  ### Minor Changes
@@ -27,6 +27,9 @@
27
27
  {
28
28
  "path": "../../editor-plugin-analytics/afm-products/tsconfig.json"
29
29
  },
30
+ {
31
+ "path": "../../editor-plugin-expand/afm-products/tsconfig.json"
32
+ },
30
33
  {
31
34
  "path": "../../editor-prosemirror/afm-products/tsconfig.json"
32
35
  },
@@ -7,7 +7,9 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.diffBySteps = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _prosemirrorChangeset = require("prosemirror-changeset");
10
11
  var _transform = require("@atlaskit/editor-prosemirror/transform");
12
+ var _optimizeChanges = require("./optimizeChanges");
11
13
  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; }
12
14
  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; }
13
15
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
@@ -67,6 +69,18 @@ var mergeOverlappingByNewDocRange = function mergeOverlappingByNewDocRange(chang
67
69
  merged.push(current);
68
70
  return merged;
69
71
  };
72
+ var isReplaceStepForTextBlockNode = function isReplaceStepForTextBlockNode(step, before, from, to) {
73
+ var _replacedSlice$conten, _replacingSlice$conte, _replacedSlice$conten2;
74
+ if (!(step instanceof _transform.ReplaceStep)) {
75
+ return false;
76
+ }
77
+ if (step.slice.openStart !== 0 || step.slice.openEnd !== 0) {
78
+ return false;
79
+ }
80
+ var replacedSlice = before.slice(from, to);
81
+ var replacingSlice = step.slice;
82
+ return Boolean(replacedSlice.openStart === 0 && replacedSlice.openEnd === 0 && replacedSlice.content.childCount === 1 && replacingSlice.content.childCount === 1 && ((_replacedSlice$conten = replacedSlice.content.firstChild) === null || _replacedSlice$conten === void 0 ? void 0 : _replacedSlice$conten.type.name) === ((_replacingSlice$conte = replacingSlice.content.firstChild) === null || _replacingSlice$conte === void 0 ? void 0 : _replacingSlice$conte.type.name) && ((_replacedSlice$conten2 = replacedSlice.content.firstChild) === null || _replacedSlice$conten2 === void 0 ? void 0 : _replacedSlice$conten2.type.isTextblock));
83
+ };
70
84
  var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps) {
71
85
  var changes = [];
72
86
  var currentDoc = originalDoc;
@@ -77,6 +91,7 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
77
91
  try {
78
92
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
79
93
  var step = _step2.value;
94
+ var before = currentDoc;
80
95
  var result = step.apply(currentDoc);
81
96
  if (result.failed !== null || !result.doc) {
82
97
  continue;
@@ -85,9 +100,12 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
85
100
  var rangeStep = step;
86
101
  if (typeof rangeStep.from === 'number' && typeof rangeStep.to === 'number') {
87
102
  rangedSteps.push({
103
+ before: before,
104
+ doc: result.doc,
88
105
  from: rangeStep.from,
89
106
  to: rangeStep.to,
90
107
  mapIndex: successfulStepMaps.length,
108
+ step: step,
91
109
  stepMap: stepMap
92
110
  });
93
111
  }
@@ -113,6 +131,34 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
113
131
  var afterStepToFinal = createMapping(successfulStepMaps.slice(rangedStep.mapIndex + 1));
114
132
  var fromB = mapPosition(afterStepToFinal, fromAfterStep);
115
133
  var toB = mapPosition(afterStepToFinal, toAfterStep);
134
+ if (isReplaceStepForTextBlockNode(rangedStep.step, rangedStep.before, rangedStep.from, rangedStep.to)) {
135
+ var granularStepChanges = _prosemirrorChangeset.ChangeSet.create(rangedStep.before).addSteps(rangedStep.doc, [rangedStep.stepMap], null);
136
+ var optimizedGranularStepChanges = (0, _optimizeChanges.optimizeChanges)((0, _prosemirrorChangeset.simplifyChanges)(granularStepChanges.changes, granularStepChanges.startDoc));
137
+ var _iterator3 = _createForOfIteratorHelper(optimizedGranularStepChanges),
138
+ _step3;
139
+ try {
140
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
141
+ var granularChange = _step3.value;
142
+ var granularFromA = mapPosition(beforeStepToOriginal, granularChange.fromA);
143
+ var granularToA = mapPosition(beforeStepToOriginal, granularChange.toA);
144
+ var granularFromB = mapPosition(afterStepToFinal, granularChange.fromB);
145
+ var granularToB = mapPosition(afterStepToFinal, granularChange.toB);
146
+ changes.push({
147
+ fromA: granularFromA,
148
+ toA: granularToA,
149
+ fromB: granularFromB,
150
+ toB: granularToB,
151
+ deleted: createSpans(Math.max(0, granularToA - granularFromA)),
152
+ inserted: createSpans(Math.max(0, granularToB - granularFromB))
153
+ });
154
+ }
155
+ } catch (err) {
156
+ _iterator3.e(err);
157
+ } finally {
158
+ _iterator3.f();
159
+ }
160
+ continue;
161
+ }
116
162
  changes.push({
117
163
  fromA: fromA,
118
164
  toA: toA,
@@ -1,4 +1,6 @@
1
- import { Mapping } from '@atlaskit/editor-prosemirror/transform';
1
+ import { simplifyChanges, ChangeSet } from 'prosemirror-changeset';
2
+ import { Mapping, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
3
+ import { optimizeChanges } from './optimizeChanges';
2
4
  const mapPosition = (mapping, pos) => mapping.map(pos);
3
5
  const createMapping = maps => {
4
6
  const mapping = new Mapping();
@@ -42,12 +44,25 @@ const mergeOverlappingByNewDocRange = changes => {
42
44
  merged.push(current);
43
45
  return merged;
44
46
  };
47
+ const isReplaceStepForTextBlockNode = (step, before, from, to) => {
48
+ var _replacedSlice$conten, _replacingSlice$conte, _replacedSlice$conten2;
49
+ if (!(step instanceof ReplaceStep)) {
50
+ return false;
51
+ }
52
+ if (step.slice.openStart !== 0 || step.slice.openEnd !== 0) {
53
+ return false;
54
+ }
55
+ const replacedSlice = before.slice(from, to);
56
+ const replacingSlice = step.slice;
57
+ return Boolean(replacedSlice.openStart === 0 && replacedSlice.openEnd === 0 && replacedSlice.content.childCount === 1 && replacingSlice.content.childCount === 1 && ((_replacedSlice$conten = replacedSlice.content.firstChild) === null || _replacedSlice$conten === void 0 ? void 0 : _replacedSlice$conten.type.name) === ((_replacingSlice$conte = replacingSlice.content.firstChild) === null || _replacingSlice$conte === void 0 ? void 0 : _replacingSlice$conte.type.name) && ((_replacedSlice$conten2 = replacedSlice.content.firstChild) === null || _replacedSlice$conten2 === void 0 ? void 0 : _replacedSlice$conten2.type.isTextblock));
58
+ };
45
59
  export const diffBySteps = (originalDoc, steps) => {
46
60
  const changes = [];
47
61
  let currentDoc = originalDoc;
48
62
  const successfulStepMaps = [];
49
63
  const rangedSteps = [];
50
64
  for (const step of steps) {
65
+ const before = currentDoc;
51
66
  const result = step.apply(currentDoc);
52
67
  if (result.failed !== null || !result.doc) {
53
68
  continue;
@@ -56,9 +71,12 @@ export const diffBySteps = (originalDoc, steps) => {
56
71
  const rangeStep = step;
57
72
  if (typeof rangeStep.from === 'number' && typeof rangeStep.to === 'number') {
58
73
  rangedSteps.push({
74
+ before,
75
+ doc: result.doc,
59
76
  from: rangeStep.from,
60
77
  to: rangeStep.to,
61
78
  mapIndex: successfulStepMaps.length,
79
+ step,
62
80
  stepMap
63
81
  });
64
82
  }
@@ -78,6 +96,25 @@ export const diffBySteps = (originalDoc, steps) => {
78
96
  const afterStepToFinal = createMapping(successfulStepMaps.slice(rangedStep.mapIndex + 1));
79
97
  const fromB = mapPosition(afterStepToFinal, fromAfterStep);
80
98
  const toB = mapPosition(afterStepToFinal, toAfterStep);
99
+ if (isReplaceStepForTextBlockNode(rangedStep.step, rangedStep.before, rangedStep.from, rangedStep.to)) {
100
+ const granularStepChanges = ChangeSet.create(rangedStep.before).addSteps(rangedStep.doc, [rangedStep.stepMap], null);
101
+ const optimizedGranularStepChanges = optimizeChanges(simplifyChanges(granularStepChanges.changes, granularStepChanges.startDoc));
102
+ for (const granularChange of optimizedGranularStepChanges) {
103
+ const granularFromA = mapPosition(beforeStepToOriginal, granularChange.fromA);
104
+ const granularToA = mapPosition(beforeStepToOriginal, granularChange.toA);
105
+ const granularFromB = mapPosition(afterStepToFinal, granularChange.fromB);
106
+ const granularToB = mapPosition(afterStepToFinal, granularChange.toB);
107
+ changes.push({
108
+ fromA: granularFromA,
109
+ toA: granularToA,
110
+ fromB: granularFromB,
111
+ toB: granularToB,
112
+ deleted: createSpans(Math.max(0, granularToA - granularFromA)),
113
+ inserted: createSpans(Math.max(0, granularToB - granularFromB))
114
+ });
115
+ }
116
+ continue;
117
+ }
81
118
  changes.push({
82
119
  fromA,
83
120
  toA,
@@ -5,7 +5,9 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
5
5
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
6
6
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
7
7
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
8
- import { Mapping } from '@atlaskit/editor-prosemirror/transform';
8
+ import { simplifyChanges, ChangeSet } from 'prosemirror-changeset';
9
+ import { Mapping, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
10
+ import { optimizeChanges } from './optimizeChanges';
9
11
  var mapPosition = function mapPosition(mapping, pos) {
10
12
  return mapping.map(pos);
11
13
  };
@@ -60,6 +62,18 @@ var mergeOverlappingByNewDocRange = function mergeOverlappingByNewDocRange(chang
60
62
  merged.push(current);
61
63
  return merged;
62
64
  };
65
+ var isReplaceStepForTextBlockNode = function isReplaceStepForTextBlockNode(step, before, from, to) {
66
+ var _replacedSlice$conten, _replacingSlice$conte, _replacedSlice$conten2;
67
+ if (!(step instanceof ReplaceStep)) {
68
+ return false;
69
+ }
70
+ if (step.slice.openStart !== 0 || step.slice.openEnd !== 0) {
71
+ return false;
72
+ }
73
+ var replacedSlice = before.slice(from, to);
74
+ var replacingSlice = step.slice;
75
+ return Boolean(replacedSlice.openStart === 0 && replacedSlice.openEnd === 0 && replacedSlice.content.childCount === 1 && replacingSlice.content.childCount === 1 && ((_replacedSlice$conten = replacedSlice.content.firstChild) === null || _replacedSlice$conten === void 0 ? void 0 : _replacedSlice$conten.type.name) === ((_replacingSlice$conte = replacingSlice.content.firstChild) === null || _replacingSlice$conte === void 0 ? void 0 : _replacingSlice$conte.type.name) && ((_replacedSlice$conten2 = replacedSlice.content.firstChild) === null || _replacedSlice$conten2 === void 0 ? void 0 : _replacedSlice$conten2.type.isTextblock));
76
+ };
63
77
  export var diffBySteps = function diffBySteps(originalDoc, steps) {
64
78
  var changes = [];
65
79
  var currentDoc = originalDoc;
@@ -70,6 +84,7 @@ export var diffBySteps = function diffBySteps(originalDoc, steps) {
70
84
  try {
71
85
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
72
86
  var step = _step2.value;
87
+ var before = currentDoc;
73
88
  var result = step.apply(currentDoc);
74
89
  if (result.failed !== null || !result.doc) {
75
90
  continue;
@@ -78,9 +93,12 @@ export var diffBySteps = function diffBySteps(originalDoc, steps) {
78
93
  var rangeStep = step;
79
94
  if (typeof rangeStep.from === 'number' && typeof rangeStep.to === 'number') {
80
95
  rangedSteps.push({
96
+ before: before,
97
+ doc: result.doc,
81
98
  from: rangeStep.from,
82
99
  to: rangeStep.to,
83
100
  mapIndex: successfulStepMaps.length,
101
+ step: step,
84
102
  stepMap: stepMap
85
103
  });
86
104
  }
@@ -106,6 +124,34 @@ export var diffBySteps = function diffBySteps(originalDoc, steps) {
106
124
  var afterStepToFinal = createMapping(successfulStepMaps.slice(rangedStep.mapIndex + 1));
107
125
  var fromB = mapPosition(afterStepToFinal, fromAfterStep);
108
126
  var toB = mapPosition(afterStepToFinal, toAfterStep);
127
+ if (isReplaceStepForTextBlockNode(rangedStep.step, rangedStep.before, rangedStep.from, rangedStep.to)) {
128
+ var granularStepChanges = ChangeSet.create(rangedStep.before).addSteps(rangedStep.doc, [rangedStep.stepMap], null);
129
+ var optimizedGranularStepChanges = optimizeChanges(simplifyChanges(granularStepChanges.changes, granularStepChanges.startDoc));
130
+ var _iterator3 = _createForOfIteratorHelper(optimizedGranularStepChanges),
131
+ _step3;
132
+ try {
133
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
134
+ var granularChange = _step3.value;
135
+ var granularFromA = mapPosition(beforeStepToOriginal, granularChange.fromA);
136
+ var granularToA = mapPosition(beforeStepToOriginal, granularChange.toA);
137
+ var granularFromB = mapPosition(afterStepToFinal, granularChange.fromB);
138
+ var granularToB = mapPosition(afterStepToFinal, granularChange.toB);
139
+ changes.push({
140
+ fromA: granularFromA,
141
+ toA: granularToA,
142
+ fromB: granularFromB,
143
+ toB: granularToB,
144
+ deleted: createSpans(Math.max(0, granularToA - granularFromA)),
145
+ inserted: createSpans(Math.max(0, granularToB - granularFromB))
146
+ });
147
+ }
148
+ } catch (err) {
149
+ _iterator3.e(err);
150
+ } finally {
151
+ _iterator3.f();
152
+ }
153
+ continue;
154
+ }
109
155
  changes.push({
110
156
  fromA: fromA,
111
157
  toA: toA,
@@ -1,4 +1,4 @@
1
- import type { Change } from 'prosemirror-changeset';
1
+ import { type Change } from 'prosemirror-changeset';
2
2
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
3
  import type { Step } from '@atlaskit/editor-prosemirror/transform';
4
4
  export declare const diffBySteps: (originalDoc: PMNode, steps: Step[]) => Change[];
@@ -1,4 +1,4 @@
1
- import type { Change } from 'prosemirror-changeset';
1
+ import { type Change } from 'prosemirror-changeset';
2
2
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
3
  import type { Step } from '@atlaskit/editor-prosemirror/transform';
4
4
  export declare const diffBySteps: (originalDoc: PMNode, steps: Step[]) => Change[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-show-diff",
3
- "version": "8.1.0",
3
+ "version": "8.1.1",
4
4
  "description": "ShowDiff plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,7 +35,7 @@
35
35
  "@atlaskit/editor-prosemirror": "^7.3.0",
36
36
  "@atlaskit/editor-tables": "^2.9.0",
37
37
  "@atlaskit/platform-feature-flags": "^1.1.0",
38
- "@atlaskit/tmp-editor-statsig": "^62.4.0",
38
+ "@atlaskit/tmp-editor-statsig": "^62.8.0",
39
39
  "@atlaskit/tokens": "^13.0.0",
40
40
  "@babel/runtime": "^7.0.0",
41
41
  "lodash": "^4.17.21",
@@ -57,7 +57,7 @@
57
57
  "react-intl-next": "npm:react-intl@^5.18.1"
58
58
  },
59
59
  "peerDependencies": {
60
- "@atlaskit/editor-common": "^114.0.0",
60
+ "@atlaskit/editor-common": "^114.1.0",
61
61
  "react": "^18.2.0"
62
62
  },
63
63
  "techstack": {