Sharkey/src/client/pages/page-editor/els/page-editor.el.section.vue

102 lines
2 KiB
Vue
Raw Normal View History

<template>
2019-05-02 08:55:59 +00:00
<x-container @remove="() => $emit('remove')" :draggable="true">
<template #header><fa :icon="faStickyNote"/> {{ value.title }}</template>
<template #func>
2020-04-16 14:13:33 +00:00
<button @click="rename()" class="_button">
<fa :icon="faPencilAlt"/>
</button>
2020-04-16 14:13:33 +00:00
<button @click="add()" class="_button">
<fa :icon="faPlus"/>
</button>
</template>
<section class="ilrvjyvi">
2020-04-20 12:35:27 +00:00
<x-blocks class="children" v-model="value.children" :hpml="hpml"/>
</section>
</x-container>
</template>
<script lang="ts">
import Vue from 'vue';
import { v4 as uuid } from 'uuid';
import { faPlus, faPencilAlt } from '@fortawesome/free-solid-svg-icons';
import { faStickyNote } from '@fortawesome/free-regular-svg-icons';
import XContainer from '../page-editor.container.vue';
export default Vue.extend({
components: {
XContainer
},
inject: ['getPageBlockList'],
props: {
value: {
required: true
},
2020-04-20 12:35:27 +00:00
hpml: {
required: true,
},
},
data() {
return {
faStickyNote, faPlus, faPencilAlt
};
},
beforeCreate() {
2019-05-02 08:55:59 +00:00
this.$options.components.XBlocks = require('../page-editor.blocks.vue').default
},
created() {
if (this.value.title == null) Vue.set(this.value, 'title', null);
if (this.value.children == null) Vue.set(this.value, 'children', []);
},
mounted() {
if (this.value.title == null) {
this.rename();
}
},
methods: {
async rename() {
const { canceled, result: title } = await this.$root.dialog({
title: 'Enter title',
input: {
type: 'text',
default: this.value.title
},
showCancelButton: true
});
if (canceled) return;
this.value.title = title;
},
async add() {
const { canceled, result: type } = await this.$root.dialog({
type: null,
title: this.$t('_pages.chooseBlock'),
select: {
2019-04-30 03:15:41 +00:00
groupedItems: this.getPageBlockList()
},
showCancelButton: true
});
if (canceled) return;
const id = uuid();
this.value.children.push({ id, type });
},
}
});
</script>
<style lang="scss" scoped>
.ilrvjyvi {
> .children {
padding: 16px;
}
}
</style>