88 </div >
99 <div
1010 v-if =" stampIdsModel.length !== 0"
11- ref =" stampListRef "
11+ ref =" containerRef "
1212 :class =" $style.stampList"
1313 >
1414 <!-- FIXME: スタンプの総数が多い時に重くなる -->
4343</template >
4444
4545<script lang="ts" setup>
46- import { nextTick , onMounted , onUnmounted , ref , watch } from ' vue'
47-
48- import Sortable , { type SortableEvent } from ' sortablejs'
46+ import { nextTick , ref , watch } from ' vue'
4947
5048import AStamp from ' /@/components/UI/AStamp.vue'
5149import IconButton from ' /@/components/UI/IconButton.vue'
50+ import { useSortable } from ' /@/composables/dom/useSortable'
5251import type { StampId } from ' /@/types/entity-ids'
5352
5453import StampPaletteEditorLimitIndicator from ' ./StampPaletteEditorLimitIndicator.vue'
@@ -73,41 +72,14 @@ const removeSelectedStamps = () => {
7372 selectedStampIds .value = []
7473}
7574
76- const stampListRef = ref <HTMLElement | null >(null )
77- let sortableInstance: Sortable | null = null
78-
79- const setupSortable = () => {
80- if (sortableInstance ) return
81- if (! stampListRef .value ) return
82- if (stampIdsModel .value .length === 0 ) return
83-
84- sortableInstance = Sortable .create (stampListRef .value , {
85- animation: 150 ,
86- draggable: ' .js-sortable-item' ,
87- onUpdate : (event : SortableEvent ) => {
88- if (
89- event .newDraggableIndex === undefined ||
90- event .oldDraggableIndex === undefined
91- )
92- return
93- const newStampIds = [... stampIdsModel .value ]
94- const movedStampId = newStampIds .splice (event .oldDraggableIndex , 1 )[0 ]
95- if (movedStampId === undefined ) return
96- newStampIds .splice (event .newDraggableIndex , 0 , movedStampId )
97- stampIdsModel .value = newStampIds
75+ const { containerRef, setupSortable, destroySortableInstance } = useSortable ({
76+ store: {
77+ set : sortable => {
78+ stampIdsModel .value = sortable .toArray ()
9879 }
99- })
100- }
101-
102- const destroySortableInstance = () => {
103- if (sortableInstance ) {
104- sortableInstance .destroy ()
105- sortableInstance = null
10680 }
107- }
81+ })
10882
109- onMounted (setupSortable )
110- onUnmounted (destroySortableInstance )
11183watch (
11284 () => stampIdsModel .value .length ,
11385 (newLength , oldLength ) => {
0 commit comments