@atlaskit/editor-plugin-show-diff 0.1.5 → 0.1.7

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,21 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 0.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [`06722cb00f629`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/06722cb00f629) -
8
+ [EDITOR-1358] Remove extra parameters parased in and refactored initialisation for show-diff
9
+ editorView
10
+
11
+ ## 0.1.6
12
+
13
+ ### Patch Changes
14
+
15
+ - [`3d9a6a0aae8c5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3d9a6a0aae8c5) -
16
+ Fix show diff not loading inline node diffs on load
17
+ - Updated dependencies
18
+
3
19
  ## 0.1.5
4
20
 
5
21
  ### Patch Changes
@@ -2,9 +2,9 @@
2
2
  "extends": "../../../../tsconfig.entry-points.confluence.json",
3
3
  "compilerOptions": {
4
4
  "target": "es5",
5
- "composite": true,
6
5
  "outDir": "../../../../../confluence/tsDist/@atlaskit__editor-plugin-show-diff",
7
- "rootDir": "../"
6
+ "rootDir": "../",
7
+ "composite": true
8
8
  },
9
9
  "include": [
10
10
  "../src/**/*.ts",
@@ -46,29 +46,48 @@ function isEditorViewWithNodeViews(view) {
46
46
  */
47
47
  var NodeViewSerializer = exports.NodeViewSerializer = /*#__PURE__*/function () {
48
48
  function NodeViewSerializer(params) {
49
- var _ref, _params$nodeViews, _this$editorView, _params$blocklist;
49
+ var _params$blocklist;
50
50
  (0, _classCallCheck2.default)(this, NodeViewSerializer);
51
- this.serializer = _model.DOMSerializer.fromSchema(params.schema);
52
- if (params.editorView && isEditorViewWithNodeViews(params.editorView)) {
53
- this.editorView = params.editorView;
51
+ if (params !== null && params !== void 0 && params.editorView) {
52
+ this.init({
53
+ editorView: params.editorView
54
+ });
54
55
  }
55
- this.nodeViews = (_ref = (_params$nodeViews = params.nodeViews) !== null && _params$nodeViews !== void 0 ? _params$nodeViews : (_this$editorView = this.editorView) === null || _this$editorView === void 0 ? void 0 : _this$editorView.nodeViews) !== null && _ref !== void 0 ? _ref : {};
56
56
  this.nodeViewBlocklist = new Set((_params$blocklist = params.blocklist) !== null && _params$blocklist !== void 0 ? _params$blocklist : ['tableRow', 'table', 'paragraph']);
57
57
  }
58
58
 
59
59
  /**
60
- * Attempts to create a node view for the given node.
61
- *
62
- * Returns `null` when there is no `EditorView`, no constructor for the node type,
63
- * or the node type is blocklisted. Otherwise returns the constructed node view instance.
60
+ * Initializes or reinitializes the NodeViewSerializer with a new EditorView.
61
+ * This allows the same serializer instance to be reused across different editor states.
64
62
  */
65
63
  return (0, _createClass2.default)(NodeViewSerializer, [{
64
+ key: "init",
65
+ value: function init(params) {
66
+ var _params$editorView, _ref, _this$editorView;
67
+ this.serializer = _model.DOMSerializer.fromSchema(params.editorView.state.schema);
68
+ if (isEditorViewWithNodeViews(params.editorView)) {
69
+ this.editorView = params.editorView;
70
+ }
71
+ var nodeViews =
72
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
+ ((_params$editorView = params.editorView) === null || _params$editorView === void 0 ? void 0 : _params$editorView.nodeViews) || {};
74
+ this.nodeViews = (_ref = nodeViews !== null && nodeViews !== void 0 ? nodeViews : (_this$editorView = this.editorView) === null || _this$editorView === void 0 ? void 0 : _this$editorView.nodeViews) !== null && _ref !== void 0 ? _ref : {};
75
+ }
76
+
77
+ /**
78
+ * Attempts to create a node view for the given node.
79
+ *
80
+ * Returns `null` when there is no `EditorView`, no constructor for the node type,
81
+ * or the node type is blocklisted. Otherwise returns the constructed node view instance.
82
+ */
83
+ }, {
66
84
  key: "tryCreateNodeView",
67
85
  value: function tryCreateNodeView(targetNode) {
86
+ var _this$nodeViews;
68
87
  if (!this.editorView) {
69
88
  return null;
70
89
  }
71
- var constructor = this.nodeViews[targetNode.type.name];
90
+ var constructor = (_this$nodeViews = this.nodeViews) === null || _this$nodeViews === void 0 ? void 0 : _this$nodeViews[targetNode.type.name];
72
91
  if (!constructor) {
73
92
  return null;
74
93
  }
@@ -86,6 +105,9 @@ var NodeViewSerializer = exports.NodeViewSerializer = /*#__PURE__*/function () {
86
105
  }, {
87
106
  key: "serializeNode",
88
107
  value: function serializeNode(node) {
108
+ if (!this.serializer) {
109
+ throw new Error('NodeViewSerializer must be initialized with init() before use');
110
+ }
89
111
  return this.serializer.serializeNode(node);
90
112
  }
91
113
 
@@ -95,6 +117,9 @@ var NodeViewSerializer = exports.NodeViewSerializer = /*#__PURE__*/function () {
95
117
  }, {
96
118
  key: "serializeFragment",
97
119
  value: function serializeFragment(fragment) {
120
+ if (!this.serializer) {
121
+ throw new Error('NodeViewSerializer must be initialized with init() before use');
122
+ }
98
123
  return this.serializer.serializeFragment(fragment);
99
124
  }
100
125
  }]);
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.createInlineChangedDecoration = exports.createDeletedContentDecoration = void 0;
7
7
  var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
8
8
  var _view = require("@atlaskit/editor-prosemirror/view");
9
- var _NodeViewSerializer = require("./NodeViewSerializer");
10
9
  var style = (0, _lazyNodeView.convertToInlineCss)({
11
10
  background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
12
11
  textDecoration: 'underline',
@@ -53,9 +52,7 @@ var deletedContentStyleUnbounded = (0, _lazyNodeView.convertToInlineCss)({
53
52
  var createDeletedContentDecoration = exports.createDeletedContentDecoration = function createDeletedContentDecoration(_ref) {
54
53
  var change = _ref.change,
55
54
  doc = _ref.doc,
56
- tr = _ref.tr,
57
- editorView = _ref.editorView,
58
- nodeViews = _ref.nodeViews;
55
+ nodeViewSerializer = _ref.nodeViewSerializer;
59
56
  var dom = document.createElement('span');
60
57
  dom.setAttribute('style', deletedContentStyle);
61
58
 
@@ -65,11 +62,7 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
65
62
  * or sliced End depth is and match only the content and not with the entire node.
66
63
  */
67
64
  var slice = doc.slice(change.fromA, change.toA);
68
- var nodeViewSerializer = new _NodeViewSerializer.NodeViewSerializer({
69
- schema: tr.doc.type.schema,
70
- editorView: editorView,
71
- nodeViews: nodeViews
72
- });
65
+ var serializer = nodeViewSerializer;
73
66
  slice.content.forEach(function (node) {
74
67
  // Create a wrapper for each node with strikethrough
75
68
  var createWrapperWithStrikethrough = function createWrapperWithStrikethrough() {
@@ -86,7 +79,7 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
86
79
  var handleMultipleChildNodes = function handleMultipleChildNodes(node) {
87
80
  if (node.content.childCount > 1 && node.type.inlineContent) {
88
81
  node.content.forEach(function (childNode) {
89
- var childNodeView = nodeViewSerializer.tryCreateNodeView(childNode);
82
+ var childNodeView = serializer.tryCreateNodeView(childNode);
90
83
  if (childNodeView) {
91
84
  var lineBreak = document.createElement('br');
92
85
  targetNode = node;
@@ -96,7 +89,7 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
96
89
  dom.append(wrapper);
97
90
  } else {
98
91
  // Fallback to serializing the individual child node
99
- var serializedChild = nodeViewSerializer.serializeNode(childNode);
92
+ var serializedChild = serializer.serializeNode(childNode);
100
93
  dom.append(serializedChild);
101
94
  }
102
95
  });
@@ -117,7 +110,7 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
117
110
  }
118
111
  targetNode = node.content.content[0];
119
112
  fallbackSerialization = function fallbackSerialization() {
120
- return nodeViewSerializer.serializeFragment(node.content);
113
+ return serializer.serializeFragment(node.content);
121
114
  };
122
115
  } else if (isLast && slice.content.childCount === 2) {
123
116
  if (handleMultipleChildNodes(node)) {
@@ -131,9 +124,9 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
131
124
  if (node.type.name === 'paragraph') {
132
125
  var lineBreak = document.createElement('br');
133
126
  dom.append(lineBreak);
134
- return nodeViewSerializer.serializeFragment(node.content);
127
+ return serializer.serializeFragment(node.content);
135
128
  }
136
- return nodeViewSerializer.serializeFragment(node.content);
129
+ return serializer.serializeFragment(node.content);
137
130
  };
138
131
  } else {
139
132
  if (handleMultipleChildNodes(node)) {
@@ -141,12 +134,12 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
141
134
  }
142
135
  targetNode = node.content.content[0] || node;
143
136
  fallbackSerialization = function fallbackSerialization() {
144
- return nodeViewSerializer.serializeNode(node);
137
+ return serializer.serializeNode(node);
145
138
  };
146
139
  }
147
140
 
148
141
  // Try to create node view, fallback to serialization
149
- var nodeView = nodeViewSerializer.tryCreateNodeView(targetNode);
142
+ var nodeView = serializer.tryCreateNodeView(targetNode);
150
143
  if (nodeView) {
151
144
  var wrapper = createWrapperWithStrikethrough();
152
145
  wrapper.append(nodeView.dom);
@@ -14,6 +14,7 @@ var _transform = require("@atlaskit/editor-prosemirror/transform");
14
14
  var _view = require("@atlaskit/editor-prosemirror/view");
15
15
  var _decorations = require("./decorations");
16
16
  var _markDecorations = require("./markDecorations");
17
+ var _NodeViewSerializer = require("./NodeViewSerializer");
17
18
  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; }
18
19
  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; }
19
20
  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; } } }; }
@@ -22,8 +23,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
22
23
  var calculateDecorations = function calculateDecorations(_ref) {
23
24
  var state = _ref.state,
24
25
  pluginState = _ref.pluginState,
25
- editorView = _ref.editorView,
26
- nodeViews = _ref.nodeViews;
26
+ nodeViewSerializer = _ref.nodeViewSerializer;
27
27
  var originalDoc = pluginState.originalDoc,
28
28
  steps = pluginState.steps;
29
29
  if (!originalDoc || !pluginState.isDisplayingChanges) {
@@ -61,9 +61,7 @@ var calculateDecorations = function calculateDecorations(_ref) {
61
61
  decorations.push((0, _decorations.createDeletedContentDecoration)({
62
62
  change: change,
63
63
  doc: originalDoc,
64
- tr: tr,
65
- editorView: editorView,
66
- nodeViews: nodeViews
64
+ nodeViewSerializer: nodeViewSerializer
67
65
  }));
68
66
  }
69
67
  });
@@ -74,64 +72,41 @@ var calculateDecorations = function calculateDecorations(_ref) {
74
72
  };
75
73
  var showDiffPluginKey = exports.showDiffPluginKey = new _state.PluginKey('showDiffPlugin');
76
74
  var createPlugin = exports.createPlugin = function createPlugin(config) {
77
- var editorView;
78
- var setEditorView = function setEditorView(newEditorView) {
79
- editorView = newEditorView;
75
+ var nodeViewSerializer = new _NodeViewSerializer.NodeViewSerializer({});
76
+ var setNodeViewSerializer = function setNodeViewSerializer(editorView) {
77
+ nodeViewSerializer.init({
78
+ editorView: editorView
79
+ });
80
80
  };
81
81
  return new _safePlugin.SafePlugin({
82
82
  key: showDiffPluginKey,
83
83
  state: {
84
84
  init: function init(_, state) {
85
- var _config$steps, _config$steps2, _editorView;
86
- var schema = state.schema;
87
- var isDisplayingChanges = ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).length > 0;
88
- var steps = ((_config$steps2 = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps2 !== void 0 ? _config$steps2 : []).map(function (step) {
89
- return _transform.Step.fromJSON(schema, step);
90
- });
91
-
92
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
- var nodeViews = ((_editorView = editorView) === null || _editorView === void 0 ? void 0 : _editorView.nodeViews) || {};
85
+ // We do initial setup after we setup the editor view
94
86
  return {
95
- steps: steps,
96
- originalDoc: config !== null && config !== void 0 && config.originalDoc ? (0, _processRawValue.processRawValue)(state.schema, config.originalDoc) : undefined,
97
- decorations: calculateDecorations({
98
- state: state,
99
- pluginState: {
100
- steps: steps,
101
- originalDoc: config !== null && config !== void 0 && config.originalDoc ? (0, _processRawValue.processRawValue)(state.schema, config.originalDoc) : undefined,
102
- isDisplayingChanges: isDisplayingChanges
103
- },
104
- editorView: editorView,
105
- nodeViews: nodeViews
106
- }),
107
- isDisplayingChanges: isDisplayingChanges
87
+ steps: [],
88
+ originalDoc: undefined,
89
+ decorations: _view.DecorationSet.empty,
90
+ isDisplayingChanges: false
108
91
  };
109
92
  },
110
93
  apply: function apply(tr, currentPluginState, oldState, newState) {
111
- var _editorView2;
112
94
  var meta = tr.getMeta(showDiffPluginKey);
113
95
  var newPluginState = currentPluginState;
114
-
115
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
116
- var nodeViews = ((_editorView2 = editorView) === null || _editorView2 === void 0 ? void 0 : _editorView2.nodeViews) || {};
117
96
  if (meta) {
118
97
  if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'SHOW_DIFF') {
119
- var _meta$steps, _meta$originalDoc;
98
+ // Update the plugin state with the new metadata
99
+ newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
100
+ isDisplayingChanges: true
101
+ });
120
102
  // Calculate and store decorations in state
121
103
  var decorations = calculateDecorations({
122
104
  state: newState,
123
- pluginState: {
124
- steps: (_meta$steps = meta.steps) !== null && _meta$steps !== void 0 ? _meta$steps : currentPluginState.steps,
125
- originalDoc: (_meta$originalDoc = meta.originalDoc) !== null && _meta$originalDoc !== void 0 ? _meta$originalDoc : currentPluginState.originalDoc,
126
- isDisplayingChanges: true
127
- },
128
- editorView: editorView,
129
- nodeViews: nodeViews
130
- });
131
- newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
132
- decorations: decorations,
133
- isDisplayingChanges: true
105
+ pluginState: newPluginState,
106
+ nodeViewSerializer: nodeViewSerializer
134
107
  });
108
+ // Update the decorations
109
+ newPluginState.decorations = decorations;
135
110
  } else if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'HIDE_DIFF') {
136
111
  newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
137
112
  decorations: _view.DecorationSet.empty,
@@ -147,8 +122,23 @@ var createPlugin = exports.createPlugin = function createPlugin(config) {
147
122
  }
148
123
  },
149
124
  view: function view(editorView) {
150
- setEditorView(editorView);
151
- return {};
125
+ setNodeViewSerializer(editorView);
126
+ var isFirst = true;
127
+ return {
128
+ update: function update(view) {
129
+ // If we're using configuration to show diffs we initialise here once we setup the editor view
130
+ if (config !== null && config !== void 0 && config.originalDoc && config !== null && config !== void 0 && config.steps && config.steps.length > 0 && isFirst) {
131
+ isFirst = false;
132
+ view.dispatch(view.state.tr.setMeta(showDiffPluginKey, {
133
+ action: 'SHOW_DIFF',
134
+ steps: config.steps.map(function (step) {
135
+ return _transform.Step.fromJSON(view.state.schema, step);
136
+ }),
137
+ originalDoc: (0, _processRawValue.processRawValue)(view.state.schema, config.originalDoc)
138
+ }));
139
+ }
140
+ }
141
+ };
152
142
  },
153
143
  props: {
154
144
  decorations: function decorations(state) {
@@ -37,15 +37,31 @@ export function isEditorViewWithNodeViews(view) {
37
37
  */
38
38
  export class NodeViewSerializer {
39
39
  constructor(params) {
40
- var _ref, _params$nodeViews, _this$editorView, _params$blocklist;
41
- this.serializer = DOMSerializer.fromSchema(params.schema);
42
- if (params.editorView && isEditorViewWithNodeViews(params.editorView)) {
43
- this.editorView = params.editorView;
40
+ var _params$blocklist;
41
+ if (params !== null && params !== void 0 && params.editorView) {
42
+ this.init({
43
+ editorView: params.editorView
44
+ });
44
45
  }
45
- this.nodeViews = (_ref = (_params$nodeViews = params.nodeViews) !== null && _params$nodeViews !== void 0 ? _params$nodeViews : (_this$editorView = this.editorView) === null || _this$editorView === void 0 ? void 0 : _this$editorView.nodeViews) !== null && _ref !== void 0 ? _ref : {};
46
46
  this.nodeViewBlocklist = new Set((_params$blocklist = params.blocklist) !== null && _params$blocklist !== void 0 ? _params$blocklist : ['tableRow', 'table', 'paragraph']);
47
47
  }
48
48
 
49
+ /**
50
+ * Initializes or reinitializes the NodeViewSerializer with a new EditorView.
51
+ * This allows the same serializer instance to be reused across different editor states.
52
+ */
53
+ init(params) {
54
+ var _params$editorView, _ref, _this$editorView;
55
+ this.serializer = DOMSerializer.fromSchema(params.editorView.state.schema);
56
+ if (isEditorViewWithNodeViews(params.editorView)) {
57
+ this.editorView = params.editorView;
58
+ }
59
+ const nodeViews =
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
+ ((_params$editorView = params.editorView) === null || _params$editorView === void 0 ? void 0 : _params$editorView.nodeViews) || {};
62
+ this.nodeViews = (_ref = nodeViews !== null && nodeViews !== void 0 ? nodeViews : (_this$editorView = this.editorView) === null || _this$editorView === void 0 ? void 0 : _this$editorView.nodeViews) !== null && _ref !== void 0 ? _ref : {};
63
+ }
64
+
49
65
  /**
50
66
  * Attempts to create a node view for the given node.
51
67
  *
@@ -53,10 +69,11 @@ export class NodeViewSerializer {
53
69
  * or the node type is blocklisted. Otherwise returns the constructed node view instance.
54
70
  */
55
71
  tryCreateNodeView(targetNode) {
72
+ var _this$nodeViews;
56
73
  if (!this.editorView) {
57
74
  return null;
58
75
  }
59
- const constructor = this.nodeViews[targetNode.type.name];
76
+ const constructor = (_this$nodeViews = this.nodeViews) === null || _this$nodeViews === void 0 ? void 0 : _this$nodeViews[targetNode.type.name];
60
77
  if (!constructor) {
61
78
  return null;
62
79
  }
@@ -70,6 +87,9 @@ export class NodeViewSerializer {
70
87
  * Serializes a node to a DOM `Node` using the schema's `DOMSerializer`.
71
88
  */
72
89
  serializeNode(node) {
90
+ if (!this.serializer) {
91
+ throw new Error('NodeViewSerializer must be initialized with init() before use');
92
+ }
73
93
  return this.serializer.serializeNode(node);
74
94
  }
75
95
 
@@ -77,6 +97,9 @@ export class NodeViewSerializer {
77
97
  * Serializes a fragment to a `DocumentFragment` using the schema's `DOMSerializer`.
78
98
  */
79
99
  serializeFragment(fragment) {
100
+ if (!this.serializer) {
101
+ throw new Error('NodeViewSerializer must be initialized with init() before use');
102
+ }
80
103
  return this.serializer.serializeFragment(fragment);
81
104
  }
82
105
  }
@@ -1,6 +1,5 @@
1
1
  import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
2
2
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
- import { NodeViewSerializer } from './NodeViewSerializer';
4
3
  const style = convertToInlineCss({
5
4
  background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
6
5
  textDecoration: 'underline',
@@ -45,9 +44,7 @@ const deletedContentStyleUnbounded = convertToInlineCss({
45
44
  export const createDeletedContentDecoration = ({
46
45
  change,
47
46
  doc,
48
- tr,
49
- editorView,
50
- nodeViews
47
+ nodeViewSerializer
51
48
  }) => {
52
49
  const dom = document.createElement('span');
53
50
  dom.setAttribute('style', deletedContentStyle);
@@ -58,11 +55,7 @@ export const createDeletedContentDecoration = ({
58
55
  * or sliced End depth is and match only the content and not with the entire node.
59
56
  */
60
57
  const slice = doc.slice(change.fromA, change.toA);
61
- const nodeViewSerializer = new NodeViewSerializer({
62
- schema: tr.doc.type.schema,
63
- editorView,
64
- nodeViews
65
- });
58
+ const serializer = nodeViewSerializer;
66
59
  slice.content.forEach(node => {
67
60
  // Create a wrapper for each node with strikethrough
68
61
  const createWrapperWithStrikethrough = () => {
@@ -79,7 +72,7 @@ export const createDeletedContentDecoration = ({
79
72
  const handleMultipleChildNodes = node => {
80
73
  if (node.content.childCount > 1 && node.type.inlineContent) {
81
74
  node.content.forEach(childNode => {
82
- const childNodeView = nodeViewSerializer.tryCreateNodeView(childNode);
75
+ const childNodeView = serializer.tryCreateNodeView(childNode);
83
76
  if (childNodeView) {
84
77
  const lineBreak = document.createElement('br');
85
78
  targetNode = node;
@@ -89,7 +82,7 @@ export const createDeletedContentDecoration = ({
89
82
  dom.append(wrapper);
90
83
  } else {
91
84
  // Fallback to serializing the individual child node
92
- const serializedChild = nodeViewSerializer.serializeNode(childNode);
85
+ const serializedChild = serializer.serializeNode(childNode);
93
86
  dom.append(serializedChild);
94
87
  }
95
88
  });
@@ -109,7 +102,7 @@ export const createDeletedContentDecoration = ({
109
102
  return;
110
103
  }
111
104
  targetNode = node.content.content[0];
112
- fallbackSerialization = () => nodeViewSerializer.serializeFragment(node.content);
105
+ fallbackSerialization = () => serializer.serializeFragment(node.content);
113
106
  } else if (isLast && slice.content.childCount === 2) {
114
107
  if (handleMultipleChildNodes(node)) {
115
108
  return;
@@ -122,20 +115,20 @@ export const createDeletedContentDecoration = ({
122
115
  if (node.type.name === 'paragraph') {
123
116
  const lineBreak = document.createElement('br');
124
117
  dom.append(lineBreak);
125
- return nodeViewSerializer.serializeFragment(node.content);
118
+ return serializer.serializeFragment(node.content);
126
119
  }
127
- return nodeViewSerializer.serializeFragment(node.content);
120
+ return serializer.serializeFragment(node.content);
128
121
  };
129
122
  } else {
130
123
  if (handleMultipleChildNodes(node)) {
131
124
  return;
132
125
  }
133
126
  targetNode = node.content.content[0] || node;
134
- fallbackSerialization = () => nodeViewSerializer.serializeNode(node);
127
+ fallbackSerialization = () => serializer.serializeNode(node);
135
128
  }
136
129
 
137
130
  // Try to create node view, fallback to serialization
138
- const nodeView = nodeViewSerializer.tryCreateNodeView(targetNode);
131
+ const nodeView = serializer.tryCreateNodeView(targetNode);
139
132
  if (nodeView) {
140
133
  const wrapper = createWrapperWithStrikethrough();
141
134
  wrapper.append(nodeView.dom);
@@ -7,11 +7,11 @@ import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform'
7
7
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
8
  import { createInlineChangedDecoration, createDeletedContentDecoration } from './decorations';
9
9
  import { getMarkChangeRanges } from './markDecorations';
10
+ import { NodeViewSerializer } from './NodeViewSerializer';
10
11
  const calculateDecorations = ({
11
12
  state,
12
13
  pluginState,
13
- editorView,
14
- nodeViews
14
+ nodeViewSerializer
15
15
  }) => {
16
16
  const {
17
17
  originalDoc,
@@ -45,9 +45,7 @@ const calculateDecorations = ({
45
45
  decorations.push(createDeletedContentDecoration({
46
46
  change,
47
47
  doc: originalDoc,
48
- tr,
49
- editorView,
50
- nodeViews
48
+ nodeViewSerializer
51
49
  }));
52
50
  }
53
51
  });
@@ -58,64 +56,43 @@ const calculateDecorations = ({
58
56
  };
59
57
  export const showDiffPluginKey = new PluginKey('showDiffPlugin');
60
58
  export const createPlugin = config => {
61
- let editorView;
62
- const setEditorView = newEditorView => {
63
- editorView = newEditorView;
59
+ const nodeViewSerializer = new NodeViewSerializer({});
60
+ const setNodeViewSerializer = editorView => {
61
+ nodeViewSerializer.init({
62
+ editorView
63
+ });
64
64
  };
65
65
  return new SafePlugin({
66
66
  key: showDiffPluginKey,
67
67
  state: {
68
68
  init(_, state) {
69
- var _config$steps, _config$steps2, _editorView;
70
- const schema = state.schema;
71
- const isDisplayingChanges = ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).length > 0;
72
- const steps = ((_config$steps2 = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps2 !== void 0 ? _config$steps2 : []).map(step => ProseMirrorStep.fromJSON(schema, step));
73
-
74
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
- const nodeViews = ((_editorView = editorView) === null || _editorView === void 0 ? void 0 : _editorView.nodeViews) || {};
69
+ // We do initial setup after we setup the editor view
76
70
  return {
77
- steps,
78
- originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined,
79
- decorations: calculateDecorations({
80
- state,
81
- pluginState: {
82
- steps,
83
- originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined,
84
- isDisplayingChanges
85
- },
86
- editorView,
87
- nodeViews
88
- }),
89
- isDisplayingChanges
71
+ steps: [],
72
+ originalDoc: undefined,
73
+ decorations: DecorationSet.empty,
74
+ isDisplayingChanges: false
90
75
  };
91
76
  },
92
77
  apply: (tr, currentPluginState, oldState, newState) => {
93
- var _editorView2;
94
78
  const meta = tr.getMeta(showDiffPluginKey);
95
79
  let newPluginState = currentPluginState;
96
-
97
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
- const nodeViews = ((_editorView2 = editorView) === null || _editorView2 === void 0 ? void 0 : _editorView2.nodeViews) || {};
99
80
  if (meta) {
100
81
  if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'SHOW_DIFF') {
101
- var _meta$steps, _meta$originalDoc;
102
- // Calculate and store decorations in state
103
- const decorations = calculateDecorations({
104
- state: newState,
105
- pluginState: {
106
- steps: (_meta$steps = meta.steps) !== null && _meta$steps !== void 0 ? _meta$steps : currentPluginState.steps,
107
- originalDoc: (_meta$originalDoc = meta.originalDoc) !== null && _meta$originalDoc !== void 0 ? _meta$originalDoc : currentPluginState.originalDoc,
108
- isDisplayingChanges: true
109
- },
110
- editorView,
111
- nodeViews: nodeViews
112
- });
82
+ // Update the plugin state with the new metadata
113
83
  newPluginState = {
114
84
  ...currentPluginState,
115
85
  ...meta,
116
- decorations,
117
86
  isDisplayingChanges: true
118
87
  };
88
+ // Calculate and store decorations in state
89
+ const decorations = calculateDecorations({
90
+ state: newState,
91
+ pluginState: newPluginState,
92
+ nodeViewSerializer
93
+ });
94
+ // Update the decorations
95
+ newPluginState.decorations = decorations;
119
96
  } else if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'HIDE_DIFF') {
120
97
  newPluginState = {
121
98
  ...currentPluginState,
@@ -137,8 +114,21 @@ export const createPlugin = config => {
137
114
  }
138
115
  },
139
116
  view(editorView) {
140
- setEditorView(editorView);
141
- return {};
117
+ setNodeViewSerializer(editorView);
118
+ let isFirst = true;
119
+ return {
120
+ update(view) {
121
+ // If we're using configuration to show diffs we initialise here once we setup the editor view
122
+ if (config !== null && config !== void 0 && config.originalDoc && config !== null && config !== void 0 && config.steps && config.steps.length > 0 && isFirst) {
123
+ isFirst = false;
124
+ view.dispatch(view.state.tr.setMeta(showDiffPluginKey, {
125
+ action: 'SHOW_DIFF',
126
+ steps: config.steps.map(step => ProseMirrorStep.fromJSON(view.state.schema, step)),
127
+ originalDoc: processRawValue(view.state.schema, config.originalDoc)
128
+ }));
129
+ }
130
+ }
131
+ };
142
132
  },
143
133
  props: {
144
134
  decorations: state => {
@@ -39,29 +39,48 @@ export function isEditorViewWithNodeViews(view) {
39
39
  */
40
40
  export var NodeViewSerializer = /*#__PURE__*/function () {
41
41
  function NodeViewSerializer(params) {
42
- var _ref, _params$nodeViews, _this$editorView, _params$blocklist;
42
+ var _params$blocklist;
43
43
  _classCallCheck(this, NodeViewSerializer);
44
- this.serializer = DOMSerializer.fromSchema(params.schema);
45
- if (params.editorView && isEditorViewWithNodeViews(params.editorView)) {
46
- this.editorView = params.editorView;
44
+ if (params !== null && params !== void 0 && params.editorView) {
45
+ this.init({
46
+ editorView: params.editorView
47
+ });
47
48
  }
48
- this.nodeViews = (_ref = (_params$nodeViews = params.nodeViews) !== null && _params$nodeViews !== void 0 ? _params$nodeViews : (_this$editorView = this.editorView) === null || _this$editorView === void 0 ? void 0 : _this$editorView.nodeViews) !== null && _ref !== void 0 ? _ref : {};
49
49
  this.nodeViewBlocklist = new Set((_params$blocklist = params.blocklist) !== null && _params$blocklist !== void 0 ? _params$blocklist : ['tableRow', 'table', 'paragraph']);
50
50
  }
51
51
 
52
52
  /**
53
- * Attempts to create a node view for the given node.
54
- *
55
- * Returns `null` when there is no `EditorView`, no constructor for the node type,
56
- * or the node type is blocklisted. Otherwise returns the constructed node view instance.
53
+ * Initializes or reinitializes the NodeViewSerializer with a new EditorView.
54
+ * This allows the same serializer instance to be reused across different editor states.
57
55
  */
58
56
  return _createClass(NodeViewSerializer, [{
57
+ key: "init",
58
+ value: function init(params) {
59
+ var _params$editorView, _ref, _this$editorView;
60
+ this.serializer = DOMSerializer.fromSchema(params.editorView.state.schema);
61
+ if (isEditorViewWithNodeViews(params.editorView)) {
62
+ this.editorView = params.editorView;
63
+ }
64
+ var nodeViews =
65
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
+ ((_params$editorView = params.editorView) === null || _params$editorView === void 0 ? void 0 : _params$editorView.nodeViews) || {};
67
+ this.nodeViews = (_ref = nodeViews !== null && nodeViews !== void 0 ? nodeViews : (_this$editorView = this.editorView) === null || _this$editorView === void 0 ? void 0 : _this$editorView.nodeViews) !== null && _ref !== void 0 ? _ref : {};
68
+ }
69
+
70
+ /**
71
+ * Attempts to create a node view for the given node.
72
+ *
73
+ * Returns `null` when there is no `EditorView`, no constructor for the node type,
74
+ * or the node type is blocklisted. Otherwise returns the constructed node view instance.
75
+ */
76
+ }, {
59
77
  key: "tryCreateNodeView",
60
78
  value: function tryCreateNodeView(targetNode) {
79
+ var _this$nodeViews;
61
80
  if (!this.editorView) {
62
81
  return null;
63
82
  }
64
- var constructor = this.nodeViews[targetNode.type.name];
83
+ var constructor = (_this$nodeViews = this.nodeViews) === null || _this$nodeViews === void 0 ? void 0 : _this$nodeViews[targetNode.type.name];
65
84
  if (!constructor) {
66
85
  return null;
67
86
  }
@@ -79,6 +98,9 @@ export var NodeViewSerializer = /*#__PURE__*/function () {
79
98
  }, {
80
99
  key: "serializeNode",
81
100
  value: function serializeNode(node) {
101
+ if (!this.serializer) {
102
+ throw new Error('NodeViewSerializer must be initialized with init() before use');
103
+ }
82
104
  return this.serializer.serializeNode(node);
83
105
  }
84
106
 
@@ -88,6 +110,9 @@ export var NodeViewSerializer = /*#__PURE__*/function () {
88
110
  }, {
89
111
  key: "serializeFragment",
90
112
  value: function serializeFragment(fragment) {
113
+ if (!this.serializer) {
114
+ throw new Error('NodeViewSerializer must be initialized with init() before use');
115
+ }
91
116
  return this.serializer.serializeFragment(fragment);
92
117
  }
93
118
  }]);
@@ -1,6 +1,5 @@
1
1
  import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
2
2
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
- import { NodeViewSerializer } from './NodeViewSerializer';
4
3
  var style = convertToInlineCss({
5
4
  background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
6
5
  textDecoration: 'underline',
@@ -47,9 +46,7 @@ var deletedContentStyleUnbounded = convertToInlineCss({
47
46
  export var createDeletedContentDecoration = function createDeletedContentDecoration(_ref) {
48
47
  var change = _ref.change,
49
48
  doc = _ref.doc,
50
- tr = _ref.tr,
51
- editorView = _ref.editorView,
52
- nodeViews = _ref.nodeViews;
49
+ nodeViewSerializer = _ref.nodeViewSerializer;
53
50
  var dom = document.createElement('span');
54
51
  dom.setAttribute('style', deletedContentStyle);
55
52
 
@@ -59,11 +56,7 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
59
56
  * or sliced End depth is and match only the content and not with the entire node.
60
57
  */
61
58
  var slice = doc.slice(change.fromA, change.toA);
62
- var nodeViewSerializer = new NodeViewSerializer({
63
- schema: tr.doc.type.schema,
64
- editorView: editorView,
65
- nodeViews: nodeViews
66
- });
59
+ var serializer = nodeViewSerializer;
67
60
  slice.content.forEach(function (node) {
68
61
  // Create a wrapper for each node with strikethrough
69
62
  var createWrapperWithStrikethrough = function createWrapperWithStrikethrough() {
@@ -80,7 +73,7 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
80
73
  var handleMultipleChildNodes = function handleMultipleChildNodes(node) {
81
74
  if (node.content.childCount > 1 && node.type.inlineContent) {
82
75
  node.content.forEach(function (childNode) {
83
- var childNodeView = nodeViewSerializer.tryCreateNodeView(childNode);
76
+ var childNodeView = serializer.tryCreateNodeView(childNode);
84
77
  if (childNodeView) {
85
78
  var lineBreak = document.createElement('br');
86
79
  targetNode = node;
@@ -90,7 +83,7 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
90
83
  dom.append(wrapper);
91
84
  } else {
92
85
  // Fallback to serializing the individual child node
93
- var serializedChild = nodeViewSerializer.serializeNode(childNode);
86
+ var serializedChild = serializer.serializeNode(childNode);
94
87
  dom.append(serializedChild);
95
88
  }
96
89
  });
@@ -111,7 +104,7 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
111
104
  }
112
105
  targetNode = node.content.content[0];
113
106
  fallbackSerialization = function fallbackSerialization() {
114
- return nodeViewSerializer.serializeFragment(node.content);
107
+ return serializer.serializeFragment(node.content);
115
108
  };
116
109
  } else if (isLast && slice.content.childCount === 2) {
117
110
  if (handleMultipleChildNodes(node)) {
@@ -125,9 +118,9 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
125
118
  if (node.type.name === 'paragraph') {
126
119
  var lineBreak = document.createElement('br');
127
120
  dom.append(lineBreak);
128
- return nodeViewSerializer.serializeFragment(node.content);
121
+ return serializer.serializeFragment(node.content);
129
122
  }
130
- return nodeViewSerializer.serializeFragment(node.content);
123
+ return serializer.serializeFragment(node.content);
131
124
  };
132
125
  } else {
133
126
  if (handleMultipleChildNodes(node)) {
@@ -135,12 +128,12 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
135
128
  }
136
129
  targetNode = node.content.content[0] || node;
137
130
  fallbackSerialization = function fallbackSerialization() {
138
- return nodeViewSerializer.serializeNode(node);
131
+ return serializer.serializeNode(node);
139
132
  };
140
133
  }
141
134
 
142
135
  // Try to create node view, fallback to serialization
143
- var nodeView = nodeViewSerializer.tryCreateNodeView(targetNode);
136
+ var nodeView = serializer.tryCreateNodeView(targetNode);
144
137
  if (nodeView) {
145
138
  var wrapper = createWrapperWithStrikethrough();
146
139
  wrapper.append(nodeView.dom);
@@ -13,11 +13,11 @@ import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform'
13
13
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
14
14
  import { createInlineChangedDecoration, createDeletedContentDecoration } from './decorations';
15
15
  import { getMarkChangeRanges } from './markDecorations';
16
+ import { NodeViewSerializer } from './NodeViewSerializer';
16
17
  var calculateDecorations = function calculateDecorations(_ref) {
17
18
  var state = _ref.state,
18
19
  pluginState = _ref.pluginState,
19
- editorView = _ref.editorView,
20
- nodeViews = _ref.nodeViews;
20
+ nodeViewSerializer = _ref.nodeViewSerializer;
21
21
  var originalDoc = pluginState.originalDoc,
22
22
  steps = pluginState.steps;
23
23
  if (!originalDoc || !pluginState.isDisplayingChanges) {
@@ -55,9 +55,7 @@ var calculateDecorations = function calculateDecorations(_ref) {
55
55
  decorations.push(createDeletedContentDecoration({
56
56
  change: change,
57
57
  doc: originalDoc,
58
- tr: tr,
59
- editorView: editorView,
60
- nodeViews: nodeViews
58
+ nodeViewSerializer: nodeViewSerializer
61
59
  }));
62
60
  }
63
61
  });
@@ -68,64 +66,41 @@ var calculateDecorations = function calculateDecorations(_ref) {
68
66
  };
69
67
  export var showDiffPluginKey = new PluginKey('showDiffPlugin');
70
68
  export var createPlugin = function createPlugin(config) {
71
- var editorView;
72
- var setEditorView = function setEditorView(newEditorView) {
73
- editorView = newEditorView;
69
+ var nodeViewSerializer = new NodeViewSerializer({});
70
+ var setNodeViewSerializer = function setNodeViewSerializer(editorView) {
71
+ nodeViewSerializer.init({
72
+ editorView: editorView
73
+ });
74
74
  };
75
75
  return new SafePlugin({
76
76
  key: showDiffPluginKey,
77
77
  state: {
78
78
  init: function init(_, state) {
79
- var _config$steps, _config$steps2, _editorView;
80
- var schema = state.schema;
81
- var isDisplayingChanges = ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).length > 0;
82
- var steps = ((_config$steps2 = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps2 !== void 0 ? _config$steps2 : []).map(function (step) {
83
- return ProseMirrorStep.fromJSON(schema, step);
84
- });
85
-
86
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
- var nodeViews = ((_editorView = editorView) === null || _editorView === void 0 ? void 0 : _editorView.nodeViews) || {};
79
+ // We do initial setup after we setup the editor view
88
80
  return {
89
- steps: steps,
90
- originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined,
91
- decorations: calculateDecorations({
92
- state: state,
93
- pluginState: {
94
- steps: steps,
95
- originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined,
96
- isDisplayingChanges: isDisplayingChanges
97
- },
98
- editorView: editorView,
99
- nodeViews: nodeViews
100
- }),
101
- isDisplayingChanges: isDisplayingChanges
81
+ steps: [],
82
+ originalDoc: undefined,
83
+ decorations: DecorationSet.empty,
84
+ isDisplayingChanges: false
102
85
  };
103
86
  },
104
87
  apply: function apply(tr, currentPluginState, oldState, newState) {
105
- var _editorView2;
106
88
  var meta = tr.getMeta(showDiffPluginKey);
107
89
  var newPluginState = currentPluginState;
108
-
109
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
110
- var nodeViews = ((_editorView2 = editorView) === null || _editorView2 === void 0 ? void 0 : _editorView2.nodeViews) || {};
111
90
  if (meta) {
112
91
  if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'SHOW_DIFF') {
113
- var _meta$steps, _meta$originalDoc;
92
+ // Update the plugin state with the new metadata
93
+ newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
94
+ isDisplayingChanges: true
95
+ });
114
96
  // Calculate and store decorations in state
115
97
  var decorations = calculateDecorations({
116
98
  state: newState,
117
- pluginState: {
118
- steps: (_meta$steps = meta.steps) !== null && _meta$steps !== void 0 ? _meta$steps : currentPluginState.steps,
119
- originalDoc: (_meta$originalDoc = meta.originalDoc) !== null && _meta$originalDoc !== void 0 ? _meta$originalDoc : currentPluginState.originalDoc,
120
- isDisplayingChanges: true
121
- },
122
- editorView: editorView,
123
- nodeViews: nodeViews
124
- });
125
- newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
126
- decorations: decorations,
127
- isDisplayingChanges: true
99
+ pluginState: newPluginState,
100
+ nodeViewSerializer: nodeViewSerializer
128
101
  });
102
+ // Update the decorations
103
+ newPluginState.decorations = decorations;
129
104
  } else if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'HIDE_DIFF') {
130
105
  newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
131
106
  decorations: DecorationSet.empty,
@@ -141,8 +116,23 @@ export var createPlugin = function createPlugin(config) {
141
116
  }
142
117
  },
143
118
  view: function view(editorView) {
144
- setEditorView(editorView);
145
- return {};
119
+ setNodeViewSerializer(editorView);
120
+ var isFirst = true;
121
+ return {
122
+ update: function update(view) {
123
+ // If we're using configuration to show diffs we initialise here once we setup the editor view
124
+ if (config !== null && config !== void 0 && config.originalDoc && config !== null && config !== void 0 && config.steps && config.steps.length > 0 && isFirst) {
125
+ isFirst = false;
126
+ view.dispatch(view.state.tr.setMeta(showDiffPluginKey, {
127
+ action: 'SHOW_DIFF',
128
+ steps: config.steps.map(function (step) {
129
+ return ProseMirrorStep.fromJSON(view.state.schema, step);
130
+ }),
131
+ originalDoc: processRawValue(view.state.schema, config.originalDoc)
132
+ }));
133
+ }
134
+ }
135
+ };
146
136
  },
147
137
  props: {
148
138
  decorations: function decorations(state) {
@@ -1,5 +1,5 @@
1
1
  import { type NodeViewConstructor } from '@atlaskit/editor-common/lazy-node-view';
2
- import type { Schema, Node as PMNode, Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ import type { Node as PMNode, Fragment } from '@atlaskit/editor-prosemirror/model';
3
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
  /**
5
5
  * Utilities for working with ProseMirror node views and DOM serialization within the
@@ -34,16 +34,21 @@ export declare function isEditorViewWithNodeViews(view: EditorView): view is Edi
34
34
  * - Preventing node view creation for blocklisted node types
35
35
  */
36
36
  export declare class NodeViewSerializer {
37
- private serializer;
38
37
  private editorView?;
39
- private nodeViews;
38
+ private serializer?;
39
+ private nodeViews?;
40
40
  private nodeViewBlocklist;
41
41
  constructor(params: {
42
42
  blocklist?: string[];
43
43
  editorView?: EditorView;
44
- nodeViews?: Record<string, NodeViewConstructor>;
45
- schema: Schema;
46
44
  });
45
+ /**
46
+ * Initializes or reinitializes the NodeViewSerializer with a new EditorView.
47
+ * This allows the same serializer instance to be reused across different editor states.
48
+ */
49
+ init(params: {
50
+ editorView: EditorView;
51
+ }): void;
47
52
  /**
48
53
  * Attempts to create a node view for the given node.
49
54
  *
@@ -1,9 +1,7 @@
1
1
  import type { Change } from 'prosemirror-changeset';
2
- import { type NodeViewConstructor } from '@atlaskit/editor-common/lazy-node-view';
3
2
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
5
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
3
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
4
+ import type { NodeViewSerializer } from './NodeViewSerializer';
7
5
  /**
8
6
  * Inline decoration used for insertions as the content already exists in the document
9
7
  *
@@ -17,9 +15,7 @@ export declare const createInlineChangedDecoration: (change: {
17
15
  interface DeletedContentDecorationProps {
18
16
  change: Change;
19
17
  doc: PMNode;
20
- editorView?: EditorView;
21
- nodeViews: Record<string, NodeViewConstructor>;
22
- tr: Transaction;
18
+ nodeViewSerializer: NodeViewSerializer;
23
19
  }
24
20
  /**
25
21
  * Creates a widget to represent the deleted content in the editor
@@ -29,5 +25,5 @@ interface DeletedContentDecorationProps {
29
25
  * @param props.tr The relevant transaction this decoration is being created against
30
26
  * @returns Prosemirror widget decoration
31
27
  */
32
- export declare const createDeletedContentDecoration: ({ change, doc, tr, editorView, nodeViews, }: DeletedContentDecorationProps) => Decoration;
28
+ export declare const createDeletedContentDecoration: ({ change, doc, nodeViewSerializer, }: DeletedContentDecorationProps) => Decoration;
33
29
  export {};
@@ -1,5 +1,5 @@
1
1
  import { type NodeViewConstructor } from '@atlaskit/editor-common/lazy-node-view';
2
- import type { Schema, Node as PMNode, Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ import type { Node as PMNode, Fragment } from '@atlaskit/editor-prosemirror/model';
3
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
  /**
5
5
  * Utilities for working with ProseMirror node views and DOM serialization within the
@@ -34,16 +34,21 @@ export declare function isEditorViewWithNodeViews(view: EditorView): view is Edi
34
34
  * - Preventing node view creation for blocklisted node types
35
35
  */
36
36
  export declare class NodeViewSerializer {
37
- private serializer;
38
37
  private editorView?;
39
- private nodeViews;
38
+ private serializer?;
39
+ private nodeViews?;
40
40
  private nodeViewBlocklist;
41
41
  constructor(params: {
42
42
  blocklist?: string[];
43
43
  editorView?: EditorView;
44
- nodeViews?: Record<string, NodeViewConstructor>;
45
- schema: Schema;
46
44
  });
45
+ /**
46
+ * Initializes or reinitializes the NodeViewSerializer with a new EditorView.
47
+ * This allows the same serializer instance to be reused across different editor states.
48
+ */
49
+ init(params: {
50
+ editorView: EditorView;
51
+ }): void;
47
52
  /**
48
53
  * Attempts to create a node view for the given node.
49
54
  *
@@ -1,9 +1,7 @@
1
1
  import type { Change } from 'prosemirror-changeset';
2
- import { type NodeViewConstructor } from '@atlaskit/editor-common/lazy-node-view';
3
2
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
5
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
3
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
4
+ import type { NodeViewSerializer } from './NodeViewSerializer';
7
5
  /**
8
6
  * Inline decoration used for insertions as the content already exists in the document
9
7
  *
@@ -17,9 +15,7 @@ export declare const createInlineChangedDecoration: (change: {
17
15
  interface DeletedContentDecorationProps {
18
16
  change: Change;
19
17
  doc: PMNode;
20
- editorView?: EditorView;
21
- nodeViews: Record<string, NodeViewConstructor>;
22
- tr: Transaction;
18
+ nodeViewSerializer: NodeViewSerializer;
23
19
  }
24
20
  /**
25
21
  * Creates a widget to represent the deleted content in the editor
@@ -29,5 +25,5 @@ interface DeletedContentDecorationProps {
29
25
  * @param props.tr The relevant transaction this decoration is being created against
30
26
  * @returns Prosemirror widget decoration
31
27
  */
32
- export declare const createDeletedContentDecoration: ({ change, doc, tr, editorView, nodeViews, }: DeletedContentDecorationProps) => Decoration;
28
+ export declare const createDeletedContentDecoration: ({ change, doc, nodeViewSerializer, }: DeletedContentDecorationProps) => Decoration;
33
29
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-show-diff",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "ShowDiff plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -37,7 +37,7 @@
37
37
  "prosemirror-changeset": "^2.2.1"
38
38
  },
39
39
  "peerDependencies": {
40
- "@atlaskit/editor-common": "^107.28.0",
40
+ "@atlaskit/editor-common": "^107.31.0",
41
41
  "react": "^18.2.0"
42
42
  },
43
43
  "techstack": {