@malloy-publisher/sdk 0.4.1 → 0.5.0

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 (59) hide show
  1. package/dist/{DocumentStorage-BiFqO15i.es.js → DocumentStorage-B04sZ5Ie.es.js} +2284 -2319
  2. package/dist/{DocumentStorage-CMyLifsz.cjs.js → DocumentStorage-B_MMJ0Ot.cjs.js} +29 -29
  3. package/dist/{RenderedResult-CvrmYyr5.es.js → RenderedResult-BB7eokcf.es.js} +100 -80
  4. package/dist/{RenderedResult-CZzE8wv-.cjs.js → RenderedResult-DVuGhatg.cjs.js} +27 -7
  5. package/dist/ServerProvider-D-jjzfE5.cjs.js +1 -0
  6. package/dist/{ServerProvider-BWOEKg0O.es.js → ServerProvider-Do-GBvpn.es.js} +492 -481
  7. package/dist/builder/index.cjs.js +54 -49
  8. package/dist/builder/index.es.js +4124 -3521
  9. package/dist/client/api.d.ts +14 -1
  10. package/dist/client/index.cjs.js +1 -1
  11. package/dist/client/index.es.js +1 -1
  12. package/dist/components/Dashboard/TileCard.d.ts +7 -3
  13. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +15 -4
  14. package/dist/components/DashboardBuilder/controls.d.ts +8 -6
  15. package/dist/components/DashboardBuilder/document.d.ts +19 -5
  16. package/dist/components/DashboardBuilder/malloyText.d.ts +0 -30
  17. package/dist/components/DashboardBuilder/malloyTree.d.ts +232 -0
  18. package/dist/components/DashboardBuilder/preview.d.ts +17 -0
  19. package/dist/components/DashboardBuilder/readDocument.d.ts +23 -28
  20. package/dist/components/DashboardBuilder/spliceDocument.d.ts +12 -0
  21. package/dist/index.cjs.js +1 -1
  22. package/dist/index.es.js +5 -5
  23. package/dist/theme/resolveTheme.d.ts +1 -1
  24. package/dist/theme/types.d.ts +12 -2
  25. package/package.json +1 -1
  26. package/src/components/Dashboard/TileCard.tsx +8 -4
  27. package/src/components/DashboardBuilder/BuilderToolbar.tsx +4 -5
  28. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +356 -0
  29. package/src/components/DashboardBuilder/DashboardEditor.tsx +116 -25
  30. package/src/components/DashboardBuilder/FilterDialog.tsx +19 -6
  31. package/src/components/DashboardBuilder/TileFrame.tsx +11 -2
  32. package/src/components/DashboardBuilder/TileMenu.tsx +6 -0
  33. package/src/components/DashboardBuilder/__test__/inventory.ts +367 -0
  34. package/src/components/DashboardBuilder/controls.spec.ts +53 -3
  35. package/src/components/DashboardBuilder/controls.ts +9 -7
  36. package/src/components/DashboardBuilder/document.ts +17 -5
  37. package/src/components/DashboardBuilder/invariants.spec.ts +297 -0
  38. package/src/components/DashboardBuilder/malloyText.spec.ts +27 -66
  39. package/src/components/DashboardBuilder/malloyText.ts +4 -109
  40. package/src/components/DashboardBuilder/malloyTree.spec.ts +362 -0
  41. package/src/components/DashboardBuilder/malloyTree.ts +954 -0
  42. package/src/components/DashboardBuilder/preview.spec.ts +18 -0
  43. package/src/components/DashboardBuilder/preview.ts +24 -6
  44. package/src/components/DashboardBuilder/readDocument.spec.ts +312 -21
  45. package/src/components/DashboardBuilder/readDocument.ts +144 -165
  46. package/src/components/DashboardBuilder/scannerShapes.spec.ts +550 -0
  47. package/src/components/DashboardBuilder/spliceDocument.spec.ts +955 -21
  48. package/src/components/DashboardBuilder/spliceDocument.ts +509 -119
  49. package/src/components/DashboardBuilder/statementExtent.spec.ts +606 -0
  50. package/src/components/RenderedResult/RenderedResult.tsx +21 -1
  51. package/src/components/given/GivensPanel.tsx +15 -3
  52. package/src/theme/buildTableCssVars.spec.ts +3 -0
  53. package/src/theme/buildTableCssVars.ts +6 -0
  54. package/src/theme/defaults.ts +16 -12
  55. package/src/theme/resolveTheme.spec.ts +14 -7
  56. package/src/theme/resolveTheme.ts +14 -8
  57. package/src/theme/types.ts +12 -2
  58. package/tsconfig.spec.json +5 -1
  59. package/dist/ServerProvider-Cc489A3f.cjs.js +0 -1
@@ -0,0 +1,606 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { openDocument, refused, spliced } from "./testing/fixtures";
6
+ import { syntaxErrors } from "./spliceDocument";
7
+
8
+ /**
9
+ * Malloy's unit is the statement; every scan in this directory works a line at
10
+ * a time. Where the two disagree -- a clause list or a predicate carried onto
11
+ * the next line -- the reader used to report the first line as a whole binding
12
+ * and the writer would rewrite it, stranding the remainder as a statement of
13
+ * its own. The result was invalid Malloy that the round-trip gate accepted,
14
+ * because the orphaned text is not a filter and so nothing the gate compares
15
+ * ever looked at it.
16
+ *
17
+ * Each case here asserts the SURVIVING TEXT, never that the splice merely
18
+ * returned ok: the unfixed path returned ok too.
19
+ */
20
+ describe("a where: that spans lines is never the builder's to rewrite", () => {
21
+ const body = (stage: string) => `##! experimental.givens
22
+ ## artifact { title="T" tiles=["a -> kpis"] }
23
+ import "../m.malloy"
24
+
25
+ source: a is one extend {
26
+ view: kpis is {
27
+ ${stage}
28
+ aggregate: n is count()
29
+ }
30
+ }`;
31
+
32
+ const CONTINUED_LIST = body(" where: a ~ $A,\n b ~ $B");
33
+ const CONTINUED_PREDICATE = body(" where: a ~ $A\n and c = 1");
34
+
35
+ // A clause list carried onto a second line: the parser gives both clauses
36
+ // their exact spans, so both are ordinary bindings rather than a shape the
37
+ // builder has to declare off limits.
38
+ it("reads every clause of a continued list", async () => {
39
+ const d = await openDocument(CONTINUED_LIST);
40
+ expect(d.tiles[0].filters).toEqual([
41
+ { field: "a", given: "A" },
42
+ { field: "b", given: "B" },
43
+ ]);
44
+ });
45
+
46
+ it("does not read a continued predicate as a binding", async () => {
47
+ const d = await openDocument(CONTINUED_PREDICATE);
48
+ expect(d.tiles[0].filters).toBeUndefined();
49
+ });
50
+
51
+ // Unticking used to delete the first line and leave `b ~ $B` behind as a
52
+ // statement Malloy cannot parse. Now the whole statement goes, and the
53
+ // aggregate beside it does not.
54
+ it("removes a continued clause list whole when the tile is unbound", async () => {
55
+ const out = await spliced(CONTINUED_LIST, (d) => {
56
+ delete d.tiles[0].filters;
57
+ d.tiles[0].colspan = 4;
58
+ });
59
+ expect(out).not.toContain("where:");
60
+ expect(out).not.toContain("b ~ $B");
61
+ expect(out).toContain(" aggregate: n is count()");
62
+ expect(out).toContain("# colspan=4");
63
+ });
64
+
65
+ // Dropping ONE clause of the pair leaves the other exactly, separator and
66
+ // all -- the half-read that stranded text on `main`.
67
+ it("drops one clause of a continued list and keeps the other", async () => {
68
+ const out = await spliced(CONTINUED_LIST, (d) => {
69
+ d.tiles[0].filters = [{ field: "a", given: "A" }];
70
+ });
71
+ expect(out).toContain(" where: a ~ $A\n aggregate: n is count()");
72
+ expect(out).not.toContain("b ~ $B");
73
+ });
74
+
75
+ // The mirror risk, and the one that fails quietly: Malloy takes a comma as a
76
+ // statement separator, so a trailing comma does NOT mean the clause list
77
+ // carries on. Reading it as a continuation would leave an ordinary binding
78
+ // unmanaged, and the control would silently stop filtering.
79
+ it("still reads a binding whose line ends in a separator comma", async () => {
80
+ const d = await openDocument(body(" where: a ~ $A,"));
81
+ expect(d.tiles[0].filters).toEqual([{ field: "a", given: "A" }]);
82
+ });
83
+
84
+ it("still reads one where the comma is the last thing in the stage", async () => {
85
+ const trailing = `##! experimental.givens
86
+ ## artifact { title="T" tiles=["a -> kpis"] }
87
+ import "../m.malloy"
88
+
89
+ source: a is one extend {
90
+ view: kpis is {
91
+ aggregate: n is count()
92
+ where: a ~ $A,
93
+ }
94
+ }`;
95
+ const d = await openDocument(trailing);
96
+ expect(d.tiles[0].filters).toEqual([{ field: "a", given: "A" }]);
97
+ });
98
+
99
+ it("leaves a continued predicate whole when the tile changes", async () => {
100
+ const out = await spliced(CONTINUED_PREDICATE, (d) => {
101
+ delete d.tiles[0].filters;
102
+ d.tiles[0].colspan = 4;
103
+ });
104
+ expect(out).toContain(" where: a ~ $A\n and c = 1");
105
+ expect(out).toContain("# colspan=4");
106
+ });
107
+ });
108
+
109
+ /**
110
+ * The same disagreement on the reference path, where it predates this change:
111
+ * `filtersOf` matched binding clauses anywhere in a `+ { … }` refinement with
112
+ * no isolation check, so `where: a ~ $A and c = 1` read as a binding on $A --
113
+ * and the writer, removing what the reader reported, cut the clause out with a
114
+ * global regex and stranded ` and c = 1`.
115
+ */
116
+ describe("a compound predicate in a refinement is unmodeled Malloy", () => {
117
+ const COMPOUND = `##! experimental.givens
118
+ ## artifact { title="T" tiles=["a -> kpis"] }
119
+ import "../m.malloy"
120
+
121
+ source: a is one extend {
122
+ view: kpis is vx + { where: a ~ $A and c = 1 }
123
+ }`;
124
+
125
+ it("does not read it as a binding", async () => {
126
+ const d = await openDocument(COMPOUND);
127
+ expect(d.tiles[0].filters).toBeUndefined();
128
+ });
129
+
130
+ it("survives an unrelated change to the tile", async () => {
131
+ const out = await spliced(COMPOUND, (d) => {
132
+ d.tiles[0].colspan = 4;
133
+ });
134
+ expect(out).toContain("vx + { where: a ~ $A and c = 1 }");
135
+ });
136
+
137
+ // $A is already filtering from text the builder cannot rewrite, so adding a
138
+ // managed clause for it would filter on $A twice.
139
+ it("refuses to bind a given it already filters on", async () => {
140
+ const reason = await refused(COMPOUND, (d) => {
141
+ d.tiles[0].filters = [{ field: "a2", given: "A" }];
142
+ });
143
+ expect(reason).toContain("already filters on `$A`");
144
+ });
145
+
146
+ // A DIFFERENT given is fine: the compound is kept and spaced off the new
147
+ // clause, because Malloy rejects a comma after some statement forms.
148
+ it("keeps the compound when a different given is bound", async () => {
149
+ const out = await spliced(COMPOUND, (d) => {
150
+ d.tiles[0].filters = [{ field: "b", given: "B" }];
151
+ });
152
+ expect(out).toContain("vx + { where: a ~ $A and c = 1 where: b ~ $B }");
153
+ });
154
+ });
155
+
156
+ /**
157
+ * A binding is a statement of the view the builder owns. A `where:` inside a
158
+ * `nest:`, or inside a filtered measure's own `count() { … }`, belongs to that
159
+ * inner block -- reading it as the tile's filter means a later edit deletes or
160
+ * relocates someone else's predicate. Both gates are blind to it: the result
161
+ * still parses, and the projection still matches.
162
+ */
163
+ describe("a where: inside an inner block is not the tile's binding", () => {
164
+ const doc = (declaration: string) => `##! experimental.givens
165
+ ## artifact { title="T" tiles=["a -> kpis"] }
166
+ import "../m.malloy"
167
+
168
+ source: a is one extend {
169
+ ${declaration}
170
+ }`;
171
+
172
+ const MEASURE = doc(
173
+ " view: kpis is { aggregate: big is count() { where: amt > $MIN } }",
174
+ );
175
+ const NESTED = doc(" view: kpis is vx + { nest: y is { where: b ~ $B } }");
176
+
177
+ it("does not read a filtered measure's predicate as a tile filter", async () => {
178
+ const d = await openDocument(MEASURE);
179
+ expect(d.tiles[0].filters).toBeUndefined();
180
+ });
181
+
182
+ it("does not delete that predicate when the tile is edited", async () => {
183
+ const out = await spliced(MEASURE, (d) => {
184
+ delete d.tiles[0].filters;
185
+ d.tiles[0].colspan = 4;
186
+ });
187
+ expect(out).toContain("aggregate: big is count() { where: amt > $MIN }");
188
+ });
189
+
190
+ it("does not read a nest's own where: as a tile filter", async () => {
191
+ const d = await openDocument(NESTED);
192
+ expect(d.tiles[0].filters).toBeUndefined();
193
+ });
194
+
195
+ // This one used to LIFT the nest's filter out to tile level on an edit that
196
+ // had nothing to do with filters at all.
197
+ it("leaves a nest's where: inside the nest on an unrelated change", async () => {
198
+ const out = await spliced(NESTED, (d) => {
199
+ d.tiles[0].colspan = 4;
200
+ });
201
+ expect(out).toContain("vx + { nest: y is { where: b ~ $B } }");
202
+ });
203
+ });
204
+
205
+ describe("the duplicate-given guard sees text it does not own", () => {
206
+ const CONTINUED = `##! experimental.givens
207
+ ## artifact { title="T" tiles=["a -> kpis"] }
208
+ import "../m.malloy"
209
+
210
+ source: a is one extend {
211
+ view: kpis is {
212
+ where: a ~ $A,
213
+ b ~ $B
214
+ aggregate: n is count()
215
+ }
216
+ }`;
217
+
218
+ // $B is on the CONTINUATION line, which a line-at-a-time guard never saw --
219
+ // so a second $B clause was written and the tile filtered on one control
220
+ // twice. Both clauses are the builder's now, so rebinding $B REPLACES it
221
+ // rather than doubling it, which is the outcome the refusal stood in for.
222
+ it("rebinds a given used only on a continuation line, without doubling it", async () => {
223
+ const out = await spliced(CONTINUED, (d) => {
224
+ d.tiles[0].filters = [{ field: "b2", given: "B" }];
225
+ });
226
+ expect(out.match(/\$B\b/g)).toHaveLength(1);
227
+ expect(out).toContain(" where: b2 ~ $B");
228
+ expect(out).toContain(" aggregate: n is count()");
229
+ });
230
+
231
+ // And it does not fire on a given's name sitting inside a string literal.
232
+ it("does not mistake a given named in a literal for a use of it", async () => {
233
+ const out = await spliced(
234
+ `##! experimental.givens
235
+ ## artifact { title="T" tiles=["a -> kpis"] }
236
+ import "../m.malloy"
237
+
238
+ source: a is one extend {
239
+ view: kpis is vx + { where: label = 'costs $B' }
240
+ }`,
241
+ (d) => {
242
+ d.tiles[0].filters = [{ field: "b", given: "B" }];
243
+ },
244
+ );
245
+ expect(out).toContain("where: label = 'costs $B'");
246
+ expect(out).toContain("where: b ~ $B");
247
+ });
248
+ });
249
+
250
+ describe("syntaxErrors", () => {
251
+ it("is quiet on a document whose imports are unresolved", async () => {
252
+ expect(
253
+ await syntaxErrors(`##! experimental.givens
254
+ import "../m.malloy"
255
+
256
+ source: a is one extend {
257
+ view: v is { where: c ~ $C
258
+ aggregate: n is count()
259
+ }
260
+ }`),
261
+ ).toEqual([]);
262
+ });
263
+
264
+ it("reports a statement Malloy cannot parse", async () => {
265
+ const errs = await syntaxErrors(`source: a is one extend {
266
+ view: v is {
267
+ b ~ $B
268
+ aggregate: n is count()
269
+ }
270
+ }`);
271
+ expect(errs.length).toBeGreaterThan(0);
272
+ });
273
+ });
274
+
275
+ /**
276
+ * The duplicate-given guard decides by reading text the builder does not own,
277
+ * so what counts as "text" and what counts as "a filter" both matter. It used
278
+ * to scan the raw first stage for `$NAME` anywhere, which broke in both
279
+ * directions at once.
280
+ */
281
+ describe("the duplicate-given guard reads only what actually filters", () => {
282
+ const body = (stage: string) => `##! experimental.givens
283
+ ## artifact { title="T" tiles=["a -> kpis"] }
284
+ import "../m.malloy"
285
+
286
+ source: a is one extend {
287
+ view: kpis is {
288
+ ${stage}
289
+ aggregate: n is count()
290
+ }
291
+ }`;
292
+
293
+ // FAIL-OPEN, the worst of the three: an apostrophe in prose opened a quote
294
+ // that masked the rest of the stage, so the guard saw nothing and wrote a
295
+ // second $B clause under the compound one it was meant to protect.
296
+ it("is not disarmed by an apostrophe in a comment", async () => {
297
+ const reason = await refused(
298
+ body(" // don't remove\n where: b ~ $B and c = 1"),
299
+ (d) => {
300
+ d.tiles[0].filters = [{ field: "b2", given: "B" }];
301
+ },
302
+ );
303
+ expect(reason).toContain("already filters on `$B`");
304
+ });
305
+
306
+ it("does not treat a given named in a comment as a filter", async () => {
307
+ const out = await spliced(
308
+ body(" // TODO: maybe filter on $B later\n group_by: c"),
309
+ (d) => {
310
+ d.tiles[0].filters = [{ field: "b", given: "B" }];
311
+ },
312
+ );
313
+ expect(out).toContain("where: b ~ $B");
314
+ expect(out).toContain("// TODO: maybe filter on $B later");
315
+ });
316
+
317
+ // One control both filtering a tile and feeding a derived column is an
318
+ // ordinary shape. Refusing it made a file the builder itself wrote
319
+ // uneditable through the builder.
320
+ it("does not treat a given in a group_by expression as a filter", async () => {
321
+ const out = await spliced(
322
+ body(" where: amt > $MIN\n group_by: big is amt > $MIN"),
323
+ (d) => {
324
+ d.tiles[0].filters = [{ field: "amt", given: "MIN", op: ">=" }];
325
+ },
326
+ );
327
+ expect(out).toContain("where: amt >= $MIN");
328
+ expect(out).toContain("group_by: big is amt > $MIN");
329
+ });
330
+ });
331
+
332
+ /**
333
+ * A chained `+ { … } + { … }` refinement is valid Malloy the builder cannot
334
+ * manage: one greedy unwrap spans both blocks. An unmatched `}` mid-text used
335
+ * to drive the mask below depth 0, which made the second block look top-level
336
+ * -- so the reader reported only that block's binding and dropped the first
337
+ * from the projection entirely.
338
+ */
339
+ describe("a chained refinement is left alone rather than half-read", () => {
340
+ const CHAINED = `##! experimental.givens
341
+ ## artifact { title="T" tiles=["a -> kpis"] }
342
+ import "../m.malloy"
343
+
344
+ source: a is one extend {
345
+ view: kpis is vx + { where: a ~ $A } + { limit: 5 }
346
+ }`;
347
+
348
+ it("does not report a partial filter set", async () => {
349
+ const d = await openDocument(CHAINED);
350
+ expect(d.tiles[0].filters).toBeUndefined();
351
+ });
352
+
353
+ // Declared HERE, in a body with no one block a binding belongs in. Saying
354
+ // "declared on its source" about it -- which is what the menu used to say --
355
+ // is simply untrue, and it hid the fact that its tags ARE editable.
356
+ it("reads as declared here, with a reason, and keeps its tags", async () => {
357
+ const d = await openDocument(
358
+ CHAINED.replace(" view: kpis", " # colspan=6\n view: kpis"),
359
+ );
360
+ expect(d.tiles[0].declaration).toEqual({
361
+ kind: "opaque",
362
+ why: "a chained refinement",
363
+ });
364
+ expect(d.tiles[0].colspan).toBe(6);
365
+ });
366
+
367
+ it("survives an unrelated change untouched", async () => {
368
+ const out = await spliced(CHAINED, (d) => {
369
+ d.tiles[0].colspan = 4;
370
+ });
371
+ expect(out).toContain("vx + { where: a ~ $A } + { limit: 5 }");
372
+ });
373
+
374
+ // Two refinement blocks: no one of them is where a binding belongs, and a
375
+ // given already filtered on in the other would be bound a second time.
376
+ it("refuses a filter change rather than writing into one block", async () => {
377
+ const reason = await refused(CHAINED, (d) => {
378
+ d.tiles[0].filters = [{ field: "n", given: "N" }];
379
+ });
380
+ expect(reason).toContain("chained refinement");
381
+ // The view is declared right here; blaming the model would send whoever
382
+ // reads this to the wrong file.
383
+ expect(reason).not.toContain("declared on its source");
384
+ });
385
+ });
386
+
387
+ /**
388
+ * The other shape that reads `opaque`. `->` and a chained `+ { … }` reach that
389
+ * kind by different routes in `readBody`, and only one of them was followed all
390
+ * the way out to a document and back: a tree-level assertion says the body is
391
+ * unsupported, not that the tile keeps its tags, offers no filter, and survives
392
+ * a retag with its text intact.
393
+ */
394
+ describe("a `->` pipeline is left alone rather than half-read", () => {
395
+ const PIPELINE = `##! experimental.givens
396
+ ## artifact { title="T" tiles=["a -> kpis"] }
397
+ import "../m.malloy"
398
+
399
+ source: a is one extend {
400
+ # colspan=6
401
+ view: kpis is vx -> { group_by: b }
402
+ }`;
403
+
404
+ it("reads as declared here, with a reason, and keeps its tags", async () => {
405
+ const d = await openDocument(PIPELINE);
406
+ expect(d.tiles[0].declaration).toEqual({
407
+ kind: "opaque",
408
+ why: "a `->` pipeline from a named view",
409
+ });
410
+ expect(d.tiles[0].colspan).toBe(6);
411
+ expect(d.tiles[0].filters).toBeUndefined();
412
+ });
413
+
414
+ it("survives an unrelated change untouched", async () => {
415
+ const out = await spliced(PIPELINE, (d) => {
416
+ d.tiles[0].colspan = 4;
417
+ });
418
+ expect(out).toContain("vx -> { group_by: b }");
419
+ expect(out).toContain("# colspan=4");
420
+ });
421
+
422
+ it("refuses a filter change rather than writing into a stage", async () => {
423
+ const reason = await refused(PIPELINE, (d) => {
424
+ d.tiles[0].filters = [{ field: "n", given: "N" }];
425
+ });
426
+ expect(reason).toContain("pipeline");
427
+ expect(reason).not.toContain("declared on its source");
428
+ });
429
+ });
430
+
431
+ /**
432
+ * A `//` comment is trivia: it sits outside every parse-tree span, so a writer
433
+ * that deletes a range wider than one node's own text takes it without either
434
+ * gate noticing -- the file still parses, and the projection the readback
435
+ * compares has no comments in it. Each case here asserts the SURVIVING TEXT.
436
+ */
437
+ describe("a comment is nobody's to delete", () => {
438
+ const head = `##! experimental.givens
439
+ ## artifact { title="T" tiles=["a -> kpis"] }
440
+ import "../m.malloy"
441
+ `;
442
+
443
+ it("refuses to remove a clause whose separator carries a comment", async () => {
444
+ const reason = await refused(
445
+ `${head}
446
+ source: a is one extend {
447
+ view: kpis is {
448
+ where: a ~ $A,
449
+ // keep
450
+ b ~ $B
451
+ }
452
+ }`,
453
+ (d) => {
454
+ d.tiles[0].filters = [{ field: "b", given: "B" }];
455
+ },
456
+ );
457
+ expect(reason).toContain("// keep");
458
+ });
459
+
460
+ // The sibling of the case above, and the one that got missed: when EVERY
461
+ // clause of a `where:` is the builder's, the statement goes whole and the
462
+ // comment inside its span went with it, silently and successfully.
463
+ it("refuses to remove a whole where: whose span holds a comment", async () => {
464
+ const reason = await refused(
465
+ `${head}
466
+ source: a is one extend {
467
+ view: kpis is {
468
+ where: a ~ $A,
469
+ // why both
470
+ b ~ $B
471
+ aggregate: n is count()
472
+ }
473
+ }`,
474
+ (d) => {
475
+ delete d.tiles[0].filters;
476
+ },
477
+ );
478
+ expect(reason).toContain("// why both");
479
+ });
480
+
481
+ // Same statement, comment trailing it rather than inside it. The cut spared
482
+ // the comment and stranded it above the closing brace, explaining nothing.
483
+ it("refuses to remove a where: that a comment trails", async () => {
484
+ const reason = await refused(
485
+ `${head}
486
+ source: a is one extend {
487
+ view: kpis is {
488
+ where: a ~ $A // only this quarter
489
+ aggregate: n is count()
490
+ }
491
+ }`,
492
+ (d) => {
493
+ delete d.tiles[0].filters;
494
+ },
495
+ );
496
+ expect(reason).toContain("// only this quarter");
497
+ });
498
+
499
+ // `/* … */` is a comment to Malloy's lexer under a token of its own, so a
500
+ // guard that knew only `COMMENT_TO_EOL` deleted one without seeing it.
501
+ it("refuses to remove a clause whose separator carries a block comment", async () => {
502
+ const reason = await refused(
503
+ `${head}
504
+ source: a is one extend {
505
+ view: kpis is {
506
+ where: a ~ $A,
507
+ /* keep both */
508
+ b ~ $B
509
+ }
510
+ }`,
511
+ (d) => {
512
+ d.tiles[0].filters = [{ field: "b", given: "B" }];
513
+ },
514
+ );
515
+ expect(reason).toContain("/* keep both */");
516
+ });
517
+
518
+ it("refuses to collapse a refinement over a comment beside it", async () => {
519
+ const reason = await refused(
520
+ `${head}
521
+ source: a is one extend {
522
+ view: vx is { aggregate: n is count() }
523
+ view: kpis is vx // note
524
+ + { where: a ~ $A }
525
+ }`,
526
+ (d) => {
527
+ delete d.tiles[0].filters;
528
+ },
529
+ );
530
+ expect(reason).toContain("// note");
531
+ });
532
+
533
+ // The anchor is the statement's end, and a trailing comment is past it. The
534
+ // new line used to land BETWEEN them, so the comment ended up explaining a
535
+ // `where:` its author never wrote -- and it was still in the file, so
536
+ // nothing downstream could tell.
537
+ it("inserts a new filter after a trailing comment, not before it", async () => {
538
+ const out = await spliced(
539
+ `${head}
540
+ source: a is one extend {
541
+ view: kpis is {
542
+ aggregate: n is count() // keep with measure
543
+ }
544
+ }`,
545
+ (d) => {
546
+ d.tiles[0].filters = [{ field: "b", given: "B" }];
547
+ },
548
+ );
549
+ expect(out).toContain(
550
+ " aggregate: n is count() // keep with measure\n where: b ~ $B\n",
551
+ );
552
+ });
553
+ });
554
+
555
+ /**
556
+ * Malloy lets a second declaration share a line. One that is not a tile of this
557
+ * dashboard is invisible to the readback gate, so widening a removal to whole
558
+ * lines deleted it and reported success.
559
+ */
560
+ describe("removing a tile that shares its line", () => {
561
+ it("leaves the declaration beside it alone", async () => {
562
+ const out = await spliced(
563
+ `##! experimental.givens
564
+ ## artifact { title="T" tiles=["a -> kpis", "a -> keeper"] }
565
+ import "../m.malloy"
566
+
567
+ source: a is one extend {
568
+ view: vx is { aggregate: n is count() }
569
+ view: vh is { aggregate: m is count() }
570
+ view: keeper is vh
571
+ view: kpis is vx view: helper is vh
572
+ }`,
573
+ (d) => {
574
+ d.tiles = d.tiles.filter((tile) => tile.name !== "kpis");
575
+ },
576
+ );
577
+ expect(out).toContain("view: helper is vh");
578
+ expect(out).not.toContain("kpis");
579
+ });
580
+ });
581
+
582
+ /**
583
+ * `NAME :: string is` with its default on the line below is ordinary Malloy the
584
+ * reader accepts. The writer planned from the line the name sits on, so removal
585
+ * left the continuation behind as a statement of its own.
586
+ */
587
+ describe("a given declared across two lines", () => {
588
+ const source = `##! experimental.givens
589
+ ## artifact { title="T" tiles=["a -> kpis"] }
590
+ import "../m.malloy"
591
+
592
+ given: SPARE :: string is
593
+ 'x'
594
+
595
+ source: a is one extend {
596
+ view: kpis is { aggregate: n is count() }
597
+ }`;
598
+
599
+ it("is removed whole, continuation and all", async () => {
600
+ const out = await spliced(source, (d) => {
601
+ d.localGivens = [];
602
+ });
603
+ expect(out).not.toContain("SPARE");
604
+ expect(out).not.toContain("'x'");
605
+ });
606
+ });
@@ -276,7 +276,27 @@ div.malloy-render .malloy-dashboard .dashboard-row-header {
276
276
  background: var(--malloy-render--tile-background) !important;
277
277
  color: var(--malloy-render--table-body-color) !important;
278
278
  box-shadow: none !important;
279
- border: var(--malloy-render--table-border) !important;
279
+ /* The card edge, not the table gridline: --publisher-dashboard-card-border,
280
+ the same value TileCard paints, so the renderer's card and the composite
281
+ one are outlined identically. */
282
+ border: var(--publisher-dashboard-card-border) !important;
283
+ }
284
+ /* The renderer's big-value card — the small card a "# big_value" measure sits
285
+ in, several to a row inside one tile. (No backticks in here: this is inside
286
+ a template literal.) Its own CSS gives it a 0.55px edge in
287
+ #e5e7eb: a sub-pixel width, and a grey off the slate ramp everything else on
288
+ the page is on. It is a dashboard card like any other, so it takes the card
289
+ edge and stops being the one card outlined in a hairline nobody can see. */
290
+ .malloy-render .malloy-big-value-card {
291
+ border: var(--publisher-dashboard-card-border) !important;
292
+ /* Its shadow is a four-layer Tailwind stack, and only two of those layers
293
+ are a shadow: the other is "0 0 0 1px #e5e7eb", a spread ring drawn as a
294
+ second border OVER the real one. So the border above was landing
295
+ underneath a ring in the renderer's own grey, and the card kept both a
296
+ lifted look the flat cards around it do not have and an edge we did not
297
+ pick. Dropped whole rather than rebuilt layer by layer: the ring's job is
298
+ the border's job, and the border is already doing it. */
299
+ box-shadow: none !important;
280
300
  }
281
301
  .malloy-render .malloy-dashboard .dashboard-row-header-separator {
282
302
  background: var(--malloy-render--table-border) !important;
@@ -5,6 +5,7 @@ import { Box, Button, Paper, Stack, Typography } from "@mui/material";
5
5
  import { Given } from "../../client";
6
6
  import { GivenValue } from "../../hooks/givenValue";
7
7
  import { GivenInput } from "./GivenInput";
8
+ import { usePublisherTheme } from "../../theme/ThemeContext";
8
9
 
9
10
  /**
10
11
  * How the control row is laid out.
@@ -64,6 +65,10 @@ export function GivensPanel({
64
65
  apply,
65
66
  title,
66
67
  }: GivensPanelProps) {
68
+ // Above the early return below, not down at its use site: the bar layout is
69
+ // the only branch that paints a border, but a hook called conditionally is
70
+ // a hook called on some renders and not others.
71
+ const { theme } = usePublisherTheme();
67
72
  if (givens.length === 0) return null;
68
73
  // Some value actually SET, not merely some entry present. `paramsToGivens`
69
74
  // records `?X=` as a null entry, so counting entries offered Reset for a
@@ -126,10 +131,17 @@ export function GivensPanel({
126
131
  elevation={0}
127
132
  sx={{
128
133
  p: 2,
129
- border: 1,
130
- borderColor: "divider",
134
+ // The card edge, not MUI's `divider`: this row IS one of the
135
+ // page's cards as far as a reader is concerned, and on
136
+ // `divider` it stayed at the old hairline weight while the
137
+ // cards under it darkened — the one box on the page outlined
138
+ // differently from everything it sits above.
139
+ border: theme.cardBorder,
131
140
  borderRadius: 1,
132
- backgroundColor: "background.paper",
141
+ // Border only, no raised fill — the same construction the
142
+ // dashboard's cards use, so the control row reads as part of
143
+ // the page rather than as a panel floating above it.
144
+ backgroundColor: "transparent",
133
145
  }}
134
146
  >
135
147
  <Stack
@@ -23,6 +23,9 @@ describe("buildTableCssVars", () => {
23
23
  expect(vars["--malloy-render--table-header-color"]).toBe(t.tableHeader);
24
24
  expect(vars["--malloy-render--table-body-color"]).toBe(t.tableBody);
25
25
  expect(vars["--malloy-render--table-border"]).toBe(t.border);
26
+ // The card edge rides its own var, so darkening a card cannot darken
27
+ // every gridline in the table it holds.
28
+ expect(vars["--publisher-dashboard-card-border"]).toBe(t.cardBorder);
26
29
  // `tile-background` is our custom var for the dashboard tile
27
30
  // container. It's NOT the renderer's `table-pinned-background`
28
31
  // (which now carries `tableHeaderBackground` via the theme prop).