summaryrefslogtreecommitdiff
path: root/util/normalizeLinkEnds.ts
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2022-09-27 16:32:13 +0200
committerGitHub <[email protected]>2022-09-27 16:32:13 +0200
commit6f783297f37e95d083b32a7160afcb55e309e883 (patch)
treeaf9fdc3db50ecbc61036d88c81eeea3703ff17cc /util/normalizeLinkEnds.ts
parent16a8da9e5107833032893bc4c0680b368ac423ac (diff)
parent1936250b99b8747d841edd83002ed20ec12aa793 (diff)
feat: add ability to add/remove nodes to/from the local graph from emacs
Adds the commands `org-roam-ui-add-to-local-graph` and `org-roam-ui-remove-from-local-graph`
Diffstat (limited to 'util/normalizeLinkEnds.ts')
-rw-r--r--util/normalizeLinkEnds.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/util/normalizeLinkEnds.ts b/util/normalizeLinkEnds.ts
new file mode 100644
index 0000000..43eee9c
--- /dev/null
+++ b/util/normalizeLinkEnds.ts
@@ -0,0 +1,12 @@
+import { OrgRoamLink } from '../api'
+import { LinkObject } from 'force-graph'
+
+export function normalizeLinkEnds(link: OrgRoamLink | LinkObject): [string, string] {
+ // we need to cover both because force-graph modifies the original data
+ // but if we supply the original data on each render, the graph will re-render sporadically
+ const sourceId =
+ typeof link.source === 'object' ? (link.source.id! as string) : (link.source as string)
+ const targetId =
+ typeof link.target === 'object' ? (link.target.id! as string) : (link.target as string)
+ return [sourceId, targetId]
+}