import { useState } from "react"; import { createRoot } from "react-dom/client"; import type { IBroadcastService, IServiceAccessor } from "@zcode/services"; import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js"; import { TooltipProvider } from "@/components/ui/tooltip.js"; import { ServiceProvider } from "@/hooks/useServices.js"; import { usePluginStoreOrder } from "@/hooks/usePluginStoreOrder.js"; import { StoreContext } from "@/store/StoreProvider.js"; import { createZCodeStore } from "@/store/index.js"; import { PluginStoreListView, type PluginStoreSegment } from "@/settings/PluginStoreListView.js"; import { buildStoreItems, type StorePluginItem } from "@/settings/pluginStoreListing.js"; import "@/styles.css"; const params = new URLSearchParams(location.search); const broadcast: IBroadcastService = { send: async () => {}, onMessage: () => ({ dispose() {} }), acquireClaim: async () => ({ status: "unavailable" }), commitClaim: async () => {}, releaseClaim: async () => {}, tryClaim: async () => false, }; const store = createZCodeStore(broadcast); store.getState().setInterfaceMode("coding"); store.getState().setTheme(params.get("theme") === "light" ? "light" : "dark"); const official = "zcode-plugins-official"; function item(name: string, category: string, marketplace = official): StorePluginItem { return { id: `${name}@${marketplace}`, name, marketplace, installed: false, restorable: false, orphaned: false, listing: { category }, }; } const defaultItems = params.get("documentOrder") === "1" ? ["aaa", "documents", "spreadsheets", "presentations", "pdf"].map((name) => ({ ...item(name, "productivity"), installed: true, })) : params.get("missingConfig") === "1" ? buildStoreItems({ marketplaces: [], marketplaceAvailabilityKnown: true, installedPlugins: [], restorableBuiltins: [], availablePlugins: [ "plugin-creator", "documents", "pdf", "presentations", "spreadsheets", "image-search", "repairable", ].map((name) => ({ id: `${name}@${official}`, name, marketplace: official, installed: name !== "repairable", listing: { category: "productivity" }, })), plugins: ["document-skills", "repairable"].map((name) => ({ id: `${name}@${official}`, name, marketplace: official, enabled: true, source: "missing" as const, packageStatus: "missing" as const, rootPath: "", skillCount: 0, skillRootCount: 0, commandRootCount: 0, components: [], declaredMcpServerNames: [], mcpServerNames: [], enabledSource: "user" as const, })), }) : [ item("dev", "developer-tools"), item("other", "other"), item("legacy-guide", "guides"), { ...item("restore-legacy-sessions", "utilities"), installed: true }, ...(params.get("retired") === "1" ? [item("restore-legacy-sessions", "utilities", "personal")] : []), ...(params.get("legal") === "1" ? [item("legal-example", "legal")] : []), ...Array.from({ length: 8 }, (_, i) => item(`p${i}`, "productivity")), item("personal-b", "productivity", "personal"), item("personal-a", "productivity", "personal"), ]; const items = params.get("uiGroups") === "1" ? ["public", "community", "personal"].flatMap((segment) => { const marketplace = segment === "personal" ? "personal" : official; return Array.from({ length: 9 }, (_, index) => { const entry = item( `${segment}-${index < 8 ? `panel-${index}` : "regular"}`, "utilities", marketplace, ); return { ...entry, listing: { ...entry.listing, publisherType: segment === "community" ? ("community" as const) : ("official" as const), }, summary: { id: entry.id, name: entry.name, marketplace, installed: false, componentTypes: index < 8 ? ["ui" as const] : [], }, }; }); }) : defaultItems; let requests = 0; const services = { clientConfigService: { getSnapshot: async () => { requests += 1; const response = await fetch("/order"); if (!response.ok) throw new Error("offline"); return { pluginStoreOrder: await response.json() }; }, }, } as unknown as IServiceAccessor; function Fixture() { const { order, refresh } = usePluginStoreOrder(); const [query, setQuery] = useState(""); const [segment, setSegment] = useState("public"); const [enabled, setEnabled] = useState(true); const [action, setAction] = useState(""); const visibleItems = params.get("installedActions") === "1" ? [ { ...item("installed-example", "productivity"), installed: true, info: { id: `installed-example@${official}`, name: "installed-example", enabled }, } as StorePluginItem, item("new-example", "productivity"), ] : items; return (
{requests} {action} setAction("detail"), onUpdate: () => {}, onInstall: () => {}, onUninstall: () => setAction("uninstall"), onSetEnabled: (_id, next) => setEnabled(next), activeOperations: [], togglingPluginId: null, }} />
); } createRoot(document.getElementById("root")!).render( , );