Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/crutchcorn/hearthspace-ui-experiments. crutchcorn.github.io/hearthspace-ui-experiments
Something went wrong. Try again.
1.7 kB · 71 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172import type { Bounds, CanvasControl, DesktopItem, DesktopWindow, WindowSelectionShape, Workspace,} from './desktop'import type { DrawingLayerName } from './drawings'import type { SelectionPoint } from './selection'
export type PointerSessionDetails = | { type: 'pan' } | { type: 'move' id: string bounds: DesktopWindow windows: DesktopWindow[] } | { type: 'resize'; id: string; bounds: DesktopWindow; edge: string } | { type: 'window-select' selectionShape: WindowSelectionShape points: SelectionPoint[] } | { type: 'item-select' selectedItemIds: string[] selectedControlIds: string[] } | { type: 'item-move' id?: string controlId?: string bounds: Bounds items: DesktopItem[] controls: CanvasControl[] } | { type: 'draw' id?: string points: SelectionPoint[] drawingLayer: DrawingLayerName } | { type: 'drawing-move'; id: string; bounds: Bounds }
export type PointerSession = PointerSessionDetails & { pointerId: number startX: number startY: number scrollX: number scrollY: number moved: boolean}
export function restoreDesktopDrag( workspace: Workspace, session: Extract<PointerSession, { type: 'item-move' }>,): Workspace { const items = new Map(session.items.map((item) => [item.id, item])) const controls = new Map( session.controls.map((control) => [control.id, control]), ) return { ...workspace, items: workspace.items.map((item) => items.get(item.id) ?? item), controls: workspace.controls?.map( (control) => controls.get(control.id) ?? control, ), }}