@manuscripts/track-changes-plugin 2.0.5 → 2.0.6
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.
|
@@ -40,7 +40,7 @@ function trackTransaction(tr, oldState, newTr, authorID, changeSet) {
|
|
|
40
40
|
(0, track_utils_1.handleDirectPendingMoveDeletions)(tr, newTr, movingStepsAssociated);
|
|
41
41
|
const cleanSteps = (0, track_utils_1.filterMeaninglessMoveSteps)(tr, movingStepsAssociated);
|
|
42
42
|
for (let i = cleanSteps.length - 1; i >= 0; i--) {
|
|
43
|
-
const step =
|
|
43
|
+
const step = cleanSteps[i];
|
|
44
44
|
logger_1.log.info('transaction step', step);
|
|
45
45
|
iters += 1;
|
|
46
46
|
const uiEvent = tr.getMeta('uiEvent');
|
|
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
14
|
+
exports.filterMeaninglessMoveSteps = exports.handleDirectPendingMoveDeletions = exports.isDirectPendingMoveDeletion = exports.isDeletingPendingMovedNode = exports.isPendingChange = 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
15
|
const prosemirror_transform_1 = require("prosemirror-transform");
|
|
16
16
|
const change_1 = require("../types/change");
|
|
17
17
|
const uuidv4_1 = require("./uuidv4");
|
|
@@ -146,6 +146,10 @@ const HasMoveOperations = (tr) => {
|
|
|
146
146
|
return movingAssoc;
|
|
147
147
|
};
|
|
148
148
|
exports.HasMoveOperations = HasMoveOperations;
|
|
149
|
+
const isPendingChange = (trackedAttrs, operation) => {
|
|
150
|
+
return !!(trackedAttrs === null || trackedAttrs === void 0 ? void 0 : trackedAttrs.some((t) => t.operation === operation));
|
|
151
|
+
};
|
|
152
|
+
exports.isPendingChange = isPendingChange;
|
|
149
153
|
const isDeletingPendingMovedNode = (step, doc) => {
|
|
150
154
|
if (!step.slice || step.from === step.to || step.slice.content.size > 0) {
|
|
151
155
|
return undefined;
|
|
@@ -173,8 +177,7 @@ const isDirectPendingMoveDeletion = (step, doc, movingSteps) => {
|
|
|
173
177
|
if (!node) {
|
|
174
178
|
return false;
|
|
175
179
|
}
|
|
176
|
-
|
|
177
|
-
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));
|
|
180
|
+
return (0, exports.isPendingChange)(node.attrs.dataTracked, change_1.CHANGE_OPERATION.move);
|
|
178
181
|
};
|
|
179
182
|
exports.isDirectPendingMoveDeletion = isDirectPendingMoveDeletion;
|
|
180
183
|
const handleDirectPendingMoveDeletions = (tr, newTr, movingSteps) => {
|
|
@@ -192,18 +195,33 @@ const handleDirectPendingMoveDeletions = (tr, newTr, movingSteps) => {
|
|
|
192
195
|
};
|
|
193
196
|
exports.handleDirectPendingMoveDeletions = handleDirectPendingMoveDeletions;
|
|
194
197
|
const filterMeaninglessMoveSteps = (tr, movingSteps) => {
|
|
198
|
+
var _a;
|
|
195
199
|
const cleanSteps = [];
|
|
196
200
|
for (let i = 0; i < tr.steps.length; i++) {
|
|
197
201
|
const step = tr.steps[i];
|
|
198
202
|
const moveID = movingSteps.get(step);
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
203
|
+
if (moveID) {
|
|
204
|
+
const prevMoveID = (0, exports.isDeletingPendingMovedNode)(step, tr.docs[i]);
|
|
205
|
+
if (prevMoveID) {
|
|
206
|
+
movingSteps.forEach((replaceStepMoveID, replaceStep) => {
|
|
207
|
+
if (replaceStep !== step && moveID === replaceStepMoveID) {
|
|
208
|
+
movingSteps.set(replaceStep, prevMoveID);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (step instanceof prosemirror_transform_1.ReplaceStep) {
|
|
214
|
+
const { slice } = step;
|
|
215
|
+
if ((_a = slice === null || slice === void 0 ? void 0 : slice.content) === null || _a === void 0 ? void 0 : _a.firstChild) {
|
|
216
|
+
const insertedNode = slice.content.firstChild;
|
|
217
|
+
if (insertedNode.attrs.dataTracked) {
|
|
218
|
+
const isPendingInsert = (0, exports.isPendingChange)(insertedNode.attrs.dataTracked, change_1.CHANGE_OPERATION.insert);
|
|
219
|
+
if (isPendingInsert) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
204
223
|
}
|
|
205
|
-
}
|
|
206
|
-
continue;
|
|
224
|
+
}
|
|
207
225
|
}
|
|
208
226
|
cleanSteps.push(step);
|
|
209
227
|
}
|
|
@@ -34,7 +34,7 @@ export function trackTransaction(tr, oldState, newTr, authorID, changeSet) {
|
|
|
34
34
|
handleDirectPendingMoveDeletions(tr, newTr, movingStepsAssociated);
|
|
35
35
|
const cleanSteps = filterMeaninglessMoveSteps(tr, movingStepsAssociated);
|
|
36
36
|
for (let i = cleanSteps.length - 1; i >= 0; i--) {
|
|
37
|
-
const step =
|
|
37
|
+
const step = cleanSteps[i];
|
|
38
38
|
log.info('transaction step', step);
|
|
39
39
|
iters += 1;
|
|
40
40
|
const uiEvent = tr.getMeta('uiEvent');
|
|
@@ -130,6 +130,9 @@ export const HasMoveOperations = (tr) => {
|
|
|
130
130
|
}
|
|
131
131
|
return movingAssoc;
|
|
132
132
|
};
|
|
133
|
+
export const isPendingChange = (trackedAttrs, operation) => {
|
|
134
|
+
return !!(trackedAttrs === null || trackedAttrs === void 0 ? void 0 : trackedAttrs.some((t) => t.operation === operation));
|
|
135
|
+
};
|
|
133
136
|
export const isDeletingPendingMovedNode = (step, doc) => {
|
|
134
137
|
if (!step.slice || step.from === step.to || step.slice.content.size > 0) {
|
|
135
138
|
return undefined;
|
|
@@ -156,8 +159,7 @@ export const isDirectPendingMoveDeletion = (step, doc, movingSteps) => {
|
|
|
156
159
|
if (!node) {
|
|
157
160
|
return false;
|
|
158
161
|
}
|
|
159
|
-
|
|
160
|
-
return !!(trackedAttrs === null || trackedAttrs === void 0 ? void 0 : trackedAttrs.some((t) => t.operation === CHANGE_OPERATION.move && t.status === CHANGE_STATUS.pending));
|
|
162
|
+
return isPendingChange(node.attrs.dataTracked, CHANGE_OPERATION.move);
|
|
161
163
|
};
|
|
162
164
|
export const handleDirectPendingMoveDeletions = (tr, newTr, movingSteps) => {
|
|
163
165
|
tr.steps.forEach((step) => {
|
|
@@ -173,18 +175,33 @@ export const handleDirectPendingMoveDeletions = (tr, newTr, movingSteps) => {
|
|
|
173
175
|
});
|
|
174
176
|
};
|
|
175
177
|
export const filterMeaninglessMoveSteps = (tr, movingSteps) => {
|
|
178
|
+
var _a;
|
|
176
179
|
const cleanSteps = [];
|
|
177
180
|
for (let i = 0; i < tr.steps.length; i++) {
|
|
178
181
|
const step = tr.steps[i];
|
|
179
182
|
const moveID = movingSteps.get(step);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
if (moveID) {
|
|
184
|
+
const prevMoveID = isDeletingPendingMovedNode(step, tr.docs[i]);
|
|
185
|
+
if (prevMoveID) {
|
|
186
|
+
movingSteps.forEach((replaceStepMoveID, replaceStep) => {
|
|
187
|
+
if (replaceStep !== step && moveID === replaceStepMoveID) {
|
|
188
|
+
movingSteps.set(replaceStep, prevMoveID);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (step instanceof ReplaceStep) {
|
|
194
|
+
const { slice } = step;
|
|
195
|
+
if ((_a = slice === null || slice === void 0 ? void 0 : slice.content) === null || _a === void 0 ? void 0 : _a.firstChild) {
|
|
196
|
+
const insertedNode = slice.content.firstChild;
|
|
197
|
+
if (insertedNode.attrs.dataTracked) {
|
|
198
|
+
const isPendingInsert = isPendingChange(insertedNode.attrs.dataTracked, CHANGE_OPERATION.insert);
|
|
199
|
+
if (isPendingInsert) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
185
203
|
}
|
|
186
|
-
}
|
|
187
|
-
continue;
|
|
204
|
+
}
|
|
188
205
|
}
|
|
189
206
|
cleanSteps.push(step);
|
|
190
207
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Node as PMNode, Slice } from 'prosemirror-model';
|
|
2
2
|
import { Selection, Transaction } from 'prosemirror-state';
|
|
3
3
|
import { ReplaceAroundStep, ReplaceStep, Step } from 'prosemirror-transform';
|
|
4
|
+
import { CHANGE_OPERATION, TrackedAttrs } from '../types/change';
|
|
4
5
|
import { NewDeleteAttrs, NewEmptyAttrs, NewInsertAttrs, NewReferenceAttrs, NewSplitNodeAttrs, NewUpdateAttrs } from '../types/track';
|
|
5
6
|
export declare function createNewInsertAttrs(attrs: NewEmptyAttrs): NewInsertAttrs;
|
|
6
7
|
export declare function createNewWrapAttrs(attrs: NewEmptyAttrs): NewInsertAttrs;
|
|
@@ -20,6 +21,7 @@ export declare function stepIsLift(gap: {
|
|
|
20
21
|
}, node: PMNode, to: number): boolean;
|
|
21
22
|
export declare const trFromHistory: (tr: Transaction) => string | undefined;
|
|
22
23
|
export declare const HasMoveOperations: (tr: Transaction) => Map<ReplaceStep, string>;
|
|
24
|
+
export declare const isPendingChange: (trackedAttrs: TrackedAttrs[] | undefined, operation: CHANGE_OPERATION) => boolean;
|
|
23
25
|
export declare const isDeletingPendingMovedNode: (step: ReplaceStep, doc: PMNode) => string | undefined;
|
|
24
26
|
export declare const isDirectPendingMoveDeletion: (step: ReplaceStep, doc: PMNode, movingSteps: Map<ReplaceStep, string>) => boolean;
|
|
25
27
|
export declare const handleDirectPendingMoveDeletions: (tr: Transaction, newTr: Transaction, movingSteps: Map<ReplaceStep, string>) => void;
|
package/package.json
CHANGED