Skip to content

Commit bbb899d

Browse files
feat: third-party component redesign
1 parent 100dc91 commit bbb899d

35 files changed

+516
-315
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
.next/
33
.vercel/
44
build/
5-
docs/
5+
docs/

examples/full/components/NotionPage.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,35 @@ import Head from 'next/head'
33
import Image from 'next/image'
44
import dynamic from 'next/dynamic'
55

6-
import { getPageTitle } from 'notion-utils'
76
import { NotionRenderer } from 'react-notion-x'
87
import { ExtendedRecordMap } from 'notion-types'
8+
import { getPageTitle } from 'notion-utils'
99
import { Tweet, TwitterContextProvider } from 'react-static-tweets'
1010

1111
// -----------------------------------------------------------------------------
1212
// dynamic imports for optional components
1313
// -----------------------------------------------------------------------------
1414

15+
const Collection = dynamic(() =>
16+
import('react-notion-x/third-party/collection').then((m) => m.Collection)
17+
)
1518
const Code = dynamic(() =>
16-
import('react-notion-x').then((notion) => notion.Code)
19+
import('react-notion-x/third-party/code').then((m) => m.Code)
1720
)
18-
19-
const Collection = dynamic(() =>
20-
import('react-notion-x').then((notion) => notion.Collection)
21+
const Equation = dynamic(() =>
22+
import('react-notion-x/third-party/equation').then((m) => m.Equation)
2123
)
22-
23-
const CollectionRow = dynamic(
24-
() => import('react-notion-x').then((notion) => notion.CollectionRow),
24+
const Pdf = dynamic(
25+
() => import('react-notion-x/third-party/pdf').then((m) => m.Pdf),
2526
{
2627
ssr: false
2728
}
2829
)
29-
30-
// NOTE: PDF support via "react-pdf" can sometimes cause errors depending on your
31-
// build setup. If you're running into issues, just disable PDF support altogether.
32-
const Pdf = dynamic(
33-
() => import('react-notion-x').then((notion) => (notion as any).Pdf),
34-
{ ssr: false }
35-
)
36-
37-
const Equation = dynamic(() =>
38-
import('react-notion-x').then((notion) => notion.Equation)
30+
const Modal = dynamic(
31+
() => import('react-notion-x/third-party/modal').then((m) => m.Modal),
32+
{
33+
ssr: false
34+
}
3935
)
4036

4137
export const NotionPage = ({
@@ -146,9 +142,9 @@ export const NotionPage = ({
146142
},
147143
code: Code,
148144
collection: Collection,
149-
collectionRow: CollectionRow,
150145
equation: Equation,
151146
pdf: Pdf,
147+
modal: Modal,
152148
tweet: Tweet
153149
}}
154150
/>

examples/minimal/components/NotionPage.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import React from 'react'
22
import Head from 'next/head'
33

4-
import { getPageTitle } from 'notion-utils'
54
import { NotionRenderer } from 'react-notion-x'
65
import { ExtendedRecordMap } from 'notion-types'
6+
import { getPageTitle } from 'notion-utils'
77

88
export const NotionPage = ({
99
recordMap,
10-
rootPageId,
11-
rootDomain
10+
rootPageId
1211
}: {
1312
recordMap: ExtendedRecordMap
1413
rootPageId?: string
15-
rootDomain?: string
1614
}) => {
1715
if (!recordMap) {
1816
return null
@@ -33,7 +31,6 @@ export const NotionPage = ({
3331
recordMap={recordMap}
3432
fullPage={true}
3533
darkMode={false}
36-
rootDomain={rootDomain}
3734
rootPageId={rootPageId}
3835
/>
3936
</>

examples/minimal/lib/config.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
// TODO: change these to your own values
2-
// NOTE: rootNotionSpaceId is optional; set it to undefined if you don't want to
3-
// use it.
1+
// TODO: change this to the notion ID of the page you want to test
42
export const rootNotionPageId = '067dd719a912471ea9a3ac10710e7fdf'
5-
export const rootNotionSpaceId = 'fde5ac74-eea3-4527-8f00-4482710e1af3'
63

74
export const isDev =
85
process.env.NODE_ENV === 'development' || !process.env.NODE_ENV
9-
10-
export const port = process.env.PORT || 3000
11-
export const rootDomain = isDev ? `localhost:${port}` : null

examples/minimal/pages/[pageId].tsx

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
import React from 'react'
22

33
import { NotionAPI } from 'notion-client'
4-
import { getAllPagesInSpace } from 'notion-utils'
5-
import { defaultMapPageUrl } from 'react-notion-x'
64
import { ExtendedRecordMap } from 'notion-types'
75

86
import { NotionPage } from '../components/NotionPage'
9-
import {
10-
rootNotionPageId,
11-
rootNotionSpaceId,
12-
rootDomain,
13-
isDev
14-
} from '../lib/config'
7+
import { rootNotionPageId } from '../lib/config'
158

169
export const notion = new NotionAPI()
1710

@@ -28,44 +21,12 @@ export const getStaticProps = async (context) => {
2821
}
2922

3023
export async function getStaticPaths() {
31-
if (isDev) {
32-
return {
33-
paths: [],
34-
fallback: true
35-
}
36-
}
37-
38-
const mapPageUrl = defaultMapPageUrl(rootNotionPageId)
39-
40-
// This crawls all public pages starting from the given root page in order
41-
// for next.js to pre-generate all pages via static site generation (SSG).
42-
// This is a useful optimization but not necessary; you could just as easily
43-
// set paths to an empty array to not pre-generate any pages at build time.
44-
const pages = await getAllPagesInSpace(
45-
rootNotionPageId,
46-
rootNotionSpaceId,
47-
notion.getPage.bind(notion),
48-
{
49-
traverseCollections: false
50-
}
51-
)
52-
53-
const paths = Object.keys(pages)
54-
.map((pageId) => mapPageUrl(pageId))
55-
.filter((path) => path && path !== '/')
56-
5724
return {
58-
paths,
25+
paths: [],
5926
fallback: true
6027
}
6128
}
6229

6330
export default function Page({ recordMap }: { recordMap: ExtendedRecordMap }) {
64-
return (
65-
<NotionPage
66-
recordMap={recordMap}
67-
rootPageId={rootNotionPageId}
68-
rootDomain={rootDomain}
69-
/>
70-
)
31+
return <NotionPage recordMap={recordMap} rootPageId={rootNotionPageId} />
7132
}

examples/minimal/pages/index.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { NotionAPI } from 'notion-client'
44
import { ExtendedRecordMap } from 'notion-types'
55

66
import { NotionPage } from '../components/NotionPage'
7-
import { rootNotionPageId, rootDomain } from '../lib/config'
7+
import { rootNotionPageId } from '../lib/config'
88

99
export const notion = new NotionAPI()
1010

@@ -21,11 +21,5 @@ export const getStaticProps = async () => {
2121
}
2222

2323
export default function Page({ recordMap }: { recordMap: ExtendedRecordMap }) {
24-
return (
25-
<NotionPage
26-
recordMap={recordMap}
27-
rootDomain={rootDomain}
28-
rootPageId={rootNotionPageId}
29-
/>
30-
)
24+
return <NotionPage recordMap={recordMap} rootPageId={rootNotionPageId} />
3125
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"docs:extract": "lerna exec --ignore react-notion-x --ignore notion-x-example-minimal notion-x-example-full api-extractor run",
2929
"docs:generate": "api-documenter markdown -i build -o docs",
3030
"bootstrap": "lerna bootstrap",
31-
"publish": "lerna publish",
31+
"publish": "run-s build publish:lerna",
32+
"publish:lerna": "lerna publish",
3233
"preinstall": "node -e \"if (process.env.npm_execpath.indexOf('yarn') < 0) throw new Error('this package requires yarn for development')\"",
3334
"postinstall": "run-s bootstrap",
3435
"prepare": "husky install",

packages/react-notion-x/package.json

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,40 @@
99
"module": "build/esm/index.js",
1010
"typings": "build/esm/index.d.ts",
1111
"sideEffects": false,
12+
"exports": {
13+
".": {
14+
"requires": "./build/cjs/index.js",
15+
"types": "./build/esm/index.d.ts",
16+
"default": "./build/esm/index.js"
17+
},
18+
"./third-party/code": {
19+
"requires": "./build/cjs/third-party/code.js",
20+
"types": "./build/esm/third-party/code.d.ts",
21+
"default": "./build/esm/third-party/code.js"
22+
},
23+
"./third-party/collection": {
24+
"requires": "./build/cjs/third-party/collection.js",
25+
"types": "./build/esm/third-party/collection.d.ts",
26+
"default": "./build/esm/third-party/collection.js"
27+
},
28+
"./third-party/equation": {
29+
"requires": "./build/cjs/third-party/equation.js",
30+
"types": "./build/esm/third-party/equation.d.ts",
31+
"default": "./build/esm/third-party/equation.js"
32+
},
33+
"./third-party/modal": {
34+
"requires": "./build/cjs/third-party/modal.js",
35+
"types": "./build/esm/third-party/modal.d.ts",
36+
"default": "./build/esm/third-party/modal.js"
37+
},
38+
"./third-party/pdf": {
39+
"requires": "./build/cjs/third-party/pdf.js",
40+
"types": "./build/esm/third-party/pdf.d.ts",
41+
"default": "./build/esm/third-party/pdf.js"
42+
},
43+
"./styles.css": "./src/styles.css",
44+
"./src/styles.css": "./src/styles.css"
45+
},
1246
"engines": {
1347
"node": ">=12"
1448
},
@@ -22,7 +56,7 @@
2256
"medium-zoom": "^1.0.6",
2357
"notion-types": "^4.19.8",
2458
"notion-utils": "^4.19.8",
25-
"prismjs": "^1.20.0",
59+
"prismjs": "^1.27.0",
2660
"rc-dropdown": "^3.1.2",
2761
"rc-menu": "^9.0.14",
2862
"react-hotkeys-hook": "^3.0.3",

0 commit comments

Comments
 (0)