Skip to content

Dash scaffolding #369

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

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const EXTRA_FILES = new Map([["node_modules/@observablehq/runtime/dist/runtime.j
const CLIENT_BUNDLES: [entry: string, name: string][] = [
["./src/client/index.js", "client.js"],
["./src/client/stdlib.js", "stdlib.js"],
["./src/client/stdlib/dash.js", "stdlib/dash.js"],
["./src/client/stdlib/dot.js", "stdlib/dot.js"],
["./src/client/stdlib/duckdb.js", "stdlib/duckdb.js"],
["./src/client/stdlib/mermaid.js", "stdlib/mermaid.js"],
Expand Down
1 change: 1 addition & 0 deletions src/client/stdlib/dash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dash/resize.js";
22 changes: 22 additions & 0 deletions src/client/stdlib/dash/resize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// TODO Automatically disconnect the observer when the returned DIV is detached.
export function resize(run: (width: number, height: number) => Node, invalidation?: Promise<void>): Node {
const div = document.createElement("div");
div.style.cssText = "position: relative; height: 100%;";
const observer = new ResizeObserver(([entry]) => {
const {width, height} = entry.contentRect;
while (div.lastChild) div.lastChild.remove();
if (width > 0) {
const child = run(width, height);
// prevent feedback loop if height is used
if (run.length !== 1 && isElement(child)) child.style.position = "absolute";
div.append(child);
}
});
observer.observe(div);
invalidation?.then(() => observer.disconnect());
return div;
}

function isElement(node: Node): node is HTMLElement {
return node.nodeType === 1;
}
1 change: 1 addition & 0 deletions src/client/stdlib/recommendedLibraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const _ = () => import("npm:lodash").then((lodash) => lodash.default);
export const aq = () => import("npm:arquero");
export const Arrow = () => import("npm:apache-arrow");
export const d3 = () => import("npm:d3");
export const Dash = () => import("observablehq:stdlib/dash");
export const dot = () => import("observablehq:stdlib/dot").then((dot) => dot.default);
export const duckdb = () => import("npm:@duckdb/duckdb-wasm");
export const DuckDBClient = () => import("observablehq:stdlib/duckdb").then((duckdb) => duckdb.DuckDBClient);
Expand Down
2 changes: 2 additions & 0 deletions src/javascript/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ export function createImportResolver(root: string, base: "." | "_import" = "."):
? resolveBuiltin(base, path, "runtime.js")
: specifier === "npm:@observablehq/stdlib"
? resolveBuiltin(base, path, "stdlib.js")
: specifier === "npm:@observablehq/dash"
? resolveBuiltin(base, path, "stdlib/dash.js") // TODO publish to npm
: specifier === "npm:@observablehq/dot"
? resolveBuiltin(base, path, "stdlib/dot.js") // TODO publish to npm
: specifier === "npm:@observablehq/duckdb"
Expand Down
8 changes: 7 additions & 1 deletion src/rollup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {existsSync} from "node:fs";
import {dirname, join, relative} from "node:path";
import {cwd} from "node:process";
import {fileURLToPath} from "node:url";
Expand Down Expand Up @@ -86,5 +87,10 @@ function importMetaResolve(): Plugin {
}

export function getClientPath(entry: string): string {
return relative(cwd(), join(dirname(fileURLToPath(import.meta.url)), "..", entry));
const path = relative(cwd(), join(dirname(fileURLToPath(import.meta.url)), "..", entry));
if (path.endsWith(".js") && !existsSync(path)) {
const tspath = path.slice(0, -".js".length) + ".ts";
if (existsSync(tspath)) return tspath;
}
return path;
}
1 change: 1 addition & 0 deletions test/deploy-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const EXTRA_FILES: string[] = [
"_observablehq/client.js",
"_observablehq/runtime.js",
"_observablehq/stdlib.js",
"_observablehq/stdlib/dash.js",
"_observablehq/stdlib/dot.js",
"_observablehq/stdlib/duckdb.js",
"_observablehq/stdlib/mermaid.js",
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this empty?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other files (such as test/output/build/simple-public/_observablehq/style.css) are also empty. I think the build-test.ts test cases assert that certain files exist as part of the build step, but do not check their contents

Empty file.