#38 Show alert when mention is added to limited post

This commit is contained in:
KMY 2023-09-28 16:17:58 +09:00
parent 62b7b7a9b9
commit d75c8506ce
3 changed files with 42 additions and 2 deletions

View file

@ -0,0 +1,29 @@
const MENTION_SEPARATORS = '_\\u00b7\\u200c';
const ALPHA = '\\p{L}\\p{M}';
const WORD = '\\p{L}\\p{M}\\p{N}\\p{Pc}';
const buildMentionPatternRegex = () => {
try {
return new RegExp(
`(?:^|[^\\/\\)\\w])@(([${WORD}_][${WORD}${MENTION_SEPARATORS}]*[${ALPHA}${MENTION_SEPARATORS}][${WORD}${MENTION_SEPARATORS}]*[${WORD}_])|([${WORD}_]*[${ALPHA}][${WORD}_]*))`,
'iu',
);
} catch {
return /(?:^|[^/)\w])#(\w*[a-zA-Z·]\w*)/i;
}
};
const buildMentionRegex = () => {
try {
return new RegExp(
`^(([${WORD}_][${WORD}${MENTION_SEPARATORS}]*[${ALPHA}${MENTION_SEPARATORS}][${WORD}${MENTION_SEPARATORS}]*[${WORD}_])|([${WORD}_]*[${ALPHA}][${WORD}_]*))$`,
'iu',
);
} catch {
return /^(\w*[a-zA-Z·]\w*)$/i;
}
};
export const MENTION_PATTERN_REGEX = buildMentionPatternRegex();
export const MENTION_REGEX = buildMentionRegex();