dn-react-router-toolkit 0.7.14 → 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/auth/cookie_manager.d.mts +2 -1
- package/dist/auth/cookie_manager.d.ts +2 -1
- package/dist/auth/cookie_manager.js +9 -3
- package/dist/auth/cookie_manager.mjs +9 -3
- package/dist/auth/index.js +9 -3
- package/dist/auth/index.mjs +9 -3
- package/dist/crud/crud_form.js +1 -1
- package/dist/crud/crud_form.mjs +1 -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 +226 -198
- package/dist/crud/crud_page.mjs +224 -202
- 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 +246 -206
- package/dist/crud/index.mjs +252 -218
- 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 +3 -3
package/dist/table/index.js
CHANGED
|
@@ -22,10 +22,13 @@ var table_exports = {};
|
|
|
22
22
|
__export(table_exports, {
|
|
23
23
|
BaseTableRepository: () => BaseTableRepository,
|
|
24
24
|
Table: () => Table,
|
|
25
|
+
TableForm: () => TableForm,
|
|
25
26
|
TablePageButtons: () => TablePageButtons,
|
|
26
27
|
createTablePage: () => createTablePage,
|
|
28
|
+
loadTable: () => loadTable,
|
|
27
29
|
tableItemloader: () => tableItemloader,
|
|
28
|
-
tableLoader: () => tableLoader
|
|
30
|
+
tableLoader: () => tableLoader,
|
|
31
|
+
useTable: () => useTable
|
|
29
32
|
});
|
|
30
33
|
module.exports = __toCommonJS(table_exports);
|
|
31
34
|
|
|
@@ -37,7 +40,7 @@ var BaseTableRepository = class {
|
|
|
37
40
|
pk;
|
|
38
41
|
constructor(db, schema, pk = "id") {
|
|
39
42
|
this.db = db;
|
|
40
|
-
this.schema = schema;
|
|
43
|
+
this.schema = db._.fullSchema[schema];
|
|
41
44
|
this.pk = pk;
|
|
42
45
|
}
|
|
43
46
|
async find(id) {
|
|
@@ -167,51 +170,68 @@ var tableItemloader = ({
|
|
|
167
170
|
};
|
|
168
171
|
};
|
|
169
172
|
|
|
170
|
-
// src/table/
|
|
173
|
+
// src/table/load_table.tsx
|
|
171
174
|
var import_drizzle_orm2 = require("drizzle-orm");
|
|
175
|
+
async function loadTable({
|
|
176
|
+
request,
|
|
177
|
+
repository,
|
|
178
|
+
options
|
|
179
|
+
}) {
|
|
180
|
+
const searchParams = new URL(request.url).searchParams;
|
|
181
|
+
const { where, searchKey, defaultOrderBy, defaultDirection } = options;
|
|
182
|
+
const query = searchParams.get("query") ?? void 0;
|
|
183
|
+
const limit = Number(searchParams.get("limit") ?? "20");
|
|
184
|
+
const offset = Number(searchParams.get("offset") ?? "0");
|
|
185
|
+
const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
|
|
186
|
+
const direction = searchParams.get("direction") ?? defaultDirection;
|
|
187
|
+
const whereClauses = (0, import_drizzle_orm2.and)(
|
|
188
|
+
searchKey && query ? (0, import_drizzle_orm2.ilike)(
|
|
189
|
+
repository.schema[searchKey],
|
|
190
|
+
`%${query}%`
|
|
191
|
+
) : void 0,
|
|
192
|
+
...where ?? []
|
|
193
|
+
);
|
|
194
|
+
const total = await repository.countTotal({ where: whereClauses });
|
|
195
|
+
const items = await repository.findAll({
|
|
196
|
+
orderBy,
|
|
197
|
+
direction,
|
|
198
|
+
limit,
|
|
199
|
+
offset,
|
|
200
|
+
where: whereClauses
|
|
201
|
+
});
|
|
202
|
+
return {
|
|
203
|
+
items,
|
|
204
|
+
total,
|
|
205
|
+
limit,
|
|
206
|
+
offset,
|
|
207
|
+
orderBy,
|
|
208
|
+
direction,
|
|
209
|
+
searchKey
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/table/loader.tsx
|
|
172
214
|
function tableLoader({
|
|
173
215
|
repository,
|
|
174
|
-
|
|
216
|
+
options
|
|
175
217
|
}) {
|
|
176
218
|
return async ({ request }) => {
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const offset = Number(searchParams.get("offset") ?? "0");
|
|
182
|
-
const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
|
|
183
|
-
const direction = searchParams.get("direction") ?? defaultDirection;
|
|
184
|
-
const whereClauses = (0, import_drizzle_orm2.and)(
|
|
185
|
-
searchKey && query ? (0, import_drizzle_orm2.ilike)(
|
|
186
|
-
repository.schema[searchKey],
|
|
187
|
-
`%${query}%`
|
|
188
|
-
) : void 0,
|
|
189
|
-
...where ?? []
|
|
190
|
-
);
|
|
191
|
-
const total = await repository.countTotal({ where: whereClauses });
|
|
192
|
-
const items = await repository.findAll({
|
|
193
|
-
orderBy,
|
|
194
|
-
direction,
|
|
195
|
-
limit,
|
|
196
|
-
offset,
|
|
197
|
-
where: whereClauses
|
|
219
|
+
const table = await loadTable({
|
|
220
|
+
request,
|
|
221
|
+
repository,
|
|
222
|
+
options
|
|
198
223
|
});
|
|
199
224
|
return {
|
|
200
|
-
table
|
|
201
|
-
items,
|
|
202
|
-
total,
|
|
203
|
-
limit,
|
|
204
|
-
offset,
|
|
205
|
-
orderBy,
|
|
206
|
-
direction,
|
|
207
|
-
searchKey
|
|
208
|
-
}
|
|
225
|
+
table
|
|
209
226
|
};
|
|
210
227
|
};
|
|
211
228
|
}
|
|
212
229
|
|
|
213
230
|
// src/table/page.tsx
|
|
214
|
-
var
|
|
231
|
+
var import_react_router5 = require("react-router");
|
|
232
|
+
|
|
233
|
+
// src/table/table_form.tsx
|
|
234
|
+
var import_react_router4 = require("react-router");
|
|
215
235
|
var import_go2 = require("react-icons/go");
|
|
216
236
|
|
|
217
237
|
// src/table/table.tsx
|
|
@@ -317,8 +337,96 @@ function Table({
|
|
|
317
337
|
);
|
|
318
338
|
}
|
|
319
339
|
|
|
320
|
-
// src/table/
|
|
340
|
+
// src/table/use_table.tsx
|
|
341
|
+
var import_react_router3 = require("react-router");
|
|
342
|
+
function useTable() {
|
|
343
|
+
const { table } = (0, import_react_router3.useLoaderData)();
|
|
344
|
+
const { items, total, limit, offset, orderBy, direction, searchKey } = table;
|
|
345
|
+
return {
|
|
346
|
+
items,
|
|
347
|
+
total,
|
|
348
|
+
limit,
|
|
349
|
+
offset,
|
|
350
|
+
orderBy,
|
|
351
|
+
direction,
|
|
352
|
+
searchKey
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// src/table/table_form.tsx
|
|
321
357
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
358
|
+
function TableForm({
|
|
359
|
+
columns,
|
|
360
|
+
primaryKey = "id"
|
|
361
|
+
}) {
|
|
362
|
+
const { pathname } = (0, import_react_router4.useLocation)();
|
|
363
|
+
const { items, total, limit, offset, orderBy, direction, searchKey } = useTable();
|
|
364
|
+
const navigate = (0, import_react_router4.useNavigate)();
|
|
365
|
+
const search = (query) => {
|
|
366
|
+
const searchParams2 = new URLSearchParams(window.location.search);
|
|
367
|
+
searchParams2.set("query", query);
|
|
368
|
+
searchParams2.set("offset", "0");
|
|
369
|
+
navigate(`${pathname}?${searchParams2.toString()}`);
|
|
370
|
+
};
|
|
371
|
+
const [searchParams] = (0, import_react_router4.useSearchParams)();
|
|
372
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
373
|
+
searchKey && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
374
|
+
"form",
|
|
375
|
+
{
|
|
376
|
+
className: "h-18 px-4 flex items-center border-t",
|
|
377
|
+
onSubmit: (e) => {
|
|
378
|
+
e.preventDefault();
|
|
379
|
+
const formData = new FormData(e.currentTarget);
|
|
380
|
+
const query = formData.get("query");
|
|
381
|
+
search(query);
|
|
382
|
+
},
|
|
383
|
+
children: [
|
|
384
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
385
|
+
"button",
|
|
386
|
+
{
|
|
387
|
+
type: "submit",
|
|
388
|
+
className: "w-10 h-10 flex justify-center items-center",
|
|
389
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_go2.GoSearch, { className: "text-xl mr-4" })
|
|
390
|
+
}
|
|
391
|
+
),
|
|
392
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
393
|
+
"input",
|
|
394
|
+
{
|
|
395
|
+
className: "outline-none h-full flex-1",
|
|
396
|
+
placeholder: "\uC5EC\uAE30\uC5D0 \uAC80\uC0C9\uD558\uC138\uC694...",
|
|
397
|
+
name: "query",
|
|
398
|
+
defaultValue: searchParams.get("query") ?? ""
|
|
399
|
+
}
|
|
400
|
+
)
|
|
401
|
+
]
|
|
402
|
+
}
|
|
403
|
+
),
|
|
404
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
405
|
+
Table,
|
|
406
|
+
{
|
|
407
|
+
data: items,
|
|
408
|
+
columns,
|
|
409
|
+
getLink: primaryKey ? (item) => `${pathname}/${item[primaryKey]}` : void 0,
|
|
410
|
+
limit,
|
|
411
|
+
offset,
|
|
412
|
+
orderBy,
|
|
413
|
+
direction
|
|
414
|
+
}
|
|
415
|
+
),
|
|
416
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
417
|
+
TablePageButtons,
|
|
418
|
+
{
|
|
419
|
+
total,
|
|
420
|
+
limit,
|
|
421
|
+
offset,
|
|
422
|
+
MAX_PAGES_TO_SHOW: 10
|
|
423
|
+
}
|
|
424
|
+
)
|
|
425
|
+
] });
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// src/table/page.tsx
|
|
429
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
322
430
|
function createTablePage({
|
|
323
431
|
name,
|
|
324
432
|
columns,
|
|
@@ -327,82 +435,19 @@ function createTablePage({
|
|
|
327
435
|
return function TablePage({
|
|
328
436
|
header: Header
|
|
329
437
|
}) {
|
|
330
|
-
const { pathname } = (0,
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const navigate = (0, import_react_router3.useNavigate)();
|
|
334
|
-
const search = (query) => {
|
|
335
|
-
const searchParams2 = new URLSearchParams(window.location.search);
|
|
336
|
-
searchParams2.set("query", query);
|
|
337
|
-
searchParams2.set("offset", "0");
|
|
338
|
-
navigate(`${pathname}?${searchParams2.toString()}`);
|
|
339
|
-
};
|
|
340
|
-
const [searchParams] = (0, import_react_router3.useSearchParams)();
|
|
341
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
342
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
438
|
+
const { pathname } = (0, import_react_router5.useLocation)();
|
|
439
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
440
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
343
441
|
Header,
|
|
344
442
|
{
|
|
345
443
|
title: name,
|
|
346
|
-
actions: /* @__PURE__ */ (0,
|
|
444
|
+
actions: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_router5.Link, { to: `${pathname}/new`, className: "button-primary", children: [
|
|
347
445
|
name,
|
|
348
446
|
" \uCD94\uAC00"
|
|
349
447
|
] })
|
|
350
448
|
}
|
|
351
449
|
),
|
|
352
|
-
/* @__PURE__ */ (0,
|
|
353
|
-
searchKey && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
354
|
-
"form",
|
|
355
|
-
{
|
|
356
|
-
className: "h-18 px-4 flex items-center border-t",
|
|
357
|
-
onSubmit: (e) => {
|
|
358
|
-
e.preventDefault();
|
|
359
|
-
const formData = new FormData(e.currentTarget);
|
|
360
|
-
const query = formData.get("query");
|
|
361
|
-
search(query);
|
|
362
|
-
},
|
|
363
|
-
children: [
|
|
364
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
365
|
-
"button",
|
|
366
|
-
{
|
|
367
|
-
type: "submit",
|
|
368
|
-
className: "w-10 h-10 flex justify-center items-center",
|
|
369
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_go2.GoSearch, { className: "text-xl mr-4" })
|
|
370
|
-
}
|
|
371
|
-
),
|
|
372
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
373
|
-
"input",
|
|
374
|
-
{
|
|
375
|
-
className: "outline-none h-full flex-1",
|
|
376
|
-
placeholder: "\uC5EC\uAE30\uC5D0 \uAC80\uC0C9\uD558\uC138\uC694...",
|
|
377
|
-
name: "query",
|
|
378
|
-
defaultValue: searchParams.get("query") ?? ""
|
|
379
|
-
}
|
|
380
|
-
)
|
|
381
|
-
]
|
|
382
|
-
}
|
|
383
|
-
),
|
|
384
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
385
|
-
Table,
|
|
386
|
-
{
|
|
387
|
-
data: items,
|
|
388
|
-
columns,
|
|
389
|
-
getLink: primaryKey ? (item) => `${pathname}/${item[primaryKey]}` : void 0,
|
|
390
|
-
limit,
|
|
391
|
-
offset,
|
|
392
|
-
orderBy,
|
|
393
|
-
direction
|
|
394
|
-
}
|
|
395
|
-
),
|
|
396
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
397
|
-
TablePageButtons,
|
|
398
|
-
{
|
|
399
|
-
total,
|
|
400
|
-
limit,
|
|
401
|
-
offset,
|
|
402
|
-
MAX_PAGES_TO_SHOW: 10
|
|
403
|
-
}
|
|
404
|
-
)
|
|
405
|
-
] })
|
|
450
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "max-w-7xl mx-auto w-full overflow-auto", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TableForm, { columns, primaryKey }) })
|
|
406
451
|
] });
|
|
407
452
|
};
|
|
408
453
|
}
|
|
@@ -410,8 +455,11 @@ function createTablePage({
|
|
|
410
455
|
0 && (module.exports = {
|
|
411
456
|
BaseTableRepository,
|
|
412
457
|
Table,
|
|
458
|
+
TableForm,
|
|
413
459
|
TablePageButtons,
|
|
414
460
|
createTablePage,
|
|
461
|
+
loadTable,
|
|
415
462
|
tableItemloader,
|
|
416
|
-
tableLoader
|
|
463
|
+
tableLoader,
|
|
464
|
+
useTable
|
|
417
465
|
});
|
package/dist/table/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ var BaseTableRepository = class {
|
|
|
11
11
|
pk;
|
|
12
12
|
constructor(db, schema, pk = "id") {
|
|
13
13
|
this.db = db;
|
|
14
|
-
this.schema = schema;
|
|
14
|
+
this.schema = db._.fullSchema[schema];
|
|
15
15
|
this.pk = pk;
|
|
16
16
|
}
|
|
17
17
|
async find(id) {
|
|
@@ -141,60 +141,71 @@ var tableItemloader = ({
|
|
|
141
141
|
};
|
|
142
142
|
};
|
|
143
143
|
|
|
144
|
-
// src/table/
|
|
144
|
+
// src/table/load_table.tsx
|
|
145
145
|
import {
|
|
146
146
|
and,
|
|
147
147
|
ilike
|
|
148
148
|
} from "drizzle-orm";
|
|
149
|
+
async function loadTable({
|
|
150
|
+
request,
|
|
151
|
+
repository,
|
|
152
|
+
options
|
|
153
|
+
}) {
|
|
154
|
+
const searchParams = new URL(request.url).searchParams;
|
|
155
|
+
const { where, searchKey, defaultOrderBy, defaultDirection } = options;
|
|
156
|
+
const query = searchParams.get("query") ?? void 0;
|
|
157
|
+
const limit = Number(searchParams.get("limit") ?? "20");
|
|
158
|
+
const offset = Number(searchParams.get("offset") ?? "0");
|
|
159
|
+
const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
|
|
160
|
+
const direction = searchParams.get("direction") ?? defaultDirection;
|
|
161
|
+
const whereClauses = and(
|
|
162
|
+
searchKey && query ? ilike(
|
|
163
|
+
repository.schema[searchKey],
|
|
164
|
+
`%${query}%`
|
|
165
|
+
) : void 0,
|
|
166
|
+
...where ?? []
|
|
167
|
+
);
|
|
168
|
+
const total = await repository.countTotal({ where: whereClauses });
|
|
169
|
+
const items = await repository.findAll({
|
|
170
|
+
orderBy,
|
|
171
|
+
direction,
|
|
172
|
+
limit,
|
|
173
|
+
offset,
|
|
174
|
+
where: whereClauses
|
|
175
|
+
});
|
|
176
|
+
return {
|
|
177
|
+
items,
|
|
178
|
+
total,
|
|
179
|
+
limit,
|
|
180
|
+
offset,
|
|
181
|
+
orderBy,
|
|
182
|
+
direction,
|
|
183
|
+
searchKey
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/table/loader.tsx
|
|
149
188
|
function tableLoader({
|
|
150
189
|
repository,
|
|
151
|
-
|
|
190
|
+
options
|
|
152
191
|
}) {
|
|
153
192
|
return async ({ request }) => {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const offset = Number(searchParams.get("offset") ?? "0");
|
|
159
|
-
const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
|
|
160
|
-
const direction = searchParams.get("direction") ?? defaultDirection;
|
|
161
|
-
const whereClauses = and(
|
|
162
|
-
searchKey && query ? ilike(
|
|
163
|
-
repository.schema[searchKey],
|
|
164
|
-
`%${query}%`
|
|
165
|
-
) : void 0,
|
|
166
|
-
...where ?? []
|
|
167
|
-
);
|
|
168
|
-
const total = await repository.countTotal({ where: whereClauses });
|
|
169
|
-
const items = await repository.findAll({
|
|
170
|
-
orderBy,
|
|
171
|
-
direction,
|
|
172
|
-
limit,
|
|
173
|
-
offset,
|
|
174
|
-
where: whereClauses
|
|
193
|
+
const table = await loadTable({
|
|
194
|
+
request,
|
|
195
|
+
repository,
|
|
196
|
+
options
|
|
175
197
|
});
|
|
176
198
|
return {
|
|
177
|
-
table
|
|
178
|
-
items,
|
|
179
|
-
total,
|
|
180
|
-
limit,
|
|
181
|
-
offset,
|
|
182
|
-
orderBy,
|
|
183
|
-
direction,
|
|
184
|
-
searchKey
|
|
185
|
-
}
|
|
199
|
+
table
|
|
186
200
|
};
|
|
187
201
|
};
|
|
188
202
|
}
|
|
189
203
|
|
|
190
204
|
// src/table/page.tsx
|
|
191
|
-
import {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
useNavigate,
|
|
196
|
-
useSearchParams as useSearchParams3
|
|
197
|
-
} from "react-router";
|
|
205
|
+
import { Link as Link3, useLocation as useLocation3 } from "react-router";
|
|
206
|
+
|
|
207
|
+
// src/table/table_form.tsx
|
|
208
|
+
import { useLocation as useLocation2, useNavigate, useSearchParams as useSearchParams3 } from "react-router";
|
|
198
209
|
import { GoSearch } from "react-icons/go";
|
|
199
210
|
|
|
200
211
|
// src/table/table.tsx
|
|
@@ -300,8 +311,96 @@ function Table({
|
|
|
300
311
|
);
|
|
301
312
|
}
|
|
302
313
|
|
|
303
|
-
// src/table/
|
|
314
|
+
// src/table/use_table.tsx
|
|
315
|
+
import { useLoaderData } from "react-router";
|
|
316
|
+
function useTable() {
|
|
317
|
+
const { table } = useLoaderData();
|
|
318
|
+
const { items, total, limit, offset, orderBy, direction, searchKey } = table;
|
|
319
|
+
return {
|
|
320
|
+
items,
|
|
321
|
+
total,
|
|
322
|
+
limit,
|
|
323
|
+
offset,
|
|
324
|
+
orderBy,
|
|
325
|
+
direction,
|
|
326
|
+
searchKey
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// src/table/table_form.tsx
|
|
304
331
|
import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
332
|
+
function TableForm({
|
|
333
|
+
columns,
|
|
334
|
+
primaryKey = "id"
|
|
335
|
+
}) {
|
|
336
|
+
const { pathname } = useLocation2();
|
|
337
|
+
const { items, total, limit, offset, orderBy, direction, searchKey } = useTable();
|
|
338
|
+
const navigate = useNavigate();
|
|
339
|
+
const search = (query) => {
|
|
340
|
+
const searchParams2 = new URLSearchParams(window.location.search);
|
|
341
|
+
searchParams2.set("query", query);
|
|
342
|
+
searchParams2.set("offset", "0");
|
|
343
|
+
navigate(`${pathname}?${searchParams2.toString()}`);
|
|
344
|
+
};
|
|
345
|
+
const [searchParams] = useSearchParams3();
|
|
346
|
+
return /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
347
|
+
searchKey && /* @__PURE__ */ jsxs3(
|
|
348
|
+
"form",
|
|
349
|
+
{
|
|
350
|
+
className: "h-18 px-4 flex items-center border-t",
|
|
351
|
+
onSubmit: (e) => {
|
|
352
|
+
e.preventDefault();
|
|
353
|
+
const formData = new FormData(e.currentTarget);
|
|
354
|
+
const query = formData.get("query");
|
|
355
|
+
search(query);
|
|
356
|
+
},
|
|
357
|
+
children: [
|
|
358
|
+
/* @__PURE__ */ jsx3(
|
|
359
|
+
"button",
|
|
360
|
+
{
|
|
361
|
+
type: "submit",
|
|
362
|
+
className: "w-10 h-10 flex justify-center items-center",
|
|
363
|
+
children: /* @__PURE__ */ jsx3(GoSearch, { className: "text-xl mr-4" })
|
|
364
|
+
}
|
|
365
|
+
),
|
|
366
|
+
/* @__PURE__ */ jsx3(
|
|
367
|
+
"input",
|
|
368
|
+
{
|
|
369
|
+
className: "outline-none h-full flex-1",
|
|
370
|
+
placeholder: "\uC5EC\uAE30\uC5D0 \uAC80\uC0C9\uD558\uC138\uC694...",
|
|
371
|
+
name: "query",
|
|
372
|
+
defaultValue: searchParams.get("query") ?? ""
|
|
373
|
+
}
|
|
374
|
+
)
|
|
375
|
+
]
|
|
376
|
+
}
|
|
377
|
+
),
|
|
378
|
+
/* @__PURE__ */ jsx3(
|
|
379
|
+
Table,
|
|
380
|
+
{
|
|
381
|
+
data: items,
|
|
382
|
+
columns,
|
|
383
|
+
getLink: primaryKey ? (item) => `${pathname}/${item[primaryKey]}` : void 0,
|
|
384
|
+
limit,
|
|
385
|
+
offset,
|
|
386
|
+
orderBy,
|
|
387
|
+
direction
|
|
388
|
+
}
|
|
389
|
+
),
|
|
390
|
+
/* @__PURE__ */ jsx3(
|
|
391
|
+
TablePageButtons,
|
|
392
|
+
{
|
|
393
|
+
total,
|
|
394
|
+
limit,
|
|
395
|
+
offset,
|
|
396
|
+
MAX_PAGES_TO_SHOW: 10
|
|
397
|
+
}
|
|
398
|
+
)
|
|
399
|
+
] });
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// src/table/page.tsx
|
|
403
|
+
import { Fragment as Fragment4, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
305
404
|
function createTablePage({
|
|
306
405
|
name,
|
|
307
406
|
columns,
|
|
@@ -310,90 +409,30 @@ function createTablePage({
|
|
|
310
409
|
return function TablePage({
|
|
311
410
|
header: Header
|
|
312
411
|
}) {
|
|
313
|
-
const { pathname } =
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const navigate = useNavigate();
|
|
317
|
-
const search = (query) => {
|
|
318
|
-
const searchParams2 = new URLSearchParams(window.location.search);
|
|
319
|
-
searchParams2.set("query", query);
|
|
320
|
-
searchParams2.set("offset", "0");
|
|
321
|
-
navigate(`${pathname}?${searchParams2.toString()}`);
|
|
322
|
-
};
|
|
323
|
-
const [searchParams] = useSearchParams3();
|
|
324
|
-
return /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
325
|
-
/* @__PURE__ */ jsx3(
|
|
412
|
+
const { pathname } = useLocation3();
|
|
413
|
+
return /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
414
|
+
/* @__PURE__ */ jsx4(
|
|
326
415
|
Header,
|
|
327
416
|
{
|
|
328
417
|
title: name,
|
|
329
|
-
actions: /* @__PURE__ */
|
|
418
|
+
actions: /* @__PURE__ */ jsxs4(Link3, { to: `${pathname}/new`, className: "button-primary", children: [
|
|
330
419
|
name,
|
|
331
420
|
" \uCD94\uAC00"
|
|
332
421
|
] })
|
|
333
422
|
}
|
|
334
423
|
),
|
|
335
|
-
/* @__PURE__ */
|
|
336
|
-
searchKey && /* @__PURE__ */ jsxs3(
|
|
337
|
-
"form",
|
|
338
|
-
{
|
|
339
|
-
className: "h-18 px-4 flex items-center border-t",
|
|
340
|
-
onSubmit: (e) => {
|
|
341
|
-
e.preventDefault();
|
|
342
|
-
const formData = new FormData(e.currentTarget);
|
|
343
|
-
const query = formData.get("query");
|
|
344
|
-
search(query);
|
|
345
|
-
},
|
|
346
|
-
children: [
|
|
347
|
-
/* @__PURE__ */ jsx3(
|
|
348
|
-
"button",
|
|
349
|
-
{
|
|
350
|
-
type: "submit",
|
|
351
|
-
className: "w-10 h-10 flex justify-center items-center",
|
|
352
|
-
children: /* @__PURE__ */ jsx3(GoSearch, { className: "text-xl mr-4" })
|
|
353
|
-
}
|
|
354
|
-
),
|
|
355
|
-
/* @__PURE__ */ jsx3(
|
|
356
|
-
"input",
|
|
357
|
-
{
|
|
358
|
-
className: "outline-none h-full flex-1",
|
|
359
|
-
placeholder: "\uC5EC\uAE30\uC5D0 \uAC80\uC0C9\uD558\uC138\uC694...",
|
|
360
|
-
name: "query",
|
|
361
|
-
defaultValue: searchParams.get("query") ?? ""
|
|
362
|
-
}
|
|
363
|
-
)
|
|
364
|
-
]
|
|
365
|
-
}
|
|
366
|
-
),
|
|
367
|
-
/* @__PURE__ */ jsx3(
|
|
368
|
-
Table,
|
|
369
|
-
{
|
|
370
|
-
data: items,
|
|
371
|
-
columns,
|
|
372
|
-
getLink: primaryKey ? (item) => `${pathname}/${item[primaryKey]}` : void 0,
|
|
373
|
-
limit,
|
|
374
|
-
offset,
|
|
375
|
-
orderBy,
|
|
376
|
-
direction
|
|
377
|
-
}
|
|
378
|
-
),
|
|
379
|
-
/* @__PURE__ */ jsx3(
|
|
380
|
-
TablePageButtons,
|
|
381
|
-
{
|
|
382
|
-
total,
|
|
383
|
-
limit,
|
|
384
|
-
offset,
|
|
385
|
-
MAX_PAGES_TO_SHOW: 10
|
|
386
|
-
}
|
|
387
|
-
)
|
|
388
|
-
] })
|
|
424
|
+
/* @__PURE__ */ jsx4("div", { className: "max-w-7xl mx-auto w-full overflow-auto", children: /* @__PURE__ */ jsx4(TableForm, { columns, primaryKey }) })
|
|
389
425
|
] });
|
|
390
426
|
};
|
|
391
427
|
}
|
|
392
428
|
export {
|
|
393
429
|
BaseTableRepository,
|
|
394
430
|
Table,
|
|
431
|
+
TableForm,
|
|
395
432
|
TablePageButtons,
|
|
396
433
|
createTablePage,
|
|
434
|
+
loadTable,
|
|
397
435
|
tableItemloader,
|
|
398
|
-
tableLoader
|
|
436
|
+
tableLoader,
|
|
437
|
+
useTable
|
|
399
438
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Table } from 'drizzle-orm';
|
|
2
1
|
import { TableRepository } from './repository.mjs';
|
|
3
2
|
import { LoaderFunctionArgs } from 'react-router';
|
|
4
|
-
import 'drizzle-orm/pg-core';
|
|
3
|
+
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
4
|
+
import 'drizzle-orm';
|
|
5
|
+
import 'drizzle-orm/node-postgres';
|
|
5
6
|
|
|
6
|
-
type TableItemLoaderOptions<T extends
|
|
7
|
+
type TableItemLoaderOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
7
8
|
repository: TableRepository<T, TSelect>;
|
|
8
9
|
};
|
|
9
|
-
declare const tableItemloader: <T extends
|
|
10
|
+
declare const tableItemloader: <T extends PgTableWithColumns<any>, TSelect>({ repository, }: TableItemLoaderOptions<T, TSelect>) => (args: LoaderFunctionArgs) => Promise<{
|
|
10
11
|
item: Awaited<TSelect> | undefined;
|
|
11
12
|
}>;
|
|
12
13
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Table } from 'drizzle-orm';
|
|
2
1
|
import { TableRepository } from './repository.js';
|
|
3
2
|
import { LoaderFunctionArgs } from 'react-router';
|
|
4
|
-
import 'drizzle-orm/pg-core';
|
|
3
|
+
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
4
|
+
import 'drizzle-orm';
|
|
5
|
+
import 'drizzle-orm/node-postgres';
|
|
5
6
|
|
|
6
|
-
type TableItemLoaderOptions<T extends
|
|
7
|
+
type TableItemLoaderOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
7
8
|
repository: TableRepository<T, TSelect>;
|
|
8
9
|
};
|
|
9
|
-
declare const tableItemloader: <T extends
|
|
10
|
+
declare const tableItemloader: <T extends PgTableWithColumns<any>, TSelect>({ repository, }: TableItemLoaderOptions<T, TSelect>) => (args: LoaderFunctionArgs) => Promise<{
|
|
10
11
|
item: Awaited<TSelect> | undefined;
|
|
11
12
|
}>;
|
|
12
13
|
|