-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.html
More file actions
245 lines (212 loc) · 7.53 KB
/
ui.html
File metadata and controls
245 lines (212 loc) · 7.53 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<style>
body {
background-color: var(--figma-color-bg);
color: var(--figma-color-text);
font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
display: flex;
flex-direction: column;
margin-top: 0;
padding: 10px;
gap: 0.5rem;
}
h2 {
margin: 8px 0;
}
p {
margin: 8px 0;
}
#input-container {
display: flex;
flex-direction: column;
padding: 0.75rem;
background-color: var(--figma-color-bg-secondary);
gap: 0.5rem;
border-radius: 1rem;
}
#input-wrapper {
display: flex;
gap: 0.25rem;
height: fit-content;
font-size: 13px;
letter-spacing: 0.05rem;
flex-direction: column;
}
input {
font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
padding: 8px;
border: 2px solid var(--figma-color-border-brand);
border-radius: 4px;
font-size: 14px !important;
width: 100%;
}
input:focus-visible,
button:focus-visible {
outline: 3px solid var(--figma-color-border-brand-strong);
}
.input-label {
margin: 0 2px;
font-size: 12px;
letter-spacing: 0.75px;
color: var(--figma-color-text-secondary);
font-weight: 300;
}
#text-box {
display: flex;
flex-direction: row;
gap: 0.5rem;
}
.error-msg {
color: var(--figma-color-text-danger);
font-size: 0.9rem;
margin: 0 2px;
}
.button-container {
padding: 0;
display: grid;
grid-template-columns: 1fr 1fr;
/* flex-direction: column; */
gap: 8px;
}
button {
font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 15px;
font-weight: 500;
cursor: pointer;
padding: 10px 8px;
border: none;
border-radius: 4px;
}
button:hover {
outline: 2px solid var(--figma-color-border-brand-strong);
}
button[disabled="true"] {
background-color: var(--figma-color-bg-disabled);
color: var(--figma-color-text-disabled);
outline: none;
cursor: default;
}
.primary-button {
background-color: var(--figma-color-bg-brand);
color: var(--figma-color-text-onbrand);
}
.secondary-button {
background-color: var(--figma-color-bg-brand-secondary);
color: var(--figma-color-text-onbrand);
}
.cancel-button {
background-color: var(--figma-color-bg-tertiary);
color: var(--figma-color-text-onbrand);
}
.description {
font-size: 0.9em;
color: var(--figma-color-text-secondary);
font-weight: 300;
}
</style>
<div class="">
<p>⚠️ <strong>Important</strong></p>
<p class="description">
Paste the file link (Share > Copy Link) below to ensure your links will redirect to the correct file.
</p>
</div>
<!-- The following is needed when private plugin API is unavailable, like publicly published plugins -->
<div id="input-container">
<div id="input-wrapper">
<p class="input-label">File Link</p>
<div id="text-box"><input id="file-link" type="text" value="" placeholder="Share -> Copy Link">
<button id="update-link" class="secondary-button">Update</button>
</div>
</div>
<div id="add-error-msg" class="error-msg"> </div>
<div id="file-name" class=""> </div>
</div>
<p class="description">
<strong>Ignores</strong>: Frames that are hidden, named "Meeting Notes", start with "." or "_", or are unnamed.
<br> Also removes leading emojis from page names.
</p>
<div id="button-container" class="button-container">
<button id="pages" class="primary-button" disabled="false">All Pages</button>
<button id="selected" class="primary-button" disabled="false">Selected Frames and Sections</button>
<button id="sections" class="primary-button" disabled="false">All Sections on Page</button>
<button id="generate" class="primary-button" disabled="false">All Frames on Page</button>
<!-- <button id="cancel" class="cancel-button" disabled="false">Cancel</button> -->
</div>
<script>
var fileTitle = "";
function toggleButtonState(btnContainerId, bool) { // Enables and disables multiple buttons when given its parent container
let container = document.getElementById(btnContainerId);
if (container.children != 0) {
if (bool == true) { // if bool arg is true, enable. If false, disable the buttons
for (const child of container.children) {
child.removeAttribute('disabled');
}
} else {
for (const child of container.children) {
child.setAttribute('disabled', true);
}
}
}
}
function extractFileName(linkText) { // Takes a Figma link and extracts the file title. Very basic, doesn't account for special characters
let extractedName = linkText.split("/")[5];
extractedName = decodeURIComponent(extractedName.split("?node-id")[0]);
extractedName = extractedName.replace(/\-/g, ' ');
return extractedName;
}
function displayMsg(msg, container) { // Displays message on UI and hides the parent container if none
let msgContainer = document.getElementById(container);
msgContainer.innerHTML = "";
if (msg == "clear") {
msgContainer.style.display = "none";
} else {
let errorFeedback = document.createTextNode(msg);
msgContainer.appendChild(errorFeedback);
msgContainer.style.display = "inherit";
}
}
function validateLink(linkText) {
if (linkText == "") { // Display error if input is empty
displayMsg("Please add a link to the current file", "add-error-msg");
fileTitle = "";
return false;
}
else if (!linkText.includes("https://www.figma.com/design/")) { // Display error if input lacks figma design url format
displayMsg("Invalid link", "add-error-msg");
fileTitle = "";
return false;
} else { // Passes validation: Clear error messages, extract file name from URL
displayMsg("clear", "add-error-msg");
fileTitle = extractFileName(linkText);
toggleButtonState("button-container", true);
return true;
}
}
function showFileTitle() { // Updates file name on UI
let inputBox = document.getElementById("file-name");
inputBox.innerHTML = "";
let fileTitleText = document.createTextNode(fileTitle);
inputBox.appendChild(fileTitleText);
inputBox.style.display = "inherit";
toggleButtonState("button-container", true);
}
onmessage = (event) => { // When code.ts sends a file link, update file name
validateLink(event.data.pluginMessage);
showFileTitle();
const textbox = document.getElementById('file-link');
textbox.value = event.data.pluginMessage;
}
if (fileTitle == "") { toggleButtonState("button-container", false); } // If no file link has been added, disable the 'create' buttons
document.getElementById('update-link').onclick = () => { // Validates file link input, sends to code.ts
const textbox = document.getElementById('file-link');
const newFileLink = textbox.value;
if (validateLink(newFileLink)) {
parent.postMessage({ pluginMessage: { type: 'file-link', value: newFileLink } }, '*');
showFileTitle();
}
}
document.getElementById('pages').onclick = () => { parent.postMessage({ pluginMessage: { type: 'pages' } }, '*') }
document.getElementById('sections').onclick = () => { parent.postMessage({ pluginMessage: { type: 'sections' } }, '*') }
document.getElementById('generate').onclick = () => { parent.postMessage({ pluginMessage: { type: 'generate-toc' } }, '*'); }
document.getElementById('selected').onclick = () => { parent.postMessage({ pluginMessage: { type: 'selected' } }, '*'); }
// document.getElementById('cancel').onclick = () => { parent.postMessage({ pluginMessage: { type: 'cancel' } }, '*') }
</script>