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

138 lines
3.7 KiB
Vue
Raw Normal View History

2020-04-30 14:21:43 +02:00
<template>
2020-07-08 11:19:23 +02:00
<div>
2020-10-29 21:44:22 +01:00
<div class="editor-outer" v-if="loaded" :class="{ 'has-tabs': hasTabs, '-infos-aside': !nested && infos != 'none', 'is-page': isPage, 'as-boxes': asBoxes }">
2020-10-18 23:47:59 +02:00
<ui-tabs class="editor">
<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">
2020-10-29 21:44:22 +01:00
<h3 v-if="asBoxes" class="ui-headline" v-localize="tab.name"></h3>
2020-10-18 23:47:59 +02:00
<editor-component v-for="(field, fieldIndex) in tab.fields" :key="fieldIndex" :config="field" @input="onChange" :editor="editorConfig" :value="value" />
2020-10-22 11:52:22 +02:00
<component v-if="tab.component" :is="tab.component" v-model="value" />
2020-07-08 11:19:23 +02:00
</ui-tab>
</ui-tabs>
2020-12-06 19:58:36 +01:00
<editor-aside :editor="editorConfig" :value="value" v-if="infos != 'none' && !isPage" v-bind="{ infos, activeToggle, nested, isPage }">
2020-12-05 15:33:52 +01:00
<template v-slot:info-boxes>
<slot name="info-boxes"></slot>
</template>
<template v-slot:settings>
<slot name="settings"></slot>
</template>
<template v-slot:settings-properties>
<slot name="settings-properties"></slot>
</template>
<template v-slot:infos>
<slot name="infos"></slot>
</template>
<template v-slot:infos-more>
<slot name="infos-more"></slot>
</template>
<template v-slot:infos-after>
<slot name="infos-after"></slot>
</template>
</editor-aside>
2020-07-08 11:19:23 +02:00
</div>
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 {
2020-11-17 15:44:04 +01:00
meta: this.meta
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
},
infos: {
type: String,
default: 'aside'
},
activeToggle: {
type: Boolean,
default: true
},
nested: {
type: Boolean,
default: false
},
isPage: {
type: Boolean,
default: false
},
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: () => ({
2020-10-18 23:47:59 +02:00
editorConfig: null,
2020-04-30 14:21:43 +02:00
loaded: false,
2020-10-19 14:48:21 +02:00
hasTabs: false,
2020-10-23 13:22:41 +02:00
asBoxes: false,
coreDatabase: false,
2020-10-18 23:47:59 +02:00
tabs: []
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;
if (this.editorConfig.tabs.length > 0)
2020-10-18 23:47:59 +02:00
{
2020-10-19 14:48:21 +02:00
this.hasTabs = true;
this.tabs = this.editorConfig.tabs.map(tab =>
{
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)
};
});
}
else
{
this.tabs = [{
name: '_',
count: value => 0,
disabled: value => false,
fields: this.editorConfig.getFields()
}];
}
2020-10-18 23:47:59 +02:00
2020-10-23 13:22:41 +02:00
this.asBoxes = this.editorConfig.options.boxes;
this.coreDatabase = this.editorConfig.options.coreDatabase;
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>