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.
- package/README.md +683 -0
- package/dist/components/default-container.d.ts +5 -0
- package/dist/components/default-node.d.ts +1 -1
- package/dist/index.js +75 -29
- package/dist/index.js.map +1 -1
- package/dist/interfaces/node-api.d.ts +4 -4
- package/dist/interfaces/tree-api.d.ts +3 -2
- package/dist/module.js +74 -28
- package/dist/module.js.map +1 -1
- package/dist/types/tree-props.d.ts +2 -1
- package/package.json +2 -1
- package/src/components/default-container.tsx +9 -0
- package/src/components/default-node.tsx +43 -8
- package/src/components/list-outer-element.tsx +1 -1
- package/src/components/provider.tsx +1 -1
- package/src/data/create-root.ts +3 -2
- package/src/interfaces/node-api.ts +23 -23
- package/src/interfaces/tree-api.ts +14 -9
- package/src/types/tree-props.ts +2 -1
- package/tsconfig.json +1 -1
- package/dist/data/flatten-tree.d.ts +0 -4
- package/dist/hooks/use-uncontrolled-tree.d.ts +0 -24
- package/dist/utils/props.d.ts +0 -3
- package/src/utils/props.ts +0 -8
package/dist/index.js
CHANGED
|
@@ -248,16 +248,51 @@ function $ff6862a32cc2ac81$export$f9c541e71856c524({ node: node , attrs: attrs ,
|
|
|
248
248
|
|
|
249
249
|
|
|
250
250
|
|
|
251
|
-
function $3240a4b0b5620968$export$909e23cbfbbd3351(
|
|
251
|
+
function $3240a4b0b5620968$export$909e23cbfbbd3351(props) {
|
|
252
252
|
return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsxs)("div", {
|
|
253
|
-
|
|
254
|
-
|
|
253
|
+
ref: props.dragHandle,
|
|
254
|
+
style: props.style,
|
|
255
255
|
children: [
|
|
256
|
-
|
|
257
|
-
|
|
256
|
+
/*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("span", {
|
|
257
|
+
onClick: (e)=>{
|
|
258
|
+
e.stopPropagation();
|
|
259
|
+
props.node.toggle();
|
|
260
|
+
},
|
|
261
|
+
children: props.node.isLeaf ? "\uD83C\uDF33" : props.node.isOpen ? "\uD83D\uDDC1" : "\uD83D\uDDC0"
|
|
262
|
+
}),
|
|
263
|
+
" ",
|
|
264
|
+
props.node.isEditing ? /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)($3240a4b0b5620968$var$Edit, {
|
|
265
|
+
...props
|
|
266
|
+
}) : /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)($3240a4b0b5620968$var$Show, {
|
|
267
|
+
...props
|
|
268
|
+
})
|
|
258
269
|
]
|
|
259
270
|
});
|
|
260
271
|
}
|
|
272
|
+
function $3240a4b0b5620968$var$Show(props) {
|
|
273
|
+
return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $foSVk$reactjsxruntime.Fragment), {
|
|
274
|
+
children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("span", {
|
|
275
|
+
children: props.node.data.name
|
|
276
|
+
})
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
function $3240a4b0b5620968$var$Edit({ node: node }) {
|
|
280
|
+
const input = (0, $foSVk$react.useRef)();
|
|
281
|
+
(0, $foSVk$react.useEffect)(()=>{
|
|
282
|
+
input.current?.focus();
|
|
283
|
+
input.current?.select();
|
|
284
|
+
}, []);
|
|
285
|
+
return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("input", {
|
|
286
|
+
ref: input,
|
|
287
|
+
// @ts-ignore
|
|
288
|
+
defaultValue: node.data.name,
|
|
289
|
+
onBlur: ()=>node.reset(),
|
|
290
|
+
onKeyDown: (e)=>{
|
|
291
|
+
if (e.key === "Escape") node.reset();
|
|
292
|
+
if (e.key === "Enter") node.submit(input.current?.value || "");
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
261
296
|
|
|
262
297
|
|
|
263
298
|
function $1297c48a54b69bac$export$e1a8e267487c59d1(id) {
|
|
@@ -321,18 +356,6 @@ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
|
|
|
321
356
|
this.isDroppable = params.isDroppable;
|
|
322
357
|
this.rowIndex = params.rowIndex;
|
|
323
358
|
}
|
|
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
359
|
get isRoot() {
|
|
337
360
|
return this.id === (0, $0d7f39915c1a8ae9$export$ec71a3379b43ae5c);
|
|
338
361
|
}
|
|
@@ -360,10 +383,6 @@ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
|
|
|
360
383
|
get isFocused() {
|
|
361
384
|
return this.tree.isFocused(this.id);
|
|
362
385
|
}
|
|
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
386
|
get isDragging() {
|
|
368
387
|
return this.tree.isDragging(this.id);
|
|
369
388
|
}
|
|
@@ -382,6 +401,22 @@ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
|
|
|
382
401
|
willReceiveDrop: this.willReceiveDrop
|
|
383
402
|
};
|
|
384
403
|
}
|
|
404
|
+
get childIndex() {
|
|
405
|
+
if (this.parent && this.parent.children) return this.parent.children.findIndex((child)=>child.id === this.id);
|
|
406
|
+
else return -1;
|
|
407
|
+
}
|
|
408
|
+
get next() {
|
|
409
|
+
if (this.rowIndex === null) return null;
|
|
410
|
+
return this.tree.at(this.rowIndex + 1);
|
|
411
|
+
}
|
|
412
|
+
get prev() {
|
|
413
|
+
if (this.rowIndex === null) return null;
|
|
414
|
+
return this.tree.at(this.rowIndex - 1);
|
|
415
|
+
}
|
|
416
|
+
get nextSibling() {
|
|
417
|
+
const i = this.childIndex;
|
|
418
|
+
return this.parent?.children[i + 1] ?? null;
|
|
419
|
+
}
|
|
385
420
|
select() {
|
|
386
421
|
this.tree.select(this);
|
|
387
422
|
}
|
|
@@ -440,18 +475,19 @@ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
|
|
|
440
475
|
const $0d7f39915c1a8ae9$export$ec71a3379b43ae5c = "__REACT_ARBORIST_INTERNAL_ROOT__";
|
|
441
476
|
function $0d7f39915c1a8ae9$export$882461b6382ed46c(tree) {
|
|
442
477
|
function visitSelfAndChildren(data, level, parent) {
|
|
478
|
+
const id = tree.accessId(data);
|
|
443
479
|
const node = new (0, $9b37fe5960a1a3c6$export$d4b903da0f522dc8)({
|
|
444
480
|
tree: tree,
|
|
445
481
|
data: data,
|
|
446
482
|
level: level,
|
|
447
483
|
parent: parent,
|
|
448
|
-
id:
|
|
484
|
+
id: id,
|
|
449
485
|
children: null,
|
|
450
486
|
isDraggable: tree.isDraggable(data),
|
|
451
487
|
isDroppable: tree.isDroppable(data),
|
|
452
488
|
rowIndex: null
|
|
453
489
|
});
|
|
454
|
-
const children = tree.
|
|
490
|
+
const children = tree.accessChildren(data);
|
|
455
491
|
if (children) node.children = children.map((child)=>visitSelfAndChildren(child, level + 1, node));
|
|
456
492
|
return node;
|
|
457
493
|
}
|
|
@@ -822,7 +858,7 @@ const $0e2adc7837d85ac3$export$70c2b8898b86d3ad = /*#__PURE__*/ (0, $foSVk$react
|
|
|
822
858
|
ref: ref,
|
|
823
859
|
...rest,
|
|
824
860
|
onClick: (e)=>{
|
|
825
|
-
if (e.currentTarget === e.target) tree.
|
|
861
|
+
if (e.currentTarget === e.target) tree.deselectAll();
|
|
826
862
|
},
|
|
827
863
|
children: [
|
|
828
864
|
/*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)($0e2adc7837d85ac3$var$DropContainer, {}),
|
|
@@ -1241,6 +1277,7 @@ function $bb9a1e34249689ac$export$ff4858a4110d9246() {
|
|
|
1241
1277
|
onKeyDown: (e)=>{
|
|
1242
1278
|
if (tree.isEditing) return;
|
|
1243
1279
|
if (e.key === "Backspace") {
|
|
1280
|
+
if (!tree.props.onDelete) return;
|
|
1244
1281
|
const ids = Array.from(tree.selectedIds);
|
|
1245
1282
|
if (ids.length > 1) {
|
|
1246
1283
|
let nextFocus = tree.mostRecentNode;
|
|
@@ -1324,10 +1361,12 @@ function $bb9a1e34249689ac$export$ff4858a4110d9246() {
|
|
|
1324
1361
|
return;
|
|
1325
1362
|
}
|
|
1326
1363
|
if (e.key === "a" && !e.metaKey) {
|
|
1364
|
+
if (!tree.props.onCreate) return;
|
|
1327
1365
|
tree.createLeaf();
|
|
1328
1366
|
return;
|
|
1329
1367
|
}
|
|
1330
1368
|
if (e.key === "A" && !e.metaKey) {
|
|
1369
|
+
if (!tree.props.onCreate) return;
|
|
1331
1370
|
tree.createInternal();
|
|
1332
1371
|
return;
|
|
1333
1372
|
}
|
|
@@ -1344,6 +1383,7 @@ function $bb9a1e34249689ac$export$ff4858a4110d9246() {
|
|
|
1344
1383
|
return;
|
|
1345
1384
|
}
|
|
1346
1385
|
if (e.key === "Enter") {
|
|
1386
|
+
if (!tree.props.onRename) return;
|
|
1347
1387
|
setTimeout(()=>{
|
|
1348
1388
|
if (tree.focusedNode) tree.edit(tree.focusedNode);
|
|
1349
1389
|
});
|
|
@@ -1511,10 +1551,16 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
|
|
|
1511
1551
|
});
|
|
1512
1552
|
return (node)=>match(node, this.searchTerm);
|
|
1513
1553
|
}
|
|
1514
|
-
|
|
1515
|
-
const get = this.props.
|
|
1554
|
+
accessChildren(data) {
|
|
1555
|
+
const get = this.props.childrenAccessor || "children";
|
|
1516
1556
|
return $eb5355379510ac9b$exports.access(data, get) ?? null;
|
|
1517
1557
|
}
|
|
1558
|
+
accessId(data) {
|
|
1559
|
+
const get = this.props.idAccessor || "id";
|
|
1560
|
+
const id = $eb5355379510ac9b$exports.access(data, get);
|
|
1561
|
+
if (!id) throw new Error("Data must contain an 'id' property or props.idAccessor must return a string");
|
|
1562
|
+
return id;
|
|
1563
|
+
}
|
|
1518
1564
|
/* Node Access */ get firstNode() {
|
|
1519
1565
|
return this.visibleNodes[0] ?? null;
|
|
1520
1566
|
}
|
|
@@ -1726,7 +1772,7 @@ class $5c74fef433be2b0a$export$e2da3477247342d1 {
|
|
|
1726
1772
|
this.scrollTo(id);
|
|
1727
1773
|
$5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
|
|
1728
1774
|
}
|
|
1729
|
-
|
|
1775
|
+
deselectAll() {
|
|
1730
1776
|
this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).clear());
|
|
1731
1777
|
this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).anchor(null));
|
|
1732
1778
|
this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(null));
|
|
@@ -1953,7 +1999,7 @@ function $9511ad6af37da13b$export$c49dab5eb1b4ce0c({ treeProps: treeProps , impe
|
|
|
1953
1999
|
/* Expose the tree api */ (0, $foSVk$react.useImperativeHandle)(imperativeHandle, ()=>api);
|
|
1954
2000
|
/* Change selection based on props */ (0, $foSVk$react.useEffect)(()=>{
|
|
1955
2001
|
if (api.props.selection) api.select(api.props.selection);
|
|
1956
|
-
else api.
|
|
2002
|
+
else api.deselectAll();
|
|
1957
2003
|
}, [
|
|
1958
2004
|
api.props.selection
|
|
1959
2005
|
]);
|
|
@@ -2283,11 +2329,11 @@ var $6cfe0c91f2a90e78$exports = {};
|
|
|
2283
2329
|
|
|
2284
2330
|
$parcel$exportWildcard(module.exports, $73c61fb8fd3b5237$exports);
|
|
2285
2331
|
$parcel$exportWildcard(module.exports, $6740b53b975d3884$exports);
|
|
2332
|
+
$parcel$exportWildcard(module.exports, $6cfe0c91f2a90e78$exports);
|
|
2286
2333
|
$parcel$exportWildcard(module.exports, $9b37fe5960a1a3c6$exports);
|
|
2287
2334
|
$parcel$exportWildcard(module.exports, $5c74fef433be2b0a$exports);
|
|
2288
2335
|
$parcel$exportWildcard(module.exports, $ce2da9e8a36b0fcd$exports);
|
|
2289
2336
|
$parcel$exportWildcard(module.exports, $2492d77b1ec82005$exports);
|
|
2290
|
-
$parcel$exportWildcard(module.exports, $6cfe0c91f2a90e78$exports);
|
|
2291
2337
|
|
|
2292
2338
|
|
|
2293
2339
|
//# sourceMappingURL=index.js.map
|