@tarojs/runtime 3.7.0-alpha.25 → 3.7.0-alpha.27

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.
@@ -431,7 +431,7 @@ declare const nav: any;
431
431
  declare let now: () => number;
432
432
  // https://gist.github.com/paulirish/1579671
433
433
  // https://gist.github.com/jalbam/5fe05443270fa6d8136238ec72accbc0
434
- declare const _raf: typeof requestAnimationFrame | ((callback: any) => NodeJS.Timeout);
434
+ declare const _raf: typeof requestAnimationFrame | ((callback: any) => NodeJS.Timer);
435
435
  declare const _caf: typeof cancelAnimationFrame;
436
436
  declare class URLSearchParams {
437
437
  #private;
@@ -626,6 +626,7 @@ declare const KEY_CODE = "keyCode";
626
626
  declare const TOUCHMOVE = "touchmove";
627
627
  declare const DATE = "Date";
628
628
  declare const SET_TIMEOUT = "setTimeout";
629
+ declare const COMPILE_MODE = "compileMode";
629
630
  declare const CATCHMOVE = "catchMove";
630
631
  declare const CATCH_VIEW = "catch-view";
631
632
  declare const COMMENT = "comment";
@@ -776,5 +777,23 @@ declare function hydrate(node: TaroElement | TaroText): MiniData;
776
777
  declare const nextTick: (cb: Func, ctx?: Record<string, any>) => void;
777
778
  declare const options: Options;
778
779
  declare const incrementId: () => () => string;
780
+ declare function isElement(node: TaroNode): node is TaroElement;
781
+ declare function isText(node: TaroNode): node is TaroText;
782
+ declare function isComment(node: TaroNode): boolean;
783
+ declare function isHasExtractProp(el: TaroElement): boolean;
784
+ /**
785
+ * 往上寻找组件树直到 root,寻找是否有祖先组件绑定了同类型的事件
786
+ * @param node 当前组件
787
+ * @param type 事件类型
788
+ */
789
+ declare function isParentBinded(node: TaroElement | null, type: string): boolean;
790
+ declare function shortcutAttr(key: string): string;
791
+ declare const customWrapperCache: Map<string, Record<string, any>>;
792
+ interface Ctor {
793
+ new (...args: any[]): any;
794
+ }
795
+ declare function extend(ctor: Ctor, methodName: string, options: Func | Record<string, any>): void;
796
+ declare function getComponentsAlias(): any;
797
+ declare function convertNumber2PX(value: number): string;
779
798
  export { hooks } from '@tarojs/shared';
780
- export { document, getComputedStyle, History, Location, nav as navigator, _caf as cancelAnimationFrame, now, _raf as requestAnimationFrame, parseUrl, URL, URLSearchParams, history, location, window, TaroElement, createEvent, eventHandler, TaroEvent, FormElement, TaroNode, TaroRootElement, Style, SVGElement, TaroText, MutationObserver, env, PROPERTY_THRESHOLD, TARO_RUNTIME, HOOKS_APP_ID, SET_DATA, PAGE_INIT, ROOT_STR, HTML, HEAD, BODY, APP, CONTAINER, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, ID, UID, CLASS, STYLE, FOCUS, VIEW, STATIC_VIEW, PURE_VIEW, PROPS, DATASET, OBJECT, VALUE, INPUT, CHANGE, CUSTOM_WRAPPER, TARGET, CURRENT_TARGET, TYPE, CONFIRM, TIME_STAMP, KEY_CODE, TOUCHMOVE, DATE, SET_TIMEOUT, CATCHMOVE, CATCH_VIEW, COMMENT, ON_LOAD, ON_READY, ON_SHOW, ON_HIDE, OPTIONS, EXTERNAL_CLASSES, EVENT_CALLBACK_RESULT, BEHAVIORS, A, CONTEXT_ACTIONS, Current, getCurrentInstance, eventSource, addLeadingSlash, createComponentConfig, createPageConfig, createRecursiveComponentConfig, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, injectPageInstance, removePageInstance, safeExecute, stringify, EventsType, eventCenter, Events, hydrate, nextTick, options, incrementId, Instance, VueAppInstance, VueInstance, PageProps, ReactPageComponent, ReactPageInstance, ReactAppInstance, PageLifeCycle, PageInstance, AppInstance, Attributes, EventOptions, MpEvent, EventListenerOptions, AddEventListenerOptions, EventHandler, MpInstance, MiniElementData, MiniData, HydratedData, UpdatePayloadValue, DataTree, UpdatePayload, Options$0 as Options, Func, Ctx };
799
+ export { document, getComputedStyle, History, Location, nav as navigator, _caf as cancelAnimationFrame, now, _raf as requestAnimationFrame, parseUrl, URL, URLSearchParams, history, location, window, TaroElement, createEvent, eventHandler, TaroEvent, FormElement, TaroNode, TaroRootElement, Style, SVGElement, TaroText, MutationObserver, env, PROPERTY_THRESHOLD, TARO_RUNTIME, HOOKS_APP_ID, SET_DATA, PAGE_INIT, ROOT_STR, HTML, HEAD, BODY, APP, CONTAINER, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, ID, UID, CLASS, STYLE, FOCUS, VIEW, STATIC_VIEW, PURE_VIEW, PROPS, DATASET, OBJECT, VALUE, INPUT, CHANGE, CUSTOM_WRAPPER, TARGET, CURRENT_TARGET, TYPE, CONFIRM, TIME_STAMP, KEY_CODE, TOUCHMOVE, DATE, SET_TIMEOUT, COMPILE_MODE, CATCHMOVE, CATCH_VIEW, COMMENT, ON_LOAD, ON_READY, ON_SHOW, ON_HIDE, OPTIONS, EXTERNAL_CLASSES, EVENT_CALLBACK_RESULT, BEHAVIORS, A, CONTEXT_ACTIONS, Current, getCurrentInstance, eventSource, addLeadingSlash, createComponentConfig, createPageConfig, createRecursiveComponentConfig, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, injectPageInstance, removePageInstance, safeExecute, stringify, EventsType, eventCenter, Events, hydrate, nextTick, options, incrementId, isElement, isText, isComment, isHasExtractProp, isParentBinded, shortcutAttr, customWrapperCache, extend, getComponentsAlias, convertNumber2PX, Instance, VueAppInstance, VueInstance, PageProps, ReactPageComponent, ReactPageInstance, ReactAppInstance, PageLifeCycle, PageInstance, AppInstance, Attributes, EventOptions, MpEvent, EventListenerOptions, AddEventListenerOptions, EventHandler, MpInstance, MiniElementData, MiniTextData, MiniData, HydratedData, UpdatePayloadValue, DataTree, UpdatePayload, Options$0 as Options, Func, Ctx };
@@ -39,6 +39,7 @@ const KEY_CODE = 'keyCode';
39
39
  const TOUCHMOVE = 'touchmove';
40
40
  const DATE = 'Date';
41
41
  const SET_TIMEOUT = 'setTimeout';
42
+ const COMPILE_MODE = 'compileMode';
42
43
  const CATCHMOVE = 'catchMove';
43
44
  const CATCH_VIEW = 'catch-view';
44
45
  const COMMENT = 'comment';
@@ -124,7 +125,7 @@ class MutationObserver {
124
125
  constructor(callback) {
125
126
  {
126
127
  if (process.env.NODE_ENV !== 'production') {
127
- console.warn('[Taro Warning] 若要使用 MutationObserver,请在 Taro 编译配置中设置 \'mini.enableMutationObserver: true\'');
128
+ console.warn('[Taro Warning] 若要使用 MutationObserver,请在 Taro 编译配置中设置 \'mini.runtime.enableMutationObserver: true\'');
128
129
  }
129
130
  this.core = {
130
131
  observe: shared.noop,
@@ -198,15 +199,15 @@ function isHasExtractProp(el) {
198
199
  */
199
200
  function isParentBinded(node, type) {
200
201
  var _a;
201
- let res = false;
202
- while ((node === null || node === void 0 ? void 0 : node.parentElement) && node.parentElement._path !== ROOT_STR) {
203
- if ((_a = node.parentElement.__handlers[type]) === null || _a === void 0 ? void 0 : _a.length) {
204
- res = true;
205
- break;
202
+ while ((node = (node === null || node === void 0 ? void 0 : node.parentElement) || null)) {
203
+ if (!node || node.nodeName === ROOT_STR || node.nodeName === 'root-portal') {
204
+ return false;
205
+ }
206
+ else if ((_a = node.__handlers[type]) === null || _a === void 0 ? void 0 : _a.length) {
207
+ return true;
206
208
  }
207
- node = node.parentElement;
208
209
  }
209
- return res;
210
+ return false;
210
211
  }
211
212
  function shortcutAttr(key) {
212
213
  switch (key) {
@@ -236,6 +237,9 @@ function getComponentsAlias() {
236
237
  }
237
238
  return componentsAlias$1;
238
239
  }
240
+ function convertNumber2PX(value) {
241
+ return value + 'px';
242
+ }
239
243
 
240
244
  class ClassList {
241
245
  constructor(className, el) {
@@ -357,14 +361,10 @@ let componentsAlias;
357
361
  */
358
362
  function hydrate(node) {
359
363
  var _a;
360
- if (!componentsAlias) {
361
- // 初始化 componentsAlias
362
- componentsAlias = getComponentsAlias();
363
- }
364
- if (!SPECIAL_NODES) {
365
- // 初始化 SPECIAL_NODES
366
- SPECIAL_NODES = shared.hooks.call('getSpecialNodes');
367
- }
364
+ // 初始化 componentsAlias
365
+ componentsAlias || (componentsAlias = getComponentsAlias());
366
+ // 初始化 SPECIAL_NODES
367
+ SPECIAL_NODES || (SPECIAL_NODES = shared.hooks.call('getSpecialNodes'));
368
368
  const nodeName = node.nodeName;
369
369
  if (isText(node)) {
370
370
  return {
@@ -393,22 +393,19 @@ function hydrate(node) {
393
393
  prop !== CLASS &&
394
394
  prop !== STYLE &&
395
395
  prop !== ID &&
396
- propInCamelCase !== CATCHMOVE) {
396
+ propInCamelCase !== CATCHMOVE &&
397
+ propInCamelCase !== COMPILE_MODE) {
397
398
  data[propInCamelCase] = props[prop];
398
399
  }
399
400
  if (nodeName === VIEW && propInCamelCase === CATCHMOVE && props[prop] !== false) {
400
401
  data["nn" /* Shortcuts.NodeName */] = CATCH_VIEW;
401
402
  }
403
+ if (propInCamelCase === COMPILE_MODE) {
404
+ data["nn" /* Shortcuts.NodeName */] = props[prop];
405
+ }
402
406
  }
403
- let { childNodes } = node;
404
- // 过滤 comment 节点
405
- childNodes = childNodes.filter(node => !isComment(node));
406
- if (childNodes.length > 0) {
407
- data["cn" /* Shortcuts.Childnodes */] = childNodes.map(hydrate);
408
- }
409
- else {
410
- data["cn" /* Shortcuts.Childnodes */] = [];
411
- }
407
+ // Children
408
+ data["cn" /* Shortcuts.Childnodes */] = node.childNodes.filter(node => !isComment(node)).map(hydrate);
412
409
  if (node.className !== '') {
413
410
  data["cl" /* Shortcuts.Class */] = node.className;
414
411
  }
@@ -416,7 +413,7 @@ function hydrate(node) {
416
413
  if (cssText !== '' && nodeName !== 'swiper-item') {
417
414
  data["st" /* Shortcuts.Style */] = cssText;
418
415
  }
419
- shared.hooks.call('modifyHydrateData', data);
416
+ shared.hooks.call('modifyHydrateData', data, node);
420
417
  const nn = data["nn" /* Shortcuts.NodeName */];
421
418
  const componentAlias = componentsAlias[nn];
422
419
  if (componentAlias) {
@@ -428,7 +425,8 @@ function hydrate(node) {
428
425
  }
429
426
  }
430
427
  }
431
- return data;
428
+ const resData = shared.hooks.call('transferHydrateData', data, node, componentAlias);
429
+ return resData || data;
432
430
  }
433
431
 
434
432
  class TaroEventTarget {
@@ -1426,9 +1424,6 @@ class TaroElement extends TaroNode {
1426
1424
  if (event._stop) {
1427
1425
  this._stopPropagation(event);
1428
1426
  }
1429
- else {
1430
- event._stop = true;
1431
- }
1432
1427
  return listeners != null;
1433
1428
  }
1434
1429
  addEventListener(type, handler, options) {
@@ -1439,6 +1434,7 @@ class TaroElement extends TaroNode {
1439
1434
  sideEffect = false;
1440
1435
  delete options.sideEffect;
1441
1436
  }
1437
+ shared.hooks.call('modifyAddEventListener', this, sideEffect, getComponentsAlias);
1442
1438
  if (sideEffect !== false && !this.isAnyEventBinded() && SPECIAL_NODES.indexOf(name) > -1) {
1443
1439
  const componentsAlias = getComponentsAlias();
1444
1440
  const alias = componentsAlias[name]._num;
@@ -1453,6 +1449,7 @@ class TaroElement extends TaroNode {
1453
1449
  super.removeEventListener(type, handler);
1454
1450
  const name = this.nodeName;
1455
1451
  const SPECIAL_NODES = shared.hooks.call('getSpecialNodes');
1452
+ shared.hooks.call('modifyRemoveEventListener', this, sideEffect, getComponentsAlias);
1456
1453
  if (sideEffect !== false && !this.isAnyEventBinded() && SPECIAL_NODES.indexOf(name) > -1) {
1457
1454
  const componentsAlias = getComponentsAlias();
1458
1455
  const value = isHasExtractProp(this) ? `static-${name}` : `pure-${name}`;
@@ -1505,6 +1502,8 @@ options.html = {
1505
1502
  renderHTMLTag: false
1506
1503
  };
1507
1504
 
1505
+ process.env.TARO_ENV === 'harmony';
1506
+
1508
1507
  // Taro 事件对象。以 Web 标准的事件对象为基础,加入小程序事件对象中携带的部分信息,并模拟实现事件冒泡。
1509
1508
  class TaroEvent {
1510
1509
  constructor(type, opts, event) {
@@ -2310,6 +2309,17 @@ class AnchorElement extends TaroElement {
2310
2309
  }
2311
2310
  }
2312
2311
 
2312
+ class TransferElement extends TaroElement {
2313
+ constructor(dataName) {
2314
+ super();
2315
+ this.dataName = dataName;
2316
+ this.isTransferElement = true;
2317
+ }
2318
+ get _path() {
2319
+ return this.dataName;
2320
+ }
2321
+ }
2322
+
2313
2323
  class TaroDocument extends TaroElement {
2314
2324
  constructor() {
2315
2325
  super();
@@ -2330,6 +2340,10 @@ class TaroDocument extends TaroElement {
2330
2340
  case nodeName === A:
2331
2341
  element = new AnchorElement();
2332
2342
  break;
2343
+ case nodeName === 'page-meta':
2344
+ case nodeName === 'navigation-bar':
2345
+ element = new TransferElement(shared.toCamelCase(nodeName));
2346
+ break;
2333
2347
  default:
2334
2348
  element = new TaroElement();
2335
2349
  break;
@@ -3189,7 +3203,7 @@ function createRecursiveComponentConfig(componentName) {
3189
3203
  }
3190
3204
  }
3191
3205
  : shared.EMPTY_OBJ;
3192
- return Object.assign({ properties: {
3206
+ return shared.hooks.call('modifyRecursiveComponentConfig', Object.assign({ properties: {
3193
3207
  i: {
3194
3208
  type: Object,
3195
3209
  value: {
@@ -3205,7 +3219,7 @@ function createRecursiveComponentConfig(componentName) {
3205
3219
  virtualHost: !isCustomWrapper
3206
3220
  }, methods: {
3207
3221
  eh: eventHandler
3208
- } }, lifeCycles);
3222
+ } }, lifeCycles), { isCustomWrapper });
3209
3223
  }
3210
3224
 
3211
3225
  const TIMEOUT = 100;
@@ -3264,6 +3278,7 @@ exports.CATCH_VIEW = CATCH_VIEW;
3264
3278
  exports.CHANGE = CHANGE;
3265
3279
  exports.CLASS = CLASS;
3266
3280
  exports.COMMENT = COMMENT;
3281
+ exports.COMPILE_MODE = COMPILE_MODE;
3267
3282
  exports.CONFIRM = CONFIRM;
3268
3283
  exports.CONTAINER = CONTAINER;
3269
3284
  exports.CURRENT_TARGET = CURRENT_TARGET;
@@ -3320,14 +3335,18 @@ exports.VALUE = VALUE;
3320
3335
  exports.VIEW = VIEW;
3321
3336
  exports.addLeadingSlash = addLeadingSlash;
3322
3337
  exports.cancelAnimationFrame = _caf;
3338
+ exports.convertNumber2PX = convertNumber2PX;
3323
3339
  exports.createComponentConfig = createComponentConfig;
3324
3340
  exports.createEvent = createEvent;
3325
3341
  exports.createPageConfig = createPageConfig;
3326
3342
  exports.createRecursiveComponentConfig = createRecursiveComponentConfig;
3343
+ exports.customWrapperCache = customWrapperCache;
3327
3344
  exports.env = env;
3328
3345
  exports.eventCenter = eventCenter;
3329
3346
  exports.eventHandler = eventHandler;
3330
3347
  exports.eventSource = eventSource;
3348
+ exports.extend = extend;
3349
+ exports.getComponentsAlias = getComponentsAlias;
3331
3350
  exports.getComputedStyle = getComputedStyle;
3332
3351
  exports.getCurrentInstance = getCurrentInstance;
3333
3352
  exports.getOnHideEventKey = getOnHideEventKey;
@@ -3339,6 +3358,11 @@ exports.history = history;
3339
3358
  exports.hydrate = hydrate;
3340
3359
  exports.incrementId = incrementId;
3341
3360
  exports.injectPageInstance = injectPageInstance;
3361
+ exports.isComment = isComment;
3362
+ exports.isElement = isElement;
3363
+ exports.isHasExtractProp = isHasExtractProp;
3364
+ exports.isParentBinded = isParentBinded;
3365
+ exports.isText = isText;
3342
3366
  exports.location = location;
3343
3367
  exports.navigator = nav;
3344
3368
  exports.nextTick = nextTick;
@@ -3347,4 +3371,5 @@ exports.parseUrl = parseUrl;
3347
3371
  exports.removePageInstance = removePageInstance;
3348
3372
  exports.requestAnimationFrame = _raf;
3349
3373
  exports.safeExecute = safeExecute;
3374
+ exports.shortcutAttr = shortcutAttr;
3350
3375
  exports.stringify = stringify;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/runtime",
3
- "version": "3.7.0-alpha.25",
3
+ "version": "3.7.0-alpha.27",
4
4
  "description": "taro runtime for mini apps.",
5
5
  "main:h5": "dist/runtime.h5.js",
6
6
  "main": "dist/runtime.esm.js",
@@ -20,10 +20,10 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "lodash-es": "4.17.21",
23
- "@tarojs/shared": "3.7.0-alpha.25"
23
+ "@tarojs/shared": "3.7.0-alpha.27"
24
24
  },
25
25
  "devDependencies": {
26
- "@rollup/plugin-buble": "^0.21.3",
26
+ "@rollup/plugin-buble": "^1.0.3",
27
27
  "@rollup/plugin-replace": "^5.0.2",
28
28
  "@rollup/plugin-typescript": "^11.1.0",
29
29
  "@vue/runtime-core": "3.2.41",
@@ -37,7 +37,7 @@
37
37
  "typescript": "^4.7.4"
38
38
  },
39
39
  "scripts": {
40
- "prebuild": "rimraf ./dist",
40
+ "prebuild": "rimraf --impl=move-remove ./dist",
41
41
  "build": "pnpm run rollup",
42
42
  "dev": "pnpm run rollup --environment TARGET:esm -w",
43
43
  "rollup": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs",