Files
cobble/src/components/general/code-editor.tsx
T
tben bf533330b1
CI / check (push) Canceled after 0s
Release image / image (release) Canceled after 0s
Release image / computer-image (release) Canceled after 0s
Hold the drawer's computer preview until asked, and tell SSH computers apart
The Tools section streamed a bot's computer screen the moment the drawer
opened. It now shows the same block with a line and a Preview button, and
streams only once that is clicked.

Also show the bot's memory of the viewer in the drawer's settings tab, space
the panel fields so their labels stop overlapping, and draw an SSH computer
with a server icon instead of the container's monitor.
2026-11-24 16:50:51 +01:00

77 lines
2.1 KiB
TypeScript

import { useEffect, useRef } from "react";
import AceEditor from "@moduletrace/twui/editors/AceEditor";
import type AceEditorModes from "@moduletrace/twui/editors/ace-editor-modes";
import Span from "@moduletrace/twui/layout/Span";
import Stack from "@moduletrace/twui/layout/Stack";
import { twMerge } from "tailwind-merge";
import loadAceScripts from "@/src/utils/load-ace-scripts";
type Props = {
title: string;
/**
* The starting text. Changes come back through `onChange`.
*/
content?: string;
mode: (typeof AceEditorModes)[number];
placeholder?: string;
/**
* One line under it, like a field's info.
*/
info?: string;
/**
* Its height, e.g. `h-24`.
*/
className?: string;
/**
* Shows the text without letting it be edited; `onChange` is then never
* called.
*/
readOnly?: boolean;
onChange: (value: string) => void;
};
/**
* A code field: twui's `AceEditor` with its label, and a line of info
* under it. Loads the editor's scripts when it first shows
* (`loadAceScripts`).
*/
export default function CodeEditor({
title,
content,
mode,
placeholder,
info,
className,
readOnly,
onChange,
}: Props) {
/**
* The editor keeps the handler it was created with; this keeps it
* calling the latest one.
*/
const change = useRef(onChange);
change.current = onChange;
useEffect(() => {
loadAceScripts().catch(() => {});
}, []);
return (
<Stack className="w-full gap-1.5! items-stretch">
<AceEditor
title={title}
showLabel
content={content}
mode={mode}
placeholder={placeholder}
readOnly={readOnly}
fontSize="13px"
delay={0}
wrapperProps={{ className: twMerge("h-40", className) }}
onChange={(value) => change.current(value)}
/>
{info ? <Span className="text-[13px] leading-[18px] text-ink-secondary">{info}</Span> : null}
</Stack>
);
}