Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
9e2e54cd
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
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,发现更多精彩内容 >>
提交
9e2e54cd
编写于
8月 09, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(app): wxs
上级
16da9f60
变更
35
显示空白变更内容
内联
并排
Showing
35 changed file
with
666 addition
and
38 deletion
+666
-38
packages/uni-app-plus/dist/tools.umd.js
packages/uni-app-plus/dist/tools.umd.js
+23
-1
packages/uni-app-plus/dist/uni-app-service.es.js
packages/uni-app-plus/dist/uni-app-service.es.js
+68
-1
packages/uni-app-plus/dist/uni-app-view.umd.js
packages/uni-app-plus/dist/uni-app-view.umd.js
+54
-0
packages/uni-app-plus/src/service/framework/dom/Page.ts
packages/uni-app-plus/src/service/framework/dom/Page.ts
+27
-0
packages/uni-app-plus/src/view/framework/dom/decodeActions.ts
...ages/uni-app-plus/src/view/framework/dom/decodeActions.ts
+31
-0
packages/uni-app-plus/src/view/framework/dom/elements/UniElement.ts
...ni-app-plus/src/view/framework/dom/elements/UniElement.ts
+13
-1
packages/uni-app-plus/src/view/framework/dom/index.ts
packages/uni-app-plus/src/view/framework/dom/index.ts
+7
-0
packages/uni-app-plus/src/view/framework/dom/modules/events.ts
...ges/uni-app-plus/src/view/framework/dom/modules/events.ts
+60
-0
packages/uni-app-vite/dist/index.js
packages/uni-app-vite/dist/index.js
+2
-0
packages/uni-app-vite/dist/plugin/uni/index.js
packages/uni-app-vite/dist/plugin/uni/index.js
+0
-0
packages/uni-app-vite/dist/plugin/uni/transforms/transformRenderjs.js
...-app-vite/dist/plugin/uni/transforms/transformRenderjs.js
+5
-0
packages/uni-app-vite/dist/plugins/renderjs.js
packages/uni-app-vite/dist/plugins/renderjs.js
+3
-1
packages/uni-app-vite/src/index.ts
packages/uni-app-vite/src/index.ts
+2
-0
packages/uni-app-vite/src/plugin/uni/index.ts
packages/uni-app-vite/src/plugin/uni/index.ts
+0
-0
packages/uni-app-vite/src/plugin/uni/transforms/transformRenderjs.ts
...i-app-vite/src/plugin/uni/transforms/transformRenderjs.ts
+3
-0
packages/uni-app-vite/src/plugins/renderjs.ts
packages/uni-app-vite/src/plugins/renderjs.ts
+30
-0
packages/uni-app-vue/dist/service.runtime.esm.js
packages/uni-app-vue/dist/service.runtime.esm.js
+60
-9
packages/uni-app-vue/lib/service.runtime.esm.js
packages/uni-app-vue/lib/service.runtime.esm.js
+26
-7
packages/uni-cli-shared/src/vite/index.ts
packages/uni-cli-shared/src/vite/index.ts
+1
-0
packages/uni-components/src/components/form/index.tsx
packages/uni-components/src/components/form/index.tsx
+1
-1
packages/uni-h5/dist/uni-h5.cjs.js
packages/uni-h5/dist/uni-h5.cjs.js
+4
-1
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+4
-1
packages/uni-shared/dist/uni-shared.cjs.js
packages/uni-shared/dist/uni-shared.cjs.js
+27
-2
packages/uni-shared/dist/uni-shared.d.ts
packages/uni-shared/dist/uni-shared.d.ts
+31
-1
packages/uni-shared/dist/uni-shared.es.js
packages/uni-shared/dist/uni-shared.es.js
+25
-3
packages/uni-shared/src/constants.ts
packages/uni-shared/src/constants.ts
+3
-0
packages/uni-shared/src/vdom/Action.ts
packages/uni-shared/src/vdom/Action.ts
+16
-0
packages/uni-shared/src/vdom/Event.ts
packages/uni-shared/src/vdom/Event.ts
+1
-0
packages/uni-shared/src/vdom/Node.ts
packages/uni-shared/src/vdom/Node.ts
+42
-6
packages/uni-vue/src/componentOptions/hooks.ts
packages/uni-vue/src/componentOptions/hooks.ts
+1
-1
packages/uni-vue/src/componentOptions/index.ts
packages/uni-vue/src/componentOptions/index.ts
+22
-0
packages/uni-vue/src/componentOptions/renderjs.ts
packages/uni-vue/src/componentOptions/renderjs.ts
+55
-0
packages/uni-vue/src/componentOptions/wxs.ts
packages/uni-vue/src/componentOptions/wxs.ts
+9
-0
packages/vite-plugin-uni/package.json
packages/vite-plugin-uni/package.json
+1
-1
packages/vite-plugin-uni/src/vue/options.ts
packages/vite-plugin-uni/src/vue/options.ts
+9
-1
未找到文件。
packages/uni-app-plus/dist/tools.umd.js
浏览文件 @
9e2e54cd
...
...
@@ -14,6 +14,7 @@
const
ACTION_TYPE_ADD_EVENT
=
8
;
const
ACTION_TYPE_REMOVE_EVENT
=
9
;
const
ACTION_TYPE_SET_TEXT
=
10
;
const
ACTION_TYPE_ADD_WXS_EVENT
=
12
;
const
ACTION_TYPE_DICT
=
0
;
...
...
@@ -64,6 +65,8 @@
return
decodeRemoveAttributeAction
(
action
,
getDict
);
case
ACTION_TYPE_ADD_EVENT
:
return
decodeAddEventAction
(
action
,
getDict
);
case
ACTION_TYPE_ADD_WXS_EVENT
:
return
decodeAddWxsEventAction
(
action
,
getDict
);
case
ACTION_TYPE_REMOVE_EVENT
:
return
decodeRemoveEventAction
(
action
,
getDict
);
case
ACTION_TYPE_SET_TEXT
:
...
...
@@ -87,6 +90,9 @@
if
(
nodeJson
.
e
)
{
nodeJson
.
e
=
getDict
(
nodeJson
.
e
,
false
);
}
if
(
nodeJson
.
w
)
{
nodeJson
.
w
=
getWxsEventDict
(
nodeJson
.
w
,
getDict
);
}
if
(
nodeJson
.
s
)
{
nodeJson
.
s
=
getDict
(
nodeJson
.
s
);
}
...
...
@@ -95,6 +101,13 @@
}
return
nodeJson
;
}
function
getWxsEventDict
(
w
,
getDict
)
{
const
res
=
{};
w
.
forEach
(([
name
,
[
wxsEvent
,
flag
]])
=>
{
res
[
getDict
(
name
)]
=
[
getDict
(
wxsEvent
),
flag
];
});
return
res
;
}
function
decodeCreateAction
([,
nodeId
,
nodeName
,
parentNodeId
,
refNodeId
,
nodeJson
],
getDict
)
{
return
[
'
create
'
,
...
...
@@ -114,6 +127,15 @@
function
decodeAddEventAction
([,
...
action
],
getDict
)
{
return
[
'
addEvent
'
,
action
[
0
],
getDict
(
action
[
1
]),
action
[
2
]];
}
function
decodeAddWxsEventAction
([,
...
action
],
getDict
)
{
return
[
'
addWxsEvent
'
,
action
[
0
],
getDict
(
action
[
1
]),
getDict
(
action
[
2
]),
action
[
3
],
];
}
function
decodeRemoveEventAction
([,
...
action
],
getDict
)
{
return
[
'
removeEvent
'
,
action
[
0
],
getDict
(
action
[
1
])];
}
...
...
packages/uni-app-plus/dist/uni-app-service.es.js
浏览文件 @
9e2e54cd
...
...
@@ -1055,6 +1055,7 @@ var serviceContext = (function (vue) {
const ACTION_TYPE_ADD_EVENT = 8;
const ACTION_TYPE_REMOVE_EVENT = 9;
const ACTION_TYPE_SET_TEXT = 10;
const ACTION_TYPE_ADD_WXS_EVENT = 12;
const ACTION_TYPE_PAGE_SCROLL = 15;
const ACTION_TYPE_EVENT = 20;
...
...
@@ -1133,6 +1134,7 @@ var serviceContext = (function (vue) {
const BACKGROUND_COLOR = '#f7f7f7'; // 背景色,如标题栏默认背景色
const SCHEME_RE = /^([a-z-]+:)?\/\//i;
const DATA_RE = /^data:.*,.*/;
const WXS_PROTOCOL = 'wxs://';
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
...
...
@@ -9371,7 +9373,7 @@ var serviceContext = (function (vue) {
}, errorCallback);
}, RequestPaymentProtocol);
function
applyOption
s(options, instance, publicThis) {
function
initHook
s(options, instance, publicThis) {
const mpType = options.mpType || publicThis.$mpType;
// 为了组件也可以监听部分生命周期,故不再判断mpType,统一添加on开头的生命周期
Object.keys(options).forEach((name) => {
...
...
@@ -9393,6 +9395,57 @@ var serviceContext = (function (vue) {
}
}
function initRenderjs({ $renderjs }, instance) {
initModules(instance, $renderjs);
}
function initModules(instance, modules) {
if (!isArray(modules)) {
return;
}
const ctx = instance.ctx;
const $wxsModules = (instance.$wxsModules ||
(instance.$wxsModules = []));
modules.forEach((module) => {
ctx[module] = proxyModule(module);
$wxsModules.push(module);
});
}
const renderjsModule = {};
function proxyModule(module) {
return new Proxy(renderjsModule, {
get(_, p) {
return createModuleFunction(module, p);
},
});
}
function renderjsFn() { }
function createModuleFunction(module, name) {
const toJSON = () => WXS_PROTOCOL + JSON.stringify([module + '.' + name]);
return new Proxy(renderjsFn, {
get(_, p) {
if (p === 'toJSON') {
return toJSON;
}
return createModuleFunction(module + '.' + name, p);
},
apply(_target, _thisArg, args) {
return WXS_PROTOCOL + JSON.stringify([module + '.' + name, ...args]);
},
});
}
function initWxs({ $wxs }, instance) {
initModules(instance, $wxs);
}
function applyOptions(options, instance, publicThis) {
{
initWxs(options, instance);
initRenderjs(options, instance);
}
initHooks(options, instance, publicThis);
}
function set(target, key, val) {
return (target[key] = val);
}
...
...
@@ -10467,6 +10520,11 @@ var serviceContext = (function (vue) {
pushAddEventAction(this, thisNode.nodeId, name, flag);
}
}
onAddWxsEvent(thisNode, name, wxsEvent, flag) {
if (thisNode.parentNode) {
pushAddWxsEventAction(this, thisNode.nodeId, name, wxsEvent, flag);
}
}
onRemoveEvent(thisNode, name) {
if (thisNode.parentNode) {
pushRemoveEventAction(this, thisNode.nodeId, name);
...
...
@@ -10622,6 +10680,15 @@ var serviceContext = (function (vue) {
function pushAddEventAction(pageNode, nodeId, name, value) {
pageNode.push([ACTION_TYPE_ADD_EVENT, nodeId, pageNode.addDict(name), value]);
}
function pushAddWxsEventAction(pageNode, nodeId, name, wxsEvent, value) {
pageNode.push([
ACTION_TYPE_ADD_WXS_EVENT,
nodeId,
pageNode.addDict(name),
pageNode.addDict(wxsEvent),
value,
]);
}
function pushRemoveEventAction(pageNode, nodeId, name) {
pageNode.push([ACTION_TYPE_REMOVE_EVENT, nodeId, pageNode.addDict(name)]);
}
...
...
packages/uni-app-plus/dist/uni-app-view.umd.js
浏览文件 @
9e2e54cd
...
...
@@ -874,6 +874,7 @@
var ACTION_TYPE_ADD_EVENT = 8;
var ACTION_TYPE_REMOVE_EVENT = 9;
var ACTION_TYPE_SET_TEXT = 10;
var ACTION_TYPE_ADD_WXS_EVENT = 12;
var ACTION_TYPE_PAGE_SCROLL = 15;
var ACTION_TYPE_EVENT = 20;
function cache(fn) {
...
...
@@ -7394,6 +7395,9 @@
if (nodeJson.e) {
nodeJson.e = getDict(nodeJson.e, false);
}
if (nodeJson.w) {
nodeJson.w = getWxsEventDict(nodeJson.w, getDict);
}
if (nodeJson.s) {
nodeJson.s = getDict(nodeJson.s);
}
...
...
@@ -7402,6 +7406,13 @@
}
return nodeJson;
}
function getWxsEventDict(w, getDict) {
var res = {};
w.forEach(([name, [wxsEvent, flag]]) => {
res[getDict(name)] = [getDict(wxsEvent), flag];
});
return res;
}
class UniNode {
constructor(id2, tag, parentNodeId, element) {
this.isMounted = false;
...
...
@@ -7545,6 +7556,35 @@
}
return modifiers;
}
function patchWxsEvent(el, name, wxsEvent, flag) {
var [type, options] = parseEventName(name);
if (flag === -1) {
var listener = el.__listeners[type];
if (listener) {
el.removeEventListener(type, listener);
} else {
console.error(formatLog("tag", el.tagName, el.__id, "event[" + type + "] not found"));
}
} else {
if (el.__listeners[type]) {
{
console.error(formatLog("tag", el.tagName, el.__id, "event[" + type + "] already registered"));
}
return;
}
el.__listeners[type] = createWxsEventInvoker(el.__id, wxsEvent, flag, options);
el.addEventListener(type, el.__listeners[type], options);
}
}
function createWxsEventInvoker(id2, wxsEvent, flag, options) {
var invoker = (evt) => {
console.log("call wxsEvent", id2, wxsEvent, flag, options);
};
if (!flag) {
return invoker;
}
return withModifiers(invoker, resolveModifier(flag));
}
var postActionJobs = new Set();
function queuePostActionJob(job) {
postActionJobs.add(job);
...
...
@@ -7591,6 +7631,9 @@
if (hasOwn$1(nodeJson, "e")) {
this.addEvents(nodeJson.e);
}
if (hasOwn$1(nodeJson, "w")) {
this.addWxsEvents(nodeJson.w);
}
super.init(nodeJson);
watch(this.$props, () => {
queuePostActionJob(this._update);
...
...
@@ -7604,11 +7647,20 @@
this.setAttr(name, attrs2[name]);
});
}
addWxsEvents(events) {
Object.keys(events).forEach((name) => {
var [wxsEvent, flag] = events[name];
this.addWxsEvent(name, wxsEvent, flag);
});
}
addEvents(events) {
Object.keys(events).forEach((name) => {
this.addEvent(name, events[name]);
});
}
addWxsEvent(name, wxsEvent, flag) {
patchWxsEvent(this.$, name, wxsEvent, flag);
}
addEvent(name, value) {
patchEvent(this.$, name, value);
}
...
...
@@ -17956,6 +18008,8 @@
return $(action[1]).removeAttr(getDict(action[2]));
case ACTION_TYPE_ADD_EVENT:
return $(action[1]).addEvent(getDict(action[2]), action[3]);
case ACTION_TYPE_ADD_WXS_EVENT:
return $(action[1]).addWxsEvent(getDict(action[2]), getDict(action[3]), action[4]);
case ACTION_TYPE_REMOVE_EVENT:
return $(action[1]).removeEvent(getDict(action[2]));
case ACTION_TYPE_SET_TEXT:
...
...
packages/uni-app-plus/src/service/framework/dom/Page.ts
浏览文件 @
9e2e54cd
...
...
@@ -27,6 +27,7 @@ import {
ON_PAGE_SCROLL
,
ON_REACH_BOTTOM
,
ACTION_TYPE_PAGE_SCROLL
,
ACTION_TYPE_ADD_WXS_EVENT
,
}
from
'
@dcloudio/uni-shared
'
import
{
getPageById
}
from
'
@dcloudio/uni-core
'
...
...
@@ -153,6 +154,16 @@ export default class UniPageNode extends UniNode implements IUniPageNode {
pushAddEventAction
(
this
,
thisNode
.
nodeId
!
,
name
,
flag
)
}
}
onAddWxsEvent
(
thisNode
:
UniNode
,
name
:
string
,
wxsEvent
:
string
,
flag
:
number
)
{
if
(
thisNode
.
parentNode
)
{
pushAddWxsEventAction
(
this
,
thisNode
.
nodeId
!
,
name
,
wxsEvent
,
flag
)
}
}
onRemoveEvent
(
thisNode
:
UniNode
,
name
:
string
)
{
if
(
thisNode
.
parentNode
)
{
pushRemoveEventAction
(
this
,
thisNode
.
nodeId
!
,
name
)
...
...
@@ -344,6 +355,22 @@ function pushAddEventAction(
pageNode
.
push
([
ACTION_TYPE_ADD_EVENT
,
nodeId
,
pageNode
.
addDict
(
name
),
value
])
}
function
pushAddWxsEventAction
(
pageNode
:
UniPageNode
,
nodeId
:
number
,
name
:
string
,
wxsEvent
:
string
,
value
:
number
)
{
pageNode
.
push
([
ACTION_TYPE_ADD_WXS_EVENT
,
nodeId
,
pageNode
.
addDict
(
name
),
pageNode
.
addDict
(
wxsEvent
),
value
,
])
}
function
pushRemoveEventAction
(
pageNode
:
UniPageNode
,
nodeId
:
number
,
...
...
packages/uni-app-plus/src/view/framework/dom/decodeActions.ts
浏览文件 @
9e2e54cd
import
{
ACTION_TYPE_ADD_EVENT
,
ACTION_TYPE_ADD_WXS_EVENT
,
ACTION_TYPE_CREATE
,
ACTION_TYPE_INSERT
,
ACTION_TYPE_PAGE_CREATE
,
...
...
@@ -10,6 +11,7 @@ import {
ACTION_TYPE_SET_ATTRIBUTE
,
ACTION_TYPE_SET_TEXT
,
AddEventAction
,
AddWxsEventAction
,
CreateAction
,
InsertAction
,
PageAction
,
...
...
@@ -84,6 +86,8 @@ export function decodeActions(actions: (PageAction | DictAction)[]) {
return
decodeRemoveAttributeAction
(
action
,
getDict
)
case
ACTION_TYPE_ADD_EVENT
:
return
decodeAddEventAction
(
action
,
getDict
)
case
ACTION_TYPE_ADD_WXS_EVENT
:
return
decodeAddWxsEventAction
(
action
,
getDict
)
case
ACTION_TYPE_REMOVE_EVENT
:
return
decodeRemoveEventAction
(
action
,
getDict
)
case
ACTION_TYPE_SET_TEXT
:
...
...
@@ -119,6 +123,12 @@ export function decodeNodeJson(
false
)
as
Record
<
string
,
number
>
}
if
(
nodeJson
.
w
)
{
;(
nodeJson
as
unknown
as
UniNodeJSON
).
w
=
getWxsEventDict
(
nodeJson
.
w
,
getDict
)
}
if
(
nodeJson
.
s
)
{
;(
nodeJson
as
unknown
as
UniNodeJSON
).
s
=
getDict
(
nodeJson
.
s
as
[
number
,
number
][]
...
...
@@ -130,6 +140,14 @@ export function decodeNodeJson(
return
nodeJson
as
unknown
as
UniNodeJSON
}
function
getWxsEventDict
(
w
:
UniNodeJSONMinify
[
'
w
'
],
getDict
:
GetDict
)
{
const
res
:
UniNodeJSON
[
'
w
'
]
=
{}
w
.
forEach
(([
name
,
[
wxsEvent
,
flag
]])
=>
{
res
[
getDict
(
name
)]
=
[
getDict
(
wxsEvent
),
flag
]
})
return
res
}
function
decodeCreateAction
(
[,
nodeId
,
nodeName
,
parentNodeId
,
refNodeId
,
nodeJson
]:
CreateAction
,
getDict
:
GetDict
...
...
@@ -156,6 +174,19 @@ function decodeAddEventAction([, ...action]: AddEventAction, getDict: GetDict) {
return
[
'
addEvent
'
,
action
[
0
],
getDict
(
action
[
1
]
as
number
),
action
[
2
]]
}
function
decodeAddWxsEventAction
(
[,
...
action
]:
AddWxsEventAction
,
getDict
:
GetDict
)
{
return
[
'
addWxsEvent
'
,
action
[
0
],
getDict
(
action
[
1
]
as
number
),
getDict
(
action
[
2
]
as
number
),
action
[
3
],
]
}
function
decodeRemoveEventAction
(
[,
...
action
]:
RemoveEventAction
,
getDict
:
GetDict
...
...
packages/uni-app-plus/src/view/framework/dom/elements/UniElement.ts
浏览文件 @
9e2e54cd
...
...
@@ -11,7 +11,7 @@ import { reactive, watch } from 'vue'
import
{
UniNode
}
from
'
./UniNode
'
import
{
patchClass
}
from
'
../modules/class
'
import
{
patchStyle
}
from
'
../modules/style
'
import
{
patchEvent
}
from
'
../modules/events
'
import
{
patchEvent
,
patchWxsEvent
}
from
'
../modules/events
'
import
{
UniCustomElement
}
from
'
../components
'
import
{
queuePostActionJob
}
from
'
../scheduler
'
import
{
decodeAttr
}
from
'
../utils
'
...
...
@@ -48,6 +48,9 @@ export class UniElement<T extends object> extends UniNode {
if
(
hasOwn
(
nodeJson
,
'
e
'
))
{
this
.
addEvents
(
nodeJson
.
e
!
)
}
if
(
hasOwn
(
nodeJson
,
'
w
'
))
{
this
.
addWxsEvents
(
nodeJson
.
w
!
)
}
super
.
init
(
nodeJson
)
watch
(
this
.
$props
,
...
...
@@ -63,11 +66,20 @@ export class UniElement<T extends object> extends UniNode {
this
.
setAttr
(
name
,
attrs
[
name
])
})
}
addWxsEvents
(
events
:
Record
<
string
,
[
string
,
number
]
>
)
{
Object
.
keys
(
events
).
forEach
((
name
)
=>
{
const
[
wxsEvent
,
flag
]
=
events
[
name
]
this
.
addWxsEvent
(
name
,
wxsEvent
,
flag
)
})
}
addEvents
(
events
:
Record
<
string
,
number
>
)
{
Object
.
keys
(
events
).
forEach
((
name
)
=>
{
this
.
addEvent
(
name
,
events
[
name
])
})
}
addWxsEvent
(
name
:
string
,
wxsEvent
:
string
,
flag
:
number
)
{
patchWxsEvent
(
this
.
$
,
name
,
wxsEvent
,
flag
)
}
addEvent
(
name
:
string
,
value
:
number
)
{
patchEvent
(
this
.
$
,
name
,
value
)
}
...
...
packages/uni-app-plus/src/view/framework/dom/index.ts
浏览文件 @
9e2e54cd
...
...
@@ -13,6 +13,7 @@ import {
PageCreateAction
,
formatLog
,
ACTION_TYPE_PAGE_SCROLL
,
ACTION_TYPE_ADD_WXS_EVENT
,
}
from
'
@dcloudio/uni-shared
'
import
{
UniNodeJSONMinify
}
from
'
packages/uni-shared/src/vdom/Node
'
import
{
ACTION_TYPE_DICT
,
DictAction
,
Dictionary
}
from
'
../../../constants
'
...
...
@@ -76,6 +77,12 @@ function onPageUpdateSync(actions: (PageAction | DictAction)[]) {
return
$
(
action
[
1
]).
removeAttr
(
getDict
(
action
[
2
]
as
number
))
case
ACTION_TYPE_ADD_EVENT
:
return
$
(
action
[
1
]).
addEvent
(
getDict
(
action
[
2
]
as
number
),
action
[
3
])
case
ACTION_TYPE_ADD_WXS_EVENT
:
return
$
(
action
[
1
]).
addWxsEvent
(
getDict
(
action
[
2
]
as
number
),
getDict
(
action
[
3
]
as
number
),
action
[
4
]
)
case
ACTION_TYPE_REMOVE_EVENT
:
return
$
(
action
[
1
]).
removeEvent
(
getDict
(
action
[
2
]
as
number
))
case
ACTION_TYPE_SET_TEXT
:
...
...
packages/uni-app-plus/src/view/framework/dom/modules/events.ts
浏览文件 @
9e2e54cd
...
...
@@ -71,3 +71,63 @@ function resolveModifier(flag: number) {
}
return
modifiers
}
export
function
patchWxsEvent
(
el
:
UniCustomElement
,
name
:
string
,
wxsEvent
:
string
,
flag
:
number
)
{
const
[
type
,
options
]
=
parseEventName
(
name
)
if
(
flag
===
-
1
)
{
// remove
const
listener
=
el
.
__listeners
[
type
]
if
(
listener
)
{
el
.
removeEventListener
(
type
,
listener
)
}
else
if
(
__DEV__
)
{
console
.
error
(
formatLog
(
`tag`
,
el
.
tagName
,
el
.
__id
,
'
event[
'
+
type
+
'
] not found
'
)
)
}
}
else
{
// add
if
(
el
.
__listeners
[
type
])
{
if
(
__DEV__
)
{
console
.
error
(
formatLog
(
`tag`
,
el
.
tagName
,
el
.
__id
,
'
event[
'
+
type
+
'
] already registered
'
)
)
}
return
}
el
.
__listeners
[
type
]
=
createWxsEventInvoker
(
el
.
__id
,
wxsEvent
,
flag
,
options
)
el
.
addEventListener
(
type
,
el
.
__listeners
[
type
],
options
)
}
}
function
createWxsEventInvoker
(
id
:
number
,
wxsEvent
:
string
,
flag
:
number
,
options
?:
AddEventListenerOptions
)
{
const
invoker
=
(
evt
:
Event
)
=>
{
console
.
log
(
'
call wxsEvent
'
,
id
,
wxsEvent
,
flag
,
options
)
// const event = normalizeNativeEvent(evt)
// ;(event as any).type = normalizeEventType(evt.type, options)
// UniViewJSBridge.publishHandler(VD_SYNC, [[ACTION_TYPE_EVENT, id, event]])
}
if
(
!
flag
)
{
return
invoker
}
return
withModifiers
(
invoker
,
resolveModifier
(
flag
))
}
packages/uni-app-vite/dist/index.js
浏览文件 @
9e2e54cd
...
...
@@ -7,6 +7,7 @@ const mainJs_1 = require("./plugins/mainJs");
const
manifestJson_1
=
require
(
"
./plugins/manifestJson
"
);
const
pagesJson_1
=
require
(
"
./plugins/pagesJson
"
);
const
resolveId_1
=
require
(
"
./plugins/resolveId
"
);
const
renderjs_1
=
require
(
"
./plugins/renderjs
"
);
function
initUniCssScopedPluginOptions
()
{
const
styleIsolation
=
uni_cli_shared_1
.
getAppStyleIsolation
(
uni_cli_shared_1
.
parseManifestJsonOnce
(
process
.
env
.
UNI_INPUT_DIR
));
if
(
styleIsolation
===
'
shared
'
)
{
...
...
@@ -26,6 +27,7 @@ const plugins = [
manifestJson_1
.
uniManifestJsonPlugin
(),
pagesJson_1
.
uniPagesJsonPlugin
(),
uni_cli_shared_1
.
uniViteInjectPlugin
(
uni_cli_shared_1
.
initProvide
()),
renderjs_1
.
uniRenderjsPlugin
(),
plugin_1
.
UniAppPlugin
,
];
const
uniCssScopedPluginOptions
=
initUniCssScopedPluginOptions
();
...
...
packages/uni-app-vite/dist/plugin/uni.js
→
packages/uni-app-vite/dist/plugin/uni
/index
.js
浏览文件 @
9e2e54cd
文件已移动
packages/uni-app-vite/dist/plugin/uni/transforms/transformRenderjs.js
0 → 100644
浏览文件 @
9e2e54cd
"
use strict
"
;
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
transformRenderjs
=
void
0
;
const
transformRenderjs
=
()
=>
{
};
exports
.
transformRenderjs
=
transformRenderjs
;
packages/uni-app-vite/dist/plugins/renderjs.js
浏览文件 @
9e2e54cd
...
...
@@ -24,7 +24,9 @@ function uniRenderjsPlugin() {
type
:
'
asset
'
,
source
:
code
,
});
return
''
;
return
`export default Comp => {
;(Comp.$
${
type
}
|| (Comp.$
${
type
}
= [])).push('
${
name
}
')
}`
;
},
};
}
...
...
packages/uni-app-vite/src/index.ts
浏览文件 @
9e2e54cd
...
...
@@ -11,6 +11,7 @@ import { uniMainJsPlugin } from './plugins/mainJs'
import
{
uniManifestJsonPlugin
}
from
'
./plugins/manifestJson
'
import
{
uniPagesJsonPlugin
}
from
'
./plugins/pagesJson
'
import
{
uniResolveIdPlugin
}
from
'
./plugins/resolveId
'
import
{
uniRenderjsPlugin
}
from
'
./plugins/renderjs
'
function
initUniCssScopedPluginOptions
()
{
const
styleIsolation
=
getAppStyleIsolation
(
...
...
@@ -34,6 +35,7 @@ const plugins = [
uniManifestJsonPlugin
(),
uniPagesJsonPlugin
(),
uniViteInjectPlugin
(
initProvide
()),
uniRenderjsPlugin
(),
UniAppPlugin
,
]
...
...
packages/uni-app-vite/src/plugin/uni.ts
→
packages/uni-app-vite/src/plugin/uni
/index
.ts
浏览文件 @
9e2e54cd
文件已移动
packages/uni-app-vite/src/plugin/uni/transforms/transformRenderjs.ts
0 → 100644
浏览文件 @
9e2e54cd
import
{
NodeTransform
}
from
'
@vue/compiler-core
'
export
const
transformRenderjs
:
NodeTransform
=
()
=>
{}
packages/uni-app-vite/src/plugins/renderjs.ts
0 → 100644
浏览文件 @
9e2e54cd
import
debug
from
'
debug
'
import
{
Plugin
}
from
'
vite
'
import
{
missingModuleName
,
parseRenderjs
}
from
'
@dcloudio/uni-cli-shared
'
const
debugRenderjs
=
debug
(
'
vite:uni:renderjs
'
)
export
function
uniRenderjsPlugin
():
Plugin
{
return
{
name
:
'
vite:uni-app-renderjs
'
,
transform
(
code
,
id
)
{
const
{
type
,
name
}
=
parseRenderjs
(
id
)
if
(
!
type
)
{
return
}
debugRenderjs
(
id
)
if
(
!
name
)
{
this
.
error
(
missingModuleName
(
type
,
code
))
}
this
.
emitFile
({
fileName
:
'
.renderjs.js
'
,
type
:
'
asset
'
,
source
:
code
,
})
return
`export default Comp => {
;(Comp.$
${
type
}
|| (Comp.$
${
type
}
= [])).push('
${
name
}
')
}`
},
}
}
packages/uni-app-vue/dist/service.runtime.esm.js
浏览文件 @
9e2e54cd
...
...
@@ -410,9 +410,13 @@ export default function vueFactory(exports) {
super
.
addEventListener
(
type
,
listener
,
options
);
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
if
(
listener
.
wxsEvent
)
{
this
.
pageNode
.
onAddWxsEvent
(
this
,
normalizeEventType
(
type
,
options
),
listener
.
wxsEvent
,
encodeModifier
(
listener
.
modifiers
||
[]));
}
else
{
this
.
pageNode
.
onAddEvent
(
this
,
normalizeEventType
(
type
,
options
),
encodeModifier
(
listener
.
modifiers
||
[]));
}
}
}
removeEventListener
(
type
,
callback
,
options
)
{
super
.
removeEventListener
(
type
,
callback
,
options
);
...
...
@@ -473,16 +477,35 @@ export default function vueFactory(exports) {
var
events
=
Object
.
keys
(
listeners
);
if
(
events
.
length
)
{
var
w
=
undefined
;
var
e
=
{};
events
.
forEach
(
name
=>
{
var
handlers
=
listeners
[
name
];
if
(
handlers
.
length
)
{
// 可能存在多个 handler 且不同 modifiers 吗?
e
[
name
]
=
encodeModifier
(
handlers
[
0
].
modifiers
||
[]);
var
{
wxsEvent
,
modifiers
}
=
handlers
[
0
];
var
modifier
=
encodeModifier
(
modifiers
||
[]);
if
(
!
wxsEvent
)
{
e
[
name
]
=
modifier
;
}
else
{
if
(
!
w
)
{
w
=
{};
}
w
[
name
]
=
[
normalize
?
normalize
(
wxsEvent
)
:
wxsEvent
,
modifier
];
}
}
});
res
.
e
=
normalize
?
normalize
(
e
,
false
)
:
e
;
if
(
w
)
{
res
.
w
=
normalize
?
normalize
(
w
,
false
)
:
w
;
}
}
if
(
style
!==
null
)
{
...
...
@@ -2299,7 +2322,8 @@ export default function vueFactory(exports) {
if
(
throwInDev
)
{
throw
err
;
// throw err fixed by xxxxxx 避免 error 导致 App 端不可用(比如跳转时报错)
console
.
error
(
err
);
}
else
{
console
.
error
(
err
);
}
...
...
@@ -5172,6 +5196,7 @@ export default function vueFactory(exports) {
function
injectHook
(
type
,
hook
,
target
=
currentInstance
,
prepend
=
false
)
{
if
(
target
)
{
// fixed by xxxxxx
if
(
isRootHook
(
type
))
{
target
=
target
.
root
;
}
...
...
@@ -11139,16 +11164,42 @@ export default function vueFactory(exports) {
});
}
});
}
else
if
(
invoker
.
value
.
modifiers
)
{
}
else
{
if
(
invoker
.
value
.
modifiers
)
{
invoker
.
value
.
modifiers
.
forEach
(
m
=>
{
modifiers
.
add
(
m
);
});
}
initWxsEvent
(
invoker
,
instance
);
}
invoker
.
modifiers
=
[...
modifiers
];
return
invoker
;
}
function
initWxsEvent
(
invoker
,
instance
)
{
if
(
!
instance
)
{
return
;
}
var
{
$wxsModules
}
=
instance
;
if
(
!
$wxsModules
)
{
return
;
}
var
invokerSourceCode
=
invoker
.
value
.
toString
();
if
(
!
$wxsModules
.
find
(
module
=>
invokerSourceCode
.
indexOf
(
'
.
'
+
module
+
'
.
'
)
>
-
1
))
{
return
;
}
invoker
.
wxsEvent
=
invoker
.
value
();
}
var
forcePatchProps
=
{
AD
:
[
'
data
'
],
'
AD-DRAW
'
:
[
'
data
'
],
...
...
@@ -11176,7 +11227,7 @@ export default function vueFactory(exports) {
return
false
;
};
var
patchProp
=
(
el
,
key
,
prevValue
,
nextValue
,
parentComponent
)
=>
{
var
patchProp
=
(
el
,
key
,
prevValue
,
nextValue
,
isSVG
=
false
,
prevChildren
,
parentComponent
,
parentSuspense
,
unmountChildren
)
=>
{
switch
(
key
)
{
// special
case
'
class
'
:
...
...
@@ -11191,7 +11242,7 @@ export default function vueFactory(exports) {
if
(
isOn
(
key
))
{
// ignore v-model listeners
if
(
!
isModelListener
(
key
))
{
patchEvent
(
el
,
key
,
prevValue
,
nextValue
);
patchEvent
(
el
,
key
,
prevValue
,
nextValue
,
parentComponent
);
}
}
else
{
// 非基本类型
...
...
packages/uni-app-vue/lib/service.runtime.esm.js
浏览文件 @
9e2e54cd
...
...
@@ -1352,7 +1352,8 @@ function logError(err, type, contextVNode, throwInDev = true) {
}
// crash in dev by default so it's more noticeable
if
(
throwInDev
)
{
throw
err
;
// throw err fixed by xxxxxx 避免 error 导致 App 端不可用(比如跳转时报错)
console
.
error
(
err
);
}
else
{
console
.
error
(
err
);
...
...
@@ -4036,6 +4037,7 @@ function getInnerChild(vnode) {
function
injectHook
(
type
,
hook
,
target
=
currentInstance
,
prepend
=
false
)
{
if
(
target
)
{
// fixed by xxxxxx
if
(
isRootHook
(
type
))
{
target
=
target
.
root
;
}
...
...
@@ -9122,14 +9124,31 @@ function createInvoker(initialValue, instance) {
}
});
}
else
if
(
invoker
.
value
.
modifiers
)
{
else
{
if
(
invoker
.
value
.
modifiers
)
{
invoker
.
value
.
modifiers
.
forEach
((
m
)
=>
{
modifiers
.
add
(
m
);
});
}
initWxsEvent
(
invoker
,
instance
);
}
invoker
.
modifiers
=
[...
modifiers
];
return
invoker
;
}
function
initWxsEvent
(
invoker
,
instance
)
{
if
(
!
instance
)
{
return
;
}
const
{
$wxsModules
}
=
instance
;
if
(
!
$wxsModules
)
{
return
;
}
const
invokerSourceCode
=
invoker
.
value
.
toString
();
if
(
!
$wxsModules
.
find
(
module
=>
invokerSourceCode
.
indexOf
(
'
.
'
+
module
+
'
.
'
)
>
-
1
))
{
return
;
}
invoker
.
wxsEvent
=
invoker
.
value
();
}
const
forcePatchProps
=
{
AD
:
[
'
data
'
],
...
...
@@ -9160,7 +9179,7 @@ const forcePatchProp = (_, key) => {
}
return
false
;
};
const
patchProp
=
(
el
,
key
,
prevValue
,
nextValue
,
parentComponent
)
=>
{
const
patchProp
=
(
el
,
key
,
prevValue
,
nextValue
,
isSVG
=
false
,
prevChildren
,
parentComponent
,
parentSuspense
,
unmountChildren
)
=>
{
switch
(
key
)
{
// special
case
'
class
'
:
...
...
@@ -9173,7 +9192,7 @@ const patchProp = (el, key, prevValue, nextValue, parentComponent) => {
if
(
isOn
(
key
))
{
// ignore v-model listeners
if
(
!
isModelListener
(
key
))
{
patchEvent
(
el
,
key
,
prevValue
,
nextValue
);
patchEvent
(
el
,
key
,
prevValue
,
nextValue
,
parentComponent
);
}
}
else
{
...
...
packages/uni-cli-shared/src/vite/index.ts
浏览文件 @
9e2e54cd
...
...
@@ -15,6 +15,7 @@ interface UniVitePluginUniOptions {
isNativeTag
:
ParserOptions
[
'
isNativeTag
'
]
isCustomElement
:
ParserOptions
[
'
isCustomElement
'
]
directiveTransforms
?:
CompilerOptions
[
'
directiveTransforms
'
]
nodeTransforms
?:
CompilerOptions
[
'
nodeTransforms
'
]
}
transformEvent
?:
Record
<
string
,
string
>
copyOptions
?:
CopyOptions
|
(()
=>
CopyOptions
)
...
...
packages/uni-components/src/components/form/index.tsx
浏览文件 @
9e2e54cd
import
{
provide
,
ref
,
SetupContext
}
from
'
vue
'
import
{
provide
,
ref
}
from
'
vue
'
import
{
CustomEventTrigger
,
EmitEvent
,
...
...
packages/uni-h5/dist/uni-h5.cjs.js
浏览文件 @
9e2e54cd
...
...
@@ -6642,7 +6642,7 @@ function useContextInfo(_id) {
const
id
=
_id
||
vm
.
id
||
`context
${
index$a
++
}
`
;
return
`
${
type
}
.
${
id
}
`
;
}
function
applyOption
s
(
options
,
instance
,
publicThis
)
{
function
initHook
s
(
options
,
instance
,
publicThis
)
{
options
.
mpType
||
publicThis
.
$mpType
;
Object
.
keys
(
options
).
forEach
((
name
)
=>
{
if
(
name
.
indexOf
(
"
on
"
)
===
0
)
{
...
...
@@ -6653,6 +6653,9 @@ function applyOptions(options, instance, publicThis) {
}
});
}
function
applyOptions
(
options
,
instance
,
publicThis
)
{
initHooks
(
options
,
instance
,
publicThis
);
}
function
set
(
target
,
key
,
val
)
{
return
target
[
key
]
=
val
;
}
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
9e2e54cd
...
...
@@ -13221,7 +13221,7 @@ function useContextInfo(_id) {
function getContextInfo(el) {
return el.__uniContextInfo;
}
function
applyOption
s(options, instance2, publicThis) {
function
initHook
s(options, instance2, publicThis) {
options.mpType || publicThis.$mpType;
Object.keys(options).forEach((name) => {
if (name.indexOf("on") === 0) {
...
...
@@ -13232,6 +13232,9 @@ function applyOptions(options, instance2, publicThis) {
}
});
}
function applyOptions(options, instance2, publicThis) {
initHooks(options, instance2, publicThis);
}
function set(target, key, val) {
return target[key] = val;
}
...
...
packages/uni-shared/dist/uni-shared.cjs.js
浏览文件 @
9e2e54cd
...
...
@@ -598,9 +598,14 @@ class UniBaseNode extends UniNode {
addEventListener
(
type
,
listener
,
options
)
{
super
.
addEventListener
(
type
,
listener
,
options
);
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
if
(
listener
.
wxsEvent
)
{
this
.
pageNode
.
onAddWxsEvent
(
this
,
normalizeEventType
(
type
,
options
),
listener
.
wxsEvent
,
encodeModifier
(
listener
.
modifiers
||
[]));
}
else
{
this
.
pageNode
.
onAddEvent
(
this
,
normalizeEventType
(
type
,
options
),
encodeModifier
(
listener
.
modifiers
||
[]));
}
}
}
removeEventListener
(
type
,
callback
,
options
)
{
super
.
removeEventListener
(
type
,
callback
,
options
);
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
...
...
@@ -643,15 +648,29 @@ class UniBaseNode extends UniNode {
}
const
events
=
Object
.
keys
(
listeners
);
if
(
events
.
length
)
{
let
w
=
undefined
;
const
e
=
{};
events
.
forEach
((
name
)
=>
{
const
handlers
=
listeners
[
name
];
if
(
handlers
.
length
)
{
// 可能存在多个 handler 且不同 modifiers 吗?
e
[
name
]
=
encodeModifier
(
handlers
[
0
].
modifiers
||
[]);
const
{
wxsEvent
,
modifiers
}
=
handlers
[
0
];
const
modifier
=
encodeModifier
(
modifiers
||
[]);
if
(
!
wxsEvent
)
{
e
[
name
]
=
modifier
;
}
else
{
if
(
!
w
)
{
w
=
{};
}
w
[
name
]
=
[
normalize
?
normalize
(
wxsEvent
)
:
wxsEvent
,
modifier
];
}
}
});
res
.
e
=
normalize
?
normalize
(
e
,
false
)
:
e
;
if
(
w
)
{
res
.
w
=
normalize
?
normalize
(
w
,
false
)
:
w
;
}
}
if
(
style
!==
null
)
{
res
.
s
=
normalize
?
normalize
(
style
)
:
style
;
...
...
@@ -731,6 +750,7 @@ const ACTION_TYPE_REMOVE_ATTRIBUTE = 7;
const
ACTION_TYPE_ADD_EVENT
=
8
;
const
ACTION_TYPE_REMOVE_EVENT
=
9
;
const
ACTION_TYPE_SET_TEXT
=
10
;
const
ACTION_TYPE_ADD_WXS_EVENT
=
12
;
const
ACTION_TYPE_PAGE_SCROLL
=
15
;
const
ACTION_TYPE_EVENT
=
20
;
...
...
@@ -837,7 +857,9 @@ const UNI_SSR_GLOBAL_DATA = 'globalData';
const
SCHEME_RE
=
/^
([
a-z-
]
+:
)?\/\/
/i
;
const
DATA_RE
=
/^data:.*,.*/
;
const
WEB_INVOKE_APPSERVICE
=
'
WEB_INVOKE_APPSERVICE
'
;
const
WXS_PROTOCOL
=
'
wxs://
'
;
const
JSON_PROTOCOL
=
'
json://
'
;
const
WXS_METHOD_SYMBOL
=
Symbol
(
'
wxs.method
'
);
// lifecycle
// App and Page
const
ON_SHOW
=
'
onShow
'
;
...
...
@@ -954,6 +976,7 @@ function getEnvLocale() {
}
exports
.
ACTION_TYPE_ADD_EVENT
=
ACTION_TYPE_ADD_EVENT
;
exports
.
ACTION_TYPE_ADD_WXS_EVENT
=
ACTION_TYPE_ADD_WXS_EVENT
;
exports
.
ACTION_TYPE_CREATE
=
ACTION_TYPE_CREATE
;
exports
.
ACTION_TYPE_EVENT
=
ACTION_TYPE_EVENT
;
exports
.
ACTION_TYPE_INSERT
=
ACTION_TYPE_INSERT
;
...
...
@@ -1034,6 +1057,8 @@ exports.UniNode = UniNode;
exports
.
UniTextAreaElement
=
UniTextAreaElement
;
exports
.
UniTextNode
=
UniTextNode
;
exports
.
WEB_INVOKE_APPSERVICE
=
WEB_INVOKE_APPSERVICE
;
exports
.
WXS_METHOD_SYMBOL
=
WXS_METHOD_SYMBOL
;
exports
.
WXS_PROTOCOL
=
WXS_PROTOCOL
;
exports
.
addFont
=
addFont
;
exports
.
cache
=
cache
;
exports
.
cacheStringFunction
=
cacheStringFunction
;
...
...
packages/uni-shared/dist/uni-shared.d.ts
浏览文件 @
9e2e54cd
...
...
@@ -2,6 +2,8 @@ import { FontFaceDescriptors } from 'css-font-loading-module';
export
declare
const
ACTION_TYPE_ADD_EVENT
=
8
;
export
declare
const
ACTION_TYPE_ADD_WXS_EVENT
=
12
;
export
declare
const
ACTION_TYPE_CREATE
=
3
;
export
declare
const
ACTION_TYPE_EVENT
=
20
;
...
...
@@ -38,6 +40,20 @@ number
export
declare
function
addFont
(
family
:
string
,
source
:
string
,
desc
?:
FontFaceDescriptors
):
Promise
<
void
>
;
/**
* nodeId
* event
* wxsEvent
* flag
*/
export
declare
type
AddWxsEventAction
=
[
typeof
ACTION_TYPE_ADD_WXS_EVENT
,
number
,
string
|
number
,
string
|
number
,
number
];
export
declare
const
ATTR_CLASS
=
"
class
"
;
export
declare
const
ATTR_INNER_HTML
=
"
innerHTML
"
;
...
...
@@ -189,6 +205,7 @@ export declare interface IUniPageNode {
onInsertBefore
:
(
thisNode
:
UniNode
,
newChild
:
UniNode
,
refChild
:
UniNode
|
null
)
=>
UniNode
;
onRemoveChild
:
(
oldChild
:
UniNode
)
=>
UniNode
;
onAddEvent
:
(
thisNode
:
UniNode
,
name
:
string
,
flag
:
number
)
=>
void
;
onAddWxsEvent
:
(
thisNode
:
UniNode
,
name
:
string
,
wxsEvent
:
string
,
flag
:
number
)
=>
void
;
onRemoveEvent
:
(
thisNode
:
UniNode
,
name
:
string
)
=>
void
;
onSetAttribute
:
(
thisNode
:
UniNode
,
qualifiedName
:
string
,
value
:
unknown
)
=>
void
;
onRemoveAttribute
:
(
thisNode
:
UniNode
,
qualifiedName
:
string
)
=>
void
;
...
...
@@ -318,7 +335,7 @@ export declare interface PageNodeOptions {
*/
export
declare
type
PageScrollAction
=
[
typeof
ACTION_TYPE_PAGE_SCROLL
,
number
];
export
declare
type
PageUpdateAction
=
CreateAction
|
InsertAction
|
RemoveAction
|
AddEventAction
|
RemoveEventAction
|
SetAttributeAction
|
RemoveAttributeAction
|
SetTextAction
;
export
declare
type
PageUpdateAction
=
CreateAction
|
InsertAction
|
RemoveAction
|
AddEventAction
|
AddWxsEventAction
|
RemoveEventAction
|
SetAttributeAction
|
RemoveAttributeAction
|
SetTextAction
;
export
declare
function
parseEventName
(
name
:
string
):
[
string
,
EventListenerOptions
|
undefined
];
...
...
@@ -482,6 +499,7 @@ export declare class UniEvent {
export
declare
interface
UniEventListener
{
(
evt
:
UniEvent
):
void
;
modifiers
?:
string
[];
wxsEvent
?:
string
;
}
declare
interface
UniEventOptions
{
...
...
@@ -542,6 +560,10 @@ export declare interface UniNodeJSON {
* listeners
*/
e
:
Record
<
string
,
number
>
;
/**
* wxs listeners
*/
w
:
Record
<
string
,
[
string
,
number
]
>
;
/**
* style
*/
...
...
@@ -569,6 +591,10 @@ declare interface UniNodeJSONMinify {
* listeners
*/
e
:
DictArray
;
/**
* wxs listeners
*/
w
:
[
number
,
[
number
,
number
]][];
/**
* style
*/
...
...
@@ -594,4 +620,8 @@ export declare function updateElementStyle(element: HTMLElement, styles: Partial
export
declare
const
WEB_INVOKE_APPSERVICE
=
"
WEB_INVOKE_APPSERVICE
"
;
export
declare
const
WXS_METHOD_SYMBOL
:
unique
symbol
;
export
declare
const
WXS_PROTOCOL
=
"
wxs://
"
;
export
{
}
packages/uni-shared/dist/uni-shared.es.js
浏览文件 @
9e2e54cd
...
...
@@ -594,9 +594,14 @@ class UniBaseNode extends UniNode {
addEventListener
(
type
,
listener
,
options
)
{
super
.
addEventListener
(
type
,
listener
,
options
);
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
if
(
listener
.
wxsEvent
)
{
this
.
pageNode
.
onAddWxsEvent
(
this
,
normalizeEventType
(
type
,
options
),
listener
.
wxsEvent
,
encodeModifier
(
listener
.
modifiers
||
[]));
}
else
{
this
.
pageNode
.
onAddEvent
(
this
,
normalizeEventType
(
type
,
options
),
encodeModifier
(
listener
.
modifiers
||
[]));
}
}
}
removeEventListener
(
type
,
callback
,
options
)
{
super
.
removeEventListener
(
type
,
callback
,
options
);
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
...
...
@@ -639,15 +644,29 @@ class UniBaseNode extends UniNode {
}
const
events
=
Object
.
keys
(
listeners
);
if
(
events
.
length
)
{
let
w
=
undefined
;
const
e
=
{};
events
.
forEach
((
name
)
=>
{
const
handlers
=
listeners
[
name
];
if
(
handlers
.
length
)
{
// 可能存在多个 handler 且不同 modifiers 吗?
e
[
name
]
=
encodeModifier
(
handlers
[
0
].
modifiers
||
[]);
const
{
wxsEvent
,
modifiers
}
=
handlers
[
0
];
const
modifier
=
encodeModifier
(
modifiers
||
[]);
if
(
!
wxsEvent
)
{
e
[
name
]
=
modifier
;
}
else
{
if
(
!
w
)
{
w
=
{};
}
w
[
name
]
=
[
normalize
?
normalize
(
wxsEvent
)
:
wxsEvent
,
modifier
];
}
}
});
res
.
e
=
normalize
?
normalize
(
e
,
false
)
:
e
;
if
(
w
)
{
res
.
w
=
normalize
?
normalize
(
w
,
false
)
:
w
;
}
}
if
(
style
!==
null
)
{
res
.
s
=
normalize
?
normalize
(
style
)
:
style
;
...
...
@@ -727,6 +746,7 @@ const ACTION_TYPE_REMOVE_ATTRIBUTE = 7;
const
ACTION_TYPE_ADD_EVENT
=
8
;
const
ACTION_TYPE_REMOVE_EVENT
=
9
;
const
ACTION_TYPE_SET_TEXT
=
10
;
const
ACTION_TYPE_ADD_WXS_EVENT
=
12
;
const
ACTION_TYPE_PAGE_SCROLL
=
15
;
const
ACTION_TYPE_EVENT
=
20
;
...
...
@@ -833,7 +853,9 @@ const UNI_SSR_GLOBAL_DATA = 'globalData';
const
SCHEME_RE
=
/^
([
a-z-
]
+:
)?\/\/
/i
;
const
DATA_RE
=
/^data:.*,.*/
;
const
WEB_INVOKE_APPSERVICE
=
'
WEB_INVOKE_APPSERVICE
'
;
const
WXS_PROTOCOL
=
'
wxs://
'
;
const
JSON_PROTOCOL
=
'
json://
'
;
const
WXS_METHOD_SYMBOL
=
Symbol
(
'
wxs.method
'
);
// lifecycle
// App and Page
const
ON_SHOW
=
'
onShow
'
;
...
...
@@ -949,4 +971,4 @@ function getEnvLocale() {
return
(
lang
&&
lang
.
replace
(
/
[
.:
]
.*/
,
''
))
||
'
en
'
;
}
export
{
ACTION_TYPE_ADD_EVENT
,
ACTION_TYPE_
CREATE
,
ACTION_TYPE_EVENT
,
ACTION_TYPE_INSERT
,
ACTION_TYPE_PAGE_CREATE
,
ACTION_TYPE_PAGE_CREATED
,
ACTION_TYPE_PAGE_SCROLL
,
ACTION_TYPE_REMOVE
,
ACTION_TYPE_REMOVE_ATTRIBUTE
,
ACTION_TYPE_REMOVE_EVENT
,
ACTION_TYPE_SET_ATTRIBUTE
,
ACTION_TYPE_SET_TEXT
,
ATTR_CLASS
,
ATTR_INNER_HTML
,
ATTR_STYLE
,
ATTR_TEXT_CONTENT
,
ATTR_V_SHOW
,
BACKGROUND_COLOR
,
BUILT_IN_TAGS
,
COMPONENT_NAME_PREFIX
,
COMPONENT_PREFIX
,
COMPONENT_SELECTOR_PREFIX
,
DATA_RE
,
EventChannel
,
EventModifierFlags
,
JSON_PROTOCOL
,
NAVBAR_HEIGHT
,
NODE_TYPE_COMMENT
,
NODE_TYPE_ELEMENT
,
NODE_TYPE_PAGE
,
NODE_TYPE_TEXT
,
ON_ADD_TO_FAVORITES
,
ON_APP_ENTER_BACKGROUND
,
ON_APP_ENTER_FOREGROUND
,
ON_BACK_PRESS
,
ON_ERROR
,
ON_HIDE
,
ON_KEYBOARD_HEIGHT_CHANGE
,
ON_LAUNCH
,
ON_LOAD
,
ON_NAVIGATION_BAR_BUTTON_TAP
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
,
ON_PAGE_NOT_FOUND
,
ON_PAGE_SCROLL
,
ON_PULL_DOWN_REFRESH
,
ON_REACH_BOTTOM
,
ON_REACH_BOTTOM_DISTANCE
,
ON_READY
,
ON_RESIZE
,
ON_SHARE_APP_MESSAGE
,
ON_SHARE_TIMELINE
,
ON_SHOW
,
ON_TAB_ITEM_TAP
,
ON_THEME_CHANGE
,
ON_UNHANDLE_REJECTION
,
ON_UNLOAD
,
ON_WEB_INVOKE_APP_SERVICE
,
PLUS_RE
,
PRIMARY_COLOR
,
RESPONSIVE_MIN_WIDTH
,
SCHEME_RE
,
SELECTED_COLOR
,
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
,
cache
,
cacheStringFunction
,
callOptions
,
createRpx2Unit
,
createUniEvent
,
debounce
,
decode
,
decodedQuery
,
defaultRpx2Unit
,
formatDateTime
,
formatLog
,
getCustomDataset
,
getEnvLocale
,
getLen
,
initCustomDataset
,
invokeArrayFns
,
isBuiltInComponent
,
isCustomElement
,
isNativeTag
,
isRootHook
,
isServiceCustomElement
,
isServiceNativeTag
,
normalizeDataset
,
normalizeEventType
,
normalizeTarget
,
once
,
parseEventName
,
parseQuery
,
parseUrl
,
passive
,
plusReady
,
removeLeadingSlash
,
sanitise
,
scrollTo
,
stringifyQuery
,
updateElementStyle
};
export
{
ACTION_TYPE_ADD_EVENT
,
ACTION_TYPE_
ADD_WXS_EVENT
,
ACTION_TYPE_CREATE
,
ACTION_TYPE_EVENT
,
ACTION_TYPE_INSERT
,
ACTION_TYPE_PAGE_CREATE
,
ACTION_TYPE_PAGE_CREATED
,
ACTION_TYPE_PAGE_SCROLL
,
ACTION_TYPE_REMOVE
,
ACTION_TYPE_REMOVE_ATTRIBUTE
,
ACTION_TYPE_REMOVE_EVENT
,
ACTION_TYPE_SET_ATTRIBUTE
,
ACTION_TYPE_SET_TEXT
,
ATTR_CLASS
,
ATTR_INNER_HTML
,
ATTR_STYLE
,
ATTR_TEXT_CONTENT
,
ATTR_V_SHOW
,
BACKGROUND_COLOR
,
BUILT_IN_TAGS
,
COMPONENT_NAME_PREFIX
,
COMPONENT_PREFIX
,
COMPONENT_SELECTOR_PREFIX
,
DATA_RE
,
EventChannel
,
EventModifierFlags
,
JSON_PROTOCOL
,
NAVBAR_HEIGHT
,
NODE_TYPE_COMMENT
,
NODE_TYPE_ELEMENT
,
NODE_TYPE_PAGE
,
NODE_TYPE_TEXT
,
ON_ADD_TO_FAVORITES
,
ON_APP_ENTER_BACKGROUND
,
ON_APP_ENTER_FOREGROUND
,
ON_BACK_PRESS
,
ON_ERROR
,
ON_HIDE
,
ON_KEYBOARD_HEIGHT_CHANGE
,
ON_LAUNCH
,
ON_LOAD
,
ON_NAVIGATION_BAR_BUTTON_TAP
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
,
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
,
ON_PAGE_NOT_FOUND
,
ON_PAGE_SCROLL
,
ON_PULL_DOWN_REFRESH
,
ON_REACH_BOTTOM
,
ON_REACH_BOTTOM_DISTANCE
,
ON_READY
,
ON_RESIZE
,
ON_SHARE_APP_MESSAGE
,
ON_SHARE_TIMELINE
,
ON_SHOW
,
ON_TAB_ITEM_TAP
,
ON_THEME_CHANGE
,
ON_UNHANDLE_REJECTION
,
ON_UNLOAD
,
ON_WEB_INVOKE_APP_SERVICE
,
PLUS_RE
,
PRIMARY_COLOR
,
RESPONSIVE_MIN_WIDTH
,
SCHEME_RE
,
SELECTED_COLOR
,
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
,
WXS_METHOD_SYMBOL
,
WXS_PROTOCOL
,
addFont
,
cache
,
cacheStringFunction
,
callOptions
,
createRpx2Unit
,
createUniEvent
,
debounce
,
decode
,
decodedQuery
,
defaultRpx2Unit
,
formatDateTime
,
formatLog
,
getCustomDataset
,
getEnvLocale
,
getLen
,
initCustomDataset
,
invokeArrayFns
,
isBuiltInComponent
,
isCustomElement
,
isNativeTag
,
isRootHook
,
isServiceCustomElement
,
isServiceNativeTag
,
normalizeDataset
,
normalizeEventType
,
normalizeTarget
,
once
,
parseEventName
,
parseQuery
,
parseUrl
,
passive
,
plusReady
,
removeLeadingSlash
,
sanitise
,
scrollTo
,
stringifyQuery
,
updateElementStyle
};
packages/uni-shared/src/constants.ts
浏览文件 @
9e2e54cd
...
...
@@ -20,8 +20,11 @@ export const DATA_RE = /^data:.*,.*/
export
const
WEB_INVOKE_APPSERVICE
=
'
WEB_INVOKE_APPSERVICE
'
export
const
WXS_PROTOCOL
=
'
wxs://
'
export
const
JSON_PROTOCOL
=
'
json://
'
export
const
WXS_METHOD_SYMBOL
=
Symbol
(
'
wxs.method
'
)
// lifecycle
// App and Page
...
...
packages/uni-shared/src/vdom/Action.ts
浏览文件 @
9e2e54cd
...
...
@@ -11,6 +11,7 @@ export const ACTION_TYPE_ADD_EVENT = 8
export
const
ACTION_TYPE_REMOVE_EVENT
=
9
export
const
ACTION_TYPE_SET_TEXT
=
10
export
const
ACTION_TYPE_ADD_WXS_EVENT
=
12
export
const
ACTION_TYPE_PAGE_SCROLL
=
15
export
const
ACTION_TYPE_EVENT
=
20
...
...
@@ -77,6 +78,20 @@ export type AddEventAction = [
number
]
/**
* nodeId
* event
* wxsEvent
* flag
*/
export
type
AddWxsEventAction
=
[
typeof
ACTION_TYPE_ADD_WXS_EVENT
,
number
,
string
|
number
,
string
|
number
,
number
]
/**
* nodeId
* event
...
...
@@ -129,6 +144,7 @@ export type PageUpdateAction =
|
InsertAction
|
RemoveAction
|
AddEventAction
|
AddWxsEventAction
|
RemoveEventAction
|
SetAttributeAction
|
RemoveAttributeAction
...
...
packages/uni-shared/src/vdom/Event.ts
浏览文件 @
9e2e54cd
...
...
@@ -23,6 +23,7 @@ export function normalizeEventType(
export
interface
UniEventListener
{
(
evt
:
UniEvent
):
void
modifiers
?:
string
[]
wxsEvent
?:
string
// 'wxs://['animate.start']'
}
interface
UniEventOptions
{
...
...
packages/uni-shared/src/vdom/Node.ts
浏览文件 @
9e2e54cd
...
...
@@ -53,6 +53,12 @@ export interface IUniPageNode {
)
=>
UniNode
onRemoveChild
:
(
oldChild
:
UniNode
)
=>
UniNode
onAddEvent
:
(
thisNode
:
UniNode
,
name
:
string
,
flag
:
number
)
=>
void
onAddWxsEvent
:
(
thisNode
:
UniNode
,
name
:
string
,
wxsEvent
:
string
,
flag
:
number
)
=>
void
onRemoveEvent
:
(
thisNode
:
UniNode
,
name
:
string
)
=>
void
onSetAttribute
:
(
thisNode
:
UniNode
,
...
...
@@ -216,6 +222,10 @@ export interface UniNodeJSONMinify {
* listeners
*/
e
:
DictArray
/**
* wxs listeners
*/
w
:
[
number
,
[
number
,
number
]][]
/**
* style
*/
...
...
@@ -242,6 +252,10 @@ export interface UniNodeJSON {
* listeners
*/
e
:
Record
<
string
,
number
>
/**
* wxs listeners
*/
w
:
Record
<
string
,
[
string
,
number
]
>
/**
* style
*/
...
...
@@ -295,6 +309,14 @@ export class UniBaseNode extends UniNode {
)
{
super
.
addEventListener
(
type
,
listener
,
options
)
if
(
this
.
pageNode
&&
!
this
.
pageNode
.
isUnmounted
)
{
if
(
listener
.
wxsEvent
)
{
this
.
pageNode
.
onAddWxsEvent
(
this
,
normalizeEventType
(
type
,
options
),
listener
.
wxsEvent
,
encodeModifier
(
listener
.
modifiers
||
[])
)
}
else
{
this
.
pageNode
.
onAddEvent
(
this
,
normalizeEventType
(
type
,
options
),
...
...
@@ -302,6 +324,7 @@ export class UniBaseNode extends UniNode {
)
}
}
}
removeEventListener
(
type
:
string
,
...
...
@@ -358,15 +381,28 @@ export class UniBaseNode extends UniNode {
}
const
events
=
Object
.
keys
(
listeners
)
if
(
events
.
length
)
{
let
w
:
Record
<
string
,
[
string
|
number
,
number
]
>
|
undefined
=
undefined
const
e
:
Record
<
string
,
number
>
=
{}
events
.
forEach
((
name
)
=>
{
const
handlers
=
listeners
[
name
]
if
(
handlers
.
length
)
{
// 可能存在多个 handler 且不同 modifiers 吗?
e
[
name
]
=
encodeModifier
(
handlers
[
0
].
modifiers
||
[])
const
{
wxsEvent
,
modifiers
}
=
handlers
[
0
]
const
modifier
=
encodeModifier
(
modifiers
||
[])
if
(
!
wxsEvent
)
{
e
[
name
]
=
modifier
}
else
{
if
(
!
w
)
{
w
=
{}
}
w
[
name
]
=
[
normalize
?
normalize
(
wxsEvent
!
)
:
wxsEvent
,
modifier
]
}
}
})
res
.
e
=
normalize
?
normalize
(
e
,
false
)
:
e
if
(
w
)
{
res
.
w
=
normalize
?
normalize
(
w
,
false
)
:
w
}
}
if
(
style
!==
null
)
{
res
.
s
=
normalize
?
normalize
(
style
)
:
style
...
...
packages/uni-vue/src/componentOptions.ts
→
packages/uni-vue/src/componentOptions
/hooks
.ts
浏览文件 @
9e2e54cd
...
...
@@ -10,7 +10,7 @@ import {
// @ts-ignore
import
{
injectHook
}
from
'
vue
'
export
function
applyOption
s
(
export
function
initHook
s
(
options
:
ComponentOptions
,
instance
:
ComponentInternalInstance
,
publicThis
:
ComponentPublicInstance
...
...
packages/uni-vue/src/componentOptions/index.ts
0 → 100644
浏览文件 @
9e2e54cd
import
{
ComponentOptions
,
ComponentInternalInstance
,
ComponentPublicInstance
,
}
from
'
vue
'
// @ts-ignore
import
{
injectHook
}
from
'
vue
'
import
{
initHooks
}
from
'
./hooks
'
import
{
initRenderjs
}
from
'
./renderjs
'
import
{
initWxs
}
from
'
./wxs
'
export
function
applyOptions
(
options
:
ComponentOptions
,
instance
:
ComponentInternalInstance
,
publicThis
:
ComponentPublicInstance
)
{
if
(
__PLATFORM__
===
'
app
'
)
{
initWxs
(
options
,
instance
)
initRenderjs
(
options
,
instance
)
}
initHooks
(
options
,
instance
,
publicThis
)
}
packages/uni-vue/src/componentOptions/renderjs.ts
0 → 100644
浏览文件 @
9e2e54cd
import
{
WXS_PROTOCOL
}
from
'
@dcloudio/uni-shared
'
import
{
isArray
}
from
'
@vue/shared
'
import
{
ComponentInternalInstance
,
ComponentOptions
}
from
'
vue
'
export
function
initRenderjs
(
{
$renderjs
}:
ComponentOptions
,
instance
:
ComponentInternalInstance
)
{
initModules
(
instance
,
$renderjs
)
}
export
function
initModules
(
instance
:
ComponentInternalInstance
,
modules
:
string
[]
)
{
if
(
!
isArray
(
modules
))
{
return
}
const
ctx
=
(
instance
as
any
).
ctx
const
$wxsModules
=
(
instance
.
$wxsModules
||
(
instance
.
$wxsModules
=
[]))
as
unknown
as
string
[]
modules
.
forEach
((
module
)
=>
{
ctx
[
module
]
=
proxyModule
(
module
)
$wxsModules
.
push
(
module
)
})
}
const
renderjsModule
=
{}
function
proxyModule
(
module
:
string
)
{
return
new
Proxy
(
renderjsModule
,
{
get
(
_
,
p
)
{
return
createModuleFunction
(
module
,
p
as
string
)
},
})
}
function
renderjsFn
()
{}
function
createModuleFunction
(
module
:
string
,
name
:
string
):
Function
{
const
toJSON
=
()
=>
WXS_PROTOCOL
+
JSON
.
stringify
([
module
+
'
.
'
+
name
])
return
new
Proxy
(
renderjsFn
,
{
get
(
_
,
p
)
{
if
(
p
===
'
toJSON
'
)
{
return
toJSON
}
return
createModuleFunction
(
module
+
'
.
'
+
name
,
p
as
string
)
},
apply
(
_target
,
_thisArg
,
args
)
{
return
WXS_PROTOCOL
+
JSON
.
stringify
([
module
+
'
.
'
+
name
,
...
args
])
},
})
}
packages/uni-vue/src/componentOptions/wxs.ts
0 → 100644
浏览文件 @
9e2e54cd
import
{
ComponentInternalInstance
,
ComponentOptions
}
from
'
vue
'
import
{
initModules
}
from
'
./renderjs
'
export
function
initWxs
(
{
$wxs
}:
ComponentOptions
,
instance
:
ComponentInternalInstance
)
{
initModules
(
instance
,
$wxs
)
}
packages/vite-plugin-uni/package.json
浏览文件 @
9e2e54cd
...
...
@@ -40,7 +40,7 @@
"@types/sass"
:
"^1.16.0"
},
"uni-app"
:
{
"compilerVersion"
:
"3.2.
0
"
"compilerVersion"
:
"3.2.
1
"
},
"gitHead"
:
"4dd0e035b52584ff028ee3028c46adc555be0529"
}
packages/vite-plugin-uni/src/vue/options.ts
浏览文件 @
9e2e54cd
...
...
@@ -66,7 +66,12 @@ export function initPluginVueOptions(
templateOptions
.
compilerOptions
||
(
templateOptions
.
compilerOptions
=
{})
const
{
compilerOptions
:
{
isNativeTag
,
isCustomElement
,
directiveTransforms
},
compilerOptions
:
{
isNativeTag
,
isCustomElement
,
nodeTransforms
,
directiveTransforms
,
},
}
=
uniPluginOptions
compilerOptions
.
isNativeTag
=
isNativeTag
compilerOptions
.
isCustomElement
=
isCustomElement
...
...
@@ -80,6 +85,9 @@ export function initPluginVueOptions(
if
(
!
compilerOptions
.
nodeTransforms
)
{
compilerOptions
.
nodeTransforms
=
[]
}
if
(
nodeTransforms
)
{
compilerOptions
.
nodeTransforms
.
push
(...
nodeTransforms
)
}
// const compatConfig = parseCompatConfigOnce(options.inputDir)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录