From 78f15c54c2e0d1f61abc9eec4d88ee020b191e95 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Tue, 2 Nov 2021 23:24:07 +0100 Subject: Feat/collapse: add collapsible/toggleable headers and outline layout in the preview panel (#139) * feat(preview): collapsible headings * feat(preview): collapsible headings * feat(collapse): change icons for headings * feat(collapse): * feat(collapse): use new uniorg and better looks * feat(collapse): fix typescript errors * fix(ci): better filter * feat(collapse): more small adjustments * feat(collapse): collapse all button * fix(collapse): fix global css * fix(cd): remove yarn and add export * fix(collapse): type-errors * fix(cd): fix format-all fucking up yml --- util/NoteContext.tsx | 11 +++++++++++ util/processOrg.tsx | 28 +++++++++++++++++++++------- util/uniorg.tsx | 6 ++++++ 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 util/NoteContext.tsx (limited to 'util') diff --git a/util/NoteContext.tsx b/util/NoteContext.tsx new file mode 100644 index 0000000..4578ca2 --- /dev/null +++ b/util/NoteContext.tsx @@ -0,0 +1,11 @@ +import { createContext } from 'react' + +export interface NoteContextProps { + outline: boolean + collapse: boolean +} + +export const NoteContext = createContext({ + outline: false, + collapse: true, +}) diff --git a/util/processOrg.tsx b/util/processOrg.tsx index 6d3a380..84eb280 100644 --- a/util/processOrg.tsx +++ b/util/processOrg.tsx @@ -8,15 +8,16 @@ import attachments from 'uniorg-attach' // rehypeHighlight does not have any types // add error thing here // import highlight from 'rehype-highlight' -//import sectionParent from '@agentofuser/rehype-section' import katex from 'rehype-katex' import 'katex/dist/katex.css' import rehype2react from 'rehype-react' import { PreviewLink } from '../components/Sidebar/Link' import { NodeByCite, NodeById } from '../pages' -import React, { useMemo } from 'react' +import React, { createContext, ReactNode, useMemo } from 'react' import { OrgImage } from '../components/Sidebar/OrgImage' +import { Section } from '../components/Sidebar/Section' +import { NoteContext } from './NoteContext' export interface ProcessedOrgProps { nodeById: NodeById @@ -26,6 +27,8 @@ export interface ProcessedOrgProps { nodeByCite: NodeByCite setSidebarHighlightedNode: any openContextMenu: any + outline: boolean + collapse: boolean } export const ProcessedOrg = (props: ProcessedOrgProps) => { @@ -37,17 +40,17 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => { nodeByCite, previewNode, openContextMenu, + outline, + collapse, } = props - //const section = sectionParent.default const processor = unified() .use(uniorgParse) .use(extractKeywords) .use(attachments) .use(uniorgSlug) - .use(uniorg2rehype) + .use(uniorg2rehype, { useSections: true }) //.data('settings', { fragment: true }) - //.use(section) // .use(highlight) .use(katex) .use(rehype2react, { @@ -63,17 +66,28 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => { nodeById={nodeById} setPreviewNode={setPreviewNode} openContextMenu={openContextMenu} + outline={outline} > {children} ) }, img: ({ src }) => { - return + return + }, + section: ({ children, className }) => ( +
+ {children} +
+ ), + p: ({ children }) => { + return

{children as ReactNode}

}, }, }) const text = useMemo(() => processor.processSync(previewText).result, [previewText]) - return <>{text} + return ( + {text as ReactNode} + ) } diff --git a/util/uniorg.tsx b/util/uniorg.tsx index 98aa878..d0251c0 100644 --- a/util/uniorg.tsx +++ b/util/uniorg.tsx @@ -10,6 +10,8 @@ export interface UniOrgProps { nodeByCite: NodeByCite setSidebarHighlightedNode: any openContextMenu: any + outline: boolean + collapse: boolean } export const UniOrg = (props: UniOrgProps) => { @@ -20,6 +22,8 @@ export const UniOrg = (props: UniOrgProps) => { nodeByCite, previewNode, setPreviewNode, + outline, + collapse, } = props const [previewText, setPreviewText] = useState('') @@ -58,6 +62,8 @@ export const UniOrg = (props: UniOrgProps) => { nodeByCite, setSidebarHighlightedNode, openContextMenu, + outline, + collapse, }} /> )} -- cgit v1.2.3