figma-mcp-console 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/bin/darwin-amd64/figma-mcp +0 -0
- package/bin/darwin-arm64/figma-mcp +0 -0
- package/bin/linux-amd64/figma-mcp +0 -0
- package/bin/linux-arm64/figma-mcp +0 -0
- package/bin/plugin/code.js +1091 -114
- package/bin/plugin/manifest.json +1 -0
- package/bin/plugin/ui.html +498 -30
- package/bin/windows-amd64/figma-mcp.exe +0 -0
- package/bin/windows-arm64/figma-mcp.exe +0 -0
- package/package.json +2 -2
package/bin/plugin/manifest.json
CHANGED
package/bin/plugin/ui.html
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
* {
|
|
3
3
|
box-sizing: border-box;
|
|
4
4
|
}
|
|
5
|
+
|
|
5
6
|
html,
|
|
6
7
|
body {
|
|
7
8
|
height: 100%;
|
|
8
9
|
}
|
|
10
|
+
|
|
9
11
|
body {
|
|
10
12
|
font:
|
|
11
13
|
12px/1.5 -apple-system,
|
|
@@ -13,19 +15,21 @@
|
|
|
13
15
|
"Segoe UI",
|
|
14
16
|
sans-serif;
|
|
15
17
|
margin: 0;
|
|
16
|
-
padding:
|
|
18
|
+
padding: 10px;
|
|
17
19
|
color: #2c2c34;
|
|
18
20
|
background: linear-gradient(160deg, #f6f7fb 0%, #eef0f7 100%);
|
|
19
21
|
display: flex;
|
|
20
22
|
flex-direction: column;
|
|
21
23
|
}
|
|
24
|
+
|
|
22
25
|
.card {
|
|
23
26
|
background: #fff;
|
|
24
27
|
border: 1px solid #e6e8f0;
|
|
25
|
-
border-radius:
|
|
26
|
-
padding: 9px
|
|
28
|
+
border-radius: 9px;
|
|
29
|
+
padding: 7px 9px;
|
|
27
30
|
box-shadow: 0 1px 2px rgba(30, 34, 60, 0.04);
|
|
28
31
|
}
|
|
32
|
+
|
|
29
33
|
#status-row {
|
|
30
34
|
display: flex;
|
|
31
35
|
align-items: center;
|
|
@@ -35,6 +39,7 @@
|
|
|
35
39
|
font-size: 13px;
|
|
36
40
|
color: #1f2330;
|
|
37
41
|
}
|
|
42
|
+
|
|
38
43
|
#dot {
|
|
39
44
|
flex: none;
|
|
40
45
|
width: 9px;
|
|
@@ -46,45 +51,231 @@
|
|
|
46
51
|
background 0.2s,
|
|
47
52
|
box-shadow 0.2s;
|
|
48
53
|
}
|
|
54
|
+
|
|
49
55
|
#dot.on {
|
|
50
56
|
background: #22a06b;
|
|
51
57
|
box-shadow: 0 0 0 3px rgba(34, 160, 107, 0.15);
|
|
52
58
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
|
|
60
|
+
#result {
|
|
61
|
+
display: none;
|
|
62
|
+
margin-top: 10px;
|
|
63
|
+
border-top: 1px solid #eceef5;
|
|
64
|
+
padding-top: 9px;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#result.show {
|
|
68
|
+
display: block;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.res-head {
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
justify-content: space-between;
|
|
75
|
+
margin-bottom: 6px;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.res-title {
|
|
79
|
+
font-weight: 600;
|
|
80
|
+
font-size: 10px;
|
|
81
|
+
color: #8288a0;
|
|
82
|
+
text-transform: uppercase;
|
|
83
|
+
letter-spacing: 0.04em;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.res-list {
|
|
87
|
+
display: flex;
|
|
88
|
+
flex-direction: column;
|
|
89
|
+
gap: 4px;
|
|
90
|
+
max-height: 190px;
|
|
91
|
+
overflow: auto;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.res-row {
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
gap: 6px;
|
|
98
|
+
padding: 5px 7px;
|
|
99
|
+
border: 1px solid #e6e8f0;
|
|
100
|
+
border-radius: 7px;
|
|
101
|
+
background: #fbfcfe;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.res-name {
|
|
105
|
+
flex: 1;
|
|
106
|
+
min-width: 0;
|
|
107
|
+
overflow: hidden;
|
|
108
|
+
text-overflow: ellipsis;
|
|
109
|
+
white-space: nowrap;
|
|
110
|
+
font-size: 11px;
|
|
111
|
+
color: #2c2c34;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.res-type {
|
|
115
|
+
flex: none;
|
|
116
|
+
font-size: 9px;
|
|
117
|
+
color: #a0a4b0;
|
|
118
|
+
text-transform: uppercase;
|
|
119
|
+
letter-spacing: 0.03em;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.copy-btn {
|
|
123
|
+
flex: none;
|
|
124
|
+
border: 1px solid #d6d9e6;
|
|
125
|
+
background: #fff;
|
|
126
|
+
color: #4b5168;
|
|
127
|
+
border-radius: 6px;
|
|
128
|
+
padding: 2px 8px;
|
|
129
|
+
font-size: 10px;
|
|
130
|
+
cursor: pointer;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* ---- checkpoint: what changed in the selected frame since the user saved it ---- */
|
|
134
|
+
#cp:empty {
|
|
135
|
+
display: none;
|
|
136
|
+
}
|
|
137
|
+
#cp {
|
|
138
|
+
margin-top: 10px;
|
|
56
139
|
font-size: 11px;
|
|
57
|
-
line-height: 1.45;
|
|
58
140
|
}
|
|
141
|
+
#cp .res-head {
|
|
142
|
+
margin-bottom: 4px;
|
|
143
|
+
font-size: 10px;
|
|
144
|
+
}
|
|
145
|
+
.cp-bar {
|
|
146
|
+
display: flex;
|
|
147
|
+
align-items: center;
|
|
148
|
+
gap: 5px;
|
|
149
|
+
}
|
|
150
|
+
.cp-list {
|
|
151
|
+
max-height: 220px;
|
|
152
|
+
overflow: auto;
|
|
153
|
+
margin-top: 5px;
|
|
154
|
+
}
|
|
155
|
+
.cp-row {
|
|
156
|
+
padding: 3px 5px;
|
|
157
|
+
border-radius: 5px;
|
|
158
|
+
cursor: pointer;
|
|
159
|
+
overflow-wrap: anywhere;
|
|
160
|
+
}
|
|
161
|
+
.cp-row:hover {
|
|
162
|
+
background: #f0f2f8;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.copy-btn:hover {
|
|
166
|
+
background: #f0f2f8;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.copy-btn.done {
|
|
170
|
+
color: #22a06b;
|
|
171
|
+
border-color: #bfe6d3;
|
|
172
|
+
background: #f0faf5;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.copy-all {
|
|
176
|
+
padding: 1px 6px;
|
|
177
|
+
font-size: 10px;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.out-close {
|
|
181
|
+
border: none;
|
|
182
|
+
background: none;
|
|
183
|
+
color: #8288a0;
|
|
184
|
+
cursor: pointer;
|
|
185
|
+
font-size: 13px;
|
|
186
|
+
padding: 0 2px;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.muted {
|
|
190
|
+
color: #8288a0;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.k-del {
|
|
194
|
+
color: #d1434b;
|
|
195
|
+
font-weight: 600;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.k-chg {
|
|
199
|
+
color: #b7791f;
|
|
200
|
+
font-weight: 600;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.used {
|
|
204
|
+
color: #22a06b;
|
|
205
|
+
font-weight: 600;
|
|
206
|
+
}
|
|
207
|
+
|
|
59
208
|
#credit {
|
|
60
209
|
margin-top: auto;
|
|
61
|
-
padding-top:
|
|
210
|
+
padding-top: 7px;
|
|
62
211
|
text-align: center;
|
|
63
212
|
color: #a0a4b0;
|
|
64
213
|
font-size: 10px;
|
|
65
214
|
}
|
|
66
|
-
|
|
215
|
+
|
|
216
|
+
#version {
|
|
67
217
|
color: #8288a0;
|
|
68
|
-
text-decoration: none;
|
|
69
218
|
}
|
|
70
|
-
|
|
71
|
-
|
|
219
|
+
|
|
220
|
+
/* ---- read-only switch and activity log ---- */
|
|
221
|
+
#act-head {
|
|
222
|
+
display: flex;
|
|
223
|
+
align-items: center;
|
|
224
|
+
gap: 6px;
|
|
225
|
+
margin-top: 10px;
|
|
226
|
+
border-top: 1px solid #eceef5;
|
|
227
|
+
padding-top: 8px;
|
|
228
|
+
font-size: 10.5px;
|
|
229
|
+
}
|
|
230
|
+
#act-head label {
|
|
231
|
+
display: flex;
|
|
232
|
+
align-items: center;
|
|
233
|
+
gap: 4px;
|
|
234
|
+
cursor: pointer;
|
|
235
|
+
}
|
|
236
|
+
#act-counts {
|
|
237
|
+
flex: 1;
|
|
238
|
+
text-align: right;
|
|
239
|
+
cursor: pointer;
|
|
240
|
+
white-space: nowrap;
|
|
241
|
+
}
|
|
242
|
+
#activity {
|
|
243
|
+
margin-top: 4px;
|
|
244
|
+
font-size: 10.5px;
|
|
245
|
+
}
|
|
246
|
+
#activity:not(.open) {
|
|
247
|
+
display: none;
|
|
248
|
+
}
|
|
249
|
+
.act-row {
|
|
250
|
+
padding: 2px 4px;
|
|
251
|
+
border-radius: 4px;
|
|
252
|
+
white-space: nowrap;
|
|
253
|
+
overflow: hidden;
|
|
254
|
+
text-overflow: ellipsis;
|
|
255
|
+
}
|
|
256
|
+
.act-row[data-id] {
|
|
257
|
+
cursor: pointer;
|
|
258
|
+
}
|
|
259
|
+
.act-row[data-id]:hover {
|
|
260
|
+
background: #f0f2f8;
|
|
72
261
|
}
|
|
73
262
|
</style>
|
|
74
263
|
|
|
75
264
|
<div class="card">
|
|
76
|
-
<div id="status-row">
|
|
265
|
+
<div id="status-row" title="Keep open while AI works · run it in every file">
|
|
77
266
|
<span id="dot"></span><span id="status">Connecting…</span>
|
|
78
267
|
</div>
|
|
79
|
-
<div id="
|
|
80
|
-
|
|
81
|
-
|
|
268
|
+
<div id="result"></div>
|
|
269
|
+
<div id="cp"></div>
|
|
270
|
+
<div id="act-head">
|
|
271
|
+
<label title="Refuse every AI command that would change this file"><input type="checkbox" id="readonly" checked> Read-only</label>
|
|
272
|
+
<span id="act-counts" class="muted" title="Show or hide what the AI did in this file"></span>
|
|
273
|
+
<button id="act-clear" class="out-close" title="Clear the log">×</button>
|
|
82
274
|
</div>
|
|
275
|
+
<div id="activity"></div>
|
|
83
276
|
</div>
|
|
84
277
|
<div id="credit">
|
|
85
|
-
<
|
|
86
|
-
>@hoangann2000</a
|
|
87
|
-
>
|
|
278
|
+
<span id="version"></span>
|
|
88
279
|
</div>
|
|
89
280
|
|
|
90
281
|
<script>
|
|
@@ -98,7 +289,7 @@
|
|
|
98
289
|
// the status line also trigger an immediate attempt.
|
|
99
290
|
const PORT = 2000,
|
|
100
291
|
RETRY = 1000,
|
|
101
|
-
PROTOCOL =
|
|
292
|
+
PROTOCOL = 3; // must match bridge.ProtocolVersion in the Go server
|
|
102
293
|
let ws = null; // open connection, null while disconnected
|
|
103
294
|
let attempt = null; // socket currently trying to connect
|
|
104
295
|
let reg = null; // {key, name} of this file, sent by the main thread
|
|
@@ -116,7 +307,9 @@
|
|
|
116
307
|
|
|
117
308
|
function sendRegister() {
|
|
118
309
|
if (ws && ws.readyState === WebSocket.OPEN && reg) {
|
|
119
|
-
|
|
310
|
+
// protocol tells the server this window's build, so an error from an
|
|
311
|
+
// outdated plugin can say "re-import" instead of "unknown command".
|
|
312
|
+
ws.send(JSON.stringify({ register: Object.assign({}, reg, { protocol: PROTOCOL }) }));
|
|
120
313
|
}
|
|
121
314
|
}
|
|
122
315
|
|
|
@@ -135,24 +328,42 @@
|
|
|
135
328
|
ws = sock;
|
|
136
329
|
sendRegister();
|
|
137
330
|
setStatus(true, label());
|
|
331
|
+
cp = { id: null };
|
|
332
|
+
syncCheckpoint();
|
|
138
333
|
};
|
|
139
334
|
sock.onmessage = (e) => {
|
|
140
335
|
const msg = JSON.parse(e.data);
|
|
141
336
|
if (msg.hello) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
337
|
+
// Name the side that is behind: a stale server is just as common as
|
|
338
|
+
// a stale plugin, and blaming the plugin sends people re-importing
|
|
339
|
+
// a plugin that was already up to date.
|
|
340
|
+
// Show which server build we are talking to; "dev" means a local
|
|
341
|
+
// go build rather than a release.
|
|
342
|
+
if (msg.hello.version) {
|
|
343
|
+
document.getElementById("version").textContent = "v" + msg.hello.version;
|
|
344
|
+
}
|
|
345
|
+
protoWarning = null;
|
|
346
|
+
if (msg.hello.protocol && msg.hello.protocol !== PROTOCOL) {
|
|
347
|
+
protoWarning =
|
|
348
|
+
msg.hello.protocol < PROTOCOL
|
|
349
|
+
? "⚠ Server outdated — restart your AI client"
|
|
350
|
+
: "⚠ Plugin outdated — re-import from the latest release";
|
|
351
|
+
}
|
|
146
352
|
setStatus(true, label());
|
|
147
353
|
return;
|
|
148
354
|
}
|
|
149
|
-
|
|
150
|
-
|
|
355
|
+
if (msg.checkpointResult) return onCheckpointResult(msg.checkpointResult);
|
|
356
|
+
// Relay only commands: the socket must not reach the window's own
|
|
357
|
+
// messages (setReadOnly, uiAction) or a local process could unlock the file.
|
|
358
|
+
if (msg.id && msg.command) {
|
|
359
|
+
parent.postMessage({ pluginMessage: { id: msg.id, command: msg.command, params: msg.params } }, "*");
|
|
360
|
+
}
|
|
151
361
|
};
|
|
152
362
|
sock.onclose = () => {
|
|
153
363
|
if (attempt === sock) attempt = null;
|
|
154
364
|
if (ws === sock) ws = null;
|
|
155
365
|
if (!ws) {
|
|
366
|
+
drawCheckpoint();
|
|
156
367
|
setStatus(false, "Searching for MCP server…");
|
|
157
368
|
schedule();
|
|
158
369
|
}
|
|
@@ -160,7 +371,7 @@
|
|
|
160
371
|
sock.onerror = () => {
|
|
161
372
|
try {
|
|
162
373
|
sock.close();
|
|
163
|
-
} catch (e) {}
|
|
374
|
+
} catch (e) { }
|
|
164
375
|
};
|
|
165
376
|
}
|
|
166
377
|
|
|
@@ -173,8 +384,246 @@
|
|
|
173
384
|
}, RETRY);
|
|
174
385
|
}
|
|
175
386
|
|
|
387
|
+
// ---- live selection list (name + copyable link) ----
|
|
388
|
+
let selItems = []; // everything currently selected in Figma
|
|
389
|
+
|
|
390
|
+
function esc(s) {
|
|
391
|
+
return String(s)
|
|
392
|
+
.replace(/&/g, "&")
|
|
393
|
+
.replace(/</g, "<")
|
|
394
|
+
.replace(/>/g, ">")
|
|
395
|
+
.replace(/"/g, """);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Frames copy as a link block; every other element copies its exported SVG.
|
|
399
|
+
function copyLabelFor(it) {
|
|
400
|
+
return it.type === "FRAME" ? "Copy" : "Copy SVG";
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// Copyable text for one item. Frames use the requested link format:
|
|
404
|
+
// # <name>:
|
|
405
|
+
// <link>
|
|
406
|
+
// Other elements return their SVG (or the export error, so the click still
|
|
407
|
+
// gives feedback instead of silently copying nothing).
|
|
408
|
+
function copyValueForItem(it) {
|
|
409
|
+
if (it.type === "FRAME") return "# " + it.name + ":\n" + (it.link || "");
|
|
410
|
+
return it.svg || it.svgError || "";
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function renderSelection(items) {
|
|
414
|
+
if (items) selItems = items;
|
|
415
|
+
drawSelection();
|
|
416
|
+
syncCheckpoint();
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// ---- checkpoint: save the selected frame's design, later ask what changed ----
|
|
420
|
+
// The server keeps the snapshot and does the comparing; this only asks and shows.
|
|
421
|
+
let canEdit = false;
|
|
422
|
+
let cp = { id: null }; // { id, saved, changes, total, busy, error } for the selected node
|
|
423
|
+
|
|
424
|
+
function askCheckpoint(op) {
|
|
425
|
+
if (!ws || ws.readyState !== WebSocket.OPEN || !cp.id) return;
|
|
426
|
+
if (op !== "status") cp.busy = op;
|
|
427
|
+
ws.send(JSON.stringify({ checkpoint: { op, node_id: cp.id } }));
|
|
428
|
+
drawCheckpoint();
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function syncCheckpoint() {
|
|
432
|
+
const id = canEdit && selItems.length === 1 ? selItems[0].id : null;
|
|
433
|
+
if (id === cp.id) return;
|
|
434
|
+
cp = { id };
|
|
435
|
+
drawCheckpoint();
|
|
436
|
+
askCheckpoint("status");
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function onCheckpointResult(r) {
|
|
440
|
+
if (r.node_id !== cp.id) return; // the selection moved on
|
|
441
|
+
cp.busy = null;
|
|
442
|
+
cp.error = r.error || null;
|
|
443
|
+
if (r.saved) cp.saved = r.saved;
|
|
444
|
+
if (r.op === "save" && !r.error) cp.changes = null;
|
|
445
|
+
if (r.op === "diff" && !r.error) {
|
|
446
|
+
cp.changes = r.changes || [];
|
|
447
|
+
cp.total = r.total || 0;
|
|
448
|
+
}
|
|
449
|
+
drawCheckpoint();
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const CP_KIND = { "+": ['used', "added"], "-": ['k-del', "removed"], "~": ['k-chg', "changed"] };
|
|
453
|
+
|
|
454
|
+
function drawCheckpoint() {
|
|
455
|
+
const box = document.getElementById("cp");
|
|
456
|
+
if (!cp.id || !ws) {
|
|
457
|
+
box.innerHTML = "";
|
|
458
|
+
return fit();
|
|
459
|
+
}
|
|
460
|
+
let html =
|
|
461
|
+
'<div class="res-head"><span class="res-title">Checkpoint</span>' +
|
|
462
|
+
'<span class="muted" title="Saved on this computer; the file is not changed">' +
|
|
463
|
+
(cp.saved ? "Saved " + esc(cp.saved) : "Not saved yet") + "</span></div>" +
|
|
464
|
+
'<div class="cp-bar"><button class="copy-btn" data-cp="save"' + (cp.busy ? " disabled" : "") + ' title="Remember this frame as it is now">' +
|
|
465
|
+
(cp.busy === "save" ? "Saving…" : "Save checkpoint") + "</button>" +
|
|
466
|
+
(cp.saved
|
|
467
|
+
? '<button class="copy-btn" data-cp="diff"' + (cp.busy ? " disabled" : "") + ' title="What changed in this frame since the checkpoint">' +
|
|
468
|
+
(cp.busy === "diff" ? "Comparing…" : "What changed?") + "</button>"
|
|
469
|
+
: "") +
|
|
470
|
+
"</div>";
|
|
471
|
+
if (cp.error) html += '<div class="k-del">' + esc(cp.error) + "</div>";
|
|
472
|
+
else if (cp.changes) {
|
|
473
|
+
html += cp.changes.length
|
|
474
|
+
? '<div class="cp-list">' +
|
|
475
|
+
cp.changes.map((c) => {
|
|
476
|
+
const k = CP_KIND[c.kind] || ["muted", ""];
|
|
477
|
+
return '<div class="cp-row" data-id="' + esc(c.id) + '" title="Show this layer"><span class="' + k[0] + '">' + k[1] +
|
|
478
|
+
"</span> <b>" + esc(c.name) + "</b>" + (c.detail ? ' <span class="muted">' + esc(c.detail) + "</span>" : "") + "</div>";
|
|
479
|
+
}).join("") +
|
|
480
|
+
"</div>" +
|
|
481
|
+
(cp.total > cp.changes.length ? '<div class="muted">First ' + cp.changes.length + " of " + cp.total + " changes.</div>" : "")
|
|
482
|
+
: '<div class="used">No changes since the checkpoint.</div>';
|
|
483
|
+
}
|
|
484
|
+
box.innerHTML = html;
|
|
485
|
+
fit();
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
document.getElementById("cp").addEventListener("click", (e) => {
|
|
489
|
+
const btn = e.target.closest("[data-cp]");
|
|
490
|
+
if (btn) return askCheckpoint(btn.dataset.cp);
|
|
491
|
+
const row = e.target.closest(".cp-row");
|
|
492
|
+
// A removed layer no longer exists; the plugin ignores a select it cannot do.
|
|
493
|
+
if (row) parent.postMessage({ pluginMessage: { uiAction: "select", nodeId: row.dataset.id } }, "*");
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
function drawSelection() {
|
|
497
|
+
const box = document.getElementById("result");
|
|
498
|
+
if (!selItems.length) {
|
|
499
|
+
box.className = "";
|
|
500
|
+
box.innerHTML = "";
|
|
501
|
+
fit();
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
const head =
|
|
505
|
+
'<div class="res-head"><span class="res-title">Selected (' + selItems.length + ")</span>" +
|
|
506
|
+
(selItems.length > 1 ? '<button class="copy-btn copy-all" data-all="1">Copy all</button>' : "") +
|
|
507
|
+
"</div>";
|
|
508
|
+
|
|
509
|
+
const body =
|
|
510
|
+
'<div class="res-list">' +
|
|
511
|
+
selItems
|
|
512
|
+
.map(
|
|
513
|
+
(it, i) =>
|
|
514
|
+
'<div class="res-row">' +
|
|
515
|
+
'<span class="res-name" title="' + esc(it.name) + '">' + esc(it.name) + "</span>" +
|
|
516
|
+
'<span class="res-type">' + esc(it.type) + "</span>" +
|
|
517
|
+
'<button class="copy-btn" data-i="' + i + '">' + copyLabelFor(it) + "</button>" +
|
|
518
|
+
"</div>",
|
|
519
|
+
)
|
|
520
|
+
.join("") +
|
|
521
|
+
"</div>";
|
|
522
|
+
|
|
523
|
+
box.innerHTML = head + body;
|
|
524
|
+
box.className = "show";
|
|
525
|
+
fit();
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// Ask the main thread to size the window to its content.
|
|
529
|
+
function fit() {
|
|
530
|
+
requestAnimationFrame(() => {
|
|
531
|
+
const card = document.querySelector(".card");
|
|
532
|
+
const credit = document.getElementById("credit");
|
|
533
|
+
const h = card.getBoundingClientRect().bottom + credit.offsetHeight + 12;
|
|
534
|
+
parent.postMessage({ pluginMessage: { resize: h } }, "*");
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// What each button copies: a row copies its own value (link block for a
|
|
539
|
+
// frame, SVG otherwise); "Copy all" joins every item with a blank line between.
|
|
540
|
+
function copyValueFor(btn) {
|
|
541
|
+
if (btn.hasAttribute("data-all")) {
|
|
542
|
+
return selItems.map(copyValueForItem).join("\n\n");
|
|
543
|
+
}
|
|
544
|
+
const it = selItems[+btn.getAttribute("data-i")];
|
|
545
|
+
return it ? copyValueForItem(it) : "";
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// navigator.clipboard is often unavailable in the plugin iframe, so use the
|
|
549
|
+
// textarea + execCommand fallback which works reliably here.
|
|
550
|
+
function copyText(text) {
|
|
551
|
+
const ta = document.createElement("textarea");
|
|
552
|
+
ta.value = text;
|
|
553
|
+
ta.style.position = "fixed";
|
|
554
|
+
ta.style.opacity = "0";
|
|
555
|
+
document.body.appendChild(ta);
|
|
556
|
+
ta.select();
|
|
557
|
+
try {
|
|
558
|
+
document.execCommand("copy");
|
|
559
|
+
} catch (e) { }
|
|
560
|
+
document.body.removeChild(ta);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
document.getElementById("result").addEventListener("click", (e) => {
|
|
564
|
+
const btn = e.target.closest(".copy-btn");
|
|
565
|
+
if (!btn) return;
|
|
566
|
+
copyText(copyValueFor(btn));
|
|
567
|
+
const old = btn.textContent;
|
|
568
|
+
btn.textContent = "Copied";
|
|
569
|
+
btn.classList.add("done");
|
|
570
|
+
setTimeout(() => {
|
|
571
|
+
btn.textContent = old;
|
|
572
|
+
btn.classList.remove("done");
|
|
573
|
+
}, 1200);
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
// ---- activity log: what the AI did in this file, newest first ----
|
|
577
|
+
let acts = [];
|
|
578
|
+
let counts = { read: 0, write: 0, error: 0 };
|
|
579
|
+
|
|
580
|
+
function logActivity(a) {
|
|
581
|
+
counts[a.error ? "error" : a.write ? "write" : "read"]++;
|
|
582
|
+
acts.unshift(Object.assign({ time: new Date().toTimeString().slice(0, 8) }, a));
|
|
583
|
+
acts = acts.slice(0, 5);
|
|
584
|
+
renderActivity();
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function renderActivity() {
|
|
588
|
+
const open = document.getElementById("activity").classList.contains("open");
|
|
589
|
+
const parts = [];
|
|
590
|
+
if (counts.read) parts.push(counts.read + " read");
|
|
591
|
+
if (counts.write) parts.push(counts.write + " write");
|
|
592
|
+
if (counts.error) parts.push('<span class="k-del">' + counts.error + " error</span>");
|
|
593
|
+
document.getElementById("act-counts").innerHTML =
|
|
594
|
+
"AI: " + (parts.join(" · ") || "no activity") + (open ? " ▾" : " ▸");
|
|
595
|
+
document.getElementById("activity").innerHTML = acts
|
|
596
|
+
.map((a) =>
|
|
597
|
+
'<div class="act-row"' + (a.node && !a.error ? ' data-id="' + esc(a.node) + '"' : "") + ' title="' + esc(a.error || a.command) + '">' +
|
|
598
|
+
'<span class="muted">' + a.time + "</span> " +
|
|
599
|
+
(a.error ? '<span class="k-del">✗</span> ' : '<span class="used">✓</span> ') + esc(a.command) +
|
|
600
|
+
(a.write && !a.error ? ' <span class="k-chg">edit</span>' : "") +
|
|
601
|
+
(a.error ? ' <span class="muted">' + esc(a.error) + "</span>" : "") +
|
|
602
|
+
"</div>")
|
|
603
|
+
.join("");
|
|
604
|
+
fit();
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
document.getElementById("readonly").onchange = (e) =>
|
|
608
|
+
parent.postMessage({ pluginMessage: { setReadOnly: e.target.checked } }, "*");
|
|
609
|
+
document.getElementById("act-clear").onclick = () => {
|
|
610
|
+
acts = [];
|
|
611
|
+
counts = { read: 0, write: 0, error: 0 };
|
|
612
|
+
renderActivity();
|
|
613
|
+
};
|
|
614
|
+
document.getElementById("act-counts").onclick = () => {
|
|
615
|
+
document.getElementById("activity").classList.toggle("open");
|
|
616
|
+
renderActivity();
|
|
617
|
+
};
|
|
618
|
+
renderActivity();
|
|
619
|
+
document.getElementById("activity").addEventListener("click", (e) => {
|
|
620
|
+
const row = e.target.closest(".act-row[data-id]");
|
|
621
|
+
if (row) parent.postMessage({ pluginMessage: { uiAction: "select", nodeId: row.dataset.id } }, "*");
|
|
622
|
+
});
|
|
623
|
+
|
|
176
624
|
// Relay plugin main-thread frames: the register frame is cached here and
|
|
177
|
-
// re-sent on every reconnect
|
|
625
|
+
// re-sent on every reconnect, the selection frame drives the list above, and
|
|
626
|
+
// everything else goes to the server.
|
|
178
627
|
window.onmessage = (e) => {
|
|
179
628
|
const msg = e.data.pluginMessage;
|
|
180
629
|
if (!msg) return;
|
|
@@ -184,6 +633,24 @@
|
|
|
184
633
|
if (ws) setStatus(true, label());
|
|
185
634
|
return;
|
|
186
635
|
}
|
|
636
|
+
if (Array.isArray(msg.selection)) {
|
|
637
|
+
renderSelection(msg.selection);
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
if (msg.activity) {
|
|
641
|
+
logActivity(msg.activity);
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
if (msg.canEdit !== undefined) {
|
|
645
|
+
canEdit = msg.canEdit;
|
|
646
|
+
cp = { id: null };
|
|
647
|
+
syncCheckpoint();
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
if (msg.readOnly !== undefined) {
|
|
651
|
+
document.getElementById("readonly").checked = msg.readOnly;
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
187
654
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
188
655
|
ws.send(JSON.stringify(msg));
|
|
189
656
|
}
|
|
@@ -195,4 +662,5 @@
|
|
|
195
662
|
});
|
|
196
663
|
|
|
197
664
|
connect();
|
|
198
|
-
|
|
665
|
+
fit();
|
|
666
|
+
</script>
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "figma-mcp-console",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"prepublishOnly": "cp
|
|
5
|
+
"prepublishOnly": "test -d bin/plugin && cd .. && go vet ./... && go test ./... && node --check plugin/code.js && cp README.md npm/README.md"
|
|
6
6
|
},
|
|
7
7
|
"description": "Figma MCP server for AI coding assistants — real-time read/write via a Figma Desktop plugin. No API token, no rate limits.",
|
|
8
8
|
"bin": {
|