dnd-block-tree 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +555 -10
- package/dist/index.d.mts +296 -12
- package/dist/index.d.ts +296 -12
- package/dist/index.js +849 -114
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +836 -116
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,8 @@ interface BaseBlock {
|
|
|
11
11
|
id: string;
|
|
12
12
|
type: string;
|
|
13
13
|
parentId: string | null;
|
|
14
|
-
|
|
14
|
+
/** Ordering value. Number for integer ordering (default), string for fractional ordering. */
|
|
15
|
+
order: number | string;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Normalized index structure for efficient tree operations
|
|
@@ -106,6 +107,20 @@ interface BlockMoveEvent<T extends BaseBlock = BaseBlock> {
|
|
|
106
107
|
to: BlockPosition;
|
|
107
108
|
/** All blocks after the move */
|
|
108
109
|
blocks: T[];
|
|
110
|
+
/** IDs of all blocks that were moved (for multi-select) */
|
|
111
|
+
movedIds: string[];
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A pending move operation passed through the onBeforeMove middleware pipeline.
|
|
115
|
+
* Return a modified operation to transform the move, or return false to cancel.
|
|
116
|
+
*/
|
|
117
|
+
interface MoveOperation<T extends BaseBlock = BaseBlock> {
|
|
118
|
+
/** The block being moved */
|
|
119
|
+
block: T;
|
|
120
|
+
/** Position before the move */
|
|
121
|
+
from: BlockPosition;
|
|
122
|
+
/** Target drop zone ID */
|
|
123
|
+
targetZone: string;
|
|
109
124
|
}
|
|
110
125
|
/**
|
|
111
126
|
* Event fired when expand state changes
|
|
@@ -115,6 +130,22 @@ interface ExpandChangeEvent<T extends BaseBlock = BaseBlock> {
|
|
|
115
130
|
blockId: string;
|
|
116
131
|
expanded: boolean;
|
|
117
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Event fired when a block is added
|
|
135
|
+
*/
|
|
136
|
+
interface BlockAddEvent<T extends BaseBlock = BaseBlock> {
|
|
137
|
+
block: T;
|
|
138
|
+
parentId: string | null;
|
|
139
|
+
index: number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Event fired when a block (and optionally its descendants) is deleted
|
|
143
|
+
*/
|
|
144
|
+
interface BlockDeleteEvent<T extends BaseBlock = BaseBlock> {
|
|
145
|
+
block: T;
|
|
146
|
+
deletedIds: string[];
|
|
147
|
+
parentId: string | null;
|
|
148
|
+
}
|
|
118
149
|
/**
|
|
119
150
|
* Event fired when hover zone changes
|
|
120
151
|
*/
|
|
@@ -136,13 +167,33 @@ interface BlockTreeCallbacks<T extends BaseBlock = BaseBlock> {
|
|
|
136
167
|
onDragEnd?: (event: DragEndEvent<T>) => void;
|
|
137
168
|
/** Called when drag is cancelled */
|
|
138
169
|
onDragCancel?: (event: DragEndEvent<T>) => void;
|
|
170
|
+
/**
|
|
171
|
+
* Called before a block move is committed. Return a modified MoveOperation to
|
|
172
|
+
* transform the move (e.g. change the target zone), or return false to cancel.
|
|
173
|
+
* Return void / undefined to allow the move as-is.
|
|
174
|
+
*/
|
|
175
|
+
onBeforeMove?: (operation: MoveOperation<T>) => MoveOperation<T> | false | void;
|
|
139
176
|
/** Called after a block is moved to a new position */
|
|
140
177
|
onBlockMove?: (event: BlockMoveEvent<T>) => void;
|
|
141
178
|
/** Called when expand/collapse state changes */
|
|
142
179
|
onExpandChange?: (event: ExpandChangeEvent<T>) => void;
|
|
143
180
|
/** Called when hover zone changes during drag */
|
|
144
181
|
onHoverChange?: (event: HoverChangeEvent<T>) => void;
|
|
182
|
+
/** Called after a block is added */
|
|
183
|
+
onBlockAdd?: (event: BlockAddEvent<T>) => void;
|
|
184
|
+
/** Called after a block (and its descendants) is deleted */
|
|
185
|
+
onBlockDelete?: (event: BlockDeleteEvent<T>) => void;
|
|
145
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Ordering strategy for block siblings.
|
|
189
|
+
*
|
|
190
|
+
* - `'integer'` (default): siblings are reindexed 0, 1, 2, … after every move.
|
|
191
|
+
* Simple and efficient; not suitable for collaborative/CRDT scenarios.
|
|
192
|
+
* - `'fractional'`: each move only updates the moved block's `order` with a
|
|
193
|
+
* lexicographically sortable string key (fractional index). Siblings are never
|
|
194
|
+
* reindexed, making it conflict-free for concurrent edits.
|
|
195
|
+
*/
|
|
196
|
+
type OrderingStrategy = 'integer' | 'fractional';
|
|
146
197
|
/**
|
|
147
198
|
* Filter function to determine if a block can be dragged
|
|
148
199
|
*/
|
|
@@ -162,6 +213,10 @@ interface SensorConfig {
|
|
|
162
213
|
activationDistance?: number;
|
|
163
214
|
activationDelay?: number;
|
|
164
215
|
tolerance?: number;
|
|
216
|
+
/** Override the default long-press delay (200ms) for touch sensors */
|
|
217
|
+
longPressDelay?: number;
|
|
218
|
+
/** Trigger haptic feedback (vibration) on drag start for touch devices */
|
|
219
|
+
hapticFeedback?: boolean;
|
|
165
220
|
}
|
|
166
221
|
/**
|
|
167
222
|
* Drop zone configuration
|
|
@@ -218,6 +273,14 @@ interface BlockTreeCustomization<T extends BaseBlock = BaseBlock> {
|
|
|
218
273
|
idGenerator?: IdGeneratorFn;
|
|
219
274
|
/** Initially expanded block IDs */
|
|
220
275
|
initialExpanded?: string[] | 'all' | 'none';
|
|
276
|
+
/**
|
|
277
|
+
* Ordering strategy for block siblings.
|
|
278
|
+
* Defaults to `'integer'` (reindex all siblings on every move).
|
|
279
|
+
* Use `'fractional'` for CRDT-compatible collaborative editing.
|
|
280
|
+
*/
|
|
281
|
+
orderingStrategy?: OrderingStrategy;
|
|
282
|
+
/** Maximum nesting depth (1 = flat list, 2 = one level of nesting, etc.) */
|
|
283
|
+
maxDepth?: number;
|
|
221
284
|
}
|
|
222
285
|
/**
|
|
223
286
|
* Block action types for the reducer
|
|
@@ -312,6 +375,10 @@ interface BlockStateProviderProps<T extends BaseBlock = BaseBlock> {
|
|
|
312
375
|
initialBlocks?: T[];
|
|
313
376
|
containerTypes?: readonly string[];
|
|
314
377
|
onChange?: (blocks: T[]) => void;
|
|
378
|
+
orderingStrategy?: OrderingStrategy;
|
|
379
|
+
maxDepth?: number;
|
|
380
|
+
onBlockAdd?: (event: BlockAddEvent<T>) => void;
|
|
381
|
+
onBlockDelete?: (event: BlockDeleteEvent<T>) => void;
|
|
315
382
|
}
|
|
316
383
|
/**
|
|
317
384
|
* Tree state provider props
|
|
@@ -395,12 +462,27 @@ interface BlockTreeProps<T extends BaseBlock, C extends readonly T['type'][] = r
|
|
|
395
462
|
indentClassName?: string;
|
|
396
463
|
/** Show live preview of drop position during drag (default: true) */
|
|
397
464
|
showDropPreview?: boolean;
|
|
465
|
+
/** Enable keyboard navigation with arrow keys (default: false) */
|
|
466
|
+
keyboardNavigation?: boolean;
|
|
467
|
+
/** Enable multi-select with Cmd/Ctrl+Click and Shift+Click (default: false) */
|
|
468
|
+
multiSelect?: boolean;
|
|
469
|
+
/** Externally-controlled selected IDs (for multi-select) */
|
|
470
|
+
selectedIds?: Set<string>;
|
|
471
|
+
/** Called when selection changes (for multi-select) */
|
|
472
|
+
onSelectionChange?: (selectedIds: Set<string>) => void;
|
|
473
|
+
/** Enable virtual scrolling for large trees (fixed item height only) */
|
|
474
|
+
virtualize?: {
|
|
475
|
+
/** Fixed height of each item in pixels */
|
|
476
|
+
itemHeight: number;
|
|
477
|
+
/** Number of extra items to render outside the visible range (default: 5) */
|
|
478
|
+
overscan?: number;
|
|
479
|
+
};
|
|
398
480
|
}
|
|
399
481
|
/**
|
|
400
482
|
* Main BlockTree component
|
|
401
483
|
* Provides drag-and-drop functionality for hierarchical block structures
|
|
402
484
|
*/
|
|
403
|
-
declare function BlockTree<T extends BaseBlock, C extends readonly T['type'][] = readonly T['type'][]>({ blocks, renderers, containerTypes, onChange, dragOverlay, activationDistance, previewDebounce, className, dropZoneClassName, dropZoneActiveClassName, indentClassName, showDropPreview, onDragStart, onDragMove, onDragEnd, onDragCancel, onBlockMove, onExpandChange, onHoverChange, canDrag, canDrop, collisionDetection, sensors: sensorConfig, initialExpanded, }: BlockTreeProps<T, C>): react_jsx_runtime.JSX.Element;
|
|
485
|
+
declare function BlockTree<T extends BaseBlock, C extends readonly T['type'][] = readonly T['type'][]>({ blocks, renderers, containerTypes, onChange, dragOverlay, activationDistance, previewDebounce, className, dropZoneClassName, dropZoneActiveClassName, indentClassName, showDropPreview, onDragStart, onDragMove, onDragEnd, onDragCancel, onBeforeMove, onBlockMove, onExpandChange, onHoverChange, canDrag, canDrop, collisionDetection, sensors: sensorConfig, animation, initialExpanded, orderingStrategy, maxDepth, keyboardNavigation, multiSelect, selectedIds: externalSelectedIds, onSelectionChange, virtualize, }: BlockTreeProps<T, C>): react_jsx_runtime.JSX.Element;
|
|
404
486
|
|
|
405
487
|
interface TreeRendererProps<T extends BaseBlock> {
|
|
406
488
|
blocks: T[];
|
|
@@ -425,11 +507,21 @@ interface TreeRendererProps<T extends BaseBlock> {
|
|
|
425
507
|
} | null;
|
|
426
508
|
/** The dragged block for rendering preview ghost */
|
|
427
509
|
draggedBlock?: T | null;
|
|
510
|
+
/** Currently focused block ID for keyboard navigation */
|
|
511
|
+
focusedId?: string | null;
|
|
512
|
+
/** Currently selected block IDs for multi-select */
|
|
513
|
+
selectedIds?: Set<string>;
|
|
514
|
+
/** Click handler for multi-select */
|
|
515
|
+
onBlockClick?: (blockId: string, event: React.MouseEvent) => void;
|
|
516
|
+
/** Animation configuration */
|
|
517
|
+
animation?: AnimationConfig;
|
|
518
|
+
/** When virtual scrolling is active, only render blocks in this set */
|
|
519
|
+
virtualVisibleIds?: Set<string> | null;
|
|
428
520
|
}
|
|
429
521
|
/**
|
|
430
522
|
* Recursive tree renderer with smart drop zones
|
|
431
523
|
*/
|
|
432
|
-
declare function TreeRenderer<T extends BaseBlock>({ blocks, blocksByParent, parentId, activeId, expandedMap, renderers, containerTypes, onHover, onToggleExpand, depth, dropZoneClassName, dropZoneActiveClassName, indentClassName, rootClassName, canDrag, previewPosition, draggedBlock, }: TreeRendererProps<T>): react_jsx_runtime.JSX.Element;
|
|
524
|
+
declare function TreeRenderer<T extends BaseBlock>({ blocks, blocksByParent, parentId, activeId, expandedMap, renderers, containerTypes, onHover, onToggleExpand, depth, dropZoneClassName, dropZoneActiveClassName, indentClassName, rootClassName, canDrag, previewPosition, draggedBlock, focusedId, selectedIds, onBlockClick, animation, virtualVisibleIds, }: TreeRendererProps<T>): react_jsx_runtime.JSX.Element;
|
|
433
525
|
|
|
434
526
|
interface DropZoneProps {
|
|
435
527
|
id: string;
|
|
@@ -450,18 +542,31 @@ declare const DropZone: react.MemoExoticComponent<typeof DropZoneComponent>;
|
|
|
450
542
|
interface DragOverlayProps<T extends BaseBlock> {
|
|
451
543
|
activeBlock: T | null;
|
|
452
544
|
children?: (block: T) => ReactNode;
|
|
545
|
+
/** Number of selected items being dragged (for multi-select badge) */
|
|
546
|
+
selectedCount?: number;
|
|
453
547
|
}
|
|
454
548
|
/**
|
|
455
549
|
* Default drag overlay component
|
|
456
550
|
* Shows a preview of the dragged item
|
|
457
551
|
*/
|
|
458
|
-
declare function DragOverlay<T extends BaseBlock>({ activeBlock, children, }: DragOverlayProps<T>): react_jsx_runtime.JSX.Element;
|
|
552
|
+
declare function DragOverlay<T extends BaseBlock>({ activeBlock, children, selectedCount, }: DragOverlayProps<T>): react_jsx_runtime.JSX.Element;
|
|
553
|
+
|
|
554
|
+
interface BlockTreeSSRProps<T extends BaseBlock, C extends readonly T['type'][] = readonly T['type'][]> extends BlockTreeProps<T, C> {
|
|
555
|
+
/** Content to render before hydration completes (default: null) */
|
|
556
|
+
fallback?: ReactNode;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Hydration-safe wrapper for BlockTree in SSR environments.
|
|
560
|
+
* Renders the fallback (or nothing) on the server and during initial hydration,
|
|
561
|
+
* then mounts the full BlockTree after the client has hydrated.
|
|
562
|
+
*/
|
|
563
|
+
declare function BlockTreeSSR<T extends BaseBlock, C extends readonly T['type'][] = readonly T['type'][]>({ fallback, ...props }: BlockTreeSSRProps<T, C>): react_jsx_runtime.JSX.Element;
|
|
459
564
|
|
|
460
565
|
/**
|
|
461
566
|
* Create block state context and hooks
|
|
462
567
|
*/
|
|
463
568
|
declare function createBlockState<T extends BaseBlock>(): {
|
|
464
|
-
BlockStateProvider: ({ children, initialBlocks, containerTypes, onChange, }: BlockStateProviderProps<T>) => react_jsx_runtime.JSX.Element;
|
|
569
|
+
BlockStateProvider: ({ children, initialBlocks, containerTypes, onChange, orderingStrategy, maxDepth, onBlockAdd, onBlockDelete, }: BlockStateProviderProps<T>) => react_jsx_runtime.JSX.Element;
|
|
465
570
|
useBlockState: () => BlockStateContextValue<T>;
|
|
466
571
|
};
|
|
467
572
|
|
|
@@ -478,6 +583,89 @@ declare function createTreeState<T extends BaseBlock>(options?: CreateTreeStateO
|
|
|
478
583
|
useTreeState: () => TreeStateContextValue<T>;
|
|
479
584
|
};
|
|
480
585
|
|
|
586
|
+
interface UseBlockHistoryOptions {
|
|
587
|
+
/** Maximum number of undo steps to retain (default: 50) */
|
|
588
|
+
maxSteps?: number;
|
|
589
|
+
}
|
|
590
|
+
interface UseBlockHistoryResult<T extends BaseBlock> {
|
|
591
|
+
/** Current blocks state */
|
|
592
|
+
blocks: T[];
|
|
593
|
+
/** Set new blocks state (pushes current to undo stack) */
|
|
594
|
+
set: (blocks: T[]) => void;
|
|
595
|
+
/** Undo the last change */
|
|
596
|
+
undo: () => void;
|
|
597
|
+
/** Redo the last undone change */
|
|
598
|
+
redo: () => void;
|
|
599
|
+
/** Whether undo is available */
|
|
600
|
+
canUndo: boolean;
|
|
601
|
+
/** Whether redo is available */
|
|
602
|
+
canRedo: boolean;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Composable hook for undo/redo support with BlockTree.
|
|
606
|
+
*
|
|
607
|
+
* Usage:
|
|
608
|
+
* ```tsx
|
|
609
|
+
* const { blocks, set, undo, redo, canUndo, canRedo } = useBlockHistory(initialBlocks)
|
|
610
|
+
* <BlockTree blocks={blocks} onChange={set} />
|
|
611
|
+
* <button onClick={undo} disabled={!canUndo}>Undo</button>
|
|
612
|
+
* <button onClick={redo} disabled={!canRedo}>Redo</button>
|
|
613
|
+
* ```
|
|
614
|
+
*/
|
|
615
|
+
declare function useBlockHistory<T extends BaseBlock>(initialBlocks: T[], options?: UseBlockHistoryOptions): UseBlockHistoryResult<T>;
|
|
616
|
+
|
|
617
|
+
interface UseLayoutAnimationOptions {
|
|
618
|
+
/** Duration of the transition in ms (default: 200) */
|
|
619
|
+
duration?: number;
|
|
620
|
+
/** CSS easing function (default: 'ease') */
|
|
621
|
+
easing?: string;
|
|
622
|
+
/** CSS selector for animated children (default: '[data-block-id]') */
|
|
623
|
+
selector?: string;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* FLIP-based layout animation hook for reorder transitions.
|
|
627
|
+
*
|
|
628
|
+
* Captures block positions before render (layout effect cleanup),
|
|
629
|
+
* computes the delta after render, and applies a CSS transform transition.
|
|
630
|
+
*
|
|
631
|
+
* Usage:
|
|
632
|
+
* ```tsx
|
|
633
|
+
* const containerRef = useRef<HTMLDivElement>(null)
|
|
634
|
+
* useLayoutAnimation(containerRef, { duration: 200 })
|
|
635
|
+
* return <div ref={containerRef}>...</div>
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
declare function useLayoutAnimation(containerRef: React.RefObject<HTMLElement | null>, options?: UseLayoutAnimationOptions): void;
|
|
639
|
+
|
|
640
|
+
interface UseVirtualTreeOptions {
|
|
641
|
+
/** Ref to the scrollable container element */
|
|
642
|
+
containerRef: React.RefObject<HTMLElement | null>;
|
|
643
|
+
/** Total number of items in the tree */
|
|
644
|
+
itemCount: number;
|
|
645
|
+
/** Fixed height of each item in pixels */
|
|
646
|
+
itemHeight: number;
|
|
647
|
+
/** Number of extra items to render outside the visible range (default: 5) */
|
|
648
|
+
overscan?: number;
|
|
649
|
+
}
|
|
650
|
+
interface UseVirtualTreeResult {
|
|
651
|
+
/** Start and end indices of the visible range (inclusive) */
|
|
652
|
+
visibleRange: {
|
|
653
|
+
start: number;
|
|
654
|
+
end: number;
|
|
655
|
+
};
|
|
656
|
+
/** Total height of all items for the spacer div */
|
|
657
|
+
totalHeight: number;
|
|
658
|
+
/** Offset from top for the first rendered item */
|
|
659
|
+
offsetY: number;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Lightweight fixed-height virtual scrolling hook for tree lists.
|
|
663
|
+
*
|
|
664
|
+
* Tracks scroll position on the container and computes which items
|
|
665
|
+
* should be rendered based on the viewport and overscan.
|
|
666
|
+
*/
|
|
667
|
+
declare function useVirtualTree({ containerRef, itemCount, itemHeight, overscan, }: UseVirtualTreeOptions): UseVirtualTreeResult;
|
|
668
|
+
|
|
481
669
|
/**
|
|
482
670
|
* Clone a Map
|
|
483
671
|
*/
|
|
@@ -487,26 +675,49 @@ declare function cloneMap<K, V>(map: Map<K, V>): Map<K, V>;
|
|
|
487
675
|
*/
|
|
488
676
|
declare function cloneParentMap(map: Map<string | null, string[]>): Map<string | null, string[]>;
|
|
489
677
|
/**
|
|
490
|
-
* Compute normalized index from flat block array
|
|
678
|
+
* Compute normalized index from flat block array.
|
|
679
|
+
*
|
|
680
|
+
* With `orderingStrategy: 'fractional'`, siblings are sorted by their `order`
|
|
681
|
+
* field (lexicographic). With `'integer'` (default), the input order is preserved.
|
|
491
682
|
*/
|
|
492
|
-
declare function computeNormalizedIndex<T extends BaseBlock>(blocks: T[]): BlockIndex<T>;
|
|
683
|
+
declare function computeNormalizedIndex<T extends BaseBlock>(blocks: T[], orderingStrategy?: OrderingStrategy): BlockIndex<T>;
|
|
493
684
|
/**
|
|
494
|
-
* Build ordered flat array from BlockIndex
|
|
685
|
+
* Build ordered flat array from BlockIndex.
|
|
686
|
+
*
|
|
687
|
+
* With `'integer'` ordering (default), assigns sequential `order: 0, 1, 2, …`.
|
|
688
|
+
* With `'fractional'` ordering, preserves existing `order` values — the moved
|
|
689
|
+
* block already has its new fractional key set by `reparentBlockIndex`.
|
|
495
690
|
*/
|
|
496
|
-
declare function buildOrderedBlocks<T extends BaseBlock>(index: BlockIndex<T>, containerTypes?: readonly string[]): T[];
|
|
691
|
+
declare function buildOrderedBlocks<T extends BaseBlock>(index: BlockIndex<T>, containerTypes?: readonly string[], orderingStrategy?: OrderingStrategy): T[];
|
|
497
692
|
/**
|
|
498
|
-
* Reparent a block based on drop zone ID
|
|
693
|
+
* Reparent a block based on drop zone ID.
|
|
499
694
|
*
|
|
500
695
|
* @param state - Current block index
|
|
501
696
|
* @param activeId - ID of the dragged block
|
|
502
697
|
* @param targetZone - Drop zone ID (e.g., "after-uuid", "before-uuid", "into-uuid")
|
|
503
698
|
* @param containerTypes - Block types that can have children
|
|
699
|
+
* @param orderingStrategy - Whether to assign a fractional key to the moved block
|
|
504
700
|
*/
|
|
505
|
-
declare function reparentBlockIndex<T extends BaseBlock>(state: BlockIndex<T>, activeId: UniqueIdentifier, targetZone: string, containerTypes?: readonly string[]): BlockIndex<T>;
|
|
701
|
+
declare function reparentBlockIndex<T extends BaseBlock>(state: BlockIndex<T>, activeId: UniqueIdentifier, targetZone: string, containerTypes?: readonly string[], orderingStrategy?: OrderingStrategy, maxDepth?: number): BlockIndex<T>;
|
|
702
|
+
/**
|
|
703
|
+
* Compute the depth of a block by walking its parentId chain.
|
|
704
|
+
* Root-level blocks have depth 1.
|
|
705
|
+
*/
|
|
706
|
+
declare function getBlockDepth<T extends BaseBlock>(index: BlockIndex<T>, blockId: string): number;
|
|
707
|
+
/**
|
|
708
|
+
* Compute the maximum depth of a subtree rooted at blockId (inclusive).
|
|
709
|
+
* A leaf block returns 1.
|
|
710
|
+
*/
|
|
711
|
+
declare function getSubtreeDepth<T extends BaseBlock>(index: BlockIndex<T>, blockId: string): number;
|
|
506
712
|
/**
|
|
507
713
|
* Get all descendant IDs of a block
|
|
508
714
|
*/
|
|
509
715
|
declare function getDescendantIds<T extends BaseBlock>(state: BlockIndex<T>, parentId: string): Set<string>;
|
|
716
|
+
/**
|
|
717
|
+
* Reparent multiple blocks to a target zone, preserving their relative order.
|
|
718
|
+
* The first block in `blockIds` is treated as the primary (anchor) block.
|
|
719
|
+
*/
|
|
720
|
+
declare function reparentMultipleBlocks<T extends BaseBlock>(state: BlockIndex<T>, blockIds: string[], targetZone: string, containerTypes?: readonly string[], orderingStrategy?: OrderingStrategy, maxDepth?: number): BlockIndex<T>;
|
|
510
721
|
/**
|
|
511
722
|
* Delete a block and all its descendants
|
|
512
723
|
*/
|
|
@@ -526,5 +737,78 @@ declare function debounce<Args extends unknown[]>(fn: (...args: Args) => void, d
|
|
|
526
737
|
* Generate a unique ID (simple implementation)
|
|
527
738
|
*/
|
|
528
739
|
declare function generateId(): string;
|
|
740
|
+
/**
|
|
741
|
+
* Trigger haptic feedback (vibration) on supported devices.
|
|
742
|
+
* Safe to call in any environment — no-ops when `navigator.vibrate` is unavailable.
|
|
743
|
+
*/
|
|
744
|
+
declare function triggerHaptic(durationMs?: number): void;
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* A nested/tree representation of a block.
|
|
748
|
+
* Omits `parentId` and `order` since they are reconstructed during flattening.
|
|
749
|
+
*/
|
|
750
|
+
type NestedBlock<T extends BaseBlock> = Omit<T, 'parentId' | 'order'> & {
|
|
751
|
+
children: NestedBlock<T>[];
|
|
752
|
+
};
|
|
753
|
+
/**
|
|
754
|
+
* Convert a flat block array into a nested tree structure.
|
|
755
|
+
* Groups blocks by parentId, sorts siblings by order, and recursively builds children arrays.
|
|
756
|
+
*/
|
|
757
|
+
declare function flatToNested<T extends BaseBlock>(blocks: T[]): NestedBlock<T>[];
|
|
758
|
+
/**
|
|
759
|
+
* Convert a nested tree structure back to a flat block array.
|
|
760
|
+
* DFS walk assigning parentId and integer order on the way down.
|
|
761
|
+
*/
|
|
762
|
+
declare function nestedToFlat<T extends BaseBlock>(nested: NestedBlock<T>[]): T[];
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* Fractional indexing utilities
|
|
766
|
+
*
|
|
767
|
+
* Generates lexicographically sortable string keys that allow insertion between
|
|
768
|
+
* any two existing keys without reindexing siblings. Suitable for CRDT-based
|
|
769
|
+
* collaborative editing.
|
|
770
|
+
*
|
|
771
|
+
* Alphabet: 0-9a-z (base 36). Lexicographic order matches semantic order since
|
|
772
|
+
* '0' < '1' < ... < '9' < 'a' < ... < 'z' in ASCII.
|
|
773
|
+
*/
|
|
774
|
+
/**
|
|
775
|
+
* Generate a key that sorts strictly between `lo` and `hi`.
|
|
776
|
+
*
|
|
777
|
+
* @param lo - Lower bound (null means no lower bound)
|
|
778
|
+
* @param hi - Upper bound (null means no upper bound)
|
|
779
|
+
*/
|
|
780
|
+
declare function generateKeyBetween(lo: string | null, hi: string | null): string;
|
|
781
|
+
/**
|
|
782
|
+
* Generate `n` evenly distributed keys between `lo` and `hi` using binary
|
|
783
|
+
* subdivision. Keys grow at O(log n) depth, avoiding unbounded length.
|
|
784
|
+
*
|
|
785
|
+
* @param lo - Lower bound (null means no lower bound)
|
|
786
|
+
* @param hi - Upper bound (null means no upper bound)
|
|
787
|
+
* @param n - Number of keys to generate
|
|
788
|
+
*/
|
|
789
|
+
declare function generateNKeysBetween(lo: string | null, hi: string | null, n: number): string[];
|
|
790
|
+
/**
|
|
791
|
+
* Generate initial keys for `n` items starting from an empty list.
|
|
792
|
+
*/
|
|
793
|
+
declare function generateInitialKeys(n: number): string[];
|
|
794
|
+
/**
|
|
795
|
+
* Compare two fractional keys lexicographically.
|
|
796
|
+
* Returns negative if a < b, positive if a > b, 0 if equal.
|
|
797
|
+
*/
|
|
798
|
+
declare function compareFractionalKeys(a: string, b: string): number;
|
|
799
|
+
/**
|
|
800
|
+
* Assign initial fractional `order` keys to a flat array of blocks.
|
|
801
|
+
*
|
|
802
|
+
* Groups siblings by `parentId`, sorts each group by existing `order`, then
|
|
803
|
+
* assigns evenly-distributed fractional keys via binary subdivision.
|
|
804
|
+
*
|
|
805
|
+
* Use this to migrate an integer-ordered (or unkeyed) dataset to fractional
|
|
806
|
+
* ordering before passing blocks to a `BlockTree` with `orderingStrategy="fractional"`.
|
|
807
|
+
*/
|
|
808
|
+
declare function initFractionalOrder<T extends {
|
|
809
|
+
id: string;
|
|
810
|
+
parentId: string | null;
|
|
811
|
+
order: number | string;
|
|
812
|
+
}>(blocks: T[]): T[];
|
|
529
813
|
|
|
530
|
-
export { type AnimationConfig, type AutoExpandConfig, type BaseBlock, type BlockAction, type BlockIndex, type BlockMoveEvent, type BlockPosition, type BlockRendererProps, type BlockRenderers, type BlockStateContextValue, type BlockStateProviderProps, BlockTree, type BlockTreeCallbacks, type BlockTreeConfig, type BlockTreeCustomization, type BlockTreeProps, type CanDragFn, type CanDropFn, type ContainerRendererProps, type DragEndEvent, type DragMoveEvent, DragOverlay, type DragOverlayProps$1 as DragOverlayProps, type DragStartEvent, DropZone, type DropZoneConfig, type DropZoneProps, type DropZoneType, type ExpandChangeEvent, type HoverChangeEvent, type IdGeneratorFn, type InternalRenderers, type RendererPropsFor, type SensorConfig, TreeRenderer, type TreeRendererProps, type TreeStateContextValue, type TreeStateProviderProps, buildOrderedBlocks, cloneMap, cloneParentMap, closestCenterCollision, computeNormalizedIndex, createBlockState, createStickyCollision, createTreeState, debounce, deleteBlockAndDescendants, extractBlockId, extractUUID, generateId, getDescendantIds, getDropZoneType, getSensorConfig, reparentBlockIndex, useConfiguredSensors, weightedVerticalCollision };
|
|
814
|
+
export { type AnimationConfig, type AutoExpandConfig, type BaseBlock, type BlockAction, type BlockAddEvent, type BlockDeleteEvent, type BlockIndex, type BlockMoveEvent, type BlockPosition, type BlockRendererProps, type BlockRenderers, type BlockStateContextValue, type BlockStateProviderProps, BlockTree, type BlockTreeCallbacks, type BlockTreeConfig, type BlockTreeCustomization, type BlockTreeProps, BlockTreeSSR, type BlockTreeSSRProps, type CanDragFn, type CanDropFn, type ContainerRendererProps, type DragEndEvent, type DragMoveEvent, DragOverlay, type DragOverlayProps$1 as DragOverlayProps, type DragStartEvent, DropZone, type DropZoneConfig, type DropZoneProps, type DropZoneType, type ExpandChangeEvent, type HoverChangeEvent, type IdGeneratorFn, type InternalRenderers, type MoveOperation, type NestedBlock, type OrderingStrategy, type RendererPropsFor, type SensorConfig, TreeRenderer, type TreeRendererProps, type TreeStateContextValue, type TreeStateProviderProps, type UseBlockHistoryOptions, type UseBlockHistoryResult, type UseLayoutAnimationOptions, type UseVirtualTreeOptions, type UseVirtualTreeResult, buildOrderedBlocks, cloneMap, cloneParentMap, closestCenterCollision, compareFractionalKeys, computeNormalizedIndex, createBlockState, createStickyCollision, createTreeState, debounce, deleteBlockAndDescendants, extractBlockId, extractUUID, flatToNested, generateId, generateInitialKeys, generateKeyBetween, generateNKeysBetween, getBlockDepth, getDescendantIds, getDropZoneType, getSensorConfig, getSubtreeDepth, initFractionalOrder, nestedToFlat, reparentBlockIndex, reparentMultipleBlocks, triggerHaptic, useBlockHistory, useConfiguredSensors, useLayoutAnimation, useVirtualTree, weightedVerticalCollision };
|