@manuscripts/track-changes-plugin 1.7.23-LEAN-3893.2 → 1.7.23
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.
|
@@ -1,38 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.revertRejectedChanges = void 0;
|
|
4
|
-
const
|
|
4
|
+
const prosemirror_transform_1 = require("prosemirror-transform");
|
|
5
5
|
const nodeHelpers_1 = require("../compute/nodeHelpers");
|
|
6
6
|
const change_1 = require("../types/change");
|
|
7
7
|
const applyChanges_1 = require("./applyChanges");
|
|
8
8
|
function revertSplitNodeChange(tr, change, changeSet) {
|
|
9
9
|
let sourceChange = changeSet.changes.find((c) => c.dataTracked.operation === 'reference' && c.dataTracked.referenceId === change.id);
|
|
10
|
-
const node = tr.doc.nodeAt(change.from);
|
|
11
|
-
tr.
|
|
12
|
-
tr.replaceWith(sourceChange.to - 1, sourceChange.to, node.content);
|
|
10
|
+
const node = tr.doc.nodeAt(tr.mapping.map(change.from));
|
|
11
|
+
tr.delete(tr.mapping.map(change.from), tr.mapping.map(change.to));
|
|
12
|
+
tr.replaceWith(tr.mapping.map(sourceChange.to - 1), tr.mapping.map(sourceChange.to), node.content);
|
|
13
13
|
if (change.node.type.name === 'list_item') {
|
|
14
14
|
tr.join(sourceChange.to - 1);
|
|
15
15
|
}
|
|
16
16
|
const childSource = changeSet.changes.find((c) => c.from === change.from && c.dataTracked.operation === 'reference');
|
|
17
17
|
if (childSource) {
|
|
18
|
-
const node = tr.doc.nodeAt(sourceChange.from);
|
|
18
|
+
const node = tr.doc.nodeAt(tr.mapping.map(sourceChange.from));
|
|
19
19
|
const dataTracked = (0, nodeHelpers_1.getBlockInlineTrackedData)(node).map((c) => c.operation === 'reference' ? childSource.dataTracked : c);
|
|
20
|
-
tr.setNodeMarkup(sourceChange.from, undefined, Object.assign(Object.assign({}, node.attrs), { dataTracked }), node.marks);
|
|
20
|
+
tr.setNodeMarkup(tr.mapping.map(sourceChange.from), undefined, Object.assign(Object.assign({}, node.attrs), { dataTracked }), node.marks);
|
|
21
21
|
}
|
|
22
22
|
const deleteChange = changeSet.changes.find((c) => c.dataTracked.operation == 'delete' && c.from === sourceChange.from);
|
|
23
23
|
if (deleteChange) {
|
|
24
|
-
const node = tr.doc.nodeAt(deleteChange.from);
|
|
25
|
-
tr.setNodeMarkup(deleteChange.from, undefined, (0, applyChanges_1.getUpdatedDataTracked)(node.attrs.dataTracked, deleteChange.id));
|
|
24
|
+
const node = tr.doc.nodeAt(tr.mapping.map(deleteChange.from));
|
|
25
|
+
tr.setNodeMarkup(tr.mapping.map(deleteChange.from), undefined, (0, applyChanges_1.getUpdatedDataTracked)(node.attrs.dataTracked, deleteChange.id));
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
function revertWrapNodeChange(tr, change) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
tr.doc.nodesBetween(change.from, change.to, (node, pos) => {
|
|
30
|
+
const $fromPos = tr.doc.resolve(tr.mapping.map(pos));
|
|
31
|
+
const $toPos = tr.doc.resolve(tr.mapping.map(pos + node.nodeSize - 1));
|
|
32
|
+
const nodeRange = $fromPos.blockRange($toPos);
|
|
33
|
+
if (!nodeRange) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const targetLiftDepth = (0, prosemirror_transform_1.liftTarget)(nodeRange);
|
|
37
|
+
if (targetLiftDepth || targetLiftDepth === 0) {
|
|
38
|
+
tr.lift(nodeRange, targetLiftDepth);
|
|
39
|
+
}
|
|
33
40
|
});
|
|
34
|
-
tr.replaceWith(change.from, change.to, prosemirror_model_1.Fragment.empty);
|
|
35
|
-
tr.insert(tr.mapping.map(change.to), content);
|
|
36
41
|
}
|
|
37
42
|
function revertRejectedChanges(tr, schema, ids, changeSet, status) {
|
|
38
43
|
if (status !== change_1.CHANGE_STATUS.rejected) {
|
|
@@ -87,9 +87,8 @@ exports.setFragmentAsWrapChange = setFragmentAsWrapChange;
|
|
|
87
87
|
function setFragmentAsNodeSplit($pos, newTr, inserted, attrs) {
|
|
88
88
|
const lastChild = inserted.lastChild;
|
|
89
89
|
const referenceId = (0, uuidv4_1.uuidv4)();
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
const parent = $pos.node($pos.depth - listItemSplit);
|
|
90
|
+
const parentPos = $pos.before($pos.depth);
|
|
91
|
+
const parent = $pos.node($pos.depth);
|
|
93
92
|
const oldDataTracked = (0, nodeHelpers_1.getBlockInlineTrackedData)(parent) || [];
|
|
94
93
|
newTr.setNodeMarkup(parentPos, undefined, Object.assign(Object.assign({}, parent.attrs), { dataTracked: [
|
|
95
94
|
...oldDataTracked.filter((c) => c.operation !== 'reference'),
|
|
@@ -97,7 +96,14 @@ function setFragmentAsNodeSplit($pos, newTr, inserted, attrs) {
|
|
|
97
96
|
] }));
|
|
98
97
|
const splitSource = oldDataTracked.find((c) => c.operation === 'reference');
|
|
99
98
|
const dataTracked = Object.assign(Object.assign({}, trackUtils.createNewSplitAttrs(Object.assign({}, attrs))), { id: referenceId });
|
|
100
|
-
|
|
99
|
+
if (lastChild.type.name === 'list_item') {
|
|
100
|
+
let firstChild = lastChild.content.firstChild;
|
|
101
|
+
firstChild = firstChild.type.create(Object.assign(Object.assign({}, lastChild.attrs), { dataTracked: splitSource ? [dataTracked, splitSource] : [dataTracked] }), firstChild.content);
|
|
102
|
+
inserted = inserted.replaceChild(inserted.childCount - 1, lastChild.type.create(lastChild.attrs, lastChild.content.cut(firstChild.nodeSize).addToStart(firstChild)));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
inserted = inserted.replaceChild(inserted.childCount - 1, lastChild.type.create(Object.assign(Object.assign({}, lastChild.attrs), { dataTracked: splitSource ? [dataTracked, splitSource] : [dataTracked] }), lastChild.content));
|
|
106
|
+
}
|
|
101
107
|
return inserted;
|
|
102
108
|
}
|
|
103
109
|
exports.setFragmentAsNodeSplit = setFragmentAsNodeSplit;
|
|
@@ -1,35 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { liftTarget } from 'prosemirror-transform';
|
|
2
2
|
import { getBlockInlineTrackedData } from '../compute/nodeHelpers';
|
|
3
3
|
import { CHANGE_OPERATION, CHANGE_STATUS } from '../types/change';
|
|
4
4
|
import { getUpdatedDataTracked } from './applyChanges';
|
|
5
5
|
function revertSplitNodeChange(tr, change, changeSet) {
|
|
6
6
|
let sourceChange = changeSet.changes.find((c) => c.dataTracked.operation === 'reference' && c.dataTracked.referenceId === change.id);
|
|
7
|
-
const node = tr.doc.nodeAt(change.from);
|
|
8
|
-
tr.
|
|
9
|
-
tr.replaceWith(sourceChange.to - 1, sourceChange.to, node.content);
|
|
7
|
+
const node = tr.doc.nodeAt(tr.mapping.map(change.from));
|
|
8
|
+
tr.delete(tr.mapping.map(change.from), tr.mapping.map(change.to));
|
|
9
|
+
tr.replaceWith(tr.mapping.map(sourceChange.to - 1), tr.mapping.map(sourceChange.to), node.content);
|
|
10
10
|
if (change.node.type.name === 'list_item') {
|
|
11
11
|
tr.join(sourceChange.to - 1);
|
|
12
12
|
}
|
|
13
13
|
const childSource = changeSet.changes.find((c) => c.from === change.from && c.dataTracked.operation === 'reference');
|
|
14
14
|
if (childSource) {
|
|
15
|
-
const node = tr.doc.nodeAt(sourceChange.from);
|
|
15
|
+
const node = tr.doc.nodeAt(tr.mapping.map(sourceChange.from));
|
|
16
16
|
const dataTracked = getBlockInlineTrackedData(node).map((c) => c.operation === 'reference' ? childSource.dataTracked : c);
|
|
17
|
-
tr.setNodeMarkup(sourceChange.from, undefined, Object.assign(Object.assign({}, node.attrs), { dataTracked }), node.marks);
|
|
17
|
+
tr.setNodeMarkup(tr.mapping.map(sourceChange.from), undefined, Object.assign(Object.assign({}, node.attrs), { dataTracked }), node.marks);
|
|
18
18
|
}
|
|
19
19
|
const deleteChange = changeSet.changes.find((c) => c.dataTracked.operation == 'delete' && c.from === sourceChange.from);
|
|
20
20
|
if (deleteChange) {
|
|
21
|
-
const node = tr.doc.nodeAt(deleteChange.from);
|
|
22
|
-
tr.setNodeMarkup(deleteChange.from, undefined, getUpdatedDataTracked(node.attrs.dataTracked, deleteChange.id));
|
|
21
|
+
const node = tr.doc.nodeAt(tr.mapping.map(deleteChange.from));
|
|
22
|
+
tr.setNodeMarkup(tr.mapping.map(deleteChange.from), undefined, getUpdatedDataTracked(node.attrs.dataTracked, deleteChange.id));
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
function revertWrapNodeChange(tr, change) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
tr.doc.nodesBetween(change.from, change.to, (node, pos) => {
|
|
27
|
+
const $fromPos = tr.doc.resolve(tr.mapping.map(pos));
|
|
28
|
+
const $toPos = tr.doc.resolve(tr.mapping.map(pos + node.nodeSize - 1));
|
|
29
|
+
const nodeRange = $fromPos.blockRange($toPos);
|
|
30
|
+
if (!nodeRange) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const targetLiftDepth = liftTarget(nodeRange);
|
|
34
|
+
if (targetLiftDepth || targetLiftDepth === 0) {
|
|
35
|
+
tr.lift(nodeRange, targetLiftDepth);
|
|
36
|
+
}
|
|
30
37
|
});
|
|
31
|
-
tr.replaceWith(change.from, change.to, Fragment.empty);
|
|
32
|
-
tr.insert(tr.mapping.map(change.to), content);
|
|
33
38
|
}
|
|
34
39
|
export function revertRejectedChanges(tr, schema, ids, changeSet, status) {
|
|
35
40
|
if (status !== CHANGE_STATUS.rejected) {
|
|
@@ -59,9 +59,8 @@ export function setFragmentAsWrapChange(inserted, attrs, schema) {
|
|
|
59
59
|
export function setFragmentAsNodeSplit($pos, newTr, inserted, attrs) {
|
|
60
60
|
const lastChild = inserted.lastChild;
|
|
61
61
|
const referenceId = uuidv4();
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const parent = $pos.node($pos.depth - listItemSplit);
|
|
62
|
+
const parentPos = $pos.before($pos.depth);
|
|
63
|
+
const parent = $pos.node($pos.depth);
|
|
65
64
|
const oldDataTracked = getBlockInlineTrackedData(parent) || [];
|
|
66
65
|
newTr.setNodeMarkup(parentPos, undefined, Object.assign(Object.assign({}, parent.attrs), { dataTracked: [
|
|
67
66
|
...oldDataTracked.filter((c) => c.operation !== 'reference'),
|
|
@@ -69,6 +68,13 @@ export function setFragmentAsNodeSplit($pos, newTr, inserted, attrs) {
|
|
|
69
68
|
] }));
|
|
70
69
|
const splitSource = oldDataTracked.find((c) => c.operation === 'reference');
|
|
71
70
|
const dataTracked = Object.assign(Object.assign({}, trackUtils.createNewSplitAttrs(Object.assign({}, attrs))), { id: referenceId });
|
|
72
|
-
|
|
71
|
+
if (lastChild.type.name === 'list_item') {
|
|
72
|
+
let firstChild = lastChild.content.firstChild;
|
|
73
|
+
firstChild = firstChild.type.create(Object.assign(Object.assign({}, lastChild.attrs), { dataTracked: splitSource ? [dataTracked, splitSource] : [dataTracked] }), firstChild.content);
|
|
74
|
+
inserted = inserted.replaceChild(inserted.childCount - 1, lastChild.type.create(lastChild.attrs, lastChild.content.cut(firstChild.nodeSize).addToStart(firstChild)));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
inserted = inserted.replaceChild(inserted.childCount - 1, lastChild.type.create(Object.assign(Object.assign({}, lastChild.attrs), { dataTracked: splitSource ? [dataTracked, splitSource] : [dataTracked] }), lastChild.content));
|
|
78
|
+
}
|
|
73
79
|
return inserted;
|
|
74
80
|
}
|
package/package.json
CHANGED