|
1 | 1 | /*! |
2 | | - * he-tree-vue v2.0.1 |
| 2 | + * he-tree-vue v2.0.2-beta |
3 | 3 | * (c) phphe <phphe@outlook.com> (https://github.com/phphe) |
4 | 4 | * Homepage: https://he-tree-vue.phphe.com |
5 | 5 | * Released under the MIT License. |
|
2870 | 2870 | } |
2871 | 2871 |
|
2872 | 2872 | /*! |
2873 | | - * draggable-helper v5.0.1 |
| 2873 | + * draggable-helper v5.0.2 |
2874 | 2874 | * (c) phphe <phphe@outlook.com> (https://github.com/phphe) |
2875 | 2875 | * Homepage: undefined |
2876 | 2876 | * Released under the MIT License. |
|
2985 | 2985 | // 定义mousedown和touchstart事件监听器 |
2986 | 2986 |
|
2987 | 2987 | var onMousedownOrTouchStart = function onMousedownOrTouchStart(e, mouse) { |
| 2988 | + // execute native event hooks |
| 2989 | + if (!DragEventService.isTouch(e)) { |
| 2990 | + opt.onmousedown && opt.onmousedown(e); |
| 2991 | + } else { |
| 2992 | + opt.ontouchstart && opt.ontouchstart(e); |
| 2993 | + } |
| 2994 | + |
2988 | 2995 | var target = e.target; // check if triggered by ignore tags |
2989 | 2996 | // 检查是否由忽略的标签名触发 |
2990 | 2997 |
|
|
3098 | 3105 | if (!DragEventService.isTouch(e)) { |
3099 | 3106 | // Do not prevent when touch. Or the elements within the node can not trigger click event. |
3100 | 3107 | // 不要在触摸时阻止事件. 否则将导致节点内的元素不触发点击事件. |
3101 | | - e.preventDefault(); |
| 3108 | + if (opt.preventTextSelection) { |
| 3109 | + e.preventDefault(); |
| 3110 | + } |
3102 | 3111 | } // listen mousemove and touchmove |
3103 | 3112 | // 监听mousemove和touchmove |
3104 | 3113 |
|
|
3119 | 3128 | // 定义mousemove和touchmove事件监听器 |
3120 | 3129 |
|
3121 | 3130 | var onMousemoveOrTouchMove = function onMousemoveOrTouchMove(e, mouse) { |
| 3131 | + // execute native event hooks |
| 3132 | + if (!DragEventService.isTouch(e)) { |
| 3133 | + opt.onmousemove && opt.onmousemove(e); |
| 3134 | + } else { |
| 3135 | + opt.ontouchmove && opt.ontouchmove(e); |
| 3136 | + } // |
| 3137 | + |
| 3138 | + |
3122 | 3139 | var _store = store, |
3123 | 3140 | movedOrClonedElement = _store.movedOrClonedElement; // calc move and attach related info to store |
3124 | 3141 | // 计算move并附加相关信息到store |
|
3128 | 3145 | y: mouse.clientY - store.initialMouse.clientY |
3129 | 3146 | }; |
3130 | 3147 | store.moveEvent = e; |
3131 | | - store.mouse = mouse; // prevent text be selected. prevent page scroll when touch. |
3132 | | - // 阻止文字被选中. 当触摸时阻止屏幕被拖动. |
| 3148 | + store.mouse = mouse; |
3133 | 3149 |
|
3134 | | - e.preventDefault(); // first move |
| 3150 | + if (DragEventService.isTouch(e)) { |
| 3151 | + // prevent page scroll when touch. |
| 3152 | + // 当触摸时阻止屏幕被拖动. |
| 3153 | + e.preventDefault(); |
| 3154 | + } else { |
| 3155 | + // prevent text be selected |
| 3156 | + // 阻止文字被选中 |
| 3157 | + if (opt.preventTextSelection) { |
| 3158 | + e.preventDefault(); |
| 3159 | + } |
| 3160 | + } // first move |
3135 | 3161 | // 第一次移动 |
3136 | 3162 |
|
| 3163 | + |
3137 | 3164 | if (store.movedCount === 0) { |
3138 | 3165 | // check if min displacement exceeded. |
3139 | 3166 | // 检查是否达到最小位移 |
|
3154 | 3181 |
|
3155 | 3182 | store.movedOrClonedElement = movedOrClonedElement; |
3156 | 3183 | store.movedElement = movedElement; |
| 3184 | + store.initialPositionRelativeToViewport = initialPosition; |
3157 | 3185 | store.initialPosition = initialPosition; // define the function to update moved element style |
3158 | 3186 | // 定义更新移动元素样式的方法 |
3159 | 3187 |
|
|
3181 | 3209 |
|
3182 | 3210 | backupAttr(movedElement, 'class'); |
3183 | 3211 | addClass(movedElement, opt.draggingClassName); |
| 3212 | + /* |
| 3213 | + check if the changed position is expected and correct it. about stacking context. |
| 3214 | + 当某父元素使用了transform属性时, fixed不再以窗口左上角为坐标. 以下功能是在第一次移动后, 检查元素实际位置和期望位置是否相同, 不同则说明坐标系不是期望的. 则把初始位置减去偏移, 无论任何父元素导致了层叠上下文问题, 都能正确显示. |
| 3215 | + */ |
| 3216 | + |
| 3217 | + var nowPosition = getViewportPosition(movedElement); |
| 3218 | + |
| 3219 | + if (nowPosition.x !== initialPosition.x) { |
| 3220 | + initialPosition.x = initialPosition.x - (nowPosition.x - initialPosition.x); |
| 3221 | + initialPosition.y = initialPosition.y - (nowPosition.y - initialPosition.y); |
| 3222 | + movedElement.style.left = initialPosition.x + 'px'; |
| 3223 | + movedElement.style.top = initialPosition.y + 'px'; |
| 3224 | + } |
3184 | 3225 | }; |
3185 | 3226 |
|
3186 | 3227 | store.updateMovedElementStyle = updateMovedElementStyle; // call hook beforeFirstMove, beforeMove |
|
3233 | 3274 |
|
3234 | 3275 |
|
3235 | 3276 | var onMouseupOrTouchEnd = function onMouseupOrTouchEnd(e) { |
3236 | | - // cancel listening mousemove, touchmove, mouseup, touchend |
| 3277 | + // execute native event hooks |
| 3278 | + if (!DragEventService.isTouch(e)) { |
| 3279 | + opt.onmousedown && opt.onmousedown(e); |
| 3280 | + } else { |
| 3281 | + opt.ontouchend && opt.ontouchend(e); |
| 3282 | + } // cancel listening mousemove, touchmove, mouseup, touchend |
3237 | 3283 | // 取消监听事件mousemove, touchmove, mouseup, touchend |
| 3284 | + |
| 3285 | + |
3238 | 3286 | DragEventService.off(document, 'move', onMousemoveOrTouchMove, { |
3239 | 3287 | touchArgs: [{ |
3240 | 3288 | passive: false |
|
3303 | 3351 | draggingClassName: 'dragging', |
3304 | 3352 | clone: false, |
3305 | 3353 | updateMovedElementStyleManually: false, |
| 3354 | + preventTextSelection: true, |
3306 | 3355 | edgeScrollTriggerMargin: 50, |
3307 | 3356 | edgeScrollSpeed: 0.35, |
3308 | 3357 | edgeScrollTriggerMode: 'top_left_corner' |
|
3682 | 3731 | edgeScrollSpeed: options.edgeScrollSpeed, |
3683 | 3732 | edgeScrollTriggerMode: options.edgeScrollTriggerMode, |
3684 | 3733 | rtl: options.rtl, |
| 3734 | + preventTextSelection: options.preventTextSelection, |
3685 | 3735 | updateMovedElementStyleManually: true, |
3686 | 3736 | getMovedOrClonedElement: function getMovedOrClonedElement(directTriggerElement, store) { |
3687 | 3737 | // find closest branch from parents |
|
4618 | 4668 | edgeScrollTriggerMargin: options.edgeScrollTriggerMargin, |
4619 | 4669 | edgeScrollSpeed: options.edgeScrollSpeed, |
4620 | 4670 | edgeScrollTriggerMode: options.edgeScrollTriggerMode, |
4621 | | - rtl: options.rtl |
| 4671 | + // |
| 4672 | + rtl: options.rtl, |
| 4673 | + preventTextSelection: options.preventTextSelection |
4622 | 4674 | }); |
4623 | 4675 | } |
4624 | 4676 | } |
|
4691 | 4743 | edgeScrollTriggerMode: { |
4692 | 4744 | type: String, |
4693 | 4745 | default: 'top_left_corner' |
| 4746 | + }, |
| 4747 | + preventTextSelection: { |
| 4748 | + type: Boolean, |
| 4749 | + default: true |
4694 | 4750 | } |
4695 | 4751 | }, |
4696 | 4752 | // components: {}, |
|
4871 | 4927 | edgeScrollSpeed: this.edgeScrollSpeed, |
4872 | 4928 | edgeScrollTriggerMode: this.edgeScrollTriggerMode, |
4873 | 4929 | rtl: this.rtl, |
| 4930 | + preventTextSelection: this.preventTextSelection, |
4874 | 4931 | treeClass: 'he-tree', |
4875 | 4932 | rootClass: 'tree-root', |
4876 | 4933 | childrenClass: 'tree-children', |
|
5105 | 5162 | var _makeTreeDraggable_obj = this._makeTreeDraggable_obj = makeTreeDraggable(this.$el, options); // watch props and update options |
5106 | 5163 |
|
5107 | 5164 |
|
5108 | | - ['indent', 'triggerClass', 'triggerBySelf', 'unfoldWhenDragover', 'unfoldWhenDragoverDelay', 'draggingNodePositionMode', 'cloneWhenDrag', 'edgeScroll', 'edgeScrollTriggerMargin', 'edgeScrollSpeed', 'edgeScrollTriggerMode', 'rtl'].forEach(function (name) { |
| 5165 | + ['indent', 'triggerClass', 'triggerBySelf', 'unfoldWhenDragover', 'unfoldWhenDragoverDelay', 'draggingNodePositionMode', 'cloneWhenDrag', 'edgeScroll', 'edgeScrollTriggerMargin', 'edgeScrollSpeed', 'edgeScrollTriggerMode', 'rtl', 'preventTextSelection'].forEach(function (name) { |
5109 | 5166 | _this.$watch(name, function (value) { |
5110 | 5167 | _makeTreeDraggable_obj.options[name] = value; |
5111 | 5168 |
|
|
0 commit comments