tdesign-vue
Version:
103 lines (99 loc) • 2.87 kB
JavaScript
/**
* tdesign v1.12.1
* (c) 2025 tdesign
* @license MIT
*/
import { DragPosition } from './useDraggable.js';
import { emitEvent } from '../util.js';
import 'lodash-es';
import '@vue/composition-api';
import '@babel/runtime/helpers/defineProperty';
function useDragHandle(state) {
var props = state.props,
context = state.context,
scope = state.scope,
store = state.store;
var dragNode = null;
var handleDragStart = function handleDragStart(state2) {
var dragEvent = state2.dragEvent,
node = state2.node;
dragNode = node;
var ctx = {
node: node.getModel(),
e: dragEvent
};
emitEvent(props, context, "drag-start", ctx);
};
var handleDragEnd = function handleDragEnd(state2) {
var dragEvent = state2.dragEvent,
node = state2.node;
dragNode = node;
var ctx = {
node: node.getModel(),
e: dragEvent
};
emitEvent(props, context, "drag-end", ctx);
};
var handleDragOver = function handleDragOver(state2) {
var dragEvent = state2.dragEvent,
node = state2.node;
var ctx = {
node: node.getModel(),
e: dragEvent
};
emitEvent(props, context, "drag-over", ctx);
};
var handleDragLeave = function handleDragLeave(state2) {
var dragEvent = state2.dragEvent,
node = state2.node;
var ctx = {
node: node.getModel(),
e: dragEvent
};
emitEvent(props, context, "drag-leave", ctx);
};
var handleDrop = function handleDrop(state2) {
var _props$allowDrop;
var dragEvent = state2.dragEvent,
node = state2.node,
dropPosition = state2.dropPosition;
if (node.value === dragNode.value || node.getParents().some(function (_node) {
return _node.value === dragNode.value;
})) return;
var ctx = {
dropNode: node.getModel(),
dragNode: dragNode.getModel(),
dropPosition: dropPosition,
e: dragEvent
};
if (((_props$allowDrop = props.allowDrop) === null || _props$allowDrop === void 0 ? void 0 : _props$allowDrop.call(props, ctx)) === false) return;
var nodes = store.getNodes();
nodes.some(function (_node) {
if (_node.value === node.value) {
if (dropPosition === DragPosition.Inside) {
dragNode.appendTo(store, _node);
} else if (dropPosition === DragPosition.Before) {
node.insertBefore(dragNode);
} else {
node.insertAfter(dragNode);
}
return true;
}
return false;
});
emitEvent(props, context, "drop", ctx);
};
var drag = {
handleDragStart: handleDragStart,
handleDragEnd: handleDragEnd,
handleDragOver: handleDragOver,
handleDragLeave: handleDragLeave,
handleDrop: handleDrop
};
scope.drag = drag;
return {
drag: drag
};
}
export { useDragHandle as default };
//# sourceMappingURL=useDragHandle.js.map