@malloy-publisher/sdk 0.9.4 → 0.9.6

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 (53) hide show
  1. package/dist/{RenderedResult-DwB0-9Yx.es.js → RenderedResult-BUb2Xvr2.es.js} +34 -19
  2. package/dist/{RenderedResult-hKjFEqaN.cjs.js → RenderedResult-qnpbr4tc.cjs.js} +15 -3
  3. package/dist/{ServerProvider-CcSrGaRN.es.js → ServerProvider-C6QQVKPm.es.js} +149 -141
  4. package/dist/ServerProvider-Gj-im5VD.cjs.js +1 -0
  5. package/dist/builder/index.cjs.js +82 -82
  6. package/dist/builder/index.es.js +3242 -3188
  7. package/dist/client/api.d.ts +54 -11
  8. package/dist/client/index.cjs.js +1 -1
  9. package/dist/client/index.es.js +57 -56
  10. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -5
  11. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +3 -1
  12. package/dist/components/DashboardBuilder/addTileToDocument.d.ts +14 -0
  13. package/dist/components/DashboardBuilder/catalog.d.ts +5 -1
  14. package/dist/components/DashboardBuilder/imports.d.ts +11 -12
  15. package/dist/components/DashboardBuilder/spliceDocument.d.ts +2 -0
  16. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +2 -0
  17. package/dist/components/DashboardBuilder/useTileEditing.d.ts +3 -1
  18. package/dist/index.cjs.js +1 -1
  19. package/dist/index.es.js +5 -5
  20. package/dist/theme/buildVegaThemeOverride.d.ts +7 -3
  21. package/dist/{useCompiledDocument-BU6d8FPp.es.js → useCompiledDocument-0sxonf6N.es.js} +3707 -3686
  22. package/dist/{useCompiledDocument-pOg2W-Yt.cjs.js → useCompiledDocument-tBejqZ7s.cjs.js} +31 -31
  23. package/package.json +2 -1
  24. package/src/components/DashboardBuilder/AddTileDialog.tsx +16 -11
  25. package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +13 -5
  26. package/src/components/DashboardBuilder/DashboardBuilder.tsx +5 -0
  27. package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +3 -0
  28. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +3 -0
  29. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +10 -2
  30. package/src/components/DashboardBuilder/DashboardEditor.textSource.spec.tsx +79 -3
  31. package/src/components/DashboardBuilder/EditorSurface.tsx +30 -2
  32. package/src/components/DashboardBuilder/addTile.compile.spec.ts +184 -0
  33. package/src/components/DashboardBuilder/addTileToDocument.spec.ts +58 -0
  34. package/src/components/DashboardBuilder/addTileToDocument.ts +64 -0
  35. package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +1 -0
  36. package/src/components/DashboardBuilder/catalog.spec.ts +79 -3
  37. package/src/components/DashboardBuilder/catalog.ts +23 -5
  38. package/src/components/DashboardBuilder/imports.spec.ts +56 -0
  39. package/src/components/DashboardBuilder/imports.ts +16 -13
  40. package/src/components/DashboardBuilder/preview.spec.ts +21 -0
  41. package/src/components/DashboardBuilder/preview.ts +10 -1
  42. package/src/components/DashboardBuilder/spliceDocument.spec.ts +24 -9
  43. package/src/components/DashboardBuilder/spliceDocument.ts +18 -6
  44. package/src/components/DashboardBuilder/useDashboardEditor.ts +6 -2
  45. package/src/components/DashboardBuilder/useTileEditing.ts +13 -48
  46. package/src/components/RenderedResult/RenderedResult.tsx +12 -0
  47. package/src/components/given/GivenInput.tsx +39 -16
  48. package/src/components/given/utils.spec.ts +5 -0
  49. package/src/components/given/utils.ts +1 -1
  50. package/src/theme/buildVegaThemeOverride.spec.ts +11 -1
  51. package/src/theme/buildVegaThemeOverride.ts +10 -3
  52. package/src/timezone_runs.spec.ts +64 -0
  53. package/dist/ServerProvider-Gbf1YPOP.cjs.js +0 -1
@@ -11,6 +11,15 @@ import {
11
11
  isDashboardModel,
12
12
  } from "./catalog";
13
13
 
14
+ /** A `modelInfo` exporting these sources, and a named query beside them. */
15
+ const infoOf = (...sources: string[]) =>
16
+ JSON.stringify({
17
+ entries: [
18
+ ...sources.map((name) => ({ kind: "source", name })),
19
+ { kind: "query", name: "a_named_query" },
20
+ ],
21
+ });
22
+
14
23
  /**
15
24
  * Shaped like the real response, including the two details that are easy to get
16
25
  * wrong from the type alone: annotations arrive RAW with their trailing newline,
@@ -18,6 +27,7 @@ import {
18
27
  */
19
28
  const MODEL: CompiledModel = {
20
29
  modelPath: "data_app.malloy",
30
+ modelInfo: infoOf("scoped_orders"),
21
31
  sources: [
22
32
  {
23
33
  name: "scoped_orders",
@@ -127,15 +137,80 @@ describe("buildCatalog", () => {
127
137
  expect(catalog.sources).toEqual([]);
128
138
  });
129
139
 
130
- // An imported source appears in every model that imports it. The first one
131
- // to declare it wins, so a preview runs against the file that defines it.
132
- it("keeps one entry for a source that several models carry", () => {
140
+ // `sources` also lists names a model only imports; an import of one of
141
+ // those from the importer fails to compile.
142
+ it("credits a source to the model that exports it, not an importer listed first", () => {
143
+ const importer = {
144
+ ...MODEL,
145
+ modelPath: "data_app.malloy",
146
+ modelInfo: infoOf("scoped_orders"),
147
+ sources: [
148
+ ...MODEL.sources!,
149
+ { name: "order_items", views: [{ name: "by_category" }] },
150
+ ],
151
+ } as CompiledModel;
152
+ const exporter = {
153
+ modelPath: "storefront.malloy",
154
+ modelInfo: infoOf("order_items"),
155
+ sources: [{ name: "order_items", views: [{ name: "by_category" }] }],
156
+ } as CompiledModel;
157
+ const catalog = buildCatalog([importer, exporter]);
158
+ expect(catalog.sources.map((s) => [s.name, s.modelPath]).sort()).toEqual([
159
+ ["order_items", "storefront.malloy"],
160
+ ["scoped_orders", "data_app.malloy"],
161
+ ]);
162
+ });
163
+
164
+ it("records every model that lists a source, imported or not, as where it is visible", () => {
165
+ const catalog = buildCatalog([
166
+ {
167
+ ...MODEL,
168
+ modelInfo: infoOf(),
169
+ modelPath: "importer.malloy",
170
+ } as CompiledModel,
171
+ MODEL,
172
+ ]);
173
+ expect(catalog.sources[0].exporters).toEqual(["data_app.malloy"]);
174
+ expect(catalog.sources[0].visibleIn).toEqual([
175
+ "importer.malloy",
176
+ "data_app.malloy",
177
+ ]);
178
+ });
179
+
180
+ it("lists every model that exports a source, the first as its modelPath", () => {
133
181
  const catalog = buildCatalog([
134
182
  MODEL,
135
183
  { ...MODEL, modelPath: "storefront.malloy" } as CompiledModel,
136
184
  ]);
137
185
  expect(catalog.sources).toHaveLength(1);
138
186
  expect(catalog.sources[0].modelPath).toBe("data_app.malloy");
187
+ expect(catalog.sources[0].exporters).toEqual([
188
+ "data_app.malloy",
189
+ "storefront.malloy",
190
+ ]);
191
+ });
192
+
193
+ // Falling back to the first model that lists a source would bring the
194
+ // unreachable import back.
195
+ it("offers nothing from a model with no modelInfo, or one that does not parse", () => {
196
+ expect(
197
+ buildCatalog([{ ...MODEL, modelInfo: undefined } as CompiledModel])
198
+ .sources,
199
+ ).toEqual([]);
200
+ expect(
201
+ buildCatalog([{ ...MODEL, modelInfo: "{not json" } as CompiledModel])
202
+ .sources,
203
+ ).toEqual([]);
204
+ });
205
+
206
+ it("does not make a source of a named query", () => {
207
+ const catalog = buildCatalog([
208
+ {
209
+ ...MODEL,
210
+ sources: [...MODEL.sources!, { name: "a_named_query" }],
211
+ } as CompiledModel,
212
+ ]);
213
+ expect(catalog.sources.map((s) => s.name)).toEqual(["scoped_orders"]);
139
214
  });
140
215
  });
141
216
 
@@ -144,6 +219,7 @@ describe("filterableFields", () => {
144
219
  // what people filter on, and a view is not a field at all.
145
220
  const model: CompiledModel = {
146
221
  modelPath: "storefront.malloy",
222
+ modelInfo: infoOf("order_items"),
147
223
  sources: [{ name: "order_items" }],
148
224
  sourceInfos: [
149
225
  JSON.stringify({
@@ -3,6 +3,7 @@
3
3
 
4
4
  import { parseTag } from "@malloydata/malloy-tag";
5
5
  import type { CompiledModel } from "../../client";
6
+ import { exportedSources } from "../DocumentCreate/exportedSources";
6
7
  import { CHART_TAGS } from "./chartLine";
7
8
 
8
9
  export { CHART_TAGS };
@@ -40,8 +41,12 @@ export interface CatalogView {
40
41
 
41
42
  export interface CatalogSource {
42
43
  name: string;
43
- /** The model that declares it, which is what a preview runs against. */
44
+ /** The model that exports it, which its import names. */
44
45
  modelPath: string;
46
+ /** Every model that exports it: a whole-file import of any of them carries the source. Absent from a hand-built catalog, where `modelPath` is the only one. */
47
+ exporters?: string[];
48
+ /** Every model that lists it, imported or exported: what a document extending that model can name without an import. */
49
+ visibleIn?: string[];
45
50
  description?: string;
46
51
  views: CatalogView[];
47
52
  /**
@@ -213,6 +218,19 @@ const pathOf = (model: CompiledModel): string =>
213
218
  export function buildCatalog(models: CompiledModel[]): PackageCatalog {
214
219
  const sources: CatalogSource[] = [];
215
220
  const seen = new Set<string>();
221
+ const exporters = new Map<string, string[]>();
222
+ const exported = new Map<CompiledModel, Set<string>>();
223
+ const listed = new Map<string, string[]>();
224
+ for (const model of models) {
225
+ const modelPath = pathOf(model);
226
+ if (isDashboardModel(modelPath)) continue;
227
+ const names = exportedSources(model.modelInfo);
228
+ exported.set(model, names);
229
+ for (const { name } of model.sources ?? [])
230
+ if (name) listed.set(name, [...(listed.get(name) ?? []), modelPath]);
231
+ for (const name of names)
232
+ exporters.set(name, [...(exporters.get(name) ?? []), modelPath]);
233
+ }
216
234
 
217
235
  for (const model of models) {
218
236
  const modelPath = pathOf(model);
@@ -223,10 +241,8 @@ export function buildCatalog(models: CompiledModel[]): PackageCatalog {
223
241
  for (const source of model.sources ?? []) {
224
242
  const name = source.name;
225
243
  if (!name) continue;
226
- // A source reached through an import appears in every model that
227
- // imports it. The first model to declare it wins, so a preview runs
228
- // against the file that actually defines it.
229
- if (seen.has(name)) continue;
244
+ // `sources` also lists imported names, which an import cannot reach unless the model re-exports them.
245
+ if (!exported.get(model)?.has(name) || seen.has(name)) continue;
230
246
  seen.add(name);
231
247
 
232
248
  const givens = (
@@ -238,6 +254,8 @@ export function buildCatalog(models: CompiledModel[]): PackageCatalog {
238
254
  sources.push({
239
255
  name,
240
256
  modelPath,
257
+ exporters: exporters.get(name) ?? [modelPath],
258
+ visibleIn: listed.get(name) ?? [modelPath],
241
259
  ...(docOf(source.annotations)
242
260
  ? { description: docOf(source.annotations) as string }
243
261
  : {}),
@@ -58,4 +58,60 @@ describe("withSource", () => {
58
58
  reaches(doc("../storefront.malloy"), "orders", "storefront.malloy"),
59
59
  ).toBe(true);
60
60
  });
61
+
62
+ it("joins an exporter's existing import when a re-exporting model is the one credited", () => {
63
+ const next = withSource(
64
+ doc("../storefront.malloy"),
65
+ "regions",
66
+ "data_app.malloy",
67
+ "dashboards/x.malloy",
68
+ ["data_app.malloy", "storefront.malloy"],
69
+ );
70
+ expect(next).toEqual([
71
+ {
72
+ kind: "names",
73
+ names: ["orders", "regions"],
74
+ from: "../storefront.malloy",
75
+ },
76
+ ]);
77
+ });
78
+ });
79
+
80
+ describe("reaches, through a whole-file import", () => {
81
+ const whole = (from: string) => ({
82
+ imports: [{ kind: "all" as const, from }],
83
+ sources: [],
84
+ });
85
+
86
+ it("counts an import of the model that exports the source", () => {
87
+ expect(
88
+ reaches(whole("../storefront.malloy"), "orders", "storefront.malloy"),
89
+ ).toBe(true);
90
+ });
91
+
92
+ it("counts an import of any exporter, not only the one the catalog credits", () => {
93
+ const args = [
94
+ "orders",
95
+ "data_app.malloy",
96
+ "dashboards/x.malloy",
97
+ ] as const;
98
+ expect(reaches(whole("../storefront.malloy"), ...args)).toBe(false);
99
+ expect(
100
+ reaches(whole("../storefront.malloy"), ...args, [
101
+ "data_app.malloy",
102
+ "storefront.malloy",
103
+ ]),
104
+ ).toBe(true);
105
+ });
106
+
107
+ it("reads './../m.malloy' as '../m.malloy'", () => {
108
+ expect(
109
+ reaches(
110
+ whole("./../storefront.malloy"),
111
+ "orders",
112
+ "storefront.malloy",
113
+ "dashboards/x.malloy",
114
+ ),
115
+ ).toBe(true);
116
+ });
61
117
  });
@@ -37,44 +37,47 @@ export function importPathOf(modelPath: string, documentPath: string): string {
37
37
  }
38
38
 
39
39
  /**
40
- * Whether the file can already see `name` from `modelPath`: it extends it,
41
- * imports it by name, or imports that model whole. A whole-file import brings
42
- * every source the model exports, and naming one of them again would declare
43
- * it twice. A source the file sees only through another model that re-exports
44
- * it is not followed: that needs the catalog to say which model declares each
45
- * source, and the compile check on save catches the duplicate.
40
+ * Whether the file can already see `name`: it extends it, imports it by name,
41
+ * or imports a model that exports it whole. A whole-file import brings every
42
+ * source the model exports, and naming one again would declare it twice.
43
+ * `exporters` is every model that exports `name`, `[modelPath]` when the
44
+ * catalog names one.
46
45
  */
47
46
  export function reaches(
48
47
  document: Pick<DashboardDocument, "imports" | "sources">,
49
48
  name: string,
50
49
  modelPath: string,
51
50
  documentPath: string = DEFAULT_DOCUMENT_PATH,
51
+ exporters: readonly string[] = [modelPath],
52
52
  ): boolean {
53
53
  if (document.sources.some((s) => s.base === name)) return true;
54
54
  return document.imports.some((i) =>
55
55
  i.kind === "names"
56
56
  ? i.names.includes(name)
57
- : resolvedOf(i.from, documentPath) === modelPath,
57
+ : exporters.includes(resolvedOf(i.from, documentPath)),
58
58
  );
59
59
  }
60
60
 
61
61
  /**
62
- * `imports` with `name` from `modelPath` brought in, by name — into that
63
- * model's existing `{ … }` import when there is one, else as a new statement
64
- * written relative to where the document sits. Unchanged when the file can
65
- * already see it.
62
+ * `imports` with `name` brought in by name, from the exporter the file already
63
+ * imports by name when there is one (else `modelPath`) — into that model's
64
+ * existing `{ … }` import, else as a new statement written relative to where
65
+ * the document sits. Unchanged when the file can already see it.
66
66
  */
67
67
  export function withSource(
68
68
  document: Pick<DashboardDocument, "imports" | "sources">,
69
69
  name: string,
70
70
  modelPath: string,
71
71
  documentPath: string = DEFAULT_DOCUMENT_PATH,
72
+ exporters: readonly string[] = [modelPath],
72
73
  ): DashboardImport[] {
73
74
  const { imports } = document;
74
- if (reaches(document, name, modelPath, documentPath)) return imports;
75
+ if (reaches(document, name, modelPath, documentPath, exporters))
76
+ return imports;
75
77
  const at = imports.findIndex(
76
78
  (i) =>
77
- i.kind === "names" && resolvedOf(i.from, documentPath) === modelPath,
79
+ i.kind === "names" &&
80
+ exporters.includes(resolvedOf(i.from, documentPath)),
78
81
  );
79
82
  if (at < 0)
80
83
  return [
@@ -64,6 +64,27 @@ describe("previewGivens", () => {
64
64
  });
65
65
  });
66
66
 
67
+ it("shows a filter default as the server publishes it: unwrapped, and none when empty", () => {
68
+ const filtered: DashboardDocument = {
69
+ ...document,
70
+ localGivens: [
71
+ { name: "EMPTY", type: "filter<string>", default: "f''" },
72
+ { name: "STATE", type: "filter<string>", default: "f'WN'" },
73
+ ],
74
+ tiles: [
75
+ tile("t", "v", [
76
+ { field: "a", given: "EMPTY" },
77
+ { field: "b", given: "STATE" },
78
+ ]),
79
+ ],
80
+ };
81
+ const [empty, state] = previewGivens(filtered, []);
82
+ expect(empty.default).toBeUndefined();
83
+ expect(state.default).toBe("WN");
84
+ // The document keeps the literal the file is written from.
85
+ expect(filtered.localGivens?.[1].default).toBe("f'WN'");
86
+ });
87
+
67
88
  it("uses the model's own spec for a model given a tile binds", () => {
68
89
  const withModel: DashboardDocument = {
69
90
  ...document,
@@ -69,10 +69,11 @@ export function previewGivens(
69
69
 
70
70
  /** A `given:` this file declares, as the `Given` the control row renders. */
71
71
  function givenFromLocal(local: LocalGiven): Given {
72
+ const shown = displayDefault(local);
72
73
  return {
73
74
  name: local.name,
74
75
  type: local.type,
75
- default: local.default,
76
+ ...(shown === undefined ? {} : { default: shown }),
76
77
  ...(local.label === undefined ? {} : { label: local.label }),
77
78
  ...(local.description === undefined
78
79
  ? {}
@@ -98,6 +99,14 @@ function givenFromLocal(local: LocalGiven): Given {
98
99
  };
99
100
  }
100
101
 
102
+ /** The default the server would publish: it unwraps a filter's `f'…'`, so an empty one shows no caption. */
103
+ function displayDefault(local: LocalGiven): string | undefined {
104
+ if (!local.type?.startsWith("filter<")) return local.default;
105
+ const body = local.default?.match(/^f(['"])([\s\S]*)\1$/)?.[2];
106
+ if (body === undefined) return local.default;
107
+ return body === "" ? undefined : body;
108
+ }
109
+
101
110
  /**
102
111
  * Whether dropping the wrapper's chart line leaves a view with no chart of its own: an inline
103
112
  * body, a `{ … } + { … }` compound or a `->` pipeline. Any other opaque body starts from a
@@ -1456,17 +1456,32 @@ source: products_tiles is products extend {
1456
1456
  `);
1457
1457
  });
1458
1458
 
1459
- it("refuses a tile on a source the file does not import by name", async () => {
1460
- const r = await splice(SOURCE, (d) => {
1461
- d.sources.push({ name: "orders_tiles", base: "order_items" });
1462
- d.tiles.push({
1463
- name: "t",
1464
- source: "orders_tiles",
1465
- declaration: { kind: "reference", from: "by_category" },
1466
- });
1459
+ const addOnOrderItems = (d: DashboardDocument) => {
1460
+ d.sources.push({ name: "orders_tiles", base: "order_items" });
1461
+ d.tiles.push({
1462
+ name: "t",
1463
+ source: "orders_tiles",
1464
+ declaration: { kind: "reference", from: "by_category" },
1467
1465
  });
1466
+ };
1467
+
1468
+ it("refuses a tile on a source the file does not import", async () => {
1469
+ const r = await splice(
1470
+ SOURCE.replace('import "../data_app.malloy"\n', ""),
1471
+ addOnOrderItems,
1472
+ );
1468
1473
  expect(r.ok).toBe(false);
1469
- if (spliceFailed(r)) expect(r.reason).toContain("not imported by name");
1474
+ if (spliceFailed(r))
1475
+ expect(r.reason).toContain(
1476
+ "`order_items` is not imported in this file",
1477
+ );
1478
+ });
1479
+
1480
+ // A whole-file import brings every source the model exports, so the builder
1481
+ // adds no named import and the extension has to be accepted without one.
1482
+ it("accepts a tile on a source a whole-file import carries", async () => {
1483
+ const r = await splice(SOURCE, addOnOrderItems);
1484
+ expect(r.ok).toBe(true);
1470
1485
  });
1471
1486
  });
1472
1487
 
@@ -348,6 +348,7 @@ function checkShape(
348
348
  current: DashboardDocument,
349
349
  next: DashboardDocument,
350
350
  changeKind: boolean,
351
+ visibleSources: readonly string[] | undefined,
351
352
  ): SpliceFailure | TileMembership {
352
353
  if (kindOf(current) !== kindOf(next) && !changeKind) {
353
354
  return {
@@ -384,12 +385,14 @@ function checkShape(
384
385
  }
385
386
  // Sources may only be ADDED, and only for a tile being added on them — the
386
387
  // builder never renames or removes an extension, so a new extension's base
387
- // has to be a source the file imports by name (or already extends).
388
+ // has to be a source the file imports by name, already extends, or gets
389
+ // through a whole-file import; a document held as text sees its run model's.
388
390
  const currentSources = new Map(current.sources.map((s) => [s.name, s]));
389
391
  const importedByName = new Set(
390
392
  next.imports.flatMap((i) => (i.kind === "names" ? i.names : [])),
391
393
  );
392
394
  for (const source of current.sources) importedByName.add(source.base);
395
+ const wholeFile = next.imports.some((i) => i.kind === "all");
393
396
  const newSources = next.sources.filter((s) => !currentSources.has(s.name));
394
397
  for (const source of current.sources) {
395
398
  const still = next.sources.find((s) => s.name === source.name);
@@ -407,12 +410,14 @@ function checkShape(
407
410
  reason: `A new source \`${source.name}\` needs a tile on it.`,
408
411
  };
409
412
  }
410
- if (!importedByName.has(source.base)) {
413
+ if (
414
+ !importedByName.has(source.base) &&
415
+ !wholeFile &&
416
+ !visibleSources?.includes(source.base)
417
+ ) {
411
418
  return {
412
419
  ok: false,
413
- reason:
414
- `\`${source.base}\` is not imported by name in this file, so a ` +
415
- `tile cannot be put on it. Add it as a source first.`,
420
+ reason: `\`${source.base}\` is not imported in this file, so a tile cannot be put on it.`,
416
421
  };
417
422
  }
418
423
  }
@@ -2074,6 +2079,8 @@ export interface SpliceOptions {
2074
2079
  modelPath?: string;
2075
2080
  /** Write `kind=dashboard` too, whatever the folder: for a document held as text, which the server reads by its tags and not by a folder. */
2076
2081
  explicitKind?: boolean;
2082
+ /** The sources a document held as text sees without an `import`: its run model's. */
2083
+ visibleSources?: readonly string[];
2077
2084
  }
2078
2085
 
2079
2086
  export async function spliceDashboardDocument(
@@ -2108,7 +2115,12 @@ async function spliceLines(
2108
2115
  }
2109
2116
  const current = before.document;
2110
2117
  const next = keepUnstatedCharts(current, requested);
2111
- const shape = checkShape(current, next, options.changeKind === true);
2118
+ const shape = checkShape(
2119
+ current,
2120
+ next,
2121
+ options.changeKind === true,
2122
+ options.visibleSources,
2123
+ );
2112
2124
  if ("reason" in shape) return shape;
2113
2125
  const problem = unwritable(current, next);
2114
2126
  if (problem) return { ok: false, reason: problem };
@@ -50,8 +50,11 @@ export function useDashboardEditor(options: {
50
50
  modelPath?: string;
51
51
  /** The document is held as text: a kind switch always writes `kind=`. */
52
52
  explicitKind?: boolean;
53
+ /** The sources a document held as text sees without an `import`. */
54
+ visibleSources?: readonly string[];
53
55
  }): DashboardEditor {
54
- const { conversion, modelPath, explicitKind, ...rest } = options;
56
+ const { conversion, modelPath, explicitKind, visibleSources, ...rest } =
57
+ options;
55
58
  const from = conversion?.from;
56
59
  const to = conversion?.to;
57
60
  const splice = useCallback(
@@ -64,9 +67,10 @@ export function useDashboardEditor(options: {
64
67
  changeKind: true,
65
68
  ...(modelPath !== undefined ? { modelPath } : {}),
66
69
  ...(explicitKind ? { explicitKind } : {}),
70
+ ...(visibleSources ? { visibleSources } : {}),
67
71
  },
68
72
  ),
69
- [from, to, modelPath, explicitKind],
73
+ [from, to, modelPath, explicitKind, visibleSources],
70
74
  );
71
75
  return useDocumentEditor({
72
76
  ...rest,
@@ -3,13 +3,8 @@
3
3
 
4
4
  import { useState } from "react";
5
5
  import type { NewTile } from "./AddTileDialog";
6
- import {
7
- isQueryTile,
8
- isTextTile,
9
- tileKey,
10
- type DashboardTile,
11
- } from "./document";
12
- import { withSource } from "./imports";
6
+ import { isTextTile, tileKey, type DashboardTile } from "./document";
7
+ import { addTileToDocument } from "./addTileToDocument";
13
8
  import type { DashboardEditor } from "./useDashboardEditor";
14
9
 
15
10
  /**
@@ -21,6 +16,7 @@ export function useTileEditing({
21
16
  notebook,
22
17
  columns,
23
18
  modelPath,
19
+ textHeld,
24
20
  selectTile,
25
21
  deselectTile,
26
22
  }: {
@@ -29,6 +25,8 @@ export function useTileEditing({
29
25
  columns: number;
30
26
  /** The document's file within the package, which a tile's import is relative to. */
31
27
  modelPath: string | undefined;
28
+ /** The document is held as text: it has no `import`, so a tile's source is the run model's and nothing is imported. */
29
+ textHeld: boolean;
32
30
  selectTile: (index: number) => void;
33
31
  deselectTile: () => void;
34
32
  }) {
@@ -49,47 +47,14 @@ export function useTileEditing({
49
47
  /** A tile from the picker: on the extension of its source, or a new one. */
50
48
  const addTile = (tile: NewTile) => {
51
49
  setAddingTile(false);
52
- editor.update((draft) => {
53
- // A source the file cannot see yet comes in by name, with the tile.
54
- if (tile.modelPath)
55
- draft.imports = withSource(
56
- draft,
57
- tile.base,
58
- tile.modelPath,
59
- ...(modelPath ? [modelPath] : []),
60
- );
61
- let extension = draft.sources.find((s) => s.base === tile.base);
62
- if (!extension) {
63
- // A name of the file's own: the base's, suffixed, since an
64
- // extension cannot share its base's name.
65
- const taken = new Set(draft.sources.map((s) => s.name));
66
- let name = `${tile.base}_tiles`;
67
- for (let n = 2; taken.has(name); n++)
68
- name = `${tile.base}_tiles_${n}`;
69
- extension = { name, base: tile.base };
70
- draft.sources.push(extension);
71
- }
72
- // The view's name in the extension: the base view's, suffixed,
73
- // because an extension inherits its base's views and cannot redeclare
74
- // one under the same name; then kept distinct from its siblings.
75
- const used = new Set(
76
- draft.tiles
77
- .filter(isQueryTile)
78
- .filter((t) => t.source === extension!.name)
79
- .map((t) => t.name),
80
- );
81
- let name = `${tile.view}_tile`;
82
- for (let n = 2; used.has(name); n++) name = `${tile.view}_tile_${n}`;
83
- draft.tiles.splice(insertAt ?? draft.tiles.length, 0, {
84
- name,
85
- source: extension.name,
86
- declaration: { kind: "reference", from: tile.view },
87
- ...(notebook ? {} : { colspan: tile.colspan }),
88
- ...(tile.label ? { label: tile.label } : {}),
89
- ...(tile.chart ? { chart: tile.chart } : {}),
90
- ...(tile.chartCarried ? { chartCarried: tile.chartCarried } : {}),
91
- });
92
- });
50
+ editor.update((draft) =>
51
+ addTileToDocument(draft, tile, {
52
+ modelPath,
53
+ textHeld,
54
+ notebook,
55
+ insertAt,
56
+ }),
57
+ );
93
58
  selectTile(insertAt ?? editor.document.tiles.length);
94
59
  };
95
60
 
@@ -301,6 +301,18 @@ div.malloy-render .malloy-dashboard .dashboard-row-header {
301
301
  the border's job, and the border is already doing it. */
302
302
  box-shadow: none !important;
303
303
  }
304
+ /* The strip of big-value cards as a grid, so cards share a width and the last one does not wrap
305
+ alone. The renderer's wrapping flex row sizes each card to its own text. The 250px floor is the
306
+ widest realistic value: it is nowrap at 32px in an overflow:visible card, so a narrower track
307
+ would spill it onto its neighbour. Embedded (a nested big_value) is left as the renderer draws it. */
308
+ .malloy-render .malloy-big-value:not(.malloy-big-value--embedded) {
309
+ display: grid;
310
+ grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
311
+ }
312
+ .malloy-render .malloy-big-value-card:not(.malloy-big-value-card--embedded) {
313
+ width: auto;
314
+ max-width: none;
315
+ }
304
316
  .malloy-render .malloy-dashboard .dashboard-row-header-separator {
305
317
  background: var(--malloy-render--table-border) !important;
306
318
  }