Skip to content

Commit 4a7dd52

Browse files
committed
fix width
1 parent dc2fa7f commit 4a7dd52

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ TODO
3030
- ✅ file attachments
3131
- ✅ check that files exist before registering file attachments
3232
- ✅ prevent parsing embedded expressions within script tags
33-
- fix width definition when sidebar is open
33+
- fix width definition when sidebar is open
3434
- generate bootstrapped docs for the cli repo
3535
- database clients (databases registered in YAML or observablehq.json)
3636
- secrets (defined via environment variable?)

public/client.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
import {Runtime, Inspector} from "/_observablehq/runtime.js";
1+
import {Runtime, Library, Inspector} from "/_observablehq/runtime.js";
22

3-
const runtime = new Runtime();
3+
const library = Object.assign(new Library(), {width});
4+
const runtime = new Runtime(library);
45
const main = runtime.module();
56

67
const attachedFiles = new Map();
78
const resolveFile = (name) => attachedFiles.get(name);
89
main.builtin("FileAttachment", runtime.fileAttachments(resolveFile));
910

11+
function width() {
12+
return library.Generators.observe((notify) => {
13+
let width;
14+
const observer = new ResizeObserver(([entry]) => {
15+
const w = entry.contentRect.width;
16+
if (w !== width) notify((width = w));
17+
});
18+
observer.observe(document.querySelector("main"));
19+
return () => observer.disconnect();
20+
});
21+
}
22+
1023
export function define({id, inline, inputs = [], outputs = [], files = [], body}) {
1124
const root = document.querySelector(`#cell-${id}`);
1225
const observer = {pending: () => (root.innerHTML = ""), rejected: (error) => new Inspector(root).rejected(error)};

0 commit comments

Comments
 (0)