import { useRef, useState } from "react"; import { createRoot } from "react-dom/client"; import { LexicalComposer } from "@lexical/react/LexicalComposer"; import { PlainTextPlugin } from "@lexical/react/LexicalPlainTextPlugin"; import { ContentEditable } from "@lexical/react/LexicalContentEditable"; import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary"; import { MentionPlugin } from "@/mentions/MentionPlugin.js"; import { PromptMentionNode } from "@/mentions/nodes/PromptMentionNode.js"; import { ChatPromptActionMenu } from "@/prompt-editor/ChatPromptActionMenu.js"; import type { LexicalChatInputHandle } from "@/LexicalChatInput.js"; import { ServiceProvider } from "@/hooks/useServices.js"; import { StoreContext } from "@/store/StoreProvider.js"; import { createZCodeStore } from "@/store/index.js"; import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js"; import { TooltipProvider } from "@/components/ui/tooltip.js"; import type { IBroadcastService, IServiceAccessor } from "@zcode/services"; import "@/styles.css"; const params = new URLSearchParams(location.search); const store = createZCodeStore({ send: async () => {}, onMessage: () => ({ dispose() {} }), } as unknown as IBroadcastService); store.getState().setInterfaceMode("coding"); store.getState().setTheme(params.get("theme") === "light" ? "light" : "dark"); const services = { pluginManagementService: { getPluginReferenceCatalog: async (params: unknown) => { const response = await fetch("/catalog", { method: "POST", body: JSON.stringify(params) }); if (!response.ok) throw new Error("catalog unavailable"); return response.json(); }, }, zcodeAgentService: { onAgentRuntimeRestarted: () => ({ dispose() {} }) }, clientConfigService: { getSnapshot: async () => { const response = await fetch("/order"); if (!response.ok) throw new Error("config unavailable"); return { pluginStoreOrder: await response.json() }; }, }, } as unknown as IServiceAccessor; function Fixture() { const [container, setContainer] = useState(null); const [sessionId, setSessionId] = useState("frozen-session"); const [selected, setSelected] = useState(""); const input = useRef({ getText: () => "", focus: () => document.querySelector('[data-testid="editor"]')?.focus(), getEditorState: () => undefined, insertMention: (item: { value: string }) => setSelected(item.value), } as unknown as LexicalChatInputHandle); return (
{selected}
{ throw error; }, }} > } placeholder={null} ErrorBoundary={LexicalErrorBoundary} />
); } createRoot(document.getElementById("root")!).render( , );