2021-12-09 10:51:10 +01:00
|
|
|
<template>
|
2021-12-22 15:41:11 +01:00
|
|
|
<div class="editor-outer" v-if="loaded && editorConfig">
|
2021-12-09 10:51:10 +01:00
|
|
|
<header class="editor-above" v-if="aboveDefined">
|
2021-12-21 13:58:48 +01:00
|
|
|
<!--<slot name="above" v-bind:config="editorConfig"></slot>-->
|
2021-12-09 10:51:10 +01:00
|
|
|
</header>
|
2021-12-30 13:39:31 +01:00
|
|
|
<div class="editor" :class="['display-' + editorConfig.display, { 'has-sidebar': asideDefined, 'hide-tabs': editorConfig.tabs.length < 2, 'has-below': belowDefined }]">
|
2021-12-09 10:51:10 +01:00
|
|
|
<ui-tabs class="editor-tabs">
|
2021-12-21 13:58:48 +01:00
|
|
|
<ui-tab v-for="(tab, index) in editorConfig.tabs" :key="index" class="ui-box"
|
|
|
|
|
:class="tab.class"
|
|
|
|
|
:data-alias="tab.alias"
|
|
|
|
|
:label="tab.name"
|
|
|
|
|
:count="tab.count(value)"
|
|
|
|
|
:hide="tab.hidden(value)"
|
|
|
|
|
:disabled="tab.disabled(value)">
|
2021-12-30 13:39:31 +01:00
|
|
|
<h3 v-if="editorConfig.display == 'boxes' && tab.name" class="ui-headline editor-tab-headline" v-localize="tab.name"></h3>
|
2021-12-09 10:51:10 +01:00
|
|
|
<slot name="blueprint">
|
2021-12-22 10:55:40 +01:00
|
|
|
<blueprint-property v-if="value && editorConfig.blueprint.isEnabled" :value="value" :meta="meta" :config="editorConfig.blueprint" />
|
2021-12-09 10:51:10 +01:00
|
|
|
</slot>
|
2021-12-21 13:58:48 +01:00
|
|
|
<div v-if="!tab.component" class="ui-property ui-property-parent" v-for="(fieldset, fieldsetIndex) in tab.fieldsets" :key="fieldsetIndex">
|
|
|
|
|
|
|
|
|
|
<editor-component v-for="(field, fieldIndex) in fieldset.fields" :key="fieldIndex"
|
|
|
|
|
:value="value"
|
|
|
|
|
:field="field"
|
|
|
|
|
:disabled="disabled"
|
2021-12-21 14:41:50 +01:00
|
|
|
:system="system"
|
2022-01-03 01:08:55 +01:00
|
|
|
:data-xo="JSON.stringify(field.configuration)"
|
2021-12-21 13:58:48 +01:00
|
|
|
:class="field.configuration.classes"
|
2022-01-03 01:08:55 +01:00
|
|
|
:x-data-cols="fieldset.hasColumns"
|
|
|
|
|
:x-style="{ 'grid-column': fieldset.hasColumns ? 'span ' + field.configuration.columns : null }"
|
2021-12-21 13:58:48 +01:00
|
|
|
@input="onChange" />
|
2021-12-09 10:51:10 +01:00
|
|
|
|
|
|
|
|
</div>
|
2021-12-21 14:41:50 +01:00
|
|
|
<component v-else :is="tab.component" v-model="value" :system="system" />
|
2021-12-09 10:51:10 +01:00
|
|
|
</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>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-12-22 15:41:11 +01:00
|
|
|
<div class="editor-outer" v-if="loaded && !editorConfig">
|
|
|
|
|
<div class="page page-error" style="min-height: 400px;">
|
|
|
|
|
<ui-icon symbol="fth-cloud-snow" class="page-error-icon" :size="82" />
|
|
|
|
|
<p class="page-error-text">
|
|
|
|
|
<strong class="page-error-headline">Could not find editor</strong><br>
|
|
|
|
|
<span v-if="typeof config === 'string'">Please register an editor schema with the alias:<br />[{{config}}]</span>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-12-09 10:51:10 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-12-21 13:58:48 +01:00
|
|
|
// :data-cols="!!field.options.fieldset"
|
|
|
|
|
// :style="{ 'grid-column': field.options.fieldset ? 'span ' + field.options.fieldsetColumns : null }"
|
|
|
|
|
|
2021-12-21 00:53:17 +01:00
|
|
|
import './ui-editor.scss';
|
|
|
|
|
import EditorComponent from './ui-editor-component.vue';
|
2021-12-22 10:55:40 +01:00
|
|
|
import BlueprintProperty from './blueprint/property.vue';
|
2021-12-14 14:21:48 +01:00
|
|
|
import { defineComponent } from 'vue';
|
2021-12-22 15:41:11 +01:00
|
|
|
import { compileEditor } from './compile';
|
2021-12-09 10:51:10 +01:00
|
|
|
|
2021-12-14 14:21:48 +01:00
|
|
|
export default defineComponent({
|
2021-12-09 10:51:10 +01:00
|
|
|
name: 'uiEditor',
|
|
|
|
|
|
|
|
|
|
provide: function ()
|
|
|
|
|
{
|
|
|
|
|
return {
|
|
|
|
|
meta: this.meta,
|
|
|
|
|
editor: this.config
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
props: {
|
|
|
|
|
config: {
|
|
|
|
|
type: [String, Object],
|
|
|
|
|
required: true
|
|
|
|
|
},
|
|
|
|
|
meta: {
|
|
|
|
|
type: Object,
|
|
|
|
|
default: () => { }
|
|
|
|
|
},
|
|
|
|
|
disabled: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
2021-12-21 14:41:50 +01:00
|
|
|
scope: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: true
|
|
|
|
|
},
|
2021-12-14 14:21:48 +01:00
|
|
|
value: {
|
2021-12-09 10:51:10 +01:00
|
|
|
type: Object
|
|
|
|
|
},
|
|
|
|
|
onConfigure: {
|
|
|
|
|
type: Function,
|
|
|
|
|
default: () => { }
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2021-12-22 10:55:40 +01:00
|
|
|
components: { EditorComponent, BlueprintProperty },
|
2021-12-09 10:51:10 +01:00
|
|
|
|
|
|
|
|
data: () => ({
|
|
|
|
|
editorConfig: {},
|
|
|
|
|
loaded: false,
|
|
|
|
|
tabs: [],
|
2021-12-21 14:41:50 +01:00
|
|
|
system: false,
|
2021-12-09 10:51:10 +01:00
|
|
|
currentFieldset: null
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
|
aboveDefined()
|
|
|
|
|
{
|
2021-12-21 13:58:48 +01:00
|
|
|
return this.$slots.hasOwnProperty('above');
|
2021-12-09 10:51:10 +01:00
|
|
|
},
|
|
|
|
|
asideDefined()
|
|
|
|
|
{
|
2021-12-21 13:58:48 +01:00
|
|
|
return this.$slots.hasOwnProperty('aside');
|
2021-12-09 10:51:10 +01:00
|
|
|
},
|
|
|
|
|
belowDefined()
|
|
|
|
|
{
|
2021-12-21 13:58:48 +01:00
|
|
|
return this.$slots.hasOwnProperty('below');
|
2021-12-09 10:51:10 +01:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2021-12-14 14:21:48 +01:00
|
|
|
async created()
|
2021-12-09 10:51:10 +01:00
|
|
|
{
|
2021-12-21 16:13:41 +01:00
|
|
|
this.system = this.$route.query['zero.scope'] == 'system';
|
2021-12-21 13:58:48 +01:00
|
|
|
const schema = typeof this.config === 'string' ? await this.zero.getSchema(this.config) : this.config;
|
2021-12-22 15:41:11 +01:00
|
|
|
this.editorConfig = compileEditor(this.zero, schema);
|
2021-12-09 10:51:10 +01:00
|
|
|
|
2022-01-12 23:52:37 +01:00
|
|
|
this.onConfigure(this.editorConfig, this);
|
2021-12-09 10:51:10 +01:00
|
|
|
|
|
|
|
|
this.loaded = true;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
|
|
onChange()
|
|
|
|
|
{
|
2021-12-14 14:21:48 +01:00
|
|
|
this.$emit('input', this.value);
|
2021-12-09 10:51:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-14 14:21:48 +01:00
|
|
|
})
|
2021-12-09 10:51:10 +01:00
|
|
|
</script>
|