@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.
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ var reactDom = require('react-dom');
10
10
  var isNumber = require('lodash/isNumber');
11
11
  var SuperSelect = require('@kne/super-select');
12
12
  var superSelectPlus = require('@kne/super-select-plus');
13
+ require('@kne/super-select/dist/index.css');
13
14
  require('@kne/super-select-plus/dist/index.css');
14
15
  var dayjs = require('dayjs');
15
16
  var transform = require('lodash/transform');
@@ -46,7 +47,7 @@ function _objectWithoutPropertiesLoose(r, e) {
46
47
  return t;
47
48
  }
48
49
 
49
- 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"};
50
+ 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"};
50
51
 
51
52
  const context = /*#__PURE__*/react.createContext({});
52
53
  const Provider = context.Provider;
@@ -124,53 +125,290 @@ const useHorizontalScrollShadows = ({
124
125
  };
125
126
  };
126
127
 
127
- const Line$1 = _ref => {
128
- let list = _ref.list,
129
- children = _ref.children;
128
+ const GAP = 8;
129
+ const SAFETY_GAP = 2;
130
+ const useVisibleItemCount = ({
131
+ items,
132
+ enabled,
133
+ strategy = 'asc'
134
+ }) => {
135
+ const containerRef = react.useRef(null);
136
+ const measureRef = react.useRef(null);
137
+ const moreMeasureRef = react.useRef(null);
138
+ const rafRef = react.useRef(null);
139
+ const lastWidthRef = react.useRef(0);
140
+ const [containerEl, setContainerEl] = react.useState(null);
141
+ const [visibleCount, setVisibleCount] = react.useState(() => items.length > 0 ? 1 : 0);
142
+ const setContainerRef = react.useCallback(node => {
143
+ containerRef.current = node;
144
+ setContainerEl(node || null);
145
+ }, []);
146
+ const setMeasureRef = react.useCallback(node => {
147
+ measureRef.current = node;
148
+ }, []);
149
+ const setMoreMeasureRef = react.useCallback(node => {
150
+ moreMeasureRef.current = node;
151
+ }, []);
152
+ const getWidths = react.useCallback(() => {
153
+ const container = containerRef.current;
154
+ const measureEl = measureRef.current;
155
+ if (!container || !measureEl) {
156
+ return null;
157
+ }
158
+ const containerWidth = container.clientWidth;
159
+ if (containerWidth <= 0) {
160
+ return null;
161
+ }
162
+ const itemNodes = measureEl.querySelectorAll('[data-filter-measure-item]');
163
+ if (!itemNodes.length) {
164
+ return null;
165
+ }
166
+ const moreButtonWidth = moreMeasureRef.current?.getBoundingClientRect().width || 0;
167
+ if (items.length > 1 && moreButtonWidth <= 0) {
168
+ return null;
169
+ }
170
+ const itemWidths = Array.from(itemNodes, node => node.getBoundingClientRect().width);
171
+ return {
172
+ containerWidth,
173
+ itemWidths,
174
+ moreButtonWidth
175
+ };
176
+ }, [items.length]);
177
+ const getWidthForCount = react.useCallback((itemWidths, moreButtonWidth, count) => {
178
+ let usedWidth = 0;
179
+ for (let i = 0; i < count; i++) {
180
+ usedWidth += itemWidths[i] + (i > 0 ? GAP : 0);
181
+ }
182
+ if (count < items.length) {
183
+ usedWidth += GAP + moreButtonWidth;
184
+ }
185
+ return usedWidth;
186
+ }, [items.length]);
187
+ const resolveVisibleCount = react.useCallback(widths => {
188
+ const {
189
+ containerWidth,
190
+ itemWidths,
191
+ moreButtonWidth
192
+ } = widths;
193
+ const maxCount = Math.min(items.length, itemWidths.length);
194
+ let count = 1;
195
+ if (strategy === 'desc') {
196
+ count = maxCount;
197
+ while (count > 1) {
198
+ const usedWidth = getWidthForCount(itemWidths, moreButtonWidth, count);
199
+ if (usedWidth + SAFETY_GAP <= containerWidth) {
200
+ break;
201
+ }
202
+ count -= 1;
203
+ }
204
+ } else {
205
+ count = 1;
206
+ while (count < maxCount) {
207
+ const nextCount = count + 1;
208
+ const usedWidth = getWidthForCount(itemWidths, moreButtonWidth, nextCount);
209
+ if (usedWidth + SAFETY_GAP > containerWidth) {
210
+ break;
211
+ }
212
+ count = nextCount;
213
+ }
214
+ }
215
+ return Math.max(1, count);
216
+ }, [getWidthForCount, items.length, strategy]);
217
+ const calculateByWidth = react.useCallback(() => {
218
+ if (!enabled || !items.length) {
219
+ setVisibleCount(prev => prev === items.length ? prev : items.length);
220
+ return;
221
+ }
222
+ const widths = getWidths();
223
+ if (!widths) {
224
+ return;
225
+ }
226
+ const nextCount = resolveVisibleCount(widths);
227
+ setVisibleCount(prev => prev === nextCount ? prev : nextCount);
228
+ }, [enabled, getWidths, items.length, resolveVisibleCount]);
229
+ const scheduleCalculate = react.useCallback(() => {
230
+ if (rafRef.current) {
231
+ window.cancelAnimationFrame(rafRef.current);
232
+ }
233
+ rafRef.current = window.requestAnimationFrame(() => {
234
+ rafRef.current = null;
235
+ calculateByWidth();
236
+ });
237
+ }, [calculateByWidth]);
238
+ react.useLayoutEffect(() => {
239
+ scheduleCalculate();
240
+ return () => {
241
+ if (rafRef.current) {
242
+ window.cancelAnimationFrame(rafRef.current);
243
+ rafRef.current = null;
244
+ }
245
+ };
246
+ }, [items, scheduleCalculate]);
247
+ react.useEffect(() => {
248
+ if (!enabled || !containerEl) {
249
+ return undefined;
250
+ }
251
+ const observer = new ResizeObserver(entries => {
252
+ const entry = entries.find(item => item.target === containerEl);
253
+ const nextWidth = entry?.contentRect.width ?? containerEl.clientWidth;
254
+ if (Math.abs(nextWidth - lastWidthRef.current) < 1) {
255
+ return;
256
+ }
257
+ lastWidthRef.current = nextWidth;
258
+ scheduleCalculate();
259
+ });
260
+ lastWidthRef.current = containerEl.clientWidth;
261
+ observer.observe(containerEl);
262
+ window.addEventListener('resize', scheduleCalculate);
263
+ return () => {
264
+ observer.disconnect();
265
+ window.removeEventListener('resize', scheduleCalculate);
266
+ if (rafRef.current) {
267
+ window.cancelAnimationFrame(rafRef.current);
268
+ rafRef.current = null;
269
+ }
270
+ };
271
+ }, [containerEl, enabled, scheduleCalculate]);
272
+ return {
273
+ setContainerRef,
274
+ setMeasureRef,
275
+ setMoreMeasureRef,
276
+ visibleCount
277
+ };
278
+ };
279
+
280
+ const isFilterListItem = item => {
281
+ if (!item) return false;
282
+ if (typeof item === 'function') return true;
283
+ return !!item.type;
284
+ };
285
+ const isNestedFilterList = list => {
286
+ if (!Array.isArray(list) || list.length === 0) return false;
287
+ return Array.isArray(list[0]) && !isFilterListItem(list[0]);
288
+ };
289
+ const normalizeFilterList = list => {
290
+ const safeList = Array.isArray(list) ? list : [];
291
+ if (!safeList.length) {
292
+ return {
293
+ mode: 'flat',
294
+ items: [],
295
+ lines: []
296
+ };
297
+ }
298
+ if (isNestedFilterList(safeList)) {
299
+ return {
300
+ mode: 'nested',
301
+ items: null,
302
+ lines: safeList
303
+ };
304
+ }
305
+ return {
306
+ mode: 'flat',
307
+ items: safeList,
308
+ lines: null
309
+ };
310
+ };
311
+ const getMobileFilterList = list => {
312
+ const {
313
+ mode,
314
+ items,
315
+ lines
316
+ } = normalizeFilterList(list);
317
+ if (mode === 'flat') return items;
318
+ return lines.reduce((result, line) => result.concat(line), []);
319
+ };
320
+
321
+ const isValidFilterItem = item => !!item && (item.type || typeof item === 'function');
322
+ const useFilterItemRenderer = () => {
130
323
  const _useContext = useContext(),
131
324
  value = _useContext.value,
132
325
  onChange = _useContext.onChange;
133
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
134
- className: style$1['filter-line'],
135
- children: [list.filter(item => !!item.type).map((item, index) => {
136
- if (typeof item === 'function') {
137
- return item(props => {
138
- return {
139
- index,
140
- value: value ? get__default["default"](value.get(props == null ? void 0 : props.name), 'value') : props == null ? void 0 : props.value,
141
- onChange: onChange ? value => onChange({
142
- name: props == null ? void 0 : props.name,
143
- label: props == null ? void 0 : props.label,
144
- value
145
- }) : props == null ? void 0 : props.onChange
146
- };
147
- });
148
- }
149
- const ComponentItem = item.type;
150
- return /*#__PURE__*/react.createElement(ComponentItem, _extends({}, Object.assign({}, item.props, {
151
- value: value ? get__default["default"](value.get(item.props.name), 'value') : item.props.value,
152
- onChange: onChange ? value => onChange({
153
- name: item.props.name,
154
- label: item.props.label,
155
- value
156
- }) : item.props.onChange
157
- }), {
158
- key: item.key || item.props.name || index
326
+ return react.useCallback((item, index) => {
327
+ if (typeof item === 'function') {
328
+ return item(props => ({
329
+ index,
330
+ value: value ? get__default["default"](value.get(props == null ? void 0 : props.name), 'value') : props == null ? void 0 : props.value,
331
+ onChange: onChange ? nextValue => onChange({
332
+ name: props == null ? void 0 : props.name,
333
+ label: props == null ? void 0 : props.label,
334
+ value: nextValue
335
+ }) : props == null ? void 0 : props.onChange
159
336
  }));
160
- }), children]
337
+ }
338
+ const ComponentItem = item.type;
339
+ return /*#__PURE__*/react.createElement(ComponentItem, _extends({}, Object.assign({}, item.props, {
340
+ value: value ? get__default["default"](value.get(item.props.name), 'value') : item.props.value,
341
+ onChange: onChange ? nextValue => onChange({
342
+ name: item.props.name,
343
+ label: item.props.label,
344
+ value: nextValue
345
+ }) : item.props.onChange
346
+ }), {
347
+ key: item.key || item.props.name || index
348
+ }));
349
+ }, [onChange, value]);
350
+ };
351
+ const Line$1 = _ref => {
352
+ let list = _ref.list,
353
+ children = _ref.children,
354
+ innerRef = _ref.innerRef,
355
+ nowrap = _ref.nowrap;
356
+ const renderItem = useFilterItemRenderer();
357
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
358
+ ref: innerRef,
359
+ className: classnames__default["default"](style$1['filter-line'], {
360
+ [style$1['filter-line-nowrap']]: nowrap
361
+ }),
362
+ children: [list.filter(isValidFilterItem).map((item, index) => renderItem(item, index)), children]
363
+ });
364
+ };
365
+ const CollapseButtons = _ref2 => {
366
+ let onClick = _ref2.onClick,
367
+ toggleUpText = _ref2.toggleUpText;
368
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
369
+ children: [/*#__PURE__*/jsxRuntime.jsx(antd.Space, {
370
+ size: 4,
371
+ className: classnames__default["default"](style$1['un-expand-shadow']),
372
+ children: /*#__PURE__*/jsxRuntime.jsxs(antd.Space, {
373
+ size: 4,
374
+ className: classnames__default["default"](style$1['option'], style$1['filter-item']),
375
+ children: [toggleUpText, /*#__PURE__*/jsxRuntime.jsx("span", {
376
+ className: style$1['filter-item-option-icon'],
377
+ children: "\u25B2"
378
+ })]
379
+ })
380
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Space, {
381
+ size: 4,
382
+ className: classnames__default["default"](style$1['un-expand']),
383
+ onClick: onClick,
384
+ children: /*#__PURE__*/jsxRuntime.jsxs(antd.Space, {
385
+ size: 4,
386
+ className: classnames__default["default"](style$1['option'], style$1['filter-item']),
387
+ children: [toggleUpText, /*#__PURE__*/jsxRuntime.jsx("span", {
388
+ className: style$1['filter-item-option-icon'],
389
+ children: "\u25B2"
390
+ })]
391
+ })
392
+ })]
161
393
  });
162
394
  };
163
- const FilterLines = _ref2 => {
164
- let className = _ref2.className,
165
- _ref2$list = _ref2.list,
166
- list = _ref2$list === void 0 ? [] : _ref2$list,
167
- _ref2$displayLine = _ref2.displayLine,
168
- displayLine = _ref2$displayLine === void 0 ? 1 : _ref2$displayLine,
169
- label = _ref2.label,
170
- extra = _ref2.extra,
171
- children = _ref2.children;
172
- const hasMore = list.length > displayLine;
173
- const mobileList = list.reduce((result, item) => result.concat(Array.isArray(item) ? item : [item]), []);
395
+ const FilterLines = _ref3 => {
396
+ let className = _ref3.className,
397
+ _ref3$list = _ref3.list,
398
+ list = _ref3$list === void 0 ? [] : _ref3$list,
399
+ _ref3$displayLine = _ref3.displayLine,
400
+ displayLine = _ref3$displayLine === void 0 ? 1 : _ref3$displayLine,
401
+ label = _ref3.label,
402
+ extra = _ref3.extra,
403
+ children = _ref3.children,
404
+ _ref3$visibleCountStr = _ref3.visibleCountStrategy,
405
+ visibleCountStrategy = _ref3$visibleCountStr === void 0 ? 'asc' : _ref3$visibleCountStr;
406
+ const _useMemo = react.useMemo(() => normalizeFilterList(list), [list]),
407
+ mode = _useMemo.mode,
408
+ flatItems = _useMemo.items,
409
+ lines = _useMemo.lines;
410
+ const mobileList = react.useMemo(() => getMobileFilterList(list), [list]);
411
+ const isFlatMode = mode === 'flat';
174
412
  const _useState = react.useState(false),
175
413
  isExpand = _useState[0],
176
414
  setIsExpand = _useState[1];
@@ -182,10 +420,38 @@ const FilterLines = _ref2 => {
182
420
  scrollRef = _useHorizontalScrollS.scrollRef,
183
421
  showScrollPrev = _useHorizontalScrollS.showScrollPrev,
184
422
  showScrollNext = _useHorizontalScrollS.showScrollNext;
423
+ const _useVisibleItemCount = useVisibleItemCount({
424
+ items: flatItems,
425
+ enabled: !isMobile && isFlatMode,
426
+ strategy: visibleCountStrategy
427
+ }),
428
+ setContainerRef = _useVisibleItemCount.setContainerRef,
429
+ setMeasureRef = _useVisibleItemCount.setMeasureRef,
430
+ setMoreMeasureRef = _useVisibleItemCount.setMoreMeasureRef,
431
+ visibleCount = _useVisibleItemCount.visibleCount;
432
+ const renderItem = useFilterItemRenderer();
185
433
  const _useIntl = reactIntl.useIntl({
186
434
  moduleName: 'Filter'
187
435
  }),
188
436
  formatMessage = _useIntl.formatMessage;
437
+ const visibleFlatItems = isFlatMode ? flatItems.slice(0, visibleCount) : [];
438
+ const hiddenFlatItems = isFlatMode ? flatItems.slice(visibleCount) : [];
439
+ const hasMoreFlat = hiddenFlatItems.length > 0;
440
+ const hasMoreNested = !isFlatMode && lines.length > displayLine;
441
+ const hasMore = isFlatMode ? hasMoreFlat : hasMoreNested;
442
+ const visibleLines = !isFlatMode ? lines.slice(0, displayLine) : [];
443
+ const hiddenLines = !isFlatMode ? lines.slice(displayLine) : [];
444
+ const showLabel = isFlatMode ? flatItems.length > 0 : lines.length > 0;
445
+ const setScrollContainerRef = react.useCallback(node => {
446
+ scrollRef.current = node;
447
+ }, [scrollRef]);
448
+ const setMeasureContainerRef = react.useCallback(node => {
449
+ if (!isMobile && isFlatMode) {
450
+ setContainerRef(node);
451
+ } else {
452
+ setContainerRef(null);
453
+ }
454
+ }, [isFlatMode, isMobile, setContainerRef]);
189
455
  const scrollToNext = react.useCallback(() => {
190
456
  const el = scrollRef.current;
191
457
  if (!el) return;
@@ -205,6 +471,62 @@ const FilterLines = _ref2 => {
205
471
  inline: 'center'
206
472
  });
207
473
  }, [isMobile, scrollRef]);
474
+ const toggleExpand = react.useCallback(() => {
475
+ setIsExpand(value => !value);
476
+ }, []);
477
+ const moreButtonLabel = /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
478
+ children: [formatMessage({
479
+ id: 'moreText'
480
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
481
+ className: style$1['filter-item-option-icon'],
482
+ children: "\u25BC"
483
+ })]
484
+ });
485
+ const moreButton = /*#__PURE__*/jsxRuntime.jsx(antd.Space, {
486
+ size: 4,
487
+ className: classnames__default["default"](style$1['filter-item'], style$1['option']),
488
+ onClick: toggleExpand,
489
+ children: moreButtonLabel
490
+ });
491
+ const renderDesktopContent = () => {
492
+ if (isFlatMode) {
493
+ return /*#__PURE__*/jsxRuntime.jsx(Line$1, {
494
+ list: visibleFlatItems,
495
+ nowrap: hasMoreFlat && !isExpand,
496
+ children: hasMoreFlat && !isExpand ? /*#__PURE__*/jsxRuntime.jsx("span", {
497
+ "data-filter-more": true,
498
+ children: moreButton
499
+ }) : null
500
+ });
501
+ }
502
+ return visibleLines.map((line, index) => /*#__PURE__*/jsxRuntime.jsx(Line$1, {
503
+ list: line,
504
+ children: hasMoreNested && !isExpand && index === displayLine - 1 ? moreButton : null
505
+ }, index));
506
+ };
507
+ const renderExpandedContent = () => {
508
+ if (isFlatMode) {
509
+ if (!hiddenFlatItems.length) return null;
510
+ return /*#__PURE__*/jsxRuntime.jsx(Line$1, {
511
+ list: hiddenFlatItems,
512
+ children: /*#__PURE__*/jsxRuntime.jsx(CollapseButtons, {
513
+ onClick: toggleExpand,
514
+ toggleUpText: formatMessage({
515
+ id: 'toggleUpText'
516
+ })
517
+ })
518
+ });
519
+ }
520
+ return hiddenLines.map((line, index) => /*#__PURE__*/jsxRuntime.jsx(Line$1, {
521
+ list: line,
522
+ children: index === hiddenLines.length - 1 ? /*#__PURE__*/jsxRuntime.jsx(CollapseButtons, {
523
+ onClick: toggleExpand,
524
+ toggleUpText: formatMessage({
525
+ id: 'toggleUpText'
526
+ })
527
+ }) : null
528
+ }, index));
529
+ };
208
530
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
209
531
  children: [/*#__PURE__*/jsxRuntime.jsxs(antd.Space, {
210
532
  className: classnames__default["default"](style$1['filter-title'], 'filter-title', className),
@@ -212,7 +534,7 @@ const FilterLines = _ref2 => {
212
534
  size: 16,
213
535
  children: [/*#__PURE__*/jsxRuntime.jsx("span", {
214
536
  className: style$1['filter-label'],
215
- children: list && list.length > 0 && (label || formatMessage({
537
+ children: showLabel && (label || formatMessage({
216
538
  id: 'filterText'
217
539
  }))
218
540
  }), /*#__PURE__*/jsxRuntime.jsxs(antd.Row, {
@@ -223,29 +545,38 @@ const FilterLines = _ref2 => {
223
545
  className: style$1['filter-list'],
224
546
  flex: 1,
225
547
  children: /*#__PURE__*/jsxRuntime.jsxs("div", {
226
- className: style$1['filter-list-scroll-wrap'],
227
- children: [isMobile && showScrollPrev ? /*#__PURE__*/jsxRuntime.jsx("div", {
548
+ ref: setMeasureContainerRef,
549
+ className: classnames__default["default"](style$1['filter-list-scroll-wrap'], {
550
+ [style$1['filter-list-constrained']]: !isMobile && isFlatMode
551
+ }),
552
+ children: [!isMobile && isFlatMode ? /*#__PURE__*/jsxRuntime.jsxs("div", {
553
+ ref: setMeasureRef,
554
+ className: classnames__default["default"](style$1['filter-line'], style$1['filter-line-measure']),
555
+ "aria-hidden": true,
556
+ children: [flatItems.filter(isValidFilterItem).map((item, index) => {
557
+ var _item$props;
558
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
559
+ "data-filter-measure-item": true,
560
+ children: renderItem(item, index)
561
+ }, item.key || ((_item$props = item.props) == null ? void 0 : _item$props.name) || index);
562
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
563
+ ref: setMoreMeasureRef,
564
+ "data-filter-measure-more": true,
565
+ children: /*#__PURE__*/jsxRuntime.jsx(antd.Space, {
566
+ size: 4,
567
+ className: classnames__default["default"](style$1['filter-item'], style$1['option']),
568
+ children: moreButtonLabel
569
+ })
570
+ })]
571
+ }) : null, isMobile && showScrollPrev ? /*#__PURE__*/jsxRuntime.jsx("div", {
228
572
  className: style$1['filter-scroll-prev-shadow']
229
573
  }) : null, /*#__PURE__*/jsxRuntime.jsx("div", {
230
574
  className: style$1['filter-list-scroll'],
231
- ref: scrollRef,
575
+ ref: setScrollContainerRef,
232
576
  onClick: scrollItemIntoView,
233
- children: (isMobile ? mobileList : list.slice(0, displayLine)).map((item, index) => /*#__PURE__*/jsxRuntime.jsx(Line$1, {
234
- list: isMobile ? [item] : item,
235
- children: !isMobile && hasMore && isExpand === false && index === displayLine - 1 ? /*#__PURE__*/jsxRuntime.jsxs(antd.Space, {
236
- size: 4,
237
- className: classnames__default["default"](style$1['filter-item'], style$1['option']),
238
- onClick: () => {
239
- setIsExpand(value => !value);
240
- },
241
- children: [formatMessage({
242
- id: 'moreText'
243
- }), /*#__PURE__*/jsxRuntime.jsx("span", {
244
- className: style$1['filter-item-option-icon'],
245
- children: "\u25BC"
246
- })]
247
- }) : null
248
- }, index))
577
+ children: isMobile ? mobileList.map((item, index) => /*#__PURE__*/jsxRuntime.jsx(Line$1, {
578
+ list: [item]
579
+ }, index)) : renderDesktopContent()
249
580
  }), isMobile && showScrollNext ? /*#__PURE__*/jsxRuntime.jsx("button", {
250
581
  type: "button",
251
582
  className: style$1['filter-scroll-next'],
@@ -279,41 +610,7 @@ const FilterLines = _ref2 => {
279
610
  })
280
611
  }), /*#__PURE__*/jsxRuntime.jsx("div", {
281
612
  className: style$1['filter-list'],
282
- children: list.slice(displayLine).map((item, index) => /*#__PURE__*/jsxRuntime.jsx(Line$1, {
283
- list: item,
284
- children: index === list.length - displayLine - 1 && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
285
- children: [/*#__PURE__*/jsxRuntime.jsx(antd.Space, {
286
- size: 4,
287
- className: classnames__default["default"](style$1['un-expand-shadow']),
288
- children: /*#__PURE__*/jsxRuntime.jsxs(antd.Space, {
289
- size: 4,
290
- className: classnames__default["default"](style$1['option'], style$1['filter-item']),
291
- children: [formatMessage({
292
- id: 'toggleUpText'
293
- }), /*#__PURE__*/jsxRuntime.jsx("span", {
294
- className: style$1['filter-item-option-icon'],
295
- children: "\u25B2"
296
- })]
297
- })
298
- }), /*#__PURE__*/jsxRuntime.jsx(antd.Space, {
299
- size: 4,
300
- className: classnames__default["default"](style$1['un-expand']),
301
- onClick: () => {
302
- setIsExpand(value => !value);
303
- },
304
- children: /*#__PURE__*/jsxRuntime.jsxs(antd.Space, {
305
- size: 4,
306
- className: classnames__default["default"](style$1['option'], style$1['filter-item']),
307
- children: [formatMessage({
308
- id: 'toggleUpText'
309
- }), /*#__PURE__*/jsxRuntime.jsx("span", {
310
- className: style$1['filter-item-option-icon'],
311
- children: "\u25B2"
312
- })]
313
- })
314
- })]
315
- })
316
- }, index))
613
+ children: renderExpandedContent()
317
614
  })]
318
615
  })]
319
616
  });
@@ -1438,6 +1735,15 @@ const NumberRangeFilterItem = withInputDefaultPlaceholder(NumberRangeFilterItem$
1438
1735
  const SuperSelectFilterItem = withFieldItem(SuperSelect__default["default"], {
1439
1736
  forcePopup: true
1440
1737
  });
1738
+ const SelectTableListFilterItem = withFieldItem(SuperSelect.SelectTableList, {
1739
+ forcePopup: true
1740
+ });
1741
+ const SelectTreeFilterItem = withFieldItem(SuperSelect.SelectTree, {
1742
+ forcePopup: true
1743
+ });
1744
+ const SelectCascaderFilterItem = withFieldItem(SuperSelect.SelectCascader, {
1745
+ forcePopup: true
1746
+ });
1441
1747
  const SelectFunctionFilterItem = withFieldItem(superSelectPlus.SelectFunction, {
1442
1748
  forcePopup: true
1443
1749
  });
@@ -1453,6 +1759,9 @@ var fields$1 = {
1453
1759
  InputFilterItem: InputFilterItem$1,
1454
1760
  NumberRangeFilterItem: NumberRangeFilterItem,
1455
1761
  SuperSelectFilterItem: SuperSelectFilterItem,
1762
+ SelectTableListFilterItem: SelectTableListFilterItem,
1763
+ SelectTreeFilterItem: SelectTreeFilterItem,
1764
+ SelectCascaderFilterItem: SelectCascaderFilterItem,
1456
1765
  SelectFunctionFilterItem: SelectFunctionFilterItem,
1457
1766
  SelectIndustryFilterItem: SelectIndustryFilterItem,
1458
1767
  SelectAddressFilterItem: SelectAddressFilterItem,
@@ -1493,33 +1802,90 @@ const withFilterValue = WrappedComponent => {
1493
1802
  };
1494
1803
  };
1495
1804
 
1496
- const _excluded$2 = ["label", "onChange", "value", "placeholder"];
1805
+ const _excluded$2 = ["label", "onChange", "value", "placeholder", "searchDelay"];
1497
1806
  const Search = antd.Input.Search;
1498
- const SearchInput = withFilterValue(_ref => {
1807
+ const SearchInput = withLocale(withFilterValue(_ref => {
1499
1808
  let label = _ref.label,
1500
1809
  onChange = _ref.onChange,
1501
1810
  value = _ref.value,
1502
1811
  placeholder = _ref.placeholder,
1812
+ _ref$searchDelay = _ref.searchDelay,
1813
+ searchDelay = _ref$searchDelay === void 0 ? 500 : _ref$searchDelay,
1503
1814
  props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
1504
1815
  const _useIntl = reactIntl.useIntl({
1505
1816
  moduleName: 'Filter'
1506
1817
  }),
1507
1818
  formatMessage = _useIntl.formatMessage;
1819
+ const propsValue = value == null ? void 0 : value.value;
1820
+ const _useState = react.useState(propsValue || ''),
1821
+ inputValue = _useState[0],
1822
+ setInputValue = _useState[1];
1823
+ const inputValueRef = react.useRef('');
1824
+ const onChangeRef = react.useRef(onChange);
1825
+ const searchTimerRef = react.useRef(null);
1826
+ const isComposingRef = react.useRef(false);
1827
+ inputValueRef.current = inputValue;
1828
+ onChangeRef.current = onChange;
1829
+ const clearSearchTimer = () => {
1830
+ if (searchTimerRef.current) {
1831
+ clearTimeout(searchTimerRef.current);
1832
+ searchTimerRef.current = null;
1833
+ }
1834
+ };
1835
+ const submitSearch = searchValue => {
1836
+ onChangeRef.current == null || onChangeRef.current(searchValue ? {
1837
+ label: searchValue,
1838
+ value: searchValue
1839
+ } : null);
1840
+ };
1841
+ const scheduleSearch = searchValue => {
1842
+ clearSearchTimer();
1843
+ searchTimerRef.current = setTimeout(() => {
1844
+ searchTimerRef.current = null;
1845
+ submitSearch(searchValue);
1846
+ }, searchDelay);
1847
+ };
1848
+ react.useEffect(() => {
1849
+ if (propsValue !== inputValueRef.current) {
1850
+ clearSearchTimer();
1851
+ setInputValue(propsValue || '');
1852
+ }
1853
+ }, [propsValue]);
1854
+ react.useEffect(() => {
1855
+ return () => {
1856
+ clearSearchTimer();
1857
+ };
1858
+ }, []);
1508
1859
  return /*#__PURE__*/jsxRuntime.jsx(Search, _extends({}, props, {
1509
1860
  placeholder: placeholder || formatMessage({
1510
1861
  id: 'inputPlaceholder'
1511
1862
  }, {
1512
1863
  label
1513
1864
  }),
1514
- value: (value == null ? void 0 : value.value) || '',
1515
- onSearch: value => {
1516
- onChange({
1517
- label: value,
1518
- value
1519
- });
1865
+ value: inputValue,
1866
+ onChange: e => {
1867
+ const nextValue = e.target.value;
1868
+ setInputValue(nextValue);
1869
+ if (!isComposingRef.current) {
1870
+ scheduleSearch(nextValue);
1871
+ }
1872
+ },
1873
+ onCompositionStart: () => {
1874
+ isComposingRef.current = true;
1875
+ clearSearchTimer();
1876
+ },
1877
+ onCompositionEnd: e => {
1878
+ isComposingRef.current = false;
1879
+ const nextValue = e.target.value;
1880
+ setInputValue(nextValue);
1881
+ scheduleSearch(nextValue);
1882
+ },
1883
+ onSearch: searchValue => {
1884
+ clearSearchTimer();
1885
+ submitSearch(searchValue);
1520
1886
  }
1521
1887
  }));
1522
- });
1888
+ }));
1523
1889
 
1524
1890
  /**
1525
1891
  * 从筛选值中提取原始值数组。
@@ -2452,8 +2818,11 @@ exports.NumberRangeFilterItem = NumberRangeFilterItem;
2452
2818
  exports.PopoverItem = PopoverItem;
2453
2819
  exports.SearchInput = SearchInput;
2454
2820
  exports.SelectAddressFilterItem = SelectAddressFilterItem;
2821
+ exports.SelectCascaderFilterItem = SelectCascaderFilterItem;
2455
2822
  exports.SelectFunctionFilterItem = SelectFunctionFilterItem;
2456
2823
  exports.SelectIndustryFilterItem = SelectIndustryFilterItem;
2824
+ exports.SelectTableListFilterItem = SelectTableListFilterItem;
2825
+ exports.SelectTreeFilterItem = SelectTreeFilterItem;
2457
2826
  exports.SuperSelectFilterItem = SuperSelectFilterItem;
2458
2827
  exports.TypeDateRangePickerField = TypeDateRangePickerField;
2459
2828
  exports.TypeDateRangePickerFilterItem = TypeDateRangePickerFilterItem;