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
@@ -1,300 +0,0 @@
1
- // src/table/page.tsx
2
- import { Link as Link3, useLocation as useLocation3 } from "react-router";
3
-
4
- // src/table/table_form.tsx
5
- import { useLocation as useLocation2, useNavigate, useSearchParams as useSearchParams3 } from "react-router";
6
- import { GoSearch } from "react-icons/go";
7
-
8
- // src/table/table.tsx
9
- import { cn } from "dn-react-toolkit/utils";
10
- import { GoArrowDown, GoArrowUp } from "react-icons/go";
11
- import { Link, useSearchParams } from "react-router";
12
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
13
- function Table({
14
- className = "min-w-full whitespace-nowrap",
15
- data,
16
- columns,
17
- mapper: Mapper,
18
- getLink,
19
- limit,
20
- offset,
21
- orderBy,
22
- direction
23
- }) {
24
- const keys = Object.entries(columns).filter((entry) => entry[1]).map(([key]) => key);
25
- const sortedArray = [...data];
26
- const [_, setSearchParams] = useSearchParams();
27
- return /* @__PURE__ */ jsxs(
28
- "table",
29
- {
30
- className: cn(className, "text-[15px] border-separate border-spacing-0"),
31
- children: [
32
- /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: keys.map((key) => {
33
- const value = columns[key];
34
- function getReactNode() {
35
- if (value && typeof value === "object" && "label" in value) {
36
- return value.label;
37
- }
38
- return value;
39
- }
40
- function Head() {
41
- const reactNode = getReactNode();
42
- if (typeof reactNode === "string") {
43
- return /* @__PURE__ */ jsxs(
44
- "button",
45
- {
46
- className: cn(
47
- orderBy === key ? "text-neutral-900 font-medium" : "text-neutral-500",
48
- "px-4 h-14 flex items-center w-full"
49
- ),
50
- onClick: () => {
51
- let newDirection = "asc";
52
- if (orderBy === key) {
53
- newDirection = direction === "asc" ? "desc" : "asc";
54
- }
55
- setSearchParams({
56
- orderBy: key,
57
- direction: newDirection
58
- });
59
- },
60
- children: [
61
- reactNode,
62
- orderBy === key && /* @__PURE__ */ jsx("div", { className: "ml-0.5", children: direction === "asc" ? /* @__PURE__ */ jsx(GoArrowUp, {}) : /* @__PURE__ */ jsx(GoArrowDown, {}) })
63
- ]
64
- }
65
- );
66
- }
67
- return /* @__PURE__ */ jsx(Fragment, { children: reactNode });
68
- }
69
- return /* @__PURE__ */ jsx("th", { className: cn("border-y font-normal"), children: /* @__PURE__ */ jsx(Head, {}) }, key);
70
- }) }) }),
71
- /* @__PURE__ */ jsxs("tbody", { children: [
72
- sortedArray.length === 0 && /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx(
73
- "td",
74
- {
75
- colSpan: keys.length,
76
- className: "px-4 h-14 text-neutral-400 text-center",
77
- children: "\uB370\uC774\uD130\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."
78
- }
79
- ) }),
80
- sortedArray.map((item, i) => /* @__PURE__ */ jsx("tr", { className: "hover:bg-gray-50 transition-colors", children: keys.map((key, i2) => {
81
- const value = item[key];
82
- function Content() {
83
- if (key in columns) {
84
- const column = columns[key];
85
- if (column && typeof column === "object" && "mapper" in column) {
86
- const mapper = column.mapper;
87
- if (mapper) {
88
- return /* @__PURE__ */ jsx(Fragment, { children: mapper(item) });
89
- }
90
- }
91
- }
92
- return /* @__PURE__ */ jsx(Fragment, { children: String(value) });
93
- }
94
- const linkedContent = getLink ? /* @__PURE__ */ jsx(
95
- Link,
96
- {
97
- to: getLink(item),
98
- className: "block content-center px-4 w-full h-full",
99
- children: /* @__PURE__ */ jsx(Content, {})
100
- }
101
- ) : /* @__PURE__ */ jsx(Content, {});
102
- const cell = Mapper ? /* @__PURE__ */ jsx(Mapper, { item, index: i2, children: linkedContent }) : linkedContent;
103
- return /* @__PURE__ */ jsx("td", { className: "px-0 h-14 border-b", children: cell }, key);
104
- }) }, i))
105
- ] })
106
- ]
107
- }
108
- );
109
- }
110
-
111
- // src/table/use_table.tsx
112
- import { useLoaderData } from "react-router";
113
- function useTable() {
114
- const { table } = useLoaderData();
115
- const { items, total, limit, offset, orderBy, direction, searchKey } = table;
116
- return {
117
- items,
118
- total,
119
- limit,
120
- offset,
121
- orderBy,
122
- direction,
123
- searchKey
124
- };
125
- }
126
-
127
- // src/table/buttons.tsx
128
- import { cn as cn2 } from "dn-react-toolkit/utils";
129
- import { Link as Link2, useLocation, useSearchParams as useSearchParams2 } from "react-router";
130
- import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
131
- function TablePageButtons({
132
- MAX_PAGES_TO_SHOW,
133
- total,
134
- limit,
135
- offset
136
- }) {
137
- const pages = Math.ceil(total / limit);
138
- const { pathname } = useLocation();
139
- const [searchParams] = useSearchParams2();
140
- const currentPage = Math.floor(offset / limit) + 1;
141
- const startButton = (Math.ceil(currentPage / MAX_PAGES_TO_SHOW) - 1) * MAX_PAGES_TO_SHOW;
142
- const endButton = Math.min(startButton + MAX_PAGES_TO_SHOW - 1, pages);
143
- return /* @__PURE__ */ jsx2(Fragment2, { children: pages > 1 && /* @__PURE__ */ jsxs2("div", { className: "flex justify-center items-center my-8 gap-4 text-neutral-400", children: [
144
- startButton > 1 && /* @__PURE__ */ jsx2(
145
- Link2,
146
- {
147
- to: (() => {
148
- searchParams.set(
149
- "offset",
150
- String((startButton - 1) * limit)
151
- );
152
- return `${pathname}?${searchParams.toString()}`;
153
- })(),
154
- className: "w-10 block text-center transition-colors hover:text-primary",
155
- children: "\uC774\uC804"
156
- }
157
- ),
158
- Array.from({
159
- length: Math.min(
160
- MAX_PAGES_TO_SHOW,
161
- pages - startButton
162
- )
163
- }).map((_, index) => {
164
- return /* @__PURE__ */ jsx2(
165
- Link2,
166
- {
167
- to: (() => {
168
- searchParams.set(
169
- "offset",
170
- String((startButton + index) * limit)
171
- );
172
- return `${pathname}?${searchParams.toString()}`;
173
- })(),
174
- className: cn2(
175
- "w-6 block text-center transition-colors",
176
- currentPage === startButton + index + 1 ? "font-bold text-primary" : "hover:text-primary"
177
- ),
178
- children: startButton + index + 1
179
- },
180
- index
181
- );
182
- }),
183
- endButton < pages && /* @__PURE__ */ jsx2(
184
- Link2,
185
- {
186
- to: (() => {
187
- searchParams.set(
188
- "offset",
189
- String((endButton + 1) * limit)
190
- );
191
- return `${pathname}?${searchParams.toString()}`;
192
- })(),
193
- className: "w-10 block text-center transition-colors hover:text-primary",
194
- children: "\uB2E4\uC74C"
195
- }
196
- )
197
- ] }) });
198
- }
199
-
200
- // src/table/table_form.tsx
201
- import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
202
- function TableForm({
203
- columns,
204
- primaryKey = "id"
205
- }) {
206
- const { pathname } = useLocation2();
207
- const { items, total, limit, offset, orderBy, direction, searchKey } = useTable();
208
- const navigate = useNavigate();
209
- const search = (query) => {
210
- const searchParams2 = new URLSearchParams(window.location.search);
211
- searchParams2.set("query", query);
212
- searchParams2.set("offset", "0");
213
- navigate(`${pathname}?${searchParams2.toString()}`);
214
- };
215
- const [searchParams] = useSearchParams3();
216
- return /* @__PURE__ */ jsxs3(Fragment3, { children: [
217
- searchKey && /* @__PURE__ */ jsxs3(
218
- "form",
219
- {
220
- className: "h-18 px-4 flex items-center border-t",
221
- onSubmit: (e) => {
222
- e.preventDefault();
223
- const formData = new FormData(e.currentTarget);
224
- const query = formData.get("query");
225
- search(query);
226
- },
227
- children: [
228
- /* @__PURE__ */ jsx3(
229
- "button",
230
- {
231
- type: "submit",
232
- className: "w-10 h-10 flex justify-center items-center",
233
- children: /* @__PURE__ */ jsx3(GoSearch, { className: "text-xl mr-4" })
234
- }
235
- ),
236
- /* @__PURE__ */ jsx3(
237
- "input",
238
- {
239
- className: "outline-none h-full flex-1",
240
- placeholder: "\uC5EC\uAE30\uC5D0 \uAC80\uC0C9\uD558\uC138\uC694...",
241
- name: "query",
242
- defaultValue: searchParams.get("query") ?? ""
243
- }
244
- )
245
- ]
246
- }
247
- ),
248
- /* @__PURE__ */ jsx3(
249
- Table,
250
- {
251
- data: items,
252
- columns,
253
- getLink: primaryKey ? (item) => `${pathname}/${item[primaryKey]}` : void 0,
254
- limit,
255
- offset,
256
- orderBy,
257
- direction
258
- }
259
- ),
260
- /* @__PURE__ */ jsx3(
261
- TablePageButtons,
262
- {
263
- total,
264
- limit,
265
- offset,
266
- MAX_PAGES_TO_SHOW: 10
267
- }
268
- )
269
- ] });
270
- }
271
-
272
- // src/table/page.tsx
273
- import { Fragment as Fragment4, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
274
- function createTablePage({
275
- name,
276
- columns,
277
- primaryKey = "id"
278
- }) {
279
- return function TablePage({
280
- header: Header
281
- }) {
282
- const { pathname } = useLocation3();
283
- return /* @__PURE__ */ jsxs4(Fragment4, { children: [
284
- /* @__PURE__ */ jsx4(
285
- Header,
286
- {
287
- title: name,
288
- actions: /* @__PURE__ */ jsxs4(Link3, { to: `${pathname}/new`, className: "button-primary", children: [
289
- name,
290
- " \uCD94\uAC00"
291
- ] })
292
- }
293
- ),
294
- /* @__PURE__ */ jsx4("div", { className: "max-w-7xl mx-auto w-full overflow-auto", children: /* @__PURE__ */ jsx4(TableForm, { columns, primaryKey }) })
295
- ] });
296
- };
297
- }
298
- export {
299
- createTablePage
300
- };