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.
Files changed (85) hide show
  1. package/dist/{lib/components → components}/drop-cursor.d.ts +1 -0
  2. package/dist/{lib/components → components}/preview.d.ts +1 -0
  3. package/dist/{lib/components → components}/row.d.ts +0 -0
  4. package/dist/{lib/components → components}/tree.d.ts +0 -0
  5. package/dist/{lib/context.d.ts → context.d.ts} +0 -0
  6. package/dist/{lib/data → data}/enrich-tree.d.ts +0 -0
  7. package/dist/{lib/data → data}/flatten-tree.d.ts +0 -0
  8. package/dist/{lib/dnd → dnd}/compute-drop.d.ts +0 -0
  9. package/dist/{lib/dnd → dnd}/drag-hook.d.ts +0 -0
  10. package/dist/{lib/dnd → dnd}/drop-hook.d.ts +0 -0
  11. package/dist/{lib/dnd → dnd}/outer-drop-hook.d.ts +0 -0
  12. package/dist/index.d.ts +4 -0
  13. package/dist/index.js +1354 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/module.js +1346 -0
  16. package/dist/module.js.map +1 -0
  17. package/dist/{lib/provider.d.ts → provider.d.ts} +1 -0
  18. package/dist/{lib/reducer.d.ts → reducer.d.ts} +0 -0
  19. package/dist/{lib/selection → selection}/range.d.ts +0 -0
  20. package/dist/{lib/selection → selection}/selection-hook.d.ts +0 -0
  21. package/dist/{lib/selection → selection}/selection.d.ts +0 -0
  22. package/dist/{lib/tree-api-hook.d.ts → tree-api-hook.d.ts} +0 -0
  23. package/dist/{lib/tree-api.d.ts → tree-api.d.ts} +1 -1
  24. package/dist/{lib/types.d.ts → types.d.ts} +4 -0
  25. package/dist/types.d.ts.map +1 -0
  26. package/dist/{lib/utils.d.ts → utils.d.ts} +0 -0
  27. package/package.json +16 -44
  28. package/src/components/drop-cursor.tsx +47 -0
  29. package/src/components/preview.tsx +108 -0
  30. package/src/components/row.tsx +119 -0
  31. package/src/components/tree.tsx +118 -0
  32. package/src/context.tsx +52 -0
  33. package/src/data/enrich-tree.ts +74 -0
  34. package/src/data/flatten-tree.ts +17 -0
  35. package/src/data/make-tree.ts +37 -0
  36. package/src/dnd/compute-drop.ts +184 -0
  37. package/src/dnd/drag-hook.ts +48 -0
  38. package/src/dnd/drop-hook.ts +66 -0
  39. package/src/dnd/measure-hover.ts +26 -0
  40. package/src/dnd/outer-drop-hook.ts +50 -0
  41. package/src/index.ts +5 -0
  42. package/src/provider.tsx +61 -0
  43. package/src/reducer.ts +161 -0
  44. package/src/selection/range.ts +41 -0
  45. package/src/selection/selection-hook.ts +24 -0
  46. package/src/selection/selection.test.ts +111 -0
  47. package/src/selection/selection.ts +186 -0
  48. package/src/tree-api-hook.ts +34 -0
  49. package/src/tree-api.ts +129 -0
  50. package/src/types.ts +147 -0
  51. package/src/utils.ts +35 -0
  52. package/tsconfig.json +28 -0
  53. package/README.md +0 -197
  54. package/dist/lib/components/drop-cursor.js +0 -53
  55. package/dist/lib/components/preview.js +0 -91
  56. package/dist/lib/components/row.js +0 -122
  57. package/dist/lib/components/tree.js +0 -76
  58. package/dist/lib/context.js +0 -57
  59. package/dist/lib/data/enrich-tree.js +0 -48
  60. package/dist/lib/data/flatten-tree.js +0 -20
  61. package/dist/lib/data/make-tree.d.ts +0 -5
  62. package/dist/lib/data/make-tree.js +0 -40
  63. package/dist/lib/data/visible-nodes-hook.d.ts +0 -2
  64. package/dist/lib/data/visible-nodes-hook.js +0 -19
  65. package/dist/lib/dnd/compute-drop.js +0 -146
  66. package/dist/lib/dnd/drag-hook.js +0 -36
  67. package/dist/lib/dnd/drop-hook.js +0 -59
  68. package/dist/lib/dnd/measure-hover.d.ts +0 -8
  69. package/dist/lib/dnd/measure-hover.js +0 -21
  70. package/dist/lib/dnd/outer-drop-hook.js +0 -51
  71. package/dist/lib/index.d.ts +0 -3
  72. package/dist/lib/index.js +0 -7
  73. package/dist/lib/provider.js +0 -46
  74. package/dist/lib/reducer.js +0 -147
  75. package/dist/lib/selection/range.js +0 -45
  76. package/dist/lib/selection/selection-hook.js +0 -24
  77. package/dist/lib/selection/selection.js +0 -192
  78. package/dist/lib/selection/selection.test.d.ts +0 -1
  79. package/dist/lib/selection/selection.test.js +0 -102
  80. package/dist/lib/tree-api-hook.js +0 -26
  81. package/dist/lib/tree-api.js +0 -130
  82. package/dist/lib/tree-monitor.d.ts +0 -15
  83. package/dist/lib/tree-monitor.js +0 -32
  84. package/dist/lib/types.js +0 -2
  85. package/dist/lib/utils.js +0 -39
package/dist/module.js ADDED
@@ -0,0 +1,1346 @@
1
+ import {jsxs as $g00cZ$jsxs, jsx as $g00cZ$jsx} from "react/jsx-runtime";
2
+ import $g00cZ$react, {forwardRef as $g00cZ$forwardRef, useMemo as $g00cZ$useMemo, useRef as $g00cZ$useRef, createContext as $g00cZ$createContext, useContext as $g00cZ$useContext, useReducer as $g00cZ$useReducer, useImperativeHandle as $g00cZ$useImperativeHandle, useEffect as $g00cZ$useEffect, useLayoutEffect as $g00cZ$useLayoutEffect, memo as $g00cZ$memo, useCallback as $g00cZ$useCallback} from "react";
3
+ import {DndProvider as $g00cZ$DndProvider, useDrop as $g00cZ$useDrop, useDragLayer as $g00cZ$useDragLayer, useDrag as $g00cZ$useDrag} from "react-dnd";
4
+ import {HTML5Backend as $g00cZ$HTML5Backend, getEmptyImage as $g00cZ$getEmptyImage} from "react-dnd-html5-backend";
5
+ import {FixedSizeList as $g00cZ$FixedSizeList} from "react-window";
6
+ import $g00cZ$memoizeone from "memoize-one";
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+ class $043ce40ea783107b$export$9a58ef0d7ad3278c {
15
+ constructor(start, end){
16
+ this.start = start;
17
+ this.end = end;
18
+ if (this.start > this.end) throw new Error("Invalid range: start larger than end");
19
+ }
20
+ serialize() {
21
+ return [
22
+ this.start,
23
+ this.end
24
+ ];
25
+ }
26
+ contains(n) {
27
+ return n >= this.start && n <= this.end;
28
+ }
29
+ overlaps(r) {
30
+ return this.contains(r.start - 1) || this.contains(r.end + 1);
31
+ }
32
+ combine(r) {
33
+ this.start = Math.min(r.start, this.start);
34
+ this.end = Math.max(r.end, this.end);
35
+ }
36
+ get size() {
37
+ return this.end - this.start + 1;
38
+ }
39
+ clone() {
40
+ return new $043ce40ea783107b$export$9a58ef0d7ad3278c(this.start, this.end);
41
+ }
42
+ map(fn) {
43
+ let returns = [];
44
+ for(let i = this.start; i <= this.end; i++)returns.push(fn(i));
45
+ return returns;
46
+ }
47
+ isEqual(other) {
48
+ return this.start === other.start && this.end === other.end;
49
+ }
50
+ }
51
+
52
+
53
+ class $5ee99f971bd267fd$export$52baac22726c72bf {
54
+ static parse(data, items) {
55
+ if (data) return new $5ee99f971bd267fd$export$52baac22726c72bf(data.ranges, data.currentIndex, data.direction, items);
56
+ else return new $5ee99f971bd267fd$export$52baac22726c72bf();
57
+ }
58
+ constructor(ranges = [], currentIndex = ranges.length ? ranges.length - 1 : null, direction = "none", items = []){
59
+ this.ranges = [];
60
+ this.direction = "none";
61
+ ranges.forEach(([s, e])=>this.addRange(s, e)
62
+ );
63
+ this.currentIndex = currentIndex;
64
+ this.direction = direction;
65
+ this.items = items;
66
+ }
67
+ get current() {
68
+ if (this.currentIndex === null) return null;
69
+ const range = this.ranges[this.currentIndex];
70
+ if (!range) return null;
71
+ else return range;
72
+ }
73
+ select(n) {
74
+ if (n < 0 || n >= this.items.length) return;
75
+ this.clear();
76
+ this.currentIndex = this.addRange(n, n);
77
+ }
78
+ multiSelect(n) {
79
+ if (n < 0 || n >= this.items.length) return;
80
+ if (this.contains(n)) return;
81
+ this.currentIndex = this.addRange(n, n);
82
+ this.compact(n);
83
+ }
84
+ deselect(n) {
85
+ if (n < 0 || n >= this.items.length) return;
86
+ const r1 = this.ranges.find((r)=>r.contains(n)
87
+ );
88
+ if (!r1) return;
89
+ else if (r1.size === 1) this.removeRange(r1);
90
+ else if (r1.start === n) r1.start++;
91
+ else if (r1.end === n) r1.end--;
92
+ else {
93
+ this.removeRange(r1);
94
+ this.addRange(r1.start, n - 1);
95
+ this.currentIndex = this.addRange(n + 1, r1.end);
96
+ }
97
+ }
98
+ getSelectedItems() {
99
+ return this.ranges.flatMap((range)=>range.map((index)=>this.items[index]
100
+ )
101
+ );
102
+ }
103
+ extend(n) {
104
+ if (n < 0 || n >= this.items.length) return;
105
+ if (this.isEmpty()) this.select(n);
106
+ else {
107
+ const anchor = this.getAnchor();
108
+ if (anchor !== null && this.current) {
109
+ const [start, end] = [
110
+ n,
111
+ anchor
112
+ ].sort((a, b)=>a - b
113
+ );
114
+ this.current.start = start;
115
+ this.current.end = end;
116
+ this.compact(n);
117
+ }
118
+ }
119
+ }
120
+ contains(n) {
121
+ if (n === null) return false;
122
+ return this.ranges.some((r)=>r.contains(n)
123
+ );
124
+ }
125
+ getRanges() {
126
+ return this.ranges.map((r)=>r.serialize()
127
+ );
128
+ }
129
+ clear() {
130
+ this.ranges = [];
131
+ this.currentIndex = null;
132
+ this.direction = "none";
133
+ }
134
+ serialize() {
135
+ return {
136
+ ranges: this.getRanges(),
137
+ currentIndex: this.currentIndex,
138
+ direction: this.direction
139
+ };
140
+ }
141
+ isEqual(other) {
142
+ if (other.ranges.length !== this.ranges.length) return false;
143
+ for(let i = 0; i < this.ranges.length; ++i){
144
+ if (!this.ranges[i].isEqual(other.ranges[i])) return false;
145
+ }
146
+ return true;
147
+ }
148
+ addRange(start, end) {
149
+ const r2 = new $043ce40ea783107b$export$9a58ef0d7ad3278c(start, end);
150
+ // Keep ranges sorted by start
151
+ const index = this.ranges.findIndex((r)=>r.start >= start
152
+ );
153
+ if (index === -1) this.ranges.push(r2);
154
+ else this.ranges.splice(index, 0, r2);
155
+ return index === -1 ? this.ranges.length - 1 : index;
156
+ }
157
+ removeRange(r) {
158
+ const index = this.ranges.indexOf(r);
159
+ this.ranges.splice(index, 1);
160
+ if (this.isEmpty()) this.currentIndex = null;
161
+ else if (index === this.currentIndex) this.currentIndex = this.ranges.length - 1;
162
+ }
163
+ isEmpty() {
164
+ return this.ranges.length === 0;
165
+ }
166
+ getAnchor() {
167
+ if (!this.current) return null;
168
+ return this.direction === "backward" ? this.current.end : this.current.start;
169
+ }
170
+ getFocus() {
171
+ if (!this.current) return -1;
172
+ return this.direction === "backward" ? this.current.start : this.current.end;
173
+ }
174
+ compact(focus) {
175
+ const removals = [];
176
+ const current = this.current;
177
+ for (let r3 of this.ranges){
178
+ if (!this.current || r3 === this.current) continue;
179
+ if (this.current.overlaps(r3)) {
180
+ this.current.combine(r3);
181
+ removals.push(r3);
182
+ }
183
+ }
184
+ removals.forEach((r)=>this.removeRange(r)
185
+ );
186
+ if (current) this.currentIndex = this.ranges.indexOf(current);
187
+ if (!this.current) return;
188
+ if (this.current.start < focus) this.direction = "forward";
189
+ else if (this.current.end > focus) this.direction = "backward";
190
+ else this.direction = "none";
191
+ }
192
+ }
193
+
194
+
195
+ const $3273af3fe11a7001$export$7380e5d4146ff2ce = /*#__PURE__*/ $g00cZ$createContext(null);
196
+ function $3273af3fe11a7001$export$8e294ac6de4c921f() {
197
+ return $g00cZ$useContext($3273af3fe11a7001$export$7380e5d4146ff2ce);
198
+ }
199
+ const $3273af3fe11a7001$export$86fe4415b73783a1 = /*#__PURE__*/ $g00cZ$createContext(false);
200
+ function $3273af3fe11a7001$export$f3ad962ff713505f() {
201
+ return $g00cZ$useContext($3273af3fe11a7001$export$86fe4415b73783a1);
202
+ }
203
+ const $3273af3fe11a7001$export$76f51715425ee155 = /*#__PURE__*/ $g00cZ$createContext(null);
204
+ function $3273af3fe11a7001$export$6c87584817ff2461() {
205
+ return $g00cZ$useContext($3273af3fe11a7001$export$76f51715425ee155);
206
+ }
207
+ const $3273af3fe11a7001$export$c1b9a1d3af45b7b6 = /*#__PURE__*/ $g00cZ$createContext(null);
208
+ function $3273af3fe11a7001$export$ea6c3ae2bd3a5510() {
209
+ const value = $g00cZ$useContext($3273af3fe11a7001$export$c1b9a1d3af45b7b6);
210
+ if (!value) throw new Error("Context must be in a provider");
211
+ return value;
212
+ }
213
+ const $3273af3fe11a7001$export$f34e95fabff36a8f = /*#__PURE__*/ $g00cZ$createContext(null);
214
+ function $3273af3fe11a7001$export$8ad76b76a4c905f8() {
215
+ const dispatch = $g00cZ$useContext($3273af3fe11a7001$export$f34e95fabff36a8f);
216
+ if (!dispatch) throw new Error("No dispatch provided");
217
+ return dispatch;
218
+ }
219
+ const $3273af3fe11a7001$export$7c7a4fd7f1336e2c = /*#__PURE__*/ $g00cZ$createContext(null);
220
+ function $3273af3fe11a7001$export$1c9b7756eccadc96() {
221
+ const value = $g00cZ$useContext($3273af3fe11a7001$export$7c7a4fd7f1336e2c);
222
+ if (!value) throw new Error("Must provide selection context");
223
+ return value.ids;
224
+ }
225
+ function $3273af3fe11a7001$export$fb40a80c530e5f2b() {
226
+ const value = $g00cZ$useContext($3273af3fe11a7001$export$7c7a4fd7f1336e2c);
227
+ if (!value) throw new Error("Must provide selection context");
228
+ const s = $g00cZ$useMemo(()=>$5ee99f971bd267fd$export$52baac22726c72bf.parse(value.data, [])
229
+ , [
230
+ value.data
231
+ ]);
232
+ return (i)=>s.contains(i)
233
+ ;
234
+ }
235
+ const $3273af3fe11a7001$export$7f994e57c9e78355 = /*#__PURE__*/ $g00cZ$createContext(null);
236
+ function $3273af3fe11a7001$export$9ab192f953c1b33b() {
237
+ return $g00cZ$useContext($3273af3fe11a7001$export$7f994e57c9e78355);
238
+ }
239
+
240
+
241
+ function $1e5818ce7991d06d$var$createNode(model, level, parent, children, isOpen, isDraggable, isDroppable) {
242
+ return {
243
+ id: model.id,
244
+ level: level,
245
+ parent: parent,
246
+ children: children,
247
+ isOpen: isOpen,
248
+ isDraggable: isDraggable,
249
+ isDroppable: isDroppable,
250
+ model: model,
251
+ rowIndex: null
252
+ };
253
+ }
254
+ function $1e5818ce7991d06d$var$access(obj, accessor) {
255
+ if (typeof accessor === "boolean") return accessor;
256
+ if (typeof accessor === "string") return obj[accessor];
257
+ return accessor(obj);
258
+ }
259
+ function $1e5818ce7991d06d$export$9c537176392280a0(model1, hideRoot = false, getChildren = "children", isOpen = "isOpen", disableDrag = false, disableDrop = false, openByDefault = true) {
260
+ function visitSelfAndChildren(model, level, parent) {
261
+ const open = $1e5818ce7991d06d$var$access(model, isOpen);
262
+ const draggable = !$1e5818ce7991d06d$var$access(model, disableDrag);
263
+ const droppable = !$1e5818ce7991d06d$var$access(model, disableDrop);
264
+ const node = $1e5818ce7991d06d$var$createNode(model, level, parent, null, open === undefined ? openByDefault : open, draggable, droppable);
265
+ const children = $1e5818ce7991d06d$var$access(model, getChildren);
266
+ if (children) node.children = children.map((child)=>visitSelfAndChildren(child, level + 1, node)
267
+ );
268
+ return node;
269
+ }
270
+ return visitSelfAndChildren(model1, hideRoot ? -1 : 0, null);
271
+ }
272
+
273
+
274
+
275
+
276
+ function $0e6083160f4b36ed$export$adf7c0fe6059d774(n, min, max) {
277
+ return Math.max(Math.min(n, max), min);
278
+ }
279
+ const $0e6083160f4b36ed$export$769c5e872f5f8638 = (node)=>!!node.children
280
+ ;
281
+ function $0e6083160f4b36ed$export$5318634f2ee07019(node) {
282
+ return node && !$0e6083160f4b36ed$export$769c5e872f5f8638(node);
283
+ }
284
+ function $0e6083160f4b36ed$export$4210f5ea57fbae57(node) {
285
+ return node && $0e6083160f4b36ed$export$769c5e872f5f8638(node) && !node.isOpen;
286
+ }
287
+ const $0e6083160f4b36ed$export$1e38f72c6c546f70 = (a, b)=>{
288
+ let n = a;
289
+ while(n){
290
+ if (n.id === b.id) return true;
291
+ n = n.parent;
292
+ }
293
+ return false;
294
+ };
295
+ const $0e6083160f4b36ed$export$305f7d4e9d4624f2 = (node)=>{
296
+ // This should probably not throw an error, but instead return null
297
+ if (!node.parent) throw Error("Node does not have a parent");
298
+ return node.parent.children.findIndex((c)=>c.id === node.id
299
+ );
300
+ };
301
+ function $0e6083160f4b36ed$export$8793edee2d425525() {
302
+ }
303
+
304
+
305
+ function $2db980bfed6822da$var$measureHover(el, offset) {
306
+ const rect = el.getBoundingClientRect();
307
+ const x = offset.x - Math.round(rect.x);
308
+ const y = offset.y - Math.round(rect.y);
309
+ const height = rect.height;
310
+ const inTopHalf = y < height / 2;
311
+ const inBottomHalf = !inTopHalf;
312
+ const pad = height / 4;
313
+ const inMiddle = y > pad && y < height - pad;
314
+ const atTop = !inMiddle && inTopHalf;
315
+ const atBottom = !inMiddle && inBottomHalf;
316
+ return {
317
+ x: x,
318
+ inTopHalf: inTopHalf,
319
+ inBottomHalf: inBottomHalf,
320
+ inMiddle: inMiddle,
321
+ atTop: atTop,
322
+ atBottom: atBottom
323
+ };
324
+ }
325
+ function $2db980bfed6822da$var$getNodesAroundCursor(node, prev, next, hover) {
326
+ if (!node) // We're hoving over the empty part of the list, not over an item,
327
+ // Put the cursor below the last item which is "prev"
328
+ return [
329
+ prev,
330
+ null
331
+ ];
332
+ if ($0e6083160f4b36ed$export$769c5e872f5f8638(node)) {
333
+ if (hover.atTop) return [
334
+ prev,
335
+ node
336
+ ];
337
+ else if (hover.inMiddle) return [
338
+ node,
339
+ node
340
+ ];
341
+ else return [
342
+ node,
343
+ next
344
+ ];
345
+ } else {
346
+ if (hover.inTopHalf) return [
347
+ prev,
348
+ node
349
+ ];
350
+ else return [
351
+ node,
352
+ next
353
+ ];
354
+ }
355
+ }
356
+ function $2db980bfed6822da$var$getDropLevel(hovering, aboveCursor, belowCursor, indent) {
357
+ const hoverLevel = Math.round(Math.max(0, hovering.x - indent) / indent);
358
+ let min, max;
359
+ if (!aboveCursor) {
360
+ max = 0;
361
+ min = 0;
362
+ } else if (!belowCursor) {
363
+ max = aboveCursor.level;
364
+ min = 0;
365
+ } else {
366
+ max = aboveCursor.level;
367
+ min = belowCursor.level;
368
+ }
369
+ return $0e6083160f4b36ed$export$adf7c0fe6059d774(hoverLevel, min, max);
370
+ }
371
+ function $2db980bfed6822da$var$canDrop(above, below) {
372
+ if (!above) return true;
373
+ let n = above;
374
+ if ($0e6083160f4b36ed$export$4210f5ea57fbae57(above) && above !== below) n = above.parent;
375
+ while(n){
376
+ if (!n.isDroppable) return false;
377
+ n = n.parent;
378
+ }
379
+ return true;
380
+ }
381
+ function $2db980bfed6822da$var$dropAt(parentId, index) {
382
+ return {
383
+ parentId: parentId || null,
384
+ index: index
385
+ };
386
+ }
387
+ function $2db980bfed6822da$var$lineCursor(index, level) {
388
+ return {
389
+ type: "line",
390
+ index: index,
391
+ level: level
392
+ };
393
+ }
394
+ function $2db980bfed6822da$var$noCursor() {
395
+ return {
396
+ type: "none"
397
+ };
398
+ }
399
+ function $2db980bfed6822da$var$highlightCursor(id) {
400
+ return {
401
+ type: "highlight",
402
+ id: id
403
+ };
404
+ }
405
+ function $2db980bfed6822da$var$walkUpFrom(node, level) {
406
+ let drop = node;
407
+ while(drop.parent && drop.level > level)drop = drop.parent;
408
+ const parentId = drop.parent?.id || null;
409
+ const index = $0e6083160f4b36ed$export$305f7d4e9d4624f2(drop) + 1;
410
+ return {
411
+ parentId: parentId,
412
+ index: index
413
+ };
414
+ }
415
+ function $2db980bfed6822da$export$f502ca02ebb85a1c(args) {
416
+ const hover = $2db980bfed6822da$var$measureHover(args.element, args.offset);
417
+ const { node: node , nextNode: nextNode , prevNode: prevNode } = args;
418
+ const [above, below] = $2db980bfed6822da$var$getNodesAroundCursor(node, prevNode, nextNode, hover);
419
+ if (!$2db980bfed6822da$var$canDrop(above, below)) return {
420
+ drop: null,
421
+ cursor: $2db980bfed6822da$var$noCursor()
422
+ };
423
+ /* Hovering over the middle of a folder */ if (node && $0e6083160f4b36ed$export$769c5e872f5f8638(node) && hover.inMiddle) return {
424
+ drop: $2db980bfed6822da$var$dropAt(node.id, 0),
425
+ cursor: $2db980bfed6822da$var$highlightCursor(node.id)
426
+ };
427
+ /* At the top of the list */ if (!above) return {
428
+ drop: $2db980bfed6822da$var$dropAt(below?.parent?.id, 0),
429
+ cursor: $2db980bfed6822da$var$lineCursor(0, 0)
430
+ };
431
+ /* The above node is an item or a closed folder */ if ($0e6083160f4b36ed$export$5318634f2ee07019(above) || $0e6083160f4b36ed$export$4210f5ea57fbae57(above)) {
432
+ const level = $2db980bfed6822da$var$getDropLevel(hover, above, below, args.indent);
433
+ return {
434
+ drop: $2db980bfed6822da$var$walkUpFrom(above, level),
435
+ cursor: $2db980bfed6822da$var$lineCursor(above.rowIndex + 1, level)
436
+ };
437
+ }
438
+ /* The above node is an open folder */ return {
439
+ drop: $2db980bfed6822da$var$dropAt(above?.id, 0),
440
+ cursor: $2db980bfed6822da$var$lineCursor(above.rowIndex + 1, above.level + 1)
441
+ };
442
+ }
443
+
444
+
445
+ function $e739455e59c6aed3$export$5a6c424b1725f44f() {
446
+ const tree = $3273af3fe11a7001$export$ea6c3ae2bd3a5510();
447
+ // In case we drop an item at the bottom of the list
448
+ const [, drop1] = $g00cZ$useDrop(()=>({
449
+ accept: "NODE",
450
+ hover: (item, m)=>{
451
+ if (!m.isOver({
452
+ shallow: true
453
+ })) return;
454
+ const offset = m.getClientOffset();
455
+ if (!tree.listEl.current || !offset) return;
456
+ const { cursor: cursor } = $2db980bfed6822da$export$f502ca02ebb85a1c({
457
+ element: tree.listEl.current,
458
+ offset: offset,
459
+ indent: tree.indent,
460
+ node: null,
461
+ prevNode: tree.api.visibleNodes[tree.api.visibleNodes.length - 1],
462
+ nextNode: null
463
+ });
464
+ if (cursor) tree.api.showCursor(cursor);
465
+ },
466
+ canDrop: (item, m)=>{
467
+ return m.isOver({
468
+ shallow: true
469
+ });
470
+ },
471
+ drop: (item, m)=>{
472
+ if (m.didDrop()) return;
473
+ const offset = m.getClientOffset();
474
+ if (!tree.listEl.current || !offset) return;
475
+ const { drop: drop } = $2db980bfed6822da$export$f502ca02ebb85a1c({
476
+ element: tree.listEl.current,
477
+ offset: offset,
478
+ indent: tree.indent,
479
+ node: null,
480
+ prevNode: tree.api.visibleNodes[tree.api.visibleNodes.length - 1],
481
+ nextNode: null
482
+ });
483
+ return drop;
484
+ }
485
+ })
486
+ , [
487
+ tree
488
+ ]);
489
+ drop1(tree.listEl);
490
+ }
491
+
492
+
493
+
494
+
495
+
496
+
497
+ const $b26f0eafd5701d7d$export$f6196a6c6bb539b4 = ()=>({
498
+ visibleIds: [],
499
+ cursor: {
500
+ type: "none"
501
+ },
502
+ editingId: null,
503
+ selection: {
504
+ data: null,
505
+ ids: []
506
+ }
507
+ })
508
+ ;
509
+ const $b26f0eafd5701d7d$export$e324594224ef24da = {
510
+ setCursorLocation: (cursor)=>({
511
+ type: "SET_CURSOR_LOCATION",
512
+ cursor: cursor
513
+ })
514
+ ,
515
+ setVisibleIds: (ids, idMap // id to index
516
+ )=>({
517
+ type: "SET_VISIBLE_IDS",
518
+ ids: ids,
519
+ idMap: idMap
520
+ })
521
+ ,
522
+ select: (index, meta, shift)=>({
523
+ type: "SELECT",
524
+ index: index,
525
+ meta: meta,
526
+ shift: shift
527
+ })
528
+ ,
529
+ selectId: (id)=>({
530
+ type: "SELECT_ID",
531
+ id: id
532
+ })
533
+ ,
534
+ edit: (id)=>({
535
+ type: "EDIT",
536
+ id: id
537
+ })
538
+ ,
539
+ stepUp: (shift, ids)=>({
540
+ type: "STEP_UP",
541
+ shift: shift
542
+ })
543
+ ,
544
+ stepDown: (shift, ids)=>({
545
+ type: "STEP_DOWN",
546
+ shift: shift
547
+ })
548
+ };
549
+ function $b26f0eafd5701d7d$export$1650419e431d3ba3(state, action) {
550
+ switch(action.type){
551
+ case "EDIT":
552
+ return {
553
+ ...state,
554
+ editingId: action.id
555
+ };
556
+ case "SET_CURSOR_LOCATION":
557
+ if ($b26f0eafd5701d7d$var$equal(state.cursor, action.cursor)) return state;
558
+ else return {
559
+ ...state,
560
+ cursor: action.cursor
561
+ };
562
+ case "SELECT":
563
+ var s = $5ee99f971bd267fd$export$52baac22726c72bf.parse(state.selection.data, state.visibleIds);
564
+ if (action.index === null) s.clear();
565
+ else if (action.meta) {
566
+ if (s.contains(action.index)) s.deselect(action.index);
567
+ else s.multiSelect(action.index);
568
+ } else if (action.shift) s.extend(action.index);
569
+ else s.select(action.index);
570
+ return {
571
+ ...state,
572
+ selection: {
573
+ data: s.serialize(),
574
+ ids: s.getSelectedItems()
575
+ }
576
+ };
577
+ case "SELECT_ID":
578
+ return {
579
+ ...state,
580
+ selection: {
581
+ ...state.selection,
582
+ ids: [
583
+ action.id
584
+ ]
585
+ }
586
+ };
587
+ case "STEP_UP":
588
+ var s3 = $5ee99f971bd267fd$export$52baac22726c72bf.parse(state.selection.data, state.visibleIds);
589
+ var f = s3.getFocus();
590
+ if (action.shift) s3.extend(f - 1);
591
+ else s3.select(f - 1);
592
+ return {
593
+ ...state,
594
+ selection: {
595
+ data: s3.serialize(),
596
+ ids: s3.getSelectedItems()
597
+ }
598
+ };
599
+ case "STEP_DOWN":
600
+ var s6 = $5ee99f971bd267fd$export$52baac22726c72bf.parse(state.selection.data, state.visibleIds);
601
+ var f2 = s6.getFocus();
602
+ if (action.shift) s6.extend(f2 + 1);
603
+ else s6.select(f2 + 1);
604
+ return {
605
+ ...state,
606
+ selection: {
607
+ data: s6.serialize(),
608
+ ids: s6.getSelectedItems()
609
+ }
610
+ };
611
+ case "SET_VISIBLE_IDS":
612
+ // The visible ids changed
613
+ var ids = state.selection.ids;
614
+ // Start with a blank selection
615
+ var s2 = new $5ee99f971bd267fd$export$52baac22726c72bf([], null, "none", state.visibleIds);
616
+ // Add each of the old selected ids to this new selection
617
+ for (let id of ids)if (id in action.idMap) s2.multiSelect(action.idMap[id]);
618
+ return {
619
+ ...state,
620
+ visibleIds: action.ids,
621
+ selection: {
622
+ ids: ids,
623
+ data: s2.serialize()
624
+ }
625
+ };
626
+ default:
627
+ return state;
628
+ }
629
+ }
630
+ function $b26f0eafd5701d7d$var$equal(a, b) {
631
+ if (a === null || b === null) return false;
632
+ return JSON.stringify(a) === JSON.stringify(b);
633
+ }
634
+
635
+
636
+
637
+ function $bafe08914d05476b$export$de605877a37dc399(ref, api) {
638
+ $g00cZ$useEffect(()=>{
639
+ const el = ref.current;
640
+ const cb = (e)=>{
641
+ if (e.code === "ArrowDown") {
642
+ e.preventDefault();
643
+ api.selectDownwards(e.shiftKey);
644
+ } else if (e.code === "ArrowUp") {
645
+ e.preventDefault();
646
+ api.selectUpwards(e.shiftKey);
647
+ }
648
+ };
649
+ el?.addEventListener("keydown", cb);
650
+ return ()=>{
651
+ el?.removeEventListener("keydown", cb);
652
+ };
653
+ }, [
654
+ ref,
655
+ api
656
+ ]);
657
+ }
658
+
659
+
660
+
661
+
662
+
663
+ function $4dcb7be69f759cab$export$79f9fa345a841d8b(root) {
664
+ const list = [];
665
+ let index = 0;
666
+ function collect(node) {
667
+ if (node.level >= 0) {
668
+ node.rowIndex = index++;
669
+ list.push(node);
670
+ }
671
+ if (node.isOpen) node.children?.forEach(collect);
672
+ }
673
+ collect(root);
674
+ return list;
675
+ }
676
+
677
+
678
+
679
+ class $40fcfa3e17312481$export$e2da3477247342d1 {
680
+ constructor(dispatch, state, props, list){
681
+ this.dispatch = dispatch;
682
+ this.state = state;
683
+ this.props = props;
684
+ this.list = list;
685
+ }
686
+ assign(dispatch, state, props, list) {
687
+ this.dispatch = dispatch;
688
+ this.state = state;
689
+ this.props = props;
690
+ this.list = list;
691
+ }
692
+ getNode(id) {
693
+ if (id in this.idToIndex) return this.visibleNodes[this.idToIndex[id]] || null;
694
+ else return null;
695
+ }
696
+ getSelectedIds() {
697
+ return this.state.selection.ids;
698
+ }
699
+ edit(id) {
700
+ this.dispatch($b26f0eafd5701d7d$export$e324594224ef24da.edit(id ? id.toString() : null));
701
+ }
702
+ select(index, meta, shift) {
703
+ this.dispatch($b26f0eafd5701d7d$export$e324594224ef24da.select(index, meta, shift));
704
+ }
705
+ selectUpwards(shiftKey) {
706
+ this.dispatch($b26f0eafd5701d7d$export$e324594224ef24da.stepUp(shiftKey, this.visibleIds));
707
+ }
708
+ selectDownwards(shiftKey) {
709
+ this.dispatch($b26f0eafd5701d7d$export$e324594224ef24da.stepDown(shiftKey, this.visibleIds));
710
+ }
711
+ hideCursor() {
712
+ this.dispatch($b26f0eafd5701d7d$export$e324594224ef24da.setCursorLocation({
713
+ type: "none"
714
+ }));
715
+ }
716
+ showCursor(cursor) {
717
+ this.dispatch($b26f0eafd5701d7d$export$e324594224ef24da.setCursorLocation(cursor));
718
+ }
719
+ scrollToId(id) {
720
+ if (!this.list) return;
721
+ const index1 = this.idToIndex[id];
722
+ if (index1) this.list.scrollToItem(index1, "start");
723
+ else {
724
+ this.openParents(id);
725
+ // This appears to be synchronous
726
+ // But I've only tested it in the console and
727
+ // not in an event handler which will be batched...
728
+ // We may need to wrap this in a timeout or trigger an effect somehow
729
+ setTimeout(()=>{
730
+ const index = this.idToIndex[id];
731
+ if (index) this.list?.scrollToItem(index, "start");
732
+ });
733
+ }
734
+ }
735
+ open(id) {
736
+ this.props.onToggle(id, true);
737
+ }
738
+ openParents(id) {
739
+ const node = $40fcfa3e17312481$var$dfs(this.props.root, id);
740
+ let parent = node?.parent;
741
+ while(parent){
742
+ this.open(parent.id);
743
+ parent = parent.parent;
744
+ }
745
+ }
746
+ get visibleIds() {
747
+ return $40fcfa3e17312481$var$getIds(this.visibleNodes);
748
+ }
749
+ get idToIndex() {
750
+ return $40fcfa3e17312481$var$createIndex(this.visibleNodes);
751
+ }
752
+ get visibleNodes() {
753
+ return $40fcfa3e17312481$var$createList(this.props.root);
754
+ }
755
+ }
756
+ const $40fcfa3e17312481$var$getIds = $g00cZ$memoizeone((nodes)=>nodes.map((n)=>n.id
757
+ )
758
+ );
759
+ const $40fcfa3e17312481$var$createIndex = $g00cZ$memoizeone((nodes)=>{
760
+ return nodes.reduce((map, node, index)=>{
761
+ map[node.id] = index;
762
+ return map;
763
+ }, {
764
+ });
765
+ });
766
+ const $40fcfa3e17312481$var$createList = $g00cZ$memoizeone($4dcb7be69f759cab$export$79f9fa345a841d8b);
767
+ function $40fcfa3e17312481$var$dfs(node, id) {
768
+ if (!node) return null;
769
+ if (node.id === id) return node;
770
+ if (node.children) for (let child of node.children){
771
+ const result = $40fcfa3e17312481$var$dfs(child, id);
772
+ if (result) return result;
773
+ }
774
+ return null;
775
+ }
776
+
777
+
778
+ function $496a9613a893751e$export$367b0f2231a90ba0(state, dispatch, props, list) {
779
+ /**
780
+ * We only ever want one instance of the api object
781
+ * It will get updated as the props change, but the
782
+ * reference will not.
783
+ */ const api = $g00cZ$useMemo(()=>new $40fcfa3e17312481$export$e2da3477247342d1(dispatch, state, props, list)
784
+ , // eslint-disable-next-line
785
+ []);
786
+ api.assign(dispatch, state, props, list);
787
+ /**
788
+ * This ensures that the selection remains correct even
789
+ * after opening and closing a folders
790
+ */ $g00cZ$useLayoutEffect(()=>{
791
+ dispatch($b26f0eafd5701d7d$export$e324594224ef24da.setVisibleIds(api.visibleIds, api.idToIndex));
792
+ }, [
793
+ dispatch,
794
+ api,
795
+ props.root
796
+ ]);
797
+ return api;
798
+ }
799
+
800
+
801
+ function $3a48b0a92affa3e3$export$6a399b2f7f12632c(props) {
802
+ const [state, dispatch] = $g00cZ$useReducer($b26f0eafd5701d7d$export$1650419e431d3ba3, $b26f0eafd5701d7d$export$f6196a6c6bb539b4());
803
+ const list = $g00cZ$useRef();
804
+ const api = $496a9613a893751e$export$367b0f2231a90ba0(state, dispatch, props, list.current);
805
+ $g00cZ$useImperativeHandle(props.imperativeHandle, ()=>api
806
+ );
807
+ $bafe08914d05476b$export$de605877a37dc399(props.listEl, api);
808
+ const staticValue = $g00cZ$useMemo(()=>({
809
+ ...props,
810
+ api: api,
811
+ list: list
812
+ })
813
+ , [
814
+ props,
815
+ api,
816
+ list
817
+ ]);
818
+ /**
819
+ * This context pattern is ridiculous, next time use redux.
820
+ */ return(// @ts-ignore
821
+ /*#__PURE__*/ $g00cZ$jsx($3273af3fe11a7001$export$c1b9a1d3af45b7b6.Provider, {
822
+ value: staticValue,
823
+ children: /*#__PURE__*/ $g00cZ$jsx($3273af3fe11a7001$export$7f994e57c9e78355.Provider, {
824
+ value: state.editingId,
825
+ children: /*#__PURE__*/ $g00cZ$jsx($3273af3fe11a7001$export$7c7a4fd7f1336e2c.Provider, {
826
+ value: state.selection,
827
+ children: /*#__PURE__*/ $g00cZ$jsx($3273af3fe11a7001$export$7380e5d4146ff2ce.Provider, {
828
+ value: $3a48b0a92affa3e3$var$getParentId(state.cursor),
829
+ children: /*#__PURE__*/ $g00cZ$jsx($3273af3fe11a7001$export$86fe4415b73783a1.Provider, {
830
+ value: $3a48b0a92affa3e3$var$isOverFolder(state),
831
+ children: /*#__PURE__*/ $g00cZ$jsx($3273af3fe11a7001$export$76f51715425ee155.Provider, {
832
+ value: state.cursor,
833
+ children: props.children
834
+ })
835
+ })
836
+ })
837
+ })
838
+ })
839
+ }));
840
+ }
841
+ function $3a48b0a92affa3e3$var$getParentId(cursor) {
842
+ switch(cursor.type){
843
+ case "highlight":
844
+ return cursor.id;
845
+ default:
846
+ return null;
847
+ }
848
+ }
849
+ function $3a48b0a92affa3e3$var$isOverFolder(state) {
850
+ return state.cursor.type === "highlight";
851
+ }
852
+
853
+
854
+
855
+
856
+
857
+
858
+ function $fe2fd2e13360ebf7$export$ef961593063b03e8() {
859
+ const treeView = $3273af3fe11a7001$export$ea6c3ae2bd3a5510();
860
+ const cursor = $3273af3fe11a7001$export$6c87584817ff2461();
861
+ if (!cursor || cursor.type !== "line") return null;
862
+ const top = treeView.rowHeight * cursor.index;
863
+ const left = treeView.indent * cursor.level;
864
+ const style = {
865
+ position: "absolute",
866
+ pointerEvents: "none",
867
+ top: top - 2 + "px",
868
+ left: treeView.indent + left + "px",
869
+ right: treeView.indent + "px"
870
+ };
871
+ return(/*#__PURE__*/ $g00cZ$jsx($fe2fd2e13360ebf7$var$DefaultCursor, {
872
+ style: style
873
+ }));
874
+ }
875
+ const $fe2fd2e13360ebf7$var$placeholderStyle = {
876
+ display: "flex",
877
+ alignItems: "center"
878
+ };
879
+ const $fe2fd2e13360ebf7$var$lineStyle = {
880
+ flex: 1,
881
+ height: "2px",
882
+ background: "#4B91E2",
883
+ borderRadius: "1px"
884
+ };
885
+ const $fe2fd2e13360ebf7$var$circleStyle = {
886
+ width: "4px",
887
+ height: "4px",
888
+ boxShadow: "0 0 0 3px #4B91E2",
889
+ borderRadius: "50%"
890
+ };
891
+ function $fe2fd2e13360ebf7$var$DefaultCursor({ style: style }) {
892
+ return(/*#__PURE__*/ $g00cZ$jsxs("div", {
893
+ style: {
894
+ ...$fe2fd2e13360ebf7$var$placeholderStyle,
895
+ ...style
896
+ },
897
+ children: [
898
+ /*#__PURE__*/ $g00cZ$jsx("div", {
899
+ style: {
900
+ ...$fe2fd2e13360ebf7$var$circleStyle
901
+ }
902
+ }),
903
+ /*#__PURE__*/ $g00cZ$jsx("div", {
904
+ style: {
905
+ ...$fe2fd2e13360ebf7$var$lineStyle
906
+ }
907
+ })
908
+ ]
909
+ }));
910
+ }
911
+
912
+
913
+
914
+
915
+
916
+
917
+ const $6d8109ab8cbcd5e7$var$layerStyles = {
918
+ position: "fixed",
919
+ pointerEvents: "none",
920
+ zIndex: 100,
921
+ left: 0,
922
+ top: 0,
923
+ width: "100%",
924
+ height: "100%"
925
+ };
926
+ const $6d8109ab8cbcd5e7$var$getStyle = (offset)=>{
927
+ if (!offset) return {
928
+ display: "none"
929
+ };
930
+ const { x: x , y: y } = offset;
931
+ return {
932
+ transform: `translate(${x}px, ${y}px)`
933
+ };
934
+ };
935
+ const $6d8109ab8cbcd5e7$var$getCountStyle = (offset)=>{
936
+ if (!offset) return {
937
+ display: "none"
938
+ };
939
+ const { x: x , y: y } = offset;
940
+ return {
941
+ transform: `translate(${x + 10}px, ${y + 10}px)`
942
+ };
943
+ };
944
+ function $6d8109ab8cbcd5e7$export$133773870222880f() {
945
+ const { offset: offset , mouse: mouse , item: item , isDragging: isDragging } = $g00cZ$useDragLayer((m)=>({
946
+ offset: m.getSourceClientOffset(),
947
+ mouse: m.getClientOffset(),
948
+ item: m.getItem(),
949
+ isDragging: m.isDragging()
950
+ })
951
+ );
952
+ return(/*#__PURE__*/ $g00cZ$jsxs($6d8109ab8cbcd5e7$var$Overlay, {
953
+ isDragging: isDragging,
954
+ children: [
955
+ /*#__PURE__*/ $g00cZ$jsx($6d8109ab8cbcd5e7$var$Position, {
956
+ offset: offset,
957
+ children: /*#__PURE__*/ $g00cZ$jsx($6d8109ab8cbcd5e7$var$PreviewNode, {
958
+ item: item
959
+ })
960
+ }),
961
+ /*#__PURE__*/ $g00cZ$jsx($6d8109ab8cbcd5e7$var$Count, {
962
+ mouse: mouse,
963
+ item: item
964
+ })
965
+ ]
966
+ }));
967
+ }
968
+ const $6d8109ab8cbcd5e7$var$Overlay = /*#__PURE__*/ $g00cZ$memo(function Overlay(props) {
969
+ if (!props.isDragging) return null;
970
+ return(/*#__PURE__*/ $g00cZ$jsx("div", {
971
+ style: $6d8109ab8cbcd5e7$var$layerStyles,
972
+ children: props.children
973
+ }));
974
+ });
975
+ function $6d8109ab8cbcd5e7$var$Position(props) {
976
+ return(/*#__PURE__*/ $g00cZ$jsx("div", {
977
+ className: "row preview",
978
+ style: $6d8109ab8cbcd5e7$var$getStyle(props.offset),
979
+ children: props.children
980
+ }));
981
+ }
982
+ function $6d8109ab8cbcd5e7$var$Count(props) {
983
+ const { item: item , mouse: mouse } = props;
984
+ if (item?.dragIds?.length > 1) return(/*#__PURE__*/ $g00cZ$jsx("div", {
985
+ className: "selected-count",
986
+ style: $6d8109ab8cbcd5e7$var$getCountStyle(mouse),
987
+ children: item.dragIds.length
988
+ }));
989
+ else return null;
990
+ }
991
+ const $6d8109ab8cbcd5e7$var$PreviewNode = /*#__PURE__*/ $g00cZ$memo(function PreviewNode(props) {
992
+ const tree = $3273af3fe11a7001$export$ea6c3ae2bd3a5510();
993
+ if (!props.item) return null;
994
+ const node = tree.api.getNode(props.item.id);
995
+ if (!node) return null;
996
+ return(/*#__PURE__*/ $g00cZ$jsx(tree.renderer, {
997
+ preview: true,
998
+ innerRef: ()=>{
999
+ },
1000
+ data: node.model,
1001
+ styles: {
1002
+ row: {
1003
+ },
1004
+ indent: {
1005
+ paddingLeft: node.level * tree.indent
1006
+ }
1007
+ },
1008
+ tree: tree.api,
1009
+ state: {
1010
+ isDragging: false,
1011
+ isEditing: false,
1012
+ isSelected: false,
1013
+ isFirstOfSelected: false,
1014
+ isLastOfSelected: false,
1015
+ isHoveringOverChild: false,
1016
+ isOpen: node.isOpen
1017
+ },
1018
+ handlers: {
1019
+ edit: ()=>{
1020
+ },
1021
+ select: ()=>{
1022
+ },
1023
+ toggle: ()=>{
1024
+ },
1025
+ submit: ()=>{
1026
+ },
1027
+ reset: ()=>{
1028
+ }
1029
+ }
1030
+ }));
1031
+ });
1032
+
1033
+
1034
+
1035
+
1036
+
1037
+
1038
+
1039
+
1040
+
1041
+ function $907e707a330ef23a$export$715c0d031ede7907(node) {
1042
+ const tree = $3273af3fe11a7001$export$ea6c3ae2bd3a5510();
1043
+ const isSelected = $3273af3fe11a7001$export$fb40a80c530e5f2b();
1044
+ const ids = $3273af3fe11a7001$export$1c9b7756eccadc96();
1045
+ const [{ isDragging: isDragging }, ref, preview] = $g00cZ$useDrag(()=>({
1046
+ canDrag: ()=>node.isDraggable
1047
+ ,
1048
+ type: "NODE",
1049
+ item: ()=>({
1050
+ id: node.id,
1051
+ dragIds: isSelected(node.rowIndex) ? ids : [
1052
+ node.id
1053
+ ]
1054
+ })
1055
+ ,
1056
+ collect: (m)=>({
1057
+ isDragging: m.isDragging()
1058
+ })
1059
+ ,
1060
+ end: (item, monitor)=>{
1061
+ tree.api.hideCursor();
1062
+ const drop = monitor.getDropResult();
1063
+ if (drop && drop.parentId) {
1064
+ tree.onMove(item.dragIds, drop.parentId, drop.index);
1065
+ tree.onToggle(drop.parentId, true);
1066
+ }
1067
+ }
1068
+ })
1069
+ , [
1070
+ ids,
1071
+ node
1072
+ ]);
1073
+ $g00cZ$useEffect(()=>{
1074
+ preview($g00cZ$getEmptyImage());
1075
+ }, [
1076
+ preview
1077
+ ]);
1078
+ return [
1079
+ {
1080
+ isDragging: isDragging
1081
+ },
1082
+ ref
1083
+ ];
1084
+ }
1085
+
1086
+
1087
+
1088
+
1089
+
1090
+
1091
+ function $d38aa53467160173$export$57afafec4637d997(el, node, prev, next) {
1092
+ const tree = $3273af3fe11a7001$export$ea6c3ae2bd3a5510();
1093
+ return $g00cZ$useDrop(()=>({
1094
+ accept: "NODE",
1095
+ canDrop: (item)=>{
1096
+ for (let id of item.dragIds){
1097
+ const drag = tree.api.getNode(id);
1098
+ if (!drag) return false;
1099
+ if ($0e6083160f4b36ed$export$769c5e872f5f8638(drag) && $0e6083160f4b36ed$export$1e38f72c6c546f70(node, drag)) return false;
1100
+ }
1101
+ return true;
1102
+ },
1103
+ hover: (item, m)=>{
1104
+ if (m.canDrop()) {
1105
+ const offset = m.getClientOffset();
1106
+ if (!el.current || !offset) return;
1107
+ const { cursor: cursor } = $2db980bfed6822da$export$f502ca02ebb85a1c({
1108
+ element: el.current,
1109
+ offset: offset,
1110
+ indent: tree.indent,
1111
+ node: node,
1112
+ prevNode: prev,
1113
+ nextNode: next
1114
+ });
1115
+ if (cursor) tree.api.showCursor(cursor);
1116
+ } else tree.api.hideCursor();
1117
+ },
1118
+ drop: (item, m)=>{
1119
+ const offset = m.getClientOffset();
1120
+ if (!el.current || !offset) return;
1121
+ const { drop: drop } = $2db980bfed6822da$export$f502ca02ebb85a1c({
1122
+ element: el.current,
1123
+ offset: offset,
1124
+ indent: tree.indent,
1125
+ node: node,
1126
+ prevNode: prev,
1127
+ nextNode: next
1128
+ });
1129
+ return drop;
1130
+ }
1131
+ })
1132
+ , [
1133
+ node,
1134
+ prev,
1135
+ el,
1136
+ tree
1137
+ ]);
1138
+ }
1139
+
1140
+
1141
+ const $2c0a5a237609003e$export$b59bdbef9ce70de2 = /*#__PURE__*/ $g00cZ$react.memo(function $2c0a5a237609003e$export$b59bdbef9ce70de2({ index: index , style: style }) {
1142
+ const tree = $3273af3fe11a7001$export$ea6c3ae2bd3a5510();
1143
+ const selected = $3273af3fe11a7001$export$fb40a80c530e5f2b();
1144
+ const node = tree.api.visibleNodes[index];
1145
+ const next = tree.api.visibleNodes[index + 1] || null;
1146
+ const prev = tree.api.visibleNodes[index - 1] || null;
1147
+ const cursorParentId = $3273af3fe11a7001$export$8e294ac6de4c921f();
1148
+ const cursorOverFolder = $3273af3fe11a7001$export$f3ad962ff713505f();
1149
+ const el = $g00cZ$useRef(null);
1150
+ const [{ isDragging: isDragging }, dragRef] = $907e707a330ef23a$export$715c0d031ede7907(node);
1151
+ const [, dropRef] = $d38aa53467160173$export$57afafec4637d997(el, node, prev, next);
1152
+ const isEditing = node.id === $3273af3fe11a7001$export$9ab192f953c1b33b();
1153
+ const isSelected = selected(index);
1154
+ const nextSelected = next && selected(index + 1);
1155
+ const prevSelected = prev && selected(index - 1);
1156
+ const isHoveringOverChild = node.id === cursorParentId;
1157
+ const isOverFolder = node.id === cursorParentId && cursorOverFolder;
1158
+ const isOpen = node.isOpen;
1159
+ const indent = tree.indent * node.level;
1160
+ const state = $g00cZ$useMemo(()=>{
1161
+ return {
1162
+ isEditing: isEditing,
1163
+ isDragging: isDragging,
1164
+ isFirstOfSelected: isSelected && !prevSelected,
1165
+ isLastOfSelected: isSelected && !nextSelected,
1166
+ isSelected: isSelected,
1167
+ isHoveringOverChild: isHoveringOverChild,
1168
+ isOpen: isOpen,
1169
+ isOverFolder: isOverFolder
1170
+ };
1171
+ }, [
1172
+ isEditing,
1173
+ isSelected,
1174
+ prevSelected,
1175
+ nextSelected,
1176
+ isHoveringOverChild,
1177
+ isOpen,
1178
+ isDragging,
1179
+ isOverFolder,
1180
+ ]);
1181
+ if (isSelected) console.log({
1182
+ id: node.id,
1183
+ state: state
1184
+ });
1185
+ const ref = $g00cZ$useCallback((n)=>{
1186
+ el.current = n;
1187
+ dragRef(dropRef(n));
1188
+ }, [
1189
+ dragRef,
1190
+ dropRef
1191
+ ]);
1192
+ const styles = $g00cZ$useMemo(()=>({
1193
+ row: {
1194
+ ...style
1195
+ },
1196
+ indent: {
1197
+ paddingLeft: indent
1198
+ }
1199
+ })
1200
+ , [
1201
+ indent,
1202
+ style
1203
+ ]);
1204
+ const handlers = $g00cZ$useMemo(()=>{
1205
+ return {
1206
+ select: (e, selectOnClick = true)=>{
1207
+ if (node.rowIndex === null) return;
1208
+ if (selectOnClick || e.metaKey || e.shiftKey) tree.api.select(node.rowIndex, e.metaKey, e.shiftKey);
1209
+ else tree.api.select(null, false, false);
1210
+ },
1211
+ toggle: (e)=>{
1212
+ e.stopPropagation();
1213
+ tree.onToggle(node.id, !node.isOpen);
1214
+ },
1215
+ edit: ()=>{
1216
+ tree.api.edit(node.id);
1217
+ },
1218
+ submit: (name)=>{
1219
+ if (name.trim()) tree.onEdit(node.id, name);
1220
+ tree.api.edit(null);
1221
+ },
1222
+ reset: ()=>{
1223
+ tree.api.edit(null);
1224
+ }
1225
+ };
1226
+ }, [
1227
+ tree,
1228
+ node
1229
+ ]);
1230
+ const Renderer = $g00cZ$useMemo(()=>{
1231
+ return(/*#__PURE__*/ $g00cZ$react.memo(tree.renderer));
1232
+ }, [
1233
+ tree.renderer
1234
+ ]);
1235
+ return(/*#__PURE__*/ $g00cZ$jsx(Renderer, {
1236
+ innerRef: ref,
1237
+ data: node.model,
1238
+ styles: styles,
1239
+ state: state,
1240
+ handlers: handlers,
1241
+ preview: false,
1242
+ tree: tree.api
1243
+ }));
1244
+ });
1245
+
1246
+
1247
+ const $2ba43033bb8eb39d$var$OuterElement = /*#__PURE__*/ $g00cZ$forwardRef(function Outer(props, ref) {
1248
+ const { children: children , ...rest } = props;
1249
+ const tree = $3273af3fe11a7001$export$ea6c3ae2bd3a5510();
1250
+ return(// @ts-ignore
1251
+ /*#__PURE__*/ $g00cZ$jsxs("div", {
1252
+ ref: ref,
1253
+ ...rest,
1254
+ onClick: tree.onClick,
1255
+ children: [
1256
+ /*#__PURE__*/ $g00cZ$jsx("div", {
1257
+ style: {
1258
+ height: tree.api.visibleNodes.length * tree.rowHeight,
1259
+ width: "100%",
1260
+ overflow: "hidden",
1261
+ position: "absolute",
1262
+ left: "0",
1263
+ right: "0"
1264
+ },
1265
+ children: /*#__PURE__*/ $g00cZ$jsx($fe2fd2e13360ebf7$export$ef961593063b03e8, {
1266
+ })
1267
+ }),
1268
+ children
1269
+ ]
1270
+ }));
1271
+ });
1272
+ function $2ba43033bb8eb39d$var$List(props) {
1273
+ const tree = $3273af3fe11a7001$export$ea6c3ae2bd3a5510();
1274
+ return(/*#__PURE__*/ $g00cZ$jsx("div", {
1275
+ style: {
1276
+ height: tree.height,
1277
+ width: tree.width,
1278
+ overflow: "hidden"
1279
+ },
1280
+ children: /*#__PURE__*/ $g00cZ$jsx($g00cZ$FixedSizeList, {
1281
+ className: props.className,
1282
+ outerRef: tree.listEl,
1283
+ itemCount: tree.api.visibleNodes.length,
1284
+ height: tree.height,
1285
+ width: tree.width,
1286
+ itemSize: tree.rowHeight,
1287
+ itemKey: (index)=>tree.api.visibleNodes[index]?.id || index
1288
+ ,
1289
+ outerElementType: $2ba43033bb8eb39d$var$OuterElement,
1290
+ // @ts-ignore
1291
+ ref: tree.list,
1292
+ children: $2c0a5a237609003e$export$b59bdbef9ce70de2
1293
+ })
1294
+ }));
1295
+ }
1296
+ function $2ba43033bb8eb39d$var$OuterDrop(props) {
1297
+ $e739455e59c6aed3$export$5a6c424b1725f44f();
1298
+ return props.children;
1299
+ }
1300
+ const $2ba43033bb8eb39d$export$7fbedc92909ed28e = /*#__PURE__*/ $g00cZ$forwardRef(function $2ba43033bb8eb39d$export$7fbedc92909ed28e(props, ref) {
1301
+ const root = $g00cZ$useMemo(()=>$1e5818ce7991d06d$export$9c537176392280a0(props.data, props.hideRoot, props.getChildren, props.isOpen, props.disableDrag, props.disableDrop, props.openByDefault)
1302
+ , [
1303
+ props.data,
1304
+ props.hideRoot,
1305
+ props.getChildren,
1306
+ props.isOpen,
1307
+ props.disableDrag,
1308
+ props.disableDrop,
1309
+ props.openByDefault,
1310
+ ]);
1311
+ return(/*#__PURE__*/ $g00cZ$jsx($3a48b0a92affa3e3$export$6a399b2f7f12632c, {
1312
+ imperativeHandle: ref,
1313
+ root: root,
1314
+ listEl: $g00cZ$useRef(null),
1315
+ renderer: props.children,
1316
+ width: props.width === undefined ? 300 : props.width,
1317
+ height: props.height === undefined ? 500 : props.height,
1318
+ indent: props.indent === undefined ? 24 : props.indent,
1319
+ rowHeight: props.rowHeight === undefined ? 24 : props.rowHeight,
1320
+ onMove: props.onMove || $0e6083160f4b36ed$export$8793edee2d425525,
1321
+ onToggle: props.onToggle || $0e6083160f4b36ed$export$8793edee2d425525,
1322
+ onEdit: props.onEdit || $0e6083160f4b36ed$export$8793edee2d425525,
1323
+ onClick: props.onClick,
1324
+ onContextMenu: props.onContextMenu,
1325
+ children: /*#__PURE__*/ $g00cZ$jsxs($g00cZ$DndProvider, {
1326
+ backend: $g00cZ$HTML5Backend,
1327
+ children: [
1328
+ /*#__PURE__*/ $g00cZ$jsx($2ba43033bb8eb39d$var$OuterDrop, {
1329
+ children: /*#__PURE__*/ $g00cZ$jsx($2ba43033bb8eb39d$var$List, {
1330
+ className: props.className,
1331
+ onClick: props.onClick
1332
+ })
1333
+ }),
1334
+ /*#__PURE__*/ $g00cZ$jsx($6d8109ab8cbcd5e7$export$133773870222880f, {
1335
+ })
1336
+ ]
1337
+ })
1338
+ }));
1339
+ });
1340
+
1341
+
1342
+
1343
+
1344
+
1345
+ export {$2ba43033bb8eb39d$export$7fbedc92909ed28e as Tree, $40fcfa3e17312481$export$e2da3477247342d1 as TreeApi};
1346
+ //# sourceMappingURL=module.js.map