mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-11 20:19:51 +08:00
The canvas components will be reused by the MCP server's browser shell, which has no chat and no Next.js. They now read everything they need from small contexts and the canvas store instead of the chat engine: - components/canvas/versions-context.tsx: VersionsProvider and useVersionsContext give the version cards, the strip and the compare dialog a VersionsSource (versions, onCanvasId, undoneId, isBusy, canUndo, canRedo, restore, undo, redo). The chat fills it from the versions store and the engine in components/chat/chat-versions.tsx. - stores/canvas-store.ts: isBusy and busyReason; the chat engine sets them while a turn runs, SelectionAsk and the version UI read them. - components/canvas/version-card.tsx: the visual version card and the thumbnail, out of tool-activity.tsx; the chat's card composes it and adds its "Show XML" link and code panel. - compare-dialog.tsx and version-strip.tsx move to components/canvas; the strip takes the minimum number of versions to show as a prop, the chat panel computes it from the cards it has. - components/canvas/locale-context.tsx: LocaleProvider and useLocale, fed by the [lang] layout; CanvasStage no longer uses next/navigation. The overlay (SelectionAsk) is a slot and the wait for the saved language is a prop, so the shell can leave both out. - lib/version-text.ts: describeChanges is now describeChangeSummary, so it can be imported next to the MCP core's describeChanges.
30 lines
691 B
TypeScript
30 lines
691 B
TypeScript
"use client"
|
|
|
|
import { createContext, useContext } from "react"
|
|
import type { Locale } from "@/lib/i18n/config"
|
|
|
|
const LocaleContext = createContext<Locale | null>(null)
|
|
|
|
/** The page's language; the web layout feeds it from its route param */
|
|
export function LocaleProvider({
|
|
locale,
|
|
children,
|
|
}: {
|
|
locale: Locale
|
|
children: React.ReactNode
|
|
}) {
|
|
return (
|
|
<LocaleContext.Provider value={locale}>
|
|
{children}
|
|
</LocaleContext.Provider>
|
|
)
|
|
}
|
|
|
|
export function useLocale(): Locale {
|
|
const locale = useContext(LocaleContext)
|
|
if (!locale) {
|
|
throw new Error("useLocale must be used within a LocaleProvider")
|
|
}
|
|
return locale
|
|
}
|