@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
|
@@ -1,21 +1,39 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
+
import { annotationTextProblem } from "./annotationText";
|
|
5
|
+
import {
|
|
6
|
+
chartLineText,
|
|
7
|
+
isChartPick,
|
|
8
|
+
mentionsChartTag,
|
|
9
|
+
parseChartLine,
|
|
10
|
+
type ChartPick,
|
|
11
|
+
} from "./chartLine";
|
|
4
12
|
import type {
|
|
5
13
|
DashboardDocument,
|
|
6
14
|
DashboardDrill,
|
|
7
15
|
DashboardSource,
|
|
8
16
|
DashboardTile,
|
|
17
|
+
DocumentKind,
|
|
18
|
+
QueryTile,
|
|
19
|
+
TextTile,
|
|
9
20
|
} from "./document";
|
|
21
|
+
import { isQueryTile, isTextTile } from "./document";
|
|
10
22
|
import type { LocalGiven } from "./document";
|
|
11
23
|
import {
|
|
12
24
|
artifactLine,
|
|
25
|
+
artifactTag,
|
|
26
|
+
type ArtifactTag,
|
|
13
27
|
descriptionNotes,
|
|
14
|
-
|
|
15
|
-
|
|
28
|
+
isIdentifier,
|
|
29
|
+
isBareName,
|
|
30
|
+
isStrictName,
|
|
31
|
+
malloyPath,
|
|
32
|
+
} from "../../utils/malloyText";
|
|
16
33
|
import {
|
|
17
34
|
parseMalloy,
|
|
18
35
|
parseRefused,
|
|
36
|
+
readTileList,
|
|
19
37
|
translate,
|
|
20
38
|
type ParsedMalloy,
|
|
21
39
|
type Span,
|
|
@@ -24,6 +42,11 @@ import {
|
|
|
24
42
|
type TreeView,
|
|
25
43
|
} from "./malloyTree";
|
|
26
44
|
import { blockAbove, readDashboardDocument, readFailed } from "./readDocument";
|
|
45
|
+
import {
|
|
46
|
+
spliceFailed,
|
|
47
|
+
type SpliceFailure,
|
|
48
|
+
type SpliceResult,
|
|
49
|
+
} from "./spliceResult";
|
|
27
50
|
|
|
28
51
|
/**
|
|
29
52
|
* The syntax errors Malloy's own parser reports for `text`, as a multiset of
|
|
@@ -68,8 +91,8 @@ export async function syntaxErrors(text: string): Promise<string[]> {
|
|
|
68
91
|
* ADDED or REMOVED: a new `view:` inside the extension of the source it reads
|
|
69
92
|
* (or a new extension, when the file imports that source by name), a removed
|
|
70
93
|
* one deleted with its `#` tags. Those moves are the one place the file cannot
|
|
71
|
-
* say who owns the comment beside a declaration, so the
|
|
72
|
-
*
|
|
94
|
+
* say who owns the comment beside a declaration, so the `//` comments are left
|
|
95
|
+
* where they were and the author can read the change back with View change.
|
|
73
96
|
*
|
|
74
97
|
* A given is different from a tile in exactly the way that matters there: the
|
|
75
98
|
* `#` tags above its declaration are its control contract and have no other
|
|
@@ -77,16 +100,7 @@ export async function syntaxErrors(text: string): Promise<string[]> {
|
|
|
77
100
|
* in the same block is left where it is.
|
|
78
101
|
*/
|
|
79
102
|
|
|
80
|
-
export
|
|
81
|
-
ok: false;
|
|
82
|
-
reason: string;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export type SpliceResult = { ok: true; source: string } | SpliceFailure;
|
|
86
|
-
|
|
87
|
-
/** Narrow to the failure arm; see {@link readFailed} for why a guard. */
|
|
88
|
-
export const spliceFailed = (result: SpliceResult): result is SpliceFailure =>
|
|
89
|
-
result.ok === false;
|
|
103
|
+
export { spliceFailed, type SpliceFailure, type SpliceResult };
|
|
90
104
|
|
|
91
105
|
/**
|
|
92
106
|
* A stable serialisation for comparing documents.
|
|
@@ -112,6 +126,11 @@ function canonical(value: unknown): string {
|
|
|
112
126
|
return JSON.stringify(walk(value));
|
|
113
127
|
}
|
|
114
128
|
|
|
129
|
+
/** A description without blank lines at either end, each of which would write a bare `##"`. */
|
|
130
|
+
function trimDescription(text: string): string {
|
|
131
|
+
return text.replace(/^(?:[ \t]*\r?\n)+/, "").trimEnd();
|
|
132
|
+
}
|
|
133
|
+
|
|
115
134
|
/** A byte-range replacement. Applied last-first so earlier offsets stay valid. */
|
|
116
135
|
interface Edit {
|
|
117
136
|
start: number;
|
|
@@ -141,8 +160,14 @@ function applyEdits(source: string, edits: Edit[]): string {
|
|
|
141
160
|
return out;
|
|
142
161
|
}
|
|
143
162
|
|
|
163
|
+
/** The chart a tile's `chart` asks the writer to put on its wrapper; `default` and `custom` ask for no line. */
|
|
164
|
+
const writableChart = (
|
|
165
|
+
chart: QueryTile["chart"],
|
|
166
|
+
): ChartPick | "none" | undefined =>
|
|
167
|
+
chart === "none" || isChartPick(chart) ? chart : undefined;
|
|
168
|
+
|
|
144
169
|
/** The `#` tags a tile's presentation implies, in the order they are written. */
|
|
145
|
-
function tagsFor(tile:
|
|
170
|
+
function tagsFor(tile: QueryTile, withChart = true): string[] {
|
|
146
171
|
const tags: string[] = [];
|
|
147
172
|
if (tile.colspan !== undefined) tags.push(`# colspan=${tile.colspan}`);
|
|
148
173
|
if (tile.break) tags.push("# break");
|
|
@@ -150,6 +175,8 @@ function tagsFor(tile: DashboardTile): string[] {
|
|
|
150
175
|
if (tile.label !== undefined) tags.push(`# label=${quoted(tile.label)}`);
|
|
151
176
|
if (tile.subtitle !== undefined)
|
|
152
177
|
tags.push(`# subtitle=${quoted(tile.subtitle)}`);
|
|
178
|
+
const chart = withChart ? writableChart(tile.chart) : undefined;
|
|
179
|
+
if (chart !== undefined) tags.push(chartLineText(chart, tile.chartCarried));
|
|
153
180
|
return tags;
|
|
154
181
|
}
|
|
155
182
|
|
|
@@ -194,10 +221,8 @@ const MODELLED_GIVEN_TAG_KEYS: ReadonlySet<string> = new Set([
|
|
|
194
221
|
"range_max",
|
|
195
222
|
]);
|
|
196
223
|
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
b: DashboardDocument,
|
|
200
|
-
) => canonical(a.imports) === canonical(b.imports);
|
|
224
|
+
const kindOf = (document: DashboardDocument): DocumentKind =>
|
|
225
|
+
document.kind ?? "dashboard";
|
|
201
226
|
|
|
202
227
|
/**
|
|
203
228
|
* A given's tag line, composed from its control contract. One line, in the
|
|
@@ -215,10 +240,10 @@ function givenTagLine(given: LocalGiven): string | undefined {
|
|
|
215
240
|
given.suggest.source !== undefined
|
|
216
241
|
? `source=${given.suggest.source}`
|
|
217
242
|
: given.suggest.query !== undefined
|
|
218
|
-
? `query=${given.suggest.query}`
|
|
243
|
+
? `query=${quoted(given.suggest.query)}`
|
|
219
244
|
: undefined;
|
|
220
245
|
parts.push(
|
|
221
|
-
`suggest { ${by ? `${by} ` : ""}dimension=${given.suggest.dimension} }`,
|
|
246
|
+
`suggest { ${by ? `${by} ` : ""}dimension=${quoted(given.suggest.dimension)} }`,
|
|
222
247
|
);
|
|
223
248
|
}
|
|
224
249
|
if (given.rangeMin !== undefined) parts.push(`range_min=${given.rangeMin}`);
|
|
@@ -278,7 +303,9 @@ const quoted = (text: string) =>
|
|
|
278
303
|
* rewrite declarations?" wants THIS key.
|
|
279
304
|
*/
|
|
280
305
|
export const tileFileKey = (t: DashboardTile) =>
|
|
281
|
-
|
|
306
|
+
isTextTile(t)
|
|
307
|
+
? canonical(["text", t.name])
|
|
308
|
+
: canonical([t.name, t.source, t.declaration]);
|
|
282
309
|
const tileKey = tileFileKey;
|
|
283
310
|
|
|
284
311
|
/** The tile list as identities, IN ORDER. Differs under a reorder. */
|
|
@@ -307,6 +334,10 @@ interface SpliceContext extends TileMembership {
|
|
|
307
334
|
current: DashboardDocument;
|
|
308
335
|
next: DashboardDocument;
|
|
309
336
|
edits: Edit[];
|
|
337
|
+
/** The file's package path, when known. */
|
|
338
|
+
modelPath?: string;
|
|
339
|
+
/** A kind switch writes `kind=` whichever way it goes; see {@link SpliceOptions.explicitKind}. */
|
|
340
|
+
explicitKind?: boolean;
|
|
310
341
|
}
|
|
311
342
|
|
|
312
343
|
/**
|
|
@@ -316,12 +347,19 @@ interface SpliceContext extends TileMembership {
|
|
|
316
347
|
function checkShape(
|
|
317
348
|
current: DashboardDocument,
|
|
318
349
|
next: DashboardDocument,
|
|
350
|
+
changeKind: boolean,
|
|
319
351
|
): SpliceFailure | TileMembership {
|
|
352
|
+
if (kindOf(current) !== kindOf(next) && !changeKind) {
|
|
353
|
+
return {
|
|
354
|
+
ok: false,
|
|
355
|
+
reason:
|
|
356
|
+
"The document's kind is not changed by an ordinary edit; switch it with the explicit kind change.",
|
|
357
|
+
};
|
|
358
|
+
}
|
|
320
359
|
// Tiles ADDED and REMOVED, by identity. A removed tile's declaration goes,
|
|
321
360
|
// with its `#` tags; a `//` comment above it stays, because the file cannot
|
|
322
361
|
// say whether it belonged to the tile, the row or the page, and a comment
|
|
323
|
-
// left behind is a smaller wrong than one destroyed
|
|
324
|
-
// this diff before it saves. An added tile is a `view:` in the extension of
|
|
362
|
+
// left behind is a smaller wrong than one destroyed. An added tile is a `view:` in the extension of
|
|
325
363
|
// the source it reads, or a new extension when the file has none yet.
|
|
326
364
|
//
|
|
327
365
|
// REORDERING is neither: a tile's position is the `tiles=[…]` array on the
|
|
@@ -334,7 +372,7 @@ function checkShape(
|
|
|
334
372
|
const reordered =
|
|
335
373
|
membershipChanged || tileIdentity(current) !== tileIdentity(next);
|
|
336
374
|
for (const tile of addedTiles) {
|
|
337
|
-
if (tile.declaration.kind !== "reference") {
|
|
375
|
+
if (isQueryTile(tile) && tile.declaration.kind !== "reference") {
|
|
338
376
|
return {
|
|
339
377
|
ok: false,
|
|
340
378
|
reason:
|
|
@@ -345,12 +383,11 @@ function checkShape(
|
|
|
345
383
|
}
|
|
346
384
|
}
|
|
347
385
|
// Sources may only be ADDED, and only for a tile being added on them — the
|
|
348
|
-
// builder never renames or removes an extension,
|
|
349
|
-
//
|
|
350
|
-
// name (or already extends).
|
|
386
|
+
// builder never renames or removes an extension, so a new extension's base
|
|
387
|
+
// has to be a source the file imports by name (or already extends).
|
|
351
388
|
const currentSources = new Map(current.sources.map((s) => [s.name, s]));
|
|
352
389
|
const importedByName = new Set(
|
|
353
|
-
|
|
390
|
+
next.imports.flatMap((i) => (i.kind === "names" ? i.names : [])),
|
|
354
391
|
);
|
|
355
392
|
for (const source of current.sources) importedByName.add(source.base);
|
|
356
393
|
const newSources = next.sources.filter((s) => !currentSources.has(s.name));
|
|
@@ -364,7 +401,7 @@ function checkShape(
|
|
|
364
401
|
}
|
|
365
402
|
}
|
|
366
403
|
for (const source of newSources) {
|
|
367
|
-
if (!addedTiles.some((t) => t.source === source.name)) {
|
|
404
|
+
if (!addedTiles.some((t) => isQueryTile(t) && t.source === source.name)) {
|
|
368
405
|
return {
|
|
369
406
|
ok: false,
|
|
370
407
|
reason: `A new source \`${source.name}\` needs a tile on it.`,
|
|
@@ -375,17 +412,10 @@ function checkShape(
|
|
|
375
412
|
ok: false,
|
|
376
413
|
reason:
|
|
377
414
|
`\`${source.base}\` is not imported by name in this file, so a ` +
|
|
378
|
-
`tile cannot be put on it.
|
|
379
|
-
`import { ${source.base} } from the model first.`,
|
|
415
|
+
`tile cannot be put on it. Add it as a source first.`,
|
|
380
416
|
};
|
|
381
417
|
}
|
|
382
418
|
}
|
|
383
|
-
if (!isSameDocumentExceptTiles(current, next)) {
|
|
384
|
-
return {
|
|
385
|
-
ok: false,
|
|
386
|
-
reason: "The dashboard's imports cannot be changed here.",
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
419
|
return {
|
|
390
420
|
currentKeys,
|
|
391
421
|
nextKeys,
|
|
@@ -397,64 +427,178 @@ function checkShape(
|
|
|
397
427
|
};
|
|
398
428
|
}
|
|
399
429
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
ok: false,
|
|
412
|
-
reason: "Could not find the `## artifact` tag to reorder.",
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
if (hasNonQuotedTiles(lines[artifactAt])) {
|
|
416
|
-
return {
|
|
417
|
-
ok: false,
|
|
418
|
-
reason:
|
|
419
|
-
"The `tiles=[…]` list holds an entry the builder does not model, such as a text tile, and rewriting the list would drop it. Reorder, add and remove tiles in the file's text.",
|
|
420
|
-
};
|
|
430
|
+
/** A text entry's width and row break, which the list entry carries because the block has no tags. */
|
|
431
|
+
const textEntryChanged = (was: TextTile, now: TextTile) =>
|
|
432
|
+
was.colspan !== now.colspan || Boolean(was.break) !== Boolean(now.break);
|
|
433
|
+
|
|
434
|
+
/** `text` with every quoted string blanked to `x`s of the same length, so a scan for syntax cannot land inside one. */
|
|
435
|
+
function maskStrings(text: string): string {
|
|
436
|
+
let out = "";
|
|
437
|
+
for (let i = 0; i < text.length; i++) {
|
|
438
|
+
if (text[i] !== '"') {
|
|
439
|
+
out += text[i];
|
|
440
|
+
continue;
|
|
421
441
|
}
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
442
|
+
const end = endOfString(text, i);
|
|
443
|
+
out += "x".repeat(Math.min(end, text.length - 1) - i + 1);
|
|
444
|
+
i = end;
|
|
445
|
+
}
|
|
446
|
+
return out;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** A `name { kind=text … }` entry with its `colspan` and `break` set as `tile` has them, every other property as written. */
|
|
450
|
+
function textEntry(tile: TextTile, written?: string): string {
|
|
451
|
+
if (written === undefined)
|
|
452
|
+
return `${tile.name} { kind=text${
|
|
453
|
+
tile.colspan === undefined ? "" : ` colspan=${tile.colspan}`
|
|
454
|
+
}${tile.break ? " break" : ""} }`;
|
|
455
|
+
const masked = maskStrings(written);
|
|
456
|
+
const open = masked.indexOf("{");
|
|
457
|
+
const close = masked.lastIndexOf("}");
|
|
458
|
+
let inner = written.slice(open + 1, close);
|
|
459
|
+
let maskedInner = masked.slice(open + 1, close);
|
|
460
|
+
const drop = (re: RegExp) => {
|
|
461
|
+
const hit = re.exec(maskedInner);
|
|
462
|
+
if (!hit) return;
|
|
463
|
+
inner =
|
|
464
|
+
inner.slice(0, hit.index) + inner.slice(hit.index + hit[0].length);
|
|
465
|
+
maskedInner =
|
|
466
|
+
maskedInner.slice(0, hit.index) +
|
|
467
|
+
maskedInner.slice(hit.index + hit[0].length);
|
|
468
|
+
};
|
|
469
|
+
drop(/\s*\bcolspan\s*=\s*[^\s}]+/);
|
|
470
|
+
drop(/\s*\bbreak\b(?!\s*=)/);
|
|
471
|
+
const props = [
|
|
472
|
+
inner.trim(),
|
|
473
|
+
tile.colspan === undefined ? "" : `colspan=${tile.colspan}`,
|
|
474
|
+
tile.break ? "break" : "",
|
|
475
|
+
].filter(Boolean);
|
|
476
|
+
return `${written.slice(0, open)}{ ${props.join(" ")} }${written.slice(close + 1)}`;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function planOrder(ctx: SpliceContext): SpliceFailure | undefined {
|
|
480
|
+
const {
|
|
481
|
+
lines,
|
|
482
|
+
wholeLine,
|
|
483
|
+
current,
|
|
484
|
+
next,
|
|
485
|
+
reordered,
|
|
486
|
+
currentKeys,
|
|
487
|
+
nextKeys,
|
|
488
|
+
edits,
|
|
489
|
+
} = ctx;
|
|
490
|
+
const wasText = new Map(
|
|
491
|
+
current.tiles.filter(isTextTile).map((tile) => [tile.name, tile]),
|
|
492
|
+
);
|
|
493
|
+
const resized = next.tiles.filter(isTextTile).some((tile) => {
|
|
494
|
+
const was = wasText.get(tile.name);
|
|
495
|
+
return was !== undefined && textEntryChanged(was, tile);
|
|
496
|
+
});
|
|
497
|
+
// A reorder, and a text tile's width, are one rewritten array on the
|
|
498
|
+
// `## artifact` line. Each entry is re-emitted AS IT WAS WRITTEN rather than
|
|
499
|
+
// rebuilt from `source` and `name`, so a file that spells a tile
|
|
500
|
+
// `overview->kpis` keeps its spelling and the diff is the change and nothing else.
|
|
501
|
+
if (!reordered && !resized) return undefined;
|
|
502
|
+
const tag = artifactTag(lines);
|
|
503
|
+
if (!tag) {
|
|
504
|
+
return {
|
|
505
|
+
ok: false,
|
|
506
|
+
reason: "Could not find the `## artifact` tag to reorder.",
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
const line = tag.text;
|
|
510
|
+
const list = readTileList(line);
|
|
511
|
+
if (!list) {
|
|
512
|
+
return {
|
|
513
|
+
ok: false,
|
|
514
|
+
reason: "Could not read the `tiles=[…]` list to rewrite it.",
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
if (nextKeys.size === 0 && currentKeys.size > 0) {
|
|
518
|
+
return {
|
|
519
|
+
ok: false,
|
|
520
|
+
reason:
|
|
521
|
+
"A dashboard with no tiles is not served, so the last tile cannot be removed. Add another tile first.",
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
const byKey = new Map<string, string>();
|
|
525
|
+
for (const { text } of list.entries) {
|
|
526
|
+
const quoted = /^"((?:[^"\\]|\\.)+)"$/.exec(text);
|
|
527
|
+
if (quoted) {
|
|
528
|
+
const parts = quoted[1].split("->").map((part) => part.trim());
|
|
529
|
+
if (parts.length === 2) byKey.set(`${parts[0]}->${parts[1]}`, text);
|
|
530
|
+
continue;
|
|
429
531
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
532
|
+
const name = /^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(text)?.[1];
|
|
533
|
+
if (name !== undefined) byKey.set(`text.${name}`, text);
|
|
534
|
+
}
|
|
535
|
+
// An existing tile keeps its spelling; a new one is written canonically.
|
|
536
|
+
const nextEntries = next.tiles.map((tile) => {
|
|
537
|
+
const isNew = !currentKeys.has(tileKey(tile));
|
|
538
|
+
if (isTextTile(tile)) {
|
|
539
|
+
const written = byKey.get(`text.${tile.name}`);
|
|
540
|
+
return written !== undefined
|
|
541
|
+
? wasText.has(tile.name) &&
|
|
542
|
+
!textEntryChanged(wasText.get(tile.name), tile)
|
|
543
|
+
? written
|
|
544
|
+
: textEntry(tile, written)
|
|
545
|
+
: isNew
|
|
546
|
+
? textEntry(tile)
|
|
547
|
+
: undefined;
|
|
444
548
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
const rewritten = lines[artifactAt].replace(
|
|
449
|
-
/tiles\s*=\s*\[[\s\S]*?\]/,
|
|
450
|
-
list,
|
|
549
|
+
return (
|
|
550
|
+
byKey.get(`${tile.source}->${tile.name}`) ??
|
|
551
|
+
(isNew ? `"${tile.source} -> ${tile.name}"` : undefined)
|
|
451
552
|
);
|
|
452
|
-
|
|
453
|
-
|
|
553
|
+
});
|
|
554
|
+
if (nextEntries.some((entry) => entry === undefined)) {
|
|
555
|
+
return {
|
|
556
|
+
ok: false,
|
|
557
|
+
reason:
|
|
558
|
+
"A tile in the new order is not one the `## artifact` tag names.",
|
|
559
|
+
};
|
|
454
560
|
}
|
|
561
|
+
// A `## artifact` line must stay on ONE line or the package fails to
|
|
562
|
+
// compile, so the array is replaced in place rather than reformatted; a
|
|
563
|
+
// `##|` block keeps whatever line layout its array was written in.
|
|
564
|
+
const keyAt = line.slice(0, list.open).search(/tiles\s*=\s*$/);
|
|
565
|
+
const rewritten = `${line.slice(0, keyAt)}tiles=[${arrayBody(line, list, nextEntries)}]${line.slice(list.close + 1)}`;
|
|
566
|
+
if (rewritten !== line)
|
|
567
|
+
edits.push({ ...tagExtent(wholeLine, tag), text: `${rewritten}\n` });
|
|
455
568
|
return undefined;
|
|
456
569
|
}
|
|
457
570
|
|
|
571
|
+
/** The whole lines a tag's text occupies; a block's closer is not part of its text. */
|
|
572
|
+
function tagExtent(
|
|
573
|
+
wholeLine: (line: number) => { start: number; end: number },
|
|
574
|
+
tag: ArtifactTag,
|
|
575
|
+
) {
|
|
576
|
+
return {
|
|
577
|
+
start: wholeLine(tag.from).start,
|
|
578
|
+
end: wholeLine(tag.block ? tag.to - 1 : tag.from).end,
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/** The text between a list's brackets for `entries`, spaced as the list was: a multi-line list keeps its lead, separator and tail. */
|
|
583
|
+
function arrayBody(
|
|
584
|
+
line: string,
|
|
585
|
+
list: NonNullable<ReturnType<typeof readTileList>>,
|
|
586
|
+
entries: string[],
|
|
587
|
+
): string {
|
|
588
|
+
const first = list.entries[0];
|
|
589
|
+
const last = list.entries[list.entries.length - 1];
|
|
590
|
+
if (!first || !/\n/.test(line.slice(list.open, list.close)))
|
|
591
|
+
return entries.join(", ");
|
|
592
|
+
const lead = line.slice(list.open + 1, first.span.start);
|
|
593
|
+
const tail = line.slice(last.span.end, list.close);
|
|
594
|
+
const indent = lead.slice(lead.lastIndexOf("\n"));
|
|
595
|
+
const separator =
|
|
596
|
+
list.entries.length > 1
|
|
597
|
+
? line.slice(first.span.end, list.entries[1].span.start)
|
|
598
|
+
: `,${indent.startsWith("\n") ? indent : " "}`;
|
|
599
|
+
return `${lead}${entries.join(separator)}${tail}`;
|
|
600
|
+
}
|
|
601
|
+
|
|
458
602
|
/**
|
|
459
603
|
* `line` without one property of the artifact tag's own braces: spelled with
|
|
460
604
|
* any spacing round the `=`, and never matched inside a quoted string or a
|
|
@@ -533,32 +677,35 @@ function endOfString(line: string, open: number): number {
|
|
|
533
677
|
function planSettings(ctx: SpliceContext): SpliceFailure | undefined {
|
|
534
678
|
const { lines, wholeLine, current, next, edits } = ctx;
|
|
535
679
|
// THE PAGE'S OWN SETTINGS. Title, autorun and starting values are
|
|
536
|
-
// properties on the
|
|
537
|
-
// `dashboard { columns=N }` beside it; the description is the run of `##"`
|
|
538
|
-
// lines above. Each is patched in place
|
|
539
|
-
//
|
|
680
|
+
// properties on the `## artifact { … }` tag (one line, or a `##|` block);
|
|
681
|
+
// the grid width is the `dashboard { columns=N }` beside it; the description is the run of `##"`
|
|
682
|
+
// lines above. Each is patched in place, so a one-line tag stays one line
|
|
683
|
+
// — the package fails to compile otherwise — and a property
|
|
540
684
|
// the file spells its own way keeps that spelling when it did not change.
|
|
541
685
|
if (
|
|
686
|
+
kindOf(current) !== kindOf(next) ||
|
|
542
687
|
current.title !== next.title ||
|
|
543
688
|
current.autorun !== next.autorun ||
|
|
544
689
|
current.columns !== next.columns ||
|
|
545
690
|
canonical(current.startingGivens) !== canonical(next.startingGivens)
|
|
546
691
|
) {
|
|
547
|
-
const
|
|
548
|
-
if (
|
|
692
|
+
const tag = artifactTag(lines);
|
|
693
|
+
if (!tag) {
|
|
549
694
|
return {
|
|
550
695
|
ok: false,
|
|
551
696
|
reason:
|
|
552
697
|
"Could not find the `## artifact` tag to change the page's settings.",
|
|
553
698
|
};
|
|
554
699
|
}
|
|
555
|
-
|
|
700
|
+
const extent = tagExtent(wholeLine, tag);
|
|
701
|
+
// Whatever the reorder wrote to this tag is the text to patch further.
|
|
556
702
|
const already = edits.find(
|
|
557
|
-
(edit) =>
|
|
558
|
-
edit.start === wholeLine(artifactAt).start &&
|
|
559
|
-
edit.end === wholeLine(artifactAt).end,
|
|
703
|
+
(edit) => edit.start === extent.start && edit.end === extent.end,
|
|
560
704
|
);
|
|
561
|
-
let line = already ? already.text.replace(/\n$/, "") :
|
|
705
|
+
let line = already ? already.text.replace(/\n$/, "") : tag.text;
|
|
706
|
+
// Depth-aware, since a text tile's own `kind=text` sits inside the tag.
|
|
707
|
+
if (kindOf(current) !== kindOf(next))
|
|
708
|
+
line = removeArtifactProperty(line, "kind");
|
|
562
709
|
// The artifact tag's braces: everything up to the matching `}`.
|
|
563
710
|
const open = line.indexOf("artifact");
|
|
564
711
|
const braceOpen = line.indexOf("{", open);
|
|
@@ -578,14 +725,37 @@ function planSettings(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
578
725
|
};
|
|
579
726
|
}
|
|
580
727
|
let inner = line.slice(braceOpen + 1, braceClose);
|
|
728
|
+
// A block puts each property on a line of its own, as its array is.
|
|
729
|
+
const lineBreak = tag.block
|
|
730
|
+
? `\n${/\n([ \t]+)\S/.exec(inner)?.[1] ?? " "}`
|
|
731
|
+
: " ";
|
|
732
|
+
const append = (property: string) =>
|
|
733
|
+
tag.block
|
|
734
|
+
? `${inner.trimEnd()}${lineBreak}${property}\n`
|
|
735
|
+
: `${inner.trimEnd()} ${property} `;
|
|
581
736
|
const setProperty = (key: string, value: string | undefined) => {
|
|
582
737
|
const re = new RegExp(
|
|
583
|
-
|
|
738
|
+
`${tag.block ? "[ \\t]*" : "\\s*"}\\b${key}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`,
|
|
584
739
|
);
|
|
585
|
-
if (value === undefined)
|
|
586
|
-
|
|
587
|
-
|
|
740
|
+
if (value === undefined) {
|
|
741
|
+
const own = new RegExp(`\n${re.source}[ \\t]*(?=\n)`);
|
|
742
|
+
inner = inner.replace(tag.block && own.test(inner) ? own : re, "");
|
|
743
|
+
} else if (re.test(inner))
|
|
744
|
+
inner = inner.replace(
|
|
745
|
+
re,
|
|
746
|
+
(hit) =>
|
|
747
|
+
`${tag.block ? hit.slice(0, hit.length - hit.trimStart().length) : " "}${key}=${value}`,
|
|
748
|
+
);
|
|
749
|
+
else inner = append(`${key}=${value}`);
|
|
588
750
|
};
|
|
751
|
+
if (kindOf(current) !== kindOf(next) && kindOf(next) === "notebook")
|
|
752
|
+
inner = append("kind=notebook");
|
|
753
|
+
// A tag with no kind takes its folder's, and the server's compile of text takes none: a switch that leaves it off lets the two disagree.
|
|
754
|
+
else if (
|
|
755
|
+
kindOf(current) !== kindOf(next) &&
|
|
756
|
+
(ctx.explicitKind || !ctx.modelPath?.startsWith("dashboards/"))
|
|
757
|
+
)
|
|
758
|
+
inner = append("kind=dashboard");
|
|
589
759
|
if (current.title !== next.title)
|
|
590
760
|
setProperty("title", next.title ? quoted(next.title) : undefined);
|
|
591
761
|
if (current.autorun !== next.autorun)
|
|
@@ -602,12 +772,16 @@ function planSettings(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
602
772
|
// string's text — `CATEGORY="Jeans"` reads as `Jeans`, which is
|
|
603
773
|
// what the document holds and what is written back here.
|
|
604
774
|
if (entries.length > 0)
|
|
605
|
-
inner =
|
|
606
|
-
.map(([k, v]) => `${k}=${quoted(v)}`)
|
|
607
|
-
|
|
775
|
+
inner = append(
|
|
776
|
+
`givens { ${entries.map(([k, v]) => `${k}=${quoted(v)}`).join(" ")} }`,
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
if (tag.block) {
|
|
780
|
+
line = `${line.slice(0, braceOpen + 1)}${inner}${line.slice(braceClose)}`;
|
|
781
|
+
} else {
|
|
782
|
+
inner = inner.replace(/\s{2,}/g, " ");
|
|
783
|
+
line = `${line.slice(0, braceOpen + 1)}${inner.startsWith(" ") ? inner : ` ${inner}`}${inner.endsWith(" ") ? "" : " "}${line.slice(braceClose)}`;
|
|
608
784
|
}
|
|
609
|
-
inner = inner.replace(/\s{2,}/g, " ");
|
|
610
|
-
line = `${line.slice(0, braceOpen + 1)}${inner.startsWith(" ") ? inner : ` ${inner}`}${inner.endsWith(" ") ? "" : " "}${line.slice(braceClose)}`;
|
|
611
785
|
if (current.columns !== next.columns) {
|
|
612
786
|
// The deprecated alias would otherwise sit beside the new width and conflict with it.
|
|
613
787
|
line = removeArtifactProperty(line, "dashboard_columns");
|
|
@@ -616,7 +790,7 @@ function planSettings(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
616
790
|
line = `${line.trimEnd()} dashboard { columns=${next.columns} }`;
|
|
617
791
|
}
|
|
618
792
|
if (already) already.text = `${line}\n`;
|
|
619
|
-
else edits.push({ ...
|
|
793
|
+
else edits.push({ ...extent, text: `${line}\n` });
|
|
620
794
|
}
|
|
621
795
|
if (current.description !== next.description) {
|
|
622
796
|
// Written above the tag, where the server reads it. A description read
|
|
@@ -630,7 +804,7 @@ function planSettings(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
630
804
|
"The description is written in a `##|\"` block, which the builder cannot edit in place. Change it in the file's text.",
|
|
631
805
|
};
|
|
632
806
|
}
|
|
633
|
-
const text = (next.description ?? "")
|
|
807
|
+
const text = trimDescription(next.description ?? "")
|
|
634
808
|
.split("\n")
|
|
635
809
|
.map((para) => (para.trim() === "" ? '##"' : `##" ${para.trim()}`))
|
|
636
810
|
.join("\n");
|
|
@@ -824,6 +998,100 @@ function planGivens(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
824
998
|
return undefined;
|
|
825
999
|
}
|
|
826
1000
|
|
|
1001
|
+
/** `import { a, b } from "../model.malloy"`, the one-line spelling the builder writes. */
|
|
1002
|
+
const importStatement = (names: string[], from: string) =>
|
|
1003
|
+
`import { ${names.join(", ")} } from ${quoted(from)}`;
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* IMPORTS. Only a `{ names }` import is the builder's to edit: a name is added
|
|
1007
|
+
* to the statement for its file (or a new statement follows the last import),
|
|
1008
|
+
* a name taken off rewrites it, and the last name takes the statement. A bare
|
|
1009
|
+
* `import "…"` brings in a whole file's declarations and is never touched, and
|
|
1010
|
+
* a name a source or tile still reads cannot go.
|
|
1011
|
+
*/
|
|
1012
|
+
function planImports(ctx: SpliceContext): SpliceFailure | undefined {
|
|
1013
|
+
const { parsed, current, next, edits, wholeLine } = ctx;
|
|
1014
|
+
const bare = (document: DashboardDocument) =>
|
|
1015
|
+
canonical(
|
|
1016
|
+
document.imports
|
|
1017
|
+
.flatMap((i) => (i.kind === "all" ? [i.from] : []))
|
|
1018
|
+
.sort(),
|
|
1019
|
+
);
|
|
1020
|
+
if (bare(current) !== bare(next)) {
|
|
1021
|
+
return {
|
|
1022
|
+
ok: false,
|
|
1023
|
+
reason: "A whole-file `import` cannot be changed here.",
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
if (canonical(current.imports) === canonical(next.imports)) return undefined;
|
|
1027
|
+
|
|
1028
|
+
const wanted = next.imports.flatMap((i) =>
|
|
1029
|
+
i.kind === "names" ? [{ ...i, claimed: false }] : [],
|
|
1030
|
+
);
|
|
1031
|
+
const inUse = new Set([
|
|
1032
|
+
...next.sources.map((s) => s.base),
|
|
1033
|
+
...next.tiles.filter(isQueryTile).map((t) => t.source),
|
|
1034
|
+
]);
|
|
1035
|
+
const written = parsed.imports.map((statement, index) => ({
|
|
1036
|
+
statement,
|
|
1037
|
+
entry: current.imports[index],
|
|
1038
|
+
}));
|
|
1039
|
+
for (const { statement, entry } of written) {
|
|
1040
|
+
if (!entry || entry.kind !== "names") continue;
|
|
1041
|
+
const keep = wanted.find((w) => !w.claimed && w.from === entry.from);
|
|
1042
|
+
if (keep) keep.claimed = true;
|
|
1043
|
+
const names = keep?.names ?? [];
|
|
1044
|
+
const dropped = entry.names.filter((n) => !names.includes(n));
|
|
1045
|
+
const stuck = dropped.find((n) => inUse.has(n));
|
|
1046
|
+
if (stuck !== undefined) {
|
|
1047
|
+
return {
|
|
1048
|
+
ok: false,
|
|
1049
|
+
reason: `\`${stuck}\` is still read by a tile, so its import cannot be removed.`,
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
if (canonical(names) === canonical(entry.names)) continue;
|
|
1053
|
+
const cut =
|
|
1054
|
+
names.length === 0
|
|
1055
|
+
? statementCut(parsed, statement.statement)
|
|
1056
|
+
: statement.statement;
|
|
1057
|
+
const lost = parsed.commentIn(cut);
|
|
1058
|
+
if (lost) {
|
|
1059
|
+
return {
|
|
1060
|
+
ok: false,
|
|
1061
|
+
reason:
|
|
1062
|
+
`Changing this import would also remove the comment inside it ` +
|
|
1063
|
+
`(\`${parsed.text.slice(lost.start, lost.end).trim()}\`), so ` +
|
|
1064
|
+
`nothing was written. Delete it in the file first.`,
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
edits.push({
|
|
1068
|
+
...cut,
|
|
1069
|
+
text: names.length === 0 ? "" : importStatement(names, entry.from),
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
const added = wanted.filter((w) => !w.claimed);
|
|
1074
|
+
if (added.length > 0) {
|
|
1075
|
+
const last = parsed.imports.at(-1);
|
|
1076
|
+
if (!last) {
|
|
1077
|
+
return {
|
|
1078
|
+
ok: false,
|
|
1079
|
+
reason:
|
|
1080
|
+
"This file has no `import` to put a source beside. Import its first source in the file.",
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
const at = wholeLine(lineOf(parsed, last.statement.end - 1)).end;
|
|
1084
|
+
edits.push({
|
|
1085
|
+
start: at,
|
|
1086
|
+
end: at,
|
|
1087
|
+
text: added
|
|
1088
|
+
.map((w) => `${importStatement(w.names, w.from)}\n`)
|
|
1089
|
+
.join(""),
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
return undefined;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
827
1095
|
function planDrills(ctx: SpliceContext): SpliceFailure | undefined {
|
|
828
1096
|
const { lines, wholeLine, indentOf, current, next, edits, parsed } = ctx;
|
|
829
1097
|
// DRILLS. A drill is one `# drill` tag on a dimension THIS FILE declares —
|
|
@@ -888,7 +1156,7 @@ function planRemovedTiles(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
888
1156
|
// runs to its closing brace; a reference is one line. An inherited tile has
|
|
889
1157
|
// nothing here to remove — its entry left the artifact list above.
|
|
890
1158
|
for (const tile of removedTiles) {
|
|
891
|
-
if (tile.declaration.kind === "inherited") continue;
|
|
1159
|
+
if (isTextTile(tile) || tile.declaration.kind === "inherited") continue;
|
|
892
1160
|
const view = viewOf(ctx, tile);
|
|
893
1161
|
if (!view) {
|
|
894
1162
|
return {
|
|
@@ -961,19 +1229,20 @@ function planAddedTiles(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
961
1229
|
// ADDED TILES: a `view:` with its tags, inside the extension of the source
|
|
962
1230
|
// the tile reads — before that extension's closing brace — or in a new
|
|
963
1231
|
// extension after the last one, when the file has none for that source.
|
|
964
|
-
const byExtension = new Map<string,
|
|
1232
|
+
const byExtension = new Map<string, QueryTile[]>();
|
|
965
1233
|
for (const tile of addedTiles) {
|
|
1234
|
+
if (isTextTile(tile)) continue;
|
|
966
1235
|
const list = byExtension.get(tile.source) ?? [];
|
|
967
1236
|
list.push(tile);
|
|
968
1237
|
byExtension.set(tile.source, list);
|
|
969
1238
|
}
|
|
970
|
-
const declarationOf = (tile:
|
|
1239
|
+
const declarationOf = (tile: QueryTile, indent: string) => {
|
|
971
1240
|
const from =
|
|
972
1241
|
tile.declaration.kind === "reference"
|
|
973
1242
|
? tile.declaration.from
|
|
974
1243
|
: tile.name;
|
|
975
1244
|
const bindings = (tile.filters ?? [])
|
|
976
|
-
.map((f) => `where: ${f.field} ${f.op ?? "~"} $${f.given}`)
|
|
1245
|
+
.map((f) => `where: ${malloyPath(f.field)} ${f.op ?? "~"} $${f.given}`)
|
|
977
1246
|
.join(", ");
|
|
978
1247
|
return [
|
|
979
1248
|
...tagsFor(tile).map((tag) => `${indent}${tag}`),
|
|
@@ -1074,9 +1343,13 @@ function planTilePresentation(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
1074
1343
|
|
|
1075
1344
|
for (const tile of next.tiles) {
|
|
1076
1345
|
const was = currentByKey.get(tileKey(tile));
|
|
1077
|
-
// Written whole above, tags and all.
|
|
1078
|
-
if (was === undefined) continue;
|
|
1079
|
-
if (
|
|
1346
|
+
// Written whole above, tags and all; a text tile has no declaration to retag.
|
|
1347
|
+
if (was === undefined || isTextTile(tile) || isTextTile(was)) continue;
|
|
1348
|
+
if (
|
|
1349
|
+
canonical(withoutDefaultChart(was)) ===
|
|
1350
|
+
canonical(withoutDefaultChart(tile))
|
|
1351
|
+
)
|
|
1352
|
+
continue;
|
|
1080
1353
|
|
|
1081
1354
|
// Declared in the model, not here, so there is nothing in this file to
|
|
1082
1355
|
// patch -- saying so beats writing a tag that would land on the wrong
|
|
@@ -1106,15 +1379,55 @@ function planTilePresentation(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
1106
1379
|
|
|
1107
1380
|
const { tags } = blockAbove(parsed, lines, declLine);
|
|
1108
1381
|
const indent = indentOf(declLine);
|
|
1109
|
-
const wanted = tagsFor(tile);
|
|
1382
|
+
const wanted = tagsFor(tile, false);
|
|
1110
1383
|
const wantedByKey = new Map(
|
|
1111
1384
|
wanted.map((text) => [tagKey(text) ?? text, text]),
|
|
1112
1385
|
);
|
|
1113
1386
|
const seen = new Set<string>();
|
|
1114
1387
|
|
|
1388
|
+
// Only a changed chart touches a chart line, so a bare `# bar_chart` survives every other edit.
|
|
1389
|
+
const wantChart = writableChart(tile.chart);
|
|
1390
|
+
const chartChanged = chartOf(was) !== chartOf(tile);
|
|
1391
|
+
if (chartChanged) {
|
|
1392
|
+
const blockers = tags.filter((tag) => mentionsChartTag(tag.text));
|
|
1393
|
+
const ours = tags.filter((tag) => parseChartLine(tag.text));
|
|
1394
|
+
const stuck =
|
|
1395
|
+
was.chart === "custom"
|
|
1396
|
+
? tags.filter(
|
|
1397
|
+
(tag) =>
|
|
1398
|
+
parseChartLine(tag.text) || mentionsChartTag(tag.text),
|
|
1399
|
+
)
|
|
1400
|
+
: blockers.length > 0
|
|
1401
|
+
? blockers
|
|
1402
|
+
: ours.length > 1
|
|
1403
|
+
? ours
|
|
1404
|
+
: [];
|
|
1405
|
+
if (stuck.length > 0) {
|
|
1406
|
+
return {
|
|
1407
|
+
ok: false,
|
|
1408
|
+
reason:
|
|
1409
|
+
`\`${tile.source} -> ${tile.name}\` has a chart line the builder does not ` +
|
|
1410
|
+
`model (${stuck.map((tag) => tag.text).join(" and ")}), so its chart ` +
|
|
1411
|
+
`cannot be changed here.`,
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
let chartPlaced = false;
|
|
1416
|
+
|
|
1115
1417
|
// Existing tag lines are patched or removed IN PLACE, so anything else in
|
|
1116
1418
|
// the block — a comment explaining the tile — keeps its position.
|
|
1117
1419
|
for (const tag of tags) {
|
|
1420
|
+
if (chartChanged && parseChartLine(tag.text)) {
|
|
1421
|
+
if (wantChart === undefined)
|
|
1422
|
+
edits.push({ ...wholeLine(tag.line), text: "" });
|
|
1423
|
+
else if (tag.text !== chartLineText(wantChart, tile.chartCarried))
|
|
1424
|
+
edits.push({
|
|
1425
|
+
...wholeLine(tag.line),
|
|
1426
|
+
text: `${indent}${chartLineText(wantChart, tile.chartCarried)}\n`,
|
|
1427
|
+
});
|
|
1428
|
+
chartPlaced = true;
|
|
1429
|
+
continue;
|
|
1430
|
+
}
|
|
1118
1431
|
const key = tagKey(tag.text);
|
|
1119
1432
|
// Not a property this document models: not ours to touch.
|
|
1120
1433
|
if (key === undefined || !MODELLED_TAG_KEYS.has(key)) continue;
|
|
@@ -1132,6 +1445,8 @@ function planTilePresentation(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
1132
1445
|
// New tags go immediately above the declaration, which is where a reader
|
|
1133
1446
|
// looks for them and where `blockAbove` will find them again.
|
|
1134
1447
|
const added = wanted.filter((text) => !seen.has(tagKey(text) ?? text));
|
|
1448
|
+
if (chartChanged && wantChart !== undefined && !chartPlaced)
|
|
1449
|
+
added.push(chartLineText(wantChart, tile.chartCarried));
|
|
1135
1450
|
if (added.length > 0) {
|
|
1136
1451
|
const at = starts[declLine];
|
|
1137
1452
|
edits.push({
|
|
@@ -1174,12 +1489,293 @@ function planTilePresentation(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
1174
1489
|
return undefined;
|
|
1175
1490
|
}
|
|
1176
1491
|
|
|
1492
|
+
/** A tile's chart as the writer compares it: no line (absent or `default`) is one state. */
|
|
1493
|
+
const chartOf = (tile: QueryTile) =>
|
|
1494
|
+
tile.chart === "default" ? undefined : tile.chart;
|
|
1495
|
+
|
|
1496
|
+
/** The tile as the writer compares it: "default" is no line, and `chartLines` and `chartCarried` are not part of what is asked for. */
|
|
1497
|
+
const withoutDefaultChart = (tile: QueryTile): QueryTile => {
|
|
1498
|
+
const { chartLines: _lines, chartCarried: _carried, ...rest } = tile;
|
|
1499
|
+
if (rest.chart !== "default") return rest;
|
|
1500
|
+
const { chart: _chart, ...bare } = rest;
|
|
1501
|
+
return bare;
|
|
1502
|
+
};
|
|
1503
|
+
|
|
1504
|
+
/** A matched tile with no `chart` stated is unchanged, so only an explicit "default" removes a line. */
|
|
1505
|
+
function keepUnstatedCharts(
|
|
1506
|
+
current: DashboardDocument,
|
|
1507
|
+
next: DashboardDocument,
|
|
1508
|
+
): DashboardDocument {
|
|
1509
|
+
const was = new Map(current.tiles.map((t) => [tileKey(t), t]));
|
|
1510
|
+
return {
|
|
1511
|
+
...next,
|
|
1512
|
+
tiles: next.tiles.map((tile) => {
|
|
1513
|
+
const before = was.get(tileKey(tile));
|
|
1514
|
+
return isQueryTile(tile) &&
|
|
1515
|
+
tile.chart === undefined &&
|
|
1516
|
+
before &&
|
|
1517
|
+
isQueryTile(before) &&
|
|
1518
|
+
before.chart !== undefined
|
|
1519
|
+
? { ...tile, chart: before.chart }
|
|
1520
|
+
: tile;
|
|
1521
|
+
}),
|
|
1522
|
+
};
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
/** Why a text tile's markdown cannot be written into a block, or undefined when it can: the writer's refusals, for an editor to show live. */
|
|
1526
|
+
export function markdownProblem(markdown: string): string | undefined {
|
|
1527
|
+
if (markdown.includes("\r"))
|
|
1528
|
+
return "Text uses plain line breaks; a carriage return cannot be written.";
|
|
1529
|
+
if (/^\|##/m.test(markdown))
|
|
1530
|
+
return "A line starting with `|##` would close the text early. Indent that line or reword it.";
|
|
1531
|
+
return undefined;
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
/** Why `tile` cannot be written, or undefined; only what changed from `before` is judged, so an existing odd value does not block unrelated edits. */
|
|
1535
|
+
function textTileProblem(
|
|
1536
|
+
tile: TextTile,
|
|
1537
|
+
before: TextTile | undefined,
|
|
1538
|
+
seen: Set<string>,
|
|
1539
|
+
): string | undefined {
|
|
1540
|
+
if (seen.has(tile.name))
|
|
1541
|
+
return `Two text tiles are named \`${tile.name}\`, so they could not be told apart.`;
|
|
1542
|
+
seen.add(tile.name);
|
|
1543
|
+
if (before === undefined && !isIdentifier(tile.name))
|
|
1544
|
+
return `The text tile name ${JSON.stringify(tile.name)} must be a bare word.`;
|
|
1545
|
+
if (before === undefined || tile.markdown !== before.markdown) {
|
|
1546
|
+
const problem = markdownProblem(tile.markdown);
|
|
1547
|
+
if (problem) return problem;
|
|
1548
|
+
}
|
|
1549
|
+
if (
|
|
1550
|
+
tile.colspan !== undefined &&
|
|
1551
|
+
tile.colspan !== before?.colspan &&
|
|
1552
|
+
!(Number.isInteger(tile.colspan) && tile.colspan >= 1)
|
|
1553
|
+
)
|
|
1554
|
+
return "A text tile's width is a whole number of columns, 1 or more.";
|
|
1555
|
+
return undefined;
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
/** The block a text tile's prose is written in. */
|
|
1559
|
+
const textBlockText = (tile: TextTile) =>
|
|
1560
|
+
`##|(markdown) ${tile.name}\n${tile.markdown === "" ? "" : `${tile.markdown}\n`}|##\n`;
|
|
1561
|
+
|
|
1562
|
+
function planTextBlocks(ctx: SpliceContext): SpliceFailure | undefined {
|
|
1563
|
+
const { sourceText, lines, wholeLine, current, next, parsed, edits } = ctx;
|
|
1564
|
+
// TEXT TILES: the `##|(markdown) name` block is the tile's body, so adding
|
|
1565
|
+
// one writes a block, editing one replaces its block, and removing one takes
|
|
1566
|
+
// the block out; the `tiles=[…]` entry was already handled with the order.
|
|
1567
|
+
const wasText = new Map(
|
|
1568
|
+
current.tiles.filter(isTextTile).map((tile) => [tile.name, tile]),
|
|
1569
|
+
);
|
|
1570
|
+
const nowText = next.tiles.filter(isTextTile);
|
|
1571
|
+
const blockOf = (name: string) =>
|
|
1572
|
+
parsed.textBlocks.find((block) => block.name === name);
|
|
1573
|
+
const nowNames = new Set(nowText.map((tile) => tile.name));
|
|
1574
|
+
|
|
1575
|
+
for (const name of wasText.keys()) {
|
|
1576
|
+
const block = nowNames.has(name) ? undefined : blockOf(name);
|
|
1577
|
+
if (!block) continue;
|
|
1578
|
+
const last = lineOf(parsed, block.span.end - 1);
|
|
1579
|
+
edits.push({ ...block.span, text: "" });
|
|
1580
|
+
const after = wholeLine(last + 1);
|
|
1581
|
+
const blankBefore =
|
|
1582
|
+
block.line === 0 || lines[block.line - 1].trim() === "";
|
|
1583
|
+
// The blank line after goes too when one already precedes, or two separators meet.
|
|
1584
|
+
if (
|
|
1585
|
+
after.end > after.start &&
|
|
1586
|
+
lines[last + 1].trim() === "" &&
|
|
1587
|
+
blankBefore
|
|
1588
|
+
)
|
|
1589
|
+
edits.push({ ...after, text: "" });
|
|
1590
|
+
// A last block takes the blank line that set it off.
|
|
1591
|
+
else if (
|
|
1592
|
+
block.line > 0 &&
|
|
1593
|
+
blankBefore &&
|
|
1594
|
+
sourceText.slice(block.span.end).trim() === ""
|
|
1595
|
+
)
|
|
1596
|
+
edits.push({ ...wholeLine(block.line - 1), text: "" });
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
const fresh: string[] = [];
|
|
1600
|
+
for (const tile of nowText) {
|
|
1601
|
+
const was = wasText.get(tile.name);
|
|
1602
|
+
const block = blockOf(tile.name);
|
|
1603
|
+
if (was === undefined) {
|
|
1604
|
+
if (block) {
|
|
1605
|
+
return {
|
|
1606
|
+
ok: false,
|
|
1607
|
+
reason: `A block named \`${tile.name}\` is already in this file, so a new text tile cannot take that name.`,
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
fresh.push(textBlockText(tile));
|
|
1611
|
+
} else if (was.markdown !== tile.markdown) {
|
|
1612
|
+
if (block) edits.push({ ...block.span, text: textBlockText(tile) });
|
|
1613
|
+
else fresh.push(textBlockText(tile));
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
if (fresh.length > 0) {
|
|
1617
|
+
// Prose blocks group together ahead of the `<source>_tiles` extension, in tile order.
|
|
1618
|
+
const kept = parsed.textBlocks.filter(
|
|
1619
|
+
(block) => block.name === undefined || nowNames.has(block.name),
|
|
1620
|
+
);
|
|
1621
|
+
const lastKept = kept[kept.length - 1];
|
|
1622
|
+
const extension = parsed.sources.find((s) => s.name.endsWith("_tiles"));
|
|
1623
|
+
if (lastKept) {
|
|
1624
|
+
const at = lastKept.span.end;
|
|
1625
|
+
const after = sourceText.slice(at);
|
|
1626
|
+
edits.push({
|
|
1627
|
+
start: at,
|
|
1628
|
+
end: at,
|
|
1629
|
+
text: `\n${fresh.join("\n")}${after === "" || after.startsWith("\n") ? "" : "\n"}`,
|
|
1630
|
+
});
|
|
1631
|
+
return undefined;
|
|
1632
|
+
}
|
|
1633
|
+
if (extension) {
|
|
1634
|
+
const at = ctx.starts[parsed.blockStart(extension.line)];
|
|
1635
|
+
const blankBefore =
|
|
1636
|
+
at === 0 || sourceText.slice(0, at).endsWith("\n\n");
|
|
1637
|
+
edits.push({
|
|
1638
|
+
start: at,
|
|
1639
|
+
end: at,
|
|
1640
|
+
text: `${blankBefore ? "" : "\n"}${fresh.join("\n")}\n`,
|
|
1641
|
+
});
|
|
1642
|
+
return undefined;
|
|
1643
|
+
}
|
|
1644
|
+
const at = sourceText.length;
|
|
1645
|
+
const lead =
|
|
1646
|
+
sourceText === "" || sourceText.endsWith("\n\n")
|
|
1647
|
+
? ""
|
|
1648
|
+
: sourceText.endsWith("\n")
|
|
1649
|
+
? "\n"
|
|
1650
|
+
: "\n\n";
|
|
1651
|
+
edits.push({ start: at, end: at, text: lead + fresh.join("\n") });
|
|
1652
|
+
}
|
|
1653
|
+
return undefined;
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
/** A name the writer emits unquoted, or why it cannot be written. */
|
|
1657
|
+
const nameProblem = (name: string, bare = isBareName) =>
|
|
1658
|
+
bare(name)
|
|
1659
|
+
? undefined
|
|
1660
|
+
: `The name ${JSON.stringify(name)} cannot be written as a Malloy name.`;
|
|
1661
|
+
|
|
1662
|
+
/** Why `next` holds a chart, name or annotation text the writer must not emit; only what changed is judged, so an existing odd string does not block unrelated edits. */
|
|
1663
|
+
function unwritable(
|
|
1664
|
+
current: DashboardDocument,
|
|
1665
|
+
next: DashboardDocument,
|
|
1666
|
+
): string | undefined {
|
|
1667
|
+
const was = new Map(current.tiles.map((t) => [tileKey(t), t]));
|
|
1668
|
+
if (
|
|
1669
|
+
kindOf(next) === "notebook" &&
|
|
1670
|
+
next.columns !== undefined &&
|
|
1671
|
+
(kindOf(current) !== "notebook" || next.columns !== current.columns)
|
|
1672
|
+
)
|
|
1673
|
+
return "A notebook is one column, so its width is not written. Clear the width when switching a dashboard to a notebook.";
|
|
1674
|
+
const textNames = new Set<string>();
|
|
1675
|
+
for (const tile of next.tiles) {
|
|
1676
|
+
const before = was.get(tileKey(tile));
|
|
1677
|
+
if (isTextTile(tile)) {
|
|
1678
|
+
const problem = textTileProblem(
|
|
1679
|
+
tile,
|
|
1680
|
+
before && isTextTile(before) ? before : undefined,
|
|
1681
|
+
textNames,
|
|
1682
|
+
);
|
|
1683
|
+
if (problem) return problem;
|
|
1684
|
+
continue;
|
|
1685
|
+
}
|
|
1686
|
+
const prior = before && isQueryTile(before) ? before : undefined;
|
|
1687
|
+
if (before && !prior) continue;
|
|
1688
|
+
const chart = tile.chart;
|
|
1689
|
+
if (
|
|
1690
|
+
chart !== undefined &&
|
|
1691
|
+
chart !== "default" &&
|
|
1692
|
+
chart !== "none" &&
|
|
1693
|
+
!isChartPick(chart) &&
|
|
1694
|
+
!(chart === "custom" && prior?.chart === "custom")
|
|
1695
|
+
)
|
|
1696
|
+
return `"${String(chart)}" is not a chart this editor writes.`;
|
|
1697
|
+
const filtersBefore = new Set(prior?.filters?.map((f) => f.field));
|
|
1698
|
+
for (const f of tile.filters ?? []) {
|
|
1699
|
+
if (!filtersBefore.has(f.field) && /[\r\n]/.test(f.field))
|
|
1700
|
+
return "A filter field is one line.";
|
|
1701
|
+
}
|
|
1702
|
+
if (before === undefined) {
|
|
1703
|
+
const names = [tile.name, tile.source];
|
|
1704
|
+
if (tile.declaration.kind === "reference")
|
|
1705
|
+
names.push(tile.declaration.from);
|
|
1706
|
+
for (const name of names) {
|
|
1707
|
+
const problem = nameProblem(name);
|
|
1708
|
+
if (problem) return problem;
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
for (const key of ["label", "subtitle"] as const) {
|
|
1712
|
+
const text = tile[key];
|
|
1713
|
+
if (text === undefined || text === prior?.[key]) continue;
|
|
1714
|
+
const problem = annotationTextProblem(`tile ${key}`, text);
|
|
1715
|
+
if (problem) return problem;
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
const knownSources = new Set(current.sources.map((s) => s.name));
|
|
1719
|
+
for (const source of next.sources) {
|
|
1720
|
+
if (knownSources.has(source.name)) continue;
|
|
1721
|
+
for (const name of [source.name, source.base]) {
|
|
1722
|
+
const problem = nameProblem(name);
|
|
1723
|
+
if (problem) return problem;
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
if (next.description !== current.description) {
|
|
1727
|
+
for (const line of (next.description ?? "").split(/\r?\n/)) {
|
|
1728
|
+
const problem = annotationTextProblem("description line", line);
|
|
1729
|
+
if (problem) return problem;
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
if (next.title !== current.title) {
|
|
1733
|
+
const problem = annotationTextProblem("title", next.title);
|
|
1734
|
+
if (problem) return problem;
|
|
1735
|
+
}
|
|
1736
|
+
const givens = new Map((current.localGivens ?? []).map((g) => [g.name, g]));
|
|
1737
|
+
for (const given of next.localGivens ?? []) {
|
|
1738
|
+
const was = givens.get(given.name);
|
|
1739
|
+
if (was === undefined) {
|
|
1740
|
+
const problem = nameProblem(given.name, isStrictName);
|
|
1741
|
+
if (problem) return problem;
|
|
1742
|
+
}
|
|
1743
|
+
const source = given.suggest?.source;
|
|
1744
|
+
if (source !== undefined && source !== was?.suggest?.source) {
|
|
1745
|
+
const problem = nameProblem(source);
|
|
1746
|
+
if (problem) return `The suggest source is not a name. ${problem}`;
|
|
1747
|
+
}
|
|
1748
|
+
for (const key of ["query", "dimension"] as const) {
|
|
1749
|
+
const text = given.suggest?.[key];
|
|
1750
|
+
if (text === undefined || text === was?.suggest?.[key]) continue;
|
|
1751
|
+
const problem = annotationTextProblem(`suggest ${key}`, text);
|
|
1752
|
+
if (problem) return problem;
|
|
1753
|
+
}
|
|
1754
|
+
for (const key of ["label", "description"] as const) {
|
|
1755
|
+
const text = given[key];
|
|
1756
|
+
if (text === undefined || text === givens.get(given.name)?.[key])
|
|
1757
|
+
continue;
|
|
1758
|
+
const problem = annotationTextProblem(`given ${key}`, text);
|
|
1759
|
+
if (problem) return problem;
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
for (const [name, value] of Object.entries(next.startingGivens ?? {})) {
|
|
1763
|
+
if (value === current.startingGivens?.[name]) continue;
|
|
1764
|
+
const problem = annotationTextProblem(
|
|
1765
|
+
`starting value for ${name}`,
|
|
1766
|
+
value,
|
|
1767
|
+
);
|
|
1768
|
+
if (problem) return problem;
|
|
1769
|
+
}
|
|
1770
|
+
return undefined;
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1177
1773
|
/** The 0-based line an offset falls on. */
|
|
1178
1774
|
const lineOf = (parsed: ParsedMalloy, offset: number): number =>
|
|
1179
1775
|
parsed.lineStarts.findLastIndex((at) => at <= offset);
|
|
1180
1776
|
|
|
1181
1777
|
/** The parsed declaration a tile names, if this file declares it. */
|
|
1182
|
-
function viewOf(ctx: SpliceContext, tile:
|
|
1778
|
+
function viewOf(ctx: SpliceContext, tile: QueryTile): TreeView | undefined {
|
|
1183
1779
|
return ctx.parsed.sources
|
|
1184
1780
|
.find((source) => source.name === tile.source)
|
|
1185
1781
|
?.views.find((view) => view.name === tile.name);
|
|
@@ -1218,7 +1814,7 @@ function collisionRefusal(tileName: string, given: string): SpliceFailure {
|
|
|
1218
1814
|
}
|
|
1219
1815
|
|
|
1220
1816
|
const bindingText = (f: { field: string; given: string; op?: string }) =>
|
|
1221
|
-
`where: ${f.field} ${f.op ?? "~"} $${f.given}`;
|
|
1817
|
+
`where: ${malloyPath(f.field)} ${f.op ?? "~"} $${f.given}`;
|
|
1222
1818
|
|
|
1223
1819
|
/**
|
|
1224
1820
|
* THE RULE the three removal paths obey: a comment goes only with a
|
|
@@ -1228,8 +1824,7 @@ const bindingText = (f: { field: string; given: string; op?: string }) =>
|
|
|
1228
1824
|
* is nobody's to strand either. Both refuse, and say which comment.
|
|
1229
1825
|
*
|
|
1230
1826
|
* Removing a TILE is the other case, and the one exception: the declaration
|
|
1231
|
-
* itself is what was asked for, so its own comments go with it
|
|
1232
|
-
* shows that diff before a structural save.
|
|
1827
|
+
* itself is what was asked for, so its own comments go with it.
|
|
1233
1828
|
*/
|
|
1234
1829
|
function commentRefusal(
|
|
1235
1830
|
tileName: string,
|
|
@@ -1330,7 +1925,7 @@ function statementCut(parsed: ParsedMalloy, span: Span): Span {
|
|
|
1330
1925
|
*/
|
|
1331
1926
|
function planStageFilters(
|
|
1332
1927
|
ctx: SpliceContext,
|
|
1333
|
-
tile:
|
|
1928
|
+
tile: QueryTile,
|
|
1334
1929
|
stage: TreeStage,
|
|
1335
1930
|
): SpliceFailure | undefined {
|
|
1336
1931
|
const { parsed, edits } = ctx;
|
|
@@ -1421,7 +2016,7 @@ function planStageFilters(
|
|
|
1421
2016
|
*/
|
|
1422
2017
|
function planReferenceFilters(
|
|
1423
2018
|
ctx: SpliceContext,
|
|
1424
|
-
tile:
|
|
2019
|
+
tile: QueryTile,
|
|
1425
2020
|
view: TreeView,
|
|
1426
2021
|
): SpliceFailure | undefined {
|
|
1427
2022
|
if (view.body.kind !== "reference") return undefined;
|
|
@@ -1472,11 +2067,39 @@ function planReferenceFilters(
|
|
|
1472
2067
|
return planStageFilters(ctx, tile, refinement);
|
|
1473
2068
|
}
|
|
1474
2069
|
|
|
2070
|
+
export interface SpliceOptions {
|
|
2071
|
+
/** Lets `requested.kind` differ from the file's: the one edit that switches a dashboard to a notebook or back. */
|
|
2072
|
+
changeKind?: boolean;
|
|
2073
|
+
/** The file's path within the package; a dashboard under `notebooks/` is tagged `kind=dashboard` rather than left untagged. */
|
|
2074
|
+
modelPath?: string;
|
|
2075
|
+
/** Write `kind=dashboard` too, whatever the folder: for a document held as text, which the server reads by its tags and not by a folder. */
|
|
2076
|
+
explicitKind?: boolean;
|
|
2077
|
+
}
|
|
2078
|
+
|
|
1475
2079
|
export async function spliceDashboardDocument(
|
|
1476
2080
|
sourceText: string,
|
|
1477
|
-
|
|
2081
|
+
requested: DashboardDocument,
|
|
2082
|
+
options: SpliceOptions = {},
|
|
2083
|
+
): Promise<SpliceResult> {
|
|
2084
|
+
// The planners split and join on `\n`, so a wholly CRLF file is edited as LF and written back as CRLF.
|
|
2085
|
+
const crlf = sourceText.includes("\r\n") && !/(?<!\r)\n/.test(sourceText);
|
|
2086
|
+
if (!crlf) return spliceLines(sourceText, requested, options);
|
|
2087
|
+
const result = await spliceLines(
|
|
2088
|
+
sourceText.replace(/\r\n/g, "\n"),
|
|
2089
|
+
requested,
|
|
2090
|
+
options,
|
|
2091
|
+
);
|
|
2092
|
+
return spliceFailed(result)
|
|
2093
|
+
? result
|
|
2094
|
+
: { ...result, source: result.source.replace(/\n/g, "\r\n") };
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
async function spliceLines(
|
|
2098
|
+
sourceText: string,
|
|
2099
|
+
requested: DashboardDocument,
|
|
2100
|
+
options: SpliceOptions,
|
|
1478
2101
|
): Promise<SpliceResult> {
|
|
1479
|
-
const before = await readDashboardDocument(sourceText);
|
|
2102
|
+
const before = await readDashboardDocument(sourceText, options.modelPath);
|
|
1480
2103
|
if (readFailed(before)) {
|
|
1481
2104
|
return {
|
|
1482
2105
|
ok: false,
|
|
@@ -1484,8 +2107,11 @@ export async function spliceDashboardDocument(
|
|
|
1484
2107
|
};
|
|
1485
2108
|
}
|
|
1486
2109
|
const current = before.document;
|
|
1487
|
-
const
|
|
2110
|
+
const next = keepUnstatedCharts(current, requested);
|
|
2111
|
+
const shape = checkShape(current, next, options.changeKind === true);
|
|
1488
2112
|
if ("reason" in shape) return shape;
|
|
2113
|
+
const problem = unwritable(current, next);
|
|
2114
|
+
if (problem) return { ok: false, reason: problem };
|
|
1489
2115
|
|
|
1490
2116
|
const parse = await parseMalloy(sourceText);
|
|
1491
2117
|
if (parseRefused(parse))
|
|
@@ -1514,6 +2140,10 @@ export async function spliceDashboardDocument(
|
|
|
1514
2140
|
current,
|
|
1515
2141
|
next,
|
|
1516
2142
|
edits,
|
|
2143
|
+
...(options.modelPath !== undefined
|
|
2144
|
+
? { modelPath: options.modelPath }
|
|
2145
|
+
: {}),
|
|
2146
|
+
...(options.explicitKind ? { explicitKind: true } : {}),
|
|
1517
2147
|
};
|
|
1518
2148
|
|
|
1519
2149
|
// Each concern plans its own edits against the file as it stands; the
|
|
@@ -1522,11 +2152,13 @@ export async function spliceDashboardDocument(
|
|
|
1522
2152
|
for (const plan of [
|
|
1523
2153
|
planOrder,
|
|
1524
2154
|
planSettings,
|
|
2155
|
+
planImports,
|
|
1525
2156
|
planGivens,
|
|
1526
2157
|
planDrills,
|
|
1527
2158
|
planRemovedTiles,
|
|
1528
2159
|
planAddedTiles,
|
|
1529
2160
|
planTilePresentation,
|
|
2161
|
+
planTextBlocks,
|
|
1530
2162
|
]) {
|
|
1531
2163
|
const failure = plan(ctx);
|
|
1532
2164
|
if (failure) return failure;
|
|
@@ -1540,14 +2172,19 @@ export async function spliceDashboardDocument(
|
|
|
1540
2172
|
// normalises its shape asks for no change, gets no edits, and would be told
|
|
1541
2173
|
// its save did not produce what it asked for.
|
|
1542
2174
|
const comparable = (document: DashboardDocument): DashboardDocument => {
|
|
1543
|
-
const { drills, localGivens, ...rest } = document;
|
|
2175
|
+
const { drills, localGivens, kind, description, ...rest } = document;
|
|
1544
2176
|
const tiles = document.tiles.map((tile) => {
|
|
1545
|
-
if (tile
|
|
2177
|
+
if (isTextTile(tile)) return tile;
|
|
2178
|
+
if (tile.filters?.length) return withoutDefaultChart(tile);
|
|
1546
2179
|
const { filters: _filters, ...tileRest } = tile;
|
|
1547
|
-
return tileRest as
|
|
2180
|
+
return withoutDefaultChart(tileRest as QueryTile);
|
|
1548
2181
|
});
|
|
1549
2182
|
return {
|
|
1550
2183
|
...rest,
|
|
2184
|
+
...(description === undefined
|
|
2185
|
+
? {}
|
|
2186
|
+
: { description: trimDescription(description) }),
|
|
2187
|
+
...(kind === "notebook" ? { kind } : {}),
|
|
1551
2188
|
tiles,
|
|
1552
2189
|
...(drills?.length
|
|
1553
2190
|
? {
|
|
@@ -1608,7 +2245,7 @@ export async function spliceDashboardDocument(
|
|
|
1608
2245
|
// The second gate. Read back what was actually written and compare it
|
|
1609
2246
|
// against what was asked for. Comments survived because they were never
|
|
1610
2247
|
// rewritten; correctness is established here rather than assumed.
|
|
1611
|
-
const after = await readDashboardDocument(spliced);
|
|
2248
|
+
const after = await readDashboardDocument(spliced, options.modelPath);
|
|
1612
2249
|
if (readFailed(after)) {
|
|
1613
2250
|
return {
|
|
1614
2251
|
ok: false,
|