2019-05-02 17:55:59 +09:00
|
|
|
<template>
|
2022-12-24 11:57:06 +09: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 12:50:09 +09:00
|
|
|
<template #item="{element}">
|
2022-12-24 11:57:06 +09: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 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 XImage from './els/page-editor.el.image.vue';
|
2020-11-15 13:42:04 +09:00
|
|
|
import XNote from './els/page-editor.el.note.vue';
|
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-24 11:57:06 +09:00
|
|
|
XSection, XText, XImage, 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
|
|
|
},
|
|
|
|
},
|
|
|
|
|
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
|
|
|
methods: {
|
|
|
|
updateItem(v) {
|
2022-12-24 11:57:06 +09:00
|
|
|
const i = this.modelValue.findIndex(x => x.id === v.id);
|
2019-05-02 17:55:59 +09:00
|
|
|
const newValue = [
|
2022-12-24 11:57:06 +09:00
|
|
|
...this.modelValue.slice(0, i),
|
2019-05-02 17:55:59 +09:00
|
|
|
v,
|
2022-12-24 11:57:06 +09:00
|
|
|
...this.modelValue.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) {
|
2022-12-24 11:57:06 +09:00
|
|
|
const i = this.modelValue.findIndex(x => x.id === el.id);
|
2019-05-02 17:55:59 +09:00
|
|
|
const newValue = [
|
2022-12-24 11:57:06 +09:00
|
|
|
...this.modelValue.slice(0, i),
|
|
|
|
...this.modelValue.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>
|
2022-12-24 11:57:06 +09:00
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.item {
|
|
|
|
& + .item {
|
|
|
|
margin-top: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|