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

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,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
- const canMergeToNodeAbove = (resPos.parent !== tr.doc || resPos.nodeBefore) && node.isBlock && ((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.isText);
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 (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);
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);
@@ -1213,8 +1214,31 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1213
1214
  changeSteps.push(...deleteSteps);
1214
1215
  log.info('TR: steps after applying delete', [...newTr.steps]);
1215
1216
  log.info('DELETE STEPS: ', changeSteps);
1216
- const adjustedInsertPos = toA;
1217
- if (newSliceContent.size > 0) {
1217
+ // console.log('CHANGE STEPS AT THIS POINT:')
1218
+ // console.log(JSON.parse(JSON.stringify(changeSteps)))
1219
+ function sameThingBackSpaced() {
1220
+ /*
1221
+ When deleting text with backspace and getting to the point of when a space and a character before a deleted piece of text is deleted
1222
+ the prosemirror would interpret it as moving the <del> node (this is a tracked deletion) one characted behind.
1223
+ It normally results in [delete, delete, insert] set of ChangSteps where the 1st delete is for the delete done by
1224
+ 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
1225
+ and removed as they are not meaningful.
1226
+ */
1227
+ if (changeSteps.length == 2 && newSliceContent.size > 0) {
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);
1219
1243
  // Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
1220
1244
  // the sides should be equal. TODO can they be other than 0?
@@ -1222,8 +1246,11 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1222
1246
  const openEnd = slice.openStart !== slice.openEnd ? 0 : slice.openEnd;
1223
1247
  changeSteps.push({
1224
1248
  type: 'insert-slice',
1225
- from: adjustedInsertPos,
1226
- to: adjustedInsertPos,
1249
+ from: textWasDeleted ? fromB : toA,
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
+ */
1227
1254
  sliceWasSplit,
1228
1255
  slice: new prosemirrorModel.Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd),
1229
1256
  });
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
- const canMergeToNodeAbove = (resPos.parent !== tr.doc || resPos.nodeBefore) && node.isBlock && ((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.isText);
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 (canJoin(tr.doc, pos + node.nodeSize)) {
505
- // TODO should copy the attributes from the merged node below
506
- return tr.join(pos + node.nodeSize);
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);
@@ -1205,8 +1206,31 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1205
1206
  changeSteps.push(...deleteSteps);
1206
1207
  log.info('TR: steps after applying delete', [...newTr.steps]);
1207
1208
  log.info('DELETE STEPS: ', changeSteps);
1208
- const adjustedInsertPos = toA;
1209
- if (newSliceContent.size > 0) {
1209
+ // console.log('CHANGE STEPS AT THIS POINT:')
1210
+ // console.log(JSON.parse(JSON.stringify(changeSteps)))
1211
+ function sameThingBackSpaced() {
1212
+ /*
1213
+ When deleting text with backspace and getting to the point of when a space and a character before a deleted piece of text is deleted
1214
+ the prosemirror would interpret it as moving the <del> node (this is a tracked deletion) one characted behind.
1215
+ It normally results in [delete, delete, insert] set of ChangSteps where the 1st delete is for the delete done by
1216
+ 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
1217
+ and removed as they are not meaningful.
1218
+ */
1219
+ if (changeSteps.length == 2 && newSliceContent.size > 0) {
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);
1211
1235
  // Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
1212
1236
  // the sides should be equal. TODO can they be other than 0?
@@ -1214,8 +1238,11 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1214
1238
  const openEnd = slice.openStart !== slice.openEnd ? 0 : slice.openEnd;
1215
1239
  changeSteps.push({
1216
1240
  type: 'insert-slice',
1217
- from: adjustedInsertPos,
1218
- to: adjustedInsertPos,
1241
+ from: textWasDeleted ? fromB : toA,
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
+ */
1219
1246
  sliceWasSplit,
1220
1247
  slice: new Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd),
1221
1248
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manuscripts/track-changes-plugin",
3
- "version": "1.5.0",
3
+ "version": "1.5.2-LEAN-2508",
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",