@manuscripts/track-changes-plugin 1.6.1 → 1.7.0-LEAN-2850
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/actions.d.ts +3 -1
- package/dist/index.cjs +26 -9
- package/dist/index.js +26 -9
- package/dist/steps/trackReplaceAroundStep.d.ts +1 -1
- package/package.json +1 -1
package/dist/actions.d.ts
CHANGED
|
@@ -22,7 +22,8 @@ export declare enum TrackChangesAction {
|
|
|
22
22
|
setPluginStatus = "track-changes-set-track-status",
|
|
23
23
|
setChangeStatuses = "track-changes-set-change-statuses",
|
|
24
24
|
refreshChanges = "track-changes-refresh-changes",
|
|
25
|
-
applyAndRemoveChanges = "track-changes-apply-remove-changes"
|
|
25
|
+
applyAndRemoveChanges = "track-changes-apply-remove-changes",
|
|
26
|
+
updateMetaNode = "track-changes-update-meta-node"
|
|
26
27
|
}
|
|
27
28
|
export declare type TrackChangesActionParams = {
|
|
28
29
|
[TrackChangesAction.skipTrack]: boolean;
|
|
@@ -34,6 +35,7 @@ export declare type TrackChangesActionParams = {
|
|
|
34
35
|
};
|
|
35
36
|
[TrackChangesAction.refreshChanges]: boolean;
|
|
36
37
|
[TrackChangesAction.applyAndRemoveChanges]: boolean;
|
|
38
|
+
[TrackChangesAction.updateMetaNode]: boolean;
|
|
37
39
|
};
|
|
38
40
|
/**
|
|
39
41
|
* Gets the value of a meta field, action payload, of a defined track-changes action.
|
package/dist/index.cjs
CHANGED
|
@@ -19,6 +19,7 @@ var TrackChangesAction;
|
|
|
19
19
|
TrackChangesAction["setChangeStatuses"] = "track-changes-set-change-statuses";
|
|
20
20
|
TrackChangesAction["refreshChanges"] = "track-changes-refresh-changes";
|
|
21
21
|
TrackChangesAction["applyAndRemoveChanges"] = "track-changes-apply-remove-changes";
|
|
22
|
+
TrackChangesAction["updateMetaNode"] = "track-changes-update-meta-node";
|
|
22
23
|
})(TrackChangesAction || (TrackChangesAction = {}));
|
|
23
24
|
/**
|
|
24
25
|
* Gets the value of a meta field, action payload, of a defined track-changes action.
|
|
@@ -161,13 +162,14 @@ const enableDebug = (enabled) => {
|
|
|
161
162
|
}
|
|
162
163
|
};
|
|
163
164
|
|
|
164
|
-
var _ChangeSet_changes;
|
|
165
|
+
var _ChangeSet_instances, _ChangeSet_changes, _ChangeSet_isSameNodeChange, _ChangeSet_isNotPendingOrDeleted;
|
|
165
166
|
/**
|
|
166
167
|
* ChangeSet is a data structure to contain the tracked changes with some utility methods and computed
|
|
167
168
|
* values to allow easier operability.
|
|
168
169
|
*/
|
|
169
170
|
class ChangeSet {
|
|
170
171
|
constructor(changes = []) {
|
|
172
|
+
_ChangeSet_instances.add(this);
|
|
171
173
|
_ChangeSet_changes.set(this, void 0);
|
|
172
174
|
__classPrivateFieldSet(this, _ChangeSet_changes, changes, "f");
|
|
173
175
|
}
|
|
@@ -198,7 +200,10 @@ class ChangeSet {
|
|
|
198
200
|
rootNodes.push(currentNodeChange);
|
|
199
201
|
currentNodeChange = undefined;
|
|
200
202
|
}
|
|
201
|
-
if (currentNodeChange &&
|
|
203
|
+
if (currentNodeChange &&
|
|
204
|
+
c.from < currentNodeChange.to &&
|
|
205
|
+
!(__classPrivateFieldGet(this, _ChangeSet_instances, "m", _ChangeSet_isSameNodeChange).call(this, currentNodeChange, c) &&
|
|
206
|
+
__classPrivateFieldGet(this, _ChangeSet_instances, "m", _ChangeSet_isNotPendingOrDeleted).call(this, currentNodeChange))) {
|
|
202
207
|
currentNodeChange.children.push(c);
|
|
203
208
|
}
|
|
204
209
|
else if (c.type === 'node-change') {
|
|
@@ -320,7 +325,12 @@ class ChangeSet {
|
|
|
320
325
|
return change.type === 'node-attr-change';
|
|
321
326
|
}
|
|
322
327
|
}
|
|
323
|
-
_ChangeSet_changes = new WeakMap()
|
|
328
|
+
_ChangeSet_changes = new WeakMap(), _ChangeSet_instances = new WeakSet(), _ChangeSet_isSameNodeChange = function _ChangeSet_isSameNodeChange(currentChange, nextChange) {
|
|
329
|
+
return currentChange.from === nextChange.from && currentChange.to === nextChange.to;
|
|
330
|
+
}, _ChangeSet_isNotPendingOrDeleted = function _ChangeSet_isNotPendingOrDeleted(change) {
|
|
331
|
+
return (change.dataTracked.operation !== exports.CHANGE_OPERATION.delete &&
|
|
332
|
+
change.dataTracked.status !== exports.CHANGE_STATUS.pending);
|
|
333
|
+
};
|
|
324
334
|
|
|
325
335
|
/*!
|
|
326
336
|
* © 2021 Atypon Systems LLC
|
|
@@ -1137,7 +1147,7 @@ function deleteAndMergeSplitNodes(from, to, gap, startDoc, newTr, schema, trackA
|
|
|
1137
1147
|
* See the License for the specific language governing permissions and
|
|
1138
1148
|
* limitations under the License.
|
|
1139
1149
|
*/
|
|
1140
|
-
function trackReplaceAroundStep(step, oldState, newTr, attrs) {
|
|
1150
|
+
function trackReplaceAroundStep(step, oldState, tr, newTr, attrs) {
|
|
1141
1151
|
log.info('###### ReplaceAroundStep ######');
|
|
1142
1152
|
// @ts-ignore
|
|
1143
1153
|
const { from, to, gapFrom, gapTo, insert, slice, structure, } = step;
|
|
@@ -1158,14 +1168,18 @@ function trackReplaceAroundStep(step, oldState, newTr, attrs) {
|
|
|
1158
1168
|
log.info('DELETE STEPS: ', deleteSteps);
|
|
1159
1169
|
// We only want to insert when there something inside the gap (actually would this be always true?)
|
|
1160
1170
|
// or insert slice wasn't just start/end tokens (which we already merged inside deleteAndMergeSplitBlockNodes)
|
|
1161
|
-
|
|
1171
|
+
// ^^answering above comment we could have meta node like(bibliography_item, contributor) will not have content at all,
|
|
1172
|
+
// and that case gap will be 0, for that will use updateMetaNode to indicate that we are going just to update that node
|
|
1173
|
+
if (gap.size > 0 ||
|
|
1174
|
+
(!structure && newSliceContent.size > 0) ||
|
|
1175
|
+
tr.getMeta(TrackChangesAction.updateMetaNode)) {
|
|
1162
1176
|
log.info('newSliceContent', newSliceContent);
|
|
1163
1177
|
// Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
|
|
1164
1178
|
// the sides should be equal. TODO can they be other than 0?
|
|
1165
1179
|
const openStart = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openStart;
|
|
1166
1180
|
const openEnd = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openEnd;
|
|
1167
1181
|
let insertedSlice = new prosemirrorModel.Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd);
|
|
1168
|
-
if (gap.size > 0) {
|
|
1182
|
+
if (gap.size > 0 || tr.getMeta(TrackChangesAction.updateMetaNode)) {
|
|
1169
1183
|
log.info('insertedSlice before inserted gap', insertedSlice);
|
|
1170
1184
|
insertedSlice = insertedSlice.insertAt(insertedSlice.size === 0 ? 0 : insert, gap.content);
|
|
1171
1185
|
log.info('insertedSlice after inserted gap', insertedSlice);
|
|
@@ -1432,8 +1446,11 @@ function processChangeSteps(changes, startPos, newTr, emptyAttrs, schema) {
|
|
|
1432
1446
|
}
|
|
1433
1447
|
: addTrackIdIfDoesntExist(createNewUpdateAttrs(emptyAttrs, c.node.attrs));
|
|
1434
1448
|
// Dont add update changes if there exists already an insert change for this node
|
|
1435
|
-
if (JSON.stringify(oldAttrs) !== JSON.stringify(c.newAttrs)
|
|
1436
|
-
|
|
1449
|
+
if ((JSON.stringify(oldAttrs) !== JSON.stringify(c.newAttrs) ||
|
|
1450
|
+
c.node.type === c.node.type.schema.nodes.citation) &&
|
|
1451
|
+
!oldDataTracked.find((d) => (d.operation === exports.CHANGE_OPERATION.insert ||
|
|
1452
|
+
d.operation === exports.CHANGE_OPERATION.set_node_attributes) &&
|
|
1453
|
+
d.status === exports.CHANGE_STATUS.pending)) {
|
|
1437
1454
|
newDataTracked.push(newUpdate);
|
|
1438
1455
|
}
|
|
1439
1456
|
newTr.setNodeMarkup(mapping.map(c.pos), undefined, {
|
|
@@ -1724,7 +1741,7 @@ function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
1724
1741
|
}
|
|
1725
1742
|
}
|
|
1726
1743
|
else if (step instanceof prosemirrorTransform.ReplaceAroundStep) {
|
|
1727
|
-
let steps = trackReplaceAroundStep(step, oldState, newTr, emptyAttrs);
|
|
1744
|
+
let steps = trackReplaceAroundStep(step, oldState, tr, newTr, emptyAttrs);
|
|
1728
1745
|
const deleted = steps.filter((s) => s.type !== 'insert-slice');
|
|
1729
1746
|
const inserted = steps.filter((s) => s.type === 'insert-slice');
|
|
1730
1747
|
log.info('INSERT STEPS: ', inserted);
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ var TrackChangesAction;
|
|
|
11
11
|
TrackChangesAction["setChangeStatuses"] = "track-changes-set-change-statuses";
|
|
12
12
|
TrackChangesAction["refreshChanges"] = "track-changes-refresh-changes";
|
|
13
13
|
TrackChangesAction["applyAndRemoveChanges"] = "track-changes-apply-remove-changes";
|
|
14
|
+
TrackChangesAction["updateMetaNode"] = "track-changes-update-meta-node";
|
|
14
15
|
})(TrackChangesAction || (TrackChangesAction = {}));
|
|
15
16
|
/**
|
|
16
17
|
* Gets the value of a meta field, action payload, of a defined track-changes action.
|
|
@@ -153,13 +154,14 @@ const enableDebug = (enabled) => {
|
|
|
153
154
|
}
|
|
154
155
|
};
|
|
155
156
|
|
|
156
|
-
var _ChangeSet_changes;
|
|
157
|
+
var _ChangeSet_instances, _ChangeSet_changes, _ChangeSet_isSameNodeChange, _ChangeSet_isNotPendingOrDeleted;
|
|
157
158
|
/**
|
|
158
159
|
* ChangeSet is a data structure to contain the tracked changes with some utility methods and computed
|
|
159
160
|
* values to allow easier operability.
|
|
160
161
|
*/
|
|
161
162
|
class ChangeSet {
|
|
162
163
|
constructor(changes = []) {
|
|
164
|
+
_ChangeSet_instances.add(this);
|
|
163
165
|
_ChangeSet_changes.set(this, void 0);
|
|
164
166
|
__classPrivateFieldSet(this, _ChangeSet_changes, changes, "f");
|
|
165
167
|
}
|
|
@@ -190,7 +192,10 @@ class ChangeSet {
|
|
|
190
192
|
rootNodes.push(currentNodeChange);
|
|
191
193
|
currentNodeChange = undefined;
|
|
192
194
|
}
|
|
193
|
-
if (currentNodeChange &&
|
|
195
|
+
if (currentNodeChange &&
|
|
196
|
+
c.from < currentNodeChange.to &&
|
|
197
|
+
!(__classPrivateFieldGet(this, _ChangeSet_instances, "m", _ChangeSet_isSameNodeChange).call(this, currentNodeChange, c) &&
|
|
198
|
+
__classPrivateFieldGet(this, _ChangeSet_instances, "m", _ChangeSet_isNotPendingOrDeleted).call(this, currentNodeChange))) {
|
|
194
199
|
currentNodeChange.children.push(c);
|
|
195
200
|
}
|
|
196
201
|
else if (c.type === 'node-change') {
|
|
@@ -312,7 +317,12 @@ class ChangeSet {
|
|
|
312
317
|
return change.type === 'node-attr-change';
|
|
313
318
|
}
|
|
314
319
|
}
|
|
315
|
-
_ChangeSet_changes = new WeakMap()
|
|
320
|
+
_ChangeSet_changes = new WeakMap(), _ChangeSet_instances = new WeakSet(), _ChangeSet_isSameNodeChange = function _ChangeSet_isSameNodeChange(currentChange, nextChange) {
|
|
321
|
+
return currentChange.from === nextChange.from && currentChange.to === nextChange.to;
|
|
322
|
+
}, _ChangeSet_isNotPendingOrDeleted = function _ChangeSet_isNotPendingOrDeleted(change) {
|
|
323
|
+
return (change.dataTracked.operation !== CHANGE_OPERATION.delete &&
|
|
324
|
+
change.dataTracked.status !== CHANGE_STATUS.pending);
|
|
325
|
+
};
|
|
316
326
|
|
|
317
327
|
/*!
|
|
318
328
|
* © 2021 Atypon Systems LLC
|
|
@@ -1129,7 +1139,7 @@ function deleteAndMergeSplitNodes(from, to, gap, startDoc, newTr, schema, trackA
|
|
|
1129
1139
|
* See the License for the specific language governing permissions and
|
|
1130
1140
|
* limitations under the License.
|
|
1131
1141
|
*/
|
|
1132
|
-
function trackReplaceAroundStep(step, oldState, newTr, attrs) {
|
|
1142
|
+
function trackReplaceAroundStep(step, oldState, tr, newTr, attrs) {
|
|
1133
1143
|
log.info('###### ReplaceAroundStep ######');
|
|
1134
1144
|
// @ts-ignore
|
|
1135
1145
|
const { from, to, gapFrom, gapTo, insert, slice, structure, } = step;
|
|
@@ -1150,14 +1160,18 @@ function trackReplaceAroundStep(step, oldState, newTr, attrs) {
|
|
|
1150
1160
|
log.info('DELETE STEPS: ', deleteSteps);
|
|
1151
1161
|
// We only want to insert when there something inside the gap (actually would this be always true?)
|
|
1152
1162
|
// or insert slice wasn't just start/end tokens (which we already merged inside deleteAndMergeSplitBlockNodes)
|
|
1153
|
-
|
|
1163
|
+
// ^^answering above comment we could have meta node like(bibliography_item, contributor) will not have content at all,
|
|
1164
|
+
// and that case gap will be 0, for that will use updateMetaNode to indicate that we are going just to update that node
|
|
1165
|
+
if (gap.size > 0 ||
|
|
1166
|
+
(!structure && newSliceContent.size > 0) ||
|
|
1167
|
+
tr.getMeta(TrackChangesAction.updateMetaNode)) {
|
|
1154
1168
|
log.info('newSliceContent', newSliceContent);
|
|
1155
1169
|
// Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
|
|
1156
1170
|
// the sides should be equal. TODO can they be other than 0?
|
|
1157
1171
|
const openStart = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openStart;
|
|
1158
1172
|
const openEnd = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openEnd;
|
|
1159
1173
|
let insertedSlice = new Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd);
|
|
1160
|
-
if (gap.size > 0) {
|
|
1174
|
+
if (gap.size > 0 || tr.getMeta(TrackChangesAction.updateMetaNode)) {
|
|
1161
1175
|
log.info('insertedSlice before inserted gap', insertedSlice);
|
|
1162
1176
|
insertedSlice = insertedSlice.insertAt(insertedSlice.size === 0 ? 0 : insert, gap.content);
|
|
1163
1177
|
log.info('insertedSlice after inserted gap', insertedSlice);
|
|
@@ -1424,8 +1438,11 @@ function processChangeSteps(changes, startPos, newTr, emptyAttrs, schema) {
|
|
|
1424
1438
|
}
|
|
1425
1439
|
: addTrackIdIfDoesntExist(createNewUpdateAttrs(emptyAttrs, c.node.attrs));
|
|
1426
1440
|
// Dont add update changes if there exists already an insert change for this node
|
|
1427
|
-
if (JSON.stringify(oldAttrs) !== JSON.stringify(c.newAttrs)
|
|
1428
|
-
|
|
1441
|
+
if ((JSON.stringify(oldAttrs) !== JSON.stringify(c.newAttrs) ||
|
|
1442
|
+
c.node.type === c.node.type.schema.nodes.citation) &&
|
|
1443
|
+
!oldDataTracked.find((d) => (d.operation === CHANGE_OPERATION.insert ||
|
|
1444
|
+
d.operation === CHANGE_OPERATION.set_node_attributes) &&
|
|
1445
|
+
d.status === CHANGE_STATUS.pending)) {
|
|
1429
1446
|
newDataTracked.push(newUpdate);
|
|
1430
1447
|
}
|
|
1431
1448
|
newTr.setNodeMarkup(mapping.map(c.pos), undefined, {
|
|
@@ -1716,7 +1733,7 @@ function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
1716
1733
|
}
|
|
1717
1734
|
}
|
|
1718
1735
|
else if (step instanceof ReplaceAroundStep) {
|
|
1719
|
-
let steps = trackReplaceAroundStep(step, oldState, newTr, emptyAttrs);
|
|
1736
|
+
let steps = trackReplaceAroundStep(step, oldState, tr, newTr, emptyAttrs);
|
|
1720
1737
|
const deleted = steps.filter((s) => s.type !== 'insert-slice');
|
|
1721
1738
|
const inserted = steps.filter((s) => s.type === 'insert-slice');
|
|
1722
1739
|
log.info('INSERT STEPS: ', inserted);
|
|
@@ -2,4 +2,4 @@ import type { EditorState, Transaction } from 'prosemirror-state';
|
|
|
2
2
|
import { ReplaceAroundStep } from 'prosemirror-transform';
|
|
3
3
|
import { NewEmptyAttrs } from '../types/track';
|
|
4
4
|
import { ChangeStep } from '../types/step';
|
|
5
|
-
export declare function trackReplaceAroundStep(step: ReplaceAroundStep, oldState: EditorState, newTr: Transaction, attrs: NewEmptyAttrs): ChangeStep[];
|
|
5
|
+
export declare function trackReplaceAroundStep(step: ReplaceAroundStep, oldState: EditorState, tr: Transaction, newTr: Transaction, attrs: NewEmptyAttrs): ChangeStep[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/track-changes-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0-LEAN-2850",
|
|
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",
|