@tarojs/router 3.6.22-alpha.5 → 3.6.22

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.esm.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { createBrowserHistory, createHashHistory, Action, parsePath } from 'history';
2
2
  import { Current, incrementId, eventCenter, createPageConfig, hooks, stringify, requestAnimationFrame as requestAnimationFrame$1 } from '@tarojs/runtime';
3
- import MobileDetect from 'mobile-detect';
4
3
  import queryString from 'query-string';
5
4
  import { defineCustomElementTaroTabbar } from '@tarojs/components/dist/components';
6
5
  import { initTabBarApis } from '@tarojs/taro';
@@ -388,15 +387,9 @@ function getCurrentPages() {
388
387
  return pages.map(e => { var _a; return (Object.assign(Object.assign({}, e), { route: ((_a = e.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) || '' })); });
389
388
  }
390
389
 
391
- let md;
392
390
  let preTitle = document.title;
393
391
  let isLoadDdEntry = false;
394
- function getMobileDetect() {
395
- if (!md) {
396
- md = new MobileDetect(navigator.userAgent);
397
- }
398
- return md;
399
- }
392
+ const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
400
393
  function setTitle(title) {
401
394
  return __awaiter(this, void 0, void 0, function* () {
402
395
  if (preTitle === title)
@@ -414,10 +407,6 @@ function setTitle(title) {
414
407
  return title;
415
408
  });
416
409
  }
417
- function isDingTalk() {
418
- const md = getMobileDetect();
419
- return md.match(/DingTalk/ig);
420
- }
421
410
 
422
411
  let pageResizeFn;
423
412
  function bindPageResize(page) {
@@ -618,6 +607,14 @@ class MultiPageHandler {
618
607
  : {};
619
608
  return Object.assign(Object.assign({}, query), options);
620
609
  }
610
+ isDefaultNavigationStyle() {
611
+ var _a, _b;
612
+ let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
613
+ if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
614
+ style = this.pageConfig.navigationStyle;
615
+ }
616
+ return style !== 'custom';
617
+ }
621
618
  mount() {
622
619
  setHistoryMode(this.routerMode, this.router.basename);
623
620
  loadRouterStyle(this.usingWindowScroll);
@@ -680,10 +677,13 @@ class MultiPageHandler {
680
677
  return;
681
678
  (_a = page.onLoad) === null || _a === void 0 ? void 0 : _a.call(page, this.getQuery('', page.options), () => {
682
679
  var _a;
680
+ const pageEl = this.getPageContainer(page);
683
681
  if (this.isTabBar) {
684
- const pageEl = this.getPageContainer(page);
685
682
  pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page');
686
683
  }
684
+ if (this.isDefaultNavigationStyle()) {
685
+ pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page');
686
+ }
687
687
  this.onReady(page, true);
688
688
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
689
689
  this.bindPageEvents(page, pageConfig);
@@ -842,6 +842,14 @@ class PageHandler {
842
842
  })) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
843
843
  return !!pagePath && this.tabBarList.some(t => stripTrailing(t.pagePath) === pagePath);
844
844
  }
845
+ isDefaultNavigationStyle() {
846
+ var _a, _b;
847
+ let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
848
+ if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
849
+ style = this.pageConfig.navigationStyle;
850
+ }
851
+ return style !== 'custom';
852
+ }
845
853
  isSamePage(page) {
846
854
  const routePath = stripBasename(this.pathname, this.basename);
847
855
  const pagePath = stripBasename(page === null || page === void 0 ? void 0 : page.path, this.basename);
@@ -948,19 +956,22 @@ class PageHandler {
948
956
  if (pageEl) {
949
957
  pageEl.classList.remove('taro_page_shade');
950
958
  this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
959
+ this.isDefaultNavigationStyle() && pageEl.classList.add('taro_navigation_page');
951
960
  this.addAnimation(pageEl, pageNo === 0);
952
961
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
953
962
  this.bindPageEvents(page, pageConfig);
954
963
  this.triggerRouterChange();
955
964
  }
956
965
  else {
966
+ // FIXME 在 iOS 端快速切换页面时,可能不会执行回调注入对应类名导致 TabBar 白屏
957
967
  (_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
958
968
  var _a;
959
969
  pageEl = this.getPageContainer(page);
960
970
  this.isTabBar(this.pathname) && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page'));
971
+ this.isDefaultNavigationStyle() && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page'));
961
972
  this.addAnimation(pageEl, pageNo === 0);
962
- this.onReady(page, true);
963
973
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
974
+ this.onReady(page, true);
964
975
  this.bindPageEvents(page, pageConfig);
965
976
  this.triggerRouterChange();
966
977
  });
@@ -1022,8 +1033,8 @@ class PageHandler {
1022
1033
  var _a;
1023
1034
  pageEl = this.getPageContainer(page);
1024
1035
  this.addAnimation(pageEl, pageNo === 0);
1025
- this.onReady(page, false);
1026
1036
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1037
+ this.onReady(page, false);
1027
1038
  this.bindPageEvents(page, pageConfig);
1028
1039
  this.triggerRouterChange();
1029
1040
  });
@@ -1139,7 +1150,7 @@ function createRouter(app, config, framework) {
1139
1150
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1140
1151
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
1141
1152
  const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
1142
- var _c, _d, _e, _f, _g, _h;
1153
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l;
1143
1154
  handler.pathname = decodeURI(location.pathname);
1144
1155
  if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
1145
1156
  window.scrollTo(0, 0);
@@ -1168,22 +1179,35 @@ function createRouter(app, config, framework) {
1168
1179
  window.location.reload();
1169
1180
  }
1170
1181
  else {
1171
- throw new Error(error);
1182
+ throw error;
1172
1183
  }
1173
1184
  }
1174
1185
  if (!element)
1175
1186
  return;
1176
1187
  const pageConfig = handler.pageConfig;
1177
1188
  let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
1189
+ let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
1190
+ let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
1191
+ let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
1178
1192
  if (pageConfig) {
1179
- setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
1193
+ setTitle((_j = pageConfig.navigationBarTitleText) !== null && _j !== void 0 ? _j : document.title);
1180
1194
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
1181
1195
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
1182
1196
  }
1197
+ if (typeof pageConfig.navigationStyle === 'string') {
1198
+ navigationStyle = pageConfig.navigationStyle;
1199
+ }
1200
+ if (typeof pageConfig.navigationBarTextStyle === 'string') {
1201
+ navigationBarTextStyle = pageConfig.navigationBarTextStyle;
1202
+ }
1203
+ if (typeof pageConfig.navigationBarBackgroundColor === 'string') {
1204
+ navigationBarBackgroundColor = pageConfig.navigationBarBackgroundColor;
1205
+ }
1183
1206
  }
1207
+ eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
1184
1208
  const currentPage = Current.page;
1185
1209
  const pathname = handler.pathname;
1186
- const methodName = (_g = stacks.method) !== null && _g !== void 0 ? _g : '';
1210
+ const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
1187
1211
  const cacheTabs = stacks.getTabs();
1188
1212
  let shouldLoad = false;
1189
1213
  stacks.method = '';
@@ -1249,7 +1273,7 @@ function createRouter(app, config, framework) {
1249
1273
  shouldLoad = true;
1250
1274
  }
1251
1275
  if (shouldLoad || stacks.length < 1) {
1252
- const el = (_h = element.default) !== null && _h !== void 0 ? _h : element;
1276
+ const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
1253
1277
  const loadConfig = Object.assign({}, pageConfig);
1254
1278
  const stacksIndex = stacks.length;
1255
1279
  delete loadConfig['path'];