y-mxgraph 0.1.5 → 0.1.6

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.
Files changed (2) hide show
  1. package/README.md +12 -5
  2. package/package.json +6 -1
package/README.md CHANGED
@@ -29,13 +29,20 @@ import { Binding, LOCAL_ORIGIN } from 'y-mxgraph';
29
29
  const doc = new Y.Doc();
30
30
 
31
31
  App.main((app) => {
32
- // Ensure consistent initial files across clients. draw.io generates random diagram ids by default,
33
- // which can cause sync issues if clients start from different states. Use generateFileTemplate to create a unified template.
34
- if (!app.currentFile.data) {
35
- app.currentFile.data = Binding.generateFileTemplate('diagram-0');
32
+ const file = app.currentFile;
33
+
34
+ // If Y.Doc already has data (from other clients), use it
35
+ const mxfileMap = doc.getMap('mxfile');
36
+ const diagramMap = mxfileMap.get('diagram');
37
+ if (diagramMap && diagramMap.size > 0) {
38
+ const { doc2xml } = await import('y-mxgraph');
39
+ file.ui.setFileData(doc2xml(doc));
40
+ file.setData(doc2xml(doc));
41
+ } else if (!file.data) {
42
+ file.data = Binding.generateFileTemplate('diagram-0');
36
43
  }
37
44
 
38
- const binding = new Binding(app.currentFile, { doc });
45
+ const binding = new Binding(file, { doc });
39
46
 
40
47
  window.addEventListener('beforeunload', () => binding.destroy());
41
48
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "y-mxgraph",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Yjs binding for draw.io (mxGraph) documents",
5
5
  "keywords": [
6
6
  "yjs",
@@ -28,6 +28,11 @@
28
28
  "types": "./index.d.ts"
29
29
  }
30
30
  },
31
+ "dependencies": {
32
+ "colord": "^2.9.3",
33
+ "lodash-es": "^4.17.21",
34
+ "xml-js": "^1.6.11"
35
+ },
31
36
  "peerDependencies": {
32
37
  "y-protocols": "^1.0.0",
33
38
  "yjs": "^13.6.0"