@kne/react-filter 1.0.4 → 1.0.6

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,292 @@ 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 containerRef = useRef(null);
127
+ const measureRef = useRef(null);
128
+ const moreMeasureRef = useRef(null);
129
+ const rafRef = useRef(null);
130
+ const lastWidthRef = useRef(0);
131
+ const [containerEl, setContainerEl] = useState(null);
132
+ const [visibleCount, setVisibleCount] = useState(() => items.length > 0 ? 1 : 0);
133
+ const setContainerRef = useCallback(node => {
134
+ containerRef.current = node;
135
+ setContainerEl(node || null);
136
+ }, []);
137
+ const setMeasureRef = useCallback(node => {
138
+ measureRef.current = node;
139
+ }, []);
140
+ const setMoreMeasureRef = useCallback(node => {
141
+ moreMeasureRef.current = node;
142
+ }, []);
143
+ const getWidths = useCallback(() => {
144
+ var _moreMeasureRef$curre;
145
+ const container = containerRef.current;
146
+ const measureEl = measureRef.current;
147
+ if (!container || !measureEl) {
148
+ return null;
149
+ }
150
+ const containerWidth = container.clientWidth;
151
+ if (containerWidth <= 0) {
152
+ return null;
153
+ }
154
+ const itemNodes = measureEl.querySelectorAll('[data-filter-measure-item]');
155
+ if (!itemNodes.length) {
156
+ return null;
157
+ }
158
+ const moreButtonWidth = ((_moreMeasureRef$curre = moreMeasureRef.current) == null ? void 0 : _moreMeasureRef$curre.getBoundingClientRect().width) || 0;
159
+ if (items.length > 1 && moreButtonWidth <= 0) {
160
+ return null;
161
+ }
162
+ const itemWidths = Array.from(itemNodes, node => node.getBoundingClientRect().width);
163
+ return {
164
+ containerWidth,
165
+ itemWidths,
166
+ moreButtonWidth
167
+ };
168
+ }, [items.length]);
169
+ const getWidthForCount = useCallback((itemWidths, moreButtonWidth, count) => {
170
+ let usedWidth = 0;
171
+ for (let i = 0; i < count; i++) {
172
+ usedWidth += itemWidths[i] + (i > 0 ? GAP : 0);
173
+ }
174
+ if (count < items.length) {
175
+ usedWidth += GAP + moreButtonWidth;
176
+ }
177
+ return usedWidth;
178
+ }, [items.length]);
179
+ const resolveVisibleCount = useCallback(widths => {
180
+ const {
181
+ containerWidth,
182
+ itemWidths,
183
+ moreButtonWidth
184
+ } = widths;
185
+ const maxCount = Math.min(items.length, itemWidths.length);
186
+ let count = 1;
187
+ if (_strategy === 'desc') {
188
+ count = maxCount;
189
+ while (count > 1) {
190
+ const usedWidth = getWidthForCount(itemWidths, moreButtonWidth, count);
191
+ if (usedWidth + SAFETY_GAP <= containerWidth) {
192
+ break;
193
+ }
194
+ count -= 1;
195
+ }
196
+ } else {
197
+ count = 1;
198
+ while (count < maxCount) {
199
+ const nextCount = count + 1;
200
+ const usedWidth = getWidthForCount(itemWidths, moreButtonWidth, nextCount);
201
+ if (usedWidth + SAFETY_GAP > containerWidth) {
202
+ break;
203
+ }
204
+ count = nextCount;
205
+ }
206
+ }
207
+ return Math.max(1, count);
208
+ }, [getWidthForCount, items.length, _strategy]);
209
+ const calculateByWidth = useCallback(() => {
210
+ if (!enabled || !items.length) {
211
+ setVisibleCount(prev => prev === items.length ? prev : items.length);
212
+ return;
213
+ }
214
+ const widths = getWidths();
215
+ if (!widths) {
216
+ return;
217
+ }
218
+ const nextCount = resolveVisibleCount(widths);
219
+ setVisibleCount(prev => prev === nextCount ? prev : nextCount);
220
+ }, [enabled, getWidths, items.length, resolveVisibleCount]);
221
+ const scheduleCalculate = useCallback(() => {
222
+ if (rafRef.current) {
223
+ window.cancelAnimationFrame(rafRef.current);
224
+ }
225
+ rafRef.current = window.requestAnimationFrame(() => {
226
+ rafRef.current = null;
227
+ calculateByWidth();
228
+ });
229
+ }, [calculateByWidth]);
230
+ useLayoutEffect(() => {
231
+ scheduleCalculate();
232
+ return () => {
233
+ if (rafRef.current) {
234
+ window.cancelAnimationFrame(rafRef.current);
235
+ rafRef.current = null;
236
+ }
237
+ };
238
+ }, [items, scheduleCalculate]);
239
+ useEffect(() => {
240
+ if (!enabled || !containerEl) {
241
+ return undefined;
242
+ }
243
+ const observer = new ResizeObserver(entries => {
244
+ var _entry$contentRect$wi;
245
+ const entry = entries.find(item => item.target === containerEl);
246
+ const nextWidth = (_entry$contentRect$wi = entry == null ? void 0 : entry.contentRect.width) != null ? _entry$contentRect$wi : containerEl.clientWidth;
247
+ if (Math.abs(nextWidth - lastWidthRef.current) < 1) {
248
+ return;
249
+ }
250
+ lastWidthRef.current = nextWidth;
251
+ scheduleCalculate();
252
+ });
253
+ lastWidthRef.current = containerEl.clientWidth;
254
+ observer.observe(containerEl);
255
+ window.addEventListener('resize', scheduleCalculate);
256
+ return () => {
257
+ observer.disconnect();
258
+ window.removeEventListener('resize', scheduleCalculate);
259
+ if (rafRef.current) {
260
+ window.cancelAnimationFrame(rafRef.current);
261
+ rafRef.current = null;
262
+ }
263
+ };
264
+ }, [containerEl, enabled, scheduleCalculate]);
265
+ return {
266
+ setContainerRef,
267
+ setMeasureRef,
268
+ setMoreMeasureRef,
269
+ visibleCount
270
+ };
271
+ };
272
+
273
+ const isFilterListItem = item => {
274
+ if (!item) return false;
275
+ if (typeof item === 'function') return true;
276
+ return !!item.type;
277
+ };
278
+ const isNestedFilterList = list => {
279
+ if (!Array.isArray(list) || list.length === 0) return false;
280
+ return Array.isArray(list[0]) && !isFilterListItem(list[0]);
281
+ };
282
+ const normalizeFilterList = list => {
283
+ const safeList = Array.isArray(list) ? list : [];
284
+ if (!safeList.length) {
285
+ return {
286
+ mode: 'flat',
287
+ items: [],
288
+ lines: []
289
+ };
290
+ }
291
+ if (isNestedFilterList(safeList)) {
292
+ return {
293
+ mode: 'nested',
294
+ items: null,
295
+ lines: safeList
296
+ };
297
+ }
298
+ return {
299
+ mode: 'flat',
300
+ items: safeList,
301
+ lines: null
302
+ };
303
+ };
304
+ const getMobileFilterList = list => {
305
+ const {
306
+ mode,
307
+ items,
308
+ lines
309
+ } = normalizeFilterList(list);
310
+ if (mode === 'flat') return items;
311
+ return lines.reduce((result, line) => result.concat(line), []);
312
+ };
313
+
314
+ const isValidFilterItem = item => !!item && (item.type || typeof item === 'function');
315
+ const useFilterItemRenderer = () => {
122
316
  const {
123
317
  value,
124
318
  onChange
125
319
  } = 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
320
+ return useCallback((item, index) => {
321
+ if (typeof item === 'function') {
322
+ return item(props => ({
323
+ index,
324
+ value: value ? get(value.get(props == null ? void 0 : props.name), 'value') : props == null ? void 0 : props.value,
325
+ onChange: onChange ? nextValue => onChange({
326
+ name: props == null ? void 0 : props.name,
327
+ label: props == null ? void 0 : props.label,
328
+ value: nextValue
329
+ }) : props == null ? void 0 : props.onChange
152
330
  }));
153
- }), children]
331
+ }
332
+ const ComponentItem = item.type;
333
+ return /*#__PURE__*/createElement(ComponentItem, _extends({}, Object.assign({}, item.props, {
334
+ value: value ? get(value.get(item.props.name), 'value') : item.props.value,
335
+ onChange: onChange ? nextValue => onChange({
336
+ name: item.props.name,
337
+ label: item.props.label,
338
+ value: nextValue
339
+ }) : item.props.onChange
340
+ }), {
341
+ key: item.key || item.props.name || index
342
+ }));
343
+ }, [onChange, value]);
344
+ };
345
+ const Line$1 = ({
346
+ list,
347
+ children,
348
+ innerRef,
349
+ nowrap
350
+ }) => {
351
+ const renderItem = useFilterItemRenderer();
352
+ return /*#__PURE__*/jsxs("div", {
353
+ ref: innerRef,
354
+ className: classnames(style$1['filter-line'], {
355
+ [style$1['filter-line-nowrap']]: nowrap
356
+ }),
357
+ children: [list.filter(isValidFilterItem).map((item, index) => renderItem(item, index)), children]
154
358
  });
155
359
  };
360
+ const CollapseButtons = ({
361
+ onClick,
362
+ toggleUpText
363
+ }) => /*#__PURE__*/jsxs(Fragment, {
364
+ children: [/*#__PURE__*/jsx(Space, {
365
+ size: 4,
366
+ className: classnames(style$1['un-expand-shadow']),
367
+ children: /*#__PURE__*/jsxs(Space, {
368
+ size: 4,
369
+ className: classnames(style$1['option'], style$1['filter-item']),
370
+ children: [toggleUpText, /*#__PURE__*/jsx("span", {
371
+ className: style$1['filter-item-option-icon'],
372
+ children: "\u25B2"
373
+ })]
374
+ })
375
+ }), /*#__PURE__*/jsx(Space, {
376
+ size: 4,
377
+ className: classnames(style$1['un-expand']),
378
+ onClick: onClick,
379
+ children: /*#__PURE__*/jsxs(Space, {
380
+ size: 4,
381
+ className: classnames(style$1['option'], style$1['filter-item']),
382
+ children: [toggleUpText, /*#__PURE__*/jsx("span", {
383
+ className: style$1['filter-item-option-icon'],
384
+ children: "\u25B2"
385
+ })]
386
+ })
387
+ })]
388
+ });
156
389
  const FilterLines = ({
157
390
  className,
158
391
  list: _list = [],
159
392
  displayLine: _displayLine = 1,
160
393
  label,
161
394
  extra,
162
- children
395
+ children,
396
+ visibleCountStrategy: _visibleCountStrategy = 'asc'
163
397
  }) => {
164
- const hasMore = _list.length > _displayLine;
165
- const mobileList = _list.reduce((result, item) => result.concat(Array.isArray(item) ? item : [item]), []);
398
+ const {
399
+ mode,
400
+ items: flatItems,
401
+ lines
402
+ } = useMemo(() => normalizeFilterList(_list), [_list]);
403
+ const mobileList = useMemo(() => getMobileFilterList(_list), [_list]);
404
+ const isFlatMode = mode === 'flat';
166
405
  const [isExpand, setIsExpand] = useState(false);
167
406
  const isMobile = useMobile();
168
407
  const {
@@ -173,11 +412,40 @@ const FilterLines = ({
173
412
  enabled: isMobile,
174
413
  refreshKey: _list
175
414
  });
415
+ const {
416
+ setContainerRef,
417
+ setMeasureRef,
418
+ setMoreMeasureRef,
419
+ visibleCount
420
+ } = useVisibleItemCount({
421
+ items: flatItems,
422
+ enabled: !isMobile && isFlatMode,
423
+ strategy: _visibleCountStrategy
424
+ });
425
+ const renderItem = useFilterItemRenderer();
176
426
  const {
177
427
  formatMessage
178
428
  } = useIntl({
179
429
  moduleName: 'Filter'
180
430
  });
431
+ const visibleFlatItems = isFlatMode ? flatItems.slice(0, visibleCount) : [];
432
+ const hiddenFlatItems = isFlatMode ? flatItems.slice(visibleCount) : [];
433
+ const hasMoreFlat = hiddenFlatItems.length > 0;
434
+ const hasMoreNested = !isFlatMode && lines.length > _displayLine;
435
+ const hasMore = isFlatMode ? hasMoreFlat : hasMoreNested;
436
+ const visibleLines = !isFlatMode ? lines.slice(0, _displayLine) : [];
437
+ const hiddenLines = !isFlatMode ? lines.slice(_displayLine) : [];
438
+ const showLabel = isFlatMode ? flatItems.length > 0 : lines.length > 0;
439
+ const setScrollContainerRef = useCallback(node => {
440
+ scrollRef.current = node;
441
+ }, [scrollRef]);
442
+ const setMeasureContainerRef = useCallback(node => {
443
+ if (!isMobile && isFlatMode) {
444
+ setContainerRef(node);
445
+ } else {
446
+ setContainerRef(null);
447
+ }
448
+ }, [isFlatMode, isMobile, setContainerRef]);
181
449
  const scrollToNext = useCallback(() => {
182
450
  const el = scrollRef.current;
183
451
  if (!el) return;
@@ -197,6 +465,62 @@ const FilterLines = ({
197
465
  inline: 'center'
198
466
  });
199
467
  }, [isMobile, scrollRef]);
468
+ const toggleExpand = useCallback(() => {
469
+ setIsExpand(value => !value);
470
+ }, []);
471
+ const moreButtonLabel = /*#__PURE__*/jsxs(Fragment, {
472
+ children: [formatMessage({
473
+ id: 'moreText'
474
+ }), /*#__PURE__*/jsx("span", {
475
+ className: style$1['filter-item-option-icon'],
476
+ children: "\u25BC"
477
+ })]
478
+ });
479
+ const moreButton = /*#__PURE__*/jsx(Space, {
480
+ size: 4,
481
+ className: classnames(style$1['filter-item'], style$1['option']),
482
+ onClick: toggleExpand,
483
+ children: moreButtonLabel
484
+ });
485
+ const renderDesktopContent = () => {
486
+ if (isFlatMode) {
487
+ return /*#__PURE__*/jsx(Line$1, {
488
+ list: visibleFlatItems,
489
+ nowrap: hasMoreFlat && !isExpand,
490
+ children: hasMoreFlat && !isExpand ? /*#__PURE__*/jsx("span", {
491
+ "data-filter-more": true,
492
+ children: moreButton
493
+ }) : null
494
+ });
495
+ }
496
+ return visibleLines.map((line, index) => /*#__PURE__*/jsx(Line$1, {
497
+ list: line,
498
+ children: hasMoreNested && !isExpand && index === _displayLine - 1 ? moreButton : null
499
+ }, index));
500
+ };
501
+ const renderExpandedContent = () => {
502
+ if (isFlatMode) {
503
+ if (!hiddenFlatItems.length) return null;
504
+ return /*#__PURE__*/jsx(Line$1, {
505
+ list: hiddenFlatItems,
506
+ children: /*#__PURE__*/jsx(CollapseButtons, {
507
+ onClick: toggleExpand,
508
+ toggleUpText: formatMessage({
509
+ id: 'toggleUpText'
510
+ })
511
+ })
512
+ });
513
+ }
514
+ return hiddenLines.map((line, index) => /*#__PURE__*/jsx(Line$1, {
515
+ list: line,
516
+ children: index === hiddenLines.length - 1 ? /*#__PURE__*/jsx(CollapseButtons, {
517
+ onClick: toggleExpand,
518
+ toggleUpText: formatMessage({
519
+ id: 'toggleUpText'
520
+ })
521
+ }) : null
522
+ }, index));
523
+ };
200
524
  return /*#__PURE__*/jsxs(Fragment, {
201
525
  children: [/*#__PURE__*/jsxs(Space, {
202
526
  className: classnames(style$1['filter-title'], 'filter-title', className),
@@ -204,7 +528,7 @@ const FilterLines = ({
204
528
  size: 16,
205
529
  children: [/*#__PURE__*/jsx("span", {
206
530
  className: style$1['filter-label'],
207
- children: _list && _list.length > 0 && (label || formatMessage({
531
+ children: showLabel && (label || formatMessage({
208
532
  id: 'filterText'
209
533
  }))
210
534
  }), /*#__PURE__*/jsxs(Row, {
@@ -215,29 +539,38 @@ const FilterLines = ({
215
539
  className: style$1['filter-list'],
216
540
  flex: 1,
217
541
  children: /*#__PURE__*/jsxs("div", {
218
- className: style$1['filter-list-scroll-wrap'],
219
- children: [isMobile && showScrollPrev ? /*#__PURE__*/jsx("div", {
542
+ ref: setMeasureContainerRef,
543
+ className: classnames(style$1['filter-list-scroll-wrap'], {
544
+ [style$1['filter-list-constrained']]: !isMobile && isFlatMode
545
+ }),
546
+ children: [!isMobile && isFlatMode ? /*#__PURE__*/jsxs("div", {
547
+ ref: setMeasureRef,
548
+ className: classnames(style$1['filter-line'], style$1['filter-line-measure']),
549
+ "aria-hidden": true,
550
+ children: [flatItems.filter(isValidFilterItem).map((item, index) => {
551
+ var _item$props;
552
+ return /*#__PURE__*/jsx("div", {
553
+ "data-filter-measure-item": true,
554
+ children: renderItem(item, index)
555
+ }, item.key || ((_item$props = item.props) == null ? void 0 : _item$props.name) || index);
556
+ }), /*#__PURE__*/jsx("div", {
557
+ ref: setMoreMeasureRef,
558
+ "data-filter-measure-more": true,
559
+ children: /*#__PURE__*/jsx(Space, {
560
+ size: 4,
561
+ className: classnames(style$1['filter-item'], style$1['option']),
562
+ children: moreButtonLabel
563
+ })
564
+ })]
565
+ }) : null, isMobile && showScrollPrev ? /*#__PURE__*/jsx("div", {
220
566
  className: style$1['filter-scroll-prev-shadow']
221
567
  }) : null, /*#__PURE__*/jsx("div", {
222
568
  className: style$1['filter-list-scroll'],
223
- ref: scrollRef,
569
+ ref: setScrollContainerRef,
224
570
  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))
571
+ children: isMobile ? mobileList.map((item, index) => /*#__PURE__*/jsx(Line$1, {
572
+ list: [item]
573
+ }, index)) : renderDesktopContent()
241
574
  }), isMobile && showScrollNext ? /*#__PURE__*/jsx("button", {
242
575
  type: "button",
243
576
  className: style$1['filter-scroll-next'],
@@ -271,41 +604,7 @@ const FilterLines = ({
271
604
  })
272
605
  }), /*#__PURE__*/jsx("div", {
273
606
  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))
607
+ children: renderExpandedContent()
309
608
  })]
310
609
  })]
311
610
  });
@@ -1409,6 +1708,15 @@ const NumberRangeFilterItem = withInputDefaultPlaceholder(NumberRangeFilterItem$
1409
1708
  const SuperSelectFilterItem = withFieldItem(SuperSelect, {
1410
1709
  forcePopup: true
1411
1710
  });
1711
+ const SelectTableListFilterItem = withFieldItem(SelectTableList, {
1712
+ forcePopup: true
1713
+ });
1714
+ const SelectTreeFilterItem = withFieldItem(SelectTree, {
1715
+ forcePopup: true
1716
+ });
1717
+ const SelectCascaderFilterItem = withFieldItem(SelectCascader, {
1718
+ forcePopup: true
1719
+ });
1412
1720
  const SelectFunctionFilterItem = withFieldItem(SelectFunction, {
1413
1721
  forcePopup: true
1414
1722
  });
@@ -1424,6 +1732,9 @@ var fields$1 = {
1424
1732
  InputFilterItem: InputFilterItem$1,
1425
1733
  NumberRangeFilterItem: NumberRangeFilterItem,
1426
1734
  SuperSelectFilterItem: SuperSelectFilterItem,
1735
+ SelectTableListFilterItem: SelectTableListFilterItem,
1736
+ SelectTreeFilterItem: SelectTreeFilterItem,
1737
+ SelectCascaderFilterItem: SelectCascaderFilterItem,
1427
1738
  SelectFunctionFilterItem: SelectFunctionFilterItem,
1428
1739
  SelectIndustryFilterItem: SelectIndustryFilterItem,
1429
1740
  SelectAddressFilterItem: SelectAddressFilterItem,
@@ -1467,16 +1778,17 @@ const withFilterValue = WrappedComponent => {
1467
1778
  };
1468
1779
  };
1469
1780
 
1470
- const _excluded$4 = ["label", "onChange", "value", "placeholder"];
1781
+ const _excluded$4 = ["label", "onChange", "value", "placeholder", "searchDelay"];
1471
1782
  const {
1472
1783
  Search
1473
1784
  } = Input;
1474
- const SearchInput = withFilterValue(_ref => {
1785
+ const SearchInput = withLocale(withFilterValue(_ref => {
1475
1786
  let {
1476
1787
  label,
1477
1788
  onChange,
1478
1789
  value,
1479
- placeholder
1790
+ placeholder,
1791
+ searchDelay = 500
1480
1792
  } = _ref,
1481
1793
  props = _objectWithoutPropertiesLoose(_ref, _excluded$4);
1482
1794
  const {
@@ -1484,21 +1796,74 @@ const SearchInput = withFilterValue(_ref => {
1484
1796
  } = useIntl({
1485
1797
  moduleName: 'Filter'
1486
1798
  });
1799
+ const propsValue = value == null ? void 0 : value.value;
1800
+ const [inputValue, setInputValue] = useState(propsValue || '');
1801
+ const inputValueRef = useRef('');
1802
+ const onChangeRef = useRef(onChange);
1803
+ const searchTimerRef = useRef(null);
1804
+ const isComposingRef = useRef(false);
1805
+ inputValueRef.current = inputValue;
1806
+ onChangeRef.current = onChange;
1807
+ const clearSearchTimer = () => {
1808
+ if (searchTimerRef.current) {
1809
+ clearTimeout(searchTimerRef.current);
1810
+ searchTimerRef.current = null;
1811
+ }
1812
+ };
1813
+ const submitSearch = searchValue => {
1814
+ onChangeRef.current == null || onChangeRef.current(searchValue ? {
1815
+ label: searchValue,
1816
+ value: searchValue
1817
+ } : null);
1818
+ };
1819
+ const scheduleSearch = searchValue => {
1820
+ clearSearchTimer();
1821
+ searchTimerRef.current = setTimeout(() => {
1822
+ searchTimerRef.current = null;
1823
+ submitSearch(searchValue);
1824
+ }, searchDelay);
1825
+ };
1826
+ useEffect(() => {
1827
+ if (propsValue !== inputValueRef.current) {
1828
+ clearSearchTimer();
1829
+ setInputValue(propsValue || '');
1830
+ }
1831
+ }, [propsValue]);
1832
+ useEffect(() => {
1833
+ return () => {
1834
+ clearSearchTimer();
1835
+ };
1836
+ }, []);
1487
1837
  return /*#__PURE__*/jsx(Search, _extends({}, props, {
1488
1838
  placeholder: placeholder || formatMessage({
1489
1839
  id: 'inputPlaceholder'
1490
1840
  }, {
1491
1841
  label
1492
1842
  }),
1493
- value: (value == null ? void 0 : value.value) || '',
1494
- onSearch: value => {
1495
- onChange({
1496
- label: value,
1497
- value
1498
- });
1843
+ value: inputValue,
1844
+ onChange: e => {
1845
+ const nextValue = e.target.value;
1846
+ setInputValue(nextValue);
1847
+ if (!isComposingRef.current) {
1848
+ scheduleSearch(nextValue);
1849
+ }
1850
+ },
1851
+ onCompositionStart: () => {
1852
+ isComposingRef.current = true;
1853
+ clearSearchTimer();
1854
+ },
1855
+ onCompositionEnd: e => {
1856
+ isComposingRef.current = false;
1857
+ const nextValue = e.target.value;
1858
+ setInputValue(nextValue);
1859
+ scheduleSearch(nextValue);
1860
+ },
1861
+ onSearch: searchValue => {
1862
+ clearSearchTimer();
1863
+ submitSearch(searchValue);
1499
1864
  }
1500
1865
  }));
1501
- });
1866
+ }));
1502
1867
 
1503
1868
  /**
1504
1869
  * 从筛选值中提取原始值数组。
@@ -2416,5 +2781,5 @@ Filter.filterInterceptors = filterInterceptors;
2416
2781
  Filter.singleSelectInterceptor = singleSelectInterceptor;
2417
2782
  Filter.multiSelectInterceptor = multiSelectInterceptor;
2418
2783
 
2419
- 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 };
2784
+ 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 };
2420
2785
  //# sourceMappingURL=index.modern.js.map