From e73c6ebdc0015c8c620122e05b1e425462b353de Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Tue, 29 Jul 2025 19:36:20 +0200 Subject: [PATCH 1/4] feat: accept more nullish parameter in various methods This prepares the migration of the "Wires" story to TypeScript. Add a new factory method in `CellMarker` to override the `CellHighlight` instance Export missing `ConnectionHandlerCellMarker` class The signature of some methods of the following classes now accepts null and/or undefined because their implementation already supported it: - CellMixin - ConnectionHandler - EdgeMixin - Geometry.setTerminalPoint - GraphView.updateFixedTerminalPoint - VertexMixin Improve JSDoc in various locations. --- packages/core/src/index.ts | 1 + packages/core/src/view/GraphView.ts | 4 +- packages/core/src/view/cell/CellHighlight.ts | 2 +- packages/core/src/view/cell/CellMarker.ts | 10 +- packages/core/src/view/geometry/Geometry.ts | 2 +- .../core/src/view/mixins/CellsMixin.type.ts | 2 +- packages/core/src/view/mixins/EdgeMixin.ts | 8 +- .../core/src/view/mixins/EdgeMixin.type.ts | 16 +- packages/core/src/view/mixins/VertexMixin.ts | 8 +- .../core/src/view/mixins/VertexMixin.type.ts | 12 +- .../src/view/plugins/ConnectionHandler.ts | 157 +++++++++--------- .../core/src/view/plugins/PanningHandler.ts | 6 +- 12 files changed, 123 insertions(+), 105 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 1c1e05b3f7..15f9331c87 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -49,6 +49,7 @@ export { Editor } from './editor/Editor.js'; export { default as CellHighlight } from './view/cell/CellHighlight.js'; export { default as CellMarker } from './view/cell/CellMarker.js'; +export { ConnectionHandlerCellMarker } from './view/plugins/ConnectionHandler'; export { default as CellTracker } from './view/cell/CellTracker.js'; export { default as ConstraintHandler } from './view/handler/ConstraintHandler.js'; export { default as EdgeHandler } from './view/handler/EdgeHandler.js'; diff --git a/packages/core/src/view/GraphView.ts b/packages/core/src/view/GraphView.ts index 08dbeb85be..77b5bdb6c1 100644 --- a/packages/core/src/view/GraphView.ts +++ b/packages/core/src/view/GraphView.ts @@ -1138,10 +1138,10 @@ export class GraphView extends EventSource { edge: CellState, terminal: CellState | null, source: boolean, - constraint: ConnectionConstraint + constraint: ConnectionConstraint | null ) { edge.setAbsoluteTerminalPoint( - this.getFixedTerminalPoint(edge, terminal, source, constraint), + this.getFixedTerminalPoint(edge, terminal, source, constraint), source ); } diff --git a/packages/core/src/view/cell/CellHighlight.ts b/packages/core/src/view/cell/CellHighlight.ts index 9b773caf91..26237a6e25 100644 --- a/packages/core/src/view/cell/CellHighlight.ts +++ b/packages/core/src/view/cell/CellHighlight.ts @@ -228,7 +228,7 @@ class CellHighlight { } /** - * Marks the {@link arkedState} and fires a {@link ark} event. + * Marks the {@link CellState} and fires a {@link InternalEvent.MARK} event. */ highlight(state: CellState | null = null): void { if (this.state !== state) { diff --git a/packages/core/src/view/cell/CellMarker.ts b/packages/core/src/view/cell/CellMarker.ts index e2f60777a1..404683712e 100644 --- a/packages/core/src/view/cell/CellMarker.ts +++ b/packages/core/src/view/cell/CellMarker.ts @@ -129,7 +129,15 @@ class CellMarker extends EventSource { this.validColor = validColor; this.invalidColor = invalidColor; this.hotspot = hotspot; - this.highlight = new CellHighlight(graph); + this.highlight = this.createCellHighlight(graph); + } + + /** + * Hook method to override the implementation of {@link highlight}. + * @since 0.22.0 + */ + protected createCellHighlight(graph: AbstractGraph): CellHighlight { + return new CellHighlight(graph); } /** diff --git a/packages/core/src/view/geometry/Geometry.ts b/packages/core/src/view/geometry/Geometry.ts index 5e4439a68f..75b924249b 100644 --- a/packages/core/src/view/geometry/Geometry.ts +++ b/packages/core/src/view/geometry/Geometry.ts @@ -192,7 +192,7 @@ class Geometry extends Rectangle { * @param {Point} point to be used as the new source or target point. * @param {Boolean} isSource that specifies if the source or target point should be set. */ - setTerminalPoint(point: Point, isSource: boolean) { + setTerminalPoint(point: Point | null, isSource: boolean) { if (isSource) { this.sourcePoint = point; } else { diff --git a/packages/core/src/view/mixins/CellsMixin.type.ts b/packages/core/src/view/mixins/CellsMixin.type.ts index 008efbe724..4488b1c351 100644 --- a/packages/core/src/view/mixins/CellsMixin.type.ts +++ b/packages/core/src/view/mixins/CellsMixin.type.ts @@ -299,7 +299,7 @@ declare module '../AbstractGraph' { */ addCell: ( cell: Cell, - parent: Cell | null, + parent?: Cell | null, index?: number | null, source?: Cell | null, target?: Cell | null diff --git a/packages/core/src/view/mixins/EdgeMixin.ts b/packages/core/src/view/mixins/EdgeMixin.ts index c8d7503c3d..4d60f1eae4 100644 --- a/packages/core/src/view/mixins/EdgeMixin.ts +++ b/packages/core/src/view/mixins/EdgeMixin.ts @@ -247,16 +247,16 @@ export const EdgeMixin: PartialType = { }, createEdge( - parent = null, + _parent = null, id, value, - source = null, - target = null, + _source = null, + _target = null, style: CellStyle = {} ) { // Creates the edge const edge = new Cell(value, new Geometry(), style); - edge.setId(id); + edge.setId(id!); // the auto-generated id is done when adding the cell to the model edge.setEdge(true); edge.geometry!.relative = true; // geometry is set when creating the cell above return edge; diff --git a/packages/core/src/view/mixins/EdgeMixin.type.ts b/packages/core/src/view/mixins/EdgeMixin.type.ts index 52ddee0665..1504ebe094 100644 --- a/packages/core/src/view/mixins/EdgeMixin.type.ts +++ b/packages/core/src/view/mixins/EdgeMixin.type.ts @@ -183,9 +183,9 @@ declare module '../AbstractGraph' { * @param style Optional object that defines the cell style. */ insertEdge( - parent: Cell | null, - id: string | null | undefined, - value: EdgeParametersValue, + parent?: Cell | null, + id?: string | null, + value?: EdgeParametersValue, source?: Cell | null, target?: Cell | null, style?: CellStyle @@ -213,11 +213,11 @@ declare module '../AbstractGraph' { * @param style Optional object that defines the cell style. */ createEdge: ( - parent: Cell | null, - id: string, - value: any, - source: Cell | null, - target: Cell | null, + parent?: Cell | null, + id?: string, + value?: any, + source?: Cell | null, + target?: Cell | null, style?: CellStyle ) => Cell; diff --git a/packages/core/src/view/mixins/VertexMixin.ts b/packages/core/src/view/mixins/VertexMixin.ts index 366d302e05..270070cec6 100644 --- a/packages/core/src/view/mixins/VertexMixin.ts +++ b/packages/core/src/view/mixins/VertexMixin.ts @@ -98,9 +98,9 @@ export const VertexMixin: PartialType = { }, createVertex( - _parent: Cell | null, - id: string, - value: any, + _parent?: Cell | null, + id?: string, + value?: any, x?: number, y?: number, width?: number, @@ -115,7 +115,7 @@ export const VertexMixin: PartialType = { // Creates the vertex const vertex = new Cell(value, geometry, style); - vertex.setId(id); + vertex.setId(id!); // the auto-generated id is done when adding the cell to the model vertex.setVertex(true); vertex.setConnectable(true); diff --git a/packages/core/src/view/mixins/VertexMixin.type.ts b/packages/core/src/view/mixins/VertexMixin.type.ts index b56c3f557d..3373633650 100644 --- a/packages/core/src/view/mixins/VertexMixin.type.ts +++ b/packages/core/src/view/mixins/VertexMixin.type.ts @@ -89,9 +89,9 @@ declare module '../AbstractGraph' { * This can be useful for defining custom constraints. Default is {@link Geometry}. */ insertVertex( - parent: Cell | null, - id: string | null | undefined, - value: any, + parent?: Cell | null, + id?: string | null, + value?: any, x?: number, y?: number, width?: number, @@ -162,9 +162,9 @@ declare module '../AbstractGraph' { * This can be useful for defining custom constraints. Default is {@link Geometry}. */ createVertex( - parent: Cell | null, - id: string | null | undefined, - value: any, + parent?: Cell | null, + id?: string | null, + value?: any, x?: number, y?: number, width?: number, diff --git a/packages/core/src/view/plugins/ConnectionHandler.ts b/packages/core/src/view/plugins/ConnectionHandler.ts index 8d5dd4ca8d..54209de20e 100644 --- a/packages/core/src/view/plugins/ConnectionHandler.ts +++ b/packages/core/src/view/plugins/ConnectionHandler.ts @@ -202,7 +202,10 @@ type FactoryMethod = ( * * @category Plugin */ -class ConnectionHandler extends EventSource implements GraphPlugin, MouseListenerSet { +export default class ConnectionHandler + extends EventSource + implements GraphPlugin, MouseListenerSet +{ static readonly pluginId = 'ConnectionHandler'; previous: CellState | null = null; @@ -242,7 +245,8 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene /** * Specifies if icons should be moved to the back of the overlay pane. This can * be set to true if the icons of the connection handler conflict with other - * handles, such as the vertex label move handle. Default is false. + * handles, such as the vertex label move handle. + * @default false */ moveIconBack = false; @@ -254,28 +258,31 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene connectImage: Image | null = null; /** - * Specifies if the connect icon should be centered on the target state - * while connections are being previewed. Default is false. + * Specifies if the connect icon should be centered on the target state while connections are being previewed. + * @default false */ targetConnectImage = false; /** - * Specifies if events are handled. Default is false. + * Specifies if events are handled. + * @default false */ enabled = false; /** - * Specifies if new edges should be selected. Default is true. + * Specifies if new edges should be selected. + * @default true */ select = true; /** - * Specifies if should be called if no target was under the + * Specifies if {@link createTargetVertex} should be called if no target was under the * mouse for the new connection. Setting this to true means the connection * will be drawn as valid if no target is under the mouse, and - * will be called before the connection is created between - * the source cell and the newly created vertex in , which - * can be overridden to create a new target. Default is false. + * {@link createTargetVertex} will be called before the connection is created between + * the source cell and the newly created vertex in {@link createTargetVertex}, which + * can be overridden to create a new target. + * @default false */ createTarget = false; @@ -291,39 +298,41 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene /** * Holds the current validation error while connections are being created. + * @default null */ error: string | null = null; /** - * Specifies if single clicks should add waypoints on the new edge. Default is - * false. + * Specifies if single clicks should add waypoints on the new edge. + * @default false */ waypointsEnabled = false; /** - * Specifies if the connection handler should ignore the state of the mouse - * button when highlighting the source. Default is false, that is, the - * handler only highlights the source if no button is being pressed. + * Specifies if the connection handler should ignore the state of the mouse button when highlighting the source. + * + * When false, that is, the handler only highlights the source if no button is being pressed. + * + * @default false */ ignoreMouseDown = false; /** - * Holds the {@link Point} where the mouseDown took place while the handler is - * active. + * Holds the {@link Point} where the mouseDown took place while the handler is active. */ first: Point | null = null; /** * Holds the offset for connect icons during connection preview. - * Default is mxPoint(0, {@link Constants#TOOLTIP_VERTICAL_OFFSET}). + * Default is mxPoint(0, {@link TOOLTIP_VERTICAL_OFFSET}). * Note that placing the icon under the mouse pointer with an * offset of (0,0) will affect hit detection. */ connectIconOffset = new Point(0, TOOLTIP_VERTICAL_OFFSET); /** - * Optional that represents the preview edge while the - * handler is active. This is created in . + * Optional {@link CellState} that represents the preview edge while the + * handler is active. This is created in {@link createEdgeState}. */ edgeState: CellState | null = null; @@ -344,7 +353,7 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene mouseDownCounter = 0; /** - * Switch to enable moving the preview away from the mousepointer. This is required in browsers + * Switch to enable moving the preview away from the mouse pointer. This is required in browsers * where the preview cannot be made transparent to events and if the built-in hit detection on * the HTML elements in the page should be used. * @default false @@ -361,7 +370,8 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene /** * Specifies if the actual shape of the edge state should be used for the preview. - * Default is false. (Ignored if no edge state is created in .) + * This is ignored if no edge state is created in {@link createEdgeState}. + * @default false */ livePreview = false; @@ -472,11 +482,11 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene /** * Returns for non-loops and false for loops. * - * @param edge that represents the edge to be inserted. - * @param source that represents the source terminal. - * @param target that represents the target terminal. + * @param edge {@link Cell} that represents the edge to be inserted. + * @param source {@link Cell} that represents the source terminal. + * @param target {@link Cell} that represents the target terminal. * @param evt Mousedown event of the connect gesture. - * @param dropTarget that represents the cell under the mouse when it was + * @param dropTarget {@link Cell} that represents the cell under the mouse when it was * released. */ isInsertBefore( @@ -536,7 +546,7 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene } /** - * Creates and returns the {@link CellMarker} used in {@link arker}. + * Creates and returns the {@link CellMarker} used in {@link marker}. */ createMarker() { return new ConnectionHandlerCellMarker(this.graph, this); @@ -569,7 +579,7 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene /** * Returns {@link AbstractGraph.isValidSource} for the given source terminal. * - * @param cell that represents the source terminal. + * @param cell {@link Cell} that represents the source terminal. * @param me {@link MouseEvent} that is associated with this call. */ isValidSource(cell: Cell, me: InternalMouseEvent) { @@ -581,7 +591,7 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene * {@link AbstractGraph.getEdgeValidationError} in . This is an * additional hook for disabling certain targets in this specific handler. * - * @param cell that represents the target terminal. + * @param cell {@link Cell} that represents the target terminal. */ isValidTarget(cell: Cell) { return true; @@ -592,8 +602,8 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene * given source target pair is not valid. Otherwise it returns null. This * implementation uses {@link AbstractGraph.getEdgeValidationError}. * - * @param source that represents the source terminal. - * @param target that represents the target terminal. + * @param source {@link Cell} that represents the source terminal. + * @param target {@link Cell} that represents the target terminal. */ validateConnection(source: Cell, target: Cell) { if (!this.isValidTarget(target)) { @@ -744,11 +754,11 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene } /** - * Returns true if the given mouse down event should start this handler. The + * Returns true if the given mouse down event should start this handler. * This implementation returns true if the event does not force marquee * selection, and the currentConstraint and currentFocus of the - * are not null, or and are not null and - * is null or and are not null. + * {@link constraintHandler} are not null, or {@link previous} and {@link error} are not null and + * {@link icons} is null or {@link icons} and {@link icon} are not `null`. */ isStartEvent(me: InternalMouseEvent) { return ( @@ -874,8 +884,7 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene } /** - * Updates the current state for a given mouse move event by using - * the {@link arker}. + * Updates the current state for a given mouse move event by using the {@link marker}. */ updateCurrentState(me: InternalMouseEvent, point: Point): void { this.constraintHandler.update( @@ -1288,12 +1297,12 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene if (!this.edgeState) return; // TODO: Use generic method for writing constraint to style - if (this.sourceConstraint && this.sourceConstraint.point) { + if (this.sourceConstraint?.point) { this.edgeState.style.exitX = this.sourceConstraint.point.x; this.edgeState.style.exitY = this.sourceConstraint.point.y; } - if (constraint && constraint.point) { + if (constraint?.point) { this.edgeState.style.entryX = constraint.point.x; this.edgeState.style.entryY = constraint.point.y; } else { @@ -1432,31 +1441,34 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene return result; } - /** - * Hook to update the icon position(s) based on a mouseOver event. This is - * an empty implementation. + * Hook to update the icon position(s) based on a mouseOver event. * - * @param state under the mouse. + * This is an empty implementation. + * + * @param state {@link CellState} under the mouse. * @param icons Array of currently displayed icons. * @param me {@link MouseEvent} that contains the mouse event. */ + updateIcons(state: CellState, icons: ImageShape[], me: InternalMouseEvent) { // empty } /** - * Returns true if the given mouse up event should stop this handler. The - * connection will be created if is null. Note that this is only - * called if is true. This implemtation returns true - * if there is a cell state in the given event. + * Returns `true` if the given mouse up event should stop this handler. + * + * The connection will be created if {@link error} is `null`. + * Note that this is only called if {@link waypointsEnabled} is `true`. + * + * This implementation returns `true` if there is a cell state in the given event. */ isStopEvent(me: InternalMouseEvent) { return !!me.getState(); } /** - * Adds the waypoint for the given event to . + * Adds the waypoint for the given event to {@link waypoints}. */ addWaypointForEvent(me: InternalMouseEvent) { if (!this.first) return; @@ -1480,9 +1492,9 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene } /** - * Returns true if the connection for the given constraints is valid. This - * implementation returns true if the constraints are not pointing to the - * same fixed connection point. + * Returns `true` if the connection for the given constraints is valid. + * + * This implementation returns `true` if the constraints are not pointing to the same fixed connection point. */ checkConstraints(c1: ConnectionConstraint | null, c2: ConnectionConstraint | null) { return ( @@ -1589,8 +1601,7 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene } /** - * Redraws the preview edge using the color and width returned by - * and . + * Redraws the preview edge using the color and width returned by {@link getEdgeColor} and {@link getEdgeWidth}. */ drawPreview() { this.updatePreview(this.error === null); @@ -1598,11 +1609,10 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene } /** - * Returns the color used to draw the preview edge. This returns green if - * there is no edge validation error and red otherwise. + * Returns the color used to draw the preview edge. + * This returns green if there is no edge validation error and red otherwise. * - * @param valid Boolean indicating if the color for a valid edge should be - * returned. + * @param valid Boolean indicating if the color for a valid edge should be returned. */ updatePreview(valid: boolean) { if (this.shape) { @@ -1612,35 +1622,36 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene } /** - * Returns the color used to draw the preview edge. This returns green if - * there is no edge validation error and red otherwise. + * Returns the color used to draw the preview edge. + * + * This returns green if there is no edge validation error and red otherwise. * - * @param valid Boolean indicating if the color for a valid edge should be - * returned. + * @param valid Boolean indicating if the color for a valid edge should be returned. */ getEdgeColor(valid: boolean) { return valid ? VALID_COLOR : INVALID_COLOR; } /** - * Returns the width used to draw the preview edge. This returns 3 if - * there is no edge validation error and 1 otherwise. + * Returns the width used to draw the preview edge. * - * @param valid Boolean indicating if the width for a valid edge should be - * returned. + * This returns `3` if there is no edge validation error and `1` otherwise. + * + * @param valid Boolean indicating if the width for a valid edge should be returned. */ getEdgeWidth(valid: boolean): number { return valid ? 3 : 1; } /** - * Connects the given source and target using a new edge. This - * implementation uses to create the edge. + * Connects the given source and target using a new edge. * - * @param source that represents the source terminal. - * @param target that represents the target terminal. - * @param evt Mousedown event of the connect gesture. - * @param dropTarget that represents the cell under the mouse when it was + * This implementation uses {@link createEdge} to create the edge. + * + * @param source {@link Cell} that represents the source terminal. + * @param target {@link Cell} that represents the target terminal. + * @param evt {@link MouseEvent} event of the connect gesture. + * @param dropTarget {@link Cell} that represents the cell under the mouse when it was * released. */ connect( @@ -1867,7 +1878,7 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene * returns null. * * @param evt Mousedown event of the connect gesture. - * @param source that represents the source terminal. + * @param source {@link Cell} that represents the source terminal. */ createTargetVertex(evt: MouseEvent, source: Cell) { // Uses the first non-relative source @@ -2000,7 +2011,7 @@ class ConnectionHandler extends EventSource implements GraphPlugin, MouseListene } } -class ConnectionHandlerCellMarker extends CellMarker { +export class ConnectionHandlerCellMarker extends CellMarker { connectionHandler: ConnectionHandler; hotspotEnabled = true; @@ -2113,5 +2124,3 @@ class ConnectionHandlerCellMarker extends CellMarker { return super.intersects(state, evt); } } - -export default ConnectionHandler; diff --git a/packages/core/src/view/plugins/PanningHandler.ts b/packages/core/src/view/plugins/PanningHandler.ts index 68c062af52..0b38834578 100644 --- a/packages/core/src/view/plugins/PanningHandler.ts +++ b/packages/core/src/view/plugins/PanningHandler.ts @@ -264,9 +264,9 @@ class PanningHandler extends EventSource implements GraphPlugin, MouseListenerSe } /** - * Returns true if the given event is a panning trigger for the optional - * given cell. This returns true if control-shift is pressed or if - * is true and the event is a popup trigger. + * Returns `true` if the given event is a panning trigger for the optional given cell. + * + * This returns true if control-shift is pressed or if {@link usePopupTrigger} is `true` and the event is a popup trigger. */ isPanningTrigger(me: InternalMouseEvent) { const evt = me.getEvent(); From 8e6189523b11efec064a0ecf46545c5884c57a9b Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Tue, 29 Jul 2025 19:48:04 +0200 Subject: [PATCH 2/4] Fix import --- packages/core/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 15f9331c87..645041465b 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -49,7 +49,7 @@ export { Editor } from './editor/Editor.js'; export { default as CellHighlight } from './view/cell/CellHighlight.js'; export { default as CellMarker } from './view/cell/CellMarker.js'; -export { ConnectionHandlerCellMarker } from './view/plugins/ConnectionHandler'; +export { ConnectionHandlerCellMarker } from './view/plugins/ConnectionHandler.js'; export { default as CellTracker } from './view/cell/CellTracker.js'; export { default as ConstraintHandler } from './view/handler/ConstraintHandler.js'; export { default as EdgeHandler } from './view/handler/EdgeHandler.js'; From 26b847cbc59fec824c43ff212fc40d6868d27ead Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Wed, 30 Jul 2025 09:20:38 +0200 Subject: [PATCH 3/4] create cell: improve comment [skip ci] --- packages/core/src/view/mixins/EdgeMixin.ts | 2 +- packages/core/src/view/mixins/VertexMixin.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/view/mixins/EdgeMixin.ts b/packages/core/src/view/mixins/EdgeMixin.ts index 4d60f1eae4..431ef0e0e5 100644 --- a/packages/core/src/view/mixins/EdgeMixin.ts +++ b/packages/core/src/view/mixins/EdgeMixin.ts @@ -256,7 +256,7 @@ export const EdgeMixin: PartialType = { ) { // Creates the edge const edge = new Cell(value, new Geometry(), style); - edge.setId(id!); // the auto-generated id is done when adding the cell to the model + edge.setId(id!); // this is not an issue to set undefined here. If so, the id will be auto-generated when adding the cell to the model edge.setEdge(true); edge.geometry!.relative = true; // geometry is set when creating the cell above return edge; diff --git a/packages/core/src/view/mixins/VertexMixin.ts b/packages/core/src/view/mixins/VertexMixin.ts index 270070cec6..da3b39d79f 100644 --- a/packages/core/src/view/mixins/VertexMixin.ts +++ b/packages/core/src/view/mixins/VertexMixin.ts @@ -115,7 +115,7 @@ export const VertexMixin: PartialType = { // Creates the vertex const vertex = new Cell(value, geometry, style); - vertex.setId(id!); // the auto-generated id is done when adding the cell to the model + vertex.setId(id!); // this is not an issue to set undefined here. If so, the id will be auto-generated when adding the cell to the model vertex.setVertex(true); vertex.setConnectable(true); From 2499230006bbc48fa2eb5aecb36f4d53fb3b548f Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Wed, 30 Jul 2025 09:25:47 +0200 Subject: [PATCH 4/4] ConnectionHandler: improve JSDoc [skip ci] --- packages/core/src/view/plugins/ConnectionHandler.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/core/src/view/plugins/ConnectionHandler.ts b/packages/core/src/view/plugins/ConnectionHandler.ts index 54209de20e..5188c3cae4 100644 --- a/packages/core/src/view/plugins/ConnectionHandler.ts +++ b/packages/core/src/view/plugins/ConnectionHandler.ts @@ -699,9 +699,10 @@ export default class ConnectionHandler } /** - * Redraws the given array of {@link ImageShapes}. + * Redraws the given array of {@link ImageShape}s. * - * @param icons Array of {@link ImageShapes} to be redrawn. + * @param icons Array of {@link ImageShape}s to be redrawn. + * @param state {@link CellState} under the mouse. */ redrawIcons(icons: ImageShape[], state: CellState) { if (icons[0] && icons[0].bounds) { @@ -712,7 +713,12 @@ export default class ConnectionHandler } } - // TODO: Document me! =========================================================================================================== + /** + * Returns the center position of the given icon. + * + * @param icon The connect icon of {@link ImageShape} with the mouse. + * @param state {@link CellState} under the mouse. + */ getIconPosition(icon: ImageShape, state: CellState) { const { scale } = this.graph.getView(); let cx = state.getCenterX();