@malloy-publisher/sdk 0.2.7 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +180 -204
  2. package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +134 -0
  3. package/dist/DocumentStorageProvider-tGvodI8f.es.js +24268 -0
  4. package/dist/RenderedResult-CPi6uQWq.cjs.js +115 -0
  5. package/dist/RenderedResult-mDE-4u8S.es.js +542 -0
  6. package/dist/{ServerProvider-xXW1HJOJ.cjs.js → ServerProvider-CH71GsoL.cjs.js} +1 -1
  7. package/dist/{ServerProvider-ksC5Su_x.es.js → ServerProvider-X2Ma0HRs.es.js} +324 -359
  8. package/dist/builder/index.cjs.js +105 -0
  9. package/dist/builder/index.d.ts +2 -0
  10. package/dist/builder/index.es.js +9561 -0
  11. package/dist/builder-entry.d.ts +8 -0
  12. package/dist/client/api.d.ts +13 -1
  13. package/dist/client/index.cjs.js +1 -1
  14. package/dist/client/index.es.js +1 -1
  15. package/dist/components/ApiErrorDisplay.d.ts +1 -2
  16. package/dist/components/Dashboard/Dashboard.d.ts +23 -16
  17. package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
  18. package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
  19. package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
  20. package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
  21. package/dist/components/Dashboard/TileCard.d.ts +44 -0
  22. package/dist/components/Dashboard/index.d.ts +2 -0
  23. package/dist/components/Dashboard/promoteMeasureRow.d.ts +40 -0
  24. package/dist/components/Dashboard/telemetry.d.ts +43 -0
  25. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
  26. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +29 -0
  27. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +112 -0
  28. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +32 -0
  29. package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
  30. package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
  31. package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
  32. package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
  33. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
  34. package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
  35. package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
  36. package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
  37. package/dist/components/DashboardBuilder/controls.d.ts +157 -0
  38. package/dist/components/DashboardBuilder/diff.d.ts +35 -0
  39. package/dist/components/DashboardBuilder/document.d.ts +218 -0
  40. package/dist/components/DashboardBuilder/layout.d.ts +71 -0
  41. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
  42. package/dist/components/DashboardBuilder/preview.d.ts +60 -0
  43. package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
  44. package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
  45. package/dist/components/DashboardBuilder/spliceDocument.d.ts +44 -0
  46. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
  47. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
  48. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
  49. package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
  50. package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
  51. package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
  52. package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
  53. package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +14 -0
  54. package/dist/components/DocumentStorage/DocumentStorage.d.ts +58 -0
  55. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +25 -0
  56. package/dist/components/DocumentStorage/index.d.ts +3 -0
  57. package/dist/components/FloatingIconButton.d.ts +16 -0
  58. package/dist/components/Model/index.d.ts +0 -1
  59. package/dist/components/Prose.d.ts +46 -0
  60. package/dist/components/RenderedResult/RenderedResult.d.ts +12 -0
  61. package/dist/components/RenderedResult/ResultContainer.d.ts +7 -1
  62. package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
  63. package/dist/components/RenderedResult/index.d.ts +2 -0
  64. package/dist/components/RenderedResult/resultSizing.d.ts +183 -0
  65. package/dist/components/drill/index.d.ts +2 -1
  66. package/dist/components/drill/resolveDrill.d.ts +22 -0
  67. package/dist/components/drill/useDrill.d.ts +11 -2
  68. package/dist/components/drill/useDrillSelf.d.ts +46 -0
  69. package/dist/components/given/filterValue.d.ts +63 -0
  70. package/dist/components/given/index.d.ts +1 -0
  71. package/dist/components/given/useGivenUrlParams.d.ts +39 -0
  72. package/dist/components/index.d.ts +3 -3
  73. package/dist/components/styles.d.ts +3 -7
  74. package/dist/core-8NVBCLZh.cjs.js +148 -0
  75. package/dist/{core-BY7vB5gN.es.js → core-B8oMW4sm.es.js} +3540 -2335
  76. package/dist/hooks/index.d.ts +3 -1
  77. package/dist/hooks/useDocumentControls.d.ts +70 -0
  78. package/dist/hooks/useQueryResult.d.ts +40 -0
  79. package/dist/hooks/useSuggestOptions.d.ts +28 -12
  80. package/dist/index.cjs.js +34 -1
  81. package/dist/index.es.js +21487 -79
  82. package/dist/sdk.css +1 -1
  83. package/dist/styles.css +0 -1
  84. package/dist/utils/malloyLiteral.d.ts +11 -0
  85. package/package.json +25 -14
  86. package/src/builder-entry.ts +55 -0
  87. package/src/components/ApiErrorDisplay.tsx +1 -1
  88. package/src/components/Connections/EditConnectionDialog.tsx +96 -86
  89. package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
  90. package/src/components/Dashboard/Dashboard.tsx +184 -229
  91. package/src/components/Dashboard/DashboardGrid.tsx +124 -0
  92. package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
  93. package/src/components/Dashboard/DashboardTile.tsx +67 -101
  94. package/src/components/Dashboard/ExploreDialog.tsx +84 -0
  95. package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
  96. package/src/components/Dashboard/RowsDialog.tsx +234 -0
  97. package/src/components/Dashboard/TileCard.tsx +120 -0
  98. package/src/components/Dashboard/index.ts +2 -0
  99. package/src/components/Dashboard/promoteMeasureRow.spec.ts +207 -0
  100. package/src/components/Dashboard/promoteMeasureRow.ts +160 -0
  101. package/src/components/Dashboard/telemetry.ts +44 -0
  102. package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
  103. package/src/components/DashboardBuilder/AddTileDialog.tsx +249 -0
  104. package/src/components/DashboardBuilder/BuilderToolbar.tsx +270 -0
  105. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +858 -0
  106. package/src/components/DashboardBuilder/DashboardBuilder.tsx +653 -0
  107. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +211 -0
  108. package/src/components/DashboardBuilder/DashboardEditor.tsx +493 -0
  109. package/src/components/DashboardBuilder/DiffDialog.tsx +129 -0
  110. package/src/components/DashboardBuilder/DrillDialog.tsx +281 -0
  111. package/src/components/DashboardBuilder/FilterDialog.tsx +581 -0
  112. package/src/components/DashboardBuilder/FilterStrip.tsx +125 -0
  113. package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
  114. package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
  115. package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
  116. package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
  117. package/src/components/DashboardBuilder/catalog.ts +225 -0
  118. package/src/components/DashboardBuilder/controls.spec.ts +243 -0
  119. package/src/components/DashboardBuilder/controls.ts +398 -0
  120. package/src/components/DashboardBuilder/diff.spec.ts +44 -0
  121. package/src/components/DashboardBuilder/diff.ts +93 -0
  122. package/src/components/DashboardBuilder/document.ts +209 -0
  123. package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
  124. package/src/components/DashboardBuilder/layout.ts +143 -0
  125. package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
  126. package/src/components/DashboardBuilder/malloyText.ts +151 -0
  127. package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
  128. package/src/components/DashboardBuilder/preview.spec.ts +149 -0
  129. package/src/components/DashboardBuilder/preview.ts +172 -0
  130. package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
  131. package/src/components/DashboardBuilder/readDocument.ts +467 -0
  132. package/src/components/DashboardBuilder/sortable.tsx +151 -0
  133. package/src/components/DashboardBuilder/spliceDocument.spec.ts +1108 -0
  134. package/src/components/DashboardBuilder/spliceDocument.ts +1098 -0
  135. package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
  136. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
  137. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +255 -0
  138. package/src/components/DashboardBuilder/useDashboardEditor.ts +193 -0
  139. package/src/components/DashboardBuilder/useDraft.ts +43 -0
  140. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
  141. package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
  142. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
  143. package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
  144. package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
  145. package/src/components/DashboardBuilder/useTileResize.ts +110 -0
  146. package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
  147. package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +81 -0
  148. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +105 -0
  149. package/src/components/DocumentStorage/DocumentStorage.ts +73 -0
  150. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +58 -0
  151. package/src/components/DocumentStorage/index.ts +16 -0
  152. package/src/components/Environment/About.tsx +4 -36
  153. package/src/components/FloatingIconButton.tsx +41 -0
  154. package/src/components/Model/Model.tsx +6 -23
  155. package/src/components/Model/ModelCell.tsx +34 -72
  156. package/src/components/Model/index.ts +0 -1
  157. package/src/components/Notebook/Notebook.tsx +27 -156
  158. package/src/components/Notebook/NotebookCell.tsx +37 -191
  159. package/src/components/Prose.spec.tsx +85 -0
  160. package/src/components/Prose.tsx +179 -0
  161. package/src/components/QueryResult/QueryResult.tsx +15 -43
  162. package/src/components/RenderedResult/RenderedResult.tsx +86 -76
  163. package/src/components/RenderedResult/ResultContainer.tsx +25 -36
  164. package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
  165. package/src/components/RenderedResult/ResultPanel.tsx +73 -0
  166. package/src/components/RenderedResult/index.ts +16 -0
  167. package/src/components/RenderedResult/resultSizing.spec.ts +249 -0
  168. package/src/components/RenderedResult/resultSizing.ts +308 -0
  169. package/src/components/ResultsDialog.tsx +2 -1
  170. package/src/components/drill/index.ts +6 -0
  171. package/src/components/drill/resolveDrill.ts +22 -1
  172. package/src/components/drill/useDrill.spec.tsx +94 -0
  173. package/src/components/drill/useDrill.tsx +52 -12
  174. package/src/components/drill/useDrillSelf.spec.tsx +64 -0
  175. package/src/components/drill/useDrillSelf.ts +110 -0
  176. package/src/components/given/GivenInput.spec.tsx +196 -2
  177. package/src/components/given/GivenInput.tsx +300 -25
  178. package/src/components/given/GivensPanel.tsx +1 -1
  179. package/src/components/given/filterValue.spec.ts +112 -0
  180. package/src/components/given/filterValue.ts +188 -0
  181. package/src/components/given/index.ts +4 -0
  182. package/src/components/given/useGivenUrlParams.spec.tsx +74 -0
  183. package/src/components/given/useGivenUrlParams.ts +87 -0
  184. package/src/components/index.ts +11 -3
  185. package/src/components/styles.ts +0 -37
  186. package/src/hooks/index.ts +13 -1
  187. package/src/hooks/useDocumentControls.ts +170 -0
  188. package/src/hooks/useGivensState.spec.ts +158 -0
  189. package/src/hooks/useGivensState.ts +114 -23
  190. package/src/hooks/useQueryResult.ts +82 -0
  191. package/src/hooks/useSuggestOptions.dom.spec.ts +60 -1
  192. package/src/hooks/useSuggestOptions.ts +94 -51
  193. package/src/utils/malloyLiteral.spec.ts +43 -0
  194. package/src/utils/malloyLiteral.ts +76 -0
  195. package/vite.config.ts +5 -1
  196. package/dist/components/AnalyzePackageButton.d.ts +0 -6
  197. package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +0 -9
  198. package/dist/components/Workbook/EditableMalloyCell.d.ts +0 -11
  199. package/dist/components/Workbook/ModelPicker.d.ts +0 -11
  200. package/dist/components/Workbook/MutableCell.d.ts +0 -17
  201. package/dist/components/Workbook/Workbook.d.ts +0 -7
  202. package/dist/components/Workbook/WorkbookList.d.ts +0 -7
  203. package/dist/components/Workbook/WorkbookManager.d.ts +0 -84
  204. package/dist/components/Workbook/WorkbookStorage.d.ts +0 -17
  205. package/dist/components/Workbook/WorkbookStorageProvider.d.ts +0 -12
  206. package/dist/components/Workbook/index.d.ts +0 -7
  207. package/dist/core-CWKmWEg2.cjs.js +0 -148
  208. package/dist/index-B0WyZAUA.es.js +0 -66412
  209. package/dist/index-kxVD1RjY.cjs.js +0 -356
  210. package/dist/markdown-editor.css +0 -341
  211. package/src/components/AnalyzePackageButton.tsx +0 -319
  212. package/src/components/Workbook/BrowserWorkbookStorage.ts +0 -64
  213. package/src/components/Workbook/EditableMalloyCell.tsx +0 -49
  214. package/src/components/Workbook/ModelPicker.tsx +0 -134
  215. package/src/components/Workbook/MutableCell.tsx +0 -458
  216. package/src/components/Workbook/Workbook.tsx +0 -501
  217. package/src/components/Workbook/WorkbookList.tsx +0 -110
  218. package/src/components/Workbook/WorkbookManager.ts +0 -214
  219. package/src/components/Workbook/WorkbookStorage.ts +0 -35
  220. package/src/components/Workbook/WorkbookStorageProvider.tsx +0 -40
  221. package/src/components/Workbook/index.ts +0 -10
@@ -0,0 +1,218 @@
1
+ /**
2
+ * The dashboard builder's working representation of a `dashboards/*.malloy`
3
+ * file.
4
+ *
5
+ * This is an editing PROJECTION, not a complete representation of the file, and
6
+ * the distinction is load-bearing. The builder writes changes by SPLICING the
7
+ * source text — patching the ranges it owns and leaving every other byte alone —
8
+ * so anything this type does not model survives an edit untouched. A `where:` in
9
+ * a source extension, an inline computed dimension, a `#(doc)` tag, a reader's
10
+ * comments: none of them appear below, and none of them are lost.
11
+ *
12
+ * What that buys is the reason the projection exists. A writer that regenerated
13
+ * the whole file would have to model everything or destroy it, which is why the
14
+ * earlier design could only ever have edited files it wrote itself.
15
+ *
16
+ * The document is still what decides whether a file can be opened at all: the
17
+ * reader refuses a file it cannot fully turn into one of these, rather than
18
+ * opening it half-understood. See {@link readDashboardDocument}.
19
+ */
20
+ /** One `import` line. The file needs both forms, and for different reasons. */
21
+ export type DashboardImport =
22
+ /** `import "../givens.malloy"` — the whole file's declarations. */
23
+ {
24
+ kind: "all";
25
+ from: string;
26
+ }
27
+ /**
28
+ * `import { products, regions } from "../storefront.malloy"` — specific
29
+ * names. Not interchangeable with the bare form: a bare import is not
30
+ * transitive, so a dashboard whose control has `suggest { source=products }`
31
+ * must name `products` here or the package load reports an error for every
32
+ * such given.
33
+ */
34
+ | {
35
+ kind: "names";
36
+ names: string[];
37
+ from: string;
38
+ };
39
+ /**
40
+ * A given this dashboard declares itself, rather than taking from the model.
41
+ *
42
+ * This is the CONVENTION for a dashboard the builder edits, not the exception:
43
+ * the builder adds and removes filters, and a filter it can add has to be a
44
+ * declaration in the one file it writes. A given imported from the model is
45
+ * still read and still bindable, but it is the model's, and the builder never
46
+ * edits imports or model files.
47
+ *
48
+ * Measured, and the reason the convention has to be this way round: a local
49
+ * given does NOT drive a model-level `where:` of the same name. Binding is per
50
+ * declaration, not per name, so a dashboard that declares `CATEGORY` and extends
51
+ * a source whose own `where:` reads the model's `CATEGORY` gets a control that
52
+ * moves nothing. The filtering therefore lives on the dashboard's tiles, as
53
+ * {@link DashboardTile.filters} — which is what the builder writes anyway.
54
+ *
55
+ * The fields are the declaration and its control contract, spelled as in the
56
+ * file. A tag this does not model survives an edit like any other unmodelled
57
+ * Malloy, because the writer patches rather than regenerates.
58
+ */
59
+ export interface LocalGiven {
60
+ name: string;
61
+ /** The declared type, spelled as in the file: `filter<string>`, `date`, … */
62
+ type: string;
63
+ /** The default, spelled as in the file: `f'Jeans'`, `@2023-01-01`, … */
64
+ default: string;
65
+ label?: string;
66
+ /** `# description="…"`: helper text under the control. */
67
+ description?: string;
68
+ /** `control=select` / `multiselect`. */
69
+ control?: string;
70
+ /**
71
+ * `suggest { source=products dimension=category }`, or `{ query=… }`: where
72
+ * a picker gets its options. The source or query has to resolve in this file,
73
+ * and the builder does not add imports — so a given it creates suggests over
74
+ * a source the file already reads, or over nothing.
75
+ */
76
+ suggest?: {
77
+ source?: string;
78
+ query?: string;
79
+ dimension: string;
80
+ };
81
+ /** `range_min=` / `range_max=` on a `filter<number>`: a slider's bounds. */
82
+ rangeMin?: number;
83
+ rangeMax?: number;
84
+ }
85
+ /** A `# drill` dimension the dashboard declares in its own source extension. */
86
+ export interface DashboardDrill {
87
+ /** The source this dimension is declared on. */
88
+ source: string;
89
+ /** `dimension: <name> is <expression>`. */
90
+ name: string;
91
+ expression: string;
92
+ /** Dashboard slugs, or the literal `self`. */
93
+ to: string[];
94
+ /** The given a click seeds. Absent means the dimension's own name. */
95
+ given?: string;
96
+ }
97
+ /**
98
+ * Where a tile's view is declared, and therefore what the builder may edit.
99
+ *
100
+ * Three forms, all of them found in dashboards that ship in this repository, and
101
+ * the distinction decides which affordances a tile gets:
102
+ *
103
+ * - `reference` — `view: revenue_trend is sales_by_month` in this file. Fully
104
+ * editable: the layout tags sit above that line and the builder owns them.
105
+ * - `inline` — `view: order_tile is { aggregate: order_count }` in this file.
106
+ * Its tags are editable for the same reason; its QUERY is not, because
107
+ * authoring a query body is a separate feature. The projection holds: the body
108
+ * is never rewritten, so it cannot be damaged.
109
+ * - `inherited` — not declared in this file at all, as in a dashboard whose only
110
+ * tile is `orders -> by_brand` against an imported source. Nothing about it is
111
+ * editable here, because its tags live on the model's own view and the builder
112
+ * does not write model files. Read and shown, not changed.
113
+ */
114
+ export type TileDeclaration = {
115
+ kind: "reference";
116
+ from: string;
117
+ } | {
118
+ kind: "inline";
119
+ } | {
120
+ kind: "inherited";
121
+ };
122
+ /** One tile: a view shown on the page, plus how it is presented. */
123
+ export interface DashboardTile {
124
+ /**
125
+ * The view name. For a tile declared in this file, assigned ONCE when the
126
+ * tile is added and never recomputed — deriving it from position would
127
+ * rename every later tile on a reorder, turning a pure-layout edit into a
128
+ * large diff.
129
+ */
130
+ name: string;
131
+ /**
132
+ * The source it reads, by NAME — an index would break on reorder. May name a
133
+ * source this file declares in {@link DashboardDocument.sources}, or one it
134
+ * merely imports.
135
+ */
136
+ source: string;
137
+ declaration: TileDeclaration;
138
+ /**
139
+ * Given bindings, emitted as a `+ { where: … }` refinement on the view.
140
+ *
141
+ * `op` is the comparison, and absent means `~`, which is how a `filter<…>`
142
+ * given binds. A plain `date` or `number` given is a VALUE, not a filter,
143
+ * and compares with `>=`, `<=` or `=` — measured: `created_at >= $SINCE`
144
+ * compiles and `created_at ~ $SINCE` does not, on a `date` given.
145
+ */
146
+ filters?: Array<{
147
+ field: string;
148
+ given: string;
149
+ op?: string;
150
+ }>;
151
+ label?: string;
152
+ subtitle?: string;
153
+ colspan?: number;
154
+ break?: boolean;
155
+ borderless?: boolean;
156
+ }
157
+ /**
158
+ * A source extension the dashboard DECLARES, holding tiles that read it.
159
+ *
160
+ * A LIST, not one source, because a composite dashboard exists precisely to
161
+ * combine queries no single Malloy result can span. Measured: a dashboard whose
162
+ * tiles come from two sources loads clean and scopes givens per source. A picker
163
+ * over a package catalog offers every source's views side by side, so the second
164
+ * tile a reader adds can already need this.
165
+ *
166
+ * May be EMPTY. A dashboard whose tiles all read imported sources declares no
167
+ * extension at all — `tiles=["orders -> by_brand"]` over an imported `orders` is
168
+ * a complete dashboard with nothing else in the file.
169
+ */
170
+ export interface DashboardSource {
171
+ name: string;
172
+ /** What it extends: `source: <name> is <base> extend { … }`. */
173
+ base: string;
174
+ /** A `#(doc)` description on the source. */
175
+ doc?: string;
176
+ /**
177
+ * The dimensions this extension declares itself, in file order. These are
178
+ * the only fields a `# drill` can be authored on here: a drill is a tag on
179
+ * the dimension's declaration, and the model's dimensions are declared in
180
+ * the model.
181
+ */
182
+ dimensions?: DashboardDimension[];
183
+ }
184
+ /** A tile's identity across a reorder: what the grid keys on, a drag names and the writer matches. */
185
+ export declare const tileKey: (tile: {
186
+ source: string;
187
+ name: string;
188
+ }) => string;
189
+ /** `dimension: <name> is <expression>` in the dashboard's own extension. */
190
+ export interface DashboardDimension {
191
+ name: string;
192
+ expression: string;
193
+ }
194
+ export interface DashboardDocument {
195
+ title: string;
196
+ /** The narrative header, as markdown. Emitted as `##"` lines. */
197
+ description?: string;
198
+ /** `# dashboard { columns=N }`. */
199
+ columns?: number;
200
+ /** `## artifact { autorun=false }`. Absent means autorun. */
201
+ autorun?: boolean;
202
+ imports: DashboardImport[];
203
+ sources: DashboardSource[];
204
+ localGivens?: LocalGiven[];
205
+ /** `## artifact { givens { … } }` — where the controls open. */
206
+ startingGivens?: Record<string, string>;
207
+ drills?: DashboardDrill[];
208
+ /**
209
+ * Tiles in layout order. The grid flows in declaration order, so this array
210
+ * IS the layout, and there is no separate ordering field to fall out of step
211
+ * with it.
212
+ *
213
+ * One array drives both halves of the file: the `## artifact { tiles=[…] }`
214
+ * list and the `view:` declarations inside each extension. They therefore
215
+ * cannot disagree, which they can and do in hand-written files.
216
+ */
217
+ tiles: DashboardTile[];
218
+ }
@@ -0,0 +1,71 @@
1
+ import { GridTile } from '../Dashboard/DashboardGrid';
2
+ import { DashboardTile } from './document';
3
+ /**
4
+ * How the builder's grid is arranged: what a reorder does to the rows, and
5
+ * where the empty end of a row is. Pure, so the gestures that call it can be
6
+ * tested without a pointer.
7
+ */
8
+ /**
9
+ * Reordering keeps the ROW STRUCTURE and moves only the tiles through it.
10
+ *
11
+ * `# break` starts a fresh row. It is written as a tag on a tile, so the
12
+ * obvious reading is that it belongs to the tile and should travel with it.
13
+ * That is wrong in practice: drag one of four half-width tiles and its `break`
14
+ * lands mid-row, forcing a new row and leaving the half beside it empty — four
15
+ * `colspan=6` tiles stop being a 2x2 the moment one moves.
16
+ *
17
+ * The tag is positional in MEANING even though it is stored per tile: it
18
+ * says "a row starts here", which is a fact about the grid, not about the
19
+ * view that happens to sit there. So a move re-applies the break pattern by
20
+ * POSITION, and the surrounding tiles close up behind the one that left.
21
+ * Widths still travel with their tiles, because a width really is the tile's.
22
+ */
23
+ export declare const keepRowStructure: (reordered: DashboardTile[], pattern: readonly boolean[]) => DashboardTile[];
24
+ /**
25
+ * Moving a tile INTO A GAP — the empty end of a row — is the one move that
26
+ * must change the row structure, because the gap IS the row structure.
27
+ *
28
+ * A gap exists for one reason: the tile after the row's last tile carries a
29
+ * `# break`, so it starts a fresh row instead of filling the space. Dropping a
30
+ * tile into that space says, as plainly as a gesture can, "this belongs up
31
+ * here" — and {@link keepRowStructure} would refuse it: re-applying the break
32
+ * by position hands the break to the moved tile, which then starts its own row
33
+ * and leaves the gap exactly where it was. Measured on the storefront overview
34
+ * with the trend narrowed to half width: the map could not be dragged up
35
+ * beside it at all.
36
+ *
37
+ * So a gap drop lets the break TRAVEL instead: the moved tile arrives with
38
+ * none, so it flows into the row; the tile that started the next row keeps its
39
+ * break and still does. And the row the tile LEFT closes up — if it was that
40
+ * row's first tile, the tile after it starts the row now, which is what the
41
+ * positional rule would have done there too.
42
+ *
43
+ * `to` is where the tile lands in the array it is spliced back into, after
44
+ * `from` has been removed — the same convention the tile-target move uses.
45
+ */
46
+ export declare const moveIntoGap: (tiles: readonly DashboardTile[], from: number, to: number) => DashboardTile[];
47
+ /** One thing the grid lays out: a tile, or the empty end of a row. */
48
+ export type GridEntry = GridTile & ({
49
+ kind: "tile";
50
+ tile: DashboardTile;
51
+ /** Its place among the TILES — what a sortable item is told. */
52
+ index: number;
53
+ } | {
54
+ kind: "gap";
55
+ after: string;
56
+ });
57
+ export declare const tileEntry: (tile: DashboardTile, index: number) => GridEntry;
58
+ /** A gap's id: its drop target's, and the grid's key for it. */
59
+ export declare const gapId: (after: string) => string;
60
+ /**
61
+ * The grid's entries with a drop target in every gap.
62
+ *
63
+ * A flow grid has no element where a row runs out; the space is simply not
64
+ * painted, so there is nothing for a drag to be "over". This walks the tiles
65
+ * as the grid will place them — `# break` starts a row, and so does a tile too
66
+ * wide for what is left of the current one — and wherever a row ends short of
67
+ * the last column, lays a gap entry spanning exactly the columns left over. It
68
+ * fills space that was already empty, so adding it moves nothing; and it
69
+ * carries the key of the tile it follows, which is what a drop on it needs.
70
+ */
71
+ export declare const withGaps: (tiles: readonly DashboardTile[], columns: number) => GridEntry[];
@@ -0,0 +1,45 @@
1
+ export declare const isIdentifier: (text: string) => boolean;
2
+ /** A one-line `<keyword>: <name> is <rest>` declaration. */
3
+ export interface DeclarationAt {
4
+ line: number;
5
+ /** Everything after `is`, trimmed: a base view, an expression, or `{`. */
6
+ rest: string;
7
+ }
8
+ /**
9
+ * The `<keyword>:` declarations under `source: <owner>`, in file order. The
10
+ * body of a source ends at the next top-level declaration or `##` line.
11
+ */
12
+ export declare function declarationsUnder(lines: string[], owner: string, keyword: "view" | "dimension"): Map<string, DeclarationAt>;
13
+ /** The line declaring `<keyword>: <name> is`, or -1. */
14
+ export declare function declarationLine(lines: string[], keyword: "view" | "source", name: string): number;
15
+ /** The line carrying the model-level `## artifact` tag, or -1. */
16
+ export declare const artifactLine: (lines: string[]) => number;
17
+ /** A `given:` declaration: its line, and the block header when it is in one. */
18
+ export interface GivenAt {
19
+ line: number;
20
+ blockHeader?: number;
21
+ /** `NAME :: type is default`, as written. */
22
+ declaration: string;
23
+ }
24
+ /**
25
+ * Every `given:` declaration, by name, in both spellings Malloy accepts:
26
+ *
27
+ * given: CATEGORY :: filter<string> is f'' // one per line
28
+ *
29
+ * given: // a block
30
+ * CATEGORY :: filter<string> is f''
31
+ * SINCE :: date is @2023-01-01
32
+ */
33
+ export declare function givenDeclarations(lines: string[]): Map<string, GivenAt>;
34
+ /** A tile expression's steps: `orders -> by_brand + { limit: 2 }`. */
35
+ export interface TileSteps {
36
+ source: string;
37
+ view: string;
38
+ /** The refinement on the view, `+ { … }`, when the expression carries one. */
39
+ refinement?: string;
40
+ }
41
+ /**
42
+ * `source -> view`, optionally refined — the one form the builder lays out.
43
+ * Undefined for anything else: an inline stage, or a longer pipeline.
44
+ */
45
+ export declare function tileSteps(expression: string | undefined): TileSteps | undefined;
@@ -0,0 +1,60 @@
1
+ import { Given } from '../../client';
2
+ import { GivenValue } from '../../hooks/givenValue';
3
+ import { DashboardDocument, DashboardTile } from './document';
4
+ /**
5
+ * What a reader would see if the DOCUMENT were the file: the controls, and
6
+ * each tile's query — so the builder's live view follows an edit the moment it
7
+ * is made, rather than the file on the server's disk. Run from the file, an
8
+ * unbound tile keeps filtering and a removed control stays in the row until a
9
+ * save lands, so the edit looks like it did nothing.
10
+ *
11
+ * Two functions, one per half of what a reader sees. Both are pure, so the
12
+ * host can hold the live document and derive its preview from it. A given the
13
+ * document declares but the server's model has not compiled cannot be SENT to
14
+ * it — the server refuses a given it does not know — so a new control's value
15
+ * is written into the query as a literal instead, and the new filter works the
16
+ * moment it is added rather than after a save.
17
+ */
18
+ /**
19
+ * The controls this document shows: every given some tile binds, this file's
20
+ * own declarations first in declaration order, then the model's.
21
+ *
22
+ * That is the reader's rule — only a given some tile reads becomes a control
23
+ * — applied to the document instead of the manifest. A local declaration is
24
+ * built into a `Given` from its control contract; a model given is the
25
+ * manifest's own spec, which carries what the file cannot say (`givenNames` a
26
+ * suggest is gated by, for one).
27
+ */
28
+ export declare function previewGivens(document: DashboardDocument, modelSpecs: readonly Given[]): Given[];
29
+ /** A tile's query as the document has it, and the givens it sends. */
30
+ export interface PreviewTileQuery {
31
+ /** A run expression, without `run:` — what `DashboardTile.tile` takes. */
32
+ expression: string;
33
+ /**
34
+ * The givens this tile binds and the server can take, for narrowing the
35
+ * request. Undefined for a tile whose bindings live in the model, where the
36
+ * document cannot know them: send the whole row, as the reader does.
37
+ */
38
+ givenNames: string[] | undefined;
39
+ }
40
+ /**
41
+ * A tile's query with the DOCUMENT's bindings, run on the dashboard's own
42
+ * extension.
43
+ *
44
+ * `overview -> revenue_trend` would run the view AS SAVED, bindings and all.
45
+ * `overview -> sales_by_month + { where: category ~ $CATEGORY }` is the base
46
+ * view the tile names, on the same extension, refined by what the document
47
+ * binds now — which is exactly the declaration the writer would produce, run
48
+ * before it is written. Every reference tile has such a base view, and the
49
+ * extension inherits it: `view: x is base_view + …` can only name a view of the
50
+ * source the extension extends.
51
+ *
52
+ * `runnable` is the set of givens the server's model declares; a binding to
53
+ * one of them is written as `$NAME` and the given is sent with the request. A
54
+ * binding to a given outside it — one this document just declared, which the
55
+ * server would refuse by name — is written with its VALUE as a literal,
56
+ * `where: brand ~ f'Nike'`, from `values` and the declaration's type; with no
57
+ * value yet it is left out, which is what an empty filter means. A binding to
58
+ * a given neither side knows is left out too.
59
+ */
60
+ export declare function previewTileQuery(document: DashboardDocument, tile: DashboardTile, runnable: ReadonlySet<string>, values?: ReadonlyMap<string, GivenValue>): PreviewTileQuery;
@@ -0,0 +1,106 @@
1
+ import { DashboardDocument, LocalGiven } from './document';
2
+ /**
3
+ * Read a `dashboards/*.malloy` file into a {@link DashboardDocument}.
4
+ *
5
+ * PURE: source text in, document out. No server, no schema, no connection.
6
+ * `Malloy.parse` needs none of those — only `Malloy.compile` does — so this runs
7
+ * in the browser and in a unit test alike, which is what lets the suite open
8
+ * every dashboard in the repository as a regression gate.
9
+ *
10
+ * Structure comes from the parser's symbol tree, which covers imports (including
11
+ * the items of a named list), sources, views and dimensions, each with a source
12
+ * RANGE. Content comes from the text inside those ranges, and tags from
13
+ * `parseAnnotation` over the block above each declaration.
14
+ *
15
+ * Reading tags from the text rather than from the server, which serves them
16
+ * already attached, is deliberate. The splice writer has to LOCATE a tag in
17
+ * order to edit it, so the scan exists either way; taking the values from the
18
+ * same scan keeps one source of truth for them and keeps this function pure.
19
+ *
20
+ * ALL-OR-NOTHING: a file this cannot fully represent is refused rather than
21
+ * half-opened. The bar is lower than it sounds because the document is an
22
+ * editing projection — unmodelled Malloy survives a splice untouched, so it only
23
+ * blocks when it would make an edit unsafe.
24
+ */
25
+ /** Why a file could not be opened, in terms its author can act on. */
26
+ export interface ReadFailure {
27
+ ok: false;
28
+ reason: string;
29
+ /** 1-based, for a message that can point at the line. */
30
+ line?: number;
31
+ }
32
+ export type ReadResult = {
33
+ ok: true;
34
+ document: DashboardDocument;
35
+ } | ReadFailure;
36
+ /**
37
+ * Narrow a result to its failure arm.
38
+ *
39
+ * A guard rather than `if (!result.ok)`, because this package compiles with
40
+ * `strict: false` — the tsconfig says why, and it is not ours to change — and
41
+ * without `strictNullChecks` TypeScript does not narrow a discriminated union
42
+ * through a negated discriminant. The failure is quiet: `result.reason` simply
43
+ * does not typecheck, in a codebase where most code never notices.
44
+ */
45
+ export declare const readFailed: (result: ReadResult) => result is ReadFailure;
46
+ /** A `#`/`//` block above a declaration, and where it sits. */
47
+ export interface Block {
48
+ /** 0-based line of the first line in the block. */
49
+ start: number;
50
+ /**
51
+ * The `#`-prefixed lines only, in order, WITH their line numbers. The writer
52
+ * needs the numbers to patch a tag in place; the reader only needs the text.
53
+ */
54
+ tags: Array<{
55
+ line: number;
56
+ text: string;
57
+ }>;
58
+ }
59
+ /**
60
+ * The comment-and-tag block immediately above `declLine`.
61
+ *
62
+ * Scans upward while lines are `#` tags or `//` comments and STOPS AT A BLANK
63
+ * LINE. Validated against the bundled dashboard, where it collects
64
+ * `revenue_trend`'s three tags and the fourteen-line comment explaining its
65
+ * colspan, then stops at the blank line above — which is the right unit to carry
66
+ * when that tile moves.
67
+ *
68
+ * A blank line is the author's own separator, which is why it is the boundary
69
+ * rather than a count or a heuristic about comment content.
70
+ */
71
+ export declare function blockAbove(lines: string[], declLine: number): Block;
72
+ /**
73
+ * One `where: <field> <op> $<GIVEN>` clause. Exported for the writer, which
74
+ * has to find the same clauses in order to replace them and nothing else.
75
+ */
76
+ export declare const BINDING_CLAUSE: RegExp;
77
+ /**
78
+ * A tag object, as `parseAnnotation` returns it. Only the reads this file makes.
79
+ */
80
+ type TagLike = {
81
+ text: (key: string) => string | undefined;
82
+ numeric: (key: string) => number | undefined;
83
+ tag: (key: string) => TagLike | undefined;
84
+ };
85
+ type ParseTags = (lines: string[]) => {
86
+ tag?: TagLike | null;
87
+ };
88
+ /**
89
+ * `given:` declarations, which the parser's symbol tree does not cover at all —
90
+ * its types are query, unnamed_query, explore, field, join, import and
91
+ * import_item. So these are read as text, in BOTH spellings Malloy accepts and
92
+ * this repository uses:
93
+ *
94
+ * given: CATEGORY :: filter<string> is f'' // one per line
95
+ *
96
+ * given: // a block
97
+ * CATEGORY :: filter<string> is f''
98
+ * SINCE :: date is @2023-01-01
99
+ *
100
+ * The one-line form is what `givens.malloy` and the docs write and what the
101
+ * builder emits; the block form is read so a file written the other way still
102
+ * opens. Either way the tags above a declaration are its control contract.
103
+ */
104
+ export declare function localGivens(lines: string[], parse: ParseTags): LocalGiven[] | undefined;
105
+ export declare function readDashboardDocument(sourceText: string): Promise<ReadResult>;
106
+ export {};
@@ -0,0 +1,51 @@
1
+ import { KeyboardSensor, PointerSensor, PointerSensorOptions } from '@dnd-kit/dom';
2
+ import { ReactNode } from 'react';
3
+ import { PluginDescriptor, Plugin } from '@dnd-kit/abstract';
4
+ /** The type of a gap: the empty end of a row, offered as a drop target. */
5
+ export declare const GAP_TYPE = "gap";
6
+ export declare const builderSensors: ( PluginDescriptor<any, Plugin<any, PointerSensorOptions>, typeof PointerSensor> | typeof KeyboardSensor)[];
7
+ interface TileSortableHandles {
8
+ /** The tile's element: what is dragged, and what a drop lands on. */
9
+ ref: (element: Element | null) => void;
10
+ /** The grip: keyboard focus and screen-reader instructions live here. */
11
+ handleRef: (element: Element | null) => void;
12
+ /** This tile is the one being dragged. */
13
+ isDragSource: boolean;
14
+ }
15
+ /**
16
+ * A tile as a sortable item. A component rather than a hook call in the
17
+ * builder's render, because the grid renders tiles through a callback and a
18
+ * hook cannot be called from one.
19
+ *
20
+ * `index` is the tile's place in the PREVIEWED order, which is what lets the
21
+ * library animate a tile to its new slot when that order changes under it.
22
+ */
23
+ export declare function TileSortable({ id, index, children, }: {
24
+ id: string;
25
+ index: number;
26
+ children: (handles: TileSortableHandles) => ReactNode;
27
+ }): import("react/jsx-runtime").JSX.Element;
28
+ /** What a gap drop target carries: the key of the tile the gap follows. */
29
+ export interface GapData {
30
+ after: string;
31
+ }
32
+ /**
33
+ * The empty end of a row, as a drop target.
34
+ *
35
+ * A flow grid has no element where a row runs out; the space is simply not
36
+ * painted. So while a drag is live the builder lays one of these into each
37
+ * such space, spanning exactly the columns left over, and the library can
38
+ * report the pointer over it like any other target. `pointerIntersection`
39
+ * rather than the default shape overlap: the dragged copy is tile-sized and
40
+ * would overlap a neighbouring tile more than a narrow gap; the pointer is
41
+ * where the reader means.
42
+ */
43
+ export declare function GapDroppable({ id, after, children, }: {
44
+ id: string;
45
+ after: string;
46
+ children: (handles: {
47
+ ref: (element: Element | null) => void;
48
+ isDropTarget: boolean;
49
+ }) => ReactNode;
50
+ }): import("react/jsx-runtime").JSX.Element;
51
+ export {};
@@ -0,0 +1,44 @@
1
+ import { DashboardDocument } from './document';
2
+ /**
3
+ * Write a change back into a `dashboards/*.malloy` file by PATCHING it.
4
+ *
5
+ * The builder does not regenerate the file. It rewrites the bytes it owns and
6
+ * leaves every other byte exactly where it was, which is what lets it edit a
7
+ * dashboard somebody else wrote: comments, formatting, declaration order and
8
+ * unmodelled Malloy all survive an edit because nothing rewrites them.
9
+ *
10
+ * The safety property is a SEMANTIC round-trip, not a byte one. After splicing,
11
+ * the result is read back and compared against the document that was asked for;
12
+ * a mismatch refuses the write. Byte-identity with a regenerated file would be
13
+ * a weaker thing to know, and would make every commented file read-only.
14
+ *
15
+ * A refused write NEVER discards the edit. The caller keeps its document and is
16
+ * told the writer produced something it could not read back — that is a defect
17
+ * in this module, not a mistake by the person editing.
18
+ *
19
+ * SCOPE, deliberately: a tile's presentation, its filter bindings, the order of
20
+ * tiles, and the dashboard's OWN givens — added, removed or retagged. Never an
21
+ * import, and never a model file: a filter the builder adds is a declaration in
22
+ * this file, which is the convention {@link LocalGiven} describes. And tiles
23
+ * ADDED or REMOVED: a new `view:` inside the extension of the source it reads
24
+ * (or a new extension, when the file imports that source by name), a removed
25
+ * one deleted with its `#` tags. Those moves are the one place the file cannot
26
+ * say who owns the comment beside a declaration, so the builder shows the diff
27
+ * before a structural save and the `//` comments are left where they were.
28
+ *
29
+ * A given is different from a tile in exactly the way that matters there: the
30
+ * `#` tags above its declaration are its control contract and have no other
31
+ * owner, so removing the declaration can take them with it, and a `//` comment
32
+ * in the same block is left where it is.
33
+ */
34
+ export interface SpliceFailure {
35
+ ok: false;
36
+ reason: string;
37
+ }
38
+ export type SpliceResult = {
39
+ ok: true;
40
+ source: string;
41
+ } | SpliceFailure;
42
+ /** Narrow to the failure arm; see {@link readFailed} for why a guard. */
43
+ export declare const spliceFailed: (result: SpliceResult) => result is SpliceFailure;
44
+ export declare function spliceDashboardDocument(sourceText: string, next: DashboardDocument): Promise<SpliceResult>;
@@ -0,0 +1,10 @@
1
+ import { DashboardDocument } from '../document';
2
+ import { SpliceResult } from '../spliceDocument';
3
+ /** The document a file produces, or a thrown reason: what a spec starts from. */
4
+ export declare function openDocument(source: string): Promise<DashboardDocument>;
5
+ /** Open, edit a copy, and hand back what the writer says. */
6
+ export declare function splice(source: string, edit: (document: DashboardDocument) => void): Promise<SpliceResult>;
7
+ /** `splice`, for an edit the writer is expected to accept. */
8
+ export declare function spliced(source: string, edit: (document: DashboardDocument) => void): Promise<string>;
9
+ /** `splice`, for an edit the writer is expected to refuse; its reason. */
10
+ export declare function refused(source: string, edit: (document: DashboardDocument) => void): Promise<string>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The keyboard an editor is expected to have.
3
+ *
4
+ * Undo and redo on the platform's usual keys, save on ⌘S / Ctrl+S (which the
5
+ * browser would otherwise take), Escape to drop the selection, and the arrow
6
+ * keys to nudge the selected tile's width a column at a time — the one layout
7
+ * edit that is otherwise drag-only.
8
+ *
9
+ * Nothing but Escape fires while a text field has focus, so typing into a
10
+ * title never undoes a layout.
11
+ */
12
+ export interface BuilderShortcutHandlers {
13
+ undo: () => void;
14
+ redo: () => void;
15
+ save?: () => void;
16
+ escape: () => void;
17
+ /** Nudge the selected tile's width by ±1 column. */
18
+ nudge: (delta: 1 | -1) => void;
19
+ }
20
+ /** The modifier's glyph for a tooltip. */
21
+ export declare const MOD: string;
22
+ export declare function useBuilderShortcuts(handlers: BuilderShortcutHandlers): void;