Skip to content

Commit 677a4dc

Browse files
committed
Better naming
1 parent 26621d3 commit 677a4dc

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

plugin/helpers/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ export function roundToDecimals(value: number | string, decimals: number = 2): n
3333
}
3434

3535

36-
export const notifyConfigDefault = { timeout: 3000, error: false, button: { text: "OK", action: () => console.log("Notification closed") } };
36+
export const notifyConfigDevDefault = { timeout: 3000, error: false, button: { text: "OK", action: () => console.log("Notification closed") } };

plugin/pluginController.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Config */
22
import { PLUGIN_UI_CONFIG as UiConfig } from './config';
33
/* Helpers */
4-
import { getNodeProps, notifyConfigDefault } from './helpers/helpers';
4+
import { getNodeProps, notifyConfigDevDefault } from './helpers/helpers';
55
/* Demo */
66
import { createColorfulSpiral } from './demo/spiralGenerator';
77

@@ -20,7 +20,7 @@ figma.ui.onmessage = (msg) => {
2020
origin: 'figma',
2121
message: `Created a spiral with ${msg.count} ${msg.shape}s`,
2222
});
23-
figma.notify("Figma: Created spiral", notifyConfigDefault);
23+
figma.notify("Figma: Created spiral", notifyConfigDevDefault);
2424
break;
2525
case 'demo-insert-quote':
2626
let quote = msg.quote ?? '';
@@ -38,7 +38,7 @@ figma.ui.onmessage = (msg) => {
3838
figma.currentPage.appendChild(textNode);
3939
figma.currentPage.selection = [textNode];
4040
figma.viewport.scrollAndZoomIntoView([textNode]);
41-
figma.notify("Figma: Inserted quote", notifyConfigDefault);
41+
figma.notify("Figma: Inserted quote", notifyConfigDevDefault);
4242
})
4343
.catch(err => {
4444
console.error("Failed to load font:", err);
@@ -47,7 +47,12 @@ figma.ui.onmessage = (msg) => {
4747
break;
4848
/* /DEMO */
4949

50-
case 'get-selection-contents-deep':
50+
case 'get-frame-contents-deep':
51+
/* check if selection has at least one frame */
52+
if (!figma.currentPage.selection.some(node => node.type === 'FRAME')) {
53+
figma.notify("Figma: No frame selected", notifyConfigDevDefault);
54+
break;
55+
}
5156
const frameContents = figma.currentPage.selection
5257
.filter(node => node.type === 'FRAME')
5358
.flatMap(frame => {
@@ -71,15 +76,15 @@ figma.ui.onmessage = (msg) => {
7176
console.log(frameContents);
7277
figma.notify("Figma: Selection contents sent. Check console for details.");
7378
figma.ui.postMessage({
74-
type: 'get-selection-contents-deep',
79+
type: 'get-frame-contents-deep',
7580
origin: 'figma',
7681
message: frameContents,
7782
});
7883
break;
7984

8085
case 'show-notification':
8186
if (msg.message) {
82-
figma.notify(msg.message, notifyConfigDefault);
87+
figma.notify(msg.message, notifyConfigDevDefault);
8388
}
8489
break;
8590

ui/app/Demo/SelectionChanges.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ export default function SelectionChanges({ sendToFigma, figmaSelectedNodeCount:
66
<div>
77
<h3 className="text-md font-bold">Inter-process communication</h3>
88
<p className='text-xs text-gray-500 pb-2'>Nodes selected in Figma: {fsnc}</p>
9-
<button onClick={() => sendToFigma({ type: 'get-selection-contents-deep' })} type="button"
9+
<button onClick={() => sendToFigma({ type: 'get-frame-contents-deep' })} type="button"
1010
className='text-sm text-white py-1 px-3 rounded-sm bg-blue-500 hover:bg-blue-700'>
11-
Get selection contents
11+
Get frame contents
1212
</button>
1313
</div>
1414
);

0 commit comments

Comments
 (0)