@atlaskit/editor-plugin-show-diff 3.1.0 → 3.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 +7 -0
- package/dist/cjs/pm-plugins/calculateDiffDecorations.js +2 -1
- package/dist/cjs/pm-plugins/decorations.js +5 -2
- package/dist/cjs/pm-plugins/findSafeInsertPos.js +28 -0
- package/dist/es2019/pm-plugins/calculateDiffDecorations.js +2 -1
- package/dist/es2019/pm-plugins/decorations.js +5 -2
- package/dist/es2019/pm-plugins/findSafeInsertPos.js +23 -0
- package/dist/esm/pm-plugins/calculateDiffDecorations.js +2 -1
- package/dist/esm/pm-plugins/decorations.js +5 -2
- package/dist/esm/pm-plugins/findSafeInsertPos.js +23 -0
- package/dist/types/pm-plugins/decorations.d.ts +2 -1
- package/dist/types/pm-plugins/findSafeInsertPos.d.ts +9 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/findSafeInsertPos.d.ts +9 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-show-diff
|
|
2
2
|
|
|
3
|
+
## 3.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`174d939cfd1ba`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/174d939cfd1ba) -
|
|
8
|
+
Use valid positioning for deleted diff content to avoid invalid nesting diffs
|
|
9
|
+
|
|
3
10
|
## 3.1.0
|
|
4
11
|
|
|
5
12
|
### Minor Changes
|
|
@@ -140,7 +140,8 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref)
|
|
|
140
140
|
change: change,
|
|
141
141
|
doc: originalDoc,
|
|
142
142
|
nodeViewSerializer: nodeViewSerializer,
|
|
143
|
-
colourScheme: colourScheme
|
|
143
|
+
colourScheme: colourScheme,
|
|
144
|
+
newDoc: tr.doc
|
|
144
145
|
});
|
|
145
146
|
if (decoration) {
|
|
146
147
|
decorations.push(decoration);
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.createInlineChangedDecoration = exports.createDeletedContentDecoration = exports.createBlockChangedDecoration = void 0;
|
|
7
7
|
var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
|
|
8
8
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
9
|
+
var _findSafeInsertPos = require("./findSafeInsertPos");
|
|
9
10
|
var editingStyle = (0, _lazyNodeView.convertToInlineCss)({
|
|
10
11
|
background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
|
|
11
12
|
textDecoration: 'underline',
|
|
@@ -151,7 +152,8 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
|
|
|
151
152
|
var change = _ref.change,
|
|
152
153
|
doc = _ref.doc,
|
|
153
154
|
nodeViewSerializer = _ref.nodeViewSerializer,
|
|
154
|
-
colourScheme = _ref.colourScheme
|
|
155
|
+
colourScheme = _ref.colourScheme,
|
|
156
|
+
newDoc = _ref.newDoc;
|
|
155
157
|
var slice = doc.slice(change.fromA, change.toA);
|
|
156
158
|
if (slice.content.content.length === 0) {
|
|
157
159
|
return;
|
|
@@ -277,5 +279,6 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
|
|
|
277
279
|
|
|
278
280
|
// Widget decoration used for deletions as the content is not in the document
|
|
279
281
|
// and we want to display the deleted content with a style.
|
|
280
|
-
|
|
282
|
+
var safeInsertPos = (0, _findSafeInsertPos.findSafeInsertPos)(newDoc, change.fromB, slice);
|
|
283
|
+
return _view.Decoration.widget(safeInsertPos, dom, {});
|
|
281
284
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findSafeInsertPos = findSafeInsertPos;
|
|
7
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
8
|
+
/**
|
|
9
|
+
* Find a safe position to insert a deletion slice at the given position.
|
|
10
|
+
* @param doc
|
|
11
|
+
* @param pos
|
|
12
|
+
* @param slice
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
function findSafeInsertPos(doc, pos, slice) {
|
|
16
|
+
if (pos > doc.content.size) {
|
|
17
|
+
return doc.content.size;
|
|
18
|
+
}
|
|
19
|
+
var $pos = doc.resolve(pos);
|
|
20
|
+
while (!(0, _utils.canInsert)($pos, slice.content) && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type.name) !== 'paragraph') {
|
|
21
|
+
var _slice$content$firstC;
|
|
22
|
+
if ($pos.pos + 1 > doc.content.size) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
$pos = doc.resolve($pos.pos + 1);
|
|
26
|
+
}
|
|
27
|
+
return $pos.pos;
|
|
28
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
|
|
2
2
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import { findSafeInsertPos } from './findSafeInsertPos';
|
|
3
4
|
const editingStyle = convertToInlineCss({
|
|
4
5
|
background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
|
|
5
6
|
textDecoration: 'underline',
|
|
@@ -137,7 +138,8 @@ export const createDeletedContentDecoration = ({
|
|
|
137
138
|
change,
|
|
138
139
|
doc,
|
|
139
140
|
nodeViewSerializer,
|
|
140
|
-
colourScheme
|
|
141
|
+
colourScheme,
|
|
142
|
+
newDoc
|
|
141
143
|
}) => {
|
|
142
144
|
const slice = doc.slice(change.fromA, change.toA);
|
|
143
145
|
if (slice.content.content.length === 0) {
|
|
@@ -256,5 +258,6 @@ export const createDeletedContentDecoration = ({
|
|
|
256
258
|
|
|
257
259
|
// Widget decoration used for deletions as the content is not in the document
|
|
258
260
|
// and we want to display the deleted content with a style.
|
|
259
|
-
|
|
261
|
+
const safeInsertPos = findSafeInsertPos(newDoc, change.fromB, slice);
|
|
262
|
+
return Decoration.widget(safeInsertPos, dom, {});
|
|
260
263
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { canInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Find a safe position to insert a deletion slice at the given position.
|
|
5
|
+
* @param doc
|
|
6
|
+
* @param pos
|
|
7
|
+
* @param slice
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export function findSafeInsertPos(doc, pos, slice) {
|
|
11
|
+
if (pos > doc.content.size) {
|
|
12
|
+
return doc.content.size;
|
|
13
|
+
}
|
|
14
|
+
let $pos = doc.resolve(pos);
|
|
15
|
+
while (!canInsert($pos, slice.content) && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type.name) !== 'paragraph') {
|
|
16
|
+
var _slice$content$firstC;
|
|
17
|
+
if ($pos.pos + 1 > doc.content.size) {
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
$pos = doc.resolve($pos.pos + 1);
|
|
21
|
+
}
|
|
22
|
+
return $pos.pos;
|
|
23
|
+
}
|
|
@@ -134,7 +134,8 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref)
|
|
|
134
134
|
change: change,
|
|
135
135
|
doc: originalDoc,
|
|
136
136
|
nodeViewSerializer: nodeViewSerializer,
|
|
137
|
-
colourScheme: colourScheme
|
|
137
|
+
colourScheme: colourScheme,
|
|
138
|
+
newDoc: tr.doc
|
|
138
139
|
});
|
|
139
140
|
if (decoration) {
|
|
140
141
|
decorations.push(decoration);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
|
|
2
2
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import { findSafeInsertPos } from './findSafeInsertPos';
|
|
3
4
|
var editingStyle = convertToInlineCss({
|
|
4
5
|
background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
|
|
5
6
|
textDecoration: 'underline',
|
|
@@ -145,7 +146,8 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
|
|
|
145
146
|
var change = _ref.change,
|
|
146
147
|
doc = _ref.doc,
|
|
147
148
|
nodeViewSerializer = _ref.nodeViewSerializer,
|
|
148
|
-
colourScheme = _ref.colourScheme
|
|
149
|
+
colourScheme = _ref.colourScheme,
|
|
150
|
+
newDoc = _ref.newDoc;
|
|
149
151
|
var slice = doc.slice(change.fromA, change.toA);
|
|
150
152
|
if (slice.content.content.length === 0) {
|
|
151
153
|
return;
|
|
@@ -271,5 +273,6 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
|
|
|
271
273
|
|
|
272
274
|
// Widget decoration used for deletions as the content is not in the document
|
|
273
275
|
// and we want to display the deleted content with a style.
|
|
274
|
-
|
|
276
|
+
var safeInsertPos = findSafeInsertPos(newDoc, change.fromB, slice);
|
|
277
|
+
return Decoration.widget(safeInsertPos, dom, {});
|
|
275
278
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { canInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Find a safe position to insert a deletion slice at the given position.
|
|
5
|
+
* @param doc
|
|
6
|
+
* @param pos
|
|
7
|
+
* @param slice
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export function findSafeInsertPos(doc, pos, slice) {
|
|
11
|
+
if (pos > doc.content.size) {
|
|
12
|
+
return doc.content.size;
|
|
13
|
+
}
|
|
14
|
+
var $pos = doc.resolve(pos);
|
|
15
|
+
while (!canInsert($pos, slice.content) && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type.name) !== 'paragraph') {
|
|
16
|
+
var _slice$content$firstC;
|
|
17
|
+
if ($pos.pos + 1 > doc.content.size) {
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
$pos = doc.resolve($pos.pos + 1);
|
|
21
|
+
}
|
|
22
|
+
return $pos.pos;
|
|
23
|
+
}
|
|
@@ -27,7 +27,8 @@ interface DeletedContentDecorationProps {
|
|
|
27
27
|
change: Change;
|
|
28
28
|
colourScheme?: 'standard' | 'traditional';
|
|
29
29
|
doc: PMNode;
|
|
30
|
+
newDoc: PMNode;
|
|
30
31
|
nodeViewSerializer: NodeViewSerializer;
|
|
31
32
|
}
|
|
32
|
-
export declare const createDeletedContentDecoration: ({ change, doc, nodeViewSerializer, colourScheme, }: DeletedContentDecorationProps) => Decoration | undefined;
|
|
33
|
+
export declare const createDeletedContentDecoration: ({ change, doc, nodeViewSerializer, colourScheme, newDoc, }: DeletedContentDecorationProps) => Decoration | undefined;
|
|
33
34
|
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Node as PMNode, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
/**
|
|
3
|
+
* Find a safe position to insert a deletion slice at the given position.
|
|
4
|
+
* @param doc
|
|
5
|
+
* @param pos
|
|
6
|
+
* @param slice
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function findSafeInsertPos(doc: PMNode, pos: number, slice: Slice): number;
|
|
@@ -27,7 +27,8 @@ interface DeletedContentDecorationProps {
|
|
|
27
27
|
change: Change;
|
|
28
28
|
colourScheme?: 'standard' | 'traditional';
|
|
29
29
|
doc: PMNode;
|
|
30
|
+
newDoc: PMNode;
|
|
30
31
|
nodeViewSerializer: NodeViewSerializer;
|
|
31
32
|
}
|
|
32
|
-
export declare const createDeletedContentDecoration: ({ change, doc, nodeViewSerializer, colourScheme, }: DeletedContentDecorationProps) => Decoration | undefined;
|
|
33
|
+
export declare const createDeletedContentDecoration: ({ change, doc, nodeViewSerializer, colourScheme, newDoc, }: DeletedContentDecorationProps) => Decoration | undefined;
|
|
33
34
|
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Node as PMNode, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
/**
|
|
3
|
+
* Find a safe position to insert a deletion slice at the given position.
|
|
4
|
+
* @param doc
|
|
5
|
+
* @param pos
|
|
6
|
+
* @param slice
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function findSafeInsertPos(doc: PMNode, pos: number, slice: Slice): number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-show-diff",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
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": "^110.
|
|
40
|
+
"@atlaskit/editor-common": "^110.15.0",
|
|
41
41
|
"react": "^18.2.0"
|
|
42
42
|
},
|
|
43
43
|
"techstack": {
|