@malloy-publisher/sdk 0.9.14 → 0.9.16

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 (164) hide show
  1. package/dist/RenderedResult-5hOs5XnV.cjs.js +171 -0
  2. package/dist/RenderedResult-DxmHGZNQ.es.js +671 -0
  3. package/dist/{ServerProvider-BV7IoDMR.es.js → ServerProvider-D7neZcTk.es.js} +283 -265
  4. package/dist/ServerProvider-e2369oom.cjs.js +1 -0
  5. package/dist/builder/index.cjs.js +80 -79
  6. package/dist/builder/index.es.js +7732 -6717
  7. package/dist/builder-entry.d.ts +1 -1
  8. package/dist/client/api.d.ts +31 -7
  9. package/dist/client/index.cjs.js +1 -1
  10. package/dist/client/index.es.js +1 -1
  11. package/dist/components/Dashboard/DashboardGrid.d.ts +51 -1
  12. package/dist/components/Dashboard/DashboardTile.d.ts +7 -2
  13. package/dist/components/Dashboard/DashboardView.d.ts +9 -2
  14. package/dist/components/Dashboard/index.d.ts +1 -1
  15. package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
  16. package/dist/components/Dashboard/useStuck.d.ts +18 -12
  17. package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
  18. package/dist/components/RenderedResult/ResultContainer.d.ts +18 -1
  19. package/dist/components/RenderedResult/ResultPanel.d.ts +7 -1
  20. package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
  21. package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
  22. package/dist/components/RenderedResult/resultSizing.d.ts +47 -6
  23. package/dist/components/Report/Report.d.ts +7 -1
  24. package/dist/components/Report/ReportPage.d.ts +7 -0
  25. package/dist/components/Report/layoutRules.d.ts +45 -0
  26. package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
  27. package/dist/components/ReportBuilder/ArrangeMenu.d.ts +9 -0
  28. package/dist/components/ReportBuilder/BuilderGrid.d.ts +15 -4
  29. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +3 -1
  30. package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
  31. package/dist/components/ReportBuilder/EditorSurface.d.ts +10 -1
  32. package/dist/components/ReportBuilder/ReportBuilder.d.ts +1 -1
  33. package/dist/components/ReportBuilder/TileFrame.d.ts +54 -10
  34. package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
  35. package/dist/components/ReportBuilder/builderControls.d.ts +19 -0
  36. package/dist/components/ReportBuilder/catalog.d.ts +23 -0
  37. package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
  38. package/dist/components/ReportBuilder/controls.d.ts +2 -2
  39. package/dist/components/ReportBuilder/document.d.ts +53 -5
  40. package/dist/components/ReportBuilder/imports.d.ts +7 -0
  41. package/dist/components/ReportBuilder/placement.d.ts +121 -0
  42. package/dist/components/ReportBuilder/preview.d.ts +59 -10
  43. package/dist/components/ReportBuilder/sortable.d.ts +12 -1
  44. package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
  45. package/dist/components/ReportBuilder/useBuilderShortcuts.d.ts +9 -1
  46. package/dist/components/ReportBuilder/useEdgeResize.d.ts +84 -0
  47. package/dist/components/ReportBuilder/useTileReorder.d.ts +30 -3
  48. package/dist/index.cjs.js +7 -7
  49. package/dist/index.es.js +3349 -3307
  50. package/dist/text/index.es.js +1 -1
  51. package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
  52. package/dist/theme/classes.d.ts +1 -1
  53. package/dist/theme/resolveTheme.d.ts +15 -0
  54. package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-CaYP_OYG.es.js} +6353 -6047
  55. package/dist/useCompiledDocument-zYEfLogf.cjs.js +142 -0
  56. package/dist/utils/blankQuoted.d.ts +15 -0
  57. package/package.json +1 -1
  58. package/src/builder-entry.ts +1 -0
  59. package/src/components/Dashboard/DashboardGrid.tsx +129 -10
  60. package/src/components/Dashboard/DashboardTile.tsx +15 -1
  61. package/src/components/Dashboard/DashboardView.tsx +64 -10
  62. package/src/components/Dashboard/TileCard.tsx +6 -0
  63. package/src/components/Dashboard/index.ts +1 -0
  64. package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
  65. package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
  66. package/src/components/Dashboard/tileHeight.spec.ts +72 -0
  67. package/src/components/Dashboard/useStuck.ts +76 -28
  68. package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
  69. package/src/components/Package/NewDocumentDialog.tsx +10 -11
  70. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
  71. package/src/components/RenderedResult/RenderedResult.tsx +39 -6
  72. package/src/components/RenderedResult/ResultContainer.tsx +99 -10
  73. package/src/components/RenderedResult/ResultPanel.tsx +25 -1
  74. package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
  75. package/src/components/RenderedResult/chartPresentation.ts +166 -0
  76. package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
  77. package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
  78. package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
  79. package/src/components/RenderedResult/resultSizing.ts +71 -11
  80. package/src/components/Report/Report.spec.tsx +19 -0
  81. package/src/components/Report/Report.tsx +8 -1
  82. package/src/components/Report/ReportPage.tsx +13 -1
  83. package/src/components/Report/layoutRules.spec.ts +43 -3
  84. package/src/components/Report/layoutRules.ts +70 -0
  85. package/src/components/Report/tileOverflow.spec.tsx +162 -0
  86. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
  87. package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
  88. package/src/components/ReportBuilder/ArrangeMenu.tsx +80 -0
  89. package/src/components/ReportBuilder/BuilderBar.tsx +5 -1
  90. package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -1
  91. package/src/components/ReportBuilder/BuilderGrid.tsx +142 -35
  92. package/src/components/ReportBuilder/BuilderToolbar.tsx +4 -0
  93. package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
  94. package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
  95. package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
  96. package/src/components/ReportBuilder/EditorSurface.tsx +101 -20
  97. package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
  98. package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
  99. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
  100. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
  101. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
  102. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +242 -2
  103. package/src/components/ReportBuilder/ReportBuilder.tsx +161 -27
  104. package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
  105. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
  106. package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
  107. package/src/components/ReportBuilder/ReportEditor.tsx +13 -0
  108. package/src/components/ReportBuilder/TileFrame.tsx +366 -170
  109. package/src/components/ReportBuilder/TileMenu.tsx +259 -20
  110. package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
  111. package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
  112. package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
  113. package/src/components/ReportBuilder/builderControls.ts +34 -0
  114. package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
  115. package/src/components/ReportBuilder/catalog.ts +90 -37
  116. package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
  117. package/src/components/ReportBuilder/chartLine.ts +80 -2
  118. package/src/components/ReportBuilder/controls.ts +4 -3
  119. package/src/components/ReportBuilder/document.ts +65 -7
  120. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  121. package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
  122. package/src/components/ReportBuilder/imports.ts +1 -1
  123. package/src/components/ReportBuilder/invariants.spec.ts +18 -10
  124. package/src/components/ReportBuilder/layout.ts +3 -0
  125. package/src/components/ReportBuilder/placement.spec.ts +401 -0
  126. package/src/components/ReportBuilder/placement.ts +416 -0
  127. package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
  128. package/src/components/ReportBuilder/preview.spec.ts +151 -11
  129. package/src/components/ReportBuilder/preview.ts +203 -40
  130. package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
  131. package/src/components/ReportBuilder/readDocument.spec.ts +53 -19
  132. package/src/components/ReportBuilder/readDocument.ts +197 -29
  133. package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
  134. package/src/components/ReportBuilder/sortable.tsx +30 -2
  135. package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
  136. package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
  137. package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
  138. package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -58
  139. package/src/components/ReportBuilder/spliceDocument.ts +139 -91
  140. package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
  141. package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
  142. package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
  143. package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
  144. package/src/components/ReportBuilder/useBuilderSession.ts +7 -2
  145. package/src/components/ReportBuilder/useBuilderShortcuts.ts +25 -1
  146. package/src/components/ReportBuilder/useEdgeResize.spec.tsx +324 -0
  147. package/src/components/ReportBuilder/useEdgeResize.ts +397 -0
  148. package/src/components/ReportBuilder/useTileEditing.ts +16 -3
  149. package/src/components/ReportBuilder/useTileReorder.ts +143 -6
  150. package/src/components/given/FilterButton.spec.tsx +27 -11
  151. package/src/components/given/FilterButton.tsx +19 -6
  152. package/src/theme/classes.ts +1 -1
  153. package/src/theme/resolveTheme.spec.ts +72 -1
  154. package/src/theme/resolveTheme.ts +43 -0
  155. package/src/utils/blankQuoted.spec.ts +50 -0
  156. package/src/utils/blankQuoted.ts +32 -0
  157. package/src/utils/malloyText.ts +2 -1
  158. package/dist/RenderedResult-DnBtf-cI.es.js +0 -593
  159. package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
  160. package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
  161. package/dist/components/ReportBuilder/useTileResize.d.ts +0 -32
  162. package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
  163. package/src/components/ReportBuilder/useTileResize.spec.tsx +0 -146
  164. package/src/components/ReportBuilder/useTileResize.ts +0 -133
@@ -7,6 +7,8 @@ import {
7
7
  isChartPick,
8
8
  mentionsChartTag,
9
9
  parseChartLine,
10
+ seriesColorLine,
11
+ seriesColorOf,
10
12
  type ChartPick,
11
13
  } from "./chartLine";
12
14
  import type {
@@ -17,7 +19,12 @@ import type {
17
19
  QueryTile,
18
20
  TextTile,
19
21
  } from "./document";
20
- import { isQueryTile, isTextTile } from "./document";
22
+ import {
23
+ isQueryTile,
24
+ isReadOnlyTile,
25
+ isTextTile,
26
+ tileExpression,
27
+ } from "./document";
21
28
  import type { LocalGiven } from "./document";
22
29
  import {
23
30
  artifactLine,
@@ -174,22 +181,33 @@ const writableChart = (
174
181
  ): ChartPick | "none" | undefined =>
175
182
  chart === "none" || isChartPick(chart) ? chart : undefined;
176
183
 
177
- /** The `#` tags a tile's presentation implies, in the order they are written. */
184
+ /**
185
+ * The `#` tags a tile's presentation implies, in the order they are written.
186
+ * Never its layout: that is written on its entry in `tiles=[…]`.
187
+ */
178
188
  function tagsFor(tile: QueryTile, withChart = true): string[] {
179
189
  const tags: string[] = [];
180
- if (tile.colspan !== undefined) tags.push(`# colspan=${tile.colspan}`);
181
- if (tile.break) tags.push("# break");
182
190
  if (tile.borderless) tags.push("# borderless");
183
191
  if (tile.label !== undefined) tags.push(`# label=${quoted(tile.label)}`);
184
192
  if (tile.subtitle !== undefined)
185
193
  tags.push(`# subtitle=${quoted(tile.subtitle)}`);
186
194
  const chart = withChart ? writableChart(tile.chart) : undefined;
187
195
  if (chart !== undefined) tags.push(chartLineText(chart, tile.chartCarried));
196
+ if (tile.color !== undefined) tags.push(seriesColorLine(tile.color));
188
197
  return tags;
189
198
  }
190
199
 
191
- /** Which property a tag line carries, so an existing line can be replaced. */
200
+ /** The key of the one-colour line the builder writes; see `seriesColorLine`. */
201
+ const SERIES_COLOR_KEY = "theme.palette.series";
202
+
203
+ /**
204
+ * Which property a tag line carries, so an existing line can be replaced. A
205
+ * colour line is keyed only when it is the builder's own one-colour form: a
206
+ * `# theme.palette.series` that lists a whole palette is the author's, and is
207
+ * keyed apart so it is never rewritten or removed.
208
+ */
192
209
  function tagKey(text: string): string | undefined {
210
+ if (seriesColorOf(text) !== undefined) return SERIES_COLOR_KEY;
193
211
  const m = /^#\s*([a-z_]+)/.exec(text);
194
212
  return m?.[1];
195
213
  }
@@ -211,6 +229,7 @@ const MODELLED_TAG_KEYS: ReadonlySet<string> = new Set([
211
229
  "borderless",
212
230
  "label",
213
231
  "subtitle",
232
+ SERIES_COLOR_KEY,
214
233
  ]);
215
234
 
216
235
  /**
@@ -430,9 +449,38 @@ function checkShape(
430
449
  };
431
450
  }
432
451
 
433
- /** A text entry's width and row break, which the list entry carries because the block has no tags. */
434
- const textEntryChanged = (was: TextTile, now: TextTile) =>
435
- was.colspan !== now.colspan || Boolean(was.break) !== Boolean(now.break);
452
+ /** The tag keys of a tile's layout, which a view declared here carries until the builder moves them to its entry. */
453
+ const LAYOUT_TAG_KEYS: ReadonlySet<string> = new Set(["colspan", "break"]);
454
+
455
+ /** Whether a tile's place on the grid changed: its width, row break, rowspan, row or column. */
456
+ const layoutChanged = (was: DashboardTile, now: DashboardTile) =>
457
+ was.colspan !== now.colspan ||
458
+ Boolean(was.break) !== Boolean(now.break) ||
459
+ was.rowspan !== now.rowspan ||
460
+ was.row !== now.row ||
461
+ was.col !== now.col;
462
+
463
+ /** A tile with its layout taken off, for asking whether anything ELSE about it changed. */
464
+ const withoutLayout = <T extends DashboardTile>(tile: T): T => {
465
+ const {
466
+ colspan: _c,
467
+ break: _b,
468
+ rowspan: _r,
469
+ row: _row,
470
+ col: _col,
471
+ ...rest
472
+ } = tile;
473
+ return rest as T;
474
+ };
475
+
476
+ /** The properties a tile's layout is written as on its entry. */
477
+ const layoutProperties = (tile: DashboardTile): string[] => [
478
+ ...(tile.row === undefined ? [] : [`row=${tile.row}`]),
479
+ ...(tile.col === undefined ? [] : [`col=${tile.col}`]),
480
+ ...(tile.colspan === undefined ? [] : [`colspan=${tile.colspan}`]),
481
+ ...(tile.break ? ["break"] : []),
482
+ ...(tile.rowspan === undefined ? [] : [`rowspan=${tile.rowspan}`]),
483
+ ];
436
484
 
437
485
  /** `text` with every quoted string blanked to `x`s of the same length, so a scan for syntax cannot land inside one. */
438
486
  function maskStrings(text: string): string {
@@ -449,14 +497,22 @@ function maskStrings(text: string): string {
449
497
  return out;
450
498
  }
451
499
 
452
- /** A `name { kind=text … }` entry with its `colspan` and `break` set as `tile` has them, every other property as written. */
453
- function textEntry(tile: TextTile, written?: string): string {
454
- if (written === undefined)
455
- return `${tile.name} { kind=text${
456
- tile.colspan === undefined ? "" : ` colspan=${tile.colspan}`
457
- }${tile.break ? " break" : ""} }`;
500
+ /**
501
+ * A tile's entry in `tiles=[…]` with its layout set as `tile` has it, and
502
+ * every other property as written: `name { kind=text … }` for prose, and
503
+ * `"source -> view"` for a query, with a `{ … }` only when it has layout.
504
+ */
505
+ function tileEntryText(tile: DashboardTile, written?: string): string {
506
+ const layout = layoutProperties(tile);
507
+ if (written === undefined) {
508
+ const head = isTextTile(tile) ? tile.name : `"${tileExpression(tile)}"`;
509
+ const props = [...(isTextTile(tile) ? ["kind=text"] : []), ...layout];
510
+ return props.length > 0 ? `${head} { ${props.join(" ")} }` : head;
511
+ }
458
512
  const masked = maskStrings(written);
459
513
  const open = masked.indexOf("{");
514
+ if (open === -1)
515
+ return layout.length > 0 ? `${written} { ${layout.join(" ")} }` : written;
460
516
  const close = masked.lastIndexOf("}");
461
517
  let inner = written.slice(open + 1, close);
462
518
  let maskedInner = masked.slice(open + 1, close);
@@ -470,12 +526,13 @@ function textEntry(tile: TextTile, written?: string): string {
470
526
  maskedInner.slice(hit.index + hit[0].length);
471
527
  };
472
528
  drop(/\s*\bcolspan\s*=\s*[^\s}]+/);
473
- drop(/\s*\bbreak\b(?!\s*=)/);
474
- const props = [
475
- inner.trim(),
476
- tile.colspan === undefined ? "" : `colspan=${tile.colspan}`,
477
- tile.break ? "break" : "",
478
- ].filter(Boolean);
529
+ drop(/\s*\bbreak\b(?:\s*=\s*[^\s}]+)?/);
530
+ drop(/\s*\browspan\s*=\s*[^\s}]+/);
531
+ drop(/\s*\brow\s*=\s*[^\s}]+/);
532
+ drop(/\s*\bcol\s*=\s*[^\s}]+/);
533
+ const props = [inner.trim(), ...layout].filter(Boolean);
534
+ // A query entry left with nothing in its braces is its expression alone.
535
+ if (props.length === 0) return written.slice(0, open).trimEnd();
479
536
  return `${written.slice(0, open)}{ ${props.join(" ")} }${written.slice(close + 1)}`;
480
537
  }
481
538
 
@@ -490,14 +547,12 @@ function planOrder(ctx: SpliceContext): SpliceFailure | undefined {
490
547
  nextKeys,
491
548
  edits,
492
549
  } = ctx;
493
- const wasText = new Map(
494
- current.tiles.filter(isTextTile).map((tile) => [tile.name, tile]),
495
- );
496
- const resized = next.tiles.filter(isTextTile).some((tile) => {
497
- const was = wasText.get(tile.name);
498
- return was !== undefined && textEntryChanged(was, tile);
550
+ const wasByKey = new Map(current.tiles.map((tile) => [tileKey(tile), tile]));
551
+ const resized = next.tiles.some((tile) => {
552
+ const was = wasByKey.get(tileKey(tile));
553
+ return was !== undefined && layoutChanged(was, tile);
499
554
  });
500
- // A reorder, and a text tile's width, are one rewritten array on the
555
+ // A reorder, and any tile's layout, are one rewritten array on the
501
556
  // `## artifact` line. Each entry is re-emitted AS IT WAS WRITTEN rather than
502
557
  // rebuilt from `source` and `name`, so a file that spells a tile
503
558
  // `overview->kpis` keeps its spelling and the diff is the change and nothing else.
@@ -526,33 +581,44 @@ function planOrder(ctx: SpliceContext): SpliceFailure | undefined {
526
581
  }
527
582
  const byKey = new Map<string, string>();
528
583
  for (const { text } of list.entries) {
529
- const quoted = /^"((?:[^"\\]|\\.)+)"$/.exec(text);
584
+ const quoted = /^"((?:[^"\\]|\\.)+)"\s*(?:\{[\s\S]*\})?$/.exec(text);
530
585
  if (quoted) {
531
586
  const parts = quoted[1].split("->").map((part) => part.trim());
532
587
  if (parts.length === 2) byKey.set(`${parts[0]}->${parts[1]}`, text);
588
+ // A named query: kept as written, never resolved to what it reads.
589
+ else if (parts.length === 1) byKey.set(`query.${parts[0]}`, text);
590
+ continue;
591
+ }
592
+ // A bare name is a named query too (`tiles=[by_carrier]`), kept bare.
593
+ if (isIdentifier(text)) {
594
+ byKey.set(`query.${text}`, text);
533
595
  continue;
534
596
  }
597
+ // `name { … }`: a text tile, or a bare named query carrying its layout.
535
598
  const name = /^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(text)?.[1];
536
- if (name !== undefined) byKey.set(`text.${name}`, text);
599
+ if (name !== undefined)
600
+ byKey.set(
601
+ /\bkind\s*=\s*text\b/.test(maskStrings(text))
602
+ ? `text.${name}`
603
+ : `query.${name}`,
604
+ text,
605
+ );
537
606
  }
538
607
  // An existing tile keeps its spelling; a new one is written canonically.
539
608
  const nextEntries = next.tiles.map((tile) => {
540
609
  const isNew = !currentKeys.has(tileKey(tile));
541
- if (isTextTile(tile)) {
542
- const written = byKey.get(`text.${tile.name}`);
543
- return written !== undefined
544
- ? wasText.has(tile.name) &&
545
- !textEntryChanged(wasText.get(tile.name), tile)
546
- ? written
547
- : textEntry(tile, written)
548
- : isNew
549
- ? textEntry(tile)
550
- : undefined;
551
- }
552
- return (
553
- byKey.get(`${tile.source}->${tile.name}`) ??
554
- (isNew ? `"${tile.source} -> ${tile.name}"` : undefined)
610
+ const written = byKey.get(
611
+ isTextTile(tile)
612
+ ? `text.${tile.name}`
613
+ : tile.declaration.kind === "query"
614
+ ? `query.${tile.name}`
615
+ : `${tile.source}->${tile.name}`,
555
616
  );
617
+ if (written === undefined) return isNew ? tileEntryText(tile) : undefined;
618
+ const was = wasByKey.get(tileKey(tile));
619
+ return was !== undefined && !layoutChanged(was, tile)
620
+ ? written
621
+ : tileEntryText(tile, written);
556
622
  });
557
623
  if (nextEntries.some((entry) => entry === undefined)) {
558
624
  return {
@@ -602,43 +668,6 @@ function arrayBody(
602
668
  return `${lead}${entries.join(separator)}${tail}`;
603
669
  }
604
670
 
605
- /**
606
- * `line` without one property of the artifact tag's own braces: spelled with
607
- * any spacing round the `=`, and never matched inside a quoted string or a
608
- * nested block.
609
- */
610
- function removeArtifactProperty(line: string, key: string): string {
611
- let depth = 0;
612
- let groups = 0;
613
- for (let i = 0; i < line.length; i++) {
614
- const c = line[i];
615
- if (c === '"') {
616
- i = endOfString(line, i);
617
- } else if (c === "{" || c === "[") {
618
- if (depth++ === 0) groups++;
619
- } else if (c === "}" || c === "]") {
620
- depth--;
621
- } else if (
622
- groups === 1 &&
623
- depth === 1 &&
624
- line.startsWith(key, i) &&
625
- !/[A-Za-z0-9_]/.test(line[i - 1] ?? " ")
626
- ) {
627
- const eq = /^\s*=\s*/.exec(line.slice(i + key.length));
628
- if (!eq) continue;
629
- const valueAt = i + key.length + eq[0].length;
630
- const valueEnd =
631
- line[valueAt] === '"'
632
- ? endOfString(line, valueAt) + 1
633
- : valueAt +
634
- (/^[^\s}]*/.exec(line.slice(valueAt))?.[0].length ?? 0);
635
- const from = i - (/\s*$/.exec(line.slice(0, i))?.[0].length ?? 0);
636
- return line.slice(0, from) + line.slice(valueEnd);
637
- }
638
- }
639
- return line;
640
- }
641
-
642
671
  /** `line` without its `dashboard { … }` block: outside the artifact braces and never inside a string. */
643
672
  function removeDashboardBlock(line: string): string {
644
673
  let depth = 0;
@@ -778,8 +807,6 @@ function planSettings(ctx: SpliceContext): SpliceFailure | undefined {
778
807
  line = `${line.slice(0, braceOpen + 1)}${inner.startsWith(" ") ? inner : ` ${inner}`}${inner.endsWith(" ") ? "" : " "}${line.slice(braceClose)}`;
779
808
  }
780
809
  if (current.columns !== next.columns) {
781
- // The deprecated alias would otherwise sit beside the new width and conflict with it.
782
- line = removeArtifactProperty(line, "dashboard_columns");
783
810
  line = removeDashboardBlock(line);
784
811
  if (next.columns !== undefined)
785
812
  line = `${line.trimEnd()} dashboard { columns=${next.columns} }`;
@@ -1149,9 +1176,10 @@ function planRemovedTiles(ctx: SpliceContext): SpliceFailure | undefined {
1149
1176
  const { lines, wholeLine, removedTiles, edits, parsed } = ctx;
1150
1177
  // REMOVED TILES: the declaration and its `#` tags. An inline view's body
1151
1178
  // runs to its closing brace; a reference is one line. An inherited tile has
1152
- // nothing here to remove — its entry left the artifact list above.
1179
+ // nothing here to remove — its entry left the artifact list above — and nor
1180
+ // does a named query, whose `query:` may be read by more than this list.
1153
1181
  for (const tile of removedTiles) {
1154
- if (isTextTile(tile) || tile.declaration.kind === "inherited") continue;
1182
+ if (isTextTile(tile) || isReadOnlyTile(tile)) continue;
1155
1183
  const view = viewOf(ctx, tile);
1156
1184
  if (!view) {
1157
1185
  return {
@@ -1340,23 +1368,37 @@ function planTilePresentation(ctx: SpliceContext): SpliceFailure | undefined {
1340
1368
  const was = currentByKey.get(tileKey(tile));
1341
1369
  // Written whole above, tags and all; a text tile has no declaration to retag.
1342
1370
  if (was === undefined || isTextTile(tile) || isTextTile(was)) continue;
1343
- if (
1344
- canonical(withoutDefaultChart(was)) ===
1345
- canonical(withoutDefaultChart(tile))
1346
- )
1347
- continue;
1371
+ // A layout change is written on the entry (`planOrder`); here it only
1372
+ // takes the view's own `# colspan` and `# break` off, so the entry is
1373
+ // the one place the layout lives.
1374
+ const moved = layoutChanged(was, tile);
1375
+ const presented =
1376
+ canonical(withoutLayout(withoutDefaultChart(was))) !==
1377
+ canonical(withoutLayout(withoutDefaultChart(tile)));
1378
+ if (!presented && !moved) continue;
1348
1379
 
1349
1380
  // Declared in the model, not here, so there is nothing in this file to
1350
1381
  // patch -- saying so beats writing a tag that would land on the wrong
1351
- // object.
1382
+ // object. Its layout is its entry's, which is this file's.
1352
1383
  if (tile.declaration.kind === "inherited") {
1384
+ if (!presented) continue;
1353
1385
  return {
1354
1386
  ok: false,
1355
1387
  reason:
1356
- `\`${tile.source} -> ${tile.name}\` is declared on its source, ` +
1388
+ `\`${tileExpression(tile)}\` is declared on its source, ` +
1357
1389
  `not in this report, so its presentation cannot be changed here.`,
1358
1390
  };
1359
1391
  }
1392
+ // Its layout is its entry's too, which wins over the query's own tags.
1393
+ if (tile.declaration.kind === "query") {
1394
+ if (!presented) continue;
1395
+ return {
1396
+ ok: false,
1397
+ reason:
1398
+ `\`${tile.name}\` names a query, whose presentation is the ` +
1399
+ `query's own, so it cannot be changed here.`,
1400
+ };
1401
+ }
1360
1402
 
1361
1403
  // An `opaque` tile falls through on purpose: its TAGS are ordinary `#`
1362
1404
  // lines in this file, so a label or colspan change is safe. Only a filter
@@ -1426,6 +1468,12 @@ function planTilePresentation(ctx: SpliceContext): SpliceFailure | undefined {
1426
1468
  const key = tagKey(tag.text);
1427
1469
  // Not a property this document models: not ours to touch.
1428
1470
  if (key === undefined || !MODELLED_TAG_KEYS.has(key)) continue;
1471
+ // The view's layout stays put until the tile's layout changes, and
1472
+ // then it moves to the entry.
1473
+ if (LAYOUT_TAG_KEYS.has(key)) {
1474
+ if (moved) edits.push({ ...wholeLine(tag.line), text: "" });
1475
+ continue;
1476
+ }
1429
1477
  const want = wantedByKey.get(key);
1430
1478
  if (want === undefined) {
1431
1479
  // Removed: take the whole line, including its newline.
@@ -60,7 +60,7 @@ ${stage}
60
60
  expect(out).not.toContain("where:");
61
61
  expect(out).not.toContain("b ~ $B");
62
62
  expect(out).toContain(" aggregate: n is count()");
63
- expect(out).toContain("# colspan=4");
63
+ expect(out).toContain('"a -> kpis" { colspan=4 }');
64
64
  });
65
65
 
66
66
  // Dropping ONE clause of the pair leaves the other exactly, separator and
@@ -103,7 +103,7 @@ source: a is one extend {
103
103
  d.tiles[0].colspan = 4;
104
104
  });
105
105
  expect(out).toContain(" where: a ~ $A\n and c = 1");
106
- expect(out).toContain("# colspan=4");
106
+ expect(out).toContain('"a -> kpis" { colspan=4 }');
107
107
  });
108
108
  });
109
109
 
@@ -419,7 +419,7 @@ source: a is one extend {
419
419
  d.tiles[0].colspan = 4;
420
420
  });
421
421
  expect(out).toContain("vx -> { group_by: b }");
422
- expect(out).toContain("# colspan=4");
422
+ expect(out).toContain('"a -> kpis" { colspan=4 }');
423
423
  });
424
424
 
425
425
  it("refuses a filter change rather than writing into a stage", async () => {
@@ -0,0 +1,42 @@
1
+ {
2
+ "_comment": "One case table for the reader's control row order (server, report_given_order.spec.ts) and the builder's (SDK, preview.spec.ts). `tiles` is each tile's served givenNames; `row` is manifest.givens by name.",
3
+ "model": "##! experimental.givens\ngiven:\n MANUFACTURER :: filter<string> is f''\n\nsource: all_recalls is duckdb.sql(\"\"\"select 'a' as maker, 's' as subject, DATE '2020-01-01' as recall_date\"\"\") extend {\n view: by_year is { group_by: recall_date; aggregate: n is count() }\n view: by_subject is { group_by: subject; aggregate: n is count() }\n}\n\nsource: recalls is all_recalls extend {\n where: maker ~ $MANUFACTURER\n}\n",
4
+ "cases": [
5
+ {
6
+ "name": "the model's read first, then each tile's bindings",
7
+ "report": "##! experimental.givens\nimport \"recalls.malloy\"\n\ngiven:\n SUBJECT :: filter<string> is f''\n SINCE :: filter<date> is f''\n\n## artifact { layout=grid tiles=[\"recalls_tiles -> year_tile\", \"recalls_tiles -> subject_tile\"] }\nsource: recalls_tiles is recalls extend {\n view: year_tile is by_year + { where: subject ~ $SUBJECT; where: recall_date ~ $SINCE }\n view: subject_tile is by_subject\n}\n",
8
+ "tiles": {
9
+ "recalls_tiles -> year_tile": ["MANUFACTURER", "SUBJECT", "SINCE"],
10
+ "recalls_tiles -> subject_tile": ["MANUFACTURER"]
11
+ },
12
+ "row": ["MANUFACTURER", "SUBJECT", "SINCE"]
13
+ },
14
+ {
15
+ "name": "a binding on the second tile follows the first tile's reads",
16
+ "report": "##! experimental.givens\nimport \"recalls.malloy\"\n\ngiven:\n SUBJECT :: filter<string> is f''\n SINCE :: filter<date> is f''\n\n## artifact { layout=grid tiles=[\"recalls_tiles -> year_tile\", \"recalls_tiles -> subject_tile\"] }\nsource: recalls_tiles is recalls extend {\n view: year_tile is by_year + { where: recall_date ~ $SINCE }\n view: subject_tile is by_subject + { where: subject ~ $SUBJECT }\n}\n",
17
+ "tiles": {
18
+ "recalls_tiles -> year_tile": ["MANUFACTURER", "SINCE"],
19
+ "recalls_tiles -> subject_tile": ["MANUFACTURER", "SUBJECT"]
20
+ },
21
+ "row": ["MANUFACTURER", "SINCE", "SUBJECT"]
22
+ },
23
+ {
24
+ "name": "a tile's bindings in the order it binds them, not declaration order",
25
+ "report": "##! experimental.givens\nimport \"recalls.malloy\"\n\ngiven:\n SUBJECT :: filter<string> is f''\n SINCE :: filter<date> is f''\n\n## artifact { layout=grid tiles=[\"recalls_tiles -> year_tile\", \"recalls_tiles -> subject_tile\"] }\nsource: recalls_tiles is recalls extend {\n view: year_tile is by_year + { where: recall_date ~ $SINCE; where: subject ~ $SUBJECT }\n view: subject_tile is by_subject\n}\n",
26
+ "tiles": {
27
+ "recalls_tiles -> year_tile": ["MANUFACTURER", "SINCE", "SUBJECT"],
28
+ "recalls_tiles -> subject_tile": ["MANUFACTURER"]
29
+ },
30
+ "row": ["MANUFACTURER", "SINCE", "SUBJECT"]
31
+ },
32
+ {
33
+ "name": "a model given only a later tile reads comes after an earlier tile's binding",
34
+ "report": "##! experimental.givens\nimport \"recalls.malloy\"\n\ngiven:\n SUBJECT :: filter<string> is f''\n SINCE :: filter<date> is f''\n\n## artifact { layout=grid tiles=[\"all_tiles -> year_tile\", \"recalls_tiles -> subject_tile\"] }\nsource: all_tiles is all_recalls extend {\n view: year_tile is by_year + { where: recall_date ~ $SINCE }\n}\n\nsource: recalls_tiles is recalls extend {\n view: subject_tile is by_subject + { where: subject ~ $SUBJECT }\n}\n",
35
+ "tiles": {
36
+ "all_tiles -> year_tile": ["SINCE"],
37
+ "recalls_tiles -> subject_tile": ["MANUFACTURER", "SUBJECT"]
38
+ },
39
+ "row": ["SINCE", "MANUFACTURER", "SUBJECT"]
40
+ }
41
+ ]
42
+ }
@@ -196,9 +196,9 @@ describe("readDashboardDocument: text tiles and layout", () => {
196
196
  expect(result.reason).toContain("outro");
197
197
  });
198
198
 
199
- it("refuses a quoted entry that is not source -> view", async () => {
199
+ it("refuses a quoted entry that is neither source -> view nor a query's name", async () => {
200
200
  const result = await readDashboardDocument(
201
- NOTEBOOK.replace('"a_tiles -> cell_1"', '"a_tiles"'),
201
+ NOTEBOOK.replace('"a_tiles -> cell_1"', '"a_tiles -> cell_1 -> x"'),
202
202
  );
203
203
  if (!readFailed(result)) throw new Error("expected a refusal");
204
204
  expect(result.reason).toContain("source -> view");
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { tileTitle } from "../Dashboard/DashboardTile";
5
- import type { QueryTile } from "./document";
5
+ import { tileExpression, type QueryTile } from "./document";
6
6
 
7
7
  /**
8
8
  * The title a query tile is drawn under when it has no label of its own: the
@@ -10,4 +10,4 @@ import type { QueryTile } from "./document";
10
10
  * live tile, a placeholder and the menu agree.
11
11
  */
12
12
  export const tileDisplayTitle = (tile: QueryTile): string =>
13
- tile.label ?? tileTitle(`${tile.source} -> ${tile.name}`);
13
+ tile.label ?? tileTitle(tileExpression(tile));
@@ -79,7 +79,10 @@ export interface BuilderSessionOptions<D, L extends LastSave = LastSave> {
79
79
  /** Runs before every save entry point, handing it the save to run once the document is ready. */
80
80
  prepare?: (run: () => Promise<void> | void) => Promise<void> | void;
81
81
  /** The builder's own keys, less undo, redo and save, which the session owns. Memoized by the caller. */
82
- shortcuts: Pick<BuilderShortcutHandlers, "escape" | "nudge">;
82
+ shortcuts: Pick<
83
+ BuilderShortcutHandlers,
84
+ "escape" | "nudge" | "move" | "paused"
85
+ >;
83
86
  }
84
87
 
85
88
  /**
@@ -216,7 +219,9 @@ export function useBuilderSession<
216
219
  undo: editor.undo,
217
220
  redo: editor.redo,
218
221
  ...(onSave ? { save } : {}),
219
- paused: exitGuard.dialog.open,
222
+ // Paused by the exit dialog, or by the builder itself (an edge
223
+ // dragged, whose release would write over a mid-drag undo).
224
+ paused: exitGuard.dialog.open || shortcuts.paused === true,
220
225
  }),
221
226
  [shortcuts, editor, onSave, save, exitGuard.dialog.open],
222
227
  ),
@@ -8,7 +8,8 @@ import { useEffect, useRef, useState } from "react";
8
8
  *
9
9
  * Undo and redo on the platform's usual keys, save on ⌘S / Ctrl+S (which the
10
10
  * browser would otherwise take), Escape to drop the selection, and the arrow
11
- * keys to nudge the selected tile's width a column at a time.
11
+ * keys to nudge the selected tile's width a column at a time; with Option/Alt
12
+ * held, they move a placed tile one cell.
12
13
  *
13
14
  * Nothing but Escape and save fires while a text field has focus, so typing
14
15
  * into a title never undoes a layout. Save leaves the field first, so its
@@ -21,6 +22,13 @@ export interface BuilderShortcutHandlers {
21
22
  escape: () => void;
22
23
  /** Nudge the selected tile's width by ±1 column. Absent, the arrow keys are left alone. */
23
24
  nudge?: (delta: 1 | -1) => void;
25
+ /**
26
+ * Move the selected tile one cell with Option/Alt and an arrow key, on a
27
+ * report whose tiles are placed. Answers whether it moved one: when it did
28
+ * not (nothing placed is selected), the key is left to the browser, which
29
+ * uses Alt with an arrow for Back and Forward.
30
+ */
31
+ move?: (rows: -1 | 0 | 1, cols: -1 | 0 | 1) => boolean;
24
32
  /** A modal owns the keyboard: no shortcut fires, so none can open a second dialog over it. */
25
33
  paused?: boolean;
26
34
  }
@@ -107,6 +115,22 @@ export function useBuilderShortcuts(handlers: BuilderShortcutHandlers) {
107
115
  current.save?.();
108
116
  return;
109
117
  }
118
+ if (current.move && event.altKey && !mod && !event.shiftKey) {
119
+ const step =
120
+ event.key === "ArrowLeft"
121
+ ? ([0, -1] as const)
122
+ : event.key === "ArrowRight"
123
+ ? ([0, 1] as const)
124
+ : event.key === "ArrowUp"
125
+ ? ([-1, 0] as const)
126
+ : event.key === "ArrowDown"
127
+ ? ([1, 0] as const)
128
+ : undefined;
129
+ if (step && current.move(step[0], step[1])) {
130
+ event.preventDefault();
131
+ return;
132
+ }
133
+ }
110
134
  if (
111
135
  current.nudge &&
112
136
  !mod &&