y-mxgraph 0.4.0 → 0.4.1
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.
- package/README.md +27 -2
- package/README.zh-CN.md +27 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,20 +120,45 @@ pnpm --filter @y-mxgraph/ws-demo dev # Start client on port 5174
|
|
|
120
120
|
|
|
121
121
|
```ts
|
|
122
122
|
// Server (parent page)
|
|
123
|
+
import * as Y from 'yjs';
|
|
124
|
+
import { WebrtcProvider } from 'y-webrtc';
|
|
125
|
+
import { LOCAL_ORIGIN } from 'y-mxgraph';
|
|
126
|
+
import { IFRAME_ORIGIN } from 'y-mxgraph/iframe-bridge';
|
|
123
127
|
import { createIframeBridgeServer } from 'y-mxgraph/iframe-bridge/server';
|
|
124
128
|
|
|
125
129
|
const doc = new Y.Doc();
|
|
126
130
|
const provider = new WebrtcProvider(roomName, doc, { signaling });
|
|
127
|
-
const
|
|
131
|
+
const awareness = provider.awareness;
|
|
132
|
+
|
|
133
|
+
// Optional: enable cross-iframe undo/redo
|
|
134
|
+
const undoManager = new Y.UndoManager(doc, {
|
|
135
|
+
trackedOrigins: new Set([LOCAL_ORIGIN, IFRAME_ORIGIN]),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const bridge = createIframeBridgeServer(doc, awareness, { undoManager });
|
|
128
139
|
bridge.addIframe(iframeElement, 'child-1');
|
|
129
140
|
|
|
141
|
+
// Undo/redo from parent page
|
|
142
|
+
document.getElementById('undo-btn')!.onclick = () => {
|
|
143
|
+
if (undoManager.canUndo()) undoManager.undo();
|
|
144
|
+
};
|
|
145
|
+
|
|
130
146
|
// Provider (iframe child)
|
|
147
|
+
import * as Y from 'yjs';
|
|
148
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
149
|
+
import { Binding } from 'y-mxgraph';
|
|
131
150
|
import { createIframeBridgeProvider } from 'y-mxgraph/iframe-bridge/provider';
|
|
132
151
|
|
|
133
152
|
const doc = new Y.Doc();
|
|
134
153
|
const awareness = new Awareness(doc);
|
|
135
154
|
const bridge = createIframeBridgeProvider(doc, awareness);
|
|
136
|
-
|
|
155
|
+
|
|
156
|
+
App.main((app) => {
|
|
157
|
+
const file = app.currentFile;
|
|
158
|
+
const binding = new Binding(file, { doc, awareness });
|
|
159
|
+
// Takeover draw.io's undo manager to route through Server
|
|
160
|
+
bridge.takeoverUndoManager(file);
|
|
161
|
+
});
|
|
137
162
|
```
|
|
138
163
|
|
|
139
164
|
See [iframe Bridge documentation](https://mizuka-wu.github.io/y-mxgraph/en/guide/iframe-bridge) for details.
|
package/README.zh-CN.md
CHANGED
|
@@ -82,20 +82,45 @@ App.main((app) => {
|
|
|
82
82
|
|
|
83
83
|
```ts
|
|
84
84
|
// Server(父页面)
|
|
85
|
+
import * as Y from 'yjs';
|
|
86
|
+
import { WebrtcProvider } from 'y-webrtc';
|
|
87
|
+
import { LOCAL_ORIGIN } from 'y-mxgraph';
|
|
88
|
+
import { IFRAME_ORIGIN } from 'y-mxgraph/iframe-bridge';
|
|
85
89
|
import { createIframeBridgeServer } from 'y-mxgraph/iframe-bridge/server';
|
|
86
90
|
|
|
87
91
|
const doc = new Y.Doc();
|
|
88
92
|
const provider = new WebrtcProvider(roomName, doc, { signaling });
|
|
89
|
-
const
|
|
93
|
+
const awareness = provider.awareness;
|
|
94
|
+
|
|
95
|
+
// 可选:启用跨 iframe 撤销/重做
|
|
96
|
+
const undoManager = new Y.UndoManager(doc, {
|
|
97
|
+
trackedOrigins: new Set([LOCAL_ORIGIN, IFRAME_ORIGIN]),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const bridge = createIframeBridgeServer(doc, awareness, { undoManager });
|
|
90
101
|
bridge.addIframe(iframeElement, 'child-1');
|
|
91
102
|
|
|
103
|
+
// 从父页面执行撤销/重做
|
|
104
|
+
document.getElementById('undo-btn')!.onclick = () => {
|
|
105
|
+
if (undoManager.canUndo()) undoManager.undo();
|
|
106
|
+
};
|
|
107
|
+
|
|
92
108
|
// Provider(iframe 子页面)
|
|
109
|
+
import * as Y from 'yjs';
|
|
110
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
111
|
+
import { Binding } from 'y-mxgraph';
|
|
93
112
|
import { createIframeBridgeProvider } from 'y-mxgraph/iframe-bridge/provider';
|
|
94
113
|
|
|
95
114
|
const doc = new Y.Doc();
|
|
96
115
|
const awareness = new Awareness(doc);
|
|
97
116
|
const bridge = createIframeBridgeProvider(doc, awareness);
|
|
98
|
-
|
|
117
|
+
|
|
118
|
+
App.main((app) => {
|
|
119
|
+
const file = app.currentFile;
|
|
120
|
+
const binding = new Binding(file, { doc, awareness });
|
|
121
|
+
// 接管 draw.io 的 undo manager,使其通过 Server 执行
|
|
122
|
+
bridge.takeoverUndoManager(file);
|
|
123
|
+
});
|
|
99
124
|
```
|
|
100
125
|
|
|
101
126
|
详见 [iframe Bridge 文档](https://mizuka-wu.github.io/y-mxgraph/guide/iframe-bridge)。
|