@manuscripts/track-changes-plugin 2.0.12 → 2.1.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.
Files changed (43) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/ChangeSet.js +27 -8
  3. package/dist/cjs/changes/applyChanges.js +27 -13
  4. package/dist/cjs/changes/findChanges.js +16 -0
  5. package/dist/cjs/changes/revertChange.js +2 -2
  6. package/dist/cjs/changes/updateChangeAttrs.js +27 -0
  7. package/dist/cjs/compute/nodeHelpers.js +11 -0
  8. package/dist/cjs/mutate/deleteAndMergeSplitNodes.js +2 -1
  9. package/dist/cjs/mutate/deleteNode.js +4 -4
  10. package/dist/cjs/mutate/dropStructureChange.js +29 -4
  11. package/dist/cjs/steps/trackMarkSteps.js +140 -0
  12. package/dist/cjs/steps/trackReplaceAroundStep.js +3 -3
  13. package/dist/cjs/steps/trackReplaceStep.js +3 -3
  14. package/dist/cjs/steps/trackTransaction.js +14 -2
  15. package/dist/cjs/steps/utils.js +70 -0
  16. package/dist/cjs/utils/track-utils.js +28 -51
  17. package/dist/cjs/utils/uuidv4.js +3 -0
  18. package/dist/es/ChangeSet.js +27 -8
  19. package/dist/es/changes/applyChanges.js +28 -13
  20. package/dist/es/changes/findChanges.js +17 -1
  21. package/dist/es/changes/revertChange.js +2 -2
  22. package/dist/es/changes/updateChangeAttrs.js +27 -0
  23. package/dist/es/compute/nodeHelpers.js +10 -0
  24. package/dist/es/mutate/deleteAndMergeSplitNodes.js +2 -1
  25. package/dist/es/mutate/deleteNode.js +2 -2
  26. package/dist/es/mutate/dropStructureChange.js +29 -4
  27. package/dist/es/steps/trackMarkSteps.js +134 -0
  28. package/dist/es/steps/trackReplaceAroundStep.js +1 -1
  29. package/dist/es/steps/trackReplaceStep.js +1 -1
  30. package/dist/es/steps/trackTransaction.js +14 -2
  31. package/dist/es/steps/utils.js +62 -0
  32. package/dist/es/utils/track-utils.js +24 -45
  33. package/dist/es/utils/uuidv4.js +3 -0
  34. package/dist/types/ChangeSet.d.ts +5 -2
  35. package/dist/types/changes/applyChanges.d.ts +1 -2
  36. package/dist/types/compute/nodeHelpers.d.ts +2 -1
  37. package/dist/types/mutate/deleteNode.d.ts +1 -1
  38. package/dist/types/mutate/dropStructureChange.d.ts +1 -1
  39. package/dist/types/steps/trackMarkSteps.d.ts +8 -0
  40. package/dist/types/steps/utils.d.ts +28 -0
  41. package/dist/types/types/change.d.ts +4 -1
  42. package/dist/types/utils/track-utils.d.ts +7 -14
  43. package/package.json +1 -1
@@ -0,0 +1,134 @@
1
+ import { AddMarkStep, AddNodeMarkStep, RemoveMarkStep } from 'prosemirror-transform';
2
+ import { CHANGE_OPERATION } from '../types/change';
3
+ import { createNewDeleteAttrs, createNewInsertAttrs, isValidTrackableMark } from '../utils/track-utils';
4
+ import { uuidv4 } from '../utils/uuidv4';
5
+ function markHasOp(mark, operation) {
6
+ if (mark.attrs.dataTracked && Array.isArray(mark.attrs.dataTracked)) {
7
+ const dtAttrs = mark.attrs.dataTracked;
8
+ return dtAttrs.some((at) => at.operation === operation);
9
+ }
10
+ }
11
+ export function trackRemoveMarkStep(step, emptyAttrs, newTr, doc) {
12
+ if (isValidTrackableMark(step.mark)) {
13
+ const markName = step.mark.type.name;
14
+ const markSource = step.mark.type.schema.marks[step.mark.type.name];
15
+ let sameMark = null;
16
+ const targetNode = doc.nodeAt(step.from);
17
+ if (targetNode) {
18
+ let targetNodePos = -1;
19
+ doc.descendants((node, pos) => {
20
+ if (node === targetNode) {
21
+ targetNodePos = pos;
22
+ }
23
+ if (targetNodePos >= 0) {
24
+ return false;
25
+ }
26
+ });
27
+ const parentsSameMark = targetNode.marks.find((mark) => {
28
+ var _a;
29
+ if (mark.type.name === markName && ((_a = mark.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.length)) {
30
+ return mark;
31
+ }
32
+ });
33
+ const nodeEnd = targetNodePos + targetNode.nodeSize;
34
+ if (parentsSameMark && step.from <= nodeEnd && step.to <= nodeEnd) {
35
+ sameMark = parentsSameMark;
36
+ }
37
+ }
38
+ const newDataTracked = createNewDeleteAttrs(emptyAttrs);
39
+ const newMark = markSource.create({
40
+ dataTracked: [Object.assign(Object.assign({}, newDataTracked), { id: uuidv4() })],
41
+ });
42
+ let newStep = new AddMarkStep(step.from, step.to, newMark);
43
+ if (sameMark) {
44
+ if (markHasOp(step.mark, CHANGE_OPERATION.delete)) {
45
+ newStep = new AddMarkStep(step.from, step.to, markSource.create({
46
+ dataTracked: [],
47
+ }));
48
+ }
49
+ if (markHasOp(step.mark, CHANGE_OPERATION.insert)) {
50
+ newStep = new RemoveMarkStep(step.from, step.to, step.mark);
51
+ }
52
+ }
53
+ try {
54
+ newTr.step(newStep);
55
+ }
56
+ catch (e) {
57
+ console.error('Unable to record a RemoveMarkStep with error: ' + e);
58
+ }
59
+ }
60
+ }
61
+ export function trackRemoveNodeMarkStep(step, emptyAttrs, newTr, doc) {
62
+ if (isValidTrackableMark(step.mark)) {
63
+ const markName = step.mark.type.name;
64
+ const markSource = step.mark.type.schema.marks[markName];
65
+ let sameMark = null;
66
+ const targetNode = doc.nodeAt(step.pos);
67
+ if (targetNode) {
68
+ targetNode.marks.find((mark) => {
69
+ var _a;
70
+ if (mark.type.name === markName && ((_a = mark.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.length)) {
71
+ sameMark = mark;
72
+ }
73
+ });
74
+ }
75
+ const newDataTracked = createNewDeleteAttrs(emptyAttrs);
76
+ const newMark = markSource.create({
77
+ dataTracked: [Object.assign(Object.assign({}, newDataTracked), { id: uuidv4() })],
78
+ });
79
+ let newStep = new AddNodeMarkStep(step.pos, newMark);
80
+ if (sameMark) {
81
+ if (markHasOp(step.mark, CHANGE_OPERATION.delete)) {
82
+ newStep = new AddNodeMarkStep(step.pos, markSource.create({
83
+ dataTracked: [],
84
+ }));
85
+ }
86
+ if (markHasOp(step.mark, CHANGE_OPERATION.insert)) {
87
+ newStep = new AddNodeMarkStep(step.pos, step.mark);
88
+ }
89
+ }
90
+ try {
91
+ newTr.step(newStep);
92
+ }
93
+ catch (e) {
94
+ console.error('Unable to record a RemoveNodeMarkStep with error: ' + e);
95
+ }
96
+ }
97
+ }
98
+ export function trackAddMarkStep(step, emptyAttrs, newTr, doc) {
99
+ if (isValidTrackableMark(step.mark)) {
100
+ const markName = step.mark.type.name;
101
+ const markSource = step.mark.type.schema.marks[markName];
102
+ const newDataTracked = createNewInsertAttrs(emptyAttrs);
103
+ const newMark = markSource.create({
104
+ dataTracked: [Object.assign(Object.assign({}, newDataTracked), { id: uuidv4() })],
105
+ });
106
+ const newStep = new AddMarkStep(step.from, step.to, newMark);
107
+ try {
108
+ const inverted = step.invert();
109
+ newTr.step(inverted);
110
+ newTr.step(newStep);
111
+ }
112
+ catch (e) {
113
+ console.error('Unable to record a remove node mark step: ' + e);
114
+ }
115
+ }
116
+ }
117
+ export function trackAddNodeMarkStep(step, emptyAttrs, newTr, stepDoc) {
118
+ if (isValidTrackableMark(step.mark)) {
119
+ const newDataTracked = createNewInsertAttrs(emptyAttrs);
120
+ const markSource = step.mark.type.schema.marks[step.mark.type.name];
121
+ const newMark = markSource.create({
122
+ dataTracked: [Object.assign(Object.assign({}, newDataTracked), { id: uuidv4() })],
123
+ });
124
+ const newStep = new AddNodeMarkStep(step.pos, newMark);
125
+ try {
126
+ const inverted = step.invert(stepDoc);
127
+ newTr.step(inverted);
128
+ newTr.step(newStep);
129
+ }
130
+ catch (e) {
131
+ console.error('Unable to record an AddNodeMarkStep with error: ' + e);
132
+ }
133
+ }
134
+ }
@@ -4,7 +4,7 @@ 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 { isLiftStep, isWrapStep } from '../utils/track-utils';
7
+ import { isLiftStep, isWrapStep } from './utils';
8
8
  function preserveDataTrackedFromPreviousStep(newTr, step, newStep) {
9
9
  const prevDoc = newTr.docs[newTr.docs.length - 2];
10
10
  if (prevDoc && (step.slice.openEnd || step.slice.openStart)) {
@@ -5,7 +5,7 @@ import { deleteAndMergeSplitNodes } from '../mutate/deleteAndMergeSplitNodes';
5
5
  import { joinStructureChanges } from '../mutate/dropStructureChange';
6
6
  import { log } from '../utils/logger';
7
7
  import * as trackUtils from '../utils/track-utils';
8
- import { isSplitStep, isStructureSteps } from '../utils/track-utils';
8
+ import { isSplitStep, isStructureSteps } from './utils';
9
9
  export function trackReplaceStep(step, oldState, newTr, attrsTemplate, stepResult, currentStepDoc, tr, moveID) {
10
10
  log.info('###### ReplaceStep ######');
11
11
  let selectionPos = 0;
@@ -1,5 +1,5 @@
1
1
  import { NodeSelection as NodeSelectionClass, TextSelection, } from 'prosemirror-state';
2
- import { AddMarkStep, AttrStep, Mapping, ReplaceAroundStep, ReplaceStep, } from 'prosemirror-transform';
2
+ import { AddMarkStep, AddNodeMarkStep, AttrStep, Mapping, RemoveMarkStep, RemoveNodeMarkStep, ReplaceAroundStep, ReplaceStep, } from 'prosemirror-transform';
3
3
  import { getAction, TrackChangesAction } from '../actions';
4
4
  import { diffChangeSteps } from '../change-steps/diffChangeSteps';
5
5
  import { processChangeSteps } from '../change-steps/processChangeSteps';
@@ -8,11 +8,13 @@ import { getNodeTrackedData } from '../compute/nodeHelpers';
8
8
  import { CHANGE_STATUS } from '../types/change';
9
9
  import { log } from '../utils/logger';
10
10
  import { mapChangeSteps } from '../utils/mapChangeStep';
11
- import { filterMeaninglessMoveSteps, handleDirectPendingMoveDeletions, HasMoveOperations, isStructureSteps, } from '../utils/track-utils';
11
+ import { filterMeaninglessMoveSteps, handleDirectPendingMoveDeletions, HasMoveOperations, } from '../utils/track-utils';
12
12
  import { uuidv4 } from '../utils/uuidv4';
13
13
  import trackAttrsChange from './trackAttrsChange';
14
+ import { trackAddMarkStep, trackAddNodeMarkStep, trackRemoveMarkStep, trackRemoveNodeMarkStep, } from './trackMarkSteps';
14
15
  import { trackReplaceAroundStep } from './trackReplaceAroundStep';
15
16
  import { trackReplaceStep } from './trackReplaceStep';
17
+ import { isStructureSteps } from './utils';
16
18
  const getSelectionStaticConstructor = (sel) => Object.getPrototypeOf(sel).constructor;
17
19
  const isHighlightMarkerNode = (node) => node && node.type === node.type.schema.nodes.highlight_marker;
18
20
  export function trackTransaction(tr, oldState, newTr, authorID, changeSet) {
@@ -109,11 +111,21 @@ export function trackTransaction(tr, oldState, newTr, authorID, changeSet) {
109
111
  const [mapping, selectionPos] = processChangeSteps(changeSteps, tr.selection.from, newTr, emptyAttrs, oldState.schema, deletedNodeMapping);
110
112
  }
111
113
  else if (step instanceof AddMarkStep) {
114
+ trackAddMarkStep(step, emptyAttrs, newTr, tr.docs[i]);
112
115
  const dataTracked = (_f = getNodeTrackedData(newTr.doc.nodeAt(step.from), oldState.schema)) === null || _f === void 0 ? void 0 : _f.pop();
113
116
  if (dataTracked) {
114
117
  updateChangeAttrs(newTr, { id: dataTracked.id, from: step.from, to: step.to, type: 'text-change', dataTracked }, Object.assign(Object.assign({}, dataTracked), { id: uuidv4() }), oldState.schema);
115
118
  }
116
119
  }
120
+ else if (step instanceof RemoveMarkStep) {
121
+ trackRemoveMarkStep(step, emptyAttrs, newTr, tr.docs[i]);
122
+ }
123
+ else if (step instanceof RemoveNodeMarkStep) {
124
+ trackRemoveNodeMarkStep(step, emptyAttrs, newTr, tr.docs[i]);
125
+ }
126
+ else if (step instanceof AddNodeMarkStep) {
127
+ trackAddNodeMarkStep(step, emptyAttrs, newTr, tr.docs[i]);
128
+ }
117
129
  tr.getMeta('inputType') && newTr.setMeta('inputType', tr.getMeta('inputType'));
118
130
  tr.getMeta('uiEvent') && newTr.setMeta('uiEvent', tr.getMeta('uiEvent'));
119
131
  }
@@ -0,0 +1,62 @@
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 { ReplaceStep } from 'prosemirror-transform';
17
+ import { TrackChangesAction } from '../actions';
18
+ export const isSplitStep = (step, selection, uiEvent) => {
19
+ var _a, _b, _c, _d;
20
+ const { from, to, slice } = step;
21
+ if (from !== to ||
22
+ slice.content.childCount < 2 ||
23
+ (((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.isInline) && ((_b = slice.content.lastChild) === null || _b === void 0 ? void 0 : _b.isInline))) {
24
+ return false;
25
+ }
26
+ const { $anchor: { parentOffset: startOffset }, $head: { parentOffset: endOffset }, $from, } = selection;
27
+ const parentSize = $from.node().content.size;
28
+ if (uiEvent === 'paste') {
29
+ return !((startOffset === 0 && endOffset === 0) ||
30
+ (startOffset === parentSize && endOffset === parentSize));
31
+ }
32
+ const { content: { firstChild, lastChild }, openStart, openEnd, } = slice;
33
+ if ((((_c = window.event) === null || _c === void 0 ? void 0 : _c.code) === 'Enter' || ((_d = window.event) === null || _d === void 0 ? void 0 : _d.code) === 'NumpadEnter') &&
34
+ (firstChild === null || firstChild === void 0 ? void 0 : firstChild.type.name) === 'list_item') {
35
+ return !(parentSize === startOffset && parentSize === endOffset) && (lastChild === null || lastChild === void 0 ? void 0 : lastChild.type.name) === 'list_item';
36
+ }
37
+ return (openStart === openEnd &&
38
+ firstChild.type === lastChild.type &&
39
+ firstChild.inlineContent &&
40
+ lastChild.inlineContent &&
41
+ !(startOffset === parentSize && endOffset === parentSize));
42
+ };
43
+ export const isWrapStep = (step) => step.from === step.gapFrom &&
44
+ step.to === step.gapTo &&
45
+ step.slice.openStart === 0 &&
46
+ step.slice.openEnd === 0;
47
+ export const isLiftStep = (step) => {
48
+ if (step.from < step.gapFrom &&
49
+ step.to > step.gapTo &&
50
+ step.slice.size === 0 &&
51
+ step.gapTo - step.gapFrom > 0) {
52
+ return true;
53
+ }
54
+ return false;
55
+ };
56
+ export function stepIsLift(gap, node, to) {
57
+ return gap.start < gap.end && gap.insert === 0 && gap.end === to && !node.isText;
58
+ }
59
+ export const isStructureSteps = (tr) => tr.getMeta(TrackChangesAction.structuralChangeAction) &&
60
+ tr.steps.length === 2 &&
61
+ tr.steps[0] instanceof ReplaceStep &&
62
+ tr.steps[1] instanceof ReplaceStep;
@@ -39,51 +39,6 @@ export function createNewUpdateAttrs(attrs, oldAttrs) {
39
39
  export function createNewStructureAttrs(attrs) {
40
40
  return Object.assign(Object.assign({}, attrs), { operation: CHANGE_OPERATION.structure });
41
41
  }
42
- export const isSplitStep = (step, selection, uiEvent) => {
43
- var _a, _b, _c, _d;
44
- const { from, to, slice } = step;
45
- if (from !== to ||
46
- slice.content.childCount < 2 ||
47
- (((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.isInline) && ((_b = slice.content.lastChild) === null || _b === void 0 ? void 0 : _b.isInline))) {
48
- return false;
49
- }
50
- const { $anchor: { parentOffset: startOffset }, $head: { parentOffset: endOffset }, $from, } = selection;
51
- const parentSize = $from.node().content.size;
52
- if (uiEvent === 'paste') {
53
- return !((startOffset === 0 && endOffset === 0) ||
54
- (startOffset === parentSize && endOffset === parentSize));
55
- }
56
- const { content: { firstChild, lastChild }, openStart, openEnd, } = slice;
57
- if ((((_c = window.event) === null || _c === void 0 ? void 0 : _c.code) === 'Enter' || ((_d = window.event) === null || _d === void 0 ? void 0 : _d.code) === 'NumpadEnter') &&
58
- (firstChild === null || firstChild === void 0 ? void 0 : firstChild.type.name) === 'list_item') {
59
- return !(parentSize === startOffset && parentSize === endOffset) && (lastChild === null || lastChild === void 0 ? void 0 : lastChild.type.name) === 'list_item';
60
- }
61
- return (openStart === openEnd &&
62
- firstChild.type === lastChild.type &&
63
- firstChild.inlineContent &&
64
- lastChild.inlineContent &&
65
- !(startOffset === parentSize && endOffset === parentSize));
66
- };
67
- export const isWrapStep = (step) => step.from === step.gapFrom &&
68
- step.to === step.gapTo &&
69
- step.slice.openStart === 0 &&
70
- step.slice.openEnd === 0;
71
- export 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
- export function stepIsLift(gap, node, to) {
81
- return gap.start < gap.end && gap.insert === 0 && gap.end === to && !node.isText;
82
- }
83
- export const isStructureSteps = (tr) => tr.getMeta(TrackChangesAction.structuralChangeAction) &&
84
- tr.steps.length === 2 &&
85
- tr.steps[0] instanceof ReplaceStep &&
86
- tr.steps[1] instanceof ReplaceStep;
87
42
  export const trFromHistory = (tr) => Object.keys(tr.meta).find((s) => s.startsWith('history$'));
88
43
  export const HasMoveOperations = (tr) => {
89
44
  const movingAssoc = new Map();
@@ -236,3 +191,27 @@ export const updateBlockNodesAttrs = (fragment, predicate) => {
236
191
  });
237
192
  return Fragment.fromArray(updatedNodes);
238
193
  };
194
+ export function isValidTrackableMark(mark) {
195
+ var _a, _b;
196
+ const spec = mark.type.spec;
197
+ const name = mark.type.name;
198
+ if (!name.startsWith('tracked_') &&
199
+ ((_a = spec.attrs) === null || _a === void 0 ? void 0 : _a.dataTracked) &&
200
+ typeof ((_b = spec.attrs) === null || _b === void 0 ? void 0 : _b.dataTracked) === 'object') {
201
+ return true;
202
+ }
203
+ return false;
204
+ }
205
+ export function excludeFromTracked(dataTracked, changeIdToExclude) {
206
+ if (!dataTracked) {
207
+ return null;
208
+ }
209
+ const newDataTracked = dataTracked.filter((c) => c.id !== changeIdToExclude);
210
+ return newDataTracked.length ? newDataTracked : null;
211
+ }
212
+ export function isInlineMarkChange(change) {
213
+ if (change.type == 'mark-change') {
214
+ return change.nodeType.isInline || change.nodeType.isText;
215
+ }
216
+ return false;
217
+ }
@@ -1,4 +1,7 @@
1
1
  export function uuidv4() {
2
+ if (typeof crypto !== 'undefined' && crypto.randomUUID) {
3
+ return crypto.randomUUID();
4
+ }
2
5
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
3
6
  const r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
4
7
  return v.toString(16);
@@ -1,4 +1,4 @@
1
- import { IncompleteChange, NodeAttrChange, NodeChange, ReferenceChange, RootChanges, TextChange, TrackedAttrs, TrackedChange } from './types/change';
1
+ import { IncompleteChange, MarkChange, 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)[]);
@@ -22,12 +22,15 @@ export declare class ChangeSet {
22
22
  index: number;
23
23
  root: NodeChange;
24
24
  } | undefined;
25
- canJoinAdjacentInlineChanges(change: TrackedChange, index: number): boolean | undefined;
25
+ areMatchingWrapOperations(c1: TrackedChange, c2: TrackedChange): boolean;
26
+ areMatchingMarkOperations(c1: TrackedChange, c2: TrackedChange): boolean;
27
+ canJoinAdjacentInlineChanges(change: TrackedChange, index: number): boolean;
26
28
  joinRelatedStructuralChanges(rootNodes: RootChanges, change: TrackedChange): true | undefined;
27
29
  static flattenTreeToIds(changes: TrackedChange[]): string[];
28
30
  static shouldDeleteChange(change: TrackedChange): boolean;
29
31
  static isValidDataTracked(dataTracked?: Partial<TrackedAttrs>): boolean;
30
32
  static isTextChange(change: TrackedChange): change is TextChange;
33
+ static isMarkChange(change: TrackedChange): change is MarkChange;
31
34
  static isNodeChange(change: TrackedChange): change is NodeChange;
32
35
  static isNodeAttrChange(change: TrackedChange): change is NodeAttrChange;
33
36
  static isReferenceChange(change: TrackedChange): change is ReferenceChange;
@@ -2,6 +2,5 @@ import { Schema } from 'prosemirror-model';
2
2
  import { Transaction } from 'prosemirror-state';
3
3
  import { Mapping } from 'prosemirror-transform';
4
4
  import { ChangeSet } from '../ChangeSet';
5
- import { TrackedAttrs, TrackedChange } from '../types/change';
6
- export declare function getUpdatedDataTracked(dataTracked: TrackedAttrs[] | null, changeId: string): TrackedAttrs[] | null;
5
+ import { TrackedChange } from '../types/change';
7
6
  export declare function applyAcceptedRejectedChanges(tr: Transaction, schema: Schema, changes: TrackedChange[], changeSet: ChangeSet, deleteMap?: Mapping): Mapping;
@@ -1,10 +1,11 @@
1
- import { Node as PMNode, Schema } from 'prosemirror-model';
1
+ import { Mark, Node as PMNode, Schema } from 'prosemirror-model';
2
2
  import { CHANGE_OPERATION, TrackedAttrs } from '../types/change';
3
3
  export declare function addTrackIdIfDoesntExist(attrs: Partial<TrackedAttrs>): Partial<TrackedAttrs>;
4
4
  export declare function getTextNodeTrackedMarkData(node: PMNode | undefined | null, schema: Schema): (Omit<Partial<TrackedAttrs>, "operation"> & {
5
5
  operation: CHANGE_OPERATION;
6
6
  }) | undefined;
7
7
  export declare function getBlockInlineTrackedData(node: PMNode): Partial<TrackedAttrs>[] | undefined;
8
+ export declare function getMarkTrackedData(node: PMNode | undefined | null): Map<Mark, Partial<TrackedAttrs>[]>;
8
9
  export declare function getNodeTrackedData(node: PMNode | undefined | null, schema: Schema): Partial<TrackedAttrs>[] | undefined;
9
10
  export declare function equalMarks(n1: PMNode, n2: PMNode): boolean;
10
11
  export declare function shouldMergeTrackedAttributes(left?: Partial<TrackedAttrs>, right?: Partial<TrackedAttrs>): boolean;
@@ -3,4 +3,4 @@ import { Transaction } from 'prosemirror-state';
3
3
  import { NewDeleteAttrs } from '../types/track';
4
4
  export declare function deleteNode(node: PMNode, pos: number, tr: Transaction): Transaction;
5
5
  export declare function deleteOrSetNodeDeleted(node: PMNode, pos: number, newTr: Transaction, deleteAttrs: NewDeleteAttrs): Transaction | undefined;
6
- export declare const keepDeleteWithMoveNodeId: (node: PMNode) => Partial<import("../types/change").TrackedAttrs>[] | null;
6
+ export declare const keepPairedChanges: (node: PMNode) => Partial<import("../types/change").TrackedAttrs>[] | null;
@@ -2,5 +2,5 @@ import { Fragment } from 'prosemirror-model';
2
2
  import { Transaction } from 'prosemirror-state';
3
3
  import { NewEmptyAttrs } from '../types/track';
4
4
  export declare const dropStructuralChangeShadow: (moveNodeId: string | undefined, tr: Transaction) => Transaction;
5
- export declare const dropOrphanChanges: (newTr: Transaction, dropDataTracked?: boolean) => void;
5
+ export declare const dropOrphanChanges: (newTr: Transaction) => void;
6
6
  export declare const joinStructureChanges: (attrs: NewEmptyAttrs, sliceContent: Fragment, content: Fragment, tr: Transaction, newTr: Transaction) => Fragment;
@@ -0,0 +1,8 @@
1
+ import { Node as PMNode } from 'prosemirror-model';
2
+ import { Transaction } from 'prosemirror-state';
3
+ import { AddMarkStep, AddNodeMarkStep, RemoveMarkStep, RemoveNodeMarkStep } from 'prosemirror-transform';
4
+ import { NewEmptyAttrs } from '../types/track';
5
+ export declare function trackRemoveMarkStep(step: RemoveMarkStep, emptyAttrs: NewEmptyAttrs, newTr: Transaction, doc: PMNode): void;
6
+ export declare function trackRemoveNodeMarkStep(step: RemoveNodeMarkStep, emptyAttrs: NewEmptyAttrs, newTr: Transaction, doc: PMNode): void;
7
+ export declare function trackAddMarkStep(step: AddMarkStep, emptyAttrs: NewEmptyAttrs, newTr: Transaction, doc: PMNode): void;
8
+ export declare function trackAddNodeMarkStep(step: AddNodeMarkStep, emptyAttrs: NewEmptyAttrs, newTr: Transaction, stepDoc: PMNode): void;
@@ -0,0 +1,28 @@
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 { Node as PMNode, Slice } from 'prosemirror-model';
17
+ import { Selection, Transaction } from 'prosemirror-state';
18
+ import { ReplaceAroundStep, ReplaceStep } from 'prosemirror-transform';
19
+ export declare const isSplitStep: (step: ReplaceStep, selection: Selection, uiEvent: string) => boolean;
20
+ export declare const isWrapStep: (step: ReplaceAroundStep) => boolean;
21
+ export declare const isLiftStep: (step: ReplaceAroundStep) => boolean;
22
+ export declare function stepIsLift(gap: {
23
+ start: number;
24
+ end: number;
25
+ slice: Slice;
26
+ insert: number;
27
+ }, node: PMNode, to: number): boolean;
28
+ export declare const isStructureSteps: (tr: Transaction) => any;
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Node, NodeType } from 'prosemirror-model';
16
+ import { Mark, Node, NodeType } from 'prosemirror-model';
17
17
  export declare enum CHANGE_OPERATION {
18
18
  insert = "insert",
19
19
  delete = "delete",
@@ -95,6 +95,9 @@ export type ReferenceChange = Change & {
95
95
  };
96
96
  export type MarkChange = Change & {
97
97
  type: 'mark-change';
98
+ nodeType: NodeType;
99
+ mark: Mark;
100
+ node: Node;
98
101
  };
99
102
  export type TrackedChange = TextChange | NodeChange | NodeAttrChange | WrapChange | ReferenceChange | MarkChange;
100
103
  export type PartialChange<T extends TrackedChange> = Omit<T, 'dataTracked'> & {
@@ -1,7 +1,7 @@
1
- import { Attrs, Fragment, Node as PMNode, Slice } from 'prosemirror-model';
2
- import { Selection, Transaction } from 'prosemirror-state';
3
- import { ReplaceAroundStep, ReplaceStep, Step } from 'prosemirror-transform';
4
- import { CHANGE_OPERATION, TrackedAttrs } from '../types/change';
1
+ import { Attrs, Fragment, Mark, Node as PMNode } from 'prosemirror-model';
2
+ import { Transaction } from 'prosemirror-state';
3
+ import { ReplaceStep, Step } from 'prosemirror-transform';
4
+ import { CHANGE_OPERATION, TrackedAttrs, TrackedChange } from '../types/change';
5
5
  import { NewDeleteAttrs, NewEmptyAttrs, NewInsertAttrs, NewMoveAttrs, NewReferenceAttrs, NewSplitNodeAttrs, NewUpdateAttrs } from '../types/track';
6
6
  export declare function createNewInsertAttrs(attrs: NewEmptyAttrs): NewInsertAttrs;
7
7
  export declare function createNewWrapAttrs(attrs: NewEmptyAttrs): NewInsertAttrs;
@@ -11,16 +11,6 @@ export declare function createNewDeleteAttrs(attrs: NewEmptyAttrs): NewDeleteAtt
11
11
  export declare function createNewMoveAttrs(attrs: NewEmptyAttrs, indentationType?: 'indent' | 'unindent'): NewMoveAttrs;
12
12
  export declare function createNewUpdateAttrs(attrs: NewEmptyAttrs, oldAttrs: Record<string, any>): NewUpdateAttrs;
13
13
  export declare function createNewStructureAttrs(attrs: NewEmptyAttrs): NewInsertAttrs;
14
- export declare const isSplitStep: (step: ReplaceStep, selection: Selection, uiEvent: string) => boolean;
15
- export declare const isWrapStep: (step: ReplaceAroundStep) => boolean;
16
- export declare const isLiftStep: (step: ReplaceAroundStep) => boolean;
17
- export declare function stepIsLift(gap: {
18
- start: number;
19
- end: number;
20
- slice: Slice;
21
- insert: number;
22
- }, node: PMNode, to: number): boolean;
23
- export declare const isStructureSteps: (tr: Transaction) => any;
24
14
  export declare const trFromHistory: (tr: Transaction) => string | undefined;
25
15
  export declare const HasMoveOperations: (tr: Transaction) => Map<ReplaceStep, string>;
26
16
  export declare const isPendingChange: (trackedAttrs: TrackedAttrs[] | undefined, operation: CHANGE_OPERATION) => boolean;
@@ -29,3 +19,6 @@ export declare const isDirectPendingMoveDeletion: (step: ReplaceStep, doc: PMNod
29
19
  export declare const handleDirectPendingMoveDeletions: (tr: Transaction, newTr: Transaction, movingSteps: Map<ReplaceStep, string>) => void;
30
20
  export declare const filterMeaninglessMoveSteps: (tr: Transaction, movingSteps: Map<ReplaceStep, string>) => Step[];
31
21
  export declare const updateBlockNodesAttrs: (fragment: Fragment, predicate: (attrs: Attrs, node: PMNode) => Attrs) => Fragment;
22
+ export declare function isValidTrackableMark(mark: Mark): boolean;
23
+ export declare function excludeFromTracked(dataTracked: TrackedAttrs[] | null, changeIdToExclude: string): TrackedAttrs[] | null;
24
+ export declare function isInlineMarkChange(change: TrackedChange): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manuscripts/track-changes-plugin",
3
- "version": "2.0.12",
3
+ "version": "2.1.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",