@manuscripts/track-changes-plugin 0.0.4 → 0.3.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.
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
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;