2 |
Select one or more elements and choose the appropriate options below to create grid or a pattern
3 |
4 |
5 |
6 |
10 |
Rows
11 |
12 |
13 |
14 |
15 |
16 |
20 |
Columns
21 |
22 |
23 |
24 |
25 |
26 |
30 |
31 |
Padding
32 |
33 |
34 |
35 |
50 |
65 |
79 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/src/ui.js:
--------------------------------------------------------------------------------
1 | import './ui.css'
2 | import Vue from "vue";
3 |
4 | let app = new Vue({
5 | el: '#app',
6 | data: {
7 | config: {
8 | rows: 10,
9 | cols: 10,
10 | padding: 5,
11 | shuffle: false,
12 | repeat: true,
13 | group: true,
14 | },
15 | loading: false,
16 | },
17 | mounted() {
18 | // Initing plugin for saved settings
19 | parent.postMessage({ pluginMessage: { type: 'INIT_PLUGIN' } }, '*')
20 | },
21 | methods: {
22 | createPattern: function() {
23 | if (this.loading) return;
24 |
25 | this.loading = true;
26 |
27 | //Adding timeout to show the loader in button
28 | setTimeout(() => {
29 | parent.postMessage({ pluginMessage: { type: 'CREATE_GRID', options: this.config } }, '*');
30 | },100);
31 | }
32 | }
33 | })
34 |
35 | // Function to recieve events from figma
36 | onmessage = e => {
37 | if (!e.data) return;
38 |
39 | const data = e.data.pluginMessage.data;
40 | const type = e.data.pluginMessage.type;
41 |
42 | if (type === 'SETTINGS') {
43 | if (data) {
44 | Object.assign(app.config, data);
45 | }
46 | }
47 | if (type === 'DONE_LOADING') {
48 | app.loading = false;
49 | }
50 | if (type === 'ERROR_EMPTY_SELECTION') {
51 | app.loading = false;
52 | }
53 | };
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin')
2 | const HtmlWebpackPlugin = require('html-webpack-plugin')
3 | const VueLoaderPlugin = require('vue-loader/lib/plugin')
4 | const path = require('path')
5 |
6 | module.exports = (env, argv) => ({
7 | mode: argv.mode === 'production' ? 'production' : 'development',
8 |
9 | // This is necessary because Figma's 'eval' works differently than normal eval
10 | devtool: argv.mode === 'production' ? false : 'inline-source-map',
11 |
12 | entry: {
13 | ui: './src/ui.js', // The entry point for your UI code
14 | code: './src/code.js', // The entry point for your plugin code
15 | },
16 |
17 | module: {
18 | rules: [
19 | // Enables vue loader
20 | { test: /\.vue$/, loader: 'vue-loader' },
21 |
22 | // Enables including CSS by doing "import './file.css'" in your TypeScript code
23 | { test: /\.css$/, loader: [{ loader: 'style-loader' }, { loader: 'css-loader' }] },
24 |
25 | // Allows you to use "<%= require('./file.svg') %>" in your HTML code to get a data URI
26 | { test: /\.(png|jpg|gif|webp|svg)$/, loader: [{ loader: 'url-loader' }] },
27 | ],
28 | },
29 |
30 | // Webpack tries these extensions for you if you omit the extension like "import './file'"
31 | resolve: {
32 | extensions: ['.tsx', '.ts', '.jsx', '.js', '.vue'],
33 | alias: { vue: argv.mode === 'production' ? 'vue/dist/vue.min' : 'vue/dist/vue.js' }
34 | },
35 |
36 | output: {
37 | filename: '[name].js',
38 | path: path.resolve(__dirname, 'dist'), // Compile into a folder called "dist"
39 | },
40 |
41 | // Tells Webpack to generate "ui.html" and to inline "ui.ts" into it
42 | plugins: [
43 | new VueLoaderPlugin(),
44 | new HtmlWebpackPlugin({
45 | template: './src/ui.html',
46 | filename: 'ui.html',
47 | inlineSource: '.(js)$',
48 | chunks: ['ui'],
49 | }),
50 | new HtmlWebpackInlineSourcePlugin(),
51 | ],
52 | })
--------------------------------------------------------------------------------