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