2019-04-29 03:11:57 +03:00
|
|
|
<template>
|
2020-10-17 14:12:00 +03:00
|
|
|
<XContainer :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>
|
2019-04-29 03:11:57 +03:00
|
|
|
<template #func>
|
2020-04-12 21:23:23 +03:00
|
|
|
<button @click="changeType()" class="_button">
|
2020-10-17 14:12:00 +03:00
|
|
|
<Fa :icon="faPencilAlt"/>
|
2019-04-29 03:11:57 +03:00
|
|
|
</button>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<section v-if="value.type === null" class="pbglfege" @click="changeType()">
|
2020-01-29 21:37:25 +02:00
|
|
|
{{ $t('_pages.script.emptySlot') }}
|
2019-04-29 03:11:57 +03:00
|
|
|
</section>
|
|
|
|
<section v-else-if="value.type === 'text'" class="tbwccoaw">
|
|
|
|
<input v-model="value.value"/>
|
|
|
|
</section>
|
|
|
|
<section v-else-if="value.type === 'multiLineText'" class="tbwccoaw">
|
|
|
|
<textarea v-model="value.value"></textarea>
|
|
|
|
</section>
|
2019-04-29 08:51:04 +03:00
|
|
|
<section v-else-if="value.type === 'textList'" class="tbwccoaw">
|
2020-01-29 21:37:25 +02:00
|
|
|
<textarea v-model="value.value" :placeholder="$t('_pages.script.blocks._textList.info')"></textarea>
|
2019-04-29 03:11:57 +03:00
|
|
|
</section>
|
|
|
|
<section v-else-if="value.type === 'number'" class="tbwccoaw">
|
|
|
|
<input v-model="value.value" type="number"/>
|
|
|
|
</section>
|
|
|
|
<section v-else-if="value.type === 'ref'" class="hpdwcrvs">
|
|
|
|
<select v-model="value.value">
|
2020-04-20 15:35:27 +03:00
|
|
|
<option v-for="v in hpml.getVarsByType(getExpectedType ? getExpectedType() : null).filter(x => x.name !== name)" :value="v.name">{{ v.name }}</option>
|
2020-01-29 21:37:25 +02:00
|
|
|
<optgroup :label="$t('_pages.script.argVariables')">
|
2019-05-01 08:54:34 +03:00
|
|
|
<option v-for="v in fnSlots" :value="v.name">{{ v.name }}</option>
|
|
|
|
</optgroup>
|
2020-01-29 21:37:25 +02:00
|
|
|
<optgroup :label="$t('_pages.script.pageVariables')">
|
2020-04-20 15:35:27 +03:00
|
|
|
<option v-for="v in hpml.getPageVarsByType(getExpectedType ? getExpectedType() : null)" :value="v">{{ v }}</option>
|
2019-04-29 03:11:57 +03:00
|
|
|
</optgroup>
|
2020-01-29 21:37:25 +02:00
|
|
|
<optgroup :label="$t('_pages.script.enviromentVariables')">
|
2020-04-20 15:35:27 +03:00
|
|
|
<option v-for="v in hpml.getEnvVarsByType(getExpectedType ? getExpectedType() : null)" :value="v">{{ v }}</option>
|
2019-04-29 03:11:57 +03:00
|
|
|
</optgroup>
|
|
|
|
</select>
|
|
|
|
</section>
|
2020-04-12 21:23:23 +03:00
|
|
|
<section v-else-if="value.type === 'aiScriptVar'" class="tbwccoaw">
|
|
|
|
<input v-model="value.value"/>
|
|
|
|
</section>
|
2019-05-01 04:05:33 +03:00
|
|
|
<section v-else-if="value.type === 'fn'" class="" style="padding:0 16px 16px 16px;">
|
2020-10-17 14:12:00 +03:00
|
|
|
<MkTextarea v-model:value="slots">
|
2020-07-24 19:56:52 +03:00
|
|
|
<span>{{ $t('_pages.script.blocks._fn.slots') }}</span>
|
2020-01-29 21:37:25 +02:00
|
|
|
<template #desc>{{ $t('_pages.script.blocks._fn.slots-info') }}</template>
|
2020-10-17 14:12:00 +03:00
|
|
|
</MkTextarea>
|
|
|
|
<XV v-if="value.value.expression" v-model:value="value.value.expression" :title="$t(`_pages.script.blocks._fn.arg1`)" :get-expected-type="() => null" :hpml="hpml" :fn-slots="value.value.slots" :name="name"/>
|
2019-04-29 03:11:57 +03:00
|
|
|
</section>
|
|
|
|
<section v-else-if="value.type.startsWith('fn:')" class="" style="padding:16px;">
|
2020-10-17 14:12:00 +03:00
|
|
|
<XV v-for="(x, i) in value.args" v-model:value="value.args[i]" :title="hpml.getVarByName(value.type.split(':')[1]).value.slots[i].name" :get-expected-type="() => null" :hpml="hpml" :name="name" :key="i"/>
|
2019-04-29 03:11:57 +03:00
|
|
|
</section>
|
|
|
|
<section v-else class="" style="padding:16px;">
|
2020-10-17 14:12:00 +03:00
|
|
|
<XV v-for="(x, i) in value.args" v-model:value="value.args[i]" :title="$t(`_pages.script.blocks._${value.type}.arg${i + 1}`)" :get-expected-type="() => _getExpectedType(i)" :hpml="hpml" :name="name" :fn-slots="fnSlots" :key="i"/>
|
2019-04-29 03:11:57 +03:00
|
|
|
</section>
|
2020-10-17 14:12:00 +03:00
|
|
|
</XContainer>
|
2019-04-29 03:11:57 +03:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 14:12:00 +03:00
|
|
|
import { defineComponent } from 'vue';
|
2019-05-01 13:50:56 +03:00
|
|
|
import { faPencilAlt, faPlug } from '@fortawesome/free-solid-svg-icons';
|
2019-08-18 06:42:58 +03:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2020-01-29 21:37:25 +02:00
|
|
|
import XContainer from './page-editor.container.vue';
|
2020-10-17 14:12:00 +03:00
|
|
|
import MkTextarea from '@/components/ui/textarea.vue';
|
|
|
|
import { isLiteralBlock, funcDefs, blockDefs } from '@/scripts/hpml/index';
|
|
|
|
import * as os from '@/os';
|
2019-04-29 03:11:57 +03:00
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
export default defineComponent({
|
2019-04-29 03:11:57 +03:00
|
|
|
components: {
|
2020-01-29 21:37:25 +02:00
|
|
|
XContainer, MkTextarea
|
2019-04-29 03:11:57 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
inject: ['getScriptBlockList'],
|
|
|
|
|
|
|
|
props: {
|
|
|
|
getExpectedType: {
|
|
|
|
required: false,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
value: {
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
removable: {
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
},
|
2020-04-20 15:35:27 +03:00
|
|
|
hpml: {
|
2019-04-29 03:11:57 +03:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
fnSlots: {
|
|
|
|
required: false,
|
|
|
|
},
|
2019-05-10 10:04:32 +03:00
|
|
|
draggable: {
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
}
|
2019-04-29 03:11:57 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
error: null,
|
|
|
|
warn: null,
|
|
|
|
slots: '',
|
2019-05-01 13:45:05 +03:00
|
|
|
faPencilAlt
|
2019-04-29 03:11:57 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
icon(): any {
|
|
|
|
if (this.value.type === null) return null;
|
2019-05-01 13:50:56 +03:00
|
|
|
if (this.value.type.startsWith('fn:')) return faPlug;
|
2019-05-01 12:33:11 +03:00
|
|
|
return blockDefs.find(x => x.type === this.value.type).icon;
|
2019-04-29 03:11:57 +03:00
|
|
|
},
|
|
|
|
typeText(): any {
|
|
|
|
if (this.value.type === null) return null;
|
2019-05-01 08:54:34 +03:00
|
|
|
if (this.value.type.startsWith('fn:')) return this.value.type.split(':')[1];
|
2020-01-29 21:37:25 +02:00
|
|
|
return this.$t(`_pages.script.blocks.${this.value.type}`);
|
2019-04-29 03:11:57 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
2020-10-17 14:12:00 +03:00
|
|
|
slots: {
|
|
|
|
handler() {
|
|
|
|
this.value.value.slots = this.slots.split('\n').map(x => ({
|
|
|
|
name: x,
|
|
|
|
type: null
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
deep: true
|
2019-04-29 03:11:57 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeCreate() {
|
|
|
|
this.$options.components.XV = require('./page-editor.script-block.vue').default;
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
2020-10-17 14:12:00 +03:00
|
|
|
if (this.value.value == null) this.value.value = null;
|
2019-04-29 03:11:57 +03:00
|
|
|
|
2019-05-01 04:05:33 +03:00
|
|
|
if (this.value.value && this.value.value.slots) this.slots = this.value.value.slots.map(x => x.name).join('\n');
|
2019-04-29 03:11:57 +03:00
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
this.$watch(() => this.value.type, (t) => {
|
2019-04-29 03:11:57 +03:00
|
|
|
this.warn = null;
|
|
|
|
|
|
|
|
if (this.value.type === 'fn') {
|
2019-08-18 06:42:58 +03:00
|
|
|
const id = uuid();
|
2020-10-17 14:12:00 +03:00
|
|
|
this.value.value = {
|
|
|
|
slots: [],
|
|
|
|
expression: { id, type: null }
|
|
|
|
};
|
2019-04-29 03:11:57 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.value.type && this.value.type.startsWith('fn:')) {
|
|
|
|
const fnName = this.value.type.split(':')[1];
|
2020-04-20 15:35:27 +03:00
|
|
|
const fn = this.hpml.getVarByName(fnName);
|
2019-04-29 03:11:57 +03:00
|
|
|
|
|
|
|
const empties = [];
|
|
|
|
for (let i = 0; i < fn.value.slots.length; i++) {
|
2019-08-18 06:42:58 +03:00
|
|
|
const id = uuid();
|
2019-04-29 03:11:57 +03:00
|
|
|
empties.push({ id, type: null });
|
|
|
|
}
|
2020-10-17 14:12:00 +03:00
|
|
|
this.value.args = empties;
|
2019-04-29 03:11:57 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-01 12:33:11 +03:00
|
|
|
if (isLiteralBlock(this.value)) return;
|
2019-04-29 03:11:57 +03:00
|
|
|
|
|
|
|
const empties = [];
|
2019-05-01 12:33:11 +03:00
|
|
|
for (let i = 0; i < funcDefs[this.value.type].in.length; i++) {
|
2019-08-18 06:42:58 +03:00
|
|
|
const id = uuid();
|
2019-04-29 03:11:57 +03:00
|
|
|
empties.push({ id, type: null });
|
|
|
|
}
|
2020-10-17 14:12:00 +03:00
|
|
|
this.value.args = empties;
|
2019-04-29 03:11:57 +03:00
|
|
|
|
2019-05-01 12:33:11 +03:00
|
|
|
for (let i = 0; i < funcDefs[this.value.type].in.length; i++) {
|
|
|
|
const inType = funcDefs[this.value.type].in[i];
|
2019-04-29 03:11:57 +03:00
|
|
|
if (typeof inType !== 'number') {
|
|
|
|
if (inType === 'number') this.value.args[i].type = 'number';
|
|
|
|
if (inType === 'string') this.value.args[i].type = 'text';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
this.$watch(() => this.value.args, (args) => {
|
2019-04-29 03:11:57 +03:00
|
|
|
if (args == null) {
|
|
|
|
this.warn = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const emptySlotIndex = args.findIndex(x => x.type === null);
|
|
|
|
if (emptySlotIndex !== -1 && emptySlotIndex < args.length) {
|
|
|
|
this.warn = {
|
|
|
|
slot: emptySlotIndex
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.warn = null;
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
deep: true
|
|
|
|
});
|
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
this.$watch(() => this.hpml.variables, () => {
|
2019-04-29 03:11:57 +03:00
|
|
|
if (this.type != null && this.value) {
|
2020-04-20 15:35:27 +03:00
|
|
|
this.error = this.hpml.typeCheck(this.value);
|
2019-04-29 03:11:57 +03:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
deep: true
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
async changeType() {
|
2020-10-17 14:12:00 +03:00
|
|
|
const { canceled, result: type } = await os.dialog({
|
2019-04-29 03:11:57 +03:00
|
|
|
type: null,
|
2020-03-22 03:51:40 +02:00
|
|
|
title: this.$t('_pages.selectType'),
|
2019-04-29 03:11:57 +03:00
|
|
|
select: {
|
|
|
|
groupedItems: this.getScriptBlockList(this.getExpectedType ? this.getExpectedType() : null)
|
|
|
|
},
|
|
|
|
showCancelButton: true
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
this.value.type = type;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getExpectedType(slot: number) {
|
2020-04-20 15:35:27 +03:00
|
|
|
return this.hpml.getExpectedType(this.value, slot);
|
2019-04-29 03:11:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.turmquns {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
2019-04-29 03:11:57 +03:00
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
.pbglfege {
|
|
|
|
opacity: 0.5;
|
|
|
|
padding: 16px;
|
|
|
|
text-align: center;
|
|
|
|
cursor: pointer;
|
|
|
|
color: var(--fg);
|
|
|
|
}
|
2019-04-29 03:11:57 +03:00
|
|
|
|
2020-01-29 21:37:25 +02: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 21:23:23 +03:00
|
|
|
box-sizing: border-box;
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
2019-04-29 03:11:57 +03:00
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
> textarea {
|
|
|
|
min-height: 100px;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 03:11:57 +03:00
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
.hpdwcrvs {
|
|
|
|
padding: 16px;
|
2019-04-29 03:11:57 +03:00
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
> select {
|
|
|
|
display: block;
|
|
|
|
padding: 4px;
|
|
|
|
font-size: 16px;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 03:11:57 +03:00
|
|
|
</style>
|