-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
68 lines (59 loc) · 2.12 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
<html>
<head>
<style>
body { margin: 0; }
.container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-areas:
"edit-area canvas";
}
#edit-area { grid-area: edit-area; height: 100vh; outline: 1px solid gray; }
#editor { position: relative; width: 100%; height: 100%; }
#canvas { grid-area: canvas; outline: 1px solid gray; }
</style>
</head>
<body>
<div class="container">
<div id="edit-area"><div id="editor"></div></div>
<div id="canvas"></div>
</div>
<!-- load the lively stuff, this includes lively.modules, SystemJS, babel -->
<script src="livelify-web.js" type="text/javascript" charset="utf-8"></script>
<!-- load a text editor -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.9/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var editor, baseDir = lively.resources.resource(document.location.href).parent(),
reactModule = lively.modules.module(baseDir.join("some-react.js").url);
initAce();
loadEditorContent().catch(err => console.log(err));
function initAce() {
editor = ace.edit("editor");
editor.setOption("showGutter", false)
editor.getSession().setUseWorker(false);
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/javascript");
editor.getKeyboardHandler().addCommand({
name: "[react-dev-page] save and refresh",
bindKey: {mac: "Command-S", win: "Ctrl-S"},
exec: function (e){
reactModule.changeSource(editor.getValue(), {doEval: true, doSave: false/*no write*/})
.catch(err => alert("Error updating code: " + err));
}
})
}
function loadEditorContent() {
return Promise.resolve()
.then(() => lively.modules.registerPackage(baseDir.url))
.then(() => reactModule.load())
.then(() => reactModule.source())
.then(source => {
if (editor.getKeyboardHandler().platform !== "mac")
source.replace(/cmd\+|command\+/, "Ctrl+");
editor.setValue(source);
editor.clearSelection();
});
}
</script>
</body>
</html>