@webview-bridge/react-native 1.7.3 → 1.7.4

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 CHANGED
@@ -561,14 +561,14 @@ var INJECT_BRIDGE_STATE = function(initialState) {
561
561
  };
562
562
  var SAFE_NATIVE_EMITTER_EMIT = function(eventName, data) {
563
563
  var dataString = JSON.stringify(data);
564
- return "\nif (window.nativeEmitter && Object.keys(window.nativeEmitter).length > 0) {\n for (const [_, emitter] of Object.entries(window.nativeEmitter)) {\n emitter.emit('".concat(eventName, "', ").concat(dataString, ");\n }\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', ").concat(dataString, "]);\n}\ntrue;\n");
564
+ return "\nif (window.nativeEmitterMap && Object.keys(window.nativeEmitterMap).length > 0) {\n for (const [_, emitter] of Object.entries(window.nativeEmitterMap)) {\n emitter.emit('".concat(eventName, "', ").concat(dataString, ");\n }\n} else if (window.nativeEmitter) {\n // @deprecated This version is not used after 1.7.2\n window.nativeEmitter.emit('").concat(eventName, "', ").concat(dataString, ");\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', ").concat(dataString, "]);\n}\ntrue;\n");
565
565
  };
566
566
  var SAFE_NATIVE_EMITTER_EMIT_BY_BRIDGE_ID = function(bridgeId, eventName, data) {
567
567
  var dataString = JSON.stringify(data);
568
- return "\nif (window.nativeEmitter && window.nativeEmitter['".concat(bridgeId, "']) {\n window.nativeEmitter['").concat(bridgeId, "'].emit('").concat(eventName, "', ").concat(dataString, ");\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', ").concat(dataString, "]);\n}\ntrue;\n");
568
+ return "\nif (window.nativeEmitterMap && window.nativeEmitterMap['".concat(bridgeId, "']) {\n window.nativeEmitterMap['").concat(bridgeId, "'].emit('").concat(eventName, "', ").concat(dataString, ");\n} else if (window.nativeEmitter) {\n // @deprecated This version is not used after 1.7.2\n window.nativeEmitter.emit('").concat(eventName, "', ").concat(dataString, ");\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', ").concat(dataString, "]);\n}\ntrue;\n");
569
569
  };
570
570
  var SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID = function(bridgeId, eventName) {
571
- return "\nif (window.nativeEmitter['".concat(bridgeId, "']) {\n window.nativeEmitter['").concat(bridgeId, "'].emit('").concat(eventName, "', {}, true);\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', {}, true]);\n}\ntrue;\n");
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
574
  var INJECT_DEBUG = '\n{\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';
package/dist/index.js CHANGED
@@ -467,14 +467,14 @@ var INJECT_BRIDGE_STATE = function(initialState) {
467
467
  };
468
468
  var SAFE_NATIVE_EMITTER_EMIT = function(eventName, data) {
469
469
  var dataString = JSON.stringify(data);
470
- return "\nif (window.nativeEmitter && Object.keys(window.nativeEmitter).length > 0) {\n for (const [_, emitter] of Object.entries(window.nativeEmitter)) {\n emitter.emit('".concat(eventName, "', ").concat(dataString, ");\n }\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', ").concat(dataString, "]);\n}\ntrue;\n");
470
+ return "\nif (window.nativeEmitterMap && Object.keys(window.nativeEmitterMap).length > 0) {\n for (const [_, emitter] of Object.entries(window.nativeEmitterMap)) {\n emitter.emit('".concat(eventName, "', ").concat(dataString, ");\n }\n} else if (window.nativeEmitter) {\n // @deprecated This version is not used after 1.7.2\n window.nativeEmitter.emit('").concat(eventName, "', ").concat(dataString, ");\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', ").concat(dataString, "]);\n}\ntrue;\n");
471
471
  };
472
472
  var SAFE_NATIVE_EMITTER_EMIT_BY_BRIDGE_ID = function(bridgeId, eventName, data) {
473
473
  var dataString = JSON.stringify(data);
474
- return "\nif (window.nativeEmitter && window.nativeEmitter['".concat(bridgeId, "']) {\n window.nativeEmitter['").concat(bridgeId, "'].emit('").concat(eventName, "', ").concat(dataString, ");\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', ").concat(dataString, "]);\n}\ntrue;\n");
474
+ return "\nif (window.nativeEmitterMap && window.nativeEmitterMap['".concat(bridgeId, "']) {\n window.nativeEmitterMap['").concat(bridgeId, "'].emit('").concat(eventName, "', ").concat(dataString, ");\n} else if (window.nativeEmitter) {\n // @deprecated This version is not used after 1.7.2\n window.nativeEmitter.emit('").concat(eventName, "', ").concat(dataString, ");\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', ").concat(dataString, "]);\n}\ntrue;\n");
475
475
  };
476
476
  var SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID = function(bridgeId, eventName) {
477
- return "\nif (window.nativeEmitter['".concat(bridgeId, "']) {\n window.nativeEmitter['").concat(bridgeId, "'].emit('").concat(eventName, "', {}, true);\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', {}, true]);\n}\ntrue;\n");
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
  var INJECT_DEBUG = '\n{\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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webview-bridge/react-native",
3
- "version": "1.7.3",
3
+ "version": "1.7.4",
4
4
  "type": "module",
5
5
  "description": "Fully Type-Safe Integration for React Native WebView and Web",
6
6
  "main": "dist/index.cjs",
@@ -39,8 +39,8 @@
39
39
  "react-native-webview": "*"
40
40
  },
41
41
  "dependencies": {
42
- "@webview-bridge/utils": "1.7.3",
43
- "@webview-bridge/types": "1.7.3",
42
+ "@webview-bridge/utils": "1.7.4",
43
+ "@webview-bridge/types": "1.7.4",
44
44
  "use-sync-external-store": "^1.2.0"
45
45
  },
46
46
  "scripts": {
@@ -125,10 +125,13 @@ export const INJECT_BRIDGE_STATE = (
125
125
  export const SAFE_NATIVE_EMITTER_EMIT = (eventName: string, data: unknown) => {
126
126
  const dataString = JSON.stringify(data);
127
127
  return `
128
- if (window.nativeEmitter && Object.keys(window.nativeEmitter).length > 0) {
129
- for (const [_, emitter] of Object.entries(window.nativeEmitter)) {
128
+ if (window.nativeEmitterMap && Object.keys(window.nativeEmitterMap).length > 0) {
129
+ for (const [_, emitter] of Object.entries(window.nativeEmitterMap)) {
130
130
  emitter.emit('${eventName}', ${dataString});
131
131
  }
132
+ } else if (window.nativeEmitter) {
133
+ // @deprecated This version is not used after 1.7.2
134
+ window.nativeEmitter.emit('${eventName}', ${dataString});
132
135
  } else {
133
136
  window.nativeBatchedEvents = window.nativeBatchedEvents || [];
134
137
  window.nativeBatchedEvents.push(['${eventName}', ${dataString}]);
@@ -144,8 +147,11 @@ export const SAFE_NATIVE_EMITTER_EMIT_BY_BRIDGE_ID = (
144
147
  ) => {
145
148
  const dataString = JSON.stringify(data);
146
149
  return `
147
- if (window.nativeEmitter && window.nativeEmitter['${bridgeId}']) {
148
- window.nativeEmitter['${bridgeId}'].emit('${eventName}', ${dataString});
150
+ if (window.nativeEmitterMap && window.nativeEmitterMap['${bridgeId}']) {
151
+ window.nativeEmitterMap['${bridgeId}'].emit('${eventName}', ${dataString});
152
+ } else if (window.nativeEmitter) {
153
+ // @deprecated This version is not used after 1.7.2
154
+ window.nativeEmitter.emit('${eventName}', ${dataString});
149
155
  } else {
150
156
  window.nativeBatchedEvents = window.nativeBatchedEvents || [];
151
157
  window.nativeBatchedEvents.push(['${eventName}', ${dataString}]);
@@ -158,8 +164,11 @@ export const SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID = (
158
164
  bridgeId: string,
159
165
  eventName: string,
160
166
  ) => `
161
- if (window.nativeEmitter['${bridgeId}']) {
162
- window.nativeEmitter['${bridgeId}'].emit('${eventName}', {}, true);
167
+ if (window.nativeEmitterMap && window.nativeEmitterMap['${bridgeId}']) {
168
+ window.nativeEmitterMap['${bridgeId}'].emit('${eventName}', {}, true);
169
+ } else if (window.nativeEmitter) {
170
+ // @deprecated This version is not used after 1.7.2
171
+ window.nativeEmitter.emit('${eventName}', {}, true);
163
172
  } else {
164
173
  window.nativeBatchedEvents = window.nativeBatchedEvents || [];
165
174
  window.nativeBatchedEvents.push(['${eventName}', {}, true]);