diff --git a/components/mentions/index.tsx b/components/mentions/index.tsx index aae40b17069e..1fdac041ad37 100644 --- a/components/mentions/index.tsx +++ b/components/mentions/index.tsx @@ -318,29 +318,29 @@ Mentions.getMentions = (value = '', config: MentionsConfig = {}): MentionsEntity const { prefix = '@', split = ' ' } = config; const prefixList: string[] = toList(prefix); - return value - .split(split) - .map((str = ''): MentionsEntity | null => { - let hitPrefix: string | null = null; - - prefixList.some((prefixStr) => { - const startStr = str.slice(0, prefixStr.length); - if (startStr === prefixStr) { - hitPrefix = prefixStr; - return true; - } - return false; - }); - - if (hitPrefix !== null) { - return { - prefix: hitPrefix, - value: str.slice((hitPrefix as string).length), - }; + return value.split(split).reduce((list, str = '') => { + let hitPrefix: string | null = null; + + prefixList.some((prefixStr) => { + const startStr = str.slice(0, prefixStr.length); + if (startStr === prefixStr) { + hitPrefix = prefixStr; + return true; } - return null; - }) - .filter((entity): entity is MentionsEntity => !!entity && !!entity.value); + return false; + }); + + if (hitPrefix !== null) { + const entity = { + prefix: hitPrefix, + value: str.slice((hitPrefix as string).length), + }; + if (entity.value) { + list.push(entity); + } + } + return list; + }, []); }; export default Mentions; diff --git a/components/select/style/select-input.ts b/components/select/style/select-input.ts index 091df45be9e8..f53913d1e9a4 100644 --- a/components/select/style/select-input.ts +++ b/components/select/style/select-input.ts @@ -270,6 +270,8 @@ const genSelectInputStyle: GenerateStyle = (token) => { margin: 0, padding: 0, color: varRef('color'), + fontFamily: 'inherit', + fontSize: 'inherit', '&::-webkit-search-cancel-button': { display: 'none', @@ -287,7 +289,7 @@ const genSelectInputStyle: GenerateStyle = (token) => { [`${componentCls}-input`]: { position: 'absolute', inset: 0, - lineHeight: `calc(${varRef('font-height')} + ${varRef('padding-vertical')} * 2)`, + lineHeight: 'inherit', }, // Content center align diff --git a/components/table/hooks/useFilter/index.tsx b/components/table/hooks/useFilter/index.tsx index afdcc959833d..11947b360b6a 100644 --- a/components/table/hooks/useFilter/index.tsx +++ b/components/table/hooks/useFilter/index.tsx @@ -290,19 +290,21 @@ const useFilter = ( const keyList = (mergedColumns || []).map((column, index) => getColumnKey(column, getColumnPos(index)), ); - return filterStates - .filter(({ key }) => keyList.includes(key)) - .map((item) => { - const col = mergedColumns[keyList.indexOf(item.key)]; - return { + return filterStates.reduce[]>((list, item) => { + const keyIndex = keyList.indexOf(item.key); + if (keyIndex !== -1) { + const col = mergedColumns[keyIndex]; + list.push({ ...item, column: { ...item.column, ...col, }, forceFiltered: col.filtered, - }; - }); + }); + } + return list; + }, []); } warning( diff --git a/components/table/hooks/useSelection.tsx b/components/table/hooks/useSelection.tsx index 48d3a47aa5ea..703c85fb3924 100644 --- a/components/table/hooks/useSelection.tsx +++ b/components/table/hooks/useSelection.tsx @@ -295,79 +295,82 @@ const useSelection = ( const selectionList: INTERNAL_SELECTION_ITEM[] = selections === true ? [SELECTION_ALL, SELECTION_INVERT, SELECTION_NONE] : selections; - return selectionList - .map((selection: INTERNAL_SELECTION_ITEM) => { - if (selection === SELECTION_ALL) { - return { - key: 'all', - text: tableLocale.selectionAll, - onSelect() { - setSelectedKeys( - data - .map((record, index) => getRowKey(record, index)) - .filter((key) => { - const checkProps = checkboxPropsMap.get(key); - return !checkProps?.disabled || derivedSelectedKeySet.has(key); - }), - 'all', - ); - }, - }; - } - if (selection === SELECTION_INVERT) { - return { - key: 'invert', - text: tableLocale.selectInvert, - onSelect() { - const keySet = new Set(derivedSelectedKeySet); - pageData.forEach((record, index) => { + return selectionList.map((selection: INTERNAL_SELECTION_ITEM) => { + let mergedSelection: SelectionItem; + + if (selection === SELECTION_ALL) { + mergedSelection = { + key: 'all', + text: tableLocale.selectionAll, + onSelect() { + setSelectedKeys( + data.reduce((keys, record, index) => { const key = getRowKey(record, index); const checkProps = checkboxPropsMap.get(key); - - if (!checkProps?.disabled) { - if (keySet.has(key)) { - keySet.delete(key); - } else { - keySet.add(key); - } + if (!checkProps?.disabled || derivedSelectedKeySet.has(key)) { + keys.push(key); + } + return keys; + }, []), + 'all', + ); + }, + }; + } else if (selection === SELECTION_INVERT) { + mergedSelection = { + key: 'invert', + text: tableLocale.selectInvert, + onSelect() { + const keySet = new Set(derivedSelectedKeySet); + pageData.forEach((record, index) => { + const key = getRowKey(record, index); + const checkProps = checkboxPropsMap.get(key); + + if (!checkProps?.disabled) { + if (keySet.has(key)) { + keySet.delete(key); + } else { + keySet.add(key); } - }); - - const keys = Array.from(keySet); - if (onSelectInvert) { - warning.deprecated(false, 'onSelectInvert', 'onChange'); - onSelectInvert(keys); } + }); - setSelectedKeys(keys, 'invert'); - }, - }; - } - if (selection === SELECTION_NONE) { - return { - key: 'none', - text: tableLocale.selectNone, - onSelect() { - onSelectNone?.(); - setSelectedKeys( - Array.from(derivedSelectedKeySet).filter((key) => { - const checkProps = checkboxPropsMap.get(key); - return checkProps?.disabled; - }), - 'none', - ); - }, - }; - } - return selection as SelectionItem; - }) - .map((selection) => ({ - ...selection, - onSelect: (...rest) => { - selection.onSelect?.(...rest); + const keys = Array.from(keySet); + if (onSelectInvert) { + warning.deprecated(false, 'onSelectInvert', 'onChange'); + onSelectInvert(keys); + } + + setSelectedKeys(keys, 'invert'); + }, + }; + } else if (selection === SELECTION_NONE) { + mergedSelection = { + key: 'none', + text: tableLocale.selectNone, + onSelect() { + onSelectNone?.(); + setSelectedKeys( + Array.from(derivedSelectedKeySet).filter((key) => { + const checkProps = checkboxPropsMap.get(key); + return checkProps?.disabled; + }), + 'none', + ); + }, + }; + } else { + mergedSelection = selection as SelectionItem; + } + + return { + ...mergedSelection, + onSelect: (currentRowKeys) => { + mergedSelection.onSelect?.(currentRowKeys); updatePrevSelectedIndex(null); }, - })); + }; + }); }, [ selections, hideSelectAll, @@ -402,9 +405,13 @@ const useSelection = ( const keySet = new Set(derivedSelectedKeySet); // Record key only need check with enabled - const recordKeys = flattedData - .map(getRowKey) - .filter((key) => !checkboxPropsMap.get(key)!.disabled); + const recordKeys = flattedData.reduce((keys, record, index) => { + const key = getRowKey(record, index); + if (!checkboxPropsMap.get(key)!.disabled) { + keys.push(key); + } + return keys; + }, []); const checkedCurrentAll = recordKeys.every((key) => keySet.has(key)); const checkedCurrentSome = recordKeys.some((key) => keySet.has(key)); @@ -469,13 +476,17 @@ const useSelection = ( ); } - const allDisabledData = flattedData - .map((record, index) => { - const key = getRowKey(record, index); - const checkboxProps = checkboxPropsMap.get(key) || {}; - return { checked: keySet.has(key), ...checkboxProps }; - }) - .filter(({ disabled }) => disabled); + const allDisabledData = flattedData.reduce< + Array & { checked?: boolean }> + >((list, record, index) => { + const key = getRowKey(record, index); + const checkboxProps = checkboxPropsMap.get(key) || {}; + const item = { checked: keySet.has(key), ...checkboxProps }; + if (item.disabled) { + list.push(item); + } + return list; + }, []); const allDisabled = !!allDisabledData.length && allDisabledData.length === flattedData.length; diff --git a/components/table/hooks/useSorter.tsx b/components/table/hooks/useSorter.tsx index 11bd59612779..44e3066654f0 100644 --- a/components/table/hooks/useSorter.tsx +++ b/components/table/hooks/useSorter.tsx @@ -296,9 +296,12 @@ const stateToInfo = ( const generateSorterInfo = ( sorterStates: SortState[], ): SorterResult | SorterResult[] => { - const activeSorters = sorterStates - .filter(({ sortOrder }) => sortOrder) - .map>(stateToInfo); + const activeSorters = sorterStates.reduce[]>((list, sorterState) => { + if (sorterState.sortOrder) { + list.push(stateToInfo(sorterState)); + } + return list; + }, []); // =========== Legacy compatible support =========== // https://github.com/ant-design/ant-design/pull/19226