File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed
react-notion-x/src/components Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,24 @@ export interface BaseContentBlock extends BaseBlock {
142
142
file_ids ?: string [ ]
143
143
}
144
144
145
+ export interface BaseImageBlock extends BaseContentBlock {
146
+ properties : {
147
+ source : string [ ] [ ]
148
+ caption ?: Decoration [ ]
149
+ }
150
+ format ?: {
151
+ block_alignment : 'center' | 'left' | 'right'
152
+ block_width : number
153
+ block_height : number
154
+ display_source : string
155
+ block_full_width : boolean
156
+ block_page_width : boolean
157
+ block_aspect_ratio : number
158
+ block_preserve_scale : boolean
159
+ }
160
+ file_ids ?: string [ ]
161
+ }
162
+
145
163
export interface BasePageBlock extends BaseBlock {
146
164
properties ?: {
147
165
title : Decoration [ ]
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ export const AssetWrapper: React.FC<{
74
74
return figure
75
75
}
76
76
77
- function isValidURL ( str ) {
77
+ function isValidURL ( str : string ) {
78
78
// TODO: replace this with a more well-tested package
79
79
const pattern = new RegExp (
80
80
'^(https?:\\/\\/)?' + // protocol
@@ -88,7 +88,7 @@ function isValidURL(str) {
88
88
return ! ! pattern . test ( str )
89
89
}
90
90
91
- function extractHostname ( url ) {
91
+ function extractHostname ( url : string ) {
92
92
try {
93
93
const hostname = new URL ( url ) . hostname
94
94
return hostname
Original file line number Diff line number Diff line change 1
1
import * as React from 'react'
2
- import { BaseContentBlock , Block } from 'notion-types'
2
+ import { BaseContentBlock , BaseImageBlock , Block } from 'notion-types'
3
3
import { getTextContent } from 'notion-utils'
4
4
5
5
import { useNotionContext } from '../context'
@@ -87,6 +87,23 @@ export const Asset: React.FC<{
87
87
}
88
88
}
89
89
} else {
90
+ if ( block . type == 'image' ) {
91
+ switch ( ( block as BaseImageBlock ) . format ?. block_alignment ) {
92
+ case 'center' : {
93
+ style . alignSelf = 'center'
94
+ break
95
+ }
96
+ case 'left' : {
97
+ style . alignSelf = 'start'
98
+ break
99
+ }
100
+ case 'right' : {
101
+ style . alignSelf = 'end'
102
+ break
103
+ }
104
+ }
105
+ }
106
+
90
107
if ( block_width ) {
91
108
style . width = block_width
92
109
}
You can’t perform that action at this time.
0 commit comments