@holistics/anfra-sdk 0.21.0 → 0.23.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/dist/api.d.ts +1 -1
- package/dist/api.js +8 -0
- package/dist/app.d.ts +5 -5
- package/dist/app.js +3 -3
- package/dist/{bootstrap-BxBqFhgm.d.ts → bootstrap-DULxuxqY.d.ts} +49 -4
- package/dist/build.d.ts +2 -2
- package/dist/{chunk-E3Q3FRKQ.js → chunk-D3KOXXL2.js} +1 -1
- package/dist/{chunk-ACKFOANJ.js → chunk-DWQUIHUX.js} +4 -1
- package/dist/{chunk-IHRNKDMO.js → chunk-Q75JDXVL.js} +381 -11
- package/dist/{chunk-7NZOMBYE.js → chunk-YVWJ3WCK.js} +1 -1
- package/dist/common.d.ts +3 -3
- package/dist/common.js +1 -1
- package/dist/{errors-DR05L6-y.d.ts → errors-CWaxgIdV.d.ts} +1 -1
- package/dist/host.d.ts +2 -2
- package/dist/host.js +3 -3
- package/dist/{overview-KOQJNG2Y.js → overview-M3OBCW35.js} +2 -2
- package/dist/{plugin-BIcighnC.d.ts → plugin-CG0mVS1X.d.ts} +2 -2
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +5 -5
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +2 -2
- package/dist/{menu-CuTKq-dC.d.ts → theme-C9Tuzqu7.d.ts} +71 -55
- package/dist/{types-C_-1rgj2.d.ts → types-BiRAlSSk.d.ts} +141 -2
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from "./chunk-RXPNL7UR.js";
|
|
15
15
|
import {
|
|
16
16
|
version
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-D3KOXXL2.js";
|
|
18
18
|
import {
|
|
19
19
|
abortError,
|
|
20
20
|
createEndpoint
|
|
@@ -284,6 +284,129 @@ function assertCacheDuration(duration, declarer, setting, entity, how = "declare
|
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
+
// src/app/annotations.ts
|
|
288
|
+
var ANNOTATION_KINDS = ["mark", "focus", "line", "band", "series"];
|
|
289
|
+
var SEVERITIES = ["info", "warning", "critical"];
|
|
290
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
291
|
+
function checkAnnotations(plugin, queryName, result, annotations) {
|
|
292
|
+
if (!Array.isArray(annotations)) {
|
|
293
|
+
throw new ValidationError(`Plugin '${plugin}' annotated query '${queryName}' with something other than a list of annotations.`, queryName);
|
|
294
|
+
}
|
|
295
|
+
const ids = /* @__PURE__ */ new Set();
|
|
296
|
+
return annotations.map((annotation, position) => {
|
|
297
|
+
const at = `Annotation ${position} of plugin '${plugin}' on query '${queryName}'`;
|
|
298
|
+
const fail = (message) => {
|
|
299
|
+
throw new ValidationError(`${at} ${message}`, queryName);
|
|
300
|
+
};
|
|
301
|
+
if (!isObject(annotation)) return fail("is not an object.");
|
|
302
|
+
const { kind } = annotation;
|
|
303
|
+
if (!ANNOTATION_KINDS.includes(kind)) {
|
|
304
|
+
return fail(`has kind '${String(kind)}', but a kind is one of ${ANNOTATION_KINDS.map((k) => `'${k}'`).join(", ")}.`);
|
|
305
|
+
}
|
|
306
|
+
const text = {};
|
|
307
|
+
for (const field of ["id", "label", "detail"]) {
|
|
308
|
+
const value = annotation[field];
|
|
309
|
+
if (value === void 0) continue;
|
|
310
|
+
if (typeof value !== "string") fail(`has a ${field} that isn't a string.`);
|
|
311
|
+
text[field] = value;
|
|
312
|
+
}
|
|
313
|
+
if (text.id !== void 0) {
|
|
314
|
+
if (ids.has(text.id)) fail(`has the id '${text.id}', which another annotation in the set has.`);
|
|
315
|
+
ids.add(text.id);
|
|
316
|
+
}
|
|
317
|
+
if (annotation.severity !== void 0) {
|
|
318
|
+
if (!SEVERITIES.includes(annotation.severity)) {
|
|
319
|
+
fail(`has severity '${String(annotation.severity)}', but a severity is 'info', 'warning' or 'critical'.`);
|
|
320
|
+
}
|
|
321
|
+
text.severity = annotation.severity;
|
|
322
|
+
}
|
|
323
|
+
const check = anchorChecker(result.columns, fail);
|
|
324
|
+
const anchor = isObject(annotation.anchor) ? annotation.anchor : fail("has no anchor.");
|
|
325
|
+
return { kind, ...text, anchor: check(kind, anchor) };
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
function anchorChecker(columns, fail) {
|
|
329
|
+
const column = (name, role) => {
|
|
330
|
+
const found = typeof name === "string" ? columns.find((candidate) => candidate.name === name) : void 0;
|
|
331
|
+
if (found) return found;
|
|
332
|
+
return fail(typeof name === "string" ? withSuggestion(`names ${role} '${name}', but the result has no column '${name}'.`, name, columns.map((c) => c.name)) : `has no ${role}.`);
|
|
333
|
+
};
|
|
334
|
+
const measure = (name) => {
|
|
335
|
+
const found = column(name, "the measure");
|
|
336
|
+
if (!found.isMeasure) fail(`names '${found.name}' as its measure, but '${found.name}' is not a measure column.`);
|
|
337
|
+
return found.name;
|
|
338
|
+
};
|
|
339
|
+
const string = (value, what) => typeof value === "string" ? value : fail(`has a ${what} that isn't a string. Values are strings, as rows carry them.`);
|
|
340
|
+
const dimensions = (row, what) => {
|
|
341
|
+
if (!isObject(row) || !Object.keys(row).length) return fail(`has a ${what} that doesn't name a row by its dimension values.`);
|
|
342
|
+
for (const name of Object.keys(row)) {
|
|
343
|
+
if (column(name, "the column").isMeasure) fail(`names a ${what} by '${name}', a measure; name rows by their dimension values.`);
|
|
344
|
+
}
|
|
345
|
+
return { ...row };
|
|
346
|
+
};
|
|
347
|
+
return (kind, anchor) => {
|
|
348
|
+
if (kind === "mark" || kind === "focus") {
|
|
349
|
+
if (!Array.isArray(anchor.rows) || !anchor.rows.length) fail("has no rows in its anchor.");
|
|
350
|
+
const rows = anchor.rows.map((row) => dimensions(row, "row"));
|
|
351
|
+
return { rows, ...anchor.measure !== void 0 ? { measure: measure(anchor.measure) } : {} };
|
|
352
|
+
}
|
|
353
|
+
if (kind === "line") {
|
|
354
|
+
return { column: column(anchor.column, "the column").name, value: string(anchor.value, "value") };
|
|
355
|
+
}
|
|
356
|
+
if (kind === "band") {
|
|
357
|
+
if (anchor.from === void 0 || anchor.to === void 0) fail("needs a from and a to in its anchor.");
|
|
358
|
+
return { column: column(anchor.column, "the column").name, from: string(anchor.from, "from"), to: string(anchor.to, "to") };
|
|
359
|
+
}
|
|
360
|
+
const name = measure(anchor.measure);
|
|
361
|
+
if (!Array.isArray(anchor.points) || !anchor.points.length) fail("has no points in its anchor.");
|
|
362
|
+
const points = anchor.points.map((point) => {
|
|
363
|
+
if (!isObject(point)) return fail("has a point that is not an object.");
|
|
364
|
+
const hasBounds = point.lower !== void 0 && point.upper !== void 0;
|
|
365
|
+
if (point.value === void 0 && !hasBounds) fail("has a point with neither a value nor both bounds (lower and upper).");
|
|
366
|
+
if (point.lower === void 0 !== (point.upper === void 0)) fail("has a point with one bound: give its value or bounds, both lower and upper.");
|
|
367
|
+
return {
|
|
368
|
+
at: dimensions(point.at, "point"),
|
|
369
|
+
...point.value !== void 0 ? { value: string(point.value, "value") } : {},
|
|
370
|
+
...hasBounds ? { lower: string(point.lower, "lower bound"), upper: string(point.upper, "upper bound") } : {}
|
|
371
|
+
};
|
|
372
|
+
});
|
|
373
|
+
return { measure: name, points };
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
var sameValue = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
|
|
377
|
+
var rowMatches = (named, row) => Object.keys(named).every((name) => sameValue(named[name], row[name]));
|
|
378
|
+
function resolveAnnotations(sets, rows) {
|
|
379
|
+
const merged = [];
|
|
380
|
+
for (const [plugin, set] of sets) {
|
|
381
|
+
set.forEach((annotation, position) => {
|
|
382
|
+
const key = `${plugin}:${annotation.id ?? position}`;
|
|
383
|
+
if (annotation.kind !== "mark" && annotation.kind !== "focus") {
|
|
384
|
+
merged.push({ ...annotation, plugin, key });
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const found = [];
|
|
388
|
+
const index = [];
|
|
389
|
+
for (const named of annotation.anchor.rows) {
|
|
390
|
+
let any = false;
|
|
391
|
+
rows.forEach((row, at) => {
|
|
392
|
+
if (!rowMatches(named, row)) return;
|
|
393
|
+
any = true;
|
|
394
|
+
if (!index.includes(at)) index.push(at);
|
|
395
|
+
});
|
|
396
|
+
if (any) found.push(named);
|
|
397
|
+
}
|
|
398
|
+
if (!index.length) return;
|
|
399
|
+
merged.push({
|
|
400
|
+
...annotation,
|
|
401
|
+
anchor: { ...annotation.anchor, rows: found, index: index.sort((a, b) => a - b) },
|
|
402
|
+
plugin,
|
|
403
|
+
key
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
return merged;
|
|
408
|
+
}
|
|
409
|
+
|
|
287
410
|
// src/app/query.ts
|
|
288
411
|
function assertDeclaration(name, declaration, how = "declares") {
|
|
289
412
|
if (!declaration.aql?.trim()) {
|
|
@@ -345,6 +468,15 @@ var Query = class extends Observable {
|
|
|
345
468
|
__publicField(this, "runningSignature");
|
|
346
469
|
/** The signature of its last run, when that run failed. */
|
|
347
470
|
__publicField(this, "failedSignature");
|
|
471
|
+
/** Each plugin's annotations on the current result, by plugin, in the order they were first set. */
|
|
472
|
+
__publicField(this, "annotationSets", /* @__PURE__ */ new Map());
|
|
473
|
+
/**
|
|
474
|
+
* The results that are the current one: the last run's, and each that a page extended it into, so
|
|
475
|
+
* annotations computed before a `fetchMore` still land.
|
|
476
|
+
*/
|
|
477
|
+
__publicField(this, "currentResults", /* @__PURE__ */ new WeakSet());
|
|
478
|
+
/** `annotations` as last read, until a set or the result changes. */
|
|
479
|
+
__publicField(this, "resolvedAnnotations");
|
|
348
480
|
assertDeclaration(name, declaration);
|
|
349
481
|
this.name = name;
|
|
350
482
|
this.id = id;
|
|
@@ -366,7 +498,8 @@ var Query = class extends Observable {
|
|
|
366
498
|
}
|
|
367
499
|
/**
|
|
368
500
|
* Swaps what this query is: its dataset, its AQL, its page size, its cache, checked as `createQuery` checks
|
|
369
|
-
* them. Its name, its edges and its result stay; the result until the rerun replaces it
|
|
501
|
+
* them. Its name, its edges and its result stay; the result until the rerun replaces it, but its
|
|
502
|
+
* annotations go at once, and plugins can't annotate that result any more. Runs
|
|
370
503
|
* nothing: the query is dirty, and the next `app.execute()` reruns it, so several edits go out
|
|
371
504
|
* as one run. Back to the first page. A run or page in flight is aborted, and `fetchMore` does
|
|
372
505
|
* nothing until the rerun. A new AQL or dataset clears the sort (unless `sort` is given) and a
|
|
@@ -399,6 +532,8 @@ var Query = class extends Observable {
|
|
|
399
532
|
this.runningSignature = void 0;
|
|
400
533
|
if (this._state === "executing") this._state = this._result ? "success" : "idle";
|
|
401
534
|
this.resultSuperseded = true;
|
|
535
|
+
this.clearAnnotations();
|
|
536
|
+
this.currentResults = /* @__PURE__ */ new WeakSet();
|
|
402
537
|
this._declaration = declaration;
|
|
403
538
|
this._dataset = dataset;
|
|
404
539
|
this._sort = [...sort];
|
|
@@ -409,6 +544,7 @@ var Query = class extends Observable {
|
|
|
409
544
|
/** @internal The app's half of `remove`: stop what is in flight, and stay quiet from then on. */
|
|
410
545
|
markRemoved() {
|
|
411
546
|
this.removed = true;
|
|
547
|
+
this.clearAnnotations();
|
|
412
548
|
this.controller?.abort();
|
|
413
549
|
this.controller = void 0;
|
|
414
550
|
this.runningSignature = void 0;
|
|
@@ -595,6 +731,31 @@ var Query = class extends Observable {
|
|
|
595
731
|
const picked = new Set(selection.rows.map(key));
|
|
596
732
|
return rows.filter((row) => picked.has(key(row)));
|
|
597
733
|
}
|
|
734
|
+
/**
|
|
735
|
+
* What plugins say about this query's current result, every plugin's merged: draw the kinds your
|
|
736
|
+
* chart declares in `data-anfra-annotations`, by `index` for a rows anchor. Each has its plugin
|
|
737
|
+
* and a stable `key`. A change notifies through `subscribe`; they go when the result is replaced.
|
|
738
|
+
*/
|
|
739
|
+
get annotations() {
|
|
740
|
+
this.resolvedAnnotations ?? (this.resolvedAnnotations = Object.freeze(resolveAnnotations(this.annotationSets, this._result?.rows ?? [])));
|
|
741
|
+
return this.resolvedAnnotations;
|
|
742
|
+
}
|
|
743
|
+
/** @internal Whether `result` is this query's current result, or one a page has since extended. */
|
|
744
|
+
isCurrentResult(result) {
|
|
745
|
+
return this.currentResults.has(result);
|
|
746
|
+
}
|
|
747
|
+
/** @internal `kernel.annotate`'s, checked by then: replace one plugin's set, `[]` clearing it. */
|
|
748
|
+
setAnnotations(plugin, annotations) {
|
|
749
|
+
if (annotations.length) this.annotationSets.set(plugin, annotations);
|
|
750
|
+
else if (!this.annotationSets.delete(plugin)) return;
|
|
751
|
+
this.resolvedAnnotations = void 0;
|
|
752
|
+
this.notify();
|
|
753
|
+
}
|
|
754
|
+
/** Every plugin's annotations go, with the result they were about. */
|
|
755
|
+
clearAnnotations() {
|
|
756
|
+
this.annotationSets.clear();
|
|
757
|
+
this.resolvedAnnotations = void 0;
|
|
758
|
+
}
|
|
598
759
|
/** @internal */
|
|
599
760
|
markExecuting() {
|
|
600
761
|
if (this.removed) return;
|
|
@@ -622,13 +783,17 @@ var Query = class extends Observable {
|
|
|
622
783
|
if (!append) this.runFailed = false;
|
|
623
784
|
this.lastRunSignature = signature;
|
|
624
785
|
this.lastPageRows = result.rows.length;
|
|
786
|
+
if (!append) this.clearAnnotations();
|
|
787
|
+
else this.resolvedAnnotations = void 0;
|
|
625
788
|
if (append && this._result) {
|
|
626
789
|
const added = result.meta.pivot ? newGridRows(this._result.rows, result.rows) : result.rows;
|
|
627
790
|
const rows = [...this._result.rows, ...added];
|
|
628
791
|
this._result = { ...result, rows, meta: { ...result.meta, numRows: rows.length } };
|
|
629
792
|
} else {
|
|
630
793
|
this._result = result;
|
|
794
|
+
this.currentResults = /* @__PURE__ */ new WeakSet();
|
|
631
795
|
}
|
|
796
|
+
this.currentResults.add(this._result);
|
|
632
797
|
this.notify();
|
|
633
798
|
}
|
|
634
799
|
/**
|
|
@@ -1213,6 +1378,33 @@ function describeNode(node, element, structure) {
|
|
|
1213
1378
|
}
|
|
1214
1379
|
|
|
1215
1380
|
// src/app/menu.ts
|
|
1381
|
+
function annotationNote(annotation) {
|
|
1382
|
+
return {
|
|
1383
|
+
label: annotation.label || defaultLabel(annotation),
|
|
1384
|
+
...annotation.detail ? { detail: annotation.detail } : {},
|
|
1385
|
+
...annotation.severity ? { severity: annotation.severity } : {},
|
|
1386
|
+
plugin: annotation.plugin
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
function defaultLabel(annotation) {
|
|
1390
|
+
switch (annotation.kind) {
|
|
1391
|
+
case "line":
|
|
1392
|
+
return `${annotation.anchor.column} at ${annotation.anchor.value}`;
|
|
1393
|
+
case "band":
|
|
1394
|
+
return `${annotation.anchor.column} from ${annotation.anchor.from} to ${annotation.anchor.to}`;
|
|
1395
|
+
case "series":
|
|
1396
|
+
return `A series of ${annotation.anchor.measure}`;
|
|
1397
|
+
case "focus":
|
|
1398
|
+
return "In focus";
|
|
1399
|
+
case "mark":
|
|
1400
|
+
return "Marked";
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
function forHost(target) {
|
|
1404
|
+
if (target.kind !== "rows" || !target.annotations) return target;
|
|
1405
|
+
const { annotations: _, ...rest } = target;
|
|
1406
|
+
return rest;
|
|
1407
|
+
}
|
|
1216
1408
|
var rowsOpener;
|
|
1217
1409
|
function openRowsMenu(event, target) {
|
|
1218
1410
|
return rowsOpener ? rowsOpener(event, target) : false;
|
|
@@ -1303,12 +1495,12 @@ function installContentUi(kernel) {
|
|
|
1303
1495
|
const entries = [...own.entries];
|
|
1304
1496
|
if (hostKinds.has(target.kind)) {
|
|
1305
1497
|
try {
|
|
1306
|
-
const answered = await kernel.call("anfra.menu", target);
|
|
1498
|
+
const answered = await kernel.call("anfra.menu", forHost(target));
|
|
1307
1499
|
for (const entry of Array.isArray(answered) ? answered : []) {
|
|
1308
1500
|
if (typeof entry?.id !== "string" || typeof entry.label !== "string") continue;
|
|
1309
1501
|
const key = `host:${entry.id}:${target.kind}`;
|
|
1310
1502
|
entries.push({ id: key, label: entry.label, ...typeof entry.disabled === "string" ? { disabled: entry.disabled } : {} });
|
|
1311
|
-
run.set(key, () => kernel.call("anfra.run", { id: entry.id, target }));
|
|
1503
|
+
run.set(key, () => kernel.call("anfra.run", { id: entry.id, target: forHost(target) }));
|
|
1312
1504
|
}
|
|
1313
1505
|
} catch {
|
|
1314
1506
|
}
|
|
@@ -1316,8 +1508,9 @@ function installContentUi(kernel) {
|
|
|
1316
1508
|
return { entries, run };
|
|
1317
1509
|
}
|
|
1318
1510
|
function open(event, targets, about) {
|
|
1511
|
+
const notes = targets.flatMap((target) => target.kind === "rows" ? target.annotations ?? [] : []).map(annotationNote);
|
|
1319
1512
|
const relevant = targets.map((target) => ({ target, own: frameEntries(target) })).filter(({ target, own }) => own.entries.length || hostKinds.has(target.kind));
|
|
1320
|
-
if (!relevant.length) return false;
|
|
1513
|
+
if (!relevant.length && !notes.length) return false;
|
|
1321
1514
|
event.preventDefault();
|
|
1322
1515
|
const point = event;
|
|
1323
1516
|
const x = typeof point.clientX === "number" ? point.clientX : 0;
|
|
@@ -1325,11 +1518,12 @@ function installContentUi(kernel) {
|
|
|
1325
1518
|
void (async () => {
|
|
1326
1519
|
const [body, ...found] = await Promise.all([ui(), ...relevant.map(({ target, own }) => entriesFor(target, own))]);
|
|
1327
1520
|
const groups = found.map((group) => group.entries).filter((group) => group.length);
|
|
1328
|
-
if (!groups.length) return;
|
|
1521
|
+
if (!groups.length && !notes.length) return;
|
|
1329
1522
|
closeCurrent();
|
|
1330
1523
|
const close = body.menu(root(), {
|
|
1331
1524
|
x,
|
|
1332
1525
|
y,
|
|
1526
|
+
...notes.length ? { notes } : {},
|
|
1333
1527
|
groups,
|
|
1334
1528
|
onPick: (key) => {
|
|
1335
1529
|
const action = found.map((group) => group.run.get(key)).find(Boolean);
|
|
@@ -1364,7 +1558,9 @@ function installContentUi(kernel) {
|
|
|
1364
1558
|
if (event.defaultPrevented || event.shiftKey) return false;
|
|
1365
1559
|
const element = blockOf(event.target);
|
|
1366
1560
|
const node = element ? nodeTarget(element) : void 0;
|
|
1367
|
-
const
|
|
1561
|
+
const point = event;
|
|
1562
|
+
const at = typeof point.clientX === "number" && typeof point.clientY === "number" ? { x: point.clientX, y: point.clientY } : void 0;
|
|
1563
|
+
const rows = { ...target, ...node ? { node } : {}, ...at ? { at } : {} };
|
|
1368
1564
|
return open(event, node ? [rows, node] : [rows], { app: target.app, query: target.query });
|
|
1369
1565
|
};
|
|
1370
1566
|
kernel.onApp((app) => app.onRemoved((entity) => {
|
|
@@ -1402,7 +1598,7 @@ function installContentUi(kernel) {
|
|
|
1402
1598
|
}
|
|
1403
1599
|
return {
|
|
1404
1600
|
addItem(plugin, item) {
|
|
1405
|
-
items.push({ ...item, full: `${plugin}.${item.id}
|
|
1601
|
+
items.push({ ...item, full: `${plugin}.${item.id}`, plugin });
|
|
1406
1602
|
listen();
|
|
1407
1603
|
},
|
|
1408
1604
|
modal: (input) => show(input, (body, onClose) => body.modal(root(), {
|
|
@@ -1411,6 +1607,26 @@ function installContentUi(kernel) {
|
|
|
1411
1607
|
mount: reported(input.mount),
|
|
1412
1608
|
onClose
|
|
1413
1609
|
})),
|
|
1610
|
+
popoverAt: (anchor, input) => show(input, (body, onClose) => body.popover(root(), {
|
|
1611
|
+
anchor,
|
|
1612
|
+
side: input.side,
|
|
1613
|
+
mount: reported(input.mount),
|
|
1614
|
+
dismiss: input.dismiss,
|
|
1615
|
+
closeButton: input.closeButton,
|
|
1616
|
+
onClose
|
|
1617
|
+
})),
|
|
1618
|
+
rowsEntries(plugin, target) {
|
|
1619
|
+
return items.filter((item) => item.plugin === plugin).flatMap((item) => {
|
|
1620
|
+
if (item.target !== "rows") return [];
|
|
1621
|
+
try {
|
|
1622
|
+
if (item.when && item.when(target) === false) return [];
|
|
1623
|
+
if (!item.entries) return [{ label: item.label, run: () => item.run(target) }];
|
|
1624
|
+
return (item.entries(target) ?? []).filter((entry) => typeof entry?.label === "string" && (entry.disabled || typeof entry.run === "function"));
|
|
1625
|
+
} catch {
|
|
1626
|
+
return [];
|
|
1627
|
+
}
|
|
1628
|
+
});
|
|
1629
|
+
},
|
|
1414
1630
|
popover: (input) => show(input, (body, onClose) => {
|
|
1415
1631
|
const { anchor } = input;
|
|
1416
1632
|
let rect;
|
|
@@ -2379,8 +2595,16 @@ var App = class extends Observable {
|
|
|
2379
2595
|
);
|
|
2380
2596
|
}
|
|
2381
2597
|
}
|
|
2598
|
+
return openRowsMenu(event, this.rowsTarget(query, rows, fields, measure));
|
|
2599
|
+
}
|
|
2600
|
+
/**
|
|
2601
|
+
* @internal What a menu on these rows of the query is about: their conditions, derived as a
|
|
2602
|
+
* cross-filter's, and the annotations plugins set on them (on `measure`'s, when given).
|
|
2603
|
+
*/
|
|
2604
|
+
rowsTarget(query, rows, fields, measure) {
|
|
2382
2605
|
const derived = deriveSelection(query, rows, fields, this.drillTransformations(query));
|
|
2383
|
-
|
|
2606
|
+
const annotations = query.annotations.filter((annotation) => (annotation.kind === "mark" || annotation.kind === "focus") && (measure === void 0 || annotation.anchor.measure === void 0 || annotation.anchor.measure === measure) && annotation.anchor.rows.some((named) => rows.some((row) => rowMatches(named, row))));
|
|
2607
|
+
return {
|
|
2384
2608
|
kind: "rows",
|
|
2385
2609
|
app: this.index,
|
|
2386
2610
|
query: query.name,
|
|
@@ -2388,8 +2612,9 @@ var App = class extends Observable {
|
|
|
2388
2612
|
fields: derived?.fields ? [...derived.fields] : [],
|
|
2389
2613
|
...measure !== void 0 ? { measure } : {},
|
|
2390
2614
|
conditions: derived?.conditions ? [...derived.conditions] : [],
|
|
2391
|
-
...derived?.expression ? { expression: derived.expression } : {}
|
|
2392
|
-
|
|
2615
|
+
...derived?.expression ? { expression: derived.expression } : {},
|
|
2616
|
+
...annotations.length ? { annotations } : {}
|
|
2617
|
+
};
|
|
2393
2618
|
}
|
|
2394
2619
|
/**
|
|
2395
2620
|
* @internal Backs the kernel's `queryRequest(query)`: what the query runs with now, from its applied
|
|
@@ -2983,6 +3208,17 @@ function createKernel(plugin, shared, entities) {
|
|
|
2983
3208
|
menuItem: (item) => shared.contentUi?.addItem(plugin, item),
|
|
2984
3209
|
modal: (input) => shared.contentUi.modal(input),
|
|
2985
3210
|
popover: (input) => shared.contentUi.popover(input),
|
|
3211
|
+
annotate(query, annotations, options) {
|
|
3212
|
+
if (query?.isRemoved) return false;
|
|
3213
|
+
const app = sdk.apps.find((candidate) => candidate.queries[query?.name] === query);
|
|
3214
|
+
if (!app) throw new ValidationError(`Plugin '${plugin}' annotated a query that belongs to no app.`, query?.name);
|
|
3215
|
+
if (!options || typeof options.result !== "object" || options.result === null) {
|
|
3216
|
+
throw new ValidationError(`Plugin '${plugin}' annotated query '${query.name}' without the result it computed them from ({ result: query.result }).`, query.name);
|
|
3217
|
+
}
|
|
3218
|
+
if (!query.isCurrentResult(options.result)) return false;
|
|
3219
|
+
query.setAnnotations(plugin, checkAnnotations(plugin, query.name, options.result, annotations));
|
|
3220
|
+
return true;
|
|
3221
|
+
},
|
|
2986
3222
|
body() {
|
|
2987
3223
|
loading ?? (loading = endpoint.call(BODY_CALL, { plugin }).then((code) => runBody(win, code)).catch((err) => {
|
|
2988
3224
|
loading = void 0;
|
|
@@ -3150,6 +3386,139 @@ function installInspection(kernel) {
|
|
|
3150
3386
|
});
|
|
3151
3387
|
}
|
|
3152
3388
|
|
|
3389
|
+
// src/app/annotationBadges.ts
|
|
3390
|
+
var ANNOTATIONS_ATTRIBUTE = "data-anfra-annotations";
|
|
3391
|
+
function drawnBy(element) {
|
|
3392
|
+
const value = element.getAttribute(ANNOTATIONS_ATTRIBUTE);
|
|
3393
|
+
if (value?.trim() === "off") return "off";
|
|
3394
|
+
return new Set((value ?? "").split(/\s+/).filter((kind) => ANNOTATION_KINDS.includes(kind)));
|
|
3395
|
+
}
|
|
3396
|
+
function badgedAnnotations(element, annotations) {
|
|
3397
|
+
const drawn = drawnBy(element);
|
|
3398
|
+
return drawn === "off" ? [] : annotations.filter((annotation) => !drawn.has(annotation.kind));
|
|
3399
|
+
}
|
|
3400
|
+
function highest(annotations) {
|
|
3401
|
+
let top = -1;
|
|
3402
|
+
for (const { severity } of annotations) top = Math.max(top, severity ? SEVERITIES.indexOf(severity) : -1);
|
|
3403
|
+
return top < 0 ? void 0 : SEVERITIES[top];
|
|
3404
|
+
}
|
|
3405
|
+
var describe = (count, severity) => `${count} annotation${count === 1 ? "" : "s"}${severity ? `, highest: ${severity}` : ""}`;
|
|
3406
|
+
function installAnnotationBadges(kernel, contentUi) {
|
|
3407
|
+
const doc = kernel.window.document;
|
|
3408
|
+
const realm = kernel.window;
|
|
3409
|
+
const apps = [];
|
|
3410
|
+
let scheduled = false;
|
|
3411
|
+
let drawnAny = false;
|
|
3412
|
+
let observer;
|
|
3413
|
+
const lists = /* @__PURE__ */ new WeakMap();
|
|
3414
|
+
let listed = 0;
|
|
3415
|
+
const listId = (list) => {
|
|
3416
|
+
if (!lists.has(list)) lists.set(list, listed += 1);
|
|
3417
|
+
return lists.get(list);
|
|
3418
|
+
};
|
|
3419
|
+
const ui = () => kernel.body();
|
|
3420
|
+
function actionsFor(app, query, annotation, at) {
|
|
3421
|
+
const rows = query.result?.rows;
|
|
3422
|
+
if (annotation.kind !== "mark" && annotation.kind !== "focus" || !rows) return [];
|
|
3423
|
+
const target = app.rowsTarget(query, annotation.anchor.index.map((index) => rows[index]), void 0, annotation.anchor.measure);
|
|
3424
|
+
return contentUi.rowsEntries(annotation.plugin, { ...target, ...at ? { at } : {}, annotations: [annotation] });
|
|
3425
|
+
}
|
|
3426
|
+
async function open(app, query, covered, anchor) {
|
|
3427
|
+
const body = await ui();
|
|
3428
|
+
const badge = anchor();
|
|
3429
|
+
const at = badge ? { x: badge.x, y: badge.y + badge.height } : void 0;
|
|
3430
|
+
const opening = contentUi.popoverAt(anchor, {
|
|
3431
|
+
about: { app: app.index, query: query.name },
|
|
3432
|
+
side: "bottom",
|
|
3433
|
+
dismiss: "outside",
|
|
3434
|
+
mount: (root) => body.annotationList(
|
|
3435
|
+
root,
|
|
3436
|
+
covered.map((annotation) => ({ ...annotationNote(annotation), actions: actionsFor(app, query, annotation, at) })),
|
|
3437
|
+
(action) => {
|
|
3438
|
+
void opening.then((opened) => opened.close());
|
|
3439
|
+
Promise.resolve().then(action.run).catch((err) => {
|
|
3440
|
+
realm.console?.error("anfra: an annotation's action failed:", err);
|
|
3441
|
+
reportError("plugin.uncaught", err);
|
|
3442
|
+
});
|
|
3443
|
+
}
|
|
3444
|
+
)
|
|
3445
|
+
});
|
|
3446
|
+
await opening;
|
|
3447
|
+
}
|
|
3448
|
+
let shown = { signature: "", elements: [] };
|
|
3449
|
+
async function draw() {
|
|
3450
|
+
scheduled = false;
|
|
3451
|
+
const list = [];
|
|
3452
|
+
const parts = [];
|
|
3453
|
+
let annotated = false;
|
|
3454
|
+
for (const app of apps) {
|
|
3455
|
+
for (const query of Object.values(app.queries)) {
|
|
3456
|
+
const { annotations } = query;
|
|
3457
|
+
if (!annotations.length) continue;
|
|
3458
|
+
annotated = true;
|
|
3459
|
+
markersFor(doc, "query", app.index, query.name).forEach((element, position) => {
|
|
3460
|
+
const covered = badgedAnnotations(element, annotations);
|
|
3461
|
+
if (!covered.length) return;
|
|
3462
|
+
const severity = highest(covered);
|
|
3463
|
+
const id = `${app.index}/${query.name}#${position}`;
|
|
3464
|
+
parts.push(`${id}:${listId(annotations)}:${covered.length}`);
|
|
3465
|
+
list.push({
|
|
3466
|
+
id,
|
|
3467
|
+
element,
|
|
3468
|
+
count: covered.length,
|
|
3469
|
+
...severity ? { severity } : {},
|
|
3470
|
+
label: describe(covered.length, severity),
|
|
3471
|
+
onOpen: (anchor) => {
|
|
3472
|
+
open(app, query, covered, anchor).catch((err) => {
|
|
3473
|
+
realm.console?.error("anfra: the annotations popover failed to open:", err);
|
|
3474
|
+
reportError("plugin.uncaught", err);
|
|
3475
|
+
});
|
|
3476
|
+
}
|
|
3477
|
+
});
|
|
3478
|
+
});
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
watchPage(annotated);
|
|
3482
|
+
const elements = list.map((badge) => badge.element);
|
|
3483
|
+
const signature = parts.join("|");
|
|
3484
|
+
if (signature === shown.signature && elements.every((element, at) => element === shown.elements[at])) return;
|
|
3485
|
+
shown = { signature, elements };
|
|
3486
|
+
if (!list.length && !drawnAny) return;
|
|
3487
|
+
drawnAny = true;
|
|
3488
|
+
const body = await ui();
|
|
3489
|
+
body.badges(layerRoot(doc, "anfra-badges"), list);
|
|
3490
|
+
}
|
|
3491
|
+
const schedule = () => {
|
|
3492
|
+
if (scheduled) return;
|
|
3493
|
+
scheduled = true;
|
|
3494
|
+
queueMicrotask(() => {
|
|
3495
|
+
draw().catch((err) => {
|
|
3496
|
+
realm.console?.error("anfra: the annotations badge failed to draw:", err);
|
|
3497
|
+
reportError("plugin.uncaught", err);
|
|
3498
|
+
});
|
|
3499
|
+
});
|
|
3500
|
+
};
|
|
3501
|
+
function watchPage(on) {
|
|
3502
|
+
if (on && !observer && typeof realm.MutationObserver === "function") {
|
|
3503
|
+
observer = new realm.MutationObserver(schedule);
|
|
3504
|
+
observer.observe(doc.documentElement, {
|
|
3505
|
+
subtree: true,
|
|
3506
|
+
childList: true,
|
|
3507
|
+
attributes: true,
|
|
3508
|
+
attributeFilter: [ATTR.query, ANNOTATIONS_ATTRIBUTE]
|
|
3509
|
+
});
|
|
3510
|
+
} else if (!on && observer) {
|
|
3511
|
+
observer.disconnect();
|
|
3512
|
+
observer = void 0;
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
kernel.onApp((app) => {
|
|
3516
|
+
apps.push(app);
|
|
3517
|
+
app.subscribe(schedule);
|
|
3518
|
+
app.onRemoved(schedule);
|
|
3519
|
+
});
|
|
3520
|
+
}
|
|
3521
|
+
|
|
3153
3522
|
// src/app/bootstrap.ts
|
|
3154
3523
|
function bootstrap(win, setups = []) {
|
|
3155
3524
|
const element = win.document.getElementById(PROVISION_ELEMENT_ID);
|
|
@@ -3221,6 +3590,7 @@ function bootstrap(win, setups = []) {
|
|
|
3221
3590
|
installInspection(own);
|
|
3222
3591
|
installCore(createKernel("core", shared, { Query, Control }));
|
|
3223
3592
|
shared.contentUi = installContentUi(own);
|
|
3593
|
+
installAnnotationBadges(own, shared.contentUi);
|
|
3224
3594
|
own.on("theme", (theme) => {
|
|
3225
3595
|
const resolved = resolveTheme(theme);
|
|
3226
3596
|
themeLayer(win.document, resolved);
|
package/dist/common.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as ApiErrorCode, D as DataAppError, a as DataAppErrorInit, E as ErrorCode, b as ErrorContextEntry, c as ErrorDetails, d as ErrorScope, F as FromHttpStatusOptions, G as GENERIC_CODES, e as GenericCode, V as ValidationError, f as callFailed, g as connectionFailed, h as forbidden, i as fromHttpStatus, j as hasErrorCode, k as invalidRequest, l as isDataAppError } from './errors-
|
|
2
|
-
export { A as Aggregation, a as
|
|
1
|
+
export { A as ApiErrorCode, D as DataAppError, a as DataAppErrorInit, E as ErrorCode, b as ErrorContextEntry, c as ErrorDetails, d as ErrorScope, F as FromHttpStatusOptions, G as GENERIC_CODES, e as GenericCode, V as ValidationError, f as callFailed, g as connectionFailed, h as forbidden, i as fromHttpStatus, j as hasErrorCode, k as invalidRequest, l as isDataAppError } from './errors-CWaxgIdV.js';
|
|
2
|
+
export { A as Aggregation, a as Annotation, b as AnnotationInput, c as AnnotationKind, d as AnnotationSeverity, e as AppDeclaration, f as AppJson, g as ArrowType, B as Backend, h as BackendCondition, i as BackendDateDrill, j as BackendExportRequest, k as BackendFilter, l as BackendLineageRequest, m as BackendQueryRequest, n as BackendQueryResult, o as BackendSort, C as CallStamp, p as ColumnMeta, q as Condition, r as ConditionValue, s as ControlMappingJson, t as CrossFilterJson, D as DatasetDescriptor, u as DatasetRelationship, v as DateDrillDeclaration, w as DateGrain, x as DateTransformation, E as EntityKind, y as EntityRef, z as EntityUsage, F as ExecuteOptions, G as ExecuteSummary, H as ExportFormat, I as ExportFormatOptions, J as ExportOptions, K as ExportResult, L as FILTER_AGGREGATIONS, M as FieldLineage, N as FieldSuggestionsRequest, O as FilterAggregation, P as FilterDeclaration, Q as FilterValueType, R as InspectedApp, S as InspectedControl, T as InspectedError, U as InspectedQuery, V as InspectedSelection, W as InspectedStructure, X as LineageCard, Y as LineageDiagram, Z as LineageNode, _ as LineageOptions, $ as LineageResult, a0 as LineageTarget, a1 as Listener, a2 as LocateKind, a3 as LocateTarget, a4 as MappingJson, a5 as Operator, a6 as QueryCacheResult, a7 as QueryCacheSettings, a8 as QueryDebug, a9 as QueryDeclaration, aa as QueryInput, ab as QueryInputDefaults, ac as QueryPagination, ad as QueryPivot, ae as QueryRequest, af as QueryResult, ag as QuerySeeds, ah as QuerySort, ai as QueryStamp, aj as QueryState, ak as QueryTimings, al as RangeAnchor, am as RenderFormat, an as RenderRequest, ao as Rendering, ap as ResolvedRowsAnchor, aq as Row, ar as RowsAnchor, as as SdkEnvironment, at as SdkFeatures, au as Selection, av as SelectionCondition, aw as SemanticType, ax as SeriesAnchor, ay as SeriesPoint, az as StructureKind, aA as StructureNode, aB as Unsubscribe, aC as User, aD as ValueAnchor, aE as WeekStartDay } from './types-BiRAlSSk.js';
|
|
3
3
|
export { A as AppConsoleEvent, a as AppErrorEvent, b as AppErrorKind } from './runtimeErrors-gswksjDk.js';
|
|
4
|
-
export { B as BridgeError, a as BridgeMessage, D as DEFAULT_TOKENS, b as DESIGN_TOKENS, F as FrameMessage, H as HostMessage, M as MenuEntry, c as MenuTarget, d as MenuTargetKind, N as NodeTarget, P as PROVISION_ELEMENT_ID, e as PluginInfo, f as Provision, R as RowsTarget, T as THEME_TOKENS, g as
|
|
4
|
+
export { B as BridgeError, a as BridgeMessage, D as DEFAULT_TOKENS, b as DESIGN_TOKENS, F as FrameMessage, H as HostMessage, M as MenuEntry, c as MenuTarget, d as MenuTargetKind, N as NodeTarget, P as PROVISION_ELEMENT_ID, e as PluginInfo, f as Provision, R as RowsTarget, T as THEME_TOKENS, g as TargetPoint, h as TargetRect, i as Theme, j as ThemeInput, k as ThemeScheme, l as ThemeToken, m as ThemeTokens, n as checkTarget, o as designTheme, r as resolveTheme } from './theme-C9Tuzqu7.js';
|
package/dist/common.js
CHANGED
package/dist/host.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginInfo, Theme, ThemeInput, Provision } from './app.js';
|
|
2
2
|
import { DatasetDescriptor, User } from './app.js';
|
|
3
|
-
import { C as Command, T as Tab, a as CallOptions, P as Panel, b as CommandState, c as Plugin, M as Middleware, d as CommandContribution, e as TabContribution, f as Contribution } from './plugin-
|
|
4
|
-
export { g as CallContext, h as CallDefinition, i as CallHandler, j as Caller, k as CommandRun, l as CommandStateContext, E as EventCheck, F as FrameHalf, H as HandlerCallOptions, m as HandlerContext, n as HostHalf, o as MountContext, p as PanelVerb, S as Snapshot, q as TabContext, r as definePlugin } from './plugin-
|
|
3
|
+
import { C as Command, T as Tab, a as CallOptions, P as Panel, b as CommandState, c as Plugin, M as Middleware, d as CommandContribution, e as TabContribution, f as Contribution } from './plugin-CG0mVS1X.js';
|
|
4
|
+
export { g as CallContext, h as CallDefinition, i as CallHandler, j as Caller, k as CommandRun, l as CommandStateContext, E as EventCheck, F as FrameHalf, H as HandlerCallOptions, m as HandlerContext, n as HostHalf, o as MountContext, p as PanelVerb, S as Snapshot, q as TabContext, r as definePlugin } from './plugin-CG0mVS1X.js';
|
|
5
5
|
export { A as AppConsoleEvent, a as AppErrorEvent, b as AppErrorKind } from './runtimeErrors-gswksjDk.js';
|
|
6
6
|
|
|
7
7
|
interface HostOptions {
|