tdesign-vue
Version:
121 lines (115 loc) • 3.66 kB
JavaScript
/**
* tdesign v1.11.2
* (c) 2025 tdesign
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var tree_hooks_useDraggable = require('./useDraggable.js');
var tree_util = require('../util.js');
require('../../_chunks/dep-13309278.js');
require('../../_chunks/dep-f3761329.js');
require('../../_chunks/dep-a4cecac4.js');
require('@babel/runtime/helpers/typeof');
require('../../_chunks/dep-a4308f57.js');
require('../../_chunks/dep-848a5a32.js');
require('../../_chunks/dep-d3015b4c.js');
require('../../_chunks/dep-e4278c54.js');
require('@vue/composition-api');
require('@babel/runtime/helpers/defineProperty');
require('../../_chunks/dep-7c854ec6.js');
require('../../_chunks/dep-eceed11d.js');
require('../../_chunks/dep-201f7798.js');
require('../../_chunks/dep-fcf0662d.js');
require('../../_chunks/dep-f8a85d6a.js');
require('../../_chunks/dep-5b117689.js');
require('../../_chunks/dep-6478392e.js');
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
};
tree_util.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
};
tree_util.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
};
tree_util.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
};
tree_util.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 === tree_hooks_useDraggable.DragPosition.Inside) {
dragNode.appendTo(store, _node);
} else if (dropPosition === tree_hooks_useDraggable.DragPosition.Before) {
node.insertBefore(dragNode);
} else {
node.insertAfter(dragNode);
}
return true;
}
return false;
});
tree_util.emitEvent(props, context, "drop", ctx);
};
var drag = {
handleDragStart: handleDragStart,
handleDragEnd: handleDragEnd,
handleDragOver: handleDragOver,
handleDragLeave: handleDragLeave,
handleDrop: handleDrop
};
scope.drag = drag;
return {
drag: drag
};
}
exports["default"] = useDragHandle;
//# sourceMappingURL=useDragHandle.js.map