dn-react-router-toolkit 0.8.1 → 0.9.0

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