-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnotebook.js
43 lines (37 loc) · 1.09 KB
/
notebook.js
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
let Runtime, Inspector;
let notebook, cells;
async function loadNotebook(url) {
({Runtime, Inspector} = await import('https://unpkg.com/@observablehq/notebook-runtime?module'));
({default: notebook} = await import(url));
cells = {}
Runtime.load(notebook, (cell) => {
if (cell.name) {
const div = document.createElement('div')
const name = document.createElement('div')
const view = document.createElement('div')
document.body.appendChild(div)
div.classList.add('cell')
div.appendChild(name)
div.appendChild(view)
name.classList.add('name')
name.innerText = cell.name;
view.classList.add('view')
const inspector = new Inspector(view)
return {
pending: () => {
inspector.pending()
},
fulfilled: (value) => {
cells[cell.name] = value;
inspector.fulfilled(value)
},
rejected: (error) => {
cells[cell.name] = error;
inspector.rejected(error)
}
}
}
})
}
let url = window.location.hash.replace(/^#/, '')
loadNotebook(url)