@opengeospatial/jsonld-ui-utils 0.2.0 → 0.2.7
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 +96 -74
- package/dist/index.cjs.js +458 -423
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.esm.js +458 -422
- package/dist/index.esm.js.map +1 -1
- package/dist/jsonld-ui-utils-leaflet.min.js +26 -0
- package/dist/jsonld-ui-utils-leaflet.min.js.map +1 -0
- package/dist/jsonld-ui-utils.css +45 -0
- package/dist/jsonld-ui-utils.min.js +4 -49
- package/dist/jsonld-ui-utils.min.js.map +1 -1
- package/dist/jsonld.d.ts +2 -2
- package/dist/leaflet.cjs.js +549 -0
- package/dist/leaflet.cjs.js.map +1 -0
- package/dist/leaflet.d.ts +10 -0
- package/dist/leaflet.esm.js +528 -0
- package/dist/leaflet.esm.js.map +1 -0
- package/dist/resource.d.ts +1 -2
- package/package.json +30 -8
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# jsonld-ui-utils
|
|
1
|
+
# @opengeospatial/jsonld-ui-utils
|
|
2
2
|
|
|
3
3
|
A JavaScript/TypeScript library that renders JSON-LD feature data as interactive HTML tables and enriches them with semantic metadata (labels, descriptions) fetched from RDF sources.
|
|
4
4
|
|
|
@@ -9,33 +9,42 @@ A JavaScript/TypeScript library that renders JSON-LD feature data as interactive
|
|
|
9
9
|
- Fetch RDF metadata (labels, descriptions) for resolved URIs
|
|
10
10
|
- Multiple fallback mechanisms: direct fetch, [RAINBOW](https://github.com/ogcincubator/rainbow) proxy, SPARQL endpoint
|
|
11
11
|
- Built-in caching to avoid redundant network requests
|
|
12
|
+
- [Leaflet](https://leafletjs.com/) plugin for GeoJSON layers with automatic popup tables
|
|
12
13
|
|
|
13
14
|
## Installation
|
|
14
15
|
|
|
15
|
-
This package is not published to npm. Install the latest release directly from GitHub:
|
|
16
|
-
|
|
17
16
|
```bash
|
|
18
|
-
npm install
|
|
17
|
+
npm install github:avillar/jsonld-ui-utils
|
|
19
18
|
# or
|
|
20
|
-
yarn add
|
|
19
|
+
yarn add github:avillar/jsonld-ui-utils
|
|
21
20
|
```
|
|
22
21
|
|
|
23
|
-
To pin to a specific version
|
|
22
|
+
To pin to a specific version:
|
|
24
23
|
|
|
25
24
|
```bash
|
|
26
|
-
npm install
|
|
25
|
+
npm install github:avillar/jsonld-ui-utils#v0.2.7
|
|
26
|
+
# or
|
|
27
|
+
yarn add github:avillar/jsonld-ui-utils#v0.2.7
|
|
27
28
|
```
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
### Optional peer dependencies
|
|
31
|
+
|
|
32
|
+
[`jsonld`](https://www.npmjs.com/package/jsonld) is an optional peer dependency. Install it if you need to fetch and resolve JSON-LD contexts by URL:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install jsonld
|
|
36
|
+
```
|
|
33
37
|
|
|
34
|
-
### Browser (
|
|
38
|
+
### Browser (IIFE)
|
|
35
39
|
|
|
36
40
|
```html
|
|
37
|
-
|
|
38
|
-
<
|
|
41
|
+
<!-- optional: library-provided styles -->
|
|
42
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/avillar/jsonld-ui-utils@v0.2.7/dist/jsonld-ui-utils.css"/>
|
|
43
|
+
|
|
44
|
+
<!-- optional: jsonld peer dep (needed for context URL resolution) -->
|
|
45
|
+
<script src="https://cdn.jsdelivr.net/npm/jsonld@8/dist/jsonld.min.js"></script>
|
|
46
|
+
|
|
47
|
+
<script src="https://cdn.jsdelivr.net/gh/avillar/jsonld-ui-utils@v0.2.7/dist/jsonld-ui-utils.min.js"></script>
|
|
39
48
|
```
|
|
40
49
|
|
|
41
50
|
This exposes `jsonldUIUtils` as a global variable.
|
|
@@ -45,15 +54,13 @@ This exposes `jsonldUIUtils` as a global variable.
|
|
|
45
54
|
### Quick start
|
|
46
55
|
|
|
47
56
|
```javascript
|
|
48
|
-
import
|
|
57
|
+
import { loadFeature, createPropertiesTable, augment } from '@opengeospatial/jsonld-ui-utils';
|
|
49
58
|
|
|
50
|
-
const { feature, context } = await
|
|
51
|
-
'https://example.org/features/my-feature.json'
|
|
52
|
-
);
|
|
59
|
+
const { feature, context } = await loadFeature('https://example.org/features/my-feature.json');
|
|
53
60
|
|
|
54
61
|
const container = document.getElementById('feature');
|
|
55
|
-
|
|
56
|
-
await
|
|
62
|
+
createPropertiesTable(feature, container);
|
|
63
|
+
await augment(container, context);
|
|
57
64
|
```
|
|
58
65
|
|
|
59
66
|
### Step by step
|
|
@@ -61,7 +68,7 @@ await jsonldUIUtils.augment(container, context);
|
|
|
61
68
|
#### 1. Load a JSON-LD feature
|
|
62
69
|
|
|
63
70
|
```javascript
|
|
64
|
-
const { feature, context } = await
|
|
71
|
+
const { feature, context } = await loadFeature(featureUrl);
|
|
65
72
|
```
|
|
66
73
|
|
|
67
74
|
`loadFeature` fetches the document at `featureUrl`, extracts its `@context`, recursively loads and merges any referenced context URLs, and returns both the raw feature object and the resolved context.
|
|
@@ -70,30 +77,33 @@ const { feature, context } = await jsonldUIUtils.loadFeature(featureUrl);
|
|
|
70
77
|
|
|
71
78
|
```javascript
|
|
72
79
|
const container = document.getElementById('feature');
|
|
73
|
-
|
|
80
|
+
createPropertiesTable(feature, container);
|
|
74
81
|
```
|
|
75
82
|
|
|
76
83
|
This builds a nested HTML table structure inside `container`. By default it reads from the `properties` field of the feature object. Pass `propertiesField: null` to use the entire feature object instead:
|
|
77
84
|
|
|
78
85
|
```javascript
|
|
79
|
-
|
|
86
|
+
createPropertiesTable(feature, container, { propertiesField: null });
|
|
80
87
|
```
|
|
81
88
|
|
|
82
89
|
The generated elements carry CSS classes you can style:
|
|
83
90
|
|
|
84
91
|
| Class | Applied to |
|
|
85
92
|
|---|---|
|
|
93
|
+
| `.object-properties` | Wrapper `<div>` around the top-level table |
|
|
86
94
|
| `.object-table` | `<table>` elements |
|
|
87
95
|
| `.object-property` | Property name cells |
|
|
88
96
|
| `.object-value` | Property value cells |
|
|
89
97
|
| `.literal-value` | Scalar (non-object) values |
|
|
90
98
|
| `.array-entry` | Entries within an array value |
|
|
91
99
|
|
|
100
|
+
Include `dist/jsonld-ui-utils.css` (or the CDN link above) for default styling of these classes.
|
|
101
|
+
|
|
92
102
|
#### 3. Augment with semantic metadata
|
|
93
103
|
|
|
94
104
|
```javascript
|
|
95
|
-
await
|
|
96
|
-
|
|
105
|
+
await augment(container, context, {
|
|
106
|
+
fallbackSparqlEndpoints: 'https://example.org/sparql',
|
|
97
107
|
});
|
|
98
108
|
```
|
|
99
109
|
|
|
@@ -114,20 +124,17 @@ During and after augmentation, elements receive additional CSS classes:
|
|
|
114
124
|
|
|
115
125
|
| Option | Type | Default | Description |
|
|
116
126
|
|---|---|---|---|
|
|
117
|
-
| `propertiesField` | `string
|
|
127
|
+
| `propertiesField` | `string` or `null` | `'properties'` | Property on `feature` to use as the root object. Set to `null` to use the entire feature. |
|
|
118
128
|
|
|
119
129
|
#### `augment(rootElem, context, options?)`
|
|
120
130
|
|
|
121
131
|
| Option | Type | Default | Description |
|
|
122
132
|
|---|---|---|---|
|
|
123
133
|
| `replaceElements` | `boolean` | `true` | Replace element text with the resolved label. |
|
|
124
|
-
| `labelPredicates` | `
|
|
125
|
-
| `descriptionPredicates` | `
|
|
126
|
-
| `fallbackRainbowInstances` | `string
|
|
127
|
-
| `fallbackSparqlEndpoints` | `string
|
|
128
|
-
| `acceptedContentTypes` | `object` | Turtle, N-Triples, RDF/XML, anot+Turtle | RDF content types to accept, mapped to `true` or a normalised type string. |
|
|
129
|
-
|
|
130
|
-
> **Note:** The singular aliases `fallbackRainbowInstance` and `fallbackSparqlEndpoint` are still accepted for backward compatibility and behave as a single-element list appended after any values provided via the plural options.
|
|
134
|
+
| `labelPredicates` | `string[]` | SKOS prefLabel, DCT/DC title, SDO/FOAF name, RDFS label | RDF predicates checked when extracting a label. |
|
|
135
|
+
| `descriptionPredicates` | `string[]` | SKOS definition, DCT/DC description, RDFS comment | RDF predicates checked when extracting a description. |
|
|
136
|
+
| `fallbackRainbowInstances` | `string` or `string[]` | — | One or more RAINBOW proxy base URLs tried in order when a direct fetch returns no label. |
|
|
137
|
+
| `fallbackSparqlEndpoints` | `string` or `string[]` | — | One or more SPARQL endpoint URLs tried in order as a last resort (`DESCRIBE <uri>`). |
|
|
131
138
|
|
|
132
139
|
### Lower-level API
|
|
133
140
|
|
|
@@ -144,8 +151,8 @@ interface ResourceData {
|
|
|
144
151
|
```
|
|
145
152
|
|
|
146
153
|
```javascript
|
|
147
|
-
const data = await
|
|
148
|
-
|
|
154
|
+
const data = await fetchResource('https://example.org/vocab/MyTerm', {
|
|
155
|
+
fallbackSparqlEndpoints: 'https://example.org/sparql',
|
|
149
156
|
});
|
|
150
157
|
console.log(data.label); // e.g. "My Term"
|
|
151
158
|
```
|
|
@@ -155,59 +162,74 @@ console.log(data.label); // e.g. "My Term"
|
|
|
155
162
|
Load and merge one or more JSON-LD contexts. Accepts a context object, a URL string, or an array of either:
|
|
156
163
|
|
|
157
164
|
```javascript
|
|
158
|
-
const merged = await
|
|
165
|
+
const merged = await loadContext([
|
|
159
166
|
'https://example.org/context1.json',
|
|
160
167
|
'https://example.org/context2.json',
|
|
161
168
|
]);
|
|
162
169
|
```
|
|
163
170
|
|
|
164
|
-
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Leaflet plugin
|
|
174
|
+
|
|
175
|
+
The Leaflet plugin creates a `L.GeoJSON` layer that automatically renders popup tables for each feature and augments them with RDF metadata.
|
|
165
176
|
|
|
166
|
-
|
|
177
|
+
Same package as above — no separate install needed. Import the plugin entry point:
|
|
167
178
|
|
|
168
179
|
```javascript
|
|
169
|
-
import {
|
|
170
|
-
createPropertiesTable,
|
|
171
|
-
augment,
|
|
172
|
-
fetchResource,
|
|
173
|
-
loadFeature,
|
|
174
|
-
loadContext,
|
|
175
|
-
} from 'jsonld-ui-utils';
|
|
180
|
+
import { createJsonLDGeoJSONLayer } from '@opengeospatial/jsonld-ui-utils/leaflet';
|
|
176
181
|
```
|
|
177
182
|
|
|
178
|
-
|
|
183
|
+
### Browser (IIFE)
|
|
179
184
|
|
|
180
185
|
```html
|
|
181
|
-
|
|
182
|
-
<
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return jsonldUIUtils.augment(root, context, {
|
|
203
|
-
fallbackSparqlEndpoint: 'https://example.org/sparql',
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
</script>
|
|
207
|
-
</body>
|
|
208
|
-
</html>
|
|
186
|
+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/>
|
|
187
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/avillar/jsonld-ui-utils@v0.2.7/dist/jsonld-ui-utils.css"/>
|
|
188
|
+
|
|
189
|
+
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
|
190
|
+
<script src="https://cdn.jsdelivr.net/gh/avillar/jsonld-ui-utils@v0.2.7/dist/jsonld-ui-utils-leaflet.min.js"></script>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
This exposes `jsonldUIUtilsLeaflet` as a global variable.
|
|
194
|
+
|
|
195
|
+
### Usage
|
|
196
|
+
|
|
197
|
+
```javascript
|
|
198
|
+
const layer = jsonldUIUtilsLeaflet.createJsonLDGeoJSONLayer(L, geojsonData, {
|
|
199
|
+
ldContext: 'https://example.org/context.jsonld',
|
|
200
|
+
popupOptions: { maxWidth: 420 },
|
|
201
|
+
augmentOptions: {
|
|
202
|
+
fallbackSparqlEndpoints: 'https://example.org/sparql',
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
layer.addTo(map);
|
|
209
207
|
```
|
|
210
208
|
|
|
209
|
+
### Behaviour
|
|
210
|
+
|
|
211
|
+
- Each feature with a non-empty `properties` object gets a popup with a rendered table.
|
|
212
|
+
- If the feature has an `id`, it is shown as a hover tooltip automatically.
|
|
213
|
+
- The popup table is augmented with RDF labels/descriptions when `ldContext` is provided.
|
|
214
|
+
|
|
215
|
+
### Options (`JsonLDGeoJSONOptions`)
|
|
216
|
+
|
|
217
|
+
| Option | Type | Default | Description |
|
|
218
|
+
|---|---|---|---|
|
|
219
|
+
| `ldContext` | `string`, `object`, or `array` | — | JSON-LD context (URL, object, or array) used to resolve property URIs. |
|
|
220
|
+
| `popupOptions` | `object` | `{ maxWidth: 400 }` | Options passed to Leaflet's `bindPopup`. |
|
|
221
|
+
| `augmentOptions` | `object` | `{}` | Options passed to `augment()` (see above). |
|
|
222
|
+
| `onEachFeature` | `function` | — | Called for every feature before the plugin's own logic, matching Leaflet's `onEachFeature` signature. |
|
|
223
|
+
|
|
224
|
+
Any other options are forwarded to `L.geoJSON`.
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Demos
|
|
229
|
+
|
|
230
|
+
- [Basic demo](https://avillar.github.io/jsonld-ui-utils/demo/index.html) — renders a JSON-LD feature as an augmented properties table
|
|
231
|
+
- [Leaflet demo](https://avillar.github.io/jsonld-ui-utils/demo/leaflet.html) — GeoJSON layer with popup tables and RDF augmentation
|
|
232
|
+
|
|
211
233
|
## Building from source
|
|
212
234
|
|
|
213
235
|
```bash
|