benwinding / command-pal

The hackable command palette for the web, inspired by Visual Studio Code.
https://benwinding.github.io/command-pal/docs
MIT License
75 stars 8 forks source link

Add CommandPalette.version property. #16

Open rouilj opened 1 year ago

rouilj commented 1 year ago

Would it be possible to add a version property to CommandPal? Would something like:

class CommandPal {

  version = "0.2.7";

  constructor(options) {
    console.log("CommandPal", { options });
    this.options = options || {};
    this.ps = pubsub.create();
  }

make:

cp = new CommandPal({
         commands: { 
              name: "CommandPal version",
              handler = () => (alert("CommandPal version " + CommandPal.version )),
              },
              name:  "Another version method",
              handler = () => (alert("CommandPal version " + cp.version )),
         }
      });

work?

Also in the docs, the handler definition is shown as:

// Callback function of the command to execute
  handler: (e) => {
    // DO SOMETHING
  }

What is e? From my testing it looks like it is undefined.

I assume there is some mechanism driven off of package.json to keep the version identifier up to date?

rouilj commented 1 year ago

Since I got the dev environment running I get an error when trying to define a class property. Neither:

class ... {

  version = "0.2.7"
  static myversion = "0.2.7"
}

seem to work. It throws a syntax error on the = sign. So maybe:

class ... {
     version() { return "0.2.7"};
}

method is the way to go here if you think it's worthwhile.