2019-05-02 10:55:59 +02:00
|
|
|
<template>
|
2022-12-24 03:57:06 +01:00
|
|
|
<Sortable :model-value="modelValue" tag="div" item-key="id" handle=".drag-handle" :group="{ name: 'blocks' }" :animation="150" :swap-threshold="0.5" @update:model-value="v => $emit('update:modelValue', v)">
|
2020-12-05 04:50:09 +01:00
|
|
|
<template #item="{element}">
|
2022-12-24 03:57:06 +01:00
|
|
|
<div :class="$style.item">
|
|
|
|
<!-- divが無いとエラーになる https://github.com/SortableJS/vue.draggable.next/issues/189 -->
|
|
|
|
<component :is="'x-' + element.type" :model-value="element" @update:model-value="updateItem" @remove="() => removeItem(element)"/>
|
|
|
|
</div>
|
2020-12-05 04:50:09 +01:00
|
|
|
</template>
|
2022-12-21 03:04:49 +01:00
|
|
|
</Sortable>
|
2019-05-02 10:55:59 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 13:12:00 +02:00
|
|
|
import { defineComponent, defineAsyncComponent } from 'vue';
|
2019-05-02 10:55:59 +02:00
|
|
|
import XSection from './els/page-editor.el.section.vue';
|
|
|
|
import XText from './els/page-editor.el.text.vue';
|
|
|
|
import XImage from './els/page-editor.el.image.vue';
|
2020-11-15 05:42:04 +01:00
|
|
|
import XNote from './els/page-editor.el.note.vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import * as os from '@/os';
|
2022-12-24 03:57:06 +01:00
|
|
|
import { deepClone } from '@/scripts/clone';
|
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: {
|
2022-12-21 07:10:21 +01:00
|
|
|
Sortable: defineAsyncComponent(() => import('vuedraggable').then(x => x.default)),
|
2022-12-24 03:57:06 +01:00
|
|
|
XSection, XText, XImage, 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,
|
2022-12-21 03:04:49 +01:00
|
|
|
required: true,
|
2019-05-02 10:55:59 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-09-29 17:50:45 +02:00
|
|
|
emits: ['update:modelValue'],
|
2020-12-05 04:50:09 +01:00
|
|
|
|
2019-05-02 10:55:59 +02:00
|
|
|
methods: {
|
|
|
|
updateItem(v) {
|
2022-12-24 03:57:06 +01:00
|
|
|
const i = this.modelValue.findIndex(x => x.id === v.id);
|
2019-05-02 10:55:59 +02:00
|
|
|
const newValue = [
|
2022-12-24 03:57:06 +01:00
|
|
|
...this.modelValue.slice(0, i),
|
2019-05-02 10:55:59 +02:00
|
|
|
v,
|
2022-12-24 03:57:06 +01:00
|
|
|
...this.modelValue.slice(i + 1),
|
2019-05-02 10:55:59 +02:00
|
|
|
];
|
2021-09-29 17:50:45 +02:00
|
|
|
this.$emit('update:modelValue', newValue);
|
2019-05-02 10:55:59 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
removeItem(el) {
|
2022-12-24 03:57:06 +01:00
|
|
|
const i = this.modelValue.findIndex(x => x.id === el.id);
|
2019-05-02 10:55:59 +02:00
|
|
|
const newValue = [
|
2022-12-24 03:57:06 +01:00
|
|
|
...this.modelValue.slice(0, i),
|
|
|
|
...this.modelValue.slice(i + 1),
|
2019-05-02 10:55:59 +02:00
|
|
|
];
|
2021-09-29 17:50:45 +02:00
|
|
|
this.$emit('update:modelValue', newValue);
|
2019-05-02 10:55:59 +02:00
|
|
|
},
|
2022-12-21 03:04:49 +01:00
|
|
|
},
|
2019-05-02 10:55:59 +02:00
|
|
|
});
|
|
|
|
</script>
|
2022-12-24 03:57:06 +01:00
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.item {
|
|
|
|
& + .item {
|
|
|
|
margin-top: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|