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