35 lines
772 B
TypeScript
35 lines
772 B
TypeScript
import { create } from 'zustand'
|
|
|
|
export interface DragState {
|
|
draggedPath: string | null
|
|
draggedType: 'file' | 'dir' | null
|
|
dropTargetPath: string | null
|
|
}
|
|
|
|
interface DragStore {
|
|
state: DragState
|
|
setState: (state: DragState) => void
|
|
isDraggedInsidePath: (checkPath: string) => boolean
|
|
}
|
|
|
|
const initialState: DragState = {
|
|
draggedPath: null,
|
|
draggedType: null,
|
|
dropTargetPath: null
|
|
}
|
|
|
|
export const useDragStore = create<DragStore>((set, get) => ({
|
|
state: initialState,
|
|
|
|
setState: (state) => set({ state }),
|
|
|
|
isDraggedInsidePath: (checkPath) => {
|
|
const { state } = get()
|
|
if (!state.draggedPath) return false
|
|
if (state.draggedType === 'dir') {
|
|
return checkPath.startsWith(`${state.draggedPath}/`)
|
|
}
|
|
return false
|
|
}
|
|
}))
|