UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

73 lines (69 loc) 2.36 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ import { ref, getCurrentInstance, provide } from 'vue'; import { dragInjectKey } from '../constants.js'; import '../../hooks/useConfig.js'; import '../../config-provider/useConfig.js'; import 'lodash/isFunction'; import 'lodash/cloneDeep'; import 'lodash/isString'; import '../../config-provider/context.js'; import 'lodash/mergeWith'; import 'lodash/merge'; import '../../_common/js/global-config/default-config.js'; import '../../_common/js/global-config/locale/en_US.js'; import '../../_chunks/dep-3a1cce9f.js'; import 'lodash/isArray'; function useOnDrag(treeStore) { var dragNode = ref(); var _getCurrentInstance = getCurrentInstance(), emit = _getCurrentInstance.emit; var onDragStart = function onDragStart(context) { dragNode.value = context.node; emit === null || emit === void 0 ? void 0 : emit("dragStart", context); }; var onDragEnd = function onDragEnd(context) { dragNode.value = context.node; emit === null || emit === void 0 ? void 0 : emit("dragEnd", context); }; var onDragOver = function onDragOver(context) { emit === null || emit === void 0 ? void 0 : emit("dragOver", context); }; var onDragLeave = function onDragLeave(context) { emit === null || emit === void 0 ? void 0 : emit("dragLeave", context); }; var onDrop = function onDrop(context) { var node = context.node, dropPosition = context.dropPosition; if (node.value === dragNode.value.value || node.getParents().some(function (_node) { return _node.value === dragNode.value.value; })) return; var nodes = treeStore.value.getNodes(); nodes.some(function (_node, _index) { if (_node.value === node.value) { if (dropPosition === 0) { dragNode.value.appendTo(treeStore.value, _node); } else if (dropPosition < 0) { node.insertBefore(dragNode.value); } else { node.insertAfter(dragNode.value); } return true; } return false; }); emit === null || emit === void 0 ? void 0 : emit("drop", context); }; provide(dragInjectKey, { onDragStart: onDragStart, onDragEnd: onDragEnd, onDragOver: onDragOver, onDragLeave: onDragLeave, onDrop: onDrop }); } export { useOnDrag as default }; //# sourceMappingURL=useOnDrag.js.map