@holistics/anfra-sdk 0.13.4 → 0.14.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.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/dist/api.d.ts +1 -1
  3. package/dist/app.d.ts +5 -4
  4. package/dist/app.js +17 -7
  5. package/dist/{bootstrap-DctKHBAj.d.ts → bootstrap-MhTSkiA1.d.ts} +97 -4
  6. package/dist/build.d.ts +2 -0
  7. package/dist/chunk-7IHICYVH.js +10 -0
  8. package/dist/chunk-CYZQ7ZTJ.js +237 -0
  9. package/dist/chunk-DITKCHFQ.js +166 -0
  10. package/dist/chunk-F6MRA7J4.js +65 -0
  11. package/dist/chunk-GBXK7F2V.js +431 -0
  12. package/dist/chunk-GOUDXWG4.js +750 -0
  13. package/dist/chunk-GV7SVWEK.js +84 -0
  14. package/dist/chunk-H52PO7MP.js +105 -0
  15. package/dist/chunk-HI3ZAXJK.js +8 -0
  16. package/dist/{chunk-ZHIDMLJH.js → chunk-HZEECB6R.js} +477 -25
  17. package/dist/chunk-K633QHGO.js +51 -0
  18. package/dist/chunk-KFD6CHLI.js +38 -0
  19. package/dist/{chunk-2Q4HPPUK.js → chunk-NOFPRSSI.js} +1 -1
  20. package/dist/{chunk-ADWBOQW2.js → chunk-S6XLP6U4.js} +31 -1
  21. package/dist/{chunk-TQ7S5DRE.js → chunk-WI5VJ2Z6.js} +1 -1
  22. package/dist/common.d.ts +2 -2
  23. package/dist/common.js +14 -4
  24. package/dist/data-UCCW2VWH.js +233 -0
  25. package/dist/declaration-GVDOGQY6.js +218 -0
  26. package/dist/host.d.ts +42 -4
  27. package/dist/host.js +412 -9
  28. package/dist/menu-CdGVKc4_.d.ts +151 -0
  29. package/dist/overview-3DNXEQNY.js +358 -0
  30. package/dist/plugin-BmIDirTx.d.ts +303 -0
  31. package/dist/plugins.d.ts +6 -8
  32. package/dist/plugins.js +98 -69
  33. package/dist/queries-2OHKMTPC.js +661 -0
  34. package/dist/structure-WRDUXHD4.js +256 -0
  35. package/dist/tab-HMQOITVM.js +932 -0
  36. package/dist/testing.js +4 -4
  37. package/dist/{types-B9DqPgWS.d.ts → types-CWNv6N0y.d.ts} +10 -0
  38. package/package.json +1 -1
  39. package/dist/bridge-_Ez5VZV9.d.ts +0 -73
  40. package/dist/chunk-33B2D4U5.js +0 -6
  41. package/dist/plugin-056-SKwd.d.ts +0 -132
  42. /package/dist/{chunk-52LXBYQM.js → chunk-UUKXJSE4.js} +0 -0
@@ -0,0 +1,151 @@
1
+ import { D as DatasetDescriptor, aj as User, ah as StructureNode, aa as Row, ae as SelectionCondition } from './types-CWNv6N0y.js';
2
+
3
+ /**
4
+ * The bridge: the postMessage protocol between a Data App's frame (`app`'s bootstrap) and the
5
+ * page hosting it (`host`). The frame has an opaque origin and no access to the API: everything it
6
+ * reaches crosses here, as a plugin's calls and events (docs/designs/sdk-plugins.md).
7
+ *
8
+ * Both sides speak the same messages. A call is answered by its `id`, which each side counts on
9
+ * its own: a result answers a call the other side made.
10
+ */
11
+
12
+ /** A plugin a host installed, as a frame sees it (`Anfra.plugins`). */
13
+ interface PluginInfo {
14
+ name: string;
15
+ version: string;
16
+ }
17
+ /** What the host provisions a frame with, as JSON in `<script type="application/json" id="anfra-provision">`. */
18
+ interface Provision {
19
+ datasets: Record<string, DatasetDescriptor>;
20
+ user: User;
21
+ /** Every plugin the host installed, whether or not it has a frame half. */
22
+ plugins: PluginInfo[];
23
+ /** The host page's origin: where the frame posts, so nothing else can read its messages. */
24
+ hostOrigin: string;
25
+ }
26
+ declare const PROVISION_ELEMENT_ID = "anfra-provision";
27
+ /** An error as it crosses the bridge: the SDK's error class by name, and its message. */
28
+ interface BridgeError {
29
+ name: string;
30
+ message: string;
31
+ }
32
+ type BridgeMessage =
33
+ /** Frame → host: the frame's kernel is running (once per load of its document). */
34
+ {
35
+ type: 'anfra:ready';
36
+ }
37
+ /** A plugin call, `<plugin>.<name>`, answered by an `anfra:result` with the same id. */
38
+ | {
39
+ type: 'anfra:call';
40
+ id: number;
41
+ name: string;
42
+ request: unknown;
43
+ } | {
44
+ type: 'anfra:result';
45
+ id: number;
46
+ ok: true;
47
+ result: unknown;
48
+ } | {
49
+ type: 'anfra:result';
50
+ id: number;
51
+ ok: false;
52
+ error: BridgeError;
53
+ }
54
+ /** The caller gave up on its call: stop it. Nothing answers. */
55
+ | {
56
+ type: 'anfra:cancel';
57
+ id: number;
58
+ }
59
+ /** A bridge event, `<plugin>.<name>`. Nothing answers. */
60
+ | {
61
+ type: 'anfra:event';
62
+ name: string;
63
+ payload: unknown;
64
+ };
65
+ /** Frame → host. */
66
+ type FrameMessage = BridgeMessage;
67
+ /** Host → frame. */
68
+ type HostMessage = Exclude<BridgeMessage, {
69
+ type: 'anfra:ready';
70
+ }>;
71
+
72
+ /**
73
+ * The theme a host hands plugin UI: a light or dark scheme, and a fixed set of tokens, each a CSS
74
+ * custom property `--anfra-<token>`. A host maps its own design tokens onto them once; tabs, and
75
+ * frame halves in the plugin layer, use only these, so every plugin's UI follows every host. A
76
+ * definition may read them (`Anfra.theme`), and is never styled by them unasked.
77
+ */
78
+ type ThemeScheme = 'light' | 'dark';
79
+ /** The tokens, by name: each is the CSS custom property `--anfra-<name>`. */
80
+ declare const THEME_TOKENS: readonly ["color-bg", "color-fg", "color-muted", "color-border", "color-accent", "color-danger", "radius", "font", "font-mono"];
81
+ type ThemeToken = typeof THEME_TOKENS[number];
82
+ type ThemeTokens = Record<ThemeToken, string>;
83
+ /** A theme as a host gives it: the scheme, and the tokens it sets (the others keep the scheme's defaults). */
84
+ interface ThemeInput {
85
+ scheme: ThemeScheme;
86
+ tokens?: Partial<ThemeTokens>;
87
+ }
88
+ /** A theme with every token: what plugin UI and `Anfra.theme` read. */
89
+ interface Theme {
90
+ readonly scheme: ThemeScheme;
91
+ readonly tokens: Readonly<ThemeTokens>;
92
+ }
93
+ /** Each scheme's tokens where the host sets none. */
94
+ declare const DEFAULT_TOKENS: Readonly<Record<ThemeScheme, Readonly<ThemeTokens>>>;
95
+ /**
96
+ * A theme with every token, from what a host or the bridge gives: the scheme's defaults under the
97
+ * tokens set, and each value that isn't a short, plain CSS value left at its default.
98
+ */
99
+ declare function resolveTheme(input: unknown): Theme;
100
+
101
+ /**
102
+ * What a menu on a Data App's content is about: a marked node of the page (a right-click on a
103
+ * block), or some of a query's result rows (a right-click on a chart's point, which the definition
104
+ * reports with `query.menu`). Built in the frame, and checked by the host, which trusts nothing the
105
+ * frame sends.
106
+ */
107
+
108
+ /** A box in the frame's viewport. */
109
+ interface TargetRect {
110
+ x: number;
111
+ y: number;
112
+ width: number;
113
+ height: number;
114
+ }
115
+ /** A marked node, as the structure has it, its ancestors outermost first (both without children's children), and where it is. */
116
+ interface NodeTarget {
117
+ kind: 'node';
118
+ node: StructureNode;
119
+ ancestors: StructureNode[];
120
+ rect: TargetRect;
121
+ }
122
+ /**
123
+ * Rows of a query's result: the query, by its app's index and name; the rows as the definition
124
+ * passed them; the dimensions that took part; and the conditions they make, derived as a
125
+ * cross-filter's are (an AQL `expression` when per-field conditions would admit more rows). With
126
+ * the node the rows are drawn in, when the event was inside one.
127
+ */
128
+ interface RowsTarget {
129
+ kind: 'rows';
130
+ app: number;
131
+ query: string;
132
+ rows: Row[];
133
+ fields: string[];
134
+ conditions: SelectionCondition[];
135
+ expression?: string;
136
+ node?: NodeTarget;
137
+ }
138
+ type MenuTarget = NodeTarget | RowsTarget;
139
+ type MenuTargetKind = MenuTarget['kind'];
140
+ /** One entry of a menu, as the host answers it for a target. */
141
+ interface MenuEntry {
142
+ id: string;
143
+ label: string;
144
+ /** Why it can't run: shown, and the entry can't be picked. */
145
+ disabled?: string;
146
+ }
147
+ /** A target as the frame sends it, or undefined when it isn't one: of its shape only, never trusted further. */
148
+ declare function checkTarget(value: unknown): MenuTarget | undefined;
149
+
150
+ export { DEFAULT_TOKENS as D, PROVISION_ELEMENT_ID as P, THEME_TOKENS as T, checkTarget as l, resolveTheme as r };
151
+ export type { BridgeError as B, FrameMessage as F, HostMessage as H, MenuEntry as M, NodeTarget as N, RowsTarget as R, BridgeMessage as a, MenuTarget as b, MenuTargetKind as c, PluginInfo as d, Provision as e, TargetRect as f, Theme as g, ThemeInput as h, ThemeScheme as i, ThemeToken as j, ThemeTokens as k };
@@ -0,0 +1,358 @@
1
+ import {
2
+ changesOf,
3
+ issuesOf,
4
+ queryCounts
5
+ } from "./chunk-GV7SVWEK.js";
6
+ import {
7
+ controlTargets
8
+ } from "./chunk-DITKCHFQ.js";
9
+ import {
10
+ PLUGIN_VERSION
11
+ } from "./chunk-7IHICYVH.js";
12
+ import {
13
+ queriesOf,
14
+ stateOf
15
+ } from "./chunk-CYZQ7ZTJ.js";
16
+ import "./chunk-NOFPRSSI.js";
17
+ import {
18
+ LEVELS,
19
+ TRUST_LEVELS,
20
+ appTrust,
21
+ collapsible,
22
+ drawTab,
23
+ fields,
24
+ h,
25
+ icon,
26
+ link,
27
+ note,
28
+ popover,
29
+ trustBars
30
+ } from "./chunk-GOUDXWG4.js";
31
+ import "./chunk-K633QHGO.js";
32
+ import {
33
+ QUERIES_TAB,
34
+ formatAgo,
35
+ formatTime,
36
+ plural,
37
+ usageOf
38
+ } from "./chunk-H52PO7MP.js";
39
+ import "./chunk-PKBMQBKP.js";
40
+
41
+ // src/plugins/inspect/tabs/overview.ts
42
+ var FIRST_ISSUES = 5;
43
+ var TICK_MS = 3e4;
44
+ var CSS = `
45
+ .overview { display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }
46
+ .statusbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
47
+ .statusbar .pop-trigger.pill, .count { display: inline-flex; align-items: center; gap: 5px; border: 0; padding: 2px 9px; font-variant-numeric: tabular-nums; }
48
+ .count { border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--hover); color: var(--anfra-color-fg); }
49
+ .count:hover { filter: brightness(0.95); }
50
+ .count.error { background: var(--danger-bg); color: var(--anfra-color-danger); }
51
+ .count.executing { background: color-mix(in srgb, var(--run) 16%, transparent); color: var(--run); }
52
+ .count.dirty { background: var(--warn-bg); color: var(--warn); }
53
+ .count .dot { width: 6px; height: 6px; }
54
+ .dot.dirty { background: var(--warn); }
55
+ .tile { padding: 12px 14px; border-radius: 10px; background: var(--subtle); min-width: 0; }
56
+ .eyebrow { margin: 0; display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--anfra-color-muted); }
57
+ .eyebrow strong { color: var(--anfra-color-fg); }
58
+ .eyebrow .pop-trigger { color: var(--anfra-color-muted); cursor: help; }
59
+ .trust-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
60
+ .trust-level { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.2; }
61
+ .trust-level span { display: block; font-size: 13px; font-weight: 500; }
62
+ .trust-why { margin: 2px 0 0; font-size: 12px; color: var(--anfra-color-muted); }
63
+ .stats { display: grid; gap: 10px; }
64
+ .stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
65
+ .stats.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
66
+ .stat { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; border: 0; text-align: left; }
67
+ .stat:hover:not(:disabled) { background: var(--hover); }
68
+ .stat .go { position: absolute; top: 12px; right: 12px; color: var(--anfra-color-muted); opacity: 0; }
69
+ .stat:hover .go, .stat:focus-visible .go { opacity: 1; }
70
+ .stat-value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
71
+ .stat-detail { width: 100%; font-size: 12px; color: var(--anfra-color-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
72
+ .issues { list-style: none; margin: 4px 0 0; padding: 0; }
73
+ .issue { display: flex; align-items: flex-start; gap: 8px; width: 100%; border: 0; border-radius: 6px; background: none; padding: 5px 6px; text-align: left; overflow-wrap: anywhere; }
74
+ .issue:hover { background: var(--hover); }
75
+ .issue .mark { flex: none; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; }
76
+ .issue .mark.error { background: var(--anfra-color-danger); } .issue .mark.warn { background: var(--warn); }
77
+ .overview > h5 { margin: 6px 0 0; }
78
+ .tile.collapsible { padding: 6px 12px; }
79
+ .tile.collapsible > summary { font-weight: 500; }
80
+ .tile.collapsible > summary .muted { margin-left: auto; font-weight: normal; font-size: 12px; }
81
+ .changes { list-style: none; margin: 0; padding: 0; }
82
+ .change { display: flex; align-items: center; gap: 2px; padding: 3px 0; }
83
+ .change > .link { flex: 1; min-width: 0; flex-direction: column; align-items: flex-start; color: var(--anfra-color-fg); font-size: 12px; text-align: left; }
84
+ .change .from { text-decoration: line-through; color: var(--anfra-color-muted); }
85
+ .warning { margin: 0 0 8px; padding: 6px 8px; border-radius: 6px; background: var(--warn-bg); color: var(--warn); font-size: 12px; }
86
+ .levels { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
87
+ .levels > li { display: flex; align-items: flex-start; gap: 8px; padding: 3px 6px; border-radius: 6px; }
88
+ .levels > li > .bars { margin-top: 3px; }
89
+ .levels > li[aria-current] { background: var(--hover); }
90
+ .levels ul { margin: 1px 0 0; padding-left: 14px; color: var(--anfra-color-muted); }
91
+ .trust-pop { display: block; width: 300px; }
92
+ .trust-pop header { display: flex; align-items: center; gap: 8px; font-weight: 600; }
93
+ `;
94
+ function overviewTab(root, context) {
95
+ const doc = context.document;
96
+ const { panel, mount } = context;
97
+ const state = stateOf(mount);
98
+ let allIssues = false;
99
+ const reveal = (target) => state.reveal(panel, target);
100
+ const showQueries = (filter) => reveal({ tab: QUERIES_TAB, filter });
101
+ const trustLevels = (trust) => h(
102
+ doc,
103
+ "span",
104
+ { class: "trust-pop", "data-testid": "trust-levels" },
105
+ h(doc, "header", {}, trustBars(doc, trust, "md"), h(doc, "span", { class: `tone-${trust.tone}` }, `Level ${trust.level} \xB7 ${TRUST_LEVELS[trust.level].name}`)),
106
+ h(doc, "span", { class: "trust-why" }, trust.text),
107
+ h(doc, "p", { class: "trust-why" }, "How far the numbers trace back to the semantic layer:"),
108
+ h(doc, "ol", { class: "levels" }, LEVELS.map((level) => {
109
+ const { name, points, tone } = TRUST_LEVELS[level];
110
+ return h(
111
+ doc,
112
+ "li",
113
+ { "aria-current": level === trust.level ? "true" : void 0 },
114
+ trustBars(doc, { level, tone, text: "" }, "sm"),
115
+ h(doc, "span", {}, h(doc, "strong", {}, `${level}. ${name}`), h(doc, "ul", {}, points.map((point) => h(doc, "li", {}, point))))
116
+ );
117
+ }))
118
+ );
119
+ function statusBar(apps) {
120
+ const counts = queryCounts(apps);
121
+ const items = [
122
+ { n: counts.success, label: "ok", dot: "success", filter: "all" },
123
+ { n: counts.error, label: "error", dot: "error", filter: "errors" },
124
+ { n: counts.executing, label: "running", dot: "executing", filter: "all" },
125
+ { n: counts.idle, label: "idle", dot: "idle", filter: "all" },
126
+ { n: counts.dirty + counts.dirtyControls, label: "dirty", dot: "dirty", filter: "dirty" }
127
+ ];
128
+ const shown = items.filter((item) => item.n > 0);
129
+ const trust = apps.length ? apps.map(appTrust).reduce((lowest, t) => t.level < lowest.level ? t : lowest) : void 0;
130
+ return h(
131
+ doc,
132
+ "div",
133
+ { class: "statusbar", "data-testid": "status-bar" },
134
+ trust && popover(doc, [h(doc, "span", { class: `tone-${trust.tone}` }, `L${trust.level}`), TRUST_LEVELS[trust.level].name], () => trustLevels(trust), {
135
+ class: "pop-trigger pill",
136
+ "data-key": "status:trust",
137
+ "data-testid": "status-trust",
138
+ "aria-label": `Trust level ${trust.level}: ${TRUST_LEVELS[trust.level].name}`
139
+ }),
140
+ shown.length === 0 && h(doc, "span", { class: "pill", "data-testid": "status-none" }, "No queries"),
141
+ shown.map((item) => h(doc, "button", {
142
+ type: "button",
143
+ class: `count ${item.dot}`,
144
+ "data-tip": "Show in Queries",
145
+ "data-key": `status:${item.label}`,
146
+ "data-testid": `status-${item.label}`,
147
+ onclick: () => showQueries(item.filter)
148
+ }, h(doc, "span", { class: `dot ${item.dot}` }), `${item.n} ${item.label}`))
149
+ );
150
+ }
151
+ function trustCard(app, label) {
152
+ const trust = appTrust(app);
153
+ return h(
154
+ doc,
155
+ "section",
156
+ { class: "tile", "data-testid": "trust-card" },
157
+ h(
158
+ doc,
159
+ "p",
160
+ { class: "eyebrow" },
161
+ h(doc, "span", {}, label && h(doc, "strong", {}, `${label} \xB7 `), "Trust level"),
162
+ popover(doc, icon(doc, "info"), () => trustLevels(trust), { "aria-label": "About trust levels", "data-key": `trust:${label ?? ""}` })
163
+ ),
164
+ h(
165
+ doc,
166
+ "div",
167
+ { class: "trust-row" },
168
+ trustBars(doc, trust, "lg"),
169
+ h(
170
+ doc,
171
+ "div",
172
+ {},
173
+ h(doc, "p", { class: `trust-level tone-${trust.tone}` }, `Level ${trust.level}`, h(doc, "span", {}, TRUST_LEVELS[trust.level].name)),
174
+ h(doc, "p", { class: "trust-why" }, trust.text)
175
+ )
176
+ )
177
+ );
178
+ }
179
+ function stat(id, title, value, detail, onclick, tone) {
180
+ return h(
181
+ doc,
182
+ "button",
183
+ {
184
+ type: "button",
185
+ class: "tile stat",
186
+ disabled: !onclick,
187
+ "data-key": `stat:${id}`,
188
+ "data-testid": `stat-${id}`,
189
+ onclick
190
+ },
191
+ h(doc, "span", { class: "eyebrow" }, title),
192
+ h(doc, "span", { class: `stat-value${tone ? ` tone-${tone}` : ""}` }, value),
193
+ h(doc, "span", { class: "stat-detail", "data-tip": detail }, detail),
194
+ onclick && h(doc, "span", { class: "go" }, icon(doc, "chevron"))
195
+ );
196
+ }
197
+ function stats(apps, issues, requests) {
198
+ const counts = queryCounts(apps);
199
+ const errors = issues.filter((issue) => issue.level === "error").length;
200
+ const warnings = issues.length - errors;
201
+ const controls = apps.reduce((n, app) => n + Object.keys(app.controls).length, 0);
202
+ const unapplied = counts.dirtyControls;
203
+ const last = requests.findLast((entry) => entry.call === "core.submitQuery" && entry.status !== "pending");
204
+ const lastQuery = last?.aql && last.dataset ? queriesOf({ ...last, dataset: last.dataset, aql: last.aql }, apps)[0] : void 0;
205
+ const first = issues[0];
206
+ const queries = [
207
+ `${counts.success} ok`,
208
+ counts.error && `${counts.error} failed`,
209
+ counts.executing && `${counts.executing} running`,
210
+ counts.idle && `${counts.idle} idle`
211
+ ].filter(Boolean).join(" \xB7 ");
212
+ return [
213
+ h(
214
+ doc,
215
+ "div",
216
+ { class: "stats three" },
217
+ stat(
218
+ "issues",
219
+ "Issues",
220
+ String(issues.length),
221
+ issues.length ? `${plural(errors, "error")} \xB7 ${plural(warnings, "warning")}` : "None found",
222
+ // Failed queries are what Queries' Errors filter lists; warnings have no such list.
223
+ counts.error ? () => showQueries("errors") : first ? () => reveal(first.target) : void 0,
224
+ errors ? "error" : warnings ? "warn" : void 0
225
+ ),
226
+ stat("queries", "Queries", String(counts.total), queries, () => showQueries("all"), counts.error ? "error" : void 0),
227
+ stat("controls", "Controls", String(controls), unapplied ? `${unapplied} unapplied` : "All applied", () => showQueries("all"), unapplied ? "warn" : void 0)
228
+ ),
229
+ h(
230
+ doc,
231
+ "div",
232
+ { class: "stats two" },
233
+ stat(
234
+ "last-request",
235
+ "Last request",
236
+ last ? h(doc, "span", { "data-tip": formatTime(last.at) }, formatAgo(last.at)) : "\u2014",
237
+ last ? lastQuery?.name ?? "no query" : "Nothing has run yet",
238
+ lastQuery && (() => reveal({ entity: "query", ...lastQuery })),
239
+ last?.status === "error" ? "error" : void 0
240
+ ),
241
+ stat(
242
+ "last-duration",
243
+ "Last run duration",
244
+ last?.durationMs !== void 0 ? `${last.durationMs} ms` : "\u2014",
245
+ !last ? "\u2014" : last.status !== "ok" ? last.status : last.fromCache ? "from cache" : "from database"
246
+ )
247
+ )
248
+ ];
249
+ }
250
+ function issuesList(issues) {
251
+ if (issues.length === 0) return void 0;
252
+ const shown = allIssues ? issues : issues.slice(0, FIRST_ISSUES);
253
+ return [
254
+ h(doc, "h5", {}, "Issues"),
255
+ h(doc, "ul", { class: "issues", "data-testid": "issues" }, shown.map((issue, i) => h(
256
+ doc,
257
+ "li",
258
+ {},
259
+ h(doc, "button", {
260
+ type: "button",
261
+ class: "issue",
262
+ "data-key": `issue:${i}`,
263
+ "data-testid": "issue",
264
+ onclick: () => reveal(issue.target)
265
+ }, h(doc, "span", { class: `mark ${issue.level}`, role: "img", "aria-label": issue.level === "error" ? "Error" : "Warning" }), issue.message)
266
+ ))),
267
+ issues.length > FIRST_ISSUES && link(doc, allIssues ? "Show fewer" : `Show all ${issues.length}`, () => {
268
+ allIssues = !allIssues;
269
+ tab.redraw();
270
+ }, { "data-key": "issues:all", "data-testid": "issues-all" })
271
+ ];
272
+ }
273
+ function changes(snapshot) {
274
+ const { apps, structure } = snapshot;
275
+ const list = changesOf(apps);
276
+ return collapsible(doc, "changes", ["Changes from the original", h(doc, "span", { class: "muted" }, list.length ? plural(list.length, "change") : "none")], () => list.length === 0 ? h(doc, "p", { class: "muted" }, "Every control is still as the app declared it.") : h(doc, "ul", { class: "changes", "data-testid": "changes" }, list.map((change) => {
277
+ const app = apps[change.app];
278
+ const targets = controlTargets(app, change.name).map((target) => target.query);
279
+ const show = () => reveal({ entity: "control", app: change.app, name: change.name });
280
+ return h(
281
+ doc,
282
+ "li",
283
+ { class: "change", "data-testid": "change" },
284
+ link(doc, [
285
+ h(doc, "strong", {}, `${apps.length > 1 ? `App ${change.app + 1} \xB7 ` : ""}${change.name}`),
286
+ h(doc, "span", {}, h(doc, "span", { class: "from" }, change.from), " \u2192 ", change.to)
287
+ ], show, { "data-tip": targets.length ? `Applies to ${targets.join(", ")}` : "Applies to no query", "data-key": `change:${change.app}/${change.name}` }),
288
+ usageOf(structure, "control", change.app, change.name) && h(doc, "button", {
289
+ type: "button",
290
+ class: "row-action",
291
+ "data-tip": "Highlight on the page",
292
+ "aria-label": "Highlight on the page",
293
+ "data-testid": "change-locate",
294
+ onclick: () => panel.locate({ app: change.app, kind: "control", name: change.name })
295
+ }, icon(doc, "locate")),
296
+ h(doc, "button", {
297
+ type: "button",
298
+ class: "row-action",
299
+ "data-tip": "Show in Queries",
300
+ "aria-label": "Show in Queries",
301
+ "data-testid": "change-show",
302
+ onclick: show
303
+ }, icon(doc, "query"))
304
+ );
305
+ })), { class: "tile" });
306
+ }
307
+ function environment(apps) {
308
+ const { user } = mount;
309
+ const datasets = Object.values(mount.datasets).map((dataset) => dataset.label || dataset.name);
310
+ const label = (index) => apps.length > 1 ? `App ${index + 1}` : "the app";
311
+ const mismatched = apps.flatMap((app, index) => app.timezone && app.timezone !== user.timezone ? [`${label(index)} runs in ${app.timezone}`] : []);
312
+ return collapsible(doc, "environment", "Environment", () => [
313
+ mismatched.length > 0 && h(
314
+ doc,
315
+ "p",
316
+ { class: "warning", role: "note", "data-testid": "timezone-warning" },
317
+ `The reader is in ${user.timezone}, but ${mismatched.join(", ")}: dates are computed in the app's timezone.`
318
+ ),
319
+ fields(doc, [
320
+ ["SDK", PLUGIN_VERSION],
321
+ ["Reader", `${user.name} \xB7 ${user.email} \xB7 ${user.role}`],
322
+ ["Reader timezone", user.timezone],
323
+ ...apps.map((app, index) => [apps.length > 1 ? `App ${index + 1} timezone` : "App timezone", app.timezone || "tenant default"]),
324
+ ["Generated SQL", user.permissions.canViewGeneratedSql ? "can view" : "hidden"],
325
+ ["Export", user.permissions.canExportData ? "allowed" : "not allowed"],
326
+ // The log keeps the newest 200, so this stops there.
327
+ ["Requests", `${state.requests.entries().length} since the app loaded`],
328
+ [`Datasets (${datasets.length})`, datasets.join(", ") || "none"]
329
+ ], { "data-testid": "environment" })
330
+ ], { class: "tile" });
331
+ }
332
+ const tab = drawTab(root, context, () => {
333
+ const { snapshot } = panel;
334
+ if (!snapshot) return note(doc, "Waiting for the Data App\u2026", { "data-testid": "inspect-waiting" });
335
+ const { apps } = snapshot;
336
+ const issues = issuesOf(snapshot);
337
+ return h(
338
+ doc,
339
+ "div",
340
+ { class: "overview" },
341
+ statusBar(apps),
342
+ apps.length === 0 ? note(doc, "This Data App hasn't created an SDK app.", { "data-testid": "no-apps" }) : apps.map((app, index) => trustCard(app, apps.length > 1 ? `App ${index + 1}` : void 0)),
343
+ stats(apps, issues, state.requests.entries()),
344
+ issuesList(issues),
345
+ changes(snapshot),
346
+ environment(apps)
347
+ );
348
+ }, { also: [state.subscribe] });
349
+ root.append(h(doc, "style", {}, CSS));
350
+ const timer = setInterval(tab.redraw, TICK_MS);
351
+ return () => {
352
+ clearInterval(timer);
353
+ tab.dispose();
354
+ };
355
+ }
356
+ export {
357
+ overviewTab as default
358
+ };