Skip to content

Commit 8b20838

Browse files
authored
feat(canvas): allow customize below layer (#56)
```ts class CustomBackground extends Component { render() { return <div>Custom Background</div>; } } const graph = new Graph({ settings: { background: Background, }, }); ```
1 parent da92917 commit 8b20838

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/components/canvas/layers/belowLayer/BelowLayer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class BelowLayer extends Layer<TBelowLayerProps, TBelowLayerContext> {
4242

4343
this.performRender = this.performRender.bind(this);
4444
this.context.graph.on("camera-change", this.performRender);
45+
this.props.graph.rootStore.settings.$background.subscribe(this.performRender);
4546
}
4647

4748
protected unmount() {
@@ -61,6 +62,6 @@ export class BelowLayer extends Layer<TBelowLayerProps, TBelowLayerContext> {
6162
}
6263

6364
public updateChildren() {
64-
return [Background.create()];
65+
return [(this.props.graph.rootStore.settings.$background.value || Background).create({})];
6566
}
6667
}

src/store/settings.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { computed, signal } from "@preact/signals-core";
22

33
import type { Block, TBlock } from "../components/canvas/blocks/Block";
44
import { BlockConnection } from "../components/canvas/connections/BlockConnection";
5+
import { Component } from "../lib";
56

67
import { TConnection } from "./connection/ConnectionState";
78

@@ -29,6 +30,7 @@ export type TGraphSettingsConfig<Block extends TBlock = TBlock, Connection exten
2930
showConnectionLabels: boolean;
3031
blockComponents: Record<string, typeof Block<Block>>;
3132
connection?: typeof BlockConnection<Connection>;
33+
background?: typeof Component;
3234
};
3335

3436
const getInitState: TGraphSettingsConfig = {
@@ -54,6 +56,10 @@ export class GraphEditorSettings {
5456
return this.$settings.value.blockComponents;
5557
});
5658

59+
public $background = computed(() => {
60+
return this.$settings.value.background;
61+
});
62+
5763
public $connection = computed(() => {
5864
return this.$settings.value.connection;
5965
});

0 commit comments

Comments
 (0)