@atlaskit/editor-plugin-show-diff 2.1.2 → 3.0.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,19 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 3.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 2.1.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [`b8555904ec1cc`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b8555904ec1cc) -
14
+ Add new util for comparing nodes ignoring attributes.
15
+ - Updated dependencies
16
+
3
17
  ## 2.1.2
4
18
 
5
19
  ### Patch Changes
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.areNodesEqual = areNodesEqual;
7
6
  exports.calculateDiffDecorations = void 0;
8
7
  var _prosemirrorChangeset = require("prosemirror-changeset");
8
+ var _document = require("@atlaskit/editor-common/utils/document");
9
9
  var _view = require("@atlaskit/editor-prosemirror/view");
10
10
  var _decorations = require("./decorations");
11
11
  var _markDecorations = require("./markDecorations");
@@ -43,7 +43,7 @@ var calculateDiffDecorations = exports.calculateDiffDecorations = function calcu
43
43
  } finally {
44
44
  _iterator.f();
45
45
  }
46
- if (!areNodesEqual(steppedDoc, tr.doc)) {
46
+ if (!(0, _document.areNodesEqualIgnoreAttrs)(steppedDoc, tr.doc)) {
47
47
  return _view.DecorationSet.empty;
48
48
  }
49
49
  var changes = (0, _prosemirrorChangeset.simplifyChanges)(changeset.changes, tr.doc);
@@ -68,35 +68,4 @@ var calculateDiffDecorations = exports.calculateDiffDecorations = function calcu
68
68
  decorations.push((0, _decorations.createInlineChangedDecoration)(change, colourScheme));
69
69
  });
70
70
  return _view.DecorationSet.empty.add(tr.doc, decorations);
71
- };
72
-
73
- /**
74
- * Compares two ProseMirror documents for equality, ignoring attributes
75
- * which don't affect the document structure.
76
- *
77
- * This is almost a copy of the .eq() PM function - tweaked to ignore attrs
78
- *
79
- * @param doc1 PMNode
80
- * @param doc2 PMNode
81
- * @returns boolean
82
- */
83
- function areNodesEqual(node1, node2) {
84
- if (node1.isText) {
85
- return node1.eq(node2);
86
- }
87
- return node1 === node2 || node1.hasMarkup(node2.type, node1.attrs, node2.marks) && areFragmentsEqual(node1.content, node2.content);
88
- }
89
- function areFragmentsEqual(frag1, frag2) {
90
- if (frag1.content.length !== frag2.content.length) {
91
- return false;
92
- }
93
- var childrenEqual = true;
94
- frag1.content.forEach(function (child, i) {
95
- var otherChild = frag2.child(i);
96
- if (child === otherChild || otherChild && areNodesEqual(child, otherChild)) {
97
- return;
98
- }
99
- childrenEqual = false;
100
- });
101
- return childrenEqual;
102
- }
71
+ };
@@ -1,5 +1,6 @@
1
1
  // eslint-disable-next-line @atlassian/tangerine/import/entry-points
2
2
  import { ChangeSet, simplifyChanges } from 'prosemirror-changeset';
3
+ import { areNodesEqualIgnoreAttrs } from '@atlaskit/editor-common/utils/document';
3
4
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
5
  import { createInlineChangedDecoration, createDeletedContentDecoration } from './decorations';
5
6
  import { getMarkChangeRanges } from './markDecorations';
@@ -30,7 +31,7 @@ export const calculateDiffDecorations = ({
30
31
  }
31
32
  // Rather than using .eq() we use a custom function that only checks for structural
32
33
  // changes and ignores differences in attributes which don't affect decoration positions
33
- if (!areNodesEqual(steppedDoc, tr.doc)) {
34
+ if (!areNodesEqualIgnoreAttrs(steppedDoc, tr.doc)) {
34
35
  return DecorationSet.empty;
35
36
  }
36
37
  const changes = simplifyChanges(changeset.changes, tr.doc);
@@ -55,35 +56,4 @@ export const calculateDiffDecorations = ({
55
56
  decorations.push(createInlineChangedDecoration(change, colourScheme));
56
57
  });
57
58
  return DecorationSet.empty.add(tr.doc, decorations);
58
- };
59
-
60
- /**
61
- * Compares two ProseMirror documents for equality, ignoring attributes
62
- * which don't affect the document structure.
63
- *
64
- * This is almost a copy of the .eq() PM function - tweaked to ignore attrs
65
- *
66
- * @param doc1 PMNode
67
- * @param doc2 PMNode
68
- * @returns boolean
69
- */
70
- export function areNodesEqual(node1, node2) {
71
- if (node1.isText) {
72
- return node1.eq(node2);
73
- }
74
- return node1 === node2 || node1.hasMarkup(node2.type, node1.attrs, node2.marks) && areFragmentsEqual(node1.content, node2.content);
75
- }
76
- function areFragmentsEqual(frag1, frag2) {
77
- if (frag1.content.length !== frag2.content.length) {
78
- return false;
79
- }
80
- let childrenEqual = true;
81
- frag1.content.forEach((child, i) => {
82
- const otherChild = frag2.child(i);
83
- if (child === otherChild || otherChild && areNodesEqual(child, otherChild)) {
84
- return;
85
- }
86
- childrenEqual = false;
87
- });
88
- return childrenEqual;
89
- }
59
+ };
@@ -3,6 +3,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
3
3
  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; }
4
4
  // eslint-disable-next-line @atlassian/tangerine/import/entry-points
5
5
  import { ChangeSet, simplifyChanges } from 'prosemirror-changeset';
6
+ import { areNodesEqualIgnoreAttrs } from '@atlaskit/editor-common/utils/document';
6
7
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
8
  import { createInlineChangedDecoration, createDeletedContentDecoration } from './decorations';
8
9
  import { getMarkChangeRanges } from './markDecorations';
@@ -37,7 +38,7 @@ export var calculateDiffDecorations = function calculateDiffDecorations(_ref) {
37
38
  } finally {
38
39
  _iterator.f();
39
40
  }
40
- if (!areNodesEqual(steppedDoc, tr.doc)) {
41
+ if (!areNodesEqualIgnoreAttrs(steppedDoc, tr.doc)) {
41
42
  return DecorationSet.empty;
42
43
  }
43
44
  var changes = simplifyChanges(changeset.changes, tr.doc);
@@ -62,35 +63,4 @@ export var calculateDiffDecorations = function calculateDiffDecorations(_ref) {
62
63
  decorations.push(createInlineChangedDecoration(change, colourScheme));
63
64
  });
64
65
  return DecorationSet.empty.add(tr.doc, decorations);
65
- };
66
-
67
- /**
68
- * Compares two ProseMirror documents for equality, ignoring attributes
69
- * which don't affect the document structure.
70
- *
71
- * This is almost a copy of the .eq() PM function - tweaked to ignore attrs
72
- *
73
- * @param doc1 PMNode
74
- * @param doc2 PMNode
75
- * @returns boolean
76
- */
77
- export function areNodesEqual(node1, node2) {
78
- if (node1.isText) {
79
- return node1.eq(node2);
80
- }
81
- return node1 === node2 || node1.hasMarkup(node2.type, node1.attrs, node2.marks) && areFragmentsEqual(node1.content, node2.content);
82
- }
83
- function areFragmentsEqual(frag1, frag2) {
84
- if (frag1.content.length !== frag2.content.length) {
85
- return false;
86
- }
87
- var childrenEqual = true;
88
- frag1.content.forEach(function (child, i) {
89
- var otherChild = frag2.child(i);
90
- if (child === otherChild || otherChild && areNodesEqual(child, otherChild)) {
91
- return;
92
- }
93
- childrenEqual = false;
94
- });
95
- return childrenEqual;
96
- }
66
+ };
@@ -1,4 +1,3 @@
1
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
1
  import { type EditorState } from '@atlaskit/editor-prosemirror/state';
3
2
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
3
  import type { ShowDiffPluginState } from './main';
@@ -9,14 +8,3 @@ export declare const calculateDiffDecorations: ({ state, pluginState, nodeViewSe
9
8
  pluginState: Omit<ShowDiffPluginState, "decorations">;
10
9
  state: EditorState;
11
10
  }) => DecorationSet;
12
- /**
13
- * Compares two ProseMirror documents for equality, ignoring attributes
14
- * which don't affect the document structure.
15
- *
16
- * This is almost a copy of the .eq() PM function - tweaked to ignore attrs
17
- *
18
- * @param doc1 PMNode
19
- * @param doc2 PMNode
20
- * @returns boolean
21
- */
22
- export declare function areNodesEqual(node1: PMNode, node2: PMNode): boolean;
@@ -1,4 +1,3 @@
1
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
1
  import { type EditorState } from '@atlaskit/editor-prosemirror/state';
3
2
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
3
  import type { ShowDiffPluginState } from './main';
@@ -9,14 +8,3 @@ export declare const calculateDiffDecorations: ({ state, pluginState, nodeViewSe
9
8
  pluginState: Omit<ShowDiffPluginState, "decorations">;
10
9
  state: EditorState;
11
10
  }) => DecorationSet;
12
- /**
13
- * Compares two ProseMirror documents for equality, ignoring attributes
14
- * which don't affect the document structure.
15
- *
16
- * This is almost a copy of the .eq() PM function - tweaked to ignore attrs
17
- *
18
- * @param doc1 PMNode
19
- * @param doc2 PMNode
20
- * @returns boolean
21
- */
22
- export declare function areNodesEqual(node1: PMNode, node2: PMNode): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-show-diff",
3
- "version": "2.1.2",
3
+ "version": "3.0.0",
4
4
  "description": "ShowDiff plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,7 +34,7 @@
34
34
  "prosemirror-changeset": "^2.2.1"
35
35
  },
36
36
  "peerDependencies": {
37
- "@atlaskit/editor-common": "^109.8.0",
37
+ "@atlaskit/editor-common": "^110.0.0",
38
38
  "react": "^18.2.0"
39
39
  },
40
40
  "techstack": {