{"id":13606946,"url":"https://github.com/benwinding/command-pal","last_synced_at":"2025-04-13T15:53:21.331Z","repository":{"id":51266894,"uuid":"260943098","full_name":"benwinding/command-pal","owner":"benwinding","description":"The hackable command palette for the web, inspired by Visual Studio Code.","archived":false,"fork":false,"pushed_at":"2023-02-20T18:11:43.000Z","size":682,"stargazers_count":84,"open_issues_count":25,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T13:17:10.488Z","etag":null,"topics":["command-palette","html","js","micro-framework"],"latest_commit_sha":null,"homepage":"https://benwinding.github.io/command-pal/docs","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benwinding.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-05-03T14:30:11.000Z","updated_at":"2025-03-28T09:42:40.000Z","dependencies_parsed_at":"2024-01-15T17:39:18.251Z","dependency_job_id":"17fb656e-188c-4d73-acd5-9bc776e23237","html_url":"https://github.com/benwinding/command-pal","commit_stats":{"total_commits":99,"total_committers":6,"mean_commits":16.5,"dds":"0.24242424242424243","last_synced_commit":"ffd610c6e8c59472068fd436984eff862fbb68e3"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benwinding%2Fcommand-pal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benwinding%2Fcommand-pal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benwinding%2Fcommand-pal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benwinding%2Fcommand-pal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benwinding","download_url":"https://codeload.github.com/benwinding/command-pal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248741154,"owners_count":21154249,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-palette","html","js","micro-framework"],"created_at":"2024-08-01T19:01:14.039Z","updated_at":"2025-04-13T15:53:21.305Z","avatar_url":"https://github.com/benwinding.png","language":"HTML","funding_links":[],"categories":["Libraries"],"sub_categories":["General"],"readme":"\u003ch1 align=\"center\" style=\"font-family: mono\"\u003ecommand-pal\u003c/h1\u003e\n\u003cp align=\"center\"\u003e⌨ The hackable command palette for the web, inspired by \u003ca href=\"https://github.com/microsoft/vscode\"\u003eVisual Studio Code\u003c/a\u003e.\u003c/p\u003e\n\u003cdiv align=\"center\"\u003e\n\n\u003c!-- [START badges] --\u003e\n[![NPM Version](https://img.shields.io/npm/v/command-pal.svg)](https://www.npmjs.com/package/command-pal) \n[![License](https://img.shields.io/npm/l/command-pal.svg)](https://github.com/benwinding/command-pal/blob/master/LICENSE) \n[![Downloads/week](https://img.shields.io/npm/dm/command-pal.svg)](https://www.npmjs.com/package/command-pal) \n[![Github Issues](https://img.shields.io/github/issues/benwinding/command-pal.svg)](https://github.com/benwinding/command-pal)\n\u003c!-- [END badges] --\u003e\n\n\u003c/div\u003e\n\n![screen cap](https://i.imgur.com/jhJjLVL.gif)\n\n\u003cdiv align=\"center\"\u003e\n  \u003ci\u003eConfigure custom commands with custom keyboard shortcuts!\u003c/i\u003e\n\u003c/div\u003e\n\n## Demos\n\n- [Demo Simple](https://benwinding.github.io/command-pal/demos/cp-simple)\n- [Demo Advanced](https://benwinding.github.io/command-pal/demos/cp-advanced)\n- [Demo Dynamic](https://benwinding.github.io/command-pal/demos/cp-dynamic)\n- [Code Pen](https://codepen.io/benaloney/pen/BaobQmd)\n\n## Benefit's of Command Palettes\n\n- **Ease of use**\n\t- Simply 1 keyboard shortcut to remember\n\t- Fuzzy search allows you to find commands easily\n- **Speed**\n\t- Keyboard makes it fast to access any command/function\n\t- Fuzzy search allows for quick ordering of commands\n\t- Efficient to find a commands that you used once a long time ago\n- **Discoverability**\n\t- You can scroll down the entire list of commands\n\t- Find commands by simply searching the Command palette\n\t- Tips and functions can be given to you as you type\n\n## Features\n\n- JS framework agnostic (can be attached to any site)\n- Keyboard first control (shortcuts configurable)\n- Custom commands\n- Dynamically Add/Remove commands\n- Nested commands\n- Fuzzy text matching (fuse.js)\n- Themeable (theme-light.css and theme-dark.css included)\n- Mobile friendly (button in bottom-left)\n\n![screen cap](https://i.imgur.com/Bb6njpV.gif)\n\n## Why?\n\n_Command Palettes_ have alwyas impressed me with how easy they are to use and develop for. I rarely see them on the web platform, so I thought I'd give it a shot.\n\n## Get Started\n\n### Install\n\nEither install from npm\n\n`yarn add command-pal`\n\nOr use the script tag\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/command-pal\"\u003e\u003c/script\u003e\n```\n\n### Usage - Simple\n\n``` js\nconst c = new CommandPal({\n  hotkey: \"ctrl+space\",\n  commands: [\n    {\n      name: \"Send Message\",\n      shortcut: \"ctrl+m\",\n      handler: () =\u003e alert(\"Send Message\"),\n    },\n    {\n      name: \"Search Contacts\",\n      handler: () =\u003e alert(\"Searching contacts...\"),\n    },\n    {\n      name: \"Goto Profile\",\n      shortcut: \"ctrl+4\",\n      handler: () =\u003e window.location.hash = \"profile\",\n    },\n  ],\n});\nc.start();\n```\n\n### Usage - Advanced\n\n``` js\nconst c = new CommandPal({\n  hotkey: \"ctrl+space\",\n  placeholder: \"Custom placeholder text...\",\n  commands: [\n    {\n      name: \"Change Language\",\n      children: [\n        {\n          name: \"English\",\n          handler: () =\u003e alert(\"Changing to English\")\n        },\n        {\n          name: \"Spanglish\",\n          handler: () =\u003e alert(\"Changing to Spanglish\")\n        }\n      ]\n    },\n    {\n      name: \"Goto About\",\n      handler: () =\u003e window.location.hash = \"about\",\n    },\n  ],\n});\nc.start();\n```\n\n## API\n\n### CommandPal instance\n``` js\nconst c = new CommandPal({\n  hotkey: \"ctrl+space\",  // Launcher shortcut\n  hotkeysGlobal: true,       // Makes shortcut keys work in any \u003ctextarea\u003e, \u003cinput\u003e or \u003cselect\u003e\n  id: \"CommandPal\", // adds unique ID to aid in targeting with CSS\n  placeholder: \"Custom placeholder text...\", //  Changes placeholder text of input\n  debugOuput: false, // if true report debugging info to console\n  hideButton: false, // if true, do not generate mobile button\n  commands: [\n    // Commands go here\n  ]\n});\n// Start the instance\nc.start()\n// Destroy the instance\nc.destroy()\n```\n\n### Subscribe to events\nThere's a few events that can be subscribed to during command-pal's execution.\n\n``` js\n// When a command is executed\nc.subscribe(\"exec\", (e) =\u003e { console.log(\"exec\", { e }); });\n// On TextChanged\nc.subscribe(\"textChanged\", (e) =\u003e { console.log(\"textChanged\", { e }); });\n// When a command palette is opened\nc.subscribe(\"opened\", (e) =\u003e { console.log(\"opened\", { e }); });\n// When a command palette is closed\nc.subscribe(\"closed\", (e) =\u003e { console.log(\"closed\", { e }); });\n```\n\n### Command Item\n\n``` js\n{\n  // Required name of command (displayed)\n  name: \"Open Messages\",\n  // Required name of command (displayed)\n  description: \"View all messages in inbox\",\n  // Shortcut of command\n  shortcut: \"ctrl+3\",\n  // Callback function of the command to execute\n  handler: (e) =\u003e {\n    // DO SOMETHING\n  }\n  // Child commands which can be executed\n  children: [...]\n},\n```\n\n### Command Item Child\n\nNote: Child commands cannot have shortcuts.\n\n``` js\n{\n  // Required name of command (displayed)\n  name: \"Open Messages\",\n  // Description of command, used in matching command (not displayed)\n  description: \"View all messages in inbox\",\n  // Callback function of the command to execute\n  handler: (e) =\u003e {\n    // DO SOMETHING\n  }\n},\n```\n\n### Add/Remove Command's At Runtime\n\nThe command list is an observed array, which means you can modify it even after it's instantiated. The following snippet shows how commands can be dynamically added during runtime.\n\n``` js\nconst commands = [\n  {\n    name: \"Add Command to List\",\n    handler: () =\u003e {\n      commands.push({\n        name: 'New Command',\n        handler: () =\u003e {\n          // Do something\n        },\n      });\n    },\n  },\n];\nconst c = new CommandPal({\n  hotkey: \"ctrl+space\",\n  commands: commands,\n});\nc.start();\n```\n\n### Styling CommandPal instances\n\nThe styles used by command-pal are included in the package. However you can override the default CSS using the following.\n\n```css\n  /* mobile button */\n  #CommandPal .mobile-button  { top: 30px; }\n  /* modal background */\n  #CommandPal .modal-mask { background-color: rgb(0,128,200,0.75); }\n  /* item background */\n  #CommandPal [slot=items] { background-color: yellow;}\n  /* item text */\n  #CommandPal .item { color:black; }\n```\n\nYou can also assign a custom `id` to the CommandPal instance.\n\n```js\n   c = CommandPal(..., id: 'mypal',)\n```\n\nWhich allows you to style a specific instance.\n\n```css\n  /* mobile button for CommandPal with id='mypal' */\n  #mypal .mobile-button  { top: 30px; bottom: auto;}\n```\n\n## Local Development\n\nTo develop on `command-pal` simply clone, install and run\n\n```\nnpm run dev\n```\nThen the following link:\n\n- http://localhost:5005/cp-advanced/local-dev.html\n\n### Prevent Blur\n\nWhen the search input loses focus (receives a blur event), the palette\ncloses. This makes inspecting the palette using the browser's DevTools\ndifficult, as switching to DevTools causes the focus to be lost. It is\npossible to stop the palette from closing when focus is lost.\n\n``` js\n// Disable palette from closing during testing\nwindow.commandPalIgnoreBlur = true;\n// Re-enable\nwindow.commandPalIgnoreBlur = false;\n```\nTo close the palette. focus/select the search input and press the escape `ESC` key.\n\nHave a go, PR's and issues always welcome.\n\n## Prior Art\nMany applications have implemented this before, here's a few. My favourite implementation is the VScode, which is the main influence for this project.\n\n**Editors**\n\n- [VScode (Text Editor)](https://code.visualstudio.com/docs/getstarted/tips-and-tricks#_command-palette)\n- [Sublime (Text Editor)](https://www.sublimetext.com/)\n- [Atom (Text Editor)](https://atom.io/packages/command-palette)\n- [Webstorm's Search Everywhere (IDE)](https://www.jetbrains.com/help/webstorm/searching-everywhere.html?search=search)\n- [Caret (Markdown Editor)](https://caret.io/v2)\n- [Commander (Eclipse Plugin)](https://github.com/dakaraphi/eclipse-plugin-commander#kavi-implemented-features-for-all-interfaces)\n\n**Misc**\n\n- [Fman (File Manager)](https://fman.io/)\n- [Plotinus (GTK desktop extension)](https://github.com/p-e-w/plotinus)\n- [command-palette (Wordpress Extension)](https://wordpress.org/plugins/command-palette/)\n- [Vimium (Browser Extension)](https://chrome.google.com/webstore/detail/vimium/dbepggeogbaibhgnhhndojpepiihcmeb)\n- [JupyterLab (Notebook)](https://jupyterlab.readthedocs.io/en/stable/user/commands.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenwinding%2Fcommand-pal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenwinding%2Fcommand-pal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenwinding%2Fcommand-pal/lists"}