Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
da96069d
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
725
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
da96069d
编写于
6月 16, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: add normalizeRoute
上级
32305c76
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
214 addition
and
252 deletion
+214
-252
packages/global.d.ts
packages/global.d.ts
+2
-0
packages/shims-uni-app.d.ts
packages/shims-uni-app.d.ts
+4
-0
packages/uni-api/src/protocols/route/route.ts
packages/uni-api/src/protocols/route/route.ts
+2
-2
packages/uni-core/src/helpers/index.ts
packages/uni-core/src/helpers/index.ts
+1
-1
packages/uni-core/src/helpers/route.ts
packages/uni-core/src/helpers/route.ts
+15
-16
packages/uni-h5/dist/uni-h5.cjs.js
packages/uni-h5/dist/uni-h5.cjs.js
+7
-18
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+18
-22
packages/uni-h5/src/framework/setup/index.ts
packages/uni-h5/src/framework/setup/index.ts
+2
-2
packages/uni-h5/src/platform/dom.ts
packages/uni-h5/src/platform/dom.ts
+1
-4
packages/uni-h5/src/service/api/ui/tabBar.ts
packages/uni-h5/src/service/api/ui/tabBar.ts
+2
-2
packages/uni-shared/__tests__/vdom/utils.spec.ts
packages/uni-shared/__tests__/vdom/utils.spec.ts
+3
-4
packages/uni-shared/dist/uni-shared.cjs.js
packages/uni-shared/dist/uni-shared.cjs.js
+46
-58
packages/uni-shared/dist/uni-shared.d.ts
packages/uni-shared/dist/uni-shared.d.ts
+9
-1
packages/uni-shared/dist/uni-shared.es.js
packages/uni-shared/dist/uni-shared.es.js
+43
-59
packages/uni-shared/src/constants.ts
packages/uni-shared/src/constants.ts
+5
-0
packages/uni-shared/src/utils.ts
packages/uni-shared/src/utils.ts
+10
-0
packages/uni-shared/src/vdom/Node.ts
packages/uni-shared/src/vdom/Node.ts
+2
-2
packages/uni-shared/src/vdom/decode.ts
packages/uni-shared/src/vdom/decode.ts
+25
-0
packages/uni-shared/src/vdom/encode.ts
packages/uni-shared/src/vdom/encode.ts
+15
-60
packages/uni-shared/src/vdom/index.ts
packages/uni-shared/src/vdom/index.ts
+2
-1
未找到文件。
packages/global.d.ts
浏览文件 @
da96069d
declare
var
weex
:
any
declare
var
tt
:
any
declare
var
qa
:
any
declare
var
swan
:
any
...
...
packages/shims-uni-app.d.ts
浏览文件 @
da96069d
...
...
@@ -51,6 +51,10 @@ declare namespace UniApp {
tabBar
?:
TabBarOptions
subPackages
?:
{
root
:
string
}[]
qqMapKey
?:
string
// app-plus
entryPagePath
?:
string
entryPageQuery
?:
string
realEntryPagePath
?:
string
}
interface
UniRoute
{
...
...
packages/uni-api/src/protocols/route/route.ts
浏览文件 @
da96069d
import
{
extend
}
from
'
@vue/shared
'
import
{
getReal
Route
}
from
'
@dcloudio/uni-core
'
import
{
normalize
Route
}
from
'
@dcloudio/uni-core
'
import
{
encodeQueryString
}
from
'
./encodeQueryString
'
const
ANIMATION_IN
=
[
...
...
@@ -135,7 +135,7 @@ function createNormalizeUrl(type: string) {
return
`Missing required args: "url"`
}
// 格式化为绝对路径路由
url
=
getReal
Route
(
url
)
url
=
normalize
Route
(
url
)
const
pagePath
=
url
.
split
(
'
?
'
)[
0
]
// 匹配路由是否存在
const
routeOptions
=
__uniRoutes
.
find
(
...
...
packages/uni-core/src/helpers/index.ts
浏览文件 @
da96069d
...
...
@@ -3,6 +3,6 @@ export * from './util'
export
*
from
'
./icon
'
export
*
from
'
./page
'
export
*
from
'
./scroll
'
export
*
from
'
./
getRealR
oute
'
export
*
from
'
./
r
oute
'
export
*
from
'
./callbacks
'
export
{
default
as
Emitter
}
from
'
./TinyEmitter
'
packages/uni-core/src/helpers/
getRealR
oute.ts
→
packages/uni-core/src/helpers/
r
oute.ts
浏览文件 @
da96069d
export
function
getRealRoute
(
fromRoute
:
string
,
toRoute
?:
string
):
string
{
if
(
!
toRoute
)
{
toRoute
=
fromRoute
if
(
toRoute
.
indexOf
(
'
/
'
)
===
0
)
{
return
toRoute
}
const
pages
=
getCurrentPages
()
if
(
pages
.
length
)
{
fromRoute
=
(
pages
[
pages
.
length
-
1
]
as
any
).
$page
.
route
}
else
{
fromRoute
=
''
}
}
else
{
if
(
toRoute
.
indexOf
(
'
/
'
)
===
0
)
{
return
toRoute
}
export
function
normalizeRoute
(
toRoute
:
string
)
{
if
(
toRoute
.
indexOf
(
'
/
'
)
===
0
)
{
return
toRoute
}
let
fromRoute
=
''
const
pages
=
getCurrentPages
()
if
(
pages
.
length
)
{
fromRoute
=
(
pages
[
pages
.
length
-
1
]
as
any
).
$page
.
route
}
return
getRealRoute
(
fromRoute
,
toRoute
)
}
export
function
getRealRoute
(
fromRoute
:
string
,
toRoute
:
string
):
string
{
if
(
toRoute
.
indexOf
(
'
/
'
)
===
0
)
{
return
toRoute
}
if
(
toRoute
.
indexOf
(
'
./
'
)
===
0
)
{
return
getRealRoute
(
fromRoute
,
toRoute
.
substr
(
2
))
...
...
packages/uni-h5/dist/uni-h5.cjs.js
浏览文件 @
da96069d
...
...
@@ -419,21 +419,8 @@ function useCurrentPageId() {
return
vue
.
getCurrentInstance
().
root
.
proxy
.
$page
.
id
;
}
function
getRealRoute
(
fromRoute
,
toRoute
)
{
if
(
!
toRoute
)
{
toRoute
=
fromRoute
;
if
(
toRoute
.
indexOf
(
"
/
"
)
===
0
)
{
return
toRoute
;
}
const
pages
=
getCurrentPages
();
if
(
pages
.
length
)
{
fromRoute
=
pages
[
pages
.
length
-
1
].
$page
.
route
;
}
else
{
fromRoute
=
""
;
}
}
else
{
if
(
toRoute
.
indexOf
(
"
/
"
)
===
0
)
{
return
toRoute
;
}
if
(
toRoute
.
indexOf
(
"
/
"
)
===
0
)
{
return
toRoute
;
}
if
(
toRoute
.
indexOf
(
"
./
"
)
===
0
)
{
return
getRealRoute
(
fromRoute
,
toRoute
.
substr
(
2
));
...
...
@@ -975,8 +962,6 @@ var index$w = /* @__PURE__ */ defineBuiltInComponent({
};
}
});
const
SCHEME_RE
=
/^
([
a-z-
]
+:
)?\/\/
/i
;
const
DATA_RE
=
/^data:.*,.*/
;
const
baseUrl
=
__IMPORT_META_ENV_BASE_URL__
;
function
addBase
(
filePath
)
{
return
baseUrl
+
filePath
;
...
...
@@ -992,7 +977,7 @@ function getRealPath(filePath) {
return
addBase
(
filePath
.
substr
(
1
));
}
}
if
(
SCHEME_RE
.
test
(
filePath
)
||
DATA_RE
.
test
(
filePath
)
||
filePath
.
indexOf
(
"
blob:
"
)
===
0
)
{
if
(
uniShared
.
SCHEME_RE
.
test
(
filePath
)
||
uniShared
.
DATA_RE
.
test
(
filePath
)
||
filePath
.
indexOf
(
"
blob:
"
)
===
0
)
{
return
filePath
;
}
const
pages
=
getCurrentPages
();
...
...
@@ -9472,6 +9457,10 @@ function normalizeContentType(header) {
return
;
}
const
contentType
=
header
[
name
];
if
(
name
!==
"
Content-Type
"
)
{
header
[
"
Content-Type
"
]
=
header
[
name
];
delete
header
[
name
];
}
if
(
contentType
.
indexOf
(
"
application/json
"
)
===
0
)
{
return
"
json
"
;
}
else
if
(
contentType
.
indexOf
(
"
application/x-www-form-urlencoded
"
)
===
0
)
{
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
da96069d
import { isFunction, extend, hyphenate, isPlainObject, isString, isArray, hasOwn, isObject, capitalize, toRawType, makeMap as makeMap$1, isPromise, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { once, passive, normalizeTarget, isBuiltInComponent, initCustomDataset, invokeArrayFns,
getCustomDataset, callOptions, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, NAVBAR_HEIGHT, parseQuery, ON_REACH_BOTTOM_DISTANCE, decodedQuery
, updateElementStyle, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime } from "@dcloudio/uni-shared";
import { once, passive, normalizeTarget, isBuiltInComponent, initCustomDataset, invokeArrayFns,
SCHEME_RE, DATA_RE, getCustomDataset, callOptions, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, NAVBAR_HEIGHT, parseQuery, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE
, updateElementStyle, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime } from "@dcloudio/uni-shared";
import { openBlock, createBlock, mergeProps, createVNode, toDisplayString, withModifiers, getCurrentInstance, defineComponent, ref, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, createTextVNode, injectHook, onBeforeActivate, onBeforeDeactivate, renderList, onDeactivated, Teleport, createApp, Transition, withCtx, KeepAlive, resolveDynamicComponent, renderSlot } from "vue";
import { initVueI18n, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n";
import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router";
...
...
@@ -857,22 +857,20 @@ function createScrollListener({
ticking = true;
};
}
function normalizeRoute(toRoute) {
if (toRoute.indexOf("/") === 0) {
return toRoute;
}
let fromRoute = "";
const pages = getCurrentPages();
if (pages.length) {
fromRoute = pages[pages.length - 1].$page.route;
}
return getRealRoute(fromRoute, toRoute);
}
function getRealRoute(fromRoute, toRoute) {
if (!toRoute) {
toRoute = fromRoute;
if (toRoute.indexOf("/") === 0) {
return toRoute;
}
const pages = getCurrentPages();
if (pages.length) {
fromRoute = pages[pages.length - 1].$page.route;
} else {
fromRoute = "";
}
} else {
if (toRoute.indexOf("/") === 0) {
return toRoute;
}
if (toRoute.indexOf("/") === 0) {
return toRoute;
}
if (toRoute.indexOf("./") === 0) {
return getRealRoute(fromRoute, toRoute.substr(2));
...
...
@@ -1824,8 +1822,6 @@ var index$s = /* @__PURE__ */ defineBuiltInComponent({
function findElem(vm) {
return vm.$el;
}
const SCHEME_RE = /^([a-z-]+:)?\/\//i;
const DATA_RE = /^data:.*,.*/;
const baseUrl = import.meta.env.BASE_URL;
function addBase(filePath) {
return baseUrl + filePath;
...
...
@@ -4665,7 +4661,7 @@ function createNormalizeUrl(type) {
if (!url) {
return `Missing required args: "url"`;
}
url =
getReal
Route(url);
url =
normalize
Route(url);
const pagePath = url.split("?")[0];
const routeOptions = __uniRoutes.find(({ path, alias }) => path === pagePath || alias === pagePath);
if (!routeOptions) {
...
...
@@ -13430,7 +13426,7 @@ function setupApp(comp) {
}
onMounted(() => {
window.addEventListener("message", function(evt) {
if (isPlainObject(evt.data) && evt.data.type ===
"WEB_INVOKE_APPSERVICE"
) {
if (isPlainObject(evt.data) && evt.data.type ===
WEB_INVOKE_APPSERVICE
) {
UniServiceJSBridge.emit("onWebInvokeAppService", evt.data.data, evt.data.pageId);
}
});
...
...
@@ -17911,7 +17907,7 @@ function setProperties(item, props2, propsData) {
}
});
}
function normalizeRoute(index2, oldPagePath, newPagePath) {
function normalize
TabBar
Route(index2, oldPagePath, newPagePath) {
const oldTabBarRoute = __uniRoutes.find((item) => item.meta.route === oldPagePath);
if (oldTabBarRoute) {
const { meta } = oldTabBarRoute;
...
...
@@ -17941,7 +17937,7 @@ function setTabBar(type, args, resolve) {
setProperties(tabBarItem, setTabBarItemProps, args);
const { pagePath } = args;
if (pagePath && pagePath !== oldPagePath) {
normalizeRoute(index2, oldPagePath, pagePath);
normalize
TabBar
Route(index2, oldPagePath, pagePath);
}
break;
case API_SET_TAB_BAR_STYLE:
...
...
packages/uni-h5/src/framework/setup/index.ts
浏览文件 @
da96069d
...
...
@@ -12,7 +12,7 @@ import {
onBeforeMount
,
}
from
'
vue
'
import
{
useRouter
}
from
'
vue-router
'
import
{
decodedQuery
}
from
'
@dcloudio/uni-shared
'
import
{
decodedQuery
,
WEB_INVOKE_APPSERVICE
}
from
'
@dcloudio/uni-shared
'
import
{
LayoutComponent
}
from
'
../..
'
import
{
initApp
}
from
'
./app
'
import
{
initPage
,
onPageShow
,
onPageReady
}
from
'
./page
'
...
...
@@ -134,7 +134,7 @@ export function setupApp(comp: any) {
})
{
if
(
isPlainObject
(
evt
.
data
)
&&
evt
.
data
.
type
===
'
WEB_INVOKE_APPSERVICE
'
evt
.
data
.
type
===
WEB_INVOKE_APPSERVICE
)
{
UniServiceJSBridge
.
emit
(
'
onWebInvokeAppService
'
,
...
...
packages/uni-h5/src/platform/dom.ts
浏览文件 @
da96069d
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
getRealRoute
}
from
'
@dcloudio/uni-core
'
import
{
DATA_RE
,
SCHEME_RE
}
from
'
@dcloudio/uni-shared
'
declare
global
{
interface
ImportMeta
{
env
:
{
...
...
@@ -13,9 +13,6 @@ export function findElem(vm: ComponentPublicInstance) {
return
vm
.
$el
}
const
SCHEME_RE
=
/^
([
a-z-
]
+:
)?\/\/
/i
const
DATA_RE
=
/^data:.*,.*/
const
baseUrl
=
__IMPORT_META_ENV_BASE_URL__
function
addBase
(
filePath
:
string
)
{
return
baseUrl
+
filePath
...
...
packages/uni-h5/src/service/api/ui/tabBar.ts
浏览文件 @
da96069d
...
...
@@ -54,7 +54,7 @@ function setProperties(
})
}
function
normalizeRoute
(
function
normalize
TabBar
Route
(
index
:
number
,
oldPagePath
:
string
,
newPagePath
:
string
...
...
@@ -97,7 +97,7 @@ function setTabBar(
setProperties
(
tabBarItem
,
setTabBarItemProps
,
args
)
const
{
pagePath
}
=
args
if
(
pagePath
&&
pagePath
!==
oldPagePath
)
{
normalizeRoute
(
index
,
oldPagePath
,
pagePath
)
normalize
TabBar
Route
(
index
,
oldPagePath
,
pagePath
)
}
break
case
API_SET_TAB_BAR_STYLE
:
...
...
packages/uni-shared/__tests__/vdom/utils.spec.ts
浏览文件 @
da96069d
import
{
ATTR_MAP
,
COMPONENT_MAP
,
encodeTag
,
decodeTag
,
ATTR_MAP
,
encodeAttr
,
decodeAttr
,
}
from
'
../../src/vdom/utils
'
}
from
'
../../src/vdom/encode
'
import
{
decodeTag
,
decodeAttr
}
from
'
../../src/vdom/decode
'
describe
(
'
encode
'
,
()
=>
{
test
(
'
tag
'
,
()
=>
{
...
...
packages/uni-shared/dist/uni-shared.cjs.js
浏览文件 @
da96069d
...
...
@@ -367,17 +367,25 @@ function proxyStyle(uniCssStyle) {
const
ATTR_MAP
=
{
class
:
'
.c
'
,
style
:
'
.s
'
,
onClick
:
'
.e0
'
,
onChange
:
'
.e1
'
,
onInput
:
'
.e2
'
,
onLoad
:
'
.e3
'
,
onError
:
'
.e4
'
,
onTouchstart
:
'
.e5
'
,
onTouchmove
:
'
.e6
'
,
onTouchcancel
:
'
.e7
'
,
onTouchend
:
'
.e8
'
,
onLongpress
:
'
.e9
'
,
onTransitionend
:
'
.ea
'
,
onAnimationstart
:
'
.eb
'
,
onAnimationiteration
:
'
.ec
'
,
onAnimationend
:
'
.ed
'
,
onTouchforcechange
:
'
.ee
'
,
};
function
encodeAttr
(
name
)
{
return
ATTR_MAP
[
name
]
||
name
;
}
const
ATTR_RESTORE_MAP
=
{
'
.c
'
:
'
class
'
,
'
.s
'
:
'
style
'
,
};
function
decodeAttr
(
name
)
{
return
ATTR_RESTORE_MAP
[
name
]
||
name
;
}
const
COMPONENT_MAP
=
{
VIEW
:
1
,
IMAGE
:
2
,
...
...
@@ -425,55 +433,6 @@ const COMPONENT_MAP = {
};
function
encodeTag
(
tag
)
{
return
COMPONENT_MAP
[
tag
]
||
tag
;
}
const
COMPONENT_ARR
=
[
''
,
'
view
'
,
'
image
'
,
'
text
'
,
'
#text
'
,
'
#comment
'
,
'
navigator
'
,
'
form
'
,
'
button
'
,
'
input
'
,
'
label
'
,
'
radio
'
,
'
checkbox
'
,
'
checkbox-group
'
,
'
ad
'
,
'
audio
'
,
'
camera
'
,
'
canvas
'
,
'
cover-image
'
,
'
cover-view
'
,
'
editor
'
,
'
functional-page-navigator
'
,
'
icon
'
,
'
radio-group
'
,
'
live-player
'
,
'
live-pusher
'
,
'
map
'
,
'
movable-area
'
,
'
movable-view
'
,
'
official-account
'
,
'
open-data
'
,
'
picker
'
,
'
picker-view
'
,
'
picker-view-column
'
,
'
progress
'
,
'
rich-text
'
,
'
scroll-view
'
,
'
slider
'
,
'
swiper
'
,
'
swiper-item
'
,
'
switch
'
,
'
textarea
'
,
'
video
'
,
'
web-view
'
,
];
function
decodeTag
(
tag
)
{
return
COMPONENT_ARR
[
tag
]
||
tag
;
}
const
NODE_TYPE_PAGE
=
0
;
...
...
@@ -628,7 +587,7 @@ class UniBaseNode extends UniNode {
removeEventListener
(
type
,
callback
,
options
)
{
super
.
removeEventListener
(
type
,
callback
,
options
);
const
normalized
=
normalizeEventType
(
type
);
if
(
this
.
attributes
[
normalized
])
{
if
(
this
.
attributes
[
encodeAttr
(
normalized
)
])
{
this
.
removeAttribute
(
normalized
);
}
}
...
...
@@ -713,6 +672,28 @@ class UniTextNode extends UniBaseNode {
}
}
const
DECODED_ATTR_MAP
=
/*#__PURE__*/
Object
.
keys
(
ATTR_MAP
).
reduce
((
map
,
name
)
=>
{
map
[
ATTR_MAP
[
name
]]
=
name
;
return
map
;
},
Object
.
create
(
null
));
function
decodeAttr
(
name
)
{
return
DECODED_ATTR_MAP
[
name
]
||
name
;
}
const
DECODED_COMPONENT_ARR
=
/*#__PURE__*/
Object
.
keys
(
COMPONENT_MAP
).
reduce
((
arr
,
name
)
=>
{
arr
.
push
(
name
.
toLowerCase
());
return
arr
;
},
[
''
]);
function
decodeTag
(
tag
)
{
return
DECODED_COMPONENT_ARR
[
tag
]
||
tag
;
}
const
cacheStringFunction
=
(
fn
)
=>
{
const
cache
=
Object
.
create
(
null
);
return
((
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
});
};
function
getLen
(
str
=
''
)
{
return
(
''
+
str
).
replace
(
/
[^\x
00-
\x
ff
]
/g
,
'
**
'
).
length
;
}
...
...
@@ -883,7 +864,10 @@ const UNI_SSR = '__uniSSR';
const
UNI_SSR_TITLE
=
'
title
'
;
const
UNI_SSR_STORE
=
'
store
'
;
const
UNI_SSR_DATA
=
'
data
'
;
const
UNI_SSR_GLOBAL_DATA
=
'
globalData
'
;
const
UNI_SSR_GLOBAL_DATA
=
'
globalData
'
;
const
SCHEME_RE
=
/^
([
a-z-
]
+:
)?\/\/
/i
;
const
DATA_RE
=
/^data:.*,.*/
;
const
WEB_INVOKE_APPSERVICE
=
'
WEB_INVOKE_APPSERVICE
'
;
function
getEnvLocale
()
{
const
{
env
}
=
process
;
...
...
@@ -895,6 +879,7 @@ exports.BUILT_IN_TAGS = BUILT_IN_TAGS;
exports
.
COMPONENT_NAME_PREFIX
=
COMPONENT_NAME_PREFIX
;
exports
.
COMPONENT_PREFIX
=
COMPONENT_PREFIX
;
exports
.
COMPONENT_SELECTOR_PREFIX
=
COMPONENT_SELECTOR_PREFIX
;
exports
.
DATA_RE
=
DATA_RE
;
exports
.
NAVBAR_HEIGHT
=
NAVBAR_HEIGHT
;
exports
.
NODE_TYPE_COMMENT
=
NODE_TYPE_COMMENT
;
exports
.
NODE_TYPE_ELEMENT
=
NODE_TYPE_ELEMENT
;
...
...
@@ -904,6 +889,7 @@ exports.ON_REACH_BOTTOM_DISTANCE = ON_REACH_BOTTOM_DISTANCE;
exports
.
PLUS_RE
=
PLUS_RE
;
exports
.
PRIMARY_COLOR
=
PRIMARY_COLOR
;
exports
.
RESPONSIVE_MIN_WIDTH
=
RESPONSIVE_MIN_WIDTH
;
exports
.
SCHEME_RE
=
SCHEME_RE
;
exports
.
TABBAR_HEIGHT
=
TABBAR_HEIGHT
;
exports
.
TAGS
=
TAGS
;
exports
.
UNI_SSR
=
UNI_SSR
;
...
...
@@ -919,7 +905,9 @@ exports.UniInputElement = UniInputElement;
exports
.
UniNode
=
UniNode
;
exports
.
UniTextAreaElement
=
UniTextAreaElement
;
exports
.
UniTextNode
=
UniTextNode
;
exports
.
WEB_INVOKE_APPSERVICE
=
WEB_INVOKE_APPSERVICE
;
exports
.
addFont
=
addFont
;
exports
.
cacheStringFunction
=
cacheStringFunction
;
exports
.
callOptions
=
callOptions
;
exports
.
createRpx2Unit
=
createRpx2Unit
;
exports
.
debounce
=
debounce
;
...
...
packages/uni-shared/dist/uni-shared.d.ts
浏览文件 @
da96069d
...
...
@@ -4,6 +4,8 @@ export declare function addFont(family: string, source: string, desc?: FontFaceD
export
declare
const
BUILT_IN_TAGS
:
string
[];
export
declare
const
cacheStringFunction
:
<
T
extends
(
str
:
string
)
=>
string
>
(
fn
:
T
)
=>
T
;
export
declare
function
callOptions
(
options
:
Options
,
errMsg
:
string
):
void
;
export
declare
function
callOptions
(
options
:
Options
,
data
:
{
...
...
@@ -19,6 +21,8 @@ export declare const COMPONENT_SELECTOR_PREFIX = "uni-";
export
declare
function
createRpx2Unit
(
unit
:
string
,
unitRatio
:
number
,
unitPrecision
:
number
):
(
val
:
string
)
=>
string
;
export
declare
const
DATA_RE
:
RegExp
;
export
declare
function
debounce
(
fn
:
Function
,
delay
:
number
):
{
(
this
:
any
):
void
;
cancel
():
void
;
...
...
@@ -33,7 +37,7 @@ export declare function debounce(fn: Function, delay: number): {
*/
export
declare
function
decode
(
text
:
string
|
number
):
string
;
export
declare
function
decodeAttr
(
name
:
string
):
string
;
export
declare
function
decodeAttr
(
name
:
string
):
any
;
export
declare
function
decodedQuery
(
query
?:
Record
<
string
,
any
>
):
Record
<
string
,
string
>
;
...
...
@@ -144,6 +148,8 @@ export declare type Rpx2UnitOptions = typeof defaultRpx2Unit;
export
declare
const
sanitise
:
(
val
:
unknown
)
=>
any
;
export
declare
const
SCHEME_RE
:
RegExp
;
declare
function
scrollTo_2
(
scrollTop
:
number
|
string
,
duration
:
number
):
void
;
export
{
scrollTo_2
as
scrollTo
}
...
...
@@ -310,4 +316,6 @@ export declare class UniTextNode extends UniBaseNode {
export
declare
function
updateElementStyle
(
element
:
HTMLElement
,
styles
:
Partial
<
CSSStyleDeclaration
>
):
void
;
export
declare
const
WEB_INVOKE_APPSERVICE
=
"
WEB_INVOKE_APPSERVICE
"
;
export
{
}
packages/uni-shared/dist/uni-shared.es.js
浏览文件 @
da96069d
...
...
@@ -363,17 +363,25 @@ function proxyStyle(uniCssStyle) {
const
ATTR_MAP
=
{
class
:
'
.c
'
,
style
:
'
.s
'
,
onClick
:
'
.e0
'
,
onChange
:
'
.e1
'
,
onInput
:
'
.e2
'
,
onLoad
:
'
.e3
'
,
onError
:
'
.e4
'
,
onTouchstart
:
'
.e5
'
,
onTouchmove
:
'
.e6
'
,
onTouchcancel
:
'
.e7
'
,
onTouchend
:
'
.e8
'
,
onLongpress
:
'
.e9
'
,
onTransitionend
:
'
.ea
'
,
onAnimationstart
:
'
.eb
'
,
onAnimationiteration
:
'
.ec
'
,
onAnimationend
:
'
.ed
'
,
onTouchforcechange
:
'
.ee
'
,
};
function
encodeAttr
(
name
)
{
return
ATTR_MAP
[
name
]
||
name
;
}
const
ATTR_RESTORE_MAP
=
{
'
.c
'
:
'
class
'
,
'
.s
'
:
'
style
'
,
};
function
decodeAttr
(
name
)
{
return
ATTR_RESTORE_MAP
[
name
]
||
name
;
}
const
COMPONENT_MAP
=
{
VIEW
:
1
,
IMAGE
:
2
,
...
...
@@ -421,55 +429,6 @@ const COMPONENT_MAP = {
};
function
encodeTag
(
tag
)
{
return
COMPONENT_MAP
[
tag
]
||
tag
;
}
const
COMPONENT_ARR
=
[
''
,
'
view
'
,
'
image
'
,
'
text
'
,
'
#text
'
,
'
#comment
'
,
'
navigator
'
,
'
form
'
,
'
button
'
,
'
input
'
,
'
label
'
,
'
radio
'
,
'
checkbox
'
,
'
checkbox-group
'
,
'
ad
'
,
'
audio
'
,
'
camera
'
,
'
canvas
'
,
'
cover-image
'
,
'
cover-view
'
,
'
editor
'
,
'
functional-page-navigator
'
,
'
icon
'
,
'
radio-group
'
,
'
live-player
'
,
'
live-pusher
'
,
'
map
'
,
'
movable-area
'
,
'
movable-view
'
,
'
official-account
'
,
'
open-data
'
,
'
picker
'
,
'
picker-view
'
,
'
picker-view-column
'
,
'
progress
'
,
'
rich-text
'
,
'
scroll-view
'
,
'
slider
'
,
'
swiper
'
,
'
swiper-item
'
,
'
switch
'
,
'
textarea
'
,
'
video
'
,
'
web-view
'
,
];
function
decodeTag
(
tag
)
{
return
COMPONENT_ARR
[
tag
]
||
tag
;
}
const
NODE_TYPE_PAGE
=
0
;
...
...
@@ -624,7 +583,7 @@ class UniBaseNode extends UniNode {
removeEventListener
(
type
,
callback
,
options
)
{
super
.
removeEventListener
(
type
,
callback
,
options
);
const
normalized
=
normalizeEventType
(
type
);
if
(
this
.
attributes
[
normalized
])
{
if
(
this
.
attributes
[
encodeAttr
(
normalized
)
])
{
this
.
removeAttribute
(
normalized
);
}
}
...
...
@@ -709,6 +668,28 @@ class UniTextNode extends UniBaseNode {
}
}
const
DECODED_ATTR_MAP
=
/*#__PURE__*/
Object
.
keys
(
ATTR_MAP
).
reduce
((
map
,
name
)
=>
{
map
[
ATTR_MAP
[
name
]]
=
name
;
return
map
;
},
Object
.
create
(
null
));
function
decodeAttr
(
name
)
{
return
DECODED_ATTR_MAP
[
name
]
||
name
;
}
const
DECODED_COMPONENT_ARR
=
/*#__PURE__*/
Object
.
keys
(
COMPONENT_MAP
).
reduce
((
arr
,
name
)
=>
{
arr
.
push
(
name
.
toLowerCase
());
return
arr
;
},
[
''
]);
function
decodeTag
(
tag
)
{
return
DECODED_COMPONENT_ARR
[
tag
]
||
tag
;
}
const
cacheStringFunction
=
(
fn
)
=>
{
const
cache
=
Object
.
create
(
null
);
return
((
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
});
};
function
getLen
(
str
=
''
)
{
return
(
''
+
str
).
replace
(
/
[^\x
00-
\x
ff
]
/g
,
'
**
'
).
length
;
}
...
...
@@ -879,7 +860,10 @@ const UNI_SSR = '__uniSSR';
const
UNI_SSR_TITLE
=
'
title
'
;
const
UNI_SSR_STORE
=
'
store
'
;
const
UNI_SSR_DATA
=
'
data
'
;
const
UNI_SSR_GLOBAL_DATA
=
'
globalData
'
;
const
UNI_SSR_GLOBAL_DATA
=
'
globalData
'
;
const
SCHEME_RE
=
/^
([
a-z-
]
+:
)?\/\/
/i
;
const
DATA_RE
=
/^data:.*,.*/
;
const
WEB_INVOKE_APPSERVICE
=
'
WEB_INVOKE_APPSERVICE
'
;
function
getEnvLocale
()
{
const
{
env
}
=
process
;
...
...
@@ -887,4 +871,4 @@ function getEnvLocale() {
return
(
lang
&&
lang
.
replace
(
/
[
.:
]
.*/
,
''
))
||
'
en
'
;
}
export
{
BUILT_IN_TAGS
,
COMPONENT_NAME_PREFIX
,
COMPONENT_PREFIX
,
COMPONENT_SELECTOR_PREFIX
,
NAVBAR_HEIGHT
,
NODE_TYPE_COMMENT
,
NODE_TYPE_ELEMENT
,
NODE_TYPE_PAGE
,
NODE_TYPE_TEXT
,
ON_REACH_BOTTOM_DISTANCE
,
PLUS_RE
,
PRIMARY_COLOR
,
RESPONSIVE_MIN_WIDTH
,
TABBAR_HEIGHT
,
TAGS
,
UNI_SSR
,
UNI_SSR_DATA
,
UNI_SSR_GLOBAL_DATA
,
UNI_SSR_STORE
,
UNI_SSR_TITLE
,
UniBaseNode
,
UniCommentNode
,
UniElement
,
UniEvent
,
UniInputElement
,
UniNode
,
UniTextAreaElement
,
UniTextNode
,
addFont
,
callOptions
,
createRpx2Unit
,
debounce
,
decode
,
decodeAttr
,
decodeTag
,
decodedQuery
,
defaultRpx2Unit
,
encodeAttr
,
encodeTag
,
formatDateTime
,
getCustomDataset
,
getEnvLocale
,
getLen
,
initCustomDataset
,
invokeArrayFns
,
isBuiltInComponent
,
isCustomElement
,
isNativeTag
,
normalizeDataset
,
normalizeTarget
,
once
,
parseQuery
,
passive
,
plusReady
,
removeLeadingSlash
,
sanitise
,
scrollTo
,
stringifyQuery
,
updateElementStyle
};
export
{
BUILT_IN_TAGS
,
COMPONENT_NAME_PREFIX
,
COMPONENT_PREFIX
,
COMPONENT_SELECTOR_PREFIX
,
DATA_RE
,
NAVBAR_HEIGHT
,
NODE_TYPE_COMMENT
,
NODE_TYPE_ELEMENT
,
NODE_TYPE_PAGE
,
NODE_TYPE_TEXT
,
ON_REACH_BOTTOM_DISTANCE
,
PLUS_RE
,
PRIMARY_COLOR
,
RESPONSIVE_MIN_WIDTH
,
SCHEME_RE
,
TABBAR_HEIGHT
,
TAGS
,
UNI_SSR
,
UNI_SSR_DATA
,
UNI_SSR_GLOBAL_DATA
,
UNI_SSR_STORE
,
UNI_SSR_TITLE
,
UniBaseNode
,
UniCommentNode
,
UniElement
,
UniEvent
,
UniInputElement
,
UniNode
,
UniTextAreaElement
,
UniTextNode
,
WEB_INVOKE_APPSERVICE
,
addFont
,
cacheStringFunction
,
callOptions
,
createRpx2Unit
,
debounce
,
decode
,
decodeAttr
,
decodeTag
,
decodedQuery
,
defaultRpx2Unit
,
encodeAttr
,
encodeTag
,
formatDateTime
,
getCustomDataset
,
getEnvLocale
,
getLen
,
initCustomDataset
,
invokeArrayFns
,
isBuiltInComponent
,
isCustomElement
,
isNativeTag
,
normalizeDataset
,
normalizeTarget
,
once
,
parseQuery
,
passive
,
plusReady
,
removeLeadingSlash
,
sanitise
,
scrollTo
,
stringifyQuery
,
updateElementStyle
};
packages/uni-shared/src/constants.ts
浏览文件 @
da96069d
...
...
@@ -12,3 +12,8 @@ export const UNI_SSR_TITLE = 'title'
export
const
UNI_SSR_STORE
=
'
store
'
export
const
UNI_SSR_DATA
=
'
data
'
export
const
UNI_SSR_GLOBAL_DATA
=
'
globalData
'
export
const
SCHEME_RE
=
/^
([
a-z-
]
+:
)?\/\/
/i
export
const
DATA_RE
=
/^data:.*,.*/
export
const
WEB_INVOKE_APPSERVICE
=
'
WEB_INVOKE_APPSERVICE
'
packages/uni-shared/src/utils.ts
浏览文件 @
da96069d
export
const
cacheStringFunction
=
<
T
extends
(
str
:
string
)
=>
string
>
(
fn
:
T
):
T
=>
{
const
cache
:
Record
<
string
,
string
>
=
Object
.
create
(
null
)
return
((
str
:
string
)
=>
{
const
hit
=
cache
[
str
]
return
hit
||
(
cache
[
str
]
=
fn
(
str
))
})
as
any
}
export
function
getLen
(
str
=
''
)
{
return
(
''
+
str
).
replace
(
/
[^\x
00-
\x
ff
]
/g
,
'
**
'
).
length
}
...
...
packages/uni-shared/src/vdom/Node.ts
浏览文件 @
da96069d
...
...
@@ -8,7 +8,7 @@ import {
UniCSSStyleDeclaration
,
UniCSSStyleDeclarationJSON
,
}
from
'
./Style
'
import
{
encodeAttr
,
encodeTag
}
from
'
./
utils
'
import
{
encodeAttr
,
encodeTag
}
from
'
./
encode
'
export
const
NODE_TYPE_PAGE
=
0
export
const
NODE_TYPE_ELEMENT
=
1
...
...
@@ -270,7 +270,7 @@ export class UniBaseNode extends UniNode {
)
{
super
.
removeEventListener
(
type
,
callback
,
options
)
const
normalized
=
normalizeEventType
(
type
)
if
(
this
.
attributes
[
normalized
])
{
if
(
this
.
attributes
[
encodeAttr
(
normalized
)
])
{
this
.
removeAttribute
(
normalized
)
}
}
...
...
packages/uni-shared/src/vdom/decode.ts
0 → 100644
浏览文件 @
da96069d
import
{
ATTR_MAP
,
COMPONENT_MAP
}
from
'
./encode
'
const
DECODED_ATTR_MAP
=
/*#__PURE__*/
Object
.
keys
(
ATTR_MAP
).
reduce
(
(
map
,
name
)
=>
{
map
[
ATTR_MAP
[
name
as
keyof
typeof
ATTR_MAP
]]
=
name
return
map
},
Object
.
create
(
null
)
)
export
function
decodeAttr
(
name
:
string
)
{
return
DECODED_ATTR_MAP
[
name
as
keyof
typeof
DECODED_ATTR_MAP
]
||
name
}
const
DECODED_COMPONENT_ARR
=
/*#__PURE__*/
Object
.
keys
(
COMPONENT_MAP
).
reduce
(
(
arr
,
name
)
=>
{
arr
.
push
(
name
.
toLowerCase
())
return
arr
},
[
''
]
)
export
function
decodeTag
(
tag
:
string
|
number
)
{
return
DECODED_COMPONENT_ARR
[
tag
as
number
]
||
tag
}
packages/uni-shared/src/vdom/
utils
.ts
→
packages/uni-shared/src/vdom/
encode
.ts
浏览文件 @
da96069d
export
const
ATTR_MAP
=
{
class
:
'
.c
'
,
style
:
'
.s
'
,
onClick
:
'
.e0
'
,
onChange
:
'
.e1
'
,
onInput
:
'
.e2
'
,
onLoad
:
'
.e3
'
,
onError
:
'
.e4
'
,
onTouchstart
:
'
.e5
'
,
onTouchmove
:
'
.e6
'
,
onTouchcancel
:
'
.e7
'
,
onTouchend
:
'
.e8
'
,
onLongpress
:
'
.e9
'
,
onTransitionend
:
'
.ea
'
,
onAnimationstart
:
'
.eb
'
,
onAnimationiteration
:
'
.ec
'
,
onAnimationend
:
'
.ed
'
,
onTouchforcechange
:
'
.ee
'
,
}
export
function
encodeAttr
(
name
:
string
)
{
return
ATTR_MAP
[
name
as
keyof
typeof
ATTR_MAP
]
||
name
}
export
const
ATTR_RESTORE_MAP
=
{
'
.c
'
:
'
class
'
,
'
.s
'
:
'
style
'
,
}
export
function
decodeAttr
(
name
:
string
)
{
return
ATTR_RESTORE_MAP
[
name
as
keyof
typeof
ATTR_RESTORE_MAP
]
||
name
}
export
const
COMPONENT_MAP
=
{
VIEW
:
1
,
IMAGE
:
2
,
...
...
@@ -65,54 +71,3 @@ export const COMPONENT_MAP = {
export
function
encodeTag
(
tag
:
string
)
{
return
COMPONENT_MAP
[
tag
as
keyof
typeof
COMPONENT_MAP
]
||
tag
}
const
COMPONENT_ARR
=
[
''
,
'
view
'
,
'
image
'
,
'
text
'
,
'
#text
'
,
'
#comment
'
,
'
navigator
'
,
'
form
'
,
'
button
'
,
'
input
'
,
'
label
'
,
'
radio
'
,
'
checkbox
'
,
'
checkbox-group
'
,
'
ad
'
,
'
audio
'
,
'
camera
'
,
'
canvas
'
,
'
cover-image
'
,
'
cover-view
'
,
'
editor
'
,
'
functional-page-navigator
'
,
'
icon
'
,
'
radio-group
'
,
'
live-player
'
,
'
live-pusher
'
,
'
map
'
,
'
movable-area
'
,
'
movable-view
'
,
'
official-account
'
,
'
open-data
'
,
'
picker
'
,
'
picker-view
'
,
'
picker-view-column
'
,
'
progress
'
,
'
rich-text
'
,
'
scroll-view
'
,
'
slider
'
,
'
swiper
'
,
'
swiper-item
'
,
'
switch
'
,
'
textarea
'
,
'
video
'
,
'
web-view
'
,
]
export
function
decodeTag
(
tag
:
string
|
number
)
{
return
COMPONENT_ARR
[
tag
as
number
]
||
tag
}
packages/uni-shared/src/vdom/index.ts
浏览文件 @
da96069d
...
...
@@ -12,4 +12,5 @@ export {
IUniPageNode
,
}
from
'
./Node
'
export
{
UniTextNode
}
from
'
./Text
'
export
{
encodeTag
,
decodeTag
,
encodeAttr
,
decodeAttr
}
from
'
./utils
'
export
{
encodeAttr
,
encodeTag
}
from
'
./encode
'
export
{
decodeAttr
,
decodeTag
}
from
'
./decode
'
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录