import { ContentEditable } from "@common/components/ContentEditable"; import { highlight } from "@common/highlight"; import { useAppState, type Tab } from "../contexts/state"; import styles from '../assets/editor.module.css'; import { useMemo } from "preact/hooks"; import clsx from "clsx"; import { CharacterEditor } from "./character-editor"; import { LocationEditor } from "./location-editor"; import { ChaptersEditor } from "./chapters-editor"; import { LoreEditor } from "./lore-editor"; import { useInputCallback } from "@common/hooks/useInputCallback"; import Prompt from "../utils/prompt"; const TABS: { id: Tab; label: string; right?: boolean }[] = [ { id: "story", label: "Story" }, { id: "chapters", label: "Chapters" }, { id: "lore", label: "Lore" }, { id: "characters", label: "Characters" }, { id: "locations", label: "Locations" }, { id: "prompt", label: "Prompt", right: true }, ]; export const Editor = () => { const appState = useAppState(); const { currentStory, dispatch } = appState; const handleInput = useInputCallback((text: string) => { if (!currentStory) return; dispatch({ type: 'EDIT_STORY', id: currentStory.id, text, }); }, [currentStory?.id]); const handleTabChange = (tab: Tab) => { if (!currentStory) return; dispatch({ type: 'SET_CURRENT_TAB', id: currentStory.id, tab, }); }; const storyValue = useMemo(() => currentStory ? highlight(currentStory.text) : '', [currentStory?.text]); const promptPreview = useMemo(() => { if (currentStory?.currentTab !== 'prompt') return ''; const text = Prompt.formatSystemPrompt(appState); return highlight(text, false); }, [currentStory?.currentTab, appState]); if (!currentStory) { return
; } return (