diff --git a/package.json b/package.json index ce777dd5..c45fda13 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ }, "dependencies": { "@deathbeds/jupyterlab-rjsf": "^1.1.0", - "@jupyter-notebook/ydoc": "^0.2.0", + "@jupyter/ydoc": "^0.2.0", "@jupyterlab/application": "^4.0.0-alpha.16", "@jupyterlab/apputils": "^4.0.0-alpha.16", "@jupyterlab/collaboration": "^4.0.0-alpha.16", diff --git a/src/mainview.tsx b/src/mainview.tsx index 39f63230..0af8425c 100644 --- a/src/mainview.tsx +++ b/src/mainview.tsx @@ -32,7 +32,7 @@ import { import { ContextMenu } from '@lumino/widgets'; import { CommandRegistry } from '@lumino/commands'; -import { MapChange } from '@jupyter-notebook/ydoc'; +import { MapChange } from '@jupyter/ydoc'; import { Annotation } from './annotation/view'; import { AnnotationModel } from './annotation/model'; diff --git a/src/model.ts b/src/model.ts index ef96276f..f280f6b2 100644 --- a/src/model.ts +++ b/src/model.ts @@ -1,6 +1,6 @@ import { IChangedArgs } from '@jupyterlab/coreutils'; import { IModelDB, ModelDB } from '@jupyterlab/observables'; -import { MapChange, YDocument } from '@jupyter-notebook/ydoc'; +import { MapChange, YDocument } from '@jupyter/ydoc'; import { PartialJSONObject } from '@lumino/coreutils'; import { ISignal, Signal } from '@lumino/signaling'; import Ajv from 'ajv'; @@ -241,18 +241,17 @@ export class JupyterCadDoc this._options = this.ydoc.getMap('options'); this._objects = this.ydoc.getArray('objects'); + this._metadata = this.ydoc.getMap('metadata'); this.undoManager.addToScope(this._objects); - this._objects.observe(this._objectsObserver); - - this._metadata = this.ydoc.getMap('metadata'); + this._objects.observeDeep(this._objectsObserver); this._metadata.observe(this._metaObserver); } dispose(): void { - // this._objects.unobserve(this._objectsObserver); - // this._options.unobserve(this._optionsObserver); + this._objects.unobserveDeep(this._objectsObserver); + this._metadata.unobserve(this._metaObserver); } get objects(): Y.Array { @@ -352,27 +351,14 @@ export class JupyterCadDoc return new JupyterCadDoc(); } - private _objectsObserver = (event: Y.YArrayEvent): void => { - event.changes.added.forEach(item => { - const type = (item.content as Y.ContentType).type as Y.Map; - type.observe(this.emitChange); - }); - event.changes.deleted.forEach(item => { - const type = (item.content as Y.ContentType).type as Y.Map; - type.unobserve(this.emitChange); - }); - const objectChange = []; - this._changed.emit({ objectChange }); + private _objectsObserver = (event: Y.YEvent[]): void => { + this._changed.emit({ objectChange: [] }); }; private _metaObserver = (event: Y.YMapEvent): void => { this._metadataChanged.emit(event.keys); }; - private emitChange = () => { - this._changed.emit({}); - }; - private _objects: Y.Array; private _options: Y.Map; private _metadata: Y.Map; diff --git a/src/types.ts b/src/types.ts index 9dfd8cf6..0cf421ba 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,7 @@ import { IJCadObject } from './_interface/jcad.d'; import { IChangedArgs } from '@jupyterlab/coreutils'; import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry'; -import { MapChange, YDocument, StateChange } from '@jupyter-notebook/ydoc'; +import { MapChange, YDocument, StateChange } from '@jupyter/ydoc'; import { ReactWidget } from '@jupyterlab/ui-components'; import { User } from '@jupyterlab/services'; import { ISignal, Signal } from '@lumino/signaling'; diff --git a/yarn.lock b/yarn.lock index 0e011932..15c5316b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -529,7 +529,7 @@ resolved "https://registry.yarnpkg.com/@juggle/resize-observer/-/resize-observer-3.4.0.tgz#08d6c5e20cf7e4cc02fd181c4b0c225cd31dbb60" integrity sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA== -"@jupyter-notebook/ydoc@^0.2.0", "@jupyter-notebook/ydoc@~0.2.0": +"@jupyter-notebook/ydoc@~0.2.0": version "0.2.0" resolved "https://registry.yarnpkg.com/@jupyter-notebook/ydoc/-/ydoc-0.2.0.tgz#0febf91cd80dd2206f668c60e8ee20f4983cca99" integrity sha512-R8iHKwU+8OvdYwtgNj9dh3vv0OrAyHLNDmXjaSu6CJ1w10OP7MuQasvD18DAgTjqlHEUgnPoSJA2j0UlflSC1Q== @@ -541,6 +541,18 @@ y-protocols "^1.0.5" yjs "^13.5.40" +"@jupyter/ydoc@^0.2.0": + version "0.2.2" + resolved "https://registry.yarnpkg.com/@jupyter/ydoc/-/ydoc-0.2.2.tgz#a2be83d2a0e076cef7ed77302e69153a0a4d6c16" + integrity sha512-UtU7ZxpL0k+QF9So4wtGxaS2C+nno58dig7sQUaBn48wlQDiuypzKgUmF7I37srpu6f/ywon3JBuEjxuL1CIBQ== + dependencies: + "@jupyterlab/nbformat" "^3.0.0 || ^4.0.0-alpha.15" + "@lumino/coreutils" "^1.11.0 || ^2.0.0-alpha.6" + "@lumino/disposable" "^1.10.0 || ^2.0.0-alpha.6" + "@lumino/signaling" "^1.10.0 || ^2.0.0-alpha.6" + y-protocols "^1.0.5" + yjs "^13.5.40" + "@jupyterlab/application@^4.0.0-alpha.16": version "4.0.0-alpha.16" resolved "https://registry.yarnpkg.com/@jupyterlab/application/-/application-4.0.0-alpha.16.tgz#737f5875115fecddcd5b2b2f45114b35390b09f7"