Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

feat: port ace editor to codemirror

liyasthomas02cf6200901f
diff --git a/assets/scss/styles.scss b/assets/scss/styles.scss
index a08772cd2..b253cd68d 100644
--- a/assets/scss/styles.scss
+++ b/assets/scss/styles.scss
@@ -467,7 +467,7 @@ input[type="checkbox"] {
@apply border-b;
@apply border-dividerLight;
@apply w-full;
- @apply h-auto;
+ @apply !h-full;
}
.CodeMirror * {
diff --git a/components/graphql/Request.vue b/components/graphql/Request.vue
index a84a16459..304ca6482 100644
--- a/components/graphql/Request.vue
+++ b/components/graphql/Request.vue
@@ -33,45 +33,32 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent, PropType } from "@nuxtjs/composition-api"
+<script setup lang="ts">
import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
import { GQLConnection } from "~/helpers/GQLConnection"
import { getCurrentStrategyID } from "~/helpers/network"
import { useReadonlyStream, useStream } from "~/helpers/utils/composables"
import { gqlHeaders$, gqlURL$, setGQLURL } from "~/newstore/GQLSession"
-export default defineComponent({
- props: {
- conn: {
- type: Object as PropType<GQLConnection>,
- required: true,
- },
- },
- setup(props) {
- const connected = useReadonlyStream(props.conn.connected$, false)
- const headers = useReadonlyStream(gqlHeaders$, [])
+const props = defineProps<{
+ conn: GQLConnection
+}>()
- const url = useStream(gqlURL$, "", setGQLURL)
+const connected = useReadonlyStream(props.conn.connected$, false)
+const headers = useReadonlyStream(gqlHeaders$, [])
- const onConnectClick = () => {
- if (!connected.value) {
- props.conn.connect(url.value, headers.value as any)
+const url = useStream(gqlURL$, "", setGQLURL)
- logHoppRequestRunToAnalytics({
- platform: "graphql-schema",
- strategy: getCurrentStrategyID(),
- })
- } else {
- props.conn.disconnect()
- }
- }
+const onConnectClick = () => {
+ if (!connected.value) {
+ props.conn.connect(url.value, headers.value as any)
- return {
- url,
- connected,
- onConnectClick,
- }
- },
-})
+ logHoppRequestRunToAnalytics({
+ platform: "graphql-schema",
+ strategy: getCurrentStrategyID(),
+ })
+ } else {
+ props.conn.disconnect()
+ }
+}
</script>
diff --git a/components/graphql/RequestOptions.vue b/components/graphql/RequestOptions.vue
index 2c4863d36..e8c7147f8 100644
--- a/components/graphql/RequestOptions.vue
+++ b/components/graphql/RequestOptions.vue
@@ -106,19 +106,7 @@
/>
</div>
</div>
- <SmartAceEditor
- ref="variableEditor"
- v-model="variableString"
- :lang="'json'"
- :options="{
- maxLines: Infinity,
- minLines: 16,
- autoScrollEditorIntoView: true,
- showPrintMargin: false,
- useWorker: false,
- }"
- styles="border-b border-dividerLight"
- />
+ <div ref="variableEditor" class="w-full block"></div>
</AppSection>
</SmartTab>
@@ -323,6 +311,7 @@ import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
import { getCurrentStrategyID } from "~/helpers/network"
import { makeGQLRequest } from "~/helpers/types/HoppGQLRequest"
import { useCodemirror } from "~/helpers/editor/codemirror"
+import "codemirror/mode/javascript/javascript"
const props = defineProps<{
conn: GQLConnection
@@ -370,6 +359,16 @@ useCodemirror(bulkEditor, bulkHeaders, {
completer: null,
})
+const variableEditor = ref<any | null>(null)
+
+useCodemirror(variableEditor, variableString, {
+ extendedEditorConfig: {
+ mode: "javascript",
+ },
+ linter: null,
+ completer: null,
+})
+
const queryEditor = ref<any | null>(null)
const copyQueryIcon = ref("copy")
diff --git a/components/graphql/Response.vue b/components/graphql/Response.vue
index feca15fcd..09c6be4e1 100644
--- a/components/graphql/Response.vue
+++ b/components/graphql/Response.vue
@@ -59,38 +59,6 @@
justify-center
"
>
- <div class="flex space-x-2 pb-4">
- <div class="flex flex-col space-y-4 items-end">
- <span class="flex flex-1 items-center">
- {{ $t("shortcut.request.send_request") }}
- </span>
- <span class="flex flex-1 items-center">
- {{ $t("shortcut.general.show_all") }}
- </span>
- <!-- <span class="flex flex-1 items-center">
- {{ $t("shortcut.general.command_menu") }}
- </span>
- <span class="flex flex-1 items-center">
- {{ $t("shortcut.general.help_menu") }}
- </span> -->
- </div>
- <div class="flex flex-col space-y-4">
- <div class="flex">
- <span class="shortcut-key">{{ getSpecialKey() }}</span>
- <span class="shortcut-key">G</span>
- </div>
- <div class="flex">
- <span class="shortcut-key">{{ getSpecialKey() }}</span>
- <span class="shortcut-key">K</span>
- </div>
- <!-- <div class="flex">
- <span class="shortcut-key">/</span>
- </div>
- <div class="flex">
- <span class="shortcut-key">?</span>
- </div> -->
- </div>
- </div>
<ButtonSecondary
:label="$t('app.documentation')"
to="https://docs.hoppscotch.io"
@@ -103,77 +71,56 @@
</AppSection>
</template>
-<script lang="ts">
-import {
- defineComponent,
- PropType,
- ref,
- useContext,
-} from "@nuxtjs/composition-api"
+<script setup lang="ts">
+import { PropType, ref, useContext } from "@nuxtjs/composition-api"
import { GQLConnection } from "~/helpers/GQLConnection"
-import { getPlatformSpecialKey } from "~/helpers/platformutils"
import { copyToClipboard } from "~/helpers/utils/clipboard"
import { useReadonlyStream } from "~/helpers/utils/composables"
import { gqlResponse$ } from "~/newstore/GQLSession"
-export default defineComponent({
- props: {
- conn: {
- type: Object as PropType<GQLConnection>,
- required: true,
- },
+defineProps({
+ conn: {
+ type: Object as PropType<GQLConnection>,
+ required: true,
},
- setup() {
- const {
- $toast,
- app: { i18n },
- } = useContext()
- const t = i18n.t.bind(i18n)
-
- const responseString = useReadonlyStream(gqlResponse$, "")
-
- const downloadResponseIcon = ref("download")
- const copyResponseIcon = ref("copy")
-
- const copyResponse = () => {
- copyToClipboard(responseString.value!)
- copyResponseIcon.value = "check"
- setTimeout(() => (copyResponseIcon.value = "copy"), 1000)
- }
+})
- const downloadResponse = () => {
- const dataToWrite = responseString.value
- const file = new Blob([dataToWrite!], { type: "application/json" })
- const a = document.createElement("a")
- const url = URL.createObjectURL(file)
- a.href = url
- a.download = `${url.split("/").pop()!.split("#")[0].split("?")[0]}`
- document.body.appendChild(a)
- a.click()
- downloadResponseIcon.value = "check"
- $toast.success(t("state.download_started").toString(), {
- icon: "downloading",
- })
- setTimeout(() => {
- document.body.removeChild(a)
- URL.revokeObjectURL(url)
- downloadResponseIcon.value = "download"
- }, 1000)
- }
+const {
+ $toast,
+ app: { i18n },
+} = useContext()
+const t = i18n.t.bind(i18n)
- return {
- responseString,
+const responseString = useReadonlyStream(gqlResponse$, "")
- downloadResponseIcon,
- copyResponseIcon,
+const downloadResponseIcon = ref("download")
+const copyResponseIcon = ref("copy")
- downloadResponse,
- copyResponse,
+const copyResponse = () => {
+ copyToClipboard(responseString.value!)
+ copyResponseIcon.value = "check"
+ setTimeout(() => (copyResponseIcon.value = "copy"), 1000)
+}
- getSpecialKey: getPlatformSpecialKey,
- }
- },
-})
+const downloadResponse = () => {
+ const dataToWrite = responseString.value
+ const file = new Blob([dataToWrite!], { type: "application/json" })
+ const a = document.createElement("a")
+ const url = URL.createObjectURL(file)
+ a.href = url
+ a.download = `${url.split("/").pop()!.split("#")[0].split("?")[0]}`
+ document.body.appendChild(a)
+ a.click()
+ downloadResponseIcon.value = "check"
+ $toast.success(t("state.download_started").toString(), {
+ icon: "downloading",
+ })
+ setTimeout(() => {
+ document.body.removeChild(a)
+ URL.revokeObjectURL(url)
+ downloadResponseIcon.value = "download"
+ }, 1000)
+}
</script>
<style lang="scss" scoped>
diff --git a/components/http/ResponseMeta.vue b/components/http/ResponseMeta.vue
index 0052608a0..b0903e155 100644
--- a/components/http/ResponseMeta.vue
+++ b/components/http/ResponseMeta.vue
@@ -9,38 +9,6 @@
justify-center
"
>
- <div class="flex space-x-2 pb-4">
- <div class="flex flex-col space-y-4 items-end">
- <span class="flex flex-1 items-center">
- {{ $t("shortcut.request.send_request") }}
- </span>
- <span class="flex flex-1 items-center">
- {{ $t("shortcut.general.show_all") }}
- </span>
- <!-- <span class="flex flex-1 items-center">
- {{ $t("shortcut.general.command_menu") }}
- </span>
- <span class="flex flex-1 items-center">
- {{ $t("shortcut.general.help_menu") }}
- </span> -->
- </div>
- <div class="flex flex-col space-y-4">
- <div class="flex">
- <span class="shortcut-key">{{ getSpecialKey() }}</span>
- <span class="shortcut-key">G</span>
- </div>
- <div class="flex">
- <span class="shortcut-key">{{ getSpecialKey() }}</span>
- <span class="shortcut-key">K</span>
- </div>
- <!-- <div class="flex">
- <span class="shortcut-key">/</span>
- </div>
- <div class="flex">
- <span class="shortcut-key">?</span>
- </div> -->
- </div>
- </div>
<ButtonSecondary
:label="$t('app.documentation')"
to="https://docs.hoppscotch.io"
@@ -102,26 +70,22 @@
</div>
</template>
-<script>
-import { defineComponent } from "@nuxtjs/composition-api"
+<script setup lang="ts">
+import { computed } from "@nuxtjs/composition-api"
import findStatusGroup from "~/helpers/findStatusGroup"
-import { getPlatformSpecialKey } from "~/helpers/platformutils"
+import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
+
+const props = defineProps<{
+ response: HoppRESTResponse
+}>()
-export default defineComponent({
- props: {
- response: {
- type: Object,
- default: () => null,
- },
- },
- computed: {
- statusCategory() {
- return findStatusGroup(this.response.statusCode)
- },
- },
- methods: {
- getSpecialKey: getPlatformSpecialKey,
- },
+const statusCategory = computed(() => {
+ if (
+ props.response.type === "loading" ||
+ props.response.type === "network_fail"
+ )
+ return ""
+ return findStatusGroup(props.response.statusCode)
})
</script>
diff --git a/components/lenses/renderers/HTMLLensRenderer.vue b/components/lenses/renderers/HTMLLensRenderer.vue
index 9ba3e3d90..f3a751de4 100644
--- a/components/lenses/renderers/HTMLLensRenderer.vue
+++ b/components/lenses/renderers/HTMLLensRenderer.vue
@@ -45,19 +45,7 @@
</div>
</div>
<div class="relative">
- <SmartAceEditor
- :value="responseBodyText"
- :lang="'html'"
- :options="{
- maxLines: Infinity,
- minLines: 16,
- autoScrollEditorIntoView: true,
- readOnly: true,
- showPrintMargin: false,
- useWorker: false,
- }"
- styles="border-b border-dividerLight"
- />
+ <div ref="htmlResponse" class="w-full block"></div>
<iframe
ref="previewFrame"
:class="{ hidden: !previewEnabled }"
@@ -68,76 +56,102 @@
</div>
</template>
-<script>
-import { defineComponent } from "@nuxtjs/composition-api"
-import TextContentRendererMixin from "./mixins/TextContentRendererMixin"
+<script setup lang="ts">
+import { computed, ref, useContext } from "@nuxtjs/composition-api"
+import { useCodemirror } from "~/helpers/editor/codemirror"
import { copyToClipboard } from "~/helpers/utils/clipboard"
+import "codemirror/mode/htmlmixed/htmlmixed"
+import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
-export default defineComponent({
- mixins: [TextContentRendererMixin],
- props: {
- response: { type: Object, default: () => {} },
- },
- data() {
- return {
- downloadIcon: "download",
- copyIcon: "copy",
- previewEnabled: false,
- }
- },
- methods: {
- downloadResponse() {
- const dataToWrite = this.responseBodyText
- const file = new Blob([dataToWrite], { type: "text/html" })
- const a = document.createElement("a")
- const url = URL.createObjectURL(file)
- a.href = url
- // TODO get uri from meta
- a.download = `${url.split("/").pop().split("#")[0].split("?")[0]}`
- document.body.appendChild(a)
- a.click()
- this.downloadIcon = "check"
- this.$toast.success(this.$t("state.download_started"), {
- icon: "downloading",
- })
- setTimeout(() => {
- document.body.removeChild(a)
- URL.revokeObjectURL(url)
- this.downloadIcon = "download"
- }, 1000)
- },
- copyResponse() {
- copyToClipboard(this.responseBodyText)
- this.copyIcon = "check"
- this.$toast.success(this.$t("state.copied_to_clipboard"), {
- icon: "content_paste",
- })
- setTimeout(() => (this.copyIcon = "copy"), 1000)
- },
- togglePreview() {
- this.previewEnabled = !this.previewEnabled
- if (this.previewEnabled) {
- if (
- this.$refs.previewFrame.getAttribute("data-previewing-url") ===
- this.url
- )
- return
- // Use DOMParser to parse document HTML.
- const previewDocument = new DOMParser().parseFromString(
- this.responseBodyText,
- "text/html"
- )
- // Inject <base href="..."> tag to head, to fix relative CSS/HTML paths.
- previewDocument.head.innerHTML =
- `<base href="${this.url}">` + previewDocument.head.innerHTML
- // Finally, set the iframe source to the resulting HTML.
- this.$refs.previewFrame.srcdoc =
- previewDocument.documentElement.outerHTML
- this.$refs.previewFrame.setAttribute("data-previewing-url", this.url)
- }
- },
+const props = defineProps<{
+ response: HoppRESTResponse
+}>()
+
+const {
+ $toast,
+ app: { i18n },
+} = useContext()
+const t = i18n.t.bind(i18n)
+
+const responseBodyText = computed(() => {
+ if (
+ props.response.type === "loading" ||
+ props.response.type === "network_fail"
+ )
+ return ""
+ if (typeof props.response.body === "string") return props.response.body
+ else {
+ const res = new TextDecoder("utf-8").decode(props.response.body)
+ // HACK: Temporary trailing null character issue from the extension fix
+ return res.replace(/\0+$/, "")
+ }
+})
+
+const downloadIcon = ref("download")
+const copyIcon = ref("copy")
+const previewEnabled = ref(false)
+const previewFrame = ref<any | null>(null)
+const url = ref("")
+
+const htmlResponse = ref<any | null>(null)
+
+useCodemirror(htmlResponse, responseBodyText, {
+ extendedEditorConfig: {
+ mode: "javascript",
+ readOnly: true,
},
+ linter: null,
+ completer: null,
})
+
+const downloadResponse = () => {
+ const dataToWrite = responseBodyText.value
+ const file = new Blob([dataToWrite], { type: "text/html" })
+ const a = document.createElement("a")
+ const url = URL.createObjectURL(file)
+ a.href = url
+ // TODO get uri from meta
+ a.download = `${url.split("/").pop().split("#")[0].split("?")[0]}`
+ document.body.appendChild(a)
+ a.click()
+ downloadIcon.value = "check"
+ $toast.success(t("state.download_started").toString(), {
+ icon: "downloading",
+ })
+ setTimeout(() => {
+ document.body.removeChild(a)
+ URL.revokeObjectURL(url)
+ downloadIcon.value = "download"
+ }, 1000)
+}
+
+const copyResponse = () => {
+ copyToClipboard(responseBodyText.value)
+ copyIcon.value = "check"
+ $toast.success(t("state.copied_to_clipboard").toString(), {
+ icon: "content_paste",
+ })
+ setTimeout(() => (copyIcon.value = "copy"), 1000)
+}
+
+const togglePreview = () => {
+ previewEnabled.value = !previewEnabled.value
+ if (previewEnabled.value) {
+ if (previewFrame.value.getAttribute("data-previewing-url") === url.value)
+ return
+ // Use DOMParser to parse document HTML.
+ const previewDocument = new DOMParser().parseFromString(
+ responseBodyText.value,
+ "text/html"
+ )
+ // Inject <base href="..."> tag to head, to fix relative CSS/HTML paths.
+ previewDocument.head.innerHTML =
+ `<base href="${url.value}">` + previewDocument.head.innerHTML
+ // Finally, set the iframe source to the resulting HTML.
+ previewFrame.value.srcdoc = previewDocument.documentElement.outerHTML
+ previewFrame.value.setAttribute("data-previewing-url", url.value)
+ }
+}
</script>
<style lang="scss" scoped>
@@ -149,5 +163,6 @@ export default defineComponent({
@apply w-full;
@apply border;
@apply border-dividerLight;
+ @apply z-5;
}
</style>
diff --git a/components/lenses/renderers/JSONLensRenderer.vue b/components/lenses/renderers/JSONLensRenderer.vue
index fc6bc2f12..c1ea9347d 100644
--- a/components/lenses/renderers/JSONLensRenderer.vue
+++ b/components/lenses/renderers/JSONLensRenderer.vue
@@ -36,88 +36,92 @@
</div>
</div>
<div class="relative">
- <SmartAceEditor
- :value="jsonBodyText"
- :lang="'json'"
- :provide-outline="true"
- :options="{
- maxLines: Infinity,
- minLines: 16,
- autoScrollEditorIntoView: true,
- readOnly: true,
- showPrintMargin: false,
- useWorker: false,
- }"
- styles="border-b border-dividerLight"
- />
+ <div ref="jsonResponse" class="w-full block"></div>
</div>
</div>
</template>
-<script>
-import { defineComponent } from "@nuxtjs/composition-api"
-import TextContentRendererMixin from "./mixins/TextContentRendererMixin"
+<script setup lang="ts">
+import { computed, ref, useContext } from "@nuxtjs/composition-api"
+import { useCodemirror } from "~/helpers/editor/codemirror"
import { copyToClipboard } from "~/helpers/utils/clipboard"
+import "codemirror/mode/javascript/javascript"
+import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
-export default defineComponent({
- mixins: [TextContentRendererMixin],
- props: {
- response: { type: Object, default: () => {} },
- },
- data() {
- return {
- downloadIcon: "download",
- copyIcon: "copy",
- }
- },
- computed: {
- jsonBodyText() {
- try {
- return JSON.stringify(JSON.parse(this.responseBodyText), null, 2)
- } catch (e) {
- // Most probs invalid JSON was returned, so drop prettification (should we warn ?)
- return this.responseBodyText
- }
- },
- responseType() {
- return (
- this.response.headers.find(
- (h) => h.key.toLowerCase() === "content-type"
- ).value || ""
- )
- .split(";")[0]
- .toLowerCase()
- },
- },
- methods: {
- downloadResponse() {
- const dataToWrite = this.responseBodyText
- const file = new Blob([dataToWrite], { type: "application/json" })
- const a = document.createElement("a")
- const url = URL.createObjectURL(file)
- a.href = url
- // TODO get uri from meta
- a.download = `${url.split("/").pop().split("#")[0].split("?")[0]}`
- document.body.appendChild(a)
- a.click()
- this.downloadIcon = "check"
- this.$toast.success(this.$t("state.download_started"), {
- icon: "downloading",
- })
- setTimeout(() => {
- document.body.removeChild(a)
- URL.revokeObjectURL(url)
- this.downloadIcon = "download"
- }, 1000)
- },
- copyResponse() {
- copyToClipboard(this.responseBodyText)
- this.copyIcon = "check"
- this.$toast.success(this.$t("state.copied_to_clipboard"), {
- icon: "content_paste",
- })
- setTimeout(() => (this.copyIcon = "copy"), 1000)
- },
+const props = defineProps<{
+ response: HoppRESTResponse
+}>()
+
+const {
+ $toast,
+ app: { i18n },
+} = useContext()
+const t = i18n.t.bind(i18n)
+
+const responseBodyText = computed(() => {
+ if (
+ props.response.type === "loading" ||
+ props.response.type === "network_fail"
+ )
+ return ""
+ if (typeof props.response.body === "string") return props.response.body
+ else {
+ const res = new TextDecoder("utf-8").decode(props.response.body)
+ // HACK: Temporary trailing null character issue from the extension fix
+ return res.replace(/\0+$/, "")
+ }
+})
+
+const downloadIcon = ref("download")
+const copyIcon = ref("copy")
+
+const jsonBodyText = computed(() => {
+ try {
+ return JSON.stringify(JSON.parse(responseBodyText.value), null, 2)
+ } catch (e) {
+ // Most probs invalid JSON was returned, so drop prettification (should we warn ?)
+ return responseBodyText.value
+ }
+})
+
+const jsonResponse = ref<any | null>(null)
+
+useCodemirror(jsonResponse, jsonBodyText, {
+ extendedEditorConfig: {
+ mode: "javascript",
+ readOnly: true,
},
+ linter: null,
+ completer: null,
})
+
+const downloadResponse = () => {
+ const dataToWrite = responseBodyText.value
+ const file = new Blob([dataToWrite], { type: "application/json" })
+ const a = document.createElement("a")
+ const url = URL.createObjectURL(file)
+ a.href = url
+ // TODO get uri from meta
+ a.download = `${url.split("/").pop().split("#")[0].split("?")[0]}`
+ document.body.appendChild(a)
+ a.click()
+ downloadIcon.value = "check"
+ $toast.success(t("state.download_started").toString(), {
+ icon: "downloading",
+ })
+ setTimeout(() => {
+ document.body.removeChild(a)
+ URL.revokeObjectURL(url)
+ downloadIcon.value = "download"
+ }, 1000)
+}
+
+const copyResponse = () => {
+ copyToClipboard(responseBodyText.value)
+ copyIcon.value = "check"
+ $toast.success(t("state.copied_to_clipboard").toString(), {
+ icon: "content_paste",
+ })
+ setTimeout(() => (copyIcon.value = "copy"), 1000)
+}
</script>
diff --git a/components/lenses/renderers/RawLensRenderer.vue b/components/lenses/renderers/RawLensRenderer.vue
index 563f9de1f..ec5b015aa 100644
--- a/components/lenses/renderers/RawLensRenderer.vue
+++ b/components/lenses/renderers/RawLensRenderer.vue
@@ -36,79 +36,92 @@
</div>
</div>
<div class="relative">
- <SmartAceEditor
- :value="responseBodyText"
- :lang="'plain_text'"
- :options="{
- maxLines: Infinity,
- minLines: 16,
- autoScrollEditorIntoView: true,
- readOnly: true,
- showPrintMargin: false,
- useWorker: false,
- }"
- styles="border-b border-dividerLight"
- />
+ <div ref="rawResponse" class="w-full block"></div>
</div>
</div>
</template>
-<script>
-import { defineComponent } from "@nuxtjs/composition-api"
-import TextContentRendererMixin from "./mixins/TextContentRendererMixin"
+<script setup lang="ts">
+import { ref, useContext, computed } from "@nuxtjs/composition-api"
+import { useCodemirror } from "~/helpers/editor/codemirror"
import { copyToClipboard } from "~/helpers/utils/clipboard"
+import "codemirror/mode/yaml/yaml"
+import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
-export default defineComponent({
- mixins: [TextContentRendererMixin],
- props: {
- response: { type: Object, default: () => {} },
- },
- data() {
- return {
- downloadIcon: "download",
- copyIcon: "copy",
- }
- },
- computed: {
- responseType() {
- return (
- this.response.headers.find(
- (h) => h.key.toLowerCase() === "content-type"
- ).value || ""
- )
- .split(";")[0]
- .toLowerCase()
- },
- },
- methods: {
- downloadResponse() {
- const dataToWrite = this.responseBodyText
- const file = new Blob([dataToWrite], { type: this.responseType })
- const a = document.createElement("a")
- const url = URL.createObjectURL(file)
- a.href = url
- // TODO get uri from meta
- a.download = `${url.split("/").pop().split("#")[0].split("?")[0]}`
- document.body.appendChild(a)
- a.click()
- this.downloadIcon = "check"
- this.$toast.success(this.$t("state.download_started"), {
- icon: "downloading",
- })
- setTimeout(() => {
- document.body.removeChild(a)
- URL.revokeObjectURL(url)
- this.downloadIcon = "download"
- }, 1000)
- },
- copyResponse() {
- copyToClipboard(this.responseBodyText)
- this.copyIcon = "check"
- this.$toast.success(this.$t("state.copied_to_clipboard"), {
- icon: "content_paste",
- })
- setTimeout(() => (this.copyIcon = "copy"), 1000)
- },
+const props = defineProps<{
+ response: HoppRESTResponse
+}>()
+
+const {
+ $toast,
+ app: { i18n },
+} = useContext()
+const t = i18n.t.bind(i18n)
+
+const responseBodyText = computed(() => {
+ if (
+ props.response.type === "loading" ||
+ props.response.type === "network_fail"
+ )
+ return ""
+ if (typeof props.response.body === "string") return props.response.body
+ else {
+ const res = new TextDecoder("utf-8").decode(props.response.body)
+ // HACK: Temporary trailing null character issue from the extension fix
+ return res.replace(/\0+$/, "")
+ }
+})
+
+const downloadIcon = ref("download")
+const copyIcon = ref("copy")
+
+const responseType = computed(() => {
+ return (
+ props.response.headers.find((h) => h.key.toLowerCase() === "content-type")
+ .value || ""
+ )
+ .split(";")[0]
+ .toLowerCase()
+})
+
+const rawResponse = ref<any | null>(null)
+
+useCodemirror(rawResponse, responseBodyText, {
+ extendedEditorConfig: {
+ mode: "text/x-yaml",
+ readOnly: true,
},
+ linter: null,
+ completer: null,
})
+
+const downloadResponse = () => {
+ const dataToWrite = responseBodyText.value
+ const file = new Blob([dataToWrite], { type: responseType.value })
+ const a = document.createElement("a")
+ const url = URL.createObjectURL(file)
+ a.href = url
+ // TODO get uri from meta
+ a.download = `${url.split("/").pop().split("#")[0].split("?")[0]}`
+ document.body.appendChild(a)
+ a.click()
+ downloadIcon.value = "check"
+ $toast.success(t("state.download_started").toString(), {
+ icon: "downloading",
+ })
+ setTimeout(() => {
+ document.body.removeChild(a)
+ URL.revokeObjectURL(url)
+ downloadIcon.value = "download"
+ }, 1000)
+}
+
+const copyResponse = () => {
+ copyToClipboard(responseBodyText.value)
+ copyIcon.value = "check"
+ $toast.success(t("state.copied_to_clipboard").toString(), {
+ icon: "content_paste",
+ })
+ setTimeout(() => (copyIcon.value = "copy"), 1000)
+}
</script>
diff --git a/components/lenses/renderers/XMLLensRenderer.vue b/components/lenses/renderers/XMLLensRenderer.vue
index eb5340f41..11a6463a6 100644
--- a/components/lenses/renderers/XMLLensRenderer.vue
+++ b/components/lenses/renderers/XMLLensRenderer.vue
@@ -36,79 +36,92 @@
</div>
</div>
<div class="relative">
- <SmartAceEditor
- :value="responseBodyText"
- :lang="'xml'"
- :options="{
- maxLines: Infinity,
- minLines: 16,
- autoScrollEditorIntoView: true,
- readOnly: true,
- showPrintMargin: false,
- useWorker: false,
- }"
- styles="border-b border-dividerLight"
- />
+ <div ref="xmlResponse" class="w-full block"></div>
</div>
</div>
</template>
-<script>
-import { defineComponent } from "@nuxtjs/composition-api"
-import TextContentRendererMixin from "./mixins/TextContentRendererMixin"
+<script setup lang="ts">
+import { computed, ref, useContext } from "@nuxtjs/composition-api"
+import { useCodemirror } from "~/helpers/editor/codemirror"
import { copyToClipboard } from "~/helpers/utils/clipboard"
+import "codemirror/mode/xml/xml"
+import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
-export default defineComponent({
- mixins: [TextContentRendererMixin],
- props: {
- response: { type: Object, default: () => {} },
- },
- data() {
- return {
- copyIcon: "copy",
- downloadIcon: "download",
- }
- },
- computed: {
- responseType() {
- return (
- this.response.headers.find(
- (h) => h.key.toLowerCase() === "content-type"
- ).value || ""
- )
- .split(";")[0]
- .toLowerCase()
- },
- },
- methods: {
- downloadResponse() {
- const dataToWrite = this.responseBodyText
- const file = new Blob([dataToWrite], { type: this.responseType })
- const a = document.createElement("a")
- const url = URL.createObjectURL(file)
- a.href = url
- // TODO get uri from meta
- a.download = `${url.split("/").pop().split("#")[0].split("?")[0]}`
- document.body.appendChild(a)
- a.click()
- this.downloadIcon = "check"
- this.$toast.success(this.$t("state.download_started"), {
- icon: "downloading",
- })
- setTimeout(() => {
- document.body.removeChild(a)
- URL.revokeObjectURL(url)
- this.downloadIcon = "download"
- }, 1000)
- },
- copyResponse() {
- copyToClipboard(this.responseBodyText)
- this.copyIcon = "check"
- this.$toast.success(this.$t("state.copied_to_clipboard"), {
- icon: "content_paste",
- })
- setTimeout(() => (this.copyIcon = "copy"), 1000)
- },
+const props = defineProps<{
+ response: HoppRESTResponse
+}>()
+
+const {
+ $toast,
+ app: { i18n },
+} = useContext()
+const t = i18n.t.bind(i18n)
+
+const responseBodyText = computed(() => {
+ if (
+ props.response.type === "loading" ||
+ props.response.type === "network_fail"
+ )
+ return ""
+ if (typeof props.response.body === "string") return props.response.body
+ else {
+ const res = new TextDecoder("utf-8").decode(props.response.body)
+ // HACK: Temporary trailing null character issue from the extension fix
+ return res.replace(/\0+$/, "")
+ }
+})
+
+const downloadIcon = ref("download")
+const copyIcon = ref("copy")
+
+const responseType = computed(() => {
+ return (
+ props.response.headers.find((h) => h.key.toLowerCase() === "content-type")
+ .value || ""
+ )
+ .split(";")[0]
+ .toLowerCase()
+})
+
+const xmlResponse = ref<any | null>(null)
+
+useCodemirror(xmlResponse, responseBodyText, {
+ extendedEditorConfig: {
+ mode: "application/xml",
+ readOnly: true,
},
+ linter: null,
+ completer: null,
})
+
+const downloadResponse = () => {
+ const dataToWrite = responseBodyText.value
+ const file = new Blob([dataToWrite], { type: responseType.value })
+ const a = document.createElement("a")
+ const url = URL.createObjectURL(file)
+ a.href = url
+ // TODO get uri from meta
+ a.download = `${url.split("/").pop().split("#")[0].split("?")[0]}`
+ document.body.appendChild(a)
+ a.click()
+ downloadIcon.value = "check"
+ $toast.success(t("state.download_started").toString(), {
+ icon: "downloading",
+ })
+ setTimeout(() => {
+ document.body.removeChild(a)
+ URL.revokeObjectURL(url)
+ downloadIcon.value = "download"
+ }, 1000)
+}
+
+const copyResponse = () => {
+ copyToClipboard(responseBodyText.value)
+ copyIcon.value = "check"
+ $toast.success(t("state.copied_to_clipboard").toString(), {
+ icon: "content_paste",
+ })
+ setTimeout(() => (copyIcon.value = "copy"), 1000)
+}
</script>
diff --git a/helpers/editor/codemirror.ts b/helpers/editor/codemirror.ts
index 487365c49..e7781ae7c 100644
--- a/helpers/editor/codemirror.ts
+++ b/helpers/editor/codemirror.ts
@@ -44,6 +44,7 @@ const DEFAULT_EDITOR_CONFIG: CodeMirror.EditorConfiguration = {
extraKeys: {
"Ctrl-Space": "autocomplete",
},
+ viewportMargin: Infinity,
}
/**
@@ -120,6 +121,8 @@ export function useCodemirror(
cm.value = CodeMirror(el.value!, DEFAULT_EDITOR_CONFIG)
+ cm.value.setValue(value.value)
+
setTheme()
updateEditorConfig()
updateLinterConfig()
@@ -139,7 +142,14 @@ export function useCodemirror(
})
// Reinitialize if the target ref updates
- watch(el, initialize)
+ watch(el, () => {
+ if (cm.value) {
+ const parent = cm.value.getWrapperElement()
+ parent.remove()
+ cm.value = null
+ }
+ initialize()
+ })
const setTheme = () => {
if (cm.value) {