mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-13 04:59:51 +08:00
fix(chat): the AI reads and draws the page the user is viewing
The model always got the first page and display_diagram replaced the whole file with one page, so drawing on page 3 of a multi-page file deleted the other pages (#241), and edits went to page 1 while the user looked at another page. Now a turn records the page the user is viewing when the message is sent. That page's model goes to the model (also as previousXml, on regenerate and in edit_diagram error messages), selected shapes are sent on any page, display_diagram and append_diagram replace only that page (a drawing that brings several pages still replaces the file), edit_diagram targets it, and the streaming preview draws on it. Compact cells and default styles take the layer and the edges of that page, in the preview and in editDiagram. The editor bridge replaces the current page in place when the other pages are unchanged, so Ctrl+Z undoes an AI change on a multi-page file in one step; when a full load is needed, the user's page is shown again afterwards. Version summaries and the compare dialog count the page the change was made on.
This commit is contained in:
@@ -263,3 +263,50 @@ describe("applyDiagramOperations with wrapped cells", () => {
|
||||
expect(errors[0]?.message).toContain("not found")
|
||||
})
|
||||
})
|
||||
|
||||
describe("edit_diagram on one page of a multi-page file", () => {
|
||||
// Page A has an edge "g"; on page B, "g" is a shape on layer "L"
|
||||
const twoPages = `<mxfile><diagram id="pa" name="A"><mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/>${box("s")}${box("t")}<mxCell id="g" edge="1" parent="1" source="s" target="t"><mxGeometry relative="1" as="geometry"/></mxCell></root></mxGraphModel></diagram><diagram id="pb" name="B"><mxGraphModel><root><mxCell id="0"/><mxCell id="L" parent="0"/>${box("g", "L")}</root></mxGraphModel></diagram></mxfile>`
|
||||
const cellOn = (xml: string, pageId: string, id: string) =>
|
||||
new DOMParser()
|
||||
.parseFromString(xml, "text/xml")
|
||||
.querySelector(`diagram[id="${pageId}"] mxCell[id="${id}"]`)
|
||||
|
||||
it("puts a compact cell without a parent on that page's layer", () => {
|
||||
const outcome = editDiagram(
|
||||
twoPages,
|
||||
[
|
||||
{
|
||||
operation: "add",
|
||||
cell_id: "c",
|
||||
new_xml:
|
||||
'<mxCell id="c" value="c" x="10" y="10" w="80" h="40"/>',
|
||||
},
|
||||
],
|
||||
{ page_id: "pb" },
|
||||
)
|
||||
if (!outcome.ok) throw new Error(outcome.errors.join("; "))
|
||||
expect(cellOn(outcome.xml, "pb", "c")?.getAttribute("parent")).toBe("L")
|
||||
expect(cellOn(outcome.xml, "pa", "c")).toBeNull()
|
||||
})
|
||||
|
||||
it("reads the edges of that page only", () => {
|
||||
// A shape inside the group "g" is no edge label on page B
|
||||
const outcome = editDiagram(
|
||||
twoPages,
|
||||
[
|
||||
{
|
||||
operation: "add",
|
||||
cell_id: "c",
|
||||
new_xml:
|
||||
'<mxCell id="c" value="c" parent="g" x="10" y="10" w="80" h="40"/>',
|
||||
},
|
||||
],
|
||||
{ page_id: "pb" },
|
||||
)
|
||||
if (!outcome.ok) throw new Error(outcome.errors.join("; "))
|
||||
expect(cellOn(outcome.xml, "pb", "c")?.getAttribute("style")).toContain(
|
||||
"whiteSpace=wrap",
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user