diff --git a/lib/forge-std b/lib/forge-std index c19dfd2..87c27a3 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit c19dfd2f2a88a461216b0dd1f4961e1a85dcad46 +Subproject commit 87c27a333ed67b8e09c46a9ebf4606421fadfe47 diff --git a/packages/inspector/components/RawSVGViewer.tsx b/packages/inspector/components/SVGViewer.tsx similarity index 79% rename from packages/inspector/components/RawSVGViewer.tsx rename to packages/inspector/components/SVGViewer.tsx index 38ec98c..3cb2681 100644 --- a/packages/inspector/components/RawSVGViewer.tsx +++ b/packages/inspector/components/SVGViewer.tsx @@ -1,10 +1,10 @@ import { useEffect, useRef } from "react"; import { downloadSVG, downloadPNG, scaleCanvas } from "../util/index"; -type RawSVGViewerProps = { +type SVGViewerProps = { debug?: boolean; className?: string; - rawSVG: string; + svg: string; isLoading?: boolean; tokenId: number; }; @@ -12,7 +12,7 @@ type RawSVGViewerProps = { const WIDTH = 1200; const HEIGHT = 1200; -export function RawSVGViewer(props: RawSVGViewerProps) { +export function SVGViewer(props: SVGViewerProps) { const canvasRef = useRef(null); useEffect(() => { @@ -21,7 +21,7 @@ export function RawSVGViewer(props: RawSVGViewerProps) { return (
@@ -62,7 +62,7 @@ export function RawSVGViewer(props: RawSVGViewerProps) { ); } -RawSVGViewer.defaultProps = { +SVGViewer.defaultProps = { debug: false, className: "", }; diff --git a/packages/inspector/components/TraitsTable.tsx b/packages/inspector/components/TraitsTable.tsx index 5f74515..45ffa2a 100644 --- a/packages/inspector/components/TraitsTable.tsx +++ b/packages/inspector/components/TraitsTable.tsx @@ -18,7 +18,10 @@ export const TraitsTable = ({ {name} {attributes.map(({ trait_type, value }, i) => ( - + {trait_type} {value} diff --git a/packages/inspector/hooks/useSVG.tsx b/packages/inspector/hooks/useFormattedSVG.tsx similarity index 55% rename from packages/inspector/hooks/useSVG.tsx rename to packages/inspector/hooks/useFormattedSVG.tsx index acab0e6..b5d8d4e 100644 --- a/packages/inspector/hooks/useSVG.tsx +++ b/packages/inspector/hooks/useFormattedSVG.tsx @@ -1,37 +1,36 @@ import { useState, useEffect } from "react"; // import babelParser from 'prettier/parser-babel' -import htmlParser from 'prettier/parser-html' -import prettier from 'prettier/standalone' +import htmlParser from "prettier/parser-html"; +import prettier from "prettier/standalone"; const options = { - parser: 'html', + parser: "html", plugins: [htmlParser], tabWidth: 2, semi: false, singleQuote: false, bracketSameLine: true, -} +}; function formatSVG(code: string) { - return prettier.format(code, options) + return prettier.format(code, options); } - -export const useSvg = (svg: string) => { - const [formatted, setFormatted] = useState(""); +export const useFormattedSvg = (svg: string) => { + const [formattedSvg, setFormattedSvg] = useState(""); const [error, setError] = useState(""); useEffect(() => { try { if (svg === null) { - setFormatted(""); + setFormattedSvg(""); } else { - setFormatted(formatSVG(svg)); + setFormattedSvg(formatSVG(svg)); } } catch (e) { setError(e.message); } }, [svg]); - return { formatted, error }; + return { formattedSvg, error }; }; diff --git a/packages/inspector/hooks/useNFT.tsx b/packages/inspector/hooks/useNFT.tsx index 01d7b79..245bd6a 100644 --- a/packages/inspector/hooks/useNFT.tsx +++ b/packages/inspector/hooks/useNFT.tsx @@ -1,6 +1,6 @@ import { useState, useEffect } from "react"; import { decodeBase64 } from "../util"; -import { trait, NFTState } from "../types"; +import { NFTState } from "../types"; const defaultState = { metadata: { @@ -9,7 +9,7 @@ const defaultState = { attributes: [], }, tokenId: null, - rawSVG: null, + svg: null, }; export const useNFT = (tokenURI: string) => { @@ -18,14 +18,14 @@ export const useNFT = (tokenURI: string) => { useEffect(() => { if (tokenURI == null) return; // decode and parse metadata - console.log(decodeBase64(tokenURI)) + console.log(decodeBase64(tokenURI)); const metadata = JSON.parse(decodeBase64(tokenURI)); const tokenId = metadata.tokenId; // decode svg - const rawSVG = decodeBase64(metadata.image); - setState({ metadata, tokenId, rawSVG }); + const svg = decodeBase64(metadata.image); + setState({ metadata, tokenId, svg }); }, [tokenURI]); return { ...state }; diff --git a/packages/inspector/pages/index.tsx b/packages/inspector/pages/index.tsx index 774fac8..49cd98b 100644 --- a/packages/inspector/pages/index.tsx +++ b/packages/inspector/pages/index.tsx @@ -1,42 +1,42 @@ import { useState } from "react"; import SyntaxHighlighter from "react-syntax-highlighter"; -import { xml } from '@codemirror/lang-xml' -import { EditorView } from '@codemirror/view' -import { basicSetup } from 'codemirror' -import CodeMirror from '@uiw/react-codemirror' -import { syntaxHighlighting, bracketMatching, foldGutter, codeFolding } from '@codemirror/language' -import { highlightDark, themeDark } from '../components/CodeMirrorTheme' +import { xml } from "@codemirror/lang-xml"; +import { EditorView } from "@codemirror/view"; +import { basicSetup } from "codemirror"; +import CodeMirror from "@uiw/react-codemirror"; +import { syntaxHighlighting, bracketMatching, foldGutter, codeFolding } from "@codemirror/language"; +import { highlightDark, themeDark } from "../components/CodeMirrorTheme"; import { NFTStatus, IndexView } from "../types"; import { useLocalRender } from "../hooks/useLocalRender"; import { useNFT } from "../hooks/useNFT"; -import { useSvg } from "../hooks/useSVG"; +import { useFormattedSvg } from "../hooks/useFormattedSVG"; import { Container } from "../components/Container"; import { Pane } from "../components/Pane"; import { HorizontalRule } from "../components/HorizontalRule"; import { Toolbar } from "../components/Toolbar"; import { VerticalRule } from "../components/VerticalRule"; import { Button } from "../components/Button"; -import { RawSVGViewer } from "../components/RawSVGViewer"; +import { SVGViewer } from "../components/SVGViewer"; import { ToggleButton } from "../components/ToggleButton"; import { TraitsTable } from "../components/TraitsTable"; export default function Index() { const { tokenURI, status, handleFetchNFT } = useLocalRender(); - const { metadata, tokenId, rawSVG } = useNFT(tokenURI); + const { metadata, tokenId, svg } = useNFT(tokenURI); const [debug, setDebug] = useState(false); - const { formatted, error } = useSvg(rawSVG); + const { formattedSvg, error } = useFormattedSvg(svg); - const loc = formatted.split(/\r\n|\r|\n/).length; - const kb = ((new TextEncoder().encode(rawSVG)).length * 0.001).toFixed(3) + const loc = formattedSvg.split(/\r\n|\r|\n/).length; + const kb = (new TextEncoder().encode(svg).length * 0.001).toFixed(3); return (
-
- { - error.length === 0 ? ( - null - ) : + {error.length === 0 ? null : ( <> -
-
- Error parsing SVG +
+
Error parsing SVG
+
{error}
-
{error}
-
- } + )}
@@ -86,9 +82,14 @@ export default function Index() {
-
{loc}
LOC
-
{kb}
kb
- +
+
{loc}
+
LOC
+
+
+
{kb}
+
kb
+
@@ -97,7 +98,12 @@ export default function Index() {
- +