2019-05-02 10:55:59 +02:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<XDraggable
|
|
|
|
v-model="blocks"
|
|
|
|
tag="div"
|
|
|
|
item-key="id"
|
|
|
|
handle=".drag-handle"
|
|
|
|
:group="{ name: 'blocks' }"
|
|
|
|
animation="150"
|
|
|
|
swap-threshold="0.5"
|
|
|
|
>
|
|
|
|
<template #item="{ element }">
|
|
|
|
<component
|
|
|
|
:is="'x-' + element.type"
|
|
|
|
:value="element"
|
|
|
|
:hpml="hpml"
|
|
|
|
@update:value="updateItem"
|
|
|
|
@remove="() => removeItem(element)"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</XDraggable>
|
2019-05-02 10:55:59 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-04-08 02:01:42 +02:00
|
|
|
import { defineComponent, defineAsyncComponent } from "vue";
|
|
|
|
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";
|
|
|
|
import XNumberInput from "./els/page-editor.el.number-input.vue";
|
|
|
|
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";
|
|
|
|
import XRadioButton from "./els/page-editor.el.radio-button.vue";
|
|
|
|
import XCanvas from "./els/page-editor.el.canvas.vue";
|
|
|
|
import XNote from "./els/page-editor.el.note.vue";
|
|
|
|
import * as os from "@/os";
|
2019-05-02 10:55:59 +02:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
export default defineComponent({
|
2019-05-02 10:55:59 +02:00
|
|
|
components: {
|
2023-04-08 02:01:42 +02:00
|
|
|
XDraggable: defineAsyncComponent(() =>
|
|
|
|
import("vuedraggable").then((x) => x.default)
|
|
|
|
),
|
|
|
|
XSection,
|
|
|
|
XText,
|
|
|
|
XImage,
|
|
|
|
XButton,
|
|
|
|
XTextarea,
|
|
|
|
XTextInput,
|
|
|
|
XTextareaInput,
|
|
|
|
XNumberInput,
|
|
|
|
XSwitch,
|
|
|
|
XIf,
|
|
|
|
XPost,
|
|
|
|
XCounter,
|
|
|
|
XRadioButton,
|
|
|
|
XCanvas,
|
|
|
|
XNote,
|
2019-05-02 10:55:59 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
2021-09-29 17:50:45 +02:00
|
|
|
modelValue: {
|
2019-05-02 10:55:59 +02:00
|
|
|
type: Array,
|
2023-04-08 02:01:42 +02:00
|
|
|
required: true,
|
2019-05-02 10:55:59 +02:00
|
|
|
},
|
2020-04-20 14:35:27 +02:00
|
|
|
hpml: {
|
2019-05-02 10:55:59 +02:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
emits: ["update:modelValue"],
|
2020-12-05 04:50:09 +01:00
|
|
|
|
2019-05-02 10:55:59 +02:00
|
|
|
computed: {
|
2020-12-05 04:50:09 +01:00
|
|
|
blocks: {
|
|
|
|
get() {
|
2021-09-29 17:50:45 +02:00
|
|
|
return this.modelValue;
|
2020-12-05 04:50:09 +01:00
|
|
|
},
|
|
|
|
set(value) {
|
2023-04-08 02:01:42 +02:00
|
|
|
this.$emit("update:modelValue", value);
|
|
|
|
},
|
|
|
|
},
|
2019-05-02 10:55:59 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
updateItem(v) {
|
2023-04-08 02:01:42 +02:00
|
|
|
const i = this.blocks.findIndex((x) => x.id === v.id);
|
2019-05-02 10:55:59 +02:00
|
|
|
const newValue = [
|
|
|
|
...this.blocks.slice(0, i),
|
|
|
|
v,
|
2023-04-08 02:01:42 +02:00
|
|
|
...this.blocks.slice(i + 1),
|
2019-05-02 10:55:59 +02:00
|
|
|
];
|
2023-04-08 02:01:42 +02:00
|
|
|
this.$emit("update:modelValue", newValue);
|
2019-05-02 10:55:59 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
removeItem(el) {
|
2023-04-08 02:01:42 +02:00
|
|
|
const i = this.blocks.findIndex((x) => x.id === el.id);
|
2019-05-02 10:55:59 +02:00
|
|
|
const newValue = [
|
|
|
|
...this.blocks.slice(0, i),
|
2023-04-08 02:01:42 +02:00
|
|
|
...this.blocks.slice(i + 1),
|
2019-05-02 10:55:59 +02:00
|
|
|
];
|
2023-04-08 02:01:42 +02:00
|
|
|
this.$emit("update:modelValue", newValue);
|
2019-05-02 10:55:59 +02:00
|
|
|
},
|
2023-04-08 02:01:42 +02:00
|
|
|
},
|
2019-05-02 10:55:59 +02:00
|
|
|
});
|
|
|
|
</script>
|