/
msg.ts
48 lines (43 loc) · 826 Bytes
/
msg.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
import { PluginSettings } from "./app";
export type PostMessage =
| {
type: "refreshFigmaData";
}
| {
type: "log";
payload: {
count: number;
foo: boolean;
};
}
| {
type: "create";
}
| {
type: "close";
}
| {
type: "notifiy";
payload: {
message: string;
options?: NotificationOptions;
};
}
| {
type: "toggleLibraries";
};
export type UIPostMessagePayload = {
settings: PluginSettings;
};
export type UIPostMessage = {
data: {
pluginId: string;
pluginMessage: UIPostMessagePayload;
};
};
export const postToUI = (msg: UIPostMessagePayload) => {
figma.ui.postMessage(msg);
};
export const postToFigma = (msg: PostMessage) => {
parent.postMessage({ pluginMessage: msg }, "*");
};