@malloy-publisher/sdk 0.9.11 → 0.9.13

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 (74) hide show
  1. package/README.md +5 -7
  2. package/dist/{RenderedResult-Cmx8sX8d.es.js → RenderedResult-DnBtf-cI.es.js} +2 -2
  3. package/dist/{RenderedResult-BlNoIiSi.cjs.js → RenderedResult-DtQtNV0d.cjs.js} +1 -1
  4. package/dist/ServerProvider-BIFPCzTD.cjs.js +1 -0
  5. package/dist/{ServerProvider-azXLkk1q.es.js → ServerProvider-BV7IoDMR.es.js} +808 -607
  6. package/dist/builder/index.cjs.js +72 -72
  7. package/dist/builder/index.es.js +4156 -4219
  8. package/dist/builder-entry.d.ts +1 -0
  9. package/dist/client/api.d.ts +224 -1
  10. package/dist/client/index.cjs.js +1 -1
  11. package/dist/client/index.es.js +41 -37
  12. package/dist/components/Connections/common.d.ts +11 -3
  13. package/dist/components/Report/telemetry.d.ts +0 -5
  14. package/dist/components/ReportBuilder/BuilderBar.d.ts +1 -1
  15. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +14 -10
  16. package/dist/components/ReportBuilder/EditorSurface.d.ts +1 -2
  17. package/dist/components/ReportBuilder/ReportBuilder.d.ts +3 -10
  18. package/dist/components/ReportBuilder/ReportEditor.d.ts +2 -9
  19. package/dist/components/ReportBuilder/SaveStatus.d.ts +16 -0
  20. package/dist/components/ReportBuilder/TileFrame.d.ts +9 -2
  21. package/dist/components/ReportBuilder/builderControls.d.ts +14 -6
  22. package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
  23. package/dist/components/ReportBuilder/useReportDraft.d.ts +6 -2
  24. package/dist/components/given/GivenInput.d.ts +18 -1
  25. package/dist/components/given/GivensPanel.d.ts +12 -1
  26. package/dist/components/given/useOptionSearch.d.ts +30 -0
  27. package/dist/hooks/index.d.ts +1 -1
  28. package/dist/hooks/useDocumentControls.d.ts +5 -0
  29. package/dist/hooks/useGivensState.d.ts +7 -0
  30. package/dist/hooks/useSuggestOptions.d.ts +60 -4
  31. package/dist/index.cjs.js +9 -9
  32. package/dist/index.es.js +2541 -2400
  33. package/dist/{useCompiledDocument-7j5cBjQd.es.js → useCompiledDocument-B4QF1mIl.es.js} +6912 -6759
  34. package/dist/useCompiledDocument-D0OAMejE.cjs.js +142 -0
  35. package/package.json +1 -1
  36. package/src/builder-entry.ts +1 -0
  37. package/src/components/Connections/AddConnectionDialog.tsx +34 -2
  38. package/src/components/Connections/EditConnectionDialog.tsx +45 -3
  39. package/src/components/Connections/common.spec.ts +69 -0
  40. package/src/components/Connections/common.ts +132 -0
  41. package/src/components/Environment/Connections.tsx +1 -0
  42. package/src/components/Report/ReportPage.tsx +5 -1
  43. package/src/components/Report/telemetry.ts +0 -6
  44. package/src/components/ReportBuilder/AddTileDialog.tsx +2 -2
  45. package/src/components/ReportBuilder/BuilderBar.tsx +5 -256
  46. package/src/components/ReportBuilder/BuilderHeader.tsx +9 -3
  47. package/src/components/ReportBuilder/BuilderToolbar.tsx +15 -38
  48. package/src/components/ReportBuilder/EditorSurface.tsx +0 -3
  49. package/src/components/ReportBuilder/FilterDialog.tsx +1 -1
  50. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +210 -24
  51. package/src/components/ReportBuilder/ReportBuilder.tsx +43 -85
  52. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +0 -36
  53. package/src/components/ReportBuilder/ReportEditor.tsx +2 -13
  54. package/src/components/ReportBuilder/SaveStatus.tsx +271 -0
  55. package/src/components/ReportBuilder/TileFrame.spec.ts +34 -0
  56. package/src/components/ReportBuilder/TileFrame.tsx +10 -3
  57. package/src/components/ReportBuilder/builderControls.ts +39 -13
  58. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  59. package/src/components/ReportBuilder/useReportDraft.ts +38 -4
  60. package/src/components/given/GivenInput.tsx +219 -104
  61. package/src/components/given/GivensPanel.spec.tsx +19 -0
  62. package/src/components/given/GivensPanel.tsx +31 -1
  63. package/src/components/given/useOptionSearch.spec.tsx +218 -0
  64. package/src/components/given/useOptionSearch.ts +100 -0
  65. package/src/hooks/index.ts +5 -1
  66. package/src/hooks/useDocumentControls.ts +12 -1
  67. package/src/hooks/useGivensState.spec.ts +54 -0
  68. package/src/hooks/useGivensState.ts +21 -1
  69. package/src/hooks/useSuggestOptions.dom.spec.ts +125 -4
  70. package/src/hooks/useSuggestOptions.spec.ts +73 -2
  71. package/src/hooks/useSuggestOptions.ts +234 -62
  72. package/dist/ServerProvider-BOgiW8MX.cjs.js +0 -1
  73. package/dist/useCompiledDocument-B21sVbb4.cjs.js +0 -141
  74. package/src/components/ReportBuilder/ReportBuilder.layoutSwitch.spec.tsx +0 -145
@@ -3,41 +3,31 @@
3
3
 
4
4
  import { reportClasses } from "../../theme/classes";
5
5
  import AddIcon from "@mui/icons-material/Add";
6
- import CheckIcon from "@mui/icons-material/Check";
7
6
  import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
8
7
  import FilterListIcon from "@mui/icons-material/FilterList";
9
8
  import InsertChartOutlinedIcon from "@mui/icons-material/InsertChartOutlined";
10
9
  import NotesIcon from "@mui/icons-material/Notes";
11
- import RestartAltIcon from "@mui/icons-material/RestartAlt";
12
10
  import RedoIcon from "@mui/icons-material/Redo";
13
11
  import UndoIcon from "@mui/icons-material/Undo";
14
12
  import {
15
13
  Box,
16
14
  Button,
17
- ButtonBase,
18
15
  Divider,
19
16
  IconButton,
20
17
  Menu,
21
18
  MenuItem,
22
19
  Stack,
23
- ToggleButton,
24
- ToggleButtonGroup,
25
20
  Tooltip,
26
21
  useMediaQuery,
27
22
  } from "@mui/material";
28
- import type { Theme } from "@mui/material";
29
23
  import { useState, type ReactNode } from "react";
30
24
  import { MOTION_FAST } from "../../theme/motion";
31
25
  import type { ReportUi } from "../../theme/ui";
32
26
  import { usePublisherTheme } from "../../theme/ThemeContext";
33
27
  import { edgeColor, hoverEdgeColor } from "../controlTokens";
34
28
  import type { BuilderControls } from "./builderControls";
35
- import {
36
- controlSx,
37
- dividerSx,
38
- iconControlSx,
39
- segmentedSx,
40
- } from "./BuilderToolbar";
29
+ import { controlSx, dividerSx, iconControlSx } from "./BuilderToolbar";
30
+ import { SaveStatus } from "./SaveStatus";
41
31
  import { MOD } from "./useBuilderShortcuts";
42
32
 
43
33
  export interface BuilderBarProps {
@@ -49,7 +39,7 @@ export interface BuilderBarProps {
49
39
 
50
40
  /**
51
41
  * The builder's controls as one bar, for a host's header: the save status,
52
- * undo and redo, the layout switch, an Add menu, then Done and, while there
42
+ * undo and redo, an Add menu, then Done and, while there
53
43
  * are unsaved edits, Save. The page under it stays the reader's page, with the
54
44
  * tile and filter controls on the things they change.
55
45
  *
@@ -99,7 +89,7 @@ export function BuilderBar({ controls, onDone: onDoneProp }: BuilderBarProps) {
99
89
  >
100
90
  {controls && (
101
91
  <>
102
- {controls.save && <SaveStatus controls={controls} />}
92
+ {controls.save && <SaveStatus {...controls} />}
103
93
  {!compact && (
104
94
  <>
105
95
  <Tooltip title={`Undo (${MOD}Z)`}>
@@ -128,40 +118,9 @@ export function BuilderBar({ controls, onDone: onDoneProp }: BuilderBarProps) {
128
118
  </IconButton>
129
119
  </span>
130
120
  </Tooltip>
131
- {(controls.layout || canAdd) && (
121
+ {canAdd && (
132
122
  <Divider orientation="vertical" sx={dividerSx} />
133
123
  )}
134
- {controls.layout && (
135
- <Tooltip title="Layout: tiles side by side, or one after another">
136
- <ToggleButtonGroup
137
- size="small"
138
- exclusive
139
- value={controls.layout.value}
140
- aria-label="Layout"
141
- onChange={(
142
- _event,
143
- next: "grid" | "linear" | null,
144
- ) => {
145
- if (next && next !== controls.layout?.value)
146
- controls.layout?.set(next);
147
- }}
148
- sx={segmentedSx(edge, theme.ui)}
149
- >
150
- <ToggleButton
151
- value="linear"
152
- aria-label="Linear layout"
153
- >
154
- Linear
155
- </ToggleButton>
156
- <ToggleButton
157
- value="grid"
158
- aria-label="Grid layout"
159
- >
160
- Grid
161
- </ToggleButton>
162
- </ToggleButtonGroup>
163
- </Tooltip>
164
- )}
165
124
  {canAdd && (
166
125
  <>
167
126
  <Button
@@ -294,216 +253,6 @@ export function BuilderBar({ controls, onDone: onDoneProp }: BuilderBarProps) {
294
253
  );
295
254
  }
296
255
 
297
- /**
298
- * Where the edits stand: saved, saving, kept in this browser, or (with no
299
- * draft) unsaved. While there are edits to drop, it opens a menu offering
300
- * Discard edits, which is one undoable edit back to the saved report.
301
- */
302
- function SaveStatus({ controls }: { controls: BuilderControls }) {
303
- const { theme } = usePublisherTheme();
304
- const ui = theme.ui;
305
- const [anchor, setAnchor] = useState<HTMLElement | null>(null);
306
- const { status, draftKeptAt, discard } = controls;
307
- const words =
308
- status === "saved"
309
- ? "Saved"
310
- : status === "saving"
311
- ? "Saving…"
312
- : draftKeptAt !== undefined
313
- ? "Draft saved"
314
- : "Unsaved changes";
315
- const hint =
316
- status === "unsaved" && draftKeptAt !== undefined
317
- ? "Your edits are kept in this browser. Done saves them to the report."
318
- : controls.saveTarget;
319
- // One element for every state, set the same way: the same type and
320
- // padding, an icon slot of one size (a dot, or the check), and the
321
- // chevron's room kept whether or not the menu is offered. Each state used
322
- // to be drawn differently (a menu button for a draft, bare text otherwise),
323
- // so Draft saved → Saving… → Saved changed font, padding and width at every
324
- // step, and the controls beside it jumped. A minimum width, with the words
325
- // set against the undo buttons, keeps them still.
326
- const menu = discard !== undefined && status === "unsaved";
327
- const sx = (mui: Theme) => ({
328
- display: "inline-flex",
329
- alignItems: "center",
330
- justifyContent: "flex-end",
331
- gap: 0.75,
332
- minWidth: 132,
333
- height: ui.size.control,
334
- px: 1,
335
- borderRadius: ui.radius.control,
336
- font: "inherit",
337
- ...ui.type.control,
338
- whiteSpace: "nowrap" as const,
339
- color:
340
- status === "saved"
341
- ? mui.palette.text.secondary
342
- : mui.palette.text.primary,
343
- transition: `color ${MOTION_FAST}, background-color ${MOTION_FAST}`,
344
- ...(menu ? { "&:hover": { bgcolor: mui.palette.action.hover } } : {}),
345
- });
346
- const inner = (
347
- <>
348
- <Box
349
- component="span"
350
- aria-hidden
351
- sx={{
352
- width: 16,
353
- height: 16,
354
- flex: "none",
355
- display: "inline-flex",
356
- alignItems: "center",
357
- justifyContent: "center",
358
- }}
359
- >
360
- {status === "saved" ? (
361
- <CheckIcon sx={{ fontSize: 16 }} />
362
- ) : (
363
- <Box
364
- component="span"
365
- sx={(mui) => ({
366
- width: 7,
367
- height: 7,
368
- borderRadius: "50%",
369
- bgcolor:
370
- status === "saving" || draftKeptAt !== undefined
371
- ? mui.palette.text.disabled
372
- : mui.palette.warning.main,
373
- })}
374
- />
375
- )}
376
- </Box>
377
- <Box component="span" aria-hidden>
378
- {words}
379
- </Box>
380
- <ExpandMoreIcon
381
- aria-hidden
382
- sx={{
383
- fontSize: 16,
384
- ml: -0.25,
385
- visibility: menu ? "visible" : "hidden",
386
- }}
387
- />
388
- </>
389
- );
390
- // The words a screen reader hears as they change, beside the control
391
- // rather than in it, so a button around them is named by its words.
392
- const announce = (
393
- <Box
394
- component="span"
395
- role="status"
396
- aria-live="polite"
397
- sx={VISUALLY_HIDDEN}
398
- >
399
- {words}
400
- </Box>
401
- );
402
- return (
403
- <>
404
- {announce}
405
- <Tooltip title={hint} describeChild>
406
- {menu ? (
407
- <ButtonBase
408
- className={reportClasses.saveStatus}
409
- aria-label={words}
410
- aria-haspopup="menu"
411
- aria-expanded={anchor !== null}
412
- onClick={(event) => setAnchor(event.currentTarget)}
413
- sx={sx}
414
- >
415
- {inner}
416
- </ButtonBase>
417
- ) : (
418
- <Box
419
- component="span"
420
- className={reportClasses.saveStatus}
421
- sx={sx}
422
- >
423
- {inner}
424
- </Box>
425
- )}
426
- </Tooltip>
427
- <Menu
428
- className={reportClasses.menu}
429
- anchorEl={anchor}
430
- open={anchor !== null}
431
- onClose={() => setAnchor(null)}
432
- anchorOrigin={{ vertical: "bottom", horizontal: "left" }}
433
- transformOrigin={{ vertical: -4, horizontal: "left" }}
434
- slotProps={{
435
- paper: {
436
- sx: {
437
- minWidth: 240,
438
- borderRadius: ui.radius.menu,
439
- border: `1px solid ${edgeColor(theme.cardBorder)}`,
440
- boxShadow: ui.shadow.menu,
441
- },
442
- },
443
- }}
444
- MenuListProps={{ dense: true, sx: { py: 0.5 } }}
445
- >
446
- {draftKeptAt !== undefined && (
447
- <Box
448
- component="li"
449
- role="presentation"
450
- sx={{
451
- px: 1.75,
452
- pt: 0.75,
453
- pb: 1,
454
- ...ui.type.caption,
455
- color: "text.secondary",
456
- }}
457
- >
458
- Kept in this browser at{" "}
459
- {new Date(draftKeptAt).toLocaleTimeString([], {
460
- hour: "numeric",
461
- minute: "2-digit",
462
- })}
463
- </Box>
464
- )}
465
- <MenuItem
466
- onClick={() => {
467
- setAnchor(null);
468
- discard();
469
- }}
470
- sx={{
471
- mx: 0.5,
472
- borderRadius: ui.radius.control,
473
- gap: 1.25,
474
- color: "error.main",
475
- // The menu focuses its item on open; a full focus ring
476
- // there read as two stray rules across the menu.
477
- "&.Mui-focusVisible": {
478
- outline: "none",
479
- bgcolor: "action.hover",
480
- },
481
- }}
482
- >
483
- <RestartAltIcon fontSize="small" />
484
- Discard edits
485
- </MenuItem>
486
- </Menu>
487
- </>
488
- );
489
- }
490
-
491
- /** In the accessibility tree, not on screen: the status line's announcement. */
492
- const VISUALLY_HIDDEN = {
493
- position: "absolute",
494
- // Strings, not numbers: in `sx` a width or height of 1 is 100%, and a
495
- // margin of -1 is one spacing unit. As numbers, this "hidden" span was as
496
- // wide as the host's header and scrolled its panel sideways.
497
- width: "1px",
498
- height: "1px",
499
- margin: "-1px",
500
- padding: 0,
501
- overflow: "hidden",
502
- clip: "rect(0 0 0 0)",
503
- whiteSpace: "nowrap",
504
- border: 0,
505
- } as const;
506
-
507
256
  /** The builder's menus: a card set like its windows, rounded and bordered. */
508
257
  const menuPaperSx = (edge: string, ui: ReportUi) => ({
509
258
  minWidth: 260,
@@ -10,8 +10,14 @@ import { InlineText } from "./InlineText";
10
10
  import { selectionSx } from "./TileFrame";
11
11
  import type { ReportEditorHandle } from "./useReportEditor";
12
12
 
13
- /** How far the description's selection ring stands off its text. */
14
- const DESCRIPTION_RING_OFFSET_PX = 12;
13
+ /**
14
+ * How far the description's selection ring stands off its text: wide across,
15
+ * where the page has room, and close above and below, where it has only the
16
+ * header's gap to the title (12px) and the page's gap to the filter row
17
+ * (16px). The ring (2px) and its halo (4px) have to fit inside those too: at
18
+ * 12px all round, the halo ran into the filters.
19
+ */
20
+ const DESCRIPTION_RING_OFFSET = { x: 12, y: 6 };
15
21
 
16
22
  /**
17
23
  * The reader's {@link ReportHeader}, with its title and description edited
@@ -72,7 +78,7 @@ export function BuilderHeader({
72
78
  ...selectionSx(theme, {
73
79
  selected: descriptionSelected,
74
80
  bare: true,
75
- ringOffset: DESCRIPTION_RING_OFFSET_PX,
81
+ ringOffset: DESCRIPTION_RING_OFFSET,
76
82
  }),
77
83
  }}
78
84
  >
@@ -11,13 +11,12 @@ import {
11
11
  Divider,
12
12
  IconButton,
13
13
  Stack,
14
- ToggleButton,
15
- ToggleButtonGroup,
16
14
  Tooltip,
17
15
  } from "@mui/material";
18
16
  import type { ReactNode, Ref } from "react";
19
17
  import type { SavesTo } from "./documentSession";
20
18
  import { SecondaryButton } from "../buttons";
19
+ import { SaveStatus, type SaveStatusProps } from "./SaveStatus";
21
20
  import { MOD } from "./useBuilderShortcuts";
22
21
  import { edgeColor, hoverEdgeColor } from "../controlTokens";
23
22
  import { DEFAULT_UI, type ReportUi } from "../../theme/ui";
@@ -68,11 +67,12 @@ export const dividerSx = {
68
67
  } as const;
69
68
 
70
69
  /**
71
- * A segmented control, built as an outlined button group: the same edge,
72
- * height, radius and padding as "+ Tile" beside it, each segment the full
73
- * height of the control with a rule between them, and the chosen one tinted
74
- * edge to edge. An inset chip inside the outline read as a control within a
75
- * control, a size smaller than the button next to it.
70
+ * A segmented control, built as an outlined button group, for the builder's
71
+ * windows (the tile picker, the filter window): the same edge, height, radius
72
+ * and padding as "+ Tile", each segment the full height of the control with a
73
+ * rule between them, and the chosen one tinted edge to edge. An inset chip
74
+ * inside the outline read as a control within a control, a size smaller than
75
+ * the button next to it.
76
76
  */
77
77
  export const segmentedSx = (edge: string, ui: ReportUi = DEFAULT_UI) =>
78
78
  ({
@@ -140,10 +140,12 @@ export interface BuilderToolbarProps {
140
140
  * Console leaves from its own header and passes nothing.
141
141
  */
142
142
  onExit?: () => void;
143
- /** The report's layout, for the switch. Absent, no switch is drawn. */
144
- layout?: "grid" | "linear";
145
- /** Switch the layout: rewrites `layout=` in the tag and nothing else. */
146
- onLayoutChange?: (layout: "grid" | "linear") => void;
143
+ /**
144
+ * Where the edits stand, drawn before Save, for a builder that keeps a
145
+ * draft: the same status a host's {@link BuilderBar} draws, with its
146
+ * Discard edits menu and the word that edits were put back on opening.
147
+ */
148
+ saveStatus?: SaveStatusProps;
147
149
  }
148
150
 
149
151
  export function BuilderToolbar({
@@ -160,8 +162,7 @@ export function BuilderToolbar({
160
162
  actions,
161
163
  onAddTile,
162
164
  onExit,
163
- layout,
164
- onLayoutChange,
165
+ saveStatus,
165
166
  }: BuilderToolbarProps) {
166
167
  const { theme } = usePublisherTheme();
167
168
  const edge = edgeColor(theme.cardBorder);
@@ -179,31 +180,6 @@ export function BuilderToolbar({
179
180
  "& .MuiButton-root": { whiteSpace: "nowrap" },
180
181
  }}
181
182
  >
182
- {/* How the page is laid out: one property of the tag, switched in place. */}
183
- {layout && onLayoutChange && (
184
- <>
185
- <Tooltip title="Layout: tiles side by side, or one after another">
186
- <ToggleButtonGroup
187
- size="small"
188
- exclusive
189
- value={layout}
190
- aria-label="Layout"
191
- onChange={(_event, next: "grid" | "linear" | null) => {
192
- if (next && next !== layout) onLayoutChange(next);
193
- }}
194
- sx={segmentedSx(edge, theme.ui)}
195
- >
196
- <ToggleButton value="linear" aria-label="Linear layout">
197
- Linear
198
- </ToggleButton>
199
- <ToggleButton value="grid" aria-label="Grid layout">
200
- Grid
201
- </ToggleButton>
202
- </ToggleButtonGroup>
203
- </Tooltip>
204
- <Divider orientation="vertical" sx={dividerSx} />
205
- </>
206
- )}
207
183
  {/* What the page is made of. */}
208
184
  {onAddTile && (
209
185
  <Button
@@ -251,6 +227,7 @@ export function BuilderToolbar({
251
227
  <Divider orientation="vertical" sx={dividerSx} />
252
228
  )}
253
229
  {actions}
230
+ {onSave && saveStatus && <SaveStatus {...saveStatus} />}
254
231
  {onSave ? (
255
232
  <Tooltip
256
233
  title={
@@ -86,7 +86,6 @@ export function EditorSurface({
86
86
  onOpenModel,
87
87
  onControlsChange,
88
88
  draftKey,
89
- allowLayoutChange,
90
89
  onEvent,
91
90
  savesTo,
92
91
  saveLabel,
@@ -113,7 +112,6 @@ export function EditorSurface({
113
112
  onControlsChange?: BuilderControlsHandler;
114
113
  /** Keep unsaved edits in this browser under this key; see `ReportBuilderProps.draftKey`. */
115
114
  draftKey?: string;
116
- allowLayoutChange?: boolean;
117
115
  onEvent?: ReportEventHandler;
118
116
  savesTo: SavesTo;
119
117
  saveLabel?: string;
@@ -616,7 +614,6 @@ export function EditorSurface({
616
614
  {...(onOpenModel ? { onOpenModel } : {})}
617
615
  {...(onControlsChange ? { onControlsChange } : {})}
618
616
  {...(draftKey !== undefined ? { draftKey } : {})}
619
- {...(allowLayoutChange !== undefined ? { allowLayoutChange } : {})}
620
617
  {...(offered ? { catalog: offered } : {})}
621
618
  dashboards={otherDashboards}
622
619
  {...(onEvent ? { onEvent } : {})}
@@ -331,7 +331,7 @@ export function FilterDialog({
331
331
  })
332
332
  : "Any"
333
333
  : "All";
334
- // The builder's own segmented control, as the bar's layout switch is.
334
+ // The builder's own segmented control, as the tile picker's is.
335
335
  const segmentSx = {
336
336
  ...segmentedSx(edge, ui),
337
337
  alignSelf: "flex-start",