y-mxgraph 0.5.6 → 0.5.7
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/iframe-bridge/{provider.cjs.js → provider.cjs} +1 -1
- package/iframe-bridge/provider.cjs.map +1 -0
- package/iframe-bridge/{provider.es.js → provider.js} +1 -1
- package/iframe-bridge/provider.js.map +1 -0
- package/iframe-bridge/{server.cjs.js → server.cjs} +1 -1
- package/iframe-bridge/server.cjs.map +1 -0
- package/iframe-bridge/{server.es.js → server.js} +1 -1
- package/iframe-bridge/server.js.map +1 -0
- package/index-BGGQoepi.js +241 -0
- package/index-BGGQoepi.js.map +1 -0
- package/index-Dpa3-atS.cjs +257 -0
- package/index-Dpa3-atS.cjs.map +1 -0
- package/package.json +14 -9
- package/transformer.cjs +6 -0
- package/transformer.cjs.map +1 -0
- package/transformer.js +6 -0
- package/transformer.js.map +1 -0
- package/{y-mxgraph.cjs.js → y-mxgraph.cjs} +70 -294
- package/y-mxgraph.cjs.map +1 -0
- package/{y-mxgraph.es.js → y-mxgraph.js} +5 -229
- package/y-mxgraph.js.map +1 -0
- package/iframe-bridge/provider.cjs.js.map +0 -1
- package/iframe-bridge/provider.es.js.map +0 -1
- package/iframe-bridge/server.cjs.js.map +0 -1
- package/iframe-bridge/server.es.js.map +0 -1
- package/y-mxgraph.cjs.js.map +0 -1
- package/y-mxgraph.es.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const transformer = require("./index-Dpa3-atS.cjs");
|
|
4
4
|
const Y = require("yjs");
|
|
5
5
|
const colord = require("colord");
|
|
6
6
|
function _interopNamespaceDefault(e) {
|
|
@@ -20,191 +20,6 @@ function _interopNamespaceDefault(e) {
|
|
|
20
20
|
return Object.freeze(n);
|
|
21
21
|
}
|
|
22
22
|
const Y__namespace = /* @__PURE__ */ _interopNamespaceDefault(Y);
|
|
23
|
-
function deepProcess(node) {
|
|
24
|
-
if (node == null) return;
|
|
25
|
-
if (Array.isArray(node)) {
|
|
26
|
-
for (const item of node) {
|
|
27
|
-
deepProcess(item);
|
|
28
|
-
}
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (typeof node !== "object") return;
|
|
32
|
-
const obj = node;
|
|
33
|
-
const keys = Object.keys(obj);
|
|
34
|
-
for (const key2 of keys) {
|
|
35
|
-
if (key2 === "_attributes") continue;
|
|
36
|
-
let value = obj[key2];
|
|
37
|
-
const keyLower = key2.toLowerCase();
|
|
38
|
-
if ((keyLower === "diagram" || keyLower === "mxcell") && value !== void 0 && !Array.isArray(value)) {
|
|
39
|
-
obj[key2] = [value];
|
|
40
|
-
value = obj[key2];
|
|
41
|
-
}
|
|
42
|
-
if (Array.isArray(value)) {
|
|
43
|
-
for (const v of value) deepProcess(v);
|
|
44
|
-
} else if (value && typeof value === "object") {
|
|
45
|
-
deepProcess(value);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function parse$4(xml) {
|
|
50
|
-
const result = xmlJs.xml2js(xml, { compact: true });
|
|
51
|
-
deepProcess(result);
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
function serializer$1(obj, spaces = 2) {
|
|
55
|
-
return xmlJs.js2xml(obj, {
|
|
56
|
-
compact: true,
|
|
57
|
-
spaces
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
const key$3 = "mxCell";
|
|
61
|
-
const mxGeometryKey = "mxGeometry";
|
|
62
|
-
const mxGeometryAttributeKey = "geometry";
|
|
63
|
-
function parse$3(object) {
|
|
64
|
-
var _a;
|
|
65
|
-
const xmlElement = new Y__namespace.XmlElement("mxCell");
|
|
66
|
-
for (const attribute of Object.keys(object._attributes || {})) {
|
|
67
|
-
xmlElement.setAttribute(
|
|
68
|
-
attribute,
|
|
69
|
-
`${((_a = object._attributes) == null ? void 0 : _a[attribute]) || ""}`
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
if (object[mxGeometryKey]) {
|
|
73
|
-
const geometry = object[mxGeometryKey];
|
|
74
|
-
const geometryString = xmlJs.js2xml(geometry, {
|
|
75
|
-
compact: true
|
|
76
|
-
});
|
|
77
|
-
xmlElement.setAttribute(mxGeometryAttributeKey, geometryString);
|
|
78
|
-
delete object[mxGeometryKey];
|
|
79
|
-
}
|
|
80
|
-
return xmlElement;
|
|
81
|
-
}
|
|
82
|
-
function serialize$2(xmlElement) {
|
|
83
|
-
const rawAttributes = {
|
|
84
|
-
...xmlElement.getAttributes()
|
|
85
|
-
};
|
|
86
|
-
let mxGeometry = null;
|
|
87
|
-
let mxGeometryString;
|
|
88
|
-
if (mxGeometryAttributeKey in rawAttributes) {
|
|
89
|
-
mxGeometryString = rawAttributes[mxGeometryAttributeKey];
|
|
90
|
-
delete rawAttributes[mxGeometryAttributeKey];
|
|
91
|
-
}
|
|
92
|
-
const attributes = {};
|
|
93
|
-
for (const [key2, value] of Object.entries(rawAttributes)) {
|
|
94
|
-
if (typeof value === "string") {
|
|
95
|
-
attributes[key2] = value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
96
|
-
} else if (value != null) {
|
|
97
|
-
attributes[key2] = String(value);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (mxGeometryString) {
|
|
101
|
-
try {
|
|
102
|
-
const parsed = xmlJs.xml2js(mxGeometryString, { compact: true });
|
|
103
|
-
mxGeometry = parsed[mxGeometryKey] ?? null;
|
|
104
|
-
if (mxGeometry && mxGeometry._attributes) {
|
|
105
|
-
mxGeometry._attributes["as"] = "geometry";
|
|
106
|
-
}
|
|
107
|
-
} catch (e) {
|
|
108
|
-
console.warn("[y-mxgraph] Failed to parse mxGeometry:", e);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const obj = {
|
|
112
|
-
_attributes: attributes
|
|
113
|
-
};
|
|
114
|
-
if (mxGeometry) {
|
|
115
|
-
obj[mxGeometryKey] = mxGeometry;
|
|
116
|
-
}
|
|
117
|
-
return obj;
|
|
118
|
-
}
|
|
119
|
-
const key$2 = "mxGraphModel";
|
|
120
|
-
const mxCellOrderKey = key$3 + "Order";
|
|
121
|
-
function parse$2(object, doc) {
|
|
122
|
-
const mxCells = (object.root[key$3] || []).map((cell) => {
|
|
123
|
-
var _a;
|
|
124
|
-
return {
|
|
125
|
-
value: parse$3(cell),
|
|
126
|
-
id: ((_a = cell._attributes) == null ? void 0 : _a.id) || ""
|
|
127
|
-
};
|
|
128
|
-
});
|
|
129
|
-
const mxGraphElement = (doc == null ? void 0 : doc.getMap(key$2)) || new Y__namespace.Map();
|
|
130
|
-
const cells = new Y__namespace.Map();
|
|
131
|
-
const cellsOrder = new Y__namespace.Array();
|
|
132
|
-
mxCells.forEach((cell) => {
|
|
133
|
-
cells.set(cell.id, cell.value);
|
|
134
|
-
});
|
|
135
|
-
cellsOrder.push(mxCells.map((cell) => cell.id));
|
|
136
|
-
mxGraphElement.set(key$3, cells);
|
|
137
|
-
mxGraphElement.set(mxCellOrderKey, cellsOrder);
|
|
138
|
-
return mxGraphElement;
|
|
139
|
-
}
|
|
140
|
-
function serialize$1(map) {
|
|
141
|
-
const cells = map.get(key$3);
|
|
142
|
-
const cellsOrder = map.get(mxCellOrderKey);
|
|
143
|
-
return {
|
|
144
|
-
_attributes: {},
|
|
145
|
-
root: {
|
|
146
|
-
[key$3]: cellsOrder.toArray().map((id) => serialize$2(cells.get(id)))
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
const key$1 = "diagram";
|
|
151
|
-
function parse$1(object) {
|
|
152
|
-
var _a, _b;
|
|
153
|
-
const yDiagramElement = new Y__namespace.Map();
|
|
154
|
-
yDiagramElement.set("name", `${((_a = object._attributes) == null ? void 0 : _a.name) || ""}`);
|
|
155
|
-
yDiagramElement.set("id", `${((_b = object._attributes) == null ? void 0 : _b.id) || ""}`);
|
|
156
|
-
const mxGraphModel = parse$2(object[key$2]);
|
|
157
|
-
yDiagramElement.set(key$2, mxGraphModel);
|
|
158
|
-
return yDiagramElement;
|
|
159
|
-
}
|
|
160
|
-
function serialize(yDiagram) {
|
|
161
|
-
const mxGraphModel = yDiagram.get(key$2);
|
|
162
|
-
return {
|
|
163
|
-
_attributes: {
|
|
164
|
-
name: yDiagram.get("name"),
|
|
165
|
-
id: yDiagram.get("id")
|
|
166
|
-
},
|
|
167
|
-
[key$2]: mxGraphModel ? serialize$1(mxGraphModel) : void 0
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
const key = "mxfile";
|
|
171
|
-
const diagramOrderKey = key$1 + "Order";
|
|
172
|
-
function parse(object, doc) {
|
|
173
|
-
var _a;
|
|
174
|
-
const mxfile = doc.getMap(key);
|
|
175
|
-
mxfile.set("pages", (((_a = object._attributes) == null ? void 0 : _a.pages) || "1") + "");
|
|
176
|
-
const diagramList = object.diagram.map((diagram) => {
|
|
177
|
-
var _a2;
|
|
178
|
-
return {
|
|
179
|
-
value: parse$1(diagram),
|
|
180
|
-
id: ((_a2 = diagram._attributes) == null ? void 0 : _a2.id) || ""
|
|
181
|
-
};
|
|
182
|
-
});
|
|
183
|
-
const diagramMap = new Y__namespace.Map();
|
|
184
|
-
const diagramOrder = new Y__namespace.Array();
|
|
185
|
-
diagramList.forEach((diagram) => {
|
|
186
|
-
diagramMap.set(diagram.id, diagram.value);
|
|
187
|
-
});
|
|
188
|
-
diagramOrder.push(diagramList.map((diagram) => diagram.id));
|
|
189
|
-
mxfile.set(key$1, diagramMap);
|
|
190
|
-
mxfile.set(diagramOrderKey, diagramOrder);
|
|
191
|
-
return mxfile;
|
|
192
|
-
}
|
|
193
|
-
function serializer(yMxFile) {
|
|
194
|
-
const diagrams = yMxFile.get(key$1);
|
|
195
|
-
const diagramOrder = yMxFile.get(
|
|
196
|
-
diagramOrderKey
|
|
197
|
-
);
|
|
198
|
-
const orderIds = diagramOrder ? diagramOrder.toArray() : [];
|
|
199
|
-
const ids = orderIds.length > 0 ? orderIds : diagrams ? Array.from(diagrams.keys()) : [];
|
|
200
|
-
const obj = {
|
|
201
|
-
_attributes: {
|
|
202
|
-
pages: yMxFile.get("pages") || "1"
|
|
203
|
-
},
|
|
204
|
-
[key$1]: ids.map((id) => diagrams.get(id)).filter((d) => !!d).map((diagramElement) => serialize(diagramElement))
|
|
205
|
-
};
|
|
206
|
-
return obj;
|
|
207
|
-
}
|
|
208
23
|
const DIFF_INSERT = "i";
|
|
209
24
|
const DIFF_REMOVE = "r";
|
|
210
25
|
const DIFF_UPDATE = "u";
|
|
@@ -240,11 +55,11 @@ function ensureUniqueOrder(orderArr) {
|
|
|
240
55
|
}
|
|
241
56
|
function applyFilePatch(doc, patch, options) {
|
|
242
57
|
doc.transact(() => {
|
|
243
|
-
const mxfile = doc.getMap(key);
|
|
58
|
+
const mxfile = doc.getMap(transformer.key);
|
|
244
59
|
if (patch[DIFF_REMOVE]) {
|
|
245
|
-
const diagramsMap = mxfile.get(key$1);
|
|
60
|
+
const diagramsMap = mxfile.get(transformer.key$1);
|
|
246
61
|
const orderArr = mxfile.get(
|
|
247
|
-
diagramOrderKey
|
|
62
|
+
transformer.diagramOrderKey
|
|
248
63
|
);
|
|
249
64
|
ensureUniqueOrder(orderArr);
|
|
250
65
|
const orderList = orderArr.toArray();
|
|
@@ -256,9 +71,9 @@ function applyFilePatch(doc, patch, options) {
|
|
|
256
71
|
}
|
|
257
72
|
}
|
|
258
73
|
if (patch[DIFF_INSERT]) {
|
|
259
|
-
const diagramsMap = mxfile.get(key$1);
|
|
74
|
+
const diagramsMap = mxfile.get(transformer.key$1);
|
|
260
75
|
const orderArr = mxfile.get(
|
|
261
|
-
diagramOrderKey
|
|
76
|
+
transformer.diagramOrderKey
|
|
262
77
|
);
|
|
263
78
|
ensureUniqueOrder(orderArr);
|
|
264
79
|
const currentOrder = orderArr.toArray();
|
|
@@ -271,9 +86,9 @@ function applyFilePatch(doc, patch, options) {
|
|
|
271
86
|
const existingIndex = /* @__PURE__ */ new Map();
|
|
272
87
|
existingIds.forEach((id, idx) => existingIndex.set(id, idx));
|
|
273
88
|
const inserts = patch[DIFF_INSERT].map((item, order) => {
|
|
274
|
-
const object = parse
|
|
89
|
+
const object = transformer.parse(item.data);
|
|
275
90
|
const diagramObj = Array.isArray(object == null ? void 0 : object.diagram) ? object.diagram[0] : object == null ? void 0 : object.diagram;
|
|
276
|
-
const diagramElement = parse$1(
|
|
91
|
+
const diagramElement = transformer.parse$1(
|
|
277
92
|
diagramObj
|
|
278
93
|
);
|
|
279
94
|
return {
|
|
@@ -327,7 +142,7 @@ function applyFilePatch(doc, patch, options) {
|
|
|
327
142
|
if (patch[DIFF_UPDATE]) {
|
|
328
143
|
Object.keys(patch[DIFF_UPDATE]).forEach((id) => {
|
|
329
144
|
const diagramsMap = mxfile.get(
|
|
330
|
-
key$1
|
|
145
|
+
transformer.key$1
|
|
331
146
|
);
|
|
332
147
|
const diagram = diagramsMap.get(id);
|
|
333
148
|
if (diagram) {
|
|
@@ -339,10 +154,10 @@ function applyFilePatch(doc, patch, options) {
|
|
|
339
154
|
);
|
|
340
155
|
}
|
|
341
156
|
if (update.cells) {
|
|
342
|
-
const yMxGraphModel = diagram.get(key$2);
|
|
157
|
+
const yMxGraphModel = diagram.get(transformer.key$2);
|
|
343
158
|
if (!yMxGraphModel) return;
|
|
344
|
-
const cellsMap = yMxGraphModel.get(key$3);
|
|
345
|
-
const orderArr = yMxGraphModel.get(mxCellOrderKey);
|
|
159
|
+
const cellsMap = yMxGraphModel.get(transformer.key$3);
|
|
160
|
+
const orderArr = yMxGraphModel.get(transformer.mxCellOrderKey);
|
|
346
161
|
if (!cellsMap || !orderArr) return;
|
|
347
162
|
ensureUniqueOrder(orderArr);
|
|
348
163
|
if (update.cells[DIFF_REMOVE] && update.cells[DIFF_REMOVE].length) {
|
|
@@ -358,9 +173,9 @@ function applyFilePatch(doc, patch, options) {
|
|
|
358
173
|
const id2 = item["id"];
|
|
359
174
|
if (!id2) continue;
|
|
360
175
|
const xmlElement = new Y__namespace.XmlElement("mxCell");
|
|
361
|
-
Object.keys(item).forEach((
|
|
362
|
-
if (
|
|
363
|
-
xmlElement.setAttribute(
|
|
176
|
+
Object.keys(item).forEach((key) => {
|
|
177
|
+
if (key === "previous") return;
|
|
178
|
+
xmlElement.setAttribute(key, item[key]);
|
|
364
179
|
});
|
|
365
180
|
cellsMap.set(id2, xmlElement);
|
|
366
181
|
const previous = item["previous"];
|
|
@@ -462,7 +277,7 @@ function applyFilePatch(doc, patch, options) {
|
|
|
462
277
|
if ("previous" in update) {
|
|
463
278
|
const previous = update.previous || null;
|
|
464
279
|
const orderArr = mxfile.get(
|
|
465
|
-
diagramOrderKey
|
|
280
|
+
transformer.diagramOrderKey
|
|
466
281
|
);
|
|
467
282
|
ensureUniqueOrder(orderArr);
|
|
468
283
|
insertAfterUnique(orderArr, id, previous, false);
|
|
@@ -474,9 +289,9 @@ function applyFilePatch(doc, patch, options) {
|
|
|
474
289
|
}
|
|
475
290
|
function initDocSnapshot(doc, resetSnapshot = false) {
|
|
476
291
|
try {
|
|
477
|
-
const mxfile = doc.getMap(key);
|
|
478
|
-
const diagramsMap = mxfile.get(key$1);
|
|
479
|
-
const orderArr = mxfile.get(diagramOrderKey);
|
|
292
|
+
const mxfile = doc.getMap(transformer.key);
|
|
293
|
+
const diagramsMap = mxfile.get(transformer.key$1);
|
|
294
|
+
const orderArr = mxfile.get(transformer.diagramOrderKey);
|
|
480
295
|
const orderIds = orderArr ? orderArr.toArray() : [];
|
|
481
296
|
const allDiagramIds = orderIds.length > 0 ? orderIds : diagramsMap ? Array.from(diagramsMap.keys()) : [];
|
|
482
297
|
const diagramOrder = resetSnapshot ? [] : allDiagramIds.slice();
|
|
@@ -489,12 +304,12 @@ function initDocSnapshot(doc, resetSnapshot = false) {
|
|
|
489
304
|
for (const d of diagrams) {
|
|
490
305
|
const did = d.get("id") || "";
|
|
491
306
|
if (!did) continue;
|
|
492
|
-
const gm = d.get(key$2);
|
|
307
|
+
const gm = d.get(transformer.key$2);
|
|
493
308
|
if (gm) {
|
|
494
|
-
const order = gm.get(mxCellOrderKey);
|
|
309
|
+
const order = gm.get(transformer.mxCellOrderKey);
|
|
495
310
|
const ids = order ? order.toArray().slice() : [];
|
|
496
311
|
snap.cellsOrder.set(did, ids);
|
|
497
|
-
const cellsMap = gm.get(key$3);
|
|
312
|
+
const cellsMap = gm.get(transformer.key$3);
|
|
498
313
|
const attrMap = /* @__PURE__ */ new Map();
|
|
499
314
|
if (cellsMap) {
|
|
500
315
|
for (const cid of ids) {
|
|
@@ -524,9 +339,9 @@ function generatePatch(events, explicitDoc) {
|
|
|
524
339
|
const doc = (_b = (_a = events[0]) == null ? void 0 : _a.transaction) == null ? void 0 : _b.doc;
|
|
525
340
|
if (!doc) return patch;
|
|
526
341
|
if (!events || events.length === 0) return patch;
|
|
527
|
-
const mxfile = doc.getMap(key);
|
|
528
|
-
const diagramsMap = mxfile.get(key$1);
|
|
529
|
-
const orderArr = mxfile.get(diagramOrderKey);
|
|
342
|
+
const mxfile = doc.getMap(transformer.key);
|
|
343
|
+
const diagramsMap = mxfile.get(transformer.key$1);
|
|
344
|
+
const orderArr = mxfile.get(transformer.diagramOrderKey);
|
|
530
345
|
let snap = docSnapshots.get(doc);
|
|
531
346
|
if (!snap) {
|
|
532
347
|
snap = {
|
|
@@ -557,10 +372,10 @@ function generatePatch(events, explicitDoc) {
|
|
|
557
372
|
for (const d of diagramsList) {
|
|
558
373
|
const did = d.get("id") || "";
|
|
559
374
|
const attrs = /* @__PURE__ */ new Map();
|
|
560
|
-
const gm = d.get(key$2);
|
|
375
|
+
const gm = d.get(transformer.key$2);
|
|
561
376
|
if (gm) {
|
|
562
|
-
const cellsMap = gm.get(key$3);
|
|
563
|
-
const orderArr2 = gm.get(mxCellOrderKey);
|
|
377
|
+
const cellsMap = gm.get(transformer.key$3);
|
|
378
|
+
const orderArr2 = gm.get(transformer.mxCellOrderKey);
|
|
564
379
|
if (cellsMap && orderArr2) {
|
|
565
380
|
const ids = orderArr2.toArray();
|
|
566
381
|
currCellsOrder.set(did, ids);
|
|
@@ -597,7 +412,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
597
412
|
const previous = index <= 0 ? "" : currDiagramOrder[index - 1];
|
|
598
413
|
const yDiagram = diagramsMap.get(id);
|
|
599
414
|
if (!yDiagram) continue;
|
|
600
|
-
const data = serializer
|
|
415
|
+
const data = transformer.serializer({ diagram: transformer.serialize(yDiagram) });
|
|
601
416
|
patch[DIFF_INSERT].push({ id, previous, data });
|
|
602
417
|
insertedDiagramIdGlobal.add(id);
|
|
603
418
|
}
|
|
@@ -714,8 +529,8 @@ function generatePatch(events, explicitDoc) {
|
|
|
714
529
|
const cellsPatch = ensureCellSection(diagramId);
|
|
715
530
|
cellsPatch[DIFF_UPDATE] = cellsPatch[DIFF_UPDATE] || {};
|
|
716
531
|
const cellUpdate = cellsPatch[DIFF_UPDATE][cellId] = cellsPatch[DIFF_UPDATE][cellId] || {};
|
|
717
|
-
for (const
|
|
718
|
-
cellUpdate[
|
|
532
|
+
for (const key of Array.from(changed)) {
|
|
533
|
+
cellUpdate[key] = el.getAttribute(key) || "";
|
|
719
534
|
}
|
|
720
535
|
}
|
|
721
536
|
if (prevDiagramOrder) {
|
|
@@ -769,45 +584,6 @@ function generatePatch(events, explicitDoc) {
|
|
|
769
584
|
docSnapshots.set(doc, snap);
|
|
770
585
|
return patch;
|
|
771
586
|
}
|
|
772
|
-
function xml2ydoc(xml, doc) {
|
|
773
|
-
const object = parse$4(xml);
|
|
774
|
-
const mxfile = object.mxfile;
|
|
775
|
-
const mxGraphModel = object.mxGraphModel;
|
|
776
|
-
if (mxfile) {
|
|
777
|
-
doc.transact(() => {
|
|
778
|
-
parse(mxfile, doc);
|
|
779
|
-
});
|
|
780
|
-
} else if (mxGraphModel) {
|
|
781
|
-
doc.transact(() => {
|
|
782
|
-
parse$2(mxGraphModel, doc);
|
|
783
|
-
});
|
|
784
|
-
} else {
|
|
785
|
-
throw new Error("不支持的文件格式");
|
|
786
|
-
}
|
|
787
|
-
return doc;
|
|
788
|
-
}
|
|
789
|
-
function ydoc2xml(doc, spaces = 0) {
|
|
790
|
-
if (doc.share.has(key)) {
|
|
791
|
-
return serializer$1(
|
|
792
|
-
{
|
|
793
|
-
[key]: serializer(
|
|
794
|
-
doc.share.get(key)
|
|
795
|
-
)
|
|
796
|
-
},
|
|
797
|
-
spaces
|
|
798
|
-
);
|
|
799
|
-
} else if (doc.share.has(key$2)) {
|
|
800
|
-
return serializer$1(
|
|
801
|
-
{
|
|
802
|
-
[key$2]: serialize$1(
|
|
803
|
-
doc.share.get(key$2)
|
|
804
|
-
)
|
|
805
|
-
},
|
|
806
|
-
spaces
|
|
807
|
-
);
|
|
808
|
-
}
|
|
809
|
-
return "";
|
|
810
|
-
}
|
|
811
587
|
const LOCAL_ORIGIN = {};
|
|
812
588
|
function createMxEventObject(name, props) {
|
|
813
589
|
const _props = props || {};
|
|
@@ -832,9 +608,9 @@ function bindUndoManager(doc, file, yUndo) {
|
|
|
832
608
|
const pairs = [];
|
|
833
609
|
const raw = Array.isArray(originUndoManager == null ? void 0 : originUndoManager.eventListeners) ? originUndoManager.eventListeners : [];
|
|
834
610
|
for (let i = 0; i + 1 < raw.length; i += 2) {
|
|
835
|
-
const
|
|
611
|
+
const key = String(raw[i]);
|
|
836
612
|
const fn = raw[i + 1];
|
|
837
|
-
pairs.push([
|
|
613
|
+
pairs.push([key, fn]);
|
|
838
614
|
}
|
|
839
615
|
const mxLike = {
|
|
840
616
|
eventListeners: [],
|
|
@@ -848,9 +624,9 @@ function bindUndoManager(doc, file, yUndo) {
|
|
|
848
624
|
var _a;
|
|
849
625
|
const eventName = (evt == null ? void 0 : evt.name) || (((_a = evt == null ? void 0 : evt.getName) == null ? void 0 : _a.call(evt)) ?? "");
|
|
850
626
|
for (let i = 0; i + 1 < this.eventListeners.length; i += 2) {
|
|
851
|
-
const
|
|
627
|
+
const key = this.eventListeners[i];
|
|
852
628
|
const listener = this.eventListeners[i + 1];
|
|
853
|
-
if (
|
|
629
|
+
if (key === eventName) {
|
|
854
630
|
try {
|
|
855
631
|
listener(this, evt);
|
|
856
632
|
} catch (e) {
|
|
@@ -936,8 +712,8 @@ function bindUndoManager(doc, file, yUndo) {
|
|
|
936
712
|
mxLike.fireEvent(evt);
|
|
937
713
|
};
|
|
938
714
|
yUndo.on("stack-item-updated", updatedHandler);
|
|
939
|
-
pairs.forEach(([
|
|
940
|
-
const k =
|
|
715
|
+
pairs.forEach(([key, fn]) => {
|
|
716
|
+
const k = key.toLowerCase();
|
|
941
717
|
if (k === "add" || k === "clear" || k === "undo" || k === "redo") {
|
|
942
718
|
mxLike.addListener(k, fn);
|
|
943
719
|
}
|
|
@@ -958,33 +734,33 @@ function bindUndoManager(doc, file, yUndo) {
|
|
|
958
734
|
};
|
|
959
735
|
return destroy;
|
|
960
736
|
}
|
|
961
|
-
function getAwarenessStateValue(awareness,
|
|
737
|
+
function getAwarenessStateValue(awareness, key, clientId) {
|
|
962
738
|
const states = awareness.getStates();
|
|
963
739
|
const id = clientId != null ? Number(clientId) : awareness.clientID;
|
|
964
740
|
const clientState = states.get(id);
|
|
965
741
|
if (!clientState) return null;
|
|
966
|
-
if (!
|
|
967
|
-
return getByPath(clientState,
|
|
742
|
+
if (!key) return clientState;
|
|
743
|
+
return getByPath(clientState, key);
|
|
968
744
|
}
|
|
969
745
|
function getByPath(obj, path) {
|
|
970
746
|
const parts = path.split(".");
|
|
971
747
|
let cur = obj;
|
|
972
748
|
for (const part of parts) {
|
|
973
749
|
if (cur == null) return null;
|
|
974
|
-
const
|
|
975
|
-
cur = cur == null ? void 0 : cur[
|
|
750
|
+
const key = Array.isArray(cur) && /^\d+$/.test(part) ? Number(part) : part;
|
|
751
|
+
cur = cur == null ? void 0 : cur[key];
|
|
976
752
|
}
|
|
977
753
|
return cur;
|
|
978
754
|
}
|
|
979
|
-
function setAwarenessStateValue(awareness,
|
|
755
|
+
function setAwarenessStateValue(awareness, key, value, clientId) {
|
|
980
756
|
const id = awareness.clientID;
|
|
981
757
|
if (id !== awareness.clientID) return false;
|
|
982
|
-
if (!
|
|
758
|
+
if (!key) {
|
|
983
759
|
awareness.setLocalState(value);
|
|
984
760
|
return true;
|
|
985
761
|
}
|
|
986
762
|
const current = awareness.getLocalState() || {};
|
|
987
|
-
const next = setByPath(current,
|
|
763
|
+
const next = setByPath(current, key, value);
|
|
988
764
|
awareness.setLocalState(next);
|
|
989
765
|
return true;
|
|
990
766
|
}
|
|
@@ -995,19 +771,19 @@ function setByPath(obj, path, value) {
|
|
|
995
771
|
for (let i = 0; i < parts.length; i++) {
|
|
996
772
|
const part = parts[i];
|
|
997
773
|
const isIndex = /^\d+$/.test(part);
|
|
998
|
-
const
|
|
774
|
+
const key = isIndex ? Number(part) : part;
|
|
999
775
|
const isLast = i === parts.length - 1;
|
|
1000
776
|
if (isLast) {
|
|
1001
|
-
cur[
|
|
777
|
+
cur[key] = value;
|
|
1002
778
|
} else {
|
|
1003
|
-
let next = cur[
|
|
779
|
+
let next = cur[key];
|
|
1004
780
|
const nextIsIndex = /^\d+$/.test(parts[i + 1]);
|
|
1005
781
|
if (next == null) {
|
|
1006
782
|
next = nextIsIndex ? [] : {};
|
|
1007
783
|
} else {
|
|
1008
784
|
next = Array.isArray(next) ? next.slice() : { ...next };
|
|
1009
785
|
}
|
|
1010
|
-
cur[
|
|
786
|
+
cur[key] = next;
|
|
1011
787
|
cur = next;
|
|
1012
788
|
}
|
|
1013
789
|
}
|
|
@@ -1269,7 +1045,7 @@ function bindSelection(file, options) {
|
|
|
1269
1045
|
const cells = graph.getSelectionModel().cells;
|
|
1270
1046
|
const ids = Object.keys(cells || {}).map(
|
|
1271
1047
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1272
|
-
(
|
|
1048
|
+
(key) => getId(cells[key])
|
|
1273
1049
|
).filter(Boolean);
|
|
1274
1050
|
awareness.setLocalStateField("selection", { ids, pageId });
|
|
1275
1051
|
};
|
|
@@ -1423,7 +1199,7 @@ const defaultApplyFileData = (file, xml) => {
|
|
|
1423
1199
|
function mergeFileIntoDoc(doc, fileXml, strategy) {
|
|
1424
1200
|
let parsed;
|
|
1425
1201
|
try {
|
|
1426
|
-
parsed = parse
|
|
1202
|
+
parsed = transformer.parse(fileXml);
|
|
1427
1203
|
} catch (err) {
|
|
1428
1204
|
console.warn(
|
|
1429
1205
|
"[y-mxgraph] 合并失败,file XML 解析异常,回退到 replace:",
|
|
@@ -1438,9 +1214,9 @@ function mergeFileIntoDoc(doc, fileXml, strategy) {
|
|
|
1438
1214
|
);
|
|
1439
1215
|
return false;
|
|
1440
1216
|
}
|
|
1441
|
-
const mxfileMap = doc.getMap(key);
|
|
1442
|
-
const diagramMap = mxfileMap.get(key$1);
|
|
1443
|
-
const diagramOrder = mxfileMap.get(diagramOrderKey);
|
|
1217
|
+
const mxfileMap = doc.getMap(transformer.key);
|
|
1218
|
+
const diagramMap = mxfileMap.get(transformer.key$1);
|
|
1219
|
+
const diagramOrder = mxfileMap.get(transformer.diagramOrderKey);
|
|
1444
1220
|
if (!diagramMap || !diagramOrder) {
|
|
1445
1221
|
console.warn("[y-mxgraph] 合并失败,doc 结构不完整,回退到 replace");
|
|
1446
1222
|
return false;
|
|
@@ -1454,7 +1230,7 @@ function mergeFileIntoDoc(doc, fileXml, strategy) {
|
|
|
1454
1230
|
if (docHas && strategy === "merge-remote") {
|
|
1455
1231
|
continue;
|
|
1456
1232
|
}
|
|
1457
|
-
const yDiagram = parse$1(
|
|
1233
|
+
const yDiagram = transformer.parse$1(
|
|
1458
1234
|
diagram
|
|
1459
1235
|
);
|
|
1460
1236
|
diagramMap.set(id, yDiagram);
|
|
@@ -1466,13 +1242,13 @@ function mergeFileIntoDoc(doc, fileXml, strategy) {
|
|
|
1466
1242
|
return true;
|
|
1467
1243
|
}
|
|
1468
1244
|
function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
1469
|
-
const mxfileMap = doc.getMap(key);
|
|
1245
|
+
const mxfileMap = doc.getMap(transformer.key);
|
|
1470
1246
|
const docHasData = mxfileMap.size > 0;
|
|
1471
1247
|
const fileHasAnyData = !!file.data;
|
|
1472
1248
|
const fileHasDiagrams = fileHasAnyData && file.data.includes("<diagram");
|
|
1473
1249
|
if (strategy === "replace") {
|
|
1474
1250
|
if (docHasData) {
|
|
1475
|
-
const xml2 = ydoc2xml(doc);
|
|
1251
|
+
const xml2 = transformer.ydoc2xml(doc);
|
|
1476
1252
|
if (xml2 && xml2.includes("<diagram")) {
|
|
1477
1253
|
applyFileData(file, xml2);
|
|
1478
1254
|
} else if (!fileHasAnyData) {
|
|
@@ -1492,7 +1268,7 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1492
1268
|
if (!docHasData && fileHasDiagrams) {
|
|
1493
1269
|
try {
|
|
1494
1270
|
doc.transact(() => {
|
|
1495
|
-
xml2ydoc(file.data, doc);
|
|
1271
|
+
transformer.xml2ydoc(file.data, doc);
|
|
1496
1272
|
});
|
|
1497
1273
|
return true;
|
|
1498
1274
|
} catch (err) {
|
|
@@ -1505,7 +1281,7 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1505
1281
|
}
|
|
1506
1282
|
}
|
|
1507
1283
|
if (docHasData && !fileHasDiagrams) {
|
|
1508
|
-
const xml2 = ydoc2xml(doc);
|
|
1284
|
+
const xml2 = transformer.ydoc2xml(doc);
|
|
1509
1285
|
if (xml2 && xml2.includes("<diagram")) {
|
|
1510
1286
|
applyFileData(file, xml2);
|
|
1511
1287
|
} else if (!fileHasAnyData) {
|
|
@@ -1515,11 +1291,11 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1515
1291
|
}
|
|
1516
1292
|
const ok = mergeFileIntoDoc(doc, file.data, strategy);
|
|
1517
1293
|
if (!ok) {
|
|
1518
|
-
const xml2 = ydoc2xml(doc);
|
|
1294
|
+
const xml2 = transformer.ydoc2xml(doc);
|
|
1519
1295
|
if (xml2 && xml2.includes("<diagram")) applyFileData(file, xml2);
|
|
1520
1296
|
return mxfileMap.size > 0;
|
|
1521
1297
|
}
|
|
1522
|
-
const xml = ydoc2xml(doc);
|
|
1298
|
+
const xml = transformer.ydoc2xml(doc);
|
|
1523
1299
|
if (xml && xml.includes("<diagram")) applyFileData(file, xml);
|
|
1524
1300
|
return true;
|
|
1525
1301
|
}
|
|
@@ -1573,7 +1349,7 @@ class Binding {
|
|
|
1573
1349
|
if (patchKeys.length === 0) return;
|
|
1574
1350
|
if (!this.docInitialized) {
|
|
1575
1351
|
doc.transact(() => {
|
|
1576
|
-
xml2ydoc(file.data, doc);
|
|
1352
|
+
transformer.xml2ydoc(file.data, doc);
|
|
1577
1353
|
initDocSnapshot(doc, false);
|
|
1578
1354
|
});
|
|
1579
1355
|
this.docInitialized = true;
|
|
@@ -1589,10 +1365,10 @@ class Binding {
|
|
|
1589
1365
|
return;
|
|
1590
1366
|
}
|
|
1591
1367
|
if (this.shouldReplaceWhenDocHasData && !transaction.local) {
|
|
1592
|
-
const mxfileMap = doc.getMap(key);
|
|
1593
|
-
const diagramMap = mxfileMap.get(key$1);
|
|
1368
|
+
const mxfileMap = doc.getMap(transformer.key);
|
|
1369
|
+
const diagramMap = mxfileMap.get(transformer.key$1);
|
|
1594
1370
|
if (diagramMap && diagramMap.size > 0) {
|
|
1595
|
-
const xml = ydoc2xml(doc);
|
|
1371
|
+
const xml = transformer.ydoc2xml(doc);
|
|
1596
1372
|
if (xml && xml.includes("<diagram")) {
|
|
1597
1373
|
this.suppressLocalApply = true;
|
|
1598
1374
|
try {
|
|
@@ -1622,7 +1398,7 @@ class Binding {
|
|
|
1622
1398
|
this.suppressLocalApply = false;
|
|
1623
1399
|
}
|
|
1624
1400
|
};
|
|
1625
|
-
doc.getMap(key).observeDeep(this.docObserver);
|
|
1401
|
+
doc.getMap(transformer.key).observeDeep(this.docObserver);
|
|
1626
1402
|
if (awareness) {
|
|
1627
1403
|
this.cleanupCollaborator = bindCollaborator(file, {
|
|
1628
1404
|
awareness,
|
|
@@ -1657,7 +1433,7 @@ class Binding {
|
|
|
1657
1433
|
destroy(deep = false) {
|
|
1658
1434
|
var _a, _b;
|
|
1659
1435
|
this.mxGraphModel.removeListener("change", this.mxListener);
|
|
1660
|
-
this.doc.getMap(key).unobserveDeep(this.docObserver);
|
|
1436
|
+
this.doc.getMap(transformer.key).unobserveDeep(this.docObserver);
|
|
1661
1437
|
if (deep) {
|
|
1662
1438
|
(_a = this.cleanupCollaborator) == null ? void 0 : _a.call(this);
|
|
1663
1439
|
(_b = this.cleanupUndoManager) == null ? void 0 : _b.call(this);
|
|
@@ -1698,10 +1474,10 @@ class Binding {
|
|
|
1698
1474
|
return new Binding(file, options);
|
|
1699
1475
|
}
|
|
1700
1476
|
}
|
|
1477
|
+
exports.xml2ydoc = transformer.xml2ydoc;
|
|
1478
|
+
exports.ydoc2xml = transformer.ydoc2xml;
|
|
1701
1479
|
exports.Binding = Binding;
|
|
1702
1480
|
exports.DEFAULT_USER_COLOR_KEY = DEFAULT_USER_COLOR_KEY;
|
|
1703
1481
|
exports.DEFAULT_USER_NAME_KEY = DEFAULT_USER_NAME_KEY;
|
|
1704
1482
|
exports.LOCAL_ORIGIN = LOCAL_ORIGIN;
|
|
1705
|
-
|
|
1706
|
-
exports.ydoc2xml = ydoc2xml;
|
|
1707
|
-
//# sourceMappingURL=y-mxgraph.cjs.js.map
|
|
1483
|
+
//# sourceMappingURL=y-mxgraph.cjs.map
|