@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,284 @@
1
+ "use client";
2
+ 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); }
3
+ 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; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
5
+ 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); }
6
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
7
+ 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."); }
8
+ 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); }
9
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
11
+ 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; }
12
+ import React from 'react';
13
+ import { Flex, Popover } from 'antd';
14
+ import Checkbox from "../../../../checkbox";
15
+ import theme from "../../../../theme";
16
+ import Input from "../../../../input";
17
+ import Empty from "../../../../empty";
18
+ import { CheckOutlined, CloseOutlined, RightOutlined, SearchOutlined } from '@oceanbase/icons';
19
+ import classNames from 'classnames';
20
+ import { getFilterCls } from "../../../style";
21
+ import { MAX_HEIGHT, PADDING_VERTICAL, PADDING_HORIZONTAL, GAP_SIZE_SMALL } from "../constants";
22
+ import { jsx as _jsx } from "react/jsx-runtime";
23
+ import { Fragment as _Fragment } from "react/jsx-runtime";
24
+ import { jsxs as _jsxs } from "react/jsx-runtime";
25
+ /**
26
+ * 非 Flat 模式的级联内容组件
27
+ */
28
+ export var NormalCascaderContent = function NormalCascaderContent(_ref) {
29
+ var options = _ref.options,
30
+ currentValue = _ref.currentValue,
31
+ multiple = _ref.multiple,
32
+ prefixCls = _ref.prefixCls,
33
+ openPopoverKey = _ref.openPopoverKey,
34
+ filterButtonRef = _ref.filterButtonRef,
35
+ onOpenPopoverKeyChange = _ref.onOpenPopoverKeyChange,
36
+ onValueChange = _ref.onValueChange,
37
+ onHandleChange = _ref.onHandleChange,
38
+ onClearByParent = _ref.onClearByParent,
39
+ onSelectAllChildren = _ref.onSelectAllChildren,
40
+ _ref$showSearch = _ref.showSearch,
41
+ showSearch = _ref$showSearch === void 0 ? false : _ref$showSearch,
42
+ _ref$searchKeyword = _ref.searchKeyword,
43
+ searchKeyword = _ref$searchKeyword === void 0 ? '' : _ref$searchKeyword,
44
+ onSearchChange = _ref.onSearchChange;
45
+ var _theme$useToken = theme.useToken(),
46
+ token = _theme$useToken.token;
47
+ return /*#__PURE__*/_jsxs("div", {
48
+ style: {
49
+ padding: PADDING_VERTICAL,
50
+ maxHeight: MAX_HEIGHT,
51
+ overflowY: 'auto'
52
+ },
53
+ children: [showSearch && /*#__PURE__*/_jsx("div", {
54
+ style: {
55
+ marginInline: 12,
56
+ marginBottom: 8
57
+ },
58
+ children: /*#__PURE__*/_jsx(Input, {
59
+ placeholder: "\u641C\u7D22",
60
+ prefix: /*#__PURE__*/_jsx(SearchOutlined, {}),
61
+ allowClear: true,
62
+ value: searchKeyword,
63
+ onChange: function onChange(e) {
64
+ return onSearchChange === null || onSearchChange === void 0 ? void 0 : onSearchChange(e.target.value);
65
+ },
66
+ onClick: function onClick(e) {
67
+ return e.stopPropagation();
68
+ }
69
+ })
70
+ }), options.length === 0 ? /*#__PURE__*/_jsx(Empty, {
71
+ image: Empty.PRESENTED_IMAGE_SIMPLE,
72
+ description: "\u65E0\u5339\u914D\u7ED3\u679C",
73
+ style: {
74
+ padding: '16px 0'
75
+ }
76
+ }) : options.map(function (option) {
77
+ var _option$children;
78
+ var selectedChildren = currentValue.filter(function (item) {
79
+ return item[0] === option.value;
80
+ }).map(function (item) {
81
+ return item[1];
82
+ });
83
+ var hasSelectedChildren = selectedChildren.length > 0;
84
+ var hasChildren = option.children && option.children.length > 0;
85
+ var allChildrenSelected = multiple && hasChildren && selectedChildren.length === option.children.length;
86
+
87
+ // 判断当前节点是否被选中(用于无子节点的情况)
88
+ var isNodeSelected = currentValue.some(function (item) {
89
+ return item[0] === option.value && !item[1];
90
+ });
91
+
92
+ // 处理无子节点的点击事件
93
+ var handleNodeClick = function handleNodeClick() {
94
+ if (option.disabled) {
95
+ return;
96
+ }
97
+ if (!hasChildren) {
98
+ // 无子节点时,直接选中/取消选中该节点
99
+ if (multiple) {
100
+ var isSelected = currentValue.some(function (item) {
101
+ return item[0] === option.value && !item[1];
102
+ });
103
+ if (isSelected) {
104
+ onValueChange(currentValue.filter(function (item) {
105
+ return !(item[0] === option.value && !item[1]);
106
+ }));
107
+ } else {
108
+ onValueChange([].concat(_toConsumableArray(currentValue), [[option.value, '']]));
109
+ }
110
+ } else {
111
+ var _isSelected = currentValue.some(function (item) {
112
+ return item[0] === option.value && !item[1];
113
+ });
114
+ if (_isSelected) {
115
+ onValueChange([]);
116
+ } else {
117
+ onValueChange([[option.value, '']]);
118
+ }
119
+ onOpenPopoverKeyChange(null);
120
+ setTimeout(function () {
121
+ var _filterButtonRef$curr;
122
+ (_filterButtonRef$curr = filterButtonRef.current) === null || _filterButtonRef$curr === void 0 || _filterButtonRef$curr.closePopover();
123
+ }, 0);
124
+ }
125
+ }
126
+ };
127
+
128
+ // 没有子节点时,直接渲染节点项,不使用 Popover
129
+ if (!hasChildren) {
130
+ return /*#__PURE__*/_jsx("div", {
131
+ style: {
132
+ padding: PADDING_HORIZONTAL
133
+ },
134
+ children: /*#__PURE__*/_jsx(Flex, {
135
+ gap: GAP_SIZE_SMALL * 2,
136
+ className: classNames(getFilterCls(prefixCls, 'select-option'), _defineProperty({}, getFilterCls(prefixCls, 'has-selected'), isNodeSelected)),
137
+ justify: "space-between",
138
+ align: "center",
139
+ onClick: handleNodeClick,
140
+ style: {
141
+ cursor: option.disabled ? 'not-allowed' : 'pointer',
142
+ color: option.disabled ? token.colorTextDisabled : 'inherit'
143
+ },
144
+ children: multiple ? /*#__PURE__*/_jsx(Checkbox, {
145
+ checked: isNodeSelected,
146
+ disabled: option.disabled,
147
+ children: /*#__PURE__*/_jsx("span", {
148
+ className: getFilterCls(prefixCls, 'text-ellipsis'),
149
+ children: option.label
150
+ })
151
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
152
+ children: [/*#__PURE__*/_jsx("div", {
153
+ className: getFilterCls(prefixCls, 'text-ellipsis'),
154
+ children: option.label
155
+ }), /*#__PURE__*/_jsx("span", {
156
+ children: isNodeSelected && /*#__PURE__*/_jsx(CheckOutlined, {
157
+ style: {
158
+ color: token.colorPrimary
159
+ }
160
+ })
161
+ })]
162
+ })
163
+ })
164
+ }, option.value);
165
+ }
166
+
167
+ // 有子节点时,使用 Popover
168
+ return /*#__PURE__*/_jsx(Popover, {
169
+ placement: "rightTop",
170
+ trigger: 'hover',
171
+ arrow: false,
172
+ open: option !== null && option !== void 0 && option.disabled ? false : multiple ? undefined : openPopoverKey === option.value,
173
+ onOpenChange: multiple ? undefined : function (open) {
174
+ if (!open) {
175
+ onOpenPopoverKeyChange(null);
176
+ } else {
177
+ onOpenPopoverKeyChange(option.value);
178
+ }
179
+ },
180
+ content: (_option$children = option.children) === null || _option$children === void 0 ? void 0 : _option$children.map(function (child) {
181
+ var isSelected = selectedChildren.includes(child.value);
182
+ var isChildDisabled = child.disabled || false;
183
+ return /*#__PURE__*/_jsx(Flex, {
184
+ gap: GAP_SIZE_SMALL * 2,
185
+ className: getFilterCls(prefixCls, 'select-option'),
186
+ justify: "space-between",
187
+ onClick: function onClick(e) {
188
+ e.stopPropagation();
189
+ if (!isChildDisabled) {
190
+ onHandleChange(option.value, child.value);
191
+ }
192
+ },
193
+ style: {
194
+ cursor: isChildDisabled ? 'not-allowed' : 'pointer',
195
+ color: isChildDisabled ? token.colorTextDisabled : 'inherit'
196
+ },
197
+ children: multiple ? /*#__PURE__*/_jsx(Checkbox, {
198
+ checked: isSelected,
199
+ disabled: isChildDisabled,
200
+ children: /*#__PURE__*/_jsx("span", {
201
+ className: getFilterCls(prefixCls, 'text-ellipsis'),
202
+ children: child.label
203
+ })
204
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
205
+ children: [/*#__PURE__*/_jsx("span", {
206
+ className: getFilterCls(prefixCls, 'text-ellipsis'),
207
+ children: child.label
208
+ }), /*#__PURE__*/_jsx("span", {
209
+ children: isSelected && /*#__PURE__*/_jsx(CheckOutlined, {
210
+ style: {
211
+ color: token.colorPrimary
212
+ }
213
+ })
214
+ })]
215
+ })
216
+ }, child.value);
217
+ }),
218
+ styles: {
219
+ body: {
220
+ padding: 8,
221
+ maxHeight: 220,
222
+ maxWidth: 300,
223
+ overflowY: 'auto'
224
+ }
225
+ },
226
+ children: /*#__PURE__*/_jsx("div", {
227
+ style: {
228
+ padding: PADDING_HORIZONTAL
229
+ },
230
+ children: /*#__PURE__*/_jsxs(Flex, {
231
+ gap: GAP_SIZE_SMALL * 2,
232
+ className: classNames(getFilterCls(prefixCls, 'select-option'), _defineProperty({}, getFilterCls(prefixCls, 'has-selected'), hasSelectedChildren)),
233
+ justify: "space-between",
234
+ align: "center",
235
+ style: {
236
+ cursor: option.disabled ? 'not-allowed' : 'pointer',
237
+ color: option.disabled ? token.colorTextDisabled : 'inherit'
238
+ },
239
+ children: [multiple ? /*#__PURE__*/_jsx(Checkbox, {
240
+ checked: allChildrenSelected,
241
+ indeterminate: hasSelectedChildren && !allChildrenSelected,
242
+ disabled: option.disabled,
243
+ onClick: function onClick(e) {
244
+ return e.stopPropagation();
245
+ },
246
+ onChange: function onChange() {
247
+ if (!option.disabled) {
248
+ if (allChildrenSelected) {
249
+ onClearByParent(option.value);
250
+ } else {
251
+ onSelectAllChildren(option);
252
+ }
253
+ }
254
+ },
255
+ children: /*#__PURE__*/_jsx("span", {
256
+ className: getFilterCls(prefixCls, 'text-ellipsis'),
257
+ children: option.label
258
+ })
259
+ }) : /*#__PURE__*/_jsx("div", {
260
+ className: getFilterCls(prefixCls, 'text-ellipsis'),
261
+ children: option.label
262
+ }), /*#__PURE__*/_jsx(Flex, {
263
+ align: "center",
264
+ gap: GAP_SIZE_SMALL,
265
+ children: /*#__PURE__*/_jsxs("div", {
266
+ className: getFilterCls(prefixCls, 'icon-wrapper'),
267
+ children: [/*#__PURE__*/_jsx(RightOutlined, {
268
+ className: hasSelectedChildren ? getFilterCls(prefixCls, 'arrow-icon') : ''
269
+ }), hasSelectedChildren && /*#__PURE__*/_jsx("div", {
270
+ className: getFilterCls(prefixCls, 'clear-icon'),
271
+ onClick: function onClick(e) {
272
+ e.stopPropagation();
273
+ onClearByParent(option.value);
274
+ },
275
+ children: /*#__PURE__*/_jsx(CloseOutlined, {})
276
+ })]
277
+ })
278
+ })]
279
+ })
280
+ })
281
+ }, option.value);
282
+ })]
283
+ });
284
+ };
@@ -0,0 +1,7 @@
1
+ export declare const COLUMN_WIDTH = 200;
2
+ export declare const MAX_HEIGHT = 300;
3
+ export declare const PADDING_VERTICAL = "8px 0px";
4
+ export declare const PADDING_HORIZONTAL = "0px 8px";
5
+ export declare const ICON_SIZE = 12;
6
+ export declare const GAP_SIZE = 8;
7
+ export declare const GAP_SIZE_SMALL = 4;
@@ -0,0 +1,8 @@
1
+ // 样式常量
2
+ export var COLUMN_WIDTH = 200;
3
+ export var MAX_HEIGHT = 300;
4
+ export var PADDING_VERTICAL = '8px 0px';
5
+ export var PADDING_HORIZONTAL = '0px 8px';
6
+ export var ICON_SIZE = 12;
7
+ export var GAP_SIZE = 8;
8
+ export var GAP_SIZE_SMALL = 4;
@@ -0,0 +1,12 @@
1
+ import type { CascaderOption } from '../types';
2
+ import type { FilterButtonRef } from '../../FilterButton';
3
+ /**
4
+ * 管理级联选择器的所有回调函数
5
+ */
6
+ export declare const useCascaderCallbacks: (currentValue: string[][], setValue: (value: string[][]) => void, options: CascaderOption[], multiple: boolean, filterButtonRef: React.RefObject<FilterButtonRef>, setOpenPopoverKey: (key: string | null) => void) => {
7
+ handleChange: (parentValue: string, childValue: string) => void;
8
+ clearByParent: (parentValue: string) => void;
9
+ handleClear: () => void;
10
+ selectAllChildren: (option: CascaderOption) => void;
11
+ handleRemoveTag: (tagValue: string) => void;
12
+ };
@@ -0,0 +1,101 @@
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
+ import { useCallback } from 'react';
8
+ /**
9
+ * 管理级联选择器的所有回调函数
10
+ */
11
+ export var useCascaderCallbacks = function useCascaderCallbacks(currentValue, setValue, options, multiple, filterButtonRef, setOpenPopoverKey) {
12
+ var handleChange = useCallback(function (parentValue, childValue) {
13
+ var _parentOption$childre;
14
+ var parentOption = options.find(function (opt) {
15
+ return opt.value === parentValue;
16
+ });
17
+ var childOption = parentOption === null || parentOption === void 0 || (_parentOption$childre = parentOption.children) === null || _parentOption$childre === void 0 ? void 0 : _parentOption$childre.find(function (child) {
18
+ return child.value === childValue;
19
+ });
20
+ if (parentOption !== null && parentOption !== void 0 && parentOption.disabled || childOption !== null && childOption !== void 0 && childOption.disabled) {
21
+ return;
22
+ }
23
+ if (multiple) {
24
+ var existingIndex = currentValue.findIndex(function (item) {
25
+ return item[0] === parentValue && item[1] === childValue;
26
+ });
27
+ var newValueList;
28
+ if (existingIndex !== -1) {
29
+ newValueList = currentValue.filter(function (_, index) {
30
+ return index !== existingIndex;
31
+ });
32
+ } else {
33
+ newValueList = [].concat(_toConsumableArray(currentValue), [[parentValue, childValue]]);
34
+ }
35
+ setValue(newValueList);
36
+ } else {
37
+ var isCurrentSelected = currentValue.length === 1 && currentValue[0][0] === parentValue && currentValue[0][1] === childValue;
38
+ var _newValueList;
39
+ if (isCurrentSelected) {
40
+ _newValueList = [];
41
+ } else {
42
+ _newValueList = [[parentValue, childValue]];
43
+ }
44
+ setValue(_newValueList);
45
+ setOpenPopoverKey(null);
46
+ setTimeout(function () {
47
+ var _filterButtonRef$curr;
48
+ (_filterButtonRef$curr = filterButtonRef.current) === null || _filterButtonRef$curr === void 0 || _filterButtonRef$curr.closePopover();
49
+ }, 0);
50
+ }
51
+ }, [currentValue, multiple, setValue, options, filterButtonRef, setOpenPopoverKey]);
52
+ var clearByParent = useCallback(function (parentValue) {
53
+ var newValueList = currentValue.filter(function (item) {
54
+ return item[0] !== parentValue;
55
+ });
56
+ setValue(newValueList);
57
+ }, [currentValue, setValue]);
58
+ var handleClear = useCallback(function () {
59
+ setValue([]);
60
+ }, [setValue]);
61
+ var selectAllChildren = useCallback(function (option) {
62
+ var _option$children;
63
+ if (option.disabled) {
64
+ return;
65
+ }
66
+ var otherValues = currentValue.filter(function (item) {
67
+ return item[0] !== option.value;
68
+ });
69
+ var allChildValues = ((_option$children = option.children) === null || _option$children === void 0 ? void 0 : _option$children.filter(function (child) {
70
+ return !child.disabled;
71
+ }).map(function (child) {
72
+ return [option.value, child.value];
73
+ })) || [];
74
+ var newValueList = [].concat(_toConsumableArray(otherValues), _toConsumableArray(allChildValues));
75
+ setValue(newValueList);
76
+ }, [currentValue, setValue]);
77
+
78
+ // 移除某个选中的值
79
+ var handleRemoveTag = useCallback(function (tagValue) {
80
+ // tagValue 格式:path1::path2::path3::index
81
+ var parts = tagValue.split('::');
82
+ if (parts.length >= 2) {
83
+ var pathParts = parts.slice(0, -1); // 移除最后的 index
84
+
85
+ var newValueList = currentValue.filter(function (item) {
86
+ if (item.length !== pathParts.length) return true;
87
+ return !item.every(function (val, idx) {
88
+ return val === pathParts[idx];
89
+ });
90
+ });
91
+ setValue(newValueList);
92
+ }
93
+ }, [currentValue, setValue]);
94
+ return {
95
+ handleChange: handleChange,
96
+ clearByParent: clearByParent,
97
+ handleClear: handleClear,
98
+ selectAllChildren: selectAllChildren,
99
+ handleRemoveTag: handleRemoveTag
100
+ };
101
+ };
@@ -0,0 +1,9 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { CascaderOption, SelectedTag } from '../types';
3
+ /**
4
+ * 管理级联选择器的标签显示逻辑
5
+ */
6
+ export declare const useCascaderLabels: (currentValue: string[][], options: CascaderOption[], label: ReactNode, multiple: boolean, isCollapsed: boolean) => {
7
+ getSelectedLabel: () => ReactNode;
8
+ getSelectedTags: () => SelectedTag[];
9
+ };
@@ -0,0 +1,50 @@
1
+ import { useCallback } from 'react';
2
+ import { findOptionByPath } from "../utils/pathUtils";
3
+
4
+ /**
5
+ * 管理级联选择器的标签显示逻辑
6
+ */
7
+ export var useCascaderLabels = function useCascaderLabels(currentValue, options, label, multiple, isCollapsed) {
8
+ // 获取当前选中值的 label(用于单选模式显示)
9
+ var getSelectedLabel = useCallback(function () {
10
+ if (isCollapsed && currentValue.length === 0) {
11
+ return '';
12
+ }
13
+ if (currentValue.length === 0) {
14
+ return label;
15
+ }
16
+ if (!multiple && currentValue.length === 1) {
17
+ var selectedPath = currentValue[0];
18
+
19
+ // 如果是空路径
20
+ if (!selectedPath || selectedPath.length === 0) {
21
+ return label;
22
+ }
23
+
24
+ // 对于多层级路径,查找最后一个节点
25
+ var currentOption = findOptionByPath(options, selectedPath);
26
+ return (currentOption === null || currentOption === void 0 ? void 0 : currentOption.label) || label;
27
+ }
28
+ return label;
29
+ }, [currentValue, isCollapsed, label, multiple, options]);
30
+
31
+ // 获取选中值的 tags(用于多选模式 Tag 显示)
32
+ var getSelectedTags = useCallback(function () {
33
+ return currentValue.map(function (selectedPath, index) {
34
+ // 对于多层级路径,查找最后一个节点
35
+ var currentOption = findOptionByPath(options, selectedPath);
36
+ var displayLabel = (currentOption === null || currentOption === void 0 ? void 0 : currentOption.label) || selectedPath[selectedPath.length - 1];
37
+ var valueKey = selectedPath.join('::') + "::".concat(index);
38
+ return {
39
+ label: displayLabel,
40
+ value: valueKey,
41
+ parentValue: selectedPath[0],
42
+ childValue: selectedPath[selectedPath.length - 1]
43
+ };
44
+ });
45
+ }, [currentValue, options]);
46
+ return {
47
+ getSelectedLabel: getSelectedLabel,
48
+ getSelectedTags: getSelectedTags
49
+ };
50
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 管理级联选择器的值,处理单选/多选格式转换
3
+ */
4
+ export declare const useNormalizedValue: (value: string[] | string[][] | undefined, onChange: ((value: string[]) => void) | ((value: string[][]) => void), multiple: boolean) => {
5
+ currentValue: string[][];
6
+ setValue: (newValue: string[][]) => void;
7
+ };
@@ -0,0 +1,53 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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."); }
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 _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; }
5
+ 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; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useCallback, useEffect, useState } from 'react';
8
+
9
+ /**
10
+ * 管理级联选择器的值,处理单选/多选格式转换
11
+ */
12
+ export var useNormalizedValue = function useNormalizedValue(value, onChange, multiple) {
13
+ var normalizeValue = useCallback(function (val) {
14
+ if (!val) return [];
15
+ if (val.length === 0) return [];
16
+ // 判断是否为单选格式 string[]
17
+ if (!multiple && val.length > 0 && typeof val[0] === 'string') {
18
+ return [val];
19
+ }
20
+ return val;
21
+ }, [multiple]);
22
+ var denormalizeValue = useCallback(function (val) {
23
+ if (!multiple && val.length > 0) {
24
+ return val[0]; // 单选模式返回 string[]
25
+ }
26
+ return val; // 多选模式返回 string[][]
27
+ }, [multiple]);
28
+
29
+ // 使用受控状态 hook,内部统一使用 string[][] 格式
30
+ var _useState = useState(function () {
31
+ return normalizeValue(value);
32
+ }),
33
+ _useState2 = _slicedToArray(_useState, 2),
34
+ internalValue = _useState2[0],
35
+ setInternalValue = _useState2[1];
36
+
37
+ // 同步外部 value 到内部
38
+ useEffect(function () {
39
+ setInternalValue(normalizeValue(value));
40
+ }, [value, normalizeValue]);
41
+
42
+ // 内部 setValue 包装函数
43
+ var setValue = useCallback(function (newValue) {
44
+ setInternalValue(newValue);
45
+ if (onChange) {
46
+ onChange(denormalizeValue(newValue));
47
+ }
48
+ }, [onChange, denormalizeValue]);
49
+ return {
50
+ currentValue: internalValue,
51
+ setValue: setValue
52
+ };
53
+ };
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import type { FilterCascaderProps } from './types';
3
+ declare const FilterCascader: React.FC<FilterCascaderProps>;
4
+ export type { FilterCascaderProps, CascaderOption } from './types';
5
+ export default FilterCascader;