retejs / rete

JavaScript framework for visual programming
https://retejs.org
MIT License
10.17k stars 653 forks source link

fix: when SocketView.getPosition el.offsetParent is not nodeview.el #608

Closed deepkolos closed 1 year ago

deepkolos commented 1 year ago

when socket within complex layout, it's offsetParent is not NodeView.el, it have to collect offsets until NodeView.el

image

fix before

image

fix after

image
Ni55aN commented 1 year ago

Thanks, is it possible for you to carry out some refactoring? SocketView can be decoupled from NodeView, as it requires only this.nodeView.el. Also, offset calculation can be moved to a separate module

deepkolos commented 1 year ago

@Ni55aN code refactored

Ni55aN commented 1 year ago

build errors

src/view/node.ts:58:76 - error TS2554: Expected 5 arguments, but got 6.

58         this.sockets.set(io, new SocketView(el, type, io, this.node, this, this.el));
                                                                              ~~~~~~~

src/view/node.ts:74:35 - error TS2345: Argument of type 'Node' is not assignable to parameter of type '{ position: number[]; el: HTMLElement; }'.
  Property 'el' is missing in type 'Node' but required in type '{ position: number[]; el: HTMLElement; }'.

74         return socket.getPosition(this.node);
                                     ~~~~~~~~~

  src/view/socket.ts:24:69
    24     getPosition({ position, el: nodeViewEl }: { position: number[], el: HTMLElement }): [number, number] {
                                                                           ~~
    'el' is declared here.
deepkolos commented 1 year ago

@Ni55aN fixed

Ni55aN commented 1 year ago

🙆‍♂️ image

Ni55aN commented 1 year ago

Anyway, published v1.5.1 manually

Ni55aN commented 1 year ago

@deepkolos thanks for contributing!