-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.html
112 lines (82 loc) · 3.17 KB
/
page.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./dist/styles.css">
<style>
.fullscreen {
position: fixed;
width: 100vh;
height: 100vh;
}
.fullscreen iframe {
width: 100%;
height: 100%;
}
</style>
<title>Document</title>
</head>
<body>
<form u-form u-on:submit="save(js)"
u-on:keydown="($event) => fullscreen = $event.key === 'Escape' ? false : fullscreen">
<div u-container u-view-my="md" u-data="{fullscreen: false}" u-view-h="100">
<div u-row u-view-h="100">
<div u-col u-col-col="6">
<div u-row u-view-mt="xxl">
<div u-col u-col-col="12">
<div u-form-field>
<div u-form-field-label>
Label
</div>
<div u-code-editor u-view-w="100" u-view-h="100" lang="js" name="js" value="Initial"></div>
</div>
</div>
<div u-col>
<button u-on:click="save(js)" u-button u-button-color="primary">Run</button>
<button type="button" u-on:click="fullscreen = !fullscreen" u-button
u-button-color="primary">Run</button>
</div>
</div>
</div>
<div u-col u-col-col="6" u-bind:class="fullscreen ? 'fullscreen' : ''">
<iframe u-view-w="100" u-view-h="100" src='javascript:void(0)' id="iframe"></iframe>
</div>
</div>
</form>
</div>
<script src="./dist/ulibs.js"></script>
<script>
function runCode(js) {
const code = `
import {Button, Container, View} from 'https://unpkg.com/@ulibs/ui@next/src/components/index.js'
const data = {name: 'My Name', username: 'My Username', id: 'My ID'}
const page = ${js}
document.getElementById("app").innerHTML = page.toString().replace(/\\{\\{(\\w+)\\}\\}/g, (a, b) => data[b]);
`
const iframe = document.querySelector(`[id="iframe"]`)
var html_string = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/@ulibs/ui@next/dist/styles.css">
<title>Document</title>
</head>
<bo`+ `dy class="${document.body.classList.toString()}">
<div id="app"></div>
<scr`+ `ipt type="module">${code}<\/sc` + `ript></bo` + `dy>
</ht`+ `ml>
`;
iframe.src = "data:text/html;charset=utf-8," + escape(html_string);
console.log(iframe.src)
}
function save(js) {
runCode(js)
}
function fullscreen() {
}
</script>
</body>
</html>