Skip to content

Commit

Permalink
refactor: use closest to match handle and exclude options for `…
Browse files Browse the repository at this point in the history
…v-drag`
  • Loading branch information
xiaodemen authored and Justineo committed Nov 8, 2022
1 parent 694a448 commit 2defcde
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
1 change: 1 addition & 0 deletions packages/veui-theme-dls/components/tabs.less
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
&-item-status {
margin-left: @dls-tab-content-spacing;
cursor: pointer;
flex-shrink: 0;

.veui-tabs-status(@type) {
@color-name: ~"dls-foreground-color-@{type}-primary";
Expand Down
2 changes: 1 addition & 1 deletion packages/veui/src/components/Tabs/Tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default {
dragend: () => {
this.dragging = false
},
excludeHandle: `.${this.$c('tabs-item-remove')}`,
exclude: `.${this.$c('tabs-item-remove')}`,
sort: (fromIndex, toIndex) => {
const items = this.realItems.map((tab) => omit(tab, 'id'))
const item = items[fromIndex]
Expand Down
25 changes: 8 additions & 17 deletions packages/veui/src/directives/drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { isFirefox as checkIsFirefox } from '../utils/bom'
import BaseHandler from './drag/BaseHandler'
import TranslateHandler from './drag/TranslateHandler'
import SortHandler from './drag/SortHandler'
import { matches } from '../utils/dom'
import { closest } from '../utils/dom'

const isFirefox = checkIsFirefox()

Expand Down Expand Up @@ -121,14 +121,14 @@ function refresh (el, binding, vnode) {

prepareHandler (event) {
const evTarget = event.target
const { excludeHandle, handle, enableSelector } = options
const { exclude, handle, enableSelector } = options
let match = !enableSelector
if (enableSelector) {
match = matchesOrContainsSelector(evTarget, handle)
match = matchesSelectorInContainer(evTarget, handle, target)
}

if (match && excludeHandle && typeof excludeHandle === 'string') {
match = !matchesOrContainsSelector(evTarget, excludeHandle)
if (match && exclude && typeof exclude === 'string') {
match = !matchesSelectorInContainer(evTarget, exclude, target)
}

if (match) {
Expand Down Expand Up @@ -281,18 +281,9 @@ function isRect (containment) {
)
}

function matchesOrContainsSelector (el, selector) {
if (matches(el, selector)) {
return true
}
if (selector.indexOf('*') === -1) {
const realSelectors = selector
.split(',')
.map((selector) => `${selector} *`)
.join(',')
return matches(el, realSelectors)
}
return false
function matchesSelectorInContainer (el, selector, container) {
const matched = closest(el, selector)
return !!matched && container.contains(matched)
}

/**
Expand Down

1 comment on commit 2defcde

@vercel
Copy link

@vercel vercel bot commented on 2defcde Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

veui – ./

veui-demo.vercel.app
d20.veui.dev
veui-git-d20-ecomfe.vercel.app
veui-ecomfe.vercel.app

Please sign in to comment.