@mpxjs/core 2.9.1 → 2.9.6

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/@types/index.d.ts CHANGED
@@ -31,13 +31,18 @@ type ArrayType<T extends any[]> = T extends Array<infer R> ? R : never;
31
31
  // Mpx types
32
32
  type Data = object | (() => object)
33
33
 
34
- type PropConstructor<T = any> = {
35
- new (...args: any[]): T & {};
36
- } | {
37
- (): T;
38
- }
39
-
40
- export type PropType<T> = PropConstructor<T>
34
+ export type PropType<T> = T & (
35
+ T extends string
36
+ ? StringConstructor
37
+ : T extends number
38
+ ? NumberConstructor
39
+ : T extends boolean
40
+ ? BooleanConstructor
41
+ : T extends any[]
42
+ ? ArrayConstructor
43
+ : T extends object
44
+ ? ObjectConstructor
45
+ : never )
41
46
 
42
47
  type FullPropType<T> = {
43
48
  type: PropType<T>;
@@ -75,17 +80,17 @@ interface WatchField {
75
80
 
76
81
  type GetDataType<T> = T extends () => any ? ReturnType<T> : T
77
82
 
78
- type PropValueType<Def> = Def extends {
79
- type: (...args: any[]) => infer T;
80
- optionalType?: ((...args: any[]) => infer T)[];
81
- value?: infer T;
82
- }
83
+ type PropValueType<Def> = Def extends FullPropType<infer T>
83
84
  ? T
84
- : Def extends (...args: any[]) => infer T
85
+ : Def extends PropType<infer T>
85
86
  ? T
86
- : Def extends FullPropType<infer T>
87
+ : Def extends {
88
+ type: (...args: any[]) => infer T;
89
+ optionalType?: ((...args: any[]) => infer T)[];
90
+ value?: infer T;
91
+ }
87
92
  ? T
88
- : Def extends PropType<infer T>
93
+ : Def extends (...args: any[]) => infer T
89
94
  ? T
90
95
  : any;
91
96
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.9.1",
3
+ "version": "2.9.6",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -47,5 +47,5 @@
47
47
  "url": "https://github.com/didi/mpx/issues"
48
48
  },
49
49
  "sideEffects": false,
50
- "gitHead": "5460efb7afae97e321ff608258a8c0ad0b366f4c"
50
+ "gitHead": "9034343edacc95da66b6e8ddb5c2f64a4be97231"
51
51
  }
@@ -41,6 +41,7 @@ export default function pageScrollMixin (mixinType) {
41
41
  return {
42
42
  mounted () {
43
43
  this.__lastScrollY = 0
44
+ this.__originalOverflow = document.body.style.overflow
44
45
  },
45
46
  activated () {
46
47
  if (!refreshMs()) {
@@ -72,19 +73,22 @@ export default function pageScrollMixin (mixinType) {
72
73
  }
73
74
  },
74
75
  deactivated () {
75
- if (ms) {
76
+ if (ms) { // 保存滚动位置, 用于 keep-alive
76
77
  this.__lastScrollY = getScrollTop()
77
- ms.destroy()
78
- hideLoading(this)
79
78
  }
79
+ this.__uninstallMpxScroll()
80
80
  },
81
81
  beforeDestroy () {
82
- if (ms) {
83
- ms.destroy()
84
- hideLoading(this)
85
- }
82
+ this.__uninstallMpxScroll()
86
83
  },
87
84
  methods: {
85
+ __uninstallMpxScroll () {
86
+ if (ms) {
87
+ ms.destroy()
88
+ hideLoading(this)
89
+ document.body.style.overflow = this.__originalOverflow // 恢复原有 overflow, 避免影响其他页面
90
+ }
91
+ },
88
92
  __mpxPullDownHandler (autoStop = false, isRefresh = false) {
89
93
  this.__pullingDown = true
90
94
  // 同微信保持一致
@@ -1,4 +1,5 @@
1
1
  import {
2
+ BEFORECREATE,
2
3
  CREATED,
3
4
  ONHIDE,
4
5
  ONSHOW,
@@ -47,6 +48,18 @@ if (isBrowser) {
47
48
  window.addEventListener('resize', onResize)
48
49
  }
49
50
 
51
+ function getParentPage (vm) {
52
+ let parent = vm.$parent
53
+ while (parent) {
54
+ if (parent.route) {
55
+ return parent
56
+ } else if (parent.$page) {
57
+ return parent.$page
58
+ }
59
+ parent = parent.$parent
60
+ }
61
+ }
62
+
50
63
  export default function pageStatusMixin (mixinType) {
51
64
  const mixin = {}
52
65
 
@@ -69,10 +82,19 @@ export default function pageStatusMixin (mixinType) {
69
82
  })
70
83
  }
71
84
 
85
+ // 创建组件时记录当前所属page,用于驱动pageLifetimes和onShow/onHide钩子
86
+ if (mixinType === 'component') {
87
+ Object.assign(mixin, {
88
+ [BEFORECREATE] () {
89
+ this.$page = getParentPage(this)
90
+ }
91
+ })
92
+ }
93
+
72
94
  Object.assign(mixin, {
73
95
  [CREATED] () {
74
96
  if (isBrowser) {
75
- const pageInstance = mixinType === 'page' ? this : getCurrentPageInstance()
97
+ const pageInstance = mixinType === 'page' ? this : this.$page
76
98
  if (pageInstance) {
77
99
  this.$watch(() => pageInstance.mpxPageStatus, status => {
78
100
  if (!status) return
@@ -35,7 +35,7 @@ export default function proxyEventMixin () {
35
35
  let fallbackType = ''
36
36
  if (type === 'begin' || type === 'end') {
37
37
  // 地图的 regionchange 事件会派发 e.type 为 begin 和 end 的事件
38
- fallbackType = 'regionchange'
38
+ fallbackType = __mpx_mode__ === 'ali' ? 'regionChange' : 'regionchange'
39
39
  } else if (/-([a-z])/.test(type)) {
40
40
  fallbackType = dash2hump(type)
41
41
  } else if (__mpx_mode__ === 'ali') {