@tarojs/runtime 3.4.0-beta.1 → 3.4.1
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 +78 -50
- 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
|
@@ -70,10 +70,9 @@ if (process.env.TARO_ENV === 'h5') {
|
|
|
70
70
|
};
|
|
71
71
|
// Load global or shim versions of Map, Set, and WeakMap
|
|
72
72
|
var functionPrototype = Object.getPrototypeOf(Function);
|
|
73
|
-
var usePolyfill = isObject(process) && process.env && process.env["REFLECT_METADATA_USE_MAP_POLYFILL"] === "true";
|
|
74
73
|
var _Map = Map;
|
|
75
74
|
var _Set = Set;
|
|
76
|
-
var _WeakMap =
|
|
75
|
+
var _WeakMap = isFunction(WeakMap) ? WeakMap : CreateWeakMapPolyfill();
|
|
77
76
|
// [[Metadata]] internal slot
|
|
78
77
|
// https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots
|
|
79
78
|
var Metadata = new _WeakMap();
|
|
@@ -1260,7 +1259,8 @@ function shortcutAttr(key) {
|
|
|
1260
1259
|
default:
|
|
1261
1260
|
return key;
|
|
1262
1261
|
}
|
|
1263
|
-
}
|
|
1262
|
+
}
|
|
1263
|
+
const customWrapperCache = new Map();
|
|
1264
1264
|
|
|
1265
1265
|
const SID_TARO_ELEMENT = '0';
|
|
1266
1266
|
const SID_TARO_ELEMENT_FACTORY = '1';
|
|
@@ -1358,6 +1358,7 @@ let TaroEventTarget = class TaroEventTarget {
|
|
|
1358
1358
|
}
|
|
1359
1359
|
addEventListener(type, handler, options) {
|
|
1360
1360
|
var _a, _b;
|
|
1361
|
+
type = type.toLowerCase();
|
|
1361
1362
|
(_b = (_a = this.hooks).onAddEvent) === null || _b === void 0 ? void 0 : _b.call(_a, type, handler, options, this);
|
|
1362
1363
|
if (type === 'regionchange') {
|
|
1363
1364
|
// map 组件的 regionchange 事件非常特殊,详情:https://github.com/NervJS/taro/issues/5766
|
|
@@ -1365,8 +1366,6 @@ let TaroEventTarget = class TaroEventTarget {
|
|
|
1365
1366
|
this.addEventListener('end', handler, options);
|
|
1366
1367
|
return;
|
|
1367
1368
|
}
|
|
1368
|
-
type = type.toLowerCase();
|
|
1369
|
-
const handlers = this.__handlers[type];
|
|
1370
1369
|
let isCapture = Boolean(options);
|
|
1371
1370
|
let isOnce = false;
|
|
1372
1371
|
if (isObject(options)) {
|
|
@@ -1382,6 +1381,16 @@ let TaroEventTarget = class TaroEventTarget {
|
|
|
1382
1381
|
return;
|
|
1383
1382
|
}
|
|
1384
1383
|
process.env.NODE_ENV !== 'production' && warn(isCapture, 'Taro 暂未实现 event 的 capture 特性。');
|
|
1384
|
+
// 某些框架,如 PReact 有委托的机制,handler 始终是同一个函数
|
|
1385
|
+
// 这会导致多层停止冒泡失败:view -> view(handler.stop = false) -> view(handler.stop = true)
|
|
1386
|
+
// 这样解决:view -> view(handlerA.stop = false) -> view(handlerB.stop = false)
|
|
1387
|
+
// 因此每次绑定事件都新建一个函数,如果带来了性能问题,可以把这段逻辑抽取到 PReact 插件中。
|
|
1388
|
+
const oldHandler = handler;
|
|
1389
|
+
handler = function () {
|
|
1390
|
+
oldHandler.apply(this, arguments); // this 指向 Element
|
|
1391
|
+
};
|
|
1392
|
+
handler.oldHandler = oldHandler;
|
|
1393
|
+
const handlers = this.__handlers[type];
|
|
1385
1394
|
if (isArray(handlers)) {
|
|
1386
1395
|
handlers.push(handler);
|
|
1387
1396
|
}
|
|
@@ -1398,7 +1407,10 @@ let TaroEventTarget = class TaroEventTarget {
|
|
|
1398
1407
|
if (!isArray(handlers)) {
|
|
1399
1408
|
return;
|
|
1400
1409
|
}
|
|
1401
|
-
const index = handlers.
|
|
1410
|
+
const index = handlers.findIndex(item => {
|
|
1411
|
+
if (item === handler || item.oldHandler === handler)
|
|
1412
|
+
return true;
|
|
1413
|
+
});
|
|
1402
1414
|
process.env.NODE_ENV !== 'production' && warn(index === -1, `事件: '${type}' 没有注册在 DOM 中,因此不会被移除。`);
|
|
1403
1415
|
handlers.splice(index, 1);
|
|
1404
1416
|
}
|
|
@@ -2605,24 +2617,33 @@ class Performance {
|
|
|
2605
2617
|
}
|
|
2606
2618
|
const perf = new Performance();
|
|
2607
2619
|
|
|
2608
|
-
function findCustomWrapper(
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
let
|
|
2612
|
-
|
|
2613
|
-
|
|
2620
|
+
function findCustomWrapper(root, dataPathArr) {
|
|
2621
|
+
// ['root', 'cn', '[0]'] remove 'root' => ['cn', '[0]']
|
|
2622
|
+
const list = dataPathArr.slice(1);
|
|
2623
|
+
let currentData = root;
|
|
2624
|
+
let customWrapper;
|
|
2625
|
+
let splitedPath = '';
|
|
2626
|
+
list.some((item, i) => {
|
|
2627
|
+
const key = item
|
|
2628
|
+
// '[0]' => '0'
|
|
2629
|
+
.replace(/^\[(.+)\]$/, '$1')
|
|
2630
|
+
// 'cn' => 'childNodes'
|
|
2631
|
+
.replace(/\bcn\b/g, 'childNodes');
|
|
2614
2632
|
currentData = currentData[key];
|
|
2615
2633
|
if (isUndefined(currentData))
|
|
2616
2634
|
return true;
|
|
2617
|
-
if (currentData.
|
|
2618
|
-
|
|
2619
|
-
|
|
2635
|
+
if (currentData.nodeName === CUSTOM_WRAPPER) {
|
|
2636
|
+
const res = customWrapperCache.get(currentData.sid);
|
|
2637
|
+
if (res) {
|
|
2638
|
+
customWrapper = res;
|
|
2639
|
+
splitedPath = dataPathArr.slice(i + 2).join('.');
|
|
2640
|
+
}
|
|
2620
2641
|
}
|
|
2621
2642
|
});
|
|
2622
|
-
if (
|
|
2643
|
+
if (customWrapper) {
|
|
2623
2644
|
return {
|
|
2624
|
-
|
|
2625
|
-
|
|
2645
|
+
customWrapper,
|
|
2646
|
+
splitedPath
|
|
2626
2647
|
};
|
|
2627
2648
|
}
|
|
2628
2649
|
}
|
|
@@ -2690,17 +2711,12 @@ let TaroRootElement = class TaroRootElement extends TaroElement {
|
|
|
2690
2711
|
// 更新渲染,区分 CustomWrapper 与页面级别的 setData
|
|
2691
2712
|
for (const p in data) {
|
|
2692
2713
|
const dataPathArr = p.split('.');
|
|
2693
|
-
const found = findCustomWrapper(
|
|
2714
|
+
const found = findCustomWrapper(this, dataPathArr);
|
|
2694
2715
|
if (found) {
|
|
2695
2716
|
// 此项数据使用 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
|
-
}
|
|
2717
|
+
const { customWrapper, splitedPath } = found;
|
|
2718
|
+
// 合并同一个 customWrapper 的相关更新到一次 setData 中
|
|
2719
|
+
customWrapperMap.set(customWrapper, Object.assign(Object.assign({}, (customWrapperMap.get(customWrapper) || {})), { [`i.${splitedPath}`]: data[p] }));
|
|
2704
2720
|
}
|
|
2705
2721
|
else {
|
|
2706
2722
|
// 此项数据使用页面去更新
|
|
@@ -4292,11 +4308,11 @@ if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
|
4292
4308
|
if (!(DATE in window$1)) {
|
|
4293
4309
|
window$1.Date = Date;
|
|
4294
4310
|
}
|
|
4295
|
-
window$1.setTimeout = function (
|
|
4296
|
-
setTimeout(
|
|
4311
|
+
window$1.setTimeout = function (...args) {
|
|
4312
|
+
return setTimeout(...args);
|
|
4297
4313
|
};
|
|
4298
|
-
window$1.clearTimeout = function (
|
|
4299
|
-
clearTimeout(
|
|
4314
|
+
window$1.clearTimeout = function (...args) {
|
|
4315
|
+
return clearTimeout(...args);
|
|
4300
4316
|
};
|
|
4301
4317
|
document$1.defaultView = window$1;
|
|
4302
4318
|
}
|
|
@@ -4433,11 +4449,8 @@ function stringify(obj) {
|
|
|
4433
4449
|
return path === '' ? path : '?' + path;
|
|
4434
4450
|
}
|
|
4435
4451
|
function getPath(id, options) {
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
path = id + stringify(options);
|
|
4439
|
-
}
|
|
4440
|
-
return path;
|
|
4452
|
+
const idx = id.indexOf('?');
|
|
4453
|
+
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
4454
|
}
|
|
4442
4455
|
function getOnReadyEventKey(path) {
|
|
4443
4456
|
return path + '.' + ON_READY;
|
|
@@ -4479,6 +4492,9 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4479
4492
|
// this.$taroPath 是页面唯一标识,不可变,因此页面参数 options 也不可变
|
|
4480
4493
|
this.$taroPath = getPath(id, options);
|
|
4481
4494
|
const $taroPath = this.$taroPath;
|
|
4495
|
+
if (process.env.TARO_ENV === 'h5') {
|
|
4496
|
+
config.path = this.$taroPath;
|
|
4497
|
+
}
|
|
4482
4498
|
// this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
|
|
4483
4499
|
if (this.$taroParams == null) {
|
|
4484
4500
|
this.$taroParams = Object.assign({}, options);
|
|
@@ -4529,13 +4545,13 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4529
4545
|
raf(() => eventCenter.trigger(getOnReadyEventKey(id)));
|
|
4530
4546
|
this.onReady.called = true;
|
|
4531
4547
|
},
|
|
4532
|
-
[ONSHOW]() {
|
|
4548
|
+
[ONSHOW](options = {}) {
|
|
4533
4549
|
hasLoaded.then(() => {
|
|
4534
4550
|
// 设置 Current 的 page 和 router
|
|
4535
4551
|
Current.page = this;
|
|
4536
4552
|
setCurrentRouter(this);
|
|
4537
4553
|
// 触发生命周期
|
|
4538
|
-
safeExecute(this.$taroPath, ON_SHOW);
|
|
4554
|
+
safeExecute(this.$taroPath, ON_SHOW, options);
|
|
4539
4555
|
// 通过事件触发子组件的生命周期
|
|
4540
4556
|
raf(() => eventCenter.trigger(getOnShowEventKey(id)));
|
|
4541
4557
|
});
|
|
@@ -4584,9 +4600,6 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4584
4600
|
if (!isUndefined(data)) {
|
|
4585
4601
|
config.data = data;
|
|
4586
4602
|
}
|
|
4587
|
-
if (process.env.TARO_ENV === 'h5') {
|
|
4588
|
-
config.path = id;
|
|
4589
|
-
}
|
|
4590
4603
|
(_c = hooks.modifyPageObject) === null || _c === void 0 ? void 0 : _c.call(hooks, config);
|
|
4591
4604
|
return config;
|
|
4592
4605
|
}
|
|
@@ -4631,8 +4644,26 @@ function createComponentConfig(component, componentName, data) {
|
|
|
4631
4644
|
return config;
|
|
4632
4645
|
}
|
|
4633
4646
|
function createRecursiveComponentConfig(componentName) {
|
|
4634
|
-
|
|
4635
|
-
|
|
4647
|
+
const isCustomWrapper = componentName === CUSTOM_WRAPPER;
|
|
4648
|
+
const lifeCycles = isCustomWrapper
|
|
4649
|
+
? {
|
|
4650
|
+
attached() {
|
|
4651
|
+
var _a;
|
|
4652
|
+
const componentId = (_a = this.data.i) === null || _a === void 0 ? void 0 : _a.sid;
|
|
4653
|
+
if (isString(componentId)) {
|
|
4654
|
+
customWrapperCache.set(componentId, this);
|
|
4655
|
+
}
|
|
4656
|
+
},
|
|
4657
|
+
detached() {
|
|
4658
|
+
var _a;
|
|
4659
|
+
const componentId = (_a = this.data.i) === null || _a === void 0 ? void 0 : _a.sid;
|
|
4660
|
+
if (isString(componentId)) {
|
|
4661
|
+
customWrapperCache.delete(componentId);
|
|
4662
|
+
}
|
|
4663
|
+
}
|
|
4664
|
+
}
|
|
4665
|
+
: EMPTY_OBJ;
|
|
4666
|
+
return Object.assign({ properties: {
|
|
4636
4667
|
i: {
|
|
4637
4668
|
type: Object,
|
|
4638
4669
|
value: {
|
|
@@ -4643,15 +4674,12 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
4643
4674
|
type: String,
|
|
4644
4675
|
value: ''
|
|
4645
4676
|
}
|
|
4646
|
-
},
|
|
4647
|
-
options: {
|
|
4677
|
+
}, options: {
|
|
4648
4678
|
addGlobalClass: true,
|
|
4649
|
-
virtualHost:
|
|
4650
|
-
},
|
|
4651
|
-
methods: {
|
|
4679
|
+
virtualHost: !isCustomWrapper
|
|
4680
|
+
}, methods: {
|
|
4652
4681
|
eh: eventHandler
|
|
4653
|
-
}
|
|
4654
|
-
};
|
|
4682
|
+
} }, lifeCycles);
|
|
4655
4683
|
}
|
|
4656
4684
|
|
|
4657
4685
|
function removeLeadingSlash(path) {
|