import { Editor, Range } from "@tiptap/core"; import { syncBlocksClient } from "../services/sync-blocks-client"; /** * Slash command handler for `/sync-block` (R4.2). * * Creates a new master sync block via the REST API, then inserts a * `syncBlock` node into the editor with the returned masterId. * * The insert is atomic from the user's perspective: if the API call fails, * the editor is not modified and the error is propagated to the caller. */ export async function insertSyncBlock(editor: Editor, range: Range): Promise { // Delete the slash trigger text before the async operation to prevent // the slash menu from staying open on slow networks. editor.chain().focus().deleteRange(range).run(); const block = await syncBlocksClient.create({}); editor.chain().focus().insertSyncBlock({ masterId: block.id }).run(); }