From e8650951ea652e26979319ba5eb56a7daa05f682 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Tue, 31 Jan 2023 17:37:22 -0500 Subject: [PATCH] [playground] Add diff view toggle Quick hack to show a diff view comparing previous pass to current. Default is the output view ![Screenshot 2023-01-31 at 5 37 09 PM](https://user-images.githubusercontent.com/1390709/215899637-672d578a-6fb9-4580-ae87-ae0be0878a59.png) ![Screenshot 2023-01-31 at 5 37 12 PM](https://user-images.githubusercontent.com/1390709/215899640-7aff3c06-fc67-476a-82f9-59d65b4f9ac4.png) --- .../playground/components/Editor/Output.tsx | 119 +++++++++++++++--- .../playground/components/TabbedWindow.tsx | 2 +- 2 files changed, 100 insertions(+), 21 deletions(-) diff --git a/compiler/forget/packages/playground/components/Editor/Output.tsx b/compiler/forget/packages/playground/components/Editor/Output.tsx index ac52b9ebb7..94b252927b 100644 --- a/compiler/forget/packages/playground/components/Editor/Output.tsx +++ b/compiler/forget/packages/playground/components/Editor/Output.tsx @@ -7,7 +7,7 @@ import generate from "@babel/generator"; import * as t from "@babel/types"; -import MonacoEditor from "@monaco-editor/react"; +import MonacoEditor, { DiffEditor } from "@monaco-editor/react"; import { type CompilerError } from "babel-plugin-react-forget"; import prettier from "prettier"; import prettierParserBabel from "prettier/parser-babel"; @@ -15,6 +15,12 @@ import { memo, useMemo, useState } from "react"; import { type Store } from "../../lib/stores"; import TabbedWindow from "../TabbedWindow"; import { monacoOptions } from "./monacoOptions"; +import { + CodeIcon, + DocumentAddIcon, + InformationCircleIcon, +} from "@heroicons/react/outline"; + const MemoizedOutput = memo(Output); export default MemoizedOutput; @@ -86,8 +92,17 @@ function tabify(source: string, compilerOutput: CompilerOutput) { } } } + let lastPassOutput: string | null = null; for (const [passName, text] of concattedResults) { - tabs.set(passName, ); + tabs.set( + passName, + + ); + lastPassOutput = text; } // Ensure that JS and the JS source map come first if (topLevelFnDecls.length > 0) { @@ -95,7 +110,14 @@ function tabify(source: string, compilerOutput: CompilerOutput) { // FunctionDeclarations const ast = t.program(topLevelFnDecls); const { code, sourceMapUrl } = codegen(ast, source); - reorderedTabs.set("JS", ); + reorderedTabs.set( + "JS", + + ); if (sourceMapUrl) { reorderedTabs.set( "SourceMap", @@ -164,13 +186,16 @@ function Output({ store, compilerOutput }: Props) { tabs={tabs} /> {compilerOutput.kind === "err" ? ( -
+

COMPILER ERRORS

             {compilerOutput.error.toString()}
           
@@ -180,24 +205,78 @@ function Output({ store, compilerOutput }: Props) { ); } -function TextTabContent({ output }: { output: string }) { +function TextTabContent({ + output, + diff, + showInfoPanel, +}: { + output: string; + diff: string | null; + showInfoPanel: boolean; +}) { + const [value, setValue] = useState(output); return ( // Restrict MonacoEditor's height, since the config autoLayout:true // will grow the editor to fit within parent element
- + {showInfoPanel ? ( +
+ {diff != null && output !== diff ? ( + + ) : ( + <> + + No changes from + previous pass + + + )} +
+ ) : null} + {diff != null && value !== output ? ( + + ) : ( + + )}
); } diff --git a/compiler/forget/packages/playground/components/TabbedWindow.tsx b/compiler/forget/packages/playground/components/TabbedWindow.tsx index b1ab3aad19..8251f52ed9 100644 --- a/compiler/forget/packages/playground/components/TabbedWindow.tsx +++ b/compiler/forget/packages/playground/components/TabbedWindow.tsx @@ -68,7 +68,7 @@ function TabbedWindowItem({ return (
{isShow ? ( -
+