Comparing version 13.5.28 to 13.5.29
@@ -17,5 +17,5 @@ /** | ||
* | ||
* @extends {Observable<'stack-item-added'|'stack-item-popped'>} | ||
* @extends {Observable<'stack-item-added'|'stack-item-popped'|'stack-cleared'|'stack-item-updated'>} | ||
*/ | ||
export class UndoManager extends Observable<"stack-item-added" | "stack-item-popped"> { | ||
export class UndoManager extends Observable<"stack-item-added" | "stack-item-popped" | "stack-cleared" | "stack-item-updated"> { | ||
/** | ||
@@ -26,3 +26,6 @@ * @param {AbstractType<any>|Array<AbstractType<any>>} typeScope Accepts either a single type, or an array of types | ||
constructor(typeScope: AbstractType<any> | Array<AbstractType<any>>, { captureTimeout, deleteFilter, trackedOrigins }?: UndoManagerOptions); | ||
scope: AbstractType<any>[]; | ||
/** | ||
* @type {Array<AbstractType<any>>} | ||
*/ | ||
scope: Array<AbstractType<any>>; | ||
deleteFilter: (arg0: Item) => boolean; | ||
@@ -47,4 +50,8 @@ trackedOrigins: Set<any>; | ||
lastChange: number; | ||
clear(): void; | ||
/** | ||
* @param {Array<AbstractType<any>> | AbstractType<any>} ytypes | ||
*/ | ||
addToScope(ytypes: Array<AbstractType<any>> | AbstractType<any>): void; | ||
clear(clearUndoStack?: boolean, clearRedoStack?: boolean): void; | ||
/** | ||
* UndoManager merges Undo-StackItem if they are created within time-gap | ||
@@ -51,0 +58,0 @@ * smaller than `options.captureTimeout`. Call `um.stopCapturing()` so that the next |
{ | ||
"name": "yjs", | ||
"version": "13.5.28", | ||
"version": "13.5.29", | ||
"description": "Shared Editing Library", | ||
@@ -5,0 +5,0 @@ "main": "./dist/yjs.cjs", |
@@ -52,2 +52,3 @@ | ||
collaboration platform. | ||
* [Living Spec](https://livingspec.com/) A modern way for product teams to collaborate. | ||
@@ -85,2 +86,3 @@ ## Table of Contents | ||
| [valtio](https://github.com/pmndrs/valtio) | | [valtio-yjs](https://github.com/dai-shi/valtio-yjs) | [demo](https://codesandbox.io/s/valtio-yjs-demo-ox3iy) | | ||
| [immer](https://github.com/immerjs/immer) | | [immer-yjs](https://github.com/sep2/immer-yjs) | [demo](https://codesandbox.io/s/immer-yjs-demo-6e0znb) | | ||
| React / Vue / Svelte / MobX | | [SyncedStore](https://syncedstore.org) | [demo](https://syncedstore.org/docs/react) | | ||
@@ -876,2 +878,12 @@ | ||
<code> | ||
on('stack-item-updated', { stackItem: { meta: Map<any,any> }, type: 'undo' | ||
| 'redo' }) | ||
</code> | ||
</b> | ||
<dd> | ||
Register an event that is called when an existing <code>StackItem</code> is updated. | ||
This happens when two changes happen within a "captureInterval". | ||
</dd> | ||
<b> | ||
<code> | ||
on('stack-item-popped', { stackItem: { meta: Map<any,any> }, type: 'undo' | ||
@@ -885,2 +897,10 @@ | 'redo' }) | ||
</dd> | ||
<b> | ||
<code> | ||
on('stack-cleared', { undoStackCleared: boolean, redoStackCleared: boolean }) | ||
</code> | ||
</b> | ||
<dd> | ||
Register an event that is called when the undo- and/or the redo-stack is cleared. | ||
</dd> | ||
</dl> | ||
@@ -887,0 +907,0 @@ |
@@ -103,2 +103,2 @@ | ||
*/ | ||
export const readContentFormat = decoder => new ContentFormat(decoder.readString(), decoder.readJSON()) | ||
export const readContentFormat = decoder => new ContentFormat(decoder.readKey(), decoder.readJSON()) |
@@ -17,2 +17,3 @@ import { | ||
import * as time from 'lib0/time' | ||
import * as array from 'lib0/array' | ||
import { Observable } from 'lib0/observable' | ||
@@ -34,2 +35,14 @@ | ||
} | ||
/** | ||
* @param {Transaction} tr | ||
* @param {UndoManager} um | ||
* @param {StackItem} stackItem | ||
*/ | ||
const clearUndoManagerStackItem = (tr, um, stackItem) => { | ||
iterateDeletedStructs(tr, stackItem.deletions, item => { | ||
if (item instanceof Item && um.scope.some(type => isParentOf(type, item))) { | ||
keepItem(item, false) | ||
} | ||
}) | ||
} | ||
@@ -138,3 +151,3 @@ /** | ||
* | ||
* @extends {Observable<'stack-item-added'|'stack-item-popped'>} | ||
* @extends {Observable<'stack-item-added'|'stack-item-popped'|'stack-cleared'|'stack-item-updated'>} | ||
*/ | ||
@@ -148,3 +161,7 @@ export class UndoManager extends Observable { | ||
super() | ||
this.scope = typeScope instanceof Array ? typeScope : [typeScope] | ||
/** | ||
* @type {Array<AbstractType<any>>} | ||
*/ | ||
this.scope = [] | ||
this.addToScope(typeScope) | ||
this.deleteFilter = deleteFilter | ||
@@ -182,3 +199,3 @@ trackedOrigins.add(this) | ||
// neither undoing nor redoing: delete redoStack | ||
this.redoStack = [] | ||
this.clear(false, true) | ||
} | ||
@@ -214,27 +231,42 @@ const insertions = new DeleteSet() | ||
}) | ||
const changeEvent = [{ stackItem: stack[stack.length - 1], origin: transaction.origin, type: undoing ? 'redo' : 'undo', changedParentTypes: transaction.changedParentTypes }, this] | ||
if (didAdd) { | ||
this.emit('stack-item-added', [{ stackItem: stack[stack.length - 1], origin: transaction.origin, type: undoing ? 'redo' : 'undo', changedParentTypes: transaction.changedParentTypes }, this]) | ||
this.emit('stack-item-added', changeEvent) | ||
} else { | ||
this.emit('stack-item-updated', changeEvent) | ||
} | ||
}) | ||
this.doc.on('destroy', () => { | ||
this.destroy() | ||
}) | ||
} | ||
clear () { | ||
this.doc.transact(transaction => { | ||
/** | ||
* @param {StackItem} stackItem | ||
*/ | ||
const clearItem = stackItem => { | ||
iterateDeletedStructs(transaction, stackItem.deletions, item => { | ||
if (item instanceof Item && this.scope.some(type => isParentOf(type, item))) { | ||
keepItem(item, false) | ||
} | ||
}) | ||
/** | ||
* @param {Array<AbstractType<any>> | AbstractType<any>} ytypes | ||
*/ | ||
addToScope (ytypes) { | ||
ytypes = array.isArray(ytypes) ? ytypes : [ytypes] | ||
ytypes.forEach(ytype => { | ||
if (this.scope.every(yt => yt !== ytype)) { | ||
this.scope.push(ytype) | ||
} | ||
this.undoStack.forEach(clearItem) | ||
this.redoStack.forEach(clearItem) | ||
}) | ||
this.undoStack = [] | ||
this.redoStack = [] | ||
} | ||
clear (clearUndoStack = true, clearRedoStack = true) { | ||
if ((clearUndoStack && this.canUndo()) || (clearRedoStack && this.canRedo())) { | ||
this.doc.transact(tr => { | ||
if (clearUndoStack) { | ||
this.undoStack.forEach(item => clearUndoManagerStackItem(tr, this, item)) | ||
this.undoStack = [] | ||
} | ||
if (clearRedoStack) { | ||
this.redoStack.forEach(item => clearUndoManagerStackItem(tr, this, item)) | ||
this.redoStack = [] | ||
} | ||
this.emit('stack-cleared', [{ undoStackCleared: clearUndoStack, redoStackCleared: clearRedoStack }]) | ||
}) | ||
} | ||
} | ||
/** | ||
@@ -241,0 +273,0 @@ * UndoManager merges Undo-StackItem if they are created within time-gap |
@@ -301,8 +301,22 @@ | ||
if (clock === undefined) { | ||
/** | ||
* @todo uncomment to introduce this feature finally | ||
* | ||
* Background. The ContentFormat object was always encoded using writeKey, but the decoder used to use readString. | ||
* Furthermore, I forgot to set the keyclock. So everything was working fine. | ||
* | ||
* However, this feature here is basically useless as it is not being used (it actually only consumes extra memory). | ||
* | ||
* I don't know yet how to reintroduce this feature.. | ||
* | ||
* Older clients won't be able to read updates when we reintroduce this feature. So this should probably be done using a flag. | ||
* | ||
*/ | ||
// this.keyMap.set(key, this.keyClock) | ||
this.keyClockEncoder.write(this.keyClock++) | ||
this.stringEncoder.write(key) | ||
} else { | ||
this.keyClockEncoder.write(this.keyClock++) | ||
this.keyClockEncoder.write(clock) | ||
} | ||
} | ||
} |
@@ -128,3 +128,3 @@ | ||
const structs = [] | ||
const updateDecoder = new UpdateDecoderV1(decoding.createDecoder(update)) | ||
const updateDecoder = new YDecoder(decoding.createDecoder(update)) | ||
const lazyDecoder = new LazyStructReader(updateDecoder, false) | ||
@@ -131,0 +131,0 @@ for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2097403
32488
1069