@tarojs/runtime 3.3.16 → 3.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bom/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 +1108 -2649
- 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
|
|
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,
|
|
@@ -3971,8 +3274,12 @@ class StyleTagParser {
|
|
|
3971
3274
|
// console.log('res this.styles: ', this.styles)
|
|
3972
3275
|
}
|
|
3973
3276
|
parseSelector(src) {
|
|
3974
|
-
|
|
3975
|
-
|
|
3277
|
+
const list = src
|
|
3278
|
+
.trim()
|
|
3279
|
+
.replace(/ *([>~+]) */g, ' $1')
|
|
3280
|
+
.replace(/ +/g, ' ')
|
|
3281
|
+
.replace(/\[\s*([^[\]=\s]+)\s*=\s*([^[\]=\s]+)\s*\]/g, '[$1=$2]')
|
|
3282
|
+
.split(' ');
|
|
3976
3283
|
const selectors = list.map(item => {
|
|
3977
3284
|
const firstChar = item.charAt(0);
|
|
3978
3285
|
const selector = {
|
|
@@ -4218,7 +3525,7 @@ function format(children, document, styleOptions, parent) {
|
|
|
4218
3525
|
// 文本节点
|
|
4219
3526
|
if (child.type === 'text') {
|
|
4220
3527
|
let text = document.createTextNode(child.content);
|
|
4221
|
-
if (isFunction
|
|
3528
|
+
if (isFunction(options.html.transformText)) {
|
|
4222
3529
|
text = options.html.transformText(text, child);
|
|
4223
3530
|
}
|
|
4224
3531
|
parent === null || parent === void 0 ? void 0 : parent.appendChild(text);
|
|
@@ -4252,7 +3559,7 @@ function format(children, document, styleOptions, parent) {
|
|
|
4252
3559
|
styleTagParser,
|
|
4253
3560
|
descendantList: list
|
|
4254
3561
|
}, el);
|
|
4255
|
-
if (isFunction
|
|
3562
|
+
if (isFunction(options.html.transformElement)) {
|
|
4256
3563
|
return options.html.transformElement(el, child);
|
|
4257
3564
|
}
|
|
4258
3565
|
return el;
|
|
@@ -4382,7 +3689,7 @@ function setInnerHTML(element, html, getDoc) {
|
|
|
4382
3689
|
* An implementation of `Element.insertAdjacentHTML()`
|
|
4383
3690
|
* to support Vue 3 with a version of or greater than `vue@3.1.2`
|
|
4384
3691
|
*/
|
|
4385
|
-
function insertAdjacentHTMLImpl(position, html
|
|
3692
|
+
function insertAdjacentHTMLImpl(getDoc, position, html) {
|
|
4386
3693
|
var _a, _b;
|
|
4387
3694
|
const parsedNodes = parser(html, getDoc());
|
|
4388
3695
|
for (let i = 0; i < parsedNodes.length; i++) {
|
|
@@ -4408,13 +3715,13 @@ function insertAdjacentHTMLImpl(position, html, getDoc) {
|
|
|
4408
3715
|
}
|
|
4409
3716
|
}
|
|
4410
3717
|
}
|
|
4411
|
-
function cloneNode(
|
|
3718
|
+
function cloneNode(getDoc, isDeep = false) {
|
|
4412
3719
|
const document = getDoc();
|
|
4413
3720
|
let newNode;
|
|
4414
|
-
if (
|
|
4415
|
-
newNode = document.createElement(
|
|
3721
|
+
if (this.nodeType === 1 /* ELEMENT_NODE */) {
|
|
3722
|
+
newNode = document.createElement(this.nodeName);
|
|
4416
3723
|
}
|
|
4417
|
-
else if (
|
|
3724
|
+
else if (this.nodeType === 3 /* TEXT_NODE */) {
|
|
4418
3725
|
newNode = document.createTextNode('');
|
|
4419
3726
|
}
|
|
4420
3727
|
for (const key in this) {
|
|
@@ -4431,9 +3738,20 @@ function cloneNode(ctx, getDoc, isDeep = false) {
|
|
|
4431
3738
|
}
|
|
4432
3739
|
}
|
|
4433
3740
|
if (isDeep) {
|
|
4434
|
-
newNode.childNodes =
|
|
3741
|
+
newNode.childNodes = this.childNodes.map(node => node.cloneNode(true));
|
|
4435
3742
|
}
|
|
4436
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;
|
|
4437
3755
|
}
|
|
4438
3756
|
|
|
4439
3757
|
let TaroNodeImpl = class TaroNodeImpl {
|
|
@@ -4446,11 +3764,14 @@ let TaroNodeImpl = class TaroNodeImpl {
|
|
|
4446
3764
|
if (ENABLE_INNER_HTML) {
|
|
4447
3765
|
bindInnerHTML(ctx, getDoc);
|
|
4448
3766
|
if (ENABLE_ADJACENT_HTML) {
|
|
4449
|
-
|
|
3767
|
+
ctx.insertAdjacentHTML = insertAdjacentHTMLImpl.bind(ctx, getDoc);
|
|
4450
3768
|
}
|
|
4451
3769
|
}
|
|
4452
3770
|
if (ENABLE_CLONE_NODE) {
|
|
4453
|
-
ctx.cloneNode = cloneNode.bind(ctx,
|
|
3771
|
+
ctx.cloneNode = cloneNode.bind(ctx, getDoc);
|
|
3772
|
+
}
|
|
3773
|
+
if (ENABLE_CONTAINS) {
|
|
3774
|
+
ctx.contains = contains.bind(ctx);
|
|
4454
3775
|
}
|
|
4455
3776
|
}
|
|
4456
3777
|
};
|
|
@@ -4464,17 +3785,12 @@ function bindInnerHTML(ctx, getDoc) {
|
|
|
4464
3785
|
configurable: true,
|
|
4465
3786
|
enumerable: true,
|
|
4466
3787
|
set(html) {
|
|
4467
|
-
setInnerHTML.call(
|
|
3788
|
+
setInnerHTML.call(this, this, html, getDoc);
|
|
4468
3789
|
},
|
|
4469
3790
|
get() {
|
|
4470
3791
|
return '';
|
|
4471
3792
|
}
|
|
4472
3793
|
});
|
|
4473
|
-
}
|
|
4474
|
-
function bindAdjacentHTML(ctx, getDoc) {
|
|
4475
|
-
ctx.insertAdjacentHTML = function (position, html) {
|
|
4476
|
-
insertAdjacentHTMLImpl.call(ctx, position, html, getDoc);
|
|
4477
|
-
};
|
|
4478
3794
|
}
|
|
4479
3795
|
|
|
4480
3796
|
function getBoundingClientRectImpl() {
|
|
@@ -4503,9 +3819,7 @@ function getTemplateContent(ctx) {
|
|
|
4503
3819
|
let TaroElementImpl = class TaroElementImpl {
|
|
4504
3820
|
bind(ctx) {
|
|
4505
3821
|
if (ENABLE_SIZE_APIS) {
|
|
4506
|
-
ctx.getBoundingClientRect =
|
|
4507
|
-
return await getBoundingClientRectImpl.apply(ctx, args);
|
|
4508
|
-
};
|
|
3822
|
+
ctx.getBoundingClientRect = getBoundingClientRectImpl.bind(ctx);
|
|
4509
3823
|
}
|
|
4510
3824
|
if (ENABLE_TEMPLATE_CONTENT) {
|
|
4511
3825
|
bindContent(ctx);
|
|
@@ -4527,20 +3841,21 @@ function bindContent(ctx) {
|
|
|
4527
3841
|
|
|
4528
3842
|
let TaroDocument = class TaroDocument extends TaroElement {
|
|
4529
3843
|
constructor(// eslint-disable-next-line @typescript-eslint/indent
|
|
4530
|
-
|
|
4531
|
-
super(
|
|
3844
|
+
getText) {
|
|
3845
|
+
super();
|
|
4532
3846
|
this._getText = getText;
|
|
4533
3847
|
this.nodeType = 9 /* DOCUMENT_NODE */;
|
|
4534
3848
|
this.nodeName = DOCUMENT_ELEMENT_NAME;
|
|
4535
3849
|
}
|
|
4536
3850
|
createElement(type) {
|
|
3851
|
+
const getElement = this._getElement;
|
|
4537
3852
|
if (type === ROOT_STR) {
|
|
4538
|
-
return
|
|
3853
|
+
return getElement(ElementNames.RootElement)();
|
|
4539
3854
|
}
|
|
4540
3855
|
if (controlledComponent.has(type)) {
|
|
4541
|
-
return
|
|
3856
|
+
return getElement(ElementNames.FormElement)(type);
|
|
4542
3857
|
}
|
|
4543
|
-
return
|
|
3858
|
+
return getElement(ElementNames.Element)(type);
|
|
4544
3859
|
}
|
|
4545
3860
|
// an ugly fake createElementNS to deal with @vue/runtime-dom's
|
|
4546
3861
|
// support mounting app to svg container since vue@3.0.8
|
|
@@ -4574,23 +3889,109 @@ let TaroDocument = class TaroDocument extends TaroElement {
|
|
|
4574
3889
|
};
|
|
4575
3890
|
TaroDocument = __decorate([
|
|
4576
3891
|
injectable(),
|
|
4577
|
-
__param(0, inject(
|
|
4578
|
-
|
|
4579
|
-
__param(2, inject(SERVICE_IDENTIFIER.Hooks)),
|
|
4580
|
-
__param(3, inject(SERVICE_IDENTIFIER.TaroElementImpl)),
|
|
4581
|
-
__param(4, inject(SERVICE_IDENTIFIER.TaroTextFactory)),
|
|
4582
|
-
__metadata("design:paramtypes", [Function, Function, Function, Function, Function])
|
|
3892
|
+
__param(0, inject(SID_TARO_TEXT_FACTORY)),
|
|
3893
|
+
__metadata("design:paramtypes", [Function])
|
|
4583
3894
|
], TaroDocument);
|
|
4584
3895
|
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
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;
|
|
4592
3989
|
(_a = this.modifyTaroEventImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(e, element));
|
|
4593
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
|
+
}
|
|
4594
3995
|
initNativeApi(taro) {
|
|
4595
3996
|
var _a;
|
|
4596
3997
|
(_a = this.initNativeApiImpls) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(taro));
|
|
@@ -4601,87 +4002,101 @@ let Hooks = class Hooks {
|
|
|
4601
4002
|
}
|
|
4602
4003
|
};
|
|
4603
4004
|
__decorate([
|
|
4604
|
-
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),
|
|
4605
4010
|
__metadata("design:type", Function)
|
|
4606
4011
|
], Hooks.prototype, "getLifecycle", void 0);
|
|
4607
4012
|
__decorate([
|
|
4608
|
-
inject(
|
|
4013
|
+
inject(SID_GET_PATH_INDEX),
|
|
4609
4014
|
__metadata("design:type", Function)
|
|
4610
4015
|
], Hooks.prototype, "getPathIndex", void 0);
|
|
4611
4016
|
__decorate([
|
|
4612
|
-
inject(
|
|
4017
|
+
inject(SID_GET_EVENT_CENTER),
|
|
4613
4018
|
__metadata("design:type", Function)
|
|
4614
4019
|
], Hooks.prototype, "getEventCenter", void 0);
|
|
4615
4020
|
__decorate([
|
|
4616
|
-
inject(
|
|
4021
|
+
inject(SID_IS_BUBBLE_EVENTS),
|
|
4617
4022
|
__metadata("design:type", Function)
|
|
4618
4023
|
], Hooks.prototype, "isBubbleEvents", void 0);
|
|
4619
4024
|
__decorate([
|
|
4620
|
-
inject(
|
|
4025
|
+
inject(SID_GET_SPECIAL_NODES),
|
|
4621
4026
|
__metadata("design:type", Function)
|
|
4622
4027
|
], Hooks.prototype, "getSpecialNodes", void 0);
|
|
4623
4028
|
__decorate([
|
|
4624
|
-
inject(
|
|
4029
|
+
inject(SID_ON_REMOVE_ATTRIBUTE),
|
|
4625
4030
|
optional(),
|
|
4626
4031
|
__metadata("design:type", Function)
|
|
4627
4032
|
], Hooks.prototype, "onRemoveAttribute", void 0);
|
|
4628
4033
|
__decorate([
|
|
4629
|
-
inject(
|
|
4034
|
+
inject(SID_BATCHED_EVENT_UPDATES),
|
|
4630
4035
|
optional(),
|
|
4631
4036
|
__metadata("design:type", Function)
|
|
4632
4037
|
], Hooks.prototype, "batchedEventUpdates", void 0);
|
|
4633
4038
|
__decorate([
|
|
4634
|
-
inject(
|
|
4039
|
+
inject(SID_MERGE_PAGE_INSTANCE),
|
|
4635
4040
|
optional(),
|
|
4636
4041
|
__metadata("design:type", Function)
|
|
4637
4042
|
], Hooks.prototype, "mergePageInstance", void 0);
|
|
4638
4043
|
__decorate([
|
|
4639
|
-
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),
|
|
4640
4050
|
optional(),
|
|
4641
4051
|
__metadata("design:type", Function)
|
|
4642
4052
|
], Hooks.prototype, "createPullDownComponent", void 0);
|
|
4643
4053
|
__decorate([
|
|
4644
|
-
inject(
|
|
4054
|
+
inject(SID_GET_DOM_NODE),
|
|
4645
4055
|
optional(),
|
|
4646
4056
|
__metadata("design:type", Function)
|
|
4647
4057
|
], Hooks.prototype, "getDOMNode", void 0);
|
|
4648
4058
|
__decorate([
|
|
4649
|
-
inject(
|
|
4059
|
+
inject(SID_MODIFY_HYDRATE_DATA),
|
|
4650
4060
|
optional(),
|
|
4651
4061
|
__metadata("design:type", Function)
|
|
4652
4062
|
], Hooks.prototype, "modifyHydrateData", void 0);
|
|
4653
4063
|
__decorate([
|
|
4654
|
-
inject(
|
|
4064
|
+
inject(SID_MODIFY_SET_ATTR_PAYLOAD),
|
|
4655
4065
|
optional(),
|
|
4656
4066
|
__metadata("design:type", Function)
|
|
4657
4067
|
], Hooks.prototype, "modifySetAttrPayload", void 0);
|
|
4658
4068
|
__decorate([
|
|
4659
|
-
inject(
|
|
4069
|
+
inject(SID_MODIFY_RM_ATTR_PAYLOAD),
|
|
4660
4070
|
optional(),
|
|
4661
4071
|
__metadata("design:type", Function)
|
|
4662
4072
|
], Hooks.prototype, "modifyRmAttrPayload", void 0);
|
|
4663
4073
|
__decorate([
|
|
4664
|
-
inject(
|
|
4074
|
+
inject(SID_ON_ADD_EVENT),
|
|
4665
4075
|
optional(),
|
|
4666
4076
|
__metadata("design:type", Function)
|
|
4667
4077
|
], Hooks.prototype, "onAddEvent", void 0);
|
|
4668
4078
|
__decorate([
|
|
4669
|
-
multiInject(
|
|
4079
|
+
multiInject(SID_MODIFY_MP_EVENT),
|
|
4670
4080
|
optional(),
|
|
4671
4081
|
__metadata("design:type", Array)
|
|
4672
4082
|
], Hooks.prototype, "modifyMpEventImpls", void 0);
|
|
4673
4083
|
__decorate([
|
|
4674
|
-
multiInject(
|
|
4084
|
+
multiInject(SID_MODIFY_TARO_EVENT),
|
|
4675
4085
|
optional(),
|
|
4676
4086
|
__metadata("design:type", Array)
|
|
4677
4087
|
], Hooks.prototype, "modifyTaroEventImpls", void 0);
|
|
4678
4088
|
__decorate([
|
|
4679
|
-
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),
|
|
4680
4095
|
optional(),
|
|
4681
4096
|
__metadata("design:type", Array)
|
|
4682
4097
|
], Hooks.prototype, "initNativeApiImpls", void 0);
|
|
4683
4098
|
__decorate([
|
|
4684
|
-
multiInject(
|
|
4099
|
+
multiInject(SID_PATCH_ELEMENT),
|
|
4685
4100
|
optional(),
|
|
4686
4101
|
__metadata("design:type", Array)
|
|
4687
4102
|
], Hooks.prototype, "patchElementImpls", void 0);
|
|
@@ -4689,48 +4104,6 @@ Hooks = __decorate([
|
|
|
4689
4104
|
injectable()
|
|
4690
4105
|
], Hooks);
|
|
4691
4106
|
|
|
4692
|
-
/**
|
|
4693
|
-
* 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
|
|
4694
|
-
* 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
|
|
4695
|
-
*/
|
|
4696
|
-
const BUBBLE_EVENTS = new Set([
|
|
4697
|
-
'touchstart',
|
|
4698
|
-
'touchmove',
|
|
4699
|
-
'touchcancel',
|
|
4700
|
-
'touchend',
|
|
4701
|
-
'touchforcechange',
|
|
4702
|
-
'tap',
|
|
4703
|
-
'longpress',
|
|
4704
|
-
'longtap',
|
|
4705
|
-
'transitionend',
|
|
4706
|
-
'animationstart',
|
|
4707
|
-
'animationiteration',
|
|
4708
|
-
'animationend'
|
|
4709
|
-
]);
|
|
4710
|
-
|
|
4711
|
-
const getLifecycle = function (instance, lifecycle) {
|
|
4712
|
-
return instance[lifecycle];
|
|
4713
|
-
};
|
|
4714
|
-
const getPathIndex = function (indexOfNode) {
|
|
4715
|
-
return `[${indexOfNode}]`;
|
|
4716
|
-
};
|
|
4717
|
-
const getEventCenter = function (Events) {
|
|
4718
|
-
return new Events();
|
|
4719
|
-
};
|
|
4720
|
-
const isBubbleEvents = function (eventName) {
|
|
4721
|
-
return BUBBLE_EVENTS.has(eventName);
|
|
4722
|
-
};
|
|
4723
|
-
const getSpecialNodes = function () {
|
|
4724
|
-
return ['view', 'text', 'image'];
|
|
4725
|
-
};
|
|
4726
|
-
const DefaultHooksContainer = new ContainerModule(bind => {
|
|
4727
|
-
bind(SERVICE_IDENTIFIER.getLifecycle).toFunction(getLifecycle);
|
|
4728
|
-
bind(SERVICE_IDENTIFIER.getPathIndex).toFunction(getPathIndex);
|
|
4729
|
-
bind(SERVICE_IDENTIFIER.getEventCenter).toFunction(getEventCenter);
|
|
4730
|
-
bind(SERVICE_IDENTIFIER.isBubbleEvents).toFunction(isBubbleEvents);
|
|
4731
|
-
bind(SERVICE_IDENTIFIER.getSpecialNodes).toFunction(getSpecialNodes);
|
|
4732
|
-
});
|
|
4733
|
-
|
|
4734
4107
|
function processPluginHooks(container) {
|
|
4735
4108
|
const keys = Object.keys(defaultReconciler);
|
|
4736
4109
|
keys.forEach(key => {
|
|
@@ -4738,7 +4111,7 @@ function processPluginHooks(container) {
|
|
|
4738
4111
|
// is hooks
|
|
4739
4112
|
const identifier = SERVICE_IDENTIFIER[key];
|
|
4740
4113
|
const fn = defaultReconciler[key];
|
|
4741
|
-
if (isArray
|
|
4114
|
+
if (isArray(fn)) {
|
|
4742
4115
|
// is multi
|
|
4743
4116
|
fn.forEach(item => container.bind(identifier).toFunction(item));
|
|
4744
4117
|
}
|
|
@@ -4756,14 +4129,27 @@ function processPluginHooks(container) {
|
|
|
4756
4129
|
}
|
|
4757
4130
|
|
|
4758
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
|
+
}
|
|
4759
4142
|
if (process.env.TARO_ENV !== 'h5') {
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
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) => {
|
|
4765
4151
|
return (named) => (nodeName) => {
|
|
4766
|
-
const el = context.container.getNamed(
|
|
4152
|
+
const el = context.container.getNamed(SID_TARO_ELEMENT, named);
|
|
4767
4153
|
if (nodeName) {
|
|
4768
4154
|
el.nodeName = nodeName;
|
|
4769
4155
|
}
|
|
@@ -4771,130 +4157,18 @@ if (process.env.TARO_ENV !== 'h5') {
|
|
|
4771
4157
|
return el;
|
|
4772
4158
|
};
|
|
4773
4159
|
});
|
|
4774
|
-
container.bind(
|
|
4775
|
-
container.bind(SERVICE_IDENTIFIER.TaroTextFactory).toFactory((context) => {
|
|
4160
|
+
container.bind(SID_TARO_TEXT_FACTORY).toFactory((context) => {
|
|
4776
4161
|
return (text) => {
|
|
4777
|
-
const textNode = context.container.get(
|
|
4162
|
+
const textNode = context.container.get(SID_TARO_TEXT);
|
|
4778
4163
|
textNode._value = text;
|
|
4779
4164
|
return textNode;
|
|
4780
4165
|
};
|
|
4781
4166
|
});
|
|
4782
|
-
container.bind(SERVICE_IDENTIFIER.TaroNodeImpl).to(TaroNodeImpl).inSingletonScope();
|
|
4783
|
-
container.bind(SERVICE_IDENTIFIER.TaroElementImpl).to(TaroElementImpl).inSingletonScope();
|
|
4784
4167
|
}
|
|
4785
|
-
|
|
4168
|
+
bind(SID_HOOKS, Hooks, { single: true });
|
|
4786
4169
|
container.load(DefaultHooksContainer);
|
|
4787
|
-
processPluginHooks(container);
|
|
4788
|
-
|
|
4789
|
-
let hooks;
|
|
4790
|
-
let getElement;
|
|
4791
|
-
let document$1;
|
|
4792
|
-
if (process.env.TARO_ENV !== 'h5') {
|
|
4793
|
-
hooks = container.get(SERVICE_IDENTIFIER.Hooks);
|
|
4794
|
-
getElement = container.get(SERVICE_IDENTIFIER.TaroElementFactory);
|
|
4795
|
-
document$1 = getElement(ElementNames.Document)();
|
|
4796
|
-
}
|
|
4797
|
-
// Taro 事件对象。以 Web 标准的事件对象为基础,加入小程序事件对象中携带的部分信息,并模拟实现事件冒泡。
|
|
4798
|
-
class TaroEvent {
|
|
4799
|
-
constructor(type, opts, event) {
|
|
4800
|
-
this._stop = false;
|
|
4801
|
-
this._end = false;
|
|
4802
|
-
this.defaultPrevented = false;
|
|
4803
|
-
// timestamp can either be hi-res ( relative to page load) or low-res (relative to UNIX epoch)
|
|
4804
|
-
// here use hi-res timestamp
|
|
4805
|
-
this.timeStamp = Date.now();
|
|
4806
|
-
this.type = type.toLowerCase();
|
|
4807
|
-
this.mpEvent = event;
|
|
4808
|
-
this.bubbles = Boolean(opts && opts.bubbles);
|
|
4809
|
-
this.cancelable = Boolean(opts && opts.cancelable);
|
|
4810
|
-
}
|
|
4811
|
-
stopPropagation() {
|
|
4812
|
-
this._stop = true;
|
|
4813
|
-
}
|
|
4814
|
-
stopImmediatePropagation() {
|
|
4815
|
-
this._end = this._stop = true;
|
|
4816
|
-
}
|
|
4817
|
-
preventDefault() {
|
|
4818
|
-
this.defaultPrevented = true;
|
|
4819
|
-
}
|
|
4820
|
-
get target() {
|
|
4821
|
-
var _a, _b, _c;
|
|
4822
|
-
const element = document$1.getElementById((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.target.id);
|
|
4823
|
-
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 });
|
|
4824
|
-
}
|
|
4825
|
-
get currentTarget() {
|
|
4826
|
-
var _a, _b, _c;
|
|
4827
|
-
const element = document$1.getElementById((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.currentTarget.id);
|
|
4828
|
-
if (element === null) {
|
|
4829
|
-
return this.target;
|
|
4830
|
-
}
|
|
4831
|
-
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 });
|
|
4832
|
-
}
|
|
4833
|
-
}
|
|
4834
|
-
function createEvent(event, node) {
|
|
4835
|
-
if (typeof event === 'string') {
|
|
4836
|
-
// For Vue3 using document.createEvent
|
|
4837
|
-
return new TaroEvent(event, { bubbles: true, cancelable: true });
|
|
4838
|
-
}
|
|
4839
|
-
const domEv = new TaroEvent(event.type, { bubbles: true, cancelable: true }, event);
|
|
4840
|
-
for (const key in event) {
|
|
4841
|
-
if (key === CURRENT_TARGET || key === TARGET || key === TYPE || key === TIME_STAMP) {
|
|
4842
|
-
continue;
|
|
4843
|
-
}
|
|
4844
|
-
else {
|
|
4845
|
-
domEv[key] = event[key];
|
|
4846
|
-
}
|
|
4847
|
-
}
|
|
4848
|
-
if (domEv.type === CONFIRM && (node === null || node === void 0 ? void 0 : node.nodeName) === INPUT) {
|
|
4849
|
-
// eslint-disable-next-line dot-notation
|
|
4850
|
-
domEv[KEY_CODE] = 13;
|
|
4851
|
-
}
|
|
4852
|
-
return domEv;
|
|
4853
|
-
}
|
|
4854
|
-
const eventsBatch = {};
|
|
4855
|
-
// 小程序的事件代理回调函数
|
|
4856
|
-
function eventHandler(event) {
|
|
4857
|
-
var _a;
|
|
4858
|
-
(_a = hooks.modifyMpEvent) === null || _a === void 0 ? void 0 : _a.call(hooks, event);
|
|
4859
|
-
if (event.currentTarget == null) {
|
|
4860
|
-
event.currentTarget = event.target;
|
|
4861
|
-
}
|
|
4862
|
-
const node = document$1.getElementById(event.currentTarget.id);
|
|
4863
|
-
if (node) {
|
|
4864
|
-
const dispatch = () => {
|
|
4865
|
-
var _a;
|
|
4866
|
-
const e = createEvent(event, node);
|
|
4867
|
-
(_a = hooks.modifyTaroEvent) === null || _a === void 0 ? void 0 : _a.call(hooks, e, node);
|
|
4868
|
-
node.dispatchEvent(e);
|
|
4869
|
-
};
|
|
4870
|
-
if (typeof hooks.batchedEventUpdates === 'function') {
|
|
4871
|
-
const type = event.type;
|
|
4872
|
-
if (!hooks.isBubbleEvents(type) ||
|
|
4873
|
-
!isParentBinded(node, type) ||
|
|
4874
|
-
(type === TOUCHMOVE && !!node.props.catchMove)) {
|
|
4875
|
-
// 最上层组件统一 batchUpdate
|
|
4876
|
-
hooks.batchedEventUpdates(() => {
|
|
4877
|
-
if (eventsBatch[type]) {
|
|
4878
|
-
eventsBatch[type].forEach(fn => fn());
|
|
4879
|
-
delete eventsBatch[type];
|
|
4880
|
-
}
|
|
4881
|
-
dispatch();
|
|
4882
|
-
});
|
|
4883
|
-
}
|
|
4884
|
-
else {
|
|
4885
|
-
// 如果上层组件也有绑定同类型的组件,委托给上层组件调用事件回调
|
|
4886
|
-
(eventsBatch[type] || (eventsBatch[type] = [])).push(dispatch);
|
|
4887
|
-
}
|
|
4888
|
-
}
|
|
4889
|
-
else {
|
|
4890
|
-
dispatch();
|
|
4891
|
-
}
|
|
4892
|
-
}
|
|
4893
|
-
}
|
|
4894
|
-
|
|
4895
|
-
const isBrowser = typeof document !== 'undefined' && !!document.scripts;
|
|
4896
|
-
const doc = isBrowser ? document : EMPTY_OBJ;
|
|
4897
|
-
const win = isBrowser ? window : EMPTY_OBJ;
|
|
4170
|
+
processPluginHooks(container);
|
|
4171
|
+
store.container = container;
|
|
4898
4172
|
|
|
4899
4173
|
function createDocument() {
|
|
4900
4174
|
/**
|
|
@@ -4929,15 +4203,18 @@ function createDocument() {
|
|
|
4929
4203
|
doc.createEvent = createEvent;
|
|
4930
4204
|
return doc;
|
|
4931
4205
|
}
|
|
4932
|
-
const document$
|
|
4206
|
+
const document$1 = process.env.TARO_ENV === 'h5'
|
|
4207
|
+
? doc
|
|
4208
|
+
: createDocument();
|
|
4933
4209
|
|
|
4934
4210
|
const machine = 'Macintosh';
|
|
4935
4211
|
const arch = 'Intel Mac OS X 10_14_5';
|
|
4936
4212
|
const engine = 'AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36';
|
|
4937
|
-
const
|
|
4213
|
+
const msg = '(' + machine + '; ' + arch + ') ' + engine;
|
|
4214
|
+
const navigator = process.env.TARO_ENV === 'h5' ? win.navigator : {
|
|
4938
4215
|
appCodeName: 'Mozilla',
|
|
4939
4216
|
appName: 'Netscape',
|
|
4940
|
-
appVersion: '5.0
|
|
4217
|
+
appVersion: '5.0 ' + msg,
|
|
4941
4218
|
cookieEnabled: true,
|
|
4942
4219
|
mimeTypes: [],
|
|
4943
4220
|
onLine: true,
|
|
@@ -4945,7 +4222,7 @@ const navigator = isBrowser ? win.navigator : {
|
|
|
4945
4222
|
plugins: [],
|
|
4946
4223
|
product: 'Taro',
|
|
4947
4224
|
productSub: '20030107',
|
|
4948
|
-
userAgent: 'Mozilla/5.0
|
|
4225
|
+
userAgent: 'Mozilla/5.0 ' + msg,
|
|
4949
4226
|
vendor: 'Joyent',
|
|
4950
4227
|
vendorSub: ''
|
|
4951
4228
|
};
|
|
@@ -4991,11 +4268,11 @@ function getComputedStyle(element) {
|
|
|
4991
4268
|
return element.style;
|
|
4992
4269
|
}
|
|
4993
4270
|
|
|
4994
|
-
const window$1 =
|
|
4271
|
+
const window$1 = process.env.TARO_ENV === 'h5' ? win : {
|
|
4995
4272
|
navigator,
|
|
4996
|
-
document: document$
|
|
4273
|
+
document: document$1
|
|
4997
4274
|
};
|
|
4998
|
-
if (
|
|
4275
|
+
if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
4999
4276
|
const globalProperties = [
|
|
5000
4277
|
...Object.getOwnPropertyNames(global || win),
|
|
5001
4278
|
...Object.getOwnPropertySymbols(global || win)
|
|
@@ -5007,14 +4284,11 @@ if (!isBrowser) {
|
|
|
5007
4284
|
window$1[property] = global[property];
|
|
5008
4285
|
}
|
|
5009
4286
|
});
|
|
5010
|
-
document$2.defaultView = window$1;
|
|
5011
|
-
}
|
|
5012
|
-
if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
5013
4287
|
window$1.requestAnimationFrame = raf;
|
|
5014
4288
|
window$1.cancelAnimationFrame = caf;
|
|
5015
4289
|
window$1.getComputedStyle = getComputedStyle;
|
|
5016
|
-
window$1.addEventListener =
|
|
5017
|
-
window$1.removeEventListener =
|
|
4290
|
+
window$1.addEventListener = noop;
|
|
4291
|
+
window$1.removeEventListener = noop;
|
|
5018
4292
|
if (!(DATE in window$1)) {
|
|
5019
4293
|
window$1.Date = Date;
|
|
5020
4294
|
}
|
|
@@ -5024,6 +4298,7 @@ if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
|
5024
4298
|
window$1.clearTimeout = function (seed) {
|
|
5025
4299
|
clearTimeout(seed);
|
|
5026
4300
|
};
|
|
4301
|
+
document$1.defaultView = window$1;
|
|
5027
4302
|
}
|
|
5028
4303
|
|
|
5029
4304
|
const Current = {
|
|
@@ -5035,12 +4310,8 @@ const getCurrentInstance = () => Current;
|
|
|
5035
4310
|
|
|
5036
4311
|
class Events {
|
|
5037
4312
|
constructor(opts) {
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
}
|
|
5041
|
-
else {
|
|
5042
|
-
this.callbacks = {};
|
|
5043
|
-
}
|
|
4313
|
+
var _a;
|
|
4314
|
+
this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
|
|
5044
4315
|
}
|
|
5045
4316
|
on(eventName, callback, context) {
|
|
5046
4317
|
let event, node, tail, list;
|
|
@@ -5117,17 +4388,15 @@ class Events {
|
|
|
5117
4388
|
}
|
|
5118
4389
|
}
|
|
5119
4390
|
Events.eventSplitter = /\s+/;
|
|
5120
|
-
const
|
|
5121
|
-
|
|
5122
|
-
container.bind(SERVICE_IDENTIFIER.eventCenter).toConstantValue(eventCenter);
|
|
4391
|
+
const eventCenter = getHooks().getEventCenter(Events);
|
|
4392
|
+
container.bind(SID_EVENT_CENTER).toConstantValue(eventCenter);
|
|
5123
4393
|
|
|
5124
4394
|
/* eslint-disable dot-notation */
|
|
5125
4395
|
const instances = new Map();
|
|
5126
4396
|
const pageId = incrementId();
|
|
5127
|
-
const hooks$2 = container.get(SERVICE_IDENTIFIER.Hooks);
|
|
5128
4397
|
function injectPageInstance(inst, id) {
|
|
5129
|
-
var _a;
|
|
5130
|
-
(_a =
|
|
4398
|
+
var _a, _b;
|
|
4399
|
+
(_b = (_a = getHooks()).mergePageInstance) === null || _b === void 0 ? void 0 : _b.call(_a, instances.get(id), inst);
|
|
5131
4400
|
instances.set(id, inst);
|
|
5132
4401
|
}
|
|
5133
4402
|
function getPageInstance(id) {
|
|
@@ -5144,12 +4413,12 @@ function safeExecute(path, lifecycle, ...args) {
|
|
|
5144
4413
|
if (instance == null) {
|
|
5145
4414
|
return;
|
|
5146
4415
|
}
|
|
5147
|
-
const func =
|
|
5148
|
-
if (isArray
|
|
4416
|
+
const func = getHooks().getLifecycle(instance, lifecycle);
|
|
4417
|
+
if (isArray(func)) {
|
|
5149
4418
|
const res = func.map(fn => fn.apply(instance, args));
|
|
5150
4419
|
return res[0];
|
|
5151
4420
|
}
|
|
5152
|
-
if (!isFunction
|
|
4421
|
+
if (!isFunction(func)) {
|
|
5153
4422
|
return;
|
|
5154
4423
|
}
|
|
5155
4424
|
return func.apply(instance, args);
|
|
@@ -5165,31 +4434,43 @@ function stringify(obj) {
|
|
|
5165
4434
|
}
|
|
5166
4435
|
function getPath(id, options) {
|
|
5167
4436
|
let path = id;
|
|
5168
|
-
if (
|
|
4437
|
+
if (process.env.TARO_ENV !== 'h5') {
|
|
5169
4438
|
path = id + stringify(options);
|
|
5170
4439
|
}
|
|
5171
4440
|
return path;
|
|
5172
4441
|
}
|
|
5173
4442
|
function getOnReadyEventKey(path) {
|
|
5174
|
-
return path + '.' +
|
|
4443
|
+
return path + '.' + ON_READY;
|
|
5175
4444
|
}
|
|
5176
4445
|
function getOnShowEventKey(path) {
|
|
5177
|
-
return path + '.' +
|
|
4446
|
+
return path + '.' + ON_SHOW;
|
|
5178
4447
|
}
|
|
5179
4448
|
function getOnHideEventKey(path) {
|
|
5180
|
-
return path + '.' +
|
|
4449
|
+
return path + '.' + ON_HIDE;
|
|
5181
4450
|
}
|
|
5182
4451
|
function createPageConfig(component, pageName, data, pageConfig) {
|
|
5183
|
-
var _a, _b;
|
|
5184
|
-
const id = pageName !== null && pageName !== void 0 ? pageName : `taro_page_${pageId()}`;
|
|
4452
|
+
var _a, _b, _c;
|
|
5185
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;
|
|
5186
4457
|
let pageElement = null;
|
|
5187
4458
|
let unmounting = false;
|
|
5188
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
|
+
}
|
|
5189
4470
|
let loadResolver;
|
|
5190
4471
|
let hasLoaded;
|
|
5191
4472
|
const config = {
|
|
5192
|
-
|
|
4473
|
+
[ONLOAD](options = {}, cb) {
|
|
5193
4474
|
hasLoaded = new Promise(resolve => { loadResolver = resolve; });
|
|
5194
4475
|
perf.start(PAGE_INIT);
|
|
5195
4476
|
Current.page = this;
|
|
@@ -5197,30 +4478,24 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
5197
4478
|
options.$taroTimestamp = Date.now();
|
|
5198
4479
|
// this.$taroPath 是页面唯一标识,不可变,因此页面参数 options 也不可变
|
|
5199
4480
|
this.$taroPath = getPath(id, options);
|
|
4481
|
+
const $taroPath = this.$taroPath;
|
|
5200
4482
|
// this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
|
|
5201
4483
|
if (this.$taroParams == null) {
|
|
5202
4484
|
this.$taroParams = Object.assign({}, options);
|
|
5203
4485
|
}
|
|
5204
|
-
|
|
5205
|
-
Current.router = {
|
|
5206
|
-
params: this.$taroParams,
|
|
5207
|
-
path: addLeadingSlash(router),
|
|
5208
|
-
onReady: getOnReadyEventKey(id),
|
|
5209
|
-
onShow: getOnShowEventKey(id),
|
|
5210
|
-
onHide: getOnHideEventKey(id)
|
|
5211
|
-
};
|
|
4486
|
+
setCurrentRouter(this);
|
|
5212
4487
|
const mount = () => {
|
|
5213
|
-
Current.app.mount(component,
|
|
5214
|
-
pageElement = document$
|
|
4488
|
+
Current.app.mount(component, $taroPath, () => {
|
|
4489
|
+
pageElement = document$1.getElementById($taroPath);
|
|
5215
4490
|
ensure(pageElement !== null, '没有找到页面实例。');
|
|
5216
|
-
safeExecute(
|
|
4491
|
+
safeExecute($taroPath, ON_LOAD, this.$taroParams);
|
|
5217
4492
|
loadResolver();
|
|
5218
|
-
if (
|
|
4493
|
+
if (process.env.TARO_ENV !== 'h5') {
|
|
5219
4494
|
pageElement.ctx = this;
|
|
5220
4495
|
pageElement.performUpdate(true, cb);
|
|
5221
4496
|
}
|
|
5222
4497
|
else {
|
|
5223
|
-
isFunction
|
|
4498
|
+
isFunction(cb) && cb();
|
|
5224
4499
|
}
|
|
5225
4500
|
});
|
|
5226
4501
|
};
|
|
@@ -5231,20 +4506,15 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
5231
4506
|
mount();
|
|
5232
4507
|
}
|
|
5233
4508
|
},
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
eventCenter.trigger(getOnReadyEventKey(id));
|
|
5237
|
-
});
|
|
5238
|
-
safeExecute(this.$taroPath, 'onReady');
|
|
5239
|
-
this.onReady.called = true;
|
|
5240
|
-
},
|
|
5241
|
-
onUnload() {
|
|
4509
|
+
[ONUNLOAD]() {
|
|
4510
|
+
const $taroPath = this.$taroPath;
|
|
5242
4511
|
unmounting = true;
|
|
5243
|
-
Current.app.unmount(
|
|
4512
|
+
Current.app.unmount($taroPath, () => {
|
|
5244
4513
|
unmounting = false;
|
|
5245
|
-
instances.delete(
|
|
4514
|
+
instances.delete($taroPath);
|
|
5246
4515
|
if (pageElement) {
|
|
5247
4516
|
pageElement.ctx = null;
|
|
4517
|
+
pageElement = null;
|
|
5248
4518
|
}
|
|
5249
4519
|
if (prepareMountList.length) {
|
|
5250
4520
|
prepareMountList.forEach(fn => fn());
|
|
@@ -5252,72 +4522,52 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
5252
4522
|
}
|
|
5253
4523
|
});
|
|
5254
4524
|
},
|
|
5255
|
-
|
|
4525
|
+
[ONREADY]() {
|
|
4526
|
+
// 触发生命周期
|
|
4527
|
+
safeExecute(this.$taroPath, ON_READY);
|
|
4528
|
+
// 通过事件触发子组件的生命周期
|
|
4529
|
+
raf(() => eventCenter.trigger(getOnReadyEventKey(id)));
|
|
4530
|
+
this.onReady.called = true;
|
|
4531
|
+
},
|
|
4532
|
+
[ONSHOW]() {
|
|
5256
4533
|
hasLoaded.then(() => {
|
|
4534
|
+
// 设置 Current 的 page 和 router
|
|
5257
4535
|
Current.page = this;
|
|
5258
|
-
this
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
onReady: getOnReadyEventKey(id),
|
|
5264
|
-
onShow: getOnShowEventKey(id),
|
|
5265
|
-
onHide: getOnHideEventKey(id)
|
|
5266
|
-
};
|
|
5267
|
-
raf(() => {
|
|
5268
|
-
eventCenter.trigger(getOnShowEventKey(id));
|
|
5269
|
-
});
|
|
5270
|
-
safeExecute(this.$taroPath, 'onShow');
|
|
4536
|
+
setCurrentRouter(this);
|
|
4537
|
+
// 触发生命周期
|
|
4538
|
+
safeExecute(this.$taroPath, ON_SHOW);
|
|
4539
|
+
// 通过事件触发子组件的生命周期
|
|
4540
|
+
raf(() => eventCenter.trigger(getOnShowEventKey(id)));
|
|
5271
4541
|
});
|
|
5272
4542
|
},
|
|
5273
|
-
|
|
5274
|
-
Current
|
|
5275
|
-
Current.
|
|
5276
|
-
|
|
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
|
+
// 通过事件触发子组件的生命周期
|
|
5277
4552
|
eventCenter.trigger(getOnHideEventKey(id));
|
|
5278
|
-
},
|
|
5279
|
-
onPullDownRefresh() {
|
|
5280
|
-
return safeExecute(this.$taroPath, 'onPullDownRefresh');
|
|
5281
|
-
},
|
|
5282
|
-
onReachBottom() {
|
|
5283
|
-
return safeExecute(this.$taroPath, 'onReachBottom');
|
|
5284
|
-
},
|
|
5285
|
-
onPageScroll(options) {
|
|
5286
|
-
return safeExecute(this.$taroPath, 'onPageScroll', options);
|
|
5287
|
-
},
|
|
5288
|
-
onResize(options) {
|
|
5289
|
-
return safeExecute(this.$taroPath, 'onResize', options);
|
|
5290
|
-
},
|
|
5291
|
-
onTabItemTap(options) {
|
|
5292
|
-
return safeExecute(this.$taroPath, 'onTabItemTap', options);
|
|
5293
|
-
},
|
|
5294
|
-
onTitleClick() {
|
|
5295
|
-
return safeExecute(this.$taroPath, 'onTitleClick');
|
|
5296
|
-
},
|
|
5297
|
-
onOptionMenuClick() {
|
|
5298
|
-
return safeExecute(this.$taroPath, 'onOptionMenuClick');
|
|
5299
|
-
},
|
|
5300
|
-
onPopMenuClick() {
|
|
5301
|
-
return safeExecute(this.$taroPath, 'onPopMenuClick');
|
|
5302
|
-
},
|
|
5303
|
-
onPullIntercept() {
|
|
5304
|
-
return safeExecute(this.$taroPath, 'onPullIntercept');
|
|
5305
|
-
},
|
|
5306
|
-
onAddToFavorites() {
|
|
5307
|
-
return safeExecute(this.$taroPath, 'onAddToFavorites');
|
|
5308
4553
|
}
|
|
5309
4554
|
};
|
|
4555
|
+
LIFECYCLES.forEach((lifecycle) => {
|
|
4556
|
+
config[lifecycle] = function () {
|
|
4557
|
+
return safeExecute(this.$taroPath, lifecycle, ...arguments);
|
|
4558
|
+
};
|
|
4559
|
+
});
|
|
5310
4560
|
// onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。
|
|
5311
4561
|
if (component.onShareAppMessage ||
|
|
5312
4562
|
((_a = component.prototype) === null || _a === void 0 ? void 0 : _a.onShareAppMessage) ||
|
|
5313
4563
|
component.enableShareAppMessage) {
|
|
5314
4564
|
config.onShareAppMessage = function (options) {
|
|
5315
4565
|
const target = options === null || options === void 0 ? void 0 : options.target;
|
|
5316
|
-
if (target
|
|
4566
|
+
if (target) {
|
|
5317
4567
|
const id = target.id;
|
|
5318
|
-
const element = document$
|
|
5319
|
-
if (element
|
|
5320
|
-
|
|
4568
|
+
const element = document$1.getElementById(id);
|
|
4569
|
+
if (element) {
|
|
4570
|
+
target.dataset = element.dataset;
|
|
5321
4571
|
}
|
|
5322
4572
|
}
|
|
5323
4573
|
return safeExecute(this.$taroPath, 'onShareAppMessage', options);
|
|
@@ -5334,13 +4584,13 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
5334
4584
|
if (!isUndefined(data)) {
|
|
5335
4585
|
config.data = data;
|
|
5336
4586
|
}
|
|
5337
|
-
if (
|
|
4587
|
+
if (process.env.TARO_ENV === 'h5') {
|
|
5338
4588
|
config.path = id;
|
|
5339
4589
|
}
|
|
4590
|
+
(_c = hooks.modifyPageObject) === null || _c === void 0 ? void 0 : _c.call(hooks, config);
|
|
5340
4591
|
return config;
|
|
5341
4592
|
}
|
|
5342
4593
|
function createComponentConfig(component, componentName, data) {
|
|
5343
|
-
var _a, _b, _c;
|
|
5344
4594
|
const id = componentName !== null && componentName !== void 0 ? componentName : `taro_component_${pageId()}`;
|
|
5345
4595
|
let componentElement = null;
|
|
5346
4596
|
const config = {
|
|
@@ -5349,10 +4599,10 @@ function createComponentConfig(component, componentName, data) {
|
|
|
5349
4599
|
perf.start(PAGE_INIT);
|
|
5350
4600
|
const path = getPath(id, { id: ((_a = this.getPageId) === null || _a === void 0 ? void 0 : _a.call(this)) || pageId() });
|
|
5351
4601
|
Current.app.mount(component, path, () => {
|
|
5352
|
-
componentElement = document$
|
|
4602
|
+
componentElement = document$1.getElementById(path);
|
|
5353
4603
|
ensure(componentElement !== null, '没有找到组件实例。');
|
|
5354
|
-
safeExecute(path,
|
|
5355
|
-
if (
|
|
4604
|
+
safeExecute(path, ON_LOAD);
|
|
4605
|
+
if (process.env.TARO_ENV !== 'h5') {
|
|
5356
4606
|
componentElement.ctx = this;
|
|
5357
4607
|
componentElement.performUpdate(true);
|
|
5358
4608
|
}
|
|
@@ -5374,9 +4624,10 @@ function createComponentConfig(component, componentName, data) {
|
|
|
5374
4624
|
if (!isUndefined(data)) {
|
|
5375
4625
|
config.data = data;
|
|
5376
4626
|
}
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
4627
|
+
[OPTIONS, EXTERNAL_CLASSES, BEHAVIORS].forEach(key => {
|
|
4628
|
+
var _a;
|
|
4629
|
+
config[key] = (_a = component[key]) !== null && _a !== void 0 ? _a : EMPTY_OBJ;
|
|
4630
|
+
});
|
|
5380
4631
|
return config;
|
|
5381
4632
|
}
|
|
5382
4633
|
function createRecursiveComponentConfig(componentName) {
|
|
@@ -5385,7 +4636,7 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
5385
4636
|
i: {
|
|
5386
4637
|
type: Object,
|
|
5387
4638
|
value: {
|
|
5388
|
-
["nn" /* NodeName */]:
|
|
4639
|
+
["nn" /* NodeName */]: VIEW
|
|
5389
4640
|
}
|
|
5390
4641
|
},
|
|
5391
4642
|
l: {
|
|
@@ -5395,806 +4646,14 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
5395
4646
|
},
|
|
5396
4647
|
options: {
|
|
5397
4648
|
addGlobalClass: true,
|
|
5398
|
-
virtualHost: componentName !==
|
|
5399
|
-
},
|
|
5400
|
-
methods: {
|
|
5401
|
-
eh: eventHandler
|
|
5402
|
-
}
|
|
5403
|
-
};
|
|
5404
|
-
}
|
|
5405
|
-
|
|
5406
|
-
const hooks$3 = container.get(SERVICE_IDENTIFIER.Hooks);
|
|
5407
|
-
function isClassComponent(R, component) {
|
|
5408
|
-
var _a;
|
|
5409
|
-
return isFunction$1(component.render) ||
|
|
5410
|
-
!!((_a = component.prototype) === null || _a === void 0 ? void 0 : _a.isReactComponent) ||
|
|
5411
|
-
component.prototype instanceof R.Component; // compat for some others react-like library
|
|
5412
|
-
}
|
|
5413
|
-
// 初始值设置为 any 主要是为了过 TS 的校验
|
|
5414
|
-
let R = EMPTY_OBJ;
|
|
5415
|
-
let PageContext = EMPTY_OBJ;
|
|
5416
|
-
function connectReactPage(R, id) {
|
|
5417
|
-
const h = R.createElement;
|
|
5418
|
-
return (component) => {
|
|
5419
|
-
// eslint-disable-next-line dot-notation
|
|
5420
|
-
const isReactComponent = isClassComponent(R, component);
|
|
5421
|
-
const inject = (node) => node && injectPageInstance(node, id);
|
|
5422
|
-
const refs = isReactComponent ? { ref: inject } : {
|
|
5423
|
-
forwardedRef: inject,
|
|
5424
|
-
// 兼容 react-redux 7.20.1+
|
|
5425
|
-
reactReduxForwardedRef: inject
|
|
5426
|
-
};
|
|
5427
|
-
if (PageContext === EMPTY_OBJ) {
|
|
5428
|
-
PageContext = R.createContext('');
|
|
5429
|
-
}
|
|
5430
|
-
return class Page extends R.Component {
|
|
5431
|
-
constructor() {
|
|
5432
|
-
super(...arguments);
|
|
5433
|
-
this.state = {
|
|
5434
|
-
hasError: false
|
|
5435
|
-
};
|
|
5436
|
-
}
|
|
5437
|
-
static getDerivedStateFromError(error) {
|
|
5438
|
-
process.env.NODE_ENV !== 'production' && console.warn(error);
|
|
5439
|
-
return { hasError: true };
|
|
5440
|
-
}
|
|
5441
|
-
// React 16 uncaught error 会导致整个应用 crash,
|
|
5442
|
-
// 目前把错误缩小到页面
|
|
5443
|
-
componentDidCatch(error, info) {
|
|
5444
|
-
process.env.NODE_ENV !== 'production' && console.warn(error);
|
|
5445
|
-
process.env.NODE_ENV !== 'production' && console.error(info.componentStack);
|
|
5446
|
-
}
|
|
5447
|
-
render() {
|
|
5448
|
-
const children = this.state.hasError
|
|
5449
|
-
? []
|
|
5450
|
-
: h(PageContext.Provider, { value: id }, h(component, Object.assign(Object.assign({}, this.props), refs)));
|
|
5451
|
-
if (isBrowser) {
|
|
5452
|
-
return h('div', { id, className: 'taro_page' }, children);
|
|
5453
|
-
}
|
|
5454
|
-
return h('root', { id }, children);
|
|
5455
|
-
}
|
|
5456
|
-
};
|
|
5457
|
-
};
|
|
5458
|
-
}
|
|
5459
|
-
let ReactDOM;
|
|
5460
|
-
function setReconciler() {
|
|
5461
|
-
const getLifecycle = function (instance, lifecycle) {
|
|
5462
|
-
lifecycle = lifecycle.replace(/^on(Show|Hide)$/, 'componentDid$1');
|
|
5463
|
-
return instance[lifecycle];
|
|
5464
|
-
};
|
|
5465
|
-
const modifyMpEvent = function (event) {
|
|
5466
|
-
event.type = event.type.replace(/-/g, '');
|
|
5467
|
-
};
|
|
5468
|
-
const batchedEventUpdates = function (cb) {
|
|
5469
|
-
ReactDOM.unstable_batchedUpdates(cb);
|
|
5470
|
-
};
|
|
5471
|
-
const mergePageInstance = function (prev, next) {
|
|
5472
|
-
if (!prev || !next)
|
|
5473
|
-
return;
|
|
5474
|
-
// 子组件使用 lifecycle hooks 注册了生命周期后,会存在 prev,里面是注册的生命周期回调。
|
|
5475
|
-
// prev 使用 Object.create(null) 创建,H5 的 fast-refresh 可能也会导致存在 prev,要排除这些意外产生的 prev
|
|
5476
|
-
if ('constructor' in prev)
|
|
5477
|
-
return;
|
|
5478
|
-
Object.keys(prev).forEach(item => {
|
|
5479
|
-
if (isFunction$1(next[item])) {
|
|
5480
|
-
next[item] = [next[item], ...prev[item]];
|
|
5481
|
-
}
|
|
5482
|
-
else {
|
|
5483
|
-
next[item] = [...(next[item] || []), ...prev[item]];
|
|
5484
|
-
}
|
|
5485
|
-
});
|
|
5486
|
-
};
|
|
5487
|
-
hooks$3.getLifecycle = getLifecycle;
|
|
5488
|
-
hooks$3.modifyMpEvent = modifyMpEvent;
|
|
5489
|
-
hooks$3.batchedEventUpdates = batchedEventUpdates;
|
|
5490
|
-
hooks$3.mergePageInstance = mergePageInstance;
|
|
5491
|
-
if (process.env.TARO_ENV === 'h5') {
|
|
5492
|
-
hooks$3.createPullDownComponent = (el, _, R, customWrapper) => {
|
|
5493
|
-
const isReactComponent = isClassComponent(R, el);
|
|
5494
|
-
return R.forwardRef((props, ref) => {
|
|
5495
|
-
const newProps = Object.assign({}, props);
|
|
5496
|
-
const refs = isReactComponent ? { ref: ref } : {
|
|
5497
|
-
forwardedRef: ref,
|
|
5498
|
-
// 兼容 react-redux 7.20.1+
|
|
5499
|
-
reactReduxForwardedRef: ref
|
|
5500
|
-
};
|
|
5501
|
-
return R.createElement(customWrapper || 'taro-pull-to-refresh', null, R.createElement(el, Object.assign(Object.assign({}, newProps), refs)));
|
|
5502
|
-
});
|
|
5503
|
-
};
|
|
5504
|
-
hooks$3.getDOMNode = (inst) => {
|
|
5505
|
-
return ReactDOM.findDOMNode(inst);
|
|
5506
|
-
};
|
|
5507
|
-
}
|
|
5508
|
-
}
|
|
5509
|
-
const pageKeyId = incrementId();
|
|
5510
|
-
function createReactApp(App, react, reactdom, config) {
|
|
5511
|
-
R = react;
|
|
5512
|
-
ReactDOM = reactdom;
|
|
5513
|
-
ensure(!!ReactDOM, '构建 React/Nerv 项目请把 process.env.FRAMEWORK 设置为 \'react\'/\'nerv\' ');
|
|
5514
|
-
const ref = R.createRef();
|
|
5515
|
-
const isReactComponent = isClassComponent(R, App);
|
|
5516
|
-
setReconciler();
|
|
5517
|
-
class AppWrapper extends R.Component {
|
|
5518
|
-
constructor() {
|
|
5519
|
-
super(...arguments);
|
|
5520
|
-
// run createElement() inside the render function to make sure that owner is right
|
|
5521
|
-
this.pages = [];
|
|
5522
|
-
this.elements = [];
|
|
5523
|
-
}
|
|
5524
|
-
mount(component, id, cb) {
|
|
5525
|
-
const key = id + pageKeyId();
|
|
5526
|
-
const page = () => R.createElement(component, { key, tid: id });
|
|
5527
|
-
this.pages.push(page);
|
|
5528
|
-
this.forceUpdate(cb);
|
|
5529
|
-
}
|
|
5530
|
-
unmount(id, cb) {
|
|
5531
|
-
for (let i = 0; i < this.elements.length; i++) {
|
|
5532
|
-
const element = this.elements[i];
|
|
5533
|
-
if (element.props.tid === id) {
|
|
5534
|
-
this.elements.splice(i, 1);
|
|
5535
|
-
break;
|
|
5536
|
-
}
|
|
5537
|
-
}
|
|
5538
|
-
this.forceUpdate(cb);
|
|
5539
|
-
}
|
|
5540
|
-
render() {
|
|
5541
|
-
while (this.pages.length > 0) {
|
|
5542
|
-
const page = this.pages.pop();
|
|
5543
|
-
this.elements.push(page());
|
|
5544
|
-
}
|
|
5545
|
-
let props = null;
|
|
5546
|
-
if (isReactComponent) {
|
|
5547
|
-
props = { ref };
|
|
5548
|
-
}
|
|
5549
|
-
return R.createElement(App, props, isBrowser ? R.createElement('div', null, this.elements.slice()) : this.elements.slice());
|
|
5550
|
-
}
|
|
5551
|
-
}
|
|
5552
|
-
let wrapper;
|
|
5553
|
-
if (!isBrowser) {
|
|
5554
|
-
// eslint-disable-next-line react/no-render-return-value
|
|
5555
|
-
wrapper = ReactDOM.render(R.createElement(AppWrapper), document$2.getElementById('app'));
|
|
5556
|
-
}
|
|
5557
|
-
const app = Object.create({
|
|
5558
|
-
render(cb) {
|
|
5559
|
-
wrapper.forceUpdate(cb);
|
|
5560
|
-
},
|
|
5561
|
-
mount(component, id, cb) {
|
|
5562
|
-
const page = connectReactPage(R, id)(component);
|
|
5563
|
-
wrapper.mount(page, id, cb);
|
|
5564
|
-
},
|
|
5565
|
-
unmount(id, cb) {
|
|
5566
|
-
wrapper.unmount(id, cb);
|
|
5567
|
-
}
|
|
5568
|
-
}, {
|
|
5569
|
-
config: {
|
|
5570
|
-
writable: true,
|
|
5571
|
-
enumerable: true,
|
|
5572
|
-
configurable: true,
|
|
5573
|
-
value: config
|
|
5574
|
-
},
|
|
5575
|
-
onLaunch: {
|
|
5576
|
-
enumerable: true,
|
|
5577
|
-
writable: true,
|
|
5578
|
-
value(options) {
|
|
5579
|
-
Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
|
|
5580
|
-
if (isBrowser) {
|
|
5581
|
-
// 由于 H5 路由初始化的时候会清除 app 下的 dom 元素,所以需要在路由初始化后执行 render
|
|
5582
|
-
// eslint-disable-next-line react/no-render-return-value
|
|
5583
|
-
wrapper = ReactDOM.render(R.createElement(AppWrapper), document$2.getElementById('app'));
|
|
5584
|
-
}
|
|
5585
|
-
const app = ref.current;
|
|
5586
|
-
// For taroize
|
|
5587
|
-
// 把 App Class 上挂载的额外属性同步到全局 app 对象中
|
|
5588
|
-
if (app === null || app === void 0 ? void 0 : app.taroGlobalData) {
|
|
5589
|
-
const globalData = app.taroGlobalData;
|
|
5590
|
-
const keys = Object.keys(globalData);
|
|
5591
|
-
const descriptors = Object.getOwnPropertyDescriptors(globalData);
|
|
5592
|
-
keys.forEach(key => {
|
|
5593
|
-
Object.defineProperty(this, key, {
|
|
5594
|
-
configurable: true,
|
|
5595
|
-
enumerable: true,
|
|
5596
|
-
get() {
|
|
5597
|
-
return globalData[key];
|
|
5598
|
-
},
|
|
5599
|
-
set(value) {
|
|
5600
|
-
globalData[key] = value;
|
|
5601
|
-
}
|
|
5602
|
-
});
|
|
5603
|
-
});
|
|
5604
|
-
Object.defineProperties(this, descriptors);
|
|
5605
|
-
}
|
|
5606
|
-
this.$app = app;
|
|
5607
|
-
if (app != null && isFunction$1(app.onLaunch)) {
|
|
5608
|
-
app.onLaunch(options);
|
|
5609
|
-
}
|
|
5610
|
-
}
|
|
5611
|
-
},
|
|
5612
|
-
onShow: {
|
|
5613
|
-
enumerable: true,
|
|
5614
|
-
writable: true,
|
|
5615
|
-
value(options) {
|
|
5616
|
-
const app = ref.current;
|
|
5617
|
-
Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
|
|
5618
|
-
if (app != null && isFunction$1(app.componentDidShow)) {
|
|
5619
|
-
app.componentDidShow(options);
|
|
5620
|
-
}
|
|
5621
|
-
// app useDidShow
|
|
5622
|
-
triggerAppHook('onShow');
|
|
5623
|
-
}
|
|
5624
|
-
},
|
|
5625
|
-
onHide: {
|
|
5626
|
-
enumerable: true,
|
|
5627
|
-
writable: true,
|
|
5628
|
-
value(options) {
|
|
5629
|
-
const app = ref.current;
|
|
5630
|
-
if (app != null && isFunction$1(app.componentDidHide)) {
|
|
5631
|
-
app.componentDidHide(options);
|
|
5632
|
-
}
|
|
5633
|
-
// app useDidHide
|
|
5634
|
-
triggerAppHook('onHide');
|
|
5635
|
-
}
|
|
5636
|
-
},
|
|
5637
|
-
onPageNotFound: {
|
|
5638
|
-
enumerable: true,
|
|
5639
|
-
writable: true,
|
|
5640
|
-
value(res) {
|
|
5641
|
-
const app = ref.current;
|
|
5642
|
-
if (app != null && isFunction$1(app.onPageNotFound)) {
|
|
5643
|
-
app.onPageNotFound(res);
|
|
5644
|
-
}
|
|
5645
|
-
}
|
|
5646
|
-
}
|
|
5647
|
-
});
|
|
5648
|
-
function triggerAppHook(lifecycle) {
|
|
5649
|
-
const instance = getPageInstance(HOOKS_APP_ID);
|
|
5650
|
-
if (instance) {
|
|
5651
|
-
const app = ref.current;
|
|
5652
|
-
const func = hooks$3.getLifecycle(instance, lifecycle);
|
|
5653
|
-
if (Array.isArray(func)) {
|
|
5654
|
-
func.forEach(cb => cb.apply(app));
|
|
5655
|
-
}
|
|
5656
|
-
}
|
|
5657
|
-
}
|
|
5658
|
-
Current.app = app;
|
|
5659
|
-
return Current.app;
|
|
5660
|
-
}
|
|
5661
|
-
const getNativeCompId = incrementId();
|
|
5662
|
-
function initNativeComponentEntry(R, ReactDOM) {
|
|
5663
|
-
class NativeComponentWrapper extends R.Component {
|
|
5664
|
-
constructor() {
|
|
5665
|
-
super(...arguments);
|
|
5666
|
-
this.root = R.createRef();
|
|
5667
|
-
this.ctx = this.props.getCtx();
|
|
5668
|
-
}
|
|
5669
|
-
componentDidMount() {
|
|
5670
|
-
this.ctx.component = this;
|
|
5671
|
-
const rootElement = this.root.current;
|
|
5672
|
-
rootElement.ctx = this.ctx;
|
|
5673
|
-
rootElement.performUpdate(true);
|
|
5674
|
-
}
|
|
5675
|
-
render() {
|
|
5676
|
-
return (R.createElement('root', {
|
|
5677
|
-
ref: this.root
|
|
5678
|
-
}, this.props.renderComponent(this.ctx)));
|
|
5679
|
-
}
|
|
5680
|
-
}
|
|
5681
|
-
class Entry extends R.Component {
|
|
5682
|
-
constructor() {
|
|
5683
|
-
super(...arguments);
|
|
5684
|
-
this.state = {
|
|
5685
|
-
components: []
|
|
5686
|
-
};
|
|
5687
|
-
}
|
|
5688
|
-
componentDidMount() {
|
|
5689
|
-
Current.app = this;
|
|
5690
|
-
}
|
|
5691
|
-
mount(Component, compId, getCtx) {
|
|
5692
|
-
const isReactComponent = isClassComponent(R, Component);
|
|
5693
|
-
const inject = (node) => node && injectPageInstance(node, compId);
|
|
5694
|
-
const refs = isReactComponent ? { ref: inject } : {
|
|
5695
|
-
forwardedRef: inject,
|
|
5696
|
-
reactReduxForwardedRef: inject
|
|
5697
|
-
};
|
|
5698
|
-
const item = {
|
|
5699
|
-
compId,
|
|
5700
|
-
element: R.createElement(NativeComponentWrapper, {
|
|
5701
|
-
key: compId,
|
|
5702
|
-
getCtx,
|
|
5703
|
-
renderComponent(ctx) {
|
|
5704
|
-
return R.createElement(Component, Object.assign(Object.assign({}, (ctx.data || (ctx.data = {})).props), refs));
|
|
5705
|
-
}
|
|
5706
|
-
})
|
|
5707
|
-
};
|
|
5708
|
-
this.setState({
|
|
5709
|
-
components: [...this.state.components, item]
|
|
5710
|
-
});
|
|
5711
|
-
}
|
|
5712
|
-
unmount(compId) {
|
|
5713
|
-
const components = this.state.components;
|
|
5714
|
-
const index = components.findIndex(item => item.compId === compId);
|
|
5715
|
-
const next = [...components.slice(0, index), ...components.slice(index + 1)];
|
|
5716
|
-
this.setState({
|
|
5717
|
-
components: next
|
|
5718
|
-
});
|
|
5719
|
-
}
|
|
5720
|
-
render() {
|
|
5721
|
-
const components = this.state.components;
|
|
5722
|
-
return (components.map(({ element }) => element));
|
|
5723
|
-
}
|
|
5724
|
-
}
|
|
5725
|
-
setReconciler();
|
|
5726
|
-
const app = document$2.getElementById('app');
|
|
5727
|
-
ReactDOM.render(R.createElement(Entry, {}), app);
|
|
5728
|
-
}
|
|
5729
|
-
function createNativeComponentConfig(Component, react, reactdom, componentConfig) {
|
|
5730
|
-
R = react;
|
|
5731
|
-
ReactDOM = reactdom;
|
|
5732
|
-
setReconciler();
|
|
5733
|
-
const config = {
|
|
5734
|
-
properties: {
|
|
5735
|
-
props: {
|
|
5736
|
-
type: null,
|
|
5737
|
-
value: null,
|
|
5738
|
-
observer(_newVal, oldVal) {
|
|
5739
|
-
oldVal && this.component.forceUpdate();
|
|
5740
|
-
}
|
|
5741
|
-
}
|
|
5742
|
-
},
|
|
5743
|
-
created() {
|
|
5744
|
-
if (!Current.app) {
|
|
5745
|
-
initNativeComponentEntry(R, ReactDOM);
|
|
5746
|
-
}
|
|
5747
|
-
},
|
|
5748
|
-
attached() {
|
|
5749
|
-
setCurrent();
|
|
5750
|
-
this.compId = getNativeCompId();
|
|
5751
|
-
this.config = componentConfig;
|
|
5752
|
-
Current.app.mount(Component, this.compId, () => this);
|
|
5753
|
-
},
|
|
5754
|
-
ready() {
|
|
5755
|
-
safeExecute(this.compId, 'onReady');
|
|
5756
|
-
},
|
|
5757
|
-
detached() {
|
|
5758
|
-
Current.app.unmount(this.compId);
|
|
5759
|
-
},
|
|
5760
|
-
pageLifetimes: {
|
|
5761
|
-
show() {
|
|
5762
|
-
safeExecute(this.compId, 'onShow');
|
|
5763
|
-
},
|
|
5764
|
-
hide() {
|
|
5765
|
-
safeExecute(this.compId, 'onHide');
|
|
5766
|
-
}
|
|
4649
|
+
virtualHost: componentName !== CUSTOM_WRAPPER
|
|
5767
4650
|
},
|
|
5768
4651
|
methods: {
|
|
5769
4652
|
eh: eventHandler
|
|
5770
4653
|
}
|
|
5771
4654
|
};
|
|
5772
|
-
function setCurrent() {
|
|
5773
|
-
const pages = getCurrentPages();
|
|
5774
|
-
const currentPage = pages[pages.length - 1];
|
|
5775
|
-
if (Current.page === currentPage)
|
|
5776
|
-
return;
|
|
5777
|
-
Current.page = currentPage;
|
|
5778
|
-
const route = currentPage.route || currentPage.__route__;
|
|
5779
|
-
const router = {
|
|
5780
|
-
params: currentPage.options || {},
|
|
5781
|
-
path: addLeadingSlash(route),
|
|
5782
|
-
onReady: '',
|
|
5783
|
-
onHide: '',
|
|
5784
|
-
onShow: ''
|
|
5785
|
-
};
|
|
5786
|
-
Current.router = router;
|
|
5787
|
-
if (!currentPage.options) {
|
|
5788
|
-
// 例如在微信小程序中,页面 options 的设置时机比组件 attached 慢
|
|
5789
|
-
Object.defineProperty(currentPage, 'options', {
|
|
5790
|
-
enumerable: true,
|
|
5791
|
-
configurable: true,
|
|
5792
|
-
get() {
|
|
5793
|
-
return this._optionsValue;
|
|
5794
|
-
},
|
|
5795
|
-
set(value) {
|
|
5796
|
-
router.params = value;
|
|
5797
|
-
this._optionsValue = value;
|
|
5798
|
-
}
|
|
5799
|
-
});
|
|
5800
|
-
}
|
|
5801
|
-
}
|
|
5802
|
-
return config;
|
|
5803
|
-
}
|
|
5804
|
-
|
|
5805
|
-
function connectVuePage(Vue, id) {
|
|
5806
|
-
return (component) => {
|
|
5807
|
-
const injectedPage = Vue.extend({
|
|
5808
|
-
props: {
|
|
5809
|
-
tid: String
|
|
5810
|
-
},
|
|
5811
|
-
mixins: [component, {
|
|
5812
|
-
created() {
|
|
5813
|
-
injectPageInstance(this, id);
|
|
5814
|
-
}
|
|
5815
|
-
}]
|
|
5816
|
-
});
|
|
5817
|
-
const options = {
|
|
5818
|
-
render(h) {
|
|
5819
|
-
return h(isBrowser ? 'div' : 'root', {
|
|
5820
|
-
attrs: {
|
|
5821
|
-
id,
|
|
5822
|
-
class: isBrowser ? 'taro_page' : ''
|
|
5823
|
-
}
|
|
5824
|
-
}, [
|
|
5825
|
-
h(injectedPage, { props: { tid: id } })
|
|
5826
|
-
]);
|
|
5827
|
-
}
|
|
5828
|
-
};
|
|
5829
|
-
return options;
|
|
5830
|
-
};
|
|
5831
|
-
}
|
|
5832
|
-
function setReconciler$1() {
|
|
5833
|
-
const hooks = container.get(SERVICE_IDENTIFIER.Hooks);
|
|
5834
|
-
const onRemoveAttribute = function (dom, qualifiedName) {
|
|
5835
|
-
// 处理原因: https://github.com/NervJS/taro/pull/5990
|
|
5836
|
-
const props = dom.props;
|
|
5837
|
-
if (!props.hasOwnProperty(qualifiedName) || isBoolean(props[qualifiedName])) {
|
|
5838
|
-
dom.setAttribute(qualifiedName, false);
|
|
5839
|
-
return true;
|
|
5840
|
-
}
|
|
5841
|
-
};
|
|
5842
|
-
const getLifecycle = function (instance, lifecycle) {
|
|
5843
|
-
return instance.$options[lifecycle];
|
|
5844
|
-
};
|
|
5845
|
-
hooks.onRemoveAttribute = onRemoveAttribute;
|
|
5846
|
-
hooks.getLifecycle = getLifecycle;
|
|
5847
|
-
if (process.env.TARO_ENV === 'h5') {
|
|
5848
|
-
hooks.createPullDownComponent = (el, path, vue) => {
|
|
5849
|
-
const injectedPage = vue.extend({
|
|
5850
|
-
props: {
|
|
5851
|
-
tid: String
|
|
5852
|
-
},
|
|
5853
|
-
mixins: [el, {
|
|
5854
|
-
created() {
|
|
5855
|
-
injectPageInstance(this, path);
|
|
5856
|
-
}
|
|
5857
|
-
}]
|
|
5858
|
-
});
|
|
5859
|
-
const options = {
|
|
5860
|
-
name: 'PullToRefresh',
|
|
5861
|
-
render(h) {
|
|
5862
|
-
return h('taro-pull-to-refresh', {
|
|
5863
|
-
class: ['hydrated']
|
|
5864
|
-
}, [h(injectedPage, this.$slots.default)]);
|
|
5865
|
-
}
|
|
5866
|
-
};
|
|
5867
|
-
return options;
|
|
5868
|
-
};
|
|
5869
|
-
hooks.getDOMNode = (el) => {
|
|
5870
|
-
return el.$el;
|
|
5871
|
-
};
|
|
5872
|
-
}
|
|
5873
|
-
}
|
|
5874
|
-
let Vue;
|
|
5875
|
-
function createVueApp(App, vue, config) {
|
|
5876
|
-
Vue = vue;
|
|
5877
|
-
ensure(!!Vue, '构建 Vue 项目请把 process.env.FRAMEWORK 设置为 \'vue\'');
|
|
5878
|
-
setReconciler$1();
|
|
5879
|
-
Vue.config.getTagNamespace = noop;
|
|
5880
|
-
const elements = [];
|
|
5881
|
-
const pages = [];
|
|
5882
|
-
let appInstance;
|
|
5883
|
-
const wrapper = new Vue({
|
|
5884
|
-
render(h) {
|
|
5885
|
-
while (pages.length > 0) {
|
|
5886
|
-
const page = pages.pop();
|
|
5887
|
-
elements.push(page(h));
|
|
5888
|
-
}
|
|
5889
|
-
return h(App, { ref: 'app' }, elements.slice());
|
|
5890
|
-
},
|
|
5891
|
-
methods: {
|
|
5892
|
-
mount(component, id, cb) {
|
|
5893
|
-
pages.push((h) => h(component, { key: id }));
|
|
5894
|
-
this.updateSync(cb);
|
|
5895
|
-
},
|
|
5896
|
-
updateSync(cb) {
|
|
5897
|
-
this._update(this._render(), false);
|
|
5898
|
-
this.$children.forEach((child) => child._update(child._render(), false));
|
|
5899
|
-
cb();
|
|
5900
|
-
},
|
|
5901
|
-
unmount(id, cb) {
|
|
5902
|
-
for (let i = 0; i < elements.length; i++) {
|
|
5903
|
-
const element = elements[i];
|
|
5904
|
-
if (element.key === id) {
|
|
5905
|
-
elements.splice(i, 1);
|
|
5906
|
-
break;
|
|
5907
|
-
}
|
|
5908
|
-
}
|
|
5909
|
-
this.updateSync(cb);
|
|
5910
|
-
}
|
|
5911
|
-
}
|
|
5912
|
-
});
|
|
5913
|
-
if (!isBrowser) {
|
|
5914
|
-
wrapper.$mount(document$2.getElementById('app'));
|
|
5915
|
-
}
|
|
5916
|
-
const app = Object.create({
|
|
5917
|
-
mount(component, id, cb) {
|
|
5918
|
-
const page = connectVuePage(Vue, id)(component);
|
|
5919
|
-
wrapper.mount(page, id, cb);
|
|
5920
|
-
},
|
|
5921
|
-
unmount(id, cb) {
|
|
5922
|
-
wrapper.unmount(id, cb);
|
|
5923
|
-
}
|
|
5924
|
-
}, {
|
|
5925
|
-
config: {
|
|
5926
|
-
writable: true,
|
|
5927
|
-
enumerable: true,
|
|
5928
|
-
configurable: true,
|
|
5929
|
-
value: config
|
|
5930
|
-
},
|
|
5931
|
-
onLaunch: {
|
|
5932
|
-
writable: true,
|
|
5933
|
-
enumerable: true,
|
|
5934
|
-
value(options) {
|
|
5935
|
-
Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
|
|
5936
|
-
if (isBrowser) {
|
|
5937
|
-
// 由于 H5 路由初始化的时候会清除 app 下的 dom 元素,所以需要在路由初始化后再执行 render
|
|
5938
|
-
wrapper.$mount(document$2.getElementById('app'));
|
|
5939
|
-
}
|
|
5940
|
-
appInstance = wrapper.$refs.app;
|
|
5941
|
-
if (appInstance != null && isFunction$1(appInstance.$options.onLaunch)) {
|
|
5942
|
-
appInstance.$options.onLaunch.call(appInstance, options);
|
|
5943
|
-
}
|
|
5944
|
-
}
|
|
5945
|
-
},
|
|
5946
|
-
onShow: {
|
|
5947
|
-
writable: true,
|
|
5948
|
-
enumerable: true,
|
|
5949
|
-
value(options) {
|
|
5950
|
-
Current.router = Object.assign({ params: options === null || options === void 0 ? void 0 : options.query }, options);
|
|
5951
|
-
if (appInstance != null && isFunction$1(appInstance.$options.onShow)) {
|
|
5952
|
-
appInstance.$options.onShow.call(appInstance, options);
|
|
5953
|
-
}
|
|
5954
|
-
}
|
|
5955
|
-
},
|
|
5956
|
-
onHide: {
|
|
5957
|
-
writable: true,
|
|
5958
|
-
enumerable: true,
|
|
5959
|
-
value(options) {
|
|
5960
|
-
if (appInstance != null && isFunction$1(appInstance.$options.onHide)) {
|
|
5961
|
-
appInstance.$options.onHide.call(appInstance, options);
|
|
5962
|
-
}
|
|
5963
|
-
}
|
|
5964
|
-
}
|
|
5965
|
-
});
|
|
5966
|
-
Current.app = app;
|
|
5967
|
-
return Current.app;
|
|
5968
|
-
}
|
|
5969
|
-
|
|
5970
|
-
function createVue3Page(h, id) {
|
|
5971
|
-
return function (component) {
|
|
5972
|
-
var _a;
|
|
5973
|
-
const inject = {
|
|
5974
|
-
props: {
|
|
5975
|
-
tid: String
|
|
5976
|
-
},
|
|
5977
|
-
created() {
|
|
5978
|
-
injectPageInstance(this, id);
|
|
5979
|
-
// vue3 组件 created 时机比小程序页面 onShow 慢,因此在 created 后再手动触发一次 onShow。
|
|
5980
|
-
this.$nextTick(() => {
|
|
5981
|
-
safeExecute(id, 'onShow');
|
|
5982
|
-
});
|
|
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
4655
|
}
|
|
6136
4656
|
|
|
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
|