@tarojs/runtime 3.4.0-beta.2 → 3.4.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dsl/common.d.ts +1 -22
- package/dist/dsl/instance.d.ts +10 -8
- package/dist/runtime.esm.js +70 -45
- package/dist/runtime.esm.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/package.json +4 -4
package/dist/dsl/common.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { eventHandler } from '../dom/event';
|
|
3
2
|
import type { PageConfig } from '@tarojs/taro';
|
|
4
3
|
import type { Instance, PageInstance, PageProps } from './instance';
|
|
5
4
|
export declare function injectPageInstance(inst: Instance<PageProps>, id: string): void;
|
|
@@ -13,24 +12,4 @@ export declare function getOnShowEventKey(path: string): string;
|
|
|
13
12
|
export declare function getOnHideEventKey(path: string): string;
|
|
14
13
|
export declare function createPageConfig(component: any, pageName?: string, data?: Record<string, unknown>, pageConfig?: PageConfig): PageInstance;
|
|
15
14
|
export declare function createComponentConfig(component: React.ComponentClass, componentName?: string, data?: Record<string, unknown>): any;
|
|
16
|
-
export declare function createRecursiveComponentConfig(componentName?: string):
|
|
17
|
-
properties: {
|
|
18
|
-
i: {
|
|
19
|
-
type: ObjectConstructor;
|
|
20
|
-
value: {
|
|
21
|
-
nn: string;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
l: {
|
|
25
|
-
type: StringConstructor;
|
|
26
|
-
value: string;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
options: {
|
|
30
|
-
addGlobalClass: boolean;
|
|
31
|
-
virtualHost: boolean;
|
|
32
|
-
};
|
|
33
|
-
methods: {
|
|
34
|
-
eh: typeof eventHandler;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
15
|
+
export declare function createRecursiveComponentConfig(componentName?: string): any;
|
package/dist/dsl/instance.d.ts
CHANGED
|
@@ -21,13 +21,13 @@ interface VueInternal {
|
|
|
21
21
|
export interface PageProps {
|
|
22
22
|
tid?: string;
|
|
23
23
|
}
|
|
24
|
-
export interface ReactPageComponent<T = PageProps> extends ComponentClass<T>,
|
|
24
|
+
export interface ReactPageComponent<T = PageProps> extends ComponentClass<T>, PageInstance {
|
|
25
25
|
}
|
|
26
|
-
export interface ReactPageInstance<T = PageProps> extends Component<T>,
|
|
26
|
+
export interface ReactPageInstance<T = PageProps> extends Component<T>, PageInstance {
|
|
27
27
|
componentDidShow?(): void;
|
|
28
28
|
componentDidHide?(): void;
|
|
29
29
|
}
|
|
30
|
-
export interface ReactAppInstance<T = AppInstance> extends Component<T>,
|
|
30
|
+
export interface ReactAppInstance<T = AppInstance> extends Component<T>, AppInstance {
|
|
31
31
|
}
|
|
32
32
|
export interface PageLifeCycle extends Show {
|
|
33
33
|
onPullDownRefresh?(): void;
|
|
@@ -63,15 +63,17 @@ export interface PageInstance extends PageLifeCycle {
|
|
|
63
63
|
options?: Record<string, unknown>;
|
|
64
64
|
}
|
|
65
65
|
interface Show {
|
|
66
|
-
componentDidShow?(
|
|
67
|
-
componentDidHide?(
|
|
68
|
-
onShow?(
|
|
69
|
-
onHide?(
|
|
66
|
+
componentDidShow?(): void;
|
|
67
|
+
componentDidHide?(): void;
|
|
68
|
+
onShow?(): void;
|
|
69
|
+
onHide?(): void;
|
|
70
70
|
}
|
|
71
71
|
export interface AppInstance extends Show {
|
|
72
|
-
onLaunch?(options?: string): void;
|
|
72
|
+
onLaunch?(options?: Record<string, unknown>): void;
|
|
73
73
|
mount?(component: React.ComponentClass | ComponentOptions<VueCtor> | Vue3Component, id: string, cb: (...args: any[]) => void): void;
|
|
74
74
|
mount?(component: React.ComponentClass | ComponentOptions<VueCtor> | Vue3Component, id: string, cb: () => void): void;
|
|
75
|
+
componentDidShow?(options?: Record<string, unknown>): void;
|
|
76
|
+
onShow?(options?: Record<string, unknown>): void;
|
|
75
77
|
unmount?(id: string): void;
|
|
76
78
|
unmount?(id: string, cb: () => void): void;
|
|
77
79
|
onPageNotFound?(res: any): void;
|
package/dist/runtime.esm.js
CHANGED
|
@@ -1260,7 +1260,8 @@ function shortcutAttr(key) {
|
|
|
1260
1260
|
default:
|
|
1261
1261
|
return key;
|
|
1262
1262
|
}
|
|
1263
|
-
}
|
|
1263
|
+
}
|
|
1264
|
+
const customWrapperCache = new Map();
|
|
1264
1265
|
|
|
1265
1266
|
const SID_TARO_ELEMENT = '0';
|
|
1266
1267
|
const SID_TARO_ELEMENT_FACTORY = '1';
|
|
@@ -1358,6 +1359,14 @@ let TaroEventTarget = class TaroEventTarget {
|
|
|
1358
1359
|
}
|
|
1359
1360
|
addEventListener(type, handler, options) {
|
|
1360
1361
|
var _a, _b;
|
|
1362
|
+
// 某些框架,如 PReact 有委托的机制,handler 始终是同一个函数
|
|
1363
|
+
// 这会导致多层停止冒泡失败:view -> view(handler.stop = false) -> view(handler.stop = true)
|
|
1364
|
+
// 这样解决:view -> view(handlerA.stop = false) -> view(handlerB.stop = false)
|
|
1365
|
+
// 因此每次绑定事件都新建一个函数,如果带来了性能问题,可以把这段逻辑抽取到 PReact 插件中。
|
|
1366
|
+
const oldHandler = handler;
|
|
1367
|
+
handler = function () {
|
|
1368
|
+
oldHandler.apply(this, arguments); // this 指向 Element
|
|
1369
|
+
};
|
|
1361
1370
|
(_b = (_a = this.hooks).onAddEvent) === null || _b === void 0 ? void 0 : _b.call(_a, type, handler, options, this);
|
|
1362
1371
|
if (type === 'regionchange') {
|
|
1363
1372
|
// map 组件的 regionchange 事件非常特殊,详情:https://github.com/NervJS/taro/issues/5766
|
|
@@ -2605,24 +2614,33 @@ class Performance {
|
|
|
2605
2614
|
}
|
|
2606
2615
|
const perf = new Performance();
|
|
2607
2616
|
|
|
2608
|
-
function findCustomWrapper(
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
let
|
|
2612
|
-
|
|
2613
|
-
|
|
2617
|
+
function findCustomWrapper(root, dataPathArr) {
|
|
2618
|
+
// ['root', 'cn', '[0]'] remove 'root' => ['cn', '[0]']
|
|
2619
|
+
const list = dataPathArr.slice(1);
|
|
2620
|
+
let currentData = root;
|
|
2621
|
+
let customWrapper;
|
|
2622
|
+
let splitedPath = '';
|
|
2623
|
+
list.some((item, i) => {
|
|
2624
|
+
const key = item
|
|
2625
|
+
// '[0]' => '0'
|
|
2626
|
+
.replace(/^\[(.+)\]$/, '$1')
|
|
2627
|
+
// 'cn' => 'childNodes'
|
|
2628
|
+
.replace(/\bcn\b/g, 'childNodes');
|
|
2614
2629
|
currentData = currentData[key];
|
|
2615
2630
|
if (isUndefined(currentData))
|
|
2616
2631
|
return true;
|
|
2617
|
-
if (currentData.
|
|
2618
|
-
|
|
2619
|
-
|
|
2632
|
+
if (currentData.nodeName === CUSTOM_WRAPPER) {
|
|
2633
|
+
const res = customWrapperCache.get(currentData.sid);
|
|
2634
|
+
if (res) {
|
|
2635
|
+
customWrapper = res;
|
|
2636
|
+
splitedPath = dataPathArr.slice(i + 2).join('.');
|
|
2637
|
+
}
|
|
2620
2638
|
}
|
|
2621
2639
|
});
|
|
2622
|
-
if (
|
|
2640
|
+
if (customWrapper) {
|
|
2623
2641
|
return {
|
|
2624
|
-
|
|
2625
|
-
|
|
2642
|
+
customWrapper,
|
|
2643
|
+
splitedPath
|
|
2626
2644
|
};
|
|
2627
2645
|
}
|
|
2628
2646
|
}
|
|
@@ -2690,17 +2708,12 @@ let TaroRootElement = class TaroRootElement extends TaroElement {
|
|
|
2690
2708
|
// 更新渲染,区分 CustomWrapper 与页面级别的 setData
|
|
2691
2709
|
for (const p in data) {
|
|
2692
2710
|
const dataPathArr = p.split('.');
|
|
2693
|
-
const found = findCustomWrapper(
|
|
2711
|
+
const found = findCustomWrapper(this, dataPathArr);
|
|
2694
2712
|
if (found) {
|
|
2695
2713
|
// 此项数据使用 CustomWrapper 去更新
|
|
2696
|
-
const {
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
if (customWrapper) {
|
|
2700
|
-
const splitedPath = dataPathArr.slice(index + 1).join('.');
|
|
2701
|
-
// 合并同一个 customWrapper 的相关更新到一次 setData 中
|
|
2702
|
-
customWrapperMap.set(customWrapper, Object.assign(Object.assign({}, (customWrapperMap.get(customWrapper) || {})), { [`i.${splitedPath}`]: data[p] }));
|
|
2703
|
-
}
|
|
2714
|
+
const { customWrapper, splitedPath } = found;
|
|
2715
|
+
// 合并同一个 customWrapper 的相关更新到一次 setData 中
|
|
2716
|
+
customWrapperMap.set(customWrapper, Object.assign(Object.assign({}, (customWrapperMap.get(customWrapper) || {})), { [`i.${splitedPath}`]: data[p] }));
|
|
2704
2717
|
}
|
|
2705
2718
|
else {
|
|
2706
2719
|
// 此项数据使用页面去更新
|
|
@@ -4292,11 +4305,11 @@ if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
|
4292
4305
|
if (!(DATE in window$1)) {
|
|
4293
4306
|
window$1.Date = Date;
|
|
4294
4307
|
}
|
|
4295
|
-
window$1.setTimeout = function (
|
|
4296
|
-
setTimeout(
|
|
4308
|
+
window$1.setTimeout = function (...args) {
|
|
4309
|
+
return setTimeout(...args);
|
|
4297
4310
|
};
|
|
4298
|
-
window$1.clearTimeout = function (
|
|
4299
|
-
clearTimeout(
|
|
4311
|
+
window$1.clearTimeout = function (...args) {
|
|
4312
|
+
return clearTimeout(...args);
|
|
4300
4313
|
};
|
|
4301
4314
|
document$1.defaultView = window$1;
|
|
4302
4315
|
}
|
|
@@ -4433,11 +4446,8 @@ function stringify(obj) {
|
|
|
4433
4446
|
return path === '' ? path : '?' + path;
|
|
4434
4447
|
}
|
|
4435
4448
|
function getPath(id, options) {
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
path = id + stringify(options);
|
|
4439
|
-
}
|
|
4440
|
-
return path;
|
|
4449
|
+
const idx = id.indexOf('?');
|
|
4450
|
+
return `${idx > -1 ? id.substring(0, idx) : id}${stringify(process.env.TARO_ENV === 'h5' ? { stamp: (options === null || options === void 0 ? void 0 : options.stamp) || '' } : options)}`;
|
|
4441
4451
|
}
|
|
4442
4452
|
function getOnReadyEventKey(path) {
|
|
4443
4453
|
return path + '.' + ON_READY;
|
|
@@ -4479,6 +4489,9 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4479
4489
|
// this.$taroPath 是页面唯一标识,不可变,因此页面参数 options 也不可变
|
|
4480
4490
|
this.$taroPath = getPath(id, options);
|
|
4481
4491
|
const $taroPath = this.$taroPath;
|
|
4492
|
+
if (process.env.TARO_ENV === 'h5') {
|
|
4493
|
+
config.path = this.$taroPath;
|
|
4494
|
+
}
|
|
4482
4495
|
// this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
|
|
4483
4496
|
if (this.$taroParams == null) {
|
|
4484
4497
|
this.$taroParams = Object.assign({}, options);
|
|
@@ -4529,13 +4542,13 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4529
4542
|
raf(() => eventCenter.trigger(getOnReadyEventKey(id)));
|
|
4530
4543
|
this.onReady.called = true;
|
|
4531
4544
|
},
|
|
4532
|
-
[ONSHOW]() {
|
|
4545
|
+
[ONSHOW](options = {}) {
|
|
4533
4546
|
hasLoaded.then(() => {
|
|
4534
4547
|
// 设置 Current 的 page 和 router
|
|
4535
4548
|
Current.page = this;
|
|
4536
4549
|
setCurrentRouter(this);
|
|
4537
4550
|
// 触发生命周期
|
|
4538
|
-
safeExecute(this.$taroPath, ON_SHOW);
|
|
4551
|
+
safeExecute(this.$taroPath, ON_SHOW, options);
|
|
4539
4552
|
// 通过事件触发子组件的生命周期
|
|
4540
4553
|
raf(() => eventCenter.trigger(getOnShowEventKey(id)));
|
|
4541
4554
|
});
|
|
@@ -4584,9 +4597,6 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4584
4597
|
if (!isUndefined(data)) {
|
|
4585
4598
|
config.data = data;
|
|
4586
4599
|
}
|
|
4587
|
-
if (process.env.TARO_ENV === 'h5') {
|
|
4588
|
-
config.path = id;
|
|
4589
|
-
}
|
|
4590
4600
|
(_c = hooks.modifyPageObject) === null || _c === void 0 ? void 0 : _c.call(hooks, config);
|
|
4591
4601
|
return config;
|
|
4592
4602
|
}
|
|
@@ -4631,8 +4641,26 @@ function createComponentConfig(component, componentName, data) {
|
|
|
4631
4641
|
return config;
|
|
4632
4642
|
}
|
|
4633
4643
|
function createRecursiveComponentConfig(componentName) {
|
|
4634
|
-
|
|
4635
|
-
|
|
4644
|
+
const isCustomWrapper = componentName === CUSTOM_WRAPPER;
|
|
4645
|
+
const lifeCycles = isCustomWrapper
|
|
4646
|
+
? {
|
|
4647
|
+
attached() {
|
|
4648
|
+
var _a;
|
|
4649
|
+
const componentId = (_a = this.data.i) === null || _a === void 0 ? void 0 : _a.sid;
|
|
4650
|
+
if (isString(componentId)) {
|
|
4651
|
+
customWrapperCache.set(componentId, this);
|
|
4652
|
+
}
|
|
4653
|
+
},
|
|
4654
|
+
detached() {
|
|
4655
|
+
var _a;
|
|
4656
|
+
const componentId = (_a = this.data.i) === null || _a === void 0 ? void 0 : _a.sid;
|
|
4657
|
+
if (isString(componentId)) {
|
|
4658
|
+
customWrapperCache.delete(componentId);
|
|
4659
|
+
}
|
|
4660
|
+
}
|
|
4661
|
+
}
|
|
4662
|
+
: EMPTY_OBJ;
|
|
4663
|
+
return Object.assign({ properties: {
|
|
4636
4664
|
i: {
|
|
4637
4665
|
type: Object,
|
|
4638
4666
|
value: {
|
|
@@ -4643,15 +4671,12 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
4643
4671
|
type: String,
|
|
4644
4672
|
value: ''
|
|
4645
4673
|
}
|
|
4646
|
-
},
|
|
4647
|
-
options: {
|
|
4674
|
+
}, options: {
|
|
4648
4675
|
addGlobalClass: true,
|
|
4649
|
-
virtualHost:
|
|
4650
|
-
},
|
|
4651
|
-
methods: {
|
|
4676
|
+
virtualHost: !isCustomWrapper
|
|
4677
|
+
}, methods: {
|
|
4652
4678
|
eh: eventHandler
|
|
4653
|
-
}
|
|
4654
|
-
};
|
|
4679
|
+
} }, lifeCycles);
|
|
4655
4680
|
}
|
|
4656
4681
|
|
|
4657
4682
|
function removeLeadingSlash(path) {
|