@holistics/anfra-sdk 0.13.5 → 0.14.1

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 (40) hide show
  1. package/README.md +1 -1
  2. package/dist/app.d.ts +4 -3
  3. package/dist/app.js +17 -7
  4. package/dist/{bootstrap-BbsNvZ8s.d.ts → bootstrap-MhTSkiA1.d.ts} +96 -3
  5. package/dist/build.d.ts +2 -0
  6. package/dist/chunk-A3LNZMT6.js +10 -0
  7. package/dist/chunk-CYZQ7ZTJ.js +237 -0
  8. package/dist/chunk-DITKCHFQ.js +166 -0
  9. package/dist/chunk-F6MRA7J4.js +65 -0
  10. package/dist/chunk-GBXK7F2V.js +431 -0
  11. package/dist/chunk-GOUDXWG4.js +750 -0
  12. package/dist/chunk-GV7SVWEK.js +84 -0
  13. package/dist/chunk-H52PO7MP.js +105 -0
  14. package/dist/chunk-HI3ZAXJK.js +8 -0
  15. package/dist/{chunk-KI5CAVAR.js → chunk-HRV45ULB.js} +477 -25
  16. package/dist/chunk-K633QHGO.js +51 -0
  17. package/dist/chunk-KFD6CHLI.js +38 -0
  18. package/dist/{chunk-OJ5WIKWE.js → chunk-Q46CZIEK.js} +1 -1
  19. package/dist/{chunk-ADWBOQW2.js → chunk-S6XLP6U4.js} +31 -1
  20. package/dist/{chunk-TQ7S5DRE.js → chunk-WI5VJ2Z6.js} +1 -1
  21. package/dist/common.d.ts +1 -1
  22. package/dist/common.js +14 -4
  23. package/dist/data-UCCW2VWH.js +233 -0
  24. package/dist/declaration-GVDOGQY6.js +218 -0
  25. package/dist/host.d.ts +42 -4
  26. package/dist/host.js +412 -9
  27. package/dist/menu-CdGVKc4_.d.ts +151 -0
  28. package/dist/overview-XXND2V5V.js +358 -0
  29. package/dist/plugin-BmIDirTx.d.ts +303 -0
  30. package/dist/plugins.d.ts +6 -8
  31. package/dist/plugins.js +98 -69
  32. package/dist/queries-2OHKMTPC.js +661 -0
  33. package/dist/structure-WRDUXHD4.js +256 -0
  34. package/dist/tab-HMQOITVM.js +932 -0
  35. package/dist/testing.js +4 -4
  36. package/package.json +1 -1
  37. package/dist/bridge-WC7GliCH.d.ts +0 -73
  38. package/dist/chunk-33B2D4U5.js +0 -6
  39. package/dist/plugin-056-SKwd.d.ts +0 -132
  40. /package/dist/{chunk-52LXBYQM.js → chunk-UUKXJSE4.js} +0 -0
@@ -2,14 +2,20 @@ import {
2
2
  FILTER_AGGREGATIONS
3
3
  } from "./chunk-XIUFHRZE.js";
4
4
  import {
5
- createEndpoint
6
- } from "./chunk-ADWBOQW2.js";
5
+ createEndpoint,
6
+ eventShortcut,
7
+ isTyping,
8
+ normalizeShortcut
9
+ } from "./chunk-S6XLP6U4.js";
7
10
  import {
8
- PROVISION_ELEMENT_ID
9
- } from "./chunk-33B2D4U5.js";
11
+ DEFAULT_TOKENS,
12
+ PROVISION_ELEMENT_ID,
13
+ applyTheme,
14
+ resolveTheme
15
+ } from "./chunk-F6MRA7J4.js";
10
16
  import {
11
17
  version
12
- } from "./chunk-OJ5WIKWE.js";
18
+ } from "./chunk-Q46CZIEK.js";
13
19
  import {
14
20
  DataAppError,
15
21
  PermissionError,
@@ -179,6 +185,16 @@ var Query = class extends Observable {
179
185
  this._page += 1;
180
186
  await this.app.fetchPage(this);
181
187
  }
188
+ /**
189
+ * Opens the menu on these rows of this query: the items plugins and the host offer for a point
190
+ * of data, such as "View underlying data". Call it from your chart's own right-click handler,
191
+ * with the event and the rows under the pointer, as for `select`; `fields` narrows the dimensions
192
+ * that take part. Whether a menu opens: when one does, the event's default (the browser's menu)
193
+ * is prevented, and when none would (no plugin offers one), nothing happens.
194
+ */
195
+ menu(event, rows, options = {}) {
196
+ return this.app.menu(this, event, Array.isArray(rows) ? rows : [rows], options.fields);
197
+ }
182
198
  /**
183
199
  * Cross-filters this query's targets by the rows the reader picked.
184
200
  *
@@ -480,6 +496,36 @@ var CrossFilter = class {
480
496
  }
481
497
  };
482
498
 
499
+ // src/app/layer.ts
500
+ var LAYER_ATTRIBUTE = "data-anfra-layer";
501
+ var themes = /* @__PURE__ */ new WeakMap();
502
+ var LAYER_STYLE = "position:absolute;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483647;";
503
+ function layerOf(doc) {
504
+ const existing = doc.querySelector(`[${LAYER_ATTRIBUTE}]`);
505
+ if (existing instanceof (doc.defaultView?.HTMLElement ?? HTMLElement)) return existing;
506
+ const layer = doc.createElement("div");
507
+ layer.setAttribute(LAYER_ATTRIBUTE, "");
508
+ layer.setAttribute("style", LAYER_STYLE);
509
+ const theme = themes.get(doc);
510
+ if (theme) applyTheme(layer.style, theme);
511
+ (doc.body ?? doc.documentElement).appendChild(layer);
512
+ return layer;
513
+ }
514
+ function layerRoot(doc, part) {
515
+ const layer = layerOf(doc);
516
+ const host = [...layer.children].find((child) => child.getAttribute("data-part") === part);
517
+ if (host?.shadowRoot) return host.shadowRoot;
518
+ const element = doc.createElement("div");
519
+ element.setAttribute("data-part", part);
520
+ layer.appendChild(element);
521
+ return element.attachShadow({ mode: "open" });
522
+ }
523
+ function themeLayer(doc, theme) {
524
+ themes.set(doc, theme);
525
+ const existing = doc.querySelector(`[${LAYER_ATTRIBUTE}]`);
526
+ if (existing) applyTheme(existing.style, theme);
527
+ }
528
+
483
529
  // src/app/structure.ts
484
530
  var ATTR = {
485
531
  container: "data-anfra-container",
@@ -587,27 +633,214 @@ function buildStructure(doc, apps) {
587
633
  keysOf
588
634
  };
589
635
  }
636
+ var usageKey = (kind, app, name) => `${kind}:${app}/${name}`;
637
+ function sizeOf(element) {
638
+ const rect = element.getBoundingClientRect();
639
+ return `${Math.round(rect.width)} \xD7 ${Math.round(rect.height)}`;
640
+ }
641
+ function describeNode(node, element, structure) {
642
+ const size = sizeOf(element);
643
+ if (node.kind === "container" || node.kind === "block") {
644
+ return {
645
+ kind: node.kind,
646
+ name: node.id ?? "",
647
+ ...node.label ? { label: node.label } : {},
648
+ size
649
+ };
650
+ }
651
+ const use = structure.usage[usageKey(node.kind, node.app ?? 0, node.name ?? "")];
652
+ return {
653
+ kind: node.kind,
654
+ name: node.name ?? "",
655
+ ...use && use.markers > 1 ? { note: `1 of ${use.markers}` } : {},
656
+ size
657
+ };
658
+ }
590
659
 
591
- // src/app/layer.ts
592
- var LAYER_ATTRIBUTE = "data-anfra-layer";
593
- var LAYER_STYLE = "position:absolute;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483647;";
594
- function layerOf(doc) {
595
- const existing = doc.querySelector(`[${LAYER_ATTRIBUTE}]`);
596
- if (existing instanceof (doc.defaultView?.HTMLElement ?? HTMLElement)) return existing;
597
- const layer = doc.createElement("div");
598
- layer.setAttribute(LAYER_ATTRIBUTE, "");
599
- layer.setAttribute("style", LAYER_STYLE);
600
- (doc.body ?? doc.documentElement).appendChild(layer);
601
- return layer;
660
+ // src/app/menu.ts
661
+ var rowsOpener;
662
+ function openRowsMenu(event, target) {
663
+ return rowsOpener ? rowsOpener(event, target) : false;
602
664
  }
603
- function layerRoot(doc, part) {
604
- const layer = layerOf(doc);
605
- const host = [...layer.children].find((child) => child.getAttribute("data-part") === part);
606
- if (host?.shadowRoot) return host.shadowRoot;
607
- const element = doc.createElement("div");
608
- element.setAttribute("data-part", part);
609
- layer.appendChild(element);
610
- return element.attachShadow({ mode: "open" });
665
+ var BLOCK = `[${ATTR.block}]`;
666
+ var OPTED_OUT = '[data-anfra-menu="off"]';
667
+ var bare = (node) => ({ ...node, children: node.children.map((child) => ({ ...child, children: [] })) });
668
+ function pathTo(nodes, key, above = []) {
669
+ for (const node of nodes) {
670
+ if (node.key === key) return [...above, node];
671
+ const inner = pathTo(node.children, key, [...above, node]);
672
+ if (inner) return inner;
673
+ }
674
+ return void 0;
675
+ }
676
+ var isElement = (value) => typeof value?.closest === "function";
677
+ function installContentUi(kernel) {
678
+ const win = kernel.window;
679
+ const doc = win.document;
680
+ const items = [];
681
+ let hostKinds = /* @__PURE__ */ new Set();
682
+ let listening = false;
683
+ let current;
684
+ const ui = () => kernel.body();
685
+ const root = () => layerRoot(doc, "anfra-ui");
686
+ const offered = (kind) => hostKinds.has(kind) || items.some((item) => item.target === kind);
687
+ const closeCurrent = () => {
688
+ const close = current;
689
+ current = void 0;
690
+ close?.();
691
+ };
692
+ function blockOf(target) {
693
+ const element = isElement(target) ? target.closest(BLOCK) : null;
694
+ return element && !element.closest(OPTED_OUT) ? element : void 0;
695
+ }
696
+ function nodeTarget(element) {
697
+ const structure = kernel.structure();
698
+ const key = structure.keysOf.get(element)?.[0];
699
+ const path = key !== void 0 ? pathTo(structure.nodes, key) : void 0;
700
+ if (!path) return void 0;
701
+ const { x, y, width, height } = element.getBoundingClientRect();
702
+ return {
703
+ kind: "node",
704
+ node: bare(path[path.length - 1]),
705
+ ancestors: path.slice(0, -1).map((node) => ({ ...node, children: [] })),
706
+ rect: { x, y, width, height }
707
+ };
708
+ }
709
+ function frameEntries(target) {
710
+ const run = /* @__PURE__ */ new Map();
711
+ const entries = [];
712
+ for (const item of items) {
713
+ if (item.target !== target.kind) continue;
714
+ let applies = true;
715
+ try {
716
+ applies = item.when ? item.when(target) !== false : true;
717
+ } catch {
718
+ applies = false;
719
+ }
720
+ if (!applies) continue;
721
+ const key = `frame:${item.full}:${target.kind}`;
722
+ entries.push({ id: key, label: item.label });
723
+ run.set(key, () => item.run(target));
724
+ }
725
+ return { entries, run };
726
+ }
727
+ async function entriesFor(target, own) {
728
+ const run = new Map(own.run);
729
+ const entries = [...own.entries];
730
+ if (hostKinds.has(target.kind)) {
731
+ try {
732
+ const answered = await kernel.call("anfra.menu", target);
733
+ for (const entry of Array.isArray(answered) ? answered : []) {
734
+ if (typeof entry?.id !== "string" || typeof entry.label !== "string") continue;
735
+ const key = `host:${entry.id}:${target.kind}`;
736
+ entries.push({ id: key, label: entry.label, ...typeof entry.disabled === "string" ? { disabled: entry.disabled } : {} });
737
+ run.set(key, () => kernel.call("anfra.run", { id: entry.id, target }));
738
+ }
739
+ } catch {
740
+ }
741
+ }
742
+ return { entries, run };
743
+ }
744
+ function open(event, targets) {
745
+ const relevant = targets.map((target) => ({ target, own: frameEntries(target) })).filter(({ target, own }) => own.entries.length || hostKinds.has(target.kind));
746
+ if (!relevant.length) return false;
747
+ event.preventDefault();
748
+ const point = event;
749
+ const x = typeof point.clientX === "number" ? point.clientX : 0;
750
+ const y = typeof point.clientY === "number" ? point.clientY : 0;
751
+ void (async () => {
752
+ const [body, ...found] = await Promise.all([ui(), ...relevant.map(({ target, own }) => entriesFor(target, own))]);
753
+ const groups = found.map((group) => group.entries).filter((group) => group.length);
754
+ if (!groups.length) return;
755
+ closeCurrent();
756
+ const close = body.menu(root(), {
757
+ x,
758
+ y,
759
+ groups,
760
+ onPick: (key) => {
761
+ const action = found.map((group) => group.run.get(key)).find(Boolean);
762
+ Promise.resolve().then(action).catch((err) => win.console?.error("anfra: a menu item failed:", err));
763
+ },
764
+ onClose: () => {
765
+ if (current === close) current = void 0;
766
+ }
767
+ });
768
+ current = close;
769
+ })().catch((err) => win.console?.error("anfra: the menu failed to open:", err));
770
+ return true;
771
+ }
772
+ function listen() {
773
+ if (listening || !(offered("node") || offered("rows"))) return;
774
+ listening = true;
775
+ win.addEventListener("contextmenu", (event) => {
776
+ if (event.defaultPrevented || event.shiftKey) return;
777
+ const element = blockOf(event.target);
778
+ const target = element && nodeTarget(element);
779
+ if (target) open(event, [target]);
780
+ });
781
+ }
782
+ rowsOpener = (event, target) => {
783
+ if (event.defaultPrevented || event.shiftKey) return false;
784
+ const element = blockOf(event.target);
785
+ const node = element ? nodeTarget(element) : void 0;
786
+ const rows = node ? { ...target, node } : target;
787
+ return open(event, node ? [rows, node] : [rows]);
788
+ };
789
+ kernel.on("menu", (payload) => {
790
+ const kinds = payload?.kinds;
791
+ hostKinds = new Set((Array.isArray(kinds) ? kinds : []).filter((kind) => kind === "node" || kind === "rows"));
792
+ listen();
793
+ });
794
+ async function show(input, draw) {
795
+ const body = await ui();
796
+ closeCurrent();
797
+ let close = () => {
798
+ };
799
+ const onClose = () => {
800
+ if (current === close) current = void 0;
801
+ try {
802
+ input.onClose?.();
803
+ } catch {
804
+ }
805
+ };
806
+ close = draw(body, onClose);
807
+ current = close;
808
+ return { close };
809
+ }
810
+ return {
811
+ addItem(plugin, item) {
812
+ items.push({ ...item, full: `${plugin}.${item.id}` });
813
+ listen();
814
+ },
815
+ modal: (input) => show(input, (body, onClose) => body.modal(root(), {
816
+ title: input.title,
817
+ size: input.size,
818
+ mount: input.mount,
819
+ onClose
820
+ })),
821
+ popover: (input) => show(input, (body, onClose) => {
822
+ const { anchor } = input;
823
+ let rect;
824
+ if ("kind" in anchor) {
825
+ const element = kernel.structure().elements.get(anchor.node.key);
826
+ rect = () => {
827
+ if (!element?.isConnected) return void 0;
828
+ const { x, y, width, height } = element.getBoundingClientRect();
829
+ return { x, y, width, height };
830
+ };
831
+ } else {
832
+ rect = () => ({ x: anchor.x, y: anchor.y, width: 0, height: 0 });
833
+ }
834
+ return body.popover(root(), {
835
+ anchor: rect,
836
+ side: input.side,
837
+ mount: input.mount,
838
+ dismiss: input.dismiss,
839
+ closeButton: input.closeButton,
840
+ onClose
841
+ });
842
+ })
843
+ };
611
844
  }
612
845
 
613
846
  // src/app/overlay.ts
@@ -1499,6 +1732,21 @@ var App = class extends Observable {
1499
1732
  });
1500
1733
  return byField;
1501
1734
  }
1735
+ menu(query, event, rows, fields) {
1736
+ if (this._queries.get(query.name) !== query) {
1737
+ throw new ValidationError(`Query '${query.name}' belongs to a different app.`, query.name);
1738
+ }
1739
+ const derived = deriveSelection(query, rows, fields, this.drillTransformations(query));
1740
+ return openRowsMenu(event, {
1741
+ kind: "rows",
1742
+ app: this.index,
1743
+ query: query.name,
1744
+ rows: [...rows],
1745
+ fields: derived?.fields ? [...derived.fields] : [],
1746
+ conditions: derived?.conditions ? [...derived.conditions] : [],
1747
+ ...derived?.expression ? { expression: derived.expression } : {}
1748
+ });
1749
+ }
1502
1750
  select(query, rows, fields) {
1503
1751
  if (this._queries.get(query.name) !== query) {
1504
1752
  throw new ValidationError(`Query '${query.name}' belongs to a different app.`, query.name);
@@ -1753,6 +2001,37 @@ var App = class extends Observable {
1753
2001
  };
1754
2002
 
1755
2003
  // src/app/sdk.ts
2004
+ var HostTheme = class {
2005
+ constructor() {
2006
+ __publicField(this, "current", { scheme: "light", tokens: DEFAULT_TOKENS.light });
2007
+ __publicField(this, "listeners", /* @__PURE__ */ new Set());
2008
+ }
2009
+ /** `light` or `dark`; `light` until the host says. */
2010
+ get scheme() {
2011
+ return this.current.scheme;
2012
+ }
2013
+ /** Every token by name (`color-bg`, `font`): each is the CSS custom property `--anfra-<name>`. */
2014
+ get tokens() {
2015
+ return this.current.tokens;
2016
+ }
2017
+ /** Each time the host's theme changes. Returns the function that stops listening. */
2018
+ subscribe(listener) {
2019
+ this.listeners.add(listener);
2020
+ return () => {
2021
+ this.listeners.delete(listener);
2022
+ };
2023
+ }
2024
+ /** @internal The kernel's, on the host's word. */
2025
+ set(theme) {
2026
+ this.current = theme;
2027
+ this.listeners.forEach((listener) => {
2028
+ try {
2029
+ listener(theme);
2030
+ } catch {
2031
+ }
2032
+ });
2033
+ }
2034
+ };
1756
2035
  var InstalledPlugins = class {
1757
2036
  constructor(plugins) {
1758
2037
  /** Each plugin's name and version, in the order the host installed them. */
@@ -1796,6 +2075,8 @@ var Sdk = class {
1796
2075
  * before using an optional one.
1797
2076
  */
1798
2077
  __publicField(this, "plugins");
2078
+ /** The host's theme: `light` or `dark`, and its tokens. */
2079
+ __publicField(this, "theme", new HostTheme());
1799
2080
  /** The kernel's gates (`dateDrill`), as the environment gave them. */
1800
2081
  __publicField(this, "gates");
1801
2082
  __publicField(this, "deprecatedFeatures");
@@ -1945,6 +2226,9 @@ function createKernel(plugin, shared, entities) {
1945
2226
  provideOnQuery: (factory) => addExtension(sdk.extensions.query, entities.Query.prototype, "query", plugin, factory),
1946
2227
  provideOnControl: (factory) => addExtension(sdk.extensions.control, entities.Control.prototype, "control", plugin, factory),
1947
2228
  layer: () => layerRoot(win.document, plugin),
2229
+ menuItem: (item) => shared.contentUi?.addItem(plugin, item),
2230
+ modal: (input) => shared.contentUi.modal(input),
2231
+ popover: (input) => shared.contentUi.popover(input),
1948
2232
  body() {
1949
2233
  loading ?? (loading = endpoint.call(BODY_CALL, { plugin }).then((code) => runBody(win, code)).catch((err) => {
1950
2234
  loading = void 0;
@@ -1955,6 +2239,152 @@ function createKernel(plugin, shared, entities) {
1955
2239
  };
1956
2240
  }
1957
2241
 
2242
+ // src/app/pick.ts
2243
+ function startPick(doc, handlers) {
2244
+ let current = null;
2245
+ const under = (event) => event.target instanceof Element ? event.target.closest(MARKED) : null;
2246
+ const onMove = (event) => {
2247
+ const element = under(event);
2248
+ if (element === current) return;
2249
+ current = element;
2250
+ handlers.onHover(element);
2251
+ };
2252
+ const onClick = (event) => {
2253
+ event.preventDefault();
2254
+ event.stopPropagation();
2255
+ const element = under(event);
2256
+ if (element) handlers.onPick(element);
2257
+ };
2258
+ const onKey = (event) => {
2259
+ if (event.key === "Escape") handlers.onCancel();
2260
+ };
2261
+ const options = { capture: true };
2262
+ doc.addEventListener("mousemove", onMove, options);
2263
+ doc.addEventListener("click", onClick, options);
2264
+ doc.addEventListener("keydown", onKey, options);
2265
+ return () => {
2266
+ doc.removeEventListener("mousemove", onMove, options);
2267
+ doc.removeEventListener("click", onClick, options);
2268
+ doc.removeEventListener("keydown", onKey, options);
2269
+ };
2270
+ }
2271
+
2272
+ // src/app/inspection.ts
2273
+ function findNode(nodes, key) {
2274
+ for (const node of nodes) {
2275
+ if (node.key === key) return node;
2276
+ const inner = findNode(node.children, key);
2277
+ if (inner) return inner;
2278
+ }
2279
+ return void 0;
2280
+ }
2281
+ function installInspection(kernel) {
2282
+ const win = kernel.window;
2283
+ const doc = win.document;
2284
+ let inspecting = false;
2285
+ let timer;
2286
+ let structure;
2287
+ let lastStructureJson = "";
2288
+ let observer;
2289
+ let stopPick;
2290
+ function postSnapshot() {
2291
+ timer = void 0;
2292
+ if (!inspecting) return;
2293
+ try {
2294
+ structure = kernel.structure();
2295
+ lastStructureJson = JSON.stringify(structure.nodes);
2296
+ kernel.emit("snapshot", {
2297
+ apps: kernel.sdk.apps.map((app) => app.toInspectJSON()),
2298
+ structure: { nodes: structure.nodes, usage: structure.usage }
2299
+ });
2300
+ } catch {
2301
+ }
2302
+ }
2303
+ function scheduleSnapshot() {
2304
+ if (inspecting && timer === void 0) timer = setTimeout(postSnapshot, 50);
2305
+ }
2306
+ function observeStructure() {
2307
+ const Observer = win.MutationObserver;
2308
+ if (observer || typeof Observer !== "function") return;
2309
+ const watcher = new Observer(() => {
2310
+ if (!inspecting || timer !== void 0) return;
2311
+ try {
2312
+ if (JSON.stringify(kernel.structure().nodes) !== lastStructureJson) scheduleSnapshot();
2313
+ } catch {
2314
+ }
2315
+ });
2316
+ observer = watcher;
2317
+ watcher.observe(doc.documentElement, {
2318
+ childList: true,
2319
+ subtree: true,
2320
+ attributes: true,
2321
+ attributeFilter: Object.values(ATTR)
2322
+ });
2323
+ }
2324
+ function highlight(key) {
2325
+ const node = key !== null && structure ? findNode(structure.nodes, key) : void 0;
2326
+ const element = key !== null ? structure?.elements.get(key) : void 0;
2327
+ if (!node || !element || !structure) {
2328
+ kernel.overlay.hide();
2329
+ return;
2330
+ }
2331
+ kernel.overlay.show([element], describeNode(node, element, structure));
2332
+ }
2333
+ function setPicking(on) {
2334
+ if (!on) {
2335
+ stopPick?.();
2336
+ stopPick = void 0;
2337
+ return;
2338
+ }
2339
+ if (stopPick) return;
2340
+ const keyOf = (element) => structure?.keysOf.get(element)?.[0];
2341
+ stopPick = startPick(doc, {
2342
+ onHover: (element) => highlight(element ? keyOf(element) ?? null : null),
2343
+ onPick: (element) => {
2344
+ const key = keyOf(element);
2345
+ if (key !== void 0) kernel.emit("picked", { node: key });
2346
+ },
2347
+ onCancel: () => {
2348
+ setPicking(false);
2349
+ kernel.overlay.hide();
2350
+ kernel.emit("picked", { node: null });
2351
+ }
2352
+ });
2353
+ }
2354
+ function setInspecting(open) {
2355
+ inspecting = open;
2356
+ if (open) {
2357
+ observeStructure();
2358
+ postSnapshot();
2359
+ } else {
2360
+ observer?.disconnect();
2361
+ observer = void 0;
2362
+ setPicking(false);
2363
+ kernel.overlay.hide();
2364
+ structure = void 0;
2365
+ lastStructureJson = "";
2366
+ }
2367
+ }
2368
+ function locate(target) {
2369
+ if ("node" in target) {
2370
+ const element = structure?.elements.get(target.node);
2371
+ if (element) scrollTo(element);
2372
+ highlight(target.node);
2373
+ } else {
2374
+ kernel.sdk.apps[target.app]?.locate(target.kind, target.name);
2375
+ }
2376
+ scheduleSnapshot();
2377
+ }
2378
+ kernel.on("watch", (open) => setInspecting(open === true));
2379
+ kernel.on("highlight", (node) => highlight(node));
2380
+ kernel.on("locate", (target) => locate(target));
2381
+ kernel.on("pick", (on) => setPicking(on === true));
2382
+ kernel.onApp((app) => {
2383
+ app.subscribe(scheduleSnapshot);
2384
+ scheduleSnapshot();
2385
+ });
2386
+ }
2387
+
1958
2388
  // src/app/bootstrap.ts
1959
2389
  function bootstrap(win, setups = []) {
1960
2390
  const element = win.document.getElementById(PROVISION_ELEMENT_ID);
@@ -2016,6 +2446,28 @@ function bootstrap(win, setups = []) {
2016
2446
  listeners,
2017
2447
  appListeners
2018
2448
  };
2449
+ const own = createKernel("anfra", shared, { Query, Control });
2450
+ installInspection(own);
2451
+ shared.contentUi = installContentUi(own);
2452
+ own.on("theme", (theme) => {
2453
+ const resolved = resolveTheme(theme);
2454
+ themeLayer(win.document, resolved);
2455
+ instance.theme.set(resolved);
2456
+ });
2457
+ let shortcuts = /* @__PURE__ */ new Set();
2458
+ let listening = false;
2459
+ own.on("shortcuts", (list) => {
2460
+ shortcuts = new Set((Array.isArray(list) ? list : []).map(normalizeShortcut).filter((s) => !!s));
2461
+ if (listening || !shortcuts.size) return;
2462
+ listening = true;
2463
+ win.addEventListener("keydown", (event) => {
2464
+ if (event.defaultPrevented || event.repeat || isTyping(event.target)) return;
2465
+ const shortcut = eventShortcut(event);
2466
+ if (!shortcuts.has(shortcut)) return;
2467
+ event.preventDefault();
2468
+ own.emit("shortcut", shortcut);
2469
+ });
2470
+ });
2019
2471
  for (const [name, setup] of setups) {
2020
2472
  if (typeof setup !== "function") continue;
2021
2473
  try {
@@ -2035,10 +2487,10 @@ export {
2035
2487
  DateDrillControl,
2036
2488
  Mapping,
2037
2489
  CrossFilter,
2490
+ LAYER_ATTRIBUTE,
2038
2491
  ATTR,
2039
2492
  parseRef,
2040
2493
  buildStructure,
2041
- LAYER_ATTRIBUTE,
2042
2494
  OVERLAY_ID,
2043
2495
  App,
2044
2496
  InstalledPlugins,
@@ -0,0 +1,51 @@
1
+ // src/plugins/inspect/model/checks.ts
2
+ function mentionsField(aql, field) {
3
+ const escaped = field.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4
+ return new RegExp(`(^|[^\\w.])${escaped}(?![\\w])`).test(aql);
5
+ }
6
+ var controlMappings = (app) => app.declaration.mappings.filter((m) => m.kind === "control");
7
+ var crossFilters = (app) => app.declaration.mappings.filter((m) => m.kind === "crossFilter");
8
+ function wiringChecks(app) {
9
+ const { queries, filters, dateDrills } = app.declaration;
10
+ const mappings = controlMappings(app);
11
+ const crosses = crossFilters(app);
12
+ const checks = [];
13
+ for (const cross of crosses) {
14
+ const from = queries[cross.from.name];
15
+ const to = queries[cross.to.name];
16
+ if (from?.dataset && to?.dataset && from.dataset !== to.dataset) {
17
+ checks.push({
18
+ level: "error",
19
+ message: `Cross-filter ${cross.from.name} \u2192 ${cross.to.name} spans datasets (${from.dataset} \u2192 ${to.dataset}).`,
20
+ about: { entity: "query", name: cross.from.name }
21
+ });
22
+ }
23
+ }
24
+ for (const name of [...Object.keys(filters), ...Object.keys(dateDrills)]) {
25
+ if (!mappings.some((m) => m.from.name === name)) {
26
+ checks.push({ level: "warn", message: `${name} is mapped to no query, so it has no effect.`, about: { entity: "control", name } });
27
+ }
28
+ }
29
+ for (const mapping of mappings) {
30
+ if (mapping.from.kind !== "dateDrill") continue;
31
+ const aql = queries[mapping.to.name]?.aql;
32
+ if (aql && !mentionsField(aql, mapping.field)) {
33
+ checks.push({
34
+ level: "warn",
35
+ message: `${mapping.from.name} \u2192 ${mapping.to.name}: ${mapping.field} isn't in the query's AQL, so the grain never changes.`,
36
+ about: { entity: "control", name: mapping.from.name }
37
+ });
38
+ }
39
+ }
40
+ for (const name of Object.keys(queries)) {
41
+ const fed = mappings.some((m) => m.to.name === name) || crosses.some((c) => c.to.name === name);
42
+ if (!fed) checks.push({ level: "info", message: `${name} has no controls or cross-filters, so it never changes.`, about: { entity: "query", name } });
43
+ }
44
+ return checks;
45
+ }
46
+
47
+ export {
48
+ controlMappings,
49
+ crossFilters,
50
+ wiringChecks
51
+ };
@@ -0,0 +1,38 @@
1
+ // src/common/menu.ts
2
+ var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3
+ var isRect = (value) => isObject(value) && ["x", "y", "width", "height"].every((key) => typeof value[key] === "number");
4
+ var isNode = (value) => isObject(value) && typeof value.key === "string" && typeof value.kind === "string" && Array.isArray(value.problems) && Array.isArray(value.children);
5
+ function checkNode(value) {
6
+ if (!isObject(value) || value.kind !== "node" || !isNode(value.node) || !Array.isArray(value.ancestors) || !value.ancestors.every(isNode) || !isRect(value.rect)) return void 0;
7
+ return {
8
+ kind: "node",
9
+ node: value.node,
10
+ ancestors: value.ancestors,
11
+ rect: value.rect
12
+ };
13
+ }
14
+ function checkTarget(value) {
15
+ if (!isObject(value)) return void 0;
16
+ if (value.kind === "node") return checkNode(value);
17
+ if (value.kind !== "rows") return void 0;
18
+ if (typeof value.app !== "number" || typeof value.query !== "string" || !Array.isArray(value.rows) || !value.rows.every(isObject)) return void 0;
19
+ if (!Array.isArray(value.fields) || !value.fields.every((field) => typeof field === "string")) return void 0;
20
+ if (!Array.isArray(value.conditions) || !value.conditions.every(isObject)) return void 0;
21
+ if (value.expression !== void 0 && typeof value.expression !== "string") return void 0;
22
+ const node = value.node === void 0 ? void 0 : checkNode(value.node);
23
+ if (value.node !== void 0 && !node) return void 0;
24
+ return {
25
+ kind: "rows",
26
+ app: value.app,
27
+ query: value.query,
28
+ rows: value.rows,
29
+ fields: value.fields,
30
+ conditions: value.conditions,
31
+ ...value.expression !== void 0 ? { expression: value.expression } : {},
32
+ ...node ? { node } : {}
33
+ };
34
+ }
35
+
36
+ export {
37
+ checkTarget
38
+ };
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.13.5";
2
+ var version = "0.14.1";
3
3
 
4
4
  export {
5
5
  version