async function importCell(
cell,
notebook,
injections = {},
target
) {
const runtime = new Runtime();
const main = runtime.module();
for (const name in injections) {
main.define(name, [], () => injections[name]);
}
const origin = `https://api.observablehq.com`;
const {
default: define
} = await import(/^@[0-9a-z_-]+\/[0-9a-z_-]+(\/\d+)?([@~]|$)/.test(
(notebook += "")
)
? `${origin}/${notebook}.js?v=3`
: /^[0-9a-f]{16}([@~]|$)/.test(notebook)
? `${origin}/d/${notebook}.js?v=3`
: notebook);
const imported = runtime.module(define);
const derived = imported.derive([...Object.keys(injections)], main);
return Generators.observe(notify => {
var inspector = target && new Inspector(target);
main
.variable({
fulfilled(value) {
target && inspector.fulfilled(value);
notify(value);
},
rejected(value) {
notify(Promise.reject(value));
}
})
.import(cell, derived);
return () => runtime.dispose();
});
}