@manuscripts/track-changes-plugin 1.10.8-LEAN-4160.0 → 1.10.8
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.
|
@@ -20,20 +20,6 @@ const trackReplaceAroundStep_1 = require("./trackReplaceAroundStep");
|
|
|
20
20
|
const trackReplaceStep_1 = require("./trackReplaceStep");
|
|
21
21
|
const getSelectionStaticConstructor = (sel) => Object.getPrototypeOf(sel).constructor;
|
|
22
22
|
const isHighlightMarkerNode = (node) => node && node.type === node.type.schema.nodes.highlight_marker;
|
|
23
|
-
function isSimplePendingMoveDeletion(step, doc, movingSteps) {
|
|
24
|
-
if (step.from === step.to || step.slice.content.size > 0) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
if (movingSteps.has(step)) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
const node = doc.nodeAt(step.from);
|
|
31
|
-
if (!node) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
const trackedAttrs = node.attrs.dataTracked;
|
|
35
|
-
return !!(trackedAttrs === null || trackedAttrs === void 0 ? void 0 : trackedAttrs.some((t) => t.operation === change_1.CHANGE_OPERATION.move && t.status === change_1.CHANGE_STATUS.pending));
|
|
36
|
-
}
|
|
37
23
|
function trackTransaction(tr, oldState, newTr, authorID, changeSet) {
|
|
38
24
|
var _a, _b, _c, _d, _e;
|
|
39
25
|
const emptyAttrs = {
|
|
@@ -51,35 +37,8 @@ function trackTransaction(tr, oldState, newTr, authorID, changeSet) {
|
|
|
51
37
|
logger_1.log.info('ORIGINAL transaction', tr);
|
|
52
38
|
let trContext = {};
|
|
53
39
|
const movingStepsAssociated = (0, track_utils_1.HasMoveOperations)(tr);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (step instanceof prosemirror_transform_1.ReplaceStep) {
|
|
57
|
-
const doc = tr.docs[tr.steps.indexOf(step)];
|
|
58
|
-
if (isSimplePendingMoveDeletion(step, doc, movingStepsAssociated)) {
|
|
59
|
-
const node = doc.nodeAt(step.from);
|
|
60
|
-
(_a = node === null || node === void 0 ? void 0 : node.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.forEach((tracked) => {
|
|
61
|
-
if (tracked.operation === change_1.CHANGE_OPERATION.move && tracked.status === change_1.CHANGE_STATUS.pending) {
|
|
62
|
-
newTr.setNodeMarkup(step.from, undefined, Object.assign(Object.assign({}, node.attrs), { dataTracked: node.attrs.dataTracked.map((t) => t.id === tracked.id ? Object.assign(Object.assign({}, t), { status: change_1.CHANGE_STATUS.rejected }) : t) }));
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
const cleanSteps = [];
|
|
69
|
-
for (let i = 0; i < tr.steps.length; i++) {
|
|
70
|
-
const step = tr.steps[i];
|
|
71
|
-
const moveID = movingStepsAssociated.get(step);
|
|
72
|
-
const prevMoveID = (0, track_utils_1.isDeletingPendingMovedNode)(step, tr.docs[i]);
|
|
73
|
-
if (moveID && prevMoveID) {
|
|
74
|
-
movingStepsAssociated.forEach((replaceStepMoveID, replaceStep) => {
|
|
75
|
-
if (replaceStep !== step && moveID === replaceStepMoveID) {
|
|
76
|
-
movingStepsAssociated.set(replaceStep, prevMoveID);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
cleanSteps.push(step);
|
|
82
|
-
}
|
|
40
|
+
(0, track_utils_1.handleDirectPendingMoveDeletions)(tr, newTr, movingStepsAssociated);
|
|
41
|
+
const cleanSteps = (0, track_utils_1.filterMeaninglessMoveSteps)(tr, movingStepsAssociated);
|
|
83
42
|
for (let i = cleanSteps.length - 1; i >= 0; i--) {
|
|
84
43
|
const step = tr.steps[i];
|
|
85
44
|
logger_1.log.info('transaction step', step);
|
|
@@ -11,7 +11,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.isDeletingPendingMovedNode = exports.HasMoveOperations = exports.trFromHistory = exports.stepIsLift = exports.isLiftStep = exports.isWrapStep = exports.isSplitStep = exports.createNewUpdateAttrs = exports.createNewMoveAttrs = exports.createNewDeleteAttrs = exports.createNewReferenceAttrs = exports.createNewSplitAttrs = exports.createNewWrapAttrs = exports.createNewInsertAttrs = void 0;
|
|
14
|
+
exports.filterMeaninglessMoveSteps = exports.handleDirectPendingMoveDeletions = exports.isDirectPendingMoveDeletion = exports.isDeletingPendingMovedNode = exports.HasMoveOperations = exports.trFromHistory = exports.stepIsLift = exports.isLiftStep = exports.isWrapStep = exports.isSplitStep = exports.createNewUpdateAttrs = exports.createNewMoveAttrs = exports.createNewDeleteAttrs = exports.createNewReferenceAttrs = exports.createNewSplitAttrs = exports.createNewWrapAttrs = exports.createNewInsertAttrs = void 0;
|
|
15
|
+
const prosemirror_transform_1 = require("prosemirror-transform");
|
|
15
16
|
const change_1 = require("../types/change");
|
|
16
17
|
const uuidv4_1 = require("./uuidv4");
|
|
17
18
|
function createNewInsertAttrs(attrs) {
|
|
@@ -157,3 +158,51 @@ const isDeletingPendingMovedNode = (step, doc) => {
|
|
|
157
158
|
return undefined;
|
|
158
159
|
};
|
|
159
160
|
exports.isDeletingPendingMovedNode = isDeletingPendingMovedNode;
|
|
161
|
+
const isDirectPendingMoveDeletion = (step, doc, movingSteps) => {
|
|
162
|
+
if (step.from === step.to || step.slice.content.size > 0) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
if (movingSteps.has(step)) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
const node = doc.nodeAt(step.from);
|
|
169
|
+
if (!node) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
const trackedAttrs = node.attrs.dataTracked;
|
|
173
|
+
return !!(trackedAttrs === null || trackedAttrs === void 0 ? void 0 : trackedAttrs.some((t) => t.operation === change_1.CHANGE_OPERATION.move && t.status === change_1.CHANGE_STATUS.pending));
|
|
174
|
+
};
|
|
175
|
+
exports.isDirectPendingMoveDeletion = isDirectPendingMoveDeletion;
|
|
176
|
+
const handleDirectPendingMoveDeletions = (tr, newTr, movingSteps) => {
|
|
177
|
+
tr.steps.forEach((step) => {
|
|
178
|
+
if (step instanceof prosemirror_transform_1.ReplaceStep) {
|
|
179
|
+
const doc = tr.docs[tr.steps.indexOf(step)];
|
|
180
|
+
if ((0, exports.isDirectPendingMoveDeletion)(step, doc, movingSteps)) {
|
|
181
|
+
const node = doc.nodeAt(step.from);
|
|
182
|
+
if (node === null || node === void 0 ? void 0 : node.attrs.dataTracked) {
|
|
183
|
+
newTr.setNodeMarkup(step.from, undefined, Object.assign(Object.assign({}, node.attrs), { dataTracked: node.attrs.dataTracked.filter((t) => !(t.operation === change_1.CHANGE_OPERATION.move && t.status === change_1.CHANGE_STATUS.pending)) }));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
exports.handleDirectPendingMoveDeletions = handleDirectPendingMoveDeletions;
|
|
190
|
+
const filterMeaninglessMoveSteps = (tr, movingSteps) => {
|
|
191
|
+
const cleanSteps = [];
|
|
192
|
+
for (let i = 0; i < tr.steps.length; i++) {
|
|
193
|
+
const step = tr.steps[i];
|
|
194
|
+
const moveID = movingSteps.get(step);
|
|
195
|
+
const prevMoveID = (0, exports.isDeletingPendingMovedNode)(step, tr.docs[i]);
|
|
196
|
+
if (moveID && prevMoveID) {
|
|
197
|
+
movingSteps.forEach((replaceStepMoveID, replaceStep) => {
|
|
198
|
+
if (replaceStep !== step && moveID === replaceStepMoveID) {
|
|
199
|
+
movingSteps.set(replaceStep, prevMoveID);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
cleanSteps.push(step);
|
|
205
|
+
}
|
|
206
|
+
return cleanSteps;
|
|
207
|
+
};
|
|
208
|
+
exports.filterMeaninglessMoveSteps = filterMeaninglessMoveSteps;
|
|
@@ -4,30 +4,16 @@ import { diffChangeSteps } from '../change-steps/diffChangeSteps';
|
|
|
4
4
|
import { processChangeSteps } from '../change-steps/processChangeSteps';
|
|
5
5
|
import { updateChangeAttrs } from '../changes/updateChangeAttrs';
|
|
6
6
|
import { getNodeTrackedData } from '../compute/nodeHelpers';
|
|
7
|
-
import {
|
|
7
|
+
import { CHANGE_STATUS } from '../types/change';
|
|
8
8
|
import { log } from '../utils/logger';
|
|
9
9
|
import { mapChangeSteps } from '../utils/mapChangeStep';
|
|
10
|
-
import { HasMoveOperations,
|
|
10
|
+
import { filterMeaninglessMoveSteps, handleDirectPendingMoveDeletions, HasMoveOperations, } from '../utils/track-utils';
|
|
11
11
|
import { uuidv4 } from '../utils/uuidv4';
|
|
12
12
|
import trackAttrsChange from './trackAttrsChange';
|
|
13
13
|
import { trackReplaceAroundStep } from './trackReplaceAroundStep';
|
|
14
14
|
import { trackReplaceStep } from './trackReplaceStep';
|
|
15
15
|
const getSelectionStaticConstructor = (sel) => Object.getPrototypeOf(sel).constructor;
|
|
16
16
|
const isHighlightMarkerNode = (node) => node && node.type === node.type.schema.nodes.highlight_marker;
|
|
17
|
-
function isSimplePendingMoveDeletion(step, doc, movingSteps) {
|
|
18
|
-
if (step.from === step.to || step.slice.content.size > 0) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
if (movingSteps.has(step)) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
const node = doc.nodeAt(step.from);
|
|
25
|
-
if (!node) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
const trackedAttrs = node.attrs.dataTracked;
|
|
29
|
-
return !!(trackedAttrs === null || trackedAttrs === void 0 ? void 0 : trackedAttrs.some((t) => t.operation === CHANGE_OPERATION.move && t.status === CHANGE_STATUS.pending));
|
|
30
|
-
}
|
|
31
17
|
export function trackTransaction(tr, oldState, newTr, authorID, changeSet) {
|
|
32
18
|
var _a, _b, _c, _d, _e;
|
|
33
19
|
const emptyAttrs = {
|
|
@@ -45,35 +31,8 @@ export function trackTransaction(tr, oldState, newTr, authorID, changeSet) {
|
|
|
45
31
|
log.info('ORIGINAL transaction', tr);
|
|
46
32
|
let trContext = {};
|
|
47
33
|
const movingStepsAssociated = HasMoveOperations(tr);
|
|
48
|
-
tr
|
|
49
|
-
|
|
50
|
-
if (step instanceof ReplaceStep) {
|
|
51
|
-
const doc = tr.docs[tr.steps.indexOf(step)];
|
|
52
|
-
if (isSimplePendingMoveDeletion(step, doc, movingStepsAssociated)) {
|
|
53
|
-
const node = doc.nodeAt(step.from);
|
|
54
|
-
(_a = node === null || node === void 0 ? void 0 : node.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.forEach((tracked) => {
|
|
55
|
-
if (tracked.operation === CHANGE_OPERATION.move && tracked.status === CHANGE_STATUS.pending) {
|
|
56
|
-
newTr.setNodeMarkup(step.from, undefined, Object.assign(Object.assign({}, node.attrs), { dataTracked: node.attrs.dataTracked.map((t) => t.id === tracked.id ? Object.assign(Object.assign({}, t), { status: CHANGE_STATUS.rejected }) : t) }));
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
const cleanSteps = [];
|
|
63
|
-
for (let i = 0; i < tr.steps.length; i++) {
|
|
64
|
-
const step = tr.steps[i];
|
|
65
|
-
const moveID = movingStepsAssociated.get(step);
|
|
66
|
-
const prevMoveID = isDeletingPendingMovedNode(step, tr.docs[i]);
|
|
67
|
-
if (moveID && prevMoveID) {
|
|
68
|
-
movingStepsAssociated.forEach((replaceStepMoveID, replaceStep) => {
|
|
69
|
-
if (replaceStep !== step && moveID === replaceStepMoveID) {
|
|
70
|
-
movingStepsAssociated.set(replaceStep, prevMoveID);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
cleanSteps.push(step);
|
|
76
|
-
}
|
|
34
|
+
handleDirectPendingMoveDeletions(tr, newTr, movingStepsAssociated);
|
|
35
|
+
const cleanSteps = filterMeaninglessMoveSteps(tr, movingStepsAssociated);
|
|
77
36
|
for (let i = cleanSteps.length - 1; i >= 0; i--) {
|
|
78
37
|
const step = tr.steps[i];
|
|
79
38
|
log.info('transaction step', step);
|
|
@@ -9,6 +9,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
+
import { ReplaceStep } from 'prosemirror-transform';
|
|
12
13
|
import { CHANGE_OPERATION, CHANGE_STATUS } from '../types/change';
|
|
13
14
|
import { uuidv4 } from './uuidv4';
|
|
14
15
|
export function createNewInsertAttrs(attrs) {
|
|
@@ -140,3 +141,48 @@ export const isDeletingPendingMovedNode = (step, doc) => {
|
|
|
140
141
|
}
|
|
141
142
|
return undefined;
|
|
142
143
|
};
|
|
144
|
+
export const isDirectPendingMoveDeletion = (step, doc, movingSteps) => {
|
|
145
|
+
if (step.from === step.to || step.slice.content.size > 0) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
if (movingSteps.has(step)) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
const node = doc.nodeAt(step.from);
|
|
152
|
+
if (!node) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
const trackedAttrs = node.attrs.dataTracked;
|
|
156
|
+
return !!(trackedAttrs === null || trackedAttrs === void 0 ? void 0 : trackedAttrs.some((t) => t.operation === CHANGE_OPERATION.move && t.status === CHANGE_STATUS.pending));
|
|
157
|
+
};
|
|
158
|
+
export const handleDirectPendingMoveDeletions = (tr, newTr, movingSteps) => {
|
|
159
|
+
tr.steps.forEach((step) => {
|
|
160
|
+
if (step instanceof ReplaceStep) {
|
|
161
|
+
const doc = tr.docs[tr.steps.indexOf(step)];
|
|
162
|
+
if (isDirectPendingMoveDeletion(step, doc, movingSteps)) {
|
|
163
|
+
const node = doc.nodeAt(step.from);
|
|
164
|
+
if (node === null || node === void 0 ? void 0 : node.attrs.dataTracked) {
|
|
165
|
+
newTr.setNodeMarkup(step.from, undefined, Object.assign(Object.assign({}, node.attrs), { dataTracked: node.attrs.dataTracked.filter((t) => !(t.operation === CHANGE_OPERATION.move && t.status === CHANGE_STATUS.pending)) }));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
export const filterMeaninglessMoveSteps = (tr, movingSteps) => {
|
|
172
|
+
const cleanSteps = [];
|
|
173
|
+
for (let i = 0; i < tr.steps.length; i++) {
|
|
174
|
+
const step = tr.steps[i];
|
|
175
|
+
const moveID = movingSteps.get(step);
|
|
176
|
+
const prevMoveID = isDeletingPendingMovedNode(step, tr.docs[i]);
|
|
177
|
+
if (moveID && prevMoveID) {
|
|
178
|
+
movingSteps.forEach((replaceStepMoveID, replaceStep) => {
|
|
179
|
+
if (replaceStep !== step && moveID === replaceStepMoveID) {
|
|
180
|
+
movingSteps.set(replaceStep, prevMoveID);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
cleanSteps.push(step);
|
|
186
|
+
}
|
|
187
|
+
return cleanSteps;
|
|
188
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Node as PMNode, Slice } from 'prosemirror-model';
|
|
2
2
|
import { Selection, Transaction } from 'prosemirror-state';
|
|
3
|
-
import { ReplaceAroundStep, ReplaceStep } from 'prosemirror-transform';
|
|
3
|
+
import { ReplaceAroundStep, ReplaceStep, Step } from 'prosemirror-transform';
|
|
4
4
|
import { NewDeleteAttrs, NewEmptyAttrs, NewInsertAttrs, NewReferenceAttrs, NewSplitNodeAttrs, NewUpdateAttrs } from '../types/track';
|
|
5
5
|
export declare function createNewInsertAttrs(attrs: NewEmptyAttrs): NewInsertAttrs;
|
|
6
6
|
export declare function createNewWrapAttrs(attrs: NewEmptyAttrs): NewInsertAttrs;
|
|
@@ -21,3 +21,6 @@ export declare function stepIsLift(gap: {
|
|
|
21
21
|
export declare const trFromHistory: (tr: Transaction) => string | undefined;
|
|
22
22
|
export declare const HasMoveOperations: (tr: Transaction) => Map<ReplaceStep, string>;
|
|
23
23
|
export declare const isDeletingPendingMovedNode: (step: ReplaceStep, doc: PMNode) => string | undefined;
|
|
24
|
+
export declare const isDirectPendingMoveDeletion: (step: ReplaceStep, doc: PMNode, movingSteps: Map<ReplaceStep, string>) => boolean;
|
|
25
|
+
export declare const handleDirectPendingMoveDeletions: (tr: Transaction, newTr: Transaction, movingSteps: Map<ReplaceStep, string>) => void;
|
|
26
|
+
export declare const filterMeaninglessMoveSteps: (tr: Transaction, movingSteps: Map<ReplaceStep, string>) => Step[];
|
package/package.json
CHANGED