@manuscripts/track-changes-plugin 1.8.5 → 1.8.6-LEAN-4102.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.
package/dist/cjs/ChangeSet.js
CHANGED
|
@@ -38,13 +38,23 @@ class ChangeSet {
|
|
|
38
38
|
get changeTree() {
|
|
39
39
|
const rootNodes = [];
|
|
40
40
|
let currentNodeChange;
|
|
41
|
-
|
|
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.
|
|
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;
|
package/dist/es/ChangeSet.js
CHANGED
|
@@ -35,13 +35,23 @@ export class ChangeSet {
|
|
|
35
35
|
get changeTree() {
|
|
36
36
|
const rootNodes = [];
|
|
37
37
|
let currentNodeChange;
|
|
38
|
-
|
|
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.
|
|
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 {
|
|
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,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:
|
|
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
|
|
95
|
+
export type RootChanges = TrackedChange[][];
|
|
96
|
+
export type RootChange = TrackedChange[];
|
|
96
97
|
export {};
|
package/package.json
CHANGED