yumechi-no-kuni/src/client/pages/scratchpad.vue
tamaina 3963ed8ff7
feat(client): 翻訳をIndexedDBに保存・プッシュ通知を翻訳 (#6396)
* wip

* tabun ok

* better msg

* oops

* fix lint

* Update gulpfile.ts

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>

* Update src/client/scripts/set-i18n-contexts.ts

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>

* refactor

Co-authored-by: acid-chicken <root@acid-chicken.com>

* 

* wip

* fix lint

* たぶんおk

* fix flush

* Translate Notification

* remove console.log

* fix

* add notifications

* remove san

* wip

* ok

* ✌️

* Update src/prelude/array.ts

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>

* wip

* i18n refactor

* Update init.ts

* ✌️

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
Co-authored-by: syuilo <syuilotan@yahoo.co.jp>
2020-05-23 13:19:31 +09:00

137 lines
2.8 KiB
Vue

<template>
<div class="">
<portal to="icon"><fa :icon="faTerminal"/></portal>
<portal to="title">{{ $t('scratchpad') }}</portal>
<div class="_panel">
<prism-editor v-model="code" :line-numbers="false" language="js"/>
<mk-button style="position: absolute; top: 8px; right: 8px;" @click="run()" primary><fa :icon="faPlay"/></mk-button>
</div>
<mk-container :body-togglable="true">
<template #header><fa fixed-width/>{{ $t('output') }}</template>
<div class="bepmlvbi">
<div v-for="log in logs" class="log" :key="log.id" :class="{ print: log.print }">{{ log.text }}</div>
</div>
</mk-container>
<section class="_card" style="margin-top: var(--margin);">
<div class="_content">{{ $t('scratchpadDescription') }}</div>
</section>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import { faTerminal, faPlay } from '@fortawesome/free-solid-svg-icons';
import "prismjs";
import 'prismjs/themes/prism-okaidia.css';
import PrismEditor from 'vue-prism-editor';
import { AiScript, parse, utils, values } from '@syuilo/aiscript';
import MkContainer from '../components/ui/container.vue';
import MkButton from '../components/ui/button.vue';
import { createAiScriptEnv } from '../scripts/create-aiscript-env';
export default Vue.extend({
metaInfo() {
return {
title: this.$t('scratchpad') as string
};
},
components: {
MkContainer,
MkButton,
PrismEditor,
},
data() {
return {
code: '',
logs: [],
faTerminal, faPlay
}
},
watch: {
code() {
localStorage.setItem('scratchpad', this.code);
}
},
created() {
const saved = localStorage.getItem('scratchpad');
if (saved) {
this.code = saved;
}
},
methods: {
async run() {
this.logs = [];
const aiscript = new AiScript(createAiScriptEnv(this, {
storageKey: 'scratchpad'
}), {
in: (q) => {
return new Promise(ok => {
this.$root.dialog({
title: q,
input: {}
}).then(({ canceled, result: a }) => {
ok(a);
});
});
},
out: (value) => {
this.logs.push({
id: Math.random(),
text: value.type === 'str' ? value.value : utils.valToString(value),
print: true
});
},
log: (type, params) => {
switch (type) {
case 'end': this.logs.push({
id: Math.random(),
text: utils.valToString(params.val, true),
print: false
}); break;
default: break;
}
}
});
let ast;
try {
ast = parse(this.code);
} catch (e) {
this.$root.dialog({
type: 'error',
text: 'Syntax error :('
});
return;
}
try {
await aiscript.exec(ast);
} catch (e) {
this.$root.dialog({
type: 'error',
text: e
});
}
}
}
});
</script>
<style lang="scss" scoped>
.bepmlvbi {
padding: 16px;
> .log {
&:not(.print) {
opacity: 0.7;
}
}
}
</style>