Files
next-ai-draw-io/stores/canvas-store.ts
T
dayuan.jiang d87c3c0bab Merge origin/main (#984, the canvas shell) into the cleanup branch
Conflicts resolved in 16 files. Where main's new shell, classic page and
tests depend on a wire format or a signature the cleanup had changed, main
wins; where main only extended code the cleanup had restructured, main's
change is carried over into the new structure:

- MCP HTTP server: the poll response keeps main's separate export fields
  (exportFormat, exportXml, exportOptions, exportId with a random id)
  instead of the cleanup's pendingExport object; the classic preview page
  is main's version
- MCP index: start_session keeps the cleanup's structure and gains main's
  BROWSER=none, previewUrl and same-origin note; get_selection is written
  in the registerTool style; create_new_diagram keeps the cleanup's
  helpers with main's comment
- history: addHistory takes main's source parameter and returns the index
  again (main's signature)
- new-diagram: the cleanup's prepareNewModel split plus main's page ids
  for diagrams without one
- diagram context: one ExportResult type (main's, with optional fields)
  for both the tagged exports and main's requestExport; the cleanup's
  single export resolver stays
- versions store and version-text test: main's VersionItem base type and
  describeChangeSummary rename, without the legacy history conversion the
  cleanup removed
- dictionaries: main's shell section added; openFileHint stays removed
  (unused on main too)
- tests: the server wiring test keeps the SDK client and gains main's
  session cases; the HTTP server test uses main's export fields; the DOM
  polyfill comes from tests/setup.ts
- package.json: main's postcss kept, the cleanup's removals kept; lockfile
  regenerated
2026-10-12 11:59:51 +09:00

43 lines
1.1 KiB
TypeScript

import { create } from "zustand"
export interface SelectedCell {
id: string
label: string
isEdge: boolean
}
/** Rectangle relative to the draw.io iframe's top-left corner */
interface CanvasRect {
x: number
y: number
width: number
height: number
}
interface CanvasState {
/** The page can call the draw.io editor directly (same-origin iframe) */
hasEditor: boolean
currentPageId: string | null
selection: SelectedCell[]
selectionRect: CanvasRect | null
/** Freehand drawing is on */
isFreehand: boolean
/** One of draw.io's menus or dialogs is open over the canvas */
isDrawioPopupOpen: boolean
/** Something is changing the canvas (an answer streams in, a sync
* runs): version actions and "ask AI" wait */
isBusy: boolean
set: (partial: Partial<Omit<CanvasState, "set">>) => void
}
export const useCanvasStore = create<CanvasState>((set) => ({
hasEditor: false,
currentPageId: null,
selection: [],
selectionRect: null,
isFreehand: false,
isDrawioPopupOpen: false,
isBusy: false,
set: (partial) => set(partial),
}))