@webview-bridge/react-native 1.7.5 → 1.7.7
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/dist/index.cjs +14 -11
- package/dist/index.js +7 -4
- package/package.json +4 -4
- package/src/integrations/console.ts +10 -0
package/dist/index.cjs
CHANGED
|
@@ -400,8 +400,8 @@ var __toCommonJS = function(mod) {
|
|
|
400
400
|
}), mod);
|
|
401
401
|
};
|
|
402
402
|
// src/index.ts
|
|
403
|
-
var
|
|
404
|
-
__export(
|
|
403
|
+
var index_exports = {};
|
|
404
|
+
__export(index_exports, {
|
|
405
405
|
INJECT_BRIDGE_METHODS: function() {
|
|
406
406
|
return INJECT_BRIDGE_METHODS;
|
|
407
407
|
},
|
|
@@ -433,9 +433,9 @@ __export(src_exports, {
|
|
|
433
433
|
return useBridge;
|
|
434
434
|
}
|
|
435
435
|
});
|
|
436
|
-
module.exports = __toCommonJS(
|
|
436
|
+
module.exports = __toCommonJS(index_exports);
|
|
437
437
|
// src/createWebView.tsx
|
|
438
|
-
var
|
|
438
|
+
var import_utils4 = require("@webview-bridge/utils");
|
|
439
439
|
var import_react = require("react");
|
|
440
440
|
var import_react_native_webview = __toESM(require("react-native-webview"), 1);
|
|
441
441
|
// src/integrations/bridge.ts
|
|
@@ -571,7 +571,9 @@ var SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID = function(bridgeId, eventName) {
|
|
|
571
571
|
return "\nif (window.nativeEmitterMap && window.nativeEmitterMap['".concat(bridgeId, "']) {\n window.nativeEmitterMap['").concat(bridgeId, "'].emit('").concat(eventName, "', {}, true);\n} else if (window.nativeEmitter) {\n // @deprecated This version is not used after 1.7.2\n window.nativeEmitter.emit('").concat(eventName, "', {}, true);\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', {}, true]);\n}\ntrue;\n");
|
|
572
572
|
};
|
|
573
573
|
// src/integrations/console.ts
|
|
574
|
-
var
|
|
574
|
+
var import_utils2 = require("@webview-bridge/utils");
|
|
575
|
+
var injectionDetectKey = "__bridge_debug_injected_".concat((0, import_utils2.createRandomId)());
|
|
576
|
+
var INJECT_DEBUG = '\n{\n if (window["'.concat(injectionDetectKey, '"]) {\n return;\n }\n\n window["').concat(injectionDetectKey, '"] = true;\n const originalConsoleLog = console.log;\n const originalConsoleError = console.error;\n const originalConsoleWarn = console.warn;\n\n console.log = function() {\n var message = JSON.stringify(Array.from(arguments));\n window.ReactNativeWebView?.postMessage(\n JSON.stringify({ type: "log", body: { method: "log", args: message } }),\n );\n originalConsoleLog.apply(console, arguments);\n };\n\n console.error = function() {\n var message = JSON.stringify(Array.from(arguments));\n window.ReactNativeWebView?.postMessage(\n JSON.stringify({ type: "log", body: { method: "error", args: message } }),\n );\n originalConsoleError.apply(console, arguments);\n };\n\n console.warn = function() {\n var message = JSON.stringify(Array.from(arguments));\n window.ReactNativeWebView?.postMessage(\n JSON.stringify({ type: "log", body: { method: "warn", args: message } }),\n );\n originalConsoleWarn.apply(console, arguments);\n };\n};\n');
|
|
575
577
|
var handleLog = function(type, message) {
|
|
576
578
|
var _JSON_parse = _to_array(JSON.parse(message)), formatMessage = _JSON_parse[0], parsedMessage = _JSON_parse.slice(1);
|
|
577
579
|
var webviewMark = "(WebView) ";
|
|
@@ -603,7 +605,7 @@ var handleLog = function(type, message) {
|
|
|
603
605
|
}
|
|
604
606
|
};
|
|
605
607
|
// src/integrations/handleRegisterWebMethod.ts
|
|
606
|
-
var
|
|
608
|
+
var import_utils3 = require("@webview-bridge/utils");
|
|
607
609
|
// src/error.ts
|
|
608
610
|
var WebMethodError = /*#__PURE__*/ function(Error1) {
|
|
609
611
|
_inherits(WebMethodError, Error1);
|
|
@@ -628,11 +630,11 @@ var handleRegisterWebMethod = function(emitter, webview, bridgeNames, responseTi
|
|
|
628
630
|
for(_len = _arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
629
631
|
args[_key] = _arguments[_key];
|
|
630
632
|
}
|
|
631
|
-
eventId = (0,
|
|
633
|
+
eventId = (0, import_utils3.createRandomId)();
|
|
632
634
|
return [
|
|
633
635
|
2,
|
|
634
636
|
Promise.race([
|
|
635
|
-
(0,
|
|
637
|
+
(0, import_utils3.createResolver)({
|
|
636
638
|
emitter: emitter,
|
|
637
639
|
methodName: methodName,
|
|
638
640
|
eventId: eventId,
|
|
@@ -641,7 +643,7 @@ var handleRegisterWebMethod = function(emitter, webview, bridgeNames, responseTi
|
|
|
641
643
|
},
|
|
642
644
|
failHandler: new WebMethodError(methodName)
|
|
643
645
|
}),
|
|
644
|
-
(0,
|
|
646
|
+
(0, import_utils3.timeout)(responseTimeout)
|
|
645
647
|
])
|
|
646
648
|
];
|
|
647
649
|
});
|
|
@@ -650,6 +652,7 @@ var handleRegisterWebMethod = function(emitter, webview, bridgeNames, responseTi
|
|
|
650
652
|
}, {});
|
|
651
653
|
};
|
|
652
654
|
// src/createWebView.tsx
|
|
655
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
653
656
|
var createWebView = function(param) {
|
|
654
657
|
var bridge2 = param.bridge, debug = param.debug, _param_responseTimeout = param.responseTimeout, responseTimeout = _param_responseTimeout === void 0 ? 2e3 : _param_responseTimeout, postMessageSchema2 = param.postMessageSchema, fallback = param.fallback;
|
|
655
658
|
var WebMethod = {
|
|
@@ -658,7 +661,7 @@ var createWebView = function(param) {
|
|
|
658
661
|
}
|
|
659
662
|
};
|
|
660
663
|
var webviewRefList = [];
|
|
661
|
-
var emitter = (0,
|
|
664
|
+
var emitter = (0, import_utils4.createEvents)();
|
|
662
665
|
bridge2.subscribe(function(state) {
|
|
663
666
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
664
667
|
try {
|
|
@@ -863,7 +866,7 @@ var createWebView = function(param) {
|
|
|
863
866
|
return _ref.apply(this, arguments);
|
|
864
867
|
};
|
|
865
868
|
}();
|
|
866
|
-
return /* @__PURE__ */
|
|
869
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native_webview.default, _object_spread_props(_object_spread({}, props), {
|
|
867
870
|
ref: webviewRef,
|
|
868
871
|
onMessage: handleMessage,
|
|
869
872
|
injectedJavaScriptBeforeContentLoaded: [
|
package/dist/index.js
CHANGED
|
@@ -477,7 +477,9 @@ var SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID = function(bridgeId, eventName) {
|
|
|
477
477
|
return "\nif (window.nativeEmitterMap && window.nativeEmitterMap['".concat(bridgeId, "']) {\n window.nativeEmitterMap['").concat(bridgeId, "'].emit('").concat(eventName, "', {}, true);\n} else if (window.nativeEmitter) {\n // @deprecated This version is not used after 1.7.2\n window.nativeEmitter.emit('").concat(eventName, "', {}, true);\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', {}, true]);\n}\ntrue;\n");
|
|
478
478
|
};
|
|
479
479
|
// src/integrations/console.ts
|
|
480
|
-
|
|
480
|
+
import { createRandomId } from "@webview-bridge/utils";
|
|
481
|
+
var injectionDetectKey = "__bridge_debug_injected_".concat(createRandomId());
|
|
482
|
+
var INJECT_DEBUG = '\n{\n if (window["'.concat(injectionDetectKey, '"]) {\n return;\n }\n\n window["').concat(injectionDetectKey, '"] = true;\n const originalConsoleLog = console.log;\n const originalConsoleError = console.error;\n const originalConsoleWarn = console.warn;\n\n console.log = function() {\n var message = JSON.stringify(Array.from(arguments));\n window.ReactNativeWebView?.postMessage(\n JSON.stringify({ type: "log", body: { method: "log", args: message } }),\n );\n originalConsoleLog.apply(console, arguments);\n };\n\n console.error = function() {\n var message = JSON.stringify(Array.from(arguments));\n window.ReactNativeWebView?.postMessage(\n JSON.stringify({ type: "log", body: { method: "error", args: message } }),\n );\n originalConsoleError.apply(console, arguments);\n };\n\n console.warn = function() {\n var message = JSON.stringify(Array.from(arguments));\n window.ReactNativeWebView?.postMessage(\n JSON.stringify({ type: "log", body: { method: "warn", args: message } }),\n );\n originalConsoleWarn.apply(console, arguments);\n };\n};\n');
|
|
481
483
|
var handleLog = function(type, message) {
|
|
482
484
|
var _JSON_parse = _to_array(JSON.parse(message)), formatMessage = _JSON_parse[0], parsedMessage = _JSON_parse.slice(1);
|
|
483
485
|
var webviewMark = "(WebView) ";
|
|
@@ -509,7 +511,7 @@ var handleLog = function(type, message) {
|
|
|
509
511
|
}
|
|
510
512
|
};
|
|
511
513
|
// src/integrations/handleRegisterWebMethod.ts
|
|
512
|
-
import { createRandomId, createResolver, timeout } from "@webview-bridge/utils";
|
|
514
|
+
import { createRandomId as createRandomId2, createResolver, timeout } from "@webview-bridge/utils";
|
|
513
515
|
// src/error.ts
|
|
514
516
|
var WebMethodError = /*#__PURE__*/ function(Error1) {
|
|
515
517
|
"use strict";
|
|
@@ -535,7 +537,7 @@ var handleRegisterWebMethod = function(emitter, webview, bridgeNames, responseTi
|
|
|
535
537
|
for(_len = _arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
536
538
|
args[_key] = _arguments[_key];
|
|
537
539
|
}
|
|
538
|
-
eventId =
|
|
540
|
+
eventId = createRandomId2();
|
|
539
541
|
return [
|
|
540
542
|
2,
|
|
541
543
|
Promise.race([
|
|
@@ -557,6 +559,7 @@ var handleRegisterWebMethod = function(emitter, webview, bridgeNames, responseTi
|
|
|
557
559
|
}, {});
|
|
558
560
|
};
|
|
559
561
|
// src/createWebView.tsx
|
|
562
|
+
import { jsx } from "react/jsx-runtime";
|
|
560
563
|
var createWebView = function(param) {
|
|
561
564
|
var bridge2 = param.bridge, debug = param.debug, _param_responseTimeout = param.responseTimeout, responseTimeout = _param_responseTimeout === void 0 ? 2e3 : _param_responseTimeout, postMessageSchema2 = param.postMessageSchema, fallback = param.fallback;
|
|
562
565
|
var WebMethod = {
|
|
@@ -770,7 +773,7 @@ var createWebView = function(param) {
|
|
|
770
773
|
return _ref.apply(this, arguments);
|
|
771
774
|
};
|
|
772
775
|
}();
|
|
773
|
-
return /* @__PURE__ */
|
|
776
|
+
return /* @__PURE__ */ jsx(WebView, _object_spread_props(_object_spread({}, props), {
|
|
774
777
|
ref: webviewRef,
|
|
775
778
|
onMessage: handleMessage,
|
|
776
779
|
injectedJavaScriptBeforeContentLoaded: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webview-bridge/react-native",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Fully Type-Safe Integration for React Native WebView and Web",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"react-native-webview": "*"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@webview-bridge/utils": "1.7.
|
|
43
|
-
"@webview-bridge/types": "1.7.
|
|
42
|
+
"@webview-bridge/utils": "1.7.7",
|
|
43
|
+
"@webview-bridge/types": "1.7.7",
|
|
44
44
|
"use-sync-external-store": "^1.2.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
|
-
"build": "tsup
|
|
47
|
+
"build": "tsup --config ./tsup.config.ts",
|
|
48
48
|
"test:type": "tsc --noEmit",
|
|
49
49
|
"lint": "biome check"
|
|
50
50
|
}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
import { createRandomId } from "@webview-bridge/utils";
|
|
2
|
+
|
|
3
|
+
// prevent name collision with other libraries
|
|
4
|
+
const injectionDetectKey = `__bridge_debug_injected_${createRandomId()}`;
|
|
5
|
+
|
|
1
6
|
export const INJECT_DEBUG = `
|
|
2
7
|
{
|
|
8
|
+
if (window["${injectionDetectKey}"]) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
window["${injectionDetectKey}"] = true;
|
|
3
13
|
const originalConsoleLog = console.log;
|
|
4
14
|
const originalConsoleError = console.error;
|
|
5
15
|
const originalConsoleWarn = console.warn;
|