mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-27 21:10:20 +01:00
Add button widget
This commit is contained in:
parent
b002651194
commit
ea6aa40b09
3 changed files with 97 additions and 0 deletions
|
@ -1011,6 +1011,7 @@ _widgets:
|
|||
federation: "連合"
|
||||
postForm: "投稿フォーム"
|
||||
slideshow: "スライドショー"
|
||||
button: "ボタン"
|
||||
|
||||
_cw:
|
||||
hide: "隠す"
|
||||
|
|
94
src/client/widgets/button.vue
Normal file
94
src/client/widgets/button.vue
Normal file
|
@ -0,0 +1,94 @@
|
|||
<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: 'scratchpad'
|
||||
}), {
|
||||
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>
|
|
@ -14,6 +14,7 @@ export default function(app: App) {
|
|||
app.component('MkwFederation', defineAsyncComponent(() => import('./federation.vue')));
|
||||
app.component('MkwPostForm', defineAsyncComponent(() => import('./post-form.vue')));
|
||||
app.component('MkwSlideshow', defineAsyncComponent(() => import('./slideshow.vue')));
|
||||
app.component('MkwButton', defineAsyncComponent(() => import('./button.vue')));
|
||||
}
|
||||
|
||||
export const widgets = [
|
||||
|
@ -30,4 +31,5 @@ export const widgets = [
|
|||
'federation',
|
||||
'postForm',
|
||||
'slideshow',
|
||||
'button',
|
||||
];
|
||||
|
|
Loading…
Reference in a new issue