@apps-in-toss/framework 1.4.5 → 1.4.6
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 +88 -27
- package/dist/index.js +88 -27
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -1594,25 +1594,20 @@ function useBridgeHandler({
|
|
|
1594
1594
|
onMessage,
|
|
1595
1595
|
constantHandlerMap,
|
|
1596
1596
|
asyncHandlerMap,
|
|
1597
|
-
eventListenerMap
|
|
1598
|
-
injectedJavaScript: originalInjectedJavaScript
|
|
1597
|
+
eventListenerMap
|
|
1599
1598
|
}) {
|
|
1600
1599
|
const ref = (0, import_react23.useRef)(null);
|
|
1601
1600
|
const injectedJavaScript = (0, import_react23.useMemo)(
|
|
1602
|
-
() =>
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
originalInjectedJavaScript,
|
|
1613
|
-
"true"
|
|
1614
|
-
].join("\n"),
|
|
1615
|
-
[constantHandlerMap, originalInjectedJavaScript]
|
|
1601
|
+
() => `window.__CONSTANT_HANDLER_MAP = ${JSON.stringify(
|
|
1602
|
+
Object.entries(constantHandlerMap).reduce(
|
|
1603
|
+
(acc, [key, value]) => {
|
|
1604
|
+
acc[key] = typeof value === "function" ? value() : value;
|
|
1605
|
+
return acc;
|
|
1606
|
+
},
|
|
1607
|
+
{}
|
|
1608
|
+
)
|
|
1609
|
+
)};`,
|
|
1610
|
+
[constantHandlerMap]
|
|
1616
1611
|
);
|
|
1617
1612
|
const createHandleOnEvent = (functionName, eventId) => (response) => {
|
|
1618
1613
|
ref.current?.injectJavaScript(`
|
|
@@ -1628,7 +1623,7 @@ function useBridgeHandler({
|
|
|
1628
1623
|
const $onMessage = (0, import_react23.useCallback)(
|
|
1629
1624
|
async (e) => {
|
|
1630
1625
|
onMessage?.(e);
|
|
1631
|
-
const data =
|
|
1626
|
+
const data = parseNativeEventData(e.nativeEvent.data);
|
|
1632
1627
|
if (typeof data !== "object" || data === null || typeof data.functionName !== "string" || typeof data.eventId !== "string" || typeof data.type !== "string" || !["addEventListener", "removeEventListener", "method"].includes(data.type)) {
|
|
1633
1628
|
return;
|
|
1634
1629
|
}
|
|
@@ -1674,6 +1669,14 @@ function useBridgeHandler({
|
|
|
1674
1669
|
onMessage: $onMessage
|
|
1675
1670
|
};
|
|
1676
1671
|
}
|
|
1672
|
+
function parseNativeEventData(data) {
|
|
1673
|
+
try {
|
|
1674
|
+
return JSON.parse(data);
|
|
1675
|
+
} catch (error) {
|
|
1676
|
+
console.error(error);
|
|
1677
|
+
return null;
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1677
1680
|
|
|
1678
1681
|
// src/core/hooks/useWebBackHandler.tsx
|
|
1679
1682
|
var import_react_native27 = require("@granite-js/react-native");
|
|
@@ -2134,19 +2137,11 @@ function WebView({ type, local, onMessage, ...props }) {
|
|
|
2134
2137
|
const bottom = (0, import_private9.useSafeAreaBottom)();
|
|
2135
2138
|
const global2 = getAppsInTossGlobals();
|
|
2136
2139
|
const navigationBarContext = useNavigationBarContext();
|
|
2137
|
-
const disableTextSelectionCSS = `
|
|
2138
|
-
(function() {
|
|
2139
|
-
const style = document.createElement('style');
|
|
2140
|
-
style.textContent = '*:not(input):not(textarea) { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; -webkit-touch-callout: none; }';
|
|
2141
|
-
document.head.appendChild(style);
|
|
2142
|
-
})();
|
|
2143
|
-
`;
|
|
2144
2140
|
const [allowsBackForwardNavigationGestures, setAllowsBackForwardNavigationGestures] = (0, import_react28.useState)(
|
|
2145
2141
|
props.allowsBackForwardNavigationGestures
|
|
2146
2142
|
);
|
|
2147
2143
|
const handler = useBridgeHandler({
|
|
2148
2144
|
onMessage,
|
|
2149
|
-
injectedJavaScript: [disableTextSelectionCSS].join("\n"),
|
|
2150
2145
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2151
2146
|
eventListenerMap: {
|
|
2152
2147
|
...appsInTossEventBridges,
|
|
@@ -2250,6 +2245,7 @@ function WebView({ type, local, onMessage, ...props }) {
|
|
|
2250
2245
|
import_react_native33.BackHandler.addEventListener("hardwareBackPress", callback);
|
|
2251
2246
|
return () => import_react_native33.BackHandler.removeEventListener("hardwareBackPress", callback);
|
|
2252
2247
|
}, [webBackHandler]);
|
|
2248
|
+
const globalScripts = useGlobalScripts();
|
|
2253
2249
|
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
2254
2250
|
BaseWebView,
|
|
2255
2251
|
{
|
|
@@ -2277,13 +2273,78 @@ function WebView({ type, local, onMessage, ...props }) {
|
|
|
2277
2273
|
webviewDebuggingEnabled: webViewDebuggingEnabled,
|
|
2278
2274
|
thirdPartyCookiesEnabled: true,
|
|
2279
2275
|
onMessage: handler.onMessage,
|
|
2280
|
-
injectedJavaScript:
|
|
2281
|
-
injectedJavaScriptBeforeContentLoaded: handler.injectedJavaScript,
|
|
2276
|
+
injectedJavaScript: globalScripts.afterLoad,
|
|
2277
|
+
injectedJavaScriptBeforeContentLoaded: mergeScripts(handler.injectedJavaScript, globalScripts.beforeLoad),
|
|
2282
2278
|
decelerationRate: import_react_native33.Platform.OS === "ios" ? 1 : void 0,
|
|
2283
2279
|
allowsBackForwardNavigationGestures
|
|
2284
2280
|
}
|
|
2285
2281
|
);
|
|
2286
2282
|
}
|
|
2283
|
+
function useGlobalScripts() {
|
|
2284
|
+
const global2 = getAppsInTossGlobals();
|
|
2285
|
+
const disableTextSelectionCSS = `
|
|
2286
|
+
const style = document.createElement('style');
|
|
2287
|
+
style.textContent = '*:not(input):not(textarea) { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; -webkit-touch-callout: none; }';
|
|
2288
|
+
document.head.appendChild(style);
|
|
2289
|
+
`;
|
|
2290
|
+
const applyGameResourcesCache = `
|
|
2291
|
+
(function () {
|
|
2292
|
+
if (typeof caches === 'undefined') {
|
|
2293
|
+
return;
|
|
2294
|
+
}
|
|
2295
|
+
const cacheKeyPrefix = '@apps-in-toss/caches/';
|
|
2296
|
+
const cacheKey = \`\${cacheKeyPrefix}${global2.deploymentId}\`;
|
|
2297
|
+
window.addEventListener('load', async () => {
|
|
2298
|
+
const keys = await caches.keys();
|
|
2299
|
+
for (const key of keys) {
|
|
2300
|
+
if (key.startsWith(cacheKeyPrefix) && key !== cacheKey) {
|
|
2301
|
+
await caches.delete(key);
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
});
|
|
2305
|
+
window.fetch = new Proxy(window.fetch, {
|
|
2306
|
+
async apply(originalFetch, thisArg, args) {
|
|
2307
|
+
const request = new Request(args[0], args[1]);
|
|
2308
|
+
if (!/\\.(data|wasm|framework\\.js)(?:\\.gz|\\.br|\\.unityweb)?$/.test(request.url)) {
|
|
2309
|
+
return await originalFetch.call(thisArg, request);
|
|
2310
|
+
}
|
|
2311
|
+
const cache = await caches.open(cacheKey);
|
|
2312
|
+
const cached = await cache.match(request);
|
|
2313
|
+
if (cached) {
|
|
2314
|
+
const eTag = cached.headers.get('ETag');
|
|
2315
|
+
const lastModified = cached.headers.get('Last-Modified');
|
|
2316
|
+
if (eTag) {
|
|
2317
|
+
request.headers.set('If-None-Match', eTag);
|
|
2318
|
+
}
|
|
2319
|
+
if (lastModified) {
|
|
2320
|
+
request.headers.set('If-Modified-Since', lastModified);
|
|
2321
|
+
}
|
|
2322
|
+
const revalidated = await originalFetch.call(thisArg, request);
|
|
2323
|
+
if (revalidated.status === 304) {
|
|
2324
|
+
return cached;
|
|
2325
|
+
}
|
|
2326
|
+
cache.put(request, revalidated.clone());
|
|
2327
|
+
return revalidated;
|
|
2328
|
+
}
|
|
2329
|
+
const response = await originalFetch.call(thisArg, request);
|
|
2330
|
+
cache.put(request, response.clone());
|
|
2331
|
+
return response;
|
|
2332
|
+
},
|
|
2333
|
+
});
|
|
2334
|
+
})();
|
|
2335
|
+
`;
|
|
2336
|
+
return {
|
|
2337
|
+
beforeLoad: mergeScripts(
|
|
2338
|
+
global2.webViewType === "game" && applyGameResourcesCache
|
|
2339
|
+
),
|
|
2340
|
+
afterLoad: mergeScripts(
|
|
2341
|
+
disableTextSelectionCSS
|
|
2342
|
+
)
|
|
2343
|
+
};
|
|
2344
|
+
}
|
|
2345
|
+
function mergeScripts(...scripts) {
|
|
2346
|
+
return scripts.filter((script) => typeof script === "string").join("\n");
|
|
2347
|
+
}
|
|
2287
2348
|
|
|
2288
2349
|
// src/index.ts
|
|
2289
2350
|
__reExport(src_exports, require("@apps-in-toss/analytics"), module.exports);
|
package/dist/index.js
CHANGED
|
@@ -1579,25 +1579,20 @@ function useBridgeHandler({
|
|
|
1579
1579
|
onMessage,
|
|
1580
1580
|
constantHandlerMap,
|
|
1581
1581
|
asyncHandlerMap,
|
|
1582
|
-
eventListenerMap
|
|
1583
|
-
injectedJavaScript: originalInjectedJavaScript
|
|
1582
|
+
eventListenerMap
|
|
1584
1583
|
}) {
|
|
1585
1584
|
const ref = useRef4(null);
|
|
1586
1585
|
const injectedJavaScript = useMemo3(
|
|
1587
|
-
() =>
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
originalInjectedJavaScript,
|
|
1598
|
-
"true"
|
|
1599
|
-
].join("\n"),
|
|
1600
|
-
[constantHandlerMap, originalInjectedJavaScript]
|
|
1586
|
+
() => `window.__CONSTANT_HANDLER_MAP = ${JSON.stringify(
|
|
1587
|
+
Object.entries(constantHandlerMap).reduce(
|
|
1588
|
+
(acc, [key, value]) => {
|
|
1589
|
+
acc[key] = typeof value === "function" ? value() : value;
|
|
1590
|
+
return acc;
|
|
1591
|
+
},
|
|
1592
|
+
{}
|
|
1593
|
+
)
|
|
1594
|
+
)};`,
|
|
1595
|
+
[constantHandlerMap]
|
|
1601
1596
|
);
|
|
1602
1597
|
const createHandleOnEvent = (functionName, eventId) => (response) => {
|
|
1603
1598
|
ref.current?.injectJavaScript(`
|
|
@@ -1613,7 +1608,7 @@ function useBridgeHandler({
|
|
|
1613
1608
|
const $onMessage = useCallback10(
|
|
1614
1609
|
async (e) => {
|
|
1615
1610
|
onMessage?.(e);
|
|
1616
|
-
const data =
|
|
1611
|
+
const data = parseNativeEventData(e.nativeEvent.data);
|
|
1617
1612
|
if (typeof data !== "object" || data === null || typeof data.functionName !== "string" || typeof data.eventId !== "string" || typeof data.type !== "string" || !["addEventListener", "removeEventListener", "method"].includes(data.type)) {
|
|
1618
1613
|
return;
|
|
1619
1614
|
}
|
|
@@ -1659,6 +1654,14 @@ function useBridgeHandler({
|
|
|
1659
1654
|
onMessage: $onMessage
|
|
1660
1655
|
};
|
|
1661
1656
|
}
|
|
1657
|
+
function parseNativeEventData(data) {
|
|
1658
|
+
try {
|
|
1659
|
+
return JSON.parse(data);
|
|
1660
|
+
} catch (error) {
|
|
1661
|
+
console.error(error);
|
|
1662
|
+
return null;
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1662
1665
|
|
|
1663
1666
|
// src/core/hooks/useWebBackHandler.tsx
|
|
1664
1667
|
import { closeView as closeView6, useBackEventState } from "@granite-js/react-native";
|
|
@@ -2119,19 +2122,11 @@ function WebView({ type, local, onMessage, ...props }) {
|
|
|
2119
2122
|
const bottom = useSafeAreaBottom();
|
|
2120
2123
|
const global2 = getAppsInTossGlobals();
|
|
2121
2124
|
const navigationBarContext = useNavigationBarContext();
|
|
2122
|
-
const disableTextSelectionCSS = `
|
|
2123
|
-
(function() {
|
|
2124
|
-
const style = document.createElement('style');
|
|
2125
|
-
style.textContent = '*:not(input):not(textarea) { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; -webkit-touch-callout: none; }';
|
|
2126
|
-
document.head.appendChild(style);
|
|
2127
|
-
})();
|
|
2128
|
-
`;
|
|
2129
2125
|
const [allowsBackForwardNavigationGestures, setAllowsBackForwardNavigationGestures] = useState8(
|
|
2130
2126
|
props.allowsBackForwardNavigationGestures
|
|
2131
2127
|
);
|
|
2132
2128
|
const handler = useBridgeHandler({
|
|
2133
2129
|
onMessage,
|
|
2134
|
-
injectedJavaScript: [disableTextSelectionCSS].join("\n"),
|
|
2135
2130
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2136
2131
|
eventListenerMap: {
|
|
2137
2132
|
...appsInTossEventBridges,
|
|
@@ -2235,6 +2230,7 @@ function WebView({ type, local, onMessage, ...props }) {
|
|
|
2235
2230
|
BackHandler2.addEventListener("hardwareBackPress", callback);
|
|
2236
2231
|
return () => BackHandler2.removeEventListener("hardwareBackPress", callback);
|
|
2237
2232
|
}, [webBackHandler]);
|
|
2233
|
+
const globalScripts = useGlobalScripts();
|
|
2238
2234
|
return /* @__PURE__ */ jsx16(
|
|
2239
2235
|
BaseWebView,
|
|
2240
2236
|
{
|
|
@@ -2262,13 +2258,78 @@ function WebView({ type, local, onMessage, ...props }) {
|
|
|
2262
2258
|
webviewDebuggingEnabled: webViewDebuggingEnabled,
|
|
2263
2259
|
thirdPartyCookiesEnabled: true,
|
|
2264
2260
|
onMessage: handler.onMessage,
|
|
2265
|
-
injectedJavaScript:
|
|
2266
|
-
injectedJavaScriptBeforeContentLoaded: handler.injectedJavaScript,
|
|
2261
|
+
injectedJavaScript: globalScripts.afterLoad,
|
|
2262
|
+
injectedJavaScriptBeforeContentLoaded: mergeScripts(handler.injectedJavaScript, globalScripts.beforeLoad),
|
|
2267
2263
|
decelerationRate: Platform6.OS === "ios" ? 1 : void 0,
|
|
2268
2264
|
allowsBackForwardNavigationGestures
|
|
2269
2265
|
}
|
|
2270
2266
|
);
|
|
2271
2267
|
}
|
|
2268
|
+
function useGlobalScripts() {
|
|
2269
|
+
const global2 = getAppsInTossGlobals();
|
|
2270
|
+
const disableTextSelectionCSS = `
|
|
2271
|
+
const style = document.createElement('style');
|
|
2272
|
+
style.textContent = '*:not(input):not(textarea) { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; -webkit-touch-callout: none; }';
|
|
2273
|
+
document.head.appendChild(style);
|
|
2274
|
+
`;
|
|
2275
|
+
const applyGameResourcesCache = `
|
|
2276
|
+
(function () {
|
|
2277
|
+
if (typeof caches === 'undefined') {
|
|
2278
|
+
return;
|
|
2279
|
+
}
|
|
2280
|
+
const cacheKeyPrefix = '@apps-in-toss/caches/';
|
|
2281
|
+
const cacheKey = \`\${cacheKeyPrefix}${global2.deploymentId}\`;
|
|
2282
|
+
window.addEventListener('load', async () => {
|
|
2283
|
+
const keys = await caches.keys();
|
|
2284
|
+
for (const key of keys) {
|
|
2285
|
+
if (key.startsWith(cacheKeyPrefix) && key !== cacheKey) {
|
|
2286
|
+
await caches.delete(key);
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
});
|
|
2290
|
+
window.fetch = new Proxy(window.fetch, {
|
|
2291
|
+
async apply(originalFetch, thisArg, args) {
|
|
2292
|
+
const request = new Request(args[0], args[1]);
|
|
2293
|
+
if (!/\\.(data|wasm|framework\\.js)(?:\\.gz|\\.br|\\.unityweb)?$/.test(request.url)) {
|
|
2294
|
+
return await originalFetch.call(thisArg, request);
|
|
2295
|
+
}
|
|
2296
|
+
const cache = await caches.open(cacheKey);
|
|
2297
|
+
const cached = await cache.match(request);
|
|
2298
|
+
if (cached) {
|
|
2299
|
+
const eTag = cached.headers.get('ETag');
|
|
2300
|
+
const lastModified = cached.headers.get('Last-Modified');
|
|
2301
|
+
if (eTag) {
|
|
2302
|
+
request.headers.set('If-None-Match', eTag);
|
|
2303
|
+
}
|
|
2304
|
+
if (lastModified) {
|
|
2305
|
+
request.headers.set('If-Modified-Since', lastModified);
|
|
2306
|
+
}
|
|
2307
|
+
const revalidated = await originalFetch.call(thisArg, request);
|
|
2308
|
+
if (revalidated.status === 304) {
|
|
2309
|
+
return cached;
|
|
2310
|
+
}
|
|
2311
|
+
cache.put(request, revalidated.clone());
|
|
2312
|
+
return revalidated;
|
|
2313
|
+
}
|
|
2314
|
+
const response = await originalFetch.call(thisArg, request);
|
|
2315
|
+
cache.put(request, response.clone());
|
|
2316
|
+
return response;
|
|
2317
|
+
},
|
|
2318
|
+
});
|
|
2319
|
+
})();
|
|
2320
|
+
`;
|
|
2321
|
+
return {
|
|
2322
|
+
beforeLoad: mergeScripts(
|
|
2323
|
+
global2.webViewType === "game" && applyGameResourcesCache
|
|
2324
|
+
),
|
|
2325
|
+
afterLoad: mergeScripts(
|
|
2326
|
+
disableTextSelectionCSS
|
|
2327
|
+
)
|
|
2328
|
+
};
|
|
2329
|
+
}
|
|
2330
|
+
function mergeScripts(...scripts) {
|
|
2331
|
+
return scripts.filter((script) => typeof script === "string").join("\n");
|
|
2332
|
+
}
|
|
2272
2333
|
|
|
2273
2334
|
// src/index.ts
|
|
2274
2335
|
export * from "@apps-in-toss/analytics";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apps-in-toss/framework",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.6",
|
|
5
5
|
"description": "The framework for Apps In Toss",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"prepack": "yarn build",
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
"ait": "./bin/ait.js"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@apps-in-toss/analytics": "1.4.
|
|
60
|
-
"@apps-in-toss/cli": "1.4.
|
|
61
|
-
"@apps-in-toss/native-modules": "1.4.
|
|
62
|
-
"@apps-in-toss/plugins": "1.4.
|
|
63
|
-
"@apps-in-toss/types": "1.4.
|
|
59
|
+
"@apps-in-toss/analytics": "1.4.6",
|
|
60
|
+
"@apps-in-toss/cli": "1.4.6",
|
|
61
|
+
"@apps-in-toss/native-modules": "1.4.6",
|
|
62
|
+
"@apps-in-toss/plugins": "1.4.6",
|
|
63
|
+
"@apps-in-toss/types": "1.4.6",
|
|
64
64
|
"es-hangul": "^2.3.2"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"publishConfig": {
|
|
97
97
|
"access": "public"
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "8ed7aaf219f9afa8146361cc4508d0c425f3b3d6"
|
|
100
100
|
}
|