@malloy-publisher/sdk 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{RenderedResult-CBLHr32C.es.js → RenderedResult-DwB0-9Yx.es.js} +118 -119
- package/dist/{RenderedResult-B48wAjM8.cjs.js → RenderedResult-hKjFEqaN.cjs.js} +2 -2
- package/dist/{ServerProvider-DCV8BUWD.es.js → ServerProvider-CcSrGaRN.es.js} +1281 -1142
- package/dist/ServerProvider-Gbf1YPOP.cjs.js +1 -0
- package/dist/builder/index.cjs.js +112 -115
- package/dist/builder/index.es.js +11766 -11502
- package/dist/builder-entry.d.ts +1 -1
- package/dist/client/api.d.ts +170 -9
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +93 -89
- package/dist/client-entry.d.ts +2 -0
- package/dist/components/ApiErrorDisplay.d.ts +11 -0
- package/dist/components/AppDialog.d.ts +6 -6
- package/dist/components/Dashboard/DashboardGrid.d.ts +18 -3
- package/dist/components/Dashboard/DashboardTile.d.ts +12 -2
- package/dist/components/Dashboard/DashboardView.d.ts +38 -3
- package/dist/components/Dashboard/TileCard.d.ts +16 -2
- package/dist/components/Dashboard/dropValueUrlTags.d.ts +6 -0
- package/dist/components/Dashboard/index.d.ts +3 -2
- package/dist/components/Dashboard/telemetry.d.ts +2 -1
- package/dist/components/Dashboard/textSource.d.ts +19 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +7 -8
- package/dist/components/DashboardBuilder/BuilderDialogs.d.ts +25 -0
- package/dist/components/DashboardBuilder/BuilderGrid.d.ts +31 -0
- package/dist/components/DashboardBuilder/BuilderHeader.d.ts +17 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +14 -17
- package/dist/components/DashboardBuilder/ChartPicker.d.ts +3 -1
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +15 -7
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +28 -2
- package/dist/components/DashboardBuilder/EditorSurface.d.ts +33 -0
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +6 -4
- package/dist/components/DashboardBuilder/InlineText.d.ts +1 -1
- package/dist/components/DashboardBuilder/NotebookEditor.d.ts +1 -1
- package/dist/components/DashboardBuilder/TextTileBody.d.ts +4 -1
- package/dist/components/DashboardBuilder/TileFrame.d.ts +43 -6
- package/dist/components/DashboardBuilder/TileMenu.d.ts +6 -8
- package/dist/components/DashboardBuilder/builderReport.d.ts +13 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +0 -18
- package/dist/components/DashboardBuilder/documentSession.d.ts +2 -2
- package/dist/components/DashboardBuilder/imports.d.ts +19 -0
- package/dist/components/DashboardBuilder/inlineEdit.d.ts +18 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +3 -1
- package/dist/components/DashboardBuilder/readForEditor.d.ts +1 -1
- package/dist/components/DashboardBuilder/sortable.d.ts +2 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +2 -0
- package/dist/components/DashboardBuilder/testing/resize.d.ts +7 -0
- package/dist/components/DashboardBuilder/tileDisplayTitle.d.ts +7 -0
- package/dist/components/DashboardBuilder/useBuilderSelection.d.ts +53 -0
- package/dist/components/DashboardBuilder/useBuilderSession.d.ts +4 -7
- package/dist/components/DashboardBuilder/useControlBindings.d.ts +30 -0
- package/dist/components/DashboardBuilder/useConversionConfirm.d.ts +20 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +2 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +3 -1
- package/dist/components/DashboardBuilder/useHostCopy.d.ts +26 -0
- package/dist/components/DashboardBuilder/useOpenDraftCommit.d.ts +17 -0
- package/dist/components/DashboardBuilder/useOpenedDocument.d.ts +71 -0
- package/dist/components/DashboardBuilder/useSaveChannel.d.ts +50 -0
- package/dist/components/DashboardBuilder/useTileEditing.d.ts +33 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +32 -0
- package/dist/components/Loading.d.ts +13 -0
- package/dist/components/Notebook/NotebookCell.d.ts +1 -5
- package/dist/components/Package/Package.d.ts +16 -1
- package/dist/components/Package/index.d.ts +1 -1
- package/dist/components/Prose.d.ts +1 -1
- package/dist/components/RenderedResult/loadRenderer.d.ts +7 -0
- package/dist/components/given/paramCodec.d.ts +8 -1
- package/dist/components/index.d.ts +1 -2
- package/dist/components/styles.d.ts +4 -4
- package/dist/hooks/givenValue.d.ts +6 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useCompiledDocument.d.ts +23 -0
- package/dist/hooks/useDocumentControls.d.ts +6 -1
- package/dist/hooks/useNearViewport.d.ts +16 -0
- package/dist/hooks/useQueryWithApiError.d.ts +7 -2
- package/dist/hooks/useSuggestOptions.d.ts +9 -2
- package/dist/index.cjs.js +14 -14
- package/dist/index.es.js +9760 -10363
- package/dist/text/index.es.js +1 -1
- package/dist/{text-entry-CbbBcZl8.es.js → text-entry-CA0LZ1xL.es.js} +8 -8
- package/dist/text-entry.d.ts +1 -1
- package/dist/theme/accent.d.ts +29 -0
- package/dist/theme/buildVegaThemeOverride.d.ts +3 -3
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/keys.d.ts +1 -1
- package/dist/theme/motion.d.ts +31 -0
- package/dist/theme/readChartAnnotations.d.ts +1 -1
- package/dist/theme/resolveTheme.d.ts +4 -4
- package/dist/theme/types.d.ts +33 -5
- package/dist/{DashboardTile-BFcxdv7R.es.js → useCompiledDocument-BU6d8FPp.es.js} +6978 -6289
- package/dist/useCompiledDocument-pOg2W-Yt.cjs.js +142 -0
- package/package.json +11 -11
- package/src/builder-entry.ts +1 -0
- package/src/client-entry.ts +8 -0
- package/src/clientEntry.spec.ts +17 -0
- package/src/components/ApiErrorDisplay.tsx +37 -18
- package/src/components/AppDialog.tsx +8 -7
- package/src/components/Dashboard/Dashboard.spec.tsx +3 -32
- package/src/components/Dashboard/Dashboard.tsx +2 -2
- package/src/components/Dashboard/DashboardGrid.tsx +23 -5
- package/src/components/Dashboard/DashboardTile.spec.tsx +97 -2
- package/src/components/Dashboard/DashboardTile.tsx +95 -31
- package/src/components/Dashboard/DashboardView.spec.tsx +156 -0
- package/src/components/Dashboard/DashboardView.tsx +165 -89
- package/src/components/Dashboard/RowsDialog.tsx +3 -2
- package/src/components/Dashboard/TileCard.tsx +17 -2
- package/src/components/Dashboard/dropValueUrlTags.spec.ts +177 -0
- package/src/components/Dashboard/dropValueUrlTags.ts +108 -0
- package/src/components/Dashboard/index.ts +11 -2
- package/src/components/Dashboard/telemetry.ts +2 -1
- package/src/components/Dashboard/textSource.spec.ts +36 -0
- package/src/components/Dashboard/textSource.ts +39 -0
- package/src/components/DashboardBuilder/AddTileDialog.tsx +16 -56
- package/src/components/DashboardBuilder/BuilderDialogs.tsx +162 -0
- package/src/components/DashboardBuilder/BuilderGrid.tsx +245 -0
- package/src/components/DashboardBuilder/BuilderHeader.tsx +107 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +86 -113
- package/src/components/DashboardBuilder/ChartPicker.tsx +4 -1
- package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +5 -5
- package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +74 -83
- package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +62 -18
- package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +55 -108
- package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +10 -62
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +50 -57
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +53 -40
- package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +10 -8
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +227 -704
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +32 -52
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +1 -50
- package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +12 -18
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +4 -24
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +4 -4
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +8 -13
- package/src/components/DashboardBuilder/DashboardEditor.textSource.spec.tsx +317 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +142 -820
- package/src/components/DashboardBuilder/DrillDialog.tsx +2 -2
- package/src/components/DashboardBuilder/EditorSurface.tsx +471 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +13 -8
- package/src/components/DashboardBuilder/FilterStrip.tsx +117 -79
- package/src/components/DashboardBuilder/InlineMarkdown.tsx +7 -9
- package/src/components/DashboardBuilder/InlineText.tsx +23 -17
- package/src/components/DashboardBuilder/NotebookEditor.tsx +3 -3
- package/src/components/DashboardBuilder/TextTileBody.tsx +5 -2
- package/src/components/DashboardBuilder/TileFrame.tsx +255 -90
- package/src/components/DashboardBuilder/TileMenu.tsx +41 -91
- package/src/components/DashboardBuilder/artifactBlock.spec.ts +1 -1
- package/src/components/DashboardBuilder/artifactTagParity.spec.ts +9 -4
- package/src/components/DashboardBuilder/builderReport.ts +74 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +0 -44
- package/src/components/DashboardBuilder/catalog.ts +0 -36
- package/src/components/DashboardBuilder/controls.spec.ts +1 -1
- package/src/components/DashboardBuilder/controls.ts +1 -1
- package/src/components/DashboardBuilder/documentSession.ts +3 -2
- package/src/components/DashboardBuilder/imports.spec.ts +61 -0
- package/src/components/DashboardBuilder/imports.ts +93 -0
- package/src/components/DashboardBuilder/inlineEdit.tsx +78 -0
- package/src/components/DashboardBuilder/legacyNotebook.ts +1 -1
- package/src/components/DashboardBuilder/malloyTree.ts +5 -1
- package/src/components/DashboardBuilder/newDashboard.ts +1 -1
- package/src/components/DashboardBuilder/preview.ts +1 -1
- package/src/components/DashboardBuilder/readDocument.spec.ts +36 -0
- package/src/components/DashboardBuilder/readDocument.ts +10 -4
- package/src/components/DashboardBuilder/readForEditor.ts +7 -2
- package/src/components/DashboardBuilder/sortable.spec.ts +25 -1
- package/src/components/DashboardBuilder/sortable.tsx +11 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +8 -3
- package/src/components/DashboardBuilder/testing/artifactTagParity.json +62 -6
- package/src/components/DashboardBuilder/testing/documentKindRule.json +40 -0
- package/src/components/DashboardBuilder/testing/inline.ts +1 -1
- package/src/components/DashboardBuilder/testing/resize.ts +48 -0
- package/src/components/DashboardBuilder/testing/urlRenderTags.json +62 -0
- package/src/components/DashboardBuilder/textTiles.spec.ts +43 -1
- package/src/components/DashboardBuilder/tileDisplayTitle.ts +13 -0
- package/src/components/DashboardBuilder/useBuilderSelection.ts +121 -0
- package/src/components/DashboardBuilder/useBuilderSession.spec.ts +0 -85
- package/src/components/DashboardBuilder/useBuilderSession.ts +6 -43
- package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +32 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +11 -1
- package/src/components/DashboardBuilder/useControlBindings.ts +152 -0
- package/src/components/DashboardBuilder/useConversionConfirm.ts +55 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +5 -2
- package/src/components/DashboardBuilder/useDraft.ts +15 -2
- package/src/components/DashboardBuilder/useHostCopy.ts +104 -0
- package/src/components/DashboardBuilder/useOpenDraftCommit.ts +47 -0
- package/src/components/DashboardBuilder/useOpenedDocument.ts +314 -0
- package/src/components/DashboardBuilder/useSaveChannel.ts +275 -0
- package/src/components/DashboardBuilder/useTileEditing.ts +141 -0
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +146 -0
- package/src/components/DashboardBuilder/useTileResize.ts +133 -0
- package/src/components/DataAppViewer/DataAppViewer.tsx +7 -4
- package/src/components/DocumentCreate/guards.ts +1 -1
- package/src/components/Environment/Environment.tsx +0 -10
- package/src/components/Loading.tsx +14 -0
- package/src/components/Model/Model.tsx +16 -9
- package/src/components/Model/ModelExplorer.tsx +2 -2
- package/src/components/Notebook/Notebook.tsx +6 -2
- package/src/components/Notebook/NotebookCell.tsx +90 -215
- package/src/components/Package/Package.artifacts.spec.tsx +8 -12
- package/src/components/Package/Package.create.spec.tsx +22 -1
- package/src/components/Package/Package.tsx +51 -27
- package/src/components/Package/index.ts +1 -1
- package/src/components/Prose.spec.tsx +37 -0
- package/src/components/Prose.tsx +35 -5
- package/src/components/RenderedResult/RenderedResult.tsx +5 -7
- package/src/components/RenderedResult/ResultContainer.tsx +7 -2
- package/src/components/RenderedResult/ResultPanel.tsx +20 -5
- package/src/components/RenderedResult/loadRenderer.ts +42 -0
- package/src/components/given/GivenInput.spec.tsx +5 -5
- package/src/components/given/GivenInput.tsx +46 -38
- package/src/components/given/GivensPanel.tsx +2 -8
- package/src/components/given/paramCodec.ts +27 -1
- package/src/components/index.ts +1 -2
- package/src/components/styles.ts +4 -5
- package/src/hooks/givenValue.ts +9 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useCompiledDocument.spec.tsx +86 -0
- package/src/hooks/useCompiledDocument.ts +59 -0
- package/src/hooks/useDimensionalFilterRangeData.ts +3 -1
- package/src/hooks/useDocumentControls.ts +13 -1
- package/src/hooks/useNearViewport.spec.tsx +150 -0
- package/src/hooks/useNearViewport.ts +102 -0
- package/src/hooks/useQueryResult.ts +7 -1
- package/src/hooks/useQueryWithApiError.ts +10 -3
- package/src/hooks/useRawQueryData.ts +3 -1
- package/src/hooks/useSuggestOptions.dom.spec.ts +40 -1
- package/src/hooks/useSuggestOptions.ts +42 -10
- package/src/text-entry.ts +1 -1
- package/src/textEntry.spec.ts +2 -8
- package/src/theme/accent.spec.ts +116 -0
- package/src/theme/accent.ts +148 -0
- package/src/theme/buildTableCssVars.spec.ts +24 -0
- package/src/theme/buildTableCssVars.ts +1 -2
- package/src/theme/buildVegaThemeOverride.spec.ts +38 -2
- package/src/theme/buildVegaThemeOverride.ts +5 -5
- package/src/theme/defaults.ts +34 -0
- package/src/theme/index.ts +9 -0
- package/src/theme/keys.ts +6 -0
- package/src/theme/motion.ts +44 -0
- package/src/theme/readChartAnnotations.spec.ts +18 -0
- package/src/theme/readChartAnnotations.ts +1 -1
- package/src/theme/resolveTheme.spec.ts +73 -0
- package/src/theme/resolveTheme.ts +61 -20
- package/src/theme/types.ts +30 -5
- package/src/utils/queryClient.ts +8 -0
- package/dist/DashboardTile-sg8LjUk8.cjs.js +0 -137
- package/dist/ServerProvider-HRqT3w1C.cjs.js +0 -1
- package/dist/components/Dashboard/DashboardBar.d.ts +0 -21
- package/dist/components/Dashboard/ExploreDialog.d.ts +0 -20
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +0 -7
- package/dist/components/DashboardBuilder/SaveNotice.d.ts +0 -27
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +0 -32
- package/dist/components/DashboardBuilder/diff.d.ts +0 -35
- package/src/components/Dashboard/DashboardBar.tsx +0 -88
- package/src/components/Dashboard/ExploreDialog.tsx +0 -89
- package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +0 -194
- package/src/components/DashboardBuilder/DiffDialog.spec.tsx +0 -25
- package/src/components/DashboardBuilder/DiffDialog.tsx +0 -103
- package/src/components/DashboardBuilder/SaveNotice.tsx +0 -113
- package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +0 -87
- package/src/components/DashboardBuilder/SettingsPopover.tsx +0 -326
- package/src/components/DashboardBuilder/diff.spec.ts +0 -44
- package/src/components/DashboardBuilder/diff.ts +0 -93
- /package/dist/{components/DashboardBuilder → utils}/malloyText.d.ts +0 -0
- /package/src/{components/DashboardBuilder → utils}/malloyText.spec.ts +0 -0
- /package/src/{components/DashboardBuilder → utils}/malloyText.ts +0 -0
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
Stack,
|
|
18
18
|
TextField,
|
|
19
19
|
Typography,
|
|
20
|
+
type SxProps,
|
|
21
|
+
type Theme,
|
|
20
22
|
} from "@mui/material";
|
|
21
23
|
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
|
|
22
24
|
import { DatePicker } from "@mui/x-date-pickers/DatePicker";
|
|
@@ -504,7 +506,10 @@ export function GivenInput({
|
|
|
504
506
|
<Typography variant="body2" color="text.secondary" noWrap>
|
|
505
507
|
{label}
|
|
506
508
|
</Typography>
|
|
507
|
-
<Typography
|
|
509
|
+
<Typography
|
|
510
|
+
variant="body2"
|
|
511
|
+
sx={{ fontWeight: "fontWeightMedium" }}
|
|
512
|
+
>
|
|
508
513
|
{/* `≥ N` only for a FILTER, whose value IS a lower
|
|
509
514
|
bound. A plain `number` given is an ordinary value, and
|
|
510
515
|
the onChange below says so by committing `picked`
|
|
@@ -521,20 +526,16 @@ export function GivenInput({
|
|
|
521
526
|
: String(position)}
|
|
522
527
|
</Typography>
|
|
523
528
|
{isOverridden && (
|
|
524
|
-
<
|
|
525
|
-
size="small"
|
|
526
|
-
aria-label="clear value"
|
|
529
|
+
<ClearButton
|
|
527
530
|
// `null`, like every other × in this file: revert the
|
|
528
531
|
// override. It used to send `""` for a filter, which
|
|
529
532
|
// `decodeAtLeast` reads back as undefined, so the
|
|
530
533
|
// control redrew as "Any" and hid this button while the
|
|
531
534
|
// given was still explicitly set to the empty filter.
|
|
532
535
|
// The reader could neither see the override nor undo it.
|
|
533
|
-
|
|
536
|
+
onClear={() => onChange(null)}
|
|
534
537
|
sx={{ p: 0 }}
|
|
535
|
-
|
|
536
|
-
<ClearIcon fontSize="small" />
|
|
537
|
-
</IconButton>
|
|
538
|
+
/>
|
|
538
539
|
)}
|
|
539
540
|
</Stack>
|
|
540
541
|
<Slider
|
|
@@ -735,14 +736,7 @@ export function GivenInput({
|
|
|
735
736
|
label={label}
|
|
736
737
|
/>
|
|
737
738
|
{isOverridden && (
|
|
738
|
-
<
|
|
739
|
-
size="small"
|
|
740
|
-
aria-label="clear value"
|
|
741
|
-
onClick={() => onChange(null)}
|
|
742
|
-
edge="end"
|
|
743
|
-
>
|
|
744
|
-
<ClearIcon fontSize="small" />
|
|
745
|
-
</IconButton>
|
|
739
|
+
<ClearButton onClear={() => onChange(null)} edge="end" />
|
|
746
740
|
)}
|
|
747
741
|
</Stack>
|
|
748
742
|
{helperNode && <FormHelperText>{helperNode}</FormHelperText>}
|
|
@@ -889,17 +883,39 @@ export function GivenInput({
|
|
|
889
883
|
);
|
|
890
884
|
}
|
|
891
885
|
|
|
886
|
+
/**
|
|
887
|
+
* The × that reverts a control to its default: one button, so every control
|
|
888
|
+
* says the same thing to a screen reader and offers the same 24px target.
|
|
889
|
+
*/
|
|
890
|
+
function ClearButton({
|
|
891
|
+
onClear,
|
|
892
|
+
edge,
|
|
893
|
+
sx,
|
|
894
|
+
}: {
|
|
895
|
+
onClear: () => void;
|
|
896
|
+
edge?: "start" | "end";
|
|
897
|
+
sx?: SxProps<Theme>;
|
|
898
|
+
}) {
|
|
899
|
+
return (
|
|
900
|
+
<IconButton
|
|
901
|
+
size="small"
|
|
902
|
+
aria-label="Clear value"
|
|
903
|
+
onClick={onClear}
|
|
904
|
+
edge={edge}
|
|
905
|
+
sx={[
|
|
906
|
+
{ minWidth: 24, minHeight: 24 },
|
|
907
|
+
...(Array.isArray(sx) ? sx : [sx]),
|
|
908
|
+
]}
|
|
909
|
+
>
|
|
910
|
+
<ClearIcon fontSize="small" />
|
|
911
|
+
</IconButton>
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
|
|
892
915
|
function ClearAdornment({ onClear }: { onClear: () => void }) {
|
|
893
916
|
return (
|
|
894
917
|
<InputAdornment position="end">
|
|
895
|
-
<
|
|
896
|
-
size="small"
|
|
897
|
-
aria-label="clear value"
|
|
898
|
-
onClick={onClear}
|
|
899
|
-
edge="end"
|
|
900
|
-
>
|
|
901
|
-
<ClearIcon fontSize="small" />
|
|
902
|
-
</IconButton>
|
|
918
|
+
<ClearButton onClear={onClear} edge="end" />
|
|
903
919
|
</InputAdornment>
|
|
904
920
|
);
|
|
905
921
|
}
|
|
@@ -953,14 +969,10 @@ function BooleanFilterControl({
|
|
|
953
969
|
},
|
|
954
970
|
input: {
|
|
955
971
|
endAdornment: isOverridden ? (
|
|
956
|
-
<
|
|
957
|
-
|
|
958
|
-
aria-label="clear value"
|
|
959
|
-
onClick={() => onChange(null)}
|
|
972
|
+
<ClearButton
|
|
973
|
+
onClear={() => onChange(null)}
|
|
960
974
|
sx={{ mr: 2 }}
|
|
961
|
-
|
|
962
|
-
<ClearIcon fontSize="small" />
|
|
963
|
-
</IconButton>
|
|
975
|
+
/>
|
|
964
976
|
) : undefined,
|
|
965
977
|
},
|
|
966
978
|
}}
|
|
@@ -1103,18 +1115,14 @@ function TimeRangeControl({
|
|
|
1103
1115
|
endAdornment: isOverridden ? (
|
|
1104
1116
|
// Before the dropdown arrow, which MUI positions on its
|
|
1105
1117
|
// own; the × reverts, like every × in this file.
|
|
1106
|
-
<
|
|
1107
|
-
|
|
1108
|
-
aria-label="clear value"
|
|
1109
|
-
onClick={() => {
|
|
1118
|
+
<ClearButton
|
|
1119
|
+
onClear={() => {
|
|
1110
1120
|
setCustom(false);
|
|
1111
1121
|
setDraft({});
|
|
1112
1122
|
onChange(null);
|
|
1113
1123
|
}}
|
|
1114
1124
|
sx={{ mr: 2 }}
|
|
1115
|
-
|
|
1116
|
-
<ClearIcon fontSize="small" />
|
|
1117
|
-
</IconButton>
|
|
1125
|
+
/>
|
|
1118
1126
|
) : undefined,
|
|
1119
1127
|
},
|
|
1120
1128
|
}}
|
|
@@ -107,18 +107,12 @@ export function GivensPanel({
|
|
|
107
107
|
disableElevation
|
|
108
108
|
onClick={apply.onApply}
|
|
109
109
|
disabled={!apply.pending}
|
|
110
|
-
sx={{ textTransform: "none" }}
|
|
111
110
|
>
|
|
112
111
|
Apply
|
|
113
112
|
</Button>
|
|
114
113
|
)}
|
|
115
114
|
{hasValues && (
|
|
116
|
-
<Button
|
|
117
|
-
variant="text"
|
|
118
|
-
size="small"
|
|
119
|
-
onClick={onReset}
|
|
120
|
-
sx={{ textTransform: "none" }}
|
|
121
|
-
>
|
|
115
|
+
<Button variant="text" size="small" onClick={onReset}>
|
|
122
116
|
Reset
|
|
123
117
|
</Button>
|
|
124
118
|
)}
|
|
@@ -178,7 +172,7 @@ export function GivensPanel({
|
|
|
178
172
|
>
|
|
179
173
|
<Typography
|
|
180
174
|
variant="subtitle2"
|
|
181
|
-
sx={{ fontWeight:
|
|
175
|
+
sx={{ fontWeight: "fontWeightMedium", color: "text.primary" }}
|
|
182
176
|
>
|
|
183
177
|
{title ?? "Filters"}
|
|
184
178
|
</Typography>
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* are filter syntax rather than numbers.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import type { GivenValue } from "../../hooks/givenValue";
|
|
18
|
+
import type { GivenValue, HostGivenValue } from "../../hooks/givenValue";
|
|
19
19
|
import { isFilterType } from "./filterValue";
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -461,6 +461,32 @@ export function givensToRequest(
|
|
|
461
461
|
return request;
|
|
462
462
|
}
|
|
463
463
|
|
|
464
|
+
/**
|
|
465
|
+
* The host-set givens a request carries, added AFTER {@link givensToRequest}
|
|
466
|
+
* because that drops arrays and a host's list-valued given must reach the server.
|
|
467
|
+
* A name already in `request` is a control's and keeps its value; `only` narrows
|
|
468
|
+
* to the names a query reads, as it does there.
|
|
469
|
+
*/
|
|
470
|
+
export function withHostGivens(
|
|
471
|
+
request: Record<string, unknown>,
|
|
472
|
+
host: Readonly<Record<string, HostGivenValue>> | undefined,
|
|
473
|
+
only?: readonly string[],
|
|
474
|
+
): Record<string, unknown> {
|
|
475
|
+
if (!host) return request;
|
|
476
|
+
const names = only ? new Set(only) : undefined;
|
|
477
|
+
const merged = { ...request };
|
|
478
|
+
for (const [name, value] of Object.entries(host)) {
|
|
479
|
+
if (names && !names.has(name)) continue;
|
|
480
|
+
if (name in merged || value === null || value === undefined) continue;
|
|
481
|
+
merged[name] = Array.isArray(value)
|
|
482
|
+
? [...value]
|
|
483
|
+
: value instanceof Date
|
|
484
|
+
? dateToRequest(value, undefined)
|
|
485
|
+
: value;
|
|
486
|
+
}
|
|
487
|
+
return merged;
|
|
488
|
+
}
|
|
489
|
+
|
|
464
490
|
/**
|
|
465
491
|
* Read query parameters into control values, keeping only the names the
|
|
466
492
|
* dashboard actually declares.
|
package/src/components/index.ts
CHANGED
|
@@ -12,11 +12,10 @@ export { AppDialog } from "./AppDialog";
|
|
|
12
12
|
export { UnsavedChangesDialog } from "./UnsavedChangesDialog";
|
|
13
13
|
export { BackLink } from "./BackLink";
|
|
14
14
|
export { NarrowEditGate } from "./NarrowEditGate";
|
|
15
|
-
export { DashboardBar } from "./Dashboard/DashboardBar";
|
|
16
15
|
// The Console's palette, and the two maps drawn from it. Exported so a host
|
|
17
16
|
// paints its own chrome — the Publisher app's theme included — from the same
|
|
18
17
|
// hues rather than picking a near-miss beside them.
|
|
19
|
-
export { PALETTE, SURFACE_TINT } from "./styles";
|
|
18
|
+
export { MONO_FONT_FAMILY, PALETTE, SURFACE_TINT } from "./styles";
|
|
20
19
|
export { useRouterClickHandler, type NavigationClick } from "./click_helper";
|
|
21
20
|
export * from "./Dashboard";
|
|
22
21
|
export * from "./DataAppViewer";
|
package/src/components/styles.ts
CHANGED
|
@@ -63,8 +63,8 @@ export const SURFACE_TINT = {
|
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Monospace font stack used by code-like surfaces inside the SDK
|
|
66
|
-
* (file-path labels in `ItemRow`, code blocks, etc.)
|
|
67
|
-
*
|
|
66
|
+
* (file-path labels in `ItemRow`, code blocks, etc.) and by the
|
|
67
|
+
* Console, which re-exports it from its theme.
|
|
68
68
|
*/
|
|
69
69
|
export const MONO_FONT_FAMILY =
|
|
70
70
|
'"JetBrains Mono", "ui-monospace", "SFMono-Regular", "Menlo", monospace';
|
|
@@ -90,14 +90,13 @@ export const StyledCardMedia = styled(CardMedia)({
|
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
// New clean notebook styles
|
|
93
|
+
// No width or side padding of its own: like the Dashboard, a notebook fills
|
|
94
|
+
// the column its host gives it, so a package's pages share one set of edges.
|
|
93
95
|
export const CleanNotebookContainer = styled("div")(({ theme }) => ({
|
|
94
96
|
backgroundColor: theme.palette.background.default,
|
|
95
|
-
padding: "0 8px 0px 8px",
|
|
96
97
|
borderRadius: "12px",
|
|
97
98
|
boxShadow: "none",
|
|
98
99
|
border: "none",
|
|
99
|
-
maxWidth: "1200px",
|
|
100
|
-
margin: "0 auto",
|
|
101
100
|
}));
|
|
102
101
|
|
|
103
102
|
export const CleanNotebookSection = styled("div")({
|
package/src/hooks/givenValue.ts
CHANGED
|
@@ -11,3 +11,12 @@
|
|
|
11
11
|
* to be canonical this week.
|
|
12
12
|
*/
|
|
13
13
|
export type GivenValue = string | number | boolean | Date | null;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A value the HOST sets for a given no control shows. Only a host can send a
|
|
17
|
+
* list (`GivenValue` leaves arrays out on purpose: a control's value must
|
|
18
|
+
* round-trip through a URL), and the server accepts one for a `string[]` given.
|
|
19
|
+
*/
|
|
20
|
+
export type HostGivenValue =
|
|
21
|
+
| GivenValue
|
|
22
|
+
| readonly (string | number | boolean)[];
|
package/src/hooks/index.ts
CHANGED
|
@@ -43,6 +43,10 @@ export {
|
|
|
43
43
|
type UseGivensStateResult,
|
|
44
44
|
} from "./useGivensState";
|
|
45
45
|
export { useSuggestOptions } from "./useSuggestOptions";
|
|
46
|
+
export {
|
|
47
|
+
useCompiledDocument,
|
|
48
|
+
type CompiledDocumentSpec,
|
|
49
|
+
} from "./useCompiledDocument";
|
|
46
50
|
|
|
47
51
|
// One query, and one control row, as every surface asks for them
|
|
48
52
|
export {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { renderHook, waitFor } from "@testing-library/react";
|
|
5
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import {
|
|
7
|
+
clearCache,
|
|
8
|
+
mockServerProvider,
|
|
9
|
+
serverWrapper,
|
|
10
|
+
} from "../../test/serverProvider";
|
|
11
|
+
|
|
12
|
+
const compileModelSource = mock(
|
|
13
|
+
(
|
|
14
|
+
_env: string,
|
|
15
|
+
_pkg: string,
|
|
16
|
+
_path: string,
|
|
17
|
+
_body: { source?: string; scope?: string; givens?: object },
|
|
18
|
+
) => Promise.resolve({ data: { status: "success", problems: [] } }),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
mockServerProvider({ models: { compileModelSource } });
|
|
22
|
+
|
|
23
|
+
const { useCompiledDocument } = await import("./useCompiledDocument");
|
|
24
|
+
|
|
25
|
+
const SOURCE = '## artifact { tiles=["orders_secured -> by_status"] }\n';
|
|
26
|
+
|
|
27
|
+
const render = (givens?: Record<string, unknown>) =>
|
|
28
|
+
renderHook(
|
|
29
|
+
() =>
|
|
30
|
+
useCompiledDocument({
|
|
31
|
+
environmentName: "env",
|
|
32
|
+
packageName: "pkg",
|
|
33
|
+
modelPath: "index.malloy",
|
|
34
|
+
source: SOURCE,
|
|
35
|
+
givens,
|
|
36
|
+
}),
|
|
37
|
+
{ wrapper: serverWrapper },
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const bodyOfLastCall = () => compileModelSource.mock.calls.at(-1)?.[3];
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
clearCache();
|
|
44
|
+
compileModelSource.mockClear();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("useCompiledDocument: the givens a gate reads", () => {
|
|
48
|
+
it("sends no givens key when the host sets none", async () => {
|
|
49
|
+
const { result } = render();
|
|
50
|
+
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
|
51
|
+
expect(bodyOfLastCall()).toEqual({ source: SOURCE, scope: "append" });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("sends a list-valued given as the list, which a `$TENANTS`-style gate reads", async () => {
|
|
55
|
+
const { result } = render({ TENANTS: ["acme", "globex"] });
|
|
56
|
+
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
|
57
|
+
expect(bodyOfLastCall()).toEqual({
|
|
58
|
+
source: SOURCE,
|
|
59
|
+
scope: "append",
|
|
60
|
+
givens: { TENANTS: ["acme", "globex"] },
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("compiles again when a given's value changes, so a stale restricted verdict is not reused", async () => {
|
|
65
|
+
const { result, rerender } = renderHook(
|
|
66
|
+
({ givens }: { givens: Record<string, unknown> }) =>
|
|
67
|
+
useCompiledDocument({
|
|
68
|
+
environmentName: "env",
|
|
69
|
+
packageName: "pkg",
|
|
70
|
+
modelPath: "index.malloy",
|
|
71
|
+
source: SOURCE,
|
|
72
|
+
givens,
|
|
73
|
+
}),
|
|
74
|
+
{
|
|
75
|
+
wrapper: serverWrapper,
|
|
76
|
+
initialProps: { givens: { TENANTS: ["acme"] } },
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
|
80
|
+
rerender({ givens: { TENANTS: ["acme", "globex"] } });
|
|
81
|
+
await waitFor(() => expect(compileModelSource).toHaveBeenCalledTimes(2));
|
|
82
|
+
expect(bodyOfLastCall()?.givens).toEqual({
|
|
83
|
+
TENANTS: ["acme", "globex"],
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { CompiledDocument, CompileResult } from "../client";
|
|
5
|
+
import { useServer } from "../components/ServerProvider";
|
|
6
|
+
import { useQueryWithApiError } from "./useQueryWithApiError";
|
|
7
|
+
|
|
8
|
+
export interface CompiledDocumentSpec {
|
|
9
|
+
environmentName: string;
|
|
10
|
+
packageName: string;
|
|
11
|
+
/** The model the text is compiled on top of: what it may name is what this model offers the viewer. */
|
|
12
|
+
modelPath: string;
|
|
13
|
+
source: string;
|
|
14
|
+
/** The values the host sets for the givens a source's gate reads; a gate sent none of its givens denies, so every tile would come back `restricted`. */
|
|
15
|
+
givens?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The document a text compiles to, read for the viewer who asks: the manifest
|
|
20
|
+
* and cells the server would serve, with the tiles and cells that viewer may
|
|
21
|
+
* not read marked `restricted`. Compile-only; nothing runs.
|
|
22
|
+
*/
|
|
23
|
+
export function useCompiledDocument(
|
|
24
|
+
spec: CompiledDocumentSpec,
|
|
25
|
+
{ enabled = true }: { enabled?: boolean } = {},
|
|
26
|
+
) {
|
|
27
|
+
const { apiClients } = useServer();
|
|
28
|
+
return useQueryWithApiError<{
|
|
29
|
+
document?: CompiledDocument;
|
|
30
|
+
result: CompileResult;
|
|
31
|
+
}>({
|
|
32
|
+
queryKey: [
|
|
33
|
+
"compiled-document",
|
|
34
|
+
spec.environmentName,
|
|
35
|
+
spec.packageName,
|
|
36
|
+
spec.modelPath,
|
|
37
|
+
spec.source,
|
|
38
|
+
spec.givens ?? null,
|
|
39
|
+
],
|
|
40
|
+
queryFn: async () => {
|
|
41
|
+
const result = (
|
|
42
|
+
await apiClients.models.compileModelSource(
|
|
43
|
+
spec.environmentName,
|
|
44
|
+
spec.packageName,
|
|
45
|
+
spec.modelPath,
|
|
46
|
+
{
|
|
47
|
+
source: spec.source,
|
|
48
|
+
scope: "append",
|
|
49
|
+
...(spec.givens && Object.keys(spec.givens).length > 0
|
|
50
|
+
? { givens: spec.givens }
|
|
51
|
+
: {}),
|
|
52
|
+
},
|
|
53
|
+
)
|
|
54
|
+
).data;
|
|
55
|
+
return { document: result.document, result };
|
|
56
|
+
},
|
|
57
|
+
enabled,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -698,7 +698,7 @@ export function useDimensionalFilterRangeData(
|
|
|
698
698
|
versionId,
|
|
699
699
|
activeFilters,
|
|
700
700
|
],
|
|
701
|
-
queryFn: async () => {
|
|
701
|
+
queryFn: async ({ signal }) => {
|
|
702
702
|
if (!shouldExecuteQuery) {
|
|
703
703
|
// Return empty map if no query needed (using composite keys)
|
|
704
704
|
const emptyMap = new Map<string, DimensionValue[]>();
|
|
@@ -721,6 +721,8 @@ export function useDimensionalFilterRangeData(
|
|
|
721
721
|
versionId: versionId,
|
|
722
722
|
bypassFilters: true,
|
|
723
723
|
},
|
|
724
|
+
undefined,
|
|
725
|
+
{ signal },
|
|
724
726
|
);
|
|
725
727
|
return {
|
|
726
728
|
config,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { useCallback, useMemo } from "react";
|
|
5
5
|
import type { Given } from "../client";
|
|
6
|
+
import type { HostGivenValue } from "./givenValue";
|
|
6
7
|
import { useDrillSelf } from "../components/drill/useDrillSelf";
|
|
7
8
|
import type { GivensPanelProps } from "../components/given/GivensPanel";
|
|
8
9
|
import { useGivensState, type UseGivensStateResult } from "./useGivensState";
|
|
@@ -63,6 +64,10 @@ export interface UseDocumentControlsOptions {
|
|
|
63
64
|
versionId?: string;
|
|
64
65
|
/** How the document names itself in a refused-drill warning. */
|
|
65
66
|
documentName: string;
|
|
67
|
+
/** Text-source mode: the document's definitions, which a suggest runs after as the viewer's own text. */
|
|
68
|
+
preamble?: string;
|
|
69
|
+
/** Givens the host sets with no control, so a suggest over a source they gate still carries them. */
|
|
70
|
+
hostGivens?: Readonly<Record<string, HostGivenValue>>;
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
export interface DocumentControls extends UseGivensStateResult {
|
|
@@ -92,6 +97,8 @@ export function useDocumentControls({
|
|
|
92
97
|
modelPath,
|
|
93
98
|
versionId,
|
|
94
99
|
documentName,
|
|
100
|
+
preamble,
|
|
101
|
+
hostGivens,
|
|
95
102
|
}: UseDocumentControlsOptions): DocumentControls {
|
|
96
103
|
const declaredTypes = useMemo(
|
|
97
104
|
() =>
|
|
@@ -136,7 +143,12 @@ export function useDocumentControls({
|
|
|
136
143
|
specs,
|
|
137
144
|
versionId,
|
|
138
145
|
// So a suggest over a gated or scoped source carries the givens it needs.
|
|
139
|
-
{
|
|
146
|
+
{
|
|
147
|
+
values: state.applied,
|
|
148
|
+
declaredTypes,
|
|
149
|
+
...(hostGivens ? { host: hostGivens } : {}),
|
|
150
|
+
},
|
|
151
|
+
preamble,
|
|
140
152
|
);
|
|
141
153
|
|
|
142
154
|
const { canSelf, onSelf } = useDrillSelf({
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { afterEach, expect, it } from "bun:test";
|
|
5
|
+
import { act, render, screen } from "@testing-library/react";
|
|
6
|
+
import { useNearViewport } from "./useNearViewport";
|
|
7
|
+
|
|
8
|
+
function Probe() {
|
|
9
|
+
const [ref, near] = useNearViewport<HTMLDivElement>();
|
|
10
|
+
return <div ref={ref}>{near ? "near" : "far"}</div>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let callbacks: IntersectionObserverCallback[] = [];
|
|
14
|
+
let options: Array<IntersectionObserverInit | undefined> = [];
|
|
15
|
+
let disconnects = 0;
|
|
16
|
+
class FakeObserver {
|
|
17
|
+
private callback: IntersectionObserverCallback;
|
|
18
|
+
constructor(
|
|
19
|
+
callback: IntersectionObserverCallback,
|
|
20
|
+
init?: IntersectionObserverInit,
|
|
21
|
+
) {
|
|
22
|
+
this.callback = callback;
|
|
23
|
+
options.push(init);
|
|
24
|
+
}
|
|
25
|
+
observe() {
|
|
26
|
+
callbacks.push(this.callback);
|
|
27
|
+
}
|
|
28
|
+
disconnect() {
|
|
29
|
+
disconnects += 1;
|
|
30
|
+
}
|
|
31
|
+
unobserve() {}
|
|
32
|
+
takeRecords() {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const report = (isIntersecting: boolean) =>
|
|
37
|
+
act(() =>
|
|
38
|
+
callbacks.forEach((callback) =>
|
|
39
|
+
callback(
|
|
40
|
+
[{ isIntersecting } as IntersectionObserverEntry],
|
|
41
|
+
{} as IntersectionObserver,
|
|
42
|
+
),
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// happy-dom's own, put back after each spec: @dnd-kit elsewhere needs one.
|
|
47
|
+
const original = globalThis.IntersectionObserver;
|
|
48
|
+
const install = (observer: unknown) => {
|
|
49
|
+
(globalThis as { IntersectionObserver?: unknown }).IntersectionObserver =
|
|
50
|
+
observer;
|
|
51
|
+
};
|
|
52
|
+
// Somewhere far below the fold, for an element the observer has to report.
|
|
53
|
+
const placeFarBelow = () =>
|
|
54
|
+
Object.assign(HTMLElement.prototype, {
|
|
55
|
+
getBoundingClientRect: () => ({ top: 10_000, bottom: 10_400 }) as DOMRect,
|
|
56
|
+
});
|
|
57
|
+
const originalRect = HTMLElement.prototype.getBoundingClientRect;
|
|
58
|
+
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
install(original);
|
|
61
|
+
HTMLElement.prototype.getBoundingClientRect = originalRect;
|
|
62
|
+
callbacks = [];
|
|
63
|
+
options = [];
|
|
64
|
+
disconnects = 0;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("is open where there is no IntersectionObserver to ask", () => {
|
|
68
|
+
install(undefined);
|
|
69
|
+
render(<Probe />);
|
|
70
|
+
expect(screen.getByText("near")).toBeDefined();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("is open at once for an element that mounts near the viewport", () => {
|
|
74
|
+
install(FakeObserver);
|
|
75
|
+
render(<Probe />);
|
|
76
|
+
expect(screen.getByText("near")).toBeDefined();
|
|
77
|
+
expect(callbacks).toHaveLength(0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("opens once the element comes within the margin, and stays open", () => {
|
|
81
|
+
install(FakeObserver);
|
|
82
|
+
placeFarBelow();
|
|
83
|
+
render(<Probe />);
|
|
84
|
+
expect(screen.getByText("far")).toBeDefined();
|
|
85
|
+
expect(options[0]?.rootMargin).toBe("600px 0px");
|
|
86
|
+
|
|
87
|
+
report(false);
|
|
88
|
+
expect(screen.getByText("far")).toBeDefined();
|
|
89
|
+
|
|
90
|
+
report(true);
|
|
91
|
+
expect(screen.getByText("near")).toBeDefined();
|
|
92
|
+
expect(disconnects).toBeGreaterThan(0);
|
|
93
|
+
|
|
94
|
+
// Scrolled away again: what has run stays run.
|
|
95
|
+
report(false);
|
|
96
|
+
expect(screen.getByText("near")).toBeDefined();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("measures against the box that scrolls the page, not the window", () => {
|
|
100
|
+
install(FakeObserver);
|
|
101
|
+
// The scroller is on screen; the tile is far down inside it.
|
|
102
|
+
Object.assign(HTMLElement.prototype, {
|
|
103
|
+
getBoundingClientRect(this: HTMLElement) {
|
|
104
|
+
return (
|
|
105
|
+
this.dataset.scroller
|
|
106
|
+
? { top: 0, bottom: 400 }
|
|
107
|
+
: { top: 10_000, bottom: 10_400 }
|
|
108
|
+
) as DOMRect;
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
const scrollHeight = Object.getOwnPropertyDescriptor(
|
|
112
|
+
HTMLElement.prototype,
|
|
113
|
+
"scrollHeight",
|
|
114
|
+
);
|
|
115
|
+
Object.defineProperty(HTMLElement.prototype, "scrollHeight", {
|
|
116
|
+
configurable: true,
|
|
117
|
+
get() {
|
|
118
|
+
return (this as HTMLElement).dataset.scroller ? 5000 : 0;
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
render(
|
|
123
|
+
<div data-scroller="yes" style={{ overflowY: "auto", height: 400 }}>
|
|
124
|
+
<Probe />
|
|
125
|
+
</div>,
|
|
126
|
+
);
|
|
127
|
+
expect(screen.getByText("far")).toBeDefined();
|
|
128
|
+
expect(
|
|
129
|
+
(options[0]?.root as HTMLElement | undefined)?.dataset.scroller,
|
|
130
|
+
).toBe("yes");
|
|
131
|
+
} finally {
|
|
132
|
+
if (scrollHeight)
|
|
133
|
+
Object.defineProperty(
|
|
134
|
+
HTMLElement.prototype,
|
|
135
|
+
"scrollHeight",
|
|
136
|
+
scrollHeight,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("opens for printing, which lays the whole page out at once", () => {
|
|
142
|
+
install(FakeObserver);
|
|
143
|
+
placeFarBelow();
|
|
144
|
+
render(<Probe />);
|
|
145
|
+
expect(screen.getByText("far")).toBeDefined();
|
|
146
|
+
act(() => {
|
|
147
|
+
window.dispatchEvent(new Event("beforeprint"));
|
|
148
|
+
});
|
|
149
|
+
expect(screen.getByText("near")).toBeDefined();
|
|
150
|
+
});
|