lucos_search_component 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example/example.js +3 -1
- package/example/index.html +1 -1
- package/index.js +23 -1
- package/package.json +2 -1
package/example/example.js
CHANGED
package/example/index.html
CHANGED
package/index.js
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
class LucosSearchComponent extends HTMLElement {
|
|
2
|
+
static get observedAttributes() {
|
|
3
|
+
return ['api-key'];
|
|
4
|
+
}
|
|
2
5
|
constructor() {
|
|
3
6
|
super();
|
|
4
7
|
const shadow = this.attachShadow({mode: 'closed'});
|
|
5
|
-
|
|
8
|
+
|
|
9
|
+
const results = document.createElement("span");
|
|
10
|
+
this.updateResults = resultData => {
|
|
11
|
+
results.innerText = JSON.stringify(resultData);
|
|
12
|
+
}
|
|
13
|
+
shadow.appendChild(results);
|
|
14
|
+
}
|
|
15
|
+
async searchAPI(query) {
|
|
16
|
+
const key = this.getAttribute("api-key");
|
|
17
|
+
if (!key) throw new Error("No `api-key` attribute set on `lucos-search` component");
|
|
18
|
+
|
|
19
|
+
const queryParams = new URLSearchParams({
|
|
20
|
+
q: query,
|
|
21
|
+
});
|
|
22
|
+
const response = await fetch("https://arachne.l42.eu/basic-search?"+queryParams.toString(), {
|
|
23
|
+
headers: { Authorization: `key ${key}` },
|
|
24
|
+
signal: AbortSignal.timeout(900),
|
|
25
|
+
});
|
|
26
|
+
const data = await response.json();
|
|
27
|
+
this.updateResults(data);
|
|
6
28
|
}
|
|
7
29
|
}
|
|
8
30
|
customElements.define('lucos-search', LucosSearchComponent);
|
package/package.json
CHANGED