mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-13 04:59:51 +08:00
39 lines
973 B
TypeScript
39 lines
973 B
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
|
||
|
|
set: (partial: Partial<Omit<CanvasState, "set">>) => void
|
||
|
|
}
|
||
|
|
|
||
|
|
export const useCanvasStore = create<CanvasState>((set) => ({
|
||
|
|
hasEditor: false,
|
||
|
|
currentPageId: null,
|
||
|
|
selection: [],
|
||
|
|
selectionRect: null,
|
||
|
|
isFreehand: false,
|
||
|
|
isDrawioPopupOpen: false,
|
||
|
|
set: (partial) => set(partial),
|
||
|
|
}))
|