Skip to content

Commit 574d197

Browse files
committed
caniuse database wip
1 parent 9ce4d36 commit 574d197

36 files changed

+763
-47
lines changed

package-lock.json

Lines changed: 102 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@
1818
"gsap": "^3.12.5",
1919
"htm": "^3.1.1",
2020
"marquee-content": "^4.2.0",
21-
"preact": "^10.24.3"
21+
"preact": "^10.24.3",
22+
"preact-fetching": "^1.0.0"
2223
},
2324
"devDependencies": {
2425
"@babel/core": "^7.26.0",
2526
"@babel/preset-env": "^7.26.0",
2627
"@types/lodash-es": "^4.17.12",
28+
"@types/semver": "^7.5.8",
2729
"@webosbrew/caniroot": "^1.2.5",
2830
"autoprefixer": "^10.4.20",
2931
"babel-loader": "^9.2.1",
3032
"babel-plugin-htm": "^3.0.0",
3133
"copy-webpack-plugin": "^12.0.2",
3234
"css-loader": "^7.1.2",
3335
"css-minimizer-webpack-plugin": "^7.0.0",
36+
"escape-string-regexp": "^5.0.0",
3437
"favicons": "^7.2.0",
3538
"handlebars": "^4.7.8",
3639
"hast-util-to-html": "^9.0.1",
@@ -59,6 +62,7 @@
5962
"responsive-loader": "^3.1.2",
6063
"sass": "^1.80.5",
6164
"sass-loader": "^16.0.3",
65+
"semver": "^7.6.3",
6266
"sharp": "^0.33.4",
6367
"style-loader": "^4.0.0",
6468
"ts-loader": "^9.5.1",
@@ -68,7 +72,8 @@
6872
"vfile": "^6.0.1",
6973
"webpack": "^5.96.0",
7074
"webpack-cli": "^5.1.4",
71-
"webpack-dev-server": "^5.1.0"
75+
"webpack-dev-server": "^5.1.0",
76+
"yaml": "^2.6.0"
7277
},
7378
"engines": {
7479
"node": ">=20"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** @type {Record<string, string[]>} */
2+
export default {/*DATA_INDEX*/};

src/views/develop/caniuse/caniuse.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import {Component, html, render} from "htm/preact";
2+
import {DataEntry} from "./types";
3+
import {useQuery} from "preact-fetching";
4+
import {CanIUseCard} from "./card";
5+
import {uniq} from "lodash-es";
6+
7+
interface AppState {
8+
index: Record<string, string[]>;
9+
}
10+
11+
class App extends Component<unknown, AppState> {
12+
constructor() {
13+
super();
14+
fetch('caniuse/data/index.json').then(resp => resp.json()).then(data => this.setState({
15+
index: data
16+
}));
17+
}
18+
19+
render(props: unknown, state: AppState) {
20+
const query = new URLSearchParams(location.search);
21+
const name = query.get('q')
22+
return html`
23+
<h1>Can I use <input type="search" class=""/>?</h1>
24+
<hr/>
25+
${state.index && html`
26+
<${CanIUseSearch} index=${state.index} name=${name}/>`}`;
27+
}
28+
29+
}
30+
31+
function CanIUseSearch(props: { index: Record<string, string[]>, name: string }) {
32+
const {name, index} = props;
33+
34+
async function fetchData(q: string): Promise<DataEntry[]> {
35+
return Promise.all(uniq(Object.entries(index).flatMap(([k, names]) => k.includes(q) ? names : []))
36+
.map(name => fetch(`caniuse/data/${name}.json`).then(resp => {
37+
if (!resp.ok) {
38+
throw new Error(`Failed to fetch data for ${name}`);
39+
}
40+
return resp.json();
41+
})));
42+
}
43+
44+
const {isLoading, isError, error, data} = useQuery(`caniuse/data/${name}`, async () => fetchData(name));
45+
if (isError) {
46+
return html`
47+
<div>Error: ${error.message}</div>`;
48+
}
49+
if (isLoading) {
50+
return html`
51+
<div>Loading...</div>`;
52+
}
53+
return html`
54+
<div class="row g-3">${data?.map(entry => html`
55+
<${CanIUseCard} data=${entry}/>`)}
56+
</div>`;
57+
}
58+
59+
render(html`
60+
<${App}/>`,
61+
document.getElementById('app-container')!);

0 commit comments

Comments
 (0)