react-arborist 2.0.0-rc → 2.0.0-rc.2

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.
@@ -1,3 +1,3 @@
1
1
  import React from "react";
2
- import { DropCursorProps } from "../types/renderers";
3
- export declare const DefaultCursor: React.NamedExoticComponent<DropCursorProps>;
2
+ import { CursorProps } from "../types/renderers";
3
+ export declare const DefaultCursor: React.NamedExoticComponent<CursorProps>;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { NodeRendererProps } from "../types/renderers";
3
3
  import { IdObj } from "../types/utils";
4
- export declare function DefaultNode<T extends IdObj>({ style, node, dragHandle, }: NodeRendererProps<T>): JSX.Element;
4
+ export declare function DefaultNode<T extends IdObj>(props: NodeRendererProps<T>): JSX.Element;
package/dist/index.js CHANGED
@@ -72,6 +72,7 @@ $parcel$export($eb5355379510ac9b$exports, "isDecendent", () => $eb5355379510ac9b
72
72
  $parcel$export($eb5355379510ac9b$exports, "indexOf", () => $eb5355379510ac9b$export$305f7d4e9d4624f2);
73
73
  $parcel$export($eb5355379510ac9b$exports, "noop", () => $eb5355379510ac9b$export$8793edee2d425525);
74
74
  $parcel$export($eb5355379510ac9b$exports, "dfs", () => $eb5355379510ac9b$export$51b654aff22fc5a6);
75
+ $parcel$export($eb5355379510ac9b$exports, "walk", () => $eb5355379510ac9b$export$588732934346abbf);
75
76
  $parcel$export($eb5355379510ac9b$exports, "focusNextElement", () => $eb5355379510ac9b$export$3b0237e8566c8d65);
76
77
  $parcel$export($eb5355379510ac9b$exports, "focusPrevElement", () => $eb5355379510ac9b$export$33b47db07a82b2fb);
77
78
  $parcel$export($eb5355379510ac9b$exports, "access", () => $eb5355379510ac9b$export$9bb0e144ba4929ca);
@@ -80,6 +81,8 @@ $parcel$export($eb5355379510ac9b$exports, "identify", () => $eb5355379510ac9b$ex
80
81
  $parcel$export($eb5355379510ac9b$exports, "mergeRefs", () => $eb5355379510ac9b$export$c9058316764c140e);
81
82
  $parcel$export($eb5355379510ac9b$exports, "safeRun", () => $eb5355379510ac9b$export$c6d63370cef03886);
82
83
  $parcel$export($eb5355379510ac9b$exports, "waitFor", () => $eb5355379510ac9b$export$9bbfceb27f687c1b);
84
+ $parcel$export($eb5355379510ac9b$exports, "getInsertIndex", () => $eb5355379510ac9b$export$e12bf2314d0bc2a9);
85
+ $parcel$export($eb5355379510ac9b$exports, "getInsertParentId", () => $eb5355379510ac9b$export$58fe32731f07ed56);
83
86
  function $eb5355379510ac9b$export$adf7c0fe6059d774(n, min, max) {
84
87
  return Math.max(Math.min(n, max), min);
85
88
  }
@@ -111,6 +114,10 @@ function $eb5355379510ac9b$export$51b654aff22fc5a6(node, id) {
111
114
  }
112
115
  return null;
113
116
  }
117
+ function $eb5355379510ac9b$export$588732934346abbf(node, fn) {
118
+ fn(node);
119
+ if (node.children) for (let child of node.children)$eb5355379510ac9b$export$588732934346abbf(child, fn);
120
+ }
114
121
  function $eb5355379510ac9b$export$3b0237e8566c8d65(target) {
115
122
  const elements = $eb5355379510ac9b$var$getFocusable(target);
116
123
  let next;
@@ -183,6 +190,20 @@ function $eb5355379510ac9b$export$9bbfceb27f687c1b(fn) {
183
190
  check();
184
191
  });
185
192
  }
193
+ function $eb5355379510ac9b$export$e12bf2314d0bc2a9(tree) {
194
+ const focus = tree.focusedNode;
195
+ if (!focus) return tree.root.children?.length ?? 0;
196
+ if (focus.isOpen) return 0;
197
+ if (focus.parent) return focus.childIndex + 1;
198
+ return 0;
199
+ }
200
+ function $eb5355379510ac9b$export$58fe32731f07ed56(tree) {
201
+ const focus = tree.focusedNode;
202
+ if (!focus) return null;
203
+ if (focus.isOpen) return focus.id;
204
+ if (focus.parent) return focus.parent.id;
205
+ return null;
206
+ }
186
207
 
187
208
 
188
209
 
@@ -248,16 +269,51 @@ function $ff6862a32cc2ac81$export$f9c541e71856c524({ node: node , attrs: attrs ,
248
269
 
249
270
 
250
271
 
251
- function $3240a4b0b5620968$export$909e23cbfbbd3351({ style: style , node: node , dragHandle: dragHandle }) {
272
+ function $3240a4b0b5620968$export$909e23cbfbbd3351(props) {
252
273
  return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsxs)("div", {
253
- style: style,
254
- ref: dragHandle,
274
+ ref: props.dragHandle,
275
+ style: props.style,
255
276
  children: [
256
- "ID: ",
257
- node.data.id
277
+ /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("span", {
278
+ onClick: (e)=>{
279
+ e.stopPropagation();
280
+ props.node.toggle();
281
+ },
282
+ children: props.node.isLeaf ? "\uD83C\uDF33" : props.node.isOpen ? "\uD83D\uDDC1" : "\uD83D\uDDC0"
283
+ }),
284
+ " ",
285
+ props.node.isEditing ? /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)($3240a4b0b5620968$var$Edit, {
286
+ ...props
287
+ }) : /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)($3240a4b0b5620968$var$Show, {
288
+ ...props
289
+ })
258
290
  ]
259
291
  });
260
292
  }
293
+ function $3240a4b0b5620968$var$Show(props) {
294
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $foSVk$reactjsxruntime.Fragment), {
295
+ children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("span", {
296
+ children: props.node.data.name
297
+ })
298
+ });
299
+ }
300
+ function $3240a4b0b5620968$var$Edit({ node: node }) {
301
+ const input = (0, $foSVk$react.useRef)();
302
+ (0, $foSVk$react.useEffect)(()=>{
303
+ input.current?.focus();
304
+ input.current?.select();
305
+ }, []);
306
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("input", {
307
+ ref: input,
308
+ // @ts-ignore
309
+ defaultValue: node.data.name,
310
+ onBlur: ()=>node.reset(),
311
+ onKeyDown: (e)=>{
312
+ if (e.key === "Escape") node.reset();
313
+ if (e.key === "Enter") node.submit(input.current?.value || "");
314
+ }
315
+ });
316
+ }
261
317
 
262
318
 
263
319
  function $1297c48a54b69bac$export$e1a8e267487c59d1(id) {
@@ -321,18 +377,6 @@ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
321
377
  this.isDroppable = params.isDroppable;
322
378
  this.rowIndex = params.rowIndex;
323
379
  }
324
- get next() {
325
- if (this.rowIndex === null) return null;
326
- return this.tree.at(this.rowIndex + 1);
327
- }
328
- get prev() {
329
- if (this.rowIndex === null) return null;
330
- return this.tree.at(this.rowIndex - 1);
331
- }
332
- get nextSibling() {
333
- const i = this.childIndex;
334
- return this.parent?.children[i + 1] ?? null;
335
- }
336
380
  get isRoot() {
337
381
  return this.id === (0, $0d7f39915c1a8ae9$export$ec71a3379b43ae5c);
338
382
  }
@@ -345,12 +389,18 @@ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
345
389
  get isOpen() {
346
390
  return this.isLeaf ? false : this.tree.isOpen(this.id);
347
391
  }
392
+ get isClosed() {
393
+ return this.isLeaf ? false : !this.tree.isOpen(this.id);
394
+ }
348
395
  get isEditing() {
349
396
  return this.tree.editingId === this.id;
350
397
  }
351
398
  get isSelected() {
352
399
  return this.tree.isSelected(this.id);
353
400
  }
401
+ get isOnlySelection() {
402
+ return this.isSelected && this.tree.hasOneSelection;
403
+ }
354
404
  get isSelectedStart() {
355
405
  return this.isSelected && !this.prev?.isSelected;
356
406
  }
@@ -360,10 +410,6 @@ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
360
410
  get isFocused() {
361
411
  return this.tree.isFocused(this.id);
362
412
  }
363
- get childIndex() {
364
- if (this.parent && this.parent.children) return this.parent.children.findIndex((child)=>child.id === this.id);
365
- else return -1;
366
- }
367
413
  get isDragging() {
368
414
  return this.tree.isDragging(this.id);
369
415
  }
@@ -372,16 +418,35 @@ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
372
418
  }
373
419
  get state() {
374
420
  return {
375
- isEditing: this.isEditing,
421
+ isClosed: this.isClosed,
376
422
  isDragging: this.isDragging,
377
- isSelected: this.isSelected,
378
- isSelectedStart: this.isSelectedStart,
379
- isSelectedEnd: this.isSelectedEnd,
423
+ isEditing: this.isEditing,
380
424
  isFocused: this.isFocused,
425
+ isInternal: this.isInternal,
426
+ isLeaf: this.isLeaf,
381
427
  isOpen: this.isOpen,
428
+ isSelected: this.isSelected,
429
+ isSelectedEnd: this.isSelectedEnd,
430
+ isSelectedStart: this.isSelectedStart,
382
431
  willReceiveDrop: this.willReceiveDrop
383
432
  };
384
433
  }
434
+ get childIndex() {
435
+ if (this.parent && this.parent.children) return this.parent.children.findIndex((child)=>child.id === this.id);
436
+ else return -1;
437
+ }
438
+ get next() {
439
+ if (this.rowIndex === null) return null;
440
+ return this.tree.at(this.rowIndex + 1);
441
+ }
442
+ get prev() {
443
+ if (this.rowIndex === null) return null;
444
+ return this.tree.at(this.rowIndex - 1);
445
+ }
446
+ get nextSibling() {
447
+ const i = this.childIndex;
448
+ return this.parent?.children[i + 1] ?? null;
449
+ }
385
450
  select() {
386
451
  this.tree.select(this);
387
452
  }
@@ -440,18 +505,19 @@ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
440
505
  const $0d7f39915c1a8ae9$export$ec71a3379b43ae5c = "__REACT_ARBORIST_INTERNAL_ROOT__";
441
506
  function $0d7f39915c1a8ae9$export$882461b6382ed46c(tree) {
442
507
  function visitSelfAndChildren(data, level, parent) {
508
+ const id = tree.accessId(data);
443
509
  const node = new (0, $9b37fe5960a1a3c6$export$d4b903da0f522dc8)({
444
510
  tree: tree,
445
511
  data: data,
446
512
  level: level,
447
513
  parent: parent,
448
- id: data.id,
514
+ id: id,
449
515
  children: null,
450
516
  isDraggable: tree.isDraggable(data),
451
517
  isDroppable: tree.isDroppable(data),
452
518
  rowIndex: null
453
519
  });
454
- const children = tree.getChildren(data);
520
+ const children = tree.accessChildren(data);
455
521
  if (children) node.children = children.map((child)=>visitSelfAndChildren(child, level + 1, node));
456
522
  return node;
457
523
  }
@@ -797,7 +863,7 @@ const $6e3db8c23c41dfc9$var$PreviewNode = /*#__PURE__*/ (0, $foSVk$react.memo)(f
797
863
 
798
864
 
799
865
 
800
- function $e527b4e3d64e6932$export$ef961593063b03e8() {
866
+ function $e527b4e3d64e6932$export$b6a79797ad180576() {
801
867
  const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
802
868
  const state = (0, $d5cb84d44d1b8acc$export$4930f6bf413be70e)();
803
869
  const cursor = state.cursor;
@@ -822,7 +888,7 @@ const $0e2adc7837d85ac3$export$70c2b8898b86d3ad = /*#__PURE__*/ (0, $foSVk$react
822
888
  ref: ref,
823
889
  ...rest,
824
890
  onClick: (e)=>{
825
- if (e.currentTarget === e.target) tree.selectNone();
891
+ if (e.currentTarget === e.target) tree.deselectAll();
826
892
  },
827
893
  children: [
828
894
  /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)($0e2adc7837d85ac3$var$DropContainer, {}),
@@ -840,10 +906,7 @@ const $0e2adc7837d85ac3$var$DropContainer = ()=>{
840
906
  left: "0",
841
907
  right: "0"
842
908
  },
843
- onClick: (e)=>{
844
- console.log(e.currentTarget, e.target);
845
- },
846
- children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $e527b4e3d64e6932$export$ef961593063b03e8), {})
909
+ children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $e527b4e3d64e6932$export$b6a79797ad180576), {})
847
910
  });
848
911
  };
849
912
 
@@ -1192,7 +1255,8 @@ const $37e3f46f8fd1101f$export$a9754b3c8daa5172 = /*#__PURE__*/ (0, ($parcel$int
1192
1255
  "aria-level": node.level,
1193
1256
  "aria-selected": node.isSelected,
1194
1257
  style: rowStyle,
1195
- tabIndex: -1
1258
+ tabIndex: -1,
1259
+ className: tree.props.rowClassName
1196
1260
  };
1197
1261
  (0, $foSVk$react.useEffect)(()=>{
1198
1262
  if (!node.isEditing && node.isFocused) el.current?.focus();
@@ -1241,6 +1305,7 @@ function $bb9a1e34249689ac$export$ff4858a4110d9246() {
1241
1305
  onKeyDown: (e)=>{
1242
1306
  if (tree.isEditing) return;
1243
1307
  if (e.key === "Backspace") {
1308
+ if (!tree.props.onDelete) return;
1244
1309
  const ids = Array.from(tree.selectedIds);
1245
1310
  if (ids.length > 1) {
1246
1311
  let nextFocus = tree.mostRecentNode;
@@ -1324,10 +1389,12 @@ function $bb9a1e34249689ac$export$ff4858a4110d9246() {
1324
1389
  return;
1325
1390
  }
1326
1391
  if (e.key === "a" && !e.metaKey) {
1392
+ if (!tree.props.onCreate) return;
1327
1393
  tree.createLeaf();
1328
1394
  return;
1329
1395
  }
1330
1396
  if (e.key === "A" && !e.metaKey) {
1397
+ if (!tree.props.onCreate) return;
1331
1398
  tree.createInternal();
1332
1399
  return;
1333
1400
  }
@@ -1344,6 +1411,7 @@ function $bb9a1e34249689ac$export$ff4858a4110d9246() {
1344
1411
  return;
1345
1412
  }
1346
1413
  if (e.key === "Enter") {
1414
+ if (!tree.props.onRename) return;
1347
1415
  setTimeout(()=>{
1348
1416
  if (tree.focusedNode) tree.edit(tree.focusedNode);
1349
1417
  });
@@ -1490,16 +1558,16 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1490
1558
  return this.state.nodes.open.unfiltered;
1491
1559
  }
1492
1560
  /* Tree Props */ get width() {
1493
- return this.props.width || 300;
1561
+ return this.props.width ?? 300;
1494
1562
  }
1495
1563
  get height() {
1496
- return this.props.height || 500;
1564
+ return this.props.height ?? 500;
1497
1565
  }
1498
1566
  get indent() {
1499
- return this.props.indent || 24;
1567
+ return this.props.indent ?? 24;
1500
1568
  }
1501
1569
  get rowHeight() {
1502
- return this.props.rowHeight || 24;
1570
+ return this.props.rowHeight ?? 24;
1503
1571
  }
1504
1572
  get searchTerm() {
1505
1573
  return (this.props.searchTerm || "").trim();
@@ -1511,10 +1579,16 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1511
1579
  });
1512
1580
  return (node)=>match(node, this.searchTerm);
1513
1581
  }
1514
- getChildren(data) {
1515
- const get = this.props.getChildren || "children";
1582
+ accessChildren(data) {
1583
+ const get = this.props.childrenAccessor || "children";
1516
1584
  return $eb5355379510ac9b$exports.access(data, get) ?? null;
1517
1585
  }
1586
+ accessId(data) {
1587
+ const get = this.props.idAccessor || "id";
1588
+ const id = $eb5355379510ac9b$exports.access(data, get);
1589
+ if (!id) throw new Error("Data must contain an 'id' property or props.idAccessor must return a string");
1590
+ return id;
1591
+ }
1518
1592
  /* Node Access */ get firstNode() {
1519
1593
  return this.visibleNodes[0] ?? null;
1520
1594
  }
@@ -1563,31 +1637,20 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1563
1637
  return this.state.nodes.edit.id;
1564
1638
  }
1565
1639
  createInternal() {
1566
- return this.create("internal");
1640
+ return this.create({
1641
+ type: "internal"
1642
+ });
1567
1643
  }
1568
1644
  createLeaf() {
1569
- return this.create("leaf");
1570
- }
1571
- async create(type) {
1572
- let index;
1573
- let parentId;
1574
- const focus = this.focusedNode;
1575
- if (focus && focus.parent) {
1576
- if (focus.isInternal && focus.isOpen) {
1577
- parentId = focus.id;
1578
- index = 0;
1579
- } else {
1580
- index = focus.childIndex + 1;
1581
- parentId = focus.parent.isRoot ? null : focus.parent.id;
1582
- }
1583
- } else {
1584
- index = this.root?.children?.length || -1;
1585
- parentId = null;
1586
- }
1645
+ return this.create({
1646
+ type: "leaf"
1647
+ });
1648
+ }
1649
+ async create(opts = {}) {
1587
1650
  const data = await $5c74fef433be2b0a$var$safeRun(this.props.onCreate, {
1588
- parentId: parentId,
1589
- index: index,
1590
- type: type
1651
+ type: opts.type ?? "leaf",
1652
+ parentId: opts.parentId === undefined ? $eb5355379510ac9b$exports.getInsertParentId(this) : opts.parentId,
1653
+ index: opts.index ?? $eb5355379510ac9b$exports.getInsertIndex(this)
1591
1654
  });
1592
1655
  if (data) {
1593
1656
  this.focus(data);
@@ -1670,6 +1733,7 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1670
1733
  else {
1671
1734
  this.dispatch((0, $61ef7f2c3c9633e7$export$d7ddd398f22d79ef)($5c74fef433be2b0a$var$identify(node)));
1672
1735
  if (opts.scroll !== false) this.scrollTo(node);
1736
+ if (this.focusedNode) $5c74fef433be2b0a$var$safeRun(this.props.onFocus, this.focusedNode);
1673
1737
  }
1674
1738
  }
1675
1739
  pageUp() {
@@ -1698,6 +1762,7 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1698
1762
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).anchor(id));
1699
1763
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(id));
1700
1764
  this.scrollTo(id, opts.align);
1765
+ if (this.focusedNode) $5c74fef433be2b0a$var$safeRun(this.props.onFocus, this.focusedNode);
1701
1766
  $5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
1702
1767
  }
1703
1768
  deselect(node) {
@@ -1713,6 +1778,7 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1713
1778
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).anchor(node.id));
1714
1779
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(node.id));
1715
1780
  this.scrollTo(node);
1781
+ if (this.focusedNode) $5c74fef433be2b0a$var$safeRun(this.props.onFocus, this.focusedNode);
1716
1782
  $5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
1717
1783
  }
1718
1784
  selectContiguous(identity) {
@@ -1724,9 +1790,10 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1724
1790
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).add(this.nodesBetween(anchor, $5c74fef433be2b0a$var$identifyNull(id))));
1725
1791
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(id));
1726
1792
  this.scrollTo(id);
1793
+ if (this.focusedNode) $5c74fef433be2b0a$var$safeRun(this.props.onFocus, this.focusedNode);
1727
1794
  $5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
1728
1795
  }
1729
- selectNone() {
1796
+ deselectAll() {
1730
1797
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).clear());
1731
1798
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).anchor(null));
1732
1799
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(null));
@@ -1737,6 +1804,7 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1737
1804
  this.dispatch((0, $61ef7f2c3c9633e7$export$d7ddd398f22d79ef)(this.lastNode?.id));
1738
1805
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).anchor(this.firstNode));
1739
1806
  this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(this.lastNode));
1807
+ if (this.focusedNode) $5c74fef433be2b0a$var$safeRun(this.props.onFocus, this.focusedNode);
1740
1808
  $5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
1741
1809
  }
1742
1810
  /* Drag and Drop */ get cursorParentId() {
@@ -1762,12 +1830,16 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1762
1830
  /* Visibility */ open(identity) {
1763
1831
  const id = $5c74fef433be2b0a$var$identifyNull(identity);
1764
1832
  if (!id) return;
1833
+ if (this.isOpen(id)) return;
1765
1834
  this.dispatch((0, $d519ceb3313d9d0e$export$e324594224ef24da).open(id, this.isFiltered));
1835
+ $5c74fef433be2b0a$var$safeRun(this.props.onToggle, id);
1766
1836
  }
1767
1837
  close(identity) {
1768
1838
  const id = $5c74fef433be2b0a$var$identifyNull(identity);
1769
1839
  if (!id) return;
1840
+ if (!this.isOpen(id)) return;
1770
1841
  this.dispatch((0, $d519ceb3313d9d0e$export$e324594224ef24da).close(id, this.isFiltered));
1842
+ $5c74fef433be2b0a$var$safeRun(this.props.onToggle, id);
1771
1843
  }
1772
1844
  toggle(identity) {
1773
1845
  const id = $5c74fef433be2b0a$var$identifyNull(identity);
@@ -1793,6 +1865,16 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1793
1865
  this.scrollTo(this.focusedNode);
1794
1866
  }
1795
1867
  }
1868
+ openAll() {
1869
+ $eb5355379510ac9b$exports.walk(this.root, (node)=>{
1870
+ if (node.isInternal) node.open();
1871
+ });
1872
+ }
1873
+ closeAll() {
1874
+ $eb5355379510ac9b$exports.walk(this.root, (node)=>{
1875
+ if (node.isInternal) node.close();
1876
+ });
1877
+ }
1796
1878
  /* Scrolling */ scrollTo(identity, align = "smart") {
1797
1879
  if (!identity) return;
1798
1880
  const id = $5c74fef433be2b0a$var$identify(identity);
@@ -1814,6 +1896,15 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1814
1896
  get hasFocus() {
1815
1897
  return this.state.nodes.focus.treeFocused;
1816
1898
  }
1899
+ get hasNoSelection() {
1900
+ return this.state.nodes.selection.ids.size === 0;
1901
+ }
1902
+ get hasOneSelection() {
1903
+ return this.state.nodes.selection.ids.size === 1;
1904
+ }
1905
+ get hasMultipleSelections() {
1906
+ return this.state.nodes.selection.ids.size > 1;
1907
+ }
1817
1908
  isSelected(id) {
1818
1909
  if (!id) return false;
1819
1910
  return this.state.nodes.selection.ids.has(id);
@@ -1953,7 +2044,7 @@ function $9511ad6af37da13b$export$c49dab5eb1b4ce0c({ treeProps: treeProps , impe
1953
2044
  /* Expose the tree api */ (0, $foSVk$react.useImperativeHandle)(imperativeHandle, ()=>api);
1954
2045
  /* Change selection based on props */ (0, $foSVk$react.useEffect)(()=>{
1955
2046
  if (api.props.selection) api.select(api.props.selection);
1956
- else api.selectNone();
2047
+ else api.deselectAll();
1957
2048
  }, [
1958
2049
  api.props.selection
1959
2050
  ]);
@@ -1987,6 +2078,7 @@ function $9511ad6af37da13b$export$c49dab5eb1b4ce0c({ treeProps: treeProps , impe
1987
2078
 
1988
2079
 
1989
2080
 
2081
+
1990
2082
  function $6c0a9a91d5e7ff45$export$5a6c424b1725f44f() {
1991
2083
  const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
1992
2084
  // In case we drop an item at the bottom of the list
@@ -1996,9 +2088,28 @@ function $6c0a9a91d5e7ff45$export$5a6c424b1725f44f() {
1996
2088
  if (!m.isOver({
1997
2089
  shallow: true
1998
2090
  })) return;
2091
+ if (m.canDrop()) {
2092
+ const offset = m.getClientOffset();
2093
+ if (!tree.listEl.current || !offset) return;
2094
+ const { cursor: cursor } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
2095
+ element: tree.listEl.current,
2096
+ offset: offset,
2097
+ indent: tree.indent,
2098
+ node: null,
2099
+ prevNode: tree.visibleNodes[tree.visibleNodes.length - 1],
2100
+ nextNode: null
2101
+ });
2102
+ if (cursor) tree.showCursor(cursor);
2103
+ } else tree.hideCursor();
2104
+ },
2105
+ canDrop: (item, m)=>{
2106
+ if (!m.isOver({
2107
+ shallow: true
2108
+ })) return false;
2109
+ if (tree.isFiltered) return false;
1999
2110
  const offset = m.getClientOffset();
2000
- if (!tree.listEl.current || !offset) return;
2001
- const { cursor: cursor } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
2111
+ if (!tree.listEl.current || !offset) return false;
2112
+ const { drop: drop } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
2002
2113
  element: tree.listEl.current,
2003
2114
  offset: offset,
2004
2115
  indent: tree.indent,
@@ -2006,12 +2117,15 @@ function $6c0a9a91d5e7ff45$export$5a6c424b1725f44f() {
2006
2117
  prevNode: tree.visibleNodes[tree.visibleNodes.length - 1],
2007
2118
  nextNode: null
2008
2119
  });
2009
- if (cursor) tree.showCursor(cursor);
2010
- },
2011
- canDrop: (item, m)=>{
2012
- return m.isOver({
2013
- shallow: true
2014
- });
2120
+ if (!drop) return false;
2121
+ const dropParent = tree.get(drop.parentId) ?? tree.root;
2122
+ for (let id of item.dragIds){
2123
+ const drag = tree.get(id);
2124
+ if (!drag) return false;
2125
+ if (!dropParent) return false;
2126
+ if (drag.isInternal && (0, $eb5355379510ac9b$export$1e38f72c6c546f70)(dropParent, drag)) return false;
2127
+ }
2128
+ return true;
2015
2129
  },
2016
2130
  drop: (item, m)=>{
2017
2131
  if (m.didDrop()) return;
@@ -2283,11 +2397,11 @@ var $6cfe0c91f2a90e78$exports = {};
2283
2397
 
2284
2398
  $parcel$exportWildcard(module.exports, $73c61fb8fd3b5237$exports);
2285
2399
  $parcel$exportWildcard(module.exports, $6740b53b975d3884$exports);
2400
+ $parcel$exportWildcard(module.exports, $6cfe0c91f2a90e78$exports);
2286
2401
  $parcel$exportWildcard(module.exports, $9b37fe5960a1a3c6$exports);
2287
2402
  $parcel$exportWildcard(module.exports, $5c74fef433be2b0a$exports);
2288
2403
  $parcel$exportWildcard(module.exports, $ce2da9e8a36b0fcd$exports);
2289
2404
  $parcel$exportWildcard(module.exports, $2492d77b1ec82005$exports);
2290
- $parcel$exportWildcard(module.exports, $6cfe0c91f2a90e78$exports);
2291
2405
 
2292
2406
 
2293
2407
  //# sourceMappingURL=index.js.map