vanilla stdlib; server-side render implicit stylesheets; async Generators; width(target)#294
vanilla stdlib; server-side render implicit stylesheets; async Generators; width(target)#294
Conversation
510abc5 to
4f18eca
Compare
3381e64 to
cc1fafe
Compare
|
Open questions: 1. Implement
|
|
In a follow-up PR we'll need to document each of the modules in the placeholders (docs/libs/) #307 |
We don’t control how third-party libraries and bundled, and we’re already doing The Right Thing(tm) here in my opinion for our own libraries. I can’t really articulate when it’s appropriate to use default exports, but it feels right when the name of the library matches the single thing that it exports (as with On the libraries themselves, we’re using the names they’re published as to npm. The only thing I think we should fix there is maybe republishing |
Co-authored-by: Philippe Rivière <fil@rezo.net>
|
Thank for you the feedback. This is ready for another look. 🙏 |
|
Re: 2.5. Remove rewriting of fetch? |
|
Good catch @cinxmo. There’s some additional copying over of files in |
We require that for |
ed091b1 to
e858436
Compare

This makes the Observable standard library naturally consumable from vanilla JavaScript: it’s no longer a
Libraryobject only intended for use with the Observable Runtime; it’s now just a library with normal exports.nowimport {now} from "npm:@observablehq/stdlib"widthimport {width} from "npm:@observablehq/stdlib"DatabaseClientimport {DatabaseClient} from "npm:@observablehq/stdlib"FileAttachmentimport {FileAttachment} from "npm:@observablehq/stdlib"Generatorsimport {Generators} from "npm:@observablehq/stdlib"Mutableimport {Mutable} from "npm:@observablehq/stdlib"_import _ from "npm:lodash"aqimport * as aq from "npm:arquero"Arrowimport * as Arrow from "npm:apache-arrow"d3import * as d3 from "npm:d3"dotimport dot from "npm:@observablehq/dot"duckdbimport * as duckdb from "npm:@duckdb/duckdb-wasm"DuckDBClientimport {DuckDBClient} from "npm:@observablehq/duckdb"htlimport * as htl from "npm:htl"htmlimport {html} from "npm:htl"svgimport {svg} from "npm:htl"Inputsimport * as Inputs from "npm:@observablehq/inputs"Limport * as L from "npm:leaflet"mermaidimport mermaid from "npm:@observablehq/mermaid"Plotimport * as Plot from "npm:@observablehq/plot"SQLiteimport SQLite from "npm:@observablehq/sqlite"SQLiteDatabaseClientimport {SQLiteDatabaseClient} from "npm:@observablehq/sqlite"teximport tex from "npm:@observablehq/tex"topojsonimport * as topojson from "npm:topojson-client"For example, if you
import * as L from "npm:leaflet", it is now exactly the same asLfrom the standard library. And rather than wrapping Leaflet to inject the stylesheet, we server-side render the stylesheet link so that it loads faster! (We do the same now for KaTeX and Observable Inputs.)Two exceptions are
nowandwidth: since these are reactive variables implemented by generators, in vanilla JavaScript they are generator functions and hence you must callnow()orwidth()to get the generator. I’m not entirely sure what to do with these 🤷 but that was the easiest thing to do. Additional exceptions are “special” variables that only make sense in reactive JavaScript:display,invalidation,visibility, andview. The sample datasets also are available in Markdown but aren’t importable; I think that’s fine.The
widthfunction now also accepts an optionaltarget: Elementif you want to observe something other than the first main element.This also kills the following features from the standard library:
requireresolvemd__queryDOM.canvasDOM.context2dDOM.downloadDOM.elementDOM.inputDOM.rangeDOM.selectDOM.svgDOM.textDOM.uidFiles.bufferFiles.textFiles.urlGenerators.disposableGenerators.filterGenerators.mapGenerators.rangeGenerators.valueAtGenerators.workerPromises.delayPromises.tickPromises.whenIn addition to the above changes, this also implements server-side rendering of stylesheets that are implicitly needed by recommended libraries. 🚀 Specifically:
npm:@observablehq/inputshttps://cdn.jsdelivr.net/gh/observablehq/inputs/src/style.cssnpm:katexhttps://cdn.jsdelivr.net/npm/katex/dist/katex.min.cssnpm:leaflethttps://cdn.jsdelivr.net/npm/leaflet/dist/leaflet.cssThis approach improves performance over wrapping the library to insert the stylesheet after the library loads.
This PR also simplifies the “CLI resolver” abstraction to a
resolveDatabasefunction.This PR also re-implements Generators.observe, Generators.input, and Generators.queue as async generators.
Future work:
typed: "auto"forFileAttachment.csvandFileAttachment.tsvFileAttachmentcalls in imported modules; depends on find fetches in locally imported files #286@observablehq/dotto npm; archive@observablehq/graphviz@observablehq/duckdbto npm@observablehq/mermaidto npm@observablehq/sqliteto npm@observablehq/stdlibv6 with most functionality removed? or branch?@observablehq/texto npm; archive@observablehq/katex@observablehq/xlsxto npmFixes #24. Fixes #19.