dn-react-router-toolkit 0.8.1 → 0.9.1

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 (130) hide show
  1. package/dist/api/create_api_handler.d.mts +2 -2
  2. package/dist/api/create_api_handler.d.ts +2 -2
  3. package/dist/api/create_api_handler.js +55 -52
  4. package/dist/api/create_api_handler.mjs +61 -59
  5. package/dist/api/create_handler.d.mts +5 -5
  6. package/dist/api/create_handler.d.ts +5 -5
  7. package/dist/api/create_handler.js +41 -44
  8. package/dist/api/create_handler.mjs +41 -44
  9. package/dist/api/index.d.mts +4 -3
  10. package/dist/api/index.d.ts +4 -3
  11. package/dist/api/index.js +118 -102
  12. package/dist/api/index.mjs +130 -109
  13. package/dist/api/item_api_handler.d.mts +4 -3
  14. package/dist/api/item_api_handler.d.ts +4 -3
  15. package/dist/api/item_api_handler.js +22 -6
  16. package/dist/api/item_api_handler.mjs +28 -6
  17. package/dist/auth/cookie_manager.d.mts +1 -1
  18. package/dist/auth/cookie_manager.d.ts +1 -1
  19. package/dist/auth/index.d.mts +2 -2
  20. package/dist/auth/index.d.ts +2 -2
  21. package/dist/auth/index.js +18 -18
  22. package/dist/auth/index.mjs +18 -18
  23. package/dist/auth/with_auth.d.mts +2 -2
  24. package/dist/auth/with_auth.d.ts +2 -2
  25. package/dist/auth/with_auth.js +18 -18
  26. package/dist/auth/with_auth.mjs +18 -18
  27. package/dist/client/editor.d.mts +2 -2
  28. package/dist/client/editor.d.ts +2 -2
  29. package/dist/client/editor.js +9 -3
  30. package/dist/client/editor.mjs +9 -3
  31. package/dist/client/index.d.mts +2 -2
  32. package/dist/client/index.d.ts +2 -2
  33. package/dist/client/index.js +9 -3
  34. package/dist/client/index.mjs +9 -3
  35. package/dist/crud/crud_form.js +22 -4
  36. package/dist/crud/crud_form.mjs +11 -3
  37. package/dist/crud/crud_form_provider.js +16 -3
  38. package/dist/crud/crud_form_provider.mjs +14 -1
  39. package/dist/crud/index.d.mts +0 -20
  40. package/dist/crud/index.d.ts +0 -20
  41. package/dist/crud/index.js +32 -8589
  42. package/dist/crud/index.mjs +11 -8599
  43. package/dist/db/backup/index.d.mts +1 -1
  44. package/dist/db/backup/index.d.ts +1 -1
  45. package/dist/form/create_form_component.js +21 -2
  46. package/dist/form/create_form_component.mjs +10 -1
  47. package/dist/form/form_components.js +21 -2
  48. package/dist/form/form_components.mjs +10 -1
  49. package/dist/form/index.js +21 -2
  50. package/dist/form/index.mjs +10 -1
  51. package/dist/post/editor_toolbar.js +20 -3
  52. package/dist/post/editor_toolbar.mjs +9 -2
  53. package/dist/post/index.js +93 -7711
  54. package/dist/post/index.mjs +69 -7723
  55. package/dist/post/post_form_page.js +91 -7711
  56. package/dist/post/post_form_page.mjs +69 -7725
  57. package/dist/post/thumbnail_picker.js +21 -2
  58. package/dist/post/thumbnail_picker.mjs +10 -1
  59. package/dist/table/buttons.js +11 -14
  60. package/dist/table/buttons.mjs +10 -13
  61. package/dist/table/index.d.mts +0 -2
  62. package/dist/table/index.d.ts +0 -2
  63. package/dist/table/index.js +24 -95
  64. package/dist/table/index.mjs +23 -92
  65. package/dist/table/load_table.d.mts +1 -1
  66. package/dist/table/load_table.d.ts +1 -1
  67. package/dist/table/load_table.js +2 -2
  68. package/dist/table/load_table.mjs +2 -2
  69. package/dist/table/loader.js +2 -2
  70. package/dist/table/loader.mjs +2 -2
  71. package/dist/table/table.d.mts +2 -2
  72. package/dist/table/table.d.ts +2 -2
  73. package/dist/table/table.js +14 -25
  74. package/dist/table/table.mjs +11 -24
  75. package/dist/table/table_form.js +16 -39
  76. package/dist/table/table_form.mjs +15 -38
  77. package/dist/utils/cn.d.mts +3 -0
  78. package/dist/utils/cn.d.ts +3 -0
  79. package/dist/utils/cn.js +32 -0
  80. package/dist/utils/cn.mjs +7 -0
  81. package/dist/utils/date.d.mts +5 -0
  82. package/dist/utils/date.d.ts +5 -0
  83. package/dist/utils/date.js +65 -0
  84. package/dist/utils/date.mjs +29 -0
  85. package/dist/utils/index.d.mts +7 -0
  86. package/dist/utils/index.d.ts +7 -0
  87. package/dist/utils/index.js +116 -0
  88. package/dist/utils/index.mjs +73 -0
  89. package/dist/utils/korean.d.mts +6 -0
  90. package/dist/utils/korean.d.ts +6 -0
  91. package/dist/{crud/generate_pages.js → utils/korean.js} +16 -30
  92. package/dist/utils/korean.mjs +16 -0
  93. package/dist/utils/singleton.d.mts +3 -0
  94. package/dist/utils/singleton.d.ts +3 -0
  95. package/dist/utils/singleton.js +37 -0
  96. package/dist/utils/singleton.mjs +12 -0
  97. package/dist/utils/sleep.d.mts +3 -0
  98. package/dist/utils/sleep.d.ts +3 -0
  99. package/dist/{table/item_loader.js → utils/sleep.js} +8 -19
  100. package/dist/utils/sleep.mjs +7 -0
  101. package/dist/utils/slug.d.mts +3 -0
  102. package/dist/utils/slug.d.ts +3 -0
  103. package/dist/{crud/generate_handlers.js → utils/slug.js} +8 -15
  104. package/dist/utils/slug.mjs +7 -0
  105. package/package.json +7 -3
  106. package/dist/crud/crud_loader.d.mts +0 -26
  107. package/dist/crud/crud_loader.d.ts +0 -26
  108. package/dist/crud/crud_loader.js +0 -351
  109. package/dist/crud/crud_loader.mjs +0 -337
  110. package/dist/crud/crud_page.d.mts +0 -32
  111. package/dist/crud/crud_page.d.ts +0 -32
  112. package/dist/crud/crud_page.js +0 -776
  113. package/dist/crud/crud_page.mjs +0 -758
  114. package/dist/crud/generate_handlers.d.mts +0 -16
  115. package/dist/crud/generate_handlers.d.ts +0 -16
  116. package/dist/crud/generate_handlers.mjs +0 -14
  117. package/dist/crud/generate_pages.d.mts +0 -19
  118. package/dist/crud/generate_pages.d.ts +0 -19
  119. package/dist/crud/generate_pages.mjs +0 -30
  120. package/dist/crud/generate_routes.d.mts +0 -5
  121. package/dist/crud/generate_routes.d.ts +0 -5
  122. package/dist/crud/generate_routes.js +0 -7639
  123. package/dist/crud/generate_routes.mjs +0 -7627
  124. package/dist/table/item_loader.d.mts +0 -14
  125. package/dist/table/item_loader.d.ts +0 -14
  126. package/dist/table/item_loader.mjs +0 -18
  127. package/dist/table/page.d.mts +0 -16
  128. package/dist/table/page.d.ts +0 -16
  129. package/dist/table/page.js +0 -375
  130. 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
- };