sol-components 2.2.0 → 2.2.2

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # Solid Web Components
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/sol-components)](https://www.npmjs.com/package/sol-components)
4
+
3
5
  ## This is a Work In Progress!
4
6
 
5
7
  See the <a href="https://jeff-zucker.github.io/sol-components/">help pages</a> for details.
@@ -14,6 +14,11 @@
14
14
  // row (+ a `sol-select` event on change); anything else → nothing is rendered and
15
15
  // the W3C SPARQL 1.1 Query Results JSON is left on `el.swcData` for you to use.
16
16
  //
17
+ // When the results land, the host fires a `sol-data-ready` event (bubbles/composed,
18
+ // detail.data = the W3C JSON), so a custom element or page can react on the event
19
+ // instead of reading el.swcData:
20
+ // el.addEventListener('sol-data-ready', (e) => render(e.detail.data.results.bindings));
21
+ //
17
22
  // Config attributes (endpoint, pattern, sparql, query, var-<name>) may be written
18
23
  // bare OR `data-`-prefixed (data-endpoint, …, data-var-<name>) to keep the markup
19
24
  // spec-valid HTML; bare wins if both are given. `data-from-query` is the trigger.
@@ -118,20 +123,40 @@ function fillSelect(el, vars, rows) {
118
123
  }
119
124
  }
120
125
 
121
- // The host's tag picks the shape. Unknown tags render nothing the W3C JSON is
122
- // left on `el.swcData` for the page to consume.
126
+ // While the query runs, show a loading indicator IN the host, shaped to its tag
127
+ // (a <li> in a list, an <option> in a select, else a <div>). aria-live announces it.
128
+ function setLoading(el) {
129
+ const tag = el.localName;
130
+ let node;
131
+ if (tag === 'ul' || tag === 'ol') node = document.createElement('li');
132
+ else if (tag === 'select') { node = document.createElement('option'); node.disabled = true; node.selected = true; }
133
+ else { node = document.createElement('div'); node.setAttribute('role', 'status'); }
134
+ node.className = 'swc-loading';
135
+ node.setAttribute('aria-live', 'polite');
136
+ node.textContent = 'Loading…';
137
+ el.replaceChildren(node);
138
+ }
139
+
140
+ // The host's tag picks the shape. Unknown tags render nothing into the DOM — the
141
+ // W3C JSON is left on `el.swcData` for the page to consume. Either way, when the
142
+ // results land we fire a `sol-data-ready` event (detail.data = the W3C JSON) so a
143
+ // custom element / page can react without polling el.swcData.
123
144
  function renderInto(el, data) {
124
145
  el.swcData = data;
125
146
  const vars = data.head.vars;
126
147
  const rows = data.results.bindings;
127
148
  const tag = el.localName;
128
- if (tag === 'ul' || tag === 'ol') return fillList(el, vars, rows);
129
- if (tag === 'select') return fillSelect(el, vars, rows);
130
- // anything else: leave the DOM untouched; the JSON is on el.swcData.
149
+ if (tag === 'ul' || tag === 'ol') fillList(el, vars, rows);
150
+ else if (tag === 'select') fillSelect(el, vars, rows);
151
+ else el.replaceChildren(); // clear the loading indicator
152
+ el.dispatchEvent(new CustomEvent('sol-data-ready', {
153
+ bubbles: true, composed: true, detail: { data: data },
154
+ }));
131
155
  }
132
156
 
133
157
  activate('[data-from-query]', (el) => {
134
158
  if (el.localName === 'sol-query') return; // the element handles itself
159
+ setLoading(el);
135
160
  buildData(el)
136
161
  .then((data) => renderInto(el, data))
137
162
  .catch((e) => { el.innerHTML = `<div class="error">${(e && e.message) || e}</div>`; console.error('[data-from-query]', e); });
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "sol-components",
3
-
3
+ "attributes": {
4
+ "data-from-query": "sol-components/core/from-query.js",
5
+ "data-handler": "sol-components/core/handler.js",
6
+ "data-edit-shape data-from-rdf": "rdf-bundle"
7
+ },
8
+ "objects": {
9
+ "provides": {
10
+ "store": {
11
+ "service": "rdf",
12
+ "sendValue": "store"
13
+ },
14
+ "auth": {
15
+ "service": "auth",
16
+ "sendValue": "fetch"
17
+ },
18
+ "navigation": {
19
+ "respondTo": "sol-navigate",
20
+ "sendValue": "detail.url"
21
+ }
22
+ },
23
+ "consumes": {
24
+ "store": {
25
+ "call": "rdf.useStore"
26
+ },
27
+ "auth": {
28
+ "call": "adoptFetch"
29
+ }
30
+ },
31
+ "accepts": {
32
+ "navigation": {
33
+ "onElement": "sol-query",
34
+ "applyValueTo": "endpoint"
35
+ }
36
+ }
37
+ },
38
+ "bundles": {
39
+ "rdf-bundle": [
40
+ "solid-logic",
41
+ "solid-ui",
42
+ "sol-tree-edit",
43
+ "sol-form",
44
+ "sol-settings",
45
+ "sol-components/core/edit-placements.js",
46
+ "sol-components/core/from-rdf.js"
47
+ ]
48
+ },
4
49
  "stages": {
5
50
  "local": {
6
51
  "components": {
@@ -104,38 +149,5 @@
104
149
  "sol-components/": "https://esm.sh/sol-components/web/"
105
150
  }
106
151
  }
107
- },
108
-
109
- "bundles": {
110
- "rdf-bundle": [
111
- "solid-logic",
112
- "solid-ui",
113
- "sol-tree-edit",
114
- "sol-form",
115
- "sol-settings",
116
- "sol-components/core/edit-placements.js",
117
- "sol-components/core/from-rdf.js"
118
- ]
119
- },
120
-
121
- "attributes": {
122
- "data-from-query": "sol-components/core/from-query.js",
123
- "data-handler": "sol-components/core/handler.js",
124
- "data-edit-shape data-from-rdf": "rdf-bundle"
125
- },
126
-
127
- "objects": {
128
- "provides": {
129
- "store": { "service": "rdf", "sendValue": "store" },
130
- "auth": { "service": "auth", "sendValue": "fetch" },
131
- "navigation": { "respondTo": "sol-navigate", "sendValue": "detail.url" }
132
- },
133
- "consumes": {
134
- "store": { "call": "rdf.useStore" },
135
- "auth": { "call": "adoptFetch" }
136
- },
137
- "accepts": {
138
- "navigation": { "onElement": "sol-query", "applyValueTo": "endpoint" }
139
- }
140
152
  }
141
153
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sol-components",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "Web components and Node.js tools for querying, including, and editing RDF/Linked Data on Solid Pods",
5
5
  "type": "module",
6
6
  "exports": {