@manuscripts/track-changes-plugin 1.8.6 → 1.8.7-LEAN-4145.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.
- package/dist/cjs/compute/setFragmentAsInserted.js +1 -1
- package/dist/cjs/mutate/deleteAndMergeSplitNodes.js +15 -2
- package/dist/cjs/steps/trackReplaceAroundStep.js +61 -13
- package/dist/cjs/steps/trackTransaction.js +4 -3
- package/dist/cjs/utils/track-utils.js +17 -3
- package/dist/es/compute/setFragmentAsInserted.js +1 -1
- package/dist/es/mutate/deleteAndMergeSplitNodes.js +15 -2
- package/dist/es/steps/trackReplaceAroundStep.js +60 -13
- package/dist/es/steps/trackTransaction.js +4 -3
- package/dist/es/utils/track-utils.js +13 -1
- package/dist/types/mutate/deleteAndMergeSplitNodes.d.ts +3 -1
- package/dist/types/steps/trackReplaceAroundStep.d.ts +3 -2
- package/dist/types/types/step.d.ts +2 -0
- package/dist/types/types/track.d.ts +6 -0
- package/dist/types/utils/track-utils.d.ts +9 -1
- package/package.json +1 -1
|
@@ -92,7 +92,7 @@ function setFragmentAsNodeSplit($pos, newTr, inserted, attrs) {
|
|
|
92
92
|
const oldDataTracked = (0, nodeHelpers_1.getBlockInlineTrackedData)(parent) || [];
|
|
93
93
|
newTr.setNodeMarkup(parentPos, undefined, Object.assign(Object.assign({}, parent.attrs), { dataTracked: [
|
|
94
94
|
...oldDataTracked.filter((c) => c.operation !== 'reference'),
|
|
95
|
-
Object.assign({}, (0, nodeHelpers_1.addTrackIdIfDoesntExist)(trackUtils.
|
|
95
|
+
Object.assign({}, (0, nodeHelpers_1.addTrackIdIfDoesntExist)(trackUtils.createNewReferenceAttrs(Object.assign(Object.assign({}, attrs), { status: change_1.CHANGE_STATUS.pending }), referenceId))),
|
|
96
96
|
] }));
|
|
97
97
|
const splitSource = oldDataTracked.find((c) => c.operation === 'reference');
|
|
98
98
|
const dataTracked = Object.assign(Object.assign({}, trackUtils.createNewSplitAttrs(Object.assign({}, attrs))), { id: referenceId });
|
|
@@ -56,8 +56,21 @@ function deleteAndMergeSplitNodes(from, to, gap, startDoc, newTr, schema, trackA
|
|
|
56
56
|
? firstMergedNode === null || firstMergedNode === void 0 ? void 0 : firstMergedNode.mergedNodeContent
|
|
57
57
|
: lastMergedNode === null || lastMergedNode === void 0 ? void 0 : lastMergedNode.mergedNodeContent;
|
|
58
58
|
const mergeStartNode = endTokenDeleted && openStart > 0 && depth === openStart && mergeContent && mergeContent.size;
|
|
59
|
-
const mergeEndNode = startTokenDeleted && openEnd > 0 && depth === openEnd && mergeContent
|
|
60
|
-
|
|
59
|
+
const mergeEndNode = startTokenDeleted && openEnd > 0 && depth === openEnd && mergeContent;
|
|
60
|
+
const mergeEndNodeNotEmpty = mergeEndNode && mergeContent.size;
|
|
61
|
+
if (mergeEndNode && !mergeEndNodeNotEmpty && gap) {
|
|
62
|
+
if (trackUtils.stepIsLift(gap, node, to)) {
|
|
63
|
+
gap.slice.content.forEach((node, offset) => {
|
|
64
|
+
steps.push({
|
|
65
|
+
type: 'delete-node',
|
|
66
|
+
pos: gap.start + offset,
|
|
67
|
+
nodeEnd: gap.start + offset + node.nodeSize,
|
|
68
|
+
node,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (mergeStartNode || mergeEndNodeNotEmpty) {
|
|
61
74
|
steps.push({
|
|
62
75
|
type: 'merge-fragment',
|
|
63
76
|
pos,
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.trackReplaceAroundStep = void 0;
|
|
26
|
+
exports.trackReplaceAroundStep = exports.fakef = void 0;
|
|
27
27
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
28
28
|
const actions_1 = require("../actions");
|
|
29
29
|
const setFragmentAsInserted_1 = require("../compute/setFragmentAsInserted");
|
|
@@ -31,18 +31,36 @@ const deleteAndMergeSplitNodes_1 = require("../mutate/deleteAndMergeSplitNodes")
|
|
|
31
31
|
const logger_1 = require("../utils/logger");
|
|
32
32
|
const trackUtils = __importStar(require("../utils/track-utils"));
|
|
33
33
|
const track_utils_1 = require("../utils/track-utils");
|
|
34
|
-
function
|
|
34
|
+
function fakef() {
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
exports.fakef = fakef;
|
|
38
|
+
function preserveDataTrackedFromPreviousStep(newTr, step, newStep) {
|
|
39
|
+
const prevDoc = newTr.docs[newTr.docs.length - 2];
|
|
40
|
+
if (prevDoc && (step.slice.openEnd || step.slice.openStart)) {
|
|
41
|
+
prevDoc.nodesBetween(newStep.from, newStep.to, (node, pos) => {
|
|
42
|
+
newStep.slice.content.forEach((n, offset) => {
|
|
43
|
+
if (n.type === node.type && !node.isText && n.attrs.id === node.attrs.id) {
|
|
44
|
+
newTr.setNodeAttribute(newStep.from + offset, 'dataTracked', node.attrs.dataTracked);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return newTr;
|
|
50
|
+
}
|
|
51
|
+
function trackReplaceAroundStep(step, oldState, tr, newTr, attrs, currentStepDoc, trContext) {
|
|
35
52
|
logger_1.log.info('###### ReplaceAroundStep ######');
|
|
36
53
|
const { from, to, gapFrom, gapTo, insert, slice, structure, } = step;
|
|
37
54
|
const newStep = step.invert(currentStepDoc);
|
|
38
|
-
|
|
55
|
+
let stepResult = newTr.maybeStep(newStep);
|
|
39
56
|
if (stepResult.failed) {
|
|
40
57
|
logger_1.log.error(`inverting ReplaceAroundStep failed: "${stepResult.failed}"`, newStep);
|
|
41
58
|
return [];
|
|
42
59
|
}
|
|
60
|
+
preserveDataTrackedFromPreviousStep(newTr, step, newStep);
|
|
43
61
|
const gap = currentStepDoc.slice(gapFrom, gapTo);
|
|
44
62
|
logger_1.log.info('RETAINED GAP CONTENT', gap);
|
|
45
|
-
|
|
63
|
+
let { sliceWasSplit, newSliceContent, steps: deleteSteps, } = (0, deleteAndMergeSplitNodes_1.deleteAndMergeSplitNodes)(from, to, { start: gapFrom, end: gapTo, slice: gap, insert }, newTr.doc, newTr, oldState.schema, attrs, slice);
|
|
46
64
|
let fragment;
|
|
47
65
|
if ((0, track_utils_1.isWrapStep)(step)) {
|
|
48
66
|
fragment = (0, setFragmentAsInserted_1.setFragmentAsWrapChange)(newSliceContent, attrs, oldState.schema);
|
|
@@ -50,9 +68,21 @@ function trackReplaceAroundStep(step, oldState, tr, newTr, attrs, currentStepDoc
|
|
|
50
68
|
else {
|
|
51
69
|
fragment = (0, setFragmentAsInserted_1.setFragmentAsInserted)(newSliceContent, trackUtils.createNewInsertAttrs(attrs), oldState.schema);
|
|
52
70
|
}
|
|
53
|
-
|
|
71
|
+
let steps = deleteSteps;
|
|
54
72
|
logger_1.log.info('TR: new steps after applying delete', [...newTr.steps]);
|
|
55
73
|
logger_1.log.info('DELETE STEPS: ', deleteSteps);
|
|
74
|
+
let liftStep = (0, track_utils_1.isLiftStep)(step);
|
|
75
|
+
if (liftStep) {
|
|
76
|
+
logger_1.log.info('DETECTING INIT LIFT STEP: ', step);
|
|
77
|
+
trContext.prevLiftStep = step;
|
|
78
|
+
}
|
|
79
|
+
else if (trContext.prevLiftStep && trContext.prevLiftStep.gapFrom === step.gapTo) {
|
|
80
|
+
logger_1.log.info('DETECTING CHAIN LIFT STEP');
|
|
81
|
+
trContext.prevLiftStep = step;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
trContext.prevLiftStep = undefined;
|
|
85
|
+
}
|
|
56
86
|
if (gap.size > 0 ||
|
|
57
87
|
(!structure && newSliceContent.size > 0) ||
|
|
58
88
|
tr.getMeta(actions_1.TrackChangesAction.updateMetaNode)) {
|
|
@@ -62,16 +92,34 @@ function trackReplaceAroundStep(step, oldState, tr, newTr, attrs, currentStepDoc
|
|
|
62
92
|
let insertedSlice = new prosemirror_model_1.Slice(fragment, openStart, openEnd);
|
|
63
93
|
if (gap.size > 0 || tr.getMeta(actions_1.TrackChangesAction.updateMetaNode)) {
|
|
64
94
|
logger_1.log.info('insertedSlice before inserted gap', insertedSlice);
|
|
65
|
-
|
|
95
|
+
let sliceContent = gap.content;
|
|
96
|
+
insertedSlice = insertedSlice.insertAt(insertedSlice.size === 0 ? 0 : insert, sliceContent);
|
|
66
97
|
logger_1.log.info('insertedSlice after inserted gap', insertedSlice);
|
|
67
98
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
99
|
+
if (trContext.prevLiftStep) {
|
|
100
|
+
trContext.liftFragment = trContext.liftFragment
|
|
101
|
+
? insertedSlice.content.append(trContext.liftFragment)
|
|
102
|
+
: insertedSlice.content;
|
|
103
|
+
if (tr.steps.indexOf(step) === 0) {
|
|
104
|
+
const fragmentTracked = (0, setFragmentAsInserted_1.setFragmentAsInserted)(trContext.liftFragment, trackUtils.createNewInsertAttrs(attrs), oldState.schema);
|
|
105
|
+
steps.push({
|
|
106
|
+
type: 'insert-slice',
|
|
107
|
+
from: from,
|
|
108
|
+
to: from,
|
|
109
|
+
slice: new prosemirror_model_1.Slice(fragmentTracked, 0, 0),
|
|
110
|
+
sliceWasSplit: true,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
steps.push({
|
|
116
|
+
type: 'insert-slice',
|
|
117
|
+
from: gapFrom,
|
|
118
|
+
to: gapTo,
|
|
119
|
+
slice: insertedSlice,
|
|
120
|
+
sliceWasSplit,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
75
123
|
}
|
|
76
124
|
else {
|
|
77
125
|
}
|
|
@@ -33,6 +33,7 @@ function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
33
33
|
const setsNewSelection = tr.selectionSet;
|
|
34
34
|
let iters = 0;
|
|
35
35
|
logger_1.log.info('ORIGINAL transaction', tr);
|
|
36
|
+
let trContext = {};
|
|
36
37
|
for (let i = tr.steps.length - 1; i >= 0; i--) {
|
|
37
38
|
const step = tr.steps[i];
|
|
38
39
|
logger_1.log.info('transaction step', step);
|
|
@@ -82,7 +83,7 @@ function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
else if (step instanceof prosemirror_transform_1.ReplaceAroundStep) {
|
|
85
|
-
let steps = (0, trackReplaceAroundStep_1.trackReplaceAroundStep)(step, oldState, tr, newTr, emptyAttrs, tr.docs[i]);
|
|
86
|
+
let steps = (0, trackReplaceAroundStep_1.trackReplaceAroundStep)(step, oldState, tr, newTr, emptyAttrs, tr.docs[i], trContext);
|
|
86
87
|
const deleted = steps.filter((s) => s.type !== 'insert-slice');
|
|
87
88
|
const inserted = steps.filter((s) => s.type === 'insert-slice');
|
|
88
89
|
logger_1.log.info('INSERT STEPS: ', inserted);
|
|
@@ -91,8 +92,8 @@ function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
91
92
|
const [mapping, selectionPos] = (0, processChangeSteps_1.processChangeSteps)(steps, tr.selection.from, newTr, emptyAttrs, oldState.schema);
|
|
92
93
|
}
|
|
93
94
|
else if (step instanceof prosemirror_transform_1.AttrStep) {
|
|
94
|
-
const
|
|
95
|
-
const [mapping, selectionPos] = (0, processChangeSteps_1.processChangeSteps)(
|
|
95
|
+
const changeSteps = (0, trackAttrsChange_1.default)(step, oldState, tr, newTr, emptyAttrs, tr.docs[i]);
|
|
96
|
+
const [mapping, selectionPos] = (0, processChangeSteps_1.processChangeSteps)(changeSteps, tr.selection.from, newTr, emptyAttrs, oldState.schema);
|
|
96
97
|
}
|
|
97
98
|
else if (step instanceof prosemirror_transform_1.AddMarkStep) {
|
|
98
99
|
const dataTracked = (_e = (0, nodeHelpers_1.getNodeTrackedData)(newTr.doc.nodeAt(step.from), oldState.schema)) === null || _e === void 0 ? void 0 : _e.pop();
|
|
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.isWrapStep = exports.isSplitStep = exports.createNewUpdateAttrs = exports.createNewDeleteAttrs = exports.
|
|
14
|
+
exports.stepIsLift = exports.isLiftStep = exports.isWrapStep = exports.isSplitStep = exports.createNewUpdateAttrs = exports.createNewDeleteAttrs = exports.createNewReferenceAttrs = exports.createNewSplitAttrs = exports.createNewWrapAttrs = exports.createNewInsertAttrs = void 0;
|
|
15
15
|
const change_1 = require("../types/change");
|
|
16
16
|
function createNewInsertAttrs(attrs) {
|
|
17
17
|
return Object.assign(Object.assign({}, attrs), { operation: change_1.CHANGE_OPERATION.insert });
|
|
@@ -25,10 +25,10 @@ function createNewSplitAttrs(attrs) {
|
|
|
25
25
|
return Object.assign(Object.assign({}, attrs), { operation: change_1.CHANGE_OPERATION.node_split });
|
|
26
26
|
}
|
|
27
27
|
exports.createNewSplitAttrs = createNewSplitAttrs;
|
|
28
|
-
function
|
|
28
|
+
function createNewReferenceAttrs(attrs, id) {
|
|
29
29
|
return Object.assign(Object.assign({}, attrs), { operation: change_1.CHANGE_OPERATION.reference, referenceId: id });
|
|
30
30
|
}
|
|
31
|
-
exports.
|
|
31
|
+
exports.createNewReferenceAttrs = createNewReferenceAttrs;
|
|
32
32
|
function createNewDeleteAttrs(attrs) {
|
|
33
33
|
return Object.assign(Object.assign({}, attrs), { operation: change_1.CHANGE_OPERATION.delete });
|
|
34
34
|
}
|
|
@@ -68,3 +68,17 @@ const isWrapStep = (step) => step.from === step.gapFrom &&
|
|
|
68
68
|
step.slice.openStart === 0 &&
|
|
69
69
|
step.slice.openEnd === 0;
|
|
70
70
|
exports.isWrapStep = isWrapStep;
|
|
71
|
+
const isLiftStep = (step) => {
|
|
72
|
+
if (step.from < step.gapFrom &&
|
|
73
|
+
step.to > step.gapTo &&
|
|
74
|
+
step.slice.size === 0 &&
|
|
75
|
+
step.gapTo - step.gapFrom > 0) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
};
|
|
80
|
+
exports.isLiftStep = isLiftStep;
|
|
81
|
+
function stepIsLift(gap, node, to) {
|
|
82
|
+
return gap.start < gap.end && gap.insert === 0 && gap.end === to && !node.isText;
|
|
83
|
+
}
|
|
84
|
+
exports.stepIsLift = stepIsLift;
|
|
@@ -64,7 +64,7 @@ export function setFragmentAsNodeSplit($pos, newTr, inserted, attrs) {
|
|
|
64
64
|
const oldDataTracked = getBlockInlineTrackedData(parent) || [];
|
|
65
65
|
newTr.setNodeMarkup(parentPos, undefined, Object.assign(Object.assign({}, parent.attrs), { dataTracked: [
|
|
66
66
|
...oldDataTracked.filter((c) => c.operation !== 'reference'),
|
|
67
|
-
Object.assign({}, addTrackIdIfDoesntExist(trackUtils.
|
|
67
|
+
Object.assign({}, addTrackIdIfDoesntExist(trackUtils.createNewReferenceAttrs(Object.assign(Object.assign({}, attrs), { status: CHANGE_STATUS.pending }), referenceId))),
|
|
68
68
|
] }));
|
|
69
69
|
const splitSource = oldDataTracked.find((c) => c.operation === 'reference');
|
|
70
70
|
const dataTracked = Object.assign(Object.assign({}, trackUtils.createNewSplitAttrs(Object.assign({}, attrs))), { id: referenceId });
|
|
@@ -30,8 +30,21 @@ export function deleteAndMergeSplitNodes(from, to, gap, startDoc, newTr, schema,
|
|
|
30
30
|
? firstMergedNode === null || firstMergedNode === void 0 ? void 0 : firstMergedNode.mergedNodeContent
|
|
31
31
|
: lastMergedNode === null || lastMergedNode === void 0 ? void 0 : lastMergedNode.mergedNodeContent;
|
|
32
32
|
const mergeStartNode = endTokenDeleted && openStart > 0 && depth === openStart && mergeContent && mergeContent.size;
|
|
33
|
-
const mergeEndNode = startTokenDeleted && openEnd > 0 && depth === openEnd && mergeContent
|
|
34
|
-
|
|
33
|
+
const mergeEndNode = startTokenDeleted && openEnd > 0 && depth === openEnd && mergeContent;
|
|
34
|
+
const mergeEndNodeNotEmpty = mergeEndNode && mergeContent.size;
|
|
35
|
+
if (mergeEndNode && !mergeEndNodeNotEmpty && gap) {
|
|
36
|
+
if (trackUtils.stepIsLift(gap, node, to)) {
|
|
37
|
+
gap.slice.content.forEach((node, offset) => {
|
|
38
|
+
steps.push({
|
|
39
|
+
type: 'delete-node',
|
|
40
|
+
pos: gap.start + offset,
|
|
41
|
+
nodeEnd: gap.start + offset + node.nodeSize,
|
|
42
|
+
node,
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (mergeStartNode || mergeEndNodeNotEmpty) {
|
|
35
48
|
steps.push({
|
|
36
49
|
type: 'merge-fragment',
|
|
37
50
|
pos,
|
|
@@ -4,19 +4,36 @@ import { setFragmentAsInserted, setFragmentAsWrapChange } from '../compute/setFr
|
|
|
4
4
|
import { deleteAndMergeSplitNodes } from '../mutate/deleteAndMergeSplitNodes';
|
|
5
5
|
import { log } from '../utils/logger';
|
|
6
6
|
import * as trackUtils from '../utils/track-utils';
|
|
7
|
-
import { isWrapStep } from '../utils/track-utils';
|
|
8
|
-
export function
|
|
7
|
+
import { isLiftStep, isWrapStep } from '../utils/track-utils';
|
|
8
|
+
export function fakef() {
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
function preserveDataTrackedFromPreviousStep(newTr, step, newStep) {
|
|
12
|
+
const prevDoc = newTr.docs[newTr.docs.length - 2];
|
|
13
|
+
if (prevDoc && (step.slice.openEnd || step.slice.openStart)) {
|
|
14
|
+
prevDoc.nodesBetween(newStep.from, newStep.to, (node, pos) => {
|
|
15
|
+
newStep.slice.content.forEach((n, offset) => {
|
|
16
|
+
if (n.type === node.type && !node.isText && n.attrs.id === node.attrs.id) {
|
|
17
|
+
newTr.setNodeAttribute(newStep.from + offset, 'dataTracked', node.attrs.dataTracked);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return newTr;
|
|
23
|
+
}
|
|
24
|
+
export function trackReplaceAroundStep(step, oldState, tr, newTr, attrs, currentStepDoc, trContext) {
|
|
9
25
|
log.info('###### ReplaceAroundStep ######');
|
|
10
26
|
const { from, to, gapFrom, gapTo, insert, slice, structure, } = step;
|
|
11
27
|
const newStep = step.invert(currentStepDoc);
|
|
12
|
-
|
|
28
|
+
let stepResult = newTr.maybeStep(newStep);
|
|
13
29
|
if (stepResult.failed) {
|
|
14
30
|
log.error(`inverting ReplaceAroundStep failed: "${stepResult.failed}"`, newStep);
|
|
15
31
|
return [];
|
|
16
32
|
}
|
|
33
|
+
preserveDataTrackedFromPreviousStep(newTr, step, newStep);
|
|
17
34
|
const gap = currentStepDoc.slice(gapFrom, gapTo);
|
|
18
35
|
log.info('RETAINED GAP CONTENT', gap);
|
|
19
|
-
|
|
36
|
+
let { sliceWasSplit, newSliceContent, steps: deleteSteps, } = deleteAndMergeSplitNodes(from, to, { start: gapFrom, end: gapTo, slice: gap, insert }, newTr.doc, newTr, oldState.schema, attrs, slice);
|
|
20
37
|
let fragment;
|
|
21
38
|
if (isWrapStep(step)) {
|
|
22
39
|
fragment = setFragmentAsWrapChange(newSliceContent, attrs, oldState.schema);
|
|
@@ -24,9 +41,21 @@ export function trackReplaceAroundStep(step, oldState, tr, newTr, attrs, current
|
|
|
24
41
|
else {
|
|
25
42
|
fragment = setFragmentAsInserted(newSliceContent, trackUtils.createNewInsertAttrs(attrs), oldState.schema);
|
|
26
43
|
}
|
|
27
|
-
|
|
44
|
+
let steps = deleteSteps;
|
|
28
45
|
log.info('TR: new steps after applying delete', [...newTr.steps]);
|
|
29
46
|
log.info('DELETE STEPS: ', deleteSteps);
|
|
47
|
+
let liftStep = isLiftStep(step);
|
|
48
|
+
if (liftStep) {
|
|
49
|
+
log.info('DETECTING INIT LIFT STEP: ', step);
|
|
50
|
+
trContext.prevLiftStep = step;
|
|
51
|
+
}
|
|
52
|
+
else if (trContext.prevLiftStep && trContext.prevLiftStep.gapFrom === step.gapTo) {
|
|
53
|
+
log.info('DETECTING CHAIN LIFT STEP');
|
|
54
|
+
trContext.prevLiftStep = step;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
trContext.prevLiftStep = undefined;
|
|
58
|
+
}
|
|
30
59
|
if (gap.size > 0 ||
|
|
31
60
|
(!structure && newSliceContent.size > 0) ||
|
|
32
61
|
tr.getMeta(TrackChangesAction.updateMetaNode)) {
|
|
@@ -36,16 +65,34 @@ export function trackReplaceAroundStep(step, oldState, tr, newTr, attrs, current
|
|
|
36
65
|
let insertedSlice = new Slice(fragment, openStart, openEnd);
|
|
37
66
|
if (gap.size > 0 || tr.getMeta(TrackChangesAction.updateMetaNode)) {
|
|
38
67
|
log.info('insertedSlice before inserted gap', insertedSlice);
|
|
39
|
-
|
|
68
|
+
let sliceContent = gap.content;
|
|
69
|
+
insertedSlice = insertedSlice.insertAt(insertedSlice.size === 0 ? 0 : insert, sliceContent);
|
|
40
70
|
log.info('insertedSlice after inserted gap', insertedSlice);
|
|
41
71
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
if (trContext.prevLiftStep) {
|
|
73
|
+
trContext.liftFragment = trContext.liftFragment
|
|
74
|
+
? insertedSlice.content.append(trContext.liftFragment)
|
|
75
|
+
: insertedSlice.content;
|
|
76
|
+
if (tr.steps.indexOf(step) === 0) {
|
|
77
|
+
const fragmentTracked = setFragmentAsInserted(trContext.liftFragment, trackUtils.createNewInsertAttrs(attrs), oldState.schema);
|
|
78
|
+
steps.push({
|
|
79
|
+
type: 'insert-slice',
|
|
80
|
+
from: from,
|
|
81
|
+
to: from,
|
|
82
|
+
slice: new Slice(fragmentTracked, 0, 0),
|
|
83
|
+
sliceWasSplit: true,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
steps.push({
|
|
89
|
+
type: 'insert-slice',
|
|
90
|
+
from: gapFrom,
|
|
91
|
+
to: gapTo,
|
|
92
|
+
slice: insertedSlice,
|
|
93
|
+
sliceWasSplit,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
49
96
|
}
|
|
50
97
|
else {
|
|
51
98
|
}
|
|
@@ -27,6 +27,7 @@ export function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
27
27
|
const setsNewSelection = tr.selectionSet;
|
|
28
28
|
let iters = 0;
|
|
29
29
|
log.info('ORIGINAL transaction', tr);
|
|
30
|
+
let trContext = {};
|
|
30
31
|
for (let i = tr.steps.length - 1; i >= 0; i--) {
|
|
31
32
|
const step = tr.steps[i];
|
|
32
33
|
log.info('transaction step', step);
|
|
@@ -76,7 +77,7 @@ export function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
else if (step instanceof ReplaceAroundStep) {
|
|
79
|
-
let steps = trackReplaceAroundStep(step, oldState, tr, newTr, emptyAttrs, tr.docs[i]);
|
|
80
|
+
let steps = trackReplaceAroundStep(step, oldState, tr, newTr, emptyAttrs, tr.docs[i], trContext);
|
|
80
81
|
const deleted = steps.filter((s) => s.type !== 'insert-slice');
|
|
81
82
|
const inserted = steps.filter((s) => s.type === 'insert-slice');
|
|
82
83
|
log.info('INSERT STEPS: ', inserted);
|
|
@@ -85,8 +86,8 @@ export function trackTransaction(tr, oldState, newTr, authorID) {
|
|
|
85
86
|
const [mapping, selectionPos] = processChangeSteps(steps, tr.selection.from, newTr, emptyAttrs, oldState.schema);
|
|
86
87
|
}
|
|
87
88
|
else if (step instanceof AttrStep) {
|
|
88
|
-
const
|
|
89
|
-
const [mapping, selectionPos] = processChangeSteps(
|
|
89
|
+
const changeSteps = trackAttrsChange(step, oldState, tr, newTr, emptyAttrs, tr.docs[i]);
|
|
90
|
+
const [mapping, selectionPos] = processChangeSteps(changeSteps, tr.selection.from, newTr, emptyAttrs, oldState.schema);
|
|
90
91
|
}
|
|
91
92
|
else if (step instanceof AddMarkStep) {
|
|
92
93
|
const dataTracked = (_e = getNodeTrackedData(newTr.doc.nodeAt(step.from), oldState.schema)) === null || _e === void 0 ? void 0 : _e.pop();
|
|
@@ -19,7 +19,7 @@ export function createNewWrapAttrs(attrs) {
|
|
|
19
19
|
export function createNewSplitAttrs(attrs) {
|
|
20
20
|
return Object.assign(Object.assign({}, attrs), { operation: CHANGE_OPERATION.node_split });
|
|
21
21
|
}
|
|
22
|
-
export function
|
|
22
|
+
export function createNewReferenceAttrs(attrs, id) {
|
|
23
23
|
return Object.assign(Object.assign({}, attrs), { operation: CHANGE_OPERATION.reference, referenceId: id });
|
|
24
24
|
}
|
|
25
25
|
export function createNewDeleteAttrs(attrs) {
|
|
@@ -57,3 +57,15 @@ export const isWrapStep = (step) => step.from === step.gapFrom &&
|
|
|
57
57
|
step.to === step.gapTo &&
|
|
58
58
|
step.slice.openStart === 0 &&
|
|
59
59
|
step.slice.openEnd === 0;
|
|
60
|
+
export const isLiftStep = (step) => {
|
|
61
|
+
if (step.from < step.gapFrom &&
|
|
62
|
+
step.to > step.gapTo &&
|
|
63
|
+
step.slice.size === 0 &&
|
|
64
|
+
step.gapTo - step.gapFrom > 0) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
};
|
|
69
|
+
export function stepIsLift(gap, node, to) {
|
|
70
|
+
return gap.start < gap.end && gap.insert === 0 && gap.end === to && !node.isText;
|
|
71
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fragment, Node as PMNode, Schema } from 'prosemirror-model';
|
|
1
|
+
import { Fragment, Node as PMNode, Schema, Slice } from 'prosemirror-model';
|
|
2
2
|
import type { Transaction } from 'prosemirror-state';
|
|
3
3
|
import { ExposedSlice } from '../types/pm';
|
|
4
4
|
import { ChangeStep } from '../types/step';
|
|
@@ -6,6 +6,8 @@ import { NewEmptyAttrs } from '../types/track';
|
|
|
6
6
|
export declare function deleteAndMergeSplitNodes(from: number, to: number, gap: {
|
|
7
7
|
start: number;
|
|
8
8
|
end: number;
|
|
9
|
+
slice: Slice;
|
|
10
|
+
insert: number;
|
|
9
11
|
} | undefined, startDoc: PMNode, newTr: Transaction, schema: Schema, trackAttrs: NewEmptyAttrs, insertSlice: ExposedSlice): {
|
|
10
12
|
sliceWasSplit: boolean;
|
|
11
13
|
newSliceContent: Fragment;
|
|
@@ -2,5 +2,6 @@ import { Node as PMNode } from 'prosemirror-model';
|
|
|
2
2
|
import type { EditorState, Transaction } from 'prosemirror-state';
|
|
3
3
|
import { ReplaceAroundStep } from 'prosemirror-transform';
|
|
4
4
|
import { ChangeStep } from '../types/step';
|
|
5
|
-
import { NewEmptyAttrs } from '../types/track';
|
|
6
|
-
export declare function
|
|
5
|
+
import { NewEmptyAttrs, TrTrackingContext } from '../types/track';
|
|
6
|
+
export declare function fakef(): number;
|
|
7
|
+
export declare function trackReplaceAroundStep(step: ReplaceAroundStep, oldState: EditorState, tr: Transaction, newTr: Transaction, attrs: NewEmptyAttrs, currentStepDoc: PMNode, trContext: TrTrackingContext): ChangeStep[];
|
|
@@ -5,6 +5,7 @@ export interface DeleteNodeStep {
|
|
|
5
5
|
nodeEnd: number;
|
|
6
6
|
type: 'delete-node';
|
|
7
7
|
node: PMNode;
|
|
8
|
+
ref?: string;
|
|
8
9
|
}
|
|
9
10
|
export interface DeleteTextStep {
|
|
10
11
|
pos: number;
|
|
@@ -12,6 +13,7 @@ export interface DeleteTextStep {
|
|
|
12
13
|
to: number;
|
|
13
14
|
type: 'delete-text';
|
|
14
15
|
node: PMNode;
|
|
16
|
+
ref?: string;
|
|
15
17
|
}
|
|
16
18
|
export interface MergeFragmentStep {
|
|
17
19
|
pos: number;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Fragment } from 'prosemirror-model';
|
|
1
2
|
import type { PluginKey } from 'prosemirror-state';
|
|
3
|
+
import { ReplaceAroundStep } from 'prosemirror-transform';
|
|
2
4
|
import { ChangeSet } from '../ChangeSet';
|
|
3
5
|
import { CHANGE_OPERATION, TrackedAttrs } from './change';
|
|
4
6
|
export interface TrackChangesOptions {
|
|
@@ -36,3 +38,7 @@ export declare enum TrackChangesStatus {
|
|
|
36
38
|
viewSnapshots = "view-snapshots",
|
|
37
39
|
disabled = "disabled"
|
|
38
40
|
}
|
|
41
|
+
export type TrTrackingContext = {
|
|
42
|
+
prevLiftStep?: ReplaceAroundStep;
|
|
43
|
+
liftFragment?: Fragment;
|
|
44
|
+
};
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
import { Node as PMNode, Slice } from 'prosemirror-model';
|
|
1
2
|
import { Selection } from 'prosemirror-state';
|
|
2
3
|
import { ReplaceAroundStep, ReplaceStep } from 'prosemirror-transform';
|
|
3
4
|
import { NewDeleteAttrs, NewEmptyAttrs, NewInsertAttrs, NewReferenceAttrs, NewSplitNodeAttrs, NewUpdateAttrs } from '../types/track';
|
|
4
5
|
export declare function createNewInsertAttrs(attrs: NewEmptyAttrs): NewInsertAttrs;
|
|
5
6
|
export declare function createNewWrapAttrs(attrs: NewEmptyAttrs): NewInsertAttrs;
|
|
6
7
|
export declare function createNewSplitAttrs(attrs: NewEmptyAttrs): NewSplitNodeAttrs;
|
|
7
|
-
export declare function
|
|
8
|
+
export declare function createNewReferenceAttrs(attrs: NewEmptyAttrs, id: string): NewReferenceAttrs;
|
|
8
9
|
export declare function createNewDeleteAttrs(attrs: NewEmptyAttrs): NewDeleteAttrs;
|
|
9
10
|
export declare function createNewUpdateAttrs(attrs: NewEmptyAttrs, oldAttrs: Record<string, any>): NewUpdateAttrs;
|
|
10
11
|
export declare const isSplitStep: (step: ReplaceStep, selection: Selection, uiEvent: string) => boolean;
|
|
11
12
|
export declare const isWrapStep: (step: ReplaceAroundStep) => boolean;
|
|
13
|
+
export declare const isLiftStep: (step: ReplaceAroundStep) => boolean;
|
|
14
|
+
export declare function stepIsLift(gap: {
|
|
15
|
+
start: number;
|
|
16
|
+
end: number;
|
|
17
|
+
slice: Slice;
|
|
18
|
+
insert: number;
|
|
19
|
+
}, node: PMNode, to: number): boolean;
|
package/package.json
CHANGED