use sections plugin

This commit is contained in:
2023-08-16 13:49:35 +02:00
parent 8af2815bb6
commit 0148c0f3a0
7 changed files with 80 additions and 72 deletions

View File

@@ -15,7 +15,7 @@
"bootstrap": "^5.3.1", "bootstrap": "^5.3.1",
"bootstrap-icons": "^1.10.5", "bootstrap-icons": "^1.10.5",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"magico-section": "../magico-section", "magico-section": "https://serwer.magico.pl/gitrepos/public/magico-section.git",
"tinymce": "^6.0.3", "tinymce": "^6.0.3",
"vue": "^3.3.4", "vue": "^3.3.4",
"vuedraggable": "^4.1.0" "vuedraggable": "^4.1.0"

View File

@@ -1,24 +1,34 @@
<template> <template>
<div id="app" class="container"> <div id="app" class="container">
<img alt="Vue logo" style="width:100px" src="./assets/logo.png"> <img alt="Vue logo" style="width: 100px" src="./assets/logo.png" />
<h2>Pagebuilder Magico</h2> <h2>Pagebuilder Magico</h2>
<MagicoPagebuilder v-model="data" /> <MagicoPagebuilder v-model="data" />
<div class="bg-dark text-light mt-4 p-2">{{data}}</div> <div class="bg-dark text-light mt-4 p-2">{{ data }}</div>
</div> </div>
</template> </template>
<script> <script>
import { useSections } from './components/registerSections'
import axios from 'axios'
export default { export default {
name: 'App', name: 'App',
components: { components: {},
data: function () {
},
data: function(){
return { return {
data:'[{"label":"1 kolumna ","name":"col_1","columns":[{"name":"col-md-12","items":[{"name":"core_section_textarea","text":""},{"name":"core_section_text","text":""}]}]}]' data: '[{"label":"1 kolumna ","name":"col_1","columns":[{"name":"col-md-12","items":[{"name":"core_section_textarea","text":""},{"name":"core_section_text","text":""}]}]}]'
} }
},
mounted() {
const { register: sectionRegister } = useSections()
let vm = this
this.$pagebuilder.axios = axios.create({
headers: { Authorization: 'Bearer ffe788a01ac6c7461c2159d76271485130994e02' }
})
this.$pagebuilder.axios.get('https://cms.magico.pro/api/v1/section').then((response) => {
sectionRegister(vm.$pagebuilder, response.data.data)
})
} }
} }
</script> </script>
@@ -31,4 +41,4 @@ export default {
color: #2c3e50; color: #2c3e50;
margin-top: 60px; margin-top: 60px;
} }
</style> </style>

View File

@@ -17,6 +17,12 @@
v-if="item.svg" v-if="item.svg"
v-html="item.svg" v-html="item.svg"
></div> ></div>
<img
style="width: 100%"
v-else-if="item.image"
:src="item.image"
>
<img <img
v-else v-else
style="width: 100%" style="width: 100%"
@@ -69,7 +75,6 @@ export default {
} }
}, },
mounted() { mounted() {
} }
} }
</script> </script>

View File

@@ -1,9 +1,5 @@
<template> <template>
<div <div style="min-height: 100px" class="pagebuilder-column" :class="value.name">
style="min-height: 100px"
class="pagebuilder-column"
:class="value.name"
>
<b-modal <b-modal
v-model.value="modalAddBox" v-model.value="modalAddBox"
class_other="modal-xl" class_other="modal-xl"
@@ -11,7 +7,7 @@
title="Dodaj widżet" title="Dodaj widżet"
> >
<div> <div>
<DropdownSectionSection @choose="clickAdd"> </DropdownSectionSection> <DropdownSectionSection v-if="modalAddBox" @choose="clickAdd"> </DropdownSectionSection>
</div> </div>
</b-modal> </b-modal>
@@ -24,19 +20,11 @@
<div> <div>
<div class="from-group"> <div class="from-group">
<label>Klasa kolumny</label> <label>Klasa kolumny</label>
<input <input @input="onChange" v-model="value.class" type="text" class="form-control" />
@input="onChange"
v-model="value.class"
type="text"
class="form-control"
/>
</div> </div>
</div> </div>
<div> <div>
<button <button @click="modalColumnsSettings = false" class="btn btn-outline-secondary">
@click="modalColumnsSettings = false"
class="btn btn-outline-secondary"
>
Zapisz i zamknij Zapisz i zamknij
</button> </button>
</div> </div>
@@ -47,7 +35,7 @@
@start="drag = true" @start="drag = true"
@end=" @end="
drag = false; drag = false;
onChange(); onChange()
" "
group="people" group="people"
> >
@@ -95,53 +83,58 @@
</div> </div>
</template> </template>
<script> <script>
import draggable from "vuedraggable"; import draggable from 'vuedraggable'
import MagicoModal from "./MagicoModal.vue"; import MagicoModal from './MagicoModal.vue'
import SectionText from "./plugin/SectionText.vue"; import SectionText from './plugin/SectionText.vue'
import SectionTextarea from "./plugin/SectionTextarea.vue"; import SectionTextarea from './plugin/SectionTextarea.vue'
import SectionHtml from "./plugin/SectionHtml.vue"; import SectionHtml from './plugin/SectionHtml.vue'
import SectionImage from "./plugin/SectionImage.vue"; import SectionImage from './plugin/SectionImage.vue'
import DropdownSectionSection from "./DropdownSectionSection.vue"; import DropdownSectionSection from './DropdownSectionSection.vue'
export default { export default {
data: function () { data: function () {
return { opcja: "", modalAddBox: false, drag: false, modalColumnsSettings: false }; return { opcja: '', modalAddBox: false, drag: false, modalColumnsSettings: false }
}, },
props: { value: Object }, props: { value: Object },
emits: ["update:modelValue"], emits: ['update:modelValue'],
components: { components: {
draggable, draggable,
"b-modal": MagicoModal, 'b-modal': MagicoModal,
core_section_textarea: SectionTextarea, core_section_textarea: SectionTextarea,
core_section_text: SectionText, core_section_text: SectionText,
core_section_html: SectionHtml, core_section_html: SectionHtml,
core_section_image: SectionImage, core_section_image: SectionImage,
DropdownSectionSection, DropdownSectionSection
}, },
methods: { methods: {
onChange: function () { onChange: function () {
this.$emit("change"); this.$emit('change')
}, },
rand: function () { rand: function () {
return "component" + Math.random() * 100; return 'component' + Math.random() * 100
}, },
removeItem(item) { removeItem(item) {
this.value.items.indexOf(item); this.value.items.indexOf(item)
this.value.items.splice(this.value.items.indexOf(item), 1); this.value.items.splice(this.value.items.indexOf(item), 1)
this.onChange(); this.onChange()
}, },
clickAdd: function (item) { clickAdd: function (item) {
console.log(item); console.log(item)
this.modalAddBox = false; const sectionobj = this.$pagebuilder.items[item]
var a = { name: item, open: true }; console.log('addedd', sectionobj)
this.value.items.push(a); this.modalAddBox = false
this.onChange(); var a = { name: item, open: true }
}, if (sectionobj.section_id) {
}, a.section_id = sectionobj.section_id;
}; }
this.value.items.push(a)
this.onChange()
}
}
}
</script> </script>
<style> <style>
.pagebuilder-column-hover { .pagebuilder-column-hover {

View File

@@ -1,16 +1,20 @@
import PagebuilderSectionPlugin from "../../../magico-section/src/components/PagebuilderSectionPlugin.vue"; import PagebuilderSectionPlugin from 'magico-section/src/components/PagebuilderSectionPlugin.vue'
export function useSections() { export function useSections() {
console.log('DUPA',PagebuilderSectionPlugin); function register(vm, sections) {
function register(vm) { console.log('sections', sections, vm)
vm.registerPlugin( sections.forEach((item) => {
"SectionX1", vm.registerPlugin(
{ 'section_' + item.section_id,
label: "Sekcja 1", {
svg_off: ``, label: item.title,
}, svg_off: ``,
PagebuilderSectionPlugin section_id: item.section_id,
); image: item.image
},
PagebuilderSectionPlugin
)
})
} }
return { register }; return { register }
} }

View File

@@ -2,16 +2,11 @@ import './assets/main.css'
import { createApp } from 'vue' import { createApp } from 'vue'
import App from './App.vue' import App from './App.vue'
import axios from 'axios'
import 'bootstrap/dist/css/bootstrap.min.css' import 'bootstrap/dist/css/bootstrap.min.css'
import MagicoPagebuilder from './components/MagicoPagebuilderPlugin.js' import MagicoPagebuilder from './components/MagicoPagebuilderPlugin.js'
const app = createApp(App).use(MagicoPagebuilder).mount('#app')
import { useSections } from "./components/registerSections";
const app = createApp(App).use(MagicoPagebuilder).mount("#app");
const { register: sectionRegister } = useSections();
sectionRegister(app.$pagebuilder);

View File

@@ -1030,8 +1030,9 @@ magic-string@^0.30.0:
dependencies: dependencies:
"@jridgewell/sourcemap-codec" "^1.4.15" "@jridgewell/sourcemap-codec" "^1.4.15"
magico-section@../magico-section: "magico-section@https://serwer.magico.pl/gitrepos/public/magico-section.git":
version "0.1.0" version "0.1.0"
resolved "https://serwer.magico.pl/gitrepos/public/magico-section.git#913d62c6aac1c0ce60c3c17c8d64b029b7c43df2"
dependencies: dependencies:
"@popperjs/core" "^2.11.8" "@popperjs/core" "^2.11.8"
axios "^1.4.0" axios "^1.4.0"