<!-- ParentComponent.vue -->
<template>
<div id="app">
<h1 class="mb-4">Product Schema Manager</h1>
<YamlEditor
:model-name="'Product'"
:field-config="fieldConfig"
:yaml-data-prop.sync="yamlData"
:yaml-db-data-prop.sync="yamlDbData"
:db-object-schema-prop.sync="dbObjectSchema"
:print-setting-prop.sync="printSettings"
:print-body-prop.sync="printBody"
:form-layout-prop.sync="formLayout"
:view-layout-prop.sync="viewLayout"
:form-preview-url="'/api/preview/form'"
:view-preview-url="'/api/preview/view'"
:render-preview-url="'/api/preview/print'"
:file-tree-url="'/api/files/tree'"
:load-yaml-url="'/api/files/load'"
/>
<div class="mt-5">
<h4>Live Data in Parent Component:</h4>
<pre><code>{{ JSON.stringify(yamlData, null, 2) }}</code></pre>
</div>
</div>
</template>
<script>
import YamlEditor from './components/YamlEditor.vue';
export default {
name: 'ParentComponent',
components: {
YamlEditor,
},
data() {
return {
// Configuration for the property editor
fieldConfig: {
types: [ 'text', 'number', 'boolean', 'date', 'select' ],
sections: {
vue: {
properties: [ 'model', 'type', 'default', 'label' ]
},
table: {
properties: [ 'name', 'label', 'show', 'sort', 'filter' ]
},
form: {
properties: [ 'model', 'label', 'type', 'create', 'edit' ]
},
// ... other sections
}
},
// Initial main schema data
yamlData: {
vue: [
{ model: 'product_name', type: 'string', default: '', label: 'Product Name' },
{ model: 'price', type: 'number', default: 0, label: 'Price' }
],
table: [
{ name: 'product_name', label: 'Product Name', show: true, sort: true },
{ name: 'price', label: 'Price', show: true, sort: true }
],
form: [
{ model: 'product_name', label: 'Product Name', type: 'text', create: true, edit: true },
{ model: 'price', label: 'Price', type: 'number', create: true, edit: true }
],
view: [
{ model: 'product_name', label: 'Product Name', type: 'text' },
{ model: 'price', label: 'Price', type: 'text' }
]
},
// Initial DB schema data
yamlDbData: [
{ name: 'product_name', type: 'string', nullable: false, api: { show: true } },
{ name: 'price', type: 'decimal', default: 0, api: { show: true } }
],
// Initial DB Object Schema data
dbObjectSchema: {
primary_key: 'id',
fields: {
id: { type: 'increments', name: 'id' }
}
},
// Initial layout and print data
formLayout: "rows:\n - columns:\n - fields: ['product_name']\n - fields: ['price']",
viewLayout: "rows:\n - columns:\n - fields: ['product_name', 'price']",
printSettings: {
margins: { top: '20mm', bottom: '20mm', left: '10mm', right: '10mm' }
},
printBody: "<h1>Product Details</h1><p>Name: {{ product_name }}</p><p>Price: {{ price }}</p>",
};
}
};
</script>
<style>
/* Add bootstrap or other global styles if needed */
@import"https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css";
pre {
background-color: #f4f4f4;
padding: 1rem;
border-radius: 5px;
white-space: pre-wrap;
}
</style>