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