Skip to content
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
1 change: 1 addition & 0 deletions src/components/canvas/anchors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export class Anchor<T extends TAnchorProps = TAnchorProps> extends GraphComponen

protected unmount() {
this.props.port.removeOwner();
this.connectedState.unsetViewComponent();
super.unmount();
}

Expand Down
15 changes: 14 additions & 1 deletion src/react-components/hooks/useBlockAnchorState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,20 @@ export function useBlockAnchorPosition(
return;
}

const position = state.getViewComponent()?.getPosition();
if (!state.$viewComponentReady.value) {
return;
}

const viewComponent = state.getViewComponent();
if (!viewComponent) {
return;
}

const position = viewComponent.getPosition();
if (!position) {
return;
}

const blockGeometry = state.block.$geometry.value;
anchorContainerRef.current.style.setProperty("--graph-block-anchor-x", `${position.x - blockGeometry.x}px`);
anchorContainerRef.current.style.setProperty("--graph-block-anchor-y", `${position.y - blockGeometry.y}px`);
Expand Down
8 changes: 8 additions & 0 deletions src/store/anchor/Anchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export class AnchorState {

public $selected = computed(() => this.block.store.anchorSelectionBucket.isSelected(this.id));

public $viewComponentReady = signal<boolean>(false);

private anchorView: Anchor;

public get id() {
Expand Down Expand Up @@ -43,6 +45,12 @@ export class AnchorState {

public setViewComponent(anchorComponent: Anchor) {
this.anchorView = anchorComponent;
this.$viewComponentReady.value = true;
}

public unsetViewComponent() {
this.anchorView = undefined;
this.$viewComponentReady.value = false;
}

public getViewComponent() {
Expand Down
Loading