@particle-academy/react-fancy 2.8.0 → 2.9.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/dist/index.cjs +120 -79
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -2
- package/dist/index.d.ts +27 -2
- package/dist/index.js +120 -79
- package/dist/index.js.map +1 -1
- package/docs/Canvas.md +5 -2
- package/docs/TreeNav.md +27 -2
- package/package.json +1 -1
package/docs/Canvas.md
CHANGED
|
@@ -37,8 +37,11 @@ import { Canvas } from "@particle-academy/react-fancy";
|
|
|
37
37
|
| maxZoom | `number` | `3` | Maximum zoom level |
|
|
38
38
|
| pannable | `boolean` | `true` | Enable panning (click+drag on background) |
|
|
39
39
|
| zoomable | `boolean` | `true` | Enable zoom (Ctrl+scroll) |
|
|
40
|
-
| gridSize | `number` |
|
|
41
|
-
| showGrid | `boolean` | `false` | Display
|
|
40
|
+
| gridSize | `number` | `20` | Grid cell size in canvas-space pixels |
|
|
41
|
+
| showGrid | `boolean` | `false` | Display the canvas grid background |
|
|
42
|
+
| gridStyle | `'dots' \| 'lines' \| 'none'` | `'dots'` | Grid pattern when shown. `'none'` hides the grid even when `showGrid` is true |
|
|
43
|
+
| gridColor | `string` | `'rgb(161 161 170 / 0.3)'` | Any CSS color for grid dots/lines |
|
|
44
|
+
| snapToGrid | `boolean` | `false` | Snap dragged nodes to the grid |
|
|
42
45
|
| fitOnMount | `boolean` | `false` | Auto-fit all nodes into view on mount |
|
|
43
46
|
| className | `string` | - | Additional CSS classes |
|
|
44
47
|
| style | `CSSProperties` | - | Inline styles |
|
package/docs/TreeNav.md
CHANGED
|
@@ -49,8 +49,10 @@ const files: TreeNodeData[] = [
|
|
|
49
49
|
| selectedId | `string` | - | Currently selected node ID |
|
|
50
50
|
| onSelect | `(id: string, node: TreeNodeData) => void` | - | Selection callback |
|
|
51
51
|
| onNodeContextMenu | `(e: React.MouseEvent, node: TreeNodeData) => void` | - | Right-click callback per node |
|
|
52
|
-
| draggable | `boolean` | `false` | Enable drag-and-drop reordering |
|
|
53
|
-
| onNodeMove | `(sourceId: string, targetId: string, position: DropPosition) => void` | - | Callback when a node is moved via drag-and-drop |
|
|
52
|
+
| draggable | `boolean` | `false` | Enable drag-and-drop reordering of tree nodes |
|
|
53
|
+
| onNodeMove | `(sourceId: string, targetId: string, position: DropPosition) => void` | - | Callback when a node is moved via drag-and-drop within the tree |
|
|
54
|
+
| acceptExternalDrops | `boolean` | `false` | Accept drops from outside the tree — OS files, items dragged from other components, etc. |
|
|
55
|
+
| onExternalDrop | `(event: React.DragEvent, target: TreeNodeData, position: DropPosition) => void` | - | Fires on external drop. Read `event.dataTransfer.files` for OS file drops or `event.dataTransfer.getData(type)` for custom MIME payloads. |
|
|
54
56
|
| expandedIds | `string[]` | - | Controlled expanded node IDs |
|
|
55
57
|
| defaultExpandedIds | `string[]` | - | Initial expanded nodes (uncontrolled) |
|
|
56
58
|
| onExpandedChange | `(ids: string[]) => void` | - | Callback when expanded state changes |
|
|
@@ -177,6 +179,29 @@ function handleNodeMove(sourceId: string, targetId: string, position: DropPositi
|
|
|
177
179
|
- Folders auto-expand after 500ms when dragging over them
|
|
178
180
|
- Disabled nodes cannot be dragged
|
|
179
181
|
|
|
182
|
+
## External Drops (files, cross-component)
|
|
183
|
+
|
|
184
|
+
Set `acceptExternalDrops` and supply `onExternalDrop` to accept payloads from outside the tree — OS files dragged from the desktop, items dragged from a Kanban card, anything that ships a `dataTransfer`. The same `before` / `after` / `inside` indicators apply, and folders still auto-expand.
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
<TreeNav
|
|
188
|
+
nodes={files}
|
|
189
|
+
acceptExternalDrops
|
|
190
|
+
onExternalDrop={(event, target, position) => {
|
|
191
|
+
// OS file drop?
|
|
192
|
+
if (event.dataTransfer.files.length > 0) {
|
|
193
|
+
uploadFiles(event.dataTransfer.files, target.id);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
// Custom payload from another component?
|
|
197
|
+
const payload = event.dataTransfer.getData("application/x-card-id");
|
|
198
|
+
if (payload) attachCardToNode(payload, target.id, position);
|
|
199
|
+
}}
|
|
200
|
+
/>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
`acceptExternalDrops` and `draggable` are independent — enable either, both, or neither. With both on, internal drag-reorder and external drops coexist; the handler distinguishes via the absence of an internal drag source.
|
|
204
|
+
|
|
180
205
|
## Context Menu
|
|
181
206
|
|
|
182
207
|
Use `onNodeContextMenu` with the `ContextMenu` component to add right-click menus per node:
|