123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import { BlockData, BlockType } from '$app/interfaces/document';
- export enum SplitRelationship {
- NextSibling,
- FirstChild,
- }
- /**
- * If the block type is not in the config, it will be thrown an error in development env
- */
- export const blockConfig: Record<
- string,
- {
- /**
- * Whether the block can have children
- */
- canAddChild: boolean;
- /**
- * The regexps that will be used to match the markdown flag
- */
- markdownRegexps?: RegExp[];
- /**
- * The default data of the block
- */
- defaultData?: BlockData<any>;
- /**
- * The props that will be passed to the text split function
- */
- splitProps?: {
- /**
- * The relationship between the next line block and the current block
- */
- nextLineRelationShip: SplitRelationship;
- /**
- * The type of the next line block
- */
- nextLineBlockType: BlockType;
- };
- }
- > = {
- [BlockType.TextBlock]: {
- canAddChild: true,
- defaultData: {
- delta: [],
- },
- splitProps: {
- nextLineRelationShip: SplitRelationship.NextSibling,
- nextLineBlockType: BlockType.TextBlock,
- },
- },
- [BlockType.HeadingBlock]: {
- canAddChild: false,
- splitProps: {
- nextLineRelationShip: SplitRelationship.NextSibling,
- nextLineBlockType: BlockType.TextBlock,
- },
- /**
- * # or ## or ###
- */
- markdownRegexps: [/^(#{1,3})$/],
- },
- [BlockType.TodoListBlock]: {
- canAddChild: true,
- defaultData: {
- delta: [],
- checked: false,
- },
- splitProps: {
- nextLineRelationShip: SplitRelationship.NextSibling,
- nextLineBlockType: BlockType.TodoListBlock,
- },
- /**
- * -[] or -[x] or -[ ] or [] or [x] or [ ]
- */
- markdownRegexps: [/^((-)?\[(x|\s)?\])$/],
- },
- [BlockType.BulletedListBlock]: {
- canAddChild: true,
- defaultData: {
- delta: [],
- format: 'default',
- },
- splitProps: {
- nextLineRelationShip: SplitRelationship.NextSibling,
- nextLineBlockType: BlockType.BulletedListBlock,
- },
- /**
- * - or + or *
- */
- markdownRegexps: [/^(\s*[-+*])$/],
- },
- [BlockType.NumberedListBlock]: {
- canAddChild: true,
- defaultData: {
- delta: [],
- format: 'default',
- },
- splitProps: {
- nextLineRelationShip: SplitRelationship.NextSibling,
- nextLineBlockType: BlockType.NumberedListBlock,
- },
- /**
- * 1. or 2. or 3.
- * a. or b. or c.
- */
- markdownRegexps: [/^(\s*[\d|a-zA-Z]+\.)$/],
- },
- [BlockType.QuoteBlock]: {
- canAddChild: true,
- defaultData: {
- delta: [],
- size: 'default',
- },
- splitProps: {
- nextLineRelationShip: SplitRelationship.NextSibling,
- nextLineBlockType: BlockType.TextBlock,
- },
- /**
- * " or “ or ”
- */
- markdownRegexps: [/^("|“|”)$/],
- },
- [BlockType.ToggleListBlock]: {
- canAddChild: true,
- defaultData: {
- delta: [],
- collapsed: false,
- },
- splitProps: {
- nextLineRelationShip: SplitRelationship.FirstChild,
- nextLineBlockType: BlockType.TextBlock,
- },
- /**
- * >
- */
- markdownRegexps: [/^(>)$/],
- },
- [BlockType.CodeBlock]: {
- canAddChild: false,
- /**
- * ```
- */
- markdownRegexps: [/^(```)$/],
- },
- };
|