diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-12 02:02:25 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-12 02:02:25 +0900 |
| commit | 0e4a111f81cceed275d9bec2695f6e401fb654d8 (patch) | |
| tree | 40874799472fa07416f17b50a398ac33b7771905 /packages/client/src/widgets/button.vue | |
| parent | update deps (diff) | |
| download | misskey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.gz misskey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.bz2 misskey-0e4a111f81cceed275d9bec2695f6e401fb654d8.zip | |
refactoring
Resolve #7779
Diffstat (limited to 'packages/client/src/widgets/button.vue')
| -rw-r--r-- | packages/client/src/widgets/button.vue | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/packages/client/src/widgets/button.vue b/packages/client/src/widgets/button.vue new file mode 100644 index 0000000000..3417181d0c --- /dev/null +++ b/packages/client/src/widgets/button.vue @@ -0,0 +1,95 @@ +<template> +<div class="mkw-button"> + <MkButton :primary="props.colored" full @click="run"> + {{ props.label }} + </MkButton> +</div> +</template> + +<script lang="ts"> +import { defineComponent } from 'vue'; +import define from './define'; +import MkButton from '@/components/ui/button.vue'; +import * as os from '@/os'; +import { AiScript, parse, utils } from '@syuilo/aiscript'; +import { createAiScriptEnv } from '@/scripts/aiscript/api'; + +const widget = define({ + name: 'button', + props: () => ({ + label: { + type: 'string', + default: 'BUTTON', + }, + colored: { + type: 'boolean', + default: true, + }, + script: { + type: 'string', + multiline: true, + default: 'Mk:dialog("hello" "world")', + }, + }) +}); + +export default defineComponent({ + components: { + MkButton + }, + extends: widget, + data() { + return { + }; + }, + methods: { + async run() { + const aiscript = new AiScript(createAiScriptEnv({ + storageKey: 'widget', + token: this.$i?.token, + }), { + in: (q) => { + return new Promise(ok => { + os.dialog({ + title: q, + input: {} + }).then(({ canceled, result: a }) => { + ok(a); + }); + }); + }, + out: (value) => { + // nop + }, + log: (type, params) => { + // nop + } + }); + + let ast; + try { + ast = parse(this.props.script); + } catch (e) { + os.dialog({ + type: 'error', + text: 'Syntax error :(' + }); + return; + } + try { + await aiscript.exec(ast); + } catch (e) { + os.dialog({ + type: 'error', + text: e + }); + } + }, + } +}); +</script> + +<style lang="scss" scoped> +.mkw-button { +} +</style> |