[fix] catch errs

This commit is contained in:
Andy Bunce 2025-11-03 16:36:30 +00:00
parent 6ff94888ef
commit 4c6570e2b4
2 changed files with 37 additions and 55 deletions

View file

@ -47,31 +47,7 @@
<quiet-icon slot="start" name="link"></quiet-icon>Web
</quiet-button>
<quiet-select id="load" style="width:16em;">
<option selected value="">load..</option>
<optgroup label="XQuery3">
<option
value="https://raw.githubusercontent.com/expkg-zone58/pdfbox/refs/heads/main/src/Pdfbox3.xqm">
Pdfbox3.xqm</option>
<option
value="https://raw.githubusercontent.com/Quodatum/xqdoca/refs/heads/master/src/main/lib/model.xqm">
model.xqm</option>
</optgroup>
<optgroup label="XQuery4">
<option
value="https://git.quodatum.duckdns.org/quodatum/basex-lsp/raw/branch/main/webapp/lsp/lsp-text.xqm">
lsp-text.xqm</option>
<option value="../../../lsp/lsp-text.xqm">
lsp-text.xqm</option>
</optgroup>
<optgroup label="xpath">
<option
value="https://raw.githubusercontent.com/dnovatchev/Articles/refs/heads/main/Generators/Code/generator.xq">
generator.xquery</option>
</optgroup>
</quiet-select>
</quiet-button-group>
<quiet-button-group>
@ -94,7 +70,6 @@
<quiet-toolbar>
<quiet-button-group>
<button id="search" title="Search" type="button"><i class="codicon codicon-search"></i></button>
<button id="lint" title="Display diagnostics" type="button"><i
@ -113,6 +88,7 @@
<button id="cmdList" type="button" title="Command and key mapping help">
<i class="codicon codicon-record-keys"></i>
</button>
<button type="button" popovertarget="popSettings" title="Settings">
<i class="codicon codicon-settings"></i></button>
</quiet-button-group>
@ -122,13 +98,12 @@
<i class="codicon codicon-screen-full"></i>
</button>
<button id="bnSave" type="button" title="save view">
<i class="codicon codicon-git-stash"></i></button>
<button id="bnLoad" type="button" title="load view">
<i class="codicon codicon-git-stash-pop"></i></button>
<button id="bnWordAt" type="button" title="word at">
<i class="codicon codicon-whole-word"></i></button>
@ -201,9 +176,11 @@
</select>
</footer>
</div>
<!-- dialogs -->
<quiet-popover for="popover__url">
<form style="background: #ffecb3;">
<quiet-popover id="popWeb" for="popover__url">
<form id="popUrl" style="background: #ffecb3;">
<quiet-text-field type="url" name="url" label="URL to fetch" placeholder="http://..." with-clear required
style="width: 20em;">
<datalist>
@ -214,8 +191,8 @@
value="https://raw.githubusercontent.com/Quodatum/xqdoca/refs/heads/master/src/main/lib/model.xqm">
model.xqm (Quodatum/xqdoca)</option>
<option
value="https://git.quodatum.duckdns.org/quodatum/basex-lsp/raw/branch/main/webapp/lsp/lsp-text.xqm">
lsp-text.xqm</option>
value="https://git.quodatum.duckdns.org/api/v1/repos/quodatum/basex-lsp/raw/webapp/lsp/lsp-text.xqm">
lsp-text.xqm (quodatum/basex-lsp FORGEIO)</option>
<option
value="https://raw.githubusercontent.com/dnovatchev/Articles/refs/heads/main/Generators/Code/generator.xq">
generator.xquery</option>

View file

@ -42,16 +42,15 @@ $("connect").onclick = e => { e.preventDefault(); connect() };
$("symTrigger").onclick = e => { e.preventDefault(); };
$("symOptions").onclick = e => { e.preventDefault(); };
$("bnNew").onclick = e => {
let name = prompt("New file name?");
let name = prompt("New file name?", "untitled.xq");
if (name === null) return;
alert("TODO")
docSwitch("", name);
};
$("search").onclick = e => lsp.openSearchPanel(view);
$("fullscreen").onclick = e => $("editor").requestFullscreen();
$("bnWordAt").onclick = e => {
let pos = view.state.selection.main.head;
let w = view.state.wordAt(pos);
@ -64,7 +63,6 @@ $("symbols2").onclick = e => {
.then(r => {
console.log("symbols", r)
$("symPanel").open = true;
$("symList").setData(r);
});
};
@ -102,34 +100,30 @@ $("bnLoad").onclick = e => { const v = workspace[iFile]; if (v) view.setState(v)
// select local file
$("bnRead").onclick = e => { $("fileElem").click(); };
$("fileElem").onchange = e => {
let file = e.target.files[0]
let fr = new FileReader();
fr.onload = function () {
alert(fr.result);
}
fr.readAsText(e.target.files[0]);
fr.onload = () => docSwitch(fr.result, file.name);
fr.readAsText(file);
};
$("format").onclick = e => { console.log("FMT", lsp.formatDocument(view)); };
$("load").onchange = e => {
const url = e.target.value;
if (url.length == 0) return
fetch(url)
$("popUrl").onsubmit = e => {
e.preventDefault();
const f = objectFromForm("popUrl");
fetch(f.url)
.then(response => response.text())
.then(t => {
view.dispatch({
changes: {
from: 0,
to: view.state.doc.length,
insert: t
}
})
//client.sync();
//console.log("SYNC");
docSwitch(t, f.url)
$("popWeb").open = false;
})
.catch(error => {
alert("CORS?: " + error)
});
$("load").value = "";
};
$("tConnect").addEventListener('quiet-change', e => {
e.preventDefault();
$("popConnect").showPopover()
@ -185,6 +179,17 @@ function connect() {
};
// change active doc
function docSwitch(text, url) {
view.dispatch({
changes: {
from: 0,
to: view.state.doc.length,
insert: text
}
})
$("iFile").value = url;
};
function incoming(msg) {