diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2020-04-16 00:39:21 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2020-04-16 00:39:21 +0900 |
| commit | 90e8527556f5040f5e98769130dadca94fc1324e (patch) | |
| tree | cc6e3504d37fc9de9f7a9dead75bd0a3a25809ee /src/client/components | |
| parent | Update CHANGELOG.md (diff) | |
| download | misskey-90e8527556f5040f5e98769130dadca94fc1324e.tar.gz misskey-90e8527556f5040f5e98769130dadca94fc1324e.tar.bz2 misskey-90e8527556f5040f5e98769130dadca94fc1324e.zip | |
Resolve #6256
Diffstat (limited to 'src/client/components')
| -rw-r--r-- | src/client/components/page/page.block.vue | 3 | ||||
| -rw-r--r-- | src/client/components/page/page.canvas.vue | 29 | ||||
| -rw-r--r-- | src/client/components/page/page.vue | 75 |
3 files changed, 69 insertions, 38 deletions
diff --git a/src/client/components/page/page.block.vue b/src/client/components/page/page.block.vue index c1d046fa2e..04bbb0b858 100644 --- a/src/client/components/page/page.block.vue +++ b/src/client/components/page/page.block.vue @@ -17,10 +17,11 @@ import XTextarea from './page.textarea.vue'; import XPost from './page.post.vue'; import XCounter from './page.counter.vue'; import XRadioButton from './page.radio-button.vue'; +import XCanvas from './page.canvas.vue'; export default Vue.extend({ components: { - XText, XSection, XImage, XButton, XNumberInput, XTextInput, XTextareaInput, XTextarea, XPost, XSwitch, XIf, XCounter, XRadioButton + XText, XSection, XImage, XButton, XNumberInput, XTextInput, XTextareaInput, XTextarea, XPost, XSwitch, XIf, XCounter, XRadioButton, XCanvas }, props: { value: { diff --git a/src/client/components/page/page.canvas.vue b/src/client/components/page/page.canvas.vue new file mode 100644 index 0000000000..edcb9cba39 --- /dev/null +++ b/src/client/components/page/page.canvas.vue @@ -0,0 +1,29 @@ +<template> +<div> + <canvas ref="canvas" class="ysrxegms" :width="value.width" :height="value.height"/> +</div> +</template> + +<script lang="ts"> +import Vue from 'vue'; + +export default Vue.extend({ + props: { + value: { + required: true + }, + script: { + required: true + } + }, + mounted() { + this.script.aoiScript.registerCanvas(this.value.name, this.$refs.canvas); + } +}); +</script> + +<style lang="scss" scoped> +.ysrxegms { + display: block; +} +</style> diff --git a/src/client/components/page/page.vue b/src/client/components/page/page.vue index 3723fcd3ce..99cc6e67e5 100644 --- a/src/client/components/page/page.vue +++ b/src/client/components/page/page.vue @@ -21,39 +21,11 @@ class Script { public vars: Record<string, any>; public page: Record<string, any>; - constructor(page, aoiScript, onError, cb) { + constructor(page, aoiScript, onError) { this.page = page; this.aoiScript = aoiScript; this.onError = onError; - - if (this.page.script && this.aoiScript.aiscript) { - let ast; - try { - ast = parse(this.page.script); - } catch (e) { - console.error(e); - /*this.$root.dialog({ - type: 'error', - text: 'Syntax error :(' - });*/ - return; - } - this.aoiScript.aiscript.exec(ast).then(() => { - this.eval(); - cb(); - }).catch(e => { - console.error(e); - /*this.$root.dialog({ - type: 'error', - text: e - });*/ - }); - } else { - setTimeout(() => { - this.eval(); - cb(); - }, 1); - } + this.eval(); } public eval() { @@ -67,13 +39,15 @@ class Script { public interpolate(str: string) { if (str == null) return null; return str.replace(/{(.+?)}/g, match => { - const v = this.vars[match.slice(1, -1).trim()]; + const v = this.vars ? this.vars[match.slice(1, -1).trim()] : null; return v == null ? 'NULL' : v.toString(); }); } public callAiScript(fn: string) { - if (this.aoiScript.aiscript) this.aoiScript.aiscript.execFn(this.aoiScript.aiscript.scope.get(fn), []); + try { + if (this.aoiScript.aiscript) this.aoiScript.aiscript.execFn(this.aoiScript.aiscript.scope.get(fn), []); + } catch (e) {} } } @@ -101,7 +75,7 @@ export default Vue.extend({ created() { const pageVars = this.getPageVars(); - const s = new Script(this.page, new ASEvaluator(this, this.page.variables, pageVars, { + this.script = new Script(this.page, new ASEvaluator(this, this.page.variables, pageVars, { randomSeed: Math.random(), visitor: this.$store.state.i, page: this.page, @@ -109,15 +83,42 @@ export default Vue.extend({ enableAiScript: !this.$store.state.device.disablePagesScript }), e => { console.dir(e); - }, () => { - this.script = s; }); - if (s.aoiScript.aiscript) s.aoiScript.aiscript.scope.opts.onUpdated = (name, value) => { - s.eval(); + if (this.script.aoiScript.aiscript) this.script.aoiScript.aiscript.scope.opts.onUpdated = (name, value) => { + this.script.eval(); }; }, + mounted() { + this.$nextTick(() => { + if (this.script.page.script && this.script.aoiScript.aiscript) { + let ast; + try { + ast = parse(this.script.page.script); + } catch (e) { + console.error(e); + /*this.$root.dialog({ + type: 'error', + text: 'Syntax error :(' + });*/ + return; + } + this.script.aoiScript.aiscript.exec(ast).then(() => { + this.script.eval(); + }).catch(e => { + console.error(e); + /*this.$root.dialog({ + type: 'error', + text: e + });*/ + }); + } else { + this.script.eval(); + } + }); + }, + beforeDestroy() { if (this.script.aoiScript.aiscript) this.script.aoiScript.aiscript.abort(); }, |