2023-12-11 15:12:51 +00:00
|
|
|
<template>
|
2023-12-12 12:20:36 +00:00
|
|
|
<client-only>
|
|
|
|
<vue-monaco-editor
|
|
|
|
:options="options"
|
|
|
|
:language="answers.language ?? 'text'"
|
|
|
|
v-model:value="answers.code"
|
|
|
|
class="min-h-[360px] code-editor"
|
|
|
|
/>
|
|
|
|
</client-only>
|
2023-12-11 15:12:51 +00:00
|
|
|
|
2023-12-12 12:20:36 +00:00
|
|
|
<n-divider class="mx-[-24px] w-[calc(100%+48px)] divider-below-code" />
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<n-space>
|
|
|
|
<n-select
|
|
|
|
:options="languages"
|
|
|
|
v-model:value="answers.language"
|
|
|
|
placeholder="Programming Language"
|
|
|
|
class="w-120"
|
|
|
|
/>
|
|
|
|
</n-space>
|
|
|
|
</section>
|
2023-12-11 15:12:51 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2023-12-12 12:20:36 +00:00
|
|
|
import { NDivider, NSpace, NSelect } from "naive-ui";
|
|
|
|
import { VueMonacoEditor } from "@guolao/vue-monaco-editor";
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
challenge: any,
|
|
|
|
problem: any,
|
|
|
|
answers: any,
|
|
|
|
}>();
|
|
|
|
const emits = defineEmits(["update:answers"]);
|
|
|
|
|
|
|
|
const answers = ref(props.challenge?.answers ?? {});
|
|
|
|
|
|
|
|
watch(answers, (v) => {
|
|
|
|
emits("update:answers", v);
|
|
|
|
});
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
minimap: { enabled: false }
|
|
|
|
};
|
|
|
|
|
|
|
|
const languageWhitelist: string[] = props.problem?.languageWhitelist ?? [];
|
|
|
|
const languageBlacklist: string[] = props.problem?.languageBlacklist ?? [];
|
2023-12-11 15:12:51 +00:00
|
|
|
|
2023-12-12 12:20:36 +00:00
|
|
|
const languages = [
|
|
|
|
{ label: "C", value: "c" },
|
|
|
|
{ label: "C++", value: "cpp" },
|
|
|
|
{ label: "JSON", value: "json" }, // Huh?
|
|
|
|
].filter((item) => {
|
|
|
|
return languageWhitelist.filter((x) => new RegExp(x, item.value)).length > 0 ||
|
|
|
|
!(languageBlacklist.filter((x) => new RegExp(x, item.value)).length > 0);
|
|
|
|
});
|
2023-12-11 15:12:51 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
2023-12-12 12:20:36 +00:00
|
|
|
.code-editor {
|
|
|
|
min-width: calc(100% + 48px);
|
|
|
|
margin-top: -20px;
|
|
|
|
margin-left: -24px;
|
|
|
|
margin-right: -24px;
|
|
|
|
}
|
2023-12-11 15:12:51 +00:00
|
|
|
|
2023-12-12 12:20:36 +00:00
|
|
|
.divider-below-code {
|
|
|
|
margin-top: 0 !important;
|
|
|
|
}
|
|
|
|
</style>
|