Skip to content

Commit 6b122da

Browse files
committed
Add Display Netwrok implementation
2 parents 6eb90bd + 867bdf3 commit 6b122da

7 files changed

Lines changed: 96 additions & 40 deletions

File tree

manifest_prod.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Super Tidy",
3+
"id": "731260060173130163",
4+
"api": "1.0.0",
5+
"ui": "dist/ui.html",
6+
"main": "dist/core.js",
7+
"menu": [
8+
{"name": "Rename", "command": "rename"},
9+
{"name": "Reorder", "command": "reorder"},
10+
{"name": "Tidy", "command": "tidy"},
11+
{"name": "Run all", "command": "all"},
12+
{"separator": true},
13+
{"name": "Run custom...", "command": "options"}
14+
]
15+
}

package-lock.json

Lines changed: 33 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
},
2121
"dependencies": {
2222
"@basiclines/leo": "^0.6.4",
23-
"ua-parser-js": "^0.7.21"
23+
"ua-parser-js": "^0.7.24"
2424
}
2525
}

src/App.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
}
4848

4949
body { text-align: left; overflow: hidden; }
50-
root-ui { transition: opacity 0.05s linear; display: block; position: relative; height: 459px; }
50+
root-ui { transition: opacity 0.05s linear; display: block; position: relative; height: 539px; }
5151
root-ui[notready] { opacity: 0; pointer-events: none; }
5252

5353
.c-icon {

src/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ui extends Element {
6060
xspacing="${this.data.preferences.spacing.x}"
6161
yspacing="${this.data.preferences.spacing.y}"
6262
startname="${this.data.preferences.start_name}"
63+
wrapinstances="${this.data.preferences.wrap_instances}"
6364
renamestrategy="${this.data.preferences.rename_strategy}"
6465
>
6566
</v-form>

src/Core.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function cmdReorder() {
8787
})
8888
}
8989

90-
function cmdTidy(xSpacing, ySpacing) {
90+
function cmdTidy(xSpacing, ySpacing, wrapInstances) {
9191
var selection = figma.currentPage.selection
9292
var parent = (selection[0].type == 'PAGE') ? figma.currentPage : selection[0].parent
9393
var allNodes = parent.children
@@ -117,20 +117,34 @@ function cmdTidy(xSpacing, ySpacing) {
117117
xPos = col.x
118118
yPos = col.y
119119
}
120-
var match = allNodes.find(node => node.id === col.id)
121-
match.x = (colidx == 0) ? xPos : xPos + xSpacing;
122-
match.y = yPos
123-
xPos = match.x + match.width
120+
var match = allNodes.find(node => node.id === col.id)
121+
var newXPos = (colidx == 0) ? xPos : xPos + xSpacing;
122+
var newYPos = yPos
123+
124+
// Wrap instances with a frame around
125+
if (wrapInstances && match.type == 'INSTANCE') {
126+
var instanceParent = figma.createFrame()
127+
instanceParent.x = newXPos
128+
instanceParent.y = newYPos
129+
instanceParent.resize(match.width, match.height)
130+
instanceParent.appendChild(match)
131+
match.x = 0
132+
match.y = 0
133+
figma.currentPage.selection = figma.currentPage.selection.concat(instanceParent)
134+
} else {
135+
match.x = newXPos
136+
match.y = newYPos
137+
}
138+
139+
xPos = newXPos + match.width
124140
})
125141

126142
xPos = x0
127143
yPos = yPos + (tallestInRow[rowidx] + ySpacing)
128144
})
129145
}
130146

131-
// Obtain UUID then trigger init event
132-
133-
// Obtain UUID and saved file url then trigger init event
147+
// Obtain UUID and preferences then trigger init event
134148
Promise.all([
135149
figma.clientStorage.getAsync('UUID'),
136150
figma.clientStorage.getAsync('preferences'),
@@ -144,11 +158,13 @@ Promise.all([
144158

145159
let SPACING = { x: 100, y: 200 }
146160
let START_NAME = '000'
161+
let WRAP_INSTANCES = true
147162
let RENAME_STRATEGY_REPLACE = 'replace'
148163
let RENAME_STRATEGY_MERGE = 'merge'
149164
let PREFERENCES = {
150165
spacing: SPACING,
151166
start_name: START_NAME,
167+
wrap_instances: WRAP_INSTANCES,
152168
rename_strategy: RENAME_STRATEGY_REPLACE
153169
}
154170

@@ -188,21 +204,21 @@ Promise.all([
188204
} else
189205
if (cmd == 'tidy') {
190206
// RUNS WITHOUT UI
191-
cmdTidy(preferences.spacing.x, preferences.spacing.y)
207+
cmdTidy(preferences.spacing.x, preferences.spacing.y, preferences.wrap_instances)
192208
figma.notify('Super Tidy: Tidy')
193209
setTimeout(() => figma.closePlugin(), 100)
194210
} else
195211
if (cmd == 'all') {
196212
// RUNS WITHOUT UI
197-
cmdTidy(preferences.spacing.x, preferences.spacing.y)
213+
cmdTidy(preferences.spacing.x, preferences.spacing.y, preferences.wrap_instances)
198214
cmdReorder()
199215
cmdRename(preferences.rename_strategy, preferences.start_name)
200216
figma.notify('Super Tidy')
201217
setTimeout(() => figma.closePlugin(), 100)
202218
} else
203219
if (cmd == 'options') {
204220
// OPEN UI
205-
figma.showUI(__html__, { width: 320, height: 460 })
221+
figma.showUI(__html__, { width: 320, height: 540 })
206222
figma.ui.postMessage({
207223
type: 'init',
208224
UUID: UUID,
@@ -215,14 +231,14 @@ Promise.all([
215231
figma.on('selectionchange', () => {
216232
figma.ui.postMessage({ type: 'selection', selection: figma.currentPage.selection })
217233
})
218-
234+
219235
figma.ui.onmessage = msg => {
220236
if (msg.type === 'tidy') {
221237
var RENAMING_ENABLED = msg.options.renaming
222238
var REORDER_ENABLED = msg.options.reorder
223239
var TIDY_ENABLED = msg.options.tidy
224240

225-
if (TIDY_ENABLED) cmdTidy(preferences.spacing.x, preferences.spacing.y)
241+
if (TIDY_ENABLED) cmdTidy(preferences.spacing.x, preferences.spacing.y, preferences.wrap_instances)
226242
if (RENAMING_ENABLED) cmdRename(preferences.rename_strategy, preferences.start_name)
227243
if (REORDER_ENABLED) cmdReorder()
228244
figma.notify('Super Tidy')
@@ -234,7 +250,7 @@ Promise.all([
234250
figma.notify('Preferences saved')
235251
} else
236252
if (msg.type === 'displayImpression') {
237-
figma.ui.resize(320, 460+124)
253+
figma.ui.resize(320, 540+124)
238254
figma.clientStorage.setAsync('AD_LAST_SHOWN_DATE', Date.now())
239255
}
240256
}

src/ui/views/preferences/PreferencesView.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ class PreferencesView extends Element {
1212
let x_spacing = this.find('#x_spacing').value
1313
let y_spacing = this.find('#y_spacing').value
1414
let starting_name = this.find('#starting_name').value
15+
let wrap_instances = this.find('#wrap_instances').checked
1516
let rename_trategy = this.find('#rename_strategy [selected]').getAttribute('data-value')
1617

1718
let preferences = {
1819
spacing: { x: parseInt(x_spacing), y: parseInt(y_spacing) },
1920
start_name: starting_name,
21+
wrap_instances: wrap_instances,
2022
rename_strategy: rename_trategy
2123
}
2224

@@ -32,7 +34,7 @@ class PreferencesView extends Element {
3234
})
3335
}
3436

35-
render() {
37+
render() {
3638
return `
3739
<form id="preferences" action="#">
3840
<fieldset>
@@ -58,6 +60,18 @@ class PreferencesView extends Element {
5860
</label>
5961
</fieldset>
6062
63+
<label>
64+
<strong>Wrap instances with frames</strong>
65+
<p>When using the Tidy action, all instances will be wrapped with a frame of the same dimensions.</p>
66+
67+
<label class="switch">
68+
<div class="switch__container">
69+
<input id="wrap_instances" type="checkbox" class="switch__checkbox" ${(this.attrs.wrapinstances == 'true') ? 'checked' : ''}>
70+
<span class="switch__slider"></span>
71+
</div>
72+
</label>
73+
</label>
74+
6175
<label>
6276
<strong>Starting frame number</strong>
6377
<p>Renames your frames starting from the given number when using the Rename action.</p>

0 commit comments

Comments
 (0)