dn-react-router-toolkit 0.8.0 → 0.9.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 (71) hide show
  1. package/dist/api/index.js +13 -4
  2. package/dist/api/index.mjs +14 -5
  3. package/dist/api/item_api_handler.d.mts +4 -2
  4. package/dist/api/item_api_handler.d.ts +4 -2
  5. package/dist/api/item_api_handler.js +13 -4
  6. package/dist/api/item_api_handler.mjs +14 -5
  7. package/dist/crud/index.d.mts +0 -20
  8. package/dist/crud/index.d.ts +0 -20
  9. package/dist/crud/index.js +12 -8508
  10. package/dist/crud/index.mjs +0 -8516
  11. package/dist/post/index.js +67 -7705
  12. package/dist/post/index.mjs +54 -7717
  13. package/dist/post/post_form_page.js +67 -7705
  14. package/dist/post/post_form_page.mjs +54 -7717
  15. package/dist/table/index.d.mts +1 -3
  16. package/dist/table/index.d.ts +1 -3
  17. package/dist/table/index.js +83 -76
  18. package/dist/table/index.mjs +84 -74
  19. package/dist/table/load_table.d.mts +8 -2
  20. package/dist/table/load_table.d.ts +8 -2
  21. package/dist/table/load_table.js +23 -3
  22. package/dist/table/load_table.mjs +24 -3
  23. package/dist/table/loader.d.mts +3 -0
  24. package/dist/table/loader.d.ts +3 -0
  25. package/dist/table/loader.js +23 -3
  26. package/dist/table/loader.mjs +24 -3
  27. package/dist/table/repository.d.mts +6 -4
  28. package/dist/table/repository.d.ts +6 -4
  29. package/dist/table/repository.js +4 -0
  30. package/dist/table/repository.mjs +4 -0
  31. package/dist/table/table.d.mts +5 -2
  32. package/dist/table/table.d.ts +5 -2
  33. package/dist/table/table.js +38 -6
  34. package/dist/table/table.mjs +38 -6
  35. package/dist/table/table_form.d.mts +2 -2
  36. package/dist/table/table_form.d.ts +2 -2
  37. package/dist/table/table_form.js +52 -19
  38. package/dist/table/table_form.mjs +52 -19
  39. package/dist/table/use_table.d.mts +3 -3
  40. package/dist/table/use_table.d.ts +3 -3
  41. package/dist/table/use_table.js +1 -10
  42. package/dist/table/use_table.mjs +1 -10
  43. package/package.json +1 -1
  44. package/dist/crud/crud_loader.d.mts +0 -26
  45. package/dist/crud/crud_loader.d.ts +0 -26
  46. package/dist/crud/crud_loader.js +0 -322
  47. package/dist/crud/crud_loader.mjs +0 -307
  48. package/dist/crud/crud_page.d.mts +0 -32
  49. package/dist/crud/crud_page.d.ts +0 -32
  50. package/dist/crud/crud_page.js +0 -726
  51. package/dist/crud/crud_page.mjs +0 -708
  52. package/dist/crud/generate_handlers.d.mts +0 -16
  53. package/dist/crud/generate_handlers.d.ts +0 -16
  54. package/dist/crud/generate_handlers.js +0 -39
  55. package/dist/crud/generate_handlers.mjs +0 -14
  56. package/dist/crud/generate_pages.d.mts +0 -19
  57. package/dist/crud/generate_pages.d.ts +0 -19
  58. package/dist/crud/generate_pages.js +0 -55
  59. package/dist/crud/generate_pages.mjs +0 -30
  60. package/dist/crud/generate_routes.d.mts +0 -5
  61. package/dist/crud/generate_routes.d.ts +0 -5
  62. package/dist/crud/generate_routes.js +0 -7639
  63. package/dist/crud/generate_routes.mjs +0 -7627
  64. package/dist/table/item_loader.d.mts +0 -14
  65. package/dist/table/item_loader.d.ts +0 -14
  66. package/dist/table/item_loader.js +0 -43
  67. package/dist/table/item_loader.mjs +0 -18
  68. package/dist/table/page.d.mts +0 -16
  69. package/dist/table/page.d.ts +0 -16
  70. package/dist/table/page.js +0 -325
  71. package/dist/table/page.mjs +0 -300
@@ -40,7 +40,8 @@ function Table({
40
40
  limit,
41
41
  offset,
42
42
  orderBy,
43
- direction
43
+ direction,
44
+ filters
44
45
  }) {
45
46
  const keys = Object.entries(columns).filter((entry) => entry[1]).map(([key]) => key);
46
47
  const sortedArray = [...data];
@@ -65,8 +66,8 @@ function Table({
65
66
  "button",
66
67
  {
67
68
  className: (0, import_utils.cn)(
68
- orderBy === key ? "text-neutral-900 font-medium" : "text-neutral-500",
69
- "px-4 h-14 flex items-center w-full"
69
+ orderBy === key ? "text-gray-900 font-medium" : "text-gray-500 font-medium",
70
+ "px-4 flex items-center w-full"
70
71
  ),
71
72
  onClick: () => {
72
73
  let newDirection = "asc";
@@ -87,14 +88,45 @@ function Table({
87
88
  }
88
89
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: reactNode });
89
90
  }
90
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { className: (0, import_utils.cn)("border-y font-normal"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Head, {}) }, key);
91
+ const filter = filters?.[key];
92
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
93
+ "th",
94
+ {
95
+ className: (0, import_utils.cn)("py-4 border-y font-normal align-top"),
96
+ children: [
97
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Head, {}),
98
+ filter && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-3 mt-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
99
+ "select",
100
+ {
101
+ className: "w-full h-10 px-1.5 border rounded-full outline-none",
102
+ onChange: (e) => {
103
+ const value2 = e.target.value;
104
+ setSearchParams((prev) => {
105
+ if (value2) {
106
+ prev.set(key, encodeURIComponent(value2));
107
+ } else {
108
+ prev.delete(key);
109
+ }
110
+ return prev;
111
+ });
112
+ },
113
+ children: [
114
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: "\uC804\uCCB4" }),
115
+ filter.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: option, children: option }, option))
116
+ ]
117
+ }
118
+ ) })
119
+ ]
120
+ },
121
+ key
122
+ );
91
123
  }) }) }),
92
124
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tbody", { children: [
93
125
  sortedArray.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
94
126
  "td",
95
127
  {
96
128
  colSpan: keys.length,
97
- className: "px-4 h-14 text-neutral-400 text-center",
129
+ className: "px-4 h-20 text-gray-400 text-center",
98
130
  children: "\uB370\uC774\uD130\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."
99
131
  }
100
132
  ) }),
@@ -119,7 +151,7 @@ function Table({
119
151
  className: "block content-center px-4 w-full h-full",
120
152
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Content, {})
121
153
  }
122
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Content, {});
154
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-4 w-full h-full content-center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Content, {}) });
123
155
  const cell = Mapper ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Mapper, { item, index: i2, children: linkedContent }) : linkedContent;
124
156
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { className: "px-0 h-14 border-b", children: cell }, key);
125
157
  }) }, i))
@@ -133,16 +165,7 @@ function Table({
133
165
  var import_react_router2 = require("react-router");
134
166
  function useTable() {
135
167
  const { table } = (0, import_react_router2.useLoaderData)();
136
- const { items, total, limit, offset, orderBy, direction, searchKey } = table;
137
- return {
138
- items,
139
- total,
140
- limit,
141
- offset,
142
- orderBy,
143
- direction,
144
- searchKey
145
- };
168
+ return table;
146
169
  }
147
170
 
148
171
  // src/table/buttons.tsx
@@ -225,7 +248,16 @@ function TableForm({
225
248
  primaryKey = "id"
226
249
  }) {
227
250
  const { pathname } = (0, import_react_router4.useLocation)();
228
- const { items, total, limit, offset, orderBy, direction, searchKey } = useTable();
251
+ const {
252
+ items,
253
+ total,
254
+ limit,
255
+ offset,
256
+ orderBy,
257
+ direction,
258
+ searchKey,
259
+ filters
260
+ } = useTable();
229
261
  const navigate = (0, import_react_router4.useNavigate)();
230
262
  const search = (query) => {
231
263
  const searchParams2 = new URLSearchParams(window.location.search);
@@ -238,7 +270,7 @@ function TableForm({
238
270
  searchKey && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
239
271
  "form",
240
272
  {
241
- className: "h-18 px-4 flex items-center border-t",
273
+ className: "h-20 px-4 flex items-center border-t",
242
274
  onSubmit: (e) => {
243
275
  e.preventDefault();
244
276
  const formData = new FormData(e.currentTarget);
@@ -275,7 +307,8 @@ function TableForm({
275
307
  limit,
276
308
  offset,
277
309
  orderBy,
278
- direction
310
+ direction,
311
+ filters
279
312
  }
280
313
  ),
281
314
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
@@ -16,7 +16,8 @@ function Table({
16
16
  limit,
17
17
  offset,
18
18
  orderBy,
19
- direction
19
+ direction,
20
+ filters
20
21
  }) {
21
22
  const keys = Object.entries(columns).filter((entry) => entry[1]).map(([key]) => key);
22
23
  const sortedArray = [...data];
@@ -41,8 +42,8 @@ function Table({
41
42
  "button",
42
43
  {
43
44
  className: cn(
44
- orderBy === key ? "text-neutral-900 font-medium" : "text-neutral-500",
45
- "px-4 h-14 flex items-center w-full"
45
+ orderBy === key ? "text-gray-900 font-medium" : "text-gray-500 font-medium",
46
+ "px-4 flex items-center w-full"
46
47
  ),
47
48
  onClick: () => {
48
49
  let newDirection = "asc";
@@ -63,14 +64,45 @@ function Table({
63
64
  }
64
65
  return /* @__PURE__ */ jsx(Fragment, { children: reactNode });
65
66
  }
66
- return /* @__PURE__ */ jsx("th", { className: cn("border-y font-normal"), children: /* @__PURE__ */ jsx(Head, {}) }, key);
67
+ const filter = filters?.[key];
68
+ return /* @__PURE__ */ jsxs(
69
+ "th",
70
+ {
71
+ className: cn("py-4 border-y font-normal align-top"),
72
+ children: [
73
+ /* @__PURE__ */ jsx(Head, {}),
74
+ filter && /* @__PURE__ */ jsx("div", { className: "px-3 mt-4", children: /* @__PURE__ */ jsxs(
75
+ "select",
76
+ {
77
+ className: "w-full h-10 px-1.5 border rounded-full outline-none",
78
+ onChange: (e) => {
79
+ const value2 = e.target.value;
80
+ setSearchParams((prev) => {
81
+ if (value2) {
82
+ prev.set(key, encodeURIComponent(value2));
83
+ } else {
84
+ prev.delete(key);
85
+ }
86
+ return prev;
87
+ });
88
+ },
89
+ children: [
90
+ /* @__PURE__ */ jsx("option", { value: "", children: "\uC804\uCCB4" }),
91
+ filter.map((option) => /* @__PURE__ */ jsx("option", { value: option, children: option }, option))
92
+ ]
93
+ }
94
+ ) })
95
+ ]
96
+ },
97
+ key
98
+ );
67
99
  }) }) }),
68
100
  /* @__PURE__ */ jsxs("tbody", { children: [
69
101
  sortedArray.length === 0 && /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx(
70
102
  "td",
71
103
  {
72
104
  colSpan: keys.length,
73
- className: "px-4 h-14 text-neutral-400 text-center",
105
+ className: "px-4 h-20 text-gray-400 text-center",
74
106
  children: "\uB370\uC774\uD130\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."
75
107
  }
76
108
  ) }),
@@ -95,7 +127,7 @@ function Table({
95
127
  className: "block content-center px-4 w-full h-full",
96
128
  children: /* @__PURE__ */ jsx(Content, {})
97
129
  }
98
- ) : /* @__PURE__ */ jsx(Content, {});
130
+ ) : /* @__PURE__ */ jsx("div", { className: "px-4 w-full h-full content-center", children: /* @__PURE__ */ jsx(Content, {}) });
99
131
  const cell = Mapper ? /* @__PURE__ */ jsx(Mapper, { item, index: i2, children: linkedContent }) : linkedContent;
100
132
  return /* @__PURE__ */ jsx("td", { className: "px-0 h-14 border-b", children: cell }, key);
101
133
  }) }, i))
@@ -109,16 +141,7 @@ function Table({
109
141
  import { useLoaderData } from "react-router";
110
142
  function useTable() {
111
143
  const { table } = useLoaderData();
112
- const { items, total, limit, offset, orderBy, direction, searchKey } = table;
113
- return {
114
- items,
115
- total,
116
- limit,
117
- offset,
118
- orderBy,
119
- direction,
120
- searchKey
121
- };
144
+ return table;
122
145
  }
123
146
 
124
147
  // src/table/buttons.tsx
@@ -201,7 +224,16 @@ function TableForm({
201
224
  primaryKey = "id"
202
225
  }) {
203
226
  const { pathname } = useLocation2();
204
- const { items, total, limit, offset, orderBy, direction, searchKey } = useTable();
227
+ const {
228
+ items,
229
+ total,
230
+ limit,
231
+ offset,
232
+ orderBy,
233
+ direction,
234
+ searchKey,
235
+ filters
236
+ } = useTable();
205
237
  const navigate = useNavigate();
206
238
  const search = (query) => {
207
239
  const searchParams2 = new URLSearchParams(window.location.search);
@@ -214,7 +246,7 @@ function TableForm({
214
246
  searchKey && /* @__PURE__ */ jsxs3(
215
247
  "form",
216
248
  {
217
- className: "h-18 px-4 flex items-center border-t",
249
+ className: "h-20 px-4 flex items-center border-t",
218
250
  onSubmit: (e) => {
219
251
  e.preventDefault();
220
252
  const formData = new FormData(e.currentTarget);
@@ -251,7 +283,8 @@ function TableForm({
251
283
  limit,
252
284
  offset,
253
285
  orderBy,
254
- direction
286
+ direction,
287
+ filters
255
288
  }
256
289
  ),
257
290
  /* @__PURE__ */ jsx3(
@@ -1,4 +1,4 @@
1
- type LoadedTable<T extends (...args: any) => any> = Awaited<ReturnType<T>>["table"];
2
- declare function useTable<T extends (...args: any) => any>(): LoadedTable<T>;
1
+ type TableLoaderData<T extends (...args: any) => any> = Awaited<ReturnType<T>>["table"];
2
+ declare function useTable<T extends (...args: any) => any>(): TableLoaderData<T>;
3
3
 
4
- export { type LoadedTable, useTable };
4
+ export { type TableLoaderData, useTable };
@@ -1,4 +1,4 @@
1
- type LoadedTable<T extends (...args: any) => any> = Awaited<ReturnType<T>>["table"];
2
- declare function useTable<T extends (...args: any) => any>(): LoadedTable<T>;
1
+ type TableLoaderData<T extends (...args: any) => any> = Awaited<ReturnType<T>>["table"];
2
+ declare function useTable<T extends (...args: any) => any>(): TableLoaderData<T>;
3
3
 
4
- export { type LoadedTable, useTable };
4
+ export { type TableLoaderData, useTable };
@@ -26,16 +26,7 @@ module.exports = __toCommonJS(use_table_exports);
26
26
  var import_react_router = require("react-router");
27
27
  function useTable() {
28
28
  const { table } = (0, import_react_router.useLoaderData)();
29
- const { items, total, limit, offset, orderBy, direction, searchKey } = table;
30
- return {
31
- items,
32
- total,
33
- limit,
34
- offset,
35
- orderBy,
36
- direction,
37
- searchKey
38
- };
29
+ return table;
39
30
  }
40
31
  // Annotate the CommonJS export names for ESM import in node:
41
32
  0 && (module.exports = {
@@ -2,16 +2,7 @@
2
2
  import { useLoaderData } from "react-router";
3
3
  function useTable() {
4
4
  const { table } = useLoaderData();
5
- const { items, total, limit, offset, orderBy, direction, searchKey } = table;
6
- return {
7
- items,
8
- total,
9
- limit,
10
- offset,
11
- orderBy,
12
- direction,
13
- searchKey
14
- };
5
+ return table;
15
6
  }
16
7
  export {
17
8
  useTable
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dn-react-router-toolkit",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "types": "./dist/index.d.ts",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.js",
@@ -1,26 +0,0 @@
1
- import { LoaderFunctionArgs, LoaderFunction } from 'react-router';
2
- import { TableItemLoaderOptions } from '../table/item_loader.mjs';
3
- import { TableRepository } from '../table/repository.mjs';
4
- import { TableLoaderOptions } from '../table/load_table.mjs';
5
- import { PgTableWithColumns } from 'drizzle-orm/pg-core';
6
- import { APIHandlerOptions } from '../api/create_api_handler.mjs';
7
- import 'drizzle-orm';
8
- import 'drizzle-orm/node-postgres';
9
- import '../auth/with_auth.mjs';
10
- import 'dn-react-toolkit/auth';
11
- import 'dn-react-toolkit/auth/server';
12
-
13
- type CrudHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
14
- repository: TableRepository<T, TSelect>;
15
- apiHandlerOptions: Omit<APIHandlerOptions<T, TSelect>, "repository">;
16
- loaderOptions: Omit<TableLoaderOptions<T, TSelect>, "repository"> & {
17
- loader?: LoaderFunction;
18
- };
19
- itemLoaderOptions: Omit<TableItemLoaderOptions<T, TSelect>, "repository"> & {
20
- loader?: LoaderFunction;
21
- };
22
- };
23
- type CrudHandler = (prefix: string) => (args: LoaderFunctionArgs) => Promise<any>;
24
- declare function crudHandler<T extends PgTableWithColumns<any>, TSelect>({ repository, apiHandlerOptions, loaderOptions, itemLoaderOptions, }: CrudHandlerOptions<T, TSelect>): (prefix: string) => (args: LoaderFunctionArgs) => Promise<unknown>;
25
-
26
- export { type CrudHandler, type CrudHandlerOptions, crudHandler };
@@ -1,26 +0,0 @@
1
- import { LoaderFunctionArgs, LoaderFunction } from 'react-router';
2
- import { TableItemLoaderOptions } from '../table/item_loader.js';
3
- import { TableRepository } from '../table/repository.js';
4
- import { TableLoaderOptions } from '../table/load_table.js';
5
- import { PgTableWithColumns } from 'drizzle-orm/pg-core';
6
- import { APIHandlerOptions } from '../api/create_api_handler.js';
7
- import 'drizzle-orm';
8
- import 'drizzle-orm/node-postgres';
9
- import '../auth/with_auth.js';
10
- import 'dn-react-toolkit/auth';
11
- import 'dn-react-toolkit/auth/server';
12
-
13
- type CrudHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
14
- repository: TableRepository<T, TSelect>;
15
- apiHandlerOptions: Omit<APIHandlerOptions<T, TSelect>, "repository">;
16
- loaderOptions: Omit<TableLoaderOptions<T, TSelect>, "repository"> & {
17
- loader?: LoaderFunction;
18
- };
19
- itemLoaderOptions: Omit<TableItemLoaderOptions<T, TSelect>, "repository"> & {
20
- loader?: LoaderFunction;
21
- };
22
- };
23
- type CrudHandler = (prefix: string) => (args: LoaderFunctionArgs) => Promise<any>;
24
- declare function crudHandler<T extends PgTableWithColumns<any>, TSelect>({ repository, apiHandlerOptions, loaderOptions, itemLoaderOptions, }: CrudHandlerOptions<T, TSelect>): (prefix: string) => (args: LoaderFunctionArgs) => Promise<unknown>;
25
-
26
- export { type CrudHandler, type CrudHandlerOptions, crudHandler };