@manuscripts/track-changes-plugin 1.7.11 → 1.7.12-LEAN-3609.0

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.
@@ -51,10 +51,24 @@ class ChangeSet {
51
51
  currentNodeChange.children.push(c);
52
52
  }
53
53
  else if (c.type === 'node-change') {
54
- currentNodeChange = Object.assign(Object.assign({}, c), { children: [] });
54
+ const result = this.matchAndAddToRootChange(rootNodes, c);
55
+ if (result) {
56
+ const { index, root } = result;
57
+ rootNodes[index] = root;
58
+ }
59
+ else {
60
+ currentNodeChange = Object.assign(Object.assign({}, c), { children: [] });
61
+ }
55
62
  }
56
63
  else {
57
- rootNodes.push(c);
64
+ const result = this.matchAndAddToRootChange(rootNodes, c);
65
+ if (result) {
66
+ const { index, root } = result;
67
+ rootNodes[index] = root;
68
+ }
69
+ else {
70
+ rootNodes.push(c);
71
+ }
58
72
  }
59
73
  });
60
74
  if (currentNodeChange) {
@@ -110,6 +124,17 @@ class ChangeSet {
110
124
  getNotIn(ids) {
111
125
  return __classPrivateFieldGet(this, _ChangeSet_changes, "f").filter((c) => ids.includes(c.id));
112
126
  }
127
+ matchAndAddToRootChange(rootNodes, change) {
128
+ for (let i = 0; i < rootNodes.length; i++) {
129
+ const root = rootNodes[i];
130
+ if (root.type === 'node-change' &&
131
+ change.from < root.to &&
132
+ change.dataTracked.statusUpdateAt === root.dataTracked.statusUpdateAt) {
133
+ root.children.push(change);
134
+ return { index: i, root };
135
+ }
136
+ }
137
+ }
113
138
  static flattenTreeToIds(changes) {
114
139
  return changes.flatMap((c) => (this.isNodeChange(c) ? [c.id, ...c.children.map((c) => c.id)] : c.id));
115
140
  }
@@ -48,10 +48,24 @@ export class ChangeSet {
48
48
  currentNodeChange.children.push(c);
49
49
  }
50
50
  else if (c.type === 'node-change') {
51
- currentNodeChange = Object.assign(Object.assign({}, c), { children: [] });
51
+ const result = this.matchAndAddToRootChange(rootNodes, c);
52
+ if (result) {
53
+ const { index, root } = result;
54
+ rootNodes[index] = root;
55
+ }
56
+ else {
57
+ currentNodeChange = Object.assign(Object.assign({}, c), { children: [] });
58
+ }
52
59
  }
53
60
  else {
54
- rootNodes.push(c);
61
+ const result = this.matchAndAddToRootChange(rootNodes, c);
62
+ if (result) {
63
+ const { index, root } = result;
64
+ rootNodes[index] = root;
65
+ }
66
+ else {
67
+ rootNodes.push(c);
68
+ }
55
69
  }
56
70
  });
57
71
  if (currentNodeChange) {
@@ -107,6 +121,17 @@ export class ChangeSet {
107
121
  getNotIn(ids) {
108
122
  return __classPrivateFieldGet(this, _ChangeSet_changes, "f").filter((c) => ids.includes(c.id));
109
123
  }
124
+ matchAndAddToRootChange(rootNodes, change) {
125
+ for (let i = 0; i < rootNodes.length; i++) {
126
+ const root = rootNodes[i];
127
+ if (root.type === 'node-change' &&
128
+ change.from < root.to &&
129
+ change.dataTracked.statusUpdateAt === root.dataTracked.statusUpdateAt) {
130
+ root.children.push(change);
131
+ return { index: i, root };
132
+ }
133
+ }
134
+ }
110
135
  static flattenTreeToIds(changes) {
111
136
  return changes.flatMap((c) => (this.isNodeChange(c) ? [c.id, ...c.children.map((c) => c.id)] : c.id));
112
137
  }
@@ -19,6 +19,10 @@ export declare class ChangeSet {
19
19
  get(id: string): TrackedChange | IncompleteChange | undefined;
20
20
  getIn(ids: string[]): (TrackedChange | IncompleteChange)[];
21
21
  getNotIn(ids: string[]): (TrackedChange | IncompleteChange)[];
22
+ matchAndAddToRootChange(rootNodes: TrackedChange[], change: TrackedChange): {
23
+ index: number;
24
+ root: NodeChange;
25
+ } | undefined;
22
26
  static flattenTreeToIds(changes: TrackedChange[]): string[];
23
27
  static shouldDeleteChange(change: TrackedChange): boolean;
24
28
  static isValidDataTracked(dataTracked?: Partial<TrackedAttrs>): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manuscripts/track-changes-plugin",
3
- "version": "1.7.11",
3
+ "version": "1.7.12-LEAN-3609.0",
4
4
  "author": "Atypon Systems LLC",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/Atypon-OpenSource/manuscripts-track-changes-plugin",
@@ -69,4 +69,4 @@
69
69
  "resolutions": {
70
70
  "eslint-mdx": "2.0.5"
71
71
  }
72
- }
72
+ }