observablehq / stdlib

The Observable standard library.
https://observablehq.com/@observablehq/standard-library
ISC License
961 stars 83 forks source link

Add recommended libraries #207

Closed mbostock closed 3 years ago

mbostock commented 3 years ago

This adds a handful of first-party and sanctioned third-party libraries to the Observable standard library for convenient access from notebooks. This set of libraries may grow over time based on demand. The current set is:

In the last case, some additional code is required based on this notebook.

The trickiest part here is version pinning. I chose to hard-code the versions and paths in the standard library for stability and performance, and in particular to guarantee that duplicate versions of D3 and Hypertext Literal are not loaded: Observable Plot depends on D3, and Observable Inputs depends on Hypertext Literal. A consequence of this choice is that we’ll need to upgrade the Observable standard library explicitly, for everyone, when new versions of these libraries are released. However, when Observable supports version pinning natively in the future, we should be able to relax these requirements and give authors control over which version to use. In the meantime, notebook authors can require the libraries explicitly rather than depending on the standard library if they want to specify the version.

shancarter commented 3 years ago

I don't have an solutions to offer, but having both htl and html feels like a bummer. Or does one replace the other?

mbostock commented 3 years ago

We can’t change the behavior of html without breaking lots of notebooks. When we support standard library versioning, we can replace the existing html and svg directly instead of introducing htl.

tophtucker commented 3 years ago

how much does this increase the size of the bundle? we could add an example to the examples repo showing how to roll your own version-pinning for downloaded notebooks (i.e. the example would just sub in an older or pruned version of stdlib)

mbostock commented 3 years ago

It has a negligible increase in the bundle size because everything is loaded lazily. You only load d3 if you reference it.

tophtucker commented 3 years ago

oh wow that's sweet

Fil commented 3 years ago

To help the user could you add .version systematically? Currently each library has a different method (if at all): https://observablehq.com/@fil/stdlib-recommended-libraries

mootari commented 3 years ago

A consequence of this choice is that we’ll need to upgrade the Observable standard library explicitly, for everyone, when new versions of these libraries are released.

Is the current plan to hold out on BC breaking updates for these libraries until Observable supports version pinning out of the box?

mbostock commented 3 years ago

@mootari Yes, we’re only going to accept patch and minor upgrades until Observable supports version pinning.