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

120 lines
3.6 KiB
Vue
Raw Normal View History

2020-04-30 14:21:43 +02:00
<template>
2021-09-16 10:25:56 +02:00
<div class="editor" v-if="loaded" :class="['display-' + display, { 'has-sidebar': asideDefined, 'hide-tabs': tabs.length < 2, 'has-below': belowDefined }]">
2021-01-09 19:09:31 +01:00
<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-11-11 13:46:03 +01:00
<slot name="blueprint">
2021-11-16 13:48:18 +01:00
<blueprint-property v-if="value && editorConfig.blueprint" :value="value" :meta="meta" :config="editorConfig.blueprint" />
2021-11-11 13:46:03 +01:00
</slot>
2021-09-10 14:52:28 +02:00
<div class="ui-property ui-property-parent" v-for="fieldset in tab.fieldsets">
2021-11-15 13:15:00 +01:00
<editor-component v-for="(field, fieldIndex) in fieldset.fields" :disabled="disabled" :key="fieldIndex" :config="field" @input="onChange" :editor="editorConfig" :value="value"
2021-09-10 14:52:28 +02:00
:class="field.options.class" :data-cols="!!field.options.fieldset" :style="{ 'grid-column': field.options.fieldset ? 'span ' + field.options.fieldsetColumns : null }" />
2021-11-11 14:47:50 +01:00
2021-09-10 14:52:28 +02:00
</div>
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';
2021-11-16 13:48:18 +01:00
import { createBlueprintConfig } from 'zero/core/editor-blueprint.ts';
2021-11-11 13:46:03 +01:00
import BlueprintProperty from './blueprint/property.vue';
2021-11-16 13:48:18 +01:00
import Localization from 'zero/helpers/localization.js';
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: () => { }
},
2021-11-15 13:15:00 +01:00
disabled: {
type: Boolean,
default: false
},
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
},
2021-11-11 13:46:03 +01:00
components: { EditorComponent, EditorAside, BlueprintProperty },
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,
2021-09-10 14:52:28 +02:00
tabs: [],
2021-11-16 13:48:18 +01:00
currentFieldset: null
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-11-16 13:48:18 +01:00
this.editorConfig.blueprint = createBlueprintConfig(this.zero, this.editorConfig, this.value);
2020-10-19 14:48:21 +02:00
2021-01-09 19:09:31 +01:00
this.tabs = this.editorConfig.tabs.map(tab =>
2020-10-18 23:47:59 +02:00
{
2021-09-10 14:52:28 +02:00
let fieldsets = this.editorConfig.getFieldsets(tab);
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),
2021-09-10 14:52:28 +02:00
fieldsets
2021-01-09 19:09:31 +01:00
};
});
2020-10-18 23:47:59 +02:00
2021-01-09 19:09:31 +01:00
this.display = this.editorConfig.options.display || 'tabs';
2021-11-16 13:48:18 +01:00
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>