@mpxjs/api-proxy 2.9.67 → 2.9.70-alpha.0

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 (37) hide show
  1. package/package.json +3 -4
  2. package/src/common/js/ToPromise.js +25 -0
  3. package/src/common/js/index.js +1 -0
  4. package/src/common/js/utils.js +11 -1
  5. package/src/common/stylus/Modal.tenon.styl +42 -0
  6. package/src/common/stylus/Toast.tenon.styl +56 -0
  7. package/src/index.tenon.js +27 -0
  8. package/src/platform/api/animation/animation.tenon.js +225 -0
  9. package/src/platform/api/animation/index.tenon.js +89 -0
  10. package/src/platform/api/create-selector-query/rnNodesRef.js +1 -6
  11. package/src/platform/api/event-channel/index.tenon.js +52 -0
  12. package/src/platform/api/modal/index.tenon.js +12 -0
  13. package/src/platform/api/modal/tenonModal.js +154 -0
  14. package/src/platform/api/next-tick/index.ios.js +7 -1
  15. package/src/platform/api/next-tick/index.tenon.js +11 -0
  16. package/src/platform/api/request/index.tenon.js +85 -0
  17. package/src/platform/api/request/tenonUtil.js +0 -0
  18. package/src/platform/api/route/index.ios.js +18 -8
  19. package/src/platform/api/route/index.tenon.js +121 -0
  20. package/src/platform/api/set-navigation-bar/index.tenon.js +17 -0
  21. package/src/platform/api/socket/SocketTask.tenon.js +105 -0
  22. package/src/platform/api/socket/index.tenon.js +48 -0
  23. package/src/platform/api/storage/index.tenon.js +144 -0
  24. package/src/platform/api/storage/index.web.js +1 -1
  25. package/src/platform/api/storage/rnStorage.js +1 -1
  26. package/src/platform/api/system/index.ali.js +7 -1
  27. package/src/platform/api/system/index.js +7 -1
  28. package/src/platform/api/system/index.tenon.js +52 -0
  29. package/src/platform/api/system/index.web.js +77 -16
  30. package/src/platform/api/system/rnSystem.js +21 -5
  31. package/src/platform/api/toast/Toast.tenon.js +101 -0
  32. package/src/platform/api/toast/index.tenon.js +36 -0
  33. package/src/platform/index.js +0 -3
  34. package/LICENSE +0 -433
  35. package/src/platform/api/lifecycle/index.ali.js +0 -9
  36. package/src/platform/api/lifecycle/index.js +0 -7
  37. package/src/platform/api/lifecycle/index.web.js +0 -12
@@ -0,0 +1,144 @@
1
+ import { successHandle, failHandle, warn } from '../../../common/js'
2
+ import { hasOwn } from '@mpxjs/utils'
3
+ const { Storage } = __GLOBAL__
4
+
5
+ function setStorage (options = {}) {
6
+ const { key, data, success, fail, complete } = options
7
+
8
+ try {
9
+ setStorageSync(key, data)
10
+
11
+ const res = { errMsg: 'setStorage:ok' }
12
+ successHandle(res, success, complete)
13
+ return Promise.resolve(res)
14
+ } catch (err) {
15
+ const res = { errMsg: `setStorage:fail ${err}` }
16
+ failHandle(res, fail, complete)
17
+ return Promise.reject(res)
18
+ }
19
+ }
20
+
21
+ function setStorageSync (key = '', data) {
22
+ let obj = {}
23
+
24
+ if (typeof data === 'symbol') {
25
+ obj = { data: '' }
26
+ } else {
27
+ obj = { data }
28
+ }
29
+ Storage.set(key, JSON.stringify(obj))
30
+ }
31
+
32
+ function getStorage (options = {}) {
33
+ const { key, success, fail, complete } = options
34
+ const { result, data } = getItem(key)
35
+
36
+ if (result) {
37
+ const res = { errMsg: 'getStorage:ok', data: data }
38
+ successHandle(res, success, complete)
39
+ return Promise.resolve(res)
40
+ } else {
41
+ const res = { errMsg: 'getStorage:fail', data: null }
42
+ failHandle(res, fail, complete)
43
+ return Promise.reject(res)
44
+ }
45
+ }
46
+
47
+ function getStorageSync (key) {
48
+ const res = getItem(key)
49
+ if (res.result) return res.data
50
+
51
+ return ''
52
+ }
53
+
54
+ function getItem (key) {
55
+ let item
56
+ try {
57
+ item = JSON.parse(Storage.get(key))
58
+ } catch (e) {}
59
+
60
+ if (item && typeof item === 'object' && hasOwn(item, 'data')) {
61
+ return { result: true, data: item.data }
62
+ } else {
63
+ return { result: false }
64
+ }
65
+ }
66
+
67
+ function getStorageInfo (options = {}) {
68
+ const { success, fail, complete } = options
69
+
70
+ try {
71
+ const info = getStorageInfoSync()
72
+
73
+ const res = Object.assign({}, { errMsg: 'getStorageInfo:ok' }, info)
74
+ successHandle(res, success, complete)
75
+ return Promise.resolve(res)
76
+ } catch (err) {
77
+ const res = { errMsg: `getStorageInfo:fail ${err}` }
78
+ failHandle(res, fail, complete)
79
+ return Promise.reject(res)
80
+ }
81
+ }
82
+
83
+ function getStorageInfoSync () {
84
+ return {
85
+ keys: Object.keys(Storage),
86
+ limitSize: null,
87
+ currentSize: null
88
+ }
89
+ }
90
+
91
+ function removeStorage (options = { key: '' }) {
92
+ const { key, success, fail, complete } = options
93
+
94
+ try {
95
+ removeStorageSync(key)
96
+
97
+ const res = { errMsg: 'removeStorage:ok' }
98
+ successHandle(res, success, complete)
99
+ return Promise.resolve(res)
100
+ } catch (err) {
101
+ const res = { errMsg: `removeStorage:fail ${err}` }
102
+ failHandle(res, fail, complete)
103
+ return Promise.reject(res)
104
+ }
105
+ }
106
+
107
+ function removeStorageSync (key) {
108
+ Storage.remove(key)
109
+ }
110
+
111
+ function clearStorage (options = {}) {
112
+ warn('不支持clearStorageSync')
113
+ // const { success, fail, complete } = options
114
+
115
+ // try {
116
+ // clearStorageSync()
117
+
118
+ // const res = { errMsg: 'clearStorage:ok' }
119
+ // successHandle(res, success, complete)
120
+ // return Promise.resolve(res)
121
+ // } catch (err) {
122
+ // const res = { errMsg: `clearStorage:fail ${err}` }
123
+ // failHandle(res, fail, complete)
124
+ // return Promise.reject(res)
125
+ // }
126
+ }
127
+
128
+ function clearStorageSync () {
129
+ // Storage.clear()
130
+ warn('不支持clearStorageSync')
131
+ }
132
+
133
+ export {
134
+ setStorage,
135
+ setStorageSync,
136
+ getStorage,
137
+ getStorageSync,
138
+ getStorageInfo,
139
+ getStorageInfoSync,
140
+ removeStorage,
141
+ removeStorageSync,
142
+ clearStorage,
143
+ clearStorageSync
144
+ }
@@ -69,7 +69,7 @@ function getItem (key) {
69
69
  } catch (e) {
70
70
  }
71
71
 
72
- if (item && typeof item === 'object' && hasOwn(item, 'data')) {
72
+ if (hasOwn(item, 'data')) {
73
73
  return { result: true, data: item.data }
74
74
  } else {
75
75
  return { result: false }
@@ -49,7 +49,7 @@ function getStorage (options = {}) {
49
49
  item = JSON.parse(res)
50
50
  } catch (e) {
51
51
  }
52
- if (item && typeof item === 'object' && hasOwn(item, 'data')) {
52
+ if (hasOwn(item, 'data')) {
53
53
  data = item.data
54
54
  }
55
55
  const result = {
@@ -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
  }
@@ -0,0 +1,52 @@
1
+ import { successHandle } from '../../../common/js'
2
+ const { Hummer } = __GLOBAL__
3
+
4
+ function getSystemInfoSync () {
5
+ const {
6
+ platform,
7
+ osVersion,
8
+ deviceWidth,
9
+ deviceHeight,
10
+ availableWidth,
11
+ availableHeight,
12
+ safeAreaBottom
13
+ } = Hummer.env || {}
14
+ return {
15
+ brand: platform,
16
+ model: platform,
17
+ pixelRatio: null,
18
+ screenWidth: deviceWidth,
19
+ screenHeight: deviceHeight,
20
+ windowWidth: availableWidth,
21
+ windowHeight: availableHeight,
22
+ statusBarHeight: null,
23
+ language: null,
24
+ version: null,
25
+ system: platform + osVersion,
26
+ platform: platform,
27
+ fontSizeSetting: null,
28
+ SDKVersion: null,
29
+ benchmarkLevel: null,
30
+ albumAuthorized: null,
31
+ cameraAuthorized: null,
32
+ locationAuthorized: null,
33
+ microphoneAuthorized: null,
34
+ notificationAlertAuthorized: null,
35
+ notificationAuthorized: null,
36
+ notificationBadgeAuthorized: null,
37
+ notificationSoundAuthorized: null,
38
+ bluetoothEnabled: null,
39
+ locationEnabled: null,
40
+ wifiEnabled: null,
41
+ safeArea: safeAreaBottom
42
+ }
43
+ }
44
+
45
+ function getSystemInfo (options = {}) {
46
+ const info = getSystemInfoSync()
47
+ const res = Object.assign({ errMsg: 'getSystemInfo:ok' }, info)
48
+ successHandle(res, options.success, options.complete)
49
+ return Promise.resolve(res)
50
+ }
51
+
52
+ export { getSystemInfo, getSystemInfoSync }
@@ -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
  }
@@ -5,7 +5,7 @@ import { getWindowInfo } from './rnWindowInfo'
5
5
 
6
6
  const getSystemInfoSync = function () {
7
7
  const windowInfo = getWindowInfo()
8
- const { screenWidth, screenHeight, safeArea } = windowInfo
8
+ const { screenWidth, screenHeight } = windowInfo
9
9
 
10
10
  const result = {
11
11
  brand: DeviceInfo.getBrand(),
@@ -13,10 +13,9 @@ const getSystemInfoSync = function () {
13
13
  system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
14
14
  platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
15
15
  deviceOrientation: screenWidth > screenHeight ? 'portrait' : 'landscape',
16
- statusBarHeight: safeArea.top,
17
- fontSizeSetting: PixelRatio.getFontScale(),
18
- ...windowInfo
16
+ fontSizeSetting: PixelRatio.getFontScale()
19
17
  }
18
+ Object.assign(result, windowInfo)
20
19
  defineUnsupportedProps(result, [
21
20
  'language',
22
21
  'version',
@@ -75,9 +74,26 @@ const getDeviceInfo = function () {
75
74
  return deviceInfo
76
75
  }
77
76
 
77
+ const getLaunchOptionsSync = function () {
78
+ const options = global.__mpxEnterOptions || {}
79
+ const { path, scene, query } = options
80
+ return {
81
+ path,
82
+ scene,
83
+ query
84
+ }
85
+ }
86
+
87
+ const getEnterOptionsSync = function () {
88
+ const result = getLaunchOptionsSync()
89
+ return result
90
+ }
91
+
78
92
  export {
79
93
  getSystemInfo,
80
94
  getSystemInfoSync,
81
95
  getDeviceInfo,
82
- getWindowInfo
96
+ getWindowInfo,
97
+ getLaunchOptionsSync,
98
+ getEnterOptionsSync
83
99
  }
@@ -0,0 +1,101 @@
1
+ import { successHandle } from '../../../common/js'
2
+ import '../../../common/stylus/Toast.styl'
3
+
4
+ import { getClassStyle } from '@hummer/tenon-vue'
5
+
6
+ function createDom (Element, attrs = {}, children = []) {
7
+ const dom = new Element()
8
+ Object.keys(attrs).forEach(k => Reflect.set(dom, k, attrs[k]))
9
+ children.length && children.forEach(child => dom.appendChild(child))
10
+ return dom
11
+ }
12
+
13
+ export default class Toast {
14
+ constructor () {
15
+ this.defaultOpts = {
16
+ title: '',
17
+ icon: 'success',
18
+ image: '',
19
+ duration: 1500,
20
+ mask: false,
21
+ success: () => {},
22
+ fail: () => {},
23
+ complete: () => {}
24
+ }
25
+ this.dialog = null
26
+ this.hideTimer = null
27
+ this.type = null
28
+
29
+ // create & combine toast
30
+ this.toast = createDom(View, { style: getClassStyle(null, '__mpx_toast__') }, [
31
+ // todo 暂不支持 mask隐藏
32
+ // this.mask = createDom(View, { style: getClassStyle(null, '__mpx_mask__') }),
33
+ this.content = createDom(View, { style: getClassStyle(null, '__mpx_toast_box__') }, [
34
+ this.icon = createDom(View, { style: getClassStyle(null, '__mpx_toast_icon__') }),
35
+ this.title = createDom(Text, { style: getClassStyle(null, '__mpx_toast_title__') })
36
+ ])
37
+ ])
38
+ }
39
+
40
+ show (options, type) {
41
+ if (this.hideTimer) {
42
+ clearTimeout(this.hideTimer)
43
+ this.hideTimer = null
44
+ }
45
+
46
+ const opts = Object.assign({}, this.defaultOpts, options)
47
+
48
+ this.type = type
49
+
50
+ // if (opts.mask) {
51
+ // this.mask.class += 'show'
52
+ // } else {
53
+ // this.mask.classList.remove('show')
54
+ // }
55
+
56
+ // const defaultIconClass = '__mpx_toast_icon__'
57
+
58
+ const iconClass = opts.image
59
+ ? '' // image
60
+ : opts.icon === 'none'
61
+ ? '__hide_icon' // none
62
+ : opts.icon === 'error'
63
+ ? '__error_icon'
64
+ : '__success_icon' // default
65
+
66
+ // 在Hummer环境,Object.assign 有一些问题,需要重新进行一次赋值
67
+ this.icon.style = Object.assign(this.icon.style, getClassStyle(null, `${iconClass}`))
68
+
69
+ opts.image && (this.icon.style = Object.assign(this.icon.style, { backgroundImage: opts.image }))
70
+
71
+ this.title.text = opts.title || ''
72
+
73
+ this.dialog = new Dialog()
74
+ this.dialog.cancelable = false
75
+ opts.icon === 'loading'
76
+ ? this.dialog.loading(opts.title || 'loading...') // 空字符串也被过滤
77
+ : this.dialog.custom(this.toast)
78
+
79
+ opts.duration >= 0 && this.hide({ duration: opts.duration }, type)
80
+
81
+ const errMsg = type === 'loading' ? 'showLoading:ok' : 'showToast:ok'
82
+ successHandle({ errMsg }, opts.success, opts.complete)
83
+ return Promise.resolve({ errMsg })
84
+ }
85
+
86
+ hide (options = {}, type) {
87
+ if (this.type !== type) return
88
+
89
+ const duration = options.duration || 0
90
+ const errMsg = type === 'loading' ? 'hideLoading:ok' : 'hideToast:ok'
91
+ successHandle({ errMsg }, options.success, options.complete)
92
+
93
+ if (this.hideTimer) {
94
+ clearTimeout(this.hideTimer)
95
+ this.hideTimer = null
96
+ }
97
+
98
+ this.hideTimer = setTimeout(() => { this.dialog.dismiss() }, duration)
99
+ return Promise.resolve({ errMsg })
100
+ }
101
+ }
@@ -0,0 +1,36 @@
1
+ import Toast from './Toast'
2
+
3
+ let toast = null
4
+
5
+ function showToast (options = { title: '' }) {
6
+ if (!toast) { toast = new Toast() }
7
+ return toast.show(options, 'toast')
8
+ }
9
+
10
+ function hideToast (options = {}) {
11
+ if (!toast) { return }
12
+ return toast.hide(Object.assign({ duration: 0 }, options), 'toast')
13
+ }
14
+
15
+ function showLoading (options = { title: '' }) {
16
+ if (!toast) { toast = new Toast() }
17
+ return toast.show(Object.assign({
18
+ icon: 'loading',
19
+ duration: -1
20
+ }, options), 'loading')
21
+ }
22
+
23
+ function hideLoading (options = {}) {
24
+ if (!toast) { return }
25
+ return toast.hide(Object.assign({
26
+ icon: 'loading',
27
+ duration: 0
28
+ }, options), 'loading')
29
+ }
30
+
31
+ export {
32
+ showToast,
33
+ hideToast,
34
+ showLoading,
35
+ hideLoading
36
+ }
@@ -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