XMLLensRenderer.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div class="flex flex-col flex-1">
  3. <div
  4. class="sticky z-10 flex items-center justify-between pl-4 border-b bg-primary border-dividerLight top-lowerSecondaryStickyFold"
  5. >
  6. <label class="font-semibold text-secondaryLight">
  7. {{ t("response.body") }}
  8. </label>
  9. <div class="flex">
  10. <ButtonSecondary
  11. v-if="response.body"
  12. v-tippy="{ theme: 'tooltip' }"
  13. :title="t('state.linewrap')"
  14. :class="{ '!text-accent': linewrapEnabled }"
  15. svg="wrap-text"
  16. @click.native.prevent="linewrapEnabled = !linewrapEnabled"
  17. />
  18. <ButtonSecondary
  19. v-if="response.body"
  20. ref="downloadResponse"
  21. v-tippy="{ theme: 'tooltip' }"
  22. :title="t('action.download_file')"
  23. :svg="downloadIcon"
  24. @click.native="downloadResponse"
  25. />
  26. <ButtonSecondary
  27. v-if="response.body"
  28. ref="copyResponse"
  29. v-tippy="{ theme: 'tooltip' }"
  30. :title="t('action.copy')"
  31. :svg="copyIcon"
  32. @click.native="copyResponse"
  33. />
  34. </div>
  35. </div>
  36. <div ref="xmlResponse" class="flex flex-col flex-1"></div>
  37. </div>
  38. </template>
  39. <script setup lang="ts">
  40. import { computed, ref, reactive } from "@nuxtjs/composition-api"
  41. import { useCodemirror } from "~/helpers/editor/codemirror"
  42. import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
  43. import { useI18n } from "~/helpers/utils/composables"
  44. import useResponseBody from "~/helpers/lenses/composables/useResponseBody"
  45. import useDownloadResponse from "~/helpers/lenses/composables/useDownloadResponse"
  46. import useCopyResponse from "~/helpers/lenses/composables/useCopyResponse"
  47. const t = useI18n()
  48. const props = defineProps<{
  49. response: HoppRESTResponse
  50. }>()
  51. const { responseBodyText } = useResponseBody(props.response)
  52. const responseType = computed(() => {
  53. return (
  54. props.response.headers.find((h) => h.key.toLowerCase() === "content-type")
  55. .value || ""
  56. )
  57. .split(";")[0]
  58. .toLowerCase()
  59. })
  60. const { downloadIcon, downloadResponse } = useDownloadResponse(
  61. responseType.value,
  62. responseBodyText
  63. )
  64. const { copyIcon, copyResponse } = useCopyResponse(responseBodyText)
  65. const xmlResponse = ref<any | null>(null)
  66. const linewrapEnabled = ref(true)
  67. useCodemirror(
  68. xmlResponse,
  69. responseBodyText,
  70. reactive({
  71. extendedEditorConfig: {
  72. mode: "application/xml",
  73. readOnly: true,
  74. lineWrapping: linewrapEnabled,
  75. },
  76. linter: null,
  77. completer: null,
  78. environmentHighlights: true,
  79. })
  80. )
  81. </script>