@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
package/README.md CHANGED
@@ -2,15 +2,12 @@
2
2
 
3
3
  ProseMirror plugin to track inserts/deletes to nodes and text.
4
4
 
5
- If you have multiple versions of prosemirror packages, ensure that track-changes' dependencies `prosemirror-model` and `prosemirror-transform` are aliased/deduped to same instance. `prosemirror-state` and `prosemirror-view` are only used at type level. [Example](https://github.com/Atypon-OpenSource/manuscripts-quarterback/blob/main/examples-packages/client/vite.config.js).
6
-
7
- [More detailed overview](https://github.com/Atypon-OpenSource/manuscripts-quarterback/blob/main/quarterback-packages/track-changes-plugin/OVERVIEW.md)
8
-
9
5
  ## How to use
10
6
 
11
- First install the plugin: `npm i @manuscripts/track-changes-plugin`
7
+ Requires normal ProseMirror editor dependencies.
12
8
 
13
- Then add the plugin to ProseMirror plugins:
9
+ 1. Install the plugin: `npm i @manuscripts/track-changes-plugin`
10
+ 2. Add it to ProseMirror plugins:
14
11
 
15
12
  ```ts
16
13
  import { EditorState } from 'prosemirror-state'
@@ -20,9 +17,11 @@ import { trackChangesPlugin } from '@manuscripts/track-changes-plugin'
20
17
 
21
18
  import { schema } from './schema'
22
19
 
23
- const plugins = exampleSetup({ schema }).concat(trackChangesPlugin({
24
- debug: true
25
- }))
20
+ const plugins = exampleSetup({ schema }).concat(
21
+ trackChangesPlugin({
22
+ debug: true,
23
+ })
24
+ )
26
25
  const state = EditorState.create({
27
26
  schema,
28
27
  plugins,
@@ -32,9 +31,9 @@ const view = new EditorView(document.querySelector('#editor') as HTMLElement, {
32
31
  })
33
32
  ```
34
33
 
35
- where `schema` is https://github.com/Atypon-OpenSource/manuscripts-quarterback/blob/main/quarterback-packages/track-changes-plugin/test/utils/schema.ts
34
+ where `schema` contains `dataTracked` attributes for tracked nodes and `tracked_insert` & `tracked_delete` marks as shown here: https://github.com/Atypon-OpenSource/manuscripts-quarterback/blob/main/quarterback-packages/track-changes-plugin/test/utils/schema.ts
36
35
 
37
- Enable or disable the plugin with:
36
+ 3. That should start tracking all transactions. You can use the following commands to enable/disable/enter read-only mode:
38
37
 
39
38
  ```ts
40
39
  import { trackCommands, TrackChangesStatus } from '@manuscripts/track-changes-plugin'
@@ -52,7 +51,11 @@ trackCommands.setTrackingStatus(TrackChangesStatus.disabled))(view.state, view.d
52
51
  trackCommands.setTrackingStatus(TrackChangesStatus.viewSnapshots))(view.state, view.dispatch, view)
53
52
  ```
54
53
 
55
- See an example app at https://github.com/Atypon-OpenSource/manuscripts-quarterback/tree/main/examples-packages/client
54
+ See an example app at https://github.com/Atypon-OpenSource/manuscripts-quarterback/tree/main/examples-packages/client for a more complete boilerplate.
55
+
56
+ **NOTE**: If you have multiple versions of prosemirror packages, ensure that track-changes' dependencies `prosemirror-model` and `prosemirror-transform` are aliased/deduped to same instance. `prosemirror-state` and `prosemirror-view` are only used at type level. [Example](https://github.com/Atypon-OpenSource/manuscripts-quarterback/blob/main/examples-packages/client/vite.config.js).
57
+
58
+ [More detailed overview](https://github.com/Atypon-OpenSource/manuscripts-quarterback/blob/main/quarterback-packages/track-changes-plugin/OVERVIEW.md)
56
59
 
57
60
  ## API
58
61
 
@@ -128,44 +131,16 @@ export const refreshChanges = () => Command
128
131
 
129
132
  ### Actions
130
133
 
131
- Actions are used to access/set transaction meta fields. I don't think you ever would need to use other than `TrackChangesAction.skipTrack` but they are all exposed, nonetheless.
134
+ Actions are used to access/set transaction meta fields internally. `skipTracking` is exposed publicly to set track-changes to skip certain transaction.
132
135
 
133
136
  ```ts
134
- export type TrackChangesActionParams = {
135
- [TrackChangesAction.skipTrack]: boolean
136
- [TrackChangesAction.setUserID]: string
137
- [TrackChangesAction.setPluginStatus]: TrackChangesStatus
138
- [TrackChangesAction.setChangeStatuses]: {
139
- status: CHANGE_STATUS
140
- ids: string[]
141
- }
142
- [TrackChangesAction.updateChanges]: string[]
143
- [TrackChangesAction.refreshChanges]: boolean
144
- [TrackChangesAction.applyAndRemoveChanges]: boolean
145
- }
146
137
  /**
147
- * Gets the value of a meta field, action payload, of a defined track-changes action.
138
+ * Skip tracking for a transaction, use this with caution to avoid race-conditions or just to otherwise
139
+ * omitting applying of track attributes or marks.
148
140
  * @param tr
149
- * @param action
141
+ * @returns
150
142
  */
151
- export function getAction<K extends keyof TrackChangesActionParams>(tr: Transaction, action: K) {
152
- return tr.getMeta(action) as TrackChangesActionParams[K] | undefined
153
- }
154
-
155
- /**
156
- * Use this function to set meta keys to transactions that are consumed by the track-changes-plugin.
157
- * For example, you can skip tracking of a transaction with setAction(tr, TrackChangesAction.skipTrack, true)
158
- * @param tr
159
- * @param action
160
- * @param payload
161
- */
162
- export function setAction<K extends keyof TrackChangesActionParams>(
163
- tr: Transaction,
164
- action: K,
165
- payload: TrackChangesActionParams[K]
166
- ) {
167
- return tr.setMeta(action, payload)
168
- }
143
+ export const skipTracking = (tr: Transaction) => setAction(tr, TrackChangesAction.skipTrack, true)
169
144
  ```
170
145
 
171
146
  ### Types
@@ -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 { NodeChange, IncompleteChange, TextChange, TrackedAttrs, TrackedChange } from './types/change';
16
+ import { NodeChange, IncompleteChange, TextChange, TrackedAttrs, TrackedChange, NodeAttrChange } from './types/change';
17
17
  /**
18
18
  * ChangeSet is a data structure to contain the tracked changes with some utility methods and computed
19
19
  * values to allow easier operability.
@@ -37,6 +37,7 @@ export declare class ChangeSet {
37
37
  get rejected(): TrackedChange[];
38
38
  get textChanges(): TrackedChange[];
39
39
  get nodeChanges(): TrackedChange[];
40
+ get nodeAttrChanges(): TrackedChange[];
40
41
  get isEmpty(): boolean;
41
42
  /**
42
43
  * Used to determine whether `fixInconsistentChanges` has to be executed to replace eg duplicate ids or
@@ -70,4 +71,5 @@ export declare class ChangeSet {
70
71
  static isValidTrackedAttrs(attrs?: Partial<TrackedAttrs>): boolean;
71
72
  static isTextChange(change: TrackedChange): change is TextChange;
72
73
  static isNodeChange(change: TrackedChange): change is NodeChange;
74
+ static isNodeAttrChange(change: TrackedChange): change is NodeAttrChange;
73
75
  }
package/dist/actions.d.ts CHANGED
@@ -50,4 +50,11 @@ export declare function getAction<K extends keyof TrackChangesActionParams>(tr:
50
50
  * @param action
51
51
  * @param payload
52
52
  */
53
- export declare function setAction<K extends keyof TrackChangesActionParams>(tr: Transaction, action: K, payload: TrackChangesActionParams[K]): Transaction<any>;
53
+ export declare function setAction<K extends keyof TrackChangesActionParams>(tr: Transaction, action: K, payload: TrackChangesActionParams[K]): Transaction;
54
+ /**
55
+ * Skip tracking for a transaction, use this with caution to avoid race-conditions or just to otherwise
56
+ * omitting applying of track attributes or marks.
57
+ * @param tr
58
+ * @returns
59
+ */
60
+ export declare const skipTracking: (tr: Transaction) => Transaction;
@@ -0,0 +1,21 @@
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 { Schema } from 'prosemirror-model';
17
+ import type { Transaction } from 'prosemirror-state';
18
+ import { ExposedFragment } from '../types/pm';
19
+ import { ChangeStep, InsertSliceStep } from '../types/step';
20
+ export declare function matchInserted(inDeleted: number, deleted: ChangeStep[], inserted: ExposedFragment, newTr: Transaction, schema: Schema): [number, ChangeStep[]];
21
+ export declare function diffChangeSteps(deleted: ChangeStep[], inserted: InsertSliceStep[], newTr: Transaction, schema: Schema): ChangeStep[];
@@ -0,0 +1,21 @@
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 { Schema } from 'prosemirror-model';
17
+ import type { Transaction } from 'prosemirror-state';
18
+ import { Mapping } from 'prosemirror-transform';
19
+ import { ChangeStep } from '../types/step';
20
+ import { NewEmptyAttrs } from '../types/track';
21
+ export declare function processChangeSteps(changes: ChangeStep[], startPos: number, newTr: Transaction, emptyAttrs: NewEmptyAttrs, schema: Schema): [Mapping, number];
File without changes
File without changes
File without changes
@@ -13,8 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { Command } from 'prosemirror-state';
16
17
  import { CHANGE_STATUS } from './types/change';
17
- import type { Command } from './types/editor';
18
18
  import { TrackChangesStatus } from './types/track';
19
19
  /**
20
20
  * Sets track-changes plugin's status to any of: 'enabled' 'disabled' 'viewSnapshots'. Passing undefined will
@@ -14,21 +14,14 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { Node as PMNode, Schema } from 'prosemirror-model';
17
- import { Transaction } from 'prosemirror-state';
18
17
  import { CHANGE_OPERATION, TrackedAttrs } from '../types/change';
19
18
  export declare function addTrackIdIfDoesntExist(attrs: Partial<TrackedAttrs>): Partial<TrackedAttrs>;
20
- /**
21
- * Not in use, maybe for ReplaceAroundSteps but we'll see
22
- * @param pos
23
- * @param tr
24
- */
25
- export declare function liftNode(pos: number, tr: Transaction): Transaction<any> | undefined;
26
- export declare function getInlineNodeTrackedMarkData(node: PMNode | undefined | null, schema: Schema): {
19
+ export declare function getInlineNodeTrackedMarkData(node: PMNode | undefined | null, schema: Schema): (Omit<Partial<TrackedAttrs>, "operation"> & {
27
20
  operation: CHANGE_OPERATION;
28
- } | undefined;
21
+ }) | undefined;
29
22
  export declare function getNodeTrackedData(node: PMNode | undefined | null, schema: Schema): Partial<TrackedAttrs> | undefined;
30
23
  export declare function equalMarks(n1: PMNode, n2: PMNode): boolean;
31
24
  export declare function shouldMergeTrackedAttributes(left?: Partial<TrackedAttrs>, right?: Partial<TrackedAttrs>): boolean;
32
- export declare function getMergeableMarkTrackedAttrs(node: PMNode | undefined | null, attrs: Partial<TrackedAttrs>, schema: Schema): {
25
+ export declare function getMergeableMarkTrackedAttrs(node: PMNode | undefined | null, attrs: Partial<TrackedAttrs>, schema: Schema): (Omit<Partial<TrackedAttrs>, "operation"> & {
33
26
  operation: CHANGE_OPERATION;
34
- } | null;
27
+ }) | null;
@@ -14,5 +14,5 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { Fragment, Schema } from 'prosemirror-model';
17
- import { NewInsertAttrs } from '../../types/track';
17
+ import { NewInsertAttrs } from '../types/track';
18
18
  export declare function setFragmentAsInserted(inserted: Fragment, insertAttrs: NewInsertAttrs, schema: Schema): Fragment;
@@ -0,0 +1,41 @@
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 '../types/pm';
18
+ /**
19
+ * Filters merged nodes from an open insertSlice to manually merge them to prevent unwanted deletions
20
+ *
21
+ * So instead of joining the slice by its open sides, possibly deleting previous nodes, we can push the
22
+ * changed content manually inside the merged nodes.
23
+ * Eg. instead of doing `|<p>asdf</p><p>|bye</p>` automatically, we extract the merged nodes first:
24
+ * {
25
+ * updatedSliceNodes: [<p>asdf</p>],
26
+ * firstMergedNode: <p>bye</p>,
27
+ * lastMergedNode: undefined,
28
+ * }
29
+ * @param insertSlice inserted slice
30
+ */
31
+ export declare function splitSliceIntoMergedParts(insertSlice: ExposedSlice, mergeEqualSides?: boolean): {
32
+ updatedSliceNodes: PMNode[];
33
+ firstMergedNode: {
34
+ mergedNodeContent: ExposedFragment;
35
+ unmergedContent: ExposedFragment | undefined;
36
+ } | undefined;
37
+ lastMergedNode: {
38
+ mergedNodeContent: ExposedFragment;
39
+ unmergedContent: ExposedFragment | undefined;
40
+ } | undefined;
41
+ };