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