@malloy-publisher/sdk 0.3.0 → 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 (156) hide show
  1. package/README.md +8 -0
  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-CH71GsoL.cjs.js +1 -0
  7. package/dist/{ServerProvider-DSK9rfSY.es.js → ServerProvider-X2Ma0HRs.es.js} +486 -521
  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/index.cjs.js +1 -1
  13. package/dist/client/index.es.js +1 -1
  14. package/dist/components/Dashboard/Dashboard.d.ts +19 -14
  15. package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
  16. package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
  17. package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
  18. package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
  19. package/dist/components/Dashboard/TileCard.d.ts +44 -0
  20. package/dist/components/Dashboard/index.d.ts +2 -0
  21. package/dist/components/Dashboard/promoteMeasureRow.d.ts +7 -3
  22. package/dist/components/Dashboard/telemetry.d.ts +43 -0
  23. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
  24. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +29 -0
  25. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +112 -0
  26. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +32 -0
  27. package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
  28. package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
  29. package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
  30. package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
  31. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
  32. package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
  33. package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
  34. package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
  35. package/dist/components/DashboardBuilder/controls.d.ts +157 -0
  36. package/dist/components/DashboardBuilder/diff.d.ts +35 -0
  37. package/dist/components/DashboardBuilder/document.d.ts +218 -0
  38. package/dist/components/DashboardBuilder/layout.d.ts +71 -0
  39. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
  40. package/dist/components/DashboardBuilder/preview.d.ts +60 -0
  41. package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
  42. package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
  43. package/dist/components/DashboardBuilder/spliceDocument.d.ts +44 -0
  44. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
  45. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
  46. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
  47. package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
  48. package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
  49. package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
  50. package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
  51. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +7 -0
  52. package/dist/components/DocumentStorage/index.d.ts +1 -1
  53. package/dist/components/FloatingIconButton.d.ts +16 -0
  54. package/dist/components/Prose.d.ts +46 -0
  55. package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
  56. package/dist/components/RenderedResult/index.d.ts +1 -0
  57. package/dist/components/drill/index.d.ts +1 -1
  58. package/dist/components/drill/resolveDrill.d.ts +22 -0
  59. package/dist/components/drill/useDrill.d.ts +11 -2
  60. package/dist/components/index.d.ts +1 -0
  61. package/dist/components/styles.d.ts +0 -4
  62. package/dist/hooks/index.d.ts +2 -0
  63. package/dist/hooks/useDocumentControls.d.ts +70 -0
  64. package/dist/hooks/useQueryResult.d.ts +40 -0
  65. package/dist/index.cjs.js +23 -270
  66. package/dist/index.es.js +16977 -41293
  67. package/dist/utils/malloyLiteral.d.ts +11 -0
  68. package/package.json +24 -9
  69. package/src/builder-entry.ts +55 -0
  70. package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
  71. package/src/components/Dashboard/Dashboard.tsx +165 -175
  72. package/src/components/Dashboard/DashboardGrid.tsx +124 -0
  73. package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
  74. package/src/components/Dashboard/DashboardTile.tsx +66 -123
  75. package/src/components/Dashboard/ExploreDialog.tsx +84 -0
  76. package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
  77. package/src/components/Dashboard/RowsDialog.tsx +234 -0
  78. package/src/components/Dashboard/TileCard.tsx +120 -0
  79. package/src/components/Dashboard/index.ts +2 -0
  80. package/src/components/Dashboard/promoteMeasureRow.spec.ts +70 -0
  81. package/src/components/Dashboard/promoteMeasureRow.ts +33 -2
  82. package/src/components/Dashboard/telemetry.ts +44 -0
  83. package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
  84. package/src/components/DashboardBuilder/AddTileDialog.tsx +249 -0
  85. package/src/components/DashboardBuilder/BuilderToolbar.tsx +270 -0
  86. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +858 -0
  87. package/src/components/DashboardBuilder/DashboardBuilder.tsx +653 -0
  88. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +211 -0
  89. package/src/components/DashboardBuilder/DashboardEditor.tsx +493 -0
  90. package/src/components/DashboardBuilder/DiffDialog.tsx +129 -0
  91. package/src/components/DashboardBuilder/DrillDialog.tsx +281 -0
  92. package/src/components/DashboardBuilder/FilterDialog.tsx +581 -0
  93. package/src/components/DashboardBuilder/FilterStrip.tsx +125 -0
  94. package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
  95. package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
  96. package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
  97. package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
  98. package/src/components/DashboardBuilder/catalog.ts +225 -0
  99. package/src/components/DashboardBuilder/controls.spec.ts +243 -0
  100. package/src/components/DashboardBuilder/controls.ts +398 -0
  101. package/src/components/DashboardBuilder/diff.spec.ts +44 -0
  102. package/src/components/DashboardBuilder/diff.ts +93 -0
  103. package/src/components/DashboardBuilder/document.ts +209 -0
  104. package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
  105. package/src/components/DashboardBuilder/layout.ts +143 -0
  106. package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
  107. package/src/components/DashboardBuilder/malloyText.ts +151 -0
  108. package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
  109. package/src/components/DashboardBuilder/preview.spec.ts +149 -0
  110. package/src/components/DashboardBuilder/preview.ts +172 -0
  111. package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
  112. package/src/components/DashboardBuilder/readDocument.ts +467 -0
  113. package/src/components/DashboardBuilder/sortable.tsx +151 -0
  114. package/src/components/DashboardBuilder/spliceDocument.spec.ts +1108 -0
  115. package/src/components/DashboardBuilder/spliceDocument.ts +1098 -0
  116. package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
  117. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
  118. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +255 -0
  119. package/src/components/DashboardBuilder/useDashboardEditor.ts +193 -0
  120. package/src/components/DashboardBuilder/useDraft.ts +43 -0
  121. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
  122. package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
  123. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
  124. package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
  125. package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
  126. package/src/components/DashboardBuilder/useTileResize.ts +110 -0
  127. package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
  128. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +12 -0
  129. package/src/components/DocumentStorage/index.ts +1 -0
  130. package/src/components/Environment/About.tsx +4 -36
  131. package/src/components/FloatingIconButton.tsx +41 -0
  132. package/src/components/Model/Model.tsx +6 -23
  133. package/src/components/Model/ModelCell.tsx +33 -72
  134. package/src/components/Notebook/Notebook.tsx +25 -88
  135. package/src/components/Notebook/NotebookCell.tsx +35 -183
  136. package/src/components/Prose.spec.tsx +85 -0
  137. package/src/components/Prose.tsx +179 -0
  138. package/src/components/QueryResult/QueryResult.tsx +15 -43
  139. package/src/components/RenderedResult/ResultContainer.tsx +4 -12
  140. package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
  141. package/src/components/RenderedResult/ResultPanel.tsx +73 -0
  142. package/src/components/RenderedResult/index.ts +1 -0
  143. package/src/components/drill/index.ts +1 -0
  144. package/src/components/drill/resolveDrill.ts +22 -1
  145. package/src/components/drill/useDrill.spec.tsx +94 -0
  146. package/src/components/drill/useDrill.tsx +52 -12
  147. package/src/components/given/GivensPanel.tsx +1 -1
  148. package/src/components/index.ts +6 -0
  149. package/src/components/styles.ts +0 -37
  150. package/src/hooks/index.ts +13 -0
  151. package/src/hooks/useDocumentControls.ts +170 -0
  152. package/src/hooks/useQueryResult.ts +82 -0
  153. package/src/utils/malloyLiteral.spec.ts +43 -0
  154. package/src/utils/malloyLiteral.ts +76 -0
  155. package/vite.config.ts +5 -0
  156. package/dist/ServerProvider-CGnLjzag.cjs.js +0 -1
@@ -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;
@@ -0,0 +1,63 @@
1
+ import { DashboardDocument } from './document';
2
+ /**
3
+ * The editor's state: the document being edited, its history, and saving.
4
+ *
5
+ * Deliberately holds the DOCUMENT and nothing else. Given VALUES — what the
6
+ * preview is running with — are editor state rather than document state and
7
+ * live outside this hook, which is what keeps them out of the undo stack. Undo
8
+ * should take back a layout change; it should not rewind the filter someone was
9
+ * previewing under.
10
+ */
11
+ export interface DashboardEditor {
12
+ document: DashboardDocument;
13
+ /** The file as it currently stands, which is what a save patches. */
14
+ source: string;
15
+ canUndo: boolean;
16
+ canRedo: boolean;
17
+ /** Whether the document has changes the file does not have yet. */
18
+ dirty: boolean;
19
+ /**
20
+ * Why the last save did not happen. The document is untouched when this is
21
+ * set: a refused write keeps the reader's work and reports a defect in the
22
+ * writer, rather than discarding an edit because a tool could not read back
23
+ * what it produced.
24
+ */
25
+ error?: string;
26
+ /** Apply a change. Receives a copy; mutate it freely. */
27
+ update: (change: (draft: DashboardDocument) => void) => void;
28
+ undo: () => void;
29
+ redo: () => void;
30
+ /** Splice the change into the file, or say why it was refused. */
31
+ save: () => Promise<SaveOutcome>;
32
+ /**
33
+ * The file a save would write, without writing it: what a diff preview
34
+ * shows. The failure arm is the writer's refusal, worded for the author.
35
+ */
36
+ preview: () => Promise<{
37
+ ok: true;
38
+ source: string;
39
+ } | {
40
+ ok: false;
41
+ reason: string;
42
+ }>;
43
+ /**
44
+ * Whether the unsaved change adds or removes a tile. Those moves touch
45
+ * declarations and the comments beside them, which is when a save is worth
46
+ * showing as a diff first; a property edit never is.
47
+ */
48
+ structural: boolean;
49
+ }
50
+ export type SaveOutcome = {
51
+ ok: true;
52
+ } | {
53
+ ok: false;
54
+ reason: string;
55
+ };
56
+ export declare function useDashboardEditor(options: {
57
+ /** The file as read from storage. */
58
+ source: string;
59
+ /** The document that file produced. */
60
+ document: DashboardDocument;
61
+ /** Persist the patched file. Rejecting leaves the editor dirty. */
62
+ onSave?: (source: string) => Promise<void> | void;
63
+ }): DashboardEditor;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A copy of `value` to edit while a window is open, committed ONCE when it
3
+ * closes, and only if something changed.
4
+ *
5
+ * Per-keystroke commits would put a document in the undo stack for every
6
+ * letter typed into a title, and undo would then walk back through the word.
7
+ */
8
+ export declare function useDraft<T>(value: T | undefined, open: boolean, onCommit: (next: T) => void, onClose: () => void): {
9
+ draft: T;
10
+ patch: (change: (draft: T) => void) => void;
11
+ close: () => void;
12
+ discard: () => void;
13
+ };
@@ -0,0 +1,65 @@
1
+ import { CatalogField } from './catalog';
2
+ import { BuilderControl, ControlKind, MappingRow } from './controls';
3
+ import { DashboardDocument, DashboardTile, LocalGiven } from './document';
4
+ import { Dispatch, SetStateAction } from 'react';
5
+ type Source = {
6
+ kind: "existing";
7
+ name: string;
8
+ } | {
9
+ kind: "new";
10
+ };
11
+ /** `STATUS` → `Status`: the label a new control gets when none is typed. */
12
+ export declare const titleCase: (name: string) => string;
13
+ /**
14
+ * The filter window's state and every derivation it renders from: what the
15
+ * control is (new here, or one the model offers), which tiles it binds and on
16
+ * which field, what stands in the way of applying, and the payload an Apply
17
+ * hands back. No MUI in here, so it can be exercised without a dialog.
18
+ */
19
+ export declare function useFilterForm({ open, document, control, available, fieldsFor, onApply, }: {
20
+ open: boolean;
21
+ document: DashboardDocument;
22
+ control: BuilderControl | undefined;
23
+ available: readonly BuilderControl[];
24
+ fieldsFor?: (tile: DashboardTile) => readonly CatalogField[] | undefined;
25
+ onApply: (given: string, rows: MappingRow[], declare?: LocalGiven) => void;
26
+ }): {
27
+ editing: boolean;
28
+ shown: BuilderControl;
29
+ fromModel: boolean;
30
+ source: Source;
31
+ setSource: Dispatch<SetStateAction<Source>>;
32
+ label: string;
33
+ setLabel: Dispatch<SetStateAction<string>>;
34
+ kind: ControlKind;
35
+ dateDefault: string;
36
+ setDateDefault: Dispatch<SetStateAction<string>>;
37
+ field: string;
38
+ rows: MappingRow[];
39
+ setRows: Dispatch<SetStateAction<MappingRow[]>>;
40
+ perTile: boolean;
41
+ setPerTile: Dispatch<SetStateAction<boolean>>;
42
+ newName: string;
43
+ target: {
44
+ name: string;
45
+ type?: string;
46
+ };
47
+ valueTyped: boolean;
48
+ commonOp: string;
49
+ setRow: (index: number, patch: Partial<MappingRow>) => void;
50
+ setCommonOp: (next: string) => void;
51
+ pickExisting: (given: BuilderControl) => void;
52
+ pickKind: (next: ControlKind) => void;
53
+ bindable: boolean[];
54
+ bindableCount: number;
55
+ included: number;
56
+ commonFields: CatalogField[];
57
+ setAll: (include: boolean) => void;
58
+ accepts: (candidate: CatalogField) => boolean;
59
+ pickField: (next: string) => void;
60
+ rowProblems: string[];
61
+ commonProblem: string;
62
+ canApply: boolean;
63
+ apply: () => void;
64
+ };
65
+ export {};
@@ -0,0 +1,22 @@
1
+ import { DragEndEvent, DragOverEvent } from '@dnd-kit/react';
2
+ import { DashboardTile } from './document';
3
+ /**
4
+ * Dragging a tile to reorder it. The gesture is `@dnd-kit/react`'s (see
5
+ * `sortable.tsx`); what is decided here is what a drop means for the file,
6
+ * through `keepRowStructure` for a drop onto a tile and `moveIntoGap` for a
7
+ * drop into the empty end of a row. The preview is rebuilt on each report and
8
+ * written ONCE, on release: one history entry for the whole drag.
9
+ */
10
+ export declare function useTileReorder({ tiles, commit, onLanded, }: {
11
+ tiles: DashboardTile[];
12
+ /** The order to write when the drag ends somewhere new. */
13
+ commit: (next: DashboardTile[]) => void;
14
+ /** Where the dragged tile came to rest, which the caller selects. */
15
+ onLanded: (index: number) => void;
16
+ }): {
17
+ dragging: boolean;
18
+ preview: DashboardTile[];
19
+ onDragStart: () => void;
20
+ onDragOver: (event: DragOverEvent) => void;
21
+ onDragEnd: (event: DragEndEvent) => void;
22
+ };
@@ -0,0 +1,29 @@
1
+ import { DashboardTile } from './document';
2
+ import { RefObject } from 'react';
3
+ /** A resize in flight: the tile, the width it WOULD be, and the geometry. */
4
+ export interface ResizeState {
5
+ index: number;
6
+ span: number;
7
+ left: number;
8
+ track: number;
9
+ }
10
+ /**
11
+ * Dragging a tile's right edge to set its `colspan`. The width is previewed
12
+ * by the caller from `resize.span` and written ONCE, on release: writing on
13
+ * every pointer move would put a dozen documents in the history for one
14
+ * gesture, and undo would walk back through the drag a column at a time.
15
+ */
16
+ export declare function useTileResize({ tiles, columns, onStart, commit, }: {
17
+ tiles: readonly DashboardTile[];
18
+ columns: number;
19
+ /** The tile a resize begins on, which the caller selects. */
20
+ onStart: (index: number) => void;
21
+ /** The width to write when the drag ends. */
22
+ commit: (index: number, span: number) => void;
23
+ }): {
24
+ resize: ResizeState;
25
+ gridBox: RefObject<HTMLDivElement>;
26
+ startResize: (event: React.PointerEvent<HTMLDivElement>, index: number) => void;
27
+ onResize: (event: React.PointerEvent<HTMLDivElement>) => void;
28
+ endResize: (event: React.PointerEvent<HTMLDivElement>) => void;
29
+ };
@@ -15,4 +15,11 @@ interface DocumentStorageContextValue {
15
15
  export declare function DocumentStorageProvider({ children, documentStorage, }: DocumentStorageProviderProps): import("react/jsx-runtime").JSX.Element;
16
16
  /** The host's storage, or a thrown error outside a provider: there is no default. */
17
17
  export declare function useDocumentStorage(): DocumentStorageContextValue;
18
+ /**
19
+ * The host's storage, or undefined outside a provider. For a component that
20
+ * can do without one — the dashboard editor still edits and exports with no
21
+ * place to save — rather than the throwing form, which is for components that
22
+ * cannot.
23
+ */
24
+ export declare function useOptionalDocumentStorage(): DocumentStorageContextValue | undefined;
18
25
  export {};
@@ -1,3 +1,3 @@
1
1
  export type { DocumentLocator, DocumentStorage, DocumentType, Workspace, } from './DocumentStorage';
2
- export { DocumentStorageProvider, useDocumentStorage, type DocumentStorageProviderProps, } from './DocumentStorageProvider';
2
+ export { DocumentStorageProvider, useDocumentStorage, useOptionalDocumentStorage, type DocumentStorageProviderProps, } from './DocumentStorageProvider';
3
3
  export { BrowserDocumentStorage } from './BrowserDocumentStorage';
@@ -0,0 +1,16 @@
1
+ import { IconButtonProps } from '@mui/material';
2
+ /**
3
+ * A small round button that sits OVER content — a rendered result, an
4
+ * explorer, a chart — to open something about it: the code, the full result,
5
+ * a render warning.
6
+ *
7
+ * On the instance theme's tile colour, with its border, so it reads as a chip
8
+ * of the same card it floats on in both modes. Six of these were drawn by hand
9
+ * before, every one on a hardcoded white plate with a hardcoded dark icon,
10
+ * and the notebook's comment said why that was the only way: a white plate
11
+ * needs a dark icon whatever the mode. The plate follows the theme now, so
12
+ * the icon can too.
13
+ *
14
+ * Positioning is the caller's: it passes `sx` for where the button floats.
15
+ */
16
+ export declare function FloatingIconButton({ sx, ...props }: IconButtonProps): import("react/jsx-runtime").JSX.Element;