-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(type): provided data types in relation to content blocks
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* *** MIT LICENSE *** | ||
* ------------------------------------------------------------------------- | ||
* This code may be modified and distributed under the MIT license. | ||
* See the LICENSE file for details. | ||
* ------------------------------------------------------------------------- | ||
* | ||
* @summary Collection of block related types | ||
* | ||
* @author Alvis HT Tang <[email protected]> | ||
* @license MIT | ||
* @copyright Copyright (c) 2021 - All Rights Reserved. | ||
* ------------------------------------------------------------------------- | ||
*/ | ||
|
||
import type { RichText } from './format'; | ||
|
||
interface BlockBase<T extends string> { | ||
object: 'block'; | ||
id: string; | ||
type: T; | ||
created_time: string; | ||
last_edited_time: string; | ||
has_children: boolean; | ||
} | ||
|
||
interface HeadingOneBlock extends BlockBase<'heading_1'> { | ||
heading_1: { text: RichText[] }; | ||
} | ||
|
||
interface HeadingTwoBlock extends BlockBase<'heading_2'> { | ||
heading_2: { text: RichText[] }; | ||
} | ||
|
||
interface HeadingThreeBlock extends BlockBase<'heading_3'> { | ||
heading_3: { text: RichText[] }; | ||
} | ||
|
||
interface ParagraphBlock extends BlockBase<'paragraph'> { | ||
paragraph: { | ||
text: RichText[]; | ||
}; | ||
} | ||
|
||
interface BulletedListItemBlock extends BlockBase<'bulleted_list_item'> { | ||
bulleted_list_item: { | ||
text: RichText[]; | ||
}; | ||
} | ||
|
||
interface NumberedListItemBlock extends BlockBase<'numbered_list_item'> { | ||
numbered_list_item: { | ||
text: RichText[]; | ||
}; | ||
} | ||
|
||
interface ToDoBlock extends BlockBase<'to_do'> { | ||
to_do: { | ||
text: RichText[]; | ||
checked: boolean; | ||
}; | ||
} | ||
|
||
interface ToggleBlock extends BlockBase<'toggle'> { | ||
toggle: { | ||
text: RichText[]; | ||
}; | ||
} | ||
|
||
interface ChildPageBlock extends BlockBase<'child_page'> { | ||
child_page: { title: string }; | ||
} | ||
|
||
interface UnsupportedBlock extends BlockBase<'unsupported'> { | ||
unsupported: Record<string, never>; | ||
} | ||
|
||
export type Block = | ||
| ParagraphBlock | ||
| HeadingOneBlock | ||
| HeadingTwoBlock | ||
| HeadingThreeBlock | ||
| BulletedListItemBlock | ||
| NumberedListItemBlock | ||
| ToDoBlock | ||
| ToggleBlock | ||
| ChildPageBlock | ||
| UnsupportedBlock; | ||
|
||
export type FullBlock = Block & | ||
({ has_children: false } | { has_children: true; children: FullBlock[] }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters