22from typing import List , Optional , Union
33
44from pydantic import BaseModel
5+ from typing_extensions import Literal
56
67
78class Icon (Enum ):
@@ -24,7 +25,22 @@ class TextStyle(Enum):
2425 ITALIC = "italic"
2526
2627
28+ class BlockType (Enum ):
29+ HEADER = "header"
30+ CODE = "code"
31+ LINES = "lines"
32+ LINE = "line"
33+ TEXT = "text"
34+ LINK = "link"
35+ ICON = "icon"
36+ DIVIDER = "divider"
37+ FACT_LIST = "fact_list"
38+ FACT = "fact"
39+ EXPANDABLE = "expandable"
40+
41+
2742class BaseBlock (BaseModel ):
43+ type : BlockType
2844 pass
2945
3046
@@ -33,35 +49,41 @@ class BaseInlineTextBlock(BaseBlock):
3349
3450
3551class TextBlock (BaseInlineTextBlock ):
52+ type : Literal [BlockType .TEXT ] = BlockType .TEXT
3653 text : str
3754 style : Optional [TextStyle ] = None
3855
3956
4057class LinkBlock (BaseInlineTextBlock ):
58+ type : Literal [BlockType .LINK ] = BlockType .LINK
4159 text : str
4260 url : str
4361
4462
4563class IconBlock (BaseInlineTextBlock ):
64+ type : Literal [BlockType .ICON ] = BlockType .ICON
4665 icon : Icon
4766
4867
4968InlineBlock = Union [TextBlock , LinkBlock , IconBlock ]
5069
5170
5271class HeaderBlock (BaseBlock ):
72+ type : Literal [BlockType .HEADER ] = BlockType .HEADER
5373 text : str
5474
5575
5676class CodeBlock (BaseBlock ):
77+ type : Literal [BlockType .CODE ] = BlockType .CODE
5778 text : str
5879
5980
6081class DividerBlock (BaseBlock ):
61- pass
82+ type : Literal [ BlockType . DIVIDER ] = BlockType . DIVIDER
6283
6384
6485class LineBlock (BaseBlock ):
86+ type : Literal [BlockType .LINE ] = BlockType .LINE
6587 inlines : List [InlineBlock ]
6688 sep : str = " "
6789
@@ -71,19 +93,22 @@ class BaseLinesBlock(BaseBlock):
7193
7294
7395class LinesBlock (BaseLinesBlock ):
74- pass
96+ type : Literal [ BlockType . LINES ] = BlockType . LINES
7597
7698
7799class FactBlock (BaseBlock ):
100+ type : Literal [BlockType .FACT ] = BlockType .FACT
78101 title : LineBlock
79102 value : LineBlock
80103
81104
82105class FactListBlock (BaseBlock ):
106+ type : Literal [BlockType .FACT_LIST ] = BlockType .FACT_LIST
83107 facts : List [FactBlock ]
84108
85109
86110class ExpandableBlock (BaseBlock ):
111+ type : Literal [BlockType .EXPANDABLE ] = BlockType .EXPANDABLE
87112 title : str
88113 body : List ["InExpandableBlock" ]
89114 expanded : bool = False
0 commit comments