@akanjs/next 0.0.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/README.md +11 -0
- package/index.d.ts +1 -0
- package/index.js +21 -0
- package/package.json +57 -0
- package/src/bootCsr.d.ts +1 -0
- package/src/capacitor.base.config.d.ts +2 -0
- package/src/capacitor.base.config.js +72 -0
- package/src/createNextMiddleware.d.ts +2 -0
- package/src/createNextMiddleware.js +82 -0
- package/src/createRobotPage.d.ts +2 -0
- package/src/createRobotPage.js +38 -0
- package/src/createSitemapPage.d.ts +2 -0
- package/src/createSitemapPage.js +30 -0
- package/src/index.d.ts +20 -0
- package/src/index.js +82 -0
- package/src/lazy.d.ts +5 -0
- package/src/lazy.js +39 -0
- package/src/makePageProto.d.ts +30 -0
- package/src/types.d.ts +7 -0
- package/src/types.js +15 -0
- package/src/useCamera.d.ts +7 -0
- package/src/useCodepush.d.ts +17 -0
- package/src/useContact.d.ts +6 -0
- package/src/useCsrValues.d.ts +30 -0
- package/src/useCsrValues.js +615 -0
- package/src/useDebounce.d.ts +1 -0
- package/src/useDebounce.js +41 -0
- package/src/useFetch.d.ts +6 -0
- package/src/useFetch.js +46 -0
- package/src/useGeoLocation.d.ts +7 -0
- package/src/useHistory.d.ts +20 -0
- package/src/useHistory.js +69 -0
- package/src/useInterval.d.ts +1 -0
- package/src/useInterval.js +44 -0
- package/src/useLocation.d.ts +8 -0
- package/src/useLocation.js +82 -0
- package/src/usePurchase.d.ts +19 -0
- package/src/usePushNoti.d.ts +6 -0
- package/src/useThrottle.d.ts +1 -0
- package/src/useThrottle.js +43 -0
package/src/useFetch.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useFetch_exports = {};
|
|
20
|
+
__export(useFetch_exports, {
|
|
21
|
+
useFetch: () => useFetch
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useFetch_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
const useFetch = (fnOrPromise, { onError } = {}) => {
|
|
26
|
+
const [fetchState, setFetchState] = (0, import_react.useState)(
|
|
27
|
+
fnOrPromise instanceof Promise ? { fulfilled: false, value: null } : { fulfilled: true, value: fnOrPromise }
|
|
28
|
+
);
|
|
29
|
+
(0, import_react.useEffect)(() => {
|
|
30
|
+
void (async () => {
|
|
31
|
+
try {
|
|
32
|
+
const ret = fnOrPromise instanceof Promise ? await fnOrPromise : fnOrPromise;
|
|
33
|
+
setFetchState({ fulfilled: true, value: ret });
|
|
34
|
+
} catch (err) {
|
|
35
|
+
const content = `Error: ${typeof err === "string" ? err : err.message}`;
|
|
36
|
+
onError?.(content);
|
|
37
|
+
throw new Error(content);
|
|
38
|
+
}
|
|
39
|
+
})();
|
|
40
|
+
}, []);
|
|
41
|
+
return fetchState;
|
|
42
|
+
};
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
useFetch
|
|
46
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const useGeoLocation: () => {
|
|
2
|
+
checkPermission: () => Promise<{
|
|
3
|
+
geolocation: import("@capacitor/core").PermissionState;
|
|
4
|
+
coarseLocation: import("@capacitor/core").PermissionState;
|
|
5
|
+
}>;
|
|
6
|
+
getPosition: () => Promise<import("@capacitor/geolocation").Position | undefined>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { History, Location } from "@akanjs/client";
|
|
2
|
+
interface setForwardOptions {
|
|
3
|
+
type: "push" | "replace" | "popForward";
|
|
4
|
+
location: Location;
|
|
5
|
+
scrollTop?: number;
|
|
6
|
+
}
|
|
7
|
+
interface setBackOptions {
|
|
8
|
+
type: "back" | "popBack";
|
|
9
|
+
location: Location;
|
|
10
|
+
scrollTop?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const useHistory: (locations?: Location[]) => {
|
|
13
|
+
history: import("react").MutableRefObject<History>;
|
|
14
|
+
setHistoryForward: ({ type, location, scrollTop }: setForwardOptions) => void;
|
|
15
|
+
setHistoryBack: ({ location, scrollTop }: setBackOptions) => void;
|
|
16
|
+
getCurrentLocation: () => Location;
|
|
17
|
+
getPrevLocation: () => Location | null;
|
|
18
|
+
getScrollTop: (pathname?: string) => number;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useHistory_exports = {};
|
|
20
|
+
__export(useHistory_exports, {
|
|
21
|
+
useHistory: () => useHistory
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useHistory_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
const useHistory = (locations = []) => {
|
|
26
|
+
const history = (0, import_react.useRef)({
|
|
27
|
+
type: "initial",
|
|
28
|
+
locations,
|
|
29
|
+
scrollMap: /* @__PURE__ */ new Map([[window.location.pathname, 0]]),
|
|
30
|
+
idxMap: /* @__PURE__ */ new Map([[window.location.pathname, 0]]),
|
|
31
|
+
cachedLocationMap: /* @__PURE__ */ new Map(),
|
|
32
|
+
idx: 0
|
|
33
|
+
});
|
|
34
|
+
const setHistoryForward = (0, import_react.useCallback)(({ type, location, scrollTop = 0 }) => {
|
|
35
|
+
history.current.type = "forward";
|
|
36
|
+
history.current.scrollMap.set(location.pathname, scrollTop);
|
|
37
|
+
history.current.idxMap.set(location.pathname, history.current.idx);
|
|
38
|
+
if (type === "push")
|
|
39
|
+
history.current.locations = [...history.current.locations.slice(0, history.current.idx + 1), location];
|
|
40
|
+
else if (type === "replace")
|
|
41
|
+
history.current.locations = [...history.current.locations.slice(0, history.current.idx), location];
|
|
42
|
+
if (location.pathRoute.pageState.cache)
|
|
43
|
+
history.current.cachedLocationMap.set(location.pathRoute.path, location);
|
|
44
|
+
if (type === "push" || type === "popForward")
|
|
45
|
+
history.current.idx++;
|
|
46
|
+
}, []);
|
|
47
|
+
const setHistoryBack = (0, import_react.useCallback)(({ location, scrollTop = 0 }) => {
|
|
48
|
+
history.current.type = "back";
|
|
49
|
+
history.current.scrollMap.set(location.pathname, scrollTop);
|
|
50
|
+
history.current.idxMap.set(location.pathname, history.current.idx);
|
|
51
|
+
if (location.pathRoute.pageState.cache)
|
|
52
|
+
history.current.cachedLocationMap.set(location.pathRoute.path, location);
|
|
53
|
+
history.current.idx--;
|
|
54
|
+
}, []);
|
|
55
|
+
const getCurrentLocation = (0, import_react.useCallback)(() => {
|
|
56
|
+
return history.current.locations[history.current.idx];
|
|
57
|
+
}, []);
|
|
58
|
+
const getPrevLocation = (0, import_react.useCallback)(() => {
|
|
59
|
+
return history.current.locations.at(history.current.idx - 1) ?? null;
|
|
60
|
+
}, []);
|
|
61
|
+
const getScrollTop = (0, import_react.useCallback)((pathname = history.current.locations[history.current.idx]?.pathname ?? "/") => {
|
|
62
|
+
return history.current.scrollMap.get(pathname) ?? 0;
|
|
63
|
+
}, []);
|
|
64
|
+
return { history, setHistoryForward, setHistoryBack, getCurrentLocation, getPrevLocation, getScrollTop };
|
|
65
|
+
};
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
useHistory
|
|
69
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useInterval: (callback: (() => void) | (() => Promise<void>), delay: number) => import("react").MutableRefObject<(() => void) | (() => Promise<void>) | null>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useInterval_exports = {};
|
|
20
|
+
__export(useInterval_exports, {
|
|
21
|
+
useInterval: () => useInterval
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useInterval_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
const useInterval = (callback, delay) => {
|
|
26
|
+
const savedCallback = (0, import_react.useRef)(null);
|
|
27
|
+
(0, import_react.useEffect)(() => {
|
|
28
|
+
savedCallback.current = callback;
|
|
29
|
+
}, [callback]);
|
|
30
|
+
(0, import_react.useEffect)(() => {
|
|
31
|
+
const tick = () => {
|
|
32
|
+
void savedCallback.current?.();
|
|
33
|
+
};
|
|
34
|
+
const id = setInterval(tick, delay);
|
|
35
|
+
return () => {
|
|
36
|
+
clearInterval(id);
|
|
37
|
+
};
|
|
38
|
+
}, [delay]);
|
|
39
|
+
return savedCallback;
|
|
40
|
+
};
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
useInterval
|
|
44
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Location, type RouteGuide } from "@akanjs/client";
|
|
2
|
+
interface UseLocationOptions {
|
|
3
|
+
rootRouteGuide: RouteGuide;
|
|
4
|
+
}
|
|
5
|
+
export declare const useLocation: ({ rootRouteGuide }: UseLocationOptions) => {
|
|
6
|
+
getLocation: (href: string) => Location;
|
|
7
|
+
};
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useLocation_exports = {};
|
|
20
|
+
__export(useLocation_exports, {
|
|
21
|
+
useLocation: () => useLocation
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useLocation_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
const useLocation = ({ rootRouteGuide }) => {
|
|
26
|
+
const getLocation = (0, import_react.useCallback)((href) => {
|
|
27
|
+
const getPathSegments = (pathname2) => {
|
|
28
|
+
return [
|
|
29
|
+
...pathname2.split("/").filter((pathSegment) => !!pathSegment).map((pathSegment) => `/${pathSegment}`)
|
|
30
|
+
];
|
|
31
|
+
};
|
|
32
|
+
const getPathRoute = (pathname2) => {
|
|
33
|
+
const pathSegments = getPathSegments(pathname2);
|
|
34
|
+
const getTargetRouteGuide = (pathSegments2, routeGuide) => {
|
|
35
|
+
const pathSegment = pathSegments2.shift();
|
|
36
|
+
if (!pathSegment)
|
|
37
|
+
return routeGuide;
|
|
38
|
+
const childrenSegments = Object.keys(routeGuide.children);
|
|
39
|
+
const matchingPathSegment = childrenSegments.find((segment) => segment === pathSegment);
|
|
40
|
+
const paramSegment = childrenSegments.find((segment) => segment.startsWith("/:"));
|
|
41
|
+
const childRouteGuide = matchingPathSegment ? routeGuide.children[pathSegment] : paramSegment ? routeGuide.children[paramSegment] : null;
|
|
42
|
+
if (!childRouteGuide)
|
|
43
|
+
throw new Error("404");
|
|
44
|
+
return getTargetRouteGuide(pathSegments2, childRouteGuide);
|
|
45
|
+
};
|
|
46
|
+
const targetRouteGuide = getTargetRouteGuide(pathSegments, rootRouteGuide);
|
|
47
|
+
const pathRoute2 = targetRouteGuide.pathRoute;
|
|
48
|
+
if (!pathRoute2) {
|
|
49
|
+
window.location.assign("/404");
|
|
50
|
+
throw new Error("404");
|
|
51
|
+
}
|
|
52
|
+
return pathRoute2;
|
|
53
|
+
};
|
|
54
|
+
const getParams = (pathname2, pathRoute2) => {
|
|
55
|
+
const pathSegments = getPathSegments(pathname2);
|
|
56
|
+
return pathRoute2.pathSegments.reduce((params2, pathSegment, idx) => {
|
|
57
|
+
if (pathSegment.startsWith("/:"))
|
|
58
|
+
params2[pathSegment.slice(2)] = pathSegments[idx - 1].slice(1);
|
|
59
|
+
return params2;
|
|
60
|
+
}, {});
|
|
61
|
+
};
|
|
62
|
+
const getSearchParams = (search2) => {
|
|
63
|
+
return [...new URLSearchParams(search2).entries()].reduce(
|
|
64
|
+
(params2, [key, value]) => {
|
|
65
|
+
params2[key] = params2[key] ? [...Array.isArray(params2[key]) ? params2[key] : [params2[key]], value] : value;
|
|
66
|
+
return params2;
|
|
67
|
+
},
|
|
68
|
+
{}
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
const [pathname, search] = href.split("?");
|
|
72
|
+
const pathRoute = getPathRoute(pathname);
|
|
73
|
+
const params = getParams(pathname, pathRoute);
|
|
74
|
+
const searchParams = getSearchParams(search);
|
|
75
|
+
return { pathname, search, params, searchParams, pathRoute };
|
|
76
|
+
}, []);
|
|
77
|
+
return { getLocation };
|
|
78
|
+
};
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
useLocation
|
|
82
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "cordova-plugin-purchase/www/store";
|
|
2
|
+
export type PlatformType = "android" | "ios" | "all";
|
|
3
|
+
export interface ProductType {
|
|
4
|
+
id: string;
|
|
5
|
+
type: keyof typeof CdvPurchase.ProductType;
|
|
6
|
+
}
|
|
7
|
+
export type CdvProductType = CdvPurchase.ProductType;
|
|
8
|
+
export declare const usePurchase: ({ platform, productInfo, url, onPay, onSubscribe, }: {
|
|
9
|
+
platform: PlatformType;
|
|
10
|
+
productInfo: ProductType[];
|
|
11
|
+
url: string;
|
|
12
|
+
onPay?: (transaction: CdvPurchase.Transaction) => void | Promise<void>;
|
|
13
|
+
onSubscribe?: (transaction: CdvPurchase.Transaction) => void | Promise<void>;
|
|
14
|
+
}) => {
|
|
15
|
+
isLoading: boolean;
|
|
16
|
+
products: CdvPurchase.Product[];
|
|
17
|
+
purchaseProduct: (product: CdvPurchase.Product) => Promise<void>;
|
|
18
|
+
restorePurchases: () => Promise<void>;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useThrottle: (func: (...args: any) => any, delay?: number, deps?: any[]) => (...args: any[]) => void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useThrottle_exports = {};
|
|
20
|
+
__export(useThrottle_exports, {
|
|
21
|
+
useThrottle: () => useThrottle
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useThrottle_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
const useThrottle = (func, delay = 200, deps = []) => {
|
|
26
|
+
const throttleSeed = (0, import_react.useRef)(null);
|
|
27
|
+
const throttleFunction = (0, import_react.useCallback)(
|
|
28
|
+
(...args) => {
|
|
29
|
+
if (throttleSeed.current)
|
|
30
|
+
return;
|
|
31
|
+
func(...args);
|
|
32
|
+
throttleSeed.current = setTimeout(() => {
|
|
33
|
+
throttleSeed.current = null;
|
|
34
|
+
}, delay);
|
|
35
|
+
},
|
|
36
|
+
[func, delay, ...deps]
|
|
37
|
+
);
|
|
38
|
+
return throttleFunction;
|
|
39
|
+
};
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
useThrottle
|
|
43
|
+
});
|