-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerateStartEditingButton.tsx
More file actions
33 lines (26 loc) · 1016 Bytes
/
generateStartEditingButton.tsx
File metadata and controls
33 lines (26 loc) · 1016 Bytes
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
import { render } from "preact";
import { PublicLogger } from "../../logger/logger";
import StartEditingButtonComponent from "../components/startEditingButton";
/**
* Generates a start editing button for the visual builder.
*
* @returns The generated HTMLAnchorElement representing the start editing button, or undefined if the button cannot be created.
*/
export function generateStartEditingButton(): HTMLAnchorElement | undefined {
const existingButton = document.querySelector(
".visual-builder__start-editing-btn"
) as HTMLAnchorElement;
if (existingButton) {
return existingButton;
}
const wrapper = document.createDocumentFragment();
render(<StartEditingButtonComponent />, wrapper);
if (wrapper.children.length === 0) {
return undefined;
}
document.body.appendChild(wrapper);
const startEditingButton = document.querySelector(
".visual-builder__start-editing-btn"
) as HTMLAnchorElement;
return startEditingButton;
}