-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
249 lines (225 loc) · 10.3 KB
/
index.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Plug-in Preview</title>
<script src="https://www.unpkg.com/[email protected]/lib/codemirror.js"></script>
<link href="https://www.unpkg.com/[email protected]/lib/codemirror.css" rel="stylesheet">
<script src="https://unpkg.com/[email protected]/mode/javascript/javascript.js"></script>
<script src="https://unpkg.com/[email protected]/mode/xml/xml.js"></script>
<link href="https://unpkg.com/[email protected]/theme/colorforth.css" rel="stylesheet">
<script src="https://unpkg.com/[email protected]/jquery.js"></script>
<link href="https://unpkg.com/[email protected]/dist/css/bootstrap.css" rel="stylesheet">
<script src="https://unpkg.com/[email protected]/dist/js/bootstrap.js"></script>
<script src="https://unpkg.com/isomorphic-git"></script>
<script src="https://unpkg.com/[email protected]/dist/browserfs.min.js"></script>
<style>
html, body {
height: 100%;
}
.input-block {
height: 480px;
width: 100%;
}
.file-list {
width: 100%;
height: 180px;
writing-mode: vertical-lr;
overflow: auto;
}
.file-list > .file-item {
display: inline-block;
width: 180px;
height: 24px;
writing-mode: horizontal-tb;
padding: 2px 6px;
text-overflow: ellipsis;
cursor: pointer;
}
.file-list > .file-item:hover {
background-color: aqua;
}
.iframe-box {
width: 360px;
height: 640px;
position: absolute;
left: 50%;
margin-left: -180px;
margin-top: 12px;
box-shadow: 1px 1px 8px gray;
}
svg {
fill: white;
width: 16px;
height: 16px;
}
.popover-menu {
right: 4px;
top: -4px;
position: absolute;
width: 280px;
height: 460px;
z-index: 999;
display: none;
}
.popover-menu > button {
position: absolute;
right: 4px;
top: 4px;
}
</style>
</head>
<body>
<div class="navbar navbar-light bg-light">
<div class="container position-relative">
<a class="navbar-brand" href="#">Plug-in Preview</a>
<div class="float-end">
<a class="btn btn-dark me-2" href="https://github.com/gsioteam/plugin_online">
<img src="./res/github.png" width="16px" height="16px">
</a>
<button class="btn btn-primary" id="menu-button">
<svg id="i-menu" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32" height="32" fill="none" stroke="currentcolor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
<path d="M4 8 L28 8 M4 16 L28 16 M4 24 L28 24" />
</svg>
</button>
</div>
<div class="card mw-100 overflow-auto popover-menu">
<ul class="list-group list-group-flush">
<li class="list-group-item head bg-light"><h5>Support Types</h5></li>
</ul>
<button class="btn btn-outline-secondary btn-sm">
<svg id="i-close" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32" height="32" fill="none" stroke="currentcolor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
<path d="M2 30 L30 2 M30 30 L2 2" />
</svg>
</button>
</div>
</div>
</div>
<div class="container mt-2">
<div class="row">
<div class="col-6">
<div>
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#git-panel" type="button" role="tab" aria-controls="git-panel" aria-selected="true">Git</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#file-panel" type="button" role="tab" aria-controls="file-panel" aria-selected="false">File</button>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active mt-2" id="git-panel" role="tabpanel" aria-labelledby="git-panel-tab">
<label for="file-input" class="form-label">Input your plug-in git address</label>
<div class="input-group">
<input type="url" class="form-control" id="git-input" placeholder="https://...">
<button class="btn btn-outline-secondary" type="button" id="git-button">Submit</button>
</div>
</div>
<div class="tab-pane fade mt-2" id="file-panel" role="tabpanel" aria-labelledby="file-panel-tab">
<label for="file-input" class="form-label">Select a Zip file.</label>
<div class="input-group">
<input type="file" class="form-control" id="file-input" >
<button class="btn btn-outline-secondary" type="button" id="file-button">Submit</button>
</div>
</div>
</div>
</div>
<div class="border border-2 border-primary mt-2">
<div id="file-list" class="file-list">
</div>
</div>
<div class="border border-2 border-primary mt-2">
<textarea id="code-text" class="input-block"></textarea>
</div>
</div>
<div class="col-6 h-100 position-relative">
<iframe class="iframe-box" src="build/web"></iframe>
</div>
</div>
</div>
<script src="./browser_src/bundle.js"></script>
<script>
var ready = false;
var textarea = document.getElementById("code-text");
var templateEditor = CodeMirror.fromTextArea(textarea, {
mode: "xml",
lineNumbers: true,
readOnly: true,
lineWrapping: true
});
templateEditor.setSize('100%', 480);
const fileList = document.getElementById('file-list');
let fileItems;
document.getElementById('git-button').onclick = async function() {
let input = document.getElementById('git-input');
let url = input.value;
if (url.length > 0) {
manager.clone(url).then(function(items) {
fileItems = items;
setupFileItems();
if (ready) {
sendFiles();
}
});
} else {
input.focus();
}
};
document.getElementById('file-button').onclick = function() {
let input = document.getElementById('file-input');
if (input.files.length > 0) {
let file = input.files[0];
manager.readFile(file).then(function(items) {
fileItems = items;
setupFileItems();
if (ready) {
sendFiles();
}
});
}
console.log(input.files);
};
var iframe = document.getElementsByClassName('iframe-box')[0];
iframe.contentWindow.onmessage = function(e) {
if (e.data.type === 'ready') {
ready = true;
if (fileItems) {
sendFiles();
}
}
};
function setupFileItems() {
fileList.innerHTML = '';
for (let item of fileItems) {
fileList.appendChild(item.element);
item.onclick = function() {
if (this.ext === '.js' || this.ext === '.json') {
templateEditor.setOption('mode', 'javascript');
templateEditor.setValue(this.text);
} else if (this.ext === '.xml') {
templateEditor.setOption('mode', 'xml');
templateEditor.setValue(this.text);
} else {
}
}
}
}
function sendFiles() {
var arr = [];
for (var i = 0, t = fileItems.length; i < t; ++i) {
arr.push(fileItems[i].toJSON());
}
iframe.contentWindow.postMessage({
type: 'files',
data: arr
}, "*");
}
document.querySelector('.popover-menu > button').onclick = function() {
document.querySelector('.popover-menu').style.display = 'none';
};
document.getElementById('menu-button').onclick = function() {
document.querySelector('.popover-menu').style.display = 'block';
}
</script>
</body>
</html>