-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
133 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<template> | ||
<Container> | ||
<template #header> | ||
Input | ||
<div :class="$style.actions" v-if='props.samples'> | ||
<MenuButton :options='Object.keys(props.samples!)' @select='onSelectSample'/> | ||
</div> | ||
</template> | ||
<PrismEditor :class="$style.code" v-model="modelValueInter" :highlight="highlighter" :line-numbers="false"/> | ||
<template #footer> | ||
<span v-if="props.parseError" :class="$style.parseError">{{ props.parseError }}</span> | ||
<div :class="$style.actions"><button @click="emit('run')">RUN</button></div> | ||
</template> | ||
</Container> | ||
</template> | ||
|
||
<script setup lang='ts'> | ||
import { ref, watch } from 'vue'; | ||
import { PrismEditor } from 'vue-prism-editor'; | ||
import 'vue-prism-editor/dist/prismeditor.min.css'; | ||
import 'prismjs'; | ||
/** | ||
* @types/prismjsの更新が止まっているためとりあえずts-ignoreする(declare moduleしようとしたがうまくいかなかった) | ||
*/ | ||
// @ts-ignore | ||
import { highlight, languages } from 'prismjs/components/prism-core'; | ||
import 'prismjs/components/prism-clike'; | ||
import 'prismjs/components/prism-javascript'; | ||
import 'prismjs/themes/prism-okaidia.css'; | ||
import Container from './Container.vue'; | ||
import MenuButton from './MenuButton.vue'; | ||
// 使う場所はそんなにないしとりあえずunknownで | ||
type Grammer = unknown; | ||
declare var languages: { | ||
js: Grammer; | ||
}; | ||
declare function highlight(test: string, grammer: Grammer, language: string): string; | ||
const props = defineProps<{ | ||
modelValue: string; | ||
samples?: Record<string, string>; | ||
parseError?: string|null; | ||
}>(); | ||
const emit = defineEmits<{ | ||
(e: 'run'): void; | ||
(e: 'update:modelValue', value: string): void; | ||
}>(); | ||
const modelValueInter = ref<string>(props.modelValue); | ||
watch(modelValueInter, () => { | ||
emit('update:modelValue', modelValueInter.value); | ||
}, { | ||
immediate: true | ||
}); | ||
function onSelectSample(chosen: string) { | ||
modelValueInter.value = props.samples![chosen] as string; | ||
} | ||
const highlighter = (code: string) => { | ||
return highlight(code, languages.js, 'javascript'); | ||
}; | ||
</script> | ||
|
||
<style module> | ||
.code { | ||
box-sizing: border-box; | ||
padding: 0; | ||
} | ||
.parseError { | ||
color: #f00; | ||
} | ||
.actions { | ||
margin-left: auto; | ||
float: right; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<template> | ||
<div> | ||
<button @click="showMenu=!showMenu">Samples</button> | ||
<Transition> | ||
<div v-if='showMenu' :class="$style.menu"> | ||
<div v-if='options instanceof Array'> | ||
<div v-for='opt in options' :class="$style.opt" @click="showMenu=false; emit('select', opt)">{{ opt }}</div> | ||
</div> | ||
<div v-else> | ||
<div v-for='opt in Object.keys(options)' :class="$style.opt" @click="showMenu=false; emit('select', opt)">{{ options[opt] }}</div> | ||
</div> | ||
</div> | ||
</Transition> | ||
</div> | ||
</template> | ||
<script setup lang='ts'> | ||
import { ref } from 'vue'; | ||
const showMenu = ref<boolean>(false); | ||
const props = defineProps<{ | ||
options: string[]|Record<string, string>; | ||
}>(); | ||
const emit = defineEmits<{ | ||
(e: 'select', value: string): void; | ||
}>(); | ||
</script> | ||
|
||
<style module> | ||
.menu { | ||
position: absolute; | ||
border: solid var(--borderThickness) #555; | ||
border-radius: 4px; | ||
background: #202020; | ||
z-index: 10; | ||
} | ||
.opt { | ||
padding: 16px; | ||
border: dashed var(--borderThickness) #555; | ||
} | ||
</style> |