dn-react-router-toolkit 0.7.15 → 0.8.0

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.
Files changed (63) hide show
  1. package/dist/api/create_api_handler.d.mts +5 -4
  2. package/dist/api/create_api_handler.d.ts +5 -4
  3. package/dist/api/create_api_handler.js +0 -1
  4. package/dist/api/create_api_handler.mjs +0 -1
  5. package/dist/api/index.d.mts +1 -0
  6. package/dist/api/index.d.ts +1 -0
  7. package/dist/api/index.js +0 -2
  8. package/dist/api/index.mjs +0 -2
  9. package/dist/api/item_api_handler.d.mts +5 -4
  10. package/dist/api/item_api_handler.d.ts +5 -4
  11. package/dist/api/item_api_handler.js +0 -1
  12. package/dist/api/item_api_handler.mjs +0 -1
  13. package/dist/crud/crud_loader.d.mts +6 -5
  14. package/dist/crud/crud_loader.d.ts +6 -5
  15. package/dist/crud/crud_loader.js +46 -34
  16. package/dist/crud/crud_loader.mjs +46 -34
  17. package/dist/crud/crud_page.d.mts +3 -2
  18. package/dist/crud/crud_page.d.ts +3 -2
  19. package/dist/crud/crud_page.js +225 -197
  20. package/dist/crud/crud_page.mjs +223 -201
  21. package/dist/crud/generate_handlers.d.mts +3 -2
  22. package/dist/crud/generate_handlers.d.ts +3 -2
  23. package/dist/crud/generate_pages.d.mts +2 -1
  24. package/dist/crud/generate_pages.d.ts +2 -1
  25. package/dist/crud/index.d.mts +5 -3
  26. package/dist/crud/index.d.ts +5 -3
  27. package/dist/crud/index.js +245 -205
  28. package/dist/crud/index.mjs +251 -217
  29. package/dist/post/index.js +65 -58
  30. package/dist/post/index.mjs +68 -67
  31. package/dist/post/post_form_page.js +65 -58
  32. package/dist/post/post_form_page.mjs +68 -67
  33. package/dist/table/index.d.mts +7 -3
  34. package/dist/table/index.d.ts +7 -3
  35. package/dist/table/index.js +153 -105
  36. package/dist/table/index.mjs +149 -110
  37. package/dist/table/item_loader.d.mts +5 -4
  38. package/dist/table/item_loader.d.ts +5 -4
  39. package/dist/table/load_table.d.mts +30 -0
  40. package/dist/table/load_table.d.ts +30 -0
  41. package/dist/table/load_table.js +67 -0
  42. package/dist/table/load_table.mjs +45 -0
  43. package/dist/table/loader.d.mts +7 -15
  44. package/dist/table/loader.d.ts +7 -15
  45. package/dist/table/loader.js +47 -31
  46. package/dist/table/loader.mjs +46 -32
  47. package/dist/table/page.d.mts +6 -16
  48. package/dist/table/page.d.ts +6 -16
  49. package/dist/table/page.js +193 -165
  50. package/dist/table/page.mjs +194 -172
  51. package/dist/table/repository.d.mts +13 -11
  52. package/dist/table/repository.d.ts +13 -11
  53. package/dist/table/repository.js +1 -1
  54. package/dist/table/repository.mjs +1 -1
  55. package/dist/table/table_form.d.mts +13 -0
  56. package/dist/table/table_form.d.ts +13 -0
  57. package/dist/table/table_form.js +295 -0
  58. package/dist/table/table_form.mjs +270 -0
  59. package/dist/table/use_table.d.mts +4 -0
  60. package/dist/table/use_table.d.ts +4 -0
  61. package/dist/table/use_table.js +43 -0
  62. package/dist/table/use_table.mjs +18 -0
  63. package/package.json +1 -1
@@ -3,8 +3,9 @@ import { CrudPage } from './crud_page.js';
3
3
  import './crud_form_provider.js';
4
4
  import 'react';
5
5
  import 'react-store-input';
6
- import '../table/page.js';
6
+ import '../table/table_form.js';
7
7
  import '../table/table.js';
8
+ import '../table/use_table.js';
8
9
 
9
10
  declare const generatePages: (pages: Record<string, CrudPage>) => {
10
11
  Page: () => react_jsx_runtime.JSX.Element | undefined;
@@ -9,15 +9,17 @@ import 'react/jsx-runtime';
9
9
  import 'react';
10
10
  import 'react-store-input';
11
11
  import 'react-router';
12
- import '../table/loader.mjs';
12
+ import '../table/item_loader.mjs';
13
13
  import '../table/repository.mjs';
14
14
  import 'drizzle-orm';
15
+ import 'drizzle-orm/node-postgres';
15
16
  import 'drizzle-orm/pg-core';
16
- import '../table/item_loader.mjs';
17
+ import '../table/load_table.mjs';
17
18
  import '../api/create_api_handler.mjs';
18
19
  import '../auth/with_auth.mjs';
19
20
  import 'dn-react-toolkit/auth';
20
21
  import 'dn-react-toolkit/auth/server';
21
- import '../table/page.mjs';
22
+ import '../table/table_form.mjs';
22
23
  import '../table/table.mjs';
24
+ import '../table/use_table.mjs';
23
25
  import '@react-router/dev/routes';
@@ -9,15 +9,17 @@ import 'react/jsx-runtime';
9
9
  import 'react';
10
10
  import 'react-store-input';
11
11
  import 'react-router';
12
- import '../table/loader.js';
12
+ import '../table/item_loader.js';
13
13
  import '../table/repository.js';
14
14
  import 'drizzle-orm';
15
+ import 'drizzle-orm/node-postgres';
15
16
  import 'drizzle-orm/pg-core';
16
- import '../table/item_loader.js';
17
+ import '../table/load_table.js';
17
18
  import '../api/create_api_handler.js';
18
19
  import '../auth/with_auth.js';
19
20
  import 'dn-react-toolkit/auth';
20
21
  import 'dn-react-toolkit/auth/server';
21
- import '../table/page.js';
22
+ import '../table/table_form.js';
22
23
  import '../table/table.js';
24
+ import '../table/use_table.js';
23
25
  import '@react-router/dev/routes';
@@ -7991,45 +7991,59 @@ function CrudForm({
7991
7991
  ] });
7992
7992
  }
7993
7993
 
7994
- // src/table/loader.tsx
7994
+ // src/table/load_table.tsx
7995
7995
  var import_drizzle_orm = require("drizzle-orm");
7996
+ async function loadTable({
7997
+ request,
7998
+ repository,
7999
+ options
8000
+ }) {
8001
+ const searchParams = new URL(request.url).searchParams;
8002
+ const { where, searchKey, defaultOrderBy, defaultDirection } = options;
8003
+ const query = searchParams.get("query") ?? void 0;
8004
+ const limit = Number(searchParams.get("limit") ?? "20");
8005
+ const offset = Number(searchParams.get("offset") ?? "0");
8006
+ const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
8007
+ const direction = searchParams.get("direction") ?? defaultDirection;
8008
+ const whereClauses = (0, import_drizzle_orm.and)(
8009
+ searchKey && query ? (0, import_drizzle_orm.ilike)(
8010
+ repository.schema[searchKey],
8011
+ `%${query}%`
8012
+ ) : void 0,
8013
+ ...where ?? []
8014
+ );
8015
+ const total = await repository.countTotal({ where: whereClauses });
8016
+ const items = await repository.findAll({
8017
+ orderBy,
8018
+ direction,
8019
+ limit,
8020
+ offset,
8021
+ where: whereClauses
8022
+ });
8023
+ return {
8024
+ items,
8025
+ total,
8026
+ limit,
8027
+ offset,
8028
+ orderBy,
8029
+ direction,
8030
+ searchKey
8031
+ };
8032
+ }
8033
+
8034
+ // src/table/loader.tsx
7996
8035
  function tableLoader({
7997
8036
  repository,
7998
- tableOptions
8037
+ options
7999
8038
  }) {
8000
8039
  return async ({ request }) => {
8001
- const searchParams = new URL(request.url).searchParams;
8002
- const { where, searchKey, defaultOrderBy, defaultDirection } = tableOptions;
8003
- const query = searchParams.get("query") ?? void 0;
8004
- const limit = Number(searchParams.get("limit") ?? "10");
8005
- const offset = Number(searchParams.get("offset") ?? "0");
8006
- const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
8007
- const direction = searchParams.get("direction") ?? defaultDirection;
8008
- const whereClauses = (0, import_drizzle_orm.and)(
8009
- searchKey && query ? (0, import_drizzle_orm.ilike)(
8010
- repository.schema[searchKey],
8011
- `%${query}%`
8012
- ) : void 0,
8013
- ...where ?? []
8014
- );
8015
- const total = await repository.countTotal({ where: whereClauses });
8016
- const items = await repository.findAll({
8017
- orderBy,
8018
- direction,
8019
- limit,
8020
- offset,
8021
- where: whereClauses
8040
+ const table = await loadTable({
8041
+ request,
8042
+ repository,
8043
+ options
8022
8044
  });
8023
8045
  return {
8024
- table: {
8025
- items,
8026
- total,
8027
- limit,
8028
- offset,
8029
- orderBy,
8030
- direction,
8031
- searchKey
8032
- }
8046
+ table
8033
8047
  };
8034
8048
  };
8035
8049
  }
@@ -8053,7 +8067,6 @@ var tableItemloader = ({
8053
8067
  // src/api/create_api_handler.ts
8054
8068
  var import_http = require("dn-react-toolkit/http");
8055
8069
  var import_drizzle_orm2 = require("drizzle-orm");
8056
- var import_react_router4 = require("react-router");
8057
8070
  var import_uuid = require("uuid");
8058
8071
  function apiHandler({
8059
8072
  withAuthAction,
@@ -8142,7 +8155,6 @@ function apiHandler({
8142
8155
 
8143
8156
  // src/api/item_api_handler.ts
8144
8157
  var import_http2 = require("dn-react-toolkit/http");
8145
- var import_react_router5 = require("react-router");
8146
8158
  function itemApiHandler({
8147
8159
  withAuthAction,
8148
8160
  repository
@@ -8238,86 +8250,16 @@ var import_react_router9 = require("react-router");
8238
8250
 
8239
8251
  // src/table/page.tsx
8240
8252
  var import_react_router8 = require("react-router");
8241
- var import_go2 = require("react-icons/go");
8242
8253
 
8243
- // src/table/buttons.tsx
8244
- var import_utils3 = require("dn-react-toolkit/utils");
8245
- var import_react_router6 = require("react-router");
8246
- var import_jsx_runtime7 = require("react/jsx-runtime");
8247
- function TablePageButtons({
8248
- MAX_PAGES_TO_SHOW,
8249
- total,
8250
- limit,
8251
- offset
8252
- }) {
8253
- const pages = Math.ceil(total / limit);
8254
- const { pathname } = (0, import_react_router6.useLocation)();
8255
- const [searchParams] = (0, import_react_router6.useSearchParams)();
8256
- const currentPage = Math.floor(offset / limit) + 1;
8257
- const startButton = (Math.ceil(currentPage / MAX_PAGES_TO_SHOW) - 1) * MAX_PAGES_TO_SHOW;
8258
- const endButton = Math.min(startButton + MAX_PAGES_TO_SHOW - 1, pages);
8259
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: pages > 1 && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex justify-center items-center my-8 gap-4 text-neutral-400", children: [
8260
- startButton > 1 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
8261
- import_react_router6.Link,
8262
- {
8263
- to: (() => {
8264
- searchParams.set(
8265
- "offset",
8266
- String((startButton - 1) * limit)
8267
- );
8268
- return `${pathname}?${searchParams.toString()}`;
8269
- })(),
8270
- className: "w-10 block text-center transition-colors hover:text-primary",
8271
- children: "\uC774\uC804"
8272
- }
8273
- ),
8274
- Array.from({
8275
- length: Math.min(
8276
- MAX_PAGES_TO_SHOW,
8277
- pages - startButton
8278
- )
8279
- }).map((_, index2) => {
8280
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
8281
- import_react_router6.Link,
8282
- {
8283
- to: (() => {
8284
- searchParams.set(
8285
- "offset",
8286
- String((startButton + index2) * limit)
8287
- );
8288
- return `${pathname}?${searchParams.toString()}`;
8289
- })(),
8290
- className: (0, import_utils3.cn)(
8291
- "w-6 block text-center transition-colors",
8292
- currentPage === startButton + index2 + 1 ? "font-bold text-primary" : "hover:text-primary"
8293
- ),
8294
- children: startButton + index2 + 1
8295
- },
8296
- index2
8297
- );
8298
- }),
8299
- endButton < pages && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
8300
- import_react_router6.Link,
8301
- {
8302
- to: (() => {
8303
- searchParams.set(
8304
- "offset",
8305
- String((endButton + 1) * limit)
8306
- );
8307
- return `${pathname}?${searchParams.toString()}`;
8308
- })(),
8309
- className: "w-10 block text-center transition-colors hover:text-primary",
8310
- children: "\uB2E4\uC74C"
8311
- }
8312
- )
8313
- ] }) });
8314
- }
8254
+ // src/table/table_form.tsx
8255
+ var import_react_router7 = require("react-router");
8256
+ var import_go2 = require("react-icons/go");
8315
8257
 
8316
8258
  // src/table/table.tsx
8317
- var import_utils4 = require("dn-react-toolkit/utils");
8259
+ var import_utils3 = require("dn-react-toolkit/utils");
8318
8260
  var import_go = require("react-icons/go");
8319
- var import_react_router7 = require("react-router");
8320
- var import_jsx_runtime8 = require("react/jsx-runtime");
8261
+ var import_react_router4 = require("react-router");
8262
+ var import_jsx_runtime7 = require("react/jsx-runtime");
8321
8263
  function Table({
8322
8264
  className = "min-w-full whitespace-nowrap",
8323
8265
  data,
@@ -8331,13 +8273,13 @@ function Table({
8331
8273
  }) {
8332
8274
  const keys = Object.entries(columns).filter((entry) => entry[1]).map(([key]) => key);
8333
8275
  const sortedArray = [...data];
8334
- const [_, setSearchParams] = (0, import_react_router7.useSearchParams)();
8335
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
8276
+ const [_, setSearchParams] = (0, import_react_router4.useSearchParams)();
8277
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
8336
8278
  "table",
8337
8279
  {
8338
- className: (0, import_utils4.cn)(className, "text-[15px] border-separate border-spacing-0"),
8280
+ className: (0, import_utils3.cn)(className, "text-[15px] border-separate border-spacing-0"),
8339
8281
  children: [
8340
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("tr", { children: keys.map((key) => {
8282
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("tr", { children: keys.map((key) => {
8341
8283
  const value = columns[key];
8342
8284
  function getReactNode() {
8343
8285
  if (value && typeof value === "object" && "label" in value) {
@@ -8348,10 +8290,10 @@ function Table({
8348
8290
  function Head() {
8349
8291
  const reactNode = getReactNode();
8350
8292
  if (typeof reactNode === "string") {
8351
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
8293
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
8352
8294
  "button",
8353
8295
  {
8354
- className: (0, import_utils4.cn)(
8296
+ className: (0, import_utils3.cn)(
8355
8297
  orderBy === key ? "text-neutral-900 font-medium" : "text-neutral-500",
8356
8298
  "px-4 h-14 flex items-center w-full"
8357
8299
  ),
@@ -8367,17 +8309,17 @@ function Table({
8367
8309
  },
8368
8310
  children: [
8369
8311
  reactNode,
8370
- orderBy === key && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "ml-0.5", children: direction === "asc" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_go.GoArrowUp, {}) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_go.GoArrowDown, {}) })
8312
+ orderBy === key && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "ml-0.5", children: direction === "asc" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_go.GoArrowUp, {}) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_go.GoArrowDown, {}) })
8371
8313
  ]
8372
8314
  }
8373
8315
  );
8374
8316
  }
8375
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: reactNode });
8317
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: reactNode });
8376
8318
  }
8377
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("th", { className: (0, import_utils4.cn)("border-y font-normal"), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Head, {}) }, key);
8319
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("th", { className: (0, import_utils3.cn)("border-y font-normal"), children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Head, {}) }, key);
8378
8320
  }) }) }),
8379
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("tbody", { children: [
8380
- sortedArray.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
8321
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("tbody", { children: [
8322
+ sortedArray.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
8381
8323
  "td",
8382
8324
  {
8383
8325
  colSpan: keys.length,
@@ -8385,7 +8327,7 @@ function Table({
8385
8327
  children: "\uB370\uC774\uD130\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."
8386
8328
  }
8387
8329
  ) }),
8388
- sortedArray.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("tr", { className: "hover:bg-gray-50 transition-colors", children: keys.map((key, i2) => {
8330
+ sortedArray.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("tr", { className: "hover:bg-gray-50 transition-colors", children: keys.map((key, i2) => {
8389
8331
  const value = item[key];
8390
8332
  function Content() {
8391
8333
  if (key in columns) {
@@ -8393,22 +8335,22 @@ function Table({
8393
8335
  if (column && typeof column === "object" && "mapper" in column) {
8394
8336
  const mapper = column.mapper;
8395
8337
  if (mapper) {
8396
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: mapper(item) });
8338
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: mapper(item) });
8397
8339
  }
8398
8340
  }
8399
8341
  }
8400
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: String(value) });
8342
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: String(value) });
8401
8343
  }
8402
- const linkedContent = getLink ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
8403
- import_react_router7.Link,
8344
+ const linkedContent = getLink ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
8345
+ import_react_router4.Link,
8404
8346
  {
8405
8347
  to: getLink(item),
8406
8348
  className: "block content-center px-4 w-full h-full",
8407
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Content, {})
8349
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Content, {})
8408
8350
  }
8409
- ) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Content, {});
8410
- const cell = Mapper ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Mapper, { item, index: i2, children: linkedContent }) : linkedContent;
8411
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("td", { className: "px-0 h-14 border-b", children: cell }, key);
8351
+ ) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Content, {});
8352
+ const cell = Mapper ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Mapper, { item, index: i2, children: linkedContent }) : linkedContent;
8353
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("td", { className: "px-0 h-14 border-b", children: cell }, key);
8412
8354
  }) }, i))
8413
8355
  ] })
8414
8356
  ]
@@ -8416,8 +8358,169 @@ function Table({
8416
8358
  );
8417
8359
  }
8418
8360
 
8419
- // src/table/page.tsx
8361
+ // src/table/use_table.tsx
8362
+ var import_react_router5 = require("react-router");
8363
+ function useTable() {
8364
+ const { table } = (0, import_react_router5.useLoaderData)();
8365
+ const { items, total, limit, offset, orderBy, direction, searchKey } = table;
8366
+ return {
8367
+ items,
8368
+ total,
8369
+ limit,
8370
+ offset,
8371
+ orderBy,
8372
+ direction,
8373
+ searchKey
8374
+ };
8375
+ }
8376
+
8377
+ // src/table/buttons.tsx
8378
+ var import_utils4 = require("dn-react-toolkit/utils");
8379
+ var import_react_router6 = require("react-router");
8380
+ var import_jsx_runtime8 = require("react/jsx-runtime");
8381
+ function TablePageButtons({
8382
+ MAX_PAGES_TO_SHOW,
8383
+ total,
8384
+ limit,
8385
+ offset
8386
+ }) {
8387
+ const pages = Math.ceil(total / limit);
8388
+ const { pathname } = (0, import_react_router6.useLocation)();
8389
+ const [searchParams] = (0, import_react_router6.useSearchParams)();
8390
+ const currentPage = Math.floor(offset / limit) + 1;
8391
+ const startButton = (Math.ceil(currentPage / MAX_PAGES_TO_SHOW) - 1) * MAX_PAGES_TO_SHOW;
8392
+ const endButton = Math.min(startButton + MAX_PAGES_TO_SHOW - 1, pages);
8393
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: pages > 1 && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex justify-center items-center my-8 gap-4 text-neutral-400", children: [
8394
+ startButton > 1 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
8395
+ import_react_router6.Link,
8396
+ {
8397
+ to: (() => {
8398
+ searchParams.set(
8399
+ "offset",
8400
+ String((startButton - 1) * limit)
8401
+ );
8402
+ return `${pathname}?${searchParams.toString()}`;
8403
+ })(),
8404
+ className: "w-10 block text-center transition-colors hover:text-primary",
8405
+ children: "\uC774\uC804"
8406
+ }
8407
+ ),
8408
+ Array.from({
8409
+ length: Math.min(
8410
+ MAX_PAGES_TO_SHOW,
8411
+ pages - startButton
8412
+ )
8413
+ }).map((_, index2) => {
8414
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
8415
+ import_react_router6.Link,
8416
+ {
8417
+ to: (() => {
8418
+ searchParams.set(
8419
+ "offset",
8420
+ String((startButton + index2) * limit)
8421
+ );
8422
+ return `${pathname}?${searchParams.toString()}`;
8423
+ })(),
8424
+ className: (0, import_utils4.cn)(
8425
+ "w-6 block text-center transition-colors",
8426
+ currentPage === startButton + index2 + 1 ? "font-bold text-primary" : "hover:text-primary"
8427
+ ),
8428
+ children: startButton + index2 + 1
8429
+ },
8430
+ index2
8431
+ );
8432
+ }),
8433
+ endButton < pages && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
8434
+ import_react_router6.Link,
8435
+ {
8436
+ to: (() => {
8437
+ searchParams.set(
8438
+ "offset",
8439
+ String((endButton + 1) * limit)
8440
+ );
8441
+ return `${pathname}?${searchParams.toString()}`;
8442
+ })(),
8443
+ className: "w-10 block text-center transition-colors hover:text-primary",
8444
+ children: "\uB2E4\uC74C"
8445
+ }
8446
+ )
8447
+ ] }) });
8448
+ }
8449
+
8450
+ // src/table/table_form.tsx
8420
8451
  var import_jsx_runtime9 = require("react/jsx-runtime");
8452
+ function TableForm({
8453
+ columns,
8454
+ primaryKey = "id"
8455
+ }) {
8456
+ const { pathname } = (0, import_react_router7.useLocation)();
8457
+ const { items, total, limit, offset, orderBy, direction, searchKey } = useTable();
8458
+ const navigate = (0, import_react_router7.useNavigate)();
8459
+ const search = (query) => {
8460
+ const searchParams2 = new URLSearchParams(window.location.search);
8461
+ searchParams2.set("query", query);
8462
+ searchParams2.set("offset", "0");
8463
+ navigate(`${pathname}?${searchParams2.toString()}`);
8464
+ };
8465
+ const [searchParams] = (0, import_react_router7.useSearchParams)();
8466
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
8467
+ searchKey && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
8468
+ "form",
8469
+ {
8470
+ className: "h-18 px-4 flex items-center border-t",
8471
+ onSubmit: (e) => {
8472
+ e.preventDefault();
8473
+ const formData = new FormData(e.currentTarget);
8474
+ const query = formData.get("query");
8475
+ search(query);
8476
+ },
8477
+ children: [
8478
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
8479
+ "button",
8480
+ {
8481
+ type: "submit",
8482
+ className: "w-10 h-10 flex justify-center items-center",
8483
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_go2.GoSearch, { className: "text-xl mr-4" })
8484
+ }
8485
+ ),
8486
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
8487
+ "input",
8488
+ {
8489
+ className: "outline-none h-full flex-1",
8490
+ placeholder: "\uC5EC\uAE30\uC5D0 \uAC80\uC0C9\uD558\uC138\uC694...",
8491
+ name: "query",
8492
+ defaultValue: searchParams.get("query") ?? ""
8493
+ }
8494
+ )
8495
+ ]
8496
+ }
8497
+ ),
8498
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
8499
+ Table,
8500
+ {
8501
+ data: items,
8502
+ columns,
8503
+ getLink: primaryKey ? (item) => `${pathname}/${item[primaryKey]}` : void 0,
8504
+ limit,
8505
+ offset,
8506
+ orderBy,
8507
+ direction
8508
+ }
8509
+ ),
8510
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
8511
+ TablePageButtons,
8512
+ {
8513
+ total,
8514
+ limit,
8515
+ offset,
8516
+ MAX_PAGES_TO_SHOW: 10
8517
+ }
8518
+ )
8519
+ ] });
8520
+ }
8521
+
8522
+ // src/table/page.tsx
8523
+ var import_jsx_runtime10 = require("react/jsx-runtime");
8421
8524
  function createTablePage({
8422
8525
  name,
8423
8526
  columns,
@@ -8427,87 +8530,24 @@ function createTablePage({
8427
8530
  header: Header
8428
8531
  }) {
8429
8532
  const { pathname } = (0, import_react_router8.useLocation)();
8430
- const { table } = (0, import_react_router8.useLoaderData)();
8431
- const { items, total, limit, offset, orderBy, direction, searchKey } = table;
8432
- const navigate = (0, import_react_router8.useNavigate)();
8433
- const search = (query) => {
8434
- const searchParams2 = new URLSearchParams(window.location.search);
8435
- searchParams2.set("query", query);
8436
- searchParams2.set("offset", "0");
8437
- navigate(`${pathname}?${searchParams2.toString()}`);
8438
- };
8439
- const [searchParams] = (0, import_react_router8.useSearchParams)();
8440
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
8441
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
8533
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
8534
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
8442
8535
  Header,
8443
8536
  {
8444
8537
  title: name,
8445
- actions: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react_router8.Link, { to: `${pathname}/new`, className: "button-primary", children: [
8538
+ actions: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_react_router8.Link, { to: `${pathname}/new`, className: "button-primary", children: [
8446
8539
  name,
8447
8540
  " \uCD94\uAC00"
8448
8541
  ] })
8449
8542
  }
8450
8543
  ),
8451
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "max-w-7xl mx-auto w-full overflow-auto", children: [
8452
- searchKey && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
8453
- "form",
8454
- {
8455
- className: "h-18 px-4 flex items-center border-t",
8456
- onSubmit: (e) => {
8457
- e.preventDefault();
8458
- const formData = new FormData(e.currentTarget);
8459
- const query = formData.get("query");
8460
- search(query);
8461
- },
8462
- children: [
8463
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
8464
- "button",
8465
- {
8466
- type: "submit",
8467
- className: "w-10 h-10 flex justify-center items-center",
8468
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_go2.GoSearch, { className: "text-xl mr-4" })
8469
- }
8470
- ),
8471
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
8472
- "input",
8473
- {
8474
- className: "outline-none h-full flex-1",
8475
- placeholder: "\uC5EC\uAE30\uC5D0 \uAC80\uC0C9\uD558\uC138\uC694...",
8476
- name: "query",
8477
- defaultValue: searchParams.get("query") ?? ""
8478
- }
8479
- )
8480
- ]
8481
- }
8482
- ),
8483
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
8484
- Table,
8485
- {
8486
- data: items,
8487
- columns,
8488
- getLink: primaryKey ? (item) => `${pathname}/${item[primaryKey]}` : void 0,
8489
- limit,
8490
- offset,
8491
- orderBy,
8492
- direction
8493
- }
8494
- ),
8495
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
8496
- TablePageButtons,
8497
- {
8498
- total,
8499
- limit,
8500
- offset,
8501
- MAX_PAGES_TO_SHOW: 10
8502
- }
8503
- )
8504
- ] })
8544
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "max-w-7xl mx-auto w-full overflow-auto", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TableForm, { columns, primaryKey }) })
8505
8545
  ] });
8506
8546
  };
8507
8547
  }
8508
8548
 
8509
8549
  // src/crud/crud_page.tsx
8510
- var import_jsx_runtime10 = require("react/jsx-runtime");
8550
+ var import_jsx_runtime11 = require("react/jsx-runtime");
8511
8551
  function crudPage({
8512
8552
  name,
8513
8553
  primaryKey,
@@ -8524,10 +8564,10 @@ function crudPage({
8524
8564
  ...tablePageOptions,
8525
8565
  name
8526
8566
  });
8527
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Component, { header });
8567
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Component, { header });
8528
8568
  }
8529
8569
  if (pathname.startsWith(prefix2)) {
8530
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
8570
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
8531
8571
  CrudFormProvider,
8532
8572
  {
8533
8573
  item: data?.item,
@@ -8535,7 +8575,7 @@ function crudPage({
8535
8575
  name,
8536
8576
  columns: formOptions.columns,
8537
8577
  primaryKey,
8538
- children: formOptions.form ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(FormDelegate, { component: formOptions.form }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CrudForm, { AdminHeader: header })
8578
+ children: formOptions.form ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FormDelegate, { component: formOptions.form }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(CrudForm, { AdminHeader: header })
8539
8579
  }
8540
8580
  );
8541
8581
  }
@@ -8550,7 +8590,7 @@ function FormDelegate({
8550
8590
  component: Component
8551
8591
  }) {
8552
8592
  const form = useFormContext();
8553
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Component, { form });
8593
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Component, { form });
8554
8594
  }
8555
8595
 
8556
8596
  // src/crud/generate_handlers.ts
@@ -8567,14 +8607,14 @@ var generateHandlers = (handlers) => {
8567
8607
 
8568
8608
  // src/crud/generate_pages.tsx
8569
8609
  var import_react_router10 = require("react-router");
8570
- var import_jsx_runtime11 = require("react/jsx-runtime");
8610
+ var import_jsx_runtime12 = require("react/jsx-runtime");
8571
8611
  var generatePages = (pages) => {
8572
8612
  function Page() {
8573
8613
  const { pathname } = (0, import_react_router10.useLocation)();
8574
8614
  for (const route2 of Object.keys(pages)) {
8575
8615
  if (pathname.startsWith(route2)) {
8576
8616
  const Page2 = pages[route2].create(route2);
8577
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Page2, {});
8617
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Page2, {});
8578
8618
  }
8579
8619
  }
8580
8620
  }