Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions components/mentions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<MentionsEntity[]>((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;
4 changes: 3 additions & 1 deletion components/select/style/select-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ const genSelectInputStyle: GenerateStyle<SelectToken, CSSObject> = (token) => {
margin: 0,
padding: 0,
color: varRef('color'),
fontFamily: 'inherit',
fontSize: 'inherit',

'&::-webkit-search-cancel-button': {
display: 'none',
Expand All @@ -287,7 +289,7 @@ const genSelectInputStyle: GenerateStyle<SelectToken, CSSObject> = (token) => {
[`${componentCls}-input`]: {
position: 'absolute',
inset: 0,
lineHeight: `calc(${varRef('font-height')} + ${varRef('padding-vertical')} * 2)`,
lineHeight: 'inherit',
},

// Content center align
Expand Down
16 changes: 9 additions & 7 deletions components/table/hooks/useFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,21 @@ const useFilter = <RecordType extends AnyObject = AnyObject>(
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<FilterState<RecordType>[]>((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(
Expand Down
163 changes: 87 additions & 76 deletions components/table/hooks/useSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,79 +295,82 @@ const useSelection = <RecordType extends AnyObject = AnyObject>(
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<Key[]>((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,
Expand Down Expand Up @@ -402,9 +405,13 @@ const useSelection = <RecordType extends AnyObject = AnyObject>(
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<Key[]>((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));

Expand Down Expand Up @@ -469,13 +476,17 @@ const useSelection = <RecordType extends AnyObject = AnyObject>(
);
}

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<Partial<CheckboxProps> & { 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;
Expand Down
9 changes: 6 additions & 3 deletions components/table/hooks/useSorter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,12 @@ const stateToInfo = <RecordType extends AnyObject = AnyObject>(
const generateSorterInfo = <RecordType extends AnyObject = AnyObject>(
sorterStates: SortState<RecordType>[],
): SorterResult<RecordType> | SorterResult<RecordType>[] => {
const activeSorters = sorterStates
.filter(({ sortOrder }) => sortOrder)
.map<SorterResult<RecordType>>(stateToInfo);
const activeSorters = sorterStates.reduce<SorterResult<RecordType>[]>((list, sorterState) => {
if (sorterState.sortOrder) {
list.push(stateToInfo(sorterState));
}
return list;
}, []);

// =========== Legacy compatible support ===========
// https://github.com/ant-design/ant-design/pull/19226
Expand Down
Loading