| <template> |
| <li v-if="isTopLevel" class="nav-item"> |
| <a class="nav-link" @click="runFunction(menuData)"> |
| {{ menuData.text }} |
| </a> |
| </li> |
| <li v-else> |
| <Tooltip :tip="introductionTxt(menuData.pluginId)" placement="right"> |
| <a |
| :class="'dropdown-item pt-0' + (disabled ? ' disabled' : '')" |
| style="padding-bottom: 2px; pointer-events: all" |
| @click="runFunction(menuData)" |
| :id="'menu-plugin-' + idSlug" |
| > |
| <span v-html='menuData.text?.replace("_", "")'></span> |
| <div v-if="showHotkey" style="float: right" class="text-muted"> |
| {{ hotkeyPrefix }}{{ hotkeyToShow(menuData) }} |
| </div> |
| </a> |
| </Tooltip> |
| </li> |
| </template> |
| |
| <script lang="ts"> |
| |
| |
| import { Options, Vue } from "vue-class-component"; |
| import { Prop } from "vue-property-decorator"; |
| import { IMenuItem } from "./Menu"; |
| import { dynamicImports } from "@/Core/DynamicImports"; |
| import Tooltip from "@/UI/MessageAlerts/Tooltip.vue"; |
| import { loadedPlugins } from "@/Plugins/LoadedPlugins"; |
| import { slugify } from "@/Core/Utils/StringUtils"; |
| |
| let collapseHamburger: any; |
| let hamburgerMenu: HTMLElement; |
| |
| |
| |
| |
| @Options({ |
| components: { Tooltip }, |
| }) |
| export default class MenuActionLink extends Vue { |
| @Prop() menuData!: IMenuItem; |
| @Prop({ default: false }) isTopLevel!: boolean; |
| |
| hotkeyPrefix = "Ctrl+"; |
| |
| |
| |
| |
| |
| |
| |
| |
| introductionTxt(pluginId: string | undefined): string { |
| if (pluginId === undefined) { |
| return ""; |
| } |
| |
| if (!loadedPlugins[pluginId].intro) { |
| return ""; |
| } |
| |
| let txt = loadedPlugins[pluginId].intro as string; |
| |
| |
| txt = txt.replace(/<[^>]*>?/g, ""); |
| |
| return txt; |
| } |
| |
| |
| |
| |
| |
| |
| get disabled(): boolean { |
| const checkPluginAllowed = this.menuData.checkPluginAllowed; |
| if (checkPluginAllowed) { |
| const pluginAllowed = checkPluginAllowed( |
| this.$store.state.molecules |
| ); |
| return pluginAllowed !== null; |
| } |
| return false; |
| } |
| |
| |
| |
| |
| |
| |
| |
| hotkeyToShow(menuData: IMenuItem): string { |
| if (!menuData.hotkey) { |
| return ""; |
| } |
| |
| if (menuData.hotkey === "up") { |
| return "↑"; |
| } |
| |
| if (menuData.hotkey === "down") { |
| return "↓"; |
| } |
| |
| return menuData.hotkey.toUpperCase(); |
| } |
| |
| |
| |
| |
| |
| |
| get showHotkey(): boolean { |
| const hotkey = this.menuData.hotkey; |
| if (!hotkey) { |
| return false; |
| } |
| if (hotkey === "") { |
| return false; |
| } |
| |
| if (hotkey == "up" || hotkey == "down") { |
| return true; |
| } |
| |
| |
| |
| |
| return hotkey.length === 1; |
| } |
| |
| |
| |
| |
| |
| |
| get idSlug(): string { |
| return `${this.menuData.pluginId}-${slugify(this.menuData.text as string)}`; |
| } |
| |
| |
| |
| |
| |
| private closeRegularMenu() { |
| const dropdownElementList = document.querySelectorAll( |
| ".top-level-menu-item" |
| ); |
| |
| dynamicImports.bootstrapDropdown.module |
| .then((Dropdown: any) => { |
| dropdownElementList.forEach((dropdownToggleEl) => |
| new Dropdown(dropdownToggleEl).hide() |
| ); |
| return; |
| }) |
| .catch((err) => { |
| throw err; |
| }); |
| } |
| |
| |
| |
| |
| private closeHamburgerMenu() { |
| if (!hamburgerMenu) { |
| hamburgerMenu = document.getElementById( |
| "hamburger-button" |
| ) as HTMLElement; |
| } |
| |
| if (hamburgerMenu.offsetWidth > 0 && hamburgerMenu.offsetHeight > 0) { |
| dynamicImports.bootstrapCollapse.module |
| .then((Collapse: any) => { |
| |
| if (!collapseHamburger) { |
| collapseHamburger = new Collapse( |
| document.getElementById( |
| "navbarSupportedContent" |
| ) as HTMLElement |
| ); |
| } |
| |
| collapseHamburger.toggle(); |
| return; |
| }) |
| .catch((err) => { |
| throw err; |
| }); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| runFunction(item: IMenuItem) { |
| if (item.function) { |
| this.closeRegularMenu(); |
| this.closeHamburgerMenu(); |
| |
| |
| item.function(); |
| } |
| } |
| |
| |
| |
| |
| mounted() { |
| |
| dynamicImports.detectOs.module |
| .then((OSDetector) => { |
| const os = new OSDetector().detect().os; |
| switch (os) { |
| case "macos": |
| case "ios": |
| this.hotkeyPrefix = "⌘ "; |
| break; |
| default: |
| this.hotkeyPrefix = "Ctrl+"; |
| break; |
| } |
| return; |
| }) |
| .catch((err) => { |
| throw err; |
| }); |
| } |
| } |
| </script> |
| |
| |
| <style scoped lang="scss"></style> |
| |