@atlaskit/editor-plugin-show-diff 0.1.7 → 0.2.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,20 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`f7c9ea51bb613`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f7c9ea51bb613) -
8
+ [EDITOR-1395] dnd interferes with diff
9
+ - Updated dependencies
10
+
11
+ ## 0.2.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [`3df4a57528050`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3df4a57528050) -
16
+ Update editor showDiffPlugin to take in params for preset use in Confluence version history.
17
+
3
18
  ## 0.1.7
4
19
 
5
20
  ### Patch Changes
@@ -24,4 +24,4 @@
24
24
  "path": "../../editor-common/afm-cc/tsconfig.json"
25
25
  }
26
26
  ]
27
- }
27
+ }
@@ -53,7 +53,7 @@ var NodeViewSerializer = exports.NodeViewSerializer = /*#__PURE__*/function () {
53
53
  editorView: params.editorView
54
54
  });
55
55
  }
56
- this.nodeViewBlocklist = new Set((_params$blocklist = params.blocklist) !== null && _params$blocklist !== void 0 ? _params$blocklist : ['tableRow', 'table', 'paragraph']);
56
+ this.nodeViewBlocklist = new Set((_params$blocklist = params.blocklist) !== null && _params$blocklist !== void 0 ? _params$blocklist : ['table', 'tableRow', 'tableHeader', 'tableCell', 'paragraph']);
57
57
  }
58
58
 
59
59
  /**
@@ -122,5 +122,28 @@ var NodeViewSerializer = exports.NodeViewSerializer = /*#__PURE__*/function () {
122
122
  }
123
123
  return this.serializer.serializeFragment(fragment);
124
124
  }
125
+
126
+ /**
127
+ * Returns a copy of the current node view blocklist.
128
+ */
129
+ }, {
130
+ key: "getNodeViewBlocklist",
131
+ value: function getNodeViewBlocklist() {
132
+ return new Set(this.nodeViewBlocklist);
133
+ }
134
+
135
+ /**
136
+ * Returns a filtered copy of the node view blocklist, excluding specified node types.
137
+ * @param excludeTypes - Array of node type names to exclude from the blocklist
138
+ */
139
+ }, {
140
+ key: "getFilteredNodeViewBlocklist",
141
+ value: function getFilteredNodeViewBlocklist(excludeTypes) {
142
+ var filtered = new Set(this.nodeViewBlocklist);
143
+ excludeTypes.forEach(function (type) {
144
+ return filtered.delete(type);
145
+ });
146
+ return filtered;
147
+ }
125
148
  }]);
126
149
  }();
@@ -40,29 +40,34 @@ var deletedContentStyleUnbounded = (0, _lazyNodeView.convertToInlineCss)({
40
40
  pointerEvents: 'none',
41
41
  zIndex: 1
42
42
  });
43
-
44
- /**
45
- * Creates a widget to represent the deleted content in the editor
46
- *
47
- * @param props.change Changeset "change" containing information about the change content + range
48
- * @param props.doc Baseline doc to compare against
49
- * @param props.tr The relevant transaction this decoration is being created against
50
- * @returns Prosemirror widget decoration
51
- */
52
43
  var createDeletedContentDecoration = exports.createDeletedContentDecoration = function createDeletedContentDecoration(_ref) {
53
44
  var change = _ref.change,
54
45
  doc = _ref.doc,
55
46
  nodeViewSerializer = _ref.nodeViewSerializer;
47
+ var slice = doc.slice(change.fromA, change.toA);
48
+ if (slice.content.content.length === 0) {
49
+ return;
50
+ }
51
+ var isTableContent = slice.content.content.some(function () {
52
+ return slice.content.content.some(function (siblingNode) {
53
+ return ['tableHeader', 'tableCell', 'tableRow'].includes(siblingNode.type.name);
54
+ });
55
+ });
56
+ if (isTableContent) {
57
+ return;
58
+ }
59
+ var serializer = nodeViewSerializer;
60
+
61
+ // For non-table content, use the existing span wrapper approach
56
62
  var dom = document.createElement('span');
57
63
  dom.setAttribute('style', deletedContentStyle);
58
64
 
59
65
  /*
60
66
  * The thinking is we separate out the fragment we got from doc.slice
61
67
  * and if it's the first or last content, we go in however many the sliced Open
62
- * or sliced End depth is and match only the content and not with the entire node.
68
+ * or sliced End depth is and match only the entire node.
63
69
  */
64
- var slice = doc.slice(change.fromA, change.toA);
65
- var serializer = nodeViewSerializer;
70
+
66
71
  slice.content.forEach(function (node) {
67
72
  // Create a wrapper for each node with strikethrough
68
73
  var createWrapperWithStrikethrough = function createWrapperWithStrikethrough() {
@@ -144,6 +149,9 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
144
149
  var wrapper = createWrapperWithStrikethrough();
145
150
  wrapper.append(nodeView.dom);
146
151
  dom.append(wrapper);
152
+ } else if (nodeViewSerializer.getFilteredNodeViewBlocklist(['paragraph', 'tableRow']).has(targetNode.type.name)) {
153
+ // Skip the case where the node is a paragraph or table row that way it can still be rendered and delete the entire table
154
+ return;
147
155
  } else {
148
156
  dom.append(fallbackSerialization());
149
157
  }
@@ -58,11 +58,14 @@ var calculateDecorations = function calculateDecorations(_ref) {
58
58
  decorations.push((0, _decorations.createInlineChangedDecoration)(change));
59
59
  }
60
60
  if (change.deleted.length > 0) {
61
- decorations.push((0, _decorations.createDeletedContentDecoration)({
61
+ var decoration = (0, _decorations.createDeletedContentDecoration)({
62
62
  change: change,
63
63
  doc: originalDoc,
64
64
  nodeViewSerializer: nodeViewSerializer
65
- }));
65
+ });
66
+ if (decoration) {
67
+ decorations.push(decoration);
68
+ }
66
69
  }
67
70
  });
68
71
  (0, _markDecorations.getMarkChangeRanges)(steps).forEach(function (change) {
@@ -43,7 +43,7 @@ export class NodeViewSerializer {
43
43
  editorView: params.editorView
44
44
  });
45
45
  }
46
- this.nodeViewBlocklist = new Set((_params$blocklist = params.blocklist) !== null && _params$blocklist !== void 0 ? _params$blocklist : ['tableRow', 'table', 'paragraph']);
46
+ this.nodeViewBlocklist = new Set((_params$blocklist = params.blocklist) !== null && _params$blocklist !== void 0 ? _params$blocklist : ['table', 'tableRow', 'tableHeader', 'tableCell', 'paragraph']);
47
47
  }
48
48
 
49
49
  /**
@@ -102,4 +102,21 @@ export class NodeViewSerializer {
102
102
  }
103
103
  return this.serializer.serializeFragment(fragment);
104
104
  }
105
+
106
+ /**
107
+ * Returns a copy of the current node view blocklist.
108
+ */
109
+ getNodeViewBlocklist() {
110
+ return new Set(this.nodeViewBlocklist);
111
+ }
112
+
113
+ /**
114
+ * Returns a filtered copy of the node view blocklist, excluding specified node types.
115
+ * @param excludeTypes - Array of node type names to exclude from the blocklist
116
+ */
117
+ getFilteredNodeViewBlocklist(excludeTypes) {
118
+ const filtered = new Set(this.nodeViewBlocklist);
119
+ excludeTypes.forEach(type => filtered.delete(type));
120
+ return filtered;
121
+ }
105
122
  }
@@ -32,30 +32,31 @@ const deletedContentStyleUnbounded = convertToInlineCss({
32
32
  pointerEvents: 'none',
33
33
  zIndex: 1
34
34
  });
35
-
36
- /**
37
- * Creates a widget to represent the deleted content in the editor
38
- *
39
- * @param props.change Changeset "change" containing information about the change content + range
40
- * @param props.doc Baseline doc to compare against
41
- * @param props.tr The relevant transaction this decoration is being created against
42
- * @returns Prosemirror widget decoration
43
- */
44
35
  export const createDeletedContentDecoration = ({
45
36
  change,
46
37
  doc,
47
38
  nodeViewSerializer
48
39
  }) => {
40
+ const slice = doc.slice(change.fromA, change.toA);
41
+ if (slice.content.content.length === 0) {
42
+ return;
43
+ }
44
+ const isTableContent = slice.content.content.some(() => slice.content.content.some(siblingNode => ['tableHeader', 'tableCell', 'tableRow'].includes(siblingNode.type.name)));
45
+ if (isTableContent) {
46
+ return;
47
+ }
48
+ const serializer = nodeViewSerializer;
49
+
50
+ // For non-table content, use the existing span wrapper approach
49
51
  const dom = document.createElement('span');
50
52
  dom.setAttribute('style', deletedContentStyle);
51
53
 
52
54
  /*
53
55
  * The thinking is we separate out the fragment we got from doc.slice
54
56
  * and if it's the first or last content, we go in however many the sliced Open
55
- * or sliced End depth is and match only the content and not with the entire node.
57
+ * or sliced End depth is and match only the entire node.
56
58
  */
57
- const slice = doc.slice(change.fromA, change.toA);
58
- const serializer = nodeViewSerializer;
59
+
59
60
  slice.content.forEach(node => {
60
61
  // Create a wrapper for each node with strikethrough
61
62
  const createWrapperWithStrikethrough = () => {
@@ -133,6 +134,9 @@ export const createDeletedContentDecoration = ({
133
134
  const wrapper = createWrapperWithStrikethrough();
134
135
  wrapper.append(nodeView.dom);
135
136
  dom.append(wrapper);
137
+ } else if (nodeViewSerializer.getFilteredNodeViewBlocklist(['paragraph', 'tableRow']).has(targetNode.type.name)) {
138
+ // Skip the case where the node is a paragraph or table row that way it can still be rendered and delete the entire table
139
+ return;
136
140
  } else {
137
141
  dom.append(fallbackSerialization());
138
142
  }
@@ -42,11 +42,14 @@ const calculateDecorations = ({
42
42
  decorations.push(createInlineChangedDecoration(change));
43
43
  }
44
44
  if (change.deleted.length > 0) {
45
- decorations.push(createDeletedContentDecoration({
45
+ const decoration = createDeletedContentDecoration({
46
46
  change,
47
47
  doc: originalDoc,
48
48
  nodeViewSerializer
49
- }));
49
+ });
50
+ if (decoration) {
51
+ decorations.push(decoration);
52
+ }
50
53
  }
51
54
  });
52
55
  getMarkChangeRanges(steps).forEach(change => {
@@ -46,7 +46,7 @@ export var NodeViewSerializer = /*#__PURE__*/function () {
46
46
  editorView: params.editorView
47
47
  });
48
48
  }
49
- this.nodeViewBlocklist = new Set((_params$blocklist = params.blocklist) !== null && _params$blocklist !== void 0 ? _params$blocklist : ['tableRow', 'table', 'paragraph']);
49
+ this.nodeViewBlocklist = new Set((_params$blocklist = params.blocklist) !== null && _params$blocklist !== void 0 ? _params$blocklist : ['table', 'tableRow', 'tableHeader', 'tableCell', 'paragraph']);
50
50
  }
51
51
 
52
52
  /**
@@ -115,5 +115,28 @@ export var NodeViewSerializer = /*#__PURE__*/function () {
115
115
  }
116
116
  return this.serializer.serializeFragment(fragment);
117
117
  }
118
+
119
+ /**
120
+ * Returns a copy of the current node view blocklist.
121
+ */
122
+ }, {
123
+ key: "getNodeViewBlocklist",
124
+ value: function getNodeViewBlocklist() {
125
+ return new Set(this.nodeViewBlocklist);
126
+ }
127
+
128
+ /**
129
+ * Returns a filtered copy of the node view blocklist, excluding specified node types.
130
+ * @param excludeTypes - Array of node type names to exclude from the blocklist
131
+ */
132
+ }, {
133
+ key: "getFilteredNodeViewBlocklist",
134
+ value: function getFilteredNodeViewBlocklist(excludeTypes) {
135
+ var filtered = new Set(this.nodeViewBlocklist);
136
+ excludeTypes.forEach(function (type) {
137
+ return filtered.delete(type);
138
+ });
139
+ return filtered;
140
+ }
118
141
  }]);
119
142
  }();
@@ -34,29 +34,34 @@ var deletedContentStyleUnbounded = convertToInlineCss({
34
34
  pointerEvents: 'none',
35
35
  zIndex: 1
36
36
  });
37
-
38
- /**
39
- * Creates a widget to represent the deleted content in the editor
40
- *
41
- * @param props.change Changeset "change" containing information about the change content + range
42
- * @param props.doc Baseline doc to compare against
43
- * @param props.tr The relevant transaction this decoration is being created against
44
- * @returns Prosemirror widget decoration
45
- */
46
37
  export var createDeletedContentDecoration = function createDeletedContentDecoration(_ref) {
47
38
  var change = _ref.change,
48
39
  doc = _ref.doc,
49
40
  nodeViewSerializer = _ref.nodeViewSerializer;
41
+ var slice = doc.slice(change.fromA, change.toA);
42
+ if (slice.content.content.length === 0) {
43
+ return;
44
+ }
45
+ var isTableContent = slice.content.content.some(function () {
46
+ return slice.content.content.some(function (siblingNode) {
47
+ return ['tableHeader', 'tableCell', 'tableRow'].includes(siblingNode.type.name);
48
+ });
49
+ });
50
+ if (isTableContent) {
51
+ return;
52
+ }
53
+ var serializer = nodeViewSerializer;
54
+
55
+ // For non-table content, use the existing span wrapper approach
50
56
  var dom = document.createElement('span');
51
57
  dom.setAttribute('style', deletedContentStyle);
52
58
 
53
59
  /*
54
60
  * The thinking is we separate out the fragment we got from doc.slice
55
61
  * and if it's the first or last content, we go in however many the sliced Open
56
- * or sliced End depth is and match only the content and not with the entire node.
62
+ * or sliced End depth is and match only the entire node.
57
63
  */
58
- var slice = doc.slice(change.fromA, change.toA);
59
- var serializer = nodeViewSerializer;
64
+
60
65
  slice.content.forEach(function (node) {
61
66
  // Create a wrapper for each node with strikethrough
62
67
  var createWrapperWithStrikethrough = function createWrapperWithStrikethrough() {
@@ -138,6 +143,9 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
138
143
  var wrapper = createWrapperWithStrikethrough();
139
144
  wrapper.append(nodeView.dom);
140
145
  dom.append(wrapper);
146
+ } else if (nodeViewSerializer.getFilteredNodeViewBlocklist(['paragraph', 'tableRow']).has(targetNode.type.name)) {
147
+ // Skip the case where the node is a paragraph or table row that way it can still be rendered and delete the entire table
148
+ return;
141
149
  } else {
142
150
  dom.append(fallbackSerialization());
143
151
  }
@@ -52,11 +52,14 @@ var calculateDecorations = function calculateDecorations(_ref) {
52
52
  decorations.push(createInlineChangedDecoration(change));
53
53
  }
54
54
  if (change.deleted.length > 0) {
55
- decorations.push(createDeletedContentDecoration({
55
+ var decoration = createDeletedContentDecoration({
56
56
  change: change,
57
57
  doc: originalDoc,
58
58
  nodeViewSerializer: nodeViewSerializer
59
- }));
59
+ });
60
+ if (decoration) {
61
+ decorations.push(decoration);
62
+ }
60
63
  }
61
64
  });
62
65
  getMarkChangeRanges(steps).forEach(function (change) {
@@ -1,2 +1,2 @@
1
1
  export { showDiffPlugin } from './showDiffPlugin';
2
- export type { ShowDiffPlugin } from './showDiffPluginType';
2
+ export type { ShowDiffPlugin, DiffParams } from './showDiffPluginType';
@@ -64,4 +64,13 @@ export declare class NodeViewSerializer {
64
64
  * Serializes a fragment to a `DocumentFragment` using the schema's `DOMSerializer`.
65
65
  */
66
66
  serializeFragment(fragment: Fragment): DocumentFragment | HTMLElement;
67
+ /**
68
+ * Returns a copy of the current node view blocklist.
69
+ */
70
+ getNodeViewBlocklist(): Set<string>;
71
+ /**
72
+ * Returns a filtered copy of the node view blocklist, excluding specified node types.
73
+ * @param excludeTypes - Array of node type names to exclude from the blocklist
74
+ */
75
+ getFilteredNodeViewBlocklist(excludeTypes: string[]): Set<string>;
67
76
  }
@@ -17,13 +17,5 @@ interface DeletedContentDecorationProps {
17
17
  doc: PMNode;
18
18
  nodeViewSerializer: NodeViewSerializer;
19
19
  }
20
- /**
21
- * Creates a widget to represent the deleted content in the editor
22
- *
23
- * @param props.change Changeset "change" containing information about the change content + range
24
- * @param props.doc Baseline doc to compare against
25
- * @param props.tr The relevant transaction this decoration is being created against
26
- * @returns Prosemirror widget decoration
27
- */
28
- export declare const createDeletedContentDecoration: ({ change, doc, nodeViewSerializer, }: DeletedContentDecorationProps) => Decoration;
20
+ export declare const createDeletedContentDecoration: ({ change, doc, nodeViewSerializer, }: DeletedContentDecorationProps) => Decoration | undefined;
29
21
  export {};
@@ -1,2 +1,2 @@
1
1
  export { showDiffPlugin } from './showDiffPlugin';
2
- export type { ShowDiffPlugin } from './showDiffPluginType';
2
+ export type { ShowDiffPlugin, DiffParams } from './showDiffPluginType';
@@ -64,4 +64,13 @@ export declare class NodeViewSerializer {
64
64
  * Serializes a fragment to a `DocumentFragment` using the schema's `DOMSerializer`.
65
65
  */
66
66
  serializeFragment(fragment: Fragment): DocumentFragment | HTMLElement;
67
+ /**
68
+ * Returns a copy of the current node view blocklist.
69
+ */
70
+ getNodeViewBlocklist(): Set<string>;
71
+ /**
72
+ * Returns a filtered copy of the node view blocklist, excluding specified node types.
73
+ * @param excludeTypes - Array of node type names to exclude from the blocklist
74
+ */
75
+ getFilteredNodeViewBlocklist(excludeTypes: string[]): Set<string>;
67
76
  }
@@ -17,13 +17,5 @@ interface DeletedContentDecorationProps {
17
17
  doc: PMNode;
18
18
  nodeViewSerializer: NodeViewSerializer;
19
19
  }
20
- /**
21
- * Creates a widget to represent the deleted content in the editor
22
- *
23
- * @param props.change Changeset "change" containing information about the change content + range
24
- * @param props.doc Baseline doc to compare against
25
- * @param props.tr The relevant transaction this decoration is being created against
26
- * @returns Prosemirror widget decoration
27
- */
28
- export declare const createDeletedContentDecoration: ({ change, doc, nodeViewSerializer, }: DeletedContentDecorationProps) => Decoration;
20
+ export declare const createDeletedContentDecoration: ({ change, doc, nodeViewSerializer, }: DeletedContentDecorationProps) => Decoration | undefined;
29
21
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-show-diff",
3
- "version": "0.1.7",
3
+ "version": "0.2.1",
4
4
  "description": "ShowDiff plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -27,17 +27,14 @@
27
27
  },
28
28
  "sideEffects": false,
29
29
  "atlaskit:src": "src/index.ts",
30
- "af:exports": {
31
- ".": "./src/index.ts"
32
- },
33
30
  "dependencies": {
34
31
  "@atlaskit/editor-prosemirror": "7.0.0",
35
- "@atlaskit/tokens": "^6.0.0",
32
+ "@atlaskit/tokens": "^6.1.0",
36
33
  "@babel/runtime": "^7.0.0",
37
34
  "prosemirror-changeset": "^2.2.1"
38
35
  },
39
36
  "peerDependencies": {
40
- "@atlaskit/editor-common": "^107.31.0",
37
+ "@atlaskit/editor-common": "^107.34.0",
41
38
  "react": "^18.2.0"
42
39
  },
43
40
  "techstack": {