sol-components 2.2.0 → 2.2.1
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/README.md +2 -0
- package/core/from-query.js +18 -3
- package/package.json +1 -1
package/README.md
CHANGED
package/core/from-query.js
CHANGED
|
@@ -118,8 +118,22 @@ function fillSelect(el, vars, rows) {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
//
|
|
122
|
-
//
|
|
121
|
+
// While the query runs, show a loading indicator IN the host, shaped to its tag
|
|
122
|
+
// (a <li> in a list, an <option> in a select, else a <div>). aria-live announces it.
|
|
123
|
+
function setLoading(el) {
|
|
124
|
+
const tag = el.localName;
|
|
125
|
+
let node;
|
|
126
|
+
if (tag === 'ul' || tag === 'ol') node = document.createElement('li');
|
|
127
|
+
else if (tag === 'select') { node = document.createElement('option'); node.disabled = true; node.selected = true; }
|
|
128
|
+
else { node = document.createElement('div'); node.setAttribute('role', 'status'); }
|
|
129
|
+
node.className = 'swc-loading';
|
|
130
|
+
node.setAttribute('aria-live', 'polite');
|
|
131
|
+
node.textContent = 'Loading…';
|
|
132
|
+
el.replaceChildren(node);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// The host's tag picks the shape. Unknown tags render nothing into the DOM — the
|
|
136
|
+
// W3C JSON is left on `el.swcData` for the page to consume.
|
|
123
137
|
function renderInto(el, data) {
|
|
124
138
|
el.swcData = data;
|
|
125
139
|
const vars = data.head.vars;
|
|
@@ -127,11 +141,12 @@ function renderInto(el, data) {
|
|
|
127
141
|
const tag = el.localName;
|
|
128
142
|
if (tag === 'ul' || tag === 'ol') return fillList(el, vars, rows);
|
|
129
143
|
if (tag === 'select') return fillSelect(el, vars, rows);
|
|
130
|
-
//
|
|
144
|
+
el.replaceChildren(); // clear the loading indicator; the JSON is on el.swcData
|
|
131
145
|
}
|
|
132
146
|
|
|
133
147
|
activate('[data-from-query]', (el) => {
|
|
134
148
|
if (el.localName === 'sol-query') return; // the element handles itself
|
|
149
|
+
setLoading(el);
|
|
135
150
|
buildData(el)
|
|
136
151
|
.then((data) => renderInto(el, data))
|
|
137
152
|
.catch((e) => { el.innerHTML = `<div class="error">${(e && e.message) || e}</div>`; console.error('[data-from-query]', e); });
|