@manuscripts/track-changes-plugin 1.8.5 → 1.8.6-LEAN-4102.1

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.
@@ -38,13 +38,23 @@ class ChangeSet {
38
38
  get changeTree() {
39
39
  const rootNodes = [];
40
40
  let currentNodeChange;
41
- this.changes.forEach((c) => {
41
+ let currentInlineChange;
42
+ this.changes.forEach((c, index) => {
42
43
  if (currentNodeChange &&
43
44
  (c.from >= currentNodeChange.to ||
44
45
  c.dataTracked.statusUpdateAt !== currentNodeChange.dataTracked.statusUpdateAt)) {
45
- rootNodes.push(currentNodeChange);
46
+ rootNodes.push([currentNodeChange]);
46
47
  currentNodeChange = undefined;
47
48
  }
49
+ if (this.canJoinAdjacentInlineChanges(c, index) && !currentNodeChange) {
50
+ currentInlineChange = currentInlineChange ? [...currentInlineChange, c] : [c];
51
+ return;
52
+ }
53
+ else if (currentInlineChange) {
54
+ rootNodes.push([...currentInlineChange, c]);
55
+ currentInlineChange = undefined;
56
+ return;
57
+ }
48
58
  if (currentNodeChange &&
49
59
  c.from < currentNodeChange.to &&
50
60
  !(__classPrivateFieldGet(this, _ChangeSet_instances, "m", _ChangeSet_isSameNodeChange).call(this, currentNodeChange, c) && __classPrivateFieldGet(this, _ChangeSet_instances, "m", _ChangeSet_isNotPendingOrDeleted).call(this, currentNodeChange))) {
@@ -54,7 +64,7 @@ class ChangeSet {
54
64
  const result = this.matchAndAddToRootChange(rootNodes, c);
55
65
  if (result) {
56
66
  const { index, root } = result;
57
- rootNodes[index] = root;
67
+ rootNodes[index][0] = root;
58
68
  }
59
69
  else {
60
70
  currentNodeChange = Object.assign(Object.assign({}, c), { children: [] });
@@ -64,20 +74,20 @@ class ChangeSet {
64
74
  const result = this.matchAndAddToRootChange(rootNodes, c);
65
75
  if (result) {
66
76
  const { index, root } = result;
67
- rootNodes[index] = root;
77
+ rootNodes[index][0] = root;
68
78
  }
69
79
  else {
70
- rootNodes.push(c);
80
+ rootNodes.push([c]);
71
81
  }
72
82
  }
73
83
  });
74
84
  if (currentNodeChange) {
75
- rootNodes.push(currentNodeChange);
85
+ rootNodes.push([currentNodeChange]);
76
86
  }
77
- return rootNodes;
87
+ return rootNodes.filter((changes) => changes.filter((c) => c.dataTracked.operation !== change_1.CHANGE_OPERATION.reference));
78
88
  }
79
89
  get pending() {
80
- return this.changeTree.filter((c) => c.dataTracked.status === change_1.CHANGE_STATUS.pending);
90
+ return this.changes.filter((c) => c.dataTracked.status === change_1.CHANGE_STATUS.pending);
81
91
  }
82
92
  get textChanges() {
83
93
  return this.changes.filter((c) => c.type === 'text-change');
@@ -120,7 +130,7 @@ class ChangeSet {
120
130
  }
121
131
  matchAndAddToRootChange(rootNodes, change) {
122
132
  for (let i = 0; i < rootNodes.length; i++) {
123
- const root = rootNodes[i];
133
+ const root = rootNodes[i][0];
124
134
  if (root.type === 'node-change' &&
125
135
  change.from < root.to &&
126
136
  change.dataTracked.statusUpdateAt === root.dataTracked.statusUpdateAt) {
@@ -129,6 +139,15 @@ class ChangeSet {
129
139
  }
130
140
  }
131
141
  }
142
+ canJoinAdjacentInlineChanges(change, index) {
143
+ const nextChange = this.changes.at(index + 1);
144
+ const isInline = (c) => c.type === 'text-change' || (c.type === 'node-change' && c.node.isInline);
145
+ return (isInline(change) &&
146
+ nextChange &&
147
+ isInline(nextChange) &&
148
+ change.to === nextChange.from &&
149
+ change.dataTracked.operation === nextChange.dataTracked.operation);
150
+ }
132
151
  static flattenTreeToIds(changes) {
133
152
  return changes.flatMap((c) => (this.isNodeChange(c) ? [c.id, ...c.children.map((c) => c.id)] : c.id));
134
153
  }
@@ -12,11 +12,7 @@ function findChanges(state) {
12
12
  for (let i = 0; i < tracked.length; i += 1) {
13
13
  const dataTracked = tracked[i];
14
14
  const id = dataTracked.id || '';
15
- if (current &&
16
- current.change.id === id &&
17
- current.node.isText &&
18
- node.isText &&
19
- !(0, nodeHelpers_1.equalMarks)(node, current.node)) {
15
+ if (current && current.change.id === id) {
20
16
  current.change.to = pos + node.nodeSize;
21
17
  current.node = node;
22
18
  continue;
@@ -8,16 +8,19 @@ const prosemirror_state_1 = require("prosemirror-state");
8
8
  const prosemirror_transform_1 = require("prosemirror-transform");
9
9
  const diffChangeSteps_1 = require("../change-steps/diffChangeSteps");
10
10
  const processChangeSteps_1 = require("../change-steps/processChangeSteps");
11
+ const updateChangeAttrs_1 = require("../changes/updateChangeAttrs");
12
+ const nodeHelpers_1 = require("../compute/nodeHelpers");
11
13
  const change_1 = require("../types/change");
12
14
  const logger_1 = require("../utils/logger");
13
15
  const mapChangeStep_1 = require("../utils/mapChangeStep");
16
+ const uuidv4_1 = require("../utils/uuidv4");
14
17
  const trackAttrsChange_1 = __importDefault(require("./trackAttrsChange"));
15
18
  const trackReplaceAroundStep_1 = require("./trackReplaceAroundStep");
16
19
  const trackReplaceStep_1 = require("./trackReplaceStep");
17
20
  const getSelectionStaticConstructor = (sel) => Object.getPrototypeOf(sel).constructor;
18
21
  const isHighlightMarkerNode = (node) => node && node.type === node.type.schema.nodes.highlight_marker;
19
22
  function trackTransaction(tr, oldState, newTr, authorID) {
20
- var _a, _b, _c, _d;
23
+ var _a, _b, _c, _d, _e;
21
24
  const emptyAttrs = {
22
25
  authorID,
23
26
  reviewedByID: null,
@@ -91,6 +94,12 @@ function trackTransaction(tr, oldState, newTr, authorID) {
91
94
  const chnageSteps = (0, trackAttrsChange_1.default)(step, oldState, tr, newTr, emptyAttrs, tr.docs[i]);
92
95
  const [mapping, selectionPos] = (0, processChangeSteps_1.processChangeSteps)(chnageSteps, tr.selection.from, newTr, emptyAttrs, oldState.schema);
93
96
  }
97
+ else if (step instanceof prosemirror_transform_1.AddMarkStep) {
98
+ const dataTracked = (_e = (0, nodeHelpers_1.getNodeTrackedData)(newTr.doc.nodeAt(step.from), oldState.schema)) === null || _e === void 0 ? void 0 : _e.pop();
99
+ if (dataTracked) {
100
+ (0, updateChangeAttrs_1.updateChangeAttrs)(newTr, { id: dataTracked.id, from: step.from, to: step.to, type: 'text-change', dataTracked }, Object.assign(Object.assign({}, dataTracked), { id: (0, uuidv4_1.uuidv4)() }), oldState.schema);
101
+ }
102
+ }
94
103
  tr.getMeta('inputType') && newTr.setMeta('inputType', tr.getMeta('inputType'));
95
104
  tr.getMeta('uiEvent') && newTr.setMeta('uiEvent', tr.getMeta('uiEvent'));
96
105
  }
@@ -35,13 +35,23 @@ export class ChangeSet {
35
35
  get changeTree() {
36
36
  const rootNodes = [];
37
37
  let currentNodeChange;
38
- this.changes.forEach((c) => {
38
+ let currentInlineChange;
39
+ this.changes.forEach((c, index) => {
39
40
  if (currentNodeChange &&
40
41
  (c.from >= currentNodeChange.to ||
41
42
  c.dataTracked.statusUpdateAt !== currentNodeChange.dataTracked.statusUpdateAt)) {
42
- rootNodes.push(currentNodeChange);
43
+ rootNodes.push([currentNodeChange]);
43
44
  currentNodeChange = undefined;
44
45
  }
46
+ if (this.canJoinAdjacentInlineChanges(c, index) && !currentNodeChange) {
47
+ currentInlineChange = currentInlineChange ? [...currentInlineChange, c] : [c];
48
+ return;
49
+ }
50
+ else if (currentInlineChange) {
51
+ rootNodes.push([...currentInlineChange, c]);
52
+ currentInlineChange = undefined;
53
+ return;
54
+ }
45
55
  if (currentNodeChange &&
46
56
  c.from < currentNodeChange.to &&
47
57
  !(__classPrivateFieldGet(this, _ChangeSet_instances, "m", _ChangeSet_isSameNodeChange).call(this, currentNodeChange, c) && __classPrivateFieldGet(this, _ChangeSet_instances, "m", _ChangeSet_isNotPendingOrDeleted).call(this, currentNodeChange))) {
@@ -51,7 +61,7 @@ export class ChangeSet {
51
61
  const result = this.matchAndAddToRootChange(rootNodes, c);
52
62
  if (result) {
53
63
  const { index, root } = result;
54
- rootNodes[index] = root;
64
+ rootNodes[index][0] = root;
55
65
  }
56
66
  else {
57
67
  currentNodeChange = Object.assign(Object.assign({}, c), { children: [] });
@@ -61,20 +71,20 @@ export class ChangeSet {
61
71
  const result = this.matchAndAddToRootChange(rootNodes, c);
62
72
  if (result) {
63
73
  const { index, root } = result;
64
- rootNodes[index] = root;
74
+ rootNodes[index][0] = root;
65
75
  }
66
76
  else {
67
- rootNodes.push(c);
77
+ rootNodes.push([c]);
68
78
  }
69
79
  }
70
80
  });
71
81
  if (currentNodeChange) {
72
- rootNodes.push(currentNodeChange);
82
+ rootNodes.push([currentNodeChange]);
73
83
  }
74
- return rootNodes;
84
+ return rootNodes.filter((changes) => changes.filter((c) => c.dataTracked.operation !== CHANGE_OPERATION.reference));
75
85
  }
76
86
  get pending() {
77
- return this.changeTree.filter((c) => c.dataTracked.status === CHANGE_STATUS.pending);
87
+ return this.changes.filter((c) => c.dataTracked.status === CHANGE_STATUS.pending);
78
88
  }
79
89
  get textChanges() {
80
90
  return this.changes.filter((c) => c.type === 'text-change');
@@ -117,7 +127,7 @@ export class ChangeSet {
117
127
  }
118
128
  matchAndAddToRootChange(rootNodes, change) {
119
129
  for (let i = 0; i < rootNodes.length; i++) {
120
- const root = rootNodes[i];
130
+ const root = rootNodes[i][0];
121
131
  if (root.type === 'node-change' &&
122
132
  change.from < root.to &&
123
133
  change.dataTracked.statusUpdateAt === root.dataTracked.statusUpdateAt) {
@@ -126,6 +136,15 @@ export class ChangeSet {
126
136
  }
127
137
  }
128
138
  }
139
+ canJoinAdjacentInlineChanges(change, index) {
140
+ const nextChange = this.changes.at(index + 1);
141
+ const isInline = (c) => c.type === 'text-change' || (c.type === 'node-change' && c.node.isInline);
142
+ return (isInline(change) &&
143
+ nextChange &&
144
+ isInline(nextChange) &&
145
+ change.to === nextChange.from &&
146
+ change.dataTracked.operation === nextChange.dataTracked.operation);
147
+ }
129
148
  static flattenTreeToIds(changes) {
130
149
  return changes.flatMap((c) => (this.isNodeChange(c) ? [c.id, ...c.children.map((c) => c.id)] : c.id));
131
150
  }
@@ -1,5 +1,5 @@
1
1
  import { ChangeSet } from '../ChangeSet';
2
- import { equalMarks, getNodeTrackedData } from '../compute/nodeHelpers';
2
+ import { getNodeTrackedData } from '../compute/nodeHelpers';
3
3
  import { CHANGE_OPERATION, } from '../types/change';
4
4
  export function findChanges(state) {
5
5
  const changes = [];
@@ -9,11 +9,7 @@ export function findChanges(state) {
9
9
  for (let i = 0; i < tracked.length; i += 1) {
10
10
  const dataTracked = tracked[i];
11
11
  const id = dataTracked.id || '';
12
- if (current &&
13
- current.change.id === id &&
14
- current.node.isText &&
15
- node.isText &&
16
- !equalMarks(node, current.node)) {
12
+ if (current && current.change.id === id) {
17
13
  current.change.to = pos + node.nodeSize;
18
14
  current.node = node;
19
15
  continue;
@@ -1,17 +1,20 @@
1
1
  import { NodeSelection as NodeSelectionClass, TextSelection, } from 'prosemirror-state';
2
- import { AttrStep, ReplaceAroundStep, ReplaceStep, } from 'prosemirror-transform';
2
+ import { AddMarkStep, AttrStep, ReplaceAroundStep, ReplaceStep, } from 'prosemirror-transform';
3
3
  import { diffChangeSteps } from '../change-steps/diffChangeSteps';
4
4
  import { processChangeSteps } from '../change-steps/processChangeSteps';
5
+ import { updateChangeAttrs } from '../changes/updateChangeAttrs';
6
+ import { getNodeTrackedData } from '../compute/nodeHelpers';
5
7
  import { CHANGE_STATUS } from '../types/change';
6
8
  import { log } from '../utils/logger';
7
9
  import { mapChangeSteps } from '../utils/mapChangeStep';
10
+ import { uuidv4 } from '../utils/uuidv4';
8
11
  import trackAttrsChange from './trackAttrsChange';
9
12
  import { trackReplaceAroundStep } from './trackReplaceAroundStep';
10
13
  import { trackReplaceStep } from './trackReplaceStep';
11
14
  const getSelectionStaticConstructor = (sel) => Object.getPrototypeOf(sel).constructor;
12
15
  const isHighlightMarkerNode = (node) => node && node.type === node.type.schema.nodes.highlight_marker;
13
16
  export function trackTransaction(tr, oldState, newTr, authorID) {
14
- var _a, _b, _c, _d;
17
+ var _a, _b, _c, _d, _e;
15
18
  const emptyAttrs = {
16
19
  authorID,
17
20
  reviewedByID: null,
@@ -85,6 +88,12 @@ export function trackTransaction(tr, oldState, newTr, authorID) {
85
88
  const chnageSteps = trackAttrsChange(step, oldState, tr, newTr, emptyAttrs, tr.docs[i]);
86
89
  const [mapping, selectionPos] = processChangeSteps(chnageSteps, tr.selection.from, newTr, emptyAttrs, oldState.schema);
87
90
  }
91
+ else if (step instanceof AddMarkStep) {
92
+ const dataTracked = (_e = getNodeTrackedData(newTr.doc.nodeAt(step.from), oldState.schema)) === null || _e === void 0 ? void 0 : _e.pop();
93
+ if (dataTracked) {
94
+ updateChangeAttrs(newTr, { id: dataTracked.id, from: step.from, to: step.to, type: 'text-change', dataTracked }, Object.assign(Object.assign({}, dataTracked), { id: uuidv4() }), oldState.schema);
95
+ }
96
+ }
88
97
  tr.getMeta('inputType') && newTr.setMeta('inputType', tr.getMeta('inputType'));
89
98
  tr.getMeta('uiEvent') && newTr.setMeta('uiEvent', tr.getMeta('uiEvent'));
90
99
  }
@@ -1,10 +1,10 @@
1
- import { IncompleteChange, NodeAttrChange, NodeChange, ReferenceChange, TextChange, TrackedAttrs, TrackedChange } from './types/change';
1
+ import { IncompleteChange, NodeAttrChange, NodeChange, ReferenceChange, RootChanges, TextChange, TrackedAttrs, TrackedChange } from './types/change';
2
2
  export declare class ChangeSet {
3
3
  #private;
4
4
  constructor(changes?: (TrackedChange | IncompleteChange)[]);
5
5
  get changes(): TrackedChange[];
6
6
  get invalidChanges(): (TrackedChange | IncompleteChange)[];
7
- get changeTree(): TrackedChange[];
7
+ get changeTree(): TrackedChange[][];
8
8
  get pending(): TrackedChange[];
9
9
  get textChanges(): TrackedChange[];
10
10
  get nodeChanges(): TrackedChange[];
@@ -17,10 +17,11 @@ export declare class ChangeSet {
17
17
  get(id: string): TrackedChange | IncompleteChange | undefined;
18
18
  getIn(ids: string[]): (TrackedChange | IncompleteChange)[];
19
19
  getNotIn(ids: string[]): (TrackedChange | IncompleteChange)[];
20
- matchAndAddToRootChange(rootNodes: TrackedChange[], change: TrackedChange): {
20
+ matchAndAddToRootChange(rootNodes: RootChanges, change: TrackedChange): {
21
21
  index: number;
22
22
  root: NodeChange;
23
23
  } | undefined;
24
+ canJoinAdjacentInlineChanges(change: TrackedChange, index: number): boolean | undefined;
24
25
  static flattenTreeToIds(changes: TrackedChange[]): string[];
25
26
  static shouldDeleteChange(change: TrackedChange): boolean;
26
27
  static isValidDataTracked(dataTracked?: Partial<TrackedAttrs>): boolean;
@@ -92,5 +92,6 @@ export type PartialChange<T extends TrackedChange> = Omit<T, 'dataTracked'> & {
92
92
  export type IncompleteChange = Omit<TrackedChange, 'dataTracked'> & {
93
93
  dataTracked: Partial<TrackedAttrs>;
94
94
  };
95
- export type ChangeType = TrackedChange['type'];
95
+ export type RootChanges = TrackedChange[][];
96
+ export type RootChange = TrackedChange[];
96
97
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manuscripts/track-changes-plugin",
3
- "version": "1.8.5",
3
+ "version": "1.8.6-LEAN-4102.1",
4
4
  "author": "Atypon Systems LLC",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/Atypon-OpenSource/manuscripts-track-changes-plugin",