|
| 1 | +/* |
| 2 | + * *** MIT LICENSE *** |
| 3 | + * ------------------------------------------------------------------------- |
| 4 | + * This code may be modified and distributed under the MIT license. |
| 5 | + * See the LICENSE file for details. |
| 6 | + * ------------------------------------------------------------------------- |
| 7 | + * |
| 8 | + * @summary Collection of block related types |
| 9 | + * |
| 10 | + * @author Alvis HT Tang <alvis@hilbert.space> |
| 11 | + * @license MIT |
| 12 | + * @copyright Copyright (c) 2021 - All Rights Reserved. |
| 13 | + * ------------------------------------------------------------------------- |
| 14 | + */ |
| 15 | + |
| 16 | +import type { RichText } from './format'; |
| 17 | + |
| 18 | +interface BlockBase<T extends string> { |
| 19 | + object: 'block'; |
| 20 | + id: string; |
| 21 | + type: T; |
| 22 | + created_time: string; |
| 23 | + last_edited_time: string; |
| 24 | + has_children: boolean; |
| 25 | +} |
| 26 | + |
| 27 | +interface HeadingOneBlock extends BlockBase<'heading_1'> { |
| 28 | + heading_1: { text: RichText[] }; |
| 29 | +} |
| 30 | + |
| 31 | +interface HeadingTwoBlock extends BlockBase<'heading_2'> { |
| 32 | + heading_2: { text: RichText[] }; |
| 33 | +} |
| 34 | + |
| 35 | +interface HeadingThreeBlock extends BlockBase<'heading_3'> { |
| 36 | + heading_3: { text: RichText[] }; |
| 37 | +} |
| 38 | + |
| 39 | +interface ParagraphBlock extends BlockBase<'paragraph'> { |
| 40 | + paragraph: { |
| 41 | + text: RichText[]; |
| 42 | + }; |
| 43 | +} |
| 44 | + |
| 45 | +interface BulletedListItemBlock extends BlockBase<'bulleted_list_item'> { |
| 46 | + bulleted_list_item: { |
| 47 | + text: RichText[]; |
| 48 | + }; |
| 49 | +} |
| 50 | + |
| 51 | +interface NumberedListItemBlock extends BlockBase<'numbered_list_item'> { |
| 52 | + numbered_list_item: { |
| 53 | + text: RichText[]; |
| 54 | + }; |
| 55 | +} |
| 56 | + |
| 57 | +interface ToDoBlock extends BlockBase<'to_do'> { |
| 58 | + to_do: { |
| 59 | + text: RichText[]; |
| 60 | + checked: boolean; |
| 61 | + }; |
| 62 | +} |
| 63 | + |
| 64 | +interface ToggleBlock extends BlockBase<'toggle'> { |
| 65 | + toggle: { |
| 66 | + text: RichText[]; |
| 67 | + }; |
| 68 | +} |
| 69 | + |
| 70 | +interface ChildPageBlock extends BlockBase<'child_page'> { |
| 71 | + child_page: { title: string }; |
| 72 | +} |
| 73 | + |
| 74 | +interface UnsupportedBlock extends BlockBase<'unsupported'> { |
| 75 | + unsupported: Record<string, never>; |
| 76 | +} |
| 77 | + |
| 78 | +export type Block = |
| 79 | + | ParagraphBlock |
| 80 | + | HeadingOneBlock |
| 81 | + | HeadingTwoBlock |
| 82 | + | HeadingThreeBlock |
| 83 | + | BulletedListItemBlock |
| 84 | + | NumberedListItemBlock |
| 85 | + | ToDoBlock |
| 86 | + | ToggleBlock |
| 87 | + | ChildPageBlock |
| 88 | + | UnsupportedBlock; |
| 89 | + |
| 90 | +export type FullBlock = Block & |
| 91 | + ({ has_children: false } | { has_children: true; children: FullBlock[] }); |
0 commit comments