@manuscripts/track-changes-plugin 1.5.2 → 1.6.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/index.cjs +10 -8
- package/dist/index.js +10 -8
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -448,7 +448,8 @@ function deleteNode(node, pos, tr) {
|
|
|
448
448
|
const resPos = tr.doc.resolve(pos);
|
|
449
449
|
// Block nodes can be deleted by just removing their start token which should then merge the text
|
|
450
450
|
// content to above node's content (if there is one)
|
|
451
|
-
|
|
451
|
+
// this will work just for the node after the first child
|
|
452
|
+
const canMergeToNodeAbove = resPos.parent !== tr.doc && resPos.nodeBefore && node.isBlock && ((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.isText);
|
|
452
453
|
if (canMergeToNodeAbove) {
|
|
453
454
|
return tr.replaceWith(pos - 1, pos + 1, prosemirrorModel.Fragment.empty);
|
|
454
455
|
}
|
|
@@ -509,9 +510,9 @@ function mergeNode(node, pos, tr) {
|
|
|
509
510
|
if (prosemirrorTransform.canJoin(tr.doc, pos)) {
|
|
510
511
|
return tr.join(pos);
|
|
511
512
|
}
|
|
512
|
-
else if (
|
|
513
|
-
//
|
|
514
|
-
return
|
|
513
|
+
else if (!tr.doc.resolve(pos).nodeBefore) {
|
|
514
|
+
// for this case will just delete that node in `deleteNode.ts` as the join will not work
|
|
515
|
+
return undefined;
|
|
515
516
|
}
|
|
516
517
|
// TODO is this the same thing as join to above?
|
|
517
518
|
const resPos = tr.doc.resolve(pos);
|
|
@@ -1200,6 +1201,7 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
|
|
|
1200
1201
|
let selectionPos = 0, changeSteps = [];
|
|
1201
1202
|
// Invert the transaction step to prevent it from actually deleting or inserting anything
|
|
1202
1203
|
step.getMap().forEach((fromA, toA, fromB, toB) => {
|
|
1204
|
+
var _a, _b;
|
|
1203
1205
|
log.info(`changed ranges: ${fromA} ${toA} ${fromB} ${toB}`);
|
|
1204
1206
|
const { slice } = step;
|
|
1205
1207
|
log.info('TR: steps before applying delete', [...newTr.steps]);
|
|
@@ -1247,9 +1249,6 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
|
|
|
1247
1249
|
type: 'insert-slice',
|
|
1248
1250
|
from: textWasDeleted ? fromB : toA,
|
|
1249
1251
|
to: textWasDeleted ? toB - 1 : toA,
|
|
1250
|
-
/* it's not entirely clear why using "fromB" is needed at all but in cases where there areno content deleted before
|
|
1251
|
-
- it will gointo infinite loop if toB -1 is used
|
|
1252
|
-
*/
|
|
1253
1252
|
sliceWasSplit,
|
|
1254
1253
|
slice: new prosemirrorModel.Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd),
|
|
1255
1254
|
});
|
|
@@ -1257,7 +1256,10 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
|
|
|
1257
1256
|
else {
|
|
1258
1257
|
// Incase only deletion was applied, check whether tracked marks around deleted content can be merged
|
|
1259
1258
|
// mergeTrackedMarks(adjustedInsertPos, newTr.doc, newTr, oldState.schema)
|
|
1260
|
-
|
|
1259
|
+
// When DEL is used, the selection is set to the end of the deleted content
|
|
1260
|
+
// TODO: 'window.event' is deprecated, find a better way to detect the key used for deletion
|
|
1261
|
+
// @ts-ignore
|
|
1262
|
+
selectionPos = ((_a = window.event) === null || _a === void 0 ? void 0 : _a.code) === 'Delete' || ((_b = window.event) === null || _b === void 0 ? void 0 : _b.inputType) === 'deleteContentForward' ? toA : fromA;
|
|
1261
1263
|
}
|
|
1262
1264
|
});
|
|
1263
1265
|
return [changeSteps, selectionPos];
|
package/dist/index.js
CHANGED
|
@@ -440,7 +440,8 @@ function deleteNode(node, pos, tr) {
|
|
|
440
440
|
const resPos = tr.doc.resolve(pos);
|
|
441
441
|
// Block nodes can be deleted by just removing their start token which should then merge the text
|
|
442
442
|
// content to above node's content (if there is one)
|
|
443
|
-
|
|
443
|
+
// this will work just for the node after the first child
|
|
444
|
+
const canMergeToNodeAbove = resPos.parent !== tr.doc && resPos.nodeBefore && node.isBlock && ((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.isText);
|
|
444
445
|
if (canMergeToNodeAbove) {
|
|
445
446
|
return tr.replaceWith(pos - 1, pos + 1, Fragment.empty);
|
|
446
447
|
}
|
|
@@ -501,9 +502,9 @@ function mergeNode(node, pos, tr) {
|
|
|
501
502
|
if (canJoin(tr.doc, pos)) {
|
|
502
503
|
return tr.join(pos);
|
|
503
504
|
}
|
|
504
|
-
else if (
|
|
505
|
-
//
|
|
506
|
-
return
|
|
505
|
+
else if (!tr.doc.resolve(pos).nodeBefore) {
|
|
506
|
+
// for this case will just delete that node in `deleteNode.ts` as the join will not work
|
|
507
|
+
return undefined;
|
|
507
508
|
}
|
|
508
509
|
// TODO is this the same thing as join to above?
|
|
509
510
|
const resPos = tr.doc.resolve(pos);
|
|
@@ -1192,6 +1193,7 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
|
|
|
1192
1193
|
let selectionPos = 0, changeSteps = [];
|
|
1193
1194
|
// Invert the transaction step to prevent it from actually deleting or inserting anything
|
|
1194
1195
|
step.getMap().forEach((fromA, toA, fromB, toB) => {
|
|
1196
|
+
var _a, _b;
|
|
1195
1197
|
log.info(`changed ranges: ${fromA} ${toA} ${fromB} ${toB}`);
|
|
1196
1198
|
const { slice } = step;
|
|
1197
1199
|
log.info('TR: steps before applying delete', [...newTr.steps]);
|
|
@@ -1239,9 +1241,6 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
|
|
|
1239
1241
|
type: 'insert-slice',
|
|
1240
1242
|
from: textWasDeleted ? fromB : toA,
|
|
1241
1243
|
to: textWasDeleted ? toB - 1 : toA,
|
|
1242
|
-
/* it's not entirely clear why using "fromB" is needed at all but in cases where there areno content deleted before
|
|
1243
|
-
- it will gointo infinite loop if toB -1 is used
|
|
1244
|
-
*/
|
|
1245
1244
|
sliceWasSplit,
|
|
1246
1245
|
slice: new Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd),
|
|
1247
1246
|
});
|
|
@@ -1249,7 +1248,10 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
|
|
|
1249
1248
|
else {
|
|
1250
1249
|
// Incase only deletion was applied, check whether tracked marks around deleted content can be merged
|
|
1251
1250
|
// mergeTrackedMarks(adjustedInsertPos, newTr.doc, newTr, oldState.schema)
|
|
1252
|
-
|
|
1251
|
+
// When DEL is used, the selection is set to the end of the deleted content
|
|
1252
|
+
// TODO: 'window.event' is deprecated, find a better way to detect the key used for deletion
|
|
1253
|
+
// @ts-ignore
|
|
1254
|
+
selectionPos = ((_a = window.event) === null || _a === void 0 ? void 0 : _a.code) === 'Delete' || ((_b = window.event) === null || _b === void 0 ? void 0 : _b.inputType) === 'deleteContentForward' ? toA : fromA;
|
|
1253
1255
|
}
|
|
1254
1256
|
});
|
|
1255
1257
|
return [changeSteps, selectionPos];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/track-changes-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
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",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "rollup -c",
|
|
63
63
|
"watch": "rollup -cw",
|
|
64
|
+
"dev": "yarn run watch",
|
|
64
65
|
"test": "jest --runInBand",
|
|
65
66
|
"format": "prettier --write \"*.+(js|json|yml|yaml|ts|md|graphql|mdx)\" src/ test/",
|
|
66
67
|
"typecheck": "tsc --project tsconfig.test.json --noEmit",
|