muffin-admin 9.4.3 → 9.5.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.
@@ -1,5 +1,5 @@
1
1
  import { AdminProps, AppBarProps, LayoutProps, LoginProps } from "react-admin";
2
- export declare function MuffinAdmin(props: AdminProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function MuffinAdmin({ lightTheme, darkTheme, ...props }: AdminProps): import("react/jsx-runtime").JSX.Element;
3
3
  export declare function MuffinAdminLayout(props: LayoutProps): import("react/jsx-runtime").JSX.Element;
4
4
  export declare function MuffinAppBar(props: AppBarProps): import("react/jsx-runtime").JSX.Element;
5
5
  export declare function MuffinLogin(props: LoginProps): import("react/jsx-runtime").JSX.Element;
@@ -1,3 +1,14 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
13
  import IconButton from "@mui/material/IconButton";
3
14
  import SvgIcon from "@mui/material/SvgIcon";
@@ -8,8 +19,10 @@ import { useEffect } from "react";
8
19
  import { ConfirmationProvider } from "./common";
9
20
  import { useMuffinAdminOpts } from "./hooks";
10
21
  import { buildProvider, muffinTranslations } from "./i18n";
22
+ import { muffinDarkTheme, muffinLightTheme } from "./themes";
11
23
  import { buildAdmin, deepMerge, findBuilder, findIcon, setupAdmin } from "./utils";
12
- export function MuffinAdmin(props) {
24
+ export function MuffinAdmin(_a) {
25
+ var { lightTheme = muffinLightTheme, darkTheme = muffinDarkTheme } = _a, props = __rest(_a, ["lightTheme", "darkTheme"]);
13
26
  const opts = useMuffinAdminOpts();
14
27
  const { resources = [], auth, adminProps, apiUrl, locales: backendLocales } = opts;
15
28
  document.title = (adminProps === null || adminProps === void 0 ? void 0 : adminProps.title) || "Muffin Admin";
@@ -19,7 +32,7 @@ export function MuffinAdmin(props) {
19
32
  deepMerge({}, messages, backendLocales[locale], buildAdmin(["locale", locale]) || {}),
20
33
  ]))
21
34
  : muffinTranslations);
22
- const { basename, authProvider = findBuilder(["auth-provider"])(auth), dataProvider = findBuilder(["data-provider"])(apiUrl), catchAll, dashboard = findBuilder(["dashboard"]), disableTelemetry, error, i18nProvider = muffinI18nProvider, layout = findBuilder(["layout"]), loading, loginPage = findBuilder(["loginpage"]), authCallbackPage, notification, queryClient, requireAuth = auth.required, store = localStorageStore(), ready, theme, lightTheme, darkTheme, defaultTheme, title = "React Admin", } = props;
35
+ const { basename, authProvider = findBuilder(["auth-provider"])(auth), dataProvider = findBuilder(["data-provider"])(apiUrl), catchAll, dashboard = findBuilder(["dashboard"]), disableTelemetry, error, i18nProvider = muffinI18nProvider, layout = findBuilder(["layout"]), loading, loginPage = findBuilder(["loginpage"]), authCallbackPage, notification, queryClient, requireAuth = auth.required, store = localStorageStore(), ready, theme, defaultTheme, title = "React Admin", } = props;
23
36
  return (_jsx(AdminContext, { authProvider: authProvider, basename: basename, dataProvider: dataProvider, i18nProvider: i18nProvider, store: store, queryClient: queryClient, theme: theme, lightTheme: lightTheme, darkTheme: darkTheme, defaultTheme: defaultTheme, children: _jsx(ConfirmationProvider, { children: _jsx(AdminUI, { layout: layout, dashboard: dashboard, disableTelemetry: disableTelemetry, catchAll: catchAll, error: error, title: title, loading: loading, loginPage: loginPage, authCallbackPage: authCallbackPage, notification: notification, requireAuth: requireAuth, ready: ready, children: resources === null || resources === void 0 ? void 0 : resources.map(({ name }) => buildAdmin(["resource", name], { name })) }) }) }));
24
37
  }
25
38
  setupAdmin(["admin"], MuffinAdmin);
@@ -5,7 +5,8 @@ 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 { Menu, useTranslate } from "react-admin";
8
+ import { matchPath, useLocation } from "react-router-dom";
9
+ import { Menu, useBasename, useTranslate } from "react-admin";
9
10
  import find from "lodash/find";
10
11
  import groupBy from "lodash/groupBy";
11
12
  import { useContext, useState } from "react";
@@ -30,6 +31,11 @@ function MenuGroup({ name, resources }) {
30
31
  const iconRes = find(resources, "icon");
31
32
  const Icon = iconRes ? findIcon(iconRes.icon) : null;
32
33
  const translate = useTranslate();
33
- const [groupOpen, setGroupOpen] = useState(false);
34
+ const basename = useBasename();
35
+ const { pathname } = useLocation();
36
+ const match = resources.some((resource) => !!matchPath({
37
+ path: `${basename}/${resource.name}/*`,
38
+ }, pathname));
39
+ const [groupOpen, setGroupOpen] = useState(match);
34
40
  return (_jsxs("div", { children: [_jsxs(ListItemButton, { onClick: () => setGroupOpen(!groupOpen), children: [Icon && (_jsx(ListItemIcon, { sx: { minWidth: 40 }, children: _jsx(Icon, {}) })), _jsx(ListItemText, { primary: translate(`groups.${name}`) }), groupOpen ? _jsx(ExpandLess, {}) : _jsx(ExpandMore, {})] }), _jsx(Collapse, { in: groupOpen, timeout: "auto", unmountOnExit: true, children: resources.map(({ name }) => (_jsx(Menu.ResourceItem, { name: name }, name))) })] }));
35
41
  }
package/dist/index.d.ts CHANGED
@@ -19,4 +19,4 @@ export * from "./fields";
19
19
  export * from "./hooks";
20
20
  export * from "./types";
21
21
  export declare function initAdmin(prefix?: string, containerId?: string): Promise<void>;
22
- export declare const VERSION = "9.4.3";
22
+ export declare const VERSION = "9.5.0";
package/dist/index.js CHANGED
@@ -42,4 +42,4 @@ export function initAdmin() {
42
42
  root.render(_jsx(MuffinAdminContext.Provider, { value: adminOpts, children: _jsx(MuffinAdmin, {}) }));
43
43
  });
44
44
  }
45
- export const VERSION = "9.4.3";
45
+ export const VERSION = "9.5.0";
@@ -0,0 +1,3 @@
1
+ import { defaultDarkTheme, defaultLightTheme } from "react-admin";
2
+ export declare const muffinLightTheme: typeof defaultLightTheme;
3
+ export declare const muffinDarkTheme: typeof defaultDarkTheme;
package/dist/themes.js ADDED
@@ -0,0 +1,21 @@
1
+ import { defaultDarkTheme, defaultLightTheme } from "react-admin";
2
+ export const muffinLightTheme = Object.assign(Object.assign({}, defaultLightTheme), { components: Object.assign(Object.assign({}, defaultLightTheme.components), { RaMenuItemLink: {
3
+ styleOverrides: {
4
+ root: {
5
+ "&.RaMenuItemLink-active": {
6
+ backgroundColor: "#f0f0f0",
7
+ borderRadius: "4px",
8
+ },
9
+ },
10
+ },
11
+ } }) });
12
+ export const muffinDarkTheme = Object.assign(Object.assign({}, defaultDarkTheme), { components: Object.assign(Object.assign({}, defaultDarkTheme.components), { RaMenuItemLink: {
13
+ styleOverrides: {
14
+ root: {
15
+ "&.RaMenuItemLink-active": {
16
+ backgroundColor: "#424242",
17
+ borderRadius: "4px",
18
+ },
19
+ },
20
+ },
21
+ } }) });