retejs / rete

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

Restrict dragging of wrapper out of visible area #367

Closed jadhavsuraj2207 closed 5 years ago

jadhavsuraj2207 commented 5 years ago

Hi, I want to restrict dragging of editor wrapper out of visible area. Rete create div which is in my wrapper div and has transform and scale property. when 'translate' event fire we get {transform,x,y}.

As in above image, how we can restrict the translate beyond the box. Is there any way to restrict the translating beyond the visible area. Thanks !!

Ni55aN commented 5 years ago

You can get a bounding rect (getBoundingClientRect) for node view (editor.view.nodes.get(node)) and editor.view.container and check the intersection

Example: https://github.com/retejs/area-plugin/blob/master/src/restrictor.js#L23