@wapri/gjsbridge 5.0.0 → 5.0.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/LICENSE +21 -21
- package/README.md +7 -0
- package/dist/core/bridgeCB.js +13 -13
- package/dist/core/index.js +17 -17
- package/dist/index.js +7 -7
- package/dist/registers/canIUse/demo/index.vue +36 -36
- package/dist/registers/index.js +4 -4
- package/dist/utils/index.js +4 -4
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 wapri contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wapri contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/core/bridgeCB.js
CHANGED
|
@@ -31,11 +31,11 @@ export var BridgeCB = /*#__PURE__*/function () {
|
|
|
31
31
|
_createClass(BridgeCB, [{
|
|
32
32
|
key: "call",
|
|
33
33
|
value:
|
|
34
|
-
/**
|
|
35
|
-
* 创建一个等待 Native 响应的事务,并通过 transport 发送请求。
|
|
36
|
-
*
|
|
37
|
-
* @param options 本次 Native 调用的执行配置。
|
|
38
|
-
* @returns code 为 0 时解析 data,否则以携带 Native code 的 BridgeError 拒绝。
|
|
34
|
+
/**
|
|
35
|
+
* 创建一个等待 Native 响应的事务,并通过 transport 发送请求。
|
|
36
|
+
*
|
|
37
|
+
* @param options 本次 Native 调用的执行配置。
|
|
38
|
+
* @returns code 为 0 时解析 data,否则以携带 Native code 的 BridgeError 拒绝。
|
|
39
39
|
*/
|
|
40
40
|
function call(method, params, transport, options) {
|
|
41
41
|
var _this2 = this;
|
|
@@ -64,10 +64,10 @@ export var BridgeCB = /*#__PURE__*/function () {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
/**
|
|
68
|
-
* 订阅指定 Native 事件。
|
|
69
|
-
*
|
|
70
|
-
* @returns 取消本次订阅的函数。
|
|
67
|
+
/**
|
|
68
|
+
* 订阅指定 Native 事件。
|
|
69
|
+
*
|
|
70
|
+
* @returns 取消本次订阅的函数。
|
|
71
71
|
*/
|
|
72
72
|
}, {
|
|
73
73
|
key: "on",
|
|
@@ -83,10 +83,10 @@ export var BridgeCB = /*#__PURE__*/function () {
|
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
/**
|
|
87
|
-
* 订阅一次指定 Native 事件,首次触发后自动取消。
|
|
88
|
-
*
|
|
89
|
-
* @returns 提前取消本次订阅的函数。
|
|
86
|
+
/**
|
|
87
|
+
* 订阅一次指定 Native 事件,首次触发后自动取消。
|
|
88
|
+
*
|
|
89
|
+
* @returns 提前取消本次订阅的函数。
|
|
90
90
|
*/
|
|
91
91
|
}, {
|
|
92
92
|
key: "once",
|
package/dist/core/index.js
CHANGED
|
@@ -40,11 +40,11 @@ export var JSBNative = /*#__PURE__*/function () {
|
|
|
40
40
|
this.config.debug = debug;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
/**
|
|
44
|
-
* 将业务方法及参数交给当前 WebView 容器的 Native 通道。
|
|
45
|
-
*
|
|
46
|
-
* @param options 本次 Native 调用的执行配置。
|
|
47
|
-
* @returns Native 成功响应中的 data。
|
|
43
|
+
/**
|
|
44
|
+
* 将业务方法及参数交给当前 WebView 容器的 Native 通道。
|
|
45
|
+
*
|
|
46
|
+
* @param options 本次 Native 调用的执行配置。
|
|
47
|
+
* @returns Native 成功响应中的 data。
|
|
48
48
|
*/
|
|
49
49
|
}, {
|
|
50
50
|
key: "callNative",
|
|
@@ -76,10 +76,10 @@ export var JSBNative = /*#__PURE__*/function () {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
/**
|
|
80
|
-
* 检查 Native 通道是否已注入到当前页面。
|
|
81
|
-
*
|
|
82
|
-
* @returns `true` 表示 Android/鸿蒙或 iOS 的 Native 通道已挂载。
|
|
79
|
+
/**
|
|
80
|
+
* 检查 Native 通道是否已注入到当前页面。
|
|
81
|
+
*
|
|
82
|
+
* @returns `true` 表示 Android/鸿蒙或 iOS 的 Native 通道已挂载。
|
|
83
83
|
*/
|
|
84
84
|
}, {
|
|
85
85
|
key: "webReady",
|
|
@@ -101,14 +101,14 @@ export var JSBNative = /*#__PURE__*/function () {
|
|
|
101
101
|
bridgeWindow.onNativeEvent = this.cb.onNativeEvent;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
/**
|
|
105
|
-
* 按业务方法获取 iOS 消息通道,未注入时回退到 Android/鸿蒙通道。
|
|
106
|
-
*
|
|
107
|
-
* iOS 使用 `webkit.messageHandlers[method]`,报文中不重复携带 method;
|
|
108
|
-
* Android/鸿蒙使用 `window[nativeChannel].handle`,报文中携带完整请求。
|
|
109
|
-
*
|
|
110
|
-
* @param method 本次调用对应的 Native 方法名。
|
|
111
|
-
* @returns 可调用的 Native 消息发送函数;容器未注入时返回 undefined。
|
|
104
|
+
/**
|
|
105
|
+
* 按业务方法获取 iOS 消息通道,未注入时回退到 Android/鸿蒙通道。
|
|
106
|
+
*
|
|
107
|
+
* iOS 使用 `webkit.messageHandlers[method]`,报文中不重复携带 method;
|
|
108
|
+
* Android/鸿蒙使用 `window[nativeChannel].handle`,报文中携带完整请求。
|
|
109
|
+
*
|
|
110
|
+
* @param method 本次调用对应的 Native 方法名。
|
|
111
|
+
* @returns 可调用的 Native 消息发送函数;容器未注入时返回 undefined。
|
|
112
112
|
*/
|
|
113
113
|
}, {
|
|
114
114
|
key: "getNativeTransport",
|
package/dist/index.js
CHANGED
|
@@ -16,13 +16,13 @@ export { DEFAULT_JSBRIDGE_CONFIG } from "./core";
|
|
|
16
16
|
var EVENT_METHODS = new Set(['on', 'once', 'off']);
|
|
17
17
|
var INTERNAL_METHODS = new Set(['handle', 'ready', 'request', 'callNative', 'onNativeMessage', 'onNativeEvent', 'installNativeCallbacks', 'cb']);
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* 创建并缓存业务侧唯一的 Bridge 代理。
|
|
21
|
-
*
|
|
22
|
-
* 代理会将未注册的属性访问转换为 Native 方法调用,同时屏蔽底层通道与回调实现。
|
|
23
|
-
* Native 通道名(`nativeChannel`)与缓存键(`globalKey`)由业务传入,库内只提供通用默认值。
|
|
24
|
-
*
|
|
25
|
-
* @param config 本次创建的运行时配置,只需传要覆盖的字段。
|
|
19
|
+
/**
|
|
20
|
+
* 创建并缓存业务侧唯一的 Bridge 代理。
|
|
21
|
+
*
|
|
22
|
+
* 代理会将未注册的属性访问转换为 Native 方法调用,同时屏蔽底层通道与回调实现。
|
|
23
|
+
* Native 通道名(`nativeChannel`)与缓存键(`globalKey`)由业务传入,库内只提供通用默认值。
|
|
24
|
+
*
|
|
25
|
+
* @param config 本次创建的运行时配置,只需传要覆盖的字段。
|
|
26
26
|
*/
|
|
27
27
|
export var createJSB = function createJSB() {
|
|
28
28
|
var _config$globalKey;
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
<script lang="tsx">
|
|
2
|
-
import { defineComponent, ref } from 'vue'
|
|
3
|
-
import { jsbridge } from '@wapri/gjsbridge'
|
|
4
|
-
|
|
5
|
-
export default defineComponent({
|
|
6
|
-
setup(props) {
|
|
7
|
-
const result = ref('')
|
|
8
|
-
const errors = ref('')
|
|
9
|
-
const handleClick = () => {
|
|
10
|
-
jsbridge
|
|
11
|
-
.canIUse({ api: 'debug.demp' })
|
|
12
|
-
.then((res) => {
|
|
13
|
-
result.value = JSON.stringify(res)
|
|
14
|
-
})
|
|
15
|
-
.catch((error) => {
|
|
16
|
-
errors.value = error.message
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
return () => {
|
|
20
|
-
return (
|
|
21
|
-
<div>
|
|
22
|
-
<div>
|
|
23
|
-
<strong>result:</strong>
|
|
24
|
-
{result.value}
|
|
25
|
-
</div>
|
|
26
|
-
<div>
|
|
27
|
-
<strong>error:</strong>
|
|
28
|
-
{errors.value}
|
|
29
|
-
</div>
|
|
30
|
-
<button onClick={handleClick}>点击</button>
|
|
31
|
-
</div>
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
})
|
|
36
|
-
</script>
|
|
1
|
+
<script lang="tsx">
|
|
2
|
+
import { defineComponent, ref } from 'vue'
|
|
3
|
+
import { jsbridge } from '@wapri/gjsbridge'
|
|
4
|
+
|
|
5
|
+
export default defineComponent({
|
|
6
|
+
setup(props) {
|
|
7
|
+
const result = ref('')
|
|
8
|
+
const errors = ref('')
|
|
9
|
+
const handleClick = () => {
|
|
10
|
+
jsbridge
|
|
11
|
+
.canIUse({ api: 'debug.demp' })
|
|
12
|
+
.then((res) => {
|
|
13
|
+
result.value = JSON.stringify(res)
|
|
14
|
+
})
|
|
15
|
+
.catch((error) => {
|
|
16
|
+
errors.value = error.message
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
return () => {
|
|
20
|
+
return (
|
|
21
|
+
<div>
|
|
22
|
+
<div>
|
|
23
|
+
<strong>result:</strong>
|
|
24
|
+
{result.value}
|
|
25
|
+
</div>
|
|
26
|
+
<div>
|
|
27
|
+
<strong>error:</strong>
|
|
28
|
+
{errors.value}
|
|
29
|
+
</div>
|
|
30
|
+
<button onClick={handleClick}>点击</button>
|
|
31
|
+
</div>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
</script>
|
package/dist/registers/index.js
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -5,10 +5,10 @@ export function getBridgeWindow() {
|
|
|
5
5
|
return isUndefined(bridgeWindow) ? undefined : bridgeWindow;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* 读取注入在 window 上的 Native 通道。
|
|
10
|
-
*
|
|
11
|
-
* 通道名由业务通过 `createJSB({ nativeChannel })` 指定,因此按索引动态取值。
|
|
8
|
+
/**
|
|
9
|
+
* 读取注入在 window 上的 Native 通道。
|
|
10
|
+
*
|
|
11
|
+
* 通道名由业务通过 `createJSB({ nativeChannel })` 指定,因此按索引动态取值。
|
|
12
12
|
*/
|
|
13
13
|
export function getNativeChannel(channel) {
|
|
14
14
|
var bridgeWindow = getBridgeWindow();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wapri/gjsbridge",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "App WebView JSBridge 封装",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"android",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"registry": "https://registry.npmjs.org/"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@wapri/gbase": "^2.0.
|
|
32
|
+
"@wapri/gbase": "^2.0.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@wapri/gbase": "^2.0.
|
|
35
|
+
"@wapri/gbase": "^2.0.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@wapri/gbase": "2.0.
|
|
38
|
+
"@wapri/gbase": "2.0.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {},
|
|
41
41
|
"scripts": {
|