@atlaskit/editor-plugin-show-diff 2.1.0 → 2.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
+ ## 2.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`c6b6ef91296ca`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c6b6ef91296ca) -
8
+ [ux] Better support for block nodes for deleted diffs.
9
+ - Updated dependencies
10
+
3
11
  ## 2.1.0
4
12
 
5
13
  ### Minor Changes
@@ -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 : ['table', 'tableRow', 'tableHeader', 'tableCell', 'paragraph']);
56
+ this.nodeViewBlocklist = new Set((_params$blocklist = params.blocklist) !== null && _params$blocklist !== void 0 ? _params$blocklist : ['paragraph']);
57
57
  }
58
58
 
59
59
  /**
@@ -83,20 +83,49 @@ var NodeViewSerializer = exports.NodeViewSerializer = /*#__PURE__*/function () {
83
83
  }, {
84
84
  key: "tryCreateNodeView",
85
85
  value: function tryCreateNodeView(targetNode) {
86
- var _this$nodeViews;
86
+ var _this$nodeViews,
87
+ _this = this;
87
88
  if (!this.editorView) {
88
89
  return null;
89
90
  }
90
91
  var constructor = (_this$nodeViews = this.nodeViews) === null || _this$nodeViews === void 0 ? void 0 : _this$nodeViews[targetNode.type.name];
91
- if (!constructor) {
92
- return null;
93
- }
94
92
  if (this.nodeViewBlocklist.has(targetNode.type.name)) {
95
93
  return null;
96
94
  }
97
- return constructor(targetNode, this.editorView, function () {
98
- return 0;
99
- }, [], {});
95
+ if (!constructor) {
96
+ var _targetNode$type$spec, _targetNode$type$spec2;
97
+ if (targetNode.isInline) {
98
+ return null;
99
+ }
100
+ var toDOMResult = (_targetNode$type$spec = (_targetNode$type$spec2 = targetNode.type.spec).toDOM) === null || _targetNode$type$spec === void 0 ? void 0 : _targetNode$type$spec.call(_targetNode$type$spec2, targetNode);
101
+ if (!toDOMResult) {
102
+ return null;
103
+ }
104
+ var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, toDOMResult),
105
+ _dom = _DOMSerializer$render.dom,
106
+ _contentDOM = _DOMSerializer$render.contentDOM;
107
+ if (_dom instanceof HTMLElement) {
108
+ if (targetNode.type.name === 'paragraph' && targetNode.children.length === 1) {
109
+ return this.serializeFragment(targetNode.content);
110
+ }
111
+
112
+ // Iteratively populate children
113
+ targetNode.children.forEach(function (child) {
114
+ _contentDOM === null || _contentDOM === void 0 || _contentDOM.append(_this.tryCreateNodeView(child) || _this.serializeNode(child));
115
+ });
116
+ }
117
+ return _dom;
118
+ }
119
+ var _constructor = constructor(targetNode, this.editorView, function () {
120
+ return 0;
121
+ }, [], {}),
122
+ dom = _constructor.dom,
123
+ contentDOM = _constructor.contentDOM;
124
+ // Iteratively populate children
125
+ targetNode.children.forEach(function (child) {
126
+ contentDOM === null || contentDOM === void 0 || contentDOM.append(_this.tryCreateNodeView(child) || _this.serializeNode(child));
127
+ });
128
+ return dom;
100
129
  }
101
130
 
102
131
  /**
@@ -120,7 +120,7 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
120
120
  targetNode = node;
121
121
  dom.append(lineBreak);
122
122
  var wrapper = createWrapperWithStrikethrough();
123
- wrapper.append(childNodeView.dom);
123
+ wrapper.append(childNodeView);
124
124
  dom.append(wrapper);
125
125
  } else {
126
126
  // Fallback to serializing the individual child node
@@ -143,7 +143,7 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
143
143
  if (handleMultipleChildNodes(node)) {
144
144
  return;
145
145
  }
146
- targetNode = node.content.content[0];
146
+ targetNode = node;
147
147
  fallbackSerialization = function fallbackSerialization() {
148
148
  return serializer.serializeFragment(node.content);
149
149
  };
@@ -167,7 +167,7 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
167
167
  if (handleMultipleChildNodes(node)) {
168
168
  return;
169
169
  }
170
- targetNode = node.content.content[0] || node;
170
+ targetNode = node;
171
171
  fallbackSerialization = function fallbackSerialization() {
172
172
  return serializer.serializeNode(node);
173
173
  };
@@ -176,9 +176,13 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
176
176
  // Try to create node view, fallback to serialization
177
177
  var nodeView = serializer.tryCreateNodeView(targetNode);
178
178
  if (nodeView) {
179
- var wrapper = createWrapperWithStrikethrough();
180
- wrapper.append(nodeView.dom);
181
- dom.append(wrapper);
179
+ if (targetNode.isInline) {
180
+ var wrapper = createWrapperWithStrikethrough();
181
+ wrapper.append(nodeView);
182
+ dom.append(wrapper);
183
+ } else {
184
+ dom.append(nodeView);
185
+ }
182
186
  } else if (nodeViewSerializer.getFilteredNodeViewBlocklist(['paragraph', 'tableRow']).has(targetNode.type.name)) {
183
187
  // Skip the case where the node is a paragraph or table row that way it can still be rendered and delete the entire table
184
188
  return;
@@ -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 : ['table', 'tableRow', 'tableHeader', 'tableCell', 'paragraph']);
46
+ this.nodeViewBlocklist = new Set((_params$blocklist = params.blocklist) !== null && _params$blocklist !== void 0 ? _params$blocklist : ['paragraph']);
47
47
  }
48
48
 
49
49
  /**
@@ -74,13 +74,43 @@ export class NodeViewSerializer {
74
74
  return null;
75
75
  }
76
76
  const constructor = (_this$nodeViews = this.nodeViews) === null || _this$nodeViews === void 0 ? void 0 : _this$nodeViews[targetNode.type.name];
77
- if (!constructor) {
78
- return null;
79
- }
80
77
  if (this.nodeViewBlocklist.has(targetNode.type.name)) {
81
78
  return null;
82
79
  }
83
- return constructor(targetNode, this.editorView, () => 0, [], {});
80
+ if (!constructor) {
81
+ var _targetNode$type$spec, _targetNode$type$spec2;
82
+ if (targetNode.isInline) {
83
+ return null;
84
+ }
85
+ const toDOMResult = (_targetNode$type$spec = (_targetNode$type$spec2 = targetNode.type.spec).toDOM) === null || _targetNode$type$spec === void 0 ? void 0 : _targetNode$type$spec.call(_targetNode$type$spec2, targetNode);
86
+ if (!toDOMResult) {
87
+ return null;
88
+ }
89
+ const {
90
+ dom,
91
+ contentDOM
92
+ } = DOMSerializer.renderSpec(document, toDOMResult);
93
+ if (dom instanceof HTMLElement) {
94
+ if (targetNode.type.name === 'paragraph' && targetNode.children.length === 1) {
95
+ return this.serializeFragment(targetNode.content);
96
+ }
97
+
98
+ // Iteratively populate children
99
+ targetNode.children.forEach(child => {
100
+ contentDOM === null || contentDOM === void 0 ? void 0 : contentDOM.append(this.tryCreateNodeView(child) || this.serializeNode(child));
101
+ });
102
+ }
103
+ return dom;
104
+ }
105
+ const {
106
+ dom,
107
+ contentDOM
108
+ } = constructor(targetNode, this.editorView, () => 0, [], {});
109
+ // Iteratively populate children
110
+ targetNode.children.forEach(child => {
111
+ contentDOM === null || contentDOM === void 0 ? void 0 : contentDOM.append(this.tryCreateNodeView(child) || this.serializeNode(child));
112
+ });
113
+ return dom;
84
114
  }
85
115
 
86
116
  /**
@@ -105,7 +105,7 @@ export const createDeletedContentDecoration = ({
105
105
  targetNode = node;
106
106
  dom.append(lineBreak);
107
107
  const wrapper = createWrapperWithStrikethrough();
108
- wrapper.append(childNodeView.dom);
108
+ wrapper.append(childNodeView);
109
109
  dom.append(wrapper);
110
110
  } else {
111
111
  // Fallback to serializing the individual child node
@@ -128,7 +128,7 @@ export const createDeletedContentDecoration = ({
128
128
  if (handleMultipleChildNodes(node)) {
129
129
  return;
130
130
  }
131
- targetNode = node.content.content[0];
131
+ targetNode = node;
132
132
  fallbackSerialization = () => serializer.serializeFragment(node.content);
133
133
  } else if (isLast && slice.content.childCount === 2) {
134
134
  if (handleMultipleChildNodes(node)) {
@@ -150,16 +150,20 @@ export const createDeletedContentDecoration = ({
150
150
  if (handleMultipleChildNodes(node)) {
151
151
  return;
152
152
  }
153
- targetNode = node.content.content[0] || node;
153
+ targetNode = node;
154
154
  fallbackSerialization = () => serializer.serializeNode(node);
155
155
  }
156
156
 
157
157
  // Try to create node view, fallback to serialization
158
158
  const nodeView = serializer.tryCreateNodeView(targetNode);
159
159
  if (nodeView) {
160
- const wrapper = createWrapperWithStrikethrough();
161
- wrapper.append(nodeView.dom);
162
- dom.append(wrapper);
160
+ if (targetNode.isInline) {
161
+ const wrapper = createWrapperWithStrikethrough();
162
+ wrapper.append(nodeView);
163
+ dom.append(wrapper);
164
+ } else {
165
+ dom.append(nodeView);
166
+ }
163
167
  } else if (nodeViewSerializer.getFilteredNodeViewBlocklist(['paragraph', 'tableRow']).has(targetNode.type.name)) {
164
168
  // Skip the case where the node is a paragraph or table row that way it can still be rendered and delete the entire table
165
169
  return;
@@ -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 : ['table', 'tableRow', 'tableHeader', 'tableCell', 'paragraph']);
49
+ this.nodeViewBlocklist = new Set((_params$blocklist = params.blocklist) !== null && _params$blocklist !== void 0 ? _params$blocklist : ['paragraph']);
50
50
  }
51
51
 
52
52
  /**
@@ -76,20 +76,49 @@ export var NodeViewSerializer = /*#__PURE__*/function () {
76
76
  }, {
77
77
  key: "tryCreateNodeView",
78
78
  value: function tryCreateNodeView(targetNode) {
79
- var _this$nodeViews;
79
+ var _this$nodeViews,
80
+ _this = this;
80
81
  if (!this.editorView) {
81
82
  return null;
82
83
  }
83
84
  var constructor = (_this$nodeViews = this.nodeViews) === null || _this$nodeViews === void 0 ? void 0 : _this$nodeViews[targetNode.type.name];
84
- if (!constructor) {
85
- return null;
86
- }
87
85
  if (this.nodeViewBlocklist.has(targetNode.type.name)) {
88
86
  return null;
89
87
  }
90
- return constructor(targetNode, this.editorView, function () {
91
- return 0;
92
- }, [], {});
88
+ if (!constructor) {
89
+ var _targetNode$type$spec, _targetNode$type$spec2;
90
+ if (targetNode.isInline) {
91
+ return null;
92
+ }
93
+ var toDOMResult = (_targetNode$type$spec = (_targetNode$type$spec2 = targetNode.type.spec).toDOM) === null || _targetNode$type$spec === void 0 ? void 0 : _targetNode$type$spec.call(_targetNode$type$spec2, targetNode);
94
+ if (!toDOMResult) {
95
+ return null;
96
+ }
97
+ var _DOMSerializer$render = DOMSerializer.renderSpec(document, toDOMResult),
98
+ _dom = _DOMSerializer$render.dom,
99
+ _contentDOM = _DOMSerializer$render.contentDOM;
100
+ if (_dom instanceof HTMLElement) {
101
+ if (targetNode.type.name === 'paragraph' && targetNode.children.length === 1) {
102
+ return this.serializeFragment(targetNode.content);
103
+ }
104
+
105
+ // Iteratively populate children
106
+ targetNode.children.forEach(function (child) {
107
+ _contentDOM === null || _contentDOM === void 0 || _contentDOM.append(_this.tryCreateNodeView(child) || _this.serializeNode(child));
108
+ });
109
+ }
110
+ return _dom;
111
+ }
112
+ var _constructor = constructor(targetNode, this.editorView, function () {
113
+ return 0;
114
+ }, [], {}),
115
+ dom = _constructor.dom,
116
+ contentDOM = _constructor.contentDOM;
117
+ // Iteratively populate children
118
+ targetNode.children.forEach(function (child) {
119
+ contentDOM === null || contentDOM === void 0 || contentDOM.append(_this.tryCreateNodeView(child) || _this.serializeNode(child));
120
+ });
121
+ return dom;
93
122
  }
94
123
 
95
124
  /**
@@ -114,7 +114,7 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
114
114
  targetNode = node;
115
115
  dom.append(lineBreak);
116
116
  var wrapper = createWrapperWithStrikethrough();
117
- wrapper.append(childNodeView.dom);
117
+ wrapper.append(childNodeView);
118
118
  dom.append(wrapper);
119
119
  } else {
120
120
  // Fallback to serializing the individual child node
@@ -137,7 +137,7 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
137
137
  if (handleMultipleChildNodes(node)) {
138
138
  return;
139
139
  }
140
- targetNode = node.content.content[0];
140
+ targetNode = node;
141
141
  fallbackSerialization = function fallbackSerialization() {
142
142
  return serializer.serializeFragment(node.content);
143
143
  };
@@ -161,7 +161,7 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
161
161
  if (handleMultipleChildNodes(node)) {
162
162
  return;
163
163
  }
164
- targetNode = node.content.content[0] || node;
164
+ targetNode = node;
165
165
  fallbackSerialization = function fallbackSerialization() {
166
166
  return serializer.serializeNode(node);
167
167
  };
@@ -170,9 +170,13 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
170
170
  // Try to create node view, fallback to serialization
171
171
  var nodeView = serializer.tryCreateNodeView(targetNode);
172
172
  if (nodeView) {
173
- var wrapper = createWrapperWithStrikethrough();
174
- wrapper.append(nodeView.dom);
175
- dom.append(wrapper);
173
+ if (targetNode.isInline) {
174
+ var wrapper = createWrapperWithStrikethrough();
175
+ wrapper.append(nodeView);
176
+ dom.append(wrapper);
177
+ } else {
178
+ dom.append(nodeView);
179
+ }
176
180
  } else if (nodeViewSerializer.getFilteredNodeViewBlocklist(['paragraph', 'tableRow']).has(targetNode.type.name)) {
177
181
  // Skip the case where the node is a paragraph or table row that way it can still be rendered and delete the entire table
178
182
  return;
@@ -55,7 +55,7 @@ export declare class NodeViewSerializer {
55
55
  * Returns `null` when there is no `EditorView`, no constructor for the node type,
56
56
  * or the node type is blocklisted. Otherwise returns the constructed node view instance.
57
57
  */
58
- tryCreateNodeView(targetNode: PMNode): import("prosemirror-view").NodeView | null;
58
+ tryCreateNodeView(targetNode: PMNode): Node | null;
59
59
  /**
60
60
  * Serializes a node to a DOM `Node` using the schema's `DOMSerializer`.
61
61
  */
@@ -55,7 +55,7 @@ export declare class NodeViewSerializer {
55
55
  * Returns `null` when there is no `EditorView`, no constructor for the node type,
56
56
  * or the node type is blocklisted. Otherwise returns the constructed node view instance.
57
57
  */
58
- tryCreateNodeView(targetNode: PMNode): import("prosemirror-view").NodeView | null;
58
+ tryCreateNodeView(targetNode: PMNode): Node | null;
59
59
  /**
60
60
  * Serializes a node to a DOM `Node` using the schema's `DOMSerializer`.
61
61
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-show-diff",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
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.6.0",
37
+ "@atlaskit/editor-common": "^109.7.0",
38
38
  "react": "^18.2.0"
39
39
  },
40
40
  "techstack": {