dn-react-router-toolkit 0.5.8 → 0.6.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/auth/cookie_store.d.mts +1 -1
  2. package/dist/auth/cookie_store.d.ts +1 -1
  3. package/dist/auth/cookie_store.js +4 -4
  4. package/dist/auth/cookie_store.mjs +4 -4
  5. package/dist/auth/index.js +4 -4
  6. package/dist/auth/index.mjs +4 -4
  7. package/dist/client/env_loader.d.mts +2 -2
  8. package/dist/client/env_loader.d.ts +2 -2
  9. package/dist/client/file_input.d.mts +10 -0
  10. package/dist/client/file_input.d.ts +10 -0
  11. package/dist/client/file_input.js +80 -0
  12. package/dist/client/file_input.mjs +45 -0
  13. package/dist/client/index.d.mts +4 -0
  14. package/dist/client/index.d.ts +4 -0
  15. package/dist/client/index.js +104 -0
  16. package/dist/client/index.mjs +102 -0
  17. package/dist/client/store_text_editor.d.mts +13 -0
  18. package/dist/client/store_text_editor.d.ts +13 -0
  19. package/dist/client/store_text_editor.js +94 -0
  20. package/dist/client/store_text_editor.mjs +59 -0
  21. package/dist/crud/crud_form.d.mts +4 -6
  22. package/dist/crud/crud_form.d.ts +4 -6
  23. package/dist/crud/crud_form.js +147 -100
  24. package/dist/crud/crud_form.mjs +148 -106
  25. package/dist/crud/crud_form_provider.d.mts +10 -10
  26. package/dist/crud/crud_form_provider.d.ts +10 -10
  27. package/dist/crud/crud_form_provider.js +5 -6
  28. package/dist/crud/crud_form_provider.mjs +4 -5
  29. package/dist/crud/crud_page.d.mts +8 -8
  30. package/dist/crud/crud_page.d.ts +8 -8
  31. package/dist/crud/crud_page.js +203 -160
  32. package/dist/crud/crud_page.mjs +200 -162
  33. package/dist/crud/generate_pages.d.mts +3 -3
  34. package/dist/crud/generate_pages.d.ts +3 -3
  35. package/dist/crud/index.d.mts +1 -1
  36. package/dist/crud/index.d.ts +1 -1
  37. package/dist/crud/index.js +256 -213
  38. package/dist/crud/index.mjs +240 -202
  39. package/dist/form/create_form_component.d.mts +28 -0
  40. package/dist/form/create_form_component.d.ts +28 -0
  41. package/dist/form/create_form_component.js +47 -0
  42. package/dist/form/create_form_component.mjs +12 -0
  43. package/dist/form/form_components.d.mts +7 -0
  44. package/dist/form/form_components.d.ts +7 -0
  45. package/dist/form/form_components.js +64 -0
  46. package/dist/form/form_components.mjs +25 -0
  47. package/dist/form/index.d.mts +3 -0
  48. package/dist/form/index.d.ts +3 -0
  49. package/dist/form/index.js +66 -0
  50. package/dist/form/index.mjs +26 -0
  51. package/dist/post/index.d.mts +2 -0
  52. package/dist/post/index.d.ts +2 -0
  53. package/dist/post/index.js +33 -0
  54. package/dist/post/index.mjs +4 -0
  55. package/dist/post/thumbnail_picker.d.mts +18 -0
  56. package/dist/post/thumbnail_picker.d.ts +18 -0
  57. package/dist/post/thumbnail_picker.js +101 -0
  58. package/dist/post/thumbnail_picker.mjs +70 -0
  59. package/dist/seo/seo.d.mts +2 -2
  60. package/dist/seo/seo.d.ts +2 -2
  61. package/dist/table/buttons.d.mts +2 -2
  62. package/dist/table/buttons.d.ts +2 -2
  63. package/dist/table/index.js +44 -47
  64. package/dist/table/index.mjs +44 -47
  65. package/dist/table/page.d.mts +5 -7
  66. package/dist/table/page.d.ts +5 -7
  67. package/dist/table/page.js +44 -47
  68. package/dist/table/page.mjs +44 -47
  69. package/dist/table/table.d.mts +4 -4
  70. package/dist/table/table.d.ts +4 -4
  71. package/package.json +14 -2
@@ -3,7 +3,7 @@ import { useLoaderData as useLoaderData2, useLocation as useLocation3 } from "re
3
3
 
4
4
  // src/crud/crud_form_provider.tsx
5
5
  import { useNavigate } from "react-router";
6
- import { useStore } from "dn-react-toolkit/store";
6
+ import { useStore } from "react-store-input";
7
7
  import { createContext, useContext } from "react";
8
8
  import React from "react";
9
9
  var FormContext = createContext({});
@@ -69,10 +69,9 @@ function CrudFormProvider({
69
69
  return value2.map((v) => converter(v));
70
70
  }
71
71
  if (typeof value2 === "object") {
72
- return Object.entries(value2).reduce(
73
- reducer,
74
- {}
75
- );
72
+ return Object.entries(
73
+ value2
74
+ ).reduce(reducer, {});
76
75
  }
77
76
  };
78
77
  return {
@@ -459,7 +458,7 @@ function createTablePage({
459
458
  primaryKey = "id"
460
459
  }) {
461
460
  return function TablePage({
462
- AdminLayout
461
+ AdminHeader
463
462
  }) {
464
463
  const { pathname } = useLocation2();
465
464
  const { table } = useLoaderData();
@@ -472,189 +471,228 @@ function createTablePage({
472
471
  navigate(`${pathname}?${searchParams2.toString()}`);
473
472
  };
474
473
  const [searchParams] = useSearchParams3();
475
- return /* @__PURE__ */ React6.createElement(
476
- AdminLayout,
474
+ return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(
475
+ AdminHeader,
477
476
  {
478
477
  title: name,
479
478
  actions: /* @__PURE__ */ React6.createElement(Link3, { to: `${pathname}/new`, className: "button-primary" }, name, " \uCD94\uAC00")
479
+ }
480
+ ), /* @__PURE__ */ React6.createElement("div", { className: "max-w-7xl mx-auto" }, searchKey && /* @__PURE__ */ React6.createElement(
481
+ "form",
482
+ {
483
+ className: "h-18 px-4 flex items-center border-t",
484
+ onSubmit: (e) => {
485
+ e.preventDefault();
486
+ const formData = new FormData(e.currentTarget);
487
+ const query = formData.get("query");
488
+ search(query);
489
+ }
480
490
  },
481
- searchKey && /* @__PURE__ */ React6.createElement(
482
- "form",
483
- {
484
- className: "h-18 px-4 flex items-center border-t",
485
- onSubmit: (e) => {
486
- e.preventDefault();
487
- const formData = new FormData(e.currentTarget);
488
- const query = formData.get("query");
489
- search(query);
490
- }
491
- },
492
- /* @__PURE__ */ React6.createElement(
493
- "button",
494
- {
495
- type: "submit",
496
- className: "w-10 h-10 flex justify-center items-center"
497
- },
498
- /* @__PURE__ */ React6.createElement(GoSearch, { className: "text-xl mr-4" })
499
- ),
500
- /* @__PURE__ */ React6.createElement(
501
- "input",
502
- {
503
- className: "outline-none h-full flex-1",
504
- placeholder: "\uC5EC\uAE30\uC5D0 \uAC80\uC0C9\uD558\uC138\uC694...",
505
- name: "query",
506
- defaultValue: searchParams.get("query") ?? ""
507
- }
508
- )
509
- ),
510
491
  /* @__PURE__ */ React6.createElement(
511
- Table,
492
+ "button",
512
493
  {
513
- data: items,
514
- columns,
515
- getLink: primaryKey ? (item) => `${pathname}/${item[primaryKey]}` : void 0,
516
- limit,
517
- offset,
518
- orderBy,
519
- direction
520
- }
494
+ type: "submit",
495
+ className: "w-10 h-10 flex justify-center items-center"
496
+ },
497
+ /* @__PURE__ */ React6.createElement(GoSearch, { className: "text-xl mr-4" })
521
498
  ),
522
499
  /* @__PURE__ */ React6.createElement(
523
- TablePageButtons,
500
+ "input",
524
501
  {
525
- total,
526
- limit,
527
- offset,
528
- MAX_PAGES_TO_SHOW: 10
502
+ className: "outline-none h-full flex-1",
503
+ placeholder: "\uC5EC\uAE30\uC5D0 \uAC80\uC0C9\uD558\uC138\uC694...",
504
+ name: "query",
505
+ defaultValue: searchParams.get("query") ?? ""
529
506
  }
530
507
  )
531
- );
508
+ ), /* @__PURE__ */ React6.createElement(
509
+ Table,
510
+ {
511
+ data: items,
512
+ columns,
513
+ getLink: primaryKey ? (item) => `${pathname}/${item[primaryKey]}` : void 0,
514
+ limit,
515
+ offset,
516
+ orderBy,
517
+ direction
518
+ }
519
+ ), /* @__PURE__ */ React6.createElement(
520
+ TablePageButtons,
521
+ {
522
+ total,
523
+ limit,
524
+ offset,
525
+ MAX_PAGES_TO_SHOW: 10
526
+ }
527
+ )));
532
528
  };
533
529
  }
534
530
 
535
531
  // src/crud/crud_form.tsx
536
- import {
537
- SyncInput,
538
- SyncSelect,
539
- SyncSwitch,
540
- useSyncTextEditor
541
- } from "dn-react-toolkit/store";
532
+ import React11 from "react";
533
+ import { createTextEditor } from "dn-react-text-editor";
534
+ import { Input, Select } from "react-store-input";
535
+
536
+ // src/client/env_loader.tsx
542
537
  import React7 from "react";
543
- import { moment } from "dn-react-toolkit/utils";
544
- import { createTextEditor } from "dn-react-toolkit/text_editor";
545
- var textarea = createTextEditor();
546
- function CrudForm({ AdminLayout }) {
538
+ import { useRouteLoaderData } from "react-router";
539
+
540
+ // src/client/file_input.tsx
541
+ import "react";
542
+ import React8 from "react";
543
+
544
+ // src/client/use_user_agent.tsx
545
+ import { useRouteLoaderData as useRouteLoaderData2 } from "react-router";
546
+
547
+ // src/client/store_text_editor.tsx
548
+ import "dn-react-text-editor";
549
+ import { useStoreController } from "react-store-input";
550
+ import React9 from "react";
551
+ function createStoreTextEditor(TextEditor2) {
552
+ function StoreComponent({
553
+ store,
554
+ name,
555
+ defaultValue,
556
+ ...props
557
+ }) {
558
+ const { ref, onChange } = useStoreController(
559
+ store,
560
+ {
561
+ ref: props.ref,
562
+ onSubscribe: (state, element) => {
563
+ const result = (props.getter ? props.getter(state) : name ? state[name] : "") || "";
564
+ if (element.value !== result) {
565
+ element.value = result;
566
+ }
567
+ },
568
+ onDispatch: (state, element) => {
569
+ if (props.setter) {
570
+ props.setter(state, element.value);
571
+ return;
572
+ }
573
+ if (name) {
574
+ state[name] = element.value;
575
+ }
576
+ }
577
+ }
578
+ );
579
+ const getDefaultValue = () => {
580
+ if (props.getter) {
581
+ return props.getter(store.state);
582
+ }
583
+ if (name) {
584
+ return store.state[name];
585
+ }
586
+ return void 0;
587
+ };
588
+ return /* @__PURE__ */ React9.createElement(
589
+ TextEditor2,
590
+ {
591
+ ...props,
592
+ ref,
593
+ defaultValue: defaultValue ?? getDefaultValue(),
594
+ onChange: (e) => {
595
+ onChange();
596
+ props.onChange?.(e);
597
+ }
598
+ }
599
+ );
600
+ }
601
+ return StoreComponent;
602
+ }
603
+
604
+ // src/form/create_form_component.tsx
605
+ import { cn as cn3 } from "dn-react-toolkit/utils";
606
+ import React10 from "react";
607
+ function createComponent(tag, options) {
608
+ return function FormComponent({ className, ...props }) {
609
+ const Tag = tag;
610
+ return /* @__PURE__ */ React10.createElement(Tag, { ...props, className: cn3(options.className, className) });
611
+ };
612
+ }
613
+
614
+ // src/form/form_components.tsx
615
+ var FormEntry = createComponent("div", {
616
+ className: "flex-1"
617
+ });
618
+ var FormRow = createComponent("div", {
619
+ className: "flex-1 flex gap-4 mb-6"
620
+ });
621
+ var FormLabel = createComponent("label", {
622
+ className: "flex-1 font-semibold mb-2.5 block"
623
+ });
624
+
625
+ // src/crud/crud_form.tsx
626
+ var TextEditor = createStoreTextEditor(createTextEditor());
627
+ function CrudForm({ AdminHeader }) {
547
628
  const form = useFormContext();
548
- return /* @__PURE__ */ React7.createElement(
549
- AdminLayout,
629
+ return /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement(
630
+ AdminHeader,
550
631
  {
551
632
  title: `${form.name} ${form.item ? "\uC218\uC815" : "\uCD94\uAC00"}`,
552
- actions: /* @__PURE__ */ React7.createElement("button", { type: "button", className: "button-primary", onClick: form.submit }, "\uC800\uC7A5\uD558\uAE30"),
553
- className: "max-w-3xl mx-auto"
554
- },
555
- Object.keys(form.columns).length > 0 && /* @__PURE__ */ React7.createElement(React7.Fragment, null, Object.entries(
556
- form.columns
557
- ).map(([key, value]) => {
558
- const createComponent = () => {
559
- if (value.component) {
560
- return /* @__PURE__ */ React7.createElement(value.component, { store: form.store, property: key });
561
- }
562
- if (value.type === "checkbox") {
563
- return /* @__PURE__ */ React7.createElement(SyncSwitch, { store: form.store, property: key });
564
- }
565
- if (value.type === "number") {
566
- return /* @__PURE__ */ React7.createElement(
567
- SyncInput,
568
- {
569
- store: form.store,
570
- property: key,
571
- className: "input-form",
572
- type: "number",
573
- serializer: (value2) => {
574
- if (value2 === void 0 || value2 === null) {
575
- return "";
576
- }
577
- return String(value2);
578
- },
579
- deserializer: (value2) => {
580
- const parsed = Number(value2);
581
- if (isNaN(parsed)) {
582
- return void 0;
583
- }
584
- return parsed;
585
- }
586
- }
587
- );
588
- }
589
- if (value.type === "datetime") {
590
- return /* @__PURE__ */ React7.createElement(
591
- SyncInput,
592
- {
593
- store: form.store,
594
- property: key,
595
- className: "input-form",
596
- type: "datetime-local",
597
- serializer: (value2) => {
598
- if (value2 instanceof Date) {
599
- return moment(value2).toISOString(true).slice(0, 16);
600
- }
601
- return String(value2);
602
- },
603
- deserializer: (value2) => {
604
- if (!value2) {
605
- return void 0;
606
- }
607
- return moment(value2).toDate();
608
- }
609
- }
610
- );
611
- }
612
- if (value.type === "textarea") {
613
- const Editor = useSyncTextEditor(textarea);
614
- return /* @__PURE__ */ React7.createElement(
615
- Editor.SyncTextEditor,
616
- {
617
- store: form.store,
618
- property: key
619
- }
620
- );
621
- }
622
- if (value.options) {
623
- const Component = value.options;
624
- return /* @__PURE__ */ React7.createElement(SyncSelect, { store: form.store, property: key }, /* @__PURE__ */ React7.createElement(Component, null));
625
- }
626
- return /* @__PURE__ */ React7.createElement(
627
- SyncInput,
633
+ actions: /* @__PURE__ */ React11.createElement(
634
+ "button",
635
+ {
636
+ type: "button",
637
+ className: "button-primary",
638
+ onClick: form.submit
639
+ },
640
+ "\uC800\uC7A5\uD558\uAE30"
641
+ )
642
+ }
643
+ ), /* @__PURE__ */ React11.createElement("div", { className: "max-w-2xl mx-auto" }, Object.keys(form.columns).length > 0 && /* @__PURE__ */ React11.createElement(React11.Fragment, null, Object.entries(
644
+ form.columns
645
+ ).map(([key, value]) => {
646
+ function InputComponent() {
647
+ if (value.type === "textarea") {
648
+ return /* @__PURE__ */ React11.createElement(TextEditor, { store: form.store, name: key });
649
+ }
650
+ if (value.options) {
651
+ const Component = value.options;
652
+ return /* @__PURE__ */ React11.createElement(
653
+ Select,
628
654
  {
629
655
  store: form.store,
630
- property: key,
631
- type: value.type,
632
- className: "input-form"
633
- }
656
+ name: key,
657
+ className: "select-form"
658
+ },
659
+ /* @__PURE__ */ React11.createElement(Component, null)
634
660
  );
635
- };
636
- return /* @__PURE__ */ React7.createElement("label", { key }, value.label, createComponent());
637
- })),
638
- form.item && /* @__PURE__ */ React7.createElement(
639
- "button",
640
- {
641
- className: "button-dangerous mt-8",
642
- onClick: () => {
643
- form.delete();
661
+ }
662
+ return /* @__PURE__ */ React11.createElement(
663
+ Input,
664
+ {
665
+ store: form.store,
666
+ name: key,
667
+ type: value.type,
668
+ className: "input-form"
644
669
  }
645
- },
646
- "\uC0AD\uC81C\uD558\uAE30"
647
- )
648
- );
670
+ );
671
+ }
672
+ const v = form.store.state[key];
673
+ if (typeof v === "boolean") {
674
+ return /* @__PURE__ */ React11.createElement("div", { className: "flex" }, value.label, /* @__PURE__ */ React11.createElement("div", { className: "ml-auto" }, /* @__PURE__ */ React11.createElement(InputComponent, null)));
675
+ }
676
+ return /* @__PURE__ */ React11.createElement(FormRow, null, /* @__PURE__ */ React11.createElement(FormEntry, null, /* @__PURE__ */ React11.createElement(FormLabel, { key }, value.label), /* @__PURE__ */ React11.createElement(InputComponent, null)));
677
+ })), form.item && /* @__PURE__ */ React11.createElement(
678
+ "button",
679
+ {
680
+ className: "button-dangerous mt-8",
681
+ onClick: () => {
682
+ form.delete();
683
+ }
684
+ },
685
+ "\uC0AD\uC81C\uD558\uAE30"
686
+ )));
649
687
  }
650
688
 
651
689
  // src/crud/crud_page.tsx
652
- import React8 from "react";
690
+ import React12 from "react";
653
691
  function crudPage({
654
692
  name,
655
693
  tablePageOptions,
656
694
  formOptions,
657
- AdminLayout
695
+ AdminHeader
658
696
  }) {
659
697
  return (prefix) => {
660
698
  return function Page() {
@@ -665,10 +703,10 @@ function crudPage({
665
703
  ...tablePageOptions,
666
704
  name
667
705
  });
668
- return /* @__PURE__ */ React8.createElement(Component, { AdminLayout });
706
+ return /* @__PURE__ */ React12.createElement(Component, { AdminHeader });
669
707
  }
670
708
  if (pathname.startsWith(prefix)) {
671
- return /* @__PURE__ */ React8.createElement(
709
+ return /* @__PURE__ */ React12.createElement(
672
710
  CrudFormProvider,
673
711
  {
674
712
  item: data?.item,
@@ -676,7 +714,7 @@ function crudPage({
676
714
  name,
677
715
  columns: formOptions.columns
678
716
  },
679
- formOptions.form ? /* @__PURE__ */ React8.createElement(formOptions.form, null) : /* @__PURE__ */ React8.createElement(CrudForm, { AdminLayout })
717
+ formOptions.form ? /* @__PURE__ */ React12.createElement(formOptions.form, null) : /* @__PURE__ */ React12.createElement(CrudForm, { AdminHeader })
680
718
  );
681
719
  }
682
720
  };
@@ -1,10 +1,10 @@
1
1
  import { CrudPage } from './crud_page.mjs';
2
- import React from 'react';
2
+ import React__default from 'react';
3
3
  import './crud_form_provider.mjs';
4
- import 'dn-react-toolkit/store';
4
+ import 'react-store-input';
5
5
  import '../table/page.mjs';
6
6
  import '../table/table.mjs';
7
7
 
8
- declare const generatePages: (pages: Record<string, CrudPage>) => () => React.JSX.Element | undefined;
8
+ declare const generatePages: (pages: Record<string, CrudPage>) => () => React__default.JSX.Element | undefined;
9
9
 
10
10
  export { generatePages };
@@ -1,10 +1,10 @@
1
1
  import { CrudPage } from './crud_page.js';
2
- import React from 'react';
2
+ import React__default from 'react';
3
3
  import './crud_form_provider.js';
4
- import 'dn-react-toolkit/store';
4
+ import 'react-store-input';
5
5
  import '../table/page.js';
6
6
  import '../table/table.js';
7
7
 
8
- declare const generatePages: (pages: Record<string, CrudPage>) => () => React.JSX.Element | undefined;
8
+ declare const generatePages: (pages: Record<string, CrudPage>) => () => React__default.JSX.Element | undefined;
9
9
 
10
10
  export { generatePages };
@@ -4,7 +4,7 @@ export { CrudPage, CrudPageOptions, crudPage } from './crud_page.mjs';
4
4
  export { generateHandlers } from './generate_handlers.mjs';
5
5
  export { generatePages } from './generate_pages.mjs';
6
6
  export { generateCrudRoutes } from './generate_routes.mjs';
7
- import 'dn-react-toolkit/store';
7
+ import 'react-store-input';
8
8
  import 'react';
9
9
  import 'react-router';
10
10
  import '../table/loader.mjs';
@@ -4,7 +4,7 @@ export { CrudPage, CrudPageOptions, crudPage } from './crud_page.js';
4
4
  export { generateHandlers } from './generate_handlers.js';
5
5
  export { generatePages } from './generate_pages.js';
6
6
  export { generateCrudRoutes } from './generate_routes.js';
7
- import 'dn-react-toolkit/store';
7
+ import 'react-store-input';
8
8
  import 'react';
9
9
  import 'react-router';
10
10
  import '../table/loader.js';