From 2bcacecc7edfb1eba71c1098e5d9ec64fc8b22a1 Mon Sep 17 00:00:00 2001 From: mcyph <20507948+mcyph@users.noreply.github.com> Date: Sun, 25 Apr 2021 20:47:53 +1000 Subject: [PATCH] various bugfixes --- docs/stashed/grapheditor/www/js/Graph.js | 4 ++-- docs/stashed/grapheditor/www/js/Sidebar.js | 2 +- packages/core/src/handler/mxConstraintHandler.js | 2 +- packages/core/src/handler/mxEdgeHandler.js | 2 +- packages/core/src/layout/mxGraphLayout.js | 2 +- packages/core/src/serialization/mxCodec.js | 14 +++++++++++++- packages/core/src/util/animate/mxMorphing.js | 2 +- packages/core/src/util/gui/mxWindow.js | 1 + packages/core/src/view/cell/mxCell.ts | 2 +- packages/html/stories/Boundary.stories.js | 7 ++----- packages/html/stories/Constituent.stories.js | 2 +- packages/html/stories/DynamicLoading.stories.js | 3 ++- packages/html/stories/Groups.stories.js | 2 +- packages/html/stories/JsonData.stories.js | 3 ++- packages/html/stories/LoD.stories.js | 4 ++-- packages/html/stories/PageBreaks.stories.js | 1 + packages/html/stories/Stencils.stories.js | 7 ++++++- packages/html/stories/SwimLanes.stories.js | 4 ++-- packages/html/stories/UserObject.stories.js | 3 ++- 19 files changed, 43 insertions(+), 24 deletions(-) diff --git a/docs/stashed/grapheditor/www/js/Graph.js b/docs/stashed/grapheditor/www/js/Graph.js index 84929bb49..e19a9ff08 100644 --- a/docs/stashed/grapheditor/www/js/Graph.js +++ b/docs/stashed/grapheditor/www/js/Graph.js @@ -4694,7 +4694,7 @@ HoverIcons.prototype.getState = function(state) // Uses connectable parent vertex if child is not connectable if (cell.isVertex() && !cell.isConnectable()) { - let parent = this.cell.getParent(); + let parent = cell.getParent(); if (parent.isVertex() && parent.isConnectable()) { @@ -9616,7 +9616,7 @@ if (typeof mxVertexHandler != 'undefined') this.graph.setSelectionCell(cell); // Enables focus outline for edges and edge labels - let parent = this.cell.getParent(); + let parent = cell.getParent(); let geo = cell.getGeometry(); if ((parent.isEdge() && geo != null && geo.relative) || diff --git a/docs/stashed/grapheditor/www/js/Sidebar.js b/docs/stashed/grapheditor/www/js/Sidebar.js index 1275aeb73..eda6492cf 100644 --- a/docs/stashed/grapheditor/www/js/Sidebar.js +++ b/docs/stashed/grapheditor/www/js/Sidebar.js @@ -3447,7 +3447,7 @@ Sidebar.prototype.createDragSource = function(elt, dropHandler, preview, cells, if (cell != null && !cell.isConnectable() && !cell.isEdge()) { - let parent = this.cell.getParent(); + let parent = cell.getParent(); if (parent.isVertex() && parent.isConnectable()) diff --git a/packages/core/src/handler/mxConstraintHandler.js b/packages/core/src/handler/mxConstraintHandler.js index c075ac75d..8a877b791 100644 --- a/packages/core/src/handler/mxConstraintHandler.js +++ b/packages/core/src/handler/mxConstraintHandler.js @@ -206,7 +206,7 @@ class mxConstraintHandler { // Uses connectable parent vertex if one exists if (cell != null && !cell.isConnectable()) { - const parent = this.cell.getParent(); + const parent = cell.getParent(); if ( parent.isVertex() && diff --git a/packages/core/src/handler/mxEdgeHandler.js b/packages/core/src/handler/mxEdgeHandler.js index ae4993c5b..68c8817cd 100644 --- a/packages/core/src/handler/mxEdgeHandler.js +++ b/packages/core/src/handler/mxEdgeHandler.js @@ -602,7 +602,7 @@ class mxEdgeHandler { // Uses connectable parent vertex if one exists if (cell != null && !cell.isConnectable()) { - const parent = this.cell.getParent(); + const parent = cell.getParent(); if ( parent.isVertex() && diff --git a/packages/core/src/layout/mxGraphLayout.js b/packages/core/src/layout/mxGraphLayout.js index 73c657ee1..99d28e38c 100644 --- a/packages/core/src/layout/mxGraphLayout.js +++ b/packages/core/src/layout/mxGraphLayout.js @@ -424,7 +424,7 @@ class mxGraphLayout { } if (this.parent != null) { - const parent = this.cell.getParent(); + const parent = cell.getParent(); geo = geo.clone(); if (parent != null && parent !== this.parent) { diff --git a/packages/core/src/serialization/mxCodec.js b/packages/core/src/serialization/mxCodec.js index 317b280a2..7bedba59d 100644 --- a/packages/core/src/serialization/mxCodec.js +++ b/packages/core/src/serialization/mxCodec.js @@ -12,7 +12,19 @@ import mxCell from '../view/cell/mxCell'; import mxLog from '../util/gui/mxLog'; import { getFunctionName } from '../util/mxStringUtils'; import { importNode, isNode } from '../util/mxDomUtils'; -import { createXmlDocument } from '../util/mxXmlUtils'; + +const createXmlDocument = () => { + // Put here from '../util/mxXmlUtils' to eliminate circular dependency + let doc = null; + + if (document.implementation && document.implementation.createDocument) { + doc = document.implementation.createDocument('', '', null); + } else if ('ActiveXObject' in window) { + doc = mxUtils.createMsXmlDocument(); + } + + return doc; +}; /** * XML codec for JavaScript object graphs. See {@link mxObjectCodec} for a diff --git a/packages/core/src/util/animate/mxMorphing.js b/packages/core/src/util/animate/mxMorphing.js index 6bd092e0d..7baeff68d 100644 --- a/packages/core/src/util/animate/mxMorphing.js +++ b/packages/core/src/util/animate/mxMorphing.js @@ -205,7 +205,7 @@ class mxMorphing extends mxAnimation { let result = null; if (cell != null) { - const parent = this.cell.getParent(); + const parent = cell.getParent(); const geo = cell.getGeometry(); result = this.getOriginForCell(parent); diff --git a/packages/core/src/util/gui/mxWindow.js b/packages/core/src/util/gui/mxWindow.js index ed0b081be..cffa65251 100644 --- a/packages/core/src/util/gui/mxWindow.js +++ b/packages/core/src/util/gui/mxWindow.js @@ -15,6 +15,7 @@ import mxConstants from '../mxConstants'; import { br, write } from '../mxDomUtils'; import mxResources from '../mxResources'; import { getClientX, getClientY } from '../mxEventUtils'; +import { htmlEntities } from '../mxStringUtils'; /** * Basic window inside a document. diff --git a/packages/core/src/view/cell/mxCell.ts b/packages/core/src/view/cell/mxCell.ts index 53dd2b018..c1164604e 100644 --- a/packages/core/src/view/cell/mxCell.ts +++ b/packages/core/src/view/cell/mxCell.ts @@ -908,7 +908,7 @@ class mxCell { getOrigin(): mxPoint { let result = null; - if (this != null) { + if (this != null && this.getParent()) { result = (this.getParent()).getOrigin(); if (!this.isEdge()) { diff --git a/packages/html/stories/Boundary.stories.js b/packages/html/stories/Boundary.stories.js index 221cc8c54..73d555c36 100644 --- a/packages/html/stories/Boundary.stories.js +++ b/packages/html/stories/Boundary.stories.js @@ -22,12 +22,9 @@ const Template = ({ label, ...args }) => { mxGraph, mxEvent, mxRubberband, - mxConnectionHandler, - mxConnectionConstraint, - mxGeometry, - mxPolyline, mxPoint, - mxConstants + mxConstants, + mxUtils } = mxgraph; const container = document.createElement('div'); diff --git a/packages/html/stories/Constituent.stories.js b/packages/html/stories/Constituent.stories.js index 06bc306dd..f753b9dc4 100644 --- a/packages/html/stories/Constituent.stories.js +++ b/packages/html/stories/Constituent.stories.js @@ -43,7 +43,7 @@ const Template = ({ label, ...args }) => { getInitialCellForEvent(me) { let cell = super.getInitialCellForEvent(me); if (this.graph.isPart(cell)) { - cell = this.cell.getParent(); + cell = cell.getParent(); } return cell; } diff --git a/packages/html/stories/DynamicLoading.stories.js b/packages/html/stories/DynamicLoading.stories.js index bd20e8631..f67d1d9d6 100644 --- a/packages/html/stories/DynamicLoading.stories.js +++ b/packages/html/stories/DynamicLoading.stories.js @@ -13,6 +13,7 @@ const Template = ({ label, ...args }) => { const { mxGraph, mxText, + mxEffects, mxEvent, mxConstants, mxPerimeter, @@ -108,7 +109,7 @@ const Template = ({ label, ...args }) => { } // Merges the response model with the client model - graph.getModel().mergeChildren(model.getRoot().getChildAt(0), parent); + graph.getModel().mergeChildren(graph.getModel().getRoot().getChildAt(0), parent); // Moves the given cell to the center let geo = cell.getGeometry(); diff --git a/packages/html/stories/Groups.stories.js b/packages/html/stories/Groups.stories.js index 8cadac301..31bc83b27 100644 --- a/packages/html/stories/Groups.stories.js +++ b/packages/html/stories/Groups.stories.js @@ -64,7 +64,7 @@ const Template = ({ label, ...args }) => { !this.graph.isValidRoot(parent) ) { cell = parent; - parent = this.cell.getParent(); + parent = cell.getParent(); } } diff --git a/packages/html/stories/JsonData.stories.js b/packages/html/stories/JsonData.stories.js index bea764e75..5ff3498dc 100644 --- a/packages/html/stories/JsonData.stories.js +++ b/packages/html/stories/JsonData.stories.js @@ -1,4 +1,5 @@ import mxgraph from '@mxgraph/core'; +import { popup } from '@mxgraph/core/src/util/gui/mxWindow'; import { globalTypes } from '../.storybook/preview'; @@ -89,7 +90,7 @@ const Template = ({ label, ...args }) => { mxDomHelpers.button('Show JSON', function() { const encoder = new mxCodec(); const node = encoder.encode(graph.getModel()); - mxWindow.popup(mxUtils.getXml(node), true); + popup(mxUtils.getXml(node), true); }) ); diff --git a/packages/html/stories/LoD.stories.js b/packages/html/stories/LoD.stories.js index b551d3a00..e4f1d17cd 100644 --- a/packages/html/stories/LoD.stories.js +++ b/packages/html/stories/LoD.stories.js @@ -31,8 +31,8 @@ const Template = ({ label, ...args }) => { graph.centerZoom = false; // Links level of detail to zoom level but can be independent of zoom - const isVisible = function(cell) { - return cell.lod == null || cell.lod / 2 < this.view.scale; + const isVisible = function() { + return this.lod == null || this.lod / 2 < graph.view.scale; }; // Gets the default parent for inserting new cells. This diff --git a/packages/html/stories/PageBreaks.stories.js b/packages/html/stories/PageBreaks.stories.js index 23d0081f5..613a3e741 100644 --- a/packages/html/stories/PageBreaks.stories.js +++ b/packages/html/stories/PageBreaks.stories.js @@ -20,6 +20,7 @@ export default { const Template = ({ label, ...args }) => { const { mxGraph, + mxRectangle, mxRubberband, mxDomHelpers, mxEvent diff --git a/packages/html/stories/Stencils.stories.js b/packages/html/stories/Stencils.stories.js index acf4cb810..a5b1730dd 100644 --- a/packages/html/stories/Stencils.stories.js +++ b/packages/html/stories/Stencils.stories.js @@ -1,4 +1,5 @@ import mxgraph from '@mxgraph/core'; +import { load } from "@mxgraph/core/src/util/network/mxXmlRequest"; import { globalTypes } from '../.storybook/preview'; @@ -23,11 +24,15 @@ const Template = ({ label, ...args }) => { mxConnectionHandler, mxDomHelpers, mxEdgeHandler, + mxEvent, mxPoint, mxCellHighlight, mxConstants, mxVertexHandler, + mxRubberband, mxShape, + mxStencil, + mxStencilRegistry, mxCellRenderer, mxUtils } = mxgraph; @@ -120,7 +125,7 @@ const Template = ({ label, ...args }) => { mxCellRenderer.registerShape('customShape', CustomShape); // Loads the stencils into the registry - const req = mxUtils.load('stencils.xml'); + const req = load('stencils.xml'); const root = req.getDocumentElement(); let shape = root.firstChild; diff --git a/packages/html/stories/SwimLanes.stories.js b/packages/html/stories/SwimLanes.stories.js index 6b3f46d2d..a68d4a825 100644 --- a/packages/html/stories/SwimLanes.stories.js +++ b/packages/html/stories/SwimLanes.stories.js @@ -224,7 +224,7 @@ const Template = ({ label, ...args }) => { // TODO super cannot be used here // let style = super.getStyle(); let style; - if (this.isCellCollapsed()) { + if (this.isCollapsed()) { if (style != null) { style += ';'; } else { @@ -286,7 +286,7 @@ const Template = ({ label, ...args }) => { }; // Adds cells to the model in a single step - model.batchUpdate(() => { + graph.batchUpdate(() => { const pool1 = insertVertex({ parent, value: 'Pool 1', diff --git a/packages/html/stories/UserObject.stories.js b/packages/html/stories/UserObject.stories.js index 9a0aadbbc..c92954b5a 100644 --- a/packages/html/stories/UserObject.stories.js +++ b/packages/html/stories/UserObject.stories.js @@ -1,4 +1,5 @@ import mxgraph from '@mxgraph/core'; +import { popup } from '@mxgraph/core/src/util/gui/mxWindow'; import { globalTypes } from '../.storybook/preview'; @@ -168,7 +169,7 @@ const Template = ({ label, ...args }) => { mxDomHelpers.button('View XML', function() { const encoder = new mxCodec(); const node = encoder.encode(graph.getModel()); - mxWindow.popup(mxUtils.getPrettyXml(node), true); + popup(mxUtils.getPrettyXml(node), true); }) );