@rnaga/wp-next-admin 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/components/layout/header/index.d.ts.map +1 -1
- package/client/components/layout/header/index.js +25 -2
- package/client/hooks/use-admin-navigation.d.ts.map +1 -1
- package/client/hooks/use-admin-navigation.js +1 -0
- package/client/utils/get-default-admin-hooks.d.ts.map +1 -1
- package/client/utils/get-default-admin-hooks.js +1 -0
- package/client/wp-hooks/index.d.ts.map +1 -1
- package/client/wp-hooks/index.js +1 -0
- package/package.json +1 -1
- package/types/client/menus.d.ts +7 -1
- package/types/hooks/filters.d.ts +16 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/client/components/layout/header/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/client/components/layout/header/index.tsx"],"names":[],"mappings":"AA6LA,eAAO,MAAM,MAAM,+CA2NlB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useMemo, useRef, useState } from "react";
|
|
3
|
+
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import BookIcon from "@mui/icons-material/Book";
|
|
5
5
|
import HomeIcon from "@mui/icons-material/Home";
|
|
6
6
|
import HomeWorkIcon from "@mui/icons-material/HomeWork";
|
|
@@ -9,6 +9,7 @@ import PersonIcon from "@mui/icons-material/Person";
|
|
|
9
9
|
import ViewSidebarIcon from "@mui/icons-material/ViewSidebar";
|
|
10
10
|
import WebIcon from "@mui/icons-material/Web";
|
|
11
11
|
import { Box, IconButton, MenuItem, MenuList } from "@mui/material";
|
|
12
|
+
import { useWP } from "@rnaga/wp-next-core/client/wp";
|
|
12
13
|
import { PopperMenu } from "@rnaga/wp-next-ui/PopperMenu";
|
|
13
14
|
import { useWPTheme } from "@rnaga/wp-next-ui/ThemeRegistry";
|
|
14
15
|
import { Typography } from "@rnaga/wp-next-ui/Typography";
|
|
@@ -97,13 +98,35 @@ export const Header = () => {
|
|
|
97
98
|
const { wp: { viewport }, site: currentSite, sidebar, } = useWPAdmin();
|
|
98
99
|
const { user } = useAdminUser();
|
|
99
100
|
const { wpRawTheme } = useWPTheme();
|
|
101
|
+
const wpAdmin = useWPAdmin();
|
|
102
|
+
const adminNavigation = useAdminNavigation();
|
|
103
|
+
const { wpHooks } = useWP();
|
|
100
104
|
const homeButtonRef = useRef(null);
|
|
101
105
|
const [openHomeMenu, setOpenHomeMenu] = useState(false);
|
|
102
106
|
const manageSiteButtonRef = useRef(null);
|
|
103
107
|
const [openManageSiteMenu, setOpenManageSiteMenu] = useState(false);
|
|
108
|
+
const [customMenuComponents, setCustomMenuComponents] = useState([]);
|
|
104
109
|
const profileKey = useMemo(() => {
|
|
105
110
|
return `profile-${currentSite.settings.timezone}-${user?.ID}`;
|
|
106
111
|
}, [currentSite.settings.timezone, user]);
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
const newCustomMenus = wpHooks.filter.apply("next_admin_bar_menu", [], {
|
|
114
|
+
wpAdmin,
|
|
115
|
+
navigation: adminNavigation,
|
|
116
|
+
wpRawTheme,
|
|
117
|
+
});
|
|
118
|
+
const newCustomMenuComponents = [];
|
|
119
|
+
for (const menu of newCustomMenus) {
|
|
120
|
+
// Check if the menu has role restriction.
|
|
121
|
+
// If not, show the menu. If yes, check if the user has the capability.
|
|
122
|
+
if (!menu.roles ||
|
|
123
|
+
menu.roles.length === 0 ||
|
|
124
|
+
menu.roles.some((role) => user?.role.names.has(role))) {
|
|
125
|
+
newCustomMenuComponents.push(_jsx(React.Fragment, { children: menu.component }, newCustomMenuComponents.length));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
setCustomMenuComponents(newCustomMenuComponents);
|
|
129
|
+
}, [wpAdmin.site.blogId, user?.ID]);
|
|
107
130
|
return (_jsxs(Box
|
|
108
131
|
//variant="solid"
|
|
109
132
|
, {
|
|
@@ -172,5 +195,5 @@ export const Header = () => {
|
|
|
172
195
|
}, anchorOrigin: {
|
|
173
196
|
vertical: "bottom",
|
|
174
197
|
horizontal: "center",
|
|
175
|
-
}, children: _jsx(MenuList, { children: _jsx(ManageSiteMenuItems, {}) }) })] }))] }), _jsx(Profile, {}, profileKey)] }));
|
|
198
|
+
}, children: _jsx(MenuList, { children: _jsx(ManageSiteMenuItems, {}) }) })] })), customMenuComponents.length > 0 && _jsx(Box, { children: customMenuComponents })] }), _jsx(Profile, {}, profileKey)] }));
|
|
176
199
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-admin-navigation.d.ts","sourceRoot":"","sources":["../../../src/client/hooks/use-admin-navigation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-admin-navigation.d.ts","sourceRoot":"","sources":["../../../src/client/hooks/use-admin-navigation.ts"],"names":[],"mappings":"AAEA,OAAO,WAAW,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAIhG,OAAO,KAAK,KAAK,MAAM,aAAa,CAAC;AAGrC,OAAO,KAAK,KAAK,WAAW,MAAM,2BAA2B,CAAC;AAM9D,eAAO,MAAM,kBAAkB,GAAI,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;;;;;2BAkDlD,KAAK,CAAC,MAAM,CAAC,gBAAgB,YAC5B,OAAO,CAAC;QAChB,QAAQ,EAAE,OAAO,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,WAAW,CAAC,mBAAmB,CAAC;KAC/C,CAAC,KACD,MAAM;qBAWD,MAAM,YACF,OAAO,CAAC;QAChB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAAC;QACvC,WAAW,CAAC,EAAE,WAAW,CAAC,mBAAmB,CAAC;KAC/C,CAAC;;;;;;;;;;;qBA/CK,CAAC,MAAM,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,EAAE;;;;;;;CAgFjE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-default-admin-hooks.d.ts","sourceRoot":"","sources":["../../../src/client/utils/get-default-admin-hooks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-default-admin-hooks.d.ts","sourceRoot":"","sources":["../../../src/client/utils/get-default-admin-hooks.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,6LAAc,CAAC;AAChD,eAAe,oBAAoB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/wp-hooks/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/wp-hooks/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,eAAO,MAAM,KAAK,uEAA6D,CAAC"}
|
package/client/wp-hooks/index.js
CHANGED
package/package.json
CHANGED
package/types/client/menus.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface AdminPageSegmentMap {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
type AdminPageSegment<
|
|
8
|
-
K extends keyof AdminPageSegmentMap = keyof AdminPageSegmentMap
|
|
8
|
+
K extends keyof AdminPageSegmentMap = keyof AdminPageSegmentMap,
|
|
9
9
|
> = AdminPageSegmentMap[K] extends true ? keyof AdminPageSegmentMap : never;
|
|
10
10
|
|
|
11
11
|
export type AdminMenu = AdminMenuComponent | AdminOnclick;
|
|
@@ -37,3 +37,9 @@ export interface AdminOnclick {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export type AdminMenus = Map<keyof AdminPageSegment, AdminMenu[]>;
|
|
40
|
+
|
|
41
|
+
export type AdminBarMenus = Array<{
|
|
42
|
+
component: React.ReactNode;
|
|
43
|
+
roles?: string[];
|
|
44
|
+
onClick?: () => void;
|
|
45
|
+
}>;
|
package/types/hooks/filters.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
AdminBarMenus,
|
|
3
|
+
AdminMenu,
|
|
4
|
+
AdminPageSegment,
|
|
5
|
+
} from "../client/menus";
|
|
2
6
|
import type { WPAdmin } from "../client";
|
|
3
7
|
|
|
4
8
|
import { experimental_extendTheme as materialExtendTheme } from "@mui/material/styles";
|
|
5
9
|
import { Context } from "@rnaga/wp-node/core/context";
|
|
6
10
|
|
|
7
11
|
import { useAdminNavigation } from "../../client/hooks/use-admin-navigation";
|
|
8
|
-
|
|
12
|
+
|
|
13
|
+
import type { WPTheme } from "@rnaga/wp-next-ui/types";
|
|
9
14
|
|
|
10
15
|
export {};
|
|
11
16
|
|
|
@@ -28,6 +33,15 @@ declare module "@rnaga/wp-next-core/types/hooks/filters.d" {
|
|
|
28
33
|
}
|
|
29
34
|
) => AdminMenu[];
|
|
30
35
|
|
|
36
|
+
next_admin_bar_menu: (
|
|
37
|
+
menus: AdminBarMenus,
|
|
38
|
+
params: {
|
|
39
|
+
wpAdmin: WPAdmin;
|
|
40
|
+
navigation: AdminNavigation;
|
|
41
|
+
wpRawTheme: WPTheme;
|
|
42
|
+
}
|
|
43
|
+
) => AdminBarMenus;
|
|
44
|
+
|
|
31
45
|
next_admin_preload_modal: (
|
|
32
46
|
components: React.ReactNode[],
|
|
33
47
|
params: {
|