|
1 | 1 | import type {Module} from "@observablehq/runtime";
|
2 | 2 | import {Runtime} from "@observablehq/runtime";
|
| 3 | +import type {DefineState, Definition} from "./define.js"; |
| 4 | +import {define as _define} from "./define.js"; |
| 5 | +import type {observe} from "./display.js"; |
3 | 6 | import {fileAttachments} from "./stdlib/fileAttachment.js";
|
4 | 7 | import {library} from "./stdlib/index.js";
|
5 | 8 |
|
6 |
| -export * from "./define.js"; |
| 9 | +export type {DefineState, Definition} from "./define.js"; |
7 | 10 | export * from "./display.js";
|
8 | 11 | export * from "./inspect.js";
|
9 | 12 | export * from "./stdlib/index.js";
|
10 |
| - |
11 | 13 | export type * from "./stdlib/databaseClient.js";
|
12 |
| -export type * from "./stdlib/fileAttachment.js"; |
13 | 14 | export {DatabaseClient} from "./stdlib/databaseClient.js";
|
| 15 | +export type * from "./stdlib/fileAttachment.js"; |
14 | 16 | export {FileAttachment, registerFile} from "./stdlib/fileAttachment.js";
|
15 | 17 |
|
16 |
| -export const runtime = Object.assign(new Runtime({...library, __ojs_runtime: () => runtime}), {fileAttachments}); |
17 |
| -export const main = (runtime as typeof runtime & {main: Module}).main = runtime.module(); |
| 18 | +export class NotebookRuntime { |
| 19 | + readonly runtime: Runtime & {fileAttachments: typeof fileAttachments}; |
| 20 | + readonly main: Module; |
| 21 | + |
| 22 | + constructor(builtins = library) { |
| 23 | + const runtime = new Runtime({...builtins, __ojs_runtime: () => runtime}); |
| 24 | + this.runtime = Object.assign(runtime, {fileAttachments}); |
| 25 | + this.main = runtime.module(); |
| 26 | + } |
| 27 | + |
| 28 | + define(state: DefineState, definition: Definition, observer?: typeof observe): void { |
| 29 | + _define(this.main, state, definition, observer); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +const defaultNotebook = new NotebookRuntime(); |
| 34 | + |
| 35 | +export const runtime = defaultNotebook.runtime; |
| 36 | +export const main = defaultNotebook.main; |
| 37 | +export const define = defaultNotebook.define.bind(defaultNotebook); |
18 | 38 |
|
19 | 39 | main.constructor.prototype.defines = function (this: Module, name: string): boolean {
|
20 | 40 | return (
|
|
0 commit comments