@malloy-publisher/sdk 0.9.1 → 0.9.3

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 (410) hide show
  1. package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-DwB0-9Yx.es.js} +219 -210
  2. package/dist/RenderedResult-hKjFEqaN.cjs.js +141 -0
  3. package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-CcSrGaRN.es.js} +1473 -1326
  4. package/dist/ServerProvider-Gbf1YPOP.cjs.js +1 -0
  5. package/dist/builder/index.cjs.js +143 -58
  6. package/dist/builder/index.es.js +12179 -9318
  7. package/dist/builder-entry.d.ts +5 -1
  8. package/dist/client/api.d.ts +247 -56
  9. package/dist/client/configuration.d.ts +1 -1
  10. package/dist/client/index.cjs.js +1 -1
  11. package/dist/client/index.d.ts +1 -1
  12. package/dist/client/index.es.js +94 -88
  13. package/dist/client-entry.d.ts +2 -0
  14. package/dist/components/ApiErrorDisplay.d.ts +11 -0
  15. package/dist/components/AppDialog.d.ts +6 -6
  16. package/dist/components/Dashboard/Dashboard.d.ts +8 -15
  17. package/dist/components/Dashboard/DashboardGrid.d.ts +38 -6
  18. package/dist/components/Dashboard/DashboardTile.d.ts +21 -2
  19. package/dist/components/Dashboard/DashboardView.d.ts +71 -0
  20. package/dist/components/Dashboard/TileCard.d.ts +30 -5
  21. package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
  22. package/dist/components/Dashboard/dropValueUrlTags.d.ts +6 -0
  23. package/dist/components/Dashboard/index.d.ts +5 -1
  24. package/dist/components/Dashboard/telemetry.d.ts +16 -3
  25. package/dist/components/Dashboard/textSource.d.ts +19 -0
  26. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +15 -9
  27. package/dist/components/DashboardBuilder/BuilderDialogs.d.ts +25 -0
  28. package/dist/components/DashboardBuilder/BuilderGrid.d.ts +31 -0
  29. package/dist/components/DashboardBuilder/BuilderHeader.d.ts +17 -0
  30. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +23 -15
  31. package/dist/components/DashboardBuilder/ChartPicker.d.ts +31 -0
  32. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +56 -21
  33. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +44 -5
  34. package/dist/components/DashboardBuilder/EditorSurface.d.ts +33 -0
  35. package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
  36. package/dist/components/DashboardBuilder/FilterStrip.d.ts +8 -4
  37. package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
  38. package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
  39. package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
  40. package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
  41. package/dist/components/DashboardBuilder/TextTileBody.d.ts +10 -0
  42. package/dist/components/DashboardBuilder/TileFrame.d.ts +51 -12
  43. package/dist/components/DashboardBuilder/TileMenu.d.ts +12 -6
  44. package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
  45. package/dist/components/DashboardBuilder/builderReport.d.ts +13 -0
  46. package/dist/components/DashboardBuilder/catalog.d.ts +4 -18
  47. package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
  48. package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
  49. package/dist/components/DashboardBuilder/controls.d.ts +2 -2
  50. package/dist/components/DashboardBuilder/document.d.ts +42 -26
  51. package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
  52. package/dist/components/DashboardBuilder/imports.d.ts +19 -0
  53. package/dist/components/DashboardBuilder/inlineEdit.d.ts +18 -0
  54. package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
  55. package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
  56. package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
  57. package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
  58. package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
  59. package/dist/components/DashboardBuilder/preview.d.ts +24 -4
  60. package/dist/components/DashboardBuilder/readDocument.d.ts +6 -1
  61. package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
  62. package/dist/components/DashboardBuilder/sortable.d.ts +16 -0
  63. package/dist/components/DashboardBuilder/spliceDocument.d.ts +15 -13
  64. package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
  65. package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
  66. package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
  67. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
  68. package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
  69. package/dist/components/DashboardBuilder/testing/resize.d.ts +7 -0
  70. package/dist/components/DashboardBuilder/tileDisplayTitle.d.ts +7 -0
  71. package/dist/components/DashboardBuilder/useBuilderSelection.d.ts +53 -0
  72. package/dist/components/DashboardBuilder/useBuilderSession.d.ts +86 -0
  73. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
  74. package/dist/components/DashboardBuilder/useControlBindings.d.ts +30 -0
  75. package/dist/components/DashboardBuilder/useConversionConfirm.d.ts +20 -0
  76. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +19 -55
  77. package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
  78. package/dist/components/DashboardBuilder/useDraft.d.ts +3 -1
  79. package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
  80. package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
  81. package/dist/components/DashboardBuilder/useHostCopy.d.ts +26 -0
  82. package/dist/components/DashboardBuilder/useOpenDraftCommit.d.ts +17 -0
  83. package/dist/components/DashboardBuilder/useOpenedDocument.d.ts +71 -0
  84. package/dist/components/DashboardBuilder/useSaveChannel.d.ts +50 -0
  85. package/dist/components/DashboardBuilder/useTileEditing.d.ts +33 -0
  86. package/dist/components/DashboardBuilder/useTileResize.d.ts +6 -3
  87. package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
  88. package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
  89. package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
  90. package/dist/components/DocumentCreate/events.d.ts +10 -0
  91. package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
  92. package/dist/components/DocumentCreate/guards.d.ts +12 -0
  93. package/dist/components/DocumentCreate/index.d.ts +6 -0
  94. package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
  95. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
  96. package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
  97. package/dist/components/Loading.d.ts +13 -0
  98. package/dist/components/NarrowEditGate.d.ts +8 -0
  99. package/dist/components/Notebook/Notebook.d.ts +1 -1
  100. package/dist/components/Notebook/NotebookCell.d.ts +1 -5
  101. package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
  102. package/dist/components/Package/Package.d.ts +17 -1
  103. package/dist/components/Package/documentLocation.d.ts +28 -0
  104. package/dist/components/Package/index.d.ts +5 -1
  105. package/dist/components/Package/useDocumentLocation.d.ts +12 -0
  106. package/dist/components/PackageSection.d.ts +2 -2
  107. package/dist/components/Prose.d.ts +1 -1
  108. package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
  109. package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
  110. package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
  111. package/dist/components/RenderedResult/loadRenderer.d.ts +7 -0
  112. package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
  113. package/dist/components/ServerProvider.d.ts +2 -1
  114. package/dist/components/UnsavedChangesDialog.d.ts +9 -0
  115. package/dist/components/given/GivensPanel.d.ts +2 -2
  116. package/dist/components/given/paramCodec.d.ts +8 -1
  117. package/dist/components/index.d.ts +3 -2
  118. package/dist/components/styles.d.ts +4 -4
  119. package/dist/hooks/givenValue.d.ts +6 -0
  120. package/dist/hooks/index.d.ts +2 -0
  121. package/dist/hooks/useCompiledDocument.d.ts +23 -0
  122. package/dist/hooks/useDocumentControls.d.ts +6 -1
  123. package/dist/hooks/useNarrowScreen.d.ts +4 -0
  124. package/dist/hooks/useNearViewport.d.ts +16 -0
  125. package/dist/hooks/useQueryResult.d.ts +2 -0
  126. package/dist/hooks/useQueryWithApiError.d.ts +7 -2
  127. package/dist/hooks/useSettled.d.ts +14 -0
  128. package/dist/hooks/useSuggestOptions.d.ts +9 -2
  129. package/dist/index.cjs.js +23 -24
  130. package/dist/index.es.js +9041 -7002
  131. package/dist/text/index.cjs.js +1 -0
  132. package/dist/text/index.d.ts +2 -0
  133. package/dist/text/index.es.js +6 -0
  134. package/dist/text-entry-BJwltZiy.cjs.js +7 -0
  135. package/dist/text-entry-CA0LZ1xL.es.js +196 -0
  136. package/dist/text-entry.d.ts +2 -0
  137. package/dist/theme/accent.d.ts +29 -0
  138. package/dist/theme/buildVegaThemeOverride.d.ts +3 -3
  139. package/dist/theme/index.d.ts +3 -0
  140. package/dist/theme/keys.d.ts +1 -1
  141. package/dist/theme/motion.d.ts +31 -0
  142. package/dist/theme/readChartAnnotations.d.ts +1 -1
  143. package/dist/theme/resolveTheme.d.ts +4 -4
  144. package/dist/theme/types.d.ts +33 -5
  145. package/dist/{Dashboard-H1kJlDFo.es.js → useCompiledDocument-BU6d8FPp.es.js} +17904 -19057
  146. package/dist/useCompiledDocument-pOg2W-Yt.cjs.js +142 -0
  147. package/dist/utils/clock.d.ts +2 -0
  148. package/dist/utils/malloyText.d.ts +104 -0
  149. package/package.json +20 -11
  150. package/src/builder-entry.ts +36 -0
  151. package/src/client-entry.ts +8 -0
  152. package/src/clientEntry.spec.ts +17 -0
  153. package/src/components/ApiErrorDisplay.tsx +37 -18
  154. package/src/components/AppDialog.tsx +8 -7
  155. package/src/components/Dashboard/Dashboard.spec.tsx +3 -32
  156. package/src/components/Dashboard/Dashboard.tsx +29 -280
  157. package/src/components/Dashboard/DashboardGrid.tsx +87 -8
  158. package/src/components/Dashboard/DashboardTile.spec.tsx +121 -2
  159. package/src/components/Dashboard/DashboardTile.tsx +121 -30
  160. package/src/components/Dashboard/DashboardView.spec.tsx +368 -0
  161. package/src/components/Dashboard/DashboardView.tsx +428 -0
  162. package/src/components/Dashboard/RowsDialog.tsx +4 -3
  163. package/src/components/Dashboard/TileCard.tsx +60 -11
  164. package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
  165. package/src/components/Dashboard/TileFilterTag.tsx +78 -0
  166. package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
  167. package/src/components/Dashboard/dropValueUrlTags.spec.ts +177 -0
  168. package/src/components/Dashboard/dropValueUrlTags.ts +108 -0
  169. package/src/components/Dashboard/index.ts +13 -1
  170. package/src/components/Dashboard/telemetry.ts +17 -5
  171. package/src/components/Dashboard/textSource.spec.ts +36 -0
  172. package/src/components/Dashboard/textSource.ts +39 -0
  173. package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
  174. package/src/components/DashboardBuilder/AddTileDialog.tsx +124 -138
  175. package/src/components/DashboardBuilder/BuilderDialogs.tsx +162 -0
  176. package/src/components/DashboardBuilder/BuilderGrid.tsx +245 -0
  177. package/src/components/DashboardBuilder/BuilderHeader.tsx +107 -0
  178. package/src/components/DashboardBuilder/BuilderToolbar.tsx +111 -80
  179. package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
  180. package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
  181. package/src/components/DashboardBuilder/ChartPicker.tsx +156 -0
  182. package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
  183. package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +183 -0
  184. package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +373 -0
  185. package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +310 -0
  186. package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +105 -0
  187. package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +117 -0
  188. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +146 -108
  189. package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +179 -0
  190. package/src/components/DashboardBuilder/DashboardBuilder.tsx +330 -512
  191. package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +55 -25
  192. package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +142 -0
  193. package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
  194. package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +310 -0
  195. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +39 -13
  196. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +9 -26
  197. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +102 -25
  198. package/src/components/DashboardBuilder/DashboardEditor.textSource.spec.tsx +317 -0
  199. package/src/components/DashboardBuilder/DashboardEditor.tsx +252 -780
  200. package/src/components/DashboardBuilder/DrillDialog.tsx +2 -2
  201. package/src/components/DashboardBuilder/EditorSurface.tsx +471 -0
  202. package/src/components/DashboardBuilder/FilterDialog.tsx +23 -11
  203. package/src/components/DashboardBuilder/FilterStrip.tsx +130 -70
  204. package/src/components/DashboardBuilder/InlineMarkdown.tsx +182 -0
  205. package/src/components/DashboardBuilder/InlineText.tsx +112 -0
  206. package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
  207. package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
  208. package/src/components/DashboardBuilder/TextTileBody.tsx +31 -0
  209. package/src/components/DashboardBuilder/TileFrame.tsx +302 -163
  210. package/src/components/DashboardBuilder/TileMenu.tsx +125 -97
  211. package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
  212. package/src/components/DashboardBuilder/annotationText.ts +17 -0
  213. package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
  214. package/src/components/DashboardBuilder/artifactTagParity.spec.ts +46 -0
  215. package/src/components/DashboardBuilder/builderReport.ts +74 -0
  216. package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
  217. package/src/components/DashboardBuilder/catalog.spec.ts +2 -44
  218. package/src/components/DashboardBuilder/catalog.ts +61 -57
  219. package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
  220. package/src/components/DashboardBuilder/changedTile.ts +28 -0
  221. package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
  222. package/src/components/DashboardBuilder/chartLine.ts +121 -0
  223. package/src/components/DashboardBuilder/controls.spec.ts +21 -10
  224. package/src/components/DashboardBuilder/controls.ts +22 -8
  225. package/src/components/DashboardBuilder/document.ts +53 -5
  226. package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
  227. package/src/components/DashboardBuilder/documentSession.ts +258 -0
  228. package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
  229. package/src/components/DashboardBuilder/imports.spec.ts +61 -0
  230. package/src/components/DashboardBuilder/imports.ts +93 -0
  231. package/src/components/DashboardBuilder/inlineEdit.tsx +78 -0
  232. package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
  233. package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
  234. package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
  235. package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
  236. package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
  237. package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
  238. package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
  239. package/src/components/DashboardBuilder/malloyTree.ts +159 -7
  240. package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
  241. package/src/components/DashboardBuilder/newDashboard.ts +30 -3
  242. package/src/components/DashboardBuilder/openDraft.ts +52 -0
  243. package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
  244. package/src/components/DashboardBuilder/preview.spec.ts +159 -12
  245. package/src/components/DashboardBuilder/preview.ts +83 -9
  246. package/src/components/DashboardBuilder/readDocument.spec.ts +174 -26
  247. package/src/components/DashboardBuilder/readDocument.ts +137 -45
  248. package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
  249. package/src/components/DashboardBuilder/readForEditor.ts +52 -0
  250. package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
  251. package/src/components/DashboardBuilder/sortable.spec.ts +89 -0
  252. package/src/components/DashboardBuilder/sortable.tsx +11 -10
  253. package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
  254. package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
  255. package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
  256. package/src/components/DashboardBuilder/spliceDocument.ts +768 -131
  257. package/src/components/DashboardBuilder/spliceResult.ts +15 -0
  258. package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
  259. package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
  260. package/src/components/DashboardBuilder/tagParse.ts +103 -0
  261. package/src/components/DashboardBuilder/telemetry.ts +47 -0
  262. package/src/components/DashboardBuilder/testing/artifactTagParity.json +253 -0
  263. package/src/components/DashboardBuilder/testing/documentKindRule.json +40 -0
  264. package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
  265. package/src/components/DashboardBuilder/testing/inline.ts +25 -0
  266. package/src/components/DashboardBuilder/testing/resize.ts +48 -0
  267. package/src/components/DashboardBuilder/testing/urlRenderTags.json +62 -0
  268. package/src/components/DashboardBuilder/textTiles.spec.ts +760 -0
  269. package/src/components/DashboardBuilder/tileDisplayTitle.ts +13 -0
  270. package/src/components/DashboardBuilder/useBuilderSelection.ts +121 -0
  271. package/src/components/DashboardBuilder/useBuilderSession.spec.ts +250 -0
  272. package/src/components/DashboardBuilder/useBuilderSession.ts +255 -0
  273. package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +97 -0
  274. package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
  275. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +45 -9
  276. package/src/components/DashboardBuilder/useControlBindings.ts +152 -0
  277. package/src/components/DashboardBuilder/useConversionConfirm.ts +55 -0
  278. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
  279. package/src/components/DashboardBuilder/useDashboardEditor.ts +57 -181
  280. package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
  281. package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
  282. package/src/components/DashboardBuilder/useDraft.ts +15 -2
  283. package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
  284. package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
  285. package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
  286. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
  287. package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
  288. package/src/components/DashboardBuilder/useHostCopy.ts +104 -0
  289. package/src/components/DashboardBuilder/useOpenDraftCommit.ts +47 -0
  290. package/src/components/DashboardBuilder/useOpenedDocument.ts +314 -0
  291. package/src/components/DashboardBuilder/useSaveChannel.ts +275 -0
  292. package/src/components/DashboardBuilder/useTileEditing.ts +141 -0
  293. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
  294. package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
  295. package/src/components/DashboardBuilder/useTileResize.spec.tsx +30 -5
  296. package/src/components/DashboardBuilder/useTileResize.ts +31 -8
  297. package/src/components/DataAppViewer/DataAppViewer.tsx +7 -4
  298. package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
  299. package/src/components/DocumentCreate/canRetry.ts +19 -0
  300. package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
  301. package/src/components/DocumentCreate/createDocument.ts +159 -0
  302. package/src/components/DocumentCreate/documentPath.ts +40 -0
  303. package/src/components/DocumentCreate/events.ts +15 -0
  304. package/src/components/DocumentCreate/exportedSources.ts +25 -0
  305. package/src/components/DocumentCreate/guards.ts +45 -0
  306. package/src/components/DocumentCreate/index.ts +27 -0
  307. package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
  308. package/src/components/DocumentCreate/newNotebook.ts +44 -0
  309. package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
  310. package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
  311. package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
  312. package/src/components/Environment/Environment.tsx +0 -10
  313. package/src/components/Loading.tsx +14 -0
  314. package/src/components/Model/Model.tsx +16 -9
  315. package/src/components/Model/ModelExplorer.spec.tsx +2 -2
  316. package/src/components/Model/ModelExplorer.tsx +2 -2
  317. package/src/components/Model/SourcesExplorer.tsx +2 -4
  318. package/src/components/NarrowEditGate.spec.tsx +73 -0
  319. package/src/components/NarrowEditGate.tsx +29 -0
  320. package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
  321. package/src/components/Notebook/Notebook.tsx +72 -29
  322. package/src/components/Notebook/NotebookCell.tsx +90 -215
  323. package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
  324. package/src/components/Package/NewDocumentDialog.tsx +401 -0
  325. package/src/components/Package/Package.artifacts.spec.tsx +186 -0
  326. package/src/components/Package/Package.create.spec.tsx +401 -0
  327. package/src/components/Package/Package.notebooks.spec.tsx +18 -0
  328. package/src/components/Package/Package.tsx +396 -177
  329. package/src/components/Package/documentLocation.spec.ts +81 -0
  330. package/src/components/Package/documentLocation.ts +55 -0
  331. package/src/components/Package/index.ts +14 -1
  332. package/src/components/Package/useDocumentLocation.ts +59 -0
  333. package/src/components/PackageSection.tsx +2 -2
  334. package/src/components/Prose.spec.tsx +37 -0
  335. package/src/components/Prose.tsx +35 -5
  336. package/src/components/RenderedResult/RenderedResult.tsx +23 -8
  337. package/src/components/RenderedResult/ResultContainer.tsx +51 -13
  338. package/src/components/RenderedResult/ResultPanel.tsx +24 -5
  339. package/src/components/RenderedResult/loadRenderer.ts +42 -0
  340. package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
  341. package/src/components/RenderedResult/resultSizing.ts +14 -3
  342. package/src/components/ServerProvider.tsx +2 -1
  343. package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
  344. package/src/components/UnsavedChangesDialog.tsx +49 -0
  345. package/src/components/given/GivenInput.spec.tsx +5 -5
  346. package/src/components/given/GivenInput.tsx +46 -38
  347. package/src/components/given/GivensPanel.spec.tsx +6 -6
  348. package/src/components/given/GivensPanel.tsx +5 -11
  349. package/src/components/given/paramCodec.ts +27 -1
  350. package/src/components/index.ts +3 -2
  351. package/src/components/styles.ts +4 -5
  352. package/src/hooks/givenValue.ts +9 -0
  353. package/src/hooks/index.ts +7 -0
  354. package/src/hooks/useCompiledDocument.spec.tsx +86 -0
  355. package/src/hooks/useCompiledDocument.ts +59 -0
  356. package/src/hooks/useDimensionalFilterRangeData.ts +3 -1
  357. package/src/hooks/useDocumentControls.ts +13 -1
  358. package/src/hooks/useNarrowScreen.ts +21 -0
  359. package/src/hooks/useNearViewport.spec.tsx +150 -0
  360. package/src/hooks/useNearViewport.ts +102 -0
  361. package/src/hooks/useQueryResult.ts +23 -1
  362. package/src/hooks/useQueryWithApiError.ts +10 -3
  363. package/src/hooks/useRawQueryData.ts +3 -1
  364. package/src/hooks/useSettled.spec.ts +41 -0
  365. package/src/hooks/useSettled.ts +27 -0
  366. package/src/hooks/useSuggestOptions.dom.spec.ts +40 -1
  367. package/src/hooks/useSuggestOptions.ts +42 -10
  368. package/src/mainEntry.spec.ts +145 -0
  369. package/src/text-entry.ts +12 -0
  370. package/src/textEntry.spec.ts +112 -0
  371. package/src/theme/accent.spec.ts +116 -0
  372. package/src/theme/accent.ts +148 -0
  373. package/src/theme/buildTableCssVars.spec.ts +24 -0
  374. package/src/theme/buildTableCssVars.ts +1 -2
  375. package/src/theme/buildVegaThemeOverride.spec.ts +38 -2
  376. package/src/theme/buildVegaThemeOverride.ts +5 -5
  377. package/src/theme/defaults.ts +34 -0
  378. package/src/theme/index.ts +9 -0
  379. package/src/theme/keys.ts +6 -0
  380. package/src/theme/motion.ts +44 -0
  381. package/src/theme/readChartAnnotations.spec.ts +18 -0
  382. package/src/theme/readChartAnnotations.ts +1 -1
  383. package/src/theme/resolveTheme.spec.ts +73 -0
  384. package/src/theme/resolveTheme.ts +61 -20
  385. package/src/theme/types.ts +30 -5
  386. package/src/utils/clock.spec.ts +12 -0
  387. package/src/utils/clock.ts +6 -0
  388. package/src/{components/DashboardBuilder → utils}/malloyText.spec.ts +48 -0
  389. package/src/utils/malloyText.ts +368 -0
  390. package/src/utils/queryClient.ts +8 -0
  391. package/vite.config.ts +4 -0
  392. package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
  393. package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
  394. package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
  395. package/dist/components/Dashboard/DashboardBar.d.ts +0 -21
  396. package/dist/components/Dashboard/ExploreDialog.d.ts +0 -20
  397. package/dist/components/DashboardBuilder/DiffDialog.d.ts +0 -15
  398. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +0 -20
  399. package/dist/components/DashboardBuilder/diff.d.ts +0 -35
  400. package/dist/components/DashboardBuilder/malloyText.d.ts +0 -64
  401. package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
  402. package/src/components/Dashboard/DashboardBar.tsx +0 -88
  403. package/src/components/Dashboard/ExploreDialog.tsx +0 -89
  404. package/src/components/DashboardBuilder/DiffDialog.tsx +0 -122
  405. package/src/components/DashboardBuilder/SettingsPopover.tsx +0 -168
  406. package/src/components/DashboardBuilder/diff.spec.ts +0 -44
  407. package/src/components/DashboardBuilder/diff.ts +0 -93
  408. package/src/components/DashboardBuilder/malloyText.ts +0 -214
  409. package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
  410. package/src/components/Package/NewDashboardDialog.tsx +0 -265
@@ -30,7 +30,9 @@ const executeQueryModel = mock(
30
30
 
31
31
  mockServerProvider({ models: { executeQueryModel } });
32
32
 
33
- const { useSuggestOptions } = await import("./useSuggestOptions");
33
+ const { buildSuggestQuery, useSuggestOptions } = await import(
34
+ "./useSuggestOptions"
35
+ );
34
36
 
35
37
  const SPECS: Given[] = [
36
38
  {
@@ -148,3 +150,40 @@ it("sends no givens when the suggest names none, or the caller offers none", asy
148
150
  (executeQueryModel.mock.calls[0][3] as { givens?: unknown }).givens,
149
151
  ).toBeUndefined();
150
152
  });
153
+
154
+ it("runs a suggest as the document's definitions plus one run:, by name or by dimension, when a preamble is given", async () => {
155
+ const specs: Given[] = [
156
+ {
157
+ name: "REGION",
158
+ control: "select",
159
+ suggest: { source: "a", dimension: "region" },
160
+ },
161
+ { name: "BRAND", control: "select", suggest: { query: "brands" } },
162
+ ];
163
+ executeQueryModel.mockClear();
164
+ renderHook(
165
+ () =>
166
+ useSuggestOptions(
167
+ "env",
168
+ "pkg",
169
+ "models/orders.malloy",
170
+ specs,
171
+ undefined,
172
+ undefined,
173
+ "source: a is orders",
174
+ ),
175
+ { wrapper: serverWrapper },
176
+ );
177
+
178
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalledTimes(2));
179
+ const requests = executeQueryModel.mock.calls.map(
180
+ (call) => call[3] as { query?: string; queryName?: string },
181
+ );
182
+ expect(requests.every((request) => request.queryName === undefined)).toBe(
183
+ true,
184
+ );
185
+ expect(requests.map((request) => request.query)).toEqual([
186
+ `source: a is orders\n\n${buildSuggestQuery("a", "region")}`,
187
+ "source: a is orders\n\nrun: brands",
188
+ ]);
189
+ });
@@ -4,9 +4,13 @@
4
4
  import { useQueries } from "@tanstack/react-query";
5
5
  import { useMemo } from "react";
6
6
  import type { Given } from "../client";
7
- import { givensToRequest } from "../components/given/paramCodec";
7
+ import { withPreamble } from "../components/Dashboard/textSource";
8
+ import {
9
+ givensToRequest,
10
+ withHostGivens,
11
+ } from "../components/given/paramCodec";
8
12
  import { useServer } from "../components/ServerProvider";
9
- import type { GivenValue } from "./givenValue";
13
+ import type { GivenValue, HostGivenValue } from "./givenValue";
10
14
 
11
15
  /**
12
16
  * How many options a generated `suggest { source=… dimension=… }` asks for.
@@ -92,9 +96,10 @@ export function suggestRequestGivens(
92
96
  ): Record<string, unknown> | undefined {
93
97
  const names = spec.suggest?.givenNames;
94
98
  if (!applied || !names || names.length === 0) return undefined;
95
- const request = givensToRequest(
96
- applied.values,
97
- applied.declaredTypes,
99
+ const request = withHostGivens(
100
+ givensToRequest(applied.values, applied.declaredTypes, names),
101
+ // A control's own value wins, so only what no control declares is added.
102
+ hostOnly(applied),
98
103
  names,
99
104
  );
100
105
  return Object.keys(request).length > 0 ? request : undefined;
@@ -104,6 +109,19 @@ export function suggestRequestGivens(
104
109
  export interface AppliedGivens {
105
110
  values: ReadonlyMap<string, GivenValue>;
106
111
  declaredTypes: ReadonlyMap<string, string | undefined>;
112
+ /** Givens the host sets with no control: a gated source's suggest needs them, and they may be lists. */
113
+ host?: Readonly<Record<string, HostGivenValue>>;
114
+ }
115
+
116
+ function hostOnly(
117
+ applied: AppliedGivens,
118
+ ): Record<string, HostGivenValue> | undefined {
119
+ if (!applied.host) return undefined;
120
+ return Object.fromEntries(
121
+ Object.entries(applied.host).filter(
122
+ ([name]) => !applied.declaredTypes.has(name),
123
+ ),
124
+ );
107
125
  }
108
126
 
109
127
  export function useSuggestOptions(
@@ -120,6 +138,11 @@ export function useSuggestOptions(
120
138
  * caller that omits it gets the pre-gating behaviour.
121
139
  */
122
140
  applied?: AppliedGivens,
141
+ /**
142
+ * Text-source mode: the document's definitions, sent ahead of the suggest as
143
+ * the viewer's own text. Absent, a suggest runs by name or by view as before.
144
+ */
145
+ preamble?: string,
123
146
  ): {
124
147
  options: Map<string, string[]>;
125
148
  isLoading: boolean;
@@ -167,19 +190,21 @@ export function useSuggestOptions(
167
190
  // Only the givens the suggest carries, so a change to any OTHER
168
191
  // control leaves the cached list alone.
169
192
  givens === undefined ? null : JSON.stringify(givens),
193
+ // Only a text source keys on its definitions, so no other key changes shape.
194
+ ...(preamble === undefined ? [] : [preamble]),
170
195
  ],
171
196
  enabled: modelPath !== undefined,
172
197
  // Option lists change with the data, not with the filters, so they
173
198
  // are cached well past a single control interaction.
174
199
  staleTime: 5 * 60 * 1000,
175
200
  refetchOnWindowFocus: false,
176
- queryFn: async () => {
201
+ queryFn: async ({ signal }: { signal: AbortSignal }) => {
177
202
  const suggest = spec.suggest ?? {};
178
203
  const response = await apiClients.models.executeQueryModel(
179
204
  environmentName,
180
205
  packageName,
181
206
  modelPath as string,
182
- suggest.query !== undefined
207
+ suggest.query !== undefined && preamble === undefined
183
208
  ? {
184
209
  queryName: suggest.query,
185
210
  compactJson: true,
@@ -187,14 +212,21 @@ export function useSuggestOptions(
187
212
  givens,
188
213
  }
189
214
  : {
190
- query: buildSuggestQuery(
191
- suggest.source as string,
192
- suggest.dimension as string,
215
+ query: withPreamble(
216
+ preamble ?? "",
217
+ suggest.query !== undefined
218
+ ? `run: ${suggest.query}`
219
+ : buildSuggestQuery(
220
+ suggest.source as string,
221
+ suggest.dimension as string,
222
+ ),
193
223
  ),
194
224
  compactJson: true,
195
225
  versionId,
196
226
  givens,
197
227
  },
228
+ undefined,
229
+ { signal },
198
230
  );
199
231
  return readOptionValues(
200
232
  response.data.result,
@@ -0,0 +1,145 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import ts from "typescript";
8
+
9
+ /**
10
+ * The bundle boundary, walked rather than reviewed: `@malloydata/malloy` is
11
+ * ~440 KB gzipped and belongs to `@malloy-publisher/sdk/builder` alone, so no
12
+ * module statically reachable from the main entry may import it, or the
13
+ * builder entry, or anything under the builders. Type-only imports are erased
14
+ * and dynamic `import()` is the point, so neither counts.
15
+ */
16
+ const SRC = import.meta.dir;
17
+
18
+ /** Builder-only modules: they pull in the Malloy parser, which the main entry must not reach. */
19
+ const BUILDER_ONLY =
20
+ /^components\/DashboardBuilder\/(legacyNotebook|DashboardEditor|NotebookEditor|readDocument|spliceDocument|malloyTree|InlineText|InlineMarkdown)\./;
21
+
22
+ const EXTENSIONS = [".ts", ".tsx", "/index.ts", "/index.tsx"];
23
+
24
+ function resolve(from: string, specifier: string): string | undefined {
25
+ const base = path.resolve(path.dirname(from), specifier);
26
+ if (fs.existsSync(base) && fs.statSync(base).isFile()) return base;
27
+ return EXTENSIONS.map((ext) => base + ext).find((file) =>
28
+ fs.existsSync(file),
29
+ );
30
+ }
31
+
32
+ /** The specifiers a module imports or re-exports at runtime. */
33
+ function runtimeImports(file: string): string[] {
34
+ const source = ts.createSourceFile(
35
+ file,
36
+ fs.readFileSync(file, "utf8"),
37
+ ts.ScriptTarget.Latest,
38
+ false,
39
+ file.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS,
40
+ );
41
+ const found: string[] = [];
42
+ for (const statement of source.statements) {
43
+ if (ts.isImportDeclaration(statement)) {
44
+ const clause = statement.importClause;
45
+ const bindings = clause?.namedBindings;
46
+ const onlyTypes =
47
+ clause !== undefined &&
48
+ (clause.isTypeOnly ||
49
+ (clause.name === undefined &&
50
+ bindings !== undefined &&
51
+ ts.isNamedImports(bindings) &&
52
+ bindings.elements.length > 0 &&
53
+ bindings.elements.every((element) => element.isTypeOnly)));
54
+ if (!onlyTypes)
55
+ found.push((statement.moduleSpecifier as ts.StringLiteral).text);
56
+ } else if (
57
+ ts.isExportDeclaration(statement) &&
58
+ statement.moduleSpecifier !== undefined &&
59
+ !statement.isTypeOnly &&
60
+ !(
61
+ statement.exportClause !== undefined &&
62
+ ts.isNamedExports(statement.exportClause) &&
63
+ statement.exportClause.elements.length > 0 &&
64
+ statement.exportClause.elements.every(
65
+ (element) => element.isTypeOnly,
66
+ )
67
+ )
68
+ )
69
+ found.push((statement.moduleSpecifier as ts.StringLiteral).text);
70
+ }
71
+ return found;
72
+ }
73
+
74
+ function staticGraph(entry: string) {
75
+ const modules = new Set<string>();
76
+ const packages = new Set<string>();
77
+ // A relative import the walk cannot follow is a hole in the guard, so it is reported rather than skipped.
78
+ const unresolved: string[] = [];
79
+ const queue = [entry];
80
+ while (queue.length > 0) {
81
+ const file = queue.pop()!;
82
+ if (modules.has(file)) continue;
83
+ modules.add(file);
84
+ for (const specifier of runtimeImports(file)) {
85
+ if (!specifier.startsWith(".")) {
86
+ packages.add(specifier);
87
+ continue;
88
+ }
89
+ const target = resolve(file, specifier);
90
+ if (target === undefined)
91
+ unresolved.push(`${path.relative(SRC, file)}: ${specifier}`);
92
+ else if (/\.tsx?$/.test(target)) queue.push(target);
93
+ }
94
+ }
95
+ return { modules, packages, unresolved };
96
+ }
97
+
98
+ describe("the main entry", () => {
99
+ const { modules, packages, unresolved } = staticGraph(
100
+ path.join(SRC, "index.ts"),
101
+ );
102
+
103
+ it("follows every relative import it meets", () => {
104
+ expect(unresolved).toEqual([]);
105
+ });
106
+
107
+ it("walks a real graph", () => {
108
+ expect(modules.size).toBeGreaterThan(50);
109
+ expect(modules.has(path.join(SRC, "components/ServerProvider.tsx"))).toBe(
110
+ true,
111
+ );
112
+ });
113
+
114
+ it("never statically imports the Malloy compiler", () => {
115
+ const compiler = [...packages].filter(
116
+ (name) =>
117
+ name === "@malloydata/malloy" ||
118
+ name.startsWith("@malloydata/malloy/"),
119
+ );
120
+ expect(compiler).toEqual([]);
121
+ });
122
+
123
+ it("never reaches the builders", () => {
124
+ const builders = [...modules]
125
+ .map((file) => path.relative(SRC, file))
126
+ .filter(
127
+ (file) => file === "builder-entry.ts" || BUILDER_ONLY.test(file),
128
+ );
129
+ expect(builders).toEqual([]);
130
+ });
131
+
132
+ it("lets the create primitives in without the parser or the editors", () => {
133
+ const dir = path.join(SRC, "components/DocumentCreate");
134
+ const { modules, packages } = staticGraph(path.join(dir, "index.ts"));
135
+ expect(
136
+ [...packages].filter((name) => name.startsWith("@malloydata/malloy")),
137
+ ).toEqual([]);
138
+ const reached = [...modules]
139
+ .map((file) => path.relative(SRC, file))
140
+ .filter(
141
+ (file) => file === "builder-entry.ts" || BUILDER_ONLY.test(file),
142
+ );
143
+ expect(reached).toEqual([]);
144
+ });
145
+ });
@@ -0,0 +1,12 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ // Text and retry helpers with no dependencies, apart from the main entry: a host reads a
5
+ // file's artifact tag here without loading MUI or the Malloy parser, and in a
6
+ // plain node environment. Nothing here may import a package or another module.
7
+ export {
8
+ artifactTag,
9
+ splitSourceLines,
10
+ type ArtifactTag,
11
+ } from "./utils/malloyText";
12
+ export { canRetryRequest } from "./components/DocumentCreate/canRetry";
@@ -0,0 +1,112 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import fs from "node:fs";
6
+ import os from "node:os";
7
+ import path from "node:path";
8
+ import ts from "typescript";
9
+ import { artifactTag, splitSourceLines } from "./text-entry";
10
+
11
+ const ENTRY = path.join(import.meta.dir, "text-entry.ts");
12
+ const RETRY = path.join(
13
+ import.meta.dir,
14
+ "components/DocumentCreate/canRetry.ts",
15
+ );
16
+ const MODULE = path.join(import.meta.dir, "utils/malloyText.ts");
17
+
18
+ describe("@malloy-publisher/sdk/text", () => {
19
+ // Hosts import this in vitest's plain node environment, where they also mock the main entry.
20
+ it("re-exports two modules, which import nothing", () => {
21
+ const entry = fs.readFileSync(ENTRY, "utf8");
22
+ expect([...entry.matchAll(/from\s+"([^"]+)"/g)].map((m) => m[1])).toEqual(
23
+ ["./utils/malloyText", "./components/DocumentCreate/canRetry"],
24
+ );
25
+ expect(fs.readFileSync(RETRY, "utf8")).not.toMatch(
26
+ /^\s*(import|export\s.*\sfrom)\b|\brequire\(|\bimport\(/m,
27
+ );
28
+ expect(fs.readFileSync(MODULE, "utf8")).not.toMatch(
29
+ /^\s*(import|export\s.*\sfrom)\b|\brequire\(|\bimport\(/m,
30
+ );
31
+ });
32
+
33
+ it("loads in plain node with nothing installed and no DOM", () => {
34
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "sdk-text-"));
35
+ try {
36
+ // Transpiled rather than type-stripped: CI's node may predate stripping.
37
+ const js = ts.transpileModule(fs.readFileSync(MODULE, "utf8"), {
38
+ compilerOptions: {
39
+ module: ts.ModuleKind.ESNext,
40
+ target: ts.ScriptTarget.ES2022,
41
+ },
42
+ }).outputText;
43
+ fs.writeFileSync(path.join(dir, "text.mjs"), js);
44
+ fs.writeFileSync(
45
+ path.join(dir, "check.mjs"),
46
+ `import { artifactTag, splitSourceLines } from "./text.mjs";
47
+ const tag = artifactTag(splitSourceLines("x\\r\\n## artifact { kind=notebook }\\r\\nrun: a"));
48
+ console.log(JSON.stringify({ tag, document: typeof document }));`,
49
+ );
50
+ const run = Bun.spawnSync(["node", "check.mjs"], { cwd: dir });
51
+ expect(run.stderr.toString()).toBe("");
52
+ expect(JSON.parse(run.stdout.toString())).toEqual({
53
+ tag: {
54
+ from: 1,
55
+ to: 1,
56
+ block: false,
57
+ text: "## artifact { kind=notebook }",
58
+ },
59
+ document: "undefined",
60
+ });
61
+ } finally {
62
+ fs.rmSync(dir, { recursive: true, force: true });
63
+ }
64
+ });
65
+
66
+ it("exports only the tag reader, the line splitter and the retry rule", async () => {
67
+ expect(Object.keys(await import("./text-entry")).sort()).toEqual([
68
+ "artifactTag",
69
+ "canRetryRequest",
70
+ "splitSourceLines",
71
+ ]);
72
+ });
73
+ });
74
+
75
+ describe("splitSourceLines", () => {
76
+ it("splits on LF, CRLF and a bare CR, keeping no line ending", () => {
77
+ expect(splitSourceLines("a\nb\r\nc\rd")).toEqual(["a", "b", "c", "d"]);
78
+ expect(splitSourceLines("a\r\n\r\nb")).toEqual(["a", "", "b"]);
79
+ expect(splitSourceLines("")).toEqual([""]);
80
+ expect(splitSourceLines("a\n")).toEqual(["a", ""]);
81
+ });
82
+ });
83
+
84
+ describe("artifactTag", () => {
85
+ const tagOf = (source: string) => artifactTag(splitSourceLines(source));
86
+
87
+ it("finds a one-line tag and a block tag, by line", () => {
88
+ expect(tagOf("##! x\n## artifact { kind=dashboard }\nrun: a")).toEqual({
89
+ from: 1,
90
+ to: 1,
91
+ block: false,
92
+ text: "## artifact { kind=dashboard }",
93
+ });
94
+ expect(tagOf("##| artifact { kind=notebook\n}\n|##\nrun: a")).toEqual({
95
+ from: 0,
96
+ to: 2,
97
+ block: true,
98
+ text: "##| artifact { kind=notebook\n}",
99
+ });
100
+ });
101
+
102
+ it("reads the same tag from CRLF text", () => {
103
+ expect(
104
+ tagOf("##| artifact { kind=notebook\r\n}\r\n|##\r\nrun: a"),
105
+ ).toEqual(tagOf("##| artifact { kind=notebook\n}\n|##\nrun: a"));
106
+ });
107
+
108
+ it("finds none in an untagged file or inside another block", () => {
109
+ expect(tagOf("source: a is b")).toBeUndefined();
110
+ expect(tagOf('##|"\n## artifact { kind=notebook }\n|##')).toBeUndefined();
111
+ });
112
+ });
@@ -0,0 +1,116 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { PALETTE } from "../components/styles";
6
+ import { accentFor, contrastRatio, legibleOn } from "./accent";
7
+ import { resolveTheme } from "./resolveTheme";
8
+
9
+ const WHITE = "#ffffff";
10
+ const SLATE = "#0f172a";
11
+ const ratio = (a: string, b: string) => contrastRatio(a, b) as number;
12
+
13
+ describe("accentFor", () => {
14
+ it("keeps the Console's own blue pair when nothing is configured", () => {
15
+ expect(accentFor(PALETTE.blue, "light")).toEqual({
16
+ accent: PALETTE.blue,
17
+ accentHover: "#1d4ed8",
18
+ accentContrast: "#ffffff",
19
+ });
20
+ expect(accentFor(undefined, "dark").accent).toBe("#60a5fa");
21
+ });
22
+
23
+ it("keeps a colour that already reads, in either mode, exactly as picked", () => {
24
+ // A dark brand colour on white, and a bright one on slate.
25
+ expect(accentFor("#2d323d", "light").accent).toBe("#2d323d");
26
+ expect(accentFor("#f59e0b", "dark").accent).toBe("#f59e0b");
27
+ });
28
+
29
+ it("deepens a pale first colour on the light page until it reads at 3:1", () => {
30
+ expect(ratio("#fde047", WHITE)).toBeLessThan(3);
31
+ const { accent } = accentFor("#fde047", "light");
32
+ expect(ratio(accent, WHITE)).toBeGreaterThanOrEqual(3);
33
+ // Only as far as it takes: not all the way to black.
34
+ expect(ratio(accent, WHITE)).toBeLessThan(4);
35
+ });
36
+
37
+ it("lifts a dark first colour on the dark page only as far as it takes", () => {
38
+ expect(ratio("#2d323d", SLATE)).toBeLessThan(3);
39
+ const { accent } = accentFor("#2d323d", "dark");
40
+ expect(ratio(accent, SLATE)).toBeGreaterThanOrEqual(3);
41
+ expect(ratio(accent, SLATE)).toBeLessThan(4);
42
+ });
43
+
44
+ it("puts whichever label reads better on the accent", () => {
45
+ for (const [first, mode] of [
46
+ ["#2d323d", "light"],
47
+ ["#2d323d", "dark"],
48
+ ["#fde047", "light"],
49
+ ["#f59e0b", "dark"],
50
+ ] as const) {
51
+ const { accent, accentContrast } = accentFor(first, mode);
52
+ const other = accentContrast === WHITE ? SLATE : WHITE;
53
+ expect(ratio(accent, accentContrast)).toBeGreaterThanOrEqual(
54
+ ratio(accent, other),
55
+ );
56
+ }
57
+ });
58
+
59
+ it("uses a non-hex colour as given in light mode and keeps the dark default", () => {
60
+ expect(accentFor("rebeccapurple", "light").accent).toBe("rebeccapurple");
61
+ expect(accentFor("rebeccapurple", "dark").accent).toBe("#60a5fa");
62
+ });
63
+
64
+ it("follows the instance palette through resolveTheme, measured against its own page", () => {
65
+ const theme = resolveTheme(
66
+ [{ palette: { series: ["#2d323d", "#573f35"] } }],
67
+ "dark",
68
+ );
69
+ expect(ratio(theme.accent, theme.background)).toBeGreaterThanOrEqual(3);
70
+ expect(
71
+ resolveTheme([{ palette: { series: ["#2d323d"] } }], "light").accent,
72
+ ).toBe("#2d323d");
73
+ });
74
+
75
+ it("keeps drill links on the Console's default accent, whatever the palette", () => {
76
+ const theme = resolveTheme(
77
+ [{ palette: { series: ["#7e1d47"] } }],
78
+ "light",
79
+ );
80
+ expect(theme.drillLink).toBe(accentFor(undefined, "light").accent);
81
+ });
82
+ });
83
+
84
+ describe("legibleOn", () => {
85
+ it("returns a colour that already reads unchanged", () => {
86
+ expect(legibleOn("#b45309", SLATE)).toBe("#b45309");
87
+ });
88
+
89
+ it("moves toward white on a dark ground and toward black on a light one", () => {
90
+ expect(ratio(legibleOn("#2d323d", SLATE), SLATE)).toBeGreaterThanOrEqual(
91
+ 3,
92
+ );
93
+ expect(ratio(legibleOn("#fde047", WHITE), WHITE)).toBeGreaterThanOrEqual(
94
+ 3,
95
+ );
96
+ });
97
+ });
98
+
99
+ describe("dark mode legibility", () => {
100
+ it("lifts a series colour that disappears on the dark canvas, and leaves light mode alone", () => {
101
+ const layers = [{ palette: { series: ["#2d323d", "#b45309"] } }];
102
+ expect(resolveTheme(layers, "light").series[0]).toBe("#2d323d");
103
+ const dark = resolveTheme(layers, "dark");
104
+ expect(ratio(dark.series[0], dark.background)).toBeGreaterThanOrEqual(3);
105
+ // Already readable on slate: kept as picked.
106
+ expect(dark.series[1]).toBe("#b45309");
107
+ });
108
+
109
+ it("carries a light-only map colour into dark instead of the default", () => {
110
+ const layers = [{ palette: { mapColor: { light: "#465472" } } }];
111
+ const dark = resolveTheme(layers, "dark").mapColor;
112
+ const fallback = resolveTheme([], "dark").mapColor;
113
+ expect(dark).not.toBe(fallback);
114
+ expect(resolveTheme(layers, "light").mapColor).toBe("#465472");
115
+ });
116
+ });