From 7a4d9683f5c7afd49dd10dc270b447c5d7570aa8 Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Sun, 18 Dec 2022 19:59:50 +0100 Subject: [PATCH 1/2] fix: Graph importCells and moveCells now declare dx/dy parameters as optional Also move the JSDoc from implementation to the type declaration. The documentation is thus made available to consumers. --- packages/core/src/view/mixins/CellsMixin.ts | 90 ++++++++++----------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/packages/core/src/view/mixins/CellsMixin.ts b/packages/core/src/view/mixins/CellsMixin.ts index 4be97518dc..9c5bdbe4c3 100644 --- a/packages/core/src/view/mixins/CellsMixin.ts +++ b/packages/core/src/view/mixins/CellsMixin.ts @@ -25,10 +25,9 @@ import { toRadians, } from '../../util/mathUtils'; import { + getSizeForString, setCellStyleFlags, setCellStyles, - setStyle, - getSizeForString, } from '../../util/styleUtils'; import { ALIGN, @@ -157,18 +156,51 @@ declare module '../Graph' { constrainChildCells: (cell: Cell) => void; scaleCell: (cell: Cell, dx: number, dy: number, recurse: boolean) => void; extendParent: (cell: Cell) => void; + /** + * Clones and inserts the given cells into the graph using the move method and returns the inserted cells. This shortcut + * is used if cells are inserted via data transfer. + * + * @param cells Array of {@link Cell} to be imported. + * @param dx Integer that specifies the x-coordinate of the vector. Default is `0`. + * @param dy Integer that specifies the y-coordinate of the vector. Default is `0`. + * @param target {@link mxCell} that represents the new parent of the cells. + * @param evt {@link MouseEvent} that triggered the invocation. + * @param mapping Optional mapping for existing clones. + * @returns the cells that were imported. + */ importCells: ( cells: Cell[], - dx: number, - dy: number, + dx?: number, + dy?: number, target?: Cell | null, evt?: MouseEvent | null, mapping?: any ) => Cell[]; + + /** + * Moves or clones the specified cells and moves the cells or clones by the given amount, adding them to the optional + * target cell. The `evt` is the mouse event as the mouse was released. The change is carried out using {@link cellsMoved}. + * This method fires {@link Event#MOVE_CELLS} while the transaction is in progress. + * + * Use the following code to move all cells in the graph. + * + * ```javascript + * graph.moveCells(graph.getChildCells(null, true, true), 10, 10); + * ``` + * + * @param cells Array of {@link Cell} to be moved, cloned or added to the target. + * @param dx Integer that specifies the x-coordinate of the vector. Default is `0`. + * @param dy Integer that specifies the y-coordinate of the vector. Default is `0`. + * @param clone Boolean indicating if the cells should be cloned. Default is `false`. + * @param target {@link Cell} that represents the new parent of the cells. + * @param evt {@link MouseEvent} that triggered the invocation. + * @param mapping Optional mapping for existing clones. + * @returns the cells that were moved. + */ moveCells: ( cells: Cell[], - dx: number, - dy: number, + dx?: number, + dy?: number, clone?: boolean, target?: Cell | null, evt?: MouseEvent | null, @@ -1819,43 +1851,10 @@ export const CellsMixin: PartialType = { * Group: Cell moving *****************************************************************************/ - /** - * Clones and inserts the given cells into the graph using the move - * method and returns the inserted cells. This shortcut is used if - * cells are inserted via datatransfer. - * - * @param cells Array of {@link Cell} to be imported. - * @param dx Integer that specifies the x-coordinate of the vector. Default is `0`. - * @param dy Integer that specifies the y-coordinate of the vector. Default is `0`. - * @param target {@link mxCell} that represents the new parent of the cells. - * @param evt Mouseevent that triggered the invocation. - * @param mapping Optional mapping for existing clones. - */ - importCells(cells, dx, dy, target = null, evt = null, mapping = {}) { + importCells(cells, dx?: number, dy?: number, target = null, evt = null, mapping = {}) { return this.moveCells(cells, dx, dy, true, target, evt, mapping); }, - /** - * Moves or clones the specified cells and moves the cells or clones by the - * given amount, adding them to the optional target cell. The evt is the - * mouse event as the mouse was released. The change is carried out using - * . This method fires {@link Event#MOVE_CELLS} while the - * transaction is in progress. Returns the cells that were moved. - * - * Use the following code to move all cells in the graph. - * - * ```javascript - * graph.moveCells(graph.getChildCells(null, true, true), 10, 10); - * ``` - * - * @param cells Array of {@link Cells} to be moved, cloned or added to the target. - * @param dx Integer that specifies the x-coordinate of the vector. Default is 0. - * @param dy Integer that specifies the y-coordinate of the vector. Default is 0. - * @param clone Boolean indicating if the cells should be cloned. Default is false. - * @param target that represents the new parent of the cells. - * @param evt Mouseevent that triggered the invocation. - * @param mapping Optional mapping for existing clones. - */ moveCells( cells, dx = 0, @@ -2700,8 +2699,7 @@ export const CellsMixin: PartialType = { */ isCellRotatable(cell) { const style = this.getCurrentCellStyle(cell); - const rotatable = style.rotatable == null ? true : style.rotatable; - return rotatable; + return style.rotatable == null ? true : style.rotatable; }, /** @@ -2734,7 +2732,7 @@ export const CellsMixin: PartialType = { /** * Specifies if the graph should allow moving of cells. This implementation - * updates {@link cellsMsovable}. + * updates {@link cellsMovable}. * * @param value Boolean indicating if the graph should allow moving of cells. */ @@ -2752,9 +2750,9 @@ export const CellsMixin: PartialType = { */ isCellResizable(cell) { const style = this.getCurrentCellStyle(cell); - const r = - this.isCellsResizable() && !this.isCellLocked(cell) && (style.resizable ?? true); - return r; + return ( + this.isCellsResizable() && !this.isCellLocked(cell) && (style.resizable ?? true) + ); }, /** From ae74a384b20214125ea837fc1b26d12d319783ca Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Mon, 19 Dec 2022 10:39:40 +0100 Subject: [PATCH 2/2] Use a comment instead of JSDoc comment --- packages/core/src/view/mixins/CellsMixin.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/view/mixins/CellsMixin.ts b/packages/core/src/view/mixins/CellsMixin.ts index 9c5bdbe4c3..167d243578 100644 --- a/packages/core/src/view/mixins/CellsMixin.ts +++ b/packages/core/src/view/mixins/CellsMixin.ts @@ -1847,9 +1847,9 @@ export const CellsMixin: PartialType = { } }, - /***************************************************************************** - * Group: Cell moving - *****************************************************************************/ + // ************************************************************************************* + // Group: Cell moving + // ************************************************************************************* importCells(cells, dx?: number, dy?: number, target = null, evt = null, mapping = {}) { return this.moveCells(cells, dx, dy, true, target, evt, mapping);