Skip to content

Commit

Permalink
Webstepper style updates and added support for scss (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-yz-liu authored Dec 8, 2024
1 parent 167e1df commit 229a46e
Show file tree
Hide file tree
Showing 12 changed files with 517 additions and 81 deletions.
412 changes: 412 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions webstepper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- Launchd an initial prototype!
- Improved UI to indicate when the end of the program is reached.
- Expanded code and svg displays in UI.

### 🐛 Bug fixes

Expand All @@ -24,3 +25,4 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- Added a script for installing the Webstepper build to a specified path.
- Updated to use the window object to serve app data.
- Enabled SCSS support.
2 changes: 2 additions & 0 deletions webstepper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"html-webpack-plugin": "^5.6.0",
"jest-canvas-mock": "^2.5.2",
"jest-environment-jsdom": "^29.7.0",
"sass": "^1.82.0",
"sass-loader": "^16.0.4",
"style-loader": "^3.3.3",
"typescript": "^5.7.2",
"webpack": "^5.94.0",
Expand Down
49 changes: 26 additions & 23 deletions webstepper/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Button, Box, Typography, Stack } from "@mui/material";
import SvgDisplay from "./SvgDisplay";
import CodeDisplay from "./CodeDisplay";
import placeholder from "./placeholder";
import "./css/styles.css";

if (typeof window === "object" && process.env.NODE_ENV !== "production") {
window.svgArray = placeholder.svgArray;
Expand All @@ -21,21 +20,16 @@ export default function App() {
};

return (
<main className="container">
<>
<Header />
<Stack direction="row" spacing={2}>
<Box sx={{ width: "40%" }}>
<h2>Code</h2>
<Typography>
Step {step + 1}/{limit}
</Typography>
<Box className="code-display">
<CodeDisplay
text={codeText}
startingLineNumber={window.svgArray[0].lineNumber}
highlightLine={window.svgArray[step].lineNumber}
/>
<Box className="button-container">
<main className="container-fluid">
<Stack direction="row" spacing={2} sx={{ height: "100%" }}>
<Stack direction="column" sx={{ width: "45%" }}>
<h2>Code</h2>
<Stack direction="row" className="code-controls">
<Typography>
Step {step + 1}/{limit}
</Typography>
<Button
disabled={step === 0}
onClick={() => handleStep(step - 1)}
Expand All @@ -48,14 +42,23 @@ export default function App() {
>
Next
</Button>
</Stack>
<Box className="code-display">
<CodeDisplay
text={codeText}
startingLineNumber={
window.svgArray[0].lineNumber
}
highlightLine={window.svgArray[step].lineNumber}
/>
</Box>
</Box>
</Box>
<Box sx={{ width: "60%" }}>
<h2>Memory diagrams</h2>
<SvgDisplay step={step} />
</Box>
</Stack>
</main>
</Stack>
<Stack direction="column" sx={{ width: "55%" }}>
<h2>Memory visualization</h2>
<SvgDisplay step={step} />
</Stack>
</Stack>
</main>
</>
);
}
2 changes: 0 additions & 2 deletions webstepper/src/CodeDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from "react";
import SyntaxHighlighter from "react-syntax-highlighter";
import { a11yLight } from "react-syntax-highlighter/dist/esm/styles/hljs";
import { Box } from "@mui/material";
import "./css/styles.css";

type CodeDisplayPropTypes = {
text: string;
Expand All @@ -21,7 +20,6 @@ export default function CodeDisplay(props: CodeDisplayPropTypes) {
wrapLines={true}
wrapLongLines={true}
style={a11yLight}
customStyle={{ backgroundColor: "transparent" }}
lineProps={(lineNumber: number) => {
if (lineNumber == props.highlightLine) {
return { className: "code-box__line--highlighted" };
Expand Down
26 changes: 6 additions & 20 deletions webstepper/src/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,24 @@ export default function Header() {
: lightLogo;

return (
<header className="container">
<header className="container-fluid">
<Stack direction={"row"} justifyContent={"space-between"}>
<Box>
<h1 style={{ marginBottom: 0 }}>MemoryViz Stepper</h1>
<h1>MemoryViz Webstepper</h1>
<Typography variant="subtitle1">
A web debugger for the{" "}
A web-based interactive tool for visualizing Python
memory, based on the{" "}
<Link
href="https://github.com/david-yz-liu/memory-viz"
target="_blank"
rel="noopener noreferrer"
>
MemoryViz
</Link>{" "}
Javascript library for visualizing Python memory. Click{" "}
<Link
href="https://www.cs.toronto.edu/~david/memory-viz/docs/api/"
target="_blank"
rel="noopener noreferrer"
>
here
</Link>{" "}
for documentation.
Javascript library.
</Typography>
</Box>
<img
src={logo}
alt="MemoryViz Logo"
style={{
width: "100px",
objectFit: "contain",
}}
/>
<img src={logo} alt="MemoryViz Logo" className="logo" />
</Stack>
</header>
);
Expand Down
4 changes: 2 additions & 2 deletions webstepper/src/SvgDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useRef, useEffect } from "react";
import { Paper } from "@mui/material";
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
import "./css/styles.css";

type SvgDisplayPropTypes = {
step: number;
Expand Down Expand Up @@ -36,10 +35,11 @@ export default function SvgDisplay(props: SvgDisplayPropTypes) {
return (
<Paper
className="svg-display"
elevation={3}
sx={{ bgcolor: "primary.paper" }}
variant="outlined"
>
<TransformWrapper
centerZoomedOut={true}
minScale={0.2}
wheel={{ step: 0.2, smoothStep: 0.01 }}
>
Expand Down
2 changes: 1 addition & 1 deletion webstepper/src/__tests__/App.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("App", () => {
it("renders initial state correctly", async () => {
expect(screen.getByText(/Step \d+\/\d+/)).toBeInTheDocument();
expect(screen.getByText("Code")).toBeInTheDocument();
expect(screen.getByText("Memory diagrams")).toBeInTheDocument();
expect(screen.getByText("Memory visualization")).toBeInTheDocument();
});

it("handles next button click correctly", () => {
Expand Down
32 changes: 0 additions & 32 deletions webstepper/src/css/styles.css

This file was deleted.

61 changes: 61 additions & 0 deletions webstepper/src/css/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@use "@picocss/pico";

/* Override default picocss variables */
h1 {
--typography-spacing-vertical: 0.5rem;
}

h2 {
--typography-spacing-vertical: 0.5rem;
}

pre > code {
--spacing: 0.25rem;
}

html,
body {
height: 100%;
}

#root {
display: flex;
flex-direction: column;
height: 100%;
}

main {
flex: 1;
}

.code-controls {
align-items: center;
gap: 10px;

> button {
flex: 1;
}
}

.code-display__code-box > pre {
background-color: transparent;
}

.code-box__line--highlighted {
background-color: yellow;
}

.svg-display {
flex: 1;
margin-bottom: 1rem;
}

.react-transform-wrapper {
height: 100%;
width: 100%;
}

.logo {
object-fit: contain;
width: 100px;
}
2 changes: 1 addition & 1 deletion webstepper/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import "@picocss/pico";
import "./css/styles.scss";

import { createTheme, ThemeProvider } from "@mui/material/styles";
import { useMediaQuery } from "@mui/material";
Expand Down
4 changes: 4 additions & 0 deletions webstepper/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ module.exports = {
},
},
},
{
test: /\.s[ac]ss$/i,
use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
Expand Down

0 comments on commit 229a46e

Please sign in to comment.