@oceanbase/design 1.0.0-alpha.15 → 1.0.0-alpha.17

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.
Files changed (79) hide show
  1. package/dist/design.min.js +1 -1
  2. package/es/alert/index.d.ts +1 -1
  3. package/es/alert/index.js +4 -2
  4. package/es/filter/components/CountNumber.js +2 -1
  5. package/es/filter/components/FilterButton.d.ts +2 -0
  6. package/es/filter/components/FilterButton.js +6 -3
  7. package/es/filter/components/FilterCascader/components/CascaderOption/OptionCheckbox.d.ts +20 -0
  8. package/es/filter/components/FilterCascader/components/CascaderOption/OptionCheckbox.js +101 -0
  9. package/es/filter/components/FilterCascader/components/CascaderOption/OptionItem.d.ts +13 -0
  10. package/es/filter/components/FilterCascader/components/CascaderOption/OptionItem.js +44 -0
  11. package/es/filter/components/FilterCascader/components/FlatCascaderContent/index.d.ts +16 -0
  12. package/es/filter/components/FilterCascader/components/FlatCascaderContent/index.js +64 -0
  13. package/es/filter/components/FilterCascader/components/NormalCascaderContent.d.ts +24 -0
  14. package/es/filter/components/FilterCascader/components/NormalCascaderContent.js +284 -0
  15. package/es/filter/components/FilterCascader/constants.d.ts +7 -0
  16. package/es/filter/components/FilterCascader/constants.js +8 -0
  17. package/es/filter/components/FilterCascader/hooks/useCascaderCallbacks.d.ts +12 -0
  18. package/es/filter/components/FilterCascader/hooks/useCascaderCallbacks.js +101 -0
  19. package/es/filter/components/FilterCascader/hooks/useCascaderLabels.d.ts +9 -0
  20. package/es/filter/components/FilterCascader/hooks/useCascaderLabels.js +50 -0
  21. package/es/filter/components/FilterCascader/hooks/useNormalizedValue.d.ts +7 -0
  22. package/es/filter/components/FilterCascader/hooks/useNormalizedValue.js +53 -0
  23. package/es/filter/components/FilterCascader/index.d.ts +5 -0
  24. package/es/filter/components/FilterCascader/index.js +317 -0
  25. package/es/filter/components/FilterCascader/types.d.ts +56 -0
  26. package/es/filter/components/FilterCascader/types.js +1 -0
  27. package/es/filter/components/FilterCascader/utils/countUtils.d.ts +13 -0
  28. package/es/filter/components/FilterCascader/utils/countUtils.js +48 -0
  29. package/es/filter/components/FilterCascader/utils/pathUtils.d.ts +17 -0
  30. package/es/filter/components/FilterCascader/utils/pathUtils.js +91 -0
  31. package/es/filter/components/FilterCheckbox.js +29 -7
  32. package/es/filter/components/FilterWrap.js +30 -1
  33. package/es/filter/components/ResponsiveFilterGroup.js +252 -359
  34. package/es/filter/index.d.ts +1 -1
  35. package/es/filter/index.js +11 -7
  36. package/es/filter/style/index.js +9 -2
  37. package/es/filter/type.d.ts +5 -0
  38. package/es/table/index.d.ts +2 -2
  39. package/lib/alert/index.d.ts +1 -1
  40. package/lib/alert/index.js +3 -1
  41. package/lib/filter/components/CountNumber.js +2 -1
  42. package/lib/filter/components/FilterButton.d.ts +2 -0
  43. package/lib/filter/components/FilterButton.js +4 -2
  44. package/lib/filter/components/FilterCascader/components/CascaderOption/OptionCheckbox.d.ts +20 -0
  45. package/lib/filter/components/FilterCascader/components/CascaderOption/OptionCheckbox.js +91 -0
  46. package/lib/filter/components/FilterCascader/components/CascaderOption/OptionItem.d.ts +13 -0
  47. package/lib/filter/components/FilterCascader/components/CascaderOption/OptionItem.js +51 -0
  48. package/lib/filter/components/FilterCascader/components/FlatCascaderContent/index.d.ts +16 -0
  49. package/lib/filter/components/FilterCascader/components/FlatCascaderContent/index.js +70 -0
  50. package/lib/filter/components/FilterCascader/components/NormalCascaderContent.d.ts +24 -0
  51. package/lib/filter/components/FilterCascader/components/NormalCascaderContent.js +263 -0
  52. package/lib/filter/components/FilterCascader/constants.d.ts +7 -0
  53. package/lib/filter/components/FilterCascader/constants.js +14 -0
  54. package/lib/filter/components/FilterCascader/hooks/useCascaderCallbacks.d.ts +12 -0
  55. package/lib/filter/components/FilterCascader/hooks/useCascaderCallbacks.js +81 -0
  56. package/lib/filter/components/FilterCascader/hooks/useCascaderLabels.d.ts +9 -0
  57. package/lib/filter/components/FilterCascader/hooks/useCascaderLabels.js +56 -0
  58. package/lib/filter/components/FilterCascader/hooks/useNormalizedValue.d.ts +7 -0
  59. package/lib/filter/components/FilterCascader/hooks/useNormalizedValue.js +48 -0
  60. package/lib/filter/components/FilterCascader/index.d.ts +5 -0
  61. package/lib/filter/components/FilterCascader/index.js +298 -0
  62. package/lib/filter/components/FilterCascader/types.d.ts +56 -0
  63. package/lib/filter/components/FilterCascader/types.js +5 -0
  64. package/lib/filter/components/FilterCascader/utils/countUtils.d.ts +13 -0
  65. package/lib/filter/components/FilterCascader/utils/countUtils.js +49 -0
  66. package/lib/filter/components/FilterCascader/utils/pathUtils.d.ts +17 -0
  67. package/lib/filter/components/FilterCascader/utils/pathUtils.js +56 -0
  68. package/lib/filter/components/FilterCheckbox.js +29 -7
  69. package/lib/filter/components/FilterWrap.js +28 -1
  70. package/lib/filter/components/ResponsiveFilterGroup.js +214 -340
  71. package/lib/filter/index.d.ts +1 -1
  72. package/lib/filter/index.js +11 -7
  73. package/lib/filter/style/index.js +10 -1
  74. package/lib/filter/type.d.ts +5 -0
  75. package/package.json +3 -3
  76. package/es/filter/components/FilterCascader.d.ts +0 -31
  77. package/es/filter/components/FilterCascader.js +0 -529
  78. package/lib/filter/components/FilterCascader.d.ts +0 -31
  79. package/lib/filter/components/FilterCascader.js +0 -449
@@ -0,0 +1,317 @@
1
+ "use client";
2
+ var _excluded = ["options", "value", "onChange", "icon", "label", "bordered", "multiple", "count", "showSearch", "_isCollapsed", "flat"],
3
+ _excluded2 = ["onOpenChange"];
4
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
+ 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; }
7
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
+ 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."); }
12
+ 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); }
13
+ 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; }
14
+ 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; } }
15
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
17
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
18
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
19
+ import theme from "../../../theme";
20
+ import { useFilterContext } from "../../FilterContext";
21
+ import { useFilterCollapsed } from "../../hooks/useFilterCollapsed";
22
+ import { useFilterTooltip } from "../../hooks/useFilterTooltip";
23
+ import useFilterStyle, { getFilterCls } from "../../style";
24
+ import { generateFilterId, getPlaceholder, getWrappedValueStyle, normalizeLabel } from "../../utils";
25
+ import CountNumber from "../CountNumber";
26
+ import FilterButton from "../FilterButton";
27
+ import WrappedTagsDisplay from "../WrappedTagsDisplay";
28
+ import { useNormalizedValue } from "./hooks/useNormalizedValue";
29
+ import { useCascaderLabels } from "./hooks/useCascaderLabels";
30
+ import { useCascaderCallbacks } from "./hooks/useCascaderCallbacks";
31
+ import { countLeafNodes } from "./utils/countUtils";
32
+ import { FlatCascaderContent } from "./components/FlatCascaderContent";
33
+ import { NormalCascaderContent } from "./components/NormalCascaderContent";
34
+ import { jsx as _jsx } from "react/jsx-runtime";
35
+ import { jsxs as _jsxs } from "react/jsx-runtime";
36
+ var FilterCascader = function FilterCascader(_ref) {
37
+ var _count$showTotal;
38
+ var _ref$options = _ref.options,
39
+ options = _ref$options === void 0 ? [] : _ref$options,
40
+ value = _ref.value,
41
+ onChange = _ref.onChange,
42
+ icon = _ref.icon,
43
+ label = _ref.label,
44
+ _ref$bordered = _ref.bordered,
45
+ bordered = _ref$bordered === void 0 ? true : _ref$bordered,
46
+ _ref$multiple = _ref.multiple,
47
+ multiple = _ref$multiple === void 0 ? false : _ref$multiple,
48
+ _ref$count = _ref.count,
49
+ count = _ref$count === void 0 ? false : _ref$count,
50
+ _ref$showSearch = _ref.showSearch,
51
+ showSearch = _ref$showSearch === void 0 ? false : _ref$showSearch,
52
+ _ref$_isCollapsed = _ref._isCollapsed,
53
+ _isCollapsed = _ref$_isCollapsed === void 0 ? false : _ref$_isCollapsed,
54
+ _ref$flat = _ref.flat,
55
+ flat = _ref$flat === void 0 ? false : _ref$flat,
56
+ restProps = _objectWithoutProperties(_ref, _excluded);
57
+ var isCollapsed = useFilterCollapsed(_isCollapsed);
58
+ var _useFilterStyle = useFilterStyle(),
59
+ prefixCls = _useFilterStyle.prefixCls;
60
+ var _theme$useToken = theme.useToken(),
61
+ token = _theme$useToken.token;
62
+ var filterButtonRef = useRef(null);
63
+ var _useFilterContext = useFilterContext(),
64
+ updateFilterValue = _useFilterContext.updateFilterValue;
65
+ var filterId = useMemo(function () {
66
+ return generateFilterId('cascader', label);
67
+ }, [label]);
68
+
69
+ // 用于控制二级 Popover 的打开状态(仅在单选模式下使用)
70
+ var _useState = useState(null),
71
+ _useState2 = _slicedToArray(_useState, 2),
72
+ openPopoverKey = _useState2[0],
73
+ setOpenPopoverKey = _useState2[1];
74
+ // 用于 flat 模式下的多列路径(支持多层级)
75
+ var _useState3 = useState([]),
76
+ _useState4 = _slicedToArray(_useState3, 2),
77
+ flatColumnsPath = _useState4[0],
78
+ setFlatColumnsPath = _useState4[1];
79
+
80
+ // 搜索关键词状态
81
+ var _useState5 = useState(''),
82
+ _useState6 = _slicedToArray(_useState5, 2),
83
+ searchKeyword = _useState6[0],
84
+ setSearchKeyword = _useState6[1];
85
+
86
+ // 从 restProps 中排除 onOpenChange,避免类型冲突
87
+ var externalOnOpenChange = restProps.onOpenChange,
88
+ filterButtonProps = _objectWithoutProperties(restProps, _excluded2);
89
+
90
+ // 解析 count 配置
91
+ var showCount = !!count;
92
+ var showTotal = _typeof(count) === 'object' ? (_count$showTotal = count.showTotal) !== null && _count$showTotal !== void 0 ? _count$showTotal : false : false;
93
+
94
+ // 值管理
95
+ var _useNormalizedValue = useNormalizedValue(value, onChange, multiple),
96
+ currentValue = _useNormalizedValue.currentValue,
97
+ setValue = _useNormalizedValue.setValue;
98
+
99
+ // 标签显示
100
+ var _useCascaderLabels = useCascaderLabels(currentValue, options, label, multiple, isCollapsed),
101
+ getSelectedLabel = _useCascaderLabels.getSelectedLabel,
102
+ getSelectedTags = _useCascaderLabels.getSelectedTags;
103
+
104
+ // 回调函数
105
+ var _useCascaderCallbacks = useCascaderCallbacks(currentValue, setValue, options, multiple, filterButtonRef, setOpenPopoverKey),
106
+ handleChange = _useCascaderCallbacks.handleChange,
107
+ clearByParent = _useCascaderCallbacks.clearByParent,
108
+ handleClear = _useCascaderCallbacks.handleClear,
109
+ selectAllChildren = _useCascaderCallbacks.selectAllChildren,
110
+ handleRemoveTag = _useCascaderCallbacks.handleRemoveTag;
111
+
112
+ // 使用 Tooltip hook
113
+ var _useFilterTooltip = useFilterTooltip({
114
+ hasValue: currentValue.length > 0,
115
+ label: label,
116
+ content: currentValue.length > 0 ? getSelectedTags().map(function (i) {
117
+ return i.label;
118
+ }).join(', ') : null,
119
+ disabled: isCollapsed
120
+ }),
121
+ onPopoverOpenChange = _useFilterTooltip.onPopoverOpenChange,
122
+ wrapWithTooltip = _useFilterTooltip.wrapWithTooltip;
123
+
124
+ // 处理主弹窗状态变化
125
+ var handleMainPopoverOpenChange = useCallback(function (open) {
126
+ onPopoverOpenChange(open);
127
+ // 当主弹窗关闭时,同步关闭二级弹窗(单选模式)
128
+ if (!open && !multiple) {
129
+ setOpenPopoverKey(null);
130
+ }
131
+ // flat 模式下,关闭弹窗时重置列路径,下次打开时只显示最顶层
132
+ if (!open && flat) {
133
+ setFlatColumnsPath([]);
134
+ }
135
+ // 弹窗关闭时清空搜索关键词
136
+ if (!open) {
137
+ setSearchKeyword('');
138
+ }
139
+ externalOnOpenChange === null || externalOnOpenChange === void 0 || externalOnOpenChange(open);
140
+ }, [onPopoverOpenChange, externalOnOpenChange, multiple, flat]);
141
+
142
+ // 根据搜索关键词过滤选项(同时搜索父级和子级)
143
+ var filteredOptions = useMemo(function () {
144
+ if (!showSearch || !searchKeyword) return options;
145
+ var lowerKeyword = searchKeyword.toLowerCase().trim();
146
+ return options.map(function (option) {
147
+ var parentLabel = normalizeLabel(option.label).toLowerCase();
148
+ var parentMatches = parentLabel.includes(lowerKeyword);
149
+
150
+ // 递归过滤子级选项
151
+ var filterChildren = function filterChildren(children) {
152
+ return children.map(function (child) {
153
+ var childLabel = normalizeLabel(child.label).toLowerCase();
154
+ var childMatches = childLabel.includes(lowerKeyword);
155
+
156
+ // 如果有子级,递归过滤
157
+ if (child.children && child.children.length > 0) {
158
+ var _filteredChildren = filterChildren(child.children);
159
+ // 如果当前节点匹配或有匹配的子级,则保留
160
+ if (childMatches || _filteredChildren.length > 0) {
161
+ return _objectSpread(_objectSpread({}, child), {}, {
162
+ children: childMatches ? child.children : _filteredChildren
163
+ });
164
+ }
165
+ return null;
166
+ }
167
+
168
+ // 叶子节点,如果匹配则保留
169
+ return childMatches ? child : null;
170
+ }).filter(function (child) {
171
+ return child !== null;
172
+ });
173
+ };
174
+ var filteredChildren = option.children ? filterChildren(option.children) : [];
175
+
176
+ // 如果父级匹配或有匹配的子级,则保留该选项
177
+ if (parentMatches || filteredChildren.length > 0) {
178
+ return _objectSpread(_objectSpread({}, option), {}, {
179
+ // 如果父级不匹配但子级匹配,只显示匹配的子级
180
+ children: parentMatches ? option.children : filteredChildren
181
+ });
182
+ }
183
+ return null;
184
+ }).filter(function (option) {
185
+ return option !== null;
186
+ });
187
+ }, [showSearch, searchKeyword, options]);
188
+
189
+ // 当值变化时,更新 context 中的值
190
+ useEffect(function () {
191
+ if (isCollapsed && updateFilterValue) {
192
+ updateFilterValue(filterId, label, currentValue, options, 'cascader');
193
+ }
194
+ }, [isCollapsed, updateFilterValue, filterId, label, currentValue, options]);
195
+
196
+ // 渲染内容
197
+ var renderContent = flat ? /*#__PURE__*/_jsx(FlatCascaderContent, {
198
+ options: filteredOptions,
199
+ currentValue: currentValue,
200
+ multiple: multiple,
201
+ filterButtonRef: filterButtonRef,
202
+ onValueChange: setValue
203
+ }) : /*#__PURE__*/_jsx(NormalCascaderContent, {
204
+ options: filteredOptions,
205
+ currentValue: currentValue,
206
+ multiple: multiple,
207
+ prefixCls: prefixCls,
208
+ openPopoverKey: openPopoverKey,
209
+ filterButtonRef: filterButtonRef,
210
+ onOpenPopoverKeyChange: setOpenPopoverKey,
211
+ onValueChange: setValue,
212
+ onHandleChange: handleChange,
213
+ onClearByParent: clearByParent,
214
+ onSelectAllChildren: selectAllChildren,
215
+ showSearch: showSearch,
216
+ searchKeyword: searchKeyword,
217
+ onSearchChange: setSearchKeyword
218
+ });
219
+
220
+ // flat 模式下的 Popover 样式(动态宽度)
221
+ var flatPopoverStyles = flat ? {
222
+ body: {
223
+ padding: 0
224
+ }
225
+ } : undefined;
226
+
227
+ // 计算总数(用于显示计数)
228
+ var totalCount = showTotal ? options.reduce(function (acc, curr) {
229
+ return acc + (curr.children ? countLeafNodes(curr.children) : 0);
230
+ }, 0) : 0;
231
+
232
+ // Wrapped 模式
233
+ if (isCollapsed) {
234
+ var hasValue = currentValue.length > 0;
235
+ if (multiple) {
236
+ var selectedTags = getSelectedTags();
237
+ return /*#__PURE__*/_jsxs("div", {
238
+ style: {
239
+ paddingBlock: token.paddingXXS
240
+ },
241
+ children: [/*#__PURE__*/_jsx("div", {
242
+ style: {
243
+ marginBottom: 8
244
+ },
245
+ children: label
246
+ }), /*#__PURE__*/_jsx(FilterButton, _objectSpread(_objectSpread(_objectSpread({
247
+ ref: filterButtonRef,
248
+ icon: icon,
249
+ label: label,
250
+ bordered: bordered,
251
+ onClear: handleClear,
252
+ content: renderContent,
253
+ selected: hasValue,
254
+ onOpenChange: handleMainPopoverOpenChange,
255
+ _isFlat: flat
256
+ }, flat ? {
257
+ styles: flatPopoverStyles
258
+ } : {}), filterButtonProps), {}, {
259
+ children: /*#__PURE__*/_jsx(WrappedTagsDisplay, {
260
+ tags: selectedTags,
261
+ onRemove: handleRemoveTag
262
+ })
263
+ }))]
264
+ });
265
+ }
266
+ return /*#__PURE__*/_jsxs("div", {
267
+ children: [/*#__PURE__*/_jsx("div", {
268
+ style: {
269
+ marginBottom: 8
270
+ },
271
+ children: label
272
+ }), /*#__PURE__*/_jsx(FilterButton, _objectSpread(_objectSpread(_objectSpread({
273
+ ref: filterButtonRef,
274
+ icon: icon,
275
+ label: label,
276
+ bordered: bordered,
277
+ onClear: handleClear,
278
+ content: renderContent,
279
+ selected: hasValue,
280
+ onOpenChange: handleMainPopoverOpenChange
281
+ }, flat ? {
282
+ styles: flatPopoverStyles
283
+ } : {}), filterButtonProps), {}, {
284
+ children: /*#__PURE__*/_jsx("span", {
285
+ className: getFilterCls(prefixCls, 'text-ellipsis'),
286
+ style: getWrappedValueStyle(hasValue),
287
+ children: hasValue ? getSelectedLabel() : getPlaceholder()
288
+ })
289
+ }))]
290
+ });
291
+ }
292
+
293
+ // 正常模式
294
+ var filterButton = /*#__PURE__*/_jsxs(FilterButton, _objectSpread(_objectSpread(_objectSpread({
295
+ ref: filterButtonRef,
296
+ icon: icon,
297
+ label: label,
298
+ bordered: bordered,
299
+ onClear: handleClear,
300
+ content: renderContent,
301
+ selected: !!currentValue.length,
302
+ onOpenChange: handleMainPopoverOpenChange,
303
+ _isFlat: flat
304
+ }, flat ? {
305
+ styles: flatPopoverStyles
306
+ } : {}), filterButtonProps), {}, {
307
+ children: [/*#__PURE__*/_jsx("span", {
308
+ className: getFilterCls(prefixCls, 'text-ellipsis'),
309
+ children: getSelectedLabel()
310
+ }), multiple && showCount && currentValue.length > 0 && /*#__PURE__*/_jsx(CountNumber, {
311
+ count: currentValue.length,
312
+ total: totalCount
313
+ })]
314
+ }));
315
+ return wrapWithTooltip(filterButton);
316
+ };
317
+ export default FilterCascader;
@@ -0,0 +1,56 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { BaseFilterProps, InternalFilterProps } from '../../type';
3
+ export interface CascaderOption {
4
+ label?: ReactNode;
5
+ value: string;
6
+ disabled?: boolean;
7
+ children?: CascaderOption[];
8
+ }
9
+ interface BaseFilterCascaderProps extends BaseFilterProps, InternalFilterProps {
10
+ /** 选项列表 */
11
+ options?: CascaderOption[];
12
+ /** 是否显示计数,可传入 { showTotal: true } 同时显示总数 */
13
+ count?: boolean | {
14
+ showTotal?: boolean;
15
+ };
16
+ }
17
+ type FilterCascaderSingleBase = BaseFilterCascaderProps & {
18
+ /** 是否多选 */
19
+ multiple?: false;
20
+ /** 当前选中值,格式为 [parentValue, childValue] */
21
+ value?: string[];
22
+ /** 值变化回调 */
23
+ onChange?: (value: string[]) => void;
24
+ };
25
+ type FilterCascaderMultipleBase = BaseFilterCascaderProps & {
26
+ /** 是否多选 */
27
+ multiple?: true;
28
+ /** 当前选中值,格式为 [[parentValue, childValue], ...] */
29
+ value?: string[][];
30
+ /** 值变化回调 */
31
+ onChange?: (value: string[][]) => void;
32
+ };
33
+ type FilterCascaderWithSearch<T extends FilterCascaderSingleBase | FilterCascaderMultipleBase> = T & {
34
+ /** 是否显示搜索框,默认为 false */
35
+ showSearch: true;
36
+ flat?: never;
37
+ };
38
+ type FilterCascaderWithFlat<T extends FilterCascaderSingleBase | FilterCascaderMultipleBase> = T & {
39
+ /** 扁平化展示 */
40
+ flat: true;
41
+ showSearch?: never;
42
+ };
43
+ type FilterCascaderNormal<T extends FilterCascaderSingleBase | FilterCascaderMultipleBase> = T & {
44
+ flat?: false;
45
+ showSearch?: false;
46
+ };
47
+ export type FilterCascaderSingleProps = FilterCascaderWithSearch<FilterCascaderSingleBase> | FilterCascaderWithFlat<FilterCascaderSingleBase> | FilterCascaderNormal<FilterCascaderSingleBase>;
48
+ export type FilterCascaderMultipleProps = FilterCascaderWithSearch<FilterCascaderMultipleBase> | FilterCascaderWithFlat<FilterCascaderMultipleBase> | FilterCascaderNormal<FilterCascaderMultipleBase>;
49
+ export type FilterCascaderProps = FilterCascaderSingleProps | FilterCascaderMultipleProps;
50
+ export interface SelectedTag {
51
+ label: ReactNode;
52
+ value: string;
53
+ parentValue: string;
54
+ childValue: string;
55
+ }
56
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { CascaderOption } from '../types';
2
+ /**
3
+ * 递归统计所有叶子节点数量(只统计没有children的节点)
4
+ */
5
+ export declare const countLeafNodes: (options: CascaderOption[]) => number;
6
+ /**
7
+ * 收集所有叶子节点的完整路径
8
+ */
9
+ export declare const collectLeafPaths: (options: CascaderOption[], basePath: string[]) => string[][];
10
+ /**
11
+ * 统计选中的子节点数量
12
+ */
13
+ export declare const countSelectedChildren: (currentValue: string[][], currentPath: string[]) => number;
@@ -0,0 +1,48 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ 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."); }
3
+ 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); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ 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; }
7
+ /**
8
+ * 递归统计所有叶子节点数量(只统计没有children的节点)
9
+ */
10
+ export var countLeafNodes = function countLeafNodes(options) {
11
+ var count = 0;
12
+ options.forEach(function (opt) {
13
+ if (opt.children && opt.children.length > 0) {
14
+ count += countLeafNodes(opt.children);
15
+ } else {
16
+ count += 1;
17
+ }
18
+ });
19
+ return count;
20
+ };
21
+
22
+ /**
23
+ * 收集所有叶子节点的完整路径
24
+ */
25
+ export var collectLeafPaths = function collectLeafPaths(options, basePath) {
26
+ var paths = [];
27
+ options.forEach(function (opt) {
28
+ var optPath = [].concat(_toConsumableArray(basePath), [opt.value]);
29
+ if (opt.children && opt.children.length > 0) {
30
+ paths.push.apply(paths, _toConsumableArray(collectLeafPaths(opt.children, optPath)));
31
+ } else {
32
+ paths.push(optPath);
33
+ }
34
+ });
35
+ return paths;
36
+ };
37
+
38
+ /**
39
+ * 统计选中的子节点数量
40
+ */
41
+ export var countSelectedChildren = function countSelectedChildren(currentValue, currentPath) {
42
+ return currentValue.filter(function (selectedPath) {
43
+ if (selectedPath.length <= currentPath.length) return false;
44
+ return currentPath.every(function (val, idx) {
45
+ return selectedPath[idx] === val;
46
+ });
47
+ }).length;
48
+ };
@@ -0,0 +1,17 @@
1
+ import type { CascaderOption } from '../types';
2
+ /**
3
+ * 根据路径查找选项
4
+ */
5
+ export declare const findOptionByPath: (options: CascaderOption[], path: string[]) => CascaderOption | null;
6
+ /**
7
+ * 根据路径获取当前层级的选项列表
8
+ */
9
+ export declare const getCurrentLevelOptions: (options: CascaderOption[], path: string[]) => CascaderOption[];
10
+ /**
11
+ * 检查路径是否在选中值中
12
+ */
13
+ export declare const hasSelectedInPath: (currentValue: string[][], currentPath: string[]) => boolean;
14
+ /**
15
+ * 检查路径是否完全匹配
16
+ */
17
+ export declare const isExactMatch: (currentValue: string[][], currentPath: string[]) => boolean;
@@ -0,0 +1,91 @@
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ 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); }
3
+ 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; }
4
+ /**
5
+ * 根据路径查找选项
6
+ */
7
+ export var findOptionByPath = function findOptionByPath(options, path) {
8
+ if (!path || path.length === 0) return null;
9
+ var currentOptions = options;
10
+ var currentOption = null;
11
+ var _iterator = _createForOfIteratorHelper(path),
12
+ _step;
13
+ try {
14
+ var _loop = function _loop() {
15
+ var pathValue = _step.value;
16
+ var found = currentOptions.find(function (opt) {
17
+ return opt.value === pathValue;
18
+ });
19
+ if (!found) return {
20
+ v: null
21
+ };
22
+ currentOption = found;
23
+ currentOptions = found.children || [];
24
+ },
25
+ _ret;
26
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
27
+ _ret = _loop();
28
+ if (_ret) return _ret.v;
29
+ }
30
+ } catch (err) {
31
+ _iterator.e(err);
32
+ } finally {
33
+ _iterator.f();
34
+ }
35
+ return currentOption;
36
+ };
37
+
38
+ /**
39
+ * 根据路径获取当前层级的选项列表
40
+ */
41
+ export var getCurrentLevelOptions = function getCurrentLevelOptions(options, path) {
42
+ if (path.length === 0) return options;
43
+ var currentOptions = options;
44
+ var _iterator2 = _createForOfIteratorHelper(path),
45
+ _step2;
46
+ try {
47
+ var _loop2 = function _loop2() {
48
+ var pathValue = _step2.value;
49
+ var found = currentOptions.find(function (opt) {
50
+ return opt.value === pathValue;
51
+ });
52
+ if (!found || !found.children) return {
53
+ v: []
54
+ };
55
+ currentOptions = found.children;
56
+ },
57
+ _ret2;
58
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
59
+ _ret2 = _loop2();
60
+ if (_ret2) return _ret2.v;
61
+ }
62
+ } catch (err) {
63
+ _iterator2.e(err);
64
+ } finally {
65
+ _iterator2.f();
66
+ }
67
+ return currentOptions;
68
+ };
69
+
70
+ /**
71
+ * 检查路径是否在选中值中
72
+ */
73
+ export var hasSelectedInPath = function hasSelectedInPath(currentValue, currentPath) {
74
+ return currentValue.some(function (selectedPath) {
75
+ if (selectedPath.length < currentPath.length) return false;
76
+ return currentPath.every(function (val, idx) {
77
+ return selectedPath[idx] === val;
78
+ });
79
+ });
80
+ };
81
+
82
+ /**
83
+ * 检查路径是否完全匹配
84
+ */
85
+ export var isExactMatch = function isExactMatch(currentValue, currentPath) {
86
+ return currentValue.some(function (selectedPath) {
87
+ return selectedPath.length === currentPath.length && selectedPath.every(function (val, idx) {
88
+ return val === currentPath[idx];
89
+ });
90
+ });
91
+ };
@@ -177,8 +177,30 @@ var FilterCheckbox = function FilterCheckbox(_ref) {
177
177
  var iconWidth = 10;
178
178
  var iconWidthUnselected = 8;
179
179
  var overlapDistance = 6;
180
- var containerWidth = iconWidth + (options.length - 1) * overlapDistance + 1;
181
- var selectedStatuses = selectedValues || [];
180
+
181
+ // 按颜色分组选项,并检查每种颜色是否有选中的选项
182
+ var colorGroups = [];
183
+ var colorMap = new Map();
184
+ options.forEach(function (option) {
185
+ if (option.color) {
186
+ var isSelected = selectedValues.includes(option.value);
187
+ var existing = colorMap.get(option.color);
188
+ if (existing) {
189
+ // 如果已有该颜色,更新选中状态(只要有一个选中即为选中)
190
+ if (isSelected) {
191
+ existing.hasSelected = true;
192
+ }
193
+ } else {
194
+ var group = {
195
+ color: option.color,
196
+ hasSelected: isSelected
197
+ };
198
+ colorMap.set(option.color, group);
199
+ colorGroups.push(group);
200
+ }
201
+ }
202
+ });
203
+ var containerWidth = iconWidth + (colorGroups.length - 1) * overlapDistance + 1;
182
204
  return /*#__PURE__*/_jsx("div", {
183
205
  style: {
184
206
  position: 'relative',
@@ -187,8 +209,8 @@ var FilterCheckbox = function FilterCheckbox(_ref) {
187
209
  display: 'flex',
188
210
  alignItems: 'center'
189
211
  },
190
- children: options.map(function (item, index) {
191
- var isSelected = selectedStatuses.includes(item.value) && item.color;
212
+ children: colorGroups.map(function (group, index) {
213
+ var isSelected = group.hasSelected;
192
214
  var baseSize = isSelected ? iconWidth : iconWidthUnselected;
193
215
  return isSelected ? /*#__PURE__*/_jsx("div", {
194
216
  style: {
@@ -198,10 +220,10 @@ var FilterCheckbox = function FilterCheckbox(_ref) {
198
220
  height: baseSize,
199
221
  borderRadius: '50%',
200
222
  zIndex: index,
201
- backgroundColor: item.color,
223
+ backgroundColor: group.color,
202
224
  border: "1px solid ".concat(token.white)
203
225
  }
204
- }, item.value) : /*#__PURE__*/_jsx("div", {
226
+ }, group.color) : /*#__PURE__*/_jsx("div", {
205
227
  style: {
206
228
  position: 'absolute',
207
229
  left: index * overlapDistance,
@@ -218,7 +240,7 @@ var FilterCheckbox = function FilterCheckbox(_ref) {
218
240
  border: "1px solid ".concat(token.colorBorderSecondary)
219
241
  }
220
242
  })
221
- }, item.value);
243
+ }, group.color);
222
244
  })
223
245
  });
224
246
  }, [isStatusMode, options, selectedValues, token]);
@@ -67,12 +67,41 @@ var FilterWrap = function FilterWrap(_ref) {
67
67
  };
68
68
  }));
69
69
  }, [collapsed, contextValue.filterValues]);
70
- var filterValues = useMemo(function () {
70
+ var allFilterValues = useMemo(function () {
71
71
  if (!collapsed) return [];
72
72
  return contextValue.filterValues || [];
73
73
  // eslint-disable-next-line react-hooks/exhaustive-deps
74
74
  }, [collapsed, stableFilterValuesKey]);
75
75
 
76
+ // 从 children 中递归提取 label 集合,用于过滤 filterValues 只保留当前折叠项的值
77
+ // children 结构可能是 Fragment → Form.Item → Filter.Select,需要递归查找
78
+ var childLabelSet = useMemo(function () {
79
+ var labels = new Set();
80
+ var extractLabel = function extractLabel(node) {
81
+ if (! /*#__PURE__*/isValidElement(node)) return;
82
+ var props = node.props;
83
+ if (props.label !== undefined) {
84
+ labels.add(props.label);
85
+ return;
86
+ }
87
+ if (props.children) {
88
+ if ( /*#__PURE__*/isValidElement(props.children)) {
89
+ extractLabel(props.children);
90
+ } else if (Array.isArray(props.children)) {
91
+ props.children.forEach(extractLabel);
92
+ }
93
+ }
94
+ };
95
+ Children.forEach(children, extractLabel);
96
+ return labels;
97
+ }, [children]);
98
+ var filterValues = useMemo(function () {
99
+ if (childLabelSet.size === 0) return allFilterValues;
100
+ return allFilterValues.filter(function (item) {
101
+ return childLabelSet.has(item.label);
102
+ });
103
+ }, [allFilterValues, childLabelSet]);
104
+
76
105
  // 格式化值用于 Tooltip 显示
77
106
  var formatValueForTooltip = useCallback(function (value, options, componentName) {
78
107
  if (!value) return '';