@opengeospatial/jsonld-ui-utils 0.2.0 → 0.3.0

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,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,34 @@ 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 https://github.com/avillar/jsonld-ui-utils/releases/latest/download/jsonld-ui-utils.tgz
17
+ npm install @opengeospatial/jsonld-ui-utils
19
18
  # or
20
- yarn add https://github.com/avillar/jsonld-ui-utils/releases/latest/download/jsonld-ui-utils.tgz
19
+ yarn add @opengeospatial/jsonld-ui-utils
21
20
  ```
22
21
 
23
- To pin to a specific version, replace `latest/download` with `download/v0.1.6`:
22
+ ### Optional peer dependencies
23
+
24
+ [`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:
24
25
 
25
26
  ```bash
26
- npm install https://github.com/avillar/jsonld-ui-utils/releases/download/v0.1.6/jsonld-ui-utils.tgz
27
+ npm install jsonld
27
28
  ```
28
29
 
29
- > **Note:** [`rdflib`](https://www.npmjs.com/package/rdflib) is a peer dependency and must be installed separately:
30
- > ```bash
31
- > npm install rdflib
32
- > ```
33
-
34
- ### Browser (CDN)
30
+ ### Browser (IIFE)
35
31
 
36
32
  ```html
37
- <script src="https://cdn.jsdelivr.net/npm/rdflib@2.3.0/dist/rdflib.min.js"></script>
38
- <script src="https://github.com/avillar/jsonld-ui-utils/releases/latest/download/jsonld-ui-utils.min.js"></script>
33
+ <!-- optional: library-provided styles -->
34
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@opengeospatial/jsonld-ui-utils@latest/dist/jsonld-ui-utils.css"/>
35
+
36
+ <!-- optional: jsonld peer dep (needed for context URL resolution) -->
37
+ <script src="https://cdn.jsdelivr.net/npm/jsonld@8/dist/jsonld.min.js"></script>
38
+
39
+ <script src="https://cdn.jsdelivr.net/npm/@opengeospatial/jsonld-ui-utils@latest/dist/jsonld-ui-utils.min.js"></script>
39
40
  ```
40
41
 
41
42
  This exposes `jsonldUIUtils` as a global variable.
@@ -45,15 +46,13 @@ This exposes `jsonldUIUtils` as a global variable.
45
46
  ### Quick start
46
47
 
47
48
  ```javascript
48
- import jsonldUIUtils from 'jsonld-ui-utils';
49
+ import { loadFeature, createPropertiesTable, augment } from '@opengeospatial/jsonld-ui-utils';
49
50
 
50
- const { feature, context } = await jsonldUIUtils.loadFeature(
51
- 'https://example.org/features/my-feature.json'
52
- );
51
+ const { feature, context } = await loadFeature('https://example.org/features/my-feature.json');
53
52
 
54
53
  const container = document.getElementById('feature');
55
- jsonldUIUtils.createPropertiesTable(feature, container);
56
- await jsonldUIUtils.augment(container, context);
54
+ createPropertiesTable(feature, container);
55
+ await augment(container, context);
57
56
  ```
58
57
 
59
58
  ### Step by step
@@ -61,7 +60,7 @@ await jsonldUIUtils.augment(container, context);
61
60
  #### 1. Load a JSON-LD feature
62
61
 
63
62
  ```javascript
64
- const { feature, context } = await jsonldUIUtils.loadFeature(featureUrl);
63
+ const { feature, context } = await loadFeature(featureUrl);
65
64
  ```
66
65
 
67
66
  `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 +69,33 @@ const { feature, context } = await jsonldUIUtils.loadFeature(featureUrl);
70
69
 
71
70
  ```javascript
72
71
  const container = document.getElementById('feature');
73
- jsonldUIUtils.createPropertiesTable(feature, container);
72
+ createPropertiesTable(feature, container);
74
73
  ```
75
74
 
76
75
  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
76
 
78
77
  ```javascript
79
- jsonldUIUtils.createPropertiesTable(feature, container, { propertiesField: null });
78
+ createPropertiesTable(feature, container, { propertiesField: null });
80
79
  ```
81
80
 
82
81
  The generated elements carry CSS classes you can style:
83
82
 
84
83
  | Class | Applied to |
85
84
  |---|---|
85
+ | `.object-properties` | Wrapper `<div>` around the top-level table |
86
86
  | `.object-table` | `<table>` elements |
87
87
  | `.object-property` | Property name cells |
88
88
  | `.object-value` | Property value cells |
89
89
  | `.literal-value` | Scalar (non-object) values |
90
90
  | `.array-entry` | Entries within an array value |
91
91
 
92
+ Include `dist/jsonld-ui-utils.css` (or the CDN link above) for default styling of these classes.
93
+
92
94
  #### 3. Augment with semantic metadata
93
95
 
94
96
  ```javascript
95
- await jsonldUIUtils.augment(container, context, {
96
- fallbackSparqlEndpoint: 'https://example.org/sparql',
97
+ await augment(container, context, {
98
+ fallbackSparqlEndpoints: 'https://example.org/sparql',
97
99
  });
98
100
  ```
99
101
 
@@ -114,20 +116,17 @@ During and after augmentation, elements receive additional CSS classes:
114
116
 
115
117
  | Option | Type | Default | Description |
116
118
  |---|---|---|---|
117
- | `propertiesField` | `string \| null` | `'properties'` | Property on `feature` to use as the root object. Set to `null` to use the entire feature. |
119
+ | `propertiesField` | `string` or `null` | `'properties'` | Property on `feature` to use as the root object. Set to `null` to use the entire feature. |
118
120
 
119
121
  #### `augment(rootElem, context, options?)`
120
122
 
121
123
  | Option | Type | Default | Description |
122
124
  |---|---|---|---|
123
125
  | `replaceElements` | `boolean` | `true` | Replace element text with the resolved label. |
124
- | `labelPredicates` | `(NamedNode \| string)[]` | SKOS prefLabel, DCT/DC title, SDO/FOAF name, RDFS label | RDF predicates checked when extracting a label. |
125
- | `descriptionPredicates` | `(NamedNode \| string)[]` | SKOS definition, DCT/DC description, RDFS comment | RDF predicates checked when extracting a description. |
126
- | `fallbackRainbowInstances` | `string \| string[]` | — | One or more RAINBOW proxy base URLs tried in order when a direct fetch returns no label. |
127
- | `fallbackSparqlEndpoints` | `string \| string[]` | — | One or more SPARQL endpoint URLs tried in order as a last resort (`DESCRIBE <uri>`). |
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.
126
+ | `labelPredicates` | `string[]` | SKOS prefLabel, DCT/DC title, SDO/FOAF name, RDFS label | RDF predicates checked when extracting a label. |
127
+ | `descriptionPredicates` | `string[]` | SKOS definition, DCT/DC description, RDFS comment | RDF predicates checked when extracting a description. |
128
+ | `fallbackRainbowInstances` | `string` or `string[]` | — | One or more RAINBOW proxy base URLs tried in order when a direct fetch returns no label. |
129
+ | `fallbackSparqlEndpoints` | `string` or `string[]` | — | One or more SPARQL endpoint URLs tried in order as a last resort (`DESCRIBE <uri>`). |
131
130
 
132
131
  ### Lower-level API
133
132
 
@@ -144,8 +143,8 @@ interface ResourceData {
144
143
  ```
145
144
 
146
145
  ```javascript
147
- const data = await jsonldUIUtils.fetchResource('https://example.org/vocab/MyTerm', {
148
- fallbackSparqlEndpoint: 'https://example.org/sparql',
146
+ const data = await fetchResource('https://example.org/vocab/MyTerm', {
147
+ fallbackSparqlEndpoints: 'https://example.org/sparql',
149
148
  });
150
149
  console.log(data.label); // e.g. "My Term"
151
150
  ```
@@ -155,59 +154,74 @@ console.log(data.label); // e.g. "My Term"
155
154
  Load and merge one or more JSON-LD contexts. Accepts a context object, a URL string, or an array of either:
156
155
 
157
156
  ```javascript
158
- const merged = await jsonldUIUtils.loadContext([
157
+ const merged = await loadContext([
159
158
  'https://example.org/context1.json',
160
159
  'https://example.org/context2.json',
161
160
  ]);
162
161
  ```
163
162
 
164
- ### Named exports
163
+ ---
165
164
 
166
- In addition to the default export you can import individual functions:
165
+ ## Leaflet plugin
166
+
167
+ The Leaflet plugin creates a `L.GeoJSON` layer that automatically renders popup tables for each feature and augments them with RDF metadata.
168
+
169
+ Same package as above — no separate install needed. Import the plugin entry point:
167
170
 
168
171
  ```javascript
169
- import {
170
- createPropertiesTable,
171
- augment,
172
- fetchResource,
173
- loadFeature,
174
- loadContext,
175
- } from 'jsonld-ui-utils';
172
+ import { createJsonLDGeoJSONLayer } from '@opengeospatial/jsonld-ui-utils/leaflet';
176
173
  ```
177
174
 
178
- ## Browser example
175
+ ### Browser (IIFE)
179
176
 
180
177
  ```html
181
- <!DOCTYPE html>
182
- <html>
183
- <head>
184
- <style>
185
- .object-table { border-collapse: collapse; width: 100%; }
186
- .object-property { font-weight: bold; padding: 4px 8px; vertical-align: top; }
187
- .object-value { padding: 4px 8px; }
188
- .resource-resolved { cursor: help; }
189
- </style>
190
- </head>
191
- <body>
192
- <div id="feature"></div>
193
-
194
- <script src="https://cdn.jsdelivr.net/npm/rdflib@2.3.0/dist/rdflib.min.js"></script>
195
- <script src="https://github.com/avillar/jsonld-ui-utils/releases/latest/download/jsonld-ui-utils.min.js"></script>
196
- <script>
197
- jsonldUIUtils
198
- .loadFeature('https://example.org/features/sensor.json')
199
- .then(({ feature, context }) => {
200
- const root = document.getElementById('feature');
201
- jsonldUIUtils.createPropertiesTable(feature, root);
202
- return jsonldUIUtils.augment(root, context, {
203
- fallbackSparqlEndpoint: 'https://example.org/sparql',
204
- });
205
- });
206
- </script>
207
- </body>
208
- </html>
178
+ <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/>
179
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@opengeospatial/jsonld-ui-utils@latest/dist/jsonld-ui-utils.css"/>
180
+
181
+ <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
182
+ <script src="https://cdn.jsdelivr.net/npm/@opengeospatial/jsonld-ui-utils@latest/dist/jsonld-ui-utils-leaflet.min.js"></script>
209
183
  ```
210
184
 
185
+ This exposes `jsonldUIUtilsLeaflet` as a global variable.
186
+
187
+ ### Usage
188
+
189
+ ```javascript
190
+ const layer = jsonldUIUtilsLeaflet.createJsonLDGeoJSONLayer(L, geojsonData, {
191
+ ldContext: 'https://example.org/context.jsonld',
192
+ popupOptions: { maxWidth: 420 },
193
+ augmentOptions: {
194
+ fallbackSparqlEndpoints: 'https://example.org/sparql',
195
+ },
196
+ });
197
+
198
+ layer.addTo(map);
199
+ ```
200
+
201
+ ### Behaviour
202
+
203
+ - Each feature with a non-empty `properties` object gets a popup with a rendered table.
204
+ - If the feature has an `id`, it is shown as a hover tooltip automatically.
205
+ - The popup table is augmented with RDF labels/descriptions when `ldContext` is provided.
206
+
207
+ ### Options (`JsonLDGeoJSONOptions`)
208
+
209
+ | Option | Type | Default | Description |
210
+ |---|---|---|---|
211
+ | `ldContext` | `string`, `object`, or `array` | — | JSON-LD context (URL, object, or array) used to resolve property URIs. |
212
+ | `popupOptions` | `object` | `{ maxWidth: 400 }` | Options passed to Leaflet's `bindPopup`. |
213
+ | `augmentOptions` | `object` | `{}` | Options passed to `augment()` (see above). |
214
+ | `onEachFeature` | `function` | — | Called for every feature before the plugin's own logic, matching Leaflet's `onEachFeature` signature. |
215
+
216
+ Any other options are forwarded to `L.geoJSON`.
217
+
218
+ ---
219
+
220
+ ## Demos
221
+
222
+ - [Basic demo](https://ogcincubator.github.io/jsonld-ui-utils/demo/index.html) — renders a JSON-LD feature as an augmented properties table
223
+ - [Leaflet demo](https://ogcincubator.github.io/jsonld-ui-utils/demo/leaflet.html) — GeoJSON layer with popup tables and RDF augmentation
224
+
211
225
  ## Building from source
212
226
 
213
227
  ```bash