1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00
vault-frontend/src/constants/comment.ts
2021-10-06 12:09:33 +07:00

40 lines
1,013 B
TypeScript

import { CommentTextBlock } from '~/components/comment/CommentTextBlock';
import { CommentEmbedBlock } from '~/components/comment/CommentEmbedBlock';
export const COMMENT_BLOCK_TYPES = {
TEXT: 'TEXT',
MARK: 'MARK',
EMBED: 'EMBED',
};
export const COMMENT_BLOCK_DETECTORS = [
{
type: COMMENT_BLOCK_TYPES.EMBED,
test: /(https?:\/\/(www\.)?(youtube\.com|youtu\.be)\/(watch)?(\?v=)?[\w\-\&\=]+)/gim,
},
{
type: COMMENT_BLOCK_TYPES.MARK,
test: /^[\n\s]{0,}?<\.{3}>[\n\s]{0,}$/gi,
},
{
type: COMMENT_BLOCK_TYPES.TEXT,
test: /^.*$/gi,
},
];
export type ICommentBlock = {
type: typeof COMMENT_BLOCK_TYPES[keyof typeof COMMENT_BLOCK_TYPES];
content: string;
};
export type ICommentBlockProps = {
block: ICommentBlock;
};
export const COMMENT_BLOCK_RENDERERS = {
[COMMENT_BLOCK_TYPES.TEXT]: CommentTextBlock,
[COMMENT_BLOCK_TYPES.MARK]: CommentTextBlock,
[COMMENT_BLOCK_TYPES.EMBED]: CommentEmbedBlock,
};
export const NEW_COMMENT_CLASSNAME = 'newComment';