├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── livepreview.html ├── manifest.json ├── package.json ├── src ├── code.ts ├── codeMessageHandler.ts ├── ui │ ├── ui.html │ ├── ui.ts │ ├── ui.vue │ └── uiMessageHandler.ts └── vue-shims.d.ts ├── tsconfig.json └── webpack.config.js /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .DS_Store 4 | yarn.lock 5 | package-lock.json 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Jackie Chui 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vue 3 Plugin Template for Figma 2 | 3 | This template gets you up and running and building figma plugins with the Vue3 framework in a short time. 4 | 5 | ## Features: 6 | 7 | - Vue 8 | - Typescript 9 | - [figma-plugin-ds](https://github.com/thomas-lowry/figma-plugin-ds) integration 10 | - Message handler helper functions to simplify communication between the main code and the UI code. (Thanks to [@jackiecorn](https://github.com/jackiecorn)) 11 | - Live Server preview to make building UIs faster. `npm run preview` 12 | 13 | This template is built on top of [@jackiecorn/Vue-Plugin-Template](https://github.com/jackiecorn/Vue-Plugin-Template) and updated to use Vue3 14 | ## Downloading the template 15 | 16 | There are a few ways you can use this template. 17 | 18 | The simplest way is to hit ['use this template'](https://github.com/PluginFinchy/Figma-Vue3-Template/generate) 19 | 20 | Or [download the .zip](https://github.com/PluginFinchy/Figma-Vue3-Template/archive/main.zip) of this repo. 21 | 22 | Alternatively you can use this template as a template for your own github repo through the [github cli](https://github.com/cli/cli) 23 | 24 | `gh repo create "" -p "https://github.com/LukeFinch/Figma-Vue3-Template"` 25 | 26 | 27 | ## How to use? 28 | 29 | 1. Install dependencies with `npm i`. 30 | 2. Run `npm run dev` and a folder named `dist` will be created. 31 | 3. In the Figma desktop app, click on **Create new plugin** / **Link existing plugin** and point it to the `manifest.json` in this project. 32 | 4. Now you can edit the main Figma code from `src/code.ts` and the UI code from `src/ui/ui.vue`. Hitting save will auto-reload the build so you can see your changes right away. 33 | 5. When you're ready to publish the plugin, run `npm run build` to create a production build. 34 | 35 | ## Message handlers 36 | 37 | To communicate between the main code and the UI code, you can use the `dispatch` and `handleEvent` functions to send and listen to messages between the two environments. 38 | 39 | Sending a message from the main code to UI code: 40 | 41 | ``` 42 | dispatch('eventName', data) 43 | ``` 44 | 45 | Handling messages from the UI code to the main code: 46 | 47 | ``` 48 | handleEvent('eventName', data => { 49 | // Do something with the data 50 | }) 51 | ``` 52 | 53 | Note that data is optional so you could simply send a message by `dispatch('eventName')`. 54 | 55 | In the vue UI code, `dispatch` can be called anywhere, but `handleEvent` functions should be called in `mounted()` so they would only be called first and only once. 56 | 57 | This project template shows an example of a UI button sending a message to the main code to create a rectangle node. The main code then sends back the created node ID to be displayed in the UI. 58 | -------------------------------------------------------------------------------- /livepreview.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 |
8 |

9 | Plugin Preview 10 |

11 | 12 |

13 | Set the size for your plugin live preview 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 |