@kne/react-filter 1.0.5 → 1.0.7

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.
@@ -1,5 +1,5 @@
1
1
  import classnames from 'classnames';
2
- import { useContext as useContext$1, createContext, useState, useEffect, useRef, useCallback, createElement, useMemo } from 'react';
2
+ import { useContext as useContext$1, createContext, useState, useEffect, useRef, useCallback, useLayoutEffect, useMemo, createElement } from 'react';
3
3
  import { Space, Row, Col, Tag, Button, Dropdown, Input, InputNumber, DatePicker, Flex, Select, App } from 'antd';
4
4
  import { useIntl, createWithIntlProvider } from '@kne/react-intl';
5
5
  import get from 'lodash/get';
@@ -8,8 +8,9 @@ import { UpOutlined, DownOutlined } from '@ant-design/icons';
8
8
  import clone from 'lodash/clone';
9
9
  import { createPortal } from 'react-dom';
10
10
  import isNumber from 'lodash/isNumber';
11
- import SuperSelect from '@kne/super-select';
11
+ import SuperSelect, { SelectTableList, SelectTree, SelectCascader } from '@kne/super-select';
12
12
  import { SelectFunction, SelectIndustry, SelectAddress, createAddressApi } from '@kne/super-select-plus';
13
+ import '@kne/super-select/dist/index.css';
13
14
  import '@kne/super-select-plus/dist/index.css';
14
15
  import dayjs from 'dayjs';
15
16
  import transform from 'lodash/transform';
@@ -35,7 +36,7 @@ function _objectWithoutPropertiesLoose(r, e) {
35
36
  return t;
36
37
  }
37
38
 
38
- var style$1 = {"filter":"kne-react-filter_b3gMw","filter-item-icon":"kne-react-filter_e3V6h","filter-item-option-icon":"kne-react-filter_dLoYj","filter-title":"kne-react-filter_khFt2","filter-title-hidden":"kne-react-filter_j2mP1","ad-filter-title":"kne-react-filter_HptIY","ad-filter-line":"kne-react-filter_7Ob6-","filter-line":"kne-react-filter_Y9XTa","clean-btn":"kne-react-filter_CJ935","filter-item":"kne-react-filter_JpaMr","un-expand":"kne-react-filter_LfQME","ad-filter-selected":"kne-react-filter_pBsaE","filter-label":"kne-react-filter_Bx3s8","filter-item-wrap":"kne-react-filter_Co4Pg","option":"kne-react-filter_G1cRp","is-active":"kne-react-filter_Aab98","is-visited":"kne-react-filter_Ww12R","un-expand-shadow":"kne-react-filter_2ExqW","filter-item-label":"kne-react-filter_JAmeE","filter-item-field":"kne-react-filter_WvRvl","filter-drop-tag":"kne-react-filter_dG8rq","filter-list":"kne-react-filter_qlWu6","filter-list-scroll-wrap":"kne-react-filter_oaIF4","filter-list-scroll":"kne-react-filter_Jq43Q","filter-scroll-next":"kne-react-filter_BdfSI","filter-list-tag":"kne-react-filter_LV2VI","filter-tag":"kne-react-filter_yyR3u","filter-tag-value":"kne-react-filter_8nm8n","filter-value-tag":"kne-react-filter_tWyCr","filter-value-tag-label":"kne-react-filter_XPzrL","filter-value-tag-content":"kne-react-filter_6e79l","filter-value-display-content":"kne-react-filter_v2dnw","filter-value-tags-wrap":"kne-react-filter_J1wBU","filter-value-tags":"kne-react-filter_rRhFE","filter-value-actions":"kne-react-filter_-Brt9","filter-value-toggle":"kne-react-filter_WuL0c","pop-util-content":"kne-react-filter_g-hXk","pop-util-body":"kne-react-filter_4n4MP","date-range-picker-popup":"kne-react-filter_6Zx60","pop-util-overlay":"kne-react-filter_m7Csi","pop-util-mask":"kne-react-filter_o2B3k","pop-util-mask-fade-in":"kne-react-filter_oCXiX","pop-util-mask-leave":"kne-react-filter_qGnRO","pop-util-mask-fade-out":"kne-react-filter_cDx1y","field-item-mobile-popup":"kne-react-filter_wq5nf","pop-util-mobile-expand-down":"kne-react-filter_6RxjE","date-picker-popup":"kne-react-filter_iwLs2","pop-util-mobile-collapse-up":"kne-react-filter_009r-","pop-util-footer":"kne-react-filter_iqe8W","pop-util-text":"kne-react-filter_72gGQ","filter-item-inner":"kne-react-filter_cYX12","filter-item-text":"kne-react-filter_cnMY-","filter-item-number-range":"kne-react-filter_Cv2Bw","filter-item-custom":"kne-react-filter_CBczA","filter-item-custom-active":"kne-react-filter_ldxUR","filter-item-number-range-split":"kne-react-filter_4p3C9","filter-item-number-input":"kne-react-filter_yy1y1","range-picker":"kne-react-filter_81zQn","cascader-select-wrap":"kne-react-filter_UHBfi","cascader-dropdown-menu":"kne-react-filter_bY8JQ","filter-advanced":"kne-react-filter_rg45N","filter-advanced-item-other":"kne-react-filter_HcsA8","filter-advanced-item-other-inner":"kne-react-filter_4Bqtz","filter-advanced-more":"kne-react-filter_jVH7z","filter-value-display":"kne-react-filter_8-R34","is-not-overflow":"kne-react-filter_TM1E2","is-expand":"kne-react-filter_7aclr","filter-value-scroll-prev-shadow":"kne-react-filter_C1t-q","filter-value-scroll-next-shadow":"kne-react-filter_ZFoeL","is-overflow":"kne-react-filter_GhFCl","filter-value-action-placeholder":"kne-react-filter_wGZp6","filter-value-action-right":"kne-react-filter_vyPwo","filter-scroll-prev-shadow":"kne-react-filter_fyhz3","filter-scroll-next-icon":"kne-react-filter_Fd6ab"};
39
+ var style$1 = {"filter":"kne-react-filter_b3gMw","filter-item-icon":"kne-react-filter_e3V6h","filter-item-option-icon":"kne-react-filter_dLoYj","filter-title":"kne-react-filter_khFt2","filter-title-hidden":"kne-react-filter_j2mP1","ad-filter-title":"kne-react-filter_HptIY","ad-filter-line":"kne-react-filter_7Ob6-","filter-line":"kne-react-filter_Y9XTa","clean-btn":"kne-react-filter_CJ935","filter-item":"kne-react-filter_JpaMr","un-expand":"kne-react-filter_LfQME","ad-filter-selected":"kne-react-filter_pBsaE","filter-label":"kne-react-filter_Bx3s8","filter-line-nowrap":"kne-react-filter_Ccx24","filter-line-measure":"kne-react-filter_uMXzo","filter-item-wrap":"kne-react-filter_Co4Pg","option":"kne-react-filter_G1cRp","is-active":"kne-react-filter_Aab98","is-visited":"kne-react-filter_Ww12R","un-expand-shadow":"kne-react-filter_2ExqW","filter-item-label":"kne-react-filter_JAmeE","filter-item-field":"kne-react-filter_WvRvl","filter-drop-tag":"kne-react-filter_dG8rq","filter-list":"kne-react-filter_qlWu6","filter-list-scroll-wrap":"kne-react-filter_oaIF4","filter-list-constrained":"kne-react-filter_3gXxO","filter-list-scroll":"kne-react-filter_Jq43Q","filter-scroll-next":"kne-react-filter_BdfSI","filter-list-tag":"kne-react-filter_LV2VI","filter-tag":"kne-react-filter_yyR3u","filter-tag-value":"kne-react-filter_8nm8n","filter-value-tag":"kne-react-filter_tWyCr","filter-value-tag-label":"kne-react-filter_XPzrL","filter-value-tag-content":"kne-react-filter_6e79l","filter-value-display-content":"kne-react-filter_v2dnw","filter-value-tags-wrap":"kne-react-filter_J1wBU","filter-value-tags":"kne-react-filter_rRhFE","filter-value-actions":"kne-react-filter_-Brt9","filter-value-toggle":"kne-react-filter_WuL0c","pop-util-content":"kne-react-filter_g-hXk","pop-util-body":"kne-react-filter_4n4MP","date-range-picker-popup":"kne-react-filter_6Zx60","pop-util-overlay":"kne-react-filter_m7Csi","pop-util-mask":"kne-react-filter_o2B3k","pop-util-mask-fade-in":"kne-react-filter_oCXiX","pop-util-mask-leave":"kne-react-filter_qGnRO","pop-util-mask-fade-out":"kne-react-filter_cDx1y","field-item-mobile-popup":"kne-react-filter_wq5nf","pop-util-mobile-expand-down":"kne-react-filter_6RxjE","date-picker-popup":"kne-react-filter_iwLs2","pop-util-mobile-collapse-up":"kne-react-filter_009r-","pop-util-footer":"kne-react-filter_iqe8W","pop-util-text":"kne-react-filter_72gGQ","filter-item-inner":"kne-react-filter_cYX12","filter-item-text":"kne-react-filter_cnMY-","filter-item-number-range":"kne-react-filter_Cv2Bw","filter-item-custom":"kne-react-filter_CBczA","filter-item-custom-active":"kne-react-filter_ldxUR","filter-item-number-range-split":"kne-react-filter_4p3C9","filter-item-number-input":"kne-react-filter_yy1y1","range-picker":"kne-react-filter_81zQn","cascader-select-wrap":"kne-react-filter_UHBfi","cascader-dropdown-menu":"kne-react-filter_bY8JQ","filter-advanced":"kne-react-filter_rg45N","filter-advanced-item-other":"kne-react-filter_HcsA8","filter-advanced-item-other-inner":"kne-react-filter_4Bqtz","filter-advanced-more":"kne-react-filter_jVH7z","filter-value-display":"kne-react-filter_8-R34","is-not-overflow":"kne-react-filter_TM1E2","is-expand":"kne-react-filter_7aclr","filter-value-scroll-prev-shadow":"kne-react-filter_C1t-q","filter-value-scroll-next-shadow":"kne-react-filter_ZFoeL","is-overflow":"kne-react-filter_GhFCl","filter-value-action-placeholder":"kne-react-filter_wGZp6","filter-value-action-right":"kne-react-filter_vyPwo","filter-scroll-prev-shadow":"kne-react-filter_fyhz3","filter-scroll-next-icon":"kne-react-filter_Fd6ab"};
39
40
 
40
41
  const context = /*#__PURE__*/createContext({});
41
42
  const {
@@ -115,54 +116,293 @@ const useHorizontalScrollShadows = ({
115
116
  };
116
117
  };
117
118
 
118
- const Line$1 = ({
119
- list,
120
- children
119
+ const GAP = 8;
120
+ const SAFETY_GAP = 2;
121
+ const useVisibleItemCount = ({
122
+ items,
123
+ enabled,
124
+ strategy: _strategy = 'asc'
121
125
  }) => {
126
+ const safeItems = Array.isArray(items) ? items : [];
127
+ const containerRef = useRef(null);
128
+ const measureRef = useRef(null);
129
+ const moreMeasureRef = useRef(null);
130
+ const rafRef = useRef(null);
131
+ const lastWidthRef = useRef(0);
132
+ const [containerEl, setContainerEl] = useState(null);
133
+ const [visibleCount, setVisibleCount] = useState(() => safeItems.length > 0 ? 1 : 0);
134
+ const setContainerRef = useCallback(node => {
135
+ containerRef.current = node;
136
+ setContainerEl(node || null);
137
+ }, []);
138
+ const setMeasureRef = useCallback(node => {
139
+ measureRef.current = node;
140
+ }, []);
141
+ const setMoreMeasureRef = useCallback(node => {
142
+ moreMeasureRef.current = node;
143
+ }, []);
144
+ const getWidths = useCallback(() => {
145
+ var _moreMeasureRef$curre;
146
+ const container = containerRef.current;
147
+ const measureEl = measureRef.current;
148
+ if (!container || !measureEl) {
149
+ return null;
150
+ }
151
+ const containerWidth = container.clientWidth;
152
+ if (containerWidth <= 0) {
153
+ return null;
154
+ }
155
+ const itemNodes = measureEl.querySelectorAll('[data-filter-measure-item]');
156
+ if (!itemNodes.length) {
157
+ return null;
158
+ }
159
+ const moreButtonWidth = ((_moreMeasureRef$curre = moreMeasureRef.current) == null ? void 0 : _moreMeasureRef$curre.getBoundingClientRect().width) || 0;
160
+ if (safeItems.length > 1 && moreButtonWidth <= 0) {
161
+ return null;
162
+ }
163
+ const itemWidths = Array.from(itemNodes, node => node.getBoundingClientRect().width);
164
+ return {
165
+ containerWidth,
166
+ itemWidths,
167
+ moreButtonWidth
168
+ };
169
+ }, [safeItems.length]);
170
+ const getWidthForCount = useCallback((itemWidths, moreButtonWidth, count) => {
171
+ let usedWidth = 0;
172
+ for (let i = 0; i < count; i++) {
173
+ usedWidth += itemWidths[i] + (i > 0 ? GAP : 0);
174
+ }
175
+ if (count < safeItems.length) {
176
+ usedWidth += GAP + moreButtonWidth;
177
+ }
178
+ return usedWidth;
179
+ }, [safeItems.length]);
180
+ const resolveVisibleCount = useCallback(widths => {
181
+ const {
182
+ containerWidth,
183
+ itemWidths,
184
+ moreButtonWidth
185
+ } = widths;
186
+ const maxCount = Math.min(safeItems.length, itemWidths.length);
187
+ let count = 1;
188
+ if (_strategy === 'desc') {
189
+ count = maxCount;
190
+ while (count > 1) {
191
+ const usedWidth = getWidthForCount(itemWidths, moreButtonWidth, count);
192
+ if (usedWidth + SAFETY_GAP <= containerWidth) {
193
+ break;
194
+ }
195
+ count -= 1;
196
+ }
197
+ } else {
198
+ count = 1;
199
+ while (count < maxCount) {
200
+ const nextCount = count + 1;
201
+ const usedWidth = getWidthForCount(itemWidths, moreButtonWidth, nextCount);
202
+ if (usedWidth + SAFETY_GAP > containerWidth) {
203
+ break;
204
+ }
205
+ count = nextCount;
206
+ }
207
+ }
208
+ return Math.max(1, count);
209
+ }, [getWidthForCount, safeItems.length, _strategy]);
210
+ const calculateByWidth = useCallback(() => {
211
+ if (!enabled || !safeItems.length) {
212
+ setVisibleCount(prev => prev === safeItems.length ? prev : safeItems.length);
213
+ return;
214
+ }
215
+ const widths = getWidths();
216
+ if (!widths) {
217
+ return;
218
+ }
219
+ const nextCount = resolveVisibleCount(widths);
220
+ setVisibleCount(prev => prev === nextCount ? prev : nextCount);
221
+ }, [enabled, getWidths, safeItems.length, resolveVisibleCount]);
222
+ const scheduleCalculate = useCallback(() => {
223
+ if (rafRef.current) {
224
+ window.cancelAnimationFrame(rafRef.current);
225
+ }
226
+ rafRef.current = window.requestAnimationFrame(() => {
227
+ rafRef.current = null;
228
+ calculateByWidth();
229
+ });
230
+ }, [calculateByWidth]);
231
+ useLayoutEffect(() => {
232
+ scheduleCalculate();
233
+ return () => {
234
+ if (rafRef.current) {
235
+ window.cancelAnimationFrame(rafRef.current);
236
+ rafRef.current = null;
237
+ }
238
+ };
239
+ }, [safeItems, scheduleCalculate]);
240
+ useEffect(() => {
241
+ if (!enabled || !containerEl) {
242
+ return undefined;
243
+ }
244
+ const observer = new ResizeObserver(entries => {
245
+ var _entry$contentRect$wi;
246
+ const entry = entries.find(item => item.target === containerEl);
247
+ const nextWidth = (_entry$contentRect$wi = entry == null ? void 0 : entry.contentRect.width) != null ? _entry$contentRect$wi : containerEl.clientWidth;
248
+ if (Math.abs(nextWidth - lastWidthRef.current) < 1) {
249
+ return;
250
+ }
251
+ lastWidthRef.current = nextWidth;
252
+ scheduleCalculate();
253
+ });
254
+ lastWidthRef.current = containerEl.clientWidth;
255
+ observer.observe(containerEl);
256
+ window.addEventListener('resize', scheduleCalculate);
257
+ return () => {
258
+ observer.disconnect();
259
+ window.removeEventListener('resize', scheduleCalculate);
260
+ if (rafRef.current) {
261
+ window.cancelAnimationFrame(rafRef.current);
262
+ rafRef.current = null;
263
+ }
264
+ };
265
+ }, [containerEl, enabled, scheduleCalculate]);
266
+ return {
267
+ setContainerRef,
268
+ setMeasureRef,
269
+ setMoreMeasureRef,
270
+ visibleCount
271
+ };
272
+ };
273
+
274
+ const isFilterListItem = item => {
275
+ if (!item) return false;
276
+ if (typeof item === 'function') return true;
277
+ return !!item.type;
278
+ };
279
+ const isNestedFilterList = list => {
280
+ if (!Array.isArray(list) || list.length === 0) return false;
281
+ return Array.isArray(list[0]) && !isFilterListItem(list[0]);
282
+ };
283
+ const normalizeFilterList = list => {
284
+ const safeList = Array.isArray(list) ? list : [];
285
+ if (!safeList.length) {
286
+ return {
287
+ mode: 'flat',
288
+ items: [],
289
+ lines: []
290
+ };
291
+ }
292
+ if (isNestedFilterList(safeList)) {
293
+ return {
294
+ mode: 'nested',
295
+ items: [],
296
+ lines: safeList
297
+ };
298
+ }
299
+ return {
300
+ mode: 'flat',
301
+ items: safeList,
302
+ lines: []
303
+ };
304
+ };
305
+ const getMobileFilterList = list => {
306
+ const {
307
+ mode,
308
+ items,
309
+ lines
310
+ } = normalizeFilterList(list);
311
+ if (mode === 'flat') return items;
312
+ return lines.reduce((result, line) => result.concat(line), []);
313
+ };
314
+
315
+ const isValidFilterItem = item => !!item && (item.type || typeof item === 'function');
316
+ const useFilterItemRenderer = () => {
122
317
  const {
123
318
  value,
124
319
  onChange
125
320
  } = useContext();
126
- return /*#__PURE__*/jsxs("div", {
127
- className: style$1['filter-line'],
128
- children: [list.filter(item => !!item.type).map((item, index) => {
129
- if (typeof item === 'function') {
130
- return item(props => {
131
- return {
132
- index,
133
- value: value ? get(value.get(props == null ? void 0 : props.name), 'value') : props == null ? void 0 : props.value,
134
- onChange: onChange ? value => onChange({
135
- name: props == null ? void 0 : props.name,
136
- label: props == null ? void 0 : props.label,
137
- value
138
- }) : props == null ? void 0 : props.onChange
139
- };
140
- });
141
- }
142
- const ComponentItem = item.type;
143
- return /*#__PURE__*/createElement(ComponentItem, _extends({}, Object.assign({}, item.props, {
144
- value: value ? get(value.get(item.props.name), 'value') : item.props.value,
145
- onChange: onChange ? value => onChange({
146
- name: item.props.name,
147
- label: item.props.label,
148
- value
149
- }) : item.props.onChange
150
- }), {
151
- key: item.key || item.props.name || index
321
+ return useCallback((item, index) => {
322
+ if (typeof item === 'function') {
323
+ return item(props => ({
324
+ index,
325
+ value: value ? get(value.get(props == null ? void 0 : props.name), 'value') : props == null ? void 0 : props.value,
326
+ onChange: onChange ? nextValue => onChange({
327
+ name: props == null ? void 0 : props.name,
328
+ label: props == null ? void 0 : props.label,
329
+ value: nextValue
330
+ }) : props == null ? void 0 : props.onChange
152
331
  }));
153
- }), children]
332
+ }
333
+ const ComponentItem = item.type;
334
+ return /*#__PURE__*/createElement(ComponentItem, _extends({}, Object.assign({}, item.props, {
335
+ value: value ? get(value.get(item.props.name), 'value') : item.props.value,
336
+ onChange: onChange ? nextValue => onChange({
337
+ name: item.props.name,
338
+ label: item.props.label,
339
+ value: nextValue
340
+ }) : item.props.onChange
341
+ }), {
342
+ key: item.key || item.props.name || index
343
+ }));
344
+ }, [onChange, value]);
345
+ };
346
+ const Line$1 = ({
347
+ list,
348
+ children,
349
+ innerRef,
350
+ nowrap
351
+ }) => {
352
+ const renderItem = useFilterItemRenderer();
353
+ return /*#__PURE__*/jsxs("div", {
354
+ ref: innerRef,
355
+ className: classnames(style$1['filter-line'], {
356
+ [style$1['filter-line-nowrap']]: nowrap
357
+ }),
358
+ children: [list.filter(isValidFilterItem).map((item, index) => renderItem(item, index)), children]
154
359
  });
155
360
  };
361
+ const CollapseButtons = ({
362
+ onClick,
363
+ toggleUpText
364
+ }) => /*#__PURE__*/jsxs(Fragment, {
365
+ children: [/*#__PURE__*/jsx(Space, {
366
+ size: 4,
367
+ className: classnames(style$1['un-expand-shadow']),
368
+ children: /*#__PURE__*/jsxs(Space, {
369
+ size: 4,
370
+ className: classnames(style$1['option'], style$1['filter-item']),
371
+ children: [toggleUpText, /*#__PURE__*/jsx("span", {
372
+ className: style$1['filter-item-option-icon'],
373
+ children: "\u25B2"
374
+ })]
375
+ })
376
+ }), /*#__PURE__*/jsx(Space, {
377
+ size: 4,
378
+ className: classnames(style$1['un-expand']),
379
+ onClick: onClick,
380
+ children: /*#__PURE__*/jsxs(Space, {
381
+ size: 4,
382
+ className: classnames(style$1['option'], style$1['filter-item']),
383
+ children: [toggleUpText, /*#__PURE__*/jsx("span", {
384
+ className: style$1['filter-item-option-icon'],
385
+ children: "\u25B2"
386
+ })]
387
+ })
388
+ })]
389
+ });
156
390
  const FilterLines = ({
157
391
  className,
158
392
  list: _list = [],
159
393
  displayLine: _displayLine = 1,
160
394
  label,
161
395
  extra,
162
- children
396
+ children,
397
+ visibleCountStrategy: _visibleCountStrategy = 'asc'
163
398
  }) => {
164
- const hasMore = _list.length > _displayLine;
165
- const mobileList = _list.reduce((result, item) => result.concat(Array.isArray(item) ? item : [item]), []);
399
+ const {
400
+ mode,
401
+ items: flatItems,
402
+ lines
403
+ } = useMemo(() => normalizeFilterList(_list), [_list]);
404
+ const mobileList = useMemo(() => getMobileFilterList(_list), [_list]);
405
+ const isFlatMode = mode === 'flat';
166
406
  const [isExpand, setIsExpand] = useState(false);
167
407
  const isMobile = useMobile();
168
408
  const {
@@ -173,11 +413,40 @@ const FilterLines = ({
173
413
  enabled: isMobile,
174
414
  refreshKey: _list
175
415
  });
416
+ const {
417
+ setContainerRef,
418
+ setMeasureRef,
419
+ setMoreMeasureRef,
420
+ visibleCount
421
+ } = useVisibleItemCount({
422
+ items: flatItems,
423
+ enabled: !isMobile && isFlatMode,
424
+ strategy: _visibleCountStrategy
425
+ });
426
+ const renderItem = useFilterItemRenderer();
176
427
  const {
177
428
  formatMessage
178
429
  } = useIntl({
179
430
  moduleName: 'Filter'
180
431
  });
432
+ const visibleFlatItems = isFlatMode ? flatItems.slice(0, visibleCount) : [];
433
+ const hiddenFlatItems = isFlatMode ? flatItems.slice(visibleCount) : [];
434
+ const hasMoreFlat = hiddenFlatItems.length > 0;
435
+ const hasMoreNested = !isFlatMode && lines.length > _displayLine;
436
+ const hasMore = isFlatMode ? hasMoreFlat : hasMoreNested;
437
+ const visibleLines = !isFlatMode ? lines.slice(0, _displayLine) : [];
438
+ const hiddenLines = !isFlatMode ? lines.slice(_displayLine) : [];
439
+ const showLabel = isFlatMode ? flatItems.length > 0 : lines.length > 0;
440
+ const setScrollContainerRef = useCallback(node => {
441
+ scrollRef.current = node;
442
+ }, [scrollRef]);
443
+ const setMeasureContainerRef = useCallback(node => {
444
+ if (!isMobile && isFlatMode) {
445
+ setContainerRef(node);
446
+ } else {
447
+ setContainerRef(null);
448
+ }
449
+ }, [isFlatMode, isMobile, setContainerRef]);
181
450
  const scrollToNext = useCallback(() => {
182
451
  const el = scrollRef.current;
183
452
  if (!el) return;
@@ -197,6 +466,62 @@ const FilterLines = ({
197
466
  inline: 'center'
198
467
  });
199
468
  }, [isMobile, scrollRef]);
469
+ const toggleExpand = useCallback(() => {
470
+ setIsExpand(value => !value);
471
+ }, []);
472
+ const moreButtonLabel = /*#__PURE__*/jsxs(Fragment, {
473
+ children: [formatMessage({
474
+ id: 'moreText'
475
+ }), /*#__PURE__*/jsx("span", {
476
+ className: style$1['filter-item-option-icon'],
477
+ children: "\u25BC"
478
+ })]
479
+ });
480
+ const moreButton = /*#__PURE__*/jsx(Space, {
481
+ size: 4,
482
+ className: classnames(style$1['filter-item'], style$1['option']),
483
+ onClick: toggleExpand,
484
+ children: moreButtonLabel
485
+ });
486
+ const renderDesktopContent = () => {
487
+ if (isFlatMode) {
488
+ return /*#__PURE__*/jsx(Line$1, {
489
+ list: visibleFlatItems,
490
+ nowrap: hasMoreFlat && !isExpand,
491
+ children: hasMoreFlat && !isExpand ? /*#__PURE__*/jsx("span", {
492
+ "data-filter-more": true,
493
+ children: moreButton
494
+ }) : null
495
+ });
496
+ }
497
+ return visibleLines.map((line, index) => /*#__PURE__*/jsx(Line$1, {
498
+ list: line,
499
+ children: hasMoreNested && !isExpand && index === _displayLine - 1 ? moreButton : null
500
+ }, index));
501
+ };
502
+ const renderExpandedContent = () => {
503
+ if (isFlatMode) {
504
+ if (!hiddenFlatItems.length) return null;
505
+ return /*#__PURE__*/jsx(Line$1, {
506
+ list: hiddenFlatItems,
507
+ children: /*#__PURE__*/jsx(CollapseButtons, {
508
+ onClick: toggleExpand,
509
+ toggleUpText: formatMessage({
510
+ id: 'toggleUpText'
511
+ })
512
+ })
513
+ });
514
+ }
515
+ return hiddenLines.map((line, index) => /*#__PURE__*/jsx(Line$1, {
516
+ list: line,
517
+ children: index === hiddenLines.length - 1 ? /*#__PURE__*/jsx(CollapseButtons, {
518
+ onClick: toggleExpand,
519
+ toggleUpText: formatMessage({
520
+ id: 'toggleUpText'
521
+ })
522
+ }) : null
523
+ }, index));
524
+ };
200
525
  return /*#__PURE__*/jsxs(Fragment, {
201
526
  children: [/*#__PURE__*/jsxs(Space, {
202
527
  className: classnames(style$1['filter-title'], 'filter-title', className),
@@ -204,7 +529,7 @@ const FilterLines = ({
204
529
  size: 16,
205
530
  children: [/*#__PURE__*/jsx("span", {
206
531
  className: style$1['filter-label'],
207
- children: _list && _list.length > 0 && (label || formatMessage({
532
+ children: showLabel && (label || formatMessage({
208
533
  id: 'filterText'
209
534
  }))
210
535
  }), /*#__PURE__*/jsxs(Row, {
@@ -215,29 +540,38 @@ const FilterLines = ({
215
540
  className: style$1['filter-list'],
216
541
  flex: 1,
217
542
  children: /*#__PURE__*/jsxs("div", {
218
- className: style$1['filter-list-scroll-wrap'],
219
- children: [isMobile && showScrollPrev ? /*#__PURE__*/jsx("div", {
543
+ ref: setMeasureContainerRef,
544
+ className: classnames(style$1['filter-list-scroll-wrap'], {
545
+ [style$1['filter-list-constrained']]: !isMobile && isFlatMode
546
+ }),
547
+ children: [!isMobile && isFlatMode ? /*#__PURE__*/jsxs("div", {
548
+ ref: setMeasureRef,
549
+ className: classnames(style$1['filter-line'], style$1['filter-line-measure']),
550
+ "aria-hidden": true,
551
+ children: [flatItems.filter(isValidFilterItem).map((item, index) => {
552
+ var _item$props;
553
+ return /*#__PURE__*/jsx("div", {
554
+ "data-filter-measure-item": true,
555
+ children: renderItem(item, index)
556
+ }, item.key || ((_item$props = item.props) == null ? void 0 : _item$props.name) || index);
557
+ }), /*#__PURE__*/jsx("div", {
558
+ ref: setMoreMeasureRef,
559
+ "data-filter-measure-more": true,
560
+ children: /*#__PURE__*/jsx(Space, {
561
+ size: 4,
562
+ className: classnames(style$1['filter-item'], style$1['option']),
563
+ children: moreButtonLabel
564
+ })
565
+ })]
566
+ }) : null, isMobile && showScrollPrev ? /*#__PURE__*/jsx("div", {
220
567
  className: style$1['filter-scroll-prev-shadow']
221
568
  }) : null, /*#__PURE__*/jsx("div", {
222
569
  className: style$1['filter-list-scroll'],
223
- ref: scrollRef,
570
+ ref: setScrollContainerRef,
224
571
  onClick: scrollItemIntoView,
225
- children: (isMobile ? mobileList : _list.slice(0, _displayLine)).map((item, index) => /*#__PURE__*/jsx(Line$1, {
226
- list: isMobile ? [item] : item,
227
- children: !isMobile && hasMore && isExpand === false && index === _displayLine - 1 ? /*#__PURE__*/jsxs(Space, {
228
- size: 4,
229
- className: classnames(style$1['filter-item'], style$1['option']),
230
- onClick: () => {
231
- setIsExpand(value => !value);
232
- },
233
- children: [formatMessage({
234
- id: 'moreText'
235
- }), /*#__PURE__*/jsx("span", {
236
- className: style$1['filter-item-option-icon'],
237
- children: "\u25BC"
238
- })]
239
- }) : null
240
- }, index))
572
+ children: isMobile ? mobileList.map((item, index) => /*#__PURE__*/jsx(Line$1, {
573
+ list: [item]
574
+ }, index)) : renderDesktopContent()
241
575
  }), isMobile && showScrollNext ? /*#__PURE__*/jsx("button", {
242
576
  type: "button",
243
577
  className: style$1['filter-scroll-next'],
@@ -271,41 +605,7 @@ const FilterLines = ({
271
605
  })
272
606
  }), /*#__PURE__*/jsx("div", {
273
607
  className: style$1['filter-list'],
274
- children: _list.slice(_displayLine).map((item, index) => /*#__PURE__*/jsx(Line$1, {
275
- list: item,
276
- children: index === _list.length - _displayLine - 1 && /*#__PURE__*/jsxs(Fragment, {
277
- children: [/*#__PURE__*/jsx(Space, {
278
- size: 4,
279
- className: classnames(style$1['un-expand-shadow']),
280
- children: /*#__PURE__*/jsxs(Space, {
281
- size: 4,
282
- className: classnames(style$1['option'], style$1['filter-item']),
283
- children: [formatMessage({
284
- id: 'toggleUpText'
285
- }), /*#__PURE__*/jsx("span", {
286
- className: style$1['filter-item-option-icon'],
287
- children: "\u25B2"
288
- })]
289
- })
290
- }), /*#__PURE__*/jsx(Space, {
291
- size: 4,
292
- className: classnames(style$1['un-expand']),
293
- onClick: () => {
294
- setIsExpand(value => !value);
295
- },
296
- children: /*#__PURE__*/jsxs(Space, {
297
- size: 4,
298
- className: classnames(style$1['option'], style$1['filter-item']),
299
- children: [formatMessage({
300
- id: 'toggleUpText'
301
- }), /*#__PURE__*/jsx("span", {
302
- className: style$1['filter-item-option-icon'],
303
- children: "\u25B2"
304
- })]
305
- })
306
- })]
307
- })
308
- }, index))
608
+ children: renderExpandedContent()
309
609
  })]
310
610
  })]
311
611
  });
@@ -1409,6 +1709,15 @@ const NumberRangeFilterItem = withInputDefaultPlaceholder(NumberRangeFilterItem$
1409
1709
  const SuperSelectFilterItem = withFieldItem(SuperSelect, {
1410
1710
  forcePopup: true
1411
1711
  });
1712
+ const SelectTableListFilterItem = withFieldItem(SelectTableList, {
1713
+ forcePopup: true
1714
+ });
1715
+ const SelectTreeFilterItem = withFieldItem(SelectTree, {
1716
+ forcePopup: true
1717
+ });
1718
+ const SelectCascaderFilterItem = withFieldItem(SelectCascader, {
1719
+ forcePopup: true
1720
+ });
1412
1721
  const SelectFunctionFilterItem = withFieldItem(SelectFunction, {
1413
1722
  forcePopup: true
1414
1723
  });
@@ -1424,6 +1733,9 @@ var fields$1 = {
1424
1733
  InputFilterItem: InputFilterItem$1,
1425
1734
  NumberRangeFilterItem: NumberRangeFilterItem,
1426
1735
  SuperSelectFilterItem: SuperSelectFilterItem,
1736
+ SelectTableListFilterItem: SelectTableListFilterItem,
1737
+ SelectTreeFilterItem: SelectTreeFilterItem,
1738
+ SelectCascaderFilterItem: SelectCascaderFilterItem,
1427
1739
  SelectFunctionFilterItem: SelectFunctionFilterItem,
1428
1740
  SelectIndustryFilterItem: SelectIndustryFilterItem,
1429
1741
  SelectAddressFilterItem: SelectAddressFilterItem,
@@ -2470,5 +2782,5 @@ Filter.filterInterceptors = filterInterceptors;
2470
2782
  Filter.singleSelectInterceptor = singleSelectInterceptor;
2471
2783
  Filter.multiSelectInterceptor = multiSelectInterceptor;
2472
2784
 
2473
- export { AdvancedFilter, DatePickerFilterItem, DateRangePickerFilterItem, FilterItem, FilterItemContainer, FilterLines, FilterProvider, FilterValueDisplay, InputFilterItem$1 as InputFilterItem, NumberRangeFilterItem, PopoverItem, SearchInput, SelectAddressFilterItem, SelectFunctionFilterItem, SelectIndustryFilterItem, SuperSelectFilterItem, TypeDateRangePickerField, TypeDateRangePickerFilterItem, createFilterValueMapper, createUrlFilterReader, createUrlParamsReader, Filter as default, fields$1 as fields, filterInterceptors, filterToUrlParams, getFilterValue, multiSelectInterceptor, parseFilterEntry, pickSelectValues, singleSelectInterceptor, stripConsumedUrlParams, takeFilterEntry, useContext as useFilter, useUrlFilter, useUrlFilterValue, withFieldItem, withFilterValue };
2785
+ export { AdvancedFilter, DatePickerFilterItem, DateRangePickerFilterItem, FilterItem, FilterItemContainer, FilterLines, FilterProvider, FilterValueDisplay, InputFilterItem$1 as InputFilterItem, NumberRangeFilterItem, PopoverItem, SearchInput, SelectAddressFilterItem, SelectCascaderFilterItem, SelectFunctionFilterItem, SelectIndustryFilterItem, SelectTableListFilterItem, SelectTreeFilterItem, SuperSelectFilterItem, TypeDateRangePickerField, TypeDateRangePickerFilterItem, createFilterValueMapper, createUrlFilterReader, createUrlParamsReader, Filter as default, fields$1 as fields, filterInterceptors, filterToUrlParams, getFilterValue, multiSelectInterceptor, parseFilterEntry, pickSelectValues, singleSelectInterceptor, stripConsumedUrlParams, takeFilterEntry, useContext as useFilter, useUrlFilter, useUrlFilterValue, withFieldItem, withFilterValue };
2474
2786
  //# sourceMappingURL=index.modern.js.map