@malloy-publisher/sdk 0.9.1 → 0.9.2
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.
- package/dist/{Dashboard-H1kJlDFo.es.js → DashboardTile-BFcxdv7R.es.js} +15918 -17760
- package/dist/DashboardTile-sg8LjUk8.cjs.js +137 -0
- package/dist/RenderedResult-B48wAjM8.cjs.js +141 -0
- package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-CBLHr32C.es.js} +193 -183
- package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-DCV8BUWD.es.js} +529 -521
- package/dist/ServerProvider-HRqT3w1C.cjs.js +1 -0
- package/dist/builder/index.cjs.js +146 -58
- package/dist/builder/index.es.js +9076 -6479
- package/dist/builder-entry.d.ts +4 -0
- package/dist/client/api.d.ts +77 -47
- package/dist/client/configuration.d.ts +1 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.es.js +84 -82
- package/dist/components/Dashboard/Dashboard.d.ts +8 -15
- package/dist/components/Dashboard/DashboardGrid.d.ts +23 -6
- package/dist/components/Dashboard/DashboardTile.d.ts +10 -1
- package/dist/components/Dashboard/DashboardView.d.ts +36 -0
- package/dist/components/Dashboard/TileCard.d.ts +15 -4
- package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
- package/dist/components/Dashboard/index.d.ts +3 -0
- package/dist/components/Dashboard/telemetry.d.ts +15 -3
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -1
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +16 -5
- package/dist/components/DashboardBuilder/ChartPicker.d.ts +29 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +48 -21
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +17 -4
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +2 -10
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +3 -1
- package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
- package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
- package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
- package/dist/components/DashboardBuilder/SaveNotice.d.ts +27 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +19 -7
- package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
- package/dist/components/DashboardBuilder/TextTileBody.d.ts +7 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +14 -12
- package/dist/components/DashboardBuilder/TileMenu.d.ts +11 -3
- package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +4 -0
- package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
- package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
- package/dist/components/DashboardBuilder/controls.d.ts +2 -2
- package/dist/components/DashboardBuilder/document.d.ts +42 -26
- package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
- package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
- package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -5
- package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
- package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
- package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
- package/dist/components/DashboardBuilder/preview.d.ts +24 -4
- package/dist/components/DashboardBuilder/readDocument.d.ts +4 -1
- package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +14 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +13 -13
- package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
- package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
- package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
- package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
- package/dist/components/DashboardBuilder/useBuilderSession.d.ts +89 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +17 -55
- package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
- package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
- package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
- package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
- package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
- package/dist/components/DocumentCreate/events.d.ts +10 -0
- package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
- package/dist/components/DocumentCreate/guards.d.ts +12 -0
- package/dist/components/DocumentCreate/index.d.ts +6 -0
- package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
- package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
- package/dist/components/NarrowEditGate.d.ts +8 -0
- package/dist/components/Notebook/Notebook.d.ts +1 -1
- package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
- package/dist/components/Package/Package.d.ts +1 -0
- package/dist/components/Package/documentLocation.d.ts +28 -0
- package/dist/components/Package/index.d.ts +4 -0
- package/dist/components/Package/useDocumentLocation.d.ts +12 -0
- package/dist/components/PackageSection.d.ts +2 -2
- package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
- package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
- package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
- package/dist/components/ServerProvider.d.ts +2 -1
- package/dist/components/UnsavedChangesDialog.d.ts +9 -0
- package/dist/components/given/GivensPanel.d.ts +2 -2
- package/dist/components/index.d.ts +2 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useNarrowScreen.d.ts +4 -0
- package/dist/hooks/useQueryResult.d.ts +2 -0
- package/dist/hooks/useSettled.d.ts +14 -0
- package/dist/index.cjs.js +23 -24
- package/dist/index.es.js +9714 -7072
- package/dist/text/index.cjs.js +1 -0
- package/dist/text/index.d.ts +2 -0
- package/dist/text/index.es.js +6 -0
- package/dist/text-entry-BJwltZiy.cjs.js +7 -0
- package/dist/text-entry-CbbBcZl8.es.js +196 -0
- package/dist/text-entry.d.ts +2 -0
- package/dist/utils/clock.d.ts +2 -0
- package/package.json +10 -1
- package/src/builder-entry.ts +35 -0
- package/src/components/Dashboard/Dashboard.tsx +27 -278
- package/src/components/Dashboard/DashboardGrid.tsx +68 -7
- package/src/components/Dashboard/DashboardTile.spec.tsx +24 -0
- package/src/components/Dashboard/DashboardTile.tsx +31 -4
- package/src/components/Dashboard/DashboardView.spec.tsx +212 -0
- package/src/components/Dashboard/DashboardView.tsx +352 -0
- package/src/components/Dashboard/RowsDialog.tsx +1 -1
- package/src/components/Dashboard/TileCard.tsx +44 -10
- package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
- package/src/components/Dashboard/TileFilterTag.tsx +78 -0
- package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
- package/src/components/Dashboard/index.ts +3 -0
- package/src/components/Dashboard/telemetry.ts +16 -5
- package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
- package/src/components/DashboardBuilder/AddTileDialog.tsx +137 -111
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +85 -27
- package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
- package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
- package/src/components/DashboardBuilder/ChartPicker.tsx +153 -0
- package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
- package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +192 -0
- package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +329 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +363 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +194 -0
- package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +157 -0
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +124 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +103 -78
- package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +177 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +610 -315
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +58 -8
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +191 -0
- package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
- package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +316 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +56 -10
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +5 -22
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +96 -14
- package/src/components/DashboardBuilder/DashboardEditor.tsx +482 -332
- package/src/components/DashboardBuilder/DiffDialog.spec.tsx +25 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +5 -24
- package/src/components/DashboardBuilder/DrillDialog.tsx +1 -1
- package/src/components/DashboardBuilder/FilterDialog.tsx +10 -3
- package/src/components/DashboardBuilder/FilterStrip.tsx +26 -4
- package/src/components/DashboardBuilder/InlineMarkdown.tsx +184 -0
- package/src/components/DashboardBuilder/InlineText.tsx +106 -0
- package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
- package/src/components/DashboardBuilder/SaveNotice.tsx +113 -0
- package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +87 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +225 -67
- package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
- package/src/components/DashboardBuilder/TextTileBody.tsx +28 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +89 -115
- package/src/components/DashboardBuilder/TileMenu.tsx +168 -90
- package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
- package/src/components/DashboardBuilder/annotationText.ts +17 -0
- package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
- package/src/components/DashboardBuilder/artifactTagParity.spec.ts +41 -0
- package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +2 -0
- package/src/components/DashboardBuilder/catalog.ts +61 -21
- package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
- package/src/components/DashboardBuilder/changedTile.ts +28 -0
- package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
- package/src/components/DashboardBuilder/chartLine.ts +121 -0
- package/src/components/DashboardBuilder/controls.spec.ts +21 -10
- package/src/components/DashboardBuilder/controls.ts +22 -8
- package/src/components/DashboardBuilder/document.ts +53 -5
- package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
- package/src/components/DashboardBuilder/documentSession.ts +257 -0
- package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
- package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
- package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
- package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
- package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
- package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
- package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
- package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +48 -0
- package/src/components/DashboardBuilder/malloyText.ts +181 -27
- package/src/components/DashboardBuilder/malloyTree.ts +155 -7
- package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
- package/src/components/DashboardBuilder/newDashboard.ts +30 -3
- package/src/components/DashboardBuilder/openDraft.ts +52 -0
- package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
- package/src/components/DashboardBuilder/preview.spec.ts +159 -12
- package/src/components/DashboardBuilder/preview.ts +83 -9
- package/src/components/DashboardBuilder/readDocument.spec.ts +139 -27
- package/src/components/DashboardBuilder/readDocument.ts +130 -44
- package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
- package/src/components/DashboardBuilder/readForEditor.ts +47 -0
- package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
- package/src/components/DashboardBuilder/sortable.spec.ts +65 -0
- package/src/components/DashboardBuilder/sortable.tsx +2 -12
- package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
- package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
- package/src/components/DashboardBuilder/spliceDocument.ts +762 -130
- package/src/components/DashboardBuilder/spliceResult.ts +15 -0
- package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
- package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
- package/src/components/DashboardBuilder/tagParse.ts +103 -0
- package/src/components/DashboardBuilder/telemetry.ts +47 -0
- package/src/components/DashboardBuilder/testing/artifactTagParity.json +197 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
- package/src/components/DashboardBuilder/testing/inline.ts +25 -0
- package/src/components/DashboardBuilder/textTiles.spec.ts +718 -0
- package/src/components/DashboardBuilder/useBuilderSession.spec.ts +335 -0
- package/src/components/DashboardBuilder/useBuilderSession.ts +292 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +65 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +36 -10
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
- package/src/components/DashboardBuilder/useDashboardEditor.ts +54 -181
- package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
- package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
- package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
- package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
- package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
- package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
- package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
- package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
- package/src/components/DocumentCreate/canRetry.ts +19 -0
- package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
- package/src/components/DocumentCreate/createDocument.ts +159 -0
- package/src/components/DocumentCreate/documentPath.ts +40 -0
- package/src/components/DocumentCreate/events.ts +15 -0
- package/src/components/DocumentCreate/exportedSources.ts +25 -0
- package/src/components/DocumentCreate/guards.ts +45 -0
- package/src/components/DocumentCreate/index.ts +27 -0
- package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
- package/src/components/DocumentCreate/newNotebook.ts +44 -0
- package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
- package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
- package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
- package/src/components/Model/ModelExplorer.spec.tsx +2 -2
- package/src/components/Model/SourcesExplorer.tsx +2 -4
- package/src/components/NarrowEditGate.spec.tsx +73 -0
- package/src/components/NarrowEditGate.tsx +29 -0
- package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
- package/src/components/Notebook/Notebook.tsx +66 -27
- package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
- package/src/components/Package/NewDocumentDialog.tsx +401 -0
- package/src/components/Package/Package.artifacts.spec.tsx +190 -0
- package/src/components/Package/Package.create.spec.tsx +380 -0
- package/src/components/Package/Package.notebooks.spec.tsx +18 -0
- package/src/components/Package/Package.tsx +366 -171
- package/src/components/Package/documentLocation.spec.ts +81 -0
- package/src/components/Package/documentLocation.ts +55 -0
- package/src/components/Package/index.ts +13 -0
- package/src/components/Package/useDocumentLocation.ts +59 -0
- package/src/components/PackageSection.tsx +2 -2
- package/src/components/RenderedResult/RenderedResult.tsx +18 -1
- package/src/components/RenderedResult/ResultContainer.tsx +44 -11
- package/src/components/RenderedResult/ResultPanel.tsx +4 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
- package/src/components/RenderedResult/resultSizing.ts +14 -3
- package/src/components/ServerProvider.tsx +2 -1
- package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
- package/src/components/UnsavedChangesDialog.tsx +49 -0
- package/src/components/given/GivensPanel.spec.tsx +6 -6
- package/src/components/given/GivensPanel.tsx +3 -3
- package/src/components/index.ts +2 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useNarrowScreen.ts +21 -0
- package/src/hooks/useQueryResult.ts +16 -0
- package/src/hooks/useSettled.spec.ts +41 -0
- package/src/hooks/useSettled.ts +27 -0
- package/src/mainEntry.spec.ts +145 -0
- package/src/text-entry.ts +12 -0
- package/src/textEntry.spec.ts +118 -0
- package/src/utils/clock.spec.ts +12 -0
- package/src/utils/clock.ts +6 -0
- package/vite.config.ts +4 -0
- package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
- package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
- package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
- package/dist/components/DashboardBuilder/useTileResize.d.ts +0 -29
- package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +0 -121
- package/src/components/DashboardBuilder/useTileResize.ts +0 -110
- package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
- package/src/components/Package/NewDashboardDialog.tsx +0 -265
|
@@ -0,0 +1,718 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import {
|
|
6
|
+
isQueryTile,
|
|
7
|
+
isTextTile,
|
|
8
|
+
type DashboardDocument,
|
|
9
|
+
type TextTile,
|
|
10
|
+
} from "./document";
|
|
11
|
+
import { readTileList } from "./malloyTree";
|
|
12
|
+
import { readDashboardDocument, readFailed } from "./readDocument";
|
|
13
|
+
import {
|
|
14
|
+
markdownProblem,
|
|
15
|
+
spliceDashboardDocument,
|
|
16
|
+
spliceFailed,
|
|
17
|
+
syntaxErrors,
|
|
18
|
+
} from "./spliceDocument";
|
|
19
|
+
import { openDocument, refused } from "./testing/fixtures";
|
|
20
|
+
import { whatMoved } from "./__test__/inventory";
|
|
21
|
+
|
|
22
|
+
const NOTEBOOK = `##! experimental.givens
|
|
23
|
+
##" A review.
|
|
24
|
+
## artifact { kind=notebook title="Review" tiles=[intro { kind=text }, "a_tiles -> cell_1", outro { kind=text colspan=6 break }] }
|
|
25
|
+
import { a } from "../m.malloy"
|
|
26
|
+
|
|
27
|
+
##|(markdown) intro
|
|
28
|
+
# Review
|
|
29
|
+
|
|
30
|
+
Welcome to **the review**.
|
|
31
|
+
|##
|
|
32
|
+
|
|
33
|
+
source: a_tiles is a extend {
|
|
34
|
+
# label="By category"
|
|
35
|
+
view: cell_1 is by_cat
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
##|(markdown) outro
|
|
39
|
+
Bye.
|
|
40
|
+
|##
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
const DASHBOARD = `## artifact { title="D" tiles=["a_tiles -> x"] } dashboard { columns=12 }
|
|
44
|
+
import { a } from "../m.malloy"
|
|
45
|
+
|
|
46
|
+
source: a_tiles is a extend {
|
|
47
|
+
# colspan=6
|
|
48
|
+
view: x is vx
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
const text = (document: DashboardDocument, name: string): TextTile => {
|
|
53
|
+
const tile = document.tiles.find((t) => isTextTile(t) && t.name === name);
|
|
54
|
+
if (!tile || !isTextTile(tile)) throw new Error(`no text tile ${name}`);
|
|
55
|
+
return tile;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** Whatever the writer produced must be a file Malloy parses and the reader reads back as asked. */
|
|
59
|
+
async function writes(
|
|
60
|
+
source: string,
|
|
61
|
+
edit: (document: DashboardDocument) => void,
|
|
62
|
+
options?: { changeKind?: boolean; modelPath?: string },
|
|
63
|
+
): Promise<{ out: string; document: DashboardDocument }> {
|
|
64
|
+
const next = structuredClone(await openDocument(source));
|
|
65
|
+
edit(next);
|
|
66
|
+
const result = await spliceDashboardDocument(source, next, options);
|
|
67
|
+
if (spliceFailed(result)) throw new Error(result.reason);
|
|
68
|
+
expect(await syntaxErrors(result.source)).toEqual([]);
|
|
69
|
+
return { out: result.source, document: await openDocument(result.source) };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
describe("readTileList", () => {
|
|
73
|
+
it("splits quoted and object entries and keeps them as written", () => {
|
|
74
|
+
const line = `## artifact { title="x" tiles=[a { kind=text colspan=6 }, "s -> v", b{kind=text}] }`;
|
|
75
|
+
const list = readTileList(line);
|
|
76
|
+
expect(list?.entries.map((e) => e.text)).toEqual([
|
|
77
|
+
"a { kind=text colspan=6 }",
|
|
78
|
+
'"s -> v"',
|
|
79
|
+
"b{kind=text}",
|
|
80
|
+
]);
|
|
81
|
+
expect(line.slice(list!.open, list!.close + 1)).toBe(
|
|
82
|
+
'[a { kind=text colspan=6 }, "s -> v", b{kind=text}]',
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("is not fooled by a title holding tiles=[ or ]", () => {
|
|
87
|
+
const line = `## artifact { title="tiles=[\\"x\\"] ]" tiles=["a -> b"] }`;
|
|
88
|
+
expect(readTileList(line)?.entries.map((e) => e.text)).toEqual([
|
|
89
|
+
'"a -> b"',
|
|
90
|
+
]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("is undefined with no list or an unclosed one", () => {
|
|
94
|
+
expect(readTileList(`## artifact { title="x" }`)).toBeUndefined();
|
|
95
|
+
expect(readTileList(`## artifact { tiles=["a -> b" }`)).toBeUndefined();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("reads an empty list as no entries", () => {
|
|
99
|
+
expect(readTileList(`## artifact { tiles=[ ] }`)?.entries).toEqual([]);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe("readDashboardDocument: text tiles and kind", () => {
|
|
104
|
+
it("reads a layout notebook: kind, text tiles in order, their blocks and list properties", async () => {
|
|
105
|
+
const document = await openDocument(NOTEBOOK);
|
|
106
|
+
expect(document.kind).toBe("notebook");
|
|
107
|
+
expect(document.title).toBe("Review");
|
|
108
|
+
expect(
|
|
109
|
+
document.tiles.map((t) => `${t.kind ?? "query"}:${t.name}`),
|
|
110
|
+
).toEqual(["text:intro", "query:cell_1", "text:outro"]);
|
|
111
|
+
expect(text(document, "intro")).toEqual({
|
|
112
|
+
kind: "text",
|
|
113
|
+
name: "intro",
|
|
114
|
+
markdown: "# Review\n\nWelcome to **the review**.",
|
|
115
|
+
});
|
|
116
|
+
expect(text(document, "outro")).toEqual({
|
|
117
|
+
kind: "text",
|
|
118
|
+
name: "outro",
|
|
119
|
+
markdown: "Bye.",
|
|
120
|
+
colspan: 6,
|
|
121
|
+
break: true,
|
|
122
|
+
});
|
|
123
|
+
const query = document.tiles.find(isQueryTile);
|
|
124
|
+
expect(query?.label).toBe("By category");
|
|
125
|
+
expect(query?.source).toBe("a_tiles");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("leaves kind out for a dashboard", async () => {
|
|
129
|
+
expect((await openDocument(DASHBOARD)).kind).toBeUndefined();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("reads a listed text tile whose block is missing as empty prose", async () => {
|
|
133
|
+
const source = NOTEBOOK.replace(/##\|\(markdown\) outro[\s\S]*$/, "");
|
|
134
|
+
expect(text(await openDocument(source), "outro").markdown).toBe("");
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("reads a block's body through its first line when the opener carries text", async () => {
|
|
138
|
+
const source = NOTEBOOK.replace(
|
|
139
|
+
"##|(markdown) intro\n# Review",
|
|
140
|
+
"##|(markdown) intro\n## Heading",
|
|
141
|
+
);
|
|
142
|
+
expect(text(await openDocument(source), "intro").markdown).toBe(
|
|
143
|
+
"## Heading\n\nWelcome to **the review**.",
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("reads an unnamed or other block as nobody's body", async () => {
|
|
148
|
+
const source = NOTEBOOK.replace(
|
|
149
|
+
"##|(markdown) outro",
|
|
150
|
+
"##|(markdown) not a name",
|
|
151
|
+
);
|
|
152
|
+
expect(text(await openDocument(source), "outro").markdown).toBe("");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("marks a notebook with no tiles list as the cell format", async () => {
|
|
156
|
+
const result = await readDashboardDocument(
|
|
157
|
+
`## artifact { kind=notebook title="Old" }\nimport { a } from "../m.malloy"\n\nrun: a -> v\n`,
|
|
158
|
+
);
|
|
159
|
+
if (!readFailed(result)) throw new Error("expected a refusal");
|
|
160
|
+
expect(result.legacyNotebook).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("still refuses a dashboard with no tiles list, without the legacy mark", async () => {
|
|
164
|
+
const result = await readDashboardDocument(
|
|
165
|
+
`## artifact { title="D" }\nimport { a } from "../m.malloy"\n`,
|
|
166
|
+
);
|
|
167
|
+
if (!readFailed(result)) throw new Error("expected a refusal");
|
|
168
|
+
expect(result.legacyNotebook).toBeUndefined();
|
|
169
|
+
expect(result.reason).toContain("tiles");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("reads an empty tiles list on a notebook as a layout notebook with no tiles", async () => {
|
|
173
|
+
const document = await openDocument(
|
|
174
|
+
`## artifact { kind=notebook title="E" tiles=[] }\n`,
|
|
175
|
+
);
|
|
176
|
+
expect(document.tiles).toEqual([]);
|
|
177
|
+
expect(document.kind).toBe("notebook");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("refuses an entry that is neither quoted nor kind=text", async () => {
|
|
181
|
+
const result = await readDashboardDocument(
|
|
182
|
+
NOTEBOOK.replace(
|
|
183
|
+
"outro { kind=text colspan=6 break }",
|
|
184
|
+
"outro { kind=md }",
|
|
185
|
+
),
|
|
186
|
+
);
|
|
187
|
+
if (!readFailed(result)) throw new Error("expected a refusal");
|
|
188
|
+
expect(result.reason).toContain("outro");
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("refuses a quoted entry that is not source -> view", async () => {
|
|
192
|
+
const result = await readDashboardDocument(
|
|
193
|
+
NOTEBOOK.replace('"a_tiles -> cell_1"', '"a_tiles"'),
|
|
194
|
+
);
|
|
195
|
+
if (!readFailed(result)) throw new Error("expected a refusal");
|
|
196
|
+
expect(result.reason).toContain("source -> view");
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("refuses two text tiles of one name", async () => {
|
|
200
|
+
const result = await readDashboardDocument(
|
|
201
|
+
NOTEBOOK.replace("outro {", "intro {"),
|
|
202
|
+
);
|
|
203
|
+
if (!readFailed(result)) throw new Error("expected a refusal");
|
|
204
|
+
expect(result.reason).toContain("intro");
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe("spliceDashboardDocument: text tiles", () => {
|
|
209
|
+
it("writes an unchanged notebook back byte for byte", async () => {
|
|
210
|
+
const { out } = await writes(NOTEBOOK, () => {});
|
|
211
|
+
expect(out).toBe(NOTEBOOK);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("edits only the block when the prose changes", async () => {
|
|
215
|
+
const { out, document } = await writes(NOTEBOOK, (d) => {
|
|
216
|
+
text(d, "intro").markdown = "# New\n\n- one\n- two";
|
|
217
|
+
});
|
|
218
|
+
expect(out).toBe(
|
|
219
|
+
NOTEBOOK.replace(
|
|
220
|
+
"# Review\n\nWelcome to **the review**.",
|
|
221
|
+
"# New\n\n- one\n- two",
|
|
222
|
+
),
|
|
223
|
+
);
|
|
224
|
+
expect(text(document, "intro").markdown).toBe("# New\n\n- one\n- two");
|
|
225
|
+
const moved = await whatMoved(NOTEBOOK, out);
|
|
226
|
+
expect(moved.declarations).toEqual([]);
|
|
227
|
+
expect(moved.comments).toEqual([]);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("round-trips prose with headings, trailing newlines and indented closers", async () => {
|
|
231
|
+
for (const markdown of [
|
|
232
|
+
"## Heading",
|
|
233
|
+
"a\n\n\nb",
|
|
234
|
+
"ends with a newline\n",
|
|
235
|
+
" |## indented, so not a closer",
|
|
236
|
+
"# one\n## two\n### three",
|
|
237
|
+
"",
|
|
238
|
+
]) {
|
|
239
|
+
const { document } = await writes(NOTEBOOK, (d) => {
|
|
240
|
+
text(d, "outro").markdown = markdown;
|
|
241
|
+
});
|
|
242
|
+
expect(text(document, "outro").markdown).toBe(markdown);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("adds a text tile: a list entry where it sits and a block at the end", async () => {
|
|
247
|
+
const { out, document } = await writes(NOTEBOOK, (d) => {
|
|
248
|
+
d.tiles.splice(1, 0, {
|
|
249
|
+
kind: "text",
|
|
250
|
+
name: "middle",
|
|
251
|
+
markdown: "Between.",
|
|
252
|
+
colspan: 6,
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
expect(out).toContain(
|
|
256
|
+
'tiles=[intro { kind=text }, middle { kind=text colspan=6 }, "a_tiles -> cell_1", outro { kind=text colspan=6 break }]',
|
|
257
|
+
);
|
|
258
|
+
expect(out.endsWith("##|(markdown) middle\nBetween.\n|##\n")).toBe(true);
|
|
259
|
+
// Nothing above the appended block moved.
|
|
260
|
+
expect(out.startsWith(NOTEBOOK.replace(/\n$/, ""))).toBe(false);
|
|
261
|
+
expect(document.tiles.map((t) => t.name)).toEqual([
|
|
262
|
+
"intro",
|
|
263
|
+
"middle",
|
|
264
|
+
"cell_1",
|
|
265
|
+
"outro",
|
|
266
|
+
]);
|
|
267
|
+
expect(text(document, "middle").markdown).toBe("Between.");
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("adds an empty text tile as an empty block", async () => {
|
|
271
|
+
const { out, document } = await writes(NOTEBOOK, (d) => {
|
|
272
|
+
d.tiles.push({ kind: "text", name: "blank", markdown: "" });
|
|
273
|
+
});
|
|
274
|
+
expect(out).toContain("##|(markdown) blank\n|##\n");
|
|
275
|
+
expect(text(document, "blank").markdown).toBe("");
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("adds a text tile to a dashboard that has none, and to a file with no trailing newline", async () => {
|
|
279
|
+
const bare = DASHBOARD.replace(/\n$/, "");
|
|
280
|
+
const { out, document } = await writes(bare, (d) => {
|
|
281
|
+
d.tiles.unshift({ kind: "text", name: "lead", markdown: "Lead." });
|
|
282
|
+
});
|
|
283
|
+
expect(out).toContain('tiles=[lead { kind=text }, "a_tiles -> x"]');
|
|
284
|
+
expect(out).toContain(
|
|
285
|
+
"\n\n##|(markdown) lead\nLead.\n|##\n\nsource: a_tiles is a extend",
|
|
286
|
+
);
|
|
287
|
+
expect(document.kind).toBeUndefined();
|
|
288
|
+
expect(text(document, "lead").markdown).toBe("Lead.");
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("adds a query tile and a text tile in one edit", async () => {
|
|
292
|
+
const { document } = await writes(DASHBOARD, (d) => {
|
|
293
|
+
d.tiles.push({ kind: "text", name: "note", markdown: "A note." });
|
|
294
|
+
d.tiles.push({
|
|
295
|
+
name: "y",
|
|
296
|
+
source: "a_tiles",
|
|
297
|
+
declaration: { kind: "reference", from: "vy" },
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
expect(document.tiles.map((t) => t.name)).toEqual(["x", "note", "y"]);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("removes a text tile with its entry and its block, and nothing else", async () => {
|
|
304
|
+
const { out } = await writes(NOTEBOOK, (d) => {
|
|
305
|
+
d.tiles = d.tiles.filter((t) => t.name !== "outro");
|
|
306
|
+
});
|
|
307
|
+
expect(out).toBe(
|
|
308
|
+
NOTEBOOK.replace(
|
|
309
|
+
", outro { kind=text colspan=6 break }]",
|
|
310
|
+
"]",
|
|
311
|
+
).replace("\n##|(markdown) outro\nBye.\n|##\n", ""),
|
|
312
|
+
);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("removes the first block without leaving two blank lines", async () => {
|
|
316
|
+
const { out } = await writes(NOTEBOOK, (d) => {
|
|
317
|
+
d.tiles = d.tiles.filter((t) => t.name !== "intro");
|
|
318
|
+
});
|
|
319
|
+
expect(out).not.toContain("##|(markdown) intro");
|
|
320
|
+
expect(out).not.toMatch(/\n\n\n/);
|
|
321
|
+
expect(out).toContain('tiles=["a_tiles -> cell_1", outro');
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it("removes a listed text tile whose block is already gone", async () => {
|
|
325
|
+
const source = NOTEBOOK.replace(/\n##\|\(markdown\) outro[\s\S]*$/, "\n");
|
|
326
|
+
const { out } = await writes(source, (d) => {
|
|
327
|
+
d.tiles = d.tiles.filter((t) => t.name !== "outro");
|
|
328
|
+
});
|
|
329
|
+
expect(out).not.toContain("outro");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("writes a block for a listed text tile that had none, when its prose is set", async () => {
|
|
333
|
+
const source = NOTEBOOK.replace(/\n##\|\(markdown\) outro[\s\S]*$/, "\n");
|
|
334
|
+
const { out, document } = await writes(source, (d) => {
|
|
335
|
+
text(d, "outro").markdown = "Back.";
|
|
336
|
+
});
|
|
337
|
+
expect(out).toContain(
|
|
338
|
+
"|##\n\n##|(markdown) outro\nBack.\n|##\n\nsource: a_tiles",
|
|
339
|
+
);
|
|
340
|
+
expect(text(document, "outro").markdown).toBe("Back.");
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("puts a new block after the last existing one, and at the end of a file with no block or extension", async () => {
|
|
344
|
+
const afterLast = await writes(NOTEBOOK, (d) => {
|
|
345
|
+
d.tiles.push({ kind: "text", name: "coda", markdown: "End." });
|
|
346
|
+
});
|
|
347
|
+
expect(afterLast.out).toContain(
|
|
348
|
+
"Bye.\n|##\n\n##|(markdown) coda\nEnd.\n|##\n",
|
|
349
|
+
);
|
|
350
|
+
const bare = `## artifact { kind=notebook tiles=[] }\nimport { a } from "../m.malloy"\n`;
|
|
351
|
+
const none = await writes(bare, (d) => {
|
|
352
|
+
d.tiles.push({ kind: "text", name: "solo", markdown: "Only." });
|
|
353
|
+
});
|
|
354
|
+
expect(none.out.endsWith("\n\n##|(markdown) solo\nOnly.\n|##\n")).toBe(
|
|
355
|
+
true,
|
|
356
|
+
);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("moves text tiles among the query tiles, keeping each entry as written", async () => {
|
|
360
|
+
const { out, document } = await writes(NOTEBOOK, (d) => {
|
|
361
|
+
d.tiles.reverse();
|
|
362
|
+
});
|
|
363
|
+
expect(out).toContain(
|
|
364
|
+
'tiles=[outro { kind=text colspan=6 break }, "a_tiles -> cell_1", intro { kind=text }]',
|
|
365
|
+
);
|
|
366
|
+
expect(document.tiles.map((t) => t.name)).toEqual([
|
|
367
|
+
"outro",
|
|
368
|
+
"cell_1",
|
|
369
|
+
"intro",
|
|
370
|
+
]);
|
|
371
|
+
// A reorder moves no declaration or block.
|
|
372
|
+
expect(out.slice(out.indexOf("\n", out.indexOf("## artifact")))).toBe(
|
|
373
|
+
NOTEBOOK.slice(
|
|
374
|
+
NOTEBOOK.indexOf("\n", NOTEBOOK.indexOf("## artifact")),
|
|
375
|
+
),
|
|
376
|
+
);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it("changes a text tile's width and row break in its entry, keeping any other property", async () => {
|
|
380
|
+
const source = NOTEBOOK.replace(
|
|
381
|
+
"outro { kind=text colspan=6 break }",
|
|
382
|
+
'outro { kind=text note="a b break colspan=1" colspan=6 break }',
|
|
383
|
+
);
|
|
384
|
+
const { out, document } = await writes(source, (d) => {
|
|
385
|
+
const outro = text(d, "outro");
|
|
386
|
+
outro.colspan = 4;
|
|
387
|
+
delete outro.break;
|
|
388
|
+
});
|
|
389
|
+
expect(out).toContain(
|
|
390
|
+
'outro { kind=text note="a b break colspan=1" colspan=4 }',
|
|
391
|
+
);
|
|
392
|
+
expect(text(document, "outro")).toMatchObject({ colspan: 4 });
|
|
393
|
+
expect(text(document, "outro").break).toBeUndefined();
|
|
394
|
+
// Clearing the width too.
|
|
395
|
+
const cleared = await writes(source, (d) => {
|
|
396
|
+
delete text(d, "outro").colspan;
|
|
397
|
+
});
|
|
398
|
+
expect(cleared.out).toContain(
|
|
399
|
+
'outro { kind=text note="a b break colspan=1" break }',
|
|
400
|
+
);
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it("sets a width on an entry that has none, without disturbing a quoted entry", async () => {
|
|
404
|
+
const { out } = await writes(NOTEBOOK, (d) => {
|
|
405
|
+
text(d, "intro").colspan = 12;
|
|
406
|
+
text(d, "intro").break = true;
|
|
407
|
+
});
|
|
408
|
+
expect(out).toContain(
|
|
409
|
+
'tiles=[intro { kind=text colspan=12 break }, "a_tiles -> cell_1"',
|
|
410
|
+
);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it("combines a prose edit, a width edit and a settings edit", async () => {
|
|
414
|
+
const { document } = await writes(NOTEBOOK, (d) => {
|
|
415
|
+
d.title = "Renamed";
|
|
416
|
+
d.description = "New description";
|
|
417
|
+
text(d, "intro").markdown = "Changed.";
|
|
418
|
+
text(d, "intro").colspan = 3;
|
|
419
|
+
});
|
|
420
|
+
expect(document.title).toBe("Renamed");
|
|
421
|
+
expect(document.description).toBe("New description");
|
|
422
|
+
expect(text(document, "intro")).toMatchObject({
|
|
423
|
+
markdown: "Changed.",
|
|
424
|
+
colspan: 3,
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it("leaves a block's neighbours alone when a query tile is removed beside it", async () => {
|
|
429
|
+
const { out } = await writes(NOTEBOOK, (d) => {
|
|
430
|
+
d.tiles = d.tiles.filter(isTextTile);
|
|
431
|
+
});
|
|
432
|
+
expect(out).toContain("##|(markdown) intro\n# Review");
|
|
433
|
+
expect(out).toContain("##|(markdown) outro\nBye.\n|##\n");
|
|
434
|
+
expect(out).not.toContain("view: cell_1");
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
describe("refusals", () => {
|
|
438
|
+
const one = (edit: (d: DashboardDocument) => void) =>
|
|
439
|
+
refused(NOTEBOOK, edit);
|
|
440
|
+
|
|
441
|
+
it("refuses prose that would close its block", async () => {
|
|
442
|
+
expect(
|
|
443
|
+
await one((d) => {
|
|
444
|
+
text(d, "intro").markdown = "a\n|## b";
|
|
445
|
+
}),
|
|
446
|
+
).toContain("|##");
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it("refuses a carriage return", async () => {
|
|
450
|
+
expect(
|
|
451
|
+
await one((d) => {
|
|
452
|
+
text(d, "intro").markdown = "a\r\nb";
|
|
453
|
+
}),
|
|
454
|
+
).toContain("carriage return");
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it("refuses a name that is not a bare word", async () => {
|
|
458
|
+
for (const name of ["two words", "1st", "a-b", ""]) {
|
|
459
|
+
expect(
|
|
460
|
+
await one((d) => {
|
|
461
|
+
d.tiles.push({ kind: "text", name, markdown: "x" });
|
|
462
|
+
}),
|
|
463
|
+
).toContain("bare word");
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it("refuses a name another text tile or a block already has", async () => {
|
|
468
|
+
expect(
|
|
469
|
+
await one((d) => {
|
|
470
|
+
d.tiles.push({ kind: "text", name: "intro", markdown: "x" });
|
|
471
|
+
}),
|
|
472
|
+
).toContain("intro");
|
|
473
|
+
const orphan = `${NOTEBOOK}\n##|(markdown) spare\nUnlisted.\n|##\n`;
|
|
474
|
+
expect(
|
|
475
|
+
await refused(orphan, (d) => {
|
|
476
|
+
d.tiles.push({ kind: "text", name: "spare", markdown: "x" });
|
|
477
|
+
}),
|
|
478
|
+
).toContain("already in this file");
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
it("refuses a width that is not a whole number of columns", async () => {
|
|
482
|
+
for (const colspan of [0, -1, 1.5]) {
|
|
483
|
+
expect(
|
|
484
|
+
await one((d) => {
|
|
485
|
+
text(d, "intro").colspan = colspan;
|
|
486
|
+
}),
|
|
487
|
+
).toContain("width");
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it("does not judge prose or names that did not change", async () => {
|
|
492
|
+
const odd = NOTEBOOK.replace("Bye.", " |## not a closer");
|
|
493
|
+
await writes(odd, (d) => {
|
|
494
|
+
d.title = "Still editable";
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it("refuses removing the last tile of a list", async () => {
|
|
499
|
+
const reason = await refused(
|
|
500
|
+
`## artifact { title="T" tiles=[only { kind=text }] }\n\n##|(markdown) only\nx\n|##\n`,
|
|
501
|
+
(d) => {
|
|
502
|
+
d.tiles = [];
|
|
503
|
+
},
|
|
504
|
+
);
|
|
505
|
+
expect(reason).toContain("no tiles");
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
it("exposes the same prose rule to an editor", () => {
|
|
510
|
+
expect(markdownProblem("fine")).toBeUndefined();
|
|
511
|
+
expect(markdownProblem("")).toBeUndefined();
|
|
512
|
+
expect(markdownProblem("x\n|##")).toContain("|##");
|
|
513
|
+
expect(markdownProblem("x\r")).toContain("carriage");
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
describe("spliceDashboardDocument: text edits move nothing else", () => {
|
|
518
|
+
const RICH = `// the page
|
|
519
|
+
##! experimental.givens
|
|
520
|
+
## artifact { kind=notebook title="Rich" tiles=[intro { kind=text }, "a_tiles -> cell_1", "a_tiles -> cell_2"] }
|
|
521
|
+
import { a } from "../m.malloy"
|
|
522
|
+
|
|
523
|
+
// about the intro
|
|
524
|
+
##|(markdown) intro
|
|
525
|
+
Hello.
|
|
526
|
+
|##
|
|
527
|
+
|
|
528
|
+
source: a_tiles is a extend {
|
|
529
|
+
// why this leads
|
|
530
|
+
# big_value
|
|
531
|
+
# label="First" /* trailing */
|
|
532
|
+
view: cell_1 is by_cat + { where: category ~ $CATEGORY } // after
|
|
533
|
+
|
|
534
|
+
# bar_chart
|
|
535
|
+
view: cell_2 is by_brand
|
|
536
|
+
}
|
|
537
|
+
// the end
|
|
538
|
+
`;
|
|
539
|
+
|
|
540
|
+
const edits: Array<[string, (d: DashboardDocument) => void]> = [
|
|
541
|
+
[
|
|
542
|
+
"changing prose",
|
|
543
|
+
(d) => {
|
|
544
|
+
text(d, "intro").markdown = "Changed.\n\n- a";
|
|
545
|
+
},
|
|
546
|
+
],
|
|
547
|
+
[
|
|
548
|
+
"adding a text tile",
|
|
549
|
+
(d) => {
|
|
550
|
+
d.tiles.splice(2, 0, { kind: "text", name: "mid", markdown: "M" });
|
|
551
|
+
},
|
|
552
|
+
],
|
|
553
|
+
[
|
|
554
|
+
"resizing a text tile",
|
|
555
|
+
(d) => {
|
|
556
|
+
text(d, "intro").colspan = 8;
|
|
557
|
+
},
|
|
558
|
+
],
|
|
559
|
+
[
|
|
560
|
+
"moving a text tile",
|
|
561
|
+
(d) => {
|
|
562
|
+
d.tiles.push(d.tiles.shift());
|
|
563
|
+
},
|
|
564
|
+
],
|
|
565
|
+
];
|
|
566
|
+
for (const [name, edit] of edits) {
|
|
567
|
+
it(`${name} leaves every declaration, tag and comment where it was`, async () => {
|
|
568
|
+
const { out } = await writes(RICH, edit);
|
|
569
|
+
const moved = await whatMoved(RICH, out);
|
|
570
|
+
expect(moved.declarations).toEqual([]);
|
|
571
|
+
expect(moved.tags).toEqual([]);
|
|
572
|
+
expect(moved.tagText).toEqual([]);
|
|
573
|
+
expect(moved.comments).toEqual([]);
|
|
574
|
+
expect(moved.attached).toEqual([]);
|
|
575
|
+
// Prose is the one thing a text edit may add or drop.
|
|
576
|
+
if (!/prose|adding/.test(name)) expect(moved.residue).toEqual([]);
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
it("removing a text tile takes its block and leaves every comment and declaration", async () => {
|
|
581
|
+
const { out } = await writes(RICH, (d) => {
|
|
582
|
+
d.tiles.shift();
|
|
583
|
+
});
|
|
584
|
+
const moved = await whatMoved(RICH, out);
|
|
585
|
+
expect(moved.declarations).toEqual([]);
|
|
586
|
+
expect(moved.tags).toEqual([]);
|
|
587
|
+
expect(moved.comments).toEqual([]);
|
|
588
|
+
expect(out).toContain("// about the intro");
|
|
589
|
+
expect(out).not.toContain("##|(markdown) intro");
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
describe("spliceDashboardDocument: switching kind", () => {
|
|
594
|
+
it("refuses a kind change unless it is asked for", async () => {
|
|
595
|
+
const reason = await refused(DASHBOARD, (d) => {
|
|
596
|
+
d.kind = "notebook";
|
|
597
|
+
});
|
|
598
|
+
expect(reason).toContain("kind");
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
it("turns a dashboard into a notebook in place: kind added, width cleared", async () => {
|
|
602
|
+
const { out, document } = await writes(
|
|
603
|
+
DASHBOARD,
|
|
604
|
+
(d) => {
|
|
605
|
+
d.kind = "notebook";
|
|
606
|
+
delete d.columns;
|
|
607
|
+
},
|
|
608
|
+
{ changeKind: true },
|
|
609
|
+
);
|
|
610
|
+
expect(out).toContain(
|
|
611
|
+
'## artifact { title="D" tiles=["a_tiles -> x"] kind=notebook }',
|
|
612
|
+
);
|
|
613
|
+
expect(out).not.toContain("dashboard {");
|
|
614
|
+
expect(document.kind).toBe("notebook");
|
|
615
|
+
expect(document.columns).toBeUndefined();
|
|
616
|
+
expect(out.slice(out.indexOf("\n"))).toBe(
|
|
617
|
+
DASHBOARD.slice(DASHBOARD.indexOf("\n")),
|
|
618
|
+
);
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
it("turns a notebook back into a dashboard: kind removed, width written", async () => {
|
|
622
|
+
const { out, document } = await writes(
|
|
623
|
+
NOTEBOOK,
|
|
624
|
+
(d) => {
|
|
625
|
+
d.kind = "dashboard";
|
|
626
|
+
d.columns = 12;
|
|
627
|
+
},
|
|
628
|
+
{ changeKind: true },
|
|
629
|
+
);
|
|
630
|
+
expect(out).not.toContain("kind=notebook");
|
|
631
|
+
expect(out).toContain("kind=text");
|
|
632
|
+
expect(out).toContain("dashboard { columns=12 }");
|
|
633
|
+
expect(document.kind).toBeUndefined();
|
|
634
|
+
expect(document.columns).toBe(12);
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
it("tags a dashboard kind=dashboard under notebooks/, where an untagged file reads as a notebook, and drops the tag again for a notebook", async () => {
|
|
638
|
+
const flip = (source: string, kind: "dashboard" | "notebook") =>
|
|
639
|
+
writes(
|
|
640
|
+
source,
|
|
641
|
+
(d) => {
|
|
642
|
+
d.kind = kind;
|
|
643
|
+
if (kind === "notebook") delete d.columns;
|
|
644
|
+
},
|
|
645
|
+
{ changeKind: true, modelPath: "notebooks/n.malloy" },
|
|
646
|
+
);
|
|
647
|
+
const asDashboard = await flip(NOTEBOOK, "dashboard");
|
|
648
|
+
expect(asDashboard.out).toContain("kind=dashboard");
|
|
649
|
+
expect(asDashboard.out).not.toContain("kind=notebook");
|
|
650
|
+
expect(asDashboard.document.kind).toBeUndefined();
|
|
651
|
+
const back = await flip(asDashboard.out, "notebook");
|
|
652
|
+
expect(back.out).toContain("kind=notebook");
|
|
653
|
+
expect(back.out).not.toContain("kind=dashboard");
|
|
654
|
+
expect(back.document.kind).toBe("notebook");
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
it("leaves a dashboard under dashboards/ untagged", async () => {
|
|
658
|
+
const { out } = await writes(
|
|
659
|
+
NOTEBOOK,
|
|
660
|
+
(d) => {
|
|
661
|
+
d.kind = "dashboard";
|
|
662
|
+
},
|
|
663
|
+
{ changeKind: true, modelPath: "dashboards/n.malloy" },
|
|
664
|
+
);
|
|
665
|
+
expect(out).not.toContain("kind=dashboard");
|
|
666
|
+
expect(out).not.toContain("kind=notebook");
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
it("does not take a text tile's kind=text for the document's", async () => {
|
|
670
|
+
const source = `## artifact { tiles=[a { kind=text }] title="T" }\n\n##|(markdown) a\nx\n|##\n`;
|
|
671
|
+
const { out, document } = await writes(
|
|
672
|
+
source,
|
|
673
|
+
(d) => {
|
|
674
|
+
d.kind = "notebook";
|
|
675
|
+
},
|
|
676
|
+
{ changeKind: true },
|
|
677
|
+
);
|
|
678
|
+
expect(out).toContain("a { kind=text }");
|
|
679
|
+
expect(out).toContain("kind=notebook");
|
|
680
|
+
expect(document.kind).toBe("notebook");
|
|
681
|
+
const back = await writes(
|
|
682
|
+
out,
|
|
683
|
+
(d) => {
|
|
684
|
+
d.kind = "dashboard";
|
|
685
|
+
},
|
|
686
|
+
{ changeKind: true },
|
|
687
|
+
);
|
|
688
|
+
expect(back.out).toContain("a { kind=text }");
|
|
689
|
+
expect(back.out).not.toContain("kind=notebook");
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
it("refuses to switch to a notebook with the width still set, and never writes a notebook's width", async () => {
|
|
693
|
+
const result = await spliceDashboardDocument(
|
|
694
|
+
DASHBOARD,
|
|
695
|
+
{ ...(await openDocument(DASHBOARD)), kind: "notebook" },
|
|
696
|
+
{ changeKind: true },
|
|
697
|
+
);
|
|
698
|
+
if (!spliceFailed(result)) throw new Error("expected a refusal");
|
|
699
|
+
expect(result.reason).toContain("one column");
|
|
700
|
+
const reason = await refused(NOTEBOOK, (d) => {
|
|
701
|
+
d.columns = 6;
|
|
702
|
+
});
|
|
703
|
+
expect(reason).toContain("one column");
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
it("keeps a stray width on a notebook as the file has it", async () => {
|
|
707
|
+
const stray = NOTEBOOK.replace(
|
|
708
|
+
"break }] }",
|
|
709
|
+
"break }] } dashboard { columns=12 }",
|
|
710
|
+
);
|
|
711
|
+
const document = await openDocument(stray);
|
|
712
|
+
expect(document.columns).toBe(12);
|
|
713
|
+
const { out } = await writes(stray, (d) => {
|
|
714
|
+
text(d, "intro").markdown = "Edited.";
|
|
715
|
+
});
|
|
716
|
+
expect(out).toContain("dashboard { columns=12 }");
|
|
717
|
+
});
|
|
718
|
+
});
|