2019-05-02 17:55:59 +09:00
|
|
|
<template>
|
2022-12-21 11:04:49 +09:00
|
|
|
<Sortable :list="blocks" tag="div" item-key="id" :options="{ handle: '.drag-handle', group: { name: 'blocks' }, animation: 150, swapThreshold: 0.5 }">
|
2020-12-05 12:50:09 +09:00
|
|
|
<template #item="{element}">
|
2021-11-19 19:36:12 +09:00
|
|
|
<component :is="'x-' + element.type" :value="element" :hpml="hpml" @update:value="updateItem" @remove="() => removeItem(element)"/>
|
2020-12-05 12:50:09 +09:00
|
|
|
</template>
|
2022-12-21 11:04:49 +09:00
|
|
|
</Sortable>
|
2019-05-02 17:55:59 +09:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { defineComponent, defineAsyncComponent } from 'vue';
|
2019-05-02 17:55:59 +09:00
|
|
|
import XSection from './els/page-editor.el.section.vue';
|
|
|
|
import XText from './els/page-editor.el.text.vue';
|
|
|
|
import XTextarea from './els/page-editor.el.textarea.vue';
|
|
|
|
import XImage from './els/page-editor.el.image.vue';
|
|
|
|
import XButton from './els/page-editor.el.button.vue';
|
|
|
|
import XTextInput from './els/page-editor.el.text-input.vue';
|
|
|
|
import XTextareaInput from './els/page-editor.el.textarea-input.vue';
|
2019-05-05 15:12:25 +09:00
|
|
|
import XNumberInput from './els/page-editor.el.number-input.vue';
|
2019-05-02 17:55:59 +09:00
|
|
|
import XSwitch from './els/page-editor.el.switch.vue';
|
|
|
|
import XIf from './els/page-editor.el.if.vue';
|
|
|
|
import XPost from './els/page-editor.el.post.vue';
|
|
|
|
import XCounter from './els/page-editor.el.counter.vue';
|
2019-07-10 18:30:51 +09:00
|
|
|
import XRadioButton from './els/page-editor.el.radio-button.vue';
|
2020-04-16 00:39:21 +09:00
|
|
|
import XCanvas from './els/page-editor.el.canvas.vue';
|
2020-11-15 13:42:04 +09:00
|
|
|
import XNote from './els/page-editor.el.note.vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import * as os from '@/os';
|
2019-05-02 17:55:59 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2019-05-02 17:55:59 +09:00
|
|
|
components: {
|
2022-12-21 15:10:21 +09:00
|
|
|
Sortable: defineAsyncComponent(() => import('vuedraggable').then(x => x.default)),
|
2022-12-21 11:04:49 +09:00
|
|
|
XSection, XText, XImage, XButton, XTextarea, XTextInput, XTextareaInput, XNumberInput, XSwitch, XIf, XPost, XCounter, XRadioButton, XCanvas, XNote,
|
2019-05-02 17:55:59 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
2021-09-30 00:50:45 +09:00
|
|
|
modelValue: {
|
2019-05-02 17:55:59 +09:00
|
|
|
type: Array,
|
2022-12-21 11:04:49 +09:00
|
|
|
required: true,
|
2019-05-02 17:55:59 +09:00
|
|
|
},
|
2020-04-20 21:35:27 +09:00
|
|
|
hpml: {
|
2019-05-02 17:55:59 +09:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-09-30 00:50:45 +09:00
|
|
|
emits: ['update:modelValue'],
|
2020-12-05 12:50:09 +09:00
|
|
|
|
2019-05-02 17:55:59 +09:00
|
|
|
computed: {
|
2020-12-05 12:50:09 +09:00
|
|
|
blocks: {
|
|
|
|
get() {
|
2021-09-30 00:50:45 +09:00
|
|
|
return this.modelValue;
|
2020-12-05 12:50:09 +09:00
|
|
|
},
|
|
|
|
set(value) {
|
2021-09-30 00:50:45 +09:00
|
|
|
this.$emit('update:modelValue', value);
|
2022-12-21 11:04:49 +09:00
|
|
|
},
|
|
|
|
},
|
2019-05-02 17:55:59 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
updateItem(v) {
|
|
|
|
const i = this.blocks.findIndex(x => x.id === v.id);
|
|
|
|
const newValue = [
|
|
|
|
...this.blocks.slice(0, i),
|
|
|
|
v,
|
2022-12-21 11:04:49 +09:00
|
|
|
...this.blocks.slice(i + 1),
|
2019-05-02 17:55:59 +09:00
|
|
|
];
|
2021-09-30 00:50:45 +09:00
|
|
|
this.$emit('update:modelValue', newValue);
|
2019-05-02 17:55:59 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
removeItem(el) {
|
|
|
|
const i = this.blocks.findIndex(x => x.id === el.id);
|
|
|
|
const newValue = [
|
|
|
|
...this.blocks.slice(0, i),
|
2022-12-21 11:04:49 +09:00
|
|
|
...this.blocks.slice(i + 1),
|
2019-05-02 17:55:59 +09:00
|
|
|
];
|
2021-09-30 00:50:45 +09:00
|
|
|
this.$emit('update:modelValue', newValue);
|
2019-05-02 17:55:59 +09:00
|
|
|
},
|
2022-12-21 11:04:49 +09:00
|
|
|
},
|
2019-05-02 17:55:59 +09:00
|
|
|
});
|
|
|
|
</script>
|