Skip to content

Commit 31b700a

Browse files
feat: disable zooming for link images
1 parent 6edd357 commit 31b700a

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ export const AssetWrapper: React.FC<{
1616
const { components, mapPageUrl, rootDomain } = useNotionContext()
1717

1818
let isURL = false
19-
if (value?.properties?.caption?.length > 0) {
20-
const caption: string = value?.properties?.caption[0][0]
21-
const id = parsePageId(caption, { uuid: true })
19+
if (block.type === 'image') {
20+
const caption: string = value?.properties?.caption?.[0]?.[0]
21+
if (caption) {
22+
const id = parsePageId(caption, { uuid: true })
2223

23-
const isPage = caption.charAt(0) === '/' && id
24-
if ((block.type == 'image' && isValidURL(caption)) || isPage) {
25-
isURL = true
24+
const isPage = caption.charAt(0) === '/' && id
25+
if (isPage || isValidURL(caption)) {
26+
isURL = true
27+
}
2628
}
2729
}
2830

@@ -35,7 +37,7 @@ export const AssetWrapper: React.FC<{
3537
blockId
3638
)}
3739
>
38-
<Asset block={value}>
40+
<Asset block={value} zoomable={!isURL}>
3941
{value?.properties?.caption && !isURL && (
4042
<figcaption className='notion-asset-caption'>
4143
<Text value={value.properties.caption} block={block} />

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const supportedAssetTypes = [
2727
export const Asset: React.FC<{
2828
block: BaseContentBlock
2929
children: any
30-
}> = ({ block, children }) => {
30+
zoomable?: boolean
31+
}> = ({ block, zoomable = true, children }) => {
3132
const { recordMap, mapImageUrl, components } = useNotionContext()
3233

3334
if (!block || !supportedAssetTypes.includes(block.type)) {
@@ -250,7 +251,7 @@ export const Asset: React.FC<{
250251
<LazyImage
251252
src={src}
252253
alt={alt}
253-
zoomable={true}
254+
zoomable={zoomable}
254255
height={style.height as number}
255256
style={assetStyle}
256257
/>

0 commit comments

Comments
 (0)