Skip to content

Commit c20c1c1

Browse files
committed
feat: implement split view for HTML editor with preview functionality
- Added a split view mode to the HTML editor, allowing simultaneous editing and previewing of HTML content. - Introduced HtmlEditorSplitView component to manage the rendering of the editor and preview side by side. - Enhanced useHtmlEditor hook to support active state management and preview toggling. - Updated Editor and HtmlEditor components to integrate new split view features and improve user experience. - Refactored styles in Editor.scss and HtmlEditor.scss to accommodate the new layout and ensure responsive design.
1 parent 4194206 commit c20c1c1

File tree

8 files changed

+343
-116
lines changed

8 files changed

+343
-116
lines changed

src/frontend/src/pad/editors/Editor.scss

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,25 @@
66
overflow: hidden; /* Prevent overflow issues */
77
border-bottom-left-radius: 20px;
88
border-bottom-right-radius: 20px;
9+
10+
&--split {
11+
.monaco-editor {
12+
width: 50% !important; /* Force Monaco editor to resize */
13+
}
14+
15+
.editor__container {
16+
width: 50% !important; /* Force container to resize */
17+
}
18+
19+
.editor__toolbar {
20+
right: 50%; /* Limit toolbar width to match the editor in split view */
21+
}
22+
}
923
}
1024

1125
&__toolbar {
1226
display: flex;
13-
justify-content: space-between; /* Space between HTML controls and right-side controls */
27+
justify-content: flex-end; /* Default justify to the right when no HTML controls */
1428
padding: 8px;
1529
position: absolute; /* Position at bottom */
1630
bottom: 0;

src/frontend/src/pad/editors/Editor.tsx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useRef, useState, useEffect, useCallback } from 'react';
22
import MonacoEditor from '@monaco-editor/react';
33
import { Tooltip, updateTooltipPosition, getTooltipDiv } from '@atyrode/excalidraw';
44
import SearchableLanguageSelector from './SearchableLanguageSelector';
5-
import { useHtmlEditor, HtmlEditorControls, defaultHtml } from './HtmlEditor';
5+
import { useHtmlEditor, HtmlEditorControls, defaultHtml, HtmlEditorSplitView } from './HtmlEditor';
66
import './Editor.scss';
77

88
// Custom tooltip wrapper that positions the tooltip at the top
@@ -295,16 +295,22 @@ const Editor: React.FC<EditorProps> = ({
295295
}
296296
};
297297

298-
// Initialize HTML editor functionality if the language is HTML
298+
// Check if the language is HTML
299299
const isHtml = currentLanguage === 'html';
300300

301-
// Only initialize HTML editor hooks if we're in HTML mode and have the necessary props
302-
const htmlEditor = isHtml && element && excalidrawAPI
303-
? useHtmlEditor(element, editorRef, excalidrawAPI)
304-
: null;
301+
// Always initialize HTML editor hooks, but pass isActive flag
302+
const htmlEditor = useHtmlEditor(
303+
element,
304+
editorRef,
305+
excalidrawAPI,
306+
isHtml
307+
);
308+
309+
// Determine if we should show the split view
310+
const showSplitView = isHtml && !htmlEditor.createNew && htmlEditor.showPreview;
305311

306312
return (
307-
<div className="editor__wrapper">
313+
<div className={`editor__wrapper ${showSplitView ? 'editor__wrapper--split' : ''}`}>
308314
<MonacoEditor
309315
height={height}
310316
language={currentLanguage}
@@ -315,15 +321,26 @@ const Editor: React.FC<EditorProps> = ({
315321
onChange={handleEditorChange}
316322
className={className}
317323
/>
324+
325+
{/* Render the HTML preview in split view mode */}
326+
{showSplitView && (
327+
<HtmlEditorSplitView
328+
editorContent={contentRef.current || ''}
329+
previewContent={htmlEditor.previewContent}
330+
showPreview={htmlEditor.showPreview}
331+
/>
332+
)}
318333
{showLanguageSelector && (
319334
<div className="editor__toolbar">
320335
{/* Show HTML-specific controls when language is HTML */}
321-
{isHtml && htmlEditor && (
336+
{isHtml && (
322337
<div className="editor__html-controls">
323338
<HtmlEditorControls
324339
createNew={htmlEditor.createNew}
325340
setCreateNew={htmlEditor.setCreateNew}
326341
applyHtml={htmlEditor.applyHtml}
342+
showPreview={htmlEditor.showPreview}
343+
togglePreview={htmlEditor.togglePreview}
327344
/>
328345
</div>
329346
)}
Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,4 @@
11
.html-editor {
2-
&__container {
3-
display: flex;
4-
position: relative;
5-
width: 100%;
6-
height: 100%;
7-
flex-direction: column;
8-
box-sizing: border-box;
9-
padding: 32px;
10-
font-family: sans-serif;
11-
background: #2d2d2d;
12-
color: #e0e0e0;
13-
border-radius: 4px;
14-
border: 1px solid #484848;
15-
}
16-
17-
&__content {
18-
width: 100%;
19-
height: 100%;
20-
display: flex;
21-
flex-direction: column;
22-
position: relative;
23-
}
24-
25-
&__monaco-container {
26-
width: 100%;
27-
position: relative;
28-
flex: 1;
29-
min-height: 0;
30-
border: 1px solid #484848;
31-
border-radius: 4px;
32-
margin-bottom: 10px;
33-
}
34-
35-
&__controls {
36-
position: relative;
37-
display: flex;
38-
justify-content: space-between;
39-
align-items: center;
40-
padding: 8px 0;
41-
width: 100%;
42-
flex-shrink: 0;
43-
}
44-
452
&__label {
463
font-size: 12px;
474
color: #e0e0e0;
@@ -58,9 +15,38 @@
5815
border-radius: 4px;
5916
cursor: pointer;
6017
font-size: 12px;
18+
margin-right: 8px;
6119

6220
&:hover {
6321
background: #4285e7;
6422
}
23+
24+
&--active {
25+
background: #3a75c4;
26+
}
27+
}
28+
29+
&__split-view {
30+
position: absolute;
31+
top: 0;
32+
right: 0;
33+
width: 50%;
34+
height: 100%;
35+
box-sizing: border-box;
36+
z-index: 5;
37+
background: #ffffff00;
38+
border-left: 2px solid #484848;
39+
box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
40+
}
41+
}
42+
43+
// Split view styles for the editor container
44+
.editor__wrapper.editor__wrapper--split {
45+
.monaco-editor {
46+
width: 50% !important; /* Force Monaco editor to resize */
47+
}
48+
49+
.editor__container {
50+
width: 50% !important; /* Force container to resize */
6551
}
6652
}

0 commit comments

Comments
 (0)