composer-menu-dismiss.fixture.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { useEffect, useState } from "react";
  2. import { createRoot } from "react-dom/client";
  3. import { ModelConfigSelect } from "@/ModelConfigSelect.js";
  4. import { TooltipProvider } from "@/components/ui/tooltip.js";
  5. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  6. import { createPluginUiPagePlane } from "@/plugin-ui/adapters/pluginUiPagePlane.js";
  7. import {
  8. SidePaneFullViewConversationHost,
  9. useConversationPanePresentation,
  10. } from "@/side-pane-full-view/index.js";
  11. import type { PluginSandboxHandle } from "@zcode/shared/mcp-apps";
  12. import "@/styles.css";
  13. const params = new URLSearchParams(location.search);
  14. document.documentElement.className = `theme-zai-${params.get("theme") ?? "light"}`;
  15. const groups = [
  16. {
  17. key: "a",
  18. label: "Provider A",
  19. items: [
  20. { key: "one", value: "one", name: "Model One" },
  21. { key: "two", value: "two", name: "Model Two" },
  22. { key: "locked", value: "locked", name: "Locked Model" },
  23. ],
  24. },
  25. { key: "b", label: "Provider B", items: [{ key: "three", value: "three", name: "Model Three" }] },
  26. ];
  27. function Composer() {
  28. const [model, setModel] = useState("one");
  29. const [effort, setEffort] = useState("high");
  30. const { reportComposerDockHeight } = useConversationPanePresentation();
  31. useEffect(() => reportComposerDockHeight(56), [reportComposerDockHeight]);
  32. return (
  33. <div
  34. data-v4-composer-dock
  35. className="absolute inset-x-0 bottom-0 flex h-14 items-center gap-2 rounded-2xl bg-background p-2"
  36. >
  37. <input data-testid="v4-composer-input" aria-label="Message" className="min-w-0 flex-1" />
  38. <ModelConfigSelect
  39. modelGroups={groups}
  40. normalizedValue={model}
  41. triggerLabel={groups.flatMap((g) => g.items).find((item) => item.value === model)!.name}
  42. showManageModelsAction={false}
  43. lockReasonMessage="Unavailable"
  44. isItemLocked={(value) => value === "locked"}
  45. onValueChange={setModel}
  46. composerOptions={{
  47. providerLabel: "Provider",
  48. modelsLabel: params.get("locale") === "zh-CN" ? "模型" : "Models",
  49. effortLabel: "Effort",
  50. selectModelLabel: "Select model",
  51. levels: [
  52. { value: "low", label: "Low" },
  53. { value: "high", label: "High" },
  54. ],
  55. value: effort,
  56. onValueChange: setEffort,
  57. }}
  58. />
  59. <output data-testid="selection" hidden>
  60. {model}
  61. </output>
  62. </div>
  63. );
  64. }
  65. function Fixture() {
  66. const [slot, setSlot] = useState<HTMLDivElement | null>(null);
  67. useEffect(() => {
  68. if (!slot || !params.has("electron")) return;
  69. // 使用真实插件承载层与 webview;只替换插件资源,避免安装和 Agent 请求干扰菜单事件证据。
  70. const plane = createPluginUiPagePlane({ onVisibility() {}, onCrash() {} });
  71. const unbind = plane.bind({ node: slot, kind: "sidebar", container: slot });
  72. plane.mount({
  73. sandboxId: "menu-dismiss",
  74. initId: 1,
  75. partition: "menu-dismiss",
  76. shellUrl: `${location.origin}/guest`,
  77. } as PluginSandboxHandle);
  78. return () => {
  79. plane.dispose();
  80. unbind();
  81. };
  82. }, [slot]);
  83. return (
  84. <main className="h-screen bg-background text-foreground">
  85. <div ref={setSlot} data-testid="plugin-slot" style={{ position: "absolute", inset: 16 }}>
  86. {!params.has("electron") && (
  87. <iframe
  88. title="Plugin"
  89. src="/guest"
  90. className="size-full border-0"
  91. style={{ pointerEvents: "auto" }}
  92. />
  93. )}
  94. </div>
  95. {params.has("electron") ? (
  96. <SidePaneFullViewConversationHost
  97. mode="floating"
  98. floating="collapsed"
  99. anchor="bottom-right"
  100. slotElement={slot}
  101. onFloatingChange={() => {}}
  102. onAnchorChange={() => {}}
  103. onOpenConversation={() => {}}
  104. >
  105. <Composer />
  106. </SidePaneFullViewConversationHost>
  107. ) : (
  108. <div style={{ position: "fixed", left: 16, right: 16, bottom: 16, height: 56 }}>
  109. <Composer />
  110. </div>
  111. )}
  112. </main>
  113. );
  114. }
  115. createRoot(document.getElementById("root")!).render(
  116. <ZCodeIntlProvider initialLocale={params.get("locale") === "zh-CN" ? "zh-CN" : "en-US"}>
  117. <TooltipProvider>
  118. <Fixture />
  119. </TooltipProvider>
  120. </ZCodeIntlProvider>,
  121. );