-
Notifications
You must be signed in to change notification settings - Fork 7
ENG-2038 Add admin-flagged node card context menu to Obsidian tldraw #1255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b13ee4c
b6f04e1
84237b9
91862c1
fe0df5a
0658ee3
639524c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { createElement, useEffect, useState, type ComponentType } from "react"; | ||
| import type { TFile } from "obsidian"; | ||
| import { | ||
| DefaultStylePanel, | ||
| DefaultStylePanelContent, | ||
| useEditor, | ||
| useRelevantStyles, | ||
| useValue, | ||
| type TLUiStylePanelContentProps, | ||
| type TLUiStylePanelProps, | ||
| } from "tldraw"; | ||
| import type DiscourseGraphPlugin from "~/index"; | ||
| import type { DiscourseNodeShape } from "./shapes/DiscourseNodeShape"; | ||
| import { RelationsPanelContent } from "./overlays/RelationPanel"; | ||
|
|
||
| type NodeCardContextMenuProps = TLUiStylePanelProps & { | ||
| plugin: DiscourseGraphPlugin; | ||
| canvasFile: TFile; | ||
| }; | ||
|
|
||
| const NODE_CARD_CONTEXT_MENU_TABS = [ | ||
| { id: "context", label: "Context" }, | ||
| { id: "styling", label: "Styling" }, | ||
| ] as const; | ||
|
|
||
| type NodeCardContextMenuTab = | ||
| (typeof NODE_CARD_CONTEXT_MENU_TABS)[number]["id"]; | ||
|
|
||
| const DefaultStylePanelComponent = | ||
| DefaultStylePanel as unknown as ComponentType<TLUiStylePanelProps>; | ||
| const DefaultStylePanelContentComponent = | ||
| DefaultStylePanelContent as unknown as ComponentType<TLUiStylePanelContentProps>; | ||
|
|
||
| export const NodeCardContextMenu = ({ | ||
| plugin, | ||
| canvasFile, | ||
| isMobile, | ||
| }: NodeCardContextMenuProps) => { | ||
| const editor = useEditor(); | ||
| const styles = useRelevantStyles(); | ||
| const isEnabled = plugin.settings.nodeCardContextMenuEnabled ?? false; | ||
| const selectedShape = useValue( | ||
| "selected shape for node card context menu", | ||
| () => | ||
| editor.getCurrentToolId() === "select" | ||
| ? editor.getOnlySelectedShape() | ||
| : null, | ||
| [editor], | ||
| ); | ||
| const selectedNode = | ||
| isEnabled && selectedShape?.type === "discourse-node" | ||
| ? (selectedShape as DiscourseNodeShape) | ||
| : null; | ||
| const [activeTab, setActiveTab] = useState<NodeCardContextMenuTab>("context"); | ||
|
|
||
| useEffect(() => { | ||
| setActiveTab("context"); | ||
| }, [selectedNode?.id]); | ||
|
|
||
| if (!selectedNode) { | ||
| return createElement(DefaultStylePanelComponent, { isMobile }); | ||
| } | ||
|
|
||
| return createElement( | ||
| DefaultStylePanelComponent, | ||
| { isMobile }, | ||
| <div className="dg-node-card-menu"> | ||
| <div className="border-modifier-border grid grid-cols-2 border-b"> | ||
| {NODE_CARD_CONTEXT_MENU_TABS.map(({ id, label }) => ( | ||
| <button | ||
| key={id} | ||
| type="button" | ||
| aria-pressed={activeTab === id} | ||
| className={`cursor-pointer px-3 py-2 text-xs font-semibold ${ | ||
| activeTab === id ? "accent-border-bottom" : "" | ||
| }`} | ||
| onClick={() => setActiveTab(id)} | ||
| > | ||
| {label} | ||
| </button> | ||
| ))} | ||
| </div> | ||
|
|
||
| {activeTab === "context" ? ( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| <div className="p-3"> | ||
| <RelationsPanelContent | ||
| plugin={plugin} | ||
| canvasFile={canvasFile} | ||
| nodeShape={selectedNode} | ||
| /> | ||
| </div> | ||
| ) : ( | ||
| createElement(DefaultStylePanelContentComponent, { styles }) | ||
| )} | ||
|
Comment on lines
+84
to
+94
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Selecting a node card silently edits the canvas note and can append duplicate link blocks The relations list is now shown automatically whenever a single node card is selected ( How rendering the relations list triggers vault writesEach listed related file is rendered as a Previously this only ran after the user explicitly opened the floating Relations panel via the overlay button ( Additionally, Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
| </div>, | ||
| ); | ||
| }; | ||

Uh oh!
There was an error while loading. Please reload this page.