-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
Library
object only intended for use with the Observable Runtime; it’s now just a library with normal exports.now
import {now} from "npm:@observablehq/stdlib"
width
import {width} from "npm:@observablehq/stdlib"
DatabaseClient
import {DatabaseClient} from "npm:@observablehq/stdlib"
FileAttachment
import {FileAttachment} from "npm:@observablehq/stdlib"
Generators
import {Generators} from "npm:@observablehq/stdlib"
Mutable
import {Mutable} from "npm:@observablehq/stdlib"
_
import _ from "npm:lodash"
aq
import * as aq from "npm:arquero"
Arrow
import * as Arrow from "npm:apache-arrow"
d3
import * as d3 from "npm:d3"
dot
import dot from "npm:@observablehq/dot"
duckdb
import * as duckdb from "npm:@duckdb/duckdb-wasm"
DuckDBClient
import {DuckDBClient} from "npm:@observablehq/duckdb"
htl
import * as htl from "npm:htl"
html
import {html} from "npm:htl"
svg
import {svg} from "npm:htl"
Inputs
import * as Inputs from "npm:@observablehq/inputs"
L
import * as L from "npm:leaflet"
mermaid
import mermaid from "npm:@observablehq/mermaid"
Plot
import * as Plot from "npm:@observablehq/plot"
SQLite
import SQLite from "npm:@observablehq/sqlite"
SQLiteDatabaseClient
import {SQLiteDatabaseClient} from "npm:@observablehq/sqlite"
tex
import tex from "npm:@observablehq/tex"
topojson
import * as topojson from "npm:topojson-client"
For example, if you
import * as L from "npm:leaflet"
, it is now exactly the same asL
from 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
now
andwidth
: 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
width
function now also accepts an optionaltarget: Element
if you want to observe something other than the first main element.This also kills the following features from the standard library:
require
resolve
md
__query
DOM.canvas
DOM.context2d
DOM.download
DOM.element
DOM.input
DOM.range
DOM.select
DOM.svg
DOM.text
DOM.uid
Files.buffer
Files.text
Files.url
Generators.disposable
Generators.filter
Generators.map
Generators.range
Generators.valueAt
Generators.worker
Promises.delay
Promises.tick
Promises.when
In addition to the above changes, this also implements server-side rendering of stylesheets that are implicitly needed by recommended libraries. 🚀 Specifically:
npm:@observablehq/inputs
https://cdn.jsdelivr.net/gh/observablehq/inputs/src/style.css
npm:katex
https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css
npm:leaflet
https://cdn.jsdelivr.net/npm/leaflet/dist/leaflet.css
This 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
resolveDatabase
function.This PR also re-implements Generators.observe, Generators.input, and Generators.queue as async generators.
Future work:
typed: "auto"
forFileAttachment.csv
andFileAttachment.tsv
FileAttachment
calls in imported modules; depends on find fetches in locally imported files #286@observablehq/dot
to npm; archive@observablehq/graphviz
@observablehq/duckdb
to npm@observablehq/mermaid
to npm@observablehq/sqlite
to npm@observablehq/stdlib
v6 with most functionality removed? or branch?@observablehq/tex
to npm; archive@observablehq/katex
@observablehq/xlsx
to npmFixes #24. Fixes #19.