@malloy-publisher/sdk 0.9.1 → 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-BRgIgxWh.es.js → RenderedResult-DwB0-9Yx.es.js} +219 -210
- package/dist/RenderedResult-hKjFEqaN.cjs.js +141 -0
- package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-CcSrGaRN.es.js} +1473 -1326
- package/dist/ServerProvider-Gbf1YPOP.cjs.js +1 -0
- package/dist/builder/index.cjs.js +143 -58
- package/dist/builder/index.es.js +12179 -9318
- package/dist/builder-entry.d.ts +5 -1
- package/dist/client/api.d.ts +247 -56
- 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 +94 -88
- 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/Dashboard.d.ts +8 -15
- package/dist/components/Dashboard/DashboardGrid.d.ts +38 -6
- package/dist/components/Dashboard/DashboardTile.d.ts +21 -2
- package/dist/components/Dashboard/DashboardView.d.ts +71 -0
- package/dist/components/Dashboard/TileCard.d.ts +30 -5
- package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
- package/dist/components/Dashboard/dropValueUrlTags.d.ts +6 -0
- package/dist/components/Dashboard/index.d.ts +5 -1
- package/dist/components/Dashboard/telemetry.d.ts +16 -3
- package/dist/components/Dashboard/textSource.d.ts +19 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +15 -9
- 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 +23 -15
- package/dist/components/DashboardBuilder/ChartPicker.d.ts +31 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +56 -21
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +44 -5
- package/dist/components/DashboardBuilder/EditorSurface.d.ts +33 -0
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +8 -4
- 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/SourceViewPicker.d.ts +9 -0
- package/dist/components/DashboardBuilder/TextTileBody.d.ts +10 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +51 -12
- package/dist/components/DashboardBuilder/TileMenu.d.ts +12 -6
- package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
- package/dist/components/DashboardBuilder/builderReport.d.ts +13 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +4 -18
- 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/imports.d.ts +19 -0
- package/dist/components/DashboardBuilder/inlineEdit.d.ts +18 -0
- package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
- package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
- 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 +6 -1
- package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +16 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +15 -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/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 +86 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
- 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 +19 -55
- package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +3 -1
- package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
- 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 +6 -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/Loading.d.ts +13 -0
- package/dist/components/NarrowEditGate.d.ts +8 -0
- package/dist/components/Notebook/Notebook.d.ts +1 -1
- package/dist/components/Notebook/NotebookCell.d.ts +1 -5
- package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
- package/dist/components/Package/Package.d.ts +17 -1
- package/dist/components/Package/documentLocation.d.ts +28 -0
- package/dist/components/Package/index.d.ts +5 -1
- package/dist/components/Package/useDocumentLocation.d.ts +12 -0
- package/dist/components/PackageSection.d.ts +2 -2
- package/dist/components/Prose.d.ts +1 -1
- 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/loadRenderer.d.ts +7 -0
- 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/given/paramCodec.d.ts +8 -1
- package/dist/components/index.d.ts +3 -2
- package/dist/components/styles.d.ts +4 -4
- package/dist/hooks/givenValue.d.ts +6 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useCompiledDocument.d.ts +23 -0
- package/dist/hooks/useDocumentControls.d.ts +6 -1
- package/dist/hooks/useNarrowScreen.d.ts +4 -0
- package/dist/hooks/useNearViewport.d.ts +16 -0
- package/dist/hooks/useQueryResult.d.ts +2 -0
- package/dist/hooks/useQueryWithApiError.d.ts +7 -2
- package/dist/hooks/useSettled.d.ts +14 -0
- package/dist/hooks/useSuggestOptions.d.ts +9 -2
- package/dist/index.cjs.js +23 -24
- package/dist/index.es.js +9041 -7002
- 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-CA0LZ1xL.es.js +196 -0
- package/dist/text-entry.d.ts +2 -0
- 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/{Dashboard-H1kJlDFo.es.js → useCompiledDocument-BU6d8FPp.es.js} +17904 -19057
- package/dist/useCompiledDocument-pOg2W-Yt.cjs.js +142 -0
- package/dist/utils/clock.d.ts +2 -0
- package/dist/utils/malloyText.d.ts +104 -0
- package/package.json +20 -11
- package/src/builder-entry.ts +36 -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 +29 -280
- package/src/components/Dashboard/DashboardGrid.tsx +87 -8
- package/src/components/Dashboard/DashboardTile.spec.tsx +121 -2
- package/src/components/Dashboard/DashboardTile.tsx +121 -30
- package/src/components/Dashboard/DashboardView.spec.tsx +368 -0
- package/src/components/Dashboard/DashboardView.tsx +428 -0
- package/src/components/Dashboard/RowsDialog.tsx +4 -3
- package/src/components/Dashboard/TileCard.tsx +60 -11
- 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/dropValueUrlTags.spec.ts +177 -0
- package/src/components/Dashboard/dropValueUrlTags.ts +108 -0
- package/src/components/Dashboard/index.ts +13 -1
- package/src/components/Dashboard/telemetry.ts +17 -5
- package/src/components/Dashboard/textSource.spec.ts +36 -0
- package/src/components/Dashboard/textSource.ts +39 -0
- package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
- package/src/components/DashboardBuilder/AddTileDialog.tsx +124 -138
- 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 +111 -80
- 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 +156 -0
- package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
- package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +183 -0
- package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +373 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +310 -0
- package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +105 -0
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +117 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +146 -108
- package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +179 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +330 -512
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +55 -25
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +142 -0
- package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
- package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +310 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +39 -13
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +9 -26
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +102 -25
- package/src/components/DashboardBuilder/DashboardEditor.textSource.spec.tsx +317 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +252 -780
- package/src/components/DashboardBuilder/DrillDialog.tsx +2 -2
- package/src/components/DashboardBuilder/EditorSurface.tsx +471 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +23 -11
- package/src/components/DashboardBuilder/FilterStrip.tsx +130 -70
- package/src/components/DashboardBuilder/InlineMarkdown.tsx +182 -0
- package/src/components/DashboardBuilder/InlineText.tsx +112 -0
- package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
- package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
- package/src/components/DashboardBuilder/TextTileBody.tsx +31 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +302 -163
- package/src/components/DashboardBuilder/TileMenu.tsx +125 -97
- 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 +46 -0
- package/src/components/DashboardBuilder/builderReport.ts +74 -0
- package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +2 -44
- package/src/components/DashboardBuilder/catalog.ts +61 -57
- 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 +258 -0
- package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
- 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/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/malloyTree.ts +159 -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 +174 -26
- package/src/components/DashboardBuilder/readDocument.ts +137 -45
- package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
- package/src/components/DashboardBuilder/readForEditor.ts +52 -0
- package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
- package/src/components/DashboardBuilder/sortable.spec.ts +89 -0
- package/src/components/DashboardBuilder/sortable.tsx +11 -10
- 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 +768 -131
- 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 +253 -0
- package/src/components/DashboardBuilder/testing/documentKindRule.json +40 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
- package/src/components/DashboardBuilder/testing/inline.ts +25 -0
- 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 +760 -0
- package/src/components/DashboardBuilder/tileDisplayTitle.ts +13 -0
- package/src/components/DashboardBuilder/useBuilderSelection.ts +121 -0
- package/src/components/DashboardBuilder/useBuilderSession.spec.ts +250 -0
- package/src/components/DashboardBuilder/useBuilderSession.ts +255 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +97 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +45 -9
- package/src/components/DashboardBuilder/useControlBindings.ts +152 -0
- package/src/components/DashboardBuilder/useConversionConfirm.ts +55 -0
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
- package/src/components/DashboardBuilder/useDashboardEditor.ts +57 -181
- package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
- package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
- package/src/components/DashboardBuilder/useDraft.ts +15 -2
- 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/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/useTileReorder.spec.tsx +28 -5
- package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +30 -5
- package/src/components/DashboardBuilder/useTileResize.ts +31 -8
- package/src/components/DataAppViewer/DataAppViewer.tsx +7 -4
- 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/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.spec.tsx +2 -2
- package/src/components/Model/ModelExplorer.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 +72 -29
- package/src/components/Notebook/NotebookCell.tsx +90 -215
- 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 +186 -0
- package/src/components/Package/Package.create.spec.tsx +401 -0
- package/src/components/Package/Package.notebooks.spec.tsx +18 -0
- package/src/components/Package/Package.tsx +396 -177
- package/src/components/Package/documentLocation.spec.ts +81 -0
- package/src/components/Package/documentLocation.ts +55 -0
- package/src/components/Package/index.ts +14 -1
- package/src/components/Package/useDocumentLocation.ts +59 -0
- package/src/components/PackageSection.tsx +2 -2
- package/src/components/Prose.spec.tsx +37 -0
- package/src/components/Prose.tsx +35 -5
- package/src/components/RenderedResult/RenderedResult.tsx +23 -8
- package/src/components/RenderedResult/ResultContainer.tsx +51 -13
- package/src/components/RenderedResult/ResultPanel.tsx +24 -5
- package/src/components/RenderedResult/loadRenderer.ts +42 -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/GivenInput.spec.tsx +5 -5
- package/src/components/given/GivenInput.tsx +46 -38
- package/src/components/given/GivensPanel.spec.tsx +6 -6
- package/src/components/given/GivensPanel.tsx +5 -11
- package/src/components/given/paramCodec.ts +27 -1
- package/src/components/index.ts +3 -2
- package/src/components/styles.ts +4 -5
- package/src/hooks/givenValue.ts +9 -0
- package/src/hooks/index.ts +7 -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/useNarrowScreen.ts +21 -0
- package/src/hooks/useNearViewport.spec.tsx +150 -0
- package/src/hooks/useNearViewport.ts +102 -0
- package/src/hooks/useQueryResult.ts +23 -1
- package/src/hooks/useQueryWithApiError.ts +10 -3
- package/src/hooks/useRawQueryData.ts +3 -1
- package/src/hooks/useSettled.spec.ts +41 -0
- package/src/hooks/useSettled.ts +27 -0
- package/src/hooks/useSuggestOptions.dom.spec.ts +40 -1
- package/src/hooks/useSuggestOptions.ts +42 -10
- package/src/mainEntry.spec.ts +145 -0
- package/src/text-entry.ts +12 -0
- package/src/textEntry.spec.ts +112 -0
- 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/clock.spec.ts +12 -0
- package/src/utils/clock.ts +6 -0
- package/src/{components/DashboardBuilder → utils}/malloyText.spec.ts +48 -0
- package/src/utils/malloyText.ts +368 -0
- package/src/utils/queryClient.ts +8 -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/Dashboard/DashboardBar.d.ts +0 -21
- package/dist/components/Dashboard/ExploreDialog.d.ts +0 -20
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +0 -15
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +0 -20
- package/dist/components/DashboardBuilder/diff.d.ts +0 -35
- package/dist/components/DashboardBuilder/malloyText.d.ts +0 -64
- package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
- package/src/components/Dashboard/DashboardBar.tsx +0 -88
- package/src/components/Dashboard/ExploreDialog.tsx +0 -89
- package/src/components/DashboardBuilder/DiffDialog.tsx +0 -122
- package/src/components/DashboardBuilder/SettingsPopover.tsx +0 -168
- package/src/components/DashboardBuilder/diff.spec.ts +0 -44
- package/src/components/DashboardBuilder/diff.ts +0 -93
- package/src/components/DashboardBuilder/malloyText.ts +0 -214
- package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
- package/src/components/Package/NewDashboardDialog.tsx +0 -265
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { tileTitle } from "../Dashboard/DashboardTile";
|
|
5
|
+
import type { QueryTile } from "./document";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The title a query tile is drawn under when it has no label of its own: the
|
|
9
|
+
* one the reader's view derives from the view's name. One definition, so a
|
|
10
|
+
* live tile, a placeholder and the menu agree.
|
|
11
|
+
*/
|
|
12
|
+
export const tileDisplayTitle = (tile: QueryTile): string =>
|
|
13
|
+
tile.label ?? tileTitle(`${tile.source} -> ${tile.name}`);
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
useCallback,
|
|
6
|
+
useEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
type RefObject,
|
|
11
|
+
} from "react";
|
|
12
|
+
import { scrollBehavior } from "../../theme/motion";
|
|
13
|
+
import { changedTileKey } from "./changedTile";
|
|
14
|
+
import type { DashboardDocument } from "./document";
|
|
15
|
+
import type { DashboardEditor } from "./useDashboardEditor";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* What is selected on the page: one tile, by index, or the description.
|
|
19
|
+
*
|
|
20
|
+
* ONE value, because only one thing is ever selected: selecting a tile
|
|
21
|
+
* deselects the description, and selecting the description deselects the
|
|
22
|
+
* tile. Held as two flags, the pair could disagree for a render.
|
|
23
|
+
*/
|
|
24
|
+
type Selection = { tile: number } | "description" | undefined;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The builder's selection, and the flash that points at what undo and redo
|
|
28
|
+
* changed.
|
|
29
|
+
*
|
|
30
|
+
* `stepEditor` is the editor with its undo and redo marked as STEPS, so the
|
|
31
|
+
* document they produce is diffed against the one before it and the tile that
|
|
32
|
+
* changed is lit briefly and scrolled to. An ordinary edit is not a step: the
|
|
33
|
+
* author is already looking at what they changed.
|
|
34
|
+
*/
|
|
35
|
+
export function useBuilderSelection({
|
|
36
|
+
editor,
|
|
37
|
+
gridBox,
|
|
38
|
+
}: {
|
|
39
|
+
editor: DashboardEditor;
|
|
40
|
+
/** The grid's box, searched for the changed tile to scroll to. */
|
|
41
|
+
gridBox: RefObject<HTMLDivElement | null>;
|
|
42
|
+
}) {
|
|
43
|
+
const [selection, setSelection] = useState<Selection>(undefined);
|
|
44
|
+
const selected = typeof selection === "object" ? selection.tile : undefined;
|
|
45
|
+
// The description is selected the way a tile is, and only one thing is:
|
|
46
|
+
// selecting a tile deselects it, and selecting it deselects the tile.
|
|
47
|
+
const descriptionSelected = selection === "description";
|
|
48
|
+
const selectTile = useCallback(
|
|
49
|
+
(index: number) =>
|
|
50
|
+
setSelection((previous) =>
|
|
51
|
+
typeof previous === "object" && previous.tile === index
|
|
52
|
+
? previous
|
|
53
|
+
: { tile: index },
|
|
54
|
+
),
|
|
55
|
+
[],
|
|
56
|
+
);
|
|
57
|
+
// Drops a selected TILE only: the description, if that is what is
|
|
58
|
+
// selected, stays selected.
|
|
59
|
+
const deselectTile = useCallback(
|
|
60
|
+
() =>
|
|
61
|
+
setSelection((previous) =>
|
|
62
|
+
previous === "description" ? previous : undefined,
|
|
63
|
+
),
|
|
64
|
+
[],
|
|
65
|
+
);
|
|
66
|
+
const selectDescription = useCallback(() => setSelection("description"), []);
|
|
67
|
+
const clearSelection = useCallback(() => setSelection(undefined), []);
|
|
68
|
+
|
|
69
|
+
// Undo and redo point at the tile they changed: lit briefly, and scrolled to.
|
|
70
|
+
const [flash, setFlash] = useState<string | undefined>(undefined);
|
|
71
|
+
const stepping = useRef(false);
|
|
72
|
+
const lastDocument = useRef<DashboardDocument>(editor.document);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
const before = lastDocument.current;
|
|
75
|
+
lastDocument.current = editor.document;
|
|
76
|
+
if (!stepping.current) return;
|
|
77
|
+
stepping.current = false;
|
|
78
|
+
const key = changedTileKey(before, editor.document);
|
|
79
|
+
if (key === undefined) return;
|
|
80
|
+
setFlash(key);
|
|
81
|
+
const target = Array.from(
|
|
82
|
+
gridBox.current?.querySelectorAll<HTMLElement>("[data-tile-key]") ??
|
|
83
|
+
[],
|
|
84
|
+
).find((element) => element.dataset.tileKey === key);
|
|
85
|
+
// jsdom has no layout, so no scrollIntoView.
|
|
86
|
+
target?.scrollIntoView?.({
|
|
87
|
+
block: "nearest",
|
|
88
|
+
behavior: scrollBehavior(),
|
|
89
|
+
});
|
|
90
|
+
}, [editor.document, gridBox]);
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (flash === undefined) return;
|
|
93
|
+
const timer = setTimeout(() => setFlash(undefined), 1500);
|
|
94
|
+
return () => clearTimeout(timer);
|
|
95
|
+
}, [flash]);
|
|
96
|
+
const stepEditor = useMemo(
|
|
97
|
+
() => ({
|
|
98
|
+
...editor,
|
|
99
|
+
undo: () => {
|
|
100
|
+
stepping.current = true;
|
|
101
|
+
editor.undo();
|
|
102
|
+
},
|
|
103
|
+
redo: () => {
|
|
104
|
+
stepping.current = true;
|
|
105
|
+
editor.redo();
|
|
106
|
+
},
|
|
107
|
+
}),
|
|
108
|
+
[editor],
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
selected,
|
|
113
|
+
descriptionSelected,
|
|
114
|
+
selectTile,
|
|
115
|
+
deselectTile,
|
|
116
|
+
selectDescription,
|
|
117
|
+
clearSelection,
|
|
118
|
+
flash,
|
|
119
|
+
stepEditor,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { act, renderHook } from "@testing-library/react";
|
|
5
|
+
import { describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import {
|
|
7
|
+
useBuilderSession,
|
|
8
|
+
type BuilderSessionOptions,
|
|
9
|
+
type SessionEditor,
|
|
10
|
+
} from "./useBuilderSession";
|
|
11
|
+
import type { SaveOutcome } from "./useDocumentEditor";
|
|
12
|
+
|
|
13
|
+
type Doc = { n: number };
|
|
14
|
+
|
|
15
|
+
const makeEditor = (
|
|
16
|
+
over: Partial<SessionEditor<Doc>> = {},
|
|
17
|
+
): SessionEditor<Doc> => ({
|
|
18
|
+
document: { n: 1 },
|
|
19
|
+
saved: { n: 0 },
|
|
20
|
+
dirty: true,
|
|
21
|
+
structural: false,
|
|
22
|
+
canUndo: true,
|
|
23
|
+
canRedo: false,
|
|
24
|
+
undo: mock(() => {}),
|
|
25
|
+
redo: mock(() => {}),
|
|
26
|
+
save: mock(async (): Promise<SaveOutcome> => ({ ok: true })),
|
|
27
|
+
canUndoSave: false,
|
|
28
|
+
undoSave: mock(async (): Promise<SaveOutcome> => ({ ok: true })),
|
|
29
|
+
...over,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const mount = (
|
|
33
|
+
over: Partial<BuilderSessionOptions<Doc>> = {},
|
|
34
|
+
editor: SessionEditor<Doc> = makeEditor(),
|
|
35
|
+
) => {
|
|
36
|
+
const saved = mock((_info: unknown) => {});
|
|
37
|
+
const refused = mock((_reason: string) => {});
|
|
38
|
+
const undone = mock((_info: unknown) => {});
|
|
39
|
+
const undoRefused = mock((_reason: string) => {});
|
|
40
|
+
const onSave = mock(async (_source: string) => {});
|
|
41
|
+
const shortcuts = { escape: () => {} };
|
|
42
|
+
const view = renderHook(
|
|
43
|
+
(props: { editor: SessionEditor<Doc> }) =>
|
|
44
|
+
useBuilderSession<Doc>({
|
|
45
|
+
editor: props.editor,
|
|
46
|
+
onSave,
|
|
47
|
+
shortcuts,
|
|
48
|
+
unit: { name: "tile", count: (document) => document.n },
|
|
49
|
+
report: { size: 3, saved, refused, undone, undoRefused },
|
|
50
|
+
...over,
|
|
51
|
+
}),
|
|
52
|
+
{ initialProps: { editor } },
|
|
53
|
+
);
|
|
54
|
+
return { ...view, editor, saved, refused, undone, undoRefused, onSave };
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
describe("useBuilderSession save", () => {
|
|
58
|
+
it("writes at once and reports the size and structure it saved", async () => {
|
|
59
|
+
const { result, saved, editor } = mount(
|
|
60
|
+
{},
|
|
61
|
+
makeEditor({ structural: false }),
|
|
62
|
+
);
|
|
63
|
+
await act(async () => {
|
|
64
|
+
await result.current.save();
|
|
65
|
+
});
|
|
66
|
+
expect(editor.save).toHaveBeenCalledTimes(1);
|
|
67
|
+
expect(saved).toHaveBeenCalledTimes(1);
|
|
68
|
+
const info = saved.mock.calls[0][0] as {
|
|
69
|
+
size: number;
|
|
70
|
+
structural: boolean;
|
|
71
|
+
durationMs: number;
|
|
72
|
+
};
|
|
73
|
+
expect(info.size).toBe(3);
|
|
74
|
+
expect(info.structural).toBe(false);
|
|
75
|
+
expect(typeof info.durationMs).toBe("number");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("reports a refusal and not a save", async () => {
|
|
79
|
+
const editor = makeEditor({
|
|
80
|
+
save: mock(
|
|
81
|
+
async (): Promise<SaveOutcome> => ({ ok: false, reason: "nope" }),
|
|
82
|
+
),
|
|
83
|
+
});
|
|
84
|
+
const { result, saved, refused } = mount({}, editor);
|
|
85
|
+
await act(async () => {
|
|
86
|
+
await result.current.save();
|
|
87
|
+
});
|
|
88
|
+
expect(refused).toHaveBeenCalledWith("nope");
|
|
89
|
+
expect(saved).not.toHaveBeenCalled();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("does nothing when clean, without a writer, or while saving", async () => {
|
|
93
|
+
const clean = mount({}, makeEditor({ dirty: false }));
|
|
94
|
+
await act(async () => {
|
|
95
|
+
await clean.result.current.save();
|
|
96
|
+
});
|
|
97
|
+
expect(clean.editor.save).not.toHaveBeenCalled();
|
|
98
|
+
|
|
99
|
+
const none = mount({ onSave: undefined });
|
|
100
|
+
await act(async () => {
|
|
101
|
+
await none.result.current.save();
|
|
102
|
+
});
|
|
103
|
+
expect(none.editor.save).not.toHaveBeenCalled();
|
|
104
|
+
expect(none.result.current.toolbarProps.onSave).toBeUndefined();
|
|
105
|
+
|
|
106
|
+
let release = () => {};
|
|
107
|
+
const slow = makeEditor({
|
|
108
|
+
save: mock(
|
|
109
|
+
() =>
|
|
110
|
+
new Promise<SaveOutcome>((resolve) => {
|
|
111
|
+
release = () => resolve({ ok: true });
|
|
112
|
+
}),
|
|
113
|
+
),
|
|
114
|
+
});
|
|
115
|
+
const busy = mount({}, slow);
|
|
116
|
+
let first: Promise<void> | void;
|
|
117
|
+
act(() => {
|
|
118
|
+
first = busy.result.current.save();
|
|
119
|
+
});
|
|
120
|
+
expect(busy.result.current.saving).toBe(true);
|
|
121
|
+
await act(async () => {
|
|
122
|
+
await busy.result.current.save();
|
|
123
|
+
});
|
|
124
|
+
expect(slow.save).toHaveBeenCalledTimes(1);
|
|
125
|
+
await act(async () => {
|
|
126
|
+
release();
|
|
127
|
+
await first;
|
|
128
|
+
});
|
|
129
|
+
expect(busy.result.current.saving).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("runs every entry point through prepare", async () => {
|
|
133
|
+
const prepare = mock((run: () => Promise<void> | void) => run());
|
|
134
|
+
const { result, editor } = mount({ prepare });
|
|
135
|
+
await act(async () => {
|
|
136
|
+
await result.current.save();
|
|
137
|
+
});
|
|
138
|
+
expect(prepare).toHaveBeenCalledTimes(1);
|
|
139
|
+
expect(editor.save).toHaveBeenCalledTimes(1);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("useBuilderSession reports", () => {
|
|
144
|
+
it("reports dirty from the editor or the extra state, and clean on unmount", () => {
|
|
145
|
+
const onDirtyChange = mock((_dirty: boolean) => {});
|
|
146
|
+
const clean = makeEditor({ dirty: false });
|
|
147
|
+
const view = mount({ onDirtyChange, extraDirty: true }, clean);
|
|
148
|
+
expect(onDirtyChange).toHaveBeenLastCalledWith(true);
|
|
149
|
+
expect(view.result.current.toolbarProps.dirty).toBe(true);
|
|
150
|
+
view.unmount();
|
|
151
|
+
expect(onDirtyChange).toHaveBeenLastCalledWith(false);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("reports the document on mount and when it changes", () => {
|
|
155
|
+
const onChange = mock((_doc: Doc) => {});
|
|
156
|
+
const view = mount({ onChange });
|
|
157
|
+
expect(onChange).toHaveBeenLastCalledWith({ n: 1 });
|
|
158
|
+
view.rerender({ editor: makeEditor({ document: { n: 2 } }) });
|
|
159
|
+
expect(onChange).toHaveBeenLastCalledWith({ n: 2 });
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("useBuilderSession undo save", () => {
|
|
164
|
+
const LAST = {
|
|
165
|
+
before: "a",
|
|
166
|
+
after: "a,b",
|
|
167
|
+
structural: true,
|
|
168
|
+
clearsHistory: false,
|
|
169
|
+
};
|
|
170
|
+
const offering = (over: Partial<SessionEditor<Doc>> = {}) =>
|
|
171
|
+
makeEditor({ dirty: false, canUndoSave: true, lastSave: LAST, ...over });
|
|
172
|
+
|
|
173
|
+
it("undoes through the editor and reports it like a save", async () => {
|
|
174
|
+
const { result, editor, undone, saved } = mount({}, offering());
|
|
175
|
+
expect(result.current.canUndoSave).toBe(true);
|
|
176
|
+
expect(result.current.lastSave).toEqual(LAST);
|
|
177
|
+
await act(async () => {
|
|
178
|
+
await result.current.undoSave();
|
|
179
|
+
});
|
|
180
|
+
expect(editor.undoSave).toHaveBeenCalledTimes(1);
|
|
181
|
+
expect(saved).not.toHaveBeenCalled();
|
|
182
|
+
const info = undone.mock.calls[0][0] as {
|
|
183
|
+
size: number;
|
|
184
|
+
structural: boolean;
|
|
185
|
+
durationMs: number;
|
|
186
|
+
};
|
|
187
|
+
expect(info.size).toBe(3);
|
|
188
|
+
expect(info.structural).toBe(true);
|
|
189
|
+
expect(typeof info.durationMs).toBe("number");
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("reports a refused undo with its reason", async () => {
|
|
193
|
+
const editor = offering({
|
|
194
|
+
undoSave: mock(
|
|
195
|
+
async (): Promise<SaveOutcome> => ({
|
|
196
|
+
ok: false,
|
|
197
|
+
reason: "changed since",
|
|
198
|
+
}),
|
|
199
|
+
),
|
|
200
|
+
});
|
|
201
|
+
const { result, undone, undoRefused } = mount({}, editor);
|
|
202
|
+
await act(async () => {
|
|
203
|
+
await result.current.undoSave();
|
|
204
|
+
});
|
|
205
|
+
expect(undone).not.toHaveBeenCalled();
|
|
206
|
+
expect(undoRefused).toHaveBeenCalledWith("changed since");
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("is saving while the undo writes, so Save and a second Undo do nothing", async () => {
|
|
210
|
+
let finish!: (outcome: SaveOutcome) => void;
|
|
211
|
+
const editor = offering({
|
|
212
|
+
dirty: true,
|
|
213
|
+
undoSave: mock(
|
|
214
|
+
() => new Promise<SaveOutcome>((resolve) => (finish = resolve)),
|
|
215
|
+
),
|
|
216
|
+
});
|
|
217
|
+
const { result } = mount({}, editor);
|
|
218
|
+
let undoing!: Promise<void> | void;
|
|
219
|
+
act(() => {
|
|
220
|
+
undoing = result.current.undoSave();
|
|
221
|
+
void result.current.undoSave();
|
|
222
|
+
});
|
|
223
|
+
expect(result.current.saving).toBe(true);
|
|
224
|
+
expect(result.current.canUndoSave).toBe(false);
|
|
225
|
+
await act(async () => {
|
|
226
|
+
await result.current.save();
|
|
227
|
+
});
|
|
228
|
+
expect(editor.save).not.toHaveBeenCalled();
|
|
229
|
+
await act(async () => {
|
|
230
|
+
finish({ ok: true });
|
|
231
|
+
await undoing;
|
|
232
|
+
});
|
|
233
|
+
expect(editor.undoSave).toHaveBeenCalledTimes(1);
|
|
234
|
+
expect(result.current.saving).toBe(false);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("does nothing without a writer or an offer", async () => {
|
|
238
|
+
const none = mount({}, makeEditor());
|
|
239
|
+
await act(async () => {
|
|
240
|
+
await none.result.current.undoSave();
|
|
241
|
+
});
|
|
242
|
+
expect(none.editor.undoSave).not.toHaveBeenCalled();
|
|
243
|
+
const readOnly = mount({ onSave: undefined }, offering());
|
|
244
|
+
expect(readOnly.result.current.canUndoSave).toBe(false);
|
|
245
|
+
await act(async () => {
|
|
246
|
+
await readOnly.result.current.undoSave();
|
|
247
|
+
});
|
|
248
|
+
expect(readOnly.editor.undoSave).not.toHaveBeenCalled();
|
|
249
|
+
});
|
|
250
|
+
});
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
useCallback,
|
|
6
|
+
useEffect,
|
|
7
|
+
useLayoutEffect,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
} from "react";
|
|
12
|
+
import { now } from "../../utils/clock";
|
|
13
|
+
import type { BuilderToolbarProps } from "./BuilderToolbar";
|
|
14
|
+
import {
|
|
15
|
+
useBuilderShortcuts,
|
|
16
|
+
type BuilderShortcutHandlers,
|
|
17
|
+
} from "./useBuilderShortcuts";
|
|
18
|
+
import type { LastSave, SaveHandler, SaveOutcome } from "./useDocumentEditor";
|
|
19
|
+
import { useExitGuard } from "./useExitGuard";
|
|
20
|
+
|
|
21
|
+
/** What a builder's session reads of its document editor. */
|
|
22
|
+
export interface SessionEditor<D, L extends LastSave = LastSave> {
|
|
23
|
+
document: D;
|
|
24
|
+
/** The document as of the last save (or open). */
|
|
25
|
+
saved: D;
|
|
26
|
+
dirty: boolean;
|
|
27
|
+
/** Unsaved edits made by a person, when that differs from `dirty` (an open that is unsaved before any edit); absent means `dirty`. */
|
|
28
|
+
edited?: boolean;
|
|
29
|
+
structural: boolean;
|
|
30
|
+
/** Whether the document opened unsaved (a conversion); the save that clears it reports so. */
|
|
31
|
+
pendingOpen?: boolean;
|
|
32
|
+
canUndo: boolean;
|
|
33
|
+
canRedo: boolean;
|
|
34
|
+
undo: () => void;
|
|
35
|
+
redo: () => void;
|
|
36
|
+
save: () => Promise<SaveOutcome>;
|
|
37
|
+
canUndoSave: boolean;
|
|
38
|
+
lastSave?: L;
|
|
39
|
+
undoSave: () => Promise<SaveOutcome>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** What a builder says about a save, in its own event's words. */
|
|
43
|
+
export interface SessionReport {
|
|
44
|
+
/** How many tiles or cells the document has, as the event counts them. */
|
|
45
|
+
size: number;
|
|
46
|
+
saved: (info: SessionSaveInfo) => void;
|
|
47
|
+
refused: (reason: string) => void;
|
|
48
|
+
/** An Undo save that wrote the file back. */
|
|
49
|
+
undone: (info: SessionSaveInfo) => void;
|
|
50
|
+
undoRefused: (reason: string) => void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface SessionSaveInfo {
|
|
54
|
+
size: number;
|
|
55
|
+
structural: boolean;
|
|
56
|
+
/** The save wrote a document that opened unsaved. */
|
|
57
|
+
fromOpen: boolean;
|
|
58
|
+
durationMs: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface BuilderSessionOptions<D, L extends LastSave = LastSave> {
|
|
62
|
+
editor: SessionEditor<D, L>;
|
|
63
|
+
onSave?: SaveHandler<D>;
|
|
64
|
+
onDirtyChange?: (dirty: boolean) => void;
|
|
65
|
+
/** The host's way out, opted into: draws Close, which asks first when edits are unsaved. */
|
|
66
|
+
onExit?: () => void;
|
|
67
|
+
onChange?: (document: D) => void;
|
|
68
|
+
/** Unsaved state the editor does not hold, such as an open text draft. */
|
|
69
|
+
extraDirty?: boolean;
|
|
70
|
+
report: SessionReport;
|
|
71
|
+
/** What the notice counts and calls them: "tile" or "cell". */
|
|
72
|
+
unit: { name: string; count: (document: D) => number };
|
|
73
|
+
/** Runs before every save entry point, handing it the save to run once the document is ready. */
|
|
74
|
+
prepare?: (run: () => Promise<void> | void) => Promise<void> | void;
|
|
75
|
+
/** The builder's own keys, less undo, redo and save, which the session owns. Memoized by the caller. */
|
|
76
|
+
shortcuts: Pick<BuilderShortcutHandlers, "escape" | "nudge">;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* What the dashboard and notebook builders share around their document editor:
|
|
81
|
+
* saving (with its event and timing), the dirty and change reports, the exit
|
|
82
|
+
* guard, the keyboard, and the props their toolbar takes.
|
|
83
|
+
*/
|
|
84
|
+
export function useBuilderSession<
|
|
85
|
+
D,
|
|
86
|
+
L extends LastSave & { removedComments?: string[] } = LastSave,
|
|
87
|
+
>({
|
|
88
|
+
editor,
|
|
89
|
+
onSave,
|
|
90
|
+
onDirtyChange,
|
|
91
|
+
onExit,
|
|
92
|
+
onChange,
|
|
93
|
+
extraDirty = false,
|
|
94
|
+
report,
|
|
95
|
+
unit,
|
|
96
|
+
prepare,
|
|
97
|
+
shortcuts,
|
|
98
|
+
}: BuilderSessionOptions<D, L>) {
|
|
99
|
+
const [saving, setSaving] = useState(false);
|
|
100
|
+
const [undone, setUndone] = useState(false);
|
|
101
|
+
const saveButton = useRef<HTMLButtonElement>(null);
|
|
102
|
+
const reportRef = useRef(report);
|
|
103
|
+
reportRef.current = report;
|
|
104
|
+
const dirty = editor.dirty || extraDirty;
|
|
105
|
+
// Work to lose: a conversion nobody has touched is rebuilt by opening the file again.
|
|
106
|
+
const hasEdits = (editor.edited ?? editor.dirty) || extraDirty;
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
onChange?.(editor.document);
|
|
110
|
+
}, [editor.document, onChange]);
|
|
111
|
+
// Also on mount, so a host that remounted the builder on new text is told the slate is clean rather than carrying the previous mount's answer.
|
|
112
|
+
// A layout effect, so a host's leave guard sees the flag in the same task as the edit.
|
|
113
|
+
useLayoutEffect(() => {
|
|
114
|
+
onDirtyChange?.(hasEdits);
|
|
115
|
+
}, [hasEdits, onDirtyChange]);
|
|
116
|
+
// A host guarding navigation on this must not be left holding a stale "dirty" once the builder is gone.
|
|
117
|
+
const onDirtyChangeRef = useRef(onDirtyChange);
|
|
118
|
+
onDirtyChangeRef.current = onDirtyChange;
|
|
119
|
+
useEffect(() => () => onDirtyChangeRef.current?.(false), []);
|
|
120
|
+
const unitRef = useRef(unit);
|
|
121
|
+
unitRef.current = unit;
|
|
122
|
+
// The line saying the undo happened goes with the next edit or save; leaving it up over new work would say something stale.
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
setUndone(false);
|
|
125
|
+
}, [editor.document]);
|
|
126
|
+
|
|
127
|
+
const commitSave = useCallback(() => {
|
|
128
|
+
setSaving(true);
|
|
129
|
+
setUndone(false);
|
|
130
|
+
const started = now();
|
|
131
|
+
const { structural } = editor;
|
|
132
|
+
const fromOpen = editor.pendingOpen ?? false;
|
|
133
|
+
const size = reportRef.current.size;
|
|
134
|
+
return editor
|
|
135
|
+
.save()
|
|
136
|
+
.then((outcome) => {
|
|
137
|
+
if (outcome.ok === true) {
|
|
138
|
+
reportRef.current.saved({
|
|
139
|
+
size,
|
|
140
|
+
structural,
|
|
141
|
+
fromOpen,
|
|
142
|
+
durationMs: now() - started,
|
|
143
|
+
});
|
|
144
|
+
} else reportRef.current.refused(outcome.reason);
|
|
145
|
+
})
|
|
146
|
+
.finally(() => setSaving(false));
|
|
147
|
+
}, [editor]);
|
|
148
|
+
|
|
149
|
+
// A ref as well as `saving`, so a second click before the re-render does not write twice.
|
|
150
|
+
const undoingRef = useRef(false);
|
|
151
|
+
const focusSave = useRef(false);
|
|
152
|
+
// The notice that held focus is gone, so the key that follows is the next save; Save is enabled again once the write settles.
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (!focusSave.current || saving) return;
|
|
155
|
+
focusSave.current = false;
|
|
156
|
+
saveButton.current?.focus();
|
|
157
|
+
}, [undone, saving]);
|
|
158
|
+
const undoSave = useCallback((): Promise<void> | void => {
|
|
159
|
+
if (!onSave || saving || undoingRef.current || !editor.canUndoSave)
|
|
160
|
+
return;
|
|
161
|
+
undoingRef.current = true;
|
|
162
|
+
setSaving(true);
|
|
163
|
+
const started = now();
|
|
164
|
+
const structural = editor.lastSave?.structural ?? false;
|
|
165
|
+
const size = reportRef.current.size;
|
|
166
|
+
return editor
|
|
167
|
+
.undoSave()
|
|
168
|
+
.then((outcome) => {
|
|
169
|
+
if (outcome.ok === true) {
|
|
170
|
+
focusSave.current = true;
|
|
171
|
+
setUndone(true);
|
|
172
|
+
reportRef.current.undone({
|
|
173
|
+
size,
|
|
174
|
+
structural,
|
|
175
|
+
fromOpen: false,
|
|
176
|
+
durationMs: now() - started,
|
|
177
|
+
});
|
|
178
|
+
} else reportRef.current.undoRefused(outcome.reason);
|
|
179
|
+
})
|
|
180
|
+
.finally(() => {
|
|
181
|
+
undoingRef.current = false;
|
|
182
|
+
setSaving(false);
|
|
183
|
+
});
|
|
184
|
+
}, [onSave, saving, editor]);
|
|
185
|
+
|
|
186
|
+
const guardedSave = useCallback((): Promise<void> | void => {
|
|
187
|
+
if (!onSave || !editor.dirty || saving) return;
|
|
188
|
+
return commitSave();
|
|
189
|
+
}, [onSave, editor, saving, commitSave]);
|
|
190
|
+
const guardedRef = useRef(guardedSave);
|
|
191
|
+
guardedRef.current = guardedSave;
|
|
192
|
+
const save = useCallback((): Promise<void> | void => {
|
|
193
|
+
const run = () => guardedRef.current();
|
|
194
|
+
return prepare ? prepare(run) : run();
|
|
195
|
+
}, [prepare]);
|
|
196
|
+
|
|
197
|
+
const exitGuard = useExitGuard({
|
|
198
|
+
dirty: hasEdits,
|
|
199
|
+
saving,
|
|
200
|
+
canSave: !!onSave,
|
|
201
|
+
save,
|
|
202
|
+
onExit: () => onExit?.(),
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
useBuilderShortcuts(
|
|
206
|
+
// One handlers object per change of what they read, so the key listener is not torn down and re-bound on every render.
|
|
207
|
+
useMemo(
|
|
208
|
+
() => ({
|
|
209
|
+
...shortcuts,
|
|
210
|
+
undo: editor.undo,
|
|
211
|
+
redo: editor.redo,
|
|
212
|
+
...(onSave ? { save } : {}),
|
|
213
|
+
paused: exitGuard.dialog.open,
|
|
214
|
+
}),
|
|
215
|
+
[shortcuts, editor, onSave, save, exitGuard.dialog.open],
|
|
216
|
+
),
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
const canUndoSave = !!onSave && !saving && editor.canUndoSave;
|
|
220
|
+
const lastSave = editor.lastSave;
|
|
221
|
+
|
|
222
|
+
const toolbarProps: Pick<
|
|
223
|
+
BuilderToolbarProps,
|
|
224
|
+
| "canUndo"
|
|
225
|
+
| "canRedo"
|
|
226
|
+
| "onUndo"
|
|
227
|
+
| "onRedo"
|
|
228
|
+
| "dirty"
|
|
229
|
+
| "saving"
|
|
230
|
+
| "onSave"
|
|
231
|
+
| "saveButton"
|
|
232
|
+
| "onExit"
|
|
233
|
+
> = {
|
|
234
|
+
canUndo: editor.canUndo,
|
|
235
|
+
canRedo: editor.canRedo,
|
|
236
|
+
onUndo: editor.undo,
|
|
237
|
+
onRedo: editor.redo,
|
|
238
|
+
dirty,
|
|
239
|
+
saving,
|
|
240
|
+
saveButton,
|
|
241
|
+
...(onSave ? { onSave: save } : {}),
|
|
242
|
+
...(onExit ? { onExit: exitGuard.requestExit } : {}),
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
return {
|
|
246
|
+
saving,
|
|
247
|
+
save,
|
|
248
|
+
exitGuard,
|
|
249
|
+
/** Write the file back as it was before the last save, and put the edits back unsaved. */
|
|
250
|
+
undoSave,
|
|
251
|
+
canUndoSave,
|
|
252
|
+
lastSave,
|
|
253
|
+
toolbarProps,
|
|
254
|
+
};
|
|
255
|
+
}
|