2019-04-28 19:11:57 -05:00
|
|
|
<template>
|
2021-04-09 22:40:50 -05:00
|
|
|
<div class="_root">
|
|
|
|
<MkA class="view" v-if="pageId" :to="`/@${ author.username }/pages/${ currentName }`"><Fa :icon="faExternalLinkSquareAlt"/> {{ $ts._pages.viewPage }}</MkA>
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2021-04-09 22:40:50 -05:00
|
|
|
<div class="buttons" style="margin: 16px;">
|
|
|
|
<MkButton inline @click="save" primary class="save" v-if="!readonly"><Fa :icon="faSave"/> {{ $ts.save }}</MkButton>
|
|
|
|
<MkButton inline @click="duplicate" class="duplicate" v-if="pageId"><Fa :icon="faCopy"/> {{ $ts.duplicate }}</MkButton>
|
|
|
|
<MkButton inline @click="del" class="delete" v-if="pageId && !readonly"><Fa :icon="faTrashAlt"/> {{ $ts.delete }}</MkButton>
|
|
|
|
</div>
|
2019-04-29 00:46:35 -05:00
|
|
|
|
2021-04-09 22:40:50 -05:00
|
|
|
<MkContainer :body-togglable="true" :expanded="true" class="_vMargin">
|
|
|
|
<template #header><Fa :icon="faCog"/> {{ $ts._pages.pageSetting }}</template>
|
|
|
|
<div style="padding: 16px;">
|
|
|
|
<MkInput v-model:value="title">
|
|
|
|
<span>{{ $ts._pages.title }}</span>
|
|
|
|
</MkInput>
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2021-04-09 22:40:50 -05:00
|
|
|
<MkInput v-model:value="summary">
|
|
|
|
<span>{{ $ts._pages.summary }}</span>
|
|
|
|
</MkInput>
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2021-04-09 22:40:50 -05:00
|
|
|
<MkInput v-model:value="name">
|
|
|
|
<template #prefix>{{ url }}/@{{ author.username }}/pages/</template>
|
|
|
|
<span>{{ $ts._pages.url }}</span>
|
|
|
|
</MkInput>
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2021-04-09 22:40:50 -05:00
|
|
|
<MkSwitch v-model:value="alignCenter">{{ $ts._pages.alignCenter }}</MkSwitch>
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2021-04-09 22:40:50 -05:00
|
|
|
<MkSelect v-model:value="font">
|
|
|
|
<template #label>{{ $ts._pages.font }}</template>
|
|
|
|
<option value="serif">{{ $ts._pages.fontSerif }}</option>
|
|
|
|
<option value="sans-serif">{{ $ts._pages.fontSansSerif }}</option>
|
|
|
|
</MkSelect>
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2021-04-09 22:40:50 -05:00
|
|
|
<MkSwitch v-model:value="hideTitleWhenPinned">{{ $ts._pages.hideTitleWhenPinned }}</MkSwitch>
|
2019-07-06 16:56:13 -05:00
|
|
|
|
2021-04-09 22:40:50 -05:00
|
|
|
<div class="eyeCatch">
|
|
|
|
<MkButton v-if="eyeCatchingImageId == null && !readonly" @click="setEyeCatchingImage"><Fa :icon="faPlus"/> {{ $ts._pages.eyeCatchingImageSet }}</MkButton>
|
|
|
|
<div v-else-if="eyeCatchingImage">
|
|
|
|
<img :src="eyeCatchingImage.url" :alt="eyeCatchingImage.name" style="max-width: 100%;"/>
|
|
|
|
<MkButton @click="removeEyeCatchingImage()" v-if="!readonly"><Fa :icon="faTrashAlt"/> {{ $ts._pages.eyeCatchingImageRemove }}</MkButton>
|
2020-11-14 22:42:04 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-09 22:40:50 -05:00
|
|
|
</div>
|
|
|
|
</MkContainer>
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2021-04-09 22:40:50 -05:00
|
|
|
<MkContainer :body-togglable="true" :expanded="true" class="_vMargin">
|
|
|
|
<template #header><Fa :icon="faStickyNote"/> {{ $ts._pages.contents }}</template>
|
|
|
|
<div style="padding: 16px;">
|
|
|
|
<XBlocks class="content" v-model:value="content" :hpml="hpml"/>
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2021-04-09 22:40:50 -05:00
|
|
|
<MkButton @click="add()" v-if="!readonly"><Fa :icon="faPlus"/></MkButton>
|
|
|
|
</div>
|
|
|
|
</MkContainer>
|
2019-05-01 06:48:56 -05:00
|
|
|
|
2021-04-09 22:40:50 -05:00
|
|
|
<MkContainer :body-togglable="true" class="_vMargin">
|
|
|
|
<template #header><Fa :icon="faMagic"/> {{ $ts._pages.variables }}</template>
|
|
|
|
<div class="qmuvgica">
|
|
|
|
<XDraggable tag="div" class="variables" v-show="variables.length > 0" v-model="variables" item-key="name" handle=".drag-handle" :group="{ name: 'variables' }" animation="150" swap-threshold="0.5">
|
|
|
|
<template #item="{element}">
|
|
|
|
<XVariable
|
|
|
|
:value="element"
|
|
|
|
:removable="true"
|
|
|
|
@remove="() => removeVariable(element)"
|
|
|
|
:hpml="hpml"
|
|
|
|
:name="element.name"
|
|
|
|
:title="element.name"
|
|
|
|
:draggable="true"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</XDraggable>
|
2020-10-17 06:12:00 -05:00
|
|
|
|
2021-04-09 22:40:50 -05:00
|
|
|
<MkButton @click="addVariable()" class="add" v-if="!readonly"><Fa :icon="faPlus"/></MkButton>
|
|
|
|
</div>
|
|
|
|
</MkContainer>
|
2020-10-17 06:12:00 -05:00
|
|
|
|
2021-04-09 22:40:50 -05:00
|
|
|
<MkContainer :body-togglable="true" :expanded="true" class="_vMargin">
|
|
|
|
<template #header><Fa :icon="faCode"/> {{ $ts.script }}</template>
|
|
|
|
<div>
|
|
|
|
<MkTextarea class="_code" v-model:value="script"/>
|
|
|
|
</div>
|
|
|
|
</MkContainer>
|
2019-04-28 19:11:57 -05:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-11-14 22:42:04 -06:00
|
|
|
import { defineComponent, defineAsyncComponent, computed } from 'vue';
|
2020-08-21 18:03:11 -05:00
|
|
|
import 'prismjs';
|
|
|
|
import { highlight, languages } from 'prismjs/components/prism-core';
|
|
|
|
import 'prismjs/components/prism-clike';
|
|
|
|
import 'prismjs/components/prism-javascript';
|
2020-04-17 06:36:51 -05:00
|
|
|
import 'prismjs/themes/prism-okaidia.css';
|
2020-08-21 18:03:11 -05:00
|
|
|
import 'vue-prism-editor/dist/prismeditor.min.css';
|
2020-12-19 06:41:00 -06:00
|
|
|
import { faICursor, faPlus, faMagic, faCog, faCode, faExternalLinkSquareAlt, faPencilAlt, faCopy } from '@fortawesome/free-solid-svg-icons';
|
2019-04-28 19:11:57 -05:00
|
|
|
import { faSave, faStickyNote, faTrashAlt } from '@fortawesome/free-regular-svg-icons';
|
2020-01-29 13:37:25 -06:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2019-04-28 19:11:57 -05:00
|
|
|
import XVariable from './page-editor.script-block.vue';
|
2019-05-02 03:55:59 -05:00
|
|
|
import XBlocks from './page-editor.blocks.vue';
|
2021-03-23 03:30:14 -05:00
|
|
|
import MkTextarea from '@client/components/ui/textarea.vue';
|
|
|
|
import MkContainer from '@client/components/ui/container.vue';
|
|
|
|
import MkButton from '@client/components/ui/button.vue';
|
|
|
|
import MkSelect from '@client/components/ui/select.vue';
|
|
|
|
import MkSwitch from '@client/components/ui/switch.vue';
|
|
|
|
import MkInput from '@client/components/ui/input.vue';
|
|
|
|
import { blockDefs } from '@client/scripts/hpml/index';
|
|
|
|
import { HpmlTypeChecker } from '@client/scripts/hpml/type-checker';
|
|
|
|
import { url } from '@client/config';
|
|
|
|
import { collectPageVars } from '@client/scripts/collect-page-vars';
|
|
|
|
import * as os from '@client/os';
|
|
|
|
import { selectFile } from '@client/scripts/select-file';
|
2020-10-17 06:12:00 -05:00
|
|
|
|
|
|
|
export default defineComponent({
|
2019-04-28 19:11:57 -05:00
|
|
|
components: {
|
2020-12-04 21:50:09 -06:00
|
|
|
XDraggable: defineAsyncComponent(() => import('vuedraggable').then(x => x.default)),
|
2020-10-17 06:12:00 -05:00
|
|
|
XVariable, XBlocks, MkTextarea, MkContainer, MkButton, MkSelect, MkSwitch, MkInput,
|
2019-04-28 19:11:57 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
2019-05-24 05:19:43 -05:00
|
|
|
initPageId: {
|
|
|
|
type: String,
|
2019-04-28 19:11:57 -05:00
|
|
|
required: false
|
2019-04-29 16:40:02 -05:00
|
|
|
},
|
2019-05-24 05:19:43 -05:00
|
|
|
initPageName: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
initUser: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
2019-04-29 16:40:02 -05:00
|
|
|
},
|
2019-04-28 19:11:57 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-03-12 19:56:27 -06:00
|
|
|
INFO: computed(() => {
|
|
|
|
let title = this.$ts._pages.newPage;
|
|
|
|
if (this.initPageId) {
|
|
|
|
title = this.$ts._pages.editPage;
|
|
|
|
}
|
|
|
|
else if (this.initPageName && this.initUser) {
|
|
|
|
title = this.$ts._pages.readPage;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
title: title,
|
|
|
|
icon: faPencilAlt,
|
|
|
|
};
|
2020-11-14 22:42:04 -06:00
|
|
|
}),
|
2020-12-18 19:55:52 -06:00
|
|
|
author: this.$i,
|
2019-05-24 05:19:43 -05:00
|
|
|
readonly: false,
|
|
|
|
page: null,
|
2019-04-28 19:11:57 -05:00
|
|
|
pageId: null,
|
2019-04-29 00:46:35 -05:00
|
|
|
currentName: null,
|
2019-04-28 19:11:57 -05:00
|
|
|
title: '',
|
|
|
|
summary: null,
|
|
|
|
name: Date.now().toString(),
|
|
|
|
eyeCatchingImage: null,
|
|
|
|
eyeCatchingImageId: null,
|
|
|
|
font: 'sans-serif',
|
|
|
|
content: [],
|
|
|
|
alignCenter: false,
|
2019-07-06 16:56:13 -05:00
|
|
|
hideTitleWhenPinned: false,
|
2019-04-28 19:11:57 -05:00
|
|
|
variables: [],
|
2020-04-20 07:35:27 -05:00
|
|
|
hpml: null,
|
2020-04-12 13:23:23 -05:00
|
|
|
script: '',
|
2019-04-28 19:11:57 -05:00
|
|
|
url,
|
2020-12-19 06:41:00 -06:00
|
|
|
faPlus, faICursor, faSave, faStickyNote, faMagic, faCog, faTrashAlt, faExternalLinkSquareAlt, faCode, faCopy
|
2019-04-28 19:11:57 -05:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
async eyeCatchingImageId() {
|
|
|
|
if (this.eyeCatchingImageId == null) {
|
|
|
|
this.eyeCatchingImage = null;
|
|
|
|
} else {
|
2020-10-17 06:12:00 -05:00
|
|
|
this.eyeCatchingImage = await os.api('drive/files/show', {
|
2019-04-28 19:11:57 -05:00
|
|
|
fileId: this.eyeCatchingImageId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-05-24 05:19:43 -05:00
|
|
|
async created() {
|
2020-04-20 07:35:27 -05:00
|
|
|
this.hpml = new HpmlTypeChecker();
|
2019-04-28 19:11:57 -05:00
|
|
|
|
|
|
|
this.$watch('variables', () => {
|
2020-04-20 07:35:27 -05:00
|
|
|
this.hpml.variables = this.variables;
|
2019-04-28 19:11:57 -05:00
|
|
|
}, { deep: true });
|
|
|
|
|
|
|
|
this.$watch('content', () => {
|
2020-04-20 07:35:27 -05:00
|
|
|
this.hpml.pageVars = collectPageVars(this.content);
|
2019-04-28 19:11:57 -05:00
|
|
|
}, { deep: true });
|
|
|
|
|
2019-05-24 05:19:43 -05:00
|
|
|
if (this.initPageId) {
|
2020-10-17 06:12:00 -05:00
|
|
|
this.page = await os.api('pages/show', {
|
2019-05-24 05:19:43 -05:00
|
|
|
pageId: this.initPageId,
|
|
|
|
});
|
|
|
|
} else if (this.initPageName && this.initUser) {
|
2020-10-17 06:12:00 -05:00
|
|
|
this.page = await os.api('pages/show', {
|
2019-05-24 05:19:43 -05:00
|
|
|
name: this.initPageName,
|
|
|
|
username: this.initUser,
|
|
|
|
});
|
|
|
|
this.readonly = true;
|
|
|
|
}
|
|
|
|
|
2019-04-28 19:11:57 -05:00
|
|
|
if (this.page) {
|
2019-05-01 06:48:56 -05:00
|
|
|
this.author = this.page.user;
|
|
|
|
this.pageId = this.page.id;
|
|
|
|
this.title = this.page.title;
|
|
|
|
this.name = this.page.name;
|
|
|
|
this.currentName = this.page.name;
|
|
|
|
this.summary = this.page.summary;
|
|
|
|
this.font = this.page.font;
|
2020-04-12 13:23:23 -05:00
|
|
|
this.script = this.page.script;
|
2019-07-06 16:56:13 -05:00
|
|
|
this.hideTitleWhenPinned = this.page.hideTitleWhenPinned;
|
2019-05-01 06:48:56 -05:00
|
|
|
this.alignCenter = this.page.alignCenter;
|
|
|
|
this.content = this.page.content;
|
|
|
|
this.variables = this.page.variables;
|
|
|
|
this.eyeCatchingImageId = this.page.eyeCatchingImageId;
|
2019-04-28 19:11:57 -05:00
|
|
|
} else {
|
2019-08-17 22:42:58 -05:00
|
|
|
const id = uuid();
|
2019-04-28 19:11:57 -05:00
|
|
|
this.content = [{
|
|
|
|
id,
|
|
|
|
type: 'text',
|
|
|
|
text: 'Hello World!'
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
provide() {
|
|
|
|
return {
|
2019-04-29 16:40:02 -05:00
|
|
|
readonly: this.readonly,
|
|
|
|
getScriptBlockList: this.getScriptBlockList,
|
|
|
|
getPageBlockList: this.getPageBlockList
|
2019-04-28 19:11:57 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-12-19 06:41:00 -06:00
|
|
|
getSaveOptions() {
|
|
|
|
return {
|
2019-08-27 18:00:05 -05:00
|
|
|
title: this.title.trim(),
|
|
|
|
name: this.name.trim(),
|
|
|
|
summary: this.summary,
|
|
|
|
font: this.font,
|
2020-04-12 13:23:23 -05:00
|
|
|
script: this.script,
|
2019-08-27 18:00:05 -05:00
|
|
|
hideTitleWhenPinned: this.hideTitleWhenPinned,
|
|
|
|
alignCenter: this.alignCenter,
|
|
|
|
content: this.content,
|
|
|
|
variables: this.variables,
|
|
|
|
eyeCatchingImageId: this.eyeCatchingImageId,
|
|
|
|
};
|
2020-12-19 06:41:00 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
save() {
|
|
|
|
const options = this.getSaveOptions();
|
2019-08-27 18:00:05 -05:00
|
|
|
|
2019-09-01 16:21:43 -05:00
|
|
|
const onError = err => {
|
2019-09-01 16:02:35 -05:00
|
|
|
if (err.id == '3d81ceae-475f-4600-b2a8-2bc116157532') {
|
2019-09-01 16:04:12 -05:00
|
|
|
if (err.info.param == 'name') {
|
2020-10-17 06:12:00 -05:00
|
|
|
os.dialog({
|
2019-09-01 16:02:35 -05:00
|
|
|
type: 'error',
|
2020-12-25 19:47:36 -06:00
|
|
|
title: this.$ts._pages.invalidNameTitle,
|
|
|
|
text: this.$ts._pages.invalidNameText
|
2019-09-01 16:02:35 -05:00
|
|
|
});
|
|
|
|
}
|
2019-09-01 16:04:12 -05:00
|
|
|
} else if (err.code == 'NAME_ALREADY_EXISTS') {
|
2020-10-17 06:12:00 -05:00
|
|
|
os.dialog({
|
2019-09-01 16:04:12 -05:00
|
|
|
type: 'error',
|
2020-12-25 19:47:36 -06:00
|
|
|
text: this.$ts._pages.nameAlreadyExists
|
2019-09-01 16:04:12 -05:00
|
|
|
});
|
|
|
|
}
|
2019-09-01 16:21:43 -05:00
|
|
|
};
|
2019-09-01 16:02:35 -05:00
|
|
|
|
2019-04-28 19:11:57 -05:00
|
|
|
if (this.pageId) {
|
2019-08-27 18:00:05 -05:00
|
|
|
options.pageId = this.pageId;
|
2020-10-17 06:12:00 -05:00
|
|
|
os.api('pages/update', options)
|
2019-08-27 18:00:05 -05:00
|
|
|
.then(page => {
|
2019-04-29 00:46:35 -05:00
|
|
|
this.currentName = this.name.trim();
|
2020-10-17 06:12:00 -05:00
|
|
|
os.dialog({
|
2019-04-28 19:11:57 -05:00
|
|
|
type: 'success',
|
2020-12-25 19:47:36 -06:00
|
|
|
text: this.$ts._pages.updated
|
2019-04-28 19:11:57 -05:00
|
|
|
});
|
2019-09-01 16:04:12 -05:00
|
|
|
}).catch(onError);
|
2019-04-28 19:11:57 -05:00
|
|
|
} else {
|
2020-10-17 06:12:00 -05:00
|
|
|
os.api('pages/create', options)
|
2019-08-27 18:00:05 -05:00
|
|
|
.then(page => {
|
2019-04-28 19:11:57 -05:00
|
|
|
this.pageId = page.id;
|
2019-04-29 00:46:35 -05:00
|
|
|
this.currentName = this.name.trim();
|
2020-10-17 06:12:00 -05:00
|
|
|
os.dialog({
|
2019-04-28 19:11:57 -05:00
|
|
|
type: 'success',
|
2020-12-25 19:47:36 -06:00
|
|
|
text: this.$ts._pages.created
|
2019-04-28 19:11:57 -05:00
|
|
|
});
|
2020-11-16 23:59:15 -06:00
|
|
|
this.$router.push(`/pages/edit/${this.pageId}`);
|
2019-09-01 16:04:12 -05:00
|
|
|
}).catch(onError);
|
2019-04-28 19:11:57 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
del() {
|
2020-10-17 06:12:00 -05:00
|
|
|
os.dialog({
|
2019-04-28 19:11:57 -05:00
|
|
|
type: 'warning',
|
2020-03-21 20:51:40 -05:00
|
|
|
text: this.$t('removeAreYouSure', { x: this.title.trim() }),
|
2019-04-28 19:11:57 -05:00
|
|
|
showCancelButton: true
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
2020-10-17 06:12:00 -05:00
|
|
|
os.api('pages/delete', {
|
2019-04-28 19:11:57 -05:00
|
|
|
pageId: this.pageId,
|
|
|
|
}).then(() => {
|
2020-10-17 06:12:00 -05:00
|
|
|
os.dialog({
|
2019-04-28 19:11:57 -05:00
|
|
|
type: 'success',
|
2020-12-25 19:47:36 -06:00
|
|
|
text: this.$ts._pages.deleted
|
2019-04-28 19:11:57 -05:00
|
|
|
});
|
2020-11-16 23:59:15 -06:00
|
|
|
this.$router.push(`/pages`);
|
2019-04-28 19:11:57 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-12-19 06:41:00 -06:00
|
|
|
duplicate() {
|
|
|
|
this.title = this.title + ' - copy';
|
|
|
|
this.name = this.name + '-copy';
|
|
|
|
os.api('pages/create', this.getSaveOptions()).then(page => {
|
|
|
|
this.pageId = page.id;
|
|
|
|
this.currentName = this.name.trim();
|
|
|
|
os.dialog({
|
|
|
|
type: 'success',
|
2020-12-25 19:47:36 -06:00
|
|
|
text: this.$ts._pages.created
|
2020-12-19 06:41:00 -06:00
|
|
|
});
|
|
|
|
this.$router.push(`/pages/edit/${this.pageId}`);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-04-28 19:11:57 -05:00
|
|
|
async add() {
|
2020-10-17 06:12:00 -05:00
|
|
|
const { canceled, result: type } = await os.dialog({
|
2019-04-28 19:11:57 -05:00
|
|
|
type: null,
|
2020-12-25 19:47:36 -06:00
|
|
|
title: this.$ts._pages.chooseBlock,
|
2019-04-28 19:11:57 -05:00
|
|
|
select: {
|
2019-04-29 22:15:41 -05:00
|
|
|
groupedItems: this.getPageBlockList()
|
2019-04-28 19:11:57 -05:00
|
|
|
},
|
|
|
|
showCancelButton: true
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2019-08-17 22:42:58 -05:00
|
|
|
const id = uuid();
|
2019-04-28 19:11:57 -05:00
|
|
|
this.content.push({ id, type });
|
|
|
|
},
|
|
|
|
|
|
|
|
async addVariable() {
|
2020-10-17 06:12:00 -05:00
|
|
|
let { canceled, result: name } = await os.dialog({
|
2020-12-25 19:47:36 -06:00
|
|
|
title: this.$ts._pages.enterVariableName,
|
2019-04-28 19:11:57 -05:00
|
|
|
input: {
|
|
|
|
type: 'text',
|
|
|
|
},
|
|
|
|
showCancelButton: true
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
name = name.trim();
|
|
|
|
|
2020-04-20 07:35:27 -05:00
|
|
|
if (this.hpml.isUsedName(name)) {
|
2020-10-17 06:12:00 -05:00
|
|
|
os.dialog({
|
2019-04-28 19:11:57 -05:00
|
|
|
type: 'error',
|
2020-12-25 19:47:36 -06:00
|
|
|
text: this.$ts._pages.variableNameIsAlreadyUsed
|
2019-04-28 19:11:57 -05:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-17 22:42:58 -05:00
|
|
|
const id = uuid();
|
2019-04-28 19:11:57 -05:00
|
|
|
this.variables.push({ id, name, type: null });
|
|
|
|
},
|
|
|
|
|
|
|
|
removeVariable(v) {
|
2020-12-07 09:32:00 -06:00
|
|
|
this.variables = this.variables.filter(x => x.name !== v.name);
|
2019-04-28 19:11:57 -05:00
|
|
|
},
|
|
|
|
|
2019-04-29 16:40:02 -05:00
|
|
|
getPageBlockList() {
|
|
|
|
return [{
|
2020-12-25 19:47:36 -06:00
|
|
|
label: this.$ts._pages.contentBlocks,
|
2019-04-29 22:15:41 -05:00
|
|
|
items: [
|
2020-12-25 19:47:36 -06:00
|
|
|
{ value: 'section', text: this.$ts._pages.blocks.section },
|
|
|
|
{ value: 'text', text: this.$ts._pages.blocks.text },
|
|
|
|
{ value: 'image', text: this.$ts._pages.blocks.image },
|
|
|
|
{ value: 'textarea', text: this.$ts._pages.blocks.textarea },
|
|
|
|
{ value: 'note', text: this.$ts._pages.blocks.note },
|
|
|
|
{ value: 'canvas', text: this.$ts._pages.blocks.canvas },
|
2019-04-29 22:15:41 -05:00
|
|
|
]
|
2019-04-29 16:40:02 -05:00
|
|
|
}, {
|
2020-12-25 19:47:36 -06:00
|
|
|
label: this.$ts._pages.inputBlocks,
|
2019-04-29 22:15:41 -05:00
|
|
|
items: [
|
2020-12-25 19:47:36 -06:00
|
|
|
{ value: 'button', text: this.$ts._pages.blocks.button },
|
|
|
|
{ value: 'radioButton', text: this.$ts._pages.blocks.radioButton },
|
|
|
|
{ value: 'textInput', text: this.$ts._pages.blocks.textInput },
|
|
|
|
{ value: 'textareaInput', text: this.$ts._pages.blocks.textareaInput },
|
|
|
|
{ value: 'numberInput', text: this.$ts._pages.blocks.numberInput },
|
|
|
|
{ value: 'switch', text: this.$ts._pages.blocks.switch },
|
|
|
|
{ value: 'counter', text: this.$ts._pages.blocks.counter }
|
2019-04-29 22:15:41 -05:00
|
|
|
]
|
2019-04-29 16:40:02 -05:00
|
|
|
}, {
|
2020-12-25 19:47:36 -06:00
|
|
|
label: this.$ts._pages.specialBlocks,
|
2019-04-29 22:15:41 -05:00
|
|
|
items: [
|
2020-12-25 19:47:36 -06:00
|
|
|
{ value: 'if', text: this.$ts._pages.blocks.if },
|
|
|
|
{ value: 'post', text: this.$ts._pages.blocks.post }
|
2019-04-29 22:15:41 -05:00
|
|
|
]
|
2019-04-29 16:40:02 -05:00
|
|
|
}];
|
|
|
|
},
|
|
|
|
|
2019-04-28 19:11:57 -05:00
|
|
|
getScriptBlockList(type: string = null) {
|
|
|
|
const list = [];
|
|
|
|
|
2019-05-05 01:17:29 -05:00
|
|
|
const blocks = blockDefs.filter(block => type === null || block.out === null || block.out === type || typeof block.out === 'number');
|
2019-04-28 19:11:57 -05:00
|
|
|
|
|
|
|
for (const block of blocks) {
|
|
|
|
const category = list.find(x => x.category === block.category);
|
|
|
|
if (category) {
|
|
|
|
category.items.push({
|
|
|
|
value: block.type,
|
2020-01-29 13:37:25 -06:00
|
|
|
text: this.$t(`_pages.script.blocks.${block.type}`)
|
2019-04-28 19:11:57 -05:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
list.push({
|
|
|
|
category: block.category,
|
2020-04-12 13:23:23 -05:00
|
|
|
label: this.$t(`_pages.script.categories.${block.category}`),
|
2019-04-28 19:11:57 -05:00
|
|
|
items: [{
|
|
|
|
value: block.type,
|
2020-01-29 13:37:25 -06:00
|
|
|
text: this.$t(`_pages.script.blocks.${block.type}`)
|
2019-04-28 19:11:57 -05:00
|
|
|
}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const userFns = this.variables.filter(x => x.type === 'fn');
|
|
|
|
if (userFns.length > 0) {
|
|
|
|
list.unshift({
|
2020-04-12 13:23:23 -05:00
|
|
|
label: this.$t(`_pages.script.categories.fn`),
|
2019-04-28 19:11:57 -05:00
|
|
|
items: userFns.map(v => ({
|
|
|
|
value: 'fn:' + v.name,
|
|
|
|
text: v.name
|
|
|
|
}))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
},
|
|
|
|
|
2020-11-14 22:42:04 -06:00
|
|
|
setEyeCatchingImage(e) {
|
|
|
|
selectFile(e.currentTarget || e.target, null, false).then(file => {
|
2019-04-28 19:11:57 -05:00
|
|
|
this.eyeCatchingImageId = file.id;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
removeEyeCatchingImage() {
|
|
|
|
this.eyeCatchingImageId = null;
|
2020-08-21 18:03:11 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
highlighter(code) {
|
|
|
|
return highlight(code, languages.js, 'javascript');
|
|
|
|
},
|
2019-04-28 19:11:57 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.gwbmwxkm {
|
2020-10-17 06:12:00 -05:00
|
|
|
position: relative;
|
2020-01-29 13:37:25 -06:00
|
|
|
|
|
|
|
> header {
|
|
|
|
> .title {
|
|
|
|
z-index: 1;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0 16px;
|
|
|
|
line-height: 42px;
|
|
|
|
font-size: 0.9em;
|
|
|
|
font-weight: bold;
|
2020-04-15 10:39:21 -05:00
|
|
|
box-shadow: 0 1px rgba(#000, 0.07);
|
2020-01-29 13:37:25 -06:00
|
|
|
|
|
|
|
> [data-icon] {
|
|
|
|
margin-right: 6px;
|
|
|
|
}
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
> .buttons {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 2;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
|
|
|
|
> button {
|
|
|
|
padding: 0;
|
|
|
|
width: 42px;
|
|
|
|
font-size: 0.9em;
|
|
|
|
line-height: 42px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
> section {
|
|
|
|
padding: 0 32px 32px 32px;
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
@media (max-width: 500px) {
|
|
|
|
padding: 0 16px 16px 16px;
|
|
|
|
}
|
2019-04-29 00:46:35 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
> .view {
|
|
|
|
display: inline-block;
|
|
|
|
margin: 16px 0 0 0;
|
|
|
|
font-size: 14px;
|
|
|
|
}
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
> .content {
|
|
|
|
margin-bottom: 16px;
|
|
|
|
}
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
> .eyeCatch {
|
|
|
|
margin-bottom: 16px;
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
> div {
|
|
|
|
> img {
|
|
|
|
max-width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
.qmuvgica {
|
|
|
|
padding: 32px;
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
@media (max-width: 500px) {
|
|
|
|
padding: 16px;
|
|
|
|
}
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
> .variables {
|
|
|
|
margin-bottom: 16px;
|
|
|
|
}
|
2019-04-28 19:11:57 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
> .add {
|
|
|
|
margin-bottom: 16px;
|
|
|
|
}
|
|
|
|
}
|
2019-04-28 19:11:57 -05:00
|
|
|
</style>
|