@manuscripts/track-changes-plugin 0.1.1 → 0.4.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 (29) hide show
  1. package/README.md +20 -45
  2. package/dist/ChangeSet.d.ts +3 -1
  3. package/dist/actions.d.ts +8 -1
  4. package/dist/change-steps/diffChangeSteps.d.ts +21 -0
  5. package/dist/change-steps/processChangeSteps.d.ts +21 -0
  6. package/dist/{track → changes}/applyChanges.d.ts +0 -0
  7. package/dist/{track → changes}/findChanges.d.ts +0 -0
  8. package/dist/{track → changes}/fixInconsistentChanges.d.ts +0 -0
  9. package/dist/{track → changes}/updateChangeAttrs.d.ts +0 -0
  10. package/dist/commands.d.ts +1 -1
  11. package/dist/{track/node-utils.d.ts → compute/nodeHelpers.d.ts} +4 -11
  12. package/dist/{track/steps → compute}/setFragmentAsInserted.d.ts +1 -1
  13. package/dist/compute/splitSliceIntoMergedParts.d.ts +41 -0
  14. package/dist/{index.es.js → index.cjs} +658 -380
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +663 -412
  17. package/dist/{track/steps → mutate}/deleteAndMergeSplitNodes.d.ts +4 -3
  18. package/dist/{track → mutate}/deleteNode.d.ts +9 -0
  19. package/dist/mutate/deleteText.d.ts +32 -0
  20. package/dist/{track → mutate}/mergeNode.d.ts +1 -1
  21. package/dist/{track/steps → mutate}/mergeTrackedMarks.d.ts +0 -0
  22. package/dist/{track/steps → steps}/trackReplaceAroundStep.d.ts +3 -2
  23. package/dist/{track/steps → steps}/trackReplaceStep.d.ts +3 -2
  24. package/dist/{track → steps}/trackTransaction.d.ts +2 -2
  25. package/dist/types/change.d.ts +22 -11
  26. package/dist/types/step.d.ts +52 -0
  27. package/dist/{track/steps → utils}/track-utils.d.ts +1 -2
  28. package/package.json +6 -6
  29. package/dist/types/editor.d.ts +0 -23
@@ -16,8 +16,9 @@
16
16
  import { Fragment, Node as PMNode, Schema } from 'prosemirror-model';
17
17
  import type { Transaction } from 'prosemirror-state';
18
18
  import { Mapping } from 'prosemirror-transform';
19
- import { ExposedSlice } from '../../types/pm';
20
- import { NewEmptyAttrs } from '../../types/track';
19
+ import { ExposedSlice } from '../types/pm';
20
+ import { NewEmptyAttrs } from '../types/track';
21
+ import { ChangeStep } from '../types/step';
21
22
  /**
22
23
  * Applies deletion to the doc without actually deleting nodes that have not been inserted
23
24
  *
@@ -48,6 +49,6 @@ export declare function deleteAndMergeSplitNodes(from: number, to: number, gap:
48
49
  end: number;
49
50
  } | undefined, startDoc: PMNode, newTr: Transaction, schema: Schema, trackAttrs: NewEmptyAttrs, insertSlice: ExposedSlice): {
50
51
  deleteMap: Mapping;
51
- mergedInsertPos: undefined;
52
52
  newSliceContent: Fragment;
53
+ steps: ChangeStep[];
53
54
  };
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import { Node as PMNode } from 'prosemirror-model';
17
17
  import { Transaction } from 'prosemirror-state';
18
+ import { NewDeleteAttrs } from '../types/track';
18
19
  /**
19
20
  * Deletes node but tries to leave its content intact by trying to unwrap it first
20
21
  *
@@ -25,3 +26,11 @@ import { Transaction } from 'prosemirror-state';
25
26
  * @returns
26
27
  */
27
28
  export declare function deleteNode(node: PMNode, pos: number, tr: Transaction): Transaction;
29
+ /**
30
+ * Deletes inserted block or inline node, otherwise adds `dataTracked` object with CHANGE_STATUS 'deleted'
31
+ * @param node
32
+ * @param pos
33
+ * @param newTr
34
+ * @param deleteAttrs
35
+ */
36
+ export declare function deleteOrSetNodeDeleted(node: PMNode, pos: number, newTr: Transaction, deleteAttrs: NewDeleteAttrs): void;
@@ -0,0 +1,32 @@
1
+ /*!
2
+ * © 2021 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, Schema } from 'prosemirror-model';
17
+ import type { Transaction } from 'prosemirror-state';
18
+ import { NewDeleteAttrs } from '../types/track';
19
+ /**
20
+ * Deletes inserted text directly, otherwise wraps it with tracked_delete mark
21
+ *
22
+ * This would work for general inline nodes too, but since node marks don't work properly
23
+ * with Yjs, attributes are used instead.
24
+ * @param node
25
+ * @param pos
26
+ * @param newTr
27
+ * @param schema
28
+ * @param deleteAttrs
29
+ * @param from
30
+ * @param to
31
+ */
32
+ export declare function deleteTextIfInserted(node: PMNode, pos: number, newTr: Transaction, schema: Schema, deleteAttrs: NewDeleteAttrs, from?: number, to?: number): number;
@@ -22,4 +22,4 @@ import { Transaction } from 'prosemirror-state';
22
22
  * @param tr
23
23
  * @returns
24
24
  */
25
- export declare function mergeNode(node: PMNode, pos: number, tr: Transaction): Transaction<any> | undefined;
25
+ export declare function mergeNode(node: PMNode, pos: number, tr: Transaction): Transaction | undefined;
@@ -1,4 +1,5 @@
1
1
  import type { EditorState, Transaction } from 'prosemirror-state';
2
2
  import { ReplaceAroundStep } from 'prosemirror-transform';
3
- import { NewEmptyAttrs } from '../../types/track';
4
- export declare function trackReplaceAroundStep(step: ReplaceAroundStep, oldState: EditorState, newTr: Transaction, attrs: NewEmptyAttrs): void;
3
+ import { NewEmptyAttrs } from '../types/track';
4
+ import { ChangeStep } from '../types/step';
5
+ export declare function trackReplaceAroundStep(step: ReplaceAroundStep, oldState: EditorState, newTr: Transaction, attrs: NewEmptyAttrs): ChangeStep[];
@@ -1,4 +1,5 @@
1
1
  import type { EditorState, Transaction } from 'prosemirror-state';
2
2
  import { ReplaceStep } from 'prosemirror-transform';
3
- import { NewEmptyAttrs } from '../../types/track';
4
- export declare function trackReplaceStep(step: ReplaceStep, oldState: EditorState, newTr: Transaction, attrs: NewEmptyAttrs): number;
3
+ import { NewEmptyAttrs } from '../types/track';
4
+ import { ChangeStep } from '../types/step';
5
+ export declare function trackReplaceStep(step: ReplaceStep, oldState: EditorState, newTr: Transaction, attrs: NewEmptyAttrs): [ChangeStep[], number];
@@ -11,7 +11,7 @@ import type { EditorState, Transaction } from 'prosemirror-state';
11
11
  * @param tr Original transaction
12
12
  * @param oldState State before transaction
13
13
  * @param newTr Transaction created from the new editor state
14
- * @param userID User id
14
+ * @param authorID User id
15
15
  * @returns newTr that inverts the initial tr and applies track attributes/marks
16
16
  */
17
- export declare function trackTransaction(tr: Transaction, oldState: EditorState, newTr: Transaction, userID: string): Transaction;
17
+ export declare function trackTransaction(tr: Transaction, oldState: EditorState, newTr: Transaction, authorID: string): Transaction;
@@ -16,25 +16,28 @@
16
16
  export declare enum CHANGE_OPERATION {
17
17
  insert = "insert",
18
18
  delete = "delete",
19
- set_node_attributes = "set_node_attributes",
20
- wrap_with_node = "wrap_with_node",
21
- unwrap_from_node = "unwrap_from_node",
22
- add_mark = "add_mark",
23
- remove_mark = "remove_mark"
19
+ set_node_attributes = "set_attrs"
24
20
  }
25
21
  export declare enum CHANGE_STATUS {
26
22
  accepted = "accepted",
27
23
  rejected = "rejected",
28
24
  pending = "pending"
29
25
  }
30
- export interface TrackedAttrs {
26
+ declare type InsertDeleteAttrs = {
31
27
  id: string;
32
- userID: string;
33
- operation: CHANGE_OPERATION;
28
+ authorID: string;
29
+ reviewedByID: string | null;
30
+ operation: CHANGE_OPERATION.insert | CHANGE_OPERATION.delete;
34
31
  status: CHANGE_STATUS;
35
32
  createdAt: number;
36
- }
37
- export declare type Change = {
33
+ updatedAt: number;
34
+ };
35
+ declare type UpdateAttrs = Omit<InsertDeleteAttrs, 'operation'> & {
36
+ operation: CHANGE_OPERATION.set_node_attributes;
37
+ oldAttrs: Record<string, any>;
38
+ };
39
+ export declare type TrackedAttrs = InsertDeleteAttrs | UpdateAttrs;
40
+ declare type Change = {
38
41
  id: string;
39
42
  from: number;
40
43
  to: number;
@@ -42,12 +45,19 @@ export declare type Change = {
42
45
  };
43
46
  export declare type TextChange = Change & {
44
47
  type: 'text-change';
48
+ text: string;
45
49
  };
46
50
  export declare type NodeChange = Change & {
47
51
  type: 'node-change';
48
52
  nodeType: string;
49
53
  children: TrackedChange[];
50
54
  };
55
+ export declare type NodeAttrChange = Change & {
56
+ type: 'node-attr-change';
57
+ nodeType: string;
58
+ oldAttrs: Record<string, any>;
59
+ newAttrs: Record<string, any>;
60
+ };
51
61
  export declare type WrapChange = Change & {
52
62
  type: 'wrap-change';
53
63
  wrapperNode: string;
@@ -55,7 +65,7 @@ export declare type WrapChange = Change & {
55
65
  export declare type MarkChange = Change & {
56
66
  type: 'mark-change';
57
67
  };
58
- export declare type TrackedChange = TextChange | NodeChange | WrapChange | MarkChange;
68
+ export declare type TrackedChange = TextChange | NodeChange | NodeAttrChange | WrapChange | MarkChange;
59
69
  export declare type PartialChange<T extends TrackedChange> = Omit<T, 'attrs'> & {
60
70
  attrs: Partial<TrackedAttrs>;
61
71
  };
@@ -63,3 +73,4 @@ export declare type IncompleteChange = Omit<TrackedChange, 'attrs'> & {
63
73
  attrs: Partial<TrackedAttrs>;
64
74
  };
65
75
  export declare type ChangeType = TrackedChange['type'];
76
+ export {};
@@ -0,0 +1,52 @@
1
+ /*!
2
+ * © 2021 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 } from 'prosemirror-model';
17
+ import { ExposedFragment, ExposedSlice } from './pm';
18
+ export interface DeleteNodeStep {
19
+ pos: number;
20
+ nodeEnd: number;
21
+ type: 'delete-node';
22
+ node: PMNode;
23
+ }
24
+ export interface DeleteTextStep {
25
+ pos: number;
26
+ from: number;
27
+ to: number;
28
+ type: 'delete-text';
29
+ node: PMNode;
30
+ }
31
+ export interface MergeFragmentStep {
32
+ pos: number;
33
+ mergePos: number;
34
+ from: number;
35
+ to: number;
36
+ type: 'merge-fragment';
37
+ node: PMNode;
38
+ fragment: ExposedFragment;
39
+ }
40
+ export interface InsertSliceStep {
41
+ from: number;
42
+ to: number;
43
+ type: 'insert-slice';
44
+ slice: ExposedSlice;
45
+ }
46
+ export interface UpdateNodeAttrsStep {
47
+ pos: number;
48
+ type: 'update-node-attrs';
49
+ oldAttrs: Record<string, any>;
50
+ newAttrs: Record<string, any>;
51
+ }
52
+ export declare type ChangeStep = DeleteNodeStep | DeleteTextStep | MergeFragmentStep | InsertSliceStep | UpdateNodeAttrsStep;
@@ -13,7 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { NewDeleteAttrs, NewEmptyAttrs, NewInsertAttrs } from '../../types/track';
17
- export declare function createNewEmptyAttrs(userID: string, createdAt: number): NewEmptyAttrs;
16
+ import { NewDeleteAttrs, NewEmptyAttrs, NewInsertAttrs } from '../types/track';
18
17
  export declare function createNewInsertAttrs(attrs: NewEmptyAttrs): NewInsertAttrs;
19
18
  export declare function createNewDeleteAttrs(attrs: NewEmptyAttrs): NewDeleteAttrs;
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@manuscripts/track-changes-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.4.0",
4
4
  "author": "Atypon Systems LLC",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/Atypon-OpenSource/manuscripts-quarterback/tree/main/quarterback-packages/track-changes-plugin",
7
- "main": "dist/index.js",
8
- "module": "dist/index.es.js",
7
+ "main": "dist/index.cjs",
8
+ "module": "dist/index.js",
9
9
  "type": "module",
10
10
  "types": "dist/index.d.ts",
11
11
  "exports": {
12
12
  "./package.json": "./package.json",
13
13
  "./src/styles.css": "./src/styles.css",
14
- ".": "./dist/index.es.js"
14
+ ".": "./dist/index.js"
15
15
  },
16
16
  "files": [
17
17
  "dist",
@@ -21,7 +21,7 @@
21
21
  "access": "public"
22
22
  },
23
23
  "devDependencies": {
24
- "@manuscripts/manuscript-transform": "^0.49.1",
24
+ "@manuscripts/manuscript-transform": "^0.49.4",
25
25
  "@rollup/plugin-commonjs": "^22.0.0",
26
26
  "@types/debug": "^4.1.7",
27
27
  "@types/jest": "27.5.1",
@@ -36,7 +36,7 @@
36
36
  "prosemirror-schema-list": "^1.2.0",
37
37
  "prosemirror-state": "^1.4.1",
38
38
  "prosemirror-transform": "^1.6.0",
39
- "prosemirror-view": "^1.26.2",
39
+ "prosemirror-view": "^1.27.0",
40
40
  "rollup": "^2.74.0",
41
41
  "rollup-plugin-typescript2": "^0.31.2",
42
42
  "ts-jest": "27.1.4",
@@ -1,23 +0,0 @@
1
- /*!
2
- * © 2021 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 { EditorState, Transaction } from 'prosemirror-state';
17
- import { EditorView } from 'prosemirror-view';
18
- export declare type Commands = {
19
- [name: string]: (...args: any[]) => Command;
20
- };
21
- export declare type CommandDispatch = (tr: Transaction) => void;
22
- export declare type Command = (state: EditorState, dispatch?: CommandDispatch, view?: EditorView) => boolean;
23
- export declare type HigherOrderCommand = (command: Command) => Command;