SSShooter / mind-elixir-core

⚗ Mind Elixir is a JavaScript, framework-agnostic mind map core.
https://docs.mind-elixir.com/
MIT License
1.98k stars 293 forks source link

Is it possible to not allow the user to expand everything? #131

Closed arnonrdp closed 2 years ago

arnonrdp commented 2 years ago

First of all, congratulations on your repo. I already starred it.

I'm creating a mind map with a lot of data and it wouldn't be interesting to allow the user to leave everything expanded.

So I would like to know if it is possible to define that whenever the user expands a series, the others are collapsed.

Thank you very much in advance.

SSShooter commented 2 years ago

It doesn't have this feature so far, but anyway, you can achieve it with this snippet.

mind.bus.addListener('expandNode', node => {
  if (node.expanded === false) return
  walk(mind.nodeData.children)
  while (node.parent) {
    node.expanded = true
    node = node.parent
  }
  mind.refresh()
})

function walk(children) {
  for (let i = 0; i < children.length; i++) {
    const child = children[i]
    child.expanded = false
    if (child.children) walk(child.children)
  }
}
arnonrdp commented 2 years ago

Simple and direct solution. Really appreciate it! Thanks a lot!