Home


(codegen, showUI)

It is not normally allowed to call figma.showUI() in a codegen plugin, but there is an exception.

Quoting from ‘Jake (figma)’ in the Friends of Figma discord channel:

one thing i did want to add here is that there is one scenario where you can show a ui with a codegen plugin. you can add an action to your preferences menu, and when it is clicked, open up a ui window.
https://www.figma.com/plugin-docs/api/properties/figma-codegen-on/#signature

something like:

figma.codegen.on('preferenceschange', ({ propertyName }) => {  
  if (propertyName === "myThing") {  
    figma.showUI("...");  
  }  
});  

would require an action type preference in manifest.json…

{  
  // ...  
  "codegenPreferences": [  
    {  
      "itemType": "action",  
      "propertyName": "myThing",  
      "label": "Example action that opens ui"  
    }  
  ]  
  // ...  

source: https://discord.com/channels/675194100147945497/1129433678255235102/1129463367195709460

(spread operator, esbuild, figma, runtime error)

The usage of spreads leads to runtime errors when Figma plugins run.
The fix is to pass --target=es6 to the bundler, even if it is already set in tsconfig.json.
I bundle with:

esbuild src/main.ts --bundle --target=es6 --outfile=dist/main.js  

(figma, plugin API, exploration)

Get the color of the current selection:

figma.currentPage.selection[0].fills[0]  

Print readable 2d array in console, use console.table:

console.table(figma.currentPage.selection[0].fills[0].gradientTransform)  

(figma plugin, getting started)

(figma plugin, bundle multiple source files, esbuild, plugin setup)