muffin-admin 11.8.0 → 13.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.
Files changed (99) hide show
  1. package/dist/MuffinAdmin.d.ts +5 -5
  2. package/dist/MuffinAdmin.js +1 -1
  3. package/dist/MuffinDashboard.d.ts +1 -1
  4. package/dist/MuffinDashboard.js +3 -3
  5. package/dist/MuffinMenu.d.ts +2 -2
  6. package/dist/MuffinMenu.js +2 -2
  7. package/dist/MuffinRecordList.d.ts +2 -2
  8. package/dist/MuffinRecordList.js +1 -1
  9. package/dist/MuffinResource.d.ts +2 -2
  10. package/dist/MuffinResourceCreate.d.ts +3 -3
  11. package/dist/MuffinResourceEdit.d.ts +6 -6
  12. package/dist/MuffinResourceEdit.js +36 -4
  13. package/dist/MuffinResourceList.d.ts +2 -2
  14. package/dist/MuffinResourceList.js +10 -5
  15. package/dist/MuffinResourceShow.d.ts +5 -5
  16. package/dist/MuffinResourceShow.js +43 -6
  17. package/dist/actions/LinkAction.d.ts +2 -2
  18. package/dist/authprovider.js +7 -9
  19. package/dist/buildRA.d.ts +4 -3
  20. package/dist/buildRA.js +1 -1
  21. package/dist/buttons/ActionButton.d.ts +5 -5
  22. package/dist/buttons/ActionButton.js +5 -5
  23. package/dist/buttons/CopyButton.d.ts +1 -1
  24. package/dist/buttons/LinkButton.d.ts +2 -2
  25. package/dist/buttons/LinkButton.js +8 -2
  26. package/dist/common/AdminModal.d.ts +6 -4
  27. package/dist/common/AdminModal.js +2 -2
  28. package/dist/common/ConfirmationProvider.d.ts +2 -2
  29. package/dist/common/ConfirmationProvider.js +1 -1
  30. package/dist/common/HelpLink.d.ts +1 -1
  31. package/dist/common/PayloadButtons.d.ts +1 -1
  32. package/dist/common/PayloadButtons.js +1 -1
  33. package/dist/context.d.ts +1 -1
  34. package/dist/dataprovider.d.ts +7 -7
  35. package/dist/fields/AvatarField.d.ts +3 -3
  36. package/dist/fields/AvatarField.js +2 -2
  37. package/dist/fields/CopyField.d.ts +1 -1
  38. package/dist/fields/EditableBooleanField.d.ts +1 -1
  39. package/dist/fields/FKField.d.ts +4 -4
  40. package/dist/fields/FKField.js +12 -2
  41. package/dist/fields/JsonField.d.ts +1 -1
  42. package/dist/filters/DateRangeFilter.d.ts +1 -1
  43. package/dist/filters/Filter.d.ts +2 -2
  44. package/dist/filters/Filter.js +2 -2
  45. package/dist/filters/SearchFilter.d.ts +2 -2
  46. package/dist/filters/SearchFilter.js +6 -4
  47. package/dist/hooks/useAction.d.ts +2 -2
  48. package/dist/hooks/useAction.js +2 -2
  49. package/dist/i18n/en.d.ts +1 -1
  50. package/dist/i18n/provider.d.ts +3 -3
  51. package/dist/i18n/ru.d.ts +1 -1
  52. package/dist/index.d.ts +11 -11
  53. package/dist/index.js +12 -12
  54. package/dist/inputs/DateRangeInput.d.ts +2 -2
  55. package/dist/inputs/FKInput.d.ts +2 -2
  56. package/dist/inputs/ImgInput.d.ts +2 -2
  57. package/dist/inputs/JsonInput.d.ts +1 -1
  58. package/dist/inputs/JsonInput.js +1 -1
  59. package/dist/inputs/TimestampInput.d.ts +2 -2
  60. package/dist/utils.d.ts +2 -2
  61. package/dist/utils.js +1 -0
  62. package/dist/version.d.ts +1 -0
  63. package/dist/version.js +1 -0
  64. package/dist/web.js +0 -1
  65. package/package.json +15 -29
  66. package/src/MuffinAdmin.tsx +6 -7
  67. package/src/MuffinDashboard.tsx +6 -6
  68. package/src/MuffinMenu.tsx +3 -5
  69. package/src/MuffinRecordList.tsx +2 -2
  70. package/src/MuffinResource.tsx +1 -1
  71. package/src/MuffinResourceCreate.tsx +1 -1
  72. package/src/MuffinResourceEdit.tsx +73 -12
  73. package/src/MuffinResourceList.tsx +17 -6
  74. package/src/MuffinResourceShow.tsx +93 -15
  75. package/src/actions/LinkAction.tsx +1 -1
  76. package/src/authprovider.ts +88 -101
  77. package/src/buildRA.tsx +4 -3
  78. package/src/buttons/ActionButton.tsx +9 -10
  79. package/src/buttons/LinkButton.tsx +11 -3
  80. package/src/common/AdminModal.tsx +8 -5
  81. package/src/common/ConfirmationProvider.tsx +1 -1
  82. package/src/common/PayloadButtons.tsx +1 -1
  83. package/src/context.ts +1 -1
  84. package/src/dataprovider.ts +2 -2
  85. package/src/fields/AvatarField.tsx +8 -10
  86. package/src/fields/FKField.tsx +14 -2
  87. package/src/filters/Filter.tsx +2 -2
  88. package/src/filters/SearchFilter.tsx +14 -7
  89. package/src/globals.d.ts +1 -0
  90. package/src/hooks/useAction.ts +4 -4
  91. package/src/i18n/en.ts +1 -1
  92. package/src/i18n/ru.ts +1 -1
  93. package/src/index.tsx +12 -13
  94. package/src/inputs/DateRangeInput.tsx +1 -1
  95. package/src/inputs/JsonInput.tsx +1 -1
  96. package/src/utils.tsx +2 -1
  97. package/src/version.ts +1 -0
  98. package/src/web.ts +0 -1
  99. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,5 +1,5 @@
1
- import { AdminProps, AppBarProps, LayoutProps, LoginProps } from "react-admin";
2
- export declare function MuffinAdmin({ lightTheme, darkTheme, ...props }: AdminProps): import("react/jsx-runtime").JSX.Element;
3
- export declare function MuffinAdminLayout(props: LayoutProps): import("react/jsx-runtime").JSX.Element;
4
- export declare function MuffinAppBar(props: AppBarProps): import("react/jsx-runtime").JSX.Element;
5
- export declare function MuffinLogin(props: LoginProps): import("react/jsx-runtime").JSX.Element;
1
+ import { type AdminProps, type AppBarProps, type LayoutProps, type LoginProps } from "react-admin";
2
+ export declare function MuffinAdmin({ lightTheme, darkTheme, ...props }: AdminProps): import("react").JSX.Element;
3
+ export declare function MuffinAdminLayout(props: LayoutProps): import("react").JSX.Element;
4
+ export declare function MuffinAppBar(props: AppBarProps): import("react").JSX.Element;
5
+ export declare function MuffinLogin(props: LoginProps): import("react").JSX.Element;
@@ -14,8 +14,8 @@ import IconButton from "@mui/material/IconButton";
14
14
  import SvgIcon from "@mui/material/SvgIcon";
15
15
  import Tooltip from "@mui/material/Tooltip";
16
16
  import Typography from "@mui/material/Typography";
17
- import { AdminContext, AdminUI, AppBar, Layout, localStorageStore, Login, } from "react-admin";
18
17
  import { useEffect } from "react";
18
+ import { AdminContext, AdminUI, AppBar, Layout, Login, localStorageStore, } from "react-admin";
19
19
  import { ConfirmationProvider } from "./common";
20
20
  import { useMuffinAdminOpts } from "./hooks";
21
21
  import { buildProvider, muffinTranslations } from "./i18n";
@@ -1 +1 @@
1
- export declare function MuffinDashboard(): import("react/jsx-runtime").JSX.Element;
1
+ export declare function MuffinDashboard(): import("react").JSX.Element;
@@ -9,14 +9,14 @@ import TableCell from "@mui/material/TableCell";
9
9
  import TableRow from "@mui/material/TableRow";
10
10
  import Typography from "@mui/material/Typography";
11
11
  import { useTranslate } from "react-admin";
12
- import { VERSION } from ".";
13
12
  import { HelpLink } from "./common/HelpLink";
14
13
  import { useMuffinAdminOpts } from "./hooks";
15
14
  import { buildAdmin, setupAdmin } from "./utils";
15
+ import { VERSION } from "./version";
16
16
  export function MuffinDashboard() {
17
17
  const { dashboard, help } = useMuffinAdminOpts();
18
18
  const translate = useTranslate();
19
- return (_jsxs(Stack, { gap: 2, pt: 1, children: [_jsxs(Stack, { direction: "row", flexWrap: "wrap", gap: 1, children: [help && _jsx(HelpLink, { href: help, label: translate("muffin.how_to_use_admin") }), buildAdmin(["dashboard-actions"])] }), _jsxs(Grid, { container: true, spacing: 1, children: [buildAdmin(["dashboard-content"]), _jsx(AdminCards, { src: dashboard })] }), VERSION && (_jsxs(Typography, { variant: "body2", color: "textSecondary", align: "center", my: 1, children: ["Muffin Admin v.", VERSION] }))] }));
19
+ return (_jsxs(Stack, { sx: { gap: 2, pt: 1 }, children: [_jsxs(Stack, { direction: "row", sx: { flexWrap: "wrap", gap: 1 }, children: [help && _jsx(HelpLink, { href: help, label: translate("muffin.how_to_use_admin") }), buildAdmin(["dashboard-actions"])] }), _jsxs(Grid, { container: true, spacing: 1, children: [buildAdmin(["dashboard-content"]), _jsx(AdminCards, { src: dashboard })] }), VERSION && (_jsxs(Typography, { variant: "body2", color: "textSecondary", align: "center", sx: { my: 1 }, children: ["Muffin Admin v.", VERSION] }))] }));
20
20
  }
21
21
  setupAdmin(["dashboard"], MuffinDashboard);
22
22
  setupAdmin(["dashboard-actions"], () => null);
@@ -27,6 +27,6 @@ function AdminCards({ src }) {
27
27
  return _jsx(DashboardCard, Object.assign({}, src));
28
28
  }
29
29
  function DashboardCard({ title, value }) {
30
- return (_jsx(Card, { children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h5", component: "h2", m: 2, style: { textAlign: "center" }, children: title }), (Array.isArray(value) && _jsx(AdminTableView, { src: value })) || (_jsx("pre", { children: JSON.stringify(value, null, 2) }))] }) }));
30
+ return (_jsx(Card, { children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h5", component: "h2", sx: { m: 2, textAlign: "center" }, children: title }), (Array.isArray(value) && _jsx(AdminTableView, { src: value })) || (_jsx("pre", { children: JSON.stringify(value, null, 2) }))] }) }));
31
31
  }
32
32
  const AdminTableView = ({ src }) => (_jsx(Table, { width: "100%", sx: { tableLayout: "fixed" }, children: _jsx(TableBody, { children: src.map((row, idx) => (_jsx(TableRow, { hover: true, children: row.map((cell, idx) => (_jsx(TableCell, { children: cell }, idx))) }, idx))) }) }));
@@ -1,2 +1,2 @@
1
- import { MenuProps } from "react-admin";
2
- export declare function MuffinMenu(props: MenuProps): import("react/jsx-runtime").JSX.Element;
1
+ import { type MenuProps } from "react-admin";
2
+ export declare function MuffinMenu(props: MenuProps): import("react").JSX.Element;
@@ -5,11 +5,11 @@ import Collapse from "@mui/material/Collapse";
5
5
  import ListItemButton from "@mui/material/ListItemButton";
6
6
  import ListItemIcon from "@mui/material/ListItemIcon";
7
7
  import ListItemText from "@mui/material/ListItemText";
8
- import { matchPath, useLocation } from "react-router-dom";
9
- import { Menu, useBasename, useTheme, useTranslate } from "react-admin";
10
8
  import find from "lodash/find";
11
9
  import groupBy from "lodash/groupBy";
12
10
  import { useContext, useState } from "react";
11
+ import { Menu, useBasename, useTheme, useTranslate } from "react-admin";
12
+ import { matchPath, useLocation } from "react-router-dom";
13
13
  import { MuffinAdminContext } from "./context";
14
14
  import { findIcon, setupAdmin } from "./utils";
15
15
  export function MuffinMenu(props) {
@@ -1,8 +1,8 @@
1
- import { SortPayload } from "react-admin";
1
+ import { type SortPayload } from "react-admin";
2
2
  type TProps = {
3
3
  resource: string;
4
4
  filter: (record: any) => Record<string, any>;
5
5
  sort?: SortPayload;
6
6
  };
7
- export declare function MuffinRecordList({ resource, filter, sort }: TProps): import("react/jsx-runtime").JSX.Element;
7
+ export declare function MuffinRecordList({ resource, filter, sort }: TProps): import("react").JSX.Element;
8
8
  export {};
@@ -9,5 +9,5 @@ export function MuffinRecordList({ resource, filter, sort }) {
9
9
  const translate = useTranslate();
10
10
  const { list: { fields }, } = useMuffinResourceOpts(resource);
11
11
  const { data, isPending } = useGetList(resource, { sort, filter: filter(record) });
12
- return (_jsxs(Box, { p: 2, children: [_jsx(Typography, { variant: "h6", children: translate(`resources.${resource}.name`, { smart_count: 2 }) }), _jsx(Datagrid, { resource: resource, bulkActionButtons: false, isPending: isPending, data: data, children: buildAdmin(["list-fields", resource], fields) })] }));
12
+ return (_jsxs(Box, { sx: { p: 2 }, children: [_jsx(Typography, { variant: "h6", children: translate(`resources.${resource}.name`, { smart_count: 2 }) }), _jsx(Datagrid, { resource: resource, bulkActionButtons: false, isPending: isPending, data: data, children: buildAdmin(["list-fields", resource], fields) })] }));
13
13
  }
@@ -1,2 +1,2 @@
1
- import { ResourceProps } from "react-admin";
2
- export declare function MuffinResource({ name, ...props }: ResourceProps): import("react/jsx-runtime").JSX.Element;
1
+ import { type ResourceProps } from "react-admin";
2
+ export declare function MuffinResource({ name, ...props }: ResourceProps): import("react").JSX.Element;
@@ -1,3 +1,3 @@
1
- import { PropsWithChildren } from "react";
2
- export declare function MuffinResourceCreate({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
3
- export declare function MuffinCreateToolbar({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
1
+ import type { PropsWithChildren } from "react";
2
+ export declare function MuffinResourceCreate({ children }: PropsWithChildren): import("react").JSX.Element;
3
+ export declare function MuffinCreateToolbar({ children }: PropsWithChildren): import("react").JSX.Element;
@@ -1,6 +1,6 @@
1
- import { PropsWithChildren } from "react";
2
- export declare function MuffinEdit({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
3
- export declare function MuffinEditFormToolbar(): import("react/jsx-runtime").JSX.Element;
4
- export declare function MuffinEditInputs(): import("react/jsx-runtime").JSX.Element;
5
- export declare function MuffinEditToolbar({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
6
- export declare function MuffinEditActions({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
1
+ import type { PropsWithChildren } from "react";
2
+ export declare function MuffinEdit({ children }: PropsWithChildren): import("react").JSX.Element;
3
+ export declare function MuffinEditFormToolbar(): import("react").JSX.Element;
4
+ export declare function MuffinEditInputs(): import("react").JSX.Element;
5
+ export declare function MuffinEditToolbar({ children }: PropsWithChildren): import("react").JSX.Element;
6
+ export declare function MuffinEditActions({ children }: PropsWithChildren): import("react").JSX.Element;
@@ -1,18 +1,48 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { DeleteButton, Edit, ListButton, SaveButton, ShowButton, SimpleForm, Toolbar, TopToolbar, useResourceContext, } from "react-admin";
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Typography } from "@mui/material";
3
+ import { DeleteButton, Edit, ListButton, SaveButton, ShowButton, SimpleForm, Toolbar, TopToolbar, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
4
+ import { useLocation, useNavigate } from "react-router-dom";
3
5
  import { buildRA } from "./buildRA";
4
6
  import { ActionButton } from "./buttons";
7
+ import { AdminModal } from "./common";
5
8
  import { useMuffinAdminOpts, useMuffinResourceOpts } from "./hooks";
6
9
  import { findBuilder, setupAdmin } from "./utils";
7
10
  export function MuffinEdit({ children }) {
8
11
  const { adminProps: { mutationMode = "optimistic" }, } = useMuffinAdminOpts();
9
12
  const { edit, name, key } = useMuffinResourceOpts();
13
+ const location = useLocation();
14
+ const navigate = useNavigate();
15
+ const returnTo = new URLSearchParams(location.search).get("returnTo");
10
16
  if (!edit)
11
17
  return null;
18
+ const handleClose = () => {
19
+ if (returnTo) {
20
+ navigate(returnTo);
21
+ return;
22
+ }
23
+ if (window.history.length > 1) {
24
+ navigate(-1);
25
+ return;
26
+ }
27
+ navigate(`/${name}`);
28
+ };
12
29
  const Actions = findBuilder(["edit-toolbar", name]);
13
30
  const Inputs = findBuilder(["edit-inputs", name]);
14
31
  const FormToolbar = findBuilder(["edit-form-toolbar", name]);
15
- return (_jsxs(Edit, { actions: _jsx(Actions, {}), mutationMode: mutationMode, queryOptions: { meta: { key } }, children: [children, _jsx(SimpleForm, { toolbar: _jsx(FormToolbar, {}), children: _jsx(Inputs, {}) })] }));
32
+ return (_jsx(Edit, { actions: false, title: false, component: "div", mutationMode: mutationMode, queryOptions: { meta: { key } }, sx: {
33
+ "& .RaEdit-main": {
34
+ padding: 0,
35
+ },
36
+ }, children: _jsxs(AdminModal, { open: true, onClose: handleClose, title: _jsx(Actions, {}), maxWidth: "xl", contentSx: {
37
+ paddingTop: "8px !important",
38
+ paddingBottom: "12px !important",
39
+ paddingLeft: "16px !important",
40
+ paddingRight: "16px !important",
41
+ }, sx: {
42
+ "& .MuiDialog-paper": {
43
+ width: "min(1400px, 96vw)",
44
+ },
45
+ }, children: [children, _jsx(SimpleForm, { toolbar: _jsx(FormToolbar, {}), children: _jsx(Inputs, {}) })] }) }));
16
46
  }
17
47
  setupAdmin(["edit"], MuffinEdit);
18
48
  export function MuffinEditFormToolbar() {
@@ -33,8 +63,10 @@ export function MuffinEditInputs() {
33
63
  setupAdmin(["edit-inputs"], MuffinEditInputs);
34
64
  export function MuffinEditToolbar({ children }) {
35
65
  const resource = useResourceContext();
66
+ const record = useRecordContext();
67
+ const translate = useTranslate();
36
68
  const Actions = findBuilder(["edit-actions", resource]);
37
- return (_jsxs(TopToolbar, { children: [_jsx(Actions, {}), children, _jsx(ListButton, {}), _jsx(ShowButton, {})] }));
69
+ return (_jsx(Box, { sx: { display: "flex", flexDirection: "column", width: "100%" }, children: _jsxs(TopToolbar, { sx: { pl: 0, pr: 0, width: "100%", justifyContent: "space-between" }, children: [_jsxs(Typography, { variant: "h6", sx: { mr: 2 }, children: [translate(`resources.${resource}.name`, { smart_count: 1, _: resource }), (record === null || record === void 0 ? void 0 : record.id) ? ` #${record.id}` : ""] }), _jsxs(Box, { sx: { display: "flex", alignItems: "center" }, children: [_jsx(Actions, {}), children, _jsx(ShowButton, {}), _jsx(ListButton, {})] })] }) }));
38
70
  }
39
71
  setupAdmin(["edit-toolbar"], MuffinEditToolbar);
40
72
  export function MuffinEditActions({ children }) {
@@ -1,2 +1,2 @@
1
- import { PropsWithChildren } from "react";
2
- export declare function MuffinList({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
1
+ import type { PropsWithChildren } from "react";
2
+ export declare function MuffinList({ children }: PropsWithChildren): import("react").JSX.Element;
@@ -1,7 +1,7 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import sortBy from "lodash/sortBy";
3
3
  import uniq from "lodash/uniq";
4
- import { BulkDeleteButton, BulkExportButton, CreateButton, DatagridConfigurable, EditButton, ExportButton, FilterButton, InfiniteList, List, Pagination, SelectColumnsButton, TopToolbar, } from "react-admin";
4
+ import { BulkDeleteButton, BulkExportButton, CreateButton, DatagridConfigurable, EditButton, FilterButton, InfiniteList, List, Pagination, SelectColumnsButton, TopToolbar, useTranslate, } from "react-admin";
5
5
  import { buildRA, buildRAComponent } from "./buildRA";
6
6
  import { BulkActionButton, ListActionButton } from "./buttons";
7
7
  import { HelpLink } from "./common/HelpLink";
@@ -33,19 +33,24 @@ function MuffinListDatagrid() {
33
33
  setupAdmin(["list-grid"], MuffinListDatagrid);
34
34
  function MuffinListGridButtons() {
35
35
  const { list } = useMuffinResourceOpts();
36
+ const translate = useTranslate();
36
37
  const { edit } = list;
37
38
  if (!edit)
38
39
  return null;
39
- return _jsx(EditButton, {});
40
+ return (_jsx(EditButton, { label: "", title: translate("ra.action.edit", { _: "Edit" }), sx: {
41
+ minWidth: "auto",
42
+ width: "100%",
43
+ justifyContent: "flex-end",
44
+ "& .MuiButton-startIcon": { margin: 0 },
45
+ } }));
40
46
  }
41
47
  setupAdmin(["list-grid-buttons"], MuffinListGridButtons);
42
48
  function MuffinListToolbar() {
43
49
  const { actions: baseActions = [], help, list: { create }, } = useMuffinResourceOpts();
44
50
  const actions = baseActions.filter((a) => { var _a; return (_a = a.view) === null || _a === void 0 ? void 0 : _a.includes("list"); });
45
- const hasExport = actions.some((a) => a.id === "export");
46
51
  return (_jsxs(TopToolbar, { children: [help && _jsx(HelpLink, { href: help }), _jsx(SelectColumnsButton, {}), _jsx(FilterButton, {}), create && _jsx(CreateButton, {}), actions.length
47
52
  ? actions.map((props) => _jsx(ListActionButton, Object.assign({}, props), props.id))
48
- : null, !hasExport && _jsx(ExportButton, {})] }));
53
+ : null] }));
49
54
  }
50
55
  setupAdmin(["list-toolbar"], MuffinListToolbar);
51
56
  function MuffinListActions() {
@@ -1,5 +1,5 @@
1
- import { PropsWithChildren } from "react";
2
- export declare function MuffinShow({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
3
- export declare function MuffinShowToolbar({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
4
- export declare function MuffinShowActions({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
5
- export declare function MuffinShowLinks({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
1
+ import type { PropsWithChildren } from "react";
2
+ export declare function MuffinShow({ children }: PropsWithChildren): import("react").JSX.Element;
3
+ export declare function MuffinShowToolbar(): import("react").JSX.Element;
4
+ export declare function MuffinShowActions({ children }: PropsWithChildren): import("react").JSX.Element;
5
+ export declare function MuffinShowLinks({ children }: PropsWithChildren): import("react").JSX.Element;
@@ -1,23 +1,60 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { EditButton, ListButton, Show, SimpleShowLayout, TopToolbar } from "react-admin";
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Typography } from "@mui/material";
3
+ import { EditButton, ListButton, Show, SimpleShowLayout, TopToolbar, useRecordContext, useTranslate, } from "react-admin";
4
+ import { useLocation, useNavigate } from "react-router-dom";
3
5
  import { LinkAction } from "./actions";
4
6
  import { buildRA } from "./buildRA";
5
7
  import { ActionButton } from "./buttons";
8
+ import { AdminModal } from "./common";
6
9
  import { useMuffinResourceOpts } from "./hooks";
7
10
  import { buildAdmin, findBuilder, setupAdmin } from "./utils";
8
11
  export function MuffinShow({ children }) {
9
12
  const { show, name, key } = useMuffinResourceOpts();
13
+ const location = useLocation();
14
+ const navigate = useNavigate();
10
15
  const ShowToolbar = findBuilder(["show-toolbar", name]);
11
- return (_jsxs(Show, { actions: _jsx(ShowToolbar, {}), queryOptions: { meta: { key } }, children: [_jsx(SimpleShowLayout, { children: buildAdmin(["show-fields", name], show) }), children] }));
16
+ const returnTo = new URLSearchParams(location.search).get("returnTo");
17
+ const handleClose = () => {
18
+ if (returnTo) {
19
+ navigate(returnTo);
20
+ return;
21
+ }
22
+ if (window.history.length > 1) {
23
+ navigate(-1);
24
+ return;
25
+ }
26
+ navigate(`/${name}`);
27
+ };
28
+ return (_jsx(Show, { actions: false, title: false, component: "div", queryOptions: { meta: { key } }, sx: {
29
+ "& .RaShow-main": {
30
+ padding: 0,
31
+ },
32
+ }, children: _jsxs(AdminModal, { open: true, onClose: handleClose, title: _jsx(ShowToolbar, {}), maxWidth: "xl", hideBackdrop: true, disableScrollLock: true, contentSx: {
33
+ paddingTop: "8px !important",
34
+ paddingBottom: "12px !important",
35
+ paddingLeft: "16px !important",
36
+ paddingRight: "16px !important",
37
+ }, sx: {
38
+ "& .MuiDialog-paper": {
39
+ width: "min(1400px, 96vw)",
40
+ },
41
+ }, children: [_jsx(SimpleShowLayout, { sx: {
42
+ padding: 0,
43
+ "& .RaSimpleShowLayout-stack": {
44
+ rowGap: 1,
45
+ },
46
+ }, children: buildAdmin(["show-fields", name], show) }), children] }) }));
12
47
  }
13
48
  setupAdmin(["show"], MuffinShow);
14
49
  setupAdmin(["show-fields"], ({ fields }) => buildRA(fields));
15
- export function MuffinShowToolbar({ children }) {
50
+ export function MuffinShowToolbar() {
16
51
  const { show, name } = useMuffinResourceOpts();
52
+ const record = useRecordContext();
53
+ const translate = useTranslate();
17
54
  const { edit } = show;
18
55
  const Links = findBuilder(["show-links", name]);
19
56
  const Actions = findBuilder(["show-actions", name]);
20
- return (_jsxs(TopToolbar, { children: [_jsx(Links, {}), _jsx(Actions, {}), children, _jsx(ListButton, {}), edit && _jsx(EditButton, {})] }));
57
+ return (_jsxs(Box, { sx: { display: "flex", flexDirection: "column", width: "100%" }, children: [_jsxs(TopToolbar, { sx: { pl: 0, pr: 0, width: "100%", justifyContent: "space-between" }, children: [_jsxs(Typography, { variant: "h6", sx: { mr: 2 }, children: [translate(`resources.${name}.name`, { smart_count: 1, _: name }), (record === null || record === void 0 ? void 0 : record.id) ? ` #${record.id}` : ""] }), _jsxs(Box, { sx: { display: "flex", alignItems: "center" }, children: [_jsx(Actions, {}), edit && _jsx(EditButton, {}), _jsx(ListButton, {})] })] }), _jsx(Box, { sx: { mt: 0.5 }, children: _jsx(Links, {}) })] }));
21
58
  }
22
59
  setupAdmin(["show-toolbar"], MuffinShowToolbar);
23
60
  export function MuffinShowActions({ children }) {
@@ -29,6 +66,6 @@ setupAdmin(["show-actions"], MuffinShowActions);
29
66
  export function MuffinShowLinks({ children }) {
30
67
  const { show } = useMuffinResourceOpts();
31
68
  const { links } = show;
32
- return (_jsxs("div", { style: { marginRight: "auto" }, children: [links.map(([key, props]) => (_jsx(LinkAction, Object.assign({ resource: key }, props), key))), children] }));
69
+ return (_jsxs(Box, { sx: { display: "flex", flexWrap: "wrap", gap: 1 }, children: [links.map(([key, props]) => (_jsx(LinkAction, Object.assign({ resource: key }, props), key))), children] }));
33
70
  }
34
71
  setupAdmin(["show-links"], MuffinShowLinks);
@@ -1,4 +1,4 @@
1
- import { AdminShowLink } from "../types";
1
+ import type { AdminShowLink } from "../types";
2
2
  export declare function LinkAction({ field, filter, icon, label, ...props }: AdminShowLink & {
3
3
  resource: string;
4
- }): import("react/jsx-runtime").JSX.Element;
4
+ }): import("react").JSX.Element;
@@ -8,27 +8,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import Cookies from "js-cookie";
11
- import { findBuilder, makeRequest, requestHeaders, setupAdmin } from ".";
12
- setupAdmin(["auth-storage-get"], ({ storage, storageName }) => () => storage == "localstorage"
13
- ? localStorage.getItem(storageName)
14
- : Cookies.get(storageName));
15
- setupAdmin(["auth-storage-set"], ({ storage }) => (name, value, requestOnly) => {
11
+ import { findBuilder, makeRequest, requestHeaders, setupAdmin } from "./utils";
12
+ setupAdmin(["auth-storage-get"], ({ storage, storageName }) => () => storage == "localstorage" ? localStorage.getItem(storageName) : Cookies.get(storageName));
13
+ setupAdmin(["auth-storage-set"], ({ storage }) => (name, value, _requestOnly) => {
16
14
  if (storage == "localstorage") {
17
15
  localStorage.setItem(name, value);
18
- requestHeaders["Authorization"] = value;
16
+ requestHeaders.Authorization = value;
19
17
  }
20
18
  else
21
19
  Cookies.set(name, value);
22
20
  });
23
21
  export function MuffinAuthProvider(props) {
24
- const { identityURL, authorizeURL, logoutURL, required, storageName, storage, } = props;
22
+ const { identityURL, authorizeURL, logoutURL, required, storageName, storage } = props;
25
23
  const authGet = findBuilder(["auth-storage-get"])(props);
26
24
  const authSet = findBuilder(["auth-storage-set"])(props);
27
25
  // Initialize request headers
28
26
  if (storage == "localstorage") {
29
27
  const token = authGet(storageName);
30
28
  if (token)
31
- requestHeaders["Authorization"] = token;
29
+ requestHeaders.Authorization = token;
32
30
  }
33
31
  const getIdentity = () => __awaiter(this, void 0, void 0, function* () {
34
32
  if (identityURL) {
@@ -79,7 +77,7 @@ export function MuffinAuthProvider(props) {
79
77
  }),
80
78
  getIdentity,
81
79
  getPermissions: () => __awaiter(this, void 0, void 0, function* () {
82
- const role = authGet(storageName + "_role");
80
+ const role = authGet(`${storageName}_role`);
83
81
  return role || "";
84
82
  }),
85
83
  };
package/dist/buildRA.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export declare function buildRAComponent(name: string, props: any): import("react/jsx-runtime").JSX.Element;
2
- export declare function buildRA(items: [string, Record<string, any>][]): import("react/jsx-runtime").JSX.Element[];
3
- export declare function registerUI(name: string, component: JSX.ElementType): void;
1
+ import type { ElementType } from "react";
2
+ export declare function buildRAComponent(name: string, props: any): import("react").JSX.Element;
3
+ export declare function buildRA(items: [string, Record<string, any>][]): import("react").JSX.Element[];
4
+ export declare function registerUI(name: string, component: ElementType): void;
package/dist/buildRA.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { ArrayField, ArrayInput, AutocompleteArrayInput, AutocompleteInput, BooleanField, BooleanInput, CheckboxGroupInput, ChipField, DateField, DateInput, DateTimeInput, EmailField, FileField, FileInput, ImageField, ImageInput, NullableBooleanInput, NumberField, NumberInput, PasswordInput, RadioButtonGroupInput, ReferenceArrayField, ReferenceArrayInput, ReferenceField, ReferenceInput, ReferenceManyField, required, RichTextField, SearchInput, SelectArrayInput, SelectField, SelectInput, TextField, TextInput, UrlField, } from "react-admin";
2
+ import { ArrayField, ArrayInput, AutocompleteArrayInput, AutocompleteInput, BooleanField, BooleanInput, CheckboxGroupInput, ChipField, DateField, DateInput, DateTimeInput, EmailField, FileField, FileInput, ImageField, ImageInput, NullableBooleanInput, NumberField, NumberInput, PasswordInput, RadioButtonGroupInput, ReferenceArrayField, ReferenceArrayInput, ReferenceField, ReferenceInput, ReferenceManyField, RichTextField, required, SearchInput, SelectArrayInput, SelectField, SelectInput, TextField, TextInput, UrlField, } from "react-admin";
3
3
  import { AvatarField, CopyField, EditableBooleanField, FKField, JsonField } from "./fields";
4
4
  import { DateRangeFilter, Filter, SearchFilter } from "./filters";
5
5
  import { FKInput, ImgInput, JsonInput, TimestampInput } from "./inputs";
@@ -1,10 +1,10 @@
1
- import { AdminAction, AdminPayloadProps } from "../types";
1
+ import type { AdminAction, AdminPayloadProps } from "../types";
2
2
  export type ActionPayloadProps = {
3
3
  active: boolean;
4
4
  onClose: () => void;
5
5
  onHandle: (payload: any) => void;
6
6
  };
7
- export declare function ActionButton({ paths, confirm, file, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
8
- export declare function ListActionButton({ paths, confirm, file, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
9
- export declare function BulkActionButton({ paths, confirm, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
10
- export declare function CommonPayload({ active, onClose, onHandle, schema, title, help, }: AdminPayloadProps): import("react/jsx-runtime").JSX.Element;
7
+ export declare function ActionButton({ paths, confirm, file, ...props }: AdminAction): import("react").JSX.Element;
8
+ export declare function ListActionButton({ paths, confirm, file, ...props }: AdminAction): import("react").JSX.Element;
9
+ export declare function BulkActionButton({ paths, confirm, ...props }: AdminAction): import("react").JSX.Element;
10
+ export declare function CommonPayload({ active, onClose, onHandle, schema, title, help, }: AdminPayloadProps): import("react").JSX.Element;
@@ -18,11 +18,11 @@ var __rest = (this && this.__rest) || function (s, e) {
18
18
  }
19
19
  return t;
20
20
  };
21
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
22
- import { Button, FormGroupsProvider, useAugmentedForm, useListContext, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
23
- import { FormProvider } from "react-hook-form";
21
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
22
  import { Link, Stack } from "@mui/material";
25
23
  import { useState } from "react";
24
+ import { Button, FormGroupsProvider, useAugmentedForm, useListContext, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
25
+ import { FormProvider } from "react-hook-form";
26
26
  import { buildRA } from "../buildRA";
27
27
  import { AdminModal, PayloadButtons, useConfirmation } from "../common";
28
28
  import { HelpLink } from "../common/HelpLink";
@@ -99,7 +99,7 @@ export function CommonPayload({ active, onClose, onHandle, schema, title, help,
99
99
  record: {},
100
100
  });
101
101
  return (_jsx(FormProvider, Object.assign({}, form, { children: _jsx(FormGroupsProvider, { children: _jsx(AdminModal, { maxWidth: "sm", open: active, onClose: onClose, title: help
102
- ? (_jsxs(Stack, { alignItems: "flex-start", children: [_jsx("span", { children: translate(title, { _: title }) }), _jsx(HelpLink, { href: help, style: { alignSelf: "flex-end" } })] }))
102
+ ? (_jsxs(Stack, { sx: { alignItems: "flex-start" }, children: [_jsx("span", { children: translate(title, { _: title }) }), _jsx(HelpLink, { href: help, style: { alignSelf: "flex-end" } })] }))
103
103
  : translate(title, { _: title }), actions: _jsx(PayloadButtons, { onClose: onClose, onSubmit: formHandleSubmit, isValid: form.formState.isValid }), children: inputs }) }) })));
104
104
  }
105
105
  function FileButton({ path, record, label, icon, filterValues, }) {
@@ -107,7 +107,7 @@ function FileButton({ path, record, label, icon, filterValues, }) {
107
107
  let url = `${apiUrl}${path}?f`;
108
108
  if (record)
109
109
  url = url.replace("{id}", record.id);
110
- const authorization = requestHeaders["Authorization"];
110
+ const authorization = requestHeaders.Authorization;
111
111
  if (authorization)
112
112
  url += `&t=${authorization}`;
113
113
  if (Object.keys(filterValues).length)
@@ -1,3 +1,3 @@
1
1
  export declare function CopyButton({ value }: {
2
2
  value: any;
3
- }): import("react/jsx-runtime").JSX.Element;
3
+ }): import("react").JSX.Element;
@@ -1,7 +1,7 @@
1
- import { AdminShowLink } from "../types";
1
+ import type { AdminShowLink } from "../types";
2
2
  declare const LinkButton: ({ filters, icon, label, resource, id, title, }: AdminShowLink & {
3
3
  resource: string;
4
4
  filters?: any;
5
5
  id?: string;
6
- }) => import("react/jsx-runtime").JSX.Element;
6
+ }) => import("react").JSX.Element;
7
7
  export default LinkButton;
@@ -1,11 +1,17 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Button } from "react-admin";
3
- import { Link } from "react-router-dom";
3
+ import { Link, useLocation } from "react-router-dom";
4
4
  import { buildIcon } from "../utils";
5
5
  const LinkButton = ({ filters, icon, label, resource, id, title, }) => {
6
+ const location = useLocation();
7
+ const searchParams = new URLSearchParams();
8
+ searchParams.set("returnTo", `${location.pathname}${location.search}`);
9
+ if (filters) {
10
+ searchParams.set("filter", JSON.stringify(filters));
11
+ }
6
12
  const linkParams = {
7
13
  pathname: `/${resource}`,
8
- search: filters ? `filter=${JSON.stringify(filters)}` : undefined,
14
+ search: `?${searchParams.toString()}`,
9
15
  };
10
16
  if (id)
11
17
  linkParams.pathname += `/${id}/show`;
@@ -1,10 +1,12 @@
1
- import { DialogProps } from "@mui/material";
2
- import { PropsWithChildren } from "react";
3
- interface IProps {
1
+ import { type DialogProps } from "@mui/material";
2
+ import type { SxProps, Theme } from "@mui/material/styles";
3
+ import type { PropsWithChildren } from "react";
4
+ interface IProps extends Omit<DialogProps, "title" | "open" | "onClose"> {
4
5
  open: boolean;
5
6
  onClose: () => void;
6
7
  title?: React.ReactNode;
7
8
  actions?: React.ReactNode;
9
+ contentSx?: SxProps<Theme>;
8
10
  }
9
- export declare function AdminModal({ open, onClose, children, title, actions, ...props }: PropsWithChildren<IProps & DialogProps>): import("react/jsx-runtime").JSX.Element;
11
+ export declare function AdminModal({ open, onClose, children, title, actions, contentSx, ...props }: PropsWithChildren<IProps>): import("react").JSX.Element;
10
12
  export {};
@@ -12,6 +12,6 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { Dialog, DialogActions, DialogContent, DialogTitle } from "@mui/material";
14
14
  export function AdminModal(_a) {
15
- var { open, onClose, children, title, actions } = _a, props = __rest(_a, ["open", "onClose", "children", "title", "actions"]);
16
- return (_jsxs(Dialog, Object.assign({ open: open, onClose: onClose, fullWidth: true, maxWidth: "md" }, props, { children: [title && _jsx(DialogTitle, { children: title }), _jsx(DialogContent, { children: children }), actions && _jsx(DialogActions, { children: actions })] })));
15
+ var { open, onClose, children, title, actions, contentSx } = _a, props = __rest(_a, ["open", "onClose", "children", "title", "actions", "contentSx"]);
16
+ return (_jsxs(Dialog, Object.assign({ open: open, onClose: onClose, fullWidth: true, maxWidth: "md" }, props, { children: [title && _jsx(DialogTitle, { children: title }), _jsx(DialogContent, { sx: contentSx, children: children }), actions && _jsx(DialogActions, { children: actions })] })));
17
17
  }
@@ -1,4 +1,4 @@
1
- import { PropsWithChildren } from "react";
1
+ import { type PropsWithChildren } from "react";
2
2
  type TConfirmProps = {
3
3
  title?: string;
4
4
  message: string;
@@ -8,6 +8,6 @@ type TConfirmContext = {
8
8
  confirm: (props: TConfirmProps) => Promise<boolean>;
9
9
  };
10
10
  export declare const ConfirmContext: import("react").Context<TConfirmContext>;
11
- export declare function ConfirmationProvider({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
11
+ export declare function ConfirmationProvider({ children }: PropsWithChildren): import("react").JSX.Element;
12
12
  export declare const useConfirmation: () => TConfirmContext;
13
13
  export {};
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Button, Typography } from "@mui/material";
3
3
  import { createContext, useContext, useState } from "react";
4
4
  import { useTranslate } from "react-admin";
@@ -1,2 +1,2 @@
1
1
  import { Button } from "react-admin";
2
- export declare function HelpLink({ label, ...props }: Parameters<typeof Button>[0]): import("react/jsx-runtime").JSX.Element;
2
+ export declare function HelpLink({ label, ...props }: Parameters<typeof Button>[0]): import("react").JSX.Element;
@@ -2,4 +2,4 @@ export declare function PayloadButtons({ onClose, onSubmit, isValid, }: {
2
2
  onClose: () => void;
3
3
  onSubmit?: (e: any) => void;
4
4
  isValid: boolean;
5
- }): import("react/jsx-runtime").JSX.Element;
5
+ }): import("react").JSX.Element;
@@ -2,5 +2,5 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Stack } from "@mui/material";
3
3
  import { Button } from "react-admin";
4
4
  export function PayloadButtons({ onClose, onSubmit, isValid = true, }) {
5
- return (_jsxs(Stack, { direction: "row", alignItems: "center", justifyContent: "flex-end", spacing: 1, children: [_jsx(Button, { label: "ra.action.confirm", variant: "contained", disabled: !isValid, size: "medium", onClick: onSubmit }), _jsx(Button, { label: "ra.action.cancel", variant: "outlined", size: "medium", onClick: onClose })] }));
5
+ return (_jsxs(Stack, { direction: "row", spacing: 1, sx: { alignItems: "center", justifyContent: "flex-end" }, children: [_jsx(Button, { label: "ra.action.confirm", variant: "contained", disabled: !isValid, size: "medium", onClick: onSubmit }), _jsx(Button, { label: "ra.action.cancel", variant: "outlined", size: "medium", onClick: onClose })] }));
6
6
  }
package/dist/context.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { AdminOpts } from "./types";
1
+ import type { AdminOpts } from "./types";
2
2
  export declare const MuffinAdminContext: import("react").Context<AdminOpts>;
@@ -1,5 +1,5 @@
1
- import { TID } from "./types";
2
- import { APIParams } from "./utils";
1
+ import type { TID } from "./types";
2
+ import { type APIParams } from "./utils";
3
3
  type TQueryMeta = {
4
4
  key?: string;
5
5
  };
@@ -16,9 +16,9 @@ export declare function MuffinDataprovider(apiUrl: string): {
16
16
  hasNextPage: boolean;
17
17
  };
18
18
  } | {
19
- data: any;
20
19
  total?: undefined;
21
20
  pageInfo?: undefined;
21
+ data: any;
22
22
  }>;
23
23
  getOne: (resource: string, { id, meta }: {
24
24
  id: TID;
@@ -68,15 +68,15 @@ export declare function MuffinDataprovider(apiUrl: string): {
68
68
  hasNextPage: boolean;
69
69
  };
70
70
  } | {
71
- data: any;
72
71
  total?: undefined;
73
72
  pageInfo?: undefined;
73
+ data: any;
74
74
  }>;
75
75
  getManyReference: (resource: string, { target, id, filter, ...opts }: {
76
76
  [x: string]: any;
77
- target: any;
78
- id: any;
79
77
  filter: any;
78
+ id: any;
79
+ target: any;
80
80
  }) => Promise<{
81
81
  data: any;
82
82
  total: number;
@@ -85,9 +85,9 @@ export declare function MuffinDataprovider(apiUrl: string): {
85
85
  hasNextPage: boolean;
86
86
  };
87
87
  } | {
88
- data: any;
89
88
  total?: undefined;
90
89
  pageInfo?: undefined;
90
+ data: any;
91
91
  }>;
92
92
  runAction: (_: string, action: string, props: TActionProps) => Promise<{
93
93
  data: any;