dn-react-router-toolkit 0.6.0 → 0.6.2
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/api/create_api_handler.js +41 -43
- package/dist/api/create_api_handler.mjs +41 -43
- package/dist/client/index.js +2 -2
- package/dist/client/index.mjs +2 -2
- package/dist/client/store_text_editor.js +2 -2
- package/dist/client/store_text_editor.mjs +2 -2
- package/dist/crud/crud_form.d.mts +1 -1
- package/dist/crud/crud_form.d.ts +1 -1
- package/dist/crud/crud_form.js +28 -34
- package/dist/crud/crud_form.mjs +28 -34
- package/dist/crud/crud_form_provider.d.mts +14 -16
- package/dist/crud/crud_form_provider.d.ts +14 -16
- package/dist/crud/crud_form_provider.js +69 -53
- package/dist/crud/crud_form_provider.mjs +69 -53
- package/dist/crud/crud_loader.js +41 -43
- package/dist/crud/crud_loader.mjs +41 -43
- package/dist/crud/crud_page.d.mts +5 -4
- package/dist/crud/crud_page.d.ts +5 -4
- package/dist/crud/crud_page.js +106 -94
- package/dist/crud/crud_page.mjs +106 -94
- package/dist/crud/index.d.mts +1 -1
- package/dist/crud/index.d.ts +1 -1
- package/dist/crud/index.js +143 -137
- package/dist/crud/index.mjs +143 -137
- package/dist/crud/serialize.d.mts +4 -0
- package/dist/crud/serialize.d.ts +4 -0
- package/dist/crud/serialize.js +122 -0
- package/dist/crud/serialize.mjs +96 -0
- package/dist/table/index.js +3 -3
- package/dist/table/index.mjs +3 -3
- package/dist/table/page.d.mts +2 -2
- package/dist/table/page.d.ts +2 -2
- package/dist/table/page.js +3 -3
- package/dist/table/page.mjs +3 -3
- package/package.json +3 -3
|
@@ -27,6 +27,45 @@ var import_http = require("dn-react-toolkit/http");
|
|
|
27
27
|
var import_drizzle_orm = require("drizzle-orm");
|
|
28
28
|
var import_react_router = require("react-router");
|
|
29
29
|
var import_uuid = require("uuid");
|
|
30
|
+
|
|
31
|
+
// src/crud/serialize.ts
|
|
32
|
+
function deserialize(data) {
|
|
33
|
+
if (data === void 0) {
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
|
|
37
|
+
const { type, value } = data;
|
|
38
|
+
switch (type) {
|
|
39
|
+
case "null":
|
|
40
|
+
return null;
|
|
41
|
+
case "string":
|
|
42
|
+
return value;
|
|
43
|
+
case "number":
|
|
44
|
+
return value;
|
|
45
|
+
case "boolean":
|
|
46
|
+
return value;
|
|
47
|
+
case "date":
|
|
48
|
+
return new Date(value);
|
|
49
|
+
case "array":
|
|
50
|
+
return value.map((item) => deserialize(item));
|
|
51
|
+
case "object":
|
|
52
|
+
return Object.entries(value).reduce(
|
|
53
|
+
(acc, [key, value2]) => {
|
|
54
|
+
return {
|
|
55
|
+
...acc,
|
|
56
|
+
[key]: deserialize(value2)
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
{}
|
|
60
|
+
);
|
|
61
|
+
default:
|
|
62
|
+
return void 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return void 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/api/create_api_handler.ts
|
|
30
69
|
function apiHandler({
|
|
31
70
|
withAuthAction,
|
|
32
71
|
repository,
|
|
@@ -45,51 +84,10 @@ function apiHandler({
|
|
|
45
84
|
case "POST":
|
|
46
85
|
case "PUT": {
|
|
47
86
|
const serilaizedParams = await request.json();
|
|
48
|
-
const params =
|
|
49
|
-
function reducer(acc, [key, value]) {
|
|
50
|
-
const converter = (value2) => {
|
|
51
|
-
if (value2.type === "null") {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
if (value2.type === "string") {
|
|
55
|
-
return value2.value;
|
|
56
|
-
}
|
|
57
|
-
if (value2.type === "number") {
|
|
58
|
-
return value2.value;
|
|
59
|
-
}
|
|
60
|
-
if (value2.type === "boolean") {
|
|
61
|
-
return value2.value;
|
|
62
|
-
}
|
|
63
|
-
if (value2.type === "date") {
|
|
64
|
-
return new Date(value2.value);
|
|
65
|
-
}
|
|
66
|
-
if (Array.isArray(value2)) {
|
|
67
|
-
return value2.map((v) => converter(v));
|
|
68
|
-
}
|
|
69
|
-
if (typeof value2 === "object") {
|
|
70
|
-
return Object.entries(value2).reduce(
|
|
71
|
-
reducer,
|
|
72
|
-
{}
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const result = converter(value);
|
|
77
|
-
if (result === void 0) {
|
|
78
|
-
return acc;
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
...acc,
|
|
82
|
-
[key]: result
|
|
83
|
-
};
|
|
84
|
-
},
|
|
85
|
-
{}
|
|
86
|
-
);
|
|
87
|
+
const params = deserialize(serilaizedParams);
|
|
87
88
|
if (validators) {
|
|
88
89
|
const paramsForValidation = Object.keys(validators).filter(
|
|
89
|
-
(key) => Object.prototype.hasOwnProperty.call(
|
|
90
|
-
validators,
|
|
91
|
-
key
|
|
92
|
-
)
|
|
90
|
+
(key) => Object.prototype.hasOwnProperty.call(validators, key)
|
|
93
91
|
);
|
|
94
92
|
for (const paramKey of paramsForValidation) {
|
|
95
93
|
const value = params[paramKey];
|
|
@@ -12,6 +12,45 @@ import {
|
|
|
12
12
|
redirect
|
|
13
13
|
} from "react-router";
|
|
14
14
|
import { v4 } from "uuid";
|
|
15
|
+
|
|
16
|
+
// src/crud/serialize.ts
|
|
17
|
+
function deserialize(data) {
|
|
18
|
+
if (data === void 0) {
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
|
|
22
|
+
const { type, value } = data;
|
|
23
|
+
switch (type) {
|
|
24
|
+
case "null":
|
|
25
|
+
return null;
|
|
26
|
+
case "string":
|
|
27
|
+
return value;
|
|
28
|
+
case "number":
|
|
29
|
+
return value;
|
|
30
|
+
case "boolean":
|
|
31
|
+
return value;
|
|
32
|
+
case "date":
|
|
33
|
+
return new Date(value);
|
|
34
|
+
case "array":
|
|
35
|
+
return value.map((item) => deserialize(item));
|
|
36
|
+
case "object":
|
|
37
|
+
return Object.entries(value).reduce(
|
|
38
|
+
(acc, [key, value2]) => {
|
|
39
|
+
return {
|
|
40
|
+
...acc,
|
|
41
|
+
[key]: deserialize(value2)
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
{}
|
|
45
|
+
);
|
|
46
|
+
default:
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/api/create_api_handler.ts
|
|
15
54
|
function apiHandler({
|
|
16
55
|
withAuthAction,
|
|
17
56
|
repository,
|
|
@@ -30,51 +69,10 @@ function apiHandler({
|
|
|
30
69
|
case "POST":
|
|
31
70
|
case "PUT": {
|
|
32
71
|
const serilaizedParams = await request.json();
|
|
33
|
-
const params =
|
|
34
|
-
function reducer(acc, [key, value]) {
|
|
35
|
-
const converter = (value2) => {
|
|
36
|
-
if (value2.type === "null") {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
if (value2.type === "string") {
|
|
40
|
-
return value2.value;
|
|
41
|
-
}
|
|
42
|
-
if (value2.type === "number") {
|
|
43
|
-
return value2.value;
|
|
44
|
-
}
|
|
45
|
-
if (value2.type === "boolean") {
|
|
46
|
-
return value2.value;
|
|
47
|
-
}
|
|
48
|
-
if (value2.type === "date") {
|
|
49
|
-
return new Date(value2.value);
|
|
50
|
-
}
|
|
51
|
-
if (Array.isArray(value2)) {
|
|
52
|
-
return value2.map((v) => converter(v));
|
|
53
|
-
}
|
|
54
|
-
if (typeof value2 === "object") {
|
|
55
|
-
return Object.entries(value2).reduce(
|
|
56
|
-
reducer,
|
|
57
|
-
{}
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const result = converter(value);
|
|
62
|
-
if (result === void 0) {
|
|
63
|
-
return acc;
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
...acc,
|
|
67
|
-
[key]: result
|
|
68
|
-
};
|
|
69
|
-
},
|
|
70
|
-
{}
|
|
71
|
-
);
|
|
72
|
+
const params = deserialize(serilaizedParams);
|
|
72
73
|
if (validators) {
|
|
73
74
|
const paramsForValidation = Object.keys(validators).filter(
|
|
74
|
-
(key) => Object.prototype.hasOwnProperty.call(
|
|
75
|
-
validators,
|
|
76
|
-
key
|
|
77
|
-
)
|
|
75
|
+
(key) => Object.prototype.hasOwnProperty.call(validators, key)
|
|
78
76
|
);
|
|
79
77
|
for (const paramKey of paramsForValidation) {
|
|
80
78
|
const value = params[paramKey];
|
package/dist/client/index.js
CHANGED
|
@@ -129,7 +129,7 @@ function createStoreTextEditor(TextEditor) {
|
|
|
129
129
|
defaultValue,
|
|
130
130
|
...props
|
|
131
131
|
}) {
|
|
132
|
-
const { ref,
|
|
132
|
+
const { ref, dispatch } = (0, import_react_store_input.useStoreController)(
|
|
133
133
|
store,
|
|
134
134
|
{
|
|
135
135
|
ref: props.ref,
|
|
@@ -166,7 +166,7 @@ function createStoreTextEditor(TextEditor) {
|
|
|
166
166
|
ref,
|
|
167
167
|
defaultValue: defaultValue ?? getDefaultValue(),
|
|
168
168
|
onChange: (e) => {
|
|
169
|
-
|
|
169
|
+
dispatch();
|
|
170
170
|
props.onChange?.(e);
|
|
171
171
|
}
|
|
172
172
|
}
|
package/dist/client/index.mjs
CHANGED
|
@@ -89,7 +89,7 @@ function createStoreTextEditor(TextEditor) {
|
|
|
89
89
|
defaultValue,
|
|
90
90
|
...props
|
|
91
91
|
}) {
|
|
92
|
-
const { ref,
|
|
92
|
+
const { ref, dispatch } = useStoreController(
|
|
93
93
|
store,
|
|
94
94
|
{
|
|
95
95
|
ref: props.ref,
|
|
@@ -126,7 +126,7 @@ function createStoreTextEditor(TextEditor) {
|
|
|
126
126
|
ref,
|
|
127
127
|
defaultValue: defaultValue ?? getDefaultValue(),
|
|
128
128
|
onChange: (e) => {
|
|
129
|
-
|
|
129
|
+
dispatch();
|
|
130
130
|
props.onChange?.(e);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
@@ -43,7 +43,7 @@ function createStoreTextEditor(TextEditor) {
|
|
|
43
43
|
defaultValue,
|
|
44
44
|
...props
|
|
45
45
|
}) {
|
|
46
|
-
const { ref,
|
|
46
|
+
const { ref, dispatch } = (0, import_react_store_input.useStoreController)(
|
|
47
47
|
store,
|
|
48
48
|
{
|
|
49
49
|
ref: props.ref,
|
|
@@ -80,7 +80,7 @@ function createStoreTextEditor(TextEditor) {
|
|
|
80
80
|
ref,
|
|
81
81
|
defaultValue: defaultValue ?? getDefaultValue(),
|
|
82
82
|
onChange: (e) => {
|
|
83
|
-
|
|
83
|
+
dispatch();
|
|
84
84
|
props.onChange?.(e);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -9,7 +9,7 @@ function createStoreTextEditor(TextEditor) {
|
|
|
9
9
|
defaultValue,
|
|
10
10
|
...props
|
|
11
11
|
}) {
|
|
12
|
-
const { ref,
|
|
12
|
+
const { ref, dispatch } = useStoreController(
|
|
13
13
|
store,
|
|
14
14
|
{
|
|
15
15
|
ref: props.ref,
|
|
@@ -46,7 +46,7 @@ function createStoreTextEditor(TextEditor) {
|
|
|
46
46
|
ref,
|
|
47
47
|
defaultValue: defaultValue ?? getDefaultValue(),
|
|
48
48
|
onChange: (e) => {
|
|
49
|
-
|
|
49
|
+
dispatch();
|
|
50
50
|
props.onChange?.(e);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -6,6 +6,6 @@ type Props = {
|
|
|
6
6
|
actions?: React__default.ReactNode;
|
|
7
7
|
}>;
|
|
8
8
|
};
|
|
9
|
-
declare function CrudForm<TModel
|
|
9
|
+
declare function CrudForm<TModel extends Record<string, unknown>>({ AdminHeader, }: Props): React__default.JSX.Element;
|
|
10
10
|
|
|
11
11
|
export { CrudForm as default };
|
package/dist/crud/crud_form.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ type Props = {
|
|
|
6
6
|
actions?: React__default.ReactNode;
|
|
7
7
|
}>;
|
|
8
8
|
};
|
|
9
|
-
declare function CrudForm<TModel
|
|
9
|
+
declare function CrudForm<TModel extends Record<string, unknown>>({ AdminHeader, }: Props): React__default.JSX.Element;
|
|
10
10
|
|
|
11
11
|
export { CrudForm as default };
|
package/dist/crud/crud_form.js
CHANGED
|
@@ -47,7 +47,6 @@ function useFormContext() {
|
|
|
47
47
|
// src/crud/crud_form.tsx
|
|
48
48
|
var import_react8 = __toESM(require("react"));
|
|
49
49
|
var import_dn_react_text_editor2 = require("dn-react-text-editor");
|
|
50
|
-
var import_react_store_input3 = require("react-store-input");
|
|
51
50
|
|
|
52
51
|
// src/client/env_loader.tsx
|
|
53
52
|
var import_react3 = __toESM(require("react"));
|
|
@@ -71,7 +70,7 @@ function createStoreTextEditor(TextEditor2) {
|
|
|
71
70
|
defaultValue,
|
|
72
71
|
...props
|
|
73
72
|
}) {
|
|
74
|
-
const { ref,
|
|
73
|
+
const { ref, dispatch } = (0, import_react_store_input2.useStoreController)(
|
|
75
74
|
store,
|
|
76
75
|
{
|
|
77
76
|
ref: props.ref,
|
|
@@ -108,7 +107,7 @@ function createStoreTextEditor(TextEditor2) {
|
|
|
108
107
|
ref,
|
|
109
108
|
defaultValue: defaultValue ?? getDefaultValue(),
|
|
110
109
|
onChange: (e) => {
|
|
111
|
-
|
|
110
|
+
dispatch();
|
|
112
111
|
props.onChange?.(e);
|
|
113
112
|
}
|
|
114
113
|
}
|
|
@@ -139,9 +138,13 @@ var FormLabel = createComponent("label", {
|
|
|
139
138
|
});
|
|
140
139
|
|
|
141
140
|
// src/crud/crud_form.tsx
|
|
141
|
+
var import_react_store_input3 = require("react-store-input");
|
|
142
142
|
var TextEditor = createStoreTextEditor((0, import_dn_react_text_editor2.createTextEditor)());
|
|
143
|
-
function CrudForm({
|
|
143
|
+
function CrudForm({
|
|
144
|
+
AdminHeader
|
|
145
|
+
}) {
|
|
144
146
|
const form = useFormContext();
|
|
147
|
+
const component = (0, import_react_store_input3.useStoreComponent)(form.store);
|
|
145
148
|
return /* @__PURE__ */ import_react8.default.createElement(import_react8.default.Fragment, null, /* @__PURE__ */ import_react8.default.createElement(
|
|
146
149
|
AdminHeader,
|
|
147
150
|
{
|
|
@@ -156,41 +159,32 @@ function CrudForm({ AdminHeader }) {
|
|
|
156
159
|
"\uC800\uC7A5\uD558\uAE30"
|
|
157
160
|
)
|
|
158
161
|
}
|
|
159
|
-
), /* @__PURE__ */ import_react8.default.createElement("div", { className: "max-w-2xl mx-auto" }, Object.keys(form.columns).length > 0 && /* @__PURE__ */ import_react8.default.createElement(import_react8.default.Fragment, null, Object.entries(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
162
|
+
), /* @__PURE__ */ import_react8.default.createElement("div", { className: "max-w-2xl mx-auto" }, Object.keys(form.columns).length > 0 && /* @__PURE__ */ import_react8.default.createElement(import_react8.default.Fragment, null, Object.entries(form.columns).map(
|
|
163
|
+
([name, value]) => {
|
|
164
|
+
function InputComponent() {
|
|
165
|
+
if (value.type === "textarea") {
|
|
166
|
+
return /* @__PURE__ */ import_react8.default.createElement(TextEditor, { store: form.store, name });
|
|
167
|
+
}
|
|
168
|
+
if (value.options) {
|
|
169
|
+
const Component = value.options;
|
|
170
|
+
return /* @__PURE__ */ import_react8.default.createElement(component.select, { name, className: "select-form" }, /* @__PURE__ */ import_react8.default.createElement(Component, null));
|
|
171
|
+
}
|
|
168
172
|
return /* @__PURE__ */ import_react8.default.createElement(
|
|
169
|
-
|
|
173
|
+
component.input,
|
|
170
174
|
{
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
className: "
|
|
174
|
-
}
|
|
175
|
-
/* @__PURE__ */ import_react8.default.createElement(Component, null)
|
|
175
|
+
name,
|
|
176
|
+
type: value.type,
|
|
177
|
+
className: "input-form"
|
|
178
|
+
}
|
|
176
179
|
);
|
|
177
180
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
{
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
type: value.type,
|
|
184
|
-
className: "input-form"
|
|
185
|
-
}
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
const v = form.store.state[key];
|
|
189
|
-
if (typeof v === "boolean") {
|
|
190
|
-
return /* @__PURE__ */ import_react8.default.createElement("div", { className: "flex" }, value.label, /* @__PURE__ */ import_react8.default.createElement("div", { className: "ml-auto" }, /* @__PURE__ */ import_react8.default.createElement(InputComponent, null)));
|
|
181
|
+
const v = form.store.state[name];
|
|
182
|
+
if (typeof v === "boolean") {
|
|
183
|
+
return /* @__PURE__ */ import_react8.default.createElement("div", { className: "flex" }, value.label, /* @__PURE__ */ import_react8.default.createElement("div", { className: "ml-auto" }, /* @__PURE__ */ import_react8.default.createElement(InputComponent, null)));
|
|
184
|
+
}
|
|
185
|
+
return /* @__PURE__ */ import_react8.default.createElement(FormRow, null, /* @__PURE__ */ import_react8.default.createElement(FormEntry, null, /* @__PURE__ */ import_react8.default.createElement(FormLabel, { key: name }, value.label), /* @__PURE__ */ import_react8.default.createElement(InputComponent, null)));
|
|
191
186
|
}
|
|
192
|
-
|
|
193
|
-
})), form.item && /* @__PURE__ */ import_react8.default.createElement(
|
|
187
|
+
)), form.item && /* @__PURE__ */ import_react8.default.createElement(
|
|
194
188
|
"button",
|
|
195
189
|
{
|
|
196
190
|
className: "button-dangerous mt-8",
|
package/dist/crud/crud_form.mjs
CHANGED
|
@@ -11,7 +11,6 @@ function useFormContext() {
|
|
|
11
11
|
// src/crud/crud_form.tsx
|
|
12
12
|
import React6 from "react";
|
|
13
13
|
import { createTextEditor } from "dn-react-text-editor";
|
|
14
|
-
import { Input, Select } from "react-store-input";
|
|
15
14
|
|
|
16
15
|
// src/client/env_loader.tsx
|
|
17
16
|
import React2 from "react";
|
|
@@ -35,7 +34,7 @@ function createStoreTextEditor(TextEditor2) {
|
|
|
35
34
|
defaultValue,
|
|
36
35
|
...props
|
|
37
36
|
}) {
|
|
38
|
-
const { ref,
|
|
37
|
+
const { ref, dispatch } = useStoreController(
|
|
39
38
|
store,
|
|
40
39
|
{
|
|
41
40
|
ref: props.ref,
|
|
@@ -72,7 +71,7 @@ function createStoreTextEditor(TextEditor2) {
|
|
|
72
71
|
ref,
|
|
73
72
|
defaultValue: defaultValue ?? getDefaultValue(),
|
|
74
73
|
onChange: (e) => {
|
|
75
|
-
|
|
74
|
+
dispatch();
|
|
76
75
|
props.onChange?.(e);
|
|
77
76
|
}
|
|
78
77
|
}
|
|
@@ -103,9 +102,13 @@ var FormLabel = createComponent("label", {
|
|
|
103
102
|
});
|
|
104
103
|
|
|
105
104
|
// src/crud/crud_form.tsx
|
|
105
|
+
import { useStoreComponent } from "react-store-input";
|
|
106
106
|
var TextEditor = createStoreTextEditor(createTextEditor());
|
|
107
|
-
function CrudForm({
|
|
107
|
+
function CrudForm({
|
|
108
|
+
AdminHeader
|
|
109
|
+
}) {
|
|
108
110
|
const form = useFormContext();
|
|
111
|
+
const component = useStoreComponent(form.store);
|
|
109
112
|
return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(
|
|
110
113
|
AdminHeader,
|
|
111
114
|
{
|
|
@@ -120,41 +123,32 @@ function CrudForm({ AdminHeader }) {
|
|
|
120
123
|
"\uC800\uC7A5\uD558\uAE30"
|
|
121
124
|
)
|
|
122
125
|
}
|
|
123
|
-
), /* @__PURE__ */ React6.createElement("div", { className: "max-w-2xl mx-auto" }, Object.keys(form.columns).length > 0 && /* @__PURE__ */ React6.createElement(React6.Fragment, null, Object.entries(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
126
|
+
), /* @__PURE__ */ React6.createElement("div", { className: "max-w-2xl mx-auto" }, Object.keys(form.columns).length > 0 && /* @__PURE__ */ React6.createElement(React6.Fragment, null, Object.entries(form.columns).map(
|
|
127
|
+
([name, value]) => {
|
|
128
|
+
function InputComponent() {
|
|
129
|
+
if (value.type === "textarea") {
|
|
130
|
+
return /* @__PURE__ */ React6.createElement(TextEditor, { store: form.store, name });
|
|
131
|
+
}
|
|
132
|
+
if (value.options) {
|
|
133
|
+
const Component = value.options;
|
|
134
|
+
return /* @__PURE__ */ React6.createElement(component.select, { name, className: "select-form" }, /* @__PURE__ */ React6.createElement(Component, null));
|
|
135
|
+
}
|
|
132
136
|
return /* @__PURE__ */ React6.createElement(
|
|
133
|
-
|
|
137
|
+
component.input,
|
|
134
138
|
{
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
className: "
|
|
138
|
-
}
|
|
139
|
-
/* @__PURE__ */ React6.createElement(Component, null)
|
|
139
|
+
name,
|
|
140
|
+
type: value.type,
|
|
141
|
+
className: "input-form"
|
|
142
|
+
}
|
|
140
143
|
);
|
|
141
144
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
{
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
type: value.type,
|
|
148
|
-
className: "input-form"
|
|
149
|
-
}
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
const v = form.store.state[key];
|
|
153
|
-
if (typeof v === "boolean") {
|
|
154
|
-
return /* @__PURE__ */ React6.createElement("div", { className: "flex" }, value.label, /* @__PURE__ */ React6.createElement("div", { className: "ml-auto" }, /* @__PURE__ */ React6.createElement(InputComponent, null)));
|
|
145
|
+
const v = form.store.state[name];
|
|
146
|
+
if (typeof v === "boolean") {
|
|
147
|
+
return /* @__PURE__ */ React6.createElement("div", { className: "flex" }, value.label, /* @__PURE__ */ React6.createElement("div", { className: "ml-auto" }, /* @__PURE__ */ React6.createElement(InputComponent, null)));
|
|
148
|
+
}
|
|
149
|
+
return /* @__PURE__ */ React6.createElement(FormRow, null, /* @__PURE__ */ React6.createElement(FormEntry, null, /* @__PURE__ */ React6.createElement(FormLabel, { key: name }, value.label), /* @__PURE__ */ React6.createElement(InputComponent, null)));
|
|
155
150
|
}
|
|
156
|
-
|
|
157
|
-
})), form.item && /* @__PURE__ */ React6.createElement(
|
|
151
|
+
)), form.item && /* @__PURE__ */ React6.createElement(
|
|
158
152
|
"button",
|
|
159
153
|
{
|
|
160
154
|
className: "button-dangerous mt-8",
|
|
@@ -1,38 +1,36 @@
|
|
|
1
1
|
import { Store } from 'react-store-input';
|
|
2
2
|
import React__default from 'react';
|
|
3
3
|
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
type FormColumnValue<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof TModel ? "id" : never> = {
|
|
8
|
-
label: string;
|
|
4
|
+
type FormColumnValue<TModel> = {
|
|
5
|
+
label?: string;
|
|
9
6
|
type?: React__default.HTMLInputTypeAttribute | "textarea";
|
|
7
|
+
defaultValue?: TModel[keyof TModel];
|
|
10
8
|
component?: React__default.FC<{
|
|
11
|
-
store: Store<
|
|
9
|
+
store: Store<TModel>;
|
|
12
10
|
property: string;
|
|
13
11
|
}>;
|
|
14
12
|
options?: React__default.FC;
|
|
15
13
|
};
|
|
16
|
-
type FormColumns<TModel
|
|
17
|
-
[K in keyof TModel]: FormColumnValue<TModel
|
|
14
|
+
type FormColumns<TModel> = Partial<{
|
|
15
|
+
[K in keyof TModel]: FormColumnValue<TModel>;
|
|
18
16
|
}>;
|
|
19
17
|
declare const FormContext: React__default.Context<{}>;
|
|
20
|
-
declare function useFormContext<TModel
|
|
18
|
+
declare function useFormContext<TModel>(): {
|
|
21
19
|
name: string;
|
|
22
20
|
item?: TModel;
|
|
23
|
-
store: Store<
|
|
21
|
+
store: Store<TModel>;
|
|
24
22
|
submit: () => Promise<void>;
|
|
25
23
|
delete: () => Promise<void>;
|
|
26
|
-
columns: FormColumns<TModel
|
|
24
|
+
columns: FormColumns<TModel>;
|
|
27
25
|
};
|
|
28
|
-
type CrudFormProps<TModel
|
|
29
|
-
primaryKey
|
|
26
|
+
type CrudFormProps<TModel> = {
|
|
27
|
+
primaryKey: keyof TModel;
|
|
30
28
|
name: string;
|
|
31
29
|
prefix: string;
|
|
32
30
|
item?: TModel;
|
|
33
|
-
columns?: FormColumns<TModel
|
|
31
|
+
columns?: FormColumns<TModel>;
|
|
34
32
|
children?: React__default.ReactNode;
|
|
35
33
|
};
|
|
36
|
-
declare function CrudFormProvider<TModel
|
|
34
|
+
declare function CrudFormProvider<TModel>({ primaryKey, name, prefix, item, columns, children, }: CrudFormProps<TModel>): React__default.JSX.Element;
|
|
37
35
|
|
|
38
|
-
export { type CrudFormProps, type FormColumnValue, type FormColumns, FormContext,
|
|
36
|
+
export { type CrudFormProps, type FormColumnValue, type FormColumns, FormContext, CrudFormProvider as default, useFormContext };
|
|
@@ -1,38 +1,36 @@
|
|
|
1
1
|
import { Store } from 'react-store-input';
|
|
2
2
|
import React__default from 'react';
|
|
3
3
|
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
type FormColumnValue<TModel, TPrimaryKey extends keyof TModel = "id" extends keyof TModel ? "id" : never> = {
|
|
8
|
-
label: string;
|
|
4
|
+
type FormColumnValue<TModel> = {
|
|
5
|
+
label?: string;
|
|
9
6
|
type?: React__default.HTMLInputTypeAttribute | "textarea";
|
|
7
|
+
defaultValue?: TModel[keyof TModel];
|
|
10
8
|
component?: React__default.FC<{
|
|
11
|
-
store: Store<
|
|
9
|
+
store: Store<TModel>;
|
|
12
10
|
property: string;
|
|
13
11
|
}>;
|
|
14
12
|
options?: React__default.FC;
|
|
15
13
|
};
|
|
16
|
-
type FormColumns<TModel
|
|
17
|
-
[K in keyof TModel]: FormColumnValue<TModel
|
|
14
|
+
type FormColumns<TModel> = Partial<{
|
|
15
|
+
[K in keyof TModel]: FormColumnValue<TModel>;
|
|
18
16
|
}>;
|
|
19
17
|
declare const FormContext: React__default.Context<{}>;
|
|
20
|
-
declare function useFormContext<TModel
|
|
18
|
+
declare function useFormContext<TModel>(): {
|
|
21
19
|
name: string;
|
|
22
20
|
item?: TModel;
|
|
23
|
-
store: Store<
|
|
21
|
+
store: Store<TModel>;
|
|
24
22
|
submit: () => Promise<void>;
|
|
25
23
|
delete: () => Promise<void>;
|
|
26
|
-
columns: FormColumns<TModel
|
|
24
|
+
columns: FormColumns<TModel>;
|
|
27
25
|
};
|
|
28
|
-
type CrudFormProps<TModel
|
|
29
|
-
primaryKey
|
|
26
|
+
type CrudFormProps<TModel> = {
|
|
27
|
+
primaryKey: keyof TModel;
|
|
30
28
|
name: string;
|
|
31
29
|
prefix: string;
|
|
32
30
|
item?: TModel;
|
|
33
|
-
columns?: FormColumns<TModel
|
|
31
|
+
columns?: FormColumns<TModel>;
|
|
34
32
|
children?: React__default.ReactNode;
|
|
35
33
|
};
|
|
36
|
-
declare function CrudFormProvider<TModel
|
|
34
|
+
declare function CrudFormProvider<TModel>({ primaryKey, name, prefix, item, columns, children, }: CrudFormProps<TModel>): React__default.JSX.Element;
|
|
37
35
|
|
|
38
|
-
export { type CrudFormProps, type FormColumnValue, type FormColumns, FormContext,
|
|
36
|
+
export { type CrudFormProps, type FormColumnValue, type FormColumns, FormContext, CrudFormProvider as default, useFormContext };
|