@tker-react/layout 0.2.11 → 0.2.12
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.mjs +33 -27
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./layout.css";
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
import { useRef, useCallback, useMemo, useState, useEffect, createContext, useContext } from 'react';
|
|
3
|
+
import { useRef, useCallback, useMemo, useState, useEffect, createContext, useContext, memo } from 'react';
|
|
4
4
|
|
|
5
5
|
function findMenuItemByPath(menuData, path) {
|
|
6
6
|
for (const item of menuData) {
|
|
@@ -131,6 +131,10 @@ function useLayoutContext() {
|
|
|
131
131
|
if (!ctx) throw new Error("useLayoutContext \u5FC5\u987B\u5728 <Layout> \u5185\u90E8\u4F7F\u7528");
|
|
132
132
|
return ctx;
|
|
133
133
|
}
|
|
134
|
+
const ActivePathContext = createContext("");
|
|
135
|
+
function useActivePathContext() {
|
|
136
|
+
return useContext(ActivePathContext);
|
|
137
|
+
}
|
|
134
138
|
function LayoutProvider({
|
|
135
139
|
children,
|
|
136
140
|
activePath = "",
|
|
@@ -258,7 +262,6 @@ function LayoutProvider({
|
|
|
258
262
|
() => ({
|
|
259
263
|
adapters,
|
|
260
264
|
menuData: config.menus,
|
|
261
|
-
activePath,
|
|
262
265
|
expandedWidth: config.expandedWidth,
|
|
263
266
|
collapsedWidth: config.collapsedWidth,
|
|
264
267
|
layoutMode: config.layoutMode,
|
|
@@ -271,7 +274,6 @@ function LayoutProvider({
|
|
|
271
274
|
[
|
|
272
275
|
adapters,
|
|
273
276
|
config.menus,
|
|
274
|
-
activePath,
|
|
275
277
|
config.expandedWidth,
|
|
276
278
|
config.collapsedWidth,
|
|
277
279
|
config.layoutMode,
|
|
@@ -282,7 +284,7 @@ function LayoutProvider({
|
|
|
282
284
|
navigate
|
|
283
285
|
]
|
|
284
286
|
);
|
|
285
|
-
return /* @__PURE__ */ jsx(LayoutContext.Provider, { value, children: /* @__PURE__ */ jsx(LayoutInteractionContext.Provider, { value: interactionValue, children: /* @__PURE__ */ jsx(LayoutOpenKeysContext.Provider, { value: openKeysValue, children }) }) });
|
|
287
|
+
return /* @__PURE__ */ jsx(LayoutContext.Provider, { value, children: /* @__PURE__ */ jsx(LayoutInteractionContext.Provider, { value: interactionValue, children: /* @__PURE__ */ jsx(LayoutOpenKeysContext.Provider, { value: openKeysValue, children: /* @__PURE__ */ jsx(ActivePathContext.Provider, { value: activePath, children }) }) }) });
|
|
286
288
|
}
|
|
287
289
|
|
|
288
290
|
function LayoutAside() {
|
|
@@ -291,11 +293,11 @@ function LayoutAside() {
|
|
|
291
293
|
expandedWidth,
|
|
292
294
|
collapsedWidth,
|
|
293
295
|
menuData,
|
|
294
|
-
activePath,
|
|
295
296
|
layoutMode,
|
|
296
297
|
getFullPath,
|
|
297
298
|
navigate
|
|
298
299
|
} = useLayoutContext();
|
|
300
|
+
const activePath = useActivePathContext();
|
|
299
301
|
const { collapsed, toggleCollapse, menuItemClick } = useLayoutInteractionContext();
|
|
300
302
|
const { openKeys } = useLayoutOpenKeysContext();
|
|
301
303
|
const menuMode = layoutMode === "top-menu" ? "top" : "side";
|
|
@@ -347,18 +349,24 @@ function LayoutAside() {
|
|
|
347
349
|
] });
|
|
348
350
|
}
|
|
349
351
|
|
|
350
|
-
|
|
352
|
+
const LayoutContent = memo(function LayoutContent2({ children }) {
|
|
353
|
+
const { layoutMode } = useLayoutContext();
|
|
354
|
+
const isTopMenu = layoutMode === "top-menu";
|
|
355
|
+
return /* @__PURE__ */ jsxs("main", { className: "tker-layout-content", children: [
|
|
356
|
+
/* @__PURE__ */ jsx(LayoutTabs, { isTopMenu }),
|
|
357
|
+
/* @__PURE__ */ jsx("div", { className: "tker-layout-content__body", children })
|
|
358
|
+
] });
|
|
359
|
+
});
|
|
360
|
+
function LayoutTabs({ isTopMenu }) {
|
|
351
361
|
const {
|
|
352
362
|
adapters,
|
|
353
363
|
menuData,
|
|
354
|
-
activePath,
|
|
355
|
-
layoutMode,
|
|
356
364
|
homePath,
|
|
357
365
|
maxTabs,
|
|
358
366
|
getFullPath,
|
|
359
367
|
navigate
|
|
360
368
|
} = useLayoutContext();
|
|
361
|
-
const
|
|
369
|
+
const activePath = useActivePathContext();
|
|
362
370
|
const menuDataRef = useRef(menuData);
|
|
363
371
|
menuDataRef.current = menuData;
|
|
364
372
|
const initialTab = activePath && activePath !== "/" ? openTabInData([], activePath, { homePath, maxTabs, menuData }) : [];
|
|
@@ -451,21 +459,19 @@ function LayoutContent({ children }) {
|
|
|
451
459
|
);
|
|
452
460
|
}, []);
|
|
453
461
|
const TabAdapter = adapters.tab;
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
/* @__PURE__ */ jsx("div", { className: "tker-layout-content__body", children })
|
|
468
|
-
] });
|
|
462
|
+
if (isTopMenu || !TabAdapter) return null;
|
|
463
|
+
return /* @__PURE__ */ jsx(
|
|
464
|
+
TabAdapter,
|
|
465
|
+
{
|
|
466
|
+
tabData,
|
|
467
|
+
activeTab,
|
|
468
|
+
onSelect: handleTabSelect,
|
|
469
|
+
onClose: handleTabClose,
|
|
470
|
+
onCloseOther: handleCloseOtherTabs,
|
|
471
|
+
onCloseAll: handleCloseAllTabs,
|
|
472
|
+
onSetFixed: handleSetFixed
|
|
473
|
+
}
|
|
474
|
+
);
|
|
469
475
|
}
|
|
470
476
|
function openTabInData(tabData, path, config) {
|
|
471
477
|
const { homePath, maxTabs, menuData } = config;
|
|
@@ -516,12 +522,12 @@ function LayoutHeader() {
|
|
|
516
522
|
expandedWidth,
|
|
517
523
|
collapsedWidth,
|
|
518
524
|
menuData,
|
|
519
|
-
activePath,
|
|
520
525
|
layoutMode,
|
|
521
526
|
getFullPath,
|
|
522
527
|
isConcretePage,
|
|
523
528
|
navigate
|
|
524
529
|
} = useLayoutContext();
|
|
530
|
+
const activePath = useActivePathContext();
|
|
525
531
|
const { collapsed, menuItemClick } = useLayoutInteractionContext();
|
|
526
532
|
const isTopMenu = layoutMode === "top-menu";
|
|
527
533
|
const isSideMenu = layoutMode === "side-menu";
|
|
@@ -592,7 +598,7 @@ function LayoutHeader() {
|
|
|
592
598
|
] });
|
|
593
599
|
}
|
|
594
600
|
|
|
595
|
-
|
|
601
|
+
const LayoutInner = memo(function LayoutInner2({ children }) {
|
|
596
602
|
const { layoutMode } = useLayoutContext();
|
|
597
603
|
const isSideMenu = layoutMode === "side-menu";
|
|
598
604
|
return /* @__PURE__ */ jsxs("div", { className: "tker-layout", children: [
|
|
@@ -602,7 +608,7 @@ function LayoutInner({ children }) {
|
|
|
602
608
|
/* @__PURE__ */ jsx(LayoutContent, { children })
|
|
603
609
|
] })
|
|
604
610
|
] });
|
|
605
|
-
}
|
|
611
|
+
});
|
|
606
612
|
function Layout({ children, ...props }) {
|
|
607
613
|
return /* @__PURE__ */ jsx(LayoutProvider, { ...props, children: /* @__PURE__ */ jsx(LayoutInner, { children }) });
|
|
608
614
|
}
|