diff --git a/examples/minimal/components/NotionPage.tsx b/examples/minimal/components/NotionPage.tsx index c39f9653..da28f3b1 100644 --- a/examples/minimal/components/NotionPage.tsx +++ b/examples/minimal/components/NotionPage.tsx @@ -1,9 +1,9 @@ import * as React from 'react' import Head from 'next/head' +import { NotionRenderer } from 'areyes-react-notion-x' import { ExtendedRecordMap } from 'notion-types' import { getPageTitle } from 'notion-utils' -import { NotionRenderer } from 'react-notion-x' export const NotionPage = ({ recordMap, diff --git a/examples/minimal/pages/_app.tsx b/examples/minimal/pages/_app.tsx index eac6a0d7..ae03b4ae 100644 --- a/examples/minimal/pages/_app.tsx +++ b/examples/minimal/pages/_app.tsx @@ -1,7 +1,7 @@ import * as React from 'react' // core styles shared by all of react-notion-x (required) -import 'react-notion-x/src/styles.css' +import 'areyes-react-notion-x/src/styles.css' import '../styles/globals.css' diff --git a/packages/react-notion-x/src/block-components/aframe.tsx b/packages/react-notion-x/src/block-components/aframe.tsx new file mode 100644 index 00000000..e676abab --- /dev/null +++ b/packages/react-notion-x/src/block-components/aframe.tsx @@ -0,0 +1,177 @@ +import * as React from 'react' + +import { BaseContentBlock } from 'notion-types' + +import { Text } from '../components/text' +import { useNotionContext } from '../context' + +export const AFrame: React.FC<{ + block: BaseContentBlock +}> = ({ block }) => { + const { recordMap } = useNotionContext() + + if (!block) { + return null + } + + const style: React.CSSProperties = { + position: 'relative', + display: 'flex', + justifyContent: 'center', + alignSelf: 'center', + width: '100%', + maxWidth: '100%', + flexDirection: 'column' + } + + const assetStyle: React.CSSProperties = {} + // console.log('asset', block) + + if (block.format) { + const { + block_aspect_ratio, + block_height, + block_width, + block_full_width, + block_page_width, + block_preserve_scale + } = block.format + + if (block_full_width || block_page_width) { + if (block_full_width) { + style.width = '100vw' + } else { + style.width = '100%' + } + + if (block.type === 'video') { + if (block_height) { + style.height = block_height + } else if (block_aspect_ratio) { + style.paddingBottom = `${block_aspect_ratio * 100}%` + } else if (block_preserve_scale) { + style.objectFit = 'contain' + } + } else if (block_aspect_ratio && block.type !== 'image') { + style.paddingBottom = `${block_aspect_ratio * 100}%` + } else if (block_height) { + style.height = block_height + } else if (block_preserve_scale) { + if (block.type === 'image') { + style.height = '100%' + } else { + // TODO: this is just a guess + style.paddingBottom = '75%' + style.minHeight = 100 + } + } + } else { + switch (block.format?.block_alignment) { + case 'center': { + style.alignSelf = 'center' + break + } + case 'left': { + style.alignSelf = 'start' + break + } + case 'right': { + style.alignSelf = 'end' + break + } + } + + if (block_width) { + style.width = block_width + } + + if (block_preserve_scale && block.type !== 'image') { + style.paddingBottom = '50%' + style.minHeight = 100 + } else { + if (block_height && block.type !== 'image') { + style.height = block_height + } + } + } + + if (block.type === 'image') { + assetStyle.objectFit = 'cover' + } else if (block_preserve_scale) { + assetStyle.objectFit = 'contain' + } + } + + const source = + recordMap.signed_urls?.[block.id] || block.properties?.source?.[0]?.[0] + let content = null + + if (!source) { + return null + } + + let src = block.format?.display_source || source + + if (src) { + if (block.type === 'gist') { + if (!src.endsWith('.pibb')) { + src = `${src}.pibb` + } + + assetStyle.width = '100%' + style.paddingBottom = '50%' + + // TODO: GitHub gists do not resize their height properly + content = ( +