2026-10-08 16:20:15 +09:00
|
|
|
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 CanvasPage {
|
|
|
|
|
id: string
|
|
|
|
|
name: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface CanvasState {
|
|
|
|
|
/** The page can call the draw.io editor directly (same-origin iframe) */
|
|
|
|
|
hasEditor: boolean
|
|
|
|
|
pages: CanvasPage[]
|
|
|
|
|
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
|
2026-10-11 11:08:17 +09:00
|
|
|
/** Something is changing the canvas (an answer streams in, a sync
|
|
|
|
|
* runs): version actions and "ask AI" wait */
|
|
|
|
|
isBusy: boolean
|
2026-10-11 12:11:32 +09:00
|
|
|
set: (partial: Partial<Omit<CanvasState, "set">>) => void
|
2026-10-08 16:20:15 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const useCanvasStore = create<CanvasState>((set) => ({
|
|
|
|
|
hasEditor: false,
|
|
|
|
|
pages: [],
|
|
|
|
|
currentPageId: null,
|
|
|
|
|
selection: [],
|
|
|
|
|
selectionRect: null,
|
|
|
|
|
isFreehand: false,
|
|
|
|
|
isDrawioPopupOpen: false,
|
2026-10-11 11:08:17 +09:00
|
|
|
isBusy: false,
|
2026-10-08 16:20:15 +09:00
|
|
|
set: (partial) => set(partial),
|
|
|
|
|
}))
|