forked from TypeCellOS/BlockNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopypaste.ts
More file actions
85 lines (72 loc) · 2.59 KB
/
copypaste.ts
File metadata and controls
85 lines (72 loc) · 2.59 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { Page } from "@playwright/test";
import { PASTE_ZONE_SELECTOR, TYPE_DELAY } from "./const.js";
import { focusOnEditor } from "./editor.js";
export async function copyPaste(page: Page) {
await page.keyboard.press(`ControlOrMeta+C`);
await page.keyboard.press("ArrowDown", { delay: TYPE_DELAY });
await page.keyboard.press("Enter");
await page.keyboard.press(`ControlOrMeta+V`);
}
export async function copyPasteAll(page: Page) {
await page.keyboard.press(`ControlOrMeta+A`);
await copyPaste(page);
}
export async function copyPasteAllExternal(
page: Page,
os: "mac" | "linux" = "linux",
) {
const modifierKey = os === "mac" ? "Meta" : "Control";
await page.keyboard.press(`${modifierKey}+A`);
await page.keyboard.press(`${modifierKey}+C`);
await focusOnEditor(page);
const pasteZone = page.locator(PASTE_ZONE_SELECTOR);
await pasteZone.click();
await page.keyboard.press(`${modifierKey}+V`);
return await pasteZone.inputValue();
}
export function removeClassesFromHTML(html: string) {
return html.replace(/class="\S*"\s/g, "");
}
export function removeMetaFromHTML(html: string) {
return html.replace(/<meta charset='utf-8'>/g, "");
}
export async function insertParagraph(page: Page) {
await page.keyboard.type("Paragraph");
await page.keyboard.press("ArrowDown", { delay: TYPE_DELAY });
}
export async function insertHeading(page: Page, headingLevel: number) {
for (let i = 0; i < headingLevel; i++) {
await page.keyboard.press("#");
}
await page.keyboard.press(" ");
await page.keyboard.type("Heading");
await page.keyboard.press("ArrowDown", { delay: TYPE_DELAY });
}
export async function startList(page: Page, ordered: boolean) {
if (ordered) {
await page.keyboard.press("1");
await page.keyboard.press(".");
await page.keyboard.press(" ");
} else {
await page.keyboard.press("-");
await page.keyboard.press(" ");
}
}
export async function insertListItems(page: Page) {
await page.keyboard.type("List Item 1");
await page.keyboard.press("Enter");
await page.keyboard.type("List Item 2");
await page.keyboard.press("Enter");
await page.keyboard.type("List Item 3");
await page.keyboard.press("ArrowDown", { delay: TYPE_DELAY });
}
export async function insertNestedListItems(page: Page) {
await page.keyboard.type("List Item 1");
await page.keyboard.press("Enter");
await page.keyboard.press("Tab");
await page.keyboard.type("List Item 2");
await page.keyboard.press("Enter");
await page.keyboard.press("Tab");
await page.keyboard.type("List Item 3");
await page.keyboard.press("ArrowDown", { delay: TYPE_DELAY });
}