Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyuki authored Dec 13, 2023
2 parents 36b92e8 + d3c6df1 commit 33592de
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 20 deletions.
40 changes: 25 additions & 15 deletions packages/api-proxy/src/common/js/web.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isBrowser } from './utils'

function webHandleSuccess (result, success, complete) {
typeof success === 'function' && success(result)
typeof complete === 'function' && complete(result)
Expand Down Expand Up @@ -33,22 +35,30 @@ function createDom (tag, attrs = {}, children = []) {
// 在H5中,直接绑定 click 可能出现延时问题,很多点击可以关闭的组件被唤出之后,有概率立马触发点击事件,导致组件被关闭。
// 使用该方法通过 touchstart 和 touchend 模拟 click 事件,解决延时问题。
function bindTap (dom, handler) {
let startTime = 0; let x = 0; let y = 0
const touchStart = (e) => {
startTime = Date.now()
x = e.touches[0].pageX
y = e.touches[0].pageY
}
const touchEnd = (e) => {
if (Date.now() - startTime < 300 && Math.abs(e.changedTouches[0].pageX - x) < 10 && Math.abs(e.changedTouches[0].pageY - y) < 10) {
handler(e)
const isTouchDevice = isBrowser && document && ('ontouchstart' in document.documentElement)
if (isTouchDevice) {
let startTime = 0; let x = 0; let y = 0
const touchStart = (e) => {
startTime = Date.now()
x = e.touches[0].pageX
y = e.touches[0].pageY
}
const touchEnd = (e) => {
if (Date.now() - startTime < 300 && Math.abs(e.changedTouches[0].pageX - x) < 10 && Math.abs(e.changedTouches[0].pageY - y) < 10) {
handler(e)
}
}
dom.addEventListener('touchstart', touchStart)
dom.addEventListener('touchend', touchEnd)
return () => {
dom.removeEventListener('touchstart', touchStart)
dom.removeEventListener('touchend', touchEnd)
}
} else {
dom.addEventListener('click', handler)
return () => {
dom.removeEventListener('click', handler)
}
}
dom.addEventListener('touchstart', touchStart)
dom.addEventListener('touchend', touchEnd)
return () => {
dom.removeEventListener('touchstart', touchStart)
dom.removeEventListener('touchend', touchEnd)
}
}

Expand Down
6 changes: 5 additions & 1 deletion packages/core/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ export type Plugin = PluginInstallFunction | {
install: PluginInstallFunction
}

export type PluginFunction<T extends Plugin> = T extends PluginInstallFunction ? T : T extends { install: infer U } ? U : never;

export type PluginFunctionParams<T extends PluginInstallFunction> = T extends (app: any, ...args: infer P) => any ? P : [];

export interface Mpx {
getMixin: typeof getMixin
mixin: typeof injectMixins
Expand All @@ -293,7 +297,7 @@ export interface Mpx {
observable: typeof observable
watch: typeof watch

use (plugin: Plugin, ...rest: any[]): Mpx
use <T extends Plugin = Plugin>(plugin: T, ...rest: PluginFunctionParams<PluginFunction<T>>): Mpx

implement (name: string, options?: ImplementOptions): void

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
},
speed: {
type: Number,
default: 1000
default: 500
},
scrollOptions: {
type: Object,
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/lib/script-setup-compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ function compileScriptSetup (
(node.type === 'VariableDeclaration' && node.declare)
) {
recordType(node, declaredTypes)
_s.move(node.start, node.end, 0)
_s.move(node.start, node.end + 1, 0)
}
}

Expand Down
9 changes: 7 additions & 2 deletions test/utils/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export const createTouchEvent = (type, target, params = {}) => {
}

export const dispatchTap = (el) => {
el.dispatchEvent(createTouchEvent('touchstart', el))
el.dispatchEvent(createTouchEvent('touchend', el))
const isTouchDevice = typeof window !== 'undefined' && document && ('ontouchstart' in document.documentElement)
if (isTouchDevice) {
el.dispatchEvent(createTouchEvent('touchstart', el))
el.dispatchEvent(createTouchEvent('touchend', el))
} else {
el.dispatchEvent(new MouseEvent('click', { bubbles: true }))
}
}

0 comments on commit 33592de

Please sign in to comment.