Skip to content

Commit

Permalink
feat(type): provided data types in relation to content blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
alvis committed Jun 11, 2021
1 parent 07ae633 commit 8ef3461
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
91 changes: 91 additions & 0 deletions source/types/block.ts
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[] });
1 change: 1 addition & 0 deletions source/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

/* istanbul ignore file */

export * from './block';
export * from './format';
export * from './user';
export * from './property';

0 comments on commit 8ef3461

Please sign in to comment.