@@ -26,8 +26,6 @@ import {
2626} from "./utils" ;
2727import { SparqlOverview } from "@sib-swiss/sparql-overview" ;
2828
29- // <sparql-overview endpoint="https://sparql.uniprot.org/sparql/"></sparql-overview>
30-
3129type Autocompleter = { name : string } & Partial < CompleterConfig > ;
3230const addSlashAtEnd = ( str : string ) => ( str . endsWith ( "/" ) ? str : `${ str } /` ) ;
3331const 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 */
4139export 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