@malloy-publisher/sdk 0.9.10 → 0.9.11

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 (257) hide show
  1. package/dist/RenderedResult-BlNoIiSi.cjs.js +153 -0
  2. package/dist/{RenderedResult-Dp1Qdajz.es.js → RenderedResult-Cmx8sX8d.es.js} +102 -102
  3. package/dist/ServerProvider-BOgiW8MX.cjs.js +1 -0
  4. package/dist/{ServerProvider-CQy4jVYK.es.js → ServerProvider-azXLkk1q.es.js} +619 -586
  5. package/dist/builder/index.cjs.js +78 -130
  6. package/dist/builder/index.es.js +7493 -6769
  7. package/dist/builder-entry.d.ts +3 -0
  8. package/dist/client/api.d.ts +26 -22
  9. package/dist/client/index.cjs.js +1 -1
  10. package/dist/client/index.es.js +1 -1
  11. package/dist/components/AppDialog.d.ts +9 -1
  12. package/dist/components/Dashboard/DashboardGrid.d.ts +14 -15
  13. package/dist/components/Dashboard/DashboardTile.d.ts +8 -1
  14. package/dist/components/Dashboard/DashboardView.d.ts +22 -34
  15. package/dist/components/Dashboard/TileCard.d.ts +10 -3
  16. package/dist/components/Dashboard/useStuck.d.ts +15 -7
  17. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +6 -0
  18. package/dist/components/Package/PackageProblems.d.ts +14 -0
  19. package/dist/components/RemoveBadge.d.ts +40 -0
  20. package/dist/components/Report/Report.d.ts +13 -4
  21. package/dist/components/Report/ReportPage.d.ts +60 -0
  22. package/dist/components/Report/layoutRules.d.ts +32 -0
  23. package/dist/components/Report/reportQuery.d.ts +30 -0
  24. package/dist/components/Report/telemetry.d.ts +0 -2
  25. package/dist/components/ReportBuilder/AddTileDialog.d.ts +22 -3
  26. package/dist/components/ReportBuilder/BuilderBar.d.ts +17 -0
  27. package/dist/components/ReportBuilder/BuilderDialogs.d.ts +7 -6
  28. package/dist/components/ReportBuilder/BuilderGrid.d.ts +10 -4
  29. package/dist/components/ReportBuilder/BuilderHeader.d.ts +4 -7
  30. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +88 -0
  31. package/dist/components/ReportBuilder/DrillDialog.d.ts +3 -1
  32. package/dist/components/ReportBuilder/EditorSurface.d.ts +7 -9
  33. package/dist/components/ReportBuilder/FilterDialog.d.ts +3 -1
  34. package/dist/components/ReportBuilder/FilterStrip.d.ts +30 -8
  35. package/dist/components/ReportBuilder/InlineMarkdown.d.ts +4 -4
  36. package/dist/components/ReportBuilder/ReportBuilder.d.ts +49 -12
  37. package/dist/components/ReportBuilder/ReportEditor.d.ts +53 -3
  38. package/dist/components/ReportBuilder/TextTileBody.d.ts +2 -5
  39. package/dist/components/ReportBuilder/TileFrame.d.ts +10 -4
  40. package/dist/components/ReportBuilder/TileMenu.d.ts +12 -9
  41. package/dist/components/ReportBuilder/ViewPicker.d.ts +53 -0
  42. package/dist/components/ReportBuilder/addTileToDocument.d.ts +24 -3
  43. package/dist/components/ReportBuilder/builderControls.d.ts +60 -0
  44. package/dist/components/ReportBuilder/catalog.d.ts +2 -4
  45. package/dist/components/ReportBuilder/inlineEdit.d.ts +9 -10
  46. package/dist/components/ReportBuilder/localGiven.d.ts +12 -0
  47. package/dist/components/ReportBuilder/preview.d.ts +17 -2
  48. package/dist/components/ReportBuilder/readDocument.d.ts +0 -2
  49. package/dist/components/ReportBuilder/readForEditor.d.ts +2 -7
  50. package/dist/components/ReportBuilder/reportTag.d.ts +11 -1
  51. package/dist/components/ReportBuilder/sortable.d.ts +4 -3
  52. package/dist/components/ReportBuilder/testing/inline.d.ts +5 -1
  53. package/dist/components/ReportBuilder/useBuilderSelection.d.ts +0 -1
  54. package/dist/components/ReportBuilder/useBuilderSession.d.ts +21 -12
  55. package/dist/components/ReportBuilder/useDocumentEditor.d.ts +2 -6
  56. package/dist/components/ReportBuilder/useExitGuard.d.ts +3 -0
  57. package/dist/components/ReportBuilder/useFilterForm.d.ts +3 -1
  58. package/dist/components/ReportBuilder/useOpenedDocument.d.ts +0 -4
  59. package/dist/components/ReportBuilder/useReportDraft.d.ts +66 -0
  60. package/dist/components/ReportBuilder/useReportEditor.d.ts +0 -9
  61. package/dist/components/ReportBuilder/useTileEditing.d.ts +6 -3
  62. package/dist/components/ReportBuilder/viewAnnotations.d.ts +9 -0
  63. package/dist/components/ReportBuilder/widthLabel.d.ts +6 -0
  64. package/dist/components/ServerProvider.d.ts +9 -0
  65. package/dist/components/controlTokens.d.ts +45 -0
  66. package/dist/components/drill/markDrillableCells.d.ts +1 -1
  67. package/dist/components/given/FilterButton.d.ts +35 -0
  68. package/dist/components/given/GivensPanel.d.ts +2 -1
  69. package/dist/components/given/filterEditing.d.ts +54 -0
  70. package/dist/components/given/filterSummary.d.ts +9 -0
  71. package/dist/components/given/paramCodec.d.ts +11 -0
  72. package/dist/components/given/required.d.ts +25 -0
  73. package/dist/components/index.d.ts +3 -0
  74. package/dist/components/legacy/index.d.ts +1 -1
  75. package/dist/components/{Report/CellReport.d.ts → legacy/malloynb/CellRunnerView.d.ts} +9 -17
  76. package/dist/components/legacy/{MalloynbCells.d.ts → malloynb/MalloynbCells.d.ts} +3 -3
  77. package/dist/components/legacy/{Notebook.d.ts → malloynb/Notebook.d.ts} +1 -1
  78. package/dist/components/{Notebook → legacy/malloynb}/NotebookCell.d.ts +3 -3
  79. package/dist/components/legacy/malloynb/cellKind.d.ts +5 -0
  80. package/dist/components/{Notebook → legacy/malloynb}/types.d.ts +1 -1
  81. package/dist/components/styles.d.ts +0 -2
  82. package/dist/hooks/useQueryResult.d.ts +7 -0
  83. package/dist/index.cjs.js +16 -19
  84. package/dist/index.es.js +8324 -7769
  85. package/dist/theme/ThemeContext.d.ts +8 -1
  86. package/dist/theme/classes.d.ts +49 -0
  87. package/dist/theme/index.d.ts +2 -0
  88. package/dist/theme/types.d.ts +7 -0
  89. package/dist/theme/ui.d.ts +75 -0
  90. package/dist/{useCompiledDocument-BMPDvdFx.es.js → useCompiledDocument-7j5cBjQd.es.js} +8669 -7851
  91. package/dist/useCompiledDocument-B21sVbb4.cjs.js +141 -0
  92. package/package.json +2 -2
  93. package/src/builder-entry.ts +9 -0
  94. package/src/components/AppDialog.tsx +23 -0
  95. package/src/components/Dashboard/DashboardGrid.tsx +39 -17
  96. package/src/components/Dashboard/DashboardTile.tsx +19 -2
  97. package/src/components/Dashboard/DashboardView.spec.tsx +216 -15
  98. package/src/components/Dashboard/DashboardView.tsx +137 -155
  99. package/src/components/Dashboard/RowsDialog.tsx +1 -2
  100. package/src/components/Dashboard/TileCard.tsx +28 -10
  101. package/src/components/Dashboard/defaultTileSpan.spec.ts +24 -0
  102. package/src/components/Dashboard/useStuck.ts +28 -17
  103. package/src/components/DocumentCreate/useDocumentChoices.ts +19 -2
  104. package/src/components/Package/NewDocumentDialog.spec.tsx +76 -59
  105. package/src/components/Package/NewDocumentDialog.tsx +383 -119
  106. package/src/components/Package/Package.artifacts.spec.tsx +1 -1
  107. package/src/components/Package/Package.create.spec.tsx +7 -6
  108. package/src/components/Package/Package.tsx +10 -7
  109. package/src/components/Package/PackageProblems.spec.tsx +41 -0
  110. package/src/components/Package/PackageProblems.tsx +95 -0
  111. package/src/components/Prose.tsx +12 -7
  112. package/src/components/RemoveBadge.tsx +94 -0
  113. package/src/components/RenderedResult/RenderedResult.tsx +5 -9
  114. package/src/components/RenderedResult/ResultPanel.tsx +59 -3
  115. package/src/components/Report/Report.spec.tsx +50 -32
  116. package/src/components/Report/Report.telemetry.spec.tsx +0 -45
  117. package/src/components/Report/Report.tsx +45 -77
  118. package/src/components/Report/ReportPage.tsx +168 -0
  119. package/src/components/Report/layoutRules.spec.ts +35 -0
  120. package/src/components/Report/layoutRules.ts +55 -0
  121. package/src/components/Report/reportQuery.ts +53 -0
  122. package/src/components/Report/telemetry.ts +0 -2
  123. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +76 -41
  124. package/src/components/ReportBuilder/AddTileDialog.tsx +368 -133
  125. package/src/components/ReportBuilder/BuilderBar.tsx +599 -0
  126. package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -39
  127. package/src/components/ReportBuilder/BuilderGrid.tsx +31 -29
  128. package/src/components/ReportBuilder/BuilderHeader.tsx +63 -75
  129. package/src/components/ReportBuilder/BuilderToolbar.tsx +95 -9
  130. package/src/components/ReportBuilder/DrillDialog.tsx +240 -128
  131. package/src/components/ReportBuilder/EditorSurface.tsx +345 -69
  132. package/src/components/ReportBuilder/FilterDialog.tsx +516 -166
  133. package/src/components/ReportBuilder/FilterStrip.tsx +130 -151
  134. package/src/components/ReportBuilder/InlineMarkdown.tsx +71 -45
  135. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +35 -40
  136. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +491 -0
  137. package/src/components/ReportBuilder/ReportBuilder.exit.spec.tsx +2 -4
  138. package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +13 -15
  139. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +27 -118
  140. package/src/components/ReportBuilder/ReportBuilder.openDraft.spec.tsx +12 -5
  141. package/src/components/ReportBuilder/ReportBuilder.sources.spec.tsx +2 -10
  142. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +37 -31
  143. package/src/components/ReportBuilder/ReportBuilder.textTiles.spec.tsx +22 -15
  144. package/src/components/ReportBuilder/ReportBuilder.tsx +292 -117
  145. package/src/components/ReportBuilder/ReportEditor.emptyStart.spec.tsx +2 -1
  146. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +312 -0
  147. package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +26 -75
  148. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +6 -2
  149. package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -2
  150. package/src/components/ReportBuilder/ReportEditor.spec.tsx +2 -4
  151. package/src/components/ReportBuilder/ReportEditor.textSource.spec.tsx +93 -13
  152. package/src/components/ReportBuilder/ReportEditor.tsx +104 -14
  153. package/src/components/ReportBuilder/TextTileBody.tsx +6 -7
  154. package/src/components/ReportBuilder/TileFrame.tsx +212 -75
  155. package/src/components/ReportBuilder/TileMenu.tsx +241 -140
  156. package/src/components/ReportBuilder/ViewPicker.tsx +349 -0
  157. package/src/components/ReportBuilder/addTile.compile.spec.ts +1 -1
  158. package/src/components/ReportBuilder/addTileToDocument.spec.ts +102 -3
  159. package/src/components/ReportBuilder/addTileToDocument.ts +122 -25
  160. package/src/components/ReportBuilder/builderControls.ts +164 -0
  161. package/src/components/ReportBuilder/builderReport.ts +1 -2
  162. package/src/components/ReportBuilder/catalog.ts +10 -26
  163. package/src/components/ReportBuilder/inlineEdit.tsx +22 -54
  164. package/src/components/ReportBuilder/localGiven.ts +56 -0
  165. package/src/components/ReportBuilder/preview.spec.ts +125 -5
  166. package/src/components/ReportBuilder/preview.ts +60 -44
  167. package/src/components/ReportBuilder/readDocument.spec.ts +16 -22
  168. package/src/components/ReportBuilder/readDocument.ts +14 -11
  169. package/src/components/ReportBuilder/readForEditor.spec.ts +12 -41
  170. package/src/components/ReportBuilder/readForEditor.ts +4 -26
  171. package/src/components/ReportBuilder/reportTag.ts +28 -7
  172. package/src/components/ReportBuilder/sortable.tsx +15 -7
  173. package/src/components/ReportBuilder/spliceDocument.imports.spec.ts +1 -1
  174. package/src/components/ReportBuilder/tagParse.spec.ts +0 -40
  175. package/src/components/ReportBuilder/testing/inline.ts +25 -5
  176. package/src/components/ReportBuilder/testing/reportLayoutParity.json +13 -8
  177. package/src/components/ReportBuilder/textTiles.spec.ts +7 -6
  178. package/src/components/ReportBuilder/useBuilderSelection.ts +35 -0
  179. package/src/components/ReportBuilder/useBuilderSession.spec.ts +2 -2
  180. package/src/components/ReportBuilder/useBuilderSession.ts +21 -13
  181. package/src/components/ReportBuilder/useDocumentEditor.spec.ts +0 -58
  182. package/src/components/ReportBuilder/useDocumentEditor.ts +3 -16
  183. package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +26 -0
  184. package/src/components/ReportBuilder/useEditorCatalog.ts +7 -2
  185. package/src/components/ReportBuilder/useExitGuard.ts +16 -0
  186. package/src/components/ReportBuilder/useFilterForm.spec.tsx +17 -0
  187. package/src/components/ReportBuilder/useFilterForm.ts +5 -1
  188. package/src/components/ReportBuilder/useOpenedDocument.ts +0 -2
  189. package/src/components/ReportBuilder/useReportDraft.spec.ts +149 -0
  190. package/src/components/ReportBuilder/useReportDraft.ts +292 -0
  191. package/src/components/ReportBuilder/useReportEditor.ts +3 -12
  192. package/src/components/ReportBuilder/useSaveChannel.ts +0 -1
  193. package/src/components/ReportBuilder/useTileEditing.ts +43 -12
  194. package/src/components/ReportBuilder/viewAnnotations.ts +29 -0
  195. package/src/components/ReportBuilder/widthLabel.spec.ts +25 -0
  196. package/src/components/ReportBuilder/widthLabel.ts +26 -0
  197. package/src/components/ServerProvider.tsx +11 -0
  198. package/src/components/controlTokens.ts +47 -0
  199. package/src/components/drill/markDrillableCells.ts +2 -1
  200. package/src/components/given/FilterButton.spec.tsx +143 -0
  201. package/src/components/given/FilterButton.tsx +478 -0
  202. package/src/components/given/GivenInput.spec.tsx +47 -0
  203. package/src/components/given/GivenInput.tsx +20 -2
  204. package/src/components/given/GivensPanel.spec.tsx +11 -3
  205. package/src/components/given/GivensPanel.tsx +45 -44
  206. package/src/components/given/filterEditing.ts +60 -0
  207. package/src/components/given/filterSummary.spec.ts +108 -0
  208. package/src/components/given/filterSummary.ts +109 -0
  209. package/src/components/given/paramCodec.ts +1 -1
  210. package/src/components/given/required.spec.ts +60 -0
  211. package/src/components/given/required.ts +78 -0
  212. package/src/components/index.ts +9 -0
  213. package/src/components/legacy/Dashboard.spec.tsx +3 -1
  214. package/src/components/legacy/index.ts +1 -1
  215. package/src/components/{Report/CellReport.spec.tsx → legacy/malloynb/CellRunnerView.spec.tsx} +53 -57
  216. package/src/components/{Report/CellReport.tsx → legacy/malloynb/CellRunnerView.tsx} +122 -136
  217. package/src/components/legacy/{MalloynbCells.tsx → malloynb/MalloynbCells.tsx} +6 -6
  218. package/src/components/legacy/{Notebook.layout.spec.tsx → malloynb/Notebook.layout.spec.tsx} +16 -7
  219. package/src/components/legacy/malloynb/Notebook.served.spec.tsx +84 -0
  220. package/src/components/legacy/{Notebook.spec.tsx → malloynb/Notebook.spec.tsx} +5 -3
  221. package/src/components/legacy/{Notebook.tsx → malloynb/Notebook.tsx} +9 -7
  222. package/src/components/{Notebook → legacy/malloynb}/NotebookCell.tsx +70 -150
  223. package/src/components/legacy/malloynb/cellKind.spec.ts +33 -0
  224. package/src/components/legacy/malloynb/cellKind.ts +24 -0
  225. package/src/components/{Notebook → legacy/malloynb}/types.ts +1 -1
  226. package/src/components/styles.ts +0 -18
  227. package/src/hooks/useGivensState.ts +7 -3
  228. package/src/hooks/useQueryResult.placeholder.spec.ts +44 -0
  229. package/src/hooks/useQueryResult.ts +26 -1
  230. package/src/theme/ThemeContext.tsx +21 -1
  231. package/src/theme/classes.ts +52 -0
  232. package/src/theme/index.ts +8 -0
  233. package/src/theme/resolveTheme.ts +3 -0
  234. package/src/theme/types.ts +7 -0
  235. package/src/theme/ui.spec.tsx +91 -0
  236. package/src/theme/ui.ts +115 -0
  237. package/dist/RenderedResult-BcgYjkZ0.cjs.js +0 -153
  238. package/dist/ServerProvider-B0dUY8be.cjs.js +0 -1
  239. package/dist/components/Notebook/cellKind.d.ts +0 -20
  240. package/dist/components/Report/LinearReport.d.ts +0 -18
  241. package/dist/components/ReportBuilder/SourceViewPicker.d.ts +0 -9
  242. package/dist/components/ReportBuilder/legacyNotebook.d.ts +0 -73
  243. package/dist/components/ReportBuilder/useConversionConfirm.d.ts +0 -20
  244. package/dist/useCompiledDocument-UY28ITET.cjs.js +0 -141
  245. package/src/components/Notebook/cellKind.spec.ts +0 -199
  246. package/src/components/Notebook/cellKind.ts +0 -74
  247. package/src/components/Report/LinearReport.tsx +0 -71
  248. package/src/components/ReportBuilder/SourceViewPicker.tsx +0 -122
  249. package/src/components/ReportBuilder/legacyNotebook.chart.spec.ts +0 -77
  250. package/src/components/ReportBuilder/legacyNotebook.convert.spec.ts +0 -626
  251. package/src/components/ReportBuilder/legacyNotebook.read.spec.ts +0 -338
  252. package/src/components/ReportBuilder/legacyNotebook.ts +0 -1122
  253. package/src/components/ReportBuilder/useConversionConfirm.ts +0 -55
  254. package/src/components/legacy/Notebook.served.spec.tsx +0 -183
  255. /package/dist/components/{Notebook → legacy/malloynb}/runPlan.d.ts +0 -0
  256. /package/src/components/{Notebook → legacy/malloynb}/runPlan.spec.ts +0 -0
  257. /package/src/components/{Notebook → legacy/malloynb}/runPlan.ts +0 -0
@@ -0,0 +1,349 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import BarChartIcon from "@mui/icons-material/BarChart";
5
+ import MapIcon from "@mui/icons-material/Map";
6
+ import NumbersIcon from "@mui/icons-material/Numbers";
7
+ import ScatterPlotIcon from "@mui/icons-material/ScatterPlot";
8
+ import SearchIcon from "@mui/icons-material/Search";
9
+ import ShowChartIcon from "@mui/icons-material/ShowChart";
10
+ import TableChartIcon from "@mui/icons-material/TableChart";
11
+ import { Box, InputAdornment, TextField, Typography } from "@mui/material";
12
+ import { useId, useMemo, type ReactNode, type Ref } from "react";
13
+ import { usePublisherTheme } from "../../theme/ThemeContext";
14
+
15
+ /**
16
+ * Picking a view: one searchable list of every view on offer, grouped (by
17
+ * source, or by model and source), each by its title and its Malloy name with
18
+ * its chart's icon. The arrow keys move the pick from the search box and Enter
19
+ * takes it; a double click takes one directly.
20
+ *
21
+ * One component for every window that starts from a view (Add a tile, New
22
+ * report), so they look and work the same.
23
+ */
24
+ export interface PickerEntry {
25
+ /** Unique across every group. */
26
+ key: string;
27
+ /** The view's name in Malloy. */
28
+ name: string;
29
+ /** What the view is called to a reader: its doc line, or its name read as words. */
30
+ title: string;
31
+ /** The chart the view declares, for its icon; none is a table. */
32
+ chart?: string;
33
+ }
34
+
35
+ export interface PickerGroup {
36
+ key: string;
37
+ /** The group's name: a source. */
38
+ label: string;
39
+ /** A line beside it: the source's doc, or the model it comes from. */
40
+ detail?: string;
41
+ /** The group's accessible name, when its label alone is not unique ("orders in sales.malloy"). */
42
+ ariaLabel?: string;
43
+ entries: PickerEntry[];
44
+ }
45
+
46
+ /** `by_category` -> `By category`: a view's name read as words, where it has no doc line. */
47
+ export function readableName(name: string): string {
48
+ const words = name.replace(/_+/g, " ").trim();
49
+ return words.charAt(0).toUpperCase() + words.slice(1);
50
+ }
51
+
52
+ /** The icon for the chart a view declares; a table when it declares none. */
53
+ export function ChartGlyph({ chart }: { chart: string | undefined }) {
54
+ const sx = { fontSize: 16 };
55
+ switch (chart) {
56
+ case "bar_chart":
57
+ return <BarChartIcon sx={sx} />;
58
+ case "line_chart":
59
+ case "sparkline":
60
+ return <ShowChartIcon sx={sx} />;
61
+ case "scatter_chart":
62
+ return <ScatterPlotIcon sx={sx} />;
63
+ case "shape_map":
64
+ case "segment_map":
65
+ return <MapIcon sx={sx} />;
66
+ case "big_value":
67
+ return <NumbersIcon sx={sx} />;
68
+ default:
69
+ return <TableChartIcon sx={sx} />;
70
+ }
71
+ }
72
+
73
+ export function ViewPicker({
74
+ groups,
75
+ query,
76
+ onQuery,
77
+ picked,
78
+ onPick,
79
+ onTake,
80
+ searchRef,
81
+ empty,
82
+ footer,
83
+ disabled = false,
84
+ }: {
85
+ groups: PickerGroup[];
86
+ query: string;
87
+ onQuery: (next: string) => void;
88
+ /** The picked entry's key. */
89
+ picked: string | undefined;
90
+ onPick: (key: string) => void;
91
+ /** Enter on the search, or a double click: take the pick and go. */
92
+ onTake: (key: string) => void;
93
+ /** The search box, for a window to start in. */
94
+ searchRef?: Ref<HTMLInputElement>;
95
+ /** Shown in place of the list when there are no groups at all. */
96
+ empty?: ReactNode;
97
+ /** Under the list, when there is no search. */
98
+ footer?: ReactNode;
99
+ disabled?: boolean;
100
+ }) {
101
+ const { theme } = usePublisherTheme();
102
+ const ui = theme.ui;
103
+ const listId = useId();
104
+ const needle = query.trim().toLowerCase();
105
+ const shown = useMemo(
106
+ () =>
107
+ groups
108
+ .map((group) => ({
109
+ ...group,
110
+ entries: group.entries.filter(
111
+ (entry) =>
112
+ needle === "" ||
113
+ [entry.name, entry.title, group.label, group.detail ?? ""]
114
+ .join(" ")
115
+ .toLowerCase()
116
+ .includes(needle),
117
+ ),
118
+ }))
119
+ .filter((group) => group.entries.length > 0),
120
+ [groups, needle],
121
+ );
122
+ const flat = shown.flatMap((group) => group.entries);
123
+ // Ids by position among every entry, not by key: a key made safe for an id
124
+ // could collide with another ("a" + "b_c" and "a_b" + "c").
125
+ const ids = useMemo(
126
+ () =>
127
+ new Map(
128
+ groups
129
+ .flatMap((group) => group.entries)
130
+ .map((entry, i) => [entry.key, `${listId}-${i}`] as const),
131
+ ),
132
+ [groups, listId],
133
+ );
134
+ const optionId = (key: string) => ids.get(key) ?? `${listId}-none`;
135
+ // The pick as the list shows it: hidden by a search, it is not what Enter
136
+ // takes or what the list says is active.
137
+ const shownPick = flat.some((entry) => entry.key === picked)
138
+ ? picked
139
+ : undefined;
140
+ const pick = (key: string) => {
141
+ onPick(key);
142
+ window.requestAnimationFrame(() =>
143
+ window.document
144
+ .getElementById(optionId(key))
145
+ ?.scrollIntoView({ block: "nearest" }),
146
+ );
147
+ };
148
+ const step = (delta: 1 | -1) => {
149
+ if (flat.length === 0) return;
150
+ const at = flat.findIndex((entry) => entry.key === shownPick);
151
+ const next =
152
+ at === -1
153
+ ? delta === 1
154
+ ? 0
155
+ : flat.length - 1
156
+ : Math.min(flat.length - 1, Math.max(0, at + delta));
157
+ pick(flat[next]!.key);
158
+ };
159
+
160
+ return (
161
+ <Box
162
+ sx={{
163
+ display: "flex",
164
+ flexDirection: "column",
165
+ minHeight: 0,
166
+ flex: 1,
167
+ }}
168
+ >
169
+ <Box sx={{ p: 1.5, pb: 1 }}>
170
+ <TextField
171
+ size="small"
172
+ fullWidth
173
+ inputRef={searchRef}
174
+ placeholder="Search views"
175
+ value={query}
176
+ disabled={disabled}
177
+ onChange={(event) => onQuery(event.target.value)}
178
+ onKeyDown={(event) => {
179
+ if (event.key === "ArrowDown") {
180
+ event.preventDefault();
181
+ step(1);
182
+ } else if (event.key === "ArrowUp") {
183
+ event.preventDefault();
184
+ step(-1);
185
+ } else if (event.key === "Enter") {
186
+ // The pick if the search still shows it, else the top
187
+ // match: what the author is looking at.
188
+ const take = shownPick ?? flat[0]?.key;
189
+ if (take === undefined) return;
190
+ event.preventDefault();
191
+ onTake(take);
192
+ }
193
+ }}
194
+ inputProps={{
195
+ "aria-label": "Search views",
196
+ role: "combobox",
197
+ "aria-controls": listId,
198
+ "aria-expanded": true,
199
+ ...(shownPick !== undefined
200
+ ? { "aria-activedescendant": optionId(shownPick) }
201
+ : {}),
202
+ }}
203
+ InputProps={{
204
+ startAdornment: (
205
+ <InputAdornment position="start">
206
+ <SearchIcon
207
+ sx={{ fontSize: 18, color: "text.secondary" }}
208
+ />
209
+ </InputAdornment>
210
+ ),
211
+ }}
212
+ />
213
+ </Box>
214
+ <Box
215
+ id={listId}
216
+ role="listbox"
217
+ aria-label="Views"
218
+ sx={{ overflowY: "auto", flex: 1, minHeight: 0, pb: 1 }}
219
+ >
220
+ {groups.length === 0 && empty}
221
+ {groups.length > 0 && shown.length === 0 && (
222
+ <Typography
223
+ variant="body2"
224
+ sx={{ color: theme.tileTitle, px: 2, py: 1 }}
225
+ >
226
+ No view matches “{query.trim()}”.
227
+ </Typography>
228
+ )}
229
+ {shown.map((group) => (
230
+ <Box
231
+ key={group.key}
232
+ role="group"
233
+ aria-label={group.ariaLabel ?? group.label}
234
+ >
235
+ <Box
236
+ aria-hidden
237
+ sx={{
238
+ px: 2,
239
+ pt: 1.25,
240
+ pb: 0.5,
241
+ ...ui.type.caption,
242
+ color: "text.secondary",
243
+ whiteSpace: "nowrap",
244
+ overflow: "hidden",
245
+ textOverflow: "ellipsis",
246
+ }}
247
+ >
248
+ <Box
249
+ component="span"
250
+ sx={{
251
+ ...ui.type.label,
252
+ fontSize: "0.92em",
253
+ letterSpacing: "0.04em",
254
+ textTransform: "uppercase",
255
+ }}
256
+ >
257
+ {group.label.replace(/_+/g, " ")}
258
+ </Box>
259
+ {group.detail && ` · ${group.detail}`}
260
+ </Box>
261
+ {group.entries.map((entry) => {
262
+ const selected = entry.key === picked;
263
+ return (
264
+ <Box
265
+ key={entry.key}
266
+ id={optionId(entry.key)}
267
+ role="option"
268
+ aria-selected={selected}
269
+ aria-label={`${entry.title} (${entry.name})`}
270
+ onClick={() => {
271
+ if (!disabled) pick(entry.key);
272
+ }}
273
+ onDoubleClick={() => {
274
+ if (!disabled) onTake(entry.key);
275
+ }}
276
+ sx={(mui) => ({
277
+ display: "flex",
278
+ alignItems: "center",
279
+ gap: 1.25,
280
+ mx: 0.75,
281
+ px: 1.25,
282
+ py: 0.75,
283
+ borderRadius: ui.radius.control,
284
+ cursor: disabled ? "default" : "pointer",
285
+ bgcolor: selected
286
+ ? `color-mix(in srgb, ${theme.accent} 9%, ${mui.palette.background.paper})`
287
+ : "transparent",
288
+ "&:hover":
289
+ selected || disabled
290
+ ? {}
291
+ : { bgcolor: mui.palette.action.hover },
292
+ })}
293
+ >
294
+ <Box
295
+ aria-hidden
296
+ sx={(mui) => ({
297
+ width: 26,
298
+ height: 26,
299
+ flex: "none",
300
+ borderRadius: ui.radius.control,
301
+ display: "flex",
302
+ alignItems: "center",
303
+ justifyContent: "center",
304
+ color: selected
305
+ ? theme.accent
306
+ : mui.palette.text.secondary,
307
+ bgcolor: selected
308
+ ? mui.palette.background.paper
309
+ : mui.palette.action.hover,
310
+ boxShadow: selected
311
+ ? `inset 0 0 0 1px color-mix(in srgb, ${theme.accent} 35%, transparent)`
312
+ : "none",
313
+ })}
314
+ >
315
+ <ChartGlyph chart={entry.chart} />
316
+ </Box>
317
+ <Box sx={{ minWidth: 0 }}>
318
+ <Box
319
+ sx={{
320
+ ...ui.type.control,
321
+ fontWeight: selected
322
+ ? ui.type.label.fontWeight
323
+ : 400,
324
+ whiteSpace: "nowrap",
325
+ overflow: "hidden",
326
+ textOverflow: "ellipsis",
327
+ }}
328
+ >
329
+ {entry.title}
330
+ </Box>
331
+ <Box
332
+ sx={{
333
+ ...ui.type.code,
334
+ color: "text.secondary",
335
+ }}
336
+ >
337
+ {entry.name}
338
+ </Box>
339
+ </Box>
340
+ </Box>
341
+ );
342
+ })}
343
+ </Box>
344
+ ))}
345
+ {needle === "" && footer}
346
+ </Box>
347
+ </Box>
348
+ );
349
+ }
@@ -95,7 +95,7 @@ async function addTile(
95
95
  view: "by_category",
96
96
  colspan: 6,
97
97
  },
98
- { modelPath: DOCUMENT, textHeld, notebook: false },
98
+ { modelPath: DOCUMENT, textHeld, widths: true },
99
99
  );
100
100
  const result = await spliceDashboardDocument(text, document);
101
101
  if (spliceFailed(result)) throw new Error(result.reason);
@@ -3,7 +3,12 @@
3
3
 
4
4
  import { describe, expect, it } from "bun:test";
5
5
  import type { NewTile } from "./AddTileDialog";
6
- import { addTileToDocument, type AddTileContext } from "./addTileToDocument";
6
+ import {
7
+ addTileToDocument,
8
+ duplicateBlocked,
9
+ duplicateTile,
10
+ type AddTileContext,
11
+ } from "./addTileToDocument";
7
12
  import type { DashboardDocument } from "./document";
8
13
 
9
14
  const document = (): DashboardDocument => ({
@@ -25,7 +30,7 @@ const tile: NewTile = {
25
30
  const context: AddTileContext = {
26
31
  modelPath: "dashboards/x.malloy",
27
32
  textHeld: false,
28
- notebook: false,
33
+ widths: true,
29
34
  };
30
35
 
31
36
  describe("addTileToDocument", () => {
@@ -51,9 +56,103 @@ describe("addTileToDocument", () => {
51
56
 
52
57
  it("puts the tile on a new extension of its base, and leaves a notebook tile without a width", () => {
53
58
  const draft = document();
54
- addTileToDocument(draft, tile, { ...context, notebook: true });
59
+ addTileToDocument(draft, tile, { ...context, widths: false });
55
60
  expect(draft.sources).toEqual([{ name: "orders_tiles", base: "orders" }]);
56
61
  expect(draft.tiles).toHaveLength(1);
57
62
  expect(draft.tiles[0]).not.toHaveProperty("colspan");
58
63
  });
59
64
  });
65
+
66
+ describe("duplicateTile", () => {
67
+ const withTiles = (
68
+ tiles: DashboardDocument["tiles"],
69
+ ): DashboardDocument => ({
70
+ ...document(),
71
+ sources: [{ name: "orders_tiles", base: "orders" }],
72
+ tiles,
73
+ });
74
+
75
+ it("copies a view this file declares, as a view of its own right after it", () => {
76
+ const draft = withTiles([
77
+ {
78
+ name: "by_day_tile",
79
+ source: "orders_tiles",
80
+ declaration: { kind: "reference", from: "by_day" },
81
+ label: "Daily",
82
+ chart: "bar_chart",
83
+ colspan: 6,
84
+ break: true,
85
+ filters: [{ field: "region", given: "REGION" }],
86
+ },
87
+ ]);
88
+ expect(duplicateTile(draft, 0)).toBe(1);
89
+ expect(draft.tiles[1]).toEqual({
90
+ name: "by_day_tile_2",
91
+ source: "orders_tiles",
92
+ declaration: { kind: "reference", from: "by_day" },
93
+ label: "Daily",
94
+ chart: "bar_chart",
95
+ colspan: 6,
96
+ filters: [{ field: "region", given: "REGION" }],
97
+ });
98
+ });
99
+
100
+ it("copies a view the model declares onto the file's extension of its source", () => {
101
+ const draft: DashboardDocument = {
102
+ ...document(),
103
+ tiles: [
104
+ {
105
+ name: "by_brand",
106
+ source: "orders",
107
+ declaration: { kind: "inherited" as const },
108
+ label: "From the model",
109
+ colspan: 4,
110
+ },
111
+ ],
112
+ };
113
+ expect(duplicateTile(draft, 0)).toBe(1);
114
+ expect(draft.sources).toEqual([{ name: "orders_tiles", base: "orders" }]);
115
+ expect(draft.tiles[1]).toEqual({
116
+ name: "by_brand_tile",
117
+ source: "orders_tiles",
118
+ declaration: { kind: "reference", from: "by_brand" },
119
+ colspan: 4,
120
+ });
121
+ });
122
+
123
+ it("refuses a view whose body the writer would have to copy, and says why", () => {
124
+ const inline = {
125
+ name: "t",
126
+ source: "orders_tiles",
127
+ declaration: { kind: "inline" as const },
128
+ };
129
+ const draft = withTiles([inline]);
130
+ expect(duplicateBlocked(inline)).toContain("does not copy");
131
+ expect(duplicateTile(draft, 0)).toBeUndefined();
132
+ expect(draft.tiles).toHaveLength(1);
133
+ });
134
+ });
135
+
136
+ describe("duplicateTile onto a narrowed extension", () => {
137
+ it("copies a model view onto an unnarrowed extension, never a scoped one", () => {
138
+ const draft: DashboardDocument = {
139
+ ...document(),
140
+ sources: [
141
+ { name: "orders_west", base: "orders", scopedBy: ["REGION"] },
142
+ ],
143
+ tiles: [
144
+ {
145
+ name: "by_brand",
146
+ source: "orders",
147
+ declaration: { kind: "inherited" },
148
+ },
149
+ ],
150
+ };
151
+ expect(duplicateTile(draft, 0)).toBe(1);
152
+ expect(draft.tiles[1]).toMatchObject({ source: "orders_tiles" });
153
+ expect(draft.sources.map((s) => s.name)).toEqual([
154
+ "orders_west",
155
+ "orders_tiles",
156
+ ]);
157
+ });
158
+ });
@@ -2,7 +2,12 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import type { NewTile } from "./AddTileDialog";
5
- import { isQueryTile, type DashboardDocument } from "./document";
5
+ import {
6
+ isQueryTile,
7
+ type DashboardDocument,
8
+ type DashboardSource,
9
+ type QueryTile,
10
+ } from "./document";
6
11
  import { withSource } from "./imports";
7
12
 
8
13
  /** Where a tile is added and what the document is: the parts of an add that are not the tile. */
@@ -11,7 +16,8 @@ export interface AddTileContext {
11
16
  modelPath: string | undefined;
12
17
  /** The document is held as text: it has no `import`, so a tile's source is the run model's and nothing is imported. */
13
18
  textHeld: boolean;
14
- notebook: boolean;
19
+ /** Whether tiles carry a width (`LayoutRules.widths`): off, an added tile takes none. */
20
+ widths: boolean;
15
21
  /** Where the tile lands; undefined appends. */
16
22
  insertAt?: number;
17
23
  }
@@ -20,7 +26,7 @@ export interface AddTileContext {
20
26
  export function addTileToDocument(
21
27
  draft: DashboardDocument,
22
28
  tile: NewTile,
23
- { modelPath, textHeld, notebook, insertAt }: AddTileContext,
29
+ { modelPath, textHeld, widths, insertAt }: AddTileContext,
24
30
  ): void {
25
31
  // A source the file cannot see yet comes in by name, with the tile.
26
32
  if (tile.modelPath && !textHeld)
@@ -31,34 +37,125 @@ export function addTileToDocument(
31
37
  modelPath,
32
38
  tile.exporters ?? [tile.modelPath],
33
39
  );
34
- let extension = draft.sources.find((s) => s.base === tile.base);
35
- if (!extension) {
36
- // A name of the file's own: the base's, suffixed, since an
37
- // extension cannot share its base's name.
38
- const taken = new Set(draft.sources.map((s) => s.name));
39
- let name = `${tile.base}_tiles`;
40
- for (let n = 2; taken.has(name); n++) name = `${tile.base}_tiles_${n}`;
41
- extension = { name, base: tile.base };
42
- draft.sources.push(extension);
43
- }
44
- // The view's name in the extension: the base view's, suffixed,
45
- // because an extension inherits its base's views and cannot redeclare
46
- // one under the same name; then kept distinct from its siblings.
47
- const used = new Set(
48
- draft.tiles
49
- .filter(isQueryTile)
50
- .filter((t) => t.source === extension!.name)
51
- .map((t) => t.name),
52
- );
53
- let name = `${tile.view}_tile`;
54
- for (let n = 2; used.has(name); n++) name = `${tile.view}_tile_${n}`;
40
+ const extension = extensionOf(draft, tile.base);
41
+ const name = freeViewName(draft, extension.name, tile.view);
55
42
  draft.tiles.splice(insertAt ?? draft.tiles.length, 0, {
56
43
  name,
57
44
  source: extension.name,
58
45
  declaration: { kind: "reference", from: tile.view },
59
- ...(notebook ? {} : { colspan: tile.colspan }),
46
+ ...(widths ? { colspan: tile.colspan } : {}),
60
47
  ...(tile.label ? { label: tile.label } : {}),
61
48
  ...(tile.chart ? { chart: tile.chart } : {}),
62
49
  ...(tile.chartCarried ? { chartCarried: tile.chartCarried } : {}),
63
50
  });
64
51
  }
52
+
53
+ /** The file's extension of `base`, or a new one under a name of the file's own. */
54
+ function extensionOf(
55
+ draft: DashboardDocument,
56
+ base: string,
57
+ { unscoped = false }: { unscoped?: boolean } = {},
58
+ ): DashboardSource {
59
+ const found = draft.sources.find(
60
+ (s) => s.base === base && (!unscoped || !s.scopedBy?.length),
61
+ );
62
+ if (found) return found;
63
+ // A name of the file's own: the base's, suffixed, since an extension cannot
64
+ // share its base's name.
65
+ const taken = new Set(draft.sources.map((s) => s.name));
66
+ let name = `${base}_tiles`;
67
+ for (let n = 2; taken.has(name); n++) name = `${base}_tiles_${n}`;
68
+ const extension: DashboardSource = { name, base };
69
+ draft.sources.push(extension);
70
+ return extension;
71
+ }
72
+
73
+ /**
74
+ * A tile's view name in `extension`: the view it shows, suffixed, because an
75
+ * extension inherits its base's views and cannot redeclare one under the same
76
+ * name; then kept distinct from its siblings.
77
+ */
78
+ function freeViewName(
79
+ draft: DashboardDocument,
80
+ extension: string,
81
+ view: string,
82
+ ): string {
83
+ const used = new Set(
84
+ draft.tiles
85
+ .filter(isQueryTile)
86
+ .filter((t) => t.source === extension)
87
+ .map((t) => t.name),
88
+ );
89
+ let name = `${view}_tile`;
90
+ for (let n = 2; used.has(name); n++) name = `${view}_tile_${n}`;
91
+ return name;
92
+ }
93
+
94
+ /**
95
+ * Why a tile cannot be duplicated, or undefined when it can. A copy is a new
96
+ * view in this file, and the writer adds a view only as `view: x is y`, so a
97
+ * tile whose view the file writes some other way has no copy it could write.
98
+ */
99
+ export function duplicateBlocked(tile: QueryTile): string | undefined {
100
+ switch (tile.declaration.kind) {
101
+ case "inline":
102
+ return "Its query is written in this file, and the builder does not copy a query's body.";
103
+ case "opaque":
104
+ return `Its query is ${tile.declaration.why}, which the builder does not copy.`;
105
+ default:
106
+ return tile.chart === "custom"
107
+ ? "Its chart line is one the builder does not write, so a copy would lose it."
108
+ : undefined;
109
+ }
110
+ }
111
+
112
+ /**
113
+ * A copy of the query tile at `index`, placed right after it, as a view of its
114
+ * own so its title, chart and width can differ from the original's. Returns
115
+ * where the copy landed, or undefined when it cannot be copied
116
+ * ({@link duplicateBlocked}).
117
+ *
118
+ * A copy of a view this file declares shows the same view the original does
119
+ * (`is` the original's `from`, never the original's own name, which would carry
120
+ * the original's tags and break when the original is removed), with every
121
+ * setting the original has. A copy of a view the model declares starts as any
122
+ * added tile does: the model's view under a name of the file's own, at the
123
+ * original's width.
124
+ */
125
+ export function duplicateTile(
126
+ draft: DashboardDocument,
127
+ index: number,
128
+ ): number | undefined {
129
+ const original = draft.tiles[index];
130
+ if (!original || !isQueryTile(original)) return undefined;
131
+ if (duplicateBlocked(original) !== undefined) return undefined;
132
+ let copy: QueryTile;
133
+ if (original.declaration.kind === "reference") {
134
+ const { break: _break, ...settings } = structuredClone(original);
135
+ copy = {
136
+ ...settings,
137
+ name: freeViewName(draft, original.source, original.declaration.from),
138
+ };
139
+ } else {
140
+ // Inherited: a view of the source the tile names. When the file
141
+ // declares that source, the copy goes on it; otherwise on the file's
142
+ // extension of it, as an added tile would.
143
+ // On the file's extension of the source the tile names, but never one
144
+ // that narrows it with a `where:` of its own: the original reads the
145
+ // source unfiltered, and a copy on a narrowed extension would show
146
+ // other numbers under the same title.
147
+ const own = draft.sources.find((s) => s.name === original.source);
148
+ const extension =
149
+ own ?? extensionOf(draft, original.source, { unscoped: true });
150
+ copy = {
151
+ name: freeViewName(draft, extension.name, original.name),
152
+ source: extension.name,
153
+ declaration: { kind: "reference", from: original.name },
154
+ ...(original.colspan !== undefined
155
+ ? { colspan: original.colspan }
156
+ : {}),
157
+ };
158
+ }
159
+ draft.tiles.splice(index + 1, 0, copy);
160
+ return index + 1;
161
+ }