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

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,8 +22,7 @@ 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",
26
- updateMetaNode = "track-changes-update-meta-node"
25
+ applyAndRemoveChanges = "track-changes-apply-remove-changes"
27
26
  }
28
27
  export declare type TrackChangesActionParams = {
29
28
  [TrackChangesAction.skipTrack]: boolean;
@@ -35,7 +34,6 @@ export declare type TrackChangesActionParams = {
35
34
  };
36
35
  [TrackChangesAction.refreshChanges]: boolean;
37
36
  [TrackChangesAction.applyAndRemoveChanges]: boolean;
38
- [TrackChangesAction.updateMetaNode]: boolean;
39
37
  };
40
38
  /**
41
39
  * Gets the value of a meta field, action payload, of a defined track-changes action.
package/dist/index.cjs CHANGED
@@ -19,7 +19,6 @@ 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";
23
22
  })(TrackChangesAction || (TrackChangesAction = {}));
24
23
  /**
25
24
  * Gets the value of a meta field, action payload, of a defined track-changes action.
@@ -531,9 +530,7 @@ function updateChangeAttrs(tr, change, trackedAttrs, schema) {
531
530
  return tr;
532
531
  }
533
532
  const { operation } = trackedAttrs;
534
- const oldTrackData = change.type === 'text-change'
535
- ? getTextNodeTrackedMarkData(node, schema)
536
- : getBlockInlineTrackedData(node);
533
+ const oldTrackData = change.type === 'text-change' ? getTextNodeTrackedMarkData(node, schema) : getBlockInlineTrackedData(node);
537
534
  if (!operation) {
538
535
  log.warn('updateChangeAttrs: unable to determine operation of change ', change);
539
536
  }
@@ -554,7 +551,15 @@ function updateChangeAttrs(tr, change, trackedAttrs, schema) {
554
551
  tr.setNodeMarkup(change.from, undefined, { ...node.attrs, dataTracked: null }, node.marks);
555
552
  }
556
553
  else if (change.type === 'node-change' || change.type === 'node-attr-change') {
557
- const newDataTracked = (getBlockInlineTrackedData(node) || []).map((oldTrack) => {
554
+ const trackedDataSource = getBlockInlineTrackedData(node) || [];
555
+ const targetDataTracked = trackedDataSource.find((t) => change.id === t.id);
556
+ const newDataTracked = trackedDataSource.map((oldTrack) => {
557
+ if (targetDataTracked) {
558
+ if (oldTrack.id === targetDataTracked.id) {
559
+ return { ...oldTrack, ...trackedAttrs };
560
+ }
561
+ return oldTrack;
562
+ }
558
563
  if (oldTrack.operation === operation) {
559
564
  return { ...oldTrack, ...trackedAttrs };
560
565
  }
@@ -952,7 +957,7 @@ function createNewUpdateAttrs(attrs, oldAttrs) {
952
957
  return {
953
958
  ...attrs,
954
959
  operation: exports.CHANGE_OPERATION.set_node_attributes,
955
- oldAttrs: restAttrs,
960
+ oldAttrs: JSON.parse(JSON.stringify(restAttrs)),
956
961
  };
957
962
  }
958
963
 
@@ -1138,7 +1143,7 @@ function deleteAndMergeSplitNodes(from, to, gap, startDoc, newTr, schema, trackA
1138
1143
  * See the License for the specific language governing permissions and
1139
1144
  * limitations under the License.
1140
1145
  */
1141
- function trackReplaceAroundStep(step, oldState, tr, newTr, attrs) {
1146
+ function trackReplaceAroundStep(step, oldState, newTr, attrs) {
1142
1147
  log.info('###### ReplaceAroundStep ######');
1143
1148
  // @ts-ignore
1144
1149
  const { from, to, gapFrom, gapTo, insert, slice, structure, } = step;
@@ -1159,18 +1164,14 @@ function trackReplaceAroundStep(step, oldState, tr, newTr, attrs) {
1159
1164
  log.info('DELETE STEPS: ', deleteSteps);
1160
1165
  // We only want to insert when there something inside the gap (actually would this be always true?)
1161
1166
  // or insert slice wasn't just start/end tokens (which we already merged inside deleteAndMergeSplitBlockNodes)
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)) {
1167
+ if (gap.size > 0 || (!structure && newSliceContent.size > 0)) {
1167
1168
  log.info('newSliceContent', newSliceContent);
1168
1169
  // Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
1169
1170
  // the sides should be equal. TODO can they be other than 0?
1170
1171
  const openStart = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openStart;
1171
1172
  const openEnd = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openEnd;
1172
1173
  let insertedSlice = new prosemirrorModel.Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd);
1173
- if (gap.size > 0 || tr.getMeta(TrackChangesAction.updateMetaNode)) {
1174
+ if (gap.size > 0) {
1174
1175
  log.info('insertedSlice before inserted gap', insertedSlice);
1175
1176
  insertedSlice = insertedSlice.insertAt(insertedSlice.size === 0 ? 0 : insert, gap.content);
1176
1177
  log.info('insertedSlice after inserted gap', insertedSlice);
@@ -1203,7 +1204,8 @@ function trackReplaceAroundStep(step, oldState, tr, newTr, attrs) {
1203
1204
  */
1204
1205
  function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepDoc) {
1205
1206
  log.info('###### ReplaceStep ######');
1206
- let selectionPos = 0, changeSteps = [];
1207
+ let selectionPos = 0;
1208
+ const changeSteps = [];
1207
1209
  // Invert the transaction step to prevent it from actually deleting or inserting anything
1208
1210
  step.getMap().forEach((fromA, toA, fromB, toB) => {
1209
1211
  var _a, _b;
@@ -1427,15 +1429,29 @@ function processChangeSteps(changes, startPos, newTr, emptyAttrs, schema) {
1427
1429
  }
1428
1430
  else if (c.type === 'update-node-attrs') {
1429
1431
  const oldDataTracked = getBlockInlineTrackedData(c.node) || [];
1430
- const oldUpdate = oldDataTracked.find((d) => d.operation === exports.CHANGE_OPERATION.set_node_attributes && d.status === exports.CHANGE_STATUS.pending);
1431
- const { dataTracked, ...oldAttrs } = (oldUpdate === null || oldUpdate === void 0 ? void 0 : oldUpdate.oldAttrs) || c.node.attrs;
1432
- const newDataTracked = [...oldDataTracked.filter((d) => !oldUpdate || d.id !== oldUpdate.id)];
1433
- const newUpdate = oldUpdate
1432
+ const oldUpdate = oldDataTracked.reverse().find((d) => {
1433
+ // reversing to start from the most recent change
1434
+ if (d.operation === exports.CHANGE_OPERATION.set_node_attributes &&
1435
+ (d.status === exports.CHANGE_STATUS.pending || d.status === exports.CHANGE_STATUS.rejected)) {
1436
+ return true;
1437
+ }
1438
+ return false;
1439
+ });
1440
+ // if the selected last change is with status "rejected" we need to use oldAttrs from it because
1441
+ // node's actual attributes represent the "rejected" values
1442
+ const lastChangeRejected = oldUpdate && oldUpdate.status === exports.CHANGE_STATUS.rejected;
1443
+ const sourceAttrs = (oldUpdate === null || oldUpdate === void 0 ? void 0 : oldUpdate.oldAttrs) || c.node.attrs;
1444
+ const { dataTracked, ...restAttrs } = sourceAttrs;
1445
+ const oldAttrs = lastChangeRejected ? oldUpdate.oldAttrs : restAttrs;
1446
+ const newDataTracked = [
1447
+ ...oldDataTracked.filter((d) => !oldUpdate || d.id !== oldUpdate.id || lastChangeRejected),
1448
+ ];
1449
+ const newUpdate = oldUpdate && oldUpdate.status !== exports.CHANGE_STATUS.rejected
1434
1450
  ? {
1435
1451
  ...oldUpdate,
1436
1452
  updatedAt: emptyAttrs.updatedAt,
1437
1453
  }
1438
- : addTrackIdIfDoesntExist(createNewUpdateAttrs(emptyAttrs, c.node.attrs));
1454
+ : addTrackIdIfDoesntExist(createNewUpdateAttrs(emptyAttrs, lastChangeRejected ? oldAttrs : c.node.attrs));
1439
1455
  // Dont add update changes if there exists already an insert change for this node
1440
1456
  if (JSON.stringify(oldAttrs) !== JSON.stringify(c.newAttrs) &&
1441
1457
  !oldDataTracked.find((d) => d.operation === exports.CHANGE_OPERATION.insert)) {
@@ -1729,7 +1745,7 @@ function trackTransaction(tr, oldState, newTr, authorID) {
1729
1745
  }
1730
1746
  }
1731
1747
  else if (step instanceof prosemirrorTransform.ReplaceAroundStep) {
1732
- let steps = trackReplaceAroundStep(step, oldState, tr, newTr, emptyAttrs);
1748
+ let steps = trackReplaceAroundStep(step, oldState, newTr, emptyAttrs);
1733
1749
  const deleted = steps.filter((s) => s.type !== 'insert-slice');
1734
1750
  const inserted = steps.filter((s) => s.type === 'insert-slice');
1735
1751
  log.info('INSERT STEPS: ', inserted);
package/dist/index.js CHANGED
@@ -11,7 +11,6 @@ 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";
15
14
  })(TrackChangesAction || (TrackChangesAction = {}));
16
15
  /**
17
16
  * Gets the value of a meta field, action payload, of a defined track-changes action.
@@ -523,9 +522,7 @@ function updateChangeAttrs(tr, change, trackedAttrs, schema) {
523
522
  return tr;
524
523
  }
525
524
  const { operation } = trackedAttrs;
526
- const oldTrackData = change.type === 'text-change'
527
- ? getTextNodeTrackedMarkData(node, schema)
528
- : getBlockInlineTrackedData(node);
525
+ const oldTrackData = change.type === 'text-change' ? getTextNodeTrackedMarkData(node, schema) : getBlockInlineTrackedData(node);
529
526
  if (!operation) {
530
527
  log.warn('updateChangeAttrs: unable to determine operation of change ', change);
531
528
  }
@@ -546,7 +543,15 @@ function updateChangeAttrs(tr, change, trackedAttrs, schema) {
546
543
  tr.setNodeMarkup(change.from, undefined, { ...node.attrs, dataTracked: null }, node.marks);
547
544
  }
548
545
  else if (change.type === 'node-change' || change.type === 'node-attr-change') {
549
- const newDataTracked = (getBlockInlineTrackedData(node) || []).map((oldTrack) => {
546
+ const trackedDataSource = getBlockInlineTrackedData(node) || [];
547
+ const targetDataTracked = trackedDataSource.find((t) => change.id === t.id);
548
+ const newDataTracked = trackedDataSource.map((oldTrack) => {
549
+ if (targetDataTracked) {
550
+ if (oldTrack.id === targetDataTracked.id) {
551
+ return { ...oldTrack, ...trackedAttrs };
552
+ }
553
+ return oldTrack;
554
+ }
550
555
  if (oldTrack.operation === operation) {
551
556
  return { ...oldTrack, ...trackedAttrs };
552
557
  }
@@ -944,7 +949,7 @@ function createNewUpdateAttrs(attrs, oldAttrs) {
944
949
  return {
945
950
  ...attrs,
946
951
  operation: CHANGE_OPERATION.set_node_attributes,
947
- oldAttrs: restAttrs,
952
+ oldAttrs: JSON.parse(JSON.stringify(restAttrs)),
948
953
  };
949
954
  }
950
955
 
@@ -1130,7 +1135,7 @@ function deleteAndMergeSplitNodes(from, to, gap, startDoc, newTr, schema, trackA
1130
1135
  * See the License for the specific language governing permissions and
1131
1136
  * limitations under the License.
1132
1137
  */
1133
- function trackReplaceAroundStep(step, oldState, tr, newTr, attrs) {
1138
+ function trackReplaceAroundStep(step, oldState, newTr, attrs) {
1134
1139
  log.info('###### ReplaceAroundStep ######');
1135
1140
  // @ts-ignore
1136
1141
  const { from, to, gapFrom, gapTo, insert, slice, structure, } = step;
@@ -1151,18 +1156,14 @@ function trackReplaceAroundStep(step, oldState, tr, newTr, attrs) {
1151
1156
  log.info('DELETE STEPS: ', deleteSteps);
1152
1157
  // We only want to insert when there something inside the gap (actually would this be always true?)
1153
1158
  // or insert slice wasn't just start/end tokens (which we already merged inside deleteAndMergeSplitBlockNodes)
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)) {
1159
+ if (gap.size > 0 || (!structure && newSliceContent.size > 0)) {
1159
1160
  log.info('newSliceContent', newSliceContent);
1160
1161
  // Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
1161
1162
  // the sides should be equal. TODO can they be other than 0?
1162
1163
  const openStart = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openStart;
1163
1164
  const openEnd = slice.openStart !== slice.openEnd || newSliceContent.size === 0 ? 0 : slice.openEnd;
1164
1165
  let insertedSlice = new Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd);
1165
- if (gap.size > 0 || tr.getMeta(TrackChangesAction.updateMetaNode)) {
1166
+ if (gap.size > 0) {
1166
1167
  log.info('insertedSlice before inserted gap', insertedSlice);
1167
1168
  insertedSlice = insertedSlice.insertAt(insertedSlice.size === 0 ? 0 : insert, gap.content);
1168
1169
  log.info('insertedSlice after inserted gap', insertedSlice);
@@ -1195,7 +1196,8 @@ function trackReplaceAroundStep(step, oldState, tr, newTr, attrs) {
1195
1196
  */
1196
1197
  function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepDoc) {
1197
1198
  log.info('###### ReplaceStep ######');
1198
- let selectionPos = 0, changeSteps = [];
1199
+ let selectionPos = 0;
1200
+ const changeSteps = [];
1199
1201
  // Invert the transaction step to prevent it from actually deleting or inserting anything
1200
1202
  step.getMap().forEach((fromA, toA, fromB, toB) => {
1201
1203
  var _a, _b;
@@ -1419,15 +1421,29 @@ function processChangeSteps(changes, startPos, newTr, emptyAttrs, schema) {
1419
1421
  }
1420
1422
  else if (c.type === 'update-node-attrs') {
1421
1423
  const oldDataTracked = getBlockInlineTrackedData(c.node) || [];
1422
- const oldUpdate = oldDataTracked.find((d) => d.operation === CHANGE_OPERATION.set_node_attributes && d.status === CHANGE_STATUS.pending);
1423
- const { dataTracked, ...oldAttrs } = (oldUpdate === null || oldUpdate === void 0 ? void 0 : oldUpdate.oldAttrs) || c.node.attrs;
1424
- const newDataTracked = [...oldDataTracked.filter((d) => !oldUpdate || d.id !== oldUpdate.id)];
1425
- const newUpdate = oldUpdate
1424
+ const oldUpdate = oldDataTracked.reverse().find((d) => {
1425
+ // reversing to start from the most recent change
1426
+ if (d.operation === CHANGE_OPERATION.set_node_attributes &&
1427
+ (d.status === CHANGE_STATUS.pending || d.status === CHANGE_STATUS.rejected)) {
1428
+ return true;
1429
+ }
1430
+ return false;
1431
+ });
1432
+ // if the selected last change is with status "rejected" we need to use oldAttrs from it because
1433
+ // node's actual attributes represent the "rejected" values
1434
+ const lastChangeRejected = oldUpdate && oldUpdate.status === CHANGE_STATUS.rejected;
1435
+ const sourceAttrs = (oldUpdate === null || oldUpdate === void 0 ? void 0 : oldUpdate.oldAttrs) || c.node.attrs;
1436
+ const { dataTracked, ...restAttrs } = sourceAttrs;
1437
+ const oldAttrs = lastChangeRejected ? oldUpdate.oldAttrs : restAttrs;
1438
+ const newDataTracked = [
1439
+ ...oldDataTracked.filter((d) => !oldUpdate || d.id !== oldUpdate.id || lastChangeRejected),
1440
+ ];
1441
+ const newUpdate = oldUpdate && oldUpdate.status !== CHANGE_STATUS.rejected
1426
1442
  ? {
1427
1443
  ...oldUpdate,
1428
1444
  updatedAt: emptyAttrs.updatedAt,
1429
1445
  }
1430
- : addTrackIdIfDoesntExist(createNewUpdateAttrs(emptyAttrs, c.node.attrs));
1446
+ : addTrackIdIfDoesntExist(createNewUpdateAttrs(emptyAttrs, lastChangeRejected ? oldAttrs : c.node.attrs));
1431
1447
  // Dont add update changes if there exists already an insert change for this node
1432
1448
  if (JSON.stringify(oldAttrs) !== JSON.stringify(c.newAttrs) &&
1433
1449
  !oldDataTracked.find((d) => d.operation === CHANGE_OPERATION.insert)) {
@@ -1721,7 +1737,7 @@ function trackTransaction(tr, oldState, newTr, authorID) {
1721
1737
  }
1722
1738
  }
1723
1739
  else if (step instanceof ReplaceAroundStep) {
1724
- let steps = trackReplaceAroundStep(step, oldState, tr, newTr, emptyAttrs);
1740
+ let steps = trackReplaceAroundStep(step, oldState, newTr, emptyAttrs);
1725
1741
  const deleted = steps.filter((s) => s.type !== 'insert-slice');
1726
1742
  const inserted = steps.filter((s) => s.type === 'insert-slice');
1727
1743
  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, tr: Transaction, newTr: Transaction, attrs: NewEmptyAttrs): ChangeStep[];
5
+ export declare function trackReplaceAroundStep(step: ReplaceAroundStep, oldState: EditorState, 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.6.1-LEAN-2737",
3
+ "version": "1.6.1-LEAN-2752",
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",