@malloy-publisher/sdk 0.9.9 → 0.9.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/dist/RenderedResult-BlNoIiSi.cjs.js +153 -0
  2. package/dist/{RenderedResult-BHuJpdSn.es.js → RenderedResult-Cmx8sX8d.es.js} +102 -102
  3. package/dist/ServerProvider-BOgiW8MX.cjs.js +1 -0
  4. package/dist/{ServerProvider-CQy4jVYK.es.js → ServerProvider-azXLkk1q.es.js} +619 -586
  5. package/dist/builder/index.cjs.js +78 -130
  6. package/dist/builder/index.es.js +7440 -6727
  7. package/dist/builder-entry.d.ts +3 -0
  8. package/dist/client/api.d.ts +26 -22
  9. package/dist/client/index.cjs.js +1 -1
  10. package/dist/client/index.es.js +1 -1
  11. package/dist/components/AppDialog.d.ts +9 -1
  12. package/dist/components/Dashboard/DashboardGrid.d.ts +14 -15
  13. package/dist/components/Dashboard/DashboardTile.d.ts +8 -1
  14. package/dist/components/Dashboard/DashboardView.d.ts +22 -23
  15. package/dist/components/Dashboard/TileCard.d.ts +10 -3
  16. package/dist/components/Dashboard/useStuck.d.ts +22 -0
  17. package/dist/components/DocumentCreate/newNotebook.d.ts +9 -5
  18. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +6 -0
  19. package/dist/components/Package/PackageProblems.d.ts +14 -0
  20. package/dist/components/RemoveBadge.d.ts +40 -0
  21. package/dist/components/Report/Report.d.ts +13 -4
  22. package/dist/components/Report/ReportPage.d.ts +60 -0
  23. package/dist/components/Report/layoutRules.d.ts +32 -0
  24. package/dist/components/Report/reportQuery.d.ts +30 -0
  25. package/dist/components/Report/telemetry.d.ts +0 -2
  26. package/dist/components/ReportBuilder/AddTileDialog.d.ts +22 -3
  27. package/dist/components/ReportBuilder/BuilderBar.d.ts +17 -0
  28. package/dist/components/ReportBuilder/BuilderDialogs.d.ts +7 -6
  29. package/dist/components/ReportBuilder/BuilderGrid.d.ts +10 -4
  30. package/dist/components/ReportBuilder/BuilderHeader.d.ts +4 -7
  31. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +88 -0
  32. package/dist/components/ReportBuilder/DrillDialog.d.ts +3 -1
  33. package/dist/components/ReportBuilder/EditorSurface.d.ts +7 -9
  34. package/dist/components/ReportBuilder/FilterDialog.d.ts +3 -1
  35. package/dist/components/ReportBuilder/FilterStrip.d.ts +30 -6
  36. package/dist/components/ReportBuilder/InlineMarkdown.d.ts +4 -4
  37. package/dist/components/ReportBuilder/ReportBuilder.d.ts +49 -12
  38. package/dist/components/ReportBuilder/ReportEditor.d.ts +53 -3
  39. package/dist/components/ReportBuilder/TextTileBody.d.ts +2 -5
  40. package/dist/components/ReportBuilder/TileFrame.d.ts +10 -4
  41. package/dist/components/ReportBuilder/TileMenu.d.ts +19 -11
  42. package/dist/components/ReportBuilder/ViewPicker.d.ts +53 -0
  43. package/dist/components/ReportBuilder/addTileToDocument.d.ts +24 -3
  44. package/dist/components/ReportBuilder/builderControls.d.ts +60 -0
  45. package/dist/components/ReportBuilder/catalog.d.ts +2 -4
  46. package/dist/components/ReportBuilder/inlineEdit.d.ts +9 -10
  47. package/dist/components/ReportBuilder/localGiven.d.ts +12 -0
  48. package/dist/components/ReportBuilder/preview.d.ts +17 -2
  49. package/dist/components/ReportBuilder/readDocument.d.ts +0 -2
  50. package/dist/components/ReportBuilder/readForEditor.d.ts +2 -7
  51. package/dist/components/ReportBuilder/reportTag.d.ts +11 -1
  52. package/dist/components/ReportBuilder/sortable.d.ts +4 -3
  53. package/dist/components/ReportBuilder/testing/inline.d.ts +5 -1
  54. package/dist/components/ReportBuilder/useBuilderSelection.d.ts +0 -1
  55. package/dist/components/ReportBuilder/useBuilderSession.d.ts +21 -12
  56. package/dist/components/ReportBuilder/useDocumentEditor.d.ts +2 -6
  57. package/dist/components/ReportBuilder/useExitGuard.d.ts +3 -0
  58. package/dist/components/ReportBuilder/useFilterForm.d.ts +3 -1
  59. package/dist/components/ReportBuilder/useOpenedDocument.d.ts +0 -4
  60. package/dist/components/ReportBuilder/useReportDraft.d.ts +66 -0
  61. package/dist/components/ReportBuilder/useReportEditor.d.ts +0 -9
  62. package/dist/components/ReportBuilder/useTileEditing.d.ts +6 -3
  63. package/dist/components/ReportBuilder/viewAnnotations.d.ts +9 -0
  64. package/dist/components/ReportBuilder/widthLabel.d.ts +6 -0
  65. package/dist/components/ServerProvider.d.ts +9 -0
  66. package/dist/components/controlTokens.d.ts +45 -0
  67. package/dist/components/drill/markDrillableCells.d.ts +1 -1
  68. package/dist/components/given/FilterButton.d.ts +35 -0
  69. package/dist/components/given/GivensPanel.d.ts +2 -1
  70. package/dist/components/given/filterEditing.d.ts +54 -0
  71. package/dist/components/given/filterSummary.d.ts +9 -0
  72. package/dist/components/given/paramCodec.d.ts +11 -0
  73. package/dist/components/given/required.d.ts +25 -0
  74. package/dist/components/index.d.ts +3 -0
  75. package/dist/components/legacy/index.d.ts +1 -1
  76. package/dist/components/{Report/CellReport.d.ts → legacy/malloynb/CellRunnerView.d.ts} +9 -17
  77. package/dist/components/legacy/{MalloynbCells.d.ts → malloynb/MalloynbCells.d.ts} +3 -3
  78. package/dist/components/legacy/{Notebook.d.ts → malloynb/Notebook.d.ts} +1 -1
  79. package/dist/components/{Notebook → legacy/malloynb}/NotebookCell.d.ts +3 -3
  80. package/dist/components/legacy/malloynb/cellKind.d.ts +5 -0
  81. package/dist/components/{Notebook → legacy/malloynb}/types.d.ts +1 -1
  82. package/dist/components/styles.d.ts +0 -2
  83. package/dist/hooks/useQueryResult.d.ts +7 -0
  84. package/dist/index.cjs.js +16 -19
  85. package/dist/index.es.js +8324 -7769
  86. package/dist/theme/ThemeContext.d.ts +8 -1
  87. package/dist/theme/classes.d.ts +49 -0
  88. package/dist/theme/index.d.ts +2 -0
  89. package/dist/theme/types.d.ts +7 -0
  90. package/dist/theme/ui.d.ts +75 -0
  91. package/dist/{useCompiledDocument-1dgF5CC9.es.js → useCompiledDocument-7j5cBjQd.es.js} +8768 -7912
  92. package/dist/useCompiledDocument-B21sVbb4.cjs.js +141 -0
  93. package/package.json +2 -2
  94. package/src/builder-entry.ts +9 -0
  95. package/src/components/AppDialog.tsx +23 -0
  96. package/src/components/Dashboard/DashboardGrid.tsx +39 -17
  97. package/src/components/Dashboard/DashboardTile.tsx +19 -2
  98. package/src/components/Dashboard/DashboardView.spec.tsx +216 -15
  99. package/src/components/Dashboard/DashboardView.tsx +136 -105
  100. package/src/components/Dashboard/RowsDialog.tsx +1 -2
  101. package/src/components/Dashboard/TileCard.tsx +28 -10
  102. package/src/components/Dashboard/defaultTileSpan.spec.ts +24 -0
  103. package/src/components/Dashboard/useStuck.ts +49 -0
  104. package/src/components/DocumentCreate/newNotebook.spec.ts +8 -6
  105. package/src/components/DocumentCreate/newNotebook.ts +26 -12
  106. package/src/components/DocumentCreate/useDocumentChoices.ts +19 -2
  107. package/src/components/Package/NewDocumentDialog.spec.tsx +76 -59
  108. package/src/components/Package/NewDocumentDialog.tsx +383 -119
  109. package/src/components/Package/Package.artifacts.spec.tsx +1 -1
  110. package/src/components/Package/Package.create.spec.tsx +7 -6
  111. package/src/components/Package/Package.tsx +10 -7
  112. package/src/components/Package/PackageProblems.spec.tsx +41 -0
  113. package/src/components/Package/PackageProblems.tsx +95 -0
  114. package/src/components/Prose.tsx +12 -7
  115. package/src/components/RemoveBadge.tsx +94 -0
  116. package/src/components/RenderedResult/RenderedResult.tsx +5 -9
  117. package/src/components/RenderedResult/ResultPanel.tsx +59 -3
  118. package/src/components/Report/Report.spec.tsx +50 -32
  119. package/src/components/Report/Report.telemetry.spec.tsx +0 -45
  120. package/src/components/Report/Report.tsx +45 -77
  121. package/src/components/Report/ReportPage.tsx +168 -0
  122. package/src/components/Report/layoutRules.spec.ts +35 -0
  123. package/src/components/Report/layoutRules.ts +55 -0
  124. package/src/components/Report/reportQuery.ts +53 -0
  125. package/src/components/Report/telemetry.ts +0 -2
  126. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +76 -41
  127. package/src/components/ReportBuilder/AddTileDialog.tsx +368 -133
  128. package/src/components/ReportBuilder/BuilderBar.tsx +599 -0
  129. package/src/components/ReportBuilder/BuilderDialogs.tsx +30 -39
  130. package/src/components/ReportBuilder/BuilderGrid.tsx +43 -31
  131. package/src/components/ReportBuilder/BuilderHeader.tsx +63 -75
  132. package/src/components/ReportBuilder/BuilderToolbar.tsx +95 -9
  133. package/src/components/ReportBuilder/DrillDialog.tsx +240 -128
  134. package/src/components/ReportBuilder/EditorSurface.tsx +345 -69
  135. package/src/components/ReportBuilder/FilterDialog.tsx +516 -166
  136. package/src/components/ReportBuilder/FilterStrip.tsx +129 -150
  137. package/src/components/ReportBuilder/InlineMarkdown.tsx +71 -45
  138. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +35 -40
  139. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +491 -0
  140. package/src/components/ReportBuilder/ReportBuilder.exit.spec.tsx +2 -4
  141. package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +13 -16
  142. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +27 -118
  143. package/src/components/ReportBuilder/ReportBuilder.openDraft.spec.tsx +12 -5
  144. package/src/components/ReportBuilder/ReportBuilder.sources.spec.tsx +2 -10
  145. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +41 -36
  146. package/src/components/ReportBuilder/ReportBuilder.textTiles.spec.tsx +22 -15
  147. package/src/components/ReportBuilder/ReportBuilder.tsx +292 -116
  148. package/src/components/ReportBuilder/ReportEditor.emptyStart.spec.tsx +2 -1
  149. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +312 -0
  150. package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +26 -75
  151. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +6 -2
  152. package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -2
  153. package/src/components/ReportBuilder/ReportEditor.spec.tsx +2 -4
  154. package/src/components/ReportBuilder/ReportEditor.textSource.spec.tsx +93 -13
  155. package/src/components/ReportBuilder/ReportEditor.tsx +104 -14
  156. package/src/components/ReportBuilder/TextTileBody.tsx +6 -7
  157. package/src/components/ReportBuilder/TileFrame.tsx +212 -75
  158. package/src/components/ReportBuilder/TileMenu.tsx +248 -142
  159. package/src/components/ReportBuilder/ViewPicker.tsx +349 -0
  160. package/src/components/ReportBuilder/addTile.compile.spec.ts +1 -1
  161. package/src/components/ReportBuilder/addTileToDocument.spec.ts +102 -3
  162. package/src/components/ReportBuilder/addTileToDocument.ts +122 -25
  163. package/src/components/ReportBuilder/builderControls.ts +164 -0
  164. package/src/components/ReportBuilder/builderReport.ts +1 -2
  165. package/src/components/ReportBuilder/catalog.ts +10 -26
  166. package/src/components/ReportBuilder/inlineEdit.tsx +22 -54
  167. package/src/components/ReportBuilder/localGiven.ts +56 -0
  168. package/src/components/ReportBuilder/newDashboard.spec.ts +2 -3
  169. package/src/components/ReportBuilder/preview.spec.ts +125 -5
  170. package/src/components/ReportBuilder/preview.ts +60 -44
  171. package/src/components/ReportBuilder/readDocument.spec.ts +16 -22
  172. package/src/components/ReportBuilder/readDocument.ts +14 -11
  173. package/src/components/ReportBuilder/readForEditor.spec.ts +12 -41
  174. package/src/components/ReportBuilder/readForEditor.ts +4 -26
  175. package/src/components/ReportBuilder/reportTag.ts +28 -7
  176. package/src/components/ReportBuilder/sortable.tsx +15 -7
  177. package/src/components/ReportBuilder/spliceDocument.imports.spec.ts +1 -1
  178. package/src/components/ReportBuilder/tagParse.spec.ts +0 -40
  179. package/src/components/ReportBuilder/testing/inline.ts +25 -5
  180. package/src/components/ReportBuilder/testing/reportLayoutParity.json +13 -8
  181. package/src/components/ReportBuilder/textTiles.spec.ts +7 -6
  182. package/src/components/ReportBuilder/useBuilderSelection.ts +35 -0
  183. package/src/components/ReportBuilder/useBuilderSession.spec.ts +2 -2
  184. package/src/components/ReportBuilder/useBuilderSession.ts +21 -13
  185. package/src/components/ReportBuilder/useDocumentEditor.spec.ts +0 -58
  186. package/src/components/ReportBuilder/useDocumentEditor.ts +3 -16
  187. package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +26 -0
  188. package/src/components/ReportBuilder/useEditorCatalog.ts +7 -2
  189. package/src/components/ReportBuilder/useExitGuard.ts +16 -0
  190. package/src/components/ReportBuilder/useFilterForm.spec.tsx +17 -0
  191. package/src/components/ReportBuilder/useFilterForm.ts +5 -1
  192. package/src/components/ReportBuilder/useOpenedDocument.ts +0 -2
  193. package/src/components/ReportBuilder/useReportDraft.spec.ts +149 -0
  194. package/src/components/ReportBuilder/useReportDraft.ts +292 -0
  195. package/src/components/ReportBuilder/useReportEditor.ts +3 -12
  196. package/src/components/ReportBuilder/useSaveChannel.ts +0 -1
  197. package/src/components/ReportBuilder/useTileEditing.ts +43 -12
  198. package/src/components/ReportBuilder/viewAnnotations.ts +29 -0
  199. package/src/components/ReportBuilder/widthLabel.spec.ts +25 -0
  200. package/src/components/ReportBuilder/widthLabel.ts +26 -0
  201. package/src/components/ServerProvider.tsx +11 -0
  202. package/src/components/controlTokens.ts +47 -0
  203. package/src/components/drill/markDrillableCells.ts +2 -1
  204. package/src/components/given/FilterButton.spec.tsx +143 -0
  205. package/src/components/given/FilterButton.tsx +478 -0
  206. package/src/components/given/GivenInput.spec.tsx +47 -0
  207. package/src/components/given/GivenInput.tsx +20 -2
  208. package/src/components/given/GivensPanel.spec.tsx +11 -3
  209. package/src/components/given/GivensPanel.tsx +45 -44
  210. package/src/components/given/filterEditing.ts +60 -0
  211. package/src/components/given/filterSummary.spec.ts +108 -0
  212. package/src/components/given/filterSummary.ts +109 -0
  213. package/src/components/given/paramCodec.ts +1 -1
  214. package/src/components/given/required.spec.ts +60 -0
  215. package/src/components/given/required.ts +78 -0
  216. package/src/components/index.ts +9 -0
  217. package/src/components/legacy/Dashboard.spec.tsx +3 -1
  218. package/src/components/legacy/index.ts +1 -1
  219. package/src/components/{Report/CellReport.spec.tsx → legacy/malloynb/CellRunnerView.spec.tsx} +53 -57
  220. package/src/components/{Report/CellReport.tsx → legacy/malloynb/CellRunnerView.tsx} +122 -136
  221. package/src/components/legacy/{MalloynbCells.tsx → malloynb/MalloynbCells.tsx} +6 -6
  222. package/src/components/legacy/{Notebook.layout.spec.tsx → malloynb/Notebook.layout.spec.tsx} +16 -7
  223. package/src/components/legacy/malloynb/Notebook.served.spec.tsx +84 -0
  224. package/src/components/legacy/{Notebook.spec.tsx → malloynb/Notebook.spec.tsx} +5 -3
  225. package/src/components/legacy/{Notebook.tsx → malloynb/Notebook.tsx} +9 -7
  226. package/src/components/{Notebook → legacy/malloynb}/NotebookCell.tsx +70 -150
  227. package/src/components/legacy/malloynb/cellKind.spec.ts +33 -0
  228. package/src/components/legacy/malloynb/cellKind.ts +24 -0
  229. package/src/components/{Notebook → legacy/malloynb}/types.ts +1 -1
  230. package/src/components/styles.ts +0 -18
  231. package/src/hooks/useGivensState.ts +7 -3
  232. package/src/hooks/useQueryResult.placeholder.spec.ts +44 -0
  233. package/src/hooks/useQueryResult.ts +26 -1
  234. package/src/theme/ThemeContext.tsx +21 -1
  235. package/src/theme/classes.ts +52 -0
  236. package/src/theme/index.ts +8 -0
  237. package/src/theme/resolveTheme.ts +3 -0
  238. package/src/theme/types.ts +7 -0
  239. package/src/theme/ui.spec.tsx +91 -0
  240. package/src/theme/ui.ts +115 -0
  241. package/dist/RenderedResult-Bw7EQc42.cjs.js +0 -153
  242. package/dist/ServerProvider-B0dUY8be.cjs.js +0 -1
  243. package/dist/components/Notebook/cellKind.d.ts +0 -20
  244. package/dist/components/Report/LinearReport.d.ts +0 -18
  245. package/dist/components/ReportBuilder/SourceViewPicker.d.ts +0 -9
  246. package/dist/components/ReportBuilder/legacyNotebook.d.ts +0 -73
  247. package/dist/components/ReportBuilder/useConversionConfirm.d.ts +0 -20
  248. package/dist/useCompiledDocument-BKyRnXmA.cjs.js +0 -141
  249. package/src/components/Notebook/cellKind.spec.ts +0 -199
  250. package/src/components/Notebook/cellKind.ts +0 -74
  251. package/src/components/Report/LinearReport.tsx +0 -71
  252. package/src/components/ReportBuilder/SourceViewPicker.tsx +0 -122
  253. package/src/components/ReportBuilder/legacyNotebook.chart.spec.ts +0 -77
  254. package/src/components/ReportBuilder/legacyNotebook.convert.spec.ts +0 -626
  255. package/src/components/ReportBuilder/legacyNotebook.read.spec.ts +0 -338
  256. package/src/components/ReportBuilder/legacyNotebook.ts +0 -1122
  257. package/src/components/ReportBuilder/useConversionConfirm.ts +0 -55
  258. package/src/components/legacy/Notebook.served.spec.tsx +0 -183
  259. /package/dist/components/{Notebook → legacy/malloynb}/runPlan.d.ts +0 -0
  260. /package/src/components/{Notebook → legacy/malloynb}/runPlan.spec.ts +0 -0
  261. /package/src/components/{Notebook → legacy/malloynb}/runPlan.ts +0 -0
@@ -1,199 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import { describe, expect, it } from "bun:test";
5
- import {
6
- cellCaption,
7
- cellRuns,
8
- definitionSummary,
9
- stripProse,
10
- } from "./cellKind";
11
-
12
- describe("cellRuns", () => {
13
- // DEPRECATED FEATURE COVERAGE — delete together with
14
- // `.malloynb` notebooks (see RELEASE_NOTES deprecations).
15
- describe("deprecated: .malloynb notebooks", () => {
16
- it("runs a .malloynb code cell and skips its markdown", () => {
17
- expect(cellRuns({ type: "code" })).toBe(true);
18
- expect(cellRuns({ type: "markdown" })).toBe(false);
19
- });
20
- });
21
-
22
- it("runs only a query cell of a served notebook", () => {
23
- expect(cellRuns({ type: "code", kind: "query" })).toBe(true);
24
- expect(cellRuns({ type: "code", kind: "definition" })).toBe(false);
25
- expect(cellRuns({ type: "markdown", kind: "markdown" })).toBe(false);
26
- });
27
- });
28
-
29
- describe("cellCaption", () => {
30
- it("prefers the caption the server sent", () => {
31
- expect(
32
- cellCaption({ text: '#" From the text\nrun: q', caption: "Served" }),
33
- ).toBe("Served");
34
- });
35
-
36
- it('falls back to the #" lines of the tag block above the run', () => {
37
- expect(
38
- cellCaption({
39
- text: '#" Revenue by month\n# bar_chart\nrun: sales -> by_month',
40
- }),
41
- ).toBe("Revenue by month");
42
- expect(
43
- cellCaption({ text: '# bar_chart\n#" First\n#" second\nrun: q' }),
44
- ).toBe("First second");
45
- });
46
-
47
- it('ignores a #" past the tag block, and reads past a // comment', () => {
48
- expect(
49
- cellCaption({ text: 'run: q -> {\n#" not a caption\n select: a }' }),
50
- ).toBeUndefined();
51
- expect(cellCaption({ text: '// why\n#" Shown\nrun: q' })).toBe("Shown");
52
- });
53
-
54
- it("does not read a caption out of the prose lines the server named", () => {
55
- expect(
56
- cellCaption({
57
- text: '#|(markdown)\n#" not a caption\n|#\nrun: q',
58
- proseLines: [[0, 2]],
59
- }),
60
- ).toBeUndefined();
61
- });
62
-
63
- it("is undefined when there is no caption", () => {
64
- expect(cellCaption({ text: "# bar_chart\nrun: q" })).toBeUndefined();
65
- expect(cellCaption({ text: "" })).toBeUndefined();
66
- });
67
- });
68
-
69
- describe("definitionSummary", () => {
70
- it("names the statement kind and what it defines", () => {
71
- expect(
72
- definitionSummary({ text: "source: sales is orders extend {\n}" }),
73
- ).toBe("source: sales");
74
- expect(definitionSummary({ text: "query: top is sales -> q" })).toBe(
75
- "query: top",
76
- );
77
- expect(
78
- definitionSummary({
79
- text: '# label="Region"\ngiven: REGION :: filter<string>',
80
- }),
81
- ).toBe("given: REGION");
82
- });
83
-
84
- it("says only import for an import, whatever it brings in", () => {
85
- expect(
86
- definitionSummary({ text: 'import { a, b } from "./m.malloy"' }),
87
- ).toBe("import");
88
- });
89
-
90
- it("skips the prose lines the server named", () => {
91
- expect(
92
- definitionSummary({
93
- text: "#|(markdown)\nThe orders source.\n|#\nsource: o is t",
94
- proseLines: [[0, 2]],
95
- }),
96
- ).toBe("source: o");
97
- expect(
98
- definitionSummary({
99
- text: "#|(markdown)\nsource: not this\n|#\nsource: o is t",
100
- proseLines: [[0, 2]],
101
- }),
102
- ).toBe("source: o");
103
- });
104
-
105
- it("falls back to the first line for a statement it does not recognize", () => {
106
- expect(definitionSummary({ text: "export { a }" })).toBe("export");
107
- expect(definitionSummary({ text: "// note\nmystery thing" })).toBe(
108
- "mystery thing",
109
- );
110
- });
111
- });
112
-
113
- describe("stripProse", () => {
114
- it("removes exactly the lines the server named, and nothing else", () => {
115
- expect(
116
- stripProse({
117
- text: '#|(markdown)\nBody\n|#\n#" Caption\n#(markdown) note\n# bar_chart\nrun: q',
118
- proseLines: [
119
- [0, 2],
120
- [4, 4],
121
- ],
122
- }),
123
- ).toBe('#" Caption\n# bar_chart\nrun: q');
124
- });
125
-
126
- it("keeps a ## line the server did not name", () => {
127
- expect(
128
- stripProse({ text: "## kept\nrun: q", proseLines: [[1, 1]] }),
129
- ).toBe("## kept");
130
- });
131
-
132
- it("does not guess at prose in a nested note the server left out", () => {
133
- expect(
134
- stripProse({
135
- text: "#(markdown) lead\nsource: s is a extend {\n #(markdown) about v\n view: v is x\n}",
136
- proseLines: [[0, 0]],
137
- }),
138
- ).toBe(
139
- "source: s is a extend {\n #(markdown) about v\n view: v is x\n}",
140
- );
141
- });
142
-
143
- it("without ranges, drops the ## lines as the released viewer did", () => {
144
- expect(
145
- stripProse({ text: "## title\n ## indented\nrun: q\n#(markdown) x" }),
146
- ).toBe("run: q\n#(markdown) x");
147
- });
148
-
149
- // DEPRECATED FEATURE COVERAGE — delete together with
150
- // `.malloynb` notebooks (see RELEASE_NOTES deprecations).
151
- describe("deprecated: .malloynb notebooks", () => {
152
- it("without ranges, drops a .malloynb ##! line exactly as the released code did", () => {
153
- expect(
154
- stripProse({ text: "##! experimental.parameters\nrun: q" }),
155
- ).toBe("run: q");
156
- });
157
- });
158
-
159
- it("without ranges, leaves (markdown) lines alone", () => {
160
- const cell = '#(markdown) note\n#|(markdown)\nbody\n|#\n#" c\nrun: q';
161
- expect(stripProse({ text: cell })).toBe(cell);
162
- });
163
- });
164
-
165
- describe("a served cell trusts only the server", () => {
166
- it("keeps a ## line inside a multi-line string when it has no prose", () => {
167
- const text = 'run: duckdb.sql("""\n## not prose\nselect 1""")';
168
- expect(stripProse({ text, proseLines: [], codeLine: 0 })).toBe(text);
169
- });
170
-
171
- it("shows no caption the server did not send", () => {
172
- for (const text of [
173
- '#"x\nrun: q',
174
- '#"\u00a0nbsp\nrun: q',
175
- '#|\nlabel="a"\n#" hidden\n|#\nrun: q',
176
- ]) {
177
- expect(cellCaption({ text, proseLines: [], codeLine: 0 })).toBe(
178
- undefined,
179
- );
180
- }
181
- });
182
-
183
- it("labels a definition by the line the server points at", () => {
184
- expect(
185
- definitionSummary({
186
- text: '#|"\nRegion to filter by\n|#\ngiven: REGION :: string is "x"',
187
- proseLines: [],
188
- codeLine: 3,
189
- }),
190
- ).toBe("given: REGION");
191
- expect(
192
- definitionSummary({
193
- text: '#|\nlabel="Orders"\n|#\nsource: s is a',
194
- proseLines: [],
195
- codeLine: 3,
196
- }),
197
- ).toBe("source: s");
198
- });
199
- });
@@ -1,74 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import type { NotebookCell } from "../../client";
5
-
6
- /**
7
- * Whether the viewer sends a cell to the server to run. A served notebook's
8
- * definition cell is `type: code` too, so `type` alone would execute it.
9
- */
10
- export function cellRuns(cell: Pick<NotebookCell, "type" | "kind">): boolean {
11
- return cell.kind ? cell.kind === "query" : cell.type === "code";
12
- }
13
-
14
- type CellLines = Pick<NotebookCell, "text" | "proseLines" | "codeLine">;
15
-
16
- /** Only a served `.malloy` cell carries `proseLines`, `[]` included; a `.malloynb` or an older server sends none. */
17
- const isServed = (cell: Pick<NotebookCell, "proseLines">): boolean =>
18
- cell.proseLines !== undefined;
19
-
20
- /** The lines of a cell the server did not name as prose; all of them when it named none. */
21
- function codeLines({ text, proseLines }: CellLines): string[] {
22
- return (text ?? "")
23
- .split("\n")
24
- .filter(
25
- (_, index) =>
26
- !proseLines?.some(([start, end]) => index >= start && index <= end),
27
- );
28
- }
29
-
30
- /**
31
- * A query cell's caption. A served cell's is the server's alone, absent meaning none; on an
32
- * unserved cell (a `.malloynb`, an older server) it is the `#"` lines in the tag block above its `run:`.
33
- */
34
- export function cellCaption(
35
- cell: Pick<NotebookCell, "text" | "caption" | "proseLines" | "codeLine">,
36
- ): string | undefined {
37
- if (isServed(cell)) return cell.caption;
38
- if (cell.caption !== undefined) return cell.caption;
39
- const lines: string[] = [];
40
- for (const raw of codeLines(cell)) {
41
- const line = raw.trim();
42
- if (line.startsWith("//")) continue;
43
- if (!line.startsWith("#")) break;
44
- if (line.startsWith('#"')) lines.push(line.slice(2).trim());
45
- }
46
- return lines.length > 0 ? lines.join(" ") : undefined;
47
- }
48
-
49
- /**
50
- * A cell's code without its prose, which renders separately. A served cell loses exactly the
51
- * lines the server named; an unserved one (a `.malloynb`, an older server) loses its `##` lines.
52
- */
53
- export function stripProse(cell: CellLines): string {
54
- if (isServed(cell)) return codeLines(cell).join("\n");
55
- return cell.text
56
- .split("\n")
57
- .filter((line) => !line.trimStart().startsWith("##"))
58
- .join("\n");
59
- }
60
-
61
- /** One-line label for a folded definition cell: its statement kind and name. */
62
- export function definitionSummary(cell: CellLines): string {
63
- const line =
64
- cell.codeLine !== undefined
65
- ? (cell.text.split("\n")[cell.codeLine] ?? "").trim()
66
- : (codeLines(cell)
67
- .map((raw) => raw.trim())
68
- .find((l) => l && !l.startsWith("#") && !l.startsWith("//")) ??
69
- "");
70
- const named = /^(source|query|given|type):?\s+([A-Za-z_]\w*)/.exec(line);
71
- if (named) return `${named[1]}: ${named[2]}`;
72
- const keyword = /^(import|export)\b/.exec(line);
73
- return keyword ? keyword[1] : line;
74
- }
@@ -1,71 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import { Box } from "@mui/material";
5
- import type { DashboardManifest } from "../../client";
6
- import { DashboardProse, DashboardView } from "../Dashboard/DashboardView";
7
- import type { DrillNavigation } from "../drill";
8
- import { CleanNotebookContainer, CleanNotebookSection } from "../styles";
9
-
10
- /**
11
- * A linear report written as tiles: a one-column grid, its prose drawn bare
12
- * above the tiles and its controls as a panel.
13
- */
14
- export function LinearReport({
15
- manifest,
16
- environmentName,
17
- packageName,
18
- versionId,
19
- documentName,
20
- givens,
21
- onGivensChange,
22
- onDrillNavigate,
23
- maxResultSize,
24
- }: {
25
- /** A report manifest, or the tile layout a deprecated notebook read carries. */
26
- manifest: DashboardManifest;
27
- environmentName: string;
28
- packageName: string;
29
- versionId: string | undefined;
30
- documentName: string;
31
- givens?: Record<string, string>;
32
- onGivensChange?: (
33
- givens: Record<string, string>,
34
- managed: readonly string[],
35
- ) => void;
36
- onDrillNavigate?: (target: DrillNavigation, event?: MouseEvent) => void;
37
- maxResultSize?: number;
38
- }) {
39
- const { title, description } = manifest;
40
- return (
41
- <CleanNotebookContainer>
42
- <CleanNotebookSection>
43
- {/* chrome="none" drops the view's own header, so the prose is drawn here. */}
44
- {(title || description) && (
45
- <Box sx={{ mb: 2 }}>
46
- <DashboardProse
47
- // A linear report's text tiles have no card; its description matches them.
48
- chrome="none"
49
- title={title ?? ""}
50
- {...(description ? { description } : {})}
51
- />
52
- </Box>
53
- )}
54
- <DashboardView
55
- manifest={manifest}
56
- environmentName={environmentName}
57
- packageName={packageName}
58
- versionId={versionId}
59
- documentName={documentName}
60
- givens={givens}
61
- onGivensChange={onGivensChange}
62
- onNavigate={onDrillNavigate}
63
- maxResultSize={maxResultSize}
64
- chrome="none"
65
- // A linear report's control panel, not a grid's bar.
66
- controlsLayout="panel"
67
- />
68
- </CleanNotebookSection>
69
- </CleanNotebookContainer>
70
- );
71
- }
@@ -1,122 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import {
5
- Box,
6
- Chip,
7
- List,
8
- ListItemButton,
9
- ListItemText,
10
- MenuItem,
11
- TextField,
12
- Typography,
13
- } from "@mui/material";
14
- import { usePublisherTheme } from "../../theme/ThemeContext";
15
- import type { CatalogSource } from "./catalog";
16
-
17
- /** A source select and the list of its views, which is what both "add a tile" and "add a query" pick from. */
18
- export function SourceViewPicker({
19
- sources,
20
- source,
21
- view,
22
- onSource,
23
- onView,
24
- }: {
25
- sources: CatalogSource[];
26
- source: string;
27
- view: string;
28
- onSource: (name: string) => void;
29
- onView: (name: string) => void;
30
- }) {
31
- const { theme } = usePublisherTheme();
32
- const picked = sources.find((s) => s.name === source);
33
- return (
34
- <>
35
- <TextField
36
- select
37
- size="small"
38
- label="Source"
39
- value={source}
40
- onChange={(event) => onSource(event.target.value)}
41
- inputProps={{ "aria-label": "Source" }}
42
- >
43
- {sources.map((s) => (
44
- <MenuItem
45
- key={s.name}
46
- value={s.name}
47
- disabled={s.views.length === 0}
48
- >
49
- {s.name}
50
- {s.views.length === 0 && (
51
- <Typography
52
- component="span"
53
- variant="caption"
54
- sx={{ ml: 1 }}
55
- >
56
- declares no views
57
- </Typography>
58
- )}
59
- {s.description && (
60
- <Typography
61
- component="span"
62
- variant="caption"
63
- sx={{ ml: 1, opacity: 0.6 }}
64
- >
65
- {s.description}
66
- </Typography>
67
- )}
68
- </MenuItem>
69
- ))}
70
- </TextField>
71
- <Box>
72
- <Typography variant="subtitle2" sx={{ mb: 0.5 }}>
73
- View
74
- </Typography>
75
- <List
76
- dense
77
- disablePadding
78
- aria-label="Views"
79
- sx={{
80
- maxHeight: "min(280px, 30vh)",
81
- overflowY: "auto",
82
- border: theme.border,
83
- borderRadius: 1,
84
- }}
85
- >
86
- {(picked?.views ?? []).map((v) => (
87
- <ListItemButton
88
- key={v.name}
89
- selected={view === v.name}
90
- onClick={() => onView(v.name)}
91
- aria-label={`View ${v.name}`}
92
- >
93
- <ListItemText
94
- primary={v.name}
95
- secondary={v.description}
96
- primaryTypographyProps={{
97
- fontFamily: "ui-monospace, monospace",
98
- fontSize: 13,
99
- }}
100
- />
101
- {v.chart && (
102
- <Chip
103
- size="small"
104
- variant="outlined"
105
- label={v.chart.replace(/_chart$/, "")}
106
- />
107
- )}
108
- </ListItemButton>
109
- ))}
110
- {picked && picked.views.length === 0 && (
111
- <Typography
112
- variant="body2"
113
- sx={{ p: 1.5, color: theme.tileTitle }}
114
- >
115
- This source declares no views.
116
- </Typography>
117
- )}
118
- </List>
119
- </Box>
120
- </>
121
- );
122
- }
@@ -1,77 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import { describe, expect, it } from "bun:test";
5
- import {
6
- notebookSourceRefused,
7
- readNotebookSource,
8
- type NotebookSource,
9
- } from "./legacyNotebook";
10
-
11
- const HEAD =
12
- '## artifact { layout=linear }\nsource: a is duckdb.sql("select 1 as x")\n\n';
13
-
14
- async function read(text: string): Promise<NotebookSource> {
15
- const result = await readNotebookSource(text);
16
- if (notebookSourceRefused(result)) throw new Error(result.refused);
17
- return result.source;
18
- }
19
-
20
- describe("readNotebookSource: chart lines", () => {
21
- it("records the recognized chart line's span and where a new one goes", async () => {
22
- const cell = `#" Caption\n# -bar_chart line_chart\n// c\nrun: a -> { select: x }\n`;
23
- const source = await read(HEAD + cell);
24
- const chart = source.cells[1].chart!;
25
- expect(chart.lines.map((l) => l.text)).toEqual([
26
- "# -bar_chart line_chart",
27
- ]);
28
- const [line] = chart.lines;
29
- expect(source.text.slice(line.span.start, line.span.end)).toBe(
30
- "# -bar_chart line_chart\n",
31
- );
32
- expect(source.text.slice(chart.insertAt)).toBe(
33
- "run: a -> { select: x }\n",
34
- );
35
- expect(chart.unmodelled).toBeUndefined();
36
- });
37
-
38
- it("places a new line at the run when there are no tags, and reads CRLF", async () => {
39
- const source = await read(
40
- (HEAD + "run: a -> { select: x }\n").replace(/\n/g, "\r\n"),
41
- );
42
- const chart = source.cells[1].chart!;
43
- expect(chart.lines).toEqual([]);
44
- expect(source.text.slice(chart.insertAt)).toBe(
45
- "run: a -> { select: x }\r\n",
46
- );
47
- });
48
-
49
- it("leaves a tag with properties, or a label, as unmodelled and never as a chart line", async () => {
50
- for (const line of [
51
- "# bar_chart { size=spark }",
52
- '# line_chart label="Revenue"',
53
- "# viz=line",
54
- ]) {
55
- const source = await read(`${HEAD}${line}\nrun: a -> { select: x }\n`);
56
- const chart = source.cells[1].chart!;
57
- expect(chart.lines).toEqual([]);
58
- expect(chart.unmodelled).toBe(line);
59
- }
60
- });
61
-
62
- it("ignores chart words in captions and keeps definitions free of chart state", async () => {
63
- const source = await read(
64
- `${HEAD}#" The bar_chart story\nrun: a -> { select: x }\n`,
65
- );
66
- expect(source.cells[1].chart!.lines).toEqual([]);
67
- expect(source.cells[1].chart!.unmodelled).toBeUndefined();
68
- expect(source.cells[0].chart).toBeUndefined();
69
- });
70
-
71
- it("does not take a word inside a quoted tag value for a chart line", async () => {
72
- const source = await read(
73
- `${HEAD}# label="Sales viz"\nrun: a -> { select: x }\n`,
74
- );
75
- expect(source.cells[1].chart!.unmodelled).toBeUndefined();
76
- });
77
- });