Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow more derived State classes to be parameterized with a generic type #1022

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/curly-doors-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@projectstorm/react-canvas-core': patch
'@projectstorm/react-diagrams-core': patch
---

Allow more derived State classes to provide a generic type
3 changes: 2 additions & 1 deletion packages/react-canvas-core/src/states/DragCanvasState.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CanvasEngine } from '../CanvasEngine';
import { AbstractDisplacementState, AbstractDisplacementStateEvent } from '../core-state/AbstractDisplacementState';
import { State } from '../core-state/State';

Expand All @@ -8,7 +9,7 @@ export interface DragCanvasStateOptions {
allowDrag?: boolean;
}

export class DragCanvasState extends AbstractDisplacementState {
export class DragCanvasState<E extends CanvasEngine = CanvasEngine> extends AbstractDisplacementState<E> {
// store this as we drag the canvas
initialCanvasX: number;
initialCanvasY: number;
Expand Down
3 changes: 2 additions & 1 deletion packages/react-canvas-core/src/states/SelectingState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { State } from '../core-state/State';
import { Action, ActionEvent, InputType } from '../core-actions/Action';
import { SelectionBoxState } from './SelectionBoxState';
import { MouseEvent } from 'react';
import { CanvasEngine } from '../CanvasEngine';

export class SelectingState extends State {
export class SelectingState<E extends CanvasEngine = CanvasEngine> extends State<E> {
constructor() {
super({
name: 'selecting'
Expand Down
3 changes: 2 additions & 1 deletion packages/react-canvas-core/src/states/SelectionBoxState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SelectionLayerModel } from '../entities/selection/SelectionLayerModel';
import { Point, Rectangle } from '@projectstorm/geometry';
import { BasePositionModel } from '../core-models/BasePositionModel';
import { ModelGeometryInterface } from '../core/ModelGeometryInterface';
import { CanvasEngine } from '../CanvasEngine';

export interface SimpleClientRect {
left: number;
Expand All @@ -14,7 +15,7 @@ export interface SimpleClientRect {
bottom: number;
}

export class SelectionBoxState extends AbstractDisplacementState {
export class SelectionBoxState<E extends CanvasEngine = CanvasEngine> extends AbstractDisplacementState<E> {
layer: SelectionLayerModel;

constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PortModel } from '../entities/port/PortModel';
import { MouseEvent } from 'react';
import { LinkModel } from '../entities/link/LinkModel';

export class DragDiagramItemsState extends MoveItemsState<DiagramEngine> {
export class DragDiagramItemsState<E extends DiagramEngine = DiagramEngine> extends MoveItemsState<E> {
constructor() {
super();
this.registerAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface DragNewLinkStateOptions {
allowLinksFromLockedPorts?: boolean;
}

export class DragNewLinkState extends AbstractDisplacementState<DiagramEngine> {
export class DragNewLinkState<E extends DiagramEngine = DiagramEngine> extends AbstractDisplacementState<E> {
port: PortModel;
link: LinkModel;
config: DragNewLinkStateOptions;
Expand Down