@malloy-publisher/sdk 0.9.13 → 0.9.15

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 (148) hide show
  1. package/dist/RenderedResult-BClN_PG6.cjs.js +154 -0
  2. package/dist/{RenderedResult-DnBtf-cI.es.js → RenderedResult-YBzVMVH2.es.js} +295 -234
  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 +7430 -6548
  7. package/dist/client/api.d.ts +30 -6
  8. package/dist/client/index.cjs.js +1 -1
  9. package/dist/client/index.es.js +1 -1
  10. package/dist/components/Dashboard/DashboardGrid.d.ts +49 -1
  11. package/dist/components/Dashboard/DashboardTile.d.ts +5 -2
  12. package/dist/components/Dashboard/DashboardView.d.ts +9 -2
  13. package/dist/components/Dashboard/index.d.ts +1 -1
  14. package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
  15. package/dist/components/Dashboard/useStuck.d.ts +18 -12
  16. package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
  17. package/dist/components/RenderedResult/ResultContainer.d.ts +11 -1
  18. package/dist/components/RenderedResult/ResultPanel.d.ts +5 -1
  19. package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
  20. package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
  21. package/dist/components/RenderedResult/resultSizing.d.ts +42 -6
  22. package/dist/components/Report/Report.d.ts +7 -1
  23. package/dist/components/Report/ReportPage.d.ts +7 -0
  24. package/dist/components/Report/layoutRules.d.ts +45 -0
  25. package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
  26. package/dist/components/ReportBuilder/BuilderGrid.d.ts +14 -1
  27. package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
  28. package/dist/components/ReportBuilder/EditorSurface.d.ts +17 -1
  29. package/dist/components/ReportBuilder/ReportEditor.d.ts +18 -0
  30. package/dist/components/ReportBuilder/TileFrame.d.ts +33 -1
  31. package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
  32. package/dist/components/ReportBuilder/catalog.d.ts +23 -0
  33. package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
  34. package/dist/components/ReportBuilder/controls.d.ts +2 -2
  35. package/dist/components/ReportBuilder/document.d.ts +53 -5
  36. package/dist/components/ReportBuilder/imports.d.ts +7 -0
  37. package/dist/components/ReportBuilder/placement.d.ts +75 -0
  38. package/dist/components/ReportBuilder/preview.d.ts +59 -10
  39. package/dist/components/ReportBuilder/sortable.d.ts +3 -1
  40. package/dist/components/ReportBuilder/useTileHeight.d.ts +39 -0
  41. package/dist/components/ReportBuilder/useTileReorder.d.ts +27 -3
  42. package/dist/components/ReportBuilder/useTileResize.d.ts +8 -0
  43. package/dist/index.cjs.js +7 -7
  44. package/dist/index.es.js +3328 -3287
  45. package/dist/text/index.es.js +1 -1
  46. package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
  47. package/dist/theme/resolveTheme.d.ts +15 -0
  48. package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-BGk38oaW.es.js} +5097 -4805
  49. package/dist/useCompiledDocument-D9t5ry_t.cjs.js +142 -0
  50. package/dist/utils/blankQuoted.d.ts +15 -0
  51. package/package.json +1 -1
  52. package/src/components/Dashboard/DashboardGrid.tsx +127 -10
  53. package/src/components/Dashboard/DashboardTile.tsx +11 -1
  54. package/src/components/Dashboard/DashboardView.tsx +63 -10
  55. package/src/components/Dashboard/TileCard.tsx +6 -0
  56. package/src/components/Dashboard/index.ts +1 -0
  57. package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
  58. package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
  59. package/src/components/Dashboard/tileHeight.spec.ts +72 -0
  60. package/src/components/Dashboard/useStuck.ts +76 -28
  61. package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
  62. package/src/components/Package/NewDocumentDialog.tsx +10 -11
  63. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
  64. package/src/components/RenderedResult/RenderedResult.tsx +21 -6
  65. package/src/components/RenderedResult/ResultContainer.tsx +60 -7
  66. package/src/components/RenderedResult/ResultPanel.tsx +21 -1
  67. package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
  68. package/src/components/RenderedResult/chartPresentation.ts +166 -0
  69. package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
  70. package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
  71. package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
  72. package/src/components/RenderedResult/resultSizing.ts +65 -11
  73. package/src/components/Report/Report.spec.tsx +19 -0
  74. package/src/components/Report/Report.tsx +8 -1
  75. package/src/components/Report/ReportPage.tsx +13 -1
  76. package/src/components/Report/layoutRules.spec.ts +43 -3
  77. package/src/components/Report/layoutRules.ts +70 -0
  78. package/src/components/Report/tileOverflow.spec.tsx +162 -0
  79. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
  80. package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
  81. package/src/components/ReportBuilder/BuilderBar.tsx +1 -1
  82. package/src/components/ReportBuilder/BuilderDialogs.tsx +20 -0
  83. package/src/components/ReportBuilder/BuilderGrid.tsx +126 -20
  84. package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
  85. package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
  86. package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
  87. package/src/components/ReportBuilder/EditorSurface.tsx +110 -28
  88. package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
  89. package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
  90. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
  91. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
  92. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
  93. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +143 -2
  94. package/src/components/ReportBuilder/ReportBuilder.tsx +73 -19
  95. package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
  96. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
  97. package/src/components/ReportBuilder/ReportEditor.queryVersion.spec.tsx +292 -0
  98. package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
  99. package/src/components/ReportBuilder/ReportEditor.tsx +35 -0
  100. package/src/components/ReportBuilder/TileFrame.tsx +251 -6
  101. package/src/components/ReportBuilder/TileMenu.tsx +259 -20
  102. package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
  103. package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
  104. package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
  105. package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
  106. package/src/components/ReportBuilder/catalog.ts +90 -37
  107. package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
  108. package/src/components/ReportBuilder/chartLine.ts +80 -2
  109. package/src/components/ReportBuilder/controls.ts +4 -3
  110. package/src/components/ReportBuilder/document.ts +65 -7
  111. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  112. package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
  113. package/src/components/ReportBuilder/imports.ts +1 -1
  114. package/src/components/ReportBuilder/invariants.spec.ts +18 -10
  115. package/src/components/ReportBuilder/layout.ts +3 -0
  116. package/src/components/ReportBuilder/placement.spec.ts +193 -0
  117. package/src/components/ReportBuilder/placement.ts +250 -0
  118. package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
  119. package/src/components/ReportBuilder/preview.spec.ts +151 -11
  120. package/src/components/ReportBuilder/preview.ts +203 -40
  121. package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
  122. package/src/components/ReportBuilder/readDocument.spec.ts +46 -2
  123. package/src/components/ReportBuilder/readDocument.ts +194 -23
  124. package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
  125. package/src/components/ReportBuilder/sortable.tsx +4 -0
  126. package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
  127. package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
  128. package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
  129. package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -18
  130. package/src/components/ReportBuilder/spliceDocument.ts +139 -52
  131. package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
  132. package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
  133. package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
  134. package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
  135. package/src/components/ReportBuilder/useTileEditing.ts +16 -3
  136. package/src/components/ReportBuilder/useTileHeight.ts +149 -0
  137. package/src/components/ReportBuilder/useTileReorder.ts +143 -6
  138. package/src/components/ReportBuilder/useTileResize.ts +16 -1
  139. package/src/components/given/FilterButton.spec.tsx +27 -11
  140. package/src/components/given/FilterButton.tsx +19 -6
  141. package/src/theme/resolveTheme.spec.ts +72 -1
  142. package/src/theme/resolveTheme.ts +43 -0
  143. package/src/utils/blankQuoted.spec.ts +50 -0
  144. package/src/utils/blankQuoted.ts +32 -0
  145. package/src/utils/malloyText.ts +2 -1
  146. package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
  147. package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
  148. package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
@@ -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 {
@@ -1149,9 +1215,10 @@ function planRemovedTiles(ctx: SpliceContext): SpliceFailure | undefined {
1149
1215
  const { lines, wholeLine, removedTiles, edits, parsed } = ctx;
1150
1216
  // REMOVED TILES: the declaration and its `#` tags. An inline view's body
1151
1217
  // 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.
1218
+ // nothing here to remove — its entry left the artifact list above — and nor
1219
+ // does a named query, whose `query:` may be read by more than this list.
1153
1220
  for (const tile of removedTiles) {
1154
- if (isTextTile(tile) || tile.declaration.kind === "inherited") continue;
1221
+ if (isTextTile(tile) || isReadOnlyTile(tile)) continue;
1155
1222
  const view = viewOf(ctx, tile);
1156
1223
  if (!view) {
1157
1224
  return {
@@ -1340,23 +1407,37 @@ function planTilePresentation(ctx: SpliceContext): SpliceFailure | undefined {
1340
1407
  const was = currentByKey.get(tileKey(tile));
1341
1408
  // Written whole above, tags and all; a text tile has no declaration to retag.
1342
1409
  if (was === undefined || isTextTile(tile) || isTextTile(was)) continue;
1343
- if (
1344
- canonical(withoutDefaultChart(was)) ===
1345
- canonical(withoutDefaultChart(tile))
1346
- )
1347
- continue;
1410
+ // A layout change is written on the entry (`planOrder`); here it only
1411
+ // takes the view's own `# colspan` and `# break` off, so the entry is
1412
+ // the one place the layout lives.
1413
+ const moved = layoutChanged(was, tile);
1414
+ const presented =
1415
+ canonical(withoutLayout(withoutDefaultChart(was))) !==
1416
+ canonical(withoutLayout(withoutDefaultChart(tile)));
1417
+ if (!presented && !moved) continue;
1348
1418
 
1349
1419
  // Declared in the model, not here, so there is nothing in this file to
1350
1420
  // patch -- saying so beats writing a tag that would land on the wrong
1351
- // object.
1421
+ // object. Its layout is its entry's, which is this file's.
1352
1422
  if (tile.declaration.kind === "inherited") {
1423
+ if (!presented) continue;
1353
1424
  return {
1354
1425
  ok: false,
1355
1426
  reason:
1356
- `\`${tile.source} -> ${tile.name}\` is declared on its source, ` +
1427
+ `\`${tileExpression(tile)}\` is declared on its source, ` +
1357
1428
  `not in this report, so its presentation cannot be changed here.`,
1358
1429
  };
1359
1430
  }
1431
+ // Its layout is its entry's too, which wins over the query's own tags.
1432
+ if (tile.declaration.kind === "query") {
1433
+ if (!presented) continue;
1434
+ return {
1435
+ ok: false,
1436
+ reason:
1437
+ `\`${tile.name}\` names a query, whose presentation is the ` +
1438
+ `query's own, so it cannot be changed here.`,
1439
+ };
1440
+ }
1360
1441
 
1361
1442
  // An `opaque` tile falls through on purpose: its TAGS are ordinary `#`
1362
1443
  // lines in this file, so a label or colspan change is safe. Only a filter
@@ -1426,6 +1507,12 @@ function planTilePresentation(ctx: SpliceContext): SpliceFailure | undefined {
1426
1507
  const key = tagKey(tag.text);
1427
1508
  // Not a property this document models: not ours to touch.
1428
1509
  if (key === undefined || !MODELLED_TAG_KEYS.has(key)) continue;
1510
+ // The view's layout stays put until the tile's layout changes, and
1511
+ // then it moves to the entry.
1512
+ if (LAYOUT_TAG_KEYS.has(key)) {
1513
+ if (moved) edits.push({ ...wholeLine(tag.line), text: "" });
1514
+ continue;
1515
+ }
1429
1516
  const want = wantedByKey.get(key);
1430
1517
  if (want === undefined) {
1431
1518
  // 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));
@@ -1,6 +1,7 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
+ import { placeAtEnd } from "./placement";
4
5
  import { useState } from "react";
5
6
  import type { NewTile } from "./AddTileDialog";
6
7
  import {
@@ -56,14 +57,20 @@ export function useTileEditing({
56
57
  /** A tile from the picker: on the extension of its source, or a new one. */
57
58
  const addTile = (tile: NewTile) => {
58
59
  setAddingTile(false);
59
- editor.update((draft) =>
60
+ editor.update((draft) => {
60
61
  addTileToDocument(draft, tile, {
61
62
  modelPath,
62
63
  textHeld,
63
64
  widths: rules.widths,
64
65
  insertAt,
65
- }),
66
- );
66
+ });
67
+ if (rules.widths)
68
+ draft.tiles = placeAtEnd(
69
+ draft.tiles,
70
+ insertAt ?? draft.tiles.length - 1,
71
+ rules.columns,
72
+ );
73
+ });
67
74
  selectTile(insertAt ?? editor.document.tiles.length);
68
75
  };
69
76
 
@@ -85,6 +92,12 @@ export function useTileEditing({
85
92
  markdown: "",
86
93
  ...(rules.widths ? { colspan: rules.columns } : {}),
87
94
  });
95
+ if (rules.widths)
96
+ draft.tiles = placeAtEnd(
97
+ draft.tiles,
98
+ at ?? draft.tiles.length - 1,
99
+ rules.columns,
100
+ );
88
101
  });
89
102
  selectTile(at ?? editor.document.tiles.length);
90
103
  };
@@ -0,0 +1,149 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { useEffect, useRef, useState, type RefObject } from "react";
5
+ import { rowsForHeight, tileHeightPx } from "../Dashboard/DashboardGrid";
6
+ import { tileKey, type DashboardTile } from "./document";
7
+ import { minRowsOf } from "./placement";
8
+
9
+ /** A height drag in flight: the tile, what it WOULD be, and where its top sits. */
10
+ export interface HeightState {
11
+ index: number;
12
+ /** The rows it would be, or undefined for auto: no `rowspan`, as tall as its row. */
13
+ rows: number | undefined;
14
+ /** Its `rowspan` when the drag began: a release that changed nothing writes nothing. */
15
+ from: number | undefined;
16
+ top: number;
17
+ /** The tile's top against the grid's, where the row guides are drawn from. */
18
+ guideTop: number;
19
+ }
20
+
21
+ /** While the edge is dragged the page stops selecting text and keeps one cursor, as a width drag does. */
22
+ const dragChrome = (on: boolean) => {
23
+ const body = window.document.body;
24
+ body.style.userSelect = on ? "none" : "";
25
+ body.style.cursor = on ? "row-resize" : "";
26
+ };
27
+
28
+ /**
29
+ * Dragging a tile's bottom edge to set its `rowspan`, in whole grid rows, or
30
+ * back to auto. Previewed by the caller from `height.rows` and written ONCE,
31
+ * on release, so one gesture is one undo step.
32
+ *
33
+ * Auto is a snap point of its own. A tile with no `rowspan` is as tall as its
34
+ * row, and a row of such tiles is as tall as its tallest content, which is
35
+ * almost never a whole number of rows: 492px sits between 5 rows (464) and 6
36
+ * (560). With rows alone a tile could never be dragged level with an auto
37
+ * neighbour; snapping to the row's own height, and writing that as no
38
+ * `rowspan`, is what makes level reachable.
39
+ */
40
+ export function useTileHeight({
41
+ tiles,
42
+ gridBox,
43
+ onStart,
44
+ commit,
45
+ }: {
46
+ tiles: readonly DashboardTile[];
47
+ /** Wraps the grid: row-mates are found in it and the row guides are placed against it. */
48
+ gridBox: RefObject<HTMLDivElement | null>;
49
+ /** The tile a drag begins on, which the caller selects. */
50
+ onStart: (index: number) => void;
51
+ /** What to write when the drag ends: rows, or undefined to take the `rowspan` off. */
52
+ commit: (index: number, rows: number | undefined) => void;
53
+ }) {
54
+ const [height, setHeightState] = useState<HeightState | undefined>(
55
+ undefined,
56
+ );
57
+ // The gesture as the handlers last left it: a release can arrive before
58
+ // the render for the last move does.
59
+ const live = useRef<HeightState | undefined>(undefined);
60
+ // A tile that began on auto: its height then, which was its row's.
61
+ const startedAuto = useRef<number | undefined>(undefined);
62
+ const setHeight = (next: HeightState | undefined) => {
63
+ live.current = next;
64
+ setHeightState(next);
65
+ };
66
+ useEffect(() => () => dragChrome(false), []);
67
+
68
+ /**
69
+ * How tall the row is when this tile is on auto: the tallest of the auto
70
+ * tiles beside it, measured now. A neighbour stretched by this tile's own
71
+ * preview reads as that preview's height, which ties with it and loses;
72
+ * once the preview is shorter than the row, the neighbours read their own
73
+ * height and auto wins. Undefined when nothing says how tall auto would be.
74
+ */
75
+ const autoHeight = (drag: HeightState): number | undefined => {
76
+ const auto = new Set(
77
+ tiles.filter((tile) => tile.rowspan === undefined).map(tileKey),
78
+ );
79
+ const self = tiles[drag.index];
80
+ let tallest = startedAuto.current;
81
+ for (const frame of gridBox.current?.querySelectorAll<HTMLElement>(
82
+ "[data-tile-key]",
83
+ ) ?? []) {
84
+ const key = frame.dataset.tileKey;
85
+ if (!key || !auto.has(key) || (self && key === tileKey(self)))
86
+ continue;
87
+ const box = frame.getBoundingClientRect();
88
+ if (Math.abs(box.top - drag.top) > 1) continue;
89
+ tallest = Math.max(tallest ?? 0, box.height);
90
+ }
91
+ return tallest;
92
+ };
93
+
94
+ const startHeight = (
95
+ event: React.PointerEvent<HTMLDivElement>,
96
+ index: number,
97
+ ) => {
98
+ const tile = event.currentTarget.parentElement?.getBoundingClientRect();
99
+ const grid = gridBox.current?.getBoundingClientRect();
100
+ if (!tile || !grid) return;
101
+ event.stopPropagation();
102
+ event.preventDefault();
103
+ event.currentTarget.setPointerCapture(event.pointerId);
104
+ dragChrome(true);
105
+ onStart(index);
106
+ const from = tiles[index]?.rowspan;
107
+ startedAuto.current = from === undefined ? tile.height : undefined;
108
+ setHeight({
109
+ index,
110
+ rows: from,
111
+ from,
112
+ top: tile.top,
113
+ guideTop: tile.top - grid.top,
114
+ });
115
+ };
116
+
117
+ const onHeight = (event: React.PointerEvent<HTMLDivElement>) => {
118
+ const drag = live.current;
119
+ if (!drag) return;
120
+ const px = event.clientY - drag.top;
121
+ const self = tiles[drag.index];
122
+ const rows = rowsForHeight(px, self ? minRowsOf(self) : undefined);
123
+ const auto = autoHeight(drag);
124
+ // Ties go to rows: a neighbour stretched to the preview is no reason to leave it.
125
+ const next =
126
+ auto !== undefined &&
127
+ Math.abs(px - auto) < Math.abs(px - tileHeightPx(rows))
128
+ ? undefined
129
+ : rows;
130
+ if (next !== drag.rows) setHeight({ ...drag, rows: next });
131
+ };
132
+
133
+ const endHeight = (event: React.PointerEvent<HTMLDivElement>) => {
134
+ if (event.currentTarget.hasPointerCapture(event.pointerId))
135
+ event.currentTarget.releasePointerCapture(event.pointerId);
136
+ dragChrome(false);
137
+ const drag = live.current;
138
+ if (!drag) return;
139
+ const { index, rows, from } = drag;
140
+ setHeight(undefined);
141
+ startedAuto.current = undefined;
142
+ // A cancelled gesture puts the height back, and a press that moved
143
+ // nothing writes nothing.
144
+ if (event.type === "pointercancel" || rows === from) return;
145
+ commit(index, rows);
146
+ };
147
+
148
+ return { height, startHeight, onHeight, endHeight };
149
+ }