@manuscripts/track-changes-plugin 1.6.1-LEAN-2850 → 1.6.1-LEAN-2752-2
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/dist/index.cjs +34 -13
- package/dist/index.js +34 -13
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -530,9 +530,7 @@ function updateChangeAttrs(tr, change, trackedAttrs, schema) {
|
|
|
530
530
|
return tr;
|
|
531
531
|
}
|
|
532
532
|
const { operation } = trackedAttrs;
|
|
533
|
-
const oldTrackData = change.type === 'text-change'
|
|
534
|
-
? getTextNodeTrackedMarkData(node, schema)
|
|
535
|
-
: getBlockInlineTrackedData(node);
|
|
533
|
+
const oldTrackData = change.type === 'text-change' ? getTextNodeTrackedMarkData(node, schema) : getBlockInlineTrackedData(node);
|
|
536
534
|
if (!operation) {
|
|
537
535
|
log.warn('updateChangeAttrs: unable to determine operation of change ', change);
|
|
538
536
|
}
|
|
@@ -553,7 +551,15 @@ function updateChangeAttrs(tr, change, trackedAttrs, schema) {
|
|
|
553
551
|
tr.setNodeMarkup(change.from, undefined, { ...node.attrs, dataTracked: null }, node.marks);
|
|
554
552
|
}
|
|
555
553
|
else if (change.type === 'node-change' || change.type === 'node-attr-change') {
|
|
556
|
-
const
|
|
554
|
+
const trackedDataSource = getBlockInlineTrackedData(node) || [];
|
|
555
|
+
const targetDataTracked = trackedDataSource.find((t) => change.id === t.id);
|
|
556
|
+
const newDataTracked = trackedDataSource.map((oldTrack) => {
|
|
557
|
+
if (targetDataTracked) {
|
|
558
|
+
if (oldTrack.id === targetDataTracked.id) {
|
|
559
|
+
return { ...oldTrack, ...trackedAttrs };
|
|
560
|
+
}
|
|
561
|
+
return oldTrack;
|
|
562
|
+
}
|
|
557
563
|
if (oldTrack.operation === operation) {
|
|
558
564
|
return { ...oldTrack, ...trackedAttrs };
|
|
559
565
|
}
|
|
@@ -622,7 +628,7 @@ function applyAcceptedRejectedChanges(tr, schema, changes, deleteMap = new prose
|
|
|
622
628
|
}
|
|
623
629
|
else if (ChangeSet.isNodeAttrChange(change) &&
|
|
624
630
|
change.dataTracked.status === exports.CHANGE_STATUS.accepted) {
|
|
625
|
-
tr.setNodeMarkup(from, undefined, { ...
|
|
631
|
+
tr.setNodeMarkup(from, undefined, { ...change.newAttrs, dataTracked: null }, node.marks);
|
|
626
632
|
}
|
|
627
633
|
else if (ChangeSet.isNodeAttrChange(change) &&
|
|
628
634
|
change.dataTracked.status === exports.CHANGE_STATUS.rejected) {
|
|
@@ -951,7 +957,7 @@ function createNewUpdateAttrs(attrs, oldAttrs) {
|
|
|
951
957
|
return {
|
|
952
958
|
...attrs,
|
|
953
959
|
operation: exports.CHANGE_OPERATION.set_node_attributes,
|
|
954
|
-
oldAttrs: restAttrs,
|
|
960
|
+
oldAttrs: JSON.parse(JSON.stringify(restAttrs)),
|
|
955
961
|
};
|
|
956
962
|
}
|
|
957
963
|
|
|
@@ -1198,7 +1204,8 @@ function trackReplaceAroundStep(step, oldState, newTr, attrs) {
|
|
|
1198
1204
|
*/
|
|
1199
1205
|
function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepDoc) {
|
|
1200
1206
|
log.info('###### ReplaceStep ######');
|
|
1201
|
-
let selectionPos = 0
|
|
1207
|
+
let selectionPos = 0;
|
|
1208
|
+
const changeSteps = [];
|
|
1202
1209
|
// Invert the transaction step to prevent it from actually deleting or inserting anything
|
|
1203
1210
|
step.getMap().forEach((fromA, toA, fromB, toB) => {
|
|
1204
1211
|
var _a, _b;
|
|
@@ -1422,18 +1429,32 @@ function processChangeSteps(changes, startPos, newTr, emptyAttrs, schema) {
|
|
|
1422
1429
|
}
|
|
1423
1430
|
else if (c.type === 'update-node-attrs') {
|
|
1424
1431
|
const oldDataTracked = getBlockInlineTrackedData(c.node) || [];
|
|
1425
|
-
const oldUpdate = oldDataTracked.find((d) =>
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1432
|
+
const oldUpdate = oldDataTracked.reverse().find((d) => {
|
|
1433
|
+
// reversing to start from the most recent change
|
|
1434
|
+
if (d.operation === exports.CHANGE_OPERATION.set_node_attributes &&
|
|
1435
|
+
(d.status === exports.CHANGE_STATUS.pending || d.status === exports.CHANGE_STATUS.rejected)) {
|
|
1436
|
+
return true;
|
|
1437
|
+
}
|
|
1438
|
+
return false;
|
|
1439
|
+
});
|
|
1440
|
+
// if the selected last change is with status "rejected" we need to use oldAttrs from it because
|
|
1441
|
+
// node's actual attributes represent the "rejected" values
|
|
1442
|
+
const lastChangeRejected = oldUpdate && oldUpdate.status === exports.CHANGE_STATUS.rejected;
|
|
1443
|
+
const sourceAttrs = (oldUpdate === null || oldUpdate === void 0 ? void 0 : oldUpdate.oldAttrs) || c.node.attrs;
|
|
1444
|
+
const { dataTracked, ...restAttrs } = sourceAttrs;
|
|
1445
|
+
const oldAttrs = lastChangeRejected ? oldUpdate.oldAttrs : restAttrs;
|
|
1446
|
+
const newDataTracked = [
|
|
1447
|
+
...oldDataTracked.filter((d) => !oldUpdate || d.id !== oldUpdate.id || lastChangeRejected),
|
|
1448
|
+
];
|
|
1449
|
+
const newUpdate = oldUpdate && oldUpdate.status !== exports.CHANGE_STATUS.rejected
|
|
1429
1450
|
? {
|
|
1430
1451
|
...oldUpdate,
|
|
1431
1452
|
updatedAt: emptyAttrs.updatedAt,
|
|
1432
1453
|
}
|
|
1433
|
-
: addTrackIdIfDoesntExist(createNewUpdateAttrs(emptyAttrs, c.node.attrs));
|
|
1454
|
+
: addTrackIdIfDoesntExist(createNewUpdateAttrs(emptyAttrs, lastChangeRejected ? oldAttrs : c.node.attrs));
|
|
1434
1455
|
// Dont add update changes if there exists already an insert change for this node
|
|
1435
1456
|
if (JSON.stringify(oldAttrs) !== JSON.stringify(c.newAttrs) &&
|
|
1436
|
-
!oldDataTracked.find((d) => d.operation === exports.CHANGE_OPERATION.insert
|
|
1457
|
+
!oldDataTracked.find((d) => d.operation === exports.CHANGE_OPERATION.insert)) {
|
|
1437
1458
|
newDataTracked.push(newUpdate);
|
|
1438
1459
|
}
|
|
1439
1460
|
newTr.setNodeMarkup(mapping.map(c.pos), undefined, {
|
package/dist/index.js
CHANGED
|
@@ -522,9 +522,7 @@ function updateChangeAttrs(tr, change, trackedAttrs, schema) {
|
|
|
522
522
|
return tr;
|
|
523
523
|
}
|
|
524
524
|
const { operation } = trackedAttrs;
|
|
525
|
-
const oldTrackData = change.type === 'text-change'
|
|
526
|
-
? getTextNodeTrackedMarkData(node, schema)
|
|
527
|
-
: getBlockInlineTrackedData(node);
|
|
525
|
+
const oldTrackData = change.type === 'text-change' ? getTextNodeTrackedMarkData(node, schema) : getBlockInlineTrackedData(node);
|
|
528
526
|
if (!operation) {
|
|
529
527
|
log.warn('updateChangeAttrs: unable to determine operation of change ', change);
|
|
530
528
|
}
|
|
@@ -545,7 +543,15 @@ function updateChangeAttrs(tr, change, trackedAttrs, schema) {
|
|
|
545
543
|
tr.setNodeMarkup(change.from, undefined, { ...node.attrs, dataTracked: null }, node.marks);
|
|
546
544
|
}
|
|
547
545
|
else if (change.type === 'node-change' || change.type === 'node-attr-change') {
|
|
548
|
-
const
|
|
546
|
+
const trackedDataSource = getBlockInlineTrackedData(node) || [];
|
|
547
|
+
const targetDataTracked = trackedDataSource.find((t) => change.id === t.id);
|
|
548
|
+
const newDataTracked = trackedDataSource.map((oldTrack) => {
|
|
549
|
+
if (targetDataTracked) {
|
|
550
|
+
if (oldTrack.id === targetDataTracked.id) {
|
|
551
|
+
return { ...oldTrack, ...trackedAttrs };
|
|
552
|
+
}
|
|
553
|
+
return oldTrack;
|
|
554
|
+
}
|
|
549
555
|
if (oldTrack.operation === operation) {
|
|
550
556
|
return { ...oldTrack, ...trackedAttrs };
|
|
551
557
|
}
|
|
@@ -614,7 +620,7 @@ function applyAcceptedRejectedChanges(tr, schema, changes, deleteMap = new Mappi
|
|
|
614
620
|
}
|
|
615
621
|
else if (ChangeSet.isNodeAttrChange(change) &&
|
|
616
622
|
change.dataTracked.status === CHANGE_STATUS.accepted) {
|
|
617
|
-
tr.setNodeMarkup(from, undefined, { ...
|
|
623
|
+
tr.setNodeMarkup(from, undefined, { ...change.newAttrs, dataTracked: null }, node.marks);
|
|
618
624
|
}
|
|
619
625
|
else if (ChangeSet.isNodeAttrChange(change) &&
|
|
620
626
|
change.dataTracked.status === CHANGE_STATUS.rejected) {
|
|
@@ -943,7 +949,7 @@ function createNewUpdateAttrs(attrs, oldAttrs) {
|
|
|
943
949
|
return {
|
|
944
950
|
...attrs,
|
|
945
951
|
operation: CHANGE_OPERATION.set_node_attributes,
|
|
946
|
-
oldAttrs: restAttrs,
|
|
952
|
+
oldAttrs: JSON.parse(JSON.stringify(restAttrs)),
|
|
947
953
|
};
|
|
948
954
|
}
|
|
949
955
|
|
|
@@ -1190,7 +1196,8 @@ function trackReplaceAroundStep(step, oldState, newTr, attrs) {
|
|
|
1190
1196
|
*/
|
|
1191
1197
|
function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepDoc) {
|
|
1192
1198
|
log.info('###### ReplaceStep ######');
|
|
1193
|
-
let selectionPos = 0
|
|
1199
|
+
let selectionPos = 0;
|
|
1200
|
+
const changeSteps = [];
|
|
1194
1201
|
// Invert the transaction step to prevent it from actually deleting or inserting anything
|
|
1195
1202
|
step.getMap().forEach((fromA, toA, fromB, toB) => {
|
|
1196
1203
|
var _a, _b;
|
|
@@ -1414,18 +1421,32 @@ function processChangeSteps(changes, startPos, newTr, emptyAttrs, schema) {
|
|
|
1414
1421
|
}
|
|
1415
1422
|
else if (c.type === 'update-node-attrs') {
|
|
1416
1423
|
const oldDataTracked = getBlockInlineTrackedData(c.node) || [];
|
|
1417
|
-
const oldUpdate = oldDataTracked.find((d) =>
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1424
|
+
const oldUpdate = oldDataTracked.reverse().find((d) => {
|
|
1425
|
+
// reversing to start from the most recent change
|
|
1426
|
+
if (d.operation === CHANGE_OPERATION.set_node_attributes &&
|
|
1427
|
+
(d.status === CHANGE_STATUS.pending || d.status === CHANGE_STATUS.rejected)) {
|
|
1428
|
+
return true;
|
|
1429
|
+
}
|
|
1430
|
+
return false;
|
|
1431
|
+
});
|
|
1432
|
+
// if the selected last change is with status "rejected" we need to use oldAttrs from it because
|
|
1433
|
+
// node's actual attributes represent the "rejected" values
|
|
1434
|
+
const lastChangeRejected = oldUpdate && oldUpdate.status === CHANGE_STATUS.rejected;
|
|
1435
|
+
const sourceAttrs = (oldUpdate === null || oldUpdate === void 0 ? void 0 : oldUpdate.oldAttrs) || c.node.attrs;
|
|
1436
|
+
const { dataTracked, ...restAttrs } = sourceAttrs;
|
|
1437
|
+
const oldAttrs = lastChangeRejected ? oldUpdate.oldAttrs : restAttrs;
|
|
1438
|
+
const newDataTracked = [
|
|
1439
|
+
...oldDataTracked.filter((d) => !oldUpdate || d.id !== oldUpdate.id || lastChangeRejected),
|
|
1440
|
+
];
|
|
1441
|
+
const newUpdate = oldUpdate && oldUpdate.status !== CHANGE_STATUS.rejected
|
|
1421
1442
|
? {
|
|
1422
1443
|
...oldUpdate,
|
|
1423
1444
|
updatedAt: emptyAttrs.updatedAt,
|
|
1424
1445
|
}
|
|
1425
|
-
: addTrackIdIfDoesntExist(createNewUpdateAttrs(emptyAttrs, c.node.attrs));
|
|
1446
|
+
: addTrackIdIfDoesntExist(createNewUpdateAttrs(emptyAttrs, lastChangeRejected ? oldAttrs : c.node.attrs));
|
|
1426
1447
|
// Dont add update changes if there exists already an insert change for this node
|
|
1427
1448
|
if (JSON.stringify(oldAttrs) !== JSON.stringify(c.newAttrs) &&
|
|
1428
|
-
!oldDataTracked.find((d) => d.operation === CHANGE_OPERATION.insert
|
|
1449
|
+
!oldDataTracked.find((d) => d.operation === CHANGE_OPERATION.insert)) {
|
|
1429
1450
|
newDataTracked.push(newUpdate);
|
|
1430
1451
|
}
|
|
1431
1452
|
newTr.setNodeMarkup(mapping.map(c.pos), undefined, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/track-changes-plugin",
|
|
3
|
-
"version": "1.6.1-LEAN-
|
|
3
|
+
"version": "1.6.1-LEAN-2752-2",
|
|
4
4
|
"author": "Atypon Systems LLC",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/Atypon-OpenSource/manuscripts-quarterback/tree/main/quarterback-packages/track-changes-plugin",
|