Skip to content

Commit 5cb2849

Browse files
committed
move most stuff out of constructor to put in connectedCallback because wont work in vuejs
1 parent a8662ba commit 5cb2849

File tree

4 files changed

+40
-36
lines changed

4 files changed

+40
-36
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d
44

55
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
66

7+
#### [v0.2.10](https://github.com/sib-swiss/sparql-editor/compare/v0.2.9...v0.2.10)
8+
9+
- fix issue with undefined currentEndpoint only happening in vuejs [`a8662ba`](https://github.com/sib-swiss/sparql-editor/commit/a8662ba7de6a0e270fa01487e6c6ed310af3d053)
10+
711
#### [v0.2.9](https://github.com/sib-swiss/sparql-editor/compare/v0.2.8...v0.2.9)
812

13+
> 28 March 2025
14+
915
- upgrade versions [`3b323df`](https://github.com/sib-swiss/sparql-editor/commit/3b323df6b299c0da2604ecfc99d634a043eaefa1)
1016
- fix undefined currentEndpoint only happening in vuejs [`70aebe7`](https://github.com/sib-swiss/sparql-editor/commit/70aebe7f2ac7d2e21bb8e2656bd41ed55ab1c54a)
1117

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sparql-editor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sib-swiss/sparql-editor",
3-
"version": "0.2.9",
3+
"version": "0.2.10",
44
"description": "A standard web component to easily deploy a user-friendly SPARQL query editor for one or more endpoints. Built on the popular YASGUI editor, it provides context-aware autocomplete for classes and predicates based on the content of the endpoints.",
55
"license": "MIT",
66
"author": {

packages/sparql-editor/src/sparql-editor.ts

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
} from "./utils";
2727
import {SparqlOverview} from "@sib-swiss/sparql-overview";
2828

29-
// <sparql-overview endpoint="https://sparql.uniprot.org/sparql/"></sparql-overview>
30-
3129
type Autocompleter = {name: string} & Partial<CompleterConfig>;
3230
const addSlashAtEnd = (str: string) => (str.endsWith("/") ? str : `${str}/`);
3331
const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
@@ -39,14 +37,14 @@ const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1).t
3937
* @example <sparql-editor endpoint="https://sparql.uniprot.org/sparql/" examples-on-main-page="10"></sparql-editor>
4038
*/
4139
export class SparqlEditor extends HTMLElement {
42-
examplesOnMainPage: number;
40+
endpoints: string[] = [];
41+
examplesOnMainPage: number = 8;
4342
yasgui: Yasgui | undefined;
44-
endpoints: string[];
4543
meta: EndpointsMetadata;
46-
examplesRepo: string | null;
47-
examplesRepoAddUrl: string | null;
48-
addLimit: number | null;
49-
dialogElOpen: HTMLDialogElement | null = null;
44+
examplesRepo: string | undefined;
45+
examplesRepoAddUrl: string | undefined;
46+
addLimit: number | undefined;
47+
dialogElOpen: HTMLDialogElement | undefined;
5048
// TODO: make exampleQueries a dict with the query IRI as key, so if the window.location matches a key, it will load the query?
5149

5250
examplesNamespace() {
@@ -57,6 +55,7 @@ export class SparqlEditor extends HTMLElement {
5755

5856
// Return the current endpoint URL
5957
endpointUrl() {
58+
// console.log(this.yasgui?.getTab(), this.endpoints)
6059
return this.yasgui?.getTab()?.getEndpoint() || this.endpoints[0];
6160
}
6261

@@ -68,28 +67,6 @@ export class SparqlEditor extends HTMLElement {
6867
constructor() {
6968
super();
7069
this.meta = this.loadMetaFromLocalStorage();
71-
this.endpoints = (this.getAttribute("endpoint") || "").split(",").map(e => e.trim());
72-
73-
// NOTE: will need to be removed at some point I guess
74-
// Check if examples contain the index field, if not reset cache
75-
if (this.currentEndpoint() && this.currentEndpoint().examples?.some(example => example.iri === undefined)) {
76-
localStorage.removeItem("sparql-editor-metadata");
77-
console.warn("Invalid metadata format, resetting cache");
78-
this.meta = {};
79-
}
80-
81-
// console.log("Loaded metadata from localStorage", this.meta);
82-
if (this.endpoints.length === 0)
83-
throw new Error("No endpoint provided. Please use the 'endpoint' attribute to specify the SPARQL endpoint URL.");
84-
85-
this.addLimit = Number(this.getAttribute("add-limit")) || null;
86-
this.examplesOnMainPage = Number(this.getAttribute("examples-on-main-page")) || 8;
87-
this.examplesRepoAddUrl = this.getAttribute("examples-repo-add-url");
88-
this.examplesRepo = this.getAttribute("examples-repository");
89-
if (this.examplesRepoAddUrl && !this.examplesRepo) this.examplesRepo = this.examplesRepoAddUrl.split("/new/")[0];
90-
91-
hljs.registerLanguage("ttl", hljsDefineTurtle);
92-
hljs.registerLanguage("sparql", hljsDefineSparql);
9370
}
9471

9572
// Load and save metadata to localStorage
@@ -207,14 +184,35 @@ export class SparqlEditor extends HTMLElement {
207184
}
208185

209186
async connectedCallback() {
187+
this.endpoints = (this.getAttribute("endpoint") || "").split(",").map(e => e.trim());
188+
189+
// NOTE: will need to be removed at some point I guess
190+
// Check if examples contain the index field, if not reset cache
191+
if (this.currentEndpoint() && this.currentEndpoint().examples?.some(example => example.iri === undefined)) {
192+
localStorage.removeItem("sparql-editor-metadata");
193+
console.warn("Invalid metadata format, resetting cache");
194+
this.meta = {};
195+
}
196+
197+
// console.log("Loaded metadata from localStorage", this.meta);
198+
if (this.endpoints.length === 0)
199+
throw new Error("No endpoint provided. Please use the 'endpoint' attribute to specify the SPARQL endpoint URL.");
200+
201+
this.addLimit = Number(this.getAttribute("add-limit")) || this.addLimit;
202+
this.examplesOnMainPage = Number(this.getAttribute("examples-on-main-page")) || this.examplesOnMainPage;
203+
this.examplesRepoAddUrl = this.getAttribute("examples-repo-add-url") || this.examplesRepoAddUrl;
204+
this.examplesRepo = this.getAttribute("examples-repository") || this.examplesRepo;
205+
if (this.examplesRepoAddUrl && !this.examplesRepo) this.examplesRepo = this.examplesRepoAddUrl.split("/new/")[0];
206+
207+
hljs.registerLanguage("ttl", hljsDefineTurtle);
208+
hljs.registerLanguage("sparql", hljsDefineSparql);
209+
210210
const defaultMethod = (this.getAttribute("default-method")?.toUpperCase() as "GET" | "POST") || "GET";
211211
if (!["GET", "POST"].includes(defaultMethod))
212212
console.warn("Default method is wrong, should be GET or POST", defaultMethod);
213213

214-
// NOTE:
215-
const styleEl = document.querySelector("style") || document.createElement("style");
214+
const styleEl = document.createElement("style");
216215
styleEl.textContent = `
217-
${styleEl.textContent || ""}
218216
${yasguiCss}
219217
${yasguiGripInlineCss}
220218
${highlightjsCss}
@@ -547,7 +545,7 @@ export class SparqlEditor extends HTMLElement {
547545
closeDialog() {
548546
if (this.dialogElOpen) {
549547
this.dialogElOpen.close();
550-
this.dialogElOpen = null;
548+
this.dialogElOpen = undefined;
551549
document.body.style.overflow = "";
552550
// history.back();
553551
}

0 commit comments

Comments
 (0)