Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions frontend/app/monaco/monaco-react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { loadMonaco } from "@/app/monaco/monaco-env";
import type * as MonacoTypes from "monaco-editor";
import * as monaco from "monaco-editor";
import { useEffect, useRef } from "react";
import { debounce } from "throttle-debounce";

function createModel(value: string, path: string, language?: string) {
const uri = monaco.Uri.parse(`wave://editor/${encodeURIComponent(path)}`);
Expand Down Expand Up @@ -72,6 +73,23 @@ export function MonacoCodeEditor({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
const editor = editorRef.current;
const el = divRef.current;
if (!editor || !el) return;

const debouncedLayout = debounce(100, () => {
editor.layout();
});
const resizeObserver = new ResizeObserver(debouncedLayout);
resizeObserver.observe(el);

return () => {
resizeObserver.disconnect();
debouncedLayout.cancel();
};
}, []);

// Keep model value in sync with props
useEffect(() => {
const editor = editorRef.current;
Expand Down Expand Up @@ -145,6 +163,23 @@ export function MonacoDiffViewer({ original, modified, language, path, options }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
const diff = diffRef.current;
const el = divRef.current;
if (!diff || !el) return;

const debouncedLayout = debounce(100, () => {
diff.layout();
});
const resizeObserver = new ResizeObserver(debouncedLayout);
resizeObserver.observe(el);

return () => {
resizeObserver.disconnect();
debouncedLayout.cancel();
};
}, []);

// Update models on prop change
useEffect(() => {
const diff = diffRef.current;
Expand Down
23 changes: 4 additions & 19 deletions frontend/app/view/waveconfig/waveconfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { adaptFromReactOrNativeKeyEvent, checkKeyPressed, keydownWrapper } from
import { cn } from "@/util/util";
import { useAtom, useAtomValue } from "jotai";
import type * as MonacoTypes from "monaco-editor";
import { memo, useCallback, useEffect, useRef } from "react";
import { debounce } from "throttle-debounce";
import { memo, useCallback, useEffect } from "react";

interface ConfigSidebarProps {
model: WaveConfigViewModel;
Expand Down Expand Up @@ -97,7 +96,6 @@ const WaveConfigView = memo(({ blockId, model }: ViewComponentProps<WaveConfigVi
const [isMenuOpen, setIsMenuOpen] = useAtom(model.isMenuOpenAtom);
const hasChanges = useAtomValue(model.hasEditedAtom);
const [activeTab, setActiveTab] = useAtom(model.activeTabAtom);
const editorContainerRef = useRef<HTMLDivElement>(null);

const handleContentChange = useCallback(
(newContent: string) => {
Expand Down Expand Up @@ -147,20 +145,6 @@ const WaveConfigView = memo(({ blockId, model }: ViewComponentProps<WaveConfigVi
return () => window.removeEventListener("keydown", handleKeyDown);
}, [hasChanges, isSaving, model]);

useEffect(() => {
if (!editorContainerRef.current) {
return;
}
const debouncedLayout = debounce(100, () => {
if (model.editorRef.current) {
model.editorRef.current.layout();
}
});
const resizeObserver = new ResizeObserver(debouncedLayout);
resizeObserver.observe(editorContainerRef.current);
return () => resizeObserver.disconnect();
}, [model]);

const saveTooltip = `Save (${model.saveShortcut})`;

return (
Expand All @@ -171,7 +155,7 @@ const WaveConfigView = memo(({ blockId, model }: ViewComponentProps<WaveConfigVi
<div className={`h-full ${isMenuOpen ? "" : "@max-w600:hidden"}`}>
<ConfigSidebar model={model} />
</div>
<div ref={editorContainerRef} className="flex flex-col flex-1 min-w-0">
<div className="flex flex-col flex-1 min-w-0">
{selectedFile && (
<>
<div className="flex flex-row items-center justify-between px-4 py-2 border-b border-border">
Expand Down Expand Up @@ -279,7 +263,8 @@ const WaveConfigView = memo(({ blockId, model }: ViewComponentProps<WaveConfigVi
<div className="flex items-center justify-center h-full text-muted-foreground">
Loading...
</div>
) : selectedFile.visualComponent && (!selectedFile.hasJsonView || activeTab === "visual") ? (
) : selectedFile.visualComponent &&
(!selectedFile.hasJsonView || activeTab === "visual") ? (
(() => {
const VisualComponent = selectedFile.visualComponent;
return <VisualComponent model={model} />;
Expand Down
Loading