Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node position change event? #438

Open
terion-name opened this issue Dec 8, 2024 · 1 comment
Open

Node position change event? #438

terion-name opened this issue Dec 8, 2024 · 1 comment

Comments

@terion-name
Copy link

I'm trying to make graph to be saved in any time to localstorage to not loose changes after page reload.
For this I need to watch all changes and sync.
Currently this tracks most of the changes AFAIK:

const updaterToken = Symbol();
for (const prop of ['addNode', 'removeNode', 'addConnection', 'removeConnection']) {
  baklava.editor.graphEvents[prop].subscribe(updaterToken, () => graph.value = baklava.editor.save());
}
for (const prop of ['update', 'addInput', 'loaded', 'addOutput', 'removeInput', 'removeOutput', 'titleChanged']) {
  baklava.editor.nodeEvents[prop].subscribe(updaterToken, () => graph.value = baklava.editor.save());
}

But as far as I can see there is no way to catch node movement.

Am I missing something? If not, can this be added?

@terion-name
Copy link
Author

terion-name commented Jan 6, 2025

Nasty, but works:

const editornode = useTemplateRef('editornode')
onMounted(() => {
  if (!editornode.value) {
    return;
  }
  const observer = new MutationObserver((list, observer) => {
    // @ts-expect-error target will be html element
    for (const node of list.filter(i => i.attributeName === 'class' && i.target?.classList.contains('baklava-node'))) {
      // --dragging class will change on move, so we update graph on class change
      nextTick(() => graph.value = baklava.editor.save().graph);
    }
  })
  observer.observe(editornode.value.$el.querySelector('.node-container'), { attributes: true, subtree: true })
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant