Skip to content

Commit 73cf399

Browse files
committed
basic real time collaboration
1 parent 4a7753d commit 73cf399

File tree

4 files changed

+276
-236
lines changed

4 files changed

+276
-236
lines changed

package.json

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@
4444
"watch:src": "tsc -w"
4545
},
4646
"dependencies": {
47-
"@jupyterlab/application": "^3.0.2",
48-
"@jupyterlab/apputils": "^3.0.2",
49-
"@jupyterlab/coreutils": "^5.0.1",
50-
"@jupyterlab/docregistry": "^3.0.2",
51-
"@jupyterlab/filebrowser": "^3.0.2",
52-
"@jupyterlab/launcher": "^3.0.2",
53-
"@jupyterlab/mainmenu": "^3.0.2",
47+
"@jupyterlab/application": "^3.1.0-alpha.2",
48+
"@jupyterlab/apputils": "^3.1.0-alpha.2",
49+
"@jupyterlab/coreutils": "^5.1.0-alpha.2",
50+
"@jupyterlab/docregistry": "^3.1.0-alpha.2",
51+
"@jupyterlab/filebrowser": "^3.1.0-alpha.2",
52+
"@jupyterlab/launcher": "^3.1.0-alpha.2",
53+
"@jupyterlab/mainmenu": "^3.1.0-alpha.2",
5454
"@lumino/coreutils": "^1.5.3",
55-
"@lumino/widgets": "^1.18.0"
55+
"@lumino/widgets": "^1.18.0",
56+
"yjs": "^13.5.0"
5657
},
5758
"devDependencies": {
5859
"@jupyterlab/builder": "^3.0.0",
@@ -68,6 +69,14 @@
6869
"rimraf": "^3.0.2",
6970
"typescript": "~3.9.3"
7071
},
72+
"resolutions": {
73+
"@lumino/widgets": "~1.18.0",
74+
"@types/react": "~17.0.0",
75+
"csstype": "~2.4.0",
76+
"react": "~17.0.1",
77+
"typestyle": "~2.0.4",
78+
"yjs": "~13.5.0"
79+
},
7180
"jupyterlab": {
7281
"extension": true,
7382
"outputDir": "jupyterlab-drawio/labextension"

src/editor.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ export class DrawioWidget extends DocumentWidget<Widget> {
7979
onAfterShow(msg: Message): void {
8080
Private.ensureMx().then(() => {
8181
this._loadEditor(this.node);
82-
this._onContentChanged();
82+
const contextModel = this.context.model;
83+
const xml = this.mx.mxUtils.parseXml(contextModel.toString());
84+
this._editor.editor.setGraphXml(xml.documentElement);
8385
});
8486
}
8587

@@ -90,8 +92,8 @@ export class DrawioWidget extends DocumentWidget<Widget> {
9092
private _onContextReady(): void {
9193
const contextModel = this.context.model;
9294

93-
// Set the editor model value.
94-
this._onContentChanged();
95+
const xml = this.mx.mxUtils.parseXml(contextModel.toString());
96+
this._editor.editor.setGraphXml(xml.documentElement);
9597

9698
contextModel.contentChanged.connect(this._onContentChanged, this);
9799
contextModel.stateChanged.connect(this._onModelStateChangedNew, this);
@@ -129,13 +131,17 @@ export class DrawioWidget extends DocumentWidget<Widget> {
129131
// Workaround for TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature
130132
const _Editor: any = mx.Editor;
131133
this._editor = new mx.EditorUi(new _Editor(false, themes), node);
132-
134+
133135
this._editor.editor.graph.model.addListener(
134-
mx.mxEvent.NOTIFY,
136+
mx.mxEvent.CHANGE,
135137
(sender: any, evt: any) => {
138+
//console.log(mx.mxEvent.CHANGE, sender, evt);
139+
const changes: any[] = evt.properties.changes;
140+
for (let i=0; i<changes.length; i++) {
141+
if (changes[i].root) return;
142+
}
136143
this._saveToContext();
137-
}
138-
);
144+
});
139145

140146
return this._editor;
141147
}
@@ -157,17 +163,16 @@ export class DrawioWidget extends DocumentWidget<Widget> {
157163
const newValue = this.context.model.toString();
158164

159165
if (oldValue !== newValue && !this._editor.editor.graph.isEditing()) {
160-
if (newValue.length) {
161-
const xml = mx.mxUtils.parseXml(newValue);
162-
this._editor.editor.setGraphXml(xml.documentElement);
163-
}
166+
const xml = mx.mxUtils.parseXml(newValue);
167+
this._editor.editor.setGraphXml(xml.documentElement);
164168
}
165169
}
166170

167171
private _saveToContext(): void {
168172
if (this._editor.editor.graph.isEditing()) {
169173
this._editor.editor.graph.stopEditing();
170174
}
175+
171176
const xml = this.mx.mxUtils.getXml(this._editor.editor.getGraphXml());
172177
this.context.model.fromString(xml);
173178
}

tsconfig.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,21 @@
1616
"outDir": "lib",
1717
"rootDir": "src",
1818
"strict": true,
19+
"skipLibCheck": true,
1920
"strictNullChecks": false,
2021
"target": "es2017",
21-
"types": []
22+
"types": [],
23+
"baseUrl": ".",
24+
"paths": {
25+
"@jupyterlab/application": ["../jupyterlab/packages/application"],
26+
"@jupyterlab/apputils": ["../jupyterlab/packages/apputils"],
27+
"@jupyterlab/coreutils": ["../jupyterlab/packages/coreutils"],
28+
"@jupyterlab/docregistry": ["../jupyterlab/packages/docregistry"],
29+
"@jupyterlab/filebrowser": ["../jupyterlab/packages/filebrowser"],
30+
"@jupyterlab/launcher": ["../jupyterlab/packages/launcher"],
31+
"@jupyterlab/mainmenu": ["../jupyterlab/packages/mainmenu"],
32+
"*": ["node_modules/*"]
33+
}
2234
},
2335
"include": ["src/**/*"]
2436
}

0 commit comments

Comments
 (0)