@manuscripts/track-changes-plugin 1.7.10 → 1.7.11
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/steps/trackTransaction.js +12 -2
- package/dist/cjs/utils/mapChangeStep.js +39 -0
- package/dist/es/steps/trackTransaction.js +13 -3
- package/dist/es/utils/mapChangeStep.js +35 -0
- package/dist/types/steps/trackTransaction.d.ts +1 -1
- package/dist/types/utils/mapChangeStep.d.ts +18 -0
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ const diffChangeSteps_1 = require("../change-steps/diffChangeSteps");
|
|
|
7
7
|
const processChangeSteps_1 = require("../change-steps/processChangeSteps");
|
|
8
8
|
const change_1 = require("../types/change");
|
|
9
9
|
const logger_1 = require("../utils/logger");
|
|
10
|
+
const mapChangeStep_1 = require("../utils/mapChangeStep");
|
|
10
11
|
const trackReplaceAroundStep_1 = require("./trackReplaceAroundStep");
|
|
11
12
|
const trackReplaceStep_1 = require("./trackReplaceStep");
|
|
12
13
|
const getSelectionStaticConstructor = (sel) => Object.getPrototypeOf(sel).constructor;
|
|
@@ -22,6 +23,7 @@ function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
22
23
|
status: change_1.CHANGE_STATUS.pending,
|
|
23
24
|
};
|
|
24
25
|
const wasNodeSelection = tr.selection instanceof prosemirror_state_1.NodeSelection;
|
|
26
|
+
const setsNewSelection = tr.selectionSet;
|
|
25
27
|
let iters = 0;
|
|
26
28
|
logger_1.log.info('ORIGINAL transaction', tr);
|
|
27
29
|
for (let i = tr.steps.length - 1; i >= 0; i--) {
|
|
@@ -43,7 +45,9 @@ function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
43
45
|
if (((_b = (_a = slice === null || slice === void 0 ? void 0 : slice.content) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.length) === 1 && isHighlightMarkerNode(slice.content.content[0])) {
|
|
44
46
|
continue;
|
|
45
47
|
}
|
|
46
|
-
const
|
|
48
|
+
const invertedStep = step.invert(tr.docs[i]);
|
|
49
|
+
const thisStepMapping = tr.mapping.slice(i + 1);
|
|
50
|
+
const newStep = new prosemirror_transform_1.ReplaceStep(thisStepMapping.map(invertedStep.from), thisStepMapping.map(invertedStep.to), invertedStep.slice);
|
|
47
51
|
const stepResult = newTr.maybeStep(newStep);
|
|
48
52
|
let [steps, startPos] = (0, trackReplaceStep_1.trackReplaceStep)(step, oldState, newTr, emptyAttrs, stepResult, tr.docs[i]);
|
|
49
53
|
if (steps.length === 1) {
|
|
@@ -52,13 +56,15 @@ function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
52
56
|
continue;
|
|
53
57
|
}
|
|
54
58
|
}
|
|
59
|
+
startPos = thisStepMapping.map(startPos);
|
|
60
|
+
steps = (0, mapChangeStep_1.mapChangeSteps)(steps, thisStepMapping);
|
|
55
61
|
logger_1.log.info('CHANGES: ', steps);
|
|
56
62
|
const deleted = steps.filter((s) => s.type !== 'insert-slice');
|
|
57
63
|
const inserted = steps.filter((s) => s.type === 'insert-slice');
|
|
58
64
|
steps = (0, diffChangeSteps_1.diffChangeSteps)(deleted, inserted);
|
|
59
65
|
logger_1.log.info('DIFFED STEPS: ', steps);
|
|
60
66
|
const [mapping, selectionPos] = (0, processChangeSteps_1.processChangeSteps)(steps, startPos || tr.selection.head, newTr, emptyAttrs, oldState.schema);
|
|
61
|
-
if (!wasNodeSelection) {
|
|
67
|
+
if (!wasNodeSelection && !setsNewSelection) {
|
|
62
68
|
const sel = getSelectionStaticConstructor(tr.selection);
|
|
63
69
|
const near = sel.near(newTr.doc.resolve(selectionPos), -1);
|
|
64
70
|
newTr.setSelection(near);
|
|
@@ -76,6 +82,10 @@ function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
76
82
|
tr.getMeta('inputType') && newTr.setMeta('inputType', tr.getMeta('inputType'));
|
|
77
83
|
tr.getMeta('uiEvent') && newTr.setMeta('uiEvent', tr.getMeta('uiEvent'));
|
|
78
84
|
}
|
|
85
|
+
if (setsNewSelection && tr.selection instanceof prosemirror_state_1.TextSelection) {
|
|
86
|
+
const newPos = newTr.doc.resolve(tr.selection.from);
|
|
87
|
+
newTr.setSelection(new prosemirror_state_1.TextSelection(newPos));
|
|
88
|
+
}
|
|
79
89
|
if (wasNodeSelection) {
|
|
80
90
|
console.log('%c Getting into node select! ', 'background: #222; color: #bada55');
|
|
81
91
|
const mappedPos = newTr.mapping.map(tr.selection.from, -1);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2023 Atypon Systems LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.mapChangeSteps = void 0;
|
|
19
|
+
function mapChangeSteps(steps, mapping) {
|
|
20
|
+
steps.forEach((step) => {
|
|
21
|
+
if ('from' in step) {
|
|
22
|
+
step.from = mapping.map(step.from);
|
|
23
|
+
}
|
|
24
|
+
if ('to' in step) {
|
|
25
|
+
step.to = mapping.map(step.to);
|
|
26
|
+
}
|
|
27
|
+
if ('pos' in step) {
|
|
28
|
+
step.pos = mapping.map(step.pos);
|
|
29
|
+
}
|
|
30
|
+
if ('nodeEnd' in step) {
|
|
31
|
+
step.nodeEnd = mapping.map(step.nodeEnd);
|
|
32
|
+
}
|
|
33
|
+
if ('mergePos' in step) {
|
|
34
|
+
step.mergePos = mapping.map(step.mergePos);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return steps;
|
|
38
|
+
}
|
|
39
|
+
exports.mapChangeSteps = mapChangeSteps;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { NodeSelection as NodeSelectionClass } from 'prosemirror-state';
|
|
1
|
+
import { NodeSelection as NodeSelectionClass, TextSelection, } from 'prosemirror-state';
|
|
2
2
|
import { ReplaceAroundStep, ReplaceStep } from 'prosemirror-transform';
|
|
3
3
|
import { diffChangeSteps } from '../change-steps/diffChangeSteps';
|
|
4
4
|
import { processChangeSteps } from '../change-steps/processChangeSteps';
|
|
5
5
|
import { CHANGE_STATUS } from '../types/change';
|
|
6
6
|
import { log } from '../utils/logger';
|
|
7
|
+
import { mapChangeSteps } from '../utils/mapChangeStep';
|
|
7
8
|
import { trackReplaceAroundStep } from './trackReplaceAroundStep';
|
|
8
9
|
import { trackReplaceStep } from './trackReplaceStep';
|
|
9
10
|
const getSelectionStaticConstructor = (sel) => Object.getPrototypeOf(sel).constructor;
|
|
@@ -19,6 +20,7 @@ export function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
19
20
|
status: CHANGE_STATUS.pending,
|
|
20
21
|
};
|
|
21
22
|
const wasNodeSelection = tr.selection instanceof NodeSelectionClass;
|
|
23
|
+
const setsNewSelection = tr.selectionSet;
|
|
22
24
|
let iters = 0;
|
|
23
25
|
log.info('ORIGINAL transaction', tr);
|
|
24
26
|
for (let i = tr.steps.length - 1; i >= 0; i--) {
|
|
@@ -40,7 +42,9 @@ export function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
40
42
|
if (((_b = (_a = slice === null || slice === void 0 ? void 0 : slice.content) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.length) === 1 && isHighlightMarkerNode(slice.content.content[0])) {
|
|
41
43
|
continue;
|
|
42
44
|
}
|
|
43
|
-
const
|
|
45
|
+
const invertedStep = step.invert(tr.docs[i]);
|
|
46
|
+
const thisStepMapping = tr.mapping.slice(i + 1);
|
|
47
|
+
const newStep = new ReplaceStep(thisStepMapping.map(invertedStep.from), thisStepMapping.map(invertedStep.to), invertedStep.slice);
|
|
44
48
|
const stepResult = newTr.maybeStep(newStep);
|
|
45
49
|
let [steps, startPos] = trackReplaceStep(step, oldState, newTr, emptyAttrs, stepResult, tr.docs[i]);
|
|
46
50
|
if (steps.length === 1) {
|
|
@@ -49,13 +53,15 @@ export function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
49
53
|
continue;
|
|
50
54
|
}
|
|
51
55
|
}
|
|
56
|
+
startPos = thisStepMapping.map(startPos);
|
|
57
|
+
steps = mapChangeSteps(steps, thisStepMapping);
|
|
52
58
|
log.info('CHANGES: ', steps);
|
|
53
59
|
const deleted = steps.filter((s) => s.type !== 'insert-slice');
|
|
54
60
|
const inserted = steps.filter((s) => s.type === 'insert-slice');
|
|
55
61
|
steps = diffChangeSteps(deleted, inserted);
|
|
56
62
|
log.info('DIFFED STEPS: ', steps);
|
|
57
63
|
const [mapping, selectionPos] = processChangeSteps(steps, startPos || tr.selection.head, newTr, emptyAttrs, oldState.schema);
|
|
58
|
-
if (!wasNodeSelection) {
|
|
64
|
+
if (!wasNodeSelection && !setsNewSelection) {
|
|
59
65
|
const sel = getSelectionStaticConstructor(tr.selection);
|
|
60
66
|
const near = sel.near(newTr.doc.resolve(selectionPos), -1);
|
|
61
67
|
newTr.setSelection(near);
|
|
@@ -73,6 +79,10 @@ export function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
73
79
|
tr.getMeta('inputType') && newTr.setMeta('inputType', tr.getMeta('inputType'));
|
|
74
80
|
tr.getMeta('uiEvent') && newTr.setMeta('uiEvent', tr.getMeta('uiEvent'));
|
|
75
81
|
}
|
|
82
|
+
if (setsNewSelection && tr.selection instanceof TextSelection) {
|
|
83
|
+
const newPos = newTr.doc.resolve(tr.selection.from);
|
|
84
|
+
newTr.setSelection(new TextSelection(newPos));
|
|
85
|
+
}
|
|
76
86
|
if (wasNodeSelection) {
|
|
77
87
|
console.log('%c Getting into node select! ', 'background: #222; color: #bada55');
|
|
78
88
|
const mappedPos = newTr.mapping.map(tr.selection.from, -1);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2023 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export function mapChangeSteps(steps, mapping) {
|
|
17
|
+
steps.forEach((step) => {
|
|
18
|
+
if ('from' in step) {
|
|
19
|
+
step.from = mapping.map(step.from);
|
|
20
|
+
}
|
|
21
|
+
if ('to' in step) {
|
|
22
|
+
step.to = mapping.map(step.to);
|
|
23
|
+
}
|
|
24
|
+
if ('pos' in step) {
|
|
25
|
+
step.pos = mapping.map(step.pos);
|
|
26
|
+
}
|
|
27
|
+
if ('nodeEnd' in step) {
|
|
28
|
+
step.nodeEnd = mapping.map(step.nodeEnd);
|
|
29
|
+
}
|
|
30
|
+
if ('mergePos' in step) {
|
|
31
|
+
step.mergePos = mapping.map(step.mergePos);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return steps;
|
|
35
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EditorState, Transaction } from 'prosemirror-state';
|
|
2
2
|
export declare function trackTransaction(tr: Transaction, oldState: EditorState, newTr: Transaction, authorID: string): Transaction;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2023 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { Mapping } from 'prosemirror-transform';
|
|
17
|
+
import { ChangeStep } from '../types/step';
|
|
18
|
+
export declare function mapChangeSteps(steps: ChangeStep[], mapping: Mapping): ChangeStep[];
|
package/package.json
CHANGED