@matdata/yasr 5.15.0 → 5.16.0
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/build/ts/src/index.d.ts +5 -0
- package/build/ts/src/index.js +6 -0
- package/build/ts/src/index.js.map +1 -1
- package/build/yasr.min.css.map +1 -1
- package/build/yasr.min.js +1 -1
- package/build/yasr.min.js.map +3 -3
- package/package.json +1 -1
- package/src/index.ts +40 -0
package/build/yasr.min.js
CHANGED
|
@@ -44,7 +44,7 @@ b`.split(/\n/).length!=3?function(e){for(var t=0,o=[],i=e.length;t<=i;){var s=e.
|
|
|
44
44
|
`);c.length>a.maxLines&&(l=c.slice(0,a.maxLines).join(`
|
|
45
45
|
`));let g=document.documentElement.getAttribute("data-theme")==="dark"?"material-palenight":"default",y={readOnly:!0,lineNumbers:!0,lineWrapping:!0,foldGutter:!0,gutters:["CodeMirror-linenumbers","CodeMirror-foldgutter"],value:l,extraKeys:{Tab:!1},theme:g};this.yasr.results?.getType()==="json"&&(y.mode={name:"javascript",json:!0}),this.cm=(0,gm.default)(this.yasr.resultsEl,y),c.length>a.maxLines&&this.showLess(!1)}limitData(n){let a=n.split(`
|
|
46
46
|
`);return a.length>this.config.maxLines&&(n=a.slice(0,this.config.maxLines).join(`
|
|
47
|
-
`)),n}showLess(n=!0){if(!this.cm)return;Qe(this.cm.getWrapperElement(),"overflow"),this.overLay&&(this.overLay.remove(),this.overLay=void 0),this.overLay=document.createElement("div"),Qe(this.overLay,"overlay");let a=document.createElement("div");Qe(a,"overlay_content");let l=document.createElement("button");l.title="Show all",Qe(l,"yasr_btn","overlay_btn"),l.textContent="Show all",l.addEventListener("click",()=>this.showMore()),a.append(l);let c=document.createElement("button");c.title="Download result",Qe(c,"yasr_btn","overlay_btn");let p=document.createElement("span");p.innerText="Download result",c.appendChild(p);let g=document.createElement("i");Qe(g,"fas"),Qe(g,"fa-download"),c.appendChild(g),c.addEventListener("click",()=>this.yasr.download()),c.addEventListener("keydown",y=>{(y.code==="Space"||y.code==="Enter")&&this.yasr.download()}),a.appendChild(c),this.overLay.appendChild(a),this.cm.getWrapperElement().appendChild(this.overLay),n&&this.cm.setValue(this.limitData(this.yasr.results?.getOriginalResponseAsString()||""))}showMore(){this.cm&&(hn(this.cm.getWrapperElement(),"overflow"),this.overLay?.remove(),this.overLay=void 0,this.cm.setValue(this.yasr.results?.getOriginalResponseAsString()||""),this.cm.refresh())}};Gs.defaults={maxLines:30};var na=Gs;var ia=class{constructor(n){this.priority=20;this.hideFromSelection=!0;this.yasr=n}canHandleResults(){return!!this.yasr.results&&!!this.yasr.results.getError()}getTryBtn(n){let a=document.createElement("a");return a.href=n,a.rel="noopener noreferrer",a.target="_blank",a.className="yasr_tryQuery",a.textContent="Try query in a new browser window",a}getCorsMessage(){let n=document.createElement("div");n.className="redOutline";let a=document.createElement("p");a.textContent="Unable to get response from endpoint. Possible reasons:",n.appendChild(a);let l=document.createElement("ul"),c=document.createElement("li");c.textContent="Incorrect endpoint URL",l.appendChild(c);let p=document.createElement("li");p.textContent="Endpoint is down",l.appendChild(p);let g=document.createElement("li");g.textContent="Credentials have expired",l.appendChild(g);let y=document.createElement("li"),T=document.createElement("span");T.textContent="Endpoint is not accessible from the YASGUI server and website, and the endpoint is not ",y.appendChild(T);let U=document.createElement("a");return U.textContent="CORS-enabled",U.href="http://enable-cors.org/",U.target="_blank",U.rel="noopener noreferrer",y.appendChild(U),l.appendChild(y),n.appendChild(l),n}getStatusSpecificGuidance(n){let a=document.createElement("div");a.className="statusGuidance";let l=document.createElement("h4"),c=document.createElement("ul");switch(n){case 401:l.textContent="Authentication Required",a.appendChild(l);let p=document.createElement("li");p.textContent="The endpoint requires authentication credentials",c.appendChild(p);let g=document.createElement("li");g.textContent="Check if you need to provide an API key, username/password, or bearer token",c.appendChild(g);let y=document.createElement("li");return y.textContent="Verify your credentials are correct and not expired",c.appendChild(y),a.appendChild(c),a;case 403:l.textContent="Access Forbidden",a.appendChild(l);let T=document.createElement("li");T.textContent="You don't have permission to access this endpoint",c.appendChild(T);let U=document.createElement("li");U.textContent="Your credentials may be valid but lack sufficient privileges",c.appendChild(U);let A=document.createElement("li");A.textContent="Contact the endpoint administrator to request access",c.appendChild(A);let F=document.createElement("li");return F.textContent="A firewall such as OWASP is blocking is blocking SPARQL queries because they resemble SQL injection attempts. Contact the endpoint administrator to whitelist your queries or adjust firewall settings",c.appendChild(F),a.appendChild(c),a;case 404:l.textContent="Endpoint Not Found",a.appendChild(l);let M=document.createElement("li");M.textContent="The endpoint URL may be incorrect or has changed",c.appendChild(M);let X=document.createElement("li");X.textContent="Check for typos in the endpoint address",c.appendChild(X);let S=document.createElement("li");return S.textContent="Verify the endpoint is still active and hasn't been moved",c.appendChild(S),a.appendChild(c),a;case 429:l.textContent="Too Many Requests",a.appendChild(l);let Z=document.createElement("li");Z.textContent="You've exceeded the rate limit for this endpoint",c.appendChild(Z);let _=document.createElement("li");_.textContent="Wait a few moments before trying again",c.appendChild(_);let G=document.createElement("li");return G.textContent="Consider reducing query frequency or contacting the endpoint provider for higher limits",c.appendChild(G),a.appendChild(c),a;case 500:l.textContent="Internal Server Error",a.appendChild(l);let J=document.createElement("li");J.textContent="The SPARQL endpoint encountered an error while processing your query",c.appendChild(J);let q=document.createElement("li");q.textContent="Try simplifying your query or reducing the result limit",c.appendChild(q);let te=document.createElement("li");te.textContent="Check the error message below for specific details",c.appendChild(te);let ae=document.createElement("li");return ae.textContent="If the problem persists, contact the endpoint administrator",c.appendChild(ae),a.appendChild(c),a;case 502:case 503:case 504:l.textContent=n===502?"Bad Gateway":n===503?"Service Unavailable":"Gateway Timeout",a.appendChild(l);let R=document.createElement("li");R.textContent="The endpoint is temporarily unavailable or overloaded",c.appendChild(R);let w=document.createElement("li");w.textContent="Try again in a few moments",c.appendChild(w);let P=document.createElement("li");return P.textContent="The service may be undergoing maintenance",c.appendChild(P),a.appendChild(c),a;default:if(n>=400&&n<500){l.textContent="Client Error",a.appendChild(l);let $=document.createElement("li");$.textContent="There's an issue with the request",c.appendChild($);let fe=document.createElement("li");return fe.textContent="Check the error message below for details",c.appendChild(fe),a.appendChild(c),a}return null}}async draw(){let n=document.createElement("div");n.className="errorResult",this.yasr.resultsEl.appendChild(n);let a=this.yasr.results?.getError();if(!a)return;let l=document.createElement("div");l.className="errorHeader",n.appendChild(l);let c=await this.yasr.renderError(a);if(c){let g=document.createElement("div");g.className="redOutline",g.appendChild(c),n.appendChild(g);return}if(a.status){var p="Error";a.statusText&&a.statusText.length<100&&(p=a.statusText),p+=` (#${a.status})`;let g=document.createElement("span");if(g.className="status",g.textContent=p,l.appendChild(g),this.yasr.config.getPlainQueryLinkToEndpoint){let T=this.yasr.config.getPlainQueryLinkToEndpoint();T&&l.appendChild(this.getTryBtn(T))}let y=this.getStatusSpecificGuidance(a.status);if(y&&n.appendChild(y),a.text){let T=document.createElement("div");Qe(T,"errorMessageContainer"),n.appendChild(T);let U=document.createElement("pre");Qe(U,"errorMessage"),U.textContent=a.text,T.appendChild(U)}}else{if(this.yasr.config.getPlainQueryLinkToEndpoint){let y=this.yasr.config.getPlainQueryLinkToEndpoint();y&&l.appendChild(this.getTryBtn(y))}if(!a.text||a.text.indexOf("Request has been terminated")>=0||a.text.indexOf("Failed to fetch")>=0||a.text.indexOf("NetworkError")>=0||a.text.indexOf("Network request failed")>=0)n.appendChild(this.getCorsMessage());else{let y=document.createElement("pre");y.textContent=a.text,n.appendChild(y)}}}getIcon(){return document.createElement("")}};var ar=class ar extends mm.EventEmitter{constructor(a,l={},c){super();this.plugins={};this.helpDrawn=!1;this.isFullscreen=!1;this.isLoading=!1;this.utils={addScript:Ms,addCSS:ks,sanitize:wu};if(!a)throw new Error("No parent passed as argument. Dont know where to draw YASR");this.rootEl=document.createElement("div"),this.rootEl.className="yasr",a.appendChild(this.rootEl),this.config=Ol({},ar.defaults,l),this.storage=new ri(ar.storageNamespace),this.getConfigFromStorage(),this.headerEl=document.createElement("div"),this.headerEl.className="yasr_header",this.rootEl.appendChild(this.headerEl),this.fallbackInfoEl=document.createElement("div"),this.fallbackInfoEl.className="yasr_fallback_info",this.rootEl.appendChild(this.fallbackInfoEl),this.resultsEl=document.createElement("div"),this.resultsEl.className="yasr_results",this.resultsEl.id=Dl("resultsId"),this.rootEl.appendChild(this.resultsEl),this.createLoadingElement(),this.initializePlugins(),this.drawHeader();let p=c||this.getResponseFromStorage();p&&this.setResponse(p)}getConfigFromStorage(){let a=this.getStorageId(this.config.persistenceLabelConfig);if(a){let l=this.storage.get(a);if(l){this.selectedPlugin=l.selectedPlugin;for(let c in l.pluginsConfig){let p=l.pluginsConfig[c];p&&this.config.plugins[c]&&(this.config.plugins[c].dynamicConfig=p)}}}}async renderError(a){let l;if(this.config.errorRenderers!==void 0){for(let c of this.config.errorRenderers)if(l=await c(a),l!==void 0)break}return l}getStorageId(a,l){let c=l||this.config.persistenceId;if(c)return typeof c=="string"?c+"_"+a:c(this)+"_"+a}somethingDrawn(){return!!this.resultsEl.children.length}emptyFallbackElement(){for(;this.fallbackInfoEl.firstChild;)this.fallbackInfoEl.removeChild(this.fallbackInfoEl.firstChild)}getSelectedPluginName(){return this.selectedPlugin||this.config.defaultPlugin}getSelectedPlugin(){if(this.plugins[this.getSelectedPluginName()])return this.plugins[this.getSelectedPluginName()];console.warn(`Tried using plugin ${this.getSelectedPluginName()}, but seems this plugin isnt registered in yasr.`)}updatePluginSelectors(a){if(this.pluginSelectorsEl)for(let l in this.config.plugins){let c=this.plugins[l];c&&!c.hideFromSelection&&(a&&(a.indexOf(l)>=0?hn(this.pluginSelectorsEl.querySelector(".select_"+l),"disabled"):Qe(this.pluginSelectorsEl.querySelector(".select_"+l),"disabled")),l===this.getSelectedPluginName()?Qe(this.pluginSelectorsEl.querySelector(".select_"+l),"selected"):hn(this.pluginSelectorsEl.querySelector(".select_"+l),"selected"))}}getCompatiblePlugins(){if(!this.results)return Object.keys(Gl(this.config.plugins,l=>typeof l=="object"&&l.enabled||l===!0));let a=[];for(let l in this.plugins)this.plugins[l].canHandleResults()&&a.push({name:l,priority:this.plugins[l].priority});return a.sort((l,c)=>c.priority-l.priority).map(l=>l.name)}draw(){if(this.updateHelpButton(),this.updateResponseInfo(),!this.results)return;let a=this.getCompatiblePlugins();if(this.drawnPlugin&&this.getSelectedPluginName()!==this.drawnPlugin){for(;this.pluginControls.firstChild;)this.pluginControls.firstChild.remove();this.plugins[this.drawnPlugin].destroy?.()}let l;if(this.getSelectedPlugin()&&this.getSelectedPlugin()?.canHandleResults()?(l=this.getSelectedPluginName(),this.emptyFallbackElement()):a[0]&&(this.drawnPlugin&&this.plugins[this.drawnPlugin].destroy?.(),l=a[0],this.fillFallbackBox(l)),l){this.drawnPlugin=l,this.emit("draw",this,this.plugins[l]);let c=this.plugins[l];(c.initialize?c.initialize():Promise.resolve()).then(async()=>{if(l){for(;this.resultsEl.firstChild;)this.resultsEl.firstChild.remove();await this.plugins[l].draw(this.config.plugins[l].dynamicConfig),this.emit("drawn",this,this.plugins[l]),this.updateExportHeaders(),this.updatePluginSelectors(a)}},g=>console.error)}else this.resultsEl.textContent="cannot render result",this.updateExportHeaders(),this.updatePluginSelectors(a)}refresh(){this.draw()}destroy(){this.drawnPlugin&&this.plugins[this.drawnPlugin]?.destroy?.(),this.removeAllListeners(),this.rootEl.remove()}getPrefixes(){return this.config.prefixes?typeof this.config.prefixes=="function"?this.config.prefixes(this):this.config.prefixes:{}}selectPlugin(a){this.selectedPlugin!==a&&(this.config.plugins[a]?this.selectedPlugin=a:(console.warn(`Plugin ${a} does not exist.`),this.selectedPlugin=this.config.defaultPlugin),this.storeConfig(),this.emit("change",this),this.updatePluginSelectors(),this.draw())}drawPluginSelectors(){this.pluginSelectorsEl=document.createElement("ul"),this.pluginSelectorsEl.className="yasr_btnGroup";let a=this.config.pluginOrder;Object.keys(this.config.plugins).sort().forEach(l=>{a.indexOf(l)===-1&&a.push(l)});for(let l of a){if(!this.config.plugins[l]||!this.config.plugins[l].enabled)continue;let c=this.plugins[l];if(!c||c.hideFromSelection)continue;let p=c.label||l,g=document.createElement("button");if(Qe(g,"yasr_btn","select_"+l),g.title=p,g.type="button",g.setAttribute("aria-label",`Shows ${p} view`),c.getIcon){let U=c.getIcon();U&&(Qe(U,"plugin_icon"),g.appendChild(U))}let y=document.createElement("span");y.textContent=p,g.appendChild(y),g.addEventListener("click",()=>this.selectPlugin(l));let T=document.createElement("li");T.appendChild(g),this.pluginSelectorsEl.appendChild(T)}this.pluginSelectorsEl.children.length>=1&&this.headerEl.appendChild(this.pluginSelectorsEl),this.updatePluginSelectors()}fillFallbackBox(a){if(this.emptyFallbackElement(),this.plugins[a||this.drawnPlugin||""]?.hideFromSelection)return;let l=this.getSelectedPlugin(),c=this.plugins[a||this.drawnPlugin||""]?.label||a||this.drawnPlugin,p=l?.label||this.getSelectedPluginName(),g=document.createElement("p");if(g.innerText=`Could not render results with the ${p} plugin, the results currently are rendered with the ${c} plugin. ${this.getSelectedPlugin()?.helpReference?"See ":""}`,l?.helpReference){let y=document.createElement("a");y.innerText=`${p} documentation`,y.href=l.helpReference,y.rel="noopener noreferrer",y.target="_blank",g.append(y),g.innerHTML+=" for more information."}this.fallbackInfoEl.appendChild(g)}drawPluginElement(){let a=document.createElement("div");Qe(a,"space_element"),this.headerEl.appendChild(a),this.pluginControls=document.createElement("div"),this.pluginControls.setAttribute("id","yasr_plugin_control"),Qe(this.pluginControls,"yasr_plugin_control"),this.pluginControls.setAttribute("aria-controls",this.resultsEl.id),this.headerEl.appendChild(this.pluginControls)}drawHeader(){this.drawPluginSelectors(),this.drawResponseInfo(),this.drawPluginElement(),this.drawDownloadIcon(),this.drawFullscreenButton(),this.loadingEl&&this.headerEl.appendChild(this.loadingEl),this.drawDocumentationButton()}drawDownloadIcon(){this.downloadBtn=document.createElement("a"),Qe(this.downloadBtn,"yasr_btn","yasr_downloadIcon","btn_icon"),this.downloadBtn.download="",this.downloadBtn.setAttribute("aria-label","Download Results"),this.downloadBtn.setAttribute("tabindex","0"),this.downloadBtn.setAttribute("role","button");let a=document.createElement("i");Qe(a,"fas","fa-download"),a.setAttribute("aria-hidden","true"),this.downloadBtn.appendChild(a),this.downloadBtn.addEventListener("click",()=>{Xo(this.downloadBtn,"disabled")||this.download()}),this.downloadBtn.addEventListener("keydown",l=>{if(l.code==="Space"||l.code==="Enter"){if(Xo(this.downloadBtn,"disabled"))return;this.download()}}),this.headerEl.appendChild(this.downloadBtn)}drawResponseInfo(){this.dataElement=document.createElement("div"),Qe(this.dataElement,"yasr_response_chip"),this.headerEl.appendChild(this.dataElement),this.updateResponseInfo()}updateResponseInfo(){let a="";if(this.results){hn(this.dataElement,"empty");let l=this.results.getBindings();l&&(a+=`${l.length} result${l.length===1?"":"s"}`);let c=this.results.getResponseTime();if(c){a||(a="Response");let p=c/1e3;a+=` in ${p} second${p===1?"":"s"}`}}else Qe(this.dataElement,"empty");this.dataElement.innerText=a}updateHelpButton(){let a=this.getSelectedPlugin();if(a?.helpReference){let l=`View documentation of ${a.label||this.getSelectedPluginName()}`;this.documentationLink.href=a.helpReference,this.documentationLink.title=l,this.documentationLink.setAttribute("aria-label",l),hn(this.documentationLink,"disabled")}else Qe(this.documentationLink,"disabled"),this.documentationLink.title="This plugin doesn't have a help reference yet. Please contact the maintainer to fix this"}updateExportHeaders(){if(this.downloadBtn&&this.drawnPlugin){this.downloadBtn.title="";let a=this.plugins[this.drawnPlugin];if(a&&a.download){let l=a.download(this.config.getDownloadFileName?.());if(hn(this.downloadBtn,"disabled"),l){l.title&&(this.downloadBtn.title=l.title);return}}this.downloadBtn.title="Download not supported",Qe(this.downloadBtn,"disabled")}}drawFullscreenButton(){this.fullscreenBtn=document.createElement("button"),Qe(this.fullscreenBtn,"yasr_btn","yasr_fullscreenButton","btn_icon"),this.fullscreenBtn.setAttribute("aria-label","Toggle fullscreen"),this.fullscreenBtn.setAttribute("tabindex","0"),this.fullscreenBtn.setAttribute("role","button");let a=document.createElement("i");Qe(a,"fas"),Qe(a,"fa-expand"),Qe(a,"fullscreenIcon"),a.setAttribute("aria-hidden","true"),this.fullscreenBtn.appendChild(a);let l=document.createElement("i");Qe(l,"fas"),Qe(l,"fa-compress"),Qe(l,"fullscreenExitIcon"),l.setAttribute("aria-hidden","true"),this.fullscreenBtn.appendChild(l),this.fullscreenBtn.title="Toggle fullscreen (F10)",this.fullscreenBtn.addEventListener("click",()=>{this.toggleFullscreen()}),this.fullscreenBtn.addEventListener("keydown",c=>{(c.code==="Space"||c.code==="Enter")&&this.toggleFullscreen()}),this.headerEl.appendChild(this.fullscreenBtn)}toggleFullscreen(){this.isFullscreen=!this.isFullscreen,this.isFullscreen?(Qe(this.rootEl,"fullscreen"),this.fullscreenBtn&&(this.fullscreenBtn.title="Exit fullscreen (F10)")):(hn(this.rootEl,"fullscreen"),this.fullscreenBtn&&(this.fullscreenBtn.title="Toggle fullscreen (F10)"))}getIsFullscreen(){return this.isFullscreen}createLoadingElement(){this.loadingEl=document.createElement("div"),this.loadingEl.className="yasr_loading_indicator",this.loadingEl.title="Executing query...",this.loadingEl.innerHTML='<div class="yasr_loading_spinner"></div>',this.loadingEl.style.display="none"}showLoading(){this.isLoading=!0,this.loadingEl&&(this.loadingEl.style.display="flex")}hideLoading(){this.isLoading=!1,this.loadingEl&&(this.loadingEl.style.display="none")}drawDocumentationButton(){this.documentationLink=document.createElement("a"),Qe(this.documentationLink,"yasr_btn","yasr_external_ref_btn");let a=document.createElement("i");Qe(a,"fas","fa-circle-question"),this.documentationLink.appendChild(a),this.documentationLink.href="https://docs.triply.cc/yasgui/",this.documentationLink.target="_blank",this.documentationLink.rel="noopener noreferrer",this.headerEl.appendChild(this.documentationLink)}download(){if(!this.drawnPlugin)return;let a=this.plugins[this.drawnPlugin];if(a&&a.download){let l=a.download(this.config.getDownloadFileName?.());if(!l)return;let c=l.getData(),p;if(c.startsWith("data:"))p=c;else{let y=new Blob([c],{type:l.contentType??"text/plain"});p=window.URL.createObjectURL(y)}let g=document.createElement("a");g.href=p,g.download=l.filename,g.click()}}handleLocalStorageQuotaFull(a){console.warn("Localstorage quota exceeded. Clearing all queries"),ar.clearStorage()}getResponseFromStorage(){let a=this.getStorageId(this.config.persistenceLabelResponse);if(a)return this.storage.get(a)}getPersistentConfig(){return{selectedPlugin:this.getSelectedPluginName(),pluginsConfig:Mo(this.config.plugins,a=>a.dynamicConfig)}}storePluginConfig(a,l){this.config.plugins[a].dynamicConfig=l,this.storeConfig(),this.emit("change",this)}storeConfig(){let a=this.getStorageId(this.config.persistenceLabelConfig);a&&this.storage.set(a,this.getPersistentConfig(),this.config.persistencyExpire,this.handleLocalStorageQuotaFull)}storeResponse(){let a=this.getStorageId(this.config.persistenceLabelResponse);if(a&&this.results){let l=this.results.getAsStoreObject(this.config.maxPersistentResponseSize);l&&!l.error?this.storage.set(a,l,this.config.persistencyExpire,this.handleLocalStorageQuotaFull):this.storage.remove(a)}}setResponse(a,l){a&&(this.hideLoading(),this.results=new Us(a,l),this.draw(),this.storeResponse())}initializePlugins(){for(let a in this.config.plugins)this.config.plugins[a]&&(ar.plugins[a]?this.plugins[a]=new ar.plugins[a](this):console.warn("Wanted to initialize plugin "+a+" but could not find a matching registered plugin"))}static registerPlugin(a,l,c=!0){ar.plugins[a]=l,c?ar.defaults.plugins[a]={enabled:!0}:ar.defaults.plugins[a]={enabled:!1}}static clearStorage(){new ri(ar.storageNamespace).removeNamespace()}};ar.defaults=Zl(),ar.plugins={},ar.Dependencies={},ar.storageNamespace="triply";var $r=ar;function CR(r,n,a=!0){$r.plugins[r]=n,a?$r.defaults.plugins[r]={enabled:!0}:$r.defaults.plugins[r]={enabled:!1}}$r.registerPlugin("boolean",ra);$r.registerPlugin("response",na);$r.registerPlugin("error",ia);var AR=$r;return Ib(RR);})();
|
|
47
|
+
`)),n}showLess(n=!0){if(!this.cm)return;Qe(this.cm.getWrapperElement(),"overflow"),this.overLay&&(this.overLay.remove(),this.overLay=void 0),this.overLay=document.createElement("div"),Qe(this.overLay,"overlay");let a=document.createElement("div");Qe(a,"overlay_content");let l=document.createElement("button");l.title="Show all",Qe(l,"yasr_btn","overlay_btn"),l.textContent="Show all",l.addEventListener("click",()=>this.showMore()),a.append(l);let c=document.createElement("button");c.title="Download result",Qe(c,"yasr_btn","overlay_btn");let p=document.createElement("span");p.innerText="Download result",c.appendChild(p);let g=document.createElement("i");Qe(g,"fas"),Qe(g,"fa-download"),c.appendChild(g),c.addEventListener("click",()=>this.yasr.download()),c.addEventListener("keydown",y=>{(y.code==="Space"||y.code==="Enter")&&this.yasr.download()}),a.appendChild(c),this.overLay.appendChild(a),this.cm.getWrapperElement().appendChild(this.overLay),n&&this.cm.setValue(this.limitData(this.yasr.results?.getOriginalResponseAsString()||""))}showMore(){this.cm&&(hn(this.cm.getWrapperElement(),"overflow"),this.overLay?.remove(),this.overLay=void 0,this.cm.setValue(this.yasr.results?.getOriginalResponseAsString()||""),this.cm.refresh())}};Gs.defaults={maxLines:30};var na=Gs;var ia=class{constructor(n){this.priority=20;this.hideFromSelection=!0;this.yasr=n}canHandleResults(){return!!this.yasr.results&&!!this.yasr.results.getError()}getTryBtn(n){let a=document.createElement("a");return a.href=n,a.rel="noopener noreferrer",a.target="_blank",a.className="yasr_tryQuery",a.textContent="Try query in a new browser window",a}getCorsMessage(){let n=document.createElement("div");n.className="redOutline";let a=document.createElement("p");a.textContent="Unable to get response from endpoint. Possible reasons:",n.appendChild(a);let l=document.createElement("ul"),c=document.createElement("li");c.textContent="Incorrect endpoint URL",l.appendChild(c);let p=document.createElement("li");p.textContent="Endpoint is down",l.appendChild(p);let g=document.createElement("li");g.textContent="Credentials have expired",l.appendChild(g);let y=document.createElement("li"),T=document.createElement("span");T.textContent="Endpoint is not accessible from the YASGUI server and website, and the endpoint is not ",y.appendChild(T);let U=document.createElement("a");return U.textContent="CORS-enabled",U.href="http://enable-cors.org/",U.target="_blank",U.rel="noopener noreferrer",y.appendChild(U),l.appendChild(y),n.appendChild(l),n}getStatusSpecificGuidance(n){let a=document.createElement("div");a.className="statusGuidance";let l=document.createElement("h4"),c=document.createElement("ul");switch(n){case 401:l.textContent="Authentication Required",a.appendChild(l);let p=document.createElement("li");p.textContent="The endpoint requires authentication credentials",c.appendChild(p);let g=document.createElement("li");g.textContent="Check if you need to provide an API key, username/password, or bearer token",c.appendChild(g);let y=document.createElement("li");return y.textContent="Verify your credentials are correct and not expired",c.appendChild(y),a.appendChild(c),a;case 403:l.textContent="Access Forbidden",a.appendChild(l);let T=document.createElement("li");T.textContent="You don't have permission to access this endpoint",c.appendChild(T);let U=document.createElement("li");U.textContent="Your credentials may be valid but lack sufficient privileges",c.appendChild(U);let A=document.createElement("li");A.textContent="Contact the endpoint administrator to request access",c.appendChild(A);let F=document.createElement("li");return F.textContent="A firewall such as OWASP is blocking is blocking SPARQL queries because they resemble SQL injection attempts. Contact the endpoint administrator to whitelist your queries or adjust firewall settings",c.appendChild(F),a.appendChild(c),a;case 404:l.textContent="Endpoint Not Found",a.appendChild(l);let M=document.createElement("li");M.textContent="The endpoint URL may be incorrect or has changed",c.appendChild(M);let X=document.createElement("li");X.textContent="Check for typos in the endpoint address",c.appendChild(X);let S=document.createElement("li");return S.textContent="Verify the endpoint is still active and hasn't been moved",c.appendChild(S),a.appendChild(c),a;case 429:l.textContent="Too Many Requests",a.appendChild(l);let Z=document.createElement("li");Z.textContent="You've exceeded the rate limit for this endpoint",c.appendChild(Z);let _=document.createElement("li");_.textContent="Wait a few moments before trying again",c.appendChild(_);let G=document.createElement("li");return G.textContent="Consider reducing query frequency or contacting the endpoint provider for higher limits",c.appendChild(G),a.appendChild(c),a;case 500:l.textContent="Internal Server Error",a.appendChild(l);let J=document.createElement("li");J.textContent="The SPARQL endpoint encountered an error while processing your query",c.appendChild(J);let q=document.createElement("li");q.textContent="Try simplifying your query or reducing the result limit",c.appendChild(q);let te=document.createElement("li");te.textContent="Check the error message below for specific details",c.appendChild(te);let ae=document.createElement("li");return ae.textContent="If the problem persists, contact the endpoint administrator",c.appendChild(ae),a.appendChild(c),a;case 502:case 503:case 504:l.textContent=n===502?"Bad Gateway":n===503?"Service Unavailable":"Gateway Timeout",a.appendChild(l);let R=document.createElement("li");R.textContent="The endpoint is temporarily unavailable or overloaded",c.appendChild(R);let w=document.createElement("li");w.textContent="Try again in a few moments",c.appendChild(w);let P=document.createElement("li");return P.textContent="The service may be undergoing maintenance",c.appendChild(P),a.appendChild(c),a;default:if(n>=400&&n<500){l.textContent="Client Error",a.appendChild(l);let $=document.createElement("li");$.textContent="There's an issue with the request",c.appendChild($);let fe=document.createElement("li");return fe.textContent="Check the error message below for details",c.appendChild(fe),a.appendChild(c),a}return null}}async draw(){let n=document.createElement("div");n.className="errorResult",this.yasr.resultsEl.appendChild(n);let a=this.yasr.results?.getError();if(!a)return;let l=document.createElement("div");l.className="errorHeader",n.appendChild(l);let c=await this.yasr.renderError(a);if(c){let g=document.createElement("div");g.className="redOutline",g.appendChild(c),n.appendChild(g);return}if(a.status){var p="Error";a.statusText&&a.statusText.length<100&&(p=a.statusText),p+=` (#${a.status})`;let g=document.createElement("span");if(g.className="status",g.textContent=p,l.appendChild(g),this.yasr.config.getPlainQueryLinkToEndpoint){let T=this.yasr.config.getPlainQueryLinkToEndpoint();T&&l.appendChild(this.getTryBtn(T))}let y=this.getStatusSpecificGuidance(a.status);if(y&&n.appendChild(y),a.text){let T=document.createElement("div");Qe(T,"errorMessageContainer"),n.appendChild(T);let U=document.createElement("pre");Qe(U,"errorMessage"),U.textContent=a.text,T.appendChild(U)}}else{if(this.yasr.config.getPlainQueryLinkToEndpoint){let y=this.yasr.config.getPlainQueryLinkToEndpoint();y&&l.appendChild(this.getTryBtn(y))}if(!a.text||a.text.indexOf("Request has been terminated")>=0||a.text.indexOf("Failed to fetch")>=0||a.text.indexOf("NetworkError")>=0||a.text.indexOf("Network request failed")>=0)n.appendChild(this.getCorsMessage());else{let y=document.createElement("pre");y.textContent=a.text,n.appendChild(y)}}}getIcon(){return document.createElement("")}};var ar=class ar extends mm.EventEmitter{constructor(a,l={},c){super();this.plugins={};this.helpDrawn=!1;this.isFullscreen=!1;this.isLoading=!1;this.utils={addScript:Ms,addCSS:ks,sanitize:wu};if(!a)throw new Error("No parent passed as argument. Dont know where to draw YASR");this.rootEl=document.createElement("div"),this.rootEl.className="yasr",a.appendChild(this.rootEl),this.config=Ol({},ar.defaults,l),this.storage=new ri(ar.storageNamespace),this.getConfigFromStorage(),this.headerEl=document.createElement("div"),this.headerEl.className="yasr_header",this.rootEl.appendChild(this.headerEl),this.fallbackInfoEl=document.createElement("div"),this.fallbackInfoEl.className="yasr_fallback_info",this.rootEl.appendChild(this.fallbackInfoEl),this.resultsEl=document.createElement("div"),this.resultsEl.className="yasr_results",this.resultsEl.id=Dl("resultsId"),this.rootEl.appendChild(this.resultsEl),this.createLoadingElement(),this.initializePlugins(),this.drawHeader();let p=c||this.getResponseFromStorage();p&&this.setResponse(p)}getConfigFromStorage(){let a=this.getStorageId(this.config.persistenceLabelConfig);if(a){let l=this.storage.get(a);if(l){this.selectedPlugin=l.selectedPlugin;for(let c in l.pluginsConfig){let p=l.pluginsConfig[c];p&&this.config.plugins[c]&&(this.config.plugins[c].dynamicConfig=p)}}}}async renderError(a){let l;if(this.config.errorRenderers!==void 0){for(let c of this.config.errorRenderers)if(l=await c(a),l!==void 0)break}return l}getStorageId(a,l){let c=l||this.config.persistenceId;if(c)return typeof c=="string"?c+"_"+a:c(this)+"_"+a}somethingDrawn(){return!!this.resultsEl.children.length}emptyFallbackElement(){for(;this.fallbackInfoEl.firstChild;)this.fallbackInfoEl.removeChild(this.fallbackInfoEl.firstChild)}getSelectedPluginName(){return this.selectedPlugin||this.config.defaultPlugin}getSelectedPlugin(){if(this.plugins[this.getSelectedPluginName()])return this.plugins[this.getSelectedPluginName()];console.warn(`Tried using plugin ${this.getSelectedPluginName()}, but seems this plugin isnt registered in yasr.`)}updatePluginSelectors(a){if(this.pluginSelectorsEl)for(let l in this.config.plugins){let c=this.plugins[l];c&&!c.hideFromSelection&&(a&&(a.indexOf(l)>=0?hn(this.pluginSelectorsEl.querySelector(".select_"+l),"disabled"):Qe(this.pluginSelectorsEl.querySelector(".select_"+l),"disabled")),l===this.getSelectedPluginName()?Qe(this.pluginSelectorsEl.querySelector(".select_"+l),"selected"):hn(this.pluginSelectorsEl.querySelector(".select_"+l),"selected"))}}getCompatiblePlugins(){if(!this.results)return Object.keys(Gl(this.config.plugins,l=>typeof l=="object"&&l.enabled||l===!0));let a=[];for(let l in this.plugins)this.plugins[l].canHandleResults()&&a.push({name:l,priority:this.plugins[l].priority});return a.sort((l,c)=>c.priority-l.priority).map(l=>l.name)}draw(){if(this.updateHelpButton(),this.updateResponseInfo(),!this.results)return;let a=this.getCompatiblePlugins();if(this.drawnPlugin&&this.getSelectedPluginName()!==this.drawnPlugin){for(;this.pluginControls.firstChild;)this.pluginControls.firstChild.remove();this.plugins[this.drawnPlugin].destroy?.()}let l;if(this.getSelectedPlugin()&&this.getSelectedPlugin()?.canHandleResults()?(l=this.getSelectedPluginName(),this.emptyFallbackElement()):a[0]&&(this.drawnPlugin&&this.plugins[this.drawnPlugin].destroy?.(),l=a[0],this.fillFallbackBox(l)),l){this.drawnPlugin=l,this.emit("draw",this,this.plugins[l]);let c=this.plugins[l];(c.initialize?c.initialize():Promise.resolve()).then(async()=>{if(l){for(;this.resultsEl.firstChild;)this.resultsEl.firstChild.remove();await this.plugins[l].draw(this.config.plugins[l].dynamicConfig),this.emit("drawn",this,this.plugins[l]),this.updateExportHeaders(),this.updatePluginSelectors(a)}},g=>console.error)}else this.resultsEl.textContent="cannot render result",this.updateExportHeaders(),this.updatePluginSelectors(a)}refresh(){this.draw()}destroy(){this.drawnPlugin&&this.plugins[this.drawnPlugin]?.destroy?.(),this.removeAllListeners(),this.rootEl.remove()}getPrefixes(){return this.config.prefixes?typeof this.config.prefixes=="function"?this.config.prefixes(this):this.config.prefixes:{}}selectPlugin(a){this.selectedPlugin!==a&&(this.config.plugins[a]?this.selectedPlugin=a:(console.warn(`Plugin ${a} does not exist.`),this.selectedPlugin=this.config.defaultPlugin),this.storeConfig(),this.emit("change",this),this.updatePluginSelectors(),this.draw())}drawPluginSelectors(){this.pluginSelectorsEl=document.createElement("ul"),this.pluginSelectorsEl.className="yasr_btnGroup";let a=this.config.pluginOrder;Object.keys(this.config.plugins).sort().forEach(l=>{a.indexOf(l)===-1&&a.push(l)});for(let l of a){if(!this.config.plugins[l]||!this.config.plugins[l].enabled)continue;let c=this.plugins[l];if(!c||c.hideFromSelection)continue;let p=c.label||l,g=document.createElement("button");if(Qe(g,"yasr_btn","select_"+l),g.title=p,g.type="button",g.setAttribute("aria-label",`Shows ${p} view`),c.getIcon){let U=c.getIcon();U&&(Qe(U,"plugin_icon"),g.appendChild(U))}let y=document.createElement("span");y.textContent=p,g.appendChild(y),g.addEventListener("click",()=>this.selectPlugin(l));let T=document.createElement("li");T.appendChild(g),this.pluginSelectorsEl.appendChild(T)}this.pluginSelectorsEl.children.length>=1&&this.headerEl.appendChild(this.pluginSelectorsEl),this.updatePluginSelectors()}fillFallbackBox(a){if(this.emptyFallbackElement(),this.plugins[a||this.drawnPlugin||""]?.hideFromSelection)return;let l=this.getSelectedPlugin(),c=this.plugins[a||this.drawnPlugin||""]?.label||a||this.drawnPlugin,p=l?.label||this.getSelectedPluginName(),g=document.createElement("p");if(g.innerText=`Could not render results with the ${p} plugin, the results currently are rendered with the ${c} plugin. ${this.getSelectedPlugin()?.helpReference?"See ":""}`,l?.helpReference){let y=document.createElement("a");y.innerText=`${p} documentation`,y.href=l.helpReference,y.rel="noopener noreferrer",y.target="_blank",g.append(y),g.innerHTML+=" for more information."}this.fallbackInfoEl.appendChild(g)}drawPluginElement(){let a=document.createElement("div");Qe(a,"space_element"),this.headerEl.appendChild(a),this.pluginControls=document.createElement("div"),this.pluginControls.setAttribute("id","yasr_plugin_control"),Qe(this.pluginControls,"yasr_plugin_control"),this.pluginControls.setAttribute("aria-controls",this.resultsEl.id),this.headerEl.appendChild(this.pluginControls)}drawHeader(){this.drawPluginSelectors(),this.drawResponseInfo(),this.drawPluginElement(),this.drawDownloadIcon(),this.drawFullscreenButton(),this.loadingEl&&this.headerEl.appendChild(this.loadingEl),this.drawDocumentationButton()}drawDownloadIcon(){this.downloadBtn=document.createElement("a"),Qe(this.downloadBtn,"yasr_btn","yasr_downloadIcon","btn_icon"),this.downloadBtn.download="",this.downloadBtn.setAttribute("aria-label","Download Results"),this.downloadBtn.setAttribute("tabindex","0"),this.downloadBtn.setAttribute("role","button");let a=document.createElement("i");Qe(a,"fas","fa-download"),a.setAttribute("aria-hidden","true"),this.downloadBtn.appendChild(a),this.downloadBtn.addEventListener("click",()=>{Xo(this.downloadBtn,"disabled")||this.download()}),this.downloadBtn.addEventListener("keydown",l=>{if(l.code==="Space"||l.code==="Enter"){if(Xo(this.downloadBtn,"disabled"))return;this.download()}}),this.headerEl.appendChild(this.downloadBtn)}drawResponseInfo(){this.dataElement=document.createElement("div"),Qe(this.dataElement,"yasr_response_chip"),this.headerEl.appendChild(this.dataElement),this.updateResponseInfo()}updateResponseInfo(){let a="";if(this.results){hn(this.dataElement,"empty");let l=this.results.getBindings();l&&(a+=`${l.length} result${l.length===1?"":"s"}`);let c=this.results.getResponseTime();if(c){a||(a="Response");let p=c/1e3;a+=` in ${p} second${p===1?"":"s"}`}}else Qe(this.dataElement,"empty");this.dataElement.innerText=a}updateHelpButton(){let a=this.getSelectedPlugin();if(a?.helpReference){let l=`View documentation of ${a.label||this.getSelectedPluginName()}`;this.documentationLink.href=a.helpReference,this.documentationLink.title=l,this.documentationLink.setAttribute("aria-label",l),hn(this.documentationLink,"disabled")}else Qe(this.documentationLink,"disabled"),this.documentationLink.title="This plugin doesn't have a help reference yet. Please contact the maintainer to fix this"}updateExportHeaders(){if(this.downloadBtn&&this.drawnPlugin){this.downloadBtn.title="";let a=this.plugins[this.drawnPlugin];if(a&&a.download){let l=a.download(this.config.getDownloadFileName?.());if(hn(this.downloadBtn,"disabled"),l){l.title&&(this.downloadBtn.title=l.title);return}}this.downloadBtn.title="Download not supported",Qe(this.downloadBtn,"disabled")}}drawFullscreenButton(){this.fullscreenBtn=document.createElement("button"),Qe(this.fullscreenBtn,"yasr_btn","yasr_fullscreenButton","btn_icon"),this.fullscreenBtn.setAttribute("aria-label","Toggle fullscreen"),this.fullscreenBtn.setAttribute("tabindex","0"),this.fullscreenBtn.setAttribute("role","button");let a=document.createElement("i");Qe(a,"fas"),Qe(a,"fa-expand"),Qe(a,"fullscreenIcon"),a.setAttribute("aria-hidden","true"),this.fullscreenBtn.appendChild(a);let l=document.createElement("i");Qe(l,"fas"),Qe(l,"fa-compress"),Qe(l,"fullscreenExitIcon"),l.setAttribute("aria-hidden","true"),this.fullscreenBtn.appendChild(l),this.fullscreenBtn.title="Toggle fullscreen (F10)",this.fullscreenBtn.addEventListener("click",()=>{this.toggleFullscreen()}),this.fullscreenBtn.addEventListener("keydown",c=>{(c.code==="Space"||c.code==="Enter")&&this.toggleFullscreen()}),this.headerEl.appendChild(this.fullscreenBtn)}toggleFullscreen(){this.isFullscreen=!this.isFullscreen,this.isFullscreen?(Qe(this.rootEl,"fullscreen"),this.fullscreenBtn&&(this.fullscreenBtn.title="Exit fullscreen (F10)")):(hn(this.rootEl,"fullscreen"),this.fullscreenBtn&&(this.fullscreenBtn.title="Toggle fullscreen (F10)"))}getIsFullscreen(){return this.isFullscreen}createLoadingElement(){this.loadingEl=document.createElement("div"),this.loadingEl.className="yasr_loading_indicator",this.loadingEl.title="Executing query...",this.loadingEl.innerHTML='<div class="yasr_loading_spinner"></div>',this.loadingEl.style.display="none"}showLoading(){this.isLoading=!0,this.loadingEl&&(this.loadingEl.style.display="flex")}hideLoading(){this.isLoading=!1,this.loadingEl&&(this.loadingEl.style.display="none")}drawDocumentationButton(){this.documentationLink=document.createElement("a"),Qe(this.documentationLink,"yasr_btn","yasr_external_ref_btn");let a=document.createElement("i");Qe(a,"fas","fa-circle-question"),this.documentationLink.appendChild(a),this.documentationLink.href="https://docs.triply.cc/yasgui/",this.documentationLink.target="_blank",this.documentationLink.rel="noopener noreferrer",this.headerEl.appendChild(this.documentationLink)}download(){if(!this.drawnPlugin)return;let a=this.plugins[this.drawnPlugin];if(a&&a.download){let l=a.download(this.config.getDownloadFileName?.());if(!l)return;let c=l.getData(),p;if(c.startsWith("data:"))p=c;else{let y=new Blob([c],{type:l.contentType??"text/plain"});p=window.URL.createObjectURL(y)}let g=document.createElement("a");g.href=p,g.download=l.filename,g.click()}}handleLocalStorageQuotaFull(a){console.warn("Localstorage quota exceeded. Clearing all queries"),ar.clearStorage()}getResponseFromStorage(){let a=this.getStorageId(this.config.persistenceLabelResponse);if(a)return this.storage.get(a)}getPersistentConfig(){return{selectedPlugin:this.getSelectedPluginName(),pluginsConfig:Mo(this.config.plugins,a=>a.dynamicConfig)}}storePluginConfig(a,l){this.config.plugins[a].dynamicConfig=l,this.storeConfig(),this.emit("change",this)}storeConfig(){let a=this.getStorageId(this.config.persistenceLabelConfig);a&&this.storage.set(a,this.getPersistentConfig(),this.config.persistencyExpire,this.handleLocalStorageQuotaFull)}storeResponse(){let a=this.getStorageId(this.config.persistenceLabelResponse);if(a&&this.results){let l=this.results.getAsStoreObject(this.config.maxPersistentResponseSize);l&&!l.error?this.storage.set(a,l,this.config.persistencyExpire,this.handleLocalStorageQuotaFull):this.storage.remove(a)}}setResponse(a,l){a&&(this.hideLoading(),this.results=new Us(a,l),this.draw(),this.storeResponse())}executeQuery(a,l){return this.config.executeQuery?this.config.executeQuery(a,l):Promise.reject(new Error("No executeQuery handler configured on this Yasr instance"))}initializePlugins(){for(let a in this.config.plugins)this.config.plugins[a]&&(ar.plugins[a]?this.plugins[a]=new ar.plugins[a](this):console.warn("Wanted to initialize plugin "+a+" but could not find a matching registered plugin"))}static registerPlugin(a,l,c=!0){ar.plugins[a]=l,c?ar.defaults.plugins[a]={enabled:!0}:ar.defaults.plugins[a]={enabled:!1}}static clearStorage(){new ri(ar.storageNamespace).removeNamespace()}};ar.defaults=Zl(),ar.plugins={},ar.Dependencies={},ar.storageNamespace="triply";var $r=ar;function CR(r,n,a=!0){$r.plugins[r]=n,a?$r.defaults.plugins[r]={enabled:!0}:$r.defaults.plugins[r]={enabled:!1}}$r.registerPlugin("boolean",ra);$r.registerPlugin("response",na);$r.registerPlugin("error",ia);var AR=$r;return Ib(RR);})();
|
|
48
48
|
/*! Bundled license information:
|
|
49
49
|
|
|
50
50
|
ieee754/index.js:
|