UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

77 lines (71 loc) 2.46 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var tree_constants = require('../constants.js'); require('../../hooks/useConfig.js'); require('../../config-provider/useConfig.js'); require('lodash/isFunction'); require('lodash/cloneDeep'); require('lodash/isString'); require('../../config-provider/context.js'); require('lodash/mergeWith'); require('lodash/merge'); require('../../_common/js/global-config/default-config.js'); require('../../_common/js/global-config/locale/en_US.js'); require('../../_chunks/dep-8d10b59f.js'); require('lodash/isArray'); function useOnDrag(treeStore) { var dragNode = vue.ref(); var _getCurrentInstance = vue.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); }; vue.provide(tree_constants.dragInjectKey, { onDragStart: onDragStart, onDragEnd: onDragEnd, onDragOver: onDragOver, onDragLeave: onDragLeave, onDrop: onDrop }); } exports["default"] = useOnDrag; //# sourceMappingURL=useOnDrag.js.map