mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-12 12:25:16 +08:00
refactor(scrollbar): use evtd to handle events
This commit is contained in:
parent
50ec676e2d
commit
9673ad94cd
@ -1,4 +1,5 @@
|
|||||||
import { KEY_CODE } from '../dom/key-code'
|
import { KEY_CODE } from '../dom/key-code'
|
||||||
|
import { on } from 'evtd'
|
||||||
|
|
||||||
class KeyboardDelegate {
|
class KeyboardDelegate {
|
||||||
constructor () {
|
constructor () {
|
||||||
@ -6,7 +7,7 @@ class KeyboardDelegate {
|
|||||||
this.ctrlPressed = false
|
this.ctrlPressed = false
|
||||||
this.commandPressed = false
|
this.commandPressed = false
|
||||||
this.handlerInfoList = []
|
this.handlerInfoList = []
|
||||||
window.addEventListener('keydown', e => {
|
on('keydown', window, e => {
|
||||||
switch (e.keyCode) {
|
switch (e.keyCode) {
|
||||||
case KEY_CODE.SHIFT:
|
case KEY_CODE.SHIFT:
|
||||||
this.shiftPressed = true
|
this.shiftPressed = true
|
||||||
@ -32,7 +33,7 @@ class KeyboardDelegate {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
window.addEventListener('keyup', e => {
|
on('keyup', window, e => {
|
||||||
switch (e.keyCode) {
|
switch (e.keyCode) {
|
||||||
case KEY_CODE.SHIFT:
|
case KEY_CODE.SHIFT:
|
||||||
this.shiftPressed = false
|
this.shiftPressed = false
|
||||||
|
@ -189,8 +189,8 @@ export default {
|
|||||||
keyboardDelegate.registerHandler(KEY_CODE.LEFT, 'keydown', this.handleKeyDownLeft, {
|
keyboardDelegate.registerHandler(KEY_CODE.LEFT, 'keydown', this.handleKeyDownLeft, {
|
||||||
preventDefault: true
|
preventDefault: true
|
||||||
})
|
})
|
||||||
keyboardDelegate.registerHandler(KEY_CODE.ENTER, 'keyup', this.handleKeyUpEnter)
|
|
||||||
keyboardDelegate.registerHandler(KEY_CODE.ESC, 'keydown', this.handleKeyDownEsc)
|
keyboardDelegate.registerHandler(KEY_CODE.ESC, 'keydown', this.handleKeyDownEsc)
|
||||||
|
keyboardDelegate.registerHandler(KEY_CODE.ENTER, 'keyup', this.handleKeyUpEnter)
|
||||||
},
|
},
|
||||||
unregisterKeyboardOperations () {
|
unregisterKeyboardOperations () {
|
||||||
if (!this.keyboardHandlerRegistered) return
|
if (!this.keyboardHandlerRegistered) return
|
||||||
|
@ -100,6 +100,10 @@
|
|||||||
import {
|
import {
|
||||||
ref
|
ref
|
||||||
} from 'vue'
|
} from 'vue'
|
||||||
|
import {
|
||||||
|
on,
|
||||||
|
off
|
||||||
|
} from 'evtd'
|
||||||
import {
|
import {
|
||||||
VResizeObserver
|
VResizeObserver
|
||||||
} from 'vueuc'
|
} from 'vueuc'
|
||||||
@ -255,8 +259,8 @@ export default {
|
|||||||
beforeUnmount () {
|
beforeUnmount () {
|
||||||
window.clearTimeout(this.xBarVanishTimerId)
|
window.clearTimeout(this.xBarVanishTimerId)
|
||||||
window.clearTimeout(this.yBarVanishTimerId)
|
window.clearTimeout(this.yBarVanishTimerId)
|
||||||
window.removeEventListener('mousemove', this.handleYScrollMouseMove, true)
|
off('mousemove', window, this.handleYScrollMouseMove, true)
|
||||||
window.removeEventListener('mouseup', this.handleYScrollMouseUp, true)
|
off('mouseup', window, this.handleYScrollMouseUp, true)
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
// if container exist, it always can't be resolved when scrollbar is mounted
|
// if container exist, it always can't be resolved when scrollbar is mounted
|
||||||
@ -431,8 +435,8 @@ export default {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
this.xBarPressed = true
|
this.xBarPressed = true
|
||||||
window.addEventListener('mousemove', this.handleXScrollMouseMove)
|
on('mousemove', window, this.handleXScrollMouseMove, true)
|
||||||
window.addEventListener('mouseup', this.handleXScrollMouseUp)
|
on('mouseup', window, this.handleXScrollMouseUp, true)
|
||||||
this.memoXLeft = this.containerScrollLeft
|
this.memoXLeft = this.containerScrollLeft
|
||||||
this.memoMouseX = e.clientX
|
this.memoMouseX = e.clientX
|
||||||
},
|
},
|
||||||
@ -451,8 +455,8 @@ export default {
|
|||||||
handleXScrollMouseUp (e) {
|
handleXScrollMouseUp (e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
window.removeEventListener('mousemove', this.handleXScrollMouseMove)
|
off('mousemove', window, this.handleXScrollMouseMove, true)
|
||||||
window.removeEventListener('mouseup', this.handleXScrollMouseUp)
|
off('mouseup', window, this.handleXScrollMouseUp, true)
|
||||||
this.xBarPressed = false
|
this.xBarPressed = false
|
||||||
this.sync()
|
this.sync()
|
||||||
if (!this.mergedContainerRef().contains(e.target)) {
|
if (!this.mergedContainerRef().contains(e.target)) {
|
||||||
@ -463,8 +467,8 @@ export default {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
this.yBarPressed = true
|
this.yBarPressed = true
|
||||||
window.addEventListener('mousemove', this.handleYScrollMouseMove, true)
|
on('mousemove', window, this.handleYScrollMouseMove, true)
|
||||||
window.addEventListener('mouseup', this.handleYScrollMouseUp, true)
|
on('mouseup', window, this.handleYScrollMouseUp, true)
|
||||||
this.memoYTop = this.containerScrollTop
|
this.memoYTop = this.containerScrollTop
|
||||||
this.memoMouseY = e.clientY
|
this.memoMouseY = e.clientY
|
||||||
},
|
},
|
||||||
@ -487,8 +491,8 @@ export default {
|
|||||||
onScrollEnd
|
onScrollEnd
|
||||||
} = this
|
} = this
|
||||||
if (onScrollEnd) onScrollEnd()
|
if (onScrollEnd) onScrollEnd()
|
||||||
window.removeEventListener('mousemove', this.handleYScrollMouseMove, true)
|
off('mousemove', window, this.handleYScrollMouseMove, true)
|
||||||
window.removeEventListener('mouseup', this.handleYScrollMouseUp, true)
|
off('mouseup', window, this.handleYScrollMouseUp, true)
|
||||||
this.yBarPressed = false
|
this.yBarPressed = false
|
||||||
this.sync()
|
this.sync()
|
||||||
if (!this.mergedContainerRef().contains(e.target)) {
|
if (!this.mergedContainerRef().contains(e.target)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user