@manuscripts/track-changes-plugin 1.6.1-LEAN-2850-v4 → 1.7.0
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 +13 -17
- package/dist/index.js +13 -17
- 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,14 +162,13 @@ const enableDebug = (enabled) => {
|
|
|
161
162
|
}
|
|
162
163
|
};
|
|
163
164
|
|
|
164
|
-
var
|
|
165
|
+
var _ChangeSet_changes;
|
|
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 = []) {
|
|
171
|
-
_ChangeSet_instances.add(this);
|
|
172
172
|
_ChangeSet_changes.set(this, void 0);
|
|
173
173
|
__classPrivateFieldSet(this, _ChangeSet_changes, changes, "f");
|
|
174
174
|
}
|
|
@@ -199,10 +199,7 @@ class ChangeSet {
|
|
|
199
199
|
rootNodes.push(currentNodeChange);
|
|
200
200
|
currentNodeChange = undefined;
|
|
201
201
|
}
|
|
202
|
-
if (currentNodeChange &&
|
|
203
|
-
c.from < currentNodeChange.to &&
|
|
204
|
-
!(__classPrivateFieldGet(this, _ChangeSet_instances, "m", _ChangeSet_isSameNodeChange).call(this, currentNodeChange, c) &&
|
|
205
|
-
__classPrivateFieldGet(this, _ChangeSet_instances, "m", _ChangeSet_isNotPendingOrDeleted).call(this, currentNodeChange))) {
|
|
202
|
+
if (currentNodeChange && c.from < currentNodeChange.to) {
|
|
206
203
|
currentNodeChange.children.push(c);
|
|
207
204
|
}
|
|
208
205
|
else if (c.type === 'node-change') {
|
|
@@ -324,12 +321,7 @@ class ChangeSet {
|
|
|
324
321
|
return change.type === 'node-attr-change';
|
|
325
322
|
}
|
|
326
323
|
}
|
|
327
|
-
_ChangeSet_changes = new WeakMap()
|
|
328
|
-
return currentChange.from === nextChange.from && currentChange.to === nextChange.to;
|
|
329
|
-
}, _ChangeSet_isNotPendingOrDeleted = function _ChangeSet_isNotPendingOrDeleted(change) {
|
|
330
|
-
return (change.dataTracked.operation !== exports.CHANGE_OPERATION.delete &&
|
|
331
|
-
change.dataTracked.status !== exports.CHANGE_STATUS.pending);
|
|
332
|
-
};
|
|
324
|
+
_ChangeSet_changes = new WeakMap();
|
|
333
325
|
|
|
334
326
|
/*!
|
|
335
327
|
* © 2021 Atypon Systems LLC
|
|
@@ -1146,7 +1138,7 @@ function deleteAndMergeSplitNodes(from, to, gap, startDoc, newTr, schema, trackA
|
|
|
1146
1138
|
* See the License for the specific language governing permissions and
|
|
1147
1139
|
* limitations under the License.
|
|
1148
1140
|
*/
|
|
1149
|
-
function trackReplaceAroundStep(step, oldState, newTr, attrs) {
|
|
1141
|
+
function trackReplaceAroundStep(step, oldState, tr, newTr, attrs) {
|
|
1150
1142
|
log.info('###### ReplaceAroundStep ######');
|
|
1151
1143
|
// @ts-ignore
|
|
1152
1144
|
const { from, to, gapFrom, gapTo, insert, slice, structure, } = step;
|
|
@@ -1167,14 +1159,18 @@ function trackReplaceAroundStep(step, oldState, newTr, attrs) {
|
|
|
1167
1159
|
log.info('DELETE STEPS: ', deleteSteps);
|
|
1168
1160
|
// We only want to insert when there something inside the gap (actually would this be always true?)
|
|
1169
1161
|
// or insert slice wasn't just start/end tokens (which we already merged inside deleteAndMergeSplitBlockNodes)
|
|
1170
|
-
|
|
1162
|
+
// ^^answering above comment we could have meta node like(bibliography_item, contributor) will not have content at all,
|
|
1163
|
+
// and that case gap will be 0, for that will use updateMetaNode to indicate that we are going just to update that node
|
|
1164
|
+
if (gap.size > 0 ||
|
|
1165
|
+
(!structure && newSliceContent.size > 0) ||
|
|
1166
|
+
tr.getMeta(TrackChangesAction.updateMetaNode)) {
|
|
1171
1167
|
log.info('newSliceContent', newSliceContent);
|
|
1172
1168
|
// Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
|
|
1173
1169
|
// the sides should be equal. TODO can they be other than 0?
|
|
1174
1170
|
const openStart = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openStart;
|
|
1175
1171
|
const openEnd = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openEnd;
|
|
1176
1172
|
let insertedSlice = new prosemirrorModel.Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd);
|
|
1177
|
-
if (gap.size > 0) {
|
|
1173
|
+
if (gap.size > 0 || tr.getMeta(TrackChangesAction.updateMetaNode)) {
|
|
1178
1174
|
log.info('insertedSlice before inserted gap', insertedSlice);
|
|
1179
1175
|
insertedSlice = insertedSlice.insertAt(insertedSlice.size === 0 ? 0 : insert, gap.content);
|
|
1180
1176
|
log.info('insertedSlice after inserted gap', insertedSlice);
|
|
@@ -1442,7 +1438,7 @@ function processChangeSteps(changes, startPos, newTr, emptyAttrs, schema) {
|
|
|
1442
1438
|
: addTrackIdIfDoesntExist(createNewUpdateAttrs(emptyAttrs, c.node.attrs));
|
|
1443
1439
|
// Dont add update changes if there exists already an insert change for this node
|
|
1444
1440
|
if (JSON.stringify(oldAttrs) !== JSON.stringify(c.newAttrs) &&
|
|
1445
|
-
!oldDataTracked.find((d) => d.operation === exports.CHANGE_OPERATION.insert
|
|
1441
|
+
!oldDataTracked.find((d) => d.operation === exports.CHANGE_OPERATION.insert)) {
|
|
1446
1442
|
newDataTracked.push(newUpdate);
|
|
1447
1443
|
}
|
|
1448
1444
|
newTr.setNodeMarkup(mapping.map(c.pos), undefined, {
|
|
@@ -1733,7 +1729,7 @@ function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
1733
1729
|
}
|
|
1734
1730
|
}
|
|
1735
1731
|
else if (step instanceof prosemirrorTransform.ReplaceAroundStep) {
|
|
1736
|
-
let steps = trackReplaceAroundStep(step, oldState, newTr, emptyAttrs);
|
|
1732
|
+
let steps = trackReplaceAroundStep(step, oldState, tr, newTr, emptyAttrs);
|
|
1737
1733
|
const deleted = steps.filter((s) => s.type !== 'insert-slice');
|
|
1738
1734
|
const inserted = steps.filter((s) => s.type === 'insert-slice');
|
|
1739
1735
|
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,14 +154,13 @@ const enableDebug = (enabled) => {
|
|
|
153
154
|
}
|
|
154
155
|
};
|
|
155
156
|
|
|
156
|
-
var
|
|
157
|
+
var _ChangeSet_changes;
|
|
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 = []) {
|
|
163
|
-
_ChangeSet_instances.add(this);
|
|
164
164
|
_ChangeSet_changes.set(this, void 0);
|
|
165
165
|
__classPrivateFieldSet(this, _ChangeSet_changes, changes, "f");
|
|
166
166
|
}
|
|
@@ -191,10 +191,7 @@ class ChangeSet {
|
|
|
191
191
|
rootNodes.push(currentNodeChange);
|
|
192
192
|
currentNodeChange = undefined;
|
|
193
193
|
}
|
|
194
|
-
if (currentNodeChange &&
|
|
195
|
-
c.from < currentNodeChange.to &&
|
|
196
|
-
!(__classPrivateFieldGet(this, _ChangeSet_instances, "m", _ChangeSet_isSameNodeChange).call(this, currentNodeChange, c) &&
|
|
197
|
-
__classPrivateFieldGet(this, _ChangeSet_instances, "m", _ChangeSet_isNotPendingOrDeleted).call(this, currentNodeChange))) {
|
|
194
|
+
if (currentNodeChange && c.from < currentNodeChange.to) {
|
|
198
195
|
currentNodeChange.children.push(c);
|
|
199
196
|
}
|
|
200
197
|
else if (c.type === 'node-change') {
|
|
@@ -316,12 +313,7 @@ class ChangeSet {
|
|
|
316
313
|
return change.type === 'node-attr-change';
|
|
317
314
|
}
|
|
318
315
|
}
|
|
319
|
-
_ChangeSet_changes = new WeakMap()
|
|
320
|
-
return currentChange.from === nextChange.from && currentChange.to === nextChange.to;
|
|
321
|
-
}, _ChangeSet_isNotPendingOrDeleted = function _ChangeSet_isNotPendingOrDeleted(change) {
|
|
322
|
-
return (change.dataTracked.operation !== CHANGE_OPERATION.delete &&
|
|
323
|
-
change.dataTracked.status !== CHANGE_STATUS.pending);
|
|
324
|
-
};
|
|
316
|
+
_ChangeSet_changes = new WeakMap();
|
|
325
317
|
|
|
326
318
|
/*!
|
|
327
319
|
* © 2021 Atypon Systems LLC
|
|
@@ -1138,7 +1130,7 @@ function deleteAndMergeSplitNodes(from, to, gap, startDoc, newTr, schema, trackA
|
|
|
1138
1130
|
* See the License for the specific language governing permissions and
|
|
1139
1131
|
* limitations under the License.
|
|
1140
1132
|
*/
|
|
1141
|
-
function trackReplaceAroundStep(step, oldState, newTr, attrs) {
|
|
1133
|
+
function trackReplaceAroundStep(step, oldState, tr, newTr, attrs) {
|
|
1142
1134
|
log.info('###### ReplaceAroundStep ######');
|
|
1143
1135
|
// @ts-ignore
|
|
1144
1136
|
const { from, to, gapFrom, gapTo, insert, slice, structure, } = step;
|
|
@@ -1159,14 +1151,18 @@ function trackReplaceAroundStep(step, oldState, newTr, attrs) {
|
|
|
1159
1151
|
log.info('DELETE STEPS: ', deleteSteps);
|
|
1160
1152
|
// We only want to insert when there something inside the gap (actually would this be always true?)
|
|
1161
1153
|
// or insert slice wasn't just start/end tokens (which we already merged inside deleteAndMergeSplitBlockNodes)
|
|
1162
|
-
|
|
1154
|
+
// ^^answering above comment we could have meta node like(bibliography_item, contributor) will not have content at all,
|
|
1155
|
+
// and that case gap will be 0, for that will use updateMetaNode to indicate that we are going just to update that node
|
|
1156
|
+
if (gap.size > 0 ||
|
|
1157
|
+
(!structure && newSliceContent.size > 0) ||
|
|
1158
|
+
tr.getMeta(TrackChangesAction.updateMetaNode)) {
|
|
1163
1159
|
log.info('newSliceContent', newSliceContent);
|
|
1164
1160
|
// Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
|
|
1165
1161
|
// the sides should be equal. TODO can they be other than 0?
|
|
1166
1162
|
const openStart = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openStart;
|
|
1167
1163
|
const openEnd = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openEnd;
|
|
1168
1164
|
let insertedSlice = new Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd);
|
|
1169
|
-
if (gap.size > 0) {
|
|
1165
|
+
if (gap.size > 0 || tr.getMeta(TrackChangesAction.updateMetaNode)) {
|
|
1170
1166
|
log.info('insertedSlice before inserted gap', insertedSlice);
|
|
1171
1167
|
insertedSlice = insertedSlice.insertAt(insertedSlice.size === 0 ? 0 : insert, gap.content);
|
|
1172
1168
|
log.info('insertedSlice after inserted gap', insertedSlice);
|
|
@@ -1434,7 +1430,7 @@ function processChangeSteps(changes, startPos, newTr, emptyAttrs, schema) {
|
|
|
1434
1430
|
: addTrackIdIfDoesntExist(createNewUpdateAttrs(emptyAttrs, c.node.attrs));
|
|
1435
1431
|
// Dont add update changes if there exists already an insert change for this node
|
|
1436
1432
|
if (JSON.stringify(oldAttrs) !== JSON.stringify(c.newAttrs) &&
|
|
1437
|
-
!oldDataTracked.find((d) => d.operation === CHANGE_OPERATION.insert
|
|
1433
|
+
!oldDataTracked.find((d) => d.operation === CHANGE_OPERATION.insert)) {
|
|
1438
1434
|
newDataTracked.push(newUpdate);
|
|
1439
1435
|
}
|
|
1440
1436
|
newTr.setNodeMarkup(mapping.map(c.pos), undefined, {
|
|
@@ -1725,7 +1721,7 @@ function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
1725
1721
|
}
|
|
1726
1722
|
}
|
|
1727
1723
|
else if (step instanceof ReplaceAroundStep) {
|
|
1728
|
-
let steps = trackReplaceAroundStep(step, oldState, newTr, emptyAttrs);
|
|
1724
|
+
let steps = trackReplaceAroundStep(step, oldState, tr, newTr, emptyAttrs);
|
|
1729
1725
|
const deleted = steps.filter((s) => s.type !== 'insert-slice');
|
|
1730
1726
|
const inserted = steps.filter((s) => s.type === 'insert-slice');
|
|
1731
1727
|
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",
|
|
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",
|