diff --git a/packages/core/src/atomic_changes/mxSelectionChange.ts b/packages/core/src/atomic_changes/mxSelectionChange.ts index 5cc2af7ee..6885bdcca 100644 --- a/packages/core/src/atomic_changes/mxSelectionChange.ts +++ b/packages/core/src/atomic_changes/mxSelectionChange.ts @@ -4,6 +4,7 @@ import mxLog from '../util/gui/mxLog'; import mxEvent from '../util/event/mxEvent'; import mxGraphSelectionModel from '../view/graph/mxGraphSelectionModel'; import mxCell from '../view/cell/mxCell'; +import mxCellArray from "../view/cell/mxCellArray"; /** * @class mxSelectionChange @@ -12,8 +13,8 @@ import mxCell from '../view/cell/mxCell'; class mxSelectionChange { constructor( selectionModel: mxGraphSelectionModel, - added: mxCell[] = [], - removed: mxCell[] = [] + added: mxCellArray = new mxCellArray(), + removed: mxCellArray = new mxCellArray() ) { this.selectionModel = selectionModel; this.added = added.slice(); @@ -22,9 +23,9 @@ class mxSelectionChange { selectionModel: mxGraphSelectionModel; - added: mxCell[]; + added: mxCellArray; - removed: mxCell[]; + removed: mxCellArray; /** * Changes the current root of the view. diff --git a/packages/core/src/util/datatypes/style/mxStylesheet.js b/packages/core/src/util/datatypes/style/mxStylesheet.ts similarity index 86% rename from packages/core/src/util/datatypes/style/mxStylesheet.js rename to packages/core/src/util/datatypes/style/mxStylesheet.ts index 78980691b..ec79f7118 100644 --- a/packages/core/src/util/datatypes/style/mxStylesheet.js +++ b/packages/core/src/util/datatypes/style/mxStylesheet.ts @@ -15,6 +15,7 @@ import { import mxPerimeter from './mxPerimeter'; import mxUtils from '../../mxUtils'; import { clone } from '../../mxCloneUtils'; +import StyleMap from "../../../view/graph/StyleMap"; /** * @class mxStylesheet @@ -67,7 +68,7 @@ import { clone } from '../../mxCloneUtils'; */ class mxStylesheet { constructor() { - this.styles = {}; + this.styles = new StyleMap(); this.putDefaultVertexStyle(this.createDefaultVertexStyle()); this.putDefaultEdgeStyle(this.createDefaultEdgeStyle()); @@ -77,15 +78,13 @@ class mxStylesheet { * Maps from names to cell styles. Each cell style is a map of key, * value pairs. */ - // styles: StyleMap; - styles; + styles: StyleMap; /** * Creates and returns the default vertex style. */ - // createDefaultVertexStyle(): StyleMap; - createDefaultVertexStyle() { - const style = {}; + createDefaultVertexStyle(): StyleMap { + const style = new StyleMap(); style.shape = SHAPE_RECTANGLE; style.perimeter = mxPerimeter.RectanglePerimeter; style.verticalAlign = ALIGN_MIDDLE; @@ -99,9 +98,8 @@ class mxStylesheet { /** * Creates and returns the default edge style. */ - // createDefaultEdgeStyle(): StyleMap; - createDefaultEdgeStyle() { - const style = {}; + createDefaultEdgeStyle(): StyleMap { + const style = new StyleMap(); style.shape = SHAPE_CONNECTOR; style.endArrow = ARROW_CLASSIC; style.verticalAlign = ALIGN_MIDDLE; @@ -116,33 +114,29 @@ class mxStylesheet { * stylename. * @param style Key, value pairs that define the style. */ - // putDefaultVertexStyle(style: StyleMap): void; - putDefaultVertexStyle(style) { + putDefaultVertexStyle(style: StyleMap): void { this.putCellStyle('defaultVertex', style); } /** * Sets the default style for edges using defaultEdge as the stylename. */ - // putDefaultEdgeStyle(style: StyleMap): void; - putDefaultEdgeStyle(style) { + putDefaultEdgeStyle(style: StyleMap): void { this.putCellStyle('defaultEdge', style); } /** * Returns the default style for vertices. */ - // getDefaultVertexStyle(): StyleMap; - getDefaultVertexStyle() { - return this.styles.defaultVertex; + getDefaultVertexStyle(): StyleMap { + return this.styles.defaultVertex; } /** * Sets the default style for edges. */ - // getDefaultEdgeStyle(): StyleMap; - getDefaultEdgeStyle() { - return this.styles.defaultEdge; + getDefaultEdgeStyle(): StyleMap { + return this.styles.defaultEdge; } /** @@ -178,8 +172,7 @@ class mxStylesheet { * @param name Name for the style to be stored. * @param style Key, value pairs that define the style. */ - // putCellStyle(name: string, style: StyleMap): void; - putCellStyle(name, style) { + putCellStyle(name: string, style: StyleMap): void { this.styles[name] = style; } @@ -190,8 +183,9 @@ class mxStylesheet { * @param name String of the form [(stylename|key=value);] that represents the style. * @param defaultStyle Default style to be returned if no style can be found. */ - // getCellStyle(name: string, defaultStyle?: StyleMap): StyleMap; - getCellStyle(name, defaultStyle) { + getCellStyle(name: string, + defaultStyle: StyleMap=new StyleMap()): StyleMap { + let style = defaultStyle; if (name != null && name.length > 0) { @@ -200,12 +194,11 @@ class mxStylesheet { if (style != null && name.charAt(0) !== ';') { style = clone(style); } else { - style = {}; + style = new StyleMap(); } // Parses each key, value pair into the existing style - for (let i = 0; i < pairs.length; i += 1) { - const tmp = pairs[i]; + for (const tmp of pairs) { const pos = tmp.indexOf('='); if (pos >= 0) { diff --git a/packages/core/src/util/storage/mxClipboard.ts b/packages/core/src/util/storage/mxClipboard.ts index e0451b1b9..9fe69ee60 100644 --- a/packages/core/src/util/storage/mxClipboard.ts +++ b/packages/core/src/util/storage/mxClipboard.ts @@ -5,9 +5,9 @@ * Type definitions from the typed-mxgraph project */ -import mxCell from '../../view/cell/mxCell'; import mxGraph from '../../view/graph/mxGraph'; import mxGraphModel from "../../view/graph/mxGraphModel"; +import mxCellArray from "../../view/cell/mxCellArray"; /** * @class @@ -86,42 +86,36 @@ class mxClipboard { * Defines the step size to offset the cells after each paste operation. * Default is 10. */ - // static STEPSIZE: number; static STEPSIZE: number = 10; /** * Counts the number of times the clipboard data has been inserted. */ - // static insertCount: number; static insertCount: number = 1; /** * Holds the array of {@link mxCell} currently in the clipboard. */ - // static cells: Array; - static cells: mxCell[] | null = null; + static cells: mxCellArray | null = null; /** * Sets the cells in the clipboard. Fires a {@link mxEvent.CHANGE} event. */ - // static setCells(cells: Array): void; - static setCells(cells: mxCell[] | null) { + static setCells(cells: mxCellArray | null): void { mxClipboard.cells = cells; } /** * Returns the cells in the clipboard. */ - // static getCells(): Array; - static getCells() { + static getCells(): mxCellArray | null { return mxClipboard.cells; } /** * Returns true if the clipboard currently has not data stored. */ - // static isEmpty(): boolean; - static isEmpty() { + static isEmpty(): boolean { return mxClipboard.getCells() == null; } @@ -133,8 +127,7 @@ class mxClipboard { * @param graph - {@link mxGraph} that contains the cells to be cut. * @param cells - Optional array of {@link mxCell} to be cut. */ - // static cut(graph: mxGraph, cells?: Array): Array; - static cut(graph: mxGraph, cells: mxCell[] | null) { + static cut(graph: mxGraph, cells?: mxCellArray | null): mxCellArray | null { cells = mxClipboard.copy(graph, cells); mxClipboard.insertCount = 0; mxClipboard.removeCells(graph, cells); @@ -149,8 +142,7 @@ class mxClipboard { * @param graph - {@link mxGraph} that contains the cells to be cut. * @param cells - Array of {@link mxCell} to be cut. */ - // static removeCells(graph: mxGraph, cells: Array): void; - static removeCells(graph: mxGraph, cells: mxCell[] | null) { + static removeCells(graph: mxGraph, cells: mxCellArray | null): void { graph.removeCells(cells); } @@ -162,12 +154,11 @@ class mxClipboard { * @param graph - {@link mxGraph} that contains the cells to be copied. * @param cells - Optional array of {@link mxCell} to be copied. */ - // static copy(graph: mxGraph, cells?: Array): Array; - static copy(graph: mxGraph, cells: mxCell[] | null): mxCell[] | null { + static copy(graph: mxGraph, cells?: mxCellArray | null): mxCellArray | null { cells = cells || graph.getSelectionCells(); - const result = graph.getExportableCells((graph.model).getTopmostCells(cells)); + const result = (graph.getExportableCells(cells)).getTopmostCells(); mxClipboard.insertCount = 1; - mxClipboard.setCells(graph.cloneCells(result)); + mxClipboard.setCells(graph.cloneCells(result)); return result; } @@ -183,8 +174,7 @@ class mxClipboard { * * @param graph - {@link mxGraph} to paste the {@link cells} into. */ - // static paste(graph: mxGraph): Array; - static paste(graph: mxGraph) { + static paste(graph: mxGraph): mxCellArray | null { let cells = null; if (!mxClipboard.isEmpty()) { @@ -196,7 +186,7 @@ class mxClipboard { // Increments the counter and selects the inserted cells mxClipboard.insertCount++; - graph.setSelectionCells(cells); + graph.setSelectionCells(cells); } return cells; diff --git a/packages/core/src/view/cell/mxCell.ts b/packages/core/src/view/cell/mxCell.ts index 846d1a7fa..38341426c 100644 --- a/packages/core/src/view/cell/mxCell.ts +++ b/packages/core/src/view/cell/mxCell.ts @@ -11,6 +11,7 @@ import mxCellOverlay from './mxCellOverlay'; import { clone } from '../../util/mxCloneUtils'; import mxPoint from '../../util/datatypes/mxPoint'; import mxCellPath from './mxCellPath'; +import mxCellArray from "./mxCellArray"; /** * Cells are the elements of the graph model. They represent the state @@ -73,8 +74,8 @@ class mxCell { } // TODO: Document me!!! - getChildren(): mxCell[] { - return this.children || []; + getChildren(): mxCellArray { + return this.children || new mxCellArray(); } // TODO: Document me! @@ -89,87 +90,73 @@ class mxCell { /** * Holds the Id. Default is null. */ - // id: string; id: string | null = null; /** * Holds the user object. Default is null. */ - // value: any; value: any = null; /** * Holds the . Default is null. */ - // geometry: mxGeometry; geometry: mxGeometry | null = null; /** * Holds the style as a string of the form [(stylename|key=value);]. Default is * null. */ - // style: string; style: string | null = null; /** * Specifies whether the cell is a vertex. Default is false. */ - // vertex: boolean; vertex: boolean = false; /** * Specifies whether the cell is an edge. Default is false. */ - // edge: boolean; edge: boolean = false; /** * Specifies whether the cell is connectable. Default is true. */ - // connectable: boolean; connectable: boolean = true; /** * Specifies whether the cell is visible. Default is true. */ - // visible: boolean; visible: boolean = true; /** * Specifies whether the cell is collapsed. Default is false. */ - // collapsed: boolean; collapsed: boolean = false; /** * Reference to the parent cell. */ - // parent: mxCell; parent: mxCell | null = null; /** * Reference to the source terminal. */ - // source: mxCell; source: mxCell | null = null; /** * Reference to the target terminal. */ - // target: mxCell; target: mxCell | null = null; /** * Holds the child cells. */ - // children: Array; - children: mxCell[] | null = null; + children: mxCellArray | null = null; /** * Holds the edges. */ - // edges: Array; - edges: mxCell[] | null = null; + edges: mxCellArray | null = null; /** * List of members that should not be cloned inside . This field is @@ -178,7 +165,6 @@ class mxCell { * to mark transient fields since transient modifiers are not supported by * the language. */ - // mxTransient: Array; mxTransient: string[] = [ 'id', 'value', @@ -192,7 +178,6 @@ class mxCell { /** * Returns the Id of the cell as a string. */ - // getId(): string; getId(): string | null { return this.id; } @@ -200,7 +185,6 @@ class mxCell { /** * Sets the Id of the cell to the given string. */ - // setId(id: string): void; setId(id: string): void { this.id = id; } @@ -209,7 +193,6 @@ class mxCell { * Returns the user object of the cell. The user * object is stored in . */ - // getValue(): any; getValue(): any { return this.value; } @@ -218,7 +201,6 @@ class mxCell { * Sets the user object of the cell. The user object * is stored in . */ - // setValue(value: any): void; setValue(value: number): void { this.value = value; } @@ -229,7 +211,6 @@ class mxCell { * replaces the user object with the given value and * returns the old user object. */ - // valueChanged(newValue: any): any; valueChanged(newValue: any): any { const previous = this.getValue(); this.setValue(newValue); @@ -239,7 +220,6 @@ class mxCell { /** * Returns the that describes the . */ - // getGeometry(): mxGeometry; getGeometry(): mxGeometry | null { return this.geometry; } @@ -247,7 +227,6 @@ class mxCell { /** * Sets the to be used as the . */ - // setGeometry(geometry: mxGeometry): void; setGeometry(geometry: mxGeometry | null): void { this.geometry = geometry; } @@ -255,15 +234,13 @@ class mxCell { /** * Returns a string that describes the