refactor(lib): reuse MCP helpers for streaming preview and SVG extraction

- lib/utils.ts: remove convertToLegalXml and replaceNodes; the streaming
  preview now goes through wrapCellsInModel, autoFixXml and
  replacePageModel like the final commit path does
- lib/utils.ts: extractDiagramXML reuses extractSvgEmbeddedXml,
  pageElement and decompressPageContent instead of hand-written SVG
  parsing and pako inflation
- lib/use-file-processor.tsx: messages parameter is required, drop the
  English default texts only tests used
- hooks/use-dictionary.ts, lib/i18n/utils.ts: drop duplicate default
  exports nobody imported
- tests updated accordingly
This commit is contained in:
dayuan.jiang
2026-10-12 08:05:13 +09:00
parent 07f3e3c2a3
commit a3664367ce
8 changed files with 73 additions and 316 deletions
+5 -3
View File
@@ -22,6 +22,8 @@ function deferred<T>() {
const pdfFile = () =>
new File(["%PDF"], "slow.pdf", { type: "application/pdf" })
const textFile = () => new File(["notes"], "notes.txt", { type: "text/plain" })
// The toast texts the hook formats; toast is mocked, so any texts do
const messages = { tooLong: "{name} too long", readFailed: "failed {name}" }
describe("useFileProcessor", () => {
beforeEach(() => {
@@ -35,7 +37,7 @@ describe("useFileProcessor", () => {
vi.mocked(extractTextFileContent).mockResolvedValue("notes")
const a = pdfFile()
const b = textFile()
const { result } = renderHook(() => useFileProcessor())
const { result } = renderHook(() => useFileProcessor(messages))
let done!: Promise<void>
act(() => {
@@ -59,7 +61,7 @@ describe("useFileProcessor", () => {
vi.mocked(extractTextFileContent).mockResolvedValue("notes")
const a = pdfFile()
const b = textFile()
const { result } = renderHook(() => useFileProcessor())
const { result } = renderHook(() => useFileProcessor(messages))
let first!: Promise<void>
act(() => {
@@ -82,7 +84,7 @@ describe("useFileProcessor", () => {
const pdf = deferred<string>()
vi.mocked(extractPdfText).mockReturnValue(pdf.promise)
const a = pdfFile()
const { result } = renderHook(() => useFileProcessor())
const { result } = renderHook(() => useFileProcessor(messages))
let first!: Promise<void>
act(() => {