@arcblock/bridge 2.9.63 → 2.9.65

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.
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /* eslint-disable */
8
+ /**
9
+ * @copyright https://www.npmjs.com/package/dsbridge
10
+ * @description 只添加方法劫持前的判断,其余不做任何改动,确保不会有任何影响
11
+ */
12
+
13
+ var bridge = {
14
+ call: function call(method, args, cb) {
15
+ var ret = '';
16
+ if (typeof args == 'function') {
17
+ cb = args;
18
+ args = {};
19
+ }
20
+ var arg = {
21
+ data: args === undefined ? null : args
22
+ };
23
+ if (typeof cb == 'function') {
24
+ var cbName = 'dscb' + window.dscb++;
25
+ window[cbName] = cb;
26
+ arg['_dscbstub'] = cbName;
27
+ }
28
+ arg = JSON.stringify(arg);
29
+
30
+ //if in webview that dsBridge provided, call!
31
+ if (window._dsbridge) {
32
+ ret = _dsbridge.call(method, arg);
33
+ } else if (window._dswk || navigator.userAgent.indexOf('_dsbridge') != -1) {
34
+ ret = prompt('_dsbridge=' + method, arg);
35
+ }
36
+ return JSON.parse(ret || '{}').data;
37
+ },
38
+ register: function register(name, fun, asyn) {
39
+ var q = asyn ? window._dsaf : window._dsf;
40
+ if (!window._dsInit) {
41
+ window._dsInit = true;
42
+ //notify native that js apis register successfully on next event loop
43
+ setTimeout(function () {
44
+ bridge.call('_dsb.dsinit');
45
+ }, 0);
46
+ }
47
+ if (typeof fun == 'object') {
48
+ q._obs[name] = fun;
49
+ } else {
50
+ q[name] = fun;
51
+ }
52
+ },
53
+ registerAsyn: function registerAsyn(name, fun) {
54
+ this.register(name, fun, true);
55
+ },
56
+ hasNativeMethod: function hasNativeMethod(name, type) {
57
+ return this.call('_dsb.hasNativeMethod', {
58
+ name: name,
59
+ type: type || 'all'
60
+ });
61
+ },
62
+ disableJavascriptDialogBlock: function disableJavascriptDialogBlock(disable) {
63
+ this.call('_dsb.disableJavascriptDialogBlock', {
64
+ disable: disable !== false
65
+ });
66
+ }
67
+ };
68
+ !function () {
69
+ // 只有在 dsbridge 注入过的环境,才执行下方的代码
70
+ if (!(window._dsbridge || window._dswk || navigator.userAgent.indexOf('_dsbridge') != -1)) return;
71
+ if (window._dsf) return;
72
+ var ob = {
73
+ _dsf: {
74
+ _obs: {}
75
+ },
76
+ _dsaf: {
77
+ _obs: {}
78
+ },
79
+ dscb: 0,
80
+ dsBridge: bridge,
81
+ close: function close() {
82
+ bridge.call('_dsb.closePage');
83
+ },
84
+ _handleMessageFromNative: function _handleMessageFromNative(info) {
85
+ var arg = JSON.parse(info.data);
86
+ var ret = {
87
+ id: info.callbackId,
88
+ complete: true
89
+ };
90
+ var f = this._dsf[info.method];
91
+ var af = this._dsaf[info.method];
92
+ var callSyn = function callSyn(f, ob) {
93
+ ret.data = f.apply(ob, arg);
94
+ bridge.call('_dsb.returnValue', ret);
95
+ };
96
+ var callAsyn = function callAsyn(f, ob) {
97
+ arg.push(function (data, complete) {
98
+ ret.data = data;
99
+ ret.complete = complete !== false;
100
+ bridge.call('_dsb.returnValue', ret);
101
+ });
102
+ f.apply(ob, arg);
103
+ };
104
+ if (f) {
105
+ callSyn(f, this._dsf);
106
+ } else if (af) {
107
+ callAsyn(af, this._dsaf);
108
+ } else {
109
+ //with namespace
110
+ var name = info.method.split('.');
111
+ if (name.length < 2) return;
112
+ var method = name.pop();
113
+ var namespace = name.join('.');
114
+ var obs = this._dsf._obs;
115
+ var ob = obs[namespace] || {};
116
+ var m = ob[method];
117
+ if (m && typeof m == 'function') {
118
+ callSyn(m, ob);
119
+ return;
120
+ }
121
+ obs = this._dsaf._obs;
122
+ ob = obs[namespace] || {};
123
+ m = ob[method];
124
+ if (m && typeof m == 'function') {
125
+ callAsyn(m, ob);
126
+ return;
127
+ }
128
+ }
129
+ }
130
+ };
131
+ for (var attr in ob) {
132
+ window[attr] = ob[attr];
133
+ }
134
+ bridge.register('_hasJavascriptMethod', function (method, tag) {
135
+ var name = method.split('.');
136
+ if (name.length < 2) {
137
+ return !!(_dsf[name] || _dsaf[name]);
138
+ } else {
139
+ // with namespace
140
+ var method = name.pop();
141
+ var namespace = name.join('.');
142
+ var ob = _dsf._obs[namespace] || _dsaf._obs[namespace];
143
+ return ob && !!ob[method];
144
+ }
145
+ });
146
+ }();
147
+ var _default = exports.default = bridge;
package/lib/index.js CHANGED
@@ -4,23 +4,32 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
8
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
9
- function callBridge() {
10
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
11
- args[_key] = arguments[_key];
12
- }
13
- Promise.resolve().then(() => _interopRequireWildcard(require('dsbridge'))).then(dsbridge => {
14
- if (!dsbridge.call) {
15
- // eslint-disable-next-line no-param-reassign
16
- dsbridge = dsbridge.default;
17
- }
18
- dsbridge.call(...args);
19
- }).catch(err => {
20
- console.error('load dsbridge error', err);
21
- });
22
- }
7
+ var _dsbridge = _interopRequireDefault(require("./dsbridge"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
9
  var _default = exports.default = {
10
+ call() {
11
+ _dsbridge.default.call(...arguments);
12
+ },
13
+ asyncCall() {
14
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
15
+ args[_key] = arguments[_key];
16
+ }
17
+ return new Promise((resolve, reject) => {
18
+ _dsbridge.default.call(...args, resString => {
19
+ try {
20
+ const result = JSON.parse(resString);
21
+ if (result.code === 0) {
22
+ const data = JSON.parse(result.data);
23
+ resolve(data);
24
+ } else {
25
+ reject(new Error(result.error));
26
+ }
27
+ } catch (_unused) {
28
+ resolve(resString);
29
+ }
30
+ });
31
+ });
32
+ },
24
33
  // 基本功能
25
34
  shareMessage(params) {
26
35
  const {
@@ -33,7 +42,7 @@ var _default = exports.default = {
33
42
  fail('params error');
34
43
  return;
35
44
  }
36
- callBridge('arcShare', JSON.stringify({
45
+ _dsbridge.default.call('arcShare', JSON.stringify({
37
46
  content,
38
47
  imgUrl
39
48
  }), result => {
@@ -48,14 +57,14 @@ var _default = exports.default = {
48
57
  });
49
58
  },
50
59
  showLoading() {
51
- callBridge('arcShowLoading');
60
+ _dsbridge.default.call('arcShowLoading');
52
61
  },
53
62
  hideLoading() {
54
- callBridge('arcHideLoading');
63
+ _dsbridge.default.call('arcHideLoading');
55
64
  },
56
65
  showToast(msg) {
57
66
  if (msg && typeof msg === 'string') {
58
- callBridge('arcToast', msg);
67
+ _dsbridge.default.call('arcToast', msg);
59
68
  }
60
69
  },
61
70
  // 图片功能
@@ -65,7 +74,7 @@ var _default = exports.default = {
65
74
  success,
66
75
  fail
67
76
  } = params;
68
- callBridge('arcChooseImgs', JSON.stringify({
77
+ _dsbridge.default.call('arcChooseImgs', JSON.stringify({
69
78
  limit
70
79
  }), result => {
71
80
  const parseResult = JSON.parse(result);
@@ -85,7 +94,7 @@ var _default = exports.default = {
85
94
  if (!imgs || imgs.length === 0) {
86
95
  return;
87
96
  }
88
- callBridge('arcPreviewImgs', JSON.stringify(params));
97
+ _dsbridge.default.call('arcPreviewImgs', JSON.stringify(params));
89
98
  },
90
99
  // 钱包功能
91
100
  isSetPWD(params) {
@@ -93,7 +102,7 @@ var _default = exports.default = {
93
102
  success,
94
103
  fail
95
104
  } = params;
96
- callBridge('arcIsSetPWD', '', result => {
105
+ _dsbridge.default.call('arcIsSetPWD', '', result => {
97
106
  const parseResult = JSON.parse(result);
98
107
  if (parseResult && parseResult.code === 0) {
99
108
  if (typeof success === 'function') {
@@ -109,7 +118,7 @@ var _default = exports.default = {
109
118
  success,
110
119
  fail
111
120
  } = params;
112
- callBridge('arcIsCodeABOk', '', result => {
121
+ _dsbridge.default.call('arcIsCodeABOk', '', result => {
113
122
  const parseResult = JSON.parse(result);
114
123
  if (parseResult && parseResult.code === 0) {
115
124
  if (typeof success === 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/bridge",
3
- "version": "2.9.63",
3
+ "version": "2.9.65",
4
4
  "description": "a bridge sdk support all js api from DID Wallet.",
5
5
  "keywords": [
6
6
  "bridge",
@@ -27,9 +27,6 @@
27
27
  "bugs": {
28
28
  "url": "https://github.com/ArcBlock/ux/issues"
29
29
  },
30
- "dependencies": {
31
- "dsbridge": "^3.1.4"
32
- },
33
30
  "publishConfig": {
34
31
  "access": "public"
35
32
  },
@@ -41,5 +38,5 @@
41
38
  "eslint-plugin-react-hooks": "^4.6.0",
42
39
  "jest": "^28.1.3"
43
40
  },
44
- "gitHead": "e5e083300891c1ff349c653a70229ea6ba3f8b24"
41
+ "gitHead": "5be1d00bdc7707837c2a0045f01cd7f2f1027534"
45
42
  }
@@ -0,0 +1,139 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * @copyright https://www.npmjs.com/package/dsbridge
4
+ * @description 只添加方法劫持前的判断,其余不做任何改动,确保不会有任何影响
5
+ */
6
+
7
+ var bridge = {
8
+ call: function (method, args, cb) {
9
+ var ret = '';
10
+ if (typeof args == 'function') {
11
+ cb = args;
12
+ args = {};
13
+ }
14
+ var arg = { data: args === undefined ? null : args };
15
+ if (typeof cb == 'function') {
16
+ var cbName = 'dscb' + window.dscb++;
17
+ window[cbName] = cb;
18
+ arg['_dscbstub'] = cbName;
19
+ }
20
+ arg = JSON.stringify(arg);
21
+
22
+ //if in webview that dsBridge provided, call!
23
+ if (window._dsbridge) {
24
+ ret = _dsbridge.call(method, arg);
25
+ } else if (window._dswk || navigator.userAgent.indexOf('_dsbridge') != -1) {
26
+ ret = prompt('_dsbridge=' + method, arg);
27
+ }
28
+
29
+ return JSON.parse(ret || '{}').data;
30
+ },
31
+ register: function (name, fun, asyn) {
32
+ var q = asyn ? window._dsaf : window._dsf;
33
+ if (!window._dsInit) {
34
+ window._dsInit = true;
35
+ //notify native that js apis register successfully on next event loop
36
+ setTimeout(function () {
37
+ bridge.call('_dsb.dsinit');
38
+ }, 0);
39
+ }
40
+ if (typeof fun == 'object') {
41
+ q._obs[name] = fun;
42
+ } else {
43
+ q[name] = fun;
44
+ }
45
+ },
46
+ registerAsyn: function (name, fun) {
47
+ this.register(name, fun, true);
48
+ },
49
+ hasNativeMethod: function (name, type) {
50
+ return this.call('_dsb.hasNativeMethod', { name: name, type: type || 'all' });
51
+ },
52
+ disableJavascriptDialogBlock: function (disable) {
53
+ this.call('_dsb.disableJavascriptDialogBlock', {
54
+ disable: disable !== false,
55
+ });
56
+ },
57
+ };
58
+
59
+ !(function () {
60
+ // 只有在 dsbridge 注入过的环境,才执行下方的代码
61
+ if (!(window._dsbridge || window._dswk || navigator.userAgent.indexOf('_dsbridge') != -1)) return;
62
+ if (window._dsf) return;
63
+ var ob = {
64
+ _dsf: {
65
+ _obs: {},
66
+ },
67
+ _dsaf: {
68
+ _obs: {},
69
+ },
70
+ dscb: 0,
71
+ dsBridge: bridge,
72
+ close: function () {
73
+ bridge.call('_dsb.closePage');
74
+ },
75
+ _handleMessageFromNative: function (info) {
76
+ var arg = JSON.parse(info.data);
77
+ var ret = {
78
+ id: info.callbackId,
79
+ complete: true,
80
+ };
81
+ var f = this._dsf[info.method];
82
+ var af = this._dsaf[info.method];
83
+ var callSyn = function (f, ob) {
84
+ ret.data = f.apply(ob, arg);
85
+ bridge.call('_dsb.returnValue', ret);
86
+ };
87
+ var callAsyn = function (f, ob) {
88
+ arg.push(function (data, complete) {
89
+ ret.data = data;
90
+ ret.complete = complete !== false;
91
+ bridge.call('_dsb.returnValue', ret);
92
+ });
93
+ f.apply(ob, arg);
94
+ };
95
+ if (f) {
96
+ callSyn(f, this._dsf);
97
+ } else if (af) {
98
+ callAsyn(af, this._dsaf);
99
+ } else {
100
+ //with namespace
101
+ var name = info.method.split('.');
102
+ if (name.length < 2) return;
103
+ var method = name.pop();
104
+ var namespace = name.join('.');
105
+ var obs = this._dsf._obs;
106
+ var ob = obs[namespace] || {};
107
+ var m = ob[method];
108
+ if (m && typeof m == 'function') {
109
+ callSyn(m, ob);
110
+ return;
111
+ }
112
+ obs = this._dsaf._obs;
113
+ ob = obs[namespace] || {};
114
+ m = ob[method];
115
+ if (m && typeof m == 'function') {
116
+ callAsyn(m, ob);
117
+ return;
118
+ }
119
+ }
120
+ },
121
+ };
122
+ for (var attr in ob) {
123
+ window[attr] = ob[attr];
124
+ }
125
+ bridge.register('_hasJavascriptMethod', function (method, tag) {
126
+ var name = method.split('.');
127
+ if (name.length < 2) {
128
+ return !!(_dsf[name] || _dsaf[name]);
129
+ } else {
130
+ // with namespace
131
+ var method = name.pop();
132
+ var namespace = name.join('.');
133
+ var ob = _dsf._obs[namespace] || _dsaf._obs[namespace];
134
+ return ob && !!ob[method];
135
+ }
136
+ });
137
+ })();
138
+
139
+ export default bridge;
package/src/index.js CHANGED
@@ -1,18 +1,26 @@
1
- function callBridge(...args) {
2
- import('dsbridge')
3
- .then((dsbridge) => {
4
- if (!dsbridge.call) {
5
- // eslint-disable-next-line no-param-reassign
6
- dsbridge = dsbridge.default;
7
- }
8
- dsbridge.call(...args);
9
- })
10
- .catch((err) => {
11
- console.error('load dsbridge error', err);
12
- });
13
- }
1
+ import dsbridge from './dsbridge';
14
2
 
15
3
  export default {
4
+ call(...args) {
5
+ dsbridge.call(...args);
6
+ },
7
+ asyncCall(...args) {
8
+ return new Promise((resolve, reject) => {
9
+ dsbridge.call(...args, (resString) => {
10
+ try {
11
+ const result = JSON.parse(resString);
12
+ if (result.code === 0) {
13
+ const data = JSON.parse(result.data);
14
+ resolve(data);
15
+ } else {
16
+ reject(new Error(result.error));
17
+ }
18
+ } catch {
19
+ resolve(resString);
20
+ }
21
+ });
22
+ });
23
+ },
16
24
  // 基本功能
17
25
  shareMessage(params) {
18
26
  const { content, imgUrl, success, fail } = params;
@@ -20,7 +28,7 @@ export default {
20
28
  fail('params error');
21
29
  return;
22
30
  }
23
- callBridge('arcShare', JSON.stringify({ content, imgUrl }), (result) => {
31
+ dsbridge.call('arcShare', JSON.stringify({ content, imgUrl }), (result) => {
24
32
  const parseResult = JSON.parse(result);
25
33
  if (parseResult && parseResult.code === 0) {
26
34
  if (typeof success === 'function') {
@@ -32,20 +40,20 @@ export default {
32
40
  });
33
41
  },
34
42
  showLoading() {
35
- callBridge('arcShowLoading');
43
+ dsbridge.call('arcShowLoading');
36
44
  },
37
45
  hideLoading() {
38
- callBridge('arcHideLoading');
46
+ dsbridge.call('arcHideLoading');
39
47
  },
40
48
  showToast(msg) {
41
49
  if (msg && typeof msg === 'string') {
42
- callBridge('arcToast', msg);
50
+ dsbridge.call('arcToast', msg);
43
51
  }
44
52
  },
45
53
  // 图片功能
46
54
  chooseImgs(params) {
47
55
  const { limit, success, fail } = params;
48
- callBridge('arcChooseImgs', JSON.stringify({ limit }), (result) => {
56
+ dsbridge.call('arcChooseImgs', JSON.stringify({ limit }), (result) => {
49
57
  const parseResult = JSON.parse(result);
50
58
  if (parseResult && parseResult.code === 0) {
51
59
  if (typeof success === 'function') {
@@ -61,12 +69,12 @@ export default {
61
69
  if (!imgs || imgs.length === 0) {
62
70
  return;
63
71
  }
64
- callBridge('arcPreviewImgs', JSON.stringify(params));
72
+ dsbridge.call('arcPreviewImgs', JSON.stringify(params));
65
73
  },
66
74
  // 钱包功能
67
75
  isSetPWD(params) {
68
76
  const { success, fail } = params;
69
- callBridge('arcIsSetPWD', '', (result) => {
77
+ dsbridge.call('arcIsSetPWD', '', (result) => {
70
78
  const parseResult = JSON.parse(result);
71
79
  if (parseResult && parseResult.code === 0) {
72
80
  if (typeof success === 'function') {
@@ -79,7 +87,7 @@ export default {
79
87
  },
80
88
  isCodeABOk(params) {
81
89
  const { success, fail } = params;
82
- callBridge('arcIsCodeABOk', '', (result) => {
90
+ dsbridge.call('arcIsCodeABOk', '', (result) => {
83
91
  const parseResult = JSON.parse(result);
84
92
  if (parseResult && parseResult.code === 0) {
85
93
  if (typeof success === 'function') {