y-mxgraph 0.2.2 → 0.3.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 +57 -3
- package/README.zh-CN.md +53 -0
- package/binding/index.d.ts +19 -0
- package/binding/index.d.ts.map +1 -1
- package/iframe-bridge/provider.d.ts +2 -0
- package/iframe-bridge/provider.d.ts.map +1 -0
- package/iframe-bridge/server.d.ts +2 -0
- package/iframe-bridge/server.d.ts.map +1 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/types/drawio.d.ts +5 -0
- package/types/drawio.d.ts.map +1 -1
- package/y-mxgraph.cjs.js +31 -5
- package/y-mxgraph.cjs.js.map +1 -1
- package/y-mxgraph.es.js +25 -5
- package/y-mxgraph.es.js.map +1 -1
- package/y-mxgraph.iife.js +32 -7
- package/y-mxgraph.iife.js.map +1 -1
- package/y-mxgraph.umd.js +32 -7
- package/y-mxgraph.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ Yjs binding for draw.io (mxGraph) documents, enabling real-time collaborative ed
|
|
|
10
10
|
- **Real-time collaboration** via y-webrtc, y-websocket, or any Yjs provider
|
|
11
11
|
- **Undo/Redo support** with Y.UndoManager
|
|
12
12
|
- **Collaborative cursors** via y-protocols Awareness
|
|
13
|
+
- **iframe Bridge** for isolated draw.io instances synced via postMessage
|
|
13
14
|
- **Full TypeScript** support
|
|
14
15
|
|
|
15
16
|
## Installation
|
|
@@ -41,7 +42,10 @@ App.main((app) => {
|
|
|
41
42
|
// `file.setData(xml)` is intentionally NOT called so draw.io does not
|
|
42
43
|
// mark the file as modified and pop up the "Save diagrams to:" dialog.
|
|
43
44
|
// Override via `applyFileData` if you need to sync `file.data` too.
|
|
44
|
-
|
|
45
|
+
//
|
|
46
|
+
// `disableBeforeUnload` (default: true) disables draw.io's native
|
|
47
|
+
// "All changes will be lost" dialog since Yjs handles persistence.
|
|
48
|
+
const binding = new Binding(file, { doc });
|
|
45
49
|
|
|
46
50
|
window.addEventListener('beforeunload', () => binding.destroy());
|
|
47
51
|
});
|
|
@@ -52,6 +56,7 @@ App.main((app) => {
|
|
|
52
56
|
- [Getting Started](https://mizuka-wu.github.io/y-mxgraph/en/guide/getting-started)
|
|
53
57
|
- [API Reference](https://mizuka-wu.github.io/y-mxgraph/en/api/)
|
|
54
58
|
- [Architecture](https://mizuka-wu.github.io/y-mxgraph/en/guide/architecture)
|
|
59
|
+
- [iframe Bridge](https://mizuka-wu.github.io/y-mxgraph/en/guide/iframe-bridge)
|
|
55
60
|
|
|
56
61
|
## Development
|
|
57
62
|
|
|
@@ -76,14 +81,63 @@ pnpm --filter y-mxgraph test
|
|
|
76
81
|
# Single-page mode (draw.io loaded directly in the current page)
|
|
77
82
|
pnpm --filter @y-mxgraph/demo dev
|
|
78
83
|
|
|
79
|
-
# iframe mode (
|
|
80
|
-
# Visit http://localhost:5173/iframe
|
|
84
|
+
# iframe mode (server page runs WebRTC Provider, iframes each run draw.io + y-mxgraph, synced via postMessage)
|
|
85
|
+
# Visit http://localhost:5173/iframe.html
|
|
81
86
|
|
|
82
87
|
# WebSocket server mode (centralized server with file persistence)
|
|
83
88
|
pnpm --filter @y-mxgraph/ws-demo server # Start server on port 1234
|
|
84
89
|
pnpm --filter @y-mxgraph/ws-demo dev # Start client on port 5174
|
|
85
90
|
```
|
|
86
91
|
|
|
92
|
+
## iframe Bridge
|
|
93
|
+
|
|
94
|
+
`@y-mxgraph/iframe-bridge` enables collaborative editing in iframe-isolated environments. The **server** (parent page) manages the network connection (y-webrtc, y-websocket, etc.) and syncs Y.Doc + Awareness to one or more **providers** (iframe children) via `postMessage`.
|
|
95
|
+
|
|
96
|
+
```text
|
|
97
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
98
|
+
│ Server (parent page) │
|
|
99
|
+
│ ┌──────────┐ ┌───────────┐ ┌──────────────────────────┐ │
|
|
100
|
+
│ │ Y.Doc │ │ Awareness │ │ Provider (y-webrtc, etc) │ │
|
|
101
|
+
│ └────┬─────┘ └─────┬─────┘ └──────────────────────────┘ │
|
|
102
|
+
│ │ │ │
|
|
103
|
+
│ └──────┬───────┘ │
|
|
104
|
+
│ ▼ │
|
|
105
|
+
│ createIframeBridgeServer(doc, awareness) │
|
|
106
|
+
│ │ postMessage │
|
|
107
|
+
└──────────────│──────────────────────────────────────────────┘
|
|
108
|
+
│
|
|
109
|
+
┌──────────┴──────────┐
|
|
110
|
+
▼ ▼
|
|
111
|
+
┌─────────────┐ ┌─────────────┐
|
|
112
|
+
│ Iframe A │ │ Iframe B │
|
|
113
|
+
│ create... │ │ create... │
|
|
114
|
+
│ Provider() │ │ Provider() │
|
|
115
|
+
│ │ │ │
|
|
116
|
+
│ local Y.Doc │ │ local Y.Doc │
|
|
117
|
+
│ + draw.io │ │ + draw.io │
|
|
118
|
+
└─────────────┘ └─────────────┘
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
// Server (parent page)
|
|
123
|
+
import { createIframeBridgeServer } from 'y-mxgraph/iframe-bridge/server';
|
|
124
|
+
|
|
125
|
+
const doc = new Y.Doc();
|
|
126
|
+
const provider = new WebrtcProvider(roomName, doc, { signaling });
|
|
127
|
+
const bridge = createIframeBridgeServer(doc, provider.awareness);
|
|
128
|
+
bridge.addIframe(iframeElement, 'child-1');
|
|
129
|
+
|
|
130
|
+
// Provider (iframe child)
|
|
131
|
+
import { createIframeBridgeProvider } from 'y-mxgraph/iframe-bridge/provider';
|
|
132
|
+
|
|
133
|
+
const doc = new Y.Doc();
|
|
134
|
+
const awareness = new Awareness(doc);
|
|
135
|
+
const bridge = createIframeBridgeProvider(doc, awareness);
|
|
136
|
+
// awareness states are automatically synced with the server
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
See [iframe Bridge documentation](https://mizuka-wu.github.io/y-mxgraph/en/guide/iframe-bridge) for details.
|
|
140
|
+
|
|
87
141
|
## Docs
|
|
88
142
|
|
|
89
143
|
```bash
|
package/README.zh-CN.md
CHANGED
|
@@ -10,6 +10,7 @@ Yjs 与 draw.io (mxGraph) 文档的双向绑定库,让 draw.io 支持实时多
|
|
|
10
10
|
- **实时协作** 支持 y-webrtc、y-websocket 及任意 Yjs Provider
|
|
11
11
|
- **撤销/重做** 集成 Y.UndoManager
|
|
12
12
|
- **协同光标** 基于 y-protocols Awareness 渲染远端光标与选区
|
|
13
|
+
- **iframe Bridge** 通过 postMessage 同步隔离的 draw.io 实例
|
|
13
14
|
- **完整 TypeScript** 类型支持
|
|
14
15
|
|
|
15
16
|
## 安装
|
|
@@ -35,6 +36,8 @@ App.main((app) => {
|
|
|
35
36
|
app.currentFile.data = Binding.generateFileTemplate('diagram-0');
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
// `disableBeforeUnload`(默认 true)禁用 draw.io 的 "All changes will be lost" 弹窗,
|
|
40
|
+
// 因为 Yjs 已接管持久化。如需保留原生行为(如使用 File System Access API),设为 false。
|
|
38
41
|
const binding = new Binding(app.currentFile, { doc });
|
|
39
42
|
|
|
40
43
|
window.addEventListener('beforeunload', () => binding.destroy());
|
|
@@ -46,6 +49,56 @@ App.main((app) => {
|
|
|
46
49
|
- [快速开始](https://mizuka-wu.github.io/y-mxgraph/guide/getting-started)
|
|
47
50
|
- [API 参考](https://mizuka-wu.github.io/y-mxgraph/api/)
|
|
48
51
|
- [实现原理](https://mizuka-wu.github.io/y-mxgraph/guide/architecture)
|
|
52
|
+
- [iframe Bridge](https://mizuka-wu.github.io/y-mxgraph/guide/iframe-bridge)
|
|
53
|
+
|
|
54
|
+
## iframe Bridge
|
|
55
|
+
|
|
56
|
+
`@y-mxgraph/iframe-bridge` 支持在 iframe 隔离环境中进行协同编辑。**Server**(父页面)管理网络连接(y-webrtc、y-websocket 等),通过 `postMessage` 将 Y.Doc 和 Awareness 同步到一个或多个 **Provider**(iframe 子页面)。
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
60
|
+
│ Server(父页面) │
|
|
61
|
+
│ ┌──────────┐ ┌───────────┐ ┌──────────────────────────┐ │
|
|
62
|
+
│ │ Y.Doc │ │ Awareness │ │ Provider (y-webrtc 等) │ │
|
|
63
|
+
│ └────┬─────┘ └─────┬─────┘ └──────────────────────────┘ │
|
|
64
|
+
│ │ │ │
|
|
65
|
+
│ └──────┬───────┘ │
|
|
66
|
+
│ ▼ │
|
|
67
|
+
│ createIframeBridgeServer(doc, awareness) │
|
|
68
|
+
│ │ postMessage │
|
|
69
|
+
└──────────────│──────────────────────────────────────────────┘
|
|
70
|
+
│
|
|
71
|
+
┌──────────┴──────────┐
|
|
72
|
+
▼ ▼
|
|
73
|
+
┌─────────────┐ ┌─────────────┐
|
|
74
|
+
│ Iframe A │ │ Iframe B │
|
|
75
|
+
│ create... │ │ create... │
|
|
76
|
+
│ Provider() │ │ Provider() │
|
|
77
|
+
│ │ │ │
|
|
78
|
+
│ 本地 Y.Doc │ │ 本地 Y.Doc │
|
|
79
|
+
│ + draw.io │ │ + draw.io │
|
|
80
|
+
└─────────────┘ └─────────────┘
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
// Server(父页面)
|
|
85
|
+
import { createIframeBridgeServer } from '@y-mxgraph/iframe-bridge/server';
|
|
86
|
+
|
|
87
|
+
const doc = new Y.Doc();
|
|
88
|
+
const provider = new WebrtcProvider(roomName, doc, { signaling });
|
|
89
|
+
const bridge = createIframeBridgeServer(doc, provider.awareness);
|
|
90
|
+
bridge.addIframe(iframeElement, 'child-1');
|
|
91
|
+
|
|
92
|
+
// Provider(iframe 子页面)
|
|
93
|
+
import { createIframeBridgeProvider } from '@y-mxgraph/iframe-bridge/provider';
|
|
94
|
+
|
|
95
|
+
const doc = new Y.Doc();
|
|
96
|
+
const awareness = new Awareness(doc);
|
|
97
|
+
const bridge = createIframeBridgeProvider(doc, awareness);
|
|
98
|
+
// awareness 状态自动与 server 同步
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
详见 [iframe Bridge 文档](https://mizuka-wu.github.io/y-mxgraph/guide/iframe-bridge)。
|
|
49
102
|
|
|
50
103
|
## 本地开发
|
|
51
104
|
|
package/binding/index.d.ts
CHANGED
|
@@ -31,6 +31,18 @@ export interface BindDrawioFileOptions {
|
|
|
31
31
|
* `file.save()`),可提供自定义实现。
|
|
32
32
|
*/
|
|
33
33
|
applyFileData?: (file: DrawioFile, xml: string) => void;
|
|
34
|
+
/**
|
|
35
|
+
* 是否禁用 draw.io 的 beforeUnload 弹窗,默认 `true`。
|
|
36
|
+
*
|
|
37
|
+
* Yjs 接管持久化后,draw.io 的原生保存状态不再有意义。
|
|
38
|
+
* 但 draw.io 内部会在特定条件下(如 LocalFile 无 fileHandle、
|
|
39
|
+
* 图表非空等)弹出 "All changes will be lost" 或
|
|
40
|
+
* "Ensure your data has been saved" 提示。
|
|
41
|
+
*
|
|
42
|
+
* 设为 `true` 可彻底禁用这些弹窗,适合纯 Yjs 协作场景。
|
|
43
|
+
* 若需要保留原生行为(如使用 File System Access API),设为 `false`。
|
|
44
|
+
*/
|
|
45
|
+
disableBeforeUnload?: boolean;
|
|
34
46
|
}
|
|
35
47
|
/**
|
|
36
48
|
* Y-MXGraph 绑定类,管理 draw.io 文件与 Y.Doc 的双向同步
|
|
@@ -59,9 +71,16 @@ export declare class Binding {
|
|
|
59
71
|
private cleanupUndoManager?;
|
|
60
72
|
/** 初始内容策略 */
|
|
61
73
|
private initialContentStrategy;
|
|
74
|
+
/** draw.io UI 引用,用于重置状态和获取 currentFile */
|
|
75
|
+
private ui;
|
|
62
76
|
/** replace 策略下,构造时 doc 为空,现在 doc 有数据时需要强制替换 */
|
|
63
77
|
private get shouldReplaceWhenDocHasData();
|
|
64
78
|
constructor(file: DrawioFile, options: BindDrawioFileOptions);
|
|
79
|
+
/**
|
|
80
|
+
* 重置 editor 和 file 的 modified 状态及状态栏。
|
|
81
|
+
* Yjs 接管持久化后,draw.io 的原生保存状态不再有意义。
|
|
82
|
+
*/
|
|
83
|
+
private resetEditorStatus;
|
|
65
84
|
/**
|
|
66
85
|
* 销毁绑定,解除所有监听器
|
|
67
86
|
* @param deep - 是否深度清理(包括 awareness/undoManager),默认 false
|
package/binding/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/binding/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAiBvD,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/binding/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAiBvD,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,iBAAiB,CAAC;AAE1E;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAC9B,SAAS,GACT,cAAc,GACd,cAAc,CAAC;AAEnB,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC;IACX,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,WAAW,CAAC,EAAE,CAAC,CAAC,WAAW,CAAC;IAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EACH,OAAO,GACP;QACE,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;IACN;;OAEG;IACH,cAAc,CAAC,EAAE,sBAAsB,CAAC;IACxC;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACxD;;;;;;;;;;OAUG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AA0KD;;;;;;;GAOG;AACH,qBAAa,OAAO;IAClB,wBAAwB;IACxB,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC;IACpB,6BAA6B;IAC7B,OAAO,CAAC,YAAY,CAAe;IACnC,sBAAsB;IACtB,OAAO,CAAC,kBAAkB,CAAS;IACnC,4BAA4B;IAC5B,OAAO,CAAC,cAAc,CAAS;IAC/B,2BAA2B;IAC3B,OAAO,CAAC,UAAU,CAAa;IAC/B,oBAAoB;IACpB,OAAO,CAAC,WAAW,CAKT;IACV,gCAAgC;IAChC,OAAO,CAAC,mBAAmB,CAAC,CAAa;IACzC,yBAAyB;IACzB,OAAO,CAAC,kBAAkB,CAAC,CAAa;IACxC,aAAa;IACb,OAAO,CAAC,sBAAsB,CAAyB;IACvD,0CAA0C;IAC1C,OAAO,CAAC,EAAE,CAAyB;IAEnC,+CAA+C;IAC/C,OAAO,KAAK,2BAA2B,GAEtC;gBAEW,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,qBAAqB;IAoJ5D;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAOzB;;;OAGG;IACH,OAAO,CAAC,IAAI,UAAQ,GAAG,IAAI;IAS3B;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,oBAAoB,CAAC,SAAS,SAAc,GAAG,MAAM;IAa5D;;;OAGG;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO;CAGzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/iframe-bridge/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,mCAAmC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/iframe-bridge/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,KAAK,kBAAkB,GACxB,MAAM,iCAAiC,CAAC"}
|
package/index.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ export type { BindDrawioFileOptions, InitialContentStrategy } from "./binding";
|
|
|
3
3
|
export { xml2doc, doc2xml } from "./transformer";
|
|
4
4
|
export { LOCAL_ORIGIN } from "./helper/origin";
|
|
5
5
|
export { DEFAULT_USER_NAME_KEY, DEFAULT_USER_COLOR_KEY, } from "./binding/collaborator";
|
|
6
|
+
export { createIframeBridgeProvider, createIframeBridgeServer, } from "@y-mxgraph/iframe-bridge";
|
|
7
|
+
export type { IframeBridgeProvider, IframeBridgeServer, } from "@y-mxgraph/iframe-bridge";
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC"}
|
package/package.json
CHANGED
package/types/drawio.d.ts
CHANGED
|
@@ -41,6 +41,8 @@ export interface MxGraph {
|
|
|
41
41
|
/** draw.io 编辑器 */
|
|
42
42
|
export interface DrawioEditor {
|
|
43
43
|
graph: MxGraph;
|
|
44
|
+
setStatus(status: string): void;
|
|
45
|
+
setModified(modified: boolean): void;
|
|
44
46
|
undoManager?: {
|
|
45
47
|
eventListeners?: unknown[];
|
|
46
48
|
undoListener?: (...args: unknown[]) => void;
|
|
@@ -51,6 +53,7 @@ export interface DrawioEditor {
|
|
|
51
53
|
/** draw.io UI */
|
|
52
54
|
export interface DrawioUi {
|
|
53
55
|
editor: DrawioEditor;
|
|
56
|
+
currentFile: DrawioFile | null;
|
|
54
57
|
currentPage?: DrawioPage | null;
|
|
55
58
|
diagramContainer: HTMLElement;
|
|
56
59
|
pages: unknown[];
|
|
@@ -75,6 +78,8 @@ export interface DrawioFile {
|
|
|
75
78
|
patch(patches: unknown[]): void;
|
|
76
79
|
/** 仅赋值 this.data = xml,不触发 UI 重绘 */
|
|
77
80
|
setData(data: string): void;
|
|
81
|
+
isModified(): boolean;
|
|
82
|
+
setModified(modified: boolean): void;
|
|
78
83
|
}
|
|
79
84
|
/** draw.io App(demo 中通过 iframe 访问) */
|
|
80
85
|
export interface DrawioApp {
|
package/types/drawio.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drawio.d.ts","sourceRoot":"","sources":["../../src/types/drawio.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,iBAAiB;AACjB,MAAM,WAAW,UAAU;IACzB,KAAK,IAAI,MAAM,CAAC;CACjB;AAED,iBAAiB;AACjB,MAAM,WAA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IACxC,+CAA+C;IAC/C,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED,mBAAmB;AACnB,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,IAAI,MAAM,CAAC;IAClB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACnC;AAED,mBAAmB;AACnB,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,EAAE,CAAC;IACvB,EAAE,EAAE,QAAQ,CAAC;IACb,KAAK,IAAI,QAAQ,CAAC;IAClB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACvC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChC,oCAAoC;IACpC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,IAAI,OAAO,CAAC;IACtB,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;CACtC;AAED,sCAAsC;AACtC,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,UAAU,GAAG,IAAI,CAAC;IAC/B,MAAM,EAAE,YAAY,CAAC;CACtB"}
|
package/y-mxgraph.cjs.js
CHANGED
|
@@ -4,6 +4,7 @@ const xmlJs = require("xml-js");
|
|
|
4
4
|
const Y = require("yjs");
|
|
5
5
|
const lodashEs = require("lodash-es");
|
|
6
6
|
const colord = require("colord");
|
|
7
|
+
const iframeBridge = require("@y-mxgraph/iframe-bridge");
|
|
7
8
|
function _interopNamespaceDefault(e) {
|
|
8
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
9
10
|
if (e) {
|
|
@@ -1568,6 +1569,7 @@ class Binding {
|
|
|
1568
1569
|
constructor(file, options) {
|
|
1569
1570
|
this.suppressLocalApply = false;
|
|
1570
1571
|
this.docInitialized = false;
|
|
1572
|
+
this.ui = null;
|
|
1571
1573
|
const {
|
|
1572
1574
|
doc,
|
|
1573
1575
|
awareness,
|
|
@@ -1575,13 +1577,18 @@ class Binding {
|
|
|
1575
1577
|
mouseMoveThrottle,
|
|
1576
1578
|
cursor,
|
|
1577
1579
|
initialContent = "replace",
|
|
1578
|
-
applyFileData = defaultApplyFileData
|
|
1580
|
+
applyFileData = defaultApplyFileData,
|
|
1581
|
+
disableBeforeUnload = true
|
|
1579
1582
|
} = options;
|
|
1580
1583
|
this.doc = doc;
|
|
1581
1584
|
this.initialContentStrategy = initialContent;
|
|
1582
1585
|
const ui = file.getUi();
|
|
1583
1586
|
const graph = ui.editor.graph;
|
|
1584
1587
|
this.mxGraphModel = graph.model;
|
|
1588
|
+
this.ui = ui;
|
|
1589
|
+
if (disableBeforeUnload) {
|
|
1590
|
+
ui.onBeforeUnload = () => null;
|
|
1591
|
+
}
|
|
1585
1592
|
this.suppressLocalApply = true;
|
|
1586
1593
|
try {
|
|
1587
1594
|
this.docInitialized = reconcileInitialContent(
|
|
@@ -1616,6 +1623,7 @@ class Binding {
|
|
|
1616
1623
|
}
|
|
1617
1624
|
file.setShadowPages(file.ui.clonePages(file.ui.pages));
|
|
1618
1625
|
applyFilePatch(doc, patch, { origin: LOCAL_ORIGIN });
|
|
1626
|
+
this.resetEditorStatus();
|
|
1619
1627
|
};
|
|
1620
1628
|
this.mxGraphModel.addListener("change", this.mxListener);
|
|
1621
1629
|
this.docObserver = (events, transaction) => {
|
|
@@ -1634,10 +1642,7 @@ class Binding {
|
|
|
1634
1642
|
applyFileData(file, xml);
|
|
1635
1643
|
file.setShadowPages(file.ui.clonePages(file.ui.pages));
|
|
1636
1644
|
initDocSnapshot(doc, false);
|
|
1637
|
-
|
|
1638
|
-
const editor = ui2.editor;
|
|
1639
|
-
editor.setStatus("");
|
|
1640
|
-
editor.setModified(false);
|
|
1645
|
+
this.resetEditorStatus();
|
|
1641
1646
|
} finally {
|
|
1642
1647
|
this.suppressLocalApply = false;
|
|
1643
1648
|
}
|
|
@@ -1656,6 +1661,7 @@ class Binding {
|
|
|
1656
1661
|
try {
|
|
1657
1662
|
file.patch([patch]);
|
|
1658
1663
|
file.setShadowPages(file.ui.clonePages(file.ui.pages));
|
|
1664
|
+
this.resetEditorStatus();
|
|
1659
1665
|
} finally {
|
|
1660
1666
|
this.suppressLocalApply = false;
|
|
1661
1667
|
}
|
|
@@ -1677,6 +1683,18 @@ class Binding {
|
|
|
1677
1683
|
get shouldReplaceWhenDocHasData() {
|
|
1678
1684
|
return this.initialContentStrategy === "replace" && !this.docInitialized;
|
|
1679
1685
|
}
|
|
1686
|
+
/**
|
|
1687
|
+
* 重置 editor 和 file 的 modified 状态及状态栏。
|
|
1688
|
+
* Yjs 接管持久化后,draw.io 的原生保存状态不再有意义。
|
|
1689
|
+
*/
|
|
1690
|
+
resetEditorStatus() {
|
|
1691
|
+
var _a;
|
|
1692
|
+
if (!this.ui)
|
|
1693
|
+
return;
|
|
1694
|
+
this.ui.editor.setModified(false);
|
|
1695
|
+
this.ui.editor.setStatus("");
|
|
1696
|
+
(_a = this.ui.currentFile) == null ? void 0 : _a.setModified(false);
|
|
1697
|
+
}
|
|
1680
1698
|
/**
|
|
1681
1699
|
* 销毁绑定,解除所有监听器
|
|
1682
1700
|
* @param deep - 是否深度清理(包括 awareness/undoManager),默认 false
|
|
@@ -1725,6 +1743,14 @@ class Binding {
|
|
|
1725
1743
|
return new Binding(file, options);
|
|
1726
1744
|
}
|
|
1727
1745
|
}
|
|
1746
|
+
Object.defineProperty(exports, "createIframeBridgeProvider", {
|
|
1747
|
+
enumerable: true,
|
|
1748
|
+
get: () => iframeBridge.createIframeBridgeProvider
|
|
1749
|
+
});
|
|
1750
|
+
Object.defineProperty(exports, "createIframeBridgeServer", {
|
|
1751
|
+
enumerable: true,
|
|
1752
|
+
get: () => iframeBridge.createIframeBridgeServer
|
|
1753
|
+
});
|
|
1728
1754
|
exports.Binding = Binding;
|
|
1729
1755
|
exports.DEFAULT_USER_COLOR_KEY = DEFAULT_USER_COLOR_KEY;
|
|
1730
1756
|
exports.DEFAULT_USER_NAME_KEY = DEFAULT_USER_NAME_KEY;
|