-
Notifications
You must be signed in to change notification settings - Fork 6
/
livepreview.html
160 lines (132 loc) · 4.2 KB
/
livepreview.html
1
2
3
4
5
6
7
8
9
10
11
12
13
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<head>
<link rel="stylesheet" href="node_modules/figma-plugin-ds/dist/figma-plugin-ds.css" />
</head>
<body>
<div class="flex column justify-content-center align-items-center">
<div id="controls" class="justify-content-center align-items-center">
<h1 class="type type--xlarge type--bold">
Plugin Preview
</h1>
<p class="type type--pos type--small type--normal">
Set the size for your plugin live preview
</p>
<div class="flex row gap" id="inputs">
<div class="flex-columm">
<label class="label" for="hori">Width</label>
<div class="input input--with-icon">
<div class="icon icon--arrow-left-right"></div>
<input id="width" type="number" class="input__field" oninput="resize()" autocomplete="off">
</div>
</div>
<div class="flex-column">
<label class="label" for="vert">Height</label>
<div class="input input--with-icon">
<div class="icon icon--up-down"></div>
<input id="height" type="number" class="input__field" oninput="resize()" autocomplete="off">
</div>
</div>
<!-- <button class="button button--primary" click='set' :disabled="selectionCount < 2 || tooManyParents"> Organise Frames </button> -->
</div>
</div>
<div class="modal">
<div class="modal--header">
<div class="modal--title type type--large type--bold">
Plugin</div>
<div class="icon-button">
<div class="icon icon--close"></div>
</div>
</div>
<iframe id="iframe" src="./dist/ui.html" style="width:100%;height:100%" frameBorder=0>
</div>
</div>
</iframe>
</body>
<script>
const eventListeners = [];
const dispatch = (action, data) => {
parent.postMessage({ pluginMessage: { action, data } }, '*');
};
const handleEvent = (type, callback) => {
eventListeners.push({ type, callback });
};
window.onmessage = event => {
const message = event.data.pluginMessage;
if (message) {
for (let eventListener of eventListeners) {
if (message.action === eventListener.type) eventListener.callback(message.data);
}
}
};
const w = document.getElementById('width')
const h = document.getElementById('height')
const iframe = document.getElementById('iframe')
function docReady(fn) {
// see if DOM is already available
if (document.readyState === "complete" || document.readyState === "interactive") {
// call on next available tick
setTimeout(fn, 1);
} else {
document.addEventListener("DOMContentLoaded", fn);
}
}
function initalise(){
w.value = localStorage.getItem('w') ? localStorage.getItem('w') : 300
h.value = localStorage.getItem('h') ? localStorage.getItem('h') : 300
resize()
}
docReady(initalise)
function resize(){
localStorage.setItem('w', w.value)
localStorage.setItem('h', h.value)
iframe.style.width = w.value
iframe.style.height = h.value
}
// handleEvent('updateInstances',() => {
// console.log('event happened')
// })
handleEvent("resizeUI", (size) => {
//figma.ui.resize(size[0],size[1])
iframe.style.width = size[0]
iframe.style.height = size[1]
})
</script>
<style>
body{
margin: 120px;
}
#controls{
max-width: 400px;
margin-bottom: var(--size-xlarge)
}
.input__field{
border: 1px solid var(--black1);
}
.modal{
box-shadow: 0 2px 14px rgba(0,0,0,.15), 0 0 0 0.5px rgba(0,0,0,.2);
}
.modal--header{
font-weight: 600;
box-sizing: border-box;
height: 41px;
display: flex;
justify-content: space-between;
align-items: center;
padding-left: 8px;
padding-right: 4px;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
border-bottom: 1px solid rgba(0,0,0,.1);
cursor: default;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.modal--title{
padding-left: 8px;
width: calc(100% - 40px);
}
.gap > *:not(:last-child){
margin-right: 8px;
}
</style>