@manuscripts/track-changes-plugin 2.0.5 → 2.0.7

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.
@@ -40,7 +40,7 @@ function trackTransaction(tr, oldState, newTr, authorID, changeSet) {
40
40
  (0, track_utils_1.handleDirectPendingMoveDeletions)(tr, newTr, movingStepsAssociated);
41
41
  const cleanSteps = (0, track_utils_1.filterMeaninglessMoveSteps)(tr, movingStepsAssociated);
42
42
  for (let i = cleanSteps.length - 1; i >= 0; i--) {
43
- const step = tr.steps[i];
43
+ const step = cleanSteps[i];
44
44
  logger_1.log.info('transaction step', step);
45
45
  iters += 1;
46
46
  const uiEvent = tr.getMeta('uiEvent');
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  return t;
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.filterMeaninglessMoveSteps = exports.handleDirectPendingMoveDeletions = exports.isDirectPendingMoveDeletion = exports.isDeletingPendingMovedNode = exports.HasMoveOperations = exports.trFromHistory = exports.stepIsLift = exports.isLiftStep = exports.isWrapStep = exports.isSplitStep = exports.createNewUpdateAttrs = exports.createNewMoveAttrs = exports.createNewDeleteAttrs = exports.createNewReferenceAttrs = exports.createNewSplitAttrs = exports.createNewWrapAttrs = exports.createNewInsertAttrs = void 0;
14
+ exports.filterMeaninglessMoveSteps = exports.handleDirectPendingMoveDeletions = exports.isDirectPendingMoveDeletion = exports.isDeletingPendingMovedNode = exports.isPendingChange = exports.HasMoveOperations = exports.trFromHistory = exports.stepIsLift = exports.isLiftStep = exports.isWrapStep = exports.isSplitStep = exports.createNewUpdateAttrs = exports.createNewMoveAttrs = exports.createNewDeleteAttrs = exports.createNewReferenceAttrs = exports.createNewSplitAttrs = exports.createNewWrapAttrs = exports.createNewInsertAttrs = void 0;
15
15
  const prosemirror_transform_1 = require("prosemirror-transform");
16
16
  const change_1 = require("../types/change");
17
17
  const uuidv4_1 = require("./uuidv4");
@@ -66,7 +66,8 @@ const isSplitStep = (step, selection, uiEvent) => {
66
66
  return (openStart === openEnd &&
67
67
  firstChild.type === lastChild.type &&
68
68
  firstChild.inlineContent &&
69
- lastChild.inlineContent);
69
+ lastChild.inlineContent &&
70
+ !(startOffset === parentSize && endOffset === parentSize));
70
71
  };
71
72
  exports.isSplitStep = isSplitStep;
72
73
  const isWrapStep = (step) => step.from === step.gapFrom &&
@@ -146,6 +147,10 @@ const HasMoveOperations = (tr) => {
146
147
  return movingAssoc;
147
148
  };
148
149
  exports.HasMoveOperations = HasMoveOperations;
150
+ const isPendingChange = (trackedAttrs, operation) => {
151
+ return !!(trackedAttrs === null || trackedAttrs === void 0 ? void 0 : trackedAttrs.some((t) => t.operation === operation));
152
+ };
153
+ exports.isPendingChange = isPendingChange;
149
154
  const isDeletingPendingMovedNode = (step, doc) => {
150
155
  if (!step.slice || step.from === step.to || step.slice.content.size > 0) {
151
156
  return undefined;
@@ -173,8 +178,7 @@ const isDirectPendingMoveDeletion = (step, doc, movingSteps) => {
173
178
  if (!node) {
174
179
  return false;
175
180
  }
176
- const trackedAttrs = node.attrs.dataTracked;
177
- return !!(trackedAttrs === null || trackedAttrs === void 0 ? void 0 : trackedAttrs.some((t) => t.operation === change_1.CHANGE_OPERATION.move && t.status === change_1.CHANGE_STATUS.pending));
181
+ return (0, exports.isPendingChange)(node.attrs.dataTracked, change_1.CHANGE_OPERATION.move);
178
182
  };
179
183
  exports.isDirectPendingMoveDeletion = isDirectPendingMoveDeletion;
180
184
  const handleDirectPendingMoveDeletions = (tr, newTr, movingSteps) => {
@@ -192,18 +196,33 @@ const handleDirectPendingMoveDeletions = (tr, newTr, movingSteps) => {
192
196
  };
193
197
  exports.handleDirectPendingMoveDeletions = handleDirectPendingMoveDeletions;
194
198
  const filterMeaninglessMoveSteps = (tr, movingSteps) => {
199
+ var _a;
195
200
  const cleanSteps = [];
196
201
  for (let i = 0; i < tr.steps.length; i++) {
197
202
  const step = tr.steps[i];
198
203
  const moveID = movingSteps.get(step);
199
- const prevMoveID = (0, exports.isDeletingPendingMovedNode)(step, tr.docs[i]);
200
- if (moveID && prevMoveID) {
201
- movingSteps.forEach((replaceStepMoveID, replaceStep) => {
202
- if (replaceStep !== step && moveID === replaceStepMoveID) {
203
- movingSteps.set(replaceStep, prevMoveID);
204
+ if (moveID) {
205
+ const prevMoveID = (0, exports.isDeletingPendingMovedNode)(step, tr.docs[i]);
206
+ if (prevMoveID) {
207
+ movingSteps.forEach((replaceStepMoveID, replaceStep) => {
208
+ if (replaceStep !== step && moveID === replaceStepMoveID) {
209
+ movingSteps.set(replaceStep, prevMoveID);
210
+ }
211
+ });
212
+ continue;
213
+ }
214
+ if (step instanceof prosemirror_transform_1.ReplaceStep) {
215
+ const { slice } = step;
216
+ if ((_a = slice === null || slice === void 0 ? void 0 : slice.content) === null || _a === void 0 ? void 0 : _a.firstChild) {
217
+ const insertedNode = slice.content.firstChild;
218
+ if (insertedNode.attrs.dataTracked) {
219
+ const isPendingInsert = (0, exports.isPendingChange)(insertedNode.attrs.dataTracked, change_1.CHANGE_OPERATION.insert);
220
+ if (isPendingInsert) {
221
+ continue;
222
+ }
223
+ }
204
224
  }
205
- });
206
- continue;
225
+ }
207
226
  }
208
227
  cleanSteps.push(step);
209
228
  }
@@ -34,7 +34,7 @@ export function trackTransaction(tr, oldState, newTr, authorID, changeSet) {
34
34
  handleDirectPendingMoveDeletions(tr, newTr, movingStepsAssociated);
35
35
  const cleanSteps = filterMeaninglessMoveSteps(tr, movingStepsAssociated);
36
36
  for (let i = cleanSteps.length - 1; i >= 0; i--) {
37
- const step = tr.steps[i];
37
+ const step = cleanSteps[i];
38
38
  log.info('transaction step', step);
39
39
  iters += 1;
40
40
  const uiEvent = tr.getMeta('uiEvent');
@@ -56,7 +56,8 @@ export const isSplitStep = (step, selection, uiEvent) => {
56
56
  return (openStart === openEnd &&
57
57
  firstChild.type === lastChild.type &&
58
58
  firstChild.inlineContent &&
59
- lastChild.inlineContent);
59
+ lastChild.inlineContent &&
60
+ !(startOffset === parentSize && endOffset === parentSize));
60
61
  };
61
62
  export const isWrapStep = (step) => step.from === step.gapFrom &&
62
63
  step.to === step.gapTo &&
@@ -130,6 +131,9 @@ export const HasMoveOperations = (tr) => {
130
131
  }
131
132
  return movingAssoc;
132
133
  };
134
+ export const isPendingChange = (trackedAttrs, operation) => {
135
+ return !!(trackedAttrs === null || trackedAttrs === void 0 ? void 0 : trackedAttrs.some((t) => t.operation === operation));
136
+ };
133
137
  export const isDeletingPendingMovedNode = (step, doc) => {
134
138
  if (!step.slice || step.from === step.to || step.slice.content.size > 0) {
135
139
  return undefined;
@@ -156,8 +160,7 @@ export const isDirectPendingMoveDeletion = (step, doc, movingSteps) => {
156
160
  if (!node) {
157
161
  return false;
158
162
  }
159
- const trackedAttrs = node.attrs.dataTracked;
160
- return !!(trackedAttrs === null || trackedAttrs === void 0 ? void 0 : trackedAttrs.some((t) => t.operation === CHANGE_OPERATION.move && t.status === CHANGE_STATUS.pending));
163
+ return isPendingChange(node.attrs.dataTracked, CHANGE_OPERATION.move);
161
164
  };
162
165
  export const handleDirectPendingMoveDeletions = (tr, newTr, movingSteps) => {
163
166
  tr.steps.forEach((step) => {
@@ -173,18 +176,33 @@ export const handleDirectPendingMoveDeletions = (tr, newTr, movingSteps) => {
173
176
  });
174
177
  };
175
178
  export const filterMeaninglessMoveSteps = (tr, movingSteps) => {
179
+ var _a;
176
180
  const cleanSteps = [];
177
181
  for (let i = 0; i < tr.steps.length; i++) {
178
182
  const step = tr.steps[i];
179
183
  const moveID = movingSteps.get(step);
180
- const prevMoveID = isDeletingPendingMovedNode(step, tr.docs[i]);
181
- if (moveID && prevMoveID) {
182
- movingSteps.forEach((replaceStepMoveID, replaceStep) => {
183
- if (replaceStep !== step && moveID === replaceStepMoveID) {
184
- movingSteps.set(replaceStep, prevMoveID);
184
+ if (moveID) {
185
+ const prevMoveID = isDeletingPendingMovedNode(step, tr.docs[i]);
186
+ if (prevMoveID) {
187
+ movingSteps.forEach((replaceStepMoveID, replaceStep) => {
188
+ if (replaceStep !== step && moveID === replaceStepMoveID) {
189
+ movingSteps.set(replaceStep, prevMoveID);
190
+ }
191
+ });
192
+ continue;
193
+ }
194
+ if (step instanceof ReplaceStep) {
195
+ const { slice } = step;
196
+ if ((_a = slice === null || slice === void 0 ? void 0 : slice.content) === null || _a === void 0 ? void 0 : _a.firstChild) {
197
+ const insertedNode = slice.content.firstChild;
198
+ if (insertedNode.attrs.dataTracked) {
199
+ const isPendingInsert = isPendingChange(insertedNode.attrs.dataTracked, CHANGE_OPERATION.insert);
200
+ if (isPendingInsert) {
201
+ continue;
202
+ }
203
+ }
185
204
  }
186
- });
187
- continue;
205
+ }
188
206
  }
189
207
  cleanSteps.push(step);
190
208
  }
@@ -1,6 +1,7 @@
1
1
  import { Node as PMNode, Slice } from 'prosemirror-model';
2
2
  import { Selection, Transaction } from 'prosemirror-state';
3
3
  import { ReplaceAroundStep, ReplaceStep, Step } from 'prosemirror-transform';
4
+ import { CHANGE_OPERATION, TrackedAttrs } from '../types/change';
4
5
  import { NewDeleteAttrs, NewEmptyAttrs, NewInsertAttrs, NewReferenceAttrs, NewSplitNodeAttrs, NewUpdateAttrs } from '../types/track';
5
6
  export declare function createNewInsertAttrs(attrs: NewEmptyAttrs): NewInsertAttrs;
6
7
  export declare function createNewWrapAttrs(attrs: NewEmptyAttrs): NewInsertAttrs;
@@ -20,6 +21,7 @@ export declare function stepIsLift(gap: {
20
21
  }, node: PMNode, to: number): boolean;
21
22
  export declare const trFromHistory: (tr: Transaction) => string | undefined;
22
23
  export declare const HasMoveOperations: (tr: Transaction) => Map<ReplaceStep, string>;
24
+ export declare const isPendingChange: (trackedAttrs: TrackedAttrs[] | undefined, operation: CHANGE_OPERATION) => boolean;
23
25
  export declare const isDeletingPendingMovedNode: (step: ReplaceStep, doc: PMNode) => string | undefined;
24
26
  export declare const isDirectPendingMoveDeletion: (step: ReplaceStep, doc: PMNode, movingSteps: Map<ReplaceStep, string>) => boolean;
25
27
  export declare const handleDirectPendingMoveDeletions: (tr: Transaction, newTr: Transaction, movingSteps: Map<ReplaceStep, string>) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manuscripts/track-changes-plugin",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "author": "Atypon Systems LLC",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/Atypon-OpenSource/manuscripts-track-changes-plugin",