@opengeospatial/jsonld-ui-utils 0.4.11 → 0.5.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 +17 -4
- package/dist/augment.d.ts +2 -0
- package/dist/context.d.ts +21 -0
- package/dist/index.cjs.js +527 -253
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.esm.js +527 -254
- package/dist/index.esm.js.map +1 -1
- package/dist/jsonld-ui-utils-leaflet.min.js +4 -4
- package/dist/jsonld-ui-utils-leaflet.min.js.map +1 -1
- package/dist/jsonld-ui-utils.css +31 -1
- package/dist/jsonld-ui-utils.min.js +4 -4
- package/dist/jsonld-ui-utils.min.js.map +1 -1
- package/dist/jsonld.d.ts +14 -1
- package/dist/leaflet.cjs.js +544 -260
- package/dist/leaflet.cjs.js.map +1 -1
- package/dist/leaflet.d.ts +6 -0
- package/dist/leaflet.esm.js +544 -260
- package/dist/leaflet.esm.js.map +1 -1
- package/dist/requests.d.ts +11 -0
- package/dist/resource.d.ts +10 -0
- package/dist/sparql-batch.d.ts +7 -0
- package/package.json +4 -2
package/dist/leaflet.esm.js
CHANGED
|
@@ -2,11 +2,22 @@ import * as N3 from 'n3';
|
|
|
2
2
|
import { RdfXmlParser } from 'rdfxml-streaming-parser';
|
|
3
3
|
import proj4Lib from 'proj4';
|
|
4
4
|
|
|
5
|
-
const jsonFetch = async (url) => {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const jsonFetch = async (url, timeout) => {
|
|
6
|
+
const controller = new AbortController();
|
|
7
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
8
|
+
try {
|
|
9
|
+
const response = await fetch(url, {
|
|
10
|
+
headers: { 'Accept': 'application/json' },
|
|
11
|
+
signal: controller.signal,
|
|
12
|
+
});
|
|
13
|
+
if (!response.ok) {
|
|
14
|
+
throw new Error(`HTTP error ${response.status} loading context ${url}`);
|
|
15
|
+
}
|
|
16
|
+
return await response.json();
|
|
17
|
+
}
|
|
18
|
+
finally {
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
}
|
|
10
21
|
};
|
|
11
22
|
const mergeContexts = (definitions) => {
|
|
12
23
|
const mergePair = (a, b) => {
|
|
@@ -32,49 +43,78 @@ const mergeContexts = (definitions) => {
|
|
|
32
43
|
return currentContext;
|
|
33
44
|
};
|
|
34
45
|
const urlCache = new Map();
|
|
35
|
-
|
|
36
|
-
|
|
46
|
+
const resolveUrl = (url, baseUrl) => {
|
|
47
|
+
try {
|
|
48
|
+
return new URL(url, baseUrl).toString();
|
|
49
|
+
}
|
|
50
|
+
catch (_a) {
|
|
51
|
+
return url;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Loads a context without merging its entries. Remote references are replaced by their contents,
|
|
56
|
+
* including the scoped contexts of term definitions, which are modified in place.
|
|
57
|
+
*/
|
|
58
|
+
async function loadContextEntries(context, options = {}) {
|
|
59
|
+
const { requestTimeout = 10000 } = options;
|
|
60
|
+
const walk = async (definition, refChain, baseUrl) => {
|
|
37
61
|
for (const [key, value] of Object.entries(definition)) {
|
|
38
62
|
if (key === '@context') {
|
|
63
|
+
const entries = await load(value, refChain, baseUrl);
|
|
39
64
|
// @ts-ignore
|
|
40
|
-
definition[key] =
|
|
65
|
+
definition[key] = entries.length === 1 ? entries[0] : entries;
|
|
41
66
|
}
|
|
42
67
|
else if (typeof value === 'object' && value !== null) {
|
|
43
|
-
await walk(value, refChain);
|
|
68
|
+
await walk(value, refChain, baseUrl);
|
|
44
69
|
}
|
|
45
70
|
}
|
|
46
71
|
};
|
|
47
|
-
const load = async (context, refChain) => {
|
|
48
|
-
if (context ===
|
|
49
|
-
return
|
|
72
|
+
const load = async (context, refChain, baseUrl) => {
|
|
73
|
+
if (context === undefined) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
if (context === null) {
|
|
77
|
+
return [null];
|
|
50
78
|
}
|
|
51
79
|
if (Array.isArray(context)) {
|
|
52
|
-
|
|
53
|
-
const contextEntries = await Promise.all(context.map(e => load(e, refChain)));
|
|
54
|
-
return mergeContexts(contextEntries);
|
|
80
|
+
return (await Promise.all(context.map(e => load(e, refChain, baseUrl)))).flat();
|
|
55
81
|
}
|
|
56
|
-
|
|
57
|
-
await walk(context, refChain);
|
|
58
|
-
return context;
|
|
82
|
+
if (typeof context === 'object') {
|
|
83
|
+
await walk(context, refChain, baseUrl);
|
|
84
|
+
return [context];
|
|
59
85
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
86
|
+
const url = resolveUrl(context, baseUrl);
|
|
87
|
+
if (refChain === null || refChain === void 0 ? void 0 : refChain.includes(url)) {
|
|
88
|
+
throw new Error('Circular dependencies found: ' + refChain.join(' -> ') + ' -> ' + url);
|
|
89
|
+
}
|
|
90
|
+
const newRefChain = [...(refChain !== null && refChain !== void 0 ? refChain : []), url];
|
|
91
|
+
if (!urlCache.has(url)) {
|
|
92
|
+
// Relative references inside a remote context are resolved against that context's own URL
|
|
93
|
+
const request = jsonFetch(url, requestTimeout).then(async (obj) => {
|
|
94
|
+
const entries = await load(obj['@context'], newRefChain, url);
|
|
95
|
+
// @base is ignored in remote contexts
|
|
96
|
+
return entries.map(entry => {
|
|
97
|
+
if (!entry) {
|
|
98
|
+
return entry;
|
|
99
|
+
}
|
|
100
|
+
const { '@base': _, ...loaded } = entry;
|
|
101
|
+
return loaded;
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
// Failures are not cached, so that they can be retried
|
|
105
|
+
request.catch(() => urlCache.delete(url));
|
|
106
|
+
urlCache.set(url, request);
|
|
70
107
|
}
|
|
108
|
+
return urlCache.get(url);
|
|
71
109
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
110
|
+
return load(context, undefined, options.baseUrl);
|
|
111
|
+
}
|
|
112
|
+
async function loadContext(context, options = {}) {
|
|
113
|
+
const unwrapped = typeof context === 'object' && context !== null && '@context' in context
|
|
114
|
+
? context['@context']
|
|
115
|
+
: context;
|
|
116
|
+
const entries = await loadContextEntries(unwrapped, options);
|
|
117
|
+
return mergeContexts(entries.map(entry => entry !== null && entry !== void 0 ? entry : {}));
|
|
78
118
|
}
|
|
79
119
|
|
|
80
120
|
const ns = (base) => (local) => `${base}${local}`;
|
|
@@ -99,9 +139,106 @@ const descriptionPredicates = [
|
|
|
99
139
|
RDFS('comment'),
|
|
100
140
|
];
|
|
101
141
|
|
|
142
|
+
// Limits how many HTTP requests run at once, across all lookups
|
|
143
|
+
let active = 0;
|
|
144
|
+
const waiting = [];
|
|
145
|
+
function startWaiting() {
|
|
146
|
+
while (waiting.length && active < waiting[0].limit) {
|
|
147
|
+
active++;
|
|
148
|
+
waiting.shift().start();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Runs a task holding one request slot. The task must pass the signal to fetch() and include reading
|
|
153
|
+
* the response body, so that the slot is held (and the timeout applies) until the request is done.
|
|
154
|
+
*/
|
|
155
|
+
async function withRequestSlot(task, { limit, timeout, priority = false }) {
|
|
156
|
+
await new Promise(start => {
|
|
157
|
+
// Priority requests queue up behind earlier priority ones, ahead of everything else
|
|
158
|
+
const firstNormal = priority ? waiting.findIndex(entry => !entry.priority) : -1;
|
|
159
|
+
waiting.splice(firstNormal < 0 ? waiting.length : firstNormal, 0, { limit: Math.max(1, limit), priority, start });
|
|
160
|
+
startWaiting();
|
|
161
|
+
});
|
|
162
|
+
const controller = new AbortController();
|
|
163
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
164
|
+
try {
|
|
165
|
+
return await task(controller.signal);
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
clearTimeout(timer);
|
|
169
|
+
active--;
|
|
170
|
+
startWaiting();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Collects URIs into one DESCRIBE query per endpoint. A batch is sent when the first of these happens:
|
|
175
|
+
// it is full, no earlier lookup is pending (so nothing else can join soon), or MAX_WAIT has passed.
|
|
176
|
+
const MAX_WAIT = 500;
|
|
177
|
+
const batches = {};
|
|
178
|
+
let pendingLookups = 0;
|
|
179
|
+
let idleCheckScheduled = false;
|
|
180
|
+
// Deferred, so that URIs arriving in the same burst end up in the same batch
|
|
181
|
+
function scheduleIdleCheck() {
|
|
182
|
+
if (idleCheckScheduled) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
idleCheckScheduled = true;
|
|
186
|
+
setTimeout(() => {
|
|
187
|
+
idleCheckScheduled = false;
|
|
188
|
+
if (!pendingLookups) {
|
|
189
|
+
Object.values(batches).forEach(batch => batch.send());
|
|
190
|
+
}
|
|
191
|
+
}, 0);
|
|
192
|
+
}
|
|
193
|
+
/** Tracks the lookup stages that run before SPARQL, and can therefore still feed a batch */
|
|
194
|
+
async function trackLookup(lookup) {
|
|
195
|
+
pendingLookups++;
|
|
196
|
+
try {
|
|
197
|
+
return await lookup();
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
pendingLookups--;
|
|
201
|
+
scheduleIdleCheck();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Characters not allowed inside <...> in SPARQL: one such URI would break the query for its whole batch
|
|
205
|
+
const isQueryableIri = (uri) => /^[a-z][a-z0-9+.-]*:[^\u0000- <>"{}|^`\\]*$/i.test(uri);
|
|
206
|
+
function createBatch(endpoint, sendQuery) {
|
|
207
|
+
const uris = [];
|
|
208
|
+
let resolve;
|
|
209
|
+
const result = new Promise(r => resolve = r);
|
|
210
|
+
const batch = {
|
|
211
|
+
uris,
|
|
212
|
+
result,
|
|
213
|
+
send() {
|
|
214
|
+
clearTimeout(timer);
|
|
215
|
+
delete batches[endpoint];
|
|
216
|
+
resolve(sendQuery(`DESCRIBE ${uris.map(uri => `<${uri}>`).join(' ')}`));
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
const timer = setTimeout(batch.send, MAX_WAIT);
|
|
220
|
+
return batch;
|
|
221
|
+
}
|
|
222
|
+
/** Resolves with the response to the query that included this URI */
|
|
223
|
+
function describeInBatch(endpoint, uri, batchSize, sendQuery) {
|
|
224
|
+
var _a;
|
|
225
|
+
const batch = (_a = batches[endpoint]) !== null && _a !== void 0 ? _a : (batches[endpoint] = createBatch(endpoint, sendQuery));
|
|
226
|
+
batch.uris.push(uri);
|
|
227
|
+
if (batch.uris.length >= batchSize) {
|
|
228
|
+
batch.send();
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
scheduleIdleCheck();
|
|
232
|
+
}
|
|
233
|
+
return batch.result;
|
|
234
|
+
}
|
|
235
|
+
|
|
102
236
|
const defaultFetchResourceOptions = {
|
|
103
237
|
labelPredicates,
|
|
104
238
|
descriptionPredicates,
|
|
239
|
+
maxConcurrentRequests: 6,
|
|
240
|
+
sparqlBatchSize: 50,
|
|
241
|
+
requestTimeout: 10000,
|
|
105
242
|
};
|
|
106
243
|
const fetchResourceCache = {};
|
|
107
244
|
const requestCache = {};
|
|
@@ -181,8 +318,11 @@ function parseTurtle(text, baseIRI, contentType) {
|
|
|
181
318
|
});
|
|
182
319
|
}
|
|
183
320
|
async function parseJsonLd(text, baseIRI) {
|
|
184
|
-
|
|
185
|
-
|
|
321
|
+
var _a;
|
|
322
|
+
// jsonld is CommonJS: a dynamic import usually exposes it as the default export
|
|
323
|
+
const imported = await import('jsonld');
|
|
324
|
+
const jsonldMod = (_a = imported.default) !== null && _a !== void 0 ? _a : imported;
|
|
325
|
+
if (!(jsonldMod === null || jsonldMod === void 0 ? void 0 : jsonldMod.toRDF)) {
|
|
186
326
|
throw new Error('jsonld peer dependency is not available');
|
|
187
327
|
}
|
|
188
328
|
const doc = JSON.parse(text);
|
|
@@ -201,39 +341,41 @@ async function parseRdfXml(text, baseIRI) {
|
|
|
201
341
|
});
|
|
202
342
|
}
|
|
203
343
|
const toArray = (val) => !val ? [] : Array.isArray(val) ? val : [val];
|
|
204
|
-
const
|
|
205
|
-
const fetchAndParse = async (fetchFn, baseIRI) => {
|
|
206
|
-
var _a;
|
|
207
|
-
let response;
|
|
344
|
+
const fetchAndParse = async (url, init, baseIRI, options, priority = false) => {
|
|
208
345
|
try {
|
|
209
|
-
|
|
210
|
-
|
|
346
|
+
// The slot covers reading the body, but not parsing it
|
|
347
|
+
const received = await withRequestSlot(async (signal) => {
|
|
348
|
+
var _a;
|
|
349
|
+
const response = await fetch(url, { ...init, signal });
|
|
350
|
+
if (!response.ok) {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
contentType: ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0].trim()) || 'text/turtle',
|
|
355
|
+
text: await response.text(),
|
|
356
|
+
};
|
|
357
|
+
}, { limit: options.maxConcurrentRequests, timeout: options.requestTimeout, priority });
|
|
358
|
+
if (!received) {
|
|
211
359
|
return null;
|
|
212
360
|
}
|
|
213
|
-
|
|
214
|
-
catch (_b) {
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
const contentType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0].trim()) || 'text/turtle';
|
|
218
|
-
const text = await response.text();
|
|
219
|
-
try {
|
|
361
|
+
const { contentType, text } = received;
|
|
220
362
|
if (N3_CONTENT_TYPES.has(contentType)) {
|
|
221
|
-
return parseTurtle(text, baseIRI, contentType);
|
|
363
|
+
return await parseTurtle(text, baseIRI, contentType);
|
|
222
364
|
}
|
|
223
365
|
if (contentType === 'application/ld+json') {
|
|
224
|
-
return parseJsonLd(text, baseIRI);
|
|
366
|
+
return await parseJsonLd(text, baseIRI);
|
|
225
367
|
}
|
|
226
368
|
if (contentType === 'application/rdf+xml') {
|
|
227
|
-
return parseRdfXml(text, baseIRI);
|
|
369
|
+
return await parseRdfXml(text, baseIRI);
|
|
228
370
|
}
|
|
229
371
|
}
|
|
230
|
-
catch (
|
|
372
|
+
catch (_a) {
|
|
231
373
|
}
|
|
232
374
|
return null;
|
|
233
375
|
};
|
|
234
|
-
const fetchAndParseDocument = (docUrl,
|
|
376
|
+
const fetchAndParseDocument = (docUrl, options, baseIRI = docUrl) => {
|
|
235
377
|
if (!(docUrl in requestCache)) {
|
|
236
|
-
requestCache[docUrl] = fetchAndParse(
|
|
378
|
+
requestCache[docUrl] = fetchAndParse(docUrl, { headers: { 'Accept': ACCEPT_HEADER } }, baseIRI, options);
|
|
237
379
|
}
|
|
238
380
|
return requestCache[docUrl];
|
|
239
381
|
};
|
|
@@ -260,17 +402,20 @@ const findResourceInStore = async (storePromise, uri, options) => {
|
|
|
260
402
|
}
|
|
261
403
|
return null;
|
|
262
404
|
};
|
|
263
|
-
|
|
405
|
+
// Direct dereferencing and RAINBOW proxies: one request per URI (or per document)
|
|
406
|
+
const lookupByRequest = async (uri, options) => {
|
|
264
407
|
const docUrl = uri.includes('#') ? uri.split('#')[0] : uri;
|
|
265
|
-
// 1. Direct (cached by document URL so hash siblings share one request).
|
|
408
|
+
// 1. Direct, only for HTTP(S) URIs (cached by document URL so hash siblings share one request).
|
|
266
409
|
// On an https:// page, an http:// URI is tried as https:// first (the http:// request would be blocked).
|
|
267
410
|
let result = null;
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
411
|
+
if (/^https?:/i.test(uri)) {
|
|
412
|
+
const httpsDocUrl = toHttpsIfMixedContent(docUrl);
|
|
413
|
+
if (httpsDocUrl) {
|
|
414
|
+
result = await findResourceInStore(fetchAndParseDocument(httpsDocUrl, options, docUrl), uri, options);
|
|
415
|
+
}
|
|
416
|
+
if (!result) {
|
|
417
|
+
result = await findResourceInStore(fetchAndParseDocument(docUrl, options), uri, options);
|
|
418
|
+
}
|
|
274
419
|
}
|
|
275
420
|
// 2. Rainbow proxies (in order) — not supported for hash URIs
|
|
276
421
|
const isHashUri = uri.includes('#');
|
|
@@ -280,20 +425,23 @@ const actualFetchResource = async (uri, options) => {
|
|
|
280
425
|
}
|
|
281
426
|
const rainbowURL = new URL(instance);
|
|
282
427
|
rainbowURL.searchParams.set('uri', uri);
|
|
283
|
-
|
|
284
|
-
result = await findResourceInStore(fetchAndParseDocument(rainbowUrlStr, () => fetch(rainbowUrlStr, { headers: { 'Accept': ACCEPT_HEADER } })), uri, options);
|
|
428
|
+
result = await findResourceInStore(fetchAndParseDocument(rainbowURL.toString(), options), uri, options);
|
|
285
429
|
}
|
|
286
|
-
|
|
430
|
+
return result;
|
|
431
|
+
};
|
|
432
|
+
const sparqlQuery = (endpoint, options) => (query) => fetchAndParse(endpoint, {
|
|
433
|
+
method: 'POST',
|
|
434
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'text/turtle, application/n-triples' },
|
|
435
|
+
body: new URLSearchParams({ query }).toString(),
|
|
436
|
+
}, endpoint, options, true);
|
|
437
|
+
const actualFetchResource = async (uri, options) => {
|
|
438
|
+
let result = await trackLookup(() => lookupByRequest(uri, options));
|
|
439
|
+
// 3. SPARQL endpoints (in order), batching URIs into shared DESCRIBE queries
|
|
287
440
|
for (const endpoint of [...toArray(options.fallbackSparqlEndpoints), ...toArray(options.fallbackSparqlEndpoint)]) {
|
|
288
|
-
if (result) {
|
|
441
|
+
if (result || !isQueryableIri(uri)) {
|
|
289
442
|
break;
|
|
290
443
|
}
|
|
291
|
-
|
|
292
|
-
result = await findResourceInStore(fetchAndParse(() => fetch(endpoint, {
|
|
293
|
-
method: 'POST',
|
|
294
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'text/turtle, application/n-triples' },
|
|
295
|
-
body: formBody.toString(),
|
|
296
|
-
}), uri), uri, options);
|
|
444
|
+
result = await findResourceInStore(describeInBatch(endpoint, uri, options.sparqlBatchSize, sparqlQuery(endpoint, options)), uri, options);
|
|
297
445
|
}
|
|
298
446
|
if (!result) {
|
|
299
447
|
throw new Error(`No label data found for <${uri}>`);
|
|
@@ -308,175 +456,241 @@ async function fetchResource(uri, options = {}) {
|
|
|
308
456
|
return fetchResourceCache[uri];
|
|
309
457
|
}
|
|
310
458
|
|
|
459
|
+
const has = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
460
|
+
function pushContext(stack, context) {
|
|
461
|
+
if (Array.isArray(context)) {
|
|
462
|
+
return context.reduce(pushContext, stack);
|
|
463
|
+
}
|
|
464
|
+
if (context === null) {
|
|
465
|
+
return [];
|
|
466
|
+
}
|
|
467
|
+
return typeof context === 'object' ? [...stack, context] : stack;
|
|
468
|
+
}
|
|
469
|
+
// Each @base is resolved against the previous one, starting at the document's base URL
|
|
470
|
+
function resolveBase(stack, baseUrl) {
|
|
471
|
+
return stack.reduce((base, context) => {
|
|
472
|
+
if (!has(context, '@base')) {
|
|
473
|
+
return base;
|
|
474
|
+
}
|
|
475
|
+
const value = context['@base'];
|
|
476
|
+
if (value === null) {
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
try {
|
|
480
|
+
return new URL(value, base !== null && base !== void 0 ? base : undefined).toString();
|
|
481
|
+
}
|
|
482
|
+
catch (_a) {
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
}, baseUrl);
|
|
486
|
+
}
|
|
487
|
+
// Innermost value of a context entry; undefined if no context in the stack declares it
|
|
488
|
+
function findEntry(stack, key) {
|
|
489
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
490
|
+
if (has(stack[i], key)) {
|
|
491
|
+
return stack[i][key];
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return undefined;
|
|
495
|
+
}
|
|
496
|
+
/** Term definition in object form; null if the term is explicitly unmapped, undefined if unknown */
|
|
497
|
+
function findTerm(term, stack) {
|
|
498
|
+
const entry = findEntry(stack, term);
|
|
499
|
+
if (typeof entry === 'string') {
|
|
500
|
+
return { '@id': entry };
|
|
501
|
+
}
|
|
502
|
+
if (entry && typeof entry === 'object') {
|
|
503
|
+
return entry['@id'] === null ? null : entry;
|
|
504
|
+
}
|
|
505
|
+
return entry === null ? null : undefined;
|
|
506
|
+
}
|
|
507
|
+
/** The keyword (`@id`, `@type`...) that a key stands for, either directly or through an alias */
|
|
508
|
+
function asKeyword(key, stack) {
|
|
509
|
+
var _a;
|
|
510
|
+
if (key.startsWith('@')) {
|
|
511
|
+
return key;
|
|
512
|
+
}
|
|
513
|
+
const id = (_a = findTerm(key, stack)) === null || _a === void 0 ? void 0 : _a['@id'];
|
|
514
|
+
return (id === null || id === void 0 ? void 0 : id.startsWith('@')) ? id : null;
|
|
515
|
+
}
|
|
516
|
+
function expandIri(value, stack, options, seen = new Set()) {
|
|
517
|
+
var _a, _b, _c;
|
|
518
|
+
if (value.startsWith('@')) {
|
|
519
|
+
return value;
|
|
520
|
+
}
|
|
521
|
+
const expandTerm = (term) => expandIri(term, stack, { vocab: true }, seen);
|
|
522
|
+
if (options.vocab && !seen.has(value)) {
|
|
523
|
+
const definition = findTerm(value, stack);
|
|
524
|
+
if (definition === null) {
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
const id = (_a = definition === null || definition === void 0 ? void 0 : definition['@reverse']) !== null && _a !== void 0 ? _a : definition === null || definition === void 0 ? void 0 : definition['@id'];
|
|
528
|
+
if (id && id !== value) {
|
|
529
|
+
seen.add(value);
|
|
530
|
+
return expandTerm(id);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
const colon = value.indexOf(':');
|
|
534
|
+
if (colon > -1) {
|
|
535
|
+
const prefix = value.substring(0, colon);
|
|
536
|
+
const localPart = value.substring(colon + 1);
|
|
537
|
+
if (prefix === '_') {
|
|
538
|
+
return null;
|
|
539
|
+
}
|
|
540
|
+
if (!localPart.startsWith('//') && !seen.has(prefix) && findTerm(prefix, stack)) {
|
|
541
|
+
const expandedPrefix = expandIri(prefix, stack, { vocab: true }, new Set(seen));
|
|
542
|
+
if (expandedPrefix) {
|
|
543
|
+
return `${expandedPrefix}${localPart}`;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(value)) {
|
|
547
|
+
return value;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
if (options.vocab) {
|
|
551
|
+
const vocab = findEntry(stack, '@vocab');
|
|
552
|
+
if (vocab) {
|
|
553
|
+
const expandedVocab = vocab.includes(':') ? vocab : ((_c = (_b = findTerm(vocab, stack)) === null || _b === void 0 ? void 0 : _b['@id']) !== null && _c !== void 0 ? _c : vocab);
|
|
554
|
+
return `${expandedVocab}${value}`;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
if (options.base) {
|
|
558
|
+
const base = resolveBase(stack, options.baseUrl);
|
|
559
|
+
try {
|
|
560
|
+
return base ? new URL(value, base).toString() : null;
|
|
561
|
+
}
|
|
562
|
+
catch (_d) {
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return null;
|
|
567
|
+
}
|
|
568
|
+
|
|
311
569
|
const defaultAugmentOptions = {
|
|
312
570
|
replaceElements: true,
|
|
313
571
|
...defaultFetchResourceOptions,
|
|
314
572
|
};
|
|
315
|
-
|
|
573
|
+
const defaultTableOptions = {
|
|
316
574
|
propertiesField: 'properties',
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
575
|
+
maxDepth: 15,
|
|
576
|
+
maxElements: 100,
|
|
577
|
+
};
|
|
578
|
+
// Never cut by maxElements, since augment() needs them (e.g. for type-scoped contexts). Contexts are
|
|
579
|
+
// not known when rendering, so only the usual aliases of @id and @type can be recognized.
|
|
580
|
+
const ALWAYS_SHOWN = new Set(['@id', '@type', 'id', 'type']);
|
|
581
|
+
const RDF_TYPE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
|
|
582
|
+
const plural = (count, singular, pluralForm = `${singular}s`) => `${count} ${count === 1 ? singular : pluralForm}`;
|
|
583
|
+
const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
584
|
+
// {"@list": [...]} and {"@set": [...]} are displayed as plain arrays
|
|
585
|
+
const unwrapContainer = (value) => {
|
|
586
|
+
if (isObject(value)) {
|
|
587
|
+
const keys = Object.keys(value);
|
|
588
|
+
if (keys.length === 1 && (keys[0] === '@list' || keys[0] === '@set')) {
|
|
589
|
+
return value[keys[0]];
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return value;
|
|
593
|
+
};
|
|
594
|
+
const appendSpan = (parent, className, text) => {
|
|
595
|
+
const span = document.createElement('span');
|
|
596
|
+
span.classList.add(className);
|
|
597
|
+
span.textContent = text;
|
|
598
|
+
parent.appendChild(span);
|
|
599
|
+
return span;
|
|
600
|
+
};
|
|
601
|
+
// @context entries found in the data, kept out of the DOM for augment() to apply
|
|
602
|
+
const embeddedContexts = new WeakMap();
|
|
603
|
+
function createPropertiesTable(feature, container, options = {}) {
|
|
604
|
+
const { propertiesField, maxDepth, maxElements } = { ...defaultTableOptions, ...options };
|
|
605
|
+
const createLevel = (parent, rawValue, depth, addHeaders = false) => {
|
|
606
|
+
const value = unwrapContainer(rawValue);
|
|
607
|
+
if (isObject(value) && '@value' in value) {
|
|
608
|
+
// Value object: a single literal, plus its language or datatype
|
|
609
|
+
createLevel(parent, value['@value'], depth);
|
|
610
|
+
for (const [keyword, className] of [['@language', 'literal-language'], ['@type', 'literal-datatype']]) {
|
|
611
|
+
if (keyword in value) {
|
|
612
|
+
appendSpan(parent, className, String(value[keyword]));
|
|
613
|
+
}
|
|
323
614
|
}
|
|
324
|
-
return
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
if (value === null || typeof value !== 'object') {
|
|
618
|
+
appendSpan(parent, 'literal-value', '' + value);
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
const isArray = Array.isArray(value);
|
|
622
|
+
const entries = isArray
|
|
623
|
+
? value.map((v, i) => [String(i), v])
|
|
624
|
+
: Object.entries(value).filter(([k]) => k !== '@context');
|
|
625
|
+
if (isArray && !entries.length) {
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
if (depth > maxDepth && entries.length) {
|
|
629
|
+
appendSpan(parent, 'truncated-value', isArray ? plural(entries.length, 'item') : plural(entries.length, 'property', 'properties'));
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
const table = document.createElement('table');
|
|
633
|
+
table.classList.add(isArray ? 'array-table' : 'object-table');
|
|
634
|
+
if (!isArray && '@context' in value) {
|
|
635
|
+
embeddedContexts.set(table, value['@context']);
|
|
636
|
+
}
|
|
637
|
+
if (addHeaders && !isArray) {
|
|
638
|
+
table.innerHTML = '<thead><tr><th>Property</th><th>Value</th></tr></thead>';
|
|
639
|
+
}
|
|
640
|
+
const tbody = document.createElement('tbody');
|
|
641
|
+
const addCell = (row, ...classNames) => {
|
|
642
|
+
const cell = document.createElement('td');
|
|
643
|
+
cell.classList.add(...classNames);
|
|
644
|
+
row.appendChild(cell);
|
|
645
|
+
return cell;
|
|
646
|
+
};
|
|
647
|
+
let remaining = maxElements - (isArray ? 0 : entries.filter(([k]) => ALWAYS_SHOWN.has(k)).length);
|
|
648
|
+
const shown = entries.filter(([k]) => (!isArray && ALWAYS_SHOWN.has(k)) || remaining-- > 0);
|
|
649
|
+
for (const [k, v] of shown) {
|
|
650
|
+
const row = document.createElement('tr');
|
|
651
|
+
if (isArray) {
|
|
652
|
+
createLevel(addCell(row, 'array-value', 'array-entry'), v, depth + 1);
|
|
338
653
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const row = document.createElement('tr');
|
|
342
|
-
const keyCell = document.createElement('td');
|
|
343
|
-
keyCell.classList.add('object-property');
|
|
654
|
+
else {
|
|
655
|
+
const keyCell = addCell(row, 'object-property');
|
|
344
656
|
keyCell.setAttribute('data-property', k);
|
|
345
657
|
keyCell.textContent = k;
|
|
346
|
-
row
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
658
|
+
createLevel(addCell(row, 'object-value'), v, depth + 1);
|
|
659
|
+
}
|
|
660
|
+
tbody.appendChild(row);
|
|
661
|
+
}
|
|
662
|
+
const hidden = entries.length - shown.length;
|
|
663
|
+
if (hidden) {
|
|
664
|
+
const row = document.createElement('tr');
|
|
665
|
+
const cell = addCell(row, isArray ? 'array-value' : 'truncated-cell');
|
|
666
|
+
if (!isArray) {
|
|
667
|
+
cell.colSpan = 2;
|
|
668
|
+
}
|
|
669
|
+
appendSpan(cell, 'truncated-value', isArray
|
|
670
|
+
? plural(hidden, 'more item')
|
|
671
|
+
: plural(hidden, 'more property', 'more properties'));
|
|
672
|
+
tbody.appendChild(row);
|
|
356
673
|
}
|
|
674
|
+
table.appendChild(tbody);
|
|
675
|
+
parent.appendChild(table);
|
|
357
676
|
};
|
|
358
677
|
const wrapper = document.createElement('div');
|
|
359
678
|
wrapper.classList.add('object-properties');
|
|
360
679
|
container.appendChild(wrapper);
|
|
361
|
-
|
|
362
|
-
createLevel(wrapper, feature[options.propertiesField], true);
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
createLevel(wrapper, feature, true);
|
|
366
|
-
}
|
|
680
|
+
createLevel(wrapper, propertiesField ? feature[propertiesField] : feature, 1, true);
|
|
367
681
|
}
|
|
368
682
|
async function augment(rootElem, context, options = {}) {
|
|
369
683
|
const mergedOptions = { ...defaultAugmentOptions, ...options };
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
if (term in contextStack[i]) {
|
|
378
|
-
let resolvedTerm = contextStack[i][term];
|
|
379
|
-
let resolvedId;
|
|
380
|
-
if (resolvedTerm === null || typeof resolvedTerm === 'undefined' || typeof resolvedTerm === 'boolean'
|
|
381
|
-
|| Array.isArray(resolvedTerm)) {
|
|
382
|
-
continue;
|
|
383
|
-
}
|
|
384
|
-
if (typeof resolvedTerm === 'string') {
|
|
385
|
-
if (resolvedTerm === '@type') {
|
|
386
|
-
return { '@id': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' };
|
|
387
|
-
}
|
|
388
|
-
resolvedId = resolvedTerm;
|
|
389
|
-
resolvedTerm = { '@id': resolvedTerm };
|
|
390
|
-
}
|
|
391
|
-
else if (typeof resolvedTerm === 'object' && '@id' in resolvedTerm && typeof resolvedTerm['@id'] === 'string') {
|
|
392
|
-
resolvedId = resolvedTerm['@id'];
|
|
393
|
-
}
|
|
394
|
-
else {
|
|
395
|
-
continue;
|
|
396
|
-
}
|
|
397
|
-
const idx = resolvedId.indexOf(':');
|
|
398
|
-
if (idx > -1) {
|
|
399
|
-
const prefix = resolvedId.substring(0, idx);
|
|
400
|
-
const localPart = resolvedId.substring(idx + 1);
|
|
401
|
-
if (localPart.startsWith('//')) {
|
|
402
|
-
// Full URI -> return
|
|
403
|
-
return resolvedTerm;
|
|
404
|
-
}
|
|
405
|
-
const resolvedPrefix = resolveTerm(prefix, contextStack);
|
|
406
|
-
if (resolvedPrefix !== null && '@id' in resolvedPrefix && typeof resolvedPrefix['@id'] === 'string') {
|
|
407
|
-
// Prefix found and resolved
|
|
408
|
-
resolvedTerm['@id'] = `${resolvedPrefix['@id']}${localPart}`;
|
|
409
|
-
}
|
|
410
|
-
return resolvedTerm;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
if (closestVocab === null && contextStack[i]['@vocab']) {
|
|
414
|
-
closestVocab = contextStack[i]['@vocab'];
|
|
415
|
-
}
|
|
416
|
-
if (closestBase === null && contextStack[i]['@base']) {
|
|
417
|
-
closestBase = contextStack[i]['@base'];
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
if (term.indexOf(':') === -1) {
|
|
421
|
-
if (useVocab && closestVocab) {
|
|
422
|
-
return { '@id': `${closestVocab}${term}` };
|
|
423
|
-
}
|
|
424
|
-
if (useBase && closestBase) {
|
|
425
|
-
return { '@id': `${closestBase}${term}` };
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
const idx = term.indexOf(':');
|
|
430
|
-
const prefix = term.substring(0, idx);
|
|
431
|
-
const localPart = term.substring(idx + 1);
|
|
432
|
-
if (!localPart.startsWith('//')) {
|
|
433
|
-
const resolvedPrefix = resolveTerm(prefix, contextStack);
|
|
434
|
-
if (resolvedPrefix !== null && '@id' in resolvedPrefix && typeof resolvedPrefix['@id'] === 'string') {
|
|
435
|
-
return { '@id': `${resolvedPrefix['@id']}${localPart}` };
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
return null;
|
|
440
|
-
};
|
|
441
|
-
const findPropertyChildren = (elem) => {
|
|
442
|
-
const walker = document.createTreeWalker(elem, NodeFilter.SHOW_ELEMENT, {
|
|
443
|
-
acceptNode(node) {
|
|
444
|
-
const nodeElem = node;
|
|
445
|
-
if (node !== elem && nodeElem.classList.contains('object-value')) {
|
|
446
|
-
return NodeFilter.FILTER_REJECT;
|
|
447
|
-
}
|
|
448
|
-
if (nodeElem.classList.contains('object-property')) {
|
|
449
|
-
return NodeFilter.FILTER_ACCEPT;
|
|
450
|
-
}
|
|
451
|
-
return NodeFilter.FILTER_SKIP;
|
|
452
|
-
},
|
|
453
|
-
});
|
|
454
|
-
const result = [];
|
|
455
|
-
let cur;
|
|
456
|
-
while ((cur = walker.nextNode())) {
|
|
457
|
-
result.push(cur);
|
|
458
|
-
}
|
|
459
|
-
return result;
|
|
460
|
-
};
|
|
461
|
-
const findLiteralChildren = (elem) => {
|
|
462
|
-
const result = [];
|
|
463
|
-
const walker = document.createTreeWalker(elem, NodeFilter.SHOW_ELEMENT, {
|
|
464
|
-
acceptNode(node) {
|
|
465
|
-
const nodeElem = node;
|
|
466
|
-
if (nodeElem.classList.contains('object-property') || nodeElem.classList.contains('object-value')) {
|
|
467
|
-
return NodeFilter.FILTER_REJECT;
|
|
468
|
-
}
|
|
469
|
-
if (nodeElem.classList.contains('literal-value')) {
|
|
470
|
-
result.push(nodeElem);
|
|
471
|
-
return NodeFilter.FILTER_REJECT;
|
|
472
|
-
}
|
|
473
|
-
return NodeFilter.FILTER_SKIP;
|
|
474
|
-
},
|
|
475
|
-
});
|
|
476
|
-
while (walker.nextNode()) {
|
|
684
|
+
const { baseUrl } = mergedOptions;
|
|
685
|
+
// Outermost object tables below an element (looking through arrays and wrappers)
|
|
686
|
+
const findTables = (elem) => Array.from(elem.children).flatMap(child => child.classList.contains('object-table') ? [child] : findTables(child));
|
|
687
|
+
// Literal values of a cell, not including those that belong to nested objects
|
|
688
|
+
const findLiterals = (elem) => Array.from(elem.children).flatMap(child => {
|
|
689
|
+
if (child.classList.contains('literal-value')) {
|
|
690
|
+
return [child];
|
|
477
691
|
}
|
|
478
|
-
return
|
|
479
|
-
};
|
|
692
|
+
return child.classList.contains('object-table') ? [] : findLiterals(child);
|
|
693
|
+
});
|
|
480
694
|
const updateElement = (elem, resourceUri, replaceElements = true) => {
|
|
481
695
|
elem.setAttribute('data-uri', resourceUri);
|
|
482
696
|
elem.classList.add('resource-loading');
|
|
@@ -515,41 +729,99 @@ async function augment(rootElem, context, options = {}) {
|
|
|
515
729
|
elem.appendChild(link);
|
|
516
730
|
}
|
|
517
731
|
};
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
732
|
+
const linkLiterals = (valueElem, stack, expandOptions) => {
|
|
733
|
+
for (const literalElem of findLiterals(valueElem)) {
|
|
734
|
+
const iri = expandIri(literalElem.textContent.trim(), stack, { ...expandOptions, baseUrl });
|
|
735
|
+
if (iri && !iri.startsWith('@')) {
|
|
736
|
+
updateElement(literalElem, iri, mergedOptions.replaceElements);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
// The stack with the object's own context on top, if it has a loadable one
|
|
741
|
+
const pushEmbedded = async (stack, context) => {
|
|
742
|
+
try {
|
|
743
|
+
// Loading modifies the context, which belongs to the caller's data
|
|
744
|
+
const copy = JSON.parse(JSON.stringify(context));
|
|
745
|
+
const entries = await loadContextEntries(copy, { baseUrl, requestTimeout: mergedOptions.requestTimeout });
|
|
746
|
+
return entries.reduce(pushContext, stack);
|
|
747
|
+
}
|
|
748
|
+
catch (e) {
|
|
749
|
+
console.warn(`Error loading embedded context: ${e}`, { cause: e });
|
|
750
|
+
return stack;
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
const augmentNode = async (table, inheritedStack) => {
|
|
754
|
+
const embedded = embeddedContexts.get(table);
|
|
755
|
+
// Only wait when there is something to load
|
|
756
|
+
const stack = embedded === undefined ? inheritedStack : await pushEmbedded(inheritedStack, embedded);
|
|
757
|
+
const children = [];
|
|
758
|
+
const rows = Array.from(table.querySelectorAll(':scope > tbody > tr')).flatMap(row => {
|
|
759
|
+
const propElem = row.querySelector(':scope > .object-property');
|
|
760
|
+
if (!propElem) {
|
|
761
|
+
return [];
|
|
526
762
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
763
|
+
return [{
|
|
764
|
+
propElem,
|
|
765
|
+
valueElem: row.querySelector(':scope > .object-value'),
|
|
766
|
+
name: propElem.getAttribute('data-property') || propElem.textContent.trim(),
|
|
767
|
+
}];
|
|
768
|
+
});
|
|
769
|
+
// Type-scoped contexts apply to this node only, in lexicographical order of the types
|
|
770
|
+
const types = rows
|
|
771
|
+
.filter(({ name }) => asKeyword(name, stack) === '@type')
|
|
772
|
+
.flatMap(({ valueElem }) => valueElem ? findLiterals(valueElem) : [])
|
|
773
|
+
.map(elem => elem.textContent.trim())
|
|
774
|
+
.sort();
|
|
775
|
+
const nodeStack = types.reduce((result, type) => {
|
|
776
|
+
var _a;
|
|
777
|
+
const scoped = (_a = findTerm(type, stack)) === null || _a === void 0 ? void 0 : _a['@context'];
|
|
778
|
+
return scoped === undefined ? result : pushContext(result, scoped);
|
|
779
|
+
}, stack);
|
|
780
|
+
for (const { propElem, valueElem, name } of rows) {
|
|
781
|
+
const keyword = asKeyword(name, nodeStack);
|
|
782
|
+
let childStack = stack;
|
|
783
|
+
if (keyword === '@type') {
|
|
784
|
+
// Types are resolved before applying their scoped contexts
|
|
785
|
+
if (valueElem) {
|
|
786
|
+
linkLiterals(valueElem, stack, { vocab: true, base: true });
|
|
535
787
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
788
|
+
updateElement(propElem, RDF_TYPE, mergedOptions.replaceElements);
|
|
789
|
+
}
|
|
790
|
+
else if (keyword === '@id') {
|
|
791
|
+
if (valueElem) {
|
|
792
|
+
linkLiterals(valueElem, nodeStack, { base: true });
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
else if (keyword) {
|
|
796
|
+
// Other keywords (@graph, @reverse, @nest...) keep the current context
|
|
797
|
+
childStack = nodeStack;
|
|
798
|
+
}
|
|
799
|
+
else {
|
|
800
|
+
const definition = findTerm(name, nodeStack);
|
|
801
|
+
const propertyUri = expandIri(name, nodeStack, { vocab: true });
|
|
802
|
+
if (propertyUri) {
|
|
803
|
+
updateElement(propElem, propertyUri, mergedOptions.replaceElements);
|
|
804
|
+
}
|
|
805
|
+
if ((definition === null || definition === void 0 ? void 0 : definition['@context']) !== undefined) {
|
|
806
|
+
childStack = pushContext(stack, definition['@context']);
|
|
807
|
+
}
|
|
808
|
+
const coercion = definition === null || definition === void 0 ? void 0 : definition['@type'];
|
|
809
|
+
if (valueElem && (coercion === '@id' || coercion === '@vocab')) {
|
|
810
|
+
const valueStack = (definition === null || definition === void 0 ? void 0 : definition['@context']) === undefined
|
|
811
|
+
? nodeStack : pushContext(nodeStack, definition['@context']);
|
|
812
|
+
linkLiterals(valueElem, valueStack, { vocab: coercion === '@vocab', base: true });
|
|
545
813
|
}
|
|
546
814
|
}
|
|
547
815
|
if (valueElem) {
|
|
548
|
-
|
|
816
|
+
children.push(...findTables(valueElem).map(child => augmentNode(child, childStack)));
|
|
549
817
|
}
|
|
550
818
|
}
|
|
819
|
+
await Promise.all(children);
|
|
551
820
|
};
|
|
552
|
-
|
|
821
|
+
const rootStack = pushContext([], context !== null && context !== void 0 ? context : {});
|
|
822
|
+
const rootTables = rootElem.classList.contains('object-table')
|
|
823
|
+
? [rootElem] : findTables(rootElem);
|
|
824
|
+
await Promise.all(rootTables.map(table => augmentNode(table, rootStack)));
|
|
553
825
|
}
|
|
554
826
|
|
|
555
827
|
const WGS84_EPSG_CODES = new Set([4326, 4979]);
|
|
@@ -751,18 +1023,27 @@ const POPUP_CSS = `
|
|
|
751
1023
|
max-width: var(--jsonld-popup-max-width, 90vw) !important;
|
|
752
1024
|
max-height: var(--jsonld-popup-max-height, 80vh) !important;
|
|
753
1025
|
}
|
|
754
|
-
/* Keep cells readable: property names (often links once resolved) never wrap
|
|
755
|
-
|
|
756
|
-
Selectors are deliberately specific to win over host page
|
|
1026
|
+
/* Keep cells readable: property names (often links once resolved) never wrap. Width limits apply
|
|
1027
|
+
to leaf text only, never to cells that hold nested tables (those must be free to grow, or the
|
|
1028
|
+
nested table overflows its cell). Selectors are deliberately specific to win over host page
|
|
1029
|
+
styles for the same classes (e.g. max-width / word-break: break-all on .object-value). */
|
|
757
1030
|
.${POPUP_CLASS} .leaflet-popup-content .object-property {
|
|
758
1031
|
white-space: nowrap;
|
|
759
1032
|
word-break: normal;
|
|
760
1033
|
overflow-wrap: normal;
|
|
761
1034
|
}
|
|
762
|
-
.${POPUP_CLASS} .leaflet-popup-content .object-value
|
|
1035
|
+
.${POPUP_CLASS} .leaflet-popup-content .object-value,
|
|
1036
|
+
.${POPUP_CLASS} .leaflet-popup-content .array-value {
|
|
1037
|
+
min-width: 0;
|
|
1038
|
+
max-width: none;
|
|
1039
|
+
word-break: normal;
|
|
1040
|
+
overflow-wrap: normal;
|
|
1041
|
+
}
|
|
1042
|
+
.${POPUP_CLASS} .leaflet-popup-content .literal-value {
|
|
1043
|
+
display: inline-block;
|
|
1044
|
+
vertical-align: top;
|
|
763
1045
|
min-width: 10em;
|
|
764
1046
|
max-width: 30em;
|
|
765
|
-
word-break: normal;
|
|
766
1047
|
overflow-wrap: anywhere;
|
|
767
1048
|
}
|
|
768
1049
|
/* Let the popup content be the single scroll container (otherwise the table's own
|
|
@@ -864,7 +1145,7 @@ function recenterOnResize(popup) {
|
|
|
864
1145
|
});
|
|
865
1146
|
}
|
|
866
1147
|
async function createJsonLDGeoJSONLayer(L, data, options = {}) {
|
|
867
|
-
const { ldContext, popupOptions = {}, augmentOptions = {}, onEachFeature: userOnEachFeature, coordRefSys: coordRefSysOverride, proj4: proj4Override, crsAttribution = true, ...geoJSONOptions } = options;
|
|
1148
|
+
const { ldContext, popupOptions = {}, augmentOptions = {}, baseUrl, maxDepth, maxElements, onEachFeature: userOnEachFeature, coordRefSys: coordRefSysOverride, proj4: proj4Override, crsAttribution = true, ...geoJSONOptions } = options;
|
|
868
1149
|
let geoData = data;
|
|
869
1150
|
const crsInfo = coordRefSysOverride
|
|
870
1151
|
? detectCrs({ coordRefSys: coordRefSysOverride })
|
|
@@ -894,7 +1175,10 @@ async function createJsonLDGeoJSONLayer(L, data, options = {}) {
|
|
|
894
1175
|
if (!feature.properties || Object.keys(feature.properties).length === 0)
|
|
895
1176
|
return;
|
|
896
1177
|
const container = document.createElement('div');
|
|
897
|
-
createPropertiesTable(feature, container
|
|
1178
|
+
createPropertiesTable(feature, container, {
|
|
1179
|
+
...(maxDepth !== undefined ? { maxDepth } : {}),
|
|
1180
|
+
...(maxElements !== undefined ? { maxElements } : {}),
|
|
1181
|
+
});
|
|
898
1182
|
injectPopupCss();
|
|
899
1183
|
const className = [POPUP_CLASS, popupOptions.className].filter(Boolean).join(' ');
|
|
900
1184
|
// Large default maxWidth: the popup adapts to the table's natural width; the CSS cap (a share
|
|
@@ -907,8 +1191,8 @@ async function createJsonLDGeoJSONLayer(L, data, options = {}) {
|
|
|
907
1191
|
const contextsToMerge = [dataContext, ldContext].filter(v => v != null);
|
|
908
1192
|
if (contextsToMerge.length > 0) {
|
|
909
1193
|
const contextArg = contextsToMerge.length === 1 ? contextsToMerge[0] : contextsToMerge;
|
|
910
|
-
loadContext(contextArg).then((resolvedContext) => {
|
|
911
|
-
augment(container, resolvedContext, augmentOptions);
|
|
1194
|
+
loadContext(contextArg, { baseUrl }).then((resolvedContext) => {
|
|
1195
|
+
augment(container, resolvedContext, { baseUrl, ...augmentOptions });
|
|
912
1196
|
});
|
|
913
1197
|
}
|
|
914
1198
|
},
|