mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-05 05:50:04 +08:00
refactor: migrate to @dnd-kit/react and simplify sortable components (#7819)
* refactor: migrate to @dnd-kit/react and simplify sortable components * chore: enable css formatting in biome.json * refactor(profile): simplify icon rendering logic and add alt text * style(profiles): add overflow hidden to profile grid container * refactor(profile): add radix for parseInt and improve type safety in profiles * docs: update changelog with drag-and-drop styling improvements * refactor(profile): move hasValidName function out of ProxiesEditorViewer * refactor(proxy): refactor proxy chain into sortable components * feat(proxy): add drop state styling and arrow animations to proxy chain * style(profiles): reduce horizontal padding in profile grid * feat(profile): add vertical margin to editor viewer items * chore: refresh pnpm lockfile * fix: preserve drag and drop behavior --------- Co-authored-by: Tunglies <77394545+Tunglies@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { DragEndEvent } from '@dnd-kit/core'
|
||||
import { arrayMove } from '@dnd-kit/sortable'
|
||||
import { arrayMove } from '@dnd-kit/helpers'
|
||||
import type { DragEndEvent } from '@dnd-kit/react'
|
||||
import { isSortable } from '@dnd-kit/react/sortable'
|
||||
import { useCallback, useEffect, useMemo, useReducer } from 'react'
|
||||
|
||||
type MenuOrderAction = { type: 'sync'; payload: string[] }
|
||||
@@ -92,21 +93,26 @@ export const useNavMenuOrder = <T extends { path: string }>({
|
||||
if (!enabled) {
|
||||
return
|
||||
}
|
||||
const { operation, canceled } = event
|
||||
const { source, target } = operation
|
||||
|
||||
const { active, over } = event
|
||||
if (!over || active.id === over.id) {
|
||||
if (canceled || !target || !isSortable(source)) return
|
||||
|
||||
const { index: newIndex, initialIndex: oldIndex } = source.sortable
|
||||
if (
|
||||
oldIndex < 0 ||
|
||||
newIndex < 0 ||
|
||||
oldIndex >= menuOrder.length ||
|
||||
newIndex >= menuOrder.length ||
|
||||
oldIndex === newIndex
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const activeId = String(active.id)
|
||||
const overId = String(over.id)
|
||||
const activeId = menuOrder[oldIndex]
|
||||
const overId = menuOrder[newIndex]
|
||||
|
||||
const oldIndex = menuOrder.indexOf(activeId)
|
||||
const newIndex = menuOrder.indexOf(overId)
|
||||
|
||||
if (oldIndex === -1 || newIndex === -1) {
|
||||
return
|
||||
}
|
||||
if (activeId == null || overId == null || activeId === overId) return
|
||||
|
||||
const previousOrder = [...menuOrder]
|
||||
const nextOrder = arrayMove(menuOrder, oldIndex, newIndex)
|
||||
|
||||
Reference in New Issue
Block a user