@oceanbase/ui 0.2.32 → 0.2.33

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.
@@ -5,6 +5,10 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
5
5
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
7
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
11
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
8
12
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
13
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
14
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -19,7 +23,7 @@ import { Typography, theme } from '@oceanbase/design';
19
23
  import { isNullValue } from '@oceanbase/util';
20
24
  import { ConfigProvider, Divider, Layout, Menu, Tooltip } from '@oceanbase/design';
21
25
  import classNames from 'classnames';
22
- import { some } from 'lodash';
26
+ import { some, uniq } from 'lodash';
23
27
  import { pathToRegexp } from 'path-to-regexp';
24
28
  import React, { useEffect, useState, useContext } from 'react';
25
29
  import LocaleWrapper from "../locale/LocaleWrapper";
@@ -90,7 +94,13 @@ var BasicLayout = function BasicLayout(_ref) {
90
94
  return item;
91
95
  });
92
96
  if (newSelectedKeys.length > 0) {
93
- setSelectedKeys([newSelectedKeys[newSelectedKeys.length - 1]]);
97
+ // use last selected key to avoid multiple selected menus
98
+ var selectedKey = newSelectedKeys[newSelectedKeys.length - 1];
99
+ setSelectedKeys([selectedKey]);
100
+ // get parent keys of current selectedKey
101
+ var selectedParentKeys = getParentKeys(menus, selectedKey);
102
+ // append parent keys as open keys
103
+ setOpenKeys(uniq([].concat(_toConsumableArray(openKeys), _toConsumableArray(selectedParentKeys))));
94
104
  } else {
95
105
  setSelectedKeys([]);
96
106
  }
@@ -98,12 +108,11 @@ var BasicLayout = function BasicLayout(_ref) {
98
108
  var menuProps = {
99
109
  selectedKeys: selectedKeys,
100
110
  openKeys: openKeys,
101
- onSelect: function (_ref2) {
111
+ onSelect: function onSelect(_ref2) {
102
112
  var newSelectedKeys = _ref2.selectedKeys;
103
113
  setSelectedKeys(newSelectedKeys);
104
114
  },
105
115
  onOpenChange: function onOpenChange(newOpenKeys) {
106
- // 最多只允许一个子菜单展开
107
116
  setOpenKeys(newOpenKeys);
108
117
  }
109
118
  };
@@ -112,6 +121,21 @@ var BasicLayout = function BasicLayout(_ref) {
112
121
  return pathToRegexp(item).test(path);
113
122
  });
114
123
  };
124
+ var getParentKeys = function getParentKeys(menuList, selectedKey) {
125
+ var keys = [];
126
+ (menuList || []).forEach(function (item) {
127
+ var itemChildren = item.children || [];
128
+ var childrenKeys = itemChildren.map(function (child) {
129
+ return child.link;
130
+ });
131
+ if (childrenKeys.includes(selectedKey)) {
132
+ keys = [].concat(_toConsumableArray(keys), [item.link]);
133
+ } else {
134
+ keys = [].concat(_toConsumableArray(keys), [getParentKeys(itemChildren, selectedKey)]);
135
+ }
136
+ });
137
+ return keys;
138
+ };
115
139
  var getFlatMenuKeys = function getFlatMenuKeys(menuList) {
116
140
  var keys = [];
117
141
  (menuList || []).forEach(function (item) {
@@ -29,7 +29,7 @@ export declare const THEME_DARK = "dark";
29
29
  export declare const THEME_LIGHT = "light";
30
30
  declare const ThemeTypes: ["dark", "light"];
31
31
  export type ThemeType = (typeof ThemeTypes)[number];
32
- declare const supportedLanguages: ("ruby" | "css" | "bash" | "json" | "java" | "go" | "javascript" | "typescript" | "groovy" | "python" | "cpp" | "http" | "markdown" | "nginx" | "sql" | "xml" | "dockerfile" | "yaml" | "solidity" | "tsx" | "jsx")[];
32
+ declare const supportedLanguages: ("ruby" | "css" | "java" | "json" | "bash" | "javascript" | "typescript" | "groovy" | "python" | "cpp" | "http" | "markdown" | "nginx" | "sql" | "xml" | "dockerfile" | "go" | "yaml" | "solidity" | "tsx" | "jsx")[];
33
33
  export type LanguageType = (typeof supportedLanguages)[number] | 'html';
34
34
  export interface HighlightProps extends LocaleWrapperProps {
35
35
  /**
@@ -80,7 +80,10 @@ var BasicLayout = ({
80
80
  const selectedMenuKeys = (0, import_util2.urlToList)(pathname).map((itemPath) => getMenuMatches(getFlatMenuKeys(menus), itemPath).pop()) || [];
81
81
  const newSelectedKeys = selectedMenuKeys.filter((item) => item);
82
82
  if (newSelectedKeys.length > 0) {
83
- setSelectedKeys([newSelectedKeys[newSelectedKeys.length - 1]]);
83
+ const selectedKey = newSelectedKeys[newSelectedKeys.length - 1];
84
+ setSelectedKeys([selectedKey]);
85
+ const selectedParentKeys = getParentKeys(menus, selectedKey);
86
+ setOpenKeys((0, import_lodash.uniq)([...openKeys, ...selectedParentKeys]));
84
87
  } else {
85
88
  setSelectedKeys([]);
86
89
  }
@@ -100,6 +103,19 @@ var BasicLayout = ({
100
103
  return (0, import_path_to_regexp.pathToRegexp)(item).test(path);
101
104
  });
102
105
  };
106
+ const getParentKeys = (menuList, selectedKey) => {
107
+ let keys = [];
108
+ (menuList || []).forEach((item) => {
109
+ const itemChildren = item.children || [];
110
+ const childrenKeys = itemChildren.map((child) => child.link);
111
+ if (childrenKeys.includes(selectedKey)) {
112
+ keys = [...keys, item.link];
113
+ } else {
114
+ keys = [...keys, getParentKeys(itemChildren, selectedKey)];
115
+ }
116
+ });
117
+ return keys;
118
+ };
103
119
  const getFlatMenuKeys = (menuList) => {
104
120
  let keys = [];
105
121
  (menuList || []).forEach((item) => {
@@ -29,7 +29,7 @@ export declare const THEME_DARK = "dark";
29
29
  export declare const THEME_LIGHT = "light";
30
30
  declare const ThemeTypes: ["dark", "light"];
31
31
  export type ThemeType = (typeof ThemeTypes)[number];
32
- declare const supportedLanguages: ("ruby" | "css" | "bash" | "json" | "java" | "go" | "javascript" | "typescript" | "groovy" | "python" | "cpp" | "http" | "markdown" | "nginx" | "sql" | "xml" | "dockerfile" | "yaml" | "solidity" | "tsx" | "jsx")[];
32
+ declare const supportedLanguages: ("ruby" | "css" | "java" | "json" | "bash" | "javascript" | "typescript" | "groovy" | "python" | "cpp" | "http" | "markdown" | "nginx" | "sql" | "xml" | "dockerfile" | "go" | "yaml" | "solidity" | "tsx" | "jsx")[];
33
33
  export type LanguageType = (typeof supportedLanguages)[number] | 'html';
34
34
  export interface HighlightProps extends LocaleWrapperProps {
35
35
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oceanbase/ui",
3
- "version": "0.2.32",
3
+ "version": "0.2.33",
4
4
  "description": "The UI library based on OceanBase Design",
5
5
  "keywords": [
6
6
  "oceanbase",
@@ -37,7 +37,7 @@
37
37
  "@ant-design/cssinjs": "^1.17.2",
38
38
  "@ant-design/pro-components": "^2.6.34",
39
39
  "@ant-design/pro-layout": "^7.17.15",
40
- "@oceanbase/design": "^0.2.31",
40
+ "@oceanbase/design": "^0.2.32",
41
41
  "@oceanbase/icons": "^0.2.9",
42
42
  "@oceanbase/util": "^0.2.12",
43
43
  "ahooks": "^2.10.14",
@@ -65,5 +65,5 @@
65
65
  "react": ">=16.9.0",
66
66
  "react-dom": ">=16.9.0"
67
67
  },
68
- "gitHead": "532d9294abcd03743224d6a9d59d4f1c9ab71375"
68
+ "gitHead": "61cbd02d7b906cd6fb2ee76531fe5da792ad672b"
69
69
  }