watch for external udpate

This commit is contained in:
2024-07-02 08:46:52 +02:00
parent 4008ebbbcc
commit 883dd6da91
2 changed files with 58 additions and 46 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "magico-pagebuilder", "name": "magico-pagebuilder",
"version": "0.0.12", "version": "0.0.13",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@@ -27,7 +27,7 @@
<li> <li>
<a <a
@click.prevent=" @click.prevent="
modalLoad = !modalLoad; modalLoad = !modalLoad
pageType = { name: null } pageType = { name: null }
" "
class="dropdown-item" class="dropdown-item"
@@ -38,7 +38,7 @@
<li> <li>
<a <a
@click.prevent=" @click.prevent="
modalSave = !modalSave; modalSave = !modalSave
pageType = { name: null } pageType = { name: null }
" "
class="dropdown-item" class="dropdown-item"
@@ -47,13 +47,7 @@
> >
</li> </li>
<li v-if="descriptionAllegro"> <li v-if="descriptionAllegro">
<a <a @click.prevent="pasteAllegro" class="dropdown-item" href="#"
@click.prevent="
pasteAllegro
"
class="dropdown-item"
href="#"
>Wklej opis <i>Allegro</i></a >Wklej opis <i>Allegro</i></a
> >
</li> </li>
@@ -71,7 +65,7 @@
@start="drag = true" @start="drag = true"
item-key="d" item-key="d"
@end=" @end="
drag = false; drag = false
onChange() onChange()
" "
> >
@@ -147,7 +141,7 @@
<!-- <textarea style="display:none" :name="namex">{{ comps }}</textarea> --><button <!-- <textarea style="display:none" :name="namex">{{ comps }}</textarea> --><button
class="btn btn-block btn-primary mt-4" class="btn btn-block btn-primary mt-4"
@click.prevent=" @click.prevent="
modalAddSection = !modalAddSection; modalAddSection = !modalAddSection
optionx = false optionx = false
" "
> >
@@ -192,12 +186,13 @@ export default {
modalSave: false, modalSave: false,
modalLoad: false, modalLoad: false,
descriptionAllegro: false, descriptionAllegro: false,
ownUpdate: false
} }
}, },
props: ['name', 'modelValue', 'showcopy', 'lang'], props: ['name', 'modelValue', 'showcopy', 'lang'],
mounted: function () { mounted: function () {
if (localStorage.getItem('description_clipboard')) { if (localStorage.getItem('description_clipboard')) {
this.descriptionAllegro=true; this.descriptionAllegro = true
} }
//var trimmed = $("#body_pagebuilder").val().replace((/ |\r\n|\n|\r/gm),""); //var trimmed = $("#body_pagebuilder").val().replace((/ |\r\n|\n|\r/gm),"");
var trimmed = this.modelValue //.replace((/{2} |\r\n|\n|\r/gm), ""); var trimmed = this.modelValue //.replace((/{2} |\r\n|\n|\r/gm), "");
@@ -214,8 +209,7 @@ export default {
] ]
} }
}, },
computed: { computed: {},
},
created: function () { created: function () {
if (this.name) this.namex = this.name if (this.name) this.namex = this.name
else this.namxe = 'body' else this.namxe = 'body'
@@ -224,10 +218,29 @@ export default {
// whenever question changes, this function will run // whenever question changes, this function will run
comps: function (newQuestion) { comps: function (newQuestion) {
console.log('nq', newQuestion) console.log('nq', newQuestion)
},
modelValue: function () {
if (this.ownUpdate) {
this.ownUpdate = false
return
}
try {
this.comps = JSON.parse(trimmed)
} catch (e) {
console.warn(e)
this.comps = [
{
label: '1 kolumna ',
name: 'col_1',
columns: [{ name: 'col-md-12', items: [{ name: 'core_section_textarea' }] }]
}
]
}
} }
}, },
methods: { methods: {
onChange: function () { onChange: function () {
this.ownUpdate = true
this.$emit('update:modelValue', JSON.stringify(this.comps)) this.$emit('update:modelValue', JSON.stringify(this.comps))
this.$emit('change') this.$emit('change')
}, },
@@ -266,43 +279,42 @@ export default {
this.changeBody() this.changeBody()
}, },
pasteAllegro: function () { pasteAllegro: function () {
let sections = localStorage.getItem('description_clipboard'); let sections = localStorage.getItem('description_clipboard')
try { try {
sections = JSON.parse(sections); sections = JSON.parse(sections)
} catch (e) { } catch (e) {
if (e instanceof SyntaxError) { if (e instanceof SyntaxError) {
sections = [{ name: 'Tekst', cols: [{ type: 'text', value: sections, size: 12 }] }]; sections = [{ name: 'Tekst', cols: [{ type: 'text', value: sections, size: 12 }] }]
} }
} }
const pagebuilder = sections.map(item => { const pagebuilder = sections.map((item) => {
const columns = []; const columns = []
if (item.cols && Array.isArray(item.cols)) { if (item.cols && Array.isArray(item.cols)) {
item.cols.forEach(col => { item.cols.forEach((col) => {
const column = { const column = {
type: 'container',
type:"container",
name: 'col-md-' + col.size, name: 'col-md-' + col.size,
items: [ items: [
{ {
name: (col.type === 'img' ? 'core_section_image' : 'core_section_textarea'), name: col.type === 'img' ? 'core_section_image' : 'core_section_textarea',
text: col.value, text: col.value
} }
] ]
}; }
if (col.type === 'img' && col.figcaption) { if (col.type === 'img' && col.figcaption) {
column.items[0]['figcaption'] = col.figcaption; column.items[0]['figcaption'] = col.figcaption
} }
columns.push(column); columns.push(column)
}); })
} }
return { columns,label:'',name:'', type:'container' }; return { columns, label: '', name: '', type: 'container' }
}); })
this.comps = pagebuilder; this.comps = pagebuilder
this.onChange(); this.onChange()
}, },
changeBody() { changeBody() {
var t = this var t = this