react-arborist 2.0.0-rc → 2.0.0-rc.1

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.
@@ -23,9 +23,6 @@ export declare class NodeApi<T extends IdObj = IdObj> {
23
23
  isDroppable: boolean;
24
24
  rowIndex: number | null;
25
25
  constructor(params: Params<T>);
26
- get next(): NodeApi<T> | null;
27
- get prev(): NodeApi<T> | null;
28
- get nextSibling(): NodeApi<T> | null;
29
26
  get isRoot(): boolean;
30
27
  get isLeaf(): boolean;
31
28
  get isInternal(): boolean;
@@ -35,7 +32,6 @@ export declare class NodeApi<T extends IdObj = IdObj> {
35
32
  get isSelectedStart(): boolean;
36
33
  get isSelectedEnd(): boolean;
37
34
  get isFocused(): boolean;
38
- get childIndex(): number;
39
35
  get isDragging(): boolean;
40
36
  get willReceiveDrop(): boolean;
41
37
  get state(): {
@@ -48,6 +44,10 @@ export declare class NodeApi<T extends IdObj = IdObj> {
48
44
  isOpen: boolean;
49
45
  willReceiveDrop: boolean;
50
46
  };
47
+ get childIndex(): number;
48
+ get next(): NodeApi<T> | null;
49
+ get prev(): NodeApi<T> | null;
50
+ get nextSibling(): NodeApi<T> | null;
51
51
  select(): void;
52
52
  deselect(): void;
53
53
  selectMulti(): void;
@@ -44,7 +44,8 @@ export declare class TreeApi<T extends IdObj> {
44
44
  get rowHeight(): number;
45
45
  get searchTerm(): string;
46
46
  get matchFn(): (node: NodeApi<T>) => boolean;
47
- getChildren(data: T): T[] | null;
47
+ accessChildren(data: T): T[] | null;
48
+ accessId(data: T): string;
48
49
  get firstNode(): NodeApi<T>;
49
50
  get lastNode(): NodeApi<T>;
50
51
  get focusedNode(): NodeApi<T> | null;
@@ -78,7 +79,7 @@ export declare class TreeApi<T extends IdObj> {
78
79
  deselect(node: Identity): void;
79
80
  selectMulti(identity: Identity): void;
80
81
  selectContiguous(identity: Identity): void;
81
- selectNone(): void;
82
+ deselectAll(): void;
82
83
  selectAll(): void;
83
84
  get cursorParentId(): string | null;
84
85
  get cursorOverFolder(): boolean;
package/dist/module.js CHANGED
@@ -227,16 +227,51 @@ function $164e874d21fcd87e$export$f9c541e71856c524({ node: node , attrs: attrs ,
227
227
 
228
228
 
229
229
 
230
- function $c4edd692d5290432$export$909e23cbfbbd3351({ style: style , node: node , dragHandle: dragHandle }) {
230
+ function $c4edd692d5290432$export$909e23cbfbbd3351(props) {
231
231
  return /*#__PURE__*/ (0, $g00cZ$jsxs)("div", {
232
- style: style,
233
- ref: dragHandle,
232
+ ref: props.dragHandle,
233
+ style: props.style,
234
234
  children: [
235
- "ID: ",
236
- node.data.id
235
+ /*#__PURE__*/ (0, $g00cZ$jsx)("span", {
236
+ onClick: (e)=>{
237
+ e.stopPropagation();
238
+ props.node.toggle();
239
+ },
240
+ children: props.node.isLeaf ? "\uD83C\uDF33" : props.node.isOpen ? "\uD83D\uDDC1" : "\uD83D\uDDC0"
241
+ }),
242
+ " ",
243
+ props.node.isEditing ? /*#__PURE__*/ (0, $g00cZ$jsx)($c4edd692d5290432$var$Edit, {
244
+ ...props
245
+ }) : /*#__PURE__*/ (0, $g00cZ$jsx)($c4edd692d5290432$var$Show, {
246
+ ...props
247
+ })
237
248
  ]
238
249
  });
239
250
  }
251
+ function $c4edd692d5290432$var$Show(props) {
252
+ return /*#__PURE__*/ (0, $g00cZ$jsx)((0, $g00cZ$Fragment), {
253
+ children: /*#__PURE__*/ (0, $g00cZ$jsx)("span", {
254
+ children: props.node.data.name
255
+ })
256
+ });
257
+ }
258
+ function $c4edd692d5290432$var$Edit({ node: node }) {
259
+ const input = (0, $g00cZ$useRef)();
260
+ (0, $g00cZ$useEffect)(()=>{
261
+ input.current?.focus();
262
+ input.current?.select();
263
+ }, []);
264
+ return /*#__PURE__*/ (0, $g00cZ$jsx)("input", {
265
+ ref: input,
266
+ // @ts-ignore
267
+ defaultValue: node.data.name,
268
+ onBlur: ()=>node.reset(),
269
+ onKeyDown: (e)=>{
270
+ if (e.key === "Escape") node.reset();
271
+ if (e.key === "Enter") node.submit(input.current?.value || "");
272
+ }
273
+ });
274
+ }
240
275
 
241
276
 
242
277
  function $21783d2b0251be67$export$e1a8e267487c59d1(id) {
@@ -300,18 +335,6 @@ class $096e74084443e9a3$export$d4b903da0f522dc8 {
300
335
  this.isDroppable = params.isDroppable;
301
336
  this.rowIndex = params.rowIndex;
302
337
  }
303
- get next() {
304
- if (this.rowIndex === null) return null;
305
- return this.tree.at(this.rowIndex + 1);
306
- }
307
- get prev() {
308
- if (this.rowIndex === null) return null;
309
- return this.tree.at(this.rowIndex - 1);
310
- }
311
- get nextSibling() {
312
- const i = this.childIndex;
313
- return this.parent?.children[i + 1] ?? null;
314
- }
315
338
  get isRoot() {
316
339
  return this.id === (0, $81080a351c006222$export$ec71a3379b43ae5c);
317
340
  }
@@ -339,10 +362,6 @@ class $096e74084443e9a3$export$d4b903da0f522dc8 {
339
362
  get isFocused() {
340
363
  return this.tree.isFocused(this.id);
341
364
  }
342
- get childIndex() {
343
- if (this.parent && this.parent.children) return this.parent.children.findIndex((child)=>child.id === this.id);
344
- else return -1;
345
- }
346
365
  get isDragging() {
347
366
  return this.tree.isDragging(this.id);
348
367
  }
@@ -361,6 +380,22 @@ class $096e74084443e9a3$export$d4b903da0f522dc8 {
361
380
  willReceiveDrop: this.willReceiveDrop
362
381
  };
363
382
  }
383
+ get childIndex() {
384
+ if (this.parent && this.parent.children) return this.parent.children.findIndex((child)=>child.id === this.id);
385
+ else return -1;
386
+ }
387
+ get next() {
388
+ if (this.rowIndex === null) return null;
389
+ return this.tree.at(this.rowIndex + 1);
390
+ }
391
+ get prev() {
392
+ if (this.rowIndex === null) return null;
393
+ return this.tree.at(this.rowIndex - 1);
394
+ }
395
+ get nextSibling() {
396
+ const i = this.childIndex;
397
+ return this.parent?.children[i + 1] ?? null;
398
+ }
364
399
  select() {
365
400
  this.tree.select(this);
366
401
  }
@@ -419,18 +454,19 @@ class $096e74084443e9a3$export$d4b903da0f522dc8 {
419
454
  const $81080a351c006222$export$ec71a3379b43ae5c = "__REACT_ARBORIST_INTERNAL_ROOT__";
420
455
  function $81080a351c006222$export$882461b6382ed46c(tree) {
421
456
  function visitSelfAndChildren(data, level, parent) {
457
+ const id = tree.accessId(data);
422
458
  const node = new (0, $096e74084443e9a3$export$d4b903da0f522dc8)({
423
459
  tree: tree,
424
460
  data: data,
425
461
  level: level,
426
462
  parent: parent,
427
- id: data.id,
463
+ id: id,
428
464
  children: null,
429
465
  isDraggable: tree.isDraggable(data),
430
466
  isDroppable: tree.isDroppable(data),
431
467
  rowIndex: null
432
468
  });
433
- const children = tree.getChildren(data);
469
+ const children = tree.accessChildren(data);
434
470
  if (children) node.children = children.map((child)=>visitSelfAndChildren(child, level + 1, node));
435
471
  return node;
436
472
  }
@@ -801,7 +837,7 @@ const $05f64c7ebcbad8b5$export$70c2b8898b86d3ad = /*#__PURE__*/ (0, $g00cZ$forwa
801
837
  ref: ref,
802
838
  ...rest,
803
839
  onClick: (e)=>{
804
- if (e.currentTarget === e.target) tree.selectNone();
840
+ if (e.currentTarget === e.target) tree.deselectAll();
805
841
  },
806
842
  children: [
807
843
  /*#__PURE__*/ (0, $g00cZ$jsx)($05f64c7ebcbad8b5$var$DropContainer, {}),
@@ -1220,6 +1256,7 @@ function $065a164934293bf2$export$ff4858a4110d9246() {
1220
1256
  onKeyDown: (e)=>{
1221
1257
  if (tree.isEditing) return;
1222
1258
  if (e.key === "Backspace") {
1259
+ if (!tree.props.onDelete) return;
1223
1260
  const ids = Array.from(tree.selectedIds);
1224
1261
  if (ids.length > 1) {
1225
1262
  let nextFocus = tree.mostRecentNode;
@@ -1303,10 +1340,12 @@ function $065a164934293bf2$export$ff4858a4110d9246() {
1303
1340
  return;
1304
1341
  }
1305
1342
  if (e.key === "a" && !e.metaKey) {
1343
+ if (!tree.props.onCreate) return;
1306
1344
  tree.createLeaf();
1307
1345
  return;
1308
1346
  }
1309
1347
  if (e.key === "A" && !e.metaKey) {
1348
+ if (!tree.props.onCreate) return;
1310
1349
  tree.createInternal();
1311
1350
  return;
1312
1351
  }
@@ -1323,6 +1362,7 @@ function $065a164934293bf2$export$ff4858a4110d9246() {
1323
1362
  return;
1324
1363
  }
1325
1364
  if (e.key === "Enter") {
1365
+ if (!tree.props.onRename) return;
1326
1366
  setTimeout(()=>{
1327
1367
  if (tree.focusedNode) tree.edit(tree.focusedNode);
1328
1368
  });
@@ -1490,10 +1530,16 @@ class $bfece7c4aed4e9c4$export$e2da3477247342d1 {
1490
1530
  });
1491
1531
  return (node)=>match(node, this.searchTerm);
1492
1532
  }
1493
- getChildren(data) {
1494
- const get = this.props.getChildren || "children";
1533
+ accessChildren(data) {
1534
+ const get = this.props.childrenAccessor || "children";
1495
1535
  return $0e6083160f4b36ed$exports.access(data, get) ?? null;
1496
1536
  }
1537
+ accessId(data) {
1538
+ const get = this.props.idAccessor || "id";
1539
+ const id = $0e6083160f4b36ed$exports.access(data, get);
1540
+ if (!id) throw new Error("Data must contain an 'id' property or props.idAccessor must return a string");
1541
+ return id;
1542
+ }
1497
1543
  /* Node Access */ get firstNode() {
1498
1544
  return this.visibleNodes[0] ?? null;
1499
1545
  }
@@ -1705,7 +1751,7 @@ class $bfece7c4aed4e9c4$export$e2da3477247342d1 {
1705
1751
  this.scrollTo(id);
1706
1752
  $bfece7c4aed4e9c4$var$safeRun(this.props.onSelect, this.selectedNodes);
1707
1753
  }
1708
- selectNone() {
1754
+ deselectAll() {
1709
1755
  this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).clear());
1710
1756
  this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).anchor(null));
1711
1757
  this.dispatch((0, $37bc167debff36d2$export$e324594224ef24da).mostRecent(null));
@@ -1932,7 +1978,7 @@ function $dac24389e46ba09d$export$c49dab5eb1b4ce0c({ treeProps: treeProps , impe
1932
1978
  /* Expose the tree api */ (0, $g00cZ$useImperativeHandle)(imperativeHandle, ()=>api);
1933
1979
  /* Change selection based on props */ (0, $g00cZ$useEffect)(()=>{
1934
1980
  if (api.props.selection) api.select(api.props.selection);
1935
- else api.selectNone();
1981
+ else api.deselectAll();
1936
1982
  }, [
1937
1983
  api.props.selection
1938
1984
  ]);