Skip to content
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

Move js code to separate JS module #50

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
650f4ea
test js library
disberd Mar 22, 2024
521aae8
index.js
disberd Mar 22, 2024
3af3121
update stuff
disberd Mar 22, 2024
ad8ca8b
tests
disberd Mar 22, 2024
c4eeba5
asd
disberd Mar 22, 2024
0586c32
lol
disberd Mar 22, 2024
ab143a2
try importmap
disberd Mar 27, 2024
4203f42
add observable-html importmap
disberd Mar 27, 2024
f1802b5
revert importmaps
disberd Mar 27, 2024
d5e0fef
try accessing window via globalThis
disberd Mar 27, 2024
a4ecd88
update some code, add some JSDoc, experimenti some Deno.
disberd Apr 3, 2024
5fa8f29
status before proable bun migration
disberd Apr 4, 2024
555a4e7
fix @emotion/css bug with import map
disberd Apr 4, 2024
4d7db9d
add metafile generation in bundle
disberd Apr 7, 2024
d89bac3
add some deps for development
disberd Apr 7, 2024
a80dc3c
some changes semiworking
disberd Apr 7, 2024
8a4f35f
Merge branch 'main' into JS-module
disberd Apr 24, 2024
487c00d
draft implementation of global JS deps
disberd Apr 24, 2024
650425c
Merge branch 'main' into JS-module
disberd Jul 20, 2024
8e1660e
add PLOT_PANE to contain the plot and clean some global deps handling
disberd Jul 20, 2024
3cb25a0
add function to update plot and draft implementation of popping out
disberd Jul 21, 2024
5531d1a
add responsive to resizing and popout
disberd Jul 21, 2024
da82d32
add basis for clipboard/save functionality
disberd Jul 21, 2024
71dcaea
avoid overflowing on the right and bottom
disberd Jul 21, 2024
c7c05d6
fix border-bottom
disberd Jul 21, 2024
5a6b290
basis for resizing via js variables
disberd Jul 21, 2024
a6e8039
setting ui values from js change plot pane
disberd Jul 21, 2024
105fd94
add container resizing when changing values from UI
disberd Jul 27, 2024
9f34a2a
fix not appearing filesave stuff
disberd Jul 27, 2024
e01f63f
fix setting the format for filesave
disberd Jul 27, 2024
1463c9d
add drag functionality
disberd Jul 29, 2024
c9b9f6f
add resize functionality
disberd Jul 29, 2024
2fe1169
add floatingui to js_deps
disberd Jul 29, 2024
9380bff
add working tooltips via floating-ui
disberd Jul 30, 2024
f1f8ce1
prettify and add some comments
disberd Jul 30, 2024
f15d5ee
improve offset and width/height computations to properly account (or …
disberd Aug 1, 2024
3295ba4
use fit-content for better resizing
disberd Aug 1, 2024
eb3041b
make size stable while dragging
disberd Aug 1, 2024
4ae5506
enforce minimum width and height of the container
disberd Aug 1, 2024
b1dcd91
add help icon and improve border when filesave is active
disberd Aug 1, 2024
8d7a777
small popup additions
disberd Aug 5, 2024
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Manifest.toml
test*.jl
.vscode/
.DS_Store
js/dist/
30 changes: 30 additions & 0 deletions js/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as esbuild from "npm:[email protected]";
// Import the WASM build on platforms where running subprocesses is not
// permitted, such as Deno Deploy, or when running without `--allow-run`.
// import * as esbuild from "https://deno.land/x/[email protected]/wasm.js";

// the plugin wants an absolute path for the deno config so we have to compute the directory of this file.
// Pointing to the correct config is needed to use the import map linking the @emotion/css url to the npm version of the package to fix a bug with the library not realizing it is inside a browser otherwise.
import * as path from "https://deno.land/[email protected]/path/mod.ts";
const __dirname = path.dirname(path.fromFileUrl(import.meta.url));
const __config = path.join(__dirname, "deno.jsonc");

import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@^0.10.3";
// import { processPlotObj } from "./src/utils.js";

const result = await esbuild.build({
plugins: [...denoPlugins({configPath: __config})],
entryPoints: ["./src/prehooks.js"],
outfile: "./dist/library.esm.min.js",
bundle: true,
format: "esm",
minify: true,
metafile: true,
treeShaking: true,
});

Deno.writeTextFile("./dist/meta.json", JSON.stringify(result.metafile))

// console.log(result.metafile);

esbuild.stop();
25 changes: 25 additions & 0 deletions js/deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"lib": [
"esnext",
"dom",
"deno.ns"
],
"checkJs": true
},
"tasks": {
"bundle": "deno run --allow-read --allow-write --allow-env --allow-net --allow-run bundle.js"
},
"imports": {
/* We create an import map for the URL as the bundling with the url directly
breaks @emotion/css as it does not recognize it inside a browser.
Strangely enough, when using the package from npm instead of esm.sh
directly it bundles fine. The direct inclusion from esm.sh from the
browser also works fine so it seems to be just a bundling problem probably
tied to how deno-esbuild-loader works? */
"https://esm.sh/@emotion/[email protected]": "npm:@emotion/[email protected]",
"https://esm.sh/[email protected]": "npm:[email protected]",
"https://esm.sh/[email protected]": "npm:[email protected]",
"https://esm.sh/@floating-ui/[email protected]": "npm:@floating-ui/[email protected]"
}
}
1,589 changes: 1,589 additions & 0 deletions js/deno.lock

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions js/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>

<head>
<script src="https://cdn.plot.ly/plotly-2.32.0.min.js" charset="utf-8"></script>
<title>My Simple HTML Document</title>
<script type="module">
const asd = await import('./src/prehooks.js');
const deps = await import('./src/url_deps.js');
const { makeContainer, setGlobalDeps, GlobalDeps, updatePlotData, computeContainerPosition } = asd
setGlobalDeps(deps)
console.log(asd)
const { emotion: { css } } = GlobalDeps
console.log(css)
const dv = document.getElementById('asd');
const container = dv.insertAdjacentElement('afterend', makeContainer());

// Do the plot
// Sample data
const trace = {
x: [1, 2, 3, 4, 5],
y: [10, 15, 13, 17, 20],
mode: 'markers',
type: 'scatter',
marker: { size: 12 }
};

const layout = {
title: 'Sample Scatter Plot',
xaxis: {
title: 'X Axis'
},
yaxis: {
title: 'Y Axis'
}
};

const data = [trace];
const plot_obj = { data, layout }

// Render the plot
updatePlotData(container, plot_obj)
window.computeContainerPosition = computeContainerPosition
window.container = container
window.option_spans = container.CLIPBOARD_HEADER.option_spans
// container.classList.toggle('popped-out', true)
container.CLIPBOARD_HEADER.classList.toggle('hidden')
window.width = option_spans['width']
// container.togglePopout()
</script>
</head>

<body>
<h1>Hello, World!</h1>
<p>This is a simple HTML document.</p>
<div id="asd" style="margin: 10px 100px;">ASD</div>
</body>

</html>
16 changes: 16 additions & 0 deletions js/index2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>My Simple HTML Document</title>
<script type="module">
const tst = await import('./src/url_deps.js')
window.tst = tst
console.log(tst)
</script>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a simple HTML document.</p>
<div id="asd" style="margin-top: 400px;">ASD</div>
</body>
</html>
Loading
Loading