Skip to content

Commit 5bd43fc

Browse files
authored
Merge pull request #10 from ikoamu/revert-9-support-html-attr
Revert "support org-html"
2 parents bba277c + bde7184 commit 5bd43fc

12 files changed

+211
-907
lines changed

components/Search/SearchContent.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const SearchContent: React.FC<{
6464
autoHeight={true}
6565
autoHide={true}
6666
autoHeightMax={500}
67-
renderThumbVertical={({ style, ...props }: { style: React.CSSProperties }) => (
67+
renderThumbVertical={({ style, ...props }) => (
6868
<Box
6969
style={{
7070
...style,

components/Sidebar/Link.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export const PreviewLink = (props: LinkProps) => {
270270
autoHeight
271271
autoHeightMax={300}
272272
autoHide
273-
renderThumbVertical={({ style, ...props }: { style: any, [key: string]: any }) => (
273+
renderThumbVertical={({ style, ...props }) => (
274274
<Box
275275
style={{
276276
...style,

components/Sidebar/OrgImage.tsx

+18-49
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,24 @@ import path from 'path'
55
import { Container } from '@chakra-ui/react'
66
//import '../../../public/placeholder.png'
77

8-
const convertToNextImageAttr = (value: string | number | undefined): number | undefined => {
9-
if (value === undefined) {
10-
return undefined
11-
}
12-
13-
if (typeof value === 'number' || !isNaN(Number(value))) {
14-
return Number(value)
15-
}
16-
17-
if (value.endsWith('px')) {
18-
return Number(value.replace('px', ''))
19-
}
20-
21-
return undefined
22-
}
23-
248
export interface OrgImageProps {
25-
org: React.ClassAttributes<HTMLImageElement> & React.ImgHTMLAttributes<HTMLImageElement>
9+
src: string
2610
file: string
2711
}
2812

2913
export const OrgImage = (props: OrgImageProps) => {
30-
const { org, file } = props
31-
const { src, ...attr } = org
14+
const { src, file } = props
3215

33-
if (!src) {
34-
return null
35-
}
16+
// const [image, setImage] = useState<any>(null)
17+
18+
/* )
19+
* .then((res) => res.blob())
20+
* .then((res) => setImage(res))
21+
* .catch((e) => {
22+
* setImage(null)
23+
* console.error(e)
24+
* })
25+
}, [fullPath]) */
3626

3727
const dumbLoader = ({ src, width, quality }: { [key: string]: string | number }) => {
3828
return `${src}`
@@ -41,38 +31,17 @@ export const OrgImage = (props: OrgImageProps) => {
4131
return `img/${src}`
4232
}
4333

44-
if (src?.startsWith("file:")) {
34+
if (src.startsWith("file:")) {
4535
const srcName = src.replace(/file:/g, './')
46-
const attrWidth = convertToNextImageAttr(attr.width)
47-
const attrHeight = convertToNextImageAttr(attr.height)
48-
const layout = attrWidth || attrHeight ? undefined : "responsive"
4936
return (
50-
<Image
51-
{...attr}
52-
layout={layout}
53-
loader={dumbLoader}
54-
src={srcName}
55-
width={attrWidth}
56-
height={attrHeight}
57-
alt={attr.alt ?? "Wow, an image."}
58-
/>
37+
<Image layout="responsive" loader={dumbLoader} src={srcName} alt="" />
5938
)
6039
}
6140

6241
if (/(http)?.*/g.test(src.replace(/(http)?.*/g, '$1'))) {
63-
const attrWidth = convertToNextImageAttr(attr.width)
64-
const attrHeight = convertToNextImageAttr(attr.height)
65-
const layout = attrWidth || attrHeight ? undefined : "responsive"
42+
console.log(src.replace(/(http)?.*/g, '$1'))
6643
return (
67-
<Image
68-
{...attr}
69-
layout={layout}
70-
loader={dumbLoader}
71-
src={src}
72-
width={attrWidth}
73-
height={attrHeight}
74-
alt={attr.alt ?? "Wow, an image."}
75-
/>
44+
<Image layout="responsive" loader={dumbLoader} src={src} alt="" />
7645
)
7746
}
7847

@@ -82,10 +51,10 @@ export const OrgImage = (props: OrgImageProps) => {
8251
const fullPath =
8352
path.isAbsolute(srcName) || srcName.slice(0, 1) === '~' ? srcName : path.join(dir, srcName)
8453
const encodedPath = encodeURIComponent(encodeURIComponent(fullPath))
85-
console.log(srcName, " is ", "local")
54+
8655
return (
8756
<Container my={4} position="relative">
88-
<img {...attr} alt={attr.alt ?? "Wow, an image."} src={fullPath} />
57+
<img alt="Wow, an image." src={fullPath} />
8958
</Container>
9059
)
9160
}

components/Sidebar/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const Sidebar = (props: SidebarProps) => {
193193
//autoHeight
194194
//autoHeightMax={600}
195195
autoHide
196-
renderThumbVertical={({ style, ...props }: { style: any, [key: string]: any }) => (
196+
renderThumbVertical={({ style, ...props }) => (
197197
<Box
198198
style={{
199199
...style,

components/Tweaks/DropDownMenu.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export const DropDownMenu = (props: DropDownMenuProps) => {
1818
<Portal>
1919
{' '}
2020
<MenuList zIndex="popover">
21-
{textArray.map((option, i) => (
22-
<MenuItem key={i} onClick={onClickArray[i]}> {option} </MenuItem>
23-
))}
21+
{textArray.map((option, i) => {
22+
;<MenuItem onClick={onClickArray[i]}> {option} </MenuItem>
23+
})}
2424
</MenuList>
2525
</Portal>
2626
</Menu>

components/Tweaks/Visual/ColorMenu.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const ColorMenu = (props: ColorMenuProps) => {
2929
const { label, colorList, value, visValue, setVisuals, noEmpty } = props
3030

3131
const clickCallback = useCallback(
32-
(color: any) =>
32+
(color) =>
3333
setVisuals((curr: typeof initialVisuals) => {
3434
return {
3535
...curr,

components/Tweaks/Visual/ThemeSelect.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const ThemeSelect = () => {
2929
color="black"
3030
rightIcon={<ChevronDownIcon />}
3131
>
32-
{String(emacsTheme[0])}
32+
{emacsTheme[0]}
3333
</MenuButton>
3434
<MenuList minW={10} zIndex="popover" bgColor="gray.200">
3535
<MenuItem

components/Tweaks/Visual/VisualsPanel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const VisualsPanel = (props: VisualsPanelProps) => {
4545
setHighlightColor,
4646
threeDim,
4747
} = props
48-
const setVisualsCallback = useCallback((val: any) => setVisuals(val), [])
48+
const setVisualsCallback = useCallback((val) => setVisuals(val), [])
4949
return (
5050
<VStack justifyContent="flex-start" align="stretch">
5151
<ThemeSelect />

components/Tweaks/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const Tweaks = (props: TweakProps) => {
155155
autoHeight
156156
autoHeightMax={0.85 * globalThis.innerHeight}
157157
autoHide
158-
renderThumbVertical={({ style, ...props }: { style: any, [key: string]: any }) => (
158+
renderThumbVertical={({ style, ...props }) => (
159159
<Box
160160
{...props}
161161
style={{

package.json

+8-9
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
"react-resizable": "^3.0.4",
4747
"react-spring": "^9.2.4",
4848
"reconnecting-websocket": "^4.4.0",
49-
"rehype": "^13.0.0",
49+
"rehype": "^11.0.0",
5050
"rehype-highlight": "^4.1.0",
51-
"rehype-katex": "^7.0.0",
52-
"rehype-react": "^8.0.0",
51+
"rehype-katex": "^5.0.0",
52+
"rehype-react": "^6.2.1",
5353
"remark-extract-frontmatter": "^3.2.0",
5454
"remark-frontmatter": "^3.0.0",
5555
"remark-gfm": "^1.0.0",
@@ -64,12 +64,12 @@
6464
"three-spritetext": "^1.6.2",
6565
"through": "^2.3.8",
6666
"to-vfile": "^6.1.0",
67-
"unified": "^11.0.4",
68-
"uniorg": "^1.1.1",
67+
"unified": "^9.2.2",
68+
"uniorg": "^0.4.0",
6969
"uniorg-attach": "^0.4.5",
7070
"uniorg-extract-keywords": "^0.4.5",
71-
"uniorg-parse": "^2.1.1",
72-
"uniorg-rehype": "^1.1.1",
71+
"uniorg-parse": "^0.4.5",
72+
"uniorg-rehype": "^0.4.8",
7373
"uniorg-slug": "^0.4.8",
7474
"unist-util-find-after": "^3.0.0",
7575
"unist-util-is": "^4.1.0",
@@ -83,8 +83,7 @@
8383
"@types/d3-interpolate": "^3.0.1",
8484
"@types/mapbox__rehype-prism": "^0.8.3",
8585
"@types/node": "20.12.11",
86-
"@types/react": "^18.2.66",
87-
"@types/react-dom": "^18.2.22",
86+
"@types/react": "17.0.14",
8887
"eslint": "7.31.0",
8988
"eslint-config-next": "^14.2.3",
9089
"next-compose-plugins": "^2.2.1",

util/processOrg.tsx

+12-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { unified } from 'unified'
1+
import unified from 'unified'
22
//import createStream from 'unified-stream'
33
import uniorgParse from 'uniorg-parse'
44
import uniorg2rehype from 'uniorg-rehype'
@@ -28,7 +28,7 @@ import remarkRehype from 'remark-rehype'
2828

2929
import { PreviewLink } from '../components/Sidebar/Link'
3030
import { LinksByNodeId, NodeByCite, NodeById } from '../pages'
31-
import React, { createContext, ReactNode, useEffect, useMemo, useState } from 'react'
31+
import React, { createContext, ReactNode, useMemo } from 'react'
3232
import { OrgImage } from '../components/Sidebar/OrgImage'
3333
import { Section } from '../components/Sidebar/Section'
3434
import { NoteContext } from './NoteContext'
@@ -38,7 +38,6 @@ import { OrgRoamLink, OrgRoamNode } from '../api'
3838
import { toString } from 'hast-util-to-string'
3939
import { Box, chakra } from '@chakra-ui/react'
4040
import { normalizeLinkEnds } from './normalizeLinkEnds'
41-
import * as prod from 'react/jsx-runtime'
4241

4342
export interface ProcessedOrgProps {
4443
nodeById: NodeById
@@ -73,8 +72,13 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
7372
useInheritance,
7473
} = props
7574

75+
if (!previewNode || !linksByNodeId) {
76+
return null
77+
}
78+
7679
const orgProcessor = unified()
7780
.use(uniorgParse)
81+
.data('settings', { fragment: true })
7882
.use(extractKeywords)
7983
.use(attachments, {
8084
idDir: attachDir || undefined,
@@ -123,11 +127,11 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
123127
// .use(highlight)
124128

125129
const isMarkdown = previewNode?.file?.slice(-3) === '.md'
126-
// const baseProcessor = isMarkdown ? mdProcessor : orgProcessor
130+
const baseProcessor = isMarkdown ? mdProcessor : orgProcessor
127131

128132
const processor = useMemo(
129133
() =>
130-
orgProcessor
134+
baseProcessor
131135
.use(katex, {
132136
trust: (context) => ['\\htmlId', '\\href'].includes(context.command),
133137
macros: {
@@ -138,12 +142,9 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
138142
...macros,
139143
},
140144
})
141-
// @ts-ignore
142145
.use(rehype2react, {
143-
Fragment: prod.Fragment,
144-
jsx: prod.jsx,
145-
jsxs: prod.jsxs,
146146
createElement: React.createElement,
147+
// eslint-disable-next-line react/display-name
147148
components: {
148149
a: ({ children, href }) => {
149150
return (
@@ -166,8 +167,8 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
166167
</PreviewLink>
167168
)
168169
},
169-
img: (org) => {
170-
return <OrgImage org={org} file={previewNode?.file} />
170+
img: ({ src }) => {
171+
return <OrgImage src={src as string} file={previewNode?.file} />
171172
},
172173
section: ({ children, className }) => {
173174
if (className && (className as string).slice(-1) === `${previewNode.level}`) {
@@ -219,10 +220,6 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
219220
)
220221

221222
const text = useMemo(() => processor.processSync(previewText).result, [previewText])
222-
if (!previewNode || !linksByNodeId) {
223-
return null
224-
}
225-
226223
return (
227224
<NoteContext.Provider value={{ collapse, outline }}>{text as ReactNode}</NoteContext.Provider>
228225
)

0 commit comments

Comments
 (0)