Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { Mapping, RemoveMarkStep, ReplaceStep } from 'prosemirror-transform';
import { Slice } from 'prosemirror-model';
import removeNode from './removeNode';
const checkFromConfig = (mark, user, config) => {
if (mark.attrs.username === user.username && !config.own.accept) {
return false;
}
if (mark.attrs.username !== user.username && !config.others.accept) {
return false;
}
return true;
};
const acceptTrackChange = (state, dispatch, user, activeTrackChange) => {
const {
tr,
selection: { from, to },
} = state;
tr.setMeta('AcceptReject', true);
const map = new Mapping();
state.doc.nodesBetween(
activeTrackChange.from,
activeTrackChange.to,
(node, pos) => {
if (
node.attrs.track &&
node.attrs.track.find(track => track.type === 'deletion')
) {
removeNode(tr, node, pos, map);
}
if (
node.marks &&
node.marks.find(mark => mark.type.name === 'deletion')
) {
const deletionMark = node.marks.find(
mark => mark.type.name === 'deletion',
);
const configCheck = checkFromConfig(deletionMark, user, this.config);
if (!configCheck) return;
const deletionStep = new ReplaceStep(
map.map(Math.max(pos, from)),
map.map(Math.min(pos + node.nodeSize, to)),
Slice.empty,
);
tr.step(deletionStep);
map.appendMap(deletionStep.getMap());
} else if (
node.attrs.track &&
node.attrs.track.find(track => track.type === 'insertion')
) {
const track = node.attrs.track.filter(
track => track.type !== 'insertion',
);
tr.setNodeMarkup(
map.map(pos),
null,
Object.assign(node.attrs.track, { track }),
node.marks,
);
} else if (
node.marks &&
node.marks.find(mark => mark.type.name === 'insertion')
) {
const insertionMark = node.marks.find(
mark => mark.type.name === 'insertion',
);
// const configCheck = checkFromConfig(insertionMark, user, this.config);
// if (!configCheck) return;
tr.step(
new RemoveMarkStep(
map.map(Math.max(pos, from)),
map.map(Math.min(pos + node.nodeSize, to)),
insertionMark,
),
);
} else if (
node.marks &&
node.marks.find(mark => mark.type.name === 'format_change')
) {
const formatChangeMark = node.marks.find(
mark => mark.type.name === 'format_change',
);
// const configCheck = checkFromConfig(
// formatChangeMark,
// user,
// this.config,
// );
// if (!configCheck) return;
tr.step(
new RemoveMarkStep(
activeTrackChange.from,
activeTrackChange.to,
formatChangeMark,
),
);
} else if (
node.attrs.track &&
node.attrs.track.find(track => track.type === 'block_change')
) {
const blockChangeTrack = node.attrs.track.find(
track => track.type === 'block_change',
);
const track = node.attrs.track.filter(
track => track !== blockChangeTrack,
);
tr.setNodeMarkup(
map.map(pos),
null,
Object.assign(node.attrs.track, { track }),
node.marks,
);
}
},
);
if (tr.steps.length) dispatch(tr);
};
export default acceptTrackChange;