@tarojs/runtime 4.1.12-beta.33 → 4.1.12-beta.34

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/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export { taroHistoryProvider as history, taroLocationProvider as location, taroW
12
12
  export { TaroElement } from './dom/element.js';
13
13
  export { TaroEvent, createEvent, eventHandler } from './dom/event.js';
14
14
  export { FormElement } from './dom/form.js';
15
+ export { bumpNearestCtxEpochForRoot, getNearestCtx, isNearestCtxEnv } from './dom/nearest-ctx.js';
15
16
  export { TaroNode } from './dom/node.js';
16
17
  export { TaroRootElement } from './dom/root.js';
17
18
  export { Style } from './dom/style.js';
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@ export { taroHistoryProvider as history, taroLocationProvider as location, taroW
13
13
  export { TaroElement } from './dom/element.js';
14
14
  export { TaroEvent, createEvent, eventHandler } from './dom/event.js';
15
15
  export { FormElement } from './dom/form.js';
16
+ export { bumpNearestCtxEpochForRoot, getNearestCtx, isNearestCtxEnv } from './dom/nearest-ctx.js';
16
17
  export { TaroNode } from './dom/node.js';
17
18
  export { TaroRootElement } from './dom/root.js';
18
19
  export { Style } from './dom/style.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -241,9 +241,11 @@ declare class TaroRootElement extends TaroElement {
241
241
  private updateCallbacks;
242
242
  pendingUpdate: boolean;
243
243
  ctx: null | MpInstance;
244
+ nearestCtxEpoch: number;
244
245
  constructor();
245
246
  get _path(): string;
246
247
  get _root(): TaroRootElement;
248
+ bumpNearestCtxEpoch(): void;
247
249
  scheduleTask(fn: TFunc): void;
248
250
  enqueueUpdate(payload: UpdatePayload): void;
249
251
  performUpdate(initRender?: boolean, prerender?: TFunc): void;
@@ -267,6 +269,7 @@ declare class TaroNode extends TaroEventTarget {
267
269
  private updateChildNodes;
268
270
  private updateSingleChild;
269
271
  get _root(): TaroRootElement | null;
272
+ get _scope(): MpInstance | null | undefined;
270
273
  protected findIndex(refChild: TaroNode): number;
271
274
  get _path(): string;
272
275
  get nextSibling(): TaroNode | null;
@@ -589,6 +592,10 @@ declare const taroWindowProvider: TaroWindow;
589
592
  declare const taroLocationProvider: TaroLocation;
590
593
  declare const taroHistoryProvider: TaroHistory;
591
594
 
595
+ declare function isNearestCtxEnv(): boolean;
596
+ declare function getNearestCtx(node: TaroNode): MpInstance | null | undefined;
597
+ declare function bumpNearestCtxEpochForRoot(root: TaroRootElement | null | undefined): void;
598
+
592
599
  declare class SVGElement extends TaroElement {
593
600
  }
594
601
 
@@ -857,7 +864,7 @@ declare function getOnShowEventKey(path: string): string;
857
864
  declare function getOnHideEventKey(path: string): string;
858
865
  declare function createPageConfig(component: any, pageName?: string, data?: Record<string, unknown>, pageConfig?: PageConfig): PageInstance;
859
866
  declare function createComponentConfig(component: React.ComponentClass, componentName?: string, data?: Record<string, unknown>): any;
860
- declare function createRecursiveComponentConfig(componentName?: string): any;
867
+ declare function createRecursiveComponentConfig(componentName?: string, forceCustomWrapper?: boolean): any;
861
868
 
862
869
  /**
863
870
  * React also has a fancy function's name for this: `hydrate()`.
@@ -913,5 +920,5 @@ declare function convertNumber2PX(value: number): string;
913
920
 
914
921
  declare function handlePolyfill(): void;
915
922
 
916
- export { A, APP, BEHAVIORS, BODY, CATCHMOVE, CATCH_VIEW, CHANGE, CLASS, CLICK_VIEW, COMMENT, COMPILE_MODE, CONFIRM, CONTAINER, CONTEXT_ACTIONS, CURRENT_TARGET, CUSTOM_WRAPPER, Current, DATASET, DATE, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, EVENT_CALLBACK_RESULT, EXTERNAL_CLASSES, FOCUS, FormElement, HEAD, HOOKS_APP_ID, HTML, History, ID, INPUT, KEY_CODE, Location, MutationObserver, OBJECT, ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, OPTIONS, PAGE_INIT, PROPERTY_THRESHOLD, PROPS, PURE_VIEW, ROOT_STR, SET_DATA, SET_TIMEOUT, STATIC_VIEW, STYLE, SVGElement, Style, TARGET, TARO_RUNTIME, TIME_STAMP, TOUCHMOVE, TYPE, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, UID, TaroURLProvider as URL, URLSearchParams$1 as URLSearchParams, VALUE, VIEW, addLeadingSlash, _caf as cancelAnimationFrame, convertNumber2PX, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, customWrapperCache, debounce, taroDocumentProvider as document, env, eventCenter, eventHandler, eventSource, extend, getComponentsAlias, taroGetComputedStyleProvider as getComputedStyle, getCurrentInstance, getCurrentPage, getHomePage, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, handlePolyfill, hasBasename, taroHistoryProvider as history, hydrate, incrementId, injectPageInstance, isComment, isElement, isHasExtractProp, isParentBound, isText, taroLocationProvider as location, nav as navigator, nextTick, now, options, parseUrl, perf, removePageInstance, _raf as requestAnimationFrame, safeExecute, shortcutAttr, stringify, stripBasename, stripSuffix, stripTrailing, throttle, taroWindowProvider as window };
923
+ export { A, APP, BEHAVIORS, BODY, CATCHMOVE, CATCH_VIEW, CHANGE, CLASS, CLICK_VIEW, COMMENT, COMPILE_MODE, CONFIRM, CONTAINER, CONTEXT_ACTIONS, CURRENT_TARGET, CUSTOM_WRAPPER, Current, DATASET, DATE, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, EVENT_CALLBACK_RESULT, EXTERNAL_CLASSES, FOCUS, FormElement, HEAD, HOOKS_APP_ID, HTML, History, ID, INPUT, KEY_CODE, Location, MutationObserver, OBJECT, ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, OPTIONS, PAGE_INIT, PROPERTY_THRESHOLD, PROPS, PURE_VIEW, ROOT_STR, SET_DATA, SET_TIMEOUT, STATIC_VIEW, STYLE, SVGElement, Style, TARGET, TARO_RUNTIME, TIME_STAMP, TOUCHMOVE, TYPE, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, UID, TaroURLProvider as URL, URLSearchParams$1 as URLSearchParams, VALUE, VIEW, addLeadingSlash, bumpNearestCtxEpochForRoot, _caf as cancelAnimationFrame, convertNumber2PX, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, customWrapperCache, debounce, taroDocumentProvider as document, env, eventCenter, eventHandler, eventSource, extend, getComponentsAlias, taroGetComputedStyleProvider as getComputedStyle, getCurrentInstance, getCurrentPage, getHomePage, getNearestCtx, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, handlePolyfill, hasBasename, taroHistoryProvider as history, hydrate, incrementId, injectPageInstance, isComment, isElement, isHasExtractProp, isNearestCtxEnv, isParentBound, isText, taroLocationProvider as location, nav as navigator, nextTick, now, options, parseUrl, perf, removePageInstance, _raf as requestAnimationFrame, safeExecute, shortcutAttr, stringify, stripBasename, stripSuffix, stripTrailing, throttle, taroWindowProvider as window };
917
924
  export type { AddEventListenerOptions, AppInstance, Attributes, DataTree, EventHandler, EventListenerOptions, EventOptions, EventsType, HydratedData, Instance, KeyFrame, MiniData, MiniElementData, MiniTextData, MpEvent, MpInstance, Options$2 as Options, PageConfig, PageInstance, PageLifeCycle, PageProps, ReactAppInstance, ReactPageComponent, ReactPageInstance, ScrollTimelineOption, TFunc, UpdatePayload, UpdatePayloadValue };
@@ -1472,6 +1472,48 @@ class TaroEventTarget {
1472
1472
  }
1473
1473
  }
1474
1474
 
1475
+ const nearestCtxCache = new WeakMap();
1476
+ function isNearestCtxEnv() {
1477
+ return process.env.TARO_ENV === 'weapp' || process.env.TARO_ENV === 'jd';
1478
+ }
1479
+ function getNearestCtx(node) {
1480
+ if (!isNearestCtxEnv()) {
1481
+ return undefined;
1482
+ }
1483
+ const root = node._root;
1484
+ if (root == null) {
1485
+ return null;
1486
+ }
1487
+ const cached = nearestCtxCache.get(node);
1488
+ if (cached && cached.nearestCtxEpoch === root.nearestCtxEpoch) {
1489
+ return cached.value;
1490
+ }
1491
+ const value = resolveNearestCtxValue(node, root);
1492
+ nearestCtxCache.set(node, { value, nearestCtxEpoch: root.nearestCtxEpoch });
1493
+ return value;
1494
+ }
1495
+ function resolveNearestCtxValue(node, root) {
1496
+ var _a;
1497
+ if (node.nodeType === 1 /* NodeType.ELEMENT_NODE */) {
1498
+ const ctx = node.ctx;
1499
+ if (ctx != null)
1500
+ return ctx;
1501
+ }
1502
+ let current = node.parentNode;
1503
+ while (current) {
1504
+ if (current.nodeType === 1 /* NodeType.ELEMENT_NODE */) {
1505
+ const ctx = current.ctx;
1506
+ if (ctx != null)
1507
+ return ctx;
1508
+ }
1509
+ current = current.parentNode;
1510
+ }
1511
+ return (_a = root.ctx) !== null && _a !== void 0 ? _a : null;
1512
+ }
1513
+ function bumpNearestCtxEpochForRoot(root) {
1514
+ root === null || root === void 0 ? void 0 : root.bumpNearestCtxEpoch();
1515
+ }
1516
+
1475
1517
  const CHILDNODES = "cn" /* Shortcuts.Childnodes */;
1476
1518
  const nodeId = incrementId();
1477
1519
  class TaroNode extends TaroEventTarget {
@@ -1511,6 +1553,9 @@ class TaroNode extends TaroEventTarget {
1511
1553
  var _a;
1512
1554
  return ((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a._root) || null;
1513
1555
  }
1556
+ get _scope() {
1557
+ return getNearestCtx(this);
1558
+ }
1514
1559
  findIndex(refChild) {
1515
1560
  const index = this.childNodes.indexOf(refChild);
1516
1561
  ensure(index !== -1, 'The node to be replaced is not a child of this node.');
@@ -1656,6 +1701,9 @@ class TaroNode extends TaroEventTarget {
1656
1701
  }
1657
1702
  }
1658
1703
  }
1704
+ if (this._root) {
1705
+ bumpNearestCtxEpochForRoot(this._root);
1706
+ }
1659
1707
  MutationObserver$1.record({
1660
1708
  type: "childList" /* MutationRecordType.CHILD_LIST */,
1661
1709
  target: this,
@@ -1732,6 +1780,9 @@ class TaroNode extends TaroEventTarget {
1732
1780
  if (this._root && doUpdate !== false) {
1733
1781
  this.updateChildNodes();
1734
1782
  }
1783
+ if (this._root) {
1784
+ bumpNearestCtxEpochForRoot(this._root);
1785
+ }
1735
1786
  return child;
1736
1787
  }
1737
1788
  remove(options) {
@@ -3629,6 +3680,7 @@ class TaroRootElement extends TaroElement {
3629
3680
  this.updateCallbacks = [];
3630
3681
  this.pendingUpdate = false;
3631
3682
  this.ctx = null;
3683
+ this.nearestCtxEpoch = 0;
3632
3684
  this.nodeName = ROOT_STR;
3633
3685
  this.tagName = ROOT_STR.toUpperCase();
3634
3686
  }
@@ -3638,6 +3690,9 @@ class TaroRootElement extends TaroElement {
3638
3690
  get _root() {
3639
3691
  return this;
3640
3692
  }
3693
+ bumpNearestCtxEpoch() {
3694
+ this.nearestCtxEpoch++;
3695
+ }
3641
3696
  scheduleTask(fn) {
3642
3697
  // 这里若使用微任务可略微提前setData的执行时机,但在部分场景下可能会出现连续setData两次,造成更大的性能问题
3643
3698
  setTimeout(fn);
@@ -4060,6 +4115,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
4060
4115
  loadResolver();
4061
4116
  if (process.env.TARO_PLATFORM !== 'web') {
4062
4117
  pageElement.ctx = this;
4118
+ bumpNearestCtxEpochForRoot(pageElement);
4063
4119
  pageElement.performUpdate(true, cb);
4064
4120
  }
4065
4121
  else {
@@ -4087,6 +4143,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
4087
4143
  unmounting = false;
4088
4144
  instances.delete($taroPath);
4089
4145
  if (pageElement) {
4146
+ bumpNearestCtxEpochForRoot(pageElement);
4090
4147
  pageElement.ctx = null;
4091
4148
  pageElement = null;
4092
4149
  }
@@ -4247,19 +4304,22 @@ function createComponentConfig(component, componentName, data) {
4247
4304
  });
4248
4305
  return config;
4249
4306
  }
4250
- function createRecursiveComponentConfig(componentName) {
4307
+ function createRecursiveComponentConfig(componentName, forceCustomWrapper = false) {
4251
4308
  const isCustomWrapper = componentName === CUSTOM_WRAPPER;
4252
4309
  const [ATTACHED, DETACHED] = hooks.call('getMiniLifecycleImpl').component;
4253
- const lifeCycles = isCustomWrapper
4310
+ const lifeCycles = isCustomWrapper || forceCustomWrapper
4254
4311
  ? {
4255
4312
  [ATTACHED]() {
4256
4313
  var _a, _b;
4257
4314
  const componentId = ((_a = this.data.i) === null || _a === void 0 ? void 0 : _a.sid) || ((_b = this.props.i) === null || _b === void 0 ? void 0 : _b.sid);
4258
4315
  if (isString(componentId)) {
4259
- customWrapperCache.set(componentId, this);
4316
+ if (isCustomWrapper) {
4317
+ customWrapperCache.set(componentId, this);
4318
+ }
4260
4319
  const el = env.document.getElementById(componentId);
4261
4320
  if (el) {
4262
4321
  el.ctx = this;
4322
+ bumpNearestCtxEpochForRoot(el._root);
4263
4323
  }
4264
4324
  }
4265
4325
  },
@@ -4267,10 +4327,13 @@ function createRecursiveComponentConfig(componentName) {
4267
4327
  var _a, _b;
4268
4328
  const componentId = ((_a = this.data.i) === null || _a === void 0 ? void 0 : _a.sid) || ((_b = this.props.i) === null || _b === void 0 ? void 0 : _b.sid);
4269
4329
  if (isString(componentId)) {
4270
- customWrapperCache.delete(componentId);
4330
+ if (isCustomWrapper) {
4331
+ customWrapperCache.delete(componentId);
4332
+ }
4271
4333
  const el = env.document.getElementById(componentId);
4272
4334
  if (el) {
4273
4335
  el.ctx = null;
4336
+ bumpNearestCtxEpochForRoot(el._root);
4274
4337
  }
4275
4338
  }
4276
4339
  }
@@ -4294,7 +4357,7 @@ function createRecursiveComponentConfig(componentName) {
4294
4357
  }
4295
4358
  }, options: Object.assign(Object.assign({}, extraOptions), { virtualHost: !isCustomWrapper }), methods: {
4296
4359
  eh: eventHandler
4297
- } }, lifeCycles), { isCustomWrapper });
4360
+ } }, lifeCycles), { isCustomWrapper, forceCustomWrapper });
4298
4361
  }
4299
4362
 
4300
4363
  const TIMEOUT = 100;
@@ -5106,5 +5169,5 @@ if (process.env.SUPPORT_TARO_POLYFILL !== 'disabled' && process.env.TARO_PLATFOR
5106
5169
  handlePolyfill();
5107
5170
  }
5108
5171
 
5109
- export { A, APP, BEHAVIORS, BODY, CATCHMOVE, CATCH_VIEW, CHANGE, CLASS, CLICK_VIEW, COMMENT, COMPILE_MODE, CONFIRM, CONTAINER, CONTEXT_ACTIONS, CURRENT_TARGET, CUSTOM_WRAPPER, Current, DATASET, DATE, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, EVENT_CALLBACK_RESULT, EXTERNAL_CLASSES, FOCUS, FormElement, HEAD, HOOKS_APP_ID, HTML, History, ID, INPUT, KEY_CODE, Location, MutationObserver$1 as MutationObserver, OBJECT, ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, OPTIONS, PAGE_INIT, PROPERTY_THRESHOLD, PROPS, PURE_VIEW, ROOT_STR, SET_DATA, SET_TIMEOUT, STATIC_VIEW, STYLE, SVGElement, Style, TARGET, TARO_RUNTIME, TIME_STAMP, TOUCHMOVE, TYPE, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, UID, TaroURLProvider as URL, URLSearchParams, VALUE, VIEW, addLeadingSlash, _caf as cancelAnimationFrame, convertNumber2PX, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, customWrapperCache, debounce, taroDocumentProvider as document, env, eventCenter, eventHandler, eventSource, extend, getComponentsAlias, taroGetComputedStyleProvider as getComputedStyle, getCurrentInstance, getCurrentPage, getHomePage, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, handlePolyfill, hasBasename, taroHistoryProvider as history, hydrate, incrementId, injectPageInstance, isComment, isElement, isHasExtractProp, isParentBound, isText, taroLocationProvider as location, nav as navigator, nextTick, now, options, parseUrl, perf, removePageInstance, _raf as requestAnimationFrame, safeExecute, shortcutAttr, stringify, stripBasename, stripSuffix, stripTrailing, throttle, taroWindowProvider as window };
5172
+ export { A, APP, BEHAVIORS, BODY, CATCHMOVE, CATCH_VIEW, CHANGE, CLASS, CLICK_VIEW, COMMENT, COMPILE_MODE, CONFIRM, CONTAINER, CONTEXT_ACTIONS, CURRENT_TARGET, CUSTOM_WRAPPER, Current, DATASET, DATE, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, EVENT_CALLBACK_RESULT, EXTERNAL_CLASSES, FOCUS, FormElement, HEAD, HOOKS_APP_ID, HTML, History, ID, INPUT, KEY_CODE, Location, MutationObserver$1 as MutationObserver, OBJECT, ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, OPTIONS, PAGE_INIT, PROPERTY_THRESHOLD, PROPS, PURE_VIEW, ROOT_STR, SET_DATA, SET_TIMEOUT, STATIC_VIEW, STYLE, SVGElement, Style, TARGET, TARO_RUNTIME, TIME_STAMP, TOUCHMOVE, TYPE, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, UID, TaroURLProvider as URL, URLSearchParams, VALUE, VIEW, addLeadingSlash, bumpNearestCtxEpochForRoot, _caf as cancelAnimationFrame, convertNumber2PX, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, customWrapperCache, debounce, taroDocumentProvider as document, env, eventCenter, eventHandler, eventSource, extend, getComponentsAlias, taroGetComputedStyleProvider as getComputedStyle, getCurrentInstance, getCurrentPage, getHomePage, getNearestCtx, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, handlePolyfill, hasBasename, taroHistoryProvider as history, hydrate, incrementId, injectPageInstance, isComment, isElement, isHasExtractProp, isNearestCtxEnv, isParentBound, isText, taroLocationProvider as location, nav as navigator, nextTick, now, options, parseUrl, perf, removePageInstance, _raf as requestAnimationFrame, safeExecute, shortcutAttr, stringify, stripBasename, stripSuffix, stripTrailing, throttle, taroWindowProvider as window };
5110
5173
  //# sourceMappingURL=runtime.esm.js.map