@tarojs/taro-h5 3.3.9 → 3.3.13

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.cjs.js CHANGED
@@ -919,7 +919,11 @@ function createBrowserHistory(b) {
919
919
 
920
920
  function x(c, a) {
921
921
  void 0 === a && (a = null);
922
- return C(_extends({}, q, "string" === typeof c ? J(c) : c, {
922
+ return C(_extends({
923
+ pathname: q.pathname,
924
+ hash: "",
925
+ search: ""
926
+ }, "string" === typeof c ? J(c) : c, {
923
927
  state: a,
924
928
  key: H()
925
929
  }));
@@ -1102,7 +1106,11 @@ function createHashHistory(b) {
1102
1106
 
1103
1107
  function z(a, e) {
1104
1108
  void 0 === e && (e = null);
1105
- return C(_extends({}, d, "string" === typeof a ? J(a) : a, {
1109
+ return C(_extends({
1110
+ pathname: d.pathname,
1111
+ hash: "",
1112
+ search: ""
1113
+ }, "string" === typeof a ? J(a) : a, {
1106
1114
  state: e,
1107
1115
  key: H()
1108
1116
  }));
@@ -1244,7 +1252,7 @@ function setHistoryMode(mode) {
1244
1252
  }
1245
1253
  }
1246
1254
 
1247
- function parsePath() {
1255
+ function prependBasename() {
1248
1256
  var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
1249
1257
  return basename.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
1250
1258
  }
@@ -1286,65 +1294,98 @@ var throttle = function throttle(fn, threshold) {
1286
1294
  };
1287
1295
  };
1288
1296
 
1289
- function processNavigateUrl(option) {
1290
- var url = option.url;
1291
- var matches = option.url.match(/[?&?].*/);
1292
- var parameters = '';
1297
+ var stripBasename = function stripBasename(path, basename) {
1298
+ return path.startsWith(basename) ? path.replace(basename, '') : path;
1299
+ };
1293
1300
 
1294
- if (matches && matches.length) {
1295
- parameters = matches[0];
1296
- url = url.replace(parameters, '');
1297
- }
1301
+ var isTabBar = function isTabBar(config) {
1302
+ var _a, _b;
1303
+
1304
+ var _config$router = config.router,
1305
+ _config$router$custom = _config$router.customRoutes,
1306
+ customRoutes = _config$router$custom === void 0 ? {} : _config$router$custom,
1307
+ _config$router$basena = _config$router.basename,
1308
+ basename = _config$router$basena === void 0 ? '' : _config$router$basena,
1309
+ pathname = _config$router.pathname;
1310
+ var routePath = stripBasename(pathname, basename);
1311
+ var pagePath = ((_a = Object.entries(customRoutes).find(function (_ref) {
1312
+ var _ref2 = _slicedToArray(_ref, 2),
1313
+ target = _ref2[1];
1314
+
1315
+ return target === routePath;
1316
+ })) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
1317
+ return !!pagePath && (((_b = config.tabBar) === null || _b === void 0 ? void 0 : _b.list) || []).some(function (t) {
1318
+ return t.pagePath === pagePath;
1319
+ });
1320
+ };
1321
+
1322
+ function processNavigateUrl(option) {
1323
+ var pathPieces = J(option.url); // 处理自定义路由
1298
1324
 
1299
1325
  Object.keys(routesAlias).forEach(function (key) {
1300
- if (addLeadingSlash(key) === addLeadingSlash(url)) {
1301
- option.url = routesAlias[key] + parameters;
1326
+ if (addLeadingSlash(key) === addLeadingSlash(pathPieces.pathname)) {
1327
+ pathPieces.pathname = routesAlias[key];
1302
1328
  }
1303
- });
1304
- }
1329
+ }); // 处理 basename
1305
1330
 
1306
- function navigate(option, method) {
1307
- var success = option.success,
1308
- complete = option.complete,
1309
- fail = option.fail;
1310
- var failReason;
1331
+ pathPieces.pathname = prependBasename(pathPieces.pathname); // hack fix history v5 bug: https://github.com/remix-run/history/issues/814
1311
1332
 
1312
- if (option.url) {
1313
- processNavigateUrl(option);
1314
- }
1333
+ if (!pathPieces.search) pathPieces.search = '';
1334
+ return pathPieces;
1335
+ }
1315
1336
 
1316
- try {
1317
- if (method === 'navigateTo') {
1318
- exports.history.push(parsePath(option.url), {
1319
- timestamp: Date.now()
1320
- });
1321
- } else if (method === 'redirectTo') {
1322
- exports.history.replace(parsePath(option.url), {
1323
- timestamp: Date.now()
1324
- });
1325
- } else if (method === 'navigateBack') {
1326
- setHistoryBackDelta(option.delta);
1327
- exports.history.go(-option.delta);
1328
- }
1329
- } catch (error) {
1330
- failReason = error;
1331
- }
1337
+ function navigate(_x, _x2) {
1338
+ return _navigate.apply(this, arguments);
1339
+ }
1332
1340
 
1333
- return new Promise(function (resolve, reject) {
1334
- if (failReason) {
1335
- fail && fail(failReason);
1336
- complete && complete();
1337
- reject(failReason);
1338
- return;
1339
- }
1341
+ function _navigate() {
1342
+ _navigate = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(option, method) {
1343
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
1344
+ while (1) {
1345
+ switch (_context2.prev = _context2.next) {
1346
+ case 0:
1347
+ return _context2.abrupt("return", new Promise(function (resolve, reject) {
1348
+ var success = option.success,
1349
+ complete = option.complete,
1350
+ fail = option.fail;
1351
+ var unListen = exports.history.listen(function () {
1352
+ success === null || success === void 0 ? void 0 : success();
1353
+ complete === null || complete === void 0 ? void 0 : complete();
1354
+ resolve();
1355
+ unListen();
1356
+ });
1340
1357
 
1341
- var unlisten = exports.history.listen(function () {
1342
- success && success();
1343
- complete && complete();
1344
- resolve();
1345
- unlisten();
1346
- });
1347
- });
1358
+ try {
1359
+ if ('url' in option) {
1360
+ var pathPieces = processNavigateUrl(option);
1361
+ var state = {
1362
+ timestamp: Date.now()
1363
+ };
1364
+
1365
+ if (method === 'navigateTo') {
1366
+ exports.history.push(pathPieces, state);
1367
+ } else if (method === 'redirectTo') {
1368
+ exports.history.replace(pathPieces, state);
1369
+ }
1370
+ } else if (method === 'navigateBack') {
1371
+ setHistoryBackDelta(option.delta);
1372
+ exports.history.go(-option.delta);
1373
+ }
1374
+ } catch (error) {
1375
+ fail === null || fail === void 0 ? void 0 : fail(error);
1376
+ complete === null || complete === void 0 ? void 0 : complete();
1377
+ reject(error);
1378
+ }
1379
+ }));
1380
+
1381
+ case 1:
1382
+ case "end":
1383
+ return _context2.stop();
1384
+ }
1385
+ }
1386
+ }, _callee2);
1387
+ }));
1388
+ return _navigate.apply(this, arguments);
1348
1389
  }
1349
1390
 
1350
1391
  function navigateTo(option) {
@@ -1368,10 +1409,12 @@ function navigateBack() {
1368
1409
  }
1369
1410
 
1370
1411
  function switchTab(option) {
1371
- return navigateTo(option);
1412
+ // TODO: 清除掉所有的栈去目标页面
1413
+ return redirectTo(option);
1372
1414
  }
1373
1415
 
1374
1416
  function reLaunch(option) {
1417
+ // TODO: 清除掉所有的栈去目标页面
1375
1418
  return redirectTo(option);
1376
1419
  }
1377
1420
 
@@ -2043,6 +2086,10 @@ function initTabbar(config) {
2043
2086
  tabbar.conf.customRoutes = {};
2044
2087
  }
2045
2088
 
2089
+ if (typeof routerConfig.basename !== 'undefined') {
2090
+ tabbar.conf.basename = routerConfig.basename;
2091
+ }
2092
+
2046
2093
  var container = document.getElementById('container'); // eslint-disable-next-line no-unused-expressions
2047
2094
 
2048
2095
  container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
@@ -2812,14 +2859,14 @@ function createRouter(app, config, framework) {
2812
2859
  });
2813
2860
  app.onLaunch();
2814
2861
  var render = throttle( /*#__PURE__*/function () {
2815
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref) {
2816
- var location, action, _a, _b, _c, _d, element, pageConfig, enablePullDownRefresh, shouldLoad, delta, prevIndex, prev, el, _config, pathname, page;
2862
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref3) {
2863
+ var location, action, _a, _b, _c, _d, element, pageConfig, enablePullDownRefresh, shouldLoad, delta, prevIndex, prev, pathname, _prevIndex, _prev, el, loadConfig, _pathname, routerIndex, page;
2817
2864
 
2818
2865
  return regeneratorRuntime.wrap(function _callee$(_context) {
2819
2866
  while (1) {
2820
2867
  switch (_context.prev = _context.next) {
2821
2868
  case 0:
2822
- location = _ref.location, action = _ref.action;
2869
+ location = _ref3.location, action = _ref3.action;
2823
2870
  routerConfig.router.pathname = location.pathname;
2824
2871
  _context.prev = 2;
2825
2872
  _context.next = 5;
@@ -2875,45 +2922,96 @@ function createRouter(app, config, framework) {
2875
2922
 
2876
2923
  shouldLoad = false;
2877
2924
 
2878
- if (action === 'POP') {
2879
- unloadPage(runtime.Current.page);
2880
- delta = historyBackDelta;
2925
+ if (!(action === 'POP')) {
2926
+ _context.next = 32;
2927
+ break;
2928
+ }
2881
2929
 
2882
- while (delta-- > 1) {
2883
- unloadPage(stacks.slice(-1)[0]);
2884
- } // 最终必须重置为 1
2930
+ unloadPage(runtime.Current.page);
2931
+ delta = historyBackDelta;
2885
2932
 
2933
+ while (delta-- > 1) {
2934
+ unloadPage(stacks.slice(-1)[0]);
2935
+ } // 最终必须重置为 1
2886
2936
 
2887
- setHistoryBackDelta(1);
2888
- prevIndex = stacks.reduceRight(function (p, s, i) {
2889
- if (p !== 0) return p;else if (s.path === location.pathname + runtime.stringify(qs(i))) return i;else return 0;
2890
- }, 0);
2891
- prev = stacks[prevIndex];
2892
2937
 
2893
- if (prev) {
2894
- showPage(prev, pageConfig, prevIndex);
2895
- } else {
2896
- shouldLoad = true;
2897
- }
2898
- } else if (action === 'PUSH') {
2899
- hidePage(runtime.Current.page);
2900
- shouldLoad = true;
2901
- } else if (action === 'REPLACE') {
2902
- unloadPage(runtime.Current.page);
2938
+ setHistoryBackDelta(1);
2939
+ prevIndex = stacks.reduceRight(function (p, s, i) {
2940
+ if (p !== 0) return p;else if (s.path === location.pathname + runtime.stringify(qs(i))) return i;else return 0;
2941
+ }, 0);
2942
+ prev = stacks[prevIndex];
2943
+
2944
+ if (prev) {
2945
+ showPage(prev, pageConfig, prevIndex);
2946
+ } else {
2903
2947
  shouldLoad = true;
2904
2948
  }
2905
2949
 
2950
+ _context.next = 49;
2951
+ break;
2952
+
2953
+ case 32:
2954
+ if (!(action === 'PUSH')) {
2955
+ _context.next = 37;
2956
+ break;
2957
+ }
2958
+
2959
+ hidePage(runtime.Current.page);
2960
+ shouldLoad = true;
2961
+ _context.next = 49;
2962
+ break;
2963
+
2964
+ case 37:
2965
+ if (!(action === 'REPLACE')) {
2966
+ _context.next = 49;
2967
+ break;
2968
+ }
2969
+
2970
+ if (!isTabBar(config)) {
2971
+ _context.next = 47;
2972
+ break;
2973
+ }
2974
+
2975
+ hidePage(runtime.Current.page);
2976
+ pathname = stripBasename(config.router.pathname, basename);
2977
+ _prevIndex = stacks.findIndex(function (r) {
2978
+ var _a;
2979
+
2980
+ return ((_a = r.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) === pathname;
2981
+ });
2982
+
2983
+ if (!(_prevIndex > -1)) {
2984
+ _context.next = 45;
2985
+ break;
2986
+ }
2987
+
2988
+ // tabbar 页且之前出现过,直接复用
2989
+ _prev = stacks[_prevIndex];
2990
+ return _context.abrupt("return", showPage(_prev, pageConfig, _prevIndex));
2991
+
2992
+ case 45:
2993
+ _context.next = 48;
2994
+ break;
2995
+
2996
+ case 47:
2997
+ unloadPage(runtime.Current.page);
2998
+
2999
+ case 48:
3000
+ shouldLoad = true;
3001
+
3002
+ case 49:
2906
3003
  if (shouldLoad) {
2907
3004
  el = (_c = element["default"]) !== null && _c !== void 0 ? _c : element;
2908
- _config = Object.assign({}, pageConfig);
2909
- delete _config['path'];
2910
- delete _config['load'];
2911
- pathname = basename ? location.pathname.replace(basename, '') : location.pathname;
2912
- page = runtime.createPageConfig(enablePullDownRefresh ? (_d = runtimeHooks.createPullDownComponent) === null || _d === void 0 ? void 0 : _d.call(runtimeHooks, el, location.pathname, framework, routerConfig.PullDownRefresh) : el, pathname + runtime.stringify(qs(stacks.length)), {}, _config);
2913
- loadPage(page, pageConfig, stacks.length);
3005
+ loadConfig = Object.assign({}, pageConfig);
3006
+ delete loadConfig['path'];
3007
+ delete loadConfig['load'];
3008
+ _pathname = stripBasename(config.router.pathname, basename);
3009
+ routerIndex = stacks.length;
3010
+ page = runtime.createPageConfig(enablePullDownRefresh ? (_d = runtimeHooks.createPullDownComponent) === null || _d === void 0 ? void 0 : _d.call(runtimeHooks, el, location.pathname, framework, routerConfig.PullDownRefresh) : el, _pathname + runtime.stringify(qs(routerIndex)), {}, loadConfig);
3011
+ loadPage(page, pageConfig, routerIndex);
2914
3012
  }
2915
3013
 
2916
- case 24:
3014
+ case 50:
2917
3015
  case "end":
2918
3016
  return _context.stop();
2919
3017
  }
@@ -2921,13 +3019,13 @@ function createRouter(app, config, framework) {
2921
3019
  }, _callee, null, [[2, 8]]);
2922
3020
  }));
2923
3021
 
2924
- return function (_x) {
2925
- return _ref2.apply(this, arguments);
3022
+ return function (_x3) {
3023
+ return _ref4.apply(this, arguments);
2926
3024
  };
2927
3025
  }(), 500);
2928
3026
 
2929
3027
  if (exports.history.location.pathname === '/') {
2930
- exports.history.replace(parsePath(routes[0].path + exports.history.location.search));
3028
+ exports.history.replace(prependBasename(routes[0].path + exports.history.location.search));
2931
3029
  }
2932
3030
 
2933
3031
  render({
@@ -3276,7 +3374,7 @@ var initPxTransform = getInitPxTransform$1(taro);
3276
3374
  var requirePlugin = permanentlyNotSupport('requirePlugin');
3277
3375
 
3278
3376
  var getApp = function getApp() {
3279
- return taro._$app;
3377
+ return getCurrentInstance().app;
3280
3378
  };
3281
3379
 
3282
3380
  var pxTransform = function pxTransform(size) {
@@ -6291,11 +6389,14 @@ function _previewImage() {
6291
6389
  function loadImage(url, fail) {
6292
6390
  return new Promise(function (resolve) {
6293
6391
  var item = document.createElement('taro-swiper-item-core');
6294
- item.style.cssText = "\n display: flex;\n align-items: center;\n justify-content: center;\n ";
6392
+ item.style.cssText = "\n display: flex;\n align-items: start;\n justify-content: center;\n overflow-y: scroll;\n ";
6295
6393
  var image = new Image();
6296
6394
  image.style.maxWidth = '100%';
6297
6395
  image.src = url;
6298
- item.appendChild(image); // Note: 等待图片加载完后返回,会导致轮播被卡住
6396
+ var div = document.createElement('div');
6397
+ div.style.cssText = "\n display: flex;\n align-items: center;\n justify-content: center;\n max-width: 100%;\n min-height: 100%;\n ";
6398
+ div.appendChild(image);
6399
+ item.appendChild(div); // Note: 等待图片加载完后返回,会导致轮播被卡住
6299
6400
 
6300
6401
  resolve(item);
6301
6402
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/taro-h5",
3
- "version": "3.3.9",
3
+ "version": "3.3.13",
4
4
  "description": "Taro h5 framework",
5
5
  "main:h5": "src/index.js",
6
6
  "main": "dist/index.cjs.js",
@@ -33,9 +33,9 @@
33
33
  "author": "O2Team",
34
34
  "license": "MIT",
35
35
  "dependencies": {
36
- "@tarojs/api": "3.3.9",
37
- "@tarojs/router": "3.3.9",
38
- "@tarojs/runtime": "3.3.9",
36
+ "@tarojs/api": "3.3.13",
37
+ "@tarojs/router": "3.3.13",
38
+ "@tarojs/runtime": "3.3.13",
39
39
  "base64-js": "^1.3.0",
40
40
  "jsonp-retry": "^1.0.3",
41
41
  "mobile-detect": "^1.4.2",
@@ -45,5 +45,5 @@
45
45
  "devDependencies": {
46
46
  "jest-fetch-mock": "^3.0.3"
47
47
  },
48
- "gitHead": "dfea7ab7ac6f5abb8bb344595eadc0993d752eae"
48
+ "gitHead": "d84177a97cc27c01ca63c9dd07e5ab5bbaa91d8a"
49
49
  }
@@ -1,4 +1,3 @@
1
-
2
1
  /**
3
2
  * 在新页面中全屏预览图片。预览的过程中用户可以进行保存图片、发送给朋友等操作。
4
3
  * @param {Object} options
@@ -67,13 +66,23 @@ function loadImage (url, fail) {
67
66
  const item = document.createElement('taro-swiper-item-core')
68
67
  item.style.cssText = `
69
68
  display: flex;
70
- align-items: center;
69
+ align-items: start;
71
70
  justify-content: center;
71
+ overflow-y: scroll;
72
72
  `
73
73
  const image = new Image()
74
74
  image.style.maxWidth = '100%'
75
75
  image.src = url
76
- item.appendChild(image)
76
+ const div = document.createElement('div')
77
+ div.style.cssText = `
78
+ display: flex;
79
+ align-items: center;
80
+ justify-content: center;
81
+ max-width: 100%;
82
+ min-height: 100%;
83
+ `
84
+ div.appendChild(image)
85
+ item.appendChild(div)
77
86
  // Note: 等待图片加载完后返回,会导致轮播被卡住
78
87
  resolve(item)
79
88
  if (typeof fail === 'function') {
package/src/taro/index.js CHANGED
@@ -85,7 +85,7 @@ const initPxTransform = getInitPxTransform(taro)
85
85
 
86
86
  const requirePlugin = permanentlyNotSupport('requirePlugin')
87
87
  const getApp = function () {
88
- return taro._$app
88
+ return getCurrentInstance().app
89
89
  }
90
90
 
91
91
  const pxTransform = function (size) {