@manuscripts/track-changes-plugin 1.3.1 → 1.4.1-LEAN-2431
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/index.cjs +43 -6
- package/dist/index.js +43 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1213,17 +1213,49 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
|
|
|
1213
1213
|
changeSteps.push(...deleteSteps);
|
|
1214
1214
|
log.info('TR: steps after applying delete', [...newTr.steps]);
|
|
1215
1215
|
log.info('DELETE STEPS: ', changeSteps);
|
|
1216
|
-
|
|
1217
|
-
|
|
1216
|
+
// console.log('CHANGE STEPS AT THIS POINT:')
|
|
1217
|
+
// console.log(JSON.parse(JSON.stringify(changeSteps)))
|
|
1218
|
+
function sameThingBackSpaced() {
|
|
1219
|
+
/*
|
|
1220
|
+
When deleting text with backspace and getting to the point of when a space and a character before the space is deleted
|
|
1221
|
+
the prosemirror would interpret it as moving the <del> node (this is a tracked deletion) one characted behind.
|
|
1222
|
+
It normally results in [delete, delete, insert] set of ChangSteps where 1st delete is for the delete done by
|
|
1223
|
+
the backspace key, the second delete and the insert are a misinterpretation of the moved text. So these last 2 steps have to be caught
|
|
1224
|
+
and removed as they are not meaningful.
|
|
1225
|
+
*/
|
|
1226
|
+
if (changeSteps.length == 2 && newSliceContent.size > 0) {
|
|
1227
|
+
// or jus thangeSteps.length == 2
|
|
1228
|
+
const correspondingDeletion = changeSteps.find(
|
|
1229
|
+
// @ts-ignore
|
|
1230
|
+
(step) => step.node.text === newSliceContent.content[0].text // @TODO - get more precise proof of match. E.g.: position approximation
|
|
1231
|
+
);
|
|
1232
|
+
return correspondingDeletion;
|
|
1233
|
+
}
|
|
1234
|
+
return undefined;
|
|
1235
|
+
}
|
|
1236
|
+
const backSpacedText = sameThingBackSpaced();
|
|
1237
|
+
if (backSpacedText) {
|
|
1238
|
+
changeSteps.splice(changeSteps.indexOf(backSpacedText));
|
|
1239
|
+
}
|
|
1240
|
+
const textWasDeleted = !!changeSteps.length;
|
|
1241
|
+
if (!backSpacedText && newSliceContent.size > 0) {
|
|
1218
1242
|
log.info('newSliceContent', newSliceContent);
|
|
1243
|
+
//
|
|
1244
|
+
// console.log('Sliced Content:')
|
|
1245
|
+
// console.log(newSliceContent)
|
|
1219
1246
|
// Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
|
|
1220
1247
|
// the sides should be equal. TODO can they be other than 0?
|
|
1248
|
+
// the sides should be equal. TODO can they be other than 0?
|
|
1249
|
+
//
|
|
1221
1250
|
const openStart = slice.openStart !== slice.openEnd ? 0 : slice.openStart;
|
|
1222
1251
|
const openEnd = slice.openStart !== slice.openEnd ? 0 : slice.openEnd;
|
|
1223
1252
|
changeSteps.push({
|
|
1224
1253
|
type: 'insert-slice',
|
|
1225
|
-
from:
|
|
1226
|
-
to:
|
|
1254
|
+
from: textWasDeleted ? fromB : toA,
|
|
1255
|
+
to: textWasDeleted ? toB - 1 : toA,
|
|
1256
|
+
/* it's not entirely clear why using "fromB" is needed at all but in cases where there areno content deleted before
|
|
1257
|
+
- it will gointo infinite loop if toB -1 is used
|
|
1258
|
+
*/
|
|
1227
1259
|
sliceWasSplit,
|
|
1228
1260
|
slice: new prosemirrorModel.Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd),
|
|
1229
1261
|
});
|
|
@@ -1388,7 +1420,8 @@ function processChangeSteps(changes, startPos, newTr, emptyAttrs, schema) {
|
|
|
1388
1420
|
return;
|
|
1389
1421
|
}
|
|
1390
1422
|
mergeTrackedMarks(mapping.map(c.from), newTr.doc, newTr, schema);
|
|
1391
|
-
|
|
1423
|
+
const to = mapping.map(c.to) + c.slice.size;
|
|
1424
|
+
mergeTrackedMarks(mapping.map(c.to) + (to < newTr.doc.nodeSize ? c.slice.size : 0), newTr.doc, newTr, schema);
|
|
1392
1425
|
selectionPos = mapping.map(c.to) + c.slice.size;
|
|
1393
1426
|
}
|
|
1394
1427
|
else if (c.type === 'update-node-attrs') {
|
|
@@ -1828,7 +1861,11 @@ const trackChangesPlugin = (opts = { userID: 'anonymous:Anonymous' }) => {
|
|
|
1828
1861
|
const skipMetaUsed = skipTrsWithMetas.some((m) => tr.getMeta(m) || (wasAppended === null || wasAppended === void 0 ? void 0 : wasAppended.getMeta(m)));
|
|
1829
1862
|
const skipTrackUsed = getAction(tr, TrackChangesAction.skipTrack) ||
|
|
1830
1863
|
(wasAppended && getAction(wasAppended, TrackChangesAction.skipTrack));
|
|
1831
|
-
if (tr.docChanged &&
|
|
1864
|
+
if (tr.docChanged &&
|
|
1865
|
+
!skipMetaUsed &&
|
|
1866
|
+
!skipTrackUsed &&
|
|
1867
|
+
!tr.getMeta('history$') &&
|
|
1868
|
+
!(wasAppended && tr.getMeta('origin') === 'paragraphs')) {
|
|
1832
1869
|
createdTr = trackTransaction(tr, oldState, createdTr, userID);
|
|
1833
1870
|
}
|
|
1834
1871
|
docChanged = docChanged || tr.docChanged;
|
package/dist/index.js
CHANGED
|
@@ -1205,17 +1205,49 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
|
|
|
1205
1205
|
changeSteps.push(...deleteSteps);
|
|
1206
1206
|
log.info('TR: steps after applying delete', [...newTr.steps]);
|
|
1207
1207
|
log.info('DELETE STEPS: ', changeSteps);
|
|
1208
|
-
|
|
1209
|
-
|
|
1208
|
+
// console.log('CHANGE STEPS AT THIS POINT:')
|
|
1209
|
+
// console.log(JSON.parse(JSON.stringify(changeSteps)))
|
|
1210
|
+
function sameThingBackSpaced() {
|
|
1211
|
+
/*
|
|
1212
|
+
When deleting text with backspace and getting to the point of when a space and a character before the space is deleted
|
|
1213
|
+
the prosemirror would interpret it as moving the <del> node (this is a tracked deletion) one characted behind.
|
|
1214
|
+
It normally results in [delete, delete, insert] set of ChangSteps where 1st delete is for the delete done by
|
|
1215
|
+
the backspace key, the second delete and the insert are a misinterpretation of the moved text. So these last 2 steps have to be caught
|
|
1216
|
+
and removed as they are not meaningful.
|
|
1217
|
+
*/
|
|
1218
|
+
if (changeSteps.length == 2 && newSliceContent.size > 0) {
|
|
1219
|
+
// or jus thangeSteps.length == 2
|
|
1220
|
+
const correspondingDeletion = changeSteps.find(
|
|
1221
|
+
// @ts-ignore
|
|
1222
|
+
(step) => step.node.text === newSliceContent.content[0].text // @TODO - get more precise proof of match. E.g.: position approximation
|
|
1223
|
+
);
|
|
1224
|
+
return correspondingDeletion;
|
|
1225
|
+
}
|
|
1226
|
+
return undefined;
|
|
1227
|
+
}
|
|
1228
|
+
const backSpacedText = sameThingBackSpaced();
|
|
1229
|
+
if (backSpacedText) {
|
|
1230
|
+
changeSteps.splice(changeSteps.indexOf(backSpacedText));
|
|
1231
|
+
}
|
|
1232
|
+
const textWasDeleted = !!changeSteps.length;
|
|
1233
|
+
if (!backSpacedText && newSliceContent.size > 0) {
|
|
1210
1234
|
log.info('newSliceContent', newSliceContent);
|
|
1235
|
+
//
|
|
1236
|
+
// console.log('Sliced Content:')
|
|
1237
|
+
// console.log(newSliceContent)
|
|
1211
1238
|
// Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
|
|
1212
1239
|
// the sides should be equal. TODO can they be other than 0?
|
|
1240
|
+
// the sides should be equal. TODO can they be other than 0?
|
|
1241
|
+
//
|
|
1213
1242
|
const openStart = slice.openStart !== slice.openEnd ? 0 : slice.openStart;
|
|
1214
1243
|
const openEnd = slice.openStart !== slice.openEnd ? 0 : slice.openEnd;
|
|
1215
1244
|
changeSteps.push({
|
|
1216
1245
|
type: 'insert-slice',
|
|
1217
|
-
from:
|
|
1218
|
-
to:
|
|
1246
|
+
from: textWasDeleted ? fromB : toA,
|
|
1247
|
+
to: textWasDeleted ? toB - 1 : toA,
|
|
1248
|
+
/* it's not entirely clear why using "fromB" is needed at all but in cases where there areno content deleted before
|
|
1249
|
+
- it will gointo infinite loop if toB -1 is used
|
|
1250
|
+
*/
|
|
1219
1251
|
sliceWasSplit,
|
|
1220
1252
|
slice: new Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd),
|
|
1221
1253
|
});
|
|
@@ -1380,7 +1412,8 @@ function processChangeSteps(changes, startPos, newTr, emptyAttrs, schema) {
|
|
|
1380
1412
|
return;
|
|
1381
1413
|
}
|
|
1382
1414
|
mergeTrackedMarks(mapping.map(c.from), newTr.doc, newTr, schema);
|
|
1383
|
-
|
|
1415
|
+
const to = mapping.map(c.to) + c.slice.size;
|
|
1416
|
+
mergeTrackedMarks(mapping.map(c.to) + (to < newTr.doc.nodeSize ? c.slice.size : 0), newTr.doc, newTr, schema);
|
|
1384
1417
|
selectionPos = mapping.map(c.to) + c.slice.size;
|
|
1385
1418
|
}
|
|
1386
1419
|
else if (c.type === 'update-node-attrs') {
|
|
@@ -1820,7 +1853,11 @@ const trackChangesPlugin = (opts = { userID: 'anonymous:Anonymous' }) => {
|
|
|
1820
1853
|
const skipMetaUsed = skipTrsWithMetas.some((m) => tr.getMeta(m) || (wasAppended === null || wasAppended === void 0 ? void 0 : wasAppended.getMeta(m)));
|
|
1821
1854
|
const skipTrackUsed = getAction(tr, TrackChangesAction.skipTrack) ||
|
|
1822
1855
|
(wasAppended && getAction(wasAppended, TrackChangesAction.skipTrack));
|
|
1823
|
-
if (tr.docChanged &&
|
|
1856
|
+
if (tr.docChanged &&
|
|
1857
|
+
!skipMetaUsed &&
|
|
1858
|
+
!skipTrackUsed &&
|
|
1859
|
+
!tr.getMeta('history$') &&
|
|
1860
|
+
!(wasAppended && tr.getMeta('origin') === 'paragraphs')) {
|
|
1824
1861
|
createdTr = trackTransaction(tr, oldState, createdTr, userID);
|
|
1825
1862
|
}
|
|
1826
1863
|
docChanged = docChanged || tr.docChanged;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/track-changes-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1-LEAN-2431",
|
|
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",
|