From d5d6282643a05042736f73ca2e5958e3c05e8cac Mon Sep 17 00:00:00 2001 From: sehilyi Date: Fri, 15 Nov 2024 11:55:38 -0500 Subject: [PATCH] adding theme editor to Gosling editor --- editor/Editor.tsx | 66 +++++++++++++++++++++++++++++++----------- editor/EditorPanel.tsx | 19 +++++++----- 2 files changed, 61 insertions(+), 24 deletions(-) diff --git a/editor/Editor.tsx b/editor/Editor.tsx index c681760e..7e435cda 100644 --- a/editor/Editor.tsx +++ b/editor/Editor.tsx @@ -23,7 +23,7 @@ import { getHtmlTemplate } from './html-template'; import ErrorBoundary from './error-boundary'; import { traverseTracksAndViews } from '../src/compiler/spec-preprocess'; import { examples, type Example } from './example'; -import EditorPanel, { type EditorLangauge } from './EditorPanel'; +import EditorPanel, { type EditorCodeType } from './EditorPanel'; import EditorExamples from './EditorExamples'; import './Editor.css'; @@ -131,6 +131,8 @@ const validateExampleId = (id: string): boolean => { const getDescPanelDefultWidth = () => Math.min(500, window.innerWidth); +const isDarkTheme = (t: gosling.Theme) => (typeof t !== 'string' && 'base' in t ? t.base === 'dark' : t === 'dark'); + /** * Convert relative CSV data URLs to absolute URLs. * (e.g., './example.csv' => 'https://gist.githubusercontent.com/{urlGist}/raw/example.csv') @@ -237,7 +239,7 @@ function Editor(props: RouteComponentProps) { examples[urlExampleId] ? { id: urlExampleId, ...examples[urlExampleId] } : INIT_DEMO ); const [isImportDemo, setIsImportDemo] = useState(false); - const [theme, setTheme] = useState('light'); // or `{ base: 'light', axis: { labelMargin: -1 } }` + const [theme, setTheme] = useState({ base: 'light' }); // 'light' or `{ base: 'light', axis: { labelMargin: -1 } }` const [hg, setHg] = useState(); const [code, setCode] = useState(defaultCode); const [jsCode, setJsCode] = useState(defaultJsCode); //[TO-DO: more js format examples] @@ -300,9 +302,11 @@ function Editor(props: RouteComponentProps) { const gosRef = useRef(null); const debounceCodeEdit = useRef( - debounce((code: string, language: EditorLangauge) => { - if (language == 'json') { + debounce((code: string, codeType: EditorCodeType) => { + if (codeType == 'gosling-json') { setCode(code); + } else if (codeType == 'gosling-theme') { + setTheme(JSON.parse(code)); } else { setJsCode(code); } @@ -744,7 +748,7 @@ function Editor(props: RouteComponentProps) { return ( <>
{ // if (!gosRef.current) return; @@ -849,10 +853,10 @@ function Editor(props: RouteComponentProps) { ) : null}
{/* ------------------------ Main View ------------------------ */} -
+
-
+
+
+
+
+
@@ -1180,15 +1212,15 @@ function Editor(props: RouteComponentProps) { {/* HiGlass View Config */} -
+
Compiled HiGlass ViewConfig (Read Only)
@@ -1198,7 +1230,7 @@ function Editor(props: RouteComponentProps) {
{isResponsive && !IS_SMALL_SCREEN ? ResponsiveWidget : null}