dn-react-router-toolkit 0.8.1 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/dist/api/create_api_handler.d.mts +2 -2
  2. package/dist/api/create_api_handler.d.ts +2 -2
  3. package/dist/api/create_api_handler.js +55 -52
  4. package/dist/api/create_api_handler.mjs +61 -59
  5. package/dist/api/create_handler.d.mts +5 -5
  6. package/dist/api/create_handler.d.ts +5 -5
  7. package/dist/api/create_handler.js +41 -44
  8. package/dist/api/create_handler.mjs +41 -44
  9. package/dist/api/index.d.mts +4 -3
  10. package/dist/api/index.d.ts +4 -3
  11. package/dist/api/index.js +118 -102
  12. package/dist/api/index.mjs +130 -109
  13. package/dist/api/item_api_handler.d.mts +4 -3
  14. package/dist/api/item_api_handler.d.ts +4 -3
  15. package/dist/api/item_api_handler.js +22 -6
  16. package/dist/api/item_api_handler.mjs +28 -6
  17. package/dist/auth/cookie_manager.d.mts +1 -1
  18. package/dist/auth/cookie_manager.d.ts +1 -1
  19. package/dist/auth/index.d.mts +2 -2
  20. package/dist/auth/index.d.ts +2 -2
  21. package/dist/auth/index.js +18 -18
  22. package/dist/auth/index.mjs +18 -18
  23. package/dist/auth/with_auth.d.mts +2 -2
  24. package/dist/auth/with_auth.d.ts +2 -2
  25. package/dist/auth/with_auth.js +18 -18
  26. package/dist/auth/with_auth.mjs +18 -18
  27. package/dist/client/editor.d.mts +2 -2
  28. package/dist/client/editor.d.ts +2 -2
  29. package/dist/client/editor.js +9 -3
  30. package/dist/client/editor.mjs +9 -3
  31. package/dist/client/index.d.mts +2 -2
  32. package/dist/client/index.d.ts +2 -2
  33. package/dist/client/index.js +9 -3
  34. package/dist/client/index.mjs +9 -3
  35. package/dist/crud/crud_form.js +22 -4
  36. package/dist/crud/crud_form.mjs +11 -3
  37. package/dist/crud/crud_form_provider.js +16 -3
  38. package/dist/crud/crud_form_provider.mjs +14 -1
  39. package/dist/crud/index.d.mts +0 -20
  40. package/dist/crud/index.d.ts +0 -20
  41. package/dist/crud/index.js +32 -8589
  42. package/dist/crud/index.mjs +11 -8599
  43. package/dist/db/backup/index.d.mts +1 -1
  44. package/dist/db/backup/index.d.ts +1 -1
  45. package/dist/form/create_form_component.js +21 -2
  46. package/dist/form/create_form_component.mjs +10 -1
  47. package/dist/form/form_components.js +21 -2
  48. package/dist/form/form_components.mjs +10 -1
  49. package/dist/form/index.js +21 -2
  50. package/dist/form/index.mjs +10 -1
  51. package/dist/post/editor_toolbar.js +20 -3
  52. package/dist/post/editor_toolbar.mjs +9 -2
  53. package/dist/post/index.js +93 -7711
  54. package/dist/post/index.mjs +69 -7723
  55. package/dist/post/post_form_page.js +91 -7711
  56. package/dist/post/post_form_page.mjs +69 -7725
  57. package/dist/post/thumbnail_picker.js +21 -2
  58. package/dist/post/thumbnail_picker.mjs +10 -1
  59. package/dist/table/buttons.js +11 -14
  60. package/dist/table/buttons.mjs +10 -13
  61. package/dist/table/index.d.mts +0 -2
  62. package/dist/table/index.d.ts +0 -2
  63. package/dist/table/index.js +24 -95
  64. package/dist/table/index.mjs +23 -92
  65. package/dist/table/load_table.d.mts +1 -1
  66. package/dist/table/load_table.d.ts +1 -1
  67. package/dist/table/load_table.js +2 -2
  68. package/dist/table/load_table.mjs +2 -2
  69. package/dist/table/loader.js +2 -2
  70. package/dist/table/loader.mjs +2 -2
  71. package/dist/table/table.d.mts +2 -2
  72. package/dist/table/table.d.ts +2 -2
  73. package/dist/table/table.js +14 -25
  74. package/dist/table/table.mjs +11 -24
  75. package/dist/table/table_form.js +16 -39
  76. package/dist/table/table_form.mjs +15 -38
  77. package/dist/utils/cn.d.mts +3 -0
  78. package/dist/utils/cn.d.ts +3 -0
  79. package/dist/utils/cn.js +32 -0
  80. package/dist/utils/cn.mjs +7 -0
  81. package/dist/utils/date.d.mts +5 -0
  82. package/dist/utils/date.d.ts +5 -0
  83. package/dist/utils/date.js +65 -0
  84. package/dist/utils/date.mjs +29 -0
  85. package/dist/utils/index.d.mts +7 -0
  86. package/dist/utils/index.d.ts +7 -0
  87. package/dist/utils/index.js +116 -0
  88. package/dist/utils/index.mjs +73 -0
  89. package/dist/utils/korean.d.mts +6 -0
  90. package/dist/utils/korean.d.ts +6 -0
  91. package/dist/{crud/generate_pages.js → utils/korean.js} +16 -30
  92. package/dist/utils/korean.mjs +16 -0
  93. package/dist/utils/singleton.d.mts +3 -0
  94. package/dist/utils/singleton.d.ts +3 -0
  95. package/dist/utils/singleton.js +37 -0
  96. package/dist/utils/singleton.mjs +12 -0
  97. package/dist/utils/sleep.d.mts +3 -0
  98. package/dist/utils/sleep.d.ts +3 -0
  99. package/dist/{table/item_loader.js → utils/sleep.js} +8 -19
  100. package/dist/utils/sleep.mjs +7 -0
  101. package/dist/utils/slug.d.mts +3 -0
  102. package/dist/utils/slug.d.ts +3 -0
  103. package/dist/{crud/generate_handlers.js → utils/slug.js} +8 -15
  104. package/dist/utils/slug.mjs +7 -0
  105. package/package.json +7 -3
  106. package/dist/crud/crud_loader.d.mts +0 -26
  107. package/dist/crud/crud_loader.d.ts +0 -26
  108. package/dist/crud/crud_loader.js +0 -351
  109. package/dist/crud/crud_loader.mjs +0 -337
  110. package/dist/crud/crud_page.d.mts +0 -32
  111. package/dist/crud/crud_page.d.ts +0 -32
  112. package/dist/crud/crud_page.js +0 -776
  113. package/dist/crud/crud_page.mjs +0 -758
  114. package/dist/crud/generate_handlers.d.mts +0 -16
  115. package/dist/crud/generate_handlers.d.ts +0 -16
  116. package/dist/crud/generate_handlers.mjs +0 -14
  117. package/dist/crud/generate_pages.d.mts +0 -19
  118. package/dist/crud/generate_pages.d.ts +0 -19
  119. package/dist/crud/generate_pages.mjs +0 -30
  120. package/dist/crud/generate_routes.d.mts +0 -5
  121. package/dist/crud/generate_routes.d.ts +0 -5
  122. package/dist/crud/generate_routes.js +0 -7639
  123. package/dist/crud/generate_routes.mjs +0 -7627
  124. package/dist/table/item_loader.d.mts +0 -14
  125. package/dist/table/item_loader.d.ts +0 -14
  126. package/dist/table/item_loader.mjs +0 -18
  127. package/dist/table/page.d.mts +0 -16
  128. package/dist/table/page.d.ts +0 -16
  129. package/dist/table/page.js +0 -375
  130. package/dist/table/page.mjs +0 -350
@@ -1,776 +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/crud/crud_page.tsx
21
- var crud_page_exports = {};
22
- __export(crud_page_exports, {
23
- crudPage: () => crudPage
24
- });
25
- module.exports = __toCommonJS(crud_page_exports);
26
- var import_react_router9 = require("react-router");
27
-
28
- // src/crud/crud_form_provider.tsx
29
- var import_react_router = require("react-router");
30
- var import_react_store_input = require("react-store-input");
31
- var import_react = require("react");
32
-
33
- // src/crud/serialize.ts
34
- function serialize(value) {
35
- if (value === void 0) {
36
- return void 0;
37
- }
38
- if (value === null) {
39
- return {
40
- type: "null",
41
- value: null
42
- };
43
- }
44
- if (typeof value === "string") {
45
- return {
46
- type: "string",
47
- value
48
- };
49
- }
50
- if (typeof value === "number") {
51
- return {
52
- type: "number",
53
- value
54
- };
55
- }
56
- if (typeof value === "boolean") {
57
- return {
58
- type: "boolean",
59
- value
60
- };
61
- }
62
- if (value instanceof Date) {
63
- return {
64
- type: "date",
65
- value: value.toISOString()
66
- };
67
- }
68
- if (Array.isArray(value)) {
69
- return {
70
- type: "array",
71
- value: value.map((item) => serialize(item))
72
- };
73
- }
74
- if (typeof value === "object") {
75
- return {
76
- type: "object",
77
- value: Object.entries(value).reduce(
78
- (acc, [key, value2]) => {
79
- return {
80
- ...acc,
81
- [key]: serialize(value2)
82
- };
83
- },
84
- {}
85
- )
86
- };
87
- }
88
- return void 0;
89
- }
90
-
91
- // src/crud/crud_form_provider.tsx
92
- var import_utils = require("dn-react-toolkit/utils");
93
- var import_jsx_runtime = require("react/jsx-runtime");
94
- var FormContext = (0, import_react.createContext)({});
95
- function useFormContext() {
96
- return (0, import_react.useContext)(FormContext);
97
- }
98
- function CrudFormProvider({
99
- primaryKey,
100
- name,
101
- prefix,
102
- item,
103
- columns = {},
104
- children
105
- }) {
106
- const apiPrefix = `/api${prefix}`;
107
- const createInitialState = () => {
108
- return Object.keys(item || columns).reduce((acc, key) => {
109
- const value2 = item ? item[key] : void 0;
110
- if (columns[key]?.defaultValue !== void 0) {
111
- if (typeof value2 === "number") {
112
- return {
113
- ...acc,
114
- [key]: value2 ?? columns[key]?.defaultValue
115
- };
116
- }
117
- return {
118
- ...acc,
119
- [key]: value2 || columns[key]?.defaultValue
120
- };
121
- }
122
- return {
123
- ...acc,
124
- [key]: value2
125
- };
126
- }, {});
127
- };
128
- const store = (0, import_react_store_input.useStore)(createInitialState());
129
- const navigate = (0, import_react_router.useNavigate)();
130
- const submit = async () => {
131
- const res = await fetch(apiPrefix, {
132
- method: "POST",
133
- headers: {
134
- "Content-Type": "application/json"
135
- },
136
- body: JSON.stringify(serialize(store.state))
137
- });
138
- if (!res.ok) {
139
- const { message } = await res.json();
140
- alert(message);
141
- return;
142
- }
143
- alert(`${import_utils.Korean.with(name, ["\uC744", "\uB97C"])} \uC800\uC7A5\uD588\uC2B5\uB2C8\uB2E4.`);
144
- const { id } = await res.json();
145
- navigate(`${prefix}/${id}`);
146
- };
147
- const deleteItem = async () => {
148
- if (!item || !primaryKey) {
149
- return;
150
- }
151
- const ok = confirm("\uC815\uB9D0\uB85C \uC0AD\uC81C\uD558\uC2DC\uACA0\uC2B5\uB2C8\uAE4C?");
152
- if (!ok) {
153
- return;
154
- }
155
- const res = await fetch(`${apiPrefix}/${item[primaryKey]}`, {
156
- method: "DELETE"
157
- });
158
- if (!res.ok) {
159
- const { message } = await res.json();
160
- alert(message);
161
- return;
162
- }
163
- alert(`${import_utils.Korean.with(name, ["\uC744", "\uB97C"])} \uC0AD\uC81C\uD588\uC2B5\uB2C8\uB2E4.`);
164
- navigate(`${prefix}`);
165
- };
166
- const value = {
167
- name,
168
- item,
169
- store,
170
- submit,
171
- delete: deleteItem,
172
- columns
173
- };
174
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormContext.Provider, { value, children });
175
- }
176
-
177
- // src/table/page.tsx
178
- var import_react_router6 = require("react-router");
179
-
180
- // src/table/table_form.tsx
181
- var import_react_router5 = require("react-router");
182
- var import_go2 = require("react-icons/go");
183
-
184
- // src/table/table.tsx
185
- var import_utils2 = require("dn-react-toolkit/utils");
186
- var import_go = require("react-icons/go");
187
- var import_react_router2 = require("react-router");
188
- var import_jsx_runtime2 = require("react/jsx-runtime");
189
- function Table({
190
- className = "min-w-full whitespace-nowrap",
191
- data,
192
- columns,
193
- mapper: Mapper,
194
- getLink,
195
- limit,
196
- offset,
197
- orderBy,
198
- direction,
199
- filters
200
- }) {
201
- const keys = Object.entries(columns).filter((entry) => entry[1]).map(([key]) => key);
202
- const sortedArray = [...data];
203
- const [_, setSearchParams] = (0, import_react_router2.useSearchParams)();
204
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
205
- "table",
206
- {
207
- className: (0, import_utils2.cn)(
208
- className,
209
- "text-[15px] border-separate border-spacing-0"
210
- ),
211
- children: [
212
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: keys.map((key) => {
213
- const value = columns[key];
214
- function getReactNode() {
215
- if (value && typeof value === "object" && "label" in value) {
216
- return value.label;
217
- }
218
- return value;
219
- }
220
- function Head() {
221
- const reactNode = getReactNode();
222
- if (typeof reactNode === "string") {
223
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
224
- "button",
225
- {
226
- className: (0, import_utils2.cn)(
227
- orderBy === key ? "text-gray-900 font-medium" : "text-gray-500 font-medium",
228
- "px-4 flex items-center w-full"
229
- ),
230
- onClick: () => {
231
- let newDirection = "asc";
232
- if (orderBy === key) {
233
- newDirection = direction === "asc" ? "desc" : "asc";
234
- }
235
- setSearchParams({
236
- orderBy: key,
237
- direction: newDirection
238
- });
239
- },
240
- children: [
241
- reactNode,
242
- orderBy === key && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ml-0.5", children: direction === "asc" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_go.GoArrowUp, {}) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_go.GoArrowDown, {}) })
243
- ]
244
- }
245
- );
246
- }
247
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: reactNode });
248
- }
249
- const filter = filters[key];
250
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
251
- "th",
252
- {
253
- className: (0, import_utils2.cn)(
254
- "py-4 border-y font-normal align-top"
255
- ),
256
- children: [
257
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Head, {}),
258
- filter && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "px-3 mt-4", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
259
- "select",
260
- {
261
- className: "w-full h-10 px-1.5 border rounded-full outline-none",
262
- onChange: (e) => {
263
- const value2 = e.target.value;
264
- setSearchParams((prev) => {
265
- if (value2) {
266
- prev.set(
267
- key,
268
- encodeURIComponent(
269
- value2
270
- )
271
- );
272
- } else {
273
- prev.delete(key);
274
- }
275
- return prev;
276
- });
277
- },
278
- children: [
279
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "", children: "\uC804\uCCB4" }),
280
- filter.map((option) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
281
- "option",
282
- {
283
- value: option,
284
- children: option
285
- },
286
- option
287
- ))
288
- ]
289
- }
290
- ) })
291
- ]
292
- },
293
- key
294
- );
295
- }) }) }),
296
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tbody", { children: [
297
- sortedArray.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
298
- "td",
299
- {
300
- colSpan: keys.length,
301
- className: "px-4 h-20 text-gray-400 text-center",
302
- children: "\uB370\uC774\uD130\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."
303
- }
304
- ) }),
305
- sortedArray.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { className: "hover:bg-gray-50 transition-colors", children: keys.map((key, i2) => {
306
- const value = item[key];
307
- function Content() {
308
- if (key in columns) {
309
- const column = columns[key];
310
- if (column && typeof column === "object" && "mapper" in column) {
311
- const mapper = column.mapper;
312
- if (mapper) {
313
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: mapper(item) });
314
- }
315
- }
316
- }
317
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: String(value) });
318
- }
319
- const linkedContent = getLink ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
320
- import_react_router2.Link,
321
- {
322
- to: getLink(item),
323
- className: "block content-center px-4 w-full h-full",
324
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Content, {})
325
- }
326
- ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Content, {});
327
- const cell = Mapper ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Mapper, { item, index: i2, children: linkedContent }) : linkedContent;
328
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { className: "px-0 h-14 border-b", children: cell }, key);
329
- }) }, i))
330
- ] })
331
- ]
332
- }
333
- );
334
- }
335
-
336
- // src/table/use_table.tsx
337
- var import_react_router3 = require("react-router");
338
- function useTable() {
339
- const { table } = (0, import_react_router3.useLoaderData)();
340
- return table;
341
- }
342
-
343
- // src/table/buttons.tsx
344
- var import_utils3 = require("dn-react-toolkit/utils");
345
- var import_react_router4 = require("react-router");
346
- var import_jsx_runtime3 = require("react/jsx-runtime");
347
- function TablePageButtons({
348
- MAX_PAGES_TO_SHOW,
349
- total,
350
- limit,
351
- offset
352
- }) {
353
- const pages = Math.ceil(total / limit);
354
- const { pathname } = (0, import_react_router4.useLocation)();
355
- const [searchParams] = (0, import_react_router4.useSearchParams)();
356
- const currentPage = Math.floor(offset / limit) + 1;
357
- const startButton = (Math.ceil(currentPage / MAX_PAGES_TO_SHOW) - 1) * MAX_PAGES_TO_SHOW;
358
- const endButton = Math.min(startButton + MAX_PAGES_TO_SHOW - 1, pages);
359
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: pages > 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex justify-center items-center my-8 gap-4 text-neutral-400", children: [
360
- startButton > 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
361
- import_react_router4.Link,
362
- {
363
- to: (() => {
364
- searchParams.set(
365
- "offset",
366
- String((startButton - 1) * limit)
367
- );
368
- return `${pathname}?${searchParams.toString()}`;
369
- })(),
370
- className: "w-10 block text-center transition-colors hover:text-primary",
371
- children: "\uC774\uC804"
372
- }
373
- ),
374
- Array.from({
375
- length: Math.min(
376
- MAX_PAGES_TO_SHOW,
377
- pages - startButton
378
- )
379
- }).map((_, index) => {
380
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
381
- import_react_router4.Link,
382
- {
383
- to: (() => {
384
- searchParams.set(
385
- "offset",
386
- String((startButton + index) * limit)
387
- );
388
- return `${pathname}?${searchParams.toString()}`;
389
- })(),
390
- className: (0, import_utils3.cn)(
391
- "w-6 block text-center transition-colors",
392
- currentPage === startButton + index + 1 ? "font-bold text-primary" : "hover:text-primary"
393
- ),
394
- children: startButton + index + 1
395
- },
396
- index
397
- );
398
- }),
399
- endButton < pages && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
400
- import_react_router4.Link,
401
- {
402
- to: (() => {
403
- searchParams.set(
404
- "offset",
405
- String((endButton + 1) * limit)
406
- );
407
- return `${pathname}?${searchParams.toString()}`;
408
- })(),
409
- className: "w-10 block text-center transition-colors hover:text-primary",
410
- children: "\uB2E4\uC74C"
411
- }
412
- )
413
- ] }) });
414
- }
415
-
416
- // src/table/table_form.tsx
417
- var import_jsx_runtime4 = require("react/jsx-runtime");
418
- function TableForm({
419
- columns,
420
- primaryKey = "id"
421
- }) {
422
- const { pathname } = (0, import_react_router5.useLocation)();
423
- const {
424
- items,
425
- total,
426
- limit,
427
- offset,
428
- orderBy,
429
- direction,
430
- searchKey,
431
- filters
432
- } = useTable();
433
- const navigate = (0, import_react_router5.useNavigate)();
434
- const search = (query) => {
435
- const searchParams2 = new URLSearchParams(window.location.search);
436
- searchParams2.set("query", query);
437
- searchParams2.set("offset", "0");
438
- navigate(`${pathname}?${searchParams2.toString()}`);
439
- };
440
- const [searchParams] = (0, import_react_router5.useSearchParams)();
441
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
442
- searchKey && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
443
- "form",
444
- {
445
- className: "h-20 px-4 flex items-center border-t",
446
- onSubmit: (e) => {
447
- e.preventDefault();
448
- const formData = new FormData(e.currentTarget);
449
- const query = formData.get("query");
450
- search(query);
451
- },
452
- children: [
453
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
454
- "button",
455
- {
456
- type: "submit",
457
- className: "w-10 h-10 flex justify-center items-center",
458
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_go2.GoSearch, { className: "text-xl mr-4" })
459
- }
460
- ),
461
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
462
- "input",
463
- {
464
- className: "outline-none h-full flex-1",
465
- placeholder: "\uC5EC\uAE30\uC5D0 \uAC80\uC0C9\uD558\uC138\uC694...",
466
- name: "query",
467
- defaultValue: searchParams.get("query") ?? ""
468
- }
469
- )
470
- ]
471
- }
472
- ),
473
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
474
- Table,
475
- {
476
- data: items,
477
- columns,
478
- getLink: primaryKey ? (item) => `${pathname}/${item[primaryKey]}` : void 0,
479
- limit,
480
- offset,
481
- orderBy,
482
- direction,
483
- filters
484
- }
485
- ),
486
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
487
- TablePageButtons,
488
- {
489
- total,
490
- limit,
491
- offset,
492
- MAX_PAGES_TO_SHOW: 10
493
- }
494
- )
495
- ] });
496
- }
497
-
498
- // src/table/page.tsx
499
- var import_jsx_runtime5 = require("react/jsx-runtime");
500
- function createTablePage({
501
- name,
502
- columns,
503
- primaryKey = "id"
504
- }) {
505
- return function TablePage({
506
- header: Header
507
- }) {
508
- const { pathname } = (0, import_react_router6.useLocation)();
509
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
510
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
511
- Header,
512
- {
513
- title: name,
514
- actions: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react_router6.Link, { to: `${pathname}/new`, className: "button-primary", children: [
515
- name,
516
- " \uCD94\uAC00"
517
- ] })
518
- }
519
- ),
520
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "max-w-7xl mx-auto w-full overflow-auto", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TableForm, { columns, primaryKey }) })
521
- ] });
522
- };
523
- }
524
-
525
- // src/form/create_form_component.tsx
526
- var import_utils4 = require("dn-react-toolkit/utils");
527
- var import_react2 = require("react");
528
- var import_jsx_runtime6 = require("react/jsx-runtime");
529
- function createComponent(tag, options) {
530
- return function FormComponent({ className, ...props }) {
531
- const Tag = tag;
532
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Tag, { ...props, className: (0, import_utils4.cn)(options.className, className) });
533
- };
534
- }
535
-
536
- // src/form/form_components.tsx
537
- var FormEntry = createComponent("div", {
538
- className: "flex-1"
539
- });
540
- var FormRow = createComponent("div", {
541
- className: "flex-1 flex gap-4 mb-6"
542
- });
543
- var FormLabel = createComponent("label", {
544
- className: "flex-1 font-semibold mb-2.5 block"
545
- });
546
-
547
- // src/crud/crud_form.tsx
548
- var import_react_store_input3 = require("react-store-input");
549
-
550
- // src/client/env_loader.tsx
551
- var import_react_router7 = require("react-router");
552
- var import_jsx_runtime7 = require("react/jsx-runtime");
553
-
554
- // src/client/file_input.tsx
555
- var import_react3 = require("react");
556
- var import_jsx_runtime8 = require("react/jsx-runtime");
557
-
558
- // src/client/use_user_agent.tsx
559
- var import_react_router8 = require("react-router");
560
-
561
- // src/client/store_text_editor.tsx
562
- var import_dn_react_text_editor = require("dn-react-text-editor");
563
- var import_react_store_input2 = require("react-store-input");
564
- var import_react4 = require("react");
565
- var import_jsx_runtime9 = require("react/jsx-runtime");
566
- function StoreTextEditor({
567
- store,
568
- name,
569
- getter,
570
- setter,
571
- defaultValue,
572
- ref,
573
- ...props
574
- }) {
575
- const controllerRef = (0, import_react4.useRef)(null);
576
- (0, import_react4.useImperativeHandle)(
577
- ref,
578
- () => controllerRef.current,
579
- []
580
- );
581
- const { dispatch } = (0, import_react_store_input2.useStoreController)(store, {
582
- onSubscribe: (state) => {
583
- const controller = controllerRef.current;
584
- if (!controller) {
585
- return;
586
- }
587
- const getResult = () => {
588
- if (getter) {
589
- return getter(state) || "";
590
- }
591
- if (name) {
592
- return state[name] || "";
593
- }
594
- return "";
595
- };
596
- const result = getResult();
597
- if (controller.value !== result) {
598
- controller.value = result;
599
- }
600
- },
601
- onDispatch: (state) => {
602
- const controller = controllerRef.current;
603
- if (!controller) {
604
- return;
605
- }
606
- if (setter) {
607
- setter(state, controller.value);
608
- return;
609
- }
610
- if (name) {
611
- state[name] = controller.value;
612
- }
613
- }
614
- });
615
- const getDefaultValue = () => {
616
- if (getter) {
617
- return getter(store.state);
618
- }
619
- if (name) {
620
- return store.state[name];
621
- }
622
- return void 0;
623
- };
624
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
625
- import_dn_react_text_editor.TextEditor,
626
- {
627
- ...props,
628
- ref: controllerRef,
629
- defaultValue: defaultValue ?? getDefaultValue(),
630
- onChange: (e) => {
631
- dispatch();
632
- props.onChange?.(e);
633
- }
634
- }
635
- );
636
- }
637
-
638
- // src/client/editor.tsx
639
- var import_client = require("dn-react-toolkit/file/client");
640
-
641
- // src/crud/crud_form.tsx
642
- var import_jsx_runtime10 = require("react/jsx-runtime");
643
- function CrudForm({
644
- AdminHeader
645
- }) {
646
- const form = useFormContext();
647
- const component = (0, import_react_store_input3.useStoreComponent)(form.store);
648
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
649
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
650
- AdminHeader,
651
- {
652
- title: `${form.name} ${form.item ? "\uC218\uC815" : "\uCD94\uAC00"}`,
653
- actions: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
654
- form.item && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
655
- "button",
656
- {
657
- type: "button",
658
- className: "button-outline",
659
- onClick: () => {
660
- form.delete();
661
- },
662
- children: "\uC0AD\uC81C\uD558\uAE30"
663
- }
664
- ),
665
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
666
- "button",
667
- {
668
- type: "button",
669
- className: "button-primary",
670
- onClick: form.submit,
671
- children: "\uC800\uC7A5\uD558\uAE30"
672
- }
673
- )
674
- ] })
675
- }
676
- ),
677
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "max-w-2xl mx-auto", children: Object.keys(form.columns).length > 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: Object.entries(form.columns).map(
678
- ([name, value]) => {
679
- function InputComponent() {
680
- if (value.component) {
681
- const Component = value.component;
682
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Component, { store: form.store, name });
683
- }
684
- if (value.type === "textarea") {
685
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
686
- StoreTextEditor,
687
- {
688
- store: form.store,
689
- name,
690
- editor: {
691
- attributes: {
692
- class: "text-editor-form"
693
- }
694
- }
695
- }
696
- );
697
- }
698
- if (value.options) {
699
- const Component = value.options;
700
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(component.select, { name, className: "select-form", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Component, {}) });
701
- }
702
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
703
- component.input,
704
- {
705
- name,
706
- type: value.type,
707
- className: "input-form"
708
- }
709
- );
710
- }
711
- const v = form.store.state[name];
712
- if (typeof v === "boolean") {
713
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex", children: [
714
- value.label,
715
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "ml-auto", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(InputComponent, {}) })
716
- ] });
717
- }
718
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(FormRow, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(FormEntry, { children: [
719
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(FormLabel, { children: value.label }, name),
720
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(InputComponent, {})
721
- ] }) }, name);
722
- }
723
- ) }) })
724
- ] });
725
- }
726
-
727
- // src/crud/crud_page.tsx
728
- var import_jsx_runtime11 = require("react/jsx-runtime");
729
- function crudPage({
730
- name,
731
- primaryKey,
732
- tablePageOptions,
733
- formOptions,
734
- header
735
- }) {
736
- const create = (prefix) => {
737
- return function Page() {
738
- const data = (0, import_react_router9.useLoaderData)();
739
- const { pathname } = (0, import_react_router9.useLocation)();
740
- if (pathname === prefix) {
741
- const Component = createTablePage({
742
- ...tablePageOptions,
743
- name
744
- });
745
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Component, { header });
746
- }
747
- if (pathname.startsWith(prefix)) {
748
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
749
- CrudFormProvider,
750
- {
751
- item: data?.item,
752
- prefix,
753
- name,
754
- columns: formOptions.columns,
755
- primaryKey,
756
- children: formOptions.form ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FormDelegate, { component: formOptions.form }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(CrudForm, { AdminHeader: header })
757
- }
758
- );
759
- }
760
- };
761
- };
762
- return {
763
- name,
764
- create
765
- };
766
- }
767
- function FormDelegate({
768
- component: Component
769
- }) {
770
- const form = useFormContext();
771
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Component, { form });
772
- }
773
- // Annotate the CommonJS export names for ESM import in node:
774
- 0 && (module.exports = {
775
- crudPage
776
- });