@mpxjs/api-proxy 2.9.66 → 2.9.69

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.
Files changed (35) hide show
  1. package/package.json +3 -11
  2. package/src/platform/api/next-tick/index.ios.js +7 -1
  3. package/src/platform/api/request/index.web.js +8 -5
  4. package/src/platform/api/route/index.ios.js +19 -24
  5. package/src/platform/api/system/index.ali.js +7 -1
  6. package/src/platform/api/system/index.js +7 -1
  7. package/src/platform/api/system/index.web.js +77 -16
  8. package/src/platform/api/system/rnSystem.js +22 -46
  9. package/src/platform/api/system/rnWindowInfo.js +42 -0
  10. package/src/platform/index.js +2 -5
  11. package/src/platform/api/action-sheet/index.android.js +0 -1
  12. package/src/platform/api/animation/index.android.js +0 -1
  13. package/src/platform/api/app/index.android.js +0 -1
  14. package/src/platform/api/base/index.android.js +0 -1
  15. package/src/platform/api/clipboard-data/index.android.js +0 -1
  16. package/src/platform/api/create-selector-query/index.android.js +0 -1
  17. package/src/platform/api/device/network/index.android.js +0 -1
  18. package/src/platform/api/keyboard/index.android.js +0 -1
  19. package/src/platform/api/lifecycle/index.ali.js +0 -9
  20. package/src/platform/api/lifecycle/index.js +0 -7
  21. package/src/platform/api/lifecycle/index.web.js +0 -12
  22. package/src/platform/api/location/index.android.js +0 -1
  23. package/src/platform/api/make-phone-call/index.android.js +0 -1
  24. package/src/platform/api/modal/index.android.js +0 -1
  25. package/src/platform/api/next-tick/index.android.js +0 -1
  26. package/src/platform/api/request/index.android.js +0 -1
  27. package/src/platform/api/route/index.android.js +0 -1
  28. package/src/platform/api/screen-brightness/index.android.js +0 -1
  29. package/src/platform/api/set-navigation-bar/index.android.js +0 -1
  30. package/src/platform/api/socket/index.android.js +0 -1
  31. package/src/platform/api/storage/index.android.js +0 -1
  32. package/src/platform/api/system/index.android.js +0 -1
  33. package/src/platform/api/toast/index.android.js +0 -1
  34. package/src/platform/api/vibrate/index.android.js +0 -1
  35. package/src/platform/api/window/index.android.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/api-proxy",
3
- "version": "2.9.66",
3
+ "version": "2.9.69",
4
4
  "description": "convert miniprogram API at each end",
5
5
  "module": "src/index.js",
6
6
  "types": "@types/index.d.ts",
@@ -37,15 +37,13 @@
37
37
  },
38
38
  "homepage": "https://github.com/didi/mpx#readme",
39
39
  "dependencies": {
40
- "@mpxjs/utils": "^2.9.65",
40
+ "@mpxjs/utils": "^2.9.69",
41
41
  "axios": "^1.7.3"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@ant-design/react-native": "^5.1.3",
45
45
  "@react-native-async-storage/async-storage": "^1.23.1",
46
46
  "@react-native-community/netinfo": "^11.2.1",
47
- "expo-brightness": "~11.8.0",
48
- "expo-clipboard": "~6.0.3",
49
47
  "react-native-device-info": "^10.13.2",
50
48
  "react-native-get-location": "^4.0.1",
51
49
  "react-native-haptic-feedback": "^2.3.3",
@@ -55,9 +53,6 @@
55
53
  "@react-native-async-storage/async-storage": {
56
54
  "optional": true
57
55
  },
58
- "expo-clipboard": {
59
- "optional": true
60
- },
61
56
  "@react-native-community/netinfo": {
62
57
  "optional": true
63
58
  },
@@ -73,12 +68,9 @@
73
68
  "@ant-design/react-native": {
74
69
  "optional": true
75
70
  },
76
- "expo-brightness": {
77
- "optional": true
78
- },
79
71
  "react-native-haptic-feedback": {
80
72
  "optional": true
81
73
  }
82
74
  },
83
- "gitHead": "ff9eb06a3be28538870823cebf813ed56f39bbd7"
75
+ "gitHead": "e23c51acc4c2ffdd31fcc6c27aae1aed42d1ade2"
84
76
  }
@@ -1 +1,7 @@
1
- export * from './index.ali'
1
+ function nextTick (fn) {
2
+ Promise.resolve().then(fn)
3
+ }
4
+
5
+ export {
6
+ nextTick
7
+ }
@@ -1,6 +1,7 @@
1
1
  import axios from 'axios'
2
2
  import { successHandle, failHandle, defineUnsupportedProps } from '../../../common/js'
3
3
  import RequestTask from './RequestTask'
4
+ import { serialize, buildUrl } from '@mpxjs/utils'
4
5
 
5
6
  function request (options = { url: '' }) {
6
7
  const CancelToken = axios.CancelToken
@@ -8,6 +9,7 @@ function request (options = { url: '' }) {
8
9
  const requestTask = new RequestTask(source.cancel)
9
10
 
10
11
  let {
12
+ url,
11
13
  data = {},
12
14
  method = 'GET',
13
15
  dataType = 'json',
@@ -18,8 +20,11 @@ function request (options = { url: '' }) {
18
20
  fail = null,
19
21
  complete = null
20
22
  } = options
21
-
22
23
  method = method.toUpperCase()
24
+ if (method === 'GET') {
25
+ url = buildUrl(url, data)
26
+ data = {}
27
+ }
23
28
 
24
29
  if (
25
30
  method === 'POST' &&
@@ -27,9 +32,7 @@ function request (options = { url: '' }) {
27
32
  (header['Content-Type'] === 'application/x-www-form-urlencoded' ||
28
33
  header['content-type'] === 'application/x-www-form-urlencoded')
29
34
  ) {
30
- data = Object.keys(data).reduce((pre, curKey) => {
31
- return `${pre}&${encodeURIComponent(curKey)}=${encodeURIComponent(data[curKey])}`
32
- }, '').slice(1)
35
+ data = serialize(data)
33
36
  }
34
37
 
35
38
  /**
@@ -58,7 +61,7 @@ function request (options = { url: '' }) {
58
61
  */
59
62
  const rOptions = Object.assign(options, {
60
63
  method,
61
- url: options.url,
64
+ url,
62
65
  data,
63
66
  headers: header,
64
67
  responseType,
@@ -1,20 +1,6 @@
1
1
  import { successHandle, failHandle } from '../../../common/js'
2
- import { parseQuery } from '@mpxjs/utils'
3
-
4
- function parseUrl (url) {
5
- let path = url
6
- let query = ''
7
- const queryIndex = url.indexOf('?')
8
- if (queryIndex >= 0) {
9
- path = url.slice(0, queryIndex)
10
- query = url.slice(queryIndex)
11
- }
12
- const queryObj = parseQuery(query || '?')
13
- return {
14
- path,
15
- queryObj
16
- }
17
- }
2
+ import { parseUrlQuery as parseUrl } from '@mpxjs/utils'
3
+ import { nextTick } from '../next-tick'
18
4
 
19
5
  function getBasePath (navigation) {
20
6
  if (navigation) {
@@ -90,14 +76,23 @@ function navigateBack (options = {}) {
90
76
  const navigation = Object.values(global.__mpxPagesMap || {})[0]?.[1]
91
77
  const navigationHelper = global.__navigationHelper
92
78
  if (navigation && navigationHelper) {
93
- navigation.pop(options.delta || 1)
94
- navigationHelper.lastSuccessCallback = () => {
95
- const res = { errMsg: 'navigateBack:ok' }
96
- successHandle(res, options.success, options.complete)
97
- }
98
- navigationHelper.lastFailCallback = (msg) => {
99
- const res = { errMsg: `navigateBack:fail ${msg}` }
100
- failHandle(res, options.fail, options.complete)
79
+ const delta = options.delta || 1
80
+ const routeLength = navigation.getState().routes.length
81
+ if (delta >= routeLength && global.__mpx?.config.rnConfig.onAppBack?.(delta - routeLength + 1)) {
82
+ nextTick(() => {
83
+ const res = { errMsg: 'navigateBack:ok' }
84
+ successHandle(res, options.success, options.complete)
85
+ })
86
+ } else {
87
+ navigation.pop(delta)
88
+ navigationHelper.lastSuccessCallback = () => {
89
+ const res = { errMsg: 'navigateBack:ok' }
90
+ successHandle(res, options.success, options.complete)
91
+ }
92
+ navigationHelper.lastFailCallback = (msg) => {
93
+ const res = { errMsg: `navigateBack:fail ${msg}` }
94
+ failHandle(res, options.fail, options.complete)
95
+ }
101
96
  }
102
97
  }
103
98
  }
@@ -40,9 +40,15 @@ const getDeviceInfo = function () {
40
40
 
41
41
  const getWindowInfo = ENV_OBJ.getWindowInfo || envError('getWindowInfo')
42
42
 
43
+ const getLaunchOptionsSync = ENV_OBJ.getLaunchOptionsSync || envError('getLaunchOptionsSync')
44
+
45
+ const getEnterOptionsSync = ENV_OBJ.getEnterOptionsSync || envError('getEnterOptionsSync')
46
+
43
47
  export {
44
48
  getSystemInfo,
45
49
  getSystemInfoSync,
46
50
  getDeviceInfo,
47
- getWindowInfo
51
+ getWindowInfo,
52
+ getLaunchOptionsSync,
53
+ getEnterOptionsSync
48
54
  }
@@ -8,9 +8,15 @@ const getDeviceInfo = ENV_OBJ.getDeviceInfo || envError('getDeviceInfo')
8
8
 
9
9
  const getWindowInfo = ENV_OBJ.getWindowInfo || envError('getWindowInfo')
10
10
 
11
+ const getLaunchOptionsSync = ENV_OBJ.getLaunchOptionsSync || envError('getLaunchOptionsSync')
12
+
13
+ const getEnterOptionsSync = ENV_OBJ.getEnterOptionsSync || envError('getEnterOptionsSync')
14
+
11
15
  export {
12
16
  getSystemInfo,
13
17
  getSystemInfoSync,
14
18
  getDeviceInfo,
15
- getWindowInfo
19
+ getWindowInfo,
20
+ getLaunchOptionsSync,
21
+ getEnterOptionsSync
16
22
  }
@@ -1,10 +1,6 @@
1
- import { envError, isBrowser, throwSSRWarning, successHandle } from '../../../common/js'
1
+ import { isBrowser, throwSSRWarning, successHandle } from '../../../common/js'
2
2
 
3
- function getSystemInfoSync () {
4
- if (!isBrowser) {
5
- throwSSRWarning('getSystemInfoSync API is running in non browser environments')
6
- return
7
- }
3
+ const getDeviceInfo = function () {
8
4
  const ua = navigator.userAgent.split('(')[1]?.split(')')[0] || ''
9
5
  const phones = new Map([
10
6
  ['iPhone', /iPhone|iPad|iPod|iOS/i],
@@ -37,20 +33,57 @@ function getSystemInfoSync () {
37
33
  } else {
38
34
  system = `Android ${ua.replace(/^.*Android ([\d.]+);.*$/, '$1')}`
39
35
  }
40
-
41
36
  return {
42
- brand: brand,
37
+ abi: null,
38
+ deviceAbi: null,
39
+ benchmarkLevel: null,
40
+ brand,
43
41
  model: brand,
42
+ system,
43
+ platform: navigator.platform,
44
+ cpuType: null,
45
+ memorySize: null
46
+ }
47
+ }
48
+
49
+ const getWindowInfo = function () {
50
+ return {
44
51
  pixelRatio: window.devicePixelRatio,
45
52
  screenWidth: window.screen.width,
46
53
  screenHeight: window.screen.height,
47
54
  windowWidth: document.documentElement.clientWidth,
48
55
  windowHeight: document.documentElement.clientHeight,
49
56
  statusBarHeight: null,
57
+ safeArea: null,
58
+ screenTop: null
59
+ }
60
+ }
61
+
62
+ function getSystemInfoSync () {
63
+ if (!isBrowser) {
64
+ throwSSRWarning('getSystemInfoSync API is running in non browser environments')
65
+ return
66
+ }
67
+
68
+ const {
69
+ pixelRatio,
70
+ screenWidth,
71
+ screenHeight,
72
+ windowWidth,
73
+ windowHeight,
74
+ statusBarHeight,
75
+ safeArea
76
+ } = getWindowInfo()
77
+ const {
78
+ benchmarkLevel,
79
+ brand,
80
+ model,
81
+ system,
82
+ platform
83
+ } = getDeviceInfo()
84
+ const result = Object.assign({
50
85
  language: navigator.language,
51
86
  version: null,
52
- system,
53
- platform: navigator.platform,
54
87
  fontSizeSetting: null,
55
88
  SDKVersion: null,
56
89
  benchmarkLevel: null,
@@ -64,9 +97,23 @@ function getSystemInfoSync () {
64
97
  notificationSoundAuthorized: null,
65
98
  bluetoothEnabled: null,
66
99
  locationEnabled: null,
67
- wifiEnabled: null,
68
- safeArea: null
69
- }
100
+ wifiEnabled: null
101
+ }, {
102
+ pixelRatio,
103
+ screenWidth,
104
+ screenHeight,
105
+ windowWidth,
106
+ windowHeight,
107
+ statusBarHeight,
108
+ safeArea
109
+ }, {
110
+ benchmarkLevel,
111
+ brand,
112
+ model,
113
+ system,
114
+ platform
115
+ })
116
+ return result
70
117
  }
71
118
 
72
119
  function getSystemInfo (options = {}) {
@@ -79,13 +126,27 @@ function getSystemInfo (options = {}) {
79
126
  successHandle(res, options.success, options.complete)
80
127
  }
81
128
 
82
- const getDeviceInfo = envError('getDeviceInfo')
129
+ const getEnterOptionsSync = function () {
130
+ if (!isBrowser) {
131
+ throwSSRWarning('getEnterOptionsSync API is running in non browser environments')
132
+ return
133
+ }
134
+ return global.__mpxEnterOptions || {}
135
+ }
83
136
 
84
- const getWindowInfo = envError('getWindowInfo')
137
+ const getLaunchOptionsSync = function () {
138
+ if (!isBrowser) {
139
+ throwSSRWarning('getLaunchOptionsSync API is running in non browser environments')
140
+ return
141
+ }
142
+ return global.__mpxEnterOptions || {}
143
+ }
85
144
 
86
145
  export {
87
146
  getSystemInfo,
88
147
  getSystemInfoSync,
89
148
  getDeviceInfo,
90
- getWindowInfo
149
+ getWindowInfo,
150
+ getLaunchOptionsSync,
151
+ getEnterOptionsSync
91
152
  }
@@ -1,48 +1,7 @@
1
1
  import DeviceInfo from 'react-native-device-info'
2
- import { Platform, PixelRatio, Dimensions, StatusBar } from 'react-native'
3
- import { initialWindowMetrics } from 'react-native-safe-area-context'
4
- import { successHandle, failHandle, defineUnsupportedProps, getFocusedNavigation } from '../../../common/js'
5
-
6
- const getWindowInfo = function () {
7
- const dimensionsScreen = Dimensions.get('screen')
8
- const navigation = getFocusedNavigation()
9
- const insets = {
10
- ...initialWindowMetrics?.insets,
11
- ...navigation?.insets
12
- }
13
- let safeArea = {}
14
- let { top = 0, bottom = 0, left = 0, right = 0 } = insets
15
- if (Platform.OS === 'android') {
16
- top = StatusBar.currentHeight || 0
17
- }
18
- const screenHeight = dimensionsScreen.height
19
- const screenWidth = dimensionsScreen.width
20
- const layout = navigation?.layout || {}
21
- const layoutHeight = layout.height || 0
22
- const layoutWidth = layout.width || 0
23
- const windowHeight = layoutHeight || screenHeight
24
- try {
25
- safeArea = {
26
- left,
27
- right: screenWidth - right,
28
- top,
29
- bottom: screenHeight - bottom,
30
- height: screenHeight - top - bottom,
31
- width: screenWidth - left - right
32
- }
33
- } catch (error) {
34
- }
35
- const result = {
36
- pixelRatio: PixelRatio.get(),
37
- windowWidth: layoutWidth || screenWidth,
38
- windowHeight, // 取不到layout的时候有个兜底
39
- screenWidth: screenWidth,
40
- screenHeight: screenHeight,
41
- screenTop: screenHeight - windowHeight,
42
- safeArea
43
- }
44
- return result
45
- }
2
+ import { PixelRatio } from 'react-native'
3
+ import { successHandle, failHandle, defineUnsupportedProps } from '../../../common/js'
4
+ import { getWindowInfo } from './rnWindowInfo'
46
5
 
47
6
  const getSystemInfoSync = function () {
48
7
  const windowInfo = getWindowInfo()
@@ -101,7 +60,7 @@ const getSystemInfo = function (options = {}) {
101
60
 
102
61
  const getDeviceInfo = function () {
103
62
  const deviceInfo = {}
104
- if (Platform.OS === 'android') {
63
+ if (__mpx_mode__ === 'android') {
105
64
  const deviceAbi = DeviceInfo.supported64BitAbisSync() || []
106
65
  deviceInfo.deviceAbi = deviceAbi[0] || null
107
66
  }
@@ -116,9 +75,26 @@ const getDeviceInfo = function () {
116
75
  return deviceInfo
117
76
  }
118
77
 
78
+ const getLaunchOptionsSync = function () {
79
+ const options = global.__mpxEnterOptions || {}
80
+ const { path, scene, query } = options
81
+ return {
82
+ path,
83
+ scene,
84
+ query
85
+ }
86
+ }
87
+
88
+ const getEnterOptionsSync = function () {
89
+ const result = getLaunchOptionsSync()
90
+ return result
91
+ }
92
+
119
93
  export {
120
94
  getSystemInfo,
121
95
  getSystemInfoSync,
122
96
  getDeviceInfo,
123
- getWindowInfo
97
+ getWindowInfo,
98
+ getLaunchOptionsSync,
99
+ getEnterOptionsSync
124
100
  }
@@ -0,0 +1,42 @@
1
+ import { PixelRatio, Dimensions } from 'react-native'
2
+ import { initialWindowMetrics } from 'react-native-safe-area-context'
3
+ import { getFocusedNavigation } from '../../../common/js'
4
+
5
+ const getWindowInfo = function () {
6
+ const dimensionsScreen = Dimensions.get('screen')
7
+ const navigation = getFocusedNavigation()
8
+ const insets = Object.assign(initialWindowMetrics?.insets, navigation?.insets)
9
+ let safeArea = {}
10
+ const { top = 0, bottom = 0, left = 0, right = 0 } = insets
11
+ const screenHeight = dimensionsScreen.height
12
+ const screenWidth = dimensionsScreen.width
13
+ const layout = navigation?.layout || {}
14
+ const layoutHeight = layout.height || 0
15
+ const layoutWidth = layout.width || 0
16
+ const windowHeight = layoutHeight || screenHeight
17
+ try {
18
+ safeArea = {
19
+ left,
20
+ right: screenWidth - right,
21
+ top,
22
+ bottom: screenHeight - bottom,
23
+ height: screenHeight - top - bottom,
24
+ width: screenWidth - left - right
25
+ }
26
+ } catch (error) {
27
+ }
28
+ const result = {
29
+ pixelRatio: PixelRatio.get(),
30
+ windowWidth: layoutWidth || screenWidth,
31
+ windowHeight, // 取不到layout的时候有个兜底
32
+ screenWidth: screenWidth,
33
+ screenHeight: screenHeight,
34
+ screenTop: screenHeight - windowHeight,
35
+ safeArea
36
+ }
37
+ return result
38
+ }
39
+
40
+ export {
41
+ getWindowInfo
42
+ }
@@ -26,7 +26,7 @@ export * from './api/canvas'
26
26
  export * from './api/check-session'
27
27
 
28
28
  // setClipboardData, getClipboardData
29
- export * from './api/clipboard-data'
29
+ // export * from './api/clipboard-data'
30
30
 
31
31
  // createIntersectionObserver
32
32
  export * from './api/create-intersection-observer'
@@ -77,7 +77,7 @@ export * from './api/route'
77
77
  export * from './api/scan-code'
78
78
 
79
79
  // setScreenBrightness, getScreenBrightness
80
- export * from './api/screen-brightness'
80
+ // export * from './api/screen-brightness'
81
81
 
82
82
  // setNavigationBarTitle, setNavigationBarColor
83
83
  export * from './api/set-navigation-bar'
@@ -105,9 +105,6 @@ export * from './api/video'
105
105
  // onWindowResize, offWindowResize
106
106
  export * from './api/window'
107
107
 
108
- // getEnterOptionsSync
109
- export * from './api/lifecycle'
110
-
111
108
  // getLocation, openLocation, chooseLocation
112
109
  export * from './api/location'
113
110
 
@@ -1 +0,0 @@
1
- export * from './rnActionSheet'
@@ -1 +0,0 @@
1
- export * from './index.ios'
@@ -1 +0,0 @@
1
- export * from './index.web'
@@ -1 +0,0 @@
1
- export * from './index.web'
@@ -1 +0,0 @@
1
- export * from './rnClipboard'
@@ -1 +0,0 @@
1
- export * from './index.ios'
@@ -1 +0,0 @@
1
- export * from './rnNetwork'
@@ -1 +0,0 @@
1
- export * from './index'
@@ -1,9 +0,0 @@
1
- import { ENV_OBJ } from '../../../common/js'
2
-
3
- function getEnterOptionsSync () {
4
- return ENV_OBJ.getEnterOptionsSync()
5
- }
6
-
7
- export {
8
- getEnterOptionsSync
9
- }
@@ -1,7 +0,0 @@
1
- import { ENV_OBJ, envError } from '../../../common/js'
2
-
3
- const getEnterOptionsSync = ENV_OBJ.getEnterOptionsSync || envError('getEnterOptionsSync')
4
-
5
- export {
6
- getEnterOptionsSync
7
- }
@@ -1,12 +0,0 @@
1
- import { isBrowser, throwSSRWarning } from '../../../common/js'
2
- function getEnterOptionsSync () {
3
- if (!isBrowser) {
4
- throwSSRWarning('getEnterOptionsSync API is running in non browser environments')
5
- return
6
- }
7
- return global.__mpxEnterOptions || {}
8
- }
9
-
10
- export {
11
- getEnterOptionsSync
12
- }
@@ -1 +0,0 @@
1
- export * from './index.ios'
@@ -1 +0,0 @@
1
- export * from './rnMakePhone'
@@ -1 +0,0 @@
1
- export * from './rnModal'
@@ -1 +0,0 @@
1
- export * from './index.ali'
@@ -1 +0,0 @@
1
- export * from './index.web'
@@ -1 +0,0 @@
1
- export * from './index.ios'
@@ -1 +0,0 @@
1
- export * from './rnScreenBrightness'
@@ -1 +0,0 @@
1
- export * from './index.ios'
@@ -1 +0,0 @@
1
- export * from './index.web'
@@ -1 +0,0 @@
1
- export * from './rnStorage'
@@ -1 +0,0 @@
1
- export * from './rnSystem'
@@ -1 +0,0 @@
1
- export * from './rnToast'
@@ -1 +0,0 @@
1
- export * from './index.ios'
@@ -1 +0,0 @@
1
- export * from './rnWindow'