@malloy-publisher/sdk 0.9.0 → 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 +82 -48
- 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,60 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
5
|
+
import { afterEach, describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { isMac, useBuilderShortcuts } from "./useBuilderShortcuts";
|
|
8
|
+
|
|
9
|
+
const mod = isMac ? { metaKey: true } : { ctrlKey: true };
|
|
10
|
+
|
|
11
|
+
// Save reads the rendered state, as a builder's save reads its render closure.
|
|
12
|
+
function Harness({
|
|
13
|
+
onSave,
|
|
14
|
+
withSave = true,
|
|
15
|
+
}: {
|
|
16
|
+
onSave: (seen: string) => void;
|
|
17
|
+
withSave?: boolean;
|
|
18
|
+
}) {
|
|
19
|
+
const [value, setValue] = useState("");
|
|
20
|
+
const [committed, setCommitted] = useState("");
|
|
21
|
+
useBuilderShortcuts({
|
|
22
|
+
undo: () => {},
|
|
23
|
+
redo: () => {},
|
|
24
|
+
...(withSave ? { save: () => onSave(committed) } : {}),
|
|
25
|
+
escape: () => {},
|
|
26
|
+
});
|
|
27
|
+
return (
|
|
28
|
+
<input
|
|
29
|
+
aria-label="Field"
|
|
30
|
+
value={value}
|
|
31
|
+
onChange={(event) => setValue(event.target.value)}
|
|
32
|
+
onBlur={() => setCommitted(value)}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
afterEach(cleanup);
|
|
38
|
+
|
|
39
|
+
describe("useBuilderShortcuts: save inside a text field", () => {
|
|
40
|
+
it("leaves the field, then saves with what the blur committed", () => {
|
|
41
|
+
const onSave = mock((_seen: string) => {});
|
|
42
|
+
render(<Harness onSave={onSave} />);
|
|
43
|
+
const field = screen.getByLabelText("Field");
|
|
44
|
+
field.focus();
|
|
45
|
+
fireEvent.change(field, { target: { value: "typed" } });
|
|
46
|
+
fireEvent.keyDown(field, { key: "s", ...mod });
|
|
47
|
+
expect(onSave).toHaveBeenCalledTimes(1);
|
|
48
|
+
expect(onSave.mock.calls[0][0]).toBe("typed");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("leaves the field alone when there is nothing to save to", () => {
|
|
52
|
+
const onSave = mock((_seen: string) => {});
|
|
53
|
+
render(<Harness onSave={onSave} withSave={false} />);
|
|
54
|
+
const field = screen.getByLabelText("Field");
|
|
55
|
+
field.focus();
|
|
56
|
+
fireEvent.keyDown(field, { key: "s", ...mod });
|
|
57
|
+
expect(onSave).not.toHaveBeenCalled();
|
|
58
|
+
expect(document.activeElement).toBe(field);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import { useEffect, useRef } from "react";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The keyboard an editor is expected to have.
|
|
8
8
|
*
|
|
9
9
|
* Undo and redo on the platform's usual keys, save on ⌘S / Ctrl+S (which the
|
|
10
10
|
* browser would otherwise take), Escape to drop the selection, and the arrow
|
|
11
|
-
* keys to nudge the selected tile's width a column at a time
|
|
12
|
-
* edit that is otherwise drag-only.
|
|
11
|
+
* keys to nudge the selected tile's width a column at a time.
|
|
13
12
|
*
|
|
14
|
-
* Nothing but Escape fires while a text field has focus, so typing
|
|
15
|
-
* title never undoes a layout.
|
|
13
|
+
* Nothing but Escape and save fires while a text field has focus, so typing
|
|
14
|
+
* into a title never undoes a layout. Save leaves the field first, so its
|
|
15
|
+
* blur commits the draft, and runs once that edit has rendered.
|
|
16
16
|
*/
|
|
17
17
|
export interface BuilderShortcutHandlers {
|
|
18
18
|
undo: () => void;
|
|
19
19
|
redo: () => void;
|
|
20
20
|
save?: () => void;
|
|
21
21
|
escape: () => void;
|
|
22
|
-
/** Nudge the selected tile's width by ±1 column. */
|
|
23
|
-
nudge
|
|
22
|
+
/** Nudge the selected tile's width by ±1 column. Absent, the arrow keys are left alone. */
|
|
23
|
+
nudge?: (delta: 1 | -1) => void;
|
|
24
|
+
/** A modal owns the keyboard: no shortcut fires, so none can open a second dialog over it. */
|
|
25
|
+
paused?: boolean;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
const isMac =
|
|
28
|
+
export const isMac =
|
|
27
29
|
typeof navigator !== "undefined" &&
|
|
28
30
|
/Mac|iPhone|iPad/.test(navigator.platform);
|
|
29
31
|
|
|
@@ -37,6 +39,11 @@ const inTextEntry = (target: EventTarget | null) => {
|
|
|
37
39
|
return tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT";
|
|
38
40
|
};
|
|
39
41
|
|
|
42
|
+
const inOverlay = (target: EventTarget | null) =>
|
|
43
|
+
target instanceof Element &&
|
|
44
|
+
target.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root') !==
|
|
45
|
+
null;
|
|
46
|
+
|
|
40
47
|
export function useBuilderShortcuts(handlers: BuilderShortcutHandlers) {
|
|
41
48
|
// The handlers are read at keypress time, not bound at subscription time:
|
|
42
49
|
// the caller passes a fresh object every render, and a listener re-bound on
|
|
@@ -46,16 +53,34 @@ export function useBuilderShortcuts(handlers: BuilderShortcutHandlers) {
|
|
|
46
53
|
latest.current = handlers;
|
|
47
54
|
});
|
|
48
55
|
|
|
56
|
+
const [saveRequested, setSaveRequested] = useState(false);
|
|
57
|
+
// After the render, because save reads the document of the render it was made in.
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!saveRequested) return;
|
|
60
|
+
setSaveRequested(false);
|
|
61
|
+
latest.current.save?.();
|
|
62
|
+
}, [saveRequested]);
|
|
63
|
+
|
|
49
64
|
useEffect(() => {
|
|
50
65
|
const onKey = (event: KeyboardEvent) => {
|
|
51
66
|
const current = latest.current;
|
|
67
|
+
if (current.paused) return;
|
|
52
68
|
const mod = isMac ? event.metaKey : event.ctrlKey;
|
|
53
69
|
const key = event.key.toLowerCase();
|
|
54
70
|
if (event.key === "Escape") {
|
|
55
71
|
current.escape();
|
|
56
72
|
return;
|
|
57
73
|
}
|
|
58
|
-
if (inTextEntry(event.target))
|
|
74
|
+
if (inTextEntry(event.target)) {
|
|
75
|
+
if (mod && key === "s") {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
// A dialog's draft commits on close, so a save here would report Saved without it.
|
|
78
|
+
if (!current.save || inOverlay(event.target)) return;
|
|
79
|
+
(event.target as HTMLElement).blur();
|
|
80
|
+
setSaveRequested(true);
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
59
84
|
if (mod && key === "z") {
|
|
60
85
|
event.preventDefault();
|
|
61
86
|
if (event.shiftKey) current.redo();
|
|
@@ -69,10 +94,11 @@ export function useBuilderShortcuts(handlers: BuilderShortcutHandlers) {
|
|
|
69
94
|
}
|
|
70
95
|
if (mod && key === "s") {
|
|
71
96
|
event.preventDefault();
|
|
72
|
-
current.save?.();
|
|
97
|
+
if (!inOverlay(event.target)) current.save?.();
|
|
73
98
|
return;
|
|
74
99
|
}
|
|
75
100
|
if (
|
|
101
|
+
current.nudge &&
|
|
76
102
|
!mod &&
|
|
77
103
|
!event.altKey &&
|
|
78
104
|
!event.shiftKey &&
|
|
@@ -5,6 +5,8 @@ import { act, renderHook, waitFor } from "@testing-library/react";
|
|
|
5
5
|
import { describe, expect, it } from "bun:test";
|
|
6
6
|
import { openDocument } from "./testing/fixtures";
|
|
7
7
|
import { useDashboardEditor } from "./useDashboardEditor";
|
|
8
|
+
import { queryTile } from "./testing/fixtures";
|
|
9
|
+
import { tileKey } from "./document";
|
|
8
10
|
|
|
9
11
|
const SOURCE = `## artifact { title="Probe" tiles=["a -> by_cat", "a -> by_brand"] } dashboard { columns=12 }
|
|
10
12
|
import "../data_app.malloy"
|
|
@@ -36,14 +38,16 @@ describe("useDashboardEditor: editing", () => {
|
|
|
36
38
|
|
|
37
39
|
act(() => {
|
|
38
40
|
view.result.current.update((d) => {
|
|
39
|
-
d
|
|
41
|
+
queryTile(d, 0).label = "Categories";
|
|
40
42
|
});
|
|
41
43
|
});
|
|
42
44
|
|
|
43
|
-
expect(view.result.current.document
|
|
45
|
+
expect(queryTile(view.result.current.document, 0).label).toBe(
|
|
46
|
+
"Categories",
|
|
47
|
+
);
|
|
44
48
|
// The history entry it replaced is untouched, which is what makes undo a
|
|
45
49
|
// move rather than a reconstruction.
|
|
46
|
-
expect(before
|
|
50
|
+
expect(queryTile(before, 0).label).toBe("By category");
|
|
47
51
|
});
|
|
48
52
|
|
|
49
53
|
it("is dirty only once something actually changed", async () => {
|
|
@@ -64,7 +68,7 @@ describe("useDashboardEditor: editing", () => {
|
|
|
64
68
|
const view = await editor();
|
|
65
69
|
act(() => {
|
|
66
70
|
view.result.current.update((d) => {
|
|
67
|
-
d
|
|
71
|
+
queryTile(d, 0).label = "By category";
|
|
68
72
|
});
|
|
69
73
|
});
|
|
70
74
|
expect(view.result.current.canUndo).toBe(false);
|
|
@@ -145,7 +149,7 @@ describe("useDashboardEditor: saving", () => {
|
|
|
145
149
|
|
|
146
150
|
act(() => {
|
|
147
151
|
view.result.current.update((d) => {
|
|
148
|
-
d
|
|
152
|
+
queryTile(d, 0).label = "Categories";
|
|
149
153
|
});
|
|
150
154
|
});
|
|
151
155
|
await act(async () => {
|
|
@@ -169,7 +173,7 @@ describe("useDashboardEditor: saving", () => {
|
|
|
169
173
|
|
|
170
174
|
act(() => {
|
|
171
175
|
view.result.current.update((d) => {
|
|
172
|
-
d
|
|
176
|
+
queryTile(d, 0).label = "One";
|
|
173
177
|
});
|
|
174
178
|
});
|
|
175
179
|
await act(async () => {
|
|
@@ -177,7 +181,7 @@ describe("useDashboardEditor: saving", () => {
|
|
|
177
181
|
});
|
|
178
182
|
act(() => {
|
|
179
183
|
view.result.current.update((d) => {
|
|
180
|
-
d
|
|
184
|
+
queryTile(d, 1).label = "Two";
|
|
181
185
|
});
|
|
182
186
|
});
|
|
183
187
|
await act(async () => {
|
|
@@ -209,7 +213,7 @@ describe("useDashboardEditor: saving", () => {
|
|
|
209
213
|
});
|
|
210
214
|
|
|
211
215
|
expect(called).toBe(false);
|
|
212
|
-
expect(view.result.current.error).toContain("
|
|
216
|
+
expect(view.result.current.error).toContain("whole-file");
|
|
213
217
|
// Still there, still dirty. The reader can undo or try something else.
|
|
214
218
|
expect(view.result.current.document.imports).toHaveLength(2);
|
|
215
219
|
expect(view.result.current.dirty).toBe(true);
|
|
@@ -255,8 +259,7 @@ describe("useDashboardEditor: saving", () => {
|
|
|
255
259
|
});
|
|
256
260
|
|
|
257
261
|
/**
|
|
258
|
-
* `structural`
|
|
259
|
-
* saves, so it has to mean what the WRITER means by a changed tile — not what
|
|
262
|
+
* `structural` is what a save reports as structural, so it has to mean what the WRITER means by a changed tile — not what
|
|
260
263
|
* the grid means.
|
|
261
264
|
*/
|
|
262
265
|
describe("useDashboardEditor: structural", () => {
|
|
@@ -264,7 +267,7 @@ describe("useDashboardEditor: structural", () => {
|
|
|
264
267
|
const view = await editor();
|
|
265
268
|
act(() => {
|
|
266
269
|
view.result.current.update((d) => {
|
|
267
|
-
d
|
|
270
|
+
queryTile(d, 0).label = "Categories";
|
|
268
271
|
d.tiles[0].colspan = 4;
|
|
269
272
|
});
|
|
270
273
|
});
|
|
@@ -301,11 +304,11 @@ describe("useDashboardEditor: structural", () => {
|
|
|
301
304
|
const before = view.result.current.document.tiles[0];
|
|
302
305
|
act(() => {
|
|
303
306
|
view.result.current.update((d) => {
|
|
304
|
-
d
|
|
307
|
+
queryTile(d, 0).declaration = { kind: "inline" };
|
|
305
308
|
});
|
|
306
309
|
});
|
|
307
310
|
const after = view.result.current.document.tiles[0];
|
|
308
|
-
expect(
|
|
311
|
+
expect(tileKey(after)).toBe(tileKey(before));
|
|
309
312
|
expect(view.result.current.structural).toBe(true);
|
|
310
313
|
});
|
|
311
314
|
});
|
|
@@ -1,78 +1,35 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import { useCallback
|
|
4
|
+
import { useCallback } from "react";
|
|
5
5
|
import { type DashboardDocument } from "./document";
|
|
6
|
+
import { spliceDashboardDocument, tileFileKey } from "./spliceDocument";
|
|
6
7
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
type DocumentEditor,
|
|
9
|
+
type SaveHandler,
|
|
10
|
+
type SaveOutcome,
|
|
11
|
+
useDocumentEditor,
|
|
12
|
+
} from "./useDocumentEditor";
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
* Deliberately holds the DOCUMENT and nothing else. Given VALUES — what the
|
|
16
|
-
* preview is running with — are editor state rather than document state and
|
|
17
|
-
* live outside this hook, which is what keeps them out of the undo stack. Undo
|
|
18
|
-
* should take back a layout change; it should not rewind the filter someone was
|
|
19
|
-
* previewing under.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
export interface DashboardEditor {
|
|
23
|
-
document: DashboardDocument;
|
|
24
|
-
/** The file as it currently stands, which is what a save patches. */
|
|
25
|
-
source: string;
|
|
26
|
-
canUndo: boolean;
|
|
27
|
-
canRedo: boolean;
|
|
28
|
-
/** Whether the document has changes the file does not have yet. */
|
|
29
|
-
dirty: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Why the last save did not happen. The document is untouched when this is
|
|
32
|
-
* set: a refused write keeps the reader's work and reports a defect in the
|
|
33
|
-
* writer, rather than discarding an edit because a tool could not read back
|
|
34
|
-
* what it produced.
|
|
35
|
-
*/
|
|
36
|
-
error?: string;
|
|
37
|
-
/** Apply a change. Receives a copy; mutate it freely. */
|
|
38
|
-
update: (change: (draft: DashboardDocument) => void) => void;
|
|
39
|
-
undo: () => void;
|
|
40
|
-
redo: () => void;
|
|
41
|
-
/** Splice the change into the file, or say why it was refused. */
|
|
42
|
-
save: () => Promise<SaveOutcome>;
|
|
43
|
-
/**
|
|
44
|
-
* The file a save would write, without writing it: what a diff preview
|
|
45
|
-
* shows. The failure arm is the writer's refusal, worded for the author.
|
|
46
|
-
*/
|
|
47
|
-
preview: () => Promise<
|
|
48
|
-
{ ok: true; source: string } | { ok: false; reason: string }
|
|
49
|
-
>;
|
|
50
|
-
/**
|
|
51
|
-
* Whether the unsaved change adds or removes a tile. Those moves touch
|
|
52
|
-
* declarations and the comments beside them, which is when a save is worth
|
|
53
|
-
* showing as a diff first; a property edit never is.
|
|
54
|
-
*/
|
|
55
|
-
structural: boolean;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export type SaveOutcome = { ok: true } | { ok: false; reason: string };
|
|
59
|
-
|
|
60
|
-
interface History {
|
|
61
|
-
/** Every document state, oldest first. */
|
|
62
|
-
stack: DashboardDocument[];
|
|
63
|
-
/** Which one is current. Undo and redo move this rather than mutating. */
|
|
64
|
-
index: number;
|
|
65
|
-
}
|
|
14
|
+
export type DashboardEditor = DocumentEditor<DashboardDocument>;
|
|
15
|
+
export type { SaveOutcome };
|
|
66
16
|
|
|
67
17
|
/**
|
|
68
|
-
*
|
|
18
|
+
* Whether the unsaved change adds or removes a tile.
|
|
69
19
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
20
|
+
* The FILE's identity for a tile, not the grid's: `document.tileKey` is
|
|
21
|
+
* `source.name`, so a tile redeclared from another view keeps its key and a
|
|
22
|
+
* save that rewrites its declaration would not be reported as structural — the
|
|
23
|
+
* one case where the author most wants the diff.
|
|
74
24
|
*/
|
|
75
|
-
const
|
|
25
|
+
const tilesChanged = (saved: DashboardDocument, next: DashboardDocument) => {
|
|
26
|
+
const before = new Set(saved.tiles.map(tileFileKey));
|
|
27
|
+
const after = new Set(next.tiles.map(tileFileKey));
|
|
28
|
+
return (
|
|
29
|
+
[...before].some((k) => !after.has(k)) ||
|
|
30
|
+
[...after].some((k) => !before.has(k))
|
|
31
|
+
);
|
|
32
|
+
};
|
|
76
33
|
|
|
77
34
|
export function useDashboardEditor(options: {
|
|
78
35
|
/** The file as read from storage. */
|
|
@@ -80,122 +37,38 @@ export function useDashboardEditor(options: {
|
|
|
80
37
|
/** The document that file produced. */
|
|
81
38
|
document: DashboardDocument;
|
|
82
39
|
/** Persist the patched file. Rejecting leaves the editor dirty. */
|
|
83
|
-
onSave?:
|
|
40
|
+
onSave?: SaveHandler<DashboardDocument>;
|
|
41
|
+
/**
|
|
42
|
+
* A cell-format notebook the document is the conversion of: while `source`
|
|
43
|
+
* is `from` the edits are spliced into `to`, the layout text it converts to,
|
|
44
|
+
* and the open is unsaved ({@link DocumentEditorOptions.opensDirty}).
|
|
45
|
+
*/
|
|
46
|
+
conversion?: { from: string; to: string };
|
|
47
|
+
/** The file a save overwrites when `source` is a draft of it ({@link DocumentEditorOptions.replaces}). */
|
|
48
|
+
replaces?: string;
|
|
49
|
+
/** The file's path within the package. */
|
|
50
|
+
modelPath?: string;
|
|
84
51
|
}): DashboardEditor {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const document = history.stack[history.index];
|
|
101
|
-
|
|
102
|
-
const update = useCallback((change: (draft: DashboardDocument) => void) => {
|
|
103
|
-
setError(undefined);
|
|
104
|
-
setHistory((previous) => {
|
|
105
|
-
const draft = structuredClone(previous.stack[previous.index]);
|
|
106
|
-
change(draft);
|
|
107
|
-
// A change that changes nothing does not deserve a history entry;
|
|
108
|
-
// otherwise a click that sets a value to what it already was makes
|
|
109
|
-
// undo appear broken.
|
|
110
|
-
if (
|
|
111
|
-
JSON.stringify(draft) ===
|
|
112
|
-
JSON.stringify(previous.stack[previous.index])
|
|
113
|
-
)
|
|
114
|
-
return previous;
|
|
115
|
-
// Editing after undo discards the redo tail, which is what every
|
|
116
|
-
// editor does and what a reader expects.
|
|
117
|
-
const kept = previous.stack.slice(0, previous.index + 1);
|
|
118
|
-
const stack = [...kept, draft].slice(-HISTORY_LIMIT);
|
|
119
|
-
return { stack, index: stack.length - 1 };
|
|
120
|
-
});
|
|
121
|
-
}, []);
|
|
122
|
-
|
|
123
|
-
const undo = useCallback(() => {
|
|
124
|
-
setError(undefined);
|
|
125
|
-
setHistory((previous) =>
|
|
126
|
-
previous.index > 0
|
|
127
|
-
? { ...previous, index: previous.index - 1 }
|
|
128
|
-
: previous,
|
|
129
|
-
);
|
|
130
|
-
}, []);
|
|
131
|
-
|
|
132
|
-
const redo = useCallback(() => {
|
|
133
|
-
setError(undefined);
|
|
134
|
-
setHistory((previous) =>
|
|
135
|
-
previous.index < previous.stack.length - 1
|
|
136
|
-
? { ...previous, index: previous.index + 1 }
|
|
137
|
-
: previous,
|
|
138
|
-
);
|
|
139
|
-
}, []);
|
|
140
|
-
|
|
141
|
-
const save = useCallback(async (): Promise<SaveOutcome> => {
|
|
142
|
-
const result = await spliceDashboardDocument(source, document);
|
|
143
|
-
if (spliceFailed(result)) {
|
|
144
|
-
setError(result.reason);
|
|
145
|
-
return { ok: false, reason: result.reason };
|
|
146
|
-
}
|
|
147
|
-
try {
|
|
148
|
-
await options.onSave?.(result.source);
|
|
149
|
-
} catch (failure) {
|
|
150
|
-
// The file may or may not have been written; what is certain is that
|
|
151
|
-
// the editor must not pretend it was. Staying dirty is the safe read.
|
|
152
|
-
const reason = `Could not save: ${failure}`;
|
|
153
|
-
setError(reason);
|
|
154
|
-
return { ok: false, reason };
|
|
155
|
-
}
|
|
156
|
-
// The patched file is the new baseline, so a second save patches what is
|
|
157
|
-
// now on disk rather than re-deriving from the text this session opened.
|
|
158
|
-
setSource(result.source);
|
|
159
|
-
setSaved(document);
|
|
160
|
-
setError(undefined);
|
|
161
|
-
return { ok: true };
|
|
162
|
-
}, [document, options, source]);
|
|
163
|
-
|
|
164
|
-
const dirty = useMemo(
|
|
165
|
-
() => JSON.stringify(document) !== JSON.stringify(saved),
|
|
166
|
-
[document, saved],
|
|
52
|
+
const { conversion, modelPath, ...rest } = options;
|
|
53
|
+
const from = conversion?.from;
|
|
54
|
+
const to = conversion?.to;
|
|
55
|
+
const splice = useCallback(
|
|
56
|
+
(text: string, document: DashboardDocument) =>
|
|
57
|
+
// The kind is only ever changed by the settings toggle, so the writer is always allowed to follow it.
|
|
58
|
+
spliceDashboardDocument(
|
|
59
|
+
from !== undefined && text === from ? (to as string) : text,
|
|
60
|
+
document,
|
|
61
|
+
{
|
|
62
|
+
changeKind: true,
|
|
63
|
+
...(modelPath !== undefined ? { modelPath } : {}),
|
|
64
|
+
},
|
|
65
|
+
),
|
|
66
|
+
[from, to, modelPath],
|
|
167
67
|
);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const after = new Set(document.tiles.map(tileFileKey));
|
|
175
|
-
return (
|
|
176
|
-
[...before].some((k) => !after.has(k)) ||
|
|
177
|
-
[...after].some((k) => !before.has(k))
|
|
178
|
-
);
|
|
179
|
-
}, [document, saved]);
|
|
180
|
-
const preview = useCallback(async () => {
|
|
181
|
-
const result = await spliceDashboardDocument(source, document);
|
|
182
|
-
return spliceFailed(result)
|
|
183
|
-
? { ok: false as const, reason: result.reason }
|
|
184
|
-
: { ok: true as const, source: result.source };
|
|
185
|
-
}, [document, source]);
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
document,
|
|
189
|
-
source,
|
|
190
|
-
canUndo: history.index > 0,
|
|
191
|
-
canRedo: history.index < history.stack.length - 1,
|
|
192
|
-
dirty,
|
|
193
|
-
...(error === undefined ? {} : { error }),
|
|
194
|
-
update,
|
|
195
|
-
undo,
|
|
196
|
-
redo,
|
|
197
|
-
save,
|
|
198
|
-
preview,
|
|
199
|
-
structural,
|
|
200
|
-
};
|
|
68
|
+
return useDocumentEditor({
|
|
69
|
+
...rest,
|
|
70
|
+
splice,
|
|
71
|
+
structural: tilesChanged,
|
|
72
|
+
opensDirty: conversion !== undefined,
|
|
73
|
+
});
|
|
201
74
|
}
|