-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrenderLinkedReferenceAdditions.ts
More file actions
50 lines (45 loc) · 1.36 KB
/
Copy pathrenderLinkedReferenceAdditions.ts
File metadata and controls
50 lines (45 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import nanoid from "nanoid";
import { createElement } from "react";
import renderWithUnmount from "roamjs-components/util/renderWithUnmount";
import CanvasReferences from "~/components/canvas/CanvasReferences";
import { OnloadArgs } from "roamjs-components/types";
import { DiscourseContextCollapseOverlay } from "~/components/DiscourseContextOverlay";
import { handleTitleAdditions } from "./handleTitleAdditions";
export const renderDiscourseContext = ({
h1,
uid,
}: {
h1: HTMLHeadingElement;
uid: string;
}): void => {
if (h1.getAttribute("data-roamjs-top-discourse-context")) return;
handleTitleAdditions(
h1,
createElement(DiscourseContextCollapseOverlay, {
uid,
id: nanoid(),
}),
{ layout: "inline" },
);
h1.setAttribute("data-roamjs-top-discourse-context", "true");
};
export const renderCanvasReferences = (
div: HTMLDivElement,
uid: string,
onloadArgs: OnloadArgs,
): void => {
if (div.getAttribute("data-roamjs-canvas-reference")) return;
div.setAttribute("data-roamjs-canvas-reference", "true");
const parent = div.firstElementChild;
if (!parent) return;
const insertBefore = parent.firstElementChild;
const canvasP = document.createElement("div");
parent.insertBefore(canvasP, insertBefore);
renderWithUnmount(
createElement(CanvasReferences, {
uid,
}),
canvasP,
onloadArgs,
);
};