y-prosemirror
Advanced tools
Comparing version 1.0.20 to 1.1.0
{ | ||
"name": "y-prosemirror", | ||
"version": "1.0.20", | ||
"version": "1.1.0", | ||
"description": "Prosemirror bindings for Yjs", | ||
@@ -58,3 +58,3 @@ "main": "./dist/y-prosemirror.cjs", | ||
"peerDependencies": { | ||
"yjs": "^13.3.2", | ||
"yjs": "^13.5.38", | ||
"y-protocols": "^1.0.1", | ||
@@ -82,4 +82,4 @@ "prosemirror-model": "^1.7.1", | ||
"y-webrtc": "^10.2.0", | ||
"yjs": "^13.5.32" | ||
"yjs": "^13.5.38" | ||
} | ||
} |
@@ -182,4 +182,23 @@ # y-prosemirror [![Build Status](https://travis-ci.com/yjs/y-prosemirror.svg?branch=master)](https://travis-ci.com/yjs/y-prosemirror) | ||
### Undo/Redo | ||
The package exports `undo` and `redo` commands which can be used in place of | ||
[prosemirror-history](https://prosemirror.net/docs/ref/#history) by mapping the | ||
mod-Z/Y keys - see [ProseMirror](https://github.com/yjs/yjs-demos/blob/main/prosemirror/prosemirror.js#L29) | ||
and [Tiptap](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-collaboration/src/collaboration.ts) | ||
examples. | ||
Undo and redo are be scoped to the local client, so one peer won't undo another's | ||
changes. See [Y.UndoManager](https://docs.yjs.dev/api/undo-manager) for more details. | ||
Just like prosemirror-history, you can set a transaction's `addToHistory` meta property | ||
to false to prevent that transaction from being rolled back by undo. This can be helpful for programmatic | ||
document changes that aren't initiated by the user. | ||
```js | ||
tr.setMeta("addToHistory", false); | ||
``` | ||
### License | ||
[The MIT License](./LICENSE) © Kevin Jahns |
@@ -85,3 +85,3 @@ /** | ||
let changedInitialContent = false | ||
let rerenderTimeoutId | ||
let rerenderTimeout | ||
const plugin = new Plugin({ | ||
@@ -104,2 +104,3 @@ props: { | ||
isChangeOrigin: false, | ||
addToHistory: true, | ||
colors, | ||
@@ -118,2 +119,3 @@ colorMapping, | ||
} | ||
pluginState.addToHistory = tr.getMeta('addToHistory') !== false | ||
// always set isChangeOrigin. If undefined, this is not change origin. | ||
@@ -146,7 +148,7 @@ pluginState.isChangeOrigin = change !== undefined && !!change.isChangeOrigin | ||
const binding = new ProsemirrorBinding(yXmlFragment, view) | ||
if (rerenderTimeoutId != null) { | ||
clearTimeout(rerenderTimeoutId) | ||
if (rerenderTimeout != null) { | ||
rerenderTimeout.destroy() | ||
} | ||
// Make sure this is called in a separate context | ||
rerenderTimeoutId = eventloop.timeout(0, () => { | ||
rerenderTimeout = eventloop.timeout(0, () => { | ||
binding._forceRerender() | ||
@@ -162,3 +164,6 @@ view.dispatch(view.state.tr.setMeta(ySyncPluginKey, { binding })) | ||
changedInitialContent = true | ||
binding._prosemirrorChanged(view.state.doc) | ||
pluginState.doc.transact(tr => { | ||
tr.meta.set('addToHistory', pluginState.addToHistory) | ||
binding._prosemirrorChanged(view.state.doc) | ||
}, ySyncPluginKey) | ||
} | ||
@@ -168,3 +173,3 @@ } | ||
destroy: () => { | ||
clearTimeout(rerenderTimeoutId) | ||
rerenderTimeout.destroy() | ||
binding.destroy() | ||
@@ -171,0 +176,0 @@ } |
@@ -40,3 +40,4 @@ | ||
trackedOrigins: new Set([ySyncPluginKey].concat(trackedOrigins)), | ||
deleteFilter: (item) => defaultDeleteFilter(item, protectedNodes) | ||
deleteFilter: (item) => defaultDeleteFilter(item, protectedNodes), | ||
captureTransaction: tr => !!tr.meta.get('addToHistory') | ||
}) | ||
@@ -43,0 +44,0 @@ return { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
232528
3140
204