react-arborist 2.1.1 → 2.3.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 CHANGED
@@ -96,6 +96,7 @@ function App() {
96
96
  height={1000}
97
97
  indent={24}
98
98
  rowHeight={36}
99
+ overscanCount={1}
99
100
  paddingTop={30}
100
101
  paddingBottom={10}
101
102
  padding={25 /* sets both */}
@@ -281,6 +282,7 @@ interface TreeProps<T> {
281
282
 
282
283
  /* Sizes */
283
284
  rowHeight?: number;
285
+ overscanCount?: number;
284
286
  width?: number;
285
287
  height?: number;
286
288
  indent?: number;
@@ -291,6 +293,7 @@ interface TreeProps<T> {
291
293
  /* Config */
292
294
  openByDefault?: boolean;
293
295
  selectionFollowsFocus?: boolean;
296
+ disableMultiSelection?: boolean;
294
297
  disableDrag?: string | boolean | BoolFunc<T>;
295
298
  disableDrop?: string | boolean | BoolFunc<T>;
296
299
  childrenAccessor?: string | ((d: T) => T[]);
@@ -717,6 +720,4 @@ Returns the root _NodeApi_ instance. Its children are the Node representations o
717
720
 
718
721
  ## Author
719
722
 
720
- This library was created by James Kerr while working at Brim Data on the [Zui desktop app](https://www.youtube.com/watch?v=I2y663n8d2A). Work with data? Check us out at [brimdata.io](https://www.brimdata.io)
721
-
722
- [Follow me on Twitter](https://twitter.com/specialCaseDev) for react-arborist updates.
723
+ [James Kerr](https://twitter.com/specialCaseDev) at [Brim Data](https://brimdata.io) for the [Zui desktop app](https://www.youtube.com/watch?v=I2y663n8d2A).
package/dist/index.js CHANGED
@@ -492,8 +492,8 @@ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
492
492
  return this.tree.edit(this);
493
493
  }
494
494
  handleClick = (e)=>{
495
- if (e.metaKey) this.isSelected ? this.deselect() : this.selectMulti();
496
- else if (e.shiftKey) this.selectContiguous();
495
+ if (e.metaKey && !this.tree.props.disableMultiSelection) this.isSelected ? this.deselect() : this.selectMulti();
496
+ else if (e.shiftKey && !this.tree.props.disableMultiSelection) this.selectContiguous();
497
497
  else {
498
498
  this.select();
499
499
  this.activate();
@@ -1262,7 +1262,9 @@ const $37e3f46f8fd1101f$export$a9754b3c8daa5172 = /*#__PURE__*/ (0, ($parcel$int
1262
1262
  className: tree.props.rowClassName
1263
1263
  };
1264
1264
  (0, $foSVk$react.useEffect)(()=>{
1265
- if (!node.isEditing && node.isFocused) el.current?.focus();
1265
+ if (!node.isEditing && node.isFocused) el.current?.focus({
1266
+ preventScroll: true
1267
+ });
1266
1268
  }, [
1267
1269
  node.isEditing,
1268
1270
  node.isFocused,
@@ -1341,36 +1343,39 @@ function $bb9a1e34249689ac$export$ff4858a4110d9246() {
1341
1343
  (0, $eb5355379510ac9b$export$33b47db07a82b2fb)(e.currentTarget);
1342
1344
  return;
1343
1345
  }
1344
- if (e.key === "ArrowDown" && !e.shiftKey && !e.metaKey) {
1346
+ if (e.key === "ArrowDown") {
1345
1347
  e.preventDefault();
1346
1348
  const next = tree.nextNode;
1347
- tree.focus(next);
1348
- return;
1349
- }
1350
- if (e.key === "ArrowDown" && e.shiftKey) {
1351
- e.preventDefault();
1352
- const next1 = tree.nextNode;
1353
- if (!next1) return;
1354
- const current = tree.focusedNode;
1355
- if (!current) tree.focus(tree.firstNode);
1356
- else if (current.isSelected) tree.selectContiguous(next1);
1357
- else tree.selectMulti(next1);
1358
- return;
1359
- }
1360
- if (e.key === "ArrowUp" && !e.shiftKey) {
1361
- e.preventDefault();
1362
- tree.focus(tree.prevNode);
1363
- return;
1349
+ if (e.metaKey) {
1350
+ tree.select(tree.focusedNode);
1351
+ tree.activate(tree.focusedNode);
1352
+ return;
1353
+ } else if (!e.shiftKey || tree.props.disableMultiSelection) {
1354
+ tree.focus(next);
1355
+ return;
1356
+ } else {
1357
+ if (!next) return;
1358
+ const current = tree.focusedNode;
1359
+ if (!current) tree.focus(tree.firstNode);
1360
+ else if (current.isSelected) tree.selectContiguous(next);
1361
+ else tree.selectMulti(next);
1362
+ return;
1363
+ }
1364
1364
  }
1365
- if (e.key === "ArrowUp" && e.shiftKey) {
1365
+ if (e.key === "ArrowUp") {
1366
1366
  e.preventDefault();
1367
1367
  const prev = tree.prevNode;
1368
- const current1 = tree.focusedNode;
1369
- if (!prev) return;
1370
- if (!current1) tree.focus(tree.lastNode); // ?
1371
- else if (current1.isSelected) tree.selectContiguous(prev);
1372
- else tree.selectMulti(prev);
1373
- return;
1368
+ if (!e.shiftKey || tree.props.disableMultiSelection) {
1369
+ tree.focus(prev);
1370
+ return;
1371
+ } else {
1372
+ if (!prev) return;
1373
+ const current1 = tree.focusedNode;
1374
+ if (!current1) tree.focus(tree.lastNode); // ?
1375
+ else if (current1.isSelected) tree.selectContiguous(prev);
1376
+ else tree.selectMulti(prev);
1377
+ return;
1378
+ }
1374
1379
  }
1375
1380
  if (e.key === "ArrowRight") {
1376
1381
  const node1 = tree.focusedNode;
@@ -1386,13 +1391,12 @@ function $bb9a1e34249689ac$export$ff4858a4110d9246() {
1386
1391
  else if (!node2.parent?.isRoot) tree.focus(node2.parent);
1387
1392
  return;
1388
1393
  }
1389
- if (e.key === "a" && e.metaKey) {
1394
+ if (e.key === "a" && e.metaKey && !tree.props.disableMultiSelection) {
1390
1395
  e.preventDefault();
1391
1396
  tree.selectAll();
1392
1397
  return;
1393
1398
  }
1394
- if (e.key === "a" && !e.metaKey) {
1395
- if (!tree.props.onCreate) return;
1399
+ if (e.key === "a" && !e.metaKey && tree.props.onCreate) {
1396
1400
  tree.createLeaf();
1397
1401
  return;
1398
1402
  }
@@ -1436,12 +1440,6 @@ function $bb9a1e34249689ac$export$ff4858a4110d9246() {
1436
1440
  tree.openSiblings(node4);
1437
1441
  return;
1438
1442
  }
1439
- if (e.key === "ArrowDown" && e.metaKey) {
1440
- e.preventDefault();
1441
- tree.select(tree.focusedNode);
1442
- tree.activate(tree.focusedNode);
1443
- return;
1444
- }
1445
1443
  if (e.key === "PageUp") {
1446
1444
  e.preventDefault();
1447
1445
  tree.pageUp();
@@ -1475,6 +1473,7 @@ function $bb9a1e34249689ac$export$ff4858a4110d9246() {
1475
1473
  height: tree.height,
1476
1474
  width: tree.width,
1477
1475
  itemSize: tree.rowHeight,
1476
+ overscanCount: tree.overscanCount,
1478
1477
  itemKey: (index)=>tree.visibleNodes[index]?.id || index,
1479
1478
  outerElementType: (0, $0e2adc7837d85ac3$export$70c2b8898b86d3ad),
1480
1479
  innerElementType: (0, $472f3c5b35f3bf96$export$a9af0da3ae60cd00),
@@ -1572,6 +1571,9 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1572
1571
  get rowHeight() {
1573
1572
  return this.props.rowHeight ?? 24;
1574
1573
  }
1574
+ get overscanCount() {
1575
+ return this.props.overscanCount ?? 1;
1576
+ }
1575
1577
  get searchTerm() {
1576
1578
  return (this.props.searchTerm || "").trim();
1577
1579
  }
@@ -1894,7 +1896,7 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1894
1896
  if (index === undefined) return;
1895
1897
  this.list.current?.scrollToItem(index, align);
1896
1898
  }).catch(()=>{
1897
- console.log(`Id: ${id} never appeared in the list.`);
1899
+ // Id: ${id} never appeared in the list.
1898
1900
  });
1899
1901
  }
1900
1902
  /* State Checks */ get isEditing() {