@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
@@ -0,0 +1,258 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import type { QueryClient, QueryKey } from "@tanstack/react-query";
5
+ import { parseResourceUri } from "../../utils/formatting";
6
+ import { sha256Hex } from "../../utils/sha256";
7
+ import type { Workspace } from "../DocumentStorage";
8
+ import type { ApiClients } from "../ServerProvider";
9
+
10
+ // The pure half of an editor host's session with its document: which
11
+ // workspace it opens against, where Save goes, and the hash a package write
12
+ // carries. The dashboard and notebook hosts both decide these the same way.
13
+
14
+ import type { SavesTo } from "../Dashboard/telemetry";
15
+
16
+ export type { SavesTo };
17
+
18
+ /**
19
+ * The record when one declares itself, and otherwise the first writeable
20
+ * workspace. Pass every workspace, not only the writeable ones: a reader who
21
+ * cannot write to the record still has to be shown the record.
22
+ */
23
+ export function chooseWorkspace(
24
+ all: readonly Workspace[],
25
+ ): Workspace | undefined {
26
+ return (
27
+ all.find((candidate) => candidate.authoritative) ??
28
+ all.find((candidate) => candidate.writeable)
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Where Save goes, and which writer takes it, or `undefined` for no Save.
34
+ *
35
+ * `authoritative` wins outright rather than breaking a tie: a host whose store
36
+ * is the record may well sit on a server that reports itself writable, and
37
+ * writing the package there would edit a deploy of the record instead of the
38
+ * record.
39
+ */
40
+ export function saveTarget({
41
+ authoritative,
42
+ mutable,
43
+ versionId,
44
+ canStore,
45
+ readFailed,
46
+ }: {
47
+ authoritative: boolean;
48
+ mutable: boolean;
49
+ versionId?: string;
50
+ /** The host keeps documents and the chosen workspace takes writes. */
51
+ canStore: boolean;
52
+ /** The host's copy could not be read. */
53
+ readFailed: boolean;
54
+ }): {
55
+ savesTo: SavesTo;
56
+ pinnedPackageSave: boolean;
57
+ writer: "storage" | "package" | undefined;
58
+ } {
59
+ const savesTo = authoritative ? "host" : mutable ? "package" : "browser";
60
+ // A version is an immutable checkpoint, and `updateModelSource` cannot be
61
+ // told to write against one (the server answers 501). Without this guard,
62
+ // `expectedHash` would be the hash of the pinned text, the server would
63
+ // refuse every save against the current file, and the catch would refetch
64
+ // the same pinned text: a dead end with no way out. Storage-backed saves are
65
+ // unaffected, since they never touch the package's compare-and-swap.
66
+ const pinnedPackageSave = versionId !== undefined && savesTo === "package";
67
+ const writer = authoritative
68
+ ? canStore
69
+ ? "storage"
70
+ : undefined
71
+ : pinnedPackageSave
72
+ ? undefined
73
+ : mutable
74
+ ? "package"
75
+ : canStore
76
+ ? "storage"
77
+ : undefined;
78
+ // A copy that could not be read is not a copy that is not there. Saving on
79
+ // that belief is what rewinds the record, so Save is off until a reader can
80
+ // be told what actually happened.
81
+ return {
82
+ savesTo,
83
+ pinnedPackageSave,
84
+ writer: readFailed ? undefined : writer,
85
+ };
86
+ }
87
+
88
+ /**
89
+ * The `expectedHash` a package write carries: the server's own hash after this
90
+ * editor's last write, else the hash of the package file the editor opened on.
91
+ * Never the latest fetch's, which may already hold someone else's change.
92
+ */
93
+ export async function expectedHashFor(
94
+ savedHash: string | undefined,
95
+ base: string | undefined,
96
+ ): Promise<string | undefined> {
97
+ return savedHash ?? (base === undefined ? undefined : await sha256Hex(base));
98
+ }
99
+
100
+ /**
101
+ * What the toolbar says about where Save goes, in the backend's own words
102
+ * wherever it has any: a workspace carries a `description` precisely so the
103
+ * editor does not have to guess, and "this browser" is one host's answer
104
+ * rather than the interface's.
105
+ */
106
+ export function saveCaption({
107
+ authoritative,
108
+ mutable,
109
+ pinnedPackageSave,
110
+ workspace,
111
+ readFailure,
112
+ versionId,
113
+ }: {
114
+ authoritative: boolean;
115
+ mutable: boolean;
116
+ pinnedPackageSave: boolean;
117
+ workspace?: Workspace;
118
+ readFailure?: string;
119
+ versionId?: string;
120
+ }): string {
121
+ if (readFailure !== undefined)
122
+ return `The saved copy could not be read, so Save is off: ${readFailure}`;
123
+ if (authoritative && workspace)
124
+ return workspace.writeable
125
+ ? workspace.description
126
+ : `${workspace.description}: you cannot save into it.`;
127
+ if (pinnedPackageSave)
128
+ return `Reading version ${versionId}: a version is a fixed point in history, so Save is off.`;
129
+ if (mutable) return "Save writes the file into the package.";
130
+ if (workspace)
131
+ return `${workspace.description}: this server does not take writes.`;
132
+ return "This server does not take writes.";
133
+ }
134
+
135
+ /** What a storage backend said went wrong, for a reader who has to act on it. */
136
+ export function storageErrorMessage(error: unknown): string {
137
+ return error instanceof Error ? error.message : String(error);
138
+ }
139
+
140
+ /** The server's own reason for a refused write, when it gave one. */
141
+ export function apiErrorMessage(error: unknown): string {
142
+ const data = (error as { response?: { data?: { message?: string } } })
143
+ .response?.data;
144
+ if (data?.message) return data.message;
145
+ return error instanceof Error ? error.message : String(error);
146
+ }
147
+
148
+ /** A query family a package write marks stale. */
149
+ export interface Invalidation {
150
+ queryKey: QueryKey;
151
+ /** `"none"` marks the family stale without refetching it. */
152
+ refetchType?: "none";
153
+ /** Hold the write's result until the refetch lands. */
154
+ wait?: boolean;
155
+ }
156
+
157
+ /**
158
+ * Writes a package file against `expectedHash` and returns the server's hash
159
+ * of what it wrote. A refused write invalidates `invalidateOnError`, since it
160
+ * usually means the file moved, and throws the server's own reason.
161
+ * `afterWrite` runs once the write has landed and before the invalidations, so
162
+ * the caller's bookkeeping is in place when a refetch arrives.
163
+ */
164
+ export async function writePackageFile({
165
+ apiClients,
166
+ queryClient,
167
+ environmentName,
168
+ packageName,
169
+ modelPath,
170
+ source,
171
+ expectedHash,
172
+ invalidateOnError,
173
+ invalidate,
174
+ afterWrite,
175
+ }: {
176
+ apiClients: ApiClients;
177
+ queryClient: QueryClient;
178
+ environmentName: string;
179
+ packageName: string;
180
+ modelPath: string;
181
+ source: string;
182
+ expectedHash: string;
183
+ invalidateOnError: readonly QueryKey[];
184
+ invalidate: readonly Invalidation[];
185
+ afterWrite?: (contentHash: string) => Promise<void> | void;
186
+ }): Promise<string> {
187
+ let result;
188
+ try {
189
+ result = await apiClients.models.updateModelSource(
190
+ environmentName,
191
+ packageName,
192
+ modelPath,
193
+ { source, expectedHash },
194
+ );
195
+ } catch (error) {
196
+ for (const queryKey of invalidateOnError)
197
+ void queryClient.invalidateQueries({ queryKey });
198
+ throw new Error(apiErrorMessage(error));
199
+ }
200
+ const contentHash = result.data.contentHash;
201
+ await afterWrite?.(contentHash);
202
+ for (const { queryKey, refetchType, wait } of invalidate) {
203
+ const pending = queryClient.invalidateQueries({
204
+ queryKey,
205
+ ...(refetchType ? { refetchType } : {}),
206
+ });
207
+ if (wait) await pending;
208
+ else void pending;
209
+ }
210
+ return contentHash;
211
+ }
212
+
213
+ /** The host workspace that took a save or its undo, named on the event; a package save was taken by none. */
214
+ export function withWorkspace<E extends { type: string }>(
215
+ event: E,
216
+ workspace: string | undefined,
217
+ ): E {
218
+ if (
219
+ workspace === undefined ||
220
+ !/\.(saved|save_undone)$/.test(event.type) ||
221
+ (event as { where?: SavesTo }).where === "package"
222
+ )
223
+ return event;
224
+ return { ...event, workspace };
225
+ }
226
+
227
+ /** The environment, package and version an editor was asked for, from either prop form; a render body must not throw, so a URI `parseResourceUri` rejects reads as naming neither. */
228
+ export function resolveEditorTarget(
229
+ props:
230
+ | { resourceUri: string }
231
+ | { environmentName: string; packageName: string },
232
+ ): {
233
+ environmentName: string;
234
+ packageName: string;
235
+ versionId: string | undefined;
236
+ /** False when a resource URI did not name both an environment and a package. */
237
+ namesBoth: boolean;
238
+ } {
239
+ if (!("resourceUri" in props))
240
+ return {
241
+ environmentName: props.environmentName,
242
+ packageName: props.packageName,
243
+ versionId: undefined,
244
+ namesBoth: true,
245
+ };
246
+ let parsed: ReturnType<typeof parseResourceUri> | undefined;
247
+ try {
248
+ parsed = parseResourceUri(props.resourceUri);
249
+ } catch {
250
+ parsed = undefined;
251
+ }
252
+ return {
253
+ environmentName: parsed?.environmentName ?? "",
254
+ packageName: parsed?.packageName ?? "",
255
+ versionId: parsed?.versionId,
256
+ namesBoth: !!parsed?.environmentName && !!parsed?.packageName,
257
+ };
258
+ }
@@ -0,0 +1,131 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import {
6
+ buildSuggestQuery,
7
+ SUGGEST_OPTION_LIMIT,
8
+ } from "../../hooks/useSuggestOptions";
9
+ import { newLocalGiven } from "./controls";
10
+ import { readDashboardDocument, readFailed } from "./readDocument";
11
+ import { openDocument, refused, splice, spliced } from "./testing/fixtures";
12
+ import { spliceFailed } from "./spliceDocument";
13
+ import { queryTile } from "./testing/fixtures";
14
+ import { tileKey } from "./document";
15
+
16
+ const EMPTY = `##! experimental.givens
17
+ ## artifact { title="T" tiles=[] } dashboard { columns=12 }
18
+ import { one } from "../m.malloy"
19
+ `;
20
+
21
+ const ONE_TILE = `##! experimental.givens
22
+ ## artifact { title="T" tiles=["a -> x"] } dashboard { columns=12 }
23
+ import { one } from "../m.malloy"
24
+
25
+ source: a is one extend {
26
+ view: x is vx
27
+ }`;
28
+
29
+ describe("a dashboard with an explicit, empty tile list", () => {
30
+ it("opens with no tiles", async () => {
31
+ const doc = await openDocument(EMPTY);
32
+ expect(doc.tiles).toEqual([]);
33
+ expect(doc.title).toBe("T");
34
+ });
35
+
36
+ it("still refuses a file whose artifact tag has no tiles key", async () => {
37
+ const result = await readDashboardDocument(
38
+ '## artifact { title="T" } dashboard { columns=12 }\nimport "../m.malloy"\n',
39
+ );
40
+ expect(readFailed(result)).toBe(true);
41
+ });
42
+
43
+ it("still refuses a list holding entries the builder cannot read", async () => {
44
+ const result = await readDashboardDocument(
45
+ '## artifact { title="T" tiles=[text intro] }\nimport "../m.malloy"\n',
46
+ );
47
+ expect(readFailed(result)).toBe(true);
48
+ });
49
+
50
+ it("takes its first tile, creating the extension", async () => {
51
+ const out = await spliced(EMPTY, (d) => {
52
+ d.sources.push({ name: "one_tiles", base: "one" });
53
+ d.tiles.push({
54
+ name: "vx_tile",
55
+ source: "one_tiles",
56
+ declaration: { kind: "reference", from: "vx" },
57
+ colspan: 6,
58
+ });
59
+ });
60
+ expect(out).toContain('tiles=["one_tiles -> vx_tile"]');
61
+ const back = await openDocument(out);
62
+ expect(back.tiles.map(tileKey)).toEqual(["one_tiles.vx_tile"]);
63
+ });
64
+
65
+ it("refuses to remove the last tile, because an empty file is not served", async () => {
66
+ const reason = await refused(ONE_TILE, (d) => {
67
+ d.tiles = [];
68
+ });
69
+ expect(reason).toContain("not served");
70
+ });
71
+
72
+ it("still removes a tile when another remains", async () => {
73
+ const two = ONE_TILE.replace(
74
+ '["a -> x"]',
75
+ '["a -> x", "a -> y"]',
76
+ ).replace("view: x is vx", "view: x is vx\n view: y is vy");
77
+ const result = await splice(two, (d) => {
78
+ d.tiles.splice(1, 1);
79
+ });
80
+ expect(spliceFailed(result)).toBe(false);
81
+ });
82
+ });
83
+
84
+ describe("a filter on a joined dimension", () => {
85
+ it("keeps the whole path on the declared control", () => {
86
+ const given = newLocalGiven({
87
+ name: "CATEGORY",
88
+ label: "Category",
89
+ kind: "select",
90
+ field: "products.category",
91
+ source: "order_items",
92
+ });
93
+ expect(given.suggest).toEqual({
94
+ source: "order_items",
95
+ dimension: "products.category",
96
+ });
97
+ });
98
+
99
+ it("is written quoted, reads back whole, and forms the options query", async () => {
100
+ const source = `##! experimental.givens
101
+ ## artifact { title="T" tiles=["a -> x"] }
102
+ import { one, products } from "../m.malloy"
103
+
104
+ source: a is one extend {
105
+ view: x is vx
106
+ }`;
107
+ const out = await spliced(source, (d) => {
108
+ d.localGivens = [
109
+ newLocalGiven({
110
+ name: "CATEGORY",
111
+ label: "Category",
112
+ kind: "select",
113
+ field: "products.category",
114
+ source: "a",
115
+ }),
116
+ ];
117
+ queryTile(d, 0).filters = [
118
+ { field: "products.category", given: "CATEGORY" },
119
+ ];
120
+ });
121
+ expect(out).toContain(
122
+ '# label="Category" control=select suggest { source=a dimension="products.category" }',
123
+ );
124
+ const back = await openDocument(out);
125
+ const suggest = back.localGivens?.[0].suggest;
126
+ expect(suggest).toEqual({ source: "a", dimension: "products.category" });
127
+ expect(buildSuggestQuery(suggest!.source!, suggest!.dimension)).toBe(
128
+ `run: a -> {\n group_by: products.category\n order_by: category asc\n limit: ${SUGGEST_OPTION_LIMIT}\n}`,
129
+ );
130
+ });
131
+ });
@@ -0,0 +1,61 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { importPathOf, reaches, withSource } from "./imports";
6
+
7
+ const doc = (from: string) => ({
8
+ imports: [{ kind: "names" as const, names: ["orders"], from }],
9
+ sources: [],
10
+ });
11
+
12
+ describe("importPathOf", () => {
13
+ it("names a model from wherever the document sits", () => {
14
+ expect(importPathOf("storefront.malloy", "dashboards/x.malloy")).toBe(
15
+ "../storefront.malloy",
16
+ );
17
+ expect(importPathOf("storefront.malloy", "notebooks/sub/x.malloy")).toBe(
18
+ "../../storefront.malloy",
19
+ );
20
+ expect(importPathOf("models/m.malloy", "models/x.malloy")).toBe(
21
+ "./m.malloy",
22
+ );
23
+ expect(importPathOf("m.malloy", "x.malloy")).toBe("./m.malloy");
24
+ });
25
+ });
26
+
27
+ describe("withSource", () => {
28
+ it("writes a new import relative to a document one folder deeper", () => {
29
+ const next = withSource(
30
+ { imports: [], sources: [] },
31
+ "regions",
32
+ "storefront.malloy",
33
+ "notebooks/sub/x.malloy",
34
+ );
35
+ expect(next).toEqual([
36
+ { kind: "names", names: ["regions"], from: "../../storefront.malloy" },
37
+ ]);
38
+ });
39
+
40
+ it("joins the model's existing import however it is spelled", () => {
41
+ const next = withSource(
42
+ doc("./../storefront.malloy"),
43
+ "regions",
44
+ "storefront.malloy",
45
+ "dashboards/x.malloy",
46
+ );
47
+ expect(next).toEqual([
48
+ {
49
+ kind: "names",
50
+ names: ["orders", "regions"],
51
+ from: "./../storefront.malloy",
52
+ },
53
+ ]);
54
+ });
55
+
56
+ it("adds nothing for a source the file already imports by name", () => {
57
+ expect(
58
+ reaches(doc("../storefront.malloy"), "orders", "storefront.malloy"),
59
+ ).toBe(true);
60
+ });
61
+ });
@@ -0,0 +1,93 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import type { DashboardDocument, DashboardImport } from "./document";
5
+
6
+ /** Where a document sits when the caller does not say: one folder below the package root. */
7
+ const DEFAULT_DOCUMENT_PATH = "dashboards/document.malloy";
8
+
9
+ /** The folder a package path sits in, with its trailing slash, or "" at the root. */
10
+ const folderOf = (path: string) => path.slice(0, path.lastIndexOf("/") + 1);
11
+
12
+ /**
13
+ * The package path an import names, read from where the document sits, so
14
+ * `"../m.malloy"` and `"./../m.malloy"` are the same model: comparing the text
15
+ * alone would miss the second, and importing a source the file already
16
+ * reaches declares it twice.
17
+ */
18
+ const resolvedOf = (from: string, documentPath: string) =>
19
+ new URL(
20
+ from,
21
+ `https://malloy.invalid/${folderOf(documentPath)}`,
22
+ ).pathname.slice(1);
23
+
24
+ /** How the document at `documentPath` names the model at `modelPath`. */
25
+ export function importPathOf(modelPath: string, documentPath: string): string {
26
+ const from = folderOf(documentPath).split("/").filter(Boolean);
27
+ const to = modelPath.split("/");
28
+ let shared = 0;
29
+ while (
30
+ shared < from.length &&
31
+ shared < to.length - 1 &&
32
+ from[shared] === to[shared]
33
+ )
34
+ shared++;
35
+ const up = from.length - shared;
36
+ return `${up === 0 ? "./" : "../".repeat(up)}${to.slice(shared).join("/")}`;
37
+ }
38
+
39
+ /**
40
+ * Whether the file can already see `name` from `modelPath`: it extends it,
41
+ * imports it by name, or imports that model whole. A whole-file import brings
42
+ * every source the model exports, and naming one of them again would declare
43
+ * it twice. A source the file sees only through another model that re-exports
44
+ * it is not followed: that needs the catalog to say which model declares each
45
+ * source, and the compile check on save catches the duplicate.
46
+ */
47
+ export function reaches(
48
+ document: Pick<DashboardDocument, "imports" | "sources">,
49
+ name: string,
50
+ modelPath: string,
51
+ documentPath: string = DEFAULT_DOCUMENT_PATH,
52
+ ): boolean {
53
+ if (document.sources.some((s) => s.base === name)) return true;
54
+ return document.imports.some((i) =>
55
+ i.kind === "names"
56
+ ? i.names.includes(name)
57
+ : resolvedOf(i.from, documentPath) === modelPath,
58
+ );
59
+ }
60
+
61
+ /**
62
+ * `imports` with `name` from `modelPath` brought in, by name — into that
63
+ * model's existing `{ … }` import when there is one, else as a new statement
64
+ * written relative to where the document sits. Unchanged when the file can
65
+ * already see it.
66
+ */
67
+ export function withSource(
68
+ document: Pick<DashboardDocument, "imports" | "sources">,
69
+ name: string,
70
+ modelPath: string,
71
+ documentPath: string = DEFAULT_DOCUMENT_PATH,
72
+ ): DashboardImport[] {
73
+ const { imports } = document;
74
+ if (reaches(document, name, modelPath, documentPath)) return imports;
75
+ const at = imports.findIndex(
76
+ (i) =>
77
+ i.kind === "names" && resolvedOf(i.from, documentPath) === modelPath,
78
+ );
79
+ if (at < 0)
80
+ return [
81
+ ...imports,
82
+ {
83
+ kind: "names",
84
+ names: [name],
85
+ from: importPathOf(modelPath, documentPath),
86
+ },
87
+ ];
88
+ return imports.map((i, index) =>
89
+ index === at && i.kind === "names"
90
+ ? { ...i, names: [...i.names, name] }
91
+ : i,
92
+ );
93
+ }
@@ -0,0 +1,78 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import type { Theme } from "@mui/material";
5
+ import type { SystemStyleObject } from "@mui/system";
6
+ import { MOTION_FAST, reducedMotionSx } from "../../theme/motion";
7
+ import type { ResolvedTheme } from "../../theme/types";
8
+
9
+ /** A thin pencil, drawn as a mask so it takes the text's own colour. */
10
+ const PENCIL = `url("data:image/svg+xml;utf8,${encodeURIComponent(
11
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>',
12
+ )}")`;
13
+
14
+ /** Where the pencil goes: after a line of text, or after the first block of prose. */
15
+ export type PencilAt = "line" | "prose";
16
+
17
+ /**
18
+ * How text that is edited where it is read says so: a thin pencil straight
19
+ * after the text, in the text's own colour and in proportion to its size,
20
+ * faint at rest and clearer under the pointer. The same mark in the same place
21
+ * for every field — a title, a subtitle, a description — and nothing else: no
22
+ * wash, no outline, no gutter. The keyboard gets a focus ring, since a pencil
23
+ * does not say where focus is.
24
+ *
25
+ * Drawn as a pseudo-element, so it adds no node and moves no layout; for prose
26
+ * it follows the first paragraph or heading, which is the line the reader is
27
+ * looking at when they reach for it.
28
+ */
29
+ export const editableSx = (
30
+ theme: ResolvedTheme,
31
+ at: PencilAt = "line",
32
+ ): SystemStyleObject<Theme> => {
33
+ // The pseudo-element's selector, at rest and while the field is hovered
34
+ // or focused: on the field itself for a line; for prose, on its first
35
+ // paragraph or heading, or on the lone span markdown renders a single line
36
+ // of prose as, with no paragraph around it.
37
+ const blocks = [
38
+ ":is(p, h1, h2, h3, h4, h5, h6):first-child::after",
39
+ "> * > span:only-child::after",
40
+ ];
41
+ const within = (prefix: string) =>
42
+ blocks.map((block) => `${prefix} ${block}`).join(", ");
43
+ const host = at === "line" ? "&::after" : within("&");
44
+ const lit =
45
+ at === "line"
46
+ ? "&:hover::after, &:focus-visible::after"
47
+ : `${within("&:hover")}, ${within("&:focus-visible")}`;
48
+ return {
49
+ cursor: "text",
50
+ borderRadius: "2px",
51
+ [host]: {
52
+ content: '""',
53
+ display: "inline-block",
54
+ width: "0.8em",
55
+ height: "0.8em",
56
+ ml: "0.4em",
57
+ verticalAlign: "-0.05em",
58
+ backgroundColor: "currentColor",
59
+ maskImage: PENCIL,
60
+ WebkitMaskImage: PENCIL,
61
+ maskSize: "contain",
62
+ WebkitMaskSize: "contain",
63
+ maskRepeat: "no-repeat",
64
+ WebkitMaskRepeat: "no-repeat",
65
+ opacity: 0.35,
66
+ transition: `opacity ${MOTION_FAST}`,
67
+ ...reducedMotionSx,
68
+ pointerEvents: "none",
69
+ },
70
+ [lit]: {
71
+ opacity: 0.8,
72
+ },
73
+ "&:focus-visible": {
74
+ outline: `2px solid ${theme.accent}`,
75
+ outlineOffset: 2,
76
+ },
77
+ };
78
+ };
@@ -2,7 +2,11 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { describe, expect, it } from "bun:test";
5
- import type { DashboardDocument } from "./document";
5
+ import {
6
+ isQueryTile,
7
+ type DashboardDocument,
8
+ type QueryTile,
9
+ } from "./document";
6
10
  import { readDashboardDocument, readFailed } from "./readDocument";
7
11
  import {
8
12
  spliceDashboardDocument,
@@ -117,7 +121,7 @@ run: a -> kpis
117
121
  `;
118
122
 
119
123
  const tile = (d: DashboardDocument, name: string) =>
120
- d.tiles.find((t) => t.name === name)!;
124
+ d.tiles.find((t): t is QueryTile => isQueryTile(t) && t.name === name)!;
121
125
 
122
126
  interface Row {
123
127
  what: string;