"use client"; /** * Editor-local state (Zustand): which page/block the editor is focused on. * Server state (blocks, pages) stays in TanStack Query. * * TASK-0123: `selectedBlockIds` — the MULTI-block selection (⌘/Ctrl+click or * Shift+click range in the page view). It drives the floating selection * toolbar (the writing tools' entry point). Single-click still sets the * single `selectedBlockId` (the existing row-highlight behavior, unchanged); * the multi set is an additive, page-scoped overlay that is cleared on page * change and by the toolbar's Clear button. */ import { create } from "zustand"; interface EditorState { activePageId: string | null; selectedBlockId: string | null; /** Deep-link target: scroll + expand to this block once the page loads. */ focusBlockId: string | null; /** True once the Tiptap instance for the active page is mounted. */ editorReady: boolean; /** TASK-0123 — the multi-block selection (empty = single-select mode). */ selectedBlockIds: string[]; setActivePage: (pageId: string | null) => void; setSelection: (blockId: string | null) => void; setFocus: (blockId: string | null) => void; setReady: (ready: boolean) => void; /** Toggle one block in the multi-selection (⌘/Ctrl+click). */ toggleSelected: (blockId: string) => void; /** Replace the multi-selection (Shift+click range / toolbar Clear → []). */ setManySelected: (blockIds: string[]) => void; reset: () => void; } export const useEditorStore = create()((set) => ({ activePageId: null, selectedBlockId: null, focusBlockId: null, editorReady: false, selectedBlockIds: [], setActivePage: (activePageId) => set({ activePageId, selectedBlockId: null, focusBlockId: null, editorReady: false, selectedBlockIds: [] }), setSelection: (selectedBlockId) => set({ selectedBlockId }), setFocus: (focusBlockId) => set({ focusBlockId }), setReady: (editorReady) => set({ editorReady }), toggleSelected: (blockId) => set((s) => ({ selectedBlockIds: s.selectedBlockIds.includes(blockId) ? s.selectedBlockIds.filter((id) => id !== blockId) : [...s.selectedBlockIds, blockId] })), setManySelected: (selectedBlockIds) => set({ selectedBlockIds }), reset: () => set({ activePageId: null, selectedBlockId: null, focusBlockId: null, editorReady: false, selectedBlockIds: [] }) }));