@malloy-publisher/sdk 0.0.29 → 0.0.31

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.
@@ -0,0 +1,167 @@
1
+ import React, {
2
+ lazy,
3
+ Suspense,
4
+ useState,
5
+ useRef,
6
+ useCallback,
7
+ useEffect,
8
+ } from "react";
9
+ import { Box, IconButton } from "@mui/material";
10
+ import { ExpandMore, ExpandLess } from "@mui/icons-material";
11
+
12
+ const RenderedResult = lazy(() => import("../RenderedResult/RenderedResult"));
13
+
14
+ interface ResultContainerProps {
15
+ result: string | undefined;
16
+ minHeight: number;
17
+ maxHeight: number;
18
+ }
19
+
20
+ export default function ResultContainer({
21
+ result,
22
+ minHeight,
23
+ maxHeight,
24
+ }: ResultContainerProps) {
25
+ const [isExpanded, setIsExpanded] = useState(false);
26
+ const [contentHeight, setContentHeight] = useState<number>(0);
27
+ const [shouldShowToggle, setShouldShowToggle] = useState(false);
28
+ const contentRef = useRef<HTMLDivElement>(null);
29
+ const containerRef = useRef<HTMLDivElement>(null);
30
+ const [explicitHeight, setExplicitHeight] = useState<number>(undefined);
31
+
32
+ const handleToggle = useCallback(() => {
33
+ const wasExpanded = isExpanded;
34
+ setIsExpanded(!isExpanded);
35
+
36
+ // If we're collapsing (going from expanded to collapsed), scroll to top
37
+ if (wasExpanded && containerRef.current) {
38
+ setTimeout(() => {
39
+ containerRef.current?.scrollIntoView({
40
+ behavior: "smooth",
41
+ block: "start",
42
+ });
43
+ }, 100); // Small delay to allow the collapse animation to start
44
+ }
45
+ }, [isExpanded]);
46
+
47
+ // Handle size changes from RenderedResult
48
+ const handleSizeChange = useCallback((height: number) => {
49
+ console.log("Content height received:", height);
50
+ setContentHeight(height);
51
+ }, []);
52
+
53
+ // Determine if toggle should be shown based on content height vs container height
54
+ useEffect(() => {
55
+ // Only proceed if we have a measured content height
56
+ if (contentHeight === 0) {
57
+ setShouldShowToggle(false);
58
+ return;
59
+ }
60
+
61
+ // The available height should be the minHeight minus the padding
62
+ // We don't subtract toggle button height here since we're deciding whether to show it
63
+ const availableHeight = minHeight - 20; // Estimate padding
64
+ const exceedsHeight = contentHeight > availableHeight;
65
+ if (contentHeight < availableHeight) {
66
+ setExplicitHeight(contentHeight + 20);
67
+ }
68
+ console.log("Height comparison:", {
69
+ contentHeight,
70
+ minHeight,
71
+ availableHeight,
72
+ exceedsHeight,
73
+ });
74
+ setShouldShowToggle(exceedsHeight);
75
+ }, [contentHeight, minHeight]);
76
+
77
+ if (!result) {
78
+ return null;
79
+ }
80
+
81
+ const height = explicitHeight
82
+ ? {
83
+ minHeight: `${explicitHeight}px`,
84
+ height: `${explicitHeight}px`,
85
+ }
86
+ : {};
87
+ return (
88
+ <>
89
+ <Box
90
+ ref={containerRef}
91
+ sx={{
92
+ position: "relative",
93
+ minHeight: `${minHeight}px`,
94
+ maxHeight: `${isExpanded ? maxHeight : minHeight}px`,
95
+ border: "1px solid #e0e0e0",
96
+ borderRadius: 1,
97
+ overflow: "hidden",
98
+ display: "flex",
99
+ flexDirection: "column",
100
+ ...height,
101
+ }}
102
+ >
103
+ {/* Content area */}
104
+ <Box
105
+ ref={contentRef}
106
+ sx={{
107
+ flex: 1,
108
+ overflow: isExpanded ? "auto" : "hidden",
109
+ p: 1,
110
+ // Adjust bottom padding when toggle is shown to prevent content overlap
111
+ pb: shouldShowToggle ? "40px" : 1,
112
+ }}
113
+ >
114
+ {(result && (
115
+ <Suspense fallback={<div>Loading result...</div>}>
116
+ <RenderedResult
117
+ result={result}
118
+ onSizeChange={handleSizeChange}
119
+ />
120
+ </Suspense>
121
+ )) || <div> Loading...</div>}
122
+ </Box>
123
+
124
+ {/* Toggle button - only show if content exceeds container height */}
125
+ {shouldShowToggle && (
126
+ <Box
127
+ sx={{
128
+ position: "absolute",
129
+ bottom: 0,
130
+ left: 0,
131
+ right: 0,
132
+ height: "32px",
133
+ backgroundColor: "rgba(255, 255, 255, 0.9)",
134
+ borderTop: "1px solid #e0e0e0",
135
+ display: "flex",
136
+ alignItems: "center",
137
+ justifyContent: "center",
138
+ backdropFilter: "blur(2px)",
139
+ }}
140
+ >
141
+ <IconButton
142
+ size="small"
143
+ onClick={handleToggle}
144
+ sx={{
145
+ color: "text.secondary",
146
+ "&:hover": {
147
+ backgroundColor: "rgba(0, 0, 0, 0.04)",
148
+ },
149
+ }}
150
+ title={
151
+ isExpanded
152
+ ? "Collapse to original size"
153
+ : "Expand to full size"
154
+ }
155
+ >
156
+ {isExpanded ? (
157
+ <ExpandLess sx={{ fontSize: 20 }} />
158
+ ) : (
159
+ <ExpandMore sx={{ fontSize: 20 }} />
160
+ )}
161
+ </IconButton>
162
+ </Box>
163
+ )}
164
+ </Box>
165
+ </>
166
+ );
167
+ }
@@ -9,7 +9,7 @@ export const StyledCard = styled(Card)({
9
9
  export const StyledCardContent = styled(CardContent)({
10
10
  display: "flex",
11
11
  flexDirection: "column",
12
- padding: "0px 10px 10px 10px",
12
+ padding: "0px 4px 4px 4px",
13
13
  flexGrow: 1,
14
14
  "&:last-child": {
15
15
  paddingBottom: 0,
@@ -17,7 +17,7 @@ export const StyledCardContent = styled(CardContent)({
17
17
  });
18
18
 
19
19
  export const StyledCardMedia = styled(CardMedia)({
20
- padding: "0px 10px 0px 10px",
20
+ padding: "0px 4px 0px 4px",
21
21
  });
22
22
 
23
23
  export const StyledExplorerPage = styled("div")({
@@ -1,12 +0,0 @@
1
- import { j as t } from "./vendor-C36FjD0v.js";
2
- import "./index.es.js";
3
- import { useRef as o, useEffect as n } from "react";
4
- function l({ result: r }) {
5
- const e = o(null);
6
- return n(() => {
7
- e.current && (e.current.malloyResult = JSON.parse(r));
8
- }, [r]), /* @__PURE__ */ t.jsx("malloy-render", { ref: e });
9
- }
10
- export {
11
- l as default
12
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./vendor-DSpmIox9.cjs");require("./index.cjs.js");const t=require("react");function n({result:r}){const e=t.useRef(null);return t.useEffect(()=>{e.current&&(e.current.malloyResult=JSON.parse(r))},[r]),u.jsxRuntimeExports.jsx("malloy-render",{ref:e})}exports.default=n;