ding-react-admin 1.0.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.
- package/LICENSE +21 -0
- package/README.md +74 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3067 -0
- package/dist/src/app/AdminApp.d.ts +7 -0
- package/dist/src/app/AdminApp.d.ts.map +1 -0
- package/dist/src/components/AuthAlternateLink.d.ts +7 -0
- package/dist/src/components/AuthAlternateLink.d.ts.map +1 -0
- package/dist/src/components/DensitySwitch.d.ts +2 -0
- package/dist/src/components/DensitySwitch.d.ts.map +1 -0
- package/dist/src/components/ThemeSwitch.d.ts +2 -0
- package/dist/src/components/ThemeSwitch.d.ts.map +1 -0
- package/dist/src/components/ThemeToolbar.d.ts +2 -0
- package/dist/src/components/ThemeToolbar.d.ts.map +1 -0
- package/dist/src/components/index.d.ts +5 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/context/AppThemeProvider.d.ts +13 -0
- package/dist/src/context/AppThemeProvider.d.ts.map +1 -0
- package/dist/src/context/AuthProvider.d.ts +18 -0
- package/dist/src/context/AuthProvider.d.ts.map +1 -0
- package/dist/src/context/DataProvider.d.ts +10 -0
- package/dist/src/context/DataProvider.d.ts.map +1 -0
- package/dist/src/context/PermissionsProvider.d.ts +18 -0
- package/dist/src/context/PermissionsProvider.d.ts.map +1 -0
- package/dist/src/crud/FilterBar.d.ts +6 -0
- package/dist/src/crud/FilterBar.d.ts.map +1 -0
- package/dist/src/crud/FormSteps.d.ts +20 -0
- package/dist/src/crud/FormSteps.d.ts.map +1 -0
- package/dist/src/crud/FormTabs.d.ts +13 -0
- package/dist/src/crud/FormTabs.d.ts.map +1 -0
- package/dist/src/crud/InlineFormSet.d.ts +29 -0
- package/dist/src/crud/InlineFormSet.d.ts.map +1 -0
- package/dist/src/crud/ListActionsBar.d.ts +15 -0
- package/dist/src/crud/ListActionsBar.d.ts.map +1 -0
- package/dist/src/crud/ResourceForm.d.ts +21 -0
- package/dist/src/crud/ResourceForm.d.ts.map +1 -0
- package/dist/src/crud/ResourceFormModal.d.ts +10 -0
- package/dist/src/crud/ResourceFormModal.d.ts.map +1 -0
- package/dist/src/crud/ResourceList.d.ts +38 -0
- package/dist/src/crud/ResourceList.d.ts.map +1 -0
- package/dist/src/crud/columns/BooleanColumn.d.ts +6 -0
- package/dist/src/crud/columns/BooleanColumn.d.ts.map +1 -0
- package/dist/src/crud/columns/CustomColumn.d.ts +9 -0
- package/dist/src/crud/columns/CustomColumn.d.ts.map +1 -0
- package/dist/src/crud/columns/DateColumn.d.ts +6 -0
- package/dist/src/crud/columns/DateColumn.d.ts.map +1 -0
- package/dist/src/crud/columns/NumberColumn.d.ts +6 -0
- package/dist/src/crud/columns/NumberColumn.d.ts.map +1 -0
- package/dist/src/crud/columns/ReferenceColumn.d.ts +6 -0
- package/dist/src/crud/columns/ReferenceColumn.d.ts.map +1 -0
- package/dist/src/crud/columns/ReferenceManyColumn.d.ts +6 -0
- package/dist/src/crud/columns/ReferenceManyColumn.d.ts.map +1 -0
- package/dist/src/crud/columns/TextColumn.d.ts +7 -0
- package/dist/src/crud/columns/TextColumn.d.ts.map +1 -0
- package/dist/src/crud/context/FilterContext.d.ts +17 -0
- package/dist/src/crud/context/FilterContext.d.ts.map +1 -0
- package/dist/src/crud/context/FormContext.d.ts +16 -0
- package/dist/src/crud/context/FormContext.d.ts.map +1 -0
- package/dist/src/crud/context/FormFieldsContext.d.ts +14 -0
- package/dist/src/crud/context/FormFieldsContext.d.ts.map +1 -0
- package/dist/src/crud/context/FormSectionContext.d.ts +7 -0
- package/dist/src/crud/context/FormSectionContext.d.ts.map +1 -0
- package/dist/src/crud/context/InlineFormContext.d.ts +16 -0
- package/dist/src/crud/context/InlineFormContext.d.ts.map +1 -0
- package/dist/src/crud/context/ListContext.d.ts +22 -0
- package/dist/src/crud/context/ListContext.d.ts.map +1 -0
- package/dist/src/crud/fields/BooleanField.d.ts +7 -0
- package/dist/src/crud/fields/BooleanField.d.ts.map +1 -0
- package/dist/src/crud/fields/DateField.d.ts +8 -0
- package/dist/src/crud/fields/DateField.d.ts.map +1 -0
- package/dist/src/crud/fields/FieldWrapper.d.ts +29 -0
- package/dist/src/crud/fields/FieldWrapper.d.ts.map +1 -0
- package/dist/src/crud/fields/NumberField.d.ts +12 -0
- package/dist/src/crud/fields/NumberField.d.ts.map +1 -0
- package/dist/src/crud/fields/PasswordField.d.ts +11 -0
- package/dist/src/crud/fields/PasswordField.d.ts.map +1 -0
- package/dist/src/crud/fields/ReferenceField.d.ts +18 -0
- package/dist/src/crud/fields/ReferenceField.d.ts.map +1 -0
- package/dist/src/crud/fields/ReferenceManyField.d.ts +9 -0
- package/dist/src/crud/fields/ReferenceManyField.d.ts.map +1 -0
- package/dist/src/crud/fields/SelectField.d.ts +10 -0
- package/dist/src/crud/fields/SelectField.d.ts.map +1 -0
- package/dist/src/crud/fields/TextField.d.ts +10 -0
- package/dist/src/crud/fields/TextField.d.ts.map +1 -0
- package/dist/src/crud/fields/useInlineOrFormField.d.ts +10 -0
- package/dist/src/crud/fields/useInlineOrFormField.d.ts.map +1 -0
- package/dist/src/crud/filters/BooleanFilter.d.ts +4 -0
- package/dist/src/crud/filters/BooleanFilter.d.ts.map +1 -0
- package/dist/src/crud/filters/DateFilter.d.ts +4 -0
- package/dist/src/crud/filters/DateFilter.d.ts.map +1 -0
- package/dist/src/crud/filters/NumberFilter.d.ts +4 -0
- package/dist/src/crud/filters/NumberFilter.d.ts.map +1 -0
- package/dist/src/crud/filters/ReferenceFilter.d.ts +13 -0
- package/dist/src/crud/filters/ReferenceFilter.d.ts.map +1 -0
- package/dist/src/crud/filters/SelectFilter.d.ts +7 -0
- package/dist/src/crud/filters/SelectFilter.d.ts.map +1 -0
- package/dist/src/crud/filters/TextFilter.d.ts +6 -0
- package/dist/src/crud/filters/TextFilter.d.ts.map +1 -0
- package/dist/src/crud/index.d.ts +44 -0
- package/dist/src/crud/index.d.ts.map +1 -0
- package/dist/src/crud/types.d.ts +99 -0
- package/dist/src/crud/types.d.ts.map +1 -0
- package/dist/src/crud/utils/formErrors.d.ts +9 -0
- package/dist/src/crud/utils/formErrors.d.ts.map +1 -0
- package/dist/src/crud/utils/formSectionErrors.d.ts +6 -0
- package/dist/src/crud/utils/formSectionErrors.d.ts.map +1 -0
- package/dist/src/crud/utils/getByPath.d.ts +3 -0
- package/dist/src/crud/utils/getByPath.d.ts.map +1 -0
- package/dist/src/crud/utils/inlineArrayName.d.ts +3 -0
- package/dist/src/crud/utils/inlineArrayName.d.ts.map +1 -0
- package/dist/src/crud/utils/pickBySources.d.ts +6 -0
- package/dist/src/crud/utils/pickBySources.d.ts.map +1 -0
- package/dist/src/crud/utils/setByPath.d.ts +3 -0
- package/dist/src/crud/utils/setByPath.d.ts.map +1 -0
- package/dist/src/crud/utils/sortQueryParam.d.ts +7 -0
- package/dist/src/crud/utils/sortQueryParam.d.ts.map +1 -0
- package/dist/src/crud/utils/useChoices.d.ts +10 -0
- package/dist/src/crud/utils/useChoices.d.ts.map +1 -0
- package/dist/src/crud/utils/useListQueryState.d.ts +22 -0
- package/dist/src/crud/utils/useListQueryState.d.ts.map +1 -0
- package/dist/src/data/createMemoryResourceHandlers.d.ts +23 -0
- package/dist/src/data/createMemoryResourceHandlers.d.ts.map +1 -0
- package/dist/src/data/createRestResourceHandlers.d.ts +22 -0
- package/dist/src/data/createRestResourceHandlers.d.ts.map +1 -0
- package/dist/src/data/dataProviderTypes.d.ts +67 -0
- package/dist/src/data/dataProviderTypes.d.ts.map +1 -0
- package/dist/src/data/dataUtils.test.d.ts +2 -0
- package/dist/src/data/dataUtils.test.d.ts.map +1 -0
- package/dist/src/data/inMemoryList.d.ts +12 -0
- package/dist/src/data/inMemoryList.d.ts.map +1 -0
- package/dist/src/data/parseFormErrorHelpers.d.ts +35 -0
- package/dist/src/data/parseFormErrorHelpers.d.ts.map +1 -0
- package/dist/src/data/parseFormErrorHelpers.test.d.ts +2 -0
- package/dist/src/data/parseFormErrorHelpers.test.d.ts.map +1 -0
- package/dist/src/data/resourceHandlers.d.ts +33 -0
- package/dist/src/data/resourceHandlers.d.ts.map +1 -0
- package/dist/src/data/sortHelpers.d.ts +17 -0
- package/dist/src/data/sortHelpers.d.ts.map +1 -0
- package/dist/src/index.d.ts +31 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/layouts/AdminLayout.d.ts +3 -0
- package/dist/src/layouts/AdminLayout.d.ts.map +1 -0
- package/dist/src/layouts/AuthPageLayout.d.ts +11 -0
- package/dist/src/layouts/AuthPageLayout.d.ts.map +1 -0
- package/dist/src/pages/LoginPage.d.ts +3 -0
- package/dist/src/pages/LoginPage.d.ts.map +1 -0
- package/dist/src/pages/PlaceholderPage.d.ts +4 -0
- package/dist/src/pages/PlaceholderPage.d.ts.map +1 -0
- package/dist/src/permissions/resourcePermissions.d.ts +22 -0
- package/dist/src/permissions/resourcePermissions.d.ts.map +1 -0
- package/dist/src/router/createAdminRouter.d.ts +3 -0
- package/dist/src/router/createAdminRouter.d.ts.map +1 -0
- package/dist/src/router/guards.d.ts +20 -0
- package/dist/src/router/guards.d.ts.map +1 -0
- package/dist/src/router/routeAccess.d.ts +21 -0
- package/dist/src/router/routeAccess.d.ts.map +1 -0
- package/dist/src/types.d.ts +123 -0
- package/dist/src/types.d.ts.map +1 -0
- package/package.json +58 -0
- package/src/app/AdminApp.tsx +34 -0
- package/src/components/AuthAlternateLink.tsx +23 -0
- package/src/components/DensitySwitch.tsx +31 -0
- package/src/components/ThemeSwitch.tsx +28 -0
- package/src/components/ThemeToolbar.tsx +34 -0
- package/src/components/index.ts +4 -0
- package/src/context/AppThemeProvider.tsx +128 -0
- package/src/context/AuthProvider.tsx +77 -0
- package/src/context/DataProvider.tsx +30 -0
- package/src/context/PermissionsProvider.tsx +57 -0
- package/src/crud/FilterBar.tsx +36 -0
- package/src/crud/FormSteps.tsx +135 -0
- package/src/crud/FormTabs.tsx +126 -0
- package/src/crud/InlineFormSet.tsx +231 -0
- package/src/crud/ListActionsBar.tsx +106 -0
- package/src/crud/ResourceForm.tsx +281 -0
- package/src/crud/ResourceFormModal.tsx +121 -0
- package/src/crud/ResourceList.tsx +633 -0
- package/src/crud/columns/BooleanColumn.tsx +32 -0
- package/src/crud/columns/CustomColumn.tsx +33 -0
- package/src/crud/columns/DateColumn.tsx +28 -0
- package/src/crud/columns/NumberColumn.tsx +31 -0
- package/src/crud/columns/ReferenceColumn.tsx +85 -0
- package/src/crud/columns/ReferenceManyColumn.tsx +67 -0
- package/src/crud/columns/TextColumn.tsx +38 -0
- package/src/crud/context/FilterContext.tsx +71 -0
- package/src/crud/context/FormContext.tsx +39 -0
- package/src/crud/context/FormFieldsContext.tsx +76 -0
- package/src/crud/context/FormSectionContext.tsx +22 -0
- package/src/crud/context/InlineFormContext.tsx +71 -0
- package/src/crud/context/ListContext.tsx +93 -0
- package/src/crud/fields/BooleanField.tsx +32 -0
- package/src/crud/fields/DateField.tsx +47 -0
- package/src/crud/fields/FieldWrapper.tsx +109 -0
- package/src/crud/fields/NumberField.tsx +50 -0
- package/src/crud/fields/PasswordField.tsx +98 -0
- package/src/crud/fields/ReferenceField.tsx +191 -0
- package/src/crud/fields/ReferenceManyField.tsx +70 -0
- package/src/crud/fields/SelectField.tsx +42 -0
- package/src/crud/fields/TextField.tsx +44 -0
- package/src/crud/fields/useInlineOrFormField.tsx +91 -0
- package/src/crud/filters/BooleanFilter.tsx +38 -0
- package/src/crud/filters/DateFilter.tsx +35 -0
- package/src/crud/filters/NumberFilter.tsx +33 -0
- package/src/crud/filters/ReferenceFilter.tsx +173 -0
- package/src/crud/filters/SelectFilter.tsx +44 -0
- package/src/crud/filters/TextFilter.tsx +36 -0
- package/src/crud/index.ts +73 -0
- package/src/crud/types.ts +130 -0
- package/src/crud/utils/formErrors.ts +38 -0
- package/src/crud/utils/formSectionErrors.ts +85 -0
- package/src/crud/utils/getByPath.ts +13 -0
- package/src/crud/utils/inlineArrayName.ts +4 -0
- package/src/crud/utils/pickBySources.ts +24 -0
- package/src/crud/utils/setByPath.ts +18 -0
- package/src/crud/utils/sortQueryParam.ts +37 -0
- package/src/crud/utils/useChoices.ts +182 -0
- package/src/crud/utils/useListQueryState.ts +191 -0
- package/src/data/createMemoryResourceHandlers.ts +78 -0
- package/src/data/createRestResourceHandlers.ts +57 -0
- package/src/data/dataProviderTypes.ts +101 -0
- package/src/data/dataUtils.test.ts +108 -0
- package/src/data/inMemoryList.ts +97 -0
- package/src/data/parseFormErrorHelpers.test.ts +84 -0
- package/src/data/parseFormErrorHelpers.ts +224 -0
- package/src/data/resourceHandlers.ts +124 -0
- package/src/data/sortHelpers.ts +48 -0
- package/src/index.ts +182 -0
- package/src/layouts/AdminLayout.tsx +381 -0
- package/src/layouts/AuthPageLayout.tsx +81 -0
- package/src/pages/LoginPage.tsx +80 -0
- package/src/pages/PlaceholderPage.tsx +9 -0
- package/src/permissions/resourcePermissions.ts +47 -0
- package/src/router/createAdminRouter.tsx +64 -0
- package/src/router/guards.tsx +63 -0
- package/src/router/routeAccess.ts +89 -0
- package/src/types.ts +135 -0
- package/src/vite-env.d.ts +1 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3067 @@
|
|
|
1
|
+
import { Children as e, createContext as t, createElement as n, isValidElement as r, useCallback as i, useContext as a, useEffect as o, useMemo as s, useRef as c, useState as l } from "react";
|
|
2
|
+
import { Link as u, Navigate as d, Outlet as f, RouterProvider as p, createBrowserRouter as m, useLocation as h, useNavigate as g, useParams as _, useSearchParams as v } from "react-router-dom";
|
|
3
|
+
import { App as y, Avatar as b, Button as x, Card as S, ConfigProvider as C, DatePicker as w, Drawer as T, Dropdown as ee, Flex as E, Form as D, Grid as O, Input as k, InputNumber as A, Layout as j, Menu as te, Modal as M, Popover as ne, Segmented as N, Select as P, Space as F, Spin as I, Steps as L, Switch as re, Table as ie, Tabs as ae, Typography as R, theme as z } from "antd";
|
|
4
|
+
import { Fragment as B, jsx as V, jsxs as H } from "react/jsx-runtime";
|
|
5
|
+
import { ArrowLeftOutlined as U, CaretDownOutlined as oe, CaretUpOutlined as se, ColumnHeightOutlined as W, DesktopOutlined as ce, LayoutOutlined as le, LogoutOutlined as ue, MenuOutlined as de, MoonOutlined as fe, SettingOutlined as pe, SunOutlined as me, UserOutlined as he } from "@ant-design/icons";
|
|
6
|
+
import { Controller as ge, FormProvider as _e, useFieldArray as ve, useForm as ye, useFormContext as G, useFormState as K, useWatch as be } from "react-hook-form";
|
|
7
|
+
import xe from "dayjs";
|
|
8
|
+
//#region src/context/AppThemeProvider.tsx
|
|
9
|
+
var Se = t(null);
|
|
10
|
+
function Ce(e) {
|
|
11
|
+
try {
|
|
12
|
+
let t = localStorage.getItem(e);
|
|
13
|
+
if (t === "light" || t === "dark" || t === "system") return t;
|
|
14
|
+
} catch {}
|
|
15
|
+
return "system";
|
|
16
|
+
}
|
|
17
|
+
function we() {
|
|
18
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
19
|
+
}
|
|
20
|
+
function Te(e) {
|
|
21
|
+
try {
|
|
22
|
+
let t = localStorage.getItem(e);
|
|
23
|
+
if (t === "comfortable" || t === "compact") return t;
|
|
24
|
+
} catch {}
|
|
25
|
+
return "comfortable";
|
|
26
|
+
}
|
|
27
|
+
var Ee = "ding-react-admin-theme-mode", De = "ding-react-admin-theme-density";
|
|
28
|
+
function Oe({ children: e, modeStorageKey: t = Ee, densityStorageKey: n = De }) {
|
|
29
|
+
let [r, i] = l(() => Ce(t)), [a, c] = l(() => Te(n)), [u, d] = l(we);
|
|
30
|
+
o(() => {
|
|
31
|
+
if (r !== "system") return;
|
|
32
|
+
let e = window.matchMedia("(prefers-color-scheme: dark)"), t = () => d(e.matches);
|
|
33
|
+
return t(), e.addEventListener("change", t), () => e.removeEventListener("change", t);
|
|
34
|
+
}, [r]);
|
|
35
|
+
let f = (e) => {
|
|
36
|
+
i(e);
|
|
37
|
+
try {
|
|
38
|
+
localStorage.setItem(t, e);
|
|
39
|
+
} catch {}
|
|
40
|
+
}, p = (e) => {
|
|
41
|
+
c(e);
|
|
42
|
+
try {
|
|
43
|
+
localStorage.setItem(n, e);
|
|
44
|
+
} catch {}
|
|
45
|
+
}, m = r === "system" ? u ? "dark" : "light" : r, h = s(() => {
|
|
46
|
+
let e = m === "dark" ? z.darkAlgorithm : z.defaultAlgorithm;
|
|
47
|
+
return { algorithm: a === "compact" ? [e, z.compactAlgorithm] : e };
|
|
48
|
+
}, [m, a]), g = s(() => ({
|
|
49
|
+
mode: r,
|
|
50
|
+
setMode: f,
|
|
51
|
+
resolved: m,
|
|
52
|
+
density: a,
|
|
53
|
+
setDensity: p
|
|
54
|
+
}), [
|
|
55
|
+
r,
|
|
56
|
+
m,
|
|
57
|
+
a,
|
|
58
|
+
f,
|
|
59
|
+
p
|
|
60
|
+
]);
|
|
61
|
+
return /* @__PURE__ */ V(Se.Provider, {
|
|
62
|
+
value: g,
|
|
63
|
+
children: /* @__PURE__ */ V(C, {
|
|
64
|
+
theme: h,
|
|
65
|
+
children: e
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function ke() {
|
|
70
|
+
let e = a(Se);
|
|
71
|
+
if (!e) throw Error("useThemeMode must be used within AppThemeProvider");
|
|
72
|
+
return e;
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/components/DensitySwitch.tsx
|
|
76
|
+
var Ae = [{
|
|
77
|
+
label: "Comfortable",
|
|
78
|
+
value: "comfortable",
|
|
79
|
+
icon: /* @__PURE__ */ V(le, {})
|
|
80
|
+
}, {
|
|
81
|
+
label: "Compact",
|
|
82
|
+
value: "compact",
|
|
83
|
+
icon: /* @__PURE__ */ V(W, {})
|
|
84
|
+
}];
|
|
85
|
+
function je() {
|
|
86
|
+
let { density: e, setDensity: t } = ke();
|
|
87
|
+
return /* @__PURE__ */ V(N, {
|
|
88
|
+
size: "small",
|
|
89
|
+
value: e,
|
|
90
|
+
options: Ae,
|
|
91
|
+
onChange: (e) => t(e)
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/components/ThemeSwitch.tsx
|
|
96
|
+
var Me = [
|
|
97
|
+
{
|
|
98
|
+
label: "Light",
|
|
99
|
+
value: "light",
|
|
100
|
+
icon: /* @__PURE__ */ V(me, {})
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
label: "Dark",
|
|
104
|
+
value: "dark",
|
|
105
|
+
icon: /* @__PURE__ */ V(fe, {})
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
label: "Auto",
|
|
109
|
+
value: "system",
|
|
110
|
+
icon: /* @__PURE__ */ V(ce, {})
|
|
111
|
+
}
|
|
112
|
+
];
|
|
113
|
+
function Ne() {
|
|
114
|
+
let { mode: e, setMode: t } = ke();
|
|
115
|
+
return /* @__PURE__ */ V(N, {
|
|
116
|
+
size: "small",
|
|
117
|
+
value: e,
|
|
118
|
+
options: Me,
|
|
119
|
+
onChange: (e) => t(e)
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/components/ThemeToolbar.tsx
|
|
124
|
+
function Pe() {
|
|
125
|
+
let { token: e } = z.useToken();
|
|
126
|
+
return /* @__PURE__ */ V(ne, {
|
|
127
|
+
placement: O.useBreakpoint().lg ? "bottomRight" : "bottom",
|
|
128
|
+
trigger: "click",
|
|
129
|
+
content: /* @__PURE__ */ H(F, {
|
|
130
|
+
orientation: "vertical",
|
|
131
|
+
size: "middle",
|
|
132
|
+
style: {
|
|
133
|
+
minWidth: 240,
|
|
134
|
+
maxWidth: "min(92vw, 320px)"
|
|
135
|
+
},
|
|
136
|
+
children: [/* @__PURE__ */ V(Ne, {}), /* @__PURE__ */ V(je, {})]
|
|
137
|
+
}),
|
|
138
|
+
styles: { content: { padding: e.paddingSM } },
|
|
139
|
+
children: /* @__PURE__ */ V(x, {
|
|
140
|
+
type: "default",
|
|
141
|
+
icon: /* @__PURE__ */ V(pe, {}),
|
|
142
|
+
"aria-label": "Display and theme settings"
|
|
143
|
+
})
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/context/AuthProvider.tsx
|
|
148
|
+
var Fe = t(null);
|
|
149
|
+
function Ie({ children: e, adapter: t }) {
|
|
150
|
+
let [n, r] = l(() => t.getToken()), a = i(async (e) => {
|
|
151
|
+
await t.login(e), r(t.getToken());
|
|
152
|
+
}, [t]), o = i(() => {
|
|
153
|
+
t.logout(), r(t.getToken());
|
|
154
|
+
}, [t]), c = s(() => ({
|
|
155
|
+
isAuthenticated: !!n,
|
|
156
|
+
login: a,
|
|
157
|
+
logout: o
|
|
158
|
+
}), [
|
|
159
|
+
n,
|
|
160
|
+
a,
|
|
161
|
+
o
|
|
162
|
+
]);
|
|
163
|
+
return /* @__PURE__ */ V(Fe.Provider, {
|
|
164
|
+
value: c,
|
|
165
|
+
children: e
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function Le() {
|
|
169
|
+
let e = a(Fe);
|
|
170
|
+
if (!e) throw Error("useAuth must be used within AuthProvider");
|
|
171
|
+
return e;
|
|
172
|
+
}
|
|
173
|
+
var Re = "ding-react-admin-auth";
|
|
174
|
+
function ze(e = Re) {
|
|
175
|
+
return {
|
|
176
|
+
async login({ username: t, password: n }) {
|
|
177
|
+
if (!t.trim() || !n) throw Error("Invalid credentials");
|
|
178
|
+
sessionStorage.setItem(e, "1");
|
|
179
|
+
},
|
|
180
|
+
logout() {
|
|
181
|
+
sessionStorage.removeItem(e);
|
|
182
|
+
},
|
|
183
|
+
getToken() {
|
|
184
|
+
return sessionStorage.getItem(e);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/context/PermissionsProvider.tsx
|
|
190
|
+
var Be = t(null);
|
|
191
|
+
function Ve({ children: e, can: t }) {
|
|
192
|
+
let n = s(() => t, [t]);
|
|
193
|
+
return /* @__PURE__ */ V(Be.Provider, {
|
|
194
|
+
value: n,
|
|
195
|
+
children: e
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function q() {
|
|
199
|
+
let e = a(Be);
|
|
200
|
+
if (!e) throw Error("usePermissions must be used within PermissionsProvider");
|
|
201
|
+
return e;
|
|
202
|
+
}
|
|
203
|
+
function He(e) {
|
|
204
|
+
return (t) => e()?.includes(t) ?? !1;
|
|
205
|
+
}
|
|
206
|
+
function Ue(e) {
|
|
207
|
+
let t = q();
|
|
208
|
+
return i(() => t(e), [t, e]);
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/permissions/resourcePermissions.ts
|
|
212
|
+
function J(e, t, n) {
|
|
213
|
+
if (!t) return !0;
|
|
214
|
+
let r = t[n];
|
|
215
|
+
return n === "read" && !r && (r = t.list), r ? e(r) : !1;
|
|
216
|
+
}
|
|
217
|
+
function We(e, t) {
|
|
218
|
+
return e.map((e) => {
|
|
219
|
+
if (e.children?.length) {
|
|
220
|
+
let n = We(e.children, t);
|
|
221
|
+
return n.length === 0 ? null : {
|
|
222
|
+
...e,
|
|
223
|
+
children: n
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return e.permission && !t(e.permission) ? null : e;
|
|
227
|
+
}).filter((e) => e !== null);
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/layouts/AdminLayout.tsx
|
|
231
|
+
var Ge = "#001529", Ke = "ding-react-admin-sider-collapsed";
|
|
232
|
+
function qe(e) {
|
|
233
|
+
try {
|
|
234
|
+
return localStorage.getItem(e) === "1";
|
|
235
|
+
} catch {
|
|
236
|
+
return !1;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function Je() {
|
|
240
|
+
return O.useBreakpoint().lg !== !0;
|
|
241
|
+
}
|
|
242
|
+
function Ye(e) {
|
|
243
|
+
let t = /* @__PURE__ */ new Set();
|
|
244
|
+
function n(e) {
|
|
245
|
+
for (let r of e) r.children?.length ? n(r.children) : t.add(r.path);
|
|
246
|
+
}
|
|
247
|
+
return n(e), t;
|
|
248
|
+
}
|
|
249
|
+
function Xe(e, t) {
|
|
250
|
+
function n(e) {
|
|
251
|
+
for (let r of e) if (r.children?.length) {
|
|
252
|
+
let e = n(r.children);
|
|
253
|
+
if (e !== null) return [r.path, ...e];
|
|
254
|
+
} else if (r.path === t) return [];
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
return n(e) ?? [];
|
|
258
|
+
}
|
|
259
|
+
function Ze(e) {
|
|
260
|
+
return e.map((e) => {
|
|
261
|
+
let t = e.Icon, n = t ? /* @__PURE__ */ V(t, {}) : void 0;
|
|
262
|
+
return e.children?.length ? {
|
|
263
|
+
key: e.path,
|
|
264
|
+
icon: n,
|
|
265
|
+
label: e.label,
|
|
266
|
+
children: Ze(e.children)
|
|
267
|
+
} : {
|
|
268
|
+
key: e.path,
|
|
269
|
+
icon: n,
|
|
270
|
+
label: e.label
|
|
271
|
+
};
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
function Qe({ menuItems: e, selectedKeys: t, inlineCollapsed: n, openKeys: r, onOpenChange: i, onNavigate: a }) {
|
|
275
|
+
return /* @__PURE__ */ V(te, {
|
|
276
|
+
mode: "inline",
|
|
277
|
+
theme: "dark",
|
|
278
|
+
inlineCollapsed: n,
|
|
279
|
+
selectedKeys: t,
|
|
280
|
+
...!n && r !== void 0 && i ? {
|
|
281
|
+
openKeys: r,
|
|
282
|
+
onOpenChange: i
|
|
283
|
+
} : {},
|
|
284
|
+
items: e,
|
|
285
|
+
onClick: ({ key: e }) => a(e),
|
|
286
|
+
style: {
|
|
287
|
+
background: "transparent",
|
|
288
|
+
borderInlineEnd: "none"
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
function $e({ navItems: e, brand: t = "Admin", collapsedBrand: n = "A", mobileDrawerTitle: r, headerExtras: a, userMenuItems: c, onUserMenuClick: u, loginPath: d = "/login", siderCollapsedStorageKey: p = Ke }) {
|
|
293
|
+
let m = g(), _ = h(), { resolved: v } = ke(), y = v === "dark", { logout: S } = Le(), C = q(), [w, E] = l(() => qe(p)), [D, O] = l(!1), k = Je(), { token: A } = z.useToken(), te = r ?? t, M = () => {
|
|
294
|
+
S(), m(d, { replace: !0 });
|
|
295
|
+
}, ne = i((e) => {
|
|
296
|
+
E(e);
|
|
297
|
+
try {
|
|
298
|
+
localStorage.setItem(p, e ? "1" : "0");
|
|
299
|
+
} catch {}
|
|
300
|
+
}, [p]);
|
|
301
|
+
o(() => {
|
|
302
|
+
k || O(!1);
|
|
303
|
+
}, [k]), o(() => {
|
|
304
|
+
O(!1);
|
|
305
|
+
}, [_.pathname]);
|
|
306
|
+
let N = s(() => We(e, C), [e, C]), P = s(() => Ye(N), [N]), F = s(() => Ze(N), [N]), I = s(() => Xe(N, _.pathname), [N, _.pathname]), [L, re] = l(() => Xe(N, _.pathname));
|
|
307
|
+
o(() => {
|
|
308
|
+
re((e) => [...new Set([...e, ...I])]);
|
|
309
|
+
}, [I]);
|
|
310
|
+
let ie = i((e) => {
|
|
311
|
+
re(e);
|
|
312
|
+
}, []), ae = s(() => [{
|
|
313
|
+
key: "logout",
|
|
314
|
+
icon: /* @__PURE__ */ V(ue, {}),
|
|
315
|
+
label: "Log out",
|
|
316
|
+
danger: !0
|
|
317
|
+
}], []), B = c ?? ae, U = (e) => {
|
|
318
|
+
if (u) {
|
|
319
|
+
u(e);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
e.key === "logout" && M();
|
|
323
|
+
}, oe = y ? A.colorBgContainer : Ge, se = [_.pathname], W = (e) => {
|
|
324
|
+
P.has(e) && (m(e), k && O(!1));
|
|
325
|
+
};
|
|
326
|
+
return /* @__PURE__ */ H(j, {
|
|
327
|
+
style: {
|
|
328
|
+
minHeight: "100vh",
|
|
329
|
+
width: "100%",
|
|
330
|
+
background: A.colorBgLayout
|
|
331
|
+
},
|
|
332
|
+
children: [
|
|
333
|
+
!k && /* @__PURE__ */ H(j.Sider, {
|
|
334
|
+
collapsible: !0,
|
|
335
|
+
collapsed: w,
|
|
336
|
+
onCollapse: ne,
|
|
337
|
+
collapsedWidth: 64,
|
|
338
|
+
style: {
|
|
339
|
+
background: oe,
|
|
340
|
+
borderInlineEnd: y ? `1px solid ${A.colorSplit}` : void 0
|
|
341
|
+
},
|
|
342
|
+
children: [/* @__PURE__ */ V("div", {
|
|
343
|
+
style: {
|
|
344
|
+
height: 64,
|
|
345
|
+
display: "flex",
|
|
346
|
+
alignItems: "center",
|
|
347
|
+
justifyContent: "center",
|
|
348
|
+
fontWeight: 600
|
|
349
|
+
},
|
|
350
|
+
children: /* @__PURE__ */ V(R.Text, {
|
|
351
|
+
strong: !0,
|
|
352
|
+
style: { color: A.colorTextLightSolid },
|
|
353
|
+
children: w ? n : t
|
|
354
|
+
})
|
|
355
|
+
}), /* @__PURE__ */ V(Qe, {
|
|
356
|
+
menuItems: F,
|
|
357
|
+
selectedKeys: se,
|
|
358
|
+
inlineCollapsed: w,
|
|
359
|
+
openKeys: L,
|
|
360
|
+
onOpenChange: ie,
|
|
361
|
+
onNavigate: W
|
|
362
|
+
})]
|
|
363
|
+
}),
|
|
364
|
+
k && /* @__PURE__ */ V(T, {
|
|
365
|
+
title: /* @__PURE__ */ V(R.Text, {
|
|
366
|
+
strong: !0,
|
|
367
|
+
style: { color: A.colorTextLightSolid },
|
|
368
|
+
children: te
|
|
369
|
+
}),
|
|
370
|
+
placement: "left",
|
|
371
|
+
size: 280,
|
|
372
|
+
onClose: () => O(!1),
|
|
373
|
+
open: D,
|
|
374
|
+
styles: {
|
|
375
|
+
header: {
|
|
376
|
+
background: oe,
|
|
377
|
+
borderBottom: `1px solid ${A.colorSplit}`
|
|
378
|
+
},
|
|
379
|
+
body: {
|
|
380
|
+
padding: 0,
|
|
381
|
+
background: oe
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
destroyOnHidden: !0,
|
|
385
|
+
children: /* @__PURE__ */ V(Qe, {
|
|
386
|
+
menuItems: F,
|
|
387
|
+
selectedKeys: se,
|
|
388
|
+
inlineCollapsed: !1,
|
|
389
|
+
openKeys: L,
|
|
390
|
+
onOpenChange: ie,
|
|
391
|
+
onNavigate: W
|
|
392
|
+
})
|
|
393
|
+
}),
|
|
394
|
+
/* @__PURE__ */ H(j, { children: [/* @__PURE__ */ H(j.Header, {
|
|
395
|
+
style: {
|
|
396
|
+
background: A.colorBgContainer,
|
|
397
|
+
paddingInline: A.paddingLG,
|
|
398
|
+
display: "flex",
|
|
399
|
+
alignItems: "center",
|
|
400
|
+
gap: A.marginSM,
|
|
401
|
+
lineHeight: "normal"
|
|
402
|
+
},
|
|
403
|
+
children: [
|
|
404
|
+
k && /* @__PURE__ */ V(x, {
|
|
405
|
+
type: "text",
|
|
406
|
+
icon: /* @__PURE__ */ V(de, {}),
|
|
407
|
+
onClick: () => O(!0),
|
|
408
|
+
"aria-label": "Open navigation"
|
|
409
|
+
}),
|
|
410
|
+
/* @__PURE__ */ V("div", { style: {
|
|
411
|
+
flex: 1,
|
|
412
|
+
minWidth: 0
|
|
413
|
+
} }),
|
|
414
|
+
a,
|
|
415
|
+
/* @__PURE__ */ V(Pe, {}),
|
|
416
|
+
/* @__PURE__ */ V(ee, {
|
|
417
|
+
menu: {
|
|
418
|
+
items: B,
|
|
419
|
+
onClick: U
|
|
420
|
+
},
|
|
421
|
+
trigger: ["click"],
|
|
422
|
+
children: /* @__PURE__ */ H(x, {
|
|
423
|
+
type: "text",
|
|
424
|
+
style: {
|
|
425
|
+
display: "inline-flex",
|
|
426
|
+
alignItems: "center",
|
|
427
|
+
gap: A.marginXS,
|
|
428
|
+
maxWidth: k ? 44 : void 0,
|
|
429
|
+
paddingInline: k ? A.paddingXS : void 0
|
|
430
|
+
},
|
|
431
|
+
"aria-label": "Account menu",
|
|
432
|
+
children: [/* @__PURE__ */ V(b, {
|
|
433
|
+
size: "small",
|
|
434
|
+
icon: /* @__PURE__ */ V(he, {})
|
|
435
|
+
}), !k && /* @__PURE__ */ V(R.Text, {
|
|
436
|
+
type: "secondary",
|
|
437
|
+
children: "User"
|
|
438
|
+
})]
|
|
439
|
+
})
|
|
440
|
+
})
|
|
441
|
+
]
|
|
442
|
+
}), /* @__PURE__ */ V(j.Content, {
|
|
443
|
+
style: { margin: k ? A.marginSM : A.marginLG },
|
|
444
|
+
children: /* @__PURE__ */ V(f, {})
|
|
445
|
+
})] })
|
|
446
|
+
]
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region src/router/guards.tsx
|
|
451
|
+
function et({ when: e, redirect: t, children: n }) {
|
|
452
|
+
return e ? n : /* @__PURE__ */ V(d, {
|
|
453
|
+
to: t,
|
|
454
|
+
replace: !0
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
function tt({ children: e, redirectTo: t = "/login" }) {
|
|
458
|
+
let { isAuthenticated: n } = Le();
|
|
459
|
+
return /* @__PURE__ */ V(et, {
|
|
460
|
+
when: n,
|
|
461
|
+
redirect: t,
|
|
462
|
+
children: e
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
function nt({ children: e, redirectTo: t = "/" }) {
|
|
466
|
+
let { isAuthenticated: n } = Le();
|
|
467
|
+
return /* @__PURE__ */ V(et, {
|
|
468
|
+
when: !n,
|
|
469
|
+
redirect: t,
|
|
470
|
+
children: e
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
function rt({ permission: e, redirect: t, children: n }) {
|
|
474
|
+
return /* @__PURE__ */ V(et, {
|
|
475
|
+
when: q()(e),
|
|
476
|
+
redirect: t,
|
|
477
|
+
children: n
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/router/routeAccess.ts
|
|
482
|
+
function it(e) {
|
|
483
|
+
return e.access ?? "protected";
|
|
484
|
+
}
|
|
485
|
+
function at(e) {
|
|
486
|
+
let t = [], n = [], r = [];
|
|
487
|
+
for (let i of e) {
|
|
488
|
+
let e = it(i);
|
|
489
|
+
e === "guest" ? t.push(i) : e === "public" ? n.push(i) : r.push(i);
|
|
490
|
+
}
|
|
491
|
+
return {
|
|
492
|
+
guest: t,
|
|
493
|
+
public: n,
|
|
494
|
+
protected: r
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
function ot(e) {
|
|
498
|
+
return e.replace(/^\/+/, "");
|
|
499
|
+
}
|
|
500
|
+
function st(e) {
|
|
501
|
+
return `/${ot(e)}`;
|
|
502
|
+
}
|
|
503
|
+
function ct(e, t) {
|
|
504
|
+
let { guest: n, protected: r } = at(e), i = n.find((e) => "path" in e && e.path), a = r.find((e) => "index" in e && e.index), o = r.find((e) => "path" in e && e.path), s = t?.unauthenticated;
|
|
505
|
+
!s && i && "path" in i && i.path && (s = st(i.path));
|
|
506
|
+
let c = t?.afterLogin;
|
|
507
|
+
if (c || (a ? c = "/" : o && "path" in o && o.path && (c = st(o.path))), r.length > 0 && !s) throw Error("createAdminRouter: protected routes require redirects.unauthenticated or a guest route (access: \"guest\").");
|
|
508
|
+
if (n.length > 0 && !c) throw Error("createAdminRouter: guest routes require redirects.afterLogin or a protected route (index or path).");
|
|
509
|
+
return {
|
|
510
|
+
loginPath: s ?? "/",
|
|
511
|
+
homePath: c ?? "/"
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
function lt(e) {
|
|
515
|
+
return "index" in e && e.index ? {
|
|
516
|
+
index: !0,
|
|
517
|
+
element: e.element
|
|
518
|
+
} : {
|
|
519
|
+
path: e.path,
|
|
520
|
+
element: e.element
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region src/router/createAdminRouter.tsx
|
|
525
|
+
function ut({ navItems: e, children: t, layoutProps: n, redirects: r }) {
|
|
526
|
+
let { loginPath: i, homePath: a } = ct(t, r), { guest: o, public: s, protected: c } = at(t), l = [];
|
|
527
|
+
for (let e of o) !("path" in e) || !e.path || l.push({
|
|
528
|
+
path: ot(e.path),
|
|
529
|
+
element: /* @__PURE__ */ V(nt, {
|
|
530
|
+
redirectTo: a,
|
|
531
|
+
children: e.element
|
|
532
|
+
})
|
|
533
|
+
});
|
|
534
|
+
for (let e of s) !("path" in e) || !e.path || l.push({
|
|
535
|
+
path: ot(e.path),
|
|
536
|
+
element: e.element
|
|
537
|
+
});
|
|
538
|
+
return c.length > 0 && l.push({
|
|
539
|
+
path: "/",
|
|
540
|
+
element: /* @__PURE__ */ V(tt, {
|
|
541
|
+
redirectTo: i,
|
|
542
|
+
children: /* @__PURE__ */ V($e, {
|
|
543
|
+
navItems: e,
|
|
544
|
+
loginPath: i,
|
|
545
|
+
...n
|
|
546
|
+
})
|
|
547
|
+
}),
|
|
548
|
+
children: c.map(lt)
|
|
549
|
+
}), l.push({
|
|
550
|
+
path: "*",
|
|
551
|
+
element: /* @__PURE__ */ V(d, {
|
|
552
|
+
to: a,
|
|
553
|
+
replace: !0
|
|
554
|
+
})
|
|
555
|
+
}), m(l);
|
|
556
|
+
}
|
|
557
|
+
//#endregion
|
|
558
|
+
//#region src/app/AdminApp.tsx
|
|
559
|
+
function dt({ navItems: e, routes: t, authRedirects: n, layoutProps: r, theme: i }) {
|
|
560
|
+
let a = s(() => ut({
|
|
561
|
+
navItems: e,
|
|
562
|
+
children: t,
|
|
563
|
+
layoutProps: r,
|
|
564
|
+
redirects: n
|
|
565
|
+
}), [
|
|
566
|
+
e,
|
|
567
|
+
t,
|
|
568
|
+
r,
|
|
569
|
+
n
|
|
570
|
+
]);
|
|
571
|
+
return /* @__PURE__ */ V(Oe, {
|
|
572
|
+
...i,
|
|
573
|
+
children: /* @__PURE__ */ V(p, { router: a })
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
//#endregion
|
|
577
|
+
//#region src/context/DataProvider.tsx
|
|
578
|
+
var ft = t(null);
|
|
579
|
+
function pt({ children: e, value: t }) {
|
|
580
|
+
let n = s(() => t, [t]);
|
|
581
|
+
return /* @__PURE__ */ V(ft.Provider, {
|
|
582
|
+
value: n,
|
|
583
|
+
children: e
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
function mt() {
|
|
587
|
+
let e = a(ft);
|
|
588
|
+
if (!e) throw Error("useDataProvider must be used within DataProvider");
|
|
589
|
+
return e;
|
|
590
|
+
}
|
|
591
|
+
//#endregion
|
|
592
|
+
//#region src/data/resourceHandlers.ts
|
|
593
|
+
function ht(e) {
|
|
594
|
+
return "handlers" in e ? e : { handlers: e };
|
|
595
|
+
}
|
|
596
|
+
function gt(e, t, n) {
|
|
597
|
+
if (!(!e || !t) && !J(e, t, n)) throw Error("Forbidden");
|
|
598
|
+
}
|
|
599
|
+
function _t(e, t) {
|
|
600
|
+
let { can: n, guard: r, parseFormError: i } = t ?? {}, a = (t) => {
|
|
601
|
+
let n = e[t];
|
|
602
|
+
if (!n) throw Error(`Unknown resource: ${t}`);
|
|
603
|
+
return ht(n);
|
|
604
|
+
};
|
|
605
|
+
return {
|
|
606
|
+
async getList(e, t) {
|
|
607
|
+
let { handlers: i, permissions: o } = a(e);
|
|
608
|
+
return r?.(e, "list"), gt(n, o, "list"), i.getList(t);
|
|
609
|
+
},
|
|
610
|
+
async getOne(e, t) {
|
|
611
|
+
let { handlers: i, permissions: o } = a(e);
|
|
612
|
+
return r?.(e, "read"), gt(n, o, "read"), i.getOne(t);
|
|
613
|
+
},
|
|
614
|
+
async create(e, t) {
|
|
615
|
+
let { handlers: i, permissions: o } = a(e);
|
|
616
|
+
return r?.(e, "add"), gt(n, o, "add"), i.create(t);
|
|
617
|
+
},
|
|
618
|
+
async update(e, t) {
|
|
619
|
+
let { handlers: i, permissions: o } = a(e);
|
|
620
|
+
return r?.(e, "change"), gt(n, o, "change"), i.update(t);
|
|
621
|
+
},
|
|
622
|
+
async delete(e, t) {
|
|
623
|
+
let { handlers: i, permissions: o } = a(e);
|
|
624
|
+
return r?.(e, "delete"), gt(n, o, "delete"), i.delete(t);
|
|
625
|
+
},
|
|
626
|
+
parseFormError: i
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
//#endregion
|
|
630
|
+
//#region src/data/parseFormErrorHelpers.ts
|
|
631
|
+
function Y(e) {
|
|
632
|
+
if (typeof e == "string") return [e];
|
|
633
|
+
if (Array.isArray(e)) {
|
|
634
|
+
let t = e.filter((e) => typeof e == "string");
|
|
635
|
+
if (t.length) return t;
|
|
636
|
+
}
|
|
637
|
+
return [];
|
|
638
|
+
}
|
|
639
|
+
function vt(e) {
|
|
640
|
+
return e.length === 1 ? e[0] : e;
|
|
641
|
+
}
|
|
642
|
+
function yt(e) {
|
|
643
|
+
if (!e || typeof e != "object") return null;
|
|
644
|
+
let t = e;
|
|
645
|
+
if (t.body && typeof t.body == "object" && !Array.isArray(t.body)) return t.body;
|
|
646
|
+
let n = t.response;
|
|
647
|
+
if (n && typeof n == "object" && !Array.isArray(n)) {
|
|
648
|
+
let e = n.data;
|
|
649
|
+
if (e && typeof e == "object" && !Array.isArray(e)) return e;
|
|
650
|
+
}
|
|
651
|
+
return null;
|
|
652
|
+
}
|
|
653
|
+
function bt(e, t) {
|
|
654
|
+
if (t.inlineArrayName == null || t.rowIndex == null) return e;
|
|
655
|
+
let n = `${t.inlineArrayName}.${t.rowIndex}.`, r = {};
|
|
656
|
+
for (let [t, i] of Object.entries(e)) r[n + t] = i;
|
|
657
|
+
return r;
|
|
658
|
+
}
|
|
659
|
+
function xt(e, t, n) {
|
|
660
|
+
let r = bt(e, n);
|
|
661
|
+
return {
|
|
662
|
+
fields: Object.keys(r).length ? r : void 0,
|
|
663
|
+
global: t.length ? t : void 0
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
var St = new Set(["non_field_errors", "detail"]);
|
|
667
|
+
function Ct(e, t) {
|
|
668
|
+
let n = yt(e);
|
|
669
|
+
if (!n) return null;
|
|
670
|
+
let r = {}, i = [];
|
|
671
|
+
for (let [e, t] of Object.entries(n)) {
|
|
672
|
+
if (St.has(e)) {
|
|
673
|
+
i.push(...Y(t));
|
|
674
|
+
continue;
|
|
675
|
+
}
|
|
676
|
+
let n = Y(t);
|
|
677
|
+
n.length && (r[e] = vt(n));
|
|
678
|
+
}
|
|
679
|
+
return !Object.keys(r).length && !i.length ? null : xt(r, i, t);
|
|
680
|
+
}
|
|
681
|
+
function wt(e, t, n) {
|
|
682
|
+
let r = yt(e);
|
|
683
|
+
if (!r) return null;
|
|
684
|
+
let i = n?.camelCase ?? !0, a = n?.fieldMap, o = {}, s = [];
|
|
685
|
+
n?.includeSummary && (s.push(...Y(r.title)), s.push(...Y(r.message)));
|
|
686
|
+
let c = r.errors;
|
|
687
|
+
if (c && typeof c == "object" && !Array.isArray(c)) for (let [e, t] of Object.entries(c)) {
|
|
688
|
+
let n = a?.[e] ?? (i ? Dt(e) : e), r = Y(t);
|
|
689
|
+
r.length && (o[n] = vt(r));
|
|
690
|
+
}
|
|
691
|
+
return !Object.keys(o).length && !s.length ? null : xt(o, s, t);
|
|
692
|
+
}
|
|
693
|
+
function Tt(e, t, n) {
|
|
694
|
+
let r = yt(e);
|
|
695
|
+
if (!r) return null;
|
|
696
|
+
let i = {}, a = [], o = n?.fieldMap, s = r.errors;
|
|
697
|
+
if (Array.isArray(s)) for (let e of s) {
|
|
698
|
+
if (!e || typeof e != "object") continue;
|
|
699
|
+
let t = e, n = typeof t.path == "string" && t.path || typeof t.param == "string" && t.param || typeof t.field == "string" && t.field, r = Y(t.msg)[0] ?? Y(t.message)[0];
|
|
700
|
+
r && (n ? Et(i, o?.[n] ?? n, r) : a.push(r));
|
|
701
|
+
}
|
|
702
|
+
else if (s && typeof s == "object") for (let [e, t] of Object.entries(s)) {
|
|
703
|
+
let n = o?.[e] ?? e, r = Y(t);
|
|
704
|
+
r.length && (i[n] = vt(r));
|
|
705
|
+
}
|
|
706
|
+
let c = r.details;
|
|
707
|
+
if (Array.isArray(c)) for (let e of c) {
|
|
708
|
+
if (!e || typeof e != "object") continue;
|
|
709
|
+
let t = e, n = (Array.isArray(t.path) ? t.path : []).map((e) => String(e)).join("."), r = Y(t.message)[0];
|
|
710
|
+
if (r) if (n) {
|
|
711
|
+
let e = o?.[n] ?? n;
|
|
712
|
+
i[e] = r;
|
|
713
|
+
} else a.push(r);
|
|
714
|
+
}
|
|
715
|
+
return a.push(...Y(r.error)), !Object.keys(i).length && !a.length ? null : xt(i, a, t);
|
|
716
|
+
}
|
|
717
|
+
function Et(e, t, n) {
|
|
718
|
+
let r = e[t];
|
|
719
|
+
if (!r) {
|
|
720
|
+
e[t] = n;
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
e[t] = Array.isArray(r) ? [...r, n] : [r, n];
|
|
724
|
+
}
|
|
725
|
+
function Dt(e) {
|
|
726
|
+
return e && e.charAt(0).toLowerCase() + e.slice(1);
|
|
727
|
+
}
|
|
728
|
+
//#endregion
|
|
729
|
+
//#region src/data/inMemoryList.ts
|
|
730
|
+
function Ot(e, t) {
|
|
731
|
+
return e === t || String(e) === String(t);
|
|
732
|
+
}
|
|
733
|
+
function kt(e, t) {
|
|
734
|
+
let n = e.find((e) => Ot(e.id, t));
|
|
735
|
+
if (!n) throw Error("Not found");
|
|
736
|
+
return n;
|
|
737
|
+
}
|
|
738
|
+
function At(e, t) {
|
|
739
|
+
if (t.length === 0) return e;
|
|
740
|
+
let n = (e) => e === "DESC" ? -1 : 1;
|
|
741
|
+
return [...e].sort((e, r) => {
|
|
742
|
+
for (let { field: i, order: a } of t) {
|
|
743
|
+
let t = e[i], o = r[i];
|
|
744
|
+
if (t === o) continue;
|
|
745
|
+
if (t == null) return -1 * n(a);
|
|
746
|
+
if (o == null) return 1 * n(a);
|
|
747
|
+
if (typeof t == "number" && typeof o == "number") return t < o ? -n(a) : n(a);
|
|
748
|
+
let s = String(t).localeCompare(String(o));
|
|
749
|
+
if (s !== 0) return s * n(a);
|
|
750
|
+
}
|
|
751
|
+
return 0;
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
function jt(e, t) {
|
|
755
|
+
return t == null || t === "" ? !0 : Array.isArray(t) ? t.length === 0 ? !0 : Array.isArray(e) ? t.some((t) => e.includes(t)) : t.includes(e) : Array.isArray(e) ? e.includes(t) : typeof t == "string" && typeof e == "string" ? e.toLowerCase().includes(t.toLowerCase()) : e === t;
|
|
756
|
+
}
|
|
757
|
+
function Mt(e, t) {
|
|
758
|
+
return t ? e.filter((e) => Object.entries(t).every(([t, n]) => jt(e[t], n))) : e;
|
|
759
|
+
}
|
|
760
|
+
function Nt(e, t, n) {
|
|
761
|
+
let r = (t - 1) * n;
|
|
762
|
+
return {
|
|
763
|
+
data: e.slice(r, r + n),
|
|
764
|
+
total: e.length
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
function Pt(e, t) {
|
|
768
|
+
let { pagination: n, sort: r, filter: i } = t, a = Mt(e, i);
|
|
769
|
+
if (r) {
|
|
770
|
+
let e = Array.isArray(r) ? r : [r];
|
|
771
|
+
e.length > 0 && e[0]?.field && (a = At(a, e));
|
|
772
|
+
}
|
|
773
|
+
return n ? Nt(a, n.page, n.perPage) : {
|
|
774
|
+
data: a,
|
|
775
|
+
total: a.length
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
//#endregion
|
|
779
|
+
//#region src/data/createMemoryResourceHandlers.ts
|
|
780
|
+
function Ft(e) {
|
|
781
|
+
let t = (e) => e, n = e.mapCreate ?? ((e, t) => ({
|
|
782
|
+
...e,
|
|
783
|
+
id: t
|
|
784
|
+
})), r = e.applyUpdate ?? ((e, t) => ({
|
|
785
|
+
...e,
|
|
786
|
+
...t,
|
|
787
|
+
id: e.id
|
|
788
|
+
}));
|
|
789
|
+
return {
|
|
790
|
+
async getList(n) {
|
|
791
|
+
return Pt(t(e.scopeList ? e.scopeList(e.getRows(), n) : e.getRows()), n);
|
|
792
|
+
},
|
|
793
|
+
async getOne(t) {
|
|
794
|
+
return { data: kt(e.getRows(), t) };
|
|
795
|
+
},
|
|
796
|
+
async create(t) {
|
|
797
|
+
let r = n(t, e.nextId());
|
|
798
|
+
return e.getRows().push(r), { data: r };
|
|
799
|
+
},
|
|
800
|
+
async update({ id: t, data: n }) {
|
|
801
|
+
let i = kt(e.getRows(), t), a = r(i, n);
|
|
802
|
+
return Object.assign(i, a), { data: i };
|
|
803
|
+
},
|
|
804
|
+
async delete(t) {
|
|
805
|
+
let n = e.getRows(), r = n.findIndex((e) => Ot(e.id, t));
|
|
806
|
+
if (r < 0) return { data: null };
|
|
807
|
+
let [i] = n.splice(r, 1);
|
|
808
|
+
return e.afterDelete?.(i), { data: i };
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
//#endregion
|
|
813
|
+
//#region src/data/createRestResourceHandlers.ts
|
|
814
|
+
function It(e) {
|
|
815
|
+
return {
|
|
816
|
+
async getList(t) {
|
|
817
|
+
return e.list(t);
|
|
818
|
+
},
|
|
819
|
+
async getOne(t) {
|
|
820
|
+
return { data: await e.retrieve(t) };
|
|
821
|
+
},
|
|
822
|
+
async create(t) {
|
|
823
|
+
let n = e.transformCreate ? e.transformCreate(t) : t;
|
|
824
|
+
return { data: await e.create(n) };
|
|
825
|
+
},
|
|
826
|
+
async update({ id: t, data: n }) {
|
|
827
|
+
let r = e.transformUpdate ? e.transformUpdate(n) : n;
|
|
828
|
+
return { data: await e.update(t, r) };
|
|
829
|
+
},
|
|
830
|
+
async delete(t) {
|
|
831
|
+
return await e.destroy(t), { data: null };
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
//#endregion
|
|
836
|
+
//#region src/data/sortHelpers.ts
|
|
837
|
+
function Lt(e) {
|
|
838
|
+
return e ? Array.isArray(e) ? e : [e] : [];
|
|
839
|
+
}
|
|
840
|
+
function Rt(e) {
|
|
841
|
+
let t = Lt(e);
|
|
842
|
+
if (t.length !== 0) return t.map((e) => e.order === "DESC" ? `-${e.field}` : e.field).join(",");
|
|
843
|
+
}
|
|
844
|
+
function zt(e) {
|
|
845
|
+
let t = Lt(e);
|
|
846
|
+
if (t.length !== 0) return t.map((e) => `${e.field} ${e.order === "DESC" ? "desc" : "asc"}`).join(",");
|
|
847
|
+
}
|
|
848
|
+
function Bt(e) {
|
|
849
|
+
let t = Lt(e);
|
|
850
|
+
if (t.length !== 0) return t.map((e) => e.order === "DESC" ? `-${e.field}` : e.field).join(",");
|
|
851
|
+
}
|
|
852
|
+
//#endregion
|
|
853
|
+
//#region src/components/AuthAlternateLink.tsx
|
|
854
|
+
function Vt({ prompt: e, linkText: t, to: n }) {
|
|
855
|
+
return /* @__PURE__ */ H(R.Paragraph, {
|
|
856
|
+
type: "secondary",
|
|
857
|
+
style: {
|
|
858
|
+
textAlign: "center",
|
|
859
|
+
marginBottom: 0
|
|
860
|
+
},
|
|
861
|
+
children: [
|
|
862
|
+
e,
|
|
863
|
+
" ",
|
|
864
|
+
/* @__PURE__ */ V(u, {
|
|
865
|
+
to: n,
|
|
866
|
+
children: t
|
|
867
|
+
})
|
|
868
|
+
]
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
//#endregion
|
|
872
|
+
//#region src/layouts/AuthPageLayout.tsx
|
|
873
|
+
function Ht({ children: e, brand: t, footer: n, showThemeToolbar: r = !0 }) {
|
|
874
|
+
let { token: i } = z.useToken();
|
|
875
|
+
return /* @__PURE__ */ H(E, {
|
|
876
|
+
vertical: !0,
|
|
877
|
+
align: "stretch",
|
|
878
|
+
style: {
|
|
879
|
+
height: "100dvh",
|
|
880
|
+
maxHeight: "100dvh",
|
|
881
|
+
width: "100%",
|
|
882
|
+
overflow: "hidden",
|
|
883
|
+
background: i.colorBgLayout
|
|
884
|
+
},
|
|
885
|
+
children: [
|
|
886
|
+
r ? /* @__PURE__ */ V(E, {
|
|
887
|
+
justify: "flex-end",
|
|
888
|
+
style: {
|
|
889
|
+
flexShrink: 0,
|
|
890
|
+
width: "100%",
|
|
891
|
+
padding: 16,
|
|
892
|
+
background: i.colorBgLayout
|
|
893
|
+
},
|
|
894
|
+
children: /* @__PURE__ */ V(Pe, {})
|
|
895
|
+
}) : null,
|
|
896
|
+
t ? /* @__PURE__ */ V("div", {
|
|
897
|
+
style: {
|
|
898
|
+
flexShrink: 0,
|
|
899
|
+
textAlign: "center",
|
|
900
|
+
padding: "0 24px 16px"
|
|
901
|
+
},
|
|
902
|
+
children: t
|
|
903
|
+
}) : null,
|
|
904
|
+
/* @__PURE__ */ H(E, {
|
|
905
|
+
flex: 1,
|
|
906
|
+
vertical: !0,
|
|
907
|
+
align: "center",
|
|
908
|
+
justify: "flex-start",
|
|
909
|
+
style: {
|
|
910
|
+
width: "100%",
|
|
911
|
+
minHeight: 0,
|
|
912
|
+
padding: "0 24px 24px",
|
|
913
|
+
overflow: "auto",
|
|
914
|
+
overflowX: "hidden",
|
|
915
|
+
background: i.colorBgLayout
|
|
916
|
+
},
|
|
917
|
+
children: [e, n ? /* @__PURE__ */ V("div", {
|
|
918
|
+
style: {
|
|
919
|
+
marginTop: 16,
|
|
920
|
+
width: "100%",
|
|
921
|
+
maxWidth: 520
|
|
922
|
+
},
|
|
923
|
+
children: n
|
|
924
|
+
}) : null]
|
|
925
|
+
})
|
|
926
|
+
]
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
//#endregion
|
|
930
|
+
//#region src/pages/LoginPage.tsx
|
|
931
|
+
function Ut({ title: e = "Sign in", description: t = "Use any username and password to continue.", logo: n, brand: r, extraFields: i, showThemeToolbar: a = !0, afterLoginPath: o = "/", alternateAuth: s, footer: c }) {
|
|
932
|
+
let { login: l } = Le(), u = g();
|
|
933
|
+
return /* @__PURE__ */ V(Ht, {
|
|
934
|
+
brand: r ?? n,
|
|
935
|
+
footer: c ?? (s ? /* @__PURE__ */ V(Vt, {
|
|
936
|
+
prompt: s.prompt ?? "Don't have an account?",
|
|
937
|
+
linkText: s.linkText,
|
|
938
|
+
to: s.to
|
|
939
|
+
}) : null),
|
|
940
|
+
showThemeToolbar: a,
|
|
941
|
+
children: /* @__PURE__ */ H(S, {
|
|
942
|
+
style: {
|
|
943
|
+
width: "100%",
|
|
944
|
+
maxWidth: 360
|
|
945
|
+
},
|
|
946
|
+
title: e,
|
|
947
|
+
children: [t ? /* @__PURE__ */ V(R.Paragraph, {
|
|
948
|
+
type: "secondary",
|
|
949
|
+
style: { marginTop: 0 },
|
|
950
|
+
children: t
|
|
951
|
+
}) : null, /* @__PURE__ */ H(D, {
|
|
952
|
+
layout: "vertical",
|
|
953
|
+
onFinish: async (e) => {
|
|
954
|
+
await l({
|
|
955
|
+
username: String(e.username ?? ""),
|
|
956
|
+
password: String(e.password ?? ""),
|
|
957
|
+
...e
|
|
958
|
+
}), u(o, { replace: !0 });
|
|
959
|
+
},
|
|
960
|
+
children: [
|
|
961
|
+
/* @__PURE__ */ V(D.Item, {
|
|
962
|
+
name: "username",
|
|
963
|
+
label: "Username",
|
|
964
|
+
rules: [{
|
|
965
|
+
required: !0,
|
|
966
|
+
message: "Required"
|
|
967
|
+
}],
|
|
968
|
+
children: /* @__PURE__ */ V(k, { autoComplete: "username" })
|
|
969
|
+
}),
|
|
970
|
+
/* @__PURE__ */ V(D.Item, {
|
|
971
|
+
name: "password",
|
|
972
|
+
label: "Password",
|
|
973
|
+
rules: [{
|
|
974
|
+
required: !0,
|
|
975
|
+
message: "Required"
|
|
976
|
+
}],
|
|
977
|
+
children: /* @__PURE__ */ V(k.Password, { autoComplete: "current-password" })
|
|
978
|
+
}),
|
|
979
|
+
i,
|
|
980
|
+
/* @__PURE__ */ V(D.Item, {
|
|
981
|
+
style: { marginBottom: 0 },
|
|
982
|
+
children: /* @__PURE__ */ V(x, {
|
|
983
|
+
type: "primary",
|
|
984
|
+
htmlType: "submit",
|
|
985
|
+
block: !0,
|
|
986
|
+
children: "Log in"
|
|
987
|
+
})
|
|
988
|
+
})
|
|
989
|
+
]
|
|
990
|
+
})]
|
|
991
|
+
})
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
//#endregion
|
|
995
|
+
//#region src/pages/PlaceholderPage.tsx
|
|
996
|
+
function Wt({ title: e }) {
|
|
997
|
+
return /* @__PURE__ */ V(R.Title, {
|
|
998
|
+
level: 3,
|
|
999
|
+
style: { marginTop: 0 },
|
|
1000
|
+
children: e
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
//#endregion
|
|
1004
|
+
//#region src/crud/utils/sortQueryParam.ts
|
|
1005
|
+
function Gt(e) {
|
|
1006
|
+
if (!e) return [];
|
|
1007
|
+
let t = [];
|
|
1008
|
+
for (let n of e.split(",").map((e) => e.trim()).filter(Boolean)) {
|
|
1009
|
+
if (n.includes(":")) {
|
|
1010
|
+
let [e, r] = n.split(":");
|
|
1011
|
+
if (!e) continue;
|
|
1012
|
+
let i = r?.toLowerCase() === "desc" ? "DESC" : "ASC";
|
|
1013
|
+
t.push({
|
|
1014
|
+
field: e,
|
|
1015
|
+
order: i
|
|
1016
|
+
});
|
|
1017
|
+
continue;
|
|
1018
|
+
}
|
|
1019
|
+
n.startsWith("-") && n.length > 1 ? t.push({
|
|
1020
|
+
field: n.slice(1),
|
|
1021
|
+
order: "DESC"
|
|
1022
|
+
}) : t.push({
|
|
1023
|
+
field: n,
|
|
1024
|
+
order: "ASC"
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
return t;
|
|
1028
|
+
}
|
|
1029
|
+
function Kt(e) {
|
|
1030
|
+
return e.length === 0 ? null : e.map((e) => e.order === "DESC" ? `-${e.field}` : e.field).join(",");
|
|
1031
|
+
}
|
|
1032
|
+
function qt(e) {
|
|
1033
|
+
return new Map(e.map((e, t) => [e.field, t + 1]));
|
|
1034
|
+
}
|
|
1035
|
+
//#endregion
|
|
1036
|
+
//#region src/crud/context/ListContext.tsx
|
|
1037
|
+
var Jt = t(null);
|
|
1038
|
+
function Yt({ children: e, toggleSort: t, sort: n }) {
|
|
1039
|
+
let [r, a] = l([]), o = s(() => new Set(n.map((e) => e.field)), [n]), c = s(() => new Map(n.map((e) => [e.field, e.order])), [n]), u = s(() => qt(n), [n]), d = i((e) => (a((t) => {
|
|
1040
|
+
let n = t.findIndex((t) => t.key === e.key);
|
|
1041
|
+
if (n < 0) return [...t, e];
|
|
1042
|
+
if (t[n] === e) return t;
|
|
1043
|
+
let r = [...t];
|
|
1044
|
+
return r[n] = e, r;
|
|
1045
|
+
}), () => {
|
|
1046
|
+
a((t) => t.filter((t) => t.key !== e.key));
|
|
1047
|
+
}), []), f = s(() => ({
|
|
1048
|
+
columns: r,
|
|
1049
|
+
toggleSort: t,
|
|
1050
|
+
sortFields: o,
|
|
1051
|
+
sortOrders: c,
|
|
1052
|
+
sortPriorities: u,
|
|
1053
|
+
registerColumn: d
|
|
1054
|
+
}), [
|
|
1055
|
+
r,
|
|
1056
|
+
t,
|
|
1057
|
+
o,
|
|
1058
|
+
c,
|
|
1059
|
+
u,
|
|
1060
|
+
d
|
|
1061
|
+
]);
|
|
1062
|
+
return /* @__PURE__ */ V(Jt.Provider, {
|
|
1063
|
+
value: f,
|
|
1064
|
+
children: e
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
function Xt() {
|
|
1068
|
+
let e = a(Jt);
|
|
1069
|
+
if (!e) throw Error("Column components must be used within ResourceList");
|
|
1070
|
+
return e;
|
|
1071
|
+
}
|
|
1072
|
+
function X(e) {
|
|
1073
|
+
let { registerColumn: t } = Xt();
|
|
1074
|
+
o(() => t(e), [t, e]);
|
|
1075
|
+
}
|
|
1076
|
+
//#endregion
|
|
1077
|
+
//#region src/crud/context/FilterContext.tsx
|
|
1078
|
+
var Zt = t(null);
|
|
1079
|
+
function Qt({ children: e, values: t, setFilterValue: n }) {
|
|
1080
|
+
let [r, a] = l([]), o = i((e) => (a((t) => {
|
|
1081
|
+
let n = t.findIndex((t) => t.key === e.key);
|
|
1082
|
+
if (n < 0) return [...t, e];
|
|
1083
|
+
if (t[n] === e) return t;
|
|
1084
|
+
let r = [...t];
|
|
1085
|
+
return r[n] = e, r;
|
|
1086
|
+
}), () => {
|
|
1087
|
+
a((t) => t.filter((t) => t.key !== e.key));
|
|
1088
|
+
}), []), c = s(() => ({
|
|
1089
|
+
filters: r,
|
|
1090
|
+
values: t,
|
|
1091
|
+
setFilterValue: n,
|
|
1092
|
+
registerFilter: o
|
|
1093
|
+
}), [
|
|
1094
|
+
r,
|
|
1095
|
+
t,
|
|
1096
|
+
n,
|
|
1097
|
+
o
|
|
1098
|
+
]);
|
|
1099
|
+
return /* @__PURE__ */ V(Zt.Provider, {
|
|
1100
|
+
value: c,
|
|
1101
|
+
children: e
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
function $t() {
|
|
1105
|
+
return a(Zt);
|
|
1106
|
+
}
|
|
1107
|
+
function Z(e) {
|
|
1108
|
+
let t = $t()?.registerFilter;
|
|
1109
|
+
o(() => {
|
|
1110
|
+
if (t) return t(e);
|
|
1111
|
+
}, [t, e]);
|
|
1112
|
+
}
|
|
1113
|
+
//#endregion
|
|
1114
|
+
//#region src/crud/context/FormContext.tsx
|
|
1115
|
+
var en = t(null);
|
|
1116
|
+
function tn({ children: e, resource: t, isNew: n, disabled: r }) {
|
|
1117
|
+
return /* @__PURE__ */ V(en.Provider, {
|
|
1118
|
+
value: {
|
|
1119
|
+
resource: t,
|
|
1120
|
+
isNew: n,
|
|
1121
|
+
disabled: r
|
|
1122
|
+
},
|
|
1123
|
+
children: e
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
function nn() {
|
|
1127
|
+
return a(en);
|
|
1128
|
+
}
|
|
1129
|
+
//#endregion
|
|
1130
|
+
//#region src/crud/context/FormSectionContext.tsx
|
|
1131
|
+
var rn = t(null);
|
|
1132
|
+
function an({ sourcesRef: e, children: t }) {
|
|
1133
|
+
return /* @__PURE__ */ V(rn.Provider, {
|
|
1134
|
+
value: e,
|
|
1135
|
+
children: t
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
function on() {
|
|
1139
|
+
return a(rn);
|
|
1140
|
+
}
|
|
1141
|
+
//#endregion
|
|
1142
|
+
//#region src/crud/context/FormFieldsContext.tsx
|
|
1143
|
+
var sn = t(null);
|
|
1144
|
+
function cn({ children: e, sourcesRef: t }) {
|
|
1145
|
+
let n = c(/* @__PURE__ */ new Set()), r = t ?? n, a = i((e) => (r.current.add(e), () => {
|
|
1146
|
+
r.current.delete(e);
|
|
1147
|
+
}), [r]), o = i(() => Array.from(r.current), [r]), l = s(() => ({
|
|
1148
|
+
registerSource: a,
|
|
1149
|
+
getSources: o
|
|
1150
|
+
}), [a, o]);
|
|
1151
|
+
return /* @__PURE__ */ V(sn.Provider, {
|
|
1152
|
+
value: l,
|
|
1153
|
+
children: e
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1156
|
+
function ln() {
|
|
1157
|
+
return a(sn);
|
|
1158
|
+
}
|
|
1159
|
+
function un(e) {
|
|
1160
|
+
let t = ln()?.registerSource, n = on();
|
|
1161
|
+
o(() => {
|
|
1162
|
+
if (!t) return;
|
|
1163
|
+
let r = t(e);
|
|
1164
|
+
return n?.current.add(e), () => {
|
|
1165
|
+
r(), n?.current.delete(e);
|
|
1166
|
+
};
|
|
1167
|
+
}, [
|
|
1168
|
+
t,
|
|
1169
|
+
n,
|
|
1170
|
+
e
|
|
1171
|
+
]);
|
|
1172
|
+
}
|
|
1173
|
+
//#endregion
|
|
1174
|
+
//#region src/crud/utils/getByPath.ts
|
|
1175
|
+
function dn(e, t) {
|
|
1176
|
+
let n = t.split("."), r = e;
|
|
1177
|
+
for (let e of n) {
|
|
1178
|
+
if (typeof r != "object" || !r) return;
|
|
1179
|
+
r = r[e];
|
|
1180
|
+
}
|
|
1181
|
+
return r;
|
|
1182
|
+
}
|
|
1183
|
+
//#endregion
|
|
1184
|
+
//#region src/crud/utils/setByPath.ts
|
|
1185
|
+
function fn(e, t, n) {
|
|
1186
|
+
let r = t.split("."), i = e;
|
|
1187
|
+
for (let e = 0; e < r.length - 1; e++) {
|
|
1188
|
+
let t = r[e], n = i[t];
|
|
1189
|
+
(typeof n != "object" || !n || Array.isArray(n)) && (i[t] = {}), i = i[t];
|
|
1190
|
+
}
|
|
1191
|
+
i[r[r.length - 1]] = n;
|
|
1192
|
+
}
|
|
1193
|
+
//#endregion
|
|
1194
|
+
//#region src/crud/utils/pickBySources.ts
|
|
1195
|
+
function pn(e, t) {
|
|
1196
|
+
if (t.length === 0) return { ...e };
|
|
1197
|
+
let n = {};
|
|
1198
|
+
for (let r of t) {
|
|
1199
|
+
let t = dn(e, r);
|
|
1200
|
+
t !== void 0 && fn(n, r, t);
|
|
1201
|
+
}
|
|
1202
|
+
return n;
|
|
1203
|
+
}
|
|
1204
|
+
//#endregion
|
|
1205
|
+
//#region src/crud/utils/formErrors.ts
|
|
1206
|
+
function mn(e) {
|
|
1207
|
+
return e ? Array.isArray(e) ? e : [e] : [];
|
|
1208
|
+
}
|
|
1209
|
+
function hn(e, t, n) {
|
|
1210
|
+
for (let e of mn(t.global)) n.error(e);
|
|
1211
|
+
for (let [n, r] of Object.entries(t.fields ?? {})) {
|
|
1212
|
+
let t = Array.isArray(r) ? r.join(", ") : r;
|
|
1213
|
+
e.setError(n, {
|
|
1214
|
+
type: "server",
|
|
1215
|
+
message: t
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
function gn(e, t, n, r, i) {
|
|
1220
|
+
let a = e.parseFormError?.(r, i);
|
|
1221
|
+
if (!a) return !1;
|
|
1222
|
+
let o = Object.keys(a.fields ?? {}).length > 0, s = mn(a.global).length > 0;
|
|
1223
|
+
return !o && !s ? !1 : (hn(t, a, n), !0);
|
|
1224
|
+
}
|
|
1225
|
+
//#endregion
|
|
1226
|
+
//#region src/crud/ResourceFormModal.tsx
|
|
1227
|
+
function _n({ resource: e, editId: t, onClose: n, children: r, title: a }) {
|
|
1228
|
+
let s = t === "new" || t == null, u = t != null, d = mt(), { message: f } = y.useApp(), [p, m] = l(!s), h = ye(), g = c(/* @__PURE__ */ new Set()), _ = i(async () => {
|
|
1229
|
+
if (s || !t) {
|
|
1230
|
+
h.reset({}), m(!1);
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
m(!0);
|
|
1234
|
+
try {
|
|
1235
|
+
let n = await d.getOne(e, t);
|
|
1236
|
+
h.reset(n.data);
|
|
1237
|
+
} catch (e) {
|
|
1238
|
+
f.error(e instanceof Error ? e.message : "Load failed");
|
|
1239
|
+
} finally {
|
|
1240
|
+
m(!1);
|
|
1241
|
+
}
|
|
1242
|
+
}, [
|
|
1243
|
+
d,
|
|
1244
|
+
e,
|
|
1245
|
+
t,
|
|
1246
|
+
s,
|
|
1247
|
+
h,
|
|
1248
|
+
f
|
|
1249
|
+
]);
|
|
1250
|
+
o(() => {
|
|
1251
|
+
u && _();
|
|
1252
|
+
}, [u, _]);
|
|
1253
|
+
async function v(r) {
|
|
1254
|
+
try {
|
|
1255
|
+
let i = pn(r, Array.from(g.current));
|
|
1256
|
+
s ? (await d.create(e, i), f.success("Created")) : t && (await d.update(e, {
|
|
1257
|
+
id: t,
|
|
1258
|
+
data: i
|
|
1259
|
+
}), f.success("Updated")), n();
|
|
1260
|
+
} catch (t) {
|
|
1261
|
+
gn(d, h, f, t, {
|
|
1262
|
+
resource: e,
|
|
1263
|
+
mutation: s ? "create" : "update"
|
|
1264
|
+
}) || f.error(t instanceof Error ? t.message : "Save failed");
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
return /* @__PURE__ */ V(M, {
|
|
1268
|
+
open: u,
|
|
1269
|
+
title: a ?? (s ? `New ${e}` : `Edit ${e}`),
|
|
1270
|
+
onCancel: n,
|
|
1271
|
+
footer: null,
|
|
1272
|
+
destroyOnHidden: !0,
|
|
1273
|
+
width: 560,
|
|
1274
|
+
children: p ? /* @__PURE__ */ V(I, {}) : /* @__PURE__ */ V(tn, {
|
|
1275
|
+
resource: e,
|
|
1276
|
+
isNew: s,
|
|
1277
|
+
children: /* @__PURE__ */ V(cn, {
|
|
1278
|
+
sourcesRef: g,
|
|
1279
|
+
children: /* @__PURE__ */ V(_e, {
|
|
1280
|
+
...h,
|
|
1281
|
+
children: /* @__PURE__ */ H(D, {
|
|
1282
|
+
layout: "vertical",
|
|
1283
|
+
onFinish: () => void h.handleSubmit(v)(),
|
|
1284
|
+
children: [r, /* @__PURE__ */ H(D.Item, {
|
|
1285
|
+
style: {
|
|
1286
|
+
marginTop: 16,
|
|
1287
|
+
marginBottom: 0
|
|
1288
|
+
},
|
|
1289
|
+
children: [/* @__PURE__ */ V(x, {
|
|
1290
|
+
type: "primary",
|
|
1291
|
+
htmlType: "submit",
|
|
1292
|
+
style: { marginRight: 8 },
|
|
1293
|
+
children: "Save"
|
|
1294
|
+
}), /* @__PURE__ */ V(x, {
|
|
1295
|
+
onClick: n,
|
|
1296
|
+
children: "Cancel"
|
|
1297
|
+
})]
|
|
1298
|
+
})]
|
|
1299
|
+
})
|
|
1300
|
+
})
|
|
1301
|
+
})
|
|
1302
|
+
})
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
//#endregion
|
|
1306
|
+
//#region src/crud/ListActionsBar.tsx
|
|
1307
|
+
function vn({ selectedCount: e, total: t, allPageSelected: n, allMatchingSelected: r, onSelectAllMatching: a, onClearSelection: o, actions: c, onExecute: u, selectedIds: d, running: f = !1 }) {
|
|
1308
|
+
let [p, m] = l(), h = s(() => c.map((e) => ({
|
|
1309
|
+
value: e.key,
|
|
1310
|
+
label: e.label
|
|
1311
|
+
})), [c]), g = i(async () => {
|
|
1312
|
+
let t = c.find((e) => e.key === p);
|
|
1313
|
+
!t || e === 0 || (await u(t, d), m(void 0));
|
|
1314
|
+
}, [
|
|
1315
|
+
c,
|
|
1316
|
+
p,
|
|
1317
|
+
u,
|
|
1318
|
+
e,
|
|
1319
|
+
d
|
|
1320
|
+
]), _ = n && !r && t > e;
|
|
1321
|
+
return /* @__PURE__ */ H(F, {
|
|
1322
|
+
wrap: !0,
|
|
1323
|
+
style: {
|
|
1324
|
+
marginBottom: 16,
|
|
1325
|
+
width: "100%"
|
|
1326
|
+
},
|
|
1327
|
+
align: "center",
|
|
1328
|
+
children: [
|
|
1329
|
+
/* @__PURE__ */ H(R.Text, {
|
|
1330
|
+
type: "secondary",
|
|
1331
|
+
children: [
|
|
1332
|
+
e,
|
|
1333
|
+
" of ",
|
|
1334
|
+
t,
|
|
1335
|
+
" selected"
|
|
1336
|
+
]
|
|
1337
|
+
}),
|
|
1338
|
+
e > 0 ? /* @__PURE__ */ V(x, {
|
|
1339
|
+
type: "link",
|
|
1340
|
+
size: "small",
|
|
1341
|
+
onClick: o,
|
|
1342
|
+
style: { padding: 0 },
|
|
1343
|
+
children: "Clear selection"
|
|
1344
|
+
}) : null,
|
|
1345
|
+
_ ? /* @__PURE__ */ H(B, { children: [/* @__PURE__ */ V(R.Text, {
|
|
1346
|
+
type: "secondary",
|
|
1347
|
+
children: "·"
|
|
1348
|
+
}), /* @__PURE__ */ H(x, {
|
|
1349
|
+
type: "link",
|
|
1350
|
+
size: "small",
|
|
1351
|
+
onClick: a,
|
|
1352
|
+
style: { padding: 0 },
|
|
1353
|
+
children: [
|
|
1354
|
+
"Select all ",
|
|
1355
|
+
t,
|
|
1356
|
+
" items matching filter"
|
|
1357
|
+
]
|
|
1358
|
+
})] }) : null,
|
|
1359
|
+
r && t > 0 ? /* @__PURE__ */ H(B, { children: [/* @__PURE__ */ V(R.Text, {
|
|
1360
|
+
type: "secondary",
|
|
1361
|
+
children: "·"
|
|
1362
|
+
}), /* @__PURE__ */ H(R.Text, {
|
|
1363
|
+
type: "success",
|
|
1364
|
+
children: [
|
|
1365
|
+
"All ",
|
|
1366
|
+
t,
|
|
1367
|
+
" items selected"
|
|
1368
|
+
]
|
|
1369
|
+
})] }) : null,
|
|
1370
|
+
/* @__PURE__ */ V(P, {
|
|
1371
|
+
placeholder: "Action",
|
|
1372
|
+
style: { minWidth: 200 },
|
|
1373
|
+
options: h,
|
|
1374
|
+
value: p,
|
|
1375
|
+
onChange: m,
|
|
1376
|
+
disabled: e === 0 || f,
|
|
1377
|
+
allowClear: !0
|
|
1378
|
+
}),
|
|
1379
|
+
/* @__PURE__ */ V(x, {
|
|
1380
|
+
type: "primary",
|
|
1381
|
+
onClick: () => void g(),
|
|
1382
|
+
disabled: !p || e === 0 || f,
|
|
1383
|
+
loading: f,
|
|
1384
|
+
children: "Go"
|
|
1385
|
+
})
|
|
1386
|
+
]
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
//#endregion
|
|
1390
|
+
//#region src/crud/types.ts
|
|
1391
|
+
var yn = new Set([
|
|
1392
|
+
"page",
|
|
1393
|
+
"perPage",
|
|
1394
|
+
"sort",
|
|
1395
|
+
"create",
|
|
1396
|
+
"edit"
|
|
1397
|
+
]), bn = 1, xn = 10;
|
|
1398
|
+
function Sn(e) {
|
|
1399
|
+
if (e.includes(",")) {
|
|
1400
|
+
let t = e.split(",").map((e) => e.trim()), n = t.map(Number);
|
|
1401
|
+
return n.every((e) => Number.isFinite(e)) ? n : t;
|
|
1402
|
+
}
|
|
1403
|
+
let t = Number(e);
|
|
1404
|
+
return e !== "" && Number.isFinite(t) && String(t) === e ? t : e === "true" ? !0 : e === "false" ? !1 : e;
|
|
1405
|
+
}
|
|
1406
|
+
function Cn(e) {
|
|
1407
|
+
return e == null || e === "" ? null : Array.isArray(e) ? e.length === 0 ? null : e.map(String).join(",") : String(e);
|
|
1408
|
+
}
|
|
1409
|
+
function wn(e) {
|
|
1410
|
+
let [t, n] = v(), r = s(() => {
|
|
1411
|
+
let n = t.get("page"), r = t.get("perPage"), i = n ? Math.max(1, Number(n) || bn) : bn, a = r ? Math.max(1, Number(r) || xn) : xn, o = t.getAll("sort"), s = o.length > 0 ? o.flatMap((e) => Gt(e)) : Gt(t.get("sort")), c = { ...e };
|
|
1412
|
+
return t.forEach((e, n) => {
|
|
1413
|
+
if (yn.has(n)) return;
|
|
1414
|
+
let r = c[n];
|
|
1415
|
+
r === void 0 ? t.getAll(n).length > 1 ? c[n] = t.getAll(n).map(Sn) : c[n] = Sn(e) : c[n] = [...Array.isArray(r) ? r : [r], Sn(e)];
|
|
1416
|
+
}), {
|
|
1417
|
+
page: i,
|
|
1418
|
+
perPage: a,
|
|
1419
|
+
sort: s,
|
|
1420
|
+
filter: c,
|
|
1421
|
+
createModal: t.has("create"),
|
|
1422
|
+
editId: t.get("edit")
|
|
1423
|
+
};
|
|
1424
|
+
}, [t, e]), a = i((e) => {
|
|
1425
|
+
n((t) => {
|
|
1426
|
+
let n = new URLSearchParams(t);
|
|
1427
|
+
return e(n), n;
|
|
1428
|
+
}, { replace: !0 });
|
|
1429
|
+
}, [n]);
|
|
1430
|
+
return [r, s(() => ({
|
|
1431
|
+
setPage: (e) => {
|
|
1432
|
+
a((t) => {
|
|
1433
|
+
e <= 1 ? t.delete("page") : t.set("page", String(e));
|
|
1434
|
+
});
|
|
1435
|
+
},
|
|
1436
|
+
setPerPage: (e) => {
|
|
1437
|
+
a((t) => {
|
|
1438
|
+
e === xn ? t.delete("perPage") : t.set("perPage", String(e)), t.delete("page");
|
|
1439
|
+
});
|
|
1440
|
+
},
|
|
1441
|
+
setSort: (e) => {
|
|
1442
|
+
a((t) => {
|
|
1443
|
+
t.delete("sort");
|
|
1444
|
+
let n = Kt(e);
|
|
1445
|
+
n && t.set("sort", n);
|
|
1446
|
+
});
|
|
1447
|
+
},
|
|
1448
|
+
toggleSort: (e) => {
|
|
1449
|
+
a((t) => {
|
|
1450
|
+
let n = t.getAll("sort").flatMap((e) => Gt(e)), r = n.findIndex((t) => t.field === e), i;
|
|
1451
|
+
i = r < 0 ? [...n, {
|
|
1452
|
+
field: e,
|
|
1453
|
+
order: "ASC"
|
|
1454
|
+
}] : n[r].order === "ASC" ? n.map((e, t) => t === r ? {
|
|
1455
|
+
...e,
|
|
1456
|
+
order: "DESC"
|
|
1457
|
+
} : e) : n.filter((e, t) => t !== r), t.delete("sort");
|
|
1458
|
+
let a = Kt(i);
|
|
1459
|
+
a && t.set("sort", a);
|
|
1460
|
+
});
|
|
1461
|
+
},
|
|
1462
|
+
setFilter: (e, t) => {
|
|
1463
|
+
a((n) => {
|
|
1464
|
+
n.delete(e);
|
|
1465
|
+
let r = Cn(t);
|
|
1466
|
+
r != null && n.set(e, r), n.delete("page");
|
|
1467
|
+
});
|
|
1468
|
+
},
|
|
1469
|
+
setFilters: (e) => {
|
|
1470
|
+
a((t) => {
|
|
1471
|
+
for (let e of [...t.keys()]) yn.has(e) || t.delete(e);
|
|
1472
|
+
for (let [n, r] of Object.entries(e)) {
|
|
1473
|
+
let e = Cn(r);
|
|
1474
|
+
e != null && t.set(n, e);
|
|
1475
|
+
}
|
|
1476
|
+
t.delete("page");
|
|
1477
|
+
});
|
|
1478
|
+
},
|
|
1479
|
+
openCreateModal: () => {
|
|
1480
|
+
a((e) => {
|
|
1481
|
+
e.set("create", "1"), e.delete("edit");
|
|
1482
|
+
});
|
|
1483
|
+
},
|
|
1484
|
+
openEditModal: (e) => {
|
|
1485
|
+
a((t) => {
|
|
1486
|
+
t.set("edit", String(e)), t.delete("create");
|
|
1487
|
+
});
|
|
1488
|
+
},
|
|
1489
|
+
closeModal: () => {
|
|
1490
|
+
a((e) => {
|
|
1491
|
+
e.delete("create"), e.delete("edit");
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
}), [a])];
|
|
1495
|
+
}
|
|
1496
|
+
//#endregion
|
|
1497
|
+
//#region src/crud/ResourceList.tsx
|
|
1498
|
+
var Tn = t(null);
|
|
1499
|
+
function En() {
|
|
1500
|
+
return a(Tn);
|
|
1501
|
+
}
|
|
1502
|
+
function Dn({ resource: e, title: t, pathPrefix: n, newPath: r, editMode: a = "page", formChildren: c, actions: d, rowActions: f, headerExtra: p, bulkActions: m, bulkDelete: h = !0, bulkActionsEnabled: g = !0, permissions: _, queryState: v, queryActions: b }) {
|
|
1503
|
+
let C = mt(), w = q(), { message: T, modal: ee } = y.useApp(), { columns: E, sortOrders: D, sortPriorities: O } = Xt(), [k, A] = l(!1), [j, te] = l([]), [M, ne] = l(0), [N, P] = l(() => /* @__PURE__ */ new Set()), [I, L] = l(!1), re = r ?? `${n}/new`, ae = J(w, _, "add"), z = J(w, _, "change"), U = J(w, _, "delete"), W = z && (a === "page" || a === "both") && d?.edit !== !1, ce = z && (a === "modal" || a === "both") && d?.quickEdit !== !1, le = U && d?.delete !== !1, ue = W || ce || le || f, de = i(() => {
|
|
1504
|
+
P(/* @__PURE__ */ new Set());
|
|
1505
|
+
}, []), fe = s(() => {
|
|
1506
|
+
if (!g) return [];
|
|
1507
|
+
let t = [];
|
|
1508
|
+
return h && U && t.push({
|
|
1509
|
+
key: "__delete",
|
|
1510
|
+
label: "Delete selected",
|
|
1511
|
+
confirm: (e) => `Delete ${e.length} selected item(s)? This cannot be undone.`,
|
|
1512
|
+
execute: async (t, { reload: n, clearSelection: r }) => {
|
|
1513
|
+
await Promise.all(t.map((t) => C.delete(e, t))), r(), n(), T.success(`Deleted ${t.length} item(s)`);
|
|
1514
|
+
}
|
|
1515
|
+
}), [...t, ...m ?? []];
|
|
1516
|
+
}, [
|
|
1517
|
+
g,
|
|
1518
|
+
h,
|
|
1519
|
+
U,
|
|
1520
|
+
m,
|
|
1521
|
+
C,
|
|
1522
|
+
e,
|
|
1523
|
+
T
|
|
1524
|
+
]), pe = fe.length > 0, me = N.size, he = j.length > 0 && j.every((e) => N.has(e.id)), ge = M > 0 && me >= M, _e = s(() => j.filter((e) => N.has(e.id)).map((e) => e.id), [j, N]), ve = i((e) => {
|
|
1525
|
+
P((t) => {
|
|
1526
|
+
let n = new Set(t), r = j.map((e) => e.id);
|
|
1527
|
+
for (let t of r) e.includes(t) || n.delete(t);
|
|
1528
|
+
for (let t of e) n.add(t);
|
|
1529
|
+
return n;
|
|
1530
|
+
});
|
|
1531
|
+
}, [j]), ye = i(async () => {
|
|
1532
|
+
if (!(M <= 0)) {
|
|
1533
|
+
L(!0);
|
|
1534
|
+
try {
|
|
1535
|
+
let t = v.sort.length === 0 ? void 0 : v.sort.length === 1 ? v.sort[0] : v.sort, n = await C.getList(e, {
|
|
1536
|
+
pagination: {
|
|
1537
|
+
page: 1,
|
|
1538
|
+
perPage: M
|
|
1539
|
+
},
|
|
1540
|
+
sort: t,
|
|
1541
|
+
filter: v.filter
|
|
1542
|
+
});
|
|
1543
|
+
P(new Set(n.data.map((e) => e.id)));
|
|
1544
|
+
} catch (e) {
|
|
1545
|
+
T.error(e instanceof Error ? e.message : "Load failed");
|
|
1546
|
+
} finally {
|
|
1547
|
+
L(!1);
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
}, [
|
|
1551
|
+
C,
|
|
1552
|
+
e,
|
|
1553
|
+
M,
|
|
1554
|
+
v.sort,
|
|
1555
|
+
v.filter,
|
|
1556
|
+
T
|
|
1557
|
+
]), G = i((e) => {
|
|
1558
|
+
let t = (e) => {
|
|
1559
|
+
let t = e?.columnKey ?? e?.field;
|
|
1560
|
+
return t == null ? null : String(Array.isArray(t) ? t[0] : t);
|
|
1561
|
+
};
|
|
1562
|
+
if (Array.isArray(e)) {
|
|
1563
|
+
let n = e.find((e) => e?.order);
|
|
1564
|
+
if (n) {
|
|
1565
|
+
let e = t(n);
|
|
1566
|
+
e && b.toggleSort(e);
|
|
1567
|
+
return;
|
|
1568
|
+
}
|
|
1569
|
+
v.sort.length > 0 && b.setSort([]);
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
let n = t(e);
|
|
1573
|
+
if (n) {
|
|
1574
|
+
b.toggleSort(n);
|
|
1575
|
+
return;
|
|
1576
|
+
}
|
|
1577
|
+
!e?.order && v.sort.length > 0 && b.setSort([]);
|
|
1578
|
+
}, [b, v.sort.length]), K = i(async () => {
|
|
1579
|
+
A(!0);
|
|
1580
|
+
try {
|
|
1581
|
+
let t = v.sort.length === 0 ? void 0 : v.sort.length === 1 ? v.sort[0] : v.sort, n = await C.getList(e, {
|
|
1582
|
+
pagination: {
|
|
1583
|
+
page: v.page,
|
|
1584
|
+
perPage: v.perPage
|
|
1585
|
+
},
|
|
1586
|
+
sort: t,
|
|
1587
|
+
filter: v.filter
|
|
1588
|
+
});
|
|
1589
|
+
te(n.data), ne(n.total);
|
|
1590
|
+
} catch (e) {
|
|
1591
|
+
T.error(e instanceof Error ? e.message : "Load failed");
|
|
1592
|
+
} finally {
|
|
1593
|
+
A(!1);
|
|
1594
|
+
}
|
|
1595
|
+
}, [
|
|
1596
|
+
C,
|
|
1597
|
+
e,
|
|
1598
|
+
v,
|
|
1599
|
+
T
|
|
1600
|
+
]);
|
|
1601
|
+
o(() => {
|
|
1602
|
+
K();
|
|
1603
|
+
}, [K]);
|
|
1604
|
+
let be = s(() => ({
|
|
1605
|
+
reload: () => void K(),
|
|
1606
|
+
clearSelection: de
|
|
1607
|
+
}), [K, de]), xe = i(async (e, t) => {
|
|
1608
|
+
if (e.confirm) {
|
|
1609
|
+
let n = typeof e.confirm == "function" ? await e.confirm(t, be) : e.confirm;
|
|
1610
|
+
if (n === !1 || !await new Promise((t) => {
|
|
1611
|
+
ee.confirm({
|
|
1612
|
+
title: n,
|
|
1613
|
+
okType: e.key === "__delete" ? "danger" : "primary",
|
|
1614
|
+
onOk: () => t(!0),
|
|
1615
|
+
onCancel: () => t(!1)
|
|
1616
|
+
});
|
|
1617
|
+
})) return;
|
|
1618
|
+
}
|
|
1619
|
+
L(!0);
|
|
1620
|
+
try {
|
|
1621
|
+
await e.execute(t, be);
|
|
1622
|
+
} catch (e) {
|
|
1623
|
+
T.error(e instanceof Error ? e.message : "Action failed");
|
|
1624
|
+
} finally {
|
|
1625
|
+
L(!1);
|
|
1626
|
+
}
|
|
1627
|
+
}, [
|
|
1628
|
+
be,
|
|
1629
|
+
ee,
|
|
1630
|
+
T
|
|
1631
|
+
]), Se = i(async (t) => {
|
|
1632
|
+
if (U) try {
|
|
1633
|
+
await C.delete(e, t.id), T.success("Deleted"), K();
|
|
1634
|
+
} catch (e) {
|
|
1635
|
+
T.error(e instanceof Error ? e.message : "Delete failed");
|
|
1636
|
+
}
|
|
1637
|
+
}, [
|
|
1638
|
+
U,
|
|
1639
|
+
C,
|
|
1640
|
+
e,
|
|
1641
|
+
K,
|
|
1642
|
+
T
|
|
1643
|
+
]), Ce = s(() => {
|
|
1644
|
+
let e = E.map((e) => {
|
|
1645
|
+
let t = e.buildColumn();
|
|
1646
|
+
if (e.sortable) {
|
|
1647
|
+
let n = D.get(e.source), r = O.get(e.source), i = n === "ASC" ? "ascend" : n === "DESC" ? "descend" : void 0, a = i == null ? void 0 : /* @__PURE__ */ H("span", {
|
|
1648
|
+
style: {
|
|
1649
|
+
display: "inline-flex",
|
|
1650
|
+
alignItems: "center",
|
|
1651
|
+
gap: 2,
|
|
1652
|
+
marginInlineStart: 4,
|
|
1653
|
+
color: "var(--ant-color-primary)"
|
|
1654
|
+
},
|
|
1655
|
+
children: [r == null ? null : /* @__PURE__ */ V("span", {
|
|
1656
|
+
style: {
|
|
1657
|
+
fontSize: 11,
|
|
1658
|
+
fontWeight: 600,
|
|
1659
|
+
lineHeight: 1,
|
|
1660
|
+
minWidth: 10,
|
|
1661
|
+
textAlign: "center"
|
|
1662
|
+
},
|
|
1663
|
+
children: r
|
|
1664
|
+
}), V(i === "ascend" ? se : oe, { style: { fontSize: 11 } })]
|
|
1665
|
+
});
|
|
1666
|
+
return {
|
|
1667
|
+
...t,
|
|
1668
|
+
sorter: !0,
|
|
1669
|
+
sortOrder: i,
|
|
1670
|
+
...a ? { sortIcon: () => a } : {}
|
|
1671
|
+
};
|
|
1672
|
+
}
|
|
1673
|
+
return t;
|
|
1674
|
+
});
|
|
1675
|
+
if (!ue) return e;
|
|
1676
|
+
let t = {
|
|
1677
|
+
reload: () => void K(),
|
|
1678
|
+
openEditModal: b.openEditModal
|
|
1679
|
+
}, r = {
|
|
1680
|
+
title: "Actions",
|
|
1681
|
+
key: "__actions",
|
|
1682
|
+
width: a === "both" ? 200 : 160,
|
|
1683
|
+
render: (e, r) => /* @__PURE__ */ H(F, {
|
|
1684
|
+
size: "small",
|
|
1685
|
+
wrap: !0,
|
|
1686
|
+
children: [
|
|
1687
|
+
W ? /* @__PURE__ */ V(u, {
|
|
1688
|
+
to: `${n}/${String(r.id)}`,
|
|
1689
|
+
children: "Edit"
|
|
1690
|
+
}) : null,
|
|
1691
|
+
ce ? /* @__PURE__ */ V(x, {
|
|
1692
|
+
type: "link",
|
|
1693
|
+
size: "small",
|
|
1694
|
+
style: { padding: 0 },
|
|
1695
|
+
onClick: () => b.openEditModal(r.id),
|
|
1696
|
+
children: a === "both" ? "Quick edit" : "Edit"
|
|
1697
|
+
}) : null,
|
|
1698
|
+
le ? /* @__PURE__ */ V(x, {
|
|
1699
|
+
type: "link",
|
|
1700
|
+
danger: !0,
|
|
1701
|
+
size: "small",
|
|
1702
|
+
onClick: () => void Se(r),
|
|
1703
|
+
style: { padding: 0 },
|
|
1704
|
+
children: "Delete"
|
|
1705
|
+
}) : null,
|
|
1706
|
+
f?.(r, t)
|
|
1707
|
+
]
|
|
1708
|
+
})
|
|
1709
|
+
};
|
|
1710
|
+
return [...e, r];
|
|
1711
|
+
}, [
|
|
1712
|
+
E,
|
|
1713
|
+
ue,
|
|
1714
|
+
W,
|
|
1715
|
+
ce,
|
|
1716
|
+
le,
|
|
1717
|
+
a,
|
|
1718
|
+
n,
|
|
1719
|
+
Se,
|
|
1720
|
+
D,
|
|
1721
|
+
O,
|
|
1722
|
+
b,
|
|
1723
|
+
f,
|
|
1724
|
+
K
|
|
1725
|
+
]), we = c && (v.createModal || v.editId != null) && (a === "modal" || a === "both");
|
|
1726
|
+
return /* @__PURE__ */ H(B, { children: [/* @__PURE__ */ H(S, {
|
|
1727
|
+
title: /* @__PURE__ */ V(R.Title, {
|
|
1728
|
+
level: 5,
|
|
1729
|
+
style: { margin: 0 },
|
|
1730
|
+
children: t
|
|
1731
|
+
}),
|
|
1732
|
+
extra: p || ae ? /* @__PURE__ */ H(F, { children: [p, ae ? a === "modal" || a === "both" ? /* @__PURE__ */ H(B, { children: [a === "both" ? /* @__PURE__ */ V(u, {
|
|
1733
|
+
to: re,
|
|
1734
|
+
children: /* @__PURE__ */ V(x, { children: "New page" })
|
|
1735
|
+
}) : null, /* @__PURE__ */ V(x, {
|
|
1736
|
+
type: "primary",
|
|
1737
|
+
onClick: () => b.openCreateModal(),
|
|
1738
|
+
children: "New"
|
|
1739
|
+
})] }) : /* @__PURE__ */ V(u, {
|
|
1740
|
+
to: re,
|
|
1741
|
+
children: /* @__PURE__ */ V(x, {
|
|
1742
|
+
type: "primary",
|
|
1743
|
+
children: "New"
|
|
1744
|
+
})
|
|
1745
|
+
}) : null] }) : null,
|
|
1746
|
+
children: [pe ? /* @__PURE__ */ V(vn, {
|
|
1747
|
+
selectedCount: me,
|
|
1748
|
+
total: M,
|
|
1749
|
+
allPageSelected: he,
|
|
1750
|
+
allMatchingSelected: ge,
|
|
1751
|
+
onSelectAllMatching: () => void ye(),
|
|
1752
|
+
onClearSelection: de,
|
|
1753
|
+
actions: fe,
|
|
1754
|
+
onExecute: xe,
|
|
1755
|
+
selectedIds: [...N],
|
|
1756
|
+
running: I || k
|
|
1757
|
+
}) : null, /* @__PURE__ */ V(ie, {
|
|
1758
|
+
rowKey: "id",
|
|
1759
|
+
loading: k,
|
|
1760
|
+
columns: Ce,
|
|
1761
|
+
dataSource: j,
|
|
1762
|
+
rowSelection: pe ? {
|
|
1763
|
+
selectedRowKeys: _e,
|
|
1764
|
+
onChange: ve,
|
|
1765
|
+
preserveSelectedRowKeys: !0
|
|
1766
|
+
} : void 0,
|
|
1767
|
+
pagination: {
|
|
1768
|
+
current: v.page,
|
|
1769
|
+
pageSize: v.perPage,
|
|
1770
|
+
total: M,
|
|
1771
|
+
showSizeChanger: !0,
|
|
1772
|
+
onChange: (e, t) => {
|
|
1773
|
+
b.setPage(e), t && b.setPerPage(t);
|
|
1774
|
+
}
|
|
1775
|
+
},
|
|
1776
|
+
onChange: (e, t, n) => {
|
|
1777
|
+
G(n);
|
|
1778
|
+
}
|
|
1779
|
+
})]
|
|
1780
|
+
}), we ? /* @__PURE__ */ V(_n, {
|
|
1781
|
+
resource: e,
|
|
1782
|
+
editId: v.createModal ? "new" : v.editId,
|
|
1783
|
+
onClose: () => {
|
|
1784
|
+
b.closeModal(), K();
|
|
1785
|
+
},
|
|
1786
|
+
children: c
|
|
1787
|
+
}) : null] });
|
|
1788
|
+
}
|
|
1789
|
+
function On({ resource: e, title: t, pathPrefix: n, newPath: r, staticFilter: a, editMode: o = "page", syncQueryParams: c = !0, children: l, formChildren: u, actions: d, rowActions: f, headerExtra: p, bulkActions: m, bulkDelete: h, bulkActionsEnabled: g, permissions: _ }) {
|
|
1790
|
+
let [v, y] = wn(a), b = s(() => {
|
|
1791
|
+
if (!c) return a ?? {};
|
|
1792
|
+
let e = {};
|
|
1793
|
+
for (let [t, n] of Object.entries(v.filter)) a && t in a || (e[t] = n);
|
|
1794
|
+
return e;
|
|
1795
|
+
}, [
|
|
1796
|
+
v.filter,
|
|
1797
|
+
a,
|
|
1798
|
+
c
|
|
1799
|
+
]), x = i((e, t) => {
|
|
1800
|
+
c && y.setFilter(e, t);
|
|
1801
|
+
}, [c, y]), S = s(() => ({
|
|
1802
|
+
filterValues: b,
|
|
1803
|
+
setFilterValue: x
|
|
1804
|
+
}), [b, x]);
|
|
1805
|
+
return /* @__PURE__ */ V(Tn.Provider, {
|
|
1806
|
+
value: S,
|
|
1807
|
+
children: /* @__PURE__ */ V(Qt, {
|
|
1808
|
+
values: b,
|
|
1809
|
+
setFilterValue: x,
|
|
1810
|
+
children: /* @__PURE__ */ H(Yt, {
|
|
1811
|
+
toggleSort: y.toggleSort,
|
|
1812
|
+
sort: v.sort,
|
|
1813
|
+
children: [l, /* @__PURE__ */ V(Dn, {
|
|
1814
|
+
resource: e,
|
|
1815
|
+
title: t,
|
|
1816
|
+
pathPrefix: n,
|
|
1817
|
+
newPath: r,
|
|
1818
|
+
editMode: o,
|
|
1819
|
+
formChildren: u,
|
|
1820
|
+
actions: d,
|
|
1821
|
+
rowActions: f,
|
|
1822
|
+
headerExtra: p,
|
|
1823
|
+
bulkActions: m,
|
|
1824
|
+
bulkDelete: h,
|
|
1825
|
+
bulkActionsEnabled: g,
|
|
1826
|
+
permissions: _,
|
|
1827
|
+
queryState: v,
|
|
1828
|
+
queryActions: y
|
|
1829
|
+
})]
|
|
1830
|
+
})
|
|
1831
|
+
})
|
|
1832
|
+
});
|
|
1833
|
+
}
|
|
1834
|
+
//#endregion
|
|
1835
|
+
//#region src/crud/FilterBar.tsx
|
|
1836
|
+
function kn() {
|
|
1837
|
+
let e = $t();
|
|
1838
|
+
return !e || e.filters.length === 0 ? null : /* @__PURE__ */ V(F, {
|
|
1839
|
+
wrap: !0,
|
|
1840
|
+
size: "middle",
|
|
1841
|
+
style: { marginBottom: 16 },
|
|
1842
|
+
children: e.filters.map((t) => /* @__PURE__ */ H(F, {
|
|
1843
|
+
orientation: "vertical",
|
|
1844
|
+
size: 2,
|
|
1845
|
+
children: [t.label ? /* @__PURE__ */ V(R.Text, {
|
|
1846
|
+
type: "secondary",
|
|
1847
|
+
style: { fontSize: 12 },
|
|
1848
|
+
children: t.label
|
|
1849
|
+
}) : null, t.render({
|
|
1850
|
+
value: e.values[t.source],
|
|
1851
|
+
onChange: (n) => e.setFilterValue(t.source, n)
|
|
1852
|
+
})]
|
|
1853
|
+
}, t.key))
|
|
1854
|
+
});
|
|
1855
|
+
}
|
|
1856
|
+
function An({ children: e }) {
|
|
1857
|
+
return /* @__PURE__ */ H(B, { children: [e, /* @__PURE__ */ V(kn, {})] });
|
|
1858
|
+
}
|
|
1859
|
+
//#endregion
|
|
1860
|
+
//#region src/crud/context/InlineFormContext.tsx
|
|
1861
|
+
var jn = t(null), Mn = t([]);
|
|
1862
|
+
function Nn({ children: e, arrayName: t, layout: n = "tabular" }) {
|
|
1863
|
+
let [r, a] = l([]), o = i((e) => (a((t) => t.some((t) => t.key === e.key) ? t : [...t, e]), () => {
|
|
1864
|
+
a((t) => t.filter((t) => t.key !== e.key));
|
|
1865
|
+
}), []), c = s(() => ({
|
|
1866
|
+
arrayName: t,
|
|
1867
|
+
registerField: o,
|
|
1868
|
+
layout: n
|
|
1869
|
+
}), [
|
|
1870
|
+
t,
|
|
1871
|
+
o,
|
|
1872
|
+
n
|
|
1873
|
+
]);
|
|
1874
|
+
return /* @__PURE__ */ V(jn.Provider, {
|
|
1875
|
+
value: c,
|
|
1876
|
+
children: /* @__PURE__ */ V(Mn.Provider, {
|
|
1877
|
+
value: r,
|
|
1878
|
+
children: e
|
|
1879
|
+
})
|
|
1880
|
+
});
|
|
1881
|
+
}
|
|
1882
|
+
function Pn() {
|
|
1883
|
+
let e = a(jn), t = a(Mn);
|
|
1884
|
+
return e ? {
|
|
1885
|
+
...e,
|
|
1886
|
+
fields: t
|
|
1887
|
+
} : null;
|
|
1888
|
+
}
|
|
1889
|
+
//#endregion
|
|
1890
|
+
//#region src/crud/utils/inlineArrayName.ts
|
|
1891
|
+
function Fn(e, t) {
|
|
1892
|
+
return t ?? `__inline_${e.replace(/[^a-z0-9]/gi, "_")}`;
|
|
1893
|
+
}
|
|
1894
|
+
//#endregion
|
|
1895
|
+
//#region src/crud/InlineFormSet.tsx
|
|
1896
|
+
function In(e) {
|
|
1897
|
+
let t = Pn(), { control: n } = G(), { fields: r, append: i, remove: a } = ve({
|
|
1898
|
+
control: n,
|
|
1899
|
+
name: e
|
|
1900
|
+
});
|
|
1901
|
+
return {
|
|
1902
|
+
ctx: t,
|
|
1903
|
+
fields: r,
|
|
1904
|
+
remove: a,
|
|
1905
|
+
appendEmpty: () => {
|
|
1906
|
+
if (!t) return;
|
|
1907
|
+
let e = {};
|
|
1908
|
+
for (let n of t.fields) e[n.source] = void 0;
|
|
1909
|
+
i(e);
|
|
1910
|
+
}
|
|
1911
|
+
};
|
|
1912
|
+
}
|
|
1913
|
+
function Ln({ arrayName: e, label: t }) {
|
|
1914
|
+
let { ctx: n, fields: r, remove: i, appendEmpty: a } = In(e), o = s(() => n ? n.fields.map((t) => ({
|
|
1915
|
+
title: t.label ?? t.source,
|
|
1916
|
+
key: t.source,
|
|
1917
|
+
width: t.width,
|
|
1918
|
+
onHeaderCell: () => t.minWidth == null ? {} : { style: { minWidth: t.minWidth } },
|
|
1919
|
+
onCell: () => t.minWidth == null ? {} : { style: { minWidth: t.minWidth } },
|
|
1920
|
+
render: (n, r, i) => t.render({
|
|
1921
|
+
name: `${e}.${i}.${t.source}`,
|
|
1922
|
+
index: i
|
|
1923
|
+
})
|
|
1924
|
+
})) : [], [n, e]);
|
|
1925
|
+
return n ? /* @__PURE__ */ H("div", {
|
|
1926
|
+
style: { marginTop: 24 },
|
|
1927
|
+
children: [
|
|
1928
|
+
/* @__PURE__ */ V(R.Title, {
|
|
1929
|
+
level: 5,
|
|
1930
|
+
children: t ?? "Related items"
|
|
1931
|
+
}),
|
|
1932
|
+
/* @__PURE__ */ V(ie, {
|
|
1933
|
+
size: "small",
|
|
1934
|
+
pagination: !1,
|
|
1935
|
+
scroll: { x: "max-content" },
|
|
1936
|
+
dataSource: r.map((e) => ({
|
|
1937
|
+
...e,
|
|
1938
|
+
key: e.id
|
|
1939
|
+
})),
|
|
1940
|
+
columns: [...o, {
|
|
1941
|
+
title: "",
|
|
1942
|
+
key: "__remove",
|
|
1943
|
+
width: 80,
|
|
1944
|
+
render: (e, t, n) => /* @__PURE__ */ V(x, {
|
|
1945
|
+
type: "link",
|
|
1946
|
+
danger: !0,
|
|
1947
|
+
size: "small",
|
|
1948
|
+
onClick: () => i(n),
|
|
1949
|
+
children: "Remove"
|
|
1950
|
+
})
|
|
1951
|
+
}]
|
|
1952
|
+
}),
|
|
1953
|
+
/* @__PURE__ */ V(x, {
|
|
1954
|
+
type: "dashed",
|
|
1955
|
+
style: { marginTop: 8 },
|
|
1956
|
+
onClick: a,
|
|
1957
|
+
children: "Add row"
|
|
1958
|
+
})
|
|
1959
|
+
]
|
|
1960
|
+
}) : null;
|
|
1961
|
+
}
|
|
1962
|
+
function Rn({ arrayName: e, label: t }) {
|
|
1963
|
+
let { ctx: n, fields: r, remove: i, appendEmpty: a } = In(e);
|
|
1964
|
+
return n ? /* @__PURE__ */ H("div", {
|
|
1965
|
+
style: { marginTop: 24 },
|
|
1966
|
+
children: [
|
|
1967
|
+
/* @__PURE__ */ V(R.Title, {
|
|
1968
|
+
level: 5,
|
|
1969
|
+
children: t ?? "Related items"
|
|
1970
|
+
}),
|
|
1971
|
+
/* @__PURE__ */ V(F, {
|
|
1972
|
+
orientation: "vertical",
|
|
1973
|
+
size: "middle",
|
|
1974
|
+
style: { width: "100%" },
|
|
1975
|
+
children: r.map((t, r) => /* @__PURE__ */ V(S, {
|
|
1976
|
+
size: "small",
|
|
1977
|
+
title: `Item ${r + 1}`,
|
|
1978
|
+
extra: /* @__PURE__ */ V(x, {
|
|
1979
|
+
type: "link",
|
|
1980
|
+
danger: !0,
|
|
1981
|
+
size: "small",
|
|
1982
|
+
onClick: () => i(r),
|
|
1983
|
+
children: "Remove"
|
|
1984
|
+
}),
|
|
1985
|
+
children: n.fields.map((t) => /* @__PURE__ */ V("div", { children: t.render({
|
|
1986
|
+
name: `${e}.${r}.${t.source}`,
|
|
1987
|
+
index: r
|
|
1988
|
+
}) }, t.source))
|
|
1989
|
+
}, t.id))
|
|
1990
|
+
}),
|
|
1991
|
+
/* @__PURE__ */ V(x, {
|
|
1992
|
+
type: "dashed",
|
|
1993
|
+
style: { marginTop: 8 },
|
|
1994
|
+
onClick: a,
|
|
1995
|
+
children: "Add item"
|
|
1996
|
+
})
|
|
1997
|
+
]
|
|
1998
|
+
}) : null;
|
|
1999
|
+
}
|
|
2000
|
+
function zn({ resource: e, label: t, children: n, name: r, layout: i = "tabular" }) {
|
|
2001
|
+
let a = Fn(e, r);
|
|
2002
|
+
return /* @__PURE__ */ H(Nn, {
|
|
2003
|
+
arrayName: a,
|
|
2004
|
+
layout: i,
|
|
2005
|
+
children: [n, V(i === "stacked" ? Rn : Ln, {
|
|
2006
|
+
arrayName: a,
|
|
2007
|
+
label: t
|
|
2008
|
+
})]
|
|
2009
|
+
});
|
|
2010
|
+
}
|
|
2011
|
+
async function Bn(e, t) {
|
|
2012
|
+
let { resource: n, foreignKey: r, parentId: i, rows: a, existingIds: o = [], onRowError: s } = t, c = [];
|
|
2013
|
+
for (let t = 0; t < a.length; t++) {
|
|
2014
|
+
let l = a[t];
|
|
2015
|
+
try {
|
|
2016
|
+
let { id: t, ...a } = l, s = {
|
|
2017
|
+
...a,
|
|
2018
|
+
[r]: i
|
|
2019
|
+
}, u = l.id;
|
|
2020
|
+
if (u != null && o.some((e) => e === u)) await e.update(n, {
|
|
2021
|
+
id: u,
|
|
2022
|
+
data: s
|
|
2023
|
+
}), c.push(u);
|
|
2024
|
+
else {
|
|
2025
|
+
let t = (await e.create(n, s)).data;
|
|
2026
|
+
c.push(t.id);
|
|
2027
|
+
}
|
|
2028
|
+
} catch (e) {
|
|
2029
|
+
if (s?.(e, t)) return !1;
|
|
2030
|
+
throw e;
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
for (let t of o) c.some((e) => e === t) || await e.delete(n, t);
|
|
2034
|
+
return !0;
|
|
2035
|
+
}
|
|
2036
|
+
async function Vn(e, t, n, r) {
|
|
2037
|
+
let i = await e.getList(t, {
|
|
2038
|
+
filter: { [n]: Number(r) || r },
|
|
2039
|
+
pagination: {
|
|
2040
|
+
page: 1,
|
|
2041
|
+
perPage: 500
|
|
2042
|
+
}
|
|
2043
|
+
});
|
|
2044
|
+
return {
|
|
2045
|
+
rows: i.data,
|
|
2046
|
+
ids: i.data.map((e) => e.id)
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
//#endregion
|
|
2050
|
+
//#region src/crud/ResourceForm.tsx
|
|
2051
|
+
function Hn(e) {
|
|
2052
|
+
return Fn(e.resource, e.name);
|
|
2053
|
+
}
|
|
2054
|
+
function Un({ resource: e, title: t, listPath: r, children: a, defaultValues: s, onSaved: d, stayOnPage: f, inlines: p, permissions: m }) {
|
|
2055
|
+
let { id: h } = _(), v = h === "new" || !h, b = mt(), C = q(), w = g(), { message: T } = y.useApp(), { token: ee } = z.useToken(), [E, O] = l(!v), [k, A] = l(0), [j, te] = l({}), M = ye({ defaultValues: s }), ne = c(/* @__PURE__ */ new Set()), N = i(async () => {
|
|
2056
|
+
if (v || !h) {
|
|
2057
|
+
s && M.reset({ ...s }), O(!1);
|
|
2058
|
+
return;
|
|
2059
|
+
}
|
|
2060
|
+
O(!0);
|
|
2061
|
+
try {
|
|
2062
|
+
let t = (await b.getOne(e, h)).data;
|
|
2063
|
+
if (p?.length) {
|
|
2064
|
+
let e = { ...t }, n = {};
|
|
2065
|
+
for (let t of p) {
|
|
2066
|
+
let r = Hn(t), { rows: i, ids: a } = await Vn(b, t.resource, t.foreignKey, h);
|
|
2067
|
+
e[r] = i, n[r] = a;
|
|
2068
|
+
}
|
|
2069
|
+
M.reset(e), te(n), A((e) => e + 1);
|
|
2070
|
+
} else M.reset(t), A((e) => e + 1);
|
|
2071
|
+
} catch (e) {
|
|
2072
|
+
T.error(e instanceof Error ? e.message : "Load failed");
|
|
2073
|
+
} finally {
|
|
2074
|
+
O(!1);
|
|
2075
|
+
}
|
|
2076
|
+
}, [
|
|
2077
|
+
b,
|
|
2078
|
+
e,
|
|
2079
|
+
h,
|
|
2080
|
+
v,
|
|
2081
|
+
M,
|
|
2082
|
+
T,
|
|
2083
|
+
s,
|
|
2084
|
+
i(async (e) => {
|
|
2085
|
+
if (!p?.length) return;
|
|
2086
|
+
let t = {};
|
|
2087
|
+
for (let n of p) {
|
|
2088
|
+
let r = Hn(n), { rows: i, ids: a } = await Vn(b, n.resource, n.foreignKey, e);
|
|
2089
|
+
M.setValue(r, i), t[r] = a;
|
|
2090
|
+
}
|
|
2091
|
+
te(t);
|
|
2092
|
+
}, [
|
|
2093
|
+
b,
|
|
2094
|
+
p,
|
|
2095
|
+
M
|
|
2096
|
+
])
|
|
2097
|
+
]);
|
|
2098
|
+
o(() => {
|
|
2099
|
+
N();
|
|
2100
|
+
}, [N]), o(() => {
|
|
2101
|
+
m && (J(C, m, v ? "add" : "change") || w(r, { replace: !0 }));
|
|
2102
|
+
}, [
|
|
2103
|
+
m,
|
|
2104
|
+
v,
|
|
2105
|
+
C,
|
|
2106
|
+
w,
|
|
2107
|
+
r
|
|
2108
|
+
]);
|
|
2109
|
+
let P = m ? J(C, m, v ? "add" : "change") : !0;
|
|
2110
|
+
async function L(t) {
|
|
2111
|
+
try {
|
|
2112
|
+
let n = pn(t, Array.from(ne.current));
|
|
2113
|
+
if (p?.length) for (let e of p) delete n[Hn(e)];
|
|
2114
|
+
let i;
|
|
2115
|
+
if (v) i = (await b.create(e, n)).data, T.success("Created");
|
|
2116
|
+
else if (h) i = (await b.update(e, {
|
|
2117
|
+
id: h,
|
|
2118
|
+
data: n
|
|
2119
|
+
})).data, T.success("Updated");
|
|
2120
|
+
else return;
|
|
2121
|
+
let a = i.id;
|
|
2122
|
+
if (p?.length && a != null) for (let e of p) {
|
|
2123
|
+
let t = Hn(e), n = M.getValues(t) ?? [];
|
|
2124
|
+
if (!await Bn(b, {
|
|
2125
|
+
resource: e.resource,
|
|
2126
|
+
foreignKey: e.foreignKey,
|
|
2127
|
+
parentId: a,
|
|
2128
|
+
rows: n,
|
|
2129
|
+
existingIds: j[t] ?? [],
|
|
2130
|
+
onRowError: (r, i) => {
|
|
2131
|
+
let a = n[i]?.id;
|
|
2132
|
+
return gn(b, M, T, r, {
|
|
2133
|
+
resource: e.resource,
|
|
2134
|
+
mutation: a != null && (j[t] ?? []).some((e) => e === a) ? "update" : "create",
|
|
2135
|
+
inlineArrayName: t,
|
|
2136
|
+
rowIndex: i
|
|
2137
|
+
});
|
|
2138
|
+
}
|
|
2139
|
+
})) return;
|
|
2140
|
+
}
|
|
2141
|
+
d?.(i), f || w(r);
|
|
2142
|
+
} catch (t) {
|
|
2143
|
+
gn(b, M, T, t, {
|
|
2144
|
+
resource: e,
|
|
2145
|
+
mutation: v ? "create" : "update"
|
|
2146
|
+
}) || T.error(t instanceof Error ? t.message : "Save failed");
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
return /* @__PURE__ */ V(S, {
|
|
2150
|
+
title: /* @__PURE__ */ H(F, { children: [/* @__PURE__ */ H(u, {
|
|
2151
|
+
to: r,
|
|
2152
|
+
style: { color: ee.colorText },
|
|
2153
|
+
children: [/* @__PURE__ */ V(U, {}), " Back"]
|
|
2154
|
+
}), /* @__PURE__ */ V(R.Title, {
|
|
2155
|
+
level: 5,
|
|
2156
|
+
style: { margin: 0 },
|
|
2157
|
+
children: t
|
|
2158
|
+
})] }),
|
|
2159
|
+
children: /* @__PURE__ */ V(tn, {
|
|
2160
|
+
resource: e,
|
|
2161
|
+
isNew: v,
|
|
2162
|
+
children: /* @__PURE__ */ V(cn, {
|
|
2163
|
+
sourcesRef: ne,
|
|
2164
|
+
children: /* @__PURE__ */ H("div", {
|
|
2165
|
+
style: { position: "relative" },
|
|
2166
|
+
children: [E ? /* @__PURE__ */ V("div", {
|
|
2167
|
+
style: {
|
|
2168
|
+
position: "absolute",
|
|
2169
|
+
inset: 0,
|
|
2170
|
+
display: "flex",
|
|
2171
|
+
alignItems: "center",
|
|
2172
|
+
justifyContent: "center",
|
|
2173
|
+
zIndex: 1
|
|
2174
|
+
},
|
|
2175
|
+
children: /* @__PURE__ */ V(I, {})
|
|
2176
|
+
}) : null, /* @__PURE__ */ n(_e, {
|
|
2177
|
+
...M,
|
|
2178
|
+
key: k
|
|
2179
|
+
}, /* @__PURE__ */ H(D, {
|
|
2180
|
+
layout: "vertical",
|
|
2181
|
+
onFinish: () => void M.handleSubmit(L)(),
|
|
2182
|
+
style: {
|
|
2183
|
+
opacity: E ? .4 : 1,
|
|
2184
|
+
pointerEvents: E ? "none" : void 0
|
|
2185
|
+
},
|
|
2186
|
+
children: [a, /* @__PURE__ */ V(D.Item, {
|
|
2187
|
+
style: { marginTop: 16 },
|
|
2188
|
+
children: /* @__PURE__ */ H(F, { children: [/* @__PURE__ */ V(x, {
|
|
2189
|
+
type: "primary",
|
|
2190
|
+
htmlType: "submit",
|
|
2191
|
+
disabled: E || !P,
|
|
2192
|
+
children: "Save"
|
|
2193
|
+
}), /* @__PURE__ */ V(u, {
|
|
2194
|
+
to: r,
|
|
2195
|
+
children: /* @__PURE__ */ V(x, {
|
|
2196
|
+
disabled: E,
|
|
2197
|
+
children: "Cancel"
|
|
2198
|
+
})
|
|
2199
|
+
})] })
|
|
2200
|
+
})]
|
|
2201
|
+
}))]
|
|
2202
|
+
})
|
|
2203
|
+
})
|
|
2204
|
+
})
|
|
2205
|
+
});
|
|
2206
|
+
}
|
|
2207
|
+
//#endregion
|
|
2208
|
+
//#region src/crud/utils/formSectionErrors.ts
|
|
2209
|
+
function Wn(e, t, n) {
|
|
2210
|
+
for (let r of e) if (t(r, n).invalid) return !0;
|
|
2211
|
+
return !1;
|
|
2212
|
+
}
|
|
2213
|
+
function Gn(e) {
|
|
2214
|
+
let t = c([]);
|
|
2215
|
+
for (; t.current.length < e;) t.current.push({ current: /* @__PURE__ */ new Set() });
|
|
2216
|
+
return t.current.length > e && (t.current.length = e), t.current;
|
|
2217
|
+
}
|
|
2218
|
+
function Kn(e, t) {
|
|
2219
|
+
let { control: n, getFieldState: r, setFocus: i } = G(), a = K({ control: n }), s = c(0), l = c(0);
|
|
2220
|
+
o(() => {
|
|
2221
|
+
if (a.submitCount === 0) return;
|
|
2222
|
+
let n = Object.keys(a.errors).length, o = a.submitCount !== s.current, c = !o && n > 0 && l.current === 0;
|
|
2223
|
+
if (s.current = a.submitCount, l.current = n, !o && !c || n === 0) return;
|
|
2224
|
+
let u = e.findIndex((e) => Wn(e.current, r, a));
|
|
2225
|
+
if (u < 0) return;
|
|
2226
|
+
t(u);
|
|
2227
|
+
let d = [...e[u].current].find((e) => r(e, a).invalid);
|
|
2228
|
+
d && requestAnimationFrame(() => {
|
|
2229
|
+
i(d);
|
|
2230
|
+
});
|
|
2231
|
+
}, [
|
|
2232
|
+
t,
|
|
2233
|
+
a,
|
|
2234
|
+
a.errors,
|
|
2235
|
+
a.submitCount,
|
|
2236
|
+
r,
|
|
2237
|
+
e,
|
|
2238
|
+
i
|
|
2239
|
+
]);
|
|
2240
|
+
}
|
|
2241
|
+
//#endregion
|
|
2242
|
+
//#region src/crud/FormTabs.tsx
|
|
2243
|
+
function qn(e) {
|
|
2244
|
+
return null;
|
|
2245
|
+
}
|
|
2246
|
+
function Jn(e) {
|
|
2247
|
+
return r(e) && e.type === qn;
|
|
2248
|
+
}
|
|
2249
|
+
function Yn({ children: t, defaultActiveKey: n, activeKey: r, onChange: a, ...o }) {
|
|
2250
|
+
let { token: c } = z.useToken(), u = s(() => e.toArray(t).filter(Jn).map((e, t) => ({
|
|
2251
|
+
key: e.key ?? String(t),
|
|
2252
|
+
label: e.props.label,
|
|
2253
|
+
disabled: e.props.disabled,
|
|
2254
|
+
children: e.props.children
|
|
2255
|
+
})), [t]), d = Gn(u.length), f = r !== void 0, [p, m] = l(() => n ?? u[0]?.key ?? "0"), h = f ? r : p, g = i((e) => {
|
|
2256
|
+
f || m(e), a?.(e);
|
|
2257
|
+
}, [f, a]);
|
|
2258
|
+
Kn(d, i((e) => {
|
|
2259
|
+
let t = u[e]?.key;
|
|
2260
|
+
t != null && g(t);
|
|
2261
|
+
}, [g, u]));
|
|
2262
|
+
let { control: _, getFieldState: v } = G(), y = K({ control: _ });
|
|
2263
|
+
return /* @__PURE__ */ V(ae, {
|
|
2264
|
+
destroyOnHidden: !1,
|
|
2265
|
+
items: s(() => u.map((e, t) => {
|
|
2266
|
+
let n = Wn(d[t].current, v, y);
|
|
2267
|
+
return {
|
|
2268
|
+
key: e.key,
|
|
2269
|
+
label: n ? /* @__PURE__ */ V("span", {
|
|
2270
|
+
style: { color: c.colorError },
|
|
2271
|
+
children: e.label
|
|
2272
|
+
}) : e.label,
|
|
2273
|
+
disabled: e.disabled,
|
|
2274
|
+
children: /* @__PURE__ */ V(an, {
|
|
2275
|
+
sourcesRef: d[t],
|
|
2276
|
+
children: e.children
|
|
2277
|
+
})
|
|
2278
|
+
};
|
|
2279
|
+
}), [
|
|
2280
|
+
y,
|
|
2281
|
+
v,
|
|
2282
|
+
d,
|
|
2283
|
+
u,
|
|
2284
|
+
c.colorError
|
|
2285
|
+
]),
|
|
2286
|
+
activeKey: h,
|
|
2287
|
+
onChange: g,
|
|
2288
|
+
...o
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
//#endregion
|
|
2292
|
+
//#region src/crud/FormSteps.tsx
|
|
2293
|
+
function Xn(e) {
|
|
2294
|
+
return null;
|
|
2295
|
+
}
|
|
2296
|
+
function Zn(e) {
|
|
2297
|
+
return r(e) && e.type === Xn;
|
|
2298
|
+
}
|
|
2299
|
+
function Qn({ children: t, initialStep: n = 0, showNavigation: r = !0, allowStepSelect: a = !1, stepsStyle: o, navigationStyle: c, size: u, direction: d, type: f, status: p }) {
|
|
2300
|
+
let m = s(() => e.toArray(t).filter(Zn), [t]), h = Gn(m.length), [g, _] = l(n), v = m.length - 1;
|
|
2301
|
+
Kn(h, _);
|
|
2302
|
+
let { control: y, getFieldState: b } = G(), S = K({ control: y }), C = s(() => m.map((e, t) => {
|
|
2303
|
+
let n = Wn(h[t].current, b, S);
|
|
2304
|
+
return {
|
|
2305
|
+
title: e.props.title,
|
|
2306
|
+
description: e.props.description,
|
|
2307
|
+
status: n ? "error" : void 0
|
|
2308
|
+
};
|
|
2309
|
+
}), [
|
|
2310
|
+
S,
|
|
2311
|
+
b,
|
|
2312
|
+
h,
|
|
2313
|
+
m
|
|
2314
|
+
]), w = i((e) => {
|
|
2315
|
+
_(e);
|
|
2316
|
+
}, []);
|
|
2317
|
+
return /* @__PURE__ */ H(B, { children: [
|
|
2318
|
+
/* @__PURE__ */ V(L, {
|
|
2319
|
+
current: g,
|
|
2320
|
+
items: C,
|
|
2321
|
+
style: {
|
|
2322
|
+
marginBottom: 24,
|
|
2323
|
+
...o
|
|
2324
|
+
},
|
|
2325
|
+
onChange: a ? w : void 0,
|
|
2326
|
+
size: u,
|
|
2327
|
+
direction: d,
|
|
2328
|
+
type: f,
|
|
2329
|
+
status: p
|
|
2330
|
+
}),
|
|
2331
|
+
m.map((e, t) => /* @__PURE__ */ V("div", {
|
|
2332
|
+
style: { display: g === t ? void 0 : "none" },
|
|
2333
|
+
children: /* @__PURE__ */ V(an, {
|
|
2334
|
+
sourcesRef: h[t],
|
|
2335
|
+
children: e.props.children
|
|
2336
|
+
})
|
|
2337
|
+
}, e.key ?? String(t))),
|
|
2338
|
+
r && m.length > 1 ? /* @__PURE__ */ H(F, {
|
|
2339
|
+
style: {
|
|
2340
|
+
marginTop: 16,
|
|
2341
|
+
...c
|
|
2342
|
+
},
|
|
2343
|
+
children: [/* @__PURE__ */ V(x, {
|
|
2344
|
+
disabled: g === 0,
|
|
2345
|
+
onClick: () => _((e) => e - 1),
|
|
2346
|
+
children: "Previous"
|
|
2347
|
+
}), /* @__PURE__ */ V(x, {
|
|
2348
|
+
type: "primary",
|
|
2349
|
+
disabled: g === v,
|
|
2350
|
+
onClick: () => _((e) => e + 1),
|
|
2351
|
+
children: "Next"
|
|
2352
|
+
})]
|
|
2353
|
+
}) : null
|
|
2354
|
+
] });
|
|
2355
|
+
}
|
|
2356
|
+
//#endregion
|
|
2357
|
+
//#region src/crud/fields/FieldWrapper.tsx
|
|
2358
|
+
function $n({ source: e, label: t, required: n, rules: r, children: i }) {
|
|
2359
|
+
let { control: a } = G(), o = nn(), s = t ?? e;
|
|
2360
|
+
return un(e), /* @__PURE__ */ V(ge, {
|
|
2361
|
+
name: e,
|
|
2362
|
+
control: a,
|
|
2363
|
+
rules: {
|
|
2364
|
+
required: n ? `${s} is required` : !1,
|
|
2365
|
+
...r
|
|
2366
|
+
},
|
|
2367
|
+
render: ({ field: e, fieldState: t }) => /* @__PURE__ */ V(D.Item, {
|
|
2368
|
+
label: s,
|
|
2369
|
+
validateStatus: t.error ? "error" : void 0,
|
|
2370
|
+
help: t.error?.message,
|
|
2371
|
+
required: n,
|
|
2372
|
+
children: i({
|
|
2373
|
+
value: e.value,
|
|
2374
|
+
onChange: e.onChange,
|
|
2375
|
+
onBlur: e.onBlur,
|
|
2376
|
+
disabled: o?.disabled
|
|
2377
|
+
})
|
|
2378
|
+
})
|
|
2379
|
+
});
|
|
2380
|
+
}
|
|
2381
|
+
function er({ name: e, label: t, required: n, rules: r, hideLabel: i, children: a }) {
|
|
2382
|
+
let { control: o } = G(), s = i ? void 0 : t;
|
|
2383
|
+
return /* @__PURE__ */ V(ge, {
|
|
2384
|
+
name: e,
|
|
2385
|
+
control: o,
|
|
2386
|
+
rules: {
|
|
2387
|
+
required: n ? `${t ?? "This field"} is required` : !1,
|
|
2388
|
+
...r
|
|
2389
|
+
},
|
|
2390
|
+
render: ({ field: e, fieldState: t }) => /* @__PURE__ */ V(D.Item, {
|
|
2391
|
+
label: s,
|
|
2392
|
+
validateStatus: t.error ? "error" : void 0,
|
|
2393
|
+
help: t.error?.message,
|
|
2394
|
+
required: n && !i,
|
|
2395
|
+
style: { marginBottom: 0 },
|
|
2396
|
+
children: a({
|
|
2397
|
+
value: e.value,
|
|
2398
|
+
onChange: e.onChange,
|
|
2399
|
+
onBlur: e.onBlur
|
|
2400
|
+
})
|
|
2401
|
+
})
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2404
|
+
//#endregion
|
|
2405
|
+
//#region src/crud/fields/useInlineOrFormField.tsx
|
|
2406
|
+
function Q(e, t, n, r, i, a) {
|
|
2407
|
+
let l = Pn(), u = l?.registerField, d = u != null, f = c(i);
|
|
2408
|
+
f.current = i;
|
|
2409
|
+
let p = s(() => u ? {
|
|
2410
|
+
key: e,
|
|
2411
|
+
source: e,
|
|
2412
|
+
label: t,
|
|
2413
|
+
width: a?.width,
|
|
2414
|
+
minWidth: a?.minWidth,
|
|
2415
|
+
render: ({ name: e, index: i }) => /* @__PURE__ */ V(er, {
|
|
2416
|
+
name: e,
|
|
2417
|
+
label: t,
|
|
2418
|
+
required: n,
|
|
2419
|
+
rules: r,
|
|
2420
|
+
hideLabel: l?.layout !== "stacked",
|
|
2421
|
+
children: ({ value: t, onChange: n, onBlur: r }) => f.current({
|
|
2422
|
+
value: t,
|
|
2423
|
+
onChange: n,
|
|
2424
|
+
onBlur: r,
|
|
2425
|
+
name: e,
|
|
2426
|
+
index: i
|
|
2427
|
+
})
|
|
2428
|
+
})
|
|
2429
|
+
} : null, [
|
|
2430
|
+
u,
|
|
2431
|
+
e,
|
|
2432
|
+
t,
|
|
2433
|
+
n,
|
|
2434
|
+
r,
|
|
2435
|
+
l?.layout,
|
|
2436
|
+
a?.width,
|
|
2437
|
+
a?.minWidth
|
|
2438
|
+
]), m = c(p);
|
|
2439
|
+
return m.current = p, o(() => {
|
|
2440
|
+
if (!u) return;
|
|
2441
|
+
let e = m.current;
|
|
2442
|
+
if (e) return u(e);
|
|
2443
|
+
}, [u, e]), d ? { mode: "inline" } : {
|
|
2444
|
+
mode: "form",
|
|
2445
|
+
element: /* @__PURE__ */ V($n, {
|
|
2446
|
+
source: e,
|
|
2447
|
+
label: t,
|
|
2448
|
+
required: n,
|
|
2449
|
+
rules: r,
|
|
2450
|
+
children: ({ value: e, onChange: t, onBlur: n, disabled: r }) => i({
|
|
2451
|
+
value: e,
|
|
2452
|
+
onChange: t,
|
|
2453
|
+
onBlur: n,
|
|
2454
|
+
disabled: r
|
|
2455
|
+
})
|
|
2456
|
+
})
|
|
2457
|
+
};
|
|
2458
|
+
}
|
|
2459
|
+
//#endregion
|
|
2460
|
+
//#region src/crud/fields/TextField.tsx
|
|
2461
|
+
function tr({ source: e, label: t, required: n, rules: r, placeholder: i, width: a, minWidth: o, inputStyle: s }) {
|
|
2462
|
+
let c = Q(e, t, n, r, ({ value: e, onChange: t, onBlur: n, disabled: r }) => /* @__PURE__ */ V(k, {
|
|
2463
|
+
value: e,
|
|
2464
|
+
onChange: (e) => t(e.target.value),
|
|
2465
|
+
onBlur: n,
|
|
2466
|
+
placeholder: i,
|
|
2467
|
+
disabled: r,
|
|
2468
|
+
style: s
|
|
2469
|
+
}), {
|
|
2470
|
+
width: a,
|
|
2471
|
+
minWidth: o
|
|
2472
|
+
});
|
|
2473
|
+
return c.mode === "inline" ? null : c.element;
|
|
2474
|
+
}
|
|
2475
|
+
//#endregion
|
|
2476
|
+
//#region src/crud/fields/NumberField.tsx
|
|
2477
|
+
function nr({ source: e, label: t, required: n, rules: r, min: i, max: a, step: o, width: s, minWidth: c, inputStyle: l }) {
|
|
2478
|
+
let u = Q(e, t, n, r, ({ value: e, onChange: t, onBlur: n, disabled: r }) => /* @__PURE__ */ V(A, {
|
|
2479
|
+
value: e,
|
|
2480
|
+
onChange: (e) => t(e),
|
|
2481
|
+
onBlur: n,
|
|
2482
|
+
min: i,
|
|
2483
|
+
max: a,
|
|
2484
|
+
step: o,
|
|
2485
|
+
disabled: r,
|
|
2486
|
+
style: {
|
|
2487
|
+
width: "100%",
|
|
2488
|
+
...l
|
|
2489
|
+
}
|
|
2490
|
+
}), {
|
|
2491
|
+
width: s,
|
|
2492
|
+
minWidth: c
|
|
2493
|
+
});
|
|
2494
|
+
return u.mode === "inline" ? null : u.element;
|
|
2495
|
+
}
|
|
2496
|
+
//#endregion
|
|
2497
|
+
//#region src/crud/fields/BooleanField.tsx
|
|
2498
|
+
function rr({ source: e, label: t, required: n, rules: r }) {
|
|
2499
|
+
let i = Q(e, t, n, r, ({ value: e, onChange: t, disabled: n }) => /* @__PURE__ */ V(re, {
|
|
2500
|
+
checked: !!e,
|
|
2501
|
+
onChange: t,
|
|
2502
|
+
disabled: n
|
|
2503
|
+
}));
|
|
2504
|
+
return i.mode === "inline" ? null : i.element;
|
|
2505
|
+
}
|
|
2506
|
+
//#endregion
|
|
2507
|
+
//#region src/crud/fields/DateField.tsx
|
|
2508
|
+
var ir = "YYYY-MM-DD";
|
|
2509
|
+
function ar({ source: e, label: t, required: n, rules: r, showTime: i }) {
|
|
2510
|
+
let a = Q(e, t, n, r, ({ value: e, onChange: t, onBlur: n, disabled: r }) => /* @__PURE__ */ V(w, {
|
|
2511
|
+
value: e ? xe(String(e)) : null,
|
|
2512
|
+
onChange: (e) => t(e ? e.format(i ? `${ir} HH:mm:ss` : ir) : null),
|
|
2513
|
+
onBlur: n,
|
|
2514
|
+
showTime: i,
|
|
2515
|
+
disabled: r,
|
|
2516
|
+
format: i ? `${ir} HH:mm:ss` : ir,
|
|
2517
|
+
style: { width: "100%" }
|
|
2518
|
+
}));
|
|
2519
|
+
return a.mode === "inline" ? null : a.element;
|
|
2520
|
+
}
|
|
2521
|
+
//#endregion
|
|
2522
|
+
//#region src/crud/fields/SelectField.tsx
|
|
2523
|
+
function or({ source: e, label: t, required: n, rules: r, choices: i, mode: a, allowClear: o }) {
|
|
2524
|
+
return /* @__PURE__ */ V($n, {
|
|
2525
|
+
source: e,
|
|
2526
|
+
label: t,
|
|
2527
|
+
required: n,
|
|
2528
|
+
rules: r,
|
|
2529
|
+
children: ({ value: e, onChange: t, disabled: n }) => /* @__PURE__ */ V(P, {
|
|
2530
|
+
value: e,
|
|
2531
|
+
onChange: t,
|
|
2532
|
+
options: i,
|
|
2533
|
+
mode: a,
|
|
2534
|
+
allowClear: o,
|
|
2535
|
+
disabled: n,
|
|
2536
|
+
style: { width: "100%" }
|
|
2537
|
+
})
|
|
2538
|
+
});
|
|
2539
|
+
}
|
|
2540
|
+
//#endregion
|
|
2541
|
+
//#region src/crud/fields/PasswordField.tsx
|
|
2542
|
+
function sr({ source: e, label: t, required: n, rules: r, autoComplete: i, width: a, minWidth: o }) {
|
|
2543
|
+
let s = Q(e, t, n, r, ({ value: e, onChange: t, onBlur: n, disabled: r }) => /* @__PURE__ */ V(k.Password, {
|
|
2544
|
+
value: e,
|
|
2545
|
+
onChange: (e) => t(e.target.value),
|
|
2546
|
+
onBlur: n,
|
|
2547
|
+
disabled: r,
|
|
2548
|
+
autoComplete: i
|
|
2549
|
+
}), {
|
|
2550
|
+
width: a,
|
|
2551
|
+
minWidth: o
|
|
2552
|
+
});
|
|
2553
|
+
return s.mode === "inline" ? null : s.element;
|
|
2554
|
+
}
|
|
2555
|
+
function cr({ source: e, label: t, required: n, rules: r, confirmSource: i, confirmLabel: a = "Confirm password", autoComplete: o = "new-password", width: s, minWidth: c }) {
|
|
2556
|
+
let l = be({
|
|
2557
|
+
name: e,
|
|
2558
|
+
disabled: !i
|
|
2559
|
+
});
|
|
2560
|
+
return i ? /* @__PURE__ */ H(B, { children: [/* @__PURE__ */ V(sr, {
|
|
2561
|
+
source: e,
|
|
2562
|
+
label: t,
|
|
2563
|
+
required: n,
|
|
2564
|
+
rules: r,
|
|
2565
|
+
autoComplete: o,
|
|
2566
|
+
width: s,
|
|
2567
|
+
minWidth: c
|
|
2568
|
+
}), /* @__PURE__ */ V(sr, {
|
|
2569
|
+
source: i,
|
|
2570
|
+
label: a,
|
|
2571
|
+
required: n,
|
|
2572
|
+
autoComplete: o,
|
|
2573
|
+
width: s,
|
|
2574
|
+
minWidth: c,
|
|
2575
|
+
rules: { validate: (e) => !l || e === l || "Passwords do not match" }
|
|
2576
|
+
})] }) : /* @__PURE__ */ V(sr, {
|
|
2577
|
+
source: e,
|
|
2578
|
+
label: t,
|
|
2579
|
+
required: n,
|
|
2580
|
+
rules: r,
|
|
2581
|
+
autoComplete: o,
|
|
2582
|
+
width: s,
|
|
2583
|
+
minWidth: c
|
|
2584
|
+
});
|
|
2585
|
+
}
|
|
2586
|
+
//#endregion
|
|
2587
|
+
//#region src/crud/utils/useChoices.ts
|
|
2588
|
+
var lr = /* @__PURE__ */ new Map(), ur = /* @__PURE__ */ new Map();
|
|
2589
|
+
function dr(e, t) {
|
|
2590
|
+
return typeof e == "function" ? `fn:${t ?? ""}` : Array.isArray(e) ? `static:${e.length}` : `res:${e.resource}:${JSON.stringify(e.filter ?? {})}:${t ?? ""}`;
|
|
2591
|
+
}
|
|
2592
|
+
function fr(e, t) {
|
|
2593
|
+
return typeof t == "function" ? t(e) : String(e[t] ?? "");
|
|
2594
|
+
}
|
|
2595
|
+
async function pr(e, t, n, r, i) {
|
|
2596
|
+
return typeof e == "function" ? e({
|
|
2597
|
+
dataProvider: t,
|
|
2598
|
+
search: i
|
|
2599
|
+
}) : Array.isArray(e) ? e : (await t.getList(e.resource, {
|
|
2600
|
+
filter: {
|
|
2601
|
+
...e.filter,
|
|
2602
|
+
...i ? { q: i } : {}
|
|
2603
|
+
},
|
|
2604
|
+
pagination: {
|
|
2605
|
+
page: 1,
|
|
2606
|
+
perPage: 500
|
|
2607
|
+
}
|
|
2608
|
+
})).data.map((e) => ({
|
|
2609
|
+
label: fr(e, n),
|
|
2610
|
+
value: e[r],
|
|
2611
|
+
record: e
|
|
2612
|
+
}));
|
|
2613
|
+
}
|
|
2614
|
+
function mr(e, t, n, r, i) {
|
|
2615
|
+
let a = dr(e, i), o = lr.get(a);
|
|
2616
|
+
if (o && !i) return Promise.resolve(o);
|
|
2617
|
+
let s = ur.get(a);
|
|
2618
|
+
if (s) return s;
|
|
2619
|
+
let c = pr(e, t, n, r, i).then((e) => (i || lr.set(a, e), e)).finally(() => {
|
|
2620
|
+
ur.delete(a);
|
|
2621
|
+
});
|
|
2622
|
+
return ur.set(a, c), c;
|
|
2623
|
+
}
|
|
2624
|
+
function $(e, t, n = "name", r = "id", a) {
|
|
2625
|
+
let c = mt(), u = s(() => {
|
|
2626
|
+
if (e) return e;
|
|
2627
|
+
if (t) return {
|
|
2628
|
+
resource: t,
|
|
2629
|
+
filter: a ? { q: a } : void 0
|
|
2630
|
+
};
|
|
2631
|
+
}, [
|
|
2632
|
+
e,
|
|
2633
|
+
t,
|
|
2634
|
+
a
|
|
2635
|
+
]), d = u ? dr(u, a) : void 0, [f, p] = l(() => !d || a ? [] : lr.get(d) ?? []), [m, h] = l(() => !d || a ? !!u : !lr.has(d)), g = i(async () => {
|
|
2636
|
+
if (!u) {
|
|
2637
|
+
p([]), h(!1);
|
|
2638
|
+
return;
|
|
2639
|
+
}
|
|
2640
|
+
let e = dr(u, a), t = lr.get(e);
|
|
2641
|
+
if (t && !a) {
|
|
2642
|
+
p(t), h(!1);
|
|
2643
|
+
return;
|
|
2644
|
+
}
|
|
2645
|
+
h(!0);
|
|
2646
|
+
try {
|
|
2647
|
+
p(await mr(u, c, n, r, a));
|
|
2648
|
+
} catch {
|
|
2649
|
+
p([]);
|
|
2650
|
+
} finally {
|
|
2651
|
+
h(!1);
|
|
2652
|
+
}
|
|
2653
|
+
}, [
|
|
2654
|
+
u,
|
|
2655
|
+
c,
|
|
2656
|
+
n,
|
|
2657
|
+
r,
|
|
2658
|
+
a
|
|
2659
|
+
]);
|
|
2660
|
+
o(() => {
|
|
2661
|
+
g();
|
|
2662
|
+
}, [g]);
|
|
2663
|
+
let _ = i((e) => f.find((t) => t.value === e)?.label ?? String(e ?? "—"), [f]);
|
|
2664
|
+
return {
|
|
2665
|
+
options: f,
|
|
2666
|
+
loading: m,
|
|
2667
|
+
labelForValue: _,
|
|
2668
|
+
labelsForValues: i((e) => e?.length ? e.map((e) => _(e)).join(", ") : "—", [_]),
|
|
2669
|
+
optionForValue: i((e) => f.find((t) => t.value === e), [f]),
|
|
2670
|
+
reload: g
|
|
2671
|
+
};
|
|
2672
|
+
}
|
|
2673
|
+
//#endregion
|
|
2674
|
+
//#region src/crud/fields/ReferenceField.tsx
|
|
2675
|
+
function hr({ source: e, label: t, reference: n, choices: r, optionLabel: i = "name", optionValue: a = "id", required: o, rules: c, search: u, allowClear: d, disabled: f, width: p, minWidth: m, inputStyle: h, onValueChange: g }) {
|
|
2676
|
+
let [_, v] = l(), { options: y, loading: b, optionForValue: x } = $(r, n, i, a, u ? _ : void 0), S = s(() => y.map((e) => ({
|
|
2677
|
+
label: e.label,
|
|
2678
|
+
value: e.value
|
|
2679
|
+
})), [y]), C = Q(e, t, o, c, ({ value: e, onChange: t, disabled: n, name: r, index: i }) => /* @__PURE__ */ V(P, {
|
|
2680
|
+
value: e,
|
|
2681
|
+
onChange: (e) => {
|
|
2682
|
+
t(e), g?.(e, x(e), {
|
|
2683
|
+
name: r,
|
|
2684
|
+
index: i
|
|
2685
|
+
});
|
|
2686
|
+
},
|
|
2687
|
+
options: S,
|
|
2688
|
+
loading: b && y.length === 0,
|
|
2689
|
+
showSearch: u,
|
|
2690
|
+
filterOption: u ? !1 : void 0,
|
|
2691
|
+
onSearch: u ? v : void 0,
|
|
2692
|
+
allowClear: d,
|
|
2693
|
+
disabled: n || f,
|
|
2694
|
+
optionFilterProp: "label",
|
|
2695
|
+
style: {
|
|
2696
|
+
width: "100%",
|
|
2697
|
+
minWidth: 160,
|
|
2698
|
+
...h
|
|
2699
|
+
}
|
|
2700
|
+
}), {
|
|
2701
|
+
width: p,
|
|
2702
|
+
minWidth: m
|
|
2703
|
+
});
|
|
2704
|
+
return C.mode === "inline" ? null : C.element;
|
|
2705
|
+
}
|
|
2706
|
+
//#endregion
|
|
2707
|
+
//#region src/crud/fields/ReferenceManyField.tsx
|
|
2708
|
+
function gr({ source: e, label: t, reference: n, choices: r, optionLabel: i = "name", optionValue: a = "id", required: o, rules: c, search: u, allowClear: d = !0 }) {
|
|
2709
|
+
let [f, p] = l(), { options: m, loading: h } = $(r, n, i, a, u ? f : void 0), g = s(() => m.map((e) => ({
|
|
2710
|
+
label: e.label,
|
|
2711
|
+
value: e.value
|
|
2712
|
+
})), [m]), _ = Q(e, t, o, c, ({ value: e, onChange: t, disabled: n }) => /* @__PURE__ */ V(P, {
|
|
2713
|
+
mode: "multiple",
|
|
2714
|
+
value: e ?? [],
|
|
2715
|
+
onChange: t,
|
|
2716
|
+
options: g,
|
|
2717
|
+
loading: h,
|
|
2718
|
+
showSearch: u,
|
|
2719
|
+
filterOption: u ? !1 : void 0,
|
|
2720
|
+
onSearch: u ? p : void 0,
|
|
2721
|
+
allowClear: d,
|
|
2722
|
+
disabled: n,
|
|
2723
|
+
optionFilterProp: "label",
|
|
2724
|
+
style: { width: "100%" }
|
|
2725
|
+
}));
|
|
2726
|
+
return _.mode === "inline" ? null : _.element;
|
|
2727
|
+
}
|
|
2728
|
+
//#endregion
|
|
2729
|
+
//#region src/crud/columns/TextColumn.tsx
|
|
2730
|
+
function _r({ source: e, label: t, sortable: n = !0 }) {
|
|
2731
|
+
return X(s(() => ({
|
|
2732
|
+
key: e,
|
|
2733
|
+
source: e,
|
|
2734
|
+
label: t,
|
|
2735
|
+
sortable: n,
|
|
2736
|
+
buildColumn: () => ({
|
|
2737
|
+
title: t ?? e,
|
|
2738
|
+
dataIndex: e,
|
|
2739
|
+
key: e,
|
|
2740
|
+
sorter: n ? !0 : void 0
|
|
2741
|
+
})
|
|
2742
|
+
}), [
|
|
2743
|
+
e,
|
|
2744
|
+
t,
|
|
2745
|
+
n
|
|
2746
|
+
])), null;
|
|
2747
|
+
}
|
|
2748
|
+
function vr(e, t, n) {
|
|
2749
|
+
return typeof n == "function" ? n(e) : n ? dn(e, n) : e[t];
|
|
2750
|
+
}
|
|
2751
|
+
//#endregion
|
|
2752
|
+
//#region src/crud/columns/NumberColumn.tsx
|
|
2753
|
+
function yr({ source: e, label: t, sortable: n = !0 }) {
|
|
2754
|
+
return X(s(() => ({
|
|
2755
|
+
key: e,
|
|
2756
|
+
source: e,
|
|
2757
|
+
label: t,
|
|
2758
|
+
sortable: n,
|
|
2759
|
+
buildColumn: () => ({
|
|
2760
|
+
title: t ?? e,
|
|
2761
|
+
dataIndex: e,
|
|
2762
|
+
key: e,
|
|
2763
|
+
sorter: n ? !0 : void 0
|
|
2764
|
+
})
|
|
2765
|
+
}), [
|
|
2766
|
+
e,
|
|
2767
|
+
t,
|
|
2768
|
+
n
|
|
2769
|
+
])), null;
|
|
2770
|
+
}
|
|
2771
|
+
//#endregion
|
|
2772
|
+
//#region src/crud/columns/BooleanColumn.tsx
|
|
2773
|
+
function br({ source: e, label: t, sortable: n = !0 }) {
|
|
2774
|
+
return X(s(() => ({
|
|
2775
|
+
key: e,
|
|
2776
|
+
source: e,
|
|
2777
|
+
label: t,
|
|
2778
|
+
sortable: n,
|
|
2779
|
+
buildColumn: () => ({
|
|
2780
|
+
title: t ?? e,
|
|
2781
|
+
dataIndex: e,
|
|
2782
|
+
key: e,
|
|
2783
|
+
sorter: n ? !0 : void 0,
|
|
2784
|
+
render: (e) => e ? "Yes" : "No"
|
|
2785
|
+
})
|
|
2786
|
+
}), [
|
|
2787
|
+
e,
|
|
2788
|
+
t,
|
|
2789
|
+
n
|
|
2790
|
+
])), null;
|
|
2791
|
+
}
|
|
2792
|
+
//#endregion
|
|
2793
|
+
//#region src/crud/columns/DateColumn.tsx
|
|
2794
|
+
function xr({ source: e, label: t, sortable: n = !0 }) {
|
|
2795
|
+
return X(s(() => ({
|
|
2796
|
+
key: e,
|
|
2797
|
+
source: e,
|
|
2798
|
+
label: t,
|
|
2799
|
+
sortable: n,
|
|
2800
|
+
buildColumn: () => ({
|
|
2801
|
+
title: t ?? e,
|
|
2802
|
+
dataIndex: e,
|
|
2803
|
+
key: e,
|
|
2804
|
+
sorter: n ? !0 : void 0,
|
|
2805
|
+
render: (e) => e ? String(e).slice(0, 10) : "—"
|
|
2806
|
+
})
|
|
2807
|
+
}), [
|
|
2808
|
+
e,
|
|
2809
|
+
t,
|
|
2810
|
+
n
|
|
2811
|
+
])), null;
|
|
2812
|
+
}
|
|
2813
|
+
//#endregion
|
|
2814
|
+
//#region src/crud/columns/ReferenceColumn.tsx
|
|
2815
|
+
function Sr({ record: e, source: t, display: n, reference: r, choices: i, optionLabel: a, optionValue: o }) {
|
|
2816
|
+
let { labelForValue: s } = $(i, r, a, o), c = e[t];
|
|
2817
|
+
if (typeof n == "function") return /* @__PURE__ */ V(B, { children: n(e) });
|
|
2818
|
+
if (n && n !== t) {
|
|
2819
|
+
let r = vr(e, t, n);
|
|
2820
|
+
return /* @__PURE__ */ V(B, { children: r == null ? "—" : String(r) });
|
|
2821
|
+
}
|
|
2822
|
+
return /* @__PURE__ */ V(B, { children: s(c) });
|
|
2823
|
+
}
|
|
2824
|
+
function Cr({ source: e, label: t, reference: n, choices: r, optionLabel: i = "name", optionValue: a = "id", display: o, sortable: c = !0 }) {
|
|
2825
|
+
return X(s(() => ({
|
|
2826
|
+
key: e,
|
|
2827
|
+
source: e,
|
|
2828
|
+
label: t,
|
|
2829
|
+
sortable: c,
|
|
2830
|
+
buildColumn: () => ({
|
|
2831
|
+
title: t ?? e,
|
|
2832
|
+
dataIndex: e,
|
|
2833
|
+
key: e,
|
|
2834
|
+
sorter: c ? !0 : void 0,
|
|
2835
|
+
render: (s, c) => /* @__PURE__ */ V(Sr, {
|
|
2836
|
+
record: c,
|
|
2837
|
+
source: e,
|
|
2838
|
+
label: t,
|
|
2839
|
+
reference: n,
|
|
2840
|
+
choices: r,
|
|
2841
|
+
optionLabel: i,
|
|
2842
|
+
optionValue: a,
|
|
2843
|
+
display: o ?? i
|
|
2844
|
+
})
|
|
2845
|
+
})
|
|
2846
|
+
}), [
|
|
2847
|
+
e,
|
|
2848
|
+
t,
|
|
2849
|
+
c,
|
|
2850
|
+
n,
|
|
2851
|
+
r,
|
|
2852
|
+
i,
|
|
2853
|
+
a,
|
|
2854
|
+
o
|
|
2855
|
+
])), null;
|
|
2856
|
+
}
|
|
2857
|
+
//#endregion
|
|
2858
|
+
//#region src/crud/columns/ReferenceManyColumn.tsx
|
|
2859
|
+
function wr({ record: e, source: t, reference: n, choices: r, optionLabel: i, optionValue: a }) {
|
|
2860
|
+
let { labelsForValues: o } = $(r, n, i, a), s = e[t];
|
|
2861
|
+
return /* @__PURE__ */ V(B, { children: o(Array.isArray(s) ? s : []) });
|
|
2862
|
+
}
|
|
2863
|
+
function Tr({ source: e, label: t, reference: n, choices: r, optionLabel: i = "name", optionValue: a = "id", sortable: o = !1 }) {
|
|
2864
|
+
return X(s(() => ({
|
|
2865
|
+
key: e,
|
|
2866
|
+
source: e,
|
|
2867
|
+
label: t,
|
|
2868
|
+
sortable: o,
|
|
2869
|
+
buildColumn: () => ({
|
|
2870
|
+
title: t ?? e,
|
|
2871
|
+
dataIndex: e,
|
|
2872
|
+
key: e,
|
|
2873
|
+
sorter: o ? !0 : void 0,
|
|
2874
|
+
render: (t, o) => /* @__PURE__ */ V(wr, {
|
|
2875
|
+
record: o,
|
|
2876
|
+
source: e,
|
|
2877
|
+
reference: n,
|
|
2878
|
+
choices: r,
|
|
2879
|
+
optionLabel: i,
|
|
2880
|
+
optionValue: a
|
|
2881
|
+
})
|
|
2882
|
+
})
|
|
2883
|
+
}), [
|
|
2884
|
+
e,
|
|
2885
|
+
t,
|
|
2886
|
+
o,
|
|
2887
|
+
n,
|
|
2888
|
+
r,
|
|
2889
|
+
i,
|
|
2890
|
+
a
|
|
2891
|
+
])), null;
|
|
2892
|
+
}
|
|
2893
|
+
//#endregion
|
|
2894
|
+
//#region src/crud/columns/CustomColumn.tsx
|
|
2895
|
+
function Er({ source: e, label: t, sortable: n = !1, render: r }) {
|
|
2896
|
+
return X(s(() => ({
|
|
2897
|
+
key: e,
|
|
2898
|
+
source: e,
|
|
2899
|
+
label: t,
|
|
2900
|
+
sortable: n,
|
|
2901
|
+
buildColumn: () => ({
|
|
2902
|
+
title: t ?? e,
|
|
2903
|
+
key: e,
|
|
2904
|
+
render: (e, t) => r(t)
|
|
2905
|
+
})
|
|
2906
|
+
}), [
|
|
2907
|
+
e,
|
|
2908
|
+
t,
|
|
2909
|
+
n,
|
|
2910
|
+
r
|
|
2911
|
+
])), null;
|
|
2912
|
+
}
|
|
2913
|
+
//#endregion
|
|
2914
|
+
//#region src/crud/filters/TextFilter.tsx
|
|
2915
|
+
function Dr({ source: e, label: t, placeholder: n }) {
|
|
2916
|
+
return Z(s(() => ({
|
|
2917
|
+
key: e,
|
|
2918
|
+
source: e,
|
|
2919
|
+
label: t,
|
|
2920
|
+
render: ({ value: r, onChange: i }) => /* @__PURE__ */ V(k, {
|
|
2921
|
+
allowClear: !0,
|
|
2922
|
+
placeholder: n ?? t ?? e,
|
|
2923
|
+
value: r ?? "",
|
|
2924
|
+
onChange: (e) => i(e.target.value || void 0),
|
|
2925
|
+
style: { minWidth: 160 }
|
|
2926
|
+
})
|
|
2927
|
+
}), [
|
|
2928
|
+
e,
|
|
2929
|
+
t,
|
|
2930
|
+
n
|
|
2931
|
+
])), null;
|
|
2932
|
+
}
|
|
2933
|
+
//#endregion
|
|
2934
|
+
//#region src/crud/filters/NumberFilter.tsx
|
|
2935
|
+
function Or({ source: e, label: t }) {
|
|
2936
|
+
return Z(s(() => ({
|
|
2937
|
+
key: e,
|
|
2938
|
+
source: e,
|
|
2939
|
+
label: t,
|
|
2940
|
+
render: ({ value: n, onChange: r }) => /* @__PURE__ */ V(A, {
|
|
2941
|
+
placeholder: t ?? e,
|
|
2942
|
+
value: n,
|
|
2943
|
+
onChange: (e) => r(e ?? void 0),
|
|
2944
|
+
style: { minWidth: 120 }
|
|
2945
|
+
})
|
|
2946
|
+
}), [e, t])), null;
|
|
2947
|
+
}
|
|
2948
|
+
//#endregion
|
|
2949
|
+
//#region src/crud/filters/BooleanFilter.tsx
|
|
2950
|
+
function kr({ source: e, label: t }) {
|
|
2951
|
+
return Z(s(() => ({
|
|
2952
|
+
key: e,
|
|
2953
|
+
source: e,
|
|
2954
|
+
label: t,
|
|
2955
|
+
render: ({ value: n, onChange: r }) => /* @__PURE__ */ V(P, {
|
|
2956
|
+
allowClear: !0,
|
|
2957
|
+
placeholder: t ?? e,
|
|
2958
|
+
value: n,
|
|
2959
|
+
onChange: (e) => r(e),
|
|
2960
|
+
options: [{
|
|
2961
|
+
label: "Yes",
|
|
2962
|
+
value: !0
|
|
2963
|
+
}, {
|
|
2964
|
+
label: "No",
|
|
2965
|
+
value: !1
|
|
2966
|
+
}],
|
|
2967
|
+
style: { minWidth: 100 }
|
|
2968
|
+
})
|
|
2969
|
+
}), [e, t])), null;
|
|
2970
|
+
}
|
|
2971
|
+
//#endregion
|
|
2972
|
+
//#region src/crud/filters/DateFilter.tsx
|
|
2973
|
+
function Ar({ source: e, label: t }) {
|
|
2974
|
+
return Z(s(() => ({
|
|
2975
|
+
key: e,
|
|
2976
|
+
source: e,
|
|
2977
|
+
label: t,
|
|
2978
|
+
render: ({ value: n, onChange: r }) => /* @__PURE__ */ V(w, {
|
|
2979
|
+
allowClear: !0,
|
|
2980
|
+
placeholder: t ?? e,
|
|
2981
|
+
value: n ? xe(String(n)) : null,
|
|
2982
|
+
onChange: (e) => r(e ? e.format("YYYY-MM-DD") : void 0),
|
|
2983
|
+
style: { minWidth: 160 }
|
|
2984
|
+
})
|
|
2985
|
+
}), [e, t])), null;
|
|
2986
|
+
}
|
|
2987
|
+
//#endregion
|
|
2988
|
+
//#region src/crud/filters/SelectFilter.tsx
|
|
2989
|
+
function jr({ source: e, label: t, choices: n, multiple: r }) {
|
|
2990
|
+
return Z(s(() => ({
|
|
2991
|
+
key: e,
|
|
2992
|
+
source: e,
|
|
2993
|
+
label: t,
|
|
2994
|
+
render: ({ value: i, onChange: a }) => /* @__PURE__ */ V(P, {
|
|
2995
|
+
allowClear: !0,
|
|
2996
|
+
mode: r ? "multiple" : void 0,
|
|
2997
|
+
placeholder: t ?? e,
|
|
2998
|
+
value: i,
|
|
2999
|
+
onChange: a,
|
|
3000
|
+
options: n,
|
|
3001
|
+
style: { minWidth: 160 }
|
|
3002
|
+
})
|
|
3003
|
+
}), [
|
|
3004
|
+
e,
|
|
3005
|
+
t,
|
|
3006
|
+
n,
|
|
3007
|
+
r
|
|
3008
|
+
])), null;
|
|
3009
|
+
}
|
|
3010
|
+
//#endregion
|
|
3011
|
+
//#region src/crud/filters/ReferenceFilter.tsx
|
|
3012
|
+
function Mr({ source: e, label: t, reference: n, choices: r, optionLabel: i, optionValue: a, multiple: o, search: s, value: c, onChange: u }) {
|
|
3013
|
+
let [d, f] = l(), { options: p, loading: m } = $(r, n, i, a, s ? d : void 0);
|
|
3014
|
+
return /* @__PURE__ */ V(P, {
|
|
3015
|
+
allowClear: !0,
|
|
3016
|
+
mode: o ? "multiple" : void 0,
|
|
3017
|
+
placeholder: t ?? e,
|
|
3018
|
+
value: c,
|
|
3019
|
+
onChange: u,
|
|
3020
|
+
options: p.map((e) => ({
|
|
3021
|
+
label: e.label,
|
|
3022
|
+
value: e.value
|
|
3023
|
+
})),
|
|
3024
|
+
loading: m,
|
|
3025
|
+
showSearch: s,
|
|
3026
|
+
filterOption: s ? !1 : void 0,
|
|
3027
|
+
onSearch: s ? f : void 0,
|
|
3028
|
+
optionFilterProp: "label",
|
|
3029
|
+
style: { minWidth: 180 }
|
|
3030
|
+
});
|
|
3031
|
+
}
|
|
3032
|
+
function Nr({ source: e, label: t, reference: n, choices: r, optionLabel: i = "name", optionValue: a = "id", multiple: o, search: c }) {
|
|
3033
|
+
return Z(s(() => ({
|
|
3034
|
+
key: e,
|
|
3035
|
+
source: e,
|
|
3036
|
+
label: t,
|
|
3037
|
+
render: ({ value: s, onChange: l }) => /* @__PURE__ */ V(Mr, {
|
|
3038
|
+
source: e,
|
|
3039
|
+
label: t,
|
|
3040
|
+
reference: n,
|
|
3041
|
+
choices: r,
|
|
3042
|
+
optionLabel: i,
|
|
3043
|
+
optionValue: a,
|
|
3044
|
+
multiple: o,
|
|
3045
|
+
search: c,
|
|
3046
|
+
value: s,
|
|
3047
|
+
onChange: l
|
|
3048
|
+
})
|
|
3049
|
+
}), [
|
|
3050
|
+
e,
|
|
3051
|
+
t,
|
|
3052
|
+
n,
|
|
3053
|
+
r,
|
|
3054
|
+
i,
|
|
3055
|
+
a,
|
|
3056
|
+
o,
|
|
3057
|
+
c
|
|
3058
|
+
])), null;
|
|
3059
|
+
}
|
|
3060
|
+
function Pr(e) {
|
|
3061
|
+
return /* @__PURE__ */ V(Nr, {
|
|
3062
|
+
...e,
|
|
3063
|
+
multiple: !0
|
|
3064
|
+
});
|
|
3065
|
+
}
|
|
3066
|
+
//#endregion
|
|
3067
|
+
export { dt as AdminApp, $e as AdminLayout, Oe as AppThemeProvider, Vt as AuthAlternateLink, Ht as AuthPageLayout, Ie as AuthProvider, br as BooleanColumn, rr as BooleanField, kr as BooleanFilter, Er as CustomColumn, pt as DataProvider, xr as DateColumn, ar as DateField, Ar as DateFilter, je as DensitySwitch, An as FilterBar, Xn as FormStep, Qn as FormSteps, qn as FormTab, Yn as FormTabs, et as Guard, nt as GuestOnly, zn as InlineFormSet, Ut as LoginPage, yr as NumberColumn, nr as NumberField, Or as NumberFilter, cr as PasswordField, Ve as PermissionsProvider, Wt as PlaceholderPage, tt as Protected, Cr as ReferenceColumn, hr as ReferenceField, Nr as ReferenceFilter, Tr as ReferenceManyColumn, gr as ReferenceManyField, Pr as ReferenceManyFilter, rt as RequirePermission, Un as ResourceForm, _n as ResourceFormModal, On as ResourceList, or as SelectField, jr as SelectFilter, _r as TextColumn, tr as TextField, Dr as TextFilter, Ne as ThemeSwitch, Pe as ThemeToolbar, Pt as applyInMemoryListParams, bt as applyInlineFieldPaths, Y as asStringMessages, _t as combineResourceHandlers, ut as createAdminRouter, Ft as createMemoryResourceHandlers, He as createPermissionsChecker, It as createRestResourceHandlers, ze as createSessionStorageAuthAdapter, ct as deriveAuthPaths, We as filterNavByPermission, Mt as filterRows, xt as finalizeFormErrors, dn as getByPath, yt as getErrorBody, it as getRouteAccess, kt as getRowById, Fn as inlineArrayName, Vn as loadInlineRows, Ct as parseDjangoDRFFormErrors, wt as parseDotNetFormErrors, Tt as parseNodeFormErrors, at as partitionAdminRoutes, pn as pickBySources, Bn as saveInlineRows, Rt as toDjangoRestOrdering, Bt as toJsonApiSort, zt as toODataOrderBy, Le as useAuth, Ue as useCan, $ as useChoices, mt as useDataProvider, wn as useListQueryState, q as usePermissions, un as useRegisterFormSource, En as useResourceListContext, ke as useThemeMode };
|