Skip to content

Commit

Permalink
add tooling and comment in code
Browse files Browse the repository at this point in the history
  • Loading branch information
thierryc committed Jul 7, 2024
1 parent bb83d00 commit a6beb7d
Show file tree
Hide file tree
Showing 6 changed files with 609 additions and 469 deletions.
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
code.js
# Node modules
node_modules/

# OS generated files
.DS_Store

# Environment variable files [ALWAYS]
.env
.env.local
.env.*.local

37 changes: 37 additions & 0 deletions code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use strict";
figma.showUI(__html__, {
width: 400,
height: 400,
});
let updateTimeout = 0;
let updateCounter = 0;
let prevMsg = '';
function update() {
clearTimeout(updateTimeout);
const selection = figma.currentPage.selection;
const node = selection.length === 1 ? selection[0] : null;
const msg = {
node: node === null || node.type !== 'VECTOR' ? null : {
id: node.id,
vectorNetwork: node.vectorNetwork,
},
};
const msgStr = JSON.stringify(msg);
if (msgStr !== prevMsg) {
prevMsg = msgStr;
figma.ui.postMessage(msg);
updateCounter = 0;
}
const timeout = updateCounter++ < 20 ? 16 : 250;
updateTimeout = setTimeout(update, timeout);
}
figma.on('selectionchange', update);
update();
figma.ui.onmessage = msg => {
if (msg.node) {
const node = figma.getNodeById(msg.node.id);
if (node !== null && node.type === 'VECTOR') {
node.vectorNetwork = msg.node.vectorNetwork;
}
}
};
13 changes: 10 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"name": "Fill Rule Editor",
"id": "771155994770327940",
"name": "figma-fill-rule-editor-dev",
"id": "1391765568770221941",
"api": "1.0.0",
"main": "code.js",
"ui": "ui.html"
"capabilities": [],
"enableProposedApi": false,
"ui": "ui.html",
"networkAccess": {
"allowedDomains": [
"none"
]
}
}
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "figma-fill-rule-editor-dev",
"version": "1.0.0",
"description": "This is a Figma plugin that lets you edit the fill rules of vector objects. Click here to install it: https://www.figma.com/c/plugin/771155994770327940.",
"main": "code.js",
"scripts": {
"build": "tsc -p tsconfig.json",
"lint": "eslint --ext .ts,.tsx --ignore-pattern node_modules .",
"lint:fix": "eslint --ext .ts,.tsx --ignore-pattern node_modules --fix .",
"watch": "npm run build -- --watch"
},
"author": "",
"license": "",
"devDependencies": {
"@figma/eslint-plugin-figma-plugins": "*",
"@figma/plugin-typings": "*",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"eslint": "^8.54.0",
"typescript": "^5.3.2"
},
"eslintConfig": {
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@figma/figma-plugins/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"root": true,
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
}
}
}
10 changes: 8 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"compilerOptions": {
"target": "es6",
"lib": ["es6"],
"strict": true,
"target": "es6"
}
"typeRoots": [
"./node_modules/@types",
"./node_modules/@figma"
]
},
"include": ["./code.ts"],
}
Loading

0 comments on commit a6beb7d

Please sign in to comment.