EV01 ๐ช Live Callback Monitor
Interact with the tree to see callback invocations in real-time
Interactive Tree
Callback Log
Callback Log
0Callback Guide
๐ฏ How to Test Callbacks:
- ๐ Click nodes to trigger
onNodeClicked - ๐ก Start drag to trigger
onNodeDragStart - ๐ต Drag over nodes for
onNodeDragOver - โ
Drop to trigger
onNodeDrop
๐ Callback Statistics:
Total callbacks logged: 0Log displays last 20 invocations
Callbacks logged in real-time
EV02 ๐ฅ Callback Props Reference
Svelte 5 callback props for handling user interactions
Callback Reference
| Callback | Trigger | Signature | Description |
|---|---|---|---|
onNodeClicked | User click | (node: LTreeNode<T>) => void | Called when user clicks on any tree node |
onNodeDragStart | Drag begins | (node: LTreeNode<T>, event: DragEvent) => void | Called when user starts dragging a node |
onNodeDragOver | Drag over | (node: LTreeNode<T>, event: DragEvent) => void | Called when dragged node hovers over a target |
onNodeDrop | Drop | (dropNode, draggedNode, position, event, operation) => void | v4.5.0+: Extended signature with position and operation |
Svelte 5 Callback Props
Unlike Svelte 4's on:event dispatcher syntax, Svelte 5 uses callback props. Pass functions directly as props: onNodeClicked={handler}
Usage Examples
Implementation Guide
๐ฏ LTreeNode Structure
All callbacks receive LTreeNode<T> objects with:
path- Node's hierarchical pathdata- Your original data objectchildren- Child nodes mapisExpanded- Expansion stateisSelected- Selection state
๐ Svelte 4 Migration
Replace on:nodeClick with onNodeClicked. The callback receives the node directly, not a CustomEvent.
โก Performance
- Callbacks are invoked synchronously
- Keep handlers lightweight
- Debounce expensive operations
EV03 ๐ค onNodeDrop Deep Dive (v4.5.0+)
Extended drop callback with position and operation support
Full Signature
| Parameter | Type | Description |
|---|---|---|
dropNode | LTreeNode<T> | null | Target node, or null for root/empty tree drops |
draggedNode | LTreeNode<T> | The node being dragged |
position | 'above' | 'below' | 'child' | NEW: Where to place relative to target |
event | DragEvent | TouchEvent | Original browser event (supports touch) |
operation | 'move' | 'copy' | NEW: Ctrl+drag = copy operation |
Breaking Change in v4.5.0
The onNodeDrop signature changed from (dropNode, draggedNode, event) to include position and operation parameters.
Implementation Examples
Drop Handling Guide
๐ฏ Position Values
'above'- Insert as sibling before target'below'- Insert as sibling after target'child'- Insert as child of target
๐ Operation Types
'move'- Default drag operation'copy'- Ctrl+drag or copy drag
โ ๏ธ Null dropNode
dropNode is null when:
- Dropped on empty tree placeholder
- Dropped on root drop zone
๐ฑ Touch Support
The event can be TouchEvent on mobile devices with long-press drag.
EV04 ๐ Search API
Search is prop-based, not callback-based - use searchText prop and searchNodes method
Search Props & Methods
| Prop / Method | Type | Description |
|---|---|---|
searchText | string (bindable) | Two-way bound search query - filters tree automatically |
shouldUseInternalSearchIndex | boolean | Enable FlexSearch-based indexing for large trees |
searchValueMember | string | Property name to use for search text |
getSearchValueCallback | (data: T) => string | Custom function to extract searchable text |
searchNodes() | (text: string) => LTreeNode[] | Method: Query nodes programmatically |
Note: Prop-Based Search
Unlike drag/drop callbacks, search uses reactive props. Bind to searchText and the tree filters automatically. No search events are fired.
Search Implementation
Search Guide
๐ Reactive Filtering
When searchText changes, the tree automatically filters to show matching nodes and their ancestors.
๐ searchNodes() Method
Use treeRef.searchNodes(query) to query nodes without changing the display filter.
โก FlexSearch Integration
Enable shouldUseInternalSearchIndex for optimized search on large trees using FlexSearch.
๐จ Custom Indexing
Use getSearchValueCallback to index multiple fields or apply custom text transformations.
EV05 โก Performance & Best Practices
Optimize callback handling for large trees and complex applications
Best Practices
โ Do's
- Debounce expensive operations in callbacks
- Keep callback handlers lightweight
- Use
$effectfor reactive side effects - Batch state updates with
$state - Use
untrack()to avoid reactive loops
โ Don'ts
- Don't perform heavy computations in callbacks
- Don't make synchronous API calls in handlers
- Don't manipulate DOM directly - use reactive state
- Don't create functions inside templates
- Don't forget null checks for dropNode
๐ง Svelte 5 Cleanup
$effect blocks.
Use onDestroy only for non-reactive cleanup like timers.Svelte 5 Patterns
Performance Guide
โก Callback Performance
- Callbacks run synchronously - keep them fast
- Debounce API calls and heavy operations
- Use
untrack()for non-reactive updates
๐ Svelte 5 Runes
$statefor reactive local state$effectfor side effects$derivedfor computed values
๐ Large Trees
- Enable
shouldUseInternalSearchIndex - Use
expandLevelto limit initial render - Lazy load children on expand if needed
๐งช Testing
Test callbacks by calling them directly with mock LTreeNode objects.