Skip to content

Commit 490bc2b

Browse files
Merge pull request #350 from MichaelCasaDev/support-image-alignment
Support for new assets alignment
2 parents ab31c50 + 9dd35a4 commit 490bc2b

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

packages/notion-types/src/block.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export interface BaseContentBlock extends BaseBlock {
131131
caption?: Decoration[]
132132
}
133133
format?: {
134+
block_alignment: 'center' | 'left' | 'right'
134135
block_width: number
135136
block_height: number
136137
display_source: string
@@ -351,6 +352,7 @@ export interface GoogleDriveBlock extends BaseContentBlock {
351352
user_name: string
352353
modified_time: number
353354
}
355+
block_alignment: 'center' | 'left' | 'right'
354356
block_width: number
355357
block_height: number
356358
display_source: string

packages/react-notion-x/src/components/asset-wrapper.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const AssetWrapper: React.FC<{
7474
return figure
7575
}
7676

77-
function isValidURL(str) {
77+
function isValidURL(str: string) {
7878
// TODO: replace this with a more well-tested package
7979
const pattern = new RegExp(
8080
'^(https?:\\/\\/)?' + // protocol
@@ -88,7 +88,7 @@ function isValidURL(str) {
8888
return !!pattern.test(str)
8989
}
9090

91-
function extractHostname(url) {
91+
function extractHostname(url: string) {
9292
try {
9393
const hostname = new URL(url).hostname
9494
return hostname

packages/react-notion-x/src/components/asset.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ export const Asset: React.FC<{
8787
}
8888
}
8989
} else {
90+
switch (block.format?.block_alignment) {
91+
case 'center': {
92+
style.alignSelf = 'center'
93+
break
94+
}
95+
case 'left': {
96+
style.alignSelf = 'start'
97+
break
98+
}
99+
case 'right': {
100+
style.alignSelf = 'end'
101+
break
102+
}
103+
}
104+
90105
if (block_width) {
91106
style.width = block_width
92107
}

0 commit comments

Comments
 (0)