2019-04-29 00:11:57 +00:00
|
|
|
<template>
|
2021-11-18 14:32:43 +00:00
|
|
|
<!-- eslint-disable vue/no-mutating-props -->
|
2021-11-19 10:36:12 +00:00
|
|
|
<XContainer :removable="removable" :error="error" :warn="warn" :draggable="draggable" @remove="() => $emit('remove')">
|
|
|
|
<template #header><i v-if="icon" :class="icon"></i> <template v-if="title">{{ title }} <span v-if="typeText" class="turmquns">({{ typeText }})</span></template><template v-else-if="typeText">{{ typeText }}</template></template>
|
2019-04-29 00:11:57 +00:00
|
|
|
<template #func>
|
2021-11-19 10:36:12 +00:00
|
|
|
<button class="_button" @click="changeType()">
|
2022-12-19 10:01:30 +00:00
|
|
|
<i class="ti ti-pencil"></i>
|
2019-04-29 00:11:57 +00:00
|
|
|
</button>
|
|
|
|
</template>
|
|
|
|
|
2021-09-29 15:50:45 +00:00
|
|
|
<section v-if="modelValue.type === null" class="pbglfege" @click="changeType()">
|
2020-12-26 01:47:36 +00:00
|
|
|
{{ $ts._pages.script.emptySlot }}
|
2019-04-29 00:11:57 +00:00
|
|
|
</section>
|
2021-09-29 15:50:45 +00:00
|
|
|
<section v-else-if="modelValue.type === 'text'" class="tbwccoaw">
|
|
|
|
<input v-model="modelValue.value"/>
|
2019-04-29 00:11:57 +00:00
|
|
|
</section>
|
2021-09-29 15:50:45 +00:00
|
|
|
<section v-else-if="modelValue.type === 'multiLineText'" class="tbwccoaw">
|
|
|
|
<textarea v-model="modelValue.value"></textarea>
|
2019-04-29 00:11:57 +00:00
|
|
|
</section>
|
2021-09-29 15:50:45 +00:00
|
|
|
<section v-else-if="modelValue.type === 'textList'" class="tbwccoaw">
|
|
|
|
<textarea v-model="modelValue.value" :placeholder="$ts._pages.script.blocks._textList.info"></textarea>
|
2019-04-29 00:11:57 +00:00
|
|
|
</section>
|
2021-09-29 15:50:45 +00:00
|
|
|
<section v-else-if="modelValue.type === 'number'" class="tbwccoaw">
|
|
|
|
<input v-model="modelValue.value" type="number"/>
|
2019-04-29 00:11:57 +00:00
|
|
|
</section>
|
2021-09-29 15:50:45 +00:00
|
|
|
<section v-else-if="modelValue.type === 'ref'" class="hpdwcrvs">
|
|
|
|
<select v-model="modelValue.value">
|
2020-04-20 12:35:27 +00:00
|
|
|
<option v-for="v in hpml.getVarsByType(getExpectedType ? getExpectedType() : null).filter(x => x.name !== name)" :value="v.name">{{ v.name }}</option>
|
2020-12-26 01:47:36 +00:00
|
|
|
<optgroup :label="$ts._pages.script.argVariables">
|
2019-05-01 05:54:34 +00:00
|
|
|
<option v-for="v in fnSlots" :value="v.name">{{ v.name }}</option>
|
|
|
|
</optgroup>
|
2020-12-26 01:47:36 +00:00
|
|
|
<optgroup :label="$ts._pages.script.pageVariables">
|
2020-04-20 12:35:27 +00:00
|
|
|
<option v-for="v in hpml.getPageVarsByType(getExpectedType ? getExpectedType() : null)" :value="v">{{ v }}</option>
|
2019-04-29 00:11:57 +00:00
|
|
|
</optgroup>
|
2020-12-26 01:47:36 +00:00
|
|
|
<optgroup :label="$ts._pages.script.enviromentVariables">
|
2020-04-20 12:35:27 +00:00
|
|
|
<option v-for="v in hpml.getEnvVarsByType(getExpectedType ? getExpectedType() : null)" :value="v">{{ v }}</option>
|
2019-04-29 00:11:57 +00:00
|
|
|
</optgroup>
|
|
|
|
</select>
|
|
|
|
</section>
|
2021-09-29 15:50:45 +00:00
|
|
|
<section v-else-if="modelValue.type === 'aiScriptVar'" class="tbwccoaw">
|
|
|
|
<input v-model="modelValue.value"/>
|
2020-04-12 18:23:23 +00:00
|
|
|
</section>
|
2021-09-29 15:50:45 +00:00
|
|
|
<section v-else-if="modelValue.type === 'fn'" class="" style="padding:0 16px 16px 16px;">
|
2021-08-06 13:29:19 +00:00
|
|
|
<MkTextarea v-model="slots">
|
|
|
|
<template #label>{{ $ts._pages.script.blocks._fn.slots }}</template>
|
|
|
|
<template #caption>{{ $t('_pages.script.blocks._fn.slots-info') }}</template>
|
2020-10-17 11:12:00 +00:00
|
|
|
</MkTextarea>
|
2021-12-04 09:12:03 +00:00
|
|
|
<XV v-if="modelValue.value.expression" v-model="modelValue.value.expression" :title="$t(`_pages.script.blocks._fn.arg1`)" :get-expected-type="() => null" :hpml="hpml" :fn-slots="modelValue.value.slots" :name="name"/>
|
2019-04-29 00:11:57 +00:00
|
|
|
</section>
|
2021-09-29 15:50:45 +00:00
|
|
|
<section v-else-if="modelValue.type.startsWith('fn:')" class="" style="padding:16px;">
|
2021-12-04 09:12:03 +00:00
|
|
|
<XV v-for="(x, i) in modelValue.args" :key="i" v-model="modelValue.args[i]" :title="hpml.getVarByName(modelValue.type.split(':')[1]).value.slots[i].name" :get-expected-type="() => null" :hpml="hpml" :name="name"/>
|
2019-04-29 00:11:57 +00:00
|
|
|
</section>
|
|
|
|
<section v-else class="" style="padding:16px;">
|
2021-11-19 10:36:12 +00:00
|
|
|
<XV v-for="(x, i) in modelValue.args" :key="i" v-model="modelValue.args[i]" :title="$t(`_pages.script.blocks._${modelValue.type}.arg${i + 1}`)" :get-expected-type="() => _getExpectedType(i)" :hpml="hpml" :name="name" :fn-slots="fnSlots"/>
|
2019-04-29 00:11:57 +00:00
|
|
|
</section>
|
2020-10-17 11:12:00 +00:00
|
|
|
</XContainer>
|
2019-04-29 00:11:57 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-11-18 14:32:43 +00:00
|
|
|
/* eslint-disable vue/no-mutating-props */
|
2020-10-18 03:30:54 +00:00
|
|
|
import { defineAsyncComponent, defineComponent } from 'vue';
|
2019-08-18 03:42:58 +00:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2020-01-29 19:37:25 +00:00
|
|
|
import XContainer from './page-editor.container.vue';
|
2021-11-11 17:02:25 +00:00
|
|
|
import MkTextarea from '@/components/form/textarea.vue';
|
|
|
|
import { blockDefs } from '@/scripts/hpml/index';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import { isLiteralValue } from '@/scripts/hpml/expr';
|
|
|
|
import { funcDefs } from '@/scripts/hpml/lib';
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
export default defineComponent({
|
2019-04-29 00:11:57 +00:00
|
|
|
components: {
|
2020-10-18 03:30:54 +00:00
|
|
|
XContainer, MkTextarea,
|
|
|
|
XV: defineAsyncComponent(() => import('./page-editor.script-block.vue')),
|
2019-04-29 00:11:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
inject: ['getScriptBlockList'],
|
|
|
|
|
|
|
|
props: {
|
|
|
|
getExpectedType: {
|
|
|
|
required: false,
|
2022-12-22 07:01:59 +00:00
|
|
|
default: null,
|
2019-04-29 00:11:57 +00:00
|
|
|
},
|
2021-09-29 15:50:45 +00:00
|
|
|
modelValue: {
|
2022-12-22 07:01:59 +00:00
|
|
|
required: true,
|
2019-04-29 00:11:57 +00:00
|
|
|
},
|
|
|
|
title: {
|
2022-12-22 07:01:59 +00:00
|
|
|
required: false,
|
2019-04-29 00:11:57 +00:00
|
|
|
},
|
|
|
|
removable: {
|
|
|
|
required: false,
|
2022-12-22 07:01:59 +00:00
|
|
|
default: false,
|
2019-04-29 00:11:57 +00:00
|
|
|
},
|
2020-04-20 12:35:27 +00:00
|
|
|
hpml: {
|
2019-04-29 00:11:57 +00:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
fnSlots: {
|
|
|
|
required: false,
|
|
|
|
},
|
2019-05-10 07:04:32 +00:00
|
|
|
draggable: {
|
|
|
|
required: false,
|
2022-12-22 07:01:59 +00:00
|
|
|
default: false,
|
|
|
|
},
|
2019-04-29 00:11:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
error: null,
|
|
|
|
warn: null,
|
|
|
|
slots: '',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
icon(): any {
|
2021-09-29 15:50:45 +00:00
|
|
|
if (this.modelValue.type === null) return null;
|
2022-12-19 10:01:30 +00:00
|
|
|
if (this.modelValue.type.startsWith('fn:')) return 'ti ti-plug';
|
2021-09-29 15:50:45 +00:00
|
|
|
return blockDefs.find(x => x.type === this.modelValue.type).icon;
|
2019-04-29 00:11:57 +00:00
|
|
|
},
|
|
|
|
typeText(): any {
|
2021-09-29 15:50:45 +00:00
|
|
|
if (this.modelValue.type === null) return null;
|
|
|
|
if (this.modelValue.type.startsWith('fn:')) return this.modelValue.type.split(':')[1];
|
|
|
|
return this.$t(`_pages.script.blocks.${this.modelValue.type}`);
|
2019-04-29 00:11:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
2020-10-17 11:12:00 +00:00
|
|
|
slots: {
|
|
|
|
handler() {
|
2021-09-29 15:50:45 +00:00
|
|
|
this.modelValue.value.slots = this.slots.split('\n').map(x => ({
|
2020-10-17 11:12:00 +00:00
|
|
|
name: x,
|
2022-12-22 07:01:59 +00:00
|
|
|
type: null,
|
2020-10-17 11:12:00 +00:00
|
|
|
}));
|
|
|
|
},
|
2022-12-22 07:01:59 +00:00
|
|
|
deep: true,
|
|
|
|
},
|
2019-04-29 00:11:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
2021-09-29 15:50:45 +00:00
|
|
|
if (this.modelValue.value == null) this.modelValue.value = null;
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2021-09-29 15:50:45 +00:00
|
|
|
if (this.modelValue.value && this.modelValue.value.slots) this.slots = this.modelValue.value.slots.map(x => x.name).join('\n');
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2021-09-29 15:50:45 +00:00
|
|
|
this.$watch(() => this.modelValue.type, (t) => {
|
2019-04-29 00:11:57 +00:00
|
|
|
this.warn = null;
|
|
|
|
|
2021-09-29 15:50:45 +00:00
|
|
|
if (this.modelValue.type === 'fn') {
|
2019-08-18 03:42:58 +00:00
|
|
|
const id = uuid();
|
2021-09-29 15:50:45 +00:00
|
|
|
this.modelValue.value = {
|
2020-10-17 11:12:00 +00:00
|
|
|
slots: [],
|
2022-12-22 07:01:59 +00:00
|
|
|
expression: { id, type: null },
|
2020-10-17 11:12:00 +00:00
|
|
|
};
|
2019-04-29 00:11:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-29 15:50:45 +00:00
|
|
|
if (this.modelValue.type && this.modelValue.type.startsWith('fn:')) {
|
|
|
|
const fnName = this.modelValue.type.split(':')[1];
|
2020-04-20 12:35:27 +00:00
|
|
|
const fn = this.hpml.getVarByName(fnName);
|
2019-04-29 00:11:57 +00:00
|
|
|
|
|
|
|
const empties = [];
|
|
|
|
for (let i = 0; i < fn.value.slots.length; i++) {
|
2019-08-18 03:42:58 +00:00
|
|
|
const id = uuid();
|
2019-04-29 00:11:57 +00:00
|
|
|
empties.push({ id, type: null });
|
|
|
|
}
|
2021-09-29 15:50:45 +00:00
|
|
|
this.modelValue.args = empties;
|
2019-04-29 00:11:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-29 15:50:45 +00:00
|
|
|
if (isLiteralValue(this.modelValue)) return;
|
2019-04-29 00:11:57 +00:00
|
|
|
|
|
|
|
const empties = [];
|
2021-09-29 15:50:45 +00:00
|
|
|
for (let i = 0; i < funcDefs[this.modelValue.type].in.length; i++) {
|
2019-08-18 03:42:58 +00:00
|
|
|
const id = uuid();
|
2019-04-29 00:11:57 +00:00
|
|
|
empties.push({ id, type: null });
|
|
|
|
}
|
2021-09-29 15:50:45 +00:00
|
|
|
this.modelValue.args = empties;
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2021-09-29 15:50:45 +00:00
|
|
|
for (let i = 0; i < funcDefs[this.modelValue.type].in.length; i++) {
|
|
|
|
const inType = funcDefs[this.modelValue.type].in[i];
|
2019-04-29 00:11:57 +00:00
|
|
|
if (typeof inType !== 'number') {
|
2021-09-29 15:50:45 +00:00
|
|
|
if (inType === 'number') this.modelValue.args[i].type = 'number';
|
|
|
|
if (inType === 'string') this.modelValue.args[i].type = 'text';
|
2019-04-29 00:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-29 15:50:45 +00:00
|
|
|
this.$watch(() => this.modelValue.args, (args) => {
|
2019-04-29 00:11:57 +00:00
|
|
|
if (args == null) {
|
|
|
|
this.warn = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const emptySlotIndex = args.findIndex(x => x.type === null);
|
|
|
|
if (emptySlotIndex !== -1 && emptySlotIndex < args.length) {
|
|
|
|
this.warn = {
|
2022-12-22 07:01:59 +00:00
|
|
|
slot: emptySlotIndex,
|
2019-04-29 00:11:57 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.warn = null;
|
|
|
|
}
|
|
|
|
}, {
|
2022-12-22 07:01:59 +00:00
|
|
|
deep: true,
|
2019-04-29 00:11:57 +00:00
|
|
|
});
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
this.$watch(() => this.hpml.variables, () => {
|
2021-09-29 15:50:45 +00:00
|
|
|
if (this.type != null && this.modelValue) {
|
|
|
|
this.error = this.hpml.typeCheck(this.modelValue);
|
2019-04-29 00:11:57 +00:00
|
|
|
}
|
|
|
|
}, {
|
2022-12-22 07:01:59 +00:00
|
|
|
deep: true,
|
2019-04-29 00:11:57 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
async changeType() {
|
2021-11-18 09:45:58 +00:00
|
|
|
const { canceled, result: type } = await os.select({
|
2020-12-26 01:47:36 +00:00
|
|
|
title: this.$ts._pages.selectType,
|
2022-12-22 07:01:59 +00:00
|
|
|
groupedItems: this.getScriptBlockList(this.getExpectedType ? this.getExpectedType() : null),
|
2019-04-29 00:11:57 +00:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
2021-09-29 15:50:45 +00:00
|
|
|
this.modelValue.type = type;
|
2019-04-29 00:11:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_getExpectedType(slot: number) {
|
2021-09-29 15:50:45 +00:00
|
|
|
return this.hpml.getExpectedType(this.modelValue, slot);
|
2022-12-22 07:01:59 +00:00
|
|
|
},
|
|
|
|
},
|
2019-04-29 00:11:57 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.turmquns {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
.pbglfege {
|
|
|
|
opacity: 0.5;
|
|
|
|
padding: 16px;
|
|
|
|
text-align: center;
|
|
|
|
cursor: pointer;
|
|
|
|
color: var(--fg);
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
.tbwccoaw {
|
|
|
|
> input,
|
|
|
|
> textarea {
|
|
|
|
display: block;
|
|
|
|
-webkit-appearance: none;
|
|
|
|
-moz-appearance: none;
|
|
|
|
appearance: none;
|
|
|
|
width: 100%;
|
|
|
|
max-width: 100%;
|
|
|
|
min-width: 100%;
|
|
|
|
border: none;
|
|
|
|
box-shadow: none;
|
|
|
|
padding: 16px;
|
|
|
|
font-size: 16px;
|
|
|
|
background: transparent;
|
|
|
|
color: var(--fg);
|
2020-04-12 18:23:23 +00:00
|
|
|
box-sizing: border-box;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
> textarea {
|
|
|
|
min-height: 100px;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
.hpdwcrvs {
|
|
|
|
padding: 16px;
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
> select {
|
|
|
|
display: block;
|
|
|
|
padding: 4px;
|
|
|
|
font-size: 16px;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
</style>
|