@hylid/call 3.2.6 → 3.3.0-alpha.1

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/lib/index.d.ts CHANGED
@@ -6,6 +6,7 @@ import { webCall } from './webCall';
6
6
  import { notFound } from './notFound';
7
7
  import { Config } from './types';
8
8
  export declare function call<T extends keyof MPApi>(name: T | ({} & string), options?: PickMPArgs<T> | Common | Callback<PickMpReturns<T>>, config?: Config): any;
9
+ export declare function createWebviewSrc(url: string): string;
9
10
  export { WebViewBridge } from './webviewBridge';
10
11
  export { mpCall, mpWebCall, webCall, notFound };
11
12
  export { promisify } from './promisify';
package/lib/index.js CHANGED
@@ -12,6 +12,19 @@ export function call(name, options, config) {
12
12
  return notFound(options, config);
13
13
  }
14
14
  }
15
+ export function createWebviewSrc(url) {
16
+ var app = my.getSystemInfoSync().app;
17
+ var hashIndex = url.indexOf('#');
18
+ var hash = '';
19
+ if (hashIndex !== -1) {
20
+ hash = url.slice(hashIndex);
21
+ url = url.slice(0, hashIndex);
22
+ }
23
+ var separator = url.includes('?') ? '&' : '?';
24
+ var newUrl = url + separator + '__app__=' + app + hash;
25
+ return newUrl;
26
+ }
27
+ ;
15
28
  export { WebViewBridge } from "./webviewBridge";
16
29
  export { mpCall, mpWebCall, webCall, notFound };
17
30
  export { promisify } from "./promisify";
package/lib/mpCall.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export function mpCall(apiName, options, config) {
2
2
  var _a = (config || {}).type,
3
3
  type = _a === void 0 ? 'async' : _a;
4
- if (type === 'sync') {
4
+ if (type === 'sync' || (config === null || config === void 0 ? void 0 : config.isSync)) {
5
5
  // @ts-ignore
6
6
  return my[apiName](options);
7
7
  }
@@ -19,4 +19,8 @@ export function mpCall(apiName, options, config) {
19
19
  // @ts-ignore
20
20
  my[apiName](options);
21
21
  }
22
+ if (type === 'attribute') {
23
+ // @ts-ignore
24
+ return my[apiName];
25
+ }
22
26
  }
package/lib/mpWebCall.js CHANGED
@@ -56,7 +56,8 @@ export function mpWebCall(api, options, config) {
56
56
  api: api,
57
57
  serialId: serialId,
58
58
  options: options,
59
- config: config
59
+ config: config,
60
+ isSync: config === null || config === void 0 ? void 0 : config.isSync
60
61
  };
61
62
  mpWebPostMessage(message);
62
63
  }
package/lib/types.d.ts CHANGED
@@ -2,6 +2,10 @@ import { JsApiType, MPApi, PickMPArgs, PickMpReturns } from '@hylid/types';
2
2
  export declare type JsApi = keyof MPApi;
3
3
  export interface JsApiConfig {
4
4
  type?: JsApiType;
5
+ /**
6
+ * @deprecated 优先使用 type = "sync" 配置
7
+ */
8
+ isSync?: boolean;
5
9
  }
6
10
  export declare type Config = JsApiConfig;
7
11
  export interface MpWebMessageResult<T = any> {
@@ -16,6 +20,10 @@ export interface MpWebJsApiMessage {
16
20
  options: any;
17
21
  config?: JsApiConfig;
18
22
  result?: MpWebMessageResult;
23
+ /**
24
+ * @deprecated 优先使用 config.type = "sync" 配置
25
+ */
26
+ isSync?: boolean;
19
27
  }
20
28
  export interface MpWebBroadcastMessage {
21
29
  source: 'hylid';
@@ -103,7 +103,7 @@ var WebViewBridge = /** @class */function () {
103
103
  });
104
104
  });
105
105
  } else {
106
- console.info("[hylid-call]: context \u5728\u5C0F\u7A0B\u5E8F\u4FA7\u672A\u4F20\u5165\uFF0Cbroadcast \u529F\u80FD\u3001\u9875\u9762\u76D1\u542C\u5C06\u65E0\u6CD5\u4F7F\u7528");
106
+ console.info("[hylid-call]: context is null, broadcast and pageEvent cannot be used");
107
107
  }
108
108
  }
109
109
  WebViewBridge.prototype.bindCtxEvent = function (event, callback) {
@@ -1 +1,3 @@
1
- export declare function _getCurrentPages(): any[];
1
+ export declare function _getCurrentPages(): {
2
+ route: any;
3
+ }[];
@@ -1,3 +1,8 @@
1
1
  export function _getCurrentPages() {
2
- return getCurrentPages();
2
+ var pages = getCurrentPages();
3
+ return pages.map(function (page) {
4
+ return {
5
+ route: page.route
6
+ };
7
+ });
3
8
  }
@@ -180,7 +180,7 @@ export var getApiResult = function getApiResult(jsapi, data) {
180
180
  return __generator(this, function (_b) {
181
181
  api = data.api, options = data.options, config = data.config;
182
182
  _a = (config || {}).type, type = _a === void 0 ? 'async' : _a;
183
- if (type === 'sync') {
183
+ if (type === 'sync' || data.isSync) {
184
184
  return [2 /*return*/, getSyncApi(api, jsapi, options)];
185
185
  }
186
186
  if (type === 'async') {
@@ -0,0 +1 @@
1
+ <web-view id="{{id}}" src="{{webviewSrc}}" onMessage="onMessage" onError="onError" onLoad="onLoad" />
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Component({
4
+ data: {
5
+ webviewSrc: ''
6
+ },
7
+ onInit: function onInit() {
8
+ this.setData({
9
+ webviewSrc: this.createWebviewSrc(this.props.src)
10
+ });
11
+ },
12
+ deriveDataFromProps: function deriveDataFromProps(nextProps) {
13
+ this.setData({
14
+ webviewSrc: this.createWebviewSrc(nextProps.src)
15
+ });
16
+ },
17
+ methods: {
18
+ createWebviewSrc: function createWebviewSrc(url) {
19
+ var app = my.getSystemInfoSync().app;
20
+ var hashIndex = url.indexOf('#');
21
+ var hash = '';
22
+ if (hashIndex !== -1) {
23
+ hash = url.slice(hashIndex);
24
+ url = url.slice(0, hashIndex);
25
+ }
26
+ var separator = url.includes('?') ? '&' : '?';
27
+ var newUrl = url + separator + '__app__=' + app + hash;
28
+ return newUrl;
29
+ },
30
+ onMessage: function onMessage(params) {
31
+ this.props.onMessage && this.props.onMessage(params);
32
+ },
33
+ onLoad: function onLoad(params) {
34
+ this.props.onLoad && this.props.onLoad(params);
35
+ },
36
+ onError: function onError(params) {
37
+ this.props.onError && this.props.onError(params);
38
+ }
39
+ }
40
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "component": true
3
+ }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@hylid/call",
3
- "version": "3.2.6",
3
+ "version": "3.3.0-alpha.1",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "lib"
7
7
  ],
8
8
  "dependencies": {
9
- "@hylid/env": "^3.2.6",
10
- "@hylid/types": "^3.2.6"
9
+ "@hylid/env": "^3.3.0-alpha.1",
10
+ "@hylid/types": "^3.3.0-alpha.1"
11
11
  },
12
12
  "publishConfig": {
13
13
  "access": "public"