From 96acaddf77878e60bc6cf9cb1d43af37728096f1 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 25 Jan 2024 15:35:52 +0800 Subject: [PATCH] Optimize Playground --- .../Playground/CodeEditor/FileSelector/index.tsx | 6 ++++++ src/components/Playground/CodeEditor/index.tsx | 3 +++ .../Playground/Output/Preview/Render.tsx | 2 ++ .../Playground/Output/Preview/iframe.html | 7 +------ .../Playground/Output/Preview/index.tsx | 8 +++++--- .../Playground/Output/Preview/preview.scss | 5 ----- .../Playground/Output/Preview/render.scss | 6 ++++++ src/components/Playground/Output/index.tsx | 8 +++++--- src/components/Playground/compiler.ts | 16 ++++++++-------- src/components/Playground/index.tsx | 16 ++++++++++++++-- src/pages/System/Tools/Base.tsx | 10 ++++++---- src/pages/System/Tools/Template.tsx | 4 ++-- 12 files changed, 58 insertions(+), 33 deletions(-) create mode 100644 src/components/Playground/Output/Preview/render.scss diff --git a/src/components/Playground/CodeEditor/FileSelector/index.tsx b/src/components/Playground/CodeEditor/FileSelector/index.tsx index aa2cb62..b86cb55 100644 --- a/src/components/Playground/CodeEditor/FileSelector/index.tsx +++ b/src/components/Playground/CodeEditor/FileSelector/index.tsx @@ -110,6 +110,10 @@ const FileSelector = ({ } const handleOnValidateTab = (newFileName: string, oldFileName: string) => { + if (newFileName.length > 40) { + onError?.('File name is too long, maximum 40 characters.') + } + if (!/\.(jsx|tsx|js|ts|css|json)$/.test(newFileName)) { onError?.('Playground only supports *.jsx, *.tsx, *.js, *.ts, *.css, *.json files.') @@ -219,4 +223,6 @@ const FileSelector = ({ ) } +FileSelector.Item = Item + export default FileSelector diff --git a/src/components/Playground/CodeEditor/index.tsx b/src/components/Playground/CodeEditor/index.tsx index 938aa66..b2d70d6 100644 --- a/src/components/Playground/CodeEditor/index.tsx +++ b/src/components/Playground/CodeEditor/index.tsx @@ -160,4 +160,7 @@ const CodeEditor = ({ ) } +CodeEditor.Editor = Editor +CodeEditor.FileSelector = FileSelector + export default CodeEditor diff --git a/src/components/Playground/Output/Preview/Render.tsx b/src/components/Playground/Output/Preview/Render.tsx index 940a80f..62464d2 100644 --- a/src/components/Playground/Output/Preview/Render.tsx +++ b/src/components/Playground/Output/Preview/Render.tsx @@ -1,3 +1,4 @@ +import '@/components/Playground/Output/Preview/render.scss' import iframeRaw from '@/components/Playground/Output/Preview/iframe.html?raw' interface RenderProps { @@ -66,6 +67,7 @@ const Render = ({ iframeKey, compiledCode, onError }: RenderProps) => { return (