y-mxgraph 0.5.2 → 0.5.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.
- package/README.md +12 -14
- package/README.zh-CN.md +12 -14
- package/helper/throttle.d.ts +2 -0
- package/helper/throttle.d.ts.map +1 -0
- package/package.json +1 -3
- package/y-mxgraph.cjs.js +29 -2
- package/y-mxgraph.cjs.js.map +1 -1
- package/y-mxgraph.es.js +28 -1
- package/y-mxgraph.es.js.map +1 -1
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ pnpm --filter @y-mxgraph/ws-demo dev # Start client on port 5174
|
|
|
91
91
|
|
|
92
92
|
## iframe Bridge
|
|
93
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
|
|
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 **providers** (iframe children) via `postMessage`.
|
|
95
95
|
|
|
96
96
|
```text
|
|
97
97
|
┌─────────────────────────────────────────────────────────────┐
|
|
@@ -102,20 +102,18 @@ pnpm --filter @y-mxgraph/ws-demo dev # Start client on port 5174
|
|
|
102
102
|
│ │ │ │
|
|
103
103
|
│ └──────┬───────┘ │
|
|
104
104
|
│ ▼ │
|
|
105
|
-
│ createIframeBridgeServer(doc, awareness)
|
|
105
|
+
│ createIframeBridgeServer(iframe, doc, awareness) │
|
|
106
106
|
│ │ postMessage │
|
|
107
107
|
└──────────────│──────────────────────────────────────────────┘
|
|
108
108
|
│
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
│
|
|
113
|
-
│
|
|
114
|
-
│
|
|
115
|
-
│
|
|
116
|
-
|
|
117
|
-
│ + draw.io │ │ + draw.io │
|
|
118
|
-
└─────────────┘ └─────────────┘
|
|
109
|
+
▼
|
|
110
|
+
┌─────────────┐
|
|
111
|
+
│ Iframe │
|
|
112
|
+
│ │
|
|
113
|
+
│ local Y.Doc │
|
|
114
|
+
│ + Awareness │
|
|
115
|
+
│ + draw.io │
|
|
116
|
+
└─────────────┘
|
|
119
117
|
```
|
|
120
118
|
|
|
121
119
|
```ts
|
|
@@ -135,8 +133,8 @@ const undoManager = new Y.UndoManager(doc, {
|
|
|
135
133
|
trackedOrigins: new Set([LOCAL_ORIGIN, IFRAME_ORIGIN]),
|
|
136
134
|
});
|
|
137
135
|
|
|
138
|
-
|
|
139
|
-
bridge
|
|
136
|
+
// Create bridge server, bound directly to the target iframe
|
|
137
|
+
const bridge = createIframeBridgeServer(iframeElement, doc, awareness, { undoManager });
|
|
140
138
|
|
|
141
139
|
// Undo/redo from parent page
|
|
142
140
|
document.getElementById('undo-btn')!.onclick = () => {
|
package/README.zh-CN.md
CHANGED
|
@@ -53,7 +53,7 @@ App.main((app) => {
|
|
|
53
53
|
|
|
54
54
|
## iframe Bridge
|
|
55
55
|
|
|
56
|
-
`@y-mxgraph/iframe-bridge` 支持在 iframe 隔离环境中进行协同编辑。**Server**(父页面)管理网络连接(y-webrtc、y-websocket 等),通过 `postMessage` 将 Y.Doc 和 Awareness
|
|
56
|
+
`@y-mxgraph/iframe-bridge` 支持在 iframe 隔离环境中进行协同编辑。**Server**(父页面)管理网络连接(y-webrtc、y-websocket 等),通过 `postMessage` 将 Y.Doc 和 Awareness 同步到 **Provider**(iframe 子页面)。
|
|
57
57
|
|
|
58
58
|
```text
|
|
59
59
|
┌─────────────────────────────────────────────────────────────┐
|
|
@@ -64,20 +64,18 @@ App.main((app) => {
|
|
|
64
64
|
│ │ │ │
|
|
65
65
|
│ └──────┬───────┘ │
|
|
66
66
|
│ ▼ │
|
|
67
|
-
│ createIframeBridgeServer(doc, awareness)
|
|
67
|
+
│ createIframeBridgeServer(iframe, doc, awareness) │
|
|
68
68
|
│ │ postMessage │
|
|
69
69
|
└──────────────│──────────────────────────────────────────────┘
|
|
70
70
|
│
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
│
|
|
75
|
-
│
|
|
76
|
-
│
|
|
77
|
-
│
|
|
78
|
-
|
|
79
|
-
│ + draw.io │ │ + draw.io │
|
|
80
|
-
└─────────────┘ └─────────────┘
|
|
71
|
+
▼
|
|
72
|
+
┌─────────────┐
|
|
73
|
+
│ Iframe │
|
|
74
|
+
│ │
|
|
75
|
+
│ 本地 Y.Doc │
|
|
76
|
+
│ + Awareness │
|
|
77
|
+
│ + draw.io │
|
|
78
|
+
└─────────────┘
|
|
81
79
|
```
|
|
82
80
|
|
|
83
81
|
```ts
|
|
@@ -97,8 +95,8 @@ const undoManager = new Y.UndoManager(doc, {
|
|
|
97
95
|
trackedOrigins: new Set([LOCAL_ORIGIN, IFRAME_ORIGIN]),
|
|
98
96
|
});
|
|
99
97
|
|
|
100
|
-
|
|
101
|
-
bridge
|
|
98
|
+
// 创建 bridge server,直接绑定到目标 iframe
|
|
99
|
+
const bridge = createIframeBridgeServer(iframeElement, doc, awareness, { undoManager });
|
|
102
100
|
|
|
103
101
|
// 从父页面执行撤销/重做
|
|
104
102
|
document.getElementById('undo-btn')!.onclick = () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../src/helper/throttle.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,EAAE,EAAE,CAAC,EACL,IAAI,EAAE,MAAM,GACX,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAgCvD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "y-mxgraph",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "Yjs binding for draw.io (mxGraph) documents",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yjs",
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"graph",
|
|
16
16
|
"sync"
|
|
17
17
|
],
|
|
18
|
-
"type": "module",
|
|
19
18
|
"main": "./y-mxgraph.cjs.js",
|
|
20
19
|
"module": "./y-mxgraph.es.js",
|
|
21
20
|
"types": "./index.d.ts",
|
|
@@ -38,7 +37,6 @@
|
|
|
38
37
|
},
|
|
39
38
|
"dependencies": {
|
|
40
39
|
"colord": "^2.9.3",
|
|
41
|
-
"lodash-es": "^4.17.21",
|
|
42
40
|
"xml-js": "^1.6.11"
|
|
43
41
|
},
|
|
44
42
|
"peerDependencies": {
|
package/y-mxgraph.cjs.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const xmlJs = require("xml-js");
|
|
4
4
|
const Y = require("yjs");
|
|
5
|
-
const lodashEs = require("lodash-es");
|
|
6
5
|
const colord = require("colord");
|
|
7
6
|
function _interopNamespaceDefault(e) {
|
|
8
7
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
@@ -1064,6 +1063,34 @@ function hslToHex(h, s, l) {
|
|
|
1064
1063
|
const b = Math.round((b1 + m) * 255);
|
|
1065
1064
|
return "#" + [r, g, b].map((v) => v.toString(16).padStart(2, "0")).join("");
|
|
1066
1065
|
}
|
|
1066
|
+
function throttle(fn, wait) {
|
|
1067
|
+
let lastTime = 0;
|
|
1068
|
+
let timeoutId = null;
|
|
1069
|
+
let lastArgs = null;
|
|
1070
|
+
return (...args) => {
|
|
1071
|
+
const now = Date.now();
|
|
1072
|
+
const remaining = wait - (now - lastTime);
|
|
1073
|
+
lastArgs = args;
|
|
1074
|
+
if (remaining <= 0) {
|
|
1075
|
+
if (timeoutId) {
|
|
1076
|
+
clearTimeout(timeoutId);
|
|
1077
|
+
timeoutId = null;
|
|
1078
|
+
}
|
|
1079
|
+
lastTime = now;
|
|
1080
|
+
return fn(...args);
|
|
1081
|
+
}
|
|
1082
|
+
if (!timeoutId) {
|
|
1083
|
+
timeoutId = setTimeout(() => {
|
|
1084
|
+
lastTime = Date.now();
|
|
1085
|
+
timeoutId = null;
|
|
1086
|
+
if (lastArgs) {
|
|
1087
|
+
fn(...lastArgs);
|
|
1088
|
+
}
|
|
1089
|
+
}, remaining);
|
|
1090
|
+
}
|
|
1091
|
+
return void 0;
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1067
1094
|
function createCursorImage(color) {
|
|
1068
1095
|
const w = 8;
|
|
1069
1096
|
const h = 12;
|
|
@@ -1116,7 +1143,7 @@ function bindCursor(file, options) {
|
|
|
1116
1143
|
},
|
|
1117
1144
|
mouseUp: function() {
|
|
1118
1145
|
},
|
|
1119
|
-
mouseMove:
|
|
1146
|
+
mouseMove: throttle(function(_sender, event) {
|
|
1120
1147
|
var _a;
|
|
1121
1148
|
const containerRect = graph.container.getBoundingClientRect();
|
|
1122
1149
|
const { translate, scale } = graph.view;
|