[mod] symlist

This commit is contained in:
Andy Bunce 2025-09-21 22:02:55 +01:00
parent 2a3e962c58
commit 95aed988b6
3 changed files with 67 additions and 52 deletions

View file

@ -17,7 +17,10 @@
<nav class="navbar bg-body-tertiary"> <nav class="navbar bg-body-tertiary">
<div class="container-fluid"> <div class="container-fluid">
<a id="help" class="navbar-brand">XQuery 4.0 LSP client <a id="help" class="navbar-brand">XQuery 4.0 LSP client
<button popovertarget="popHelp"><i class="bi bi-info-circle"></i></button></a> <button id="popcon" popovertarget="popConnect" class="btn btn-danger">
<i class="bi bi-router"></i>
</button>
</a>
<ul class="nav nav-pills"> <ul class="nav nav-pills">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Editor</a> <a class="nav-link active" aria-current="page" href="#">Editor</a>
@ -32,9 +35,7 @@
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a> <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li> </li>
</ul> </ul>
<button id="popcon" popovertarget="popConnect" class="btn btn-danger">
<i class="bi bi-router"></i>
</button>
</div> </div>
</nav> </nav>
</header> </header>
@ -96,8 +97,7 @@
<aside class="page-sidebar"> <aside class="page-sidebar">
<div id="msg">(msgs)</div> <div id="msg">(msgs)</div>
<div class="bg-info">OutLine</div>
<json-list id="symList" style="display:block; overflow:scroll; height: 10em;"></json-list>
<select id="load"> <select id="load">
<option selected value="">load..</option> <option selected value="">load..</option>
<optgroup label="XQuery3"> <optgroup label="XQuery3">
@ -125,6 +125,12 @@
<ul id="traffic" style="overflow: scroll;"> <ul id="traffic" style="overflow: scroll;">
<li>-</li> <li>-</li>
</ul> </ul>
<details style="padding:5px;">
<summary class="bg-info">OutLine <b>0</b></summary>
<json-list id="symList" style="display:block; overflow:scroll; height: 10em;"></json-list>
</details>
</aside> </aside>
<footer class="page-footer"> <footer class="page-footer">
@ -134,6 +140,7 @@
<option value="xquery">xquery</option> <option value="xquery">xquery</option>
<option value="xml">xml</option> <option value="xml">xml</option>
</select> </select>
<button popovertarget="popHelp"><i class="bi bi-info-circle"></i></button></a>
</footer> </footer>
</div> </div>
<!-- Popovers --> <!-- Popovers -->
@ -168,7 +175,7 @@
<script src="./lsp.bundle.js"></script> <script src="./lsp.bundle.js"></script>
<script src="./script.js"></script> <script src="./script.js"></script>
<script src="./list.js"></script> <script src="./list.js"></script>
</body> </body>
</html> </html>

View file

@ -4,59 +4,66 @@ https://stackoverflow.com/questions/50404970/web-components-pass-data-to-and-fro
class JsonListComponent extends HTMLElement { class JsonListComponent extends HTMLElement {
#shadow; #shadow;
#data; #data;
#selected;
constructor() { constructor() {
super(); super();
this.#shadow = this.attachShadow({ mode: "open" }); this.#shadow = this.attachShadow({ mode: "open" });
this.#data = []; this.#data = [];
this.render(); this.render();
} }
setData(newData, append = false) { setData(newData, append = false) {
if (!Array.isArray(newData)) { if (!Array.isArray(newData)) {
console.warn("Invalid format, expected an array."); console.warn("Invalid format, expected an array.");
return; return;
}
this.#data = append ? this.#data.concat(newData) : structuredClone(newData);
this.render();
} }
this.#data = append ? this.#data.concat(newData) : structuredClone(newData); set data(value) {
this.render(); this.setData(value, false);
} }
get data() {
return this.#data;
}
set data(value) { /* Render the list items #data */
this.setData(value, false); render() {
} const list = document.createElement('ul');
get data() { const shad=this.#shadow;
return this.#data; this.#data.forEach((item, index) => {
} const listItem = document.createElement('li');
listItem.textContent = `${item.name} - ${item.description}`;
/* Render the list items using the fetched JSON data */ // Adding a click event listener for user interaction
render() { listItem.addEventListener('click', () => {
const list = document.createElement('ul'); console.log('Item clicked:', item, listItem);
this.#data.forEach(item => { // You can dispatch a custom event here if needed.
const listItem = document.createElement('li'); this.dispatchEvent(new CustomEvent('itemSelected', {
listItem.textContent = `${item.name} - ${item.description}`; detail: item,
// Adding a click event listener for user interaction bubbles: true,
listItem.addEventListener('click', () => { composed: true
console.log('Item clicked:', item); }));
// You can dispatch a custom event here if needed. });
this.dispatchEvent(new CustomEvent('itemSelected', { list.addEventListener('click', function (e) {
detail: item, if (e.target.tagName === 'LI') {
bubbles: true, shad.querySelectorAll('li.selected').forEach(item=>{item.className = '';});
composed: true e.target.className = 'selected';
})); }
});
list.appendChild(listItem);
}); });
list.appendChild(listItem);
}); this.#shadow.innerHTML = '';
this.#shadow.innerHTML = ''; const style = document.createElement('style');
const style = document.createElement('style'); style.textContent = `
style.textContent = `
ul { list-style-type: none; padding: 0; margin: 0; } ul { list-style-type: none; padding: 0; margin: 0; }
li { padding: 10px; border-bottom: 1px solid #ccc; cursor: pointer; } li { padding: 1px; border-bottom: 1px solid #ccc; cursor: pointer; }
li:hover { background: #f0f0f0; } li :not(.selected) :hover { background: #ccc; }
.selected { background: lightgreen;}
`; `;
this.#shadow.appendChild(style); this.#shadow.appendChild(style);
this.#shadow.appendChild(list); this.#shadow.appendChild(list);
} }
/* Render an error message if JSON fetching fails */ /* Render an error message if JSON fetching fails */
renderError(error) { renderError(error) {

View file

@ -88,8 +88,9 @@ $("cmd").onclick = e => {
}; };
$("symList").onclick = e => { $("symList").onclick = e => {
alert("Sym click"); console.log("SYM CLICK");
}; };
$("lint").onclick = async e => { $("lint").onclick = async e => {
console.log("word", view.state.wordAt(1)); console.log("word", view.state.wordAt(1));
lsp.openLintPanel(view); lsp.openLintPanel(view);