Skip to content

Commit 4696775

Browse files
committed
fully work
1 parent 89c0e45 commit 4696775

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+158
-105
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"scripts": {
2020
"dev": "npm run storybook",
2121
"build": "npm run clean && npm run build:graph && npm run build:react",
22-
"build:graph": "npm run clean:graph && rollup -c --config-package graph",
23-
"build:react": "npm run clean:react && rollup -c --config-package react",
22+
"build:graph": "npm run clean:graph && rollup -c --config-package graph && tsc --project packages/graph/tsconfig.json --emitDeclarationOnly",
23+
"build:react": "npm run clean:react && rollup -c --config-package react && tsc --project packages/react/tsconfig.json --emitDeclarationOnly",
2424
"watch": "rollup -c --watch",
2525
"typecheck": "tsc -b",
2626
"typecheck:watch": "tsc -b --watch",

packages/graph/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"types": "./dist/index.d.ts",
2525
"default": "./dist/index.js"
2626
},
27+
"./utils": {
28+
"types": "./dist/utils.d.ts",
29+
"default": "./dist/utils.js"
30+
},
2731
"./devtools": {
2832
"types": "./dist/plugins/devtools/index.d.ts",
2933
"default": "./dist/plugins/devtools/index.js"

packages/graph/src/components/canvas/blocks/Block.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,13 @@ export class Block<T extends TBlock = TBlock, Props extends TBlockProps = TBlock
473473
}
474474

475475
protected renderBody(ctx: CanvasRenderingContext2D) {
476-
const colors = this.context.colors;
477-
if (!colors) return;
478-
479-
ctx.fillStyle = colors.block.background;
480-
ctx.strokeStyle = colors.block.border;
476+
ctx.fillStyle = this.context.colors.block.background;
477+
ctx.strokeStyle = this.context.colors.block.border;
481478

482479
ctx.fillRect(this.state.x, this.state.y, this.state.width, this.state.height);
483-
this.renderStroke(this.state.selected ? colors.block.selectedBorder : colors.block.border);
480+
this.renderStroke(
481+
this.state.selected ? this.context.colors.block.selectedBorder : this.context.colors.block.border
482+
);
484483
}
485484

486485
public renderSchematicView(ctx: CanvasRenderingContext2D) {

packages/graph/src/components/canvas/blocks/Blocks.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Component } from "../../../lib/Component";
2-
import { CoreComponent } from "../../../lib/CoreComponent";
2+
import { ComponentConstructor, CoreComponent } from "../../../lib/CoreComponent";
33
import { BlockState } from "../../../store/block/Block";
44
import { TGraphLayerContext } from "../layers/graphLayer/GraphLayer";
55

66
import { Block } from "./Block";
77

88
export class Blocks extends Component {
99
protected blocks: BlockState[] = [];
10-
protected blocksView: Record<string, unknown> = {};
10+
protected blocksView: Record<string, ComponentConstructor<Block>> = {};
1111

1212
public declare context: TGraphLayerContext;
1313

@@ -24,7 +24,7 @@ export class Blocks extends Component {
2424
}
2525

2626
protected getFontScale() {
27-
return this.context.graph.rootStore.settings.getConfigFlag("scaleFontSize");
27+
return this.context.graph.rootStore.settings.getConfigFlag("scaleFontSize") as number;
2828
}
2929

3030
protected rerender() {
@@ -59,7 +59,8 @@ export class Blocks extends Component {
5959

6060
protected updateChildren() {
6161
return this.blocks.map((block, index) => {
62-
return (this.blocksView[block.$state.value.is] || Block).create(
62+
const Component = this.blocksView[block.$state.value.is] || Block;
63+
return Component.create(
6364
{
6465
id: block.id,
6566
initialIndex: index,

packages/graph/src/components/canvas/blocks/controllers/BlockController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ export class BlockController {
6565
autopanning: true,
6666
})
6767
.on(EVENTS.DRAG_START, (_event: MouseEvent) => {
68-
dispatchEvents(draggingElements, createCustomDragEvent(EVENTS.DRAG_START, _event));
68+
dispatchEvents(draggingElements as EventTarget[], createCustomDragEvent(EVENTS.DRAG_START, _event));
6969
})
7070
.on(EVENTS.DRAG_UPDATE, (_event: MouseEvent) => {
71-
dispatchEvents(draggingElements, createCustomDragEvent(EVENTS.DRAG_UPDATE, _event));
71+
dispatchEvents(draggingElements as EventTarget[], createCustomDragEvent(EVENTS.DRAG_UPDATE, _event));
7272
})
7373
.on(EVENTS.DRAG_END, (_event: MouseEvent) => {
74-
dispatchEvents(draggingElements, createCustomDragEvent(EVENTS.DRAG_END, _event));
74+
dispatchEvents(draggingElements as EventTarget[], createCustomDragEvent(EVENTS.DRAG_END, _event));
7575
});
7676
});
7777
}

packages/graph/src/components/canvas/layers/graphLayer/GraphLayer.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ export type GraphMouseEvent = CustomEvent<{
4141
}>;
4242

4343
export class GraphLayer extends Layer<TGraphLayerProps, TGraphLayerContext> {
44-
public declare $: Component & { camera: Camera };
45-
46-
private camera: ICamera;
44+
public declare $: Record<string, Component | undefined> & { camera: Camera };
4745

4846
private targetComponent: EventedComponent;
4947

@@ -89,8 +87,6 @@ export class GraphLayer extends Layer<TGraphLayerProps, TGraphLayerContext> {
8987
this.attachListeners();
9088
}
9189

92-
this.camera = this.props.camera;
93-
9490
this.performRender = this.performRender.bind(this);
9591
}
9692

packages/graph/src/components/canvas/layers/newBlockLayer/NewBlockLayer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class NewBlockLayer extends Layer<
140140
const colors = this.context.colors;
141141
render(this.context.ctx, (ctx) => {
142142
ctx.beginPath();
143-
ctx.fillStyle = this.props.ghostBackground || colors?.block.border || "#ccc";
143+
ctx.fillStyle = this.props.ghostBackground || colors.block.border || "#ccc";
144144

145145
// Draw each block ghost
146146
for (const blockState of this.blockStates) {

packages/graph/src/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ export * from "./graph";
66
export type { ZoomConfig } from "./api/PublicGraphApi";
77
export type { TGraphColors, TGraphConstants, TMouseWheelBehavior } from "./graphConfig";
88
export { initGraphColors, initGraphConstants } from "./graphConfig";
9-
export { type UnwrapGraphEventsDetail, type SelectionEvent } from "./graphEvents";
9+
export type {
10+
GraphEventsDefinitions,
11+
UnwrapGraphEvents,
12+
UnwrapGraphEventsDetail,
13+
UnwrapBaseGraphEvents,
14+
UnwrapBaseGraphEventsDetail,
15+
SelectionEvent,
16+
} from "./graphEvents";
1017
export * from "./plugins";
1118
export { ECameraScaleLevel } from "./services/camera/CameraService";
1219
export * from "./services/Layer";
@@ -16,17 +23,11 @@ export type { BlockState, TBlockId } from "./store/block/Block";
1623
export type { ConnectionState, TConnection, TConnectionId } from "./store/connection/ConnectionState";
1724
export type { AnchorState } from "./store/anchor/Anchor";
1825
export { ECanChangeBlockGeometry } from "./store/settings";
19-
export { type TMeasureTextOptions, type TWrapText, measureText } from "./utils/functions/text";
2026
export { ESchedulerPriority } from "./lib/Scheduler";
21-
export { debounce, throttle, schedule } from "./utils/functions";
22-
export type { RecursivePartial, Constructor } from "./utils/types/helpers";
23-
export * from "./utils/renderers/text";
24-
export { renderSVG } from "./utils/renderers/svgPath";
2527
export { random } from "./components/canvas/blocks/generate";
26-
export { EVENTS } from "./utils/types/events";
27-
export { type TPoint, type TRect } from "./utils/types/shapes";
2828
export { ESelectionStrategy } from "./services/selection/types";
29-
export * from "./utils/shapes";
29+
export { type HitBoxData } from "./services/HitTest";
30+
export { isPointInStroke } from "./components/canvas/connections/bezierHelpers";
3031

3132
export * from "./components/canvas/groups";
3233

packages/graph/src/lib/Component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Constructor } from "../utils/types/helpers";
2+
13
import { CoreComponent, CoreComponentContext, CoreComponentProps } from "./CoreComponent";
24
import { assign } from "./utils";
35

0 commit comments

Comments
 (0)