@malloy-publisher/sdk 0.9.2 → 0.9.3
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/{RenderedResult-CBLHr32C.es.js → RenderedResult-DwB0-9Yx.es.js} +118 -119
- package/dist/{RenderedResult-B48wAjM8.cjs.js → RenderedResult-hKjFEqaN.cjs.js} +2 -2
- package/dist/{ServerProvider-DCV8BUWD.es.js → ServerProvider-CcSrGaRN.es.js} +1281 -1142
- package/dist/ServerProvider-Gbf1YPOP.cjs.js +1 -0
- package/dist/builder/index.cjs.js +112 -115
- package/dist/builder/index.es.js +11766 -11502
- package/dist/builder-entry.d.ts +1 -1
- package/dist/client/api.d.ts +170 -9
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +93 -89
- package/dist/client-entry.d.ts +2 -0
- package/dist/components/ApiErrorDisplay.d.ts +11 -0
- package/dist/components/AppDialog.d.ts +6 -6
- package/dist/components/Dashboard/DashboardGrid.d.ts +18 -3
- package/dist/components/Dashboard/DashboardTile.d.ts +12 -2
- package/dist/components/Dashboard/DashboardView.d.ts +38 -3
- package/dist/components/Dashboard/TileCard.d.ts +16 -2
- package/dist/components/Dashboard/dropValueUrlTags.d.ts +6 -0
- package/dist/components/Dashboard/index.d.ts +3 -2
- package/dist/components/Dashboard/telemetry.d.ts +2 -1
- package/dist/components/Dashboard/textSource.d.ts +19 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +7 -8
- package/dist/components/DashboardBuilder/BuilderDialogs.d.ts +25 -0
- package/dist/components/DashboardBuilder/BuilderGrid.d.ts +31 -0
- package/dist/components/DashboardBuilder/BuilderHeader.d.ts +17 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +14 -17
- package/dist/components/DashboardBuilder/ChartPicker.d.ts +3 -1
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +15 -7
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +28 -2
- package/dist/components/DashboardBuilder/EditorSurface.d.ts +33 -0
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +6 -4
- package/dist/components/DashboardBuilder/InlineText.d.ts +1 -1
- package/dist/components/DashboardBuilder/NotebookEditor.d.ts +1 -1
- package/dist/components/DashboardBuilder/TextTileBody.d.ts +4 -1
- package/dist/components/DashboardBuilder/TileFrame.d.ts +43 -6
- package/dist/components/DashboardBuilder/TileMenu.d.ts +6 -8
- package/dist/components/DashboardBuilder/builderReport.d.ts +13 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +0 -18
- package/dist/components/DashboardBuilder/documentSession.d.ts +2 -2
- package/dist/components/DashboardBuilder/imports.d.ts +19 -0
- package/dist/components/DashboardBuilder/inlineEdit.d.ts +18 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +3 -1
- package/dist/components/DashboardBuilder/readForEditor.d.ts +1 -1
- package/dist/components/DashboardBuilder/sortable.d.ts +2 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +2 -0
- package/dist/components/DashboardBuilder/testing/resize.d.ts +7 -0
- package/dist/components/DashboardBuilder/tileDisplayTitle.d.ts +7 -0
- package/dist/components/DashboardBuilder/useBuilderSelection.d.ts +53 -0
- package/dist/components/DashboardBuilder/useBuilderSession.d.ts +4 -7
- package/dist/components/DashboardBuilder/useControlBindings.d.ts +30 -0
- package/dist/components/DashboardBuilder/useConversionConfirm.d.ts +20 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +2 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +3 -1
- package/dist/components/DashboardBuilder/useHostCopy.d.ts +26 -0
- package/dist/components/DashboardBuilder/useOpenDraftCommit.d.ts +17 -0
- package/dist/components/DashboardBuilder/useOpenedDocument.d.ts +71 -0
- package/dist/components/DashboardBuilder/useSaveChannel.d.ts +50 -0
- package/dist/components/DashboardBuilder/useTileEditing.d.ts +33 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +32 -0
- package/dist/components/Loading.d.ts +13 -0
- package/dist/components/Notebook/NotebookCell.d.ts +1 -5
- package/dist/components/Package/Package.d.ts +16 -1
- package/dist/components/Package/index.d.ts +1 -1
- package/dist/components/Prose.d.ts +1 -1
- package/dist/components/RenderedResult/loadRenderer.d.ts +7 -0
- package/dist/components/given/paramCodec.d.ts +8 -1
- package/dist/components/index.d.ts +1 -2
- package/dist/components/styles.d.ts +4 -4
- package/dist/hooks/givenValue.d.ts +6 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useCompiledDocument.d.ts +23 -0
- package/dist/hooks/useDocumentControls.d.ts +6 -1
- package/dist/hooks/useNearViewport.d.ts +16 -0
- package/dist/hooks/useQueryWithApiError.d.ts +7 -2
- package/dist/hooks/useSuggestOptions.d.ts +9 -2
- package/dist/index.cjs.js +14 -14
- package/dist/index.es.js +9760 -10363
- package/dist/text/index.es.js +1 -1
- package/dist/{text-entry-CbbBcZl8.es.js → text-entry-CA0LZ1xL.es.js} +8 -8
- package/dist/text-entry.d.ts +1 -1
- package/dist/theme/accent.d.ts +29 -0
- package/dist/theme/buildVegaThemeOverride.d.ts +3 -3
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/keys.d.ts +1 -1
- package/dist/theme/motion.d.ts +31 -0
- package/dist/theme/readChartAnnotations.d.ts +1 -1
- package/dist/theme/resolveTheme.d.ts +4 -4
- package/dist/theme/types.d.ts +33 -5
- package/dist/{DashboardTile-BFcxdv7R.es.js → useCompiledDocument-BU6d8FPp.es.js} +6978 -6289
- package/dist/useCompiledDocument-pOg2W-Yt.cjs.js +142 -0
- package/package.json +11 -11
- package/src/builder-entry.ts +1 -0
- package/src/client-entry.ts +8 -0
- package/src/clientEntry.spec.ts +17 -0
- package/src/components/ApiErrorDisplay.tsx +37 -18
- package/src/components/AppDialog.tsx +8 -7
- package/src/components/Dashboard/Dashboard.spec.tsx +3 -32
- package/src/components/Dashboard/Dashboard.tsx +2 -2
- package/src/components/Dashboard/DashboardGrid.tsx +23 -5
- package/src/components/Dashboard/DashboardTile.spec.tsx +97 -2
- package/src/components/Dashboard/DashboardTile.tsx +95 -31
- package/src/components/Dashboard/DashboardView.spec.tsx +156 -0
- package/src/components/Dashboard/DashboardView.tsx +165 -89
- package/src/components/Dashboard/RowsDialog.tsx +3 -2
- package/src/components/Dashboard/TileCard.tsx +17 -2
- package/src/components/Dashboard/dropValueUrlTags.spec.ts +177 -0
- package/src/components/Dashboard/dropValueUrlTags.ts +108 -0
- package/src/components/Dashboard/index.ts +11 -2
- package/src/components/Dashboard/telemetry.ts +2 -1
- package/src/components/Dashboard/textSource.spec.ts +36 -0
- package/src/components/Dashboard/textSource.ts +39 -0
- package/src/components/DashboardBuilder/AddTileDialog.tsx +16 -56
- package/src/components/DashboardBuilder/BuilderDialogs.tsx +162 -0
- package/src/components/DashboardBuilder/BuilderGrid.tsx +245 -0
- package/src/components/DashboardBuilder/BuilderHeader.tsx +107 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +86 -113
- package/src/components/DashboardBuilder/ChartPicker.tsx +4 -1
- package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +5 -5
- package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +74 -83
- package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +62 -18
- package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +55 -108
- package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +10 -62
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +50 -57
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +53 -40
- package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +10 -8
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +227 -704
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +32 -52
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +1 -50
- package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +12 -18
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +4 -24
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +4 -4
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +8 -13
- package/src/components/DashboardBuilder/DashboardEditor.textSource.spec.tsx +317 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +142 -820
- package/src/components/DashboardBuilder/DrillDialog.tsx +2 -2
- package/src/components/DashboardBuilder/EditorSurface.tsx +471 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +13 -8
- package/src/components/DashboardBuilder/FilterStrip.tsx +117 -79
- package/src/components/DashboardBuilder/InlineMarkdown.tsx +7 -9
- package/src/components/DashboardBuilder/InlineText.tsx +23 -17
- package/src/components/DashboardBuilder/NotebookEditor.tsx +3 -3
- package/src/components/DashboardBuilder/TextTileBody.tsx +5 -2
- package/src/components/DashboardBuilder/TileFrame.tsx +255 -90
- package/src/components/DashboardBuilder/TileMenu.tsx +41 -91
- package/src/components/DashboardBuilder/artifactBlock.spec.ts +1 -1
- package/src/components/DashboardBuilder/artifactTagParity.spec.ts +9 -4
- package/src/components/DashboardBuilder/builderReport.ts +74 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +0 -44
- package/src/components/DashboardBuilder/catalog.ts +0 -36
- package/src/components/DashboardBuilder/controls.spec.ts +1 -1
- package/src/components/DashboardBuilder/controls.ts +1 -1
- package/src/components/DashboardBuilder/documentSession.ts +3 -2
- package/src/components/DashboardBuilder/imports.spec.ts +61 -0
- package/src/components/DashboardBuilder/imports.ts +93 -0
- package/src/components/DashboardBuilder/inlineEdit.tsx +78 -0
- package/src/components/DashboardBuilder/legacyNotebook.ts +1 -1
- package/src/components/DashboardBuilder/malloyTree.ts +5 -1
- package/src/components/DashboardBuilder/newDashboard.ts +1 -1
- package/src/components/DashboardBuilder/preview.ts +1 -1
- package/src/components/DashboardBuilder/readDocument.spec.ts +36 -0
- package/src/components/DashboardBuilder/readDocument.ts +10 -4
- package/src/components/DashboardBuilder/readForEditor.ts +7 -2
- package/src/components/DashboardBuilder/sortable.spec.ts +25 -1
- package/src/components/DashboardBuilder/sortable.tsx +11 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +8 -3
- package/src/components/DashboardBuilder/testing/artifactTagParity.json +62 -6
- package/src/components/DashboardBuilder/testing/documentKindRule.json +40 -0
- package/src/components/DashboardBuilder/testing/inline.ts +1 -1
- package/src/components/DashboardBuilder/testing/resize.ts +48 -0
- package/src/components/DashboardBuilder/testing/urlRenderTags.json +62 -0
- package/src/components/DashboardBuilder/textTiles.spec.ts +43 -1
- package/src/components/DashboardBuilder/tileDisplayTitle.ts +13 -0
- package/src/components/DashboardBuilder/useBuilderSelection.ts +121 -0
- package/src/components/DashboardBuilder/useBuilderSession.spec.ts +0 -85
- package/src/components/DashboardBuilder/useBuilderSession.ts +6 -43
- package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +32 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +11 -1
- package/src/components/DashboardBuilder/useControlBindings.ts +152 -0
- package/src/components/DashboardBuilder/useConversionConfirm.ts +55 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +5 -2
- package/src/components/DashboardBuilder/useDraft.ts +15 -2
- package/src/components/DashboardBuilder/useHostCopy.ts +104 -0
- package/src/components/DashboardBuilder/useOpenDraftCommit.ts +47 -0
- package/src/components/DashboardBuilder/useOpenedDocument.ts +314 -0
- package/src/components/DashboardBuilder/useSaveChannel.ts +275 -0
- package/src/components/DashboardBuilder/useTileEditing.ts +141 -0
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +146 -0
- package/src/components/DashboardBuilder/useTileResize.ts +133 -0
- package/src/components/DataAppViewer/DataAppViewer.tsx +7 -4
- package/src/components/DocumentCreate/guards.ts +1 -1
- package/src/components/Environment/Environment.tsx +0 -10
- package/src/components/Loading.tsx +14 -0
- package/src/components/Model/Model.tsx +16 -9
- package/src/components/Model/ModelExplorer.tsx +2 -2
- package/src/components/Notebook/Notebook.tsx +6 -2
- package/src/components/Notebook/NotebookCell.tsx +90 -215
- package/src/components/Package/Package.artifacts.spec.tsx +8 -12
- package/src/components/Package/Package.create.spec.tsx +22 -1
- package/src/components/Package/Package.tsx +51 -27
- package/src/components/Package/index.ts +1 -1
- package/src/components/Prose.spec.tsx +37 -0
- package/src/components/Prose.tsx +35 -5
- package/src/components/RenderedResult/RenderedResult.tsx +5 -7
- package/src/components/RenderedResult/ResultContainer.tsx +7 -2
- package/src/components/RenderedResult/ResultPanel.tsx +20 -5
- package/src/components/RenderedResult/loadRenderer.ts +42 -0
- package/src/components/given/GivenInput.spec.tsx +5 -5
- package/src/components/given/GivenInput.tsx +46 -38
- package/src/components/given/GivensPanel.tsx +2 -8
- package/src/components/given/paramCodec.ts +27 -1
- package/src/components/index.ts +1 -2
- package/src/components/styles.ts +4 -5
- package/src/hooks/givenValue.ts +9 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useCompiledDocument.spec.tsx +86 -0
- package/src/hooks/useCompiledDocument.ts +59 -0
- package/src/hooks/useDimensionalFilterRangeData.ts +3 -1
- package/src/hooks/useDocumentControls.ts +13 -1
- package/src/hooks/useNearViewport.spec.tsx +150 -0
- package/src/hooks/useNearViewport.ts +102 -0
- package/src/hooks/useQueryResult.ts +7 -1
- package/src/hooks/useQueryWithApiError.ts +10 -3
- package/src/hooks/useRawQueryData.ts +3 -1
- package/src/hooks/useSuggestOptions.dom.spec.ts +40 -1
- package/src/hooks/useSuggestOptions.ts +42 -10
- package/src/text-entry.ts +1 -1
- package/src/textEntry.spec.ts +2 -8
- package/src/theme/accent.spec.ts +116 -0
- package/src/theme/accent.ts +148 -0
- package/src/theme/buildTableCssVars.spec.ts +24 -0
- package/src/theme/buildTableCssVars.ts +1 -2
- package/src/theme/buildVegaThemeOverride.spec.ts +38 -2
- package/src/theme/buildVegaThemeOverride.ts +5 -5
- package/src/theme/defaults.ts +34 -0
- package/src/theme/index.ts +9 -0
- package/src/theme/keys.ts +6 -0
- package/src/theme/motion.ts +44 -0
- package/src/theme/readChartAnnotations.spec.ts +18 -0
- package/src/theme/readChartAnnotations.ts +1 -1
- package/src/theme/resolveTheme.spec.ts +73 -0
- package/src/theme/resolveTheme.ts +61 -20
- package/src/theme/types.ts +30 -5
- package/src/utils/queryClient.ts +8 -0
- package/dist/DashboardTile-sg8LjUk8.cjs.js +0 -137
- package/dist/ServerProvider-HRqT3w1C.cjs.js +0 -1
- package/dist/components/Dashboard/DashboardBar.d.ts +0 -21
- package/dist/components/Dashboard/ExploreDialog.d.ts +0 -20
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +0 -7
- package/dist/components/DashboardBuilder/SaveNotice.d.ts +0 -27
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +0 -32
- package/dist/components/DashboardBuilder/diff.d.ts +0 -35
- package/src/components/Dashboard/DashboardBar.tsx +0 -88
- package/src/components/Dashboard/ExploreDialog.tsx +0 -89
- package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +0 -194
- package/src/components/DashboardBuilder/DiffDialog.spec.tsx +0 -25
- package/src/components/DashboardBuilder/DiffDialog.tsx +0 -103
- package/src/components/DashboardBuilder/SaveNotice.tsx +0 -113
- package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +0 -87
- package/src/components/DashboardBuilder/SettingsPopover.tsx +0 -326
- package/src/components/DashboardBuilder/diff.spec.ts +0 -44
- package/src/components/DashboardBuilder/diff.ts +0 -93
- /package/dist/{components/DashboardBuilder → utils}/malloyText.d.ts +0 -0
- /package/src/{components/DashboardBuilder → utils}/malloyText.spec.ts +0 -0
- /package/src/{components/DashboardBuilder → utils}/malloyText.ts +0 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { parseAnnotation } from "@malloydata/malloy-tag";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { dropValueUrlTags } from "./dropValueUrlTags";
|
|
9
|
+
|
|
10
|
+
const resultWith = (...values: string[]) =>
|
|
11
|
+
JSON.stringify({
|
|
12
|
+
schema: {
|
|
13
|
+
fields: [
|
|
14
|
+
{
|
|
15
|
+
kind: "dimension",
|
|
16
|
+
name: "pic",
|
|
17
|
+
annotations: values.map((value) => ({ value })),
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
data: { kind: "array_cell", array_value: [] },
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const annotationsOf = (result: string) =>
|
|
25
|
+
(
|
|
26
|
+
JSON.parse(result) as {
|
|
27
|
+
schema: { fields: { annotations: { value: string }[] }[] };
|
|
28
|
+
}
|
|
29
|
+
).schema.fields[0].annotations.map((a) => a.value);
|
|
30
|
+
|
|
31
|
+
describe("dropValueUrlTags", () => {
|
|
32
|
+
it("removes an image tag and keeps the other properties on the line, as the renderer reads them", () => {
|
|
33
|
+
const out = annotationsOf(
|
|
34
|
+
dropValueUrlTags(resultWith('# image { height=40px } label="Pic"\n')),
|
|
35
|
+
);
|
|
36
|
+
expect(out).toHaveLength(1);
|
|
37
|
+
const tag = parseAnnotation(out[0]).tag;
|
|
38
|
+
expect(tag.has("image")).toBe(false);
|
|
39
|
+
expect(tag.text("label")).toBe("Pic");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("leaves a well-formed empty line when an image tag was the only property", () => {
|
|
43
|
+
const out = annotationsOf(dropValueUrlTags(resultWith("# image\n")));
|
|
44
|
+
expect(out).toHaveLength(1);
|
|
45
|
+
expect(out[0]).not.toContain("# #");
|
|
46
|
+
expect(parseAnnotation(out[0]).log).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("drops a line that reads the environment, whatever else it carries", () => {
|
|
50
|
+
for (const line of [
|
|
51
|
+
"# image=@env.HOME\n",
|
|
52
|
+
"# image { alt=@env.HOME }\n",
|
|
53
|
+
"# link { url_template=@env.X }\n",
|
|
54
|
+
'# label="<img src=x>" x=@env.X\n',
|
|
55
|
+
"#|\nimage=@env.X\n|#\n",
|
|
56
|
+
]) {
|
|
57
|
+
expect(annotationsOf(dropValueUrlTags(resultWith(line)))).toEqual([
|
|
58
|
+
"",
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("drops a line the tag parser rejects, since the renderer may read it differently", () => {
|
|
64
|
+
expect(
|
|
65
|
+
annotationsOf(dropValueUrlTags(resultWith("# image {\n"))),
|
|
66
|
+
).toEqual([""]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("removes a link tag and its url_template", () => {
|
|
70
|
+
const out = annotationsOf(
|
|
71
|
+
dropValueUrlTags(
|
|
72
|
+
resultWith(
|
|
73
|
+
'# link { url_template="https://attacker.example/$$" }\n',
|
|
74
|
+
),
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
expect(out.join("")).not.toContain("attacker");
|
|
78
|
+
expect(out.join("")).not.toContain("link");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("removes a backtick-quoted tag and one nested in another tag", () => {
|
|
82
|
+
expect(
|
|
83
|
+
annotationsOf(dropValueUrlTags(resultWith("# `image`\n"))).join(""),
|
|
84
|
+
).not.toContain("image");
|
|
85
|
+
expect(
|
|
86
|
+
annotationsOf(
|
|
87
|
+
dropValueUrlTags(resultWith("# column { image }\n")),
|
|
88
|
+
).join(""),
|
|
89
|
+
).not.toContain("image");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("removes a label that carries markup, and keeps a plain one", () => {
|
|
93
|
+
const markup = annotationsOf(
|
|
94
|
+
dropValueUrlTags(
|
|
95
|
+
resultWith('# label="<img src=x onerror=alert(1)>"\n'),
|
|
96
|
+
),
|
|
97
|
+
);
|
|
98
|
+
expect(markup.join("")).not.toContain("<img");
|
|
99
|
+
const plain = annotationsOf(
|
|
100
|
+
dropValueUrlTags(resultWith('# label="a < b"\n')),
|
|
101
|
+
);
|
|
102
|
+
expect(plain[0]).toContain("a < b");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("removes each markup shape in a label and keeps a bare angle bracket", () => {
|
|
106
|
+
for (const label of [
|
|
107
|
+
"<b>x</b>",
|
|
108
|
+
"</b>",
|
|
109
|
+
"<!-- x -->",
|
|
110
|
+
"<b onclick=x a> y",
|
|
111
|
+
]) {
|
|
112
|
+
const out = annotationsOf(
|
|
113
|
+
dropValueUrlTags(resultWith(`# label="${label}"\n`)),
|
|
114
|
+
);
|
|
115
|
+
expect(out.join("")).not.toContain("label");
|
|
116
|
+
}
|
|
117
|
+
for (const label of ["a<b", "Actual<Target", "a < b"]) {
|
|
118
|
+
const source = resultWith(`# label="${label}"\n`);
|
|
119
|
+
expect(dropValueUrlTags(source)).toBe(source);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("leaves chart tags, doc notes and a field named link as a value alone", () => {
|
|
124
|
+
const source = resultWith(
|
|
125
|
+
"# bar_chart { x = link }\n",
|
|
126
|
+
"#(docs) image of the data\n# pivot { dimensions=[link] }\n",
|
|
127
|
+
);
|
|
128
|
+
expect(dropValueUrlTags(source)).toBe(source);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("cleans an annotation nested in a record field, and in the result's own", () => {
|
|
132
|
+
const result = JSON.stringify({
|
|
133
|
+
annotations: [{ value: "# link\n" }],
|
|
134
|
+
schema: {
|
|
135
|
+
fields: [
|
|
136
|
+
{
|
|
137
|
+
name: "r",
|
|
138
|
+
type: {
|
|
139
|
+
kind: "record_type",
|
|
140
|
+
fields: [
|
|
141
|
+
{ name: "p", annotations: [{ value: "# image\n" }] },
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
const out = dropValueUrlTags(result);
|
|
149
|
+
expect(out).not.toContain("image");
|
|
150
|
+
expect(out).not.toMatch(/"# link/);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("returns text that is not JSON untouched", () => {
|
|
154
|
+
expect(dropValueUrlTags("not json")).toBe("not json");
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// One case table for this list and the server's `renderTagRefusal`, whose spec reads the same file.
|
|
159
|
+
const { cases } = JSON.parse(
|
|
160
|
+
fs.readFileSync(
|
|
161
|
+
path.join(
|
|
162
|
+
import.meta.dir,
|
|
163
|
+
"../DashboardBuilder/testing/urlRenderTags.json",
|
|
164
|
+
),
|
|
165
|
+
"utf8",
|
|
166
|
+
),
|
|
167
|
+
) as { cases: { name: string; annotation: string; offends: boolean }[] };
|
|
168
|
+
|
|
169
|
+
describe("dropValueUrlTags agrees with the server's render-tag refusal", () => {
|
|
170
|
+
for (const { name, annotation, offends } of cases) {
|
|
171
|
+
it(`${offends ? "strips" : "keeps"} ${name}`, () => {
|
|
172
|
+
const line = `${annotation}\n`;
|
|
173
|
+
const [out] = annotationsOf(dropValueUrlTags(resultWith(line)));
|
|
174
|
+
expect(out !== line).toBe(offends);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { parseAnnotation, type Tag } from "@malloydata/malloy-tag";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A document held as text is written by whoever the viewer opened it from, so
|
|
8
|
+
* its results are drawn without the tags that turn a cell value into a URL or
|
|
9
|
+
* markup: `# image` (an `<img src=value>`), `# link` (an `<a href>`), and a
|
|
10
|
+
* `# label` with HTML in it. The renderer has no option for this, so the
|
|
11
|
+
* annotations are rewritten in the result before it is drawn.
|
|
12
|
+
*
|
|
13
|
+
* This also drops them from a model's own fields, which is the price of not
|
|
14
|
+
* having to know where a field came from: a field the caller could redefine
|
|
15
|
+
* (`except:` then a new `dimension:` under the same name) keeps the model's
|
|
16
|
+
* tag. A host that wants model images in documents held as text has to ask for
|
|
17
|
+
* them; the default is the safe one.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const HTML_START = /<\/?[A-Za-z][^>]*>|<!--|<![A-Za-z]/;
|
|
21
|
+
|
|
22
|
+
/** Remove the offending properties from `tag`, in place, at any depth; whether any was removed. */
|
|
23
|
+
function strip(tag: Tag): boolean {
|
|
24
|
+
let changed = false;
|
|
25
|
+
for (const [name, child] of Array.from(tag.entries())) {
|
|
26
|
+
if (child.deleted) continue;
|
|
27
|
+
if (name === "image" || name === "link") {
|
|
28
|
+
tag.delete(name);
|
|
29
|
+
changed = true;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (name === "label") {
|
|
33
|
+
let label: string | undefined;
|
|
34
|
+
try {
|
|
35
|
+
label = tag.text("label");
|
|
36
|
+
} catch {
|
|
37
|
+
label = undefined;
|
|
38
|
+
}
|
|
39
|
+
if (label !== undefined && HTML_START.test(label)) {
|
|
40
|
+
tag.delete("label");
|
|
41
|
+
changed = true;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const elements = Array.isArray(child.eq) ? child.eq : [];
|
|
46
|
+
for (const nested of [child, ...elements]) {
|
|
47
|
+
if (strip(nested)) changed = true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return changed;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** One annotation line with the offending tags removed, or the line as it was. */
|
|
54
|
+
function cleanAnnotation(value: string): string {
|
|
55
|
+
const text = value.trim();
|
|
56
|
+
// A route other than the plain MOTLY one (`#(docs)`, `#"`, `#!`) and a `##` note are never drawn as tags.
|
|
57
|
+
if (!/^#(?:\||[ \t\r\n]|$)/.test(text)) return value;
|
|
58
|
+
// The renderer hydrates `@env.` and may read a line this parser rejects, so neither can be inspected: the line goes.
|
|
59
|
+
if (text.includes("@env.")) return "";
|
|
60
|
+
let parsed: ReturnType<typeof parseAnnotation>;
|
|
61
|
+
try {
|
|
62
|
+
parsed = parseAnnotation(text);
|
|
63
|
+
} catch {
|
|
64
|
+
return "";
|
|
65
|
+
}
|
|
66
|
+
if (parsed.log.length > 0) return "";
|
|
67
|
+
// `toString()` already carries the `# ` prefix.
|
|
68
|
+
return strip(parsed.tag) ? `${parsed.tag.toString()}\n` : value;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function clean(node: unknown): void {
|
|
72
|
+
if (Array.isArray(node)) {
|
|
73
|
+
for (const item of node) clean(item);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (node === null || typeof node !== "object") return;
|
|
77
|
+
const record = node as Record<string, unknown>;
|
|
78
|
+
for (const [key, value] of Object.entries(record)) {
|
|
79
|
+
if (key === "annotations" && Array.isArray(value)) {
|
|
80
|
+
for (const annotation of value) {
|
|
81
|
+
const holder = annotation as { value?: unknown };
|
|
82
|
+
if (typeof holder?.value === "string") {
|
|
83
|
+
holder.value = cleanAnnotation(holder.value);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
clean(value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The result with every `# image`, `# link` and HTML-bearing `# label` removed
|
|
94
|
+
* from its annotations; the input string untouched when there is none or it is
|
|
95
|
+
* not JSON, for the renderer to report.
|
|
96
|
+
*/
|
|
97
|
+
export function dropValueUrlTags(result: string): string {
|
|
98
|
+
let parsed: unknown;
|
|
99
|
+
try {
|
|
100
|
+
parsed = JSON.parse(result);
|
|
101
|
+
} catch {
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
const before = JSON.stringify(parsed);
|
|
105
|
+
clean(parsed);
|
|
106
|
+
const after = JSON.stringify(parsed);
|
|
107
|
+
return after === before ? result : after;
|
|
108
|
+
}
|
|
@@ -2,9 +2,18 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
export { Dashboard, type DashboardProps } from "./Dashboard";
|
|
5
|
-
export {
|
|
5
|
+
export {
|
|
6
|
+
DashboardView,
|
|
7
|
+
STICKY_CONTROLS_Z,
|
|
8
|
+
type DashboardViewProps,
|
|
9
|
+
} from "./DashboardView";
|
|
6
10
|
export { TileFilterTag, tileIgnoredFilterLabels } from "./TileFilterTag";
|
|
7
11
|
export { DashboardTile, type DashboardTileProps } from "./DashboardTile";
|
|
12
|
+
export {
|
|
13
|
+
documentPreamble,
|
|
14
|
+
RESTRICTED_NOTICE,
|
|
15
|
+
withPreamble,
|
|
16
|
+
} from "./textSource";
|
|
8
17
|
export type { DashboardEvent, DashboardEventHandler } from "./telemetry";
|
|
9
|
-
export { TileCard, TileHeading } from "./TileCard";
|
|
18
|
+
export { TILE_MIN_HEIGHT, TileCard, TileHeading } from "./TileCard";
|
|
10
19
|
export type { TileHeadingSlots } from "./TileCard";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/** Where a host's Save lands, as an editor's events report it. */
|
|
5
|
+
export type SavesTo = "package" | "browser" | "host";
|
|
5
6
|
import type { DashboardCreatedEvent } from "../DocumentCreate/events";
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { expect, it } from "bun:test";
|
|
5
|
+
import { documentPreamble, isForbidden, withPreamble } from "./textSource";
|
|
6
|
+
|
|
7
|
+
it("builds the preamble from definition cells only, in order, leaving out restricted ones", () => {
|
|
8
|
+
expect(
|
|
9
|
+
documentPreamble([
|
|
10
|
+
{ type: "code", kind: "definition", text: "source: a is orders" },
|
|
11
|
+
{ type: "markdown", kind: "markdown", text: "prose" },
|
|
12
|
+
{ type: "code", kind: "query", text: "run: a -> { select: * }" },
|
|
13
|
+
{
|
|
14
|
+
type: "code",
|
|
15
|
+
kind: "definition",
|
|
16
|
+
text: "source: b is secret",
|
|
17
|
+
restricted: true,
|
|
18
|
+
},
|
|
19
|
+
{ type: "code", kind: "definition", text: "source: c is a" },
|
|
20
|
+
]),
|
|
21
|
+
).toBe("source: a is orders\n\nsource: c is a");
|
|
22
|
+
expect(documentPreamble(undefined)).toBe("");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("puts the preamble ahead of the run, and adds nothing when there is none", () => {
|
|
26
|
+
expect(withPreamble("source: a is orders", "run: a -> v")).toBe(
|
|
27
|
+
"source: a is orders\n\nrun: a -> v",
|
|
28
|
+
);
|
|
29
|
+
expect(withPreamble("", "run: a -> v")).toBe("run: a -> v");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("reads a 403 off the API error and nothing else", () => {
|
|
33
|
+
expect(isForbidden({ status: 403 })).toBe(true);
|
|
34
|
+
expect(isForbidden({ status: 404 })).toBe(false);
|
|
35
|
+
expect(isForbidden(undefined)).toBe(false);
|
|
36
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { NotebookCell } from "../../client";
|
|
5
|
+
import type { ApiError } from "../ApiErrorDisplay";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Text-source mode: the document is a string the host keeps, and every query
|
|
9
|
+
* it runs is that document's own definitions followed by one `run:`, sent as
|
|
10
|
+
* the caller's text against a model the caller can already read. Nothing is run
|
|
11
|
+
* as the document's author, so each viewer sees what their own identity allows.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** What a tile says in place of a result the viewer may not read. */
|
|
15
|
+
export const RESTRICTED_NOTICE = "You don't have access to this data";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The text a tile's `run:` is appended to: the document's definition cells in
|
|
19
|
+
* file order. Never an `import`, a `##!` flag or a `given:`; the model supplies
|
|
20
|
+
* those, and caller text may not carry them.
|
|
21
|
+
*/
|
|
22
|
+
export function documentPreamble(
|
|
23
|
+
cells: readonly NotebookCell[] | undefined,
|
|
24
|
+
): string {
|
|
25
|
+
return (cells ?? [])
|
|
26
|
+
.filter((cell) => cell.kind === "definition" && !cell.restricted)
|
|
27
|
+
.map((cell) => cell.text ?? "")
|
|
28
|
+
.join("\n\n");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** `preamble` then `text`, as one query. */
|
|
32
|
+
export function withPreamble(preamble: string, text: string): string {
|
|
33
|
+
return preamble === "" ? text : `${preamble}\n\n${text}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The server refused this viewer the source, as opposed to the query failing. */
|
|
37
|
+
export function isForbidden(error: unknown): boolean {
|
|
38
|
+
return (error as ApiError | undefined)?.status === 403;
|
|
39
|
+
}
|
|
@@ -11,33 +11,32 @@ import {
|
|
|
11
11
|
} from "@mui/material";
|
|
12
12
|
import { useEffect, useMemo, useState } from "react";
|
|
13
13
|
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
14
|
-
import type {
|
|
14
|
+
import type { PackageCatalog } from "./catalog";
|
|
15
15
|
import type { ChartPick } from "./chartLine";
|
|
16
|
-
import { isBareName } from "
|
|
16
|
+
import { isBareName } from "../../utils/malloyText";
|
|
17
17
|
import type { DashboardDocument } from "./document";
|
|
18
18
|
import { ChartPicker } from "./ChartPicker";
|
|
19
19
|
import { AppDialog } from "../AppDialog";
|
|
20
20
|
import { SourceViewPicker } from "./SourceViewPicker";
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* What a new tile is: a view, picked from the package
|
|
24
|
-
* can reach.
|
|
23
|
+
* What a new tile is: a view, picked from the package.
|
|
25
24
|
*
|
|
26
25
|
* The picker is what makes a tile expression correct BY CONSTRUCTION. Every
|
|
27
26
|
* `source -> view` it offers came from the catalog, so the builder never emits
|
|
28
27
|
* a tile that does not resolve — which is why saving needs no compile step
|
|
29
28
|
* beyond the reader's own round-trip.
|
|
30
29
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* or imports it BY NAME. A bare `import "../m.malloy"` may well bring it in,
|
|
36
|
-
* but the file cannot say so, and a guess here fails the whole package load.
|
|
30
|
+
* Every source the package publishes is offered. A tile's view is declared in
|
|
31
|
+
* an extension of its model source, so a source the file cannot see yet is
|
|
32
|
+
* imported by name when the tile is added (`withSource`); one the file already
|
|
33
|
+
* reaches, by name or through a whole-file import of its model, is left alone.
|
|
37
34
|
*/
|
|
38
35
|
export interface NewTile {
|
|
39
36
|
/** The model source the view lives on. */
|
|
40
37
|
base: string;
|
|
38
|
+
/** The model that declares it, for the import a source the file cannot see yet needs. */
|
|
39
|
+
modelPath: string;
|
|
41
40
|
/** The view, as the catalog names it. */
|
|
42
41
|
view: string;
|
|
43
42
|
label?: string;
|
|
@@ -59,20 +58,6 @@ export interface AddTileDialogProps {
|
|
|
59
58
|
onAddText: () => void;
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
/** The catalog sources this file can put a tile on; see the note above. */
|
|
63
|
-
function reachableSources(
|
|
64
|
-
document: DashboardDocument,
|
|
65
|
-
catalog: PackageCatalog | undefined,
|
|
66
|
-
): CatalogSource[] {
|
|
67
|
-
if (!catalog) return [];
|
|
68
|
-
const reachable = new Set<string>();
|
|
69
|
-
for (const source of document.sources) reachable.add(source.base);
|
|
70
|
-
for (const imported of document.imports)
|
|
71
|
-
if (imported.kind === "names")
|
|
72
|
-
for (const name of imported.names) reachable.add(name);
|
|
73
|
-
return catalog.sources.filter((source) => reachable.has(source.name));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
61
|
export function AddTileDialog({
|
|
77
62
|
open,
|
|
78
63
|
document,
|
|
@@ -83,11 +68,7 @@ export function AddTileDialog({
|
|
|
83
68
|
onAddText,
|
|
84
69
|
}: AddTileDialogProps) {
|
|
85
70
|
const { theme } = usePublisherTheme();
|
|
86
|
-
const
|
|
87
|
-
const sources = useMemo(
|
|
88
|
-
() => reachableSources(document, catalog),
|
|
89
|
-
[document, catalog],
|
|
90
|
-
);
|
|
71
|
+
const sources = useMemo(() => catalog?.sources ?? [], [catalog]);
|
|
91
72
|
const [mode, setMode] = useState<"query" | "text">("query");
|
|
92
73
|
const [base, setBase] = useState<string>("");
|
|
93
74
|
const [view, setView] = useState<string>("");
|
|
@@ -131,7 +112,7 @@ export function AddTileDialog({
|
|
|
131
112
|
open={open}
|
|
132
113
|
onClose={onClose}
|
|
133
114
|
title="Add a tile"
|
|
134
|
-
description=
|
|
115
|
+
description="A tile shows one view of a source in this package."
|
|
135
116
|
actions={
|
|
136
117
|
<>
|
|
137
118
|
<Button onClick={onClose}>Cancel</Button>
|
|
@@ -145,6 +126,9 @@ export function AddTileDialog({
|
|
|
145
126
|
? onAddText()
|
|
146
127
|
: onAdd({
|
|
147
128
|
base,
|
|
129
|
+
modelPath:
|
|
130
|
+
sources.find((s) => s.name === base)
|
|
131
|
+
?.modelPath ?? "",
|
|
148
132
|
view,
|
|
149
133
|
...(label.trim() ? { label: label.trim() } : {}),
|
|
150
134
|
...(chart !== "default"
|
|
@@ -193,7 +177,7 @@ export function AddTileDialog({
|
|
|
193
177
|
) : sources.length === 0 ? (
|
|
194
178
|
<Typography variant="body2" sx={{ color: theme.tileTitle }}>
|
|
195
179
|
{catalog
|
|
196
|
-
?
|
|
180
|
+
? "This package publishes no source with a view to put on a tile."
|
|
197
181
|
: "The package's sources are still loading."}
|
|
198
182
|
</Typography>
|
|
199
183
|
) : (
|
|
@@ -220,6 +204,7 @@ export function AddTileDialog({
|
|
|
220
204
|
state={chart}
|
|
221
205
|
view={picked}
|
|
222
206
|
cellLabel="new tile"
|
|
207
|
+
variant="outlined"
|
|
223
208
|
{...(picked
|
|
224
209
|
? {}
|
|
225
210
|
: {
|
|
@@ -239,31 +224,6 @@ export function AddTileDialog({
|
|
|
239
224
|
inputProps={{ "aria-label": "Tile title" }}
|
|
240
225
|
sx={{ flex: 1 }}
|
|
241
226
|
/>
|
|
242
|
-
{columns > 1 && (
|
|
243
|
-
<TextField
|
|
244
|
-
size="small"
|
|
245
|
-
type="number"
|
|
246
|
-
label={`Width (of ${columns})`}
|
|
247
|
-
value={colspan}
|
|
248
|
-
onChange={(event) =>
|
|
249
|
-
setColspan(
|
|
250
|
-
Math.min(
|
|
251
|
-
Math.max(
|
|
252
|
-
Number(event.target.value) || 1,
|
|
253
|
-
1,
|
|
254
|
-
),
|
|
255
|
-
columns,
|
|
256
|
-
),
|
|
257
|
-
)
|
|
258
|
-
}
|
|
259
|
-
inputProps={{
|
|
260
|
-
min: 1,
|
|
261
|
-
max: columns,
|
|
262
|
-
"aria-label": "Tile width",
|
|
263
|
-
}}
|
|
264
|
-
sx={{ width: 140 }}
|
|
265
|
-
/>
|
|
266
|
-
)}
|
|
267
227
|
</Stack>
|
|
268
228
|
</>
|
|
269
229
|
)}
|