vue3-dnd
Version:
Drag and Drop for Vue Composition API
30 lines (29 loc) • 1.21 kB
JavaScript
import { useRegisteredDragSource } from "./useRegisteredDragSource";
import { useOptionalFactory } from "../useOptionalFactory";
import { useDragSourceMonitor } from "./useDragSourceMonitor";
import { useDragSourceConnector } from "./useDragSourceConnector";
import { useCollectedProps } from "../useCollectedProps";
import { useConnectDragPreview, useConnectDragSource } from "./connectors";
import { computed, unref } from "vue-demi";
/**
* useDragSource hook
* @param specArg The drag source specification (object or function, function preferred)
*/ export function useDrag(specArg) {
var spec = useOptionalFactory(specArg);
var monitor = useDragSourceMonitor();
var connector = useDragSourceConnector(computed(function() {
return unref(spec).options;
}), computed(function() {
return unref(spec).previewOptions;
}));
useRegisteredDragSource(spec, monitor, connector);
return [
useCollectedProps(computed(function() {
return unref(spec).collect || function() {
return {};
};
}), monitor, connector),
useConnectDragSource(connector, spec),
useConnectDragPreview(connector, spec),
];
}