From 1e84a03aa5816746714306900bc56779ee8a43fd Mon Sep 17 00:00:00 2001 From: Dylan Vorster Date: Mon, 19 Feb 2024 15:07:14 -0700 Subject: [PATCH 1/2] fix the demos --- .../demos/demo-custom-link2/index.tsx | 54 ++++++++++++++++++- .../demos/demo-dagre/index.tsx | 9 ++-- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/diagrams-demo-gallery/demos/demo-custom-link2/index.tsx b/diagrams-demo-gallery/demos/demo-custom-link2/index.tsx index 1981996cf..908bbfef7 100644 --- a/diagrams-demo-gallery/demos/demo-custom-link2/index.tsx +++ b/diagrams-demo-gallery/demos/demo-custom-link2/index.tsx @@ -11,6 +11,8 @@ import * as React from 'react'; import { CanvasWidget } from '@projectstorm/react-canvas-core'; import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget'; import { MouseEvent } from 'react'; +import { DefaultLinkPointWidget, DefaultLinkSegmentWidget } from '@projectstorm/react-diagrams-defaults/dist'; +import { DiagramEngine } from '@projectstorm/react-diagrams-core/dist'; export class AdvancedLinkModel extends DefaultLinkModel { constructor() { @@ -56,7 +58,56 @@ const CustomLinkArrowWidget = (props) => { ); }; -export class AdvancedLinkWidget extends DefaultLinkWidget { +export interface AdvancedLinkWWidgetProps { + link: DefaultLinkModel; + diagramEngine: DiagramEngine; + pointAdded?: (point: PointModel, event: MouseEvent) => any; + renderPoints?: boolean; + selected?: (event: MouseEvent) => any; +} + +export class AdvancedLinkWidget extends React.Component { + generatePoint = (point: PointModel): JSX.Element => { + return ( + + ); + }; + + generateLink = (path: string, extraProps: any, id: string | number): JSX.Element => { + return ( + + ); + }; + + addPointToLink = (event: MouseEvent, index: number) => { + if ( + !event.shiftKey && + !this.props.link.isLocked() && + this.props.link.getPoints().length - 1 <= this.props.diagramEngine.getMaxNumberPointsPerLink() + ) { + const position = this.props.diagramEngine.getRelativeMousePoint(event); + const point = this.props.link.point(position.x, position.y, index); + event.persist(); + event.stopPropagation(); + this.props.diagramEngine.getActionEventBus().fireAction({ + event, + model: point + }); + } + }; + generateArrow(point: PointModel, previousPoint: PointModel): JSX.Element { return ( (PathFindingLinkFactory.NAME) - .calculateRoutingMatrix(); + engine.getLinkFactories().getFactory(PathFindingLinkFactory.NAME).calculateRoutingMatrix(); } function DemoWidget(props) { @@ -83,11 +80,11 @@ function DemoWidget(props) { const redistribute = () => { autoDistribute(engine); - } + }; const refreshLinks = () => { autoRefreshLinks(engine); - } + }; return ( Date: Mon, 19 Feb 2024 15:09:37 -0700 Subject: [PATCH 2/2] changeset --- .changeset/spicy-falcons-do.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/spicy-falcons-do.md diff --git a/.changeset/spicy-falcons-do.md b/.changeset/spicy-falcons-do.md new file mode 100644 index 000000000..a95e1aaf0 --- /dev/null +++ b/.changeset/spicy-falcons-do.md @@ -0,0 +1,5 @@ +--- +'@projectstorm/react-diagrams-gallery': patch +--- + +Fixed the demos