@akanjs/next 0.0.149 → 0.0.151

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.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const bootCsr: (context: Record<string, () => Promise<unknown>>, rootPath: string, entryPath?: string) => Promise<void>;
1
+ export declare const bootCsr: (context: Record<string, () => Promise<unknown>>) => Promise<void>;
package/cjs/bootCsr.js CHANGED
@@ -38,15 +38,33 @@ var import_react = __toESM(require("react"));
38
38
  var ReactDOM = __toESM(require("react-dom/client"));
39
39
  var import_useCsrValues = require("./useCsrValues");
40
40
  const supportLanguages = ["en", "ko"];
41
- const bootCsr = async (context, rootPath, entryPath = "/route") => {
41
+ const bootCsr = async (context) => {
42
+ window.document.body.style.overflow = "hidden";
43
+ const pathname = window.location.pathname;
44
+ if (pathname === "/404")
45
+ return;
42
46
  const [, jwt] = await Promise.all([import_client.device.init({ supportLanguages }), import_client.storage.getItem("jwt")]);
47
+ if (!pathname.startsWith(`/${import_client.device.lang}`))
48
+ window.location.replace(`/${import_client.device.lang}${pathname}`);
43
49
  if (jwt)
44
50
  (0, import_client.initAuth)({ jwt });
45
51
  import_common.Logger.verbose(`Set default language: ${import_client.device.lang}`);
52
+ const basePaths = process.env.basePaths?.split(",");
53
+ const currentBasePath = basePaths ? pathname.split("/")[2] : void 0;
54
+ if (currentBasePath && basePaths && !basePaths.includes(currentBasePath))
55
+ throw new Error(`Invalid path: ${pathname}`);
56
+ const baseLayoutPaths = ["/", "/:lang", ...currentBasePath ? [`/:lang/${currentBasePath}`] : []];
57
+ const otherBasePaths = basePaths?.filter((path) => path !== currentBasePath) ?? [];
46
58
  const pages = {};
47
59
  await Promise.all(
48
60
  Object.entries(context).map(async ([key, value]) => {
49
- pages[key] = await value();
61
+ if (basePaths) {
62
+ const pageBasePath = key.split("/")[2];
63
+ if (pageBasePath && otherBasePaths.includes(pageBasePath))
64
+ return;
65
+ }
66
+ const getPageContent = value;
67
+ pages[key] = await getPageContent();
50
68
  })
51
69
  );
52
70
  const getPageState = (csrConfig) => {
@@ -96,13 +114,10 @@ const bootCsr = async (context, rootPath, entryPath = "/route") => {
96
114
  }
97
115
  });
98
116
  }
99
- const pathname = window.location.pathname;
100
- const initialPath = import_client.device.lang + entryPath;
101
- window.document.body.style.overflow = "hidden";
102
117
  const getPathRoutes = (route, parentRootLayouts = [], parentLayouts = [], parentPaths = []) => {
103
118
  const parentPath = parentPaths.filter((path2) => path2 !== "/").join("");
104
119
  const currentPathSegment = /^\/\(.*\)$/.test(route.path) ? "" : route.path;
105
- const isRoot = ["/", "/:lang"].includes(parentPath + currentPathSegment) && parentRootLayouts.length < 2;
120
+ const isRoot = baseLayoutPaths.includes(parentPath + currentPathSegment) && parentRootLayouts.length < 2;
106
121
  const path = parentPath + currentPathSegment;
107
122
  const pathSegments = [...parentPaths, ...currentPathSegment ? [currentPathSegment] : []];
108
123
  const RootLayouts = [...parentRootLayouts, ...isRoot && route.Layout ? [route.Layout] : []];
@@ -149,14 +164,9 @@ const bootCsr = async (context, rootPath, entryPath = "/route") => {
149
164
  /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null)
150
165
  ));
151
166
  };
152
- if (pathname !== `/${initialPath}`) {
153
- window.location.replace(initialPath);
154
- return;
155
- } else {
156
- const el = document.getElementById("root");
157
- if (!el)
158
- throw new Error("No root element");
159
- const root = ReactDOM.createRoot(el);
160
- root.render(/* @__PURE__ */ import_react.default.createElement(RouterProvider, null));
161
- }
167
+ const el = document.getElementById("root");
168
+ if (!el)
169
+ throw new Error("No root element");
170
+ const root = ReactDOM.createRoot(el);
171
+ root.render(/* @__PURE__ */ import_react.default.createElement(RouterProvider, null));
162
172
  };
package/cjs/index.js CHANGED
@@ -33,6 +33,7 @@ __export(next_exports, {
33
33
  useHistory: () => import_useHistory.useHistory,
34
34
  useInterval: () => import_useInterval.useInterval,
35
35
  useLocation: () => import_useLocation.useLocation,
36
+ usePage: () => import_usePage.usePage,
36
37
  usePurchase: () => import_usePurchase.usePurchase,
37
38
  usePushNoti: () => import_usePushNoti.usePushNoti,
38
39
  useThrottle: () => import_useThrottle.useThrottle
@@ -57,4 +58,5 @@ var import_createNextMiddleware = require("./createNextMiddleware");
57
58
  var import_useThrottle = require("./useThrottle");
58
59
  var import_useHistory = require("./useHistory");
59
60
  var import_useLocation = require("./useLocation");
61
+ var import_usePage = require("./usePage");
60
62
  //! PageAgent csr에서 말썽 일으킨다
package/cjs/usePage.js ADDED
@@ -0,0 +1,24 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var usePage_exports = {};
19
+ __export(usePage_exports, {
20
+ usePage: () => usePage
21
+ });
22
+ module.exports = __toCommonJS(usePage_exports);
23
+ var import_makePageProto = require("./makePageProto");
24
+ const usePage = (0, import_makePageProto.makePageProto)([]);
package/esm/bootCsr.js CHANGED
@@ -11,15 +11,33 @@ import React from "react";
11
11
  import * as ReactDOM from "react-dom/client";
12
12
  import { useCsrValues } from "./useCsrValues";
13
13
  const supportLanguages = ["en", "ko"];
14
- const bootCsr = async (context, rootPath, entryPath = "/route") => {
14
+ const bootCsr = async (context) => {
15
+ window.document.body.style.overflow = "hidden";
16
+ const pathname = window.location.pathname;
17
+ if (pathname === "/404")
18
+ return;
15
19
  const [, jwt] = await Promise.all([device.init({ supportLanguages }), storage.getItem("jwt")]);
20
+ if (!pathname.startsWith(`/${device.lang}`))
21
+ window.location.replace(`/${device.lang}${pathname}`);
16
22
  if (jwt)
17
23
  initAuth({ jwt });
18
24
  Logger.verbose(`Set default language: ${device.lang}`);
25
+ const basePaths = process.env.basePaths?.split(",");
26
+ const currentBasePath = basePaths ? pathname.split("/")[2] : void 0;
27
+ if (currentBasePath && basePaths && !basePaths.includes(currentBasePath))
28
+ throw new Error(`Invalid path: ${pathname}`);
29
+ const baseLayoutPaths = ["/", "/:lang", ...currentBasePath ? [`/:lang/${currentBasePath}`] : []];
30
+ const otherBasePaths = basePaths?.filter((path) => path !== currentBasePath) ?? [];
19
31
  const pages = {};
20
32
  await Promise.all(
21
33
  Object.entries(context).map(async ([key, value]) => {
22
- pages[key] = await value();
34
+ if (basePaths) {
35
+ const pageBasePath = key.split("/")[2];
36
+ if (pageBasePath && otherBasePaths.includes(pageBasePath))
37
+ return;
38
+ }
39
+ const getPageContent = value;
40
+ pages[key] = await getPageContent();
23
41
  })
24
42
  );
25
43
  const getPageState = (csrConfig) => {
@@ -69,13 +87,10 @@ const bootCsr = async (context, rootPath, entryPath = "/route") => {
69
87
  }
70
88
  });
71
89
  }
72
- const pathname = window.location.pathname;
73
- const initialPath = device.lang + entryPath;
74
- window.document.body.style.overflow = "hidden";
75
90
  const getPathRoutes = (route, parentRootLayouts = [], parentLayouts = [], parentPaths = []) => {
76
91
  const parentPath = parentPaths.filter((path2) => path2 !== "/").join("");
77
92
  const currentPathSegment = /^\/\(.*\)$/.test(route.path) ? "" : route.path;
78
- const isRoot = ["/", "/:lang"].includes(parentPath + currentPathSegment) && parentRootLayouts.length < 2;
93
+ const isRoot = baseLayoutPaths.includes(parentPath + currentPathSegment) && parentRootLayouts.length < 2;
79
94
  const path = parentPath + currentPathSegment;
80
95
  const pathSegments = [...parentPaths, ...currentPathSegment ? [currentPathSegment] : []];
81
96
  const RootLayouts = [...parentRootLayouts, ...isRoot && route.Layout ? [route.Layout] : []];
@@ -122,16 +137,11 @@ const bootCsr = async (context, rootPath, entryPath = "/route") => {
122
137
  /* @__PURE__ */ React.createElement(React.Fragment, null)
123
138
  ));
124
139
  };
125
- if (pathname !== `/${initialPath}`) {
126
- window.location.replace(initialPath);
127
- return;
128
- } else {
129
- const el = document.getElementById("root");
130
- if (!el)
131
- throw new Error("No root element");
132
- const root = ReactDOM.createRoot(el);
133
- root.render(/* @__PURE__ */ React.createElement(RouterProvider, null));
134
- }
140
+ const el = document.getElementById("root");
141
+ if (!el)
142
+ throw new Error("No root element");
143
+ const root = ReactDOM.createRoot(el);
144
+ root.render(/* @__PURE__ */ React.createElement(RouterProvider, null));
135
145
  };
136
146
  export {
137
147
  bootCsr
package/esm/index.js CHANGED
@@ -18,6 +18,7 @@ import { createNextMiddleware } from "./createNextMiddleware";
18
18
  import { useThrottle } from "./useThrottle";
19
19
  import { useHistory } from "./useHistory";
20
20
  import { useLocation } from "./useLocation";
21
+ import { usePage } from "./usePage";
21
22
  export {
22
23
  bootCsr,
23
24
  createNextMiddleware,
@@ -35,6 +36,7 @@ export {
35
36
  useHistory,
36
37
  useInterval,
37
38
  useLocation,
39
+ usePage,
38
40
  usePurchase,
39
41
  usePushNoti,
40
42
  useThrottle
package/esm/usePage.js ADDED
@@ -0,0 +1,5 @@
1
+ import { makePageProto } from "./makePageProto";
2
+ const usePage = makePageProto([]);
3
+ export {
4
+ usePage
5
+ };
package/index.d.ts CHANGED
@@ -18,3 +18,4 @@ export { createNextMiddleware } from "./createNextMiddleware";
18
18
  export { useThrottle } from "./useThrottle";
19
19
  export { useHistory } from "./useHistory";
20
20
  export { useLocation } from "./useLocation";
21
+ export { usePage } from "./usePage";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/next",
3
- "version": "0.0.149",
3
+ "version": "0.0.151",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/usePage.d.ts ADDED
@@ -0,0 +1,74 @@
1
+ import { Translation } from "@akanjs/dictionary";
2
+ export declare const usePage: () => {
3
+ path: string;
4
+ l: {
5
+ (key: `${string}.${string}` | `${string}.${number}`, param?: {
6
+ [key: string]: string | number;
7
+ } | undefined): string;
8
+ rich(key: `${string}.${string}` | `${string}.${number}`, param?: {
9
+ [key: string]: string | number;
10
+ } | undefined): import("react").ReactNode;
11
+ field<ModelKey extends string | number>(model: ModelKey, field: keyof {
12
+ [key: string]: {
13
+ [key: string]: Translation;
14
+ };
15
+ }[ModelKey]): string;
16
+ desc<ModelKey extends string | number>(model: ModelKey, field: keyof {
17
+ [key: string]: {
18
+ [key: string]: Translation;
19
+ };
20
+ }[ModelKey]): string;
21
+ enum<ModelKey extends string | number>(model: ModelKey, field: keyof {
22
+ [key: string]: {
23
+ [key: string]: Translation;
24
+ };
25
+ }[ModelKey], value: string): string;
26
+ enumdesc<ModelKey extends string | number>(model: ModelKey, field: keyof {
27
+ [key: string]: {
28
+ [key: string]: Translation;
29
+ };
30
+ }[ModelKey], value: string): string;
31
+ api<ModelKey extends string | number>(model: ModelKey, endpoint: keyof {
32
+ [key: string]: {
33
+ [key: string]: Translation;
34
+ };
35
+ }[ModelKey]): string;
36
+ apidesc<ModelKey extends string | number>(model: ModelKey, endpoint: keyof {
37
+ [key: string]: {
38
+ [key: string]: Translation;
39
+ };
40
+ }[ModelKey]): string;
41
+ arg<ModelKey extends string | number>(model: ModelKey, endpoint: keyof {
42
+ [key: string]: {
43
+ [key: string]: Translation;
44
+ };
45
+ }[ModelKey], arg: string): string;
46
+ argdesc<ModelKey extends string | number>(model: ModelKey, endpoint: keyof {
47
+ [key: string]: {
48
+ [key: string]: Translation;
49
+ };
50
+ }[ModelKey], arg: string): string;
51
+ qry<ModelKey extends string | number>(model: ModelKey, queryKey: keyof {
52
+ [key: string]: {
53
+ [key: string]: Translation;
54
+ };
55
+ }[ModelKey]): string;
56
+ qrydesc<ModelKey extends string | number>(model: ModelKey, queryKey: keyof {
57
+ [key: string]: {
58
+ [key: string]: Translation;
59
+ };
60
+ }[ModelKey]): string;
61
+ qarg<ModelKey extends string | number>(model: ModelKey, queryKey: keyof {
62
+ [key: string]: {
63
+ [key: string]: Translation;
64
+ };
65
+ }[ModelKey], arg: string): string;
66
+ qargdesc<ModelKey extends string | number>(model: ModelKey, queryKey: keyof {
67
+ [key: string]: {
68
+ [key: string]: Translation;
69
+ };
70
+ }[ModelKey], arg: string): string;
71
+ trans(translation: Record<"en" | "ko" | (string & {}), import("react").ReactNode>): import("react").ReactNode;
72
+ };
73
+ lang: string;
74
+ };