dn-react-router-toolkit 0.5.2 → 0.5.4
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.
- package/dist/crud/crud_form.js +50 -18
- package/dist/crud/crud_form.mjs +51 -19
- package/dist/crud/crud_form_provider.d.mts +10 -6
- package/dist/crud/crud_form_provider.d.ts +10 -6
- package/dist/crud/crud_form_provider.js +50 -52
- package/dist/crud/crud_form_provider.mjs +50 -52
- package/dist/crud/crud_loader.d.mts +8 -4
- package/dist/crud/crud_loader.d.ts +8 -4
- package/dist/crud/crud_loader.js +28 -14
- package/dist/crud/crud_loader.mjs +28 -14
- package/dist/crud/crud_page.d.mts +0 -1
- package/dist/crud/crud_page.d.ts +0 -1
- package/dist/crud/crud_page.js +100 -70
- package/dist/crud/crud_page.mjs +101 -71
- package/dist/crud/generate_pages.d.mts +0 -1
- package/dist/crud/generate_pages.d.ts +0 -1
- package/dist/crud/index.d.mts +1 -1
- package/dist/crud/index.d.ts +1 -1
- package/dist/crud/index.js +134 -90
- package/dist/crud/index.mjs +129 -85
- package/dist/table/index.js +4 -12
- package/dist/table/index.mjs +4 -12
- package/dist/table/item_loader.d.mts +3 -2
- package/dist/table/item_loader.d.ts +3 -2
- package/dist/table/item_loader.js +4 -12
- package/dist/table/item_loader.mjs +4 -12
- package/package.json +75 -75
package/dist/crud/crud_form.js
CHANGED
|
@@ -47,33 +47,65 @@ function useFormContext() {
|
|
|
47
47
|
// src/crud/crud_form.tsx
|
|
48
48
|
var import_store2 = require("dn-react-toolkit/store");
|
|
49
49
|
var import_react3 = __toESM(require("react"));
|
|
50
|
+
var import_utils = require("dn-react-toolkit/utils");
|
|
50
51
|
function CrudForm({ AdminLayout }) {
|
|
51
52
|
const form = useFormContext();
|
|
52
53
|
return /* @__PURE__ */ import_react3.default.createElement(
|
|
53
54
|
AdminLayout,
|
|
54
55
|
{
|
|
55
56
|
title: `${form.name} ${form.item ? "\uC218\uC815" : "\uCD94\uAC00"}`,
|
|
56
|
-
actions: /* @__PURE__ */ import_react3.default.createElement(
|
|
57
|
-
"button",
|
|
58
|
-
{
|
|
59
|
-
type: "button",
|
|
60
|
-
className: "button-primary",
|
|
61
|
-
onClick: form.submit
|
|
62
|
-
},
|
|
63
|
-
"\uC800\uC7A5\uD558\uAE30"
|
|
64
|
-
),
|
|
57
|
+
actions: /* @__PURE__ */ import_react3.default.createElement("button", { type: "button", className: "button-primary", onClick: form.submit }, "\uC800\uC7A5\uD558\uAE30"),
|
|
65
58
|
className: "max-w-3xl mx-auto"
|
|
66
59
|
},
|
|
67
|
-
Object.keys(form.columns).length > 0 && /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, Object.entries(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
property: key
|
|
73
|
-
className: "input-form"
|
|
60
|
+
Object.keys(form.columns).length > 0 && /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, Object.entries(
|
|
61
|
+
form.columns
|
|
62
|
+
).map(([key, value]) => {
|
|
63
|
+
const createComponent = () => {
|
|
64
|
+
if (value.component) {
|
|
65
|
+
return /* @__PURE__ */ import_react3.default.createElement(value.component, { store: form.store, property: key });
|
|
74
66
|
}
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
if (value.type === "checkbox") {
|
|
68
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_store2.SyncSwitch, { store: form.store, property: key });
|
|
69
|
+
}
|
|
70
|
+
if (value.type === "datetime") {
|
|
71
|
+
return /* @__PURE__ */ import_react3.default.createElement(
|
|
72
|
+
import_store2.SyncInput,
|
|
73
|
+
{
|
|
74
|
+
store: form.store,
|
|
75
|
+
property: key,
|
|
76
|
+
className: "input-form",
|
|
77
|
+
type: "datetime-local",
|
|
78
|
+
serializer: (value2) => {
|
|
79
|
+
if (value2 instanceof Date) {
|
|
80
|
+
return (0, import_utils.moment)(value2).toISOString(true).slice(0, 16);
|
|
81
|
+
}
|
|
82
|
+
return String(value2);
|
|
83
|
+
},
|
|
84
|
+
deserializer: (value2) => {
|
|
85
|
+
if (!value2) {
|
|
86
|
+
return void 0;
|
|
87
|
+
}
|
|
88
|
+
return (0, import_utils.moment)(value2).toDate();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
if (value.options) {
|
|
94
|
+
const Component = value.options;
|
|
95
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_store2.SyncSelect, { store: form.store, property: key }, /* @__PURE__ */ import_react3.default.createElement(Component, null));
|
|
96
|
+
}
|
|
97
|
+
return /* @__PURE__ */ import_react3.default.createElement(
|
|
98
|
+
import_store2.SyncInput,
|
|
99
|
+
{
|
|
100
|
+
store: form.store,
|
|
101
|
+
property: key,
|
|
102
|
+
type: value.type,
|
|
103
|
+
className: "input-form"
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
return /* @__PURE__ */ import_react3.default.createElement("label", { key }, value.label, createComponent());
|
|
108
|
+
})),
|
|
77
109
|
form.item && /* @__PURE__ */ import_react3.default.createElement(
|
|
78
110
|
"button",
|
|
79
111
|
{
|
package/dist/crud/crud_form.mjs
CHANGED
|
@@ -9,35 +9,67 @@ function useFormContext() {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
// src/crud/crud_form.tsx
|
|
12
|
-
import { SyncInput } from "dn-react-toolkit/store";
|
|
12
|
+
import { SyncInput, SyncSelect, SyncSwitch } from "dn-react-toolkit/store";
|
|
13
13
|
import React2 from "react";
|
|
14
|
+
import { moment } from "dn-react-toolkit/utils";
|
|
14
15
|
function CrudForm({ AdminLayout }) {
|
|
15
16
|
const form = useFormContext();
|
|
16
17
|
return /* @__PURE__ */ React2.createElement(
|
|
17
18
|
AdminLayout,
|
|
18
19
|
{
|
|
19
20
|
title: `${form.name} ${form.item ? "\uC218\uC815" : "\uCD94\uAC00"}`,
|
|
20
|
-
actions: /* @__PURE__ */ React2.createElement(
|
|
21
|
-
"button",
|
|
22
|
-
{
|
|
23
|
-
type: "button",
|
|
24
|
-
className: "button-primary",
|
|
25
|
-
onClick: form.submit
|
|
26
|
-
},
|
|
27
|
-
"\uC800\uC7A5\uD558\uAE30"
|
|
28
|
-
),
|
|
21
|
+
actions: /* @__PURE__ */ React2.createElement("button", { type: "button", className: "button-primary", onClick: form.submit }, "\uC800\uC7A5\uD558\uAE30"),
|
|
29
22
|
className: "max-w-3xl mx-auto"
|
|
30
23
|
},
|
|
31
|
-
Object.keys(form.columns).length > 0 && /* @__PURE__ */ React2.createElement(React2.Fragment, null, Object.entries(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
property: key
|
|
37
|
-
className: "input-form"
|
|
24
|
+
Object.keys(form.columns).length > 0 && /* @__PURE__ */ React2.createElement(React2.Fragment, null, Object.entries(
|
|
25
|
+
form.columns
|
|
26
|
+
).map(([key, value]) => {
|
|
27
|
+
const createComponent = () => {
|
|
28
|
+
if (value.component) {
|
|
29
|
+
return /* @__PURE__ */ React2.createElement(value.component, { store: form.store, property: key });
|
|
38
30
|
}
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
if (value.type === "checkbox") {
|
|
32
|
+
return /* @__PURE__ */ React2.createElement(SyncSwitch, { store: form.store, property: key });
|
|
33
|
+
}
|
|
34
|
+
if (value.type === "datetime") {
|
|
35
|
+
return /* @__PURE__ */ React2.createElement(
|
|
36
|
+
SyncInput,
|
|
37
|
+
{
|
|
38
|
+
store: form.store,
|
|
39
|
+
property: key,
|
|
40
|
+
className: "input-form",
|
|
41
|
+
type: "datetime-local",
|
|
42
|
+
serializer: (value2) => {
|
|
43
|
+
if (value2 instanceof Date) {
|
|
44
|
+
return moment(value2).toISOString(true).slice(0, 16);
|
|
45
|
+
}
|
|
46
|
+
return String(value2);
|
|
47
|
+
},
|
|
48
|
+
deserializer: (value2) => {
|
|
49
|
+
if (!value2) {
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
return moment(value2).toDate();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
if (value.options) {
|
|
58
|
+
const Component = value.options;
|
|
59
|
+
return /* @__PURE__ */ React2.createElement(SyncSelect, { store: form.store, property: key }, /* @__PURE__ */ React2.createElement(Component, null));
|
|
60
|
+
}
|
|
61
|
+
return /* @__PURE__ */ React2.createElement(
|
|
62
|
+
SyncInput,
|
|
63
|
+
{
|
|
64
|
+
store: form.store,
|
|
65
|
+
property: key,
|
|
66
|
+
type: value.type,
|
|
67
|
+
className: "input-form"
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
return /* @__PURE__ */ React2.createElement("label", { key }, value.label, createComponent());
|
|
72
|
+
})),
|
|
41
73
|
form.item && /* @__PURE__ */ React2.createElement(
|
|
42
74
|
"button",
|
|
43
75
|
{
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { RxStore } from 'dn-react-toolkit/store';
|
|
2
|
-
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
3
2
|
import React from 'react';
|
|
4
3
|
|
|
5
4
|
type FormState<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof TModel ? "id" : never> = Omit<TModel, TPrimaryKey> & {
|
|
6
5
|
[K in TPrimaryKey]?: TModel[K];
|
|
7
6
|
};
|
|
8
|
-
type FormColumnValue = {
|
|
7
|
+
type FormColumnValue<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof TModel ? "id" : never> = {
|
|
9
8
|
label: string;
|
|
10
|
-
|
|
9
|
+
type?: React.HTMLInputTypeAttribute;
|
|
10
|
+
component?: React.FC<{
|
|
11
|
+
store: RxStore<FormState<TModel, TPrimaryKey>>;
|
|
12
|
+
property: string;
|
|
13
|
+
}>;
|
|
14
|
+
options?: React.FC;
|
|
11
15
|
};
|
|
12
|
-
type FormColumns<
|
|
13
|
-
[K in
|
|
16
|
+
type FormColumns<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof TModel ? "id" : never> = Partial<{
|
|
17
|
+
[K in keyof TModel]: FormColumnValue<TModel, TPrimaryKey>;
|
|
14
18
|
}>;
|
|
15
19
|
declare const FormContext: React.Context<{}>;
|
|
16
20
|
declare function useFormContext<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof TModel ? "id" : never>(): {
|
|
@@ -26,7 +30,7 @@ type CrudFormProps<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof
|
|
|
26
30
|
name: string;
|
|
27
31
|
prefix: string;
|
|
28
32
|
item?: TModel;
|
|
29
|
-
columns?: FormColumns<TModel>;
|
|
33
|
+
columns?: FormColumns<TModel, TPrimaryKey>;
|
|
30
34
|
children?: React.ReactNode;
|
|
31
35
|
};
|
|
32
36
|
declare function CrudFormProvider<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof TModel ? "id" : never>({ primaryKey, name, prefix, item, columns, children, }: CrudFormProps<TModel, TPrimaryKey>): React.JSX.Element;
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { RxStore } from 'dn-react-toolkit/store';
|
|
2
|
-
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
3
2
|
import React from 'react';
|
|
4
3
|
|
|
5
4
|
type FormState<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof TModel ? "id" : never> = Omit<TModel, TPrimaryKey> & {
|
|
6
5
|
[K in TPrimaryKey]?: TModel[K];
|
|
7
6
|
};
|
|
8
|
-
type FormColumnValue = {
|
|
7
|
+
type FormColumnValue<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof TModel ? "id" : never> = {
|
|
9
8
|
label: string;
|
|
10
|
-
|
|
9
|
+
type?: React.HTMLInputTypeAttribute;
|
|
10
|
+
component?: React.FC<{
|
|
11
|
+
store: RxStore<FormState<TModel, TPrimaryKey>>;
|
|
12
|
+
property: string;
|
|
13
|
+
}>;
|
|
14
|
+
options?: React.FC;
|
|
11
15
|
};
|
|
12
|
-
type FormColumns<
|
|
13
|
-
[K in
|
|
16
|
+
type FormColumns<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof TModel ? "id" : never> = Partial<{
|
|
17
|
+
[K in keyof TModel]: FormColumnValue<TModel, TPrimaryKey>;
|
|
14
18
|
}>;
|
|
15
19
|
declare const FormContext: React.Context<{}>;
|
|
16
20
|
declare function useFormContext<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof TModel ? "id" : never>(): {
|
|
@@ -26,7 +30,7 @@ type CrudFormProps<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof
|
|
|
26
30
|
name: string;
|
|
27
31
|
prefix: string;
|
|
28
32
|
item?: TModel;
|
|
29
|
-
columns?: FormColumns<TModel>;
|
|
33
|
+
columns?: FormColumns<TModel, TPrimaryKey>;
|
|
30
34
|
children?: React.ReactNode;
|
|
31
35
|
};
|
|
32
36
|
declare function CrudFormProvider<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof TModel ? "id" : never>({ primaryKey, name, prefix, item, columns, children, }: CrudFormProps<TModel, TPrimaryKey>): React.JSX.Element;
|
|
@@ -63,58 +63,56 @@ function CrudFormProvider({
|
|
|
63
63
|
"Content-Type": "application/json"
|
|
64
64
|
},
|
|
65
65
|
body: JSON.stringify(
|
|
66
|
-
Object.entries(store.state).reduce(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
{}
|
|
117
|
-
)
|
|
66
|
+
Object.entries(store.state).reduce(function reducer(acc, [key, value]) {
|
|
67
|
+
const converter = (value2) => {
|
|
68
|
+
if (value2 === void 0) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
if (value2 === null) {
|
|
72
|
+
return {
|
|
73
|
+
type: "null",
|
|
74
|
+
value: null
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (typeof value2 === "string") {
|
|
78
|
+
return {
|
|
79
|
+
type: "string",
|
|
80
|
+
value: value2
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (typeof value2 === "number") {
|
|
84
|
+
return {
|
|
85
|
+
type: "number",
|
|
86
|
+
value: value2
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (typeof value2 === "boolean") {
|
|
90
|
+
return {
|
|
91
|
+
type: "boolean",
|
|
92
|
+
value: value2
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (value2 instanceof Date) {
|
|
96
|
+
return {
|
|
97
|
+
type: "date",
|
|
98
|
+
value: value2.toISOString()
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (Array.isArray(value2)) {
|
|
102
|
+
return value2.map((v) => converter(v));
|
|
103
|
+
}
|
|
104
|
+
if (typeof value2 === "object") {
|
|
105
|
+
return Object.entries(value2).reduce(
|
|
106
|
+
reducer,
|
|
107
|
+
{}
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
...acc,
|
|
113
|
+
[key]: converter(value)
|
|
114
|
+
};
|
|
115
|
+
}, {})
|
|
118
116
|
)
|
|
119
117
|
});
|
|
120
118
|
if (!res.ok) {
|
|
@@ -27,58 +27,56 @@ function CrudFormProvider({
|
|
|
27
27
|
"Content-Type": "application/json"
|
|
28
28
|
},
|
|
29
29
|
body: JSON.stringify(
|
|
30
|
-
Object.entries(store.state).reduce(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
{}
|
|
81
|
-
)
|
|
30
|
+
Object.entries(store.state).reduce(function reducer(acc, [key, value]) {
|
|
31
|
+
const converter = (value2) => {
|
|
32
|
+
if (value2 === void 0) {
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
if (value2 === null) {
|
|
36
|
+
return {
|
|
37
|
+
type: "null",
|
|
38
|
+
value: null
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (typeof value2 === "string") {
|
|
42
|
+
return {
|
|
43
|
+
type: "string",
|
|
44
|
+
value: value2
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (typeof value2 === "number") {
|
|
48
|
+
return {
|
|
49
|
+
type: "number",
|
|
50
|
+
value: value2
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (typeof value2 === "boolean") {
|
|
54
|
+
return {
|
|
55
|
+
type: "boolean",
|
|
56
|
+
value: value2
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (value2 instanceof Date) {
|
|
60
|
+
return {
|
|
61
|
+
type: "date",
|
|
62
|
+
value: value2.toISOString()
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(value2)) {
|
|
66
|
+
return value2.map((v) => converter(v));
|
|
67
|
+
}
|
|
68
|
+
if (typeof value2 === "object") {
|
|
69
|
+
return Object.entries(value2).reduce(
|
|
70
|
+
reducer,
|
|
71
|
+
{}
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
...acc,
|
|
77
|
+
[key]: converter(value)
|
|
78
|
+
};
|
|
79
|
+
}, {})
|
|
82
80
|
)
|
|
83
81
|
});
|
|
84
82
|
if (!res.ok) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoaderFunctionArgs } from 'react-router';
|
|
1
|
+
import { LoaderFunction, LoaderFunctionArgs } from 'react-router';
|
|
2
2
|
import { TableLoaderOptions } from '../table/loader.mjs';
|
|
3
3
|
import { TableItemLoaderOptions } from '../table/item_loader.mjs';
|
|
4
4
|
import { Table } from 'drizzle-orm';
|
|
@@ -12,10 +12,14 @@ import 'dn-react-toolkit/auth/server';
|
|
|
12
12
|
type CrudHandlerOptions<T extends Table, TSelect> = {
|
|
13
13
|
repository: TableRepository<T, TSelect>;
|
|
14
14
|
apiHandlerOptions: Omit<APIHandlerOptions<T, TSelect>, "repository">;
|
|
15
|
-
loaderOptions: Omit<TableLoaderOptions<T, TSelect>, "repository"
|
|
16
|
-
|
|
15
|
+
loaderOptions: Omit<TableLoaderOptions<T, TSelect>, "repository"> & {
|
|
16
|
+
loader?: LoaderFunction;
|
|
17
|
+
};
|
|
18
|
+
itemLoaderOptions: Omit<TableItemLoaderOptions<T, TSelect>, "repository"> & {
|
|
19
|
+
loader?: LoaderFunction;
|
|
20
|
+
};
|
|
17
21
|
};
|
|
18
22
|
type CrudHandler = (prefix: string) => (args: LoaderFunctionArgs) => Promise<any>;
|
|
19
|
-
declare function crudHandler<T extends Table, TSelect>({ repository, apiHandlerOptions, loaderOptions, itemLoaderOptions, }: CrudHandlerOptions<T, TSelect>): (prefix: string) => (args: LoaderFunctionArgs) => Promise<
|
|
23
|
+
declare function crudHandler<T extends Table, TSelect>({ repository, apiHandlerOptions, loaderOptions, itemLoaderOptions, }: CrudHandlerOptions<T, TSelect>): (prefix: string) => (args: LoaderFunctionArgs) => Promise<unknown>;
|
|
20
24
|
|
|
21
25
|
export { type CrudHandler, type CrudHandlerOptions, crudHandler };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoaderFunctionArgs } from 'react-router';
|
|
1
|
+
import { LoaderFunction, LoaderFunctionArgs } from 'react-router';
|
|
2
2
|
import { TableLoaderOptions } from '../table/loader.js';
|
|
3
3
|
import { TableItemLoaderOptions } from '../table/item_loader.js';
|
|
4
4
|
import { Table } from 'drizzle-orm';
|
|
@@ -12,10 +12,14 @@ import 'dn-react-toolkit/auth/server';
|
|
|
12
12
|
type CrudHandlerOptions<T extends Table, TSelect> = {
|
|
13
13
|
repository: TableRepository<T, TSelect>;
|
|
14
14
|
apiHandlerOptions: Omit<APIHandlerOptions<T, TSelect>, "repository">;
|
|
15
|
-
loaderOptions: Omit<TableLoaderOptions<T, TSelect>, "repository"
|
|
16
|
-
|
|
15
|
+
loaderOptions: Omit<TableLoaderOptions<T, TSelect>, "repository"> & {
|
|
16
|
+
loader?: LoaderFunction;
|
|
17
|
+
};
|
|
18
|
+
itemLoaderOptions: Omit<TableItemLoaderOptions<T, TSelect>, "repository"> & {
|
|
19
|
+
loader?: LoaderFunction;
|
|
20
|
+
};
|
|
17
21
|
};
|
|
18
22
|
type CrudHandler = (prefix: string) => (args: LoaderFunctionArgs) => Promise<any>;
|
|
19
|
-
declare function crudHandler<T extends Table, TSelect>({ repository, apiHandlerOptions, loaderOptions, itemLoaderOptions, }: CrudHandlerOptions<T, TSelect>): (prefix: string) => (args: LoaderFunctionArgs) => Promise<
|
|
23
|
+
declare function crudHandler<T extends Table, TSelect>({ repository, apiHandlerOptions, loaderOptions, itemLoaderOptions, }: CrudHandlerOptions<T, TSelect>): (prefix: string) => (args: LoaderFunctionArgs) => Promise<unknown>;
|
|
20
24
|
|
|
21
25
|
export { type CrudHandler, type CrudHandlerOptions, crudHandler };
|
package/dist/crud/crud_loader.js
CHANGED
|
@@ -69,24 +69,16 @@ function tableLoader({
|
|
|
69
69
|
|
|
70
70
|
// src/table/item_loader.tsx
|
|
71
71
|
var tableItemloader = ({
|
|
72
|
-
loader,
|
|
73
72
|
repository
|
|
74
73
|
}) => {
|
|
75
|
-
return async (
|
|
76
|
-
const
|
|
77
|
-
const result = await loader({ params });
|
|
78
|
-
if (result instanceof Response) {
|
|
79
|
-
return result.json();
|
|
80
|
-
}
|
|
81
|
-
return result;
|
|
82
|
-
})() : {};
|
|
74
|
+
return async (args) => {
|
|
75
|
+
const { params } = args;
|
|
83
76
|
if (params["itemId"] === "new") {
|
|
84
|
-
return { item: void 0
|
|
77
|
+
return { item: void 0 };
|
|
85
78
|
}
|
|
86
79
|
const item = params["itemId"] ? await repository.find(params["itemId"]) : void 0;
|
|
87
80
|
return {
|
|
88
|
-
item
|
|
89
|
-
...body
|
|
81
|
+
item
|
|
90
82
|
};
|
|
91
83
|
};
|
|
92
84
|
};
|
|
@@ -272,13 +264,35 @@ function crudHandler({
|
|
|
272
264
|
}
|
|
273
265
|
}
|
|
274
266
|
if (pattern === prefix) {
|
|
275
|
-
|
|
267
|
+
const body = await tableLoader({
|
|
276
268
|
...loaderOptions,
|
|
277
269
|
repository
|
|
278
270
|
})(args);
|
|
271
|
+
if (loaderOptions.loader) {
|
|
272
|
+
const result = await loaderOptions.loader(args);
|
|
273
|
+
if (typeof result === "object") {
|
|
274
|
+
return {
|
|
275
|
+
...result,
|
|
276
|
+
...body
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return body;
|
|
279
281
|
}
|
|
280
282
|
if (pattern.startsWith(prefix)) {
|
|
281
|
-
|
|
283
|
+
const body = await tableItemloader({ ...itemLoaderOptions, repository })(
|
|
284
|
+
args
|
|
285
|
+
);
|
|
286
|
+
if (itemLoaderOptions.loader) {
|
|
287
|
+
const result = await itemLoaderOptions.loader(args);
|
|
288
|
+
if (typeof result === "object") {
|
|
289
|
+
return {
|
|
290
|
+
...result,
|
|
291
|
+
...body
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return body;
|
|
282
296
|
}
|
|
283
297
|
};
|
|
284
298
|
}
|
|
@@ -46,24 +46,16 @@ function tableLoader({
|
|
|
46
46
|
|
|
47
47
|
// src/table/item_loader.tsx
|
|
48
48
|
var tableItemloader = ({
|
|
49
|
-
loader,
|
|
50
49
|
repository
|
|
51
50
|
}) => {
|
|
52
|
-
return async (
|
|
53
|
-
const
|
|
54
|
-
const result = await loader({ params });
|
|
55
|
-
if (result instanceof Response) {
|
|
56
|
-
return result.json();
|
|
57
|
-
}
|
|
58
|
-
return result;
|
|
59
|
-
})() : {};
|
|
51
|
+
return async (args) => {
|
|
52
|
+
const { params } = args;
|
|
60
53
|
if (params["itemId"] === "new") {
|
|
61
|
-
return { item: void 0
|
|
54
|
+
return { item: void 0 };
|
|
62
55
|
}
|
|
63
56
|
const item = params["itemId"] ? await repository.find(params["itemId"]) : void 0;
|
|
64
57
|
return {
|
|
65
|
-
item
|
|
66
|
-
...body
|
|
58
|
+
item
|
|
67
59
|
};
|
|
68
60
|
};
|
|
69
61
|
};
|
|
@@ -258,13 +250,35 @@ function crudHandler({
|
|
|
258
250
|
}
|
|
259
251
|
}
|
|
260
252
|
if (pattern === prefix) {
|
|
261
|
-
|
|
253
|
+
const body = await tableLoader({
|
|
262
254
|
...loaderOptions,
|
|
263
255
|
repository
|
|
264
256
|
})(args);
|
|
257
|
+
if (loaderOptions.loader) {
|
|
258
|
+
const result = await loaderOptions.loader(args);
|
|
259
|
+
if (typeof result === "object") {
|
|
260
|
+
return {
|
|
261
|
+
...result,
|
|
262
|
+
...body
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return body;
|
|
265
267
|
}
|
|
266
268
|
if (pattern.startsWith(prefix)) {
|
|
267
|
-
|
|
269
|
+
const body = await tableItemloader({ ...itemLoaderOptions, repository })(
|
|
270
|
+
args
|
|
271
|
+
);
|
|
272
|
+
if (itemLoaderOptions.loader) {
|
|
273
|
+
const result = await itemLoaderOptions.loader(args);
|
|
274
|
+
if (typeof result === "object") {
|
|
275
|
+
return {
|
|
276
|
+
...result,
|
|
277
|
+
...body
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return body;
|
|
268
282
|
}
|
|
269
283
|
};
|
|
270
284
|
}
|
|
@@ -2,7 +2,6 @@ import { CrudFormProps } from './crud_form_provider.mjs';
|
|
|
2
2
|
import { TablePageOptions } from '../table/page.mjs';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import 'dn-react-toolkit/store';
|
|
5
|
-
import 'drizzle-orm/pg-core';
|
|
6
5
|
import '../table/table.mjs';
|
|
7
6
|
|
|
8
7
|
type CrudPageOptions<TModel, TPrimaryKey extends keyof TModel> = {
|