├── .deepsource.toml ├── .eslintrc ├── .github ├── .kodiak.toml ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── lint-n-build.yml ├── .gitignore ├── .husky ├── .gitignore └── pre-commit ├── .prettierrc ├── .stylelintrc.json ├── .vscode └── settings.json ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── index.html ├── package.json ├── pnpm-lock.yaml ├── public └── favicon.ico ├── readme-assets ├── demo-small.gif ├── demo.gif ├── logo.png ├── main-sample.png ├── menu-icon.png ├── sample1.png ├── social-logo-new.svg ├── social-logo-small.png ├── social-logo.png ├── social-logo.svg └── theme.png ├── rollup.config.js ├── src ├── App.vue ├── assets │ ├── bolt.svg │ ├── briefcase.svg │ ├── cog.svg │ ├── copy.svg │ ├── cut.svg │ ├── download.svg │ ├── edit.svg │ ├── file.svg │ ├── folder-open.svg │ ├── folder.svg │ ├── hammer.svg │ ├── info-circle.svg │ ├── mask.svg │ ├── paint-brush.svg │ ├── paste.svg │ ├── redo.svg │ ├── save.svg │ ├── search.svg │ ├── sign-out-alt.svg │ ├── times.svg │ ├── undo.svg │ ├── window-close.svg │ └── window-maximize.svg ├── components │ ├── ChevRight.vue │ ├── HelloWorld.vue │ ├── Menu.vue │ ├── MenuBar.vue │ ├── MenuBarItem.scss │ ├── MenuBarItem.vue │ ├── isMobileDevice.ts │ ├── menu-bar.scss │ └── menu.scss ├── index.css ├── index.js ├── main.js ├── models │ ├── MenuBarDockPosition.ts │ ├── MenuBarItemModel.ts │ ├── MenuBarModel.ts │ ├── MenuItemModel.ts │ ├── MenuModel.ts │ ├── SelectedItemModel.ts │ └── Theme.ts └── utils │ ├── DragUtil.ts │ └── keyboardNavigator.ts ├── tsconfig.json └── vite.config.js /.deepsource.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[analyzers]] 4 | name = "javascript" 5 | enabled = true 6 | 7 | [analyzers.meta] 8 | environment = ["browser"] 9 | plugins = ["vue"] 10 | style_guide = "standard" 11 | dialect = "typescript" 12 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es2021": true, 5 | }, 6 | "extends": [ 7 | "plugin:vue/vue3-recommended", 8 | "prettier" 9 | ], 10 | "parserOptions": { 11 | "ecmaVersion": 12, 12 | "parser": "@typescript-eslint/parser", 13 | "sourceType": "module" 14 | }, 15 | "rules": {} 16 | } -------------------------------------------------------------------------------- /.github/.kodiak.toml: -------------------------------------------------------------------------------- 1 | # .kodiak.toml 2 | 3 | version = 1 4 | 5 | [update] 6 | always = true 7 | require_automerge_label = true 8 | 9 | [merge] 10 | block_on_reviews_requested = true 11 | notify_on_conflict = true 12 | blocking_labels = ["wip"] -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | github: prabhuignoto 3 | ko_fi: prabhuignoto 4 | custom: ["paypal.me/prabhuignoto", "https://www.buymeacoffee.com/prabhuignoto"] 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/lint-n-build.yml: -------------------------------------------------------------------------------- 1 | name: Lint and Build 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | 9 | jobs: 10 | lint: 11 | runs-on: ubuntu-latest 12 | 13 | strategy: 14 | matrix: 15 | node-version: [18.x] 16 | steps: 17 | - uses: actions/checkout@v2 18 | 19 | - uses: pnpm/action-setup@v2.2.2 20 | with: 21 | version: 7 22 | 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v2 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | cache: "pnpm" 28 | 29 | - name: Install dependencies 30 | run: pnpm install 31 | 32 | - name: Run lint 33 | run: | 34 | pnpm lint:all 35 | pnpm rollup 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | *.local -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn lint:all 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 2, 3 | "useTabs": false 4 | } 5 | -------------------------------------------------------------------------------- /.stylelintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "stylelint-config-standard" 3 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "deepscan.ignoreConfirmWarning": true 3 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributor Covenant Code of Conduct 3 | 4 | ## Our Pledge 5 | 6 | We as members, contributors, and leaders pledge to make participation in our 7 | community a harassment-free experience for everyone, regardless of age, body 8 | size, visible or invisible disability, ethnicity, sex characteristics, gender 9 | identity and expression, level of experience, education, socio-economic status, 10 | nationality, personal appearance, race, religion, or sexual identity 11 | and orientation. 12 | 13 | We pledge to act and interact in ways that contribute to an open, welcoming, 14 | diverse, inclusive, and healthy community. 15 | 16 | ## Our Standards 17 | 18 | Examples of behavior that contributes to a positive environment for our 19 | community include: 20 | 21 | * Demonstrating empathy and kindness toward other people 22 | * Being respectful of differing opinions, viewpoints, and experiences 23 | * Giving and gracefully accepting constructive feedback 24 | * Accepting responsibility and apologizing to those affected by our mistakes, 25 | and learning from the experience 26 | * Focusing on what is best not just for us as individuals, but for the 27 | overall community 28 | 29 | Examples of unacceptable behavior include: 30 | 31 | * The use of sexualized language or imagery, and sexual attention or 32 | advances of any kind 33 | * Trolling, insulting or derogatory comments, and personal or political attacks 34 | * Public or private harassment 35 | * Publishing others' private information, such as a physical or email 36 | address, without their explicit permission 37 | * Other conduct which could reasonably be considered inappropriate in a 38 | professional setting 39 | 40 | ## Enforcement Responsibilities 41 | 42 | Community leaders are responsible for clarifying and enforcing our standards of 43 | acceptable behavior and will take appropriate and fair corrective action in 44 | response to any behavior that they deem inappropriate, threatening, offensive, 45 | or harmful. 46 | 47 | Community leaders have the right and responsibility to remove, edit, or reject 48 | comments, commits, code, wiki edits, issues, and other contributions that are 49 | not aligned to this Code of Conduct, and will communicate reasons for moderation 50 | decisions when appropriate. 51 | 52 | ## Scope 53 | 54 | This Code of Conduct applies within all community spaces, and also applies when 55 | an individual is officially representing the community in public spaces. 56 | Examples of representing our community include using an official e-mail address, 57 | posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. 59 | 60 | ## Enforcement 61 | 62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 | reported to the community leaders responsible for enforcement at 64 | prabhu.m.murthy@gmail.com. 65 | All complaints will be reviewed and investigated promptly and fairly. 66 | 67 | All community leaders are obligated to respect the privacy and security of the 68 | reporter of any incident. 69 | 70 | ## Enforcement Guidelines 71 | 72 | Community leaders will follow these Community Impact Guidelines in determining 73 | the consequences for any action they deem in violation of this Code of Conduct: 74 | 75 | ### 1. Correction 76 | 77 | **Community Impact**: Use of inappropriate language or other behavior deemed 78 | unprofessional or unwelcome in the community. 79 | 80 | **Consequence**: A private, written warning from community leaders, providing 81 | clarity around the nature of the violation and an explanation of why the 82 | behavior was inappropriate. A public apology may be requested. 83 | 84 | ### 2. Warning 85 | 86 | **Community Impact**: A violation through a single incident or series 87 | of actions. 88 | 89 | **Consequence**: A warning with consequences for continued behavior. No 90 | interaction with the people involved, including unsolicited interaction with 91 | those enforcing the Code of Conduct, for a specified period of time. This 92 | includes avoiding interactions in community spaces as well as external channels 93 | like social media. Violating these terms may lead to a temporary or 94 | permanent ban. 95 | 96 | ### 3. Temporary Ban 97 | 98 | **Community Impact**: A serious violation of community standards, including 99 | sustained inappropriate behavior. 100 | 101 | **Consequence**: A temporary ban from any sort of interaction or public 102 | communication with the community for a specified period of time. No public or 103 | private interaction with the people involved, including unsolicited interaction 104 | with those enforcing the Code of Conduct, is allowed during this period. 105 | Violating these terms may lead to a permanent ban. 106 | 107 | ### 4. Permanent Ban 108 | 109 | **Community Impact**: Demonstrating a pattern of violation of community 110 | standards, including sustained inappropriate behavior, harassment of an 111 | individual, or aggression toward or disparagement of classes of individuals. 112 | 113 | **Consequence**: A permanent ban from any sort of public interaction within 114 | the community. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 2.0, available at 120 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 121 | 122 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 123 | enforcement ladder](https://github.com/mozilla/diversity). 124 | 125 | [homepage]: https://www.contributor-covenant.org 126 | 127 | For answers to common questions about this code of conduct, see the FAQ at 128 | https://www.contributor-covenant.org/faq. Translations are available at 129 | https://www.contributor-covenant.org/translations. 130 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 6 | 7 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 8 | 9 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 10 | 11 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 12 | 13 | This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at https://www.contributor-covenant.org/version/1/0/0/code-of-conduct.html -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Prabhu Murthy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | ![logo](./readme-assets/social-logo-small.png) 4 | 5 | [![Build Status](https://dev.azure.com/prabhummurthy/vue-dock-menu/_apis/build/status/prabhuignoto.vue-dock-menu?branchName=master)](https://dev.azure.com/prabhummurthy/vue-dock-menu/_build/latest?definitionId=8&branchName=master) 6 | [![DeepScan grade](https://deepscan.io/api/teams/10074/projects/13372/branches/223016/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=10074&pid=13372&bid=223016) 7 | [![DeepSource](https://deepsource.io/gh/prabhuignoto/vue-dock-menu.svg/?label=active+issues)](https://deepsource.io/gh/prabhuignoto/vue-dock-menu/?ref=repository-badge) 8 | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/65c2863c31644d5a98ae5bb83c1bd104)](https://www.codacy.com/manual/prabhuignoto/vue-dock-menu/dashboard?utm_source=github.com&utm_medium=referral&utm_content=prabhuignoto/vue-dock-menu&utm_campaign=Badge_Grade) 9 | [![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/prabhuignoto/vue-dock-menu.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/prabhuignoto/vue-dock-menu/context:javascript) 10 | [![Depfu](https://badges.depfu.com/badges/f3a16c4fe1fcbd36df15d6949d9846bc/overview.svg)](https://depfu.com/github/prabhuignoto/vue-dock-menu?project_id=16495) 11 | [![Known Vulnerabilities](https://snyk.io/test/github/prabhuignoto/vue-dock-menu/badge.svg?targetFile=package.json)](https://snyk.io/test/github/prabhuignoto/vue-dock-menu?targetFile=package.json) 12 | ![https://badgen.net/bundlephobia/minzip/vue-dock-menu](https://badgen.net/bundlephobia/minzip/vue-dock-menu) 13 | 14 | ![demo](./readme-assets/demo.gif) 15 | 16 |
17 | 18 |

Features

19 | 20 | - ⚓  Dock your menu with ease. 21 | - 🤏  Dock the Menubar by dragging and dropping to the edges of the screen. 22 | - 👆  Touch support. 23 | - 👍  Support for nested menus up to any levels. 24 | - 👓  The Menus adjust to any docked position and enables an intuitive menu navigation. 25 | - ⌨  Keyboard Accessible. 26 | - 🎨  Icon support. 27 | - ⚡  Zero dependencies. 28 | - 💪  Built with [Typescript](https://www.typescriptlang.org/). 29 | - 🧰  Intuitive [API](#props) with data driven behavior. 30 | - 🌠  Built with the all new [Vue 3](https://v3.vuejs.org/). 31 | 32 |

Table of Contents

33 | 34 | - [⚡ Installation](#-installation) 35 | - [🚀 Getting Started](#-getting-started) 36 | - [Props](#props) 37 | - [⚓ Dock](#-dock) 38 | - [📡 on-selected](#-on-selected) 39 | - [⚡ Populating Menu](#-populating-menu) 40 | - [🎨 Custom color scheme](#-custom-color-scheme) 41 | - [🎭 Icon support](#-icon-support) 42 | - [What's coming next](#whats-coming-next) 43 | - [📦 Build Setup](#-build-setup) 44 | - [🔨 Contributing](#-contributing) 45 | - [🧱 Built with](#-built-with) 46 | - [📄 Notes](#-notes) 47 | - [Meta](#meta) 48 | 49 | ## ⚡ Installation 50 | 51 | ```sh 52 | yarn install vue-dock-menu 53 | ``` 54 | 55 | ## 🚀 Getting Started 56 | 57 | `vue-dock-menu` has some great defaults. Please check the [prop](#Props) section for all available options. 58 | 59 | The following snippet creates a simple Menubar and docks it to the `top` of the page. 60 | 61 | ```sh 62 | 66 | 67 | 92 | ``` 93 | 94 | ![sample1](./readme-assets/sample1.png) 95 | 96 | ## Props 97 | 98 | | Name | Description | Default | 99 | |-------------|---------------------------------------------------------------------------------------------------|---------| 100 | | dock | default docking position. Can be any one of `TOP`, `LEFT`, `RIGHT`, `BOTTOM` | `TOP` | | 101 | | on-selected | Callback that will be called on a menu item selection | | 102 | | items | Data for the Menu bar | [] | 103 | | theme | prop to customize the color theme | | 104 | | draggable | enables/disbales dragging on the menubar. | True | 105 | 106 | ### ⚓ Dock 107 | 108 | use the `dock` prop to dock the menubar to your preferred position. The prop can accept the following values `TOP`, `BOTTOM`, `LEFT`, `RIGHT`. 109 | 110 | Here we dock the Menu bar to the right side of the screen. 111 | 112 | ```sh 113 | 114 | :items="items" 115 | dock="RIGHT" 116 | 117 | ``` 118 | 119 | ### 📡 on-selected 120 | 121 | The `on-selected` prop is used to retrieve the selected menu item. The callback receives an object with `name` and a `path` property. 122 | 123 | - **name** - Name of the selected menu item. 124 | - **path** - Full path of the selected menu item. 125 | 126 | if you select the `Copy` menu item under the `Edit` menu, below would be the payload received on the `on-selected` callback. 127 | 128 | ```sh 129 | { 130 | name: "Copy", 131 | path: "edit>copy" 132 | } 133 | ``` 134 | 135 | ### ⚡ Populating Menu 136 | 137 | Use the `items` prop to create Simple or Nested menus of your liking. 138 | 139 | Here we create a simple Menu structure with 3 Menu items with `Edit` and `Open Recent` having sub menus. 140 | 141 | - To include a divider, set an empty item object with just a `isDivider` property set to `true`. 142 | - To disable an item, set `disable` to `true`. 143 | 144 | ```sh 145 | const items = [ 146 | { name: "New" }, 147 | { isDivider: true }, 148 | { 149 | name: "Edit", 150 | menu: { 151 | name: "edit-items", 152 | disable: true 153 | }, 154 | }, 155 | { isDivider: true }, 156 | { 157 | name: "Open Recent", 158 | menu: { 159 | name: "recent-items", 160 | }, 161 | }, 162 | { isDivider: true }, 163 | { name: "Save", disable: true }, 164 | { name: "Save As..." }, 165 | { isDivider: true }, 166 | { name: "Close" }, 167 | { name: "Exit" }, 168 | ] 169 | ``` 170 | 171 | ```sh 172 | 173 | :items="items" 174 | dock="BOTTOM" 175 | 176 | ``` 177 | 178 | ### 🎨 Custom color scheme 179 | 180 | use the `theme` prop to customize the colors of the menu bar. 181 | 182 | ```sh 183 | 193 | ``` 194 | 195 | ![theme](./readme-assets/theme.png) 196 | 197 | ### 🎭 Icon support 198 | 199 | Each menu item can be iconified and the component uses slots to inject the icons. 200 | 201 | Pass individual icons (or images) as templates marked with a unique `slot id`. please make sure the `ids` match the `iconSlot` property in the items array. 202 | 203 | ```sh 204 | 208 | 215 | 222 | 223 | 224 | export default defineComponent({ 225 | name: "MenuExample", 226 | data() { 227 | return { 228 | items: [ 229 | { name: "New File", iconSlot: "file" }, 230 | { name: "New Window", iconSlot: "window" }, 231 | ] 232 | } 233 | } 234 | }) 235 | ``` 236 | 237 | ![menu-icon](./readme-assets/menu-icon.png) 238 | 239 | This works seamlessly even for `nested` menu structure. Make sure the `slot ids` match and the component will render the icons appropriately. 240 | 241 | ```sh 242 | 246 | 253 | 254 | 255 | export default defineComponent({ 256 | name: "MenuExample", 257 | data() { 258 | return { 259 | items: [ 260 | { name: "New File", 261 | subMenu: [{ name: "New Window", iconSlot: "window" }]}, 262 | ] 263 | } 264 | } 265 | }); 266 | ``` 267 | 268 | ## What's coming next 269 | 270 | - support for react. 271 | - accordion style rendering on sidebar mode. 272 | 273 | ## 📦 Build Setup 274 | 275 | ``` bash 276 | # install dependencies 277 | yarn install 278 | 279 | # start dev 280 | yarn run dev 281 | 282 | # package lib 283 | npm run rollup 284 | 285 | # run css linting 286 | yarn run lint:css 287 | ``` 288 | 289 | ## 🔨 Contributing 290 | 291 | 1. Fork it ( [https://github.com/prabhuignoto/vue-dock-menu/fork](https://github.com/prabhuignoto/vue-dock-menu/fork) ) 292 | 2. Create your feature branch (`git checkout -b new-feature`) 293 | 3. Commit your changes (`git commit -am 'Add feature'`) 294 | 4. Push to the branch (`git push origin new-feature`) 295 | 5. Create a new Pull Request 296 | 297 | ## 🧱 Built with 298 | 299 | - [Typescript](typescript). 300 | 301 | ## 📄 Notes 302 | 303 | - The project uses [vite](vite) instead of @vue/cli. I choose vite for speed and i also believe [vite](vite) will be the future. 304 | 305 | ## Meta 306 | 307 | Prabhu Murthy – [@prabhumurthy2](https://twitter.com/prabhumurthy2) – prabhu.m.murthy@gmail.com 308 | 309 | [https://www.prabhumurthy.com](https://www.prabhumurthy.com) 310 | 311 | Distributed under the MIT license. See `LICENSE` for more information. 312 | 313 | [https://github.com/prabhuingoto/](https://github.com/prabhuignoto/) 314 | 315 | [vue]: https://vuejs.org 316 | [typescript]: https://typescriptlang.org 317 | [vite]: https://github.com/vitejs/vite 318 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Dock Menu 9 | 10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-dock-menu", 3 | "version": "1.1.0", 4 | "license": "MIT", 5 | "author": "Prabhu Murthy", 6 | "description": "Dockable menu bar for Vue 3", 7 | "type": "module", 8 | "keywords": [ 9 | "menu", 10 | "dock-menu", 11 | "vue-menu" 12 | ], 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/prabhuignoto/vue-dock-menu" 16 | }, 17 | "scripts": { 18 | "dev": "vite", 19 | "rollup": "rimraf ./dist && rollup -c", 20 | "eslint": "eslint src/**/*.vue --ext .vue --fix", 21 | "lint:css": "stylelint src/**/*.vue --custom-syntax postcss-html", 22 | "lint:all": "pnpm eslint && pnpm lint:css", 23 | "prepare": "husky install", 24 | "preinstall": "npx only-allow pnpm", 25 | "format": "prettier --write src/**/*.vue", 26 | "clean": "pnpm format && pnpm lint:all" 27 | }, 28 | "husky": { 29 | "hooks": { 30 | "pre-commit": "lint-staged" 31 | } 32 | }, 33 | "lint-staged": { 34 | "src/**/*.scss": [ 35 | "stylelint src/**/*.scss --fix", 36 | "git add" 37 | ], 38 | "src/**/*.vue": [ 39 | "eslint src/**/*.vue --fix", 40 | "git add" 41 | ] 42 | }, 43 | "dependencies": { 44 | "focus-visible": "^5.2.0" 45 | }, 46 | "devDependencies": { 47 | "@rollup/plugin-beep": "^1.0.2", 48 | "@rollup/plugin-buble": "^1.0.2", 49 | "@rollup/plugin-commonjs": "^24.0.1", 50 | "@rollup/plugin-node-resolve": "^15.0.1", 51 | "@rollup/plugin-sucrase": "^5.0.1", 52 | "@typescript-eslint/eslint-plugin": "^5.50.0", 53 | "@typescript-eslint/parser": "^5.50.0", 54 | "@vitejs/plugin-vue": "^4.0.0", 55 | "@vue/compiler-sfc": "^3.2.47", 56 | "eslint": "^8.33.0", 57 | "eslint-config-prettier": "^8.6.0", 58 | "eslint-plugin-vue": "^9.9.0", 59 | "husky": "^8.0.3", 60 | "lint-staged": "^13.1.0", 61 | "postcss-html": "^1.5.0", 62 | "rollup": "^3.13.0", 63 | "rollup-plugin-scss": "^4.0.0", 64 | "rollup-plugin-terser": "^7.0.2", 65 | "rollup-plugin-vue": "^6.0.0", 66 | "sass": "^1.58.0", 67 | "stylelint": "^14.16.1", 68 | "stylelint-config-standard": "^29.0.0", 69 | "typescript": "^4.9.5", 70 | "vite": "^4.1.1", 71 | "vue": "^3.2.47" 72 | }, 73 | "peerDependencies": { 74 | "@vue/compiler-sfc": "^3.0.5", 75 | "vue": "^3.0.5" 76 | }, 77 | "main": "dist/vue-dock-menu.js", 78 | "module": "dist/vue-dock-menu.es.js", 79 | "umd": "dist/vue-dock-menu.umd.js", 80 | "files": [ 81 | "dist" 82 | ] 83 | } 84 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prabhuignoto/vue-dock-menu/199dd3987e51108b65c14ded2e91e7cbd7eb29f7/public/favicon.ico -------------------------------------------------------------------------------- /readme-assets/demo-small.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prabhuignoto/vue-dock-menu/199dd3987e51108b65c14ded2e91e7cbd7eb29f7/readme-assets/demo-small.gif -------------------------------------------------------------------------------- /readme-assets/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prabhuignoto/vue-dock-menu/199dd3987e51108b65c14ded2e91e7cbd7eb29f7/readme-assets/demo.gif -------------------------------------------------------------------------------- /readme-assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prabhuignoto/vue-dock-menu/199dd3987e51108b65c14ded2e91e7cbd7eb29f7/readme-assets/logo.png -------------------------------------------------------------------------------- /readme-assets/main-sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prabhuignoto/vue-dock-menu/199dd3987e51108b65c14ded2e91e7cbd7eb29f7/readme-assets/main-sample.png -------------------------------------------------------------------------------- /readme-assets/menu-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prabhuignoto/vue-dock-menu/199dd3987e51108b65c14ded2e91e7cbd7eb29f7/readme-assets/menu-icon.png -------------------------------------------------------------------------------- /readme-assets/sample1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prabhuignoto/vue-dock-menu/199dd3987e51108b65c14ded2e91e7cbd7eb29f7/readme-assets/sample1.png -------------------------------------------------------------------------------- /readme-assets/social-logo-new.svg: -------------------------------------------------------------------------------- 1 | backgroundLayer 1vue-dock-menuDockable Menubar for Vue -------------------------------------------------------------------------------- /readme-assets/social-logo-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prabhuignoto/vue-dock-menu/199dd3987e51108b65c14ded2e91e7cbd7eb29f7/readme-assets/social-logo-small.png -------------------------------------------------------------------------------- /readme-assets/social-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prabhuignoto/vue-dock-menu/199dd3987e51108b65c14ded2e91e7cbd7eb29f7/readme-assets/social-logo.png -------------------------------------------------------------------------------- /readme-assets/social-logo.svg: -------------------------------------------------------------------------------- 1 | backgroundLayer 1vue-dock-menuDockable Menubar for Vue -------------------------------------------------------------------------------- /readme-assets/theme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prabhuignoto/vue-dock-menu/199dd3987e51108b65c14ded2e91e7cbd7eb29f7/readme-assets/theme.png -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import beep from "@rollup/plugin-beep"; 2 | import buble from "@rollup/plugin-buble"; 3 | import common from "@rollup/plugin-commonjs"; 4 | import resolve from "@rollup/plugin-node-resolve"; 5 | import sucrase from "@rollup/plugin-sucrase"; 6 | import scss from "rollup-plugin-scss"; 7 | import { terser } from "rollup-plugin-terser"; 8 | import vue from "rollup-plugin-vue"; 9 | import pkg from "./package.json"; 10 | 11 | const banner = `/* 12 | * ${pkg.name} 13 | * ${pkg.description} 14 | * v${pkg.version} 15 | * ${pkg.license} License 16 | */ 17 | `; 18 | 19 | export default { 20 | input: "src/index.js", 21 | output: [ 22 | { 23 | file: pkg.main, 24 | format: "cjs", 25 | exports: "named", 26 | strict: true, 27 | banner, 28 | }, 29 | { 30 | file: pkg.module, 31 | format: "es", 32 | exports: "named", 33 | strict: true, 34 | banner, 35 | }, 36 | { 37 | file: pkg.umd, 38 | format: "umd", 39 | exports: "named", 40 | strict: true, 41 | banner, 42 | name: "FloatMenu", 43 | globals: { 44 | vue: "vue", 45 | }, 46 | }, 47 | ], 48 | plugins: [ 49 | vue(), 50 | scss(), 51 | sucrase({ 52 | exclude: ["node_modules/**"], 53 | transforms: ["typescript"], 54 | }), 55 | beep(), 56 | common(), 57 | buble(), 58 | resolve(), 59 | terser({ 60 | compress: { 61 | drop_console: true, 62 | drop_debugger: true, 63 | }, 64 | }), 65 | ], 66 | external: ["vue"], 67 | }; 68 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 15 | -------------------------------------------------------------------------------- /src/assets/bolt.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/briefcase.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/cog.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/copy.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/cut.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/download.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/edit.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/file.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/folder-open.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/folder.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/hammer.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/info-circle.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/mask.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/paint-brush.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/paste.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/redo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/save.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/search.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/sign-out-alt.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/times.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/undo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/window-close.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/window-maximize.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/components/ChevRight.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 25 | -------------------------------------------------------------------------------- /src/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 75 | 76 | 181 | -------------------------------------------------------------------------------- /src/components/Menu.vue: -------------------------------------------------------------------------------- 1 | 94 | 95 | 352 | 353 | 354 | -------------------------------------------------------------------------------- /src/components/MenuBar.vue: -------------------------------------------------------------------------------- 1 | 52 | 53 | 407 | 408 | 409 | -------------------------------------------------------------------------------- /src/components/MenuBarItem.scss: -------------------------------------------------------------------------------- 1 | .menu-bar-item-container { 2 | align-items: center; 3 | cursor: pointer; 4 | display: flex; 5 | justify-content: center; 6 | position: relative; 7 | 8 | &:focus { 9 | outline: 0; 10 | } 11 | 12 | &:focus-visible { 13 | outline: 1px solid #0080ff; 14 | } 15 | 16 | &.left, 17 | &.right { 18 | padding: 0.5rem 0; 19 | width: 100%; 20 | } 21 | 22 | &.top, 23 | &.bottom { 24 | height: 100%; 25 | padding: 0 0.75rem; 26 | } 27 | } 28 | 29 | .menu-container { 30 | position: absolute; 31 | z-index: 9999; 32 | } 33 | 34 | .name-container { 35 | font-size: 0.95rem; 36 | margin: 0.25rem 0; 37 | overflow: hidden; 38 | text-overflow: ellipsis; 39 | text-transform: capitalize; 40 | white-space: nowrap; 41 | 42 | &.left, 43 | &.right { 44 | align-items: center; 45 | background: none; 46 | display: flex; 47 | font-size: 1rem; 48 | height: 1.5rem; 49 | justify-content: flex-start; 50 | width: 100%; 51 | 52 | &.expanded { 53 | padding-left: 1rem; 54 | } 55 | 56 | &:not(.expanded) { 57 | font-size: 1.1rem; 58 | justify-content: center; 59 | text-transform: uppercase; 60 | width: 2rem; 61 | } 62 | } 63 | } 64 | 65 | .js-focus-visible :focus:not(.focus-visible) { 66 | outline: none; 67 | } 68 | -------------------------------------------------------------------------------- /src/components/MenuBarItem.vue: -------------------------------------------------------------------------------- 1 | 37 | 38 | 342 | 343 | 344 | -------------------------------------------------------------------------------- /src/components/isMobileDevice.ts: -------------------------------------------------------------------------------- 1 | export const isMobile: () => boolean = () => { 2 | if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/iu.test(navigator.userAgent)) { 3 | return true; 4 | } else { 5 | return false; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/components/menu-bar.scss: -------------------------------------------------------------------------------- 1 | .menu-bar-container { 2 | position: fixed; 3 | display: flex; 4 | user-select: none; 5 | outline: 0; 6 | touch-action: none; 7 | z-index: 9999; 8 | background-color: var(--menubar-bg-color); 9 | 10 | &.left, 11 | &.right { 12 | height: 100%; 13 | align-items: flex-start; 14 | 15 | &.expanded { 16 | width: var(--menubar-expanded-width); 17 | animation: expand 0.1s linear; 18 | } 19 | 20 | &.not-expanded { 21 | width: var(--menubar-not-expanded-width); 22 | animation: collapse 0.1s linear; 23 | } 24 | } 25 | 26 | &.top, 27 | &.bottom { 28 | height: 2.5rem; 29 | width: 100%; 30 | align-items: center; 31 | left: 0; 32 | } 33 | 34 | &.left { 35 | left: 0; 36 | top: 0; 37 | } 38 | 39 | &.right { 40 | right: 0; 41 | top: 0; 42 | } 43 | 44 | &.top { 45 | top: 0; 46 | } 47 | 48 | &.bottom { 49 | bottom: 0; 50 | } 51 | } 52 | 53 | .menu-bar-items { 54 | display: flex; 55 | list-style: none; 56 | align-items: center; 57 | justify-content: flex-start; 58 | padding: 0; 59 | margin: 0; 60 | 61 | &.top, 62 | &.bottom { 63 | height: 100%; 64 | } 65 | 66 | &.left, 67 | &.right { 68 | flex-direction: column; 69 | width: 100%; 70 | align-items: flex-start; 71 | } 72 | } 73 | 74 | .v-dock-menu-bar-item-wrapper { 75 | height: 100%; 76 | display: flex; 77 | align-items: center; 78 | justify-content: center; 79 | 80 | &.left, 81 | &.right { 82 | width: 100%; 83 | } 84 | } 85 | 86 | @keyframes expand { 87 | 0% { 88 | width: 50px; 89 | } 90 | 91 | 100% { 92 | width: 200px; 93 | } 94 | } 95 | 96 | @keyframes collapse { 97 | 0% { 98 | width: 200px; 99 | } 100 | 101 | 100% { 102 | width: 50px; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/components/menu.scss: -------------------------------------------------------------------------------- 1 | .menu-wrapper { 2 | align-items: flex-start; 3 | display: flex; 4 | justify-content: center; 5 | min-width: 200px; 6 | padding: 0.5rem 0; 7 | } 8 | 9 | .menu-items { 10 | align-items: flex-start; 11 | display: flex; 12 | flex-direction: column; 13 | height: 100%; 14 | justify-content: flex-start; 15 | list-style: none; 16 | margin: 0; 17 | outline: 0; 18 | padding: 0; 19 | width: 100%; 20 | } 21 | 22 | .icon-wrap { 23 | align-items: center; 24 | display: flex; 25 | height: 1rem; 26 | justify-content: center; 27 | margin-left: auto; 28 | width: 1.25rem; 29 | } 30 | 31 | .menu-item-icon { 32 | align-items: center; 33 | display: flex; 34 | height: 20px; 35 | justify-content: center; 36 | margin: 0 2px 0 6px; 37 | width: 20px; 38 | } 39 | 40 | .menu-item { 41 | align-items: center; 42 | color: var(--fore-color); 43 | display: flex; 44 | font-size: 0.9rem; 45 | justify-content: flex-start; 46 | position: relative; 47 | text-transform: capitalize; 48 | width: 100%; 49 | 50 | &:not(.divider) { 51 | padding: 0.4rem 0; 52 | } 53 | 54 | &:hover:not(.divider) { 55 | cursor: pointer; 56 | background: var(--background-color-hover); 57 | color: var(--text-hover-color); 58 | } 59 | 60 | &.highlight:not(.divider) { 61 | background: var(--background-color-hover); 62 | color: var(--text-hover-color); 63 | } 64 | 65 | span.name { 66 | flex-basis: 85%; 67 | text-align: left; 68 | padding-left: 3%; 69 | } 70 | 71 | span.icon-wrap { 72 | width: 10%; 73 | visibility: hidden; 74 | 75 | &.visible { 76 | visibility: visible; 77 | } 78 | } 79 | 80 | &.right { 81 | .name { 82 | order: 2; 83 | padding-right: 5%; 84 | text-align: right; 85 | } 86 | 87 | .icon-wrap { 88 | margin-right: auto; 89 | order: 1; 90 | transform: rotate(180deg); 91 | } 92 | 93 | .menu-item-icon { 94 | margin: 0 6px 0 2px; 95 | order: 3; 96 | } 97 | } 98 | 99 | &.disable { 100 | filter: opacity(0.5); 101 | } 102 | } 103 | 104 | .sub-menu-wrapper { 105 | position: absolute; 106 | top: 0; 107 | 108 | &:not(.right) { 109 | left: 100%; 110 | } 111 | 112 | &.right { 113 | right: 100%; 114 | } 115 | 116 | &.bottom { 117 | transform: translateY(-65%); 118 | } 119 | } 120 | 121 | .menu-item-divider { 122 | background: rgba(0, 0, 0, 0.1); 123 | display: block; 124 | height: 1px; 125 | margin: 0 auto; 126 | margin-bottom: 6px; 127 | margin-top: 6px; 128 | width: 90%; 129 | } 130 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | #app { 2 | font-family: Nunito, Avenir, Helvetica, Arial, sans-serif; 3 | -webkit-font-smoothing: antialiased; 4 | -moz-osx-font-smoothing: grayscale; 5 | text-align: center; 6 | color: #2c3e50; 7 | margin-top: 60px; 8 | } 9 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import DockMenu from "./components/MenuBar.vue"; 2 | 3 | export { DockMenu }; -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import App from './App.vue' 3 | import './index.css' 4 | 5 | createApp(App).mount('#app') 6 | -------------------------------------------------------------------------------- /src/models/MenuBarDockPosition.ts: -------------------------------------------------------------------------------- 1 | enum MenuBarDockPosition { 2 | TOP = "TOP", 3 | LEFT = "LEFT", 4 | BOTTOM = "BOTTOM", 5 | RIGHT = "RIGHT", 6 | NOT_AVAILABLE = "NOT_AVAILABLE" 7 | } 8 | 9 | export default MenuBarDockPosition; -------------------------------------------------------------------------------- /src/models/MenuBarItemModel.ts: -------------------------------------------------------------------------------- 1 | import { MenuItemModel } from './MenuItemModel'; 2 | 3 | export interface MenuBarItemModel { 4 | name: string; 5 | id?: string; 6 | onSelect?: (id: string) => void; 7 | menu?: MenuItemModel[]; 8 | showMenu?: boolean; 9 | } -------------------------------------------------------------------------------- /src/models/MenuBarModel.ts: -------------------------------------------------------------------------------- 1 | import { MenuBarItemModel } from "./MenuBarItemModel"; 2 | 3 | export default interface MenuBarModel { 4 | items: MenuBarItemModel[]; 5 | } -------------------------------------------------------------------------------- /src/models/MenuItemModel.ts: -------------------------------------------------------------------------------- 1 | export interface MenuItemModel { 2 | name?: string; 3 | id?: string; 4 | onSelected?: (id: string) => void; 5 | menu?: MenuItemModel[]; 6 | disable?: boolean; 7 | highlight?: boolean; 8 | isDivider?: boolean; 9 | iconSlot?: string; 10 | } -------------------------------------------------------------------------------- /src/models/MenuModel.ts: -------------------------------------------------------------------------------- 1 | import { MenuItemModel } from "./MenuItemModel"; 2 | 3 | export interface MenuModel { 4 | items: MenuItemModel[]; 5 | } -------------------------------------------------------------------------------- /src/models/SelectedItemModel.ts: -------------------------------------------------------------------------------- 1 | export interface SelectedItemModel { 2 | name: string; 3 | path: string; 4 | event: MouseEvent | KeyboardEvent; 5 | isParent?: boolean; 6 | disable?: boolean; 7 | } -------------------------------------------------------------------------------- /src/models/Theme.ts: -------------------------------------------------------------------------------- 1 | export interface MenuTheme { 2 | primary: string; 3 | secondary: string; 4 | tertiary: string; 5 | textColor: string; 6 | textHoverColor: string; 7 | } -------------------------------------------------------------------------------- /src/utils/DragUtil.ts: -------------------------------------------------------------------------------- 1 | import MenuBarDockPosition from "../models/MenuBarDockPosition"; 2 | 3 | interface Coordinates { 4 | x: number; 5 | y: number; 6 | } 7 | 8 | const handleDragEnd: ( 9 | event: DragEvent | TouchEvent, 10 | clientCoordinates: Coordinates 11 | ) => { 12 | dragActive: boolean; 13 | dockPosition: MenuBarDockPosition; 14 | } | null = (event: DragEvent | TouchEvent, clientCoordinates: Coordinates) => { 15 | const winHeight = window.innerHeight; 16 | const winWidth = window.innerWidth; 17 | let xThreshold = 0; 18 | let yThreshold = 0; 19 | const { x, y } = clientCoordinates; 20 | 21 | const value = { 22 | dragActive: false, 23 | dockPosition: MenuBarDockPosition.NOT_AVAILABLE, 24 | }; 25 | 26 | if (event instanceof DragEvent) { 27 | xThreshold = Math.round((x / winWidth) * 100); 28 | yThreshold = Math.round((y / winHeight) * 100); 29 | } else if (event instanceof TouchEvent) { 30 | const touches = event.changedTouches[0]; 31 | if (Boolean(touches)) { 32 | const { clientX, clientY } = touches; 33 | xThreshold = Math.round((clientX / winWidth) * 100); 34 | yThreshold = Math.round((clientY / winHeight) * 100); 35 | } 36 | } 37 | 38 | if (xThreshold < 10) { 39 | value.dockPosition = MenuBarDockPosition.LEFT; 40 | } 41 | 42 | if (xThreshold > 90) { 43 | value.dockPosition = MenuBarDockPosition.RIGHT; 44 | } 45 | 46 | if (yThreshold > 90) { 47 | value.dockPosition = MenuBarDockPosition.BOTTOM; 48 | } 49 | 50 | if (yThreshold < 10) { 51 | value.dockPosition = MenuBarDockPosition.TOP; 52 | } 53 | 54 | if (value.dockPosition !== MenuBarDockPosition.NOT_AVAILABLE) { 55 | return value; 56 | } else { 57 | return null; 58 | } 59 | }; 60 | 61 | const handleDragStart: (event: DragEvent | TouchEvent) => void = ( 62 | event: DragEvent | TouchEvent 63 | ) => { 64 | // set a custom ghost image while dragging 65 | if (event instanceof DragEvent) { 66 | const img = new Image(); 67 | // img.src = 68 | // `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAsQAAALEBxi1JjQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua 69 | // 3NjYXBlLm9yZ5vuPBoAAAEFSURBVEiJ7dS9SgNBFIbhJymyWqRVay8ihT+FP42NlhZaewlW4lXkMsQuBDsLwUILKwstBAMiYilCMBCLHUHWjTujEZu8MPDN7sx5D5xlmfDf1CreZ9gN+RntkPfQ 70 | // HYfgKEhqWMU66jhGP1VWRj8IMrx9ej7EApbwhF5YG6mCYWT+kN3HFN3Ehbz7WEFZLmULd1hD4y8El/Jhll24iciVgldMj7gcQ6XgEbOJRb8V1Av7HuZ/IfhCUXCKlXEKiiziukQcS+UM4BzbPyie 71 | // YRBzsIUHzCUKWhK+un1cYSZB0MFhSkcH8n/LDpojzjTknXdwhqkUASzjBC/yARbXALeh8+TiE8A7L6BCi4Gh1q4AAAAASUVORK5CYII=`; 72 | event.dataTransfer?.setDragImage(img, 0, 0); 73 | } 74 | }; 75 | 76 | export default { handleDragEnd, handleDragStart }; 77 | -------------------------------------------------------------------------------- /src/utils/keyboardNavigator.ts: -------------------------------------------------------------------------------- 1 | import { MenuBarItemModel } from "@/models/MenuBarItemModel"; 2 | 3 | type tResult = 4 | | { 5 | navigateMenu: { 6 | items: MenuBarItemModel[]; 7 | }; 8 | } 9 | | { 10 | navigateMenubar: { 11 | nextId: string; 12 | }; 13 | }; 14 | 15 | const handleNav: ( 16 | id: string, 17 | dir: "prev" | "next", 18 | items: MenuBarItemModel[], 19 | activeSelection: number, 20 | activeMenuBarId: string 21 | ) => tResult = (id, dir, items, activeSelection, activeMenuBarId) => { 22 | const eleIndex = items.findIndex((item) => item.id === id); 23 | const newIdx = dir === "next" ? eleIndex + 1 : eleIndex - 1; 24 | const menuItemsLen = items.length; 25 | 26 | let nextId = ""; 27 | 28 | if (newIdx > -1 && newIdx < menuItemsLen) { 29 | nextId = items[newIdx].id as string; 30 | } else if (newIdx > menuItemsLen - 1) { 31 | nextId = items[0].id as string; 32 | } else if (newIdx < 0) { 33 | nextId = items[menuItemsLen - 1].id as string; 34 | } 35 | 36 | // get the menubar item 37 | const menuBarItem = items.find((item) => item.id === id); 38 | 39 | const menuItem = menuBarItem?.menu ? menuBarItem.menu[activeSelection] : null; 40 | 41 | let result: tResult; 42 | 43 | if (menuItem?.menu && dir === "next") { 44 | result = { 45 | navigateMenu: { 46 | items: items.map((item) => { 47 | if (item.id === activeMenuBarId) { 48 | return Object.assign({}, item, { 49 | menu: item.menu?.map((it) => 50 | Object.assign({}, it, { 51 | showSubMenu: 52 | it.name?.toLowerCase() === menuItem.name?.toLowerCase(), 53 | }) 54 | ), 55 | }); 56 | } else { 57 | return item; 58 | } 59 | }), 60 | }, 61 | }; 62 | } else { 63 | // move to the next menu bar item 64 | return { 65 | navigateMenubar: { 66 | nextId, 67 | }, 68 | }; 69 | } 70 | 71 | return result; 72 | }; 73 | 74 | export { handleNav }; 75 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "strict": true, 6 | "declaration": true, 7 | "declarationDir": "dist", 8 | "outDir": "dist", 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": true, 11 | "importHelpers": true, 12 | "moduleResolution": "node", 13 | "experimentalDecorators": true, 14 | "esModuleInterop": true, 15 | "allowSyntheticDefaultImports": true, 16 | "sourceMap": true, 17 | "baseUrl": ".", 18 | "types": [ 19 | "node", 20 | "vue" 21 | ], 22 | "paths": { 23 | "@/*": [ 24 | "src/*" 25 | ] 26 | }, 27 | "lib": [ 28 | "esnext", 29 | "dom", 30 | "dom.iterable", 31 | "scripthost" 32 | ] 33 | }, 34 | "exclude": [ 35 | "node_modules", 36 | "dist", 37 | "rollup.config.js" 38 | ], 39 | "include": [ 40 | "src" 41 | ], 42 | "files": [ 43 | "src/index.js" 44 | ] 45 | } -------------------------------------------------------------------------------- /vite.config.js: -------------------------------------------------------------------------------- 1 | import vue from "@vitejs/plugin-vue"; 2 | 3 | export default { 4 | plugins: [vue()], 5 | }; 6 | --------------------------------------------------------------------------------