@akanjs/ui 0.9.41 → 0.9.43

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.
@@ -21,7 +21,7 @@ interface CardListProps<T extends string, Input, Full extends {
21
21
  init?: FetchInitForm<Input, Full, Filter>;
22
22
  sliceName: string;
23
23
  columns: DataColumn<any>[];
24
- actions?: DataAction<Light>[] | ((item: Light, idx: number) => DataAction<Light>[]);
24
+ actions?: DataAction[] | ((item: Light, idx: number) => DataAction[]);
25
25
  renderItem: (args: DataItemProps<T, Full, Light>) => ReactNode;
26
26
  renderLoading?: () => ReactNode;
27
27
  renderTemplate?: (props: any) => ReactNode | null;
@@ -1,5 +1,4 @@
1
- import { StoreOf } from "@akanjs/store";
2
- export interface DashboardProps<T extends string, State, SL extends StoreOf<T, State>> {
1
+ export interface DashboardProps<T extends string, State> {
3
2
  className?: string;
4
3
  summary: {
5
4
  [key: string]: any;
@@ -12,4 +11,4 @@ export interface DashboardProps<T extends string, State, SL extends StoreOf<T, S
12
11
  presents?: string[];
13
12
  hidePresents?: boolean;
14
13
  }
15
- export default function Dashboard<T extends string, State, SL extends StoreOf<T, State>>({ className, summary, sliceName, queryMap, columns, presents, hidePresents, }: DashboardProps<T, State, SL>): import("react/jsx-runtime").JSX.Element;
14
+ export default function Dashboard<T extends string, State>({ className, summary, sliceName, queryMap, columns, presents, hidePresents, }: DashboardProps<T, State>): import("react/jsx-runtime").JSX.Element;
package/Data/Item.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Dayjs } from "@akanjs/base";
2
2
  import { DataAction, DataColumn } from "@akanjs/client";
3
- import React, { ReactNode } from "react";
3
+ import { ReactNode } from "react";
4
4
  export declare const convToAntdColumn: (column: DataColumn<any>) => {
5
5
  key: string;
6
6
  dataIndex: string;
@@ -37,7 +37,7 @@ interface ItemProps<T extends string, Full extends {
37
37
  onClick?: () => void;
38
38
  cover?: ReactNode;
39
39
  title?: ReactNode;
40
- actions?: DataAction<Light>[];
40
+ actions?: DataAction[];
41
41
  columns?: DataColumn<any>[];
42
42
  children?: ReactNode;
43
43
  }
@@ -61,7 +61,7 @@ interface ActionProps<T extends string, M extends {
61
61
  }, L extends {
62
62
  id: string;
63
63
  }> {
64
- action: DataAction<L>;
64
+ action: DataAction;
65
65
  model: L;
66
66
  sliceName: string;
67
67
  }
@@ -71,4 +71,4 @@ export declare const Action: <T extends string, M extends {
71
71
  id: string;
72
72
  }>({ action, model, sliceName, outline, }: ActionProps<T, M, L> & {
73
73
  outline?: boolean;
74
- }) => string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
74
+ }) => import("react/jsx-runtime").JSX.Element | null | undefined;
@@ -2,7 +2,7 @@ import { DataAction, DataColumn, DataTool, ModelInsightProps, ModelProps } from
2
2
  import { SortType } from "@akanjs/constant";
3
3
  import { type FetchInitForm } from "@akanjs/signal";
4
4
  import { ReactNode } from "react";
5
- interface ListContainerProps<T extends string, State, Input, Full extends {
5
+ export interface ListContainerProps<T extends string, State, Input, Full extends {
6
6
  id: string;
7
7
  }, Light extends {
8
8
  id: string;
@@ -14,20 +14,25 @@ interface ListContainerProps<T extends string, State, Input, Full extends {
14
14
  [key: string]: any;
15
15
  };
16
16
  init?: FetchInitForm<Input, Full, Sort>;
17
- sliceName: string;
17
+ sliceName: T;
18
18
  create?: boolean;
19
19
  title?: string;
20
20
  sort?: SortType;
21
21
  columns?: DataColumn<any>[];
22
22
  tools?: DataTool[] | ((modelList: Light[]) => DataTool[]);
23
- actions?: DataAction<Light>[] | ((item: Light, idx: number) => DataAction<Light>[]);
24
- renderDashboard?: ({ summary, hidePresents }: any) => ReactNode;
23
+ actions?: DataAction[] | ((item: Light, idx: number) => DataAction[]);
24
+ renderDashboard?: ({ summary, hidePresents, }: {
25
+ summary: {
26
+ [key: string]: any;
27
+ };
28
+ hidePresents?: boolean;
29
+ }) => ReactNode;
25
30
  renderItem?: (props: ModelProps<any, any>) => ReactNode;
26
31
  renderTemplate?: (props: any) => ReactNode | null;
27
32
  renderTitle?: (model: Full) => string | ReactNode;
28
33
  renderView?: (model: Full) => ReactNode | null;
29
34
  renderQueryMaker?: () => ReactNode;
30
- renderInsight?: (props: ModelInsightProps<any>) => ReactNode;
35
+ renderInsight?: (props: ModelInsightProps) => ReactNode;
31
36
  renderLoading?: () => ReactNode;
32
37
  }
33
38
  export default function ListContainer<T extends string, State, Input, Full extends {
@@ -35,4 +40,3 @@ export default function ListContainer<T extends string, State, Input, Full exten
35
40
  }, Light extends {
36
41
  id: string;
37
42
  }, Sort extends SortType>({ className, cardListClassName, type, query, init, create, sliceName, title, sort, columns, actions, tools, renderDashboard, renderItem, renderTemplate, renderTitle, renderView, renderQueryMaker, renderInsight, renderLoading, }: ListContainerProps<T, State, Input, Full, Light, Sort>): import("react/jsx-runtime").JSX.Element;
38
- export {};
@@ -15,7 +15,7 @@ interface TableListProps<T extends string, Input, Full extends {
15
15
  renderTemplate?: (props: any) => ReactNode | null;
16
16
  renderTitle?: (model: Full) => string | ReactNode;
17
17
  renderView?: (model: Full) => ReactNode | null;
18
- actions?: DataAction<Light>[] | ((item: Light, idx: number) => DataAction<Light>[]);
18
+ actions?: DataAction[] | ((item: Light, idx: number) => DataAction[]);
19
19
  onItemClick?: (item: Light, idx: number) => void;
20
20
  }
21
21
  export default function TableList<T extends string, Input, Full extends {
@@ -0,0 +1,31 @@
1
+ import { type SortType } from "@akanjs/constant";
2
+ import type { ListContainerProps } from "../Data/ListContainer";
3
+ interface AdminPanelProps<T extends string, State, Input, Full extends {
4
+ id: string;
5
+ }, Light extends {
6
+ id: string;
7
+ }, Sort extends SortType> extends ListContainerProps<T, State, Input, Full, Light, Sort> {
8
+ sliceName: T;
9
+ components: {
10
+ Template: {
11
+ [key: string]: any;
12
+ };
13
+ Unit: {
14
+ [key: string]: any;
15
+ };
16
+ View: {
17
+ [key: string]: any;
18
+ };
19
+ };
20
+ queryMap?: {
21
+ [key: string]: any;
22
+ };
23
+ summaryColumns?: string[];
24
+ insightColumns?: string[];
25
+ }
26
+ export default function AdminPanel<T extends string, State, Input, Full extends {
27
+ id: string;
28
+ }, Light extends {
29
+ id: string;
30
+ }, Sort extends SortType>({ sliceName, components, queryMap, summaryColumns, insightColumns, renderInsight, renderDashboard, ...props }: AdminPanelProps<T, State, Input, Full, Light, Sort>): import("react/jsx-runtime").JSX.Element;
31
+ export {};
package/Model/index.d.ts CHANGED
@@ -12,4 +12,5 @@ export declare const Model: {
12
12
  ViewEditModal: typeof import("./ViewEditModal").default;
13
13
  Edit: typeof import("./Edit").default;
14
14
  New: typeof import("./New").default;
15
+ AdminPanel: typeof import("./AdminPanel").default;
15
16
  };
package/Model/index_.d.ts CHANGED
@@ -11,3 +11,4 @@ export declare const ViewWrapper: typeof import("./ViewWrapper").default;
11
11
  export declare const ViewEditModal: typeof import("./ViewEditModal").default;
12
12
  export declare const Edit: typeof import("./Edit").default;
13
13
  export declare const New: typeof import("./New").default;
14
+ export declare const AdminPanel: typeof import("./AdminPanel").default;
@@ -1,6 +1 @@
1
- export interface ReconnectProps {
2
- path: string;
3
- dev?: boolean;
4
- fetchPing?: () => Promise<any>;
5
- }
6
- export declare const Reconnect: ({ path, dev, fetchPing }: ReconnectProps) => import("react/jsx-runtime").JSX.Element;
1
+ export declare const Reconnect: () => import("react/jsx-runtime").JSX.Element | null;
package/System/index.d.ts CHANGED
@@ -6,6 +6,6 @@ export declare const System: {
6
6
  ThemeToggle: () => import("react/jsx-runtime").JSX.Element | null;
7
7
  Root: ({ children, st }: import("./Root").RootProps) => import("react/jsx-runtime").JSX.Element;
8
8
  SelectLanguage: ({ className, languages }: import("./SelectLanguage").SelectLanguageProps) => import("react/jsx-runtime").JSX.Element;
9
- Reconnect: ({ path, dev, fetchPing }: import("./Reconnect").ReconnectProps) => import("react/jsx-runtime").JSX.Element;
9
+ Reconnect: () => import("react/jsx-runtime").JSX.Element | null;
10
10
  DevModeToggle: () => import("react/jsx-runtime").JSX.Element;
11
11
  };
package/cjs/Data/Item.js CHANGED
@@ -89,10 +89,7 @@ function Item({
89
89
  }) {
90
90
  const { l } = (0, import_next.usePage)();
91
91
  const strActions = actions.filter((action) => typeof action === "string").map((action, idx) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Action, { action, outline: false, model, sliceName }, idx));
92
- const customActions = actions.filter((action) => typeof action !== "string").map((action, idx) => ({
93
- key: idx,
94
- label: typeof action !== "string" ? action.render() : null
95
- }));
92
+ const customActions = actions.filter((action) => typeof action !== "string").map((action, idx) => ({ key: idx, label: action }));
96
93
  const extraCols = columns.filter((column) => {
97
94
  const key = typeof column === "string" ? column : column.key;
98
95
  return !["id", "status", "createdAt"].includes(key);
@@ -184,7 +181,7 @@ const Action = ({
184
181
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: `btn btn-square btn-ghost btn-sm m-1 text-center ${outline && "btn-outline border-dashed"}`, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ai.AiOutlineDelete, {}) })
185
182
  },
186
183
  action
187
- ) : action.render();
184
+ ) : action;
188
185
  };
189
186
  const statusColors = {
190
187
  active: "badge-info badge-outline",
@@ -57,19 +57,12 @@ function ListContainer({
57
57
  title,
58
58
  sort,
59
59
  columns = ["id", "createdAt", "updatedAt"],
60
- actions,
60
+ actions = ["remove", "edit", "view"],
61
61
  tools = [],
62
62
  renderDashboard,
63
63
  renderItem,
64
64
  renderTemplate,
65
- renderTitle = (model) => model.id ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h2", { className: "flex items-center justify-center py-3 text-lg sm:justify-start md:text-2xl", children: [
66
- sliceName,
67
- " - ",
68
- model.id
69
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h2", { className: "flex items-center justify-center py-3 text-lg sm:justify-start md:text-2xl", children: [
70
- "New ",
71
- sliceName
72
- ] }),
65
+ renderTitle,
73
66
  renderView,
74
67
  renderQueryMaker = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {}),
75
68
  renderInsight,
@@ -78,7 +71,6 @@ function ListContainer({
78
71
  const { l } = (0, import_next.usePage)();
79
72
  const storeUse = import_store.st.use;
80
73
  const storeDo = import_store.st.do;
81
- const storeGet = import_store.st.get;
82
74
  const refName = import_store.st.slice[sliceName].refName;
83
75
  const [modelName, modelClassName] = [refName, (0, import_common.capitalize)(refName)];
84
76
  if (refName !== sliceName)
@@ -111,6 +103,7 @@ function ListContainer({
111
103
  const cnst = (0, import_constant.getCnstMeta)(sliceName);
112
104
  const limitOfModel = storeUse[namesOfSlice.limitOfModel]();
113
105
  const sortOfModel = storeUse[namesOfSlice.sortOfModel]();
106
+ const RenderTitle = renderTitle ?? ((model) => `${l(`${refName}.modelName`)} - ${model.id ? model.id : "New"}`);
114
107
  const ModelDashboard = () => {
115
108
  const summary = storeUse.summary();
116
109
  const summaryLoading = storeUse.summaryLoading();
@@ -260,11 +253,11 @@ ${body}`], { type: "text/csv;charset=utf-8" });
260
253
  import_CardList.default,
261
254
  {
262
255
  sliceName,
263
- renderItem: renderItem ?? (({ [sliceName]: model }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: model.id }, model.id)),
256
+ renderItem: renderItem ?? (({ [sliceName]: model }) => null),
264
257
  renderLoading,
265
258
  renderTemplate,
266
259
  renderView,
267
- renderTitle,
260
+ renderTitle: RenderTitle,
268
261
  columns,
269
262
  actions,
270
263
  cardListClassName
@@ -276,10 +269,10 @@ ${body}`], { type: "text/csv;charset=utf-8" });
276
269
  sliceName,
277
270
  actions,
278
271
  renderTemplate,
279
- renderTitle,
272
+ renderTitle: RenderTitle,
280
273
  renderView
281
274
  }
282
275
  ),
283
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Model.Model.EditModal, { sliceName, renderTitle, children: RenderTemplate ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RenderTemplate, {}) : null })
276
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Model.Model.EditModal, { sliceName, renderTitle: RenderTitle, children: RenderTemplate ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RenderTemplate, {}) : null })
284
277
  ] });
285
278
  }
@@ -92,7 +92,7 @@ function QueryMaker({ className, sliceName, query }) {
92
92
  {
93
93
  value: querySetting.queryKey,
94
94
  options: Object.keys(summaryQueryMap).map((queryKey) => ({
95
- label: l.qry(sliceName, queryKey),
95
+ label: l.field("summary", queryKey),
96
96
  value: queryKey
97
97
  })),
98
98
  onChange: (queryKey) => {
package/cjs/Load/Page.js CHANGED
@@ -20,6 +20,7 @@ __export(Page_exports, {
20
20
  default: () => Page_default
21
21
  });
22
22
  module.exports = __toCommonJS(Page_exports);
23
+ var import_jsx_runtime = require("react/jsx-runtime");
23
24
  var import_base = require("@akanjs/base");
24
25
  var import_PageCSR = require("./PageCSR");
25
26
  const Page = import_base.baseClientEnv.renderMode === "csr" ? import_PageCSR.PageCSR : ({ loader, render }) => {
@@ -27,7 +28,11 @@ const Page = import_base.baseClientEnv.renderMode === "csr" ? import_PageCSR.Pag
27
28
  loader().then((data) => {
28
29
  resolve(render(data));
29
30
  }).catch((error) => {
30
- reject(error);
31
+ const message = error instanceof Error ? error.message : typeof error === "string" ? error : "Unknown error";
32
+ if (message === "NEXT_REDIRECT")
33
+ reject(error);
34
+ else
35
+ resolve(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-red-500", children: message }));
31
36
  });
32
37
  });
33
38
  return promise;
@@ -0,0 +1,49 @@
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 AdminPanel_exports = {};
19
+ __export(AdminPanel_exports, {
20
+ default: () => AdminPanel
21
+ });
22
+ module.exports = __toCommonJS(AdminPanel_exports);
23
+ var import_jsx_runtime = require("react/jsx-runtime");
24
+ var import_common = require("@akanjs/common");
25
+ var import_constant = require("@akanjs/constant");
26
+ var import_Data = require("../Data");
27
+ function AdminPanel({
28
+ sliceName,
29
+ components,
30
+ queryMap = (0, import_constant.getQueryMap)((0, import_constant.getScalarModelRef)(`${(0, import_common.capitalize)(sliceName)}Summary`)),
31
+ summaryColumns = ["totalAdmin"],
32
+ insightColumns = ["count"],
33
+ renderInsight = ({ insight }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Data.Data.Insight, { insight, sliceName, columns: insightColumns }),
34
+ renderDashboard = ({ summary }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Data.Data.Dashboard, { summary, sliceName, columns: summaryColumns, queryMap }),
35
+ ...props
36
+ }) {
37
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
38
+ import_Data.Data.ListContainer,
39
+ {
40
+ sliceName,
41
+ renderItem: components.Unit.General,
42
+ renderInsight,
43
+ renderDashboard,
44
+ renderTemplate: components.Template.General,
45
+ renderView: (model) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(components.View.General, { ...{ [sliceName]: model } }),
46
+ ...props
47
+ }
48
+ );
49
+ }
@@ -34,5 +34,6 @@ const Model = {
34
34
  ViewWrapper: import_index.ViewWrapper,
35
35
  ViewEditModal: import_index.ViewEditModal,
36
36
  Edit: import_index.Edit,
37
- New: import_index.New
37
+ New: import_index.New,
38
+ AdminPanel: import_index.AdminPanel
38
39
  };
@@ -27,6 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
  var index_exports = {};
29
29
  __export(index_exports, {
30
+ AdminPanel: () => AdminPanel,
30
31
  Edit: () => Edit,
31
32
  EditModal: () => EditModal,
32
33
  EditWrapper: () => EditWrapper,
@@ -56,3 +57,4 @@ const ViewWrapper = (0, import_next.lazy)(() => import("./ViewWrapper"));
56
57
  const ViewEditModal = (0, import_next.lazy)(() => import("./ViewEditModal"));
57
58
  const Edit = (0, import_next.lazy)(() => import("./Edit"));
58
59
  const New = (0, import_next.lazy)(() => import("./New"));
60
+ const AdminPanel = (0, import_next.lazy)(() => import("./AdminPanel"));
package/cjs/System/CSR.js CHANGED
@@ -154,7 +154,7 @@ const CSRWrapper = ({
154
154
  import_ui.animated.div,
155
155
  {
156
156
  id: "topSafeArea",
157
- className: (0, import_client.clsx)("bg-base-100 fixed inset-x-0 top-0", {}),
157
+ className: (0, import_client.clsx)("bg-base-100 fixed inset-x-0 top-0 max-w-screen", {}),
158
158
  ref: topSafeAreaRef,
159
159
  style: topSafeArea?.containerStyle
160
160
  }
@@ -163,7 +163,7 @@ const CSRWrapper = ({
163
163
  import_ui.animated.div,
164
164
  {
165
165
  id: "topInsetContainer",
166
- className: (0, import_client.clsx)("bg-base-100 fixed inset-x-0 isolate", {}),
166
+ className: (0, import_client.clsx)("bg-base-100 fixed inset-x-0 isolate max-w-screen", {}),
167
167
  style: topInset?.containerStyle
168
168
  }
169
169
  ),
@@ -179,7 +179,7 @@ const CSRWrapper = ({
179
179
  import_ui.animated.div,
180
180
  {
181
181
  id: "bottomInsetContainer",
182
- className: (0, import_client.clsx)("fixed inset-x-0 isolate", {}),
182
+ className: (0, import_client.clsx)("fixed inset-x-0 isolate max-w-screen", {}),
183
183
  style: bottomInset?.containerStyle
184
184
  }
185
185
  ),
@@ -187,7 +187,7 @@ const CSRWrapper = ({
187
187
  import_ui.animated.div,
188
188
  {
189
189
  id: "bottomSafeArea",
190
- className: "bg-base-100 fixed inset-x-0",
190
+ className: "bg-base-100 fixed inset-x-0 max-w-screen",
191
191
  ref: bottomSafeAreaRef,
192
192
  style: bottomSafeArea?.containerStyle
193
193
  }
@@ -24,7 +24,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
24
24
  var import_ko = require("dayjs/locale/ko");
25
25
  var import_client = require("@akanjs/client");
26
26
  var import_Load = require("../Load");
27
- var import_HealthCheck = require("./HealthCheck");
27
+ var import_Reconnect = require("./Reconnect");
28
28
  const Common = () => {
29
29
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
30
30
  };
@@ -38,7 +38,6 @@ const CommonWrapper = ({
38
38
  }) => {
39
39
  const account = (0, import_client.getAccount)();
40
40
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
41
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_HealthCheck.HealthCheck, { fetchPing }),
42
41
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
43
42
  import_Load.Load.Page,
44
43
  {
@@ -62,7 +61,8 @@ const CommonWrapper = ({
62
61
  },
63
62
  render
64
63
  }
65
- )
64
+ ),
65
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Reconnect.Reconnect, {})
66
66
  ] });
67
67
  };
68
68
  Common.Wrapper = CommonWrapper;
@@ -32,55 +32,65 @@ __export(Reconnect_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(Reconnect_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
- var import_client = require("@akanjs/client");
36
35
  var import_next = require("@akanjs/next");
37
36
  var import_signal = require("@akanjs/signal");
38
- var import_store = require("@akanjs/store");
39
37
  var import_clsx = __toESM(require("clsx"));
40
38
  var import_react = require("react");
41
39
  var import_tb = require("react-icons/tb");
42
- var import_Image = require("../Image");
43
- const Reconnect = ({ path, dev = false, fetchPing = () => import_signal.fetch.ping() }) => {
44
- const DOTS_LENGTH = 4;
40
+ const DOTS_LENGTH = 4;
41
+ const Reconnect = () => {
42
+ const { l } = (0, import_next.usePage)();
45
43
  const [dots, setDots] = (0, import_react.useState)(0);
46
- const connectStatus = import_store.st.use.connectStatus();
44
+ const [connectStatus, setConnectStatus] = (0, import_react.useState)("initial");
45
+ const handleConnect = (0, import_react.useCallback)(() => {
46
+ setConnectStatus((prev) => prev === "normal" || prev === "initial" ? prev : "connected");
47
+ }, []);
48
+ const handleDisconnect = (0, import_react.useCallback)(() => {
49
+ setConnectStatus((prev) => prev === "normal" || prev === "initial" ? "disconnected" : prev);
50
+ setTimeout(() => {
51
+ setConnectStatus((prev) => prev === "disconnected" ? "connecting" : prev);
52
+ }, 3e3);
53
+ }, []);
54
+ (0, import_react.useEffect)(() => {
55
+ const io = import_signal.client.getIo();
56
+ io.socket.on("connect", handleConnect);
57
+ io.socket.on("disconnect", handleDisconnect);
58
+ setTimeout(() => {
59
+ if (connectStatus !== "initial")
60
+ return;
61
+ if (import_signal.client.getIo().socket.connected)
62
+ setConnectStatus("normal");
63
+ else
64
+ handleDisconnect();
65
+ }, 1e3);
66
+ return () => {
67
+ io.socket.off("connect", handleConnect);
68
+ io.socket.off("disconnect", handleDisconnect);
69
+ };
70
+ }, []);
71
+ (0, import_react.useEffect)(() => {
72
+ if (connectStatus === "connected")
73
+ window.location.reload();
74
+ }, [connectStatus]);
47
75
  (0, import_next.useInterval)(() => {
48
- setDots((prev) => (prev + 1) % DOTS_LENGTH);
76
+ if (connectStatus === "connecting")
77
+ setDots((prev) => (prev + 1) % DOTS_LENGTH);
49
78
  }, 500);
50
- const reconnect = async () => {
51
- try {
52
- import_store.st.do.setConnectStatus("connecting");
53
- await fetchPing();
54
- import_store.st.do.setConnectStatus("connected");
55
- setTimeout(() => {
56
- if (!path || path === "/")
57
- import_client.router.replace("/");
58
- else
59
- import_client.router.replace(`/${path}`);
60
- }, 500);
61
- } catch (e) {
62
- }
63
- };
64
- (0, import_next.useInterval)(async () => {
65
- if (!window.location.href.includes("/unknown"))
66
- return;
67
- if (connectStatus === "connected")
68
- return;
69
- await reconnect();
70
- }, 5e3);
71
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: dev ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex h-screen flex-col items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "bg-base-300 flex w-4/5 flex-col items-center justify-center rounded-md p-5 md:w-1/3", children: [
72
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-3xl font-bold", children: connectStatus === "disconnected" ? "Something's wrong!" : connectStatus === "connecting" ? "Connecting..." : "Connected!" }),
79
+ if (connectStatus === "initial" || connectStatus === "normal")
80
+ return null;
81
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "animate-fadeIn bg-base-100/50 fixed top-0 left-0 flex h-screen w-screen flex-col items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "bg-base-300 flex w-4/5 flex-col items-center justify-center rounded-md p-5 md:w-1/3", children: [
82
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-3xl font-bold whitespace-nowrap", children: connectStatus === "disconnected" ? l("base.somethingWrong") : connectStatus === "connecting" ? l("base.connecting") : l("base.connected") }),
73
83
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col items-center justify-center", children: [
74
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "py-5", children: connectStatus === "disconnected" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-[150px] text-gray-500", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tb.TbPlugConnectedX, {}) }) }) : connectStatus === "connecting" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "animate-pulse py-5 text-[150px] text-gray-500", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tb.TbPlugConnectedX, {}) }) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "animate-pop text-[150px] text-white", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tb.TbPlugConnected, {}) }) }) }),
84
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "py-5", children: connectStatus === "disconnected" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-[150px] text-gray-500", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tb.TbPlugConnectedX, {}) }) : connectStatus === "connecting" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "animate-pulse py-5 text-[150px] text-gray-500", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tb.TbPlugConnectedX, {}) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "animate-pop text-[150px] text-white", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tb.TbPlugConnected, {}) }) }),
75
85
  connectStatus === "connected" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
76
86
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "animate-pop" }),
77
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-lg", children: "Redirecting to the previous page in some seconds." }) })
87
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-lg", children: l("base.refreshing") }) })
78
88
  ] }) : connectStatus === "connecting" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-center", children: [
79
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-lg", children: "Try reconnecting to the server" }),
89
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-lg", children: l("base.tryReconnecting") }),
80
90
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex items-center", children: Array.from({ length: DOTS_LENGTH }).map(
81
91
  (_, index) => dots >= index ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "visible", children: "." }, index) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "invisible", children: "." }, index)
82
92
  ) })
83
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-lg", children: "Server disconnected." })
93
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-lg", children: l("base.serverDisconnected") })
84
94
  ] }),
85
95
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
86
96
  "div",
@@ -89,19 +99,11 @@ const Reconnect = ({ path, dev = false, fetchPing = () => import_signal.fetch.pi
89
99
  "mt-2 text-center text-sm leading-tight text-gray-500",
90
100
  connectStatus === "disconnected" || connectStatus === "connecting" ? "visible" : "invisible"
91
101
  ),
92
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-center gap-2", children: [
93
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "font-bold", children: "*" }),
94
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col items-center justify-center", children: [
95
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: " Maybe your server is having a problem." }),
96
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "font-bold", children: "please check your server status." })
97
- ] })
98
- ] })
102
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex items-center justify-center gap-2", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col items-center justify-center", children: [
103
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: l("base.serverHasProblem") }),
104
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "font-bold", children: l("base.checkServerStatus") })
105
+ ] }) })
99
106
  }
100
107
  )
101
- ] }) }) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex h-screen items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "bg-base-300 flex w-4/5 flex-col items-center justify-center rounded-md py-5 md:w-1/3", children: [
102
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-3xl font-bold", children: "\uBB38\uC81C\uAC00 \uBC1C\uC0DD\uD588\uC5B4\uC694!" }),
103
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Image.Image, { className: "mt-5", src: "/deadBot.svg", alt: "deadBot", color: "gray", width: 120, height: 120 }),
104
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-lg", children: "\uC11C\uBC84\uC5D0 \uBB38\uC81C\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4." }),
105
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-lg", children: "\uC11C\uBC84\uC5D0 \uC5F0\uACB0\uC744 \uC7AC\uC2DC\uB3C4\uD558\uACE0 \uC788\uC5B4\uC694..." })
106
- ] }) }) });
108
+ ] }) });
107
109
  };
package/esm/Data/Item.js CHANGED
@@ -65,10 +65,7 @@ function Item({
65
65
  }) {
66
66
  const { l } = usePage();
67
67
  const strActions = actions.filter((action) => typeof action === "string").map((action, idx) => /* @__PURE__ */ jsx(Action, { action, outline: false, model, sliceName }, idx));
68
- const customActions = actions.filter((action) => typeof action !== "string").map((action, idx) => ({
69
- key: idx,
70
- label: typeof action !== "string" ? action.render() : null
71
- }));
68
+ const customActions = actions.filter((action) => typeof action !== "string").map((action, idx) => ({ key: idx, label: action }));
72
69
  const extraCols = columns.filter((column) => {
73
70
  const key = typeof column === "string" ? column : column.key;
74
71
  return !["id", "status", "createdAt"].includes(key);
@@ -160,7 +157,7 @@ const Action = ({
160
157
  children: /* @__PURE__ */ jsx("button", { className: `btn btn-square btn-ghost btn-sm m-1 text-center ${outline && "btn-outline border-dashed"}`, children: /* @__PURE__ */ jsx(AiOutlineDelete, {}) })
161
158
  },
162
159
  action
163
- ) : action.render();
160
+ ) : action;
164
161
  };
165
162
  const statusColors = {
166
163
  active: "badge-info badge-outline",
@@ -31,19 +31,12 @@ function ListContainer({
31
31
  title,
32
32
  sort,
33
33
  columns = ["id", "createdAt", "updatedAt"],
34
- actions,
34
+ actions = ["remove", "edit", "view"],
35
35
  tools = [],
36
36
  renderDashboard,
37
37
  renderItem,
38
38
  renderTemplate,
39
- renderTitle = (model) => model.id ? /* @__PURE__ */ jsxs("h2", { className: "flex items-center justify-center py-3 text-lg sm:justify-start md:text-2xl", children: [
40
- sliceName,
41
- " - ",
42
- model.id
43
- ] }) : /* @__PURE__ */ jsxs("h2", { className: "flex items-center justify-center py-3 text-lg sm:justify-start md:text-2xl", children: [
44
- "New ",
45
- sliceName
46
- ] }),
39
+ renderTitle,
47
40
  renderView,
48
41
  renderQueryMaker = () => /* @__PURE__ */ jsx(Fragment, {}),
49
42
  renderInsight,
@@ -52,7 +45,6 @@ function ListContainer({
52
45
  const { l } = usePage();
53
46
  const storeUse = st.use;
54
47
  const storeDo = st.do;
55
- const storeGet = st.get;
56
48
  const refName = st.slice[sliceName].refName;
57
49
  const [modelName, modelClassName] = [refName, capitalize(refName)];
58
50
  if (refName !== sliceName)
@@ -85,6 +77,7 @@ function ListContainer({
85
77
  const cnst = getCnstMeta(sliceName);
86
78
  const limitOfModel = storeUse[namesOfSlice.limitOfModel]();
87
79
  const sortOfModel = storeUse[namesOfSlice.sortOfModel]();
80
+ const RenderTitle = renderTitle ?? ((model) => `${l(`${refName}.modelName`)} - ${model.id ? model.id : "New"}`);
88
81
  const ModelDashboard = () => {
89
82
  const summary = storeUse.summary();
90
83
  const summaryLoading = storeUse.summaryLoading();
@@ -234,11 +227,11 @@ ${body}`], { type: "text/csv;charset=utf-8" });
234
227
  DataCardList,
235
228
  {
236
229
  sliceName,
237
- renderItem: renderItem ?? (({ [sliceName]: model }) => /* @__PURE__ */ jsx("div", { children: model.id }, model.id)),
230
+ renderItem: renderItem ?? (({ [sliceName]: model }) => null),
238
231
  renderLoading,
239
232
  renderTemplate,
240
233
  renderView,
241
- renderTitle,
234
+ renderTitle: RenderTitle,
242
235
  columns,
243
236
  actions,
244
237
  cardListClassName
@@ -250,11 +243,11 @@ ${body}`], { type: "text/csv;charset=utf-8" });
250
243
  sliceName,
251
244
  actions,
252
245
  renderTemplate,
253
- renderTitle,
246
+ renderTitle: RenderTitle,
254
247
  renderView
255
248
  }
256
249
  ),
257
- /* @__PURE__ */ jsx(Model.EditModal, { sliceName, renderTitle, children: RenderTemplate ? /* @__PURE__ */ jsx(RenderTemplate, {}) : null })
250
+ /* @__PURE__ */ jsx(Model.EditModal, { sliceName, renderTitle: RenderTitle, children: RenderTemplate ? /* @__PURE__ */ jsx(RenderTemplate, {}) : null })
258
251
  ] });
259
252
  }
260
253
  export {
@@ -78,7 +78,7 @@ function QueryMaker({ className, sliceName, query }) {
78
78
  {
79
79
  value: querySetting.queryKey,
80
80
  options: Object.keys(summaryQueryMap).map((queryKey) => ({
81
- label: l.qry(sliceName, queryKey),
81
+ label: l.field("summary", queryKey),
82
82
  value: queryKey
83
83
  })),
84
84
  onChange: (queryKey) => {
package/esm/Load/Page.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { jsx } from "react/jsx-runtime";
1
2
  import { baseClientEnv } from "@akanjs/base";
2
3
  import { PageCSR } from "./PageCSR";
3
4
  const Page = baseClientEnv.renderMode === "csr" ? PageCSR : ({ loader, render }) => {
@@ -5,7 +6,11 @@ const Page = baseClientEnv.renderMode === "csr" ? PageCSR : ({ loader, render })
5
6
  loader().then((data) => {
6
7
  resolve(render(data));
7
8
  }).catch((error) => {
8
- reject(error);
9
+ const message = error instanceof Error ? error.message : typeof error === "string" ? error : "Unknown error";
10
+ if (message === "NEXT_REDIRECT")
11
+ reject(error);
12
+ else
13
+ resolve(/* @__PURE__ */ jsx("div", { className: "text-red-500", children: message }));
9
14
  });
10
15
  });
11
16
  return promise;
@@ -0,0 +1,30 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { capitalize } from "@akanjs/common";
3
+ import { getQueryMap, getScalarModelRef } from "@akanjs/constant";
4
+ import { Data } from "../Data";
5
+ function AdminPanel({
6
+ sliceName,
7
+ components,
8
+ queryMap = getQueryMap(getScalarModelRef(`${capitalize(sliceName)}Summary`)),
9
+ summaryColumns = ["totalAdmin"],
10
+ insightColumns = ["count"],
11
+ renderInsight = ({ insight }) => /* @__PURE__ */ jsx(Data.Insight, { insight, sliceName, columns: insightColumns }),
12
+ renderDashboard = ({ summary }) => /* @__PURE__ */ jsx(Data.Dashboard, { summary, sliceName, columns: summaryColumns, queryMap }),
13
+ ...props
14
+ }) {
15
+ return /* @__PURE__ */ jsx(
16
+ Data.ListContainer,
17
+ {
18
+ sliceName,
19
+ renderItem: components.Unit.General,
20
+ renderInsight,
21
+ renderDashboard,
22
+ renderTemplate: components.Template.General,
23
+ renderView: (model) => /* @__PURE__ */ jsx(components.View.General, { ...{ [sliceName]: model } }),
24
+ ...props
25
+ }
26
+ );
27
+ }
28
+ export {
29
+ AdminPanel as default
30
+ };
@@ -1,4 +1,5 @@
1
1
  import {
2
+ AdminPanel,
2
3
  Edit,
3
4
  EditModal,
4
5
  EditWrapper,
@@ -26,7 +27,8 @@ const Model = {
26
27
  ViewWrapper,
27
28
  ViewEditModal,
28
29
  Edit,
29
- New
30
+ New,
31
+ AdminPanel
30
32
  };
31
33
  export {
32
34
  Model
@@ -12,7 +12,9 @@ const ViewWrapper = lazy(() => import("./ViewWrapper"));
12
12
  const ViewEditModal = lazy(() => import("./ViewEditModal"));
13
13
  const Edit = lazy(() => import("./Edit"));
14
14
  const New = lazy(() => import("./New"));
15
+ const AdminPanel = lazy(() => import("./AdminPanel"));
15
16
  export {
17
+ AdminPanel,
16
18
  Edit,
17
19
  EditModal,
18
20
  EditWrapper,
package/esm/System/CSR.js CHANGED
@@ -131,7 +131,7 @@ const CSRWrapper = ({
131
131
  animated.div,
132
132
  {
133
133
  id: "topSafeArea",
134
- className: clsx("bg-base-100 fixed inset-x-0 top-0", {}),
134
+ className: clsx("bg-base-100 fixed inset-x-0 top-0 max-w-screen", {}),
135
135
  ref: topSafeAreaRef,
136
136
  style: topSafeArea?.containerStyle
137
137
  }
@@ -140,7 +140,7 @@ const CSRWrapper = ({
140
140
  animated.div,
141
141
  {
142
142
  id: "topInsetContainer",
143
- className: clsx("bg-base-100 fixed inset-x-0 isolate", {}),
143
+ className: clsx("bg-base-100 fixed inset-x-0 isolate max-w-screen", {}),
144
144
  style: topInset?.containerStyle
145
145
  }
146
146
  ),
@@ -156,7 +156,7 @@ const CSRWrapper = ({
156
156
  animated.div,
157
157
  {
158
158
  id: "bottomInsetContainer",
159
- className: clsx("fixed inset-x-0 isolate", {}),
159
+ className: clsx("fixed inset-x-0 isolate max-w-screen", {}),
160
160
  style: bottomInset?.containerStyle
161
161
  }
162
162
  ),
@@ -164,7 +164,7 @@ const CSRWrapper = ({
164
164
  animated.div,
165
165
  {
166
166
  id: "bottomSafeArea",
167
- className: "bg-base-100 fixed inset-x-0",
167
+ className: "bg-base-100 fixed inset-x-0 max-w-screen",
168
168
  ref: bottomSafeAreaRef,
169
169
  style: bottomSafeArea?.containerStyle
170
170
  }
@@ -2,7 +2,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import "dayjs/locale/ko";
3
3
  import { getAccount } from "@akanjs/client";
4
4
  import { Load } from "../Load";
5
- import { HealthCheck } from "./HealthCheck";
5
+ import { Reconnect } from "./Reconnect";
6
6
  const Common = () => {
7
7
  return /* @__PURE__ */ jsx(Fragment, {});
8
8
  };
@@ -16,7 +16,6 @@ const CommonWrapper = ({
16
16
  }) => {
17
17
  const account = getAccount();
18
18
  return /* @__PURE__ */ jsxs(Fragment, { children: [
19
- /* @__PURE__ */ jsx(HealthCheck, { fetchPing }),
20
19
  /* @__PURE__ */ jsx(
21
20
  Load.Page,
22
21
  {
@@ -40,7 +39,8 @@ const CommonWrapper = ({
40
39
  },
41
40
  render
42
41
  }
43
- )
42
+ ),
43
+ /* @__PURE__ */ jsx(Reconnect, {})
44
44
  ] });
45
45
  };
46
46
  Common.Wrapper = CommonWrapper;
@@ -1,54 +1,64 @@
1
1
  "use client";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
- import { router } from "@akanjs/client";
4
- import { useInterval } from "@akanjs/next";
5
- import { fetch } from "@akanjs/signal";
6
- import { st } from "@akanjs/store";
3
+ import { useInterval, usePage } from "@akanjs/next";
4
+ import { client } from "@akanjs/signal";
7
5
  import clsx from "clsx";
8
- import { useState } from "react";
6
+ import { useCallback, useEffect, useState } from "react";
9
7
  import { TbPlugConnected, TbPlugConnectedX } from "react-icons/tb";
10
- import { Image } from "../Image";
11
- const Reconnect = ({ path, dev = false, fetchPing = () => fetch.ping() }) => {
12
- const DOTS_LENGTH = 4;
8
+ const DOTS_LENGTH = 4;
9
+ const Reconnect = () => {
10
+ const { l } = usePage();
13
11
  const [dots, setDots] = useState(0);
14
- const connectStatus = st.use.connectStatus();
12
+ const [connectStatus, setConnectStatus] = useState("initial");
13
+ const handleConnect = useCallback(() => {
14
+ setConnectStatus((prev) => prev === "normal" || prev === "initial" ? prev : "connected");
15
+ }, []);
16
+ const handleDisconnect = useCallback(() => {
17
+ setConnectStatus((prev) => prev === "normal" || prev === "initial" ? "disconnected" : prev);
18
+ setTimeout(() => {
19
+ setConnectStatus((prev) => prev === "disconnected" ? "connecting" : prev);
20
+ }, 3e3);
21
+ }, []);
22
+ useEffect(() => {
23
+ const io = client.getIo();
24
+ io.socket.on("connect", handleConnect);
25
+ io.socket.on("disconnect", handleDisconnect);
26
+ setTimeout(() => {
27
+ if (connectStatus !== "initial")
28
+ return;
29
+ if (client.getIo().socket.connected)
30
+ setConnectStatus("normal");
31
+ else
32
+ handleDisconnect();
33
+ }, 1e3);
34
+ return () => {
35
+ io.socket.off("connect", handleConnect);
36
+ io.socket.off("disconnect", handleDisconnect);
37
+ };
38
+ }, []);
39
+ useEffect(() => {
40
+ if (connectStatus === "connected")
41
+ window.location.reload();
42
+ }, [connectStatus]);
15
43
  useInterval(() => {
16
- setDots((prev) => (prev + 1) % DOTS_LENGTH);
44
+ if (connectStatus === "connecting")
45
+ setDots((prev) => (prev + 1) % DOTS_LENGTH);
17
46
  }, 500);
18
- const reconnect = async () => {
19
- try {
20
- st.do.setConnectStatus("connecting");
21
- await fetchPing();
22
- st.do.setConnectStatus("connected");
23
- setTimeout(() => {
24
- if (!path || path === "/")
25
- router.replace("/");
26
- else
27
- router.replace(`/${path}`);
28
- }, 500);
29
- } catch (e) {
30
- }
31
- };
32
- useInterval(async () => {
33
- if (!window.location.href.includes("/unknown"))
34
- return;
35
- if (connectStatus === "connected")
36
- return;
37
- await reconnect();
38
- }, 5e3);
39
- return /* @__PURE__ */ jsx(Fragment, { children: dev ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("div", { className: "flex h-screen flex-col items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "bg-base-300 flex w-4/5 flex-col items-center justify-center rounded-md p-5 md:w-1/3", children: [
40
- /* @__PURE__ */ jsx("div", { className: "text-3xl font-bold", children: connectStatus === "disconnected" ? "Something's wrong!" : connectStatus === "connecting" ? "Connecting..." : "Connected!" }),
47
+ if (connectStatus === "initial" || connectStatus === "normal")
48
+ return null;
49
+ return /* @__PURE__ */ jsx("div", { className: "animate-fadeIn bg-base-100/50 fixed top-0 left-0 flex h-screen w-screen flex-col items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "bg-base-300 flex w-4/5 flex-col items-center justify-center rounded-md p-5 md:w-1/3", children: [
50
+ /* @__PURE__ */ jsx("div", { className: "text-3xl font-bold whitespace-nowrap", children: connectStatus === "disconnected" ? l("base.somethingWrong") : connectStatus === "connecting" ? l("base.connecting") : l("base.connected") }),
41
51
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center", children: [
42
- /* @__PURE__ */ jsx("div", { className: "py-5", children: connectStatus === "disconnected" ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("div", { className: "text-[150px] text-gray-500", children: /* @__PURE__ */ jsx(TbPlugConnectedX, {}) }) }) : connectStatus === "connecting" ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("div", { className: "animate-pulse py-5 text-[150px] text-gray-500", children: /* @__PURE__ */ jsx(TbPlugConnectedX, {}) }) }) : /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("div", { className: "animate-pop text-[150px] text-white", children: /* @__PURE__ */ jsx(TbPlugConnected, {}) }) }) }),
52
+ /* @__PURE__ */ jsx("div", { className: "py-5", children: connectStatus === "disconnected" ? /* @__PURE__ */ jsx("div", { className: "text-[150px] text-gray-500", children: /* @__PURE__ */ jsx(TbPlugConnectedX, {}) }) : connectStatus === "connecting" ? /* @__PURE__ */ jsx("div", { className: "animate-pulse py-5 text-[150px] text-gray-500", children: /* @__PURE__ */ jsx(TbPlugConnectedX, {}) }) : /* @__PURE__ */ jsx("div", { className: "animate-pop text-[150px] text-white", children: /* @__PURE__ */ jsx(TbPlugConnected, {}) }) }),
43
53
  connectStatus === "connected" ? /* @__PURE__ */ jsxs(Fragment, { children: [
44
54
  /* @__PURE__ */ jsx("div", { className: "animate-pop" }),
45
- /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx("span", { className: "text-lg", children: "Redirecting to the previous page in some seconds." }) })
55
+ /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx("span", { className: "text-lg", children: l("base.refreshing") }) })
46
56
  ] }) : connectStatus === "connecting" ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center", children: [
47
- /* @__PURE__ */ jsx("div", { className: "text-lg", children: "Try reconnecting to the server" }),
57
+ /* @__PURE__ */ jsx("div", { className: "text-lg", children: l("base.tryReconnecting") }),
48
58
  /* @__PURE__ */ jsx("div", { className: "flex items-center", children: Array.from({ length: DOTS_LENGTH }).map(
49
59
  (_, index) => dots >= index ? /* @__PURE__ */ jsx("div", { className: "visible", children: "." }, index) : /* @__PURE__ */ jsx("div", { className: "invisible", children: "." }, index)
50
60
  ) })
51
- ] }) : /* @__PURE__ */ jsx("div", { className: "text-lg", children: "Server disconnected." })
61
+ ] }) : /* @__PURE__ */ jsx("div", { className: "text-lg", children: l("base.serverDisconnected") })
52
62
  ] }),
53
63
  /* @__PURE__ */ jsx(
54
64
  "div",
@@ -57,21 +67,13 @@ const Reconnect = ({ path, dev = false, fetchPing = () => fetch.ping() }) => {
57
67
  "mt-2 text-center text-sm leading-tight text-gray-500",
58
68
  connectStatus === "disconnected" || connectStatus === "connecting" ? "visible" : "invisible"
59
69
  ),
60
- children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-2", children: [
61
- /* @__PURE__ */ jsx("div", { className: "font-bold", children: "*" }),
62
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center", children: [
63
- /* @__PURE__ */ jsx("div", { children: " Maybe your server is having a problem." }),
64
- /* @__PURE__ */ jsx("div", { className: "font-bold", children: "please check your server status." })
65
- ] })
66
- ] })
70
+ children: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center gap-2", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center", children: [
71
+ /* @__PURE__ */ jsx("div", { children: l("base.serverHasProblem") }),
72
+ /* @__PURE__ */ jsx("div", { className: "font-bold", children: l("base.checkServerStatus") })
73
+ ] }) })
67
74
  }
68
75
  )
69
- ] }) }) }) : /* @__PURE__ */ jsx("div", { className: "flex h-screen items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "bg-base-300 flex w-4/5 flex-col items-center justify-center rounded-md py-5 md:w-1/3", children: [
70
- /* @__PURE__ */ jsx("div", { className: "text-3xl font-bold", children: "\uBB38\uC81C\uAC00 \uBC1C\uC0DD\uD588\uC5B4\uC694!" }),
71
- /* @__PURE__ */ jsx(Image, { className: "mt-5", src: "/deadBot.svg", alt: "deadBot", color: "gray", width: 120, height: 120 }),
72
- /* @__PURE__ */ jsx("div", { className: "text-lg", children: "\uC11C\uBC84\uC5D0 \uBB38\uC81C\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4." }),
73
- /* @__PURE__ */ jsx("div", { className: "text-lg", children: "\uC11C\uBC84\uC5D0 \uC5F0\uACB0\uC744 \uC7AC\uC2DC\uB3C4\uD558\uACE0 \uC788\uC5B4\uC694..." })
74
- ] }) }) });
76
+ ] }) });
75
77
  };
76
78
  export {
77
79
  Reconnect
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/ui",
3
- "version": "0.9.41",
3
+ "version": "0.9.43",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,5 +0,0 @@
1
- interface HealthCheckProps {
2
- fetchPing?: () => Promise<any>;
3
- }
4
- export declare const HealthCheck: ({ fetchPing }: HealthCheckProps) => import("react/jsx-runtime").JSX.Element;
5
- export {};
@@ -1,63 +0,0 @@
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 HealthCheck_exports = {};
20
- __export(HealthCheck_exports, {
21
- HealthCheck: () => HealthCheck
22
- });
23
- module.exports = __toCommonJS(HealthCheck_exports);
24
- var import_jsx_runtime = require("react/jsx-runtime");
25
- var import_client = require("@akanjs/client");
26
- var import_next = require("@akanjs/next");
27
- var import_signal = require("@akanjs/signal");
28
- var import_store = require("@akanjs/store");
29
- var import_react = require("react");
30
- const HealthCheck = ({ fetchPing = () => import_signal.fetch.ping() }) => {
31
- (0, import_react.useEffect)(() => {
32
- void (async () => {
33
- if (window.location.href.includes("/unknown"))
34
- return;
35
- const fullPath = import_client.router.getFullPath(false);
36
- try {
37
- await fetchPing();
38
- import_store.st.do.setConnectStatus("connected");
39
- if (window.location.href.includes("/unknown")) {
40
- import_client.router.back();
41
- }
42
- } catch (e) {
43
- import_store.st.do.setConnectStatus("disconnected");
44
- import_client.router.replace(`/unknown?p=${encodeURIComponent(fullPath)}`);
45
- }
46
- })();
47
- }, []);
48
- const pingCheck = async function() {
49
- try {
50
- await fetchPing();
51
- } catch (e) {
52
- import_store.st.do.setConnectStatus("disconnected");
53
- const fullPath = import_client.router.getFullPath(false);
54
- import_client.router.replace(`/unknown?p=${encodeURIComponent(fullPath)}`);
55
- }
56
- };
57
- (0, import_next.useInterval)(async () => {
58
- if (window.location.href.includes("/unknown"))
59
- return;
60
- await pingCheck();
61
- }, 1e4);
62
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
63
- };
@@ -1,44 +0,0 @@
1
- "use client";
2
- import { Fragment, jsx } from "react/jsx-runtime";
3
- import { router } from "@akanjs/client";
4
- import { useInterval } from "@akanjs/next";
5
- import { fetch } from "@akanjs/signal";
6
- import { st } from "@akanjs/store";
7
- import { useEffect } from "react";
8
- const HealthCheck = ({ fetchPing = () => fetch.ping() }) => {
9
- useEffect(() => {
10
- void (async () => {
11
- if (window.location.href.includes("/unknown"))
12
- return;
13
- const fullPath = router.getFullPath(false);
14
- try {
15
- await fetchPing();
16
- st.do.setConnectStatus("connected");
17
- if (window.location.href.includes("/unknown")) {
18
- router.back();
19
- }
20
- } catch (e) {
21
- st.do.setConnectStatus("disconnected");
22
- router.replace(`/unknown?p=${encodeURIComponent(fullPath)}`);
23
- }
24
- })();
25
- }, []);
26
- const pingCheck = async function() {
27
- try {
28
- await fetchPing();
29
- } catch (e) {
30
- st.do.setConnectStatus("disconnected");
31
- const fullPath = router.getFullPath(false);
32
- router.replace(`/unknown?p=${encodeURIComponent(fullPath)}`);
33
- }
34
- };
35
- useInterval(async () => {
36
- if (window.location.href.includes("/unknown"))
37
- return;
38
- await pingCheck();
39
- }, 1e4);
40
- return /* @__PURE__ */ jsx(Fragment, {});
41
- };
42
- export {
43
- HealthCheck
44
- };