-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💥 Major refactoring / fixed modal display issues
- Loading branch information
1 parent
0f135fa
commit 6bd818a
Showing
14 changed files
with
170 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import { LocalGraphContext } from "@vaultusaurus/plugin/types"; | ||
import { IGraphContext } from "@vaultusaurus/plugin/types"; | ||
|
||
import { createContext } from "react"; | ||
|
||
export const GraphContext = createContext<LocalGraphContext>({ | ||
setHoveredNode: () => {}, | ||
adjacencyMap: {}, | ||
simulation: null, | ||
export const GraphContext = createContext<IGraphContext>({ | ||
hoverManager: { | ||
hoveredNode: null, | ||
setHoveredNode: () => {}, | ||
adjacencyMap: {}, | ||
}, | ||
graphManager: { | ||
nodes: {}, | ||
links: [], | ||
simulation: null, | ||
expanded: false, | ||
setExpanded: () => {}, | ||
}, | ||
graphStyle: {}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import useGraphManager from "./useGraphManager"; | ||
import useGraphNode from "./useGraphNode"; | ||
import useHover from "./useHover"; | ||
import useLocalGraph from "./useLocalGraph"; | ||
import useHoverManager from "./useHoverManager"; | ||
import useZoom from "./useZoom"; | ||
|
||
export { useGraphNode, useHover, useLocalGraph, useZoom }; | ||
export { useGraphManager, useGraphNode, useHoverManager, useZoom }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { ReactElement, useContext, useRef } from "react"; | ||
|
||
import { GraphStyle } from "@vaultusaurus/common/options"; | ||
import { | ||
GraphInfo, | ||
GraphNodeInfo, | ||
GraphNodeLinkInfo, | ||
} from "@vaultusaurus/common/types"; | ||
import { GraphContext } from "@vaultusaurus/plugin/context"; | ||
import styles from "@vaultusaurus/plugin/css/index.module.css"; | ||
import { useZoom } from "@vaultusaurus/plugin/hooks"; | ||
import CollapseIcon from "@vaultusaurus/plugin/resources/CollapseIcon.svg"; | ||
import ExpandIcon from "@vaultusaurus/plugin/resources/ExpandIcon.svg"; | ||
import GraphLink from "@vaultusaurus/plugin/theme/GraphLink"; | ||
import GraphNode from "@vaultusaurus/plugin/theme/GraphNode"; | ||
|
||
interface IGraphContent { | ||
info: GraphInfo; | ||
modal: boolean; | ||
style: GraphStyle; | ||
nodes: GraphNodeInfo[]; | ||
links: GraphNodeLinkInfo[]; | ||
expanded: boolean; | ||
setExpanded: () => void; | ||
} | ||
|
||
export default function GraphContent({ | ||
expandable = true, | ||
modal = false, | ||
}): ReactElement<IGraphContent> { | ||
const { graphStyle, graphManager } = useContext(GraphContext); | ||
const { setExpanded, nodes, links } = graphManager; | ||
|
||
const inlineStyles = { | ||
"--vaultusaurus-graph-bg": graphStyle.graphBg, | ||
"--vaultusaurus-default-color": graphStyle.defaultColor, | ||
"--vaultusaurus-active-color": graphStyle.defaultColor, | ||
} as React.CSSProperties; | ||
|
||
const container = useRef(null); | ||
const { transform } = useZoom(container); | ||
|
||
return ( | ||
<div | ||
className={modal ? styles.modalContainer : styles.container} | ||
style={inlineStyles} | ||
> | ||
{!modal && expandable && ( | ||
<ExpandIcon | ||
className={styles.actionIcon} | ||
onClick={() => setExpanded(true)} | ||
/> | ||
)} | ||
{modal && ( | ||
<CollapseIcon | ||
className={styles.actionIcon} | ||
onClick={() => setExpanded(false)} | ||
/> | ||
)} | ||
<svg viewBox={`0 0 300 300`} ref={container}> | ||
<g transform={transform}> | ||
{links.map((link, idx) => { | ||
return <GraphLink key={`obsidian-link-${idx}`} link={link} />; | ||
})} | ||
{Object.values(nodes).map((node) => ( | ||
<GraphNode key={node.id} node={node} /> | ||
))} | ||
</g> | ||
</svg> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { usePluginData } from "@docusaurus/useGlobalData"; | ||
import { GraphInfo, VaultusaurusGlobalData } from "@vaultusaurus/common/types"; | ||
import { GraphContext } from "@vaultusaurus/plugin/context"; | ||
import styles from "@vaultusaurus/plugin/css/index.module.css"; | ||
import { useGraphManager, useHoverManager } from "@vaultusaurus/plugin/hooks"; | ||
import { | ||
FALLBACK_ACTIVE_COLOR, | ||
FALLBACK_BACKGROUND_COLOR, | ||
FALLBACK_DEFAULT_COLOR, | ||
} from "@vaultusaurus/plugin/utils"; | ||
import { ReactElement } from "react"; | ||
import { createPortal } from "react-dom"; | ||
import GraphContent from "./GraphContent"; | ||
|
||
interface ILocalGraph { | ||
customGraph?: GraphInfo; | ||
expandable?: boolean; | ||
} | ||
|
||
export default function VaultusaurusGraph({ | ||
customGraph, | ||
}): ReactElement<ILocalGraph> { | ||
const globalData = usePluginData( | ||
"docusaurus-plugin-vaultusaurus" | ||
) as VaultusaurusGlobalData; | ||
const graphInfo: GraphInfo = | ||
globalData.graphInfo[window.location.pathname] || customGraph; | ||
|
||
if (!graphInfo) { | ||
return null; | ||
} | ||
const inputGraphStyle = globalData.graphStyle; | ||
|
||
const graphManager = useGraphManager(graphInfo); | ||
const rawLinks = graphInfo?.links || []; | ||
const expanded = graphManager.expanded; | ||
|
||
return ( | ||
<GraphContext.Provider | ||
value={{ | ||
hoverManager: useHoverManager(rawLinks), | ||
graphManager: graphManager, | ||
graphStyle: { | ||
activeColor: inputGraphStyle.activeColor || FALLBACK_ACTIVE_COLOR, | ||
defaultColor: inputGraphStyle.defaultColor || FALLBACK_DEFAULT_COLOR, | ||
graphBg: inputGraphStyle.graphBg || FALLBACK_BACKGROUND_COLOR, | ||
}, | ||
}} | ||
> | ||
{expanded && | ||
createPortal( | ||
<div className={expanded ? styles.modalOverlay : styles.hidden}> | ||
<GraphContent modal expandable={false} /> | ||
</div>, | ||
document.body | ||
)} | ||
<GraphContent /> | ||
</GraphContext.Provider> | ||
); | ||
} |
Oops, something went wrong.