dn-react-router-toolkit 0.6.1 → 0.6.3
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 +68 -53
- package/dist/crud/crud_form_provider.mjs +68 -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 +105 -94
- package/dist/crud/crud_page.mjs +105 -94
- package/dist/crud/index.d.mts +1 -1
- package/dist/crud/index.d.ts +1 -1
- package/dist/crud/index.js +142 -137
- package/dist/crud/index.mjs +142 -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 +93 -93
package/dist/crud/index.mjs
CHANGED
|
@@ -3,12 +3,107 @@ import { useNavigate } from "react-router";
|
|
|
3
3
|
import { useStore } from "react-store-input";
|
|
4
4
|
import { createContext, useContext } from "react";
|
|
5
5
|
import React from "react";
|
|
6
|
+
|
|
7
|
+
// src/crud/serialize.ts
|
|
8
|
+
function serialize(value) {
|
|
9
|
+
if (value === void 0) {
|
|
10
|
+
return void 0;
|
|
11
|
+
}
|
|
12
|
+
if (value === null) {
|
|
13
|
+
return {
|
|
14
|
+
type: "null",
|
|
15
|
+
value: null
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (typeof value === "string") {
|
|
19
|
+
return {
|
|
20
|
+
type: "string",
|
|
21
|
+
value
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === "number") {
|
|
25
|
+
return {
|
|
26
|
+
type: "number",
|
|
27
|
+
value
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (typeof value === "boolean") {
|
|
31
|
+
return {
|
|
32
|
+
type: "boolean",
|
|
33
|
+
value
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (value instanceof Date) {
|
|
37
|
+
return {
|
|
38
|
+
type: "date",
|
|
39
|
+
value: value.toISOString()
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
return {
|
|
44
|
+
type: "array",
|
|
45
|
+
value: value.map((item) => serialize(item))
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === "object") {
|
|
49
|
+
return {
|
|
50
|
+
type: "object",
|
|
51
|
+
value: Object.entries(value).reduce(
|
|
52
|
+
(acc, [key, value2]) => {
|
|
53
|
+
return {
|
|
54
|
+
...acc,
|
|
55
|
+
[key]: serialize(value2)
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
{}
|
|
59
|
+
)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return void 0;
|
|
63
|
+
}
|
|
64
|
+
function deserialize(data) {
|
|
65
|
+
if (data === void 0) {
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
|
|
69
|
+
const { type, value } = data;
|
|
70
|
+
switch (type) {
|
|
71
|
+
case "null":
|
|
72
|
+
return null;
|
|
73
|
+
case "string":
|
|
74
|
+
return value;
|
|
75
|
+
case "number":
|
|
76
|
+
return value;
|
|
77
|
+
case "boolean":
|
|
78
|
+
return value;
|
|
79
|
+
case "date":
|
|
80
|
+
return new Date(value);
|
|
81
|
+
case "array":
|
|
82
|
+
return value.map((item) => deserialize(item));
|
|
83
|
+
case "object":
|
|
84
|
+
return Object.entries(value).reduce(
|
|
85
|
+
(acc, [key, value2]) => {
|
|
86
|
+
return {
|
|
87
|
+
...acc,
|
|
88
|
+
[key]: deserialize(value2)
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
{}
|
|
92
|
+
);
|
|
93
|
+
default:
|
|
94
|
+
return void 0;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return void 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/crud/crud_form_provider.tsx
|
|
6
101
|
var FormContext = createContext({});
|
|
7
102
|
function useFormContext() {
|
|
8
103
|
return useContext(FormContext);
|
|
9
104
|
}
|
|
10
105
|
function CrudFormProvider({
|
|
11
|
-
primaryKey
|
|
106
|
+
primaryKey,
|
|
12
107
|
name,
|
|
13
108
|
prefix: prefix2,
|
|
14
109
|
item,
|
|
@@ -17,7 +112,12 @@ function CrudFormProvider({
|
|
|
17
112
|
}) {
|
|
18
113
|
const apiPrefix = `/api${prefix2}`;
|
|
19
114
|
const store = useStore({
|
|
20
|
-
...item || {}
|
|
115
|
+
...Object.entries(item || {}).reduce((acc, [key, value]) => {
|
|
116
|
+
return {
|
|
117
|
+
...acc,
|
|
118
|
+
[key]: value ?? columns[key]?.defaultValue
|
|
119
|
+
};
|
|
120
|
+
}, {})
|
|
21
121
|
});
|
|
22
122
|
const navigate = useNavigate();
|
|
23
123
|
const submit = async () => {
|
|
@@ -26,57 +126,7 @@ function CrudFormProvider({
|
|
|
26
126
|
headers: {
|
|
27
127
|
"Content-Type": "application/json"
|
|
28
128
|
},
|
|
29
|
-
body: JSON.stringify(
|
|
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(
|
|
70
|
-
value2
|
|
71
|
-
).reduce(reducer, {});
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
return {
|
|
75
|
-
...acc,
|
|
76
|
-
[key]: converter(value)
|
|
77
|
-
};
|
|
78
|
-
}, {})
|
|
79
|
-
)
|
|
129
|
+
body: JSON.stringify(serialize(store.state))
|
|
80
130
|
});
|
|
81
131
|
if (!res.ok) {
|
|
82
132
|
const { message } = await res.json();
|
|
@@ -118,7 +168,6 @@ function CrudFormProvider({
|
|
|
118
168
|
// src/crud/crud_form.tsx
|
|
119
169
|
import React6 from "react";
|
|
120
170
|
import { createTextEditor } from "dn-react-text-editor";
|
|
121
|
-
import { Input, Select } from "react-store-input";
|
|
122
171
|
|
|
123
172
|
// src/client/env_loader.tsx
|
|
124
173
|
import React2 from "react";
|
|
@@ -142,7 +191,7 @@ function createStoreTextEditor(TextEditor2) {
|
|
|
142
191
|
defaultValue,
|
|
143
192
|
...props
|
|
144
193
|
}) {
|
|
145
|
-
const { ref,
|
|
194
|
+
const { ref, dispatch } = useStoreController(
|
|
146
195
|
store,
|
|
147
196
|
{
|
|
148
197
|
ref: props.ref,
|
|
@@ -179,7 +228,7 @@ function createStoreTextEditor(TextEditor2) {
|
|
|
179
228
|
ref,
|
|
180
229
|
defaultValue: defaultValue ?? getDefaultValue(),
|
|
181
230
|
onChange: (e) => {
|
|
182
|
-
|
|
231
|
+
dispatch();
|
|
183
232
|
props.onChange?.(e);
|
|
184
233
|
}
|
|
185
234
|
}
|
|
@@ -210,9 +259,13 @@ var FormLabel = createComponent("label", {
|
|
|
210
259
|
});
|
|
211
260
|
|
|
212
261
|
// src/crud/crud_form.tsx
|
|
262
|
+
import { useStoreComponent } from "react-store-input";
|
|
213
263
|
var TextEditor = createStoreTextEditor(createTextEditor());
|
|
214
|
-
function CrudForm({
|
|
264
|
+
function CrudForm({
|
|
265
|
+
AdminHeader
|
|
266
|
+
}) {
|
|
215
267
|
const form = useFormContext();
|
|
268
|
+
const component = useStoreComponent(form.store);
|
|
216
269
|
return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(
|
|
217
270
|
AdminHeader,
|
|
218
271
|
{
|
|
@@ -227,41 +280,32 @@ function CrudForm({ AdminHeader }) {
|
|
|
227
280
|
"\uC800\uC7A5\uD558\uAE30"
|
|
228
281
|
)
|
|
229
282
|
}
|
|
230
|
-
), /* @__PURE__ */ React6.createElement("div", { className: "max-w-2xl mx-auto" }, Object.keys(form.columns).length > 0 && /* @__PURE__ */ React6.createElement(React6.Fragment, null, Object.entries(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
283
|
+
), /* @__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(
|
|
284
|
+
([name, value]) => {
|
|
285
|
+
function InputComponent() {
|
|
286
|
+
if (value.type === "textarea") {
|
|
287
|
+
return /* @__PURE__ */ React6.createElement(TextEditor, { store: form.store, name });
|
|
288
|
+
}
|
|
289
|
+
if (value.options) {
|
|
290
|
+
const Component = value.options;
|
|
291
|
+
return /* @__PURE__ */ React6.createElement(component.select, { name, className: "select-form" }, /* @__PURE__ */ React6.createElement(Component, null));
|
|
292
|
+
}
|
|
239
293
|
return /* @__PURE__ */ React6.createElement(
|
|
240
|
-
|
|
294
|
+
component.input,
|
|
241
295
|
{
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
className: "
|
|
245
|
-
}
|
|
246
|
-
/* @__PURE__ */ React6.createElement(Component, null)
|
|
296
|
+
name,
|
|
297
|
+
type: value.type,
|
|
298
|
+
className: "input-form"
|
|
299
|
+
}
|
|
247
300
|
);
|
|
248
301
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
{
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
type: value.type,
|
|
255
|
-
className: "input-form"
|
|
256
|
-
}
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
const v = form.store.state[key];
|
|
260
|
-
if (typeof v === "boolean") {
|
|
261
|
-
return /* @__PURE__ */ React6.createElement("div", { className: "flex" }, value.label, /* @__PURE__ */ React6.createElement("div", { className: "ml-auto" }, /* @__PURE__ */ React6.createElement(InputComponent, null)));
|
|
302
|
+
const v = form.store.state[name];
|
|
303
|
+
if (typeof v === "boolean") {
|
|
304
|
+
return /* @__PURE__ */ React6.createElement("div", { className: "flex" }, value.label, /* @__PURE__ */ React6.createElement("div", { className: "ml-auto" }, /* @__PURE__ */ React6.createElement(InputComponent, null)));
|
|
305
|
+
}
|
|
306
|
+
return /* @__PURE__ */ React6.createElement(FormRow, null, /* @__PURE__ */ React6.createElement(FormEntry, null, /* @__PURE__ */ React6.createElement(FormLabel, { key: name }, value.label), /* @__PURE__ */ React6.createElement(InputComponent, null)));
|
|
262
307
|
}
|
|
263
|
-
|
|
264
|
-
})), form.item && /* @__PURE__ */ React6.createElement(
|
|
308
|
+
)), form.item && /* @__PURE__ */ React6.createElement(
|
|
265
309
|
"button",
|
|
266
310
|
{
|
|
267
311
|
className: "button-dangerous mt-8",
|
|
@@ -367,51 +411,10 @@ function apiHandler({
|
|
|
367
411
|
case "POST":
|
|
368
412
|
case "PUT": {
|
|
369
413
|
const serilaizedParams = await request.json();
|
|
370
|
-
const params =
|
|
371
|
-
function reducer(acc, [key, value]) {
|
|
372
|
-
const converter = (value2) => {
|
|
373
|
-
if (value2.type === "null") {
|
|
374
|
-
return null;
|
|
375
|
-
}
|
|
376
|
-
if (value2.type === "string") {
|
|
377
|
-
return value2.value;
|
|
378
|
-
}
|
|
379
|
-
if (value2.type === "number") {
|
|
380
|
-
return value2.value;
|
|
381
|
-
}
|
|
382
|
-
if (value2.type === "boolean") {
|
|
383
|
-
return value2.value;
|
|
384
|
-
}
|
|
385
|
-
if (value2.type === "date") {
|
|
386
|
-
return new Date(value2.value);
|
|
387
|
-
}
|
|
388
|
-
if (Array.isArray(value2)) {
|
|
389
|
-
return value2.map((v) => converter(v));
|
|
390
|
-
}
|
|
391
|
-
if (typeof value2 === "object") {
|
|
392
|
-
return Object.entries(value2).reduce(
|
|
393
|
-
reducer,
|
|
394
|
-
{}
|
|
395
|
-
);
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
const result = converter(value);
|
|
399
|
-
if (result === void 0) {
|
|
400
|
-
return acc;
|
|
401
|
-
}
|
|
402
|
-
return {
|
|
403
|
-
...acc,
|
|
404
|
-
[key]: result
|
|
405
|
-
};
|
|
406
|
-
},
|
|
407
|
-
{}
|
|
408
|
-
);
|
|
414
|
+
const params = deserialize(serilaizedParams);
|
|
409
415
|
if (validators) {
|
|
410
416
|
const paramsForValidation = Object.keys(validators).filter(
|
|
411
|
-
(key) => Object.prototype.hasOwnProperty.call(
|
|
412
|
-
validators,
|
|
413
|
-
key
|
|
414
|
-
)
|
|
417
|
+
(key) => Object.prototype.hasOwnProperty.call(validators, key)
|
|
415
418
|
);
|
|
416
419
|
for (const paramKey of paramsForValidation) {
|
|
417
420
|
const value = params[paramKey];
|
|
@@ -901,7 +904,7 @@ function createTablePage({
|
|
|
901
904
|
primaryKey = "id"
|
|
902
905
|
}) {
|
|
903
906
|
return function TablePage({
|
|
904
|
-
|
|
907
|
+
header: Header
|
|
905
908
|
}) {
|
|
906
909
|
const { pathname } = useLocation2();
|
|
907
910
|
const { table } = useLoaderData();
|
|
@@ -915,12 +918,12 @@ function createTablePage({
|
|
|
915
918
|
};
|
|
916
919
|
const [searchParams] = useSearchParams3();
|
|
917
920
|
return /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement(
|
|
918
|
-
|
|
921
|
+
Header,
|
|
919
922
|
{
|
|
920
923
|
title: name,
|
|
921
924
|
actions: /* @__PURE__ */ React11.createElement(Link3, { to: `${pathname}/new`, className: "button-primary" }, name, " \uCD94\uAC00")
|
|
922
925
|
}
|
|
923
|
-
), /* @__PURE__ */ React11.createElement("div", { className: "max-w-7xl mx-auto" }, searchKey && /* @__PURE__ */ React11.createElement(
|
|
926
|
+
), /* @__PURE__ */ React11.createElement("div", { className: "max-w-7xl mx-auto w-full overflow-auto" }, searchKey && /* @__PURE__ */ React11.createElement(
|
|
924
927
|
"form",
|
|
925
928
|
{
|
|
926
929
|
className: "h-18 px-4 flex items-center border-t",
|
|
@@ -975,9 +978,10 @@ function createTablePage({
|
|
|
975
978
|
import React12 from "react";
|
|
976
979
|
function crudPage({
|
|
977
980
|
name,
|
|
981
|
+
primaryKey,
|
|
978
982
|
tablePageOptions,
|
|
979
983
|
formOptions,
|
|
980
|
-
|
|
984
|
+
header
|
|
981
985
|
}) {
|
|
982
986
|
return (prefix2) => {
|
|
983
987
|
return function Page() {
|
|
@@ -988,7 +992,7 @@ function crudPage({
|
|
|
988
992
|
...tablePageOptions,
|
|
989
993
|
name
|
|
990
994
|
});
|
|
991
|
-
return /* @__PURE__ */ React12.createElement(Component, {
|
|
995
|
+
return /* @__PURE__ */ React12.createElement(Component, { header });
|
|
992
996
|
}
|
|
993
997
|
if (pathname.startsWith(prefix2)) {
|
|
994
998
|
return /* @__PURE__ */ React12.createElement(
|
|
@@ -997,9 +1001,10 @@ function crudPage({
|
|
|
997
1001
|
item: data?.item,
|
|
998
1002
|
prefix: prefix2,
|
|
999
1003
|
name,
|
|
1000
|
-
columns: formOptions.columns
|
|
1004
|
+
columns: formOptions.columns,
|
|
1005
|
+
primaryKey
|
|
1001
1006
|
},
|
|
1002
|
-
formOptions.form ? /* @__PURE__ */ React12.createElement(formOptions.form, null) : /* @__PURE__ */ React12.createElement(CrudForm, { AdminHeader })
|
|
1007
|
+
formOptions.form ? /* @__PURE__ */ React12.createElement(formOptions.form, null) : /* @__PURE__ */ React12.createElement(CrudForm, { AdminHeader: header })
|
|
1003
1008
|
);
|
|
1004
1009
|
}
|
|
1005
1010
|
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/crud/serialize.ts
|
|
21
|
+
var serialize_exports = {};
|
|
22
|
+
__export(serialize_exports, {
|
|
23
|
+
deserialize: () => deserialize,
|
|
24
|
+
serialize: () => serialize
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(serialize_exports);
|
|
27
|
+
function serialize(value) {
|
|
28
|
+
if (value === void 0) {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
if (value === null) {
|
|
32
|
+
return {
|
|
33
|
+
type: "null",
|
|
34
|
+
value: null
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (typeof value === "string") {
|
|
38
|
+
return {
|
|
39
|
+
type: "string",
|
|
40
|
+
value
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (typeof value === "number") {
|
|
44
|
+
return {
|
|
45
|
+
type: "number",
|
|
46
|
+
value
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (typeof value === "boolean") {
|
|
50
|
+
return {
|
|
51
|
+
type: "boolean",
|
|
52
|
+
value
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (value instanceof Date) {
|
|
56
|
+
return {
|
|
57
|
+
type: "date",
|
|
58
|
+
value: value.toISOString()
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (Array.isArray(value)) {
|
|
62
|
+
return {
|
|
63
|
+
type: "array",
|
|
64
|
+
value: value.map((item) => serialize(item))
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (typeof value === "object") {
|
|
68
|
+
return {
|
|
69
|
+
type: "object",
|
|
70
|
+
value: Object.entries(value).reduce(
|
|
71
|
+
(acc, [key, value2]) => {
|
|
72
|
+
return {
|
|
73
|
+
...acc,
|
|
74
|
+
[key]: serialize(value2)
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
{}
|
|
78
|
+
)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return void 0;
|
|
82
|
+
}
|
|
83
|
+
function deserialize(data) {
|
|
84
|
+
if (data === void 0) {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
|
|
88
|
+
const { type, value } = data;
|
|
89
|
+
switch (type) {
|
|
90
|
+
case "null":
|
|
91
|
+
return null;
|
|
92
|
+
case "string":
|
|
93
|
+
return value;
|
|
94
|
+
case "number":
|
|
95
|
+
return value;
|
|
96
|
+
case "boolean":
|
|
97
|
+
return value;
|
|
98
|
+
case "date":
|
|
99
|
+
return new Date(value);
|
|
100
|
+
case "array":
|
|
101
|
+
return value.map((item) => deserialize(item));
|
|
102
|
+
case "object":
|
|
103
|
+
return Object.entries(value).reduce(
|
|
104
|
+
(acc, [key, value2]) => {
|
|
105
|
+
return {
|
|
106
|
+
...acc,
|
|
107
|
+
[key]: deserialize(value2)
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
{}
|
|
111
|
+
);
|
|
112
|
+
default:
|
|
113
|
+
return void 0;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return void 0;
|
|
117
|
+
}
|
|
118
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
119
|
+
0 && (module.exports = {
|
|
120
|
+
deserialize,
|
|
121
|
+
serialize
|
|
122
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// src/crud/serialize.ts
|
|
2
|
+
function serialize(value) {
|
|
3
|
+
if (value === void 0) {
|
|
4
|
+
return void 0;
|
|
5
|
+
}
|
|
6
|
+
if (value === null) {
|
|
7
|
+
return {
|
|
8
|
+
type: "null",
|
|
9
|
+
value: null
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (typeof value === "string") {
|
|
13
|
+
return {
|
|
14
|
+
type: "string",
|
|
15
|
+
value
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (typeof value === "number") {
|
|
19
|
+
return {
|
|
20
|
+
type: "number",
|
|
21
|
+
value
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === "boolean") {
|
|
25
|
+
return {
|
|
26
|
+
type: "boolean",
|
|
27
|
+
value
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (value instanceof Date) {
|
|
31
|
+
return {
|
|
32
|
+
type: "date",
|
|
33
|
+
value: value.toISOString()
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
return {
|
|
38
|
+
type: "array",
|
|
39
|
+
value: value.map((item) => serialize(item))
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (typeof value === "object") {
|
|
43
|
+
return {
|
|
44
|
+
type: "object",
|
|
45
|
+
value: Object.entries(value).reduce(
|
|
46
|
+
(acc, [key, value2]) => {
|
|
47
|
+
return {
|
|
48
|
+
...acc,
|
|
49
|
+
[key]: serialize(value2)
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
{}
|
|
53
|
+
)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
function deserialize(data) {
|
|
59
|
+
if (data === void 0) {
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
62
|
+
if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
|
|
63
|
+
const { type, value } = data;
|
|
64
|
+
switch (type) {
|
|
65
|
+
case "null":
|
|
66
|
+
return null;
|
|
67
|
+
case "string":
|
|
68
|
+
return value;
|
|
69
|
+
case "number":
|
|
70
|
+
return value;
|
|
71
|
+
case "boolean":
|
|
72
|
+
return value;
|
|
73
|
+
case "date":
|
|
74
|
+
return new Date(value);
|
|
75
|
+
case "array":
|
|
76
|
+
return value.map((item) => deserialize(item));
|
|
77
|
+
case "object":
|
|
78
|
+
return Object.entries(value).reduce(
|
|
79
|
+
(acc, [key, value2]) => {
|
|
80
|
+
return {
|
|
81
|
+
...acc,
|
|
82
|
+
[key]: deserialize(value2)
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
{}
|
|
86
|
+
);
|
|
87
|
+
default:
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return void 0;
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
deserialize,
|
|
95
|
+
serialize
|
|
96
|
+
};
|
package/dist/table/index.js
CHANGED
|
@@ -480,7 +480,7 @@ function createTablePage({
|
|
|
480
480
|
primaryKey = "id"
|
|
481
481
|
}) {
|
|
482
482
|
return function TablePage({
|
|
483
|
-
|
|
483
|
+
header: Header
|
|
484
484
|
}) {
|
|
485
485
|
const { pathname } = (0, import_react_router3.useLocation)();
|
|
486
486
|
const { table } = (0, import_react_router3.useLoaderData)();
|
|
@@ -494,12 +494,12 @@ function createTablePage({
|
|
|
494
494
|
};
|
|
495
495
|
const [searchParams] = (0, import_react_router3.useSearchParams)();
|
|
496
496
|
return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement(
|
|
497
|
-
|
|
497
|
+
Header,
|
|
498
498
|
{
|
|
499
499
|
title: name,
|
|
500
500
|
actions: /* @__PURE__ */ import_react5.default.createElement(import_react_router3.Link, { to: `${pathname}/new`, className: "button-primary" }, name, " \uCD94\uAC00")
|
|
501
501
|
}
|
|
502
|
-
), /* @__PURE__ */ import_react5.default.createElement("div", { className: "max-w-7xl mx-auto" }, searchKey && /* @__PURE__ */ import_react5.default.createElement(
|
|
502
|
+
), /* @__PURE__ */ import_react5.default.createElement("div", { className: "max-w-7xl mx-auto w-full overflow-auto" }, searchKey && /* @__PURE__ */ import_react5.default.createElement(
|
|
503
503
|
"form",
|
|
504
504
|
{
|
|
505
505
|
className: "h-18 px-4 flex items-center border-t",
|
package/dist/table/index.mjs
CHANGED
|
@@ -454,7 +454,7 @@ function createTablePage({
|
|
|
454
454
|
primaryKey = "id"
|
|
455
455
|
}) {
|
|
456
456
|
return function TablePage({
|
|
457
|
-
|
|
457
|
+
header: Header
|
|
458
458
|
}) {
|
|
459
459
|
const { pathname } = useLocation2();
|
|
460
460
|
const { table } = useLoaderData();
|
|
@@ -468,12 +468,12 @@ function createTablePage({
|
|
|
468
468
|
};
|
|
469
469
|
const [searchParams] = useSearchParams3();
|
|
470
470
|
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
|
|
471
|
-
|
|
471
|
+
Header,
|
|
472
472
|
{
|
|
473
473
|
title: name,
|
|
474
474
|
actions: /* @__PURE__ */ React5.createElement(Link3, { to: `${pathname}/new`, className: "button-primary" }, name, " \uCD94\uAC00")
|
|
475
475
|
}
|
|
476
|
-
), /* @__PURE__ */ React5.createElement("div", { className: "max-w-7xl mx-auto" }, searchKey && /* @__PURE__ */ React5.createElement(
|
|
476
|
+
), /* @__PURE__ */ React5.createElement("div", { className: "max-w-7xl mx-auto w-full overflow-auto" }, searchKey && /* @__PURE__ */ React5.createElement(
|
|
477
477
|
"form",
|
|
478
478
|
{
|
|
479
479
|
className: "h-18 px-4 flex items-center border-t",
|
package/dist/table/page.d.mts
CHANGED
|
@@ -15,8 +15,8 @@ type TablePageOptions<TModel> = {
|
|
|
15
15
|
columns: TableColumnOptions<TModel>;
|
|
16
16
|
primaryKey?: keyof TModel;
|
|
17
17
|
};
|
|
18
|
-
declare function createTablePage<TModel>({ name, columns, primaryKey, }: TablePageOptions<TModel>): ({
|
|
19
|
-
|
|
18
|
+
declare function createTablePage<TModel>({ name, columns, primaryKey, }: TablePageOptions<TModel>): ({ header: Header, }: {
|
|
19
|
+
header: React__default.FC<{
|
|
20
20
|
title: string;
|
|
21
21
|
actions?: React__default.ReactNode;
|
|
22
22
|
}>;
|
package/dist/table/page.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ type TablePageOptions<TModel> = {
|
|
|
15
15
|
columns: TableColumnOptions<TModel>;
|
|
16
16
|
primaryKey?: keyof TModel;
|
|
17
17
|
};
|
|
18
|
-
declare function createTablePage<TModel>({ name, columns, primaryKey, }: TablePageOptions<TModel>): ({
|
|
19
|
-
|
|
18
|
+
declare function createTablePage<TModel>({ name, columns, primaryKey, }: TablePageOptions<TModel>): ({ header: Header, }: {
|
|
19
|
+
header: React__default.FC<{
|
|
20
20
|
title: string;
|
|
21
21
|
actions?: React__default.ReactNode;
|
|
22
22
|
}>;
|