-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtext-editor.html
51 lines (49 loc) · 1.99 KB
/
text-editor.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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Text editor</title>
</head>
<body>
<h1>Text Editor</h1>
<webrepl-connection></webrepl-connection>
<webrepl-editor code="# Write MicroPython here print('hello world!')"></webrepl-editor>
<script type="module">
// import 'https://unpkg.com/@webcomponents/custom-elements'
import '../node_modules/custom-elements/dist/CustomElements.min.js'
import './components/webrepl-connection.js'
import './components/webrepl-editor.js'
import { WebREPL } from '../webrepl.js'
let repl
window.onload = () => {
let connectionForm = document.querySelector('webrepl-connection')
let editor = document.querySelector('webrepl-editor')
connectionForm.addEventListener('connect', (e) => {
repl = new WebREPL({
ip: e.detail.ip,
password: e.detail.password,
autoConnect: true,
autoAuth: true
})
repl.on('authenticated', () => {
editor.setAttribute('connected', true)
})
repl.on('disconnected', () => {
editor.setAttribute('connected', false)
})
editor.addEventListener('run', (e) => {
console.log('Running code')
repl.execFromString(e.detail, 30)
.then(() => {
console.log('Code executed')
})
})
editor.addEventListener('stop', () => {
console.log('Sending stop')
repl.sendStop()
})
})
}
</script>
</body>
</html>