@akanjs/next 0.0.52 → 0.0.53
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/bootCsr.js +162 -0
- package/createNextMiddleware.js +78 -0
- package/createRobotPage.js +34 -0
- package/createSitemapPage.js +26 -0
- package/index.js +41 -0
- package/lazy.js +35 -0
- package/makePageProto.js +133 -0
- package/package.json +1 -1
- package/types.js +15 -0
- package/useCamera.js +96 -0
- package/useCodepush.js +103 -0
- package/useContact.js +55 -0
- package/{useCsrValues.ts → useCsrValues.js} +229 -231
- package/useDebounce.js +37 -0
- package/useFetch.js +42 -0
- package/useGeoLocation.js +40 -0
- package/useHistory.js +65 -0
- package/useInterval.js +40 -0
- package/useLocation.js +78 -0
- package/{usePurchase.tsx → usePurchase.js} +63 -79
- package/usePushNoti.js +61 -0
- package/useThrottle.js +39 -0
- package/bootCsr.tsx +0 -180
- package/createNextMiddleware.ts +0 -45
- package/createRobotPage.ts +0 -14
- package/createSitemapPage.ts +0 -6
- package/index.ts +0 -23
- package/lazy.ts +0 -9
- package/makePageProto.tsx +0 -117
- package/types.ts +0 -7
- package/useCamera.tsx +0 -94
- package/useCodepush.tsx +0 -98
- package/useContact.tsx +0 -45
- package/useDebounce.ts +0 -23
- package/useFetch.ts +0 -24
- package/useGeoLocation.tsx +0 -21
- package/useHistory.ts +0 -55
- package/useInterval.ts +0 -20
- package/useLocation.ts +0 -65
- package/usePushNoti.tsx +0 -39
- package/useThrottle.ts +0 -17
package/useFetch.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
|
|
4
|
-
export const useFetch = <Return>(
|
|
5
|
-
fnOrPromise: Promise<Return> | Return,
|
|
6
|
-
{ onError }: { onError?: (err: string) => void } = {}
|
|
7
|
-
): { fulfilled: boolean; value: Return | null } => {
|
|
8
|
-
const [fetchState, setFetchState] = useState<{ fulfilled: boolean; value: any }>(
|
|
9
|
-
fnOrPromise instanceof Promise ? { fulfilled: false, value: null } : { fulfilled: true, value: fnOrPromise }
|
|
10
|
-
);
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
void (async () => {
|
|
13
|
-
try {
|
|
14
|
-
const ret = fnOrPromise instanceof Promise ? await fnOrPromise : fnOrPromise;
|
|
15
|
-
setFetchState({ fulfilled: true, value: ret });
|
|
16
|
-
} catch (err) {
|
|
17
|
-
const content = `Error: ${typeof err === "string" ? err : (err as Error).message}`;
|
|
18
|
-
onError?.(content);
|
|
19
|
-
throw new Error(content);
|
|
20
|
-
}
|
|
21
|
-
})();
|
|
22
|
-
}, []);
|
|
23
|
-
return fetchState;
|
|
24
|
-
};
|
package/useGeoLocation.tsx
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { Geolocation } from "@capacitor/geolocation";
|
|
3
|
-
|
|
4
|
-
export const useGeoLocation = () => {
|
|
5
|
-
const checkPermission = async () => {
|
|
6
|
-
const { location: geolocation, coarseLocation } = await Geolocation.requestPermissions();
|
|
7
|
-
return { geolocation, coarseLocation };
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const getPosition = async () => {
|
|
11
|
-
const { geolocation, coarseLocation } = await checkPermission();
|
|
12
|
-
if (geolocation === "denied" || coarseLocation === "denied") {
|
|
13
|
-
location.assign("app-settings:");
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const coordinates = await Geolocation.getCurrentPosition();
|
|
17
|
-
return coordinates;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
return { checkPermission, getPosition };
|
|
21
|
-
};
|
package/useHistory.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import type { History, Location } from "@akanjs/client";
|
|
3
|
-
import { useCallback, useRef } from "react";
|
|
4
|
-
|
|
5
|
-
interface setForwardOptions {
|
|
6
|
-
type: "push" | "replace" | "popForward";
|
|
7
|
-
location: Location;
|
|
8
|
-
scrollTop?: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface setBackOptions {
|
|
12
|
-
type: "back" | "popBack";
|
|
13
|
-
location: Location;
|
|
14
|
-
scrollTop?: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const useHistory = (locations: Location[] = []) => {
|
|
18
|
-
const history = useRef<History>({
|
|
19
|
-
type: "initial",
|
|
20
|
-
locations,
|
|
21
|
-
scrollMap: new Map([[window.location.pathname, 0]]),
|
|
22
|
-
idxMap: new Map([[window.location.pathname, 0]]),
|
|
23
|
-
cachedLocationMap: new Map(),
|
|
24
|
-
idx: 0,
|
|
25
|
-
});
|
|
26
|
-
const setHistoryForward = useCallback(({ type, location, scrollTop = 0 }: setForwardOptions) => {
|
|
27
|
-
history.current.type = "forward";
|
|
28
|
-
history.current.scrollMap.set(location.pathname, scrollTop);
|
|
29
|
-
history.current.idxMap.set(location.pathname, history.current.idx);
|
|
30
|
-
if (type === "push")
|
|
31
|
-
history.current.locations = [...history.current.locations.slice(0, history.current.idx + 1), location];
|
|
32
|
-
else if (type === "replace")
|
|
33
|
-
history.current.locations = [...history.current.locations.slice(0, history.current.idx), location];
|
|
34
|
-
if (location.pathRoute.pageState.cache) history.current.cachedLocationMap.set(location.pathRoute.path, location);
|
|
35
|
-
if (type === "push" || type === "popForward") history.current.idx++;
|
|
36
|
-
}, []);
|
|
37
|
-
const setHistoryBack = useCallback(({ location, scrollTop = 0 }: setBackOptions) => {
|
|
38
|
-
history.current.type = "back";
|
|
39
|
-
history.current.scrollMap.set(location.pathname, scrollTop);
|
|
40
|
-
history.current.idxMap.set(location.pathname, history.current.idx);
|
|
41
|
-
if (location.pathRoute.pageState.cache) history.current.cachedLocationMap.set(location.pathRoute.path, location);
|
|
42
|
-
history.current.idx--;
|
|
43
|
-
}, []);
|
|
44
|
-
const getCurrentLocation = useCallback(() => {
|
|
45
|
-
return history.current.locations[history.current.idx];
|
|
46
|
-
}, []);
|
|
47
|
-
const getPrevLocation = useCallback(() => {
|
|
48
|
-
return (history.current.locations[history.current.idx - 1] ?? null) as Location | null;
|
|
49
|
-
}, []);
|
|
50
|
-
const getScrollTop = useCallback((pathname = history.current.locations[history.current.idx]?.pathname ?? "/") => {
|
|
51
|
-
return history.current.scrollMap.get(pathname) ?? 0;
|
|
52
|
-
}, []);
|
|
53
|
-
|
|
54
|
-
return { history, setHistoryForward, setHistoryBack, getCurrentLocation, getPrevLocation, getScrollTop };
|
|
55
|
-
};
|
package/useInterval.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useEffect, useRef } from "react";
|
|
3
|
-
|
|
4
|
-
export const useInterval = (callback: (() => void) | (() => Promise<void>), delay: number) => {
|
|
5
|
-
const savedCallback = useRef<(() => void) | (() => Promise<void>) | null>(null);
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
savedCallback.current = callback;
|
|
8
|
-
}, [callback]);
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
const tick = () => {
|
|
11
|
-
void savedCallback.current?.();
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const id = setInterval(tick, delay);
|
|
15
|
-
return () => {
|
|
16
|
-
clearInterval(id);
|
|
17
|
-
};
|
|
18
|
-
}, [delay]);
|
|
19
|
-
return savedCallback;
|
|
20
|
-
};
|
package/useLocation.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { type Location, type PathRoute, type RouteGuide } from "@akanjs/client";
|
|
3
|
-
import { useCallback } from "react";
|
|
4
|
-
|
|
5
|
-
interface UseLocationOptions {
|
|
6
|
-
rootRouteGuide: RouteGuide;
|
|
7
|
-
}
|
|
8
|
-
export const useLocation = ({ rootRouteGuide }: UseLocationOptions) => {
|
|
9
|
-
const getLocation = useCallback((href: string): Location => {
|
|
10
|
-
const getPathSegments = (pathname: string) => {
|
|
11
|
-
return [
|
|
12
|
-
...pathname
|
|
13
|
-
.split("/")
|
|
14
|
-
.filter((pathSegment) => !!pathSegment)
|
|
15
|
-
.map((pathSegment) => `/${pathSegment}`),
|
|
16
|
-
];
|
|
17
|
-
};
|
|
18
|
-
const getPathRoute = (pathname: string): PathRoute => {
|
|
19
|
-
const pathSegments = getPathSegments(pathname);
|
|
20
|
-
const getTargetRouteGuide = (pathSegments: string[], routeGuide: RouteGuide): RouteGuide => {
|
|
21
|
-
const pathSegment = pathSegments.shift();
|
|
22
|
-
if (!pathSegment) return routeGuide;
|
|
23
|
-
const childrenSegments = Object.keys(routeGuide.children);
|
|
24
|
-
const matchingPathSegment = childrenSegments.find((segment) => segment === pathSegment);
|
|
25
|
-
const paramSegment = childrenSegments.find((segment) => segment.startsWith("/:"));
|
|
26
|
-
const childRouteGuide = matchingPathSegment
|
|
27
|
-
? routeGuide.children[pathSegment]
|
|
28
|
-
: paramSegment
|
|
29
|
-
? routeGuide.children[paramSegment]
|
|
30
|
-
: null;
|
|
31
|
-
if (!childRouteGuide) throw new Error("404");
|
|
32
|
-
return getTargetRouteGuide(pathSegments, childRouteGuide);
|
|
33
|
-
};
|
|
34
|
-
const targetRouteGuide = getTargetRouteGuide(pathSegments, rootRouteGuide);
|
|
35
|
-
const pathRoute = targetRouteGuide.pathRoute;
|
|
36
|
-
if (!pathRoute) {
|
|
37
|
-
window.location.assign("/404");
|
|
38
|
-
throw new Error("404");
|
|
39
|
-
}
|
|
40
|
-
return pathRoute;
|
|
41
|
-
};
|
|
42
|
-
const getParams = (pathname: string, pathRoute: PathRoute) => {
|
|
43
|
-
const pathSegments = getPathSegments(pathname);
|
|
44
|
-
return pathRoute.pathSegments.reduce<{ [key: string]: string }>((params, pathSegment, idx) => {
|
|
45
|
-
if (pathSegment.startsWith("/:")) params[pathSegment.slice(2)] = pathSegments[idx - 1].slice(1);
|
|
46
|
-
return params;
|
|
47
|
-
}, {});
|
|
48
|
-
};
|
|
49
|
-
const getSearchParams = (search: string) => {
|
|
50
|
-
return [...new URLSearchParams(search).entries()].reduce<{ [key: string]: string | string[] }>(
|
|
51
|
-
(params, [key, value]) => {
|
|
52
|
-
params[key] = params[key] ? [...(Array.isArray(params[key]) ? params[key] : [params[key]]), value] : value;
|
|
53
|
-
return params;
|
|
54
|
-
},
|
|
55
|
-
{}
|
|
56
|
-
);
|
|
57
|
-
};
|
|
58
|
-
const [pathname, search] = href.split("?");
|
|
59
|
-
const pathRoute = getPathRoute(pathname);
|
|
60
|
-
const params = getParams(pathname, pathRoute);
|
|
61
|
-
const searchParams = getSearchParams(search);
|
|
62
|
-
return { pathname, search, params, searchParams, pathRoute };
|
|
63
|
-
}, []);
|
|
64
|
-
return { getLocation };
|
|
65
|
-
};
|
package/usePushNoti.tsx
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { Device } from "@capacitor/device";
|
|
3
|
-
import { PushNotifications } from "@capacitor/push-notifications";
|
|
4
|
-
import { FCM } from "@capacitor-community/fcm";
|
|
5
|
-
|
|
6
|
-
export const usePushNoti = () => {
|
|
7
|
-
const init = async () => {
|
|
8
|
-
const device = await Device.getInfo();
|
|
9
|
-
if (device.platform === "web") return;
|
|
10
|
-
void FCM.setAutoInit({ enabled: true });
|
|
11
|
-
void PushNotifications.requestPermissions().then(async (result) => {
|
|
12
|
-
if (result.receive === "granted") {
|
|
13
|
-
await PushNotifications.register();
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const checkPermission = async () => {
|
|
19
|
-
const { receive } = await PushNotifications.checkPermissions();
|
|
20
|
-
return receive === "granted";
|
|
21
|
-
};
|
|
22
|
-
const register = async () => {
|
|
23
|
-
const device = await Device.getInfo();
|
|
24
|
-
if (device.platform === "web") return;
|
|
25
|
-
const { receive } = await PushNotifications.checkPermissions();
|
|
26
|
-
//푸시알림이 거절됐으면 앱 세팅으로 넘어감
|
|
27
|
-
|
|
28
|
-
if (receive === "denied") location.assign("app-settings:");
|
|
29
|
-
else await PushNotifications.register();
|
|
30
|
-
};
|
|
31
|
-
const getToken = async () => {
|
|
32
|
-
const device = await Device.getInfo();
|
|
33
|
-
if (device.platform === "web") return;
|
|
34
|
-
const { token } = await FCM.getToken();
|
|
35
|
-
return token;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
return { init, checkPermission, register, getToken };
|
|
39
|
-
};
|
package/useThrottle.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useCallback, useRef } from "react";
|
|
3
|
-
|
|
4
|
-
export const useThrottle = (func: (...args: any) => any, delay = 200, deps: any[] = []) => {
|
|
5
|
-
const throttleSeed = useRef<NodeJS.Timeout | null>(null);
|
|
6
|
-
const throttleFunction = useCallback(
|
|
7
|
-
(...args) => {
|
|
8
|
-
if (throttleSeed.current) return;
|
|
9
|
-
func(...(args as object[]));
|
|
10
|
-
throttleSeed.current = setTimeout(() => {
|
|
11
|
-
throttleSeed.current = null;
|
|
12
|
-
}, delay);
|
|
13
|
-
},
|
|
14
|
-
[func, delay, ...(deps as object[])]
|
|
15
|
-
);
|
|
16
|
-
return throttleFunction;
|
|
17
|
-
};
|