-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathmain.js
48 lines (42 loc) · 1.28 KB
/
main.js
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
const { create, update, setState } = require("./app/index");
const { downloadImage, getMapUrl, getDimensions } = require("./app/utils");
const { dialogs } = require("./xd-utils/index");
let panel;
function applyMap(state){
const { ImageFill } = require("scenegraph");
require("application").editDocument(async (selection) => {
const node = selection.items[0];
const {width, height} = getDimensions(node);
const url = getMapUrl({...state, width, height});
setState("loading", true);
try {
const tempFile = await downloadImage(url);
const imageFill = new ImageFill(tempFile);
node.fill = imageFill;
node.fillEnabled = true;
setState("loading", false);
} catch (errMsg) {
setState({loading: false, error: errMsg});
await dialogs.error("Error", errMsg.message);
}
});
}
function show(event) {
if (!panel) {
panel = create({
onApply: applyMap
});
event.node.appendChild(panel);
}
}
module.exports = {
panels: {
setMapAsFill: {
show,
update: () => {
const { selection } = require("scenegraph");
update(selection);
}
}
}
};