dataflow icon indicating copy to clipboard operation
dataflow copied to clipboard

More import options

Open asg017 opened this issue 3 years ago • 4 comments

Only observablehq and local imports are supported now. Here are other places we should support importing from:

  • [ ] Any .js file on the internet that has a export default function define() definition
  • [ ] Any local .js file that has a export default function define() definition
  • [ ] Github (proxy to raw.githubusercontent.com)
  • [ ] gists
  • [ ] NPM (maybe should just document how to use https://www.jsdelivr.com instead of doing npm resolution ourselves

asg017 avatar May 02 '21 01:05 asg017

+1 on the npm import. Is there a way to use jsdelivr now?

Jiahao01121 avatar May 18 '21 20:05 Jiahao01121

@Jiahao01121 yup, Dataflow uses the same require functions as the notebooks on Observable, which uses d3-require under the hood. So

// notebook.ojs
moment = require("moment")

moment(new Date)

imports moment from jsdelivr.

asg017 avatar May 18 '21 21:05 asg017

+1 for local imports, this can be a big + vs observablehq for local js dev

I use a workaround to bring local js into observablehq, which also works for dataflow, but dataflow workflow has much nicer potential with local imports

(workaround = https://observablehq.com/@observablehq/require section URL)

declann avatar May 30 '21 20:05 declann

For gists, etc., this works for me in the import resolver:

fetch(path)
      .then((res) => res.text())
      .then((js) => {
        const blob = new Blob([js], {
          type: 'text/javascript',
        });
        const objectURL = URL.createObjectURL(blob);
        return objectURL;
      })

a10k avatar Jun 04 '21 19:06 a10k