hylid-bridge 1.0.0 → 1.0.4

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/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  > Unite Api For AliPay Plus MiniProgram Project.
4
4
 
5
+ ## Description
6
+
7
+ For mini programs that are launched to different native apps, they run on different containers. The JSAPIs that these mini programs can call may vary. This package can solve this problem.
8
+
5
9
  ## Install
6
10
 
7
11
  ```bash
@@ -26,9 +30,153 @@ Page({
26
30
  });
27
31
  ```
28
32
 
33
+ refer: [AliPay Plus JSAPI Overview](https://miniprogram.alipay.com/docs/miniprogram/mpdev/api_overview)
34
+
35
+ ### Use in Plain HTML
36
+
37
+ ```html
38
+ <!DOCTYPE html>
39
+ <html>
40
+ <head>
41
+ <script src="https://cdn.marmot-cloud.com/page/hylid-bridge/umd/1.0.0/index.js"></script>
42
+ </head>
43
+ <body>
44
+ <script>
45
+ my.alert({
46
+ content: 'hylid-bridge',
47
+ });
48
+ </script>
49
+ </body>
50
+ </html>
51
+ ```
52
+
53
+ refer: [How to transform an HTML 5 mobile app to an HTML 5 mini program](https://miniprogram.alipay.com/docs/miniprogram/platform/transform-html5)
54
+
29
55
  ## API
30
56
 
31
- Please refer [our website](https://miniprogram.alipay.com/docs/miniprogram/mpdev/api_api-reference) for more detail.
57
+ The following table lists the latest JSAPIs that are supported in JS bridge, and the API list will be constantly updated.
58
+
59
+ ### MiniProgram
60
+
61
+ > - alert
62
+ > - clearStorage
63
+ > - clearStorageSync
64
+ > - confirm
65
+ > - createAnimation
66
+ > - createWebViewContext
67
+ > - crossPay
68
+ > - getAuthCode
69
+ > - getClipboard
70
+ > - getLocation
71
+ > - getNetworkType
72
+ > - getOpenUserInfo
73
+ > - getStorage
74
+ > - getStorageSync
75
+ > - getSystemInfo
76
+ > - getAppIdSync
77
+ > - hideBackHome
78
+ > - hideKeyboard
79
+ > - hideLoading
80
+ > - hideTabBar
81
+ > - hideToast
82
+ > - navigateBack
83
+ > - navigateTo
84
+ > - offMemoryWarning
85
+ > - onMemoryWarning
86
+ > - pageScrollTo
87
+ > - prompt
88
+ > - redirectTo
89
+ > - reLaunch
90
+ > - removeStorage
91
+ > - removeStorageSync
92
+ > - request
93
+ > - scan
94
+ > - setBackgroundColor
95
+ > - setCanPullDown
96
+ > - setClipboard
97
+ > - setNavigationBar
98
+ > - setStorage
99
+ > - setStorageSync
100
+ > - setTabBarStyle
101
+ > - showActionSheet
102
+ > - showAuthGuide
103
+ > - showLoading
104
+ > - showToast
105
+ > - startPullDownRefresh
106
+ > - stopPullDownRefresh
107
+ > - switchTab
108
+ > - tradePay
109
+
110
+ ### HTML5 MiniProgram
111
+
112
+ > - addFatigueAction
113
+ > - alert
114
+ > - apDisableJSAPI
115
+ > - appxrpc
116
+ > - APRegionRPC
117
+ > - batchQueryCdpSpaceInfo
118
+ > - chooseImage
119
+ > - choosePhoneContact
120
+ > - clearStorage
121
+ > - confirm
122
+ > - crossPay
123
+ > - exitApp
124
+ > - getAppToken
125
+ > - getAuthCode
126
+ > - getClipboard
127
+ > - getComponentAuth
128
+ > - getImageInfo
129
+ > - getLocation
130
+ > - getNetworkType
131
+ > - getAppIdSync
132
+ > - getPaymentCode
133
+ > - getPhoneNumber
134
+ > - getServerTime
135
+ > - getSetting
136
+ > - getSiteInfo
137
+ > - getStorage
138
+ > - getSystemInfo
139
+ > - hideKeyboard
140
+ > - hideLoading
141
+ > - hideNavigationBarLoading
142
+ > - hideToast
143
+ > - inquireQuote
144
+ > - isInstalledApp
145
+ > - makePhoneCall
146
+ > - multiLevelSelect
147
+ > - navigateBack
148
+ > - navigateBackMiniProgram
149
+ > - navigateTo
150
+ > - navigateToBizScene
151
+ > - navigateToMiniProgram
152
+ > - openSchemeWithBacking
153
+ > - paySignCenter
154
+ > - previewImage
155
+ > - prompt
156
+ > - redirectTo
157
+ > - regionFetchAllApps
158
+ > - regionSearchAppsByKeywords
159
+ > - reLaunch
160
+ > - removeStorage
161
+ > - request
162
+ > - rpc
163
+ > - saveImage
164
+ > - scan
165
+ > - setClipboard
166
+ > - setNavigationBar
167
+ > - setOptionMenu
168
+ > - setStorage
169
+ > - showAuthGuide
170
+ > - showLoading
171
+ > - showNavigationBarLoading
172
+ > - showToast
173
+ > - signContract
174
+ > - startApp
175
+ > - startBizService
176
+ > - thirdPartyAuthForAc
177
+ > - tradePay
178
+ > - uploadApdidToken
179
+ > - vibrate
32
180
 
33
181
  ## License
34
182
 
package/lib/appEnv.d.ts CHANGED
@@ -6,5 +6,7 @@ interface AppEnv {
6
6
  isMpWebIntl: boolean;
7
7
  isMpWebCn: boolean;
8
8
  }
9
- declare const _default: AppEnv;
10
- export default _default;
9
+ declare let appEnv: AppEnv;
10
+ declare function setAppEnv(config: AppEnv | (() => AppEnv)): void;
11
+ export default appEnv;
12
+ export { appEnv, setAppEnv };
package/lib/appEnv.js CHANGED
@@ -1,5 +1,10 @@
1
- import { callbackFn, loadAppxBridge, upFirst } from './common/utils';
1
+ import { upFirst } from './common/utils';
2
+ import initMpWebChannel from './common/init-mp-web-channel';
2
3
  var clientType = [{
4
+ name: 'mp_web_intl',
5
+ regs: [/alipayIDE/i],
6
+ type: 'ua'
7
+ }, {
3
8
  name: 'web_cn',
4
9
  regs: [/^((?!miniprogram).)*$/i, /alipay/i],
5
10
  type: 'ua'
@@ -53,43 +58,22 @@ function getEnv() {
53
58
  return clientType.reduce(function (result, _a) {
54
59
  var name = _a.name;
55
60
  var key = 'is' + name.split('_').map(upFirst).join('');
56
- result[key] = name === client;
61
+ var current = name === client;
62
+ result[key] = current;
63
+ if (current) console.log("Note: your code is running at " + key);
57
64
  return result;
58
65
  }, {});
59
66
  }
60
67
 
61
68
  var appEnv = getEnv();
62
69
 
63
- if (appEnv.isMpWebCn || appEnv.isMpWebIntl) {
64
- var env_1 = window;
65
- var originalMessageHandler_1;
66
-
67
- var handleMiniProgramAPIMessage_1 = function handleMiniProgramAPIMessage_1(message) {
68
- var serialId = message.serialId;
69
- var data = message.result;
70
-
71
- if (serialId) {
72
- var callback = env_1.miniProgramAPICallbackArray[serialId];
73
- callbackFn(data, callback);
74
- delete env_1.miniProgramAPICallbackArray[serialId];
75
- } else if (originalMessageHandler_1) {
76
- originalMessageHandler_1 === null || originalMessageHandler_1 === void 0 ? void 0 : originalMessageHandler_1(message);
77
- }
78
- };
70
+ function setAppEnv(config) {
71
+ appEnv = typeof config === 'function' ? config() : config;
79
72
 
80
- env_1.miniProgramAPICallbackArray = {};
81
- env_1.JSBRIDGE_WAITING_QUEUE = [];
82
- loadAppxBridge(function () {
83
- if (env_1.my.onMessage) {
84
- originalMessageHandler_1 = env_1.my.onMessage;
85
- }
86
-
87
- env_1.my.onMessage = function (message) {
88
- handleMiniProgramAPIMessage_1(message);
89
- };
90
-
91
- Object.assign(my, appEnv.isMpWebCn ? require('./clients/mp-web/cn') : require('./clients/mp-web/intl'));
92
- });
73
+ if (appEnv.isMpWebCn || appEnv.isMpWebIntl) {
74
+ initMpWebChannel();
75
+ }
93
76
  }
94
77
 
95
- export default appEnv;
78
+ export default appEnv;
79
+ export { appEnv, setAppEnv };