@lemon-fe/mini-app 1.1.3 → 1.1.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.
@@ -2,7 +2,6 @@ export declare const GO_BACK = "GO_BACK";
2
2
  export declare const METHOD = "METHOD";
3
3
  export declare const METHOD_CALLBACK = "METHOD_CALLBACK";
4
4
  export declare const INIT_IFRAME = "INIT_IFRAME";
5
- export declare const LEMON_APP_EXTRA_PAYLOAD = "LEMON_APP_EXTRA_PAYLOAD";
6
5
  export declare const SCAN_CODE = "SCAN_CODE";
7
6
  export declare const EXIT = "EXIT";
8
7
  export declare const SET_STATUS_BAR_STYLE = "SET_STATUS_BAR_STYLE";
@@ -10,10 +9,10 @@ export declare const GET_USER_INFO = "GET_USER_INFO";
10
9
  export declare const GET_ACCESS_TOKEN = "GET_ACCESS_TOKEN";
11
10
  export declare const CHECK_ACCESS_TOKEN = "CHECK_ACCESS_TOKEN";
12
11
  export declare const SET_CAPSULE = "SET_CAPSULE";
13
- export declare const SET_EXTRA_PAYLOAD = "SET_EXTRA_PAYLOAD";
14
12
  export declare const SYNC_ROUTES = "SYNC_ROUTES";
15
13
  export declare const NEXT_ACTION = "NEXT_ACTION";
16
14
  export declare const REQUEST_PAYMENT = "REQUEST_PAYMENT";
17
15
  export declare const NAVIGATE = "NAVIGATE";
16
+ export declare const INJECT_OBJECT_JSON = "INJECT_OBJECT_JSON";
18
17
  export declare const ACTION_CONTINUE = "ACTION_CONTINUE";
19
18
  export declare const ACTION_CANCEL = "ACTION_CANCEL";
@@ -1,8 +1,7 @@
1
1
  export var GO_BACK = 'GO_BACK';
2
2
  export var METHOD = 'METHOD';
3
3
  export var METHOD_CALLBACK = 'METHOD_CALLBACK';
4
- export var INIT_IFRAME = 'INIT_IFRAME';
5
- export var LEMON_APP_EXTRA_PAYLOAD = 'LEMON_APP_EXTRA_PAYLOAD'; // methods
4
+ export var INIT_IFRAME = 'INIT_IFRAME'; // methods
6
5
 
7
6
  export var SCAN_CODE = 'SCAN_CODE';
8
7
  export var EXIT = 'EXIT';
@@ -11,11 +10,11 @@ export var GET_USER_INFO = 'GET_USER_INFO';
11
10
  export var GET_ACCESS_TOKEN = 'GET_ACCESS_TOKEN';
12
11
  export var CHECK_ACCESS_TOKEN = 'CHECK_ACCESS_TOKEN';
13
12
  export var SET_CAPSULE = 'SET_CAPSULE';
14
- export var SET_EXTRA_PAYLOAD = 'SET_EXTRA_PAYLOAD';
15
13
  export var SYNC_ROUTES = 'SYNC_ROUTES';
16
14
  export var NEXT_ACTION = 'NEXT_ACTION';
17
15
  export var REQUEST_PAYMENT = 'REQUEST_PAYMENT';
18
- export var NAVIGATE = 'NAVIGATE'; // actions
16
+ export var NAVIGATE = 'NAVIGATE';
17
+ export var INJECT_OBJECT_JSON = 'INJECT_OBJECT_JSON'; // actions
19
18
 
20
19
  export var ACTION_CONTINUE = 'ACTION_CONTINUE';
21
20
  export var ACTION_CANCEL = 'ACTION_CANCEL';
package/es/global.d.ts CHANGED
@@ -4,6 +4,7 @@ declare global {
4
4
  mini?: Partial<typeof bridge>;
5
5
  ReactNativeWebView?: {
6
6
  postMessage: (e: string) => void;
7
+ injectedObjectJson?: () => string;
7
8
  };
8
9
  }
9
10
  }
@@ -18,7 +19,15 @@ declare const bridge: {
18
19
  left: number;
19
20
  };
20
21
  };
21
- getExtraPayload(): any;
22
+ getExtraPayload(): {};
23
+ getMenuButtonBoundingClientRect(): {
24
+ bottom: number;
25
+ height: number;
26
+ left: number;
27
+ right: number;
28
+ top: number;
29
+ width: number;
30
+ };
22
31
  methodRegister(name: string, opts?: {
23
32
  success?: ((value: any) => void) | undefined;
24
33
  fail?: ((err: Error) => void) | undefined;
@@ -106,7 +115,15 @@ export declare const mini: {
106
115
  left: number;
107
116
  };
108
117
  };
109
- getExtraPayload: () => any;
118
+ getExtraPayload: () => {};
119
+ getMenuButtonBoundingClientRect: () => {
120
+ bottom: number;
121
+ height: number;
122
+ left: number;
123
+ right: number;
124
+ top: number;
125
+ width: number;
126
+ };
110
127
  methodRegister: (name: string, opts?: {
111
128
  success?: ((value: any) => void) | undefined;
112
129
  fail?: ((err: Error) => void) | undefined;
package/es/global.js CHANGED
@@ -4,14 +4,26 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { CHECK_ACCESS_TOKEN, EXIT, GET_ACCESS_TOKEN, GET_USER_INFO, INIT_IFRAME, LEMON_APP_EXTRA_PAYLOAD, METHOD, METHOD_CALLBACK, NAVIGATE, NEXT_ACTION, REQUEST_PAYMENT, SCAN_CODE, SET_CAPSULE, SET_EXTRA_PAYLOAD, SET_STATUS_BAR_STYLE, SYNC_ROUTES } from './constants';
8
- var whiteList = ['localhost', 'csp.nhsoft.cn', '127.0.0.1'];
7
+ import { CHECK_ACCESS_TOKEN, EXIT, GET_ACCESS_TOKEN, GET_USER_INFO, INIT_IFRAME, METHOD, METHOD_CALLBACK, NAVIGATE, NEXT_ACTION, REQUEST_PAYMENT, SCAN_CODE, SET_CAPSULE, SET_STATUS_BAR_STYLE, SYNC_ROUTES, INJECT_OBJECT_JSON } from './constants';
9
8
  var methods = {};
10
9
  var listeners = [];
11
10
  var methodID = 0;
11
+
12
+ function getInjectedObject(key, defaultValue) {
13
+ var _window$ReactNativeWe, _window$ReactNativeWe2;
14
+
15
+ var data = (_window$ReactNativeWe = window.ReactNativeWebView) === null || _window$ReactNativeWe === void 0 ? void 0 : (_window$ReactNativeWe2 = _window$ReactNativeWe.injectedObjectJson) === null || _window$ReactNativeWe2 === void 0 ? void 0 : _window$ReactNativeWe2.call(_window$ReactNativeWe);
16
+
17
+ if (data) {
18
+ return JSON.parse(data)[key] || defaultValue;
19
+ }
20
+
21
+ return defaultValue;
22
+ }
23
+
12
24
  var bridge = {
13
25
  getSystemInfoSync: function getSystemInfoSync() {
14
- return {
26
+ return getInjectedObject('systemInfo', {
15
27
  statusBarHeight: 0,
16
28
  pixelRatio: 1,
17
29
  safeArea: {
@@ -20,20 +32,30 @@ var bridge = {
20
32
  bottom: 0,
21
33
  left: 0
22
34
  }
23
- };
35
+ });
24
36
  },
25
37
  getExtraPayload: function getExtraPayload() {
26
- return JSON.parse(window.localStorage.getItem('LEMON_APP_EXTRA_PAYLOAD') || '{}');
38
+ return getInjectedObject('extraPayload', {});
39
+ },
40
+ getMenuButtonBoundingClientRect: function getMenuButtonBoundingClientRect() {
41
+ return getInjectedObject('menuButtonBoundingClientRect', {
42
+ bottom: 0,
43
+ height: 0,
44
+ left: 0,
45
+ right: 0,
46
+ top: 0,
47
+ width: 0
48
+ });
27
49
  },
28
50
  methodRegister: function methodRegister(name) {
29
- var _window$ReactNativeWe;
51
+ var _window$ReactNativeWe3;
30
52
 
31
53
  var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
32
54
  methods[methodID] = {
33
55
  success: opts.success,
34
56
  fail: opts.fail
35
57
  };
36
- (_window$ReactNativeWe = window.ReactNativeWebView) === null || _window$ReactNativeWe === void 0 ? void 0 : _window$ReactNativeWe.postMessage(JSON.stringify({
58
+ (_window$ReactNativeWe3 = window.ReactNativeWebView) === null || _window$ReactNativeWe3 === void 0 ? void 0 : _window$ReactNativeWe3.postMessage(JSON.stringify({
37
59
  type: METHOD,
38
60
  target: {
39
61
  id: methodID,
@@ -169,9 +191,13 @@ window.mini = mini;
169
191
  */
170
192
 
171
193
  if (new URLSearchParams(window.location.search).has('__APP_DEV_TOOLS__')) {
194
+ var _injectedObjectJson = '{}';
172
195
  window.ReactNativeWebView = {
173
196
  postMessage: function postMessage(e) {
174
197
  window.parent.postMessage(e, '*');
198
+ },
199
+ injectedObjectJson: function injectedObjectJson() {
200
+ return _injectedObjectJson;
175
201
  }
176
202
  };
177
203
  mini.loaded = true;
@@ -193,27 +219,23 @@ if (new URLSearchParams(window.location.search).has('__APP_DEV_TOOLS__')) {
193
219
  }
194
220
  }), '*');
195
221
  window.addEventListener('message', function (evt) {
196
- var result = /^(([^:\/\s]+):\/?\/?([^\/\s@]*@)?([^\/@:]*)?:?(\d+)?)?(\/[^?]*)?(\?([^#]*))?(#[\s\S]*)?$/.exec(evt.origin);
197
-
198
- if (result !== null && whiteList.includes(result[4])) {
199
- var action = evt.data;
222
+ var action = evt.data;
200
223
 
201
- switch (action.type) {
202
- case SET_EXTRA_PAYLOAD:
203
- window.localStorage.setItem(LEMON_APP_EXTRA_PAYLOAD, JSON.stringify(action.payload));
204
- break;
224
+ switch (action.type) {
225
+ case INJECT_OBJECT_JSON:
226
+ _injectedObjectJson = action.payload;
227
+ break;
205
228
 
206
- case METHOD_CALLBACK:
207
- var msg = action.payload;
229
+ case METHOD_CALLBACK:
230
+ var msg = action.payload;
208
231
 
209
- if (msg.type === 'success') {
210
- mini.methodSuccess(msg.id, msg.data);
211
- } else {
212
- mini.methodFail(msg.id, new Error(msg.data));
213
- }
232
+ if (msg.type === 'success') {
233
+ mini.methodSuccess(msg.id, msg.data);
234
+ } else {
235
+ mini.methodFail(msg.id, new Error(msg.data));
236
+ }
214
237
 
215
- default:
216
- }
238
+ default:
217
239
  }
218
240
  }, false);
219
241
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/mini-app",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "> TODO: description",
5
5
  "author": "鲁盛杰 <lusj@cnlemon.net>",
6
6
  "homepage": "",
@@ -31,5 +31,5 @@
31
31
  "react": "^17.0.2",
32
32
  "react-dom": "17.0.2"
33
33
  },
34
- "gitHead": "2301a8e638df65f17134fc3a58f0369ab2210c35"
34
+ "gitHead": "bce0029c1f3fa1ad3c714a92a7764db5329a81c1"
35
35
  }