chore: use licia pointerEvent

This commit is contained in:
redhoodsu
2024-09-20 16:12:03 +08:00
parent ce3f6aef38
commit 27b85b4834
4 changed files with 14 additions and 40 deletions

View File

@@ -61,7 +61,7 @@
"karma-jquery": "^0.2.4", "karma-jquery": "^0.2.4",
"karma-sourcemap-loader": "^0.3.7", "karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^5.0.0", "karma-webpack": "^5.0.0",
"licia": "^1.41.0", "licia": "^1.42.0",
"luna-box-model": "^1.0.0", "luna-box-model": "^1.0.0",
"luna-console": "^1.3.4", "luna-console": "^1.3.4",
"luna-data-grid": "^0.6.0", "luna-data-grid": "^0.6.0",

View File

@@ -15,6 +15,7 @@ import extend from 'licia/extend'
import isStr from 'licia/isStr' import isStr from 'licia/isStr'
import startWith from 'licia/startWith' import startWith from 'licia/startWith'
import ready from 'licia/ready' import ready from 'licia/ready'
import pointerEvent from 'licia/pointerEvent'
import evalCss from '../lib/evalCss' import evalCss from '../lib/evalCss'
import emitter from '../lib/emitter' import emitter from '../lib/emitter'
import { isDarkTheme } from '../lib/themes' import { isDarkTheme } from '../lib/themes'
@@ -23,7 +24,6 @@ import LunaModal from 'luna-modal'
import LunaTab from 'luna-tab' import LunaTab from 'luna-tab'
import { import {
classPrefix as c, classPrefix as c,
drag,
eventClient, eventClient,
hasSafeArea, hasSafeArea,
safeStorage, safeStorage,
@@ -358,8 +358,8 @@ export default class DevTools extends Emitter {
$resizer.css('height', '100%') $resizer.css('height', '100%')
$document.on(drag('move'), moveListener) $document.on(pointerEvent('move'), moveListener)
$document.on(drag('end'), endListener) $document.on(pointerEvent('up'), endListener)
} }
const moveListener = (e) => { const moveListener = (e) => {
if (!this._isResizing) { if (!this._isResizing) {
@@ -385,11 +385,11 @@ export default class DevTools extends Emitter {
$resizer.css('height', 10) $resizer.css('height', 10)
$document.off(drag('move'), moveListener) $document.off(pointerEvent('move'), moveListener)
$document.off(drag('end'), endListener) $document.off(pointerEvent('up'), endListener)
} }
$resizer.css('height', 10) $resizer.css('height', 10)
$resizer.on(drag('start'), startListener) $resizer.on(pointerEvent('down'), startListener)
$navBar.on('contextmenu', (e) => e.preventDefault()) $navBar.on('contextmenu', (e) => e.preventDefault())
this.$container.on('click', (e) => e.stopPropagation()) this.$container.on('click', (e) => e.stopPropagation())

View File

@@ -4,7 +4,8 @@ import Emitter from 'licia/Emitter'
import $ from 'licia/$' import $ from 'licia/$'
import nextTick from 'licia/nextTick' import nextTick from 'licia/nextTick'
import orientation from 'licia/orientation' import orientation from 'licia/orientation'
import { pxToNum, classPrefix as c, drag, eventClient } from '../lib/util' import pointerEvent from 'licia/pointerEvent'
import { pxToNum, classPrefix as c, eventClient } from '../lib/util'
import evalCss from '../lib/evalCss' import evalCss from '../lib/evalCss'
const $document = $(document) const $document = $(document)
@@ -93,8 +94,8 @@ export default class EntryBtn extends Emitter {
this._oldX = pxToNum($el.css('left')) this._oldX = pxToNum($el.css('left'))
this._oldY = pxToNum($el.css('top')) this._oldY = pxToNum($el.css('top'))
this._startY = eventClient('y', e) this._startY = eventClient('y', e)
$document.on(drag('move'), this._onDragMove) $document.on(pointerEvent('move'), this._onDragMove)
$document.on(drag('end'), this._onDragEnd) $document.on(pointerEvent('up'), this._onDragEnd)
} }
_onDragMove = (e) => { _onDragMove = (e) => {
const btnSize = this._$el.get(0).offsetWidth const btnSize = this._$el.get(0).offsetWidth
@@ -132,8 +133,8 @@ export default class EntryBtn extends Emitter {
} }
this._onDragMove(e) this._onDragMove(e)
$document.off(drag('move'), this._onDragMove) $document.off(pointerEvent('move'), this._onDragMove)
$document.off(drag('end'), this._onDragEnd) $document.off(pointerEvent('up'), this._onDragEnd)
const cfg = this.config const cfg = this.config
@@ -149,7 +150,7 @@ export default class EntryBtn extends Emitter {
_bindEvent() { _bindEvent() {
const $el = this._$el const $el = this._$el
$el.on(drag('start'), this._onDragStart) $el.on(pointerEvent('down'), this._onDragStart)
orientation.on('change', () => this._resetPos(true)) orientation.on('change', () => this._resetPos(true))
window.addEventListener('resize', () => this._resetPos()) window.addEventListener('resize', () => this._resetPos())

View File

@@ -5,7 +5,6 @@ import isUndef from 'licia/isUndef'
import last from 'licia/last' import last from 'licia/last'
import map from 'licia/map' import map from 'licia/map'
import memStorage from 'licia/memStorage' import memStorage from 'licia/memStorage'
import root from 'licia/root'
import toNum from 'licia/toNum' import toNum from 'licia/toNum'
import trim from 'licia/trim' import trim from 'licia/trim'
import html from 'licia/html' import html from 'licia/html'
@@ -147,32 +146,6 @@ function processClass(str) {
}).join(' ') }).join(' ')
} }
const hasTouchSupport = 'ontouchstart' in root
const hasPointerSupport = 'PointerEvent' in root
const touchEvents = {
start: 'touchstart',
move: 'touchmove',
end: 'touchend',
}
const mouseEvents = {
start: 'mousedown',
move: 'mousemove',
end: 'mouseup',
}
const pointerEvents = {
start: 'pointerdown',
move: 'pointermove',
end: 'pointerup',
}
export function drag(name) {
if (hasPointerSupport) {
return pointerEvents[name]
}
return hasTouchSupport ? touchEvents[name] : mouseEvents[name]
}
export function eventClient(type, e) { export function eventClient(type, e) {
const name = type === 'x' ? 'clientX' : 'clientY' const name = type === 'x' ? 'clientX' : 'clientY'