|
|
|
@ -48,26 +48,28 @@ class Mentions extends React.Component<MentionProps, MentionState> {
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
.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!.length),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (hitPrefix !== null) {
|
|
|
|
|
return {
|
|
|
|
|
prefix: hitPrefix,
|
|
|
|
|
value: str.slice(hitPrefix!.length),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
})
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
.filter((entity): entity is MentionsEntity => !!entity && !!entity.value);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -75,6 +77,8 @@ class Mentions extends React.Component<MentionProps, MentionState> {
|
|
|
|
|
focused: false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private rcMentions: any;
|
|
|
|
|
|
|
|
|
|
onFocus: React.FocusEventHandler<HTMLTextAreaElement> = (...args) => {
|
|
|
|
|
const { onFocus } = this.props;
|
|
|
|
|
if (onFocus) {
|
|
|
|
@ -125,6 +129,18 @@ class Mentions extends React.Component<MentionProps, MentionState> {
|
|
|
|
|
return filterOption;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
saveMentions = (node: typeof RcMentions) => {
|
|
|
|
|
this.rcMentions = node;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
focus() {
|
|
|
|
|
this.rcMentions.focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
blur() {
|
|
|
|
|
this.rcMentions.blur();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderMentions = ({ getPrefixCls, renderEmpty }: ConfigConsumerProps) => {
|
|
|
|
|
const { focused } = this.state;
|
|
|
|
|
const { prefixCls: customizePrefixCls, className, disabled, ...restProps } = this.props;
|
|
|
|
@ -146,6 +162,7 @@ class Mentions extends React.Component<MentionProps, MentionState> {
|
|
|
|
|
filterOption={this.getFilterOption()}
|
|
|
|
|
onFocus={this.onFocus}
|
|
|
|
|
onBlur={this.onBlur}
|
|
|
|
|
ref={this.saveMentions}
|
|
|
|
|
>
|
|
|
|
|
{this.getOptions()}
|
|
|
|
|
</RcMentions>
|
|
|
|
|