-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathmain.js
126 lines (117 loc) · 4.55 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const fs = require("uxp").storage.localFileSystem;
let rootNode = null;
let PANEL_HTML = null;
const $ = sel => rootNode && rootNode.querySelector(sel);
function panel() {
// Get Icon Data
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState == 4) {
var records = JSON.parse(this.responseText);
// Render all HTML icons
function renderHtmlData(iconStyle) {
var out = "";
var i, j;
for (i in records) {
out += '<div class="icon-category"><h3>' + records[i].name + '</h3><div class="icon-container">';
for (j in records[i].icons) {
if (iconStyle === "solid") {
out += '<img class="iconImage" id="' + records[i].icons[j] + '-solid" src="icons/' + records[i].icons[j] + '-solid.svg" draggable="true" />';
} else {
out += '<img class="iconImage" id="' + records[i].icons[j] + '" src="icons/' + records[i].icons[j] + '.svg" draggable="true" />';
}
}
out += '</div></div>';
}
return out;
}
var PANEL_STYLE = `
<style>
.header {
display:flex;
flex-direction: row;
margin-bottom: 10px;
background: #F7F7F7;
width: 100%
}
.icon-container {
display: flex;
flex-wrap: wrap;
flex: 1;
margin: 10px 0px 20px 0px;
}
.iconImage {
height: 45px;
width: 45px;
padding: 8px;
margin: 2px;
border-radius: 10px;
cursor: move;
}
.iconImage:hover {
border: solid 2px #0082F3;
}
.hide { display: none; }
.row { align-items: center; }
</style>
`
PANEL_HTML = PANEL_STYLE + `
<div method="dialog" id="main">
<div class="header">
<label class="row">
<span>Icon Style</span>
<select id="lstAction">
<option selected value="outline">Outline</option>
<option value="solid">Solid</option>
</select>
</label>
</div>
<div id="outlineIconCategoryContainer">
` + renderHtmlData("outline") + `
</div>
<div id="solidIconCategoryContainer" class="hide">
` + renderHtmlData("solid") + `
</div>
</div>`
}
};
xhr.open("GET", "denali-icon-categories.json", true);
xhr.send();
// Create the panel's DOM. We'll do this only once.
function create() {
if (rootNode) { return rootNode; }
rootNode = document.createElement("div");
rootNode.innerHTML = PANEL_HTML;
// Switch between solid and outline icons
$("#lstAction").onchange = (evt) => {
if (evt.target.value === "outline") {
document.getElementById("outlineIconCategoryContainer").classList.remove("hide");
document.getElementById("solidIconCategoryContainer").classList.add("hide");
} else {
document.getElementById("outlineIconCategoryContainer").classList.add("hide");
document.getElementById("solidIconCategoryContainer").classList.remove("hide");
}
console.log(evt.target.value);
}
return rootNode;
}
function show(event) {
event.node.appendChild(create());
// Get icon files
document.querySelectorAll('.iconImage').forEach(async (item) => {
const pluginFolder = await fs.getPluginFolder();
const theImagesFolder = await pluginFolder.getEntry("icons");
const icon = await theImagesFolder.getEntry(item.id + ".svg");
// Event on drag to place file
item.addEventListener('dragstart', event => {
event.dataTransfer.setData("text/uri-list", icon.nativePath);
})
})
}
return show
}
module.exports = {
panels: {
denaliIcons: panel()
}
};