forked from microsoft/pxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakecodeEditorService.ts
More file actions
43 lines (33 loc) · 1.1 KB
/
Copy pathmakecodeEditorService.ts
File metadata and controls
43 lines (33 loc) · 1.1 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
import { logDebug } from "pxtservices/loggingService";
import { EditorDriver } from "pxtservices/editorDriver";
let driver: EditorDriver | undefined;
let highContrast: boolean = false;
export function setEditorRef(ref: HTMLIFrameElement | undefined) {
if (driver) {
if (driver.iframe === ref) return;
driver.dispose();
driver = undefined;
}
if (ref) {
driver = new EditorDriver(ref);
driver.addEventListener("message", ev => {
logDebug(`Message received from iframe: ${JSON.stringify(ev)}`);
});
driver.addEventListener("sent", ev => {
logDebug(`Sent message to iframe: ${JSON.stringify(ev)}`);
});
driver.setHighContrast(highContrast);
}
}
export async function loadTutorialAsync(tutorialMarkdown: string) {
if (driver) {
await driver.importTutorial(tutorialMarkdown);
}
}
// an example of events that we want to/can send to the editor
export async function setHighContrastAsync(on: boolean) {
highContrast = on;
if (driver) {
await driver!.setHighContrast(on)
}
}