-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRenderer.vue
More file actions
208 lines (198 loc) · 5.89 KB
/
Copy pathRenderer.vue
File metadata and controls
208 lines (198 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<template>
<div class="notion-renderer">
<TransitionGroup
tag="div"
name="slide-up"
appear
mode="out-in"
>
<template
v-for="(block, index) in blocks"
:key="block.id"
>
<!-- Group consecutive list items into proper lists -->
<ul
v-if="
block.type === 'bulleted_list_item'
&& !isConsecutiveListItem(blocks, index, 'bulleted_list_item')
"
class="list-disc list-inside mb-4 ml-4 space-y-1"
>
<NotionBulletedListItemBlock
:block="block as BulletedListItemBlock"
/>
<!-- Render consecutive list items -->
<template
v-for="(nextBlock, nextIndex) in getConsecutiveListItems(
blocks,
index,
'bulleted_list_item',
)"
:key="`${nextBlock.id}-${nextIndex}`"
>
<NotionBulletedListItemBlock
:block="nextBlock as BulletedListItemBlock"
/>
</template>
</ul>
<ol
v-else-if="
block.type === 'numbered_list_item'
&& !isConsecutiveListItem(blocks, index, 'numbered_list_item')
"
class="list-decimal list-inside mb-4 ml-4 space-y-1"
>
<NotionNumberedListItemBlock
:block="block as NumberedListItemBlock"
/>
<!-- Render consecutive list items -->
<template
v-for="nextBlock in getConsecutiveListItems(
blocks,
index,
'numbered_list_item',
)"
:key="nextBlock.id"
>
<NotionNumberedListItemBlock
:block="nextBlock as NumberedListItemBlock"
/>
</template>
</ol>
<!-- Skip individual list items that are part of a list group -->
<template v-else-if="!isPartOfListGroup(blocks, index)">
<!-- Headings -->
<NotionHeadingBlock
v-if="isHeadingBlock(block)"
:block="block as HeadingBlock"
/>
<!-- Paragraph -->
<NotionParagraphBlock
v-else-if="block.type === 'paragraph'"
:block="block as ParagraphBlock"
/>
<!-- To-Do -->
<NotionToDoBlock
v-else-if="block.type === 'to_do'"
:block="block as ToDoBlock"
/>
<!-- Quote -->
<NotionQuoteBlock
v-else-if="block.type === 'quote'"
:block="block as QuoteBlock"
/>
<!-- Callout -->
<NotionCalloutBlock
v-else-if="block.type === 'callout'"
:block="block as CalloutBlock"
/>
<!-- Code -->
<NotionCodeBlock
v-else-if="block.type === 'code'"
:block="block as CodeBlock"
/>
<!-- Divider -->
<NotionDividerBlock
v-else-if="block.type === 'divider'"
:block="block as DividerBlock"
/>
<!-- Image -->
<NotionImageBlock
v-else-if="block.type === 'image'"
:block="block as ImageBlock"
/>
<!-- Bookmark -->
<NotionBookmarkBlock
v-else-if="block.type === 'bookmark'"
:block="block as BookmarkBlock"
/>
<!-- Video -->
<NotionVideoBlock
v-else-if="block.type === 'video'"
:block="block"
/>
<!-- Child Page -->
<NotionChildPageBlock
v-else-if="block.type === 'child_page'"
:block="block as ChildPageBlock"
/>
<!-- Unsupported block type -->
<div
v-else
class="p-4 bg-gray-100 dark:bg-gray-800 rounded-lg mb-4 border-l-4 border-yellow-400"
>
<div class="flex items-center space-x-2">
<Icon
name="i-heroicons-exclamation-triangle"
class="w-5 h-5 text-yellow-600"
/>
<span class="text-sm text-gray-600 dark:text-gray-400">
Unsupported block type: {{ block.type }}
</span>
</div>
</div>
</template>
</template>
</TransitionGroup>
</div>
</template>
<script setup lang="ts">
import type {
AnyNotionBlock,
HeadingBlock,
ParagraphBlock,
BulletedListItemBlock,
NumberedListItemBlock,
ToDoBlock,
QuoteBlock,
CalloutBlock,
CodeBlock,
DividerBlock,
ImageBlock,
BookmarkBlock,
ChildPageBlock,
} from '../types/notion-blocks'
interface Props {
blocks: AnyNotionBlock[]
}
defineProps<Props>()
// Helper functions
function isHeadingBlock(block: AnyNotionBlock): block is HeadingBlock {
return ['heading_1', 'heading_2', 'heading_3'].includes(block.type)
}
// Check if current block is a consecutive list item (not the first one in a group)
function isConsecutiveListItem(
blocks: AnyNotionBlock[],
index: number,
listType: string,
): boolean {
if (index === 0) return false
return blocks[index - 1]?.type === listType
}
// Check if current block is part of a list group (for skipping individual rendering)
function isPartOfListGroup(blocks: AnyNotionBlock[], index: number): boolean {
const block = blocks[index]
if (!['bulleted_list_item', 'numbered_list_item'].includes(block.type))
return false
// If it's the first item in a list, it's not part of a group (it starts the group)
if (index === 0) return false
return blocks[index - 1]?.type === block.type
}
// Get consecutive list items after the current index
function getConsecutiveListItems(
blocks: AnyNotionBlock[],
startIndex: number,
listType: string,
): AnyNotionBlock[] {
const items: AnyNotionBlock[] = []
for (let i = startIndex + 1; i < blocks.length; i++) {
if (blocks[i].type === listType) {
items.push(blocks[i])
}
else {
break
}
}
return items
}
</script>