@kne/react-filter 1.0.4 → 1.0.5
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/README.md +283 -227
- package/dist/index.js +66 -9
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +64 -10
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1493,33 +1493,90 @@ const withFilterValue = WrappedComponent => {
|
|
|
1493
1493
|
};
|
|
1494
1494
|
};
|
|
1495
1495
|
|
|
1496
|
-
const _excluded$2 = ["label", "onChange", "value", "placeholder"];
|
|
1496
|
+
const _excluded$2 = ["label", "onChange", "value", "placeholder", "searchDelay"];
|
|
1497
1497
|
const Search = antd.Input.Search;
|
|
1498
|
-
const SearchInput = withFilterValue(_ref => {
|
|
1498
|
+
const SearchInput = withLocale(withFilterValue(_ref => {
|
|
1499
1499
|
let label = _ref.label,
|
|
1500
1500
|
onChange = _ref.onChange,
|
|
1501
1501
|
value = _ref.value,
|
|
1502
1502
|
placeholder = _ref.placeholder,
|
|
1503
|
+
_ref$searchDelay = _ref.searchDelay,
|
|
1504
|
+
searchDelay = _ref$searchDelay === void 0 ? 500 : _ref$searchDelay,
|
|
1503
1505
|
props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
1504
1506
|
const _useIntl = reactIntl.useIntl({
|
|
1505
1507
|
moduleName: 'Filter'
|
|
1506
1508
|
}),
|
|
1507
1509
|
formatMessage = _useIntl.formatMessage;
|
|
1510
|
+
const propsValue = value == null ? void 0 : value.value;
|
|
1511
|
+
const _useState = react.useState(propsValue || ''),
|
|
1512
|
+
inputValue = _useState[0],
|
|
1513
|
+
setInputValue = _useState[1];
|
|
1514
|
+
const inputValueRef = react.useRef('');
|
|
1515
|
+
const onChangeRef = react.useRef(onChange);
|
|
1516
|
+
const searchTimerRef = react.useRef(null);
|
|
1517
|
+
const isComposingRef = react.useRef(false);
|
|
1518
|
+
inputValueRef.current = inputValue;
|
|
1519
|
+
onChangeRef.current = onChange;
|
|
1520
|
+
const clearSearchTimer = () => {
|
|
1521
|
+
if (searchTimerRef.current) {
|
|
1522
|
+
clearTimeout(searchTimerRef.current);
|
|
1523
|
+
searchTimerRef.current = null;
|
|
1524
|
+
}
|
|
1525
|
+
};
|
|
1526
|
+
const submitSearch = searchValue => {
|
|
1527
|
+
onChangeRef.current == null || onChangeRef.current(searchValue ? {
|
|
1528
|
+
label: searchValue,
|
|
1529
|
+
value: searchValue
|
|
1530
|
+
} : null);
|
|
1531
|
+
};
|
|
1532
|
+
const scheduleSearch = searchValue => {
|
|
1533
|
+
clearSearchTimer();
|
|
1534
|
+
searchTimerRef.current = setTimeout(() => {
|
|
1535
|
+
searchTimerRef.current = null;
|
|
1536
|
+
submitSearch(searchValue);
|
|
1537
|
+
}, searchDelay);
|
|
1538
|
+
};
|
|
1539
|
+
react.useEffect(() => {
|
|
1540
|
+
if (propsValue !== inputValueRef.current) {
|
|
1541
|
+
clearSearchTimer();
|
|
1542
|
+
setInputValue(propsValue || '');
|
|
1543
|
+
}
|
|
1544
|
+
}, [propsValue]);
|
|
1545
|
+
react.useEffect(() => {
|
|
1546
|
+
return () => {
|
|
1547
|
+
clearSearchTimer();
|
|
1548
|
+
};
|
|
1549
|
+
}, []);
|
|
1508
1550
|
return /*#__PURE__*/jsxRuntime.jsx(Search, _extends({}, props, {
|
|
1509
1551
|
placeholder: placeholder || formatMessage({
|
|
1510
1552
|
id: 'inputPlaceholder'
|
|
1511
1553
|
}, {
|
|
1512
1554
|
label
|
|
1513
1555
|
}),
|
|
1514
|
-
value:
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1556
|
+
value: inputValue,
|
|
1557
|
+
onChange: e => {
|
|
1558
|
+
const nextValue = e.target.value;
|
|
1559
|
+
setInputValue(nextValue);
|
|
1560
|
+
if (!isComposingRef.current) {
|
|
1561
|
+
scheduleSearch(nextValue);
|
|
1562
|
+
}
|
|
1563
|
+
},
|
|
1564
|
+
onCompositionStart: () => {
|
|
1565
|
+
isComposingRef.current = true;
|
|
1566
|
+
clearSearchTimer();
|
|
1567
|
+
},
|
|
1568
|
+
onCompositionEnd: e => {
|
|
1569
|
+
isComposingRef.current = false;
|
|
1570
|
+
const nextValue = e.target.value;
|
|
1571
|
+
setInputValue(nextValue);
|
|
1572
|
+
scheduleSearch(nextValue);
|
|
1573
|
+
},
|
|
1574
|
+
onSearch: searchValue => {
|
|
1575
|
+
clearSearchTimer();
|
|
1576
|
+
submitSearch(searchValue);
|
|
1520
1577
|
}
|
|
1521
1578
|
}));
|
|
1522
|
-
});
|
|
1579
|
+
}));
|
|
1523
1580
|
|
|
1524
1581
|
/**
|
|
1525
1582
|
* 从筛选值中提取原始值数组。
|