@kbapp/js-bridge 1.0.0-alpha.0 → 1.0.2-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.
- package/README.MD +33 -38
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +83 -82
- package/dist/index.umd.js +1 -1
- package/dist/lib/env.d.ts +2 -0
- package/dist/lib/trigger-login.d.ts +4 -4
- package/package.json +3 -3
package/README.MD
CHANGED
|
@@ -26,10 +26,14 @@ npm i @kbapp/js-bridge
|
|
|
26
26
|
|
|
27
27
|
> 通过 script 标签引入后,SDK 将作为全局变量 `kbBridge` 挂载在 window 对象上
|
|
28
28
|
|
|
29
|
+
## 测试页面
|
|
30
|
+
|
|
31
|
+
[https://unpkg.com/@kbapp/js-bridge@latest/examples/index.html](https://unpkg.com/@kbapp/js-bridge@latest/examples/index.html)
|
|
32
|
+
|
|
29
33
|
## 示例
|
|
30
34
|
|
|
31
35
|
```js
|
|
32
|
-
import { saveImageToLocal
|
|
36
|
+
import { saveImageToLocal } from '@kbapp/js-bridge'
|
|
33
37
|
|
|
34
38
|
function saveImageHandle() {
|
|
35
39
|
saveImageToLocal({
|
|
@@ -58,16 +62,6 @@ async function saveImageHandle() {
|
|
|
58
62
|
}
|
|
59
63
|
```
|
|
60
64
|
|
|
61
|
-
## 测试页面
|
|
62
|
-
|
|
63
|
-
> 可以通过以下地址访问 SDK 的测试页面,查看所有 API 的使用示例
|
|
64
|
-
|
|
65
|
-
测试页面地址:
|
|
66
|
-
|
|
67
|
-
```
|
|
68
|
-
https://unpkg.com/@kbapp/js-bridge@latest/examples/index.html
|
|
69
|
-
```
|
|
70
|
-
|
|
71
65
|
## API
|
|
72
66
|
|
|
73
67
|
### 总览
|
|
@@ -104,7 +98,8 @@ https://unpkg.com/@kbapp/js-bridge@latest/examples/index.html
|
|
|
104
98
|
| 类/枚举 | 说明 |
|
|
105
99
|
| -------------------- | ---------------- |
|
|
106
100
|
| `BridgeCode` | kbapp 桥接状态码 |
|
|
107
|
-
| `
|
|
101
|
+
| `IS_KB_APP_ENV` | 是否在开吧 APP 环境中 |
|
|
102
|
+
| `AppLoginInfo` | 登录信息模型 |
|
|
108
103
|
| `AppShareModel` | 应用分享模型 |
|
|
109
104
|
| `AppBaseInfo` | 设备信息模型 |
|
|
110
105
|
|
|
@@ -141,7 +136,7 @@ checkForNewVersion({
|
|
|
141
136
|
})
|
|
142
137
|
```
|
|
143
138
|
|
|
144
|
-
> 支持 Promise
|
|
139
|
+
> 支持 Promise 风格调用
|
|
145
140
|
|
|
146
141
|
---
|
|
147
142
|
|
|
@@ -178,7 +173,7 @@ closeWebView({
|
|
|
178
173
|
})
|
|
179
174
|
```
|
|
180
175
|
|
|
181
|
-
> 支持 Promise
|
|
176
|
+
> 支持 Promise 风格调用
|
|
182
177
|
|
|
183
178
|
---
|
|
184
179
|
|
|
@@ -224,7 +219,7 @@ definePermissionUsage({
|
|
|
224
219
|
})
|
|
225
220
|
```
|
|
226
221
|
|
|
227
|
-
> 支持 Promise
|
|
222
|
+
> 支持 Promise 风格调用
|
|
228
223
|
|
|
229
224
|
---
|
|
230
225
|
|
|
@@ -298,7 +293,7 @@ defineAppShareModel({
|
|
|
298
293
|
})
|
|
299
294
|
```
|
|
300
295
|
|
|
301
|
-
> 支持 Promise
|
|
296
|
+
> 支持 Promise 风格调用
|
|
302
297
|
|
|
303
298
|
---
|
|
304
299
|
|
|
@@ -339,7 +334,7 @@ defineAppSharePanelState({
|
|
|
339
334
|
})
|
|
340
335
|
```
|
|
341
336
|
|
|
342
|
-
> 支持 Promise
|
|
337
|
+
> 支持 Promise 风格调用
|
|
343
338
|
|
|
344
339
|
---
|
|
345
340
|
|
|
@@ -382,7 +377,7 @@ generateKBSign({
|
|
|
382
377
|
})
|
|
383
378
|
```
|
|
384
379
|
|
|
385
|
-
> 支持 Promise
|
|
380
|
+
> 支持 Promise 风格调用
|
|
386
381
|
|
|
387
382
|
---
|
|
388
383
|
|
|
@@ -394,14 +389,14 @@ generateKBSign({
|
|
|
394
389
|
|
|
395
390
|
| 参数 | 类型 | 必填 | 说明 |
|
|
396
391
|
| ---------- | ----------------------------- | -------------- | -------- | -------- |
|
|
397
|
-
| `success` | `(res:
|
|
392
|
+
| `success` | `(res: AppLoginInfo | null) => void` | 否 | 成功回调 |
|
|
398
393
|
| `fail` | `(error: BridgeCode) => void` | 否 | 失败回调 |
|
|
399
394
|
| `complete` | `() => void` | 否 | 完成回调 |
|
|
400
395
|
|
|
401
396
|
#### 返回值
|
|
402
397
|
|
|
403
398
|
```js
|
|
404
|
-
Promise<
|
|
399
|
+
Promise<AppLoginInfo | null>
|
|
405
400
|
```
|
|
406
401
|
|
|
407
402
|
#### 示例代码
|
|
@@ -423,7 +418,7 @@ getAppLoginInfo({
|
|
|
423
418
|
})
|
|
424
419
|
```
|
|
425
420
|
|
|
426
|
-
> 支持 Promise
|
|
421
|
+
> 支持 Promise 风格调用
|
|
427
422
|
|
|
428
423
|
---
|
|
429
424
|
|
|
@@ -461,7 +456,7 @@ getAppBaseInfo({
|
|
|
461
456
|
})
|
|
462
457
|
```
|
|
463
458
|
|
|
464
|
-
> 支持 Promise
|
|
459
|
+
> 支持 Promise 风格调用
|
|
465
460
|
|
|
466
461
|
---
|
|
467
462
|
|
|
@@ -506,7 +501,7 @@ openAppSharePanel({
|
|
|
506
501
|
})
|
|
507
502
|
```
|
|
508
503
|
|
|
509
|
-
> 支持 Promise
|
|
504
|
+
> 支持 Promise 风格调用
|
|
510
505
|
|
|
511
506
|
---
|
|
512
507
|
|
|
@@ -568,7 +563,7 @@ openPostEditor({
|
|
|
568
563
|
})
|
|
569
564
|
```
|
|
570
565
|
|
|
571
|
-
> 支持 Promise
|
|
566
|
+
> 支持 Promise 风格调用
|
|
572
567
|
|
|
573
568
|
---
|
|
574
569
|
|
|
@@ -611,7 +606,7 @@ const stopHandle = onAppSharePanelShow(() => {
|
|
|
611
606
|
|
|
612
607
|
| 参数 | 类型 | 说明 |
|
|
613
608
|
| ---------- | ----------------------------------------- | ------------ |
|
|
614
|
-
| `callback` | `(loginInfo:
|
|
609
|
+
| `callback` | `(loginInfo: AppLoginInfo) => void` | 登录成功回调 |
|
|
615
610
|
|
|
616
611
|
#### 返回值
|
|
617
612
|
|
|
@@ -672,7 +667,7 @@ reportDAEvent({
|
|
|
672
667
|
})
|
|
673
668
|
```
|
|
674
669
|
|
|
675
|
-
> 支持 Promise
|
|
670
|
+
> 支持 Promise 风格调用
|
|
676
671
|
|
|
677
672
|
---
|
|
678
673
|
|
|
@@ -715,7 +710,7 @@ runAction({
|
|
|
715
710
|
})
|
|
716
711
|
```
|
|
717
712
|
|
|
718
|
-
> 支持 Promise
|
|
713
|
+
> 支持 Promise 风格调用
|
|
719
714
|
|
|
720
715
|
---
|
|
721
716
|
|
|
@@ -760,7 +755,7 @@ saveImageToLocal({
|
|
|
760
755
|
})
|
|
761
756
|
```
|
|
762
757
|
|
|
763
|
-
> 支持 Promise
|
|
758
|
+
> 支持 Promise 风格调用
|
|
764
759
|
|
|
765
760
|
---
|
|
766
761
|
|
|
@@ -805,7 +800,7 @@ saveVideoToLocal({
|
|
|
805
800
|
})
|
|
806
801
|
```
|
|
807
802
|
|
|
808
|
-
> 支持 Promise
|
|
803
|
+
> 支持 Promise 风格调用
|
|
809
804
|
|
|
810
805
|
---
|
|
811
806
|
|
|
@@ -842,7 +837,7 @@ scanQRCode({
|
|
|
842
837
|
})
|
|
843
838
|
```
|
|
844
839
|
|
|
845
|
-
> 支持 Promise
|
|
840
|
+
> 支持 Promise 风格调用
|
|
846
841
|
|
|
847
842
|
---
|
|
848
843
|
|
|
@@ -893,7 +888,7 @@ setScreenOrientation({
|
|
|
893
888
|
})
|
|
894
889
|
```
|
|
895
890
|
|
|
896
|
-
> 支持 Promise
|
|
891
|
+
> 支持 Promise 风格调用
|
|
897
892
|
|
|
898
893
|
---
|
|
899
894
|
|
|
@@ -938,7 +933,7 @@ setWebViewTitle({
|
|
|
938
933
|
})
|
|
939
934
|
```
|
|
940
935
|
|
|
941
|
-
> 支持 Promise
|
|
936
|
+
> 支持 Promise 风格调用
|
|
942
937
|
|
|
943
938
|
---
|
|
944
939
|
|
|
@@ -983,7 +978,7 @@ shareImage({
|
|
|
983
978
|
})
|
|
984
979
|
```
|
|
985
980
|
|
|
986
|
-
> 支持 Promise
|
|
981
|
+
> 支持 Promise 风格调用
|
|
987
982
|
|
|
988
983
|
---
|
|
989
984
|
|
|
@@ -1024,7 +1019,7 @@ subscribeNotify({
|
|
|
1024
1019
|
})
|
|
1025
1020
|
```
|
|
1026
1021
|
|
|
1027
|
-
> 支持 Promise
|
|
1022
|
+
> 支持 Promise 风格调用
|
|
1028
1023
|
|
|
1029
1024
|
---
|
|
1030
1025
|
|
|
@@ -1068,7 +1063,7 @@ triggerAppLogin({
|
|
|
1068
1063
|
})
|
|
1069
1064
|
```
|
|
1070
1065
|
|
|
1071
|
-
> 支持 Promise
|
|
1066
|
+
> 支持 Promise 风格调用
|
|
1072
1067
|
|
|
1073
1068
|
---
|
|
1074
1069
|
|
|
@@ -1107,16 +1102,16 @@ isAppVersionSupport({
|
|
|
1107
1102
|
})
|
|
1108
1103
|
```
|
|
1109
1104
|
|
|
1110
|
-
> 支持 Promise
|
|
1105
|
+
> 支持 Promise 风格调用
|
|
1111
1106
|
|
|
1112
1107
|
## 数据模型
|
|
1113
1108
|
|
|
1114
|
-
###
|
|
1109
|
+
### AppLoginInfo
|
|
1115
1110
|
|
|
1116
1111
|
> 登录信息模型
|
|
1117
1112
|
|
|
1118
1113
|
```js
|
|
1119
|
-
class
|
|
1114
|
+
class AppLoginInfo {
|
|
1120
1115
|
/** 车牌号:例如浙A999999 */
|
|
1121
1116
|
carNo?: string
|
|
1122
1117
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './lib/bridge-code';
|
|
|
4
4
|
export * from './lib/check-for-new-version';
|
|
5
5
|
export * from './lib/close-webview';
|
|
6
6
|
export * from './lib/define-permission-usage';
|
|
7
|
+
export * from './lib/env';
|
|
7
8
|
export * from './lib/generate-kb-sign';
|
|
8
9
|
export * from './lib/get-app-base-info';
|
|
9
10
|
export * from './lib/open-post-editor';
|
package/dist/index.es.js
CHANGED
|
@@ -85,27 +85,27 @@ const C = () => {
|
|
|
85
85
|
var a = JSON.parse(n.data), d = {
|
|
86
86
|
id: n.callbackId,
|
|
87
87
|
complete: !0
|
|
88
|
-
}, f = this._dsf[n.method],
|
|
89
|
-
d.data =
|
|
90
|
-
},
|
|
91
|
-
a.push(function(
|
|
92
|
-
d.data =
|
|
93
|
-
}),
|
|
88
|
+
}, f = this._dsf[n.method], A = this._dsaf[n.method], R = function(b, S) {
|
|
89
|
+
d.data = b.apply(S, a), i.callHandler("_dsb.returnValue", d);
|
|
90
|
+
}, T = function(b, S) {
|
|
91
|
+
a.push(function(V, U) {
|
|
92
|
+
d.data = V, d.complete = U !== !1, i.callHandler("_dsb.returnValue", d);
|
|
93
|
+
}), b.apply(S, a);
|
|
94
94
|
};
|
|
95
95
|
if (f)
|
|
96
|
-
|
|
97
|
-
else if (
|
|
98
|
-
|
|
96
|
+
R(f, this._dsf);
|
|
97
|
+
else if (A)
|
|
98
|
+
T(A, this._dsaf);
|
|
99
99
|
else {
|
|
100
|
-
var
|
|
101
|
-
if (
|
|
102
|
-
var
|
|
100
|
+
var v = n.method.split(".");
|
|
101
|
+
if (v.length < 2) return;
|
|
102
|
+
var E = v.pop(), k = v.join("."), m = this._dsf._obs, g = m[k] || {}, h = g[E];
|
|
103
103
|
if (h && typeof h == "function") {
|
|
104
|
-
|
|
104
|
+
R(h, g);
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
|
-
if (
|
|
108
|
-
|
|
107
|
+
if (m = this._dsaf._obs, g = m[k] || {}, h = g[E], h && typeof h == "function") {
|
|
108
|
+
T(h, g);
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -116,18 +116,18 @@ const C = () => {
|
|
|
116
116
|
}
|
|
117
117
|
}(), i;
|
|
118
118
|
};
|
|
119
|
-
var
|
|
120
|
-
const
|
|
119
|
+
var I;
|
|
120
|
+
const O = ((e) => /(kb)/i.test(e) ? C() : {
|
|
121
121
|
registerHandler(t, r) {
|
|
122
122
|
throw p.UNSUPPORTED_BRIDGE_ENV;
|
|
123
123
|
},
|
|
124
124
|
callHandler(t, r, i) {
|
|
125
125
|
throw p.UNSUPPORTED_BRIDGE_ENV;
|
|
126
126
|
}
|
|
127
|
-
})((
|
|
127
|
+
})((I = window == null ? void 0 : window.navigator) == null ? void 0 : I.userAgent), N = (e) => new Promise((t, r) => {
|
|
128
128
|
var i, o, s;
|
|
129
129
|
try {
|
|
130
|
-
|
|
130
|
+
O.registerHandler(e.name, e.handler), (i = e.success) == null || i.call(e), t();
|
|
131
131
|
} catch (n) {
|
|
132
132
|
(o = e.fail) == null || o.call(e, n), r(n);
|
|
133
133
|
} finally {
|
|
@@ -148,7 +148,7 @@ function w(e) {
|
|
|
148
148
|
s(p.TIMEOUT);
|
|
149
149
|
}, r.timeout);
|
|
150
150
|
try {
|
|
151
|
-
|
|
151
|
+
O.callHandler(r.name, r.params, (n) => {
|
|
152
152
|
let a;
|
|
153
153
|
try {
|
|
154
154
|
typeof n == "string" && /^\s*(\{|\[).*(\}|\])\s*$/.test(n) ? a = JSON.parse(n.replace(/\n/g, "\\n").replace(/\r/g, "\\r")) : a = n;
|
|
@@ -178,7 +178,7 @@ function w(e) {
|
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
180
|
function u(e) {
|
|
181
|
-
|
|
181
|
+
O.callHandler(e.name, e.params, (t) => {
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
function c(e) {
|
|
@@ -208,17 +208,17 @@ function M(e) {
|
|
|
208
208
|
}
|
|
209
209
|
class j {
|
|
210
210
|
}
|
|
211
|
-
const H =
|
|
212
|
-
|
|
211
|
+
const H = c(
|
|
212
|
+
M(() => w({
|
|
213
213
|
name: "OpenActRequest",
|
|
214
214
|
params: {
|
|
215
215
|
type: 35,
|
|
216
216
|
data: {}
|
|
217
217
|
}
|
|
218
218
|
}))
|
|
219
|
-
),
|
|
219
|
+
), L = c(async (e) => (await H()).vcode >= e.minVersion);
|
|
220
220
|
function B(e, t) {
|
|
221
|
-
return (...r) =>
|
|
221
|
+
return (...r) => L({
|
|
222
222
|
minVersion: e.minVersion
|
|
223
223
|
}).then((i) => i ? t(...r) : Promise.reject(
|
|
224
224
|
new p({
|
|
@@ -235,7 +235,7 @@ const J = c(() => {
|
|
|
235
235
|
data: null
|
|
236
236
|
}
|
|
237
237
|
});
|
|
238
|
-
}),
|
|
238
|
+
}), K = c(() => {
|
|
239
239
|
u({
|
|
240
240
|
name: "OpenActRequest",
|
|
241
241
|
params: {
|
|
@@ -243,16 +243,16 @@ const J = c(() => {
|
|
|
243
243
|
data: {}
|
|
244
244
|
}
|
|
245
245
|
});
|
|
246
|
-
}),
|
|
246
|
+
}), P = {
|
|
247
247
|
microphone: { description: "用于发帖上传音频" },
|
|
248
248
|
location: { description: "获取你选择的位置信息,用于线下导航服务" },
|
|
249
249
|
camera: { description: "收集你选中的照片或视频信息 ,用于 发表评论、分享视频" }
|
|
250
|
-
},
|
|
250
|
+
}, F = c((e) => (Object.assign(P, e), N({
|
|
251
251
|
name: "getPermissionUsage",
|
|
252
252
|
handler(t, r) {
|
|
253
|
-
r(
|
|
253
|
+
r(P[t.permission]);
|
|
254
254
|
}
|
|
255
|
-
}))), W = c(async (e) => {
|
|
255
|
+
}))), W = /(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent), G = c(async (e) => {
|
|
256
256
|
const { kbKey: t, ...r } = e, { data: i } = await w({
|
|
257
257
|
name: "OpenActRequest",
|
|
258
258
|
params: {
|
|
@@ -262,13 +262,13 @@ const J = c(() => {
|
|
|
262
262
|
});
|
|
263
263
|
return i;
|
|
264
264
|
});
|
|
265
|
-
class
|
|
265
|
+
class D {
|
|
266
266
|
constructor() {
|
|
267
267
|
this.enableImageUpload = !0, this.enableAudioUpload = !0, this.enableVideoUpload = !0, this.enableAddress = !0, this.enableMediaVideoUpload = !1, this.minTextLength = 0, this.maxTextLength = 1e3, this.minImageCount = 0, this.maxImageCount = 9, this.isAudioRequired = !1, this.isVideoRequired = !1, this.isMediaVideoRequired = !1;
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
function
|
|
271
|
-
const t = new
|
|
270
|
+
function $(e) {
|
|
271
|
+
const t = new D();
|
|
272
272
|
return e && Object.keys(e).forEach((i) => {
|
|
273
273
|
t[i] = e[i];
|
|
274
274
|
}), {
|
|
@@ -290,7 +290,7 @@ function G(e) {
|
|
|
290
290
|
asset_video_must: t.isMediaVideoRequired
|
|
291
291
|
};
|
|
292
292
|
}
|
|
293
|
-
const
|
|
293
|
+
const z = c(
|
|
294
294
|
async (e = {}) => w({
|
|
295
295
|
name: "OpenActRequest",
|
|
296
296
|
params: { type: 13, data: e }
|
|
@@ -298,7 +298,7 @@ const $ = c(
|
|
|
298
298
|
const { pic: r, ...i } = t;
|
|
299
299
|
return { images: r, ...i };
|
|
300
300
|
})
|
|
301
|
-
),
|
|
301
|
+
), Q = c(
|
|
302
302
|
(e) => {
|
|
303
303
|
u({
|
|
304
304
|
name: "OpenActRequest",
|
|
@@ -315,7 +315,7 @@ const $ = c(
|
|
|
315
315
|
}
|
|
316
316
|
});
|
|
317
317
|
}
|
|
318
|
-
),
|
|
318
|
+
), X = c((e) => {
|
|
319
319
|
u({
|
|
320
320
|
name: "OpenActRequest",
|
|
321
321
|
params: {
|
|
@@ -323,7 +323,7 @@ const $ = c(
|
|
|
323
323
|
data: e
|
|
324
324
|
}
|
|
325
325
|
});
|
|
326
|
-
}),
|
|
326
|
+
}), Y = c(
|
|
327
327
|
(e) => {
|
|
328
328
|
u({
|
|
329
329
|
name: "OpenActRequest",
|
|
@@ -333,7 +333,7 @@ const $ = c(
|
|
|
333
333
|
}
|
|
334
334
|
});
|
|
335
335
|
}
|
|
336
|
-
),
|
|
336
|
+
), Z = c(
|
|
337
337
|
(e) => {
|
|
338
338
|
u({
|
|
339
339
|
name: "OpenActRequest",
|
|
@@ -343,13 +343,13 @@ const $ = c(
|
|
|
343
343
|
}
|
|
344
344
|
});
|
|
345
345
|
}
|
|
346
|
-
),
|
|
346
|
+
), ee = c(() => w({
|
|
347
347
|
name: "OpenActRequest",
|
|
348
348
|
params: {
|
|
349
349
|
type: 26,
|
|
350
350
|
data: {}
|
|
351
351
|
}
|
|
352
|
-
})),
|
|
352
|
+
})), te = c(
|
|
353
353
|
(e) => {
|
|
354
354
|
u({
|
|
355
355
|
name: "OpenActRequest",
|
|
@@ -359,7 +359,7 @@ const $ = c(
|
|
|
359
359
|
}
|
|
360
360
|
});
|
|
361
361
|
}
|
|
362
|
-
),
|
|
362
|
+
), ne = c(
|
|
363
363
|
(e) => {
|
|
364
364
|
u({
|
|
365
365
|
name: "OpenActRequest",
|
|
@@ -369,7 +369,7 @@ const $ = c(
|
|
|
369
369
|
}
|
|
370
370
|
});
|
|
371
371
|
}
|
|
372
|
-
),
|
|
372
|
+
), re = c(
|
|
373
373
|
(e) => {
|
|
374
374
|
u({
|
|
375
375
|
name: "OpenActRequest",
|
|
@@ -379,16 +379,16 @@ const $ = c(
|
|
|
379
379
|
}
|
|
380
380
|
});
|
|
381
381
|
}
|
|
382
|
-
),
|
|
383
|
-
class
|
|
382
|
+
), _ = "SHARE_EVENT_NAME";
|
|
383
|
+
class ie {
|
|
384
384
|
}
|
|
385
|
-
const
|
|
385
|
+
const se = c((e) => N({
|
|
386
386
|
name: "CommonShare",
|
|
387
387
|
handler(t, r) {
|
|
388
|
-
window.dispatchEvent(new Event(
|
|
388
|
+
window.dispatchEvent(new Event(_)), "onShareApp" in e && e.onShareApp ? r({ type: 12, data: e.onShareApp() }) : r({ type: 12, data: e });
|
|
389
389
|
}
|
|
390
|
-
})),
|
|
391
|
-
window.dispatchEvent(new Event(
|
|
390
|
+
})), oe = c(async (e) => {
|
|
391
|
+
window.dispatchEvent(new Event(_)), u({
|
|
392
392
|
name: "OpenActRequest",
|
|
393
393
|
params: {
|
|
394
394
|
type: 58,
|
|
@@ -396,12 +396,12 @@ const ie = c((e) => N({
|
|
|
396
396
|
}
|
|
397
397
|
});
|
|
398
398
|
});
|
|
399
|
-
function
|
|
400
|
-
return window.addEventListener(
|
|
401
|
-
window.removeEventListener(
|
|
399
|
+
function ae(e) {
|
|
400
|
+
return window.addEventListener(_, e), () => {
|
|
401
|
+
window.removeEventListener(_, e);
|
|
402
402
|
};
|
|
403
403
|
}
|
|
404
|
-
const
|
|
404
|
+
const ce = c(
|
|
405
405
|
(e) => {
|
|
406
406
|
u({
|
|
407
407
|
name: "OpenActRequest",
|
|
@@ -414,12 +414,12 @@ const ae = c(
|
|
|
414
414
|
}
|
|
415
415
|
});
|
|
416
416
|
}
|
|
417
|
-
),
|
|
417
|
+
), de = c(() => w({
|
|
418
418
|
name: "OpenActRequest",
|
|
419
419
|
params: {
|
|
420
420
|
type: 72
|
|
421
421
|
}
|
|
422
|
-
})),
|
|
422
|
+
})), ue = c(async () => {
|
|
423
423
|
u({
|
|
424
424
|
name: "OpenActRequest",
|
|
425
425
|
params: {
|
|
@@ -427,7 +427,7 @@ const ae = c(
|
|
|
427
427
|
}
|
|
428
428
|
});
|
|
429
429
|
});
|
|
430
|
-
class
|
|
430
|
+
class le {
|
|
431
431
|
}
|
|
432
432
|
const x = c(async () => (await w({
|
|
433
433
|
name: "OpenActRequest",
|
|
@@ -466,7 +466,7 @@ const x = c(async () => (await w({
|
|
|
466
466
|
t.start();
|
|
467
467
|
}
|
|
468
468
|
};
|
|
469
|
-
})(),
|
|
469
|
+
})(), pe = c(async () => {
|
|
470
470
|
y.triggerCheckTask(), w({
|
|
471
471
|
name: "OpenActRequest",
|
|
472
472
|
params: { type: 31, data: { requireLogin: !0 } },
|
|
@@ -475,42 +475,43 @@ const x = c(async () => (await w({
|
|
|
475
475
|
(t = e.data) != null && t.userId && y.triggerCheckTask();
|
|
476
476
|
}
|
|
477
477
|
});
|
|
478
|
-
}),
|
|
478
|
+
}), fe = (e) => (y.addTask(e), y.triggerCheckTask(), () => {
|
|
479
479
|
y.removeTask(e);
|
|
480
480
|
});
|
|
481
481
|
export {
|
|
482
482
|
j as AppBaseInfo,
|
|
483
|
-
|
|
484
|
-
|
|
483
|
+
le as AppLoginInfo,
|
|
484
|
+
ie as AppShareModel,
|
|
485
485
|
p as BridgeCode,
|
|
486
|
-
|
|
486
|
+
W as IS_KB_APP_ENV,
|
|
487
|
+
D as PostEditorParams,
|
|
487
488
|
J as checkForNewVersion,
|
|
488
|
-
|
|
489
|
-
|
|
489
|
+
K as closeWebView,
|
|
490
|
+
$ as createPostEditorParams,
|
|
490
491
|
B as decorateAppVersionSupport,
|
|
491
|
-
|
|
492
|
-
|
|
492
|
+
se as defineAppShareModel,
|
|
493
|
+
ce as defineAppSharePanelState,
|
|
493
494
|
N as defineBridgeCallback,
|
|
494
|
-
|
|
495
|
-
|
|
495
|
+
F as definePermissionUsage,
|
|
496
|
+
G as generateKBSign,
|
|
496
497
|
H as getAppBaseInfo,
|
|
497
498
|
x as getAppLoginInfo,
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
499
|
+
de as getAppSubscribeNotifyStatus,
|
|
500
|
+
L as isAppVersionSupport,
|
|
501
|
+
fe as onAppLoginSuccess,
|
|
502
|
+
ae as onAppSharePanelShow,
|
|
503
|
+
oe as openAppSharePanel,
|
|
504
|
+
ue as openAppSubscribeNotifySettings,
|
|
505
|
+
z as openPostEditor,
|
|
506
|
+
Q as reportDAEvent,
|
|
507
|
+
X as runAction,
|
|
507
508
|
u as runBridgeApi,
|
|
508
509
|
w as runBridgeApiResponse,
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
510
|
+
Y as saveImageToLocal,
|
|
511
|
+
Z as saveVideoToLocal,
|
|
512
|
+
ee as scanQRCode,
|
|
513
|
+
te as setScreenOrientation,
|
|
514
|
+
ne as setWebViewTitle,
|
|
515
|
+
re as shareImage,
|
|
516
|
+
pe as triggerAppLogin
|
|
516
517
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(r,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(r=typeof globalThis<"u"?globalThis:r||self,A(r.kbBridge={}))})(this,function(r){"use strict";var
|
|
1
|
+
(function(r,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(r=typeof globalThis<"u"?globalThis:r||self,A(r.kbBridge={}))})(this,function(r){"use strict";var q;function A(e){if(Object.prototype.toString.call(e)!=="[object Object]")return e;const t={};return Object.keys(e).forEach(i=>{const o=e[i];o!=null&&(t[i]=Object.prototype.toString.call(o)==="[object Object]"?A(o):o)}),t}const f=class f{constructor(t){this.errorCode=t.errorCode,this.errorMsg=t.errorMsg}};f.UNKNOWN=new f({errorCode:1e3,errorMsg:"未知错误"}),f.UNSUPPORTED_VERSION=new f({errorCode:1001,errorMsg:"当前开吧版本不支持"}),f.TIMEOUT=new f({errorCode:1002,errorMsg:"执行超时"}),f.UNSUPPORTED_BRIDGE_ENV=new f({errorCode:1003,errorMsg:"请在开吧app内执行"});let p=f;const H=()=>{const e=(a,s,n)=>{var c="";typeof s=="function"&&(n=s,s={});var u={data:s===void 0?null:s};if(typeof n=="function"){var h="dscb"+window.dscb++;window[h]=n,u._dscbstub=h}if(u=JSON.stringify(u),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(c=window.flutter_inappwebview.callHandler(""+a,u)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(c=prompt("_flutterDsbridge="+a,u)),c instanceof Promise)return c;try{return JSON.parse(c||"{}").data}catch{console.error("callHandle异常,JSON.parse错误")}},t=()=>window.navigator.userAgent.includes("Android")?window.flutter_inappwebview&&window.flutter_inappwebview._platformReady:!0,i=(()=>{const a=[],s=setInterval(()=>{t()&&(clearInterval(s),a.forEach(n=>{e.apply(window,n)}),a.length=0)},500);return(...n)=>{a.push(n)}})();var o={default:void 0,callHandler:function(a,s,n){return t()?e(a,s,n):i(a,s,n)},register:function(a,s,n){var c=n?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){o.callHandler("_dsb.dsinit")},0)),typeof s=="object"?c._obs[a]=s:c[a]=s},registerHandler:function(a,s){this.register(a,s,!0)}};return function(){if(!window._dsf){var a={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:o,_handleMessageFromNative:function(n){var c=JSON.parse(n.data),u={id:n.callbackId,complete:!0},h=this._dsf[n.method],b=this._dsaf[n.method],U=function(P,E){u.data=P.apply(E,c),o.callHandler("_dsb.returnValue",u)},C=function(P,E){c.push(function(fe,ge){u.data=fe,u.complete=ge!==!1,o.callHandler("_dsb.returnValue",u)}),P.apply(E,c)};if(h)U(h,this._dsf);else if(b)C(b,this._dsaf);else{var T=n.method.split(".");if(T.length<2)return;var M=T.pop(),L=T.join("."),O=this._dsf._obs,_=O[L]||{},w=_[M];if(w&&typeof w=="function"){U(w,_);return}if(O=this._dsaf._obs,_=O[L]||{},w=_[M],w&&typeof w=="function"){C(w,_);return}}}};for(var s in a)window[s]=a[s]}}(),o},v=(e=>/(kb)/i.test(e)?H():{registerHandler(t,i){throw p.UNSUPPORTED_BRIDGE_ENV},callHandler(t,i,o){throw p.UNSUPPORTED_BRIDGE_ENV}})((q=window==null?void 0:window.navigator)==null?void 0:q.userAgent),S=e=>new Promise((t,i)=>{var o,a,s;try{v.registerHandler(e.name,e.handler),(o=e.success)==null||o.call(e),t()}catch(n){(a=e.fail)==null||a.call(e,n),i(n)}finally{(s=e.complete)==null||s.call(e)}});function g(e){const t=i=>{let o;const a=n=>{var c;(!o||o==="success")&&(o="success",(c=i.success)==null||c.call(i,n))},s=n=>{var c;(!o||o==="error")&&(o="error",(c=i.fail)==null||c.call(i,n))};i.timeout&&setTimeout(()=>{s(p.TIMEOUT)},i.timeout);try{v.callHandler(i.name,i.params,n=>{let c;try{typeof n=="string"&&/^\s*(\{|\[).*(\}|\])\s*$/.test(n)?c=JSON.parse(n.replace(/\n/g,"\\n").replace(/\r/g,"\\r")):c=n}catch{c=n}a(c)})}catch(n){s(n)}};return new Promise((i,o)=>{t({name:e.name,params:A(e.params),timeout:e.timeout,success:a=>{var s,n;(s=e.success)==null||s.call(e,a),(n=e.complete)==null||n.call(e),i(a)},fail:a=>{var s,n;(s=e.fail)==null||s.call(e,a),(n=e.complete)==null||n.call(e),o(a)}})})}function l(e){v.callHandler(e.name,e.params,t=>{})}function d(e){return async function(...i){const o=i[0]||{},{success:a,fail:s,complete:n,...c}=o;try{const u=await Promise.resolve(e(c));return a==null||a(u),u}catch(u){const h=u!=null&&u.errorCode?u:new p({errorCode:p.UNKNOWN.errorCode,errorMsg:String(u)});throw s==null||s(h),h}finally{n==null||n()}}}function B(e){let t;return function(...i){return t||(t=e(...i),Promise.resolve(t).catch(()=>{t=void 0}),t)}}class D{}const R=d(B(()=>g({name:"OpenActRequest",params:{type:35,data:{}}}))),I=d(async e=>(await R()).vcode>=e.minVersion);function j(e,t){return(...i)=>I({minVersion:e.minVersion}).then(o=>o?t(...i):Promise.reject(new p({errorCode:p.UNSUPPORTED_VERSION.errorCode,errorMsg:`最低版本要求${e.minVersion}`})))}const K=d(()=>{l({name:"OpenActRequest",params:{type:56,data:null}})}),W=d(()=>{l({name:"OpenActRequest",params:{type:-1,data:{}}})}),k={microphone:{description:"用于发帖上传音频"},location:{description:"获取你选择的位置信息,用于线下导航服务"},camera:{description:"收集你选中的照片或视频信息 ,用于 发表评论、分享视频"}},F=d(e=>(Object.assign(k,e),S({name:"getPermissionUsage",handler(t,i){i(k[t.permission])}}))),J=/(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent),G=d(async e=>{const{kbKey:t,...i}=e,{data:o}=await g({name:"OpenActRequest",params:{type:51,data:i}});return o});class V{constructor(){this.enableImageUpload=!0,this.enableAudioUpload=!0,this.enableVideoUpload=!0,this.enableAddress=!0,this.enableMediaVideoUpload=!1,this.minTextLength=0,this.maxTextLength=1e3,this.minImageCount=0,this.maxImageCount=9,this.isAudioRequired=!1,this.isVideoRequired=!1,this.isMediaVideoRequired=!1}}function $(e){const t=new V;return e&&Object.keys(e).forEach(o=>{t[o]=e[o]}),{hint:t.placeholder,initialText:t.initialText,audio:t.enableAudioUpload,image:t.enableImageUpload,video:t.enableVideoUpload,address:t.enableAddress,asset_video:t.enableMediaVideoUpload,text_must:t.minTextLength>0,content_min_length:t.minTextLength,content_max_length:t.maxTextLength,image_must:t.minImageCount>0,min_image_count:t.minImageCount,max_image_count:t.maxImageCount,audio_must:t.isAudioRequired,video_must:t.isVideoRequired,asset_video_must:t.isMediaVideoRequired}}const z=d(async(e={})=>g({name:"OpenActRequest",params:{type:13,data:e}}).then(({data:t})=>{const{pic:i,...o}=t;return{images:i,...o}})),Q=d(e=>{l({name:"OpenActRequest",params:{type:69,data:{eventId:e.eventName,trackParams:e.eventParams,ExtEventType:e.eventType}}})}),X=d(e=>{l({name:"OpenActRequest",params:{type:1001,data:e}})}),Y=d(e=>{l({name:"OpenActRequest",params:{type:62,data:e}})}),Z=d(e=>{l({name:"OpenActRequest",params:{type:63,data:e}})}),x=d(()=>g({name:"OpenActRequest",params:{type:26,data:{}}})),ee=d(e=>{l({name:"OpenActRequest",params:{type:71,data:e}})}),te=d(e=>{l({name:"OpenActRequest",params:{type:64,data:e}})}),ne=d(e=>{l({name:"OpenActRequest",params:{type:58,data:e}})}),m="SHARE_EVENT_NAME";class ie{}const re=d(e=>S({name:"CommonShare",handler(t,i){window.dispatchEvent(new Event(m)),"onShareApp"in e&&e.onShareApp?i({type:12,data:e.onShareApp()}):i({type:12,data:e})}})),oe=d(async e=>{window.dispatchEvent(new Event(m)),l({name:"OpenActRequest",params:{type:58,data:e}})});function se(e){return window.addEventListener(m,e),()=>{window.removeEventListener(m,e)}}const ae=d(e=>{l({name:"OpenActRequest",params:{type:68,data:{show:e.showMenu,showActionMode:e.panelStyle||0}}})}),ce=d(()=>g({name:"OpenActRequest",params:{type:72}})),de=d(async()=>{l({name:"OpenActRequest",params:{type:73}})});class ue{}const N=d(async()=>(await g({name:"OpenActRequest",params:{type:31,data:{requireLogin:!1}}})).data||null),y=(()=>{const e=new Set,t=(()=>{let i;const o=a=>{i=setTimeout(async()=>{const n=await N();if(!n)return o(++a);e.forEach(c=>c(n)),e.clear()},(n=>n===0?0:n<50?600:n<80?1e3:5e3)(a))};return{start(){i&&clearTimeout(i),e.size>0&&o(0)},stop(){i&&clearTimeout(i)}}})();return{addTask(i){e.add(i)},removeTask(i){e.delete(i),e.size===0&&t.stop()},triggerCheckTask(){t.start()}}})(),le=d(async()=>{y.triggerCheckTask(),g({name:"OpenActRequest",params:{type:31,data:{requireLogin:!0}},success(e){var t;(t=e.data)!=null&&t.userId&&y.triggerCheckTask()}})}),pe=e=>(y.addTask(e),y.triggerCheckTask(),()=>{y.removeTask(e)});r.AppBaseInfo=D,r.AppLoginInfo=ue,r.AppShareModel=ie,r.BridgeCode=p,r.IS_KB_APP_ENV=J,r.PostEditorParams=V,r.checkForNewVersion=K,r.closeWebView=W,r.createPostEditorParams=$,r.decorateAppVersionSupport=j,r.defineAppShareModel=re,r.defineAppSharePanelState=ae,r.defineBridgeCallback=S,r.definePermissionUsage=F,r.generateKBSign=G,r.getAppBaseInfo=R,r.getAppLoginInfo=N,r.getAppSubscribeNotifyStatus=ce,r.isAppVersionSupport=I,r.onAppLoginSuccess=pe,r.onAppSharePanelShow=se,r.openAppSharePanel=oe,r.openAppSubscribeNotifySettings=de,r.openPostEditor=z,r.reportDAEvent=Q,r.runAction=X,r.runBridgeApi=l,r.runBridgeApiResponse=g,r.saveImageToLocal=Y,r.saveVideoToLocal=Z,r.scanQRCode=x,r.setScreenOrientation=ee,r.setWebViewTitle=te,r.shareImage=ne,r.triggerAppLogin=le,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -4,7 +4,7 @@ import { BridgeCode } from './bridge-code';
|
|
|
4
4
|
*
|
|
5
5
|
* @description 登录信息
|
|
6
6
|
*/
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class AppLoginInfo {
|
|
8
8
|
/** 车牌号:例如浙A999999 */
|
|
9
9
|
carNo?: string;
|
|
10
10
|
/** 未知 */
|
|
@@ -30,10 +30,10 @@ export declare class AppBridgedUserInfo {
|
|
|
30
30
|
* 桥接type: 31
|
|
31
31
|
*/
|
|
32
32
|
export declare const getAppLoginInfo: (params?: {
|
|
33
|
-
success?: ((res:
|
|
33
|
+
success?: ((res: AppLoginInfo | null) => void) | undefined;
|
|
34
34
|
fail?: (error: BridgeCode) => void;
|
|
35
35
|
complete?: () => void;
|
|
36
|
-
} | undefined) => Promise<
|
|
36
|
+
} | undefined) => Promise<AppLoginInfo | null>;
|
|
37
37
|
/**
|
|
38
38
|
*
|
|
39
39
|
* @description 触发登录, 该函数仅触发登录, 不会返回任何结果, 可以通过 getAppLoginInfo 获取登录结果 或者 watchAppLoginSuccess 监听到登录
|
|
@@ -58,4 +58,4 @@ const handle = watchAppLoginSuccess(() => {
|
|
|
58
58
|
// handle() 停止监听
|
|
59
59
|
```
|
|
60
60
|
*/
|
|
61
|
-
export declare const onAppLoginSuccess: (callback: (loginInfo:
|
|
61
|
+
export declare const onAppLoginSuccess: (callback: (loginInfo: AppLoginInfo) => void) => () => void;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.2-alpha.0",
|
|
7
7
|
"description": "开吧客户端桥接",
|
|
8
8
|
"author": "along",
|
|
9
9
|
"type": "module",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"module": "./dist/index.es.js",
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"build": "rm -rf ./dist && vite build",
|
|
15
|
+
"dev": "npm run build && vite",
|
|
16
16
|
"publish": "npm run build && npm publish"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|