Git Product home page Git Product logo

Comments (4)

Callmoon avatar Callmoon commented on June 1, 2024 1

Hey everyone,

if you have a look onto the example configuration there is a comment with:
// function( ele ){ return [ /*...*/ ] }, // a function that returns commands or a promise of commands

That means instead of return a static Array of commands you can also return them dynamically as a function with the selected element parameter.

 commands: (ele: Collection) => {
      return [
     //command objects,
     ]
}

That means you can control the enabled attribute very easily like this:

{
  content: 'Only enabled if less than two connections',
  select: (ele: Collection) => {
  console.log('selection possible because command is enabled')
  },
  enabled: ele.nodes().connectedEdges().length < 2  //here we can access the element from where the context menu was triggered
},

That means also you can control the visibility of the commands through filtering before returning the array.
For example by the previously setted enabled attribute:

 commands: (ele: Collection) => {
      return [
     //command objects,
     ].filter(command => command.enabled)
}

from cytoscape.js-cxtmenu.

Secretmapper avatar Secretmapper commented on June 1, 2024

We can go even further and make commands itself be dependent on content

from cytoscape.js-cxtmenu.

stale avatar stale commented on June 1, 2024

This issue has been automatically marked as stale, because it has not had activity within the past 30 days. It will be closed if no further activity occurs within the next 30 days. If a feature request is important to you, please consider making a pull request. Thank you for your contributions.

from cytoscape.js-cxtmenu.

thehappydinoa avatar thehappydinoa commented on June 1, 2024

Hi there, this is something I am interested in as well. Might there be any way we could reopen this feature request?

from cytoscape.js-cxtmenu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.