@manuscripts/track-changes-plugin 1.5.2 → 1.6.1-LEAN-2737

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 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.
@@ -448,7 +449,8 @@ function deleteNode(node, pos, tr) {
448
449
  const resPos = tr.doc.resolve(pos);
449
450
  // Block nodes can be deleted by just removing their start token which should then merge the text
450
451
  // 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);
452
+ // this will work just for the node after the first child
453
+ const canMergeToNodeAbove = resPos.parent !== tr.doc && resPos.nodeBefore && node.isBlock && ((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.isText);
452
454
  if (canMergeToNodeAbove) {
453
455
  return tr.replaceWith(pos - 1, pos + 1, prosemirrorModel.Fragment.empty);
454
456
  }
@@ -509,9 +511,9 @@ function mergeNode(node, pos, tr) {
509
511
  if (prosemirrorTransform.canJoin(tr.doc, pos)) {
510
512
  return tr.join(pos);
511
513
  }
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);
514
+ else if (!tr.doc.resolve(pos).nodeBefore) {
515
+ // for this case will just delete that node in `deleteNode.ts` as the join will not work
516
+ return undefined;
515
517
  }
516
518
  // TODO is this the same thing as join to above?
517
519
  const resPos = tr.doc.resolve(pos);
@@ -1136,7 +1138,7 @@ function deleteAndMergeSplitNodes(from, to, gap, startDoc, newTr, schema, trackA
1136
1138
  * See the License for the specific language governing permissions and
1137
1139
  * limitations under the License.
1138
1140
  */
1139
- function trackReplaceAroundStep(step, oldState, newTr, attrs) {
1141
+ function trackReplaceAroundStep(step, oldState, tr, newTr, attrs) {
1140
1142
  log.info('###### ReplaceAroundStep ######');
1141
1143
  // @ts-ignore
1142
1144
  const { from, to, gapFrom, gapTo, insert, slice, structure, } = step;
@@ -1157,14 +1159,18 @@ function trackReplaceAroundStep(step, oldState, newTr, attrs) {
1157
1159
  log.info('DELETE STEPS: ', deleteSteps);
1158
1160
  // We only want to insert when there something inside the gap (actually would this be always true?)
1159
1161
  // or insert slice wasn't just start/end tokens (which we already merged inside deleteAndMergeSplitBlockNodes)
1160
- if (gap.size > 0 || (!structure && newSliceContent.size > 0)) {
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)) {
1161
1167
  log.info('newSliceContent', newSliceContent);
1162
1168
  // Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
1163
1169
  // the sides should be equal. TODO can they be other than 0?
1164
1170
  const openStart = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openStart;
1165
1171
  const openEnd = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openEnd;
1166
1172
  let insertedSlice = new prosemirrorModel.Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd);
1167
- if (gap.size > 0) {
1173
+ if (gap.size > 0 || tr.getMeta(TrackChangesAction.updateMetaNode)) {
1168
1174
  log.info('insertedSlice before inserted gap', insertedSlice);
1169
1175
  insertedSlice = insertedSlice.insertAt(insertedSlice.size === 0 ? 0 : insert, gap.content);
1170
1176
  log.info('insertedSlice after inserted gap', insertedSlice);
@@ -1200,6 +1206,7 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1200
1206
  let selectionPos = 0, changeSteps = [];
1201
1207
  // Invert the transaction step to prevent it from actually deleting or inserting anything
1202
1208
  step.getMap().forEach((fromA, toA, fromB, toB) => {
1209
+ var _a, _b;
1203
1210
  log.info(`changed ranges: ${fromA} ${toA} ${fromB} ${toB}`);
1204
1211
  const { slice } = step;
1205
1212
  log.info('TR: steps before applying delete', [...newTr.steps]);
@@ -1247,9 +1254,6 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1247
1254
  type: 'insert-slice',
1248
1255
  from: textWasDeleted ? fromB : toA,
1249
1256
  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
1257
  sliceWasSplit,
1254
1258
  slice: new prosemirrorModel.Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd),
1255
1259
  });
@@ -1257,7 +1261,10 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1257
1261
  else {
1258
1262
  // Incase only deletion was applied, check whether tracked marks around deleted content can be merged
1259
1263
  // mergeTrackedMarks(adjustedInsertPos, newTr.doc, newTr, oldState.schema)
1260
- selectionPos = fromA;
1264
+ // When DEL is used, the selection is set to the end of the deleted content
1265
+ // TODO: 'window.event' is deprecated, find a better way to detect the key used for deletion
1266
+ // @ts-ignore
1267
+ 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
1268
  }
1262
1269
  });
1263
1270
  return [changeSteps, selectionPos];
@@ -1722,7 +1729,7 @@ function trackTransaction(tr, oldState, newTr, authorID) {
1722
1729
  }
1723
1730
  }
1724
1731
  else if (step instanceof prosemirrorTransform.ReplaceAroundStep) {
1725
- let steps = trackReplaceAroundStep(step, oldState, newTr, emptyAttrs);
1732
+ let steps = trackReplaceAroundStep(step, oldState, tr, newTr, emptyAttrs);
1726
1733
  const deleted = steps.filter((s) => s.type !== 'insert-slice');
1727
1734
  const inserted = steps.filter((s) => s.type === 'insert-slice');
1728
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.
@@ -440,7 +441,8 @@ function deleteNode(node, pos, tr) {
440
441
  const resPos = tr.doc.resolve(pos);
441
442
  // Block nodes can be deleted by just removing their start token which should then merge the text
442
443
  // 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);
444
+ // this will work just for the node after the first child
445
+ const canMergeToNodeAbove = resPos.parent !== tr.doc && resPos.nodeBefore && node.isBlock && ((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.isText);
444
446
  if (canMergeToNodeAbove) {
445
447
  return tr.replaceWith(pos - 1, pos + 1, Fragment.empty);
446
448
  }
@@ -501,9 +503,9 @@ function mergeNode(node, pos, tr) {
501
503
  if (canJoin(tr.doc, pos)) {
502
504
  return tr.join(pos);
503
505
  }
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);
506
+ else if (!tr.doc.resolve(pos).nodeBefore) {
507
+ // for this case will just delete that node in `deleteNode.ts` as the join will not work
508
+ return undefined;
507
509
  }
508
510
  // TODO is this the same thing as join to above?
509
511
  const resPos = tr.doc.resolve(pos);
@@ -1128,7 +1130,7 @@ function deleteAndMergeSplitNodes(from, to, gap, startDoc, newTr, schema, trackA
1128
1130
  * See the License for the specific language governing permissions and
1129
1131
  * limitations under the License.
1130
1132
  */
1131
- function trackReplaceAroundStep(step, oldState, newTr, attrs) {
1133
+ function trackReplaceAroundStep(step, oldState, tr, newTr, attrs) {
1132
1134
  log.info('###### ReplaceAroundStep ######');
1133
1135
  // @ts-ignore
1134
1136
  const { from, to, gapFrom, gapTo, insert, slice, structure, } = step;
@@ -1149,14 +1151,18 @@ function trackReplaceAroundStep(step, oldState, newTr, attrs) {
1149
1151
  log.info('DELETE STEPS: ', deleteSteps);
1150
1152
  // We only want to insert when there something inside the gap (actually would this be always true?)
1151
1153
  // or insert slice wasn't just start/end tokens (which we already merged inside deleteAndMergeSplitBlockNodes)
1152
- if (gap.size > 0 || (!structure && newSliceContent.size > 0)) {
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)) {
1153
1159
  log.info('newSliceContent', newSliceContent);
1154
1160
  // Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
1155
1161
  // the sides should be equal. TODO can they be other than 0?
1156
1162
  const openStart = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openStart;
1157
1163
  const openEnd = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openEnd;
1158
1164
  let insertedSlice = new Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd);
1159
- if (gap.size > 0) {
1165
+ if (gap.size > 0 || tr.getMeta(TrackChangesAction.updateMetaNode)) {
1160
1166
  log.info('insertedSlice before inserted gap', insertedSlice);
1161
1167
  insertedSlice = insertedSlice.insertAt(insertedSlice.size === 0 ? 0 : insert, gap.content);
1162
1168
  log.info('insertedSlice after inserted gap', insertedSlice);
@@ -1192,6 +1198,7 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1192
1198
  let selectionPos = 0, changeSteps = [];
1193
1199
  // Invert the transaction step to prevent it from actually deleting or inserting anything
1194
1200
  step.getMap().forEach((fromA, toA, fromB, toB) => {
1201
+ var _a, _b;
1195
1202
  log.info(`changed ranges: ${fromA} ${toA} ${fromB} ${toB}`);
1196
1203
  const { slice } = step;
1197
1204
  log.info('TR: steps before applying delete', [...newTr.steps]);
@@ -1239,9 +1246,6 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1239
1246
  type: 'insert-slice',
1240
1247
  from: textWasDeleted ? fromB : toA,
1241
1248
  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
1249
  sliceWasSplit,
1246
1250
  slice: new Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd),
1247
1251
  });
@@ -1249,7 +1253,10 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
1249
1253
  else {
1250
1254
  // Incase only deletion was applied, check whether tracked marks around deleted content can be merged
1251
1255
  // mergeTrackedMarks(adjustedInsertPos, newTr.doc, newTr, oldState.schema)
1252
- selectionPos = fromA;
1256
+ // When DEL is used, the selection is set to the end of the deleted content
1257
+ // TODO: 'window.event' is deprecated, find a better way to detect the key used for deletion
1258
+ // @ts-ignore
1259
+ 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
1260
  }
1254
1261
  });
1255
1262
  return [changeSteps, selectionPos];
@@ -1714,7 +1721,7 @@ function trackTransaction(tr, oldState, newTr, authorID) {
1714
1721
  }
1715
1722
  }
1716
1723
  else if (step instanceof ReplaceAroundStep) {
1717
- let steps = trackReplaceAroundStep(step, oldState, newTr, emptyAttrs);
1724
+ let steps = trackReplaceAroundStep(step, oldState, tr, newTr, emptyAttrs);
1718
1725
  const deleted = steps.filter((s) => s.type !== 'insert-slice');
1719
1726
  const inserted = steps.filter((s) => s.type === 'insert-slice');
1720
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.5.2",
3
+ "version": "1.6.1-LEAN-2737",
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",