@manuscripts/track-changes-plugin 2.1.1 → 2.2.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/dist/cjs/ChangeSet.js +23 -9
- package/dist/cjs/actions.js +3 -1
- package/dist/cjs/{changes/applyChanges.js → applyChanges.js} +16 -16
- package/dist/cjs/{changes → changeHelpers}/revertChange.js +3 -4
- package/dist/cjs/{mutate/dropStructureChange.js → changeHelpers/structureChange.js} +23 -17
- package/dist/cjs/{changes → changeHelpers}/updateChangeAttrs.js +4 -5
- package/dist/cjs/{changes → changeHelpers}/updateChangesStatus.js +5 -5
- package/dist/cjs/{changes/findChanges.js → findChanges.js} +5 -5
- package/dist/cjs/helpers/attributes.js +157 -0
- package/dist/cjs/{compute/setFragmentAsInserted.js → helpers/fragment.js} +71 -79
- package/dist/cjs/helpers/mark.js +19 -0
- package/dist/cjs/plugin.js +13 -22
- package/dist/cjs/trackChanges.js +47 -0
- package/dist/cjs/{change-steps → tracking/change-step}/diffChangeSteps.js +23 -28
- package/dist/cjs/{utils/mapChangeStep.js → tracking/change-step/mapChangeSteps.js} +1 -1
- package/dist/cjs/{change-steps → tracking/change-step}/processChangeSteps.js +14 -48
- package/dist/cjs/tracking/fixAndHandleSelection.js +54 -0
- package/dist/cjs/{mutate → tracking/lib}/deleteAndMergeSplitNodes.js +7 -40
- package/dist/cjs/{mutate → tracking/lib}/deleteNode.js +8 -9
- package/dist/cjs/{mutate/deleteText.js → tracking/lib/deleteTextIfInserted.js} +4 -4
- package/dist/cjs/{change-steps → tracking/lib}/matchInserted.js +15 -23
- package/dist/cjs/{mutate → tracking/lib}/mergeTrackedMarks.js +3 -3
- package/dist/cjs/tracking/lib/processStepsBeforeTracking.js +17 -0
- package/dist/cjs/{steps/utils.js → tracking/steps-trackers/qualifiers.js} +37 -10
- package/dist/cjs/{steps/trackAttrsChange.js → tracking/steps-trackers/trackAttrsChangeStep.js} +3 -3
- package/dist/cjs/{steps → tracking/steps-trackers}/trackMarkSteps.js +14 -11
- package/dist/cjs/{steps → tracking/steps-trackers}/trackReplaceAroundStep.js +12 -46
- package/dist/cjs/tracking/steps-trackers/trackReplaceStep.js +85 -0
- package/dist/cjs/tracking/trackTransaction.js +93 -0
- package/dist/cjs/tracking/transactionProcessing.js +164 -0
- package/dist/cjs/tracking/types.js +17 -0
- package/dist/es/ChangeSet.js +23 -9
- package/dist/es/actions.js +1 -0
- package/dist/es/{changes/applyChanges.js → applyChanges.js} +10 -10
- package/dist/es/{changes → changeHelpers}/revertChange.js +1 -2
- package/dist/es/{mutate/dropStructureChange.js → changeHelpers/structureChange.js} +10 -5
- package/dist/es/{changes → changeHelpers}/updateChangeAttrs.js +2 -3
- package/dist/es/{changes → changeHelpers}/updateChangesStatus.js +4 -4
- package/dist/es/{changes/findChanges.js → findChanges.js} +3 -3
- package/dist/es/helpers/attributes.js +136 -0
- package/dist/es/{compute/setFragmentAsInserted.js → helpers/fragment.js} +66 -42
- package/dist/es/helpers/mark.js +15 -0
- package/dist/es/plugin.js +12 -21
- package/dist/es/trackChanges.js +44 -0
- package/dist/es/{change-steps → tracking/change-step}/diffChangeSteps.js +23 -28
- package/dist/es/{utils/mapChangeStep.js → tracking/change-step/mapChangeSteps.js} +1 -1
- package/dist/es/{change-steps → tracking/change-step}/processChangeSteps.js +10 -11
- package/dist/es/tracking/fixAndHandleSelection.js +49 -0
- package/dist/es/{mutate → tracking/lib}/deleteAndMergeSplitNodes.js +7 -7
- package/dist/es/{mutate → tracking/lib}/deleteNode.js +4 -5
- package/dist/es/{mutate/deleteText.js → tracking/lib/deleteTextIfInserted.js} +1 -1
- package/dist/es/{change-steps → tracking/lib}/matchInserted.js +15 -23
- package/dist/es/{mutate → tracking/lib}/mergeTrackedMarks.js +2 -2
- package/dist/es/tracking/lib/processStepsBeforeTracking.js +14 -0
- package/dist/es/{steps/utils.js → tracking/steps-trackers/qualifiers.js} +32 -7
- package/dist/es/{steps/trackAttrsChange.js → tracking/steps-trackers/trackAttrsChangeStep.js} +3 -3
- package/dist/es/{steps → tracking/steps-trackers}/trackMarkSteps.js +6 -3
- package/dist/es/{steps → tracking/steps-trackers}/trackReplaceAroundStep.js +9 -10
- package/dist/es/{steps → tracking/steps-trackers}/trackReplaceStep.js +34 -26
- package/dist/es/tracking/trackTransaction.js +87 -0
- package/dist/es/tracking/transactionProcessing.js +153 -0
- package/dist/es/tracking/types.js +16 -0
- package/dist/types/ChangeSet.d.ts +4 -1
- package/dist/types/actions.d.ts +1 -0
- package/dist/types/applyChanges.d.ts +6 -0
- package/dist/types/{mutate/dropStructureChange.d.ts → changeHelpers/structureChange.d.ts} +2 -1
- package/dist/types/{changes/findChanges.d.ts → findChanges.d.ts} +1 -1
- package/dist/types/helpers/attributes.d.ts +47 -0
- package/dist/types/{compute/setFragmentAsInserted.d.ts → helpers/fragment.d.ts} +3 -1
- package/dist/types/helpers/mark.d.ts +3 -0
- package/dist/types/trackChanges.d.ts +17 -0
- package/dist/types/tracking/change-step/diffChangeSteps.d.ts +17 -0
- package/dist/types/{utils/mapChangeStep.d.ts → tracking/change-step/mapChangeSteps.d.ts} +2 -2
- package/dist/types/tracking/change-step/processChangeSteps.d.ts +6 -0
- package/dist/types/tracking/fixAndHandleSelection.d.ts +20 -0
- package/dist/types/{mutate → tracking/lib}/deleteAndMergeSplitNodes.d.ts +4 -5
- package/dist/types/{mutate → tracking/lib}/deleteNode.d.ts +2 -2
- package/dist/types/{mutate/deleteText.d.ts → tracking/lib/deleteTextIfInserted.d.ts} +1 -1
- package/dist/types/tracking/lib/matchInserted.d.ts +18 -0
- package/dist/types/tracking/lib/processStepsBeforeTracking.d.ts +4 -0
- package/dist/types/{compute → tracking/lib}/splitSliceIntoMergedParts.d.ts +1 -1
- package/dist/types/{steps/utils.d.ts → tracking/steps-trackers/qualifiers.d.ts} +5 -3
- package/dist/types/{steps/trackAttrsChange.d.ts → tracking/steps-trackers/trackAttrsChangeStep.d.ts} +4 -4
- package/dist/types/{steps → tracking/steps-trackers}/trackMarkSteps.d.ts +1 -1
- package/dist/types/{steps → tracking/steps-trackers}/trackReplaceAroundStep.d.ts +2 -2
- package/dist/types/tracking/steps-trackers/trackReplaceStep.d.ts +5 -0
- package/dist/types/tracking/trackTransaction.d.ts +4 -0
- package/dist/types/tracking/transactionProcessing.d.ts +12 -0
- package/dist/types/tracking/types.d.ts +65 -0
- package/dist/types/types/change.d.ts +1 -1
- package/dist/types/types/track.d.ts +0 -30
- package/package.json +17 -14
- package/dist/cjs/compute/nodeHelpers.js +0 -83
- package/dist/cjs/steps/trackReplaceStep.js +0 -110
- package/dist/cjs/steps/trackTransaction.js +0 -162
- package/dist/cjs/types/step.js +0 -2
- package/dist/cjs/utils/track-utils.js +0 -239
- package/dist/es/compute/nodeHelpers.js +0 -73
- package/dist/es/steps/trackTransaction.js +0 -156
- package/dist/es/types/step.js +0 -1
- package/dist/es/utils/track-utils.js +0 -217
- package/dist/types/change-steps/diffChangeSteps.d.ts +0 -2
- package/dist/types/change-steps/matchInserted.d.ts +0 -3
- package/dist/types/change-steps/processChangeSteps.d.ts +0 -6
- package/dist/types/changes/applyChanges.d.ts +0 -6
- package/dist/types/compute/nodeHelpers.d.ts +0 -14
- package/dist/types/steps/trackReplaceStep.d.ts +0 -6
- package/dist/types/steps/trackTransaction.d.ts +0 -3
- package/dist/types/types/step.d.ts +0 -40
- package/dist/types/utils/track-utils.d.ts +0 -24
- /package/dist/cjs/{changes → changeHelpers}/fixInconsistentChanges.js +0 -0
- /package/dist/cjs/{mutate → tracking/lib}/mergeNode.js +0 -0
- /package/dist/cjs/{compute → tracking/lib}/splitSliceIntoMergedParts.js +0 -0
- /package/dist/es/{changes → changeHelpers}/fixInconsistentChanges.js +0 -0
- /package/dist/es/{mutate → tracking/lib}/mergeNode.js +0 -0
- /package/dist/es/{compute → tracking/lib}/splitSliceIntoMergedParts.js +0 -0
- /package/dist/types/{changes → changeHelpers}/fixInconsistentChanges.d.ts +0 -0
- /package/dist/types/{changes → changeHelpers}/revertChange.d.ts +0 -0
- /package/dist/types/{changes → changeHelpers}/updateChangeAttrs.d.ts +0 -0
- /package/dist/types/{changes → changeHelpers}/updateChangesStatus.d.ts +0 -0
- /package/dist/types/{mutate → tracking/lib}/mergeNode.d.ts +0 -0
- /package/dist/types/{mutate → tracking/lib}/mergeTrackedMarks.d.ts +0 -0
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.updateBlockNodesAttrs = exports.filterMeaninglessMoveSteps = exports.handleDirectPendingMoveDeletions = exports.isDirectPendingMoveDeletion = exports.isDeletingPendingMovedNode = exports.isPendingChange = exports.HasMoveOperations = exports.trFromHistory = void 0;
|
|
15
|
-
exports.createNewInsertAttrs = createNewInsertAttrs;
|
|
16
|
-
exports.createNewWrapAttrs = createNewWrapAttrs;
|
|
17
|
-
exports.createNewSplitAttrs = createNewSplitAttrs;
|
|
18
|
-
exports.createNewReferenceAttrs = createNewReferenceAttrs;
|
|
19
|
-
exports.createNewDeleteAttrs = createNewDeleteAttrs;
|
|
20
|
-
exports.createNewMoveAttrs = createNewMoveAttrs;
|
|
21
|
-
exports.createNewUpdateAttrs = createNewUpdateAttrs;
|
|
22
|
-
exports.createNewStructureAttrs = createNewStructureAttrs;
|
|
23
|
-
exports.isValidTrackableMark = isValidTrackableMark;
|
|
24
|
-
exports.excludeFromTracked = excludeFromTracked;
|
|
25
|
-
exports.isInlineMarkChange = isInlineMarkChange;
|
|
26
|
-
const prosemirror_model_1 = require("prosemirror-model");
|
|
27
|
-
const prosemirror_transform_1 = require("prosemirror-transform");
|
|
28
|
-
const actions_1 = require("../actions");
|
|
29
|
-
const change_1 = require("../types/change");
|
|
30
|
-
const uuidv4_1 = require("./uuidv4");
|
|
31
|
-
function createNewInsertAttrs(attrs) {
|
|
32
|
-
return Object.assign(Object.assign({}, attrs), { operation: change_1.CHANGE_OPERATION.insert });
|
|
33
|
-
}
|
|
34
|
-
function createNewWrapAttrs(attrs) {
|
|
35
|
-
return Object.assign(Object.assign({}, attrs), { operation: change_1.CHANGE_OPERATION.wrap_with_node });
|
|
36
|
-
}
|
|
37
|
-
function createNewSplitAttrs(attrs) {
|
|
38
|
-
return Object.assign(Object.assign({}, attrs), { operation: change_1.CHANGE_OPERATION.node_split });
|
|
39
|
-
}
|
|
40
|
-
function createNewReferenceAttrs(attrs, id) {
|
|
41
|
-
return Object.assign(Object.assign({}, attrs), { operation: change_1.CHANGE_OPERATION.reference, referenceId: id });
|
|
42
|
-
}
|
|
43
|
-
function createNewDeleteAttrs(attrs) {
|
|
44
|
-
return Object.assign(Object.assign({}, attrs), { operation: change_1.CHANGE_OPERATION.delete });
|
|
45
|
-
}
|
|
46
|
-
function createNewMoveAttrs(attrs, indentationType) {
|
|
47
|
-
return Object.assign(Object.assign(Object.assign({}, attrs), { operation: change_1.CHANGE_OPERATION.move }), (indentationType && { indentationType }));
|
|
48
|
-
}
|
|
49
|
-
function createNewUpdateAttrs(attrs, oldAttrs) {
|
|
50
|
-
const { dataTracked } = oldAttrs, restAttrs = __rest(oldAttrs, ["dataTracked"]);
|
|
51
|
-
return Object.assign(Object.assign({}, attrs), { operation: change_1.CHANGE_OPERATION.set_node_attributes, oldAttrs: JSON.parse(JSON.stringify(restAttrs)) });
|
|
52
|
-
}
|
|
53
|
-
function createNewStructureAttrs(attrs) {
|
|
54
|
-
return Object.assign(Object.assign({}, attrs), { operation: change_1.CHANGE_OPERATION.structure });
|
|
55
|
-
}
|
|
56
|
-
const trFromHistory = (tr) => Object.keys(tr.meta).find((s) => s.startsWith('history$'));
|
|
57
|
-
exports.trFromHistory = trFromHistory;
|
|
58
|
-
const HasMoveOperations = (tr) => {
|
|
59
|
-
const movingAssoc = new Map();
|
|
60
|
-
if (tr.steps.length < 2) {
|
|
61
|
-
return movingAssoc;
|
|
62
|
-
}
|
|
63
|
-
if (tr.getMeta(actions_1.TrackChangesAction.structuralChangeAction)) {
|
|
64
|
-
const commonID = (0, uuidv4_1.uuidv4)();
|
|
65
|
-
movingAssoc.set(tr.steps[0], commonID);
|
|
66
|
-
movingAssoc.set(tr.steps[1], commonID);
|
|
67
|
-
return movingAssoc;
|
|
68
|
-
}
|
|
69
|
-
const matched = [];
|
|
70
|
-
for (let i = 0; i < tr.steps.length; i++) {
|
|
71
|
-
if (matched.includes(i)) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
const step = tr.steps[i];
|
|
75
|
-
const doc = tr.docs[i];
|
|
76
|
-
if (!step.slice) {
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
const stepDeletesContent = step.from !== step.to && step.slice.size === 0;
|
|
80
|
-
const stepInsertsContent = step.slice.size && step.slice.content.firstChild ? true : false;
|
|
81
|
-
for (let g = 0; g < tr.steps.length; g++) {
|
|
82
|
-
if (g === i || matched.includes(g)) {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
const peerStep = tr.steps[g];
|
|
86
|
-
if (!peerStep.slice) {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
const peerStepInsertsContent = peerStep.slice.size && peerStep.slice.content.firstChild;
|
|
90
|
-
const peerStepDeletesContent = peerStep.from !== peerStep.to && peerStep.slice.size === 0;
|
|
91
|
-
if (stepDeletesContent) {
|
|
92
|
-
const deletedContent = doc.slice(step.from, step.to);
|
|
93
|
-
if (peerStepInsertsContent &&
|
|
94
|
-
deletedContent.content.firstChild &&
|
|
95
|
-
peerStep.slice.content.firstChild.toString() === deletedContent.content.firstChild.toString()) {
|
|
96
|
-
const commonID = (0, uuidv4_1.uuidv4)();
|
|
97
|
-
movingAssoc.set(peerStep, commonID);
|
|
98
|
-
movingAssoc.set(step, commonID);
|
|
99
|
-
matched.push(i, g);
|
|
100
|
-
}
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
if (stepInsertsContent && peerStepDeletesContent) {
|
|
104
|
-
const insertedContent = step.slice;
|
|
105
|
-
const deletedPeerContent = tr.docs[g].slice(peerStep.from, peerStep.to);
|
|
106
|
-
if (insertedContent.content.firstChild &&
|
|
107
|
-
deletedPeerContent.content.firstChild &&
|
|
108
|
-
insertedContent.content.firstChild.toString() === deletedPeerContent.content.firstChild.toString()) {
|
|
109
|
-
const commonID = (0, uuidv4_1.uuidv4)();
|
|
110
|
-
movingAssoc.set(peerStep, commonID);
|
|
111
|
-
movingAssoc.set(step, commonID);
|
|
112
|
-
}
|
|
113
|
-
matched.push(i, g);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return movingAssoc;
|
|
118
|
-
};
|
|
119
|
-
exports.HasMoveOperations = HasMoveOperations;
|
|
120
|
-
const isPendingChange = (trackedAttrs, operation) => {
|
|
121
|
-
return !!(trackedAttrs === null || trackedAttrs === void 0 ? void 0 : trackedAttrs.some((t) => t.operation === operation));
|
|
122
|
-
};
|
|
123
|
-
exports.isPendingChange = isPendingChange;
|
|
124
|
-
const isDeletingPendingMovedNode = (step, doc) => {
|
|
125
|
-
if (!step.slice || step.from === step.to || step.slice.content.size > 0) {
|
|
126
|
-
return undefined;
|
|
127
|
-
}
|
|
128
|
-
const node = doc.nodeAt(step.from);
|
|
129
|
-
if (!node) {
|
|
130
|
-
return undefined;
|
|
131
|
-
}
|
|
132
|
-
const trackedAttrs = node.attrs.dataTracked;
|
|
133
|
-
const found = trackedAttrs === null || trackedAttrs === void 0 ? void 0 : trackedAttrs.find((tracked) => tracked.operation === change_1.CHANGE_OPERATION.move && tracked.status === change_1.CHANGE_STATUS.pending);
|
|
134
|
-
if (found === null || found === void 0 ? void 0 : found.moveNodeId) {
|
|
135
|
-
return found.moveNodeId;
|
|
136
|
-
}
|
|
137
|
-
return undefined;
|
|
138
|
-
};
|
|
139
|
-
exports.isDeletingPendingMovedNode = isDeletingPendingMovedNode;
|
|
140
|
-
const isDirectPendingMoveDeletion = (step, doc, movingSteps) => {
|
|
141
|
-
if (step.from === step.to || step.slice.content.size > 0) {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
if (movingSteps.has(step)) {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
const node = doc.nodeAt(step.from);
|
|
148
|
-
if (!node) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
return (0, exports.isPendingChange)(node.attrs.dataTracked, change_1.CHANGE_OPERATION.move);
|
|
152
|
-
};
|
|
153
|
-
exports.isDirectPendingMoveDeletion = isDirectPendingMoveDeletion;
|
|
154
|
-
const handleDirectPendingMoveDeletions = (tr, newTr, movingSteps) => {
|
|
155
|
-
tr.steps.forEach((step) => {
|
|
156
|
-
if (step instanceof prosemirror_transform_1.ReplaceStep) {
|
|
157
|
-
const doc = tr.docs[tr.steps.indexOf(step)];
|
|
158
|
-
if ((0, exports.isDirectPendingMoveDeletion)(step, doc, movingSteps)) {
|
|
159
|
-
const node = doc.nodeAt(step.from);
|
|
160
|
-
if (node === null || node === void 0 ? void 0 : node.attrs.dataTracked) {
|
|
161
|
-
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)) }));
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
exports.handleDirectPendingMoveDeletions = handleDirectPendingMoveDeletions;
|
|
168
|
-
const filterMeaninglessMoveSteps = (tr, movingSteps) => {
|
|
169
|
-
var _a;
|
|
170
|
-
const cleanSteps = [];
|
|
171
|
-
for (let i = 0; i < tr.steps.length; i++) {
|
|
172
|
-
const step = tr.steps[i];
|
|
173
|
-
const moveID = movingSteps.get(step);
|
|
174
|
-
if (moveID) {
|
|
175
|
-
const prevMoveID = (0, exports.isDeletingPendingMovedNode)(step, tr.docs[i]);
|
|
176
|
-
if (prevMoveID) {
|
|
177
|
-
movingSteps.forEach((replaceStepMoveID, replaceStep) => {
|
|
178
|
-
if (replaceStep !== step && moveID === replaceStepMoveID) {
|
|
179
|
-
movingSteps.set(replaceStep, prevMoveID);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
if (step instanceof prosemirror_transform_1.ReplaceStep && !tr.getMeta(actions_1.TrackChangesAction.structuralChangeAction)) {
|
|
185
|
-
const { slice } = step;
|
|
186
|
-
if ((_a = slice === null || slice === void 0 ? void 0 : slice.content) === null || _a === void 0 ? void 0 : _a.firstChild) {
|
|
187
|
-
const insertedNode = slice.content.firstChild;
|
|
188
|
-
if (insertedNode.attrs.dataTracked) {
|
|
189
|
-
const isPendingInsert = (0, exports.isPendingChange)(insertedNode.attrs.dataTracked, change_1.CHANGE_OPERATION.insert);
|
|
190
|
-
if (isPendingInsert) {
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
cleanSteps.push(step);
|
|
198
|
-
}
|
|
199
|
-
return cleanSteps;
|
|
200
|
-
};
|
|
201
|
-
exports.filterMeaninglessMoveSteps = filterMeaninglessMoveSteps;
|
|
202
|
-
const updateBlockNodesAttrs = (fragment, predicate) => {
|
|
203
|
-
const updatedNodes = [];
|
|
204
|
-
fragment.forEach((child) => {
|
|
205
|
-
if (!child.isBlock) {
|
|
206
|
-
updatedNodes.push(child);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
const newContent = child.content.size ? (0, exports.updateBlockNodesAttrs)(child.content, predicate) : child.content;
|
|
210
|
-
const newAttrs = predicate(child.attrs, child);
|
|
211
|
-
updatedNodes.push(child.type.create(newAttrs, newContent, child.marks));
|
|
212
|
-
});
|
|
213
|
-
return prosemirror_model_1.Fragment.fromArray(updatedNodes);
|
|
214
|
-
};
|
|
215
|
-
exports.updateBlockNodesAttrs = updateBlockNodesAttrs;
|
|
216
|
-
function isValidTrackableMark(mark) {
|
|
217
|
-
var _a, _b;
|
|
218
|
-
const spec = mark.type.spec;
|
|
219
|
-
const name = mark.type.name;
|
|
220
|
-
if (!name.startsWith('tracked_') &&
|
|
221
|
-
((_a = spec.attrs) === null || _a === void 0 ? void 0 : _a.dataTracked) &&
|
|
222
|
-
typeof ((_b = spec.attrs) === null || _b === void 0 ? void 0 : _b.dataTracked) === 'object') {
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
return false;
|
|
226
|
-
}
|
|
227
|
-
function excludeFromTracked(dataTracked, changeIdToExclude) {
|
|
228
|
-
if (!dataTracked) {
|
|
229
|
-
return null;
|
|
230
|
-
}
|
|
231
|
-
const newDataTracked = dataTracked.filter((c) => c.id !== changeIdToExclude);
|
|
232
|
-
return newDataTracked.length ? newDataTracked : null;
|
|
233
|
-
}
|
|
234
|
-
function isInlineMarkChange(change) {
|
|
235
|
-
if (change.type == 'mark-change') {
|
|
236
|
-
return change.nodeType.isInline || change.nodeType.isText;
|
|
237
|
-
}
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { CHANGE_OPERATION } from '../types/change';
|
|
2
|
-
import { log } from '../utils/logger';
|
|
3
|
-
import { isValidTrackableMark } from '../utils/track-utils';
|
|
4
|
-
import { uuidv4 } from '../utils/uuidv4';
|
|
5
|
-
export function addTrackIdIfDoesntExist(attrs) {
|
|
6
|
-
if (!attrs.id) {
|
|
7
|
-
return Object.assign({ id: uuidv4() }, attrs);
|
|
8
|
-
}
|
|
9
|
-
return attrs;
|
|
10
|
-
}
|
|
11
|
-
export function getTextNodeTrackedMarkData(node, schema) {
|
|
12
|
-
if (!node || !node.isText) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
const marksTrackedData = [];
|
|
16
|
-
node.marks.forEach((mark) => {
|
|
17
|
-
if (mark.type === schema.marks.tracked_insert || mark.type === schema.marks.tracked_delete) {
|
|
18
|
-
const operation = mark.type === schema.marks.tracked_insert ? CHANGE_OPERATION.insert : CHANGE_OPERATION.delete;
|
|
19
|
-
marksTrackedData.push(Object.assign(Object.assign({}, mark.attrs.dataTracked), { operation }));
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
if (marksTrackedData.length > 1) {
|
|
23
|
-
log.warn('inline node with more than 1 of tracked marks', marksTrackedData);
|
|
24
|
-
}
|
|
25
|
-
return marksTrackedData[0] || undefined;
|
|
26
|
-
}
|
|
27
|
-
export function getBlockInlineTrackedData(node) {
|
|
28
|
-
const { dataTracked } = node.attrs;
|
|
29
|
-
if (dataTracked && !Array.isArray(dataTracked)) {
|
|
30
|
-
return [dataTracked];
|
|
31
|
-
}
|
|
32
|
-
return dataTracked || [];
|
|
33
|
-
}
|
|
34
|
-
export function getMarkTrackedData(node) {
|
|
35
|
-
const tracked = node === null || node === void 0 ? void 0 : node.marks.reduce((acc, current) => {
|
|
36
|
-
if (isValidTrackableMark(current) && current.attrs.dataTracked) {
|
|
37
|
-
acc.set(current, current.attrs.dataTracked);
|
|
38
|
-
}
|
|
39
|
-
return acc;
|
|
40
|
-
}, new Map());
|
|
41
|
-
return tracked || new Map();
|
|
42
|
-
}
|
|
43
|
-
export function getNodeTrackedData(node, schema) {
|
|
44
|
-
let tracked;
|
|
45
|
-
if (node && !node.isText) {
|
|
46
|
-
tracked = getBlockInlineTrackedData(node);
|
|
47
|
-
}
|
|
48
|
-
else if (node === null || node === void 0 ? void 0 : node.isText) {
|
|
49
|
-
tracked = getTextNodeTrackedMarkData(node, schema);
|
|
50
|
-
}
|
|
51
|
-
if (tracked && !Array.isArray(tracked)) {
|
|
52
|
-
tracked = [tracked];
|
|
53
|
-
}
|
|
54
|
-
return tracked;
|
|
55
|
-
}
|
|
56
|
-
export function equalMarks(n1, n2) {
|
|
57
|
-
return (n1.marks.length === n2.marks.length &&
|
|
58
|
-
n1.marks.every((mark) => n1.marks.find((m) => m.type === mark.type)));
|
|
59
|
-
}
|
|
60
|
-
export function shouldMergeTrackedAttributes(left, right) {
|
|
61
|
-
if (!left || !right) {
|
|
62
|
-
log.warn('passed undefined dataTracked attributes to shouldMergeTrackedAttributes', {
|
|
63
|
-
left,
|
|
64
|
-
right,
|
|
65
|
-
});
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
return (left.status === right.status && left.operation === right.operation && left.authorID === right.authorID);
|
|
69
|
-
}
|
|
70
|
-
export function getMergeableMarkTrackedAttrs(node, attrs, schema) {
|
|
71
|
-
const nodeAttrs = getTextNodeTrackedMarkData(node, schema);
|
|
72
|
-
return nodeAttrs && shouldMergeTrackedAttributes(nodeAttrs, attrs) ? nodeAttrs : null;
|
|
73
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { NodeSelection as NodeSelectionClass, TextSelection, } from 'prosemirror-state';
|
|
2
|
-
import { AddMarkStep, AddNodeMarkStep, AttrStep, Mapping, RemoveMarkStep, RemoveNodeMarkStep, ReplaceAroundStep, ReplaceStep, } from 'prosemirror-transform';
|
|
3
|
-
import { getAction, TrackChangesAction } from '../actions';
|
|
4
|
-
import { diffChangeSteps } from '../change-steps/diffChangeSteps';
|
|
5
|
-
import { processChangeSteps } from '../change-steps/processChangeSteps';
|
|
6
|
-
import { updateChangeAttrs } from '../changes/updateChangeAttrs';
|
|
7
|
-
import { getNodeTrackedData } from '../compute/nodeHelpers';
|
|
8
|
-
import { CHANGE_STATUS } from '../types/change';
|
|
9
|
-
import { log } from '../utils/logger';
|
|
10
|
-
import { mapChangeSteps } from '../utils/mapChangeStep';
|
|
11
|
-
import { filterMeaninglessMoveSteps, handleDirectPendingMoveDeletions, HasMoveOperations, } from '../utils/track-utils';
|
|
12
|
-
import { uuidv4 } from '../utils/uuidv4';
|
|
13
|
-
import trackAttrsChange from './trackAttrsChange';
|
|
14
|
-
import { trackAddMarkStep, trackAddNodeMarkStep, trackRemoveMarkStep, trackRemoveNodeMarkStep, } from './trackMarkSteps';
|
|
15
|
-
import { trackReplaceAroundStep } from './trackReplaceAroundStep';
|
|
16
|
-
import { trackReplaceStep } from './trackReplaceStep';
|
|
17
|
-
import { isStructureSteps } from './utils';
|
|
18
|
-
const getSelectionStaticConstructor = (sel) => Object.getPrototypeOf(sel).constructor;
|
|
19
|
-
const isHighlightMarkerNode = (node) => node && node.type === node.type.schema.nodes.highlight_marker;
|
|
20
|
-
export function trackTransaction(tr, oldState, newTr, authorID, changeSet) {
|
|
21
|
-
var _a, _b, _c, _d, _e, _f;
|
|
22
|
-
const emptyAttrs = {
|
|
23
|
-
authorID,
|
|
24
|
-
reviewedByID: null,
|
|
25
|
-
createdAt: tr.time,
|
|
26
|
-
updatedAt: tr.time,
|
|
27
|
-
statusUpdateAt: 0,
|
|
28
|
-
status: CHANGE_STATUS.pending,
|
|
29
|
-
};
|
|
30
|
-
const action = (_a = getAction(tr, TrackChangesAction.indentationAction)) === null || _a === void 0 ? void 0 : _a.action;
|
|
31
|
-
const isIndentation = action === 'indent' || action === 'unindent';
|
|
32
|
-
const wasNodeSelection = tr.selection instanceof NodeSelectionClass;
|
|
33
|
-
const setsNewSelection = tr.selectionSet;
|
|
34
|
-
const deletedNodeMapping = new Mapping();
|
|
35
|
-
let iters = 0;
|
|
36
|
-
log.info('ORIGINAL transaction', tr);
|
|
37
|
-
let trContext = {};
|
|
38
|
-
let movingStepsAssociated = HasMoveOperations(tr);
|
|
39
|
-
if (isIndentation) {
|
|
40
|
-
const moveId = uuidv4();
|
|
41
|
-
tr.steps.forEach((step) => {
|
|
42
|
-
if (step instanceof ReplaceStep) {
|
|
43
|
-
movingStepsAssociated.set(step, moveId);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
handleDirectPendingMoveDeletions(tr, newTr, movingStepsAssociated);
|
|
48
|
-
const cleanSteps = filterMeaninglessMoveSteps(tr, movingStepsAssociated);
|
|
49
|
-
for (let i = cleanSteps.length - 1; i >= 0; i--) {
|
|
50
|
-
const step = cleanSteps[i];
|
|
51
|
-
log.info('transaction step', step);
|
|
52
|
-
iters += 1;
|
|
53
|
-
const uiEvent = tr.getMeta('uiEvent');
|
|
54
|
-
const isMassReplace = tr.getMeta('massSearchReplace');
|
|
55
|
-
if (iters > 20 && uiEvent != 'cut' && !isMassReplace) {
|
|
56
|
-
console.error('@manuscripts/track-changes-plugin: Possible infinite loop in iterating tr.steps, tracking skipped!\n' +
|
|
57
|
-
'This is probably an error with the library, please report back to maintainers with a reproduction if possible', newTr);
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
else if (!(step instanceof ReplaceStep) && step.constructor.name === 'ReplaceStep') {
|
|
61
|
-
console.error('@manuscripts/track-changes-plugin: Multiple prosemirror-transform packages imported, alias/dedupe them ' +
|
|
62
|
-
'or instanceof checks fail as well as creating new steps');
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
else if (step instanceof ReplaceStep) {
|
|
66
|
-
const { slice } = step;
|
|
67
|
-
if (((_c = (_b = slice === null || slice === void 0 ? void 0 : slice.content) === null || _b === void 0 ? void 0 : _b.content) === null || _c === void 0 ? void 0 : _c.length) === 1 && isHighlightMarkerNode(slice.content.content[0])) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
const invertedStep = step.invert(tr.docs[i]);
|
|
71
|
-
const isDelete = step.from !== step.to && step.slice.content.size < invertedStep.slice.content.size;
|
|
72
|
-
let thisStepMapping = tr.mapping.slice(i + 1, i + 1);
|
|
73
|
-
if (isDelete || isStructureSteps(tr)) {
|
|
74
|
-
thisStepMapping = deletedNodeMapping;
|
|
75
|
-
}
|
|
76
|
-
const newStep = new ReplaceStep(thisStepMapping.map(invertedStep.from), thisStepMapping.map(invertedStep.to), invertedStep.slice);
|
|
77
|
-
const stepResult = newTr.maybeStep(newStep);
|
|
78
|
-
let [steps, startPos] = trackReplaceStep(step, oldState, newTr, emptyAttrs, stepResult, tr.docs[i], tr, movingStepsAssociated.get(step));
|
|
79
|
-
if (steps.length === 1) {
|
|
80
|
-
const step = steps[0];
|
|
81
|
-
if (isHighlightMarkerNode((step === null || step === void 0 ? void 0 : step.node) || ((_e = (_d = step === null || step === void 0 ? void 0 : step.slice) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e.content[0]))) {
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
startPos = thisStepMapping.map(startPos);
|
|
86
|
-
steps = mapChangeSteps(steps, thisStepMapping);
|
|
87
|
-
log.info('CHANGES: ', steps);
|
|
88
|
-
const deleted = steps.filter((s) => s.type !== 'insert-slice');
|
|
89
|
-
const inserted = steps.filter((s) => s.type === 'insert-slice');
|
|
90
|
-
steps = diffChangeSteps(deleted, inserted);
|
|
91
|
-
log.info('DIFFED STEPS: ', steps);
|
|
92
|
-
const [mapping, selectionPos] = processChangeSteps(steps, startPos || tr.selection.head, newTr, movingStepsAssociated.has(step)
|
|
93
|
-
? Object.assign(Object.assign({}, emptyAttrs), { moveNodeId: movingStepsAssociated.get(step) }) : emptyAttrs, oldState.schema, deletedNodeMapping);
|
|
94
|
-
if (!wasNodeSelection && !setsNewSelection) {
|
|
95
|
-
const sel = getSelectionStaticConstructor(tr.selection);
|
|
96
|
-
const near = sel.near(newTr.doc.resolve(selectionPos), -1);
|
|
97
|
-
newTr.setSelection(near);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
else if (step instanceof ReplaceAroundStep) {
|
|
101
|
-
let steps = trackReplaceAroundStep(step, oldState, tr, newTr, emptyAttrs, tr.docs[i], trContext);
|
|
102
|
-
const deleted = steps.filter((s) => s.type !== 'insert-slice');
|
|
103
|
-
const inserted = steps.filter((s) => s.type === 'insert-slice');
|
|
104
|
-
log.info('INSERT STEPS: ', inserted);
|
|
105
|
-
steps = diffChangeSteps(deleted, inserted);
|
|
106
|
-
log.info('DIFFED STEPS: ', steps);
|
|
107
|
-
const [mapping, selectionPos] = processChangeSteps(steps, tr.selection.from, newTr, emptyAttrs, oldState.schema, deletedNodeMapping);
|
|
108
|
-
}
|
|
109
|
-
else if (step instanceof AttrStep) {
|
|
110
|
-
const changeSteps = trackAttrsChange(step, oldState, tr, newTr, emptyAttrs, tr.docs[i]);
|
|
111
|
-
const [mapping, selectionPos] = processChangeSteps(changeSteps, tr.selection.from, newTr, emptyAttrs, oldState.schema, deletedNodeMapping);
|
|
112
|
-
}
|
|
113
|
-
else if (step instanceof AddMarkStep) {
|
|
114
|
-
trackAddMarkStep(step, emptyAttrs, newTr, tr.docs[i]);
|
|
115
|
-
const dataTracked = (_f = getNodeTrackedData(newTr.doc.nodeAt(step.from), oldState.schema)) === null || _f === void 0 ? void 0 : _f.pop();
|
|
116
|
-
if (dataTracked) {
|
|
117
|
-
updateChangeAttrs(newTr, { id: dataTracked.id, from: step.from, to: step.to, type: 'text-change', dataTracked }, Object.assign(Object.assign({}, dataTracked), { id: uuidv4() }), oldState.schema);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
else if (step instanceof RemoveMarkStep) {
|
|
121
|
-
trackRemoveMarkStep(step, emptyAttrs, newTr, tr.docs[i]);
|
|
122
|
-
}
|
|
123
|
-
else if (step instanceof RemoveNodeMarkStep) {
|
|
124
|
-
trackRemoveNodeMarkStep(step, emptyAttrs, newTr, tr.docs[i]);
|
|
125
|
-
}
|
|
126
|
-
else if (step instanceof AddNodeMarkStep) {
|
|
127
|
-
trackAddNodeMarkStep(step, emptyAttrs, newTr, tr.docs[i]);
|
|
128
|
-
}
|
|
129
|
-
tr.getMeta('inputType') && newTr.setMeta('inputType', tr.getMeta('inputType'));
|
|
130
|
-
tr.getMeta('uiEvent') && newTr.setMeta('uiEvent', tr.getMeta('uiEvent'));
|
|
131
|
-
}
|
|
132
|
-
if (setsNewSelection && tr.selection instanceof TextSelection) {
|
|
133
|
-
let from = tr.selection.from;
|
|
134
|
-
if (isStructureSteps(tr)) {
|
|
135
|
-
const selectionMapping = new Mapping();
|
|
136
|
-
tr.steps.map((step) => {
|
|
137
|
-
const isDeleteStep = step instanceof ReplaceStep && step.from !== step.to && step.slice.size === 0;
|
|
138
|
-
if (isDeleteStep) {
|
|
139
|
-
selectionMapping.appendMap(step.getMap().invert());
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
selectionMapping.appendMapping(deletedNodeMapping);
|
|
143
|
-
from = selectionMapping.map(tr.selection.from);
|
|
144
|
-
}
|
|
145
|
-
const newPos = newTr.doc.resolve(from);
|
|
146
|
-
newTr.setSelection(new TextSelection(newPos));
|
|
147
|
-
}
|
|
148
|
-
if (wasNodeSelection) {
|
|
149
|
-
log.info('Getting into node select!');
|
|
150
|
-
const mappedPos = newTr.mapping.map(tr.selection.from, -1);
|
|
151
|
-
const sel = getSelectionStaticConstructor(tr.selection);
|
|
152
|
-
newTr.setSelection(sel.create(newTr.doc, mappedPos));
|
|
153
|
-
}
|
|
154
|
-
log.info('NEW transaction', newTr);
|
|
155
|
-
return newTr;
|
|
156
|
-
}
|
package/dist/es/types/step.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|