HTMLLensRenderer.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. v-tippy="{ theme: 'tooltip' }"
  21. :title="
  22. previewEnabled ? t('hide.preview') : t('response.preview_html')
  23. "
  24. :svg="!previewEnabled ? 'eye' : 'eye-off'"
  25. @click.native.prevent="togglePreview"
  26. />
  27. <ButtonSecondary
  28. v-if="response.body"
  29. ref="downloadResponse"
  30. v-tippy="{ theme: 'tooltip' }"
  31. :title="t('action.download_file')"
  32. :svg="downloadIcon"
  33. @click.native="downloadResponse"
  34. />
  35. <ButtonSecondary
  36. v-if="response.body"
  37. ref="copyResponse"
  38. v-tippy="{ theme: 'tooltip' }"
  39. :title="t('action.copy')"
  40. :svg="copyIcon"
  41. @click.native="copyResponse"
  42. />
  43. </div>
  44. </div>
  45. <div
  46. v-show="!previewEnabled"
  47. ref="htmlResponse"
  48. class="flex flex-col flex-1"
  49. ></div>
  50. <iframe
  51. v-show="previewEnabled"
  52. ref="previewFrame"
  53. class="covers-response"
  54. src="about:blank"
  55. loading="lazy"
  56. sandbox=""
  57. ></iframe>
  58. </div>
  59. </template>
  60. <script setup lang="ts">
  61. import { ref, reactive } from "@nuxtjs/composition-api"
  62. import usePreview from "~/helpers/lenses/composables/usePreview"
  63. import useResponseBody from "~/helpers/lenses/composables/useResponseBody"
  64. import useDownloadResponse from "~/helpers/lenses/composables/useDownloadResponse"
  65. import useCopyResponse from "~/helpers/lenses/composables/useCopyResponse"
  66. import { useCodemirror } from "~/helpers/editor/codemirror"
  67. import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
  68. import { useI18n } from "~/helpers/utils/composables"
  69. const t = useI18n()
  70. const props = defineProps<{
  71. response: HoppRESTResponse
  72. }>()
  73. const htmlResponse = ref<any | null>(null)
  74. const linewrapEnabled = ref(true)
  75. const { responseBodyText } = useResponseBody(props.response)
  76. const { downloadIcon, downloadResponse } = useDownloadResponse(
  77. "text/html",
  78. responseBodyText
  79. )
  80. const { previewFrame, previewEnabled, togglePreview } = usePreview(
  81. false,
  82. responseBodyText
  83. )
  84. const { copyIcon, copyResponse } = useCopyResponse(responseBodyText)
  85. useCodemirror(
  86. htmlResponse,
  87. responseBodyText,
  88. reactive({
  89. extendedEditorConfig: {
  90. mode: "htmlmixed",
  91. readOnly: true,
  92. lineWrapping: linewrapEnabled,
  93. },
  94. linter: null,
  95. completer: null,
  96. environmentHighlights: true,
  97. })
  98. )
  99. </script>
  100. <style lang="scss" scoped>
  101. .covers-response {
  102. @apply bg-white;
  103. @apply h-full;
  104. @apply w-full;
  105. @apply border;
  106. @apply border-dividerLight;
  107. @apply z-5;
  108. }
  109. </style>