dn-react-router-toolkit 0.4.4 → 0.5.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 (95) hide show
  1. package/dist/api/create_api_handler.d.mts +28 -0
  2. package/dist/api/create_api_handler.d.ts +28 -0
  3. package/dist/api/create_api_handler.js +148 -0
  4. package/dist/api/create_api_handler.mjs +132 -0
  5. package/dist/api/create_handler.js +27 -25
  6. package/dist/api/create_handler.mjs +27 -25
  7. package/dist/api/index.js +27 -25
  8. package/dist/api/index.mjs +27 -25
  9. package/dist/api/item_api_handler.d.mts +18 -0
  10. package/dist/api/item_api_handler.d.ts +18 -0
  11. package/dist/api/item_api_handler.js +55 -0
  12. package/dist/api/item_api_handler.mjs +30 -0
  13. package/dist/auth/index.d.mts +1 -2
  14. package/dist/auth/index.d.ts +1 -2
  15. package/dist/auth/index.js +13 -21
  16. package/dist/auth/index.mjs +12 -20
  17. package/dist/auth/with_auth.d.mts +3 -3
  18. package/dist/auth/with_auth.d.ts +3 -3
  19. package/dist/auth/with_auth.js +13 -21
  20. package/dist/auth/with_auth.mjs +12 -20
  21. package/dist/crud/crud_form.d.mts +13 -0
  22. package/dist/crud/crud_form.d.ts +13 -0
  23. package/dist/crud/crud_form.js +88 -0
  24. package/dist/crud/crud_form.mjs +55 -0
  25. package/dist/crud/crud_form_provider.d.mts +34 -0
  26. package/dist/crud/crud_form_provider.d.ts +34 -0
  27. package/dist/crud/crud_form_provider.js +160 -0
  28. package/dist/crud/crud_form_provider.mjs +124 -0
  29. package/dist/crud/crud_loader.d.mts +21 -0
  30. package/dist/crud/crud_loader.d.ts +21 -0
  31. package/dist/crud/crud_loader.js +288 -0
  32. package/dist/crud/crud_loader.mjs +273 -0
  33. package/dist/crud/crud_page.d.mts +25 -0
  34. package/dist/crud/crud_page.d.ts +25 -0
  35. package/dist/crud/crud_page.js +645 -0
  36. package/dist/crud/crud_page.mjs +616 -0
  37. package/dist/crud/generate_handlers.d.mts +15 -0
  38. package/dist/crud/generate_handlers.d.ts +15 -0
  39. package/dist/crud/generate_handlers.js +39 -0
  40. package/dist/crud/generate_handlers.mjs +14 -0
  41. package/dist/crud/generate_pages.d.mts +11 -0
  42. package/dist/crud/generate_pages.d.ts +11 -0
  43. package/dist/crud/generate_pages.js +52 -0
  44. package/dist/crud/generate_pages.mjs +17 -0
  45. package/dist/crud/generate_routes.d.mts +5 -0
  46. package/dist/crud/generate_routes.d.ts +5 -0
  47. package/dist/crud/generate_routes.js +62 -0
  48. package/dist/crud/generate_routes.mjs +27 -0
  49. package/dist/crud/index.d.mts +21 -0
  50. package/dist/crud/index.d.ts +21 -0
  51. package/dist/crud/index.js +970 -0
  52. package/dist/crud/index.mjs +945 -0
  53. package/dist/db/index.d.mts +4 -0
  54. package/dist/db/index.d.ts +4 -0
  55. package/dist/db/index.js +46 -0
  56. package/dist/db/index.mjs +8 -0
  57. package/dist/index.d.mts +3 -2
  58. package/dist/index.d.ts +3 -2
  59. package/dist/seo/index.js +26 -25
  60. package/dist/seo/index.mjs +27 -26
  61. package/dist/seo/seo.js +26 -25
  62. package/dist/seo/seo.mjs +27 -26
  63. package/dist/table/buttons.d.mts +10 -0
  64. package/dist/table/buttons.d.ts +10 -0
  65. package/dist/table/buttons.js +102 -0
  66. package/dist/table/buttons.mjs +71 -0
  67. package/dist/table/index.d.mts +9 -0
  68. package/dist/table/index.d.ts +9 -0
  69. package/dist/table/index.js +570 -0
  70. package/dist/table/index.mjs +543 -0
  71. package/dist/table/item_loader.d.mts +12 -0
  72. package/dist/table/item_loader.d.ts +12 -0
  73. package/dist/table/item_loader.js +51 -0
  74. package/dist/table/item_loader.mjs +26 -0
  75. package/dist/table/loader.d.mts +28 -0
  76. package/dist/table/loader.d.ts +28 -0
  77. package/dist/table/loader.js +70 -0
  78. package/dist/table/loader.mjs +48 -0
  79. package/dist/table/page.d.mts +27 -0
  80. package/dist/table/page.d.ts +27 -0
  81. package/dist/table/page.js +444 -0
  82. package/dist/table/page.mjs +415 -0
  83. package/dist/table/repository.d.mts +38 -0
  84. package/dist/table/repository.d.ts +38 -0
  85. package/dist/table/repository.js +76 -0
  86. package/dist/table/repository.mjs +56 -0
  87. package/dist/table/table.d.mts +27 -0
  88. package/dist/table/table.d.ts +27 -0
  89. package/dist/table/table.js +290 -0
  90. package/dist/table/table.mjs +255 -0
  91. package/package.json +21 -3
  92. package/dist/auth/temp_user.d.mts +0 -5
  93. package/dist/auth/temp_user.d.ts +0 -5
  94. package/dist/auth/temp_user.js +0 -18
  95. package/dist/auth/temp_user.mjs +0 -0
@@ -0,0 +1,543 @@
1
+ // src/table/repository.ts
2
+ import {
3
+ count,
4
+ eq,
5
+ desc,
6
+ asc
7
+ } from "drizzle-orm";
8
+ var BaseTableRepository = class {
9
+ db;
10
+ schema;
11
+ pk;
12
+ constructor(db, schema, pk = "id") {
13
+ this.db = db;
14
+ this.schema = schema;
15
+ this.pk = pk;
16
+ }
17
+ async find(id) {
18
+ return await this.db.select().from(this.schema).where(eq(this.schema[this.pk], id)).limit(1).then((res) => res[0]);
19
+ }
20
+ async countTotal({ where }) {
21
+ const [{ total }] = await this.db.select({ total: count() }).from(this.schema).where(where);
22
+ return total;
23
+ }
24
+ async findAll(options) {
25
+ const { orderBy, direction, limit, offset, where } = options;
26
+ let builder = this.db.select().from(this.schema);
27
+ if (where) {
28
+ builder = builder.where(where);
29
+ }
30
+ if (orderBy) {
31
+ builder = builder.orderBy(
32
+ direction === "desc" ? desc(this.schema[orderBy]) : asc(this.schema[orderBy])
33
+ );
34
+ }
35
+ if (limit) {
36
+ builder = builder.limit(limit);
37
+ }
38
+ if (offset) {
39
+ builder = builder.offset(offset);
40
+ }
41
+ return await builder;
42
+ }
43
+ async save(values) {
44
+ const [item] = await this.db.insert(this.schema).values(values).onConflictDoUpdate({
45
+ target: this.schema[this.pk],
46
+ set: values
47
+ }).returning();
48
+ return item;
49
+ }
50
+ async delete(pk) {
51
+ await this.db.delete(this.schema).where(eq(this.schema[this.pk], pk));
52
+ }
53
+ };
54
+
55
+ // src/table/buttons.tsx
56
+ import { cn } from "dn-react-toolkit/utils";
57
+ import { Link, useLocation, useSearchParams } from "react-router";
58
+ import React from "react";
59
+ function TablePageButtons({
60
+ MAX_PAGES_TO_SHOW,
61
+ total,
62
+ limit,
63
+ offset
64
+ }) {
65
+ const pages = Math.ceil(total / limit);
66
+ const { pathname } = useLocation();
67
+ const [searchParams] = useSearchParams();
68
+ const currentPage = Math.floor(offset / limit) + 1;
69
+ const startButton = (Math.ceil(currentPage / MAX_PAGES_TO_SHOW) - 1) * MAX_PAGES_TO_SHOW;
70
+ const endButton = Math.min(startButton + MAX_PAGES_TO_SHOW - 1, pages);
71
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, pages > 1 && /* @__PURE__ */ React.createElement("div", { className: "flex justify-center items-center my-8 gap-4 text-neutral-400" }, startButton > 1 && /* @__PURE__ */ React.createElement(
72
+ Link,
73
+ {
74
+ to: (() => {
75
+ searchParams.set(
76
+ "offset",
77
+ String((startButton - 1) * limit)
78
+ );
79
+ return `${pathname}?${searchParams.toString()}`;
80
+ })(),
81
+ className: "w-10 block text-center transition-colors hover:text-primary"
82
+ },
83
+ "\uC774\uC804"
84
+ ), Array.from({
85
+ length: Math.min(
86
+ MAX_PAGES_TO_SHOW,
87
+ pages - startButton
88
+ )
89
+ }).map((_, index) => {
90
+ return /* @__PURE__ */ React.createElement(
91
+ Link,
92
+ {
93
+ key: index,
94
+ to: (() => {
95
+ searchParams.set(
96
+ "offset",
97
+ String((startButton + index) * limit)
98
+ );
99
+ return `${pathname}?${searchParams.toString()}`;
100
+ })(),
101
+ className: cn(
102
+ "w-6 block text-center transition-colors",
103
+ currentPage === startButton + index + 1 ? "font-bold text-primary" : "hover:text-primary"
104
+ )
105
+ },
106
+ startButton + index + 1
107
+ );
108
+ }), endButton < pages && /* @__PURE__ */ React.createElement(
109
+ Link,
110
+ {
111
+ to: (() => {
112
+ searchParams.set(
113
+ "offset",
114
+ String((endButton + 1) * limit)
115
+ );
116
+ return `${pathname}?${searchParams.toString()}`;
117
+ })(),
118
+ className: "w-10 block text-center transition-colors hover:text-primary"
119
+ },
120
+ "\uB2E4\uC74C"
121
+ )));
122
+ }
123
+
124
+ // src/table/item_loader.tsx
125
+ var tableItemloader = ({
126
+ loader,
127
+ repository
128
+ }) => {
129
+ return async ({ params }) => {
130
+ const body = loader ? await (async () => {
131
+ const result = await loader({ params });
132
+ if (result instanceof Response) {
133
+ return result.json();
134
+ }
135
+ return result;
136
+ })() : {};
137
+ if (params["itemId"] === "new") {
138
+ return { item: void 0, ...body };
139
+ }
140
+ const item = params["itemId"] ? await repository.find(params["itemId"]) : void 0;
141
+ return {
142
+ item,
143
+ ...body
144
+ };
145
+ };
146
+ };
147
+
148
+ // src/table/loader.tsx
149
+ import {
150
+ and,
151
+ ilike
152
+ } from "drizzle-orm";
153
+ function tableLoader({
154
+ repository,
155
+ tableOptions
156
+ }) {
157
+ return async ({ request }) => {
158
+ const searchParams = new URL(request.url).searchParams;
159
+ const { where, searchKey, defaultOrderBy, defaultDirection } = tableOptions;
160
+ const query = searchParams.get("query") ?? void 0;
161
+ const limit = Number(searchParams.get("limit") ?? "10");
162
+ const offset = Number(searchParams.get("offset") ?? "0");
163
+ const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
164
+ const direction = searchParams.get("direction") ?? defaultDirection;
165
+ const whereClauses = and(
166
+ searchKey && query ? ilike(
167
+ repository.schema[searchKey],
168
+ `%${query}%`
169
+ ) : void 0,
170
+ ...where ?? []
171
+ );
172
+ const total = await repository.countTotal({ where: whereClauses });
173
+ const items = await repository.findAll({
174
+ orderBy,
175
+ direction,
176
+ limit,
177
+ offset,
178
+ where: whereClauses
179
+ });
180
+ return {
181
+ table: {
182
+ items,
183
+ total,
184
+ limit,
185
+ offset,
186
+ orderBy,
187
+ direction,
188
+ searchKey
189
+ }
190
+ };
191
+ };
192
+ }
193
+
194
+ // src/table/page.tsx
195
+ import {
196
+ Link as Link3,
197
+ useLoaderData,
198
+ useLocation as useLocation2,
199
+ useNavigate,
200
+ useSearchParams as useSearchParams3
201
+ } from "react-router";
202
+
203
+ // node_modules/react-icons/lib/iconBase.mjs
204
+ import React3 from "react";
205
+
206
+ // node_modules/react-icons/lib/iconContext.mjs
207
+ import React2 from "react";
208
+ var DefaultContext = {
209
+ color: void 0,
210
+ size: void 0,
211
+ className: void 0,
212
+ style: void 0,
213
+ attr: void 0
214
+ };
215
+ var IconContext = React2.createContext && /* @__PURE__ */ React2.createContext(DefaultContext);
216
+
217
+ // node_modules/react-icons/lib/iconBase.mjs
218
+ var _excluded = ["attr", "size", "title"];
219
+ function _objectWithoutProperties(source, excluded) {
220
+ if (source == null) return {};
221
+ var target = _objectWithoutPropertiesLoose(source, excluded);
222
+ var key, i;
223
+ if (Object.getOwnPropertySymbols) {
224
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
225
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
226
+ key = sourceSymbolKeys[i];
227
+ if (excluded.indexOf(key) >= 0) continue;
228
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
229
+ target[key] = source[key];
230
+ }
231
+ }
232
+ return target;
233
+ }
234
+ function _objectWithoutPropertiesLoose(source, excluded) {
235
+ if (source == null) return {};
236
+ var target = {};
237
+ for (var key in source) {
238
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
239
+ if (excluded.indexOf(key) >= 0) continue;
240
+ target[key] = source[key];
241
+ }
242
+ }
243
+ return target;
244
+ }
245
+ function _extends() {
246
+ _extends = Object.assign ? Object.assign.bind() : function(target) {
247
+ for (var i = 1; i < arguments.length; i++) {
248
+ var source = arguments[i];
249
+ for (var key in source) {
250
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
251
+ target[key] = source[key];
252
+ }
253
+ }
254
+ }
255
+ return target;
256
+ };
257
+ return _extends.apply(this, arguments);
258
+ }
259
+ function ownKeys(e, r) {
260
+ var t = Object.keys(e);
261
+ if (Object.getOwnPropertySymbols) {
262
+ var o = Object.getOwnPropertySymbols(e);
263
+ r && (o = o.filter(function(r2) {
264
+ return Object.getOwnPropertyDescriptor(e, r2).enumerable;
265
+ })), t.push.apply(t, o);
266
+ }
267
+ return t;
268
+ }
269
+ function _objectSpread(e) {
270
+ for (var r = 1; r < arguments.length; r++) {
271
+ var t = null != arguments[r] ? arguments[r] : {};
272
+ r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
273
+ _defineProperty(e, r2, t[r2]);
274
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
275
+ Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
276
+ });
277
+ }
278
+ return e;
279
+ }
280
+ function _defineProperty(obj, key, value) {
281
+ key = _toPropertyKey(key);
282
+ if (key in obj) {
283
+ Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
284
+ } else {
285
+ obj[key] = value;
286
+ }
287
+ return obj;
288
+ }
289
+ function _toPropertyKey(t) {
290
+ var i = _toPrimitive(t, "string");
291
+ return "symbol" == typeof i ? i : i + "";
292
+ }
293
+ function _toPrimitive(t, r) {
294
+ if ("object" != typeof t || !t) return t;
295
+ var e = t[Symbol.toPrimitive];
296
+ if (void 0 !== e) {
297
+ var i = e.call(t, r || "default");
298
+ if ("object" != typeof i) return i;
299
+ throw new TypeError("@@toPrimitive must return a primitive value.");
300
+ }
301
+ return ("string" === r ? String : Number)(t);
302
+ }
303
+ function Tree2Element(tree) {
304
+ return tree && tree.map((node, i) => /* @__PURE__ */ React3.createElement(node.tag, _objectSpread({
305
+ key: i
306
+ }, node.attr), Tree2Element(node.child)));
307
+ }
308
+ function GenIcon(data) {
309
+ return (props) => /* @__PURE__ */ React3.createElement(IconBase, _extends({
310
+ attr: _objectSpread({}, data.attr)
311
+ }, props), Tree2Element(data.child));
312
+ }
313
+ function IconBase(props) {
314
+ var elem = (conf) => {
315
+ var {
316
+ attr,
317
+ size,
318
+ title
319
+ } = props, svgProps = _objectWithoutProperties(props, _excluded);
320
+ var computedSize = size || conf.size || "1em";
321
+ var className;
322
+ if (conf.className) className = conf.className;
323
+ if (props.className) className = (className ? className + " " : "") + props.className;
324
+ return /* @__PURE__ */ React3.createElement("svg", _extends({
325
+ stroke: "currentColor",
326
+ fill: "currentColor",
327
+ strokeWidth: "0"
328
+ }, conf.attr, attr, svgProps, {
329
+ className,
330
+ style: _objectSpread(_objectSpread({
331
+ color: props.color || conf.color
332
+ }, conf.style), props.style),
333
+ height: computedSize,
334
+ width: computedSize,
335
+ xmlns: "http://www.w3.org/2000/svg"
336
+ }), title && /* @__PURE__ */ React3.createElement("title", null, title), props.children);
337
+ };
338
+ return IconContext !== void 0 ? /* @__PURE__ */ React3.createElement(IconContext.Consumer, null, (conf) => elem(conf)) : elem(DefaultContext);
339
+ }
340
+
341
+ // node_modules/react-icons/go/index.mjs
342
+ function GoArrowDown(props) {
343
+ return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "M4.97 13.22a.75.75 0 0 1 1.06 0L11 18.19V3.75a.75.75 0 0 1 1.5 0v14.44l4.97-4.97a.749.749 0 0 1 1.275.326.749.749 0 0 1-.215.734l-6.25 6.25a.75.75 0 0 1-1.06 0l-6.25-6.25a.75.75 0 0 1 0-1.06Z" }, "child": [] }] })(props);
344
+ }
345
+ function GoArrowUp(props) {
346
+ return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "M18.655 10.405a.75.75 0 0 1-1.06 0l-4.97-4.97v14.44a.75.75 0 0 1-1.5 0V5.435l-4.97 4.97a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l6.25-6.25a.75.75 0 0 1 1.06 0l6.25 6.25a.75.75 0 0 1 0 1.06Z" }, "child": [] }] })(props);
347
+ }
348
+ function GoSearch(props) {
349
+ return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "M10.25 2a8.25 8.25 0 0 1 6.34 13.53l5.69 5.69a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215l-5.69-5.69A8.25 8.25 0 1 1 10.25 2ZM3.5 10.25a6.75 6.75 0 1 0 13.5 0 6.75 6.75 0 0 0-13.5 0Z" }, "child": [] }] })(props);
350
+ }
351
+
352
+ // src/table/table.tsx
353
+ import { cn as cn2 } from "dn-react-toolkit/utils";
354
+ import { Link as Link2, useSearchParams as useSearchParams2 } from "react-router";
355
+ import React4 from "react";
356
+ function Table({
357
+ className = "min-w-full whitespace-nowrap",
358
+ data,
359
+ columns,
360
+ mapper: Mapper,
361
+ getLink,
362
+ limit,
363
+ offset,
364
+ orderBy,
365
+ direction
366
+ }) {
367
+ const keys = Object.entries(columns).filter((entry) => entry[1]).map(([key]) => key);
368
+ const sortedArray = [...data];
369
+ const [_, setSearchParams] = useSearchParams2();
370
+ return /* @__PURE__ */ React4.createElement(
371
+ "table",
372
+ {
373
+ className: cn2(
374
+ className,
375
+ "text-[15px] border-separate border-spacing-0"
376
+ )
377
+ },
378
+ /* @__PURE__ */ React4.createElement("thead", null, /* @__PURE__ */ React4.createElement("tr", null, keys.map((key) => {
379
+ const value = columns[key];
380
+ function getReactNode() {
381
+ if (value && typeof value === "object" && "label" in value) {
382
+ return value.label;
383
+ }
384
+ return value;
385
+ }
386
+ function Head() {
387
+ const reactNode = getReactNode();
388
+ if (typeof reactNode === "string") {
389
+ return /* @__PURE__ */ React4.createElement(
390
+ "button",
391
+ {
392
+ className: cn2(
393
+ orderBy === key ? "text-neutral-900 font-medium" : "text-neutral-500",
394
+ "px-4 h-14 flex items-center w-full"
395
+ ),
396
+ onClick: () => {
397
+ let newDirection = "asc";
398
+ if (orderBy === key) {
399
+ newDirection = direction === "asc" ? "desc" : "asc";
400
+ }
401
+ setSearchParams({
402
+ orderBy: key,
403
+ direction: newDirection
404
+ });
405
+ }
406
+ },
407
+ reactNode,
408
+ orderBy === key && /* @__PURE__ */ React4.createElement("div", { className: "ml-0.5" }, direction === "asc" ? /* @__PURE__ */ React4.createElement(GoArrowUp, null) : /* @__PURE__ */ React4.createElement(GoArrowDown, null))
409
+ );
410
+ }
411
+ return /* @__PURE__ */ React4.createElement(React4.Fragment, null, reactNode);
412
+ }
413
+ return /* @__PURE__ */ React4.createElement(
414
+ "th",
415
+ {
416
+ key,
417
+ className: cn2("border-y font-normal")
418
+ },
419
+ /* @__PURE__ */ React4.createElement(Head, null)
420
+ );
421
+ }))),
422
+ /* @__PURE__ */ React4.createElement("tbody", null, sortedArray.length === 0 && /* @__PURE__ */ React4.createElement("tr", null, /* @__PURE__ */ React4.createElement(
423
+ "td",
424
+ {
425
+ colSpan: keys.length,
426
+ className: "px-4 h-14 text-neutral-400 text-center"
427
+ },
428
+ "\uB370\uC774\uD130\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."
429
+ )), sortedArray.map((item, i) => /* @__PURE__ */ React4.createElement("tr", { key: i, className: "hover:bg-gray-50 transition-colors" }, keys.map((key, i2) => {
430
+ const value = item[key];
431
+ function Content() {
432
+ if (key in columns) {
433
+ const column = columns[key];
434
+ if (column && typeof column === "object" && "mapper" in column) {
435
+ const mapper = column.mapper;
436
+ if (mapper) {
437
+ return /* @__PURE__ */ React4.createElement(React4.Fragment, null, mapper(item));
438
+ }
439
+ }
440
+ }
441
+ return /* @__PURE__ */ React4.createElement(React4.Fragment, null, String(value));
442
+ }
443
+ const linkedContent = getLink ? /* @__PURE__ */ React4.createElement(
444
+ Link2,
445
+ {
446
+ to: getLink(item),
447
+ className: "block content-center px-4 w-full h-full"
448
+ },
449
+ /* @__PURE__ */ React4.createElement(Content, null)
450
+ ) : /* @__PURE__ */ React4.createElement(Content, null);
451
+ const cell = Mapper ? /* @__PURE__ */ React4.createElement(Mapper, { item, index: i2 }, linkedContent) : linkedContent;
452
+ return /* @__PURE__ */ React4.createElement("td", { key, className: "px-0 h-14 border-b" }, cell);
453
+ }))))
454
+ );
455
+ }
456
+
457
+ // src/table/page.tsx
458
+ import React5 from "react";
459
+ function createTablePage({
460
+ name,
461
+ columns,
462
+ primaryKey = "id"
463
+ }) {
464
+ return function TablePage({
465
+ AdminLayout
466
+ }) {
467
+ const { pathname } = useLocation2();
468
+ const { table } = useLoaderData();
469
+ const { items, total, limit, offset, orderBy, direction, searchKey } = table;
470
+ const navigate = useNavigate();
471
+ const search = (query) => {
472
+ const searchParams2 = new URLSearchParams(window.location.search);
473
+ searchParams2.set("query", query);
474
+ searchParams2.set("offset", "0");
475
+ navigate(`${pathname}?${searchParams2.toString()}`);
476
+ };
477
+ const [searchParams] = useSearchParams3();
478
+ return /* @__PURE__ */ React5.createElement(
479
+ AdminLayout,
480
+ {
481
+ title: name,
482
+ actions: /* @__PURE__ */ React5.createElement(Link3, { to: `${pathname}/new`, className: "button-primary" }, name, " \uCD94\uAC00")
483
+ },
484
+ searchKey && /* @__PURE__ */ React5.createElement(
485
+ "form",
486
+ {
487
+ className: "h-18 px-4 flex items-center border-t",
488
+ onSubmit: (e) => {
489
+ e.preventDefault();
490
+ const formData = new FormData(e.currentTarget);
491
+ const query = formData.get("query");
492
+ search(query);
493
+ }
494
+ },
495
+ /* @__PURE__ */ React5.createElement(
496
+ "button",
497
+ {
498
+ type: "submit",
499
+ className: "w-10 h-10 flex justify-center items-center"
500
+ },
501
+ /* @__PURE__ */ React5.createElement(GoSearch, { className: "text-xl mr-4" })
502
+ ),
503
+ /* @__PURE__ */ React5.createElement(
504
+ "input",
505
+ {
506
+ className: "outline-none h-full flex-1",
507
+ placeholder: "\uC5EC\uAE30\uC5D0 \uAC80\uC0C9\uD558\uC138\uC694...",
508
+ name: "query",
509
+ defaultValue: searchParams.get("query") ?? ""
510
+ }
511
+ )
512
+ ),
513
+ /* @__PURE__ */ React5.createElement(
514
+ Table,
515
+ {
516
+ data: items,
517
+ columns,
518
+ getLink: primaryKey ? (item) => `${pathname}/${item[primaryKey]}` : void 0,
519
+ limit,
520
+ offset,
521
+ orderBy,
522
+ direction
523
+ }
524
+ ),
525
+ /* @__PURE__ */ React5.createElement(
526
+ TablePageButtons,
527
+ {
528
+ total,
529
+ limit,
530
+ offset,
531
+ MAX_PAGES_TO_SHOW: 10
532
+ }
533
+ )
534
+ );
535
+ };
536
+ }
537
+ export {
538
+ BaseTableRepository,
539
+ Table,
540
+ createTablePage,
541
+ tableItemloader,
542
+ tableLoader
543
+ };
@@ -0,0 +1,12 @@
1
+ import { Table } from 'drizzle-orm';
2
+ import { TableRepository } from './repository.mjs';
3
+ import { LoaderFunctionArgs } from 'react-router';
4
+ import 'drizzle-orm/pg-core';
5
+
6
+ type TableItemLoaderOptions<T extends Table, TSelect> = {
7
+ loader?: (args: LoaderFunctionArgs) => Promise<any>;
8
+ repository: TableRepository<T, TSelect>;
9
+ };
10
+ declare const tableItemloader: <T extends Table, TSelect>({ loader, repository, }: TableItemLoaderOptions<T, TSelect>) => ({ params }: LoaderFunctionArgs) => Promise<any>;
11
+
12
+ export { type TableItemLoaderOptions, tableItemloader };
@@ -0,0 +1,12 @@
1
+ import { Table } from 'drizzle-orm';
2
+ import { TableRepository } from './repository.js';
3
+ import { LoaderFunctionArgs } from 'react-router';
4
+ import 'drizzle-orm/pg-core';
5
+
6
+ type TableItemLoaderOptions<T extends Table, TSelect> = {
7
+ loader?: (args: LoaderFunctionArgs) => Promise<any>;
8
+ repository: TableRepository<T, TSelect>;
9
+ };
10
+ declare const tableItemloader: <T extends Table, TSelect>({ loader, repository, }: TableItemLoaderOptions<T, TSelect>) => ({ params }: LoaderFunctionArgs) => Promise<any>;
11
+
12
+ export { type TableItemLoaderOptions, tableItemloader };
@@ -0,0 +1,51 @@
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/item_loader.tsx
21
+ var item_loader_exports = {};
22
+ __export(item_loader_exports, {
23
+ tableItemloader: () => tableItemloader
24
+ });
25
+ module.exports = __toCommonJS(item_loader_exports);
26
+ var tableItemloader = ({
27
+ loader,
28
+ repository
29
+ }) => {
30
+ return async ({ params }) => {
31
+ const body = loader ? await (async () => {
32
+ const result = await loader({ params });
33
+ if (result instanceof Response) {
34
+ return result.json();
35
+ }
36
+ return result;
37
+ })() : {};
38
+ if (params["itemId"] === "new") {
39
+ return { item: void 0, ...body };
40
+ }
41
+ const item = params["itemId"] ? await repository.find(params["itemId"]) : void 0;
42
+ return {
43
+ item,
44
+ ...body
45
+ };
46
+ };
47
+ };
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ tableItemloader
51
+ });
@@ -0,0 +1,26 @@
1
+ // src/table/item_loader.tsx
2
+ var tableItemloader = ({
3
+ loader,
4
+ repository
5
+ }) => {
6
+ return async ({ params }) => {
7
+ const body = loader ? await (async () => {
8
+ const result = await loader({ params });
9
+ if (result instanceof Response) {
10
+ return result.json();
11
+ }
12
+ return result;
13
+ })() : {};
14
+ if (params["itemId"] === "new") {
15
+ return { item: void 0, ...body };
16
+ }
17
+ const item = params["itemId"] ? await repository.find(params["itemId"]) : void 0;
18
+ return {
19
+ item,
20
+ ...body
21
+ };
22
+ };
23
+ };
24
+ export {
25
+ tableItemloader
26
+ };
@@ -0,0 +1,28 @@
1
+ import { LoaderFunctionArgs } from 'react-router';
2
+ import { TableRepository, ColumnOf } from './repository.mjs';
3
+ import { Table, SQLWrapper, InferSelectModel } from 'drizzle-orm';
4
+ import 'drizzle-orm/pg-core';
5
+
6
+ type TableOptions<T extends Table> = {
7
+ where?: SQLWrapper[];
8
+ searchKey?: ColumnOf<T>;
9
+ defaultOrderBy: keyof InferSelectModel<T>;
10
+ defaultDirection: "asc" | "desc";
11
+ };
12
+ type TableLoaderOptions<T extends Table, TSelect> = {
13
+ repository: TableRepository<T, TSelect>;
14
+ tableOptions: TableOptions<T>;
15
+ };
16
+ declare function tableLoader<T extends Table, TSelect>({ repository, tableOptions, }: TableLoaderOptions<T, TSelect>): ({ request }: LoaderFunctionArgs) => Promise<{
17
+ table: {
18
+ items: TSelect[];
19
+ total: number;
20
+ limit: number;
21
+ offset: number;
22
+ orderBy: keyof T["_"]["columns"] & string;
23
+ direction: "desc" | "asc";
24
+ searchKey: ColumnOf<T> | undefined;
25
+ };
26
+ }>;
27
+
28
+ export { type TableLoaderOptions, tableLoader };