Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
genary
uni-app
提交
0c2a7644
U
uni-app
项目概览
genary
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0c2a7644
编写于
4月 20, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: normalizeNativeEvent
上级
b741971a
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
268 addition
and
361 deletion
+268
-361
packages/uni-components/src/helpers/useEvent.ts
packages/uni-components/src/helpers/useEvent.ts
+3
-17
packages/uni-core/src/view/plugin/appConfig.ts
packages/uni-core/src/view/plugin/appConfig.ts
+5
-5
packages/uni-core/src/view/plugin/componentEvents.ts
packages/uni-core/src/view/plugin/componentEvents.ts
+0
-129
packages/uni-core/src/view/plugin/componentInstance.ts
packages/uni-core/src/view/plugin/componentInstance.ts
+79
-20
packages/uni-core/src/view/plugin/componentWxs.ts
packages/uni-core/src/view/plugin/componentWxs.ts
+26
-26
packages/uni-h5-vue/dist/vue.runtime.esm.js
packages/uni-h5-vue/dist/vue.runtime.esm.js
+4
-1
packages/uni-h5-vue/lib/vue.runtime.esm.js
packages/uni-h5-vue/lib/vue.runtime.esm.js
+4
-1
packages/uni-h5/dist/uni-h5.esm.js
packages/uni-h5/dist/uni-h5.esm.js
+110
-161
packages/uni-shared/dist/uni-shared.cjs.js
packages/uni-shared/dist/uni-shared.cjs.js
+10
-0
packages/uni-shared/dist/uni-shared.d.ts
packages/uni-shared/dist/uni-shared.d.ts
+7
-0
packages/uni-shared/dist/uni-shared.esm.js
packages/uni-shared/dist/uni-shared.esm.js
+10
-1
packages/uni-shared/src/dom.ts
packages/uni-shared/src/dom.ts
+10
-0
未找到文件。
packages/uni-components/src/helpers/useEvent.ts
浏览文件 @
0c2a7644
import
{
Ref
,
SetupContext
}
from
'
vue
'
import
{
normalizeTarget
}
from
'
@dcloudio/uni-shared
'
type
EventDetail
=
Record
<
string
,
any
>
export
type
CustomEventTrigger
=
ReturnType
<
typeof
useCustomEvent
>
...
...
@@ -15,33 +16,18 @@ export function useCustomEvent(
}
}
function
normalizeDataset
(
el
:
HTMLElement
)
{
return
el
.
dataset
}
function
normalizeTarget
(
el
:
HTMLElement
):
WechatMiniprogram
.
Target
{
const
{
id
,
offsetTop
,
offsetLeft
}
=
el
return
{
id
,
dataset
:
normalizeDataset
(
el
),
offsetTop
,
offsetLeft
,
}
}
function
normalizeCustomEvent
(
name
:
string
,
domEvt
:
Event
,
el
:
HTMLElement
,
detail
:
EventDetail
)
{
)
:
WechatMiniprogram
.
CustomEvent
{
const
target
=
normalizeTarget
(
el
)
const
evt
:
WechatMiniprogram
.
CustomEvent
=
{
return
{
type
:
detail
.
type
||
name
,
timeStamp
:
domEvt
.
timeStamp
||
0
,
target
,
currentTarget
:
target
,
detail
,
}
return
evt
}
packages/uni-core/src/view/plugin/appConfig.ts
浏览文件 @
0c2a7644
import
{
AppConfig
}
from
'
vue
'
//
import { extend } from '@vue/shared'
import
{
extend
}
from
'
@vue/shared
'
//
import * as instance from './componentInstance'
import
*
as
instance
from
'
./componentInstance
'
import
{
getComponentDescriptor
,
handleWxsEvent
}
from
'
./componentWxs
'
import
{
getComponentDescriptor
}
from
'
./componentWxs
'
export
function
initAppConfig
(
appConfig
:
AppConfig
)
{
const
globalProperties
=
appConfig
.
globalProperties
//
extend(globalProperties, instance)
extend
(
globalProperties
,
instance
)
if
(
__UNI_FEATURE_WXS__
)
{
globalProperties
.
getComponentDescriptor
=
getComponentDescriptor
Object
.
defineProperty
(
globalProperties
,
'
$ownerInstance
'
,
{
...
...
@@ -15,6 +15,6 @@ export function initAppConfig(appConfig: AppConfig) {
return
this
.
$getComponentDescriptor
(
this
)
},
})
globalProperties
.
$handleWxsEvent
=
handleWxsEvent
//
globalProperties.$handleWxsEvent = handleWxsEvent
}
}
packages/uni-core/src/view/plugin/componentEvents.ts
已删除
100644 → 0
浏览文件 @
b741971a
import
{
extend
}
from
'
@vue/shared
'
import
{
getWindowOffset
}
from
'
../../helpers/getWindowOffset
'
export
function
findUniTarget
(
$event
:
Event
,
$el
:
HTMLElement
):
HTMLElement
{
let
target
=
$event
.
target
as
HTMLElement
for
(;
target
&&
target
!==
$el
;
target
=
target
.
parentNode
as
HTMLElement
)
{
if
(
target
.
tagName
&&
target
.
tagName
.
indexOf
(
'
UNI-
'
)
===
0
)
{
break
}
}
return
target
}
export
function
normalizeDataset
(
dataset
:
DOMStringMap
=
{})
{
// ios8.x,9.x Object.assign({},dataset) 始终返回 {}
// http://ask.dcloud.net.cn/question/70246
const
result
=
JSON
.
parse
(
JSON
.
stringify
(
dataset
))
// 暂不处理该逻辑了,理论上应该没什么影响
// if (__PLATFORM__ === 'h5') {
// removeScoped(result)
// }
return
result
}
export
function
normalizeEvent
(
name
:
string
,
$event
:
Event
,
detail
:
Record
<
string
,
any
>
=
{},
target
:
HTMLElement
|
null
,
currentTarget
:
HTMLElement
|
null
)
{
if
((
$event
as
any
).
_processed
)
{
;(
$event
as
any
).
type
=
detail
.
type
||
name
return
$event
}
// fixed 针对小程序 click(tap)事件,补充事件详情
if
(
isClickEvent
(
$event
,
name
))
{
const
{
top
}
=
getWindowOffset
()
detail
=
{
x
:
$event
.
x
,
y
:
$event
.
y
-
top
,
}
normalizeClickEvent
(
$event
)
}
const
ret
=
{
_processed
:
true
,
type
:
detail
.
type
||
name
,
timeStamp
:
$event
.
timeStamp
||
0
,
detail
:
detail
,
target
:
normalizeTarget
(
target
,
detail
),
currentTarget
:
normalizeTarget
(
currentTarget
),
touches
:
normalizeTouchList
((
$event
as
any
).
touches
),
changedTouches
:
normalizeTouchList
((
$event
as
any
).
changedTouches
),
preventDefault
()
{},
stopPropagation
()
{},
}
if
(
__PLATFORM__
===
'
app
'
&&
currentTarget
)
{
const
nid
=
currentTarget
.
getAttribute
(
'
_i
'
)
;(
ret
as
any
).
options
=
{
nid
,
}
// 保留原始 currentTarget 方便后续对比
;(
ret
as
any
).
$origCurrentTarget
=
currentTarget
}
return
ret
}
function
normalizeClickEvent
(
$event
:
MouseEvent
)
{
;(
$event
as
any
).
touches
=
(
$event
as
any
).
changedTouches
=
[
{
force
:
1
,
identifier
:
0
,
clientX
:
$event
.
clientX
,
clientY
:
$event
.
clientY
,
pageX
:
$event
.
pageX
,
pageY
:
$event
.
pageY
,
},
]
}
function
isClickEvent
(
val
:
unknown
,
name
:
string
):
val
is
MouseEvent
{
return
name
===
'
click
'
}
function
normalizeTarget
(
target
:
HTMLElement
|
null
,
detail
?:
Record
<
string
,
any
>
|
undefined
)
{
if
(
!
target
)
{
target
=
{}
as
HTMLElement
}
const
res
=
{
id
:
target
.
id
,
offsetLeft
:
target
.
offsetLeft
,
offsetTop
:
target
.
offsetTop
,
dataset
:
normalizeDataset
(
target
.
dataset
),
}
if
(
detail
)
{
extend
(
res
,
detail
)
}
return
res
}
function
normalizeTouchList
(
touches
:
unknown
)
{
if
(
touches
&&
touches
instanceof
TouchList
)
{
const
res
=
[]
const
{
top
}
=
getWindowOffset
()
for
(
let
i
=
0
;
i
<
touches
.
length
;
i
++
)
{
const
touch
=
touches
[
i
]
res
.
push
({
identifier
:
touch
.
identifier
,
pageX
:
touch
.
pageX
,
pageY
:
touch
.
pageY
-
top
,
clientX
:
touch
.
clientX
,
clientY
:
touch
.
clientY
-
top
,
force
:
touch
.
force
||
0
,
})
}
return
res
}
return
[]
}
packages/uni-core/src/view/plugin/componentInstance.ts
浏览文件 @
0c2a7644
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
normalizeEvent
,
findUniTarget
}
from
'
./componentEvents
'
import
{
normalizeTarget
}
from
'
@dcloudio/uni-shared
'
import
{
getWindowOffset
}
from
'
../../helpers/getWindowOffset
'
export
function
$trigger
(
const
isClickEvent
=
(
val
:
Event
):
val
is
MouseEvent
=>
val
.
type
===
'
click
'
const
isMouseEvent
=
(
val
:
Event
):
val
is
MouseEvent
=>
val
.
type
.
indexOf
(
'
mouse
'
)
===
0
export
function
$normalizeNativeEvent
(
this
:
ComponentPublicInstance
,
name
:
string
,
$event
:
Event
,
detail
?:
Record
<
string
,
any
>
evt
:
Event
)
{
const
target
=
this
.
$el
this
.
$emit
(
name
,
normalizeEvent
(
name
,
$event
,
detail
,
target
,
target
))
const
{
currentTarget
}
=
evt
if
(
!
(
evt
instanceof
Event
)
||
!
(
currentTarget
instanceof
HTMLElement
))
{
return
evt
}
if
(
currentTarget
.
tagName
.
indexOf
(
'
UNI-
'
)
!==
0
)
{
return
evt
}
const
res
=
createNativeEvent
(
evt
)
if
(
isClickEvent
(
evt
))
{
normalizeClickEvent
((
res
as
unknown
)
as
WechatMiniprogram
.
Touch
,
evt
)
}
else
if
(
__PLATFORM__
===
'
h5
'
&&
isMouseEvent
(
evt
))
{
normalizeMouseEvent
((
res
as
unknown
)
as
WechatMiniprogram
.
Touch
,
evt
)
}
return
res
}
function
createNativeEvent
(
evt
:
Event
)
{
const
{
type
,
timeStamp
,
currentTarget
}
=
evt
const
target
=
normalizeTarget
(
currentTarget
as
HTMLElement
)
return
{
type
,
timeStamp
,
target
,
detail
:
{},
currentTarget
:
target
,
preventDefault
()
{
if
(
__DEV__
)
{
console
.
warn
(
'
preventDefault is only supported in h5, use `.prevent` instead.
'
)
}
return
evt
.
preventDefault
()
},
stopPropagation
()
{
if
(
__DEV__
)
{
console
.
warn
(
'
stopPropagation is only supported in h5, use `.stop` instead.
'
)
}
return
evt
.
stopPropagation
()
},
}
}
function
normalizeClickEvent
(
evt
:
WechatMiniprogram
.
Touch
,
mouseEvt
:
MouseEvent
)
{
const
{
x
,
y
}
=
mouseEvt
const
{
top
}
=
getWindowOffset
()
evt
.
detail
=
{
x
,
y
:
y
-
top
}
evt
.
touches
=
evt
.
changedTouches
=
[
createTouchEvent
(
mouseEvt
)]
}
function
normalizeMouseEvent
(
evt
:
Record
<
string
,
any
>
,
mouseEvt
:
MouseEvent
)
{
const
{
top
}
=
getWindowOffset
()
evt
.
pageX
=
mouseEvt
.
pageX
evt
.
pageY
=
mouseEvt
.
pageY
-
top
evt
.
clientX
=
mouseEvt
.
clientX
evt
.
clientY
=
mouseEvt
.
clientY
-
top
}
export
function
$handleEvent
(
this
:
ComponentPublicInstance
,
$event
:
Event
)
{
// 未处理的 event 对象 需要对 target 校正及包装
// 查找 uniTarget
if
(
$event
instanceof
Event
)
{
const
target
=
findUniTarget
(
$event
,
this
.
$el
)
return
normalizeEvent
(
$event
.
type
,
$event
,
{},
target
||
$event
.
target
,
$event
.
currentTarget
as
HTMLElement
)
function
createTouchEvent
(
evt
:
MouseEvent
)
{
return
{
force
:
1
,
identifier
:
0
,
clientX
:
evt
.
clientX
,
clientY
:
evt
.
clientY
,
pageX
:
evt
.
pageX
,
pageY
:
evt
.
pageY
,
}
return
$event
}
packages/uni-core/src/view/plugin/componentWxs.ts
浏览文件 @
0c2a7644
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
isFunction
,
isPlainObject
}
from
'
@vue/shared
'
import
{
normalizeEvent
,
findUniTarget
}
from
'
./componentEvents
'
//
import { normalizeEvent, findUniTarget } from './componentEvents'
interface
WxsElement
extends
HTMLElement
{
__wxsStyle
:
Record
<
string
,
string
>
...
...
@@ -213,28 +213,28 @@ export function getComponentDescriptor(
return
createComponentDescriptor
(
instance
||
this
,
isOwnerInstance
)
}
export
function
handleWxsEvent
(
this
:
ComponentPublicInstance
,
$event
:
Event
)
{
if
(
!
(
$event
instanceof
Event
))
{
return
$event
}
const
currentTarget
=
$event
.
currentTarget
as
WxsElement
const
instance
=
currentTarget
&&
currentTarget
.
__vue__
&&
getComponentDescriptor
.
call
(
this
,
currentTarget
.
__vue__
,
false
)
const
$origEvent
=
$event
$event
=
normalizeEvent
(
$origEvent
.
type
,
$origEvent
,
{},
findUniTarget
(
$origEvent
,
this
.
$el
)
||
$origEvent
.
target
,
$origEvent
.
currentTarget
as
HTMLElement
)
as
Event
;(
$event
as
any
).
instance
=
instance
$event
.
preventDefault
=
function
()
{
return
$origEvent
.
preventDefault
()
}
$event
.
stopPropagation
=
function
()
{
return
$origEvent
.
stopPropagation
()
}
}
//
export function handleWxsEvent(this: ComponentPublicInstance, $event: Event) {
//
if (!($event instanceof Event)) {
//
return $event
//
}
//
const currentTarget = $event.currentTarget as WxsElement
//
const instance =
//
currentTarget &&
//
currentTarget.__vue__ &&
//
getComponentDescriptor.call(this, currentTarget.__vue__, false)
//
const $origEvent = $event
//
$event = normalizeEvent(
//
$origEvent.type,
//
$origEvent,
//
{},
//
findUniTarget($origEvent, this.$el) || $origEvent.target,
//
$origEvent.currentTarget as HTMLElement
//
) as Event
//
;($event as any).instance = instance
//
$event.preventDefault = function () {
//
return $origEvent.preventDefault()
//
}
//
$event.stopPropagation = function () {
//
return $origEvent.stopPropagation()
//
}
//
}
packages/uni-h5-vue/dist/vue.runtime.esm.js
浏览文件 @
0c2a7644
...
...
@@ -8396,7 +8396,10 @@ function createInvoker(initialValue, instance) {
// AFTER it was attached.
const
timeStamp
=
e
.
timeStamp
||
_getNow
();
if
(
timeStamp
>=
invoker
.
attached
-
1
)
{
callWithAsyncErrorHandling
(
patchStopImmediatePropagation
(
e
,
invoker
.
value
),
instance
,
5
/* NATIVE_EVENT_HANDLER */
,
[
e
]);
// fixed by xxxxxx
const
proxy
=
instance
&&
instance
.
proxy
;
const
normalizeNativeEvent
=
proxy
&&
proxy
.
$normalizeNativeEvent
;
callWithAsyncErrorHandling
(
patchStopImmediatePropagation
(
e
,
invoker
.
value
),
instance
,
5
/* NATIVE_EVENT_HANDLER */
,
[
normalizeNativeEvent
?
normalizeNativeEvent
(
e
)
:
e
]);
}
};
invoker
.
value
=
initialValue
;
...
...
packages/uni-h5-vue/lib/vue.runtime.esm.js
浏览文件 @
0c2a7644
...
...
@@ -8396,7 +8396,10 @@ function createInvoker(initialValue, instance) {
// AFTER it was attached.
const
timeStamp
=
e
.
timeStamp
||
_getNow
();
if
(
timeStamp
>=
invoker
.
attached
-
1
)
{
callWithAsyncErrorHandling
(
patchStopImmediatePropagation
(
e
,
invoker
.
value
),
instance
,
5
/* NATIVE_EVENT_HANDLER */
,
[
e
]);
// fixed by xxxxxx
const
proxy
=
instance
&&
instance
.
proxy
;
const
normalizeNativeEvent
=
proxy
&&
proxy
.
$normalizeNativeEvent
;
callWithAsyncErrorHandling
(
patchStopImmediatePropagation
(
e
,
invoker
.
value
),
instance
,
5
/* NATIVE_EVENT_HANDLER */
,
[
normalizeNativeEvent
?
normalizeNativeEvent
(
e
)
:
e
]);
}
};
invoker
.
value
=
initialValue
;
...
...
packages/uni-h5/dist/uni-h5.esm.js
浏览文件 @
0c2a7644
import
{
isFunction
,
extend
,
isPlainObject
,
isString
,
invokeArrayFns
as
invokeArrayFns$1
,
hyphenate
,
isArray
,
hasOwn
as
hasOwn$1
,
isObject
as
isObject$1
,
capitalize
,
toRawType
,
makeMap
as
makeMap$1
,
isPromise
}
from
"
@vue/shared
"
;
import
{
injectHook
,
createVNode
,
inject
,
provide
,
reactive
,
computed
,
nextTick
,
getCurrentInstance
,
onBeforeMount
,
onMounted
,
onBeforeActivate
,
onBeforeDeactivate
,
openBlock
,
createBlock
,
mergeProps
,
toDisplayString
,
ref
,
defineComponent
,
resolveComponent
,
toHandlers
,
renderSlot
,
watch
,
onActivated
,
onBeforeUnmount
,
withModifiers
,
withDirectives
,
vShow
,
vModelDynamic
,
createCommentVNode
,
createTextVNode
,
Fragment
,
renderList
,
vModelText
,
watchEffect
,
withCtx
,
KeepAlive
,
resolveDynamicComponent
}
from
"
vue
"
;
import
{
once
,
passive
,
invokeArrayFns
,
NAVBAR_HEIGHT
,
parseQuery
,
decodedQuery
,
plusReady
,
debounce
,
PRIMARY_COLOR
as
PRIMARY_COLOR$1
,
removeLeadingSlash
,
getLen
,
updateElementStyle
}
from
"
@dcloudio/uni-shared
"
;
import
{
once
,
passive
,
normalizeTarget
,
invokeArrayFns
,
NAVBAR_HEIGHT
,
parseQuery
,
decodedQuery
,
plusReady
,
debounce
,
PRIMARY_COLOR
as
PRIMARY_COLOR$1
,
removeLeadingSlash
,
getLen
,
updateElementStyle
}
from
"
@dcloudio/uni-shared
"
;
import
{
useRoute
,
createRouter
,
createWebHistory
,
createWebHashHistory
,
isNavigationFailure
,
RouterView
}
from
"
vue-router
"
;
function
applyOptions
(
options
,
instance
,
publicThis
)
{
function
applyOptions
(
options
,
instance
2
,
publicThis
)
{
Object
.
keys
(
options
).
forEach
((
name
)
=>
{
if
(
name
.
indexOf
(
"
on
"
)
===
0
)
{
const
hook
=
options
[
name
];
if
(
isFunction
(
hook
))
{
injectHook
(
name
,
hook
.
bind
(
publicThis
),
instance
);
injectHook
(
name
,
hook
.
bind
(
publicThis
),
instance
2
);
}
}
});
...
...
@@ -604,7 +604,7 @@ var safeAreaInsets = {
onChange
,
offChange
};
var
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
=
safeAreaInsets
;
var
out
=
safeAreaInsets
;
function
getWindowOffset
()
{
const
style
=
document
.
documentElement
.
style
;
const
top
=
parseInt
(
style
.
getPropertyValue
(
"
--window-top
"
));
...
...
@@ -612,103 +612,81 @@ function getWindowOffset() {
const
left
=
parseInt
(
style
.
getPropertyValue
(
"
--window-left
"
));
const
right
=
parseInt
(
style
.
getPropertyValue
(
"
--window-right
"
));
return
{
top
:
top
?
top
+
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
top
:
0
,
bottom
:
bottom
?
bottom
+
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
bottom
:
0
,
left
:
left
?
left
+
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
left
:
0
,
right
:
right
?
right
+
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
right
:
0
top
:
top
?
top
+
out
.
top
:
0
,
bottom
:
bottom
?
bottom
+
out
.
bottom
:
0
,
left
:
left
?
left
+
out
.
left
:
0
,
right
:
right
?
right
+
out
.
right
:
0
};
}
function
findUniTarget
(
$event
,
$el
)
{
let
target
=
$event
.
target
;
for
(;
target
&&
target
!==
$el
;
target
=
target
.
parentNode
)
{
if
(
target
.
tagName
&&
target
.
tagName
.
indexOf
(
"
UNI-
"
)
===
0
)
{
break
;
}
const
isClickEvent
=
(
val
)
=>
val
.
type
===
"
click
"
;
const
isMouseEvent
=
(
val
)
=>
val
.
type
.
indexOf
(
"
mouse
"
)
===
0
;
function
$normalizeNativeEvent
(
evt
)
{
const
{
currentTarget
}
=
evt
;
if
(
!
(
evt
instanceof
Event
)
||
!
(
currentTarget
instanceof
HTMLElement
))
{
return
evt
;
}
return
target
;
}
function
normalizeDataset$1
(
dataset
=
{})
{
const
result
=
JSON
.
parse
(
JSON
.
stringify
(
dataset
));
return
result
;
}
function
normalizeEvent$1
(
name
,
$event
,
detail
=
{},
target
,
currentTarget
)
{
if
(
$event
.
_processed
)
{
$event
.
type
=
detail
.
type
||
name
;
return
$event
;
if
(
currentTarget
.
tagName
.
indexOf
(
"
UNI-
"
)
!==
0
)
{
return
evt
;
}
if
(
isClickEvent
(
$event
,
name
))
{
const
{
top
}
=
getWindowOffset
();
detail
=
{
x
:
$event
.
x
,
y
:
$event
.
y
-
top
};
normalizeClickEvent
(
$event
);
const
res
=
createNativeEvent
(
evt
);
if
(
isClickEvent
(
evt
))
{
normalizeClickEvent
(
res
,
evt
);
}
else
if
(
isMouseEvent
(
evt
))
{
normalizeMouseEvent
(
res
,
evt
);
}
const
ret
=
{
_processed
:
true
,
type
:
detail
.
type
||
name
,
timeStamp
:
$event
.
timeStamp
||
0
,
detail
,
target
:
normalizeTarget$1
(
target
,
detail
),
currentTarget
:
normalizeTarget$1
(
currentTarget
),
touches
:
normalizeTouchList
(
$event
.
touches
),
changedTouches
:
normalizeTouchList
(
$event
.
changedTouches
),
return
res
;
}
function
createNativeEvent
(
evt
)
{
const
{
type
,
timeStamp
,
currentTarget
}
=
evt
;
const
target
=
normalizeTarget
(
currentTarget
);
return
{
type
,
timeStamp
,
target
,
detail
:
{},
currentTarget
:
target
,
preventDefault
()
{
if
(
process
.
env
.
NODE_ENV
!==
"
production
"
)
{
console
.
warn
(
"
preventDefault is only supported in h5, use `.prevent` instead.
"
);
}
return
evt
.
preventDefault
();
},
stopPropagation
()
{
if
(
process
.
env
.
NODE_ENV
!==
"
production
"
)
{
console
.
warn
(
"
stopPropagation is only supported in h5, use `.stop` instead.
"
);
}
return
evt
.
stopPropagation
();
}
};
return
ret
;
}
function
normalizeClickEvent
(
$event
)
{
$event
.
touches
=
$event
.
changedTouches
=
[
{
force
:
1
,
identifier
:
0
,
clientX
:
$event
.
clientX
,
clientY
:
$event
.
clientY
,
pageX
:
$event
.
pageX
,
pageY
:
$event
.
pageY
}
];
function
normalizeClickEvent
(
evt
,
mouseEvt
)
{
const
{
x
,
y
}
=
mouseEvt
;
const
{
top
}
=
getWindowOffset
();
evt
.
detail
=
{
x
,
y
:
y
-
top
};
evt
.
touches
=
evt
.
changedTouches
=
[
createTouchEvent
(
mouseEvt
)];
}
function
isClickEvent
(
val
,
name
)
{
return
name
===
"
click
"
;
function
normalizeMouseEvent
(
evt
,
mouseEvt
)
{
const
{
top
}
=
getWindowOffset
();
evt
.
pageX
=
mouseEvt
.
pageX
;
evt
.
pageY
=
mouseEvt
.
pageY
-
top
;
evt
.
clientX
=
mouseEvt
.
clientX
;
evt
.
clientY
=
mouseEvt
.
clientY
-
top
;
}
function
normalizeTarget$1
(
target
,
detail
)
{
if
(
!
target
)
{
target
=
{};
}
const
res
=
{
id
:
target
.
id
,
offsetLeft
:
target
.
offsetLeft
,
offsetTop
:
target
.
offsetTop
,
dataset
:
normalizeDataset$1
(
target
.
dataset
)
function
createTouchEvent
(
evt
)
{
return
{
force
:
1
,
identifier
:
0
,
clientX
:
evt
.
clientX
,
clientY
:
evt
.
clientY
,
pageX
:
evt
.
pageX
,
pageY
:
evt
.
pageY
};
if
(
detail
)
{
extend
(
res
,
detail
);
}
return
res
;
}
function
normalizeTouchList
(
touches
)
{
if
(
touches
&&
touches
instanceof
TouchList
)
{
const
res
=
[];
const
{
top
}
=
getWindowOffset
();
for
(
let
i2
=
0
;
i2
<
touches
.
length
;
i2
++
)
{
const
touch
=
touches
[
i2
];
res
.
push
({
identifier
:
touch
.
identifier
,
pageX
:
touch
.
pageX
,
pageY
:
touch
.
pageY
-
top
,
clientX
:
touch
.
clientX
,
clientY
:
touch
.
clientY
-
top
,
force
:
touch
.
force
||
0
});
}
return
res
;
}
return
[];
}
var
instance
=
/* @__PURE__ */
Object
.
freeze
({
__proto__
:
null
,
[
Symbol
.
toStringTag
]:
"
Module
"
,
$normalizeNativeEvent
});
const
CLASS_RE
=
/^
\s
+|
\s
+$/g
;
const
WXS_CLASS_RE
=
/
\s
+/
;
function
getWxsClsArr
(
clsArr
,
classList
,
isAdd
)
{
...
...
@@ -859,27 +837,12 @@ function createComponentDescriptor(vm, isOwnerInstance = true) {
return
vm
.
$el
.
__wxsComponentDescriptor
;
}
}
function
getComponentDescriptor
(
instance
,
isOwnerInstance
)
{
return
createComponentDescriptor
(
instance
||
this
,
isOwnerInstance
);
}
function
handleWxsEvent
(
$event
)
{
if
(
!
(
$event
instanceof
Event
))
{
return
$event
;
}
const
currentTarget
=
$event
.
currentTarget
;
const
instance
=
currentTarget
&&
currentTarget
.
__vue__
&&
getComponentDescriptor
.
call
(
this
,
currentTarget
.
__vue__
,
false
);
const
$origEvent
=
$event
;
$event
=
normalizeEvent$1
(
$origEvent
.
type
,
$origEvent
,
{},
findUniTarget
(
$origEvent
,
this
.
$el
)
||
$origEvent
.
target
,
$origEvent
.
currentTarget
);
$event
.
instance
=
instance
;
$event
.
preventDefault
=
function
()
{
return
$origEvent
.
preventDefault
();
};
$event
.
stopPropagation
=
function
()
{
return
$origEvent
.
stopPropagation
();
};
function
getComponentDescriptor
(
instance2
,
isOwnerInstance
)
{
return
createComponentDescriptor
(
instance2
||
this
,
isOwnerInstance
);
}
function
initAppConfig$1
(
appConfig
)
{
const
globalProperties
=
appConfig
.
globalProperties
;
extend
(
globalProperties
,
instance
);
if
(
__UNI_FEATURE_WXS__
)
{
globalProperties
.
getComponentDescriptor
=
getComponentDescriptor
;
Object
.
defineProperty
(
globalProperties
,
"
$ownerInstance
"
,
{
...
...
@@ -887,7 +850,6 @@ function initAppConfig$1(appConfig) {
return
this
.
$getComponentDescriptor
(
this
);
}
});
globalProperties
.
$handleWxsEvent
=
handleWxsEvent
;
}
}
function
initView
(
app
)
{
...
...
@@ -1037,8 +999,8 @@ function getRealRoute(fromRoute, toRoute) {
fromRouteArray
.
splice
(
fromRouteArray
.
length
-
i2
-
1
,
i2
+
1
);
return
"
/
"
+
fromRouteArray
.
concat
(
toRouteArray
).
join
(
"
/
"
);
}
function
errorHandler
(
err
,
instance
,
info
)
{
if
(
!
instance
)
{
function
errorHandler
(
err
,
instance
2
,
info
)
{
if
(
!
instance
2
)
{
throw
err
;
}
const
app
=
getApp
();
...
...
@@ -1101,7 +1063,7 @@ function normalizePageMeta(pageMeta) {
let
offset
=
rpx2px
(
refreshOptions
.
offset
);
const
{
type
}
=
navigationBar
;
if
(
type
!==
"
transparent
"
&&
type
!==
"
none
"
)
{
offset
+=
NAVBAR_HEIGHT
+
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
top
;
offset
+=
NAVBAR_HEIGHT
+
out
.
top
;
}
refreshOptions
.
height
=
rpx2px
(
refreshOptions
.
height
);
refreshOptions
.
range
=
rpx2px
(
refreshOptions
.
range
);
...
...
@@ -1356,9 +1318,9 @@ function usePageRoute() {
function
wrapperComponentSetup
(
comp
,
{
init
:
init2
,
setup
,
after
})
{
const
oldSetup
=
comp
.
setup
;
comp
.
setup
=
(
props2
,
ctx
)
=>
{
const
instance
=
getCurrentInstance
();
init2
(
instance
.
proxy
);
setup
(
instance
);
const
instance
2
=
getCurrentInstance
();
init2
(
instance
2
.
proxy
);
setup
(
instance
2
);
if
(
oldSetup
)
{
return
oldSetup
(
props2
,
ctx
);
}
...
...
@@ -1376,32 +1338,32 @@ function setupComponent(comp, options) {
function
setupPage
(
comp
)
{
return
setupComponent
(
comp
,
{
init
:
initPage
,
setup
(
instance
)
{
setup
(
instance
2
)
{
const
route
=
usePageRoute
();
if
(
route
.
meta
.
isTabBar
)
{
instance
.
__isActive
=
true
;
instance
2
.
__isActive
=
true
;
}
onBeforeMount
(()
=>
{
const
{
onLoad
,
onShow
}
=
instance
;
const
{
onLoad
,
onShow
}
=
instance
2
;
onLoad
&&
invokeArrayFns$1
(
onLoad
,
decodedQuery
(
route
.
query
));
instance
.
__isVisible
=
true
;
instance
2
.
__isVisible
=
true
;
onShow
&&
invokeArrayFns$1
(
onShow
);
});
onMounted
(()
=>
{
const
{
onReady
}
=
instance
;
const
{
onReady
}
=
instance
2
;
onReady
&&
invokeArrayFns$1
(
onReady
);
});
onBeforeActivate
(()
=>
{
if
(
!
instance
.
__isVisible
)
{
instance
.
__isVisible
=
true
;
const
{
onShow
}
=
instance
;
if
(
!
instance
2
.
__isVisible
)
{
instance
2
.
__isVisible
=
true
;
const
{
onShow
}
=
instance
2
;
onShow
&&
invokeArrayFns$1
(
onShow
);
}
});
onBeforeDeactivate
(()
=>
{
if
(
instance
.
__isVisible
&&
!
instance
.
__isUnload
)
{
instance
.
__isVisible
=
false
;
const
{
onHide
}
=
instance
;
if
(
instance
2
.
__isVisible
&&
!
instance2
.
__isUnload
)
{
instance
2
.
__isVisible
=
false
;
const
{
onHide
}
=
instance
2
;
onHide
&&
invokeArrayFns$1
(
onHide
);
}
});
...
...
@@ -1411,10 +1373,10 @@ function setupPage(comp) {
function
setupApp
(
comp
)
{
return
setupComponent
(
comp
,
{
init
:
initApp
,
setup
(
instance
)
{
setup
(
instance
2
)
{
const
route
=
usePageRoute
();
onBeforeMount
(()
=>
{
const
{
onLaunch
,
onShow
}
=
instance
;
const
{
onLaunch
,
onShow
}
=
instance
2
;
onLaunch
&&
invokeArrayFns$1
(
onLaunch
,
{
path
:
route
.
meta
.
route
,
query
:
decodedQuery
(
route
.
query
),
...
...
@@ -5766,28 +5728,15 @@ function useCustomEvent(ref2, emit) {
emit
(
name
,
normalizeCustomEvent
(
name
,
evt
,
ref2
.
value
,
detail
||
{}));
};
}
function
normalizeDataset
(
el
)
{
return
el
.
dataset
;
}
function
normalizeTarget
(
el
)
{
const
{
id
:
id2
,
offsetTop
,
offsetLeft
}
=
el
;
return
{
id
:
id2
,
dataset
:
normalizeDataset
(
el
),
offsetTop
,
offsetLeft
};
}
function
normalizeCustomEvent
(
name
,
domEvt
,
el
,
detail
)
{
const
target
=
normalizeTarget
(
el
);
const
evt
=
{
return
{
type
:
detail
.
type
||
name
,
timeStamp
:
domEvt
.
timeStamp
||
0
,
target
,
currentTarget
:
target
,
detail
};
return
evt
;
}
var
ResizeSensor
=
/* @__PURE__ */
defineComponent
({
name
:
"
ResizeSensor
"
,
...
...
@@ -6087,14 +6036,14 @@ function useFormField(nameKey, valueKey) {
if
(
!
uniForm
)
{
return
;
}
const
instance
=
getCurrentInstance
();
const
instance
2
=
getCurrentInstance
();
const
ctx
=
{
submit
()
{
const
proxy
=
instance
.
proxy
;
const
proxy
=
instance
2
.
proxy
;
return
[
proxy
[
nameKey
],
proxy
[
valueKey
]];
},
reset
()
{
instance
.
proxy
[
valueKey
]
=
""
;
instance
2
.
proxy
[
valueKey
]
=
""
;
}
};
uniForm
.
addField
(
ctx
);
...
...
@@ -6202,9 +6151,9 @@ const _sfc_main$g = {
formElem
.
appendChild
(
this
.
$refs
.
input
);
this
.
$refs
.
wrapper
.
appendChild
(
formElem
);
}
const
instance
=
getCurrentInstance
();
if
(
instance
&&
instance
.
vnode
.
scopeId
)
{
this
.
$refs
.
placeholder
.
setAttribute
(
instance
.
vnode
.
scopeId
,
""
);
const
instance
2
=
getCurrentInstance
();
if
(
instance
2
&&
instance2
.
vnode
.
scopeId
)
{
this
.
$refs
.
placeholder
.
setAttribute
(
instance
2
.
vnode
.
scopeId
,
""
);
}
this
.
initKeyboard
(
this
.
$refs
.
input
);
},
...
...
@@ -9884,16 +9833,16 @@ function removeSubscribe(componentId, vm) {
UniViewJSBridge
.
unsubscribe
(
normalizeEvent
(
componentId
,
vm
));
}
function
useSubscribe
(
callback
)
{
const
instance
=
getCurrentInstance
().
proxy
;
const
instance
2
=
getCurrentInstance
().
proxy
;
onMounted
(()
=>
{
addSubscribe
(
instance
.
id
,
instance
,
callback
);
watch
(()
=>
instance
.
id
,
(
value
,
oldValue
)
=>
{
addSubscribe
(
value
,
instance
,
callback
);
removeSubscribe
(
oldValue
,
instance
);
addSubscribe
(
instance
2
.
id
,
instance2
,
callback
);
watch
(()
=>
instance
2
.
id
,
(
value
,
oldValue
)
=>
{
addSubscribe
(
value
,
instance
2
,
callback
);
removeSubscribe
(
oldValue
,
instance
2
);
});
});
onBeforeMount
(()
=>
{
removeSubscribe
(
instance
.
id
,
instance
);
removeSubscribe
(
instance
2
.
id
,
instance2
);
});
}
const
passiveOptions
=
passive
(
false
);
...
...
@@ -10828,7 +10777,7 @@ const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => {
const
windowWidth
=
getWindowWidth
(
screenWidth
);
let
windowHeight
=
window
.
innerHeight
;
const
language
=
navigator
.
language
;
const
statusBarHeight
=
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
top
;
const
statusBarHeight
=
out
.
top
;
let
osname
;
let
osversion
;
let
model
;
...
...
@@ -10941,12 +10890,12 @@ const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => {
const
system
=
`
${
osname
}
${
osversion
}
`
;
const
platform
=
osname
.
toLocaleLowerCase
();
const
safeArea
=
{
left
:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
left
,
right
:
windowWidth
-
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
right
,
top
:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
top
,
bottom
:
windowHeight
-
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
bottom
,
width
:
windowWidth
-
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out
.
left
-
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
right
,
height
:
windowHeight
-
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out
.
top
-
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
bottom
left
:
out
.
left
,
right
:
windowWidth
-
out
.
right
,
top
:
out
.
top
,
bottom
:
windowHeight
-
out
.
bottom
,
width
:
windowWidth
-
out
.
left
-
out
.
right
,
height
:
windowHeight
-
out
.
top
-
out
.
bottom
};
const
{
top
:
windowTop
,
bottom
:
windowBottom
}
=
getWindowOffset
();
windowHeight
-=
windowTop
;
...
...
@@ -10966,10 +10915,10 @@ const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => {
model
,
safeArea
,
safeAreaInsets
:
{
top
:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
top
,
right
:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
right
,
bottom
:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
bottom
,
left
:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
left
top
:
out
.
top
,
right
:
out
.
right
,
bottom
:
out
.
bottom
,
left
:
out
.
left
}
};
});
...
...
packages/uni-shared/dist/uni-shared.cjs.js
浏览文件 @
0c2a7644
...
...
@@ -10,6 +10,15 @@ function passive(passive) {
function
normalizeDataset
(
el
)
{
// TODO
return
JSON
.
parse
(
JSON
.
stringify
(
el
.
dataset
||
{}));
}
function
normalizeTarget
(
el
)
{
const
{
id
,
offsetTop
,
offsetLeft
}
=
el
;
return
{
id
,
dataset
:
normalizeDataset
(
el
),
offsetTop
,
offsetLeft
,
};
}
function
plusReady
(
callback
)
{
...
...
@@ -247,6 +256,7 @@ exports.isBuiltInComponent = isBuiltInComponent;
exports
.
isCustomElement
=
isCustomElement
;
exports
.
isNativeTag
=
isNativeTag
;
exports
.
normalizeDataset
=
normalizeDataset
;
exports
.
normalizeTarget
=
normalizeTarget
;
exports
.
once
=
once
;
exports
.
parseQuery
=
parseQuery
;
exports
.
passive
=
passive
;
...
...
packages/uni-shared/dist/uni-shared.d.ts
浏览文件 @
0c2a7644
...
...
@@ -37,6 +37,13 @@ export declare const NAVBAR_HEIGHT = 44;
export
declare
function
normalizeDataset
(
el
:
Element
):
any
;
export
declare
function
normalizeTarget
(
el
:
HTMLElement
):
{
id
:
string
;
dataset
:
any
;
offsetTop
:
number
;
offsetLeft
:
number
;
};
export
declare
function
once
(
fn
:
(...
args
:
any
[])
=>
any
,
ctx
?:
unknown
):
(...
args
:
any
[])
=>
any
;
/**
...
...
packages/uni-shared/dist/uni-shared.esm.js
浏览文件 @
0c2a7644
...
...
@@ -6,6 +6,15 @@ function passive(passive) {
function
normalizeDataset
(
el
)
{
// TODO
return
JSON
.
parse
(
JSON
.
stringify
(
el
.
dataset
||
{}));
}
function
normalizeTarget
(
el
)
{
const
{
id
,
offsetTop
,
offsetLeft
}
=
el
;
return
{
id
,
dataset
:
normalizeDataset
(
el
),
offsetTop
,
offsetLeft
,
};
}
function
plusReady
(
callback
)
{
...
...
@@ -224,4 +233,4 @@ const RESPONSIVE_MIN_WIDTH = 768;
const
COMPONENT_NAME_PREFIX
=
'
VUni
'
;
const
PRIMARY_COLOR
=
'
#007aff
'
;
export
{
BUILT_IN_TAGS
,
COMPONENT_NAME_PREFIX
,
COMPONENT_PREFIX
,
COMPONENT_SELECTOR_PREFIX
,
NAVBAR_HEIGHT
,
PLUS_RE
,
PRIMARY_COLOR
,
RESPONSIVE_MIN_WIDTH
,
TABBAR_HEIGHT
,
TAGS
,
debounce
,
decode
,
decodedQuery
,
getLen
,
invokeArrayFns
,
isBuiltInComponent
,
isCustomElement
,
isNativeTag
,
normalizeDataset
,
once
,
parseQuery
,
passive
,
plusReady
,
removeLeadingSlash
,
stringifyQuery
,
updateElementStyle
};
export
{
BUILT_IN_TAGS
,
COMPONENT_NAME_PREFIX
,
COMPONENT_PREFIX
,
COMPONENT_SELECTOR_PREFIX
,
NAVBAR_HEIGHT
,
PLUS_RE
,
PRIMARY_COLOR
,
RESPONSIVE_MIN_WIDTH
,
TABBAR_HEIGHT
,
TAGS
,
debounce
,
decode
,
decodedQuery
,
getLen
,
invokeArrayFns
,
isBuiltInComponent
,
isCustomElement
,
isNativeTag
,
normalizeDataset
,
normalizeTarget
,
once
,
parseQuery
,
passive
,
plusReady
,
removeLeadingSlash
,
stringifyQuery
,
updateElementStyle
};
packages/uni-shared/src/dom.ts
浏览文件 @
0c2a7644
...
...
@@ -6,3 +6,13 @@ export function normalizeDataset(el: Element) {
// TODO
return
JSON
.
parse
(
JSON
.
stringify
((
el
as
HTMLElement
).
dataset
||
{}))
}
export
function
normalizeTarget
(
el
:
HTMLElement
)
{
const
{
id
,
offsetTop
,
offsetLeft
}
=
el
return
{
id
,
dataset
:
normalizeDataset
(
el
),
offsetTop
,
offsetLeft
,
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录