Skip to content

Commit 1108c24

Browse files
committed
improved data generation
fixed data loading
1 parent c8f7fe0 commit 1108c24

File tree

7 files changed

+98
-10
lines changed

7 files changed

+98
-10
lines changed

src/views/develop/caniuse/caniuse-data.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/views/develop/caniuse/caniuse.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class App extends Component<unknown, AppState> {
1414
super();
1515
const query = new URLSearchParams(location.search);
1616
this.state = {q: (query.get('q')?.trim()) || undefined};
17-
fetch('caniuse/data/index.json').then(resp => resp.json()).then(data => this.setState({
17+
fetch(dataUrl('index')).then(resp => resp.json()).then(data => this.setState({
1818
index: data,
1919
}));
2020
}
@@ -31,7 +31,9 @@ class App extends Component<unknown, AppState> {
3131

3232
render(props: unknown, state: AppState) {
3333
return html`
34-
<h1>Can I use <input type="search" class="" oninput=${this.onSearchChange}/>?</h1>
34+
<h1>Can I use <input type="search" class="border-0 border-bottom border-dark-subtle bg-dark px-1 mx-1"
35+
defaultValue=${this.state.q} onChange=${this.onSearchChange}/>?
36+
</h1>
3537
<hr/>
3638
${state.index && state.q && html`
3739
<${CanIUseSearch} index=${state.index} name=${state.q}/>`}`;
@@ -44,7 +46,7 @@ function CanIUseSearch(props: { index: Record<string, string[]>, name: string })
4446

4547
async function fetchData(q: string): Promise<DataEntry[]> {
4648
return Promise.all(uniq(Object.entries(index).flatMap(([k, names]) => k.includes(q) ? names : []))
47-
.map(name => fetch(`caniuse/data/${name}.json`).then(resp => {
49+
.map(name => fetch(dataUrl(name)).then(resp => {
4850
if (!resp.ok) {
4951
throw new Error(`Failed to fetch data for ${name}`);
5052
}
@@ -67,6 +69,14 @@ function CanIUseSearch(props: { index: Record<string, string[]>, name: string })
6769
</div>`;
6870
}
6971

72+
function dataUrl(name: string) {
73+
const baseUrl = new URL(location.href);
74+
if (!baseUrl.pathname.endsWith('/')) {
75+
baseUrl.pathname += '/';
76+
}
77+
return new URL(`./data/${name}.json`, baseUrl);
78+
}
79+
7080
render(html`
7181
<${App}/>`,
7282
document.getElementById('app-container')!);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: libndl-directmedia2
2+
library:
3+
- libndl-directmedia2.so.1
4+
warning: |
5+
This library is only available on webOS 2.2~3.4.
6+
tags:
7+
- ndl
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
name: NDL DirectMedia
2-
library: libNDL_directmedia.so.1
2+
library:
3+
- libNDL_directmedia.so.1
4+
version_override:
5+
afro: null
6+
beehive: null
7+
dreadlocks: null
8+
dreadlocks2: v1
9+
goldilocks: v1
10+
goldilocks2: v1
11+
default: v2
312
tags:
413
- ndl

src/views/develop/caniuse/schemas/feature.schema.json

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,58 @@
1818
},
1919
"version_override": {
2020
"title": "Version Override",
21-
"type": "object"
21+
"type": "object",
22+
"properties": {
23+
"afro": {
24+
"title": "webOS 1.x",
25+
"$ref": "#/definitions/VersionOverrideValue"
26+
},
27+
"beehive": {
28+
"title": "webOS 2.x",
29+
"$ref": "#/definitions/VersionOverrideValue"
30+
},
31+
"dreadlocks": {
32+
"title": "webOS 3.0~3.4",
33+
"$ref": "#/definitions/VersionOverrideValue"
34+
},
35+
"dreadlocks2": {
36+
"title": "webOS 3.5~3.9",
37+
"$ref": "#/definitions/VersionOverrideValue"
38+
},
39+
"goldilocks": {
40+
"title": "webOS 4.0~4.4",
41+
"$ref": "#/definitions/VersionOverrideValue"
42+
},
43+
"goldilocks2": {
44+
"title": "webOS 4.5~4.10",
45+
"$ref": "#/definitions/VersionOverrideValue"
46+
},
47+
"jhericurl": {
48+
"title": "webOS 5.x",
49+
"$ref": "#/definitions/VersionOverrideValue"
50+
},
51+
"kisscurl": {
52+
"title": "webOS 6.x",
53+
"$ref": "#/definitions/VersionOverrideValue"
54+
},
55+
"mullet": {
56+
"title": "webOS 7.x",
57+
"$ref": "#/definitions/VersionOverrideValue"
58+
},
59+
"number1": {
60+
"title": "webOS 8.x",
61+
"$ref": "#/definitions/VersionOverrideValue"
62+
},
63+
"ombre": {
64+
"title": "webOS 9.x",
65+
"$ref": "#/definitions/VersionOverrideValue"
66+
},
67+
"default": {
68+
"title": "Default",
69+
"type": "string"
70+
}
71+
},
72+
"additionalProperties": false
2273
},
2374
"documentation": {
2475
"title": "Documentation URL",
@@ -70,5 +121,17 @@
70121
"required": [
71122
"name",
72123
"tags"
73-
]
124+
],
125+
"definitions": {
126+
"VersionOverrideValue": {
127+
"oneOf": [
128+
{
129+
"type": "string"
130+
},
131+
{
132+
"type": "null"
133+
}
134+
]
135+
}
136+
}
74137
}

webpack/caniuse/data-plugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export default class CanIUseDataGenPlugin {
7171
entry.documentation = feature.documentation;
7272
}
7373
for (let firmware of firmwares) {
74-
const override = feature.version_override?.[firmware.major];
74+
const override = feature.version_override && (firmware.major in feature.version_override ?
75+
feature.version_override?.[firmware.major] : feature.version_override?.default);
7576
const version = override !== undefined ? override : (await featureVersion(feature, firmware))?.format();
7677
if (version) {
7778
entry.versions[firmware.major] = version;

webpack/caniuse/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @interface
77
* @property {string} name
88
* @property {string} [warning]
9-
* @property {Record<WebOSMajor, string>} [version_override]
9+
* @property {Record<WebOSMajor | 'default', string>} [version_override]
1010
* @property {string} [documentation]
1111
* @property {string[]} tags
1212
*/

0 commit comments

Comments
 (0)