@tker-react/layout 0.2.7 → 0.2.9

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 CHANGED
@@ -55,7 +55,6 @@ interface TabAdapterProps {
55
55
  onClose: (path: string) => void;
56
56
  onCloseOther: (path?: string) => void;
57
57
  onCloseAll: () => void;
58
- onRefresh: () => void;
59
58
  onSetFixed: (path: string, fixed: boolean) => void;
60
59
  }
61
60
  interface UserAvatarAdapterProps {
package/dist/index.d.ts CHANGED
@@ -55,7 +55,6 @@ interface TabAdapterProps {
55
55
  onClose: (path: string) => void;
56
56
  onCloseOther: (path?: string) => void;
57
57
  onCloseAll: () => void;
58
- onRefresh: () => void;
59
58
  onSetFixed: (path: string, fixed: boolean) => void;
60
59
  }
61
60
  interface UserAvatarAdapterProps {
package/dist/index.mjs CHANGED
@@ -52,6 +52,14 @@ function useLayoutInteractionContext() {
52
52
  }
53
53
  return ctx;
54
54
  }
55
+ const LayoutOpenKeysContext = createContext(null);
56
+ function useLayoutOpenKeysContext() {
57
+ const ctx = useContext(LayoutOpenKeysContext);
58
+ if (!ctx) {
59
+ throw new Error("useLayoutOpenKeysContext \u5FC5\u987B\u5728 <Layout> \u5185\u90E8\u4F7F\u7528");
60
+ }
61
+ return ctx;
62
+ }
55
63
  function useLayoutContext() {
56
64
  const ctx = useContext(LayoutContext);
57
65
  if (!ctx) {
@@ -209,11 +217,13 @@ function LayoutProvider({ children }) {
209
217
  collapsed,
210
218
  toggleCollapse,
211
219
  setCollapsed,
212
- openKeys,
213
- toggleMenuOpen,
214
220
  menuItemClick
215
221
  }),
216
- [collapsed, toggleCollapse, setCollapsed, openKeys, toggleMenuOpen, menuItemClick]
222
+ [collapsed, toggleCollapse, setCollapsed, menuItemClick]
223
+ );
224
+ const openKeysValue = useMemo(
225
+ () => ({ openKeys, toggleMenuOpen }),
226
+ [openKeys, toggleMenuOpen]
217
227
  );
218
228
  const value = useMemo(
219
229
  () => ({
@@ -268,7 +278,7 @@ function LayoutProvider({ children }) {
268
278
  setMaxTabs
269
279
  ]
270
280
  );
271
- return /* @__PURE__ */ jsx(LayoutContext.Provider, { value, children: /* @__PURE__ */ jsx(LayoutInteractionContext.Provider, { value: interactionValue, children }) });
281
+ return /* @__PURE__ */ jsx(LayoutContext.Provider, { value, children: /* @__PURE__ */ jsx(LayoutInteractionContext.Provider, { value: interactionValue, children: /* @__PURE__ */ jsx(LayoutOpenKeysContext.Provider, { value: openKeysValue, children }) }) });
272
282
  }
273
283
 
274
284
  function LayoutAside() {
@@ -282,7 +292,8 @@ function LayoutAside() {
282
292
  getFullPath,
283
293
  navigate
284
294
  } = useLayoutContext();
285
- const { collapsed, toggleCollapse, openKeys, menuItemClick } = useLayoutInteractionContext();
295
+ const { collapsed, toggleCollapse, menuItemClick } = useLayoutInteractionContext();
296
+ const { openKeys } = useLayoutOpenKeysContext();
286
297
  const menuMode = layoutMode === "top-menu" ? "top" : "side";
287
298
  const handleMenuSelect = useCallback(
288
299
  (path) => {
@@ -346,7 +357,6 @@ function LayoutContent({ children }) {
346
357
  const isTopMenu = layoutMode === "top-menu";
347
358
  const [tabData, setTabData] = useState([]);
348
359
  const [activeTab, setActiveTab] = useState("");
349
- const [refreshKey, setRefreshKey] = useState(0);
350
360
  const menuDataRef = useRef(menuData);
351
361
  menuDataRef.current = menuData;
352
362
  const activeTabRef = useRef(activeTab);
@@ -430,9 +440,6 @@ function LayoutContent({ children }) {
430
440
  (prev) => prev.map((t) => t.path === path ? { ...t, fixed } : t)
431
441
  );
432
442
  }, []);
433
- const handleRefresh = useCallback(() => {
434
- setRefreshKey((k) => k + 1);
435
- }, []);
436
443
  const TabAdapter = adapters.tab;
437
444
  return /* @__PURE__ */ jsxs("main", { className: "tker-layout-content", children: [
438
445
  !isTopMenu && TabAdapter && /* @__PURE__ */ jsx(
@@ -444,11 +451,10 @@ function LayoutContent({ children }) {
444
451
  onClose: handleTabClose,
445
452
  onCloseOther: handleCloseOtherTabs,
446
453
  onCloseAll: handleCloseAllTabs,
447
- onRefresh: handleRefresh,
448
454
  onSetFixed: handleSetFixed
449
455
  }
450
456
  ),
451
- /* @__PURE__ */ jsx("div", { className: "tker-layout-content__body", children }, refreshKey)
457
+ /* @__PURE__ */ jsx("div", { className: "tker-layout-content__body", children })
452
458
  ] });
453
459
  }
454
460
  function openTabInData(tabData, path, config) {
@@ -530,6 +536,7 @@ function LayoutHeader() {
530
536
  },
531
537
  [getFullPath, navigate, isConcretePage]
532
538
  );
539
+ const emptyOpenKeysRef = useRef(/* @__PURE__ */ new Set());
533
540
  const leftContent = isTopMenu ? ["logo", "menu"] : ["logo", "breadcrumb"];
534
541
  const logoWidth = isSideMenu ? collapsed ? collapsedWidth : expandedWidth : expandedWidth;
535
542
  const LogoAdapter = adapters.logo;
@@ -555,7 +562,7 @@ function LayoutHeader() {
555
562
  collapsed: false,
556
563
  mode: "top",
557
564
  width: logoWidth,
558
- openKeys: /* @__PURE__ */ new Set(),
565
+ openKeys: emptyOpenKeysRef.current,
559
566
  onSelect: handleMenuSelect,
560
567
  onMenuItemClick: menuItemClick
561
568
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tker-react/layout",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",