@tarojs/router 3.7.0-canary.0 → 3.7.0-canary.2

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/api.js CHANGED
@@ -65,7 +65,12 @@ function navigate(option, method) {
65
65
  }
66
66
  else if (method === 'navigateBack') {
67
67
  stacks.delta = option.delta;
68
- history.go(-option.delta);
68
+ if (stacks.length > option.delta) {
69
+ history.go(-option.delta);
70
+ }
71
+ else {
72
+ history.go(1 - stacks.length);
73
+ }
69
74
  }
70
75
  }
71
76
  catch (error) {
package/dist/index.cjs.js CHANGED
@@ -41,65 +41,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
41
41
  });
42
42
  }
43
43
 
44
- // export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
45
- // export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
46
- const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
47
- const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
48
- const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
49
- const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
50
- const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
51
- var _a;
52
- const routePath = addLeadingSlash(stripBasename(path, basename));
53
- const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
54
- return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
55
- };
56
- const getCurrentPage = (routerMode = 'hash', basename = '/') => {
57
- const pagePath = routerMode === 'hash'
58
- ? location.hash.slice(1).split('?')[0]
59
- : location.pathname;
60
- return addLeadingSlash(stripBasename(pagePath, basename));
61
- };
62
- class RoutesAlias {
63
- constructor() {
64
- this.conf = [];
65
- this.getConfig = (url = '') => {
66
- const customRoute = this.conf.filter((arr) => {
67
- return arr.includes(url);
68
- });
69
- return customRoute[0];
70
- };
71
- this.getOrigin = (url = '') => {
72
- var _a;
73
- return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[0]) || url;
74
- };
75
- this.getAlias = (url = '') => {
76
- var _a;
77
- return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[1]) || url;
78
- };
79
- this.getAll = (url = '') => {
80
- return this.conf
81
- .filter((arr) => arr.includes(url))
82
- .reduceRight((p, a) => {
83
- p.unshift(a[1]);
84
- return p;
85
- }, []);
86
- };
87
- }
88
- set(customRoutes = {}) {
89
- for (let key in customRoutes) {
90
- const path = customRoutes[key];
91
- key = addLeadingSlash(key);
92
- if (typeof path === 'string') {
93
- this.conf.push([key, addLeadingSlash(path)]);
94
- }
95
- else if ((path === null || path === void 0 ? void 0 : path.length) > 0) {
96
- this.conf.push(...path.map(p => [key, addLeadingSlash(p)]));
97
- }
98
- }
99
- }
100
- }
101
- const routesAlias = new RoutesAlias();
102
-
103
44
  class RouterConfig {
104
45
  static set config(e) {
105
46
  this.__config = e;
@@ -118,7 +59,7 @@ class RouterConfig {
118
59
  }
119
60
  static get customRoutes() { return this.router.customRoutes || {}; }
120
61
  static isPage(url = '') {
121
- return this.pages.findIndex(e => addLeadingSlash(e) === url) !== -1;
62
+ return this.pages.findIndex(e => prependBasename(e) === url) !== -1;
122
63
  }
123
64
  }
124
65
 
@@ -302,6 +243,65 @@ class Stacks {
302
243
  }
303
244
  const stacks = new Stacks();
304
245
 
246
+ // export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
247
+ // export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
248
+ const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
249
+ const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
250
+ const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
251
+ const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
252
+ const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
253
+ var _a;
254
+ const routePath = addLeadingSlash(stripBasename(path, basename));
255
+ const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
256
+ return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
257
+ };
258
+ const getCurrentPage = (routerMode = 'hash', basename = '/') => {
259
+ const pagePath = routerMode === 'hash'
260
+ ? location.hash.slice(1).split('?')[0]
261
+ : location.pathname;
262
+ return addLeadingSlash(stripBasename(pagePath, basename));
263
+ };
264
+ class RoutesAlias {
265
+ constructor() {
266
+ this.conf = [];
267
+ this.getConfig = (url = '') => {
268
+ const customRoute = this.conf.filter((arr) => {
269
+ return arr.includes(url);
270
+ });
271
+ return customRoute[0];
272
+ };
273
+ this.getOrigin = (url = '') => {
274
+ var _a;
275
+ return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[0]) || url;
276
+ };
277
+ this.getAlias = (url = '') => {
278
+ var _a;
279
+ return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[1]) || url;
280
+ };
281
+ this.getAll = (url = '') => {
282
+ return this.conf
283
+ .filter((arr) => arr.includes(url))
284
+ .reduceRight((p, a) => {
285
+ p.unshift(a[1]);
286
+ return p;
287
+ }, []);
288
+ };
289
+ }
290
+ set(customRoutes = {}) {
291
+ for (let key in customRoutes) {
292
+ const path = customRoutes[key];
293
+ key = addLeadingSlash(key);
294
+ if (typeof path === 'string') {
295
+ this.conf.push([key, addLeadingSlash(path)]);
296
+ }
297
+ else if ((path === null || path === void 0 ? void 0 : path.length) > 0) {
298
+ this.conf.push(...path.map(p => [key, addLeadingSlash(p)]));
299
+ }
300
+ }
301
+ }
302
+ }
303
+ const routesAlias = new RoutesAlias();
304
+
305
305
  function processNavigateUrl(option) {
306
306
  var _a;
307
307
  const pathPieces = history.parsePath(option.url);
@@ -355,7 +355,12 @@ function navigate(option, method) {
355
355
  }
356
356
  else if (method === 'navigateBack') {
357
357
  stacks.delta = option.delta;
358
- exports.history.go(-option.delta);
358
+ if (stacks.length > option.delta) {
359
+ exports.history.go(-option.delta);
360
+ }
361
+ else {
362
+ exports.history.go(1 - stacks.length);
363
+ }
359
364
  }
360
365
  }
361
366
  catch (error) {
@@ -477,7 +482,7 @@ function getOffset() {
477
482
  */
478
483
  function loadAnimateStyle(ms = 300) {
479
484
  const css = `
480
- .taro_router .taro_page {
485
+ .taro_router > .taro_page {
481
486
  position: absolute;
482
487
  left: 0;
483
488
  top: 0;
@@ -489,14 +494,15 @@ function loadAnimateStyle(ms = 300) {
489
494
  z-index: 0;
490
495
  }
491
496
 
492
- .taro_router .taro_page.taro_tabbar_page,
493
- .taro_router .taro_page.taro_page_show.taro_page_stationed {
497
+ .taro_router > .taro_page.taro_tabbar_page,
498
+ .taro_router > .taro_page.taro_page_show.taro_page_stationed {
494
499
  transform: none;
495
500
  }
496
501
 
497
- .taro_router .taro_page.taro_page_show {
502
+ .taro_router > .taro_page.taro_page_show {
498
503
  transform: translate(0, 0);
499
- }`;
504
+ }
505
+ `;
500
506
  addStyle(css);
501
507
  }
502
508
  /**
@@ -505,15 +511,9 @@ function loadAnimateStyle(ms = 300) {
505
511
  function loadRouterStyle(usingWindowScroll) {
506
512
  const css = `
507
513
  .taro_router {
508
- overflow: hidden;
509
514
  position: relative;
510
515
  width: 100%;
511
516
  height: 100%;
512
- min-height: 100vh;
513
- }
514
-
515
- .taro-tabbar__container .taro_router {
516
- min-height: calc(100vh - 50px);
517
517
  }
518
518
 
519
519
  .taro_page {
@@ -526,12 +526,18 @@ function loadRouterStyle(usingWindowScroll) {
526
526
  `}
527
527
  }
528
528
 
529
- .taro-tabbar__container .taro-tabbar__panel {
529
+ .taro-tabbar__container > .taro-tabbar__panel {
530
530
  overflow: hidden;
531
531
  }
532
532
 
533
- .taro-tabbar__container .taro_page.taro_tabbar_page {
534
- max-height: calc(100vh - 50px);
533
+ .taro-tabbar__container > .taro-tabbar__panel > .taro_page.taro_tabbar_page {
534
+ max-height: calc(100vh - var(--taro-tabbar-height) - constant(safe-area-inset-bottom));
535
+ max-height: calc(100vh - var(--taro-tabbar-height) - env(safe-area-inset-bottom));
536
+ }
537
+
538
+ .taro_page_shade,
539
+ .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
540
+ display: none;
535
541
  }
536
542
  `;
537
543
  addStyle(css);
@@ -546,7 +552,7 @@ function addStyle(css) {
546
552
 
547
553
  // @ts-nocheck
548
554
  function initTabbar(config) {
549
- if (config.tabBar == null) {
555
+ if (config.tabBar == null || config.tabBar.custom) {
550
556
  return;
551
557
  }
552
558
  // TODO: custom-tab-bar
@@ -799,11 +805,6 @@ function createMultiRouter(app, config, framework) {
799
805
  }
800
806
 
801
807
  /* eslint-disable dot-notation */
802
- function setDisplay(el, type = '') {
803
- if (el) {
804
- el.style.display = type;
805
- }
806
- }
807
808
  class PageHandler {
808
809
  constructor(config) {
809
810
  this.defaultAnimation = { duration: 300, delay: 50 };
@@ -969,7 +970,7 @@ class PageHandler {
969
970
  const param = this.getQuery(stampId, '', page.options);
970
971
  let pageEl = this.getPageContainer(page);
971
972
  if (pageEl) {
972
- setDisplay(pageEl);
973
+ pageEl.classList.remove('taro_page_shade');
973
974
  this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
974
975
  this.addAnimation(pageEl, pageNo === 0);
975
976
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
@@ -1012,6 +1013,7 @@ class PageHandler {
1012
1013
  var _a, _b;
1013
1014
  this.unloadTimer = null;
1014
1015
  (_b = (_a = this.lastUnloadPage) === null || _a === void 0 ? void 0 : _a.onUnload) === null || _b === void 0 ? void 0 : _b.call(_a);
1016
+ runtime.eventCenter.trigger('__taroPageOnShowAfterDestroyed');
1015
1017
  }, this.animationDuration);
1016
1018
  }
1017
1019
  else {
@@ -1019,6 +1021,9 @@ class PageHandler {
1019
1021
  pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_stationed');
1020
1022
  pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_show');
1021
1023
  (_c = page === null || page === void 0 ? void 0 : page.onUnload) === null || _c === void 0 ? void 0 : _c.call(page);
1024
+ setTimeout(() => {
1025
+ runtime.eventCenter.trigger('__taroPageOnShowAfterDestroyed');
1026
+ }, 0);
1022
1027
  }
1023
1028
  if (delta >= 1)
1024
1029
  this.unload(stacks.last, delta);
@@ -1030,7 +1035,7 @@ class PageHandler {
1030
1035
  const param = this.getQuery(page['$taroParams']['stamp'], '', page.options);
1031
1036
  let pageEl = this.getPageContainer(page);
1032
1037
  if (pageEl) {
1033
- setDisplay(pageEl);
1038
+ pageEl.classList.remove('taro_page_shade');
1034
1039
  this.addAnimation(pageEl, pageNo === 0);
1035
1040
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1036
1041
  this.bindPageEvents(page, pageConfig);
@@ -1058,12 +1063,12 @@ class PageHandler {
1058
1063
  if (this.hideTimer) {
1059
1064
  clearTimeout(this.hideTimer);
1060
1065
  this.hideTimer = null;
1061
- setDisplay(this.lastHidePage, 'none');
1066
+ pageEl.classList.add('taro_page_shade');
1062
1067
  }
1063
1068
  this.lastHidePage = pageEl;
1064
1069
  this.hideTimer = setTimeout(() => {
1065
1070
  this.hideTimer = null;
1066
- setDisplay(this.lastHidePage, 'none');
1071
+ pageEl.classList.add('taro_page_shade');
1067
1072
  }, this.animationDuration + this.animationDelay);
1068
1073
  (_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
1069
1074
  }
@@ -1248,7 +1253,9 @@ function createRouter(app, config, framework) {
1248
1253
  if (currentPage !== stacks.getItem(prevIndex)) {
1249
1254
  handler.unload(currentPage, delta, prevIndex > -1);
1250
1255
  if (prevIndex > -1) {
1251
- handler.show(stacks.getItem(prevIndex), pageConfig, prevIndex);
1256
+ runtime.eventCenter.once('__taroPageOnShowAfterDestroyed', () => {
1257
+ handler.show(stacks.getItem(prevIndex), pageConfig, prevIndex);
1258
+ });
1252
1259
  }
1253
1260
  else {
1254
1261
  shouldLoad = true;