catalyst-core 0.2.0-beta.2 → 0.3.0-beta.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/babel.native.config.cjs +8 -0
- package/bin/catalyst.js +49 -105
- package/changelog.md +8 -0
- package/dist/caching.js +1 -1
- package/dist/index.jsx +8 -0
- package/dist/logger.js +74 -3
- package/dist/native/androidProject/app/build.gradle.kts +1 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CustomWebview.kt +143 -4
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MainActivity.kt +26 -6
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MetricsMonitor.kt +143 -17
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/NativeBridge.kt +6 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/WebCacheManager.kt +26 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/BridgeUtils.kt +56 -1
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/KeyboardUtil.kt +48 -8
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/PerfDeliveryState.kt +36 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/PerfEventBuffer.kt +289 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/ProfilerNavigationState.kt +13 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/ProfilerLifecycleTest.kt +51 -0
- package/dist/native/androidSetup.js +300 -8
- package/dist/native/bridge/WebBridge.js +481 -59
- package/dist/native/bridge/constants/NativeInterfaces.js +290 -44
- package/dist/native/bridge/errors.js +250 -26
- package/dist/native/bridge/hooks/index.js +125 -1
- package/dist/native/bridge/hooks/useCamera.js +347 -9
- package/dist/native/bridge/hooks/useDataProtection.js +200 -2
- package/dist/native/bridge/hooks/useDeviceInfo.js +71 -2
- package/dist/native/bridge/hooks/useFilePicker.js +429 -2
- package/dist/native/bridge/hooks/useGoogleSignIn.js +81 -1
- package/dist/native/bridge/hooks/useHapticFeedback.js +196 -1
- package/dist/native/bridge/hooks/useIntent.js +95 -1
- package/dist/native/bridge/hooks/useNativeTransition.js +202 -27
- package/dist/native/bridge/hooks/useNetworkStatus.js +84 -3
- package/dist/native/bridge/hooks/useNotification.js +318 -2
- package/dist/native/bridge/hooks/useSafeArea.js +84 -2
- package/dist/native/bridge/hooks/useVideoStream.js +434 -6
- package/dist/native/bridge/hooks/utils.js +27 -1
- package/dist/native/bridge/hooks.js +16 -1
- package/dist/native/bridge/perf/collectors/ApiCollector.js +85 -0
- package/dist/native/bridge/perf/collectors/CacheCollector.js +215 -0
- package/dist/native/bridge/perf/collectors/HookCollector.js +165 -0
- package/dist/native/bridge/perf/collectors/InsightsCollector.js +505 -0
- package/dist/native/bridge/perf/collectors/InteractionCollector.js +273 -0
- package/dist/native/bridge/perf/collectors/KeyboardCollector.js +124 -0
- package/dist/native/bridge/perf/collectors/NavigationCollector.js +294 -0
- package/dist/native/bridge/perf/collectors/NetworkTimingCollector.js +183 -0
- package/dist/native/bridge/perf/collectors/RenderCollector.js +284 -0
- package/dist/native/bridge/perf/collectors/ScrollCollector.js +111 -0
- package/dist/native/bridge/perf/collectors/ThreadCollector.js +111 -0
- package/dist/native/bridge/perf/core/constants.js +126 -0
- package/dist/native/bridge/perf/core/measure.js +189 -0
- package/dist/native/bridge/perf/core/session.js +100 -0
- package/dist/native/bridge/perf/core/store.js +554 -0
- package/dist/native/bridge/perf/core/summary.js +174 -0
- package/dist/native/bridge/perf/core/traceExport.js +240 -0
- package/dist/native/bridge/perf/core/waterfalls.js +146 -0
- package/dist/native/bridge/perf/index.js +402 -0
- package/dist/native/bridge/safeArea.js +53 -5
- package/dist/native/bridge/standardizedHooks.js +595 -82
- package/dist/native/bridge/useBaseHook.js +274 -38
- package/dist/native/bridge/utils/CameraUtils.js +201 -56
- package/dist/native/bridge/utils/FileObjectConverter.js +129 -18
- package/dist/native/bridge/utils/NativeBridge.js +425 -141
- package/dist/native/buildAndroid/assets.js +510 -13
- package/dist/native/buildAndroid/build.js +296 -19
- package/dist/native/buildAndroid/config.js +87 -1
- package/dist/native/buildAndroid/index.js +374 -1
- package/dist/native/buildAppAndroid.js +34 -2
- package/dist/native/buildAppIos.js +62 -2
- package/dist/native/buildIos/assets.js +609 -8
- package/dist/native/buildIos/build.js +639 -20
- package/dist/native/buildIos/config.js +294 -12
- package/dist/native/buildIos/index.js +343 -6
- package/dist/native/buildIos/plugins.js +343 -16
- package/dist/native/internal-plugins/device-info-plugin/android/DeviceInfoPlugin.kt +43 -0
- package/dist/native/internal-plugins/device-info-plugin/ios/DeviceInfoPlugin.swift +28 -0
- package/dist/native/internal-plugins/device-info-plugin/manifest.json +19 -0
- package/dist/native/internalPluginUtils.js +232 -7
- package/dist/native/iosnativeWebView/Sources/Core/Constants/CatalystConstants.swift +19 -0
- package/dist/native/iosnativeWebView/Sources/Core/Constants/ConfigConstants.swift +4 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/BootTimingUtility.swift +5 -1
- package/dist/native/iosnativeWebView/Sources/Core/Utils/CacheManager.swift +10 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/DisplayLinkPerfMonitor.swift +89 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/PerfEventBuffer.swift +373 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeFileHandler.swift +35 -1
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeMessageValidator.swift +24 -11
- package/dist/native/iosnativeWebView/Sources/Core/WebView/NativeBridge.swift +9 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebView.swift +126 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewNavigationDelegate.swift +75 -1
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeMessageValidatorTests.swift +13 -0
- package/dist/native/package.json +3 -0
- package/dist/native/plugin-bridge/PluginBridge.js +227 -1
- package/dist/native/pluginComposerAndroid.js +407 -23
- package/dist/native/pluginComposerIos.js +435 -11
- package/dist/native/renameAndroidProject.js +1094 -88
- package/dist/native/setupEmulatorIos.js +289 -22
- package/dist/native/setupServer.js +160 -19
- package/dist/native/terminalProgress.js +199 -11
- package/dist/native/utils.js +193 -15
- package/dist/offline/catalyst-sw.js +145 -1
- package/dist/offline/registerServiceWorker.js +33 -1
- package/dist/otel.js +375 -46
- package/dist/router/ClientRouter.js +14 -2
- package/dist/router/ServerRouter.js +9 -1
- package/dist/router.js +1 -1
- package/dist/scripts/build.js +112 -3
- package/dist/scripts/checkVersion.js +3 -1
- package/dist/scripts/cleanCache.js +30 -1
- package/dist/scripts/generateOfflineManifest.js +116 -1
- package/dist/scripts/loadEnvironmentVariables.js +32 -6
- package/dist/scripts/plugins.js +309 -1
- package/dist/scripts/preServerInit.js +13 -0
- package/dist/scripts/scriptUtils.js +54 -3
- package/dist/scripts/serve.js +51 -4
- package/dist/scripts/start.js +47 -10
- package/dist/scripts/validator.js +149 -1
- package/dist/sentry.cjs +127 -0
- package/dist/sentry.js +125 -5
- package/dist/server/expressServer.js +250 -5
- package/dist/server/manifestCache.js +36 -0
- package/dist/server/renderer/ChunkExtractor.js +144 -0
- package/dist/server/renderer/document/Body.jsx +59 -0
- package/dist/server/renderer/document/FastRefresh.jsx +20 -0
- package/dist/server/renderer/document/Head.jsx +60 -0
- package/dist/server/renderer/document/index.jsx +2 -0
- package/dist/server/renderer/extract.js +149 -31
- package/dist/server/renderer/handler.jsx +433 -0
- package/dist/server/renderer/index.js +8 -1
- package/dist/server/renderer/render.js +47 -0
- package/dist/server/utils/botDetectionMiddleware.js +29 -0
- package/dist/server/utils/cjsRequire.js +10 -0
- package/dist/server/utils/userAgentUtil.js +87 -9
- package/dist/server/utils/validator.js +164 -1
- package/dist/vite/FastRefresh.jsx +20 -0
- package/dist/vite/inject-cache-key-plugin.js +276 -0
- package/dist/vite/loadCustomViteConfig.js +22 -0
- package/dist/vite/manifest-categorization-plugin.js +455 -0
- package/dist/vite/node-loader.mjs +458 -0
- package/dist/vite/scssParams.js +21 -0
- package/dist/vite/vite.config.client.js +130 -0
- package/dist/vite/vite.config.js +422 -0
- package/dist/vite/vite.config.server.js +84 -0
- package/dist/web-router/components/MetaTag.jsx +34 -0
- package/dist/web-router/components/RouterDataProvider.jsx +332 -0
- package/dist/web-router/components/Split.jsx +200 -0
- package/dist/web-router/components/SplitInview.jsx +106 -0
- package/dist/web-router/components/SsrRequestContext.jsx +14 -0
- package/dist/web-router/context.jsx +12 -0
- package/dist/web-router/hooks.jsx +72 -0
- package/dist/web-router/types/components/MetaTag.d.ts +2 -0
- package/dist/web-router/types/components/RouterDataProvider.d.ts +95 -0
- package/dist/web-router/types/context.d.ts +14 -0
- package/dist/web-router/types/hooks.d.ts +1 -0
- package/dist/web-router/types/index.d.ts +3 -0
- package/dist/web-router/types/utils/metaDataUtils.d.ts +24 -0
- package/dist/web-router/utils/metaDataUtils.jsx +119 -0
- package/mcp_v2/conversion-tasks.json +35 -17
- package/mcp_v2/knowledge-base.json +124 -13
- package/mcp_v2/lib/helpers.js +10 -0
- package/mcp_v2/mcp.js +4 -4
- package/mcp_v2/package.json +1 -0
- package/mcp_v2/tools/build.js +116 -20
- package/mcp_v2/tools/conversion.js +106 -5
- package/mcp_v2/tools/tasks.js +18 -14
- package/package.json +35 -68
- package/babel.config.js +0 -32
- package/dist/index.js +0 -1
- package/dist/scripts/devBuild.js +0 -3
- package/dist/scripts/devServe.js +0 -3
- package/dist/scripts/loadScriptsBeforeServerStarts.js +0 -4
- package/dist/scripts/registerAliases.js +0 -6
- package/dist/server/renderer/document/Body.js +0 -11
- package/dist/server/renderer/document/Head.js +0 -9
- package/dist/server/renderer/document/index.js +0 -1
- package/dist/server/renderer/handler.js +0 -47
- package/dist/server/startServer.js +0 -57
- package/dist/webpack/babel-plugins/remove-client.plugin.js +0 -5
- package/dist/webpack/babel-plugins/remove-ssr.plugin.js +0 -5
- package/dist/webpack/babel.config.client.js +0 -1
- package/dist/webpack/babel.config.ssr.js +0 -1
- package/dist/webpack/base.babel.js +0 -7
- package/dist/webpack/development.client.babel.js +0 -10
- package/dist/webpack/production.client.babel.js +0 -4
- package/dist/webpack/production.ssr.babel.js +0 -8
- package/dist/webpack/scssParams.js +0 -9
|
@@ -1,2 +1,318 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useNotificationPermission = exports.useNotification = exports.requestNotificationPermission = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _NativeBridge = _interopRequireDefault(require("../utils/NativeBridge.js"));
|
|
9
|
+
var _NativeInterfaces = require("../constants/NativeInterfaces.js");
|
|
10
|
+
var _useBaseHook = require("../useBaseHook.js");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
/* eslint-disable react-compiler/react-compiler, react-hooks/exhaustive-deps */
|
|
13
|
+
|
|
14
|
+
// Shared callback system — allows hook + requestNotificationPermission to share one WebBridge listener
|
|
15
|
+
const permissionStatusListeners = new Set();
|
|
16
|
+
let isPermissionCallbackRegistered = false;
|
|
17
|
+
const registerPermissionStatusListener = callback => {
|
|
18
|
+
permissionStatusListeners.add(callback);
|
|
19
|
+
if (!isPermissionCallbackRegistered && typeof window !== "undefined" && window.WebBridge) {
|
|
20
|
+
isPermissionCallbackRegistered = true;
|
|
21
|
+
window.WebBridge.register(_NativeInterfaces.NATIVE_CALLBACKS.NOTIFICATION_PERMISSION_STATUS, data => {
|
|
22
|
+
permissionStatusListeners.forEach(listener => {
|
|
23
|
+
try {
|
|
24
|
+
listener(data);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error("Error in permission status listener:", error);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return () => {
|
|
32
|
+
permissionStatusListeners.delete(callback);
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const unregisterPermissionStatusListener = callback => {
|
|
36
|
+
permissionStatusListeners.delete(callback);
|
|
37
|
+
};
|
|
38
|
+
const requestNotificationPermission = () => {
|
|
39
|
+
if (typeof window === "undefined") {
|
|
40
|
+
return Promise.resolve(null);
|
|
41
|
+
}
|
|
42
|
+
if (!window.WebBridge) {
|
|
43
|
+
throw new Error("WebBridge is not initialized. Call WebBridge.init() first.");
|
|
44
|
+
}
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
try {
|
|
47
|
+
if (!_NativeBridge.default.isAvailable()) {
|
|
48
|
+
reject(new Error("Native bridge not available"));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const handlePermissionStatus = data => {
|
|
52
|
+
unregisterPermissionStatusListener(handlePermissionStatus);
|
|
53
|
+
if (data === _NativeInterfaces.PERMISSION_STATUS.GRANTED) {
|
|
54
|
+
resolve(data);
|
|
55
|
+
} else {
|
|
56
|
+
reject(new Error(`Notification permission ${data.toLowerCase()}`));
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
registerPermissionStatusListener(handlePermissionStatus);
|
|
60
|
+
_NativeBridge.default.notification.requestPermission();
|
|
61
|
+
} catch (error) {
|
|
62
|
+
reject(error);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
exports.requestNotificationPermission = requestNotificationPermission;
|
|
67
|
+
const useNotificationPermission = () => {
|
|
68
|
+
if (typeof window === "undefined") {
|
|
69
|
+
return {
|
|
70
|
+
permission: null,
|
|
71
|
+
isLoading: false
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (!window.WebBridge) {
|
|
75
|
+
throw new Error("WebBridge is not initialized. Call WebBridge.init() first.");
|
|
76
|
+
}
|
|
77
|
+
const [permission, setPermission] = (0, _react.useState)(null);
|
|
78
|
+
const [isLoading, setIsLoading] = (0, _react.useState)(true);
|
|
79
|
+
(0, _react.useEffect)(() => {
|
|
80
|
+
const requestPermission = async () => {
|
|
81
|
+
try {
|
|
82
|
+
if (!_NativeBridge.default.isAvailable()) {
|
|
83
|
+
setPermission(_NativeInterfaces.PERMISSION_STATUS.NOT_DETERMINED);
|
|
84
|
+
setIsLoading(false);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
window.WebBridge.register(_NativeInterfaces.NATIVE_CALLBACKS.NOTIFICATION_PERMISSION_STATUS, data => {
|
|
88
|
+
setPermission(data);
|
|
89
|
+
setIsLoading(false);
|
|
90
|
+
console.log("🔔 Notification permission status updated:", data);
|
|
91
|
+
});
|
|
92
|
+
_NativeBridge.default.notification.requestPermission();
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error("🔔 Error requesting notification permission:", error);
|
|
95
|
+
setPermission(_NativeInterfaces.PERMISSION_STATUS.DENIED);
|
|
96
|
+
setIsLoading(false);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
requestPermission();
|
|
100
|
+
return () => {
|
|
101
|
+
window.WebBridge.unregister(_NativeInterfaces.NATIVE_CALLBACKS.NOTIFICATION_PERMISSION_STATUS);
|
|
102
|
+
};
|
|
103
|
+
}, []);
|
|
104
|
+
return {
|
|
105
|
+
permission,
|
|
106
|
+
isLoading
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
exports.useNotificationPermission = useNotificationPermission;
|
|
110
|
+
const useNotification = () => {
|
|
111
|
+
const base = (0, _useBaseHook.useBaseHook)("useNotification");
|
|
112
|
+
const [permissionStatus, setPermissionStatus] = (0, _react.useState)(null);
|
|
113
|
+
const [pushToken, setPushToken] = (0, _react.useState)(null);
|
|
114
|
+
const [badges, setBadges] = (0, _react.useState)(0);
|
|
115
|
+
const [lastNotification, setLastNotification] = (0, _react.useState)(null);
|
|
116
|
+
const [subscribedTopics, setSubscribedTopics] = (0, _react.useState)([]);
|
|
117
|
+
if (typeof window === "undefined") {
|
|
118
|
+
return {
|
|
119
|
+
data: null,
|
|
120
|
+
loading: false,
|
|
121
|
+
error: null,
|
|
122
|
+
execute: () => {},
|
|
123
|
+
scheduleLocal: () => {},
|
|
124
|
+
cancelLocal: () => {},
|
|
125
|
+
registerForPush: () => {},
|
|
126
|
+
updateBadge: () => {},
|
|
127
|
+
subscribeToTopic: () => {},
|
|
128
|
+
unsubscribeFromTopic: () => {},
|
|
129
|
+
getSubscribedTopics: () => {},
|
|
130
|
+
permissionStatus: null,
|
|
131
|
+
pushToken: null,
|
|
132
|
+
badges: 0,
|
|
133
|
+
subscribedTopics: []
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (!window.WebBridge) {
|
|
137
|
+
throw new Error("WebBridge is not initialized. Call WebBridge.init() first.");
|
|
138
|
+
}
|
|
139
|
+
(0, _react.useEffect)(() => {
|
|
140
|
+
const unregister = registerPermissionStatusListener(data => {
|
|
141
|
+
setPermissionStatus(data);
|
|
142
|
+
});
|
|
143
|
+
if (_NativeBridge.default.isAvailable()) {
|
|
144
|
+
try {
|
|
145
|
+
if (_NativeBridge.default.isAndroid && window.NativeBridge?.checkNotificationPermissionStatus) {
|
|
146
|
+
window.NativeBridge.checkNotificationPermissionStatus(null);
|
|
147
|
+
} else if (_NativeBridge.default.isIOS && window.webkit?.messageHandlers?.NativeBridge) {
|
|
148
|
+
window.webkit.messageHandlers.NativeBridge.postMessage({
|
|
149
|
+
command: "checkNotificationPermissionStatus",
|
|
150
|
+
data: null
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
} catch (error) {
|
|
154
|
+
console.error("🔔 Error checking notification permission status:", error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
window.WebBridge.register(_NativeInterfaces.NATIVE_CALLBACKS.LOCAL_NOTIFICATION_SCHEDULED, data => {
|
|
158
|
+
try {
|
|
159
|
+
const result = typeof data === "string" ? JSON.parse(data) : data;
|
|
160
|
+
if (result?.success === false || result?.error) {
|
|
161
|
+
base.handleNativeError(result.error || result);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
base.setDataAndComplete(result);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
base.handleNativeError(error);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
window.WebBridge.register(_NativeInterfaces.NATIVE_CALLBACKS.LOCAL_NOTIFICATION_CANCELLED, data => {
|
|
170
|
+
try {
|
|
171
|
+
const result = typeof data === "string" ? JSON.parse(data) : data;
|
|
172
|
+
if (result?.success === false || result?.error) {
|
|
173
|
+
base.handleNativeError(result.error || result);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
base.setDataAndComplete(result);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
base.handleNativeError(error);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
window.WebBridge.register(_NativeInterfaces.NATIVE_CALLBACKS.PUSH_NOTIFICATION_TOKEN, data => {
|
|
182
|
+
try {
|
|
183
|
+
const result = typeof data === "string" ? JSON.parse(data) : data;
|
|
184
|
+
if (result?.error) {
|
|
185
|
+
base.handleNativeError(result.error);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
setPushToken(result.token);
|
|
189
|
+
base.setDataAndComplete(result);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
base.handleNativeError(error);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
window.WebBridge.register(_NativeInterfaces.NATIVE_CALLBACKS.NOTIFICATION_RECEIVED, data => {
|
|
195
|
+
const notification = typeof data === "string" ? JSON.parse(data) : data;
|
|
196
|
+
setLastNotification(notification);
|
|
197
|
+
});
|
|
198
|
+
window.WebBridge.register(_NativeInterfaces.NATIVE_CALLBACKS.NOTIFICATION_TAPPED, data => {
|
|
199
|
+
try {
|
|
200
|
+
const result = typeof data === "string" ? JSON.parse(data) : data;
|
|
201
|
+
base.setDataAndComplete(result);
|
|
202
|
+
} catch (error) {
|
|
203
|
+
base.handleNativeError(error);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
window.WebBridge.register(_NativeInterfaces.NATIVE_CALLBACKS.NOTIFICATION_ACTION_PERFORMED, data => {
|
|
207
|
+
const action = typeof data === "string" ? JSON.parse(data) : data;
|
|
208
|
+
base.setDataAndComplete(action);
|
|
209
|
+
});
|
|
210
|
+
window.WebBridge.register(_NativeInterfaces.NATIVE_CALLBACKS.TOPIC_SUBSCRIPTION_RESULT, data => {
|
|
211
|
+
try {
|
|
212
|
+
const result = typeof data === "string" ? JSON.parse(data) : data;
|
|
213
|
+
if (result?.error) {
|
|
214
|
+
base.handleNativeError(result.error);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (result?.success === false) {
|
|
218
|
+
base.handleNativeError(result);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
base.setDataAndComplete(result);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
base.handleNativeError(error);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
window.WebBridge.register(_NativeInterfaces.NATIVE_CALLBACKS.SUBSCRIBED_TOPICS_RESULT, data => {
|
|
227
|
+
try {
|
|
228
|
+
const result = typeof data === "string" ? JSON.parse(data) : data;
|
|
229
|
+
if (result?.error) {
|
|
230
|
+
base.handleNativeError(result.error);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (result?.success === false) {
|
|
234
|
+
base.handleNativeError(result);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
setSubscribedTopics(result.topics || []);
|
|
238
|
+
base.setDataAndComplete(result);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
base.handleNativeError(error);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
return () => {
|
|
244
|
+
unregister();
|
|
245
|
+
window.WebBridge.unregister(_NativeInterfaces.NATIVE_CALLBACKS.LOCAL_NOTIFICATION_SCHEDULED);
|
|
246
|
+
window.WebBridge.unregister(_NativeInterfaces.NATIVE_CALLBACKS.LOCAL_NOTIFICATION_CANCELLED);
|
|
247
|
+
window.WebBridge.unregister(_NativeInterfaces.NATIVE_CALLBACKS.PUSH_NOTIFICATION_TOKEN);
|
|
248
|
+
window.WebBridge.unregister(_NativeInterfaces.NATIVE_CALLBACKS.NOTIFICATION_RECEIVED);
|
|
249
|
+
window.WebBridge.unregister(_NativeInterfaces.NATIVE_CALLBACKS.NOTIFICATION_TAPPED);
|
|
250
|
+
window.WebBridge.unregister(_NativeInterfaces.NATIVE_CALLBACKS.NOTIFICATION_ACTION_PERFORMED);
|
|
251
|
+
window.WebBridge.unregister(_NativeInterfaces.NATIVE_CALLBACKS.TOPIC_SUBSCRIPTION_RESULT);
|
|
252
|
+
window.WebBridge.unregister(_NativeInterfaces.NATIVE_CALLBACKS.SUBSCRIBED_TOPICS_RESULT);
|
|
253
|
+
};
|
|
254
|
+
}, []);
|
|
255
|
+
const requestPermission = () => {
|
|
256
|
+
requestNotificationPermission().catch(err => base.handleNativeError(err));
|
|
257
|
+
};
|
|
258
|
+
const scheduleLocal = config => {
|
|
259
|
+
base.executeOperation(() => {
|
|
260
|
+
_NativeBridge.default.notification.scheduleLocal(config);
|
|
261
|
+
}, "schedule local notification");
|
|
262
|
+
};
|
|
263
|
+
const cancelLocal = notificationId => {
|
|
264
|
+
base.executeOperation(() => {
|
|
265
|
+
_NativeBridge.default.notification.cancelLocal(notificationId);
|
|
266
|
+
}, "cancel notification");
|
|
267
|
+
};
|
|
268
|
+
const registerForPush = () => {
|
|
269
|
+
base.executeOperation(() => {
|
|
270
|
+
_NativeBridge.default.notification.registerForPush();
|
|
271
|
+
}, "register for push");
|
|
272
|
+
};
|
|
273
|
+
const updateBadge = count => {
|
|
274
|
+
base.callNative(() => _NativeBridge.default.notification.updateBadge(count));
|
|
275
|
+
setBadges(count);
|
|
276
|
+
};
|
|
277
|
+
const subscribeToTopic = topic => {
|
|
278
|
+
base.executeOperation(() => {
|
|
279
|
+
_NativeBridge.default.notification.subscribeToTopic(topic);
|
|
280
|
+
}, "subscribe to topic");
|
|
281
|
+
};
|
|
282
|
+
const unsubscribeFromTopic = topic => {
|
|
283
|
+
base.executeOperation(() => {
|
|
284
|
+
_NativeBridge.default.notification.unsubscribeFromTopic(topic);
|
|
285
|
+
}, "unsubscribe from topic");
|
|
286
|
+
};
|
|
287
|
+
const getSubscribedTopics = () => {
|
|
288
|
+
base.executeOperation(() => {
|
|
289
|
+
_NativeBridge.default.notification.getSubscribedTopics();
|
|
290
|
+
}, "get subscribed topics");
|
|
291
|
+
};
|
|
292
|
+
return {
|
|
293
|
+
data: base.data,
|
|
294
|
+
loading: base.loading,
|
|
295
|
+
progress: base.progress,
|
|
296
|
+
error: base.error,
|
|
297
|
+
execute: scheduleLocal,
|
|
298
|
+
clear: base.clear,
|
|
299
|
+
clearError: base.clearError,
|
|
300
|
+
isNative: base.isNative,
|
|
301
|
+
isWeb: base.isWeb,
|
|
302
|
+
permissionStatus,
|
|
303
|
+
pushToken,
|
|
304
|
+
badges,
|
|
305
|
+
lastNotification,
|
|
306
|
+
subscribedTopics,
|
|
307
|
+
scheduleLocal,
|
|
308
|
+
cancelLocal,
|
|
309
|
+
registerForPush,
|
|
310
|
+
updateBadge,
|
|
311
|
+
subscribeToTopic,
|
|
312
|
+
unsubscribeFromTopic,
|
|
313
|
+
getSubscribedTopics,
|
|
314
|
+
schedule: scheduleLocal,
|
|
315
|
+
requestPermission
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
exports.useNotification = useNotification;
|
|
@@ -1,2 +1,84 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useSafeArea = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _NativeBridge = _interopRequireDefault(require("../utils/NativeBridge.js"));
|
|
9
|
+
var _safeArea = require("../safeArea.js");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
/* eslint-disable react-compiler/react-compiler, react-hooks/exhaustive-deps */
|
|
12
|
+
|
|
13
|
+
const useSafeArea = ({
|
|
14
|
+
webFallback
|
|
15
|
+
} = {}) => {
|
|
16
|
+
const fromGlobal = (0, _safeArea.getSafeAreaFromGlobal)();
|
|
17
|
+
const initialValue = fromGlobal || {
|
|
18
|
+
..._safeArea.DEFAULT_INSETS
|
|
19
|
+
};
|
|
20
|
+
const [insets, setInsets] = (0, _react.useState)(() => initialValue);
|
|
21
|
+
const isNative = _NativeBridge.default.isAvailable();
|
|
22
|
+
const [webFallbackState, setWebFallback] = (0, _react.useState)(true);
|
|
23
|
+
const webFallbackResolved = webFallback !== undefined ? webFallback !== false : webFallbackState;
|
|
24
|
+
const webFallbackActive = !isNative && webFallbackResolved;
|
|
25
|
+
const webFallbackDisabled = !isNative && !webFallbackResolved;
|
|
26
|
+
(0, _react.useEffect)(() => {
|
|
27
|
+
if (typeof window === "undefined") return;
|
|
28
|
+
if (!_NativeBridge.default.isAvailable()) {
|
|
29
|
+
if (webFallbackDisabled) return;
|
|
30
|
+
|
|
31
|
+
// Web fallback: read CSS env() safe area insets (Safari notch support)
|
|
32
|
+
const readCSSInsets = () => {
|
|
33
|
+
const style = getComputedStyle(document.documentElement);
|
|
34
|
+
const read = prop => {
|
|
35
|
+
const val = style.getPropertyValue(prop).trim();
|
|
36
|
+
return val ? parseFloat(val) || 0 : 0;
|
|
37
|
+
};
|
|
38
|
+
const webInsets = {
|
|
39
|
+
top: read("--sat") || read("env(safe-area-inset-top)"),
|
|
40
|
+
right: read("--sar") || read("env(safe-area-inset-right)"),
|
|
41
|
+
bottom: read("--sab") || read("env(safe-area-inset-bottom)"),
|
|
42
|
+
left: read("--sal") || read("env(safe-area-inset-left)")
|
|
43
|
+
};
|
|
44
|
+
setInsets(webInsets);
|
|
45
|
+
(0, _safeArea.setSafeAreaGlobal)(webInsets);
|
|
46
|
+
};
|
|
47
|
+
const id = setTimeout(readCSSInsets, 0);
|
|
48
|
+
return () => clearTimeout(id);
|
|
49
|
+
}
|
|
50
|
+
if (!window.WebBridge) return;
|
|
51
|
+
const handleInsetsUpdate = data => {
|
|
52
|
+
try {
|
|
53
|
+
const parsed = typeof data === "string" ? JSON.parse(data) : data;
|
|
54
|
+
const normalized = {
|
|
55
|
+
top: Number(parsed.top) || 0,
|
|
56
|
+
right: Number(parsed.right) || 0,
|
|
57
|
+
bottom: Number(parsed.bottom) || 0,
|
|
58
|
+
left: Number(parsed.left) || 0
|
|
59
|
+
};
|
|
60
|
+
setInsets(normalized);
|
|
61
|
+
(0, _safeArea.setSafeAreaGlobal)(normalized);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error("Error parsing safe area insets:", error);
|
|
64
|
+
setInsets({
|
|
65
|
+
..._safeArea.DEFAULT_INSETS
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
window.WebBridge.register("ON_SAFE_AREA_INSETS_UPDATED", handleInsetsUpdate);
|
|
70
|
+
_NativeBridge.default.safeArea.get();
|
|
71
|
+
return () => {
|
|
72
|
+
window.WebBridge.unregister("ON_SAFE_AREA_INSETS_UPDATED");
|
|
73
|
+
};
|
|
74
|
+
}, [webFallbackDisabled]);
|
|
75
|
+
return {
|
|
76
|
+
...insets,
|
|
77
|
+
isNative,
|
|
78
|
+
isWeb: !isNative,
|
|
79
|
+
webFallbackActive,
|
|
80
|
+
webFallbackDisabled,
|
|
81
|
+
setWebFallback
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
exports.useSafeArea = useSafeArea;
|