y-mxgraph 0.3.2 → 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/binding/index.d.ts +9 -1
- package/binding/index.d.ts.map +1 -1
- package/iframe-bridge/index.d.ts +2 -0
- package/iframe-bridge/index.d.ts.map +1 -0
- package/iframe-bridge/provider.cjs.js +113 -1
- package/iframe-bridge/provider.cjs.js.map +1 -1
- package/iframe-bridge/provider.es.js +113 -1
- package/iframe-bridge/provider.es.js.map +1 -1
- package/iframe-bridge/server.cjs.js +34 -6
- package/iframe-bridge/server.cjs.js.map +1 -1
- package/iframe-bridge/server.es.js +34 -6
- package/iframe-bridge/server.es.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/transformer/index.d.ts +2 -2
- package/transformer/index.d.ts.map +1 -1
- package/y-mxgraph.cjs.js +14 -13
- package/y-mxgraph.cjs.js.map +1 -1
- package/y-mxgraph.es.js +15 -14
- package/y-mxgraph.es.js.map +1 -1
package/y-mxgraph.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { xml2js, js2xml } from "xml-js";
|
|
2
2
|
import * as Y from "yjs";
|
|
3
3
|
import { throttle } from "lodash-es";
|
|
4
4
|
import { colord } from "colord";
|
|
@@ -531,7 +531,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
531
531
|
u.cells = u.cells || {};
|
|
532
532
|
return u.cells;
|
|
533
533
|
};
|
|
534
|
-
const orderIds = orderArr.toArray();
|
|
534
|
+
const orderIds = (orderArr == null ? void 0 : orderArr.toArray()) ?? [];
|
|
535
535
|
const currDiagramOrder = orderIds.length > 0 ? orderIds : diagramsMap ? Array.from(diagramsMap.keys()) : [];
|
|
536
536
|
const diagramsList = currDiagramOrder.map((id) => diagramsMap.get(id)).filter((d) => !!d);
|
|
537
537
|
const currCellsOrder = /* @__PURE__ */ new Map();
|
|
@@ -751,7 +751,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
751
751
|
docSnapshots.set(doc, snap);
|
|
752
752
|
return patch;
|
|
753
753
|
}
|
|
754
|
-
function
|
|
754
|
+
function xml2ydoc(xml, doc) {
|
|
755
755
|
const object = parse$4(xml);
|
|
756
756
|
const mxfile = object.mxfile;
|
|
757
757
|
const mxGraphModel = object.mxGraphModel;
|
|
@@ -768,7 +768,7 @@ function xml2doc(xml, doc) {
|
|
|
768
768
|
}
|
|
769
769
|
return doc;
|
|
770
770
|
}
|
|
771
|
-
function
|
|
771
|
+
function ydoc2xml(doc, spaces = 0) {
|
|
772
772
|
if (doc.share.has(key)) {
|
|
773
773
|
return serializer$1(
|
|
774
774
|
{
|
|
@@ -1426,7 +1426,7 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1426
1426
|
const fileHasDiagrams = fileHasAnyData && file.data.includes("<diagram");
|
|
1427
1427
|
if (strategy === "replace") {
|
|
1428
1428
|
if (docHasData) {
|
|
1429
|
-
const xml2 =
|
|
1429
|
+
const xml2 = ydoc2xml(doc);
|
|
1430
1430
|
if (xml2 && xml2.includes("<diagram")) {
|
|
1431
1431
|
applyFileData(file, xml2);
|
|
1432
1432
|
} else if (!fileHasAnyData) {
|
|
@@ -1446,12 +1446,12 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1446
1446
|
if (!docHasData && fileHasDiagrams) {
|
|
1447
1447
|
try {
|
|
1448
1448
|
doc.transact(() => {
|
|
1449
|
-
|
|
1449
|
+
xml2ydoc(file.data, doc);
|
|
1450
1450
|
});
|
|
1451
1451
|
return true;
|
|
1452
1452
|
} catch (err) {
|
|
1453
1453
|
console.warn(
|
|
1454
|
-
"[y-mxgraph] merge 模式下
|
|
1454
|
+
"[y-mxgraph] merge 模式下 xml2ydoc 失败,回退 replace:",
|
|
1455
1455
|
err
|
|
1456
1456
|
);
|
|
1457
1457
|
applyFileData(file, Binding.generateFileTemplate("diagram-0"));
|
|
@@ -1459,7 +1459,7 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1459
1459
|
}
|
|
1460
1460
|
}
|
|
1461
1461
|
if (docHasData && !fileHasDiagrams) {
|
|
1462
|
-
const xml2 =
|
|
1462
|
+
const xml2 = ydoc2xml(doc);
|
|
1463
1463
|
if (xml2 && xml2.includes("<diagram")) {
|
|
1464
1464
|
applyFileData(file, xml2);
|
|
1465
1465
|
} else if (!fileHasAnyData) {
|
|
@@ -1469,11 +1469,11 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1469
1469
|
}
|
|
1470
1470
|
const ok = mergeFileIntoDoc(doc, file.data, strategy);
|
|
1471
1471
|
if (!ok) {
|
|
1472
|
-
const xml2 =
|
|
1472
|
+
const xml2 = ydoc2xml(doc);
|
|
1473
1473
|
if (xml2 && xml2.includes("<diagram")) applyFileData(file, xml2);
|
|
1474
1474
|
return mxfileMap.size > 0;
|
|
1475
1475
|
}
|
|
1476
|
-
const xml =
|
|
1476
|
+
const xml = ydoc2xml(doc);
|
|
1477
1477
|
if (xml && xml.includes("<diagram")) applyFileData(file, xml);
|
|
1478
1478
|
return true;
|
|
1479
1479
|
}
|
|
@@ -1493,6 +1493,7 @@ class Binding {
|
|
|
1493
1493
|
disableBeforeUnload = true
|
|
1494
1494
|
} = options;
|
|
1495
1495
|
this.doc = doc;
|
|
1496
|
+
this.file = file;
|
|
1496
1497
|
this.initialContentStrategy = initialContent;
|
|
1497
1498
|
const ui = file.getUi();
|
|
1498
1499
|
const graph = ui.editor.graph;
|
|
@@ -1526,7 +1527,7 @@ class Binding {
|
|
|
1526
1527
|
if (patchKeys.length === 0) return;
|
|
1527
1528
|
if (!this.docInitialized) {
|
|
1528
1529
|
doc.transact(() => {
|
|
1529
|
-
|
|
1530
|
+
xml2ydoc(file.data, doc);
|
|
1530
1531
|
initDocSnapshot(doc, false);
|
|
1531
1532
|
});
|
|
1532
1533
|
this.docInitialized = true;
|
|
@@ -1545,7 +1546,7 @@ class Binding {
|
|
|
1545
1546
|
const mxfileMap = doc.getMap(key);
|
|
1546
1547
|
const diagramMap = mxfileMap.get(key$1);
|
|
1547
1548
|
if (diagramMap && diagramMap.size > 0) {
|
|
1548
|
-
const xml =
|
|
1549
|
+
const xml = ydoc2xml(doc);
|
|
1549
1550
|
if (xml && xml.includes("<diagram")) {
|
|
1550
1551
|
this.suppressLocalApply = true;
|
|
1551
1552
|
try {
|
|
@@ -1656,7 +1657,7 @@ export {
|
|
|
1656
1657
|
DEFAULT_USER_COLOR_KEY,
|
|
1657
1658
|
DEFAULT_USER_NAME_KEY,
|
|
1658
1659
|
LOCAL_ORIGIN,
|
|
1659
|
-
|
|
1660
|
-
|
|
1660
|
+
xml2ydoc,
|
|
1661
|
+
ydoc2xml
|
|
1661
1662
|
};
|
|
1662
1663
|
//# sourceMappingURL=y-mxgraph.es.js.map
|