@tker-react/layout 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +24 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -87,6 +87,7 @@ interface LayoutContextValue {
|
|
|
87
87
|
setCollapsed: (collapsed: boolean) => void;
|
|
88
88
|
openKeys: Set<string>;
|
|
89
89
|
toggleMenuOpen: (path: string, forceOpen?: boolean) => void;
|
|
90
|
+
menuItemClick: (path: string) => void;
|
|
90
91
|
setExpandedWidth: (width: string) => void;
|
|
91
92
|
setCollapsedWidth: (width: string) => void;
|
|
92
93
|
setLayoutMode: (mode: "side-menu" | "top-menu") => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -87,6 +87,7 @@ interface LayoutContextValue {
|
|
|
87
87
|
setCollapsed: (collapsed: boolean) => void;
|
|
88
88
|
openKeys: Set<string>;
|
|
89
89
|
toggleMenuOpen: (path: string, forceOpen?: boolean) => void;
|
|
90
|
+
menuItemClick: (path: string) => void;
|
|
90
91
|
setExpandedWidth: (width: string) => void;
|
|
91
92
|
setCollapsedWidth: (width: string) => void;
|
|
92
93
|
setLayoutMode: (mode: "side-menu" | "top-menu") => void;
|
package/dist/index.mjs
CHANGED
|
@@ -105,6 +105,8 @@ function LayoutProvider({ children }) {
|
|
|
105
105
|
openKeysRef.current = openKeys;
|
|
106
106
|
const collapsedRef = useRef(collapsed);
|
|
107
107
|
collapsedRef.current = collapsed;
|
|
108
|
+
const menuDataRef = useRef(menuData);
|
|
109
|
+
menuDataRef.current = menuData;
|
|
108
110
|
const toggleMenuOpen = useCallback((path, forceOpen) => {
|
|
109
111
|
setOpenKeys((prev) => {
|
|
110
112
|
const next = new Set(prev);
|
|
@@ -120,6 +122,25 @@ function LayoutProvider({ children }) {
|
|
|
120
122
|
return next;
|
|
121
123
|
});
|
|
122
124
|
}, []);
|
|
125
|
+
const menuItemClick = useCallback((path) => {
|
|
126
|
+
const item = findMenuItemByPath(menuDataRef.current, path);
|
|
127
|
+
const hasChildren = !!(item?.children && item.children.length > 0);
|
|
128
|
+
if (hasChildren) {
|
|
129
|
+
if (collapsedRef.current) {
|
|
130
|
+
setCollapsedState(false);
|
|
131
|
+
const restored = new Set(savedOpenKeysRef.current);
|
|
132
|
+
restored.add(path);
|
|
133
|
+
setOpenKeys(restored);
|
|
134
|
+
} else {
|
|
135
|
+
toggleMenuOpen(path);
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
const fullPath = pathParamsMap.current.get(path) || path;
|
|
139
|
+
if (window.location.pathname + window.location.search !== fullPath) {
|
|
140
|
+
navigateRef.current?.(fullPath);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}, []);
|
|
123
144
|
const toggleCollapse = useCallback(() => {
|
|
124
145
|
const nextCollapsed = !collapsedRef.current;
|
|
125
146
|
if (nextCollapsed) {
|
|
@@ -180,6 +201,7 @@ function LayoutProvider({ children }) {
|
|
|
180
201
|
setMenus,
|
|
181
202
|
setActivePath,
|
|
182
203
|
toggleCollapse,
|
|
204
|
+
// setCollapsed 同样处理 openKeys 保存/恢复,与 toggleCollapse 逻辑一致
|
|
183
205
|
setCollapsed: (val) => {
|
|
184
206
|
if (val) {
|
|
185
207
|
savedOpenKeysRef.current = new Set(openKeysRef.current);
|
|
@@ -191,6 +213,7 @@ function LayoutProvider({ children }) {
|
|
|
191
213
|
},
|
|
192
214
|
openKeys,
|
|
193
215
|
toggleMenuOpen,
|
|
216
|
+
menuItemClick,
|
|
194
217
|
setExpandedWidth,
|
|
195
218
|
setCollapsedWidth,
|
|
196
219
|
setLayoutMode,
|
|
@@ -222,6 +245,7 @@ function LayoutProvider({ children }) {
|
|
|
222
245
|
toggleCollapse,
|
|
223
246
|
openKeys,
|
|
224
247
|
toggleMenuOpen,
|
|
248
|
+
menuItemClick,
|
|
225
249
|
isConcretePage,
|
|
226
250
|
getFullPath,
|
|
227
251
|
setNavigateAdapter,
|