@donglegeyu/company-ui 2.10.0 → 2.11.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.
@@ -22,6 +22,7 @@ __export(FirstSidebar_exports, {
22
22
  default: () => FirstSidebar
23
23
  });
24
24
  module.exports = __toCommonJS(FirstSidebar_exports);
25
+ var import_react = require("react");
25
26
  var import_basic_components = require("../../basic-components");
26
27
  var import_shared_components = require("../../shared-components");
27
28
  var import_index = require("./index.scss");
@@ -60,7 +61,17 @@ function FirstSidebar({
60
61
  return businessMenus.slice(0, visibleMenuCount);
61
62
  })();
62
63
  const currentDomain = domains.find((d) => d.id === currentDomainId);
63
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "company-sidebar-first", children: [
64
+ const rootRef = (0, import_react.useRef)(null);
65
+ (0, import_react.useEffect)(() => {
66
+ const root = rootRef.current;
67
+ if (!root)
68
+ return;
69
+ root.querySelectorAll(".menu-item.active, .business-menu-item.active").forEach((el) => {
70
+ var _a;
71
+ return (_a = el.scrollIntoView) == null ? void 0 : _a.call(el, { block: "nearest" });
72
+ });
73
+ }, [activeFirstMenu, activeKey]);
74
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "company-sidebar-first", ref: rootRef, children: [
64
75
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "brand-area", children: [
65
76
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
66
77
  import_basic_components.CompanyPopover,
@@ -22,6 +22,7 @@ __export(SecondSidebar_exports, {
22
22
  default: () => SecondSidebar
23
23
  });
24
24
  module.exports = __toCommonJS(SecondSidebar_exports);
25
+ var import_react = require("react");
25
26
  var import_shared_components = require("../../shared-components");
26
27
  var import_index = require("./index.scss");
27
28
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -46,6 +47,13 @@ function SecondSidebar({
46
47
  }) {
47
48
  const showSecondSidebar = activeFirstMenu && activeFirstMenu !== "home" ? secondSidebarHovered || secondSidebarFixed : false;
48
49
  const isFavorites = activeFirstMenu === "favorites";
50
+ const menuListRef = (0, import_react.useRef)(null);
51
+ (0, import_react.useEffect)(() => {
52
+ var _a, _b, _c;
53
+ if (!showSecondSidebar)
54
+ return;
55
+ (_c = (_b = (_a = menuListRef.current) == null ? void 0 : _a.querySelector(".menu-item.active")) == null ? void 0 : _b.scrollIntoView) == null ? void 0 : _c.call(_b, { block: "nearest" });
56
+ }, [showSecondSidebar, activeKey, expandedKeys, isFavorites, secondMenus]);
49
57
  const favoriteItems = (favorites || []).map((item) => ({
50
58
  key: item.menuKey,
51
59
  label: item.menuLabel || "未命名",
@@ -208,7 +216,7 @@ function SecondSidebar({
208
216
  onMouseEnter,
209
217
  onMouseLeave,
210
218
  children: [
211
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "menu-list", children: isFavorites ? renderFavorites() : renderMenus() }),
219
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "menu-list", ref: menuListRef, children: isFavorites ? renderFavorites() : renderMenus() }),
212
220
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "collapse-container", children: [
213
221
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "collapse-divider" }),
214
222
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "collapse-btn", onClick: onToggleFixed, children: [
@@ -102,7 +102,6 @@ function CompanySidebar({
102
102
  hoverKey: null,
103
103
  moreDrawerOpen: false,
104
104
  customNavVisible: false,
105
- localExpandedKeys: expandedKeys,
106
105
  localFavorites: favorites,
107
106
  hasError: false
108
107
  });
@@ -128,9 +127,6 @@ function CompanySidebar({
128
127
  },
129
128
  [leafToFirstKeyMap, activeFirstMenu, onFirstMenuSelect, onMenuClick]
130
129
  );
131
- (0, import_react.useEffect)(() => {
132
- setState((prev) => ({ ...prev, localExpandedKeys: expandedKeys }));
133
- }, [expandedKeys]);
134
130
  (0, import_react.useEffect)(() => {
135
131
  setState((prev) => ({ ...prev, localFavorites: favorites }));
136
132
  }, [favorites]);
@@ -283,7 +279,7 @@ function CompanySidebar({
283
279
  secondSidebarFixed,
284
280
  secondMenus: displaySecondMenus,
285
281
  favorites: state.localFavorites,
286
- expandedKeys: state.localExpandedKeys,
282
+ expandedKeys,
287
283
  emptyImage,
288
284
  onMenuClick: (menu) => {
289
285
  handleLeafMenuClick(menu);
@@ -1,3 +1,4 @@
1
+ import { useEffect, useRef } from "react";
1
2
  import { CompanyPopover } from "../../basic-components";
2
3
  import { SvgIcon } from "../../shared-components";
3
4
  import "./index.scss";
@@ -40,8 +41,22 @@ export default function FirstSidebar(_ref) {
40
41
  var currentDomain = domains.find(function (d) {
41
42
  return d.id === currentDomainId;
42
43
  });
44
+
45
+ // active 项滚动定位:挂载与选中变化后把高亮项滚入可视区(block:"nearest",已在可视区则不动)
46
+ var rootRef = useRef(null);
47
+ useEffect(function () {
48
+ var root = rootRef.current;
49
+ if (!root) return;
50
+ root.querySelectorAll(".menu-item.active, .business-menu-item.active").forEach(function (el) {
51
+ var _el$scrollIntoView;
52
+ return (_el$scrollIntoView = el.scrollIntoView) === null || _el$scrollIntoView === void 0 ? void 0 : _el$scrollIntoView.call(el, {
53
+ block: "nearest"
54
+ });
55
+ });
56
+ }, [activeFirstMenu, activeKey]);
43
57
  return /*#__PURE__*/_jsxs("div", {
44
58
  className: "company-sidebar-first",
59
+ ref: rootRef,
45
60
  children: [/*#__PURE__*/_jsxs("div", {
46
61
  className: "brand-area",
47
62
  children: [/*#__PURE__*/_jsx(CompanyPopover, {
@@ -8,6 +8,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
8
8
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
9
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
10
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ import { useEffect, useRef } from "react";
11
12
  import { SvgIcon } from "../../shared-components";
12
13
  import "./index.scss";
13
14
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -32,6 +33,18 @@ export default function SecondSidebar(_ref) {
32
33
  isFavorited = _ref.isFavorited;
33
34
  var showSecondSidebar = activeFirstMenu && activeFirstMenu !== "home" ? secondSidebarHovered || secondSidebarFixed : false;
34
35
  var isFavorites = activeFirstMenu === "favorites";
36
+
37
+ // active 项滚动定位:二级栏显示 / 选中项 / 分组展开变化后,把高亮项滚入可视区。
38
+ // 隐藏项(display:none)的 scrollIntoView 是 no-op;分组展开由 expandedKeys 渲染期直接生效,
39
+ // 父组件同拍传 expandedKeys + activeKey 时,本 effect 在 DOM 提交后执行即可正确定位
40
+ var menuListRef = useRef(null);
41
+ useEffect(function () {
42
+ var _menuListRef$current, _menuListRef$current$;
43
+ if (!showSecondSidebar) return;
44
+ (_menuListRef$current = menuListRef.current) === null || _menuListRef$current === void 0 || (_menuListRef$current = _menuListRef$current.querySelector(".menu-item.active")) === null || _menuListRef$current === void 0 || (_menuListRef$current$ = _menuListRef$current.scrollIntoView) === null || _menuListRef$current$ === void 0 || _menuListRef$current$.call(_menuListRef$current, {
45
+ block: "nearest"
46
+ });
47
+ }, [showSecondSidebar, activeKey, expandedKeys, isFavorites, secondMenus]);
35
48
  var favoriteItems = (favorites || []).map(function (item) {
36
49
  return {
37
50
  key: item.menuKey,
@@ -203,6 +216,7 @@ export default function SecondSidebar(_ref) {
203
216
  onMouseLeave: onMouseLeave,
204
217
  children: [/*#__PURE__*/_jsx("div", {
205
218
  className: "menu-list",
219
+ ref: menuListRef,
206
220
  children: isFavorites ? renderFavorites() : renderMenus()
207
221
  }), /*#__PURE__*/_jsxs("div", {
208
222
  className: "collapse-container",
@@ -89,7 +89,6 @@ export default function CompanySidebar(_ref) {
89
89
  hoverKey: null,
90
90
  moreDrawerOpen: false,
91
91
  customNavVisible: false,
92
- localExpandedKeys: expandedKeys,
93
92
  localFavorites: favorites,
94
93
  hasError: false
95
94
  }),
@@ -132,13 +131,9 @@ export default function CompanySidebar(_ref) {
132
131
  });
133
132
  onMenuClick(menu);
134
133
  }, [leafToFirstKeyMap, activeFirstMenu, onFirstMenuSelect, onMenuClick]);
135
- useEffect(function () {
136
- setState(function (prev) {
137
- return _objectSpread(_objectSpread({}, prev), {}, {
138
- localExpandedKeys: expandedKeys
139
- });
140
- });
141
- }, [expandedKeys]);
134
+
135
+ // expandedKeys 为纯受控 prop,直接渲染(不镜像进内部 state):
136
+ // effect 镜像会让 prop 变化那一拍仍渲染旧值,消费方 effect 读 DOM 永远滞后一拍
142
137
  useEffect(function () {
143
138
  setState(function (prev) {
144
139
  return _objectSpread(_objectSpread({}, prev), {}, {
@@ -339,7 +334,7 @@ export default function CompanySidebar(_ref) {
339
334
  secondSidebarFixed: secondSidebarFixed,
340
335
  secondMenus: displaySecondMenus,
341
336
  favorites: state.localFavorites,
342
- expandedKeys: state.localExpandedKeys,
337
+ expandedKeys: expandedKeys,
343
338
  emptyImage: emptyImage,
344
339
  onMenuClick: function onMenuClick(menu) {
345
340
  handleLeafMenuClick(menu);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@donglegeyu/company-ui",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/es/index.js",
6
6
  "types": "dist/es/index.d.ts",