2021-07-21 05:20:20 +00:00
|
|
|
<template>
|
2022-02-02 09:58:59 +00:00
|
|
|
<div class="flex flex-col flex-1">
|
2021-07-21 05:20:20 +00:00
|
|
|
<div
|
2022-02-02 09:58:59 +00:00
|
|
|
class="sticky z-10 flex items-center justify-between pl-4 border-b bg-primary border-dividerLight top-upperSecondaryStickyFold"
|
2021-07-21 05:20:20 +00:00
|
|
|
>
|
2021-12-01 17:29:01 +00:00
|
|
|
<label class="font-semibold text-secondaryLight">
|
2021-11-19 17:19:11 +00:00
|
|
|
{{ t("preRequest.javascript_code") }}
|
2021-07-21 05:20:20 +00:00
|
|
|
</label>
|
2021-08-17 07:26:36 +00:00
|
|
|
<div class="flex">
|
|
|
|
|
<ButtonSecondary
|
|
|
|
|
v-tippy="{ theme: 'tooltip' }"
|
2021-08-19 06:16:22 +00:00
|
|
|
to="https://docs.hoppscotch.io/features/pre-request-script"
|
2021-08-17 07:26:36 +00:00
|
|
|
blank
|
2021-11-19 17:19:11 +00:00
|
|
|
:title="t('app.wiki')"
|
2021-08-28 00:17:33 +00:00
|
|
|
svg="help-circle"
|
2021-08-17 07:26:36 +00:00
|
|
|
/>
|
2021-09-10 05:42:08 +00:00
|
|
|
<ButtonSecondary
|
|
|
|
|
v-tippy="{ theme: 'tooltip' }"
|
2021-11-19 17:19:11 +00:00
|
|
|
:title="t('state.linewrap')"
|
2021-09-10 05:42:08 +00:00
|
|
|
:class="{ '!text-accent': linewrapEnabled }"
|
2021-12-04 13:29:26 +00:00
|
|
|
svg="wrap-text"
|
2021-09-10 05:42:08 +00:00
|
|
|
@click.native.prevent="linewrapEnabled = !linewrapEnabled"
|
|
|
|
|
/>
|
2021-08-17 07:26:36 +00:00
|
|
|
<ButtonSecondary
|
|
|
|
|
v-tippy="{ theme: 'tooltip' }"
|
2021-11-19 17:19:11 +00:00
|
|
|
:title="t('action.clear')"
|
2021-08-28 00:17:33 +00:00
|
|
|
svg="trash-2"
|
2021-08-17 07:26:36 +00:00
|
|
|
@click.native="clearContent"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2021-07-21 05:20:20 +00:00
|
|
|
</div>
|
2022-02-03 02:41:41 +00:00
|
|
|
<div class="flex flex-1 border-b border-dividerLight">
|
2021-12-31 14:35:39 +00:00
|
|
|
<div class="w-2/3 border-r border-dividerLight">
|
2021-12-18 14:21:57 +00:00
|
|
|
<div ref="preRrequestEditor" class="h-full"></div>
|
2021-08-13 11:14:02 +00:00
|
|
|
</div>
|
|
|
|
|
<div
|
2021-12-31 14:35:39 +00:00
|
|
|
class="sticky h-full p-4 overflow-auto bg-primary top-upperTertiaryStickyFold min-w-46 max-w-1/3 z-9"
|
2021-08-13 11:14:02 +00:00
|
|
|
>
|
2021-12-31 14:35:39 +00:00
|
|
|
<div class="pb-2 text-secondaryLight">
|
2021-11-19 17:19:11 +00:00
|
|
|
{{ t("helpers.pre_request_script") }}
|
2021-08-13 11:14:02 +00:00
|
|
|
</div>
|
|
|
|
|
<SmartAnchor
|
2021-11-19 17:19:11 +00:00
|
|
|
:label="`${t('preRequest.learn')}`"
|
2021-08-19 17:08:50 +00:00
|
|
|
to="https://docs.hoppscotch.io/features/pre-request-script"
|
2021-08-13 11:14:02 +00:00
|
|
|
blank
|
|
|
|
|
/>
|
2021-12-31 14:35:39 +00:00
|
|
|
<h4 class="pt-6 font-bold text-secondaryLight">
|
2021-11-19 17:19:11 +00:00
|
|
|
{{ t("preRequest.snippets") }}
|
2021-08-16 08:48:45 +00:00
|
|
|
</h4>
|
|
|
|
|
<div class="flex flex-col pt-4">
|
2021-08-17 07:26:36 +00:00
|
|
|
<TabSecondary
|
2021-08-16 08:48:45 +00:00
|
|
|
v-for="(snippet, index) in snippets"
|
|
|
|
|
:key="`snippet-${index}`"
|
|
|
|
|
:label="snippet.name"
|
2021-08-17 07:26:36 +00:00
|
|
|
active
|
2021-08-16 08:48:45 +00:00
|
|
|
@click.native="useSnippet(snippet.script)"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2021-08-13 11:14:02 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-12-15 17:36:35 +00:00
|
|
|
</div>
|
2021-07-21 05:20:20 +00:00
|
|
|
</template>
|
|
|
|
|
|
2021-09-10 05:42:08 +00:00
|
|
|
<script setup lang="ts">
|
2021-11-19 17:19:11 +00:00
|
|
|
import { reactive, ref } from "@nuxtjs/composition-api"
|
2021-07-21 05:20:20 +00:00
|
|
|
import { usePreRequestScript } from "~/newstore/RESTSession"
|
2021-09-10 05:42:08 +00:00
|
|
|
import snippets from "~/helpers/preRequestScriptSnippets"
|
2021-11-10 09:01:00 +00:00
|
|
|
import { useCodemirror } from "~/helpers/editor/codemirror"
|
2021-09-10 05:42:08 +00:00
|
|
|
import linter from "~/helpers/editor/linting/preRequest"
|
|
|
|
|
import completer from "~/helpers/editor/completion/preRequest"
|
2021-11-19 17:19:11 +00:00
|
|
|
import { useI18n } from "~/helpers/utils/composables"
|
2021-09-10 05:42:08 +00:00
|
|
|
|
2021-11-19 17:19:11 +00:00
|
|
|
const t = useI18n()
|
2021-09-11 02:56:54 +00:00
|
|
|
|
2021-09-10 05:42:08 +00:00
|
|
|
const preRequestScript = usePreRequestScript()
|
2021-07-21 05:20:20 +00:00
|
|
|
|
2021-09-10 05:42:08 +00:00
|
|
|
const preRrequestEditor = ref<any | null>(null)
|
|
|
|
|
const linewrapEnabled = ref(true)
|
2021-08-17 07:26:36 +00:00
|
|
|
|
2021-09-10 05:42:08 +00:00
|
|
|
useCodemirror(
|
|
|
|
|
preRrequestEditor,
|
|
|
|
|
preRequestScript,
|
|
|
|
|
reactive({
|
|
|
|
|
extendedEditorConfig: {
|
|
|
|
|
mode: "application/javascript",
|
|
|
|
|
lineWrapping: linewrapEnabled,
|
2021-09-18 10:39:58 +00:00
|
|
|
placeholder: `${t("preRequest.javascript_code")}`,
|
2021-09-10 05:42:08 +00:00
|
|
|
},
|
|
|
|
|
linter,
|
|
|
|
|
completer,
|
2021-12-12 15:40:05 +00:00
|
|
|
environmentHighlights: false,
|
2021-09-10 05:42:08 +00:00
|
|
|
})
|
|
|
|
|
)
|
2021-08-17 07:26:36 +00:00
|
|
|
|
2021-09-10 05:42:08 +00:00
|
|
|
const useSnippet = (script: string) => {
|
|
|
|
|
preRequestScript.value += script
|
|
|
|
|
}
|
2021-08-17 07:26:36 +00:00
|
|
|
|
2021-09-10 05:42:08 +00:00
|
|
|
const clearContent = () => {
|
|
|
|
|
preRequestScript.value = ""
|
|
|
|
|
}
|
2021-07-21 05:20:20 +00:00
|
|
|
</script>
|