@lemon-fe/components 1.4.22-alpha.2 → 1.4.22-alpha.4

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.
@@ -194,13 +194,15 @@ export default function FieldModal(props) {
194
194
  message: fieldModal.customColumnNameTextRequired
195
195
  }, {
196
196
  validator: function validator(_, val) {
197
- var _groups$find;
198
- if (groupId ? (_groups$find = groups.find(function (item) {
199
- return item.groupId === groupId;
200
- })) === null || _groups$find === void 0 || (_groups$find = _groups$find.children) === null || _groups$find === void 0 ? void 0 : _groups$find.some(function (item) {
201
- return item.headerName === val;
197
+ if (groupId ? groups.some(function (item) {
198
+ if (item.groupId === groupId) {
199
+ return item.children.some(function (child) {
200
+ return (typeof openProp === 'boolean' || child.colId !== (openProp === null || openProp === void 0 ? void 0 : openProp.id)) && child.headerName === val;
201
+ });
202
+ }
203
+ return false;
202
204
  }) : nodes.some(function (item) {
203
- return item.title === val;
205
+ return (typeof openProp === 'boolean' || item.id !== (openProp === null || openProp === void 0 ? void 0 : openProp.id)) && item.title === val;
204
206
  })) {
205
207
  return Promise.reject(new Error(fieldModal.idTooltip));
206
208
  }
@@ -20,6 +20,14 @@ interface Props<KeyType> extends Omit<TreeProps, 'onSelect' | 'selectedKeys' | '
20
20
  * @description 是否在搜索时保留父节点
21
21
  */
22
22
  filterKeepParents?: boolean;
23
+ /**
24
+ * @description 是否在搜索时保留子孙节点
25
+ */
26
+ filterKeepDescendants?: boolean;
27
+ /**
28
+ * @description 是否高亮关键词
29
+ */
30
+ highlightKeywords?: boolean;
23
31
  }
24
32
  declare function SiderTreeTabs(props: {
25
33
  tabs: {
@@ -1,5 +1,5 @@
1
1
  var _excluded = ["tabs", "children"],
2
- _excluded2 = ["data", "showSearch", "placeholder", "onSelect", "filterNode", "operation", "header", "footer", "height", "filterKeepParents"];
2
+ _excluded2 = ["data", "showSearch", "placeholder", "onSelect", "filterNode", "operation", "header", "footer", "height", "filterKeepParents", "filterKeepDescendants", "highlightKeywords"];
3
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
4
  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."); }
5
5
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
@@ -74,6 +74,8 @@ export default function SiderTree(props) {
74
74
  footer = props.footer,
75
75
  heightProp = props.height,
76
76
  filterKeepParents = props.filterKeepParents,
77
+ filterKeepDescendants = props.filterKeepDescendants,
78
+ highlightKeywords = props.highlightKeywords,
77
79
  restProps = _objectWithoutProperties(props, _excluded2);
78
80
  var _useState = useState(''),
79
81
  _useState2 = _slicedToArray(_useState, 2),
@@ -87,47 +89,70 @@ export default function SiderTree(props) {
87
89
  _useLocaleReceiver2 = _slicedToArray(_useLocaleReceiver, 1),
88
90
  SiderTreeLocale = _useLocaleReceiver2[0];
89
91
  var tree = useMemo(function () {
90
- var list = mData;
91
- var items = new Set();
92
- var addedNodes = new Set();
93
92
  var shouldInclude = function shouldInclude(item) {
94
93
  return filterNode ? filterNode(keywords, item) : item.title.toString().toLowerCase().includes(keywords.toLowerCase());
95
94
  };
96
- if (keywords && !filterKeepParents) {
97
- list = list.filter(shouldInclude);
98
- }
99
- var map = new Map(list.map(function (item) {
100
- return [item.key, {
95
+ var matchedNodes = new Set();
96
+ var childrenIndex = new Map();
97
+ var nodesIndex = new Map();
98
+ var addedNodes = new Set();
99
+ var roots = [];
100
+ mData.forEach(function (item) {
101
+ var node = {
101
102
  key: item.key,
102
103
  parent: item.parent,
103
104
  icon: item.icon,
104
105
  data: item,
105
106
  title: item.title
106
- }];
107
- }));
108
- list.forEach(function (item) {
109
- if (keywords && !shouldInclude(item)) {
107
+ };
108
+ nodesIndex.set(item.key, node);
109
+ if (item.parent !== undefined) {
110
+ var children = childrenIndex.get(item.parent) || [];
111
+ children.push(node);
112
+ childrenIndex.set(item.parent, children);
113
+ }
114
+ if (!keywords || shouldInclude(item)) {
115
+ matchedNodes.add(node);
116
+ }
117
+ });
118
+ var collectAncestors = function collectAncestors(node) {
119
+ if (addedNodes.has(node.key)) {
110
120
  return;
111
121
  }
112
- var parent;
113
- var node = map.get(item.key);
114
- while (node) {
115
- if (addedNodes.has(node)) {
116
- return;
117
- }
118
- parent = node.parent !== undefined ? map.get(node.parent) : undefined;
119
- if (parent) {
120
- parent.children = parent.children || [];
121
- parent.children.push(node);
122
+ addedNodes.add(node.key);
123
+ if (node.parent !== undefined) {
124
+ var parentNode = nodesIndex.get(node.parent);
125
+ if (parentNode && (matchedNodes.has(parentNode) || filterKeepParents)) {
126
+ parentNode.children = parentNode.children || [];
127
+ parentNode.children.push(node);
128
+ collectAncestors(parentNode);
122
129
  } else {
123
- items.add(node);
130
+ roots.push(node);
124
131
  }
125
- addedNodes.add(node);
126
- node = parent;
132
+ } else {
133
+ roots.push(node);
134
+ }
135
+ };
136
+ var collectChildren = function collectChildren(node) {
137
+ var children = childrenIndex.get(node.key) || [];
138
+ node.children = node.children || [];
139
+ children.forEach(function (child) {
140
+ if (addedNodes.has(child.key)) {
141
+ return;
142
+ }
143
+ node.children.push(child);
144
+ addedNodes.add(child.key);
145
+ collectChildren(child);
146
+ });
147
+ };
148
+ _toConsumableArray(matchedNodes).forEach(function (item) {
149
+ collectAncestors(item);
150
+ if (filterKeepDescendants) {
151
+ collectChildren(item);
127
152
  }
128
153
  });
129
- return _toConsumableArray(items);
130
- }, [mData, keywords, filterKeepParents]);
154
+ return roots;
155
+ }, [mData, keywords, filterKeepParents, filterKeepDescendants]);
131
156
  var handleChange = useDebounce(function (value) {
132
157
  setKeywords(value);
133
158
  }, 300);
@@ -156,7 +181,8 @@ export default function SiderTree(props) {
156
181
  return /*#__PURE__*/React.createElement(TreeNodeTitle, {
157
182
  operation: operation,
158
183
  node: node.data,
159
- prefixCls: prefixCls
184
+ prefixCls: prefixCls,
185
+ highlightKeywords: highlightKeywords ? keywords : undefined
160
186
  });
161
187
  },
162
188
  onSelect: function onSelect(keys, info) {
@@ -4,6 +4,7 @@ interface Props<T> {
4
4
  node: TreeData<T>;
5
5
  prefixCls: string;
6
6
  operation?: OperationType<T>;
7
+ highlightKeywords?: string;
7
8
  }
8
9
  export default function TreeNodeTitle<T>(props: Props<T>): JSX.Element;
9
10
  export {};
@@ -8,10 +8,11 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
8
8
  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; }
9
9
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
- import { Popover } from 'antd';
12
- import React, { useEffect, useRef, useState } from 'react';
11
+ import { Popover, Typography } from 'antd';
12
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
13
13
  import { useLocaleReceiver } from "../locale-receiver";
14
14
  import classNames from 'classnames';
15
+ var Text = Typography.Text;
15
16
  export default function TreeNodeTitle(props) {
16
17
  var _operation$others;
17
18
  var item = props.node,
@@ -46,17 +47,31 @@ export default function TreeNodeTitle(props) {
46
47
  title = null;
47
48
  };
48
49
  }, []);
50
+ var title = useMemo(function () {
51
+ if (!props.highlightKeywords) {
52
+ return item.title;
53
+ }
54
+ var searchValue = props.highlightKeywords;
55
+ var strTitle = item.title.toString();
56
+ var index = strTitle.indexOf(searchValue);
57
+ if (index === -1) {
58
+ return strTitle;
59
+ }
60
+ return /*#__PURE__*/React.createElement("span", null, strTitle.slice(0, index), /*#__PURE__*/React.createElement(Text, {
61
+ type: "danger"
62
+ }, strTitle.substring(index, index + searchValue.length)), strTitle.slice(index + searchValue.length));
63
+ }, [item.title, props.highlightKeywords]);
49
64
  if (!operation) {
50
65
  return /*#__PURE__*/React.createElement("div", {
51
66
  className: "".concat(prefixCls, "-title-content")
52
- }, item.title);
67
+ }, title);
53
68
  }
54
69
  var others = (_operation$others = operation.others) === null || _operation$others === void 0 ? void 0 : _operation$others.call(operation, item);
55
70
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
56
71
  className: "".concat(prefixCls, "-title-content"),
57
72
  ref: trigger,
58
73
  title: item.title.toString()
59
- }, item.title), /*#__PURE__*/React.createElement("div", {
74
+ }, title), /*#__PURE__*/React.createElement("div", {
60
75
  className: "".concat(prefixCls, "-title-operators"),
61
76
  style: {
62
77
  display: visible || show ? 'block' : 'none'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/components",
3
- "version": "1.4.22-alpha.2",
3
+ "version": "1.4.22-alpha.4",
4
4
  "description": "> TODO: description",
5
5
  "homepage": "",
6
6
  "license": "MIT",
@@ -58,5 +58,5 @@
58
58
  "publishConfig": {
59
59
  "registry": "https://registry.npmjs.org"
60
60
  },
61
- "gitHead": "b558090241f16b9e2be6079f6d8a8fad1e212cb7"
61
+ "gitHead": "ff08fa04ab97d9f6ab0e9c9130e96be8e66c1bc6"
62
62
  }