The Paths namespace provides utility methods for working with block paths and orders. It includes methods for getting block order information and checking selection states.
Legacy Compatibility: The Paths API is maintained for backward compatibility. Most methods are aliases for Selection API methods. For new code, consider using the Selection API directly.
import { Paths } from '@yoopta/editor';// Get current block orderconst current = Paths.getBlockOrder(editor);// Get next/previous blockconst next = Paths.getNextBlockOrder(editor, current);const prev = Paths.getPreviousBlockOrder(editor, current);
// Get current block orderconst current = Paths.getBlockOrder(editor);console.log('Current block:', current); // 0// Same asconst current = editor.path.current;
// Get next block from currentconst current = Paths.getBlockOrder(editor);const next = Paths.getNextBlockOrder(editor, current);if (next !== null) { console.log('Next block:', next); editor.focusBlock(editor.getBlock({ at: next })?.id!);}// Navigate to next blockfunction goToNext() { const current = Paths.getBlockOrder(editor); const next = Paths.getNextBlockOrder(editor, current); if (next !== null) { editor.setPath({ current: next }); }}
import { Blocks, Paths } from '@yoopta/editor';// Get last point in blockconst slate = Blocks.getBlockSlate(editor, { at: 0 });if (slate) { const lastPoint = Paths.getLastNodePoint(slate); console.log('Last point:', lastPoint); // { path: [0, 2], offset: 15 } // Use to focus at end of block editor.focusBlock('block-123', { focusAt: lastPoint });}
// Get first point in current blockconst firstPoint = Paths.getFirstNodePoint(editor);// Get first point in specific blockconst firstPoint = Paths.getFirstNodePoint(editor, { at: 0 });if (firstPoint) { console.log('First point:', firstPoint); // { path: [0, 0], offset: 0 }}
// Old (Paths API)const current = Paths.getBlockOrder(editor);const next = Paths.getNextBlockOrder(editor, current);const selected = Paths.getSelectedPaths(editor);// New (Selection API)const current = Selection.getCurrent(editor);const next = Selection.getNext(editor, { at: current });const selected = Selection.getSelected(editor);