@matdata/yasgui 5.19.1 → 5.20.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.
@@ -122,7 +122,7 @@ ${ug}`,t},k$=i=>{let t=i.distinct?"DISTINCT ":"";if(i.aggregateType==="count"){l
122
122
  `}if(!r)return this.getValue();var d="",h=!1,A=!1;return Tr.runMode(this.getValue(),"sparql11",function(y,E,V,Z,S){E==="keyword"&&y.toLowerCase()==="select"&&(A=!0),d+=y,A&&!h&&E==="punc"&&y==="{"&&(h=!0,d+=`
123
123
  `+r)}),d}getValueWithoutComments(){var e="";return Tr.runMode(this.getValue(),"sparql11",function(r,n){n!="comment"&&(e+=r)}),e}setCheckSyntaxErrors(e){this.config.syntaxErrorCheck=e,this.checkSyntax(),this.checkConstructVariables()}checkSyntax(){this.queryValid=!0,this.clearGutter("gutterErrorBar");for(var e,r=0;r<this.getDoc().lineCount();++r){var n=!1;this.prevQueryValid||(n=!0);var s=this.getTokenAt({line:r,ch:this.getDoc().getLine(r).length},n),e=s.state;if(this.setOption("queryType",e.queryType),e.OK==!1){if(!this.config.syntaxErrorCheck){let A=this.getWrapperElement().querySelectorAll(".sp-error");for(let y=0;y<A.length;y++){var a=A[y];a.style&&(a.style.color="black")}return}let h=document.createElement("i");if(h.className="fas fa-exclamation-circle parseErrorIcon",e.errorMsg)jC(this,h,Dm(e.errorMsg));else if(e.possibleCurrent&&e.possibleCurrent.length>0){let A=[];e.possibleCurrent.forEach(function(y){A.push("<strong style='text-decoration:underline'>"+Dm(y)+"</strong>")}),jC(this,h,"This line is invalid. Expected: "+A.join(", "))}else jC(this,h,"Syntax error");this.setGutterMarker(r,"gutterErrorBar",h),this.queryBtn&&(ie(this.queryBtn,"query_error"),this.queryBtn.title="Query has syntax errors"),this.queryValid=!1;break}}this.queryValid&&this.queryBtn&&(oi(this.queryBtn,"query_error"),this.queryBtn.title="Run query (Ctrl+Enter)")}setCheckConstructVariables(e){this.config.checkConstructVariables=e,e?this.checkConstructVariables():this.clearGutter("gutterConstructWarning")}setSaveButtonVisible(e){this.saveBtnWrapper&&(this.saveBtnWrapper.style.display=e?"inline-flex":"none")}checkConstructVariables(){if(this.clearGutter("gutterConstructWarning"),!this.config.checkConstructVariables||!this.queryValid||this.getQueryType()!=="CONSTRUCT")return;let e=this.getDoc().lastLine(),n=this.getTokenAt({line:e,ch:this.getDoc().getLine(e).length},!0).state,s=[];for(let a in n.constructVariables)n.whereVariables[a]||s.push(a);if(s.length!==0)for(let a=0;a<this.getDoc().lineCount();++a){let h=this.getTokenAt({line:a,ch:this.getDoc().getLine(a).length},!0).state;if(h.queryType==="CONSTRUCT"&&h.inConstructTemplate){let A=this.getDoc().getLine(a);for(let y of s){let E=y.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");if(new RegExp(`${E}(?![a-zA-Z0-9_])`).test(A)){let Z=document.createElement("i");Z.className="fas fa-exclamation-triangle constructVariableWarning",jC(this,Z,"Variable <strong>"+Dm(y)+"</strong> is used in CONSTRUCT but not defined in WHERE clause"),this.setGutterMarker(a,"gutterConstructWarning",Z);break}}}}}getCompleteToken(e,r){return nM(this,e,r)}getPreviousNonWsToken(e,r){return $F(this,e,r)}getNextNonWsToken(e,r){return _C(this,e,r)}showNotification(e,r){if(!this.notificationEls[e]){let s=document.createElement("div");ie(s,"notificationContainer"),this.getWrapperElement().appendChild(s),this.notificationEls[e]=document.createElement("div"),ie(this.notificationEls[e],"notification","notif_"+e),s.appendChild(this.notificationEls[e])}for(let s in this.notificationEls)s!==e&&this.hideNotification(s);let n=this.notificationEls[e];ie(n,"active"),n.innerText=r}hideNotification(e){this.notificationEls[e]&&oi(this.notificationEls[e],"active")}setSnippetsBarVisible(e){this.config.showSnippetsBar=e,this.drawSnippetsBar()}getSnippetsBarVisible(){return this.config.showSnippetsBar&&this.config.snippets.length>0}refreshSnippetsBar(){this.drawSnippetsBar(),this.snippetsResizeHandler&&this.snippetsResizeHandler()}enableCompleter(e){return Tr.Autocompleters[e]?(this.config.autocompleters.indexOf(e)<0&&this.config.autocompleters.push(e),(this.autocompleters[e]=new Gy(this,Tr.Autocompleters[e])).initialize()):Promise.reject(new Error("Autocompleter "+e+" is not a registered autocompleter"))}disableCompleter(e){this.config.autocompleters=this.config.autocompleters.filter(r=>r!==e),this.autocompleters[e]=void 0}autocomplete(e=!1){if(!this.getDoc().somethingSelected())for(let r in this.config.autocompleters){let n=this.autocompleters[this.config.autocompleters[r]];!n||n.autocomplete(e)}}collapsePrefixes(e=!0){let r=aM(this);r!==void 0&&this.foldCode(r,Sh.fold.prefix,e?"fold":"unfold")}getPrefixesFromQuery(){return uM(this)}addPrefixes(e){return cM(this,e)}removePrefixes(e){return hM(this,e)}updateWidget(){if(this.cursorCoords&&this.state.completionActive&&this.state.completionActive.widget){let e=this.cursorCoords(null).bottom;this.state.completionActive.widget.hints.style.top=e+"px"}}query(e){return this.config.queryingDisabled?Promise.reject("Querying is disabled."):(this.persistentConfig?.autoformatOnQuery&&this.format(),this.abortQuery(),tT(this,e))}getUrlParams(){let e={};return window.location.hash.length>1&&(e=Ly.parse(location.hash)),(!e||!("query"in e))&&window.location.search.length>1&&(e=Ly.parse(window.location.search)),e}configToQueryParams(){var e={};return window.location.hash.length>1&&(e=Ly.parse(window.location.hash)),e.query=this.getValue(),e}queryParamsToConfig(e){e&&e.query&&typeof e.query=="string"&&this.setValue(e.query)}getAsCurlString(e){return nT(this,e)}getAsPowerShellString(e){return sT(this,e)}getAsWgetString(e){return oT(this,e)}hasAuthenticationCredentials(e){let r=wp(this,e);return r?rT(r):!1}abortQuery(){this.req&&(this.abortController&&this.abortController.abort(),this.emit("queryAbort",this,this.req))}expandEditor(){this.setSize(null,"100%")}destroy(){this.abortQuery(),this.closeMapPopupHandler?.(),this.unregisterEventListeners(),this.horizontalResizeWrapper?.removeEventListener("mousedown",this.initDrag,!1),this.horizontalResizeWrapper?.removeEventListener("dblclick",this.expandEditor),this.snippetsClickHandler&&(document.removeEventListener("click",this.snippetsClickHandler),this.snippetsClickHandler=void 0);for(let e in this.autocompleters)this.disableCompleter(e);window.removeEventListener("hashchange",this.handleHashChange),this.rootEl.remove()}static clearStorage(){new Zo(Tr.storageNamespace).removeNamespace()}static registerAutocompleter(e,r=!0){let n=e.name;Tr.Autocompleters[n]=e,r&&Tr.defaults.autocompleters.indexOf(n)<0&&Tr.defaults.autocompleters.push(n)}static forkAutocompleter(e,r,n=!0){if(!Tr.Autocompleters[e])throw new Error("Autocompleter "+e+" does not exist");if(!r?.name)throw new Error("Expected a name for newly registered autocompleter");let s=r.name;Tr.Autocompleters[s]={...Tr.Autocompleters[e],...r},n&&Tr.defaults.autocompleters.indexOf(s)<0&&Tr.defaults.autocompleters.push(s)}};Tr.storageNamespace="triply",Tr.Sparql=aT,Tr.runMode=Sh.runMode,Tr.Autocompleters={},Tr.defaults=gT();var Ib=Tr;Object.assign(Sh.prototype,Ib.prototype);LM.forEach(i=>{Ib.registerAutocompleter(i)});var ml=Ib;function ET(){return{autofocus:!0,endpointInfo:void 0,persistenceId:function(i){var t="",e=i.rootEl;for(e.id&&(t=e.id);e&&e!==document;e=e.parentNode)if(e){e.id&&(t=e.id);break}return"yagui_"+t},tabName:"Query",persistencyExpire:60*60*24*30,persistenceLabelResponse:"response",persistenceLabelConfig:"config",yasqe:ml.defaults,yasr:ao.defaults,theme:void 0,showThemeToggle:!0,orientation:"vertical",showSnippetsBar:!0,endpointButtons:void 0,endpointCatalogueOptions:{getData:()=>[{endpoint:"https://dbpedia.org/sparql"},{endpoint:"https://query.wikidata.org/bigdata/namespace/wdq/sparql"}],keys:[],renderItem:(i,t)=>{let e=document.createElement("div");e.style.display="flex",e.style.flexDirection="column";let r=document.createElement("span");r.innerHTML=i.matches.endpoint?.reduce((n,s)=>s.highlight?n+s.text.bold():n+s.text,"")||"",e.appendChild(r),t.appendChild(e)}},copyEndpointOnNewTab:!0,populateFromUrl:!0,autoAddOnInit:!0,requestConfig:ml.defaults.requestConfig,contextMenuContainer:void 0}}var Ak="triply";function P$(){return{endpointHistory:[],tabs:[],active:void 0,tabConfig:{},lastClosedTab:void 0,prefixes:"",autoCaptureEnabled:!0,customEndpointButtons:[],endpointConfigs:[],workspaces:[],activeWorkspaceId:void 0}}var Up=class i{constructor(t){this.yasgui=t,this.storageId=this.yasgui.getStorageId(this.yasgui.config.persistenceLabelConfig),this.storage=new Zo(Ak),this.fromStorage(),this.registerListeners()}setActive(t){this.persistedJson.active=t,this.toStorage()}getActiveId(){return this.persistedJson.active}addToTabList(t,e){e!==void 0&&this.persistedJson.tabs.length>e?this.persistedJson.tabs.splice(e,0,t):this.persistedJson.tabs.push(t),this.toStorage()}setTabOrder(t){this.persistedJson.tabs=t,this.toStorage()}getEndpointHistory(){return this.persistedJson.endpointHistory}retrieveLastClosedTab(){let t=this.persistedJson.lastClosedTab;return t===void 0||(this.persistedJson.lastClosedTab=void 0),t}hasLastClosedTab(){return!!this.persistedJson.lastClosedTab}deleteTab(t){let e=this.persistedJson.tabs.indexOf(t);e>-1&&this.persistedJson.tabs.splice(e,1),this.tabIsActive(t)&&(this.persistedJson.active=void 0),this.persistedJson.lastClosedTab={index:e,tab:this.persistedJson.tabConfig[t]},delete this.persistedJson.tabConfig[t],this.toStorage()}registerListeners(){this.yasgui.on("tabChange",(t,e)=>{this.persistedJson.tabConfig[e.getId()]=e.getPersistedJson(),this.toStorage()}),this.yasgui.on("endpointHistoryChange",(t,e)=>{this.persistedJson.endpointHistory=e,this.toStorage()})}toStorage(){this.storage.set(this.storageId,this.persistedJson,this.yasgui.config.persistencyExpire,this.handleLocalStorageQuotaFull)}fromStorage(){return this.persistedJson=this.storage.get(this.storageId)||P$(),this.persistedJson.endpointHistory||(this.persistedJson.endpointHistory=[]),this.persistedJson}handleLocalStorageQuotaFull(t){console.warn("Localstorage quota exceeded. Clearing all YASGUI configurations"),i.clear()}getTabs(){return this.persistedJson.tabs}getTab(t){return this.persistedJson.tabConfig[t]}setTab(t,e){this.persistedJson.tabs.push(t),this.persistedJson.tabConfig[t]=e,this.persistedJson.active=t}tabIsActive(t){return t===this.persistedJson.active}currentId(){return this.persistedJson.active}getPrefixes(){return this.persistedJson.prefixes||""}setPrefixes(t){this.persistedJson.prefixes=t,this.toStorage()}getAutoCaptureEnabled(){return this.persistedJson.autoCaptureEnabled!==!1}setAutoCaptureEnabled(t){this.persistedJson.autoCaptureEnabled=t,this.toStorage()}getCustomEndpointButtons(){return this.persistedJson.customEndpointButtons||[]}setCustomEndpointButtons(t){this.persistedJson.customEndpointButtons=t,this.toStorage()}getShowSnippetsBar(){return this.persistedJson.showSnippetsBar}setShowSnippetsBar(t){this.persistedJson.showSnippetsBar=t,this.toStorage()}getCodeMirrorTheme(t){return t==="dark"?this.persistedJson.codeMirrorThemeDark:this.persistedJson.codeMirrorThemeLight}setCodeMirrorTheme(t,e){t==="dark"?this.persistedJson.codeMirrorThemeDark=e:this.persistedJson.codeMirrorThemeLight=e,this.toStorage()}getEndpointConfigs(){return this.persistedJson.endpointConfigs||[]}setEndpointConfigs(t){this.persistedJson.endpointConfigs=t,this.toStorage()}addOrUpdateEndpoint(t,e){let r=this.getEndpointConfigs(),n=r.findIndex(s=>s.endpoint===t);if(n>=0){let s={...r[n],...e};"authentication"in e&&e.authentication===void 0&&delete s.authentication,r[n]=s}else r.push({endpoint:t,...e});this.setEndpointConfigs(r)}getEndpointConfig(t){return this.getEndpointConfigs().find(r=>r.endpoint===t)}deleteEndpointConfig(t){let r=this.getEndpointConfigs().filter(n=>n.endpoint!==t);this.setEndpointConfigs(r)}getWorkspaces(){return this.persistedJson.workspaces||[]}getWorkspace(t){return this.getWorkspaces().find(e=>e.id===t)}setWorkspaces(t){this.persistedJson.workspaces=t,this.toStorage()}addOrUpdateWorkspace(t){let e=this.getWorkspaces(),r=e.findIndex(s=>s.id===t.id),n=new Date().toISOString();if(r>=0){let s=e[r];e[r]={...s,...t,createdAt:s.createdAt||t.createdAt||n,updatedAt:n}}else e.push({...t,createdAt:t.createdAt||n,updatedAt:n});this.setWorkspaces(e)}deleteWorkspace(t){let r=this.getWorkspaces().filter(n=>n.id!==t);this.setWorkspaces(r),this.getActiveWorkspaceId()===t&&this.setActiveWorkspaceId(void 0)}getActiveWorkspaceId(){return this.persistedJson.activeWorkspaceId}setActiveWorkspaceId(t){this.persistedJson.activeWorkspaceId=t,this.toStorage()}static clear(){new Zo(Ak).removeNamespace()}getPersistedConfig(){return this.persistedJson}updatePersistedConfig(t){Object.assign(this.persistedJson,t),this.toStorage()}getDisabledDevButtons(){return this.persistedJson.disabledDevButtons||[]}setDisabledDevButtons(t){this.persistedJson.disabledDevButtons=t,this.toStorage()}toggleDevButton(t,e){let r=this.getDisabledDevButtons();if(e){let n=r.filter(s=>s!==t);this.setDisabledDevButtons(n)}else r.includes(t)||(r.push(t),this.setDisabledDevButtons(r))}};var Kk=ki(fC());var q$="https://yasgui.matdata.eu/ontology#",K$="http://www.w3.org/1999/02/22-rdf-syntax-ns#",$$="http://www.w3.org/2000/01/rdf-schema#",eee="http://www.w3.org/2001/XMLSchema#",tee="http://purl.org/dc/terms/",iee="http://www.w3.org/ns/sparql-service-description#",ree="http://spinrdf.org/sp#",nee="http://www.w3.org/2011/http#",see="https://schema.org/";function mk(i){let t=[];t.push(`@prefix yasgui: <${q$}> .`),t.push(`@prefix rdf: <${K$}> .`),t.push(`@prefix rdfs: <${$$}> .`),t.push(`@prefix xsd: <${eee}> .`),t.push(`@prefix dcterms: <${tee}> .`),t.push(`@prefix sd: <${iee}> .`),t.push(`@prefix sp: <${ree}> .`),t.push(`@prefix http: <${nee}> .`),t.push(`@prefix schema: <${see}> .`),t.push("");let e=new Date().toISOString();if(t.push("[] a yasgui:Configuration ;"),t.push(` dcterms:created "${e}"^^xsd:dateTime ;`),i.theme&&t.push(` yasgui:theme "${i.theme}" ;`),i.orientation&&t.push(` yasgui:orientation "${i.orientation}" ;`),i.endpointHistory&&i.endpointHistory.length>0&&(t.push(" yasgui:endpointHistory ("),i.endpointHistory.forEach(r=>{t.push(` "${Wo(r)}"`)}),t.push(" ) ;")),i.active&&t.push(` yasgui:activeTab "${Wo(i.active)}" ;`),i.prefixes&&t.push(` yasgui:prefixesValue """${Wo(i.prefixes)}""" ;`),i.autoCaptureEnabled!==void 0&&t.push(` yasgui:autoCaptureEnabled "${i.autoCaptureEnabled}"^^xsd:boolean ;`),i.customEndpointButtons&&i.customEndpointButtons.length>0&&(t.push(" yasgui:customEndpointButton ["),i.customEndpointButtons.forEach((r,n)=>{let s=n===i.customEndpointButtons.length-1;t.push(` rdfs:label "${Wo(r.label)}" ;`),t.push(` sd:endpoint "${Wo(r.endpoint)}"${s?"":" ;"}`),s||t.push(" ] , [")}),t.push(" ] ;")),i.tabs&&i.tabs.length>0)t.push(" yasgui:tab ["),i.tabs.forEach((r,n)=>{let s=i.tabConfig[r],a=n===i.tabs.length-1;if(t.push(` dcterms:identifier "${Wo(r)}" ;`),t.push(` rdfs:label "${Wo(s.name)}" ;`),s.orientation&&t.push(` yasgui:orientation "${Wo(s.orientation)}" ;`),s.yasqe?.value&&t.push(` sp:text """${Wo(s.yasqe.value)}""" ;`),s.yasqe?.editorHeight&&t.push(` schema:height "${Wo(s.yasqe.editorHeight)}" ;`),s.requestConfig){let h=s.requestConfig;h.endpoint&&typeof h.endpoint=="string"&&t.push(` sd:endpoint "${Wo(h.endpoint)}" ;`),h.method&&typeof h.method=="string"&&t.push(` yasgui:requestMethod "${Wo(h.method)}" ;`),h.acceptHeaderSelect&&typeof h.acceptHeaderSelect=="string"&&(t.push(" yasgui:acceptHeaderSelect ["),t.push(' http:headerName "Accept" ;'),t.push(` http:headerValue "${Wo(h.acceptHeaderSelect)}"`),t.push(" ] ;")),h.acceptHeaderGraph&&typeof h.acceptHeaderGraph=="string"&&(t.push(" yasgui:acceptHeaderGraph ["),t.push(' http:headerName "Accept" ;'),t.push(` http:headerValue "${Wo(h.acceptHeaderGraph)}"`),t.push(" ] ;"))}if(s.yasr?.settings){let h=s.yasr.settings;h.selectedPlugin&&t.push(` yasgui:selectedPlugin "${Wo(h.selectedPlugin)}" ;`)}let d=t[t.length-1];d.endsWith(" ;")&&(t[t.length-1]=d.slice(0,-2)),a||t.push(" ] , [")}),t.push(" ] .");else{let r=t[t.length-1];r.endsWith(" ;")&&(t[t.length-1]=r.slice(0,-2)+" .")}return t.join(`
124
124
  `)}function Wo(i){return i.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}function id(i){return i.replace(/\\n/g,`
125
- `).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}function bk(i){let t={endpointHistory:[],tabs:[],tabConfig:{},customEndpointButtons:[]};try{let e=i.match(/yasgui:endpointHistory\s*\(([\s\S]*?)\)/);if(e){let V=e[1].match(/"([^"]*)"/g);V&&(t.endpointHistory=V.map(Z=>id(Z.slice(1,-1))))}let r=i.match(/yasgui:activeTab\s+"([^"]*)"/);r&&(t.active=id(r[1]));let n=i.match(/yasgui:prefixesValue\s+"""([\s\S]*?)"""/);n&&(t.prefixes=id(n[1]));let s=i.match(/yasgui:autoCaptureEnabled\s+"([^"]*)"/);s&&(t.autoCaptureEnabled=s[1]==="true");let a=i.match(/yasgui:theme\s+"([^"]*)"/);a&&(a[1]==="light"||a[1]==="dark")&&(t.theme=a[1]);let d=i.match(/yasgui:orientation\s+"([^"]*)"/);d&&(d[1]==="vertical"||d[1]==="horizontal")&&(t.orientation=d[1]);let h=/yasgui:customEndpointButton\s+\[([\s\S]*?)rdfs:label\s+"([^"]*)"\s*;\s*sd:endpoint\s+"([^"]*)"/g,A;for(;(A=h.exec(i))!==null;)t.customEndpointButtons.push({label:id(A[2]),endpoint:id(A[3])});let y=/dcterms:identifier\s+"([^"]*)"\s*;\s*rdfs:label\s+"([^"]*)"\s*;[\s\S]*?(?=dcterms:identifier|yasgui:customEndpointButton|\]\.|\]\s*,\s*\[)/g,E=i.match(/yasgui:tab\s+\[([\s\S]*)\]\s*\./);if(E){let V=E[1],Z=[...V.matchAll(/dcterms:identifier\s+"([^"]*)"/g)],S=[...V.matchAll(/rdfs:label\s+"([^"]*)"/g)],Q=[...V.matchAll(/sp:text\s+"""([\s\S]*?)"""/g)],M=[...V.matchAll(/sd:endpoint\s+"([^"]*)"/g)],Y=[...V.matchAll(/yasgui:requestMethod\s+"([^"]*)"/g)],H=[...V.matchAll(/yasgui:orientation\s+"([^"]*)"/g)];Z.forEach((K,q)=>{let ne=id(K[1]),ee=S[q]?id(S[q][1]):"Query",le=Q[q]?id(Q[q][1]):"",pe=M[q]?id(M[q][1]):"",Ce=Y[q]?id(Y[q][1]):"POST",Ee=H[q]?id(H[q][1]):void 0;t.tabs.push(ne),t.tabConfig[ne]={id:ne,name:ee,yasqe:{value:le},requestConfig:{queryArgument:void 0,endpoint:pe,method:Ce,acceptHeaderGraph:"text/turtle",acceptHeaderSelect:"application/sparql-results+json",acceptHeaderUpdate:"application/sparql-results+json",namedGraphs:[],defaultGraphs:[],args:[],headers:{},withCredentials:!1,adjustQueryBeforeRequest:!1,basicAuth:void 0,bearerAuth:void 0,apiKeyAuth:void 0,oauth2Auth:void 0},yasr:{settings:{},response:void 0},orientation:Ee}})}}catch(e){throw console.error("Error parsing Turtle configuration:",e),new Error("Failed to parse configuration. Please check the format.")}return t}function vk(i,t="yasgui-config.ttl"){let e=mk(i),r=new Blob([e],{type:"text/turtle;charset=utf-8"}),n=URL.createObjectURL(r),s=document.createElement("a");s.href=n,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(n)}async function yk(i){let t=mk(i);try{await navigator.clipboard.writeText(t)}catch{let r=document.createElement("textarea");r.value=t,r.style.position="fixed",r.style.left="-999999px",document.body.appendChild(r),r.select();try{document.execCommand("copy")}finally{document.body.removeChild(r)}}}function xT(i){return new Promise((t,e)=>{let r=new FileReader;r.onload=n=>{n.target?.result?t(n.target.result):e(new Error("Failed to read file"))},r.onerror=()=>e(new Error("Failed to read file")),r.readAsText(i)})}async function Rk(){try{return await navigator.clipboard.readText()}catch{throw new Error("Failed to read from clipboard. Please paste the content manually.")}}var Ek="5.19.1";function NT(i){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",e=crypto.getRandomValues(new Uint8Array(i));return Array.from(e).map(r=>t[r%t.length]).join("")}async function aee(i){let e=new TextEncoder().encode(i),r=await crypto.subtle.digest("SHA-256",e);return lee(r)}function lee(i){let t=new Uint8Array(i),e="";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Yy(i){return i?Date.now()>=i-6e4:!0}async function Nk(i){let t=NT(128),e=await aee(t),r=NT(32),n=NT(16);sessionStorage.setItem(`oauth2_code_verifier_${n}`,t),sessionStorage.setItem(`oauth2_state_${n}`,r);let s=new URL(i.authorizationEndpoint);s.searchParams.set("client_id",i.clientId),s.searchParams.set("response_type","code"),s.searchParams.set("redirect_uri",i.redirectUri),s.searchParams.set("code_challenge",e),s.searchParams.set("code_challenge_method","S256"),s.searchParams.set("state",`${r}:${n}`),i.scope&&s.searchParams.set("scope",i.scope);let a=600,d=700,h=window.screenX+(window.outerWidth-a)/2,A=window.screenY+(window.outerHeight-d)/2,y=window.open(s.toString(),"OAuth2 Authorization",`width=${a},height=${d},left=${h},top=${A},popup=yes,scrollbars=yes`);if(!y)throw new Error("Failed to open OAuth 2.0 authorization popup. Please allow popups for this site.");return new Promise((E,V)=>{let Z=!1,S=()=>{clearInterval(Q),window.removeEventListener("message",M),sessionStorage.removeItem(`oauth2_code_verifier_${n}`),sessionStorage.removeItem(`oauth2_state_${n}`)},Q=setInterval(()=>{try{if(y.closed){Z||(Z=!0,S(),V(new Error("OAuth 2.0 authorization was cancelled")));return}try{let Y=y.location.href;if(Y.startsWith(i.redirectUri)&&!Z){Z=!0,S(),y.close();let H=new URL(Y),K=H.searchParams.get("code"),q=H.searchParams.get("state"),ne=H.searchParams.get("error"),ee=H.searchParams.get("error_description");if(ne){V(new Error(`OAuth 2.0 error: ${ne}${ee?" - "+ee:""}`));return}if(!K){V(new Error("No authorization code received"));return}let le=`${r}:${n}`;if(q!==le){V(new Error("State mismatch - possible CSRF attack"));return}xk(i,K,t).then(E).catch(V)}}catch{}}catch{}},500),M=Y=>{if(Y.data&&Y.data.type==="oauth2_callback"&&!Z){Z=!0,S(),y&&!y.closed&&y.close();let{code:H,state:K,error:q,error_description:ne}=Y.data;if(q){V(new Error(`OAuth 2.0 error: ${q}${ne?" - "+ne:""}`));return}if(!H){V(new Error("No authorization code received"));return}let ee=`${r}:${n}`;if(K!==ee){V(new Error("State mismatch - possible CSRF attack"));return}xk(i,H,t).then(E).catch(V)}};window.addEventListener("message",M),setTimeout(()=>{Z||(Z=!0,S(),y&&!y.closed&&y.close(),V(new Error("OAuth 2.0 authorization timeout")))},5*60*1e3)})}async function xk(i,t,e){let r=i.tokenEndpoint,n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",t),n.set("redirect_uri",i.redirectUri),n.set("client_id",i.clientId),n.set("code_verifier",e);try{let s=await fetch(r,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n.toString()});if(!s.ok){let d=await s.text();throw new Error(`Token exchange failed: ${s.status} ${s.statusText} - ${d}`)}return await s.json()}catch(s){throw s}}async function Oy(i,t){let e=i.tokenEndpoint,r=new URLSearchParams;r.set("grant_type","refresh_token"),r.set("refresh_token",t),r.set("client_id",i.clientId);try{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r.toString()});if(!n.ok){let a=await n.text();throw new Error(`Token refresh failed: ${n.status} ${n.statusText} - ${a}`)}return await n.json()}catch(n){throw n}}function KC(i){if(i)return Date.now()+i*1e3}function TT(i){let t=i.split(`
125
+ `).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}function bk(i){let t={endpointHistory:[],tabs:[],tabConfig:{},customEndpointButtons:[]};try{let e=i.match(/yasgui:endpointHistory\s*\(([\s\S]*?)\)/);if(e){let V=e[1].match(/"([^"]*)"/g);V&&(t.endpointHistory=V.map(Z=>id(Z.slice(1,-1))))}let r=i.match(/yasgui:activeTab\s+"([^"]*)"/);r&&(t.active=id(r[1]));let n=i.match(/yasgui:prefixesValue\s+"""([\s\S]*?)"""/);n&&(t.prefixes=id(n[1]));let s=i.match(/yasgui:autoCaptureEnabled\s+"([^"]*)"/);s&&(t.autoCaptureEnabled=s[1]==="true");let a=i.match(/yasgui:theme\s+"([^"]*)"/);a&&(a[1]==="light"||a[1]==="dark")&&(t.theme=a[1]);let d=i.match(/yasgui:orientation\s+"([^"]*)"/);d&&(d[1]==="vertical"||d[1]==="horizontal")&&(t.orientation=d[1]);let h=/yasgui:customEndpointButton\s+\[([\s\S]*?)rdfs:label\s+"([^"]*)"\s*;\s*sd:endpoint\s+"([^"]*)"/g,A;for(;(A=h.exec(i))!==null;)t.customEndpointButtons.push({label:id(A[2]),endpoint:id(A[3])});let y=/dcterms:identifier\s+"([^"]*)"\s*;\s*rdfs:label\s+"([^"]*)"\s*;[\s\S]*?(?=dcterms:identifier|yasgui:customEndpointButton|\]\.|\]\s*,\s*\[)/g,E=i.match(/yasgui:tab\s+\[([\s\S]*)\]\s*\./);if(E){let V=E[1],Z=[...V.matchAll(/dcterms:identifier\s+"([^"]*)"/g)],S=[...V.matchAll(/rdfs:label\s+"([^"]*)"/g)],Q=[...V.matchAll(/sp:text\s+"""([\s\S]*?)"""/g)],M=[...V.matchAll(/sd:endpoint\s+"([^"]*)"/g)],Y=[...V.matchAll(/yasgui:requestMethod\s+"([^"]*)"/g)],H=[...V.matchAll(/yasgui:orientation\s+"([^"]*)"/g)];Z.forEach((K,q)=>{let ne=id(K[1]),ee=S[q]?id(S[q][1]):"Query",le=Q[q]?id(Q[q][1]):"",pe=M[q]?id(M[q][1]):"",Ce=Y[q]?id(Y[q][1]):"POST",Ee=H[q]?id(H[q][1]):void 0;t.tabs.push(ne),t.tabConfig[ne]={id:ne,name:ee,yasqe:{value:le},requestConfig:{queryArgument:void 0,endpoint:pe,method:Ce,acceptHeaderGraph:"text/turtle",acceptHeaderSelect:"application/sparql-results+json",acceptHeaderUpdate:"application/sparql-results+json",namedGraphs:[],defaultGraphs:[],args:[],headers:{},withCredentials:!1,adjustQueryBeforeRequest:!1,basicAuth:void 0,bearerAuth:void 0,apiKeyAuth:void 0,oauth2Auth:void 0},yasr:{settings:{},response:void 0},orientation:Ee}})}}catch(e){throw console.error("Error parsing Turtle configuration:",e),new Error("Failed to parse configuration. Please check the format.")}return t}function vk(i,t="yasgui-config.ttl"){let e=mk(i),r=new Blob([e],{type:"text/turtle;charset=utf-8"}),n=URL.createObjectURL(r),s=document.createElement("a");s.href=n,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(n)}async function yk(i){let t=mk(i);try{await navigator.clipboard.writeText(t)}catch{let r=document.createElement("textarea");r.value=t,r.style.position="fixed",r.style.left="-999999px",document.body.appendChild(r),r.select();try{document.execCommand("copy")}finally{document.body.removeChild(r)}}}function xT(i){return new Promise((t,e)=>{let r=new FileReader;r.onload=n=>{n.target?.result?t(n.target.result):e(new Error("Failed to read file"))},r.onerror=()=>e(new Error("Failed to read file")),r.readAsText(i)})}async function Rk(){try{return await navigator.clipboard.readText()}catch{throw new Error("Failed to read from clipboard. Please paste the content manually.")}}var Ek="5.20.0";function NT(i){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",e=crypto.getRandomValues(new Uint8Array(i));return Array.from(e).map(r=>t[r%t.length]).join("")}async function aee(i){let e=new TextEncoder().encode(i),r=await crypto.subtle.digest("SHA-256",e);return lee(r)}function lee(i){let t=new Uint8Array(i),e="";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Yy(i){return i?Date.now()>=i-6e4:!0}async function Nk(i){let t=NT(128),e=await aee(t),r=NT(32),n=NT(16);sessionStorage.setItem(`oauth2_code_verifier_${n}`,t),sessionStorage.setItem(`oauth2_state_${n}`,r);let s=new URL(i.authorizationEndpoint);s.searchParams.set("client_id",i.clientId),s.searchParams.set("response_type","code"),s.searchParams.set("redirect_uri",i.redirectUri),s.searchParams.set("code_challenge",e),s.searchParams.set("code_challenge_method","S256"),s.searchParams.set("state",`${r}:${n}`),i.scope&&s.searchParams.set("scope",i.scope);let a=600,d=700,h=window.screenX+(window.outerWidth-a)/2,A=window.screenY+(window.outerHeight-d)/2,y=window.open(s.toString(),"OAuth2 Authorization",`width=${a},height=${d},left=${h},top=${A},popup=yes,scrollbars=yes`);if(!y)throw new Error("Failed to open OAuth 2.0 authorization popup. Please allow popups for this site.");return new Promise((E,V)=>{let Z=!1,S=()=>{clearInterval(Q),window.removeEventListener("message",M),sessionStorage.removeItem(`oauth2_code_verifier_${n}`),sessionStorage.removeItem(`oauth2_state_${n}`)},Q=setInterval(()=>{try{if(y.closed){Z||(Z=!0,S(),V(new Error("OAuth 2.0 authorization was cancelled")));return}try{let Y=y.location.href;if(Y.startsWith(i.redirectUri)&&!Z){Z=!0,S(),y.close();let H=new URL(Y),K=H.searchParams.get("code"),q=H.searchParams.get("state"),ne=H.searchParams.get("error"),ee=H.searchParams.get("error_description");if(ne){V(new Error(`OAuth 2.0 error: ${ne}${ee?" - "+ee:""}`));return}if(!K){V(new Error("No authorization code received"));return}let le=`${r}:${n}`;if(q!==le){V(new Error("State mismatch - possible CSRF attack"));return}xk(i,K,t).then(E).catch(V)}}catch{}}catch{}},500),M=Y=>{if(Y.data&&Y.data.type==="oauth2_callback"&&!Z){Z=!0,S(),y&&!y.closed&&y.close();let{code:H,state:K,error:q,error_description:ne}=Y.data;if(q){V(new Error(`OAuth 2.0 error: ${q}${ne?" - "+ne:""}`));return}if(!H){V(new Error("No authorization code received"));return}let ee=`${r}:${n}`;if(K!==ee){V(new Error("State mismatch - possible CSRF attack"));return}xk(i,H,t).then(E).catch(V)}};window.addEventListener("message",M),setTimeout(()=>{Z||(Z=!0,S(),y&&!y.closed&&y.close(),V(new Error("OAuth 2.0 authorization timeout")))},5*60*1e3)})}async function xk(i,t,e){let r=i.tokenEndpoint,n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",t),n.set("redirect_uri",i.redirectUri),n.set("client_id",i.clientId),n.set("code_verifier",e);try{let s=await fetch(r,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n.toString()});if(!s.ok){let d=await s.text();throw new Error(`Token exchange failed: ${s.status} ${s.statusText} - ${d}`)}return await s.json()}catch(s){throw s}}async function Oy(i,t){let e=i.tokenEndpoint,r=new URLSearchParams;r.set("grant_type","refresh_token"),r.set("refresh_token",t),r.set("client_id",i.clientId);try{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r.toString()});if(!n.ok){let a=await n.text();throw new Error(`Token refresh failed: ${n.status} ${n.statusText} - ${a}`)}return await n.json()}catch(n){throw n}}function KC(i){if(i)return Date.now()+i*1e3}function TT(i){let t=i.split(`
126
126
  `),e=new Set,r=[];for(let n of t){let s=n.trim();if(!s)continue;let a=s.match(/^\s*PREFIX\s+(\w*):\s*<([^>]+)>\s*$/i);if(a){let d=a[1].toLowerCase();e.has(d)||(e.add(d),r.push(s))}else r.push(s)}return r.join(`
127
127
  `)}function Cb(i){return!!i&&i.trim().length>0}function ZT(i){let t=[];if(Cb(i.id)||t.push("Workspace id is required"),Cb(i.label)||t.push("Workspace label is required"),i.type==="git"){Cb(i.remoteUrl)||t.push("Git remote URL is required"),typeof i.rootPath!="string"&&t.push("Git rootPath must be a string"),(!i.auth||i.auth.type!=="pat")&&t.push("Git auth is required");let e=i;e.provider&&!["auto","github","gitlab","bitbucket","gitea"].includes(e.provider)&&t.push("Git provider must be one of: auto, github, gitlab, bitbucket, gitea"),e.apiBaseUrl&&typeof e.apiBaseUrl!="string"&&t.push("Git apiBaseUrl must be a string")}return i.type==="sparql"&&(Cb(i.endpoint)||t.push("SPARQL endpoint is required"),Cb(i.workspaceIri)||t.push("Workspace IRI is required")),{valid:t.length===0,errors:t}}var Yt=class extends Error{constructor(t,e){super(e||t),this.name="WorkspaceBackendError",this.code=t}};function Xy(i){return typeof i=="object"&&i!==null&&i.name==="WorkspaceBackendError"}function kn(i){return Xy(i)?i:i instanceof Error?new Yt("UNKNOWN",i.message):new Yt("UNKNOWN",String(i))}function bl(i){let t=i.trim();if(!t)throw new Error("Filename is required");let e=t.toLowerCase();return e.endsWith(".rq")||e.endsWith(".sparql")?t:`${t}.rq`}function Tk(i){return i.replace(/\.git$/i,"")}function Zk(i){return i.replace(/^\/+/,"")}function Vk(i){return i.replace(/\/+$/,"")}function Fk(i){let t=new URL(i),e=t.hostname.toLowerCase(),r=Tk(Vk(Zk(t.pathname)));if(!r)throw new Error("Invalid git remote URL (missing path)");return{host:e,repoPath:r}}function dee(i){let t=/^([^@]+)@([^:]+):(.+)$/.exec(i);if(!t||!t[2]||!t[3])throw new Error("Invalid SCP-like git remote URL");let e=String(t[2]).toLowerCase(),r=Tk(Vk(Zk(String(t[3]))));if(!r)throw new Error("Invalid git remote URL (missing path)");return{host:e,repoPath:r}}function Qn(i){let t=i.trim();if(!t)throw new Error("Remote URL is empty");return/^(https?|ssh):\/\//i.test(t)?Fk(t):/^[^@]+@[^:]+:.+/.test(t)?dee(t):Fk(t)}var Sp=class{constructor(t,e){this.config=t;this.client=e;this.type="git"}missingClientError(){return new Yt("UNKNOWN",`No GitProviderClient configured for remote '${this.config.remoteUrl}'. Supported providers: GitHub, GitLab, Bitbucket Cloud (bitbucket.org), and Gitea. For self-hosted/enterprise instances, set git workspace 'provider' and/or 'apiBaseUrl'.`)}async validateAccess(){if(!this.client)throw this.missingClientError();return this.client.validateAccess(this.config)}async listFolder(t){if(!this.client)throw this.missingClientError();return this.client.listFolder(this.config,t)}async readQuery(t){if(!this.client)throw this.missingClientError();return this.client.readQuery(this.config,t)}async writeQuery(t,e,r){if(!this.client)throw this.missingClientError();return this.client.writeQuery(this.config,t,e,r)}async listVersions(t){if(!this.client)throw this.missingClientError();return this.client.listVersions(this.config,t)}async readVersion(t,e){if(!this.client)throw this.missingClientError();return this.client.readVersion(this.config,t,e)}async deleteQuery(t){if(!this.client)throw this.missingClientError();return this.client.deleteQuery(this.config,t)}async moveQuery(t,e){if(!this.client)throw this.missingClientError();let r=t.split("/").filter(Boolean),n=r[r.length-1]||t,s=e.replace(/^\/+|\/+$/g,""),a=s?`${s}/${n}`:n;if(a===t)return t;let d=await this.client.readQuery(this.config,t);return await this.client.writeQuery(this.config,a,d.queryText,{message:`Move ${n} to ${s||"(root)"}`}),await this.client.deleteQuery(this.config,t),a}async renameQuery(t,e){if(!this.client)throw this.missingClientError();let r=(e||"").trim();if(!r)throw new Yt("UNKNOWN","New name is required");let n=t.split("/").filter(Boolean),s=n.pop()||t,a=n.join("/"),d=r.replace(/[\\/]/g,"-"),h=bl(d),A=a?`${a}/${h}`:h;if(A===t)return;let y=await this.client.readQuery(this.config,t);await this.client.writeQuery(this.config,A,y.queryText,{message:`Rename ${s} to ${h}`}),await this.client.deleteQuery(this.config,t)}getQueryUri(t){try{let{host:e,repoPath:r}=Qn(this.config.remoteUrl),n=r.split("/").filter(Boolean),[s,a]=n;if(!s||!a)return;let d=[this.config.rootPath,t].filter(Boolean).join("/"),h=this.config.branch?.trim()||"HEAD",A=this.config.provider;return A==="github"||(!A||A==="auto")&&(e==="github.com"||e.includes("github")&&!e.includes("gitlab"))?`https://${e}/${s}/${a}/blob/${encodeURIComponent(h)}/${d}`:A==="gitlab"||(!A||A==="auto")&&(e==="gitlab.com"||e.includes("gitlab"))?`https://${e}/${r}/-/blob/${encodeURIComponent(h)}/${d}`:A==="bitbucket"||(!A||A==="auto")&&e==="bitbucket.org"?`https://bitbucket.org/${s}/${a}/src/${encodeURIComponent(h)}/${d}`:`https://${e}/${s}/${a}/src/branch/${encodeURIComponent(h)}/${d}`}catch{return}}};function kh(i){return i.replace(/\r\n/g,`
128
128
  `).trim()}function aa(i){let t=kh(i),e=2166136261;for(let r=0;r<t.length;r++)e^=t.charCodeAt(r),e=e*16777619>>>0;return e.toString(16).padStart(8,"0")}function Wk(i){return i.replace(/\/+$/,"")}function wk(i){return i.split("/").filter(Boolean)}function gee(){return new Date().toISOString()}function rd(i){return`"${i.replace(/\\/g,"\\\\").replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\"/g,'\\"')}"`}function di(i){let t=i.trim();if(!t)throw new Error("IRI is required");return`<${t.replace(/>/g,"%3E")}>`}function cee(){let i=globalThis.crypto;if(i?.randomUUID)return i.randomUUID();let t=new Uint8Array(16);if(i?.getRandomValues)i.getRandomValues(t);else for(let r=0;r<t.length;r++)t[r]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;let e=Array.from(t,r=>r.toString(16).padStart(2,"0")).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}function hee(i){return`${i.trim()}_mq_v_${cee()}`}function uee(i){return/^[a-z][a-z0-9+.-]*:/i.test(i.trim())}function xc(i,t){return`${Wk(i)}/folder/${encodeURIComponent(t)}`}function Dy(i,t){let r=`${Wk(i)}/folder/`;if(!t.startsWith(r))return;let n=t.slice(r.length);try{return decodeURIComponent(n)}catch{return}}function Gk(i,t){return i===401?new Yt("AUTH_FAILED",t||"Authentication failed"):i===403?new Yt("FORBIDDEN",t||"Forbidden"):i===404?new Yt("NOT_FOUND",t||"Not found"):i===409?new Yt("CONFLICT",t||"Conflict"):i===429?new Yt("RATE_LIMITED",t||"Rate limited"):i>=500?new Yt("NETWORK_ERROR",t||"Server error"):new Yt("UNKNOWN",t||`HTTP ${i}`)}var Qh=class{constructor(t,e){this.config=t;this.options=e;this.type="sparql"}async resolveAuthHeaders(){try{let t=await this.options?.getAuthHeaders?.();if(t)return t}catch(t){console.error("Failed to resolve SPARQL auth headers",t)}return this.options?.authHeaders||{}}async sparqlQuery(t){let e=new URLSearchParams;e.set("query",t),this.config.defaultGraph&&e.set("default-graph-uri",this.config.defaultGraph);let r=await this.resolveAuthHeaders(),n;try{n=await fetch(this.config.endpoint,{method:"POST",headers:{Accept:"application/sparql-results+json","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",...r},body:e.toString()})}catch(s){throw new Yt("NETWORK_ERROR",s instanceof Error?s.message:String(s))}if(!n.ok){let s=await n.text().catch(()=>"");throw Gk(n.status,s||`SPARQL endpoint responded with ${n.status}`)}try{return await n.json()}catch(s){throw new Yt("UNKNOWN",s instanceof Error?s.message:"Invalid SPARQL JSON response")}}async sparqlUpdate(t){let e=new URLSearchParams;e.set("update",t),this.config.defaultGraph&&e.set("default-graph-uri",this.config.defaultGraph);let r=await this.resolveAuthHeaders(),n;try{n=await fetch(this.config.endpoint,{method:"POST",headers:{Accept:"application/sparql-results+json, */*","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",...r},body:e.toString()})}catch(s){throw new Yt("NETWORK_ERROR",s instanceof Error?s.message:String(s))}if(!n.ok){let s=await n.text().catch(()=>"");throw Gk(n.status,s||`SPARQL endpoint responded with ${n.status}`)}}getBindings(t){return t?.results?.bindings||[]}folderIriFromId(t){return t?xc(this.config.workspaceIri,t):this.config.workspaceIri}resolveManagedQueryIri(t){let e=t.trim();if(!e)throw new Yt("UNKNOWN","Query ID is required");if(uee(e))return e;throw new Yt("UNKNOWN","SPARQL managed query IDs must be IRIs")}async validateAccess(){await this.sparqlQuery("SELECT (1 AS ?ok) WHERE {} LIMIT 1")}async listFolder(t){let e=this.config.workspaceIri,r=this.folderIriFromId(t),n=t?`?folder skos:broader ${di(r)} .`:"FILTER(!BOUND(?parent))",s=`