Resolve #5755
This commit is contained in:
parent
36b9a0d42f
commit
11cc9cbc7c
28 changed files with 195 additions and 63 deletions
|
@ -10,6 +10,7 @@
|
|||
<option value="dialog">{{ $t('_pages.blocks._button._action.dialog') }}</option>
|
||||
<option value="resetRandom">{{ $t('_pages.blocks._button._action.resetRandom') }}</option>
|
||||
<option value="pushEvent">{{ $t('_pages.blocks._button._action.pushEvent') }}</option>
|
||||
<option value="callAiScript">{{ $t('_pages.blocks._button._action.callAiScript') }}</option>
|
||||
</mk-select>
|
||||
<template v-if="value.action === 'dialog'">
|
||||
<mk-input v-model="value.content"><span>{{ $t('_pages.blocks._button._action._dialog.content') }}</span></mk-input>
|
||||
|
@ -20,15 +21,18 @@
|
|||
<mk-select v-model="value.var">
|
||||
<template #label>{{ $t('_pages.blocks._button._action._pushEvent.variable') }}</template>
|
||||
<option :value="null">{{ $t('_pages.blocks._button._action._pushEvent.no-variable') }}</option>
|
||||
<option v-for="v in aiScript.getVarsByType()" :value="v.name">{{ v.name }}</option>
|
||||
<option v-for="v in aoiScript.getVarsByType()" :value="v.name">{{ v.name }}</option>
|
||||
<optgroup :label="$t('_pages.script.pageVariables')">
|
||||
<option v-for="v in aiScript.getPageVarsByType()" :value="v">{{ v }}</option>
|
||||
<option v-for="v in aoiScript.getPageVarsByType()" :value="v">{{ v }}</option>
|
||||
</optgroup>
|
||||
<optgroup :label="$t('_pages.script.enviromentVariables')">
|
||||
<option v-for="v in aiScript.getEnvVarsByType()" :value="v">{{ v }}</option>
|
||||
<option v-for="v in aoiScript.getEnvVarsByType()" :value="v">{{ v }}</option>
|
||||
</optgroup>
|
||||
</mk-select>
|
||||
</template>
|
||||
<template v-else-if="value.action === 'callAiScript'">
|
||||
<mk-input v-model="value.fn"><span>{{ $t('_pages.blocks._button._action._callAiScript.functionName') }}</span></mk-input>
|
||||
</template>
|
||||
</section>
|
||||
</x-container>
|
||||
</template>
|
||||
|
@ -53,7 +57,7 @@ export default Vue.extend({
|
|||
value: {
|
||||
required: true
|
||||
},
|
||||
aiScript: {
|
||||
aoiScript: {
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
@ -72,6 +76,7 @@ export default Vue.extend({
|
|||
if (this.value.message == null) Vue.set(this.value, 'message', null);
|
||||
if (this.value.primary == null) Vue.set(this.value, 'primary', false);
|
||||
if (this.value.var == null) Vue.set(this.value, 'var', null);
|
||||
if (this.value.fn == null) Vue.set(this.value, 'fn', null);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -10,16 +10,16 @@
|
|||
<section class="romcojzs">
|
||||
<mk-select v-model="value.var">
|
||||
<template #label>{{ $t('_pages.blocks._if.variable') }}</template>
|
||||
<option v-for="v in aiScript.getVarsByType('boolean')" :value="v.name">{{ v.name }}</option>
|
||||
<option v-for="v in aoiScript.getVarsByType('boolean')" :value="v.name">{{ v.name }}</option>
|
||||
<optgroup :label="$t('_pages.script.pageVariables')">
|
||||
<option v-for="v in aiScript.getPageVarsByType('boolean')" :value="v">{{ v }}</option>
|
||||
<option v-for="v in aoiScript.getPageVarsByType('boolean')" :value="v">{{ v }}</option>
|
||||
</optgroup>
|
||||
<optgroup :label="$t('_pages.script.enviromentVariables')">
|
||||
<option v-for="v in aiScript.getEnvVarsByType('boolean')" :value="v">{{ v }}</option>
|
||||
<option v-for="v in aoiScript.getEnvVarsByType('boolean')" :value="v">{{ v }}</option>
|
||||
</optgroup>
|
||||
</mk-select>
|
||||
|
||||
<x-blocks class="children" v-model="value.children" :ai-script="aiScript"/>
|
||||
<x-blocks class="children" v-model="value.children" :aoi-script="aoiScript"/>
|
||||
</section>
|
||||
</x-container>
|
||||
</template>
|
||||
|
@ -45,7 +45,7 @@ export default Vue.extend({
|
|||
value: {
|
||||
required: true
|
||||
},
|
||||
aiScript: {
|
||||
aoiScript: {
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
</template>
|
||||
|
||||
<section class="ilrvjyvi">
|
||||
<x-blocks class="children" v-model="value.children" :ai-script="aiScript"/>
|
||||
<x-blocks class="children" v-model="value.children" :aoi-script="aoiScript"/>
|
||||
</section>
|
||||
</x-container>
|
||||
</template>
|
||||
|
@ -37,7 +37,7 @@ export default Vue.extend({
|
|||
value: {
|
||||
required: true
|
||||
},
|
||||
aiScript: {
|
||||
aoiScript: {
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<x-container @remove="() => $emit('remove')" :draggable="true">
|
||||
<template #header><fa :icon="faAlignLeft"/> {{ $t('_pages.blocks.text') }}</template>
|
||||
|
||||
<section class="ihymsbbe">
|
||||
<section class="vckmsadr">
|
||||
<textarea v-model="value.text"></textarea>
|
||||
</section>
|
||||
</x-container>
|
||||
|
@ -40,7 +40,7 @@ export default Vue.extend({
|
|||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.ihymsbbe {
|
||||
.vckmsadr {
|
||||
> textarea {
|
||||
display: block;
|
||||
-webkit-appearance: none;
|
||||
|
@ -55,6 +55,7 @@ export default Vue.extend({
|
|||
background: transparent;
|
||||
color: var(--fg);
|
||||
font-size: 14px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -55,6 +55,7 @@ export default Vue.extend({
|
|||
background: transparent;
|
||||
color: var(--fg);
|
||||
font-size: 14px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<x-draggable tag="div" :list="blocks" handle=".drag-handle" :group="{ name: 'blocks' }" animation="150" swap-threshold="0.5">
|
||||
<component v-for="block in blocks" :is="'x-' + block.type" :value="block" @input="updateItem" @remove="() => removeItem(block)" :key="block.id" :ai-script="aiScript"/>
|
||||
<component v-for="block in blocks" :is="'x-' + block.type" :value="block" @input="updateItem" @remove="() => removeItem(block)" :key="block.id" :aoi-script="aoiScript"/>
|
||||
</x-draggable>
|
||||
</template>
|
||||
|
||||
|
@ -31,7 +31,7 @@ export default Vue.extend({
|
|||
type: Array,
|
||||
required: true
|
||||
},
|
||||
aiScript: {
|
||||
aoiScript: {
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<x-container :removable="removable" @remove="() => $emit('remove')" :error="error" :warn="warn" :draggable="draggable">
|
||||
<template #header><fa v-if="icon" :icon="icon"/> <template v-if="title">{{ title }} <span class="turmquns" v-if="typeText">({{ typeText }})</span></template><template v-else-if="typeText">{{ typeText }}</template></template>
|
||||
<template #func>
|
||||
<button @click="changeType()">
|
||||
<button @click="changeType()" class="_button">
|
||||
<fa :icon="faPencilAlt"/>
|
||||
</button>
|
||||
</template>
|
||||
|
@ -24,30 +24,33 @@
|
|||
</section>
|
||||
<section v-else-if="value.type === 'ref'" class="hpdwcrvs">
|
||||
<select v-model="value.value">
|
||||
<option v-for="v in aiScript.getVarsByType(getExpectedType ? getExpectedType() : null).filter(x => x.name !== name)" :value="v.name">{{ v.name }}</option>
|
||||
<option v-for="v in aoiScript.getVarsByType(getExpectedType ? getExpectedType() : null).filter(x => x.name !== name)" :value="v.name">{{ v.name }}</option>
|
||||
<optgroup :label="$t('_pages.script.argVariables')">
|
||||
<option v-for="v in fnSlots" :value="v.name">{{ v.name }}</option>
|
||||
</optgroup>
|
||||
<optgroup :label="$t('_pages.script.pageVariables')">
|
||||
<option v-for="v in aiScript.getPageVarsByType(getExpectedType ? getExpectedType() : null)" :value="v">{{ v }}</option>
|
||||
<option v-for="v in aoiScript.getPageVarsByType(getExpectedType ? getExpectedType() : null)" :value="v">{{ v }}</option>
|
||||
</optgroup>
|
||||
<optgroup :label="$t('_pages.script.enviromentVariables')">
|
||||
<option v-for="v in aiScript.getEnvVarsByType(getExpectedType ? getExpectedType() : null)" :value="v">{{ v }}</option>
|
||||
<option v-for="v in aoiScript.getEnvVarsByType(getExpectedType ? getExpectedType() : null)" :value="v">{{ v }}</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
</section>
|
||||
<section v-else-if="value.type === 'aiScriptVar'" class="tbwccoaw">
|
||||
<input v-model="value.value"/>
|
||||
</section>
|
||||
<section v-else-if="value.type === 'fn'" class="" style="padding:0 16px 16px 16px;">
|
||||
<mk-textarea v-model="slots">
|
||||
<span>{{ $t('_pages.script.blocks._fn.slots') }}</span>
|
||||
<template #desc>{{ $t('_pages.script.blocks._fn.slots-info') }}</template>
|
||||
</mk-textarea>
|
||||
<x-v v-if="value.value.expression" v-model="value.value.expression" :title="$t(`_pages.script.blocks._fn.arg1`)" :get-expected-type="() => null" :ai-script="aiScript" :fn-slots="value.value.slots" :name="name"/>
|
||||
<x-v v-if="value.value.expression" v-model="value.value.expression" :title="$t(`_pages.script.blocks._fn.arg1`)" :get-expected-type="() => null" :aoi-script="aoiScript" :fn-slots="value.value.slots" :name="name"/>
|
||||
</section>
|
||||
<section v-else-if="value.type.startsWith('fn:')" class="" style="padding:16px;">
|
||||
<x-v v-for="(x, i) in value.args" v-model="value.args[i]" :title="aiScript.getVarByName(value.type.split(':')[1]).value.slots[i].name" :get-expected-type="() => null" :ai-script="aiScript" :name="name" :key="i"/>
|
||||
<x-v v-for="(x, i) in value.args" v-model="value.args[i]" :title="aoiScript.getVarByName(value.type.split(':')[1]).value.slots[i].name" :get-expected-type="() => null" :aoi-script="aoiScript" :name="name" :key="i"/>
|
||||
</section>
|
||||
<section v-else class="" style="padding:16px;">
|
||||
<x-v v-for="(x, i) in value.args" v-model="value.args[i]" :title="$t(`_pages.script.blocks._${value.type}.arg${i + 1}`)" :get-expected-type="() => _getExpectedType(i)" :ai-script="aiScript" :name="name" :fn-slots="fnSlots" :key="i"/>
|
||||
<x-v v-for="(x, i) in value.args" v-model="value.args[i]" :title="$t(`_pages.script.blocks._${value.type}.arg${i + 1}`)" :get-expected-type="() => _getExpectedType(i)" :aoi-script="aoiScript" :name="name" :fn-slots="fnSlots" :key="i"/>
|
||||
</section>
|
||||
</x-container>
|
||||
</template>
|
||||
|
@ -85,7 +88,7 @@ export default Vue.extend({
|
|||
required: false,
|
||||
default: false
|
||||
},
|
||||
aiScript: {
|
||||
aoiScript: {
|
||||
required: true,
|
||||
},
|
||||
name: {
|
||||
|
@ -153,7 +156,7 @@ export default Vue.extend({
|
|||
|
||||
if (this.value.type && this.value.type.startsWith('fn:')) {
|
||||
const fnName = this.value.type.split(':')[1];
|
||||
const fn = this.aiScript.getVarByName(fnName);
|
||||
const fn = this.aoiScript.getVarByName(fnName);
|
||||
|
||||
const empties = [];
|
||||
for (let i = 0; i < fn.value.slots.length; i++) {
|
||||
|
@ -199,9 +202,9 @@ export default Vue.extend({
|
|||
deep: true
|
||||
});
|
||||
|
||||
this.$watch('aiScript.variables', () => {
|
||||
this.$watch('aoiScript.variables', () => {
|
||||
if (this.type != null && this.value) {
|
||||
this.error = this.aiScript.typeCheck(this.value);
|
||||
this.error = this.aoiScript.typeCheck(this.value);
|
||||
}
|
||||
}, {
|
||||
deep: true
|
||||
|
@ -223,7 +226,7 @@ export default Vue.extend({
|
|||
},
|
||||
|
||||
_getExpectedType(slot: number) {
|
||||
return this.aiScript.getExpectedType(this.value, slot);
|
||||
return this.aoiScript.getExpectedType(this.value, slot);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -258,6 +261,7 @@ export default Vue.extend({
|
|||
font-size: 16px;
|
||||
background: transparent;
|
||||
color: var(--fg);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
> textarea {
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
</div>
|
||||
</template>
|
||||
|
||||
<x-blocks class="content" v-model="content" :ai-script="aiScript"/>
|
||||
<x-blocks class="content" v-model="content" :aoi-script="aoiScript"/>
|
||||
|
||||
<mk-button @click="add()" v-if="!readonly"><fa :icon="faPlus"/></mk-button>
|
||||
</section>
|
||||
|
@ -62,7 +62,7 @@
|
|||
@input="v => updateVariable(v)"
|
||||
@remove="() => removeVariable(variable)"
|
||||
:key="variable.name"
|
||||
:ai-script="aiScript"
|
||||
:aoi-script="aoiScript"
|
||||
:name="variable.name"
|
||||
:title="variable.name"
|
||||
:draggable="true"
|
||||
|
@ -73,11 +73,10 @@
|
|||
</div>
|
||||
</mk-container>
|
||||
|
||||
<mk-container :body-togglable="true" :expanded="false">
|
||||
<template #header><fa :icon="faCode"/> {{ $t('_pages.inspector') }}</template>
|
||||
<div style="padding:0 32px 32px 32px;">
|
||||
<mk-textarea :value="JSON.stringify(content, null, 2)" readonly tall>{{ $t('_pages.content') }}</mk-textarea>
|
||||
<mk-textarea :value="JSON.stringify(variables, null, 2)" readonly tall>{{ $t('_pages.variables') }}</mk-textarea>
|
||||
<mk-container :body-togglable="true" :expanded="true">
|
||||
<template #header><fa :icon="faCode"/> {{ $t('script') }}</template>
|
||||
<div>
|
||||
<prism-editor v-model="script" :line-numbers="false" language="js"/>
|
||||
</div>
|
||||
</mk-container>
|
||||
</div>
|
||||
|
@ -86,6 +85,9 @@
|
|||
<script lang="ts">
|
||||
import Vue from 'vue';
|
||||
import * as XDraggable from 'vuedraggable';
|
||||
import "prismjs";
|
||||
import "prismjs/themes/prism.css";
|
||||
import PrismEditor from 'vue-prism-editor';
|
||||
import { faICursor, faPlus, faMagic, faCog, faCode, faExternalLinkSquareAlt } from '@fortawesome/free-solid-svg-icons';
|
||||
import { faSave, faStickyNote, faTrashAlt } from '@fortawesome/free-regular-svg-icons';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
|
@ -108,7 +110,7 @@ export default Vue.extend({
|
|||
i18n,
|
||||
|
||||
components: {
|
||||
XDraggable, XVariable, XBlocks, MkTextarea, MkContainer, MkButton, MkSelect, MkSwitch, MkInput
|
||||
XDraggable, XVariable, XBlocks, MkTextarea, MkContainer, MkButton, MkSelect, MkSwitch, MkInput, PrismEditor
|
||||
},
|
||||
|
||||
props: {
|
||||
|
@ -143,7 +145,8 @@ export default Vue.extend({
|
|||
alignCenter: false,
|
||||
hideTitleWhenPinned: false,
|
||||
variables: [],
|
||||
aiScript: null,
|
||||
aoiScript: null,
|
||||
script: '',
|
||||
showOptions: false,
|
||||
url,
|
||||
faPlus, faICursor, faSave, faStickyNote, faMagic, faCog, faTrashAlt, faExternalLinkSquareAlt, faCode
|
||||
|
@ -163,14 +166,14 @@ export default Vue.extend({
|
|||
},
|
||||
|
||||
async created() {
|
||||
this.aiScript = new ASTypeChecker();
|
||||
this.aoiScript = new ASTypeChecker();
|
||||
|
||||
this.$watch('variables', () => {
|
||||
this.aiScript.variables = this.variables;
|
||||
this.aoiScript.variables = this.variables;
|
||||
}, { deep: true });
|
||||
|
||||
this.$watch('content', () => {
|
||||
this.aiScript.pageVars = collectPageVars(this.content);
|
||||
this.aoiScript.pageVars = collectPageVars(this.content);
|
||||
}, { deep: true });
|
||||
|
||||
if (this.initPageId) {
|
||||
|
@ -193,6 +196,7 @@ export default Vue.extend({
|
|||
this.currentName = this.page.name;
|
||||
this.summary = this.page.summary;
|
||||
this.font = this.page.font;
|
||||
this.script = this.page.script;
|
||||
this.hideTitleWhenPinned = this.page.hideTitleWhenPinned;
|
||||
this.alignCenter = this.page.alignCenter;
|
||||
this.content = this.page.content;
|
||||
|
@ -223,6 +227,7 @@ export default Vue.extend({
|
|||
name: this.name.trim(),
|
||||
summary: this.summary,
|
||||
font: this.font,
|
||||
script: this.script,
|
||||
hideTitleWhenPinned: this.hideTitleWhenPinned,
|
||||
alignCenter: this.alignCenter,
|
||||
content: this.content,
|
||||
|
@ -317,7 +322,7 @@ export default Vue.extend({
|
|||
|
||||
name = name.trim();
|
||||
|
||||
if (this.aiScript.isUsedName(name)) {
|
||||
if (this.aoiScript.isUsedName(name)) {
|
||||
this.$root.dialog({
|
||||
type: 'error',
|
||||
text: this.$t('_pages.variableNameIsAlreadyUsed')
|
||||
|
@ -382,7 +387,7 @@ export default Vue.extend({
|
|||
} else {
|
||||
list.push({
|
||||
category: block.category,
|
||||
label: this.$t(`script.categories.${block.category}`),
|
||||
label: this.$t(`_pages.script.categories.${block.category}`),
|
||||
items: [{
|
||||
value: block.type,
|
||||
text: this.$t(`_pages.script.blocks.${block.type}`)
|
||||
|
@ -394,7 +399,7 @@ export default Vue.extend({
|
|||
const userFns = this.variables.filter(x => x.type === 'fn');
|
||||
if (userFns.length > 0) {
|
||||
list.unshift({
|
||||
label: this.$t(`script.categories.fn`),
|
||||
label: this.$t(`_pages.script.categories.fn`),
|
||||
items: userFns.map(v => ({
|
||||
value: 'fn:' + v.name,
|
||||
text: v.name
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
|
||||
<script lang="ts">
|
||||
import Vue from 'vue';
|
||||
import { faTerminal, faPlay } from '@fortawesome/free-solid-svg-icons';
|
||||
import "prismjs";
|
||||
import "prismjs/themes/prism.css";
|
||||
import { faTerminal, faPlay } from '@fortawesome/free-solid-svg-icons';
|
||||
import PrismEditor from 'vue-prism-editor';
|
||||
import { AiScript, parse, utils, values } from '@syuilo/aiscript';
|
||||
import i18n from '../i18n';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue