2019-05-02 08:55:59 +00:00
|
|
|
<template>
|
2022-12-24 02:57:06 +00: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 03:50:09 +00:00
|
|
|
<template #item="{element}">
|
2022-12-24 02:57:06 +00: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 03:50:09 +00:00
|
|
|
</template>
|
2022-12-21 02:04:49 +00:00
|
|
|
</Sortable>
|
2019-05-02 08:55:59 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 11:12:00 +00:00
|
|
|
import { defineComponent, defineAsyncComponent } from 'vue';
|
2019-05-02 08:55:59 +00: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 04:42:04 +00:00
|
|
|
import XNote from './els/page-editor.el.note.vue';
|
2021-11-11 17:02:25 +00:00
|
|
|
import * as os from '@/os';
|
2022-12-24 02:57:06 +00:00
|
|
|
import { deepClone } from '@/scripts/clone';
|
2019-05-02 08:55:59 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
export default defineComponent({
|
2019-05-02 08:55:59 +00:00
|
|
|
components: {
|
2022-12-21 06:10:21 +00:00
|
|
|
Sortable: defineAsyncComponent(() => import('vuedraggable').then(x => x.default)),
|
2022-12-24 02:57:06 +00:00
|
|
|
XSection, XText, XImage, XNote,
|
2019-05-02 08:55:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
2021-09-29 15:50:45 +00:00
|
|
|
modelValue: {
|
2019-05-02 08:55:59 +00:00
|
|
|
type: Array,
|
2022-12-21 02:04:49 +00:00
|
|
|
required: true,
|
2019-05-02 08:55:59 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-09-29 15:50:45 +00:00
|
|
|
emits: ['update:modelValue'],
|
2020-12-05 03:50:09 +00:00
|
|
|
|
2019-05-02 08:55:59 +00:00
|
|
|
methods: {
|
|
|
|
updateItem(v) {
|
2022-12-24 02:57:06 +00:00
|
|
|
const i = this.modelValue.findIndex(x => x.id === v.id);
|
2019-05-02 08:55:59 +00:00
|
|
|
const newValue = [
|
2022-12-24 02:57:06 +00:00
|
|
|
...this.modelValue.slice(0, i),
|
2019-05-02 08:55:59 +00:00
|
|
|
v,
|
2022-12-24 02:57:06 +00:00
|
|
|
...this.modelValue.slice(i + 1),
|
2019-05-02 08:55:59 +00:00
|
|
|
];
|
2021-09-29 15:50:45 +00:00
|
|
|
this.$emit('update:modelValue', newValue);
|
2019-05-02 08:55:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
removeItem(el) {
|
2022-12-24 02:57:06 +00:00
|
|
|
const i = this.modelValue.findIndex(x => x.id === el.id);
|
2019-05-02 08:55:59 +00:00
|
|
|
const newValue = [
|
2022-12-24 02:57:06 +00:00
|
|
|
...this.modelValue.slice(0, i),
|
|
|
|
...this.modelValue.slice(i + 1),
|
2019-05-02 08:55:59 +00:00
|
|
|
];
|
2021-09-29 15:50:45 +00:00
|
|
|
this.$emit('update:modelValue', newValue);
|
2019-05-02 08:55:59 +00:00
|
|
|
},
|
2022-12-21 02:04:49 +00:00
|
|
|
},
|
2019-05-02 08:55:59 +00:00
|
|
|
});
|
|
|
|
</script>
|
2022-12-24 02:57:06 +00:00
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.item {
|
|
|
|
& + .item {
|
|
|
|
margin-top: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|