file-mention-host-search.fixture.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { useState } from "react";
  2. import { createRoot } from "react-dom/client";
  3. import { LexicalComposer } from "@lexical/react/LexicalComposer";
  4. import { PlainTextPlugin } from "@lexical/react/LexicalPlainTextPlugin";
  5. import { ContentEditable } from "@lexical/react/LexicalContentEditable";
  6. import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
  7. import { MentionPlugin } from "@/mentions/MentionPlugin.js";
  8. import { PromptMentionNode } from "@/mentions/nodes/PromptMentionNode.js";
  9. import { ServiceProvider } from "@/hooks/useServices.js";
  10. import { StoreContext } from "@/store/StoreProvider.js";
  11. import { createZCodeStore } from "@/store/index.js";
  12. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  13. import { TooltipProvider } from "@/components/ui/tooltip.js";
  14. import type { IBroadcastService, IServiceAccessor } from "@zcode/services";
  15. import "@/styles.css";
  16. const params = new URLSearchParams(location.search);
  17. const store = createZCodeStore({
  18. send: async () => {},
  19. onMessage: () => ({ dispose() {} }),
  20. } as unknown as IBroadcastService);
  21. store.getState().setInterfaceMode("coding");
  22. store.getState().setTheme(params.get("theme") === "light" ? "light" : "dark");
  23. const services = {
  24. fileService: {
  25. searchWorkspaceFiles: async (params: unknown) => {
  26. const response = await fetch("/search-files", {
  27. method: "POST",
  28. body: JSON.stringify(params),
  29. });
  30. if (!response.ok) throw new Error("search unavailable");
  31. return response.json();
  32. },
  33. },
  34. } as unknown as IServiceAccessor;
  35. function Fixture() {
  36. const [container, setContainer] = useState<HTMLDivElement | null>(null);
  37. return (
  38. <main className="min-h-screen bg-background p-4 text-foreground">
  39. <div ref={setContainer} className="mt-40 w-full">
  40. <LexicalComposer
  41. initialConfig={{
  42. namespace: "file-mention-host",
  43. nodes: [PromptMentionNode],
  44. onError: (error) => {
  45. throw error;
  46. },
  47. }}
  48. >
  49. <PlainTextPlugin
  50. contentEditable={
  51. <ContentEditable data-testid="editor" className="min-h-12 border p-2" />
  52. }
  53. placeholder={null}
  54. ErrorBoundary={LexicalErrorBoundary}
  55. />
  56. <MentionPlugin
  57. workspacePath={params.get("workspace")!}
  58. workspaceIdentity="ssh:test-host"
  59. provider="zcode"
  60. container={container}
  61. />
  62. </LexicalComposer>
  63. </div>
  64. </main>
  65. );
  66. }
  67. createRoot(document.getElementById("root")!).render(
  68. <ServiceProvider services={services}>
  69. <StoreContext.Provider value={store}>
  70. <ZCodeIntlProvider initialLocale={params.get("locale") === "zh-CN" ? "zh-CN" : "en-US"}>
  71. <TooltipProvider>
  72. <Fixture />
  73. </TooltipProvider>
  74. </ZCodeIntlProvider>
  75. </StoreContext.Provider>
  76. </ServiceProvider>,
  77. );