@malloy-publisher/sdk 0.0.248 → 0.0.249
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 +32 -17
- package/dist/ServerProvider-CcfeBpt3.cjs.js +1 -0
- package/dist/{ServerProvider-BxEh3nFI.es.js → ServerProvider-EqBlMMqx.es.js} +1056 -905
- package/dist/client/api.d.ts +297 -6
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +74 -70
- package/dist/components/Dashboard/Dashboard.d.ts +49 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +48 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Notebook/Notebook.d.ts +46 -8
- package/dist/components/Notebook/NotebookCell.d.ts +37 -3
- package/dist/components/Notebook/runPlan.d.ts +29 -0
- package/dist/components/Notebook/types.d.ts +10 -0
- package/dist/components/Package/ContentTypeIcon.d.ts +17 -1
- package/dist/components/Package/Package.d.ts +1 -4
- package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
- package/dist/components/RenderedResult/ResultContainer.d.ts +3 -1
- package/dist/components/ResultsDialog.d.ts +4 -1
- package/dist/components/ServerProvider.d.ts +2 -1
- package/dist/components/click_helper.d.ts +10 -1
- package/dist/components/drill/index.d.ts +3 -0
- package/dist/components/drill/markDrillableCells.d.ts +55 -0
- package/dist/components/drill/resolveDrill.d.ts +159 -0
- package/dist/components/drill/useDrill.d.ts +63 -0
- package/dist/components/given/GivenInput.d.ts +27 -3
- package/dist/components/given/GivensPanel.d.ts +36 -7
- package/dist/components/given/filterValue.d.ts +117 -0
- package/dist/components/given/index.d.ts +1 -1
- package/dist/components/given/paramCodec.d.ts +60 -0
- package/dist/components/index.d.ts +4 -1
- package/dist/components/styles.d.ts +23 -0
- package/dist/constants/docLinks.d.ts +6 -0
- package/dist/{core-BuvlzSIX.es.js → core-DFBwNhvb.es.js} +1 -1
- package/dist/{core-C86Rb7tJ.cjs.js → core-DZk7z7ko.cjs.js} +1 -1
- package/dist/hooks/givenValue.d.ts +10 -0
- package/dist/hooks/index.d.ts +3 -1
- package/dist/hooks/useGivensState.d.ts +64 -0
- package/dist/hooks/useSuggestOptions.d.ts +78 -0
- package/dist/{index-BdtAZ5k6.es.js → index-CLcRrkxd.es.js} +41221 -39894
- package/dist/index-CWQXhe0D.cjs.js +338 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +77 -62
- package/dist/theme/types.d.ts +9 -0
- package/package.json +3 -1
- package/src/components/Connections/AddConnectionDialog.tsx +10 -1
- package/src/components/Dashboard/Dashboard.tsx +395 -0
- package/src/components/Dashboard/DashboardTile.tsx +150 -0
- package/src/components/Dashboard/index.ts +2 -0
- package/src/components/Home/Home.tsx +114 -23
- package/src/components/Notebook/Notebook.tsx +444 -390
- package/src/components/Notebook/NotebookCell.tsx +117 -3
- package/src/components/Notebook/runPlan.spec.ts +152 -0
- package/src/components/Notebook/runPlan.ts +64 -0
- package/src/components/Notebook/types.ts +11 -0
- package/src/components/Package/ContentTypeIcon.spec.ts +88 -0
- package/src/components/Package/ContentTypeIcon.tsx +77 -6
- package/src/components/Package/Package.tsx +148 -38
- package/src/components/RenderedResult/RenderedResult.tsx +309 -19
- package/src/components/RenderedResult/ResultContainer.tsx +28 -1
- package/src/components/ResultsDialog.tsx +5 -0
- package/src/components/ServerProvider.tsx +2 -0
- package/src/components/click_helper.ts +14 -1
- package/src/components/drill/index.ts +25 -0
- package/src/components/drill/markDrillableCells.dom.spec.ts +310 -0
- package/src/components/drill/markDrillableCells.spec.ts +106 -0
- package/src/components/drill/markDrillableCells.ts +311 -0
- package/src/components/drill/resolveDrill.spec.ts +446 -0
- package/src/components/drill/resolveDrill.ts +372 -0
- package/src/components/drill/useDrill.tsx +200 -0
- package/src/components/given/GivenInput.spec.tsx +495 -15
- package/src/components/given/GivenInput.tsx +562 -30
- package/src/components/given/GivensPanel.spec.tsx +172 -0
- package/src/components/given/GivensPanel.tsx +139 -32
- package/src/components/given/filterValue.spec.ts +361 -0
- package/src/components/given/filterValue.ts +204 -0
- package/src/components/given/index.ts +5 -1
- package/src/components/given/paramCodec.spec.ts +854 -0
- package/src/components/given/paramCodec.ts +480 -0
- package/src/components/index.ts +4 -1
- package/src/components/styles.ts +27 -3
- package/src/constants/docLinks.spec.ts +51 -0
- package/src/constants/docLinks.ts +26 -0
- package/src/hooks/givenValue.ts +10 -0
- package/src/hooks/index.ts +6 -4
- package/src/hooks/useGivensState.spec.ts +446 -0
- package/src/hooks/useGivensState.ts +337 -0
- package/src/hooks/useSuggestOptions.spec.ts +109 -0
- package/src/hooks/useSuggestOptions.ts +260 -0
- package/src/theme/buildTableCssVars.ts +4 -0
- package/src/theme/resolveTheme.spec.ts +13 -0
- package/src/theme/resolveTheme.ts +3 -0
- package/src/theme/types.ts +9 -0
- package/test/README.md +16 -10
- package/dist/ServerProvider-Dg5S1qBU.cjs.js +0 -1
- package/dist/hooks/useGivensForm.d.ts +0 -35
- package/dist/index-MES4MGpQ.cjs.js +0 -309
- package/src/hooks/useGivensForm.spec.ts +0 -99
- package/src/hooks/useGivensForm.ts +0 -107
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Box } from "@mui/material";
|
|
2
|
-
import React, {
|
|
2
|
+
import React, {
|
|
3
|
+
Suspense,
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useLayoutEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
} from "react";
|
|
3
9
|
import { buildMalloyExplicitTheme } from "../../theme/buildMalloyExplicitTheme";
|
|
4
10
|
import { buildTableCssVars } from "../../theme/buildTableCssVars";
|
|
5
11
|
import { buildVegaThemeOverride } from "../../theme/buildVegaThemeOverride";
|
|
@@ -7,6 +13,15 @@ import { readChartAnnotations } from "../../theme/readChartAnnotations";
|
|
|
7
13
|
import { resolveTheme } from "../../theme/resolveTheme";
|
|
8
14
|
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
9
15
|
import type { ResolvedTheme } from "../../theme/types";
|
|
16
|
+
import {
|
|
17
|
+
DRILL_CELL_CLASS,
|
|
18
|
+
moveDrillStop,
|
|
19
|
+
drillableFieldNames,
|
|
20
|
+
markDrillableCells,
|
|
21
|
+
type DrillMetadataSource,
|
|
22
|
+
} from "../drill/markDrillableCells";
|
|
23
|
+
import type { DrillClickPayload } from "../drill/resolveDrill";
|
|
24
|
+
import type { DrillBinding } from "../drill/useDrill";
|
|
10
25
|
|
|
11
26
|
type MalloyRenderElement = HTMLElement & Record<string, unknown>;
|
|
12
27
|
|
|
@@ -16,7 +31,7 @@ type MalloyRenderElement = HTMLElement & Record<string, unknown>;
|
|
|
16
31
|
* declared on the renderer's public type. Keep in sync with
|
|
17
32
|
* `@malloydata/render` if more methods are needed.
|
|
18
33
|
*/
|
|
19
|
-
interface MalloyVizHandle {
|
|
34
|
+
interface MalloyVizHandle extends DrillMetadataSource {
|
|
20
35
|
setResult: (result: unknown) => void;
|
|
21
36
|
render: (element: HTMLElement) => void;
|
|
22
37
|
remove: () => void;
|
|
@@ -43,12 +58,17 @@ interface RenderedResultProps {
|
|
|
43
58
|
height?: number;
|
|
44
59
|
isFillElement?: (boolean) => void;
|
|
45
60
|
onSizeChange?: (height: number) => void;
|
|
46
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Makes `# drill` cells clickable, and makes them look it. From `useDrill`
|
|
63
|
+
* on the host surface, which decides where a click may go; omitted where
|
|
64
|
+
* nothing can act on one, and then the result renders inert.
|
|
65
|
+
*/
|
|
66
|
+
drill?: DrillBinding;
|
|
47
67
|
}
|
|
48
68
|
|
|
49
69
|
const createRenderer = async (
|
|
50
70
|
theme: ResolvedTheme,
|
|
51
|
-
|
|
71
|
+
onClick?: DrillBinding["onClick"],
|
|
52
72
|
): Promise<MalloyVizHandle> => {
|
|
53
73
|
if (typeof window === "undefined") {
|
|
54
74
|
throw new Error("MalloyRenderer can only be used in browser environment");
|
|
@@ -56,7 +76,7 @@ const createRenderer = async (
|
|
|
56
76
|
|
|
57
77
|
const { MalloyRenderer } = await import("@malloydata/render");
|
|
58
78
|
const renderer = new MalloyRenderer({
|
|
59
|
-
onClick
|
|
79
|
+
onClick,
|
|
60
80
|
vegaConfigOverride: buildVegaThemeOverride(theme),
|
|
61
81
|
// Pass the explicit theme so table chrome and dashboard tiles
|
|
62
82
|
// pick up the operator's colours directly. Without this the
|
|
@@ -138,18 +158,17 @@ function applyTableCssVars(element: HTMLElement, theme: ResolvedTheme): void {
|
|
|
138
158
|
}
|
|
139
159
|
|
|
140
160
|
/**
|
|
141
|
-
*
|
|
142
|
-
* `<style>` tag in `document.head` cannot reach `.dashboard-item` or any
|
|
143
|
-
* of the renderer's other internal classes — Shadow DOM blocks selector
|
|
144
|
-
* matching across the boundary. CSS variables DO cross the boundary
|
|
145
|
-
* (that's why `--malloy-render--background` already paints the top-level
|
|
146
|
-
* `.malloy-render` container), but selectors don't.
|
|
161
|
+
* CSS overrides for the renderer's own hardcoded colours.
|
|
147
162
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
163
|
+
* These are appended as a `<style>` in `document.head` by
|
|
164
|
+
* `injectRendererOverrides` below, which is the mechanism actually in use and
|
|
165
|
+
* is described where it happens. An earlier version of this block said the
|
|
166
|
+
* renderer puts its DOM in a Shadow Root and that we register through
|
|
167
|
+
* `MalloyViz.addStylesheet()`. Neither is true of this code: nothing here calls
|
|
168
|
+
* that API, and were the boundary real a `document.head` stylesheet could not
|
|
169
|
+
* reach `.malloy-dashboard` at all, which is precisely what these rules do and
|
|
170
|
+
* what the theming tests check. Selectors are written at higher specificity
|
|
171
|
+
* than the renderer's own so they win regardless of stylesheet order.
|
|
153
172
|
*/
|
|
154
173
|
const PUBLISHER_RENDERER_OVERRIDES_CSS = `
|
|
155
174
|
/* dashboard.css hardcodes background: #f7f9fc on .malloy-dashboard
|
|
@@ -223,6 +242,31 @@ div.malloy-render .malloy-dashboard .dashboard-row-header {
|
|
|
223
242
|
.malloy-render .cell-content.header {
|
|
224
243
|
color: var(--malloy-render--table-header-color) !important;
|
|
225
244
|
}
|
|
245
|
+
/* A cell whose column declares a "# drill" this surface can honor, marked
|
|
246
|
+
by markDrillableCells. Ordinary text with a pointer cursor until hovered,
|
|
247
|
+
then it reads as a link: the same affordance Malloyyo gives the same tag,
|
|
248
|
+
and the only thing that tells a reader a cell navigates. Kept off the
|
|
249
|
+
resting state deliberately: a column painted blue competes with the data.
|
|
250
|
+
(No backticks in here: this is inside a template literal.) */
|
|
251
|
+
.malloy-render .${DRILL_CELL_CLASS} {
|
|
252
|
+
cursor: pointer;
|
|
253
|
+
}
|
|
254
|
+
.malloy-render .${DRILL_CELL_CLASS}:hover > .cell-content {
|
|
255
|
+
color: var(--publisher-drill-link) !important;
|
|
256
|
+
text-decoration: underline;
|
|
257
|
+
}
|
|
258
|
+
/* Keyboard focus reads the same as hover, plus a ring: a hover colour is not
|
|
259
|
+
something a keyboard user can produce, and a focus ring is not something a
|
|
260
|
+
mouse user sees. focus-visible rather than focus, so a click does not leave a
|
|
261
|
+
ring behind it. (No backticks in here: this is inside a template literal.) */
|
|
262
|
+
.malloy-render .${DRILL_CELL_CLASS}:focus-visible {
|
|
263
|
+
outline: 2px solid var(--publisher-drill-link);
|
|
264
|
+
outline-offset: -2px;
|
|
265
|
+
}
|
|
266
|
+
.malloy-render .${DRILL_CELL_CLASS}:focus-visible > .cell-content {
|
|
267
|
+
color: var(--publisher-drill-link) !important;
|
|
268
|
+
text-decoration: underline;
|
|
269
|
+
}
|
|
226
270
|
`;
|
|
227
271
|
|
|
228
272
|
/**
|
|
@@ -249,10 +293,37 @@ function injectRendererOverrides(): void {
|
|
|
249
293
|
function RenderedResultInner({
|
|
250
294
|
result,
|
|
251
295
|
height: inputHeight,
|
|
252
|
-
|
|
296
|
+
drill,
|
|
253
297
|
onSizeChange,
|
|
254
298
|
}: RenderedResultProps) {
|
|
255
299
|
const ref = useRef<HTMLDivElement>(null);
|
|
300
|
+
// The renderer binds its click handler at construction, so a changing
|
|
301
|
+
// `drill` identity would otherwise re-run the render effect and rebuild the
|
|
302
|
+
// chart: undoing the no-flicker swap below every time the parent
|
|
303
|
+
// re-renders. Read the latest binding through a ref instead, and keep
|
|
304
|
+
// `drill` out of the effect's dependencies, so callers can pass an inline
|
|
305
|
+
// one safely.
|
|
306
|
+
const drillRef = useRef(drill);
|
|
307
|
+
drillRef.current = drill;
|
|
308
|
+
const handleDrillClick = useCallback((payload: DrillClickPayload) => {
|
|
309
|
+
drillRef.current?.onClick(payload);
|
|
310
|
+
}, []);
|
|
311
|
+
// Whether any drill is wired at all, which is what the effect reacts to: a
|
|
312
|
+
// surface that gains or loses the capability has to (re)mark its cells, but
|
|
313
|
+
// a new inline binding with the same capability must not rebuild anything.
|
|
314
|
+
//
|
|
315
|
+
// KNOWN LIMITATION, and the narrower alternative is worse. `canDrill` decides
|
|
316
|
+
// WHICH cells get marked and is read once per render pass, so a predicate
|
|
317
|
+
// that changes while the result stays put leaves the previous pass's marks in
|
|
318
|
+
// place. Depending on the predicate's identity instead was tried and reverted:
|
|
319
|
+
// `canDrill` chains back to the notebook's parameters, so every control edit
|
|
320
|
+
// tore down and rebuilt every chart, which is the flicker this component was
|
|
321
|
+
// fixed for. The stale case needs a host whose predicate resolves after first
|
|
322
|
+
// paint against an unchanged result; it cannot happen in the notebook, where
|
|
323
|
+
// anything that changes the declared givens also rebuilds the cells. Fixing
|
|
324
|
+
// it properly means re-marking without re-rendering, which is a change to the
|
|
325
|
+
// marking pass rather than to this dependency list.
|
|
326
|
+
const drillable = drill !== undefined;
|
|
256
327
|
const hasMeasuredRef = useRef(false);
|
|
257
328
|
// The chart currently painted into the container, held across renders. A
|
|
258
329
|
// new render paints into a fresh offscreen stage and only swaps in (and
|
|
@@ -291,6 +362,11 @@ function RenderedResultInner({
|
|
|
291
362
|
// if this render is superseded before it swaps itself into `liveRef`.
|
|
292
363
|
let stage: HTMLDivElement | undefined;
|
|
293
364
|
let viz: MalloyVizHandle | undefined;
|
|
365
|
+
let drillObserver: MutationObserver | null = null;
|
|
366
|
+
let drillFrame = 0;
|
|
367
|
+
let drillKeydown: ((event: KeyboardEvent) => void) | null = null;
|
|
368
|
+
let drillKeyup: ((event: KeyboardEvent) => void) | null = null;
|
|
369
|
+
let drillFocusIn: ((event: FocusEvent) => void) | null = null;
|
|
294
370
|
let observer: MutationObserver | null = null;
|
|
295
371
|
let measureTimeout: NodeJS.Timeout | null = null;
|
|
296
372
|
// Safety net so a render that never signals ready (an async renderer
|
|
@@ -349,7 +425,7 @@ function RenderedResultInner({
|
|
|
349
425
|
if (!isCurrent()) return;
|
|
350
426
|
|
|
351
427
|
try {
|
|
352
|
-
viz = await createRenderer(effectiveTheme,
|
|
428
|
+
viz = await createRenderer(effectiveTheme, handleDrillClick);
|
|
353
429
|
} catch (error) {
|
|
354
430
|
console.error("Failed to create renderer:", error);
|
|
355
431
|
return;
|
|
@@ -428,6 +504,187 @@ function RenderedResultInner({
|
|
|
428
504
|
// in the SDK to avoid pinning to the malloy core types here.
|
|
429
505
|
viz.setResult(parsed);
|
|
430
506
|
viz.render(stage);
|
|
507
|
+
|
|
508
|
+
// Mark the cells a `# drill` makes clickable, so they read as
|
|
509
|
+
// links. The names come from the result's field metadata, which is
|
|
510
|
+
// complete as soon as it is set, but the DOM is not: a
|
|
511
|
+
// `# dashboard` result builds its cards over later frames, so a
|
|
512
|
+
// one-shot pass right after render() would miss every table that
|
|
513
|
+
// appears after it. Hence the observer, which re-marks (batched to
|
|
514
|
+
// a frame) as cards arrive.
|
|
515
|
+
const binding = drillRef.current;
|
|
516
|
+
// Isolated from the render above. The chart has already rendered by
|
|
517
|
+
// this point, and a throw in here would reach the same catch and
|
|
518
|
+
// replace a working result with an error message: the affordance
|
|
519
|
+
// would be taking the chart down with it. `drillableFieldNames`
|
|
520
|
+
// already guards its own metadata read on the same principle.
|
|
521
|
+
try {
|
|
522
|
+
if (binding) {
|
|
523
|
+
const names = drillableFieldNames(viz, binding.canDrill);
|
|
524
|
+
// Guarded INSIDE, not just at the first call. The try
|
|
525
|
+
// below wraps this function's definition, not the frames the
|
|
526
|
+
// observer schedules it on, so a throw on a re-mark escaped
|
|
527
|
+
// to the window and the isolation only ever covered the
|
|
528
|
+
// synchronous pass.
|
|
529
|
+
const mark = () => {
|
|
530
|
+
try {
|
|
531
|
+
markDrillableCells(stageNode, names);
|
|
532
|
+
} catch (markError) {
|
|
533
|
+
console.warn("Drill affordance skipped:", markError);
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
mark();
|
|
537
|
+
// Enter and Space fire the drill for a focused cell. Delegated
|
|
538
|
+
// on the stage rather than bound per cell, because the
|
|
539
|
+
// renderer rebuilds cells as a dashboard's cards arrive and a
|
|
540
|
+
// per-cell listener would be lost with them; this one outlives
|
|
541
|
+
// every re-mark.
|
|
542
|
+
//
|
|
543
|
+
// It synthesises a CLICK rather than calling the drill handler
|
|
544
|
+
// directly, so the payload comes from the renderer's own click
|
|
545
|
+
// path. Building one here would mean re-deriving which field
|
|
546
|
+
// and value a cell represents, which is exactly the mapping
|
|
547
|
+
// this module has no access to and the reason the affordance
|
|
548
|
+
// is matched on rendered text in the first place.
|
|
549
|
+
//
|
|
550
|
+
// The click goes to the cell's INNER `.cell-content`, not to
|
|
551
|
+
// the cell. Measured, because dispatching on the cell looked
|
|
552
|
+
// right and silently did nothing: a real mouse click lands on
|
|
553
|
+
// `.cell-content` and the renderer reads the event target to
|
|
554
|
+
// identify the field, so a click on the outer cell reaches the
|
|
555
|
+
// handler with a target it does not recognise and is dropped
|
|
556
|
+
// without a sound. Falls back to the cell for a shape that has
|
|
557
|
+
// no inner content node.
|
|
558
|
+
//
|
|
559
|
+
// Enter fires on keydown and Space on keyUP, which is the
|
|
560
|
+
// native button rule and is load-bearing here rather than
|
|
561
|
+
// pedantry. Firing Space on keydown opened the drill menu and
|
|
562
|
+
// then the SAME keypress's keyup landed on the now-focused
|
|
563
|
+
// first menu item and chose it, so a Space drill navigated
|
|
564
|
+
// straight past the menu it had just opened. Measured: the
|
|
565
|
+
// menu was visible while the key was held and gone, with the
|
|
566
|
+
// URL already changed, once it was released.
|
|
567
|
+
//
|
|
568
|
+
// Dispatched with the cell's own coordinates rather than
|
|
569
|
+
// through `HTMLElement.click()`, which reports `clientX/Y` as
|
|
570
|
+
// 0. A drill offering two destinations anchors its menu on
|
|
571
|
+
// those numbers (`useDrill` holds no ref into the renderer's
|
|
572
|
+
// DOM), so a keyboard-opened menu appeared in the corner of
|
|
573
|
+
// the viewport instead of beside the cell it came from.
|
|
574
|
+
const fire = (cell: Element) => {
|
|
575
|
+
const content =
|
|
576
|
+
cell.querySelector<HTMLElement>(".cell-content");
|
|
577
|
+
const target = content ?? (cell as HTMLElement);
|
|
578
|
+
const rect = target.getBoundingClientRect();
|
|
579
|
+
target.dispatchEvent(
|
|
580
|
+
new MouseEvent("click", {
|
|
581
|
+
bubbles: true,
|
|
582
|
+
cancelable: true,
|
|
583
|
+
view: target.ownerDocument.defaultView,
|
|
584
|
+
clientX: Math.round(rect.left + rect.width / 2),
|
|
585
|
+
clientY: Math.round(rect.bottom),
|
|
586
|
+
}),
|
|
587
|
+
);
|
|
588
|
+
};
|
|
589
|
+
const drillCell = (event: KeyboardEvent) =>
|
|
590
|
+
(
|
|
591
|
+
event.target as HTMLElement | null
|
|
592
|
+
)?.closest?.<HTMLElement>(`.${DRILL_CELL_CLASS}`) ?? null;
|
|
593
|
+
// Move the single tab stop within a drillable column.
|
|
594
|
+
// `markDrillableCells` gives a column one stop rather than one
|
|
595
|
+
// per cell, so these keys are how a reader reaches the other
|
|
596
|
+
// rows; without them the affordance would only ever fire on
|
|
597
|
+
// whichever row held the stop. Clamped rather than wrapping,
|
|
598
|
+
// which is what a table's rows read as.
|
|
599
|
+
const rove = (
|
|
600
|
+
cell: HTMLElement,
|
|
601
|
+
to: number | "first" | "last",
|
|
602
|
+
) => {
|
|
603
|
+
// The move lives in `markDrillableCells` beside the column
|
|
604
|
+
// rule, because it has to hold the same invariant the
|
|
605
|
+
// marking does: exactly one stop per column. Doing it here
|
|
606
|
+
// by clearing the focused cell assumed that cell HELD the
|
|
607
|
+
// stop, which a click-focused `tabindex="-1"` cell does not.
|
|
608
|
+
moveDrillStop(cell, to)?.focus();
|
|
609
|
+
};
|
|
610
|
+
drillKeydown = (event: KeyboardEvent) => {
|
|
611
|
+
const cell = drillCell(event) as HTMLElement | null;
|
|
612
|
+
if (!cell) return;
|
|
613
|
+
const roveKey =
|
|
614
|
+
event.key === "ArrowDown"
|
|
615
|
+
? 1
|
|
616
|
+
: event.key === "ArrowUp"
|
|
617
|
+
? -1
|
|
618
|
+
: event.key === "Home"
|
|
619
|
+
? ("first" as const)
|
|
620
|
+
: event.key === "End"
|
|
621
|
+
? ("last" as const)
|
|
622
|
+
: undefined;
|
|
623
|
+
if (roveKey !== undefined) {
|
|
624
|
+
// Prevented whether or not the move happened, so the
|
|
625
|
+
// first and last rows do not scroll the page out from
|
|
626
|
+
// under a reader who is still inside the column.
|
|
627
|
+
event.preventDefault();
|
|
628
|
+
rove(cell, roveKey);
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
if (event.key === "Enter") {
|
|
632
|
+
// Otherwise Enter submits an enclosing form on an
|
|
633
|
+
// embedding host.
|
|
634
|
+
event.preventDefault();
|
|
635
|
+
fire(cell);
|
|
636
|
+
} else if (event.key === " ") {
|
|
637
|
+
// Held Space scrolls the page; the activation itself
|
|
638
|
+
// waits for keyup.
|
|
639
|
+
event.preventDefault();
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
drillKeyup = (event: KeyboardEvent) => {
|
|
643
|
+
if (event.key !== " ") return;
|
|
644
|
+
const cell = drillCell(event);
|
|
645
|
+
if (!cell) return;
|
|
646
|
+
event.preventDefault();
|
|
647
|
+
fire(cell);
|
|
648
|
+
};
|
|
649
|
+
// Focus and the tab stop have to agree however focus got
|
|
650
|
+
// there. The arrow handler moves the stop, but a
|
|
651
|
+
// `tabindex="-1"` cell is still CLICK-focusable, so without
|
|
652
|
+
// this a reader who clicked row 5, tabbed away and tabbed back
|
|
653
|
+
// landed on row 0. That is the same asymmetry the arrow path
|
|
654
|
+
// already fixes, for the one way of arriving that does not go
|
|
655
|
+
// through it. `moveDrillStop(cell, 0)` resolves to the cell
|
|
656
|
+
// itself, so it just makes that cell the column's stop.
|
|
657
|
+
drillFocusIn = (event: FocusEvent) => {
|
|
658
|
+
const cell = (
|
|
659
|
+
event.target as HTMLElement | null
|
|
660
|
+
)?.closest?.<HTMLElement>(`.${DRILL_CELL_CLASS}`);
|
|
661
|
+
if (cell) moveDrillStop(cell, 0);
|
|
662
|
+
};
|
|
663
|
+
stageNode.addEventListener("keydown", drillKeydown);
|
|
664
|
+
stageNode.addEventListener("keyup", drillKeyup);
|
|
665
|
+
stageNode.addEventListener("focusin", drillFocusIn);
|
|
666
|
+
if (
|
|
667
|
+
names.size > 0 &&
|
|
668
|
+
typeof MutationObserver !== "undefined"
|
|
669
|
+
) {
|
|
670
|
+
drillObserver = new MutationObserver(() => {
|
|
671
|
+
cancelAnimationFrame(drillFrame);
|
|
672
|
+
drillFrame = requestAnimationFrame(mark);
|
|
673
|
+
});
|
|
674
|
+
// childList only: marking writes classes, and observing
|
|
675
|
+
// attributes would have it retrigger itself every frame.
|
|
676
|
+
drillObserver.observe(stageNode, {
|
|
677
|
+
childList: true,
|
|
678
|
+
subtree: true,
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
} catch (drillError) {
|
|
683
|
+
// No affordance, and the result stands. Clicks still resolve,
|
|
684
|
+
// because the renderer routes those itself.
|
|
685
|
+
console.warn("Drill affordance skipped:", drillError);
|
|
686
|
+
}
|
|
687
|
+
|
|
431
688
|
viz.onReady(promote);
|
|
432
689
|
// If onReady never fires (an async render error that only reaches
|
|
433
690
|
// the renderer's onError), force the swap after a bounded wait so
|
|
@@ -437,6 +694,7 @@ function RenderedResultInner({
|
|
|
437
694
|
} catch (error) {
|
|
438
695
|
console.error("Error rendering visualization:", error);
|
|
439
696
|
observer?.disconnect();
|
|
697
|
+
drillObserver?.disconnect();
|
|
440
698
|
viz.remove();
|
|
441
699
|
viz = undefined;
|
|
442
700
|
if (stageNode.parentNode === element) {
|
|
@@ -454,6 +712,30 @@ function RenderedResultInner({
|
|
|
454
712
|
// (superseded, or unmounted mid-render), tear it down so it can't
|
|
455
713
|
// leak a viz or leave an orphan node behind.
|
|
456
714
|
if (stage && liveRef.current?.node !== stage) {
|
|
715
|
+
// The keyboard listeners go with the stage, and ONLY with the
|
|
716
|
+
// stage. Removing them unconditionally tied their lifetime to the
|
|
717
|
+
// effect RUN instead, while the stage's is tied to `liveRef`: a
|
|
718
|
+
// re-run tore them off the chart that is still on screen, which
|
|
719
|
+
// keeps its `tabindex` and `role="button"` and so still says Enter
|
|
720
|
+
// and Space do something. Usually that window closes when the new
|
|
721
|
+
// render promotes, but a render that never gets that far (a parse
|
|
722
|
+
// failure, a renderer that throws) leaves the visible chart
|
|
723
|
+
// permanently keyboard-dead while still advertising otherwise.
|
|
724
|
+
// Left on a promoted stage they are collected with the node when
|
|
725
|
+
// `promote` removes it, so nothing leaks by keeping them.
|
|
726
|
+
if (drillKeydown)
|
|
727
|
+
stage.removeEventListener("keydown", drillKeydown);
|
|
728
|
+
if (drillKeyup) stage.removeEventListener("keyup", drillKeyup);
|
|
729
|
+
if (drillFocusIn)
|
|
730
|
+
stage.removeEventListener("focusin", drillFocusIn);
|
|
731
|
+
// The re-marker is scoped the same way, and for the same reason.
|
|
732
|
+
// Disconnecting it unconditionally tied it to the effect RUN: a
|
|
733
|
+
// re-run while a `# dashboard` was still building its cards stopped
|
|
734
|
+
// the LIVE stage being re-marked, so cards arriving after that point
|
|
735
|
+
// never became drillable. Like the listeners, it is collected with
|
|
736
|
+
// the node once a promoted stage is dropped.
|
|
737
|
+
drillObserver?.disconnect();
|
|
738
|
+
cancelAnimationFrame(drillFrame);
|
|
457
739
|
viz?.remove();
|
|
458
740
|
if (stage.parentNode === element) {
|
|
459
741
|
element.removeChild(stage);
|
|
@@ -464,7 +746,15 @@ function RenderedResultInner({
|
|
|
464
746
|
element.style.position = "";
|
|
465
747
|
}
|
|
466
748
|
};
|
|
467
|
-
}, [
|
|
749
|
+
}, [
|
|
750
|
+
result,
|
|
751
|
+
handleDrillClick,
|
|
752
|
+
drillable,
|
|
753
|
+
onSizeChange,
|
|
754
|
+
baseTheme,
|
|
755
|
+
layers,
|
|
756
|
+
mode,
|
|
757
|
+
]);
|
|
468
758
|
|
|
469
759
|
// Malloy renderer requires explicit pixel height to render visualizations
|
|
470
760
|
return (
|
|
@@ -3,6 +3,7 @@ import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
|
|
|
3
3
|
import { Box, Button, IconButton, Tooltip, Typography } from "@mui/material";
|
|
4
4
|
import { lazy, Suspense, useRef, useState } from "react";
|
|
5
5
|
import { LogMessage } from "../../client";
|
|
6
|
+
import type { DrillBinding } from "../drill/useDrill";
|
|
6
7
|
import { Loading } from "../Loading";
|
|
7
8
|
import { summarizeRenderLogs } from "./renderLogs";
|
|
8
9
|
|
|
@@ -18,8 +19,30 @@ interface ResultContainerProps {
|
|
|
18
19
|
// Render tag findings from the query response. Callers whose result did not
|
|
19
20
|
// come from a query response have none to pass.
|
|
20
21
|
renderLogs?: LogMessage[];
|
|
22
|
+
// `# drill` click handling and its affordance. Passed straight through: this
|
|
23
|
+
// is the one render path dashboards and notebooks share, which is what lets
|
|
24
|
+
// drill be implemented once for both.
|
|
25
|
+
drill?: DrillBinding;
|
|
21
26
|
}
|
|
22
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Height to paint at before the result has been measured.
|
|
30
|
+
*
|
|
31
|
+
* `maxHeight` is a CAP, but it was also the first paint's height, because the
|
|
32
|
+
* measured height starts out equal to it. That was harmless while every caller
|
|
33
|
+
* passed something viewport-sized (400 to 800). A caller that means "no cap"
|
|
34
|
+
* passes a number that is not a height anyone wants to see: the dashboard
|
|
35
|
+
* viewer's whole-page form passes 20000, so the panel painted twenty thousand
|
|
36
|
+
* pixels tall until the measurement landed, and a result the renderer sizes to
|
|
37
|
+
* its CONTAINER (a top-level chart, as opposed to a `# dashboard` grid, which
|
|
38
|
+
* reports its own height) measured that back and kept it.
|
|
39
|
+
*
|
|
40
|
+
* Bounded here rather than by lowering the cap, so "no cap" stays expressible.
|
|
41
|
+
* Above the cap it does nothing, which is every caller that passes a real
|
|
42
|
+
* height, so this changes nothing for them.
|
|
43
|
+
*/
|
|
44
|
+
const INITIAL_RENDER_HEIGHT = 2000;
|
|
45
|
+
|
|
23
46
|
// ResultContainer is a component that renders a result, with a toggle button to expand/collapse the result.
|
|
24
47
|
// For fill-elements, the result is rendered at minHeight, and the toggle button is shown to scale up to maxHeight.
|
|
25
48
|
// For non-fill-elements, the result is rendered at explicitHeight, with a small window (minHeight) that can be expanded to maxHeight.
|
|
@@ -29,9 +52,12 @@ export default function ResultContainer({
|
|
|
29
52
|
maxHeight,
|
|
30
53
|
maxResultSize = 0,
|
|
31
54
|
renderLogs,
|
|
55
|
+
drill,
|
|
32
56
|
}: ResultContainerProps) {
|
|
33
57
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
34
|
-
const [measuredHeight, setMeasuredHeight] = useState(
|
|
58
|
+
const [measuredHeight, setMeasuredHeight] = useState(
|
|
59
|
+
Math.min(maxHeight, INITIAL_RENDER_HEIGHT),
|
|
60
|
+
);
|
|
35
61
|
const [userAcknowledged, setUserAcknowledged] = useState(false);
|
|
36
62
|
const renderLogSummary = summarizeRenderLogs(renderLogs);
|
|
37
63
|
|
|
@@ -95,6 +121,7 @@ export default function ResultContainer({
|
|
|
95
121
|
result={result}
|
|
96
122
|
height={renderedHeight}
|
|
97
123
|
onSizeChange={setMeasuredHeight}
|
|
124
|
+
drill={drill}
|
|
98
125
|
/>
|
|
99
126
|
</Suspense>
|
|
100
127
|
)}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import CloseIcon from "@mui/icons-material/Close";
|
|
2
2
|
import { Dialog, DialogContent, DialogTitle, IconButton } from "@mui/material";
|
|
3
3
|
import { LogMessage } from "../client";
|
|
4
|
+
import type { DrillBinding } from "./drill";
|
|
4
5
|
import ResultContainer from "./RenderedResult/ResultContainer";
|
|
5
6
|
|
|
6
7
|
interface ResultsDialogProps {
|
|
@@ -9,6 +10,8 @@ interface ResultsDialogProps {
|
|
|
9
10
|
result: string;
|
|
10
11
|
title?: string;
|
|
11
12
|
renderLogs?: LogMessage[];
|
|
13
|
+
/** `# drill` wiring, so a result stays clickable when it is expanded. */
|
|
14
|
+
drill?: DrillBinding;
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
export default function ResultsDialog({
|
|
@@ -17,6 +20,7 @@ export default function ResultsDialog({
|
|
|
17
20
|
result,
|
|
18
21
|
title = "Results",
|
|
19
22
|
renderLogs,
|
|
23
|
+
drill,
|
|
20
24
|
}: ResultsDialogProps) {
|
|
21
25
|
return (
|
|
22
26
|
<Dialog
|
|
@@ -56,6 +60,7 @@ export default function ResultsDialog({
|
|
|
56
60
|
maxHeight={800}
|
|
57
61
|
maxResultSize={1000000}
|
|
58
62
|
renderLogs={renderLogs}
|
|
63
|
+
drill={drill}
|
|
59
64
|
/>
|
|
60
65
|
</DialogContent>
|
|
61
66
|
</Dialog>
|
|
@@ -11,6 +11,7 @@ import React, {
|
|
|
11
11
|
} from "react";
|
|
12
12
|
import {
|
|
13
13
|
ConnectionsApi,
|
|
14
|
+
DashboardsApi,
|
|
14
15
|
DataAppsApi,
|
|
15
16
|
DatabasesApi,
|
|
16
17
|
EnvironmentsApi,
|
|
@@ -138,6 +139,7 @@ const getApiClients = (
|
|
|
138
139
|
publisher: new PublisherApi(config, basePath, axiosInstance),
|
|
139
140
|
environments: new EnvironmentsApi(config, basePath, axiosInstance),
|
|
140
141
|
packages: new PackagesApi(config, basePath, axiosInstance),
|
|
142
|
+
dashboards: new DashboardsApi(config, basePath, axiosInstance),
|
|
141
143
|
dataApps: new DataAppsApi(config, basePath, axiosInstance),
|
|
142
144
|
notebooks: new NotebooksApi(config, basePath, axiosInstance),
|
|
143
145
|
connections: new ConnectionsApi(config, basePath, axiosInstance),
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { useNavigate } from "react-router-dom";
|
|
2
2
|
import { MouseEvent } from "react";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The modifier state a navigation decision reads, and nothing more.
|
|
6
|
+
*
|
|
7
|
+
* Both React's synthetic mouse event and the DOM's satisfy it, which is the
|
|
8
|
+
* point. A click can reach navigation from a React handler, or from outside
|
|
9
|
+
* React entirely (a `# drill` click arrives from the Malloy renderer as a plain
|
|
10
|
+
* DOM event), and neither should have to be converted to the other first.
|
|
11
|
+
*/
|
|
12
|
+
export type NavigationClick = Pick<
|
|
13
|
+
MouseEvent,
|
|
14
|
+
"metaKey" | "ctrlKey" | "shiftKey" | "button"
|
|
15
|
+
>;
|
|
16
|
+
|
|
4
17
|
/**
|
|
5
18
|
* Custom hook that returns a function for handling clicks with proper modifier key support.
|
|
6
19
|
* The returned function handles CMD/Ctrl clicks to open in new tabs, regular clicks for navigation.
|
|
@@ -10,7 +23,7 @@ import { MouseEvent } from "react";
|
|
|
10
23
|
export function useRouterClickHandler() {
|
|
11
24
|
const navigate = useNavigate();
|
|
12
25
|
|
|
13
|
-
return (to: string, event?:
|
|
26
|
+
return (to: string, event?: NavigationClick) => {
|
|
14
27
|
// If no event or no modifier keys, use normal navigation
|
|
15
28
|
if (
|
|
16
29
|
!event ||
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export {
|
|
2
|
+
DRILL_CELL_CLASS,
|
|
3
|
+
drillableFieldNames,
|
|
4
|
+
markDrillableCells,
|
|
5
|
+
type DrillMetadataSource,
|
|
6
|
+
} from "./markDrillableCells";
|
|
7
|
+
export {
|
|
8
|
+
DRILL_SELF,
|
|
9
|
+
drillDestinations,
|
|
10
|
+
drillValueToFilter,
|
|
11
|
+
encodeDrillValue,
|
|
12
|
+
humanizeSlug,
|
|
13
|
+
resolveDrill,
|
|
14
|
+
type DrillClickPayload,
|
|
15
|
+
type DrillField,
|
|
16
|
+
type DrillIntent,
|
|
17
|
+
type DrillNavigation,
|
|
18
|
+
type DrillTagReader,
|
|
19
|
+
} from "./resolveDrill";
|
|
20
|
+
export {
|
|
21
|
+
useDrill,
|
|
22
|
+
type DrillBinding,
|
|
23
|
+
type UseDrillOptions,
|
|
24
|
+
type UseDrillResult,
|
|
25
|
+
} from "./useDrill";
|