Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
64f5dddc
U
uni-app
项目概览
MuGuiLin
/
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,发现更多精彩内容 >>
提交
64f5dddc
编写于
5月 05, 2022
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'feat-web-components' into dev
上级
b875aeb4
e67c1637
变更
15
显示空白变更内容
内联
并排
Showing
15 changed file
with
266 addition
and
6 deletion
+266
-6
jsconfig.json
jsconfig.json
+9
-0
packages/uni-template-compiler/lib/app/parser/tag-parser.js
packages/uni-template-compiler/lib/app/parser/tag-parser.js
+9
-0
packages/uni-template-compiler/lib/util.js
packages/uni-template-compiler/lib/util.js
+1
-1
src/core/helpers/custom-elements-define.js
src/core/helpers/custom-elements-define.js
+51
-0
src/core/helpers/index.js
src/core/helpers/index.js
+1
-1
src/core/view/components/index.js
src/core/view/components/index.js
+18
-3
src/core/view/mixins/animation.js
src/core/view/mixins/animation.js
+1
-1
src/platforms/app-plus/view/components/view/index.vue
src/platforms/app-plus/view/components/view/index.vue
+19
-0
src/platforms/app-plus/view/elements/animation.js
src/platforms/app-plus/view/elements/animation.js
+14
-0
src/platforms/app-plus/view/elements/element.js
src/platforms/app-plus/view/elements/element.js
+24
-0
src/platforms/app-plus/view/elements/hover.js
src/platforms/app-plus/view/elements/hover.js
+109
-0
src/platforms/app-plus/view/elements/index.js
src/platforms/app-plus/view/elements/index.js
+5
-0
src/platforms/app-plus/view/elements/view.js
src/platforms/app-plus/view/elements/view.js
+5
-0
src/platforms/h5/view/components/view/README.md
src/platforms/h5/view/components/view/README.md
+0
-0
src/platforms/h5/view/components/view/index.vue
src/platforms/h5/view/components/view/index.vue
+0
-0
未找到文件。
jsconfig.json
浏览文件 @
64f5dddc
...
...
@@ -2,6 +2,15 @@
"compilerOptions"
:
{
"baseUrl"
:
"."
,
"paths"
:
{
"uni-shared"
:
[
"./src/shared/index.js"
],
"uni-helpers/*"
:
[
"./src/core/helpers/*"
],
"uni-mixins/*"
:
[
"./src/core/view/mixins/*"
],
"uni-core/*"
:
[
"./src/core/*"
],
...
...
packages/uni-template-compiler/lib/app/parser/tag-parser.js
浏览文件 @
64f5dddc
...
...
@@ -4,8 +4,17 @@ const {
const
tags
=
require
(
'
@dcloudio/uni-cli-shared/lib/tags
'
)
// web components
const
elements
=
[
'
uni-view
'
]
// 仅限 view 层
module
.
exports
=
function
parseTag
(
el
)
{
const
tag
=
el
.
tag
const
element
=
elements
.
find
(
element
=>
tag
===
element
||
'
uni-
'
+
tag
===
element
)
if
(
element
)
{
el
.
tag
=
element
return
}
if
(
el
.
tag
.
indexOf
(
'
v-uni-
'
)
!==
0
&&
hasOwn
(
tags
,
el
.
tag
))
{
el
.
tag
=
'
v-uni-
'
+
el
.
tag
}
...
...
packages/uni-template-compiler/lib/util.js
浏览文件 @
64f5dddc
...
...
@@ -210,7 +210,7 @@ function isComponent (tagName) {
return
false
}
}
return
!
hasOwn
(
tags
,
getTagName
(
tagName
.
replace
(
'
v-uni-
'
,
''
)))
return
!
hasOwn
(
tags
,
getTagName
(
tagName
.
replace
(
/^
(
v-
)?
uni-/
,
''
)))
}
function
makeMap
(
str
,
expectsLowerCase
)
{
...
...
src/core/helpers/custom-elements-define.js
0 → 100644
浏览文件 @
64f5dddc
/**
* customElements.define
*/
(
function
()
{
const
defineProperty
=
Object
.
defineProperty
const
createElement
=
document
.
createElement
const
classes
=
new
Map
()
const
registry
=
new
Map
()
if
(
'
customElements
'
in
window
&&
customElements
&&
customElements
.
define
)
{
return
}
function
HTMLBuiltIn
()
{
const
constructor
=
this
.
constructor
if
(
!
classes
.
has
(
constructor
))
{
throw
new
TypeError
(
'
Illegal constructor
'
)
}
const
is
=
classes
.
get
(
constructor
)
const
element
=
createElement
.
call
(
document
,
is
)
return
Object
.
setPrototypeOf
(
element
,
constructor
.
prototype
)
}
defineProperty
(
HTMLBuiltIn
.
prototype
=
HTMLElement
.
prototype
,
'
constructor
'
,
{
value
:
HTMLBuiltIn
})
defineProperty
(
window
,
'
HTMLElement
'
,
{
configurable
:
true
,
value
:
HTMLBuiltIn
})
defineProperty
(
document
,
'
createElement
'
,
{
configurable
:
true
,
value
:
function
value
(
name
,
options
)
{
const
is
=
options
&&
options
.
is
const
Class
=
is
?
registry
.
get
(
is
)
:
registry
.
get
(
name
)
return
Class
?
new
Class
()
:
createElement
.
call
(
document
,
name
)
}
})
defineProperty
(
window
,
'
customElements
'
,
{
configurable
:
true
,
value
:
{
define
:
function
define
(
is
,
Class
)
{
if
(
registry
.
has
(
is
))
{
throw
new
Error
(
'
the name "
'
.
concat
(
is
,
'
" has already been used with this registry
'
))
}
classes
.
set
(
Class
,
is
)
registry
.
set
(
is
,
Class
)
}
}
})
})()
src/core/helpers/index.js
浏览文件 @
64f5dddc
...
...
@@ -63,7 +63,7 @@ export function getTargetDataset (target) {
$parent
=
$parent
.
$parent
}
}
else
{
dataset
=
target
.
dataset
||
{}
dataset
=
Object
.
assign
({},
target
.
dataset
,
target
.
__uniDataset
)
}
return
normalizeDataset
(
dataset
)
}
...
...
src/core/view/components/index.js
浏览文件 @
64f5dddc
...
...
@@ -9,6 +9,19 @@ const requireComponents = [
require
.
context
(
'
../../../platforms/
'
+
__PLATFORM__
+
'
/view/components
'
,
true
,
/index
\.
vue$/
)
]
let
elements
=
{}
if
(
__PLATFORM__
===
'
app-plus
'
)
{
// TODO use full polyfill
require
(
'
uni-core/helpers/custom-elements-define
'
)
const
module
=
require
(
'
../../../platforms/app-plus/view/elements/index.js
'
)
elements
=
module
.
default
||
module
for
(
const
key
in
elements
)
{
// TODO use kebabCase
customElements
.
define
(
`uni-
${
key
.
toLowerCase
()}
`
,
elements
[
key
])
}
}
requireComponents
.
forEach
((
components
,
index
)
=>
{
components
.
keys
().
forEach
(
fileName
=>
{
// 获取组件配置
...
...
@@ -18,7 +31,9 @@ requireComponents.forEach((components, index) => {
componentConfig
.
mixins
=
componentConfig
.
mixins
?
[].
concat
(
baseMixin
,
componentConfig
.
mixins
)
:
[
baseMixin
]
if
(
!
componentConfig
.
functional
)
{
componentConfig
.
mixins
.
push
(
animation
)
}
componentConfig
.
name
=
'
VUni
'
+
componentConfig
.
name
...
...
src/core/view/mixins/animation.js
浏览文件 @
64f5dddc
...
...
@@ -51,7 +51,7 @@ function getStyle (action) {
return
style
}
function
startAnimation
(
context
)
{
export
function
startAnimation
(
context
)
{
const
animation
=
context
.
animation
if
(
!
animation
||
!
animation
.
actions
||
!
animation
.
actions
.
length
)
{
return
...
...
src/platforms/app-plus/view/components/view/index.vue
0 → 100644
浏览文件 @
64f5dddc
<
script
>
export
default
{
name
:
'
View
'
,
functional
:
true
,
render
(
createElement
,
context
)
{
return
createElement
(
'
uni-view
'
,
context
.
data
,
context
.
children
)
}
}
</
script
>
<
style
>
uni-view
{
display
:
block
;
}
uni-view
[
hidden
]
{
display
:
none
;
}
</
style
>
src/platforms/app-plus/view/elements/animation.js
0 → 100644
浏览文件 @
64f5dddc
import
UniElement
from
'
./element
'
import
{
startAnimation
}
from
'
uni-core/view/mixins/animation
'
export
default
class
UniAnimationElement
extends
UniElement
{
setAttribute
(
key
,
value
)
{
if
(
key
===
'
animation
'
)
{
startAnimation
({
$el
:
this
,
animation
:
value
})
}
super
.
setAttribute
(
key
,
value
)
}
}
src/platforms/app-plus/view/elements/element.js
0 → 100644
浏览文件 @
64f5dddc
import
{
camelize
}
from
'
uni-shared
'
function
formatKey
(
key
)
{
return
camelize
(
key
.
substring
(
5
))
}
export
default
class
UniElement
extends
HTMLElement
{
setAttribute
(
key
,
value
)
{
if
(
key
.
startsWith
(
'
data-
'
))
{
const
dataset
=
this
.
__uniDataset
||
(
this
.
__uniDataset
=
{})
dataset
[
formatKey
(
key
)]
=
value
}
super
.
setAttribute
(
key
,
value
)
}
removeAttribute
(
key
)
{
if
(
this
.
__uniDataset
&&
key
.
startsWith
(
'
data-
'
))
{
delete
this
.
__uniDataset
[
formatKey
(
key
)]
}
super
.
removeAttribute
(
key
)
}
}
src/platforms/app-plus/view/elements/hover.js
0 → 100644
浏览文件 @
64f5dddc
import
UniAnimationElement
from
'
./animation
'
export
default
class
UniHoverElement
extends
UniAnimationElement
{
setAttribute
(
key
,
value
)
{
console
.
log
(
'
setAttribute:
'
,
key
,
value
)
if
(
key
===
'
hover-class
'
)
{
this
.
_updateHoverClass
(
value
)
}
super
.
setAttribute
(
key
,
value
)
}
removeAttribute
(
key
)
{
if
(
key
===
'
hover-class
'
)
{
this
.
_updateHoverClass
()
}
super
.
removeAttribute
(
key
)
}
get
hovering
()
{
return
this
.
_hovering
}
set
hovering
(
hovering
)
{
this
.
_hovering
=
hovering
const
hoverClass
=
this
.
getAttribute
(
'
hover-class
'
)
if
(
hovering
)
{
this
.
classList
.
add
(
hoverClass
)
}
else
{
this
.
classList
.
remove
(
hoverClass
)
}
}
_updateHoverClass
(
hoverClass
)
{
hoverClass
=
hoverClass
||
'
none
'
if
(
hoverClass
===
'
none
'
)
{
this
.
_removeEventListener
()
}
else
{
this
.
_addEventListener
()
}
}
_addEventListener
()
{
if
(
!
this
.
__hoverTouchStart
)
{
this
.
addEventListener
(
'
touchstart
'
,
this
.
__hoverTouchStart
=
this
.
_hoverTouchStart
.
bind
(
this
))
this
.
addEventListener
(
'
touchend
'
,
this
.
__hoverTouchEnd
=
this
.
_hoverTouchEnd
.
bind
(
this
))
this
.
addEventListener
(
'
touchcancel
'
,
this
.
__hoverTouchCancel
=
this
.
_hoverTouchCancel
.
bind
(
this
))
}
}
_removeEventListener
()
{
if
(
this
.
__hoverTouchStart
)
{
this
.
removeEventListener
(
'
touchstart
'
,
this
.
__hoverTouchStart
)
delete
this
.
__hoverTouchStart
this
.
removeEventListener
(
'
touchend
'
,
this
.
__hoverTouchEnd
)
delete
this
.
__hoverTouchEnd
this
.
removeEventListener
(
'
touchcancel
'
,
this
.
__hoverTouchCancel
)
delete
this
.
__hoverTouchCancel
}
}
_hoverTouchStart
(
evt
)
{
if
(
evt
.
_hoverPropagationStopped
)
{
return
}
if
(
this
.
disabled
)
{
return
}
if
(
evt
.
touches
.
length
>
1
)
{
return
}
if
(
this
.
getAttribute
(
'
hover-stop-propagation
'
))
{
evt
.
_hoverPropagationStopped
=
true
}
this
.
_hoverTouch
=
true
const
hoverStartTimeDefault
=
50
const
hoverStartTime
=
Number
(
this
.
getAttribute
(
'
hover-start-time
'
)
||
hoverStartTimeDefault
)
this
.
_hoverStartTimer
=
setTimeout
(()
=>
{
this
.
hovering
=
true
if
(
!
this
.
_hoverTouch
)
{
// 防止在hoverStartTime时间内触发了 touchend 或 touchcancel
this
.
_hoverReset
()
}
},
isNaN
(
hoverStartTime
)
?
hoverStartTimeDefault
:
hoverStartTime
)
}
_hoverTouchEnd
()
{
this
.
_hoverTouch
=
false
if
(
this
.
hovering
)
{
this
.
_hoverReset
()
}
}
_hoverReset
()
{
requestAnimationFrame
(()
=>
{
clearTimeout
(
this
.
_hoverStayTimer
)
const
hoverStayTimeDefault
=
400
const
hoverStayTime
=
Number
(
this
.
getAttribute
(
'
hover-stay-time
'
)
||
hoverStayTimeDefault
)
this
.
_hoverStayTimer
=
setTimeout
(()
=>
{
this
.
hovering
=
false
},
isNaN
(
hoverStayTime
)
?
hoverStayTimeDefault
:
hoverStayTime
)
})
}
_hoverTouchCancel
()
{
this
.
_hoverTouch
=
false
this
.
hovering
=
false
clearTimeout
(
this
.
_hoverStartTimer
)
}
}
src/platforms/app-plus/view/elements/index.js
0 → 100644
浏览文件 @
64f5dddc
import
View
from
'
./view
'
export
default
{
View
}
src/platforms/app-plus/view/elements/view.js
0 → 100644
浏览文件 @
64f5dddc
import
UniHoverElement
from
'
./hover
'
export
default
class
UniView
extends
UniHoverElement
{
}
src/
core
/view/components/view/README.md
→
src/
platforms/h5
/view/components/view/README.md
浏览文件 @
64f5dddc
文件已移动
src/
core
/view/components/view/index.vue
→
src/
platforms/h5
/view/components/view/index.vue
浏览文件 @
64f5dddc
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录