@mpxjs/api-proxy 2.10.5 → 2.10.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
@@ -121,12 +121,17 @@ export const enableAlertBeforeUnload: WechatMiniprogram.Wx['enableAlertBeforeUnl
121
121
  export const disableAlertBeforeUnload: WechatMiniprogram.Wx['disableAlertBeforeUnload']
122
122
  export const getMenuButtonBoundingClientRect: WechatMiniprogram.Wx['getMenuButtonBoundingClientRect']
123
123
  export const getImageInfo: WechatMiniprogram.Wx['getImageInfo']
124
+ export const chooseMedia: WechatMiniprogram.Wx['chooseMedia']
124
125
  export const vibrateShort: WechatMiniprogram.Wx['vibrateShort']
125
126
  export const vibrateLong: WechatMiniprogram.Wx['vibrateLong']
126
127
  export const getExtConfig: WechatMiniprogram.Wx['getExtConfig']
127
128
  export const getExtConfigSync: WechatMiniprogram.Wx['getExtConfigSync']
128
129
  export const openLocation: WechatMiniprogram.Wx['openLocation']
129
130
  export const chooseLocation: WechatMiniprogram.Wx['chooseLocation']
131
+ export const onLocationChange: WechatMiniprogram.Wx['onLocationChange']
132
+ export const offLocationChange: WechatMiniprogram.Wx['offLocationChange']
133
+ export const startLocationUpdate: WechatMiniprogram.Wx['startLocationUpdate']
134
+ export const stopLocationUpdate: WechatMiniprogram.Wx['stopLocationUpdate']
130
135
 
131
136
  declare const install: (...args: any) => any
132
137
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/api-proxy",
3
- "version": "2.10.5",
3
+ "version": "2.10.6",
4
4
  "description": "convert miniprogram API at each end",
5
5
  "module": "src/index.js",
6
6
  "types": "@types/index.d.ts",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "homepage": "https://github.com/didi/mpx#readme",
39
39
  "dependencies": {
40
- "@mpxjs/utils": "^2.10.4",
40
+ "@mpxjs/utils": "^2.10.6",
41
41
  "axios": "^1.7.3"
42
42
  },
43
43
  "peerDependencies": {
@@ -68,5 +68,5 @@
68
68
  "optional": true
69
69
  }
70
70
  },
71
- "gitHead": "80a4120733a1ee64e394ae58240497ea6721f435"
71
+ "gitHead": "e28605bc2d8ab33f4dccf13ea98d9ca996f43ed6"
72
72
  }
@@ -1,4 +1,4 @@
1
- import { hasOwn, noop, getEnvObj, getFocusedNavigation } from '@mpxjs/utils'
1
+ import { hasOwn, noop, getEnvObj, getFocusedNavigation, error as errorHandler, warn as warnHandler } from '@mpxjs/utils'
2
2
  import { getCurrentInstance } from '@mpxjs/core'
3
3
 
4
4
  /**
@@ -47,15 +47,16 @@ const handleSuccess = (opts, getOptions = noop, thisObj) => {
47
47
  }
48
48
 
49
49
  function warn (msg) {
50
- console.warn && console.warn(`[@mpxjs/api-proxy warn]:\n ${msg}`)
50
+ warnHandler(msg, '@mpxjs/api-proxy')
51
51
  }
52
52
 
53
53
  function error (msg) {
54
- console.error && console.error(`[@mpxjs/api-proxy error]:\n ${msg}`)
54
+ errorHandler(msg, '@mpxjs/api-proxy')
55
55
  }
56
+
56
57
  function envError (method) {
57
58
  return () => {
58
- throw Error(`[@mpxjs/api-proxy error]:\n ${__mpx_mode__}环境不支持${method}方法`)
59
+ errorHandler(`\n ${__mpx_mode__}环境不支持${method}方法`, '@mpxjs/api-proxy')
59
60
  }
60
61
  }
61
62
 
@@ -90,7 +91,7 @@ function failHandle (result, fail, complete) {
90
91
 
91
92
  function getCurrentPageId () {
92
93
  const currentInstance = getCurrentInstance()
93
- const id = currentInstance?.getPageId() || getFocusedNavigation()?.pageId || null
94
+ const id = currentInstance?.proxy?.getPageId() || getFocusedNavigation()?.pageId || null
94
95
  return id
95
96
  }
96
97
 
@@ -1,3 +1,4 @@
1
+ import { error } from '../../../common/js'
1
2
  class Animation {
2
3
  constructor (
3
4
  {
@@ -47,7 +48,7 @@ class Animation {
47
48
  steps = []
48
49
 
49
50
  matrix (a, b, c, d, tx, ty) { // Todo
50
- console.error('React Native 不支持 matrix 动画')
51
+ error('React Native 不支持 matrix 动画')
51
52
  // this.transform.set('matrix', [a, b, c, d, tx, ty])
52
53
  return this
53
54
  }
@@ -57,7 +58,7 @@ class Animation {
57
58
  a3, b3, c3, d3,
58
59
  a4, b4, c4, d4
59
60
  ) {
60
- console.error('React Native 不支持 matrix3d 动画')
61
+ error('React Native 不支持 matrix3d 动画')
61
62
  // this.transform.set('matrix3d', [ // Todo
62
63
  // a1, b1, c1, d1,
63
64
  // a2, b2, c2, d2,
@@ -78,7 +79,7 @@ class Animation {
78
79
  // this.rotateY(y)
79
80
  // this.rotateZ(z)
80
81
  // this.rotate(angle)
81
- console.error('React Native 不支持 transform rotate3d')
82
+ error('React Native 不支持 transform rotate3d')
82
83
  return this
83
84
  }
84
85
 
@@ -116,13 +117,13 @@ class Animation {
116
117
  }
117
118
 
118
119
  scaleZ (scale) { // Todo Invariant Violation: Invalid transform scaleZ: {"scaleZ":0}
119
- console.error('React Native 不支持 transform scaleZ')
120
+ error('React Native 不支持 transform scaleZ')
120
121
  // this.transform.set('scaleZ', scale)
121
122
  return this
122
123
  }
123
124
 
124
125
  scale3d (x, y, z) { // Todo Invariant Violation: Invalid transform scaleZ: {"scaleZ":0}
125
- console.error('React Native 不支持 transform scaleZ,故不支持 scale3d')
126
+ error('React Native 不支持 transform scaleZ,故不支持 scale3d')
126
127
  // this.scaleX(x)
127
128
  // this.scaleY(y)
128
129
  // this.scaleZ(z)
@@ -167,14 +168,14 @@ class Animation {
167
168
  }
168
169
 
169
170
  translateZ (translate) { // Todo Invariant Violation: Invalid transform translateZ: {"translateZ":0}
170
- console.error('React Native 不支持 transform translateZ')
171
+ error('React Native 不支持 transform translateZ')
171
172
  // [translate] = this._transformUnit(translate)
172
173
  // this.transform.set('translateZ', translate)
173
174
  return this
174
175
  }
175
176
 
176
177
  translate3d (x, y, z) { // Todo Invariant Violation: Invalid transform translateZ: {"translateZ":0}
177
- console.error('React Native 不支持 transform translateZ,故无法支持 translate3d')
178
+ error('React Native 不支持 transform translateZ,故无法支持 translate3d')
178
179
  // [x, y, z] = this._transformUnit(x, y, z)
179
180
  // // this.transform.set('translate3d', [x, y, z])
180
181
  // this.translateX(x)
@@ -239,7 +240,7 @@ class Animation {
239
240
  transformOrigin = DEFAULT.transformOrigin
240
241
  } = arg
241
242
  if (typeof transformOrigin !== 'string') {
242
- console.error('Value of transformOrigin only support string type, please check again')
243
+ error('Value of transformOrigin only support string type, please check again')
243
244
  transformOrigin = DEFAULT.transformOrigin
244
245
  }
245
246
  this.steps.push({
@@ -1,5 +1,5 @@
1
1
  import { nextTick } from '../next-tick'
2
- import { parseDataset } from '@mpxjs/utils'
2
+ import { parseDataset, warn } from '@mpxjs/utils'
3
3
 
4
4
  let isInit = true
5
5
 
@@ -68,7 +68,7 @@ class WebIntersectionObserver {
68
68
  observe (targetSelector, callback) {
69
69
  nextTick(() => {
70
70
  if (!document.querySelector(targetSelector)) {
71
- console.warn(`[mpx runtime warn]: Node ${JSON.stringify(targetSelector)} is not found. Intersection observer will not trigger.`)
71
+ warn(`Node ${JSON.stringify(targetSelector)} is not found. Intersection observer will not trigger.`)
72
72
  return
73
73
  }
74
74
  this._observer = this.initObserver()
@@ -1,4 +1,4 @@
1
- import { ENV_OBJ, changeOpts, handleSuccess } from '../../../common/js'
1
+ import { ENV_OBJ, changeOpts, handleSuccess, envError } from '../../../common/js'
2
2
 
3
3
  function previewImage (options = {}) {
4
4
  const opts = changeOpts(options)
@@ -30,10 +30,13 @@ function compressImage (options = {}) {
30
30
  return ENV_OBJ.compressImage(opts)
31
31
  }
32
32
 
33
- const getImageInfo = ENV_OBJ.getImageInfo
33
+ const getImageInfo = ENV_OBJ.getImageInfo || envError('getImageInfo')
34
+
35
+ const chooseMedia = envError('chooseMedia')
34
36
 
35
37
  export {
36
38
  previewImage,
37
39
  compressImage,
38
- getImageInfo
40
+ getImageInfo,
41
+ chooseMedia
39
42
  }
@@ -38,8 +38,11 @@ const getImageInfo = function (options = {}) {
38
38
  })
39
39
  }
40
40
 
41
+ const chooseMedia = envError('chooseMedia')
42
+
41
43
  export {
42
44
  previewImage,
43
45
  compressImage,
44
- getImageInfo
46
+ getImageInfo,
47
+ chooseMedia
45
48
  }
@@ -6,8 +6,11 @@ const compressImage = ENV_OBJ.compressImage || envError('compressImage')
6
6
 
7
7
  const getImageInfo = ENV_OBJ.getImageInfo || envError('getImageInfo')
8
8
 
9
+ const chooseMedia = ENV_OBJ.chooseMedia || envError('chooseMedia')
10
+
9
11
  export {
10
12
  previewImage,
11
13
  compressImage,
12
- getImageInfo
14
+ getImageInfo,
15
+ chooseMedia
13
16
  }
@@ -60,8 +60,11 @@ const getImageInfo = function (options = {}) {
60
60
  }
61
61
  }
62
62
 
63
+ const chooseMedia = envError('chooseMedia')
64
+
63
65
  export {
64
66
  previewImage,
65
67
  compressImage,
66
- getImageInfo
68
+ getImageInfo,
69
+ chooseMedia
67
70
  }
@@ -1,4 +1,4 @@
1
- import { ENV_OBJ, changeOpts, handleSuccess, defineUnsupportedProps } from '../../../common/js'
1
+ import { ENV_OBJ, changeOpts, handleSuccess, defineUnsupportedProps, envError } from '../../../common/js'
2
2
 
3
3
  function getLocation (options = {}) {
4
4
  const opts = Object.assign(options, {
@@ -22,10 +22,22 @@ function openLocation (options = {}) {
22
22
  return ENV_OBJ.openLocation(opts)
23
23
  }
24
24
 
25
- const chooseLocation = ENV_OBJ.chooseLocation
25
+ const chooseLocation = ENV_OBJ.chooseLocation || envError('chooseLocation')
26
+
27
+ const onLocationChange = envError('onLocationChange')
28
+
29
+ const offLocationChange = envError('offLocationChange')
30
+
31
+ const startLocationUpdate = envError('startLocationUpdate')
32
+
33
+ const stopLocationUpdate = envError('stopLocationUpdate')
26
34
 
27
35
  export {
28
36
  getLocation,
29
37
  openLocation,
30
- chooseLocation
38
+ chooseLocation,
39
+ onLocationChange,
40
+ offLocationChange,
41
+ startLocationUpdate,
42
+ stopLocationUpdate
31
43
  }
@@ -24,8 +24,20 @@ const openLocation = envError('openLocation')
24
24
 
25
25
  const chooseLocation = envError('chooseLocation')
26
26
 
27
+ const onLocationChange = envError('onLocationChange')
28
+
29
+ const offLocationChange = envError('offLocationChange')
30
+
31
+ const startLocationUpdate = envError('startLocationUpdate')
32
+
33
+ const stopLocationUpdate = envError('stopLocationUpdate')
34
+
27
35
  export {
28
36
  getLocation,
29
37
  openLocation,
30
- chooseLocation
38
+ chooseLocation,
39
+ onLocationChange,
40
+ offLocationChange,
41
+ startLocationUpdate,
42
+ stopLocationUpdate
31
43
  }
@@ -6,8 +6,20 @@ const openLocation = ENV_OBJ.openLocation || envError('openLocation')
6
6
 
7
7
  const chooseLocation = ENV_OBJ.chooseLocation || envError('chooseLocation')
8
8
 
9
+ const onLocationChange = ENV_OBJ.onLocationChange || envError('onLocationChange')
10
+
11
+ const offLocationChange = ENV_OBJ.offLocationChange || envError('offLocationChange')
12
+
13
+ const startLocationUpdate = ENV_OBJ.startLocationUpdate || envError('startLocationUpdate')
14
+
15
+ const stopLocationUpdate = ENV_OBJ.stopLocationUpdate || envError('stopLocationUpdate')
16
+
9
17
  export {
10
18
  getLocation,
11
19
  openLocation,
12
- chooseLocation
20
+ chooseLocation,
21
+ onLocationChange,
22
+ offLocationChange,
23
+ startLocationUpdate,
24
+ stopLocationUpdate
13
25
  }
@@ -29,8 +29,20 @@ const openLocation = envError('openLocation')
29
29
 
30
30
  const chooseLocation = envError('chooseLocation')
31
31
 
32
+ const onLocationChange = envError('onLocationChange')
33
+
34
+ const offLocationChange = envError('offLocationChange')
35
+
36
+ const startLocationUpdate = envError('startLocationUpdate')
37
+
38
+ const stopLocationUpdate = envError('stopLocationUpdate')
39
+
32
40
  export {
33
41
  getLocation,
34
42
  openLocation,
35
- chooseLocation
43
+ chooseLocation,
44
+ onLocationChange,
45
+ offLocationChange,
46
+ startLocationUpdate,
47
+ stopLocationUpdate
36
48
  }
@@ -33,12 +33,46 @@ function getSystemInfoSync () {
33
33
  }
34
34
 
35
35
  const getDeviceInfo = function () {
36
- const res = ENV_OBJ.getDeviceBaseInfo()
36
+ let res
37
+ if (ENV_OBJ.canIUse('getDeviceBaseInfo')) {
38
+ res = ENV_OBJ.getDeviceBaseInfo()
39
+ } else {
40
+ const systemInfo = getSystemInfoSync()
41
+ res = {
42
+ abi: systemInfo.abi || null,
43
+ benchmarkLevel: systemInfo.benchmarkLevel || null,
44
+ brand: systemInfo.brand,
45
+ model: systemInfo.model,
46
+ system: systemInfo.system,
47
+ platform: systemInfo.platform,
48
+ memorySize: systemInfo.memorySize || null
49
+ }
50
+ }
37
51
  defineUnsupportedProps(res, ['deviceAbi', 'benchmarkLevel', 'cpuType'])
38
52
  return res
39
53
  }
40
54
 
41
- const getWindowInfo = ENV_OBJ.getWindowInfo || envError('getWindowInfo')
55
+ const getWindowInfo = function () {
56
+ let res
57
+ if (ENV_OBJ.canIUse('getWindowInfo')) {
58
+ res = ENV_OBJ.getWindowInfo()
59
+ } else {
60
+ const systemInfo = getSystemInfoSync()
61
+ res = {
62
+ pixelRatio: systemInfo.pixelRatio,
63
+ screenWidth: systemInfo.screenWidth,
64
+ screenHeight: systemInfo.screenHeight,
65
+ windowWidth: systemInfo.windowWidth,
66
+ windowHeight: systemInfo.windowHeight,
67
+ statusBarHeight: systemInfo.statusBarHeight,
68
+ safeArea: systemInfo.safeArea || null,
69
+ screenTop: systemInfo.screenTop || null
70
+ }
71
+ }
72
+ return res
73
+ }
74
+
75
+ // const getWindowInfo = ENV_OBJ.getWindowInfo || envError('getWindowInfo')
42
76
 
43
77
  const getLaunchOptionsSync = ENV_OBJ.getLaunchOptionsSync || envError('getLaunchOptionsSync')
44
78
 
@@ -32,8 +32,7 @@ const styles = StyleSheet.create({
32
32
  alignItems: 'center'
33
33
  },
34
34
  toastHasIcon: {
35
- height: 110,
36
- width: 120
35
+ width: 140
37
36
  },
38
37
  toastImg: {
39
38
  width: 40,
@@ -46,8 +45,6 @@ const styles = StyleSheet.create({
46
45
  color: '#ffffff',
47
46
  fontSize: 12,
48
47
  lineHeight: 18,
49
- height: 18,
50
- overflow: 'hidden',
51
48
  marginTop: 10
52
49
  }
53
50
  })
@@ -80,7 +77,7 @@ function showToast (options = {}) {
80
77
  ToastView = <View style={[styles.toastWrap, { pointerEvents }]}>
81
78
  <View style={[styles.toastContent, styles.toastHasIcon]}>
82
79
  <Image style={ styles.toastImg } source={{ uri: image || iconImg[icon] }}></Image>
83
- { title ? <Text style={styles.toastText}>{title}</Text> : null }
80
+ { title ? <Text numberOfLines={2} style={styles.toastText}>{title}</Text> : null }
84
81
  </View>
85
82
  </View>
86
83
  } else if (icon === 'loading') {
@@ -91,7 +88,7 @@ function showToast (options = {}) {
91
88
  size='small'
92
89
  color='#eee'
93
90
  />
94
- { title ? <Text style={styles.toastText}>{title}</Text> : null }
91
+ { title ? <Text numberOfLines={2} style={styles.toastText}>{title}</Text> : null }
95
92
  </View>
96
93
  </View>
97
94
  } else {
@@ -102,7 +99,6 @@ function showToast (options = {}) {
102
99
  ...styles.toastText,
103
100
  ...(icon === 'none'
104
101
  ? {
105
- height: 'auto',
106
102
  marginTop: 0
107
103
  }
108
104
  : {})
@@ -1,4 +1,4 @@
1
- import { isBrowser, throwSSRWarning } from '../../../common/js'
1
+ import { isBrowser, throwSSRWarning, warn } from '../../../common/js'
2
2
 
3
3
  const allowPlaybackRate = [0.5, 0.8, 1.0, 1.25, 1.5, 2.0]
4
4
  export const createVideoContext = (id, context) => {
@@ -22,22 +22,22 @@ export const createVideoContext = (id, context) => {
22
22
 
23
23
  // todo 进入后台音频播放模式
24
24
  __videoContext.requestBackgroundPlayback = () => {
25
- console.warn('暂不支持requestBackgroundPlayback API')
25
+ warn('暂不支持requestBackgroundPlayback API')
26
26
  }
27
27
 
28
28
  // todo 退出后台音频播放
29
29
  __videoContext.exitBackgroundPlayback = () => {
30
- console.warn('暂不支持exitBackgroundPlayback API')
30
+ warn('暂不支持exitBackgroundPlayback API')
31
31
  }
32
32
 
33
33
  // todo 退出小窗,该方法可在任意页面调用
34
34
  __videoContext.exitPictureInPicture = ({ success, fail, complete }) => {
35
- console.warn('暂不支持exitPictureInPicture API')
35
+ warn('暂不支持exitPictureInPicture API')
36
36
  }
37
37
 
38
38
  // todo 发送弹幕
39
39
  __videoContext.sendDanmu = ({ text, color }) => {
40
- console.warn('暂不支持发送弹幕')
40
+ warn('暂不支持发送弹幕')
41
41
  }
42
42
 
43
43
  // 进入全屏
@@ -90,7 +90,7 @@ export const createVideoContext = (id, context) => {
90
90
  // 设置倍速播放
91
91
  __videoContext.playbackRate = (number) => {
92
92
  if (allowPlaybackRate.indexOf(number) === -1) {
93
- console.warn(`不支持${number}倍速播放`)
93
+ warn(`不支持${number}倍速播放`)
94
94
  return
95
95
  }
96
96
  __videoNode.playbackRate = number
@@ -43,7 +43,7 @@ export * from './api/file'
43
43
  // getUserInfo
44
44
  export * from './api/get-user-info'
45
45
 
46
- // previewImage, compressImage, getImageInfo
46
+ // previewImage, compressImage, getImageInfo, chooseMedia
47
47
  export * from './api/image'
48
48
 
49
49
  // login
@@ -105,7 +105,7 @@ export * from './api/video'
105
105
  // onWindowResize, offWindowResize
106
106
  export * from './api/window'
107
107
 
108
- // getLocation, openLocation, chooseLocation
108
+ // getLocation, openLocation, chooseLocation, onLocationChange, offLocationChange, startLocationUpdate, stopLocationUpdate
109
109
  export * from './api/location'
110
110
 
111
111
  // getExtConfig, getExtConfigSync