@tarojs/runtime 3.5.11 → 3.6.0-beta.1
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/bom/URLSearchParams.d.ts +14 -0
- package/dist/bom/history.d.ts +29 -0
- package/dist/bom/location.d.ts +36 -0
- package/dist/bom/window.d.ts +2 -0
- package/dist/constants/index.d.ts +9 -0
- package/dist/dom/event.d.ts +1 -0
- package/dist/dsl/instance.d.ts +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/runtime.esm.d.ts +20 -1
- package/dist/runtime.esm.js +693 -15
- package/dist/runtime.esm.js.map +1 -1
- package/dist/utils/cache.d.ts +12 -0
- package/package.json +5 -2
package/dist/runtime.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { noop, isFunction, getComponentsAlias as getComponentsAlias$1, internalComponents, EMPTY_OBJ, hooks, toCamelCase, isObject, warn, isArray, ensure, isNull, isUndefined, toDashed, isString, controlledComponent, Events } from '@tarojs/shared';
|
|
1
|
+
import { noop, isFunction, getComponentsAlias as getComponentsAlias$1, internalComponents, EMPTY_OBJ, hooks, toCamelCase, isObject, warn, isArray, ensure, isNull, isUndefined, toDashed, isString, controlledComponent, Events, isNumber } from '@tarojs/shared';
|
|
2
2
|
export { Events, hooks } from '@tarojs/shared';
|
|
3
3
|
|
|
4
4
|
const PROPERTY_THRESHOLD = 2046;
|
|
@@ -44,6 +44,16 @@ const ON_HIDE = 'onHide';
|
|
|
44
44
|
const OPTIONS = 'options';
|
|
45
45
|
const EXTERNAL_CLASSES = 'externalClasses';
|
|
46
46
|
const BEHAVIORS = 'behaviors';
|
|
47
|
+
/**
|
|
48
|
+
* 页面上下文切换时的行为
|
|
49
|
+
*/
|
|
50
|
+
var CONTEXT_ACTIONS;
|
|
51
|
+
(function (CONTEXT_ACTIONS) {
|
|
52
|
+
CONTEXT_ACTIONS["INIT"] = "0";
|
|
53
|
+
CONTEXT_ACTIONS["RECOVER"] = "1";
|
|
54
|
+
CONTEXT_ACTIONS["RESTORE"] = "2";
|
|
55
|
+
CONTEXT_ACTIONS["DESTORY"] = "3";
|
|
56
|
+
})(CONTEXT_ACTIONS || (CONTEXT_ACTIONS = {}));
|
|
47
57
|
|
|
48
58
|
const observers = [];
|
|
49
59
|
/**
|
|
@@ -2335,6 +2345,8 @@ class TaroEvent {
|
|
|
2335
2345
|
this._stop = false;
|
|
2336
2346
|
this._end = false;
|
|
2337
2347
|
this.defaultPrevented = false;
|
|
2348
|
+
// Mouse Event botton property, it's used in 3rd lib, like react-router. default 0 in general
|
|
2349
|
+
this.button = 0;
|
|
2338
2350
|
// timestamp can either be hi-res ( relative to page load) or low-res (relative to UNIX epoch)
|
|
2339
2351
|
// here use hi-res timestamp
|
|
2340
2352
|
this.timeStamp = Date.now();
|
|
@@ -2416,11 +2428,18 @@ function createEvent(event, node) {
|
|
|
2416
2428
|
const eventsBatch = {};
|
|
2417
2429
|
// 小程序的事件代理回调函数
|
|
2418
2430
|
function eventHandler(event) {
|
|
2419
|
-
var _a;
|
|
2431
|
+
var _a, _b;
|
|
2432
|
+
// Note: ohos 上事件没有设置 type、detail 类型 setter 方法,且部分事件(例如 load 等)缺失 target 导致事件错误
|
|
2433
|
+
!event.type && Object.defineProperty(event, 'type', {
|
|
2434
|
+
value: event._type // ohos only
|
|
2435
|
+
});
|
|
2436
|
+
!event.detail && Object.defineProperty(event, 'detail', {
|
|
2437
|
+
value: event._detail || Object.assign({}, event) // ohos only
|
|
2438
|
+
});
|
|
2439
|
+
event.currentTarget = event.currentTarget || event.target || Object.assign({}, event);
|
|
2420
2440
|
hooks.call('modifyMpEventImpl', event);
|
|
2421
|
-
event.currentTarget || (event.currentTarget = event.target);
|
|
2422
2441
|
const currentTarget = event.currentTarget;
|
|
2423
|
-
const id = ((_a = currentTarget.dataset) === null || _a === void 0 ? void 0 : _a.sid /** sid */) || currentTarget.id /** uid */ || '';
|
|
2442
|
+
const id = ((_a = currentTarget.dataset) === null || _a === void 0 ? void 0 : _a.sid /** sid */) || currentTarget.id /** uid */ || ((_b = event.detail) === null || _b === void 0 ? void 0 : _b.id) || '';
|
|
2424
2443
|
const node = env.document.getElementById(id);
|
|
2425
2444
|
if (node) {
|
|
2426
2445
|
const dispatch = () => {
|
|
@@ -2612,9 +2631,9 @@ class TaroRootElement extends TaroElement {
|
|
|
2612
2631
|
}
|
|
2613
2632
|
}
|
|
2614
2633
|
}
|
|
2615
|
-
const
|
|
2634
|
+
const customWrapperCount = customWrapperMap.size;
|
|
2616
2635
|
const isNeedNormalUpdate = Object.keys(normalUpdate).length > 0;
|
|
2617
|
-
const updateArrLen =
|
|
2636
|
+
const updateArrLen = customWrapperCount + (isNeedNormalUpdate ? 1 : 0);
|
|
2618
2637
|
let executeTime = 0;
|
|
2619
2638
|
const cb = () => {
|
|
2620
2639
|
if (++executeTime === updateArrLen) {
|
|
@@ -2624,7 +2643,7 @@ class TaroRootElement extends TaroElement {
|
|
|
2624
2643
|
}
|
|
2625
2644
|
};
|
|
2626
2645
|
// custom-wrapper setData
|
|
2627
|
-
if (
|
|
2646
|
+
if (customWrapperCount) {
|
|
2628
2647
|
customWrapperMap.forEach((data, ctx) => {
|
|
2629
2648
|
if (process.env.NODE_ENV !== 'production' && options.debug) {
|
|
2630
2649
|
// eslint-disable-next-line no-console
|
|
@@ -2843,8 +2862,629 @@ const _caf = typeof cancelAnimationFrame !== 'undefined' && cancelAnimationFrame
|
|
|
2843
2862
|
clearTimeout(seed);
|
|
2844
2863
|
};
|
|
2845
2864
|
|
|
2865
|
+
/******************************************************************************
|
|
2866
|
+
Copyright (c) Microsoft Corporation.
|
|
2867
|
+
|
|
2868
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
2869
|
+
purpose with or without fee is hereby granted.
|
|
2870
|
+
|
|
2871
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
2872
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
2873
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
2874
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
2875
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
2876
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
2877
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
2878
|
+
***************************************************************************** */
|
|
2879
|
+
|
|
2880
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
2881
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
2882
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
2883
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2886
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
2887
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
2888
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
2889
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
2890
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
var _URLSearchParams_dict;
|
|
2894
|
+
const findReg = /[!'()~]|%20|%00/g;
|
|
2895
|
+
const plusReg = /\+/g;
|
|
2896
|
+
const replaceCharMap = {
|
|
2897
|
+
'!': '%21',
|
|
2898
|
+
"'": '%27',
|
|
2899
|
+
'(': '%28',
|
|
2900
|
+
')': '%29',
|
|
2901
|
+
'~': '%7E',
|
|
2902
|
+
'%20': '+',
|
|
2903
|
+
'%00': '\x00',
|
|
2904
|
+
};
|
|
2905
|
+
function replacer(match) {
|
|
2906
|
+
return replaceCharMap[match];
|
|
2907
|
+
}
|
|
2908
|
+
function appendTo(dict, name, value) {
|
|
2909
|
+
const res = isArray(value) ? value.join(',') : value;
|
|
2910
|
+
if (name in dict)
|
|
2911
|
+
dict[name].push(res);
|
|
2912
|
+
else
|
|
2913
|
+
dict[name] = [res];
|
|
2914
|
+
}
|
|
2915
|
+
function addEach(value, key) {
|
|
2916
|
+
appendTo(this, key, value);
|
|
2917
|
+
}
|
|
2918
|
+
function decode(str) {
|
|
2919
|
+
return decodeURIComponent(str.replace(plusReg, ' '));
|
|
2920
|
+
}
|
|
2921
|
+
function encode(str) {
|
|
2922
|
+
return encodeURIComponent(str).replace(findReg, replacer);
|
|
2923
|
+
}
|
|
2924
|
+
class URLSearchParams {
|
|
2925
|
+
constructor(query) {
|
|
2926
|
+
_URLSearchParams_dict.set(this, Object.create(null));
|
|
2927
|
+
if (!query)
|
|
2928
|
+
return;
|
|
2929
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2930
|
+
if (typeof query === 'string') {
|
|
2931
|
+
if (query.charAt(0) === '?') {
|
|
2932
|
+
query = query.slice(1);
|
|
2933
|
+
}
|
|
2934
|
+
for (let pairs = query.split('&'), i = 0, length = pairs.length; i < length; i++) {
|
|
2935
|
+
const value = pairs[i];
|
|
2936
|
+
const index = value.indexOf('=');
|
|
2937
|
+
if (index > -1) {
|
|
2938
|
+
appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));
|
|
2939
|
+
}
|
|
2940
|
+
else if (value.length) {
|
|
2941
|
+
appendTo(dict, decode(value), '');
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
else {
|
|
2946
|
+
if (isArray(query)) {
|
|
2947
|
+
for (let i = 0, length = query.length; i < length; i++) {
|
|
2948
|
+
const value = query[i];
|
|
2949
|
+
appendTo(dict, value[0], value[1]);
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
else if (query.forEach) {
|
|
2953
|
+
query.forEach(addEach, dict);
|
|
2954
|
+
}
|
|
2955
|
+
else {
|
|
2956
|
+
for (const key in query) {
|
|
2957
|
+
appendTo(dict, key, query[key]);
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
append(name, value) {
|
|
2963
|
+
appendTo(__classPrivateFieldGet(this, _URLSearchParams_dict, "f"), name, value);
|
|
2964
|
+
}
|
|
2965
|
+
delete(name) {
|
|
2966
|
+
delete __classPrivateFieldGet(this, _URLSearchParams_dict, "f")[name];
|
|
2967
|
+
}
|
|
2968
|
+
get(name) {
|
|
2969
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2970
|
+
return name in dict ? dict[name][0] : null;
|
|
2971
|
+
}
|
|
2972
|
+
getAll(name) {
|
|
2973
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2974
|
+
return name in dict ? dict[name].slice(0) : [];
|
|
2975
|
+
}
|
|
2976
|
+
has(name) {
|
|
2977
|
+
return name in __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2978
|
+
}
|
|
2979
|
+
keys() {
|
|
2980
|
+
return Object.keys(__classPrivateFieldGet(this, _URLSearchParams_dict, "f"));
|
|
2981
|
+
}
|
|
2982
|
+
set(name, value) {
|
|
2983
|
+
__classPrivateFieldGet(this, _URLSearchParams_dict, "f")[name] = ['' + value];
|
|
2984
|
+
}
|
|
2985
|
+
forEach(callback, thisArg) {
|
|
2986
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2987
|
+
Object.getOwnPropertyNames(dict).forEach(function (name) {
|
|
2988
|
+
dict[name].forEach(function (value) {
|
|
2989
|
+
callback.call(thisArg, value, name, this);
|
|
2990
|
+
}, this);
|
|
2991
|
+
}, this);
|
|
2992
|
+
}
|
|
2993
|
+
toJSON() {
|
|
2994
|
+
return {};
|
|
2995
|
+
}
|
|
2996
|
+
toString() {
|
|
2997
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2998
|
+
const query = [];
|
|
2999
|
+
for (const key in dict) {
|
|
3000
|
+
const name = encode(key);
|
|
3001
|
+
for (let i = 0, value = dict[key]; i < value.length; i++) {
|
|
3002
|
+
query.push(name + '=' + encode(value[i]));
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
return query.join('&');
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
_URLSearchParams_dict = new WeakMap();
|
|
3009
|
+
|
|
2846
3010
|
const eventCenter = hooks.call('getEventCenter', Events);
|
|
2847
3011
|
|
|
3012
|
+
/**
|
|
3013
|
+
* 一个小型缓存池,用于在切换页面时,存储一些上下文信息
|
|
3014
|
+
*/
|
|
3015
|
+
class RuntimeCache {
|
|
3016
|
+
constructor(name) {
|
|
3017
|
+
this.cache = new Map();
|
|
3018
|
+
this.name = name;
|
|
3019
|
+
}
|
|
3020
|
+
has(identifier) {
|
|
3021
|
+
return this.cache.has(identifier);
|
|
3022
|
+
}
|
|
3023
|
+
set(identifier, ctx) {
|
|
3024
|
+
if (identifier && ctx) {
|
|
3025
|
+
this.cache.set(identifier, ctx);
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
get(identifier) {
|
|
3029
|
+
if (this.has(identifier))
|
|
3030
|
+
return this.cache.get(identifier);
|
|
3031
|
+
}
|
|
3032
|
+
delete(identifier) {
|
|
3033
|
+
this.cache.delete(identifier);
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
|
|
3037
|
+
var _History_instances, _History_location, _History_stack, _History_cur, _History_window, _History_reset;
|
|
3038
|
+
const cache$1 = new RuntimeCache('history');
|
|
3039
|
+
class History extends Events {
|
|
3040
|
+
constructor(location, options) {
|
|
3041
|
+
super();
|
|
3042
|
+
_History_instances.add(this);
|
|
3043
|
+
/* private property */
|
|
3044
|
+
_History_location.set(this, void 0);
|
|
3045
|
+
_History_stack.set(this, []);
|
|
3046
|
+
_History_cur.set(this, 0);
|
|
3047
|
+
_History_window.set(this, void 0);
|
|
3048
|
+
__classPrivateFieldSet(this, _History_window, options.window, "f");
|
|
3049
|
+
__classPrivateFieldSet(this, _History_location, location, "f");
|
|
3050
|
+
__classPrivateFieldGet(this, _History_location, "f").on('__record_history__', (href) => {
|
|
3051
|
+
var _a;
|
|
3052
|
+
__classPrivateFieldSet(this, _History_cur, (_a = __classPrivateFieldGet(this, _History_cur, "f"), _a++, _a), "f");
|
|
3053
|
+
__classPrivateFieldSet(this, _History_stack, __classPrivateFieldGet(this, _History_stack, "f").slice(0, __classPrivateFieldGet(this, _History_cur, "f")), "f");
|
|
3054
|
+
__classPrivateFieldGet(this, _History_stack, "f").push({
|
|
3055
|
+
state: null,
|
|
3056
|
+
title: '',
|
|
3057
|
+
url: href
|
|
3058
|
+
});
|
|
3059
|
+
}, null);
|
|
3060
|
+
__classPrivateFieldGet(this, _History_location, "f").on('__reset_history__', (href) => {
|
|
3061
|
+
__classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this, href);
|
|
3062
|
+
}, null);
|
|
3063
|
+
// 切换上下文行为
|
|
3064
|
+
this.on(CONTEXT_ACTIONS.INIT, () => {
|
|
3065
|
+
__classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this);
|
|
3066
|
+
}, null);
|
|
3067
|
+
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3068
|
+
cache$1.set(pageId, {
|
|
3069
|
+
location: __classPrivateFieldGet(this, _History_location, "f"),
|
|
3070
|
+
stack: __classPrivateFieldGet(this, _History_stack, "f"),
|
|
3071
|
+
cur: __classPrivateFieldGet(this, _History_cur, "f")
|
|
3072
|
+
});
|
|
3073
|
+
}, null);
|
|
3074
|
+
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
3075
|
+
if (cache$1.has(pageId)) {
|
|
3076
|
+
const ctx = cache$1.get(pageId);
|
|
3077
|
+
__classPrivateFieldSet(this, _History_location, ctx.location, "f");
|
|
3078
|
+
__classPrivateFieldSet(this, _History_stack, ctx.stack, "f");
|
|
3079
|
+
__classPrivateFieldSet(this, _History_cur, ctx.cur, "f");
|
|
3080
|
+
}
|
|
3081
|
+
}, null);
|
|
3082
|
+
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
3083
|
+
cache$1.delete(pageId);
|
|
3084
|
+
}, null);
|
|
3085
|
+
__classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this);
|
|
3086
|
+
}
|
|
3087
|
+
/* public property */
|
|
3088
|
+
get length() {
|
|
3089
|
+
return __classPrivateFieldGet(this, _History_stack, "f").length;
|
|
3090
|
+
}
|
|
3091
|
+
get state() {
|
|
3092
|
+
return __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")];
|
|
3093
|
+
}
|
|
3094
|
+
/* public method */
|
|
3095
|
+
go(delta) {
|
|
3096
|
+
if (!isNumber(delta) || isNaN(delta))
|
|
3097
|
+
return;
|
|
3098
|
+
let targetIdx = __classPrivateFieldGet(this, _History_cur, "f") + delta;
|
|
3099
|
+
targetIdx = Math.min(Math.max(targetIdx, 0), this.length - 1);
|
|
3100
|
+
__classPrivateFieldSet(this, _History_cur, targetIdx, "f");
|
|
3101
|
+
__classPrivateFieldGet(this, _History_location, "f").trigger('__set_href_without_history__', __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")].url);
|
|
3102
|
+
__classPrivateFieldGet(this, _History_window, "f").trigger('popstate', __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")]);
|
|
3103
|
+
}
|
|
3104
|
+
back() {
|
|
3105
|
+
this.go(-1);
|
|
3106
|
+
}
|
|
3107
|
+
forward() {
|
|
3108
|
+
this.go(1);
|
|
3109
|
+
}
|
|
3110
|
+
pushState(state, title, url) {
|
|
3111
|
+
if (!url || !isString(url))
|
|
3112
|
+
return;
|
|
3113
|
+
__classPrivateFieldSet(this, _History_stack, __classPrivateFieldGet(this, _History_stack, "f").slice(0, __classPrivateFieldGet(this, _History_cur, "f") + 1), "f");
|
|
3114
|
+
__classPrivateFieldGet(this, _History_stack, "f").push({
|
|
3115
|
+
state,
|
|
3116
|
+
title,
|
|
3117
|
+
url
|
|
3118
|
+
});
|
|
3119
|
+
__classPrivateFieldSet(this, _History_cur, this.length - 1, "f");
|
|
3120
|
+
__classPrivateFieldGet(this, _History_location, "f").trigger('__set_href_without_history__', url);
|
|
3121
|
+
}
|
|
3122
|
+
replaceState(state, title, url) {
|
|
3123
|
+
if (!url || !isString(url))
|
|
3124
|
+
return;
|
|
3125
|
+
__classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")] = {
|
|
3126
|
+
state,
|
|
3127
|
+
title,
|
|
3128
|
+
url
|
|
3129
|
+
};
|
|
3130
|
+
__classPrivateFieldGet(this, _History_location, "f").trigger('__set_href_without_history__', url);
|
|
3131
|
+
}
|
|
3132
|
+
// For debug
|
|
3133
|
+
get cache() {
|
|
3134
|
+
return cache$1;
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
_History_location = new WeakMap(), _History_stack = new WeakMap(), _History_cur = new WeakMap(), _History_window = new WeakMap(), _History_instances = new WeakSet(), _History_reset = function _History_reset(href = '') {
|
|
3138
|
+
__classPrivateFieldSet(this, _History_stack, [
|
|
3139
|
+
{
|
|
3140
|
+
state: null,
|
|
3141
|
+
title: '',
|
|
3142
|
+
url: href || __classPrivateFieldGet(this, _History_location, "f").href
|
|
3143
|
+
}
|
|
3144
|
+
], "f");
|
|
3145
|
+
__classPrivateFieldSet(this, _History_cur, 0, "f");
|
|
3146
|
+
};
|
|
3147
|
+
|
|
3148
|
+
const Current = {
|
|
3149
|
+
app: null,
|
|
3150
|
+
router: null,
|
|
3151
|
+
page: null
|
|
3152
|
+
};
|
|
3153
|
+
const getCurrentInstance = () => Current;
|
|
3154
|
+
|
|
3155
|
+
var _Location_instances, _Location_hash, _Location_hostname, _Location_pathname, _Location_port, _Location_protocol, _Location_search, _Location_noCheckUrl, _Location_window, _Location_reset, _Location_getPreValue, _Location_rollBack, _Location_recordHistory, _Location_checkUrlChange;
|
|
3156
|
+
const DEFAULT_HOSTNAME = 'taro.com';
|
|
3157
|
+
const cache = new RuntimeCache('location');
|
|
3158
|
+
class Location extends Events {
|
|
3159
|
+
constructor(options) {
|
|
3160
|
+
super();
|
|
3161
|
+
_Location_instances.add(this);
|
|
3162
|
+
/* private property */
|
|
3163
|
+
_Location_hash.set(this, '');
|
|
3164
|
+
_Location_hostname.set(this, DEFAULT_HOSTNAME);
|
|
3165
|
+
_Location_pathname.set(this, '/');
|
|
3166
|
+
_Location_port.set(this, '');
|
|
3167
|
+
_Location_protocol.set(this, 'https:');
|
|
3168
|
+
_Location_search.set(this, '');
|
|
3169
|
+
_Location_noCheckUrl.set(this, false);
|
|
3170
|
+
_Location_window.set(this, void 0);
|
|
3171
|
+
__classPrivateFieldSet(this, _Location_window, options.window, "f");
|
|
3172
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_reset).call(this);
|
|
3173
|
+
this.on('__set_href_without_history__', (href) => {
|
|
3174
|
+
__classPrivateFieldSet(this, _Location_noCheckUrl, true, "f");
|
|
3175
|
+
const lastHash = __classPrivateFieldGet(this, _Location_hash, "f");
|
|
3176
|
+
this.href = generateFullUrl(href);
|
|
3177
|
+
if (lastHash !== __classPrivateFieldGet(this, _Location_hash, "f")) {
|
|
3178
|
+
__classPrivateFieldGet(this, _Location_window, "f").trigger('hashchange');
|
|
3179
|
+
}
|
|
3180
|
+
__classPrivateFieldSet(this, _Location_noCheckUrl, false, "f");
|
|
3181
|
+
}, null);
|
|
3182
|
+
// 切换上下文行为
|
|
3183
|
+
this.on(CONTEXT_ACTIONS.INIT, () => {
|
|
3184
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_reset).call(this);
|
|
3185
|
+
}, null);
|
|
3186
|
+
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3187
|
+
cache.set(pageId, {
|
|
3188
|
+
lastHref: this.href
|
|
3189
|
+
});
|
|
3190
|
+
}, null);
|
|
3191
|
+
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
3192
|
+
// 数据恢复时,不需要执行跳转
|
|
3193
|
+
if (cache.has(pageId)) {
|
|
3194
|
+
const ctx = cache.get(pageId);
|
|
3195
|
+
__classPrivateFieldSet(this, _Location_noCheckUrl, true, "f");
|
|
3196
|
+
this.href = ctx.lastHref;
|
|
3197
|
+
__classPrivateFieldSet(this, _Location_noCheckUrl, false, "f");
|
|
3198
|
+
}
|
|
3199
|
+
}, null);
|
|
3200
|
+
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
3201
|
+
cache.delete(pageId);
|
|
3202
|
+
}, null);
|
|
3203
|
+
}
|
|
3204
|
+
/* public property */
|
|
3205
|
+
get protocol() {
|
|
3206
|
+
return __classPrivateFieldGet(this, _Location_protocol, "f");
|
|
3207
|
+
}
|
|
3208
|
+
set protocol(val) {
|
|
3209
|
+
const reg = /^(http|https):?$/i;
|
|
3210
|
+
if (!val || !isString(val) || !reg.test(val.trim()))
|
|
3211
|
+
return;
|
|
3212
|
+
val = val.trim();
|
|
3213
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3214
|
+
__classPrivateFieldSet(this, _Location_protocol, val.endsWith(':') ? val : `${val}:`, "f");
|
|
3215
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3216
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3217
|
+
}
|
|
3218
|
+
get host() {
|
|
3219
|
+
return (__classPrivateFieldGet(this, _Location_hostname, "f") || '') + (__classPrivateFieldGet(this, _Location_port, "f") ? ':' + __classPrivateFieldGet(this, _Location_port, "f") : '');
|
|
3220
|
+
}
|
|
3221
|
+
set host(val) {
|
|
3222
|
+
if (!val || !isString(val))
|
|
3223
|
+
return;
|
|
3224
|
+
val = val.trim();
|
|
3225
|
+
const { hostname, port } = parseUrl(`//${val}`);
|
|
3226
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3227
|
+
__classPrivateFieldSet(this, _Location_hostname, hostname, "f");
|
|
3228
|
+
__classPrivateFieldSet(this, _Location_port, port, "f");
|
|
3229
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3230
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3231
|
+
}
|
|
3232
|
+
get hostname() {
|
|
3233
|
+
return __classPrivateFieldGet(this, _Location_hostname, "f");
|
|
3234
|
+
}
|
|
3235
|
+
set hostname(val) {
|
|
3236
|
+
if (!val || !isString(val))
|
|
3237
|
+
return;
|
|
3238
|
+
val = val.trim();
|
|
3239
|
+
const { hostname } = parseUrl(`//${val}`);
|
|
3240
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3241
|
+
__classPrivateFieldSet(this, _Location_hostname, hostname, "f");
|
|
3242
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3243
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3244
|
+
}
|
|
3245
|
+
get port() {
|
|
3246
|
+
return __classPrivateFieldGet(this, _Location_port, "f");
|
|
3247
|
+
}
|
|
3248
|
+
set port(val) {
|
|
3249
|
+
const xVal = Number((val = val.trim()));
|
|
3250
|
+
if (!isNumber(xVal) || xVal <= 0)
|
|
3251
|
+
return;
|
|
3252
|
+
if (val === __classPrivateFieldGet(this, _Location_port, "f"))
|
|
3253
|
+
return;
|
|
3254
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3255
|
+
__classPrivateFieldSet(this, _Location_port, val, "f");
|
|
3256
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3257
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3258
|
+
}
|
|
3259
|
+
get pathname() {
|
|
3260
|
+
return __classPrivateFieldGet(this, _Location_pathname, "f");
|
|
3261
|
+
}
|
|
3262
|
+
set pathname(val) {
|
|
3263
|
+
if (!val || !isString(val))
|
|
3264
|
+
return;
|
|
3265
|
+
val = val.trim();
|
|
3266
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3267
|
+
let newPathName = '';
|
|
3268
|
+
if (val.startsWith('/')) {
|
|
3269
|
+
newPathName = __classPrivateFieldGet(this, _Location_pathname, "f") + val;
|
|
3270
|
+
}
|
|
3271
|
+
else if (val.startsWith('./')) {
|
|
3272
|
+
val = val.replace(/\.\//, '/');
|
|
3273
|
+
newPathName = __classPrivateFieldGet(this, _Location_pathname, "f") + val;
|
|
3274
|
+
}
|
|
3275
|
+
else if (val.startsWith('../')) {
|
|
3276
|
+
newPathName = resolveRelativePath(val, preValue.pathname);
|
|
3277
|
+
}
|
|
3278
|
+
const { pathname, search, hash } = parseUrl(`//${DEFAULT_HOSTNAME}${newPathName}`);
|
|
3279
|
+
__classPrivateFieldSet(this, _Location_pathname, pathname, "f");
|
|
3280
|
+
__classPrivateFieldSet(this, _Location_search, search, "f");
|
|
3281
|
+
__classPrivateFieldSet(this, _Location_hash, hash, "f");
|
|
3282
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3283
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3284
|
+
}
|
|
3285
|
+
get search() {
|
|
3286
|
+
return __classPrivateFieldGet(this, _Location_search, "f");
|
|
3287
|
+
}
|
|
3288
|
+
set search(val) {
|
|
3289
|
+
if (!val || !isString(val))
|
|
3290
|
+
return;
|
|
3291
|
+
val = val.trim();
|
|
3292
|
+
val = val.startsWith('?') ? val : `?${val}`;
|
|
3293
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3294
|
+
const { search } = parseUrl(`//${DEFAULT_HOSTNAME}${val}`);
|
|
3295
|
+
__classPrivateFieldSet(this, _Location_search, search, "f");
|
|
3296
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3297
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3298
|
+
}
|
|
3299
|
+
get hash() {
|
|
3300
|
+
return __classPrivateFieldGet(this, _Location_hash, "f");
|
|
3301
|
+
}
|
|
3302
|
+
// 小程序的navigateTo存在截断hash字符串的问题
|
|
3303
|
+
set hash(val) {
|
|
3304
|
+
if (!val || !isString(val))
|
|
3305
|
+
return;
|
|
3306
|
+
val = val.trim();
|
|
3307
|
+
val = val.startsWith('#') ? val : `#${val}`;
|
|
3308
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3309
|
+
const { hash } = parseUrl(`//${DEFAULT_HOSTNAME}${val}`);
|
|
3310
|
+
__classPrivateFieldSet(this, _Location_hash, hash, "f");
|
|
3311
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3312
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3313
|
+
}
|
|
3314
|
+
get href() {
|
|
3315
|
+
return `${__classPrivateFieldGet(this, _Location_protocol, "f")}//${this.host}${__classPrivateFieldGet(this, _Location_pathname, "f")}${__classPrivateFieldGet(this, _Location_search, "f")}${__classPrivateFieldGet(this, _Location_hash, "f")}`;
|
|
3316
|
+
}
|
|
3317
|
+
set href(val) {
|
|
3318
|
+
const reg = /^(http:|https:)?\/\/.+/;
|
|
3319
|
+
if (!val || !isString(val) || !reg.test((val = val.trim())))
|
|
3320
|
+
return;
|
|
3321
|
+
const { protocol, hostname, port, hash, search, pathname } = parseUrl(val);
|
|
3322
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3323
|
+
__classPrivateFieldSet(this, _Location_protocol, protocol, "f");
|
|
3324
|
+
__classPrivateFieldSet(this, _Location_hostname, hostname, "f");
|
|
3325
|
+
__classPrivateFieldSet(this, _Location_port, port, "f");
|
|
3326
|
+
__classPrivateFieldSet(this, _Location_pathname, pathname, "f");
|
|
3327
|
+
__classPrivateFieldSet(this, _Location_search, search, "f");
|
|
3328
|
+
__classPrivateFieldSet(this, _Location_hash, hash, "f");
|
|
3329
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3330
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3331
|
+
}
|
|
3332
|
+
get origin() {
|
|
3333
|
+
return `${__classPrivateFieldGet(this, _Location_protocol, "f")}//${this.host}`;
|
|
3334
|
+
}
|
|
3335
|
+
set origin(val) {
|
|
3336
|
+
const reg = /^(http:|https:)?\/\/.+/;
|
|
3337
|
+
if (!val || !isString(val) || !reg.test((val = val.trim())))
|
|
3338
|
+
return;
|
|
3339
|
+
const { protocol, hostname, port } = parseUrl(val);
|
|
3340
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3341
|
+
__classPrivateFieldSet(this, _Location_protocol, protocol, "f");
|
|
3342
|
+
__classPrivateFieldSet(this, _Location_hostname, hostname, "f");
|
|
3343
|
+
__classPrivateFieldSet(this, _Location_port, port, "f");
|
|
3344
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3345
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3346
|
+
}
|
|
3347
|
+
/* public method */
|
|
3348
|
+
assign() {
|
|
3349
|
+
warn(true, '小程序环境中调用location.assign()无效.');
|
|
3350
|
+
}
|
|
3351
|
+
reload() {
|
|
3352
|
+
warn(true, '小程序环境中调用location.reload()无效.');
|
|
3353
|
+
}
|
|
3354
|
+
replace(val) {
|
|
3355
|
+
this.trigger('__set_href_without_history__', val);
|
|
3356
|
+
}
|
|
3357
|
+
toString() {
|
|
3358
|
+
return this.href;
|
|
3359
|
+
}
|
|
3360
|
+
// For debug
|
|
3361
|
+
get cache() {
|
|
3362
|
+
return cache;
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
_Location_hash = new WeakMap(), _Location_hostname = new WeakMap(), _Location_pathname = new WeakMap(), _Location_port = new WeakMap(), _Location_protocol = new WeakMap(), _Location_search = new WeakMap(), _Location_noCheckUrl = new WeakMap(), _Location_window = new WeakMap(), _Location_instances = new WeakSet(), _Location_reset = function _Location_reset() {
|
|
3366
|
+
const Current = getCurrentInstance();
|
|
3367
|
+
const router = Current.router;
|
|
3368
|
+
if (router) {
|
|
3369
|
+
const { path, params } = router;
|
|
3370
|
+
const searchArr = Object.keys(params).map(key => {
|
|
3371
|
+
return `${key}=${params[key]}`;
|
|
3372
|
+
});
|
|
3373
|
+
const searchStr = searchArr.length > 0 ? '?' + searchArr.join('&') : '';
|
|
3374
|
+
const url = `https://${DEFAULT_HOSTNAME}${path.startsWith('/') ? path : '/' + path}${searchStr}`;
|
|
3375
|
+
// 初始化页面链接时,默认pathname为 "/"
|
|
3376
|
+
// const url = `https://${DEFAULT_HOSTNAME}${searchStr}`
|
|
3377
|
+
const { protocol, hostname, port, pathname, search, hash } = parseUrl(url);
|
|
3378
|
+
__classPrivateFieldSet(this, _Location_protocol, protocol, "f");
|
|
3379
|
+
__classPrivateFieldSet(this, _Location_hostname, hostname, "f");
|
|
3380
|
+
__classPrivateFieldSet(this, _Location_port, port, "f");
|
|
3381
|
+
__classPrivateFieldSet(this, _Location_pathname, pathname, "f");
|
|
3382
|
+
__classPrivateFieldSet(this, _Location_search, search, "f");
|
|
3383
|
+
__classPrivateFieldSet(this, _Location_hash, hash, "f");
|
|
3384
|
+
this.trigger('__reset_history__', this.href);
|
|
3385
|
+
}
|
|
3386
|
+
}, _Location_getPreValue = function _Location_getPreValue() {
|
|
3387
|
+
return {
|
|
3388
|
+
protocol: __classPrivateFieldGet(this, _Location_protocol, "f"),
|
|
3389
|
+
hostname: __classPrivateFieldGet(this, _Location_hostname, "f"),
|
|
3390
|
+
port: __classPrivateFieldGet(this, _Location_port, "f"),
|
|
3391
|
+
pathname: __classPrivateFieldGet(this, _Location_pathname, "f"),
|
|
3392
|
+
search: __classPrivateFieldGet(this, _Location_search, "f"),
|
|
3393
|
+
hash: __classPrivateFieldGet(this, _Location_hash, "f")
|
|
3394
|
+
};
|
|
3395
|
+
}, _Location_rollBack = function _Location_rollBack(preValue) {
|
|
3396
|
+
__classPrivateFieldSet(this, _Location_protocol, preValue.protocol, "f");
|
|
3397
|
+
__classPrivateFieldSet(this, _Location_hostname, preValue.hostname, "f");
|
|
3398
|
+
__classPrivateFieldSet(this, _Location_port, preValue.port, "f");
|
|
3399
|
+
__classPrivateFieldSet(this, _Location_pathname, preValue.pathname, "f");
|
|
3400
|
+
__classPrivateFieldSet(this, _Location_search, preValue.search, "f");
|
|
3401
|
+
__classPrivateFieldSet(this, _Location_hash, preValue.hash, "f");
|
|
3402
|
+
}, _Location_recordHistory = function _Location_recordHistory() {
|
|
3403
|
+
this.trigger('__record_history__', this.href);
|
|
3404
|
+
}, _Location_checkUrlChange = function _Location_checkUrlChange(preValue) {
|
|
3405
|
+
if (__classPrivateFieldGet(this, _Location_noCheckUrl, "f")) {
|
|
3406
|
+
return false;
|
|
3407
|
+
}
|
|
3408
|
+
// 跨域三要素不允许修改
|
|
3409
|
+
if (__classPrivateFieldGet(this, _Location_protocol, "f") !== preValue.protocol || __classPrivateFieldGet(this, _Location_hostname, "f") !== preValue.hostname || this.port !== preValue.port) {
|
|
3410
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue);
|
|
3411
|
+
return false;
|
|
3412
|
+
}
|
|
3413
|
+
// pathname
|
|
3414
|
+
if (__classPrivateFieldGet(this, _Location_pathname, "f") !== preValue.pathname) {
|
|
3415
|
+
return true;
|
|
3416
|
+
}
|
|
3417
|
+
// search
|
|
3418
|
+
if (__classPrivateFieldGet(this, _Location_search, "f") !== preValue.search) {
|
|
3419
|
+
return true;
|
|
3420
|
+
}
|
|
3421
|
+
// hashchange
|
|
3422
|
+
if (__classPrivateFieldGet(this, _Location_hash, "f") !== preValue.hash) {
|
|
3423
|
+
__classPrivateFieldGet(this, _Location_window, "f").trigger('hashchange');
|
|
3424
|
+
return true;
|
|
3425
|
+
}
|
|
3426
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue);
|
|
3427
|
+
return false;
|
|
3428
|
+
};
|
|
3429
|
+
function resolveRelativePath(path, relative) {
|
|
3430
|
+
const relativeArr = relative.split('/');
|
|
3431
|
+
const parent = relativeArr.slice(0, relativeArr.length - 1);
|
|
3432
|
+
let depth = 0;
|
|
3433
|
+
const dests = path.split('../').map(v => {
|
|
3434
|
+
v === '' && depth++;
|
|
3435
|
+
return v;
|
|
3436
|
+
});
|
|
3437
|
+
if (depth > parent.length)
|
|
3438
|
+
return relative;
|
|
3439
|
+
return parent.slice(0, parent.length - depth).concat(dests.filter(v => v !== '')).join('/');
|
|
3440
|
+
}
|
|
3441
|
+
function generateFullUrl(val = '') {
|
|
3442
|
+
const origin = `https://${DEFAULT_HOSTNAME}`;
|
|
3443
|
+
if (val.startsWith('/')) {
|
|
3444
|
+
return origin + val;
|
|
3445
|
+
}
|
|
3446
|
+
if (val.startsWith('?')) {
|
|
3447
|
+
return origin + val;
|
|
3448
|
+
}
|
|
3449
|
+
if (val.startsWith('#')) {
|
|
3450
|
+
return origin + val;
|
|
3451
|
+
}
|
|
3452
|
+
if (/(https?:)?\/\//.test(val)) {
|
|
3453
|
+
return val;
|
|
3454
|
+
}
|
|
3455
|
+
return val;
|
|
3456
|
+
}
|
|
3457
|
+
function parseUrl(url = '') {
|
|
3458
|
+
const result = {
|
|
3459
|
+
href: '',
|
|
3460
|
+
origin: '',
|
|
3461
|
+
protocol: '',
|
|
3462
|
+
hostname: '',
|
|
3463
|
+
host: '',
|
|
3464
|
+
port: '',
|
|
3465
|
+
pathname: '',
|
|
3466
|
+
search: '',
|
|
3467
|
+
hash: ''
|
|
3468
|
+
};
|
|
3469
|
+
if (!url || !isString(url))
|
|
3470
|
+
return result;
|
|
3471
|
+
url = url.trim();
|
|
3472
|
+
const PATTERN = /^(([^:/?#]+):)?\/\/(([^/?#]+):(.+)@)?([^/?#:]*)(:(\d+))?([^?#]*)(\?([^#]*))?(#(.*))?/;
|
|
3473
|
+
const matches = url.match(PATTERN);
|
|
3474
|
+
if (!matches)
|
|
3475
|
+
return result;
|
|
3476
|
+
result.protocol = matches[1] || 'https:';
|
|
3477
|
+
result.hostname = matches[6] || DEFAULT_HOSTNAME;
|
|
3478
|
+
result.port = matches[8] || '';
|
|
3479
|
+
result.pathname = matches[9] || '/';
|
|
3480
|
+
result.search = matches[10] || '';
|
|
3481
|
+
result.hash = matches[12] || '';
|
|
3482
|
+
result.href = url;
|
|
3483
|
+
result.origin = result.protocol + '//' + result.hostname;
|
|
3484
|
+
result.host = result.hostname + (result.port ? `:${result.port}` : '');
|
|
3485
|
+
return result;
|
|
3486
|
+
}
|
|
3487
|
+
|
|
2848
3488
|
let window$1;
|
|
2849
3489
|
if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
2850
3490
|
class Window extends Events {
|
|
@@ -2866,6 +3506,33 @@ if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
|
2866
3506
|
}
|
|
2867
3507
|
});
|
|
2868
3508
|
this.Date || (this.Date = Date);
|
|
3509
|
+
// 应用启动时,提供给需要读取历史信息的库使用
|
|
3510
|
+
this.location = new Location({ window: this });
|
|
3511
|
+
this.history = new History(this.location, { window: this });
|
|
3512
|
+
this.initEvent();
|
|
3513
|
+
}
|
|
3514
|
+
initEvent() {
|
|
3515
|
+
const _location = this.location;
|
|
3516
|
+
const _history = this.history;
|
|
3517
|
+
this.on(CONTEXT_ACTIONS.INIT, (pageId) => {
|
|
3518
|
+
// 页面onload,为该页面建立新的上下文信息
|
|
3519
|
+
_location.trigger(CONTEXT_ACTIONS.INIT, pageId);
|
|
3520
|
+
}, null);
|
|
3521
|
+
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
3522
|
+
// 页面onshow,恢复当前页面的上下文信息
|
|
3523
|
+
_location.trigger(CONTEXT_ACTIONS.RECOVER, pageId);
|
|
3524
|
+
_history.trigger(CONTEXT_ACTIONS.RECOVER, pageId);
|
|
3525
|
+
}, null);
|
|
3526
|
+
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3527
|
+
// 页面onhide,缓存当前页面的上下文信息
|
|
3528
|
+
_location.trigger(CONTEXT_ACTIONS.RESTORE, pageId);
|
|
3529
|
+
_history.trigger(CONTEXT_ACTIONS.RESTORE, pageId);
|
|
3530
|
+
}, null);
|
|
3531
|
+
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
3532
|
+
// 页面onunload,清除当前页面的上下文信息
|
|
3533
|
+
_location.trigger(CONTEXT_ACTIONS.DESTORY, pageId);
|
|
3534
|
+
_history.trigger(CONTEXT_ACTIONS.DESTORY, pageId);
|
|
3535
|
+
}, null);
|
|
2869
3536
|
}
|
|
2870
3537
|
get document() {
|
|
2871
3538
|
return env.document;
|
|
@@ -2892,18 +3559,13 @@ if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
|
2892
3559
|
else {
|
|
2893
3560
|
window$1 = env.window;
|
|
2894
3561
|
}
|
|
3562
|
+
const location = window$1.location;
|
|
3563
|
+
const history = window$1.history;
|
|
2895
3564
|
|
|
2896
3565
|
// for Vue3
|
|
2897
3566
|
class SVGElement extends TaroElement {
|
|
2898
3567
|
}
|
|
2899
3568
|
|
|
2900
|
-
const Current = {
|
|
2901
|
-
app: null,
|
|
2902
|
-
router: null,
|
|
2903
|
-
page: null
|
|
2904
|
-
};
|
|
2905
|
-
const getCurrentInstance = () => Current;
|
|
2906
|
-
|
|
2907
3569
|
/* eslint-disable dot-notation */
|
|
2908
3570
|
const instances = new Map();
|
|
2909
3571
|
const pageId = incrementId();
|
|
@@ -3005,6 +3667,10 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3005
3667
|
this.$taroParams = uniqueOptions;
|
|
3006
3668
|
}
|
|
3007
3669
|
setCurrentRouter(this);
|
|
3670
|
+
// 初始化当前页面的上下文信息
|
|
3671
|
+
if (process.env.TARO_ENV !== 'h5') {
|
|
3672
|
+
window$1.trigger(CONTEXT_ACTIONS.INIT, $taroPath);
|
|
3673
|
+
}
|
|
3008
3674
|
const mount = () => {
|
|
3009
3675
|
Current.app.mount(component, $taroPath, () => {
|
|
3010
3676
|
pageElement = env.document.getElementById($taroPath);
|
|
@@ -3029,6 +3695,10 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3029
3695
|
},
|
|
3030
3696
|
[ONUNLOAD]() {
|
|
3031
3697
|
const $taroPath = this.$taroPath;
|
|
3698
|
+
// 销毁当前页面的上下文信息
|
|
3699
|
+
if (process.env.TARO_ENV !== 'h5') {
|
|
3700
|
+
window$1.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath);
|
|
3701
|
+
}
|
|
3032
3702
|
// 触发onUnload生命周期
|
|
3033
3703
|
safeExecute($taroPath, ONUNLOAD);
|
|
3034
3704
|
unmounting = true;
|
|
@@ -3057,6 +3727,10 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3057
3727
|
// 设置 Current 的 page 和 router
|
|
3058
3728
|
Current.page = this;
|
|
3059
3729
|
setCurrentRouter(this);
|
|
3730
|
+
// 恢复上下文信息
|
|
3731
|
+
if (process.env.TARO_ENV !== 'h5') {
|
|
3732
|
+
window$1.trigger(CONTEXT_ACTIONS.RECOVER, this.$taroPath);
|
|
3733
|
+
}
|
|
3060
3734
|
// 触发生命周期
|
|
3061
3735
|
safeExecute(this.$taroPath, ON_SHOW, options);
|
|
3062
3736
|
// 通过事件触发子组件的生命周期
|
|
@@ -3064,6 +3738,10 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3064
3738
|
});
|
|
3065
3739
|
},
|
|
3066
3740
|
[ONHIDE]() {
|
|
3741
|
+
// 缓存当前页面上下文信息
|
|
3742
|
+
if (process.env.TARO_ENV !== 'h5') {
|
|
3743
|
+
window$1.trigger(CONTEXT_ACTIONS.RESTORE, this.$taroPath);
|
|
3744
|
+
}
|
|
3067
3745
|
// 设置 Current 的 page 和 router
|
|
3068
3746
|
if (Current.page === this) {
|
|
3069
3747
|
Current.page = null;
|
|
@@ -3221,5 +3899,5 @@ const nextTick = (cb, ctx) => {
|
|
|
3221
3899
|
}
|
|
3222
3900
|
};
|
|
3223
3901
|
|
|
3224
|
-
export { Current, FormElement, MutationObserver, SVGElement, Style, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, addLeadingSlash, _caf as cancelAnimationFrame, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, document$1 as document, eventCenter, eventHandler, eventSource, getComputedStyle, getCurrentInstance, getPageInstance, hydrate, incrementId, injectPageInstance, nav as navigator, nextTick, now, options, removePageInstance, _raf as requestAnimationFrame, safeExecute, stringify, window$1 as window };
|
|
3902
|
+
export { Current, FormElement, MutationObserver, SVGElement, Style, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, URLSearchParams, addLeadingSlash, _caf as cancelAnimationFrame, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, document$1 as document, eventCenter, eventHandler, eventSource, getComputedStyle, getCurrentInstance, getPageInstance, history, hydrate, incrementId, injectPageInstance, location, nav as navigator, nextTick, now, options, removePageInstance, _raf as requestAnimationFrame, safeExecute, stringify, window$1 as window };
|
|
3225
3903
|
//# sourceMappingURL=runtime.esm.js.map
|