Try out Figma plugin eco system
eklem opened this issue · comments
Seems you can do more browser stuff i part of the plugin eco system there.
https://www.figma.com/plugin-docs/how-plugins-run/
The way to send and receive messages from UI (ifram) and plugin (sandboxed script connected to document):
https://www.figma.com/plugin-docs/creating-ui/
- Try out creating a plugin
-
console.log(this)
on first line of plugin to check what's available
* [x] Try out with search-index demo inui.html
. Doesn't work with IndexedDB - Try out with search-index demo in
ui.html
modified to use memdown instead of IndexedDB - Try out editing a text string in document from plugin
- Try out editing several text strings from array in plugin
- Send and array from UI to sandboxed script and edit document
- Try out with webpack'ing scripts
- Feed (post message) array of search data to sandbox and edit document
Accessing what's selected is done like this:
figma.currentPage.selection
Have to consider three situations:
- No layer is selected
- A single layer is selected
- Multiple layers are selected
The first one returns nothing (null?), error or something. Need to check. The two last ones seems to return an array.
And check if node.type === "TEXT"
Start by setting up a test-plugin
For just snooping around in the API, poke around in the Developer / Debugging Tool
Creating a plugin w/ a UI works fine. It creates a setup that needs TypeScript (and building step to create JavaScript from it), but it's only one line that is TS-specific:
const nodes: SceneNode[] = [];
--> const nodes = [];
Doesn't seem like IndexedDB is available in ui.html, only in the actual plugin environment.
So, for this to happen, one of two things is needed:
- Get a UI to work with a search-index running in the actual message. This means a lot of postMessages back and forth and maybe not so easy.
- Running the search-index in memory w/ memdown, as previously tested w/ AdobeXD.
And all css + code in ui.html needs to be in the document, not linked to.
Figmas plugin buildup seems quite different, so should be two different modules, or at least a big split in code.