@tarojs/runtime 3.3.17 → 3.4.0-beta.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/bom/raf.d.ts +1 -2
- package/dist/bom/window.d.ts +1 -18
- package/dist/constants/identifiers.d.ts +32 -0
- package/dist/constants/index.d.ts +7 -0
- package/dist/container/default-hooks.d.ts +2 -0
- package/dist/container/store.d.ts +15 -0
- package/dist/dom/document.d.ts +2 -5
- package/dist/dom/element.d.ts +2 -6
- package/dist/dom/event-source.d.ts +6 -1
- package/dist/dom/event-target.d.ts +1 -2
- package/dist/dom/node.d.ts +44 -12
- package/dist/dom/root.d.ts +2 -9
- package/dist/dom/text.d.ts +5 -5
- package/dist/dom-external/element.d.ts +2 -1
- package/dist/dom-external/mutation-observer/implements.d.ts +52 -0
- package/dist/dom-external/mutation-observer/index.d.ts +12 -0
- package/dist/dom-external/mutation-observer/record.d.ts +24 -0
- package/dist/dom-external/node.d.ts +6 -3
- package/dist/dsl/common.d.ts +1 -1
- package/dist/dsl/instance.d.ts +2 -2
- package/dist/env.d.ts +0 -1
- package/dist/hooks.d.ts +9 -4
- package/dist/index.d.ts +6 -6
- package/dist/interface/document.d.ts +1 -0
- package/dist/interface/hooks.d.ts +42 -2
- package/dist/interface/hydrate.d.ts +2 -1
- package/dist/runtime.esm.js +1102 -2643
- package/dist/runtime.esm.js.map +1 -1
- package/package.json +4 -4
- package/dist/dsl/hooks.d.ts +0 -17
- package/dist/dsl/react.d.ts +0 -28
- package/dist/dsl/vue.d.ts +0 -7
- package/dist/dsl/vue3.d.ts +0 -5
package/dist/runtime.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isFunction, isUndefined, isObject, warn, isArray, toCamelCase, noop, ensure, toDashed, isString, EMPTY_OBJ, internalComponents, controlledComponent, defaultReconciler } from '@tarojs/shared';
|
|
2
|
+
import { injectable, inject, ContainerModule, optional, multiInject, Container } from 'inversify';
|
|
3
3
|
|
|
4
4
|
/*! *****************************************************************************
|
|
5
5
|
Copyright (C) Microsoft. All rights reserved.
|
|
@@ -16,8 +16,6 @@ See the Apache Version 2.0 License for specific language governing permissions
|
|
|
16
16
|
and limitations under the License.
|
|
17
17
|
***************************************************************************** */
|
|
18
18
|
|
|
19
|
-
/** https://github.com/rbuckton/reflect-metadata */
|
|
20
|
-
|
|
21
19
|
if (process.env.TARO_ENV === 'h5') {
|
|
22
20
|
require('reflect-metadata');
|
|
23
21
|
} else {
|
|
@@ -40,7 +38,7 @@ if (process.env.TARO_ENV === 'h5') {
|
|
|
40
38
|
factory(exporter);
|
|
41
39
|
function makeExporter(target, previous) {
|
|
42
40
|
return function (key, value) {
|
|
43
|
-
if (
|
|
41
|
+
if (!isFunction(target[key])) {
|
|
44
42
|
Object.defineProperty(target, key, { configurable: true, writable: true, value: value });
|
|
45
43
|
}
|
|
46
44
|
if (previous)
|
|
@@ -50,10 +48,10 @@ if (process.env.TARO_ENV === 'h5') {
|
|
|
50
48
|
})(function (exporter) {
|
|
51
49
|
var hasOwn = Object.prototype.hasOwnProperty;
|
|
52
50
|
// feature test for Symbol support
|
|
53
|
-
var supportsSymbol =
|
|
54
|
-
var toPrimitiveSymbol = supportsSymbol &&
|
|
55
|
-
var iteratorSymbol = supportsSymbol &&
|
|
56
|
-
var supportsCreate =
|
|
51
|
+
var supportsSymbol = isFunction(Symbol);
|
|
52
|
+
var toPrimitiveSymbol = supportsSymbol && !isUndefined(Symbol.toPrimitive) ? Symbol.toPrimitive : "@@toPrimitive";
|
|
53
|
+
var iteratorSymbol = supportsSymbol && !isUndefined(Symbol.iterator) ? Symbol.iterator : "@@iterator";
|
|
54
|
+
var supportsCreate = isFunction(Object.create); // feature test for Object.create support
|
|
57
55
|
var supportsProto = { __proto__: [] } instanceof Array; // feature test for __proto__ support
|
|
58
56
|
var downLevel = !supportsCreate && !supportsProto;
|
|
59
57
|
var HashMap = {
|
|
@@ -72,10 +70,10 @@ if (process.env.TARO_ENV === 'h5') {
|
|
|
72
70
|
};
|
|
73
71
|
// Load global or shim versions of Map, Set, and WeakMap
|
|
74
72
|
var functionPrototype = Object.getPrototypeOf(Function);
|
|
75
|
-
var usePolyfill =
|
|
76
|
-
var _Map =
|
|
77
|
-
var _Set =
|
|
78
|
-
var _WeakMap = !usePolyfill &&
|
|
73
|
+
var usePolyfill = isObject(process) && process.env && process.env["REFLECT_METADATA_USE_MAP_POLYFILL"] === "true";
|
|
74
|
+
var _Map = Map;
|
|
75
|
+
var _Set = Set;
|
|
76
|
+
var _WeakMap = !usePolyfill && isFunction(WeakMap) ? WeakMap : CreateWeakMapPolyfill();
|
|
79
77
|
// [[Metadata]] internal slot
|
|
80
78
|
// https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots
|
|
81
79
|
var Metadata = new _WeakMap();
|
|
@@ -725,7 +723,7 @@ if (process.env.TARO_ENV === 'h5') {
|
|
|
725
723
|
// 6.1.7 The Object Type
|
|
726
724
|
// https://tc39.github.io/ecma262/#sec-object-type
|
|
727
725
|
function IsObject(x) {
|
|
728
|
-
return
|
|
726
|
+
return isObject(x) ? x !== null : isFunction(x);
|
|
729
727
|
}
|
|
730
728
|
// 7.1 Type Conversion
|
|
731
729
|
// https://tc39.github.io/ecma262/#sec-type-conversion
|
|
@@ -816,13 +814,13 @@ if (process.env.TARO_ENV === 'h5') {
|
|
|
816
814
|
// https://tc39.github.io/ecma262/#sec-iscallable
|
|
817
815
|
function IsCallable(argument) {
|
|
818
816
|
// NOTE: This is an approximation as we cannot check for [[Call]] internal method.
|
|
819
|
-
return
|
|
817
|
+
return isFunction(argument);
|
|
820
818
|
}
|
|
821
819
|
// 7.2.4 IsConstructor(argument)
|
|
822
820
|
// https://tc39.github.io/ecma262/#sec-isconstructor
|
|
823
821
|
function IsConstructor(argument) {
|
|
824
822
|
// NOTE: This is an approximation as we cannot check for [[Construct]] internal method.
|
|
825
|
-
return
|
|
823
|
+
return isFunction(argument);
|
|
826
824
|
}
|
|
827
825
|
// 7.2.7 IsPropertyKey(argument)
|
|
828
826
|
// https://tc39.github.io/ecma262/#sec-ispropertykey
|
|
@@ -880,7 +878,7 @@ if (process.env.TARO_ENV === 'h5') {
|
|
|
880
878
|
// https://tc39.github.io/ecma262/#sec-ordinarygetprototypeof
|
|
881
879
|
function OrdinaryGetPrototypeOf(O) {
|
|
882
880
|
var proto = Object.getPrototypeOf(O);
|
|
883
|
-
if (
|
|
881
|
+
if (!isFunction(O) || O === functionPrototype)
|
|
884
882
|
return proto;
|
|
885
883
|
// TypeScript doesn't set __proto__ in ES5, as it's non-standard.
|
|
886
884
|
// Try to determine the superclass constructor. Compatible implementations
|
|
@@ -898,7 +896,7 @@ if (process.env.TARO_ENV === 'h5') {
|
|
|
898
896
|
return proto;
|
|
899
897
|
// If the constructor was not a function, then we cannot determine the heritage.
|
|
900
898
|
var constructor = prototypeProto.constructor;
|
|
901
|
-
if (
|
|
899
|
+
if (!isFunction(constructor))
|
|
902
900
|
return proto;
|
|
903
901
|
// If we have some kind of self-reference, then we cannot determine the heritage.
|
|
904
902
|
if (constructor === O)
|
|
@@ -907,149 +905,149 @@ if (process.env.TARO_ENV === 'h5') {
|
|
|
907
905
|
return constructor;
|
|
908
906
|
}
|
|
909
907
|
// naive Map shim
|
|
910
|
-
function CreateMapPolyfill() {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
}
|
|
908
|
+
// function CreateMapPolyfill() {
|
|
909
|
+
// var cacheSentinel = {};
|
|
910
|
+
// var arraySentinel = [];
|
|
911
|
+
// var MapIterator = /** @class */ (function () {
|
|
912
|
+
// function MapIterator(keys, values, selector) {
|
|
913
|
+
// this._index = 0;
|
|
914
|
+
// this._keys = keys;
|
|
915
|
+
// this._values = values;
|
|
916
|
+
// this._selector = selector;
|
|
917
|
+
// }
|
|
918
|
+
// MapIterator.prototype["@@iterator"] = function () { return this; };
|
|
919
|
+
// MapIterator.prototype[iteratorSymbol] = function () { return this; };
|
|
920
|
+
// MapIterator.prototype.next = function () {
|
|
921
|
+
// var index = this._index;
|
|
922
|
+
// if (index >= 0 && index < this._keys.length) {
|
|
923
|
+
// var result = this._selector(this._keys[index], this._values[index]);
|
|
924
|
+
// if (index + 1 >= this._keys.length) {
|
|
925
|
+
// this._index = -1;
|
|
926
|
+
// this._keys = arraySentinel;
|
|
927
|
+
// this._values = arraySentinel;
|
|
928
|
+
// }
|
|
929
|
+
// else {
|
|
930
|
+
// this._index++;
|
|
931
|
+
// }
|
|
932
|
+
// return { value: result, done: false };
|
|
933
|
+
// }
|
|
934
|
+
// return { value: undefined, done: true };
|
|
935
|
+
// };
|
|
936
|
+
// MapIterator.prototype.throw = function (error) {
|
|
937
|
+
// if (this._index >= 0) {
|
|
938
|
+
// this._index = -1;
|
|
939
|
+
// this._keys = arraySentinel;
|
|
940
|
+
// this._values = arraySentinel;
|
|
941
|
+
// }
|
|
942
|
+
// throw error;
|
|
943
|
+
// };
|
|
944
|
+
// MapIterator.prototype.return = function (value) {
|
|
945
|
+
// if (this._index >= 0) {
|
|
946
|
+
// this._index = -1;
|
|
947
|
+
// this._keys = arraySentinel;
|
|
948
|
+
// this._values = arraySentinel;
|
|
949
|
+
// }
|
|
950
|
+
// return { value: value, done: true };
|
|
951
|
+
// };
|
|
952
|
+
// return MapIterator;
|
|
953
|
+
// }());
|
|
954
|
+
// return /** @class */ (function () {
|
|
955
|
+
// function Map() {
|
|
956
|
+
// this._keys = [];
|
|
957
|
+
// this._values = [];
|
|
958
|
+
// this._cacheKey = cacheSentinel;
|
|
959
|
+
// this._cacheIndex = -2;
|
|
960
|
+
// }
|
|
961
|
+
// Object.defineProperty(Map.prototype, "size", {
|
|
962
|
+
// get: function () { return this._keys.length; },
|
|
963
|
+
// enumerable: true,
|
|
964
|
+
// configurable: true
|
|
965
|
+
// });
|
|
966
|
+
// Map.prototype.has = function (key) { return this._find(key, /*insert*/ false) >= 0; };
|
|
967
|
+
// Map.prototype.get = function (key) {
|
|
968
|
+
// var index = this._find(key, /*insert*/ false);
|
|
969
|
+
// return index >= 0 ? this._values[index] : undefined;
|
|
970
|
+
// };
|
|
971
|
+
// Map.prototype.set = function (key, value) {
|
|
972
|
+
// var index = this._find(key, /*insert*/ true);
|
|
973
|
+
// this._values[index] = value;
|
|
974
|
+
// return this;
|
|
975
|
+
// };
|
|
976
|
+
// Map.prototype.delete = function (key) {
|
|
977
|
+
// var index = this._find(key, /*insert*/ false);
|
|
978
|
+
// if (index >= 0) {
|
|
979
|
+
// var size = this._keys.length;
|
|
980
|
+
// for (var i = index + 1; i < size; i++) {
|
|
981
|
+
// this._keys[i - 1] = this._keys[i];
|
|
982
|
+
// this._values[i - 1] = this._values[i];
|
|
983
|
+
// }
|
|
984
|
+
// this._keys.length--;
|
|
985
|
+
// this._values.length--;
|
|
986
|
+
// if (key === this._cacheKey) {
|
|
987
|
+
// this._cacheKey = cacheSentinel;
|
|
988
|
+
// this._cacheIndex = -2;
|
|
989
|
+
// }
|
|
990
|
+
// return true;
|
|
991
|
+
// }
|
|
992
|
+
// return false;
|
|
993
|
+
// };
|
|
994
|
+
// Map.prototype.clear = function () {
|
|
995
|
+
// this._keys.length = 0;
|
|
996
|
+
// this._values.length = 0;
|
|
997
|
+
// this._cacheKey = cacheSentinel;
|
|
998
|
+
// this._cacheIndex = -2;
|
|
999
|
+
// };
|
|
1000
|
+
// Map.prototype.keys = function () { return new MapIterator(this._keys, this._values, getKey); };
|
|
1001
|
+
// Map.prototype.values = function () { return new MapIterator(this._keys, this._values, getValue); };
|
|
1002
|
+
// Map.prototype.entries = function () { return new MapIterator(this._keys, this._values, getEntry); };
|
|
1003
|
+
// Map.prototype["@@iterator"] = function () { return this.entries(); };
|
|
1004
|
+
// Map.prototype[iteratorSymbol] = function () { return this.entries(); };
|
|
1005
|
+
// Map.prototype._find = function (key, insert) {
|
|
1006
|
+
// if (this._cacheKey !== key) {
|
|
1007
|
+
// this._cacheIndex = this._keys.indexOf(this._cacheKey = key);
|
|
1008
|
+
// }
|
|
1009
|
+
// if (this._cacheIndex < 0 && insert) {
|
|
1010
|
+
// this._cacheIndex = this._keys.length;
|
|
1011
|
+
// this._keys.push(key);
|
|
1012
|
+
// this._values.push(undefined);
|
|
1013
|
+
// }
|
|
1014
|
+
// return this._cacheIndex;
|
|
1015
|
+
// };
|
|
1016
|
+
// return Map;
|
|
1017
|
+
// }());
|
|
1018
|
+
// function getKey(key, _) {
|
|
1019
|
+
// return key;
|
|
1020
|
+
// }
|
|
1021
|
+
// function getValue(_, value) {
|
|
1022
|
+
// return value;
|
|
1023
|
+
// }
|
|
1024
|
+
// function getEntry(key, value) {
|
|
1025
|
+
// return [key, value];
|
|
1026
|
+
// }
|
|
1027
|
+
// }
|
|
1030
1028
|
// naive Set shim
|
|
1031
|
-
function CreateSetPolyfill() {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
}
|
|
1029
|
+
// function CreateSetPolyfill() {
|
|
1030
|
+
// return /** @class */ (function () {
|
|
1031
|
+
// function Set() {
|
|
1032
|
+
// this._map = new _Map();
|
|
1033
|
+
// }
|
|
1034
|
+
// Object.defineProperty(Set.prototype, "size", {
|
|
1035
|
+
// get: function () { return this._map.size; },
|
|
1036
|
+
// enumerable: true,
|
|
1037
|
+
// configurable: true
|
|
1038
|
+
// });
|
|
1039
|
+
// Set.prototype.has = function (value) { return this._map.has(value); };
|
|
1040
|
+
// Set.prototype.add = function (value) { return this._map.set(value, value), this; };
|
|
1041
|
+
// Set.prototype.delete = function (value) { return this._map.delete(value); };
|
|
1042
|
+
// Set.prototype.clear = function () { this._map.clear(); };
|
|
1043
|
+
// Set.prototype.keys = function () { return this._map.keys(); };
|
|
1044
|
+
// Set.prototype.values = function () { return this._map.values(); };
|
|
1045
|
+
// Set.prototype.entries = function () { return this._map.entries(); };
|
|
1046
|
+
// Set.prototype["@@iterator"] = function () { return this.keys(); };
|
|
1047
|
+
// Set.prototype[iteratorSymbol] = function () { return this.keys(); };
|
|
1048
|
+
// return Set;
|
|
1049
|
+
// }());
|
|
1050
|
+
// }
|
|
1053
1051
|
// naive WeakMap shim
|
|
1054
1052
|
function CreateWeakMapPolyfill() {
|
|
1055
1053
|
var UUID_SIZE = 16;
|
|
@@ -1104,10 +1102,10 @@ if (process.env.TARO_ENV === 'h5') {
|
|
|
1104
1102
|
return buffer;
|
|
1105
1103
|
}
|
|
1106
1104
|
function GenRandomBytes(size) {
|
|
1107
|
-
if (
|
|
1108
|
-
if (
|
|
1105
|
+
if (isFunction(Uint8Array)) {
|
|
1106
|
+
if (!isUndefined(crypto))
|
|
1109
1107
|
return crypto.getRandomValues(new Uint8Array(size));
|
|
1110
|
-
if (
|
|
1108
|
+
if (!isUndefined(msCrypto))
|
|
1111
1109
|
return msCrypto.getRandomValues(new Uint8Array(size));
|
|
1112
1110
|
return FillRandomBytes(new Uint8Array(size), size);
|
|
1113
1111
|
}
|
|
@@ -1170,37 +1168,7 @@ function __metadata(metadataKey, metadataValue) {
|
|
|
1170
1168
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
1171
1169
|
}
|
|
1172
1170
|
|
|
1173
|
-
const SERVICE_IDENTIFIER = {
|
|
1174
|
-
TaroElement: 'TaroElement',
|
|
1175
|
-
TaroElementFactory: 'Factory<TaroElement>',
|
|
1176
|
-
TaroText: 'TaroText',
|
|
1177
|
-
TaroTextFactory: 'Factory<TaroText>',
|
|
1178
|
-
TaroNodeImpl: 'TaroNodeImpl',
|
|
1179
|
-
TaroElementImpl: 'TaroElementImpl',
|
|
1180
|
-
Hooks: 'hooks',
|
|
1181
|
-
onRemoveAttribute: 'onRemoveAttribute',
|
|
1182
|
-
getLifecycle: 'getLifecycle',
|
|
1183
|
-
getPathIndex: 'getPathIndex',
|
|
1184
|
-
getEventCenter: 'getEventCenter',
|
|
1185
|
-
isBubbleEvents: 'isBubbleEvents',
|
|
1186
|
-
getSpecialNodes: 'getSpecialNodes',
|
|
1187
|
-
eventCenter: 'eventCenter',
|
|
1188
|
-
modifyMpEvent: 'modifyMpEvent',
|
|
1189
|
-
modifyTaroEvent: 'modifyTaroEvent',
|
|
1190
|
-
batchedEventUpdates: 'batchedEventUpdates',
|
|
1191
|
-
mergePageInstance: 'mergePageInstance',
|
|
1192
|
-
createPullDownComponent: 'createPullDownComponent',
|
|
1193
|
-
getDOMNode: 'getDOMNode',
|
|
1194
|
-
initNativeApi: 'initNativeApi',
|
|
1195
|
-
modifyHydrateData: 'modifyHydrateData',
|
|
1196
|
-
modifySetAttrPayload: 'modifySetAttrPayload',
|
|
1197
|
-
modifyRmAttrPayload: 'modifyRmAttrPayload',
|
|
1198
|
-
onAddEvent: 'onAddEvent',
|
|
1199
|
-
patchElement: 'patchElement'
|
|
1200
|
-
};
|
|
1201
|
-
|
|
1202
1171
|
const PROPERTY_THRESHOLD = 2046;
|
|
1203
|
-
const HOOKS_APP_ID = 'taro-app';
|
|
1204
1172
|
const SET_DATA = '小程序 setData';
|
|
1205
1173
|
const PAGE_INIT = '页面初始化';
|
|
1206
1174
|
const ROOT_STR = 'root';
|
|
@@ -1236,7 +1204,14 @@ const TOUCHMOVE = 'touchmove';
|
|
|
1236
1204
|
const DATE = 'Date';
|
|
1237
1205
|
const CATCHMOVE = 'catchMove';
|
|
1238
1206
|
const CATCH_VIEW = 'catch-view';
|
|
1239
|
-
const COMMENT = 'comment';
|
|
1207
|
+
const COMMENT = 'comment';
|
|
1208
|
+
const ON_LOAD = 'onLoad';
|
|
1209
|
+
const ON_READY = 'onReady';
|
|
1210
|
+
const ON_SHOW = 'onShow';
|
|
1211
|
+
const ON_HIDE = 'onHide';
|
|
1212
|
+
const OPTIONS = 'options';
|
|
1213
|
+
const EXTERNAL_CLASSES = 'externalClasses';
|
|
1214
|
+
const BEHAVIORS = 'behaviors';
|
|
1240
1215
|
|
|
1241
1216
|
const incrementId = () => {
|
|
1242
1217
|
let id = 0;
|
|
@@ -1287,11 +1262,99 @@ function shortcutAttr(key) {
|
|
|
1287
1262
|
}
|
|
1288
1263
|
}
|
|
1289
1264
|
|
|
1265
|
+
const SID_TARO_ELEMENT = '0';
|
|
1266
|
+
const SID_TARO_ELEMENT_FACTORY = '1';
|
|
1267
|
+
const SID_TARO_TEXT = '2';
|
|
1268
|
+
const SID_TARO_TEXT_FACTORY = '3';
|
|
1269
|
+
const SID_TARO_NODE_IMPL = '4';
|
|
1270
|
+
const SID_TARO_ELEMENT_IMPL = '5';
|
|
1271
|
+
const SID_HOOKS = '6';
|
|
1272
|
+
const SID_ON_REMOVE_ATTRIBUTE = '7';
|
|
1273
|
+
const SID_GET_MINI_LIFECYCLE = '8';
|
|
1274
|
+
const SID_GET_LIFECYCLE = '9';
|
|
1275
|
+
const SID_GET_PATH_INDEX = '10';
|
|
1276
|
+
const SID_GET_EVENT_CENTER = '11';
|
|
1277
|
+
const SID_IS_BUBBLE_EVENTS = '12';
|
|
1278
|
+
const SID_GET_SPECIAL_NODES = '13';
|
|
1279
|
+
const SID_EVENT_CENTER = '14';
|
|
1280
|
+
const SID_MODIFY_MP_EVENT = '15';
|
|
1281
|
+
const SID_MODIFY_TARO_EVENT = '16';
|
|
1282
|
+
const SID_MODIFY_DISPATCH_EVENT = '17';
|
|
1283
|
+
const SID_BATCHED_EVENT_UPDATES = '18';
|
|
1284
|
+
const SID_MERGE_PAGE_INSTANCE = '19';
|
|
1285
|
+
const SID_CREATE_PULLDOWN_COMPONENT = '20';
|
|
1286
|
+
const SID_GET_DOM_NODE = '21';
|
|
1287
|
+
const SID_INIT_NATIVE_API = '22';
|
|
1288
|
+
const SID_MODIFY_HYDRATE_DATA = '23';
|
|
1289
|
+
const SID_MODIFY_SET_ATTR_PAYLOAD = '24';
|
|
1290
|
+
const SID_MODIFY_RM_ATTR_PAYLOAD = '25';
|
|
1291
|
+
const SID_ON_ADD_EVENT = '26';
|
|
1292
|
+
const SID_PATCH_ELEMENT = '27';
|
|
1293
|
+
const SID_MODIFY_PAGE_OBJECT = '28';
|
|
1294
|
+
const SERVICE_IDENTIFIER = {
|
|
1295
|
+
TaroElement: SID_TARO_ELEMENT,
|
|
1296
|
+
TaroElementFactory: SID_TARO_ELEMENT_FACTORY,
|
|
1297
|
+
TaroText: SID_TARO_TEXT,
|
|
1298
|
+
TaroTextFactory: SID_TARO_TEXT_FACTORY,
|
|
1299
|
+
TaroNodeImpl: SID_TARO_NODE_IMPL,
|
|
1300
|
+
TaroElementImpl: SID_TARO_ELEMENT_IMPL,
|
|
1301
|
+
Hooks: SID_HOOKS,
|
|
1302
|
+
onRemoveAttribute: SID_ON_REMOVE_ATTRIBUTE,
|
|
1303
|
+
getMiniLifecycle: SID_GET_MINI_LIFECYCLE,
|
|
1304
|
+
getLifecycle: SID_GET_LIFECYCLE,
|
|
1305
|
+
getPathIndex: SID_GET_PATH_INDEX,
|
|
1306
|
+
getEventCenter: SID_GET_EVENT_CENTER,
|
|
1307
|
+
isBubbleEvents: SID_IS_BUBBLE_EVENTS,
|
|
1308
|
+
getSpecialNodes: SID_GET_SPECIAL_NODES,
|
|
1309
|
+
eventCenter: SID_EVENT_CENTER,
|
|
1310
|
+
modifyMpEvent: SID_MODIFY_MP_EVENT,
|
|
1311
|
+
modifyTaroEvent: SID_MODIFY_TARO_EVENT,
|
|
1312
|
+
modifyDispatchEvent: SID_MODIFY_DISPATCH_EVENT,
|
|
1313
|
+
batchedEventUpdates: SID_BATCHED_EVENT_UPDATES,
|
|
1314
|
+
mergePageInstance: SID_MERGE_PAGE_INSTANCE,
|
|
1315
|
+
createPullDownComponent: SID_CREATE_PULLDOWN_COMPONENT,
|
|
1316
|
+
getDOMNode: SID_GET_DOM_NODE,
|
|
1317
|
+
initNativeApi: SID_INIT_NATIVE_API,
|
|
1318
|
+
modifyHydrateData: SID_MODIFY_HYDRATE_DATA,
|
|
1319
|
+
modifySetAttrPayload: SID_MODIFY_SET_ATTR_PAYLOAD,
|
|
1320
|
+
modifyRmAttrPayload: SID_MODIFY_RM_ATTR_PAYLOAD,
|
|
1321
|
+
onAddEvent: SID_ON_ADD_EVENT,
|
|
1322
|
+
patchElement: SID_PATCH_ELEMENT,
|
|
1323
|
+
modifyPageObject: SID_MODIFY_PAGE_OBJECT
|
|
1324
|
+
};
|
|
1325
|
+
|
|
1326
|
+
var ElementNames;
|
|
1327
|
+
(function (ElementNames) {
|
|
1328
|
+
ElementNames["Element"] = "Element";
|
|
1329
|
+
ElementNames["Document"] = "Document";
|
|
1330
|
+
ElementNames["RootElement"] = "RootElement";
|
|
1331
|
+
ElementNames["FormElement"] = "FormElement";
|
|
1332
|
+
})(ElementNames || (ElementNames = {}));
|
|
1333
|
+
|
|
1334
|
+
const store = {
|
|
1335
|
+
container: null
|
|
1336
|
+
};
|
|
1337
|
+
function getHooks() {
|
|
1338
|
+
return store.container.get(SID_HOOKS);
|
|
1339
|
+
}
|
|
1340
|
+
function getElementFactory() {
|
|
1341
|
+
return store.container.get(SID_TARO_ELEMENT_FACTORY);
|
|
1342
|
+
}
|
|
1343
|
+
function getNodeImpl() {
|
|
1344
|
+
return store.container.get(SID_TARO_NODE_IMPL);
|
|
1345
|
+
}
|
|
1346
|
+
function getElementImpl() {
|
|
1347
|
+
return store.container.get(SID_TARO_ELEMENT_IMPL);
|
|
1348
|
+
}
|
|
1349
|
+
function getDocument() {
|
|
1350
|
+
const getElement = getElementFactory();
|
|
1351
|
+
return getElement(ElementNames.Document)();
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1290
1354
|
let TaroEventTarget = class TaroEventTarget {
|
|
1291
|
-
constructor(
|
|
1292
|
-
hooks) {
|
|
1355
|
+
constructor() {
|
|
1293
1356
|
this.__handlers = {};
|
|
1294
|
-
this.hooks =
|
|
1357
|
+
this.hooks = getHooks();
|
|
1295
1358
|
}
|
|
1296
1359
|
addEventListener(type, handler, options) {
|
|
1297
1360
|
var _a, _b;
|
|
@@ -1306,7 +1369,7 @@ let TaroEventTarget = class TaroEventTarget {
|
|
|
1306
1369
|
const handlers = this.__handlers[type];
|
|
1307
1370
|
let isCapture = Boolean(options);
|
|
1308
1371
|
let isOnce = false;
|
|
1309
|
-
if (isObject
|
|
1372
|
+
if (isObject(options)) {
|
|
1310
1373
|
isCapture = Boolean(options.capture);
|
|
1311
1374
|
isOnce = Boolean(options.once);
|
|
1312
1375
|
}
|
|
@@ -1319,7 +1382,7 @@ let TaroEventTarget = class TaroEventTarget {
|
|
|
1319
1382
|
return;
|
|
1320
1383
|
}
|
|
1321
1384
|
process.env.NODE_ENV !== 'production' && warn(isCapture, 'Taro 暂未实现 event 的 capture 特性。');
|
|
1322
|
-
if (isArray
|
|
1385
|
+
if (isArray(handlers)) {
|
|
1323
1386
|
handlers.push(handler);
|
|
1324
1387
|
}
|
|
1325
1388
|
else {
|
|
@@ -1328,11 +1391,11 @@ let TaroEventTarget = class TaroEventTarget {
|
|
|
1328
1391
|
}
|
|
1329
1392
|
removeEventListener(type, handler) {
|
|
1330
1393
|
type = type.toLowerCase();
|
|
1331
|
-
if (handler
|
|
1394
|
+
if (!handler) {
|
|
1332
1395
|
return;
|
|
1333
1396
|
}
|
|
1334
1397
|
const handlers = this.__handlers[type];
|
|
1335
|
-
if (!isArray
|
|
1398
|
+
if (!isArray(handlers)) {
|
|
1336
1399
|
return;
|
|
1337
1400
|
}
|
|
1338
1401
|
const index = handlers.indexOf(handler);
|
|
@@ -1347,8 +1410,7 @@ let TaroEventTarget = class TaroEventTarget {
|
|
|
1347
1410
|
};
|
|
1348
1411
|
TaroEventTarget = __decorate([
|
|
1349
1412
|
injectable(),
|
|
1350
|
-
|
|
1351
|
-
__metadata("design:paramtypes", [Object])
|
|
1413
|
+
__metadata("design:paramtypes", [])
|
|
1352
1414
|
], TaroEventTarget);
|
|
1353
1415
|
|
|
1354
1416
|
/**
|
|
@@ -1368,10 +1430,13 @@ function hydrate(node) {
|
|
|
1368
1430
|
}
|
|
1369
1431
|
const data = {
|
|
1370
1432
|
["nn" /* NodeName */]: nodeName,
|
|
1371
|
-
|
|
1433
|
+
sid: node.sid
|
|
1372
1434
|
};
|
|
1373
1435
|
const { props } = node;
|
|
1374
1436
|
const SPECIAL_NODES = node.hooks.getSpecialNodes();
|
|
1437
|
+
if (node.uid !== node.sid) {
|
|
1438
|
+
data.uid = node.uid;
|
|
1439
|
+
}
|
|
1375
1440
|
if (!node.isAnyEventBinded() && SPECIAL_NODES.indexOf(nodeName) > -1) {
|
|
1376
1441
|
data["nn" /* NodeName */] = `static-${nodeName}`;
|
|
1377
1442
|
if (nodeName === VIEW && !isHasExtractProp(node)) {
|
|
@@ -1410,40 +1475,196 @@ function hydrate(node) {
|
|
|
1410
1475
|
return data;
|
|
1411
1476
|
}
|
|
1412
1477
|
|
|
1413
|
-
|
|
1478
|
+
class EventSource extends Map {
|
|
1479
|
+
removeNode(child) {
|
|
1480
|
+
const { sid, uid } = child;
|
|
1481
|
+
this.delete(sid);
|
|
1482
|
+
if (uid !== sid && uid)
|
|
1483
|
+
this.delete(uid);
|
|
1484
|
+
}
|
|
1485
|
+
removeNodeTree(child) {
|
|
1486
|
+
this.removeNode(child);
|
|
1487
|
+
const { childNodes } = child;
|
|
1488
|
+
childNodes.forEach(node => this.removeNodeTree(node));
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
const eventSource = new EventSource();
|
|
1414
1492
|
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1493
|
+
const observers = [];
|
|
1494
|
+
/**
|
|
1495
|
+
* The MutationObserver provides the ability
|
|
1496
|
+
* to watch for changes being made to the DOM tree.
|
|
1497
|
+
* It will invoke a specified callback function
|
|
1498
|
+
* when DOM changes occur.
|
|
1499
|
+
* @see https://dom.spec.whatwg.org/#mutationobserver
|
|
1500
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
|
|
1501
|
+
*/
|
|
1502
|
+
class MutationObserverImpl {
|
|
1503
|
+
constructor(callback) {
|
|
1504
|
+
this.records = [];
|
|
1505
|
+
this.callback = callback;
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Configures the MutationObserver
|
|
1509
|
+
* to begin receiving notifications
|
|
1510
|
+
* through its callback function
|
|
1511
|
+
* when DOM changes matching the given options occur.
|
|
1512
|
+
*
|
|
1513
|
+
* Options matching is to be implemented.
|
|
1514
|
+
*/
|
|
1515
|
+
observe(target, options) {
|
|
1516
|
+
this.disconnect();
|
|
1517
|
+
this.target = target;
|
|
1518
|
+
this.options = options || {};
|
|
1519
|
+
observers.push(this);
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Stop the MutationObserver instance
|
|
1523
|
+
* from receiving further notifications
|
|
1524
|
+
* until and unless observe() is called again.
|
|
1525
|
+
*/
|
|
1526
|
+
disconnect() {
|
|
1527
|
+
this.target = null;
|
|
1528
|
+
const index = observers.indexOf(this);
|
|
1529
|
+
if (index >= 0) {
|
|
1530
|
+
observers.splice(index, 1);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* Removes all pending notifications
|
|
1535
|
+
* from the MutationObserver's notification queue
|
|
1536
|
+
* and returns them in a new Array of MutationRecord objects.
|
|
1537
|
+
*/
|
|
1538
|
+
takeRecords() {
|
|
1539
|
+
return this.records.splice(0, this.records.length);
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
/** Match two TaroNodes by sid. */
|
|
1543
|
+
const sidMatches = (observerTarget, target) => {
|
|
1544
|
+
return !!observerTarget && observerTarget.sid === (target === null || target === void 0 ? void 0 : target.sid);
|
|
1545
|
+
};
|
|
1546
|
+
const isConcerned = (record, options) => {
|
|
1547
|
+
const { characterData, characterDataOldValue, attributes, attributeOldValue, childList } = options;
|
|
1548
|
+
switch (record.type) {
|
|
1549
|
+
case "characterData" /* CHARACTER_DATA */:
|
|
1550
|
+
if (characterData) {
|
|
1551
|
+
if (!characterDataOldValue)
|
|
1552
|
+
record.oldValue = null;
|
|
1553
|
+
return true;
|
|
1554
|
+
}
|
|
1555
|
+
return false;
|
|
1556
|
+
case "attributes" /* ATTRIBUTES */:
|
|
1557
|
+
if (attributes) {
|
|
1558
|
+
if (!attributeOldValue)
|
|
1559
|
+
record.oldValue = null;
|
|
1560
|
+
return true;
|
|
1561
|
+
}
|
|
1562
|
+
return false;
|
|
1563
|
+
case "childList" /* CHILD_LIST */:
|
|
1564
|
+
if (childList) {
|
|
1565
|
+
return true;
|
|
1566
|
+
}
|
|
1567
|
+
return false;
|
|
1568
|
+
}
|
|
1569
|
+
};
|
|
1570
|
+
let pendingMuatations = false;
|
|
1571
|
+
function logMutation(observer, record) {
|
|
1572
|
+
observer.records.push(record);
|
|
1573
|
+
if (!pendingMuatations) {
|
|
1574
|
+
pendingMuatations = true;
|
|
1575
|
+
Promise
|
|
1576
|
+
.resolve()
|
|
1577
|
+
.then(() => {
|
|
1578
|
+
pendingMuatations = false;
|
|
1579
|
+
observers.forEach(observer => {
|
|
1580
|
+
return observer.callback(observer.takeRecords());
|
|
1581
|
+
});
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
function recordMutation(record) {
|
|
1586
|
+
observers.forEach(observer => {
|
|
1587
|
+
const { options } = observer;
|
|
1588
|
+
for (let t = record.target; t; t = t.parentNode) {
|
|
1589
|
+
if (sidMatches(observer.target, t) && isConcerned(record, options)) {
|
|
1590
|
+
logMutation(observer, record);
|
|
1591
|
+
break;
|
|
1592
|
+
}
|
|
1593
|
+
if (!options.subtree)
|
|
1594
|
+
break;
|
|
1595
|
+
}
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
class MutationObserver {
|
|
1600
|
+
constructor(callback) {
|
|
1601
|
+
if (ENABLE_MUTATION_OBSERVER) {
|
|
1602
|
+
this.core = new MutationObserverImpl(callback);
|
|
1603
|
+
}
|
|
1604
|
+
else {
|
|
1605
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1606
|
+
console.warn('[Taro Warning] 若要使用 MutationObserver,请在 Taro 编译配置中设置 \'mini.enableMutationObserver: true\'');
|
|
1607
|
+
}
|
|
1608
|
+
this.core = {
|
|
1609
|
+
observe: noop,
|
|
1610
|
+
disconnect: noop,
|
|
1611
|
+
takeRecords: noop
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
observe(...args) {
|
|
1616
|
+
this.core.observe(...args);
|
|
1617
|
+
}
|
|
1618
|
+
disconnect() {
|
|
1619
|
+
this.core.disconnect();
|
|
1620
|
+
}
|
|
1621
|
+
takeRecords() {
|
|
1622
|
+
return this.core.takeRecords();
|
|
1623
|
+
}
|
|
1624
|
+
static record(record) {
|
|
1625
|
+
recordMutation(record);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1422
1628
|
|
|
1629
|
+
const CHILDNODES = "cn" /* Childnodes */;
|
|
1423
1630
|
const nodeId = incrementId();
|
|
1424
1631
|
let TaroNode = class TaroNode extends TaroEventTarget {
|
|
1425
|
-
constructor(
|
|
1426
|
-
|
|
1427
|
-
super(hooks);
|
|
1632
|
+
constructor() {
|
|
1633
|
+
super();
|
|
1428
1634
|
this.parentNode = null;
|
|
1429
1635
|
this.childNodes = [];
|
|
1636
|
+
this._getElement = getElementFactory();
|
|
1430
1637
|
this.hydrate = (node) => () => hydrate(node);
|
|
1638
|
+
const impl = getNodeImpl();
|
|
1431
1639
|
impl.bind(this);
|
|
1432
|
-
this.
|
|
1433
|
-
this.
|
|
1434
|
-
eventSource.set(this.
|
|
1640
|
+
this.uid = `_n_${nodeId()}`; // dom 节点 id,开发者可修改
|
|
1641
|
+
this.sid = this.uid; // dom 节点全局唯一 id,不可被修改
|
|
1642
|
+
eventSource.set(this.sid, this);
|
|
1435
1643
|
}
|
|
1436
1644
|
/**
|
|
1437
1645
|
* like jQuery's $.empty()
|
|
1438
1646
|
*/
|
|
1439
1647
|
_empty() {
|
|
1440
|
-
while (this.
|
|
1441
|
-
|
|
1648
|
+
while (this.firstChild) {
|
|
1649
|
+
// Data Structure
|
|
1650
|
+
const child = this.firstChild;
|
|
1442
1651
|
child.parentNode = null;
|
|
1443
|
-
eventSource.delete(child.uid);
|
|
1444
1652
|
this.childNodes.shift();
|
|
1653
|
+
// eventSource
|
|
1654
|
+
eventSource.removeNodeTree(child);
|
|
1445
1655
|
}
|
|
1446
1656
|
}
|
|
1657
|
+
updateChildNodes(isClean) {
|
|
1658
|
+
const cleanChildNodes = () => [];
|
|
1659
|
+
const rerenderChildNodes = () => {
|
|
1660
|
+
const childNodes = this.childNodes.filter(node => !isComment(node));
|
|
1661
|
+
return childNodes.map(hydrate);
|
|
1662
|
+
};
|
|
1663
|
+
this.enqueueUpdate({
|
|
1664
|
+
path: `${this._path}.${CHILDNODES}`,
|
|
1665
|
+
value: isClean ? cleanChildNodes : rerenderChildNodes
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1447
1668
|
get _root() {
|
|
1448
1669
|
var _a;
|
|
1449
1670
|
return ((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a._root) || null;
|
|
@@ -1460,7 +1681,7 @@ let TaroNode = class TaroNode extends TaroEventTarget {
|
|
|
1460
1681
|
const list = parentNode.childNodes.filter(node => !isComment(node));
|
|
1461
1682
|
const indexOfNode = list.indexOf(this);
|
|
1462
1683
|
const index = this.hooks.getPathIndex(indexOfNode);
|
|
1463
|
-
return `${parentNode._path}.${
|
|
1684
|
+
return `${parentNode._path}.${CHILDNODES}.${index}`;
|
|
1464
1685
|
}
|
|
1465
1686
|
return '';
|
|
1466
1687
|
}
|
|
@@ -1491,18 +1712,32 @@ let TaroNode = class TaroNode extends TaroEventTarget {
|
|
|
1491
1712
|
* @TODO 等待完整 innerHTML 实现
|
|
1492
1713
|
*/
|
|
1493
1714
|
set textContent(text) {
|
|
1715
|
+
const document = this._getElement(ElementNames.Document)();
|
|
1716
|
+
const newText = document.createTextNode(text);
|
|
1717
|
+
// @Todo: appendChild 会多触发一次
|
|
1718
|
+
MutationObserver.record({
|
|
1719
|
+
type: "childList" /* CHILD_LIST */,
|
|
1720
|
+
target: this,
|
|
1721
|
+
removedNodes: this.childNodes.slice(),
|
|
1722
|
+
addedNodes: text === '' ? [] : [newText]
|
|
1723
|
+
});
|
|
1494
1724
|
this._empty();
|
|
1495
1725
|
if (text === '') {
|
|
1496
|
-
this.
|
|
1497
|
-
path: `${this._path}.${"cn" /* Childnodes */}`,
|
|
1498
|
-
value: () => []
|
|
1499
|
-
});
|
|
1726
|
+
this.updateChildNodes(true);
|
|
1500
1727
|
}
|
|
1501
1728
|
else {
|
|
1502
|
-
|
|
1503
|
-
this.
|
|
1729
|
+
this.appendChild(newText);
|
|
1730
|
+
this.updateChildNodes();
|
|
1504
1731
|
}
|
|
1505
1732
|
}
|
|
1733
|
+
/**
|
|
1734
|
+
* @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/insertBefore
|
|
1735
|
+
* @scenario
|
|
1736
|
+
* [A,B,C]
|
|
1737
|
+
* 1. insert D before C, D has no parent
|
|
1738
|
+
* 2. insert D before C, D has the same parent of C
|
|
1739
|
+
* 3. insert D before C, D has the different parent of C
|
|
1740
|
+
*/
|
|
1506
1741
|
insertBefore(newChild, refChild, isReplace) {
|
|
1507
1742
|
if (newChild.nodeName === DOCUMENT_FRAGMENT) {
|
|
1508
1743
|
newChild.childNodes.reduceRight((previousValue, currentValue) => {
|
|
@@ -1511,72 +1746,114 @@ let TaroNode = class TaroNode extends TaroEventTarget {
|
|
|
1511
1746
|
}, refChild);
|
|
1512
1747
|
return newChild;
|
|
1513
1748
|
}
|
|
1514
|
-
newChild
|
|
1749
|
+
// Parent release newChild
|
|
1750
|
+
// - cleanRef: false (No need to clean eventSource, because newChild is about to be inserted)
|
|
1751
|
+
// - update: true (Need to update parent.childNodes, because parent.childNodes is reordered)
|
|
1752
|
+
newChild.remove({ cleanRef: false });
|
|
1753
|
+
// Data structure
|
|
1515
1754
|
newChild.parentNode = this;
|
|
1516
|
-
let payload;
|
|
1517
1755
|
if (refChild) {
|
|
1756
|
+
// insertBefore & replaceChild
|
|
1518
1757
|
const index = this.findIndex(refChild);
|
|
1519
1758
|
this.childNodes.splice(index, 0, newChild);
|
|
1520
|
-
if (isReplace) {
|
|
1521
|
-
payload = {
|
|
1522
|
-
path: newChild._path,
|
|
1523
|
-
value: this.hydrate(newChild)
|
|
1524
|
-
};
|
|
1525
|
-
}
|
|
1526
|
-
else {
|
|
1527
|
-
payload = {
|
|
1528
|
-
path: `${this._path}.${"cn" /* Childnodes */}`,
|
|
1529
|
-
value: () => {
|
|
1530
|
-
const childNodes = this.childNodes.filter(node => !isComment(node));
|
|
1531
|
-
return childNodes.map(hydrate);
|
|
1532
|
-
}
|
|
1533
|
-
};
|
|
1534
|
-
}
|
|
1535
1759
|
}
|
|
1536
1760
|
else {
|
|
1761
|
+
// appendChild
|
|
1537
1762
|
this.childNodes.push(newChild);
|
|
1538
|
-
|
|
1763
|
+
}
|
|
1764
|
+
// Serialization
|
|
1765
|
+
if (!refChild || isReplace) {
|
|
1766
|
+
// appendChild & replaceChild
|
|
1767
|
+
this.enqueueUpdate({
|
|
1539
1768
|
path: newChild._path,
|
|
1540
1769
|
value: this.hydrate(newChild)
|
|
1541
|
-
};
|
|
1542
|
-
}
|
|
1543
|
-
this.enqueueUpdate(payload);
|
|
1544
|
-
if (!eventSource.has(newChild.uid)) {
|
|
1545
|
-
eventSource.set(newChild.uid, newChild);
|
|
1770
|
+
});
|
|
1546
1771
|
}
|
|
1772
|
+
else {
|
|
1773
|
+
// insertBefore
|
|
1774
|
+
this.updateChildNodes();
|
|
1775
|
+
}
|
|
1776
|
+
MutationObserver.record({
|
|
1777
|
+
type: "childList" /* CHILD_LIST */,
|
|
1778
|
+
target: this,
|
|
1779
|
+
addedNodes: [newChild],
|
|
1780
|
+
removedNodes: isReplace
|
|
1781
|
+
? [refChild] /** replaceChild */
|
|
1782
|
+
: [],
|
|
1783
|
+
nextSibling: isReplace
|
|
1784
|
+
? refChild.nextSibling /** replaceChild */
|
|
1785
|
+
: (refChild || null),
|
|
1786
|
+
previousSibling: newChild.previousSibling
|
|
1787
|
+
});
|
|
1547
1788
|
return newChild;
|
|
1548
1789
|
}
|
|
1549
|
-
|
|
1550
|
-
|
|
1790
|
+
/**
|
|
1791
|
+
* @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/appendChild
|
|
1792
|
+
* @scenario
|
|
1793
|
+
* [A,B,C]
|
|
1794
|
+
* 1. append C, C has no parent
|
|
1795
|
+
* 2. append C, C has the same parent of B
|
|
1796
|
+
* 3. append C, C has the different parent of B
|
|
1797
|
+
*/
|
|
1798
|
+
appendChild(newChild) {
|
|
1799
|
+
return this.insertBefore(newChild);
|
|
1551
1800
|
}
|
|
1801
|
+
/**
|
|
1802
|
+
* @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/replaceChild
|
|
1803
|
+
* @scenario
|
|
1804
|
+
* [A,B,C]
|
|
1805
|
+
* 1. replace B with C, C has no parent
|
|
1806
|
+
* 2. replace B with C, C has no parent, C has the same parent of B
|
|
1807
|
+
* 3. replace B with C, C has no parent, C has the different parent of B
|
|
1808
|
+
*/
|
|
1552
1809
|
replaceChild(newChild, oldChild) {
|
|
1553
|
-
if (oldChild.parentNode
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1810
|
+
if (oldChild.parentNode !== this)
|
|
1811
|
+
return;
|
|
1812
|
+
// Insert the newChild
|
|
1813
|
+
this.insertBefore(newChild, oldChild, true);
|
|
1814
|
+
// Destroy the oldChild
|
|
1815
|
+
// - cleanRef: true (Need to clean eventSource, because the oldChild was detached from the DOM tree)
|
|
1816
|
+
// - update: false (No need to update parent.childNodes, because replace will not cause the parent.childNodes being reordered)
|
|
1817
|
+
oldChild.remove({ doUpdate: false });
|
|
1818
|
+
return oldChild;
|
|
1558
1819
|
}
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1820
|
+
/**
|
|
1821
|
+
* @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/removeChild
|
|
1822
|
+
* @scenario
|
|
1823
|
+
* [A,B,C]
|
|
1824
|
+
* 1. remove A or B
|
|
1825
|
+
* 2. remove C
|
|
1826
|
+
*/
|
|
1827
|
+
removeChild(child, options = {}) {
|
|
1828
|
+
const { cleanRef, doUpdate } = options;
|
|
1829
|
+
if (cleanRef !== false && doUpdate !== false) {
|
|
1830
|
+
// appendChild/replaceChild/insertBefore 不应该触发
|
|
1831
|
+
// @Todo: 但其实如果 newChild 的父节点是另一颗子树的节点,应该是要触发的
|
|
1832
|
+
MutationObserver.record({
|
|
1833
|
+
type: "childList" /* CHILD_LIST */,
|
|
1834
|
+
target: this,
|
|
1835
|
+
removedNodes: [child],
|
|
1836
|
+
nextSibling: child.nextSibling,
|
|
1837
|
+
previousSibling: child.previousSibling
|
|
1569
1838
|
});
|
|
1570
1839
|
}
|
|
1840
|
+
// Data Structure
|
|
1841
|
+
const index = this.findIndex(child);
|
|
1842
|
+
this.childNodes.splice(index, 1);
|
|
1571
1843
|
child.parentNode = null;
|
|
1572
|
-
eventSource
|
|
1573
|
-
|
|
1574
|
-
|
|
1844
|
+
// Set eventSource
|
|
1845
|
+
if (cleanRef !== false) {
|
|
1846
|
+
eventSource.removeNodeTree(child);
|
|
1847
|
+
}
|
|
1848
|
+
// Serialization
|
|
1849
|
+
if (doUpdate !== false) {
|
|
1850
|
+
this.updateChildNodes();
|
|
1851
|
+
}
|
|
1575
1852
|
return child;
|
|
1576
1853
|
}
|
|
1577
|
-
remove(
|
|
1854
|
+
remove(options) {
|
|
1578
1855
|
var _a;
|
|
1579
|
-
(_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this,
|
|
1856
|
+
(_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this, options);
|
|
1580
1857
|
}
|
|
1581
1858
|
hasChildNodes() {
|
|
1582
1859
|
return this.childNodes.length > 0;
|
|
@@ -1585,17 +1862,6 @@ let TaroNode = class TaroNode extends TaroEventTarget {
|
|
|
1585
1862
|
var _a;
|
|
1586
1863
|
(_a = this._root) === null || _a === void 0 ? void 0 : _a.enqueueUpdate(payload);
|
|
1587
1864
|
}
|
|
1588
|
-
contains(node) {
|
|
1589
|
-
let isContains = false;
|
|
1590
|
-
this.childNodes.some(childNode => {
|
|
1591
|
-
const { uid } = childNode;
|
|
1592
|
-
if (uid === node.uid || uid === node.id || childNode.contains(node)) {
|
|
1593
|
-
isContains = true;
|
|
1594
|
-
return true;
|
|
1595
|
-
}
|
|
1596
|
-
});
|
|
1597
|
-
return isContains;
|
|
1598
|
-
}
|
|
1599
1865
|
get ownerDocument() {
|
|
1600
1866
|
const document = this._getElement(ElementNames.Document)();
|
|
1601
1867
|
return document;
|
|
@@ -1603,20 +1869,21 @@ let TaroNode = class TaroNode extends TaroEventTarget {
|
|
|
1603
1869
|
};
|
|
1604
1870
|
TaroNode = __decorate([
|
|
1605
1871
|
injectable(),
|
|
1606
|
-
|
|
1607
|
-
__param(1, inject(SERVICE_IDENTIFIER.TaroElementFactory)),
|
|
1608
|
-
__param(2, inject(SERVICE_IDENTIFIER.Hooks)),
|
|
1609
|
-
__metadata("design:paramtypes", [Function, Function, Function])
|
|
1872
|
+
__metadata("design:paramtypes", [])
|
|
1610
1873
|
], TaroNode);
|
|
1611
1874
|
|
|
1612
1875
|
let TaroText = class TaroText extends TaroNode {
|
|
1613
|
-
constructor(
|
|
1614
|
-
|
|
1615
|
-
super(nodeImpl, getElement, hooks);
|
|
1876
|
+
constructor() {
|
|
1877
|
+
super(...arguments);
|
|
1616
1878
|
this.nodeType = 3 /* TEXT_NODE */;
|
|
1617
1879
|
this.nodeName = '#text';
|
|
1618
1880
|
}
|
|
1619
1881
|
set textContent(text) {
|
|
1882
|
+
MutationObserver.record({
|
|
1883
|
+
target: this,
|
|
1884
|
+
type: "characterData" /* CHARACTER_DATA */,
|
|
1885
|
+
oldValue: this._value
|
|
1886
|
+
});
|
|
1620
1887
|
this._value = text;
|
|
1621
1888
|
this.enqueueUpdate({
|
|
1622
1889
|
path: `${this._path}.${"v" /* Text */}`,
|
|
@@ -1632,13 +1899,15 @@ let TaroText = class TaroText extends TaroNode {
|
|
|
1632
1899
|
get nodeValue() {
|
|
1633
1900
|
return this._value;
|
|
1634
1901
|
}
|
|
1902
|
+
set data(text) {
|
|
1903
|
+
this.textContent = text;
|
|
1904
|
+
}
|
|
1905
|
+
get data() {
|
|
1906
|
+
return this._value;
|
|
1907
|
+
}
|
|
1635
1908
|
};
|
|
1636
1909
|
TaroText = __decorate([
|
|
1637
|
-
injectable()
|
|
1638
|
-
__param(0, inject(SERVICE_IDENTIFIER.TaroNodeImpl)),
|
|
1639
|
-
__param(1, inject(SERVICE_IDENTIFIER.TaroElementFactory)),
|
|
1640
|
-
__param(2, inject(SERVICE_IDENTIFIER.Hooks)),
|
|
1641
|
-
__metadata("design:paramtypes", [Function, Function, Function])
|
|
1910
|
+
injectable()
|
|
1642
1911
|
], TaroText);
|
|
1643
1912
|
|
|
1644
1913
|
/*
|
|
@@ -1828,6 +2097,7 @@ combine('box', ['DecorationBreak', 'Shadow', 'Sizing', 'Snap'], true);
|
|
|
1828
2097
|
|
|
1829
2098
|
function setStyle(newVal, styleKey) {
|
|
1830
2099
|
const old = this[styleKey];
|
|
2100
|
+
const oldCssTxt = this.cssText;
|
|
1831
2101
|
if (newVal) {
|
|
1832
2102
|
this._usedStyleProp.add(styleKey);
|
|
1833
2103
|
}
|
|
@@ -1838,6 +2108,16 @@ function setStyle(newVal, styleKey) {
|
|
|
1838
2108
|
path: `${this._element._path}.${"st" /* Style */}`,
|
|
1839
2109
|
value: this.cssText
|
|
1840
2110
|
});
|
|
2111
|
+
// @Todo:
|
|
2112
|
+
// el.style.cssText = 'x: y;m: n'(Bug: 触发两次)
|
|
2113
|
+
// el.style.cssText = 'x: y'(正常)
|
|
2114
|
+
// el.style.x = y(正常)
|
|
2115
|
+
MutationObserver.record({
|
|
2116
|
+
type: "attributes" /* ATTRIBUTES */,
|
|
2117
|
+
target: this._element,
|
|
2118
|
+
attributeName: 'style',
|
|
2119
|
+
oldValue: oldCssTxt
|
|
2120
|
+
});
|
|
1841
2121
|
}
|
|
1842
2122
|
}
|
|
1843
2123
|
function initStyle(ctor) {
|
|
@@ -1877,15 +2157,15 @@ class Style {
|
|
|
1877
2157
|
});
|
|
1878
2158
|
}
|
|
1879
2159
|
get cssText() {
|
|
1880
|
-
|
|
2160
|
+
const texts = [];
|
|
1881
2161
|
this._usedStyleProp.forEach(key => {
|
|
1882
2162
|
const val = this[key];
|
|
1883
2163
|
if (!val)
|
|
1884
2164
|
return;
|
|
1885
2165
|
const styleName = isCssVariable(key) ? key : toDashed(key);
|
|
1886
|
-
|
|
2166
|
+
texts.push(`${styleName}: ${val};`);
|
|
1887
2167
|
});
|
|
1888
|
-
return
|
|
2168
|
+
return texts.join(' ');
|
|
1889
2169
|
}
|
|
1890
2170
|
set cssText(str) {
|
|
1891
2171
|
if (str == null) {
|
|
@@ -1992,7 +2272,7 @@ class ClassList extends Set {
|
|
|
1992
2272
|
this.el = el;
|
|
1993
2273
|
}
|
|
1994
2274
|
get value() {
|
|
1995
|
-
return [...this].join(' ');
|
|
2275
|
+
return [...this].filter(v => v !== '').join(' ');
|
|
1996
2276
|
}
|
|
1997
2277
|
add(s) {
|
|
1998
2278
|
super.add(s);
|
|
@@ -2032,15 +2312,16 @@ class ClassList extends Set {
|
|
|
2032
2312
|
}
|
|
2033
2313
|
|
|
2034
2314
|
let TaroElement = class TaroElement extends TaroNode {
|
|
2035
|
-
constructor(
|
|
2036
|
-
|
|
2037
|
-
super(
|
|
2315
|
+
constructor() {
|
|
2316
|
+
var _a, _b;
|
|
2317
|
+
super();
|
|
2038
2318
|
this.props = {};
|
|
2039
2319
|
this.dataset = EMPTY_OBJ;
|
|
2040
|
-
|
|
2320
|
+
const impl = getElementImpl();
|
|
2321
|
+
impl.bind(this);
|
|
2041
2322
|
this.nodeType = 1 /* ELEMENT_NODE */;
|
|
2042
2323
|
this.style = new Style(this);
|
|
2043
|
-
hooks.patchElement(this);
|
|
2324
|
+
(_b = (_a = this.hooks).patchElement) === null || _b === void 0 ? void 0 : _b.call(_a, this);
|
|
2044
2325
|
}
|
|
2045
2326
|
_stopPropagation(event) {
|
|
2046
2327
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
@@ -2048,7 +2329,7 @@ let TaroElement = class TaroElement extends TaroNode {
|
|
|
2048
2329
|
// eslint-disable-next-line no-cond-assign
|
|
2049
2330
|
while ((target = target.parentNode)) {
|
|
2050
2331
|
const listeners = target.__handlers[event.type];
|
|
2051
|
-
if (!isArray
|
|
2332
|
+
if (!isArray(listeners)) {
|
|
2052
2333
|
continue;
|
|
2053
2334
|
}
|
|
2054
2335
|
for (let i = listeners.length; i--;) {
|
|
@@ -2118,12 +2399,24 @@ let TaroElement = class TaroElement extends TaroNode {
|
|
|
2118
2399
|
var _a, _b;
|
|
2119
2400
|
process.env.NODE_ENV !== 'production' && warn(isString(value) && value.length > PROPERTY_THRESHOLD, `元素 ${this.nodeName} 的 属性 ${qualifiedName} 的值数据量过大,可能会影响渲染性能。考虑降低图片转为 base64 的阈值或在 CSS 中使用 base64。`);
|
|
2120
2401
|
const isPureView = this.nodeName === VIEW && !isHasExtractProp(this) && !this.isAnyEventBinded();
|
|
2402
|
+
if (qualifiedName !== STYLE) {
|
|
2403
|
+
MutationObserver.record({
|
|
2404
|
+
target: this,
|
|
2405
|
+
type: "attributes" /* ATTRIBUTES */,
|
|
2406
|
+
attributeName: qualifiedName,
|
|
2407
|
+
oldValue: this.getAttribute(qualifiedName)
|
|
2408
|
+
});
|
|
2409
|
+
}
|
|
2121
2410
|
switch (qualifiedName) {
|
|
2122
2411
|
case STYLE:
|
|
2123
2412
|
this.style.cssText = value;
|
|
2124
2413
|
break;
|
|
2125
2414
|
case ID:
|
|
2126
|
-
|
|
2415
|
+
if (this.uid !== this.sid) {
|
|
2416
|
+
// eventSource[sid] 永远保留,直到组件卸载
|
|
2417
|
+
// eventSource[uid] 可变
|
|
2418
|
+
eventSource.delete(this.uid);
|
|
2419
|
+
}
|
|
2127
2420
|
value = String(value);
|
|
2128
2421
|
this.props[qualifiedName] = this.uid = value;
|
|
2129
2422
|
eventSource.set(value, this);
|
|
@@ -2141,7 +2434,7 @@ let TaroElement = class TaroElement extends TaroNode {
|
|
|
2141
2434
|
qualifiedName = shortcutAttr(qualifiedName);
|
|
2142
2435
|
const payload = {
|
|
2143
2436
|
path: `${this._path}.${toCamelCase(qualifiedName)}`,
|
|
2144
|
-
value: isFunction
|
|
2437
|
+
value: isFunction(value) ? () => value : value
|
|
2145
2438
|
};
|
|
2146
2439
|
(_b = (_a = this.hooks).modifySetAttrPayload) === null || _b === void 0 ? void 0 : _b.call(_a, this, qualifiedName, payload);
|
|
2147
2440
|
this.enqueueUpdate(payload);
|
|
@@ -2166,6 +2459,12 @@ let TaroElement = class TaroElement extends TaroNode {
|
|
|
2166
2459
|
removeAttribute(qualifiedName) {
|
|
2167
2460
|
var _a, _b, _c, _d;
|
|
2168
2461
|
const isStaticView = this.nodeName === VIEW && isHasExtractProp(this) && !this.isAnyEventBinded();
|
|
2462
|
+
MutationObserver.record({
|
|
2463
|
+
target: this,
|
|
2464
|
+
type: "attributes" /* ATTRIBUTES */,
|
|
2465
|
+
attributeName: qualifiedName,
|
|
2466
|
+
oldValue: this.getAttribute(qualifiedName)
|
|
2467
|
+
});
|
|
2169
2468
|
if (qualifiedName === STYLE) {
|
|
2170
2469
|
this.style.cssText = '';
|
|
2171
2470
|
}
|
|
@@ -2222,7 +2521,7 @@ let TaroElement = class TaroElement extends TaroNode {
|
|
|
2222
2521
|
dispatchEvent(event) {
|
|
2223
2522
|
const cancelable = event.cancelable;
|
|
2224
2523
|
const listeners = this.__handlers[event.type];
|
|
2225
|
-
if (!isArray
|
|
2524
|
+
if (!isArray(listeners)) {
|
|
2226
2525
|
return false;
|
|
2227
2526
|
}
|
|
2228
2527
|
for (let i = listeners.length; i--;) {
|
|
@@ -2232,6 +2531,7 @@ let TaroElement = class TaroElement extends TaroNode {
|
|
|
2232
2531
|
listener._stop = false;
|
|
2233
2532
|
}
|
|
2234
2533
|
else {
|
|
2534
|
+
this.hooks.modifyDispatchEvent(event, this);
|
|
2235
2535
|
result = listener.call(this, event);
|
|
2236
2536
|
}
|
|
2237
2537
|
if ((result === false || event._end) && cancelable) {
|
|
@@ -2274,1136 +2574,66 @@ let TaroElement = class TaroElement extends TaroNode {
|
|
|
2274
2574
|
};
|
|
2275
2575
|
TaroElement = __decorate([
|
|
2276
2576
|
injectable(),
|
|
2277
|
-
|
|
2278
|
-
__param(1, inject(SERVICE_IDENTIFIER.TaroElementFactory)),
|
|
2279
|
-
__param(2, inject(SERVICE_IDENTIFIER.Hooks)),
|
|
2280
|
-
__param(3, inject(SERVICE_IDENTIFIER.TaroElementImpl)),
|
|
2281
|
-
__metadata("design:paramtypes", [Function, Function, Function, Function])
|
|
2577
|
+
__metadata("design:paramtypes", [])
|
|
2282
2578
|
], TaroElement);
|
|
2283
2579
|
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
* @memberOf _
|
|
2289
|
-
* @since 0.1.0
|
|
2290
|
-
* @category Lang
|
|
2291
|
-
* @param {*} value The value to check.
|
|
2292
|
-
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
|
2293
|
-
* @example
|
|
2294
|
-
*
|
|
2295
|
-
* _.isArray([1, 2, 3]);
|
|
2296
|
-
* // => true
|
|
2297
|
-
*
|
|
2298
|
-
* _.isArray(document.body.children);
|
|
2299
|
-
* // => false
|
|
2300
|
-
*
|
|
2301
|
-
* _.isArray('abc');
|
|
2302
|
-
* // => false
|
|
2303
|
-
*
|
|
2304
|
-
* _.isArray(_.noop);
|
|
2305
|
-
* // => false
|
|
2306
|
-
*/
|
|
2307
|
-
var isArray = Array.isArray;
|
|
2308
|
-
|
|
2309
|
-
/** Detect free variable `global` from Node.js. */
|
|
2310
|
-
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
|
2311
|
-
|
|
2312
|
-
/** Detect free variable `self`. */
|
|
2313
|
-
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
|
2314
|
-
|
|
2315
|
-
/** Used as a reference to the global object. */
|
|
2316
|
-
var root = freeGlobal || freeSelf || Function('return this')();
|
|
2317
|
-
|
|
2318
|
-
/** Built-in value references. */
|
|
2319
|
-
var Symbol$1 = root.Symbol;
|
|
2320
|
-
|
|
2321
|
-
/** Used for built-in method references. */
|
|
2322
|
-
var objectProto = Object.prototype;
|
|
2323
|
-
|
|
2324
|
-
/** Used to check objects for own properties. */
|
|
2325
|
-
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
2326
|
-
|
|
2327
|
-
/**
|
|
2328
|
-
* Used to resolve the
|
|
2329
|
-
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
|
2330
|
-
* of values.
|
|
2331
|
-
*/
|
|
2332
|
-
var nativeObjectToString = objectProto.toString;
|
|
2333
|
-
|
|
2334
|
-
/** Built-in value references. */
|
|
2335
|
-
var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined;
|
|
2336
|
-
|
|
2337
|
-
/**
|
|
2338
|
-
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
|
|
2339
|
-
*
|
|
2340
|
-
* @private
|
|
2341
|
-
* @param {*} value The value to query.
|
|
2342
|
-
* @returns {string} Returns the raw `toStringTag`.
|
|
2343
|
-
*/
|
|
2344
|
-
function getRawTag(value) {
|
|
2345
|
-
var isOwn = hasOwnProperty.call(value, symToStringTag),
|
|
2346
|
-
tag = value[symToStringTag];
|
|
2347
|
-
|
|
2348
|
-
try {
|
|
2349
|
-
value[symToStringTag] = undefined;
|
|
2350
|
-
var unmasked = true;
|
|
2351
|
-
} catch (e) {}
|
|
2352
|
-
|
|
2353
|
-
var result = nativeObjectToString.call(value);
|
|
2354
|
-
if (unmasked) {
|
|
2355
|
-
if (isOwn) {
|
|
2356
|
-
value[symToStringTag] = tag;
|
|
2357
|
-
} else {
|
|
2358
|
-
delete value[symToStringTag];
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
return result;
|
|
2362
|
-
}
|
|
2363
|
-
|
|
2364
|
-
/** Used for built-in method references. */
|
|
2365
|
-
var objectProto$1 = Object.prototype;
|
|
2366
|
-
|
|
2367
|
-
/**
|
|
2368
|
-
* Used to resolve the
|
|
2369
|
-
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
|
2370
|
-
* of values.
|
|
2371
|
-
*/
|
|
2372
|
-
var nativeObjectToString$1 = objectProto$1.toString;
|
|
2373
|
-
|
|
2374
|
-
/**
|
|
2375
|
-
* Converts `value` to a string using `Object.prototype.toString`.
|
|
2376
|
-
*
|
|
2377
|
-
* @private
|
|
2378
|
-
* @param {*} value The value to convert.
|
|
2379
|
-
* @returns {string} Returns the converted string.
|
|
2380
|
-
*/
|
|
2381
|
-
function objectToString(value) {
|
|
2382
|
-
return nativeObjectToString$1.call(value);
|
|
2383
|
-
}
|
|
2384
|
-
|
|
2385
|
-
/** `Object#toString` result references. */
|
|
2386
|
-
var nullTag = '[object Null]',
|
|
2387
|
-
undefinedTag = '[object Undefined]';
|
|
2388
|
-
|
|
2389
|
-
/** Built-in value references. */
|
|
2390
|
-
var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined;
|
|
2391
|
-
|
|
2392
|
-
/**
|
|
2393
|
-
* The base implementation of `getTag` without fallbacks for buggy environments.
|
|
2394
|
-
*
|
|
2395
|
-
* @private
|
|
2396
|
-
* @param {*} value The value to query.
|
|
2397
|
-
* @returns {string} Returns the `toStringTag`.
|
|
2398
|
-
*/
|
|
2399
|
-
function baseGetTag(value) {
|
|
2400
|
-
if (value == null) {
|
|
2401
|
-
return value === undefined ? undefinedTag : nullTag;
|
|
2402
|
-
}
|
|
2403
|
-
return (symToStringTag$1 && symToStringTag$1 in Object(value))
|
|
2404
|
-
? getRawTag(value)
|
|
2405
|
-
: objectToString(value);
|
|
2406
|
-
}
|
|
2407
|
-
|
|
2408
|
-
/**
|
|
2409
|
-
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
|
2410
|
-
* and has a `typeof` result of "object".
|
|
2411
|
-
*
|
|
2412
|
-
* @static
|
|
2413
|
-
* @memberOf _
|
|
2414
|
-
* @since 4.0.0
|
|
2415
|
-
* @category Lang
|
|
2416
|
-
* @param {*} value The value to check.
|
|
2417
|
-
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
2418
|
-
* @example
|
|
2419
|
-
*
|
|
2420
|
-
* _.isObjectLike({});
|
|
2421
|
-
* // => true
|
|
2422
|
-
*
|
|
2423
|
-
* _.isObjectLike([1, 2, 3]);
|
|
2424
|
-
* // => true
|
|
2425
|
-
*
|
|
2426
|
-
* _.isObjectLike(_.noop);
|
|
2427
|
-
* // => false
|
|
2428
|
-
*
|
|
2429
|
-
* _.isObjectLike(null);
|
|
2430
|
-
* // => false
|
|
2431
|
-
*/
|
|
2432
|
-
function isObjectLike(value) {
|
|
2433
|
-
return value != null && typeof value == 'object';
|
|
2434
|
-
}
|
|
2435
|
-
|
|
2436
|
-
/** `Object#toString` result references. */
|
|
2437
|
-
var symbolTag = '[object Symbol]';
|
|
2438
|
-
|
|
2439
|
-
/**
|
|
2440
|
-
* Checks if `value` is classified as a `Symbol` primitive or object.
|
|
2441
|
-
*
|
|
2442
|
-
* @static
|
|
2443
|
-
* @memberOf _
|
|
2444
|
-
* @since 4.0.0
|
|
2445
|
-
* @category Lang
|
|
2446
|
-
* @param {*} value The value to check.
|
|
2447
|
-
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
|
|
2448
|
-
* @example
|
|
2449
|
-
*
|
|
2450
|
-
* _.isSymbol(Symbol.iterator);
|
|
2451
|
-
* // => true
|
|
2452
|
-
*
|
|
2453
|
-
* _.isSymbol('abc');
|
|
2454
|
-
* // => false
|
|
2455
|
-
*/
|
|
2456
|
-
function isSymbol(value) {
|
|
2457
|
-
return typeof value == 'symbol' ||
|
|
2458
|
-
(isObjectLike(value) && baseGetTag(value) == symbolTag);
|
|
2459
|
-
}
|
|
2460
|
-
|
|
2461
|
-
/** Used to match property names within property paths. */
|
|
2462
|
-
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
|
|
2463
|
-
reIsPlainProp = /^\w*$/;
|
|
2464
|
-
|
|
2465
|
-
/**
|
|
2466
|
-
* Checks if `value` is a property name and not a property path.
|
|
2467
|
-
*
|
|
2468
|
-
* @private
|
|
2469
|
-
* @param {*} value The value to check.
|
|
2470
|
-
* @param {Object} [object] The object to query keys on.
|
|
2471
|
-
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
|
2472
|
-
*/
|
|
2473
|
-
function isKey(value, object) {
|
|
2474
|
-
if (isArray(value)) {
|
|
2475
|
-
return false;
|
|
2476
|
-
}
|
|
2477
|
-
var type = typeof value;
|
|
2478
|
-
if (type == 'number' || type == 'symbol' || type == 'boolean' ||
|
|
2479
|
-
value == null || isSymbol(value)) {
|
|
2480
|
-
return true;
|
|
2481
|
-
}
|
|
2482
|
-
return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
|
|
2483
|
-
(object != null && value in Object(object));
|
|
2484
|
-
}
|
|
2485
|
-
|
|
2486
|
-
/**
|
|
2487
|
-
* Checks if `value` is the
|
|
2488
|
-
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|
2489
|
-
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
2490
|
-
*
|
|
2491
|
-
* @static
|
|
2492
|
-
* @memberOf _
|
|
2493
|
-
* @since 0.1.0
|
|
2494
|
-
* @category Lang
|
|
2495
|
-
* @param {*} value The value to check.
|
|
2496
|
-
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
2497
|
-
* @example
|
|
2498
|
-
*
|
|
2499
|
-
* _.isObject({});
|
|
2500
|
-
* // => true
|
|
2501
|
-
*
|
|
2502
|
-
* _.isObject([1, 2, 3]);
|
|
2503
|
-
* // => true
|
|
2504
|
-
*
|
|
2505
|
-
* _.isObject(_.noop);
|
|
2506
|
-
* // => true
|
|
2507
|
-
*
|
|
2508
|
-
* _.isObject(null);
|
|
2509
|
-
* // => false
|
|
2510
|
-
*/
|
|
2511
|
-
function isObject(value) {
|
|
2512
|
-
var type = typeof value;
|
|
2513
|
-
return value != null && (type == 'object' || type == 'function');
|
|
2514
|
-
}
|
|
2515
|
-
|
|
2516
|
-
/** `Object#toString` result references. */
|
|
2517
|
-
var asyncTag = '[object AsyncFunction]',
|
|
2518
|
-
funcTag = '[object Function]',
|
|
2519
|
-
genTag = '[object GeneratorFunction]',
|
|
2520
|
-
proxyTag = '[object Proxy]';
|
|
2521
|
-
|
|
2522
|
-
/**
|
|
2523
|
-
* Checks if `value` is classified as a `Function` object.
|
|
2524
|
-
*
|
|
2525
|
-
* @static
|
|
2526
|
-
* @memberOf _
|
|
2527
|
-
* @since 0.1.0
|
|
2528
|
-
* @category Lang
|
|
2529
|
-
* @param {*} value The value to check.
|
|
2530
|
-
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
|
2531
|
-
* @example
|
|
2532
|
-
*
|
|
2533
|
-
* _.isFunction(_);
|
|
2534
|
-
* // => true
|
|
2535
|
-
*
|
|
2536
|
-
* _.isFunction(/abc/);
|
|
2537
|
-
* // => false
|
|
2538
|
-
*/
|
|
2539
|
-
function isFunction(value) {
|
|
2540
|
-
if (!isObject(value)) {
|
|
2541
|
-
return false;
|
|
2542
|
-
}
|
|
2543
|
-
// The use of `Object#toString` avoids issues with the `typeof` operator
|
|
2544
|
-
// in Safari 9 which returns 'object' for typed arrays and other constructors.
|
|
2545
|
-
var tag = baseGetTag(value);
|
|
2546
|
-
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
2547
|
-
}
|
|
2548
|
-
|
|
2549
|
-
/** Used to detect overreaching core-js shims. */
|
|
2550
|
-
var coreJsData = root['__core-js_shared__'];
|
|
2551
|
-
|
|
2552
|
-
/** Used to detect methods masquerading as native. */
|
|
2553
|
-
var maskSrcKey = (function() {
|
|
2554
|
-
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
|
|
2555
|
-
return uid ? ('Symbol(src)_1.' + uid) : '';
|
|
2556
|
-
}());
|
|
2557
|
-
|
|
2558
|
-
/**
|
|
2559
|
-
* Checks if `func` has its source masked.
|
|
2560
|
-
*
|
|
2561
|
-
* @private
|
|
2562
|
-
* @param {Function} func The function to check.
|
|
2563
|
-
* @returns {boolean} Returns `true` if `func` is masked, else `false`.
|
|
2564
|
-
*/
|
|
2565
|
-
function isMasked(func) {
|
|
2566
|
-
return !!maskSrcKey && (maskSrcKey in func);
|
|
2567
|
-
}
|
|
2568
|
-
|
|
2569
|
-
/** Used for built-in method references. */
|
|
2570
|
-
var funcProto = Function.prototype;
|
|
2571
|
-
|
|
2572
|
-
/** Used to resolve the decompiled source of functions. */
|
|
2573
|
-
var funcToString = funcProto.toString;
|
|
2574
|
-
|
|
2575
|
-
/**
|
|
2576
|
-
* Converts `func` to its source code.
|
|
2577
|
-
*
|
|
2578
|
-
* @private
|
|
2579
|
-
* @param {Function} func The function to convert.
|
|
2580
|
-
* @returns {string} Returns the source code.
|
|
2581
|
-
*/
|
|
2582
|
-
function toSource(func) {
|
|
2583
|
-
if (func != null) {
|
|
2584
|
-
try {
|
|
2585
|
-
return funcToString.call(func);
|
|
2586
|
-
} catch (e) {}
|
|
2587
|
-
try {
|
|
2588
|
-
return (func + '');
|
|
2589
|
-
} catch (e) {}
|
|
2590
|
-
}
|
|
2591
|
-
return '';
|
|
2592
|
-
}
|
|
2593
|
-
|
|
2594
|
-
/**
|
|
2595
|
-
* Used to match `RegExp`
|
|
2596
|
-
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
|
2597
|
-
*/
|
|
2598
|
-
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
2599
|
-
|
|
2600
|
-
/** Used to detect host constructors (Safari). */
|
|
2601
|
-
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
2602
|
-
|
|
2603
|
-
/** Used for built-in method references. */
|
|
2604
|
-
var funcProto$1 = Function.prototype,
|
|
2605
|
-
objectProto$2 = Object.prototype;
|
|
2606
|
-
|
|
2607
|
-
/** Used to resolve the decompiled source of functions. */
|
|
2608
|
-
var funcToString$1 = funcProto$1.toString;
|
|
2609
|
-
|
|
2610
|
-
/** Used to check objects for own properties. */
|
|
2611
|
-
var hasOwnProperty$1 = objectProto$2.hasOwnProperty;
|
|
2612
|
-
|
|
2613
|
-
/** Used to detect if a method is native. */
|
|
2614
|
-
var reIsNative = RegExp('^' +
|
|
2615
|
-
funcToString$1.call(hasOwnProperty$1).replace(reRegExpChar, '\\$&')
|
|
2616
|
-
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
|
2617
|
-
);
|
|
2580
|
+
const options = {
|
|
2581
|
+
prerender: true,
|
|
2582
|
+
debug: false
|
|
2583
|
+
};
|
|
2618
2584
|
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2585
|
+
class Performance {
|
|
2586
|
+
constructor() {
|
|
2587
|
+
this.recorder = new Map();
|
|
2588
|
+
}
|
|
2589
|
+
start(id) {
|
|
2590
|
+
if (!options.debug) {
|
|
2591
|
+
return;
|
|
2592
|
+
}
|
|
2593
|
+
this.recorder.set(id, Date.now());
|
|
2594
|
+
}
|
|
2595
|
+
stop(id) {
|
|
2596
|
+
if (!options.debug) {
|
|
2597
|
+
return;
|
|
2598
|
+
}
|
|
2599
|
+
const now = Date.now();
|
|
2600
|
+
const prev = this.recorder.get(id);
|
|
2601
|
+
const time = now - prev;
|
|
2602
|
+
// eslint-disable-next-line no-console
|
|
2603
|
+
console.log(`${id} 时长: ${time}ms`);
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
const perf = new Performance();
|
|
2634
2607
|
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
/**
|
|
2648
|
-
* Gets the native function at `key` of `object`.
|
|
2649
|
-
*
|
|
2650
|
-
* @private
|
|
2651
|
-
* @param {Object} object The object to query.
|
|
2652
|
-
* @param {string} key The key of the method to get.
|
|
2653
|
-
* @returns {*} Returns the function if it's native, else `undefined`.
|
|
2654
|
-
*/
|
|
2655
|
-
function getNative(object, key) {
|
|
2656
|
-
var value = getValue(object, key);
|
|
2657
|
-
return baseIsNative(value) ? value : undefined;
|
|
2658
|
-
}
|
|
2659
|
-
|
|
2660
|
-
/* Built-in method references that are verified to be native. */
|
|
2661
|
-
var nativeCreate = getNative(Object, 'create');
|
|
2662
|
-
|
|
2663
|
-
/**
|
|
2664
|
-
* Removes all key-value entries from the hash.
|
|
2665
|
-
*
|
|
2666
|
-
* @private
|
|
2667
|
-
* @name clear
|
|
2668
|
-
* @memberOf Hash
|
|
2669
|
-
*/
|
|
2670
|
-
function hashClear() {
|
|
2671
|
-
this.__data__ = nativeCreate ? nativeCreate(null) : {};
|
|
2672
|
-
this.size = 0;
|
|
2673
|
-
}
|
|
2674
|
-
|
|
2675
|
-
/**
|
|
2676
|
-
* Removes `key` and its value from the hash.
|
|
2677
|
-
*
|
|
2678
|
-
* @private
|
|
2679
|
-
* @name delete
|
|
2680
|
-
* @memberOf Hash
|
|
2681
|
-
* @param {Object} hash The hash to modify.
|
|
2682
|
-
* @param {string} key The key of the value to remove.
|
|
2683
|
-
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
2684
|
-
*/
|
|
2685
|
-
function hashDelete(key) {
|
|
2686
|
-
var result = this.has(key) && delete this.__data__[key];
|
|
2687
|
-
this.size -= result ? 1 : 0;
|
|
2688
|
-
return result;
|
|
2689
|
-
}
|
|
2690
|
-
|
|
2691
|
-
/** Used to stand-in for `undefined` hash values. */
|
|
2692
|
-
var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
|
2693
|
-
|
|
2694
|
-
/** Used for built-in method references. */
|
|
2695
|
-
var objectProto$3 = Object.prototype;
|
|
2696
|
-
|
|
2697
|
-
/** Used to check objects for own properties. */
|
|
2698
|
-
var hasOwnProperty$2 = objectProto$3.hasOwnProperty;
|
|
2699
|
-
|
|
2700
|
-
/**
|
|
2701
|
-
* Gets the hash value for `key`.
|
|
2702
|
-
*
|
|
2703
|
-
* @private
|
|
2704
|
-
* @name get
|
|
2705
|
-
* @memberOf Hash
|
|
2706
|
-
* @param {string} key The key of the value to get.
|
|
2707
|
-
* @returns {*} Returns the entry value.
|
|
2708
|
-
*/
|
|
2709
|
-
function hashGet(key) {
|
|
2710
|
-
var data = this.__data__;
|
|
2711
|
-
if (nativeCreate) {
|
|
2712
|
-
var result = data[key];
|
|
2713
|
-
return result === HASH_UNDEFINED ? undefined : result;
|
|
2714
|
-
}
|
|
2715
|
-
return hasOwnProperty$2.call(data, key) ? data[key] : undefined;
|
|
2716
|
-
}
|
|
2717
|
-
|
|
2718
|
-
/** Used for built-in method references. */
|
|
2719
|
-
var objectProto$4 = Object.prototype;
|
|
2720
|
-
|
|
2721
|
-
/** Used to check objects for own properties. */
|
|
2722
|
-
var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
|
|
2723
|
-
|
|
2724
|
-
/**
|
|
2725
|
-
* Checks if a hash value for `key` exists.
|
|
2726
|
-
*
|
|
2727
|
-
* @private
|
|
2728
|
-
* @name has
|
|
2729
|
-
* @memberOf Hash
|
|
2730
|
-
* @param {string} key The key of the entry to check.
|
|
2731
|
-
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
2732
|
-
*/
|
|
2733
|
-
function hashHas(key) {
|
|
2734
|
-
var data = this.__data__;
|
|
2735
|
-
return nativeCreate ? (data[key] !== undefined) : hasOwnProperty$3.call(data, key);
|
|
2736
|
-
}
|
|
2737
|
-
|
|
2738
|
-
/** Used to stand-in for `undefined` hash values. */
|
|
2739
|
-
var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
|
|
2740
|
-
|
|
2741
|
-
/**
|
|
2742
|
-
* Sets the hash `key` to `value`.
|
|
2743
|
-
*
|
|
2744
|
-
* @private
|
|
2745
|
-
* @name set
|
|
2746
|
-
* @memberOf Hash
|
|
2747
|
-
* @param {string} key The key of the value to set.
|
|
2748
|
-
* @param {*} value The value to set.
|
|
2749
|
-
* @returns {Object} Returns the hash instance.
|
|
2750
|
-
*/
|
|
2751
|
-
function hashSet(key, value) {
|
|
2752
|
-
var data = this.__data__;
|
|
2753
|
-
this.size += this.has(key) ? 0 : 1;
|
|
2754
|
-
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED$1 : value;
|
|
2755
|
-
return this;
|
|
2756
|
-
}
|
|
2757
|
-
|
|
2758
|
-
/**
|
|
2759
|
-
* Creates a hash object.
|
|
2760
|
-
*
|
|
2761
|
-
* @private
|
|
2762
|
-
* @constructor
|
|
2763
|
-
* @param {Array} [entries] The key-value pairs to cache.
|
|
2764
|
-
*/
|
|
2765
|
-
function Hash(entries) {
|
|
2766
|
-
var index = -1,
|
|
2767
|
-
length = entries == null ? 0 : entries.length;
|
|
2768
|
-
|
|
2769
|
-
this.clear();
|
|
2770
|
-
while (++index < length) {
|
|
2771
|
-
var entry = entries[index];
|
|
2772
|
-
this.set(entry[0], entry[1]);
|
|
2773
|
-
}
|
|
2774
|
-
}
|
|
2775
|
-
|
|
2776
|
-
// Add methods to `Hash`.
|
|
2777
|
-
Hash.prototype.clear = hashClear;
|
|
2778
|
-
Hash.prototype['delete'] = hashDelete;
|
|
2779
|
-
Hash.prototype.get = hashGet;
|
|
2780
|
-
Hash.prototype.has = hashHas;
|
|
2781
|
-
Hash.prototype.set = hashSet;
|
|
2782
|
-
|
|
2783
|
-
/**
|
|
2784
|
-
* Removes all key-value entries from the list cache.
|
|
2785
|
-
*
|
|
2786
|
-
* @private
|
|
2787
|
-
* @name clear
|
|
2788
|
-
* @memberOf ListCache
|
|
2789
|
-
*/
|
|
2790
|
-
function listCacheClear() {
|
|
2791
|
-
this.__data__ = [];
|
|
2792
|
-
this.size = 0;
|
|
2793
|
-
}
|
|
2794
|
-
|
|
2795
|
-
/**
|
|
2796
|
-
* Performs a
|
|
2797
|
-
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|
2798
|
-
* comparison between two values to determine if they are equivalent.
|
|
2799
|
-
*
|
|
2800
|
-
* @static
|
|
2801
|
-
* @memberOf _
|
|
2802
|
-
* @since 4.0.0
|
|
2803
|
-
* @category Lang
|
|
2804
|
-
* @param {*} value The value to compare.
|
|
2805
|
-
* @param {*} other The other value to compare.
|
|
2806
|
-
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
2807
|
-
* @example
|
|
2808
|
-
*
|
|
2809
|
-
* var object = { 'a': 1 };
|
|
2810
|
-
* var other = { 'a': 1 };
|
|
2811
|
-
*
|
|
2812
|
-
* _.eq(object, object);
|
|
2813
|
-
* // => true
|
|
2814
|
-
*
|
|
2815
|
-
* _.eq(object, other);
|
|
2816
|
-
* // => false
|
|
2817
|
-
*
|
|
2818
|
-
* _.eq('a', 'a');
|
|
2819
|
-
* // => true
|
|
2820
|
-
*
|
|
2821
|
-
* _.eq('a', Object('a'));
|
|
2822
|
-
* // => false
|
|
2823
|
-
*
|
|
2824
|
-
* _.eq(NaN, NaN);
|
|
2825
|
-
* // => true
|
|
2826
|
-
*/
|
|
2827
|
-
function eq(value, other) {
|
|
2828
|
-
return value === other || (value !== value && other !== other);
|
|
2829
|
-
}
|
|
2830
|
-
|
|
2831
|
-
/**
|
|
2832
|
-
* Gets the index at which the `key` is found in `array` of key-value pairs.
|
|
2833
|
-
*
|
|
2834
|
-
* @private
|
|
2835
|
-
* @param {Array} array The array to inspect.
|
|
2836
|
-
* @param {*} key The key to search for.
|
|
2837
|
-
* @returns {number} Returns the index of the matched value, else `-1`.
|
|
2838
|
-
*/
|
|
2839
|
-
function assocIndexOf(array, key) {
|
|
2840
|
-
var length = array.length;
|
|
2841
|
-
while (length--) {
|
|
2842
|
-
if (eq(array[length][0], key)) {
|
|
2843
|
-
return length;
|
|
2844
|
-
}
|
|
2845
|
-
}
|
|
2846
|
-
return -1;
|
|
2847
|
-
}
|
|
2848
|
-
|
|
2849
|
-
/** Used for built-in method references. */
|
|
2850
|
-
var arrayProto = Array.prototype;
|
|
2851
|
-
|
|
2852
|
-
/** Built-in value references. */
|
|
2853
|
-
var splice = arrayProto.splice;
|
|
2854
|
-
|
|
2855
|
-
/**
|
|
2856
|
-
* Removes `key` and its value from the list cache.
|
|
2857
|
-
*
|
|
2858
|
-
* @private
|
|
2859
|
-
* @name delete
|
|
2860
|
-
* @memberOf ListCache
|
|
2861
|
-
* @param {string} key The key of the value to remove.
|
|
2862
|
-
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
2863
|
-
*/
|
|
2864
|
-
function listCacheDelete(key) {
|
|
2865
|
-
var data = this.__data__,
|
|
2866
|
-
index = assocIndexOf(data, key);
|
|
2867
|
-
|
|
2868
|
-
if (index < 0) {
|
|
2869
|
-
return false;
|
|
2870
|
-
}
|
|
2871
|
-
var lastIndex = data.length - 1;
|
|
2872
|
-
if (index == lastIndex) {
|
|
2873
|
-
data.pop();
|
|
2874
|
-
} else {
|
|
2875
|
-
splice.call(data, index, 1);
|
|
2876
|
-
}
|
|
2877
|
-
--this.size;
|
|
2878
|
-
return true;
|
|
2879
|
-
}
|
|
2880
|
-
|
|
2881
|
-
/**
|
|
2882
|
-
* Gets the list cache value for `key`.
|
|
2883
|
-
*
|
|
2884
|
-
* @private
|
|
2885
|
-
* @name get
|
|
2886
|
-
* @memberOf ListCache
|
|
2887
|
-
* @param {string} key The key of the value to get.
|
|
2888
|
-
* @returns {*} Returns the entry value.
|
|
2889
|
-
*/
|
|
2890
|
-
function listCacheGet(key) {
|
|
2891
|
-
var data = this.__data__,
|
|
2892
|
-
index = assocIndexOf(data, key);
|
|
2893
|
-
|
|
2894
|
-
return index < 0 ? undefined : data[index][1];
|
|
2895
|
-
}
|
|
2896
|
-
|
|
2897
|
-
/**
|
|
2898
|
-
* Checks if a list cache value for `key` exists.
|
|
2899
|
-
*
|
|
2900
|
-
* @private
|
|
2901
|
-
* @name has
|
|
2902
|
-
* @memberOf ListCache
|
|
2903
|
-
* @param {string} key The key of the entry to check.
|
|
2904
|
-
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
2905
|
-
*/
|
|
2906
|
-
function listCacheHas(key) {
|
|
2907
|
-
return assocIndexOf(this.__data__, key) > -1;
|
|
2908
|
-
}
|
|
2909
|
-
|
|
2910
|
-
/**
|
|
2911
|
-
* Sets the list cache `key` to `value`.
|
|
2912
|
-
*
|
|
2913
|
-
* @private
|
|
2914
|
-
* @name set
|
|
2915
|
-
* @memberOf ListCache
|
|
2916
|
-
* @param {string} key The key of the value to set.
|
|
2917
|
-
* @param {*} value The value to set.
|
|
2918
|
-
* @returns {Object} Returns the list cache instance.
|
|
2919
|
-
*/
|
|
2920
|
-
function listCacheSet(key, value) {
|
|
2921
|
-
var data = this.__data__,
|
|
2922
|
-
index = assocIndexOf(data, key);
|
|
2923
|
-
|
|
2924
|
-
if (index < 0) {
|
|
2925
|
-
++this.size;
|
|
2926
|
-
data.push([key, value]);
|
|
2927
|
-
} else {
|
|
2928
|
-
data[index][1] = value;
|
|
2929
|
-
}
|
|
2930
|
-
return this;
|
|
2931
|
-
}
|
|
2932
|
-
|
|
2933
|
-
/**
|
|
2934
|
-
* Creates an list cache object.
|
|
2935
|
-
*
|
|
2936
|
-
* @private
|
|
2937
|
-
* @constructor
|
|
2938
|
-
* @param {Array} [entries] The key-value pairs to cache.
|
|
2939
|
-
*/
|
|
2940
|
-
function ListCache(entries) {
|
|
2941
|
-
var index = -1,
|
|
2942
|
-
length = entries == null ? 0 : entries.length;
|
|
2943
|
-
|
|
2944
|
-
this.clear();
|
|
2945
|
-
while (++index < length) {
|
|
2946
|
-
var entry = entries[index];
|
|
2947
|
-
this.set(entry[0], entry[1]);
|
|
2948
|
-
}
|
|
2949
|
-
}
|
|
2950
|
-
|
|
2951
|
-
// Add methods to `ListCache`.
|
|
2952
|
-
ListCache.prototype.clear = listCacheClear;
|
|
2953
|
-
ListCache.prototype['delete'] = listCacheDelete;
|
|
2954
|
-
ListCache.prototype.get = listCacheGet;
|
|
2955
|
-
ListCache.prototype.has = listCacheHas;
|
|
2956
|
-
ListCache.prototype.set = listCacheSet;
|
|
2957
|
-
|
|
2958
|
-
/* Built-in method references that are verified to be native. */
|
|
2959
|
-
var Map$1 = getNative(root, 'Map');
|
|
2960
|
-
|
|
2961
|
-
/**
|
|
2962
|
-
* Removes all key-value entries from the map.
|
|
2963
|
-
*
|
|
2964
|
-
* @private
|
|
2965
|
-
* @name clear
|
|
2966
|
-
* @memberOf MapCache
|
|
2967
|
-
*/
|
|
2968
|
-
function mapCacheClear() {
|
|
2969
|
-
this.size = 0;
|
|
2970
|
-
this.__data__ = {
|
|
2971
|
-
'hash': new Hash,
|
|
2972
|
-
'map': new (Map$1 || ListCache),
|
|
2973
|
-
'string': new Hash
|
|
2974
|
-
};
|
|
2975
|
-
}
|
|
2976
|
-
|
|
2977
|
-
/**
|
|
2978
|
-
* Checks if `value` is suitable for use as unique object key.
|
|
2979
|
-
*
|
|
2980
|
-
* @private
|
|
2981
|
-
* @param {*} value The value to check.
|
|
2982
|
-
* @returns {boolean} Returns `true` if `value` is suitable, else `false`.
|
|
2983
|
-
*/
|
|
2984
|
-
function isKeyable(value) {
|
|
2985
|
-
var type = typeof value;
|
|
2986
|
-
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
|
|
2987
|
-
? (value !== '__proto__')
|
|
2988
|
-
: (value === null);
|
|
2989
|
-
}
|
|
2990
|
-
|
|
2991
|
-
/**
|
|
2992
|
-
* Gets the data for `map`.
|
|
2993
|
-
*
|
|
2994
|
-
* @private
|
|
2995
|
-
* @param {Object} map The map to query.
|
|
2996
|
-
* @param {string} key The reference key.
|
|
2997
|
-
* @returns {*} Returns the map data.
|
|
2998
|
-
*/
|
|
2999
|
-
function getMapData(map, key) {
|
|
3000
|
-
var data = map.__data__;
|
|
3001
|
-
return isKeyable(key)
|
|
3002
|
-
? data[typeof key == 'string' ? 'string' : 'hash']
|
|
3003
|
-
: data.map;
|
|
3004
|
-
}
|
|
3005
|
-
|
|
3006
|
-
/**
|
|
3007
|
-
* Removes `key` and its value from the map.
|
|
3008
|
-
*
|
|
3009
|
-
* @private
|
|
3010
|
-
* @name delete
|
|
3011
|
-
* @memberOf MapCache
|
|
3012
|
-
* @param {string} key The key of the value to remove.
|
|
3013
|
-
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
3014
|
-
*/
|
|
3015
|
-
function mapCacheDelete(key) {
|
|
3016
|
-
var result = getMapData(this, key)['delete'](key);
|
|
3017
|
-
this.size -= result ? 1 : 0;
|
|
3018
|
-
return result;
|
|
3019
|
-
}
|
|
3020
|
-
|
|
3021
|
-
/**
|
|
3022
|
-
* Gets the map value for `key`.
|
|
3023
|
-
*
|
|
3024
|
-
* @private
|
|
3025
|
-
* @name get
|
|
3026
|
-
* @memberOf MapCache
|
|
3027
|
-
* @param {string} key The key of the value to get.
|
|
3028
|
-
* @returns {*} Returns the entry value.
|
|
3029
|
-
*/
|
|
3030
|
-
function mapCacheGet(key) {
|
|
3031
|
-
return getMapData(this, key).get(key);
|
|
3032
|
-
}
|
|
3033
|
-
|
|
3034
|
-
/**
|
|
3035
|
-
* Checks if a map value for `key` exists.
|
|
3036
|
-
*
|
|
3037
|
-
* @private
|
|
3038
|
-
* @name has
|
|
3039
|
-
* @memberOf MapCache
|
|
3040
|
-
* @param {string} key The key of the entry to check.
|
|
3041
|
-
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
3042
|
-
*/
|
|
3043
|
-
function mapCacheHas(key) {
|
|
3044
|
-
return getMapData(this, key).has(key);
|
|
3045
|
-
}
|
|
3046
|
-
|
|
3047
|
-
/**
|
|
3048
|
-
* Sets the map `key` to `value`.
|
|
3049
|
-
*
|
|
3050
|
-
* @private
|
|
3051
|
-
* @name set
|
|
3052
|
-
* @memberOf MapCache
|
|
3053
|
-
* @param {string} key The key of the value to set.
|
|
3054
|
-
* @param {*} value The value to set.
|
|
3055
|
-
* @returns {Object} Returns the map cache instance.
|
|
3056
|
-
*/
|
|
3057
|
-
function mapCacheSet(key, value) {
|
|
3058
|
-
var data = getMapData(this, key),
|
|
3059
|
-
size = data.size;
|
|
3060
|
-
|
|
3061
|
-
data.set(key, value);
|
|
3062
|
-
this.size += data.size == size ? 0 : 1;
|
|
3063
|
-
return this;
|
|
3064
|
-
}
|
|
3065
|
-
|
|
3066
|
-
/**
|
|
3067
|
-
* Creates a map cache object to store key-value pairs.
|
|
3068
|
-
*
|
|
3069
|
-
* @private
|
|
3070
|
-
* @constructor
|
|
3071
|
-
* @param {Array} [entries] The key-value pairs to cache.
|
|
3072
|
-
*/
|
|
3073
|
-
function MapCache(entries) {
|
|
3074
|
-
var index = -1,
|
|
3075
|
-
length = entries == null ? 0 : entries.length;
|
|
3076
|
-
|
|
3077
|
-
this.clear();
|
|
3078
|
-
while (++index < length) {
|
|
3079
|
-
var entry = entries[index];
|
|
3080
|
-
this.set(entry[0], entry[1]);
|
|
3081
|
-
}
|
|
3082
|
-
}
|
|
3083
|
-
|
|
3084
|
-
// Add methods to `MapCache`.
|
|
3085
|
-
MapCache.prototype.clear = mapCacheClear;
|
|
3086
|
-
MapCache.prototype['delete'] = mapCacheDelete;
|
|
3087
|
-
MapCache.prototype.get = mapCacheGet;
|
|
3088
|
-
MapCache.prototype.has = mapCacheHas;
|
|
3089
|
-
MapCache.prototype.set = mapCacheSet;
|
|
3090
|
-
|
|
3091
|
-
/** Error message constants. */
|
|
3092
|
-
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
3093
|
-
|
|
3094
|
-
/**
|
|
3095
|
-
* Creates a function that memoizes the result of `func`. If `resolver` is
|
|
3096
|
-
* provided, it determines the cache key for storing the result based on the
|
|
3097
|
-
* arguments provided to the memoized function. By default, the first argument
|
|
3098
|
-
* provided to the memoized function is used as the map cache key. The `func`
|
|
3099
|
-
* is invoked with the `this` binding of the memoized function.
|
|
3100
|
-
*
|
|
3101
|
-
* **Note:** The cache is exposed as the `cache` property on the memoized
|
|
3102
|
-
* function. Its creation may be customized by replacing the `_.memoize.Cache`
|
|
3103
|
-
* constructor with one whose instances implement the
|
|
3104
|
-
* [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
|
|
3105
|
-
* method interface of `clear`, `delete`, `get`, `has`, and `set`.
|
|
3106
|
-
*
|
|
3107
|
-
* @static
|
|
3108
|
-
* @memberOf _
|
|
3109
|
-
* @since 0.1.0
|
|
3110
|
-
* @category Function
|
|
3111
|
-
* @param {Function} func The function to have its output memoized.
|
|
3112
|
-
* @param {Function} [resolver] The function to resolve the cache key.
|
|
3113
|
-
* @returns {Function} Returns the new memoized function.
|
|
3114
|
-
* @example
|
|
3115
|
-
*
|
|
3116
|
-
* var object = { 'a': 1, 'b': 2 };
|
|
3117
|
-
* var other = { 'c': 3, 'd': 4 };
|
|
3118
|
-
*
|
|
3119
|
-
* var values = _.memoize(_.values);
|
|
3120
|
-
* values(object);
|
|
3121
|
-
* // => [1, 2]
|
|
3122
|
-
*
|
|
3123
|
-
* values(other);
|
|
3124
|
-
* // => [3, 4]
|
|
3125
|
-
*
|
|
3126
|
-
* object.a = 2;
|
|
3127
|
-
* values(object);
|
|
3128
|
-
* // => [1, 2]
|
|
3129
|
-
*
|
|
3130
|
-
* // Modify the result cache.
|
|
3131
|
-
* values.cache.set(object, ['a', 'b']);
|
|
3132
|
-
* values(object);
|
|
3133
|
-
* // => ['a', 'b']
|
|
3134
|
-
*
|
|
3135
|
-
* // Replace `_.memoize.Cache`.
|
|
3136
|
-
* _.memoize.Cache = WeakMap;
|
|
3137
|
-
*/
|
|
3138
|
-
function memoize(func, resolver) {
|
|
3139
|
-
if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
|
|
3140
|
-
throw new TypeError(FUNC_ERROR_TEXT);
|
|
3141
|
-
}
|
|
3142
|
-
var memoized = function() {
|
|
3143
|
-
var args = arguments,
|
|
3144
|
-
key = resolver ? resolver.apply(this, args) : args[0],
|
|
3145
|
-
cache = memoized.cache;
|
|
3146
|
-
|
|
3147
|
-
if (cache.has(key)) {
|
|
3148
|
-
return cache.get(key);
|
|
3149
|
-
}
|
|
3150
|
-
var result = func.apply(this, args);
|
|
3151
|
-
memoized.cache = cache.set(key, result) || cache;
|
|
3152
|
-
return result;
|
|
3153
|
-
};
|
|
3154
|
-
memoized.cache = new (memoize.Cache || MapCache);
|
|
3155
|
-
return memoized;
|
|
3156
|
-
}
|
|
3157
|
-
|
|
3158
|
-
// Expose `MapCache`.
|
|
3159
|
-
memoize.Cache = MapCache;
|
|
3160
|
-
|
|
3161
|
-
/** Used as the maximum memoize cache size. */
|
|
3162
|
-
var MAX_MEMOIZE_SIZE = 500;
|
|
3163
|
-
|
|
3164
|
-
/**
|
|
3165
|
-
* A specialized version of `_.memoize` which clears the memoized function's
|
|
3166
|
-
* cache when it exceeds `MAX_MEMOIZE_SIZE`.
|
|
3167
|
-
*
|
|
3168
|
-
* @private
|
|
3169
|
-
* @param {Function} func The function to have its output memoized.
|
|
3170
|
-
* @returns {Function} Returns the new memoized function.
|
|
3171
|
-
*/
|
|
3172
|
-
function memoizeCapped(func) {
|
|
3173
|
-
var result = memoize(func, function(key) {
|
|
3174
|
-
if (cache.size === MAX_MEMOIZE_SIZE) {
|
|
3175
|
-
cache.clear();
|
|
3176
|
-
}
|
|
3177
|
-
return key;
|
|
3178
|
-
});
|
|
3179
|
-
|
|
3180
|
-
var cache = result.cache;
|
|
3181
|
-
return result;
|
|
3182
|
-
}
|
|
3183
|
-
|
|
3184
|
-
/** Used to match property names within property paths. */
|
|
3185
|
-
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
|
3186
|
-
|
|
3187
|
-
/** Used to match backslashes in property paths. */
|
|
3188
|
-
var reEscapeChar = /\\(\\)?/g;
|
|
3189
|
-
|
|
3190
|
-
/**
|
|
3191
|
-
* Converts `string` to a property path array.
|
|
3192
|
-
*
|
|
3193
|
-
* @private
|
|
3194
|
-
* @param {string} string The string to convert.
|
|
3195
|
-
* @returns {Array} Returns the property path array.
|
|
3196
|
-
*/
|
|
3197
|
-
var stringToPath = memoizeCapped(function(string) {
|
|
3198
|
-
var result = [];
|
|
3199
|
-
if (string.charCodeAt(0) === 46 /* . */) {
|
|
3200
|
-
result.push('');
|
|
3201
|
-
}
|
|
3202
|
-
string.replace(rePropName, function(match, number, quote, subString) {
|
|
3203
|
-
result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
|
|
3204
|
-
});
|
|
3205
|
-
return result;
|
|
3206
|
-
});
|
|
3207
|
-
|
|
3208
|
-
/**
|
|
3209
|
-
* A specialized version of `_.map` for arrays without support for iteratee
|
|
3210
|
-
* shorthands.
|
|
3211
|
-
*
|
|
3212
|
-
* @private
|
|
3213
|
-
* @param {Array} [array] The array to iterate over.
|
|
3214
|
-
* @param {Function} iteratee The function invoked per iteration.
|
|
3215
|
-
* @returns {Array} Returns the new mapped array.
|
|
3216
|
-
*/
|
|
3217
|
-
function arrayMap(array, iteratee) {
|
|
3218
|
-
var index = -1,
|
|
3219
|
-
length = array == null ? 0 : array.length,
|
|
3220
|
-
result = Array(length);
|
|
3221
|
-
|
|
3222
|
-
while (++index < length) {
|
|
3223
|
-
result[index] = iteratee(array[index], index, array);
|
|
3224
|
-
}
|
|
3225
|
-
return result;
|
|
3226
|
-
}
|
|
3227
|
-
|
|
3228
|
-
/** Used as references for various `Number` constants. */
|
|
3229
|
-
var INFINITY = 1 / 0;
|
|
3230
|
-
|
|
3231
|
-
/** Used to convert symbols to primitives and strings. */
|
|
3232
|
-
var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined,
|
|
3233
|
-
symbolToString = symbolProto ? symbolProto.toString : undefined;
|
|
3234
|
-
|
|
3235
|
-
/**
|
|
3236
|
-
* The base implementation of `_.toString` which doesn't convert nullish
|
|
3237
|
-
* values to empty strings.
|
|
3238
|
-
*
|
|
3239
|
-
* @private
|
|
3240
|
-
* @param {*} value The value to process.
|
|
3241
|
-
* @returns {string} Returns the string.
|
|
3242
|
-
*/
|
|
3243
|
-
function baseToString(value) {
|
|
3244
|
-
// Exit early for strings to avoid a performance hit in some environments.
|
|
3245
|
-
if (typeof value == 'string') {
|
|
3246
|
-
return value;
|
|
3247
|
-
}
|
|
3248
|
-
if (isArray(value)) {
|
|
3249
|
-
// Recursively convert values (susceptible to call stack limits).
|
|
3250
|
-
return arrayMap(value, baseToString) + '';
|
|
3251
|
-
}
|
|
3252
|
-
if (isSymbol(value)) {
|
|
3253
|
-
return symbolToString ? symbolToString.call(value) : '';
|
|
3254
|
-
}
|
|
3255
|
-
var result = (value + '');
|
|
3256
|
-
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
|
3257
|
-
}
|
|
3258
|
-
|
|
3259
|
-
/**
|
|
3260
|
-
* Converts `value` to a string. An empty string is returned for `null`
|
|
3261
|
-
* and `undefined` values. The sign of `-0` is preserved.
|
|
3262
|
-
*
|
|
3263
|
-
* @static
|
|
3264
|
-
* @memberOf _
|
|
3265
|
-
* @since 4.0.0
|
|
3266
|
-
* @category Lang
|
|
3267
|
-
* @param {*} value The value to convert.
|
|
3268
|
-
* @returns {string} Returns the converted string.
|
|
3269
|
-
* @example
|
|
3270
|
-
*
|
|
3271
|
-
* _.toString(null);
|
|
3272
|
-
* // => ''
|
|
3273
|
-
*
|
|
3274
|
-
* _.toString(-0);
|
|
3275
|
-
* // => '-0'
|
|
3276
|
-
*
|
|
3277
|
-
* _.toString([1, 2, 3]);
|
|
3278
|
-
* // => '1,2,3'
|
|
3279
|
-
*/
|
|
3280
|
-
function toString(value) {
|
|
3281
|
-
return value == null ? '' : baseToString(value);
|
|
3282
|
-
}
|
|
3283
|
-
|
|
3284
|
-
/**
|
|
3285
|
-
* Casts `value` to a path array if it's not one.
|
|
3286
|
-
*
|
|
3287
|
-
* @private
|
|
3288
|
-
* @param {*} value The value to inspect.
|
|
3289
|
-
* @param {Object} [object] The object to query keys on.
|
|
3290
|
-
* @returns {Array} Returns the cast property path array.
|
|
3291
|
-
*/
|
|
3292
|
-
function castPath(value, object) {
|
|
3293
|
-
if (isArray(value)) {
|
|
3294
|
-
return value;
|
|
3295
|
-
}
|
|
3296
|
-
return isKey(value, object) ? [value] : stringToPath(toString(value));
|
|
3297
|
-
}
|
|
3298
|
-
|
|
3299
|
-
/** Used as references for various `Number` constants. */
|
|
3300
|
-
var INFINITY$1 = 1 / 0;
|
|
3301
|
-
|
|
3302
|
-
/**
|
|
3303
|
-
* Converts `value` to a string key if it's not a string or symbol.
|
|
3304
|
-
*
|
|
3305
|
-
* @private
|
|
3306
|
-
* @param {*} value The value to inspect.
|
|
3307
|
-
* @returns {string|symbol} Returns the key.
|
|
3308
|
-
*/
|
|
3309
|
-
function toKey(value) {
|
|
3310
|
-
if (typeof value == 'string' || isSymbol(value)) {
|
|
3311
|
-
return value;
|
|
3312
|
-
}
|
|
3313
|
-
var result = (value + '');
|
|
3314
|
-
return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result;
|
|
3315
|
-
}
|
|
3316
|
-
|
|
3317
|
-
/**
|
|
3318
|
-
* The base implementation of `_.get` without support for default values.
|
|
3319
|
-
*
|
|
3320
|
-
* @private
|
|
3321
|
-
* @param {Object} object The object to query.
|
|
3322
|
-
* @param {Array|string} path The path of the property to get.
|
|
3323
|
-
* @returns {*} Returns the resolved value.
|
|
3324
|
-
*/
|
|
3325
|
-
function baseGet(object, path) {
|
|
3326
|
-
path = castPath(path, object);
|
|
3327
|
-
|
|
3328
|
-
var index = 0,
|
|
3329
|
-
length = path.length;
|
|
3330
|
-
|
|
3331
|
-
while (object != null && index < length) {
|
|
3332
|
-
object = object[toKey(path[index++])];
|
|
3333
|
-
}
|
|
3334
|
-
return (index && index == length) ? object : undefined;
|
|
3335
|
-
}
|
|
3336
|
-
|
|
3337
|
-
/**
|
|
3338
|
-
* Gets the value at `path` of `object`. If the resolved value is
|
|
3339
|
-
* `undefined`, the `defaultValue` is returned in its place.
|
|
3340
|
-
*
|
|
3341
|
-
* @static
|
|
3342
|
-
* @memberOf _
|
|
3343
|
-
* @since 3.7.0
|
|
3344
|
-
* @category Object
|
|
3345
|
-
* @param {Object} object The object to query.
|
|
3346
|
-
* @param {Array|string} path The path of the property to get.
|
|
3347
|
-
* @param {*} [defaultValue] The value returned for `undefined` resolved values.
|
|
3348
|
-
* @returns {*} Returns the resolved value.
|
|
3349
|
-
* @example
|
|
3350
|
-
*
|
|
3351
|
-
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
|
3352
|
-
*
|
|
3353
|
-
* _.get(object, 'a[0].b.c');
|
|
3354
|
-
* // => 3
|
|
3355
|
-
*
|
|
3356
|
-
* _.get(object, ['a', '0', 'b', 'c']);
|
|
3357
|
-
* // => 3
|
|
3358
|
-
*
|
|
3359
|
-
* _.get(object, 'a.b.c', 'default');
|
|
3360
|
-
* // => 'default'
|
|
3361
|
-
*/
|
|
3362
|
-
function get(object, path, defaultValue) {
|
|
3363
|
-
var result = object == null ? undefined : baseGet(object, path);
|
|
3364
|
-
return result === undefined ? defaultValue : result;
|
|
3365
|
-
}
|
|
3366
|
-
|
|
3367
|
-
const options = {
|
|
3368
|
-
prerender: true,
|
|
3369
|
-
debug: false
|
|
3370
|
-
};
|
|
3371
|
-
|
|
3372
|
-
class Performance {
|
|
3373
|
-
constructor() {
|
|
3374
|
-
this.recorder = new Map();
|
|
3375
|
-
}
|
|
3376
|
-
start(id) {
|
|
3377
|
-
if (!options.debug) {
|
|
3378
|
-
return;
|
|
3379
|
-
}
|
|
3380
|
-
this.recorder.set(id, Date.now());
|
|
3381
|
-
}
|
|
3382
|
-
stop(id) {
|
|
3383
|
-
if (!options.debug) {
|
|
3384
|
-
return;
|
|
2608
|
+
function findCustomWrapper(ctx, dataPathArr) {
|
|
2609
|
+
let currentData = ctx.__data__ || ctx.data || ctx._data;
|
|
2610
|
+
let wrapper;
|
|
2611
|
+
let index;
|
|
2612
|
+
dataPathArr.some((item, i) => {
|
|
2613
|
+
const key = item.replace(/^\[(.+)\]$/, '$1');
|
|
2614
|
+
currentData = currentData[key];
|
|
2615
|
+
if (isUndefined(currentData))
|
|
2616
|
+
return true;
|
|
2617
|
+
if (currentData.nn === CUSTOM_WRAPPER) {
|
|
2618
|
+
wrapper = currentData;
|
|
2619
|
+
index = i;
|
|
3385
2620
|
}
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
2621
|
+
});
|
|
2622
|
+
if (wrapper) {
|
|
2623
|
+
return {
|
|
2624
|
+
wrapper,
|
|
2625
|
+
index: index
|
|
2626
|
+
};
|
|
3391
2627
|
}
|
|
3392
2628
|
}
|
|
3393
|
-
const perf = new Performance();
|
|
3394
|
-
|
|
3395
|
-
const eventIncrementId = incrementId();
|
|
3396
2629
|
let TaroRootElement = class TaroRootElement extends TaroElement {
|
|
3397
|
-
constructor(
|
|
3398
|
-
|
|
3399
|
-
super(nodeImpl, getElement, hooks, elementImpl);
|
|
3400
|
-
this.pendingFlush = false;
|
|
2630
|
+
constructor() {
|
|
2631
|
+
super();
|
|
3401
2632
|
this.updatePayloads = [];
|
|
3402
2633
|
this.updateCallbacks = [];
|
|
3403
2634
|
this.pendingUpdate = false;
|
|
3404
2635
|
this.ctx = null;
|
|
3405
2636
|
this.nodeName = ROOT_STR;
|
|
3406
|
-
this.eventCenter = eventCenter;
|
|
3407
2637
|
}
|
|
3408
2638
|
get _path() {
|
|
3409
2639
|
return ROOT_STR;
|
|
@@ -3413,7 +2643,7 @@ let TaroRootElement = class TaroRootElement extends TaroElement {
|
|
|
3413
2643
|
}
|
|
3414
2644
|
enqueueUpdate(payload) {
|
|
3415
2645
|
this.updatePayloads.push(payload);
|
|
3416
|
-
if (!this.pendingUpdate && this.ctx
|
|
2646
|
+
if (!this.pendingUpdate && this.ctx) {
|
|
3417
2647
|
this.performUpdate();
|
|
3418
2648
|
}
|
|
3419
2649
|
}
|
|
@@ -3441,97 +2671,71 @@ let TaroRootElement = class TaroRootElement extends TaroElement {
|
|
|
3441
2671
|
}
|
|
3442
2672
|
});
|
|
3443
2673
|
const value = data[path];
|
|
3444
|
-
if (isFunction
|
|
2674
|
+
if (isFunction(value)) {
|
|
3445
2675
|
data[path] = value();
|
|
3446
2676
|
}
|
|
3447
2677
|
}
|
|
3448
|
-
|
|
3449
|
-
|
|
2678
|
+
// 预渲染
|
|
2679
|
+
if (isFunction(prerender))
|
|
2680
|
+
return prerender(data);
|
|
2681
|
+
// 正常渲染
|
|
2682
|
+
this.pendingUpdate = false;
|
|
2683
|
+
let normalUpdate = {};
|
|
2684
|
+
const customWrapperMap = new Map();
|
|
2685
|
+
if (initRender) {
|
|
2686
|
+
// 初次渲染,使用页面级别的 setData
|
|
2687
|
+
normalUpdate = data;
|
|
3450
2688
|
}
|
|
3451
2689
|
else {
|
|
3452
|
-
|
|
3453
|
-
const
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
const
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
const
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
const customWrapper = ctx.selectComponent(`#${customWrapperId}`);
|
|
3466
|
-
const splitedPath = dataPathArr.slice(i).join('.');
|
|
3467
|
-
if (customWrapper) {
|
|
3468
|
-
hasCustomWrapper = true;
|
|
3469
|
-
customWrapperMap.set(customWrapper, Object.assign(Object.assign({}, (customWrapperMap.get(customWrapper) || {})), { [`i.${splitedPath}`]: data[p] }));
|
|
3470
|
-
}
|
|
3471
|
-
break;
|
|
3472
|
-
}
|
|
3473
|
-
}
|
|
3474
|
-
if (!hasCustomWrapper) {
|
|
3475
|
-
normalUpdate[p] = data[p];
|
|
2690
|
+
// 更新渲染,区分 CustomWrapper 与页面级别的 setData
|
|
2691
|
+
for (const p in data) {
|
|
2692
|
+
const dataPathArr = p.split('.');
|
|
2693
|
+
const found = findCustomWrapper(ctx, dataPathArr);
|
|
2694
|
+
if (found) {
|
|
2695
|
+
// 此项数据使用 CustomWrapper 去更新
|
|
2696
|
+
const { wrapper, index } = found;
|
|
2697
|
+
const customWrapperId = `#${wrapper.uid}`;
|
|
2698
|
+
const customWrapper = ctx.selectComponent(customWrapperId);
|
|
2699
|
+
if (customWrapper) {
|
|
2700
|
+
const splitedPath = dataPathArr.slice(index + 1).join('.');
|
|
2701
|
+
// 合并同一个 customWrapper 的相关更新到一次 setData 中
|
|
2702
|
+
customWrapperMap.set(customWrapper, Object.assign(Object.assign({}, (customWrapperMap.get(customWrapper) || {})), { [`i.${splitedPath}`]: data[p] }));
|
|
3476
2703
|
}
|
|
3477
2704
|
}
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
});
|
|
2705
|
+
else {
|
|
2706
|
+
// 此项数据使用页面去更新
|
|
2707
|
+
normalUpdate[p] = data[p];
|
|
3482
2708
|
}
|
|
3483
2709
|
}
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
this.flushUpdateCallback();
|
|
3495
|
-
}
|
|
3496
|
-
if (initRender) {
|
|
3497
|
-
perf.stop(PAGE_INIT);
|
|
3498
|
-
}
|
|
3499
|
-
}
|
|
3500
|
-
}, eventCenter);
|
|
3501
|
-
customWrapperUpdate.forEach(item => {
|
|
3502
|
-
if (process.env.NODE_ENV !== 'production' && options.debug) {
|
|
3503
|
-
// eslint-disable-next-line no-console
|
|
3504
|
-
console.log('custom wrapper setData: ', item.data);
|
|
3505
|
-
}
|
|
3506
|
-
item.ctx.setData(item.data, () => {
|
|
3507
|
-
eventCenter.trigger(eventId);
|
|
3508
|
-
});
|
|
3509
|
-
});
|
|
3510
|
-
if (Object.keys(normalUpdate).length) {
|
|
3511
|
-
if (process.env.NODE_ENV !== 'production' && options.debug) {
|
|
3512
|
-
// eslint-disable-next-line no-console
|
|
3513
|
-
console.log('setData:', normalUpdate);
|
|
3514
|
-
}
|
|
3515
|
-
ctx.setData(normalUpdate, () => {
|
|
3516
|
-
eventCenter.trigger(eventId);
|
|
3517
|
-
});
|
|
3518
|
-
}
|
|
2710
|
+
}
|
|
2711
|
+
const customWrpperCount = customWrapperMap.size;
|
|
2712
|
+
const isNeedNormalUpdate = Object.keys(normalUpdate).length > 0;
|
|
2713
|
+
const updateArrLen = customWrpperCount + (isNeedNormalUpdate ? 1 : 0);
|
|
2714
|
+
let executeTime = 0;
|
|
2715
|
+
const cb = () => {
|
|
2716
|
+
if (++executeTime === updateArrLen) {
|
|
2717
|
+
perf.stop(SET_DATA);
|
|
2718
|
+
this.flushUpdateCallback();
|
|
2719
|
+
initRender && perf.stop(PAGE_INIT);
|
|
3519
2720
|
}
|
|
3520
|
-
|
|
2721
|
+
};
|
|
2722
|
+
// custom-wrapper setData
|
|
2723
|
+
if (customWrpperCount) {
|
|
2724
|
+
customWrapperMap.forEach((data, ctx) => {
|
|
3521
2725
|
if (process.env.NODE_ENV !== 'production' && options.debug) {
|
|
3522
2726
|
// eslint-disable-next-line no-console
|
|
3523
|
-
console.log('setData:', data);
|
|
2727
|
+
console.log('custom wrapper setData: ', data);
|
|
3524
2728
|
}
|
|
3525
|
-
ctx.setData(data,
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
});
|
|
2729
|
+
ctx.setData(data, cb);
|
|
2730
|
+
});
|
|
2731
|
+
}
|
|
2732
|
+
// page setData
|
|
2733
|
+
if (isNeedNormalUpdate) {
|
|
2734
|
+
if (process.env.NODE_ENV !== 'production' && options.debug) {
|
|
2735
|
+
// eslint-disable-next-line no-console
|
|
2736
|
+
console.log('page setData:', normalUpdate);
|
|
3534
2737
|
}
|
|
2738
|
+
ctx.setData(normalUpdate, cb);
|
|
3535
2739
|
}
|
|
3536
2740
|
}, 0);
|
|
3537
2741
|
}
|
|
@@ -3541,8 +2745,10 @@ let TaroRootElement = class TaroRootElement extends TaroElement {
|
|
|
3541
2745
|
});
|
|
3542
2746
|
}
|
|
3543
2747
|
flushUpdateCallback() {
|
|
3544
|
-
|
|
3545
|
-
|
|
2748
|
+
const updateCallbacks = this.updateCallbacks;
|
|
2749
|
+
if (!updateCallbacks.length)
|
|
2750
|
+
return;
|
|
2751
|
+
const copies = updateCallbacks.slice(0);
|
|
3546
2752
|
this.updateCallbacks.length = 0;
|
|
3547
2753
|
for (let i = 0; i < copies.length; i++) {
|
|
3548
2754
|
copies[i]();
|
|
@@ -3551,12 +2757,7 @@ let TaroRootElement = class TaroRootElement extends TaroElement {
|
|
|
3551
2757
|
};
|
|
3552
2758
|
TaroRootElement = __decorate([
|
|
3553
2759
|
injectable(),
|
|
3554
|
-
|
|
3555
|
-
__param(1, inject(SERVICE_IDENTIFIER.TaroElementFactory)),
|
|
3556
|
-
__param(2, inject(SERVICE_IDENTIFIER.Hooks)),
|
|
3557
|
-
__param(3, inject(SERVICE_IDENTIFIER.TaroElementImpl)),
|
|
3558
|
-
__param(4, inject(SERVICE_IDENTIFIER.eventCenter)),
|
|
3559
|
-
__metadata("design:paramtypes", [Function, Function, Function, Function, Function])
|
|
2760
|
+
__metadata("design:paramtypes", [])
|
|
3560
2761
|
], TaroRootElement);
|
|
3561
2762
|
|
|
3562
2763
|
class FormElement extends TaroElement {
|
|
@@ -3589,6 +2790,108 @@ class FormElement extends TaroElement {
|
|
|
3589
2790
|
class SVGElement extends TaroElement {
|
|
3590
2791
|
}
|
|
3591
2792
|
|
|
2793
|
+
// Taro 事件对象。以 Web 标准的事件对象为基础,加入小程序事件对象中携带的部分信息,并模拟实现事件冒泡。
|
|
2794
|
+
class TaroEvent {
|
|
2795
|
+
constructor(type, opts, event) {
|
|
2796
|
+
this._stop = false;
|
|
2797
|
+
this._end = false;
|
|
2798
|
+
this.defaultPrevented = false;
|
|
2799
|
+
// timestamp can either be hi-res ( relative to page load) or low-res (relative to UNIX epoch)
|
|
2800
|
+
// here use hi-res timestamp
|
|
2801
|
+
this.timeStamp = Date.now();
|
|
2802
|
+
this.type = type.toLowerCase();
|
|
2803
|
+
this.mpEvent = event;
|
|
2804
|
+
this.bubbles = Boolean(opts && opts.bubbles);
|
|
2805
|
+
this.cancelable = Boolean(opts && opts.cancelable);
|
|
2806
|
+
}
|
|
2807
|
+
stopPropagation() {
|
|
2808
|
+
this._stop = true;
|
|
2809
|
+
}
|
|
2810
|
+
stopImmediatePropagation() {
|
|
2811
|
+
this._end = this._stop = true;
|
|
2812
|
+
}
|
|
2813
|
+
preventDefault() {
|
|
2814
|
+
this.defaultPrevented = true;
|
|
2815
|
+
}
|
|
2816
|
+
get target() {
|
|
2817
|
+
var _a, _b, _c;
|
|
2818
|
+
const element = getDocument().getElementById((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.target.id);
|
|
2819
|
+
return Object.assign(Object.assign(Object.assign({}, (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.target), (_c = this.mpEvent) === null || _c === void 0 ? void 0 : _c.detail), { dataset: element !== null ? element.dataset : EMPTY_OBJ });
|
|
2820
|
+
}
|
|
2821
|
+
get currentTarget() {
|
|
2822
|
+
var _a, _b, _c;
|
|
2823
|
+
const element = getDocument().getElementById((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.currentTarget.id);
|
|
2824
|
+
if (element === null) {
|
|
2825
|
+
return this.target;
|
|
2826
|
+
}
|
|
2827
|
+
return Object.assign(Object.assign(Object.assign({}, (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.currentTarget), (_c = this.mpEvent) === null || _c === void 0 ? void 0 : _c.detail), { dataset: element.dataset });
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
function createEvent(event, node) {
|
|
2831
|
+
if (typeof event === 'string') {
|
|
2832
|
+
// For Vue3 using document.createEvent
|
|
2833
|
+
return new TaroEvent(event, { bubbles: true, cancelable: true });
|
|
2834
|
+
}
|
|
2835
|
+
const domEv = new TaroEvent(event.type, { bubbles: true, cancelable: true }, event);
|
|
2836
|
+
for (const key in event) {
|
|
2837
|
+
if (key === CURRENT_TARGET || key === TARGET || key === TYPE || key === TIME_STAMP) {
|
|
2838
|
+
continue;
|
|
2839
|
+
}
|
|
2840
|
+
else {
|
|
2841
|
+
domEv[key] = event[key];
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
if (domEv.type === CONFIRM && (node === null || node === void 0 ? void 0 : node.nodeName) === INPUT) {
|
|
2845
|
+
// eslint-disable-next-line dot-notation
|
|
2846
|
+
domEv[KEY_CODE] = 13;
|
|
2847
|
+
}
|
|
2848
|
+
return domEv;
|
|
2849
|
+
}
|
|
2850
|
+
const eventsBatch = {};
|
|
2851
|
+
// 小程序的事件代理回调函数
|
|
2852
|
+
function eventHandler(event) {
|
|
2853
|
+
var _a, _b;
|
|
2854
|
+
const hooks = getHooks();
|
|
2855
|
+
(_a = hooks.modifyMpEvent) === null || _a === void 0 ? void 0 : _a.call(hooks, event);
|
|
2856
|
+
event.currentTarget || (event.currentTarget = event.target);
|
|
2857
|
+
const currentTarget = event.currentTarget;
|
|
2858
|
+
const id = ((_b = currentTarget.dataset) === null || _b === void 0 ? void 0 : _b.sid /** sid */) || currentTarget.id /** uid */ || '';
|
|
2859
|
+
const node = getDocument().getElementById(id);
|
|
2860
|
+
if (node) {
|
|
2861
|
+
const dispatch = () => {
|
|
2862
|
+
var _a;
|
|
2863
|
+
const e = createEvent(event, node);
|
|
2864
|
+
(_a = hooks.modifyTaroEvent) === null || _a === void 0 ? void 0 : _a.call(hooks, e, node);
|
|
2865
|
+
node.dispatchEvent(e);
|
|
2866
|
+
};
|
|
2867
|
+
if (isFunction(hooks.batchedEventUpdates)) {
|
|
2868
|
+
const type = event.type;
|
|
2869
|
+
if (!hooks.isBubbleEvents(type) ||
|
|
2870
|
+
!isParentBinded(node, type) ||
|
|
2871
|
+
(type === TOUCHMOVE && !!node.props.catchMove)) {
|
|
2872
|
+
// 最上层组件统一 batchUpdate
|
|
2873
|
+
hooks.batchedEventUpdates(() => {
|
|
2874
|
+
if (eventsBatch[type]) {
|
|
2875
|
+
eventsBatch[type].forEach(fn => fn());
|
|
2876
|
+
delete eventsBatch[type];
|
|
2877
|
+
}
|
|
2878
|
+
dispatch();
|
|
2879
|
+
});
|
|
2880
|
+
}
|
|
2881
|
+
else {
|
|
2882
|
+
// 如果上层组件也有绑定同类型的组件,委托给上层组件调用事件回调
|
|
2883
|
+
(eventsBatch[type] || (eventsBatch[type] = [])).push(dispatch);
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
else {
|
|
2887
|
+
dispatch();
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
|
|
2892
|
+
const doc = process.env.TARO_ENV === 'h5' ? document : EMPTY_OBJ;
|
|
2893
|
+
const win = process.env.TARO_ENV === 'h5' ? window : EMPTY_OBJ;
|
|
2894
|
+
|
|
3592
2895
|
function initPosition() {
|
|
3593
2896
|
return {
|
|
3594
2897
|
index: 0,
|
|
@@ -4222,7 +3525,7 @@ function format(children, document, styleOptions, parent) {
|
|
|
4222
3525
|
// 文本节点
|
|
4223
3526
|
if (child.type === 'text') {
|
|
4224
3527
|
let text = document.createTextNode(child.content);
|
|
4225
|
-
if (isFunction
|
|
3528
|
+
if (isFunction(options.html.transformText)) {
|
|
4226
3529
|
text = options.html.transformText(text, child);
|
|
4227
3530
|
}
|
|
4228
3531
|
parent === null || parent === void 0 ? void 0 : parent.appendChild(text);
|
|
@@ -4256,7 +3559,7 @@ function format(children, document, styleOptions, parent) {
|
|
|
4256
3559
|
styleTagParser,
|
|
4257
3560
|
descendantList: list
|
|
4258
3561
|
}, el);
|
|
4259
|
-
if (isFunction
|
|
3562
|
+
if (isFunction(options.html.transformElement)) {
|
|
4260
3563
|
return options.html.transformElement(el, child);
|
|
4261
3564
|
}
|
|
4262
3565
|
return el;
|
|
@@ -4386,7 +3689,7 @@ function setInnerHTML(element, html, getDoc) {
|
|
|
4386
3689
|
* An implementation of `Element.insertAdjacentHTML()`
|
|
4387
3690
|
* to support Vue 3 with a version of or greater than `vue@3.1.2`
|
|
4388
3691
|
*/
|
|
4389
|
-
function insertAdjacentHTMLImpl(position, html
|
|
3692
|
+
function insertAdjacentHTMLImpl(getDoc, position, html) {
|
|
4390
3693
|
var _a, _b;
|
|
4391
3694
|
const parsedNodes = parser(html, getDoc());
|
|
4392
3695
|
for (let i = 0; i < parsedNodes.length; i++) {
|
|
@@ -4412,13 +3715,13 @@ function insertAdjacentHTMLImpl(position, html, getDoc) {
|
|
|
4412
3715
|
}
|
|
4413
3716
|
}
|
|
4414
3717
|
}
|
|
4415
|
-
function cloneNode(
|
|
3718
|
+
function cloneNode(getDoc, isDeep = false) {
|
|
4416
3719
|
const document = getDoc();
|
|
4417
3720
|
let newNode;
|
|
4418
|
-
if (
|
|
4419
|
-
newNode = document.createElement(
|
|
3721
|
+
if (this.nodeType === 1 /* ELEMENT_NODE */) {
|
|
3722
|
+
newNode = document.createElement(this.nodeName);
|
|
4420
3723
|
}
|
|
4421
|
-
else if (
|
|
3724
|
+
else if (this.nodeType === 3 /* TEXT_NODE */) {
|
|
4422
3725
|
newNode = document.createTextNode('');
|
|
4423
3726
|
}
|
|
4424
3727
|
for (const key in this) {
|
|
@@ -4435,9 +3738,20 @@ function cloneNode(ctx, getDoc, isDeep = false) {
|
|
|
4435
3738
|
}
|
|
4436
3739
|
}
|
|
4437
3740
|
if (isDeep) {
|
|
4438
|
-
newNode.childNodes =
|
|
3741
|
+
newNode.childNodes = this.childNodes.map(node => node.cloneNode(true));
|
|
4439
3742
|
}
|
|
4440
3743
|
return newNode;
|
|
3744
|
+
}
|
|
3745
|
+
function contains(node) {
|
|
3746
|
+
let isContains = false;
|
|
3747
|
+
this.childNodes.some(childNode => {
|
|
3748
|
+
const { uid } = childNode;
|
|
3749
|
+
if (uid === node.uid || uid === node.id || childNode.contains(node)) {
|
|
3750
|
+
isContains = true;
|
|
3751
|
+
return true;
|
|
3752
|
+
}
|
|
3753
|
+
});
|
|
3754
|
+
return isContains;
|
|
4441
3755
|
}
|
|
4442
3756
|
|
|
4443
3757
|
let TaroNodeImpl = class TaroNodeImpl {
|
|
@@ -4450,11 +3764,14 @@ let TaroNodeImpl = class TaroNodeImpl {
|
|
|
4450
3764
|
if (ENABLE_INNER_HTML) {
|
|
4451
3765
|
bindInnerHTML(ctx, getDoc);
|
|
4452
3766
|
if (ENABLE_ADJACENT_HTML) {
|
|
4453
|
-
|
|
3767
|
+
ctx.insertAdjacentHTML = insertAdjacentHTMLImpl.bind(ctx, getDoc);
|
|
4454
3768
|
}
|
|
4455
3769
|
}
|
|
4456
3770
|
if (ENABLE_CLONE_NODE) {
|
|
4457
|
-
ctx.cloneNode = cloneNode.bind(ctx,
|
|
3771
|
+
ctx.cloneNode = cloneNode.bind(ctx, getDoc);
|
|
3772
|
+
}
|
|
3773
|
+
if (ENABLE_CONTAINS) {
|
|
3774
|
+
ctx.contains = contains.bind(ctx);
|
|
4458
3775
|
}
|
|
4459
3776
|
}
|
|
4460
3777
|
};
|
|
@@ -4468,17 +3785,12 @@ function bindInnerHTML(ctx, getDoc) {
|
|
|
4468
3785
|
configurable: true,
|
|
4469
3786
|
enumerable: true,
|
|
4470
3787
|
set(html) {
|
|
4471
|
-
setInnerHTML.call(
|
|
3788
|
+
setInnerHTML.call(this, this, html, getDoc);
|
|
4472
3789
|
},
|
|
4473
3790
|
get() {
|
|
4474
3791
|
return '';
|
|
4475
3792
|
}
|
|
4476
3793
|
});
|
|
4477
|
-
}
|
|
4478
|
-
function bindAdjacentHTML(ctx, getDoc) {
|
|
4479
|
-
ctx.insertAdjacentHTML = function (position, html) {
|
|
4480
|
-
insertAdjacentHTMLImpl.call(ctx, position, html, getDoc);
|
|
4481
|
-
};
|
|
4482
3794
|
}
|
|
4483
3795
|
|
|
4484
3796
|
function getBoundingClientRectImpl() {
|
|
@@ -4507,9 +3819,7 @@ function getTemplateContent(ctx) {
|
|
|
4507
3819
|
let TaroElementImpl = class TaroElementImpl {
|
|
4508
3820
|
bind(ctx) {
|
|
4509
3821
|
if (ENABLE_SIZE_APIS) {
|
|
4510
|
-
ctx.getBoundingClientRect =
|
|
4511
|
-
return await getBoundingClientRectImpl.apply(ctx, args);
|
|
4512
|
-
};
|
|
3822
|
+
ctx.getBoundingClientRect = getBoundingClientRectImpl.bind(ctx);
|
|
4513
3823
|
}
|
|
4514
3824
|
if (ENABLE_TEMPLATE_CONTENT) {
|
|
4515
3825
|
bindContent(ctx);
|
|
@@ -4531,20 +3841,21 @@ function bindContent(ctx) {
|
|
|
4531
3841
|
|
|
4532
3842
|
let TaroDocument = class TaroDocument extends TaroElement {
|
|
4533
3843
|
constructor(// eslint-disable-next-line @typescript-eslint/indent
|
|
4534
|
-
|
|
4535
|
-
super(
|
|
3844
|
+
getText) {
|
|
3845
|
+
super();
|
|
4536
3846
|
this._getText = getText;
|
|
4537
3847
|
this.nodeType = 9 /* DOCUMENT_NODE */;
|
|
4538
3848
|
this.nodeName = DOCUMENT_ELEMENT_NAME;
|
|
4539
3849
|
}
|
|
4540
3850
|
createElement(type) {
|
|
3851
|
+
const getElement = this._getElement;
|
|
4541
3852
|
if (type === ROOT_STR) {
|
|
4542
|
-
return
|
|
3853
|
+
return getElement(ElementNames.RootElement)();
|
|
4543
3854
|
}
|
|
4544
3855
|
if (controlledComponent.has(type)) {
|
|
4545
|
-
return
|
|
3856
|
+
return getElement(ElementNames.FormElement)(type);
|
|
4546
3857
|
}
|
|
4547
|
-
return
|
|
3858
|
+
return getElement(ElementNames.Element)(type);
|
|
4548
3859
|
}
|
|
4549
3860
|
// an ugly fake createElementNS to deal with @vue/runtime-dom's
|
|
4550
3861
|
// support mounting app to svg container since vue@3.0.8
|
|
@@ -4578,23 +3889,109 @@ let TaroDocument = class TaroDocument extends TaroElement {
|
|
|
4578
3889
|
};
|
|
4579
3890
|
TaroDocument = __decorate([
|
|
4580
3891
|
injectable(),
|
|
4581
|
-
__param(0, inject(
|
|
4582
|
-
|
|
4583
|
-
__param(2, inject(SERVICE_IDENTIFIER.Hooks)),
|
|
4584
|
-
__param(3, inject(SERVICE_IDENTIFIER.TaroElementImpl)),
|
|
4585
|
-
__param(4, inject(SERVICE_IDENTIFIER.TaroTextFactory)),
|
|
4586
|
-
__metadata("design:paramtypes", [Function, Function, Function, Function, Function])
|
|
3892
|
+
__param(0, inject(SID_TARO_TEXT_FACTORY)),
|
|
3893
|
+
__metadata("design:paramtypes", [Function])
|
|
4587
3894
|
], TaroDocument);
|
|
4588
3895
|
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
3896
|
+
/**
|
|
3897
|
+
* 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
|
|
3898
|
+
* 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
|
|
3899
|
+
*/
|
|
3900
|
+
const BUBBLE_EVENTS = new Set([
|
|
3901
|
+
'touchstart',
|
|
3902
|
+
'touchmove',
|
|
3903
|
+
'touchcancel',
|
|
3904
|
+
'touchend',
|
|
3905
|
+
'touchforcechange',
|
|
3906
|
+
'tap',
|
|
3907
|
+
'longpress',
|
|
3908
|
+
'longtap',
|
|
3909
|
+
'transitionend',
|
|
3910
|
+
'animationstart',
|
|
3911
|
+
'animationiteration',
|
|
3912
|
+
'animationend'
|
|
3913
|
+
]);
|
|
3914
|
+
|
|
3915
|
+
const defaultMiniLifecycle = {
|
|
3916
|
+
app: [
|
|
3917
|
+
'onLaunch',
|
|
3918
|
+
'onShow',
|
|
3919
|
+
'onHide'
|
|
3920
|
+
],
|
|
3921
|
+
page: [
|
|
3922
|
+
'onLoad',
|
|
3923
|
+
'onUnload',
|
|
3924
|
+
'onReady',
|
|
3925
|
+
'onShow',
|
|
3926
|
+
'onHide',
|
|
3927
|
+
[
|
|
3928
|
+
'onPullDownRefresh',
|
|
3929
|
+
'onReachBottom',
|
|
3930
|
+
'onPageScroll',
|
|
3931
|
+
'onResize',
|
|
3932
|
+
'onTabItemTap',
|
|
3933
|
+
'onTitleClick',
|
|
3934
|
+
'onOptionMenuClick',
|
|
3935
|
+
'onPopMenuClick',
|
|
3936
|
+
'onPullIntercept',
|
|
3937
|
+
'onAddToFavorites'
|
|
3938
|
+
]
|
|
3939
|
+
]
|
|
3940
|
+
};
|
|
3941
|
+
const getMiniLifecycle = function (defaultConfig) {
|
|
3942
|
+
return defaultConfig;
|
|
3943
|
+
};
|
|
3944
|
+
const getLifecycle = function (instance, lifecycle) {
|
|
3945
|
+
return instance[lifecycle];
|
|
3946
|
+
};
|
|
3947
|
+
const getPathIndex = function (indexOfNode) {
|
|
3948
|
+
return `[${indexOfNode}]`;
|
|
3949
|
+
};
|
|
3950
|
+
const getEventCenter = function (Events) {
|
|
3951
|
+
return new Events();
|
|
3952
|
+
};
|
|
3953
|
+
const isBubbleEvents = function (eventName) {
|
|
3954
|
+
return BUBBLE_EVENTS.has(eventName);
|
|
3955
|
+
};
|
|
3956
|
+
const getSpecialNodes = function () {
|
|
3957
|
+
return ['view', 'text', 'image'];
|
|
3958
|
+
};
|
|
3959
|
+
const DefaultHooksContainer = new ContainerModule(bind => {
|
|
3960
|
+
function bindFunction(sid, target) {
|
|
3961
|
+
return bind(sid).toFunction(target);
|
|
3962
|
+
}
|
|
3963
|
+
bindFunction(SID_GET_MINI_LIFECYCLE, getMiniLifecycle);
|
|
3964
|
+
bindFunction(SID_GET_LIFECYCLE, getLifecycle);
|
|
3965
|
+
bindFunction(SID_GET_PATH_INDEX, getPathIndex);
|
|
3966
|
+
bindFunction(SID_GET_EVENT_CENTER, getEventCenter);
|
|
3967
|
+
bindFunction(SID_IS_BUBBLE_EVENTS, isBubbleEvents);
|
|
3968
|
+
bindFunction(SID_GET_SPECIAL_NODES, getSpecialNodes);
|
|
3969
|
+
});
|
|
3970
|
+
|
|
3971
|
+
let Hooks = class Hooks {
|
|
3972
|
+
getMiniLifecycleImpl() {
|
|
3973
|
+
return this.getMiniLifecycle(defaultMiniLifecycle);
|
|
3974
|
+
}
|
|
3975
|
+
modifyMpEvent(e) {
|
|
3976
|
+
var _a;
|
|
3977
|
+
(_a = this.modifyMpEventImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => {
|
|
3978
|
+
try {
|
|
3979
|
+
// 有些小程序的事件对象的某些属性只读
|
|
3980
|
+
fn(e);
|
|
3981
|
+
}
|
|
3982
|
+
catch (error) {
|
|
3983
|
+
console.warn('[Taro modifyMpEvent hook Error]: ', error);
|
|
3984
|
+
}
|
|
3985
|
+
});
|
|
3986
|
+
}
|
|
3987
|
+
modifyTaroEvent(e, element) {
|
|
3988
|
+
var _a;
|
|
4596
3989
|
(_a = this.modifyTaroEventImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(e, element));
|
|
4597
3990
|
}
|
|
3991
|
+
modifyDispatchEvent(e, element) {
|
|
3992
|
+
var _a;
|
|
3993
|
+
(_a = this.modifyDispatchEventImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(e, element));
|
|
3994
|
+
}
|
|
4598
3995
|
initNativeApi(taro) {
|
|
4599
3996
|
var _a;
|
|
4600
3997
|
(_a = this.initNativeApiImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(taro));
|
|
@@ -4605,87 +4002,101 @@ let Hooks = class Hooks {
|
|
|
4605
4002
|
}
|
|
4606
4003
|
};
|
|
4607
4004
|
__decorate([
|
|
4608
|
-
inject(
|
|
4005
|
+
inject(SID_GET_MINI_LIFECYCLE),
|
|
4006
|
+
__metadata("design:type", Function)
|
|
4007
|
+
], Hooks.prototype, "getMiniLifecycle", void 0);
|
|
4008
|
+
__decorate([
|
|
4009
|
+
inject(SID_GET_LIFECYCLE),
|
|
4609
4010
|
__metadata("design:type", Function)
|
|
4610
4011
|
], Hooks.prototype, "getLifecycle", void 0);
|
|
4611
4012
|
__decorate([
|
|
4612
|
-
inject(
|
|
4013
|
+
inject(SID_GET_PATH_INDEX),
|
|
4613
4014
|
__metadata("design:type", Function)
|
|
4614
4015
|
], Hooks.prototype, "getPathIndex", void 0);
|
|
4615
4016
|
__decorate([
|
|
4616
|
-
inject(
|
|
4017
|
+
inject(SID_GET_EVENT_CENTER),
|
|
4617
4018
|
__metadata("design:type", Function)
|
|
4618
4019
|
], Hooks.prototype, "getEventCenter", void 0);
|
|
4619
4020
|
__decorate([
|
|
4620
|
-
inject(
|
|
4021
|
+
inject(SID_IS_BUBBLE_EVENTS),
|
|
4621
4022
|
__metadata("design:type", Function)
|
|
4622
4023
|
], Hooks.prototype, "isBubbleEvents", void 0);
|
|
4623
4024
|
__decorate([
|
|
4624
|
-
inject(
|
|
4025
|
+
inject(SID_GET_SPECIAL_NODES),
|
|
4625
4026
|
__metadata("design:type", Function)
|
|
4626
4027
|
], Hooks.prototype, "getSpecialNodes", void 0);
|
|
4627
4028
|
__decorate([
|
|
4628
|
-
inject(
|
|
4029
|
+
inject(SID_ON_REMOVE_ATTRIBUTE),
|
|
4629
4030
|
optional(),
|
|
4630
4031
|
__metadata("design:type", Function)
|
|
4631
4032
|
], Hooks.prototype, "onRemoveAttribute", void 0);
|
|
4632
4033
|
__decorate([
|
|
4633
|
-
inject(
|
|
4034
|
+
inject(SID_BATCHED_EVENT_UPDATES),
|
|
4634
4035
|
optional(),
|
|
4635
4036
|
__metadata("design:type", Function)
|
|
4636
4037
|
], Hooks.prototype, "batchedEventUpdates", void 0);
|
|
4637
4038
|
__decorate([
|
|
4638
|
-
inject(
|
|
4039
|
+
inject(SID_MERGE_PAGE_INSTANCE),
|
|
4639
4040
|
optional(),
|
|
4640
4041
|
__metadata("design:type", Function)
|
|
4641
4042
|
], Hooks.prototype, "mergePageInstance", void 0);
|
|
4642
4043
|
__decorate([
|
|
4643
|
-
inject(
|
|
4044
|
+
inject(SID_MODIFY_PAGE_OBJECT),
|
|
4045
|
+
optional(),
|
|
4046
|
+
__metadata("design:type", Function)
|
|
4047
|
+
], Hooks.prototype, "modifyPageObject", void 0);
|
|
4048
|
+
__decorate([
|
|
4049
|
+
inject(SID_CREATE_PULLDOWN_COMPONENT),
|
|
4644
4050
|
optional(),
|
|
4645
4051
|
__metadata("design:type", Function)
|
|
4646
4052
|
], Hooks.prototype, "createPullDownComponent", void 0);
|
|
4647
4053
|
__decorate([
|
|
4648
|
-
inject(
|
|
4054
|
+
inject(SID_GET_DOM_NODE),
|
|
4649
4055
|
optional(),
|
|
4650
4056
|
__metadata("design:type", Function)
|
|
4651
4057
|
], Hooks.prototype, "getDOMNode", void 0);
|
|
4652
4058
|
__decorate([
|
|
4653
|
-
inject(
|
|
4059
|
+
inject(SID_MODIFY_HYDRATE_DATA),
|
|
4654
4060
|
optional(),
|
|
4655
4061
|
__metadata("design:type", Function)
|
|
4656
4062
|
], Hooks.prototype, "modifyHydrateData", void 0);
|
|
4657
4063
|
__decorate([
|
|
4658
|
-
inject(
|
|
4064
|
+
inject(SID_MODIFY_SET_ATTR_PAYLOAD),
|
|
4659
4065
|
optional(),
|
|
4660
4066
|
__metadata("design:type", Function)
|
|
4661
4067
|
], Hooks.prototype, "modifySetAttrPayload", void 0);
|
|
4662
4068
|
__decorate([
|
|
4663
|
-
inject(
|
|
4069
|
+
inject(SID_MODIFY_RM_ATTR_PAYLOAD),
|
|
4664
4070
|
optional(),
|
|
4665
4071
|
__metadata("design:type", Function)
|
|
4666
4072
|
], Hooks.prototype, "modifyRmAttrPayload", void 0);
|
|
4667
4073
|
__decorate([
|
|
4668
|
-
inject(
|
|
4074
|
+
inject(SID_ON_ADD_EVENT),
|
|
4669
4075
|
optional(),
|
|
4670
4076
|
__metadata("design:type", Function)
|
|
4671
4077
|
], Hooks.prototype, "onAddEvent", void 0);
|
|
4672
4078
|
__decorate([
|
|
4673
|
-
multiInject(
|
|
4079
|
+
multiInject(SID_MODIFY_MP_EVENT),
|
|
4674
4080
|
optional(),
|
|
4675
4081
|
__metadata("design:type", Array)
|
|
4676
4082
|
], Hooks.prototype, "modifyMpEventImpls", void 0);
|
|
4677
4083
|
__decorate([
|
|
4678
|
-
multiInject(
|
|
4084
|
+
multiInject(SID_MODIFY_TARO_EVENT),
|
|
4679
4085
|
optional(),
|
|
4680
4086
|
__metadata("design:type", Array)
|
|
4681
4087
|
], Hooks.prototype, "modifyTaroEventImpls", void 0);
|
|
4682
4088
|
__decorate([
|
|
4683
|
-
multiInject(
|
|
4089
|
+
multiInject(SID_MODIFY_DISPATCH_EVENT),
|
|
4090
|
+
optional(),
|
|
4091
|
+
__metadata("design:type", Array)
|
|
4092
|
+
], Hooks.prototype, "modifyDispatchEventImpls", void 0);
|
|
4093
|
+
__decorate([
|
|
4094
|
+
multiInject(SID_INIT_NATIVE_API),
|
|
4684
4095
|
optional(),
|
|
4685
4096
|
__metadata("design:type", Array)
|
|
4686
4097
|
], Hooks.prototype, "initNativeApiImpls", void 0);
|
|
4687
4098
|
__decorate([
|
|
4688
|
-
multiInject(
|
|
4099
|
+
multiInject(SID_PATCH_ELEMENT),
|
|
4689
4100
|
optional(),
|
|
4690
4101
|
__metadata("design:type", Array)
|
|
4691
4102
|
], Hooks.prototype, "patchElementImpls", void 0);
|
|
@@ -4693,48 +4104,6 @@ Hooks = __decorate([
|
|
|
4693
4104
|
injectable()
|
|
4694
4105
|
], Hooks);
|
|
4695
4106
|
|
|
4696
|
-
/**
|
|
4697
|
-
* 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
|
|
4698
|
-
* 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
|
|
4699
|
-
*/
|
|
4700
|
-
const BUBBLE_EVENTS = new Set([
|
|
4701
|
-
'touchstart',
|
|
4702
|
-
'touchmove',
|
|
4703
|
-
'touchcancel',
|
|
4704
|
-
'touchend',
|
|
4705
|
-
'touchforcechange',
|
|
4706
|
-
'tap',
|
|
4707
|
-
'longpress',
|
|
4708
|
-
'longtap',
|
|
4709
|
-
'transitionend',
|
|
4710
|
-
'animationstart',
|
|
4711
|
-
'animationiteration',
|
|
4712
|
-
'animationend'
|
|
4713
|
-
]);
|
|
4714
|
-
|
|
4715
|
-
const getLifecycle = function (instance, lifecycle) {
|
|
4716
|
-
return instance[lifecycle];
|
|
4717
|
-
};
|
|
4718
|
-
const getPathIndex = function (indexOfNode) {
|
|
4719
|
-
return `[${indexOfNode}]`;
|
|
4720
|
-
};
|
|
4721
|
-
const getEventCenter = function (Events) {
|
|
4722
|
-
return new Events();
|
|
4723
|
-
};
|
|
4724
|
-
const isBubbleEvents = function (eventName) {
|
|
4725
|
-
return BUBBLE_EVENTS.has(eventName);
|
|
4726
|
-
};
|
|
4727
|
-
const getSpecialNodes = function () {
|
|
4728
|
-
return ['view', 'text', 'image'];
|
|
4729
|
-
};
|
|
4730
|
-
const DefaultHooksContainer = new ContainerModule(bind => {
|
|
4731
|
-
bind(SERVICE_IDENTIFIER.getLifecycle).toFunction(getLifecycle);
|
|
4732
|
-
bind(SERVICE_IDENTIFIER.getPathIndex).toFunction(getPathIndex);
|
|
4733
|
-
bind(SERVICE_IDENTIFIER.getEventCenter).toFunction(getEventCenter);
|
|
4734
|
-
bind(SERVICE_IDENTIFIER.isBubbleEvents).toFunction(isBubbleEvents);
|
|
4735
|
-
bind(SERVICE_IDENTIFIER.getSpecialNodes).toFunction(getSpecialNodes);
|
|
4736
|
-
});
|
|
4737
|
-
|
|
4738
4107
|
function processPluginHooks(container) {
|
|
4739
4108
|
const keys = Object.keys(defaultReconciler);
|
|
4740
4109
|
keys.forEach(key => {
|
|
@@ -4742,7 +4111,7 @@ function processPluginHooks(container) {
|
|
|
4742
4111
|
// is hooks
|
|
4743
4112
|
const identifier = SERVICE_IDENTIFIER[key];
|
|
4744
4113
|
const fn = defaultReconciler[key];
|
|
4745
|
-
if (isArray
|
|
4114
|
+
if (isArray(fn)) {
|
|
4746
4115
|
// is multi
|
|
4747
4116
|
fn.forEach(item => container.bind(identifier).toFunction(item));
|
|
4748
4117
|
}
|
|
@@ -4760,14 +4129,27 @@ function processPluginHooks(container) {
|
|
|
4760
4129
|
}
|
|
4761
4130
|
|
|
4762
4131
|
const container = new Container();
|
|
4132
|
+
function bind(sid, target, options = {}) {
|
|
4133
|
+
let res = container.bind(sid).to(target);
|
|
4134
|
+
if (options.single) {
|
|
4135
|
+
res = res.inSingletonScope();
|
|
4136
|
+
}
|
|
4137
|
+
if (options.name) {
|
|
4138
|
+
res = res.whenTargetNamed(options.name);
|
|
4139
|
+
}
|
|
4140
|
+
return res;
|
|
4141
|
+
}
|
|
4763
4142
|
if (process.env.TARO_ENV !== 'h5') {
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4143
|
+
bind(SID_TARO_TEXT, TaroText);
|
|
4144
|
+
bind(SID_TARO_ELEMENT, TaroElement, { name: ElementNames.Element });
|
|
4145
|
+
bind(SID_TARO_ELEMENT, TaroRootElement, { name: ElementNames.RootElement });
|
|
4146
|
+
bind(SID_TARO_ELEMENT, FormElement, { name: ElementNames.FormElement });
|
|
4147
|
+
bind(SID_TARO_ELEMENT, TaroDocument, { name: ElementNames.Document, single: true });
|
|
4148
|
+
bind(SID_TARO_NODE_IMPL, TaroNodeImpl, { single: true });
|
|
4149
|
+
bind(SID_TARO_ELEMENT_IMPL, TaroElementImpl, { single: true });
|
|
4150
|
+
container.bind(SID_TARO_ELEMENT_FACTORY).toFactory((context) => {
|
|
4769
4151
|
return (named) => (nodeName) => {
|
|
4770
|
-
const el = context.container.getNamed(
|
|
4152
|
+
const el = context.container.getNamed(SID_TARO_ELEMENT, named);
|
|
4771
4153
|
if (nodeName) {
|
|
4772
4154
|
el.nodeName = nodeName;
|
|
4773
4155
|
}
|
|
@@ -4775,130 +4157,18 @@ if (process.env.TARO_ENV !== 'h5') {
|
|
|
4775
4157
|
return el;
|
|
4776
4158
|
};
|
|
4777
4159
|
});
|
|
4778
|
-
container.bind(
|
|
4779
|
-
container.bind(SERVICE_IDENTIFIER.TaroTextFactory).toFactory((context) => {
|
|
4160
|
+
container.bind(SID_TARO_TEXT_FACTORY).toFactory((context) => {
|
|
4780
4161
|
return (text) => {
|
|
4781
|
-
const textNode = context.container.get(
|
|
4162
|
+
const textNode = context.container.get(SID_TARO_TEXT);
|
|
4782
4163
|
textNode._value = text;
|
|
4783
4164
|
return textNode;
|
|
4784
4165
|
};
|
|
4785
4166
|
});
|
|
4786
|
-
container.bind(SERVICE_IDENTIFIER.TaroNodeImpl).to(TaroNodeImpl).inSingletonScope();
|
|
4787
|
-
container.bind(SERVICE_IDENTIFIER.TaroElementImpl).to(TaroElementImpl).inSingletonScope();
|
|
4788
4167
|
}
|
|
4789
|
-
|
|
4168
|
+
bind(SID_HOOKS, Hooks, { single: true });
|
|
4790
4169
|
container.load(DefaultHooksContainer);
|
|
4791
|
-
processPluginHooks(container);
|
|
4792
|
-
|
|
4793
|
-
let hooks;
|
|
4794
|
-
let getElement;
|
|
4795
|
-
let document$1;
|
|
4796
|
-
if (process.env.TARO_ENV !== 'h5') {
|
|
4797
|
-
hooks = container.get(SERVICE_IDENTIFIER.Hooks);
|
|
4798
|
-
getElement = container.get(SERVICE_IDENTIFIER.TaroElementFactory);
|
|
4799
|
-
document$1 = getElement(ElementNames.Document)();
|
|
4800
|
-
}
|
|
4801
|
-
// Taro 事件对象。以 Web 标准的事件对象为基础,加入小程序事件对象中携带的部分信息,并模拟实现事件冒泡。
|
|
4802
|
-
class TaroEvent {
|
|
4803
|
-
constructor(type, opts, event) {
|
|
4804
|
-
this._stop = false;
|
|
4805
|
-
this._end = false;
|
|
4806
|
-
this.defaultPrevented = false;
|
|
4807
|
-
// timestamp can either be hi-res ( relative to page load) or low-res (relative to UNIX epoch)
|
|
4808
|
-
// here use hi-res timestamp
|
|
4809
|
-
this.timeStamp = Date.now();
|
|
4810
|
-
this.type = type.toLowerCase();
|
|
4811
|
-
this.mpEvent = event;
|
|
4812
|
-
this.bubbles = Boolean(opts && opts.bubbles);
|
|
4813
|
-
this.cancelable = Boolean(opts && opts.cancelable);
|
|
4814
|
-
}
|
|
4815
|
-
stopPropagation() {
|
|
4816
|
-
this._stop = true;
|
|
4817
|
-
}
|
|
4818
|
-
stopImmediatePropagation() {
|
|
4819
|
-
this._end = this._stop = true;
|
|
4820
|
-
}
|
|
4821
|
-
preventDefault() {
|
|
4822
|
-
this.defaultPrevented = true;
|
|
4823
|
-
}
|
|
4824
|
-
get target() {
|
|
4825
|
-
var _a, _b, _c;
|
|
4826
|
-
const element = document$1.getElementById((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.target.id);
|
|
4827
|
-
return Object.assign(Object.assign(Object.assign({}, (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.target), (_c = this.mpEvent) === null || _c === void 0 ? void 0 : _c.detail), { dataset: element !== null ? element.dataset : EMPTY_OBJ });
|
|
4828
|
-
}
|
|
4829
|
-
get currentTarget() {
|
|
4830
|
-
var _a, _b, _c;
|
|
4831
|
-
const element = document$1.getElementById((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.currentTarget.id);
|
|
4832
|
-
if (element === null) {
|
|
4833
|
-
return this.target;
|
|
4834
|
-
}
|
|
4835
|
-
return Object.assign(Object.assign(Object.assign({}, (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.currentTarget), (_c = this.mpEvent) === null || _c === void 0 ? void 0 : _c.detail), { dataset: element.dataset });
|
|
4836
|
-
}
|
|
4837
|
-
}
|
|
4838
|
-
function createEvent(event, node) {
|
|
4839
|
-
if (typeof event === 'string') {
|
|
4840
|
-
// For Vue3 using document.createEvent
|
|
4841
|
-
return new TaroEvent(event, { bubbles: true, cancelable: true });
|
|
4842
|
-
}
|
|
4843
|
-
const domEv = new TaroEvent(event.type, { bubbles: true, cancelable: true }, event);
|
|
4844
|
-
for (const key in event) {
|
|
4845
|
-
if (key === CURRENT_TARGET || key === TARGET || key === TYPE || key === TIME_STAMP) {
|
|
4846
|
-
continue;
|
|
4847
|
-
}
|
|
4848
|
-
else {
|
|
4849
|
-
domEv[key] = event[key];
|
|
4850
|
-
}
|
|
4851
|
-
}
|
|
4852
|
-
if (domEv.type === CONFIRM && (node === null || node === void 0 ? void 0 : node.nodeName) === INPUT) {
|
|
4853
|
-
// eslint-disable-next-line dot-notation
|
|
4854
|
-
domEv[KEY_CODE] = 13;
|
|
4855
|
-
}
|
|
4856
|
-
return domEv;
|
|
4857
|
-
}
|
|
4858
|
-
const eventsBatch = {};
|
|
4859
|
-
// 小程序的事件代理回调函数
|
|
4860
|
-
function eventHandler(event) {
|
|
4861
|
-
var _a;
|
|
4862
|
-
(_a = hooks.modifyMpEvent) === null || _a === void 0 ? void 0 : _a.call(hooks, event);
|
|
4863
|
-
if (event.currentTarget == null) {
|
|
4864
|
-
event.currentTarget = event.target;
|
|
4865
|
-
}
|
|
4866
|
-
const node = document$1.getElementById(event.currentTarget.id);
|
|
4867
|
-
if (node) {
|
|
4868
|
-
const dispatch = () => {
|
|
4869
|
-
var _a;
|
|
4870
|
-
const e = createEvent(event, node);
|
|
4871
|
-
(_a = hooks.modifyTaroEvent) === null || _a === void 0 ? void 0 : _a.call(hooks, e, node);
|
|
4872
|
-
node.dispatchEvent(e);
|
|
4873
|
-
};
|
|
4874
|
-
if (typeof hooks.batchedEventUpdates === 'function') {
|
|
4875
|
-
const type = event.type;
|
|
4876
|
-
if (!hooks.isBubbleEvents(type) ||
|
|
4877
|
-
!isParentBinded(node, type) ||
|
|
4878
|
-
(type === TOUCHMOVE && !!node.props.catchMove)) {
|
|
4879
|
-
// 最上层组件统一 batchUpdate
|
|
4880
|
-
hooks.batchedEventUpdates(() => {
|
|
4881
|
-
if (eventsBatch[type]) {
|
|
4882
|
-
eventsBatch[type].forEach(fn => fn());
|
|
4883
|
-
delete eventsBatch[type];
|
|
4884
|
-
}
|
|
4885
|
-
dispatch();
|
|
4886
|
-
});
|
|
4887
|
-
}
|
|
4888
|
-
else {
|
|
4889
|
-
// 如果上层组件也有绑定同类型的组件,委托给上层组件调用事件回调
|
|
4890
|
-
(eventsBatch[type] || (eventsBatch[type] = [])).push(dispatch);
|
|
4891
|
-
}
|
|
4892
|
-
}
|
|
4893
|
-
else {
|
|
4894
|
-
dispatch();
|
|
4895
|
-
}
|
|
4896
|
-
}
|
|
4897
|
-
}
|
|
4898
|
-
|
|
4899
|
-
const isBrowser = typeof document !== 'undefined' && !!document.scripts;
|
|
4900
|
-
const doc = isBrowser ? document : EMPTY_OBJ;
|
|
4901
|
-
const win = isBrowser ? window : EMPTY_OBJ;
|
|
4170
|
+
processPluginHooks(container);
|
|
4171
|
+
store.container = container;
|
|
4902
4172
|
|
|
4903
4173
|
function createDocument() {
|
|
4904
4174
|
/**
|
|
@@ -4933,15 +4203,18 @@ function createDocument() {
|
|
|
4933
4203
|
doc.createEvent = createEvent;
|
|
4934
4204
|
return doc;
|
|
4935
4205
|
}
|
|
4936
|
-
const document$
|
|
4206
|
+
const document$1 = process.env.TARO_ENV === 'h5'
|
|
4207
|
+
? doc
|
|
4208
|
+
: createDocument();
|
|
4937
4209
|
|
|
4938
4210
|
const machine = 'Macintosh';
|
|
4939
4211
|
const arch = 'Intel Mac OS X 10_14_5';
|
|
4940
4212
|
const engine = 'AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36';
|
|
4941
|
-
const
|
|
4213
|
+
const msg = '(' + machine + '; ' + arch + ') ' + engine;
|
|
4214
|
+
const navigator = process.env.TARO_ENV === 'h5' ? win.navigator : {
|
|
4942
4215
|
appCodeName: 'Mozilla',
|
|
4943
4216
|
appName: 'Netscape',
|
|
4944
|
-
appVersion: '5.0
|
|
4217
|
+
appVersion: '5.0 ' + msg,
|
|
4945
4218
|
cookieEnabled: true,
|
|
4946
4219
|
mimeTypes: [],
|
|
4947
4220
|
onLine: true,
|
|
@@ -4949,7 +4222,7 @@ const navigator = isBrowser ? win.navigator : {
|
|
|
4949
4222
|
plugins: [],
|
|
4950
4223
|
product: 'Taro',
|
|
4951
4224
|
productSub: '20030107',
|
|
4952
|
-
userAgent: 'Mozilla/5.0
|
|
4225
|
+
userAgent: 'Mozilla/5.0 ' + msg,
|
|
4953
4226
|
vendor: 'Joyent',
|
|
4954
4227
|
vendorSub: ''
|
|
4955
4228
|
};
|
|
@@ -4995,11 +4268,11 @@ function getComputedStyle(element) {
|
|
|
4995
4268
|
return element.style;
|
|
4996
4269
|
}
|
|
4997
4270
|
|
|
4998
|
-
const window$1 =
|
|
4271
|
+
const window$1 = process.env.TARO_ENV === 'h5' ? win : {
|
|
4999
4272
|
navigator,
|
|
5000
|
-
document: document$
|
|
4273
|
+
document: document$1
|
|
5001
4274
|
};
|
|
5002
|
-
if (
|
|
4275
|
+
if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
5003
4276
|
const globalProperties = [
|
|
5004
4277
|
...Object.getOwnPropertyNames(global || win),
|
|
5005
4278
|
...Object.getOwnPropertySymbols(global || win)
|
|
@@ -5011,14 +4284,11 @@ if (!isBrowser) {
|
|
|
5011
4284
|
window$1[property] = global[property];
|
|
5012
4285
|
}
|
|
5013
4286
|
});
|
|
5014
|
-
document$2.defaultView = window$1;
|
|
5015
|
-
}
|
|
5016
|
-
if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
5017
4287
|
window$1.requestAnimationFrame = raf;
|
|
5018
4288
|
window$1.cancelAnimationFrame = caf;
|
|
5019
4289
|
window$1.getComputedStyle = getComputedStyle;
|
|
5020
|
-
window$1.addEventListener =
|
|
5021
|
-
window$1.removeEventListener =
|
|
4290
|
+
window$1.addEventListener = noop;
|
|
4291
|
+
window$1.removeEventListener = noop;
|
|
5022
4292
|
if (!(DATE in window$1)) {
|
|
5023
4293
|
window$1.Date = Date;
|
|
5024
4294
|
}
|
|
@@ -5028,6 +4298,7 @@ if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
|
5028
4298
|
window$1.clearTimeout = function (seed) {
|
|
5029
4299
|
clearTimeout(seed);
|
|
5030
4300
|
};
|
|
4301
|
+
document$1.defaultView = window$1;
|
|
5031
4302
|
}
|
|
5032
4303
|
|
|
5033
4304
|
const Current = {
|
|
@@ -5039,12 +4310,8 @@ const getCurrentInstance = () => Current;
|
|
|
5039
4310
|
|
|
5040
4311
|
class Events {
|
|
5041
4312
|
constructor(opts) {
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
}
|
|
5045
|
-
else {
|
|
5046
|
-
this.callbacks = {};
|
|
5047
|
-
}
|
|
4313
|
+
var _a;
|
|
4314
|
+
this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
|
|
5048
4315
|
}
|
|
5049
4316
|
on(eventName, callback, context) {
|
|
5050
4317
|
let event, node, tail, list;
|
|
@@ -5121,17 +4388,15 @@ class Events {
|
|
|
5121
4388
|
}
|
|
5122
4389
|
}
|
|
5123
4390
|
Events.eventSplitter = /\s+/;
|
|
5124
|
-
const
|
|
5125
|
-
|
|
5126
|
-
container.bind(SERVICE_IDENTIFIER.eventCenter).toConstantValue(eventCenter);
|
|
4391
|
+
const eventCenter = getHooks().getEventCenter(Events);
|
|
4392
|
+
container.bind(SID_EVENT_CENTER).toConstantValue(eventCenter);
|
|
5127
4393
|
|
|
5128
4394
|
/* eslint-disable dot-notation */
|
|
5129
4395
|
const instances = new Map();
|
|
5130
4396
|
const pageId = incrementId();
|
|
5131
|
-
const hooks$2 = container.get(SERVICE_IDENTIFIER.Hooks);
|
|
5132
4397
|
function injectPageInstance(inst, id) {
|
|
5133
|
-
var _a;
|
|
5134
|
-
(_a =
|
|
4398
|
+
var _a, _b;
|
|
4399
|
+
(_b = (_a = getHooks()).mergePageInstance) === null || _b === void 0 ? void 0 : _b.call(_a, instances.get(id), inst);
|
|
5135
4400
|
instances.set(id, inst);
|
|
5136
4401
|
}
|
|
5137
4402
|
function getPageInstance(id) {
|
|
@@ -5148,12 +4413,12 @@ function safeExecute(path, lifecycle, ...args) {
|
|
|
5148
4413
|
if (instance == null) {
|
|
5149
4414
|
return;
|
|
5150
4415
|
}
|
|
5151
|
-
const func =
|
|
5152
|
-
if (isArray
|
|
4416
|
+
const func = getHooks().getLifecycle(instance, lifecycle);
|
|
4417
|
+
if (isArray(func)) {
|
|
5153
4418
|
const res = func.map(fn => fn.apply(instance, args));
|
|
5154
4419
|
return res[0];
|
|
5155
4420
|
}
|
|
5156
|
-
if (!isFunction
|
|
4421
|
+
if (!isFunction(func)) {
|
|
5157
4422
|
return;
|
|
5158
4423
|
}
|
|
5159
4424
|
return func.apply(instance, args);
|
|
@@ -5169,31 +4434,43 @@ function stringify(obj) {
|
|
|
5169
4434
|
}
|
|
5170
4435
|
function getPath(id, options) {
|
|
5171
4436
|
let path = id;
|
|
5172
|
-
if (
|
|
4437
|
+
if (process.env.TARO_ENV !== 'h5') {
|
|
5173
4438
|
path = id + stringify(options);
|
|
5174
4439
|
}
|
|
5175
4440
|
return path;
|
|
5176
4441
|
}
|
|
5177
4442
|
function getOnReadyEventKey(path) {
|
|
5178
|
-
return path + '.' +
|
|
4443
|
+
return path + '.' + ON_READY;
|
|
5179
4444
|
}
|
|
5180
4445
|
function getOnShowEventKey(path) {
|
|
5181
|
-
return path + '.' +
|
|
4446
|
+
return path + '.' + ON_SHOW;
|
|
5182
4447
|
}
|
|
5183
4448
|
function getOnHideEventKey(path) {
|
|
5184
|
-
return path + '.' +
|
|
4449
|
+
return path + '.' + ON_HIDE;
|
|
5185
4450
|
}
|
|
5186
4451
|
function createPageConfig(component, pageName, data, pageConfig) {
|
|
5187
|
-
var _a, _b;
|
|
5188
|
-
const id = pageName !== null && pageName !== void 0 ? pageName : `taro_page_${pageId()}`;
|
|
4452
|
+
var _a, _b, _c;
|
|
5189
4453
|
// 小程序 Page 构造器是一个傲娇小公主,不能把复杂的对象挂载到参数上
|
|
4454
|
+
const id = pageName !== null && pageName !== void 0 ? pageName : `taro_page_${pageId()}`;
|
|
4455
|
+
const hooks = getHooks();
|
|
4456
|
+
const [ONLOAD, ONUNLOAD, ONREADY, ONSHOW, ONHIDE, LIFECYCLES] = hooks.getMiniLifecycleImpl().page;
|
|
5190
4457
|
let pageElement = null;
|
|
5191
4458
|
let unmounting = false;
|
|
5192
4459
|
let prepareMountList = [];
|
|
4460
|
+
function setCurrentRouter(page) {
|
|
4461
|
+
const router = process.env.TARO_ENV === 'h5' ? page.$taroPath : page.route || page.__route__ || page.$taroPath;
|
|
4462
|
+
Current.router = {
|
|
4463
|
+
params: page.$taroParams,
|
|
4464
|
+
path: addLeadingSlash(router),
|
|
4465
|
+
onReady: getOnReadyEventKey(id),
|
|
4466
|
+
onShow: getOnShowEventKey(id),
|
|
4467
|
+
onHide: getOnHideEventKey(id)
|
|
4468
|
+
};
|
|
4469
|
+
}
|
|
5193
4470
|
let loadResolver;
|
|
5194
4471
|
let hasLoaded;
|
|
5195
4472
|
const config = {
|
|
5196
|
-
|
|
4473
|
+
[ONLOAD](options = {}, cb) {
|
|
5197
4474
|
hasLoaded = new Promise(resolve => { loadResolver = resolve; });
|
|
5198
4475
|
perf.start(PAGE_INIT);
|
|
5199
4476
|
Current.page = this;
|
|
@@ -5201,30 +4478,24 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
5201
4478
|
options.$taroTimestamp = Date.now();
|
|
5202
4479
|
// this.$taroPath 是页面唯一标识,不可变,因此页面参数 options 也不可变
|
|
5203
4480
|
this.$taroPath = getPath(id, options);
|
|
4481
|
+
const $taroPath = this.$taroPath;
|
|
5204
4482
|
// this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
|
|
5205
4483
|
if (this.$taroParams == null) {
|
|
5206
4484
|
this.$taroParams = Object.assign({}, options);
|
|
5207
4485
|
}
|
|
5208
|
-
|
|
5209
|
-
Current.router = {
|
|
5210
|
-
params: this.$taroParams,
|
|
5211
|
-
path: addLeadingSlash(router),
|
|
5212
|
-
onReady: getOnReadyEventKey(id),
|
|
5213
|
-
onShow: getOnShowEventKey(id),
|
|
5214
|
-
onHide: getOnHideEventKey(id)
|
|
5215
|
-
};
|
|
4486
|
+
setCurrentRouter(this);
|
|
5216
4487
|
const mount = () => {
|
|
5217
|
-
Current.app.mount(component,
|
|
5218
|
-
pageElement = document$
|
|
4488
|
+
Current.app.mount(component, $taroPath, () => {
|
|
4489
|
+
pageElement = document$1.getElementById($taroPath);
|
|
5219
4490
|
ensure(pageElement !== null, '没有找到页面实例。');
|
|
5220
|
-
safeExecute(
|
|
4491
|
+
safeExecute($taroPath, ON_LOAD, this.$taroParams);
|
|
5221
4492
|
loadResolver();
|
|
5222
|
-
if (
|
|
4493
|
+
if (process.env.TARO_ENV !== 'h5') {
|
|
5223
4494
|
pageElement.ctx = this;
|
|
5224
4495
|
pageElement.performUpdate(true, cb);
|
|
5225
4496
|
}
|
|
5226
4497
|
else {
|
|
5227
|
-
isFunction
|
|
4498
|
+
isFunction(cb) && cb();
|
|
5228
4499
|
}
|
|
5229
4500
|
});
|
|
5230
4501
|
};
|
|
@@ -5235,20 +4506,15 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
5235
4506
|
mount();
|
|
5236
4507
|
}
|
|
5237
4508
|
},
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
eventCenter.trigger(getOnReadyEventKey(id));
|
|
5241
|
-
});
|
|
5242
|
-
safeExecute(this.$taroPath, 'onReady');
|
|
5243
|
-
this.onReady.called = true;
|
|
5244
|
-
},
|
|
5245
|
-
onUnload() {
|
|
4509
|
+
[ONUNLOAD]() {
|
|
4510
|
+
const $taroPath = this.$taroPath;
|
|
5246
4511
|
unmounting = true;
|
|
5247
|
-
Current.app.unmount(
|
|
4512
|
+
Current.app.unmount($taroPath, () => {
|
|
5248
4513
|
unmounting = false;
|
|
5249
|
-
instances.delete(
|
|
4514
|
+
instances.delete($taroPath);
|
|
5250
4515
|
if (pageElement) {
|
|
5251
4516
|
pageElement.ctx = null;
|
|
4517
|
+
pageElement = null;
|
|
5252
4518
|
}
|
|
5253
4519
|
if (prepareMountList.length) {
|
|
5254
4520
|
prepareMountList.forEach(fn => fn());
|
|
@@ -5256,72 +4522,52 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
5256
4522
|
}
|
|
5257
4523
|
});
|
|
5258
4524
|
},
|
|
5259
|
-
|
|
4525
|
+
[ONREADY]() {
|
|
4526
|
+
// 触发生命周期
|
|
4527
|
+
safeExecute(this.$taroPath, ON_READY);
|
|
4528
|
+
// 通过事件触发子组件的生命周期
|
|
4529
|
+
raf(() => eventCenter.trigger(getOnReadyEventKey(id)));
|
|
4530
|
+
this.onReady.called = true;
|
|
4531
|
+
},
|
|
4532
|
+
[ONSHOW]() {
|
|
5260
4533
|
hasLoaded.then(() => {
|
|
4534
|
+
// 设置 Current 的 page 和 router
|
|
5261
4535
|
Current.page = this;
|
|
5262
|
-
this
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
onReady: getOnReadyEventKey(id),
|
|
5268
|
-
onShow: getOnShowEventKey(id),
|
|
5269
|
-
onHide: getOnHideEventKey(id)
|
|
5270
|
-
};
|
|
5271
|
-
raf(() => {
|
|
5272
|
-
eventCenter.trigger(getOnShowEventKey(id));
|
|
5273
|
-
});
|
|
5274
|
-
safeExecute(this.$taroPath, 'onShow');
|
|
4536
|
+
setCurrentRouter(this);
|
|
4537
|
+
// 触发生命周期
|
|
4538
|
+
safeExecute(this.$taroPath, ON_SHOW);
|
|
4539
|
+
// 通过事件触发子组件的生命周期
|
|
4540
|
+
raf(() => eventCenter.trigger(getOnShowEventKey(id)));
|
|
5275
4541
|
});
|
|
5276
4542
|
},
|
|
5277
|
-
|
|
5278
|
-
Current
|
|
5279
|
-
Current.
|
|
5280
|
-
|
|
4543
|
+
[ONHIDE]() {
|
|
4544
|
+
// 设置 Current 的 page 和 router
|
|
4545
|
+
if (Current.page === this) {
|
|
4546
|
+
Current.page = null;
|
|
4547
|
+
Current.router = null;
|
|
4548
|
+
}
|
|
4549
|
+
// 触发生命周期
|
|
4550
|
+
safeExecute(this.$taroPath, ON_HIDE);
|
|
4551
|
+
// 通过事件触发子组件的生命周期
|
|
5281
4552
|
eventCenter.trigger(getOnHideEventKey(id));
|
|
5282
|
-
},
|
|
5283
|
-
onPullDownRefresh() {
|
|
5284
|
-
return safeExecute(this.$taroPath, 'onPullDownRefresh');
|
|
5285
|
-
},
|
|
5286
|
-
onReachBottom() {
|
|
5287
|
-
return safeExecute(this.$taroPath, 'onReachBottom');
|
|
5288
|
-
},
|
|
5289
|
-
onPageScroll(options) {
|
|
5290
|
-
return safeExecute(this.$taroPath, 'onPageScroll', options);
|
|
5291
|
-
},
|
|
5292
|
-
onResize(options) {
|
|
5293
|
-
return safeExecute(this.$taroPath, 'onResize', options);
|
|
5294
|
-
},
|
|
5295
|
-
onTabItemTap(options) {
|
|
5296
|
-
return safeExecute(this.$taroPath, 'onTabItemTap', options);
|
|
5297
|
-
},
|
|
5298
|
-
onTitleClick() {
|
|
5299
|
-
return safeExecute(this.$taroPath, 'onTitleClick');
|
|
5300
|
-
},
|
|
5301
|
-
onOptionMenuClick() {
|
|
5302
|
-
return safeExecute(this.$taroPath, 'onOptionMenuClick');
|
|
5303
|
-
},
|
|
5304
|
-
onPopMenuClick() {
|
|
5305
|
-
return safeExecute(this.$taroPath, 'onPopMenuClick');
|
|
5306
|
-
},
|
|
5307
|
-
onPullIntercept() {
|
|
5308
|
-
return safeExecute(this.$taroPath, 'onPullIntercept');
|
|
5309
|
-
},
|
|
5310
|
-
onAddToFavorites() {
|
|
5311
|
-
return safeExecute(this.$taroPath, 'onAddToFavorites');
|
|
5312
4553
|
}
|
|
5313
4554
|
};
|
|
4555
|
+
LIFECYCLES.forEach((lifecycle) => {
|
|
4556
|
+
config[lifecycle] = function () {
|
|
4557
|
+
return safeExecute(this.$taroPath, lifecycle, ...arguments);
|
|
4558
|
+
};
|
|
4559
|
+
});
|
|
5314
4560
|
// onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。
|
|
5315
4561
|
if (component.onShareAppMessage ||
|
|
5316
4562
|
((_a = component.prototype) === null || _a === void 0 ? void 0 : _a.onShareAppMessage) ||
|
|
5317
4563
|
component.enableShareAppMessage) {
|
|
5318
4564
|
config.onShareAppMessage = function (options) {
|
|
5319
4565
|
const target = options === null || options === void 0 ? void 0 : options.target;
|
|
5320
|
-
if (target
|
|
4566
|
+
if (target) {
|
|
5321
4567
|
const id = target.id;
|
|
5322
|
-
const element = document$
|
|
5323
|
-
if (element
|
|
5324
|
-
|
|
4568
|
+
const element = document$1.getElementById(id);
|
|
4569
|
+
if (element) {
|
|
4570
|
+
target.dataset = element.dataset;
|
|
5325
4571
|
}
|
|
5326
4572
|
}
|
|
5327
4573
|
return safeExecute(this.$taroPath, 'onShareAppMessage', options);
|
|
@@ -5338,13 +4584,13 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
5338
4584
|
if (!isUndefined(data)) {
|
|
5339
4585
|
config.data = data;
|
|
5340
4586
|
}
|
|
5341
|
-
if (
|
|
4587
|
+
if (process.env.TARO_ENV === 'h5') {
|
|
5342
4588
|
config.path = id;
|
|
5343
4589
|
}
|
|
4590
|
+
(_c = hooks.modifyPageObject) === null || _c === void 0 ? void 0 : _c.call(hooks, config);
|
|
5344
4591
|
return config;
|
|
5345
4592
|
}
|
|
5346
4593
|
function createComponentConfig(component, componentName, data) {
|
|
5347
|
-
var _a, _b, _c;
|
|
5348
4594
|
const id = componentName !== null && componentName !== void 0 ? componentName : `taro_component_${pageId()}`;
|
|
5349
4595
|
let componentElement = null;
|
|
5350
4596
|
const config = {
|
|
@@ -5353,10 +4599,10 @@ function createComponentConfig(component, componentName, data) {
|
|
|
5353
4599
|
perf.start(PAGE_INIT);
|
|
5354
4600
|
const path = getPath(id, { id: ((_a = this.getPageId) === null || _a === void 0 ? void 0 : _a.call(this)) || pageId() });
|
|
5355
4601
|
Current.app.mount(component, path, () => {
|
|
5356
|
-
componentElement = document$
|
|
4602
|
+
componentElement = document$1.getElementById(path);
|
|
5357
4603
|
ensure(componentElement !== null, '没有找到组件实例。');
|
|
5358
|
-
safeExecute(path,
|
|
5359
|
-
if (
|
|
4604
|
+
safeExecute(path, ON_LOAD);
|
|
4605
|
+
if (process.env.TARO_ENV !== 'h5') {
|
|
5360
4606
|
componentElement.ctx = this;
|
|
5361
4607
|
componentElement.performUpdate(true);
|
|
5362
4608
|
}
|
|
@@ -5378,9 +4624,10 @@ function createComponentConfig(component, componentName, data) {
|
|
|
5378
4624
|
if (!isUndefined(data)) {
|
|
5379
4625
|
config.data = data;
|
|
5380
4626
|
}
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
4627
|
+
[OPTIONS, EXTERNAL_CLASSES, BEHAVIORS].forEach(key => {
|
|
4628
|
+
var _a;
|
|
4629
|
+
config[key] = (_a = component[key]) !== null && _a !== void 0 ? _a : EMPTY_OBJ;
|
|
4630
|
+
});
|
|
5384
4631
|
return config;
|
|
5385
4632
|
}
|
|
5386
4633
|
function createRecursiveComponentConfig(componentName) {
|
|
@@ -5389,7 +4636,7 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
5389
4636
|
i: {
|
|
5390
4637
|
type: Object,
|
|
5391
4638
|
value: {
|
|
5392
|
-
["nn" /* NodeName */]:
|
|
4639
|
+
["nn" /* NodeName */]: VIEW
|
|
5393
4640
|
}
|
|
5394
4641
|
},
|
|
5395
4642
|
l: {
|
|
@@ -5399,7 +4646,7 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
5399
4646
|
},
|
|
5400
4647
|
options: {
|
|
5401
4648
|
addGlobalClass: true,
|
|
5402
|
-
virtualHost: componentName !==
|
|
4649
|
+
virtualHost: componentName !== CUSTOM_WRAPPER
|
|
5403
4650
|
},
|
|
5404
4651
|
methods: {
|
|
5405
4652
|
eh: eventHandler
|
|
@@ -5407,794 +4654,6 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
5407
4654
|
};
|
|
5408
4655
|
}
|
|
5409
4656
|
|
|
5410
|
-
const hooks$3 = container.get(SERVICE_IDENTIFIER.Hooks);
|
|
5411
|
-
function isClassComponent(R, component) {
|
|
5412
|
-
var _a;
|
|
5413
|
-
return isFunction$1(component.render) ||
|
|
5414
|
-
!!((_a = component.prototype) === null || _a === void 0 ? void 0 : _a.isReactComponent) ||
|
|
5415
|
-
component.prototype instanceof R.Component; // compat for some others react-like library
|
|
5416
|
-
}
|
|
5417
|
-
// 初始值设置为 any 主要是为了过 TS 的校验
|
|
5418
|
-
let R = EMPTY_OBJ;
|
|
5419
|
-
let PageContext = EMPTY_OBJ;
|
|
5420
|
-
function connectReactPage(R, id) {
|
|
5421
|
-
const h = R.createElement;
|
|
5422
|
-
return (component) => {
|
|
5423
|
-
// eslint-disable-next-line dot-notation
|
|
5424
|
-
const isReactComponent = isClassComponent(R, component);
|
|
5425
|
-
const inject = (node) => node && injectPageInstance(node, id);
|
|
5426
|
-
const refs = isReactComponent ? { ref: inject } : {
|
|
5427
|
-
forwardedRef: inject,
|
|
5428
|
-
// 兼容 react-redux 7.20.1+
|
|
5429
|
-
reactReduxForwardedRef: inject
|
|
5430
|
-
};
|
|
5431
|
-
if (PageContext === EMPTY_OBJ) {
|
|
5432
|
-
PageContext = R.createContext('');
|
|
5433
|
-
}
|
|
5434
|
-
return class Page extends R.Component {
|
|
5435
|
-
constructor() {
|
|
5436
|
-
super(...arguments);
|
|
5437
|
-
this.state = {
|
|
5438
|
-
hasError: false
|
|
5439
|
-
};
|
|
5440
|
-
}
|
|
5441
|
-
static getDerivedStateFromError(error) {
|
|
5442
|
-
process.env.NODE_ENV !== 'production' && console.warn(error);
|
|
5443
|
-
return { hasError: true };
|
|
5444
|
-
}
|
|
5445
|
-
// React 16 uncaught error 会导致整个应用 crash,
|
|
5446
|
-
// 目前把错误缩小到页面
|
|
5447
|
-
componentDidCatch(error, info) {
|
|
5448
|
-
process.env.NODE_ENV !== 'production' && console.warn(error);
|
|
5449
|
-
process.env.NODE_ENV !== 'production' && console.error(info.componentStack);
|
|
5450
|
-
}
|
|
5451
|
-
render() {
|
|
5452
|
-
const children = this.state.hasError
|
|
5453
|
-
? []
|
|
5454
|
-
: h(PageContext.Provider, { value: id }, h(component, Object.assign(Object.assign({}, this.props), refs)));
|
|
5455
|
-
if (isBrowser) {
|
|
5456
|
-
return h('div', { id, className: 'taro_page' }, children);
|
|
5457
|
-
}
|
|
5458
|
-
return h('root', { id }, children);
|
|
5459
|
-
}
|
|
5460
|
-
};
|
|
5461
|
-
};
|
|
5462
|
-
}
|
|
5463
|
-
let ReactDOM;
|
|
5464
|
-
function setReconciler() {
|
|
5465
|
-
const getLifecycle = function (instance, lifecycle) {
|
|
5466
|
-
lifecycle = lifecycle.replace(/^on(Show|Hide)$/, 'componentDid$1');
|
|
5467
|
-
return instance[lifecycle];
|
|
5468
|
-
};
|
|
5469
|
-
const modifyMpEvent = function (event) {
|
|
5470
|
-
event.type = event.type.replace(/-/g, '');
|
|
5471
|
-
};
|
|
5472
|
-
const batchedEventUpdates = function (cb) {
|
|
5473
|
-
ReactDOM.unstable_batchedUpdates(cb);
|
|
5474
|
-
};
|
|
5475
|
-
const mergePageInstance = function (prev, next) {
|
|
5476
|
-
if (!prev || !next)
|
|
5477
|
-
return;
|
|
5478
|
-
// 子组件使用 lifecycle hooks 注册了生命周期后,会存在 prev,里面是注册的生命周期回调。
|
|
5479
|
-
// prev 使用 Object.create(null) 创建,H5 的 fast-refresh 可能也会导致存在 prev,要排除这些意外产生的 prev
|
|
5480
|
-
if ('constructor' in prev)
|
|
5481
|
-
return;
|
|
5482
|
-
Object.keys(prev).forEach(item => {
|
|
5483
|
-
if (isFunction$1(next[item])) {
|
|
5484
|
-
next[item] = [next[item], ...prev[item]];
|
|
5485
|
-
}
|
|
5486
|
-
else {
|
|
5487
|
-
next[item] = [...(next[item] || []), ...prev[item]];
|
|
5488
|
-
}
|
|
5489
|
-
});
|
|
5490
|
-
};
|
|
5491
|
-
hooks$3.getLifecycle = getLifecycle;
|
|
5492
|
-
hooks$3.modifyMpEvent = modifyMpEvent;
|
|
5493
|
-
hooks$3.batchedEventUpdates = batchedEventUpdates;
|
|
5494
|
-
hooks$3.mergePageInstance = mergePageInstance;
|
|
5495
|
-
if (process.env.TARO_ENV === 'h5') {
|
|
5496
|
-
hooks$3.createPullDownComponent = (el, _, R, customWrapper) => {
|
|
5497
|
-
const isReactComponent = isClassComponent(R, el);
|
|
5498
|
-
return R.forwardRef((props, ref) => {
|
|
5499
|
-
const newProps = Object.assign({}, props);
|
|
5500
|
-
const refs = isReactComponent ? { ref: ref } : {
|
|
5501
|
-
forwardedRef: ref,
|
|
5502
|
-
// 兼容 react-redux 7.20.1+
|
|
5503
|
-
reactReduxForwardedRef: ref
|
|
5504
|
-
};
|
|
5505
|
-
return R.createElement(customWrapper || 'taro-pull-to-refresh', null, R.createElement(el, Object.assign(Object.assign({}, newProps), refs)));
|
|
5506
|
-
});
|
|
5507
|
-
};
|
|
5508
|
-
hooks$3.getDOMNode = (inst) => {
|
|
5509
|
-
return ReactDOM.findDOMNode(inst);
|
|
5510
|
-
};
|
|
5511
|
-
}
|
|
5512
|
-
}
|
|
5513
|
-
const pageKeyId = incrementId();
|
|
5514
|
-
function createReactApp(App, react, reactdom, config) {
|
|
5515
|
-
R = react;
|
|
5516
|
-
ReactDOM = reactdom;
|
|
5517
|
-
ensure(!!ReactDOM, '构建 React/Nerv 项目请把 process.env.FRAMEWORK 设置为 \'react\'/\'nerv\' ');
|
|
5518
|
-
const ref = R.createRef();
|
|
5519
|
-
const isReactComponent = isClassComponent(R, App);
|
|
5520
|
-
setReconciler();
|
|
5521
|
-
class AppWrapper extends R.Component {
|
|
5522
|
-
constructor() {
|
|
5523
|
-
super(...arguments);
|
|
5524
|
-
// run createElement() inside the render function to make sure that owner is right
|
|
5525
|
-
this.pages = [];
|
|
5526
|
-
this.elements = [];
|
|
5527
|
-
}
|
|
5528
|
-
mount(component, id, cb) {
|
|
5529
|
-
const key = id + pageKeyId();
|
|
5530
|
-
const page = () => R.createElement(component, { key, tid: id });
|
|
5531
|
-
this.pages.push(page);
|
|
5532
|
-
this.forceUpdate(cb);
|
|
5533
|
-
}
|
|
5534
|
-
unmount(id, cb) {
|
|
5535
|
-
for (let i = 0; i < this.elements.length; i++) {
|
|
5536
|
-
const element = this.elements[i];
|
|
5537
|
-
if (element.props.tid === id) {
|
|
5538
|
-
this.elements.splice(i, 1);
|
|
5539
|
-
break;
|
|
5540
|
-
}
|
|
5541
|
-
}
|
|
5542
|
-
this.forceUpdate(cb);
|
|
5543
|
-
}
|
|
5544
|
-
render() {
|
|
5545
|
-
while (this.pages.length > 0) {
|
|
5546
|
-
const page = this.pages.pop();
|
|
5547
|
-
this.elements.push(page());
|
|
5548
|
-
}
|
|
5549
|
-
let props = null;
|
|
5550
|
-
if (isReactComponent) {
|
|
5551
|
-
props = { ref };
|
|
5552
|
-
}
|
|
5553
|
-
return R.createElement(App, props, isBrowser ? R.createElement('div', null, this.elements.slice()) : this.elements.slice());
|
|
5554
|
-
}
|
|
5555
|
-
}
|
|
5556
|
-
let wrapper;
|
|
5557
|
-
if (!isBrowser) {
|
|
5558
|
-
// eslint-disable-next-line react/no-render-return-value
|
|
5559
|
-
wrapper = ReactDOM.render(R.createElement(AppWrapper), document$2.getElementById('app'));
|
|
5560
|
-
}
|
|
5561
|
-
const app = Object.create({
|
|
5562
|
-
render(cb) {
|
|
5563
|
-
wrapper.forceUpdate(cb);
|
|
5564
|
-
},
|
|
5565
|
-
mount(component, id, cb) {
|
|
5566
|
-
const page = connectReactPage(R, id)(component);
|
|
5567
|
-
wrapper.mount(page, id, cb);
|
|
5568
|
-
},
|
|
5569
|
-
unmount(id, cb) {
|
|
5570
|
-
wrapper.unmount(id, cb);
|
|
5571
|
-
}
|
|
5572
|
-
}, {
|
|
5573
|
-
config: {
|
|
5574
|
-
writable: true,
|
|
5575
|
-
enumerable: true,
|
|
5576
|
-
configurable: true,
|
|
5577
|
-
value: config
|
|
5578
|
-
},
|
|
5579
|
-
onLaunch: {
|
|
5580
|
-
enumerable: true,
|
|
5581
|
-
writable: true,
|
|
5582
|
-
value(options) {
|
|
5583
|
-
Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
|
|
5584
|
-
if (isBrowser) {
|
|
5585
|
-
// 由于 H5 路由初始化的时候会清除 app 下的 dom 元素,所以需要在路由初始化后执行 render
|
|
5586
|
-
// eslint-disable-next-line react/no-render-return-value
|
|
5587
|
-
wrapper = ReactDOM.render(R.createElement(AppWrapper), document$2.getElementById('app'));
|
|
5588
|
-
}
|
|
5589
|
-
const app = ref.current;
|
|
5590
|
-
// For taroize
|
|
5591
|
-
// 把 App Class 上挂载的额外属性同步到全局 app 对象中
|
|
5592
|
-
if (app === null || app === void 0 ? void 0 : app.taroGlobalData) {
|
|
5593
|
-
const globalData = app.taroGlobalData;
|
|
5594
|
-
const keys = Object.keys(globalData);
|
|
5595
|
-
const descriptors = Object.getOwnPropertyDescriptors(globalData);
|
|
5596
|
-
keys.forEach(key => {
|
|
5597
|
-
Object.defineProperty(this, key, {
|
|
5598
|
-
configurable: true,
|
|
5599
|
-
enumerable: true,
|
|
5600
|
-
get() {
|
|
5601
|
-
return globalData[key];
|
|
5602
|
-
},
|
|
5603
|
-
set(value) {
|
|
5604
|
-
globalData[key] = value;
|
|
5605
|
-
}
|
|
5606
|
-
});
|
|
5607
|
-
});
|
|
5608
|
-
Object.defineProperties(this, descriptors);
|
|
5609
|
-
}
|
|
5610
|
-
this.$app = app;
|
|
5611
|
-
if (app != null && isFunction$1(app.onLaunch)) {
|
|
5612
|
-
app.onLaunch(options);
|
|
5613
|
-
}
|
|
5614
|
-
}
|
|
5615
|
-
},
|
|
5616
|
-
onShow: {
|
|
5617
|
-
enumerable: true,
|
|
5618
|
-
writable: true,
|
|
5619
|
-
value(options) {
|
|
5620
|
-
const app = ref.current;
|
|
5621
|
-
Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
|
|
5622
|
-
if (app != null && isFunction$1(app.componentDidShow)) {
|
|
5623
|
-
app.componentDidShow(options);
|
|
5624
|
-
}
|
|
5625
|
-
// app useDidShow
|
|
5626
|
-
triggerAppHook('onShow');
|
|
5627
|
-
}
|
|
5628
|
-
},
|
|
5629
|
-
onHide: {
|
|
5630
|
-
enumerable: true,
|
|
5631
|
-
writable: true,
|
|
5632
|
-
value(options) {
|
|
5633
|
-
const app = ref.current;
|
|
5634
|
-
if (app != null && isFunction$1(app.componentDidHide)) {
|
|
5635
|
-
app.componentDidHide(options);
|
|
5636
|
-
}
|
|
5637
|
-
// app useDidHide
|
|
5638
|
-
triggerAppHook('onHide');
|
|
5639
|
-
}
|
|
5640
|
-
},
|
|
5641
|
-
onPageNotFound: {
|
|
5642
|
-
enumerable: true,
|
|
5643
|
-
writable: true,
|
|
5644
|
-
value(res) {
|
|
5645
|
-
const app = ref.current;
|
|
5646
|
-
if (app != null && isFunction$1(app.onPageNotFound)) {
|
|
5647
|
-
app.onPageNotFound(res);
|
|
5648
|
-
}
|
|
5649
|
-
}
|
|
5650
|
-
}
|
|
5651
|
-
});
|
|
5652
|
-
function triggerAppHook(lifecycle) {
|
|
5653
|
-
const instance = getPageInstance(HOOKS_APP_ID);
|
|
5654
|
-
if (instance) {
|
|
5655
|
-
const app = ref.current;
|
|
5656
|
-
const func = hooks$3.getLifecycle(instance, lifecycle);
|
|
5657
|
-
if (Array.isArray(func)) {
|
|
5658
|
-
func.forEach(cb => cb.apply(app));
|
|
5659
|
-
}
|
|
5660
|
-
}
|
|
5661
|
-
}
|
|
5662
|
-
Current.app = app;
|
|
5663
|
-
return Current.app;
|
|
5664
|
-
}
|
|
5665
|
-
const getNativeCompId = incrementId();
|
|
5666
|
-
function initNativeComponentEntry(R, ReactDOM) {
|
|
5667
|
-
class NativeComponentWrapper extends R.Component {
|
|
5668
|
-
constructor() {
|
|
5669
|
-
super(...arguments);
|
|
5670
|
-
this.root = R.createRef();
|
|
5671
|
-
this.ctx = this.props.getCtx();
|
|
5672
|
-
}
|
|
5673
|
-
componentDidMount() {
|
|
5674
|
-
this.ctx.component = this;
|
|
5675
|
-
const rootElement = this.root.current;
|
|
5676
|
-
rootElement.ctx = this.ctx;
|
|
5677
|
-
rootElement.performUpdate(true);
|
|
5678
|
-
}
|
|
5679
|
-
render() {
|
|
5680
|
-
return (R.createElement('root', {
|
|
5681
|
-
ref: this.root
|
|
5682
|
-
}, this.props.renderComponent(this.ctx)));
|
|
5683
|
-
}
|
|
5684
|
-
}
|
|
5685
|
-
class Entry extends R.Component {
|
|
5686
|
-
constructor() {
|
|
5687
|
-
super(...arguments);
|
|
5688
|
-
this.state = {
|
|
5689
|
-
components: []
|
|
5690
|
-
};
|
|
5691
|
-
}
|
|
5692
|
-
componentDidMount() {
|
|
5693
|
-
Current.app = this;
|
|
5694
|
-
}
|
|
5695
|
-
mount(Component, compId, getCtx) {
|
|
5696
|
-
const isReactComponent = isClassComponent(R, Component);
|
|
5697
|
-
const inject = (node) => node && injectPageInstance(node, compId);
|
|
5698
|
-
const refs = isReactComponent ? { ref: inject } : {
|
|
5699
|
-
forwardedRef: inject,
|
|
5700
|
-
reactReduxForwardedRef: inject
|
|
5701
|
-
};
|
|
5702
|
-
const item = {
|
|
5703
|
-
compId,
|
|
5704
|
-
element: R.createElement(NativeComponentWrapper, {
|
|
5705
|
-
key: compId,
|
|
5706
|
-
getCtx,
|
|
5707
|
-
renderComponent(ctx) {
|
|
5708
|
-
return R.createElement(Component, Object.assign(Object.assign({}, (ctx.data || (ctx.data = {})).props), refs));
|
|
5709
|
-
}
|
|
5710
|
-
})
|
|
5711
|
-
};
|
|
5712
|
-
this.setState({
|
|
5713
|
-
components: [...this.state.components, item]
|
|
5714
|
-
});
|
|
5715
|
-
}
|
|
5716
|
-
unmount(compId) {
|
|
5717
|
-
const components = this.state.components;
|
|
5718
|
-
const index = components.findIndex(item => item.compId === compId);
|
|
5719
|
-
const next = [...components.slice(0, index), ...components.slice(index + 1)];
|
|
5720
|
-
this.setState({
|
|
5721
|
-
components: next
|
|
5722
|
-
});
|
|
5723
|
-
}
|
|
5724
|
-
render() {
|
|
5725
|
-
const components = this.state.components;
|
|
5726
|
-
return (components.map(({ element }) => element));
|
|
5727
|
-
}
|
|
5728
|
-
}
|
|
5729
|
-
setReconciler();
|
|
5730
|
-
const app = document$2.getElementById('app');
|
|
5731
|
-
ReactDOM.render(R.createElement(Entry, {}), app);
|
|
5732
|
-
}
|
|
5733
|
-
function createNativeComponentConfig(Component, react, reactdom, componentConfig) {
|
|
5734
|
-
R = react;
|
|
5735
|
-
ReactDOM = reactdom;
|
|
5736
|
-
setReconciler();
|
|
5737
|
-
const config = {
|
|
5738
|
-
properties: {
|
|
5739
|
-
props: {
|
|
5740
|
-
type: null,
|
|
5741
|
-
value: null,
|
|
5742
|
-
observer(_newVal, oldVal) {
|
|
5743
|
-
oldVal && this.component.forceUpdate();
|
|
5744
|
-
}
|
|
5745
|
-
}
|
|
5746
|
-
},
|
|
5747
|
-
created() {
|
|
5748
|
-
if (!Current.app) {
|
|
5749
|
-
initNativeComponentEntry(R, ReactDOM);
|
|
5750
|
-
}
|
|
5751
|
-
},
|
|
5752
|
-
attached() {
|
|
5753
|
-
setCurrent();
|
|
5754
|
-
this.compId = getNativeCompId();
|
|
5755
|
-
this.config = componentConfig;
|
|
5756
|
-
Current.app.mount(Component, this.compId, () => this);
|
|
5757
|
-
},
|
|
5758
|
-
ready() {
|
|
5759
|
-
safeExecute(this.compId, 'onReady');
|
|
5760
|
-
},
|
|
5761
|
-
detached() {
|
|
5762
|
-
Current.app.unmount(this.compId);
|
|
5763
|
-
},
|
|
5764
|
-
pageLifetimes: {
|
|
5765
|
-
show() {
|
|
5766
|
-
safeExecute(this.compId, 'onShow');
|
|
5767
|
-
},
|
|
5768
|
-
hide() {
|
|
5769
|
-
safeExecute(this.compId, 'onHide');
|
|
5770
|
-
}
|
|
5771
|
-
},
|
|
5772
|
-
methods: {
|
|
5773
|
-
eh: eventHandler
|
|
5774
|
-
}
|
|
5775
|
-
};
|
|
5776
|
-
function setCurrent() {
|
|
5777
|
-
const pages = getCurrentPages();
|
|
5778
|
-
const currentPage = pages[pages.length - 1];
|
|
5779
|
-
if (Current.page === currentPage)
|
|
5780
|
-
return;
|
|
5781
|
-
Current.page = currentPage;
|
|
5782
|
-
const route = currentPage.route || currentPage.__route__;
|
|
5783
|
-
const router = {
|
|
5784
|
-
params: currentPage.options || {},
|
|
5785
|
-
path: addLeadingSlash(route),
|
|
5786
|
-
onReady: '',
|
|
5787
|
-
onHide: '',
|
|
5788
|
-
onShow: ''
|
|
5789
|
-
};
|
|
5790
|
-
Current.router = router;
|
|
5791
|
-
if (!currentPage.options) {
|
|
5792
|
-
// 例如在微信小程序中,页面 options 的设置时机比组件 attached 慢
|
|
5793
|
-
Object.defineProperty(currentPage, 'options', {
|
|
5794
|
-
enumerable: true,
|
|
5795
|
-
configurable: true,
|
|
5796
|
-
get() {
|
|
5797
|
-
return this._optionsValue;
|
|
5798
|
-
},
|
|
5799
|
-
set(value) {
|
|
5800
|
-
router.params = value;
|
|
5801
|
-
this._optionsValue = value;
|
|
5802
|
-
}
|
|
5803
|
-
});
|
|
5804
|
-
}
|
|
5805
|
-
}
|
|
5806
|
-
return config;
|
|
5807
|
-
}
|
|
5808
|
-
|
|
5809
|
-
function connectVuePage(Vue, id) {
|
|
5810
|
-
return (component) => {
|
|
5811
|
-
const injectedPage = Vue.extend({
|
|
5812
|
-
props: {
|
|
5813
|
-
tid: String
|
|
5814
|
-
},
|
|
5815
|
-
mixins: [component, {
|
|
5816
|
-
created() {
|
|
5817
|
-
injectPageInstance(this, id);
|
|
5818
|
-
}
|
|
5819
|
-
}]
|
|
5820
|
-
});
|
|
5821
|
-
const options = {
|
|
5822
|
-
render(h) {
|
|
5823
|
-
return h(isBrowser ? 'div' : 'root', {
|
|
5824
|
-
attrs: {
|
|
5825
|
-
id,
|
|
5826
|
-
class: isBrowser ? 'taro_page' : ''
|
|
5827
|
-
}
|
|
5828
|
-
}, [
|
|
5829
|
-
h(injectedPage, { props: { tid: id } })
|
|
5830
|
-
]);
|
|
5831
|
-
}
|
|
5832
|
-
};
|
|
5833
|
-
return options;
|
|
5834
|
-
};
|
|
5835
|
-
}
|
|
5836
|
-
function setReconciler$1() {
|
|
5837
|
-
const hooks = container.get(SERVICE_IDENTIFIER.Hooks);
|
|
5838
|
-
const onRemoveAttribute = function (dom, qualifiedName) {
|
|
5839
|
-
// 处理原因: https://github.com/NervJS/taro/pull/5990
|
|
5840
|
-
const props = dom.props;
|
|
5841
|
-
if (!props.hasOwnProperty(qualifiedName) || isBoolean(props[qualifiedName])) {
|
|
5842
|
-
dom.setAttribute(qualifiedName, false);
|
|
5843
|
-
return true;
|
|
5844
|
-
}
|
|
5845
|
-
};
|
|
5846
|
-
const getLifecycle = function (instance, lifecycle) {
|
|
5847
|
-
return instance.$options[lifecycle];
|
|
5848
|
-
};
|
|
5849
|
-
hooks.onRemoveAttribute = onRemoveAttribute;
|
|
5850
|
-
hooks.getLifecycle = getLifecycle;
|
|
5851
|
-
if (process.env.TARO_ENV === 'h5') {
|
|
5852
|
-
hooks.createPullDownComponent = (el, path, vue) => {
|
|
5853
|
-
const injectedPage = vue.extend({
|
|
5854
|
-
props: {
|
|
5855
|
-
tid: String
|
|
5856
|
-
},
|
|
5857
|
-
mixins: [el, {
|
|
5858
|
-
created() {
|
|
5859
|
-
injectPageInstance(this, path);
|
|
5860
|
-
}
|
|
5861
|
-
}]
|
|
5862
|
-
});
|
|
5863
|
-
const options = {
|
|
5864
|
-
name: 'PullToRefresh',
|
|
5865
|
-
render(h) {
|
|
5866
|
-
return h('taro-pull-to-refresh', {
|
|
5867
|
-
class: ['hydrated']
|
|
5868
|
-
}, [h(injectedPage, this.$slots.default)]);
|
|
5869
|
-
}
|
|
5870
|
-
};
|
|
5871
|
-
return options;
|
|
5872
|
-
};
|
|
5873
|
-
hooks.getDOMNode = (el) => {
|
|
5874
|
-
return el.$el;
|
|
5875
|
-
};
|
|
5876
|
-
}
|
|
5877
|
-
}
|
|
5878
|
-
let Vue;
|
|
5879
|
-
function createVueApp(App, vue, config) {
|
|
5880
|
-
Vue = vue;
|
|
5881
|
-
ensure(!!Vue, '构建 Vue 项目请把 process.env.FRAMEWORK 设置为 \'vue\'');
|
|
5882
|
-
setReconciler$1();
|
|
5883
|
-
Vue.config.getTagNamespace = noop;
|
|
5884
|
-
const elements = [];
|
|
5885
|
-
const pages = [];
|
|
5886
|
-
let appInstance;
|
|
5887
|
-
const wrapper = new Vue({
|
|
5888
|
-
render(h) {
|
|
5889
|
-
while (pages.length > 0) {
|
|
5890
|
-
const page = pages.pop();
|
|
5891
|
-
elements.push(page(h));
|
|
5892
|
-
}
|
|
5893
|
-
return h(App, { ref: 'app' }, elements.slice());
|
|
5894
|
-
},
|
|
5895
|
-
methods: {
|
|
5896
|
-
mount(component, id, cb) {
|
|
5897
|
-
pages.push((h) => h(component, { key: id }));
|
|
5898
|
-
this.updateSync(cb);
|
|
5899
|
-
},
|
|
5900
|
-
updateSync(cb) {
|
|
5901
|
-
this._update(this._render(), false);
|
|
5902
|
-
this.$children.forEach((child) => child._update(child._render(), false));
|
|
5903
|
-
cb();
|
|
5904
|
-
},
|
|
5905
|
-
unmount(id, cb) {
|
|
5906
|
-
for (let i = 0; i < elements.length; i++) {
|
|
5907
|
-
const element = elements[i];
|
|
5908
|
-
if (element.key === id) {
|
|
5909
|
-
elements.splice(i, 1);
|
|
5910
|
-
break;
|
|
5911
|
-
}
|
|
5912
|
-
}
|
|
5913
|
-
this.updateSync(cb);
|
|
5914
|
-
}
|
|
5915
|
-
}
|
|
5916
|
-
});
|
|
5917
|
-
if (!isBrowser) {
|
|
5918
|
-
wrapper.$mount(document$2.getElementById('app'));
|
|
5919
|
-
}
|
|
5920
|
-
const app = Object.create({
|
|
5921
|
-
mount(component, id, cb) {
|
|
5922
|
-
const page = connectVuePage(Vue, id)(component);
|
|
5923
|
-
wrapper.mount(page, id, cb);
|
|
5924
|
-
},
|
|
5925
|
-
unmount(id, cb) {
|
|
5926
|
-
wrapper.unmount(id, cb);
|
|
5927
|
-
}
|
|
5928
|
-
}, {
|
|
5929
|
-
config: {
|
|
5930
|
-
writable: true,
|
|
5931
|
-
enumerable: true,
|
|
5932
|
-
configurable: true,
|
|
5933
|
-
value: config
|
|
5934
|
-
},
|
|
5935
|
-
onLaunch: {
|
|
5936
|
-
writable: true,
|
|
5937
|
-
enumerable: true,
|
|
5938
|
-
value(options) {
|
|
5939
|
-
Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
|
|
5940
|
-
if (isBrowser) {
|
|
5941
|
-
// 由于 H5 路由初始化的时候会清除 app 下的 dom 元素,所以需要在路由初始化后再执行 render
|
|
5942
|
-
wrapper.$mount(document$2.getElementById('app'));
|
|
5943
|
-
}
|
|
5944
|
-
appInstance = wrapper.$refs.app;
|
|
5945
|
-
if (appInstance != null && isFunction$1(appInstance.$options.onLaunch)) {
|
|
5946
|
-
appInstance.$options.onLaunch.call(appInstance, options);
|
|
5947
|
-
}
|
|
5948
|
-
}
|
|
5949
|
-
},
|
|
5950
|
-
onShow: {
|
|
5951
|
-
writable: true,
|
|
5952
|
-
enumerable: true,
|
|
5953
|
-
value(options) {
|
|
5954
|
-
Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
|
|
5955
|
-
if (appInstance != null && isFunction$1(appInstance.$options.onShow)) {
|
|
5956
|
-
appInstance.$options.onShow.call(appInstance, options);
|
|
5957
|
-
}
|
|
5958
|
-
}
|
|
5959
|
-
},
|
|
5960
|
-
onHide: {
|
|
5961
|
-
writable: true,
|
|
5962
|
-
enumerable: true,
|
|
5963
|
-
value(options) {
|
|
5964
|
-
if (appInstance != null && isFunction$1(appInstance.$options.onHide)) {
|
|
5965
|
-
appInstance.$options.onHide.call(appInstance, options);
|
|
5966
|
-
}
|
|
5967
|
-
}
|
|
5968
|
-
}
|
|
5969
|
-
});
|
|
5970
|
-
Current.app = app;
|
|
5971
|
-
return Current.app;
|
|
5972
|
-
}
|
|
5973
|
-
|
|
5974
|
-
function createVue3Page(h, id) {
|
|
5975
|
-
return function (component) {
|
|
5976
|
-
var _a;
|
|
5977
|
-
const inject = {
|
|
5978
|
-
props: {
|
|
5979
|
-
tid: String
|
|
5980
|
-
},
|
|
5981
|
-
created() {
|
|
5982
|
-
injectPageInstance(this, id);
|
|
5983
|
-
}
|
|
5984
|
-
};
|
|
5985
|
-
if (isArray$1(component.mixins)) {
|
|
5986
|
-
const mixins = component.mixins;
|
|
5987
|
-
const idx = mixins.length - 1;
|
|
5988
|
-
if (!((_a = mixins[idx].props) === null || _a === void 0 ? void 0 : _a.tid)) {
|
|
5989
|
-
// mixins 里还没注入过,直接推入数组
|
|
5990
|
-
component.mixins.push(inject);
|
|
5991
|
-
}
|
|
5992
|
-
else {
|
|
5993
|
-
// mixins 里已经注入过,代替前者
|
|
5994
|
-
component.mixins[idx] = inject;
|
|
5995
|
-
}
|
|
5996
|
-
}
|
|
5997
|
-
else {
|
|
5998
|
-
component.mixins = [inject];
|
|
5999
|
-
}
|
|
6000
|
-
return h(isBrowser ? 'div' : 'root', {
|
|
6001
|
-
key: id,
|
|
6002
|
-
id,
|
|
6003
|
-
class: isBrowser ? 'taro_page' : ''
|
|
6004
|
-
}, [
|
|
6005
|
-
h(Object.assign({}, component), {
|
|
6006
|
-
tid: id
|
|
6007
|
-
})
|
|
6008
|
-
]);
|
|
6009
|
-
};
|
|
6010
|
-
}
|
|
6011
|
-
function setReconciler$2() {
|
|
6012
|
-
const hooks = container.get(SERVICE_IDENTIFIER.Hooks);
|
|
6013
|
-
const getLifecycle = function (instance, lifecycle) {
|
|
6014
|
-
return instance.$options[lifecycle];
|
|
6015
|
-
};
|
|
6016
|
-
const modifyMpEvent = function (event) {
|
|
6017
|
-
event.type = event.type.replace(/-/g, '');
|
|
6018
|
-
};
|
|
6019
|
-
hooks.getLifecycle = getLifecycle;
|
|
6020
|
-
hooks.modifyMpEvent = modifyMpEvent;
|
|
6021
|
-
if (process.env.TARO_ENV === 'h5') {
|
|
6022
|
-
hooks.createPullDownComponent = (component, path, h) => {
|
|
6023
|
-
const inject = {
|
|
6024
|
-
props: {
|
|
6025
|
-
tid: String
|
|
6026
|
-
},
|
|
6027
|
-
created() {
|
|
6028
|
-
injectPageInstance(this, path);
|
|
6029
|
-
}
|
|
6030
|
-
};
|
|
6031
|
-
component.mixins = isArray$1(component.mixins)
|
|
6032
|
-
? component.mixins.push(inject)
|
|
6033
|
-
: [inject];
|
|
6034
|
-
return {
|
|
6035
|
-
render() {
|
|
6036
|
-
return h('taro-pull-to-refresh', {
|
|
6037
|
-
class: 'hydrated'
|
|
6038
|
-
}, [h(component, this.$slots.default)]);
|
|
6039
|
-
}
|
|
6040
|
-
};
|
|
6041
|
-
};
|
|
6042
|
-
hooks.getDOMNode = (el) => {
|
|
6043
|
-
return el.$el;
|
|
6044
|
-
};
|
|
6045
|
-
}
|
|
6046
|
-
}
|
|
6047
|
-
function createVue3App(app, h, config) {
|
|
6048
|
-
let pages = [];
|
|
6049
|
-
let appInstance;
|
|
6050
|
-
ensure(!isFunction$1(app._component), '入口组件不支持使用函数式组件');
|
|
6051
|
-
setReconciler$2();
|
|
6052
|
-
app._component.render = function () {
|
|
6053
|
-
return pages.slice();
|
|
6054
|
-
};
|
|
6055
|
-
if (!isBrowser) {
|
|
6056
|
-
appInstance = app.mount('#app');
|
|
6057
|
-
}
|
|
6058
|
-
const appConfig = Object.create({
|
|
6059
|
-
mount(component, id, cb) {
|
|
6060
|
-
const page = createVue3Page(h, id)(component);
|
|
6061
|
-
pages.push(page);
|
|
6062
|
-
this.updateAppInstance(cb);
|
|
6063
|
-
},
|
|
6064
|
-
unmount(id, cb) {
|
|
6065
|
-
pages = pages.filter(page => page.key !== id);
|
|
6066
|
-
this.updateAppInstance(cb);
|
|
6067
|
-
},
|
|
6068
|
-
updateAppInstance(cb) {
|
|
6069
|
-
appInstance.$forceUpdate();
|
|
6070
|
-
appInstance.$nextTick(cb);
|
|
6071
|
-
}
|
|
6072
|
-
}, {
|
|
6073
|
-
config: {
|
|
6074
|
-
writable: true,
|
|
6075
|
-
enumerable: true,
|
|
6076
|
-
configurable: true,
|
|
6077
|
-
value: config
|
|
6078
|
-
},
|
|
6079
|
-
onLaunch: {
|
|
6080
|
-
writable: true,
|
|
6081
|
-
enumerable: true,
|
|
6082
|
-
value(options) {
|
|
6083
|
-
var _a;
|
|
6084
|
-
Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
|
|
6085
|
-
if (isBrowser) {
|
|
6086
|
-
appInstance = app.mount('#app');
|
|
6087
|
-
}
|
|
6088
|
-
// 把 App Class 上挂载的额外属性同步到全局 app 对象中
|
|
6089
|
-
// eslint-disable-next-line dot-notation
|
|
6090
|
-
if (app['taroGlobalData']) {
|
|
6091
|
-
// eslint-disable-next-line dot-notation
|
|
6092
|
-
const globalData = app['taroGlobalData'];
|
|
6093
|
-
const keys = Object.keys(globalData);
|
|
6094
|
-
const descriptors = Object.getOwnPropertyDescriptors(globalData);
|
|
6095
|
-
keys.forEach(key => {
|
|
6096
|
-
Object.defineProperty(this, key, {
|
|
6097
|
-
configurable: true,
|
|
6098
|
-
enumerable: true,
|
|
6099
|
-
get() {
|
|
6100
|
-
return globalData[key];
|
|
6101
|
-
},
|
|
6102
|
-
set(value) {
|
|
6103
|
-
globalData[key] = value;
|
|
6104
|
-
}
|
|
6105
|
-
});
|
|
6106
|
-
});
|
|
6107
|
-
Object.defineProperties(this, descriptors);
|
|
6108
|
-
}
|
|
6109
|
-
const onLaunch = (_a = appInstance === null || appInstance === void 0 ? void 0 : appInstance.$options) === null || _a === void 0 ? void 0 : _a.onLaunch;
|
|
6110
|
-
isFunction$1(onLaunch) && onLaunch.call(appInstance, options);
|
|
6111
|
-
}
|
|
6112
|
-
},
|
|
6113
|
-
onShow: {
|
|
6114
|
-
writable: true,
|
|
6115
|
-
enumerable: true,
|
|
6116
|
-
value(options) {
|
|
6117
|
-
var _a;
|
|
6118
|
-
Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
|
|
6119
|
-
const onShow = (_a = appInstance === null || appInstance === void 0 ? void 0 : appInstance.$options) === null || _a === void 0 ? void 0 : _a.onShow;
|
|
6120
|
-
isFunction$1(onShow) && onShow.call(appInstance, options);
|
|
6121
|
-
}
|
|
6122
|
-
},
|
|
6123
|
-
onHide: {
|
|
6124
|
-
writable: true,
|
|
6125
|
-
enumerable: true,
|
|
6126
|
-
value(options) {
|
|
6127
|
-
var _a;
|
|
6128
|
-
const onHide = (_a = appInstance === null || appInstance === void 0 ? void 0 : appInstance.$options) === null || _a === void 0 ? void 0 : _a.onHide;
|
|
6129
|
-
isFunction$1(onHide) && onHide.call(appInstance, options);
|
|
6130
|
-
}
|
|
6131
|
-
}
|
|
6132
|
-
});
|
|
6133
|
-
Current.app = appConfig;
|
|
6134
|
-
return Current.app;
|
|
6135
|
-
}
|
|
6136
|
-
|
|
6137
|
-
const taroHooks = (lifecycle) => {
|
|
6138
|
-
return (fn) => {
|
|
6139
|
-
const id = R.useContext(PageContext) || HOOKS_APP_ID;
|
|
6140
|
-
// hold fn ref and keep up to date
|
|
6141
|
-
const fnRef = R.useRef(fn);
|
|
6142
|
-
if (fnRef.current !== fn)
|
|
6143
|
-
fnRef.current = fn;
|
|
6144
|
-
R.useLayoutEffect(() => {
|
|
6145
|
-
let inst = getPageInstance(id);
|
|
6146
|
-
let first = false;
|
|
6147
|
-
if (inst == null) {
|
|
6148
|
-
first = true;
|
|
6149
|
-
inst = Object.create(null);
|
|
6150
|
-
}
|
|
6151
|
-
inst = inst;
|
|
6152
|
-
// callback is immutable but inner function is up to date
|
|
6153
|
-
const callback = (...args) => fnRef.current(...args);
|
|
6154
|
-
if (isFunction$1(inst[lifecycle])) {
|
|
6155
|
-
inst[lifecycle] = [inst[lifecycle], callback];
|
|
6156
|
-
}
|
|
6157
|
-
else {
|
|
6158
|
-
inst[lifecycle] = [
|
|
6159
|
-
...(inst[lifecycle] || []),
|
|
6160
|
-
callback
|
|
6161
|
-
];
|
|
6162
|
-
}
|
|
6163
|
-
if (first) {
|
|
6164
|
-
injectPageInstance(inst, id);
|
|
6165
|
-
}
|
|
6166
|
-
return () => {
|
|
6167
|
-
const inst = getPageInstance(id);
|
|
6168
|
-
const list = inst[lifecycle];
|
|
6169
|
-
if (list === callback) {
|
|
6170
|
-
inst[lifecycle] = undefined;
|
|
6171
|
-
}
|
|
6172
|
-
else if (isArray$1(list)) {
|
|
6173
|
-
inst[lifecycle] = list.filter(item => item !== callback);
|
|
6174
|
-
}
|
|
6175
|
-
};
|
|
6176
|
-
}, []);
|
|
6177
|
-
};
|
|
6178
|
-
};
|
|
6179
|
-
const useDidShow = taroHooks('componentDidShow');
|
|
6180
|
-
const useDidHide = taroHooks('componentDidHide');
|
|
6181
|
-
const usePullDownRefresh = taroHooks('onPullDownRefresh');
|
|
6182
|
-
const useReachBottom = taroHooks('onReachBottom');
|
|
6183
|
-
const usePageScroll = taroHooks('onPageScroll');
|
|
6184
|
-
const useResize = taroHooks('onResize');
|
|
6185
|
-
const useShareAppMessage = taroHooks('onShareAppMessage');
|
|
6186
|
-
const useTabItemTap = taroHooks('onTabItemTap');
|
|
6187
|
-
const useTitleClick = taroHooks('onTitleClick');
|
|
6188
|
-
const useOptionMenuClick = taroHooks('onOptionMenuClick');
|
|
6189
|
-
const usePullIntercept = taroHooks('onPullIntercept');
|
|
6190
|
-
const useShareTimeline = taroHooks('onShareTimeline');
|
|
6191
|
-
const useAddToFavorites = taroHooks('onAddToFavorites');
|
|
6192
|
-
const useReady = taroHooks('onReady');
|
|
6193
|
-
const useRouter = (dynamic = false) => {
|
|
6194
|
-
return dynamic ? Current.router : R.useMemo(() => Current.router, []);
|
|
6195
|
-
};
|
|
6196
|
-
const useScope = () => undefined;
|
|
6197
|
-
|
|
6198
4657
|
function removeLeadingSlash(path) {
|
|
6199
4658
|
if (path == null) {
|
|
6200
4659
|
return '';
|
|
@@ -6212,9 +4671,9 @@ const nextTick = (cb, ctx) => {
|
|
|
6212
4671
|
if (router !== null) {
|
|
6213
4672
|
let pageElement = null;
|
|
6214
4673
|
const path = getPath(removeLeadingSlash(router.path), router.params);
|
|
6215
|
-
pageElement = document$
|
|
4674
|
+
pageElement = document$1.getElementById(path);
|
|
6216
4675
|
if (pageElement === null || pageElement === void 0 ? void 0 : pageElement.pendingUpdate) {
|
|
6217
|
-
if (
|
|
4676
|
+
if (process.env.TARO_ENV === 'h5') {
|
|
6218
4677
|
// eslint-disable-next-line dot-notation
|
|
6219
4678
|
(_c = (_b = (_a = pageElement.firstChild) === null || _a === void 0 ? void 0 : _a['componentOnReady']) === null || _b === void 0 ? void 0 : _b.call(_a).then(() => {
|
|
6220
4679
|
timerFunc();
|
|
@@ -6233,5 +4692,5 @@ const nextTick = (cb, ctx) => {
|
|
|
6233
4692
|
}
|
|
6234
4693
|
};
|
|
6235
4694
|
|
|
6236
|
-
export { Current, ElementNames, Events, FormElement, SERVICE_IDENTIFIER, SVGElement, Style, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, caf as cancelAnimationFrame,
|
|
4695
|
+
export { Current, ElementNames, Events, FormElement, MutationObserver, SERVICE_IDENTIFIER, SVGElement, Style, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, addLeadingSlash, caf as cancelAnimationFrame, container, createComponentConfig, createDocument, createEvent, createPageConfig, createRecursiveComponentConfig, document$1 as document, eventCenter, eventHandler, eventSource, getComputedStyle, getCurrentInstance, getPageInstance, hydrate, incrementId, injectPageInstance, navigator, nextTick, now, options, processPluginHooks, raf as requestAnimationFrame, safeExecute, stringify, window$1 as window };
|
|
6237
4696
|
//# sourceMappingURL=runtime.esm.js.map
|