react-arborist 0.1.14 → 0.2.0-beta.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/{lib/components → components}/drop-cursor.d.ts +1 -0
- package/dist/{lib/components → components}/preview.d.ts +1 -0
- package/dist/{lib/components → components}/row.d.ts +0 -0
- package/dist/{lib/components → components}/tree.d.ts +0 -0
- package/dist/{lib/context.d.ts → context.d.ts} +0 -0
- package/dist/{lib/data → data}/enrich-tree.d.ts +0 -0
- package/dist/{lib/data → data}/flatten-tree.d.ts +0 -0
- package/dist/{lib/dnd → dnd}/compute-drop.d.ts +0 -0
- package/dist/{lib/dnd → dnd}/drag-hook.d.ts +0 -0
- package/dist/{lib/dnd → dnd}/drop-hook.d.ts +0 -0
- package/dist/{lib/dnd → dnd}/outer-drop-hook.d.ts +0 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1354 -0
- package/dist/index.js.map +1 -0
- package/dist/module.js +1346 -0
- package/dist/module.js.map +1 -0
- package/dist/{lib/provider.d.ts → provider.d.ts} +1 -0
- package/dist/{lib/reducer.d.ts → reducer.d.ts} +0 -0
- package/dist/{lib/selection → selection}/range.d.ts +0 -0
- package/dist/{lib/selection → selection}/selection-hook.d.ts +0 -0
- package/dist/{lib/selection → selection}/selection.d.ts +0 -0
- package/dist/{lib/tree-api-hook.d.ts → tree-api-hook.d.ts} +0 -0
- package/dist/{lib/tree-api.d.ts → tree-api.d.ts} +1 -1
- package/dist/{lib/types.d.ts → types.d.ts} +4 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/{lib/utils.d.ts → utils.d.ts} +0 -0
- package/package.json +16 -44
- package/src/components/drop-cursor.tsx +47 -0
- package/src/components/preview.tsx +108 -0
- package/src/components/row.tsx +119 -0
- package/src/components/tree.tsx +118 -0
- package/src/context.tsx +52 -0
- package/src/data/enrich-tree.ts +74 -0
- package/src/data/flatten-tree.ts +17 -0
- package/src/data/make-tree.ts +37 -0
- package/src/dnd/compute-drop.ts +184 -0
- package/src/dnd/drag-hook.ts +48 -0
- package/src/dnd/drop-hook.ts +66 -0
- package/src/dnd/measure-hover.ts +26 -0
- package/src/dnd/outer-drop-hook.ts +50 -0
- package/src/index.ts +5 -0
- package/src/provider.tsx +61 -0
- package/src/reducer.ts +161 -0
- package/src/selection/range.ts +41 -0
- package/src/selection/selection-hook.ts +24 -0
- package/src/selection/selection.test.ts +111 -0
- package/src/selection/selection.ts +186 -0
- package/src/tree-api-hook.ts +34 -0
- package/src/tree-api.ts +129 -0
- package/src/types.ts +147 -0
- package/src/utils.ts +35 -0
- package/tsconfig.json +28 -0
- package/README.md +0 -197
- package/dist/lib/components/drop-cursor.js +0 -53
- package/dist/lib/components/preview.js +0 -91
- package/dist/lib/components/row.js +0 -122
- package/dist/lib/components/tree.js +0 -76
- package/dist/lib/context.js +0 -57
- package/dist/lib/data/enrich-tree.js +0 -48
- package/dist/lib/data/flatten-tree.js +0 -20
- package/dist/lib/data/make-tree.d.ts +0 -5
- package/dist/lib/data/make-tree.js +0 -40
- package/dist/lib/data/visible-nodes-hook.d.ts +0 -2
- package/dist/lib/data/visible-nodes-hook.js +0 -19
- package/dist/lib/dnd/compute-drop.js +0 -146
- package/dist/lib/dnd/drag-hook.js +0 -36
- package/dist/lib/dnd/drop-hook.js +0 -59
- package/dist/lib/dnd/measure-hover.d.ts +0 -8
- package/dist/lib/dnd/measure-hover.js +0 -21
- package/dist/lib/dnd/outer-drop-hook.js +0 -51
- package/dist/lib/index.d.ts +0 -3
- package/dist/lib/index.js +0 -7
- package/dist/lib/provider.js +0 -46
- package/dist/lib/reducer.js +0 -147
- package/dist/lib/selection/range.js +0 -45
- package/dist/lib/selection/selection-hook.js +0 -24
- package/dist/lib/selection/selection.js +0 -192
- package/dist/lib/selection/selection.test.d.ts +0 -1
- package/dist/lib/selection/selection.test.js +0 -102
- package/dist/lib/tree-api-hook.js +0 -26
- package/dist/lib/tree-api.js +0 -130
- package/dist/lib/tree-monitor.d.ts +0 -15
- package/dist/lib/tree-monitor.js +0 -32
- package/dist/lib/types.js +0 -2
- package/dist/lib/utils.js +0 -39
package/dist/lib/tree-api.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TreeApi = void 0;
|
|
7
|
-
var memoize_one_1 = __importDefault(require("memoize-one"));
|
|
8
|
-
var flatten_tree_1 = require("./data/flatten-tree");
|
|
9
|
-
var reducer_1 = require("./reducer");
|
|
10
|
-
var TreeApi = /** @class */ (function () {
|
|
11
|
-
function TreeApi(dispatch, state, props, list) {
|
|
12
|
-
this.dispatch = dispatch;
|
|
13
|
-
this.state = state;
|
|
14
|
-
this.props = props;
|
|
15
|
-
this.list = list;
|
|
16
|
-
}
|
|
17
|
-
TreeApi.prototype.assign = function (dispatch, state, props, list) {
|
|
18
|
-
this.dispatch = dispatch;
|
|
19
|
-
this.state = state;
|
|
20
|
-
this.props = props;
|
|
21
|
-
this.list = list;
|
|
22
|
-
};
|
|
23
|
-
TreeApi.prototype.getNode = function (id) {
|
|
24
|
-
if (id in this.idToIndex)
|
|
25
|
-
return this.visibleNodes[this.idToIndex[id]] || null;
|
|
26
|
-
else
|
|
27
|
-
return null;
|
|
28
|
-
};
|
|
29
|
-
TreeApi.prototype.getSelectedIds = function () {
|
|
30
|
-
return this.state.selection.ids;
|
|
31
|
-
};
|
|
32
|
-
TreeApi.prototype.edit = function (id) {
|
|
33
|
-
this.dispatch(reducer_1.actions.edit(id ? id.toString() : null));
|
|
34
|
-
};
|
|
35
|
-
TreeApi.prototype.select = function (index, meta, shift) {
|
|
36
|
-
this.dispatch(reducer_1.actions.select(index, meta, shift));
|
|
37
|
-
};
|
|
38
|
-
TreeApi.prototype.selectUpwards = function (shiftKey) {
|
|
39
|
-
this.dispatch(reducer_1.actions.stepUp(shiftKey, this.visibleIds));
|
|
40
|
-
};
|
|
41
|
-
TreeApi.prototype.selectDownwards = function (shiftKey) {
|
|
42
|
-
this.dispatch(reducer_1.actions.stepDown(shiftKey, this.visibleIds));
|
|
43
|
-
};
|
|
44
|
-
TreeApi.prototype.hideCursor = function () {
|
|
45
|
-
this.dispatch(reducer_1.actions.setCursorLocation({ type: "none" }));
|
|
46
|
-
};
|
|
47
|
-
TreeApi.prototype.showCursor = function (cursor) {
|
|
48
|
-
this.dispatch(reducer_1.actions.setCursorLocation(cursor));
|
|
49
|
-
};
|
|
50
|
-
TreeApi.prototype.scrollToId = function (id) {
|
|
51
|
-
var _this = this;
|
|
52
|
-
if (!this.list)
|
|
53
|
-
return;
|
|
54
|
-
var index = this.idToIndex[id];
|
|
55
|
-
if (index) {
|
|
56
|
-
this.list.scrollToItem(index, "start");
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
this.openParents(id);
|
|
60
|
-
// This appears to be synchronous
|
|
61
|
-
// But I've only tested it in the console and
|
|
62
|
-
// not in an event handler which will be batched...
|
|
63
|
-
// We may need to wrap this in a timeout or trigger an effect somehow
|
|
64
|
-
setTimeout(function () {
|
|
65
|
-
var _a;
|
|
66
|
-
var index = _this.idToIndex[id];
|
|
67
|
-
if (index) {
|
|
68
|
-
(_a = _this.list) === null || _a === void 0 ? void 0 : _a.scrollToItem(index, "start");
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
TreeApi.prototype.open = function (id) {
|
|
74
|
-
this.props.onToggle(id, true);
|
|
75
|
-
};
|
|
76
|
-
TreeApi.prototype.openParents = function (id) {
|
|
77
|
-
var node = dfs(this.props.root, id);
|
|
78
|
-
var parent = node === null || node === void 0 ? void 0 : node.parent;
|
|
79
|
-
while (parent) {
|
|
80
|
-
this.open(parent.id);
|
|
81
|
-
parent = parent.parent;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
Object.defineProperty(TreeApi.prototype, "visibleIds", {
|
|
85
|
-
get: function () {
|
|
86
|
-
return getIds(this.visibleNodes);
|
|
87
|
-
},
|
|
88
|
-
enumerable: false,
|
|
89
|
-
configurable: true
|
|
90
|
-
});
|
|
91
|
-
Object.defineProperty(TreeApi.prototype, "idToIndex", {
|
|
92
|
-
get: function () {
|
|
93
|
-
return createIndex(this.visibleNodes);
|
|
94
|
-
},
|
|
95
|
-
enumerable: false,
|
|
96
|
-
configurable: true
|
|
97
|
-
});
|
|
98
|
-
Object.defineProperty(TreeApi.prototype, "visibleNodes", {
|
|
99
|
-
get: function () {
|
|
100
|
-
return createList(this.props.root);
|
|
101
|
-
},
|
|
102
|
-
enumerable: false,
|
|
103
|
-
configurable: true
|
|
104
|
-
});
|
|
105
|
-
return TreeApi;
|
|
106
|
-
}());
|
|
107
|
-
exports.TreeApi = TreeApi;
|
|
108
|
-
var getIds = (0, memoize_one_1.default)(function (nodes) { return nodes.map(function (n) { return n.id; }); });
|
|
109
|
-
var createIndex = (0, memoize_one_1.default)(function (nodes) {
|
|
110
|
-
return nodes.reduce(function (map, node, index) {
|
|
111
|
-
map[node.id] = index;
|
|
112
|
-
return map;
|
|
113
|
-
}, {});
|
|
114
|
-
});
|
|
115
|
-
var createList = (0, memoize_one_1.default)(flatten_tree_1.flattenTree);
|
|
116
|
-
function dfs(node, id) {
|
|
117
|
-
if (!node)
|
|
118
|
-
return null;
|
|
119
|
-
if (node.id === id)
|
|
120
|
-
return node;
|
|
121
|
-
if (node.children) {
|
|
122
|
-
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
|
|
123
|
-
var child = _a[_i];
|
|
124
|
-
var result = dfs(child, id);
|
|
125
|
-
if (result)
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Dispatch, MutableRefObject } from "react";
|
|
2
|
-
import { FixedSizeList } from "react-window";
|
|
3
|
-
import { Action } from "./reducer";
|
|
4
|
-
import { StateContext } from "./types";
|
|
5
|
-
export declare class TreeMonitor {
|
|
6
|
-
state: StateContext;
|
|
7
|
-
dispatch: Dispatch<Action>;
|
|
8
|
-
list: MutableRefObject<FixedSizeList | undefined>;
|
|
9
|
-
constructor(state: StateContext, dispatch: Dispatch<Action>, list: MutableRefObject<FixedSizeList | undefined>);
|
|
10
|
-
assign(state: StateContext, dispatch: Dispatch<Action>, list: MutableRefObject<FixedSizeList | undefined>): void;
|
|
11
|
-
getSelectedIds(): string[];
|
|
12
|
-
edit(id: string): void;
|
|
13
|
-
scrollToIndex(index: number, align?: "start" | "center" | "end"): void;
|
|
14
|
-
scrollTo(scrollOffset: number): void;
|
|
15
|
-
}
|
package/dist/lib/tree-monitor.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TreeMonitor = void 0;
|
|
4
|
-
var reducer_1 = require("./reducer");
|
|
5
|
-
var TreeMonitor = /** @class */ (function () {
|
|
6
|
-
function TreeMonitor(state, dispatch, list) {
|
|
7
|
-
this.state = state;
|
|
8
|
-
this.dispatch = dispatch;
|
|
9
|
-
this.list = list;
|
|
10
|
-
}
|
|
11
|
-
TreeMonitor.prototype.assign = function (state, dispatch, list) {
|
|
12
|
-
this.state = state;
|
|
13
|
-
this.dispatch = dispatch;
|
|
14
|
-
this.list = list;
|
|
15
|
-
};
|
|
16
|
-
TreeMonitor.prototype.getSelectedIds = function () {
|
|
17
|
-
return this.state.selection.ids;
|
|
18
|
-
};
|
|
19
|
-
TreeMonitor.prototype.edit = function (id) {
|
|
20
|
-
this.dispatch((0, reducer_1.edit)(id));
|
|
21
|
-
};
|
|
22
|
-
TreeMonitor.prototype.scrollToIndex = function (index, align) {
|
|
23
|
-
var _a;
|
|
24
|
-
(_a = this.list.current) === null || _a === void 0 ? void 0 : _a.scrollToItem(index, align);
|
|
25
|
-
};
|
|
26
|
-
TreeMonitor.prototype.scrollTo = function (scrollOffset) {
|
|
27
|
-
var _a;
|
|
28
|
-
(_a = this.list.current) === null || _a === void 0 ? void 0 : _a.scrollTo(scrollOffset);
|
|
29
|
-
};
|
|
30
|
-
return TreeMonitor;
|
|
31
|
-
}());
|
|
32
|
-
exports.TreeMonitor = TreeMonitor;
|
package/dist/lib/types.js
DELETED
package/dist/lib/utils.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noop = exports.indexOf = exports.isDecendent = exports.isClosed = exports.isItem = exports.isFolder = exports.bound = void 0;
|
|
4
|
-
function bound(n, min, max) {
|
|
5
|
-
return Math.max(Math.min(n, max), min);
|
|
6
|
-
}
|
|
7
|
-
exports.bound = bound;
|
|
8
|
-
var isFolder = function (node) { return !!node.children; };
|
|
9
|
-
exports.isFolder = isFolder;
|
|
10
|
-
function isItem(node) {
|
|
11
|
-
return node && !(0, exports.isFolder)(node);
|
|
12
|
-
}
|
|
13
|
-
exports.isItem = isItem;
|
|
14
|
-
function isClosed(node) {
|
|
15
|
-
return node && (0, exports.isFolder)(node) && !node.isOpen;
|
|
16
|
-
}
|
|
17
|
-
exports.isClosed = isClosed;
|
|
18
|
-
/**
|
|
19
|
-
* Is first param a decendent of the second param
|
|
20
|
-
*/
|
|
21
|
-
var isDecendent = function (a, b) {
|
|
22
|
-
var n = a;
|
|
23
|
-
while (n) {
|
|
24
|
-
if (n.id === b.id)
|
|
25
|
-
return true;
|
|
26
|
-
n = n.parent;
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
};
|
|
30
|
-
exports.isDecendent = isDecendent;
|
|
31
|
-
var indexOf = function (node) {
|
|
32
|
-
// This should probably not throw an error, but instead return null
|
|
33
|
-
if (!node.parent)
|
|
34
|
-
throw Error("Node does not have a parent");
|
|
35
|
-
return node.parent.children.findIndex(function (c) { return c.id === node.id; });
|
|
36
|
-
};
|
|
37
|
-
exports.indexOf = indexOf;
|
|
38
|
-
function noop() { }
|
|
39
|
-
exports.noop = noop;
|