@manuscripts/track-changes-plugin 1.5.2-LEAN-2508 → 1.5.2-LEAN-2529

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 CHANGED
@@ -448,8 +448,7 @@ 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
- // 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);
451
+ const canMergeToNodeAbove = (resPos.parent !== tr.doc || resPos.nodeBefore) && node.isBlock && ((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.isText);
453
452
  if (canMergeToNodeAbove) {
454
453
  return tr.replaceWith(pos - 1, pos + 1, prosemirrorModel.Fragment.empty);
455
454
  }
@@ -510,9 +509,9 @@ function mergeNode(node, pos, tr) {
510
509
  if (prosemirrorTransform.canJoin(tr.doc, pos)) {
511
510
  return tr.join(pos);
512
511
  }
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;
512
+ else if (prosemirrorTransform.canJoin(tr.doc, pos + node.nodeSize)) {
513
+ // TODO should copy the attributes from the merged node below
514
+ return tr.join(pos + node.nodeSize);
516
515
  }
517
516
  // TODO is this the same thing as join to above?
518
517
  const resPos = tr.doc.resolve(pos);
@@ -1201,6 +1200,7 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1201
1200
  let selectionPos = 0, changeSteps = [];
1202
1201
  // Invert the transaction step to prevent it from actually deleting or inserting anything
1203
1202
  step.getMap().forEach((fromA, toA, fromB, toB) => {
1203
+ var _a, _b;
1204
1204
  log.info(`changed ranges: ${fromA} ${toA} ${fromB} ${toB}`);
1205
1205
  const { slice } = step;
1206
1206
  log.info('TR: steps before applying delete', [...newTr.steps]);
@@ -1248,9 +1248,6 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1248
1248
  type: 'insert-slice',
1249
1249
  from: textWasDeleted ? fromB : toA,
1250
1250
  to: textWasDeleted ? toB - 1 : toA,
1251
- /* it's not entirely clear why using "fromB" is needed at all but in cases where there areno content deleted before
1252
- - it will gointo infinite loop if toB -1 is used
1253
- */
1254
1251
  sliceWasSplit,
1255
1252
  slice: new prosemirrorModel.Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd),
1256
1253
  });
@@ -1258,7 +1255,10 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1258
1255
  else {
1259
1256
  // Incase only deletion was applied, check whether tracked marks around deleted content can be merged
1260
1257
  // mergeTrackedMarks(adjustedInsertPos, newTr.doc, newTr, oldState.schema)
1261
- selectionPos = fromA;
1258
+ // When DEL is used, the selection is set to the end of the deleted content
1259
+ // TODO: 'window.event' is deprecated, find a better way to detect the key used for deletion
1260
+ // @ts-ignore
1261
+ 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;
1262
1262
  }
1263
1263
  });
1264
1264
  return [changeSteps, selectionPos];
package/dist/index.js CHANGED
@@ -440,8 +440,7 @@ 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
- // 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);
443
+ const canMergeToNodeAbove = (resPos.parent !== tr.doc || resPos.nodeBefore) && node.isBlock && ((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.isText);
445
444
  if (canMergeToNodeAbove) {
446
445
  return tr.replaceWith(pos - 1, pos + 1, Fragment.empty);
447
446
  }
@@ -502,9 +501,9 @@ function mergeNode(node, pos, tr) {
502
501
  if (canJoin(tr.doc, pos)) {
503
502
  return tr.join(pos);
504
503
  }
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;
504
+ else if (canJoin(tr.doc, pos + node.nodeSize)) {
505
+ // TODO should copy the attributes from the merged node below
506
+ return tr.join(pos + node.nodeSize);
508
507
  }
509
508
  // TODO is this the same thing as join to above?
510
509
  const resPos = tr.doc.resolve(pos);
@@ -1193,6 +1192,7 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1193
1192
  let selectionPos = 0, changeSteps = [];
1194
1193
  // Invert the transaction step to prevent it from actually deleting or inserting anything
1195
1194
  step.getMap().forEach((fromA, toA, fromB, toB) => {
1195
+ var _a, _b;
1196
1196
  log.info(`changed ranges: ${fromA} ${toA} ${fromB} ${toB}`);
1197
1197
  const { slice } = step;
1198
1198
  log.info('TR: steps before applying delete', [...newTr.steps]);
@@ -1240,9 +1240,6 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1240
1240
  type: 'insert-slice',
1241
1241
  from: textWasDeleted ? fromB : toA,
1242
1242
  to: textWasDeleted ? toB - 1 : toA,
1243
- /* it's not entirely clear why using "fromB" is needed at all but in cases where there areno content deleted before
1244
- - it will gointo infinite loop if toB -1 is used
1245
- */
1246
1243
  sliceWasSplit,
1247
1244
  slice: new Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd),
1248
1245
  });
@@ -1250,7 +1247,10 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1250
1247
  else {
1251
1248
  // Incase only deletion was applied, check whether tracked marks around deleted content can be merged
1252
1249
  // mergeTrackedMarks(adjustedInsertPos, newTr.doc, newTr, oldState.schema)
1253
- selectionPos = fromA;
1250
+ // When DEL is used, the selection is set to the end of the deleted content
1251
+ // TODO: 'window.event' is deprecated, find a better way to detect the key used for deletion
1252
+ // @ts-ignore
1253
+ 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;
1254
1254
  }
1255
1255
  });
1256
1256
  return [changeSteps, selectionPos];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manuscripts/track-changes-plugin",
3
- "version": "1.5.2-LEAN-2508",
3
+ "version": "1.5.2-LEAN-2529",
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",