@malloy-publisher/sdk 0.8.3 → 0.8.4

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 (40) hide show
  1. package/README.md +14 -65
  2. package/dist/{DocumentStorage-CigwNjz4.es.js → Dashboard-DnqWRijB.es.js} +23660 -23575
  3. package/dist/Dashboard-FD3-Af-_.cjs.js +136 -0
  4. package/dist/{RenderedResult-BfayOSk1.es.js → RenderedResult-6UKAHaAj.es.js} +18 -18
  5. package/dist/{RenderedResult-DpHdrFtp.cjs.js → RenderedResult-CetSzFgW.cjs.js} +1 -1
  6. package/dist/ServerProvider-BsjJvkML.cjs.js +1 -0
  7. package/dist/{ServerProvider-CfUFleYe.es.js → ServerProvider-DgRFJ43L.es.js} +983 -957
  8. package/dist/builder/index.cjs.js +50 -50
  9. package/dist/builder/index.es.js +2587 -2511
  10. package/dist/client/api.d.ts +141 -40
  11. package/dist/client/configuration.d.ts +1 -1
  12. package/dist/client/index.cjs.js +1 -1
  13. package/dist/client/index.d.ts +1 -1
  14. package/dist/client/index.es.js +62 -59
  15. package/dist/components/DashboardBuilder/malloyText.d.ts +49 -0
  16. package/dist/components/DashboardBuilder/malloyTree.d.ts +2 -18
  17. package/dist/components/DashboardBuilder/readDocument.d.ts +2 -0
  18. package/dist/components/Notebook/NotebookCell.d.ts +3 -2
  19. package/dist/components/Notebook/cellKind.d.ts +20 -0
  20. package/dist/index.cjs.js +15 -12
  21. package/dist/index.es.js +4528 -4435
  22. package/package.json +1 -1
  23. package/src/components/DashboardBuilder/malloyText.spec.ts +70 -1
  24. package/src/components/DashboardBuilder/malloyText.ts +171 -3
  25. package/src/components/DashboardBuilder/malloyTree.spec.ts +35 -0
  26. package/src/components/DashboardBuilder/malloyTree.ts +28 -4
  27. package/src/components/DashboardBuilder/readDocument.spec.ts +180 -1
  28. package/src/components/DashboardBuilder/readDocument.ts +52 -14
  29. package/src/components/DashboardBuilder/spliceDocument.spec.ts +396 -2
  30. package/src/components/DashboardBuilder/spliceDocument.ts +121 -18
  31. package/src/components/Notebook/Notebook.served.spec.tsx +175 -0
  32. package/src/components/Notebook/Notebook.spec.tsx +33 -2
  33. package/src/components/Notebook/Notebook.tsx +13 -7
  34. package/src/components/Notebook/NotebookCell.tsx +124 -63
  35. package/src/components/Notebook/cellKind.spec.ts +191 -0
  36. package/src/components/Notebook/cellKind.ts +74 -0
  37. package/src/components/Package/Package.notebooks.spec.tsx +90 -0
  38. package/src/components/Package/Package.tsx +18 -4
  39. package/dist/DocumentStorage-DvUNSOiN.cjs.js +0 -134
  40. package/dist/ServerProvider-CuYLH_Yi.cjs.js +0 -1
@@ -16,7 +16,13 @@ import {
16
16
  type TreeStage,
17
17
  type TreeView,
18
18
  } from "./malloyTree";
19
- import { tileSteps } from "./malloyText";
19
+ import {
20
+ ARTIFACT_LINE,
21
+ blockLines,
22
+ descriptionNotes,
23
+ markdownNote,
24
+ tileSteps,
25
+ } from "./malloyText";
20
26
 
21
27
  /**
22
28
  * Read a `dashboards/*.malloy` file into a {@link DashboardDocument}.
@@ -75,6 +81,8 @@ export interface Block {
75
81
  * needs the numbers to patch a tag in place; the reader only needs the text.
76
82
  */
77
83
  tags: Array<{ line: number; text: string }>;
84
+ /** The `(markdown)` annotation lines in the block, which are not tags but leave with the declaration they describe. */
85
+ prose: number[];
78
86
  }
79
87
 
80
88
  /**
@@ -100,17 +108,22 @@ export function blockAbove(
100
108
  ): Block {
101
109
  const start = parsed.blockStart(declLine);
102
110
  const tags: Array<{ line: number; text: string }> = [];
111
+ const prose: number[] = [];
103
112
  for (let i = start; i < declLine; i++) {
104
113
  // Inside a `/* … */`, where a line beginning `#` is prose. Rewriting one
105
- // would put an edit inside a comment.
114
+ // would put an edit inside a comment, and `(markdown)` text there is no annotation.
106
115
  if (parsed.commentLine(i)) continue;
116
+ if (parsed.proseLine(i)) {
117
+ prose.push(i);
118
+ continue;
119
+ }
107
120
  const text = lines[i].trim();
108
121
  // `##` at this indent level is a MODEL annotation and never belongs to a
109
122
  // declaration; only single-`#` object tags do.
110
123
  if (text.startsWith("#") && !text.startsWith("##"))
111
124
  tags.push({ line: i, text });
112
125
  }
113
- return { start, tags };
126
+ return { start, tags, prose };
114
127
  }
115
128
 
116
129
  /** Just the text of a block's tags, which is what `parseAnnotation` takes. */
@@ -121,18 +134,21 @@ function modelLines(lines: string[]): {
121
134
  description?: string;
122
135
  artifact: string[];
123
136
  } {
124
- const doc: string[] = [];
125
137
  const artifact: string[] = [];
126
- for (const raw of lines) {
138
+ const inside = blockLines(lines);
139
+ for (const [i, raw] of lines.entries()) {
140
+ if (inside.has(i)) continue;
127
141
  const text = raw.trim();
128
- if (text.startsWith('##"')) doc.push(text.slice(3).trim());
129
- else if (text.startsWith("##!")) continue;
130
- else if (text.startsWith("##")) artifact.push(text);
142
+ const note = markdownNote(text);
143
+ if (
144
+ text.startsWith("##") &&
145
+ !text.startsWith('##"') &&
146
+ !text.startsWith("##!") &&
147
+ !(note?.level === 2 && !note.block)
148
+ )
149
+ artifact.push(text);
131
150
  }
132
- return {
133
- description: doc.length > 0 ? doc.join("\n") : undefined,
134
- artifact,
135
- };
151
+ return { description: descriptionNotes(lines).text, artifact };
136
152
  }
137
153
 
138
154
  /**
@@ -235,6 +251,21 @@ function readControlTags(tag: TagLike | null | undefined): Partial<LocalGiven> {
235
251
  };
236
252
  }
237
253
 
254
+ /** A grid width: a plain decimal positive integer, else undefined. */
255
+ function gridWidth(
256
+ tag: { text(key: string): string | undefined } | undefined,
257
+ key: string,
258
+ ): number | undefined {
259
+ const raw = tag?.text(key)?.trim();
260
+ if (
261
+ raw === undefined ||
262
+ !/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/.test(raw)
263
+ )
264
+ return undefined;
265
+ const value = Number(raw);
266
+ return Number.isInteger(value) && value >= 1 ? value : undefined;
267
+ }
268
+
238
269
  /** The `tiles=[…]` entries, in order, as written. */
239
270
  function tileEntries(artifactLine: string): string[] {
240
271
  const key = artifactLine.search(/tiles\s*=\s*\[/);
@@ -262,7 +293,7 @@ export async function readDashboardDocument(
262
293
  const parsed = parse.parsed;
263
294
 
264
295
  const { description, artifact } = modelLines(lines);
265
- const artifactLine = artifact.find((l) => l.includes("artifact"));
296
+ const artifactLine = artifact.find((l) => ARTIFACT_LINE.test(l));
266
297
  if (artifactLine === undefined) {
267
298
  return {
268
299
  ok: false,
@@ -424,7 +455,14 @@ export async function readDashboardDocument(
424
455
  if (value !== undefined) startingGivens[key] = value;
425
456
  }
426
457
 
427
- const columnsTag = tag?.tag("dashboard")?.numeric("columns");
458
+ // The server's rule: a written `dashboard { columns }` wins even when it is
459
+ // not a width (the default width then applies), and the alias only counts
460
+ // beside `tiles`.
461
+ const columnsTag = tag?.tag("dashboard")?.has("columns")
462
+ ? gridWidth(tag.tag("dashboard"), "columns")
463
+ : artifactTag?.array("tiles")
464
+ ? gridWidth(artifactTag, "dashboard_columns")
465
+ : undefined;
428
466
 
429
467
  return {
430
468
  ok: true,
@@ -13,6 +13,7 @@ import {
13
13
  } from "./spliceDocument";
14
14
  import { openDocument, refused, splice, spliced } from "./testing/fixtures";
15
15
  import { whatMoved } from "./__test__/inventory";
16
+ import { lintNotebookText } from "../../../../server/src/service/notebook_lint";
16
17
 
17
18
  const REPO = path.resolve(import.meta.dir, "../../../../..");
18
19
 
@@ -1010,6 +1011,24 @@ describe("spliceDashboardDocument: the page's own settings", () => {
1010
1011
  expect(flowed).not.toContain("dashboard {");
1011
1012
  });
1012
1013
 
1014
+ it("replaces the dashboard_columns alias when a width is set, and the result lints clean", async () => {
1015
+ const aliased = SOURCE.replace(
1016
+ '"a -> by_brand"] } dashboard { columns=12 }',
1017
+ '"a -> by_brand"] dashboard_columns=8 }',
1018
+ );
1019
+ expect(aliased).toContain("dashboard_columns=8");
1020
+ const out = await spliced(aliased, (d) => {
1021
+ d.columns = 12;
1022
+ });
1023
+ expect(out).not.toContain("dashboard_columns");
1024
+ expect(out).toContain("dashboard { columns=12 }");
1025
+ const removed = await spliced(aliased, (d) => {
1026
+ delete d.columns;
1027
+ });
1028
+ expect(removed).not.toContain("dashboard_columns");
1029
+ expect(removed).not.toContain("dashboard {");
1030
+ });
1031
+
1013
1032
  it("adds and removes autorun and starting values inside the tag", async () => {
1014
1033
  const out = await spliced(SOURCE, (d) => {
1015
1034
  d.autorun = false;
@@ -1051,6 +1070,177 @@ describe("spliceDashboardDocument: the page's own settings", () => {
1051
1070
  ).toBe(true);
1052
1071
  });
1053
1072
 
1073
+ // The saved file is what the server lints, so it is linted here rather than re-read.
1074
+ const lintCodes = (source: string) =>
1075
+ lintNotebookText("dashboards/d.malloy", source).map((f) => f.code);
1076
+ const TAIL = `import "../m.malloy"\n\nsource: a is one extend {\n view: x is vx\n}`;
1077
+
1078
+ describe("a width change against the deprecated alias", () => {
1079
+ it("removes the alias whatever spacing surrounds its =", async () => {
1080
+ const source = `## artifact { title="T" tiles=["a -> x"] dashboard_columns = 3 }\n${TAIL}`;
1081
+ const out = await spliced(source, (d) => {
1082
+ d.columns = 6;
1083
+ });
1084
+ expect(out).not.toContain("dashboard_columns");
1085
+ expect(out).toContain("dashboard { columns=6 }");
1086
+ expect(lintCodes(out)).toEqual([]);
1087
+ });
1088
+
1089
+ it("removes the alias, not the same words inside a quoted title", async () => {
1090
+ const source = `## artifact { title="a dashboard_columns=2 b" tiles=["a -> x"] dashboard_columns=3 }\n${TAIL}`;
1091
+ const out = await spliced(source, (d) => {
1092
+ d.columns = 6;
1093
+ });
1094
+ expect(out).toContain('title="a dashboard_columns=2 b"');
1095
+ expect(out.match(/dashboard_columns/g)).toHaveLength(1);
1096
+ expect(lintCodes(out)).toEqual([]);
1097
+ });
1098
+ });
1099
+
1100
+ it("refuses to reorder, add or remove tiles when tiles holds a text tile, and leaves the file alone", async () => {
1101
+ const source = fs.readFileSync(
1102
+ path.join(
1103
+ REPO,
1104
+ "packages/server/tests/fixtures/notebooks-malloyyo/dashboards/text_tiles.malloy",
1105
+ ),
1106
+ "utf8",
1107
+ );
1108
+ // The file has one quoted tile beside the text tile, so removal is the edit that reaches the list.
1109
+ const reason = await refused(source, (d) => {
1110
+ d.tiles.pop();
1111
+ });
1112
+ expect(reason).toContain("text tile");
1113
+ // A settings edit that does not touch the tile list still works.
1114
+ const out = await spliced(source, (d) => {
1115
+ d.title = "Renamed";
1116
+ });
1117
+ expect(out).toContain("intro { kind=text colspan=12 }");
1118
+ expect(out).toContain('title="Renamed"');
1119
+ });
1120
+
1121
+ it("changes the width of a file whose title holds dashboard { }", async () => {
1122
+ const source = `## artifact { title="my dashboard {x}" tiles=["a -> x"] } dashboard { columns=4 }\n${TAIL}`;
1123
+ const out = await spliced(source, (d) => {
1124
+ d.columns = 6;
1125
+ });
1126
+ expect(out).toContain('title="my dashboard {x}"');
1127
+ expect(out).toContain("dashboard { columns=6 }");
1128
+ expect(out.match(/dashboard \{ columns/g)).toHaveLength(1);
1129
+ const removed = await spliced(source, (d) => {
1130
+ delete d.columns;
1131
+ });
1132
+ expect(removed).toContain('title="my dashboard {x}"');
1133
+ expect(removed).not.toContain("columns=");
1134
+ });
1135
+
1136
+ describe("the description's place", () => {
1137
+ const artifact = '## artifact { title="T" tiles=["a -> x"] }';
1138
+
1139
+ it("moves a description read from below the tag above it", async () => {
1140
+ const source = `${artifact}\n##" Legacy\n##" text\n${TAIL}`;
1141
+ expect(lintCodes(source)).toEqual([
1142
+ "notebook-description-below-artifact",
1143
+ ]);
1144
+ const out = await spliced(source, (d) => {
1145
+ d.description = "Edited\ntext";
1146
+ });
1147
+ expect(out.startsWith(`##" Edited\n##" text\n${artifact}\n`)).toBe(
1148
+ true,
1149
+ );
1150
+ expect(out).not.toContain("Legacy");
1151
+ expect(lintCodes(out)).toEqual([]);
1152
+ expect((await openDocument(out)).description).toBe("Edited\ntext");
1153
+ });
1154
+
1155
+ it("clears the prose-less notes above when it moves one from below", async () => {
1156
+ const out = await spliced(
1157
+ `##"\n${artifact}\n##" Legacy\n${TAIL}`,
1158
+ (d) => {
1159
+ d.description = "Edited";
1160
+ },
1161
+ );
1162
+ expect(out.startsWith(`##" Edited\n${artifact}\n`)).toBe(true);
1163
+ expect(lintCodes(out)).toEqual([]);
1164
+ });
1165
+
1166
+ it("removes a description read from below, and only that", async () => {
1167
+ const out = await spliced(`${artifact}\n##" Legacy\n${TAIL}`, (d) => {
1168
+ delete d.description;
1169
+ });
1170
+ expect(out).toBe(`${artifact}\n${TAIL}`);
1171
+ });
1172
+
1173
+ it("edits the description and the title on a file whose prose says artifact", async () => {
1174
+ const source = `##" This artifact shows revenue\n${artifact}\n${TAIL}`;
1175
+ const edited = await spliced(source, (d) => {
1176
+ d.description = "New";
1177
+ });
1178
+ expect(edited).toBe(`##" New\n${artifact}\n${TAIL}`);
1179
+ const retitled = await spliced(source, (d) => {
1180
+ d.title = "Renamed";
1181
+ });
1182
+ expect(retitled).toContain('title="Renamed"');
1183
+ expect(retitled).toContain(`##" This artifact shows revenue\n`);
1184
+ });
1185
+
1186
+ it('refuses to edit a description held in a ##|" block, and touches nothing', async () => {
1187
+ const source = `##|"\nBlock prose\n|##\n${artifact}\n##" Legacy\n${TAIL}`;
1188
+ const reason = await refused(source, (d) => {
1189
+ d.description = "New";
1190
+ });
1191
+ expect(reason).toContain("block");
1192
+ expect(reason).toContain("##|");
1193
+ await refused(source, (d) => {
1194
+ delete d.description;
1195
+ });
1196
+ const out = await spliced(source, (d) => {
1197
+ d.title = "Renamed";
1198
+ });
1199
+ expect(out).toContain('##|"\nBlock prose\n|##\n');
1200
+ expect(out).toContain('##" Legacy\n');
1201
+ });
1202
+
1203
+ it("refuses to edit a fallback description held in a block below the tag", async () => {
1204
+ const source = `${artifact}\n##|"\nBelow block\n|##\n${TAIL}`;
1205
+ const reason = await refused(source, (d) => {
1206
+ d.description = "New";
1207
+ });
1208
+ expect(reason).toContain("block");
1209
+ await refused(source, (d) => {
1210
+ delete d.description;
1211
+ });
1212
+ });
1213
+
1214
+ it("refuses to clear a description above when a block below would take its place", async () => {
1215
+ await refused(
1216
+ `##" Above\n${artifact}\n##|"\nBelow block\n|##\n${TAIL}`,
1217
+ (d) => {
1218
+ delete d.description;
1219
+ },
1220
+ );
1221
+ });
1222
+
1223
+ it("clears the notes below the tag too when it clears one above", async () => {
1224
+ const out = await spliced(
1225
+ `##" Above\n${artifact}\n##" Ignored\n${TAIL}`,
1226
+ (d) => {
1227
+ delete d.description;
1228
+ },
1229
+ );
1230
+ expect(out).toBe(`${artifact}\n${TAIL}`);
1231
+ });
1232
+
1233
+ it("edits the notes above and leaves the ones below, which the server ignores", async () => {
1234
+ const out = await spliced(
1235
+ `##" Above\n${artifact}\n##" Ignored\n${TAIL}`,
1236
+ (d) => {
1237
+ d.description = "New";
1238
+ },
1239
+ );
1240
+ expect(out).toBe(`##" New\n${artifact}\n##" Ignored\n${TAIL}`);
1241
+ });
1242
+ });
1243
+
1054
1244
  it("retitles and reorders in one write, on the same line", async () => {
1055
1245
  const out = await spliced(SOURCE, (d) => {
1056
1246
  d.title = "Renamed";
@@ -1342,8 +1532,7 @@ describe("every composite dashboard survives an edit", () => {
1342
1532
  const editable = found.filter((f) => {
1343
1533
  const text = fs.readFileSync(f, "utf8");
1344
1534
  return (
1345
- /##\s*artifact[\s\S]*tiles\s*=/.test(text) &&
1346
- !f.includes("dashboards-lint")
1535
+ /##\s*artifact[\s\S]*tiles\s*=/.test(text) && !/-lint[\\/]/.test(f)
1347
1536
  );
1348
1537
  });
1349
1538
 
@@ -2093,3 +2282,208 @@ source: a is scoped_orders extend {
2093
2282
  );
2094
2283
  });
2095
2284
  });
2285
+
2286
+ describe("spliceDashboardDocument: the (markdown) route", () => {
2287
+ const TEXT_TILE = `##" Above
2288
+ ## artifact { title="T" tiles=[intro { kind=text colspan=12 }, "a -> x"] }
2289
+ ##(markdown) a floating one-liner
2290
+ import "../m.malloy"
2291
+
2292
+ ##|(markdown) intro
2293
+ ## How to read this page
2294
+ |##
2295
+
2296
+ source: a is one extend {
2297
+ #|(markdown)
2298
+ # Lead tile
2299
+ |#
2300
+ # colspan=6
2301
+ view: x is vx
2302
+ }`;
2303
+
2304
+ it("round-trips a text-tile dashboard, heading line and markdown lines included, byte for byte", async () => {
2305
+ const doc = await openDocument(TEXT_TILE);
2306
+ expect(doc.title).toBe("T");
2307
+ expect(doc.description).toBe("Above");
2308
+ expect(doc.tiles.find((t) => t.name === "x")?.colspan).toBe(6);
2309
+ const result = await spliceDashboardDocument(TEXT_TILE, doc);
2310
+ if (spliceFailed(result)) throw new Error(result.reason);
2311
+ expect(result.source).toBe(TEXT_TILE);
2312
+ });
2313
+
2314
+ it("still refuses a tile-list edit over the text tile", async () => {
2315
+ const reason = await refused(TEXT_TILE, (d) => {
2316
+ d.tiles.pop();
2317
+ });
2318
+ expect(reason).toContain("text tile");
2319
+ });
2320
+
2321
+ it("rewrites a description and a tile's colspan without touching the markdown around them", async () => {
2322
+ const out = await spliced(TEXT_TILE, (d) => {
2323
+ d.description = "New";
2324
+ d.tiles.find((t) => t.name === "x")!.colspan = 4;
2325
+ });
2326
+ expect(out).toContain('##" New\n## artifact');
2327
+ expect(out).toContain("##(markdown) a floating one-liner\n");
2328
+ expect(out).toContain(
2329
+ "##|(markdown) intro\n## How to read this page\n|##\n",
2330
+ );
2331
+ expect(out).toContain(
2332
+ " #|(markdown)\n # Lead tile\n |#\n # colspan=4\n",
2333
+ );
2334
+ });
2335
+
2336
+ it("takes an attached markdown block away with the given it describes", async () => {
2337
+ const source = `##! experimental.givens
2338
+ ## artifact { title="T" tiles=["a -> x"] }
2339
+ import "../m.malloy"
2340
+
2341
+ #|(markdown)
2342
+ # About the category filter
2343
+ |#
2344
+ # label="Category"
2345
+ given: CATEGORY :: filter<string> is f''
2346
+ # label="Since"
2347
+ given: SINCE :: date is @2023-01-01
2348
+
2349
+ source: a is one extend {
2350
+ view: x is vx
2351
+ }`;
2352
+ const out = await spliced(source, (d) => {
2353
+ d.localGivens = (d.localGivens ?? []).filter(
2354
+ (g) => g.name !== "CATEGORY",
2355
+ );
2356
+ });
2357
+ expect(out).not.toContain("About the category filter");
2358
+ expect(out).toContain('# label="Since"\ngiven: SINCE');
2359
+ });
2360
+
2361
+ // A closer-looking line inside a block comment is comment text, not the end of the
2362
+ // previous declaration's markdown block.
2363
+ const WITH_COMMENTED_CLOSER = `## artifact { title="T" tiles=["a -> u", "a -> x"] }
2364
+ import "../m.malloy"
2365
+
2366
+ source: a is one extend {
2367
+ #|(markdown)
2368
+ # Prev
2369
+ |#
2370
+ view: u is vu
2371
+
2372
+ # colspan=6
2373
+ /*
2374
+ |# looks like a closer
2375
+ */
2376
+ view: x is vx
2377
+ }`;
2378
+
2379
+ it("changes a tile's width when a block comment above it holds a closer-looking line", async () => {
2380
+ const out = await spliced(WITH_COMMENTED_CLOSER, (d) => {
2381
+ d.tiles.find((t) => t.name === "x")!.colspan = 4;
2382
+ });
2383
+ expect(out).toContain(" # colspan=4\n /*\n |# looks like a closer\n");
2384
+ expect(out).not.toContain("colspan=6");
2385
+ expect(out).toContain(
2386
+ " #|(markdown)\n # Prev\n |#\n view: u is vu\n",
2387
+ );
2388
+ });
2389
+
2390
+ it("removes a tile without taking the previous tile's markdown block with it", async () => {
2391
+ const out = await spliced(WITH_COMMENTED_CLOSER, (d) => {
2392
+ d.tiles = d.tiles.filter((t) => t.name !== "x");
2393
+ });
2394
+ expect(out).not.toContain("view: x");
2395
+ expect(out).toContain(" #|(markdown)\n # Prev\n |#\n view: u is vu");
2396
+ });
2397
+
2398
+ it("leaves a comment holding `#(markdown)` text in place when its given is removed", async () => {
2399
+ const source = `##! experimental.givens
2400
+ ## artifact { title="T" tiles=["a -> x"] }
2401
+ import "../m.malloy"
2402
+
2403
+ /*
2404
+ #(markdown) only a comment
2405
+ */
2406
+ # label="Since"
2407
+ given: SINCE :: date is @2023-01-01
2408
+
2409
+ source: a is one extend {
2410
+ view: x is vx
2411
+ }`;
2412
+ const out = await spliced(source, (d) => {
2413
+ d.localGivens = (d.localGivens ?? []).filter(
2414
+ (g) => g.name !== "SINCE",
2415
+ );
2416
+ });
2417
+ expect(out).not.toContain("SINCE");
2418
+ expect(out).toContain("/*\n#(markdown) only a comment\n*/");
2419
+ });
2420
+
2421
+ it("does not bleed a control from the given above a comment holding a closer-looking line", async () => {
2422
+ const source = `##! experimental.givens
2423
+ ## artifact { title="T" tiles=["a -> x"] }
2424
+ import "../m.malloy"
2425
+
2426
+ #|(markdown)
2427
+ # About
2428
+ |#
2429
+ # label="Category" control=select
2430
+ given: CATEGORY :: filter<string> is f''
2431
+
2432
+ /*
2433
+ |# looks like a closer
2434
+ */
2435
+ # label="Since"
2436
+ given: SINCE :: date is @2023-01-01
2437
+
2438
+ source: a is one extend {
2439
+ view: x is vx
2440
+ }`;
2441
+ const doc = await openDocument(source);
2442
+ const since = doc.localGivens?.find((g) => g.name === "SINCE");
2443
+ expect(since?.label).toBe("Since");
2444
+ expect(since?.control).toBeUndefined();
2445
+ const out = await spliced(source, (d) => {
2446
+ d.localGivens = (d.localGivens ?? []).filter(
2447
+ (g) => g.name !== "SINCE",
2448
+ );
2449
+ });
2450
+ expect(out).not.toContain("SINCE");
2451
+ expect(out).toContain("given: CATEGORY");
2452
+ });
2453
+
2454
+ const FLOATING = (
2455
+ body: string,
2456
+ tag = '# label="Category" control=select',
2457
+ ) => `##! experimental.givens
2458
+ ## artifact { title="T" tiles=["a -> x"] }
2459
+ import "../m.malloy"
2460
+
2461
+ ##|(markdown)
2462
+ ${body}
2463
+ Use the filters.
2464
+ |##
2465
+ ${tag}
2466
+ given: CATEGORY :: filter<string> is f''
2467
+
2468
+ source: a is one extend {
2469
+ view: x is vx
2470
+ }`;
2471
+
2472
+ it("keeps a floating text block's heading when the given right below it is removed", async () => {
2473
+ const out = await spliced(FLOATING("# Welcome"), (d) => {
2474
+ d.localGivens = (d.localGivens ?? []).filter(
2475
+ (g) => g.name !== "CATEGORY",
2476
+ );
2477
+ });
2478
+ expect(out).toContain("##|(markdown)\n# Welcome\nUse the filters.\n|##");
2479
+ expect(out).not.toContain("CATEGORY");
2480
+ });
2481
+
2482
+ it("does not read a floating text block's # line as the given's label", async () => {
2483
+ const doc = await openDocument(
2484
+ FLOATING('# label="Introduction"', "# control=select"),
2485
+ );
2486
+ const given = doc.localGivens?.find((g) => g.name === "CATEGORY");
2487
+ expect(given?.label).toBeUndefined();
2488
+ });
2489
+ });