-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathui.html
More file actions
193 lines (166 loc) · 6.08 KB
/
ui.html
File metadata and controls
193 lines (166 loc) · 6.08 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Figma 2 Maui</title>
<style>
.frame {
width: 300px;
height: 300px;
border: 1px solid #ccc;
padding: 20px;
}
h1 {
text-align: left;
}
.popup-button {
text-align: right;
margin-right: 15px;
}
.node {
display: flex;
align-items: center
}
.nodeDiv {
width: -webkit-fill-available;
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 4px;
margin-right: 10px;
padding: 4px;
}
.select{
border-radius: 0.3rem;
}
.children {
display: none; /* Initially hide children */
}
.unfolded {
display: block; /* Show children when unfolded */
}
.button-bar{
display: flex;
justify-content: space-between;
align-items: flex-end;
padding: 20px;
}
#save-button{
color: white;
background-color: rgb(83, 88, 209);
border-radius: 0.5rem;
border: 2px solid rgb(83, 88, 209);
}
#export-button{
color: white;
background-color: rgb(75, 75, 75);
border-radius: 0.5rem;
border: 2px solid rgb(75, 75, 75);
}
hr{
width: 95%;
}
</style>
</head>
<body>
<div>
<h3>Figma Design 2 .NET MAUI Code Generator</h3>
<div class="popup-button">
<a href="#" id="popup-link">How 2 use?</a>
</div>
<ul id="node-list">
<!-- JavaScript will populate this list -->
</ul>
<div class="button-bar">
<button class="button" id="save-button">Save</button>
<button class="button" id="export-button">Export Design</button>
<a id="downloadLink" style="display: none;">Download Code</a>
</div>
</div>
<script>
onmessage = (event) => {
const data = event.data.pluginMessage;
//console.log('data: ', data);
if (data.type === 'init') {
const selectedValues = [];
function createNodeElement(node) {
const listItem = document.createElement('li');
const nodeDiv = document.createElement('div');
nodeDiv.className = 'nodeDiv';
const textDiv = document.createElement('div');
const select = document.createElement('select');
textDiv.textContent = node.parent.name;
nodeDiv.appendChild(textDiv);
select.className = 'select';
select.innerHTML = `
<div class="node-name">${node.parent.name}</div>
<div>
<select>
<option value="" disabled selected>Select value</option>
<option value="None">None</option>
<option value="BUTTON">Button</option>
<option value="IMAGE">Image</option>
<option value="CHECHBOX">Check Box</option>
<option value="SLIDER">Slider</option>
<option value="SWITCH">Radio Buttin</option>
<option value="EDITOR">Text Area</option>
<option value="ENTRY">Input Field</option>
</select>
</div>
`;
select.addEventListener('change', (event) => {
const selectedValue = event.target.value;
selectedValues.push({node, selectedValue});
});
nodeDiv.appendChild(select);
listItem.appendChild(nodeDiv);
if (node.children.length > 0) {
const childrenList = document.createElement('ul');
childrenList.className = 'children';
node.children.forEach((child) => {
const childNodeElement = createNodeElement(child);
childrenList.appendChild(childNodeElement);
});
listItem.appendChild(childrenList);
// Add click event to toggle children visibility
textDiv.style.cursor = 'pointer';
textDiv.addEventListener('click', () => {
childrenList.classList.toggle('unfolded');
});
}
return listItem;
}
const nodeList = document.getElementById("node-list");
data.nodes.forEach((node) => {
const nodeElement = createNodeElement(node);
nodeList.appendChild(nodeElement);
});
const exportButton = document.getElementById("export-button");
exportButton.addEventListener('click', () => {
parent.postMessage({ pluginMessage: selectedValues }, '*')
});
}
else if (data.type === 'fileInfo') {
//console.log(data.textContent);
downloadCode(data.textContent);
}
function downloadCode(generatedCode) {
const blob = new Blob([generatedCode], { type: 'text/plain' });
// Create a URL for the Blob
const url = window.URL.createObjectURL(blob);
// Create a download link
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = url;
downloadLink.download = 'generated_code.txt';
// Display the download link and trigger the download
downloadLink.style.display = 'block';
downloadLink.click();
// Clean up the URL and hide the link
window.URL.revokeObjectURL(url);
downloadLink.style.display = 'none';
}
}
</script>
</body>
</html>