Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
陈庄旺
uni-app
提交
f4adc423
U
uni-app
项目概览
陈庄旺
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f4adc423
编写于
10月 25, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): remove unused
上级
b5819672
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
265 addition
and
1588 deletion
+265
-1588
packages/uni-mp-alipay/dist/uni.mp.esm.js
packages/uni-mp-alipay/dist/uni.mp.esm.js
+32
-192
packages/uni-mp-baidu/dist/uni.mp.esm.js
packages/uni-mp-baidu/dist/uni.mp.esm.js
+33
-203
packages/uni-mp-core/src/runtime/componentInstance/index.ts
packages/uni-mp-core/src/runtime/componentInstance/index.ts
+1
-79
packages/uni-mp-core/src/runtime/componentInstance/utils.ts
packages/uni-mp-core/src/runtime/componentInstance/utils.ts
+0
-119
packages/uni-mp-core/src/runtime/componentProps.ts
packages/uni-mp-core/src/runtime/componentProps.ts
+32
-26
packages/uni-mp-kuaishou/dist/uni.mp.esm.js
packages/uni-mp-kuaishou/dist/uni.mp.esm.js
+33
-192
packages/uni-mp-qq/dist/uni.mp.esm.js
packages/uni-mp-qq/dist/uni.mp.esm.js
+33
-192
packages/uni-mp-toutiao/dist/uni.mp.esm.js
packages/uni-mp-toutiao/dist/uni.mp.esm.js
+33
-192
packages/uni-mp-vue/dist/vue.runtime.esm.js
packages/uni-mp-vue/dist/vue.runtime.esm.js
+1
-5
packages/uni-mp-vue/src/helpers/renderSlot.ts
packages/uni-mp-vue/src/helpers/renderSlot.ts
+1
-4
packages/uni-mp-weixin/dist/uni.mp.esm.js
packages/uni-mp-weixin/dist/uni.mp.esm.js
+33
-192
packages/uni-quickapp-webview/dist/uni.mp.esm.js
packages/uni-quickapp-webview/dist/uni.mp.esm.js
+33
-192
未找到文件。
packages/uni-mp-alipay/dist/uni.mp.esm.js
浏览文件 @
f4adc423
import
{
isPlainObject
,
extend
,
hyphenate
,
isObject
,
hasOwn
,
isArray
,
toNumber
,
capitalize
,
isFunction
,
EMPTY_OBJ
,
camelize
}
from
'
@vue/shared
'
;
import
{
isPlainObject
,
hasOwn
,
capitalize
,
isFunction
,
extend
,
isArray
,
EMPTY_OBJ
,
camelize
}
from
'
@vue/shared
'
;
import
{
injectHook
,
ref
}
from
'
vue
'
;
const
encode
=
encodeURIComponent
;
...
...
@@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) {
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
function
getDataByPath
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
const
key
=
parts
[
0
];
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getDataByPath
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
...
...
@@ -143,154 +123,6 @@ function getEventChannel(id) {
return
eventChannelStack
.
shift
();
}
function
getValue
(
dataPath
,
target
)
{
return
getDataByPath
(
target
||
this
,
dataPath
);
}
function
getClass
(
dynamicClass
,
staticClass
)
{
return
renderClass
(
staticClass
,
dynamicClass
);
}
function
getStyle
(
dynamicStyle
,
staticStyle
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
;
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
);
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
;
return
Object
.
keys
(
styleObj
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
styleObj
[
name
];
})
.
join
(
'
;
'
);
}
function
toObject
(
arr
)
{
var
res
=
{};
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
]);
}
}
return
res
;
}
function
normalizeStyleBinding
(
bindingStyle
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
);
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
);
}
return
bindingStyle
;
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{};
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
;
var
propertyDelimiter
=
/:
(
.+
)
/
;
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
);
tmp
.
length
>
1
&&
(
res
[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
());
}
});
return
res
;
});
function
isDef
(
v
)
{
return
v
!==
undefined
&&
v
!==
null
;
}
function
renderClass
(
staticClass
,
dynamicClass
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
));
}
/* istanbul ignore next */
return
''
;
}
function
concat
(
a
,
b
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
;
}
function
stringifyClass
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
);
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
);
}
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
/* istanbul ignore next */
return
''
;
}
function
stringifyArray
(
value
)
{
var
res
=
''
;
var
stringified
;
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
stringified
;
}
}
return
res
;
}
function
stringifyObject
(
value
)
{
var
res
=
''
;
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
key
;
}
}
return
res
;
}
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
value
=
value
.
trim
();
}
if
(
modifiers
.
indexOf
(
'
number
'
)
!==
-
1
)
{
value
=
toNumber
(
value
);
}
}
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
setSync
(
target
,
key
,
value
)
{
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
getOrig
(
data
)
{
if
(
isPlainObject
(
data
))
{
return
data
.
$orig
||
data
;
}
return
data
;
}
function
map
(
val
,
iteratee
)
{
let
ret
,
i
,
l
,
keys
,
key
;
if
(
isArray
(
val
))
{
ret
=
new
Array
(
val
.
length
);
for
(
i
=
0
,
l
=
val
.
length
;
i
<
l
;
i
++
)
{
ret
[
i
]
=
iteratee
(
val
[
i
],
i
);
}
return
ret
;
}
else
if
(
isObject
(
val
))
{
keys
=
Object
.
keys
(
val
);
ret
=
Object
.
create
(
null
);
for
(
i
=
0
,
l
=
keys
.
length
;
i
<
l
;
i
++
)
{
key
=
keys
[
i
];
ret
[
key
]
=
iteratee
(
val
[
key
],
key
,
i
);
}
return
ret
;
}
return
[];
}
const
MP_METHODS
=
[
'
createSelectorQuery
'
,
'
createIntersectionObserver
'
,
...
...
@@ -358,15 +190,6 @@ function initComponentInstance(instance, options) {
}
};
});
// TODO other
ctx
.
__set_model
=
setModel
;
ctx
.
__set_sync
=
setSync
;
ctx
.
__get_orig
=
getOrig
;
// TODO
ctx
.
__get_value
=
getValue
;
ctx
.
__get_class
=
getClass
;
ctx
.
__get_style
=
getStyle
;
ctx
.
__map
=
map
;
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
const
ctx
=
instance
.
ctx
;
...
...
@@ -559,19 +382,30 @@ function findVmByVueId(instance, vuePid) {
}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
function
parsePropType
(
key
,
type
,
defaultValue
)
{
// [String]=>String
if
(
isArray
(
type
)
&&
type
.
length
===
1
)
{
return
type
[
0
];
}
return
type
;
}
// function parsePropType(key: string, type: unknown, defaultValue: unknown) {
// // [String]=>String
// if (isArray(type) && type.length === 1) {
// return type[0]
// }
// if ("mp-alipay" === 'mp-baidu') {
// if (
// // [String,Boolean]=>Boolean
// defaultValue === false &&
// isArray(type) &&
// type.length === 2 &&
// type.indexOf(String) !== -1 &&
// type.indexOf(Boolean) !== -1
// ) {
// return Boolean
// }
// }
// return type
// }
function
initDefaultProps
(
isBehavior
=
false
)
{
const
properties
=
{};
if
(
!
isBehavior
)
{
properties
.
vI
=
{
type
:
String
,
type
:
null
,
value
:
''
,
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
...
...
@@ -596,6 +430,12 @@ function createProperty(key, prop) {
return
prop
;
}
}
/**
* 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value
* @param mpComponentOptions
* @param rawProps
* @param isBehavior
*/
function
initProps
(
mpComponentOptions
,
rawProps
,
isBehavior
=
false
)
{
const
properties
=
initDefaultProps
(
isBehavior
);
if
(
isArray
(
rawProps
))
{
...
...
@@ -614,18 +454,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) {
if
(
isFunction
(
value
))
{
value
=
value
();
}
const
type
=
opts
.
type
;
opts
.
type
=
parsePropType
(
key
,
type
);
// const type = (opts as any).type as any
// ;(opts as any).type = parsePropType(key, type, value)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
value
,
});
}
else
{
// content:String
const
type
=
parsePropType
(
key
,
opts
);
// const type = parsePropType(key, opts, null)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
//
PROP_TYPES.indexOf(type) !== -1 ? type : null,
});
}
});
...
...
packages/uni-mp-baidu/dist/uni.mp.esm.js
浏览文件 @
f4adc423
import
{
isPlainObject
,
extend
,
hyphenate
,
isObject
,
isArray
,
hasOwn
,
toNumber
,
isFunction
,
camelize
}
from
'
@vue/shared
'
;
import
{
isPlainObject
,
isArray
,
hasOwn
,
isFunction
,
extend
,
camelize
}
from
'
@vue/shared
'
;
import
{
injectHook
,
ref
}
from
'
vue
'
;
const
encode
=
encodeURIComponent
;
...
...
@@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) {
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
function
getDataByPath
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
const
key
=
parts
[
0
];
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getDataByPath
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
...
...
@@ -141,154 +121,6 @@ function getEventChannel(id) {
return
eventChannelStack
.
shift
();
}
function
getValue
(
dataPath
,
target
)
{
return
getDataByPath
(
target
||
this
,
dataPath
);
}
function
getClass
(
dynamicClass
,
staticClass
)
{
return
renderClass
(
staticClass
,
dynamicClass
);
}
function
getStyle
(
dynamicStyle
,
staticStyle
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
;
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
);
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
;
return
Object
.
keys
(
styleObj
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
styleObj
[
name
];
})
.
join
(
'
;
'
);
}
function
toObject
(
arr
)
{
var
res
=
{};
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
]);
}
}
return
res
;
}
function
normalizeStyleBinding
(
bindingStyle
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
);
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
);
}
return
bindingStyle
;
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{};
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
;
var
propertyDelimiter
=
/:
(
.+
)
/
;
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
);
tmp
.
length
>
1
&&
(
res
[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
());
}
});
return
res
;
});
function
isDef
(
v
)
{
return
v
!==
undefined
&&
v
!==
null
;
}
function
renderClass
(
staticClass
,
dynamicClass
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
));
}
/* istanbul ignore next */
return
''
;
}
function
concat
(
a
,
b
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
;
}
function
stringifyClass
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
);
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
);
}
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
/* istanbul ignore next */
return
''
;
}
function
stringifyArray
(
value
)
{
var
res
=
''
;
var
stringified
;
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
stringified
;
}
}
return
res
;
}
function
stringifyObject
(
value
)
{
var
res
=
''
;
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
key
;
}
}
return
res
;
}
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
value
=
value
.
trim
();
}
if
(
modifiers
.
indexOf
(
'
number
'
)
!==
-
1
)
{
value
=
toNumber
(
value
);
}
}
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
setSync
(
target
,
key
,
value
)
{
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
getOrig
(
data
)
{
if
(
isPlainObject
(
data
))
{
return
data
.
$orig
||
data
;
}
return
data
;
}
function
map
(
val
,
iteratee
)
{
let
ret
,
i
,
l
,
keys
,
key
;
if
(
isArray
(
val
))
{
ret
=
new
Array
(
val
.
length
);
for
(
i
=
0
,
l
=
val
.
length
;
i
<
l
;
i
++
)
{
ret
[
i
]
=
iteratee
(
val
[
i
],
i
);
}
return
ret
;
}
else
if
(
isObject
(
val
))
{
keys
=
Object
.
keys
(
val
);
ret
=
Object
.
create
(
null
);
for
(
i
=
0
,
l
=
keys
.
length
;
i
<
l
;
i
++
)
{
key
=
keys
[
i
];
ret
[
key
]
=
iteratee
(
val
[
key
],
key
,
i
);
}
return
ret
;
}
return
[];
}
const
MP_METHODS
=
[
'
createSelectorQuery
'
,
'
createIntersectionObserver
'
,
...
...
@@ -347,15 +179,6 @@ function initComponentInstance(instance, options) {
}
};
});
// TODO other
ctx
.
__set_model
=
setModel
;
ctx
.
__set_sync
=
setSync
;
ctx
.
__get_orig
=
getOrig
;
// TODO
ctx
.
__get_value
=
getValue
;
ctx
.
__get_class
=
getClass
;
ctx
.
__get_style
=
getStyle
;
ctx
.
__map
=
map
;
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
const
ctx
=
instance
.
ctx
;
...
...
@@ -580,7 +403,7 @@ function findVmByVueId(instance, vuePid) {
}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
// const PROP_TYPES = [String, Number, Boolean, Object, Array, null]
function
createObserver
(
name
)
{
return
function
observer
(
newVal
)
{
if
(
this
.
$vm
)
{
...
...
@@ -588,29 +411,30 @@ function createObserver(name) {
}
};
}
function
parsePropType
(
key
,
type
,
defaultValue
)
{
// [String]=>String
if
(
isArray
(
type
)
&&
type
.
length
===
1
)
{
return
type
[
0
];
}
{
if
(
// [String,Boolean]=>Boolean
defaultValue
===
false
&&
isArray
(
type
)
&&
type
.
length
===
2
&&
type
.
indexOf
(
String
)
!==
-
1
&&
type
.
indexOf
(
Boolean
)
!==
-
1
)
{
return
Boolean
;
}
}
return
type
;
}
// function parsePropType(key: string, type: unknown, defaultValue: unknown) {
// // [String]=>String
// if (isArray(type) && type.length === 1) {
// return type[0]
// }
// if ("mp-baidu" === 'mp-baidu') {
// if (
// // [String,Boolean]=>Boolean
// defaultValue === false &&
// isArray(type) &&
// type.length === 2 &&
// type.indexOf(String) !== -1 &&
// type.indexOf(Boolean) !== -1
// ) {
// return Boolean
// }
// }
// return type
// }
function
initDefaultProps
(
isBehavior
=
false
)
{
const
properties
=
{};
if
(
!
isBehavior
)
{
properties
.
vI
=
{
type
:
String
,
type
:
null
,
value
:
''
,
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
...
...
@@ -634,6 +458,12 @@ function createProperty(key, prop) {
prop
.
observer
=
createObserver
(
key
);
return
prop
;
}
/**
* 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value
* @param mpComponentOptions
* @param rawProps
* @param isBehavior
*/
function
initProps
(
mpComponentOptions
,
rawProps
,
isBehavior
=
false
)
{
const
properties
=
initDefaultProps
(
isBehavior
);
if
(
isArray
(
rawProps
))
{
...
...
@@ -652,18 +482,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) {
if
(
isFunction
(
value
))
{
value
=
value
();
}
const
type
=
opts
.
type
;
opts
.
type
=
parsePropType
(
key
,
type
,
value
);
// const type = (opts as any).type as any
// ;(opts as any).type = parsePropType(key, type, value)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
value
,
});
}
else
{
// content:String
const
type
=
parsePropType
(
key
,
opts
,
null
);
// const type = parsePropType(key, opts, null)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
//
PROP_TYPES.indexOf(type) !== -1 ? type : null,
});
}
});
...
...
packages/uni-mp-core/src/runtime/componentInstance/index.ts
浏览文件 @
f4adc423
import
{
EventChannel
,
invokeArrayFns
}
from
'
@dcloudio/uni-shared
'
import
{
capitalize
,
hasOwn
,
isArray
,
toNumber
,
isObject
,
isPlainObject
,
}
from
'
@vue/shared
'
import
{
capitalize
,
hasOwn
,
isArray
}
from
'
@vue/shared
'
import
{
ComponentPublicInstance
,
ComponentInternalInstance
}
from
'
vue
'
import
{
getEventChannel
}
from
'
../../api/protocols/navigateTo
'
import
{
MPComponentInstance
}
from
'
../component
'
import
{
getClass
,
getStyle
,
getValue
}
from
'
./utils
'
function
setModel
(
this
:
ComponentPublicInstance
,
target
:
ComponentPublicInstance
,
key
:
string
,
value
:
any
,
modifiers
:
string
[]
)
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
value
=
(
value
as
string
).
trim
()
}
if
(
modifiers
.
indexOf
(
'
number
'
)
!==
-
1
)
{
value
=
toNumber
(
value
)
}
}
if
(
!
target
)
{
target
=
this
}
;(
target
as
any
)[
key
]
=
value
}
function
setSync
(
this
:
ComponentPublicInstance
,
target
:
ComponentPublicInstance
,
key
:
string
,
value
:
any
)
{
if
(
!
target
)
{
target
=
this
}
;(
target
as
any
)[
key
]
=
value
}
function
getOrig
(
data
:
unknown
)
{
if
(
isPlainObject
(
data
))
{
return
(
data
as
any
).
$orig
||
data
}
return
data
}
function
map
(
val
:
unknown
,
iteratee
:
Function
)
{
let
ret
,
i
,
l
,
keys
,
key
if
(
isArray
(
val
))
{
ret
=
new
Array
(
val
.
length
)
for
(
i
=
0
,
l
=
val
.
length
;
i
<
l
;
i
++
)
{
ret
[
i
]
=
iteratee
(
val
[
i
],
i
)
}
return
ret
}
else
if
(
isObject
(
val
))
{
keys
=
Object
.
keys
(
val
)
ret
=
Object
.
create
(
null
)
for
(
i
=
0
,
l
=
keys
.
length
;
i
<
l
;
i
++
)
{
key
=
keys
[
i
]
ret
[
key
]
=
iteratee
(
val
[
key
],
key
,
i
)
}
return
ret
}
return
[]
}
const
MP_METHODS
=
[
'
createSelectorQuery
'
,
...
...
@@ -179,16 +111,6 @@ export function initComponentInstance(
}
}
})
// TODO other
ctx
.
__set_model
=
setModel
ctx
.
__set_sync
=
setSync
ctx
.
__get_orig
=
getOrig
// TODO
ctx
.
__get_value
=
getValue
ctx
.
__get_class
=
getClass
ctx
.
__get_style
=
getStyle
ctx
.
__map
=
map
}
export
function
initMocks
(
...
...
packages/uni-mp-core/src/runtime/componentInstance/utils.ts
已删除
100644 → 0
浏览文件 @
b5819672
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
extend
,
isObject
,
hyphenate
}
from
'
@vue/shared
'
import
{
cache
,
getDataByPath
}
from
'
@dcloudio/uni-shared
'
export
function
getValue
(
this
:
ComponentPublicInstance
,
dataPath
:
string
,
target
:
Record
<
string
,
any
>
)
{
return
getDataByPath
(
target
||
this
,
dataPath
)
}
export
function
getClass
(
dynamicClass
:
unknown
,
staticClass
:
string
)
{
return
renderClass
(
staticClass
,
dynamicClass
)
}
export
function
getStyle
(
dynamicStyle
:
unknown
,
staticStyle
:
string
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
)
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
return
Object
.
keys
(
styleObj
as
any
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
(
styleObj
as
any
)[
name
]
})
.
join
(
'
;
'
)
}
function
toObject
(
arr
:
unknown
[])
{
var
res
=
{}
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
])
}
}
return
res
}
function
normalizeStyleBinding
(
bindingStyle
:
unknown
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
)
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
)
}
return
bindingStyle
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{}
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
var
propertyDelimiter
=
/:
(
.+
)
/
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
)
tmp
.
length
>
1
&&
((
res
as
any
)[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
())
}
})
return
res
})
function
isDef
(
v
:
unknown
)
{
return
v
!==
undefined
&&
v
!==
null
}
function
renderClass
(
staticClass
:
string
,
dynamicClass
:
unknown
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
))
}
/* istanbul ignore next */
return
''
}
function
concat
(
a
?:
string
,
b
?:
string
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
}
function
stringifyClass
(
value
:
unknown
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
)
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
)
}
if
(
typeof
value
===
'
string
'
)
{
return
value
}
/* istanbul ignore next */
return
''
}
function
stringifyArray
(
value
:
unknown
[])
{
var
res
=
''
var
stringified
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
}
res
+=
stringified
}
}
return
res
}
function
stringifyObject
(
value
:
Record
<
string
,
any
>
)
{
var
res
=
''
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
}
res
+=
key
}
}
return
res
}
packages/uni-mp-core/src/runtime/componentProps.ts
浏览文件 @
f4adc423
...
...
@@ -4,7 +4,7 @@ import { MPComponentOptions, MPComponentInstance } from './component'
import
Component
=
WechatMiniprogram
.
Component
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
]
//
const PROP_TYPES = [String, Number, Boolean, Object, Array, null]
function
createObserver
(
name
:
string
)
{
return
function
observer
(
this
:
MPComponentInstance
,
newVal
:
unknown
)
{
...
...
@@ -14,31 +14,31 @@ function createObserver(name: string) {
}
}
function
parsePropType
(
key
:
string
,
type
:
unknown
,
defaultValue
:
unknown
)
{
// [String]=>String
if
(
isArray
(
type
)
&&
type
.
length
===
1
)
{
return
type
[
0
]
}
if
(
__PLATFORM__
===
'
mp-baidu
'
)
{
if
(
// [String,Boolean]=>Boolean
defaultValue
===
false
&&
isArray
(
type
)
&&
type
.
length
===
2
&&
type
.
indexOf
(
String
)
!==
-
1
&&
type
.
indexOf
(
Boolean
)
!==
-
1
)
{
return
Boolean
}
}
return
type
}
//
function parsePropType(key: string, type: unknown, defaultValue: unknown) {
//
// [String]=>String
//
if (isArray(type) && type.length === 1) {
//
return type[0]
//
}
//
if (__PLATFORM__ === 'mp-baidu') {
//
if (
//
// [String,Boolean]=>Boolean
//
defaultValue === false &&
//
isArray(type) &&
//
type.length === 2 &&
//
type.indexOf(String) !== -1 &&
//
type.indexOf(Boolean) !== -1
//
) {
//
return Boolean
//
}
//
}
//
return type
//
}
function
initDefaultProps
(
isBehavior
:
boolean
=
false
)
{
const
properties
:
Component
.
PropertyOption
=
{}
if
(
!
isBehavior
)
{
properties
.
vI
=
{
type
:
String
,
type
:
null
,
// 均不指定类型,避免 property received type-uncompatible value 警告
value
:
''
,
}
if
(
__PLATFORM__
===
'
mp-toutiao
'
)
{
...
...
@@ -73,6 +73,12 @@ function createProperty(key: string, prop: any) {
return
prop
}
/**
* 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value
* @param mpComponentOptions
* @param rawProps
* @param isBehavior
*/
export
function
initProps
(
mpComponentOptions
:
MPComponentOptions
,
rawProps
:
ComponentPropsOptions
|
null
,
...
...
@@ -95,17 +101,17 @@ export function initProps(
if
(
isFunction
(
value
))
{
value
=
value
()
}
const
type
=
(
opts
as
any
).
type
as
any
;(
opts
as
any
).
type
=
parsePropType
(
key
,
type
,
value
)
//
const type = (opts as any).type as any
//
;(opts as any).type = parsePropType(key, type, value)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
//
PROP_TYPES.indexOf(type) !== -1 ? type : null,
value
,
})
}
else
{
// content:String
const
type
=
parsePropType
(
key
,
opts
,
null
)
//
const type = parsePropType(key, opts, null)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
//
PROP_TYPES.indexOf(type) !== -1 ? type : null,
})
}
})
...
...
packages/uni-mp-kuaishou/dist/uni.mp.esm.js
浏览文件 @
f4adc423
import
{
isPlainObject
,
extend
,
hyphenate
,
isObject
,
isArray
,
hasOwn
,
toNumber
,
isFunction
,
camelize
}
from
'
@vue/shared
'
;
import
{
isPlainObject
,
isArray
,
hasOwn
,
isFunction
,
extend
,
camelize
}
from
'
@vue/shared
'
;
import
{
injectHook
,
ref
}
from
'
vue
'
;
const
encode
=
encodeURIComponent
;
...
...
@@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) {
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
function
getDataByPath
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
const
key
=
parts
[
0
];
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getDataByPath
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
...
...
@@ -141,154 +121,6 @@ function getEventChannel(id) {
return
eventChannelStack
.
shift
();
}
function
getValue
(
dataPath
,
target
)
{
return
getDataByPath
(
target
||
this
,
dataPath
);
}
function
getClass
(
dynamicClass
,
staticClass
)
{
return
renderClass
(
staticClass
,
dynamicClass
);
}
function
getStyle
(
dynamicStyle
,
staticStyle
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
;
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
);
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
;
return
Object
.
keys
(
styleObj
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
styleObj
[
name
];
})
.
join
(
'
;
'
);
}
function
toObject
(
arr
)
{
var
res
=
{};
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
]);
}
}
return
res
;
}
function
normalizeStyleBinding
(
bindingStyle
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
);
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
);
}
return
bindingStyle
;
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{};
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
;
var
propertyDelimiter
=
/:
(
.+
)
/
;
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
);
tmp
.
length
>
1
&&
(
res
[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
());
}
});
return
res
;
});
function
isDef
(
v
)
{
return
v
!==
undefined
&&
v
!==
null
;
}
function
renderClass
(
staticClass
,
dynamicClass
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
));
}
/* istanbul ignore next */
return
''
;
}
function
concat
(
a
,
b
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
;
}
function
stringifyClass
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
);
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
);
}
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
/* istanbul ignore next */
return
''
;
}
function
stringifyArray
(
value
)
{
var
res
=
''
;
var
stringified
;
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
stringified
;
}
}
return
res
;
}
function
stringifyObject
(
value
)
{
var
res
=
''
;
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
key
;
}
}
return
res
;
}
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
value
=
value
.
trim
();
}
if
(
modifiers
.
indexOf
(
'
number
'
)
!==
-
1
)
{
value
=
toNumber
(
value
);
}
}
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
setSync
(
target
,
key
,
value
)
{
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
getOrig
(
data
)
{
if
(
isPlainObject
(
data
))
{
return
data
.
$orig
||
data
;
}
return
data
;
}
function
map
(
val
,
iteratee
)
{
let
ret
,
i
,
l
,
keys
,
key
;
if
(
isArray
(
val
))
{
ret
=
new
Array
(
val
.
length
);
for
(
i
=
0
,
l
=
val
.
length
;
i
<
l
;
i
++
)
{
ret
[
i
]
=
iteratee
(
val
[
i
],
i
);
}
return
ret
;
}
else
if
(
isObject
(
val
))
{
keys
=
Object
.
keys
(
val
);
ret
=
Object
.
create
(
null
);
for
(
i
=
0
,
l
=
keys
.
length
;
i
<
l
;
i
++
)
{
key
=
keys
[
i
];
ret
[
key
]
=
iteratee
(
val
[
key
],
key
,
i
);
}
return
ret
;
}
return
[];
}
const
MP_METHODS
=
[
'
createSelectorQuery
'
,
'
createIntersectionObserver
'
,
...
...
@@ -347,15 +179,6 @@ function initComponentInstance(instance, options) {
}
};
});
// TODO other
ctx
.
__set_model
=
setModel
;
ctx
.
__set_sync
=
setSync
;
ctx
.
__get_orig
=
getOrig
;
// TODO
ctx
.
__get_value
=
getValue
;
ctx
.
__get_class
=
getClass
;
ctx
.
__get_style
=
getStyle
;
ctx
.
__map
=
map
;
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
const
ctx
=
instance
.
ctx
;
...
...
@@ -580,7 +403,7 @@ function findVmByVueId(instance, vuePid) {
}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
// const PROP_TYPES = [String, Number, Boolean, Object, Array, null]
function
createObserver
(
name
)
{
return
function
observer
(
newVal
)
{
if
(
this
.
$vm
)
{
...
...
@@ -588,18 +411,30 @@ function createObserver(name) {
}
};
}
function
parsePropType
(
key
,
type
,
defaultValue
)
{
// [String]=>String
if
(
isArray
(
type
)
&&
type
.
length
===
1
)
{
return
type
[
0
];
}
return
type
;
}
// function parsePropType(key: string, type: unknown, defaultValue: unknown) {
// // [String]=>String
// if (isArray(type) && type.length === 1) {
// return type[0]
// }
// if ("mp-kuaishou" === 'mp-baidu') {
// if (
// // [String,Boolean]=>Boolean
// defaultValue === false &&
// isArray(type) &&
// type.length === 2 &&
// type.indexOf(String) !== -1 &&
// type.indexOf(Boolean) !== -1
// ) {
// return Boolean
// }
// }
// return type
// }
function
initDefaultProps
(
isBehavior
=
false
)
{
const
properties
=
{};
if
(
!
isBehavior
)
{
properties
.
vI
=
{
type
:
String
,
type
:
null
,
value
:
''
,
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
...
...
@@ -623,6 +458,12 @@ function createProperty(key, prop) {
prop
.
observer
=
createObserver
(
key
);
return
prop
;
}
/**
* 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value
* @param mpComponentOptions
* @param rawProps
* @param isBehavior
*/
function
initProps
(
mpComponentOptions
,
rawProps
,
isBehavior
=
false
)
{
const
properties
=
initDefaultProps
(
isBehavior
);
if
(
isArray
(
rawProps
))
{
...
...
@@ -641,18 +482,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) {
if
(
isFunction
(
value
))
{
value
=
value
();
}
const
type
=
opts
.
type
;
opts
.
type
=
parsePropType
(
key
,
type
);
// const type = (opts as any).type as any
// ;(opts as any).type = parsePropType(key, type, value)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
value
,
});
}
else
{
// content:String
const
type
=
parsePropType
(
key
,
opts
);
// const type = parsePropType(key, opts, null)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
//
PROP_TYPES.indexOf(type) !== -1 ? type : null,
});
}
});
...
...
packages/uni-mp-qq/dist/uni.mp.esm.js
浏览文件 @
f4adc423
import
{
isPlainObject
,
extend
,
hyphenate
,
isObject
,
isArray
,
hasOwn
,
toNumber
,
isFunction
,
camelize
}
from
'
@vue/shared
'
;
import
{
isPlainObject
,
isArray
,
hasOwn
,
isFunction
,
extend
,
camelize
}
from
'
@vue/shared
'
;
import
{
injectHook
,
ref
}
from
'
vue
'
;
const
encode
=
encodeURIComponent
;
...
...
@@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) {
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
function
getDataByPath
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
const
key
=
parts
[
0
];
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getDataByPath
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
...
...
@@ -141,154 +121,6 @@ function getEventChannel(id) {
return
eventChannelStack
.
shift
();
}
function
getValue
(
dataPath
,
target
)
{
return
getDataByPath
(
target
||
this
,
dataPath
);
}
function
getClass
(
dynamicClass
,
staticClass
)
{
return
renderClass
(
staticClass
,
dynamicClass
);
}
function
getStyle
(
dynamicStyle
,
staticStyle
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
;
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
);
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
;
return
Object
.
keys
(
styleObj
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
styleObj
[
name
];
})
.
join
(
'
;
'
);
}
function
toObject
(
arr
)
{
var
res
=
{};
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
]);
}
}
return
res
;
}
function
normalizeStyleBinding
(
bindingStyle
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
);
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
);
}
return
bindingStyle
;
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{};
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
;
var
propertyDelimiter
=
/:
(
.+
)
/
;
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
);
tmp
.
length
>
1
&&
(
res
[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
());
}
});
return
res
;
});
function
isDef
(
v
)
{
return
v
!==
undefined
&&
v
!==
null
;
}
function
renderClass
(
staticClass
,
dynamicClass
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
));
}
/* istanbul ignore next */
return
''
;
}
function
concat
(
a
,
b
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
;
}
function
stringifyClass
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
);
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
);
}
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
/* istanbul ignore next */
return
''
;
}
function
stringifyArray
(
value
)
{
var
res
=
''
;
var
stringified
;
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
stringified
;
}
}
return
res
;
}
function
stringifyObject
(
value
)
{
var
res
=
''
;
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
key
;
}
}
return
res
;
}
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
value
=
value
.
trim
();
}
if
(
modifiers
.
indexOf
(
'
number
'
)
!==
-
1
)
{
value
=
toNumber
(
value
);
}
}
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
setSync
(
target
,
key
,
value
)
{
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
getOrig
(
data
)
{
if
(
isPlainObject
(
data
))
{
return
data
.
$orig
||
data
;
}
return
data
;
}
function
map
(
val
,
iteratee
)
{
let
ret
,
i
,
l
,
keys
,
key
;
if
(
isArray
(
val
))
{
ret
=
new
Array
(
val
.
length
);
for
(
i
=
0
,
l
=
val
.
length
;
i
<
l
;
i
++
)
{
ret
[
i
]
=
iteratee
(
val
[
i
],
i
);
}
return
ret
;
}
else
if
(
isObject
(
val
))
{
keys
=
Object
.
keys
(
val
);
ret
=
Object
.
create
(
null
);
for
(
i
=
0
,
l
=
keys
.
length
;
i
<
l
;
i
++
)
{
key
=
keys
[
i
];
ret
[
key
]
=
iteratee
(
val
[
key
],
key
,
i
);
}
return
ret
;
}
return
[];
}
const
MP_METHODS
=
[
'
createSelectorQuery
'
,
'
createIntersectionObserver
'
,
...
...
@@ -347,15 +179,6 @@ function initComponentInstance(instance, options) {
}
};
});
// TODO other
ctx
.
__set_model
=
setModel
;
ctx
.
__set_sync
=
setSync
;
ctx
.
__get_orig
=
getOrig
;
// TODO
ctx
.
__get_value
=
getValue
;
ctx
.
__get_class
=
getClass
;
ctx
.
__get_style
=
getStyle
;
ctx
.
__map
=
map
;
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
const
ctx
=
instance
.
ctx
;
...
...
@@ -580,7 +403,7 @@ function findVmByVueId(instance, vuePid) {
}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
// const PROP_TYPES = [String, Number, Boolean, Object, Array, null]
function
createObserver
(
name
)
{
return
function
observer
(
newVal
)
{
if
(
this
.
$vm
)
{
...
...
@@ -588,18 +411,30 @@ function createObserver(name) {
}
};
}
function
parsePropType
(
key
,
type
,
defaultValue
)
{
// [String]=>String
if
(
isArray
(
type
)
&&
type
.
length
===
1
)
{
return
type
[
0
];
}
return
type
;
}
// function parsePropType(key: string, type: unknown, defaultValue: unknown) {
// // [String]=>String
// if (isArray(type) && type.length === 1) {
// return type[0]
// }
// if ("mp-qq" === 'mp-baidu') {
// if (
// // [String,Boolean]=>Boolean
// defaultValue === false &&
// isArray(type) &&
// type.length === 2 &&
// type.indexOf(String) !== -1 &&
// type.indexOf(Boolean) !== -1
// ) {
// return Boolean
// }
// }
// return type
// }
function
initDefaultProps
(
isBehavior
=
false
)
{
const
properties
=
{};
if
(
!
isBehavior
)
{
properties
.
vI
=
{
type
:
String
,
type
:
null
,
value
:
''
,
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
...
...
@@ -623,6 +458,12 @@ function createProperty(key, prop) {
prop
.
observer
=
createObserver
(
key
);
return
prop
;
}
/**
* 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value
* @param mpComponentOptions
* @param rawProps
* @param isBehavior
*/
function
initProps
(
mpComponentOptions
,
rawProps
,
isBehavior
=
false
)
{
const
properties
=
initDefaultProps
(
isBehavior
);
if
(
isArray
(
rawProps
))
{
...
...
@@ -641,18 +482,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) {
if
(
isFunction
(
value
))
{
value
=
value
();
}
const
type
=
opts
.
type
;
opts
.
type
=
parsePropType
(
key
,
type
);
// const type = (opts as any).type as any
// ;(opts as any).type = parsePropType(key, type, value)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
value
,
});
}
else
{
// content:String
const
type
=
parsePropType
(
key
,
opts
);
// const type = parsePropType(key, opts, null)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
//
PROP_TYPES.indexOf(type) !== -1 ? type : null,
});
}
});
...
...
packages/uni-mp-toutiao/dist/uni.mp.esm.js
浏览文件 @
f4adc423
import
{
isPlainObject
,
extend
,
hyphenate
,
isObject
,
isArray
,
hasOwn
,
toNumber
,
isFunction
,
camelize
}
from
'
@vue/shared
'
;
import
{
isPlainObject
,
isArray
,
hasOwn
,
isFunction
,
extend
,
camelize
,
isObject
}
from
'
@vue/shared
'
;
import
{
injectHook
,
ref
}
from
'
vue
'
;
const
encode
=
encodeURIComponent
;
...
...
@@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) {
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
function
getDataByPath
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
const
key
=
parts
[
0
];
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getDataByPath
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
...
...
@@ -141,154 +121,6 @@ function getEventChannel(id) {
return
eventChannelStack
.
shift
();
}
function
getValue
(
dataPath
,
target
)
{
return
getDataByPath
(
target
||
this
,
dataPath
);
}
function
getClass
(
dynamicClass
,
staticClass
)
{
return
renderClass
(
staticClass
,
dynamicClass
);
}
function
getStyle
(
dynamicStyle
,
staticStyle
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
;
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
);
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
;
return
Object
.
keys
(
styleObj
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
styleObj
[
name
];
})
.
join
(
'
;
'
);
}
function
toObject
(
arr
)
{
var
res
=
{};
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
]);
}
}
return
res
;
}
function
normalizeStyleBinding
(
bindingStyle
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
);
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
);
}
return
bindingStyle
;
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{};
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
;
var
propertyDelimiter
=
/:
(
.+
)
/
;
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
);
tmp
.
length
>
1
&&
(
res
[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
());
}
});
return
res
;
});
function
isDef
(
v
)
{
return
v
!==
undefined
&&
v
!==
null
;
}
function
renderClass
(
staticClass
,
dynamicClass
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
));
}
/* istanbul ignore next */
return
''
;
}
function
concat
(
a
,
b
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
;
}
function
stringifyClass
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
);
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
);
}
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
/* istanbul ignore next */
return
''
;
}
function
stringifyArray
(
value
)
{
var
res
=
''
;
var
stringified
;
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
stringified
;
}
}
return
res
;
}
function
stringifyObject
(
value
)
{
var
res
=
''
;
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
key
;
}
}
return
res
;
}
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
value
=
value
.
trim
();
}
if
(
modifiers
.
indexOf
(
'
number
'
)
!==
-
1
)
{
value
=
toNumber
(
value
);
}
}
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
setSync
(
target
,
key
,
value
)
{
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
getOrig
(
data
)
{
if
(
isPlainObject
(
data
))
{
return
data
.
$orig
||
data
;
}
return
data
;
}
function
map
(
val
,
iteratee
)
{
let
ret
,
i
,
l
,
keys
,
key
;
if
(
isArray
(
val
))
{
ret
=
new
Array
(
val
.
length
);
for
(
i
=
0
,
l
=
val
.
length
;
i
<
l
;
i
++
)
{
ret
[
i
]
=
iteratee
(
val
[
i
],
i
);
}
return
ret
;
}
else
if
(
isObject
(
val
))
{
keys
=
Object
.
keys
(
val
);
ret
=
Object
.
create
(
null
);
for
(
i
=
0
,
l
=
keys
.
length
;
i
<
l
;
i
++
)
{
key
=
keys
[
i
];
ret
[
key
]
=
iteratee
(
val
[
key
],
key
,
i
);
}
return
ret
;
}
return
[];
}
const
MP_METHODS
=
[
'
createSelectorQuery
'
,
'
createIntersectionObserver
'
,
...
...
@@ -347,15 +179,6 @@ function initComponentInstance(instance, options) {
}
};
});
// TODO other
ctx
.
__set_model
=
setModel
;
ctx
.
__set_sync
=
setSync
;
ctx
.
__get_orig
=
getOrig
;
// TODO
ctx
.
__get_value
=
getValue
;
ctx
.
__get_class
=
getClass
;
ctx
.
__get_style
=
getStyle
;
ctx
.
__map
=
map
;
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
const
ctx
=
instance
.
ctx
;
...
...
@@ -583,7 +406,7 @@ function findVmByVueId(instance, vuePid) {
}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
// const PROP_TYPES = [String, Number, Boolean, Object, Array, null]
function
createObserver
(
name
)
{
return
function
observer
(
newVal
)
{
if
(
this
.
$vm
)
{
...
...
@@ -591,18 +414,30 @@ function createObserver(name) {
}
};
}
function
parsePropType
(
key
,
type
,
defaultValue
)
{
// [String]=>String
if
(
isArray
(
type
)
&&
type
.
length
===
1
)
{
return
type
[
0
];
}
return
type
;
}
// function parsePropType(key: string, type: unknown, defaultValue: unknown) {
// // [String]=>String
// if (isArray(type) && type.length === 1) {
// return type[0]
// }
// if ("mp-toutiao" === 'mp-baidu') {
// if (
// // [String,Boolean]=>Boolean
// defaultValue === false &&
// isArray(type) &&
// type.length === 2 &&
// type.indexOf(String) !== -1 &&
// type.indexOf(Boolean) !== -1
// ) {
// return Boolean
// }
// }
// return type
// }
function
initDefaultProps
(
isBehavior
=
false
)
{
const
properties
=
{};
if
(
!
isBehavior
)
{
properties
.
vI
=
{
type
:
String
,
type
:
null
,
value
:
''
,
};
{
...
...
@@ -632,6 +467,12 @@ function createProperty(key, prop) {
prop
.
observer
=
createObserver
(
key
);
return
prop
;
}
/**
* 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value
* @param mpComponentOptions
* @param rawProps
* @param isBehavior
*/
function
initProps
(
mpComponentOptions
,
rawProps
,
isBehavior
=
false
)
{
const
properties
=
initDefaultProps
(
isBehavior
);
if
(
isArray
(
rawProps
))
{
...
...
@@ -650,18 +491,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) {
if
(
isFunction
(
value
))
{
value
=
value
();
}
const
type
=
opts
.
type
;
opts
.
type
=
parsePropType
(
key
,
type
);
// const type = (opts as any).type as any
// ;(opts as any).type = parsePropType(key, type, value)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
value
,
});
}
else
{
// content:String
const
type
=
parsePropType
(
key
,
opts
);
// const type = parsePropType(key, opts, null)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
//
PROP_TYPES.indexOf(type) !== -1 ? type : null,
});
}
});
...
...
packages/uni-mp-vue/dist/vue.runtime.esm.js
浏览文件 @
f4adc423
...
...
@@ -5012,14 +5012,10 @@ function renderSlot(name, props = {}) {
return
;
}
const
invoker
=
findScopedSlotInvoker
(
vueIds
.
split
(
'
,
'
)[
0
],
instance
);
// 可能不存在,因为插槽不是必需的
if
(
invoker
)
{
invoker
(
name
,
props
);
}
else
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
error
(
'
scoped slot invoker not found
'
,
vueIds
,
name
,
props
);
}
}
}
function
findScopedSlotInvoker
(
vueId
,
instance
)
{
let
parent
=
instance
.
parent
;
...
...
packages/uni-mp-vue/src/helpers/renderSlot.ts
浏览文件 @
f4adc423
...
...
@@ -9,12 +9,9 @@ export function renderSlot(name: string, props: Data = {}) {
return
}
const
invoker
=
findScopedSlotInvoker
(
vueIds
.
split
(
'
,
'
)[
0
],
instance
)
// 可能不存在,因为插槽不是必需的
if
(
invoker
)
{
invoker
(
name
,
props
)
}
else
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
error
(
'
scoped slot invoker not found
'
,
vueIds
,
name
,
props
)
}
}
}
...
...
packages/uni-mp-weixin/dist/uni.mp.esm.js
浏览文件 @
f4adc423
import
{
isPlainObject
,
extend
,
hyphenate
,
isObject
,
isArray
,
hasOwn
,
toNumber
,
isFunction
,
camelize
}
from
'
@vue/shared
'
;
import
{
isPlainObject
,
isArray
,
hasOwn
,
isFunction
,
extend
,
camelize
}
from
'
@vue/shared
'
;
import
{
injectHook
,
ref
}
from
'
vue
'
;
const
encode
=
encodeURIComponent
;
...
...
@@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) {
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
function
getDataByPath
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
const
key
=
parts
[
0
];
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getDataByPath
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
...
...
@@ -78,154 +58,6 @@ function getEventChannel(id) {
return
eventChannelStack
.
shift
();
}
function
getValue
(
dataPath
,
target
)
{
return
getDataByPath
(
target
||
this
,
dataPath
);
}
function
getClass
(
dynamicClass
,
staticClass
)
{
return
renderClass
(
staticClass
,
dynamicClass
);
}
function
getStyle
(
dynamicStyle
,
staticStyle
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
;
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
);
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
;
return
Object
.
keys
(
styleObj
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
styleObj
[
name
];
})
.
join
(
'
;
'
);
}
function
toObject
(
arr
)
{
var
res
=
{};
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
]);
}
}
return
res
;
}
function
normalizeStyleBinding
(
bindingStyle
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
);
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
);
}
return
bindingStyle
;
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{};
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
;
var
propertyDelimiter
=
/:
(
.+
)
/
;
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
);
tmp
.
length
>
1
&&
(
res
[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
());
}
});
return
res
;
});
function
isDef
(
v
)
{
return
v
!==
undefined
&&
v
!==
null
;
}
function
renderClass
(
staticClass
,
dynamicClass
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
));
}
/* istanbul ignore next */
return
''
;
}
function
concat
(
a
,
b
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
;
}
function
stringifyClass
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
);
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
);
}
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
/* istanbul ignore next */
return
''
;
}
function
stringifyArray
(
value
)
{
var
res
=
''
;
var
stringified
;
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
stringified
;
}
}
return
res
;
}
function
stringifyObject
(
value
)
{
var
res
=
''
;
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
key
;
}
}
return
res
;
}
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
value
=
value
.
trim
();
}
if
(
modifiers
.
indexOf
(
'
number
'
)
!==
-
1
)
{
value
=
toNumber
(
value
);
}
}
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
setSync
(
target
,
key
,
value
)
{
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
getOrig
(
data
)
{
if
(
isPlainObject
(
data
))
{
return
data
.
$orig
||
data
;
}
return
data
;
}
function
map
(
val
,
iteratee
)
{
let
ret
,
i
,
l
,
keys
,
key
;
if
(
isArray
(
val
))
{
ret
=
new
Array
(
val
.
length
);
for
(
i
=
0
,
l
=
val
.
length
;
i
<
l
;
i
++
)
{
ret
[
i
]
=
iteratee
(
val
[
i
],
i
);
}
return
ret
;
}
else
if
(
isObject
(
val
))
{
keys
=
Object
.
keys
(
val
);
ret
=
Object
.
create
(
null
);
for
(
i
=
0
,
l
=
keys
.
length
;
i
<
l
;
i
++
)
{
key
=
keys
[
i
];
ret
[
key
]
=
iteratee
(
val
[
key
],
key
,
i
);
}
return
ret
;
}
return
[];
}
const
MP_METHODS
=
[
'
createSelectorQuery
'
,
'
createIntersectionObserver
'
,
...
...
@@ -284,15 +116,6 @@ function initComponentInstance(instance, options) {
}
};
});
// TODO other
ctx
.
__set_model
=
setModel
;
ctx
.
__set_sync
=
setSync
;
ctx
.
__get_orig
=
getOrig
;
// TODO
ctx
.
__get_value
=
getValue
;
ctx
.
__get_class
=
getClass
;
ctx
.
__get_style
=
getStyle
;
ctx
.
__map
=
map
;
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
const
ctx
=
instance
.
ctx
;
...
...
@@ -526,7 +349,7 @@ function findVmByVueId(instance, vuePid) {
}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
// const PROP_TYPES = [String, Number, Boolean, Object, Array, null]
function
createObserver
(
name
)
{
return
function
observer
(
newVal
)
{
if
(
this
.
$vm
)
{
...
...
@@ -534,18 +357,30 @@ function createObserver(name) {
}
};
}
function
parsePropType
(
key
,
type
,
defaultValue
)
{
// [String]=>String
if
(
isArray
(
type
)
&&
type
.
length
===
1
)
{
return
type
[
0
];
}
return
type
;
}
// function parsePropType(key: string, type: unknown, defaultValue: unknown) {
// // [String]=>String
// if (isArray(type) && type.length === 1) {
// return type[0]
// }
// if ("mp-weixin" === 'mp-baidu') {
// if (
// // [String,Boolean]=>Boolean
// defaultValue === false &&
// isArray(type) &&
// type.length === 2 &&
// type.indexOf(String) !== -1 &&
// type.indexOf(Boolean) !== -1
// ) {
// return Boolean
// }
// }
// return type
// }
function
initDefaultProps
(
isBehavior
=
false
)
{
const
properties
=
{};
if
(
!
isBehavior
)
{
properties
.
vI
=
{
type
:
String
,
type
:
null
,
value
:
''
,
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
...
...
@@ -569,6 +404,12 @@ function createProperty(key, prop) {
prop
.
observer
=
createObserver
(
key
);
return
prop
;
}
/**
* 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value
* @param mpComponentOptions
* @param rawProps
* @param isBehavior
*/
function
initProps
(
mpComponentOptions
,
rawProps
,
isBehavior
=
false
)
{
const
properties
=
initDefaultProps
(
isBehavior
);
if
(
isArray
(
rawProps
))
{
...
...
@@ -587,18 +428,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) {
if
(
isFunction
(
value
))
{
value
=
value
();
}
const
type
=
opts
.
type
;
opts
.
type
=
parsePropType
(
key
,
type
);
// const type = (opts as any).type as any
// ;(opts as any).type = parsePropType(key, type, value)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
value
,
});
}
else
{
// content:String
const
type
=
parsePropType
(
key
,
opts
);
// const type = parsePropType(key, opts, null)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
//
PROP_TYPES.indexOf(type) !== -1 ? type : null,
});
}
});
...
...
packages/uni-quickapp-webview/dist/uni.mp.esm.js
浏览文件 @
f4adc423
import
{
isPlainObject
,
extend
,
hyphenate
,
isObject
,
isArray
,
hasOwn
,
toNumber
,
isFunction
,
camelize
}
from
'
@vue/shared
'
;
import
{
isPlainObject
,
isArray
,
hasOwn
,
isFunction
,
extend
,
camelize
,
isObject
}
from
'
@vue/shared
'
;
import
{
injectHook
,
ref
}
from
'
vue
'
;
const
encode
=
encodeURIComponent
;
...
...
@@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) {
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
function
getDataByPath
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
const
key
=
parts
[
0
];
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getDataByPath
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
...
...
@@ -141,154 +121,6 @@ function getEventChannel(id) {
return
eventChannelStack
.
shift
();
}
function
getValue
(
dataPath
,
target
)
{
return
getDataByPath
(
target
||
this
,
dataPath
);
}
function
getClass
(
dynamicClass
,
staticClass
)
{
return
renderClass
(
staticClass
,
dynamicClass
);
}
function
getStyle
(
dynamicStyle
,
staticStyle
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
;
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
);
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
;
return
Object
.
keys
(
styleObj
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
styleObj
[
name
];
})
.
join
(
'
;
'
);
}
function
toObject
(
arr
)
{
var
res
=
{};
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
]);
}
}
return
res
;
}
function
normalizeStyleBinding
(
bindingStyle
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
);
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
);
}
return
bindingStyle
;
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{};
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
;
var
propertyDelimiter
=
/:
(
.+
)
/
;
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
);
tmp
.
length
>
1
&&
(
res
[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
());
}
});
return
res
;
});
function
isDef
(
v
)
{
return
v
!==
undefined
&&
v
!==
null
;
}
function
renderClass
(
staticClass
,
dynamicClass
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
));
}
/* istanbul ignore next */
return
''
;
}
function
concat
(
a
,
b
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
;
}
function
stringifyClass
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
);
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
);
}
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
/* istanbul ignore next */
return
''
;
}
function
stringifyArray
(
value
)
{
var
res
=
''
;
var
stringified
;
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
stringified
;
}
}
return
res
;
}
function
stringifyObject
(
value
)
{
var
res
=
''
;
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
key
;
}
}
return
res
;
}
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
value
=
value
.
trim
();
}
if
(
modifiers
.
indexOf
(
'
number
'
)
!==
-
1
)
{
value
=
toNumber
(
value
);
}
}
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
setSync
(
target
,
key
,
value
)
{
if
(
!
target
)
{
target
=
this
;
}
target
[
key
]
=
value
;
}
function
getOrig
(
data
)
{
if
(
isPlainObject
(
data
))
{
return
data
.
$orig
||
data
;
}
return
data
;
}
function
map
(
val
,
iteratee
)
{
let
ret
,
i
,
l
,
keys
,
key
;
if
(
isArray
(
val
))
{
ret
=
new
Array
(
val
.
length
);
for
(
i
=
0
,
l
=
val
.
length
;
i
<
l
;
i
++
)
{
ret
[
i
]
=
iteratee
(
val
[
i
],
i
);
}
return
ret
;
}
else
if
(
isObject
(
val
))
{
keys
=
Object
.
keys
(
val
);
ret
=
Object
.
create
(
null
);
for
(
i
=
0
,
l
=
keys
.
length
;
i
<
l
;
i
++
)
{
key
=
keys
[
i
];
ret
[
key
]
=
iteratee
(
val
[
key
],
key
,
i
);
}
return
ret
;
}
return
[];
}
const
MP_METHODS
=
[
'
createSelectorQuery
'
,
'
createIntersectionObserver
'
,
...
...
@@ -347,15 +179,6 @@ function initComponentInstance(instance, options) {
}
};
});
// TODO other
ctx
.
__set_model
=
setModel
;
ctx
.
__set_sync
=
setSync
;
ctx
.
__get_orig
=
getOrig
;
// TODO
ctx
.
__get_value
=
getValue
;
ctx
.
__get_class
=
getClass
;
ctx
.
__get_style
=
getStyle
;
ctx
.
__map
=
map
;
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
const
ctx
=
instance
.
ctx
;
...
...
@@ -561,7 +384,7 @@ function initRefs(instance, mpInstance) {
});
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
// const PROP_TYPES = [String, Number, Boolean, Object, Array, null]
function
createObserver
(
name
)
{
return
function
observer
(
newVal
)
{
if
(
this
.
$vm
)
{
...
...
@@ -569,18 +392,30 @@ function createObserver(name) {
}
};
}
function
parsePropType
(
key
,
type
,
defaultValue
)
{
// [String]=>String
if
(
isArray
(
type
)
&&
type
.
length
===
1
)
{
return
type
[
0
];
}
return
type
;
}
// function parsePropType(key: string, type: unknown, defaultValue: unknown) {
// // [String]=>String
// if (isArray(type) && type.length === 1) {
// return type[0]
// }
// if ("quickapp-webview" === 'mp-baidu') {
// if (
// // [String,Boolean]=>Boolean
// defaultValue === false &&
// isArray(type) &&
// type.length === 2 &&
// type.indexOf(String) !== -1 &&
// type.indexOf(Boolean) !== -1
// ) {
// return Boolean
// }
// }
// return type
// }
function
initDefaultProps
(
isBehavior
=
false
)
{
const
properties
=
{};
if
(
!
isBehavior
)
{
properties
.
vI
=
{
type
:
String
,
type
:
null
,
value
:
''
,
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
...
...
@@ -604,6 +439,12 @@ function createProperty(key, prop) {
prop
.
observer
=
createObserver
(
key
);
return
prop
;
}
/**
* 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value
* @param mpComponentOptions
* @param rawProps
* @param isBehavior
*/
function
initProps
(
mpComponentOptions
,
rawProps
,
isBehavior
=
false
)
{
const
properties
=
initDefaultProps
(
isBehavior
);
if
(
isArray
(
rawProps
))
{
...
...
@@ -622,18 +463,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) {
if
(
isFunction
(
value
))
{
value
=
value
();
}
const
type
=
opts
.
type
;
opts
.
type
=
parsePropType
(
key
,
type
);
// const type = (opts as any).type as any
// ;(opts as any).type = parsePropType(key, type, value)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
value
,
});
}
else
{
// content:String
const
type
=
parsePropType
(
key
,
opts
);
// const type = parsePropType(key, opts, null)
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
type
:
null
,
//
PROP_TYPES.indexOf(type) !== -1 ? type : null,
});
}
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录