Files
mixtape/zero.Web.UI/App/editor/editor.vue
T

101 lines
2.7 KiB
Vue
Raw Normal View History

2020-04-30 14:21:43 +02:00
<template>
2021-01-09 19:09:31 +01:00
<div class="editor" v-if="loaded" :class="['display-' + display, { 'has-sidebar': asideDefined, 'hide-tabs': tabs.length < 2 }]">
<ui-tabs class="editor-tabs">
<ui-tab v-if="!tab.disabled(value)" v-for="(tab, index) in tabs" class="ui-box" :class="tab.class" :label="tab.name" :count="tab.count(value)" :key="index">
2021-01-14 16:09:39 +01:00
<h3 v-if="display == 'boxes' && tab.name" class="ui-headline editor-tab-headline" v-localize="tab.name"></h3>
2021-01-11 00:34:41 +01:00
<editor-component v-for="(field, fieldIndex) in tab.fields" :key="fieldIndex" :config="field" @input="onChange" :editor="editorConfig" :value="value" :class="field.options.class" />
2021-01-09 19:09:31 +01:00
<component v-if="tab.component" :is="tab.component" v-model="value" />
</ui-tab>
</ui-tabs>
<aside class="editor-aside" v-if="asideDefined">
<slot name="aside"></slot>
</aside>
<aside class="editor-below" v-if="belowDefined">
<slot name="below"></slot>
</aside>
2020-06-23 15:44:14 +02:00
</div>
2020-04-30 14:21:43 +02:00
</template>
<script>
2020-10-21 12:10:21 +02:00
import './editor.scss';
2020-10-18 23:47:59 +02:00
import EditorComponent from 'zero/editor/editor-component.vue';
2020-10-21 12:10:21 +02:00
import EditorAside from './editor-aside.vue';
2020-04-30 14:21:43 +02:00
export default {
name: 'uiEditor',
2020-10-18 23:47:59 +02:00
provide: function ()
{
return {
2021-01-11 15:59:18 +01:00
meta: this.meta,
editor: this.config
2020-10-18 23:47:59 +02:00
};
},
2020-05-01 14:34:44 +02:00
props: {
2020-10-19 14:48:21 +02:00
config: {
2020-10-20 13:27:17 +02:00
type: [String, Object],
2020-05-01 14:34:44 +02:00
required: true
2020-05-02 12:20:22 +02:00
},
2020-06-24 13:00:50 +02:00
meta: {
type: Object,
default: () => { }
},
2020-10-15 14:10:04 +02:00
value: {
2020-05-02 12:20:22 +02:00
type: Object
2020-10-21 12:10:21 +02:00
},
2020-10-22 11:52:22 +02:00
onConfigure: {
type: Function,
default: () => { }
},
2020-05-01 14:34:44 +02:00
},
2020-10-21 12:10:21 +02:00
components: { EditorComponent, EditorAside },
2020-04-30 14:21:43 +02:00
data: () => ({
2021-01-11 15:59:18 +01:00
editorConfig: {},
2020-04-30 14:21:43 +02:00
loaded: false,
2020-10-18 23:47:59 +02:00
tabs: []
2020-04-30 14:21:43 +02:00
}),
2021-01-09 19:09:31 +01:00
computed: {
asideDefined()
{
return this.$scopedSlots.hasOwnProperty('aside');
},
belowDefined()
{
return this.$scopedSlots.hasOwnProperty('below');
}
},
2020-04-30 14:21:43 +02:00
created()
{
2020-10-19 14:48:21 +02:00
this.editorConfig = typeof this.config === 'string' ? this.zero.getEditor(this.config) : this.config;
2021-01-09 19:09:31 +01:00
this.tabs = this.editorConfig.tabs.map(tab =>
2020-10-18 23:47:59 +02:00
{
2021-01-09 19:09:31 +01:00
return {
...tab,
count: value => typeof tab.count === 'number' ? tab.count : (typeof tab.count === 'function' ? tab.count(value) : 0),
disabled: value => typeof tab.disabled === 'boolean' ? tab.disabled : (typeof tab.disabled === 'function' ? tab.disabled(value) : false),
fields: this.editorConfig.getFields(tab)
};
});
2020-10-18 23:47:59 +02:00
2021-01-09 19:09:31 +01:00
this.display = this.editorConfig.options.display || 'tabs';
2020-10-22 11:52:22 +02:00
this.onConfigure(this);
2020-10-18 23:47:59 +02:00
this.loaded = true;
2020-05-01 14:34:44 +02:00
},
methods: {
2020-06-30 12:12:31 +02:00
onChange()
{
2020-10-15 14:10:04 +02:00
this.$emit('input', this.value);
2020-05-01 14:34:44 +02:00
}
2020-04-30 14:21:43 +02:00
}
}
2020-10-21 12:10:21 +02:00
</script>