-
Notifications
You must be signed in to change notification settings - Fork 3
/
messages.ts
83 lines (65 loc) · 2.63 KB
/
messages.ts
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
import { TransitionalMetadata } from "../transitionals/types";
// Types of messages which can be exchanged between the core and the webview
export const enum CoreToWebviewMessageType {
UpdateTransitionalContent = "UpdateTransitionalContent",
UpdateTransitionalMetadata = "UpdateTransitionalMetadata",
UpdatePDF = "UpdatePDF",
UpdateCompilationStatus = "UpdateCompilationStatus",
UpdateGlobalOptions = "UpdateGlobalOptions"
}
export const enum WebviewToCoreMessageType {
NotifyTransitionalModel = "NotifyTransitionalModel",
SaveAndRecompileRequest = "SaveAndRecompileRequest",
}
export type MessageType =
CoreToWebviewMessageType | WebviewToCoreMessageType;
// Specification of each type of message which can be sent by the core to the webview
export interface UpdateTransitionalContentMessage {
type: CoreToWebviewMessageType.UpdateTransitionalContent;
codeMappingId: number;
contentAsHtml: string;
}
export interface UpdateTransitionalMetadataMessage {
type: CoreToWebviewMessageType.UpdateTransitionalMetadata;
codeMappingId: number;
metadata: TransitionalMetadata;
}
export interface UpdatePDFMessage {
type: CoreToWebviewMessageType.UpdatePDF;
pdfUri: string;
}
export interface UpdateCompilationStatusMessage {
type: CoreToWebviewMessageType.UpdateCompilationStatus;
pdfIsCurrentlyCompiled: boolean;
lastCompilationFailed: boolean;
}
export interface UpdateGlobalOptionsMessage {
type: CoreToWebviewMessageType.UpdateGlobalOptions;
options: {
enableTransitionals: boolean;
}
}
export type CoreToWebviewMessage =
| UpdateTransitionalContentMessage
| UpdateTransitionalMetadataMessage
| UpdatePDFMessage
| UpdateCompilationStatusMessage
| UpdateGlobalOptionsMessage;
// Specification of each type of message which can be sent by the webview to the core
export interface NotifyTransitionalModelMessage {
type: WebviewToCoreMessageType.NotifyTransitionalModel;
transitionalUid: number;
title: string;
notification: object;
};
export interface SaveAndRecompileRequestMessage {
type: WebviewToCoreMessageType.SaveAndRecompileRequest;
}
export type WebviewToCoreMessage =
NotifyTransitionalModelMessage | SaveAndRecompileRequestMessage;
// Generic type of a message exchanged between the core and the webview
export type Message =
CoreToWebviewMessage | WebviewToCoreMessage;
// Generic type of all messages which match the given message type constraint
// (e.g. when T = CoreToWebviewMessageType, it matches all messages which can be sent by the core)
export type MessagesOfType<T extends MessageType> = Extract<Message, { type: T; }>;