From 6e879396b7767688bce9f0d2cdebbd990c193676 Mon Sep 17 00:00:00 2001 From: Josep Boix Requesens Date: Sat, 6 Apr 2024 01:49:30 +0200 Subject: [PATCH] feat: add toggle pane button for theme editor file navigation Introduces a new `TogglePaneButton` component, aimed at displaying a virtual file system in order to edit the multiple `scss` files found in the pillarbox default theme. When a file in the tree view is selected, its content is loaded into the theme editor for modification and previewing. ***Example*** ```html Hello World! `` --- .prebuild.js | 5 +- index.html | 7 +- scss/index.scss | 6 ++ src/components/css-editor.js | 37 +++++---- src/components/preview-box.js | 4 +- src/components/resizable-bar.js | 6 ++ src/components/toggle-pane-button.js | 95 ++++++++++++++++++++++ src/components/toggle-pane-button.scss | 57 +++++++++++++ src/components/tree-view.js | 18 ++-- src/components/tree-view.scss | 2 +- src/index.js | 22 ++++- src/workspace/sass-workspace-compiler.js | 11 +-- test/components/preview-box.test.js | 2 +- test/components/toggle-pane-button.test.js | 68 ++++++++++++++++ 14 files changed, 303 insertions(+), 37 deletions(-) create mode 100644 src/components/toggle-pane-button.js create mode 100644 src/components/toggle-pane-button.scss create mode 100644 test/components/toggle-pane-button.test.js diff --git a/.prebuild.js b/.prebuild.js index 575d2a8..fdd9765 100644 --- a/.prebuild.js +++ b/.prebuild.js @@ -3,7 +3,8 @@ * recursively includes all the files and their content to create json * representation of the workspace for the theme editor. */ -import { readdirSync, statSync, readFileSync, writeFileSync } from 'fs'; +import { mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'fs'; +import * as path from 'path'; import { join } from 'path'; const isDebugEnabled = process.argv.includes('--debug'); @@ -55,9 +56,11 @@ try { // Define the output path for the generated workspace structure JSON file. const outputPath = './src/assets/pillarbox-scss-workspace.json'; + const outputDir = path.dirname(outputPath); // Write the structured workspace to a JSON file, pretty-printed. console.log(`Writing the workspace structure to ${outputPath}...`); + mkdirSync(outputDir, { recursive: true }); writeFileSync(outputPath, JSON.stringify(structure, null, 2), 'utf-8'); console.log(`Successfully wrote the workspace structure to ${outputPath}`); diff --git a/index.html b/index.html index 50b3161..2a5badd 100644 --- a/index.html +++ b/index.html @@ -19,7 +19,12 @@

Pillarbo
-

Craft your theme

+
+

Craft your theme

+ + + +
diff --git a/scss/index.scss b/scss/index.scss index fa9bc2e..afd7bdd 100644 --- a/scss/index.scss +++ b/scss/index.scss @@ -81,6 +81,12 @@ footer { } } +.craft-title-container { + display: flex; + gap: 1em; + align-items: center; +} + /* * TODO: Adjust .monaco-container dimensions to ensure full parent coverage. * diff --git a/src/components/css-editor.js b/src/components/css-editor.js index ad409df..24449fd 100644 --- a/src/components/css-editor.js +++ b/src/components/css-editor.js @@ -4,18 +4,6 @@ import * as monaco from 'monaco-editor'; import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'; import CssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker'; -const initialStyle = ` -/* Turn the progress bar white */ -.pillarbox-js .vjs-play-progress { - color: white; - background-color: white; -} - -/* Show the scrubber */ -.pillarbox-js .vjs-play-progress::before { - font-size: 0.9em; -}`.trim(); - self.MonacoEnvironment = { getWorker: function(_, label) { if (label === 'css' || label === 'scss' || label === 'less') { @@ -45,6 +33,14 @@ class CssEditor extends LitElement { theme: { type: String } }; + /** + * Holds the initial value passed to this css editor. + * + * @type string + * @private + */ + #initialValue = ''; + constructor() { super(); this.container = createRef(); @@ -93,7 +89,20 @@ class CssEditor extends LitElement { * @returns {String} The current content of the editor. */ getValue() { - return this.editor ? this.editor.getValue() : initialStyle; + return this.editor ? this.editor.getValue() : this.#initialValue; + } + + /** + * Set the new content of the Monaco Editor. + * + * @param value {string} The new content fo the editor. + */ + setValue(value) { + if (!this.editor) { + this.#initialValue = value; + } else { + this.editor.setValue(value); + } } /** @@ -104,7 +113,7 @@ class CssEditor extends LitElement { super.firstUpdated(_changedProperties); this.editor = monaco.editor.create(this.container.value, { - value: initialStyle, + value: this.#initialValue, language: 'scss', theme: this.getTheme(), automaticLayout: true, diff --git a/src/components/preview-box.js b/src/components/preview-box.js index a32c4d5..b96a138 100644 --- a/src/components/preview-box.js +++ b/src/components/preview-box.js @@ -1,7 +1,6 @@ import { html, LitElement } from 'lit'; import { createRef, ref } from 'lit/directives/ref.js'; import pillarbox from '@srgssr/pillarbox-web'; -import pbStyle from '@srgssr/pillarbox-web/dist/pillarbox.min.css?inline'; /** * `PreviewBox` is a LitElement component that creates a pillarbox player @@ -32,7 +31,6 @@ class PreviewBox extends LitElement { */ render() { return html` -