@tarojs/runtime 3.3.19 → 3.3.20

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.
@@ -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;
@@ -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>, Show, PageInstance {
24
+ export interface ReactPageComponent<T = PageProps> extends ComponentClass<T>, PageInstance {
25
25
  }
26
- export interface ReactPageInstance<T = PageProps> extends Component<T>, Show, PageInstance {
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>, Show, AppInstance {
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?(options?: unknown): void;
67
- componentDidHide?(options?: unknown): void;
68
- onShow?(options?: unknown): void;
69
- onHide?(options?: unknown): void;
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;
@@ -7,6 +7,7 @@ export declare let PageContext: React.Context<string>;
7
7
  export declare function connectReactPage(R: typeof React, id: string): (component: ReactPageComponent) => React.ComponentClass<PageProps>;
8
8
  export declare function createReactApp(App: React.ComponentClass, react: typeof React, dom: any, config: AppConfig): AppInstance;
9
9
  export declare function createNativeComponentConfig(Component: any, react: typeof React, reactdom: any, componentConfig: any): {
10
+ options: any;
10
11
  properties: {
11
12
  props: {
12
13
  type: null;
@@ -19,7 +20,7 @@ export declare function createNativeComponentConfig(Component: any, react: typeo
19
20
  ready(): void;
20
21
  detached(): void;
21
22
  pageLifetimes: {
22
- show(): void;
23
+ show(options: any): void;
23
24
  hide(): void;
24
25
  };
25
26
  methods: {
@@ -1285,7 +1285,8 @@ function shortcutAttr(key) {
1285
1285
  default:
1286
1286
  return key;
1287
1287
  }
1288
- }
1288
+ }
1289
+ const customWrapperCache = new Map();
1289
1290
 
1290
1291
  let TaroEventTarget = class TaroEventTarget {
1291
1292
  constructor(// eslint-disable-next-line @typescript-eslint/indent
@@ -3458,17 +3459,17 @@ let TaroRootElement = class TaroRootElement extends TaroElement {
3458
3459
  const dataPathArr = p.split('.');
3459
3460
  let hasCustomWrapper = false;
3460
3461
  for (let i = dataPathArr.length; i > 0; i--) {
3461
- const allPath = dataPathArr.slice(0, i).join('.');
3462
- const getData = get(ctx.__data__ || ctx.data, allPath);
3463
- if (getData && getData.nn && getData.nn === CUSTOM_WRAPPER) {
3462
+ const allPath = dataPathArr.slice(1, i).join('.').replace(/\bcn\b/g, 'childNodes');
3463
+ const getData = get(this, allPath);
3464
+ if (getData && getData.nodeName && getData.nodeName === CUSTOM_WRAPPER) {
3464
3465
  const customWrapperId = getData.uid;
3465
- const customWrapper = ctx.selectComponent(`#${customWrapperId}`);
3466
+ const customWrapper = customWrapperCache.get(customWrapperId);
3466
3467
  const splitedPath = dataPathArr.slice(i).join('.');
3467
3468
  if (customWrapper) {
3468
3469
  hasCustomWrapper = true;
3469
3470
  customWrapperMap.set(customWrapper, Object.assign(Object.assign({}, (customWrapperMap.get(customWrapper) || {})), { [`i.${splitedPath}`]: data[p] }));
3471
+ break;
3470
3472
  }
3471
- break;
3472
3473
  }
3473
3474
  }
3474
3475
  if (!hasCustomWrapper) {
@@ -5022,11 +5023,11 @@ if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
5022
5023
  if (!(DATE in window$1)) {
5023
5024
  window$1.Date = Date;
5024
5025
  }
5025
- window$1.setTimeout = function (cb, delay) {
5026
- setTimeout(cb, delay);
5026
+ window$1.setTimeout = function (...args) {
5027
+ return setTimeout(...args);
5027
5028
  };
5028
- window$1.clearTimeout = function (seed) {
5029
- clearTimeout(seed);
5029
+ window$1.clearTimeout = function (...args) {
5030
+ return clearTimeout(...args);
5030
5031
  };
5031
5032
  }
5032
5033
 
@@ -5168,11 +5169,8 @@ function stringify(obj) {
5168
5169
  return path === '' ? path : '?' + path;
5169
5170
  }
5170
5171
  function getPath(id, options) {
5171
- let path = id;
5172
- if (!isBrowser) {
5173
- path = id + stringify(options);
5174
- }
5175
- return path;
5172
+ const idx = id.indexOf('?');
5173
+ return `${idx > -1 ? id.substring(0, idx) : id}${stringify(isBrowser ? { stamp: (options === null || options === void 0 ? void 0 : options.stamp) || '' } : options)}`;
5176
5174
  }
5177
5175
  function getOnReadyEventKey(path) {
5178
5176
  return path + '.' + 'onReady';
@@ -5201,6 +5199,9 @@ function createPageConfig(component, pageName, data, pageConfig) {
5201
5199
  options.$taroTimestamp = Date.now();
5202
5200
  // this.$taroPath 是页面唯一标识,不可变,因此页面参数 options 也不可变
5203
5201
  this.$taroPath = getPath(id, options);
5202
+ if (isBrowser) {
5203
+ config.path = this.$taroPath;
5204
+ }
5204
5205
  // this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
5205
5206
  if (this.$taroParams == null) {
5206
5207
  this.$taroParams = Object.assign({}, options);
@@ -5338,9 +5339,6 @@ function createPageConfig(component, pageName, data, pageConfig) {
5338
5339
  if (!isUndefined(data)) {
5339
5340
  config.data = data;
5340
5341
  }
5341
- if (isBrowser) {
5342
- config.path = id;
5343
- }
5344
5342
  return config;
5345
5343
  }
5346
5344
  function createComponentConfig(component, componentName, data) {
@@ -5384,8 +5382,26 @@ function createComponentConfig(component, componentName, data) {
5384
5382
  return config;
5385
5383
  }
5386
5384
  function createRecursiveComponentConfig(componentName) {
5387
- return {
5388
- properties: {
5385
+ const isCustomWrapper = componentName === 'custom-wrapper';
5386
+ const lifeCycles = isCustomWrapper
5387
+ ? {
5388
+ attached() {
5389
+ var _a;
5390
+ const componentId = (_a = this.data.i) === null || _a === void 0 ? void 0 : _a.uid;
5391
+ if (isString(componentId)) {
5392
+ customWrapperCache.set(componentId, this);
5393
+ }
5394
+ },
5395
+ detached() {
5396
+ var _a;
5397
+ const componentId = (_a = this.data.i) === null || _a === void 0 ? void 0 : _a.uid;
5398
+ if (isString(componentId)) {
5399
+ customWrapperCache.delete(componentId);
5400
+ }
5401
+ }
5402
+ }
5403
+ : EMPTY_OBJ;
5404
+ return Object.assign({ properties: {
5389
5405
  i: {
5390
5406
  type: Object,
5391
5407
  value: {
@@ -5396,15 +5412,12 @@ function createRecursiveComponentConfig(componentName) {
5396
5412
  type: String,
5397
5413
  value: ''
5398
5414
  }
5399
- },
5400
- options: {
5415
+ }, options: {
5401
5416
  addGlobalClass: true,
5402
- virtualHost: componentName !== 'custom-wrapper'
5403
- },
5404
- methods: {
5417
+ virtualHost: !isCustomWrapper
5418
+ }, methods: {
5405
5419
  eh: eventHandler
5406
- }
5407
- };
5420
+ } }, lifeCycles);
5408
5421
  }
5409
5422
 
5410
5423
  const hooks$3 = container.get(SERVICE_IDENTIFIER.Hooks);
@@ -5623,16 +5636,16 @@ function createReactApp(App, react, dom, config) {
5623
5636
  app.componentDidShow(options);
5624
5637
  }
5625
5638
  // app useDidShow
5626
- triggerAppHook('onShow');
5639
+ triggerAppHook('onShow', options);
5627
5640
  }
5628
5641
  },
5629
5642
  onHide: {
5630
5643
  enumerable: true,
5631
5644
  writable: true,
5632
- value(options) {
5645
+ value() {
5633
5646
  const app = ref.current;
5634
5647
  if (app != null && isFunction$1(app.componentDidHide)) {
5635
- app.componentDidHide(options);
5648
+ app.componentDidHide();
5636
5649
  }
5637
5650
  // app useDidHide
5638
5651
  triggerAppHook('onHide');
@@ -5649,13 +5662,13 @@ function createReactApp(App, react, dom, config) {
5649
5662
  }
5650
5663
  }
5651
5664
  });
5652
- function triggerAppHook(lifecycle) {
5665
+ function triggerAppHook(lifecycle, ...option) {
5653
5666
  const instance = getPageInstance(HOOKS_APP_ID);
5654
5667
  if (instance) {
5655
5668
  const app = ref.current;
5656
5669
  const func = hooks$3.getLifecycle(instance, lifecycle);
5657
5670
  if (Array.isArray(func)) {
5658
- func.forEach(cb => cb.apply(app));
5671
+ func.forEach(cb => cb.apply(app, option));
5659
5672
  }
5660
5673
  }
5661
5674
  }
@@ -5735,6 +5748,7 @@ function createNativeComponentConfig(Component, react, reactdom, componentConfig
5735
5748
  ReactDOM = reactdom;
5736
5749
  setReconciler();
5737
5750
  const config = {
5751
+ options: componentConfig,
5738
5752
  properties: {
5739
5753
  props: {
5740
5754
  type: null,
@@ -5762,8 +5776,8 @@ function createNativeComponentConfig(Component, react, reactdom, componentConfig
5762
5776
  Current.app.unmount(this.compId);
5763
5777
  },
5764
5778
  pageLifetimes: {
5765
- show() {
5766
- safeExecute(this.compId, 'onShow');
5779
+ show(options) {
5780
+ safeExecute(this.compId, 'onShow', options);
5767
5781
  },
5768
5782
  hide() {
5769
5783
  safeExecute(this.compId, 'onHide');