react-arborist 0.1.12 → 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} +4 -3
- package/dist/{lib/data → data}/enrich-tree.d.ts +1 -1
- package/dist/{lib/data → data}/flatten-tree.d.ts +0 -0
- package/dist/dnd/compute-drop.d.ts +37 -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} +4 -3
- 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} +4 -3
- package/dist/{lib/types.d.ts → types.d.ts} +8 -3
- package/dist/types.d.ts.map +1 -0
- package/dist/{lib/utils.d.ts → utils.d.ts} +2 -0
- package/package.json +16 -43
- 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.d.ts +0 -24
- package/dist/lib/dnd/compute-drop.js +0 -113
- package/dist/lib/dnd/drag-hook.js +0 -36
- package/dist/lib/dnd/drop-hook.js +0 -60
- 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 -50
- package/dist/lib/index.d.ts +0 -3
- package/dist/lib/index.js +0 -7
- package/dist/lib/provider.js +0 -44
- package/dist/lib/reducer.js +0 -149
- 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 -31
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Selection = void 0;
|
|
4
|
-
var range_1 = require("./range");
|
|
5
|
-
var Selection = /** @class */ (function () {
|
|
6
|
-
function Selection(ranges, currentIndex, direction, items) {
|
|
7
|
-
var _this = this;
|
|
8
|
-
if (ranges === void 0) { ranges = []; }
|
|
9
|
-
if (currentIndex === void 0) { currentIndex = ranges.length ? ranges.length - 1 : null; }
|
|
10
|
-
if (direction === void 0) { direction = "none"; }
|
|
11
|
-
if (items === void 0) { items = []; }
|
|
12
|
-
this.ranges = [];
|
|
13
|
-
this.direction = "none";
|
|
14
|
-
ranges.forEach(function (_a) {
|
|
15
|
-
var s = _a[0], e = _a[1];
|
|
16
|
-
return _this.addRange(s, e);
|
|
17
|
-
});
|
|
18
|
-
this.currentIndex = currentIndex;
|
|
19
|
-
this.direction = direction;
|
|
20
|
-
this.items = items;
|
|
21
|
-
}
|
|
22
|
-
Selection.parse = function (data, items) {
|
|
23
|
-
if (data) {
|
|
24
|
-
return new Selection(data.ranges, data.currentIndex, data.direction, items);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return new Selection();
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
Object.defineProperty(Selection.prototype, "current", {
|
|
31
|
-
get: function () {
|
|
32
|
-
if (this.currentIndex === null)
|
|
33
|
-
return null;
|
|
34
|
-
var range = this.ranges[this.currentIndex];
|
|
35
|
-
if (!range) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
return range;
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
enumerable: false,
|
|
43
|
-
configurable: true
|
|
44
|
-
});
|
|
45
|
-
Selection.prototype.select = function (n) {
|
|
46
|
-
if (n < 0 || n >= this.items.length)
|
|
47
|
-
return;
|
|
48
|
-
this.clear();
|
|
49
|
-
this.currentIndex = this.addRange(n, n);
|
|
50
|
-
};
|
|
51
|
-
Selection.prototype.multiSelect = function (n) {
|
|
52
|
-
if (n < 0 || n >= this.items.length)
|
|
53
|
-
return;
|
|
54
|
-
if (this.contains(n))
|
|
55
|
-
return;
|
|
56
|
-
this.currentIndex = this.addRange(n, n);
|
|
57
|
-
this.compact(n);
|
|
58
|
-
};
|
|
59
|
-
Selection.prototype.deselect = function (n) {
|
|
60
|
-
if (n < 0 || n >= this.items.length)
|
|
61
|
-
return;
|
|
62
|
-
var r = this.ranges.find(function (r) { return r.contains(n); });
|
|
63
|
-
if (!r)
|
|
64
|
-
return;
|
|
65
|
-
else if (r.size === 1)
|
|
66
|
-
this.removeRange(r);
|
|
67
|
-
else if (r.start === n)
|
|
68
|
-
r.start++;
|
|
69
|
-
else if (r.end === n)
|
|
70
|
-
r.end--;
|
|
71
|
-
else {
|
|
72
|
-
this.removeRange(r);
|
|
73
|
-
this.addRange(r.start, n - 1);
|
|
74
|
-
this.currentIndex = this.addRange(n + 1, r.end);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
Selection.prototype.getSelectedItems = function () {
|
|
78
|
-
var _this = this;
|
|
79
|
-
return this.ranges.flatMap(function (range) {
|
|
80
|
-
return range.map(function (index) { return _this.items[index]; });
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
Selection.prototype.extend = function (n) {
|
|
84
|
-
if (n < 0 || n >= this.items.length)
|
|
85
|
-
return;
|
|
86
|
-
if (this.isEmpty()) {
|
|
87
|
-
this.select(n);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
var anchor = this.getAnchor();
|
|
91
|
-
if (anchor !== null && this.current) {
|
|
92
|
-
var _a = [n, anchor].sort(function (a, b) { return a - b; }), start = _a[0], end = _a[1];
|
|
93
|
-
this.current.start = start;
|
|
94
|
-
this.current.end = end;
|
|
95
|
-
this.compact(n);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
Selection.prototype.contains = function (n) {
|
|
100
|
-
if (n === null)
|
|
101
|
-
return false;
|
|
102
|
-
return this.ranges.some(function (r) { return r.contains(n); });
|
|
103
|
-
};
|
|
104
|
-
Selection.prototype.getRanges = function () {
|
|
105
|
-
return this.ranges.map(function (r) { return r.serialize(); });
|
|
106
|
-
};
|
|
107
|
-
Selection.prototype.clear = function () {
|
|
108
|
-
this.ranges = [];
|
|
109
|
-
this.currentIndex = null;
|
|
110
|
-
this.direction = "none";
|
|
111
|
-
};
|
|
112
|
-
Selection.prototype.serialize = function () {
|
|
113
|
-
return {
|
|
114
|
-
ranges: this.getRanges(),
|
|
115
|
-
currentIndex: this.currentIndex,
|
|
116
|
-
direction: this.direction,
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
Selection.prototype.isEqual = function (other) {
|
|
120
|
-
if (other.ranges.length !== this.ranges.length)
|
|
121
|
-
return false;
|
|
122
|
-
for (var i = 0; i < this.ranges.length; ++i) {
|
|
123
|
-
if (!this.ranges[i].isEqual(other.ranges[i]))
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
return true;
|
|
127
|
-
};
|
|
128
|
-
Selection.prototype.addRange = function (start, end) {
|
|
129
|
-
var r = new range_1.Range(start, end);
|
|
130
|
-
// Keep ranges sorted by start
|
|
131
|
-
var index = this.ranges.findIndex(function (r) { return r.start >= start; });
|
|
132
|
-
if (index === -1)
|
|
133
|
-
this.ranges.push(r);
|
|
134
|
-
else
|
|
135
|
-
this.ranges.splice(index, 0, r);
|
|
136
|
-
return index === -1 ? this.ranges.length - 1 : index;
|
|
137
|
-
};
|
|
138
|
-
Selection.prototype.removeRange = function (r) {
|
|
139
|
-
var index = this.ranges.indexOf(r);
|
|
140
|
-
this.ranges.splice(index, 1);
|
|
141
|
-
if (this.isEmpty()) {
|
|
142
|
-
this.currentIndex = null;
|
|
143
|
-
}
|
|
144
|
-
else if (index === this.currentIndex) {
|
|
145
|
-
this.currentIndex = this.ranges.length - 1;
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
Selection.prototype.isEmpty = function () {
|
|
149
|
-
return this.ranges.length === 0;
|
|
150
|
-
};
|
|
151
|
-
Selection.prototype.getAnchor = function () {
|
|
152
|
-
if (!this.current)
|
|
153
|
-
return null;
|
|
154
|
-
return this.direction === "backward"
|
|
155
|
-
? this.current.end
|
|
156
|
-
: this.current.start;
|
|
157
|
-
};
|
|
158
|
-
Selection.prototype.getFocus = function () {
|
|
159
|
-
if (!this.current)
|
|
160
|
-
return -1;
|
|
161
|
-
return this.direction === "backward"
|
|
162
|
-
? this.current.start
|
|
163
|
-
: this.current.end;
|
|
164
|
-
};
|
|
165
|
-
Selection.prototype.compact = function (focus) {
|
|
166
|
-
var _this = this;
|
|
167
|
-
var removals = [];
|
|
168
|
-
var current = this.current;
|
|
169
|
-
for (var _i = 0, _a = this.ranges; _i < _a.length; _i++) {
|
|
170
|
-
var r = _a[_i];
|
|
171
|
-
if (!this.current || r === this.current)
|
|
172
|
-
continue;
|
|
173
|
-
if (this.current.overlaps(r)) {
|
|
174
|
-
this.current.combine(r);
|
|
175
|
-
removals.push(r);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
removals.forEach(function (r) { return _this.removeRange(r); });
|
|
179
|
-
if (current)
|
|
180
|
-
this.currentIndex = this.ranges.indexOf(current);
|
|
181
|
-
if (!this.current)
|
|
182
|
-
return;
|
|
183
|
-
if (this.current.start < focus)
|
|
184
|
-
this.direction = "forward";
|
|
185
|
-
else if (this.current.end > focus)
|
|
186
|
-
this.direction = "backward";
|
|
187
|
-
else
|
|
188
|
-
this.direction = "none";
|
|
189
|
-
};
|
|
190
|
-
return Selection;
|
|
191
|
-
}());
|
|
192
|
-
exports.Selection = Selection;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var selection_1 = require("./selection");
|
|
4
|
-
var createSelection = function () {
|
|
5
|
-
var ranges = [];
|
|
6
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
7
|
-
ranges[_i] = arguments[_i];
|
|
8
|
-
}
|
|
9
|
-
return new selection_1.Selection(ranges);
|
|
10
|
-
};
|
|
11
|
-
describe("select", function () {
|
|
12
|
-
test("select one after end", function () {
|
|
13
|
-
var s = createSelection([0, 0]);
|
|
14
|
-
s.multiSelect(1);
|
|
15
|
-
expect(s.getRanges()).toEqual([[0, 1]]);
|
|
16
|
-
expect(s.direction).toEqual("forward");
|
|
17
|
-
});
|
|
18
|
-
test("select one before start", function () {
|
|
19
|
-
var s = createSelection([1, 1]);
|
|
20
|
-
s.multiSelect(0);
|
|
21
|
-
expect(s.getRanges()).toEqual([[0, 1]]);
|
|
22
|
-
expect(s.direction).toEqual("backward");
|
|
23
|
-
});
|
|
24
|
-
test("select between two ranges", function () {
|
|
25
|
-
var s = createSelection([0, 0], [2, 2]);
|
|
26
|
-
s.multiSelect(1);
|
|
27
|
-
expect(s.getRanges()).toEqual([[0, 2]]);
|
|
28
|
-
expect(s.direction).toEqual("forward");
|
|
29
|
-
});
|
|
30
|
-
test("select new spot", function () {
|
|
31
|
-
var s = createSelection([0, 0]);
|
|
32
|
-
s.multiSelect(5);
|
|
33
|
-
expect(s.getRanges()).toEqual([
|
|
34
|
-
[0, 0],
|
|
35
|
-
[5, 5],
|
|
36
|
-
]);
|
|
37
|
-
expect(s.direction).toEqual("none");
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
describe("deselect", function () {
|
|
41
|
-
test("one", function () {
|
|
42
|
-
var s = createSelection([0, 0]);
|
|
43
|
-
s.deselect(0);
|
|
44
|
-
expect(s.getRanges()).toEqual([]);
|
|
45
|
-
});
|
|
46
|
-
test("start of a range", function () {
|
|
47
|
-
var s = createSelection([0, 5]);
|
|
48
|
-
s.deselect(0);
|
|
49
|
-
expect(s.getRanges()).toEqual([[1, 5]]);
|
|
50
|
-
});
|
|
51
|
-
test("end of a range", function () {
|
|
52
|
-
var s = createSelection([0, 5]);
|
|
53
|
-
s.deselect(5);
|
|
54
|
-
expect(s.getRanges()).toEqual([[0, 4]]);
|
|
55
|
-
});
|
|
56
|
-
test("between a range", function () {
|
|
57
|
-
var s = createSelection([0, 5]);
|
|
58
|
-
s.deselect(3);
|
|
59
|
-
expect(s.getRanges()).toEqual([
|
|
60
|
-
[0, 2],
|
|
61
|
-
[4, 5],
|
|
62
|
-
]);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
describe("extend", function () {
|
|
66
|
-
test("up", function () {
|
|
67
|
-
var s = createSelection();
|
|
68
|
-
s.multiSelect(5);
|
|
69
|
-
s.extend(6);
|
|
70
|
-
expect(s.getRanges()).toEqual([[5, 6]]);
|
|
71
|
-
});
|
|
72
|
-
test("down", function () {
|
|
73
|
-
var s = createSelection();
|
|
74
|
-
s.multiSelect(5);
|
|
75
|
-
s.extend(4);
|
|
76
|
-
expect(s.getRanges()).toEqual([[4, 5]]);
|
|
77
|
-
});
|
|
78
|
-
test("around anchor", function () {
|
|
79
|
-
var s = createSelection([5, 10]);
|
|
80
|
-
s.extend(1);
|
|
81
|
-
expect(s.getRanges()).toEqual([[1, 5]]);
|
|
82
|
-
});
|
|
83
|
-
test("through other ranges", function () {
|
|
84
|
-
var s = createSelection([0, 0], [5, 5], [9, 10]);
|
|
85
|
-
s.multiSelect(2);
|
|
86
|
-
s.extend(20);
|
|
87
|
-
expect(s.getRanges()).toEqual([
|
|
88
|
-
[0, 0],
|
|
89
|
-
[2, 20],
|
|
90
|
-
]);
|
|
91
|
-
});
|
|
92
|
-
test("clicking backward", function () {
|
|
93
|
-
var s = createSelection([15, 15]);
|
|
94
|
-
s.extend(3);
|
|
95
|
-
expect(s.getRanges()).toEqual([[3, 15]]);
|
|
96
|
-
});
|
|
97
|
-
test("split range then extend", function () {
|
|
98
|
-
var s = createSelection([5, 10]);
|
|
99
|
-
s.deselect(8);
|
|
100
|
-
expect(s.currentIndex).toEqual(1);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useTreeApi = void 0;
|
|
4
|
-
var react_1 = require("react");
|
|
5
|
-
var reducer_1 = require("./reducer");
|
|
6
|
-
var tree_api_1 = require("./tree-api");
|
|
7
|
-
function useTreeApi(state, dispatch, props, list) {
|
|
8
|
-
/**
|
|
9
|
-
* We only ever want one instance of the api object
|
|
10
|
-
* It will get updated as the props change, but the
|
|
11
|
-
* reference will not.
|
|
12
|
-
*/
|
|
13
|
-
var api = (0, react_1.useMemo)(function () { return new tree_api_1.TreeApi(dispatch, state, props, list); },
|
|
14
|
-
// eslint-disable-next-line
|
|
15
|
-
[]);
|
|
16
|
-
api.assign(dispatch, state, props, list);
|
|
17
|
-
/**
|
|
18
|
-
* This ensures that the selection remains correct even
|
|
19
|
-
* after opening and closing a folders
|
|
20
|
-
*/
|
|
21
|
-
(0, react_1.useLayoutEffect)(function () {
|
|
22
|
-
dispatch(reducer_1.actions.setVisibleIds(api.visibleIds, api.idToIndex));
|
|
23
|
-
}, [dispatch, api, props.root]);
|
|
24
|
-
return api;
|
|
25
|
-
}
|
|
26
|
-
exports.useTreeApi = useTreeApi;
|
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(null));
|
|
46
|
-
};
|
|
47
|
-
TreeApi.prototype.showCursor = function (location) {
|
|
48
|
-
this.dispatch(reducer_1.actions.setCursorLocation(location));
|
|
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,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noop = exports.indexOf = exports.isDecendent = 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
|
-
/**
|
|
11
|
-
* Is first param a decendent of the second param
|
|
12
|
-
*/
|
|
13
|
-
var isDecendent = function (a, b) {
|
|
14
|
-
var n = a;
|
|
15
|
-
while (n) {
|
|
16
|
-
if (n.id === b.id)
|
|
17
|
-
return true;
|
|
18
|
-
n = n.parent;
|
|
19
|
-
}
|
|
20
|
-
return false;
|
|
21
|
-
};
|
|
22
|
-
exports.isDecendent = isDecendent;
|
|
23
|
-
var indexOf = function (node) {
|
|
24
|
-
// This should probably not throw an error, but instead return null
|
|
25
|
-
if (!node.parent)
|
|
26
|
-
throw Error("Node does not have a parent");
|
|
27
|
-
return node.parent.children.findIndex(function (c) { return c.id === node.id; });
|
|
28
|
-
};
|
|
29
|
-
exports.indexOf = indexOf;
|
|
30
|
-
function noop() { }
|
|
31
|
-
exports.noop = noop;
|