PowerSearch.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <SmartModal v-if="show" full-width @close="$emit('hide-modal')">
  3. <template #body>
  4. <input
  5. id="command"
  6. v-model="search"
  7. v-focus
  8. type="text"
  9. autocomplete="off"
  10. name="command"
  11. :placeholder="$t('app.type_a_command_search').toString()"
  12. class="
  13. bg-transparent
  14. border-b border-dividerLight
  15. flex flex-shrink-0
  16. text-secondaryDark text-base
  17. p-6
  18. "
  19. />
  20. <AppFuse
  21. v-if="search"
  22. :input="fuse"
  23. :search="search"
  24. @action="runAction"
  25. />
  26. <div
  27. v-else
  28. class="
  29. divide-y divide-dividerLight
  30. flex flex-col
  31. space-y-4
  32. flex-1
  33. overflow-auto
  34. hide-scrollbar
  35. "
  36. >
  37. <div v-for="(map, mapIndex) in mappings" :key="`map-${mapIndex}`">
  38. <h5 class="my-2 text-secondaryLight py-2 px-6">
  39. {{ $t(map.section) }}
  40. </h5>
  41. <AppPowerSearchEntry
  42. v-for="(shortcut, shortcutIndex) in map.shortcuts"
  43. :key="`map-${mapIndex}-shortcut-${shortcutIndex}`"
  44. :shortcut="shortcut"
  45. @action="runAction"
  46. />
  47. </div>
  48. </div>
  49. </template>
  50. </SmartModal>
  51. </template>
  52. <script setup lang="ts">
  53. import { ref } from "@nuxtjs/composition-api"
  54. import { HoppAction, invokeAction } from "~/helpers/actions"
  55. import { spotlight as mappings, fuse } from "~/helpers/shortcuts"
  56. defineProps<{
  57. show: boolean
  58. }>()
  59. const emit = defineEmits<{
  60. (e: "hide-modal"): void
  61. }>()
  62. const search = ref("")
  63. const hideModal = () => {
  64. search.value = ""
  65. emit("hide-modal")
  66. }
  67. const runAction = (command: HoppAction) => {
  68. invokeAction(command)
  69. hideModal()
  70. }
  71. </script>