You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's perfectly fine not to render the `children` in the render function, or only conditionally render it.
201
217
This will prevent the user from inserting any new child blocks via drag-and-drop, though any existing children
202
218
will remain unless programmatically removed.
203
219
220
+
### Making blocks draggable
221
+
222
+
To make an element draggable, add the `data-drag-handle` attribute to it. When a user clicks and drags an element with this attribute, it will initiate a drag operation for the block. The entire block can be made draggable by adding this attribute to the root element.
223
+
224
+
If there are any elements inside the block that should be able to take focus, like `input` elements, ensure you add an event handler for the `onPointerDown` event that calls `event.stopPropagation`, otherwise focus will be immediately lost and the block itself will become selected.
225
+
226
+
```tsx
227
+
{block => (
228
+
<divdata-drag-handle>
229
+
<p>Some text</p>
230
+
<inputonPointerDown={ev=>ev.stopPropagation()} />
231
+
</div>
232
+
)}
233
+
```
234
+
204
235
## Events
205
236
206
237
The `BlockTree` component emits various kinds of events in response to drag-and-drop and other interactions.
@@ -375,6 +406,16 @@ return (
375
406
**Note:**`createBlockTree` provides handlers for `onSelectionChange`, `onInsert`, `onReorder`, and `onRemove`.
376
407
If you need copy/cut/paste functionality, you'll need to implement those handlers separately.
377
408
409
+
### Additional Methods
410
+
411
+
The object returned by `createBlockTree` also includes these additional methods:
412
+
413
+
-**`toggleBlockSelected(key: K, selected: boolean)`** - Toggle a block's selection state
414
+
-**`selectBlock(key: K)`** - Select a specific block
415
+
-**`unselectBlock(key: K)`** - Unselect a specific block
416
+
-**`updateBlock(key: K, data: T)`** - Update a block's data
417
+
-**`setRoot`** - The raw `setStoreFunction`, allowing you to make arbitrary updates to the tree state
418
+
378
419
See [`createBlockTree.ts`](https://github.com/Rafferty97/solid-nest/blob/main/src/createBlockTree.ts) to get an idea
379
420
for how you might implement your own state management system or integrate your existing one with `solid-nest`.
0 commit comments