Skip to content

Commit 920ed30

Browse files
committed
Update js framework
1 parent 6f53249 commit 920ed30

15 files changed

+3734
-22
lines changed

config/esbuild.geojson.mjs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import esbuild from 'esbuild';
2+
3+
const commonOptions = {
4+
outdir: 'dist',
5+
format: 'esm',
6+
bundle: true,
7+
loader: {
8+
'.svg': 'file',
9+
'.woff': 'file',
10+
'.woff2': 'file',
11+
'.ttf': 'file',
12+
'.otf': 'file',
13+
'.html': 'copy',
14+
'.json': 'copy',
15+
},
16+
logLevel: 'info',
17+
entryPoints: [],
18+
};
19+
20+
if (process.env.NODE_ENV === 'production') {
21+
commonOptions.entryPoints.push('src/index.js');
22+
await esbuild.build({
23+
...commonOptions,
24+
entryPoints: ['src/index.js'],
25+
minify: true,
26+
sourcemap: false,
27+
}).catch(() => process.exit(1));
28+
} else {
29+
commonOptions.entryPoints.push('example/geojson/index.html', 'example/geojson/index.js', 'example/geojson/data.json');
30+
let ctx = await esbuild.context({
31+
...commonOptions,
32+
minify: false,
33+
sourcemap: true,
34+
})
35+
36+
let { host, port } = await ctx.serve({
37+
servedir: commonOptions.outdir,
38+
});
39+
await ctx.watch();
40+
}

example/esbuild.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Code to reload in the esbuild serve development environment */
22
window.addEventListener('load', () => {
33
// eslint-disable-next-line no-restricted-globals
4-
new EventSource('/esbuild').addEventListener('change', () => location.reload());
4+
//new EventSource('/esbuild').addEventListener('change', () => location.reload());
55
});
File renamed without changes.
File renamed without changes.

example/geojson/index.html

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>GeoJSON viewer</title>
8+
<script type="module" src="index.js" defer></script>
9+
<link href="index.css" rel="stylesheet">
10+
</head>
11+
12+
<body>
13+
<js-canvas>
14+
<js-nav vertical>
15+
<js-navitem disabled><js-image id="icon"></js-image></js-navitem>
16+
<js-navitem>Home</js-navitem>
17+
</js-nav>
18+
19+
<js-content>
20+
<!-- the map -->
21+
<js-map id="map"
22+
accessToken="pk.eyJ1IjoiZGp0aG9ycGUiLCJhIjoiY2x5ZnJhZjAzMDJsYTJqcjd6eWQ3cjRvcSJ9.LvoT_wihG5VQtv008P-MPw">
23+
<!-- add a source from the array (must currently be an array of GeoJSON features) -->
24+
<js-mapsource id="area" type="geojson" data="#array"></js-mapsource>
25+
26+
<!-- display the source on the map -->
27+
<js-maplayer id="points" source="#area" type="fill" paint='{ "fill-opacity": 0.2, "fill-color": "#aa0000" }'></js-maplayer>
28+
</js-map>
29+
</js-content>
30+
31+
</js-canvas>
32+
33+
<!-- contains the GeoJSON data -->
34+
<js-array id="array" provider="#provider"></js-array>
35+
36+
<!-- data source which updates when the event source /esbuild changes -->
37+
<js-provider id="provider" path="data.json" eventsource="/esbuild"></js-provider>
38+
39+
<!-- toast which persists on the screen for 1 second -->
40+
<js-toast id="toast" duration="1"></js-toast>
41+
</body>
42+
43+
</html>

example/geojson/index.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// This file defines all the styles and elements used for the web components
2+
import '../../src/index';
3+
import '../esbuild';
4+
import hala from './hala-white-132x132.svg';
5+
import { EventType } from '../../src/core/EventType';
6+
7+
window.addEventListener('load', () => {
8+
// Brand
9+
const icon = document.querySelector('#icon');
10+
if (icon) {
11+
icon.src = hala;
12+
}
13+
14+
// Set toast when error or done
15+
const provider = document.querySelector('#provider');
16+
const toast = document.querySelector('#toast');
17+
18+
provider.addEventListener(EventType.ERROR, (e) => {
19+
toast.visible = true;
20+
toast.duration = 10;
21+
toast.color = 'error';
22+
toast.innerHTML = `${e.detail}<js-close></js-close>`;
23+
});
24+
25+
provider.addEventListener(EventType.DONE, (e) => {
26+
toast.visible = true;
27+
toast.duration = 10;
28+
toast.color = 'info';
29+
toast.innerHTML = 'Data Reloaded&nbsp;&nbsp;<js-close></js-close>';
30+
});
31+
});

0 commit comments

Comments
 (0)