@malloy-publisher/sdk 0.0.382-dev → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/README.md +115 -95
  2. package/TREE_SHAKING.md +16 -11
  3. package/bunfig.toml +7 -0
  4. package/dist/ServerProvider-Cn_LhKda.cjs.js +1 -0
  5. package/dist/ServerProvider-sfabtriY.es.js +4076 -0
  6. package/dist/client/api.d.ts +3773 -1515
  7. package/dist/client/configuration.d.ts +1 -1
  8. package/dist/client/index.cjs.js +1 -1
  9. package/dist/client/index.d.ts +1 -1
  10. package/dist/client/index.es.js +86 -59
  11. package/dist/components/Connections/EditConnectionDialog.d.ts +2 -1
  12. package/dist/components/Connections/common.d.ts +8 -2
  13. package/dist/components/Dashboard/Dashboard.d.ts +62 -0
  14. package/dist/components/Dashboard/DashboardTile.d.ts +57 -0
  15. package/dist/components/Dashboard/index.d.ts +2 -0
  16. package/dist/components/DataAppViewer/DataAppViewer.d.ts +23 -0
  17. package/dist/components/DataAppViewer/index.d.ts +1 -0
  18. package/dist/components/Environment/Environment.d.ts +6 -0
  19. package/dist/components/Environment/index.d.ts +2 -0
  20. package/dist/components/Home/AddEnvironmentDialog.d.ts +1 -0
  21. package/dist/components/Home/DeleteEnvironmentDialog.d.ts +5 -0
  22. package/dist/components/Home/EditEnvironmentDialog.d.ts +7 -0
  23. package/dist/components/Home/Home.d.ts +2 -2
  24. package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +14 -0
  25. package/dist/components/Materializations/CreateMaterializationDialog.d.ts +10 -0
  26. package/dist/components/Materializations/DeleteMaterializationDialog.d.ts +7 -0
  27. package/dist/components/Materializations/EnvironmentMaterializations.d.ts +7 -0
  28. package/dist/components/Materializations/ManifestView.d.ts +13 -0
  29. package/dist/components/Materializations/MaterializationDetailDialog.d.ts +9 -0
  30. package/dist/components/Materializations/MaterializationRunsList.d.ts +15 -0
  31. package/dist/components/Materializations/Materializations.d.ts +7 -0
  32. package/dist/components/Materializations/ScheduleCard.d.ts +20 -0
  33. package/dist/components/Materializations/SectionLabel.d.ts +10 -0
  34. package/dist/components/Materializations/SetScheduleDialog.d.ts +11 -0
  35. package/dist/components/Materializations/TriggerChip.d.ts +10 -0
  36. package/dist/components/Materializations/cron.d.ts +23 -0
  37. package/dist/components/Materializations/index.d.ts +2 -0
  38. package/dist/components/Materializations/utils.d.ts +46 -0
  39. package/dist/components/Notebook/Notebook.d.ts +47 -4
  40. package/dist/components/Notebook/NotebookCell.d.ts +37 -1
  41. package/dist/components/Notebook/runPlan.d.ts +29 -0
  42. package/dist/components/Notebook/types.d.ts +10 -0
  43. package/dist/components/Package/ContentTypeIcon.d.ts +31 -0
  44. package/dist/components/Package/Package.d.ts +1 -4
  45. package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
  46. package/dist/components/RenderedResult/ResultContainer.d.ts +5 -1
  47. package/dist/components/RenderedResult/renderLogs.d.ts +6 -0
  48. package/dist/components/ResultsDialog.d.ts +6 -1
  49. package/dist/components/ServerProvider.d.ts +28 -4
  50. package/dist/components/click_helper.d.ts +10 -1
  51. package/dist/components/drill/index.d.ts +3 -0
  52. package/dist/components/drill/markDrillableCells.d.ts +55 -0
  53. package/dist/components/drill/resolveDrill.d.ts +139 -0
  54. package/dist/components/drill/useDrill.d.ts +63 -0
  55. package/dist/components/given/GivenInput.d.ts +52 -0
  56. package/dist/components/given/GivensPanel.d.ts +47 -0
  57. package/dist/components/given/filterValue.d.ts +97 -0
  58. package/dist/components/given/index.d.ts +2 -0
  59. package/dist/components/given/paramCodec.d.ts +60 -0
  60. package/dist/components/given/utils.d.ts +17 -0
  61. package/dist/components/highlighter.d.ts +6 -1
  62. package/dist/components/index.d.ts +7 -2
  63. package/dist/components/styles.d.ts +47 -0
  64. package/dist/constants/docLinks.d.ts +12 -0
  65. package/dist/{core-YNpOLuB1.cjs.js → core-CqRKhtoy.cjs.js} +1 -1
  66. package/dist/{core-CjeTkq8O.es.js → core-DyU47reh.es.js} +1 -1
  67. package/dist/github-dark-BKL9xNgN.cjs.js +1 -0
  68. package/dist/github-dark-DenFmJkN.es.js +4 -0
  69. package/dist/hooks/givenValue.d.ts +10 -0
  70. package/dist/hooks/index.d.ts +4 -0
  71. package/dist/hooks/useDimensionFiltersFromSpec.d.ts +3 -3
  72. package/dist/hooks/useDimensionFiltersQuery.d.ts +3 -3
  73. package/dist/hooks/useDimensionalFilterRangeData.d.ts +4 -4
  74. package/dist/hooks/useGivensState.d.ts +64 -0
  75. package/dist/hooks/useModelGivens.d.ts +10 -0
  76. package/dist/hooks/useSuggestOptions.d.ts +78 -0
  77. package/dist/{index-DRDu9kIV.es.js → index-CAkFE4Ol.es.js} +41278 -28504
  78. package/dist/index-DD4b_bt0.cjs.js +356 -0
  79. package/dist/index.cjs.js +1 -1
  80. package/dist/index.d.ts +4 -1
  81. package/dist/index.es.js +79 -48
  82. package/dist/malloy-explorer.css +12 -1
  83. package/dist/sdk.css +1 -1
  84. package/dist/theme/ThemeContext.d.ts +45 -0
  85. package/dist/theme/buildMalloyExplicitTheme.d.ts +34 -0
  86. package/dist/theme/buildTableCssVars.d.ts +41 -0
  87. package/dist/theme/buildVegaThemeOverride.d.ts +16 -0
  88. package/dist/theme/defaults.d.ts +7 -0
  89. package/dist/theme/index.d.ts +8 -0
  90. package/dist/theme/keys.d.ts +20 -0
  91. package/dist/theme/readChartAnnotations.d.ts +23 -0
  92. package/dist/theme/resolveTheme.d.ts +22 -0
  93. package/dist/theme/types.d.ts +70 -0
  94. package/dist/utils/dataAppEmbed.d.ts +44 -0
  95. package/dist/utils/formatting.d.ts +1 -1
  96. package/dist/utils/malloyString.d.ts +7 -0
  97. package/dist/utils/parsing.d.ts +2 -2
  98. package/dist/utils/queryClient.d.ts +5 -0
  99. package/package.json +19 -8
  100. package/src/client-entry.ts +3 -0
  101. package/src/components/AnalyzePackageButton.tsx +9 -3
  102. package/src/components/ApiErrorDisplay.tsx +3 -0
  103. package/src/components/Connections/AddConnectionDialog.tsx +132 -25
  104. package/src/components/Connections/DeleteConnectionDialog.tsx +14 -3
  105. package/src/components/Connections/EditConnectionDialog.tsx +167 -37
  106. package/src/components/Connections/common.ts +94 -3
  107. package/src/components/DOMElement/DOMElement.tsx +3 -0
  108. package/src/components/DOMElement/index.ts +3 -0
  109. package/src/components/Dashboard/Dashboard.spec.tsx +216 -0
  110. package/src/components/Dashboard/Dashboard.tsx +458 -0
  111. package/src/components/Dashboard/DashboardTile.spec.tsx +81 -0
  112. package/src/components/Dashboard/DashboardTile.tsx +199 -0
  113. package/src/components/Dashboard/index.ts +5 -0
  114. package/src/components/Dashboard/tileGridColumn.spec.ts +35 -0
  115. package/src/components/DataAppViewer/DataAppViewer.tsx +214 -0
  116. package/src/components/DataAppViewer/index.ts +4 -0
  117. package/src/components/{Project → Environment}/About.tsx +11 -4
  118. package/src/components/Environment/AddPackageDialog.tsx +202 -0
  119. package/src/components/{Project → Environment}/ConnectionExplorer.tsx +17 -14
  120. package/src/components/Environment/Connections.tsx +391 -0
  121. package/src/components/{Project → Environment}/DeletePackageDialog.tsx +8 -4
  122. package/src/components/{Project → Environment}/EditPackageDialog.tsx +21 -13
  123. package/src/components/Environment/Environment.tsx +89 -0
  124. package/src/components/Environment/Packages.tsx +206 -0
  125. package/src/components/Environment/index.ts +5 -0
  126. package/src/components/Home/{AddProjectDialog.tsx → AddEnvironmentDialog.tsx} +25 -19
  127. package/src/components/Home/{DeleteProjectDialog.tsx → DeleteEnvironmentDialog.tsx} +20 -15
  128. package/src/components/Home/{EditProjectDialog.tsx → EditEnvironmentDialog.tsx} +35 -28
  129. package/src/components/Home/Home.tsx +386 -408
  130. package/src/components/Home/index.ts +3 -0
  131. package/src/components/Loading.tsx +3 -0
  132. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +179 -0
  133. package/src/components/Materializations/CreateMaterializationDialog.tsx +112 -0
  134. package/src/components/Materializations/DeleteMaterializationDialog.tsx +109 -0
  135. package/src/components/Materializations/EnvironmentMaterializations.tsx +267 -0
  136. package/src/components/Materializations/ManifestView.tsx +87 -0
  137. package/src/components/Materializations/MaterializationDetailDialog.tsx +259 -0
  138. package/src/components/Materializations/MaterializationRunsList.tsx +256 -0
  139. package/src/components/Materializations/Materializations.tsx +355 -0
  140. package/src/components/Materializations/ScheduleCard.tsx +231 -0
  141. package/src/components/Materializations/SectionLabel.tsx +30 -0
  142. package/src/components/Materializations/SetScheduleDialog.tsx +162 -0
  143. package/src/components/Materializations/TriggerChip.tsx +44 -0
  144. package/src/components/Materializations/cron.ts +124 -0
  145. package/src/components/Materializations/index.ts +5 -0
  146. package/src/components/Materializations/utils.ts +145 -0
  147. package/src/components/Model/Model.tsx +44 -2
  148. package/src/components/Model/ModelCell.tsx +14 -5
  149. package/src/components/Model/ModelExplorer.tsx +3 -0
  150. package/src/components/Model/ModelExplorerDialog.tsx +4 -1
  151. package/src/components/Model/SourcesExplorer.tsx +9 -6
  152. package/src/components/Model/index.ts +3 -0
  153. package/src/components/Model/useModelData.ts +6 -3
  154. package/src/components/Notebook/Notebook.spec.tsx +88 -0
  155. package/src/components/Notebook/Notebook.tsx +476 -339
  156. package/src/components/Notebook/NotebookCell.tsx +264 -25
  157. package/src/components/Notebook/index.ts +3 -0
  158. package/src/components/Notebook/runPlan.spec.ts +155 -0
  159. package/src/components/Notebook/runPlan.ts +67 -0
  160. package/src/components/Notebook/types.ts +14 -0
  161. package/src/components/Package/ContentTypeIcon.spec.ts +91 -0
  162. package/src/components/Package/ContentTypeIcon.tsx +177 -0
  163. package/src/components/Package/FileTreeView.tsx +3 -0
  164. package/src/components/Package/Models.tsx +7 -4
  165. package/src/components/Package/Package.spec.tsx +113 -0
  166. package/src/components/Package/Package.tsx +692 -59
  167. package/src/components/Package/index.ts +3 -0
  168. package/src/components/QueryResult/QueryResult.tsx +17 -8
  169. package/src/components/QueryResult/index.ts +3 -0
  170. package/src/components/RenderedResult/RenderedResult.tsx +725 -67
  171. package/src/components/RenderedResult/ResultContainer.tsx +71 -2
  172. package/src/components/RenderedResult/index.ts +3 -0
  173. package/src/components/RenderedResult/renderLogs.spec.ts +58 -0
  174. package/src/components/RenderedResult/renderLogs.ts +43 -0
  175. package/src/components/ResultsDialog.tsx +13 -1
  176. package/src/components/ServerProvider.tsx +175 -51
  177. package/src/components/Workbook/BrowserWorkbookStorage.ts +3 -0
  178. package/src/components/Workbook/EditableMalloyCell.tsx +3 -0
  179. package/src/components/Workbook/ModelPicker.tsx +7 -4
  180. package/src/components/Workbook/MutableCell.tsx +10 -5
  181. package/src/components/Workbook/Workbook.tsx +8 -5
  182. package/src/components/Workbook/WorkbookList.tsx +3 -0
  183. package/src/components/Workbook/WorkbookManager.ts +3 -0
  184. package/src/components/Workbook/WorkbookStorage.ts +3 -0
  185. package/src/components/Workbook/WorkbookStorageProvider.tsx +3 -0
  186. package/src/components/Workbook/index.ts +3 -0
  187. package/src/components/click_helper.ts +17 -1
  188. package/src/components/drill/index.ts +28 -0
  189. package/src/components/drill/markDrillableCells.dom.spec.ts +313 -0
  190. package/src/components/drill/markDrillableCells.spec.ts +109 -0
  191. package/src/components/drill/markDrillableCells.ts +314 -0
  192. package/src/components/drill/resolveDrill.spec.ts +449 -0
  193. package/src/components/drill/resolveDrill.ts +375 -0
  194. package/src/components/drill/useDrill.tsx +203 -0
  195. package/src/components/filter/DimensionFilter.tsx +3 -0
  196. package/src/components/filter/index.ts +3 -0
  197. package/src/components/filter/utils.ts +16 -5
  198. package/src/components/given/GivenInput.spec.tsx +689 -0
  199. package/src/components/given/GivenInput.tsx +801 -0
  200. package/src/components/given/GivensPanel.spec.tsx +175 -0
  201. package/src/components/given/GivensPanel.tsx +195 -0
  202. package/src/components/given/filterValue.spec.ts +364 -0
  203. package/src/components/given/filterValue.ts +207 -0
  204. package/src/components/given/index.ts +9 -0
  205. package/src/components/given/paramCodec.spec.ts +857 -0
  206. package/src/components/given/paramCodec.ts +483 -0
  207. package/src/components/given/utils.spec.ts +60 -0
  208. package/src/components/given/utils.ts +79 -0
  209. package/src/components/highlighter.ts +22 -5
  210. package/src/components/index.ts +10 -2
  211. package/src/components/styles.ts +82 -33
  212. package/src/constants/docLinks.spec.ts +54 -0
  213. package/src/constants/docLinks.ts +46 -0
  214. package/src/hooks/givenValue.ts +13 -0
  215. package/src/hooks/index.ts +13 -0
  216. package/src/hooks/useDimensionFilters.ts +4 -7
  217. package/src/hooks/useDimensionFiltersFromSpec.ts +8 -5
  218. package/src/hooks/useDimensionFiltersQuery.ts +10 -13
  219. package/src/hooks/useDimensionalFilterRangeData.ts +11 -14
  220. package/src/hooks/useGivensState.spec.ts +449 -0
  221. package/src/hooks/useGivensState.ts +340 -0
  222. package/src/hooks/useModelGivens.ts +29 -0
  223. package/src/hooks/useQueryWithApiError.ts +3 -0
  224. package/src/hooks/useRawQueryData.ts +6 -3
  225. package/src/hooks/useSuggestOptions.dom.spec.ts +91 -0
  226. package/src/hooks/useSuggestOptions.spec.ts +112 -0
  227. package/src/hooks/useSuggestOptions.ts +268 -0
  228. package/src/index.ts +10 -1
  229. package/src/react-app-env.d.ts +3 -0
  230. package/src/theme/ThemeContext.tsx +86 -0
  231. package/src/theme/buildMalloyExplicitTheme.ts +61 -0
  232. package/src/theme/buildTableCssVars.spec.ts +86 -0
  233. package/src/theme/buildTableCssVars.ts +98 -0
  234. package/src/theme/buildVegaThemeOverride.spec.ts +56 -0
  235. package/src/theme/buildVegaThemeOverride.ts +47 -0
  236. package/src/theme/defaults.ts +78 -0
  237. package/src/theme/index.ts +11 -0
  238. package/src/theme/keys.ts +32 -0
  239. package/src/theme/readChartAnnotations.spec.ts +58 -0
  240. package/src/theme/readChartAnnotations.ts +69 -0
  241. package/src/theme/resolveTheme.spec.ts +160 -0
  242. package/src/theme/resolveTheme.ts +121 -0
  243. package/src/theme/types.ts +79 -0
  244. package/src/utils/dataAppEmbed.spec.ts +63 -0
  245. package/src/utils/dataAppEmbed.ts +84 -0
  246. package/src/utils/formatting.spec.ts +25 -21
  247. package/src/utils/formatting.ts +11 -7
  248. package/src/utils/malloyString.spec.ts +24 -0
  249. package/src/utils/malloyString.ts +12 -0
  250. package/src/utils/parsing.spec.ts +26 -19
  251. package/src/utils/parsing.ts +11 -6
  252. package/src/utils/queryClient.ts +17 -0
  253. package/test/README.md +185 -0
  254. package/test/serverProvider.tsx +72 -0
  255. package/test/setup.ts +29 -0
  256. package/tsconfig.json +12 -1
  257. package/tsconfig.spec.json +22 -0
  258. package/vite.config.ts +3 -0
  259. package/dist/ServerProvider-lOQXDlqB.cjs.js +0 -1
  260. package/dist/ServerProvider-on-8FH5Z.es.js +0 -3060
  261. package/dist/components/Home/AddProjectDialog.d.ts +0 -1
  262. package/dist/components/Home/DeleteProjectDialog.d.ts +0 -5
  263. package/dist/components/Home/EditProjectDialog.d.ts +0 -7
  264. package/dist/components/Package/Config.d.ts +0 -5
  265. package/dist/components/Package/Databases.d.ts +0 -5
  266. package/dist/components/Package/Notebooks.d.ts +0 -6
  267. package/dist/components/Project/Project.d.ts +0 -6
  268. package/dist/components/Project/index.d.ts +0 -2
  269. package/dist/index-BOLBP6_i.cjs.js +0 -233
  270. package/src/components/Package/Config.tsx +0 -97
  271. package/src/components/Package/Connections.tsx +0 -373
  272. package/src/components/Package/Databases.tsx +0 -228
  273. package/src/components/Package/Notebooks.tsx +0 -77
  274. package/src/components/Project/AddPackageDialog.tsx +0 -159
  275. package/src/components/Project/Packages.tsx +0 -191
  276. package/src/components/Project/Project.tsx +0 -52
  277. package/src/components/Project/index.ts +0 -2
  278. /package/dist/components/{Project → Environment}/About.d.ts +0 -0
  279. /package/dist/components/{Project → Environment}/AddPackageDialog.d.ts +0 -0
  280. /package/dist/components/{Project → Environment}/ConnectionExplorer.d.ts +0 -0
  281. /package/dist/components/{Package → Environment}/Connections.d.ts +0 -0
  282. /package/dist/components/{Project → Environment}/DeletePackageDialog.d.ts +0 -0
  283. /package/dist/components/{Project → Environment}/EditPackageDialog.d.ts +0 -0
  284. /package/dist/components/{Project → Environment}/Packages.d.ts +0 -0
@@ -0,0 +1,56 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { buildVegaThemeOverride } from "./buildVegaThemeOverride";
6
+ import { resolveTheme } from "./resolveTheme";
7
+
8
+ describe("buildVegaThemeOverride", () => {
9
+ it("populates range.category from the resolved series", () => {
10
+ const t = resolveTheme(
11
+ [{ palette: { series: ["#ff0080", "#ff6b00"] } }],
12
+ "light",
13
+ );
14
+ const config = buildVegaThemeOverride(t)("bar");
15
+ const ranges = (config as { range: { category: string[] } }).range;
16
+ expect(ranges.category).toEqual(["#ff0080", "#ff6b00"]);
17
+ });
18
+
19
+ it("sets background to the resolved theme background", () => {
20
+ const t = resolveTheme(
21
+ [{ palette: { background: { dark: "#001122" } } }],
22
+ "dark",
23
+ );
24
+ const config = buildVegaThemeOverride(t)("line");
25
+ expect((config as { background: string }).background).toBe("#001122");
26
+ });
27
+
28
+ it("propagates the font family to axis/legend/title text marks", () => {
29
+ const t = resolveTheme([{ font: { family: "Roboto Mono" } }], "light");
30
+ const cfg = buildVegaThemeOverride(t)("bar") as {
31
+ font: string;
32
+ axis: { labelFont: string; titleFont: string };
33
+ legend: { labelFont: string; titleFont: string };
34
+ title: { font: string };
35
+ };
36
+ expect(cfg.font).toBe("Roboto Mono");
37
+ expect(cfg.axis.labelFont).toBe("Roboto Mono");
38
+ expect(cfg.legend.titleFont).toBe("Roboto Mono");
39
+ expect(cfg.title.font).toBe("Roboto Mono");
40
+ });
41
+
42
+ it("uses the resolved foreground + axisFaint values (no mode branch)", () => {
43
+ const dark = resolveTheme([], "dark");
44
+ const cfg = buildVegaThemeOverride(dark)("bar") as {
45
+ axis: { labelColor: string; gridColor: string };
46
+ };
47
+ expect(cfg.axis.labelColor).toBe(dark.foreground);
48
+ expect(cfg.axis.gridColor).toBe(dark.axisFaint);
49
+ });
50
+
51
+ it("returns the same config across chart types in v1", () => {
52
+ const t = resolveTheme([], "light");
53
+ const cb = buildVegaThemeOverride(t);
54
+ expect(cb("bar")).toBe(cb("line"));
55
+ });
56
+ });
@@ -0,0 +1,47 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import type { ResolvedTheme } from "./types";
5
+
6
+ /**
7
+ * Produce a `vegaConfigOverride` callback for `new MalloyRenderer({...})`.
8
+ * The renderer invokes the callback once per chart type and merges the
9
+ * returned object into the Vega spec's config. We set the category
10
+ * colour scale, the global font, the page background, and foreground /
11
+ * faint colours so chart text and axis chrome inherit the active mode.
12
+ *
13
+ * Foreground and axis-faint values come from {@link ResolvedTheme}
14
+ * (computed once in `resolveTheme`), so this builder no longer branches
15
+ * on mode itself.
16
+ *
17
+ * The same config is returned for every chart type today. The
18
+ * parameter is reserved for future per-chart-type tweaks.
19
+ */
20
+ export function buildVegaThemeOverride(theme: ResolvedTheme) {
21
+ const { foreground, axisFaint, font } = theme;
22
+
23
+ const config: Record<string, unknown> = {
24
+ background: theme.background,
25
+ font: font.family,
26
+ title: { color: foreground, font: font.family },
27
+ axis: {
28
+ labelColor: foreground,
29
+ titleColor: foreground,
30
+ domainColor: axisFaint,
31
+ tickColor: axisFaint,
32
+ gridColor: axisFaint,
33
+ labelFont: font.family,
34
+ titleFont: font.family,
35
+ },
36
+ legend: {
37
+ labelColor: foreground,
38
+ titleColor: foreground,
39
+ labelFont: font.family,
40
+ titleFont: font.family,
41
+ },
42
+ header: { labelColor: foreground, titleColor: foreground },
43
+ range: { category: theme.series },
44
+ };
45
+
46
+ return (_chartType: string) => config;
47
+ }
@@ -0,0 +1,78 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { MALLOY_BRAND } from "../components/styles";
5
+ import type { Theme } from "./types";
6
+
7
+ const DEFAULT_SERIES = [
8
+ MALLOY_BRAND.teal,
9
+ MALLOY_BRAND.orange,
10
+ MALLOY_BRAND.darkBlue,
11
+ "#66cedc",
12
+ "#ec72b8",
13
+ "#f9c85b",
14
+ "#aacd85",
15
+ "#b87ced",
16
+ ];
17
+
18
+ const DEFAULT_FONT_FAMILY =
19
+ "Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
20
+
21
+ /**
22
+ * Built-in theme used when nothing has been configured. Series palette
23
+ * and font are shared across modes; only colours that should genuinely
24
+ * change in dark mode (backgrounds, foregrounds) are per-mode.
25
+ */
26
+ export const DEFAULT_THEME: Required<Theme> = {
27
+ defaultMode: "light",
28
+ allowUserToggle: true,
29
+ palette: {
30
+ series: DEFAULT_SERIES,
31
+ background: {
32
+ light: "#ffffff",
33
+ // Slate to match the Publisher app's sidebar surface so
34
+ // rendered charts sit on the same elevation as the chrome
35
+ // around them.
36
+ dark: "#1e293b",
37
+ },
38
+ tableHeader: {
39
+ light: "#5d626b",
40
+ dark: "#cbd5e1",
41
+ },
42
+ // Background of the table header row, independent of the
43
+ // tile (dashboard tile container) so the operator can theme
44
+ // the header band on its own.
45
+ tableHeaderBackground: {
46
+ light: "#f5fafc",
47
+ dark: "#1e293b",
48
+ },
49
+ tableBody: {
50
+ light: "#727883",
51
+ dark: "#e2e8f0",
52
+ },
53
+ // The padded container that wraps each chart / table in a
54
+ // dashboard. Light mode: a faint tint so tiles read as recessed
55
+ // cards on the page; dark mode: page-outer slate.
56
+ tile: {
57
+ light: "#f5fafc",
58
+ dark: "#0f172a",
59
+ },
60
+ tileTitle: {
61
+ light: "#5d626b",
62
+ dark: "#94a3b8",
63
+ },
64
+ // Saturated end of the choropleth / heatmap gradient. The
65
+ // renderer pairs this with a near-neutral low end. Defaults
66
+ // match the first series colour (teal) so unbranded installs
67
+ // get a brand-coherent gradient instead of the renderer's
68
+ // hardcoded blue ramp.
69
+ mapColor: {
70
+ light: MALLOY_BRAND.teal,
71
+ dark: MALLOY_BRAND.teal,
72
+ },
73
+ },
74
+ font: {
75
+ family: DEFAULT_FONT_FAMILY,
76
+ size: 12,
77
+ },
78
+ };
@@ -0,0 +1,11 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ export { buildMalloyExplicitTheme } from "./buildMalloyExplicitTheme";
5
+ export { buildTableCssVars } from "./buildTableCssVars";
6
+ export { buildVegaThemeOverride } from "./buildVegaThemeOverride";
7
+ export { DEFAULT_THEME } from "./defaults";
8
+ export { readChartAnnotations } from "./readChartAnnotations";
9
+ export { resolveMode, resolveTheme } from "./resolveTheme";
10
+ export { ThemeProvider, usePublisherTheme } from "./ThemeContext";
11
+ export type { ResolvedTheme, Theme, ThemeMode } from "./types";
@@ -0,0 +1,32 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * The set of palette colour keys that have separate light and dark
6
+ * variants. This is the SDK-side canonical list, consumed by the
7
+ * annotation reader (readChartAnnotations) and the theme resolver
8
+ * (resolveTheme). The server keeps its own copy in
9
+ * packages/server/src/config.ts: the two packages are intentionally
10
+ * decoupled (neither imports the other; their only shared contract is
11
+ * api-doc.yaml, from which the server generates its Theme type), so the
12
+ * list is hand-duplicated. A server-side parity test
13
+ * (theme_key_parity.spec.ts) fails if this list, the server copy, or the
14
+ * api-doc Theme.palette schema drift apart. Adding a new per-mode colour
15
+ * means updating all three.
16
+ *
17
+ * Non-per-mode fields (series palette, font.family, font.size,
18
+ * defaultMode, allowUserToggle) are intentionally absent. Operators
19
+ * picked colours that change between modes; brand identity (series,
20
+ * fonts) stays consistent across modes.
21
+ */
22
+ export const PER_MODE_COLOR_KEYS = [
23
+ "background",
24
+ "tableHeader",
25
+ "tableHeaderBackground",
26
+ "tableBody",
27
+ "tile",
28
+ "tileTitle",
29
+ "mapColor",
30
+ ] as const;
31
+
32
+ export type PerModeColorKey = (typeof PER_MODE_COLOR_KEYS)[number];
@@ -0,0 +1,58 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { parseAnnotation } from "@malloydata/malloy-tag";
5
+ import { describe, expect, it } from "bun:test";
6
+ import { readChartAnnotations } from "./readChartAnnotations";
7
+
8
+ function parse(lines: string[]) {
9
+ return parseAnnotation(lines).tag;
10
+ }
11
+
12
+ describe("readChartAnnotations", () => {
13
+ it("returns undefined when no theme annotation is present", () => {
14
+ const tag = parse(["# doc = 'just a note'"]);
15
+ expect(readChartAnnotations(tag)).toBeUndefined();
16
+ });
17
+
18
+ it("extracts a series palette (shared across modes)", () => {
19
+ const tag = parse([
20
+ '# theme.palette.series = ["#ff0080", "#ff6b00", "#ffd000"]',
21
+ ]);
22
+ const t = readChartAnnotations(tag);
23
+ expect(t?.palette?.series).toEqual(["#ff0080", "#ff6b00", "#ffd000"]);
24
+ });
25
+
26
+ it("extracts font family and size (shared across modes)", () => {
27
+ const tag = parse([
28
+ '# theme.font.family = "Roboto"',
29
+ "# theme.font.size = 13",
30
+ ]);
31
+ const t = readChartAnnotations(tag);
32
+ expect(t?.font?.family).toBe("Roboto");
33
+ expect(t?.font?.size).toBe(13);
34
+ });
35
+
36
+ it("extracts per-mode background and tableHeader overrides", () => {
37
+ const tag = parse([
38
+ '# theme.palette.background.light = "#fafafa"',
39
+ '# theme.palette.background.dark = "#111"',
40
+ '# theme.palette.tableHeader.dark = "#94a3b8"',
41
+ ]);
42
+ const t = readChartAnnotations(tag);
43
+ expect(t?.palette?.background).toEqual({
44
+ light: "#fafafa",
45
+ dark: "#111",
46
+ });
47
+ expect(t?.palette?.tableHeader).toEqual({ dark: "#94a3b8" });
48
+ });
49
+
50
+ it("ignores theme keys with the wrong type without throwing", () => {
51
+ const tag = parse([
52
+ "# theme.palette.series = 42",
53
+ "# theme.font.size = 'not a number'",
54
+ ]);
55
+ const t = readChartAnnotations(tag);
56
+ expect(t).toBeUndefined();
57
+ });
58
+ });
@@ -0,0 +1,69 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import type { Tag } from "@malloydata/malloy-tag";
5
+ import { PER_MODE_COLOR_KEYS } from "./keys";
6
+ import type { Theme } from "./types";
7
+
8
+ /**
9
+ * Read a `theme.*` annotation block out of a parsed Malloy {@link Tag}
10
+ * and turn it into a partial {@link Theme} suitable for the cascade.
11
+ * Returns `undefined` if the tag has no `theme` namespace.
12
+ *
13
+ * Recognised annotation forms (all optional, all sit under `theme`):
14
+ *
15
+ * # theme.palette.series = ["#ff0080", "#ff6b00"]
16
+ * # theme.palette.background.light = "#fff"
17
+ * # theme.palette.background.dark = "#000"
18
+ * # theme.palette.tableHeader.light = "#666"
19
+ * # theme.palette.tableHeader.dark = "#aaa"
20
+ * # theme.font.family = "Roboto, sans-serif"
21
+ * # theme.font.size = 13
22
+ *
23
+ * Series and font are shared across modes; only the seven
24
+ * {@link PER_MODE_COLOR_KEYS} accept light/dark variants. Annotations
25
+ * with the wrong type are silently ignored. The goal is "worst-case a
26
+ * typo means no styling", not "a typo crashes the renderer."
27
+ */
28
+ export function readChartAnnotations(tag: Tag | undefined): Theme | undefined {
29
+ if (!tag) return undefined;
30
+ const theme = tag.tag("theme");
31
+ if (!theme) return undefined;
32
+
33
+ const out: Theme = {};
34
+
35
+ const palette = theme.tag("palette");
36
+ if (palette) {
37
+ const p: NonNullable<Theme["palette"]> = {};
38
+
39
+ const series = palette.textArray("series");
40
+ if (series && series.length > 0) p.series = series;
41
+
42
+ for (const key of PER_MODE_COLOR_KEYS) {
43
+ const sub = palette.tag(key);
44
+ if (!sub) continue;
45
+ const v: { light?: string; dark?: string } = {};
46
+ const light = sub.text("light");
47
+ const dark = sub.text("dark");
48
+ if (light) v.light = light;
49
+ if (dark) v.dark = dark;
50
+ if (Object.keys(v).length > 0) {
51
+ (p as Record<string, unknown>)[key] = v;
52
+ }
53
+ }
54
+
55
+ if (Object.keys(p).length > 0) out.palette = p;
56
+ }
57
+
58
+ const font = theme.tag("font");
59
+ if (font) {
60
+ const f: NonNullable<Theme["font"]> = {};
61
+ const family = font.text("family");
62
+ if (family) f.family = family;
63
+ const size = font.numeric("size");
64
+ if (typeof size === "number" && Number.isFinite(size)) f.size = size;
65
+ if (Object.keys(f).length > 0) out.font = f;
66
+ }
67
+
68
+ return Object.keys(out).length > 0 ? out : undefined;
69
+ }
@@ -0,0 +1,160 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { resolveMode, resolveTheme } from "./resolveTheme";
6
+ import type { Theme } from "./types";
7
+
8
+ describe("resolveTheme cascade", () => {
9
+ it("falls back to defaults when no layers are provided", () => {
10
+ const t = resolveTheme([], "light");
11
+ expect(t.series.length).toBeGreaterThan(0);
12
+ expect(t.background).toBe("#ffffff");
13
+ expect(t.font.family).toContain("Inter");
14
+ expect(t.font.size).toBe(12);
15
+ });
16
+
17
+ it("applies the instance layer over defaults", () => {
18
+ const instance: Theme = {
19
+ palette: { series: ["#aaa", "#bbb"] },
20
+ font: { family: "Roboto, sans-serif" },
21
+ };
22
+ const t = resolveTheme([instance], "light");
23
+ expect(t.series).toEqual(["#aaa", "#bbb"]);
24
+ expect(t.font.family).toBe("Roboto, sans-serif");
25
+ });
26
+
27
+ it("environment layer overrides instance per-key", () => {
28
+ const instance: Theme = {
29
+ palette: { series: ["#aaa"] },
30
+ font: { family: "Roboto" },
31
+ };
32
+ const env: Theme = {
33
+ palette: { series: ["#cc0000"] },
34
+ };
35
+ const t = resolveTheme([instance, env], "light");
36
+ expect(t.series).toEqual(["#cc0000"]);
37
+ expect(t.font.family).toBe("Roboto");
38
+ });
39
+
40
+ it("per-mode colour keys merge per-mode across layers", () => {
41
+ const instance: Theme = {
42
+ palette: {
43
+ background: { light: "#f0f0f0", dark: "#000" },
44
+ tableHeader: { light: "#111" },
45
+ },
46
+ };
47
+ const env: Theme = {
48
+ palette: { background: { dark: "#222" } },
49
+ };
50
+ const lightT = resolveTheme([instance, env], "light");
51
+ const darkT = resolveTheme([instance, env], "dark");
52
+ expect(lightT.background).toBe("#f0f0f0");
53
+ expect(darkT.background).toBe("#222");
54
+ expect(lightT.tableHeader).toBe("#111");
55
+ });
56
+
57
+ it("series and font are shared across modes", () => {
58
+ const layer: Theme = {
59
+ palette: { series: ["#aaa", "#bbb"] },
60
+ font: { family: "Roboto", size: 16 },
61
+ };
62
+ const light = resolveTheme([layer], "light");
63
+ const dark = resolveTheme([layer], "dark");
64
+ expect(light.series).toEqual(dark.series);
65
+ expect(light.font.family).toBe(dark.font.family);
66
+ expect(light.font.size).toBe(dark.font.size);
67
+ });
68
+
69
+ it("an explicit empty series array clears the cascade", () => {
70
+ const t = resolveTheme([{ palette: { series: [] } }], "light");
71
+ expect(t.series).toEqual([]);
72
+ });
73
+
74
+ it("undefined layers are skipped without throwing", () => {
75
+ const t = resolveTheme(
76
+ [undefined, { palette: { series: ["#z"] } }, undefined],
77
+ "light",
78
+ );
79
+ expect(t.series).toEqual(["#z"]);
80
+ });
81
+
82
+ it("exposes derived mode values (border, foreground, axisFaint)", () => {
83
+ const light = resolveTheme([], "light");
84
+ const dark = resolveTheme([], "dark");
85
+ expect(light.border).toBe("1px solid #e5e7eb");
86
+ expect(dark.border).toBe("1px solid #334155");
87
+ expect(light.foreground).toBe("#1f2937");
88
+ expect(dark.foreground).toBe("#e2e8f0");
89
+ expect(light.axisFaint).toBe("#d1d5db");
90
+ expect(dark.axisFaint).toBe("#475569");
91
+ expect(light.valueColor).toBe("#1f2937");
92
+ expect(dark.valueColor).toBe("#f1f5f9");
93
+ });
94
+
95
+ it("drillLink is a link colour per mode, not a series colour", () => {
96
+ // A drillable cell has to read as a link against whatever the operator
97
+ // picked for the data, so this comes from the mode rather than the palette
98
+ //, and it lightens in dark mode to stay legible on the slate panel.
99
+ expect(resolveTheme([], "light").drillLink).toBe("#2563eb");
100
+ expect(resolveTheme([], "dark").drillLink).toBe("#60a5fa");
101
+ const branded = resolveTheme(
102
+ [{ palette: { series: ["#ff00aa", "#111111"] } }],
103
+ "light",
104
+ );
105
+ expect(branded.drillLink).toBe("#2563eb");
106
+ });
107
+
108
+ it("dashboardRoot is mode-keyed and immune to operator background overrides", () => {
109
+ // Light keeps white (no regression on existing installs).
110
+ expect(resolveTheme([], "light").dashboardRoot).toBe("#ffffff");
111
+ // Dark paints slate so the panel doesn't read as a bright box.
112
+ expect(resolveTheme([], "dark").dashboardRoot).toBe("#1e293b");
113
+ // An operator picking a bold accent for `background` (the chart
114
+ // canvas) must NOT bleed into the surrounding panel.
115
+ const t = resolveTheme(
116
+ [{ palette: { background: { dark: "#ff8800" } } }],
117
+ "dark",
118
+ );
119
+ expect(t.background).toBe("#ff8800");
120
+ expect(t.dashboardRoot).toBe("#1e293b");
121
+ });
122
+
123
+ it("tableBackground follows the operator's palette.background", () => {
124
+ // Defaults track the per-mode background (white in light, slate
125
+ // in dark) so existing installs see no change.
126
+ expect(resolveTheme([], "light").tableBackground).toBe("#ffffff");
127
+ expect(resolveTheme([], "dark").tableBackground).toBe("#1e293b");
128
+ // An operator accent on palette.background bleeds into the table
129
+ // interior so charts and tables share a single viz surface
130
+ // colour. The dashboard panel between tiles stays neutral —
131
+ // that's dashboardRoot's job.
132
+ const t = resolveTheme(
133
+ [{ palette: { background: { light: "#aacd85" } } }],
134
+ "light",
135
+ );
136
+ expect(t.background).toBe("#aacd85");
137
+ expect(t.tableBackground).toBe("#aacd85");
138
+ expect(t.dashboardRoot).toBe("#ffffff");
139
+ });
140
+ });
141
+
142
+ describe("resolveMode", () => {
143
+ it("user choice wins over default and OS", () => {
144
+ expect(resolveMode("light", "dark", false)).toBe("dark");
145
+ expect(resolveMode("dark", "light", true)).toBe("light");
146
+ });
147
+
148
+ it("auto follows the OS preference", () => {
149
+ expect(resolveMode("auto", undefined, true)).toBe("dark");
150
+ expect(resolveMode("auto", undefined, false)).toBe("light");
151
+ });
152
+
153
+ it("default applies when no user choice is set", () => {
154
+ expect(resolveMode("dark", undefined, false)).toBe("dark");
155
+ });
156
+
157
+ it("falls back to light when nothing is set", () => {
158
+ expect(resolveMode(undefined, undefined, false)).toBe("light");
159
+ });
160
+ });
@@ -0,0 +1,121 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { DEFAULT_THEME } from "./defaults";
5
+ import { PER_MODE_COLOR_KEYS, type PerModeColorKey } from "./keys";
6
+ import type { ResolvedTheme, Theme, ThemeMode } from "./types";
7
+
8
+ /**
9
+ * Collapse the layered theme cascade into a {@link ResolvedTheme} that
10
+ * downstream code can consume without null-checks or mode branches.
11
+ * Layer order is low → high precedence; later layers overwrite earlier
12
+ * ones for the keys they set. Per-mode colour objects merge per-mode
13
+ * (a layer that sets only `palette.tile.dark` doesn't clobber the
14
+ * instance-level `palette.tile.light`).
15
+ *
16
+ * The derived fields on ResolvedTheme (border, pinnedBorder,
17
+ * valueColor, foreground, axisFaint) are computed once here from the
18
+ * active mode so the three builders that consume the theme stop
19
+ * recomputing them with duplicated hex literals.
20
+ */
21
+ export function resolveTheme(
22
+ layers: Array<Theme | undefined>,
23
+ mode: ThemeMode,
24
+ ): ResolvedTheme {
25
+ const defaultPalette = DEFAULT_THEME.palette ?? {};
26
+ const defaultFont = DEFAULT_THEME.font ?? {
27
+ family: "sans-serif",
28
+ size: 12,
29
+ };
30
+
31
+ let series: string[] = [...((defaultPalette.series as string[]) ?? [])];
32
+ let fontFamily: string = defaultFont.family ?? "sans-serif";
33
+ let fontSize: number = defaultFont.size ?? 12;
34
+
35
+ const perMode: Record<PerModeColorKey, { light?: string; dark?: string }> = {
36
+ background: { ...(defaultPalette.background ?? {}) },
37
+ tableHeader: { ...(defaultPalette.tableHeader ?? {}) },
38
+ tableHeaderBackground: {
39
+ ...(defaultPalette.tableHeaderBackground ?? {}),
40
+ },
41
+ tableBody: { ...(defaultPalette.tableBody ?? {}) },
42
+ tile: { ...(defaultPalette.tile ?? {}) },
43
+ tileTitle: { ...(defaultPalette.tileTitle ?? {}) },
44
+ mapColor: { ...(defaultPalette.mapColor ?? {}) },
45
+ };
46
+
47
+ for (const layer of layers) {
48
+ if (!layer) continue;
49
+ if (Array.isArray(layer.palette?.series)) {
50
+ series = [...(layer.palette.series as string[])];
51
+ }
52
+ for (const key of PER_MODE_COLOR_KEYS) {
53
+ const override = layer.palette?.[key];
54
+ if (override) {
55
+ perMode[key] = { ...perMode[key], ...override };
56
+ }
57
+ }
58
+ if (typeof layer.font?.family === "string") {
59
+ fontFamily = layer.font.family;
60
+ }
61
+ if (typeof layer.font?.size === "number") {
62
+ fontSize = layer.font.size;
63
+ }
64
+ }
65
+
66
+ const isDark = mode === "dark";
67
+ const pick = (key: PerModeColorKey): string =>
68
+ perMode[key][mode] ?? (defaultPalette[key]?.[mode] as string);
69
+
70
+ const background = pick("background");
71
+ return {
72
+ mode,
73
+ series,
74
+ font: { family: fontFamily, size: fontSize },
75
+ background,
76
+ tableHeader: pick("tableHeader"),
77
+ tableHeaderBackground: pick("tableHeaderBackground"),
78
+ tableBody: pick("tableBody"),
79
+ tile: pick("tile"),
80
+ tileTitle: pick("tileTitle"),
81
+ mapColor: pick("mapColor"),
82
+ // Table interior follows the operator's chart background so
83
+ // tables and chart canvases share a single "viz surface" colour.
84
+ tableBackground: background,
85
+ // Derived, mode-keyed defaults. Operators don't edit these in
86
+ // v1; they're consistent borders / readable foreground text for
87
+ // each mode. If a user later asks to customise them, expose them
88
+ // on the schema and the editor and replace the literals below.
89
+ border: isDark ? "1px solid #334155" : "1px solid #e5e7eb",
90
+ pinnedBorder: isDark ? "1px solid #475569" : "1px solid #daedf3",
91
+ valueColor: isDark ? "#f1f5f9" : "#1f2937",
92
+ foreground: isDark ? "#e2e8f0" : "#1f2937",
93
+ axisFaint: isDark ? "#475569" : "#d1d5db",
94
+ // Dashboard panel background (area BETWEEN tiles). Light keeps
95
+ // white so the page stays visually unchanged. Dark uses slate so
96
+ // the panel doesn't read as a bright box against the dark page
97
+ // chrome. Intentionally NOT tied to `palette.background`: the
98
+ // panel stays neutral so a bold accent on the chart canvas
99
+ // doesn't bleed into the surrounding chrome.
100
+ dashboardRoot: isDark ? "#1e293b" : "#ffffff",
101
+ // Drill link hover. Light is Malloyyo's own blue, so the same drill reads
102
+ // the same in both; dark lightens it for contrast on the slate panel.
103
+ drillLink: isDark ? "#60a5fa" : "#2563eb",
104
+ };
105
+ }
106
+
107
+ /**
108
+ * Pick the active mode for a viewer given the operator's `defaultMode`,
109
+ * any persisted viewer choice, and a snapshot of the OS dark-mode
110
+ * preference. "auto" is resolved here; callers see only "light" or
111
+ * "dark".
112
+ */
113
+ export function resolveMode(
114
+ defaultMode: Theme["defaultMode"] | undefined,
115
+ userChoice: ThemeMode | "auto" | undefined,
116
+ prefersDark: boolean,
117
+ ): ThemeMode {
118
+ const effective = userChoice ?? defaultMode ?? "light";
119
+ if (effective === "auto") return prefersDark ? "dark" : "light";
120
+ return effective;
121
+ }